(
script: string,
animationId: string,
index: number,
point: { x: number; y: number },
)
| 2967 | * No-op for missing animation/arc, out-of-range index, or cubic paths. |
| 2968 | */ |
| 2969 | export function addMotionPathPointInScript( |
| 2970 | script: string, |
| 2971 | animationId: string, |
| 2972 | index: number, |
| 2973 | point: { x: number; y: number }, |
| 2974 | ): string { |
| 2975 | const loc = locateAnimation(script, animationId); |
| 2976 | if (!loc) return script; |
| 2977 | const anim = loc.target.animation; |
| 2978 | if (!anim.arcPath?.enabled || hasCubicSegments(anim.arcPath.segments)) return script; |
| 2979 | |
| 2980 | const waypoints = extractArcWaypoints(anim); |
| 2981 | // Insert strictly between two anchors: index 1..length-1. |
| 2982 | if (index < 1 || index > waypoints.length - 1) return script; |
| 2983 | |
| 2984 | const segments = [...anim.arcPath.segments]; |
| 2985 | waypoints.splice(index, 0, { x: point.x, y: point.y }); |
| 2986 | const splitCurviness = segments[index - 1]?.curviness ?? 1; |
| 2987 | segments.splice(index - 1, 0, { curviness: splitCurviness }); |
| 2988 | |
| 2989 | return writeMotionPathValue(loc, waypoints, segments, anim.arcPath.autoRotate); |
| 2990 | } |
| 2991 | |
| 2992 | /** |
| 2993 | * Remove the waypoint at `index`. Refuses to drop below two anchors (a path |
no test coverage detected