@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/composition.d.ts +1 -1
- package/dist/composition.js.map +1 -1
- package/dist/gsapConstants.d.ts +1 -1
- package/dist/gsapConstants.js +5 -5
- package/dist/gsapConstants.js.map +1 -1
- package/dist/gsapParser.d.ts +2 -2
- package/dist/gsapParser.js +63 -41
- package/dist/gsapParser.js.map +1 -1
- package/dist/gsapParserAcorn.d.ts +2 -2
- package/dist/gsapParserAcorn.js +32 -30
- package/dist/gsapParserAcorn.js.map +1 -1
- package/dist/gsapParserExports.d.ts +15 -1
- package/dist/gsapParserExports.js +34 -30
- package/dist/gsapParserExports.js.map +1 -1
- package/dist/{gsapSerialize-CFUDcLqX.d.ts → gsapSerialize-CfSXM_Ez.d.ts} +4 -2
- package/dist/gsapWriterAcorn.d.ts +23 -3
- package/dist/gsapWriterAcorn.js +147 -89
- package/dist/gsapWriterAcorn.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +35 -31
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
export { A as ArcPathConfig,
|
|
1
|
+
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';
|
|
2
2
|
export { isStudioHoldSet } from './gsapParser.js';
|
|
3
3
|
export { SPRING_PRESETS, SpringPreset, generateSpringEaseData } from './springEase.js';
|
|
4
4
|
export { parseGsapScriptAcorn as parseGsapScript } from './gsapParserAcorn.js';
|
|
5
5
|
import './types-Ejqndkej.js';
|
|
6
|
+
|
|
7
|
+
interface ObjectArrayKeyframeTiming {
|
|
8
|
+
percentages: number[];
|
|
9
|
+
totalDuration: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolve GSAP object-array keyframe positions exactly once for parsers and writers.
|
|
13
|
+
* Each step's keyframe sits at its cumulative end; a step without a duration plays
|
|
14
|
+
* GSAP's default. A non-positive or unresolved duration leaves the timing unresolved:
|
|
15
|
+
* callers must preserve the source rather than silently invent different timing.
|
|
16
|
+
*/
|
|
17
|
+
declare function getObjectArrayKeyframeTiming(durations: ReadonlyArray<unknown>): ObjectArrayKeyframeTiming | null;
|
|
18
|
+
|
|
19
|
+
export { getObjectArrayKeyframeTiming };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/gsapConstants.ts
|
|
2
|
+
var GSAP_DEFAULT_DURATION = 0.5;
|
|
2
3
|
var SUPPORTED_PROPS = [
|
|
3
4
|
// 2D Transforms
|
|
4
5
|
"x",
|
|
@@ -345,28 +346,20 @@ import { parse as babelParse } from "@babel/parser";
|
|
|
345
346
|
// src/gsapObjectArrayTiming.ts
|
|
346
347
|
var roundPercentage = (percentage) => Math.round(percentage * 10) / 10;
|
|
347
348
|
function getObjectArrayKeyframeTiming(durations) {
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return null;
|
|
354
|
-
}
|
|
355
|
-
const totalDuration = durations.reduce((sum, duration) => sum + duration, 0);
|
|
356
|
-
let cumulative = 0;
|
|
357
|
-
return {
|
|
358
|
-
percentages: durations.map((duration) => {
|
|
359
|
-
cumulative += duration;
|
|
360
|
-
return roundPercentage(cumulative / totalDuration * 100);
|
|
361
|
-
}),
|
|
362
|
-
totalDuration
|
|
363
|
-
};
|
|
349
|
+
const steps = durations.map((duration) => duration ?? GSAP_DEFAULT_DURATION);
|
|
350
|
+
if (!steps.every(
|
|
351
|
+
(duration) => typeof duration === "number" && Number.isFinite(duration) && duration > 0
|
|
352
|
+
)) {
|
|
353
|
+
return null;
|
|
364
354
|
}
|
|
365
|
-
const
|
|
355
|
+
const totalDuration = steps.reduce((sum, duration) => sum + duration, 0);
|
|
356
|
+
let cumulative = 0;
|
|
366
357
|
return {
|
|
367
|
-
percentages:
|
|
368
|
-
|
|
369
|
-
|
|
358
|
+
percentages: steps.map((duration) => {
|
|
359
|
+
cumulative += duration;
|
|
360
|
+
return roundPercentage(cumulative / totalDuration * 100);
|
|
361
|
+
}),
|
|
362
|
+
totalDuration
|
|
370
363
|
};
|
|
371
364
|
}
|
|
372
365
|
|
|
@@ -1539,6 +1532,7 @@ function parsePercentageKeyframes(node, scope, source) {
|
|
|
1539
1532
|
if (typeof key !== "string") continue;
|
|
1540
1533
|
const pctMatch = PERCENTAGE_KEY_RE.exec(key);
|
|
1541
1534
|
if (pctMatch) {
|
|
1535
|
+
if (!isPlainStep(prop.value)) return void 0;
|
|
1542
1536
|
const percentage = Number.parseFloat(pctMatch[1] ?? "0");
|
|
1543
1537
|
const record = objectExpressionToRecord(prop.value, scope, source);
|
|
1544
1538
|
const properties = {};
|
|
@@ -1557,6 +1551,8 @@ function parsePercentageKeyframes(node, scope, source) {
|
|
|
1557
1551
|
ease = tryResolveStringProp(prop.value, scope, source) ?? ease;
|
|
1558
1552
|
} else if (key === "easeEach") {
|
|
1559
1553
|
easeEach = tryResolveStringProp(prop.value, scope, source) ?? easeEach;
|
|
1554
|
+
} else {
|
|
1555
|
+
return void 0;
|
|
1560
1556
|
}
|
|
1561
1557
|
}
|
|
1562
1558
|
keyframes.sort((a, b) => a.percentage - b.percentage);
|
|
@@ -1580,12 +1576,19 @@ function computeKeyframesTotalDuration(varsNode, scope, source) {
|
|
|
1580
1576
|
}
|
|
1581
1577
|
return getObjectArrayKeyframeTiming(durations)?.totalDuration;
|
|
1582
1578
|
}
|
|
1583
|
-
|
|
1579
|
+
function staticKeyName(prop) {
|
|
1580
|
+
if (prop.type !== "ObjectProperty" && prop.type !== "Property") return void 0;
|
|
1581
|
+
if (prop.method || prop.kind && prop.kind !== "init") return void 0;
|
|
1582
|
+
const key = prop.computed ? prop.key?.type === "Literal" && prop.key.value : prop.key?.name ?? prop.key?.value;
|
|
1583
|
+
return typeof key === "string" ? key : void 0;
|
|
1584
|
+
}
|
|
1585
|
+
var isPlainObject = (node) => node?.type === "ObjectExpression" && (node.properties ?? []).every((p) => staticKeyName(p) !== void 0);
|
|
1586
|
+
var isPlainStep = (node) => node?.type === "Literal" || isPlainObject(node);
|
|
1584
1587
|
function parseObjectArrayKeyframes(node, scope, source) {
|
|
1585
1588
|
const elements = node.elements ?? [];
|
|
1586
1589
|
const raw = [];
|
|
1587
1590
|
for (const el of elements) {
|
|
1588
|
-
if (!
|
|
1591
|
+
if (!isPlainObject(el)) return void 0;
|
|
1589
1592
|
const record = objectExpressionToRecord(el, scope, source);
|
|
1590
1593
|
const properties = {};
|
|
1591
1594
|
let duration;
|
|
@@ -1624,9 +1627,8 @@ function parseSimpleArrayKeyframes(node, scope) {
|
|
|
1624
1627
|
const values = [];
|
|
1625
1628
|
for (const el of prop.value.elements ?? []) {
|
|
1626
1629
|
const val = resolveNode(el, scope);
|
|
1627
|
-
if (typeof val
|
|
1628
|
-
|
|
1629
|
-
}
|
|
1630
|
+
if (typeof val !== "number" && typeof val !== "string") return void 0;
|
|
1631
|
+
values.push(val);
|
|
1630
1632
|
}
|
|
1631
1633
|
if (values.length > 0) arrayProps.set(key, values);
|
|
1632
1634
|
} else if (key === "ease") {
|
|
@@ -1659,6 +1661,7 @@ function parseKeyframesNode(node, scope, source) {
|
|
|
1659
1661
|
}
|
|
1660
1662
|
if (node.type !== "ObjectExpression") return void 0;
|
|
1661
1663
|
const props = node.properties ?? [];
|
|
1664
|
+
if (!props.every((p) => staticKeyName(p) !== void 0)) return void 0;
|
|
1662
1665
|
let hasPercentageKey = false;
|
|
1663
1666
|
let hasArrayValue = false;
|
|
1664
1667
|
for (const prop of props) {
|
|
@@ -1759,7 +1762,7 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
|
|
|
1759
1762
|
percentage: waypoints.length > 1 ? Math.round(i / (waypoints.length - 1) * 100) : 0,
|
|
1760
1763
|
properties: { x: wp.x, y: wp.y }
|
|
1761
1764
|
}));
|
|
1762
|
-
keyframesData = { format: "percentage", keyframes: kf };
|
|
1765
|
+
keyframesData = { format: "percentage", keyframes: kf, fromMotionPath: true };
|
|
1763
1766
|
} else {
|
|
1764
1767
|
const kfs = keyframesData.keyframes;
|
|
1765
1768
|
if (kfs.length === waypoints.length) {
|
|
@@ -1789,10 +1792,10 @@ function tweenCallToAnimation(call, scope, source, identifierBindings) {
|
|
|
1789
1792
|
const position = typeof posVal === "number" ? posVal : typeof posVal === "string" ? posVal : hasPositionArg ? `__raw:${source.slice(call.positionArg.start, call.positionArg.end)}` : 0;
|
|
1790
1793
|
let duration = typeof vars.duration === "number" ? vars.duration : void 0;
|
|
1791
1794
|
const ease = typeof vars.ease === "string" ? vars.ease : void 0;
|
|
1792
|
-
|
|
1795
|
+
const durationUnresolved = call.method !== "set" && duration === void 0 && hasUnknownDuration(call.varsArg, scope);
|
|
1796
|
+
if (duration === void 0 && keyframesData && !durationUnresolved) {
|
|
1793
1797
|
duration = computeKeyframesTotalDuration(call.varsArg, scope, source);
|
|
1794
1798
|
}
|
|
1795
|
-
const durationUnresolved = call.method !== "set" && duration === void 0 && hasUnknownDuration(call.varsArg, scope);
|
|
1796
1799
|
let selector = call.selector;
|
|
1797
1800
|
let targetIdentity;
|
|
1798
1801
|
if (selector === "__unresolved__") {
|
|
@@ -1887,7 +1890,6 @@ function annotateStaggeredCollections(anims) {
|
|
|
1887
1890
|
anim.keyframes = { format: "percentage", keyframes: staggeredKeyframes(anim, each) };
|
|
1888
1891
|
}
|
|
1889
1892
|
}
|
|
1890
|
-
var GSAP_DEFAULT_DURATION = 0.5;
|
|
1891
1893
|
function resolvePositionString(pos, cursor, prevStart) {
|
|
1892
1894
|
const trimmed = pos.trim();
|
|
1893
1895
|
if (trimmed === "") return cursor;
|
|
@@ -1969,7 +1971,7 @@ function applyTimelineDefaults(anims, defaults) {
|
|
|
1969
1971
|
if (defaults.duration !== void 0) anim.duration = defaults.duration;
|
|
1970
1972
|
else if (defaults.durationUnresolved) anim.durationUnresolved = true;
|
|
1971
1973
|
}
|
|
1972
|
-
if (anim.ease === void 0 && defaults.ease !== void 0 && !anim.keyframes) {
|
|
1974
|
+
if (anim.ease === void 0 && defaults.ease !== void 0 && (!anim.keyframes || anim.keyframes.fromMotionPath)) {
|
|
1973
1975
|
anim.ease = defaults.ease;
|
|
1974
1976
|
}
|
|
1975
1977
|
}
|
|
@@ -2160,6 +2162,7 @@ function parseGsapScriptAcornUncached(script) {
|
|
|
2160
2162
|
}
|
|
2161
2163
|
}
|
|
2162
2164
|
export {
|
|
2165
|
+
GSAP_DEFAULT_DURATION,
|
|
2163
2166
|
PROPERTY_GROUPS,
|
|
2164
2167
|
SPRING_PRESETS,
|
|
2165
2168
|
SUPPORTED_EASES,
|
|
@@ -2169,6 +2172,7 @@ export {
|
|
|
2169
2172
|
editabilityForProvenance,
|
|
2170
2173
|
generateSpringEaseData,
|
|
2171
2174
|
getAnimationsForElementId,
|
|
2175
|
+
getObjectArrayKeyframeTiming,
|
|
2172
2176
|
gsapAnimationsToKeyframes,
|
|
2173
2177
|
isStudioHoldSet,
|
|
2174
2178
|
keyframesToGsapAnimations,
|