@hyperframes/parsers 0.8.127 → 0.8.129

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-CFUDcLqX.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",
@@ -434,28 +435,20 @@ import { parse as babelParse } from "@babel/parser";
434
435
  // src/gsapObjectArrayTiming.ts
435
436
  var roundPercentage = (percentage) => Math.round(percentage * 10) / 10;
436
437
  function getObjectArrayKeyframeTiming(durations) {
437
- const hasAuthoredDuration = durations.some((duration) => duration !== void 0);
438
- if (hasAuthoredDuration) {
439
- if (!durations.every(
440
- (duration) => typeof duration === "number" && Number.isFinite(duration) && duration > 0
441
- )) {
442
- return null;
443
- }
444
- const totalDuration = durations.reduce((sum, duration) => sum + duration, 0);
445
- let cumulative = 0;
446
- return {
447
- percentages: durations.map((duration) => {
448
- cumulative += duration;
449
- return roundPercentage(cumulative / totalDuration * 100);
450
- }),
451
- totalDuration
452
- };
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;
453
443
  }
454
- const lastIndex = durations.length - 1;
444
+ const totalDuration = steps.reduce((sum, duration) => sum + duration, 0);
445
+ let cumulative = 0;
455
446
  return {
456
- percentages: durations.map(
457
- (_, index) => lastIndex > 0 ? roundPercentage(index / lastIndex * 100) : 0
458
- )
447
+ percentages: steps.map((duration) => {
448
+ cumulative += duration;
449
+ return roundPercentage(cumulative / totalDuration * 100);
450
+ }),
451
+ totalDuration
459
452
  };
460
453
  }
461
454
 
@@ -1628,6 +1621,7 @@ function parsePercentageKeyframes(node, scope, source) {
1628
1621
  if (typeof key !== "string") continue;
1629
1622
  const pctMatch = PERCENTAGE_KEY_RE.exec(key);
1630
1623
  if (pctMatch) {
1624
+ if (!isPlainStep(prop.value)) return void 0;
1631
1625
  const percentage = Number.parseFloat(pctMatch[1] ?? "0");
1632
1626
  const record = objectExpressionToRecord(prop.value, scope, source);
1633
1627
  const properties = {};
@@ -1646,6 +1640,8 @@ function parsePercentageKeyframes(node, scope, source) {
1646
1640
  ease = tryResolveStringProp(prop.value, scope, source) ?? ease;
1647
1641
  } else if (key === "easeEach") {
1648
1642
  easeEach = tryResolveStringProp(prop.value, scope, source) ?? easeEach;
1643
+ } else {
1644
+ return void 0;
1649
1645
  }
1650
1646
  }
1651
1647
  keyframes.sort((a, b) => a.percentage - b.percentage);
@@ -1669,12 +1665,19 @@ function computeKeyframesTotalDuration(varsNode, scope, source) {
1669
1665
  }
1670
1666
  return getObjectArrayKeyframeTiming(durations)?.totalDuration;
1671
1667
  }
1672
- var isFullyReadableStep = (el) => el?.type === "ObjectExpression" && !el.properties.some((p) => p.type === "SpreadElement");
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);
1673
1676
  function parseObjectArrayKeyframes(node, scope, source) {
1674
1677
  const elements = node.elements ?? [];
1675
1678
  const raw = [];
1676
1679
  for (const el of elements) {
1677
- if (!isFullyReadableStep(el)) return void 0;
1680
+ if (!isPlainObject(el)) return void 0;
1678
1681
  const record = objectExpressionToRecord(el, scope, source);
1679
1682
  const properties = {};
1680
1683
  let duration;
@@ -1713,9 +1716,8 @@ function parseSimpleArrayKeyframes(node, scope) {
1713
1716
  const values = [];
1714
1717
  for (const el of prop.value.elements ?? []) {
1715
1718
  const val = resolveNode(el, scope);
1716
- if (typeof val === "number" || typeof val === "string") {
1717
- values.push(val);
1718
- }
1719
+ if (typeof val !== "number" && typeof val !== "string") return void 0;
1720
+ values.push(val);
1719
1721
  }
1720
1722
  if (values.length > 0) arrayProps.set(key, values);
1721
1723
  } else if (key === "ease") {
@@ -1748,6 +1750,7 @@ function parseKeyframesNode(node, scope, source) {
1748
1750
  }
1749
1751
  if (node.type !== "ObjectExpression") return void 0;
1750
1752
  const props = node.properties ?? [];
1753
+ if (!props.every((p) => staticKeyName(p) !== void 0)) return void 0;
1751
1754
  let hasPercentageKey = false;
1752
1755
  let hasArrayValue = false;
1753
1756
  for (const prop of props) {
@@ -1848,7 +1851,7 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1848
1851
  percentage: waypoints.length > 1 ? Math.round(i / (waypoints.length - 1) * 100) : 0,
1849
1852
  properties: { x: wp.x, y: wp.y }
1850
1853
  }));
1851
- keyframesData = { format: "percentage", keyframes: kf };
1854
+ keyframesData = { format: "percentage", keyframes: kf, fromMotionPath: true };
1852
1855
  } else {
1853
1856
  const kfs = keyframesData.keyframes;
1854
1857
  if (kfs.length === waypoints.length) {
@@ -1878,10 +1881,10 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1878
1881
  const position = typeof posVal === "number" ? posVal : typeof posVal === "string" ? posVal : hasPositionArg ? `__raw:${source.slice(call.positionArg.start, call.positionArg.end)}` : 0;
1879
1882
  let duration = typeof vars.duration === "number" ? vars.duration : void 0;
1880
1883
  const ease = typeof vars.ease === "string" ? vars.ease : void 0;
1881
- 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) {
1882
1886
  duration = computeKeyframesTotalDuration(call.varsArg, scope, source);
1883
1887
  }
1884
- const durationUnresolved = call.method !== "set" && duration === void 0 && hasUnknownDuration(call.varsArg, scope);
1885
1888
  let selector = call.selector;
1886
1889
  let targetIdentity;
1887
1890
  if (selector === "__unresolved__") {
@@ -1976,7 +1979,6 @@ function annotateStaggeredCollections(anims) {
1976
1979
  anim.keyframes = { format: "percentage", keyframes: staggeredKeyframes(anim, each) };
1977
1980
  }
1978
1981
  }
1979
- var GSAP_DEFAULT_DURATION = 0.5;
1980
1982
  function resolvePositionString(pos, cursor, prevStart) {
1981
1983
  const trimmed = pos.trim();
1982
1984
  if (trimmed === "") return cursor;
@@ -2058,7 +2060,7 @@ function applyTimelineDefaults(anims, defaults) {
2058
2060
  if (defaults.duration !== void 0) anim.duration = defaults.duration;
2059
2061
  else if (defaults.durationUnresolved) anim.durationUnresolved = true;
2060
2062
  }
2061
- 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)) {
2062
2064
  anim.ease = defaults.ease;
2063
2065
  }
2064
2066
  }
@@ -3669,7 +3671,7 @@ var collectHelperBodies = (statements) => new Map(statements.flatMap(declaredFun
3669
3671
  function dropStatementsUnsafeToUnroll(byStatement, ctx) {
3670
3672
  for (const [stmt, anims] of byStatement) {
3671
3673
  const unknownTiming = anims.some(
3672
- (a) => a.durationUnresolved || a.resolvedStart === void 0 || a.hasUnresolvedSelector
3674
+ (a) => a.durationUnresolved || a.resolvedStart === void 0 || a.hasUnresolvedSelector || a.hasUnresolvedKeyframes
3673
3675
  );
3674
3676
  const bodyStmts = unknownTiming ? null : bodyOf(stmt, ctx.helpers);
3675
3677
  if (bodyStmts === null || !onlyAddsTweens(bodyStmts, ctx)) byStatement.delete(stmt);
@@ -4264,6 +4266,7 @@ export {
4264
4266
  EXCLUDED_TAGS,
4265
4267
  FONT_ALIAS_KEYS,
4266
4268
  FONT_ALIAS_MAP,
4269
+ GSAP_DEFAULT_DURATION,
4267
4270
  HTML_BODY_CSS_HEIGHT_FIRST_RE,
4268
4271
  HTML_BODY_CSS_WIDTH_FIRST_RE,
4269
4272
  LEGACY_TIMING_ATTRIBUTES,
@@ -4292,6 +4295,7 @@ export {
4292
4295
  generateSpringEaseData,
4293
4296
  getAnimationsForElementId,
4294
4297
  getDefaultStageZoom,
4298
+ getObjectArrayKeyframeTiming,
4295
4299
  gsapAnimationsToKeyframes,
4296
4300
  isAspectAgnosticResolutionAlias,
4297
4301
  isCompositionElement,