( script: string, animationId: string, segmentIndex: number, update: Partial<ArcPathSegment>, )
| 2860 | } |
| 2861 | |
| 2862 | export function updateArcSegmentInScript( |
| 2863 | script: string, |
| 2864 | animationId: string, |
| 2865 | segmentIndex: number, |
| 2866 | update: Partial<ArcPathSegment>, |
| 2867 | ): string { |
| 2868 | const loc = locateAnimation(script, animationId); |
| 2869 | if (!loc) return script; |
| 2870 | |
| 2871 | const anim = loc.target.animation; |
| 2872 | if (!anim.arcPath?.enabled) return script; |
| 2873 | |
| 2874 | const segments = [...anim.arcPath.segments]; |
| 2875 | if (segmentIndex < 0 || segmentIndex >= segments.length) return script; |
| 2876 | |
| 2877 | segments[segmentIndex] = { ...segments[segmentIndex]!, ...update }; |
| 2878 | |
| 2879 | const waypoints = extractArcWaypoints(anim); |
| 2880 | if (waypoints.length < 2) return script; |
| 2881 | |
| 2882 | const motionPathCode = buildMotionPathObjectCode({ |
| 2883 | waypoints, |
| 2884 | segments, |
| 2885 | autoRotate: anim.arcPath.autoRotate, |
| 2886 | }); |
| 2887 | |
| 2888 | const varsArg = loc.target.call.varsArg; |
| 2889 | const existingProp = varsArg.properties.find( |
| 2890 | (p: AstNode) => isObjectProperty(p) && propKeyName(p) === "motionPath", |
| 2891 | ); |
| 2892 | if (existingProp) { |
| 2893 | existingProp.value = parseExpr(motionPathCode); |
| 2894 | } |
| 2895 | |
| 2896 | return recast.print(loc.parsed.ast).code; |
| 2897 | } |
| 2898 | |
| 2899 | /** |
| 2900 | * Move a single motionPath waypoint (anchor) to a new position. The waypoint |
no test coverage detected