(timelineVar: string, anim: Omit<GsapAnimation, "id">)
| 52 | |
| 53 | // fallow-ignore-next-line complexity |
| 54 | function buildTweenStatementCode(timelineVar: string, anim: Omit<GsapAnimation, "id">): string { |
| 55 | const selector = JSON.stringify(anim.targetSelector); |
| 56 | const props: Record<string, number | string> = { ...anim.properties }; |
| 57 | if (anim.method !== "set" && anim.duration !== undefined) props.duration = anim.duration; |
| 58 | if (anim.ease) props.ease = anim.ease; |
| 59 | const entries = Object.entries(props).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`); |
| 60 | if (anim.extras) { |
| 61 | for (const [k, v] of Object.entries(anim.extras)) { |
| 62 | entries.push(`${safeKey(k)}: ${valueToCode(v)}`); |
| 63 | } |
| 64 | } |
| 65 | const objCode = `{ ${entries.join(", ")} }`; |
| 66 | const posCode = valueToCode( |
| 67 | typeof anim.position === "number" ? anim.position : (anim.position ?? 0), |
| 68 | ); |
| 69 | if (anim.method === "fromTo") { |
| 70 | const fromEntries = Object.entries(anim.fromProperties ?? {}).map( |
| 71 | ([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`, |
| 72 | ); |
| 73 | return `${timelineVar}.fromTo(${selector}, { ${fromEntries.join(", ")} }, ${objCode}, ${posCode});`; |
| 74 | } |
| 75 | // A base `gsap.set` is off the timeline: no timeline var, no position arg. |
| 76 | if (anim.method === "set" && anim.global) { |
| 77 | return `gsap.set(${selector}, ${objCode});`; |
| 78 | } |
| 79 | return `${timelineVar}.${anim.method}(${selector}, ${objCode}, ${posCode});`; |
| 80 | } |
| 81 | |
| 82 | // ── AST node helpers ───────────────────────────────────────────────────────── |
| 83 |
no test coverage detected