@pixodesk/svg-animator-web 1.0.24 → 1.0.27
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.cjs +1062 -665
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +1062 -665
- package/dist/index.js.map +1 -1
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.prerendered-waapi.umd.js +74 -40
- package/dist/index.prerendered-waapi.umd.js.map +1 -1
- package/dist/index.prerendered-waapi.umd.min.js +1 -1
- package/dist/index.prerendered.umd.js +292 -41
- package/dist/index.prerendered.umd.js.map +1 -1
- package/dist/index.prerendered.umd.min.js +1 -1
- package/dist/index.umd.js +1070 -669
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -63,114 +63,582 @@ var __objRest2 = (source, exclude) => {
|
|
|
63
63
|
}
|
|
64
64
|
return target;
|
|
65
65
|
};
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
function bezierToSvgPath(path, forceCurves = false) {
|
|
67
|
+
var _a, _b, _c, _d;
|
|
68
|
+
const v = path.v;
|
|
69
|
+
const i = path.i;
|
|
70
|
+
const o = path.o;
|
|
71
|
+
const c = path.c;
|
|
72
|
+
if (!v.length) return "";
|
|
73
|
+
const d = [];
|
|
74
|
+
const len = v.length;
|
|
75
|
+
d.push("M" + v[0][0] + "," + v[0][1]);
|
|
76
|
+
for (let idx = 1; idx < len; idx++) {
|
|
77
|
+
const prevV = v[idx - 1];
|
|
78
|
+
const prevO = (_a = o == null ? void 0 : o[idx - 1]) != null ? _a : prevV;
|
|
79
|
+
const currI = (_b = i == null ? void 0 : i[idx]) != null ? _b : v[idx];
|
|
80
|
+
const currV = v[idx];
|
|
81
|
+
const isLine = !forceCurves && (prevO[0] === prevV[0] && prevO[1] === prevV[1]) && (currI[0] === currV[0] && currI[1] === currV[1]);
|
|
82
|
+
if (isLine) {
|
|
83
|
+
d.push("L" + currV[0] + "," + currV[1]);
|
|
84
|
+
} else {
|
|
85
|
+
d.push("C" + prevO[0] + "," + prevO[1] + "," + currI[0] + "," + currI[1] + "," + currV[0] + "," + currV[1]);
|
|
86
|
+
}
|
|
78
87
|
}
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
if (c && len > 0) {
|
|
89
|
+
const lastV = v[len - 1];
|
|
90
|
+
const lastO = (_c = o == null ? void 0 : o[len - 1]) != null ? _c : lastV;
|
|
91
|
+
const firstI = (_d = i == null ? void 0 : i[0]) != null ? _d : v[0];
|
|
92
|
+
const firstV = v[0];
|
|
93
|
+
const isLine = !forceCurves && (lastO[0] === lastV[0] && lastO[1] === lastV[1]) && (firstI[0] === firstV[0] && firstI[1] === firstV[1]);
|
|
94
|
+
if (!isLine) {
|
|
95
|
+
d.push("C" + lastO[0] + "," + lastO[1] + "," + firstI[0] + "," + firstI[1] + "," + firstV[0] + "," + firstV[1]);
|
|
96
|
+
}
|
|
97
|
+
d.push("z");
|
|
81
98
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
99
|
+
return d.join("");
|
|
100
|
+
}
|
|
101
|
+
function interpolateNum(a, b, t) {
|
|
102
|
+
return a + (b - a) * t;
|
|
103
|
+
}
|
|
104
|
+
function interpolateVec(a, b, t) {
|
|
105
|
+
const res = [];
|
|
106
|
+
const count = Math.max(a.length, b.length);
|
|
107
|
+
for (let i = 0; i < count; i++) {
|
|
108
|
+
res[i] = interpolateNum(a[i] || 0, b[i] || 0, t);
|
|
88
109
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
110
|
+
return res;
|
|
111
|
+
}
|
|
112
|
+
function interpolateColor(a, b, t) {
|
|
113
|
+
return [
|
|
114
|
+
interpolateNum(a[0] || 0, b[0] || 0, t),
|
|
115
|
+
interpolateNum(a[1] || 0, b[1] || 0, t),
|
|
116
|
+
interpolateNum(a[2] || 0, b[2] || 0, t),
|
|
117
|
+
interpolateNum(a[3] === void 0 ? 1 : a[3], b[3] === void 0 ? 1 : b[3], t)
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
function interpolateBeziers(paths1, paths2, progress) {
|
|
121
|
+
const count = Math.max(paths1.length, paths2.length);
|
|
122
|
+
const res = [];
|
|
123
|
+
for (let i = 0; i < count; i++) {
|
|
124
|
+
res.push(interpolateBezier(paths1[i], paths2[i], progress));
|
|
92
125
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
126
|
+
return res;
|
|
127
|
+
}
|
|
128
|
+
function interpolateBezier(path1, path2, progress) {
|
|
129
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
130
|
+
if (!path1 || !path2) return path1 || path2 || { v: [] };
|
|
131
|
+
const t = Math.min(Math.max(progress, 0), 1);
|
|
132
|
+
const len = Math.min(path1.v.length, path2.v.length);
|
|
133
|
+
const v = [];
|
|
134
|
+
const i = [];
|
|
135
|
+
const o = [];
|
|
136
|
+
for (let idx = 0; idx < len; idx++) {
|
|
137
|
+
const v1 = path1.v[idx];
|
|
138
|
+
const v2 = path2.v[idx];
|
|
139
|
+
v.push(interpolateVec(v1, v2, t));
|
|
140
|
+
const i1 = (_b = (_a = path1.i) == null ? void 0 : _a[idx]) != null ? _b : v1;
|
|
141
|
+
const i2 = (_d = (_c = path2.i) == null ? void 0 : _c[idx]) != null ? _d : v2;
|
|
142
|
+
i.push(interpolateVec(i1, i2, t));
|
|
143
|
+
const o1 = (_f = (_e = path1.o) == null ? void 0 : _e[idx]) != null ? _f : v1;
|
|
144
|
+
const o2 = (_h = (_g = path2.o) == null ? void 0 : _g[idx]) != null ? _h : v2;
|
|
145
|
+
o.push(interpolateVec(o1, o2, t));
|
|
96
146
|
}
|
|
97
|
-
|
|
98
|
-
|
|
147
|
+
return { v, i: i.length ? i : void 0, o: o.length ? o : void 0, c: (_i = path1.c) != null ? _i : path2.c };
|
|
148
|
+
}
|
|
149
|
+
function remap(value, inMin, inMax, outMin, outMax) {
|
|
150
|
+
if (inMax === inMin) return outMin;
|
|
151
|
+
const t = (value - inMin) / (inMax - inMin);
|
|
152
|
+
return outMin + t * (outMax - outMin);
|
|
153
|
+
}
|
|
154
|
+
function solveCubicBezierX(p1x, p2x, x) {
|
|
155
|
+
if (x <= 0) return 0;
|
|
156
|
+
if (x >= 1) return 1;
|
|
157
|
+
const cx = 3 * p1x;
|
|
158
|
+
const bx = 3 * (p2x - p1x) - cx;
|
|
159
|
+
const ax = 1 - cx - bx;
|
|
160
|
+
function sampleX(t) {
|
|
161
|
+
return ((ax * t + bx) * t + cx) * t;
|
|
99
162
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
constructor(_default = "") {
|
|
103
|
-
super();
|
|
104
|
-
this._default = _default;
|
|
163
|
+
function sampleDX(t) {
|
|
164
|
+
return (3 * ax * t + 2 * bx) * t + cx;
|
|
105
165
|
}
|
|
106
|
-
|
|
107
|
-
|
|
166
|
+
let t2 = x;
|
|
167
|
+
let t0 = 0;
|
|
168
|
+
let t1 = 1;
|
|
169
|
+
for (let i = 0; i < 8; i++) {
|
|
170
|
+
const x2 = sampleX(t2) - x;
|
|
171
|
+
if (Math.abs(x2) < 1e-6) return t2;
|
|
172
|
+
const d2 = sampleDX(t2);
|
|
173
|
+
if (Math.abs(d2) < 1e-6) break;
|
|
174
|
+
t2 -= x2 / d2;
|
|
108
175
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return
|
|
176
|
+
t2 = x;
|
|
177
|
+
while (t0 < t1) {
|
|
178
|
+
const x2 = sampleX(t2);
|
|
179
|
+
if (Math.abs(x2 - x) < 1e-6) return t2;
|
|
180
|
+
if (x > x2) t0 = t2;
|
|
181
|
+
else t1 = t2;
|
|
182
|
+
t2 = (t1 + t0) / 2;
|
|
113
183
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
184
|
+
return t2;
|
|
185
|
+
}
|
|
186
|
+
function cubicBezier(easing) {
|
|
187
|
+
const [p1x, p1y, p2x, p2y] = easing;
|
|
188
|
+
const cy = 3 * p1y;
|
|
189
|
+
const by = 3 * (p2y - p1y) - cy;
|
|
190
|
+
const ay = 1 - cy - by;
|
|
191
|
+
function sampleCurveY(t) {
|
|
192
|
+
return ((ay * t + by) * t + cy) * t;
|
|
119
193
|
}
|
|
120
|
-
|
|
121
|
-
return
|
|
194
|
+
return function(x) {
|
|
195
|
+
return sampleCurveY(solveCubicBezierX(p1x, p2x, x));
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function lerp2(a, b, t) {
|
|
199
|
+
return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
|
|
200
|
+
}
|
|
201
|
+
function subdivideCubicBezier(p0, p1, p2, p3, t) {
|
|
202
|
+
const q0 = lerp2(p0, p1, t);
|
|
203
|
+
const q1 = lerp2(p1, p2, t);
|
|
204
|
+
const q2 = lerp2(p2, p3, t);
|
|
205
|
+
const r0 = lerp2(q0, q1, t);
|
|
206
|
+
const r1 = lerp2(q1, q2, t);
|
|
207
|
+
const s = lerp2(r0, r1, t);
|
|
208
|
+
return {
|
|
209
|
+
left: [p0, q0, r0, s],
|
|
210
|
+
right: [s, r1, q2, p3]
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function splitEasing(easing, xFraction) {
|
|
214
|
+
if (!easing) return { left: void 0, right: void 0 };
|
|
215
|
+
if (xFraction <= 0) return { left: void 0, right: easing };
|
|
216
|
+
if (xFraction >= 1) return { left: easing, right: void 0 };
|
|
217
|
+
const [x1, y1, x2, y2] = easing;
|
|
218
|
+
const t = solveCubicBezierX(x1, x2, xFraction);
|
|
219
|
+
const p0 = [0, 0];
|
|
220
|
+
const p1 = [x1, y1];
|
|
221
|
+
const p2 = [x2, y2];
|
|
222
|
+
const p3 = [1, 1];
|
|
223
|
+
const { left, right } = subdivideCubicBezier(p0, p1, p2, p3, t);
|
|
224
|
+
const sx = left[3][0];
|
|
225
|
+
const sy = left[3][1];
|
|
226
|
+
let leftEasing;
|
|
227
|
+
if (sx > 1e-9 && Math.abs(sy) > 1e-9) {
|
|
228
|
+
leftEasing = [
|
|
229
|
+
left[1][0] / sx,
|
|
230
|
+
left[1][1] / sy,
|
|
231
|
+
left[2][0] / sx,
|
|
232
|
+
left[2][1] / sy
|
|
233
|
+
];
|
|
122
234
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
235
|
+
let rightEasing;
|
|
236
|
+
const rx = 1 - sx;
|
|
237
|
+
const ry = 1 - sy;
|
|
238
|
+
if (rx > 1e-9 && Math.abs(ry) > 1e-9) {
|
|
239
|
+
rightEasing = [
|
|
240
|
+
(right[1][0] - sx) / rx,
|
|
241
|
+
(right[1][1] - sy) / ry,
|
|
242
|
+
(right[2][0] - sx) / rx,
|
|
243
|
+
(right[2][1] - sy) / ry
|
|
244
|
+
];
|
|
127
245
|
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
246
|
+
return { left: leftEasing, right: rightEasing };
|
|
247
|
+
}
|
|
248
|
+
function reverseEasing(easing) {
|
|
249
|
+
if (!easing) return void 0;
|
|
250
|
+
return [1 - easing[2], 1 - easing[3], 1 - easing[0], 1 - easing[1]];
|
|
251
|
+
}
|
|
252
|
+
function toRGBA(color) {
|
|
253
|
+
const r = Math.round(color[0] * 255);
|
|
254
|
+
const g = Math.round(color[1] * 255);
|
|
255
|
+
const b = Math.round(color[2] * 255);
|
|
256
|
+
return color.length === 4 ? "rgba(" + r + "," + g + "," + b + "," + color[3] + ")" : "rgb(" + r + "," + g + "," + b + ")";
|
|
257
|
+
}
|
|
258
|
+
function parseRgba(s) {
|
|
259
|
+
var _a;
|
|
260
|
+
const inner = (_a = s.match(/rgba?\((.*)\)/)) == null ? void 0 : _a[1];
|
|
261
|
+
if (!inner) throw new Error("Invalid rgb/rgba format");
|
|
262
|
+
const parts = inner.split(",").map((v) => +v.trim());
|
|
263
|
+
return [parts[0] / 255, parts[1] / 255, parts[2] / 255, ...parts[3] !== void 0 ? [parts[3]] : []];
|
|
264
|
+
}
|
|
265
|
+
function parseHex(s) {
|
|
266
|
+
const hex = s.slice(1);
|
|
267
|
+
const isShort = hex.length <= 4;
|
|
268
|
+
const r = isShort ? hex[0] + hex[0] : hex.slice(0, 2);
|
|
269
|
+
const g = isShort ? hex[1] + hex[1] : hex.slice(2, 4);
|
|
270
|
+
const b = isShort ? hex[2] + hex[2] : hex.slice(4, 6);
|
|
271
|
+
const a = hex.length === 4 ? hex[3] + hex[3] : hex.length === 8 ? hex.slice(6, 8) : null;
|
|
272
|
+
const result = [
|
|
273
|
+
parseInt(r, 16) / 255,
|
|
274
|
+
parseInt(g, 16) / 255,
|
|
275
|
+
parseInt(b, 16) / 255
|
|
276
|
+
];
|
|
277
|
+
if (a !== null) {
|
|
278
|
+
result.push(parseInt(a, 16) / 255);
|
|
133
279
|
}
|
|
134
|
-
|
|
135
|
-
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
function parseColor(s) {
|
|
283
|
+
if (!s) return void 0;
|
|
284
|
+
if (Array.isArray(s)) return s;
|
|
285
|
+
if (typeof s !== "string") return void 0;
|
|
286
|
+
if (s.startsWith("#")) {
|
|
287
|
+
return parseHex(s);
|
|
288
|
+
} else if (s.startsWith("rgb")) {
|
|
289
|
+
return parseRgba(s);
|
|
290
|
+
} else {
|
|
291
|
+
console.warn("Unsupported color format: " + s);
|
|
136
292
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
293
|
+
return void 0;
|
|
294
|
+
}
|
|
295
|
+
var COLOUR_ATTR_NAMES = /* @__PURE__ */ new Set(["color", "fill", "flood-color", "lighting-color", "stop-color", "stroke"]);
|
|
296
|
+
var TRANSFORM_FN_NAMES = /* @__PURE__ */ new Set(["translate", "rotate", "scale", "skew"]);
|
|
297
|
+
var PCT_BASED_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
|
|
298
|
+
function composeTransformParts(parts, opts) {
|
|
299
|
+
var _a;
|
|
300
|
+
if (!parts) return "";
|
|
301
|
+
const withUnits = (_a = opts == null ? void 0 : opts.withUnits) != null ? _a : true;
|
|
302
|
+
const segs = [];
|
|
303
|
+
const t = parts.translate;
|
|
304
|
+
const o = parts.origin;
|
|
305
|
+
const r = parts.rotate;
|
|
306
|
+
const k = parts.skew;
|
|
307
|
+
const s = parts.scale;
|
|
308
|
+
const tu = withUnits ? "px" : "";
|
|
309
|
+
const ru = withUnits ? "deg" : "";
|
|
310
|
+
if (t) segs.push("translate(" + t[0] + tu + "," + t[1] + tu + ")");
|
|
311
|
+
if (o) segs.push("translate(" + o[0] + tu + "," + o[1] + tu + ")");
|
|
312
|
+
if (r !== void 0 && r !== null) segs.push("rotate(" + r + ru + ")");
|
|
313
|
+
if (k !== void 0 && k !== null) segs.push("skewX(" + k + ru + ")");
|
|
314
|
+
if (s) segs.push("scale(" + s[0] + "," + s[1] + ")");
|
|
315
|
+
if (o) segs.push("translate(" + -o[0] + tu + "," + -o[1] + tu + ")");
|
|
316
|
+
return segs.join("");
|
|
317
|
+
}
|
|
318
|
+
var STYLE_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
|
|
319
|
+
var DEFAULT_DURATION_MS = 1e3;
|
|
320
|
+
function kebabToCamelCaseWord(kebab) {
|
|
321
|
+
return kebab.includes("-") ? kebab.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) : kebab;
|
|
322
|
+
}
|
|
323
|
+
function isCamelCaseWord(word) {
|
|
324
|
+
return !word.includes("-") && /[a-z][A-Z]/.test(word);
|
|
325
|
+
}
|
|
326
|
+
var SVG_CAMEL_CASE_ATTRS = /* @__PURE__ */ new Set([
|
|
327
|
+
// Transform/positioning
|
|
328
|
+
"viewBox",
|
|
329
|
+
"preserveAspectRatio",
|
|
330
|
+
// Gradient
|
|
331
|
+
"gradientUnits",
|
|
332
|
+
"gradientTransform",
|
|
333
|
+
"spreadMethod",
|
|
334
|
+
// Pattern
|
|
335
|
+
"patternUnits",
|
|
336
|
+
"patternContentUnits",
|
|
337
|
+
"patternTransform",
|
|
338
|
+
// Clipping/masking
|
|
339
|
+
"clipPathUnits",
|
|
340
|
+
"maskUnits",
|
|
341
|
+
"maskContentUnits",
|
|
342
|
+
// Marker (SVG spec keeps these camelCase, like viewBox)
|
|
343
|
+
"markerUnits",
|
|
344
|
+
"markerWidth",
|
|
345
|
+
"markerHeight",
|
|
346
|
+
"refX",
|
|
347
|
+
"refY",
|
|
348
|
+
// Text
|
|
349
|
+
"textLength",
|
|
350
|
+
"lengthAdjust",
|
|
351
|
+
"startOffset",
|
|
352
|
+
// Filter
|
|
353
|
+
"filterUnits",
|
|
354
|
+
"primitiveUnits",
|
|
355
|
+
"tableValues",
|
|
356
|
+
// feFuncR/G/B/A transfer table (type="table")
|
|
357
|
+
"stdDeviation",
|
|
358
|
+
"baseFrequency",
|
|
359
|
+
"numOctaves",
|
|
360
|
+
"surfaceScale",
|
|
361
|
+
"diffuseConstant",
|
|
362
|
+
"specularConstant",
|
|
363
|
+
"specularExponent",
|
|
364
|
+
"kernelMatrix",
|
|
365
|
+
"kernelUnitLength",
|
|
366
|
+
"edgeMode",
|
|
367
|
+
"preserveAlpha",
|
|
368
|
+
"targetX",
|
|
369
|
+
"targetY"
|
|
370
|
+
// // Animation
|
|
371
|
+
// 'attributeName',
|
|
372
|
+
// 'attributeType',
|
|
373
|
+
// 'calcMode',
|
|
374
|
+
// 'keyTimes',
|
|
375
|
+
// 'keySplines',
|
|
376
|
+
// 'repeatCount',
|
|
377
|
+
// 'repeatDur'
|
|
378
|
+
]);
|
|
379
|
+
function camelCaseToKebabWordIfNeeded(camel) {
|
|
380
|
+
return SVG_CAMEL_CASE_ATTRS.has(camel) ? camel : camel.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
381
|
+
}
|
|
382
|
+
function clamp(value, min, max) {
|
|
383
|
+
return Math.max(min, Math.min(value, max));
|
|
384
|
+
}
|
|
385
|
+
function bezier2D_pointAt(P0, P1, P2, P3, t) {
|
|
386
|
+
if (t <= 0) return [P0[0], P0[1]];
|
|
387
|
+
if (t >= 1) return [P3[0], P3[1]];
|
|
388
|
+
const u = 1 - t;
|
|
389
|
+
const u2 = u * u;
|
|
390
|
+
const u3 = u2 * u;
|
|
391
|
+
const t2 = t * t;
|
|
392
|
+
const t3 = t2 * t;
|
|
393
|
+
const w0 = u3;
|
|
394
|
+
const w1 = 3 * t * u2;
|
|
395
|
+
const w2 = 3 * t2 * u;
|
|
396
|
+
const w3 = t3;
|
|
397
|
+
return [
|
|
398
|
+
w0 * P0[0] + w1 * P1[0] + w2 * P2[0] + w3 * P3[0],
|
|
399
|
+
w0 * P0[1] + w1 * P1[1] + w2 * P2[1] + w3 * P3[1]
|
|
400
|
+
];
|
|
401
|
+
}
|
|
402
|
+
var BEZIER_T_NUDGE = 1e-4;
|
|
403
|
+
function bezier2D_derivativeAt(P0, P1, P2, P3, t) {
|
|
404
|
+
const result = _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t);
|
|
405
|
+
if (result[0] === 0 && result[1] === 0) {
|
|
406
|
+
const nudgedT = t < 0.5 ? t + BEZIER_T_NUDGE : t - BEZIER_T_NUDGE;
|
|
407
|
+
return _bezier2D_derivativeAtRaw(P0, P1, P2, P3, nudgedT);
|
|
408
|
+
}
|
|
409
|
+
return result;
|
|
410
|
+
}
|
|
411
|
+
function _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t) {
|
|
412
|
+
const u = 1 - t;
|
|
413
|
+
const a = 3 * u * u;
|
|
414
|
+
const b = 6 * t * u;
|
|
415
|
+
const c = 3 * t * t;
|
|
416
|
+
return [
|
|
417
|
+
a * (P1[0] - P0[0]) + b * (P2[0] - P1[0]) + c * (P3[0] - P2[0]),
|
|
418
|
+
a * (P1[1] - P0[1]) + b * (P2[1] - P1[1]) + c * (P3[1] - P2[1])
|
|
419
|
+
];
|
|
420
|
+
}
|
|
421
|
+
function bezier2D_arcLengthLUT(P0, P1, P2, P3, steps = 100) {
|
|
422
|
+
const n = steps + 1;
|
|
423
|
+
const ts = new Float64Array(n);
|
|
424
|
+
const ds = new Float64Array(n);
|
|
425
|
+
let prev = bezier2D_pointAt(P0, P1, P2, P3, 0);
|
|
426
|
+
ts[0] = 0;
|
|
427
|
+
ds[0] = 0;
|
|
428
|
+
let cum = 0;
|
|
429
|
+
for (let i = 1; i < n; i++) {
|
|
430
|
+
const t = i / steps;
|
|
431
|
+
const cur = bezier2D_pointAt(P0, P1, P2, P3, t);
|
|
432
|
+
const dx = cur[0] - prev[0];
|
|
433
|
+
const dy = cur[1] - prev[1];
|
|
434
|
+
cum += Math.sqrt(dx * dx + dy * dy);
|
|
435
|
+
ts[i] = t;
|
|
436
|
+
ds[i] = cum;
|
|
437
|
+
prev = cur;
|
|
438
|
+
}
|
|
439
|
+
return { ts, ds };
|
|
440
|
+
}
|
|
441
|
+
function bezier2D_tForDistance(lut, distance) {
|
|
442
|
+
const { ts, ds } = lut;
|
|
443
|
+
const last = ds.length - 1;
|
|
444
|
+
if (distance <= 0) return ts[0];
|
|
445
|
+
if (distance >= ds[last]) return ts[last];
|
|
446
|
+
let lo = 1;
|
|
447
|
+
let hi = last;
|
|
448
|
+
while (lo < hi) {
|
|
449
|
+
const mid = lo + hi >>> 1;
|
|
450
|
+
if (ds[mid] < distance) lo = mid + 1;
|
|
451
|
+
else hi = mid;
|
|
452
|
+
}
|
|
453
|
+
const dPrev = ds[hi - 1];
|
|
454
|
+
const dCur = ds[hi];
|
|
455
|
+
const span = dCur - dPrev;
|
|
456
|
+
const frac = span > 0 ? (distance - dPrev) / span : 0;
|
|
457
|
+
return ts[hi - 1] + frac * (ts[hi] - ts[hi - 1]);
|
|
458
|
+
}
|
|
459
|
+
function bezier2D_arcAtT(lut, t) {
|
|
460
|
+
const { ts, ds } = lut;
|
|
461
|
+
const last = ts.length - 1;
|
|
462
|
+
if (t <= ts[0]) return ds[0];
|
|
463
|
+
if (t >= ts[last]) return ds[last];
|
|
464
|
+
let lo = 1, hi = last;
|
|
465
|
+
while (lo < hi) {
|
|
466
|
+
const mid = lo + hi >>> 1;
|
|
467
|
+
if (ts[mid] < t) lo = mid + 1;
|
|
468
|
+
else hi = mid;
|
|
469
|
+
}
|
|
470
|
+
const tPrev = ts[hi - 1];
|
|
471
|
+
const span = ts[hi] - tPrev;
|
|
472
|
+
const frac = span > 0 ? (t - tPrev) / span : 0;
|
|
473
|
+
return ds[hi - 1] + frac * (ds[hi] - ds[hi - 1]);
|
|
474
|
+
}
|
|
475
|
+
function invertEasing(easing) {
|
|
476
|
+
if (!easing) return (y) => y;
|
|
477
|
+
const flipped = [easing[1], easing[0], easing[3], easing[2]];
|
|
478
|
+
return cubicBezier(flipped);
|
|
479
|
+
}
|
|
480
|
+
function isScrollTimeline(config) {
|
|
481
|
+
return (config == null ? void 0 : config.timelineSource) === "scroll";
|
|
482
|
+
}
|
|
483
|
+
function scrollTotalDurationMs(config) {
|
|
484
|
+
const duration = typeof (config == null ? void 0 : config.duration) === "number" && config.duration > 0 ? config.duration : DEFAULT_DURATION_MS;
|
|
485
|
+
const iterations = typeof (config == null ? void 0 : config.iterations) === "number" && config.iterations > 0 ? config.iterations : 1;
|
|
486
|
+
return duration * iterations;
|
|
487
|
+
}
|
|
488
|
+
function scrollPhaseInterval(phase, subjectSize, scrollportSize) {
|
|
489
|
+
const s = subjectSize, vp = scrollportSize;
|
|
490
|
+
switch (phase) {
|
|
491
|
+
case "cover":
|
|
492
|
+
return [0, s + vp];
|
|
493
|
+
case "entry":
|
|
494
|
+
return [0, Math.min(s, vp)];
|
|
495
|
+
case "contain":
|
|
496
|
+
return [Math.min(s, vp), Math.max(s, vp)];
|
|
497
|
+
case "exit":
|
|
498
|
+
return [Math.max(s, vp), s + vp];
|
|
499
|
+
case "entry-crossing":
|
|
500
|
+
return [0, s];
|
|
501
|
+
case "exit-crossing":
|
|
502
|
+
return [vp, s + vp];
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
var DEFAULT_PHASE = "cover";
|
|
506
|
+
function resolveRangePointU(point, defaultFraction, subjectSize, scrollportSize) {
|
|
507
|
+
var _a;
|
|
508
|
+
const [u0, u1] = scrollPhaseInterval((_a = point == null ? void 0 : point.phase) != null ? _a : DEFAULT_PHASE, subjectSize, scrollportSize);
|
|
509
|
+
const fraction = typeof (point == null ? void 0 : point.fraction) === "number" ? point.fraction : defaultFraction;
|
|
510
|
+
return u0 + fraction * (u1 - u0);
|
|
511
|
+
}
|
|
512
|
+
function scrollViewProgress(subjectStart, subjectSize, scrollportSize, range) {
|
|
513
|
+
const u = scrollportSize - subjectStart;
|
|
514
|
+
const uStart = resolveRangePointU(range == null ? void 0 : range.start, 0, subjectSize, scrollportSize);
|
|
515
|
+
const uEnd = resolveRangePointU(range == null ? void 0 : range.end, 1, subjectSize, scrollportSize);
|
|
516
|
+
if (uEnd <= uStart) return u >= uEnd ? 1 : 0;
|
|
517
|
+
return clamp((u - uStart) / (uEnd - uStart), 0, 1);
|
|
518
|
+
}
|
|
519
|
+
function scrollOffsetProgress(offset, maxOffset, range) {
|
|
520
|
+
var _a, _b;
|
|
521
|
+
const raw = maxOffset > 0 ? clamp(offset / maxOffset, 0, 1) : 1;
|
|
522
|
+
const start = typeof ((_a = range == null ? void 0 : range.start) == null ? void 0 : _a.fraction) === "number" ? range.start.fraction : 0;
|
|
523
|
+
const end = typeof ((_b = range == null ? void 0 : range.end) == null ? void 0 : _b.fraction) === "number" ? range.end.fraction : 1;
|
|
524
|
+
if (end <= start) return raw >= end ? 1 : 0;
|
|
525
|
+
return clamp((raw - start) / (end - start), 0, 1);
|
|
526
|
+
}
|
|
527
|
+
function scrollResolveAxis(axis, writingMode) {
|
|
528
|
+
const a = axis != null ? axis : "block";
|
|
529
|
+
if (a === "x" || a === "y") return a;
|
|
530
|
+
const vertical = !!writingMode && writingMode.startsWith("vertical");
|
|
531
|
+
if (a === "inline") return vertical ? "y" : "x";
|
|
532
|
+
return vertical ? "x" : "y";
|
|
533
|
+
}
|
|
534
|
+
function pathStr(path) {
|
|
535
|
+
if (!path.length) return ".";
|
|
536
|
+
let result = "";
|
|
537
|
+
for (const seg of path) {
|
|
538
|
+
if (seg.startsWith("[")) result += seg;
|
|
539
|
+
else result += (result ? "." : "") + seg;
|
|
540
|
+
}
|
|
541
|
+
return result;
|
|
542
|
+
}
|
|
543
|
+
var Base = class {
|
|
544
|
+
_canSanitize(raw) {
|
|
545
|
+
return this.isValid(raw);
|
|
546
|
+
}
|
|
547
|
+
optional() {
|
|
548
|
+
return new Optional(this);
|
|
141
549
|
}
|
|
142
550
|
};
|
|
143
|
-
var
|
|
144
|
-
constructor(
|
|
551
|
+
var Optional = class extends Base {
|
|
552
|
+
constructor(inner) {
|
|
145
553
|
super();
|
|
146
|
-
this.
|
|
147
|
-
this._default =
|
|
554
|
+
this.inner = inner;
|
|
555
|
+
this._default = void 0;
|
|
148
556
|
}
|
|
149
557
|
sanitize(raw) {
|
|
150
|
-
|
|
558
|
+
if (raw === void 0 || raw === null) return void 0;
|
|
559
|
+
return this.inner._canSanitize(raw) ? this.inner.sanitize(raw) : void 0;
|
|
151
560
|
}
|
|
152
561
|
isValid(raw, ctx, path) {
|
|
153
|
-
if (raw ===
|
|
154
|
-
|
|
155
|
-
|
|
562
|
+
if (raw === void 0 || raw === null) return true;
|
|
563
|
+
return this.inner.isValid(raw, ctx, path);
|
|
564
|
+
}
|
|
565
|
+
_canSanitize(raw) {
|
|
566
|
+
return raw === void 0 || raw === null || this.inner._canSanitize(raw);
|
|
156
567
|
}
|
|
157
568
|
};
|
|
158
|
-
var
|
|
159
|
-
constructor(
|
|
569
|
+
var Str = class extends Base {
|
|
570
|
+
constructor(_default = "") {
|
|
160
571
|
super();
|
|
161
|
-
this.
|
|
162
|
-
this._default = defaultVal != null ? defaultVal : values[0];
|
|
572
|
+
this._default = _default;
|
|
163
573
|
}
|
|
164
574
|
sanitize(raw) {
|
|
165
|
-
return
|
|
575
|
+
return typeof raw === "string" ? raw : this._default;
|
|
166
576
|
}
|
|
167
577
|
isValid(raw, ctx, path) {
|
|
168
|
-
if (
|
|
169
|
-
ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected
|
|
578
|
+
if (typeof raw === "string") return true;
|
|
579
|
+
ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected string, got " + typeof raw);
|
|
170
580
|
return false;
|
|
171
581
|
}
|
|
172
582
|
};
|
|
173
|
-
var
|
|
583
|
+
var Num = class extends Base {
|
|
584
|
+
constructor(_default = 0) {
|
|
585
|
+
super();
|
|
586
|
+
this._default = _default;
|
|
587
|
+
}
|
|
588
|
+
sanitize(raw) {
|
|
589
|
+
return typeof raw === "number" && isFinite(raw) ? raw : this._default;
|
|
590
|
+
}
|
|
591
|
+
isValid(raw, ctx, path) {
|
|
592
|
+
if (typeof raw === "number" && isFinite(raw)) return true;
|
|
593
|
+
ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected finite number, got " + JSON.stringify(raw));
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
var Bool = class extends Base {
|
|
598
|
+
constructor(_default = false) {
|
|
599
|
+
super();
|
|
600
|
+
this._default = _default;
|
|
601
|
+
}
|
|
602
|
+
sanitize(raw) {
|
|
603
|
+
return typeof raw === "boolean" ? raw : this._default;
|
|
604
|
+
}
|
|
605
|
+
isValid(raw, ctx, path) {
|
|
606
|
+
if (typeof raw === "boolean") return true;
|
|
607
|
+
ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected boolean, got " + typeof raw);
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
var Literal = class extends Base {
|
|
612
|
+
constructor(value) {
|
|
613
|
+
super();
|
|
614
|
+
this.value = value;
|
|
615
|
+
this._default = value;
|
|
616
|
+
}
|
|
617
|
+
sanitize(raw) {
|
|
618
|
+
return raw === this.value ? this.value : this._default;
|
|
619
|
+
}
|
|
620
|
+
isValid(raw, ctx, path) {
|
|
621
|
+
if (raw === this.value) return true;
|
|
622
|
+
ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected " + JSON.stringify(this.value) + ", got " + JSON.stringify(raw));
|
|
623
|
+
return false;
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
var Enum = class extends Base {
|
|
627
|
+
constructor(values, defaultVal) {
|
|
628
|
+
super();
|
|
629
|
+
this.values = values;
|
|
630
|
+
this._default = defaultVal != null ? defaultVal : values[0];
|
|
631
|
+
}
|
|
632
|
+
sanitize(raw) {
|
|
633
|
+
return this.values.includes(raw) ? raw : this._default;
|
|
634
|
+
}
|
|
635
|
+
isValid(raw, ctx, path) {
|
|
636
|
+
if (this.values.includes(raw)) return true;
|
|
637
|
+
ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected one of " + this.values.map((v) => JSON.stringify(v)).join(" | ") + ", got " + JSON.stringify(raw));
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
var Union = class extends Base {
|
|
174
642
|
constructor(schemas, defaultVal) {
|
|
175
643
|
super();
|
|
176
644
|
this.schemas = schemas;
|
|
@@ -725,6 +1193,22 @@ var PxDefsSchema = implementsInterface()(px.object({
|
|
|
725
1193
|
styles: px.record(px.any()).optional(),
|
|
726
1194
|
glyphs: px.record(PxGlyphFontSchema).optional()
|
|
727
1195
|
}));
|
|
1196
|
+
var PX_SCROLL_PHASES = ["cover", "contain", "entry", "exit", "entry-crossing", "exit-crossing"];
|
|
1197
|
+
var PxScrollRangePointSchema = implementsInterface()(px.object({
|
|
1198
|
+
phase: px.enum(PX_SCROLL_PHASES).optional(),
|
|
1199
|
+
fraction: px.number().optional()
|
|
1200
|
+
}));
|
|
1201
|
+
var PxScrollRangeSchema = px.object({
|
|
1202
|
+
start: PxScrollRangePointSchema.optional(),
|
|
1203
|
+
end: PxScrollRangePointSchema.optional()
|
|
1204
|
+
});
|
|
1205
|
+
var PxScrollSchema = implementsInterface()(px.object({
|
|
1206
|
+
driver: px.enum(["custom", "native"]).optional(),
|
|
1207
|
+
kind: px.enum(["view", "scroll"]).optional(),
|
|
1208
|
+
axis: px.enum(["block", "inline", "x", "y"]).optional(),
|
|
1209
|
+
source: px.enum(["nearest", "root"]).optional(),
|
|
1210
|
+
range: PxScrollRangeSchema.optional()
|
|
1211
|
+
}));
|
|
728
1212
|
var PxAnimatorConfigSchema = implementsInterface()(px.object({
|
|
729
1213
|
mode: px.enum([PxAnimatorMode.auto, PxAnimatorMode.waapi, PxAnimatorMode.frames]).optional(),
|
|
730
1214
|
duration: px.number().optional(),
|
|
@@ -740,6 +1224,7 @@ var PxAnimatorConfigSchema = implementsInterface()(px.object({
|
|
|
740
1224
|
definitions: PxDefsSchema.optional(),
|
|
741
1225
|
animateById: px.record(PxElementAnimationSchema).optional(),
|
|
742
1226
|
timelineSource: px.string().optional(),
|
|
1227
|
+
scroll: PxScrollSchema.optional(),
|
|
743
1228
|
debugInstName: px.string().optional()
|
|
744
1229
|
}));
|
|
745
1230
|
var PxBindingSchema = implementsInterface()(px.object({
|
|
@@ -759,589 +1244,177 @@ var PxAttrValueSchema = px.union([
|
|
|
759
1244
|
var PxAnimatableNumberSchema = px.union([
|
|
760
1245
|
px.number(),
|
|
761
1246
|
px.object({ value: px.number() }),
|
|
762
|
-
PxPropertyAnimationSchema
|
|
763
|
-
]);
|
|
764
|
-
var PxAnimatableVec2Schema = px.union([
|
|
765
|
-
px.tuple([px.number(), px.number()]),
|
|
766
|
-
px.object({ value: px.tuple([px.number(), px.number()]) }),
|
|
767
|
-
PxPropertyAnimationSchema
|
|
768
|
-
]);
|
|
769
|
-
var PxAnimatableStringSchema = px.union([
|
|
770
|
-
px.string(),
|
|
771
|
-
px.object({ value: px.string() }),
|
|
772
|
-
PxPropertyAnimationSchema
|
|
773
|
-
]);
|
|
774
|
-
var PxTransformByEffectSchema = implementsInterface()(px.object({
|
|
775
|
-
translate: PxAnimatableVec2Schema.optional(),
|
|
776
|
-
rotate: PxAnimatableNumberSchema.optional(),
|
|
777
|
-
scale: PxAnimatableVec2Schema.optional(),
|
|
778
|
-
skew: PxAnimatableNumberSchema.optional(),
|
|
779
|
-
origin: PxAnimatableVec2Schema.optional()
|
|
780
|
-
}));
|
|
781
|
-
var PxRepeaterEffectSchema = implementsInterface()(px.object({
|
|
782
|
-
// STATIC config, not a channel (V2/SCHEMA-DESIGN R5): the copy COUNT is read
|
|
783
|
-
// once at expansion time and never sampled — plain number, no `keyframes`.
|
|
784
|
-
copies: px.number().optional(),
|
|
785
|
-
translate: PxAnimatableVec2Schema.optional(),
|
|
786
|
-
rotate: PxAnimatableNumberSchema.optional(),
|
|
787
|
-
skew: PxAnimatableNumberSchema.optional(),
|
|
788
|
-
scale: PxAnimatableVec2Schema.optional(),
|
|
789
|
-
origin: PxAnimatableVec2Schema.optional()
|
|
790
|
-
}));
|
|
791
|
-
var PxMaskedByEffectSchema = implementsInterface()(px.object({
|
|
792
|
-
sourceId: px.string().optional(),
|
|
793
|
-
maskType: px.enum([PxMaskType.luminance, PxMaskType.alpha]).optional(),
|
|
794
|
-
maskUnits: px.enum([PxUnits.userSpaceOnUse, PxUnits.objectBoundingBox]).optional(),
|
|
795
|
-
maskContentUnits: px.enum([PxUnits.userSpaceOnUse, PxUnits.objectBoundingBox]).optional(),
|
|
796
|
-
x: px.number().optional(),
|
|
797
|
-
y: px.number().optional(),
|
|
798
|
-
width: px.number().optional(),
|
|
799
|
-
height: px.number().optional()
|
|
800
|
-
}));
|
|
801
|
-
var PxClipPathEffectSchema = implementsInterface()(px.object({
|
|
802
|
-
d: PxAnimatableStringSchema.optional(),
|
|
803
|
-
animate: PxPropertyAnimationSchema.optional()
|
|
804
|
-
}));
|
|
805
|
-
var PxTrimPathEffectSchema = implementsInterface()(px.object({
|
|
806
|
-
offset: PxAnimatableNumberSchema.optional(),
|
|
807
|
-
range: PxAnimatableVec2Schema.optional(),
|
|
808
|
-
subPaths: px.enum([PxTrimSubPaths.separate, PxTrimSubPaths.combined]).optional()
|
|
809
|
-
}));
|
|
810
|
-
var PxRetimeEffectSchema = implementsInterface()(px.object({
|
|
811
|
-
sourceId: px.string().optional(),
|
|
812
|
-
start: px.number().optional(),
|
|
813
|
-
stretch: px.number().optional(),
|
|
814
|
-
timeCrop: px.tuple([px.number(), px.number()]).optional()
|
|
815
|
-
}));
|
|
816
|
-
var PxCloneEffectSchema = implementsInterface()(px.object({
|
|
817
|
-
// Contextual kind — the `type` convention, see `PxNodeBase.type`.
|
|
818
|
-
type: px.enum([PxCloneType.content]).optional(),
|
|
819
|
-
sourceId: px.string().optional(),
|
|
820
|
-
retime: PxRetimeEffectSchema.optional()
|
|
821
|
-
}));
|
|
822
|
-
var PxGradientStopSchema = implementsInterface()(px.object({
|
|
823
|
-
offset: px.number(),
|
|
824
|
-
color: px.string()
|
|
825
|
-
}));
|
|
826
|
-
var PxAnimatableGradientStopsSchema = px.union([
|
|
827
|
-
px.array(PxGradientStopSchema),
|
|
828
|
-
px.object({ value: px.array(PxGradientStopSchema) }),
|
|
829
|
-
PxPropertyAnimationSchema
|
|
830
|
-
]);
|
|
831
|
-
var PxFillGradientEffectSchema = implementsInterface()(px.object({
|
|
832
|
-
// Contextual kind — the `type` convention, see `PxNodeBase.type`.
|
|
833
|
-
type: px.enum([PxGradientType.linear, PxGradientType.radial]),
|
|
834
|
-
p1: PxAnimatableVec2Schema.optional(),
|
|
835
|
-
p2: PxAnimatableVec2Schema.optional(),
|
|
836
|
-
c: PxAnimatableVec2Schema.optional(),
|
|
837
|
-
r: PxAnimatableNumberSchema.optional(),
|
|
838
|
-
fp: PxAnimatableVec2Schema.optional(),
|
|
839
|
-
stops: PxAnimatableGradientStopsSchema.optional(),
|
|
840
|
-
gradientUnits: px.enum([PxGradientUnits.userSpaceOnUse, PxGradientUnits.objectBoundingBox]).optional(),
|
|
841
|
-
spreadMethod: px.enum([PxGradientSpreadMethod.pad, PxGradientSpreadMethod.reflect, PxGradientSpreadMethod.repeat]).optional(),
|
|
842
|
-
gradientTransform: px.string().optional()
|
|
843
|
-
}));
|
|
844
|
-
var PxStrokeGradientEffectSchema = PxFillGradientEffectSchema;
|
|
845
|
-
var PxTextPathEffectSchema = implementsInterface()(px.object({
|
|
846
|
-
path: px.string(),
|
|
847
|
-
pathOverflow: px.enum([PxPathOverflow.clip, PxPathOverflow.extend]).optional(),
|
|
848
|
-
lengthAdjust: px.enum([PxLengthAdjust.spacing, PxLengthAdjust.spacingAndGlyphs]).optional(),
|
|
849
|
-
method: px.enum([PxTextPathMethod.align, PxTextPathMethod.stretch]).optional(),
|
|
850
|
-
spacing: px.enum([PxTextPathSpacing.auto, PxTextPathSpacing.exact]).optional(),
|
|
851
|
-
startOffset: PxAnimatableNumberSchema.optional(),
|
|
852
|
-
textLength: PxAnimatableNumberSchema.optional()
|
|
853
|
-
}));
|
|
854
|
-
var PxTextEffectSchema = implementsInterface()(px.object({
|
|
855
|
-
useGlyphs: px.boolean().optional()
|
|
856
|
-
}));
|
|
857
|
-
var PxEffectsSchema = implementsInterface()(px.object({
|
|
858
|
-
transformBy: PxTransformByEffectSchema.optional(),
|
|
859
|
-
repeater: PxRepeaterEffectSchema.optional(),
|
|
860
|
-
maskedBy: PxMaskedByEffectSchema.optional(),
|
|
861
|
-
clipPath: PxClipPathEffectSchema.optional(),
|
|
862
|
-
trimPath: PxTrimPathEffectSchema.optional(),
|
|
863
|
-
clone: PxCloneEffectSchema.optional(),
|
|
864
|
-
fillGradient: PxFillGradientEffectSchema.optional(),
|
|
865
|
-
strokeGradient: PxStrokeGradientEffectSchema.optional(),
|
|
866
|
-
textPath: PxTextPathEffectSchema.optional(),
|
|
867
|
-
text: PxTextEffectSchema.optional()
|
|
868
|
-
}));
|
|
869
|
-
function validateNodeEffects(root, opts) {
|
|
870
|
-
const warnings = [];
|
|
871
|
-
const walk = (node, path) => {
|
|
872
|
-
if (node && node.effects) {
|
|
873
|
-
const ctx = { errors: [], warnings: [], strict: !!(opts == null ? void 0 : opts.strict) };
|
|
874
|
-
const ok = PxEffectsSchema.isValid(node.effects, ctx, [path + ".effects"]);
|
|
875
|
-
if (!ok) {
|
|
876
|
-
for (const err of ctx.errors) warnings.push(err);
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
if (node && Array.isArray(node.children)) {
|
|
880
|
-
node.children.forEach((c, i) => walk(c, path + ".children[" + i + "]"));
|
|
881
|
-
}
|
|
882
|
-
};
|
|
883
|
-
walk(root, "root");
|
|
884
|
-
return warnings;
|
|
885
|
-
}
|
|
886
|
-
var PxNodeBase = px.openObject({
|
|
887
|
-
// CONVENTION (SCHEMA-DESIGN R1 / issues N4): `type` is the ONE word for "what
|
|
888
|
-
// kind of thing is this", discriminated by its CARRIER — here the node TAG
|
|
889
|
-
// (`rect`, `text`), and inside a sub-object that object's kind (`clone.type`,
|
|
890
|
-
// `fillGradient.type`, editor `preset.type`). Each sits in its own object, so
|
|
891
|
-
// the carrier disambiguates completely; synonyms (`cloneKind`, `presetShape`)
|
|
892
|
-
// would add words that all mean "type" and still need the carrier to read.
|
|
893
|
-
// Guarding a `type` SLOT against a wrong VALUE is the job of strict enums
|
|
894
|
-
// (issues V3), never of distinct key names.
|
|
895
|
-
type: px.string(),
|
|
896
|
-
id: px.string().optional(),
|
|
897
|
-
meta: px.any().optional(),
|
|
898
|
-
// Player-effects bucket emitted by the Editor's lightweight design format.
|
|
899
|
-
// Consumed and removed by `applyPlayerEffects` before any other normalisation
|
|
900
|
-
// (see `createAnimatorImpl`), so downstream code never sees it.
|
|
901
|
-
effects: PxEffectsSchema.optional(),
|
|
902
|
-
// `PxElementAnimation` (not just `PxAnimationDefinition`) — accepts
|
|
903
|
-
// string ref / array of refs / inline definition / mixed array; mirrors
|
|
904
|
-
// `animator.animateById` map values and what `processNode` resolves at runtime.
|
|
905
|
-
animate: PxElementAnimationSchema.optional(),
|
|
906
|
-
style: px.union([px.string(), px.record(px.union([px.string(), px.number()]))]).optional()
|
|
907
|
-
}, PxAttrValueSchema);
|
|
908
|
-
var PxNodeSchema = px.openObject(__spreadProps2(__spreadValues2({}, PxNodeBase._shape), {
|
|
909
|
-
children: px.lazy(() => px.array(PxNodeSchema), []).optional()
|
|
910
|
-
}), PxAttrValueSchema);
|
|
911
|
-
var PxSvgNodeExtra = px.object({
|
|
912
|
-
width: px.number().optional(),
|
|
913
|
-
height: px.number().optional(),
|
|
914
|
-
viewBox: px.string().optional(),
|
|
915
|
-
animator: PxAnimatorConfigSchema.optional()
|
|
916
|
-
});
|
|
917
|
-
var PxAnimatedSvgDocumentSchema = px.openObject(__spreadProps2(__spreadValues2(__spreadValues2({}, PxNodeBase._shape), PxSvgNodeExtra._shape), {
|
|
918
|
-
type: px.literal("svg"),
|
|
919
|
-
// override string → literal to require 'svg'
|
|
920
|
-
children: px.array(PxNodeSchema).optional()
|
|
921
|
-
}), PxAttrValueSchema);
|
|
922
|
-
var PxBezierPathSchema = implementsInterface()(px.object({
|
|
923
|
-
v: px.array(px.array(px.number())),
|
|
924
|
-
i: px.array(px.array(px.number())).optional(),
|
|
925
|
-
o: px.array(px.array(px.number())).optional(),
|
|
926
|
-
c: px.boolean().optional()
|
|
927
|
-
}));
|
|
928
|
-
function isPxElementFileFormatDeep(fileJson) {
|
|
929
|
-
const valid = PxAnimatedSvgDocumentSchema.isValid(fileJson);
|
|
930
|
-
return { valid, errors: valid ? [] : ["Document failed schema validation"] };
|
|
931
|
-
}
|
|
932
|
-
function bezierToSvgPath(path, forceCurves = false) {
|
|
933
|
-
var _a, _b, _c, _d;
|
|
934
|
-
const v = path.v;
|
|
935
|
-
const i = path.i;
|
|
936
|
-
const o = path.o;
|
|
937
|
-
const c = path.c;
|
|
938
|
-
if (!v.length) return "";
|
|
939
|
-
const d = [];
|
|
940
|
-
const len = v.length;
|
|
941
|
-
d.push("M" + v[0][0] + "," + v[0][1]);
|
|
942
|
-
for (let idx = 1; idx < len; idx++) {
|
|
943
|
-
const prevV = v[idx - 1];
|
|
944
|
-
const prevO = (_a = o == null ? void 0 : o[idx - 1]) != null ? _a : prevV;
|
|
945
|
-
const currI = (_b = i == null ? void 0 : i[idx]) != null ? _b : v[idx];
|
|
946
|
-
const currV = v[idx];
|
|
947
|
-
const isLine = !forceCurves && (prevO[0] === prevV[0] && prevO[1] === prevV[1]) && (currI[0] === currV[0] && currI[1] === currV[1]);
|
|
948
|
-
if (isLine) {
|
|
949
|
-
d.push("L" + currV[0] + "," + currV[1]);
|
|
950
|
-
} else {
|
|
951
|
-
d.push("C" + prevO[0] + "," + prevO[1] + "," + currI[0] + "," + currI[1] + "," + currV[0] + "," + currV[1]);
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
if (c && len > 0) {
|
|
955
|
-
const lastV = v[len - 1];
|
|
956
|
-
const lastO = (_c = o == null ? void 0 : o[len - 1]) != null ? _c : lastV;
|
|
957
|
-
const firstI = (_d = i == null ? void 0 : i[0]) != null ? _d : v[0];
|
|
958
|
-
const firstV = v[0];
|
|
959
|
-
const isLine = !forceCurves && (lastO[0] === lastV[0] && lastO[1] === lastV[1]) && (firstI[0] === firstV[0] && firstI[1] === firstV[1]);
|
|
960
|
-
if (!isLine) {
|
|
961
|
-
d.push("C" + lastO[0] + "," + lastO[1] + "," + firstI[0] + "," + firstI[1] + "," + firstV[0] + "," + firstV[1]);
|
|
962
|
-
}
|
|
963
|
-
d.push("z");
|
|
964
|
-
}
|
|
965
|
-
return d.join("");
|
|
966
|
-
}
|
|
967
|
-
function interpolateNum(a, b, t) {
|
|
968
|
-
return a + (b - a) * t;
|
|
969
|
-
}
|
|
970
|
-
function interpolateVec(a, b, t) {
|
|
971
|
-
const res = [];
|
|
972
|
-
const count = Math.max(a.length, b.length);
|
|
973
|
-
for (let i = 0; i < count; i++) {
|
|
974
|
-
res[i] = interpolateNum(a[i] || 0, b[i] || 0, t);
|
|
975
|
-
}
|
|
976
|
-
return res;
|
|
977
|
-
}
|
|
978
|
-
function interpolateColor(a, b, t) {
|
|
979
|
-
return [
|
|
980
|
-
interpolateNum(a[0] || 0, b[0] || 0, t),
|
|
981
|
-
interpolateNum(a[1] || 0, b[1] || 0, t),
|
|
982
|
-
interpolateNum(a[2] || 0, b[2] || 0, t),
|
|
983
|
-
interpolateNum(a[3] === void 0 ? 1 : a[3], b[3] === void 0 ? 1 : b[3], t)
|
|
984
|
-
];
|
|
985
|
-
}
|
|
986
|
-
function interpolateBeziers(paths1, paths2, progress) {
|
|
987
|
-
const count = Math.max(paths1.length, paths2.length);
|
|
988
|
-
const res = [];
|
|
989
|
-
for (let i = 0; i < count; i++) {
|
|
990
|
-
res.push(interpolateBezier(paths1[i], paths2[i], progress));
|
|
991
|
-
}
|
|
992
|
-
return res;
|
|
993
|
-
}
|
|
994
|
-
function interpolateBezier(path1, path2, progress) {
|
|
995
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
996
|
-
if (!path1 || !path2) return path1 || path2 || { v: [] };
|
|
997
|
-
const t = Math.min(Math.max(progress, 0), 1);
|
|
998
|
-
const len = Math.min(path1.v.length, path2.v.length);
|
|
999
|
-
const v = [];
|
|
1000
|
-
const i = [];
|
|
1001
|
-
const o = [];
|
|
1002
|
-
for (let idx = 0; idx < len; idx++) {
|
|
1003
|
-
const v1 = path1.v[idx];
|
|
1004
|
-
const v2 = path2.v[idx];
|
|
1005
|
-
v.push(interpolateVec(v1, v2, t));
|
|
1006
|
-
const i1 = (_b = (_a = path1.i) == null ? void 0 : _a[idx]) != null ? _b : v1;
|
|
1007
|
-
const i2 = (_d = (_c = path2.i) == null ? void 0 : _c[idx]) != null ? _d : v2;
|
|
1008
|
-
i.push(interpolateVec(i1, i2, t));
|
|
1009
|
-
const o1 = (_f = (_e = path1.o) == null ? void 0 : _e[idx]) != null ? _f : v1;
|
|
1010
|
-
const o2 = (_h = (_g = path2.o) == null ? void 0 : _g[idx]) != null ? _h : v2;
|
|
1011
|
-
o.push(interpolateVec(o1, o2, t));
|
|
1012
|
-
}
|
|
1013
|
-
return { v, i: i.length ? i : void 0, o: o.length ? o : void 0, c: (_i = path1.c) != null ? _i : path2.c };
|
|
1014
|
-
}
|
|
1015
|
-
function remap(value, inMin, inMax, outMin, outMax) {
|
|
1016
|
-
if (inMax === inMin) return outMin;
|
|
1017
|
-
const t = (value - inMin) / (inMax - inMin);
|
|
1018
|
-
return outMin + t * (outMax - outMin);
|
|
1019
|
-
}
|
|
1020
|
-
function solveCubicBezierX(p1x, p2x, x) {
|
|
1021
|
-
if (x <= 0) return 0;
|
|
1022
|
-
if (x >= 1) return 1;
|
|
1023
|
-
const cx = 3 * p1x;
|
|
1024
|
-
const bx = 3 * (p2x - p1x) - cx;
|
|
1025
|
-
const ax = 1 - cx - bx;
|
|
1026
|
-
function sampleX(t) {
|
|
1027
|
-
return ((ax * t + bx) * t + cx) * t;
|
|
1028
|
-
}
|
|
1029
|
-
function sampleDX(t) {
|
|
1030
|
-
return (3 * ax * t + 2 * bx) * t + cx;
|
|
1031
|
-
}
|
|
1032
|
-
let t2 = x;
|
|
1033
|
-
let t0 = 0;
|
|
1034
|
-
let t1 = 1;
|
|
1035
|
-
for (let i = 0; i < 8; i++) {
|
|
1036
|
-
const x2 = sampleX(t2) - x;
|
|
1037
|
-
if (Math.abs(x2) < 1e-6) return t2;
|
|
1038
|
-
const d2 = sampleDX(t2);
|
|
1039
|
-
if (Math.abs(d2) < 1e-6) break;
|
|
1040
|
-
t2 -= x2 / d2;
|
|
1041
|
-
}
|
|
1042
|
-
t2 = x;
|
|
1043
|
-
while (t0 < t1) {
|
|
1044
|
-
const x2 = sampleX(t2);
|
|
1045
|
-
if (Math.abs(x2 - x) < 1e-6) return t2;
|
|
1046
|
-
if (x > x2) t0 = t2;
|
|
1047
|
-
else t1 = t2;
|
|
1048
|
-
t2 = (t1 + t0) / 2;
|
|
1049
|
-
}
|
|
1050
|
-
return t2;
|
|
1051
|
-
}
|
|
1052
|
-
function cubicBezier(easing) {
|
|
1053
|
-
const [p1x, p1y, p2x, p2y] = easing;
|
|
1054
|
-
const cy = 3 * p1y;
|
|
1055
|
-
const by = 3 * (p2y - p1y) - cy;
|
|
1056
|
-
const ay = 1 - cy - by;
|
|
1057
|
-
function sampleCurveY(t) {
|
|
1058
|
-
return ((ay * t + by) * t + cy) * t;
|
|
1059
|
-
}
|
|
1060
|
-
return function(x) {
|
|
1061
|
-
return sampleCurveY(solveCubicBezierX(p1x, p2x, x));
|
|
1062
|
-
};
|
|
1063
|
-
}
|
|
1064
|
-
function lerp2(a, b, t) {
|
|
1065
|
-
return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
|
|
1066
|
-
}
|
|
1067
|
-
function subdivideCubicBezier(p0, p1, p2, p3, t) {
|
|
1068
|
-
const q0 = lerp2(p0, p1, t);
|
|
1069
|
-
const q1 = lerp2(p1, p2, t);
|
|
1070
|
-
const q2 = lerp2(p2, p3, t);
|
|
1071
|
-
const r0 = lerp2(q0, q1, t);
|
|
1072
|
-
const r1 = lerp2(q1, q2, t);
|
|
1073
|
-
const s = lerp2(r0, r1, t);
|
|
1074
|
-
return {
|
|
1075
|
-
left: [p0, q0, r0, s],
|
|
1076
|
-
right: [s, r1, q2, p3]
|
|
1077
|
-
};
|
|
1078
|
-
}
|
|
1079
|
-
function splitEasing(easing, xFraction) {
|
|
1080
|
-
if (!easing) return { left: void 0, right: void 0 };
|
|
1081
|
-
if (xFraction <= 0) return { left: void 0, right: easing };
|
|
1082
|
-
if (xFraction >= 1) return { left: easing, right: void 0 };
|
|
1083
|
-
const [x1, y1, x2, y2] = easing;
|
|
1084
|
-
const t = solveCubicBezierX(x1, x2, xFraction);
|
|
1085
|
-
const p0 = [0, 0];
|
|
1086
|
-
const p1 = [x1, y1];
|
|
1087
|
-
const p2 = [x2, y2];
|
|
1088
|
-
const p3 = [1, 1];
|
|
1089
|
-
const { left, right } = subdivideCubicBezier(p0, p1, p2, p3, t);
|
|
1090
|
-
const sx = left[3][0];
|
|
1091
|
-
const sy = left[3][1];
|
|
1092
|
-
let leftEasing;
|
|
1093
|
-
if (sx > 1e-9 && Math.abs(sy) > 1e-9) {
|
|
1094
|
-
leftEasing = [
|
|
1095
|
-
left[1][0] / sx,
|
|
1096
|
-
left[1][1] / sy,
|
|
1097
|
-
left[2][0] / sx,
|
|
1098
|
-
left[2][1] / sy
|
|
1099
|
-
];
|
|
1100
|
-
}
|
|
1101
|
-
let rightEasing;
|
|
1102
|
-
const rx = 1 - sx;
|
|
1103
|
-
const ry = 1 - sy;
|
|
1104
|
-
if (rx > 1e-9 && Math.abs(ry) > 1e-9) {
|
|
1105
|
-
rightEasing = [
|
|
1106
|
-
(right[1][0] - sx) / rx,
|
|
1107
|
-
(right[1][1] - sy) / ry,
|
|
1108
|
-
(right[2][0] - sx) / rx,
|
|
1109
|
-
(right[2][1] - sy) / ry
|
|
1110
|
-
];
|
|
1111
|
-
}
|
|
1112
|
-
return { left: leftEasing, right: rightEasing };
|
|
1113
|
-
}
|
|
1114
|
-
function reverseEasing(easing) {
|
|
1115
|
-
if (!easing) return void 0;
|
|
1116
|
-
return [1 - easing[2], 1 - easing[3], 1 - easing[0], 1 - easing[1]];
|
|
1117
|
-
}
|
|
1118
|
-
function toRGBA(color) {
|
|
1119
|
-
const r = Math.round(color[0] * 255);
|
|
1120
|
-
const g = Math.round(color[1] * 255);
|
|
1121
|
-
const b = Math.round(color[2] * 255);
|
|
1122
|
-
return color.length === 4 ? "rgba(" + r + "," + g + "," + b + "," + color[3] + ")" : "rgb(" + r + "," + g + "," + b + ")";
|
|
1123
|
-
}
|
|
1124
|
-
function parseRgba(s) {
|
|
1125
|
-
var _a;
|
|
1126
|
-
const inner = (_a = s.match(/rgba?\((.*)\)/)) == null ? void 0 : _a[1];
|
|
1127
|
-
if (!inner) throw new Error("Invalid rgb/rgba format");
|
|
1128
|
-
const parts = inner.split(",").map((v) => +v.trim());
|
|
1129
|
-
return [parts[0] / 255, parts[1] / 255, parts[2] / 255, ...parts[3] !== void 0 ? [parts[3]] : []];
|
|
1130
|
-
}
|
|
1131
|
-
function parseHex(s) {
|
|
1132
|
-
const hex = s.slice(1);
|
|
1133
|
-
const isShort = hex.length <= 4;
|
|
1134
|
-
const r = isShort ? hex[0] + hex[0] : hex.slice(0, 2);
|
|
1135
|
-
const g = isShort ? hex[1] + hex[1] : hex.slice(2, 4);
|
|
1136
|
-
const b = isShort ? hex[2] + hex[2] : hex.slice(4, 6);
|
|
1137
|
-
const a = hex.length === 4 ? hex[3] + hex[3] : hex.length === 8 ? hex.slice(6, 8) : null;
|
|
1138
|
-
const result = [
|
|
1139
|
-
parseInt(r, 16) / 255,
|
|
1140
|
-
parseInt(g, 16) / 255,
|
|
1141
|
-
parseInt(b, 16) / 255
|
|
1142
|
-
];
|
|
1143
|
-
if (a !== null) {
|
|
1144
|
-
result.push(parseInt(a, 16) / 255);
|
|
1145
|
-
}
|
|
1146
|
-
return result;
|
|
1147
|
-
}
|
|
1148
|
-
function parseColor(s) {
|
|
1149
|
-
if (!s) return void 0;
|
|
1150
|
-
if (Array.isArray(s)) return s;
|
|
1151
|
-
if (typeof s !== "string") return void 0;
|
|
1152
|
-
if (s.startsWith("#")) {
|
|
1153
|
-
return parseHex(s);
|
|
1154
|
-
} else if (s.startsWith("rgb")) {
|
|
1155
|
-
return parseRgba(s);
|
|
1156
|
-
} else {
|
|
1157
|
-
console.warn("Unsupported color format: " + s);
|
|
1158
|
-
}
|
|
1159
|
-
return void 0;
|
|
1160
|
-
}
|
|
1161
|
-
var COLOUR_ATTR_NAMES = /* @__PURE__ */ new Set(["color", "fill", "flood-color", "lighting-color", "stop-color", "stroke"]);
|
|
1162
|
-
var TRANSFORM_FN_NAMES = /* @__PURE__ */ new Set(["translate", "rotate", "scale", "skew"]);
|
|
1163
|
-
var PCT_BASED_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
|
|
1164
|
-
function composeTransformParts(parts, opts) {
|
|
1165
|
-
var _a;
|
|
1166
|
-
if (!parts) return "";
|
|
1167
|
-
const withUnits = (_a = opts == null ? void 0 : opts.withUnits) != null ? _a : true;
|
|
1168
|
-
const segs = [];
|
|
1169
|
-
const t = parts.translate;
|
|
1170
|
-
const o = parts.origin;
|
|
1171
|
-
const r = parts.rotate;
|
|
1172
|
-
const k = parts.skew;
|
|
1173
|
-
const s = parts.scale;
|
|
1174
|
-
const tu = withUnits ? "px" : "";
|
|
1175
|
-
const ru = withUnits ? "deg" : "";
|
|
1176
|
-
if (t) segs.push("translate(" + t[0] + tu + "," + t[1] + tu + ")");
|
|
1177
|
-
if (o) segs.push("translate(" + o[0] + tu + "," + o[1] + tu + ")");
|
|
1178
|
-
if (r !== void 0 && r !== null) segs.push("rotate(" + r + ru + ")");
|
|
1179
|
-
if (k !== void 0 && k !== null) segs.push("skewX(" + k + ru + ")");
|
|
1180
|
-
if (s) segs.push("scale(" + s[0] + "," + s[1] + ")");
|
|
1181
|
-
if (o) segs.push("translate(" + -o[0] + tu + "," + -o[1] + tu + ")");
|
|
1182
|
-
return segs.join("");
|
|
1183
|
-
}
|
|
1184
|
-
var STYLE_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
|
|
1185
|
-
var DEFAULT_DURATION_MS = 1e3;
|
|
1186
|
-
function kebabToCamelCaseWord(kebab) {
|
|
1187
|
-
return kebab.includes("-") ? kebab.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) : kebab;
|
|
1188
|
-
}
|
|
1189
|
-
function isCamelCaseWord(word) {
|
|
1190
|
-
return !word.includes("-") && /[a-z][A-Z]/.test(word);
|
|
1191
|
-
}
|
|
1192
|
-
var SVG_CAMEL_CASE_ATTRS = /* @__PURE__ */ new Set([
|
|
1193
|
-
// Transform/positioning
|
|
1194
|
-
"viewBox",
|
|
1195
|
-
"preserveAspectRatio",
|
|
1196
|
-
// Gradient
|
|
1197
|
-
"gradientUnits",
|
|
1198
|
-
"gradientTransform",
|
|
1199
|
-
"spreadMethod",
|
|
1200
|
-
// Pattern
|
|
1201
|
-
"patternUnits",
|
|
1202
|
-
"patternContentUnits",
|
|
1203
|
-
"patternTransform",
|
|
1204
|
-
// Clipping/masking
|
|
1205
|
-
"clipPathUnits",
|
|
1206
|
-
"maskUnits",
|
|
1207
|
-
"maskContentUnits",
|
|
1208
|
-
// Marker (SVG spec keeps these camelCase, like viewBox)
|
|
1209
|
-
"markerUnits",
|
|
1210
|
-
"markerWidth",
|
|
1211
|
-
"markerHeight",
|
|
1212
|
-
"refX",
|
|
1213
|
-
"refY",
|
|
1214
|
-
// Text
|
|
1215
|
-
"textLength",
|
|
1216
|
-
"lengthAdjust",
|
|
1217
|
-
"startOffset",
|
|
1218
|
-
// Filter
|
|
1219
|
-
"filterUnits",
|
|
1220
|
-
"primitiveUnits",
|
|
1221
|
-
"tableValues",
|
|
1222
|
-
// feFuncR/G/B/A transfer table (type="table")
|
|
1223
|
-
"stdDeviation",
|
|
1224
|
-
"baseFrequency",
|
|
1225
|
-
"numOctaves",
|
|
1226
|
-
"surfaceScale",
|
|
1227
|
-
"diffuseConstant",
|
|
1228
|
-
"specularConstant",
|
|
1229
|
-
"specularExponent",
|
|
1230
|
-
"kernelMatrix",
|
|
1231
|
-
"kernelUnitLength",
|
|
1232
|
-
"edgeMode",
|
|
1233
|
-
"preserveAlpha",
|
|
1234
|
-
"targetX",
|
|
1235
|
-
"targetY"
|
|
1236
|
-
// // Animation
|
|
1237
|
-
// 'attributeName',
|
|
1238
|
-
// 'attributeType',
|
|
1239
|
-
// 'calcMode',
|
|
1240
|
-
// 'keyTimes',
|
|
1241
|
-
// 'keySplines',
|
|
1242
|
-
// 'repeatCount',
|
|
1243
|
-
// 'repeatDur'
|
|
1244
|
-
]);
|
|
1245
|
-
function camelCaseToKebabWordIfNeeded(camel) {
|
|
1246
|
-
return SVG_CAMEL_CASE_ATTRS.has(camel) ? camel : camel.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
1247
|
-
}
|
|
1248
|
-
function clamp(value, min, max) {
|
|
1249
|
-
return Math.max(min, Math.min(value, max));
|
|
1250
|
-
}
|
|
1251
|
-
function bezier2D_pointAt(P0, P1, P2, P3, t) {
|
|
1252
|
-
if (t <= 0) return [P0[0], P0[1]];
|
|
1253
|
-
if (t >= 1) return [P3[0], P3[1]];
|
|
1254
|
-
const u = 1 - t;
|
|
1255
|
-
const u2 = u * u;
|
|
1256
|
-
const u3 = u2 * u;
|
|
1257
|
-
const t2 = t * t;
|
|
1258
|
-
const t3 = t2 * t;
|
|
1259
|
-
const w0 = u3;
|
|
1260
|
-
const w1 = 3 * t * u2;
|
|
1261
|
-
const w2 = 3 * t2 * u;
|
|
1262
|
-
const w3 = t3;
|
|
1263
|
-
return [
|
|
1264
|
-
w0 * P0[0] + w1 * P1[0] + w2 * P2[0] + w3 * P3[0],
|
|
1265
|
-
w0 * P0[1] + w1 * P1[1] + w2 * P2[1] + w3 * P3[1]
|
|
1266
|
-
];
|
|
1267
|
-
}
|
|
1268
|
-
var BEZIER_T_NUDGE = 1e-4;
|
|
1269
|
-
function bezier2D_derivativeAt(P0, P1, P2, P3, t) {
|
|
1270
|
-
const result = _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t);
|
|
1271
|
-
if (result[0] === 0 && result[1] === 0) {
|
|
1272
|
-
const nudgedT = t < 0.5 ? t + BEZIER_T_NUDGE : t - BEZIER_T_NUDGE;
|
|
1273
|
-
return _bezier2D_derivativeAtRaw(P0, P1, P2, P3, nudgedT);
|
|
1274
|
-
}
|
|
1275
|
-
return result;
|
|
1276
|
-
}
|
|
1277
|
-
function _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t) {
|
|
1278
|
-
const u = 1 - t;
|
|
1279
|
-
const a = 3 * u * u;
|
|
1280
|
-
const b = 6 * t * u;
|
|
1281
|
-
const c = 3 * t * t;
|
|
1282
|
-
return [
|
|
1283
|
-
a * (P1[0] - P0[0]) + b * (P2[0] - P1[0]) + c * (P3[0] - P2[0]),
|
|
1284
|
-
a * (P1[1] - P0[1]) + b * (P2[1] - P1[1]) + c * (P3[1] - P2[1])
|
|
1285
|
-
];
|
|
1286
|
-
}
|
|
1287
|
-
function bezier2D_arcLengthLUT(P0, P1, P2, P3, steps = 100) {
|
|
1288
|
-
const n = steps + 1;
|
|
1289
|
-
const ts = new Float64Array(n);
|
|
1290
|
-
const ds = new Float64Array(n);
|
|
1291
|
-
let prev = bezier2D_pointAt(P0, P1, P2, P3, 0);
|
|
1292
|
-
ts[0] = 0;
|
|
1293
|
-
ds[0] = 0;
|
|
1294
|
-
let cum = 0;
|
|
1295
|
-
for (let i = 1; i < n; i++) {
|
|
1296
|
-
const t = i / steps;
|
|
1297
|
-
const cur = bezier2D_pointAt(P0, P1, P2, P3, t);
|
|
1298
|
-
const dx = cur[0] - prev[0];
|
|
1299
|
-
const dy = cur[1] - prev[1];
|
|
1300
|
-
cum += Math.sqrt(dx * dx + dy * dy);
|
|
1301
|
-
ts[i] = t;
|
|
1302
|
-
ds[i] = cum;
|
|
1303
|
-
prev = cur;
|
|
1304
|
-
}
|
|
1305
|
-
return { ts, ds };
|
|
1306
|
-
}
|
|
1307
|
-
function bezier2D_tForDistance(lut, distance) {
|
|
1308
|
-
const { ts, ds } = lut;
|
|
1309
|
-
const last = ds.length - 1;
|
|
1310
|
-
if (distance <= 0) return ts[0];
|
|
1311
|
-
if (distance >= ds[last]) return ts[last];
|
|
1312
|
-
let lo = 1;
|
|
1313
|
-
let hi = last;
|
|
1314
|
-
while (lo < hi) {
|
|
1315
|
-
const mid = lo + hi >>> 1;
|
|
1316
|
-
if (ds[mid] < distance) lo = mid + 1;
|
|
1317
|
-
else hi = mid;
|
|
1318
|
-
}
|
|
1319
|
-
const dPrev = ds[hi - 1];
|
|
1320
|
-
const dCur = ds[hi];
|
|
1321
|
-
const span = dCur - dPrev;
|
|
1322
|
-
const frac = span > 0 ? (distance - dPrev) / span : 0;
|
|
1323
|
-
return ts[hi - 1] + frac * (ts[hi] - ts[hi - 1]);
|
|
1324
|
-
}
|
|
1325
|
-
function bezier2D_arcAtT(lut, t) {
|
|
1326
|
-
const { ts, ds } = lut;
|
|
1327
|
-
const last = ts.length - 1;
|
|
1328
|
-
if (t <= ts[0]) return ds[0];
|
|
1329
|
-
if (t >= ts[last]) return ds[last];
|
|
1330
|
-
let lo = 1, hi = last;
|
|
1331
|
-
while (lo < hi) {
|
|
1332
|
-
const mid = lo + hi >>> 1;
|
|
1333
|
-
if (ts[mid] < t) lo = mid + 1;
|
|
1334
|
-
else hi = mid;
|
|
1335
|
-
}
|
|
1336
|
-
const tPrev = ts[hi - 1];
|
|
1337
|
-
const span = ts[hi] - tPrev;
|
|
1338
|
-
const frac = span > 0 ? (t - tPrev) / span : 0;
|
|
1339
|
-
return ds[hi - 1] + frac * (ds[hi] - ds[hi - 1]);
|
|
1247
|
+
PxPropertyAnimationSchema
|
|
1248
|
+
]);
|
|
1249
|
+
var PxAnimatableVec2Schema = px.union([
|
|
1250
|
+
px.tuple([px.number(), px.number()]),
|
|
1251
|
+
px.object({ value: px.tuple([px.number(), px.number()]) }),
|
|
1252
|
+
PxPropertyAnimationSchema
|
|
1253
|
+
]);
|
|
1254
|
+
var PxAnimatableStringSchema = px.union([
|
|
1255
|
+
px.string(),
|
|
1256
|
+
px.object({ value: px.string() }),
|
|
1257
|
+
PxPropertyAnimationSchema
|
|
1258
|
+
]);
|
|
1259
|
+
var PxTransformByEffectSchema = implementsInterface()(px.object({
|
|
1260
|
+
translate: PxAnimatableVec2Schema.optional(),
|
|
1261
|
+
rotate: PxAnimatableNumberSchema.optional(),
|
|
1262
|
+
scale: PxAnimatableVec2Schema.optional(),
|
|
1263
|
+
skew: PxAnimatableNumberSchema.optional(),
|
|
1264
|
+
origin: PxAnimatableVec2Schema.optional()
|
|
1265
|
+
}));
|
|
1266
|
+
var PxRepeaterEffectSchema = implementsInterface()(px.object({
|
|
1267
|
+
// STATIC config, not a channel (V2/SCHEMA-DESIGN R5): the copy COUNT is read
|
|
1268
|
+
// once at expansion time and never sampled — plain number, no `keyframes`.
|
|
1269
|
+
copies: px.number().optional(),
|
|
1270
|
+
translate: PxAnimatableVec2Schema.optional(),
|
|
1271
|
+
rotate: PxAnimatableNumberSchema.optional(),
|
|
1272
|
+
skew: PxAnimatableNumberSchema.optional(),
|
|
1273
|
+
scale: PxAnimatableVec2Schema.optional(),
|
|
1274
|
+
origin: PxAnimatableVec2Schema.optional()
|
|
1275
|
+
}));
|
|
1276
|
+
var PxMaskedByEffectSchema = implementsInterface()(px.object({
|
|
1277
|
+
sourceId: px.string().optional(),
|
|
1278
|
+
maskType: px.enum([PxMaskType.luminance, PxMaskType.alpha]).optional(),
|
|
1279
|
+
maskUnits: px.enum([PxUnits.userSpaceOnUse, PxUnits.objectBoundingBox]).optional(),
|
|
1280
|
+
maskContentUnits: px.enum([PxUnits.userSpaceOnUse, PxUnits.objectBoundingBox]).optional(),
|
|
1281
|
+
x: px.number().optional(),
|
|
1282
|
+
y: px.number().optional(),
|
|
1283
|
+
width: px.number().optional(),
|
|
1284
|
+
height: px.number().optional()
|
|
1285
|
+
}));
|
|
1286
|
+
var PxClipPathEffectSchema = implementsInterface()(px.object({
|
|
1287
|
+
d: PxAnimatableStringSchema.optional(),
|
|
1288
|
+
animate: PxPropertyAnimationSchema.optional()
|
|
1289
|
+
}));
|
|
1290
|
+
var PxTrimPathEffectSchema = implementsInterface()(px.object({
|
|
1291
|
+
offset: PxAnimatableNumberSchema.optional(),
|
|
1292
|
+
range: PxAnimatableVec2Schema.optional(),
|
|
1293
|
+
subPaths: px.enum([PxTrimSubPaths.separate, PxTrimSubPaths.combined]).optional()
|
|
1294
|
+
}));
|
|
1295
|
+
var PxRetimeEffectSchema = implementsInterface()(px.object({
|
|
1296
|
+
sourceId: px.string().optional(),
|
|
1297
|
+
start: px.number().optional(),
|
|
1298
|
+
stretch: px.number().optional(),
|
|
1299
|
+
timeCrop: px.tuple([px.number(), px.number()]).optional()
|
|
1300
|
+
}));
|
|
1301
|
+
var PxCloneEffectSchema = implementsInterface()(px.object({
|
|
1302
|
+
// Contextual kind — the `type` convention, see `PxNodeBase.type`.
|
|
1303
|
+
type: px.enum([PxCloneType.content]).optional(),
|
|
1304
|
+
sourceId: px.string().optional(),
|
|
1305
|
+
retime: PxRetimeEffectSchema.optional()
|
|
1306
|
+
}));
|
|
1307
|
+
var PxGradientStopSchema = implementsInterface()(px.object({
|
|
1308
|
+
offset: px.number(),
|
|
1309
|
+
color: px.string()
|
|
1310
|
+
}));
|
|
1311
|
+
var PxAnimatableGradientStopsSchema = px.union([
|
|
1312
|
+
px.array(PxGradientStopSchema),
|
|
1313
|
+
px.object({ value: px.array(PxGradientStopSchema) }),
|
|
1314
|
+
PxPropertyAnimationSchema
|
|
1315
|
+
]);
|
|
1316
|
+
var PxFillGradientEffectSchema = implementsInterface()(px.object({
|
|
1317
|
+
// Contextual kind — the `type` convention, see `PxNodeBase.type`.
|
|
1318
|
+
type: px.enum([PxGradientType.linear, PxGradientType.radial]),
|
|
1319
|
+
p1: PxAnimatableVec2Schema.optional(),
|
|
1320
|
+
p2: PxAnimatableVec2Schema.optional(),
|
|
1321
|
+
c: PxAnimatableVec2Schema.optional(),
|
|
1322
|
+
r: PxAnimatableNumberSchema.optional(),
|
|
1323
|
+
fp: PxAnimatableVec2Schema.optional(),
|
|
1324
|
+
stops: PxAnimatableGradientStopsSchema.optional(),
|
|
1325
|
+
gradientUnits: px.enum([PxGradientUnits.userSpaceOnUse, PxGradientUnits.objectBoundingBox]).optional(),
|
|
1326
|
+
spreadMethod: px.enum([PxGradientSpreadMethod.pad, PxGradientSpreadMethod.reflect, PxGradientSpreadMethod.repeat]).optional(),
|
|
1327
|
+
gradientTransform: px.string().optional()
|
|
1328
|
+
}));
|
|
1329
|
+
var PxStrokeGradientEffectSchema = PxFillGradientEffectSchema;
|
|
1330
|
+
var PxTextPathEffectSchema = implementsInterface()(px.object({
|
|
1331
|
+
path: px.string(),
|
|
1332
|
+
pathOverflow: px.enum([PxPathOverflow.clip, PxPathOverflow.extend]).optional(),
|
|
1333
|
+
lengthAdjust: px.enum([PxLengthAdjust.spacing, PxLengthAdjust.spacingAndGlyphs]).optional(),
|
|
1334
|
+
method: px.enum([PxTextPathMethod.align, PxTextPathMethod.stretch]).optional(),
|
|
1335
|
+
spacing: px.enum([PxTextPathSpacing.auto, PxTextPathSpacing.exact]).optional(),
|
|
1336
|
+
startOffset: PxAnimatableNumberSchema.optional(),
|
|
1337
|
+
textLength: PxAnimatableNumberSchema.optional()
|
|
1338
|
+
}));
|
|
1339
|
+
var PxTextEffectSchema = implementsInterface()(px.object({
|
|
1340
|
+
useGlyphs: px.boolean().optional()
|
|
1341
|
+
}));
|
|
1342
|
+
var PxEffectsSchema = implementsInterface()(px.object({
|
|
1343
|
+
transformBy: PxTransformByEffectSchema.optional(),
|
|
1344
|
+
repeater: PxRepeaterEffectSchema.optional(),
|
|
1345
|
+
maskedBy: PxMaskedByEffectSchema.optional(),
|
|
1346
|
+
clipPath: PxClipPathEffectSchema.optional(),
|
|
1347
|
+
trimPath: PxTrimPathEffectSchema.optional(),
|
|
1348
|
+
clone: PxCloneEffectSchema.optional(),
|
|
1349
|
+
fillGradient: PxFillGradientEffectSchema.optional(),
|
|
1350
|
+
strokeGradient: PxStrokeGradientEffectSchema.optional(),
|
|
1351
|
+
textPath: PxTextPathEffectSchema.optional(),
|
|
1352
|
+
text: PxTextEffectSchema.optional()
|
|
1353
|
+
}));
|
|
1354
|
+
function validateNodeEffects(root, opts) {
|
|
1355
|
+
const warnings = [];
|
|
1356
|
+
const walk = (node, path) => {
|
|
1357
|
+
if (node && node.effects) {
|
|
1358
|
+
const ctx = { errors: [], warnings: [], strict: !!(opts == null ? void 0 : opts.strict) };
|
|
1359
|
+
const ok = PxEffectsSchema.isValid(node.effects, ctx, [path + ".effects"]);
|
|
1360
|
+
if (!ok) {
|
|
1361
|
+
for (const err of ctx.errors) warnings.push(err);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
if (node && Array.isArray(node.children)) {
|
|
1365
|
+
node.children.forEach((c, i) => walk(c, path + ".children[" + i + "]"));
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
walk(root, "root");
|
|
1369
|
+
return warnings;
|
|
1340
1370
|
}
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1371
|
+
var PxNodeBase = px.openObject({
|
|
1372
|
+
// CONVENTION (SCHEMA-DESIGN R1 / issues N4): `type` is the ONE word for "what
|
|
1373
|
+
// kind of thing is this", discriminated by its CARRIER — here the node TAG
|
|
1374
|
+
// (`rect`, `text`), and inside a sub-object that object's kind (`clone.type`,
|
|
1375
|
+
// `fillGradient.type`, editor `preset.type`). Each sits in its own object, so
|
|
1376
|
+
// the carrier disambiguates completely; synonyms (`cloneKind`, `presetShape`)
|
|
1377
|
+
// would add words that all mean "type" and still need the carrier to read.
|
|
1378
|
+
// Guarding a `type` SLOT against a wrong VALUE is the job of strict enums
|
|
1379
|
+
// (issues V3), never of distinct key names.
|
|
1380
|
+
type: px.string(),
|
|
1381
|
+
id: px.string().optional(),
|
|
1382
|
+
meta: px.any().optional(),
|
|
1383
|
+
// Player-effects bucket emitted by the Editor's lightweight design format.
|
|
1384
|
+
// Consumed and removed by `applyPlayerEffects` before any other normalisation
|
|
1385
|
+
// (see `createAnimatorImpl`), so downstream code never sees it.
|
|
1386
|
+
effects: PxEffectsSchema.optional(),
|
|
1387
|
+
// `PxElementAnimation` (not just `PxAnimationDefinition`) — accepts
|
|
1388
|
+
// string ref / array of refs / inline definition / mixed array; mirrors
|
|
1389
|
+
// `animator.animateById` map values and what `processNode` resolves at runtime.
|
|
1390
|
+
animate: PxElementAnimationSchema.optional(),
|
|
1391
|
+
style: px.union([px.string(), px.record(px.union([px.string(), px.number()]))]).optional()
|
|
1392
|
+
}, PxAttrValueSchema);
|
|
1393
|
+
var PxNodeSchema = px.openObject(__spreadProps2(__spreadValues2({}, PxNodeBase._shape), {
|
|
1394
|
+
children: px.lazy(() => px.array(PxNodeSchema), []).optional()
|
|
1395
|
+
}), PxAttrValueSchema);
|
|
1396
|
+
var PxSvgNodeExtra = px.object({
|
|
1397
|
+
// `"100%"` and other SVG length strings are legal here — a number-only slot rejected
|
|
1398
|
+
// real documents (e.g. apple-store-look-14-main.json) at the root <svg>.
|
|
1399
|
+
width: px.union([px.number(), px.string()]).optional(),
|
|
1400
|
+
height: px.union([px.number(), px.string()]).optional(),
|
|
1401
|
+
viewBox: px.string().optional(),
|
|
1402
|
+
animator: PxAnimatorConfigSchema.optional()
|
|
1403
|
+
});
|
|
1404
|
+
var PxAnimatedSvgDocumentSchema = px.openObject(__spreadProps2(__spreadValues2(__spreadValues2({}, PxNodeBase._shape), PxSvgNodeExtra._shape), {
|
|
1405
|
+
type: px.literal("svg"),
|
|
1406
|
+
// override string → literal to require 'svg'
|
|
1407
|
+
children: px.array(PxNodeSchema).optional()
|
|
1408
|
+
}), PxAttrValueSchema);
|
|
1409
|
+
var PxBezierPathSchema = implementsInterface()(px.object({
|
|
1410
|
+
v: px.array(px.array(px.number())),
|
|
1411
|
+
i: px.array(px.array(px.number())).optional(),
|
|
1412
|
+
o: px.array(px.array(px.number())).optional(),
|
|
1413
|
+
c: px.boolean().optional()
|
|
1414
|
+
}));
|
|
1415
|
+
function isPxElementFileFormatDeep(fileJson) {
|
|
1416
|
+
const valid = PxAnimatedSvgDocumentSchema.isValid(fileJson);
|
|
1417
|
+
return { valid, errors: valid ? [] : ["Document failed schema validation"] };
|
|
1345
1418
|
}
|
|
1346
1419
|
var _idCounter = 0;
|
|
1347
1420
|
function generateUniqueId() {
|
|
@@ -1943,7 +2016,7 @@ function walkAndMaterialise(node, opts) {
|
|
|
1943
2016
|
if (newAnimate) cloned.animate = newAnimate;
|
|
1944
2017
|
return cloned;
|
|
1945
2018
|
}
|
|
1946
|
-
var LOOP_JUMP_SHIFT_MS =
|
|
2019
|
+
var LOOP_JUMP_SHIFT_MS = 1;
|
|
1947
2020
|
function deepEqualValue(a, b) {
|
|
1948
2021
|
if (a === b) return true;
|
|
1949
2022
|
if (typeof a !== typeof b || a === null || b === null || typeof a !== "object") return false;
|
|
@@ -2192,6 +2265,8 @@ function expandLoopKeyframes(propName, keyframes, loop, duration) {
|
|
|
2192
2265
|
const looped = [];
|
|
2193
2266
|
const separateBoundary = loop.extend !== PxLoopExtend.before;
|
|
2194
2267
|
const originalTerminalKf = keyframes[keyframes.length - 1];
|
|
2268
|
+
let terminalEasingOverride;
|
|
2269
|
+
let hasTerminalEasingOverride = false;
|
|
2195
2270
|
function appendRep(repStart, isReversed, partial) {
|
|
2196
2271
|
var _a2;
|
|
2197
2272
|
let entries;
|
|
@@ -2232,7 +2307,16 @@ function expandLoopKeyframes(propName, keyframes, loop, duration) {
|
|
|
2232
2307
|
const prevKf = looped.length > 0 ? looped[looped.length - 1] : originalTerminalKf;
|
|
2233
2308
|
const isBoundary = separateBoundary && i === 0 && prevKf !== void 0 && Math.abs(((_a2 = prevKf.t) != null ? _a2 : 0) - (repStart + entry.relT * segDuration)) < 1e-9;
|
|
2234
2309
|
if (isBoundary) {
|
|
2235
|
-
if (deepEqualValue(prevKf.v, entry.v))
|
|
2310
|
+
if (deepEqualValue(prevKf.v, entry.v)) {
|
|
2311
|
+
if (looped.length > 0) {
|
|
2312
|
+
prevKf.e = entry.e;
|
|
2313
|
+
prevKf.tangentOut = entry.tangentOut;
|
|
2314
|
+
} else {
|
|
2315
|
+
terminalEasingOverride = entry.e;
|
|
2316
|
+
hasTerminalEasingOverride = true;
|
|
2317
|
+
}
|
|
2318
|
+
continue;
|
|
2319
|
+
}
|
|
2236
2320
|
if (looped.length > 0) {
|
|
2237
2321
|
delete prevKf.tangentIn;
|
|
2238
2322
|
delete prevKf.tangentOut;
|
|
@@ -2313,6 +2397,11 @@ function expandLoopKeyframes(propName, keyframes, loop, duration) {
|
|
|
2313
2397
|
if (loop.extend === PxLoopExtend.before) {
|
|
2314
2398
|
return [...looped, ...keyframes];
|
|
2315
2399
|
} else {
|
|
2400
|
+
if (hasTerminalEasingOverride && keyframes.length > 0) {
|
|
2401
|
+
const head = keyframes.slice(0, -1);
|
|
2402
|
+
const tail = __spreadProps2(__spreadValues2({}, keyframes[keyframes.length - 1]), { e: terminalEasingOverride });
|
|
2403
|
+
return [...head, tail, ...looped];
|
|
2404
|
+
}
|
|
2316
2405
|
return [...keyframes, ...looped];
|
|
2317
2406
|
}
|
|
2318
2407
|
}
|
|
@@ -2429,6 +2518,9 @@ function generateElementId() {
|
|
|
2429
2518
|
function normalizeAnimationDefinition(animDef, duration, defs, engine = PxAnimatorEngine.waapi) {
|
|
2430
2519
|
const normalized = {};
|
|
2431
2520
|
for (const [propName, propAnim] of Object.entries(animDef)) {
|
|
2521
|
+
if (propName === "transform" && propAnim.alongPathMode === "offsetPath" && animDef["offsetDistance"] !== void 0) {
|
|
2522
|
+
continue;
|
|
2523
|
+
}
|
|
2432
2524
|
const normalizedKfs = normalizeKeyframes(propName, propAnim, duration, defs);
|
|
2433
2525
|
if (normalizedKfs.length > 0) {
|
|
2434
2526
|
const out = { kfs: normalizedKfs };
|
|
@@ -5240,9 +5332,138 @@ function applyPlayerEffects_retime(node, ctx) {
|
|
|
5240
5332
|
applyAllRetimeEffects(node, ctx);
|
|
5241
5333
|
return node;
|
|
5242
5334
|
}
|
|
5335
|
+
var kfTime = (kf) => {
|
|
5336
|
+
var _a, _b;
|
|
5337
|
+
return (_b = (_a = kf.t) != null ? _a : kf.time) != null ? _b : 0;
|
|
5338
|
+
};
|
|
5339
|
+
var kfValue = (kf) => {
|
|
5340
|
+
var _a;
|
|
5341
|
+
return (_a = kf.v) != null ? _a : kf.value;
|
|
5342
|
+
};
|
|
5343
|
+
var kfEasing = (kf) => {
|
|
5344
|
+
var _a;
|
|
5345
|
+
return (_a = kf.e) != null ? _a : kf.easing;
|
|
5346
|
+
};
|
|
5347
|
+
var kfTangentIn = (kf) => {
|
|
5348
|
+
var _a;
|
|
5349
|
+
return (_a = kf.tangentIn) != null ? _a : kf.ti;
|
|
5350
|
+
};
|
|
5351
|
+
var kfTangentOut = (kf) => {
|
|
5352
|
+
var _a;
|
|
5353
|
+
return (_a = kf.tangentOut) != null ? _a : kf.to;
|
|
5354
|
+
};
|
|
5355
|
+
function cubicAt(p0, c1, c2, p1, t) {
|
|
5356
|
+
const u = 1 - t;
|
|
5357
|
+
const a = u * u * u, b = 3 * u * u * t, c = 3 * u * t * t, d = t * t * t;
|
|
5358
|
+
return [
|
|
5359
|
+
a * p0[0] + b * c1[0] + c * c2[0] + d * p1[0],
|
|
5360
|
+
a * p0[1] + b * c1[1] + c * c2[1] + d * p1[1]
|
|
5361
|
+
];
|
|
5362
|
+
}
|
|
5363
|
+
function cubicLength(p0, c1, c2, p1, steps = 64) {
|
|
5364
|
+
let len = 0;
|
|
5365
|
+
let prev = p0;
|
|
5366
|
+
for (let i = 1; i <= steps; i++) {
|
|
5367
|
+
const pt = cubicAt(p0, c1, c2, p1, i / steps);
|
|
5368
|
+
len += Math.hypot(pt[0] - prev[0], pt[1] - prev[1]);
|
|
5369
|
+
prev = pt;
|
|
5370
|
+
}
|
|
5371
|
+
return len;
|
|
5372
|
+
}
|
|
5373
|
+
var fmt2 = (n) => {
|
|
5374
|
+
const r = Math.round(n * 1e4) / 1e4;
|
|
5375
|
+
return Object.is(r, -0) ? "0" : String(r);
|
|
5376
|
+
};
|
|
5377
|
+
function buildOffsetPath(propAnim) {
|
|
5378
|
+
var _a, _b, _c, _d;
|
|
5379
|
+
if (propAnim.alongPathMode !== "offsetPath") return void 0;
|
|
5380
|
+
const kfs = (_a = propAnim.keyframes) != null ? _a : propAnim.kfs;
|
|
5381
|
+
if (!kfs || kfs.length < 2) return void 0;
|
|
5382
|
+
const first = kfValue(kfs[0]);
|
|
5383
|
+
const anchor = (first == null ? void 0 : first.origin) && first.origin.length >= 2 ? [first.origin[0], first.origin[1]] : [0, 0];
|
|
5384
|
+
const points = [];
|
|
5385
|
+
for (const kf of kfs) {
|
|
5386
|
+
const v = kfValue(kf);
|
|
5387
|
+
const tr = v == null ? void 0 : v.translate;
|
|
5388
|
+
if (!tr || tr.length < 2) return void 0;
|
|
5389
|
+
const parts = Object.keys(v);
|
|
5390
|
+
if (parts.some((p) => p !== "translate" && p !== "origin")) return void 0;
|
|
5391
|
+
const o = (_b = v == null ? void 0 : v.origin) != null ? _b : [0, 0];
|
|
5392
|
+
if (o[0] !== anchor[0] || o[1] !== anchor[1]) return void 0;
|
|
5393
|
+
points.push([tr[0] + anchor[0], tr[1] + anchor[1]]);
|
|
5394
|
+
}
|
|
5395
|
+
if (!kfs.some((kf) => kfTangentIn(kf) || kfTangentOut(kf))) return void 0;
|
|
5396
|
+
let d = "M" + fmt2(points[0][0]) + "," + fmt2(points[0][1]);
|
|
5397
|
+
const segLens = [];
|
|
5398
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
5399
|
+
const p0 = points[i], p1 = points[i + 1];
|
|
5400
|
+
const to = (_c = kfTangentOut(kfs[i])) != null ? _c : [0, 0];
|
|
5401
|
+
const ti = (_d = kfTangentIn(kfs[i + 1])) != null ? _d : [0, 0];
|
|
5402
|
+
const c1 = [p0[0] + to[0], p0[1] + to[1]];
|
|
5403
|
+
const c2 = [p1[0] + ti[0], p1[1] + ti[1]];
|
|
5404
|
+
d += "C" + fmt2(c1[0]) + "," + fmt2(c1[1]) + "," + fmt2(c2[0]) + "," + fmt2(c2[1]) + "," + fmt2(p1[0]) + "," + fmt2(p1[1]);
|
|
5405
|
+
segLens.push(cubicLength(p0, c1, c2, p1));
|
|
5406
|
+
}
|
|
5407
|
+
const total = segLens.reduce((a, b) => a + b, 0);
|
|
5408
|
+
if (!(total > 0)) return void 0;
|
|
5409
|
+
const distanceKfs = [];
|
|
5410
|
+
let cum = 0;
|
|
5411
|
+
for (let i = 0; i < kfs.length; i++) {
|
|
5412
|
+
if (i > 0) cum += segLens[i - 1];
|
|
5413
|
+
const out = { t: kfTime(kfs[i]), v: cum / total };
|
|
5414
|
+
const e = kfEasing(kfs[i]);
|
|
5415
|
+
if (e !== void 0) out.e = e;
|
|
5416
|
+
distanceKfs.push(out);
|
|
5417
|
+
}
|
|
5418
|
+
return { pathStr: d, distanceKfs, autoOrient: !!propAnim.autoOrient, anchor };
|
|
5419
|
+
}
|
|
5420
|
+
function materialiseOffsetPathsInTree(root) {
|
|
5421
|
+
const walk = (node) => {
|
|
5422
|
+
var _a;
|
|
5423
|
+
let out = node;
|
|
5424
|
+
const anim = node.animate;
|
|
5425
|
+
const transform = anim == null ? void 0 : anim["transform"];
|
|
5426
|
+
if (transform) {
|
|
5427
|
+
const built = buildOffsetPath(transform);
|
|
5428
|
+
if (built) {
|
|
5429
|
+
const newAnimate = __spreadValues2({}, anim);
|
|
5430
|
+
delete newAnimate["transform"];
|
|
5431
|
+
const distance = { keyframes: built.distanceKfs };
|
|
5432
|
+
if (transform.loop !== void 0) distance.loop = transform.loop;
|
|
5433
|
+
newAnimate["offsetDistance"] = distance;
|
|
5434
|
+
const staticTr = node.transform;
|
|
5435
|
+
let newTransform = staticTr;
|
|
5436
|
+
if (staticTr && typeof staticTr === "object") {
|
|
5437
|
+
const t = __spreadValues2({}, staticTr);
|
|
5438
|
+
delete t["translate"];
|
|
5439
|
+
delete t["origin"];
|
|
5440
|
+
newTransform = Object.keys(t).length ? t : void 0;
|
|
5441
|
+
}
|
|
5442
|
+
out = __spreadProps2(__spreadValues2({}, node), {
|
|
5443
|
+
animate: newAnimate,
|
|
5444
|
+
style: __spreadProps2(__spreadValues2({}, node.style), {
|
|
5445
|
+
offsetPath: "path('" + built.pathStr + "')",
|
|
5446
|
+
offsetAnchor: fmt2(built.anchor[0]) + "px " + fmt2(built.anchor[1]) + "px",
|
|
5447
|
+
offsetRotate: built.autoOrient ? "auto" : "0deg",
|
|
5448
|
+
offsetDistance: "0%"
|
|
5449
|
+
})
|
|
5450
|
+
});
|
|
5451
|
+
if (newTransform !== void 0) out.transform = newTransform;
|
|
5452
|
+
else delete out.transform;
|
|
5453
|
+
}
|
|
5454
|
+
}
|
|
5455
|
+
if ((_a = out.children) == null ? void 0 : _a.length) {
|
|
5456
|
+
const children = out.children.map(walk);
|
|
5457
|
+
if (children.some((c, i) => c !== out.children[i])) out = __spreadProps2(__spreadValues2({}, out), { children });
|
|
5458
|
+
}
|
|
5459
|
+
return out;
|
|
5460
|
+
};
|
|
5461
|
+
return walk(root);
|
|
5462
|
+
}
|
|
5243
5463
|
function materialiseAllInTree(doc, engine, opts) {
|
|
5244
5464
|
var _a, _b;
|
|
5245
5465
|
let root = applyPlayerEffects(doc).root;
|
|
5466
|
+
root = materialiseOffsetPathsInTree(root);
|
|
5246
5467
|
const duration = (_b = (_a = getAnimatorConfig(root)) == null ? void 0 : _a.duration) != null ? _b : DEFAULT_DURATION_MS;
|
|
5247
5468
|
root = materialiseInternalLoopsInTree(root, duration);
|
|
5248
5469
|
if (engine === PxAnimatorEngine.waapi) {
|
|
@@ -5893,7 +6114,13 @@ function createFrameLoopAnimator(doc, adapter, callbacks, rootElement) {
|
|
|
5893
6114
|
const api = __spreadProps(__spreadValues({}, basicApi), {
|
|
5894
6115
|
"getRootElement": () => rootElement || null
|
|
5895
6116
|
});
|
|
5896
|
-
if (config.trigger)
|
|
6117
|
+
if (config.trigger) {
|
|
6118
|
+
if (isScrollTimeline(config)) {
|
|
6119
|
+
console.warn("scroll timeline: `animator.trigger` is ignored (triggers do not apply to scroll-driven playback)");
|
|
6120
|
+
} else {
|
|
6121
|
+
setupAnimationTriggers(api, config.trigger);
|
|
6122
|
+
}
|
|
6123
|
+
}
|
|
5897
6124
|
return api;
|
|
5898
6125
|
}
|
|
5899
6126
|
function createDomAdapter(rootElement) {
|
|
@@ -5951,6 +6178,8 @@ function createCssKf(kf, t, propName, unsupportedSet) {
|
|
|
5951
6178
|
} else if (propName === "d") {
|
|
5952
6179
|
const paths = value && typeof value === "object" && Array.isArray(value.paths) ? value.paths : [];
|
|
5953
6180
|
cssValue = 'path("' + paths.map((bz) => bezierToSvgPath(bz, true)).join("") + '")';
|
|
6181
|
+
} else if (PCT_BASED_ATTR_NAMES.has(propName) && typeof value === "number") {
|
|
6182
|
+
cssValue = value * 100 + "%";
|
|
5954
6183
|
} else {
|
|
5955
6184
|
cssValue = "" + value;
|
|
5956
6185
|
}
|
|
@@ -6019,7 +6248,7 @@ function convertToWebApiKeyframes(animDef, unsupportedSet, config) {
|
|
|
6019
6248
|
}
|
|
6020
6249
|
return result;
|
|
6021
6250
|
}
|
|
6022
|
-
function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsupportedAttrs) {
|
|
6251
|
+
function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsupportedAttrs, scrollTimeline) {
|
|
6023
6252
|
var _a;
|
|
6024
6253
|
const config = getAnimatorConfig(doc) || {};
|
|
6025
6254
|
if (!rootElement) {
|
|
@@ -6078,7 +6307,12 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
|
|
|
6078
6307
|
if (keyframes.length > 0) {
|
|
6079
6308
|
try {
|
|
6080
6309
|
const effect = new KeyframeEffect(element, keyframes, effectOptions);
|
|
6081
|
-
const anim = new Animation(effect, document.timeline);
|
|
6310
|
+
const anim = new Animation(effect, scrollTimeline ? scrollTimeline.timeline : document.timeline);
|
|
6311
|
+
if (scrollTimeline) {
|
|
6312
|
+
const a = anim;
|
|
6313
|
+
if (scrollTimeline.rangeStart) a.rangeStart = scrollTimeline.rangeStart;
|
|
6314
|
+
if (scrollTimeline.rangeEnd) a.rangeEnd = scrollTimeline.rangeEnd;
|
|
6315
|
+
}
|
|
6082
6316
|
if (callbacks == null ? void 0 : callbacks.onFinish) anim.onfinish = () => {
|
|
6083
6317
|
var _a2;
|
|
6084
6318
|
if (finishNotified) return;
|
|
@@ -6172,11 +6406,136 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
|
|
|
6172
6406
|
}
|
|
6173
6407
|
};
|
|
6174
6408
|
if (config.trigger) {
|
|
6175
|
-
|
|
6409
|
+
if (config.timelineSource === "scroll") {
|
|
6410
|
+
console.warn("scroll timeline: `animator.trigger` is ignored (triggers do not apply to scroll-driven playback)");
|
|
6411
|
+
} else {
|
|
6412
|
+
setupAnimationTriggers(api, config.trigger);
|
|
6413
|
+
}
|
|
6414
|
+
}
|
|
6415
|
+
if (scrollTimeline) {
|
|
6416
|
+
animations.forEach((a) => a.play());
|
|
6176
6417
|
}
|
|
6177
6418
|
return api;
|
|
6178
6419
|
}
|
|
6179
6420
|
|
|
6421
|
+
// src/PxScrollDriver.ts
|
|
6422
|
+
function nativeRangeOffset(point, defaultFraction, view) {
|
|
6423
|
+
var _a, _b, _c;
|
|
6424
|
+
const fraction = typeof (point == null ? void 0 : point.fraction) === "number" ? point.fraction : defaultFraction;
|
|
6425
|
+
const pct = (_b = (_a = globalThis.CSS) == null ? void 0 : _a.percent) == null ? void 0 : _b.call(_a, fraction * 100);
|
|
6426
|
+
if (pct === void 0) return void 0;
|
|
6427
|
+
return view ? { rangeName: (_c = point == null ? void 0 : point.phase) != null ? _c : "cover", offset: pct } : { offset: pct };
|
|
6428
|
+
}
|
|
6429
|
+
function createNativeScrollTimeline(subject, config) {
|
|
6430
|
+
var _a, _b, _c, _d;
|
|
6431
|
+
if (!config || !isScrollTimeline(config)) return null;
|
|
6432
|
+
const scroll = config.scroll || {};
|
|
6433
|
+
const kind = (_a = scroll.kind) != null ? _a : "view";
|
|
6434
|
+
const g = globalThis;
|
|
6435
|
+
const view = kind === "view";
|
|
6436
|
+
const Ctor = view ? g.ViewTimeline : g.ScrollTimeline;
|
|
6437
|
+
if (typeof Ctor !== "function") return null;
|
|
6438
|
+
const axis = (_b = scroll.axis) != null ? _b : "block";
|
|
6439
|
+
let timeline;
|
|
6440
|
+
try {
|
|
6441
|
+
if (view) {
|
|
6442
|
+
timeline = new Ctor({ subject, axis });
|
|
6443
|
+
} else {
|
|
6444
|
+
const source = scroll.source === "root" ? documentScroller() : findNearestScroller(subject, "y") || findNearestScroller(subject, "x") || documentScroller();
|
|
6445
|
+
timeline = new Ctor({ source, axis });
|
|
6446
|
+
}
|
|
6447
|
+
} catch (e) {
|
|
6448
|
+
console.warn("scroll timeline: native timeline construction failed \u2014 falling back to the custom driver", e);
|
|
6449
|
+
return null;
|
|
6450
|
+
}
|
|
6451
|
+
return {
|
|
6452
|
+
timeline,
|
|
6453
|
+
rangeStart: nativeRangeOffset((_c = scroll.range) == null ? void 0 : _c.start, 0, view),
|
|
6454
|
+
rangeEnd: nativeRangeOffset((_d = scroll.range) == null ? void 0 : _d.end, 1, view)
|
|
6455
|
+
};
|
|
6456
|
+
}
|
|
6457
|
+
function findNearestScroller(el, axis) {
|
|
6458
|
+
for (let p = el.parentElement; p; p = p.parentElement) {
|
|
6459
|
+
const style = getComputedStyle(p);
|
|
6460
|
+
const overflow = axis === "y" ? style.overflowY : style.overflowX;
|
|
6461
|
+
if (overflow === "auto" || overflow === "scroll" || overflow === "hidden" || overflow === "overlay") {
|
|
6462
|
+
return p;
|
|
6463
|
+
}
|
|
6464
|
+
}
|
|
6465
|
+
return null;
|
|
6466
|
+
}
|
|
6467
|
+
function documentScroller() {
|
|
6468
|
+
return document.scrollingElement || document.documentElement;
|
|
6469
|
+
}
|
|
6470
|
+
function createScrollDriver(subject, config, onProgress) {
|
|
6471
|
+
var _a;
|
|
6472
|
+
if (!config || !isScrollTimeline(config)) return null;
|
|
6473
|
+
const scroll = config.scroll || {};
|
|
6474
|
+
const kind = (_a = scroll.kind) != null ? _a : "view";
|
|
6475
|
+
const nearest = findNearestScroller(subject, "y") || findNearestScroller(subject, "x");
|
|
6476
|
+
const scroller = kind === "scroll" && scroll.source === "root" ? documentScroller() : nearest || documentScroller();
|
|
6477
|
+
const isRootScroller = scroller === documentScroller();
|
|
6478
|
+
const axis = scrollResolveAxis(scroll.axis, getComputedStyle(scroller).writingMode);
|
|
6479
|
+
const compute = () => {
|
|
6480
|
+
if (kind === "scroll") {
|
|
6481
|
+
const offset = axis === "y" ? scroller.scrollTop : scroller.scrollLeft;
|
|
6482
|
+
const maxOffset = axis === "y" ? scroller.scrollHeight - scroller.clientHeight : scroller.scrollWidth - scroller.clientWidth;
|
|
6483
|
+
return scrollOffsetProgress(offset, maxOffset, scroll.range);
|
|
6484
|
+
}
|
|
6485
|
+
const subjectRect = subject.getBoundingClientRect();
|
|
6486
|
+
let portStart, portSize;
|
|
6487
|
+
if (isRootScroller) {
|
|
6488
|
+
portStart = 0;
|
|
6489
|
+
portSize = axis === "y" ? document.documentElement.clientHeight : document.documentElement.clientWidth;
|
|
6490
|
+
} else {
|
|
6491
|
+
const portRect = scroller.getBoundingClientRect();
|
|
6492
|
+
portStart = axis === "y" ? portRect.top : portRect.left;
|
|
6493
|
+
portSize = axis === "y" ? scroller.clientHeight : scroller.clientWidth;
|
|
6494
|
+
}
|
|
6495
|
+
const subjectStart = (axis === "y" ? subjectRect.top : subjectRect.left) - portStart;
|
|
6496
|
+
const subjectSize = axis === "y" ? subjectRect.height : subjectRect.width;
|
|
6497
|
+
return scrollViewProgress(subjectStart, subjectSize, portSize, scroll.range);
|
|
6498
|
+
};
|
|
6499
|
+
let rafId = null;
|
|
6500
|
+
let destroyed = false;
|
|
6501
|
+
const tick = () => {
|
|
6502
|
+
rafId = null;
|
|
6503
|
+
if (destroyed) return;
|
|
6504
|
+
onProgress(compute());
|
|
6505
|
+
};
|
|
6506
|
+
const schedule = () => {
|
|
6507
|
+
if (destroyed || rafId !== null) return;
|
|
6508
|
+
rafId = requestAnimationFrame(tick);
|
|
6509
|
+
};
|
|
6510
|
+
const scrollTarget = isRootScroller ? window : scroller;
|
|
6511
|
+
scrollTarget.addEventListener("scroll", schedule, { passive: true });
|
|
6512
|
+
window.addEventListener("resize", schedule, { passive: true });
|
|
6513
|
+
let resizeObserver;
|
|
6514
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
6515
|
+
resizeObserver = new ResizeObserver(schedule);
|
|
6516
|
+
resizeObserver.observe(subject);
|
|
6517
|
+
if (!isRootScroller) resizeObserver.observe(scroller);
|
|
6518
|
+
}
|
|
6519
|
+
const driver = {
|
|
6520
|
+
destroy: () => {
|
|
6521
|
+
if (destroyed) return;
|
|
6522
|
+
destroyed = true;
|
|
6523
|
+
scrollTarget.removeEventListener("scroll", schedule);
|
|
6524
|
+
window.removeEventListener("resize", schedule);
|
|
6525
|
+
resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
6526
|
+
if (rafId !== null) {
|
|
6527
|
+
cancelAnimationFrame(rafId);
|
|
6528
|
+
rafId = null;
|
|
6529
|
+
}
|
|
6530
|
+
},
|
|
6531
|
+
refresh: () => {
|
|
6532
|
+
if (!destroyed) onProgress(compute());
|
|
6533
|
+
}
|
|
6534
|
+
};
|
|
6535
|
+
driver.refresh();
|
|
6536
|
+
return driver;
|
|
6537
|
+
}
|
|
6538
|
+
|
|
6180
6539
|
// src/PxAnimatorBind.ts
|
|
6181
6540
|
function finaliseAnimator(animatorConfig, callbacks, make) {
|
|
6182
6541
|
let apiRef;
|
|
@@ -6199,6 +6558,44 @@ function finaliseAnimator(animatorConfig, callbacks, make) {
|
|
|
6199
6558
|
}
|
|
6200
6559
|
function bindWithEngineChoice(doc, adapter, callbacks, rootElement) {
|
|
6201
6560
|
const animatorConfig = getAnimatorConfig(doc) || {};
|
|
6561
|
+
if (isScrollTimeline(animatorConfig)) {
|
|
6562
|
+
return finaliseAnimator(animatorConfig, callbacks, (cb) => {
|
|
6563
|
+
var _a, _b;
|
|
6564
|
+
if (animatorConfig.mode !== PxAnimatorMode.frames && ((_a = animatorConfig.scroll) == null ? void 0 : _a.driver) === "native" && rootElement) {
|
|
6565
|
+
const native = createNativeScrollTimeline(rootElement, animatorConfig);
|
|
6566
|
+
if (native) {
|
|
6567
|
+
const api2 = createWebApiAnimator(
|
|
6568
|
+
doc,
|
|
6569
|
+
cb,
|
|
6570
|
+
rootElement,
|
|
6571
|
+
animatorConfig.mode === PxAnimatorMode.waapi,
|
|
6572
|
+
native
|
|
6573
|
+
);
|
|
6574
|
+
if (api2) return api2;
|
|
6575
|
+
}
|
|
6576
|
+
}
|
|
6577
|
+
const api = (animatorConfig.mode !== PxAnimatorMode.frames ? createWebApiAnimator(doc, cb, rootElement, animatorConfig.mode === PxAnimatorMode.waapi) : null) || createFrameLoopAnimator(doc, adapter, cb, rootElement);
|
|
6578
|
+
const subject = ((_b = api.getRootElement) == null ? void 0 : _b.call(api)) || rootElement;
|
|
6579
|
+
if (subject) {
|
|
6580
|
+
const totalMs = scrollTotalDurationMs(animatorConfig);
|
|
6581
|
+
const driver = createScrollDriver(
|
|
6582
|
+
subject,
|
|
6583
|
+
animatorConfig,
|
|
6584
|
+
(progress) => api.setCurrentTime(progress * totalMs)
|
|
6585
|
+
);
|
|
6586
|
+
if (driver) {
|
|
6587
|
+
const destroy = api.destroy.bind(api);
|
|
6588
|
+
api.destroy = () => {
|
|
6589
|
+
driver.destroy();
|
|
6590
|
+
destroy();
|
|
6591
|
+
};
|
|
6592
|
+
}
|
|
6593
|
+
} else {
|
|
6594
|
+
console.warn("scroll timeline: no root element to observe \u2014 animation will stay at frame 0");
|
|
6595
|
+
}
|
|
6596
|
+
return api;
|
|
6597
|
+
});
|
|
6598
|
+
}
|
|
6202
6599
|
return finaliseAnimator(animatorConfig, callbacks, (cb) => {
|
|
6203
6600
|
if (animatorConfig.mode === PxAnimatorMode.frames) {
|
|
6204
6601
|
return createFrameLoopAnimator(doc, adapter, cb, rootElement);
|