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

Function addAnimationToScript

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

Source from the content-addressed store, hash-verified

1513}
1514
1515export function addAnimationToScript(
1516 script: string,
1517 animation: Omit<GsapAnimation, "id">,
1518): { script: string; id: string } {
1519 let parsed: ParsedGsapAst;
1520 try {
1521 parsed = parseGsapAst(script);
1522 } catch (e) {
1523 console.warn("[gsap-parser] addAnimationToScript parse failed:", e);
1524 return { script, id: "" };
1525 }
1526 // Nothing to anchor against and no timeline to target — treat as parse failure.
1527 if (parsed.located.length === 0 && parsed.detection.ref === null) {
1528 return { script, id: "" };
1529 }
1530
1531 const id = `anim-${Date.now()}`;
1532 const statementCode = buildTweenStatementCode(parsed.timelineVar, animation);
1533 const newStatement = parseScript(statementCode).program.body[0];
1534 insertAfterAnchor(parsed, newStatement);
1535 return { script: recast.print(parsed.ast).code, id };
1536}
1537
1538export function addAnimationWithKeyframesToScript(
1539 script: string,

Calls 6

parseGsapAstFunction · 0.85
insertAfterAnchorFunction · 0.85
warnMethod · 0.80
nowMethod · 0.80
buildTweenStatementCodeFunction · 0.70
parseScriptFunction · 0.70

Tested by

no test coverage detected