@hyperframes/parsers 0.7.57 → 0.7.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { P as ParsedGsap, c as GsapMethod, G as GsapAnimation } from './gsapSerialize-B8jHFdp3.js';
2
- export { A as ArcPathConfig, a as ArcPathSegment, e as GsapProvenance, f as GsapProvenanceKind, K as KeyframeEditability, M as MotionPathShape, l as buildArcPath, h as editabilityForProvenance } from './gsapSerialize-B8jHFdp3.js';
1
+ import { P as ParsedGsap, c as GsapMethod, G as GsapAnimation } from './gsapSerialize-CTPaxKTV.js';
2
+ export { A as ArcPathConfig, a as ArcPathSegment, e as GsapProvenance, f as GsapProvenanceKind, K as KeyframeEditability, M as MotionPathShape, l as buildArcPath, h as editabilityForProvenance } from './gsapSerialize-CTPaxKTV.js';
3
3
  import './types-CaeOJXdW.js';
4
4
  import './gsapConstants.js';
5
5
 
@@ -92,13 +92,18 @@ function collectPatternNames(pattern, out) {
92
92
  else if (pattern?.type === "AssignmentPattern") collectPatternNames(pattern.left, out);
93
93
  else if (pattern?.type === "RestElement") collectPatternNames(pattern.argument, out);
94
94
  }
95
+ function boundPatterns(node) {
96
+ if (isFunctionNode(node)) return node.params ?? [];
97
+ if (node.type === "VariableDeclarator") return [node.id];
98
+ if (node.type === "CatchClause") return [node.param];
99
+ if (node.type === "AssignmentExpression" && node.left?.type === "Identifier") return [node.left];
100
+ return [];
101
+ }
95
102
  function collectBoundNames(root) {
96
103
  const names = /* @__PURE__ */ new Set();
97
104
  const visit = (node) => {
98
105
  if (!isNode(node)) return node;
99
- if (isFunctionNode(node)) for (const p of node.params ?? []) collectPatternNames(p, names);
100
- else if (node.type === "VariableDeclarator") collectPatternNames(node.id, names);
101
- else if (node.type === "CatchClause") collectPatternNames(node.param, names);
106
+ for (const pattern of boundPatterns(node)) collectPatternNames(pattern, names);
102
107
  transformChildren(node, visit);
103
108
  return node;
104
109
  };
@@ -266,8 +271,10 @@ function tagTimelineCalls(stmts, prov, ctx) {
266
271
  }
267
272
  function expandBody(bodyStmts, bindings, prov, ctx) {
268
273
  const block = substituteParams(cloneNode({ type: "BlockStatement", body: bodyStmts }), bindings);
274
+ tagProvenance(block, prov);
269
275
  tagTimelineCalls(block.body, prov, ctx);
270
- return expandStatements(block.body, { ...ctx, depth: ctx.depth + 1 });
276
+ block.body = expandStatements(block.body, { ...ctx, depth: ctx.depth + 1 });
277
+ return [block];
271
278
  }
272
279
  function inlineHelper(call, ctx) {
273
280
  const fn = ctx.helpers.get(call.callee.name);
@@ -458,6 +465,7 @@ var QUERY_METHODS = /* @__PURE__ */ new Set(["querySelector", "querySelectorAll"
458
465
  var ITERATION_METHODS = /* @__PURE__ */ new Set(["forEach", "map"]);
459
466
  var SCOPE_NODE_TYPES = /* @__PURE__ */ new Set([
460
467
  "Program",
468
+ "BlockStatement",
461
469
  "FunctionDeclaration",
462
470
  "FunctionExpression",
463
471
  "ArrowFunctionExpression"
@@ -566,10 +574,12 @@ function selectorFromQueryCall(node, scope) {
566
574
  if (method === "getElementById") return `#${argValue}`;
567
575
  return null;
568
576
  }
569
- function enclosingScopeNodeFromAncestors(ancestors) {
577
+ function enclosingScopeNodeFromAncestors(ancestors, includeBlocks = true) {
570
578
  for (let i = ancestors.length - 2; i >= 0; i--) {
571
579
  const node = ancestors[i];
572
- if (node && SCOPE_NODE_TYPES.has(node.type)) return node;
580
+ if (node && SCOPE_NODE_TYPES.has(node.type) && (includeBlocks || node.type !== "BlockStatement")) {
581
+ return node;
582
+ }
573
583
  }
574
584
  return null;
575
585
  }
@@ -581,6 +591,64 @@ function scopeChainFromAncestors(ancestors) {
581
591
  }
582
592
  return chain;
583
593
  }
594
+ function nearestExpandedScopeFromAncestors(ancestors) {
595
+ for (let index = ancestors.length - 2; index >= 0; index--) {
596
+ const candidate = ancestors[index];
597
+ if (candidate?.type === "BlockStatement" && readProvenance(candidate)) return candidate;
598
+ }
599
+ return void 0;
600
+ }
601
+ function findVisibleIdentifierDeclaration(name, ancestors, index, usageStart = Number.POSITIVE_INFINITY) {
602
+ const declarations = index.declarationsByName.get(name) ?? [];
603
+ const expandedScopeNode = nearestExpandedScopeFromAncestors(ancestors);
604
+ for (const scopeNode of scopeChainFromAncestors(ancestors)) {
605
+ const candidates = declarations.filter(
606
+ (declaration) => declaration.scopeNode === scopeNode && (!declaration.expandedScopeNode || declaration.expandedScopeNode === expandedScopeNode) && (declaration.kind === "var" || declaration.kind === "param" || declaration.node.start < usageStart)
607
+ ).sort((left, right) => right.node.start - left.node.start);
608
+ if (candidates[0]) return candidates[0];
609
+ }
610
+ return void 0;
611
+ }
612
+ function collectIdentifierBindingIndex(ast) {
613
+ const declarationsByName = /* @__PURE__ */ new Map();
614
+ const reassignedDeclarations = /* @__PURE__ */ new Set();
615
+ acornWalk.ancestor(ast, {
616
+ VariableDeclarator(node, _, ancestors) {
617
+ const name = node.id?.name;
618
+ if (!name) return;
619
+ const declaration = ancestors.at(-2);
620
+ const kind = declaration?.kind;
621
+ if (!kind) return;
622
+ const includeBlocks = declaration?.type !== "VariableDeclaration" || kind !== "var";
623
+ const scopeNode = enclosingScopeNodeFromAncestors(ancestors, includeBlocks);
624
+ const expandedScopeNode = nearestExpandedScopeFromAncestors(ancestors);
625
+ const entries = declarationsByName.get(name) ?? [];
626
+ entries.push({ node, scopeNode, expandedScopeNode, name, kind });
627
+ declarationsByName.set(name, entries);
628
+ },
629
+ FunctionDeclaration: indexFunctionParameters,
630
+ FunctionExpression: indexFunctionParameters,
631
+ ArrowFunctionExpression: indexFunctionParameters
632
+ });
633
+ const index = { declarationsByName, reassignedDeclarations };
634
+ acornWalk.ancestor(ast, {
635
+ AssignmentExpression(node, _, ancestors) {
636
+ const name = node.left?.type === "Identifier" ? node.left.name : void 0;
637
+ if (!name) return;
638
+ const declaration = findVisibleIdentifierDeclaration(name, ancestors, index, node.start);
639
+ if (declaration) reassignedDeclarations.add(declaration.node);
640
+ }
641
+ });
642
+ return index;
643
+ function indexFunctionParameters(node) {
644
+ for (const parameter of node.params ?? []) {
645
+ if (parameter?.type !== "Identifier") continue;
646
+ const entries = declarationsByName.get(parameter.name) ?? [];
647
+ entries.push({ node: parameter, scopeNode: node, name: parameter.name, kind: "param" });
648
+ declarationsByName.set(parameter.name, entries);
649
+ }
650
+ }
651
+ }
584
652
  function addBinding(bindings, scopeNode, name, selector) {
585
653
  let scoped = bindings.get(scopeNode);
586
654
  if (!scoped) {
@@ -632,21 +700,39 @@ function collectScopeBindings(ast) {
632
700
  });
633
701
  return bindings;
634
702
  }
635
- function collectTargetBindings(ast, scope) {
703
+ function collectTargetBindings(ast, scope, identifierBindings) {
636
704
  const bindings = /* @__PURE__ */ new Map();
637
705
  acornWalk.ancestor(ast, {
638
706
  VariableDeclarator(node, _, ancestors) {
639
707
  const name = node.id?.name;
640
708
  const selector = selectorFromQueryCall(node.init, scope);
641
709
  if (name && selector !== null) {
642
- addBinding(bindings, enclosingScopeNodeFromAncestors(ancestors), name, selector);
710
+ const declaration = ancestors.at(-2);
711
+ const includeBlocks = declaration?.type !== "VariableDeclaration" || declaration.kind !== "var";
712
+ addBinding(
713
+ bindings,
714
+ enclosingScopeNodeFromAncestors(ancestors, includeBlocks),
715
+ name,
716
+ selector
717
+ );
643
718
  }
644
719
  },
645
720
  AssignmentExpression(node, _, ancestors) {
646
721
  const left = node.left;
647
722
  const selector = selectorFromQueryCall(node.right, scope);
648
723
  if (left?.type === "Identifier" && selector !== null) {
649
- addBinding(bindings, enclosingScopeNodeFromAncestors(ancestors), left.name, selector);
724
+ const declaration = findVisibleIdentifierDeclaration(
725
+ left.name,
726
+ ancestors,
727
+ identifierBindings,
728
+ node.start
729
+ );
730
+ addBinding(
731
+ bindings,
732
+ declaration?.scopeNode ?? nearestExpandedScopeFromAncestors(ancestors) ?? enclosingScopeNodeFromAncestors(ancestors),
733
+ left.name,
734
+ selector
735
+ );
650
736
  }
651
737
  }
652
738
  });
@@ -1126,7 +1212,8 @@ function parseMotionPathNode(node, scope, source) {
1126
1212
  }
1127
1213
  return buildArcPath(coords, curviness, autoRotate, isCubic);
1128
1214
  }
1129
- function tweenCallToAnimation(call, scope, source) {
1215
+ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1216
+ const provenance = readProvenance(call.node);
1130
1217
  const vars = objectExpressionToRecord(call.varsArg, scope, source);
1131
1218
  const properties = {};
1132
1219
  const extras = {};
@@ -1205,9 +1292,26 @@ function tweenCallToAnimation(call, scope, source) {
1205
1292
  duration = computeKeyframesTotalDuration(call.varsArg, scope, source);
1206
1293
  }
1207
1294
  let selector = call.selector;
1295
+ let targetIdentity;
1208
1296
  if (selector === "__unresolved__") {
1209
- const proxyLabel = describeProxyTarget(call.node.arguments?.[0], call.varsArg, scope);
1210
- if (proxyLabel) selector = proxyLabel;
1297
+ const targetNode = call.node.arguments?.[0];
1298
+ const proxyLabel = describeProxyTarget(targetNode, call.varsArg, scope);
1299
+ if (proxyLabel) {
1300
+ selector = proxyLabel;
1301
+ if (targetNode?.type === "Identifier") {
1302
+ const declaration = findVisibleIdentifierDeclaration(
1303
+ targetNode.name,
1304
+ call.ancestors,
1305
+ identifierBindings,
1306
+ call.node.start
1307
+ );
1308
+ if (declaration?.node.init?.type === "ObjectExpression" && !identifierBindings.reassignedDeclarations.has(declaration.node)) {
1309
+ const declarationProvenance = readProvenance(declaration.scopeNode) ?? readProvenance(declaration.expandedScopeNode);
1310
+ const instanceIdentity = declarationProvenance && (declarationProvenance.kind === "helper" || declarationProvenance.kind === "loop") ? `:${declarationProvenance.kind}:${declarationProvenance.callSite ?? ""}:${declarationProvenance.iteration ?? ""}` : "";
1311
+ targetIdentity = `proxy:${targetNode.name}@${declaration.node.start}${instanceIdentity}`;
1312
+ }
1313
+ }
1314
+ }
1211
1315
  }
1212
1316
  const anim = {
1213
1317
  targetSelector: selector,
@@ -1218,6 +1322,7 @@ function tweenCallToAnimation(call, scope, source) {
1218
1322
  duration,
1219
1323
  ease
1220
1324
  };
1325
+ if (targetIdentity) anim.targetIdentity = targetIdentity;
1221
1326
  if (!hasPositionArg) anim.implicitPosition = true;
1222
1327
  let group = classifyTweenPropertyGroup(properties);
1223
1328
  if (!group && keyframesData) {
@@ -1234,7 +1339,6 @@ function tweenCallToAnimation(call, scope, source) {
1234
1339
  if (motionPathResult) anim.arcPath = motionPathResult.arcPath;
1235
1340
  if (hasUnresolvedKeyframes) anim.hasUnresolvedKeyframes = true;
1236
1341
  if (selector === "__unresolved__") anim.hasUnresolvedSelector = true;
1237
- const provenance = readProvenance(call.node);
1238
1342
  if (provenance) anim.provenance = provenance;
1239
1343
  return anim;
1240
1344
  }
@@ -1486,13 +1590,16 @@ function parseGsapScriptAcornForWrite(script) {
1486
1590
  locations: true
1487
1591
  });
1488
1592
  const scope = collectScopeBindings(ast);
1489
- const targetBindings = collectTargetBindings(ast, scope);
1593
+ const identifierBindings = collectIdentifierBindingIndex(ast);
1594
+ const targetBindings = collectTargetBindings(ast, scope, identifierBindings);
1490
1595
  const detection = findTimelineVar(ast, scope);
1491
1596
  const ref = detection.ref ?? { kind: "identifier", name: "tl" };
1492
1597
  const timelineVar = timelineRootSource(ref, script);
1493
1598
  const calls = findAllTweenCalls(ast, ref, scope, targetBindings);
1494
1599
  sortBySourcePosition(calls);
1495
- const rawAnims = calls.map((call) => tweenCallToAnimation(call, scope, script));
1600
+ const rawAnims = calls.map(
1601
+ (call) => tweenCallToAnimation(call, scope, script, identifierBindings)
1602
+ );
1496
1603
  applyTimelineDefaults(rawAnims, detection.defaults);
1497
1604
  resolveTimelinePositions(rawAnims);
1498
1605
  const animations = assignStableIds(rawAnims);
@@ -1523,10 +1630,13 @@ function parseGsapScriptAcorn(script) {
1523
1630
  } catch {
1524
1631
  }
1525
1632
  }
1526
- const targetBindings = collectTargetBindings(ast, scope);
1633
+ const identifierBindings = collectIdentifierBindingIndex(ast);
1634
+ const targetBindings = collectTargetBindings(ast, scope, identifierBindings);
1527
1635
  const calls = findAllTweenCalls(ast, ref, scope, targetBindings);
1528
1636
  sortBySourcePosition(calls);
1529
- const rawAnims = calls.map((call) => tweenCallToAnimation(call, scope, script));
1637
+ const rawAnims = calls.map(
1638
+ (call) => tweenCallToAnimation(call, scope, script, identifierBindings)
1639
+ );
1530
1640
  applyTimelineDefaults(rawAnims, detection.defaults);
1531
1641
  seedSetStates(rawAnims, collectGsapSetStates(ast, scope, targetBindings, script));
1532
1642
  const labelDefs = collectAddLabelDefs(ast, ref, scope, calls);