( parsed: ParsedDocument, target: HfId, tween: GsapTweenSpec, )
| 1024 | |
| 1025 | // fallow-ignore-next-line complexity |
| 1026 | function 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 |
| 1068 | function handleSetGsapTween( |
no test coverage detected