( script: string, animation: Omit<GsapAnimation, "id">, )
| 449 | } |
| 450 | |
| 451 | export function addAnimationToScript( |
| 452 | script: string, |
| 453 | animation: Omit<GsapAnimation, "id">, |
| 454 | ): { script: string; id: string } { |
| 455 | const parsed = parseGsapScriptAcornForWrite(script); |
| 456 | if (!parsed) return { script, id: "" }; |
| 457 | |
| 458 | const insertionPoint = findInsertionPoint(parsed); |
| 459 | if (insertionPoint === null) return { script, id: "" }; |
| 460 | |
| 461 | const ms = new MagicString(script); |
| 462 | const statementCode = buildTweenStatementCode(parsed.timelineVar, animation); |
| 463 | ms.appendLeft(insertionPoint, "\n" + statementCode); |
| 464 | |
| 465 | const result = ms.toString(); |
| 466 | const reParsed = parseGsapScriptAcornForWrite(result); |
| 467 | const newId = reParsed?.located[reParsed.located.length - 1]?.id ?? ""; |
| 468 | return { script: result, id: newId }; |
| 469 | } |
| 470 | |
| 471 | /** Splice a single located tween call out of a MagicString (standalone stmt or chain link). */ |
| 472 | function removeCallFromMagicString(ms: MagicString, call: TweenCallInfo, script: string): void { |
no test coverage detected