|
7 | 7 | * This is the safety net for porting WS-3 ops one at a time: each ported op |
8 | 8 | * gets a fixture row here proving it matches the battle-tested original. |
9 | 9 | * |
10 | | - * The server switches between writers via STUDIO_SDK_CUTOVER_ENABLED (WS-3.F). |
11 | | - * Recast remains the default; acorn runs only when the flag is enabled. |
| 10 | + * The server picks the writer from HYPERFRAMES_GSAP_WRITER; acorn is the default. |
12 | 11 | */ |
13 | 12 | import { describe, expect, it } from "vitest"; |
| 13 | +import { parseHTML } from "linkedom"; |
14 | 14 | import { |
15 | 15 | parseGsapScript, |
16 | 16 | removeAllKeyframesFromScript as removeAllRecast, |
@@ -1973,3 +1973,93 @@ tl.to("#el", { y: 50, duration: 1 }, "+=0.5");`; |
1973 | 1973 | expect(scaleAcorn(POSITIONS_MULTI, "#hero", 0, 1, 2, 0)).toBe(POSITIONS_MULTI); |
1974 | 1974 | }); |
1975 | 1975 | }); |
| 1976 | + |
| 1977 | +describe("shift/scalePositionsInScript carry the clip's inner tweens", () => { |
| 1978 | + const { document } = parseHTML(`<html><body> |
| 1979 | +<div id="scene" data-start="1" data-duration="4"> |
| 1980 | + <h1 class="title">Hi</h1> |
| 1981 | + <p id="child" class="inner">Kid</p> |
| 1982 | + <div id="nested" data-start="2" data-duration="1"><span id="deep">x</span></div> |
| 1983 | +</div> |
| 1984 | +<div id="sibling" class="title">Out</div> |
| 1985 | +</body></html>`); |
| 1986 | + const script = `const tl = gsap.timeline({ paused: true }); |
| 1987 | +tl.from("#scene", { opacity: 0, duration: 1 }, 1); |
| 1988 | +tl.from("#scene h1", { y: 20, duration: 1 }, 1.5); |
| 1989 | +tl.to("#child", { rotation: 90, duration: 1 }); |
| 1990 | +tl.to("#sibling", { y: 5, duration: 0.5 }); |
| 1991 | +tl.to("#child", { x: 10, duration: 1 }, 2); |
| 1992 | +tl.to(["#child", "#scene h1"], { opacity: 0.5, duration: 1 }, 3); |
| 1993 | +tl.to(".inner", { scale: 2, duration: 1 }, 3.5); |
| 1994 | +tl.to("#sibling", { x: 5, duration: 1 }, 2); |
| 1995 | +tl.to(".title", { color: "red", duration: 1 }, 2.5); |
| 1996 | +tl.to("#deep", { y: 5, duration: 0.5 }, 2); |
| 1997 | +tl.to(["#scene h1", window.logo], { x: 1, duration: 1 }, 2); |
| 1998 | +tl.to(["#scene", window.logo], { x: 2, duration: 1 }, 2);`; |
| 1999 | + const timings = (out: string) => |
| 2000 | + parseGsapScriptAcorn(out).animations.map((a) => [ |
| 2001 | + a.targetSelector, |
| 2002 | + a.implicitPosition ? "chained" : a.position, |
| 2003 | + a.duration, |
| 2004 | + ]); |
| 2005 | + const writers = [ |
| 2006 | + ["acorn", shiftAcorn, scaleAcorn], |
| 2007 | + ["recast", shiftRecast, scaleRecast], |
| 2008 | + ] as const; |
| 2009 | + |
| 2010 | + const bare = parseHTML( |
| 2011 | + `<html><body><div id="bare" class="card"><p>x</p></div></body></html>`, |
| 2012 | + ).document; |
| 2013 | + const bareScript = `const tl = gsap.timeline({ paused: true }); |
| 2014 | +tl.to(".card", { x: 1, duration: 1 }, 1);`; |
| 2015 | + |
| 2016 | + for (const [name, shift, scale] of writers) { |
| 2017 | + it(`${name}: a tween whose target is the clip moves with it, even without data-start`, () => { |
| 2018 | + expect(timings(shift(bareScript, "#bare", 1, bare))).toEqual([[".card", 2, 1]]); |
| 2019 | + }); |
| 2020 | + |
| 2021 | + it(`${name}: known limit, an outside tween chained after moved content moves with it`, () => { |
| 2022 | + const sibling = (out: string) => parseGsapScriptAcorn(out).animations[3]!; |
| 2023 | + expect(sibling(script)).toMatchObject({ targetSelector: "#sibling", resolvedStart: 3.5 }); |
| 2024 | + expect(sibling(shift(script, "#scene", 2, document))).toMatchObject({ |
| 2025 | + targetSelector: "#sibling", |
| 2026 | + implicitPosition: true, |
| 2027 | + resolvedStart: 5.5, |
| 2028 | + }); |
| 2029 | + }); |
| 2030 | + |
| 2031 | + it(`${name}: a shift moves the clip and its descendants, never outside or nested clips`, () => { |
| 2032 | + expect(timings(shift(script, "#scene", 2, document))).toEqual([ |
| 2033 | + ["#scene", 3, 1], |
| 2034 | + ["#scene h1", 3.5, 1], |
| 2035 | + ["#child", "chained", 1], |
| 2036 | + ["#sibling", "chained", 0.5], |
| 2037 | + ["#child", 4, 1], |
| 2038 | + ["#child, #scene h1", 5, 1], |
| 2039 | + [".inner", 5.5, 1], |
| 2040 | + ["#sibling", 2, 1], |
| 2041 | + [".title", 2.5, 1], |
| 2042 | + ["#deep", 2, 0.5], |
| 2043 | + ["#scene h1", 2, 1], |
| 2044 | + ["#scene", 2, 1], |
| 2045 | + ]); |
| 2046 | + }); |
| 2047 | + |
| 2048 | + it(`${name}: a scale retimes the clip and its descendants, never outside or nested clips`, () => { |
| 2049 | + expect(timings(scale(script, "#scene", 1, 4, 1, 8, document))).toEqual([ |
| 2050 | + ["#scene", 1, 2], |
| 2051 | + ["#scene h1", 2, 2], |
| 2052 | + ["#child", "chained", 2], |
| 2053 | + ["#sibling", "chained", 0.5], |
| 2054 | + ["#child", 3, 2], |
| 2055 | + ["#child, #scene h1", 5, 2], |
| 2056 | + [".inner", 6, 2], |
| 2057 | + ["#sibling", 2, 1], |
| 2058 | + [".title", 2.5, 1], |
| 2059 | + ["#deep", 2, 0.5], |
| 2060 | + ["#scene h1", 2, 1], |
| 2061 | + ["#scene", 2, 1], |
| 2062 | + ]); |
| 2063 | + }); |
| 2064 | + } |
| 2065 | +}); |
0 commit comments