@hyperframes/parsers 0.8.127 → 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.
@@ -1,5 +1,5 @@
1
- import { g as ParsedGsap, c as GsapMethod, G as GsapAnimation } from './gsapSerialize-CFUDcLqX.js';
2
- export { A as ArcPathConfig, a as ArcPathSegment, e as GsapProvenance, f as GsapProvenanceKind, K as KeyframeEditability, M as MotionPathShape, t as buildArcPath, o as editabilityForProvenance } from './gsapSerialize-CFUDcLqX.js';
1
+ import { P as ParsedGsap, G as GsapMethod, a as GsapAnimation } from './gsapSerialize-CfSXM_Ez.js';
2
+ export { A as ArcPathConfig, b as ArcPathSegment, c as GsapProvenance, d as GsapProvenanceKind, K as KeyframeEditability, M as MotionPathShape, e as buildArcPath, f as editabilityForProvenance } from './gsapSerialize-CfSXM_Ez.js';
3
3
  import './types-Ejqndkej.js';
4
4
 
5
5
  interface TweenCallInfo {
@@ -3,6 +3,7 @@ import * as acorn from "acorn";
3
3
  import * as acornWalk from "acorn-walk";
4
4
 
5
5
  // src/gsapConstants.ts
6
+ var GSAP_DEFAULT_DURATION = 0.5;
6
7
  var BUILTIN_VAR_KEYS = /* @__PURE__ */ new Set(["duration", "ease", "delay"]);
7
8
  var DROPPED_VAR_KEYS = /* @__PURE__ */ new Set([
8
9
  "onComplete",
@@ -605,28 +606,20 @@ function inlineComputedTimelines(ast, timelineVar, resolve) {
605
606
  // src/gsapObjectArrayTiming.ts
606
607
  var roundPercentage = (percentage) => Math.round(percentage * 10) / 10;
607
608
  function getObjectArrayKeyframeTiming(durations) {
608
- const hasAuthoredDuration = durations.some((duration) => duration !== void 0);
609
- if (hasAuthoredDuration) {
610
- if (!durations.every(
611
- (duration) => typeof duration === "number" && Number.isFinite(duration) && duration > 0
612
- )) {
613
- return null;
614
- }
615
- const totalDuration = durations.reduce((sum, duration) => sum + duration, 0);
616
- let cumulative = 0;
617
- return {
618
- percentages: durations.map((duration) => {
619
- cumulative += duration;
620
- return roundPercentage(cumulative / totalDuration * 100);
621
- }),
622
- totalDuration
623
- };
609
+ const steps = durations.map((duration) => duration ?? GSAP_DEFAULT_DURATION);
610
+ if (!steps.every(
611
+ (duration) => typeof duration === "number" && Number.isFinite(duration) && duration > 0
612
+ )) {
613
+ return null;
624
614
  }
625
- const lastIndex = durations.length - 1;
615
+ const totalDuration = steps.reduce((sum, duration) => sum + duration, 0);
616
+ let cumulative = 0;
626
617
  return {
627
- percentages: durations.map(
628
- (_, index) => lastIndex > 0 ? roundPercentage(index / lastIndex * 100) : 0
629
- )
618
+ percentages: steps.map((duration) => {
619
+ cumulative += duration;
620
+ return roundPercentage(cumulative / totalDuration * 100);
621
+ }),
622
+ totalDuration
630
623
  };
631
624
  }
632
625
 
@@ -1220,6 +1213,7 @@ function parsePercentageKeyframes(node, scope, source) {
1220
1213
  if (typeof key !== "string") continue;
1221
1214
  const pctMatch = PERCENTAGE_KEY_RE.exec(key);
1222
1215
  if (pctMatch) {
1216
+ if (!isPlainStep(prop.value)) return void 0;
1223
1217
  const percentage = Number.parseFloat(pctMatch[1] ?? "0");
1224
1218
  const record = objectExpressionToRecord(prop.value, scope, source);
1225
1219
  const properties = {};
@@ -1238,6 +1232,8 @@ function parsePercentageKeyframes(node, scope, source) {
1238
1232
  ease = tryResolveStringProp(prop.value, scope, source) ?? ease;
1239
1233
  } else if (key === "easeEach") {
1240
1234
  easeEach = tryResolveStringProp(prop.value, scope, source) ?? easeEach;
1235
+ } else {
1236
+ return void 0;
1241
1237
  }
1242
1238
  }
1243
1239
  keyframes.sort((a, b) => a.percentage - b.percentage);
@@ -1261,12 +1257,19 @@ function computeKeyframesTotalDuration(varsNode, scope, source) {
1261
1257
  }
1262
1258
  return getObjectArrayKeyframeTiming(durations)?.totalDuration;
1263
1259
  }
1264
- var isFullyReadableStep = (el) => el?.type === "ObjectExpression" && !el.properties.some((p) => p.type === "SpreadElement");
1260
+ function staticKeyName(prop) {
1261
+ if (prop.type !== "ObjectProperty" && prop.type !== "Property") return void 0;
1262
+ if (prop.method || prop.kind && prop.kind !== "init") return void 0;
1263
+ const key = prop.computed ? prop.key?.type === "Literal" && prop.key.value : prop.key?.name ?? prop.key?.value;
1264
+ return typeof key === "string" ? key : void 0;
1265
+ }
1266
+ var isPlainObject = (node) => node?.type === "ObjectExpression" && (node.properties ?? []).every((p) => staticKeyName(p) !== void 0);
1267
+ var isPlainStep = (node) => node?.type === "Literal" || isPlainObject(node);
1265
1268
  function parseObjectArrayKeyframes(node, scope, source) {
1266
1269
  const elements = node.elements ?? [];
1267
1270
  const raw = [];
1268
1271
  for (const el of elements) {
1269
- if (!isFullyReadableStep(el)) return void 0;
1272
+ if (!isPlainObject(el)) return void 0;
1270
1273
  const record = objectExpressionToRecord(el, scope, source);
1271
1274
  const properties = {};
1272
1275
  let duration;
@@ -1305,9 +1308,8 @@ function parseSimpleArrayKeyframes(node, scope) {
1305
1308
  const values = [];
1306
1309
  for (const el of prop.value.elements ?? []) {
1307
1310
  const val = resolveNode(el, scope);
1308
- if (typeof val === "number" || typeof val === "string") {
1309
- values.push(val);
1310
- }
1311
+ if (typeof val !== "number" && typeof val !== "string") return void 0;
1312
+ values.push(val);
1311
1313
  }
1312
1314
  if (values.length > 0) arrayProps.set(key, values);
1313
1315
  } else if (key === "ease") {
@@ -1340,6 +1342,7 @@ function parseKeyframesNode(node, scope, source) {
1340
1342
  }
1341
1343
  if (node.type !== "ObjectExpression") return void 0;
1342
1344
  const props = node.properties ?? [];
1345
+ if (!props.every((p) => staticKeyName(p) !== void 0)) return void 0;
1343
1346
  let hasPercentageKey = false;
1344
1347
  let hasArrayValue = false;
1345
1348
  for (const prop of props) {
@@ -1440,7 +1443,7 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1440
1443
  percentage: waypoints.length > 1 ? Math.round(i / (waypoints.length - 1) * 100) : 0,
1441
1444
  properties: { x: wp.x, y: wp.y }
1442
1445
  }));
1443
- keyframesData = { format: "percentage", keyframes: kf };
1446
+ keyframesData = { format: "percentage", keyframes: kf, fromMotionPath: true };
1444
1447
  } else {
1445
1448
  const kfs = keyframesData.keyframes;
1446
1449
  if (kfs.length === waypoints.length) {
@@ -1470,10 +1473,10 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
1470
1473
  const position = typeof posVal === "number" ? posVal : typeof posVal === "string" ? posVal : hasPositionArg ? `__raw:${source.slice(call.positionArg.start, call.positionArg.end)}` : 0;
1471
1474
  let duration = typeof vars.duration === "number" ? vars.duration : void 0;
1472
1475
  const ease = typeof vars.ease === "string" ? vars.ease : void 0;
1473
- if (duration === void 0 && keyframesData) {
1476
+ const durationUnresolved = call.method !== "set" && duration === void 0 && hasUnknownDuration(call.varsArg, scope);
1477
+ if (duration === void 0 && keyframesData && !durationUnresolved) {
1474
1478
  duration = computeKeyframesTotalDuration(call.varsArg, scope, source);
1475
1479
  }
1476
- const durationUnresolved = call.method !== "set" && duration === void 0 && hasUnknownDuration(call.varsArg, scope);
1477
1480
  let selector = call.selector;
1478
1481
  let targetIdentity;
1479
1482
  if (selector === "__unresolved__") {
@@ -1568,7 +1571,6 @@ function annotateStaggeredCollections(anims) {
1568
1571
  anim.keyframes = { format: "percentage", keyframes: staggeredKeyframes(anim, each) };
1569
1572
  }
1570
1573
  }
1571
- var GSAP_DEFAULT_DURATION = 0.5;
1572
1574
  function resolvePositionString(pos, cursor, prevStart) {
1573
1575
  const trimmed = pos.trim();
1574
1576
  if (trimmed === "") return cursor;
@@ -1650,7 +1652,7 @@ function applyTimelineDefaults(anims, defaults) {
1650
1652
  if (defaults.duration !== void 0) anim.duration = defaults.duration;
1651
1653
  else if (defaults.durationUnresolved) anim.durationUnresolved = true;
1652
1654
  }
1653
- if (anim.ease === void 0 && defaults.ease !== void 0 && !anim.keyframes) {
1655
+ if (anim.ease === void 0 && defaults.ease !== void 0 && (!anim.keyframes || anim.keyframes.fromMotionPath)) {
1654
1656
  anim.ease = defaults.ease;
1655
1657
  }
1656
1658
  }