MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / addAnimationToScript

Function addAnimationToScript

packages/parsers/src/gsapWriterAcorn.ts:451–469  ·  view source on GitHub ↗
(
  script: string,
  animation: Omit<GsapAnimation, "id">,
)

Source from the content-addressed store, hash-verified

449}
450
451export function addAnimationToScript(
452 script: string,
453 animation: Omit<GsapAnimation, "id">,
454): { script: string; id: string } {
455 const parsed = parseGsapScriptAcornForWrite(script);
456 if (!parsed) return { script, id: "" };
457
458 const insertionPoint = findInsertionPoint(parsed);
459 if (insertionPoint === null) return { script, id: "" };
460
461 const ms = new MagicString(script);
462 const statementCode = buildTweenStatementCode(parsed.timelineVar, animation);
463 ms.appendLeft(insertionPoint, "\n" + statementCode);
464
465 const result = ms.toString();
466 const reParsed = parseGsapScriptAcornForWrite(result);
467 const newId = reParsed?.located[reParsed.located.length - 1]?.id ?? "";
468 return { script: result, id: newId };
469}
470
471/** Splice a single located tween call out of a MagicString (standalone stmt or chain link). */
472function removeCallFromMagicString(ms: MagicString, call: TweenCallInfo, script: string): void {

Callers 2

addGroupAnimToScriptFunction · 0.70
buildSpanningSplitFunction · 0.70

Calls 3

findInsertionPointFunction · 0.85
buildTweenStatementCodeFunction · 0.70

Tested by

no test coverage detected