(
script: string,
animationId: string,
pointIndex: number,
point: { x: number; y: number },
)
| 2904 | * out of range. |
| 2905 | */ |
| 2906 | export function updateMotionPathPointInScript( |
| 2907 | script: string, |
| 2908 | animationId: string, |
| 2909 | pointIndex: number, |
| 2910 | point: { x: number; y: number }, |
| 2911 | ): string { |
| 2912 | const loc = locateAnimation(script, animationId); |
| 2913 | if (!loc) return script; |
| 2914 | |
| 2915 | const anim = loc.target.animation; |
| 2916 | if (!anim.arcPath?.enabled) return script; |
| 2917 | |
| 2918 | const waypoints = extractArcWaypoints(anim); |
| 2919 | if (pointIndex < 0 || pointIndex >= waypoints.length || waypoints.length < 2) return script; |
| 2920 | |
| 2921 | const nextWaypoints = waypoints.map((wp, i) => |
| 2922 | i === pointIndex ? { x: point.x, y: point.y } : wp, |
| 2923 | ); |
| 2924 | |
| 2925 | const motionPathCode = buildMotionPathObjectCode({ |
| 2926 | waypoints: nextWaypoints, |
| 2927 | segments: anim.arcPath.segments, |
| 2928 | autoRotate: anim.arcPath.autoRotate, |
| 2929 | }); |
| 2930 | |
| 2931 | const varsArg = loc.target.call.varsArg; |
| 2932 | const existingProp = varsArg.properties.find( |
| 2933 | (p: AstNode) => isObjectProperty(p) && propKeyName(p) === "motionPath", |
| 2934 | ); |
| 2935 | if (existingProp) { |
| 2936 | existingProp.value = parseExpr(motionPathCode); |
| 2937 | } |
| 2938 | |
| 2939 | return recast.print(loc.parsed.ast).code; |
| 2940 | } |
| 2941 | |
| 2942 | /** True when any segment carries explicit cubic control points. Add/remove are |
| 2943 | * restricted to curviness (non-cubic) paths — synthesizing control points for |
no test coverage detected