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

Function insertInheritedStateSet

packages/parsers/src/gsapParser.ts:1680–1710  ·  view source on GitHub ↗
(
  script: string,
  selector: string,
  position: number,
  properties: Record<string, number | string>,
)

Source from the content-addressed store, hash-verified

1678}
1679
1680function insertInheritedStateSet(
1681 script: string,
1682 selector: string,
1683 position: number,
1684 properties: Record<string, number | string>,
1685): string {
1686 let parsed: ParsedGsapAst;
1687 try {
1688 parsed = parseGsapAst(script);
1689 } catch {
1690 return script;
1691 }
1692 const tlVar = parsed.timelineVar;
1693 const props = Object.entries(properties)
1694 .map(([k, v]) => `${k}: ${typeof v === "string" ? JSON.stringify(v) : v}`)
1695 .join(", ");
1696 const code = `${tlVar}.set(${JSON.stringify(selector)}, { ${props} }, ${position});`;
1697 const newStatement = parseScript(code).program.body[0];
1698 const anchor = findTimelineDeclarationPath(parsed.ast, tlVar);
1699 if (anchor) {
1700 anchor.insertAfter(newStatement);
1701 } else if (parsed.located.length > 0) {
1702 const firstTween = parsed.located[0]!.call;
1703 const stmtPath = findStatementPath(firstTween.path);
1704 if (stmtPath) stmtPath.insertBefore(newStatement);
1705 else parsed.ast.program.body.unshift(newStatement);
1706 } else {
1707 parsed.ast.program.body.push(newStatement);
1708 }
1709 return recast.print(parsed.ast).code;
1710}
1711
1712/** Marker on Studio-emitted pre-keyframe hold `set`s. `data` is a GSAP-reserved
1713 * config key (attached to the tween, never applied to the target), so it carries

Callers 2

splitAnimationsInScriptFunction · 0.85

Calls 5

parseGsapAstFunction · 0.85
findStatementPathFunction · 0.85
entriesMethod · 0.80
parseScriptFunction · 0.70

Tested by

no test coverage detected