Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(core): split-into-property-groups and replace-with-keyframes mutations (#1355)
Miguel Ángelb6bf1b119093
diff --git a/packages/core/src/studio-api/routes/files.ts b/packages/core/src/studio-api/routes/files.tsindex 9fd9099207..31b879bbbc 100644--- a/packages/core/src/studio-api/routes/files.ts+++ b/packages/core/src/studio-api/routes/files.ts@@ -409,6 +409,20 @@ type GsapMutationRequest =}>;ease?: string;}+ | {+ type: "replace-with-keyframes";+ animationId: string;+ targetSelector: string;+ position: number;+ duration: number;+ keyframes: Array<{+ percentage: number;+ properties: Record<string, number | string>;+ ease?: string;+ auto?: boolean;+ }>;+ ease?: string;+ }| {type: "split-animations";originalId: string;@@ -416,6 +430,10 @@ type GsapMutationRequest =splitTime: number;elementStart: number;elementDuration: number;+ }+ | {+ type: "split-into-property-groups";+ animationId: string;};// ── GSAP mutation executor ──────────────────────────────────────────────────@@ -445,6 +463,7 @@ async function executeGsapMutation(removeArcPathFromScript,addAnimationWithKeyframesToScript,splitAnimationsInScript,+ splitIntoPropertyGroups,} = parser;function requireAnimation(@@ -617,6 +636,18 @@ async function executeGsapMutation();return result.script;}+ case "replace-with-keyframes": {+ const script = removeAnimationFromScript(block.scriptText, body.animationId);+ const added = addAnimationWithKeyframesToScript(+ script,+ body.targetSelector,+ body.position,+ body.duration,+ body.keyframes,+ body.ease,+ );+ return added.script;+ }case "split-animations": {if (typeof body.originalId !== "string" ||@@ -647,6 +678,10 @@ async function executeGsapMutation(elementDuration: body.elementDuration,});}+ case "split-into-property-groups": {+ const result = splitIntoPropertyGroups(block.scriptText, body.animationId);+ return result.script;+ }default:return respond({ error: `unknown mutation type: ${(body as { type: string }).type}` }, 400);}@@ -1061,8 +1096,9 @@ export function registerFileRoutes(api: Hono, adapter: StudioApiAdapter): void {if (result instanceof Response) return result;const newScript = typeof result === "string" ? result : result.script;- const newHtml = block.replaceScript(newScript);- if (newHtml !== html) {+ const changed = newScript !== block.scriptText;+ const newHtml = changed ? block.replaceScript(newScript) : html;+ if (changed) {writeFileSync(res.absPath, newHtml, "utf-8");}@@ -1070,6 +1106,7 @@ export function registerFileRoutes(api: Hono, adapter: StudioApiAdapter): void {const freshParsed = parseGsapScript(newScript);const responsePayload: Record<string, unknown> = {ok: true,+ changed,parsed: freshParsed,before: html,after: newHtml,diff --git a/packages/studio/src/hooks/useGsapScriptCommits.ts b/packages/studio/src/hooks/useGsapScriptCommits.tsindex 70eee5215c..998c2b2cf0 100644--- a/packages/studio/src/hooks/useGsapScriptCommits.ts+++ b/packages/studio/src/hooks/useGsapScriptCommits.ts@@ -51,6 +51,7 @@ function ensureElementAddressable(selection: DomEditSelection): {interface MutationResult {ok: boolean;+ changed?: boolean;parsed?: ParsedGsap;before?: string;after?: string;@@ -131,9 +132,16 @@ export function useGsapScriptCommits({const pid = projectIdRef.current;if (!pid) return;const targetPath = selection.sourceFile || activeCompPath || "index.html";-const result = await mutateGsapScript(pid, targetPath, mutation);- if (!result?.ok) return;+ if (!result) {+ if (options.skipReload) return;+ throw new Error(`Mutation failed: ${mutation.type}`);+ }++ if (result.changed === false) {+ if (options.skipReload) return;+ return;+ }domEditSaveTimestampRef.current = Date.now();