Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(studio): resizing a faded or moving element writes a plain size, not keyframes (#4737)
Miguel Ángeld2851aa304e1
diff --git a/packages/studio/src/hooks/gsapResizeIntercept.test.ts b/packages/studio/src/hooks/gsapResizeIntercept.test.tsindex 2037c7f19f..5b6db51b05 100644--- a/packages/studio/src/hooks/gsapResizeIntercept.test.ts+++ b/packages/studio/src/hooks/gsapResizeIntercept.test.ts@@ -521,3 +521,43 @@ it("does not move a statically positioned element when a scale resize lands", as// And the live element ends on the drop point, not a drag away from it.expect(el.getBoundingClientRect().x).toBeCloseTo(603.3, 0);});++function titleSelection(): DomEditSelection {+ const el = document.createElement("h1");+ el.id = "title";+ document.body.append(el);+ return { id: "title", selector: "#title", element: el } as DomEditSelection;+}++it("writes a plain size on an element whose only tween is a fade", async () => {+ const fade = {+ id: "#title-to-0-visual",+ targetSelector: "#title",+ propertyGroup: "visual",+ method: "to",+ properties: { opacity: 0.5 },+ position: 0,+ resolvedStart: 0,+ duration: 10,+ } as unknown as GsapAnimation;+ const commitMutation = vi.fn();++ const handled = await tryGsapResizeIntercept(+ titleSelection(),+ { width: 424, height: 237 },+ [fade],+ null,+ commitMutation,+ );++ expect(handled).toMatchObject({ status: "persisted" });+ const mutations = commitMutation.mock.calls.map((call) => call[1] as { type: string });+ expect(mutations.filter((m) => /keyframe/i.test(m.type))).toEqual([]);+ expect(mutations).toContainEqual({+ type: "add",+ targetSelector: "#title",+ method: "set",+ position: 0,+ properties: { width: 424, height: 237 },+ });+});diff --git a/packages/studio/src/hooks/gsapResizeIntercept.ts b/packages/studio/src/hooks/gsapResizeIntercept.tsindex 2a008bd1af..c5c57a28a3 100644--- a/packages/studio/src/hooks/gsapResizeIntercept.ts+++ b/packages/studio/src/hooks/gsapResizeIntercept.ts@@ -148,12 +148,16 @@ export async function tryGsapResizeIntercept(? (anim ?? findSizeSetAnimation(workingAnimations, sel, selection.element)): findSizeSetAnimation(workingAnimations, sel, selection.element);- // If the element is animated (has a real tween, not just a static size- // hold), keyframe the size at the playhead so other keyframes keep theirs —- // instead of a global set that resizes every frame.+ // Keyframe the size only when a real tween already animates it, as move and+ // rotate do; a fade or a slide on the element gets a plain size.if (resizeGroup === "size") {const animatedTween = pickClosestToPlayhead(- workingAnimations.filter((a) => !isInstantHold(a) && resolveTweenDuration(a) > 0),+ workingAnimations.filter(+ (a) =>+ !isInstantHold(a) &&+ resolveTweenDuration(a) > 0 &&+ animationWritesAnyProperty(a, resizeProperties),+ ),);if (animatedTween) {logResize("intercept-route", { route: "keyframed-size", tweenId: animatedTween.id });