@hyperframes/parsers 0.9.31 → 0.9.32
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/ffBinaries.d.ts +1 -1
- package/dist/ffBinaries.js +2 -5
- package/dist/gsapParser.js +49 -26
- package/dist/gsapParserExports.js +7 -4
- package/dist/gsapWriterAcorn.js +45 -23
- package/dist/index.js +7 -4
- package/package.json +2 -2
package/dist/ffBinaries.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ interface FindFfBinaryOptions {
|
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Resolve an FFmpeg-family binary: env override first, then a native
|
|
24
|
-
*
|
|
24
|
+
* PATH scan on Windows or `which` plus PATH scan on Unix,
|
|
25
25
|
* then a project-local `.hyperframes/bin`, then well-known Unix install dirs, then an
|
|
26
26
|
* `@ffmpeg-installer`/`@ffprobe-installer` package reachable from the current folder.
|
|
27
27
|
* A found binary is cached for the process lifetime; a miss only for a few
|
package/dist/ffBinaries.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { execFileSync } from "child_process";
|
|
3
3
|
import { accessSync, closeSync, constants, existsSync, openSync, readSync } from "fs";
|
|
4
4
|
import { createRequire } from "module";
|
|
5
|
-
import { basename, delimiter, dirname, join, resolve } from "path";
|
|
5
|
+
import { basename, delimiter, dirname, isAbsolute, join, resolve } from "path";
|
|
6
6
|
var FFMPEG_PATH_ENV = "HYPERFRAMES_FFMPEG_PATH";
|
|
7
7
|
var FFPROBE_PATH_ENV = "HYPERFRAMES_FFPROBE_PATH";
|
|
8
8
|
var ENV_BY_NAME = {
|
|
@@ -59,10 +59,7 @@ function isExecutablePathCandidate(candidate) {
|
|
|
59
59
|
}
|
|
60
60
|
function scanPath(name) {
|
|
61
61
|
const pathValue = process.env.PATH;
|
|
62
|
-
const searchDirs = [
|
|
63
|
-
...process.platform === "win32" ? [process.cwd()] : [],
|
|
64
|
-
...pathValue ? pathValue.split(delimiter) : []
|
|
65
|
-
].filter(Boolean);
|
|
62
|
+
const searchDirs = (pathValue ? pathValue.split(delimiter) : []).filter((dir) => isAbsolute(dir));
|
|
66
63
|
if (searchDirs.length === 0) return void 0;
|
|
67
64
|
const extensions = process.platform === "win32" ? [
|
|
68
65
|
".exe",
|
package/dist/gsapParser.js
CHANGED
|
@@ -213,7 +213,7 @@ function serializeGsapAnimations(animations, timelineVar = "tl", options) {
|
|
|
213
213
|
return aNum - bNum;
|
|
214
214
|
});
|
|
215
215
|
const lines = sorted.map((anim) => {
|
|
216
|
-
const selector =
|
|
216
|
+
const selector = scriptJson(anim.targetSelector);
|
|
217
217
|
const props = { ...anim.properties };
|
|
218
218
|
if (anim.duration !== void 0) props.duration = anim.duration;
|
|
219
219
|
if (anim.ease) props.ease = anim.ease;
|
|
@@ -226,7 +226,7 @@ function serializeGsapAnimations(animations, timelineVar = "tl", options) {
|
|
|
226
226
|
propsStr = propsStr.slice(0, -2) + `, ${extrasStr} }`;
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
-
const posStr =
|
|
229
|
+
const posStr = scriptJson(anim.position);
|
|
230
230
|
switch (anim.method) {
|
|
231
231
|
case "set":
|
|
232
232
|
return anim.global ? ` gsap.set(${selector}, ${propsStr});` : ` ${timelineVar}.set(${selector}, ${propsStr}, ${posStr});`;
|
|
@@ -270,11 +270,20 @@ function serializeGsapAnimations(animations, timelineVar = "tl", options) {
|
|
|
270
270
|
${lines.join("\n")}${mediaSync}${postamble}
|
|
271
271
|
`;
|
|
272
272
|
}
|
|
273
|
+
function scriptJson(value) {
|
|
274
|
+
return String(JSON.stringify(value)).replace(/<(\/script|!--)/gi, "\\u003c$1");
|
|
275
|
+
}
|
|
276
|
+
var TWEEN_METHODS = /* @__PURE__ */ new Set(["set", "to", "from", "fromTo"]);
|
|
277
|
+
function tweenMethodCode(method) {
|
|
278
|
+
if (!TWEEN_METHODS.has(method))
|
|
279
|
+
throw new TypeError(`Unsupported tween method: ${scriptJson(method)}`);
|
|
280
|
+
return method;
|
|
281
|
+
}
|
|
273
282
|
function serializeValue(value) {
|
|
274
283
|
if (typeof value === "string" && value.startsWith("__raw:")) {
|
|
275
284
|
return value.slice(6);
|
|
276
285
|
}
|
|
277
|
-
if (typeof value === "string") return
|
|
286
|
+
if (typeof value === "string") return scriptJson(value);
|
|
278
287
|
return String(value);
|
|
279
288
|
}
|
|
280
289
|
function plainPercentKey(percentage) {
|
|
@@ -282,7 +291,7 @@ function plainPercentKey(percentage) {
|
|
|
282
291
|
return `${text}%`;
|
|
283
292
|
}
|
|
284
293
|
function safeJsKey(key) {
|
|
285
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key :
|
|
294
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : scriptJson(key);
|
|
286
295
|
}
|
|
287
296
|
function serializeObject(obj) {
|
|
288
297
|
const entries = Object.entries(obj).map(([key, value]) => {
|
|
@@ -436,6 +445,19 @@ function resolveConversionProps(anim, resolvedFromValues) {
|
|
|
436
445
|
const toProps = resolvedFromValues ? { ...anim.properties, ...resolvedFromValues } : { ...anim.properties };
|
|
437
446
|
return { fromProps: { ...anim.fromProperties ?? {} }, toProps };
|
|
438
447
|
}
|
|
448
|
+
function assertMotionPathNumbers(config) {
|
|
449
|
+
const points = [
|
|
450
|
+
...config.waypoints,
|
|
451
|
+
...config.segments.flatMap((s) => [s.cp1, s.cp2].filter((p) => p !== void 0))
|
|
452
|
+
];
|
|
453
|
+
const values = [
|
|
454
|
+
...points.flatMap((p) => [p.x, p.y]),
|
|
455
|
+
...config.segments.map((s) => s.curviness ?? 1)
|
|
456
|
+
];
|
|
457
|
+
if (values.some((v) => typeof v !== "number")) {
|
|
458
|
+
throw new TypeError("Motion path coordinates and curviness must be numbers");
|
|
459
|
+
}
|
|
460
|
+
}
|
|
439
461
|
|
|
440
462
|
// src/clipTweens.ts
|
|
441
463
|
function clipTweenMatcher(clipSelectors, root, queries = /* @__PURE__ */ new Map()) {
|
|
@@ -1524,7 +1546,7 @@ function insertAfterAnchor(parsed, newStatement) {
|
|
|
1524
1546
|
}
|
|
1525
1547
|
}
|
|
1526
1548
|
function buildTweenStatementCode(timelineVar, anim) {
|
|
1527
|
-
const selector =
|
|
1549
|
+
const selector = scriptJson(anim.targetSelector);
|
|
1528
1550
|
const props = { ...anim.properties };
|
|
1529
1551
|
if (anim.method !== "set" && anim.duration !== void 0) props.duration = anim.duration;
|
|
1530
1552
|
if (anim.ease) props.ease = anim.ease;
|
|
@@ -1555,7 +1577,7 @@ function buildTweenStatementCode(timelineVar, anim) {
|
|
|
1555
1577
|
if (anim.method === "set" && anim.global) {
|
|
1556
1578
|
return `gsap.set(${selector}, ${objCode});`;
|
|
1557
1579
|
}
|
|
1558
|
-
return `${timelineVar}.${anim.method}(${selector}, ${objCode}, ${posCode});`;
|
|
1580
|
+
return `${timelineVar}.${tweenMethodCode(anim.method)}(${selector}, ${objCode}, ${posCode});`;
|
|
1559
1581
|
}
|
|
1560
1582
|
function updateAnimationInScript(script, animationId, updates) {
|
|
1561
1583
|
let parsed;
|
|
@@ -1671,10 +1693,10 @@ function addAnimationWithKeyframesToScript(script, targetSelector, position, dur
|
|
|
1671
1693
|
if (parsed.located.length === 0 && parsed.detection.ref === null) {
|
|
1672
1694
|
return { script, id: "" };
|
|
1673
1695
|
}
|
|
1674
|
-
const selector =
|
|
1696
|
+
const selector = scriptJson(targetSelector);
|
|
1675
1697
|
const kfCode = buildKeyframeObjectCode(keyframes, easeEach ? { easeEach } : void 0);
|
|
1676
1698
|
const varEntries = [`keyframes: ${kfCode}`, `duration: ${serializeValue(duration)}`];
|
|
1677
|
-
if (ease) varEntries.push(`ease: ${
|
|
1699
|
+
if (ease) varEntries.push(`ease: ${scriptJson(ease)}`);
|
|
1678
1700
|
const posCode = serializeValue(position);
|
|
1679
1701
|
const stmtCode = `${parsed.timelineVar}.to(${selector}, { ${varEntries.join(", ")} }, ${posCode});`;
|
|
1680
1702
|
const newStatement = parseScript(stmtCode).program.body[0];
|
|
@@ -1770,8 +1792,8 @@ function insertInheritedStateSet(script, selector, position, properties) {
|
|
|
1770
1792
|
return script;
|
|
1771
1793
|
}
|
|
1772
1794
|
const tlVar = parsed.timelineVar;
|
|
1773
|
-
const props = Object.entries(properties).map(([k, v]) => `${k}: ${typeof v === "string" ?
|
|
1774
|
-
const code = `${tlVar}.set(${
|
|
1795
|
+
const props = Object.entries(properties).map(([k, v]) => `${safeJsKey(k)}: ${typeof v === "string" ? scriptJson(v) : v}`).join(", ");
|
|
1796
|
+
const code = `${tlVar}.set(${scriptJson(selector)}, { ${props} }, ${position});`;
|
|
1775
1797
|
const newStatement = parseScript(code).program.body[0];
|
|
1776
1798
|
const anchor = findTimelineDeclarationPath(parsed.ast, tlVar);
|
|
1777
1799
|
if (anchor) {
|
|
@@ -1934,11 +1956,11 @@ function keyframePropsToCode(kf) {
|
|
|
1934
1956
|
function buildKeyframeObjectCode(keyframes, options) {
|
|
1935
1957
|
const entries = mergePercentageKeyframes(keyframes).map((kf) => {
|
|
1936
1958
|
const props = keyframePropsToCode(kf);
|
|
1937
|
-
if (kf.ease) props.push(`ease: ${
|
|
1959
|
+
if (kf.ease) props.push(`ease: ${scriptJson(kf.ease)}`);
|
|
1938
1960
|
if (kf.auto) props.push(`_auto: 1`);
|
|
1939
|
-
return `${
|
|
1961
|
+
return `${scriptJson(plainPercentKey(kf.percentage))}: { ${props.join(", ")} }`;
|
|
1940
1962
|
});
|
|
1941
|
-
if (options?.easeEach) entries.push(`easeEach: ${
|
|
1963
|
+
if (options?.easeEach) entries.push(`easeEach: ${scriptJson(options.easeEach)}`);
|
|
1942
1964
|
return `{ ${entries.join(", ")} }`;
|
|
1943
1965
|
}
|
|
1944
1966
|
function removeVarsKey(varsArg, key) {
|
|
@@ -1968,7 +1990,7 @@ function findKeyframePropByPct(kfNode, percentage) {
|
|
|
1968
1990
|
function buildKeyframeValueNode(properties, ease) {
|
|
1969
1991
|
const effectiveEase = ease ?? (typeof properties.ease === "string" ? properties.ease : void 0);
|
|
1970
1992
|
const entries = Object.entries(properties).filter(([k]) => k !== "ease").map(([k, v]) => `${safeJsKey(k)}: ${serializeValue(v)}`);
|
|
1971
|
-
if (effectiveEase) entries.push(`ease: ${
|
|
1993
|
+
if (effectiveEase) entries.push(`ease: ${scriptJson(effectiveEase)}`);
|
|
1972
1994
|
return parseExpr(`{ ${entries.join(", ")} }`);
|
|
1973
1995
|
}
|
|
1974
1996
|
function setObjectExpressionEase(node, ease) {
|
|
@@ -1977,7 +1999,7 @@ function setObjectExpressionEase(node, ease) {
|
|
|
1977
1999
|
const easeIdx = props.findIndex(
|
|
1978
2000
|
(property) => isObjectProperty(property) && propKeyName(property) === "ease"
|
|
1979
2001
|
);
|
|
1980
|
-
const easeNode = parseExpr(`({ ease: ${
|
|
2002
|
+
const easeNode = parseExpr(`({ ease: ${scriptJson(ease)} })`).properties[0];
|
|
1981
2003
|
if (easeIdx >= 0) props[easeIdx] = easeNode;
|
|
1982
2004
|
else props.push(easeNode);
|
|
1983
2005
|
return true;
|
|
@@ -2052,7 +2074,7 @@ function convertArrayKeyframesToObjectNode(varsArg, scope) {
|
|
|
2052
2074
|
el.properties = (el.properties ?? []).filter(
|
|
2053
2075
|
(property) => !isObjectProperty(property) || propKeyName(property) !== "duration"
|
|
2054
2076
|
);
|
|
2055
|
-
return `${
|
|
2077
|
+
return `${scriptJson(plainPercentKey(timing.percentages[i]))}: ${recast.print(el).code}`;
|
|
2056
2078
|
});
|
|
2057
2079
|
prop.value = parseExpr(`{ ${entries.join(", ")}, easeEach: "none" }`);
|
|
2058
2080
|
return prop.value;
|
|
@@ -2109,7 +2131,7 @@ function addKeyframeToScript(script, animationId, percentage, properties, ease,
|
|
|
2109
2131
|
existing.prop.value = newValueNode;
|
|
2110
2132
|
}
|
|
2111
2133
|
} else {
|
|
2112
|
-
const newProp = parseExpr(`{ ${
|
|
2134
|
+
const newProp = parseExpr(`{ ${scriptJson(pctKey)}: {} }`).properties[0];
|
|
2113
2135
|
newProp.value = newValueNode;
|
|
2114
2136
|
let insertIdx = kfNode.properties.length;
|
|
2115
2137
|
for (let i = 0; i < kfNode.properties.length; i++) {
|
|
@@ -2225,7 +2247,7 @@ function moveKeyframeInScript(script, animationId, fromPercentage, toPercentage)
|
|
|
2225
2247
|
const kept = (kfNode.properties ?? []).filter((p) => !pctProps.has(p));
|
|
2226
2248
|
kfNode.properties = [
|
|
2227
2249
|
...entries.map((e) => {
|
|
2228
|
-
const p = parseExpr(`{ ${
|
|
2250
|
+
const p = parseExpr(`{ ${scriptJson(plainPercentKey(e.pct))}: {} }`).properties[0];
|
|
2229
2251
|
p.value = e.value;
|
|
2230
2252
|
return p;
|
|
2231
2253
|
}),
|
|
@@ -2243,7 +2265,7 @@ function resizeKeyframedTweenInScript(script, animationId, newPosition, newDurat
|
|
|
2243
2265
|
const match = findKeyframePropByPct(kfNode, from);
|
|
2244
2266
|
if (!match || seen.has(match.prop)) continue;
|
|
2245
2267
|
seen.add(match.prop);
|
|
2246
|
-
match.prop.key = parseExpr(`{ ${
|
|
2268
|
+
match.prop.key = parseExpr(`{ ${scriptJson(plainPercentKey(to))}: 0 }`).properties[0].key;
|
|
2247
2269
|
}
|
|
2248
2270
|
applyUpdatesToCall(loc.target.call, {
|
|
2249
2271
|
position: newPosition,
|
|
@@ -2331,7 +2353,7 @@ function updateKeyframeInScript(script, animationId, percentage, properties, eas
|
|
|
2331
2353
|
else props.push(node);
|
|
2332
2354
|
};
|
|
2333
2355
|
for (const [k, v] of Object.entries(properties)) upsert(k, serializeValue(v));
|
|
2334
|
-
if (ease !== void 0) upsert("ease",
|
|
2356
|
+
if (ease !== void 0) upsert("ease", scriptJson(ease));
|
|
2335
2357
|
return recast.print(loc.parsed.ast).code;
|
|
2336
2358
|
}
|
|
2337
2359
|
match.prop.value = buildKeyframeValueNode(properties, ease);
|
|
@@ -2349,7 +2371,7 @@ function stripEditableAndEase(varsArg) {
|
|
|
2349
2371
|
function insertKeyframesProp(varsArg, fromProps, toProps, easeEach) {
|
|
2350
2372
|
const fromEntries = Object.entries(fromProps).map(([k, v]) => `${safeJsKey(k)}: ${serializeValue(v)}`);
|
|
2351
2373
|
const toEntries = Object.entries(toProps).map(([k, v]) => `${safeJsKey(k)}: ${serializeValue(v)}`);
|
|
2352
|
-
const easeEntry = easeEach ? `, easeEach: ${
|
|
2374
|
+
const easeEntry = easeEach ? `, easeEach: ${scriptJson(easeEach)}` : "";
|
|
2353
2375
|
const kfCode = `{ "0%": { ${fromEntries.join(", ")} }, "100%": { ${toEntries.join(", ")} }${easeEntry} }`;
|
|
2354
2376
|
const kfProp = parseExpr(`{ keyframes: {} }`).properties[0];
|
|
2355
2377
|
kfProp.value = parseExpr(kfCode);
|
|
@@ -2423,7 +2445,7 @@ function materializeKeyframesInScript(script, animationId, keyframes, easeEach,
|
|
|
2423
2445
|
if (!loc) return script;
|
|
2424
2446
|
const varsArg = loc.target.call.varsArg;
|
|
2425
2447
|
if (resolvedSelector && loc.target.call.node.arguments[0]) {
|
|
2426
|
-
loc.target.call.node.arguments[0] = parseExpr(
|
|
2448
|
+
loc.target.call.node.arguments[0] = parseExpr(scriptJson(resolvedSelector));
|
|
2427
2449
|
}
|
|
2428
2450
|
const kfObjCode = buildKeyframeObjectCode(sortedKeyframes(keyframes), { easeEach });
|
|
2429
2451
|
const kfParent = varsArg.properties.find(
|
|
@@ -2456,6 +2478,7 @@ function extractArcWaypoints(anim) {
|
|
|
2456
2478
|
];
|
|
2457
2479
|
}
|
|
2458
2480
|
function buildMotionPathObjectCode(config) {
|
|
2481
|
+
assertMotionPathNumbers(config);
|
|
2459
2482
|
const { waypoints, segments, autoRotate } = config;
|
|
2460
2483
|
const hasExplicitControlPoints = segments.some((s) => s.cp1 && s.cp2);
|
|
2461
2484
|
const curvinessVaries = segments.some(
|
|
@@ -2669,11 +2692,11 @@ function addMotionPathToScript(script, targetSelector, position, duration, point
|
|
|
2669
2692
|
segments: [{ curviness: 1 }],
|
|
2670
2693
|
autoRotate: false
|
|
2671
2694
|
});
|
|
2672
|
-
const selector =
|
|
2695
|
+
const selector = scriptJson(targetSelector);
|
|
2673
2696
|
const varEntries = [
|
|
2674
2697
|
`motionPath: ${motionPathCode}`,
|
|
2675
2698
|
`duration: ${serializeValue(duration)}`,
|
|
2676
|
-
`ease: ${
|
|
2699
|
+
`ease: ${scriptJson(ease)}`
|
|
2677
2700
|
];
|
|
2678
2701
|
const stmtCode = `${parsed.timelineVar}.to(${selector}, { ${varEntries.join(", ")} }, ${serializeValue(position)});`;
|
|
2679
2702
|
const newStatement = parseScript(stmtCode).program.body[0];
|
|
@@ -2797,7 +2820,7 @@ function unrollDynamicAnimations(script, animationId, elements) {
|
|
|
2797
2820
|
const ease = typeof easeVal === "string" ? easeVal : "none";
|
|
2798
2821
|
const posArg = loc.target.call.positionArg;
|
|
2799
2822
|
const position = posArg ? extractLiteralValue(posArg, loc.parsed.scope) : 0;
|
|
2800
|
-
const posCode = typeof position === "number" ? String(position) : typeof position === "string" ?
|
|
2823
|
+
const posCode = typeof position === "number" ? String(position) : typeof position === "string" ? scriptJson(position) : "0";
|
|
2801
2824
|
let loopNode = null;
|
|
2802
2825
|
let current = loc.target.call.path;
|
|
2803
2826
|
while (current) {
|
|
@@ -2818,7 +2841,7 @@ function unrollDynamicAnimations(script, animationId, elements) {
|
|
|
2818
2841
|
easeEach: el.easeEach
|
|
2819
2842
|
});
|
|
2820
2843
|
calls.push(
|
|
2821
|
-
`${loc.parsed.timelineVar}.to(${
|
|
2844
|
+
`${loc.parsed.timelineVar}.to(${scriptJson(el.selector)}, { keyframes: ${kfCode}, duration: ${duration}, ease: ${scriptJson(ease)} }, ${posCode});`
|
|
2822
2845
|
);
|
|
2823
2846
|
}
|
|
2824
2847
|
const replacement = calls.join("\n ");
|
|
@@ -180,7 +180,7 @@ function serializeGsapAnimations(animations, timelineVar = "tl", options) {
|
|
|
180
180
|
return aNum - bNum;
|
|
181
181
|
});
|
|
182
182
|
const lines = sorted.map((anim) => {
|
|
183
|
-
const selector =
|
|
183
|
+
const selector = scriptJson(anim.targetSelector);
|
|
184
184
|
const props = { ...anim.properties };
|
|
185
185
|
if (anim.duration !== void 0) props.duration = anim.duration;
|
|
186
186
|
if (anim.ease) props.ease = anim.ease;
|
|
@@ -193,7 +193,7 @@ function serializeGsapAnimations(animations, timelineVar = "tl", options) {
|
|
|
193
193
|
propsStr = propsStr.slice(0, -2) + `, ${extrasStr} }`;
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
const posStr =
|
|
196
|
+
const posStr = scriptJson(anim.position);
|
|
197
197
|
switch (anim.method) {
|
|
198
198
|
case "set":
|
|
199
199
|
return anim.global ? ` gsap.set(${selector}, ${propsStr});` : ` ${timelineVar}.set(${selector}, ${propsStr}, ${posStr});`;
|
|
@@ -237,15 +237,18 @@ function serializeGsapAnimations(animations, timelineVar = "tl", options) {
|
|
|
237
237
|
${lines.join("\n")}${mediaSync}${postamble}
|
|
238
238
|
`;
|
|
239
239
|
}
|
|
240
|
+
function scriptJson(value) {
|
|
241
|
+
return String(JSON.stringify(value)).replace(/<(\/script|!--)/gi, "\\u003c$1");
|
|
242
|
+
}
|
|
240
243
|
function serializeValue(value) {
|
|
241
244
|
if (typeof value === "string" && value.startsWith("__raw:")) {
|
|
242
245
|
return value.slice(6);
|
|
243
246
|
}
|
|
244
|
-
if (typeof value === "string") return
|
|
247
|
+
if (typeof value === "string") return scriptJson(value);
|
|
245
248
|
return String(value);
|
|
246
249
|
}
|
|
247
250
|
function safeJsKey(key) {
|
|
248
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key :
|
|
251
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : scriptJson(key);
|
|
249
252
|
}
|
|
250
253
|
function serializeObject(obj) {
|
|
251
254
|
const entries = Object.entries(obj).map(([key, value]) => {
|
package/dist/gsapWriterAcorn.js
CHANGED
|
@@ -149,6 +149,15 @@ function buildArcPath(coords, curviness, autoRotate, isCubic) {
|
|
|
149
149
|
}
|
|
150
150
|
return { arcPath: { enabled: true, autoRotate, segments }, waypoints };
|
|
151
151
|
}
|
|
152
|
+
function scriptJson(value) {
|
|
153
|
+
return String(JSON.stringify(value)).replace(/<(\/script|!--)/gi, "\\u003c$1");
|
|
154
|
+
}
|
|
155
|
+
var TWEEN_METHODS = /* @__PURE__ */ new Set(["set", "to", "from", "fromTo"]);
|
|
156
|
+
function tweenMethodCode(method) {
|
|
157
|
+
if (!TWEEN_METHODS.has(method))
|
|
158
|
+
throw new TypeError(`Unsupported tween method: ${scriptJson(method)}`);
|
|
159
|
+
return method;
|
|
160
|
+
}
|
|
152
161
|
function plainPercentKey(percentage) {
|
|
153
162
|
const text = Math.abs(percentage) < 1e-6 ? percentage.toFixed(20).replace(/\.?0+$/, "") : String(percentage);
|
|
154
163
|
return `${text}%`;
|
|
@@ -187,6 +196,19 @@ function resolveConversionProps(anim, resolvedFromValues) {
|
|
|
187
196
|
const toProps = resolvedFromValues ? { ...anim.properties, ...resolvedFromValues } : { ...anim.properties };
|
|
188
197
|
return { fromProps: { ...anim.fromProperties ?? {} }, toProps };
|
|
189
198
|
}
|
|
199
|
+
function assertMotionPathNumbers(config) {
|
|
200
|
+
const points = [
|
|
201
|
+
...config.waypoints,
|
|
202
|
+
...config.segments.flatMap((s) => [s.cp1, s.cp2].filter((p) => p !== void 0))
|
|
203
|
+
];
|
|
204
|
+
const values = [
|
|
205
|
+
...points.flatMap((p) => [p.x, p.y]),
|
|
206
|
+
...config.segments.map((s) => s.curviness ?? 1)
|
|
207
|
+
];
|
|
208
|
+
if (values.some((v) => typeof v !== "number")) {
|
|
209
|
+
throw new TypeError("Motion path coordinates and curviness must be numbers");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
190
212
|
function numericXY(props) {
|
|
191
213
|
const vx = props.x;
|
|
192
214
|
const vy = props.y;
|
|
@@ -237,6 +259,7 @@ function buildCubicPathEntries(waypoints, segments) {
|
|
|
237
259
|
return entries;
|
|
238
260
|
}
|
|
239
261
|
function buildMotionPathObjectCode(config) {
|
|
262
|
+
assertMotionPathNumbers(config);
|
|
240
263
|
const { waypoints, segments, autoRotate } = config;
|
|
241
264
|
const arSuffix = autoRotateSuffix(autoRotate);
|
|
242
265
|
const hasExplicitCp = segments.some((s) => s.cp1 && s.cp2);
|
|
@@ -1494,16 +1517,16 @@ function queryRoot(root, selector) {
|
|
|
1494
1517
|
// src/gsapWriterAcorn.ts
|
|
1495
1518
|
function valueToCode(value) {
|
|
1496
1519
|
if (typeof value === "string" && value.startsWith("__raw:")) return value.slice(6);
|
|
1497
|
-
if (typeof value === "string") return
|
|
1520
|
+
if (typeof value === "string") return scriptJson(value);
|
|
1498
1521
|
if (typeof value === "number") return Number.isNaN(value) ? "0" : String(value);
|
|
1499
1522
|
if (typeof value === "boolean") return String(value);
|
|
1500
|
-
return
|
|
1523
|
+
return scriptJson(value);
|
|
1501
1524
|
}
|
|
1502
1525
|
function safeKey(key) {
|
|
1503
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key :
|
|
1526
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : scriptJson(key);
|
|
1504
1527
|
}
|
|
1505
1528
|
function buildTweenStatementCode(timelineVar, anim) {
|
|
1506
|
-
const selector =
|
|
1529
|
+
const selector = scriptJson(anim.targetSelector);
|
|
1507
1530
|
const props = { ...anim.properties };
|
|
1508
1531
|
if (anim.method !== "set" && anim.duration !== void 0) props.duration = anim.duration;
|
|
1509
1532
|
if (anim.ease) props.ease = anim.ease;
|
|
@@ -1529,7 +1552,7 @@ function buildTweenStatementCode(timelineVar, anim) {
|
|
|
1529
1552
|
if (anim.method === "set" && anim.global) {
|
|
1530
1553
|
return `gsap.set(${selector}, ${objCode});`;
|
|
1531
1554
|
}
|
|
1532
|
-
return `${timelineVar}.${anim.method}(${selector}, ${objCode}, ${posCode});`;
|
|
1555
|
+
return `${timelineVar}.${tweenMethodCode(anim.method)}(${selector}, ${objCode}, ${posCode});`;
|
|
1533
1556
|
}
|
|
1534
1557
|
function isObjectProperty2(prop) {
|
|
1535
1558
|
return prop?.type === "ObjectProperty" || prop?.type === "Property";
|
|
@@ -1776,7 +1799,7 @@ function copyAnimationsInScript(script, fromSelector, toSelector, delta) {
|
|
|
1776
1799
|
const parsed = parseGsapScriptAcornForWrite(script);
|
|
1777
1800
|
if (!parsed) return script;
|
|
1778
1801
|
const block = timelineBlock(parsed);
|
|
1779
|
-
const target =
|
|
1802
|
+
const target = scriptJson(toSelector);
|
|
1780
1803
|
const ms = new MagicString(script);
|
|
1781
1804
|
const tweens = [];
|
|
1782
1805
|
for (const { animation, call } of parsed.located) {
|
|
@@ -2259,7 +2282,7 @@ function convertArrayKeyframesToObject(script, target) {
|
|
|
2259
2282
|
if (!timing) return script;
|
|
2260
2283
|
const entries = els.map((el, i) => {
|
|
2261
2284
|
const { duration: _duration, ...record } = records[i];
|
|
2262
|
-
return `${
|
|
2285
|
+
return `${scriptJson(plainPercentKey(timing.percentages[i]))}: ${recordToCode(record)}`;
|
|
2263
2286
|
});
|
|
2264
2287
|
const ms = new MagicString(script);
|
|
2265
2288
|
ms.overwrite(
|
|
@@ -2345,10 +2368,10 @@ function insertNewKeyframe(ms, kfNode, percentage, pctKey, valueCode) {
|
|
|
2345
2368
|
}
|
|
2346
2369
|
}
|
|
2347
2370
|
if (insertBeforeProp) {
|
|
2348
|
-
ms.appendLeft(insertBeforeProp.start, `${
|
|
2371
|
+
ms.appendLeft(insertBeforeProp.start, `${scriptJson(pctKey)}: ${valueCode}, `);
|
|
2349
2372
|
} else {
|
|
2350
2373
|
const sep = allProps.length > 0 ? ", " : "";
|
|
2351
|
-
ms.appendLeft(kfNode.end - 1, `${sep}${
|
|
2374
|
+
ms.appendLeft(kfNode.end - 1, `${sep}${scriptJson(pctKey)}: ${valueCode}`);
|
|
2352
2375
|
}
|
|
2353
2376
|
}
|
|
2354
2377
|
function collapseKeyframesToFlat(ms, varsNode, source, remainingRecord) {
|
|
@@ -2429,7 +2452,7 @@ function moveKeyframeInScript(script, animationId, fromPercentage, toPercentage)
|
|
|
2429
2452
|
const pctProps = new Set(percentagePropsOf(kfNode));
|
|
2430
2453
|
const kept = (kfNode.properties ?? []).filter((p) => !pctProps.has(p)).map((p) => src.slice(p.start, p.end));
|
|
2431
2454
|
const body = [
|
|
2432
|
-
...entries.map((e) => `${
|
|
2455
|
+
...entries.map((e) => `${scriptJson(plainPercentKey(e.pct))}: ${recordToCode(e.record)}`),
|
|
2433
2456
|
...kept
|
|
2434
2457
|
].join(", ");
|
|
2435
2458
|
const ms = new MagicString(src);
|
|
@@ -2450,7 +2473,7 @@ function resizeKeyframedTweenInScript(script, animationId, newPosition, newDurat
|
|
|
2450
2473
|
}
|
|
2451
2474
|
const ms = new MagicString(src);
|
|
2452
2475
|
for (const { keyNode, to } of edits) {
|
|
2453
|
-
ms.overwrite(keyNode.start, keyNode.end,
|
|
2476
|
+
ms.overwrite(keyNode.start, keyNode.end, scriptJson(plainPercentKey(to)));
|
|
2454
2477
|
}
|
|
2455
2478
|
overwritePosition(ms, target.call, newPosition);
|
|
2456
2479
|
upsertProp(ms, target.call.varsArg, "duration", newDuration);
|
|
@@ -2568,7 +2591,7 @@ function buildKeyframeObjectCode(keyframes, easeEach) {
|
|
|
2568
2591
|
const props = Object.entries(kf.properties).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`);
|
|
2569
2592
|
if (kf.ease) props.push(`ease: ${valueToCode(kf.ease)}`);
|
|
2570
2593
|
if (kf.auto) props.push(`_auto: 1`);
|
|
2571
|
-
return `${
|
|
2594
|
+
return `${scriptJson(plainPercentKey(kf.percentage))}: { ${props.join(", ")} }`;
|
|
2572
2595
|
});
|
|
2573
2596
|
if (easeEach) entries.push(`easeEach: ${valueToCode(easeEach)}`);
|
|
2574
2597
|
return `{ ${entries.join(", ")} }`;
|
|
@@ -2585,8 +2608,7 @@ function materializeKeyframesFromScript(script, animationId, keyframes, easeEach
|
|
|
2585
2608
|
const ms = new MagicString(script);
|
|
2586
2609
|
if (resolvedSelector) {
|
|
2587
2610
|
const selectorArg = call.node.arguments[0];
|
|
2588
|
-
if (selectorArg)
|
|
2589
|
-
ms.overwrite(selectorArg.start, selectorArg.end, JSON.stringify(resolvedSelector));
|
|
2611
|
+
if (selectorArg) ms.overwrite(selectorArg.start, selectorArg.end, scriptJson(resolvedSelector));
|
|
2590
2612
|
}
|
|
2591
2613
|
const kfProp = findPropertyNode2(call.varsArg, "keyframes");
|
|
2592
2614
|
if (kfProp) {
|
|
@@ -2626,7 +2648,7 @@ function replaceTweenWithKeyframesInScript(script, animationId, edit) {
|
|
|
2626
2648
|
if (edit.ease) parts.push(`ease: ${valueToCode(edit.ease)}`);
|
|
2627
2649
|
if (animation.hasUnresolvedSelector || animation.targetSelector !== edit.targetSelector) {
|
|
2628
2650
|
const selectorArg = call.node.arguments[0];
|
|
2629
|
-
ms.overwrite(selectorArg.start, selectorArg.end,
|
|
2651
|
+
ms.overwrite(selectorArg.start, selectorArg.end, scriptJson(edit.targetSelector));
|
|
2630
2652
|
}
|
|
2631
2653
|
convertMethodToTo(ms, animation, call, call.varsArg);
|
|
2632
2654
|
overwriteVarsArg(ms, call, `{ ${parts.join(", ")} }`);
|
|
@@ -2642,7 +2664,7 @@ function addAnimationWithKeyframesToScript(script, targetSelector, position, dur
|
|
|
2642
2664
|
const kfObjCode = buildKeyframeObjectCode(sorted, easeEach);
|
|
2643
2665
|
const varParts = [`keyframes: ${kfObjCode}`, `duration: ${valueToCode(duration)}`];
|
|
2644
2666
|
if (ease) varParts.push(`ease: ${valueToCode(ease)}`);
|
|
2645
|
-
const stmtCode = `${parsed.timelineVar}.to(${
|
|
2667
|
+
const stmtCode = `${parsed.timelineVar}.to(${scriptJson(targetSelector)}, { ${varParts.join(", ")} }, ${valueToCode(position)});`;
|
|
2646
2668
|
const ms = new MagicString(script);
|
|
2647
2669
|
ms.appendLeft(insertionPoint, "\n" + stmtCode);
|
|
2648
2670
|
const result = ms.toString();
|
|
@@ -2790,7 +2812,7 @@ function addLabelToScript(script, name, position) {
|
|
|
2790
2812
|
const insertionPoint = findInsertionPoint(parsed);
|
|
2791
2813
|
if (insertionPoint === null) return script;
|
|
2792
2814
|
const ms = new MagicString(script);
|
|
2793
|
-
const labelCode = `${parsed.timelineVar}.addLabel(${
|
|
2815
|
+
const labelCode = `${parsed.timelineVar}.addLabel(${scriptJson(name)}, ${valueToCode(position)});`;
|
|
2794
2816
|
ms.appendLeft(insertionPoint, "\n" + labelCode);
|
|
2795
2817
|
return ms.toString();
|
|
2796
2818
|
}
|
|
@@ -3007,14 +3029,14 @@ function updateAnimationSelectorInScript(script, animationId, newSelector) {
|
|
|
3007
3029
|
const selectorArg = target.call.node.arguments?.[0];
|
|
3008
3030
|
if (!selectorArg) return script;
|
|
3009
3031
|
const ms = new MagicString(script);
|
|
3010
|
-
ms.overwrite(selectorArg.start, selectorArg.end,
|
|
3032
|
+
ms.overwrite(selectorArg.start, selectorArg.end, scriptJson(newSelector));
|
|
3011
3033
|
return ms.toString();
|
|
3012
3034
|
}
|
|
3013
3035
|
function insertInheritedStateSetInScript(script, selector, position, properties) {
|
|
3014
3036
|
const parsed = parseGsapScriptAcornForWrite(script);
|
|
3015
3037
|
if (!parsed) return script;
|
|
3016
3038
|
const props = Object.entries(properties).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`).join(", ");
|
|
3017
|
-
const code = `${parsed.timelineVar}.set(${
|
|
3039
|
+
const code = `${parsed.timelineVar}.set(${scriptJson(selector)}, { ${props} }, ${position});`;
|
|
3018
3040
|
const ms = new MagicString(script);
|
|
3019
3041
|
const tlDecl = findTimelineDeclarationStatement(parsed.ast, parsed.timelineVar);
|
|
3020
3042
|
const firstLocated = parsed.located[0];
|
|
@@ -3309,11 +3331,11 @@ function buildUnrollReplacement(timelineVar, animation, elements) {
|
|
|
3309
3331
|
const duration = typeof animation.duration === "number" ? animation.duration : 8;
|
|
3310
3332
|
const ease = typeof animation.ease === "string" ? animation.ease : "none";
|
|
3311
3333
|
const pos = animation.position ?? 0;
|
|
3312
|
-
const posCode = typeof pos === "number" ? String(pos) :
|
|
3334
|
+
const posCode = typeof pos === "number" ? String(pos) : scriptJson(pos);
|
|
3313
3335
|
const calls = elements.map((el) => {
|
|
3314
3336
|
const sorted = [...el.keyframes].sort((a, b) => a.percentage - b.percentage);
|
|
3315
3337
|
const kfCode = buildKeyframeObjectCode(sorted, el.easeEach);
|
|
3316
|
-
return `${timelineVar}.to(${
|
|
3338
|
+
return `${timelineVar}.to(${scriptJson(el.selector)}, { keyframes: ${kfCode}, duration: ${duration}, ease: ${valueToCode(ease)} }, ${posCode});`;
|
|
3317
3339
|
});
|
|
3318
3340
|
return calls.join("\n ");
|
|
3319
3341
|
}
|
|
@@ -3321,10 +3343,10 @@ function buildUnrollCallForElement(timelineVar, animation, el) {
|
|
|
3321
3343
|
const duration = typeof animation.duration === "number" ? animation.duration : 8;
|
|
3322
3344
|
const ease = typeof animation.ease === "string" ? animation.ease : "none";
|
|
3323
3345
|
const pos = animation.position ?? 0;
|
|
3324
|
-
const posCode = typeof pos === "number" ? String(pos) :
|
|
3346
|
+
const posCode = typeof pos === "number" ? String(pos) : scriptJson(pos);
|
|
3325
3347
|
const sorted = [...el.keyframes].sort((a, b) => a.percentage - b.percentage);
|
|
3326
3348
|
const kfCode = buildKeyframeObjectCode(sorted, el.easeEach);
|
|
3327
|
-
return `${timelineVar}.to(${
|
|
3349
|
+
return `${timelineVar}.to(${scriptJson(el.selector)}, { keyframes: ${kfCode}, duration: ${duration}, ease: ${valueToCode(ease)} }, ${posCode});`;
|
|
3328
3350
|
}
|
|
3329
3351
|
var REFUSE_UNROLL = /* @__PURE__ */ Symbol("refuse-unroll");
|
|
3330
3352
|
function loopBodyRawStatements(loopNode) {
|
package/dist/index.js
CHANGED
|
@@ -293,7 +293,7 @@ function serializeGsapAnimations(animations, timelineVar = "tl", options) {
|
|
|
293
293
|
return aNum - bNum;
|
|
294
294
|
});
|
|
295
295
|
const lines = sorted.map((anim) => {
|
|
296
|
-
const selector =
|
|
296
|
+
const selector = scriptJson(anim.targetSelector);
|
|
297
297
|
const props = { ...anim.properties };
|
|
298
298
|
if (anim.duration !== void 0) props.duration = anim.duration;
|
|
299
299
|
if (anim.ease) props.ease = anim.ease;
|
|
@@ -306,7 +306,7 @@ function serializeGsapAnimations(animations, timelineVar = "tl", options) {
|
|
|
306
306
|
propsStr = propsStr.slice(0, -2) + `, ${extrasStr} }`;
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
|
-
const posStr =
|
|
309
|
+
const posStr = scriptJson(anim.position);
|
|
310
310
|
switch (anim.method) {
|
|
311
311
|
case "set":
|
|
312
312
|
return anim.global ? ` gsap.set(${selector}, ${propsStr});` : ` ${timelineVar}.set(${selector}, ${propsStr}, ${posStr});`;
|
|
@@ -350,11 +350,14 @@ function serializeGsapAnimations(animations, timelineVar = "tl", options) {
|
|
|
350
350
|
${lines.join("\n")}${mediaSync}${postamble}
|
|
351
351
|
`;
|
|
352
352
|
}
|
|
353
|
+
function scriptJson(value) {
|
|
354
|
+
return String(JSON.stringify(value)).replace(/<(\/script|!--)/gi, "\\u003c$1");
|
|
355
|
+
}
|
|
353
356
|
function serializeValue(value) {
|
|
354
357
|
if (typeof value === "string" && value.startsWith("__raw:")) {
|
|
355
358
|
return value.slice(6);
|
|
356
359
|
}
|
|
357
|
-
if (typeof value === "string") return
|
|
360
|
+
if (typeof value === "string") return scriptJson(value);
|
|
358
361
|
return String(value);
|
|
359
362
|
}
|
|
360
363
|
function plainPercentKey(percentage) {
|
|
@@ -362,7 +365,7 @@ function plainPercentKey(percentage) {
|
|
|
362
365
|
return `${text}%`;
|
|
363
366
|
}
|
|
364
367
|
function safeJsKey(key) {
|
|
365
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key :
|
|
368
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : scriptJson(key);
|
|
366
369
|
}
|
|
367
370
|
function serializeObject(obj) {
|
|
368
371
|
const entries = Object.entries(obj).map(([key, value]) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/parsers",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.32",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/heygen-com/hyperframes",
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
"tsx": "^4.21.0",
|
|
140
140
|
"typescript": "^5.0.0",
|
|
141
141
|
"vitest": "^4.1.11",
|
|
142
|
-
"@hyperframes/core": "0.9.
|
|
142
|
+
"@hyperframes/core": "0.9.32"
|
|
143
143
|
},
|
|
144
144
|
"scripts": {
|
|
145
145
|
"build": "tsup",
|