@hyperframes/parsers 0.7.58 → 0.7.60

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.
@@ -42,6 +42,8 @@ declare function editabilityForProvenance(provenance?: GsapProvenance): Keyframe
42
42
  interface GsapAnimation {
43
43
  id: string;
44
44
  targetSelector: string;
45
+ /** Stable parser-only identity for non-DOM targets whose display label is not unique. */
46
+ targetIdentity?: string;
45
47
  method: GsapMethod;
46
48
  position: number | string;
47
49
  properties: Record<string, number | string>;
@@ -1,4 +1,4 @@
1
- import { G as GsapAnimation, A as ArcPathConfig, S as SplitAnimationsOptions, g as SplitAnimationsResult, a as ArcPathSegment } from './gsapSerialize-B8jHFdp3.js';
1
+ import { G as GsapAnimation, A as ArcPathConfig, S as SplitAnimationsOptions, g as SplitAnimationsResult, a as ArcPathSegment } from './gsapSerialize-CTPaxKTV.js';
2
2
  import './types-CaeOJXdW.js';
3
3
  import './gsapConstants.js';
4
4
 
@@ -165,6 +165,7 @@ var QUERY_METHODS = /* @__PURE__ */ new Set(["querySelector", "querySelectorAll"
165
165
  var ITERATION_METHODS = /* @__PURE__ */ new Set(["forEach", "map"]);
166
166
  var SCOPE_NODE_TYPES = /* @__PURE__ */ new Set([
167
167
  "Program",
168
+ "BlockStatement",
168
169
  "FunctionDeclaration",
169
170
  "FunctionExpression",
170
171
  "ArrowFunctionExpression"
@@ -273,10 +274,12 @@ function selectorFromQueryCall(node, scope) {
273
274
  if (method === "getElementById") return `#${argValue}`;
274
275
  return null;
275
276
  }
276
- function enclosingScopeNodeFromAncestors(ancestors) {
277
+ function enclosingScopeNodeFromAncestors(ancestors, includeBlocks = true) {
277
278
  for (let i = ancestors.length - 2; i >= 0; i--) {
278
279
  const node = ancestors[i];
279
- if (node && SCOPE_NODE_TYPES.has(node.type)) return node;
280
+ if (node && SCOPE_NODE_TYPES.has(node.type) && (includeBlocks || node.type !== "BlockStatement")) {
281
+ return node;
282
+ }
280
283
  }
281
284
  return null;
282
285
  }
@@ -288,6 +291,64 @@ function scopeChainFromAncestors(ancestors) {
288
291
  }
289
292
  return chain;
290
293
  }
294
+ function nearestExpandedScopeFromAncestors(ancestors) {
295
+ for (let index = ancestors.length - 2; index >= 0; index--) {
296
+ const candidate = ancestors[index];
297
+ if (candidate?.type === "BlockStatement" && readProvenance(candidate)) return candidate;
298
+ }
299
+ return void 0;
300
+ }
301
+ function findVisibleIdentifierDeclaration(name, ancestors, index, usageStart = Number.POSITIVE_INFINITY) {
302
+ const declarations = index.declarationsByName.get(name) ?? [];
303
+ const expandedScopeNode = nearestExpandedScopeFromAncestors(ancestors);
304
+ for (const scopeNode of scopeChainFromAncestors(ancestors)) {
305
+ const candidates = declarations.filter(
306
+ (declaration) => declaration.scopeNode === scopeNode && (!declaration.expandedScopeNode || declaration.expandedScopeNode === expandedScopeNode) && (declaration.kind === "var" || declaration.kind === "param" || declaration.node.start < usageStart)
307
+ ).sort((left, right) => right.node.start - left.node.start);
308
+ if (candidates[0]) return candidates[0];
309
+ }
310
+ return void 0;
311
+ }
312
+ function collectIdentifierBindingIndex(ast) {
313
+ const declarationsByName = /* @__PURE__ */ new Map();
314
+ const reassignedDeclarations = /* @__PURE__ */ new Set();
315
+ acornWalk.ancestor(ast, {
316
+ VariableDeclarator(node, _, ancestors) {
317
+ const name = node.id?.name;
318
+ if (!name) return;
319
+ const declaration = ancestors.at(-2);
320
+ const kind = declaration?.kind;
321
+ if (!kind) return;
322
+ const includeBlocks = declaration?.type !== "VariableDeclaration" || kind !== "var";
323
+ const scopeNode = enclosingScopeNodeFromAncestors(ancestors, includeBlocks);
324
+ const expandedScopeNode = nearestExpandedScopeFromAncestors(ancestors);
325
+ const entries = declarationsByName.get(name) ?? [];
326
+ entries.push({ node, scopeNode, expandedScopeNode, name, kind });
327
+ declarationsByName.set(name, entries);
328
+ },
329
+ FunctionDeclaration: indexFunctionParameters,
330
+ FunctionExpression: indexFunctionParameters,
331
+ ArrowFunctionExpression: indexFunctionParameters
332
+ });
333
+ const index = { declarationsByName, reassignedDeclarations };
334
+ acornWalk.ancestor(ast, {
335
+ AssignmentExpression(node, _, ancestors) {
336
+ const name = node.left?.type === "Identifier" ? node.left.name : void 0;
337
+ if (!name) return;
338
+ const declaration = findVisibleIdentifierDeclaration(name, ancestors, index, node.start);
339
+ if (declaration) reassignedDeclarations.add(declaration.node);
340
+ }
341
+ });
342
+ return index;
343
+ function indexFunctionParameters(node) {
344
+ for (const parameter of node.params ?? []) {
345
+ if (parameter?.type !== "Identifier") continue;
346
+ const entries = declarationsByName.get(parameter.name) ?? [];
347
+ entries.push({ node: parameter, scopeNode: node, name: parameter.name, kind: "param" });
348
+ declarationsByName.set(parameter.name, entries);
349
+ }
350
+ }
351
+ }
291
352
  function addBinding(bindings, scopeNode, name, selector) {
292
353
  let scoped = bindings.get(scopeNode);
293
354
  if (!scoped) {
@@ -339,21 +400,39 @@ function collectScopeBindings(ast) {
339
400
  });
340
401
  return bindings;
341
402
  }
342
- function collectTargetBindings(ast, scope) {
403
+ function collectTargetBindings(ast, scope, identifierBindings) {
343
404
  const bindings = /* @__PURE__ */ new Map();
344
405
  acornWalk.ancestor(ast, {
345
406
  VariableDeclarator(node, _, ancestors) {
346
407
  const name = node.id?.name;
347
408
  const selector = selectorFromQueryCall(node.init, scope);
348
409
  if (name && selector !== null) {
349
- addBinding(bindings, enclosingScopeNodeFromAncestors(ancestors), name, selector);
410
+ const declaration = ancestors.at(-2);
411
+ const includeBlocks = declaration?.type !== "VariableDeclaration" || declaration.kind !== "var";
412
+ addBinding(
413
+ bindings,
414
+ enclosingScopeNodeFromAncestors(ancestors, includeBlocks),
415
+ name,
416
+ selector
417
+ );
350
418
  }
351
419
  },
352
420
  AssignmentExpression(node, _, ancestors) {
353
421
  const left = node.left;
354
422
  const selector = selectorFromQueryCall(node.right, scope);
355
423
  if (left?.type === "Identifier" && selector !== null) {
356
- addBinding(bindings, enclosingScopeNodeFromAncestors(ancestors), left.name, selector);
424
+ const declaration = findVisibleIdentifierDeclaration(
425
+ left.name,
426
+ ancestors,
427
+ identifierBindings,
428
+ node.start
429
+ );
430
+ addBinding(
431
+ bindings,
432
+ declaration?.scopeNode ?? nearestExpandedScopeFromAncestors(ancestors) ?? enclosingScopeNodeFromAncestors(ancestors),
433
+ left.name,
434
+ selector
435
+ );
357
436
  }
358
437
  }
359
438
  });
@@ -830,7 +909,8 @@ function parseMotionPathNode(node, scope, source) {
830
909
  }
831
910
  return buildArcPath(coords, curviness, autoRotate, isCubic);
832
911
  }
833
- function tweenCallToAnimation(call, scope, source) {
912
+ function tweenCallToAnimation(call, scope, source, identifierBindings) {
913
+ const provenance = readProvenance(call.node);
834
914
  const vars = objectExpressionToRecord(call.varsArg, scope, source);
835
915
  const properties = {};
836
916
  const extras = {};
@@ -909,9 +989,26 @@ function tweenCallToAnimation(call, scope, source) {
909
989
  duration = computeKeyframesTotalDuration(call.varsArg, scope, source);
910
990
  }
911
991
  let selector = call.selector;
992
+ let targetIdentity;
912
993
  if (selector === "__unresolved__") {
913
- const proxyLabel = describeProxyTarget(call.node.arguments?.[0], call.varsArg, scope);
914
- if (proxyLabel) selector = proxyLabel;
994
+ const targetNode = call.node.arguments?.[0];
995
+ const proxyLabel = describeProxyTarget(targetNode, call.varsArg, scope);
996
+ if (proxyLabel) {
997
+ selector = proxyLabel;
998
+ if (targetNode?.type === "Identifier") {
999
+ const declaration = findVisibleIdentifierDeclaration(
1000
+ targetNode.name,
1001
+ call.ancestors,
1002
+ identifierBindings,
1003
+ call.node.start
1004
+ );
1005
+ if (declaration?.node.init?.type === "ObjectExpression" && !identifierBindings.reassignedDeclarations.has(declaration.node)) {
1006
+ const declarationProvenance = readProvenance(declaration.scopeNode) ?? readProvenance(declaration.expandedScopeNode);
1007
+ const instanceIdentity = declarationProvenance && (declarationProvenance.kind === "helper" || declarationProvenance.kind === "loop") ? `:${declarationProvenance.kind}:${declarationProvenance.callSite ?? ""}:${declarationProvenance.iteration ?? ""}` : "";
1008
+ targetIdentity = `proxy:${targetNode.name}@${declaration.node.start}${instanceIdentity}`;
1009
+ }
1010
+ }
1011
+ }
915
1012
  }
916
1013
  const anim = {
917
1014
  targetSelector: selector,
@@ -922,6 +1019,7 @@ function tweenCallToAnimation(call, scope, source) {
922
1019
  duration,
923
1020
  ease
924
1021
  };
1022
+ if (targetIdentity) anim.targetIdentity = targetIdentity;
925
1023
  if (!hasPositionArg) anim.implicitPosition = true;
926
1024
  let group = classifyTweenPropertyGroup(properties);
927
1025
  if (!group && keyframesData) {
@@ -938,7 +1036,6 @@ function tweenCallToAnimation(call, scope, source) {
938
1036
  if (motionPathResult) anim.arcPath = motionPathResult.arcPath;
939
1037
  if (hasUnresolvedKeyframes) anim.hasUnresolvedKeyframes = true;
940
1038
  if (selector === "__unresolved__") anim.hasUnresolvedSelector = true;
941
- const provenance = readProvenance(call.node);
942
1039
  if (provenance) anim.provenance = provenance;
943
1040
  return anim;
944
1041
  }
@@ -1072,13 +1169,16 @@ function parseGsapScriptAcornForWrite(script) {
1072
1169
  locations: true
1073
1170
  });
1074
1171
  const scope = collectScopeBindings(ast);
1075
- const targetBindings = collectTargetBindings(ast, scope);
1172
+ const identifierBindings = collectIdentifierBindingIndex(ast);
1173
+ const targetBindings = collectTargetBindings(ast, scope, identifierBindings);
1076
1174
  const detection = findTimelineVar(ast, scope);
1077
1175
  const ref = detection.ref ?? { kind: "identifier", name: "tl" };
1078
1176
  const timelineVar = timelineRootSource(ref, script);
1079
1177
  const calls = findAllTweenCalls(ast, ref, scope, targetBindings);
1080
1178
  sortBySourcePosition(calls);
1081
- const rawAnims = calls.map((call) => tweenCallToAnimation(call, scope, script));
1179
+ const rawAnims = calls.map(
1180
+ (call) => tweenCallToAnimation(call, scope, script, identifierBindings)
1181
+ );
1082
1182
  applyTimelineDefaults(rawAnims, detection.defaults);
1083
1183
  resolveTimelinePositions(rawAnims);
1084
1184
  const animations = assignStableIds(rawAnims);