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

Function addMotionPathToScript

packages/parsers/src/gsapParser.ts:3023–3067  ·  view source on GitHub ↗
(
  script: string,
  targetSelector: string,
  position: number,
  duration: number,
  point: { x: number; y: number },
  ease = "power1.inOut",
)

Source from the content-addressed store, hash-verified

3021 * editing. Mirrors `addAnimationWithKeyframesToScript`.
3022 */
3023export function addMotionPathToScript(
3024 script: string,
3025 targetSelector: string,
3026 position: number,
3027 duration: number,
3028 point: { x: number; y: number },
3029 ease = "power1.inOut",
3030): { script: string; id: string | null } {
3031 // `id: null` on the failure paths is a deliberate sentinel: callers must
3032 // null-check before chaining (e.g. locating the new tween). An empty string
3033 // would silently flow into selector/locate calls and match nothing.
3034 let parsed: ParsedGsapAst;
3035 try {
3036 parsed = parseGsapAst(script);
3037 } catch (e) {
3038 console.warn("[gsap-parser] addMotionPathToScript parse failed:", e);
3039 return { script, id: null };
3040 }
3041 if (parsed.located.length === 0 && parsed.detection.ref === null) {
3042 return { script, id: null };
3043 }
3044
3045 const motionPathCode = buildMotionPathObjectCode({
3046 waypoints: [
3047 { x: 0, y: 0 },
3048 { x: point.x, y: point.y },
3049 ],
3050 segments: [{ curviness: 1 }],
3051 autoRotate: false,
3052 });
3053 const selector = JSON.stringify(targetSelector);
3054 const varEntries = [
3055 `motionPath: ${motionPathCode}`,
3056 `duration: ${valueToCode(duration)}`,
3057 `ease: ${JSON.stringify(ease)}`,
3058 ];
3059 const stmtCode = `${parsed.timelineVar}.to(${selector}, { ${varEntries.join(", ")} }, ${valueToCode(position)});`;
3060 const newStatement = parseScript(stmtCode).program.body[0];
3061 insertAfterAnchor(parsed, newStatement);
3062
3063 const result = recast.print(parsed.ast).code;
3064 const reParsed = parseGsapAst(result);
3065 const newId = reParsed.located[reParsed.located.length - 1]?.id ?? null;
3066 return { script: result, id: newId };
3067}
3068
3069export function removeArcPathFromScript(script: string, animationId: string): string {
3070 return setArcPathInScript(script, animationId, {

Callers 2

gsapParser.test.tsFile · 0.85

Calls 6

parseGsapAstFunction · 0.85
valueToCodeFunction · 0.85
insertAfterAnchorFunction · 0.85
warnMethod · 0.80
parseScriptFunction · 0.70

Tested by

no test coverage detected