@hyperframes/parsers 0.8.49 → 0.8.51

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,4 +1,4 @@
1
- export { A as ArcPathConfig, a as ArcPathSegment, G as GsapAnimation, b as GsapKeyframesData, c as GsapMethod, d as GsapPercentageKeyframe, e as GsapProvenance, f as GsapProvenanceKind, K as KeyframeEditability, P as ParsedGsap, S as SourcedGsapPercentageKeyframe, g as SplitAnimationsOptions, h as SplitAnimationsResult, i as editabilityForProvenance, j as getAnimationsForElementId, k as gsapAnimationsToKeyframes, l as keyframesToGsapAnimations, s as serializeGsapAnimations, v as validateCompositionGsap } from './gsapSerialize-QZcXUoVf.js';
1
+ export { A as ArcPathConfig, a as ArcPathSegment, G as GsapAnimation, b as GsapKeyframesData, c as GsapMethod, d as GsapPercentageKeyframe, e as GsapProvenance, f as GsapProvenanceKind, K as KeyframeEditability, P as ParsedGsap, S as SourcedGsapPercentageKeyframe, g as SplitAnimationsOptions, h as SplitAnimationsResult, i as editabilityForProvenance, j as getAnimationsForElementId, k as gsapAnimationsToKeyframes, l as keyframesToGsapAnimations, s as serializeGsapAnimations, v as validateCompositionGsap } from './gsapSerialize-b8lNzSbI.js';
2
2
  export { isStudioHoldSet } from './gsapParser.js';
3
3
  export { PROPERTY_GROUPS, PropertyGroupName, SUPPORTED_EASES, SUPPORTED_PROPS, classifyPropertyGroup, classifyTweenPropertyGroup } from './gsapConstants.js';
4
4
  export { SPRING_PRESETS, SpringPreset, generateSpringEaseData } from './springEase.js';
@@ -405,7 +405,16 @@ import * as acorn from "acorn";
405
405
  import * as acornWalk from "acorn-walk";
406
406
 
407
407
  // src/gsapInline.ts
408
- var SKIP_KEYS = /* @__PURE__ */ new Set(["type", "start", "end", "loc", "range", "__hfProvenance", "__hfOrder"]);
408
+ var SKIP_KEYS = /* @__PURE__ */ new Set([
409
+ "type",
410
+ "start",
411
+ "end",
412
+ "loc",
413
+ "range",
414
+ "__hfProvenance",
415
+ "__hfOrder",
416
+ "__hfSiteStart"
417
+ ]);
409
418
  var FUNCTION_TYPES = /* @__PURE__ */ new Set([
410
419
  "ArrowFunctionExpression",
411
420
  "FunctionExpression",
@@ -508,6 +517,9 @@ function isTimelineRooted(call, timelineVar) {
508
517
  if (timelineRootName(call) !== timelineVar) return false;
509
518
  return call.callee?.property?.type === "Identifier" && GSAP_METHODS.has(call.callee.property.name);
510
519
  }
520
+ function isAddLabelCall(call, timelineVar) {
521
+ return timelineRootName(call) === timelineVar && call.callee?.property?.name === "addLabel";
522
+ }
511
523
  function containsTimelineCall(node, timelineVar) {
512
524
  let found = false;
513
525
  walkNodes(node, (n) => {
@@ -714,12 +726,17 @@ function bodyStatements(node) {
714
726
  }
715
727
  function tagTimelineCalls(stmts, prov, ctx) {
716
728
  for (const stmt of stmts) {
729
+ const calls = [];
717
730
  walkNodes(stmt, (n) => {
718
- if (n.type === "CallExpression" && isTimelineRooted(n, ctx.timelineVar)) {
719
- tagProvenance(n, { ...prov });
720
- n.__hfOrder = ctx.order.n++;
721
- }
731
+ if (n.type === "CallExpression" && (isTimelineRooted(n, ctx.timelineVar) || isAddLabelCall(n, ctx.timelineVar)))
732
+ calls.push(n);
722
733
  });
734
+ calls.sort((a, b) => a.callee.property.start - b.callee.property.start);
735
+ for (const n of calls) {
736
+ tagProvenance(n, { ...prov });
737
+ n.__hfOrder = ctx.order.n++;
738
+ n.__hfSiteStart = ctx.rootStart;
739
+ }
723
740
  }
724
741
  }
725
742
  function expandBody(bodyStmts, bindings, prov, ctx) {
@@ -906,10 +923,14 @@ function inlineComputedTimelines(ast, timelineVar, resolve) {
906
923
  resolve,
907
924
  depth: 0,
908
925
  site: { n: 0 },
909
- order: { n: 0 }
926
+ order: { n: 0 },
927
+ rootStart: 0
910
928
  };
911
929
  const body = (ast.body ?? []).filter((stmt) => !isHelperDecl(stmt, helpers));
912
- ast.body = expandStatements(body, ctx);
930
+ ast.body = body.flatMap((stmt) => {
931
+ ctx.rootStart = stmt.start;
932
+ return expandStatements([stmt], ctx);
933
+ });
913
934
  }
914
935
 
915
936
  // src/gsapParserAcorn.ts
@@ -1327,6 +1348,14 @@ function objectExpressionToRecord(node, scope, source) {
1327
1348
  function isGsapTimelineCall(node) {
1328
1349
  return node?.type === "CallExpression" && node.callee?.type === "MemberExpression" && node.callee.object?.name === "gsap" && node.callee.property?.name === "timeline";
1329
1350
  }
1351
+ function hasUnknownDuration(varsNode, scope) {
1352
+ if (!varsNode) return false;
1353
+ if (varsNode.type !== "ObjectExpression") return true;
1354
+ const props = varsNode.properties ?? [];
1355
+ if (props.some((p) => p.type === "SpreadElement")) return true;
1356
+ const prop = props.find((p) => isObjectProperty(p) && propKeyName(p) === "duration");
1357
+ return prop !== void 0 && typeof resolveNode(prop.value, scope) !== "number";
1358
+ }
1330
1359
  function staticMemberKey(node) {
1331
1360
  if (!node || node.type !== "MemberExpression") return null;
1332
1361
  if (node.computed) {
@@ -1368,7 +1397,10 @@ function extractTimelineDefaults(callNode, scope) {
1368
1397
  const key = propKeyName(prop);
1369
1398
  const val = resolveNode(prop.value, scope);
1370
1399
  if (key === "ease" && typeof val === "string") result.ease = val;
1371
- if (key === "duration" && typeof val === "number") result.duration = val;
1400
+ if (key === "duration") {
1401
+ if (typeof val === "number") result.duration = val;
1402
+ else result.durationUnresolved = true;
1403
+ }
1372
1404
  }
1373
1405
  return Object.keys(result).length > 0 ? result : void 0;
1374
1406
  }
@@ -1743,6 +1775,7 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1743
1775
  if (duration === void 0 && keyframesData) {
1744
1776
  duration = computeKeyframesTotalDuration(call.varsArg, scope, source);
1745
1777
  }
1778
+ const durationUnresolved = call.method !== "set" && duration === void 0 && hasUnknownDuration(call.varsArg, scope);
1746
1779
  let selector = call.selector;
1747
1780
  let targetIdentity;
1748
1781
  if (selector === "__unresolved__") {
@@ -1790,6 +1823,7 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1790
1823
  if (keyframesData) anim.keyframes = keyframesData;
1791
1824
  if (motionPathResult) anim.arcPath = motionPathResult.arcPath;
1792
1825
  if (hasUnresolvedKeyframes) anim.hasUnresolvedKeyframes = true;
1826
+ if (durationUnresolved) anim.durationUnresolved = true;
1793
1827
  if (selector === "__unresolved__") anim.hasUnresolvedSelector = true;
1794
1828
  if (provenance) anim.provenance = provenance;
1795
1829
  return anim;
@@ -1913,8 +1947,9 @@ function applyTimelineDefaults(anims, defaults) {
1913
1947
  if (!defaults) return;
1914
1948
  for (const anim of anims) {
1915
1949
  if (anim.method === "set") continue;
1916
- if (anim.duration === void 0 && defaults.duration !== void 0) {
1917
- anim.duration = defaults.duration;
1950
+ if (anim.duration === void 0 && !anim.durationUnresolved) {
1951
+ if (defaults.duration !== void 0) anim.duration = defaults.duration;
1952
+ else if (defaults.durationUnresolved) anim.durationUnresolved = true;
1918
1953
  }
1919
1954
  if (anim.ease === void 0 && defaults.ease !== void 0) {
1920
1955
  anim.ease = defaults.ease;
@@ -1947,12 +1982,14 @@ function resolveAnimStart(anim, cursor, prevStart, labels) {
1947
1982
  function resolveTimelinePositions(anims, labelDefs = []) {
1948
1983
  let cursor = 0;
1949
1984
  let prevStart = 0;
1985
+ let cursorKnown = true;
1950
1986
  const labels = /* @__PURE__ */ new Map();
1951
1987
  let labelIdx = 0;
1952
1988
  const sortedLabels = [...labelDefs].sort((a, b) => a.order - b.order);
1953
1989
  const defineLabel = (def) => {
1954
1990
  let value;
1955
1991
  if (typeof def.position === "number") value = def.position;
1992
+ else if (!cursorKnown) return;
1956
1993
  else if (typeof def.position === "string") {
1957
1994
  value = resolveLabelPosition(def.position, labels, cursor) ?? cursor;
1958
1995
  } else value = cursor;
@@ -1968,7 +2005,9 @@ function resolveTimelinePositions(anims, labelDefs = []) {
1968
2005
  return;
1969
2006
  }
1970
2007
  const duration = anim.method === "set" ? 0 : anim.duration ?? GSAP_DEFAULT_DURATION;
1971
- const start = resolveAnimStart(anim, cursor, prevStart, labels);
2008
+ const readsCursor = anim.implicitPosition || typeof anim.position !== "number";
2009
+ const start = cursorKnown || !readsCursor ? resolveAnimStart(anim, cursor, prevStart, labels) : null;
2010
+ if (start == null || anim.durationUnresolved) cursorKnown = false;
1972
2011
  if (start != null) {
1973
2012
  anim.resolvedStart = Math.max(0, start);
1974
2013
  prevStart = anim.resolvedStart;
@@ -1978,7 +2017,15 @@ function resolveTimelinePositions(anims, labelDefs = []) {
1978
2017
  while (labelIdx < sortedLabels.length) defineLabel(sortedLabels[labelIdx++]);
1979
2018
  }
1980
2019
  function collectAddLabelDefs(ast, ref, scope, sortedCalls) {
1981
- const callLocs = sortedCalls.map((c) => c.node.callee?.property?.loc?.start);
2020
+ const callKeys = sortedCalls.map((c) => ({
2021
+ site: callSiteStart(c),
2022
+ order: c.node.__hfOrder
2023
+ }));
2024
+ const comesAfter = (site, order, labelSite, labelOrder) => {
2025
+ if (site === void 0) return false;
2026
+ if (site !== labelSite) return site > labelSite;
2027
+ return (order ?? -Infinity) > (labelOrder ?? -Infinity);
2028
+ };
1982
2029
  const defs = [];
1983
2030
  acornWalk.simple(ast, {
1984
2031
  // fallow-ignore-next-line complexity
@@ -1992,12 +2039,11 @@ function collectAddLabelDefs(ast, ref, scope, sortedCalls) {
1992
2039
  if (!name) return;
1993
2040
  const posVal = resolveNode(node.arguments?.[1], scope);
1994
2041
  const position = typeof posVal === "number" || typeof posVal === "string" ? posVal : void 0;
1995
- const labelLoc = callee.property?.loc?.start;
2042
+ const labelStart = node.__hfSiteStart ?? callee.property?.start;
2043
+ const labelOrder = node.__hfOrder;
1996
2044
  let order = sortedCalls.length;
1997
- if (labelLoc) {
1998
- order = callLocs.findIndex(
1999
- (l) => l && (l.line > labelLoc.line || l.line === labelLoc.line && l.column > labelLoc.column)
2000
- );
2045
+ if (labelStart !== void 0) {
2046
+ order = callKeys.findIndex((k) => comesAfter(k.site, k.order, labelStart, labelOrder));
2001
2047
  if (order === -1) order = sortedCalls.length;
2002
2048
  }
2003
2049
  defs.push({ name, position, order });
@@ -2011,13 +2057,17 @@ function compareByLoc(a, b) {
2011
2057
  if (!aLoc || !bLoc) return 0;
2012
2058
  return aLoc.line - bLoc.line || aLoc.column - bLoc.column;
2013
2059
  }
2060
+ function callSiteStart(call) {
2061
+ return call.node.__hfSiteStart ?? call.node.callee?.property?.start;
2062
+ }
2014
2063
  function compareCallOrder(a, b) {
2064
+ const aSite = callSiteStart(a);
2065
+ const bSite = callSiteStart(b);
2066
+ if (aSite !== void 0 && bSite !== void 0 && aSite !== bSite) return aSite - bSite;
2015
2067
  const ao = a.node.__hfOrder;
2016
2068
  const bo = b.node.__hfOrder;
2017
- if (ao === void 0 && bo === void 0) return compareByLoc(a, b);
2018
- if (ao === void 0) return -1;
2019
- if (bo === void 0) return 1;
2020
- return ao - bo;
2069
+ if (ao !== void 0 && bo !== void 0) return ao - bo;
2070
+ return compareByLoc(a, b);
2021
2071
  }
2022
2072
  function sortBySourcePosition(calls) {
2023
2073
  calls.sort(compareCallOrder);