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

Function handleAddGsapTween

packages/sdk/src/engine/mutate.ts:1026–1065  ·  view source on GitHub ↗
(
  parsed: ParsedDocument,
  target: HfId,
  tween: GsapTweenSpec,
)

Source from the content-addressed store, hash-verified

1024
1025// fallow-ignore-next-line complexity
1026function handleAddGsapTween(
1027 parsed: ParsedDocument,
1028 target: HfId,
1029 tween: GsapTweenSpec,
1030): MutationResult {
1031 const script = getGsapScript(parsed.document);
1032 if (!script) throw new Error("No GSAP script block found in the composition.");
1033
1034 const extras: Record<string, unknown> = {};
1035 if (tween.repeat !== undefined) extras.repeat = tween.repeat;
1036 if (tween.yoyo !== undefined) extras.yoyo = tween.yoyo;
1037 if (tween.stagger !== undefined) extras.stagger = tween.stagger;
1038
1039 // A fromTo's destination may arrive as either `toProperties` or `properties`
1040 // (the Studio add path sets `properties`). Fall back the same way for every
1041 // method — the old fromTo-only branch read `toProperties` alone and wrote an
1042 // empty to-vars object, so fromTo animations added via cutover animated to {}.
1043 const toProps = (tween.toProperties ?? tween.properties ?? {}) as Record<string, number | string>;
1044
1045 // Scoped ids like "hf-host/hf-leaf" must use the bare leaf id in the GSAP
1046 // selector — only the leaf part is written as data-hf-id on the DOM element.
1047 const bareTarget = target.includes("/") ? (target.split("/").at(-1) ?? target) : target;
1048 const animation: Omit<GsapAnimation, "id"> = {
1049 targetSelector: gsapTargetSelector(parsed.document, bareTarget),
1050 method: tween.method,
1051 position: tween.position ?? 0,
1052 ...(tween.duration !== undefined ? { duration: tween.duration } : {}),
1053 ...(tween.ease ? { ease: tween.ease } : {}),
1054 properties: toProps,
1055 ...(tween.fromProperties
1056 ? { fromProperties: tween.fromProperties as Record<string, number | string> }
1057 : {}),
1058 ...(Object.keys(extras).length > 0 ? { extras } : {}),
1059 };
1060
1061 const { script: newScript, id: animationId } = addAnimationToScript(script, animation);
1062 if (!animationId) return EMPTY;
1063 setGsapScript(parsed.document, newScript);
1064 return { ...gsapScriptChange(script, newScript), meta: { animationId } };
1065}
1066
1067// fallow-ignore-next-line complexity
1068function handleSetGsapTween(

Callers 1

applyGsapOpFunction · 0.85

Calls 5

getGsapScriptFunction · 0.85
gsapTargetSelectorFunction · 0.85
setGsapScriptFunction · 0.85
gsapScriptChangeFunction · 0.85
addAnimationToScriptFunction · 0.50

Tested by

no test coverage detected