Skip to content

Commit 5518787

Browse files
committed
fix(studio): an unplayed keyframe tween clears every keyframe's channels before it is read
1 parent 707e3d6 commit 5518787

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎packages/studio/src/hooks/gsapParsedTween.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export function findParsedTween(
6666
const win = iframe?.contentWindow as GsapWindow | null;
6767
const start = resolveTweenStart(anim);
6868
if (!win?.__timelines || start == null) return null;
69-
const props = Object.keys(anim.keyframes?.keyframes[0]?.properties ?? anim.properties);
69+
const steps = anim.keyframes?.keyframes.map((kf) => kf.properties) ?? [anim.properties];
70+
const props = [...new Set(steps.flatMap((step) => Object.keys(step)))];
7071
const keyframed = Boolean(anim.keyframes);
7172
for (const timeline of Object.values(win.__timelines)) {
7273
for (const tween of timeline?.getChildren?.(true) ?? []) {

‎packages/studio/src/hooks/gsapValueAtPlayhead.realGsap.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ window.__timelines["t"] = tl;`;
9494
timeline.kill();
9595
});
9696

97+
it("saves a dragged keyframe tween with its authored start, not the drag's live value", () => {
98+
const box = Object.assign(document.body.appendChild(document.createElement("div")), { id: "x" });
99+
const src = script(
100+
"keyframes: { '0%': { opacity: 0 }, '100%': { opacity: 1, x: 300 } }, duration: 1, ease: 'none'",
101+
).replace("}, 0);", "}, 2);");
102+
const { timeline, iframe } = play(src, 0.5);
103+
usePlayerStore.setState({ currentTime: 0.5, activeKeyframePct: null });
104+
gsap.set(box, { x: 77 });
105+
const anim = parseGsapScriptAcorn(src).animations[0]!;
106+
const selection = { id: "x", selector: "#x", element: box } as DomEditSelection;
107+
108+
const plan = planValueEdit(selection, anim, { x: 77 }, iframe);
109+
timeline.kill();
110+
111+
expect(plan.ok).toBe(true);
112+
if (!plan.ok) return;
113+
const written = replaceTweenWithKeyframesInScript(src, anim.id, plan.mutation)!;
114+
const at = (time: number) => {
115+
const replay = play(written, time);
116+
const x = gsap.getProperty(box, "x");
117+
replay.timeline.kill();
118+
return x;
119+
};
120+
expect(at(0.5)).toBe(77);
121+
expect(at(2)).toBe(0);
122+
expect(at(3)).toBe(300);
123+
});
124+
97125
it("names only an ease GSAP built in, and refuses a custom function rather than guess", () => {
98126
const custom = { vars: { ease: (p: number) => p * p } };
99127
const iframe = { contentWindow: { gsap } } as unknown as HTMLIFrameElement;

0 commit comments

Comments
 (0)