@hyperframes/parsers 0.8.126 → 0.8.128

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.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { C as CompositionVariable, T as TimelineElement, a as CanvasResolution, K as Keyframe, S as StageZoomKeyframe, V as ValidationResult } from './types-Ejqndkej.js';
2
2
  export { A as AddElementData, b as Asset, B as BooleanVariable, c as CANVAS_DIMENSIONS, d as COMPOSITION_VARIABLE_TYPES, e as ColorVariable, f as CompositionAPI, g as CompositionAsset, h as CompositionSpec, i as CompositionVariableBase, j as CompositionVariableType, D as DEFAULT_DURATIONS, E as ElementKeyframes, k as EnumVariable, F as FontVariable, I as ImageVariable, l as KeyframeProperties, M as MediaElementType, m as MediaFile, N as NumberVariable, P as PlayerAPI, R as ResolvedResolutionFlag, n as StageZoom, o as StringVariable, p as TIMELINE_COLORS, q as TimelineCompositionElement, r as TimelineElementBase, s as TimelineElementType, t as TimelineMediaElement, u as TimelineTextElement, v as VALID_CANVAS_RESOLUTIONS, W as WaveformData, w as getDefaultStageZoom, x as isAspectAgnosticResolutionAlias, y as isCompositionElement, z as isMediaElement, G as isTextElement, H as normalizeResolutionFlag, J as resolveResolutionFlagPair } from './types-Ejqndkej.js';
3
- 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 PROPERTY_GROUPS, g as ParsedGsap, h as PropertyGroupName, S as SUPPORTED_EASES, i as SUPPORTED_PROPS, j as SourcedGsapPercentageKeyframe, k as SplitAnimationsOptions, l as SplitAnimationsResult, m as classifyPropertyGroup, n as classifyTweenPropertyGroup, o as editabilityForProvenance, p as getAnimationsForElementId, q as gsapAnimationsToKeyframes, r as keyframesToGsapAnimations, s as serializeGsapAnimations, v as validateCompositionGsap } from './gsapSerialize-CVwsMItk.js';
3
+ export { A as ArcPathConfig, b as ArcPathSegment, u as GSAP_DEFAULT_DURATION, a as GsapAnimation, h as GsapKeyframesData, G as GsapMethod, i as GsapPercentageKeyframe, c as GsapProvenance, d as GsapProvenanceKind, K as KeyframeEditability, j as PROPERTY_GROUPS, P as ParsedGsap, k as PropertyGroupName, S as SUPPORTED_EASES, l as SUPPORTED_PROPS, w as SourcedGsapPercentageKeyframe, r as SplitAnimationsOptions, t as SplitAnimationsResult, m as classifyPropertyGroup, n as classifyTweenPropertyGroup, f as editabilityForProvenance, o as getAnimationsForElementId, p as gsapAnimationsToKeyframes, q as keyframesToGsapAnimations, s as serializeGsapAnimations, v as validateCompositionGsap } from './gsapSerialize-CfSXM_Ez.js';
4
4
  export { isStudioHoldSet } from './gsapParser.js';
5
+ export { getObjectArrayKeyframeTiming } from './gsapParserExports.js';
5
6
  export { SPRING_PRESETS, SpringPreset, generateSpringEaseData } from './springEase.js';
6
7
  export { parseGsapScriptAcorn as parseGsapScript } from './gsapParserAcorn.js';
7
8
  export { EXCLUDED_TAGS, ensureHfIds, isCompositionTemplate, mintHfId, walkCompositionDescendants } from './hfIds.js';
package/dist/index.js CHANGED
@@ -88,6 +88,7 @@ function getDefaultStageZoom(resolution) {
88
88
  }
89
89
 
90
90
  // src/gsapConstants.ts
91
+ var GSAP_DEFAULT_DURATION = 0.5;
91
92
  var SUPPORTED_PROPS = [
92
93
  // 2D Transforms
93
94
  "x",
@@ -128,6 +129,22 @@ var SUPPORTED_PROPS = [
128
129
  // DOM content (number counters, text roll-ups)
129
130
  "innerText"
130
131
  ];
132
+ var BUILTIN_VAR_KEYS = /* @__PURE__ */ new Set(["duration", "ease", "delay"]);
133
+ var DROPPED_VAR_KEYS = /* @__PURE__ */ new Set([
134
+ "onComplete",
135
+ "onStart",
136
+ "onUpdate",
137
+ "onRepeat"
138
+ ]);
139
+ var EXTRAS_KEYS = /* @__PURE__ */ new Set([
140
+ "stagger",
141
+ "yoyo",
142
+ "repeat",
143
+ "repeatDelay",
144
+ "snap",
145
+ "overwrite",
146
+ "immediateRender"
147
+ ]);
131
148
  var PROPERTY_GROUPS = {
132
149
  position: /* @__PURE__ */ new Set(["x", "y", "xPercent", "yPercent"]),
133
150
  scale: /* @__PURE__ */ new Set(["scale", "scaleX", "scaleY"]),
@@ -418,28 +435,20 @@ import { parse as babelParse } from "@babel/parser";
418
435
  // src/gsapObjectArrayTiming.ts
419
436
  var roundPercentage = (percentage) => Math.round(percentage * 10) / 10;
420
437
  function getObjectArrayKeyframeTiming(durations) {
421
- const hasAuthoredDuration = durations.some((duration) => duration !== void 0);
422
- if (hasAuthoredDuration) {
423
- if (!durations.every(
424
- (duration) => typeof duration === "number" && Number.isFinite(duration) && duration > 0
425
- )) {
426
- return null;
427
- }
428
- const totalDuration = durations.reduce((sum, duration) => sum + duration, 0);
429
- let cumulative = 0;
430
- return {
431
- percentages: durations.map((duration) => {
432
- cumulative += duration;
433
- return roundPercentage(cumulative / totalDuration * 100);
434
- }),
435
- totalDuration
436
- };
438
+ const steps = durations.map((duration) => duration ?? GSAP_DEFAULT_DURATION);
439
+ if (!steps.every(
440
+ (duration) => typeof duration === "number" && Number.isFinite(duration) && duration > 0
441
+ )) {
442
+ return null;
437
443
  }
438
- const lastIndex = durations.length - 1;
444
+ const totalDuration = steps.reduce((sum, duration) => sum + duration, 0);
445
+ let cumulative = 0;
439
446
  return {
440
- percentages: durations.map(
441
- (_, index) => lastIndex > 0 ? roundPercentage(index / lastIndex * 100) : 0
442
- )
447
+ percentages: steps.map((duration) => {
448
+ cumulative += duration;
449
+ return roundPercentage(cumulative / totalDuration * 100);
450
+ }),
451
+ totalDuration
443
452
  };
444
453
  }
445
454
 
@@ -1534,17 +1543,6 @@ function findTimelineVar(ast, scope) {
1534
1543
  });
1535
1544
  return { timelineVar, ref, timelineCount, defaults };
1536
1545
  }
1537
- var BUILTIN_VAR_KEYS = /* @__PURE__ */ new Set(["duration", "ease", "delay"]);
1538
- var DROPPED_VAR_KEYS = /* @__PURE__ */ new Set(["onComplete", "onStart", "onUpdate", "onRepeat"]);
1539
- var EXTRAS_KEYS = /* @__PURE__ */ new Set([
1540
- "stagger",
1541
- "yoyo",
1542
- "repeat",
1543
- "repeatDelay",
1544
- "snap",
1545
- "overwrite",
1546
- "immediateRender"
1547
- ]);
1548
1546
  function isTimelineRootedCall(callNode, ref) {
1549
1547
  let obj = callNode.callee?.object;
1550
1548
  while (obj?.type === "CallExpression") {
@@ -1623,6 +1621,7 @@ function parsePercentageKeyframes(node, scope, source) {
1623
1621
  if (typeof key !== "string") continue;
1624
1622
  const pctMatch = PERCENTAGE_KEY_RE.exec(key);
1625
1623
  if (pctMatch) {
1624
+ if (!isPlainStep(prop.value)) return void 0;
1626
1625
  const percentage = Number.parseFloat(pctMatch[1] ?? "0");
1627
1626
  const record = objectExpressionToRecord(prop.value, scope, source);
1628
1627
  const properties = {};
@@ -1641,6 +1640,8 @@ function parsePercentageKeyframes(node, scope, source) {
1641
1640
  ease = tryResolveStringProp(prop.value, scope, source) ?? ease;
1642
1641
  } else if (key === "easeEach") {
1643
1642
  easeEach = tryResolveStringProp(prop.value, scope, source) ?? easeEach;
1643
+ } else {
1644
+ return void 0;
1644
1645
  }
1645
1646
  }
1646
1647
  keyframes.sort((a, b) => a.percentage - b.percentage);
@@ -1664,11 +1665,19 @@ function computeKeyframesTotalDuration(varsNode, scope, source) {
1664
1665
  }
1665
1666
  return getObjectArrayKeyframeTiming(durations)?.totalDuration;
1666
1667
  }
1668
+ function staticKeyName(prop) {
1669
+ if (prop.type !== "ObjectProperty" && prop.type !== "Property") return void 0;
1670
+ if (prop.method || prop.kind && prop.kind !== "init") return void 0;
1671
+ const key = prop.computed ? prop.key?.type === "Literal" && prop.key.value : prop.key?.name ?? prop.key?.value;
1672
+ return typeof key === "string" ? key : void 0;
1673
+ }
1674
+ var isPlainObject = (node) => node?.type === "ObjectExpression" && (node.properties ?? []).every((p) => staticKeyName(p) !== void 0);
1675
+ var isPlainStep = (node) => node?.type === "Literal" || isPlainObject(node);
1667
1676
  function parseObjectArrayKeyframes(node, scope, source) {
1668
1677
  const elements = node.elements ?? [];
1669
1678
  const raw = [];
1670
1679
  for (const el of elements) {
1671
- if (!el || el.type !== "ObjectExpression") continue;
1680
+ if (!isPlainObject(el)) return void 0;
1672
1681
  const record = objectExpressionToRecord(el, scope, source);
1673
1682
  const properties = {};
1674
1683
  let duration;
@@ -1680,6 +1689,8 @@ function parseObjectArrayKeyframes(node, scope, source) {
1680
1689
  ease = v;
1681
1690
  } else if (typeof v === "number" || typeof v === "string") {
1682
1691
  properties[k] = v;
1692
+ } else {
1693
+ return void 0;
1683
1694
  }
1684
1695
  }
1685
1696
  raw.push({ properties, duration, ease });
@@ -1705,9 +1716,8 @@ function parseSimpleArrayKeyframes(node, scope) {
1705
1716
  const values = [];
1706
1717
  for (const el of prop.value.elements ?? []) {
1707
1718
  const val = resolveNode(el, scope);
1708
- if (typeof val === "number" || typeof val === "string") {
1709
- values.push(val);
1710
- }
1719
+ if (typeof val !== "number" && typeof val !== "string") return void 0;
1720
+ values.push(val);
1711
1721
  }
1712
1722
  if (values.length > 0) arrayProps.set(key, values);
1713
1723
  } else if (key === "ease") {
@@ -1740,6 +1750,7 @@ function parseKeyframesNode(node, scope, source) {
1740
1750
  }
1741
1751
  if (node.type !== "ObjectExpression") return void 0;
1742
1752
  const props = node.properties ?? [];
1753
+ if (!props.every((p) => staticKeyName(p) !== void 0)) return void 0;
1743
1754
  let hasPercentageKey = false;
1744
1755
  let hasArrayValue = false;
1745
1756
  for (const prop of props) {
@@ -1840,7 +1851,7 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1840
1851
  percentage: waypoints.length > 1 ? Math.round(i / (waypoints.length - 1) * 100) : 0,
1841
1852
  properties: { x: wp.x, y: wp.y }
1842
1853
  }));
1843
- keyframesData = { format: "percentage", keyframes: kf };
1854
+ keyframesData = { format: "percentage", keyframes: kf, fromMotionPath: true };
1844
1855
  } else {
1845
1856
  const kfs = keyframesData.keyframes;
1846
1857
  if (kfs.length === waypoints.length) {
@@ -1870,10 +1881,10 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1870
1881
  const position = typeof posVal === "number" ? posVal : typeof posVal === "string" ? posVal : hasPositionArg ? `__raw:${source.slice(call.positionArg.start, call.positionArg.end)}` : 0;
1871
1882
  let duration = typeof vars.duration === "number" ? vars.duration : void 0;
1872
1883
  const ease = typeof vars.ease === "string" ? vars.ease : void 0;
1873
- if (duration === void 0 && keyframesData) {
1884
+ const durationUnresolved = call.method !== "set" && duration === void 0 && hasUnknownDuration(call.varsArg, scope);
1885
+ if (duration === void 0 && keyframesData && !durationUnresolved) {
1874
1886
  duration = computeKeyframesTotalDuration(call.varsArg, scope, source);
1875
1887
  }
1876
- const durationUnresolved = call.method !== "set" && duration === void 0 && hasUnknownDuration(call.varsArg, scope);
1877
1888
  let selector = call.selector;
1878
1889
  let targetIdentity;
1879
1890
  if (selector === "__unresolved__") {
@@ -1968,7 +1979,6 @@ function annotateStaggeredCollections(anims) {
1968
1979
  anim.keyframes = { format: "percentage", keyframes: staggeredKeyframes(anim, each) };
1969
1980
  }
1970
1981
  }
1971
- var GSAP_DEFAULT_DURATION = 0.5;
1972
1982
  function resolvePositionString(pos, cursor, prevStart) {
1973
1983
  const trimmed = pos.trim();
1974
1984
  if (trimmed === "") return cursor;
@@ -2050,7 +2060,7 @@ function applyTimelineDefaults(anims, defaults) {
2050
2060
  if (defaults.duration !== void 0) anim.duration = defaults.duration;
2051
2061
  else if (defaults.durationUnresolved) anim.durationUnresolved = true;
2052
2062
  }
2053
- if (anim.ease === void 0 && defaults.ease !== void 0 && !anim.keyframes) {
2063
+ if (anim.ease === void 0 && defaults.ease !== void 0 && (!anim.keyframes || anim.keyframes.fromMotionPath)) {
2054
2064
  anim.ease = defaults.ease;
2055
2065
  }
2056
2066
  }
@@ -3661,7 +3671,7 @@ var collectHelperBodies = (statements) => new Map(statements.flatMap(declaredFun
3661
3671
  function dropStatementsUnsafeToUnroll(byStatement, ctx) {
3662
3672
  for (const [stmt, anims] of byStatement) {
3663
3673
  const unknownTiming = anims.some(
3664
- (a) => a.durationUnresolved || a.resolvedStart === void 0 || a.hasUnresolvedSelector
3674
+ (a) => a.durationUnresolved || a.resolvedStart === void 0 || a.hasUnresolvedSelector || a.hasUnresolvedKeyframes
3665
3675
  );
3666
3676
  const bodyStmts = unknownTiming ? null : bodyOf(stmt, ctx.helpers);
3667
3677
  if (bodyStmts === null || !onlyAddsTweens(bodyStmts, ctx)) byStatement.delete(stmt);
@@ -4256,6 +4266,7 @@ export {
4256
4266
  EXCLUDED_TAGS,
4257
4267
  FONT_ALIAS_KEYS,
4258
4268
  FONT_ALIAS_MAP,
4269
+ GSAP_DEFAULT_DURATION,
4259
4270
  HTML_BODY_CSS_HEIGHT_FIRST_RE,
4260
4271
  HTML_BODY_CSS_WIDTH_FIRST_RE,
4261
4272
  LEGACY_TIMING_ATTRIBUTES,
@@ -4284,6 +4295,7 @@ export {
4284
4295
  generateSpringEaseData,
4285
4296
  getAnimationsForElementId,
4286
4297
  getDefaultStageZoom,
4298
+ getObjectArrayKeyframeTiming,
4287
4299
  gsapAnimationsToKeyframes,
4288
4300
  isAspectAgnosticResolutionAlias,
4289
4301
  isCompositionElement,