@hyperframes/parsers 0.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/dist/gsapConstants.d.ts +14 -0
- package/dist/gsapConstants.js +107 -0
- package/dist/gsapConstants.js.map +1 -0
- package/dist/gsapParser.d.ts +157 -0
- package/dist/gsapParser.js +2431 -0
- package/dist/gsapParser.js.map +1 -0
- package/dist/gsapParserAcorn.d.ts +51 -0
- package/dist/gsapParserAcorn.js +1294 -0
- package/dist/gsapParserAcorn.js.map +1 -0
- package/dist/gsapParserExports.d.ts +5 -0
- package/dist/gsapParserExports.js +1558 -0
- package/dist/gsapParserExports.js.map +1 -0
- package/dist/gsapSerialize-B_JRTCeV.d.ts +535 -0
- package/dist/gsapWriterAcorn.d.ts +93 -0
- package/dist/gsapWriterAcorn.js +2369 -0
- package/dist/gsapWriterAcorn.js.map +1 -0
- package/dist/hfIds.d.ts +18 -0
- package/dist/hfIds.js +74 -0
- package/dist/hfIds.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +2500 -0
- package/dist/index.js.map +1 -0
- package/dist/springEase.d.ts +30 -0
- package/dist/springEase.js +44 -0
- package/dist/springEase.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gsapConstants.ts","../src/gsapSerialize.ts","../src/gsapParser.ts","../src/springEase.ts","../src/gsapParserAcorn.ts","../src/gsapInline.ts"],"sourcesContent":["/**\n * GSAP property and ease constants.\n *\n * Extracted into a standalone module so browser code can import them\n * without pulling in gsapParser (which depends on recast / @babel/parser).\n */\n\nexport const SUPPORTED_PROPS = [\n // 2D Transforms\n \"x\",\n \"y\",\n \"scale\",\n \"scaleX\",\n \"scaleY\",\n \"rotation\",\n \"skewX\",\n \"skewY\",\n // 3D Transforms\n \"z\",\n \"rotationX\",\n \"rotationY\",\n \"rotationZ\",\n \"perspective\",\n \"transformPerspective\",\n \"transformOrigin\",\n // Visibility\n \"opacity\",\n \"visibility\",\n \"autoAlpha\",\n // Dimensions\n \"width\",\n \"height\",\n // Colors\n \"color\",\n \"backgroundColor\",\n \"borderColor\",\n // Box model\n \"borderRadius\",\n // Typography\n \"fontSize\",\n \"letterSpacing\",\n // Filter & Clipping\n \"filter\",\n \"clipPath\",\n // DOM content (number counters, text roll-ups)\n \"innerText\",\n];\n\n// ── Property Groups ─────────────────────────────────────────────────────────\n// Each group maps to an independent GSAP tween so editing one property\n// (e.g. drag → x/y) never contaminates another (e.g. scale, rotation).\n\nexport type PropertyGroupName = \"position\" | \"scale\" | \"size\" | \"rotation\" | \"visual\" | \"other\";\n\nexport const PROPERTY_GROUPS: Record<PropertyGroupName, ReadonlySet<string>> = {\n position: new Set([\"x\", \"y\", \"xPercent\", \"yPercent\"]),\n scale: new Set([\"scale\", \"scaleX\", \"scaleY\"]),\n size: new Set([\"width\", \"height\"]),\n rotation: new Set([\"rotation\", \"skewX\", \"skewY\"]),\n visual: new Set([\"opacity\", \"autoAlpha\"]),\n other: new Set<string>(),\n};\n\nconst PROP_TO_GROUP = new Map<string, PropertyGroupName>();\nfor (const [group, props] of Object.entries(PROPERTY_GROUPS) as [\n PropertyGroupName,\n ReadonlySet<string>,\n][]) {\n for (const p of props) PROP_TO_GROUP.set(p, group);\n}\n\nexport function classifyPropertyGroup(prop: string): PropertyGroupName {\n return PROP_TO_GROUP.get(prop) ?? \"other\";\n}\n\nexport function classifyTweenPropertyGroup(\n properties: Record<string, unknown>,\n): PropertyGroupName | undefined {\n const groups = new Set<PropertyGroupName>();\n for (const key of Object.keys(properties)) {\n // transformOrigin is a modifier; `_auto` is Studio's internal endpoint marker;\n // `data` is GSAP-reserved (carries the Studio hold-set tag). None is an animated\n // property, so none should affect the group.\n if (key === \"transformOrigin\" || key === \"_auto\" || key === \"data\") continue;\n const g = classifyPropertyGroup(key);\n groups.add(g);\n }\n if (groups.size === 1) return groups.values().next().value;\n return undefined;\n}\n\nexport const SUPPORTED_EASES = [\n \"none\",\n \"power1.in\",\n \"power1.out\",\n \"power1.inOut\",\n \"power2.in\",\n \"power2.out\",\n \"power2.inOut\",\n \"power3.in\",\n \"power3.out\",\n \"power3.inOut\",\n \"power4.in\",\n \"power4.out\",\n \"power4.inOut\",\n \"back.in\",\n \"back.out\",\n \"back.inOut\",\n \"elastic.in\",\n \"elastic.out\",\n \"elastic.inOut\",\n \"bounce.in\",\n \"bounce.out\",\n \"bounce.inOut\",\n \"expo.in\",\n \"expo.out\",\n \"expo.inOut\",\n \"spring-gentle\",\n \"spring-bouncy\",\n \"spring-stiff\",\n \"spring-wobbly\",\n \"spring-heavy\",\n \"steps(1)\",\n];\n","/**\n * Recast-free GSAP helpers: serialization, keyframe<->animation conversion,\n * validation, and shared types.\n *\n * This module MUST NOT import recast / @babel/parser. It is part of the\n * isomorphic core layer that the barrel and browser code depend on. AST\n * parsing of GSAP source lives in the Node-only `./gsapParser` module.\n */\nimport type { Keyframe, KeyframeProperties, ValidationResult } from \"./types.js\";\nimport type { PropertyGroupName } from \"./gsapConstants\";\n\nexport type GsapMethod = \"set\" | \"to\" | \"from\" | \"fromTo\";\n\n/** How a tween was constructed in source — drives display classification and editability. */\nexport type GsapProvenanceKind = \"literal\" | \"helper\" | \"loop\" | \"runtime-dynamic\";\n\n/**\n * Origin of a parsed tween. `literal` tweens map 1:1 to a source call and edit\n * directly; `helper`/`loop` tweens are expanded from a reused construct (unroll\n * to edit); `runtime-dynamic` tweens come from live introspection (override to\n * edit). Absent provenance is treated as `literal`.\n */\nexport interface GsapProvenance {\n kind: GsapProvenanceKind;\n /** Helper function name (kind === \"helper\"). */\n fn?: string;\n /** 1-based ordinal of the originating call site / loop construct in source order. */\n callSite?: number;\n /** 0-based iteration index (kind === \"loop\"). */\n iteration?: number;\n /** Source offset [start, end] of the originating call/loop, when known. */\n sourceRange?: [number, number];\n}\n\n/** How a tween's keyframes can be edited, derived from its provenance. */\nexport type KeyframeEditability = \"direct\" | \"unroll\" | \"source\";\n\n/**\n * Map provenance to an editing strategy:\n * - `direct` — literal tween, maps 1:1 to source; edit in place.\n * - `unroll` — helper/loop expansion; unroll to literal tweens, then edit.\n * - `source` — runtime-dynamic value; not statically editable, edit the code.\n */\nexport function editabilityForProvenance(provenance?: GsapProvenance): KeyframeEditability {\n if (!provenance || provenance.kind === \"literal\") return \"direct\";\n if (provenance.kind === \"runtime-dynamic\") return \"source\";\n return \"unroll\";\n}\n\nexport interface GsapAnimation {\n id: string;\n targetSelector: string;\n method: GsapMethod;\n position: number | string;\n properties: Record<string, number | string>;\n fromProperties?: Record<string, number | string>;\n duration?: number;\n ease?: string;\n /** Non-editable GSAP config (stagger, yoyo, repeat, etc.) preserved for round-trips. */\n extras?: Record<string, unknown>;\n /** Native GSAP keyframes data — present when the tween uses keyframes: { ... }. */\n keyframes?: GsapKeyframesData;\n /** Arc motion path config — present when the tween uses motionPath for curved position interpolation. */\n arcPath?: ArcPathConfig;\n /** True when the tween has a `keyframes` property that couldn't be statically resolved (dynamic). */\n hasUnresolvedKeyframes?: boolean;\n /** True when the tween's target selector couldn't be statically resolved (dynamic). */\n hasUnresolvedSelector?: boolean;\n /** Absolute start time computed by walking the timeline chain (handles +=, -=, <, >, labels). */\n resolvedStart?: number;\n /** True when no position arg was authored — the tween is sequentially placed by GSAP. */\n implicitPosition?: boolean;\n /** Which property group this tween belongs to (position, scale, size, rotation, visual, other).\n * Undefined for legacy mixed tweens that bundle multiple groups. */\n propertyGroup?: PropertyGroupName;\n /** True for a base `gsap.set(...)` (a static hold that runs immediately, OFF the\n * timeline) rather than `tl.set(...)`. Carries no timeline position and shows no\n * keyframe marker — used to persist a static value (e.g. a 3D transform) without\n * introducing a 0% keyframe. */\n global?: boolean;\n /** How this tween was constructed in source. Absent ⇒ literal. */\n provenance?: GsapProvenance;\n}\n\nexport interface GsapPercentageKeyframe {\n percentage: number;\n properties: Record<string, number | string>;\n ease?: string;\n}\n\nexport type GsapKeyframeFormat = \"percentage\" | \"object-array\" | \"simple-array\";\n\nexport interface GsapKeyframesData {\n format: GsapKeyframeFormat;\n keyframes: GsapPercentageKeyframe[];\n ease?: string;\n easeEach?: string;\n}\n\nexport interface ArcPathSegment {\n curviness: number;\n cp1?: { x: number; y: number };\n cp2?: { x: number; y: number };\n}\n\nexport interface ArcPathConfig {\n enabled: boolean;\n autoRotate: boolean | number;\n segments: ArcPathSegment[];\n}\n\nexport interface MotionPathShape {\n arcPath: ArcPathConfig;\n waypoints: Array<{ x: number; y: number }>;\n}\n\n/**\n * Build arcPath segments + waypoints from resolved path coordinates. Shared by\n * the AST parser (coords from literal nodes) and the runtime scanner (coords\n * from a live `vars.motionPath`), so both produce identical arc config.\n */\nexport function buildArcPath(\n coords: Array<{ x: number; y: number }>,\n curviness: number,\n autoRotate: boolean | number,\n isCubic: boolean,\n): MotionPathShape | undefined {\n const first = coords[0];\n if (coords.length < 2 || !first) return undefined;\n const segments: ArcPathSegment[] = [];\n let waypoints: Array<{ x: number; y: number }>;\n if (isCubic && coords.length >= 4) {\n // coords are [anchor, cp1, cp2, anchor, cp1, cp2, anchor, ...].\n waypoints = [first];\n for (let i = 1; i + 2 < coords.length; i += 3) {\n const cp1 = coords[i];\n const cp2 = coords[i + 1];\n const anchor = coords[i + 2];\n if (!cp1 || !cp2 || !anchor) continue;\n waypoints.push(anchor);\n segments.push({ curviness, cp1, cp2 });\n }\n } else {\n waypoints = coords;\n for (let i = 0; i < waypoints.length - 1; i++) segments.push({ curviness });\n }\n return { arcPath: { enabled: true, autoRotate, segments }, waypoints };\n}\n\nexport interface ParsedGsap {\n animations: GsapAnimation[];\n timelineVar: string;\n preamble: string;\n postamble: string;\n multipleTimelines?: boolean;\n unsupportedTimelinePattern?: boolean;\n}\n\nexport { SUPPORTED_PROPS, SUPPORTED_EASES } from \"./gsapConstants\";\n\n// ── Split-animation types (used by gsapWriterAcorn) ─────────────────────────\n\nexport interface SplitAnimationsOptions {\n originalId: string;\n newId: string;\n splitTime: number;\n elementStart: number;\n elementDuration: number;\n}\n\nexport interface SplitAnimationsResult {\n script: string;\n /** Non-ID-selector animations that the engine cannot safely retarget. */\n skippedSelectors: string[];\n}\n\n// ── Serialization ───────────────────────────────────────────────────────────\n\nexport function serializeGsapAnimations(\n animations: GsapAnimation[],\n timelineVar = \"tl\",\n options?: { includeMediaSync?: boolean; preamble?: string; postamble?: string },\n): string {\n const sorted = [...animations].sort((a, b) => {\n const aNum =\n a.resolvedStart ?? (typeof a.position === \"number\" ? a.position : Number.MAX_SAFE_INTEGER);\n const bNum =\n b.resolvedStart ?? (typeof b.position === \"number\" ? b.position : Number.MAX_SAFE_INTEGER);\n return aNum - bNum;\n });\n // fallow-ignore-next-line complexity\n const lines = sorted.map((anim) => {\n const selector = `\"${anim.targetSelector}\"`;\n const props: Record<string, number | string> = { ...anim.properties };\n if (anim.duration !== undefined) props.duration = anim.duration;\n if (anim.ease) props.ease = anim.ease;\n let propsStr = serializeObject(props);\n if (anim.extras && Object.keys(anim.extras).length > 0) {\n const extrasStr = serializeExtras(anim.extras);\n if (Object.keys(props).length === 0) {\n propsStr = `{ ${extrasStr} }`;\n } else {\n // Insert extras before the closing brace\n propsStr = propsStr.slice(0, -2) + `, ${extrasStr} }`;\n }\n }\n const posStr = typeof anim.position === \"string\" ? `\"${anim.position}\"` : anim.position;\n switch (anim.method) {\n case \"set\":\n // A global set is a base `gsap.set` — off the timeline, no position arg.\n return anim.global\n ? ` gsap.set(${selector}, ${propsStr});`\n : ` ${timelineVar}.set(${selector}, ${propsStr}, ${posStr});`;\n case \"to\":\n return ` ${timelineVar}.to(${selector}, ${propsStr}, ${posStr});`;\n case \"from\":\n return ` ${timelineVar}.from(${selector}, ${propsStr}, ${posStr});`;\n case \"fromTo\": {\n const fromStr = serializeObject(anim.fromProperties || {});\n return ` ${timelineVar}.fromTo(${selector}, ${fromStr}, ${propsStr}, ${posStr});`;\n }\n }\n });\n\n let mediaSync = \"\";\n if (options?.includeMediaSync) {\n mediaSync = `\n ${timelineVar}.eventCallback(\"onUpdate\", function() {\n const time = ${timelineVar}.time();\n document.querySelectorAll(\"video[data-start], audio[data-start]\").forEach(function(media) {\n const start = parseFloat(media.dataset.start);\n const end = parseFloat(media.dataset.end) || Infinity;\n const mediaTime = time - start;\n if (time >= start && time < end) {\n if (Math.abs(media.currentTime - mediaTime) > 0.1) {\n media.currentTime = mediaTime;\n }\n if (media.paused && !${timelineVar}.paused()) {\n media.play().catch(function() {});\n }\n } else if (!media.paused) {\n media.pause();\n }\n });\n });`;\n }\n\n const preamble = options?.preamble || `const ${timelineVar} = gsap.timeline({ paused: true });`;\n const postamble = options?.postamble ? `\\n ${options.postamble}` : \"\";\n\n return `\n ${preamble}\n${lines.join(\"\\n\")}${mediaSync}${postamble}\n `;\n}\n\nexport function serializeValue(value: unknown): string {\n if (typeof value === \"string\" && value.startsWith(\"__raw:\")) {\n return value.slice(6);\n }\n if (typeof value === \"string\") return JSON.stringify(value);\n return String(value);\n}\n\nexport function safeJsKey(key: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : JSON.stringify(key);\n}\n\nfunction serializeObject(obj: Record<string, number | string>): string {\n const entries = Object.entries(obj).map(([key, value]) => {\n return `${safeJsKey(key)}: ${serializeValue(value)}`;\n });\n return `{ ${entries.join(\", \")} }`;\n}\n\nfunction serializeExtras(extras: Record<string, unknown>): string {\n return Object.entries(extras)\n .map(([key, value]) => {\n return `${safeJsKey(key)}: ${serializeValue(value)}`;\n })\n .join(\", \");\n}\n\n// ── Element filtering ─────────────────────────────────────────────────────────\n\n/**\n * Filter animations to those targeting `#<elementId>` (id-only match). For the\n * studio panel's id-OR-selector matching, see `getAnimationsForElement` in\n * `useGsapTweenCache.ts` — distinct on purpose, hence the distinct name.\n */\nexport function getAnimationsForElementId(\n animations: GsapAnimation[],\n elementId: string,\n): GsapAnimation[] {\n const selector = `#${elementId}`;\n return animations.filter((a) => a.targetSelector === selector);\n}\n\n// ── Validation (regex-based, no AST needed) ─────────────────────────────────\n\nconst FORBIDDEN_GSAP_PATTERNS: Array<{ pattern: RegExp; message: string }> = [\n { pattern: /\\.call\\s*\\(/, message: \"call() method not allowed\" },\n { pattern: /\\.add\\s*\\(/, message: \"add() method not allowed\" },\n { pattern: /\\.addPause\\s*\\(/, message: \"addPause() method not allowed\" },\n { pattern: /gsap\\.registerEffect\\s*\\(/, message: \"registerEffect() not allowed\" },\n { pattern: /ScrollTrigger/, message: \"ScrollTrigger not allowed\" },\n { pattern: /onComplete\\s*:/, message: \"onComplete callback not allowed\" },\n { pattern: /onUpdate\\s*:/, message: \"onUpdate callback not allowed\" },\n { pattern: /onStart\\s*:/, message: \"onStart callback not allowed\" },\n { pattern: /onRepeat\\s*:/, message: \"onRepeat callback not allowed\" },\n { pattern: /onReverseComplete\\s*:/, message: \"onReverseComplete callback not allowed\" },\n { pattern: /repeat\\s*:\\s*-1/, message: \"Infinite repeat (repeat: -1) not allowed\" },\n { pattern: /Math\\.random\\s*\\(/, message: \"Random values (Math.random) not allowed\" },\n { pattern: /Date\\.now\\s*\\(/, message: \"Date-dependent values (Date.now) not allowed\" },\n { pattern: /new\\s+Date\\s*\\(/, message: \"Date constructor not allowed\" },\n { pattern: /setTimeout\\s*\\(/, message: \"setTimeout not allowed\" },\n { pattern: /setInterval\\s*\\(/, message: \"setInterval not allowed\" },\n { pattern: /requestAnimationFrame\\s*\\(/, message: \"requestAnimationFrame not allowed\" },\n];\n\nexport function validateCompositionGsap(script: string): ValidationResult {\n const errors: string[] = [];\n const warnings: string[] = [];\n for (const { pattern, message } of FORBIDDEN_GSAP_PATTERNS) {\n if (pattern.test(script)) errors.push(message);\n }\n if (/yoyo\\s*:\\s*true/.test(script)) {\n warnings.push(\"yoyo animations may behave unexpectedly when scrubbing\");\n }\n if (/stagger\\s*:/.test(script)) {\n warnings.push(\"stagger animations may not serialize correctly\");\n }\n return { valid: errors.length === 0, errors, warnings };\n}\n\n// ── Keyframe Conversion Helpers ─────────────────────────────────────────────\n\nexport function keyframesToGsapAnimations(\n elementId: string,\n keyframes: Keyframe[],\n elementStartTime: number,\n base?: { x?: number; y?: number; scale?: number },\n): GsapAnimation[] {\n const sorted = [...keyframes].sort((a, b) => a.time - b.time);\n const animations: GsapAnimation[] = [];\n const baseX = base?.x ?? 0;\n const baseY = base?.y ?? 0;\n const baseScale = base?.scale ?? 1;\n\n // fallow-ignore-next-line complexity\n sorted.forEach((kf, i) => {\n const absoluteTime = elementStartTime + kf.time;\n const isFirst = i === 0;\n const prevKf = i > 0 ? sorted[i - 1] : null;\n const duration = prevKf ? kf.time - prevKf.time : undefined;\n const position = prevKf ? elementStartTime + prevKf.time : absoluteTime;\n\n const properties: Record<string, number | string> = {};\n for (const [key, value] of Object.entries(kf.properties)) {\n if (typeof value !== \"number\") continue;\n if (key === \"x\") properties.x = baseX + value;\n else if (key === \"y\") properties.y = baseY + value;\n else if (key === \"scale\") properties.scale = baseScale * value;\n else properties[key] = value;\n }\n\n animations.push({\n id: `${elementId}-kf-${kf.id}`,\n targetSelector: `#${elementId}`,\n method: isFirst ? \"set\" : \"to\",\n position,\n properties,\n duration: isFirst ? undefined : duration,\n ease: kf.ease,\n });\n });\n\n return animations;\n}\n\nexport function gsapAnimationsToKeyframes(\n animations: GsapAnimation[],\n elementStartTime: number,\n options?: {\n baseX?: number;\n baseY?: number;\n baseScale?: number;\n clampTimeToZero?: boolean;\n skipBaseSet?: boolean;\n },\n): Keyframe[] {\n const validMethods: GsapMethod[] = [\"set\", \"to\", \"from\", \"fromTo\"];\n const baseX = options?.baseX ?? 0;\n const baseY = options?.baseY ?? 0;\n const baseScale = options?.baseScale ?? 1;\n const clampTimeToZero = options?.clampTimeToZero ?? true;\n const skipBaseSet = options?.skipBaseSet ?? false;\n const baseTimeEpsilon = 0.001;\n const baseValueEpsilon = 0.00001;\n\n return (\n animations\n .filter(\n (a): a is GsapAnimation & { position: number } =>\n validMethods.includes(a.method) && typeof a.position === \"number\",\n )\n // fallow-ignore-next-line complexity\n .map((a) => {\n const relativeTimeRaw = a.position - elementStartTime;\n const time = clampTimeToZero ? Math.max(0, relativeTimeRaw) : relativeTimeRaw;\n\n const properties: Partial<KeyframeProperties> = {};\n for (const [key, value] of Object.entries(a.properties)) {\n if (typeof value !== \"number\") continue;\n if (key === \"x\") properties.x = value - baseX;\n else if (key === \"y\") properties.y = value - baseY;\n else if (key === \"scale\") {\n properties.scale = baseScale !== 0 ? value / baseScale : value;\n } else {\n (properties as Record<string, number>)[key] = value;\n }\n }\n\n if (\n skipBaseSet &&\n a.method === \"set\" &&\n time < baseTimeEpsilon &&\n Object.values(properties).every(\n (v) => typeof v === \"number\" && Math.abs(v) < baseValueEpsilon,\n )\n ) {\n return null;\n }\n\n return {\n id: a.id.replace(/^.*-kf-/, \"\"),\n time,\n properties: properties as KeyframeProperties,\n ease: a.ease,\n };\n })\n .filter((kf): kf is NonNullable<typeof kf> => kf !== null)\n );\n}\n\n// ── Keyframe-conversion transforms (pure; shared by recast + acorn writers) ────\n\n/**\n * CSS identity values for properties whose \"rest\" state isn't 0 — used to\n * synthesize the missing endpoint when converting a flat tween to keyframes.\n */\nconst CSS_IDENTITY: Record<string, number> = {\n opacity: 1,\n autoAlpha: 1,\n scale: 1,\n scaleX: 1,\n scaleY: 1,\n};\n\nfunction cssIdentityValue(prop: string): number {\n return CSS_IDENTITY[prop] ?? 0;\n}\n\n/** Build the identity-endpoint map for a flat tween's properties. */\nfunction buildIdentityMap(props: Record<string, number | string>): Record<string, number | string> {\n const identity: Record<string, number | string> = {};\n for (const [key, val] of Object.entries(props)) {\n if (val != null) identity[key] = typeof val === \"number\" ? cssIdentityValue(key) : val;\n }\n return identity;\n}\n\n/**\n * Resolve the 0% (from) and 100% (to) property maps for a tween being\n * converted to percentage keyframes.\n *\n * @param resolvedFromValues — Despite the \"from\" in the name (historical), these\n * are runtime-captured DOM values that override the conversion endpoint:\n * - For to(): overrides fromProps (the 0% state / where the element is now).\n * - For from(): overrides toProps (the 100% state / where the element rests).\n * - For fromTo(): merges into toProps (the 100% endpoint the user is editing).\n */\nexport function resolveConversionProps(\n anim: GsapAnimation,\n resolvedFromValues?: Record<string, number | string>,\n): { fromProps: Record<string, number | string>; toProps: Record<string, number | string> } {\n if (anim.method === \"set\") {\n // A static hold becomes a keyframed `to` whose 0% and 100% both start at the\n // set's value — the visual is unchanged until the user edits a keyframe to\n // animate it. (The caller flips the call from `set` to `to` + adds a duration.)\n return { fromProps: { ...anim.properties }, toProps: { ...anim.properties } };\n }\n if (anim.method === \"to\") {\n const identity = buildIdentityMap(anim.properties);\n const fromProps = resolvedFromValues ? { ...identity, ...resolvedFromValues } : identity;\n return { fromProps, toProps: { ...anim.properties } };\n }\n if (anim.method === \"from\") {\n const identity = buildIdentityMap(anim.properties);\n const toProps = resolvedFromValues ? { ...identity, ...resolvedFromValues } : identity;\n return { fromProps: { ...anim.properties }, toProps };\n }\n // fromTo(fromVars, toVars): anim.fromProperties = fromVars (0% state),\n // anim.properties = toVars (100% state). resolvedFromValues contains the\n // current DOM position from a drag — it represents the NEW destination, so\n // it merges into toProps (the 100% endpoint the user is editing), NOT into\n // fromProps. This is intentional and not inverted.\n const toProps = resolvedFromValues\n ? { ...anim.properties, ...resolvedFromValues }\n : { ...anim.properties };\n return { fromProps: { ...(anim.fromProperties ?? {}) }, toProps };\n}\n\n// ── Arc path serialization helpers (shared by recast + acorn writers) ─────────\n\nfunction numericXY(props: Record<string, number | string>): { x: number; y: number } | null {\n const vx = props.x;\n const vy = props.y;\n return typeof vx === \"number\" && typeof vy === \"number\" ? { x: vx, y: vy } : null;\n}\n\nexport function extractArcWaypoints(anim: GsapAnimation): Array<{ x: number; y: number }> {\n const keyframeWps = (anim.keyframes?.keyframes ?? [])\n .map((kf) => numericXY(kf.properties))\n .filter((pt): pt is { x: number; y: number } => pt !== null);\n if (keyframeWps.length >= 2) return keyframeWps;\n const propX = anim.properties.x;\n const propY = anim.properties.y;\n if (typeof propX !== \"number\" && typeof propY !== \"number\") return keyframeWps;\n const destX = typeof propX === \"number\" ? propX : 0;\n const destY = typeof propY === \"number\" ? propY : 0;\n return [\n { x: 0, y: 0 },\n { x: destX, y: destY },\n ];\n}\n\nfunction autoRotateSuffix(autoRotate: boolean | number): string {\n if (autoRotate === true) return \", autoRotate: true\";\n if (typeof autoRotate === \"number\") return `, autoRotate: ${autoRotate}`;\n return \"\";\n}\n\nfunction cubicControlPoints(\n seg: ArcPathSegment,\n wp: { x: number; y: number },\n nextWp: { x: number; y: number },\n): string[] {\n if (seg.cp1 && seg.cp2) {\n return [`{x: ${seg.cp1.x}, y: ${seg.cp1.y}}`, `{x: ${seg.cp2.x}, y: ${seg.cp2.y}}`];\n }\n const dx = nextWp.x - wp.x;\n const dy = nextWp.y - wp.y;\n const c = seg.curviness ?? 1;\n return [\n `{x: ${wp.x + dx * 0.33}, y: ${wp.y + dy * 0.33 - c * Math.abs(dx) * 0.25}}`,\n `{x: ${wp.x + dx * 0.66}, y: ${wp.y + dy * 0.66 - c * Math.abs(dx) * 0.25}}`,\n ];\n}\n\nfunction buildCubicPathEntries(\n waypoints: Array<{ x: number; y: number }>,\n segments: ArcPathSegment[],\n): string[] {\n const first = waypoints[0];\n if (!first) return [];\n const entries = [`{x: ${first.x}, y: ${first.y}}`];\n for (let i = 0; i < segments.length; i++) {\n const seg = segments[i];\n const wp = waypoints[i];\n const nextWp = waypoints[i + 1];\n if (!seg || !wp || !nextWp) continue;\n entries.push(...cubicControlPoints(seg, wp, nextWp));\n entries.push(`{x: ${nextWp.x}, y: ${nextWp.y}}`);\n }\n return entries;\n}\n\nexport function buildMotionPathObjectCode(config: {\n waypoints: Array<{ x: number; y: number }>;\n segments: ArcPathSegment[];\n autoRotate: boolean | number;\n}): string {\n const { waypoints, segments, autoRotate } = config;\n const arSuffix = autoRotateSuffix(autoRotate);\n // GSAP's simple `path` array supports only ONE scalar `curviness` for the whole\n // path, so per-segment curviness can only be expressed in the cubic form (each\n // segment's curviness baked into its control points). Emit cubic when segments\n // carry explicit control points OR when their curviness values differ — the\n // simple branch would otherwise serialize only segments[0].curviness and drop\n // every other segment's curve.\n const hasExplicitCp = segments.some((s) => s.cp1 && s.cp2);\n const curvinessVaries = segments.some(\n (s) => (s.curviness ?? 1) !== (segments[0]?.curviness ?? 1),\n );\n if ((hasExplicitCp || curvinessVaries) && waypoints.length >= 2) {\n const pathStr = buildCubicPathEntries(waypoints, segments).join(\", \");\n return `{ path: [${pathStr}], type: \"cubic\"${arSuffix} }`;\n }\n const pathEntries = waypoints.map((wp) => `{x: ${wp.x}, y: ${wp.y}}`);\n const curviness = segments[0]?.curviness ?? 1;\n const curvPart = curviness !== 1 ? `, curviness: ${curviness}` : \"\";\n return `{ path: [${pathEntries.join(\", \")}]${curvPart}${arSuffix} }`;\n}\n","/**\n * Node-only GSAP AST parser. Depends on recast / @babel/parser, which compile\n * to CommonJS that calls `require(\"fs\")` — so this module must never be in the\n * static import graph of isomorphic/browser code. It is reachable only via the\n * `@hyperframes/core/gsap-parser` subpath (studio-api mutations + the linter).\n *\n * Recast-free helpers (serialization, keyframe conversion, validation, types)\n * live in `./gsapSerialize` and are re-exported here so this subpath exposes the\n * full surface for tests and server-side consumers.\n */\nimport * as recast from \"recast\";\nimport { parse as babelParse } from \"@babel/parser\";\nimport {\n type ArcPathConfig,\n type ArcPathSegment,\n type GsapAnimation,\n type GsapKeyframesData,\n type GsapMethod,\n type GsapPercentageKeyframe,\n type ParsedGsap,\n serializeValue as valueToCode,\n safeJsKey as safeKey,\n resolveConversionProps,\n} from \"./gsapSerialize\";\n\nexport type {\n ArcPathConfig,\n ArcPathSegment,\n GsapAnimation,\n GsapMethod,\n ParsedGsap,\n GsapKeyframesData,\n GsapPercentageKeyframe,\n GsapKeyframeFormat,\n} from \"./gsapSerialize\";\nexport {\n serializeGsapAnimations,\n getAnimationsForElementId,\n validateCompositionGsap,\n keyframesToGsapAnimations,\n gsapAnimationsToKeyframes,\n SUPPORTED_PROPS,\n SUPPORTED_EASES,\n} from \"./gsapSerialize\";\nexport type { PropertyGroupName } from \"./gsapConstants\";\nexport {\n PROPERTY_GROUPS,\n classifyPropertyGroup,\n classifyTweenPropertyGroup,\n} from \"./gsapConstants\";\nimport { classifyPropertyGroup, classifyTweenPropertyGroup } from \"./gsapConstants\";\nimport type { PropertyGroupName } from \"./gsapConstants\";\nexport { generateSpringEaseData, SPRING_PRESETS } from \"./springEase\";\nexport type { SpringPreset } from \"./springEase\";\n\nconst GSAP_METHODS = new Set<string>([\"set\", \"to\", \"from\", \"fromTo\"]);\n\n// ── Recast / Babel AST shape types ────────────────────────────────────────\n//\n// Recast's own typings are loose (`any` everywhere). These local shapes\n// capture the properties we actually access, giving us IDE navigation and\n// catch-at-write-time safety without depending on @babel/types at runtime.\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- recast AST nodes are inherently untyped\ninterface AstNode extends Record<string, any> {\n type: string;\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- recast visitor paths are inherently untyped\ninterface AstPath extends Record<string, any> {\n node: AstNode;\n}\n\n// ── Recast AST Helpers ──────────────────────────────────────────────────────\n\ntype ScopeBindings = ReadonlyMap<string, number | string | boolean>;\n\nfunction parseScript(script: string) {\n return recast.parse(script, {\n parser: {\n parse(source: string) {\n return babelParse(source, { sourceType: \"script\", plugins: [], tokens: true });\n },\n },\n });\n}\n\nfunction collectScopeBindings(ast: AstNode): ScopeBindings {\n const bindings = new Map<string, number | string | boolean>();\n recast.types.visit(ast, {\n visitVariableDeclarator(path: AstPath) {\n const name = path.node.id?.name;\n const init = path.node.init;\n if (name && init) {\n const val = resolveNode(init, bindings);\n if (val !== undefined) bindings.set(name, val);\n }\n this.traverse(path);\n },\n });\n return bindings;\n}\n\nfunction resolveNode(\n node: AstNode | undefined,\n scope: ReadonlyMap<string, number | string | boolean>,\n): number | string | boolean | undefined {\n if (!node) return undefined;\n if (node.type === \"NumericLiteral\" || (node.type === \"Literal\" && typeof node.value === \"number\"))\n return node.value;\n if (node.type === \"StringLiteral\" || (node.type === \"Literal\" && typeof node.value === \"string\"))\n return node.value;\n if (\n node.type === \"BooleanLiteral\" ||\n (node.type === \"Literal\" && typeof node.value === \"boolean\")\n )\n return node.value;\n if (node.type === \"UnaryExpression\" && node.operator === \"-\" && node.argument) {\n const val = resolveNode(node.argument, scope);\n return typeof val === \"number\" ? -val : undefined;\n }\n if (node.type === \"BinaryExpression\") {\n const left = resolveNode(node.left, scope);\n const right = resolveNode(node.right, scope);\n if (typeof left === \"number\" && typeof right === \"number\") {\n switch (node.operator) {\n case \"+\":\n return left + right;\n case \"-\":\n return left - right;\n case \"*\":\n return left * right;\n case \"/\":\n return right !== 0 ? left / right : undefined;\n }\n }\n if (typeof left === \"string\" && node.operator === \"+\") return left + String(right ?? \"\");\n if (typeof right === \"string\" && node.operator === \"+\") return String(left ?? \"\") + right;\n }\n if (node.type === \"Identifier\" && scope.has(node.name)) {\n return scope.get(node.name);\n }\n if (node.type === \"TemplateLiteral\" && node.expressions?.length === 0) {\n return node.quasis?.[0]?.value?.cooked ?? undefined;\n }\n return undefined;\n}\n\nfunction extractLiteralValue(node: AstNode | undefined, scope: ScopeBindings): unknown {\n return resolveNode(node, scope);\n}\n\n// ── Element-target resolution ───────────────────────────────────────────────\n//\n// Real compositions target tweens through element variables resolved from the\n// DOM (`const kicker = root.querySelector(\".kicker\"); tl.to(kicker, …)`), arrays\n// of them (`tl.to([a, b], …)`), `gsap.utils.toArray(\".sel\")`, and per-element\n// loop variables (`items.forEach(el => tl.to(el, …))`) — not inline string\n// selectors. To make those tweens editable we resolve each target back to the\n// CSS selector(s) it addresses. Resolution is lexically scoped: the same\n// variable name can mean different elements in different IIFEs.\n\nconst QUERY_METHODS = new Set([\"querySelector\", \"querySelectorAll\"]);\nconst ITERATION_METHODS = new Set([\"forEach\", \"map\"]);\nconst SCOPE_NODE_TYPES = new Set([\n \"Program\",\n \"FunctionDeclaration\",\n \"FunctionExpression\",\n \"ArrowFunctionExpression\",\n]);\n\n/**\n * If `node` is a DOM lookup call — `x.querySelector(\".sel\")`,\n * `document.querySelectorAll(\".sel\")`, `document.getElementById(\"id\")`, or\n * `gsap.utils.toArray(\".sel\")` — return the CSS selector it resolves to.\n * `getElementById(\"id\")` maps to `#id`. Returns null for anything else.\n */\nfunction selectorFromQueryCall(node: AstNode, scope: ScopeBindings): string | null {\n if (node?.type !== \"CallExpression\") return null;\n const callee = node.callee;\n if (callee?.type !== \"MemberExpression\" || callee.property?.type !== \"Identifier\") return null;\n const method = callee.property.name;\n const argValue = resolveNode(node.arguments?.[0], scope);\n if (typeof argValue !== \"string\" || argValue.length === 0) return null;\n if (QUERY_METHODS.has(method) || method === \"toArray\") return argValue;\n if (method === \"getElementById\") return `#${argValue}`;\n return null;\n}\n\n/** The nearest enclosing function/program node — the binding scope of `path`. */\nfunction enclosingScopeNode(path: AstPath): AstNode | null {\n let p = path?.parentPath;\n while (p) {\n if (SCOPE_NODE_TYPES.has(p.node?.type)) return p.node;\n p = p.parentPath;\n }\n return null;\n}\n\n/** Scope nodes enclosing `path`, innermost first. */\nfunction scopeChainOf(path: AstPath): AstNode[] {\n const chain: AstNode[] = [];\n let p = path;\n while (p) {\n if (SCOPE_NODE_TYPES.has(p.node?.type)) chain.push(p.node);\n p = p.parentPath;\n }\n return chain;\n}\n\n/** Per-scope element bindings: scopeNode → (variable name → selector). */\ntype TargetBindings = Map<any, Map<string, string>>;\n\nfunction addBinding(\n bindings: TargetBindings,\n scopeNode: AstNode,\n name: string,\n selector: string,\n): void {\n let scoped = bindings.get(scopeNode);\n if (!scoped) {\n scoped = new Map();\n bindings.set(scopeNode, scoped);\n }\n if (!scoped.has(name)) scoped.set(name, selector);\n}\n\n/**\n * Build a lexically-scoped index of element variables → selector. Two passes:\n * (1) direct DOM-lookup assignments (`const x = root.querySelector(...)`), then\n * (2) iteration callback params (`coll.forEach(el => …)`), whose element type is\n * the collection's selector — resolved against the pass-1 bindings.\n */\nfunction collectTargetBindings(ast: AstNode, scope: ScopeBindings): TargetBindings {\n const bindings: TargetBindings = new Map();\n\n recast.types.visit(ast, {\n visitVariableDeclarator(path: AstPath) {\n const name = path.node.id?.name;\n const selector = selectorFromQueryCall(path.node.init, scope);\n const scopeNode = enclosingScopeNode(path);\n if (name && selector !== null && scopeNode) addBinding(bindings, scopeNode, name, selector);\n this.traverse(path);\n },\n visitAssignmentExpression(path: AstPath) {\n const left = path.node.left;\n const selector = selectorFromQueryCall(path.node.right, scope);\n const scopeNode = enclosingScopeNode(path);\n if (left?.type === \"Identifier\" && selector !== null && scopeNode) {\n addBinding(bindings, scopeNode, left.name, selector);\n }\n this.traverse(path);\n },\n });\n\n // Pass 2: forEach/map callback params take the collection's selector.\n recast.types.visit(ast, {\n visitCallExpression(path: AstPath) {\n const node = path.node;\n const callee = node.callee;\n if (\n callee?.type === \"MemberExpression\" &&\n callee.property?.type === \"Identifier\" &&\n ITERATION_METHODS.has(callee.property.name)\n ) {\n const collectionSelector = resolveCollectionSelector(callee.object, path, scope, bindings);\n const fn = node.arguments?.[0];\n const param = fn?.params?.[0];\n if (collectionSelector && param?.type === \"Identifier\" && isFunctionNode(fn)) {\n addBinding(bindings, fn, param.name, collectionSelector);\n }\n }\n this.traverse(path);\n },\n });\n\n return bindings;\n}\n\nfunction isFunctionNode(node: AstNode): boolean {\n return (\n node?.type === \"ArrowFunctionExpression\" ||\n node?.type === \"FunctionExpression\" ||\n node?.type === \"FunctionDeclaration\"\n );\n}\n\n/** Resolve the selector a `.forEach`/`.map` is iterating over (variable or inline call). */\nfunction resolveCollectionSelector(\n node: AstNode,\n callPath: AstPath,\n scope: ScopeBindings,\n bindings: TargetBindings,\n): string | null {\n if (node?.type === \"Identifier\") return lookupBinding(node.name, callPath, bindings);\n if (node?.type === \"CallExpression\") return selectorFromQueryCall(node, scope);\n return null;\n}\n\n/** Resolve a variable name to its selector using the lexical scope chain of `path`. */\nfunction lookupBinding(name: string, path: AstPath, bindings: TargetBindings): string | null {\n for (const scopeNode of scopeChainOf(path)) {\n const selector = bindings.get(scopeNode)?.get(name);\n if (selector !== undefined) return selector;\n }\n return null;\n}\n\n/**\n * Resolve a tween's first argument to a CSS selector. Handles inline string\n * literals, element variables (lexically scoped), arrays of elements (joined\n * into a CSS group selector), inline DOM lookup / `toArray` calls, and indexed\n * access (`items[i]`). Returns null when the target can't be resolved\n * statically (e.g. an object-target duration anchor `tl.to({ _: 0 }, …)`, or a\n * runtime-computed selector).\n */\nfunction resolveTargetSelector(\n node: AstNode,\n path: AstPath,\n scope: ScopeBindings,\n bindings: TargetBindings,\n): string | null {\n if (!node) return null;\n if (node.type === \"StringLiteral\" || node.type === \"Literal\") {\n return typeof node.value === \"string\" ? node.value : null;\n }\n if (node.type === \"Identifier\") {\n return lookupBinding(node.name, path, bindings);\n }\n if (node.type === \"CallExpression\") {\n return selectorFromQueryCall(node, scope);\n }\n if (node.type === \"ArrayExpression\") {\n const parts = node.elements\n .map((el: AstNode) => resolveTargetSelector(el, path, scope, bindings))\n .filter((s: string | null): s is string => typeof s === \"string\" && s.length > 0);\n return parts.length > 0 ? parts.join(\", \") : null;\n }\n if (node.type === \"MemberExpression\" && node.object?.type === \"Identifier\") {\n // `items[i]` — the element type is the collection's selector.\n return lookupBinding(node.object.name, path, bindings);\n }\n return null;\n}\n\nfunction objectExpressionToRecord(node: AstNode, scope: ScopeBindings): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n if (node?.type !== \"ObjectExpression\") return result;\n for (const prop of node.properties ?? []) {\n if (prop.type !== \"ObjectProperty\" && prop.type !== \"Property\") continue;\n const key = prop.key?.name ?? prop.key?.value;\n if (!key) continue;\n const resolved = resolveNode(prop.value, scope);\n if (resolved !== undefined) {\n result[key] = resolved;\n } else {\n // Preserve unresolvable values as raw source text so they survive round-trips\n result[key] = `__raw:${recast.print(prop.value).code}`;\n }\n }\n return result;\n}\n\n// ── Timeline Variable Detection ─────────────────────────────────────────────\n\nfunction isGsapTimelineCall(node: AstNode): boolean {\n return (\n node?.type === \"CallExpression\" &&\n node.callee?.type === \"MemberExpression\" &&\n node.callee.object?.name === \"gsap\" &&\n node.callee.property?.name === \"timeline\"\n );\n}\n\ninterface TimelineDefaults {\n ease?: string;\n duration?: number;\n}\n\ninterface TimelineDetection {\n timelineVar: string | null;\n timelineCount: number;\n defaults?: TimelineDefaults;\n}\n\nfunction extractTimelineDefaults(\n callNode: AstNode,\n scope: ScopeBindings,\n): TimelineDefaults | undefined {\n const arg = callNode.arguments?.[0];\n if (!arg || arg.type !== \"ObjectExpression\") return undefined;\n const defaultsProp = arg.properties?.find(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"defaults\",\n );\n if (!defaultsProp?.value || defaultsProp.value.type !== \"ObjectExpression\") return undefined;\n const record = objectExpressionToRecord(defaultsProp.value, scope);\n const result: TimelineDefaults = {};\n if (typeof record.ease === \"string\") result.ease = record.ease;\n if (typeof record.duration === \"number\") result.duration = record.duration;\n return Object.keys(result).length > 0 ? result : undefined;\n}\n\nfunction findTimelineVar(ast: AstNode, scope?: ScopeBindings): TimelineDetection {\n let timelineVar: string | null = null;\n let timelineCount = 0;\n let defaults: TimelineDefaults | undefined;\n const emptyScope: ScopeBindings = scope ?? new Map();\n recast.types.visit(ast, {\n visitVariableDeclarator(path: AstPath) {\n if (isGsapTimelineCall(path.node.init)) {\n timelineCount += 1;\n if (!timelineVar) {\n timelineVar = path.node.id?.name ?? null;\n defaults = extractTimelineDefaults(path.node.init, emptyScope);\n }\n }\n this.traverse(path);\n },\n visitAssignmentExpression(path: AstPath) {\n if (isGsapTimelineCall(path.node.right)) {\n timelineCount += 1;\n if (!timelineVar) {\n const left = path.node.left;\n if (left?.type === \"Identifier\") timelineVar = left.name;\n defaults = extractTimelineDefaults(path.node.right, emptyScope);\n }\n }\n this.traverse(path);\n },\n });\n return { timelineVar, timelineCount, defaults };\n}\n\n// ── Find All Tween Calls ────────────────────────────────────────────────────\n\ninterface TweenCallInfo {\n path: AstPath;\n node: AstNode;\n method: GsapMethod;\n selector: string;\n varsArg: AstNode;\n fromArg?: AstNode;\n positionArg?: AstNode;\n /** True for a base `gsap.set(...)` (off-timeline) rather than `tl.set(...)`. */\n global?: boolean;\n}\n\n/**\n * True when the member chain of `callNode.callee` is rooted at the timeline\n * variable — `tl.to(...)` and every link of a chain `tl.to(...).to(...)`.\n */\nfunction isTimelineRootedCall(callNode: AstNode, timelineVar: string): boolean {\n let obj = callNode.callee?.object;\n while (obj?.type === \"CallExpression\") {\n obj = obj.callee?.object;\n }\n return obj?.type === \"Identifier\" && obj.name === timelineVar;\n}\n\nfunction findAllTweenCalls(\n ast: AstNode,\n timelineVar: string,\n scope: ScopeBindings,\n targetBindings: TargetBindings,\n): TweenCallInfo[] {\n const results: TweenCallInfo[] = [];\n recast.types.visit(ast, {\n visitCallExpression(path: AstPath) {\n const node = path.node;\n const callee = node.callee;\n // A base `gsap.set(\"#sel\", props)` is an off-timeline static hold (no position,\n // no keyframe marker). Treat it as an editable `set` animation so a static\n // value (e.g. a 3D transform) round-trips and re-edits in place. Restricted to\n // a STRING-LITERAL selector: variable-target `gsap.set(el, ...)` holds stay\n // opaque surrounding source (editing them by selector would be ambiguous).\n const gsapSetArg = node.arguments?.[0];\n const isGlobalSet =\n callee?.type === \"MemberExpression\" &&\n callee.object?.type === \"Identifier\" &&\n callee.object.name === \"gsap\" &&\n callee.property?.type === \"Identifier\" &&\n callee.property.name === \"set\" &&\n (gsapSetArg?.type === \"StringLiteral\" ||\n (gsapSetArg?.type === \"Literal\" && typeof gsapSetArg.value === \"string\"));\n if (\n callee?.type === \"MemberExpression\" &&\n callee.property?.type === \"Identifier\" &&\n (isTimelineRootedCall(node, timelineVar) || isGlobalSet)\n ) {\n const method = callee.property.name;\n if (!GSAP_METHODS.has(method)) {\n this.traverse(path);\n return;\n }\n const args = node.arguments;\n if (args.length < 2) {\n this.traverse(path);\n return;\n }\n const selectorValue =\n resolveTargetSelector(args[0], path, scope, targetBindings) ?? \"__unresolved__\";\n\n if (method === \"fromTo\") {\n results.push({\n path,\n node,\n method: \"fromTo\",\n selector: selectorValue,\n fromArg: args[1],\n varsArg: args[2],\n positionArg: args[3],\n });\n } else {\n results.push({\n path,\n node,\n method: method as GsapMethod,\n selector: selectorValue,\n varsArg: args[1],\n positionArg: args[2],\n ...(isGlobalSet ? { global: true } : {}),\n });\n }\n }\n this.traverse(path);\n },\n });\n return results;\n}\n\n/** Keys that are stored on dedicated GsapAnimation fields (not in properties/extras). */\nconst BUILTIN_VAR_KEYS = new Set([\"duration\", \"ease\", \"delay\"]);\n\n/** Keys that are never preserved (callbacks / advanced patterns). */\nconst DROPPED_VAR_KEYS = new Set([\"onComplete\", \"onStart\", \"onUpdate\", \"onRepeat\"]);\n\n/** Keys that belong in `extras` — non-editable GSAP config that must survive round-trips. */\nconst EXTRAS_KEYS = new Set([\n \"stagger\",\n \"yoyo\",\n \"repeat\",\n \"repeatDelay\",\n \"snap\",\n \"overwrite\",\n \"immediateRender\",\n]);\n\n/**\n * Extract raw source text for a property in an ObjectExpression AST node.\n * Returns the printed source of the value node, suitable for verbatim re-emission.\n */\nfunction extractRawPropertySource(varsArgNode: AstNode, key: string): string | undefined {\n const node = findPropertyNode(varsArgNode, key);\n return node ? recast.print(node).code : undefined;\n}\n\n/** Find the raw AST node for a named property inside an ObjectExpression. */\nfunction findPropertyNode(varsArgNode: AstNode, key: string): AstNode | undefined {\n if (varsArgNode?.type !== \"ObjectExpression\") return undefined;\n for (const prop of varsArgNode.properties ?? []) {\n if (!isObjectProperty(prop)) continue;\n if (propKeyName(prop) === key) return prop.value;\n }\n return undefined;\n}\n\n// ── Native GSAP Keyframes Parsing ──────────────────────────────────────────\n\nconst PERCENTAGE_KEY_RE = /^(\\d+(?:\\.\\d+)?)%$/;\n\n/** Extract a string-valued ease or easeEach from an AST property node. */\nfunction tryResolveStringProp(propValue: AstNode, scope: ScopeBindings): string | undefined {\n const val = resolveNode(propValue, scope);\n return typeof val === \"string\" ? val : undefined;\n}\n\n/**\n * Parse a `keyframes` property value from a tween vars AST node into a\n * normalized `GsapKeyframesData` structure. Handles all three GSAP formats:\n * percentage objects, object arrays, and simple (property-array) objects.\n */\n// fallow-ignore-next-line complexity\nfunction parseKeyframesNode(\n node: AstNode | undefined,\n scope: ScopeBindings,\n): GsapKeyframesData | undefined {\n if (!node) return undefined;\n\n // ── Object array format: keyframes: [ { x: 0, duration: 0.5 }, ... ] ──\n if (node.type === \"ArrayExpression\") {\n return parseObjectArrayKeyframes(node, scope);\n }\n\n if (node.type !== \"ObjectExpression\") return undefined;\n\n // Distinguish percentage vs simple-array by inspecting property keys/values.\n const props = node.properties ?? [];\n let hasPercentageKey = false;\n let hasArrayValue = false;\n\n for (const prop of props) {\n if (prop.type !== \"ObjectProperty\" && prop.type !== \"Property\") continue;\n const key = prop.key?.value ?? prop.key?.name;\n if (typeof key === \"string\" && PERCENTAGE_KEY_RE.test(key)) {\n hasPercentageKey = true;\n break;\n }\n if (prop.value?.type === \"ArrayExpression\") {\n hasArrayValue = true;\n }\n }\n\n if (hasPercentageKey) return parsePercentageKeyframes(node, scope);\n if (hasArrayValue) return parseSimpleArrayKeyframes(node, scope);\n\n return undefined;\n}\n\n// fallow-ignore-next-line complexity\nfunction parsePercentageKeyframes(node: AstNode, scope: ScopeBindings): GsapKeyframesData {\n const keyframes: GsapPercentageKeyframe[] = [];\n let ease: string | undefined;\n let easeEach: string | undefined;\n\n for (const prop of node.properties ?? []) {\n if (prop.type !== \"ObjectProperty\" && prop.type !== \"Property\") continue;\n const key = prop.key?.value ?? prop.key?.name;\n if (typeof key !== \"string\") continue;\n\n const pctMatch = PERCENTAGE_KEY_RE.exec(key);\n if (pctMatch) {\n const percentage = Number.parseFloat(pctMatch[1]!);\n const record = objectExpressionToRecord(prop.value, scope);\n const properties: Record<string, number | string> = {};\n let kfEase: string | undefined;\n for (const [k, v] of Object.entries(record)) {\n if (k === \"ease\" && typeof v === \"string\") {\n kfEase = v;\n } else if (typeof v === \"number\" || typeof v === \"string\") {\n properties[k] = v;\n }\n }\n keyframes.push({ percentage, properties, ...(kfEase ? { ease: kfEase } : {}) });\n } else if (key === \"ease\") {\n ease = tryResolveStringProp(prop.value, scope) ?? ease;\n } else if (key === \"easeEach\") {\n easeEach = tryResolveStringProp(prop.value, scope) ?? easeEach;\n }\n }\n\n keyframes.sort((a, b) => a.percentage - b.percentage);\n\n return {\n format: \"percentage\",\n keyframes,\n ...(ease ? { ease } : {}),\n ...(easeEach ? { easeEach } : {}),\n };\n}\n\nfunction computeKeyframesTotalDuration(\n varsNode: AstNode,\n scope: ScopeBindings,\n): number | undefined {\n const kfNode = (varsNode.properties ?? []).find(\n (p: AstNode) => (p.key?.name ?? p.key?.value) === \"keyframes\",\n )?.value;\n if (!kfNode || kfNode.type !== \"ArrayExpression\") return undefined;\n let total = 0;\n for (const el of kfNode.elements ?? []) {\n if (!el || el.type !== \"ObjectExpression\") continue;\n const r = objectExpressionToRecord(el, scope);\n if (typeof r.duration === \"number\") total += r.duration;\n }\n return total > 0 ? total : undefined;\n}\n\n// fallow-ignore-next-line complexity\nfunction parseObjectArrayKeyframes(node: AstNode, scope: ScopeBindings): GsapKeyframesData {\n const elements = node.elements ?? [];\n const raw: Array<{\n properties: Record<string, number | string>;\n duration?: number;\n ease?: string;\n }> = [];\n\n for (const el of elements) {\n if (!el || (el.type !== \"ObjectExpression\" && el.type !== \"ObjectProperty\")) {\n // Skip non-object elements\n if (el?.type !== \"ObjectExpression\") continue;\n }\n const record = objectExpressionToRecord(el, scope);\n const properties: Record<string, number | string> = {};\n let duration: number | undefined;\n let ease: string | undefined;\n for (const [k, v] of Object.entries(record)) {\n if (k === \"duration\" && typeof v === \"number\") {\n duration = v;\n } else if (k === \"ease\" && typeof v === \"string\") {\n ease = v;\n } else if (typeof v === \"number\" || typeof v === \"string\") {\n properties[k] = v;\n }\n }\n raw.push({ properties, duration, ease });\n }\n\n // Convert durations to percentage positions. If durations are present, use\n // cumulative ratios; otherwise distribute evenly.\n const totalDuration = raw.reduce((sum, r) => sum + (r.duration ?? 0), 0);\n const keyframes: GsapPercentageKeyframe[] = [];\n\n if (totalDuration > 0) {\n let cumulative = 0;\n for (const entry of raw) {\n cumulative += entry.duration ?? 0;\n const percentage = Math.round((cumulative / totalDuration) * 100);\n keyframes.push({\n percentage,\n properties: entry.properties,\n ...(entry.ease ? { ease: entry.ease } : {}),\n });\n }\n } else {\n for (let i = 0; i < raw.length; i++) {\n const entry = raw[i]!;\n const percentage = raw.length > 1 ? Math.round((i / (raw.length - 1)) * 100) : 0;\n keyframes.push({\n percentage,\n properties: entry.properties,\n ...(entry.ease ? { ease: entry.ease } : {}),\n });\n }\n }\n\n return { format: \"object-array\", keyframes };\n}\n\n// fallow-ignore-next-line complexity\nfunction parseSimpleArrayKeyframes(node: AstNode, scope: ScopeBindings): GsapKeyframesData {\n const arrayProps: Map<string, (number | string)[]> = new Map();\n let ease: string | undefined;\n let easeEach: string | undefined;\n\n for (const prop of node.properties ?? []) {\n if (prop.type !== \"ObjectProperty\" && prop.type !== \"Property\") continue;\n const key = prop.key?.name ?? prop.key?.value;\n if (typeof key !== \"string\") continue;\n\n if (prop.value?.type === \"ArrayExpression\") {\n const values: (number | string)[] = [];\n for (const el of prop.value.elements ?? []) {\n const val = resolveNode(el, scope);\n if (typeof val === \"number\" || typeof val === \"string\") {\n values.push(val);\n }\n }\n if (values.length > 0) arrayProps.set(key, values);\n } else if (key === \"ease\") {\n ease = tryResolveStringProp(prop.value, scope) ?? ease;\n } else if (key === \"easeEach\") {\n easeEach = tryResolveStringProp(prop.value, scope) ?? easeEach;\n }\n }\n\n // Zip arrays into percentage keyframes (evenly spaced).\n const maxLen = Math.max(...[...arrayProps.values()].map((a) => a.length), 0);\n const keyframes: GsapPercentageKeyframe[] = [];\n\n for (let i = 0; i < maxLen; i++) {\n const percentage = maxLen > 1 ? Math.round((i / (maxLen - 1)) * 100) : 0;\n const properties: Record<string, number | string> = {};\n for (const [key, values] of arrayProps) {\n if (i < values.length) properties[key] = values[i]!;\n }\n keyframes.push({ percentage, properties });\n }\n\n return {\n format: \"simple-array\",\n keyframes,\n ...(ease ? { ease } : {}),\n ...(easeEach ? { easeEach } : {}),\n };\n}\n\n// ── MotionPath Parsing ────────────────────────────────────────────────────\n\ninterface MotionPathParseResult {\n arcPath: ArcPathConfig;\n waypoints: Array<{ x: number; y: number }>;\n}\n\nfunction parseMotionPathNode(\n node: AstNode | undefined,\n scope: ScopeBindings,\n): MotionPathParseResult | undefined {\n if (!node) return undefined;\n\n let pathNode: AstNode | undefined;\n let autoRotate: boolean | number = false;\n let curviness = 1;\n let isCubic = false;\n\n if (node.type === \"ObjectExpression\") {\n for (const prop of node.properties ?? []) {\n if (!isObjectProperty(prop)) continue;\n const key = propKeyName(prop);\n if (key === \"path\") pathNode = prop.value;\n else if (key === \"autoRotate\") {\n const val = resolveNode(prop.value, scope);\n autoRotate = typeof val === \"number\" ? val : val === true;\n } else if (key === \"curviness\") {\n const val = resolveNode(prop.value, scope);\n if (typeof val === \"number\") curviness = val;\n } else if (key === \"type\") {\n const val = resolveNode(prop.value, scope);\n if (val === \"cubic\") isCubic = true;\n }\n }\n } else if (node.type === \"ArrayExpression\") {\n pathNode = node;\n }\n\n if (!pathNode || pathNode.type !== \"ArrayExpression\") return undefined;\n\n const elements = pathNode.elements ?? [];\n const coords: Array<{ x: number; y: number }> = [];\n for (const elem of elements) {\n if (!elem || elem.type !== \"ObjectExpression\") continue;\n const rec = objectExpressionToRecord(elem, scope);\n const x = typeof rec.x === \"number\" ? rec.x : undefined;\n const y = typeof rec.y === \"number\" ? rec.y : undefined;\n if (x !== undefined && y !== undefined) coords.push({ x, y });\n }\n\n if (coords.length < 2) return undefined;\n\n let waypoints: Array<{ x: number; y: number }>;\n const segments: ArcPathSegment[] = [];\n\n if (isCubic && coords.length >= 4) {\n // type: \"cubic\" — coords are [anchor, cp1, cp2, anchor, cp1, cp2, anchor, ...]\n // Every 3rd coord starting from 0 is an anchor, the two between are control points.\n waypoints = [];\n waypoints.push(coords[0]!);\n for (let i = 1; i + 2 < coords.length; i += 3) {\n const cp1 = coords[i]!;\n const cp2 = coords[i + 1]!;\n const anchor = coords[i + 2]!;\n waypoints.push(anchor);\n segments.push({ curviness, cp1, cp2 });\n }\n } else {\n // Waypoint array with global curviness\n waypoints = coords;\n for (let i = 0; i < waypoints.length - 1; i++) {\n segments.push({ curviness });\n }\n }\n\n return {\n arcPath: { enabled: true, autoRotate, segments },\n waypoints,\n };\n}\n\n// fallow-ignore-next-line complexity\nfunction tweenCallToAnimation(\n call: TweenCallInfo,\n scope: ScopeBindings,\n): Omit<GsapAnimation, \"id\"> {\n const vars = objectExpressionToRecord(call.varsArg, scope);\n const properties: Record<string, number | string> = {};\n const extras: Record<string, unknown> = {};\n let keyframesData: GsapKeyframesData | undefined;\n let hasUnresolvedKeyframes = false;\n let motionPathResult: MotionPathParseResult | undefined;\n\n for (const [key, val] of Object.entries(vars)) {\n if (BUILTIN_VAR_KEYS.has(key)) continue;\n if (DROPPED_VAR_KEYS.has(key)) continue;\n\n if (key === \"keyframes\") {\n const kfNode = findPropertyNode(call.varsArg, \"keyframes\");\n keyframesData = parseKeyframesNode(kfNode, scope);\n if (!keyframesData && kfNode) hasUnresolvedKeyframes = true;\n continue;\n }\n\n if (key === \"motionPath\") {\n const mpNode = findPropertyNode(call.varsArg, \"motionPath\");\n motionPathResult = parseMotionPathNode(mpNode, scope);\n continue;\n }\n\n if (key === \"easeEach\") {\n // easeEach is only meaningful alongside keyframes — handled below.\n continue;\n }\n\n if (EXTRAS_KEYS.has(key)) {\n // For extras, prefer the raw AST source so complex objects like\n // `stagger: { each: 0.15, from: \"start\" }` survive verbatim.\n const rawSource = extractRawPropertySource(call.varsArg, key);\n if (rawSource !== undefined) {\n extras[key] = `__raw:${rawSource}`;\n } else if (val !== undefined) {\n extras[key] = val;\n }\n continue;\n }\n\n if (typeof val === \"number\" || typeof val === \"string\") {\n properties[key] = val;\n }\n }\n\n // Apply tween-level easeEach to keyframes data.\n if (keyframesData && typeof vars.easeEach === \"string\") {\n keyframesData.easeEach = vars.easeEach as string;\n }\n\n // When motionPath is present, reconstruct x/y as keyframe waypoints.\n if (motionPathResult) {\n const { waypoints } = motionPathResult;\n if (!keyframesData) {\n // No explicit keyframes — create synthetic percentage keyframes from waypoints.\n const kf: GsapPercentageKeyframe[] = waypoints.map((wp, i) => ({\n percentage: waypoints.length > 1 ? Math.round((i / (waypoints.length - 1)) * 100) : 0,\n properties: { x: wp.x, y: wp.y },\n }));\n keyframesData = { format: \"percentage\", keyframes: kf };\n } else {\n // Merge waypoint positions into existing keyframes at matching percentages.\n // If keyframe count matches waypoint count, assign positionally.\n const kfs = keyframesData.keyframes;\n if (kfs.length === waypoints.length) {\n for (let i = 0; i < kfs.length; i++) {\n kfs[i]!.properties.x = waypoints[i]!.x;\n kfs[i]!.properties.y = waypoints[i]!.y;\n }\n }\n }\n // arcPath is attached below on the animation result.\n }\n\n let fromProperties: Record<string, number | string> | undefined;\n if (call.method === \"fromTo\" && call.fromArg) {\n fromProperties = {};\n const fromVars = objectExpressionToRecord(call.fromArg, scope);\n for (const [key, val] of Object.entries(fromVars)) {\n if (typeof val === \"number\" || typeof val === \"string\") {\n fromProperties[key] = val;\n }\n }\n }\n\n const hasPositionArg = !!call.positionArg;\n const posVal = call.positionArg ? extractLiteralValue(call.positionArg, scope) : 0;\n const position: number | string =\n typeof posVal === \"number\" ? posVal : typeof posVal === \"string\" ? posVal : 0;\n let duration = typeof vars.duration === \"number\" ? vars.duration : undefined;\n const ease = typeof vars.ease === \"string\" ? vars.ease : undefined;\n\n if (duration === undefined && keyframesData) {\n duration = computeKeyframesTotalDuration(call.varsArg, scope);\n }\n\n const anim: Omit<GsapAnimation, \"id\"> = {\n targetSelector: call.selector,\n method: call.method,\n position,\n properties,\n fromProperties,\n duration,\n ease,\n };\n if (!hasPositionArg) anim.implicitPosition = true;\n let group = classifyTweenPropertyGroup(properties);\n if (!group && keyframesData) {\n const kfProps: Record<string, unknown> = {};\n for (const kf of keyframesData.keyframes) {\n for (const k of Object.keys(kf.properties)) kfProps[k] = true;\n }\n group = classifyTweenPropertyGroup(kfProps);\n }\n if (group) anim.propertyGroup = group;\n if (call.global) anim.global = true;\n if (Object.keys(extras).length > 0) anim.extras = extras;\n if (keyframesData) anim.keyframes = keyframesData;\n if (motionPathResult) anim.arcPath = motionPathResult.arcPath;\n if (hasUnresolvedKeyframes) anim.hasUnresolvedKeyframes = true;\n if (call.selector === \"__unresolved__\") anim.hasUnresolvedSelector = true;\n return anim;\n}\n\n// ── Timeline Position Resolution ──────────────────────────────────────────\n\nconst GSAP_DEFAULT_DURATION = 0.5;\n\n// NOTE: Label-based positions (e.g. \"myLabel+=0.5\") are not yet resolved —\n// they fall through to parseFloat which returns null for non-numeric strings.\nfunction resolvePositionString(pos: string, cursor: number, prevStart: number): number | null {\n const trimmed = pos.trim();\n if (trimmed === \"\") return cursor;\n if (trimmed.startsWith(\"+=\")) {\n const n = Number.parseFloat(trimmed.slice(2));\n return Number.isFinite(n) ? cursor + n : null;\n }\n if (trimmed.startsWith(\"-=\")) {\n const n = Number.parseFloat(trimmed.slice(2));\n return Number.isFinite(n) ? cursor - n : null;\n }\n if (trimmed === \"<\") return prevStart;\n if (trimmed === \">\") return cursor;\n if (trimmed.startsWith(\"<\")) {\n const n = Number.parseFloat(trimmed.slice(1));\n return Number.isFinite(n) ? prevStart + n : null;\n }\n if (trimmed.startsWith(\">\")) {\n const n = Number.parseFloat(trimmed.slice(1));\n return Number.isFinite(n) ? cursor + n : null;\n }\n const n = Number.parseFloat(trimmed);\n return Number.isFinite(n) ? n : null;\n}\n\nfunction applyTimelineDefaults(\n anims: Omit<GsapAnimation, \"id\">[],\n defaults?: TimelineDefaults,\n): void {\n if (!defaults) return;\n for (const anim of anims) {\n if (anim.method === \"set\") continue;\n if (anim.duration === undefined && defaults.duration !== undefined) {\n anim.duration = defaults.duration;\n }\n if (anim.ease === undefined && defaults.ease !== undefined) {\n anim.ease = defaults.ease;\n }\n }\n}\n\nfunction resolveTimelinePositions(anims: Omit<GsapAnimation, \"id\">[]): void {\n let cursor = 0;\n let prevStart = 0;\n for (const anim of anims) {\n // A global `gsap.set(...)` is off-timeline — it's applied once at load, not\n // sequenced on the master timeline. It carries no position arg, so the\n // cursor-based fallback below would otherwise hand it the comp-end time\n // (every prior tween's duration summed). Pin it to 0 (its load-time start)\n // and don't let it advance the cursor/prevStart for following tweens.\n if (anim.method === \"set\" && anim.global) {\n anim.resolvedStart = 0;\n continue;\n }\n const duration = anim.method === \"set\" ? 0 : (anim.duration ?? GSAP_DEFAULT_DURATION);\n let start: number | null;\n\n if (anim.implicitPosition) {\n start = cursor;\n } else if (typeof anim.position === \"number\") {\n start = anim.position;\n } else if (typeof anim.position === \"string\") {\n start = resolvePositionString(anim.position, cursor, prevStart);\n } else {\n start = cursor;\n }\n\n if (start != null) {\n anim.resolvedStart = Math.max(0, start);\n prevStart = anim.resolvedStart;\n cursor = Math.max(cursor, anim.resolvedStart + duration);\n }\n }\n}\n\nfunction sortBySourcePosition(calls: TweenCallInfo[]): void {\n calls.sort((a, b) => {\n const aLoc = a.node.callee?.property?.loc?.start;\n const bLoc = b.node.callee?.property?.loc?.start;\n if (!aLoc || !bLoc) return 0;\n return aLoc.line - bLoc.line || aLoc.column - bLoc.column;\n });\n}\n\n// ── Stable ID Generation ───────────────────────────────────────────────────\n\n/**\n * IDs are transient — recomputed on every parse, never persisted across sessions.\n * They exist only in ephemeral request/response payloads, React component state,\n * and the in-memory keyframe cache (rebuilt on every page load). No database,\n * localStorage, or file stores animation IDs, so changing the ID format (e.g.\n * adding a `-scale`/`-position` suffix) is safe.\n */\nfunction assignStableIds(anims: Omit<GsapAnimation, \"id\">[]): GsapAnimation[] {\n const counts = new Map<string, number>();\n return anims.map((anim) => {\n const posKey =\n typeof anim.position === \"number\"\n ? String(Math.round(anim.position * 1000))\n : String(anim.position);\n const groupSuffix = anim.propertyGroup ? `-${anim.propertyGroup}` : \"\";\n const base = `${anim.targetSelector}-${anim.method}-${posKey}${groupSuffix}`;\n const count = (counts.get(base) ?? 0) + 1;\n counts.set(base, count);\n const id = count === 1 ? base : `${base}-${count}`;\n return { ...anim, id };\n });\n}\n\n// ── Shared parse (AST + located tween calls) ────────────────────────────────\n\ninterface ParsedGsapAst {\n ast: AstNode;\n scope: ScopeBindings;\n timelineVar: string;\n detection: TimelineDetection;\n /** Tween calls in document order, each paired with its stable animation id. */\n located: Array<{ id: string; call: TweenCallInfo; animation: GsapAnimation }>;\n}\n\n/**\n * Parse a script to its recast AST plus the located tween calls. The mutation\n * functions reuse this so they can edit the exact call node in place (recast\n * preserves all surrounding source — interleaved `gsap.set`, element variable\n * declarations, the IIFE wrapper, comments and formatting).\n */\nfunction parseGsapAst(script: string): ParsedGsapAst {\n const ast = parseScript(script);\n const scope = collectScopeBindings(ast);\n const targetBindings = collectTargetBindings(ast, scope);\n const detection = findTimelineVar(ast, scope);\n const timelineVar = detection.timelineVar ?? \"tl\";\n const calls = findAllTweenCalls(ast, timelineVar, scope, targetBindings);\n sortBySourcePosition(calls);\n const rawAnims = calls.map((call) => tweenCallToAnimation(call, scope));\n applyTimelineDefaults(rawAnims, detection.defaults);\n resolveTimelinePositions(rawAnims);\n const animations = assignStableIds(rawAnims);\n const located = animations.map((animation, i) => ({\n id: animation.id,\n call: calls[i]!,\n animation,\n }));\n return { ast, scope, timelineVar, detection, located };\n}\n\n// ── Public API ──────────────────────────────────────────────────────────────\n\nexport function parseGsapScript(script: string): ParsedGsap {\n try {\n const { detection, timelineVar, located } = parseGsapAst(script);\n const animations = located.map((l) => l.animation);\n\n const timelineMatch = script.match(\n new RegExp(\n `^[\\\\s\\\\S]*?(?:const|let|var)\\\\s+${timelineVar}\\\\s*=\\\\s*gsap\\\\.timeline\\\\s*\\\\([^)]*\\\\)\\\\s*;?`,\n ),\n );\n const preamble =\n timelineMatch?.[0] ?? `const ${timelineVar} = gsap.timeline({ paused: true });`;\n\n const lastCallIdx = script.lastIndexOf(`${timelineVar}.`);\n let postamble = \"\";\n if (lastCallIdx !== -1) {\n const afterLast = script.slice(lastCallIdx);\n const endOfCall = afterLast.indexOf(\";\");\n if (endOfCall !== -1) {\n postamble = script.slice(lastCallIdx + endOfCall + 1).trim();\n }\n }\n\n const result: ParsedGsap = { animations, timelineVar, preamble, postamble };\n if (detection.timelineCount > 1) result.multipleTimelines = true;\n if (detection.timelineCount > 0 && detection.timelineVar === null)\n result.unsupportedTimelinePattern = true;\n return result;\n } catch {\n return { animations: [], timelineVar: \"tl\", preamble: \"\", postamble: \"\" };\n }\n}\n\n// ── In-place AST mutation helpers ───────────────────────────────────────────\n//\n// Edits operate directly on the located call's AST node and reprint via recast,\n// which preserves every untouched statement. This is what lets us edit tweens\n// in real compositions (variable targets, interleaved `gsap.set`, IIFE wrapper)\n// without regenerating — and discarding — the surrounding code.\n\n/**\n * Parse a value/expression snippet into a standalone AST expression node.\n * Uses an assignment (`__hf__ = <code>`) rather than wrapping in parens so an\n * object literal parses as an expression without recast re-emitting the\n * surrounding parentheses.\n */\nfunction parseExpr(code: string): AstNode {\n return parseScript(`__hf__ = ${code};`).program.body[0].expression.right;\n}\n\nfunction propKeyName(prop: AstNode): string | undefined {\n return prop?.key?.name ?? prop?.key?.value;\n}\n\nfunction isObjectProperty(prop: AstNode): boolean {\n return prop?.type === \"ObjectProperty\" || prop?.type === \"Property\";\n}\n\n/** A key the inspector treats as an editable transform/style property. */\nfunction isEditablePropertyKey(key: string): boolean {\n return !BUILTIN_VAR_KEYS.has(key) && !DROPPED_VAR_KEYS.has(key) && !EXTRAS_KEYS.has(key);\n}\n\nfunction makeObjectProperty(key: string, value: number | string): AstNode {\n const obj = parseExpr(`{ ${safeKey(key)}: ${valueToCode(value)} }`);\n return obj.properties[0];\n}\n\n/** Set (or insert) a single key on an ObjectExpression, preserving sibling keys. */\nfunction setVarsKey(varsArg: AstNode, key: string, value: number | string): void {\n if (varsArg?.type !== \"ObjectExpression\") return;\n const existing = varsArg.properties.find(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === key,\n );\n if (existing) {\n existing.value = parseExpr(valueToCode(value));\n } else {\n varsArg.properties.push(makeObjectProperty(key, value));\n }\n}\n\n/**\n * Filter an ObjectExpression's properties, keeping non-editable keys\n * and delegating the keep/drop decision for editable keys to `shouldKeep`.\n */\nfunction filterEditableKeys(varsArg: AstNode, shouldKeep: (key: string) => boolean): void {\n if (varsArg?.type !== \"ObjectExpression\") return;\n varsArg.properties = varsArg.properties.filter((p: AstNode) => {\n if (!isObjectProperty(p)) return true;\n const key = propKeyName(p);\n if (typeof key !== \"string\") return true;\n if (!isEditablePropertyKey(key)) return true;\n return shouldKeep(key);\n });\n}\n\n/**\n * Replace the editable-property keys on an ObjectExpression with `newProps`,\n * leaving `duration`, `ease`, `stagger`, callbacks and other non-editable keys\n * untouched.\n */\nfunction reconcileEditableProperties(\n varsArg: AstNode,\n newProps: Record<string, number | string>,\n): void {\n filterEditableKeys(varsArg, (key) => key in newProps);\n // Upsert each new prop, preserving the order keys first appeared.\n for (const [key, value] of Object.entries(newProps)) {\n setVarsKey(varsArg, key, value);\n }\n}\n\nfunction applyEaseUpdate(varsArg: AstNode, ease: string): void {\n const kfNode = findKeyframesObjectNode(varsArg);\n if (kfNode) {\n setVarsKey(kfNode, \"easeEach\", ease);\n removeVarsKey(varsArg, \"ease\");\n } else {\n setVarsKey(varsArg, \"ease\", ease);\n }\n}\n\n/**\n * \"Apply to all segments\": drop every per-keyframe `ease` override so the single\n * `easeEach` governs all segments uniformly (AE select-all + F9). Mirrors the\n * acorn writer's resetKeyframeEases branch.\n */\nfunction stripKeyframeEases(varsArg: AstNode): void {\n const kfNode = findKeyframesObjectNode(varsArg);\n const props = kfNode?.properties;\n if (!Array.isArray(props)) return;\n for (const entry of props) {\n if (isObjectProperty(entry)) removeVarsKey(entry.value, \"ease\");\n }\n}\n\nfunction applyUpdatesToCall(\n call: TweenCallInfo,\n updates: Partial<GsapAnimation> & { easeEach?: string; resetKeyframeEases?: boolean },\n): void {\n if (updates.properties) reconcileEditableProperties(call.varsArg, updates.properties);\n if (updates.fromProperties && call.method === \"fromTo\" && call.fromArg) {\n reconcileEditableProperties(call.fromArg, updates.fromProperties);\n }\n if (updates.duration !== undefined) setVarsKey(call.varsArg, \"duration\", updates.duration);\n if (updates.easeEach !== undefined) applyEaseUpdate(call.varsArg, updates.easeEach);\n else if (updates.ease !== undefined) applyEaseUpdate(call.varsArg, updates.ease);\n if (updates.resetKeyframeEases) stripKeyframeEases(call.varsArg);\n if (updates.position !== undefined) {\n const posIdx = call.method === \"fromTo\" ? 3 : 2;\n call.node.arguments[posIdx] = parseExpr(valueToCode(updates.position));\n }\n}\n\n/** Walk up to the enclosing ExpressionStatement path (for prune / insertAfter). */\nfunction findStatementPath(path: AstPath): AstPath | null {\n let p = path;\n while (p) {\n if (p.node?.type === \"ExpressionStatement\") return p;\n p = p.parentPath;\n }\n return null;\n}\n\nfunction insertAfterAnchor(parsed: ParsedGsapAst, newStatement: AstNode): void {\n const lastCall = parsed.located[parsed.located.length - 1]?.call;\n const anchorPath = lastCall\n ? findStatementPath(lastCall.path)\n : findTimelineDeclarationPath(parsed.ast, parsed.timelineVar);\n if (anchorPath) {\n anchorPath.insertAfter(newStatement);\n } else {\n parsed.ast.program.body.push(newStatement);\n }\n}\n\n/** Build the source for a single `tl.method(selector, vars, position)` call. */\nfunction buildTweenStatementCode(timelineVar: string, anim: Omit<GsapAnimation, \"id\">): string {\n const selector = JSON.stringify(anim.targetSelector);\n const props: Record<string, number | string> = { ...anim.properties };\n if (anim.method !== \"set\" && anim.duration !== undefined) props.duration = anim.duration;\n if (anim.ease) props.ease = anim.ease;\n const entries = Object.entries(props).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`);\n // immediateRender forces GSAP to apply the set when added to the timeline,\n // not on the first seek — without it, tl.set at position 0 on a paused\n // timeline is invisible until the playhead moves past 0. A base `gsap.set`\n // already runs immediately, so it doesn't need (or get) the flag.\n if (anim.method === \"set\" && !anim.global) entries.push(\"immediateRender: true\");\n if (anim.extras) {\n for (const [k, v] of Object.entries(anim.extras)) {\n entries.push(`${safeKey(k)}: ${valueToCode(v as number | string)}`);\n }\n }\n const objCode = `{ ${entries.join(\", \")} }`;\n const posCode = valueToCode(\n typeof anim.position === \"number\" ? anim.position : (anim.position ?? 0),\n );\n if (anim.method === \"fromTo\") {\n const fromEntries = Object.entries(anim.fromProperties ?? {}).map(\n ([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`,\n );\n const fromCode = `{ ${fromEntries.join(\", \")} }`;\n return `${timelineVar}.fromTo(${selector}, ${fromCode}, ${objCode}, ${posCode});`;\n }\n // A base `gsap.set` is off the timeline: no timeline var, no position arg.\n if (anim.method === \"set\" && anim.global) {\n return `gsap.set(${selector}, ${objCode});`;\n }\n return `${timelineVar}.${anim.method}(${selector}, ${objCode}, ${posCode});`;\n}\n\nexport function updateAnimationInScript(\n script: string,\n animationId: string,\n updates: Partial<GsapAnimation> & { easeEach?: string; resetKeyframeEases?: boolean },\n): string {\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch (e) {\n console.warn(\"[gsap-parser] updateAnimationInScript parse failed:\", e);\n return script;\n }\n const target = parsed.located.find((l) => l.id === animationId);\n if (!target) return script;\n applyUpdatesToCall(target.call, updates);\n return recast.print(parsed.ast).code;\n}\n\nexport function shiftPositionsInScript(\n script: string,\n targetSelector: string,\n delta: number,\n): string {\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch (e) {\n console.warn(\"[gsap-parser] shiftPositionsInScript parse failed:\", e);\n return script;\n }\n let changed = false;\n for (const entry of parsed.located) {\n if (entry.animation.targetSelector !== targetSelector) continue;\n if (typeof entry.animation.position !== \"number\") continue;\n const newPos = Math.max(0, Math.round((entry.animation.position + delta) * 1000) / 1000);\n applyUpdatesToCall(entry.call, { position: newPos });\n changed = true;\n }\n return changed ? recast.print(parsed.ast).code : script;\n}\n\nexport function scalePositionsInScript(\n script: string,\n targetSelector: string,\n oldStart: number,\n oldDuration: number,\n newStart: number,\n newDuration: number,\n): string {\n if (oldDuration <= 0 || newDuration <= 0) return script;\n const ratio = newDuration / oldDuration;\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch (e) {\n console.warn(\"[gsap-parser] scalePositionsInScript parse failed:\", e);\n return script;\n }\n let changed = false;\n for (const entry of parsed.located) {\n if (entry.animation.targetSelector !== targetSelector) continue;\n if (typeof entry.animation.position !== \"number\") continue;\n const newPos = Math.max(\n 0,\n Math.round((newStart + (entry.animation.position - oldStart) * ratio) * 1000) / 1000,\n );\n const updates: Partial<GsapAnimation> = { position: newPos };\n if (typeof entry.animation.duration === \"number\" && entry.animation.duration > 0) {\n updates.duration = Math.max(\n 0.001,\n Math.round(entry.animation.duration * ratio * 1000) / 1000,\n );\n }\n applyUpdatesToCall(entry.call, updates);\n changed = true;\n }\n return changed ? recast.print(parsed.ast).code : script;\n}\n\nfunction updateAnimationSelector(script: string, animationId: string, newSelector: string): string {\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch {\n return script;\n }\n const target = parsed.located.find((l) => l.id === animationId);\n if (!target) return script;\n const selectorArg = target.call.path.node.arguments?.[0];\n if (selectorArg?.type === \"StringLiteral\") {\n selectorArg.value = newSelector;\n } else if (selectorArg?.type === \"Identifier\") {\n target.call.path.node.arguments[0] = { type: \"StringLiteral\", value: newSelector };\n }\n return recast.print(parsed.ast).code;\n}\n\nexport function addAnimationToScript(\n script: string,\n animation: Omit<GsapAnimation, \"id\">,\n): { script: string; id: string } {\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch (e) {\n console.warn(\"[gsap-parser] addAnimationToScript parse failed:\", e);\n return { script, id: \"\" };\n }\n // Nothing to anchor against and no timeline to target — treat as parse failure.\n if (parsed.located.length === 0 && parsed.detection.timelineVar === null) {\n return { script, id: \"\" };\n }\n\n const id = `anim-${Date.now()}`;\n const statementCode = buildTweenStatementCode(parsed.timelineVar, animation);\n const newStatement = parseScript(statementCode).program.body[0];\n insertAfterAnchor(parsed, newStatement);\n return { script: recast.print(parsed.ast).code, id };\n}\n\nexport function addAnimationWithKeyframesToScript(\n script: string,\n targetSelector: string,\n position: number,\n duration: number,\n keyframes: Array<{\n percentage: number;\n properties: Record<string, number | string>;\n ease?: string;\n auto?: boolean;\n }>,\n ease?: string,\n easeEach?: string,\n): { script: string; id: string } {\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch (e) {\n console.warn(\"[gsap-parser] addAnimationWithKeyframesToScript parse failed:\", e);\n return { script, id: \"\" };\n }\n if (parsed.located.length === 0 && parsed.detection.timelineVar === null) {\n return { script, id: \"\" };\n }\n\n const selector = JSON.stringify(targetSelector);\n const kfCode = buildKeyframeObjectCode(keyframes, easeEach ? { easeEach } : undefined);\n const varEntries = [`keyframes: ${kfCode}`, `duration: ${valueToCode(duration)}`];\n if (ease) varEntries.push(`ease: ${JSON.stringify(ease)}`);\n const posCode = valueToCode(position);\n const stmtCode = `${parsed.timelineVar}.to(${selector}, { ${varEntries.join(\", \")} }, ${posCode});`;\n\n const newStatement = parseScript(stmtCode).program.body[0];\n insertAfterAnchor(parsed, newStatement);\n\n const result = recast.print(parsed.ast).code;\n const reParsed = parseGsapAst(result);\n const newId = reParsed.located[reParsed.located.length - 1]?.id ?? \"\";\n return { script: result, id: newId };\n}\n\n/** Find the statement path of `const <timelineVar> = gsap.timeline(...)`. */\nfunction findTimelineDeclarationPath(ast: AstNode, timelineVar: string): AstPath | null {\n let found: AstPath | null = null;\n recast.types.visit(ast, {\n visitVariableDeclaration(path: AstPath) {\n if (found) return false;\n for (const decl of path.node.declarations ?? []) {\n if (decl.id?.name === timelineVar && isGsapTimelineCall(decl.init)) {\n found = path;\n return false;\n }\n }\n this.traverse(path);\n },\n });\n return found;\n}\n\n/** Find the call that chains off `targetNode` (i.e. whose callee object IS it). */\nfunction findChainParentCall(stmtNode: AstNode, targetNode: AstNode): AstNode | null {\n let found: AstNode | null = null;\n recast.types.visit(stmtNode, {\n visitCallExpression(p: AstPath) {\n if (found) return false;\n if (p.node.callee?.type === \"MemberExpression\" && p.node.callee.object === targetNode) {\n found = p.node;\n return false;\n }\n this.traverse(p);\n },\n });\n return found;\n}\n\nexport function removeAnimationFromScript(script: string, animationId: string): string {\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch (e) {\n console.warn(\"[gsap-parser] removeAnimationFromScript parse failed:\", e);\n return script;\n }\n let target = parsed.located.find((l) => l.id === animationId);\n if (!target) {\n const convertedId = animationId.replace(/-from-|-fromTo-/, \"-to-\");\n target = parsed.located.find((l) => l.id === convertedId);\n }\n if (!target) return script;\n const node = target.call.node;\n const stmtPath = findStatementPath(target.call.path);\n if (!stmtPath) return script;\n\n const parentCall = findChainParentCall(stmtPath.node, node);\n if (parentCall) {\n // Inner link of a chain — splice it out by re-pointing the next link.\n parentCall.callee.object = node.callee.object;\n } else if (node.callee?.object?.type === \"CallExpression\") {\n // Outermost link of a chain with earlier links — drop just this link.\n stmtPath.node.expression = node.callee.object;\n } else {\n // Standalone tween — remove the whole statement.\n stmtPath.prune();\n }\n return recast.print(parsed.ast).code;\n}\n\nfunction insertInheritedStateSet(\n script: string,\n selector: string,\n position: number,\n properties: Record<string, number | string>,\n): string {\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch {\n return script;\n }\n const tlVar = parsed.timelineVar;\n const props = Object.entries(properties)\n .map(([k, v]) => `${k}: ${typeof v === \"string\" ? JSON.stringify(v) : v}`)\n .join(\", \");\n const code = `${tlVar}.set(${JSON.stringify(selector)}, { ${props} }, ${position});`;\n const newStatement = parseScript(code).program.body[0];\n const anchor = findTimelineDeclarationPath(parsed.ast, tlVar);\n if (anchor) {\n anchor.insertAfter(newStatement);\n } else if (parsed.located.length > 0) {\n const firstTween = parsed.located[0]!.call;\n const stmtPath = findStatementPath(firstTween.path);\n if (stmtPath) stmtPath.insertBefore(newStatement);\n else parsed.ast.program.body.unshift(newStatement);\n } else {\n parsed.ast.program.body.push(newStatement);\n }\n return recast.print(parsed.ast).code;\n}\n\n/** Marker on Studio-emitted pre-keyframe hold `set`s. `data` is a GSAP-reserved\n * config key (attached to the tween, never applied to the target), so it carries\n * the tag without triggering GSAP's \"Invalid property\" warning. */\nconst STUDIO_HOLD_MARKER = \"hf-hold\";\n\n/** True for a `tl.set(...)` this module emitted to hold a keyframe before its tween.\n * The Studio filters these out so they never appear as user keyframes/diamonds. */\nexport function isStudioHoldSet(anim: GsapAnimation): boolean {\n return anim.method === \"set\" && anim.properties?.data === STUDIO_HOLD_MARKER;\n}\n\n/**\n * Keep a `tl.set(selector, {x,y}, 0)` \"hold\" in front of every position-keyframed\n * tween that starts after t=0, so the element holds its first keyframe's position\n * BEFORE the tween plays instead of snapping to its CSS base (the universal NLE\n * \"hold before first keyframe\" behavior). The set is tagged with `data: \"hf-hold\"`\n * so this pass owns it: every call wipes the prior holds and recomputes from the\n * current keyframes, keeping them in sync as keyframes are added/moved/deleted.\n *\n * Idempotent. Only position props (x/y/xPercent/yPercent) are held — opacity/scale\n * keep their authored pre-tween behavior. A tween already starting at 0 needs no\n * hold (no gap before it).\n */\nexport function syncPositionHoldsBeforeKeyframes(script: string): string {\n let parsed: ParsedGsap;\n try {\n parsed = parseGsapScript(script);\n } catch {\n return script;\n }\n // 1. Drop every hold this pass previously emitted, so we recompute fresh.\n let result = script;\n const staleHoldIds = parsed.animations.filter(isStudioHoldSet).map((a) => a.id);\n for (const id of staleHoldIds) result = removeAnimationFromScript(result, id);\n\n // 2. Re-add a hold for each position-keyframed tween that starts after t=0.\n let reparsed: ParsedGsap;\n try {\n reparsed = parseGsapScript(result);\n } catch {\n return result;\n }\n for (const anim of reparsed.animations) {\n if (!anim.keyframes) continue;\n const start = anim.resolvedStart ?? (typeof anim.position === \"number\" ? anim.position : 0);\n if (!(start > 0.001)) continue;\n const firstKf = [...anim.keyframes.keyframes].sort((a, b) => a.percentage - b.percentage)[0];\n if (!firstKf) continue;\n const posProps: Record<string, number | string> = {};\n for (const [k, v] of Object.entries(firstKf.properties)) {\n if (classifyPropertyGroup(k) === \"position\" && typeof v === \"number\") posProps[k] = v;\n }\n if (Object.keys(posProps).length === 0) continue;\n result = insertInheritedStateSet(result, anim.targetSelector, 0, {\n ...posProps,\n data: STUDIO_HOLD_MARKER,\n });\n }\n return result;\n}\n\n// ── Split Animation Functions ─────────────────────────────────────────────\n\nexport interface SplitAnimationsOptions {\n originalId: string;\n newId: string;\n splitTime: number;\n elementStart: number;\n elementDuration: number;\n}\n\nexport interface SplitAnimationsResult {\n script: string;\n /** Non-ID-selector animations that the engine cannot safely retarget. */\n skippedSelectors: string[];\n}\n\n// fallow-ignore-next-line complexity\nexport function splitAnimationsInScript(\n script: string,\n opts: SplitAnimationsOptions,\n): SplitAnimationsResult {\n const parsed = parseGsapScript(script);\n const originalSelector = `#${opts.originalId}`;\n const newSelector = `#${opts.newId}`;\n\n const skippedSelectors: string[] = [];\n for (const a of parsed.animations) {\n if (a.targetSelector !== originalSelector && a.targetSelector.includes(opts.originalId)) {\n skippedSelectors.push(a.targetSelector);\n }\n }\n\n const matching = parsed.animations.filter((a) => a.targetSelector === originalSelector);\n if (matching.length === 0) return { script, skippedSelectors };\n\n let result = script;\n const newElementStart = opts.splitTime;\n const inheritedProps: Record<string, number | string> = {};\n\n // Reverse iteration: updateAnimationSelector mutates selectors in the source\n // string, which can shift count-based ID suffixes (e.g. \"#hero-1\" → \"#hero-2\")\n // for later animations. Processing last-to-first prevents stale ID collisions.\n for (let i = matching.length - 1; i >= 0; i--) {\n const anim = matching[i]!;\n const pos = typeof anim.position === \"number\" ? anim.position : 0;\n const dur = anim.duration ?? 0;\n const animEnd = pos + dur;\n\n if (anim.keyframes) {\n if (pos >= opts.splitTime) {\n result = updateAnimationSelector(result, anim.id, newSelector);\n } else if (animEnd > opts.splitTime) {\n // Spanning keyframes can't be correctly split without renormalizing\n // percentages and durations — leave on original, warn the caller.\n skippedSelectors.push(`${originalSelector} (keyframes spanning split)`);\n const kfs = anim.keyframes.keyframes;\n for (const kf of kfs) {\n const kfTime = pos + (kf.percentage / 100) * dur;\n if (kfTime <= opts.splitTime) {\n for (const [k, v] of Object.entries(kf.properties)) {\n inheritedProps[k] = v;\n }\n }\n }\n } else {\n // Entirely before split — extract final keyframe properties\n const kfs = anim.keyframes.keyframes;\n if (kfs.length > 0) {\n for (const [k, v] of Object.entries(kfs[kfs.length - 1]!.properties)) {\n inheritedProps[k] = v;\n }\n }\n }\n continue;\n }\n\n // `<=` (not `<`) is deliberate: a tween whose end coincides exactly with\n // the split boundary has fully played by splitTime, so it belongs to the\n // first half and contributes its resting state to the clone. The spanning\n // branch below handles only strictly-mid-flight tweens (pos < split < end).\n if (animEnd <= opts.splitTime) {\n // Only a completed .from() reverts the element to its natural state, so\n // its recorded properties are the HIDDEN start (e.g. opacity:0), not the\n // resting state — clearing them keeps the clone at its natural value\n // instead of pinning it to the from-values (which made it invisible).\n // .fromTo() and .to() both END at their to-values (no revert), so they\n // fall through to `else` and inherit `anim.properties` (the to-values) —\n // .fromTo() must NOT join the .from() clear-branch or the clone would\n // drop the very state the fromTo just established.\n if (anim.method === \"from\") {\n for (const k of Object.keys(anim.properties)) delete inheritedProps[k];\n } else {\n for (const [k, v] of Object.entries(anim.properties)) {\n inheritedProps[k] = v;\n }\n }\n continue;\n }\n\n if (pos >= opts.splitTime) {\n result = updateAnimationSelector(result, anim.id, newSelector);\n continue;\n }\n\n // Spans the split — use linear interpolation to compute mid-values,\n // then .fromTo() on the clone so both halves play the correct range.\n // For .fromTo() tweens we have explicit from-values; for .to() tweens\n // we use accumulated state from prior animations, defaulting to 0 for\n // unknown numeric properties (the standard GSAP transform initial state).\n const progress = dur > 0 ? (opts.splitTime - pos) / dur : 0;\n const fromSource = anim.fromProperties ?? inheritedProps;\n const midProps: Record<string, number | string> = {};\n for (const [k, v] of Object.entries(anim.properties)) {\n if (typeof v !== \"number\") {\n midProps[k] = v;\n continue;\n }\n const fromVal = typeof fromSource[k] === \"number\" ? (fromSource[k] as number) : 0;\n midProps[k] = fromVal + (v - fromVal) * progress;\n }\n\n const firstHalfDuration = opts.splitTime - pos;\n result = updateAnimationInScript(result, anim.id, {\n duration: firstHalfDuration,\n properties: midProps,\n });\n\n const secondHalfDuration = animEnd - opts.splitTime;\n const addResult = addAnimationToScript(result, {\n targetSelector: newSelector,\n method: \"fromTo\",\n position: newElementStart,\n duration: secondHalfDuration,\n properties: { ...anim.properties },\n fromProperties: { ...midProps },\n ease: anim.ease,\n extras: anim.extras,\n });\n result = addResult.script;\n\n for (const [k, v] of Object.entries(midProps)) {\n inheritedProps[k] = v;\n }\n }\n\n if (Object.keys(inheritedProps).length > 0) {\n result = insertInheritedStateSet(result, newSelector, newElementStart, inheritedProps);\n }\n\n return { script: result, skippedSelectors };\n}\n\n// ── Keyframe Mutation Functions ────────────────────────────────────────────\n\nfunction sortedKeyframes(\n kfs: Array<{ percentage: number; properties: Record<string, number | string>; ease?: string }>,\n) {\n return kfs.slice().sort((a, b) => a.percentage - b.percentage);\n}\n\nfunction keyframePropsToCode(kf: { properties: Record<string, number | string> }): string[] {\n return Object.entries(kf.properties).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`);\n}\n\nfunction buildKeyframeObjectCode(\n keyframes: Array<{\n percentage: number;\n properties: Record<string, number | string>;\n ease?: string;\n auto?: boolean;\n }>,\n options?: { easeEach?: string },\n): string {\n const entries = keyframes.map((kf) => {\n const props = keyframePropsToCode(kf);\n if (kf.ease) props.push(`ease: ${JSON.stringify(kf.ease)}`);\n if (kf.auto) props.push(`_auto: 1`);\n return `${JSON.stringify(`${kf.percentage}%`)}: { ${props.join(\", \")} }`;\n });\n if (options?.easeEach) entries.push(`easeEach: ${JSON.stringify(options.easeEach)}`);\n return `{ ${entries.join(\", \")} }`;\n}\n\n/** Remove a named property from an ObjectExpression's properties array. */\nfunction removeVarsKey(varsArg: AstNode, key: string): void {\n if (varsArg?.type !== \"ObjectExpression\") return;\n varsArg.properties = varsArg.properties.filter(\n (p: AstNode) => !(isObjectProperty(p) && propKeyName(p) === key),\n );\n}\n\n/** Extract the numeric percentage from a key like \"50%\". Returns NaN for non-percentage keys. */\nfunction percentageFromKey(key: string): number {\n const m = PERCENTAGE_KEY_RE.exec(key);\n return m ? Number.parseFloat(m[1]!) : Number.NaN;\n}\n\nconst PCT_TOLERANCE = 2;\n\nfunction findKeyframePropByPct(\n kfNode: AstNode,\n percentage: number,\n): { idx: number; prop: AstNode } | null {\n const props = kfNode.properties;\n for (let i = 0; i < props.length; i++) {\n if (!isObjectProperty(props[i])) continue;\n const key = propKeyName(props[i]);\n if (typeof key !== \"string\") continue;\n const parsed = percentageFromKey(key);\n if (Number.isNaN(parsed)) continue;\n if (Math.abs(parsed - percentage) <= PCT_TOLERANCE) return { idx: i, prop: props[i] };\n }\n return null;\n}\n\n/** Build a keyframe value AST node from properties and optional ease. */\nfunction buildKeyframeValueNode(\n properties: Record<string, number | string>,\n ease?: string,\n): AstNode {\n const entries = Object.entries(properties).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`);\n if (ease) entries.push(`ease: ${JSON.stringify(ease)}`);\n return parseExpr(`{ ${entries.join(\", \")} }`);\n}\n\n/** Parse + locate a target animation, returning null on failure. */\nfunction locateAnimation(\n script: string,\n animationId: string,\n): { parsed: ParsedGsapAst; target: ParsedGsapAst[\"located\"][number] } | null {\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch {\n return null;\n }\n const target = parsed.located.find((l) => l.id === animationId);\n return target ? { parsed, target } : null;\n}\n\n// Animation ids encode the tween's timeline position in ms\n// (`#puck-a-to-1200-position`). A gesture/convert can re-emit a tween at a\n// different position, changing its id — so a client that cached the old id (its\n// selectedGsapAnimations hasn't refreshed) edits a now-nonexistent id and the op\n// no-ops. Parse `{selector}-{method}-{posMs}-{group}` so we can fall back to the\n// same selector+method+group tween nearest the requested position.\nconst ANIM_ID_RE = /^(.*)-(fromTo|from|to|set)-(\\d+)-([a-z]+)$/;\n\nfunction locateAnimationWithFallback(\n script: string,\n animationId: string,\n): ReturnType<typeof locateAnimation> {\n const loc = locateAnimation(script, animationId);\n if (loc) return loc;\n const convertedId = animationId.replace(/-from-|-fromTo-/, \"-to-\");\n if (convertedId !== animationId) {\n const converted = locateAnimation(script, convertedId);\n if (converted) return converted;\n }\n // Position-drift fallback: match by stable identity (selector+method+group),\n // disambiguating by the position closest to the one the caller asked for.\n const want = ANIM_ID_RE.exec(animationId);\n if (!want) return null;\n const [, sel, method, wantPosStr, group] = want;\n const wantPos = Number(wantPosStr);\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch {\n return null;\n }\n let best: ParsedGsapAst[\"located\"][number] | null = null;\n let bestDist = Number.POSITIVE_INFINITY;\n for (const l of parsed.located) {\n const m = ANIM_ID_RE.exec(l.id);\n if (!m || m[1] !== sel || m[2] !== method || m[4] !== group) continue;\n const dist = Math.abs(Number(m[3]) - wantPos);\n if (dist < bestDist) {\n best = l;\n bestDist = dist;\n }\n }\n return best ? { parsed, target: best } : null;\n}\n\n/** Find the keyframes ObjectExpression node on a tween's varsArg, or null. */\nfunction findKeyframesObjectNode(varsArg: AstNode): AstNode | null {\n const node = findPropertyNode(varsArg, \"keyframes\");\n return node?.type === \"ObjectExpression\" ? node : null;\n}\n\n/**\n * Convert array-form keyframes (`keyframes: [{x,y}, …]`) to even-percentage object\n * form (`{ \"0%\": {…}, \"33.3%\": {…}, … }`) IN PLACE, returning the new object node\n * (or null if not array-form). GSAP distributes an array evenly, so this is\n * runtime-identical — but it gives the percentage-keyed write ops something to\n * target. Needed before INSERTING a keyframe at an arbitrary percentage, which an\n * even array can't host.\n */\nfunction convertArrayKeyframesToObjectNode(varsArg: AstNode): AstNode | null {\n if (varsArg?.type !== \"ObjectExpression\") return null;\n const prop = (varsArg.properties ?? []).find(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"keyframes\",\n );\n if (!prop || prop.value?.type !== \"ArrayExpression\") return null;\n const els: AstNode[] = (prop.value.elements ?? []).filter(\n (e: AstNode | null): e is AstNode => !!e && e.type === \"ObjectExpression\",\n );\n const n = els.length;\n if (n === 0) return null;\n const entries = els.map((el: AstNode, i: number) => {\n const pct = n > 1 ? Math.round((i / (n - 1)) * 1000) / 10 : 0;\n return `${JSON.stringify(`${pct}%`)}: ${recast.print(el).code}`;\n });\n prop.value = parseExpr(`{ ${entries.join(\", \")} }`);\n return prop.value;\n}\n\n/** Filter percentage-keyed properties from a keyframes ObjectExpression. */\nfunction filterPercentageProps(kfNode: AstNode): AstNode[] {\n return kfNode.properties.filter((p: AstNode) => {\n if (!isObjectProperty(p)) return false;\n const key = propKeyName(p);\n return typeof key === \"string\" && PERCENTAGE_KEY_RE.test(key);\n });\n}\n\n/**\n * Collapse a keyframes node to flat tween: apply `record` entries as vars keys,\n * then remove `keyframes` and `easeEach` from varsArg. Skips the `ease` key\n * from the record (per-keyframe ease, not a tween ease).\n */\nfunction collapseKeyframesToFlat(varsArg: AstNode, record: Record<string, unknown>): void {\n for (const [k, v] of Object.entries(record)) {\n if (k === \"ease\") continue;\n if (typeof v === \"number\" || typeof v === \"string\") setVarsKey(varsArg, k, v);\n }\n removeVarsKey(varsArg, \"keyframes\");\n removeVarsKey(varsArg, \"easeEach\");\n}\n\n/**\n * Locate an animation's keyframes ObjectExpression and build the percentage key.\n * Shared preamble for addKeyframeToScript, removeKeyframeFromScript, and\n * updateKeyframeInScript.\n */\nfunction locateKeyframeCtx(script: string, animationId: string, percentage: number) {\n const loc = locateAnimationWithFallback(script, animationId);\n if (!loc) return null;\n const kfNode = findKeyframesObjectNode(loc.target.call.varsArg);\n if (!kfNode) return null;\n return { loc, kfNode, pctKey: `${percentage}%` };\n}\n\n/**\n * Insert a keyframe at the given percentage in an existing percentage-keyframes\n * object. If the percentage already exists, its value is replaced.\n */\nexport function addKeyframeToScript(\n script: string,\n animationId: string,\n percentage: number,\n properties: Record<string, number | string>,\n ease?: string,\n backfillDefaults?: Record<string, number | string>,\n): string {\n let loc = locateAnimationWithFallback(script, animationId);\n if (!loc) return script;\n let kfNode = findKeyframesObjectNode(loc.target.call.varsArg);\n\n // Array-form keyframes can't host an arbitrary new percentage — normalize to\n // object form in place first. (convertToKeyframesInScript below only converts\n // FLAT tweens; it early-returns when keyframes already exist.)\n if (!kfNode) kfNode = convertArrayKeyframesToObjectNode(loc.target.call.varsArg);\n\n if (!kfNode) {\n script = convertToKeyframesInScript(script, animationId);\n loc = locateAnimationWithFallback(script, animationId);\n if (!loc) return script;\n kfNode = findKeyframesObjectNode(loc.target.call.varsArg);\n if (!kfNode) return script;\n }\n const pctKey = `${percentage}%`;\n\n const newValueNode = buildKeyframeValueNode(properties, ease);\n\n // Merge into existing keyframe at this percentage, or insert new\n const existing = findKeyframePropByPct(kfNode, percentage);\n if (existing) {\n if (existing.prop.value?.type === \"ObjectExpression\") {\n const existingRecord = objectExpressionToRecord(existing.prop.value, loc.parsed.scope);\n const merged = { ...existingRecord };\n for (const [k, v] of Object.entries(properties)) merged[k] = v;\n existing.prop.value = buildKeyframeValueNode(\n merged as Record<string, number | string>,\n ease ?? (typeof existingRecord.ease === \"string\" ? existingRecord.ease : undefined),\n );\n } else {\n existing.prop.value = newValueNode;\n }\n } else {\n // Build the new property node with a quoted percentage key\n const newProp = parseExpr(`{ ${JSON.stringify(pctKey)}: {} }`).properties[0];\n newProp.value = newValueNode;\n\n // Insert in sorted order by percentage\n let insertIdx = kfNode.properties.length;\n for (let i = 0; i < kfNode.properties.length; i++) {\n const key = isObjectProperty(kfNode.properties[i])\n ? propKeyName(kfNode.properties[i])\n : undefined;\n if (typeof key === \"string\" && percentageFromKey(key) > percentage) {\n insertIdx = i;\n break;\n }\n }\n kfNode.properties.splice(insertIdx, 0, newProp);\n }\n\n // Auto-update adjacent endpoints: only update an `_auto` 0% or 100%\n // keyframe when the new keyframe is directly next to it (no other keyframe\n // between them). This prevents a keyframe at 74% from clobbering 100% when\n // 75% already exists, and a keyframe at 30% from clobbering 0% when 25%\n // already exists.\n if (percentage > 0 && percentage < 100) {\n const pctProps = filterPercentageProps(kfNode);\n const allPcts = pctProps\n .map((p: AstNode) => percentageFromKey(propKeyName(p) ?? \"\"))\n .filter((n: number) => !Number.isNaN(n) && n !== percentage)\n .sort((a: number, b: number) => a - b);\n const leftNeighbor = allPcts.filter((p: number) => p < percentage).pop();\n const rightNeighbor = allPcts.find((p: number) => p > percentage);\n for (const endPct of [0, 100]) {\n const isNeighbor = endPct === 0 ? leftNeighbor === 0 : rightNeighbor === 100;\n if (!isNeighbor) continue;\n const endProp = pctProps.find(\n (p: AstNode) => percentageFromKey(propKeyName(p) ?? \"\") === endPct,\n );\n if (!endProp?.value || endProp.value.type !== \"ObjectExpression\") continue;\n const hasAuto = endProp.value.properties.some(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"_auto\",\n );\n if (!hasAuto) continue;\n const updatedProps = { ...properties, _auto: 1 as number | string };\n endProp.value = buildKeyframeValueNode(updatedProps, undefined);\n }\n }\n\n // Backfill: when the new keyframe introduces properties absent from other\n // keyframes, add default values so GSAP can interpolate them.\n if (backfillDefaults) {\n const newPropKeys = Object.keys(properties);\n const pctProps = filterPercentageProps(kfNode);\n for (const prop of pctProps) {\n const key = propKeyName(prop);\n if (key === pctKey) continue;\n const valObj = prop.value;\n if (!valObj || valObj.type !== \"ObjectExpression\") continue;\n const existingKeys = new Set(\n valObj.properties\n .filter((p: AstNode) => isObjectProperty(p))\n .map((p: AstNode) => propKeyName(p)),\n );\n for (const pk of newPropKeys) {\n if (existingKeys.has(pk)) continue;\n const defaultVal = backfillDefaults[pk];\n if (defaultVal == null) continue;\n const fillProp = parseExpr(`{ ${safeKey(pk)}: ${valueToCode(defaultVal)} }`).properties[0];\n valObj.properties.push(fillProp);\n }\n }\n }\n\n return recast.print(loc.parsed.ast).code;\n}\n\n/**\n * Remove a keyframe at the given percentage. If fewer than 2 keyframes remain\n * after removal, collapse the keyframes object to a flat tween using the\n * remaining keyframe's properties.\n */\nexport function removeKeyframeFromScript(\n script: string,\n animationId: string,\n percentage: number,\n): string {\n // Array-form keyframes (`keyframes: [{x,y}, …]`) have no explicit percentages —\n // GSAP distributes them evenly. The object-form path below can't see them\n // (findKeyframesObjectNode only matches ObjectExpression), so removing from an\n // array-form tween silently no-op'd. Resolve the element by its implicit\n // percentage and splice it; collapse to a flat tween when fewer than two remain.\n const arrLoc = locateAnimationWithFallback(script, animationId);\n // findPropertyNode here returns the property's VALUE node directly.\n const arrVal = arrLoc && findPropertyNode(arrLoc.target.call.varsArg, \"keyframes\");\n if (arrLoc && arrVal?.type === \"ArrayExpression\") {\n const elements: AstNode[] = (arrVal.elements ?? []).filter(\n (e: AstNode | null): e is AstNode => !!e && e.type === \"ObjectExpression\",\n );\n const n = elements.length;\n if (n === 0) return script;\n let matchIdx = -1;\n let bestDist = Number.POSITIVE_INFINITY;\n for (let i = 0; i < n; i++) {\n const pct = n > 1 ? (i / (n - 1)) * 100 : 0;\n const dist = Math.abs(pct - percentage);\n if (dist <= PCT_TOLERANCE && dist < bestDist) {\n matchIdx = i;\n bestDist = dist;\n }\n }\n if (matchIdx === -1) return script;\n const remaining = elements.filter((_, i) => i !== matchIdx);\n if (remaining.length < 2) {\n const sole = remaining[0];\n const record = sole ? objectExpressionToRecord(sole, arrLoc.parsed.scope) : {};\n collapseKeyframesToFlat(arrLoc.target.call.varsArg, record);\n } else {\n const realIdx = arrVal.elements.indexOf(elements[matchIdx]);\n arrVal.elements.splice(realIdx, 1);\n }\n return recast.print(arrLoc.parsed.ast).code;\n }\n\n const ctx = locateKeyframeCtx(script, animationId, percentage);\n if (!ctx) return script;\n const { loc, kfNode } = ctx;\n\n const match = findKeyframePropByPct(kfNode, percentage);\n if (!match) return script;\n const removeIdx = match.idx;\n\n kfNode.properties.splice(removeIdx, 1);\n\n const remainingKfs = filterPercentageProps(kfNode);\n if (remainingKfs.length < 2) {\n const record =\n remainingKfs.length === 1\n ? objectExpressionToRecord(remainingKfs[0]!.value, loc.parsed.scope)\n : {};\n collapseKeyframesToFlat(loc.target.call.varsArg, record);\n }\n\n return recast.print(loc.parsed.ast).code;\n}\n\n/**\n * Replace the properties (and optionally ease) at an existing keyframe percentage.\n */\nexport function updateKeyframeInScript(\n script: string,\n animationId: string,\n percentage: number,\n properties: Record<string, number | string>,\n ease?: string,\n): string {\n // Array-form keyframes (`keyframes: [{x,y}, …]`) have no explicit percentages —\n // GSAP distributes them evenly. The percentage-keyed object path below can't\n // match them (findKeyframesObjectNode only matches ObjectExpression), so dragging\n // a motion-path node on an array-authored tween silently no-op'd. Resolve the\n // element by its implicit percentage and replace it in place. Mirrors the array\n // branch in removeKeyframeFromScript.\n const arrLoc = locateAnimationWithFallback(script, animationId);\n const arrVal = arrLoc && findPropertyNode(arrLoc.target.call.varsArg, \"keyframes\");\n if (arrLoc && arrVal?.type === \"ArrayExpression\") {\n const elements: AstNode[] = (arrVal.elements ?? []).filter(\n (e: AstNode | null): e is AstNode => !!e && e.type === \"ObjectExpression\",\n );\n const n = elements.length;\n if (n === 0) return script;\n let matchIdx = -1;\n let bestDist = Number.POSITIVE_INFINITY;\n for (let i = 0; i < n; i++) {\n const pct = n > 1 ? (i / (n - 1)) * 100 : 0;\n const dist = Math.abs(pct - percentage);\n if (dist <= PCT_TOLERANCE && dist < bestDist) {\n matchIdx = i;\n bestDist = dist;\n }\n }\n if (matchIdx === -1) return script;\n const realIdx = arrVal.elements.indexOf(elements[matchIdx]);\n arrVal.elements[realIdx] = buildKeyframeValueNode(properties, ease);\n return recast.print(arrLoc.parsed.ast).code;\n }\n\n const ctx = locateKeyframeCtx(script, animationId, percentage);\n if (!ctx) return script;\n const { loc, kfNode } = ctx;\n\n const match = findKeyframePropByPct(kfNode, percentage);\n if (!match) return script;\n\n if (Object.keys(properties).length === 0 && ease) {\n // Ease-only update: preserve existing properties, just add/replace ease\n const existing = match.prop.value;\n if (existing?.type === \"ObjectExpression\") {\n const props = (existing.properties ?? []) as AstNode[];\n const easeIdx = props.findIndex(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"ease\",\n );\n const easeNode = parseExpr(`({ ease: ${JSON.stringify(ease)} })`).properties[0];\n if (easeIdx >= 0) {\n props[easeIdx] = easeNode;\n } else {\n props.push(easeNode);\n }\n return recast.print(loc.parsed.ast).code;\n }\n // Non-object keyframe value (primitive shorthand, e.g. \"50%\": \"0.5\"): there\n // is no property bag to merge the ease into. Rebuilding from empty\n // `properties` would wipe the primitive — leave the keyframe untouched.\n return script;\n }\n match.prop.value = buildKeyframeValueNode(properties, ease);\n return recast.print(loc.parsed.ast).code;\n}\n\n/** Strip editable properties and ease/keyframes keys from a varsArg. */\nfunction stripEditableAndEase(varsArg: AstNode): void {\n // ease is a BUILTIN_VAR_KEY (not editable), so filterEditableKeys won't remove it —\n // drop it explicitly before filtering, along with keyframes.\n if (varsArg?.type !== \"ObjectExpression\") return;\n varsArg.properties = varsArg.properties.filter((p: AstNode) => {\n if (!isObjectProperty(p)) return true;\n const key = propKeyName(p);\n return key !== \"ease\" && key !== \"keyframes\";\n });\n filterEditableKeys(varsArg, () => false);\n}\n\n/** Build and prepend a keyframes property node onto varsArg. */\nfunction insertKeyframesProp(\n varsArg: AstNode,\n fromProps: Record<string, number | string>,\n toProps: Record<string, number | string>,\n easeEach?: string,\n): void {\n const fromEntries = Object.entries(fromProps).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`);\n const toEntries = Object.entries(toProps).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`);\n const easeEntry = easeEach ? `, easeEach: ${JSON.stringify(easeEach)}` : \"\";\n const kfCode = `{ \"0%\": { ${fromEntries.join(\", \")} }, \"100%\": { ${toEntries.join(\", \")} }${easeEntry} }`;\n const kfProp = parseExpr(`{ keyframes: {} }`).properties[0];\n kfProp.value = parseExpr(kfCode);\n if (varsArg?.type === \"ObjectExpression\") varsArg.properties.unshift(kfProp);\n}\n\n/**\n * Convert a flat tween (to/from/fromTo) to percentage-keyframes format.\n * `resolvedFromValues` supplies the \"from\" state for `to()` tweens or\n * the \"to\" state for `from()` tweens (the values the DOM would resolve to).\n */\nexport function convertToKeyframesInScript(\n script: string,\n animationId: string,\n resolvedFromValues?: Record<string, number | string>,\n setDuration = 1,\n): string {\n let loc = locateAnimationWithFallback(script, animationId);\n if (!loc) return script;\n\n const anim = loc.target.animation;\n if (anim.keyframes) return script;\n\n const { fromProps, toProps } = resolveConversionProps(anim, resolvedFromValues);\n const varsArg = loc.target.call.varsArg;\n const originalEase = anim.ease;\n\n stripEditableAndEase(varsArg);\n insertKeyframesProp(varsArg, fromProps, toProps, originalEase || undefined);\n\n if (originalEase) {\n setVarsKey(varsArg, \"ease\", \"none\");\n }\n\n // For from() or fromTo(), convert to to()\n if (anim.method === \"from\" || anim.method === \"fromTo\") {\n loc.target.call.node.callee.property.name = \"to\";\n if (anim.method === \"fromTo\") loc.target.call.node.arguments.splice(1, 1);\n }\n\n // A static `set` becomes an animatable `to`: flip the method, drop the\n // immediateRender hold marker, and give it a real duration so the keyframes\n // span time. This is what makes a static 3D transform keyframeable.\n if (anim.method === \"set\") {\n // A GLOBAL `gsap.set(...)` is off-timeline; flipping only the method would\n // emit `gsap.to(...)`, which fires once at load and is NOT on the paused\n // master timeline (the engine can't seek/render it). Re-root it onto the\n // timeline var and add the position arg (a gsap.set has none) so the\n // converted tween is seekable. A `tl.set` already has the right object.\n const calleeObj = loc.target.call.node.callee.object;\n if (anim.global && calleeObj?.type === \"Identifier\") {\n calleeObj.name = loc.parsed.timelineVar;\n if (loc.target.call.node.arguments.length < 3) {\n loc.target.call.node.arguments.push(parseExpr(\"0\"));\n }\n }\n loc.target.call.node.callee.property.name = \"to\";\n removeVarsKey(varsArg, \"immediateRender\");\n setVarsKey(varsArg, \"duration\", Math.max(0.001, setDuration));\n }\n\n return recast.print(loc.parsed.ast).code;\n}\n\n/**\n * Remove all keyframes from a tween, collapsing to a flat tween with the\n * last keyframe's properties.\n */\nexport function removeAllKeyframesFromScript(script: string, animationId: string): string {\n let loc = locateAnimationWithFallback(script, animationId);\n if (!loc) return script;\n const kfNode = findKeyframesObjectNode(loc.target.call.varsArg);\n if (!kfNode) return script;\n\n const kfEntries = filterPercentageProps(kfNode)\n .map((p: AstNode) => ({ pct: percentageFromKey(propKeyName(p)!), prop: p }))\n .filter((e) => !Number.isNaN(e.pct))\n .sort((a, b) => a.pct - b.pct);\n if (kfEntries.length === 0) return script;\n\n // For to()/set(): collapse to last keyframe (the destination = visible state).\n // For from(): collapse to first keyframe (the starting state).\n const method = loc.target.call.method;\n const collapseEntry = method === \"from\" ? kfEntries[0]! : kfEntries[kfEntries.length - 1]!;\n const record = objectExpressionToRecord(collapseEntry.prop.value, loc.parsed.scope);\n collapseKeyframesToFlat(loc.target.call.varsArg, record);\n\n return recast.print(loc.parsed.ast).code;\n}\n\n/**\n * Replace a dynamic `keyframes: <expr>` with a static percentage-keyframes object.\n * Called when the user first edits a dynamically-generated keyframe in the studio.\n */\nexport function materializeKeyframesInScript(\n script: string,\n animationId: string,\n keyframes: Array<{\n percentage: number;\n properties: Record<string, number | string>;\n ease?: string;\n }>,\n easeEach?: string,\n resolvedSelector?: string,\n): string {\n let loc = locateAnimationWithFallback(script, animationId);\n if (!loc) return script;\n\n const varsArg = loc.target.call.varsArg;\n\n // Replace dynamic selector with resolved static string\n if (resolvedSelector && loc.target.call.node.arguments[0]) {\n loc.target.call.node.arguments[0] = parseExpr(JSON.stringify(resolvedSelector));\n }\n\n const kfObjCode = buildKeyframeObjectCode(sortedKeyframes(keyframes), { easeEach });\n const kfParent = varsArg.properties.find(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"keyframes\",\n );\n if (kfParent) {\n kfParent.value = parseExpr(kfObjCode);\n } else {\n const kfProp = parseExpr(`{ keyframes: ${kfObjCode} }`).properties[0];\n varsArg.properties.unshift(kfProp);\n }\n\n removeVarsKey(varsArg, \"easeEach\");\n\n return recast.print(loc.parsed.ast).code;\n}\n\n// ── Arc Path (motionPath) AST Mutations ──────────────────────────────────\n\nfunction numericXY(props: Record<string, number | string>): { x: number; y: number } | null {\n const x = props.x;\n const y = props.y;\n return typeof x === \"number\" && typeof y === \"number\" ? { x, y } : null;\n}\n\nfunction extractArcWaypoints(anim: GsapAnimation): Array<{ x: number; y: number }> {\n const kfs = anim.keyframes?.keyframes ?? [];\n const waypoints = kfs.map((kf) => numericXY(kf.properties)).filter((p) => p !== null);\n if (waypoints.length >= 2) return waypoints;\n const px = anim.properties.x;\n const py = anim.properties.y;\n if (typeof px !== \"number\" && typeof py !== \"number\") return waypoints;\n return [\n { x: 0, y: 0 },\n { x: typeof px === \"number\" ? px : 0, y: typeof py === \"number\" ? py : 0 },\n ];\n}\n\nfunction buildMotionPathObjectCode(config: {\n waypoints: Array<{ x: number; y: number }>;\n segments: ArcPathSegment[];\n autoRotate: boolean | number;\n}): string {\n const { waypoints, segments, autoRotate } = config;\n const hasExplicitControlPoints = segments.some((s) => s.cp1 && s.cp2);\n // The simple `path` array supports only one scalar curviness for the whole\n // path, so per-segment curviness must use the cubic form (curviness baked into\n // each segment's control points). Without this, the simple branch serializes\n // only segments[0].curviness and silently drops every other segment's curve.\n const curvinessVaries = segments.some(\n (s) => (s.curviness ?? 1) !== (segments[0]?.curviness ?? 1),\n );\n\n let pathEntries: string[];\n if ((hasExplicitControlPoints || curvinessVaries) && waypoints.length >= 2) {\n // type: \"cubic\" — interleave control points: [anchor, cp1, cp2, anchor, ...]\n pathEntries = [`{x: ${waypoints[0]!.x}, y: ${waypoints[0]!.y}}`];\n for (let i = 0; i < segments.length; i++) {\n const seg = segments[i]!;\n const nextWp = waypoints[i + 1]!;\n if (seg.cp1 && seg.cp2) {\n pathEntries.push(`{x: ${seg.cp1.x}, y: ${seg.cp1.y}}`);\n pathEntries.push(`{x: ${seg.cp2.x}, y: ${seg.cp2.y}}`);\n } else {\n // Auto-generate simple midpoint control points from curviness\n const wp = waypoints[i]!;\n const dx = nextWp.x - wp.x;\n const dy = nextWp.y - wp.y;\n const c = seg.curviness ?? 1;\n pathEntries.push(\n `{x: ${wp.x + dx * 0.33}, y: ${wp.y + dy * 0.33 - c * Math.abs(dx) * 0.25}}`,\n );\n pathEntries.push(\n `{x: ${wp.x + dx * 0.66}, y: ${wp.y + dy * 0.66 - c * Math.abs(dx) * 0.25}}`,\n );\n }\n pathEntries.push(`{x: ${nextWp.x}, y: ${nextWp.y}}`);\n }\n const pathStr = pathEntries.join(\", \");\n const parts = [`path: [${pathStr}]`, `type: \"cubic\"`];\n if (autoRotate === true) parts.push(\"autoRotate: true\");\n else if (typeof autoRotate === \"number\") parts.push(`autoRotate: ${autoRotate}`);\n return `{ ${parts.join(\", \")} }`;\n }\n\n // Simple waypoint array with curviness\n pathEntries = waypoints.map((wp) => `{x: ${wp.x}, y: ${wp.y}}`);\n const curviness = segments[0]?.curviness ?? 1;\n const parts = [`path: [${pathEntries.join(\", \")}]`];\n if (curviness !== 1) parts.push(`curviness: ${curviness}`);\n if (autoRotate === true) parts.push(\"autoRotate: true\");\n else if (typeof autoRotate === \"number\") parts.push(`autoRotate: ${autoRotate}`);\n return `{ ${parts.join(\", \")} }`;\n}\n\nexport function setArcPathInScript(\n script: string,\n animationId: string,\n config: ArcPathConfig,\n): string {\n const loc = locateAnimation(script, animationId);\n if (!loc) return script;\n\n const varsArg = loc.target.call.varsArg;\n const anim = loc.target.animation;\n\n if (!config.enabled) {\n // Disable arc: restore x/y from motionPath's last waypoint, then remove motionPath\n const motionPathProp = varsArg.properties.find(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"motionPath\",\n );\n if (motionPathProp) {\n const mpVal = motionPathProp.value;\n let pathArr: AstNode[] | undefined;\n if (mpVal?.type === \"ObjectExpression\") {\n const pathProp = mpVal.properties.find(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"path\",\n );\n if (pathProp?.value?.type === \"ArrayExpression\") pathArr = pathProp.value.elements;\n }\n if (pathArr && pathArr.length > 0) {\n const last = pathArr[pathArr.length - 1];\n if (last?.type === \"ObjectExpression\") {\n for (const p of last.properties) {\n const k = propKeyName(p);\n if (k === \"x\" || k === \"y\") {\n const v = p.value?.value;\n if (typeof v === \"number\") setVarsKey(varsArg, k, v);\n }\n }\n }\n }\n }\n removeVarsKey(varsArg, \"motionPath\");\n return recast.print(loc.parsed.ast).code;\n }\n\n const waypoints = extractArcWaypoints(anim);\n if (waypoints.length < 2) return script;\n\n // Build segments — use provided segments or create defaults\n const segments: ArcPathSegment[] =\n config.segments.length === waypoints.length - 1\n ? config.segments\n : Array.from({ length: waypoints.length - 1 }, () => ({ curviness: 1 }));\n\n const motionPathCode = buildMotionPathObjectCode({\n waypoints,\n segments,\n autoRotate: config.autoRotate,\n });\n\n // Set motionPath on the vars\n const motionPathNode = parseExpr(motionPathCode);\n const existingProp = varsArg.properties.find(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"motionPath\",\n );\n if (existingProp) {\n existingProp.value = motionPathNode;\n } else {\n const prop = parseExpr(`{ motionPath: ${motionPathCode} }`).properties[0];\n varsArg.properties.push(prop);\n }\n\n // Strip x/y from keyframes (they're now in motionPath)\n const kfNode = findKeyframesObjectNode(varsArg);\n if (kfNode) {\n for (const pctProp of filterPercentageProps(kfNode)) {\n if (pctProp.value?.type === \"ObjectExpression\") {\n pctProp.value.properties = pctProp.value.properties.filter((p: AstNode) => {\n const k = propKeyName(p);\n return k !== \"x\" && k !== \"y\";\n });\n }\n }\n }\n\n // Strip flat x/y from vars (they're now in motionPath)\n removeVarsKey(varsArg, \"x\");\n removeVarsKey(varsArg, \"y\");\n\n return recast.print(loc.parsed.ast).code;\n}\n\nexport function updateArcSegmentInScript(\n script: string,\n animationId: string,\n segmentIndex: number,\n update: Partial<ArcPathSegment>,\n): string {\n const loc = locateAnimation(script, animationId);\n if (!loc) return script;\n\n const anim = loc.target.animation;\n if (!anim.arcPath?.enabled) return script;\n\n const segments = [...anim.arcPath.segments];\n if (segmentIndex < 0 || segmentIndex >= segments.length) return script;\n\n segments[segmentIndex] = { ...segments[segmentIndex]!, ...update };\n\n const waypoints = extractArcWaypoints(anim);\n if (waypoints.length < 2) return script;\n\n const motionPathCode = buildMotionPathObjectCode({\n waypoints,\n segments,\n autoRotate: anim.arcPath.autoRotate,\n });\n\n const varsArg = loc.target.call.varsArg;\n const existingProp = varsArg.properties.find(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"motionPath\",\n );\n if (existingProp) {\n existingProp.value = parseExpr(motionPathCode);\n }\n\n return recast.print(loc.parsed.ast).code;\n}\n\n/**\n * Move a single motionPath waypoint (anchor) to a new position. The waypoint\n * list is normalized to anchors for both straight and cubic paths, so\n * `pointIndex` matches the node order the studio overlay renders; cubic control\n * points are preserved. No-op when the animation/arc is missing or the index is\n * out of range.\n */\nexport function updateMotionPathPointInScript(\n script: string,\n animationId: string,\n pointIndex: number,\n point: { x: number; y: number },\n): string {\n const loc = locateAnimation(script, animationId);\n if (!loc) return script;\n\n const anim = loc.target.animation;\n if (!anim.arcPath?.enabled) return script;\n\n const waypoints = extractArcWaypoints(anim);\n if (pointIndex < 0 || pointIndex >= waypoints.length || waypoints.length < 2) return script;\n\n const nextWaypoints = waypoints.map((wp, i) =>\n i === pointIndex ? { x: point.x, y: point.y } : wp,\n );\n\n const motionPathCode = buildMotionPathObjectCode({\n waypoints: nextWaypoints,\n segments: anim.arcPath.segments,\n autoRotate: anim.arcPath.autoRotate,\n });\n\n const varsArg = loc.target.call.varsArg;\n const existingProp = varsArg.properties.find(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"motionPath\",\n );\n if (existingProp) {\n existingProp.value = parseExpr(motionPathCode);\n }\n\n return recast.print(loc.parsed.ast).code;\n}\n\n/** True when any segment carries explicit cubic control points. Add/remove are\n * restricted to curviness (non-cubic) paths — synthesizing control points for\n * an inserted cubic anchor is out of scope. */\nfunction hasCubicSegments(segments: ArcPathSegment[]): boolean {\n return segments.some((s) => s.cp1 != null || s.cp2 != null);\n}\n\nfunction writeMotionPathValue(\n loc: NonNullable<ReturnType<typeof locateAnimation>>,\n waypoints: Array<{ x: number; y: number }>,\n segments: ArcPathSegment[],\n autoRotate: boolean | number,\n): string {\n const motionPathCode = buildMotionPathObjectCode({ waypoints, segments, autoRotate });\n const varsArg = loc.target.call.varsArg;\n const existingProp = varsArg.properties.find(\n (p: AstNode) => isObjectProperty(p) && propKeyName(p) === \"motionPath\",\n );\n if (existingProp) existingProp.value = parseExpr(motionPathCode);\n return recast.print(loc.parsed.ast).code;\n}\n\n/**\n * Insert a waypoint at `index` (between existing anchors), splitting the segment\n * it lands on so the new neighbor inherits its curviness. Non-cubic paths only.\n * No-op for missing animation/arc, out-of-range index, or cubic paths.\n */\nexport function addMotionPathPointInScript(\n script: string,\n animationId: string,\n index: number,\n point: { x: number; y: number },\n): string {\n const loc = locateAnimation(script, animationId);\n if (!loc) return script;\n const anim = loc.target.animation;\n if (!anim.arcPath?.enabled || hasCubicSegments(anim.arcPath.segments)) return script;\n\n const waypoints = extractArcWaypoints(anim);\n // Insert strictly between two anchors: index 1..length-1.\n if (index < 1 || index > waypoints.length - 1) return script;\n\n const segments = [...anim.arcPath.segments];\n waypoints.splice(index, 0, { x: point.x, y: point.y });\n const splitCurviness = segments[index - 1]?.curviness ?? 1;\n segments.splice(index - 1, 0, { curviness: splitCurviness });\n\n return writeMotionPathValue(loc, waypoints, segments, anim.arcPath.autoRotate);\n}\n\n/**\n * Remove the waypoint at `index`. Refuses to drop below two anchors (a path\n * can't have fewer). Non-cubic paths only. No-op for missing animation/arc,\n * out-of-range index, cubic paths, or a 2-point path.\n */\nexport function removeMotionPathPointInScript(\n script: string,\n animationId: string,\n index: number,\n): string {\n const loc = locateAnimation(script, animationId);\n if (!loc) return script;\n const anim = loc.target.animation;\n if (!anim.arcPath?.enabled || hasCubicSegments(anim.arcPath.segments)) return script;\n\n const waypoints = extractArcWaypoints(anim);\n if (waypoints.length <= 2 || index < 0 || index >= waypoints.length) return script;\n\n const segments = [...anim.arcPath.segments];\n waypoints.splice(index, 1);\n // Drop the segment on the side that still exists (last anchor → preceding segment).\n segments.splice(Math.min(index, segments.length - 1), 1);\n\n return writeMotionPathValue(loc, waypoints, segments, anim.arcPath.autoRotate);\n}\n\n/**\n * Author a fresh 2-anchor motionPath tween on a target element: a straight line\n * from the element's home (0,0) to `point`, gentle ease, ready for waypoint\n * editing. Mirrors `addAnimationWithKeyframesToScript`.\n */\nexport function addMotionPathToScript(\n script: string,\n targetSelector: string,\n position: number,\n duration: number,\n point: { x: number; y: number },\n ease = \"power1.inOut\",\n): { script: string; id: string | null } {\n // `id: null` on the failure paths is a deliberate sentinel: callers must\n // null-check before chaining (e.g. locating the new tween). An empty string\n // would silently flow into selector/locate calls and match nothing.\n let parsed: ParsedGsapAst;\n try {\n parsed = parseGsapAst(script);\n } catch (e) {\n console.warn(\"[gsap-parser] addMotionPathToScript parse failed:\", e);\n return { script, id: null };\n }\n if (parsed.located.length === 0 && parsed.detection.timelineVar === null) {\n return { script, id: null };\n }\n\n const motionPathCode = buildMotionPathObjectCode({\n waypoints: [\n { x: 0, y: 0 },\n { x: point.x, y: point.y },\n ],\n segments: [{ curviness: 1 }],\n autoRotate: false,\n });\n const selector = JSON.stringify(targetSelector);\n const varEntries = [\n `motionPath: ${motionPathCode}`,\n `duration: ${valueToCode(duration)}`,\n `ease: ${JSON.stringify(ease)}`,\n ];\n const stmtCode = `${parsed.timelineVar}.to(${selector}, { ${varEntries.join(\", \")} }, ${valueToCode(position)});`;\n const newStatement = parseScript(stmtCode).program.body[0];\n insertAfterAnchor(parsed, newStatement);\n\n const result = recast.print(parsed.ast).code;\n const reParsed = parseGsapAst(result);\n const newId = reParsed.located[reParsed.located.length - 1]?.id ?? null;\n return { script: result, id: newId };\n}\n\nexport function removeArcPathFromScript(script: string, animationId: string): string {\n return setArcPathInScript(script, animationId, {\n enabled: false,\n autoRotate: false,\n segments: [],\n });\n}\n\n// ── Split Into Property Groups ────────────────────────────────────────────\n\n/**\n * Split a multi-group tween into separate per-group tweens. Each resulting\n * tween contains only properties belonging to one property group (position,\n * scale, rotation, visual, etc.). `transformOrigin` stays with the group that\n * has the most properties. If the tween already belongs to a single group,\n * returns the script unchanged with the original ID.\n */\n// fallow-ignore-next-line complexity\nexport function splitIntoPropertyGroups(\n script: string,\n animationId: string,\n): { script: string; ids: string[] } {\n let loc = locateAnimationWithFallback(script, animationId);\n if (!loc) return { script, ids: [animationId] };\n\n const anim = loc.target.animation;\n\n // Collect the properties to partition. For keyframed tweens, gather the\n // union of all properties across all keyframes. For flat tweens, use the\n // tween's own properties map.\n const allPropKeys = new Set<string>();\n if (anim.keyframes) {\n for (const kf of anim.keyframes.keyframes) {\n for (const k of Object.keys(kf.properties)) allPropKeys.add(k);\n }\n } else {\n for (const k of Object.keys(anim.properties)) allPropKeys.add(k);\n }\n\n // Partition properties into groups (excluding transformOrigin — handled below).\n const groupProps = new Map<PropertyGroupName, string[]>();\n for (const key of allPropKeys) {\n if (key === \"transformOrigin\") continue;\n const group = classifyPropertyGroup(key);\n let arr = groupProps.get(group);\n if (!arr) {\n arr = [];\n groupProps.set(group, arr);\n }\n arr.push(key);\n }\n\n // Only one group (or zero) — no split needed.\n if (groupProps.size <= 1) return { script, ids: [anim.id] };\n\n // Assign transformOrigin to the group with the most properties.\n if (allPropKeys.has(\"transformOrigin\")) {\n let largestGroup: PropertyGroupName | undefined;\n let largestCount = 0;\n for (const [group, props] of groupProps) {\n if (props.length > largestCount) {\n largestCount = props.length;\n largestGroup = group;\n }\n }\n if (largestGroup) {\n groupProps.get(largestGroup)!.push(\"transformOrigin\");\n }\n }\n\n // Build per-group tweens and insert them, then remove the original.\n let result = script;\n\n // Remove the original tween first.\n result = removeAnimationFromScript(result, anim.id);\n\n // Insert one tween per group. Iteration order of the Map follows insertion\n // order, which mirrors the order properties were encountered.\n for (const [, props] of groupProps) {\n const propSet = new Set(props);\n\n if (anim.keyframes) {\n // Build keyframes containing only this group's properties per keyframe.\n const groupKeyframes: Array<{\n percentage: number;\n properties: Record<string, number | string>;\n ease?: string;\n auto?: boolean;\n }> = [];\n\n for (const kf of anim.keyframes.keyframes) {\n const filtered: Record<string, number | string> = {};\n for (const [k, v] of Object.entries(kf.properties)) {\n if (propSet.has(k)) filtered[k] = v;\n }\n // Skip keyframes where this group has zero properties.\n if (Object.keys(filtered).length === 0) continue;\n groupKeyframes.push({\n percentage: kf.percentage,\n properties: filtered,\n ...(kf.ease ? { ease: kf.ease } : {}),\n });\n }\n\n if (groupKeyframes.length === 0) continue;\n\n const addResult = addAnimationWithKeyframesToScript(\n result,\n anim.targetSelector,\n typeof anim.position === \"number\" ? anim.position : 0,\n anim.duration ?? 0.5,\n groupKeyframes,\n anim.keyframes.easeEach ?? anim.ease,\n );\n result = addResult.script;\n } else {\n // Flat tween — filter properties to this group.\n const groupProperties: Record<string, number | string> = {};\n for (const [k, v] of Object.entries(anim.properties)) {\n if (propSet.has(k)) groupProperties[k] = v;\n }\n if (Object.keys(groupProperties).length === 0) continue;\n\n let fromProperties: Record<string, number | string> | undefined;\n if (anim.method === \"fromTo\" && anim.fromProperties) {\n fromProperties = {};\n for (const [k, v] of Object.entries(anim.fromProperties)) {\n if (propSet.has(k)) fromProperties[k] = v;\n }\n }\n\n const addResult = addAnimationToScript(result, {\n targetSelector: anim.targetSelector,\n method: anim.method,\n position: anim.position,\n duration: anim.duration,\n ease: anim.ease,\n properties: groupProperties,\n fromProperties,\n extras: anim.extras,\n });\n result = addResult.script;\n }\n }\n\n // Re-parse to collect the new IDs.\n const reParsed = parseGsapAst(result);\n const newIds = reParsed.located\n .filter((l) => l.animation.targetSelector === anim.targetSelector)\n .map((l) => l.id);\n\n return { script: result, ids: newIds };\n}\n\n/**\n * Replace a dynamic loop that generates multiple tween calls with individual\n * static `tl.to()` calls — one per element. Finds the loop containing the\n * animation and replaces the entire loop body with unrolled static calls.\n */\nexport function unrollDynamicAnimations(\n script: string,\n animationId: string,\n elements: Array<{\n selector: string;\n keyframes: Array<{ percentage: number; properties: Record<string, number | string> }>;\n easeEach?: string;\n }>,\n): string {\n const loc = locateAnimation(script, animationId);\n if (!loc) return script;\n\n const varsArg = loc.target.call.varsArg;\n\n // Read duration and ease from the original tween vars\n const durationVal = extractLiteralValue(findPropertyNode(varsArg, \"duration\"), loc.parsed.scope);\n const easeVal = extractLiteralValue(findPropertyNode(varsArg, \"ease\"), loc.parsed.scope);\n const duration = typeof durationVal === \"number\" ? durationVal : 8;\n const ease = typeof easeVal === \"string\" ? easeVal : \"none\";\n const posArg = loc.target.call.positionArg;\n const position = posArg ? extractLiteralValue(posArg, loc.parsed.scope) : 0;\n const posCode =\n typeof position === \"number\"\n ? String(position)\n : typeof position === \"string\"\n ? JSON.stringify(position)\n : \"0\";\n\n // Find the enclosing loop (for/forEach) by walking up the AST path\n let loopNode: AstNode | null = null;\n let current = loc.target.call.path;\n while (current) {\n const node = current.node ?? current.value;\n if (\n node?.type === \"ForStatement\" ||\n node?.type === \"ForInStatement\" ||\n node?.type === \"ForOfStatement\" ||\n node?.type === \"WhileStatement\"\n ) {\n loopNode = node;\n break;\n }\n if (\n node?.type === \"ExpressionStatement\" &&\n node.expression?.type === \"CallExpression\" &&\n node.expression.callee?.property?.name === \"forEach\"\n ) {\n loopNode = node;\n break;\n }\n current = current.parent ?? current.parentPath;\n }\n\n // Build replacement code: individual tl.to() calls for each element\n const calls: string[] = [];\n for (const el of elements) {\n const kfCode = buildKeyframeObjectCode(sortedKeyframes(el.keyframes), {\n easeEach: el.easeEach,\n });\n calls.push(\n `${loc.parsed.timelineVar}.to(${JSON.stringify(el.selector)}, { keyframes: ${kfCode}, duration: ${duration}, ease: ${JSON.stringify(ease)} }, ${posCode});`,\n );\n }\n\n const replacement = calls.join(\"\\n \");\n\n if (loopNode) {\n // Replace the entire loop with the unrolled calls\n const start = loopNode.start ?? loopNode.range?.[0];\n const end = loopNode.end ?? loopNode.range?.[1];\n if (typeof start === \"number\" && typeof end === \"number\") {\n return script.slice(0, start) + replacement + script.slice(end);\n }\n }\n\n // Fallback: replace just the tween call's enclosing expression statement\n const stmtNode = loc.target.call.path?.parent?.node ?? loc.target.call.path?.parentPath?.node;\n if (stmtNode?.type === \"ExpressionStatement\") {\n const start = stmtNode.start ?? stmtNode.range?.[0];\n const end = stmtNode.end ?? stmtNode.range?.[1];\n if (typeof start === \"number\" && typeof end === \"number\") {\n return script.slice(0, start) + replacement + script.slice(end);\n }\n }\n\n return script;\n}\n","/**\n * Damped harmonic oscillator solver for GSAP CustomEase spring curves.\n *\n * Generates an SVG path data string compatible with `CustomEase.create(id, data)`.\n * The solver supports underdamped (bouncy), critically damped, and overdamped\n * spring configurations. Output is normalized to x ∈ [0,1] with y starting at 0\n * and settling to 1.\n */\n\nexport interface SpringPreset {\n name: string;\n label: string;\n mass: number;\n stiffness: number;\n damping: number;\n}\n\nexport const SPRING_PRESETS: SpringPreset[] = [\n { name: \"spring-gentle\", label: \"Gentle\", mass: 1, stiffness: 100, damping: 15 },\n { name: \"spring-bouncy\", label: \"Bouncy\", mass: 1, stiffness: 180, damping: 12 },\n { name: \"spring-stiff\", label: \"Stiff\", mass: 1, stiffness: 300, damping: 20 },\n { name: \"spring-wobbly\", label: \"Wobbly\", mass: 1, stiffness: 120, damping: 8 },\n { name: \"spring-heavy\", label: \"Heavy\", mass: 3, stiffness: 200, damping: 20 },\n];\n\n/**\n * Solve a damped harmonic oscillator and return a GSAP CustomEase data string.\n *\n * The output is an SVG path (`M0,0 L... L...`) that CustomEase.create() accepts.\n * The curve is normalized so x spans [0,1] and the spring settles at y = 1.\n *\n * @param mass - Spring mass (> 0)\n * @param stiffness - Spring stiffness constant (> 0)\n * @param damping - Damping coefficient (> 0)\n * @param steps - Number of sample points (default 120)\n */\nexport function generateSpringEaseData(\n mass: number,\n stiffness: number,\n damping: number,\n steps = 120,\n): string {\n const w0 = Math.sqrt(stiffness / mass);\n const zeta = damping / (2 * Math.sqrt(stiffness * mass));\n\n // Determine simulation duration: time until oscillation settles within threshold of 1.0.\n // Underdamped: ~5 time constants. Critically/overdamped: characteristic decay time.\n let settleDuration: number;\n if (zeta < 1) {\n settleDuration = Math.min(5 / (zeta * w0), 10);\n } else {\n const decayRate = zeta * w0 - w0 * Math.sqrt(zeta * zeta - 1);\n settleDuration = Math.min(4 / Math.max(decayRate, 0.01), 10);\n }\n const simDuration = Math.max(settleDuration, 1);\n\n const segments: string[] = [\"M0,0\"];\n\n for (let i = 1; i <= steps; i++) {\n const t = i / steps;\n const simT = t * simDuration;\n let value: number;\n\n if (zeta < 1) {\n // Underdamped — oscillates before settling\n const wd = w0 * Math.sqrt(1 - zeta * zeta);\n value =\n 1 -\n Math.exp(-zeta * w0 * simT) *\n (Math.cos(wd * simT) + ((zeta * w0) / wd) * Math.sin(wd * simT));\n } else if (zeta === 1) {\n // Critically damped — fastest approach without oscillation\n value = 1 - (1 + w0 * simT) * Math.exp(-w0 * simT);\n } else {\n // Overdamped — slow exponential approach\n const s1 = -w0 * (zeta - Math.sqrt(zeta * zeta - 1));\n const s2 = -w0 * (zeta + Math.sqrt(zeta * zeta - 1));\n value = 1 + (s1 * Math.exp(s2 * simT) - s2 * Math.exp(s1 * simT)) / (s2 - s1);\n }\n\n segments.push(`${t.toFixed(4)},${value.toFixed(4)}`);\n }\n\n // Force exact endpoint\n segments[segments.length - 1] = \"1,1\";\n\n return `${segments[0]} L${segments.slice(1).join(\" \")}`;\n}\n","// fallow-ignore-file code-duplication\n/**\n * Browser-safe GSAP read path — acorn + acorn-walk.\n *\n * T6b oracle: produces identical ParsedGsap output to gsapParser.ts (recast).\n * Replaces recast as the shared implementation once T6d passes.\n *\n * Write path (T6c) will add magic-string splice once read parity is confirmed.\n * No Node globals, no fs, no require — safe to bundle for browser use.\n */\nimport * as acorn from \"acorn\";\nimport * as acornWalk from \"acorn-walk\";\nimport type {\n ArcPathConfig,\n GsapAnimation,\n GsapKeyframesData,\n GsapMethod,\n GsapPercentageKeyframe,\n ParsedGsap,\n} from \"./gsapSerialize.js\";\nimport { classifyTweenPropertyGroup } from \"./gsapConstants.js\";\nimport { buildArcPath } from \"./gsapSerialize.js\";\nimport { inlineComputedTimelines, readProvenance } from \"./gsapInline.js\";\n\n// Browser-safe re-exports so studio code can build arc config without importing\n// the recast parser (this acorn module is the browser-safe gsap subpath).\nexport { buildArcPath, editabilityForProvenance } from \"./gsapSerialize.js\";\nexport type {\n ArcPathConfig,\n ArcPathSegment,\n MotionPathShape,\n GsapProvenance,\n GsapProvenanceKind,\n KeyframeEditability,\n} from \"./gsapSerialize.js\";\n\nconst GSAP_METHODS = new Set<string>([\"set\", \"to\", \"from\", \"fromTo\"]);\nconst QUERY_METHODS = new Set([\"querySelector\", \"querySelectorAll\"]);\nconst ITERATION_METHODS = new Set([\"forEach\", \"map\"]);\nconst SCOPE_NODE_TYPES = new Set([\n \"Program\",\n \"FunctionDeclaration\",\n \"FunctionExpression\",\n \"ArrowFunctionExpression\",\n]);\n\n// ── Types ────────────────────────────────────────────────────────────────────\n\ntype ScopeBindings = ReadonlyMap<string, number | string | boolean>;\n/** Per-scope element bindings: scopeNode → (variable name → selector). */\ntype TargetBindings = Map<any, Map<string, string>>;\n\n// ── Value resolution ─────────────────────────────────────────────────────────\n\n// fallow-ignore-next-line complexity\nfunction resolveNode(\n node: any,\n scope: ReadonlyMap<string, number | string | boolean>,\n): number | string | boolean | undefined {\n if (!node) return undefined;\n if (node.type === \"NumericLiteral\" || (node.type === \"Literal\" && typeof node.value === \"number\"))\n return node.value;\n if (node.type === \"StringLiteral\" || (node.type === \"Literal\" && typeof node.value === \"string\"))\n return node.value;\n if (\n node.type === \"BooleanLiteral\" ||\n (node.type === \"Literal\" && typeof node.value === \"boolean\")\n )\n return node.value;\n if (node.type === \"UnaryExpression\" && node.operator === \"-\" && node.argument) {\n const val = resolveNode(node.argument, scope);\n return typeof val === \"number\" ? -val : undefined;\n }\n if (node.type === \"BinaryExpression\") {\n const left = resolveNode(node.left, scope);\n const right = resolveNode(node.right, scope);\n if (typeof left === \"number\" && typeof right === \"number\") {\n switch (node.operator) {\n case \"+\":\n return left + right;\n case \"-\":\n return left - right;\n case \"*\":\n return left * right;\n case \"/\":\n return right !== 0 ? left / right : undefined;\n }\n }\n if (typeof left === \"string\" && node.operator === \"+\") return left + String(right ?? \"\");\n if (typeof right === \"string\" && node.operator === \"+\") return String(left ?? \"\") + right;\n }\n if (node.type === \"Identifier\" && scope.has(node.name)) {\n return scope.get(node.name);\n }\n if (node.type === \"TemplateLiteral\" && node.expressions?.length === 0) {\n return node.quasis?.[0]?.value?.cooked ?? undefined;\n }\n return undefined;\n}\n\nfunction extractLiteralValue(node: any, scope: ScopeBindings): unknown {\n return resolveNode(node, scope);\n}\n\n// ── DOM selector resolution ───────────────────────────────────────────────────\n\n// fallow-ignore-next-line complexity\nfunction selectorFromQueryCall(node: any, scope: ScopeBindings): string | null {\n if (node?.type !== \"CallExpression\") return null;\n const callee = node.callee;\n if (callee?.type !== \"MemberExpression\" || callee.property?.type !== \"Identifier\") return null;\n const method = callee.property.name;\n const argValue = resolveNode(node.arguments?.[0], scope);\n if (typeof argValue !== \"string\" || argValue.length === 0) return null;\n if (QUERY_METHODS.has(method) || method === \"toArray\") return argValue;\n if (method === \"getElementById\") return `#${argValue}`;\n return null;\n}\n\n// ── Ancestor-based scope helpers (replaces NodePath walking) ──────────────────\n\n/**\n * Return the nearest ancestor node whose type is in SCOPE_NODE_TYPES.\n * `ancestors` is the acorn-walk ancestor array (root→current, current is last).\n */\nfunction enclosingScopeNodeFromAncestors(ancestors: any[]): any {\n for (let i = ancestors.length - 2; i >= 0; i--) {\n const node = ancestors[i];\n if (node && SCOPE_NODE_TYPES.has(node.type)) return node;\n }\n return null;\n}\n\n/** Scope chain innermost-first, derived from the acorn-walk ancestors array. */\nfunction scopeChainFromAncestors(ancestors: any[]): any[] {\n const chain: any[] = [];\n for (let i = ancestors.length - 1; i >= 0; i--) {\n const node = ancestors[i];\n if (node && SCOPE_NODE_TYPES.has(node.type)) chain.push(node);\n }\n return chain;\n}\n\n// ── Target bindings ───────────────────────────────────────────────────────────\n\nfunction addBinding(\n bindings: TargetBindings,\n scopeNode: any,\n name: string,\n selector: string,\n): void {\n let scoped = bindings.get(scopeNode);\n if (!scoped) {\n scoped = new Map();\n bindings.set(scopeNode, scoped);\n }\n if (!scoped.has(name)) scoped.set(name, selector);\n}\n\nfunction lookupBindingFromAncestors(\n name: string,\n ancestors: any[],\n bindings: TargetBindings,\n): string | null {\n for (const scopeNode of scopeChainFromAncestors(ancestors)) {\n const selector = bindings.get(scopeNode)?.get(name);\n if (selector !== undefined) return selector;\n }\n // Program-scope bindings are stored under null (enclosingScopeNodeFromAncestors\n // returns null when no function wrapper exists — the common case in HF scripts).\n return bindings.get(null)?.get(name) ?? null;\n}\n\nfunction isFunctionNode(node: any): boolean {\n return (\n node?.type === \"ArrowFunctionExpression\" ||\n node?.type === \"FunctionExpression\" ||\n node?.type === \"FunctionDeclaration\"\n );\n}\n\nfunction resolveCollectionSelector(\n node: any,\n ancestors: any[],\n scope: ScopeBindings,\n bindings: TargetBindings,\n): string | null {\n if (node?.type === \"Identifier\")\n return lookupBindingFromAncestors(node.name, ancestors, bindings);\n if (node?.type === \"CallExpression\") return selectorFromQueryCall(node, scope);\n return null;\n}\n\nfunction collectScopeBindings(ast: any): ScopeBindings {\n const bindings = new Map<string, number | string | boolean>();\n acornWalk.simple(ast, {\n VariableDeclarator(node: any) {\n const name = node.id?.name;\n const init = node.init;\n if (name && init) {\n const val = resolveNode(init, bindings);\n if (val !== undefined) bindings.set(name, val);\n }\n },\n });\n return bindings;\n}\n\n/**\n * Build a lexically-scoped index of element variables → selector.\n * Pass 1: direct DOM-lookup assignments.\n * Pass 2: forEach/map callback params whose collection's selector is known.\n */\nfunction collectTargetBindings(ast: any, scope: ScopeBindings): TargetBindings {\n const bindings: TargetBindings = new Map();\n\n acornWalk.ancestor(ast, {\n VariableDeclarator(node: any, _: unknown, ancestors: any[]) {\n const name = node.id?.name;\n const selector = selectorFromQueryCall(node.init, scope);\n if (name && selector !== null) {\n addBinding(bindings, enclosingScopeNodeFromAncestors(ancestors), name, selector);\n }\n },\n AssignmentExpression(node: any, _: unknown, ancestors: any[]) {\n const left = node.left;\n const selector = selectorFromQueryCall(node.right, scope);\n if (left?.type === \"Identifier\" && selector !== null) {\n addBinding(bindings, enclosingScopeNodeFromAncestors(ancestors), left.name, selector);\n }\n },\n } as any);\n\n // Pass 2: forEach/map callback params take the collection's selector.\n acornWalk.ancestor(ast, {\n // fallow-ignore-next-line complexity\n CallExpression(node: any, _: unknown, ancestors: any[]) {\n const callee = node.callee;\n if (\n callee?.type === \"MemberExpression\" &&\n callee.property?.type === \"Identifier\" &&\n ITERATION_METHODS.has(callee.property.name)\n ) {\n const collectionSelector = resolveCollectionSelector(\n callee.object,\n ancestors,\n scope,\n bindings,\n );\n const fn = node.arguments?.[0];\n const param = fn?.params?.[0];\n if (collectionSelector && param?.type === \"Identifier\" && isFunctionNode(fn)) {\n addBinding(bindings, fn, param.name, collectionSelector);\n }\n }\n },\n } as any);\n\n return bindings;\n}\n\n// fallow-ignore-next-line complexity\nfunction resolveTargetSelector(\n node: any,\n ancestors: any[],\n scope: ScopeBindings,\n bindings: TargetBindings,\n): string | null {\n if (!node) return null;\n if (node.type === \"StringLiteral\" || node.type === \"Literal\") {\n return typeof node.value === \"string\" ? node.value : null;\n }\n if (node.type === \"Identifier\") {\n return lookupBindingFromAncestors(node.name, ancestors, bindings);\n }\n if (node.type === \"CallExpression\") {\n return selectorFromQueryCall(node, scope);\n }\n if (node.type === \"ArrayExpression\") {\n const parts = node.elements\n .map((el: any) => resolveTargetSelector(el, ancestors, scope, bindings))\n .filter((s: string | null): s is string => typeof s === \"string\" && s.length > 0);\n return parts.length > 0 ? parts.join(\", \") : null;\n }\n if (node.type === \"MemberExpression\" && node.object?.type === \"Identifier\") {\n return lookupBindingFromAncestors(node.object.name, ancestors, bindings);\n }\n return null;\n}\n\n// ── ObjectExpression utilities ────────────────────────────────────────────────\n\nfunction isObjectProperty(prop: any): boolean {\n return prop?.type === \"ObjectProperty\" || prop?.type === \"Property\";\n}\n\nfunction propKeyName(prop: any): string | undefined {\n return prop?.key?.name ?? prop?.key?.value;\n}\n\nfunction findPropertyNode(varsArgNode: any, key: string): any | undefined {\n if (varsArgNode?.type !== \"ObjectExpression\") return undefined;\n for (const prop of varsArgNode.properties ?? []) {\n if (!isObjectProperty(prop)) continue;\n if (propKeyName(prop) === key) return prop.value;\n }\n return undefined;\n}\n\n/**\n * Extract raw source text for a property value — the offset-splice primitive.\n * Equivalent to `recast.print(node).code` for unmodified nodes.\n */\nfunction extractRawPropertySource(\n varsArgNode: any,\n key: string,\n source: string,\n): string | undefined {\n const node = findPropertyNode(varsArgNode, key);\n return node ? source.slice(node.start, node.end) : undefined;\n}\n\n// fallow-ignore-next-line complexity\nfunction objectExpressionToRecord(\n node: any,\n scope: ScopeBindings,\n source: string,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n if (node?.type !== \"ObjectExpression\") return result;\n for (const prop of node.properties ?? []) {\n if (!isObjectProperty(prop)) continue;\n const key = prop.key?.name ?? prop.key?.value;\n if (!key) continue;\n const resolved = resolveNode(prop.value, scope);\n if (resolved !== undefined) {\n result[key] = resolved;\n } else {\n result[key] = `__raw:${source.slice(prop.value.start, prop.value.end)}`;\n }\n }\n return result;\n}\n\n// ── Timeline detection ────────────────────────────────────────────────────────\n\nfunction isGsapTimelineCall(node: any): boolean {\n return (\n node?.type === \"CallExpression\" &&\n node.callee?.type === \"MemberExpression\" &&\n node.callee.object?.name === \"gsap\" &&\n node.callee.property?.name === \"timeline\"\n );\n}\n\ninterface TimelineDefaults {\n ease?: string;\n duration?: number;\n}\n\ninterface TimelineDetection {\n timelineVar: string | null;\n timelineCount: number;\n defaults?: TimelineDefaults;\n}\n\n// fallow-ignore-next-line complexity\nfunction extractTimelineDefaults(\n callNode: any,\n scope: ScopeBindings,\n): TimelineDefaults | undefined {\n const arg = callNode.arguments?.[0];\n if (!arg || arg.type !== \"ObjectExpression\") return undefined;\n const defaultsProp = arg.properties?.find(\n (p: any) => isObjectProperty(p) && propKeyName(p) === \"defaults\",\n );\n if (!defaultsProp?.value || defaultsProp.value.type !== \"ObjectExpression\") return undefined;\n const result: TimelineDefaults = {};\n for (const prop of defaultsProp.value.properties ?? []) {\n if (!isObjectProperty(prop)) continue;\n const key = propKeyName(prop);\n const val = resolveNode(prop.value, scope);\n if (key === \"ease\" && typeof val === \"string\") result.ease = val;\n if (key === \"duration\" && typeof val === \"number\") result.duration = val;\n }\n return Object.keys(result).length > 0 ? result : undefined;\n}\n\nfunction findTimelineVar(ast: any, scope?: ScopeBindings): TimelineDetection {\n let timelineVar: string | null = null;\n let timelineCount = 0;\n let defaults: TimelineDefaults | undefined;\n const emptyScope: ScopeBindings = scope ?? new Map();\n\n acornWalk.simple(ast, {\n VariableDeclarator(node: any) {\n if (isGsapTimelineCall(node.init)) {\n timelineCount += 1;\n if (!timelineVar) {\n timelineVar = node.id?.name ?? null;\n defaults = extractTimelineDefaults(node.init, emptyScope);\n }\n }\n },\n AssignmentExpression(node: any) {\n if (isGsapTimelineCall(node.right)) {\n timelineCount += 1;\n if (!timelineVar) {\n const left = node.left;\n if (left?.type === \"Identifier\") timelineVar = left.name;\n defaults = extractTimelineDefaults(node.right, emptyScope);\n }\n }\n },\n });\n\n return { timelineVar, timelineCount, defaults };\n}\n\n// ── Tween call collection ─────────────────────────────────────────────────────\n\n/** Keys stored on dedicated GsapAnimation fields (not in properties/extras). */\nconst BUILTIN_VAR_KEYS = new Set([\"duration\", \"ease\", \"delay\"]);\n/** Keys never preserved (callbacks / advanced patterns). */\nconst DROPPED_VAR_KEYS = new Set([\"onComplete\", \"onStart\", \"onUpdate\", \"onRepeat\"]);\n/** Keys that go in `extras` — non-editable GSAP config that must survive round-trips. */\nconst EXTRAS_KEYS = new Set([\n \"stagger\",\n \"yoyo\",\n \"repeat\",\n \"repeatDelay\",\n \"snap\",\n \"overwrite\",\n \"immediateRender\",\n]);\n\nexport interface TweenCallInfo {\n node: any;\n /** acorn-walk ancestor array at the call site (root→call, call is last). */\n ancestors: any[];\n method: GsapMethod;\n selector: string;\n varsArg: any;\n fromArg?: any;\n positionArg?: any;\n /** True for a base `gsap.set(...)` (off-timeline) rather than `tl.set(...)`. */\n global?: boolean;\n}\n\n/** True when callee chain is rooted at the timeline variable. */\nfunction isTimelineRootedCall(callNode: any, timelineVar: string): boolean {\n let obj = callNode.callee?.object;\n while (obj?.type === \"CallExpression\") {\n obj = obj.callee?.object;\n }\n return obj?.type === \"Identifier\" && obj.name === timelineVar;\n}\n\n/**\n * Pre-order recursive walk for tween collection.\n *\n * acorn-walk is POST-order (visitor fires after children), which reverses\n * chained calls vs recast.types.visit (PRE-order). We need pre-order to\n * match the golden ordering where the outermost chained call appears first.\n */\nfunction findAllTweenCalls(\n ast: any,\n timelineVar: string,\n scope: ScopeBindings,\n targetBindings: TargetBindings,\n): TweenCallInfo[] {\n const results: TweenCallInfo[] = [];\n\n // fallow-ignore-next-line complexity\n function visit(node: any, ancestors: readonly any[]): void {\n if (!node || typeof node !== \"object\") return;\n const nodeAncestors = [...ancestors, node];\n\n // Fire BEFORE children (pre-order) so chained outer calls come first.\n if (node.type === \"CallExpression\") {\n const callee = node.callee;\n // A base `gsap.set(\"#sel\", props)` is an off-timeline static hold — parse it as\n // an editable global `set` so a static value round-trips and re-edits in place.\n // STRING-LITERAL selectors only: variable-target holds stay surrounding source.\n const gsapSetArg = node.arguments?.[0];\n const isGlobalSet =\n callee?.type === \"MemberExpression\" &&\n callee.object?.type === \"Identifier\" &&\n callee.object.name === \"gsap\" &&\n callee.property?.type === \"Identifier\" &&\n callee.property.name === \"set\" &&\n (gsapSetArg?.type === \"StringLiteral\" ||\n (gsapSetArg?.type === \"Literal\" && typeof gsapSetArg.value === \"string\"));\n if (\n callee?.type === \"MemberExpression\" &&\n callee.property?.type === \"Identifier\" &&\n (isTimelineRootedCall(node, timelineVar) || isGlobalSet) &&\n GSAP_METHODS.has(callee.property.name)\n ) {\n const method = callee.property.name;\n const args = node.arguments;\n const selectorValue =\n args.length >= 1\n ? (resolveTargetSelector(args[0], nodeAncestors, scope, targetBindings) ??\n \"__unresolved__\")\n : \"__unresolved__\";\n\n if (method === \"fromTo\" && args.length >= 3) {\n results.push({\n node,\n ancestors: nodeAncestors,\n method: \"fromTo\",\n selector: selectorValue,\n fromArg: args[1],\n varsArg: args[2],\n positionArg: args[3],\n });\n } else if (method !== \"fromTo\" && args.length >= 2) {\n results.push({\n node,\n ancestors: nodeAncestors,\n method: method as GsapMethod,\n selector: selectorValue,\n varsArg: args[1],\n positionArg: args[2],\n ...(isGlobalSet ? { global: true } : {}),\n });\n }\n }\n }\n\n // Traverse children. Object.keys preserves insertion order, so callee\n // comes before arguments in acorn's CallExpression nodes.\n for (const key of Object.keys(node)) {\n if (key === \"type\" || key === \"start\" || key === \"end\" || key === \"loc\") continue;\n const child = (node as any)[key];\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item === \"object\" && item.type) visit(item, nodeAncestors);\n }\n } else if (child && typeof child === \"object\" && (child as any).type) {\n visit(child, nodeAncestors);\n }\n }\n }\n\n visit(ast, []);\n return results;\n}\n\n// ── Keyframes parsing ─────────────────────────────────────────────────────────\n\nconst PERCENTAGE_KEY_RE = /^(\\d+(?:\\.\\d+)?)%$/;\n\nfunction tryResolveStringProp(propValue: any, scope: ScopeBindings): string | undefined {\n const val = resolveNode(propValue, scope);\n return typeof val === \"string\" ? val : undefined;\n}\n\n// fallow-ignore-next-line complexity\nfunction parsePercentageKeyframes(\n node: any,\n scope: ScopeBindings,\n source: string,\n): GsapKeyframesData {\n const keyframes: GsapPercentageKeyframe[] = [];\n let ease: string | undefined;\n let easeEach: string | undefined;\n\n for (const prop of node.properties ?? []) {\n if (prop.type !== \"ObjectProperty\" && prop.type !== \"Property\") continue;\n const key = prop.key?.value ?? prop.key?.name;\n if (typeof key !== \"string\") continue;\n\n const pctMatch = PERCENTAGE_KEY_RE.exec(key);\n if (pctMatch) {\n const percentage = Number.parseFloat(pctMatch[1] ?? \"0\");\n const record = objectExpressionToRecord(prop.value, scope, source);\n const properties: Record<string, number | string> = {};\n let kfEase: string | undefined;\n for (const [k, v] of Object.entries(record)) {\n if (k === \"ease\" && typeof v === \"string\") {\n kfEase = v;\n } else if (typeof v === \"number\" || typeof v === \"string\") {\n properties[k] = v;\n }\n }\n keyframes.push({ percentage, properties, ...(kfEase ? { ease: kfEase } : {}) });\n } else if (key === \"ease\") {\n ease = tryResolveStringProp(prop.value, scope) ?? ease;\n } else if (key === \"easeEach\") {\n easeEach = tryResolveStringProp(prop.value, scope) ?? easeEach;\n }\n }\n\n keyframes.sort((a, b) => a.percentage - b.percentage);\n\n return {\n format: \"percentage\",\n keyframes,\n ...(ease ? { ease } : {}),\n ...(easeEach ? { easeEach } : {}),\n };\n}\n\n// fallow-ignore-next-line complexity\nfunction computeKeyframesTotalDuration(\n varsNode: any,\n scope: ScopeBindings,\n source: string,\n): number | undefined {\n const kfNode = (varsNode.properties ?? []).find(\n (p: any) => (p.key?.name ?? p.key?.value) === \"keyframes\",\n )?.value;\n if (!kfNode || kfNode.type !== \"ArrayExpression\") return undefined;\n let total = 0;\n for (const el of kfNode.elements ?? []) {\n if (!el || el.type !== \"ObjectExpression\") continue;\n const r = objectExpressionToRecord(el, scope, source);\n if (typeof r.duration === \"number\") total += r.duration;\n }\n return total > 0 ? total : undefined;\n}\n\n// fallow-ignore-next-line complexity\nfunction parseObjectArrayKeyframes(\n node: any,\n scope: ScopeBindings,\n source: string,\n): GsapKeyframesData {\n const elements = node.elements ?? [];\n const raw: Array<{\n properties: Record<string, number | string>;\n duration?: number;\n ease?: string;\n }> = [];\n\n for (const el of elements) {\n if (!el || el.type !== \"ObjectExpression\") continue;\n const record = objectExpressionToRecord(el, scope, source);\n const properties: Record<string, number | string> = {};\n let duration: number | undefined;\n let ease: string | undefined;\n for (const [k, v] of Object.entries(record)) {\n if (k === \"duration\" && typeof v === \"number\") {\n duration = v;\n } else if (k === \"ease\" && typeof v === \"string\") {\n ease = v;\n } else if (typeof v === \"number\" || typeof v === \"string\") {\n properties[k] = v;\n }\n }\n raw.push({ properties, duration, ease });\n }\n\n const totalDuration = raw.reduce((sum, r) => sum + (r.duration ?? 0), 0);\n const keyframes: GsapPercentageKeyframe[] = [];\n\n if (totalDuration > 0) {\n let cumulative = 0;\n for (const entry of raw) {\n cumulative += entry.duration ?? 0;\n const percentage = Math.round((cumulative / totalDuration) * 100);\n keyframes.push({\n percentage,\n properties: entry.properties,\n ...(entry.ease ? { ease: entry.ease } : {}),\n });\n }\n } else {\n for (let i = 0; i < raw.length; i++) {\n const entry = raw[i];\n if (!entry) continue;\n const percentage = raw.length > 1 ? Math.round((i / (raw.length - 1)) * 100) : 0;\n keyframes.push({\n percentage,\n properties: entry.properties,\n ...(entry.ease ? { ease: entry.ease } : {}),\n });\n }\n }\n\n return { format: \"object-array\", keyframes };\n}\n\n// fallow-ignore-next-line complexity\nfunction parseSimpleArrayKeyframes(node: any, scope: ScopeBindings): GsapKeyframesData {\n const arrayProps: Map<string, (number | string)[]> = new Map();\n let ease: string | undefined;\n let easeEach: string | undefined;\n\n for (const prop of node.properties ?? []) {\n if (prop.type !== \"ObjectProperty\" && prop.type !== \"Property\") continue;\n const key = prop.key?.name ?? prop.key?.value;\n if (typeof key !== \"string\") continue;\n\n if (prop.value?.type === \"ArrayExpression\") {\n const values: (number | string)[] = [];\n for (const el of prop.value.elements ?? []) {\n const val = resolveNode(el, scope);\n if (typeof val === \"number\" || typeof val === \"string\") {\n values.push(val);\n }\n }\n if (values.length > 0) arrayProps.set(key, values);\n } else if (key === \"ease\") {\n ease = tryResolveStringProp(prop.value, scope) ?? ease;\n } else if (key === \"easeEach\") {\n easeEach = tryResolveStringProp(prop.value, scope) ?? easeEach;\n }\n }\n\n const maxLen = Math.max(...[...arrayProps.values()].map((a) => a.length), 0);\n const keyframes: GsapPercentageKeyframe[] = [];\n\n for (let i = 0; i < maxLen; i++) {\n const percentage = maxLen > 1 ? Math.round((i / (maxLen - 1)) * 100) : 0;\n const properties: Record<string, number | string> = {};\n for (const [key, values] of arrayProps) {\n if (i < values.length) properties[key] = values[i] as number | string;\n }\n keyframes.push({ percentage, properties });\n }\n\n return {\n format: \"simple-array\",\n keyframes,\n ...(ease ? { ease } : {}),\n ...(easeEach ? { easeEach } : {}),\n };\n}\n\n// fallow-ignore-next-line complexity\nfunction parseKeyframesNode(\n node: any,\n scope: ScopeBindings,\n source: string,\n): GsapKeyframesData | undefined {\n if (!node) return undefined;\n\n if (node.type === \"ArrayExpression\") {\n return parseObjectArrayKeyframes(node, scope, source);\n }\n\n if (node.type !== \"ObjectExpression\") return undefined;\n\n const props = node.properties ?? [];\n let hasPercentageKey = false;\n let hasArrayValue = false;\n\n for (const prop of props) {\n if (prop.type !== \"ObjectProperty\" && prop.type !== \"Property\") continue;\n const key = prop.key?.value ?? prop.key?.name;\n if (typeof key === \"string\" && PERCENTAGE_KEY_RE.test(key)) {\n hasPercentageKey = true;\n break;\n }\n if (prop.value?.type === \"ArrayExpression\") {\n hasArrayValue = true;\n }\n }\n\n if (hasPercentageKey) return parsePercentageKeyframes(node, scope, source);\n if (hasArrayValue) return parseSimpleArrayKeyframes(node, scope);\n\n return undefined;\n}\n\n// ── MotionPath parsing ────────────────────────────────────────────────────────\n\ninterface MotionPathParseResult {\n arcPath: ArcPathConfig;\n waypoints: Array<{ x: number; y: number }>;\n}\n\n// fallow-ignore-next-line complexity\nfunction parseMotionPathNode(\n node: any,\n scope: ScopeBindings,\n source: string,\n): MotionPathParseResult | undefined {\n if (!node) return undefined;\n\n let pathNode: any;\n let autoRotate: boolean | number = false;\n let curviness = 1;\n let isCubic = false;\n\n if (node.type === \"ObjectExpression\") {\n for (const prop of node.properties ?? []) {\n if (!isObjectProperty(prop)) continue;\n const key = propKeyName(prop);\n if (key === \"path\") pathNode = prop.value;\n else if (key === \"autoRotate\") {\n const val = resolveNode(prop.value, scope);\n autoRotate = typeof val === \"number\" ? val : val === true;\n } else if (key === \"curviness\") {\n const val = resolveNode(prop.value, scope);\n if (typeof val === \"number\") curviness = val;\n } else if (key === \"type\") {\n const val = resolveNode(prop.value, scope);\n if (val === \"cubic\") isCubic = true;\n }\n }\n } else if (node.type === \"ArrayExpression\") {\n pathNode = node;\n }\n\n if (!pathNode || pathNode.type !== \"ArrayExpression\") return undefined;\n\n const elements = pathNode.elements ?? [];\n const coords: Array<{ x: number; y: number }> = [];\n for (const elem of elements) {\n if (!elem || elem.type !== \"ObjectExpression\") continue;\n const rec = objectExpressionToRecord(elem, scope, source);\n const x = typeof rec.x === \"number\" ? rec.x : undefined;\n const y = typeof rec.y === \"number\" ? rec.y : undefined;\n if (x !== undefined && y !== undefined) coords.push({ x, y });\n }\n\n return buildArcPath(coords, curviness, autoRotate, isCubic);\n}\n\n// ── Animation assembly ────────────────────────────────────────────────────────\n\n// fallow-ignore-next-line complexity\nfunction tweenCallToAnimation(\n call: TweenCallInfo,\n scope: ScopeBindings,\n source: string,\n): Omit<GsapAnimation, \"id\"> {\n const vars = objectExpressionToRecord(call.varsArg, scope, source);\n const properties: Record<string, number | string> = {};\n const extras: Record<string, unknown> = {};\n let keyframesData: GsapKeyframesData | undefined;\n let hasUnresolvedKeyframes = false;\n let motionPathResult: MotionPathParseResult | undefined;\n\n for (const [key, val] of Object.entries(vars)) {\n if (BUILTIN_VAR_KEYS.has(key)) continue;\n if (DROPPED_VAR_KEYS.has(key)) continue;\n\n if (key === \"keyframes\") {\n const kfNode = findPropertyNode(call.varsArg, \"keyframes\");\n keyframesData = parseKeyframesNode(kfNode, scope, source);\n if (!keyframesData && kfNode) hasUnresolvedKeyframes = true;\n continue;\n }\n\n if (key === \"motionPath\") {\n const mpNode = findPropertyNode(call.varsArg, \"motionPath\");\n motionPathResult = parseMotionPathNode(mpNode, scope, source);\n continue;\n }\n\n if (key === \"easeEach\") continue;\n\n if (EXTRAS_KEYS.has(key)) {\n const rawSource = extractRawPropertySource(call.varsArg, key, source);\n if (rawSource !== undefined) {\n extras[key] = `__raw:${rawSource}`;\n } else if (val !== undefined) {\n extras[key] = val;\n }\n continue;\n }\n\n if (typeof val === \"number\" || typeof val === \"string\") {\n properties[key] = val;\n }\n }\n\n if (keyframesData && typeof vars.easeEach === \"string\") {\n keyframesData.easeEach = vars.easeEach as string;\n }\n\n if (motionPathResult) {\n const { waypoints } = motionPathResult;\n if (!keyframesData) {\n const kf: GsapPercentageKeyframe[] = waypoints.map((wp, i) => ({\n percentage: waypoints.length > 1 ? Math.round((i / (waypoints.length - 1)) * 100) : 0,\n properties: { x: wp.x, y: wp.y },\n }));\n keyframesData = { format: \"percentage\", keyframes: kf };\n } else {\n const kfs = keyframesData.keyframes;\n if (kfs.length === waypoints.length) {\n for (let i = 0; i < kfs.length; i++) {\n const kf = kfs[i];\n const wp = waypoints[i];\n if (kf && wp) {\n kf.properties.x = wp.x;\n kf.properties.y = wp.y;\n }\n }\n }\n }\n }\n\n let fromProperties: Record<string, number | string> | undefined;\n if (call.method === \"fromTo\" && call.fromArg) {\n fromProperties = {};\n const fromVars = objectExpressionToRecord(call.fromArg, scope, source);\n for (const [key, val] of Object.entries(fromVars)) {\n if (typeof val === \"number\" || typeof val === \"string\") {\n fromProperties[key] = val;\n }\n }\n }\n\n const hasPositionArg = !!call.positionArg;\n const posVal = hasPositionArg ? extractLiteralValue(call.positionArg, scope) : 0;\n const position: number | string =\n typeof posVal === \"number\" ? posVal : typeof posVal === \"string\" ? posVal : 0;\n let duration = typeof vars.duration === \"number\" ? vars.duration : undefined;\n const ease = typeof vars.ease === \"string\" ? vars.ease : undefined;\n\n if (duration === undefined && keyframesData) {\n duration = computeKeyframesTotalDuration(call.varsArg, scope, source);\n }\n\n const anim: Omit<GsapAnimation, \"id\"> = {\n targetSelector: call.selector,\n method: call.method,\n position,\n properties,\n fromProperties,\n duration,\n ease,\n };\n if (!hasPositionArg) anim.implicitPosition = true;\n let group = classifyTweenPropertyGroup(properties);\n if (!group && keyframesData) {\n const kfProps: Record<string, unknown> = {};\n for (const kf of keyframesData.keyframes) {\n for (const k of Object.keys(kf.properties)) kfProps[k] = true;\n }\n group = classifyTweenPropertyGroup(kfProps);\n }\n if (group) anim.propertyGroup = group;\n if (call.global) anim.global = true;\n if (Object.keys(extras).length > 0) anim.extras = extras;\n if (keyframesData) anim.keyframes = keyframesData;\n if (motionPathResult) anim.arcPath = motionPathResult.arcPath;\n if (hasUnresolvedKeyframes) anim.hasUnresolvedKeyframes = true;\n if (call.selector === \"__unresolved__\") anim.hasUnresolvedSelector = true;\n const provenance = readProvenance(call.node);\n if (provenance) anim.provenance = provenance;\n return anim;\n}\n\n// ── Timeline position resolution ─────────────────────────────────────────────\n\nconst GSAP_DEFAULT_DURATION = 0.5;\n\n// fallow-ignore-next-line complexity\nfunction resolvePositionString(pos: string, cursor: number, prevStart: number): number | null {\n const trimmed = pos.trim();\n if (trimmed === \"\") return cursor;\n if (trimmed.startsWith(\"+=\")) {\n const n = Number.parseFloat(trimmed.slice(2));\n return Number.isFinite(n) ? cursor + n : null;\n }\n if (trimmed.startsWith(\"-=\")) {\n const n = Number.parseFloat(trimmed.slice(2));\n return Number.isFinite(n) ? cursor - n : null;\n }\n if (trimmed === \"<\") return prevStart;\n if (trimmed === \">\") return cursor;\n if (trimmed.startsWith(\"<\")) {\n const n = Number.parseFloat(trimmed.slice(1));\n return Number.isFinite(n) ? prevStart + n : null;\n }\n if (trimmed.startsWith(\">\")) {\n const n = Number.parseFloat(trimmed.slice(1));\n return Number.isFinite(n) ? cursor + n : null;\n }\n const n = Number.parseFloat(trimmed);\n return Number.isFinite(n) ? n : null;\n}\n\nfunction applyTimelineDefaults(\n anims: Omit<GsapAnimation, \"id\">[],\n defaults?: TimelineDefaults,\n): void {\n if (!defaults) return;\n for (const anim of anims) {\n if (anim.method === \"set\") continue;\n if (anim.duration === undefined && defaults.duration !== undefined) {\n anim.duration = defaults.duration;\n }\n if (anim.ease === undefined && defaults.ease !== undefined) {\n anim.ease = defaults.ease;\n }\n }\n}\n\n// fallow-ignore-next-line complexity\nfunction resolveTimelinePositions(anims: Omit<GsapAnimation, \"id\">[]): void {\n let cursor = 0;\n let prevStart = 0;\n for (const anim of anims) {\n // A global `gsap.set(...)` is off-timeline — applied once at load, not\n // sequenced on the master timeline. It carries no position arg, so the\n // cursor fallback would otherwise hand it the comp-end time. Pin it to 0\n // (its load-time start) and don't advance the cursor/prevStart.\n if (anim.method === \"set\" && anim.global) {\n anim.resolvedStart = 0;\n continue;\n }\n const duration = anim.method === \"set\" ? 0 : (anim.duration ?? GSAP_DEFAULT_DURATION);\n let start: number | null;\n\n if (anim.implicitPosition) {\n start = cursor;\n } else if (typeof anim.position === \"number\") {\n start = anim.position;\n } else if (typeof anim.position === \"string\") {\n start = resolvePositionString(anim.position, cursor, prevStart);\n } else {\n start = cursor;\n }\n\n if (start != null) {\n anim.resolvedStart = Math.max(0, start);\n prevStart = anim.resolvedStart;\n cursor = Math.max(cursor, anim.resolvedStart + duration);\n }\n }\n}\n\nfunction compareByLoc(a: TweenCallInfo, b: TweenCallInfo): number {\n const aLoc = a.node.callee?.property?.loc?.start;\n const bLoc = b.node.callee?.property?.loc?.start;\n if (!aLoc || !bLoc) return 0;\n return aLoc.line - bLoc.line || aLoc.column - bLoc.column;\n}\n\n// Inlined tweens carry a monotonic __hfOrder (clones share source loc, so loc\n// can't order them); they sort by that, after all literal (loc-ordered) tweens.\nfunction compareCallOrder(a: TweenCallInfo, b: TweenCallInfo): number {\n const ao = a.node.__hfOrder;\n const bo = b.node.__hfOrder;\n if (ao === undefined && bo === undefined) return compareByLoc(a, b);\n if (ao === undefined) return -1;\n if (bo === undefined) return 1;\n return ao - bo;\n}\n\nfunction sortBySourcePosition(calls: TweenCallInfo[]): void {\n calls.sort(compareCallOrder);\n}\n\n// ── Stable ID generation ──────────────────────────────────────────────────────\n\nfunction assignStableIds(anims: Omit<GsapAnimation, \"id\">[]): GsapAnimation[] {\n const counts = new Map<string, number>();\n return anims.map((anim) => {\n const posKey =\n typeof anim.position === \"number\"\n ? String(Math.round(anim.position * 1000))\n : String(anim.position);\n const groupSuffix = anim.propertyGroup ? `-${anim.propertyGroup}` : \"\";\n const base = `${anim.targetSelector}-${anim.method}-${posKey}${groupSuffix}`;\n const count = (counts.get(base) ?? 0) + 1;\n counts.set(base, count);\n const id = count === 1 ? base : `${base}-${count}`;\n return { ...anim, id };\n });\n}\n\n// ── Write-path internal parse ─────────────────────────────────────────────────\n\nexport interface ParsedGsapAcornForWrite {\n ast: any;\n timelineVar: string;\n hasTimeline: boolean;\n located: Array<{ id: string; call: TweenCallInfo; animation: GsapAnimation }>;\n}\n\n/**\n * Parse a GSAP script and return internal AST + call nodes for the write path.\n * Consumed by gsapWriterAcorn.ts (magic-string offset-splice).\n */\nexport function parseGsapScriptAcornForWrite(script: string): ParsedGsapAcornForWrite | null {\n try {\n const ast = acorn.parse(script, {\n ecmaVersion: \"latest\",\n sourceType: \"script\",\n locations: true,\n });\n const scope = collectScopeBindings(ast);\n const targetBindings = collectTargetBindings(ast, scope);\n const detection = findTimelineVar(ast, scope);\n const timelineVar = detection.timelineVar ?? \"tl\";\n const calls = findAllTweenCalls(ast, timelineVar, scope, targetBindings);\n sortBySourcePosition(calls);\n const rawAnims = calls.map((call) => tweenCallToAnimation(call, scope, script));\n applyTimelineDefaults(rawAnims, detection.defaults);\n resolveTimelinePositions(rawAnims);\n const animations = assignStableIds(rawAnims);\n const located = calls.map((call, i) => ({\n id: animations[i]!.id,\n call,\n animation: animations[i]!,\n }));\n return { ast, timelineVar, hasTimeline: detection.timelineVar !== null, located };\n } catch {\n return null;\n }\n}\n\n// ── Public API ────────────────────────────────────────────────────────────────\n\n/**\n * Browser-safe equivalent of `parseGsapScript` (gsapParser.ts).\n * Uses acorn + acorn-walk instead of recast + @babel/parser.\n */\nexport function parseGsapScriptAcorn(script: string): ParsedGsap {\n try {\n const ast = acorn.parse(script, {\n ecmaVersion: \"latest\",\n sourceType: \"script\",\n locations: true,\n });\n const scope = collectScopeBindings(ast);\n const detection = findTimelineVar(ast, scope);\n const timelineVar = detection.timelineVar ?? \"tl\";\n // Expand helper-built / bounded-loop timelines before analysis so their\n // tweens resolve at true positions (read path only — the write path keeps\n // original source nodes). Degrades to the un-inlined AST on any failure.\n try {\n inlineComputedTimelines(ast, timelineVar, (node) => resolveNode(node, scope));\n } catch {\n /* fall back to current behavior */\n }\n const targetBindings = collectTargetBindings(ast, scope);\n const calls = findAllTweenCalls(ast, timelineVar, scope, targetBindings);\n sortBySourcePosition(calls);\n const rawAnims = calls.map((call) => tweenCallToAnimation(call, scope, script));\n applyTimelineDefaults(rawAnims, detection.defaults);\n resolveTimelinePositions(rawAnims);\n const animations = assignStableIds(rawAnims);\n\n const timelineMatch = script.match(\n new RegExp(\n `^[\\\\s\\\\S]*?(?:const|let|var)\\\\s+${timelineVar}\\\\s*=\\\\s*gsap\\\\.timeline\\\\s*\\\\([^)]*\\\\)\\\\s*;?`,\n ),\n );\n const preamble =\n timelineMatch?.[0] ?? `const ${timelineVar} = gsap.timeline({ paused: true });`;\n\n const lastCallIdx = script.lastIndexOf(`${timelineVar}.`);\n let postamble = \"\";\n if (lastCallIdx !== -1) {\n const afterLast = script.slice(lastCallIdx);\n const endOfCall = afterLast.indexOf(\";\");\n if (endOfCall !== -1) {\n postamble = script.slice(lastCallIdx + endOfCall + 1).trim();\n }\n }\n\n const result: ParsedGsap = { animations, timelineVar, preamble, postamble };\n if (detection.timelineCount > 1) result.multipleTimelines = true;\n if (detection.timelineCount > 0 && detection.timelineVar === null)\n result.unsupportedTimelinePattern = true;\n return result;\n } catch {\n return { animations: [], timelineVar: \"tl\", preamble: \"\", postamble: \"\" };\n }\n}\n\n// ── Label extraction (WS-C) ──────────────────────────────────────────────────\n\nexport interface GsapLabelEntry {\n name: string;\n position: number;\n}\n\n/**\n * Extract all `tl.addLabel(\"name\", position)` calls from a GSAP script.\n *\n * Returns labels in source order. Position must be a numeric literal; labels\n * with non-numeric positions (e.g. label-relative offsets) are skipped.\n *\n * Pure — no side effects, no DOM, no Date.now.\n */\nexport function extractGsapLabels(script: string): GsapLabelEntry[] {\n try {\n const ast = acorn.parse(script, {\n ecmaVersion: \"latest\",\n sourceType: \"script\",\n locations: true,\n });\n const scope = collectScopeBindings(ast);\n const detection = findTimelineVar(ast, scope);\n const timelineVar = detection.timelineVar ?? \"tl\";\n\n const labels: GsapLabelEntry[] = [];\n\n acornWalk.simple(ast, {\n // fallow-ignore-next-line complexity\n ExpressionStatement(node: any) {\n const expr = node.expression;\n if (!expr || expr.type !== \"CallExpression\") return;\n const callee = expr.callee;\n // Match tl.addLabel(...)\n if (\n callee?.type !== \"MemberExpression\" ||\n callee.object?.name !== timelineVar ||\n callee.property?.name !== \"addLabel\"\n )\n return;\n const args = expr.arguments ?? [];\n const nameNode = args[0];\n const posNode = args[1];\n if (nameNode?.type !== \"Literal\" || typeof nameNode.value !== \"string\") return;\n if (!posNode) return;\n const pos = resolveNode(posNode, scope);\n if (typeof pos !== \"number\" || !Number.isFinite(pos)) return;\n labels.push({ name: nameNode.value, position: pos });\n },\n });\n\n return labels;\n } catch {\n // Labels are best-effort/supplementary, not load-bearing — a malformed or\n // unparseable script yields no labels rather than failing the caller.\n return [];\n }\n}\n","/**\n * Static evaluation for computed GSAP timelines (browser-safe, acorn/ESTree).\n *\n * The read parser resolves only literals and top-level consts, so timelines\n * built by a helper called N times or by a bounded loop collapse to position 0.\n * This module expands those constructs into a synthetic analysis AST: each\n * helper invocation and each loop iteration becomes its own concrete set of\n * `tl.*` calls, with parameters/loop-vars substituted by the call's argument\n * (or element/index) AST nodes — after which the existing parse pipeline\n * resolves positions and `motionPath` arcs unchanged.\n *\n * Substituted nodes keep their original source offsets, so downstream\n * source-slicing (raw extras, keyframes) stays correct. The substitution\n * primitives never mutate their input; `inlineComputedTimelines` rewrites the\n * Program body of the freshly-parsed AST it is handed (owned by the caller).\n */\nimport type { GsapProvenance } from \"./gsapSerialize.js\";\n\n// acorn ESTree nodes are structurally untyped; mirror gsapParserAcorn.ts.\ntype Node = any;\n\n/** Node keys that are metadata, not child AST to traverse/substitute. */\nconst SKIP_KEYS = new Set([\"type\", \"start\", \"end\", \"loc\", \"range\", \"__hfProvenance\", \"__hfOrder\"]);\n\nconst FUNCTION_TYPES = new Set([\n \"ArrowFunctionExpression\",\n \"FunctionExpression\",\n \"FunctionDeclaration\",\n]);\nconst GSAP_METHODS = new Set([\"set\", \"to\", \"from\", \"fromTo\"]);\n\n// Bounds on synthetic expansion (recursion + iteration runaway guards).\nconst MAX_DEPTH = 8;\nconst MAX_ITERS = 512;\n\nfunction isFunctionNode(node: Node): boolean {\n return !!node && FUNCTION_TYPES.has(node.type);\n}\n\nfunction isNode(x: Node): boolean {\n return !!x && typeof x === \"object\" && typeof x.type === \"string\";\n}\n\n/**\n * Apply `fn` to each child AST node, writing back its return value. Skips\n * metadata keys and key/member slots that must not be treated as values.\n * The one place array-vs-single child traversal lives, so walkers stay flat.\n */\nfunction transformChildren(node: Node, fn: (child: Node) => Node): void {\n for (const key of Object.keys(node)) {\n if (SKIP_KEYS.has(key) || isNonValueIdentifierSlot(node, key)) continue;\n const child = node[key];\n if (Array.isArray(child)) {\n for (let i = 0; i < child.length; i++) child[i] = fn(child[i]);\n } else {\n node[key] = fn(child);\n }\n }\n}\n\n/** Deep structural clone preserving `start`/`end`/`loc` (needed for source slicing). */\nexport function cloneNode<T extends Node>(node: T): T {\n return structuredClone(node);\n}\n\n// ponytail: Identifier + default + rest only. Destructured bindings (`{x}`, `[x]`)\n// aren't inlined (U2 inlines Identifier-param helpers / loop vars only), so a\n// destructuring shadow is a double-rare miss that just falls back. Add the\n// pattern cases here if that ever bites.\nfunction collectPatternNames(pattern: Node, out: Set<string>): void {\n if (pattern?.type === \"Identifier\") out.add(pattern.name);\n else if (pattern?.type === \"AssignmentPattern\") collectPatternNames(pattern.left, out);\n else if (pattern?.type === \"RestElement\") collectPatternNames(pattern.argument, out);\n}\n\n/** Every identifier name bound anywhere inside the subtree (fn params, declared vars, catch params). */\nfunction collectBoundNames(root: Node): Set<string> {\n const names = new Set<string>();\n const visit = (node: Node): Node => {\n if (!isNode(node)) return node;\n if (isFunctionNode(node)) for (const p of node.params ?? []) collectPatternNames(p, names);\n else if (node.type === \"VariableDeclarator\") collectPatternNames(node.id, names);\n else if (node.type === \"CatchClause\") collectPatternNames(node.param, names);\n transformChildren(node, visit);\n return node;\n };\n visit(root);\n return names;\n}\n\n/** A child in key/property position that must not be treated as a value identifier. */\nfunction isNonValueIdentifierSlot(node: Node, key: string): boolean {\n if (node.computed) return false;\n return (\n (node.type === \"MemberExpression\" && key === \"property\") ||\n (node.type === \"Property\" && key === \"key\")\n );\n}\n\n/**\n * Substitute bound identifiers in an already-cloned subtree, returning the\n * (possibly replaced) root. Names shadowed anywhere inside (nested function\n * params, declared vars) are dropped up front rather than tracked per scope —\n * worst case we under-substitute and the caller falls back to current behavior.\n * Never substitutes identifiers in key/member positions. Mutates the passed\n * clone in place — callers pass `cloneNode(...)`.\n */\nexport function substituteParams(node: Node, bindings: ReadonlyMap<string, Node>): Node {\n const shadowed = collectBoundNames(node);\n let effective = bindings;\n if (shadowed.size > 0) {\n effective = new Map(bindings);\n for (const name of shadowed) (effective as Map<string, Node>).delete(name);\n }\n if (effective.size === 0) return node;\n return replace(node, effective);\n}\n\nfunction replace(node: Node, bindings: ReadonlyMap<string, Node>): Node {\n if (!isNode(node)) return node;\n if (node.type === \"Identifier\" && bindings.has(node.name)) {\n return cloneNode(bindings.get(node.name));\n }\n transformChildren(node, (child) => replace(child, bindings));\n return node;\n}\n\n/** Tag a node (typically a `tl.*` CallExpression) with its construction provenance. */\nexport function tagProvenance(node: Node, provenance: GsapProvenance): Node {\n if (node && typeof node === \"object\") node.__hfProvenance = provenance;\n return node;\n}\n\n/** Read a provenance tag previously set by `tagProvenance`, if any. */\nexport function readProvenance(node: Node): GsapProvenance | undefined {\n return node?.__hfProvenance;\n}\n\n/** Synthesize a numeric `Literal` node (for loop indices, which have no source node). */\nexport function numericLiteral(value: number): Node {\n return { type: \"Literal\", value, raw: String(value) };\n}\n\n// ── Expansion engine (U2) ─────────────────────────────────────────────────────\n\n/** Resolve an expression to a literal value (top-level consts in scope, arithmetic). */\ntype LiteralResolver = (node: Node) => number | string | boolean | undefined;\n\ninterface ExpandCtx {\n helpers: Map<string, Node>;\n timelineVar: string;\n resolve: LiteralResolver;\n depth: number;\n /** Mutable source-order counter for provenance call-site ordinals. */\n site: { n: number };\n /** Mutable counter stamping expansion order onto tweens (clones share source loc). */\n order: { n: number };\n}\n\nfunction walkNodes(node: Node, fn: (n: Node) => void): void {\n if (!isNode(node)) return;\n fn(node);\n for (const key of Object.keys(node)) {\n if (SKIP_KEYS.has(key)) continue;\n const child = node[key];\n if (Array.isArray(child)) for (const c of child) walkNodes(c, fn);\n else walkNodes(child, fn);\n }\n}\n\n/** The identifier a (possibly chained) call's member expression is rooted at. */\nfunction timelineRootName(call: Node): string | null {\n let obj = call.callee?.object;\n while (obj?.type === \"CallExpression\") obj = obj.callee?.object;\n return obj?.type === \"Identifier\" ? obj.name : null;\n}\n\nfunction isTimelineRooted(call: Node, timelineVar: string): boolean {\n if (timelineRootName(call) !== timelineVar) return false;\n return (\n call.callee?.property?.type === \"Identifier\" && GSAP_METHODS.has(call.callee.property.name)\n );\n}\n\nfunction containsTimelineCall(node: Node, timelineVar: string): boolean {\n let found = false;\n walkNodes(node, (n) => {\n if (n.type === \"CallExpression\" && isTimelineRooted(n, timelineVar)) found = true;\n });\n return found;\n}\n\nfunction rangeOf(node: Node): [number, number] | undefined {\n return typeof node.start === \"number\" && typeof node.end === \"number\"\n ? [node.start, node.end]\n : undefined;\n}\n\n/** Plain identifier params + block body (shape we can inline). Timeline content checked separately. */\nfunction isShapeEligible(fn: Node): boolean {\n return (\n isFunctionNode(fn) &&\n fn.body?.type === \"BlockStatement\" &&\n !(fn.params ?? []).some((p: Node) => p.type !== \"Identifier\")\n );\n}\n\n/** True if the subtree calls any function named in `names`. */\nfunction callsAny(node: Node, names: Set<string>): boolean {\n let hit = false;\n walkNodes(node, (n) => {\n if (\n n.type === \"CallExpression\" &&\n n.callee?.type === \"Identifier\" &&\n names.has(n.callee.name)\n ) {\n hit = true;\n }\n });\n return hit;\n}\n\n/** `[name, fnNode]` if a single-declarator `const f = fn` is an inlinable-shaped helper. */\nfunction varDeclHelper(stmt: Node): [string, Node] | null {\n if (stmt.declarations?.length !== 1) return null;\n const d = stmt.declarations[0];\n return d.id?.type === \"Identifier\" && isShapeEligible(d.init) ? [d.id.name, d.init] : null;\n}\n\n/** `[name, fnNode]` if `stmt` declares an inlinable-shaped helper, else null. */\nfunction helperFromStatement(stmt: Node): [string, Node] | null {\n if (stmt.type === \"FunctionDeclaration\") {\n return stmt.id && isShapeEligible(stmt) ? [stmt.id.name, stmt] : null;\n }\n if (stmt.type === \"VariableDeclaration\") return varDeclHelper(stmt);\n return null;\n}\n\n/** Top-level functions whose shape we can inline (Identifier params + block body). */\nfunction gatherHelperCandidates(program: Node): Map<string, Node> {\n const candidates = new Map<string, Node>();\n for (const stmt of program.body ?? []) {\n const helper = helperFromStatement(stmt);\n if (helper) candidates.set(helper[0], helper[1]);\n }\n return candidates;\n}\n\n/** Names that build the timeline directly or by calling another builder (transitive closure). */\nfunction timelineBuildingNames(candidates: Map<string, Node>, timelineVar: string): Set<string> {\n const building = new Set<string>();\n for (const [name, fn] of candidates) {\n if (containsTimelineCall(fn.body, timelineVar)) building.add(name);\n }\n for (let changed = true; changed; ) {\n changed = false;\n for (const [name, fn] of candidates) {\n if (!building.has(name) && callsAny(fn.body, building)) {\n building.add(name);\n changed = true;\n }\n }\n }\n return building;\n}\n\nfunction bump(counts: Map<string, number>, key: string): void {\n counts.set(key, (counts.get(key) ?? 0) + 1);\n}\n\n/**\n * Keep only candidates safe to drop: every reference to the name is its\n * declaration or a statement-level call. (1 decl id + 1 callee id per\n * statement-level call ⇒ total occurrences with no stray uses.)\n */\nfunction safelyDroppable(program: Node, candidates: Map<string, Node>): Map<string, Node> {\n const names = new Set(candidates.keys());\n const totalIds = new Map<string, number>();\n const stmtCalls = new Map<string, number>();\n walkNodes(program, (n) => {\n if (n.type === \"Identifier\" && names.has(n.name)) bump(totalIds, n.name);\n const e = n.type === \"ExpressionStatement\" ? n.expression : undefined;\n if (\n e?.type === \"CallExpression\" &&\n e.callee?.type === \"Identifier\" &&\n names.has(e.callee.name)\n ) {\n bump(stmtCalls, e.callee.name);\n }\n });\n const safe = new Map<string, Node>();\n for (const [name, fn] of candidates) {\n if ((totalIds.get(name) ?? 0) === 1 + (stmtCalls.get(name) ?? 0)) safe.set(name, fn);\n }\n return safe;\n}\n\n/** Top-level timeline-building helpers that are safe to inline-and-drop. */\nfunction collectInlinableHelpers(program: Node, timelineVar: string): Map<string, Node> {\n const candidates = gatherHelperCandidates(program);\n if (candidates.size === 0) return candidates;\n const building = timelineBuildingNames(candidates, timelineVar);\n for (const name of [...candidates.keys()]) if (!building.has(name)) candidates.delete(name);\n if (candidates.size === 0) return candidates;\n return safelyDroppable(program, candidates);\n}\n\nfunction isHelperDecl(stmt: Node, helpers: Map<string, Node>): boolean {\n if (stmt.type === \"FunctionDeclaration\") return !!stmt.id && helpers.get(stmt.id.name) === stmt;\n if (stmt.type === \"VariableDeclaration\" && stmt.declarations?.length === 1) {\n const d = stmt.declarations[0];\n return d.id?.type === \"Identifier\" && helpers.get(d.id.name) === d.init;\n }\n return false;\n}\n\nfunction bodyStatements(node: Node): Node[] {\n if (node?.type === \"BlockStatement\") return node.body ?? [];\n return node ? [{ type: \"ExpressionStatement\", expression: node }] : [];\n}\n\n/** Tag this body's direct timeline tweens with provenance + a monotonic expansion-order stamp. */\nfunction tagTimelineCalls(stmts: Node[], prov: GsapProvenance, ctx: ExpandCtx): void {\n for (const stmt of stmts) {\n walkNodes(stmt, (n) => {\n if (n.type === \"CallExpression\" && isTimelineRooted(n, ctx.timelineVar)) {\n tagProvenance(n, { ...prov });\n n.__hfOrder = ctx.order.n++;\n }\n });\n }\n}\n\n/** Clone a body as one scope, substitute the bindings, tag provenance, recurse. */\nfunction expandBody(\n bodyStmts: Node[],\n bindings: Map<string, Node>,\n prov: GsapProvenance,\n ctx: ExpandCtx,\n): Node[] {\n const block = substituteParams(cloneNode({ type: \"BlockStatement\", body: bodyStmts }), bindings);\n tagTimelineCalls(block.body, prov, ctx);\n return expandStatements(block.body, { ...ctx, depth: ctx.depth + 1 });\n}\n\nfunction inlineHelper(call: Node, ctx: ExpandCtx): Node[] {\n const fn = ctx.helpers.get(call.callee.name);\n const bindings = new Map<string, Node>();\n (fn.params ?? []).forEach((p: Node, i: number) => {\n const arg = call.arguments?.[i];\n if (arg) bindings.set(p.name, arg);\n });\n const prov: GsapProvenance = {\n kind: \"helper\",\n fn: call.callee.name,\n callSite: ++ctx.site.n,\n sourceRange: rangeOf(call),\n };\n return expandBody(fn.body.body, bindings, prov, ctx);\n}\n\nfunction assignStep(update: Node, resolve: LiteralResolver): number | undefined {\n if (update.operator === \"+=\") return asNum(resolve(update.right));\n if (update.operator === \"-=\") {\n const s = asNum(resolve(update.right));\n return s === undefined ? undefined : -s;\n }\n // `i = i + S` — the step is the right operand of the addition.\n if (update.operator === \"=\" && update.right?.type === \"BinaryExpression\") {\n return asNum(resolve(update.right.right));\n }\n return undefined;\n}\n\n/** The loop variable a `for` update clause mutates (`i++` or `i += S`), or null. */\nfunction updatedVarName(update: Node): string | null {\n if (update?.type === \"UpdateExpression\") return update.argument?.name ?? null;\n if (update?.type === \"AssignmentExpression\") return update.left?.name ?? null;\n return null;\n}\n\nfunction loopStep(update: Node, varName: string, resolve: LiteralResolver): number | undefined {\n if (updatedVarName(update) !== varName) return undefined;\n if (update.type === \"UpdateExpression\") return update.operator === \"++\" ? 1 : -1;\n return assignStep(update, resolve);\n}\n\nfunction asNum(v: unknown): number | undefined {\n return typeof v === \"number\" && Number.isFinite(v) ? v : undefined;\n}\n\nfunction loopSatisfied(op: string, x: number, end: number): boolean {\n if (op === \"<\") return x < end;\n if (op === \"<=\") return x <= end;\n if (op === \">\") return x > end;\n if (op === \">=\") return x >= end;\n return false;\n}\n\ninterface ForHeader {\n v: string;\n start: number;\n end: number;\n op: string;\n step: number;\n}\n\n/** The single `let v = <init>` of a for-loop init clause, or null. */\nfunction forInitVar(init: Node): { name: string; initExpr: Node } | null {\n if (init?.type !== \"VariableDeclaration\" || init.declarations?.length !== 1) return null;\n const d = init.declarations[0];\n return d.id?.type === \"Identifier\" ? { name: d.id.name, initExpr: d.init } : null;\n}\n\n/** Parse `for (let v = A; v <op> B; v += S)` into resolved bounds, or null if not statically bounded. */\nfunction parseForHeader(stmt: Node, resolve: LiteralResolver): ForHeader | null {\n const iv = forInitVar(stmt.init);\n const test = stmt.test;\n if (!iv || test?.type !== \"BinaryExpression\" || test.left?.name !== iv.name) return null;\n const start = asNum(resolve(iv.initExpr));\n const end = asNum(resolve(test.right));\n const step = loopStep(stmt.update, iv.name, resolve);\n if (start === undefined || end === undefined || !step) return null;\n return { v: iv.name, start, end, op: test.operator, step };\n}\n\nfunction unrollFor(stmt: Node, ctx: ExpandCtx): Node[] | null {\n const h = parseForHeader(stmt, ctx.resolve);\n if (!h) return null;\n const body = bodyStatements(stmt.body);\n const out: Node[] = [];\n const site = ++ctx.site.n;\n let iteration = 0;\n for (let x = h.start; loopSatisfied(h.op, x, h.end); x += h.step) {\n if (iteration >= MAX_ITERS) return null;\n const prov: GsapProvenance = {\n kind: \"loop\",\n callSite: site,\n iteration,\n sourceRange: rangeOf(stmt),\n };\n out.push(...expandBody(body, new Map([[h.v, numericLiteral(x)]]), prov, ctx));\n iteration++;\n }\n return out;\n}\n\nfunction forOfVarName(left: Node): string | null {\n if (left?.type === \"VariableDeclaration\") {\n const id = left.declarations?.[0]?.id;\n return id?.type === \"Identifier\" ? id.name : null;\n }\n return left?.type === \"Identifier\" ? left.name : null;\n}\n\n/** Expand `for (const el of [literal array]) {...}` and `[literal array].forEach((el, i) => {...})`. */\nfunction unrollOverArray(\n elements: Node[],\n body: Node[],\n elName: string | null,\n idxName: string | null,\n range: [number, number] | undefined,\n ctx: ExpandCtx,\n): Node[] {\n const out: Node[] = [];\n const site = ++ctx.site.n;\n elements.forEach((el, i) => {\n if (!el) return;\n const bindings = new Map<string, Node>();\n if (elName) bindings.set(elName, el);\n if (idxName) bindings.set(idxName, numericLiteral(i));\n const prov: GsapProvenance = { kind: \"loop\", callSite: site, iteration: i, sourceRange: range };\n out.push(...expandBody(body, bindings, prov, ctx));\n });\n return out;\n}\n\nfunction unrollForOf(stmt: Node, ctx: ExpandCtx): Node[] | null {\n if (stmt.right?.type !== \"ArrayExpression\") return null;\n const elName = forOfVarName(stmt.left);\n if (!elName) return null;\n return unrollOverArray(\n stmt.right.elements ?? [],\n bodyStatements(stmt.body),\n elName,\n null,\n rangeOf(stmt),\n ctx,\n );\n}\n\n/** The (element, index) param names of a callback, or null if either is non-Identifier. */\nfunction callbackParamNames(cb: Node): { el: string | null; idx: string | null } | null {\n const names: Array<string | null> = [];\n for (const p of [cb.params?.[0], cb.params?.[1]]) {\n if (!p) names.push(null);\n else if (p.type !== \"Identifier\") return null;\n else names.push(p.name);\n }\n return { el: names[0]!, idx: names[1]! };\n}\n\n/** True for `[arrayLiteral].forEach` member callees. */\nfunction isForEachCall(callee: Node): boolean {\n return (\n callee?.type === \"MemberExpression\" &&\n callee.property?.name === \"forEach\" &&\n callee.object?.type === \"ArrayExpression\"\n );\n}\n\n/** The element array + callback of `[...].forEach(cb)`, or null. */\nfunction forEachTarget(call: Node): { elements: Node[]; cb: Node } | null {\n if (!isForEachCall(call.callee)) return null;\n const cb = call.arguments?.[0];\n return isFunctionNode(cb) ? { elements: call.callee.object.elements ?? [], cb } : null;\n}\n\nfunction unrollForEach(call: Node, ctx: ExpandCtx): Node[] | null {\n const target = forEachTarget(call);\n if (!target) return null;\n const params = callbackParamNames(target.cb);\n if (!params) return null;\n return unrollOverArray(\n target.elements,\n bodyStatements(target.cb.body),\n params.el,\n params.idx,\n rangeOf(call),\n ctx,\n );\n}\n\nfunction expandCall(call: Node, ctx: ExpandCtx): Node[] | null {\n if (call.callee?.type === \"Identifier\" && ctx.helpers.has(call.callee.name)) {\n return inlineHelper(call, ctx);\n }\n return unrollForEach(call, ctx);\n}\n\nfunction expandStatement(stmt: Node, ctx: ExpandCtx): Node[] | null {\n if (ctx.depth >= MAX_DEPTH) return null;\n if (stmt.type === \"ForStatement\") return unrollFor(stmt, ctx);\n if (stmt.type === \"ForOfStatement\") return unrollForOf(stmt, ctx);\n if (stmt.type === \"ExpressionStatement\" && stmt.expression?.type === \"CallExpression\") {\n return expandCall(stmt.expression, ctx);\n }\n return null;\n}\n\nfunction expandStatements(stmts: Node[], ctx: ExpandCtx): Node[] {\n const out: Node[] = [];\n for (const stmt of stmts) {\n const expanded = expandStatement(stmt, ctx);\n if (expanded) out.push(...expanded);\n else out.push(stmt);\n }\n return out;\n}\n\n/**\n * Rewrite the Program body so helper invocations and bounded loops that build\n * the timeline are expanded into concrete per-call / per-iteration `tl.*`\n * statements, each tagged with provenance. Mutates `ast` in place (caller owns\n * the freshly-parsed tree). Constructs it can't statically resolve are left\n * untouched, so the parser falls back to current behavior for them.\n */\nexport function inlineComputedTimelines(\n ast: Node,\n timelineVar: string,\n resolve: LiteralResolver,\n): void {\n const helpers = collectInlinableHelpers(ast, timelineVar);\n const ctx: ExpandCtx = {\n helpers,\n timelineVar,\n resolve,\n depth: 0,\n site: { n: 0 },\n order: { n: 0 },\n };\n const body = (ast.body ?? []).filter((stmt: Node) => !isHelperDecl(stmt, helpers));\n ast.body = expandStatements(body, ctx);\n}\n"],"mappings":";AAOO,IAAM,kBAAkB;AAAA;AAAA,EAE7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EACA;AA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