@hyperframes/parsers 0.8.50 → 0.8.52

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-QZcXUoVf.js';
2
- export { A as ArcPathConfig, a as ArcPathSegment, e as GsapProvenance, f as GsapProvenanceKind, K as KeyframeEditability, M as MotionPathShape, m as buildArcPath, i as editabilityForProvenance } from './gsapSerialize-QZcXUoVf.js';
1
+ import { P as ParsedGsap, c as GsapMethod, G as GsapAnimation } from './gsapSerialize-b8lNzSbI.js';
2
+ export { A as ArcPathConfig, a as ArcPathSegment, e as GsapProvenance, f as GsapProvenanceKind, K as KeyframeEditability, M as MotionPathShape, m as buildArcPath, i as editabilityForProvenance } from './gsapSerialize-b8lNzSbI.js';
3
3
  import './types-Y0NXTiVo.js';
4
4
  import './gsapConstants.js';
5
5
 
@@ -58,7 +58,16 @@ function buildArcPath(coords, curviness, autoRotate, isCubic) {
58
58
  }
59
59
 
60
60
  // src/gsapInline.ts
61
- var SKIP_KEYS = /* @__PURE__ */ new Set(["type", "start", "end", "loc", "range", "__hfProvenance", "__hfOrder"]);
61
+ var SKIP_KEYS = /* @__PURE__ */ new Set([
62
+ "type",
63
+ "start",
64
+ "end",
65
+ "loc",
66
+ "range",
67
+ "__hfProvenance",
68
+ "__hfOrder",
69
+ "__hfSiteStart"
70
+ ]);
62
71
  var FUNCTION_TYPES = /* @__PURE__ */ new Set([
63
72
  "ArrowFunctionExpression",
64
73
  "FunctionExpression",
@@ -161,6 +170,9 @@ function isTimelineRooted(call, timelineVar) {
161
170
  if (timelineRootName(call) !== timelineVar) return false;
162
171
  return call.callee?.property?.type === "Identifier" && GSAP_METHODS.has(call.callee.property.name);
163
172
  }
173
+ function isAddLabelCall(call, timelineVar) {
174
+ return timelineRootName(call) === timelineVar && call.callee?.property?.name === "addLabel";
175
+ }
164
176
  function containsTimelineCall(node, timelineVar) {
165
177
  let found = false;
166
178
  walkNodes(node, (n) => {
@@ -367,12 +379,17 @@ function bodyStatements(node) {
367
379
  }
368
380
  function tagTimelineCalls(stmts, prov, ctx) {
369
381
  for (const stmt of stmts) {
382
+ const calls = [];
370
383
  walkNodes(stmt, (n) => {
371
- if (n.type === "CallExpression" && isTimelineRooted(n, ctx.timelineVar)) {
372
- tagProvenance(n, { ...prov });
373
- n.__hfOrder = ctx.order.n++;
374
- }
384
+ if (n.type === "CallExpression" && (isTimelineRooted(n, ctx.timelineVar) || isAddLabelCall(n, ctx.timelineVar)))
385
+ calls.push(n);
375
386
  });
387
+ calls.sort((a, b) => a.callee.property.start - b.callee.property.start);
388
+ for (const n of calls) {
389
+ tagProvenance(n, { ...prov });
390
+ n.__hfOrder = ctx.order.n++;
391
+ n.__hfSiteStart = ctx.rootStart;
392
+ }
376
393
  }
377
394
  }
378
395
  function expandBody(bodyStmts, bindings, prov, ctx) {
@@ -559,10 +576,14 @@ function inlineComputedTimelines(ast, timelineVar, resolve) {
559
576
  resolve,
560
577
  depth: 0,
561
578
  site: { n: 0 },
562
- order: { n: 0 }
579
+ order: { n: 0 },
580
+ rootStart: 0
563
581
  };
564
582
  const body = (ast.body ?? []).filter((stmt) => !isHelperDecl(stmt, helpers));
565
- ast.body = expandStatements(body, ctx);
583
+ ast.body = body.flatMap((stmt) => {
584
+ ctx.rootStart = stmt.start;
585
+ return expandStatements([stmt], ctx);
586
+ });
566
587
  }
567
588
 
568
589
  // src/gsapObjectArrayTiming.ts
@@ -1008,6 +1029,14 @@ function objectExpressionToRecord(node, scope, source) {
1008
1029
  function isGsapTimelineCall(node) {
1009
1030
  return node?.type === "CallExpression" && node.callee?.type === "MemberExpression" && node.callee.object?.name === "gsap" && node.callee.property?.name === "timeline";
1010
1031
  }
1032
+ function hasUnknownDuration(varsNode, scope) {
1033
+ if (!varsNode) return false;
1034
+ if (varsNode.type !== "ObjectExpression") return true;
1035
+ const props = varsNode.properties ?? [];
1036
+ if (props.some((p) => p.type === "SpreadElement")) return true;
1037
+ const prop = props.find((p) => isObjectProperty(p) && propKeyName(p) === "duration");
1038
+ return prop !== void 0 && typeof resolveNode(prop.value, scope) !== "number";
1039
+ }
1011
1040
  function staticMemberKey(node) {
1012
1041
  if (!node || node.type !== "MemberExpression") return null;
1013
1042
  if (node.computed) {
@@ -1049,7 +1078,10 @@ function extractTimelineDefaults(callNode, scope) {
1049
1078
  const key = propKeyName(prop);
1050
1079
  const val = resolveNode(prop.value, scope);
1051
1080
  if (key === "ease" && typeof val === "string") result.ease = val;
1052
- if (key === "duration" && typeof val === "number") result.duration = val;
1081
+ if (key === "duration") {
1082
+ if (typeof val === "number") result.duration = val;
1083
+ else result.durationUnresolved = true;
1084
+ }
1053
1085
  }
1054
1086
  return Object.keys(result).length > 0 ? result : void 0;
1055
1087
  }
@@ -1424,6 +1456,7 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1424
1456
  if (duration === void 0 && keyframesData) {
1425
1457
  duration = computeKeyframesTotalDuration(call.varsArg, scope, source);
1426
1458
  }
1459
+ const durationUnresolved = call.method !== "set" && duration === void 0 && hasUnknownDuration(call.varsArg, scope);
1427
1460
  let selector = call.selector;
1428
1461
  let targetIdentity;
1429
1462
  if (selector === "__unresolved__") {
@@ -1471,6 +1504,7 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1471
1504
  if (keyframesData) anim.keyframes = keyframesData;
1472
1505
  if (motionPathResult) anim.arcPath = motionPathResult.arcPath;
1473
1506
  if (hasUnresolvedKeyframes) anim.hasUnresolvedKeyframes = true;
1507
+ if (durationUnresolved) anim.durationUnresolved = true;
1474
1508
  if (selector === "__unresolved__") anim.hasUnresolvedSelector = true;
1475
1509
  if (provenance) anim.provenance = provenance;
1476
1510
  return anim;
@@ -1594,8 +1628,9 @@ function applyTimelineDefaults(anims, defaults) {
1594
1628
  if (!defaults) return;
1595
1629
  for (const anim of anims) {
1596
1630
  if (anim.method === "set") continue;
1597
- if (anim.duration === void 0 && defaults.duration !== void 0) {
1598
- anim.duration = defaults.duration;
1631
+ if (anim.duration === void 0 && !anim.durationUnresolved) {
1632
+ if (defaults.duration !== void 0) anim.duration = defaults.duration;
1633
+ else if (defaults.durationUnresolved) anim.durationUnresolved = true;
1599
1634
  }
1600
1635
  if (anim.ease === void 0 && defaults.ease !== void 0) {
1601
1636
  anim.ease = defaults.ease;
@@ -1628,12 +1663,14 @@ function resolveAnimStart(anim, cursor, prevStart, labels) {
1628
1663
  function resolveTimelinePositions(anims, labelDefs = []) {
1629
1664
  let cursor = 0;
1630
1665
  let prevStart = 0;
1666
+ let cursorKnown = true;
1631
1667
  const labels = /* @__PURE__ */ new Map();
1632
1668
  let labelIdx = 0;
1633
1669
  const sortedLabels = [...labelDefs].sort((a, b) => a.order - b.order);
1634
1670
  const defineLabel = (def) => {
1635
1671
  let value;
1636
1672
  if (typeof def.position === "number") value = def.position;
1673
+ else if (!cursorKnown) return;
1637
1674
  else if (typeof def.position === "string") {
1638
1675
  value = resolveLabelPosition(def.position, labels, cursor) ?? cursor;
1639
1676
  } else value = cursor;
@@ -1649,7 +1686,9 @@ function resolveTimelinePositions(anims, labelDefs = []) {
1649
1686
  return;
1650
1687
  }
1651
1688
  const duration = anim.method === "set" ? 0 : anim.duration ?? GSAP_DEFAULT_DURATION;
1652
- const start = resolveAnimStart(anim, cursor, prevStart, labels);
1689
+ const readsCursor = anim.implicitPosition || typeof anim.position !== "number";
1690
+ const start = cursorKnown || !readsCursor ? resolveAnimStart(anim, cursor, prevStart, labels) : null;
1691
+ if (start == null || anim.durationUnresolved) cursorKnown = false;
1653
1692
  if (start != null) {
1654
1693
  anim.resolvedStart = Math.max(0, start);
1655
1694
  prevStart = anim.resolvedStart;
@@ -1659,7 +1698,15 @@ function resolveTimelinePositions(anims, labelDefs = []) {
1659
1698
  while (labelIdx < sortedLabels.length) defineLabel(sortedLabels[labelIdx++]);
1660
1699
  }
1661
1700
  function collectAddLabelDefs(ast, ref, scope, sortedCalls) {
1662
- const callLocs = sortedCalls.map((c) => c.node.callee?.property?.loc?.start);
1701
+ const callKeys = sortedCalls.map((c) => ({
1702
+ site: callSiteStart(c),
1703
+ order: c.node.__hfOrder
1704
+ }));
1705
+ const comesAfter = (site, order, labelSite, labelOrder) => {
1706
+ if (site === void 0) return false;
1707
+ if (site !== labelSite) return site > labelSite;
1708
+ return (order ?? -Infinity) > (labelOrder ?? -Infinity);
1709
+ };
1663
1710
  const defs = [];
1664
1711
  acornWalk.simple(ast, {
1665
1712
  // fallow-ignore-next-line complexity
@@ -1673,12 +1720,11 @@ function collectAddLabelDefs(ast, ref, scope, sortedCalls) {
1673
1720
  if (!name) return;
1674
1721
  const posVal = resolveNode(node.arguments?.[1], scope);
1675
1722
  const position = typeof posVal === "number" || typeof posVal === "string" ? posVal : void 0;
1676
- const labelLoc = callee.property?.loc?.start;
1723
+ const labelStart = node.__hfSiteStart ?? callee.property?.start;
1724
+ const labelOrder = node.__hfOrder;
1677
1725
  let order = sortedCalls.length;
1678
- if (labelLoc) {
1679
- order = callLocs.findIndex(
1680
- (l) => l && (l.line > labelLoc.line || l.line === labelLoc.line && l.column > labelLoc.column)
1681
- );
1726
+ if (labelStart !== void 0) {
1727
+ order = callKeys.findIndex((k) => comesAfter(k.site, k.order, labelStart, labelOrder));
1682
1728
  if (order === -1) order = sortedCalls.length;
1683
1729
  }
1684
1730
  defs.push({ name, position, order });
@@ -1692,13 +1738,17 @@ function compareByLoc(a, b) {
1692
1738
  if (!aLoc || !bLoc) return 0;
1693
1739
  return aLoc.line - bLoc.line || aLoc.column - bLoc.column;
1694
1740
  }
1741
+ function callSiteStart(call) {
1742
+ return call.node.__hfSiteStart ?? call.node.callee?.property?.start;
1743
+ }
1695
1744
  function compareCallOrder(a, b) {
1745
+ const aSite = callSiteStart(a);
1746
+ const bSite = callSiteStart(b);
1747
+ if (aSite !== void 0 && bSite !== void 0 && aSite !== bSite) return aSite - bSite;
1696
1748
  const ao = a.node.__hfOrder;
1697
1749
  const bo = b.node.__hfOrder;
1698
- if (ao === void 0 && bo === void 0) return compareByLoc(a, b);
1699
- if (ao === void 0) return -1;
1700
- if (bo === void 0) return 1;
1701
- return ao - bo;
1750
+ if (ao !== void 0 && bo !== void 0) return ao - bo;
1751
+ return compareByLoc(a, b);
1702
1752
  }
1703
1753
  function sortBySourcePosition(calls) {
1704
1754
  calls.sort(compareCallOrder);