@hyperframes/parsers 0.7.71 → 0.7.72
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/colorGradingContract.js +23 -3
- package/dist/colorGradingContract.js.map +1 -1
- package/dist/gsapConstants.js +4 -0
- package/dist/gsapConstants.js.map +1 -1
- package/dist/gsapParser.d.ts +3 -4
- package/dist/gsapParser.js +201 -86
- package/dist/gsapParser.js.map +1 -1
- package/dist/gsapParserAcorn.js +41 -29
- package/dist/gsapParserAcorn.js.map +1 -1
- package/dist/gsapParserExports.js +45 -29
- package/dist/gsapParserExports.js.map +1 -1
- package/dist/gsapWriterAcorn.d.ts +3 -4
- package/dist/gsapWriterAcorn.js +167 -69
- package/dist/gsapWriterAcorn.js.map +1 -1
- package/dist/index.js +45 -29
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/gsapParserAcorn.js
CHANGED
|
@@ -459,6 +459,34 @@ function inlineComputedTimelines(ast, timelineVar, resolve) {
|
|
|
459
459
|
ast.body = expandStatements(body, ctx);
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
+
// src/gsapObjectArrayTiming.ts
|
|
463
|
+
var roundPercentage = (percentage) => Math.round(percentage * 10) / 10;
|
|
464
|
+
function getObjectArrayKeyframeTiming(durations) {
|
|
465
|
+
const hasAuthoredDuration = durations.some((duration) => duration !== void 0);
|
|
466
|
+
if (hasAuthoredDuration) {
|
|
467
|
+
if (!durations.every(
|
|
468
|
+
(duration) => typeof duration === "number" && Number.isFinite(duration) && duration > 0
|
|
469
|
+
)) {
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
const totalDuration = durations.reduce((sum, duration) => sum + duration, 0);
|
|
473
|
+
let cumulative = 0;
|
|
474
|
+
return {
|
|
475
|
+
percentages: durations.map((duration) => {
|
|
476
|
+
cumulative += duration;
|
|
477
|
+
return roundPercentage(cumulative / totalDuration * 100);
|
|
478
|
+
}),
|
|
479
|
+
totalDuration
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
const lastIndex = durations.length - 1;
|
|
483
|
+
return {
|
|
484
|
+
percentages: durations.map(
|
|
485
|
+
(_, index) => lastIndex > 0 ? roundPercentage(index / lastIndex * 100) : 0
|
|
486
|
+
)
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
462
490
|
// src/gsapParserAcorn.ts
|
|
463
491
|
var GSAP_METHODS2 = /* @__PURE__ */ new Set(["set", "to", "from", "fromTo"]);
|
|
464
492
|
var QUERY_METHODS = /* @__PURE__ */ new Set(["querySelector", "querySelectorAll"]);
|
|
@@ -1047,6 +1075,8 @@ function parsePercentageKeyframes(node, scope, source) {
|
|
|
1047
1075
|
for (const [k, v] of Object.entries(record)) {
|
|
1048
1076
|
if (k === "ease" && typeof v === "string") {
|
|
1049
1077
|
kfEase = v;
|
|
1078
|
+
} else if (k === "duration") {
|
|
1079
|
+
continue;
|
|
1050
1080
|
} else if (typeof v === "number" || typeof v === "string") {
|
|
1051
1081
|
properties[k] = v;
|
|
1052
1082
|
}
|
|
@@ -1071,13 +1101,13 @@ function computeKeyframesTotalDuration(varsNode, scope, source) {
|
|
|
1071
1101
|
(p) => (p.key?.name ?? p.key?.value) === "keyframes"
|
|
1072
1102
|
)?.value;
|
|
1073
1103
|
if (!kfNode || kfNode.type !== "ArrayExpression") return void 0;
|
|
1074
|
-
|
|
1104
|
+
const durations = [];
|
|
1075
1105
|
for (const el of kfNode.elements ?? []) {
|
|
1076
1106
|
if (!el || el.type !== "ObjectExpression") continue;
|
|
1077
1107
|
const r = objectExpressionToRecord(el, scope, source);
|
|
1078
|
-
|
|
1108
|
+
durations.push(r.duration);
|
|
1079
1109
|
}
|
|
1080
|
-
return
|
|
1110
|
+
return getObjectArrayKeyframeTiming(durations)?.totalDuration;
|
|
1081
1111
|
}
|
|
1082
1112
|
function parseObjectArrayKeyframes(node, scope, source) {
|
|
1083
1113
|
const elements = node.elements ?? [];
|
|
@@ -1089,7 +1119,7 @@ function parseObjectArrayKeyframes(node, scope, source) {
|
|
|
1089
1119
|
let duration;
|
|
1090
1120
|
let ease;
|
|
1091
1121
|
for (const [k, v] of Object.entries(record)) {
|
|
1092
|
-
if (k === "duration"
|
|
1122
|
+
if (k === "duration") {
|
|
1093
1123
|
duration = v;
|
|
1094
1124
|
} else if (k === "ease" && typeof v === "string") {
|
|
1095
1125
|
ease = v;
|
|
@@ -1099,31 +1129,13 @@ function parseObjectArrayKeyframes(node, scope, source) {
|
|
|
1099
1129
|
}
|
|
1100
1130
|
raw.push({ properties, duration, ease });
|
|
1101
1131
|
}
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
keyframes.push({
|
|
1110
|
-
percentage,
|
|
1111
|
-
properties: entry.properties,
|
|
1112
|
-
...entry.ease ? { ease: entry.ease } : {}
|
|
1113
|
-
});
|
|
1114
|
-
}
|
|
1115
|
-
} else {
|
|
1116
|
-
for (let i = 0; i < raw.length; i++) {
|
|
1117
|
-
const entry = raw[i];
|
|
1118
|
-
if (!entry) continue;
|
|
1119
|
-
const percentage = raw.length > 1 ? Math.round(i / (raw.length - 1) * 100) : 0;
|
|
1120
|
-
keyframes.push({
|
|
1121
|
-
percentage,
|
|
1122
|
-
properties: entry.properties,
|
|
1123
|
-
...entry.ease ? { ease: entry.ease } : {}
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1132
|
+
const timing = getObjectArrayKeyframeTiming(raw.map((entry) => entry.duration));
|
|
1133
|
+
if (!timing) return void 0;
|
|
1134
|
+
const keyframes = raw.map((entry, index) => ({
|
|
1135
|
+
percentage: timing.percentages[index],
|
|
1136
|
+
properties: entry.properties,
|
|
1137
|
+
...entry.ease ? { ease: entry.ease } : {}
|
|
1138
|
+
}));
|
|
1127
1139
|
return { format: "object-array", keyframes };
|
|
1128
1140
|
}
|
|
1129
1141
|
function parseSimpleArrayKeyframes(node, scope) {
|