Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
"@chenglou/pretext": "^0.0.5",
"acorn": "^8.17.0",
"acorn-walk": "^8.3.5",
"magic-string": "^0.30.21",
"postcss": "^8.5.8",
"postcss-selector-parser": "^7.1.2",
"recast": "^0.23.11"
Expand Down
42 changes: 41 additions & 1 deletion packages/core/src/parsers/gsapParserAcorn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ const EXTRAS_KEYS = new Set([
"immediateRender",
]);

interface TweenCallInfo {
export interface TweenCallInfo {
node: any;
/** acorn-walk ancestor array at the call site (root→call, call is last). */
ancestors: any[];
Expand Down Expand Up @@ -1041,6 +1041,46 @@ function assignStableIds(anims: Omit<GsapAnimation, "id">[]): GsapAnimation[] {
});
}

// ── Write-path internal parse ─────────────────────────────────────────────────

export interface ParsedGsapAcornForWrite {
ast: any;
timelineVar: string;
located: Array<{ id: string; call: TweenCallInfo; animation: GsapAnimation }>;
}

/**
* Parse a GSAP script and return internal AST + call nodes for the write path.
* Consumed by gsapWriterAcorn.ts (magic-string offset-splice).
*/
export function parseGsapScriptAcornForWrite(script: string): ParsedGsapAcornForWrite | null {
try {
const ast = acorn.parse(script, {
ecmaVersion: "latest",
sourceType: "script",
locations: true,
});
const scope = collectScopeBindings(ast);
const targetBindings = collectTargetBindings(ast, scope);
const detection = findTimelineVar(ast, scope);
const timelineVar = detection.timelineVar ?? "tl";
const calls = findAllTweenCalls(ast, timelineVar, scope, targetBindings);
sortBySourcePosition(calls);
const rawAnims = calls.map((call) => tweenCallToAnimation(call, scope, script));
applyTimelineDefaults(rawAnims, detection.defaults);
resolveTimelinePositions(rawAnims);
const animations = assignStableIds(rawAnims);
const located = calls.map((call, i) => ({
id: animations[i]!.id,
call,
animation: animations[i]!,
}));
return { ast, timelineVar, located };
} catch {
return null;
}
}

// ── Public API ────────────────────────────────────────────────────────────────

/**
Expand Down
Loading
Loading