MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / updateArcSegmentInScript

Function updateArcSegmentInScript

packages/parsers/src/gsapParser.ts:2862–2897  ·  view source on GitHub ↗
(
  script: string,
  animationId: string,
  segmentIndex: number,
  update: Partial<ArcPathSegment>,
)

Source from the content-addressed store, hash-verified

2860}
2861
2862export 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

Callers 4

executeGsapMutationAcornFunction · 0.50
applyArcPathOpFunction · 0.50

Calls 7

locateAnimationFunction · 0.85
parseExprFunction · 0.85
extractArcWaypointsFunction · 0.70
isObjectPropertyFunction · 0.70
propKeyNameFunction · 0.70
findMethod · 0.65

Tested by

no test coverage detected