Build the full replacement vars object for a tween being converted to keyframes.
( animation: GsapAnimation, fromProps: Record<string, number | string>, toProps: Record<string, number | string>, varsNode: Node, source: string, setDuration?: number, )
| 1384 | |
| 1385 | /** Build the full replacement vars object for a tween being converted to keyframes. */ |
| 1386 | function buildKeyframesVarsCode( |
| 1387 | animation: GsapAnimation, |
| 1388 | fromProps: Record<string, number | string>, |
| 1389 | toProps: Record<string, number | string>, |
| 1390 | varsNode: Node, |
| 1391 | source: string, |
| 1392 | setDuration?: number, |
| 1393 | ): string { |
| 1394 | const fromEntries = Object.entries(fromProps).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`); |
| 1395 | const toEntries = Object.entries(toProps).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`); |
| 1396 | const easeEntry = animation.ease ? `, easeEach: ${JSON.stringify(animation.ease)}` : ""; |
| 1397 | const kfCode = `{ "0%": { ${fromEntries.join(", ")} }, "100%": { ${toEntries.join(", ")} }${easeEntry} }`; |
| 1398 | // Preserve every non-editable key (duration/delay/callbacks/stagger/yoyo/…) |
| 1399 | // verbatim from source — rebuilding from the animation object alone dropped |
| 1400 | // `delay` (not a GsapAnimation field), shifting the tween's start time. |
| 1401 | let preserved = preservedVarsEntries(varsNode, source); |
| 1402 | // Converting a static `set` → drop its hold markers and give it a real duration |
| 1403 | // so the keyframes span time. |
| 1404 | if (setDuration !== undefined) { |
| 1405 | preserved = preserved.filter((e) => !/^\s*(immediateRender|data|duration)\s*:/.test(e)); |
| 1406 | } |
| 1407 | const parts: string[] = [`keyframes: ${kfCode}`, ...preserved]; |
| 1408 | if (setDuration !== undefined) parts.push(`duration: ${Math.max(0.001, setDuration)}`); |
| 1409 | if (animation.ease) parts.push(`ease: "none"`); |
| 1410 | return `{ ${parts.join(", ")} }`; |
| 1411 | } |
| 1412 | |
| 1413 | /** |
| 1414 | * Convert a flat tween (to/from/fromTo) to percentage-keyframes format. |
no test coverage detected