(
script: string,
animationId: string,
newPosition: number,
newDuration: number,
pctRemap: ReadonlyArray<{ from: number; to: number }>,
)
| 2391 | * tween `ease` untouched. Acorn twin: resizeKeyframedTweenInScript. |
| 2392 | */ |
| 2393 | export function resizeKeyframedTweenInScript( |
| 2394 | script: string, |
| 2395 | animationId: string, |
| 2396 | newPosition: number, |
| 2397 | newDuration: number, |
| 2398 | pctRemap: ReadonlyArray<{ from: number; to: number }>, |
| 2399 | ): string { |
| 2400 | const loc = locateAnimationWithFallback(script, animationId); |
| 2401 | if (!loc) return script; |
| 2402 | // Array-form keyframes can't host an arbitrary re-keyed percentage — |
| 2403 | // normalize to object form in place first (mirrors addKeyframeToScript). |
| 2404 | const kfNode = |
| 2405 | findKeyframesObjectNode(loc.target.call.varsArg) ?? |
| 2406 | convertArrayKeyframesToObjectNode(loc.target.call.varsArg); |
| 2407 | if (!kfNode) return script; |
| 2408 | |
| 2409 | const seen = new Set<AstNode>(); |
| 2410 | for (const { from, to } of pctRemap) { |
| 2411 | const match = findKeyframePropByPct(kfNode, from); |
| 2412 | if (!match || seen.has(match.prop)) continue; |
| 2413 | seen.add(match.prop); |
| 2414 | // Replace only the key node; the value node (incl. _auto + per-keyframe ease) |
| 2415 | // stays verbatim. easeEach is a sibling non-percentage prop, left untouched. |
| 2416 | match.prop.key = parseExpr(`{ ${JSON.stringify(`${to}%`)}: 0 }`).properties[0].key; |
| 2417 | } |
| 2418 | |
| 2419 | applyUpdatesToCall(loc.target.call, { position: newPosition, duration: newDuration }); |
| 2420 | return recast.print(loc.parsed.ast).code; |
| 2421 | } |
| 2422 | |
| 2423 | /** |
| 2424 | * Replace the properties (and optionally ease) at an existing keyframe percentage. |
no test coverage detected