@pixodesk/svg-animator-web 1.0.26 → 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 CHANGED
@@ -172,114 +172,582 @@ var __objRest2 = (source, exclude) => {
172
172
  }
173
173
  return target;
174
174
  };
175
- function pathStr(path) {
176
- if (!path.length) return ".";
177
- let result = "";
178
- for (const seg of path) {
179
- if (seg.startsWith("[")) result += seg;
180
- else result += (result ? "." : "") + seg;
181
- }
182
- return result;
183
- }
184
- var Base = class {
185
- _canSanitize(raw) {
186
- return this.isValid(raw);
175
+ function bezierToSvgPath(path, forceCurves = false) {
176
+ var _a, _b, _c, _d;
177
+ const v = path.v;
178
+ const i = path.i;
179
+ const o = path.o;
180
+ const c = path.c;
181
+ if (!v.length) return "";
182
+ const d = [];
183
+ const len = v.length;
184
+ d.push("M" + v[0][0] + "," + v[0][1]);
185
+ for (let idx = 1; idx < len; idx++) {
186
+ const prevV = v[idx - 1];
187
+ const prevO = (_a = o == null ? void 0 : o[idx - 1]) != null ? _a : prevV;
188
+ const currI = (_b = i == null ? void 0 : i[idx]) != null ? _b : v[idx];
189
+ const currV = v[idx];
190
+ const isLine = !forceCurves && (prevO[0] === prevV[0] && prevO[1] === prevV[1]) && (currI[0] === currV[0] && currI[1] === currV[1]);
191
+ if (isLine) {
192
+ d.push("L" + currV[0] + "," + currV[1]);
193
+ } else {
194
+ d.push("C" + prevO[0] + "," + prevO[1] + "," + currI[0] + "," + currI[1] + "," + currV[0] + "," + currV[1]);
195
+ }
187
196
  }
188
- optional() {
189
- return new Optional(this);
197
+ if (c && len > 0) {
198
+ const lastV = v[len - 1];
199
+ const lastO = (_c = o == null ? void 0 : o[len - 1]) != null ? _c : lastV;
200
+ const firstI = (_d = i == null ? void 0 : i[0]) != null ? _d : v[0];
201
+ const firstV = v[0];
202
+ const isLine = !forceCurves && (lastO[0] === lastV[0] && lastO[1] === lastV[1]) && (firstI[0] === firstV[0] && firstI[1] === firstV[1]);
203
+ if (!isLine) {
204
+ d.push("C" + lastO[0] + "," + lastO[1] + "," + firstI[0] + "," + firstI[1] + "," + firstV[0] + "," + firstV[1]);
205
+ }
206
+ d.push("z");
190
207
  }
191
- };
192
- var Optional = class extends Base {
193
- constructor(inner) {
194
- super();
195
- this.inner = inner;
196
- this._default = void 0;
208
+ return d.join("");
209
+ }
210
+ function interpolateNum(a, b, t) {
211
+ return a + (b - a) * t;
212
+ }
213
+ function interpolateVec(a, b, t) {
214
+ const res = [];
215
+ const count = Math.max(a.length, b.length);
216
+ for (let i = 0; i < count; i++) {
217
+ res[i] = interpolateNum(a[i] || 0, b[i] || 0, t);
197
218
  }
198
- sanitize(raw) {
199
- if (raw === void 0 || raw === null) return void 0;
200
- return this.inner._canSanitize(raw) ? this.inner.sanitize(raw) : void 0;
219
+ return res;
220
+ }
221
+ function interpolateColor(a, b, t) {
222
+ return [
223
+ interpolateNum(a[0] || 0, b[0] || 0, t),
224
+ interpolateNum(a[1] || 0, b[1] || 0, t),
225
+ interpolateNum(a[2] || 0, b[2] || 0, t),
226
+ interpolateNum(a[3] === void 0 ? 1 : a[3], b[3] === void 0 ? 1 : b[3], t)
227
+ ];
228
+ }
229
+ function interpolateBeziers(paths1, paths2, progress) {
230
+ const count = Math.max(paths1.length, paths2.length);
231
+ const res = [];
232
+ for (let i = 0; i < count; i++) {
233
+ res.push(interpolateBezier(paths1[i], paths2[i], progress));
201
234
  }
202
- isValid(raw, ctx, path) {
203
- if (raw === void 0 || raw === null) return true;
204
- return this.inner.isValid(raw, ctx, path);
235
+ return res;
236
+ }
237
+ function interpolateBezier(path1, path2, progress) {
238
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
239
+ if (!path1 || !path2) return path1 || path2 || { v: [] };
240
+ const t = Math.min(Math.max(progress, 0), 1);
241
+ const len = Math.min(path1.v.length, path2.v.length);
242
+ const v = [];
243
+ const i = [];
244
+ const o = [];
245
+ for (let idx = 0; idx < len; idx++) {
246
+ const v1 = path1.v[idx];
247
+ const v2 = path2.v[idx];
248
+ v.push(interpolateVec(v1, v2, t));
249
+ const i1 = (_b = (_a = path1.i) == null ? void 0 : _a[idx]) != null ? _b : v1;
250
+ const i2 = (_d = (_c = path2.i) == null ? void 0 : _c[idx]) != null ? _d : v2;
251
+ i.push(interpolateVec(i1, i2, t));
252
+ const o1 = (_f = (_e = path1.o) == null ? void 0 : _e[idx]) != null ? _f : v1;
253
+ const o2 = (_h = (_g = path2.o) == null ? void 0 : _g[idx]) != null ? _h : v2;
254
+ o.push(interpolateVec(o1, o2, t));
205
255
  }
206
- _canSanitize(raw) {
207
- return raw === void 0 || raw === null || this.inner._canSanitize(raw);
256
+ return { v, i: i.length ? i : void 0, o: o.length ? o : void 0, c: (_i = path1.c) != null ? _i : path2.c };
257
+ }
258
+ function remap(value, inMin, inMax, outMin, outMax) {
259
+ if (inMax === inMin) return outMin;
260
+ const t = (value - inMin) / (inMax - inMin);
261
+ return outMin + t * (outMax - outMin);
262
+ }
263
+ function solveCubicBezierX(p1x, p2x, x) {
264
+ if (x <= 0) return 0;
265
+ if (x >= 1) return 1;
266
+ const cx = 3 * p1x;
267
+ const bx = 3 * (p2x - p1x) - cx;
268
+ const ax = 1 - cx - bx;
269
+ function sampleX(t) {
270
+ return ((ax * t + bx) * t + cx) * t;
208
271
  }
209
- };
210
- var Str = class extends Base {
211
- constructor(_default = "") {
212
- super();
213
- this._default = _default;
272
+ function sampleDX(t) {
273
+ return (3 * ax * t + 2 * bx) * t + cx;
214
274
  }
215
- sanitize(raw) {
216
- return typeof raw === "string" ? raw : this._default;
275
+ let t2 = x;
276
+ let t0 = 0;
277
+ let t1 = 1;
278
+ for (let i = 0; i < 8; i++) {
279
+ const x2 = sampleX(t2) - x;
280
+ if (Math.abs(x2) < 1e-6) return t2;
281
+ const d2 = sampleDX(t2);
282
+ if (Math.abs(d2) < 1e-6) break;
283
+ t2 -= x2 / d2;
217
284
  }
218
- isValid(raw, ctx, path) {
219
- if (typeof raw === "string") return true;
220
- ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected string, got " + typeof raw);
221
- return false;
285
+ t2 = x;
286
+ while (t0 < t1) {
287
+ const x2 = sampleX(t2);
288
+ if (Math.abs(x2 - x) < 1e-6) return t2;
289
+ if (x > x2) t0 = t2;
290
+ else t1 = t2;
291
+ t2 = (t1 + t0) / 2;
222
292
  }
223
- };
224
- var Num = class extends Base {
225
- constructor(_default = 0) {
226
- super();
227
- this._default = _default;
293
+ return t2;
294
+ }
295
+ function cubicBezier(easing) {
296
+ const [p1x, p1y, p2x, p2y] = easing;
297
+ const cy = 3 * p1y;
298
+ const by = 3 * (p2y - p1y) - cy;
299
+ const ay = 1 - cy - by;
300
+ function sampleCurveY(t) {
301
+ return ((ay * t + by) * t + cy) * t;
228
302
  }
229
- sanitize(raw) {
230
- return typeof raw === "number" && isFinite(raw) ? raw : this._default;
303
+ return function(x) {
304
+ return sampleCurveY(solveCubicBezierX(p1x, p2x, x));
305
+ };
306
+ }
307
+ function lerp2(a, b, t) {
308
+ return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
309
+ }
310
+ function subdivideCubicBezier(p0, p1, p2, p3, t) {
311
+ const q0 = lerp2(p0, p1, t);
312
+ const q1 = lerp2(p1, p2, t);
313
+ const q2 = lerp2(p2, p3, t);
314
+ const r0 = lerp2(q0, q1, t);
315
+ const r1 = lerp2(q1, q2, t);
316
+ const s = lerp2(r0, r1, t);
317
+ return {
318
+ left: [p0, q0, r0, s],
319
+ right: [s, r1, q2, p3]
320
+ };
321
+ }
322
+ function splitEasing(easing, xFraction) {
323
+ if (!easing) return { left: void 0, right: void 0 };
324
+ if (xFraction <= 0) return { left: void 0, right: easing };
325
+ if (xFraction >= 1) return { left: easing, right: void 0 };
326
+ const [x1, y1, x2, y2] = easing;
327
+ const t = solveCubicBezierX(x1, x2, xFraction);
328
+ const p0 = [0, 0];
329
+ const p1 = [x1, y1];
330
+ const p2 = [x2, y2];
331
+ const p3 = [1, 1];
332
+ const { left, right } = subdivideCubicBezier(p0, p1, p2, p3, t);
333
+ const sx = left[3][0];
334
+ const sy = left[3][1];
335
+ let leftEasing;
336
+ if (sx > 1e-9 && Math.abs(sy) > 1e-9) {
337
+ leftEasing = [
338
+ left[1][0] / sx,
339
+ left[1][1] / sy,
340
+ left[2][0] / sx,
341
+ left[2][1] / sy
342
+ ];
231
343
  }
232
- isValid(raw, ctx, path) {
233
- if (typeof raw === "number" && isFinite(raw)) return true;
234
- ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected finite number, got " + JSON.stringify(raw));
235
- return false;
344
+ let rightEasing;
345
+ const rx = 1 - sx;
346
+ const ry = 1 - sy;
347
+ if (rx > 1e-9 && Math.abs(ry) > 1e-9) {
348
+ rightEasing = [
349
+ (right[1][0] - sx) / rx,
350
+ (right[1][1] - sy) / ry,
351
+ (right[2][0] - sx) / rx,
352
+ (right[2][1] - sy) / ry
353
+ ];
236
354
  }
237
- };
238
- var Bool = class extends Base {
239
- constructor(_default = false) {
240
- super();
241
- this._default = _default;
355
+ return { left: leftEasing, right: rightEasing };
356
+ }
357
+ function reverseEasing(easing) {
358
+ if (!easing) return void 0;
359
+ return [1 - easing[2], 1 - easing[3], 1 - easing[0], 1 - easing[1]];
360
+ }
361
+ function toRGBA(color) {
362
+ const r = Math.round(color[0] * 255);
363
+ const g = Math.round(color[1] * 255);
364
+ const b = Math.round(color[2] * 255);
365
+ return color.length === 4 ? "rgba(" + r + "," + g + "," + b + "," + color[3] + ")" : "rgb(" + r + "," + g + "," + b + ")";
366
+ }
367
+ function parseRgba(s) {
368
+ var _a;
369
+ const inner = (_a = s.match(/rgba?\((.*)\)/)) == null ? void 0 : _a[1];
370
+ if (!inner) throw new Error("Invalid rgb/rgba format");
371
+ const parts = inner.split(",").map((v) => +v.trim());
372
+ return [parts[0] / 255, parts[1] / 255, parts[2] / 255, ...parts[3] !== void 0 ? [parts[3]] : []];
373
+ }
374
+ function parseHex(s) {
375
+ const hex = s.slice(1);
376
+ const isShort = hex.length <= 4;
377
+ const r = isShort ? hex[0] + hex[0] : hex.slice(0, 2);
378
+ const g = isShort ? hex[1] + hex[1] : hex.slice(2, 4);
379
+ const b = isShort ? hex[2] + hex[2] : hex.slice(4, 6);
380
+ const a = hex.length === 4 ? hex[3] + hex[3] : hex.length === 8 ? hex.slice(6, 8) : null;
381
+ const result = [
382
+ parseInt(r, 16) / 255,
383
+ parseInt(g, 16) / 255,
384
+ parseInt(b, 16) / 255
385
+ ];
386
+ if (a !== null) {
387
+ result.push(parseInt(a, 16) / 255);
242
388
  }
243
- sanitize(raw) {
244
- return typeof raw === "boolean" ? raw : this._default;
389
+ return result;
390
+ }
391
+ function parseColor(s) {
392
+ if (!s) return void 0;
393
+ if (Array.isArray(s)) return s;
394
+ if (typeof s !== "string") return void 0;
395
+ if (s.startsWith("#")) {
396
+ return parseHex(s);
397
+ } else if (s.startsWith("rgb")) {
398
+ return parseRgba(s);
399
+ } else {
400
+ console.warn("Unsupported color format: " + s);
245
401
  }
246
- isValid(raw, ctx, path) {
247
- if (typeof raw === "boolean") return true;
248
- ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected boolean, got " + typeof raw);
249
- return false;
402
+ return void 0;
403
+ }
404
+ var COLOUR_ATTR_NAMES = /* @__PURE__ */ new Set(["color", "fill", "flood-color", "lighting-color", "stop-color", "stroke"]);
405
+ var TRANSFORM_FN_NAMES = /* @__PURE__ */ new Set(["translate", "rotate", "scale", "skew"]);
406
+ var PCT_BASED_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
407
+ function composeTransformParts(parts, opts) {
408
+ var _a;
409
+ if (!parts) return "";
410
+ const withUnits = (_a = opts == null ? void 0 : opts.withUnits) != null ? _a : true;
411
+ const segs = [];
412
+ const t = parts.translate;
413
+ const o = parts.origin;
414
+ const r = parts.rotate;
415
+ const k = parts.skew;
416
+ const s = parts.scale;
417
+ const tu = withUnits ? "px" : "";
418
+ const ru = withUnits ? "deg" : "";
419
+ if (t) segs.push("translate(" + t[0] + tu + "," + t[1] + tu + ")");
420
+ if (o) segs.push("translate(" + o[0] + tu + "," + o[1] + tu + ")");
421
+ if (r !== void 0 && r !== null) segs.push("rotate(" + r + ru + ")");
422
+ if (k !== void 0 && k !== null) segs.push("skewX(" + k + ru + ")");
423
+ if (s) segs.push("scale(" + s[0] + "," + s[1] + ")");
424
+ if (o) segs.push("translate(" + -o[0] + tu + "," + -o[1] + tu + ")");
425
+ return segs.join("");
426
+ }
427
+ var STYLE_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
428
+ var DEFAULT_DURATION_MS = 1e3;
429
+ function kebabToCamelCaseWord(kebab) {
430
+ return kebab.includes("-") ? kebab.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) : kebab;
431
+ }
432
+ function isCamelCaseWord(word) {
433
+ return !word.includes("-") && /[a-z][A-Z]/.test(word);
434
+ }
435
+ var SVG_CAMEL_CASE_ATTRS = /* @__PURE__ */ new Set([
436
+ // Transform/positioning
437
+ "viewBox",
438
+ "preserveAspectRatio",
439
+ // Gradient
440
+ "gradientUnits",
441
+ "gradientTransform",
442
+ "spreadMethod",
443
+ // Pattern
444
+ "patternUnits",
445
+ "patternContentUnits",
446
+ "patternTransform",
447
+ // Clipping/masking
448
+ "clipPathUnits",
449
+ "maskUnits",
450
+ "maskContentUnits",
451
+ // Marker (SVG spec keeps these camelCase, like viewBox)
452
+ "markerUnits",
453
+ "markerWidth",
454
+ "markerHeight",
455
+ "refX",
456
+ "refY",
457
+ // Text
458
+ "textLength",
459
+ "lengthAdjust",
460
+ "startOffset",
461
+ // Filter
462
+ "filterUnits",
463
+ "primitiveUnits",
464
+ "tableValues",
465
+ // feFuncR/G/B/A transfer table (type="table")
466
+ "stdDeviation",
467
+ "baseFrequency",
468
+ "numOctaves",
469
+ "surfaceScale",
470
+ "diffuseConstant",
471
+ "specularConstant",
472
+ "specularExponent",
473
+ "kernelMatrix",
474
+ "kernelUnitLength",
475
+ "edgeMode",
476
+ "preserveAlpha",
477
+ "targetX",
478
+ "targetY"
479
+ // // Animation
480
+ // 'attributeName',
481
+ // 'attributeType',
482
+ // 'calcMode',
483
+ // 'keyTimes',
484
+ // 'keySplines',
485
+ // 'repeatCount',
486
+ // 'repeatDur'
487
+ ]);
488
+ function camelCaseToKebabWordIfNeeded(camel) {
489
+ return SVG_CAMEL_CASE_ATTRS.has(camel) ? camel : camel.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
490
+ }
491
+ function clamp(value, min, max) {
492
+ return Math.max(min, Math.min(value, max));
493
+ }
494
+ function bezier2D_pointAt(P0, P1, P2, P3, t) {
495
+ if (t <= 0) return [P0[0], P0[1]];
496
+ if (t >= 1) return [P3[0], P3[1]];
497
+ const u = 1 - t;
498
+ const u2 = u * u;
499
+ const u3 = u2 * u;
500
+ const t2 = t * t;
501
+ const t3 = t2 * t;
502
+ const w0 = u3;
503
+ const w1 = 3 * t * u2;
504
+ const w2 = 3 * t2 * u;
505
+ const w3 = t3;
506
+ return [
507
+ w0 * P0[0] + w1 * P1[0] + w2 * P2[0] + w3 * P3[0],
508
+ w0 * P0[1] + w1 * P1[1] + w2 * P2[1] + w3 * P3[1]
509
+ ];
510
+ }
511
+ var BEZIER_T_NUDGE = 1e-4;
512
+ function bezier2D_derivativeAt(P0, P1, P2, P3, t) {
513
+ const result = _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t);
514
+ if (result[0] === 0 && result[1] === 0) {
515
+ const nudgedT = t < 0.5 ? t + BEZIER_T_NUDGE : t - BEZIER_T_NUDGE;
516
+ return _bezier2D_derivativeAtRaw(P0, P1, P2, P3, nudgedT);
517
+ }
518
+ return result;
519
+ }
520
+ function _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t) {
521
+ const u = 1 - t;
522
+ const a = 3 * u * u;
523
+ const b = 6 * t * u;
524
+ const c = 3 * t * t;
525
+ return [
526
+ a * (P1[0] - P0[0]) + b * (P2[0] - P1[0]) + c * (P3[0] - P2[0]),
527
+ a * (P1[1] - P0[1]) + b * (P2[1] - P1[1]) + c * (P3[1] - P2[1])
528
+ ];
529
+ }
530
+ function bezier2D_arcLengthLUT(P0, P1, P2, P3, steps = 100) {
531
+ const n = steps + 1;
532
+ const ts = new Float64Array(n);
533
+ const ds = new Float64Array(n);
534
+ let prev = bezier2D_pointAt(P0, P1, P2, P3, 0);
535
+ ts[0] = 0;
536
+ ds[0] = 0;
537
+ let cum = 0;
538
+ for (let i = 1; i < n; i++) {
539
+ const t = i / steps;
540
+ const cur = bezier2D_pointAt(P0, P1, P2, P3, t);
541
+ const dx = cur[0] - prev[0];
542
+ const dy = cur[1] - prev[1];
543
+ cum += Math.sqrt(dx * dx + dy * dy);
544
+ ts[i] = t;
545
+ ds[i] = cum;
546
+ prev = cur;
547
+ }
548
+ return { ts, ds };
549
+ }
550
+ function bezier2D_tForDistance(lut, distance) {
551
+ const { ts, ds } = lut;
552
+ const last = ds.length - 1;
553
+ if (distance <= 0) return ts[0];
554
+ if (distance >= ds[last]) return ts[last];
555
+ let lo = 1;
556
+ let hi = last;
557
+ while (lo < hi) {
558
+ const mid = lo + hi >>> 1;
559
+ if (ds[mid] < distance) lo = mid + 1;
560
+ else hi = mid;
561
+ }
562
+ const dPrev = ds[hi - 1];
563
+ const dCur = ds[hi];
564
+ const span = dCur - dPrev;
565
+ const frac = span > 0 ? (distance - dPrev) / span : 0;
566
+ return ts[hi - 1] + frac * (ts[hi] - ts[hi - 1]);
567
+ }
568
+ function bezier2D_arcAtT(lut, t) {
569
+ const { ts, ds } = lut;
570
+ const last = ts.length - 1;
571
+ if (t <= ts[0]) return ds[0];
572
+ if (t >= ts[last]) return ds[last];
573
+ let lo = 1, hi = last;
574
+ while (lo < hi) {
575
+ const mid = lo + hi >>> 1;
576
+ if (ts[mid] < t) lo = mid + 1;
577
+ else hi = mid;
578
+ }
579
+ const tPrev = ts[hi - 1];
580
+ const span = ts[hi] - tPrev;
581
+ const frac = span > 0 ? (t - tPrev) / span : 0;
582
+ return ds[hi - 1] + frac * (ds[hi] - ds[hi - 1]);
583
+ }
584
+ function invertEasing(easing) {
585
+ if (!easing) return (y) => y;
586
+ const flipped = [easing[1], easing[0], easing[3], easing[2]];
587
+ return cubicBezier(flipped);
588
+ }
589
+ function isScrollTimeline(config) {
590
+ return (config == null ? void 0 : config.timelineSource) === "scroll";
591
+ }
592
+ function scrollTotalDurationMs(config) {
593
+ const duration = typeof (config == null ? void 0 : config.duration) === "number" && config.duration > 0 ? config.duration : DEFAULT_DURATION_MS;
594
+ const iterations = typeof (config == null ? void 0 : config.iterations) === "number" && config.iterations > 0 ? config.iterations : 1;
595
+ return duration * iterations;
596
+ }
597
+ function scrollPhaseInterval(phase, subjectSize, scrollportSize) {
598
+ const s = subjectSize, vp = scrollportSize;
599
+ switch (phase) {
600
+ case "cover":
601
+ return [0, s + vp];
602
+ case "entry":
603
+ return [0, Math.min(s, vp)];
604
+ case "contain":
605
+ return [Math.min(s, vp), Math.max(s, vp)];
606
+ case "exit":
607
+ return [Math.max(s, vp), s + vp];
608
+ case "entry-crossing":
609
+ return [0, s];
610
+ case "exit-crossing":
611
+ return [vp, s + vp];
612
+ }
613
+ }
614
+ var DEFAULT_PHASE = "cover";
615
+ function resolveRangePointU(point, defaultFraction, subjectSize, scrollportSize) {
616
+ var _a;
617
+ const [u0, u1] = scrollPhaseInterval((_a = point == null ? void 0 : point.phase) != null ? _a : DEFAULT_PHASE, subjectSize, scrollportSize);
618
+ const fraction = typeof (point == null ? void 0 : point.fraction) === "number" ? point.fraction : defaultFraction;
619
+ return u0 + fraction * (u1 - u0);
620
+ }
621
+ function scrollViewProgress(subjectStart, subjectSize, scrollportSize, range) {
622
+ const u = scrollportSize - subjectStart;
623
+ const uStart = resolveRangePointU(range == null ? void 0 : range.start, 0, subjectSize, scrollportSize);
624
+ const uEnd = resolveRangePointU(range == null ? void 0 : range.end, 1, subjectSize, scrollportSize);
625
+ if (uEnd <= uStart) return u >= uEnd ? 1 : 0;
626
+ return clamp((u - uStart) / (uEnd - uStart), 0, 1);
627
+ }
628
+ function scrollOffsetProgress(offset, maxOffset, range) {
629
+ var _a, _b;
630
+ const raw = maxOffset > 0 ? clamp(offset / maxOffset, 0, 1) : 1;
631
+ const start = typeof ((_a = range == null ? void 0 : range.start) == null ? void 0 : _a.fraction) === "number" ? range.start.fraction : 0;
632
+ const end = typeof ((_b = range == null ? void 0 : range.end) == null ? void 0 : _b.fraction) === "number" ? range.end.fraction : 1;
633
+ if (end <= start) return raw >= end ? 1 : 0;
634
+ return clamp((raw - start) / (end - start), 0, 1);
635
+ }
636
+ function scrollResolveAxis(axis, writingMode) {
637
+ const a = axis != null ? axis : "block";
638
+ if (a === "x" || a === "y") return a;
639
+ const vertical = !!writingMode && writingMode.startsWith("vertical");
640
+ if (a === "inline") return vertical ? "y" : "x";
641
+ return vertical ? "x" : "y";
642
+ }
643
+ function pathStr(path) {
644
+ if (!path.length) return ".";
645
+ let result = "";
646
+ for (const seg of path) {
647
+ if (seg.startsWith("[")) result += seg;
648
+ else result += (result ? "." : "") + seg;
649
+ }
650
+ return result;
651
+ }
652
+ var Base = class {
653
+ _canSanitize(raw) {
654
+ return this.isValid(raw);
655
+ }
656
+ optional() {
657
+ return new Optional(this);
250
658
  }
251
659
  };
252
- var Literal = class extends Base {
253
- constructor(value) {
660
+ var Optional = class extends Base {
661
+ constructor(inner) {
254
662
  super();
255
- this.value = value;
256
- this._default = value;
663
+ this.inner = inner;
664
+ this._default = void 0;
257
665
  }
258
666
  sanitize(raw) {
259
- return raw === this.value ? this.value : this._default;
667
+ if (raw === void 0 || raw === null) return void 0;
668
+ return this.inner._canSanitize(raw) ? this.inner.sanitize(raw) : void 0;
260
669
  }
261
670
  isValid(raw, ctx, path) {
262
- if (raw === this.value) return true;
263
- ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected " + JSON.stringify(this.value) + ", got " + JSON.stringify(raw));
264
- return false;
671
+ if (raw === void 0 || raw === null) return true;
672
+ return this.inner.isValid(raw, ctx, path);
673
+ }
674
+ _canSanitize(raw) {
675
+ return raw === void 0 || raw === null || this.inner._canSanitize(raw);
265
676
  }
266
677
  };
267
- var Enum = class extends Base {
268
- constructor(values, defaultVal) {
678
+ var Str = class extends Base {
679
+ constructor(_default = "") {
269
680
  super();
270
- this.values = values;
271
- this._default = defaultVal != null ? defaultVal : values[0];
681
+ this._default = _default;
272
682
  }
273
683
  sanitize(raw) {
274
- return this.values.includes(raw) ? raw : this._default;
684
+ return typeof raw === "string" ? raw : this._default;
275
685
  }
276
686
  isValid(raw, ctx, path) {
277
- if (this.values.includes(raw)) return true;
278
- 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));
687
+ if (typeof raw === "string") return true;
688
+ ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected string, got " + typeof raw);
279
689
  return false;
280
690
  }
281
691
  };
282
- var Union = class extends Base {
692
+ var Num = class extends Base {
693
+ constructor(_default = 0) {
694
+ super();
695
+ this._default = _default;
696
+ }
697
+ sanitize(raw) {
698
+ return typeof raw === "number" && isFinite(raw) ? raw : this._default;
699
+ }
700
+ isValid(raw, ctx, path) {
701
+ if (typeof raw === "number" && isFinite(raw)) return true;
702
+ ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected finite number, got " + JSON.stringify(raw));
703
+ return false;
704
+ }
705
+ };
706
+ var Bool = class extends Base {
707
+ constructor(_default = false) {
708
+ super();
709
+ this._default = _default;
710
+ }
711
+ sanitize(raw) {
712
+ return typeof raw === "boolean" ? raw : this._default;
713
+ }
714
+ isValid(raw, ctx, path) {
715
+ if (typeof raw === "boolean") return true;
716
+ ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected boolean, got " + typeof raw);
717
+ return false;
718
+ }
719
+ };
720
+ var Literal = class extends Base {
721
+ constructor(value) {
722
+ super();
723
+ this.value = value;
724
+ this._default = value;
725
+ }
726
+ sanitize(raw) {
727
+ return raw === this.value ? this.value : this._default;
728
+ }
729
+ isValid(raw, ctx, path) {
730
+ if (raw === this.value) return true;
731
+ ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected " + JSON.stringify(this.value) + ", got " + JSON.stringify(raw));
732
+ return false;
733
+ }
734
+ };
735
+ var Enum = class extends Base {
736
+ constructor(values, defaultVal) {
737
+ super();
738
+ this.values = values;
739
+ this._default = defaultVal != null ? defaultVal : values[0];
740
+ }
741
+ sanitize(raw) {
742
+ return this.values.includes(raw) ? raw : this._default;
743
+ }
744
+ isValid(raw, ctx, path) {
745
+ if (this.values.includes(raw)) return true;
746
+ 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));
747
+ return false;
748
+ }
749
+ };
750
+ var Union = class extends Base {
283
751
  constructor(schemas, defaultVal) {
284
752
  super();
285
753
  this.schemas = schemas;
@@ -834,6 +1302,22 @@ var PxDefsSchema = implementsInterface()(px.object({
834
1302
  styles: px.record(px.any()).optional(),
835
1303
  glyphs: px.record(PxGlyphFontSchema).optional()
836
1304
  }));
1305
+ var PX_SCROLL_PHASES = ["cover", "contain", "entry", "exit", "entry-crossing", "exit-crossing"];
1306
+ var PxScrollRangePointSchema = implementsInterface()(px.object({
1307
+ phase: px.enum(PX_SCROLL_PHASES).optional(),
1308
+ fraction: px.number().optional()
1309
+ }));
1310
+ var PxScrollRangeSchema = px.object({
1311
+ start: PxScrollRangePointSchema.optional(),
1312
+ end: PxScrollRangePointSchema.optional()
1313
+ });
1314
+ var PxScrollSchema = implementsInterface()(px.object({
1315
+ driver: px.enum(["custom", "native"]).optional(),
1316
+ kind: px.enum(["view", "scroll"]).optional(),
1317
+ axis: px.enum(["block", "inline", "x", "y"]).optional(),
1318
+ source: px.enum(["nearest", "root"]).optional(),
1319
+ range: PxScrollRangeSchema.optional()
1320
+ }));
837
1321
  var PxAnimatorConfigSchema = implementsInterface()(px.object({
838
1322
  mode: px.enum([PxAnimatorMode.auto, PxAnimatorMode.waapi, PxAnimatorMode.frames]).optional(),
839
1323
  duration: px.number().optional(),
@@ -849,6 +1333,7 @@ var PxAnimatorConfigSchema = implementsInterface()(px.object({
849
1333
  definitions: PxDefsSchema.optional(),
850
1334
  animateById: px.record(PxElementAnimationSchema).optional(),
851
1335
  timelineSource: px.string().optional(),
1336
+ scroll: PxScrollSchema.optional(),
852
1337
  debugInstName: px.string().optional()
853
1338
  }));
854
1339
  var PxBindingSchema = implementsInterface()(px.object({
@@ -928,531 +1413,117 @@ var PxCloneEffectSchema = implementsInterface()(px.object({
928
1413
  sourceId: px.string().optional(),
929
1414
  retime: PxRetimeEffectSchema.optional()
930
1415
  }));
931
- var PxGradientStopSchema = implementsInterface()(px.object({
932
- offset: px.number(),
933
- color: px.string()
934
- }));
935
- var PxAnimatableGradientStopsSchema = px.union([
936
- px.array(PxGradientStopSchema),
937
- px.object({ value: px.array(PxGradientStopSchema) }),
938
- PxPropertyAnimationSchema
939
- ]);
940
- var PxFillGradientEffectSchema = implementsInterface()(px.object({
941
- // Contextual kind — the `type` convention, see `PxNodeBase.type`.
942
- type: px.enum([PxGradientType.linear, PxGradientType.radial]),
943
- p1: PxAnimatableVec2Schema.optional(),
944
- p2: PxAnimatableVec2Schema.optional(),
945
- c: PxAnimatableVec2Schema.optional(),
946
- r: PxAnimatableNumberSchema.optional(),
947
- fp: PxAnimatableVec2Schema.optional(),
948
- stops: PxAnimatableGradientStopsSchema.optional(),
949
- gradientUnits: px.enum([PxGradientUnits.userSpaceOnUse, PxGradientUnits.objectBoundingBox]).optional(),
950
- spreadMethod: px.enum([PxGradientSpreadMethod.pad, PxGradientSpreadMethod.reflect, PxGradientSpreadMethod.repeat]).optional(),
951
- gradientTransform: px.string().optional()
952
- }));
953
- var PxStrokeGradientEffectSchema = PxFillGradientEffectSchema;
954
- var PxTextPathEffectSchema = implementsInterface()(px.object({
955
- path: px.string(),
956
- pathOverflow: px.enum([PxPathOverflow.clip, PxPathOverflow.extend]).optional(),
957
- lengthAdjust: px.enum([PxLengthAdjust.spacing, PxLengthAdjust.spacingAndGlyphs]).optional(),
958
- method: px.enum([PxTextPathMethod.align, PxTextPathMethod.stretch]).optional(),
959
- spacing: px.enum([PxTextPathSpacing.auto, PxTextPathSpacing.exact]).optional(),
960
- startOffset: PxAnimatableNumberSchema.optional(),
961
- textLength: PxAnimatableNumberSchema.optional()
962
- }));
963
- var PxTextEffectSchema = implementsInterface()(px.object({
964
- useGlyphs: px.boolean().optional()
965
- }));
966
- var PxEffectsSchema = implementsInterface()(px.object({
967
- transformBy: PxTransformByEffectSchema.optional(),
968
- repeater: PxRepeaterEffectSchema.optional(),
969
- maskedBy: PxMaskedByEffectSchema.optional(),
970
- clipPath: PxClipPathEffectSchema.optional(),
971
- trimPath: PxTrimPathEffectSchema.optional(),
972
- clone: PxCloneEffectSchema.optional(),
973
- fillGradient: PxFillGradientEffectSchema.optional(),
974
- strokeGradient: PxStrokeGradientEffectSchema.optional(),
975
- textPath: PxTextPathEffectSchema.optional(),
976
- text: PxTextEffectSchema.optional()
977
- }));
978
- function validateNodeEffects(root, opts) {
979
- const warnings = [];
980
- const walk = (node, path) => {
981
- if (node && node.effects) {
982
- const ctx = { errors: [], warnings: [], strict: !!(opts == null ? void 0 : opts.strict) };
983
- const ok = PxEffectsSchema.isValid(node.effects, ctx, [path + ".effects"]);
984
- if (!ok) {
985
- for (const err of ctx.errors) warnings.push(err);
986
- }
987
- }
988
- if (node && Array.isArray(node.children)) {
989
- node.children.forEach((c, i) => walk(c, path + ".children[" + i + "]"));
990
- }
991
- };
992
- walk(root, "root");
993
- return warnings;
994
- }
995
- var PxNodeBase = px.openObject({
996
- // CONVENTION (SCHEMA-DESIGN R1 / issues N4): `type` is the ONE word for "what
997
- // kind of thing is this", discriminated by its CARRIER — here the node TAG
998
- // (`rect`, `text`), and inside a sub-object that object's kind (`clone.type`,
999
- // `fillGradient.type`, editor `preset.type`). Each sits in its own object, so
1000
- // the carrier disambiguates completely; synonyms (`cloneKind`, `presetShape`)
1001
- // would add words that all mean "type" and still need the carrier to read.
1002
- // Guarding a `type` SLOT against a wrong VALUE is the job of strict enums
1003
- // (issues V3), never of distinct key names.
1004
- type: px.string(),
1005
- id: px.string().optional(),
1006
- meta: px.any().optional(),
1007
- // Player-effects bucket emitted by the Editor's lightweight design format.
1008
- // Consumed and removed by `applyPlayerEffects` before any other normalisation
1009
- // (see `createAnimatorImpl`), so downstream code never sees it.
1010
- effects: PxEffectsSchema.optional(),
1011
- // `PxElementAnimation` (not just `PxAnimationDefinition`) — accepts
1012
- // string ref / array of refs / inline definition / mixed array; mirrors
1013
- // `animator.animateById` map values and what `processNode` resolves at runtime.
1014
- animate: PxElementAnimationSchema.optional(),
1015
- style: px.union([px.string(), px.record(px.union([px.string(), px.number()]))]).optional()
1016
- }, PxAttrValueSchema);
1017
- var PxNodeSchema = px.openObject(__spreadProps2(__spreadValues2({}, PxNodeBase._shape), {
1018
- children: px.lazy(() => px.array(PxNodeSchema), []).optional()
1019
- }), PxAttrValueSchema);
1020
- var PxSvgNodeExtra = px.object({
1021
- // `"100%"` and other SVG length strings are legal here — a number-only slot rejected
1022
- // real documents (e.g. apple-store-look-14-main.json) at the root <svg>.
1023
- width: px.union([px.number(), px.string()]).optional(),
1024
- height: px.union([px.number(), px.string()]).optional(),
1025
- viewBox: px.string().optional(),
1026
- animator: PxAnimatorConfigSchema.optional()
1027
- });
1028
- var PxAnimatedSvgDocumentSchema = px.openObject(__spreadProps2(__spreadValues2(__spreadValues2({}, PxNodeBase._shape), PxSvgNodeExtra._shape), {
1029
- type: px.literal("svg"),
1030
- // override string → literal to require 'svg'
1031
- children: px.array(PxNodeSchema).optional()
1032
- }), PxAttrValueSchema);
1033
- var PxBezierPathSchema = implementsInterface()(px.object({
1034
- v: px.array(px.array(px.number())),
1035
- i: px.array(px.array(px.number())).optional(),
1036
- o: px.array(px.array(px.number())).optional(),
1037
- c: px.boolean().optional()
1038
- }));
1039
- function isPxElementFileFormatDeep(fileJson) {
1040
- const valid = PxAnimatedSvgDocumentSchema.isValid(fileJson);
1041
- return { valid, errors: valid ? [] : ["Document failed schema validation"] };
1042
- }
1043
- function bezierToSvgPath(path, forceCurves = false) {
1044
- var _a, _b, _c, _d;
1045
- const v = path.v;
1046
- const i = path.i;
1047
- const o = path.o;
1048
- const c = path.c;
1049
- if (!v.length) return "";
1050
- const d = [];
1051
- const len = v.length;
1052
- d.push("M" + v[0][0] + "," + v[0][1]);
1053
- for (let idx = 1; idx < len; idx++) {
1054
- const prevV = v[idx - 1];
1055
- const prevO = (_a = o == null ? void 0 : o[idx - 1]) != null ? _a : prevV;
1056
- const currI = (_b = i == null ? void 0 : i[idx]) != null ? _b : v[idx];
1057
- const currV = v[idx];
1058
- const isLine = !forceCurves && (prevO[0] === prevV[0] && prevO[1] === prevV[1]) && (currI[0] === currV[0] && currI[1] === currV[1]);
1059
- if (isLine) {
1060
- d.push("L" + currV[0] + "," + currV[1]);
1061
- } else {
1062
- d.push("C" + prevO[0] + "," + prevO[1] + "," + currI[0] + "," + currI[1] + "," + currV[0] + "," + currV[1]);
1063
- }
1064
- }
1065
- if (c && len > 0) {
1066
- const lastV = v[len - 1];
1067
- const lastO = (_c = o == null ? void 0 : o[len - 1]) != null ? _c : lastV;
1068
- const firstI = (_d = i == null ? void 0 : i[0]) != null ? _d : v[0];
1069
- const firstV = v[0];
1070
- const isLine = !forceCurves && (lastO[0] === lastV[0] && lastO[1] === lastV[1]) && (firstI[0] === firstV[0] && firstI[1] === firstV[1]);
1071
- if (!isLine) {
1072
- d.push("C" + lastO[0] + "," + lastO[1] + "," + firstI[0] + "," + firstI[1] + "," + firstV[0] + "," + firstV[1]);
1073
- }
1074
- d.push("z");
1075
- }
1076
- return d.join("");
1077
- }
1078
- function interpolateNum(a, b, t) {
1079
- return a + (b - a) * t;
1080
- }
1081
- function interpolateVec(a, b, t) {
1082
- const res = [];
1083
- const count = Math.max(a.length, b.length);
1084
- for (let i = 0; i < count; i++) {
1085
- res[i] = interpolateNum(a[i] || 0, b[i] || 0, t);
1086
- }
1087
- return res;
1088
- }
1089
- function interpolateColor(a, b, t) {
1090
- return [
1091
- interpolateNum(a[0] || 0, b[0] || 0, t),
1092
- interpolateNum(a[1] || 0, b[1] || 0, t),
1093
- interpolateNum(a[2] || 0, b[2] || 0, t),
1094
- interpolateNum(a[3] === void 0 ? 1 : a[3], b[3] === void 0 ? 1 : b[3], t)
1095
- ];
1096
- }
1097
- function interpolateBeziers(paths1, paths2, progress) {
1098
- const count = Math.max(paths1.length, paths2.length);
1099
- const res = [];
1100
- for (let i = 0; i < count; i++) {
1101
- res.push(interpolateBezier(paths1[i], paths2[i], progress));
1102
- }
1103
- return res;
1104
- }
1105
- function interpolateBezier(path1, path2, progress) {
1106
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1107
- if (!path1 || !path2) return path1 || path2 || { v: [] };
1108
- const t = Math.min(Math.max(progress, 0), 1);
1109
- const len = Math.min(path1.v.length, path2.v.length);
1110
- const v = [];
1111
- const i = [];
1112
- const o = [];
1113
- for (let idx = 0; idx < len; idx++) {
1114
- const v1 = path1.v[idx];
1115
- const v2 = path2.v[idx];
1116
- v.push(interpolateVec(v1, v2, t));
1117
- const i1 = (_b = (_a = path1.i) == null ? void 0 : _a[idx]) != null ? _b : v1;
1118
- const i2 = (_d = (_c = path2.i) == null ? void 0 : _c[idx]) != null ? _d : v2;
1119
- i.push(interpolateVec(i1, i2, t));
1120
- const o1 = (_f = (_e = path1.o) == null ? void 0 : _e[idx]) != null ? _f : v1;
1121
- const o2 = (_h = (_g = path2.o) == null ? void 0 : _g[idx]) != null ? _h : v2;
1122
- o.push(interpolateVec(o1, o2, t));
1123
- }
1124
- return { v, i: i.length ? i : void 0, o: o.length ? o : void 0, c: (_i = path1.c) != null ? _i : path2.c };
1125
- }
1126
- function remap(value, inMin, inMax, outMin, outMax) {
1127
- if (inMax === inMin) return outMin;
1128
- const t = (value - inMin) / (inMax - inMin);
1129
- return outMin + t * (outMax - outMin);
1130
- }
1131
- function solveCubicBezierX(p1x, p2x, x) {
1132
- if (x <= 0) return 0;
1133
- if (x >= 1) return 1;
1134
- const cx = 3 * p1x;
1135
- const bx = 3 * (p2x - p1x) - cx;
1136
- const ax = 1 - cx - bx;
1137
- function sampleX(t) {
1138
- return ((ax * t + bx) * t + cx) * t;
1139
- }
1140
- function sampleDX(t) {
1141
- return (3 * ax * t + 2 * bx) * t + cx;
1142
- }
1143
- let t2 = x;
1144
- let t0 = 0;
1145
- let t1 = 1;
1146
- for (let i = 0; i < 8; i++) {
1147
- const x2 = sampleX(t2) - x;
1148
- if (Math.abs(x2) < 1e-6) return t2;
1149
- const d2 = sampleDX(t2);
1150
- if (Math.abs(d2) < 1e-6) break;
1151
- t2 -= x2 / d2;
1152
- }
1153
- t2 = x;
1154
- while (t0 < t1) {
1155
- const x2 = sampleX(t2);
1156
- if (Math.abs(x2 - x) < 1e-6) return t2;
1157
- if (x > x2) t0 = t2;
1158
- else t1 = t2;
1159
- t2 = (t1 + t0) / 2;
1160
- }
1161
- return t2;
1162
- }
1163
- function cubicBezier(easing) {
1164
- const [p1x, p1y, p2x, p2y] = easing;
1165
- const cy = 3 * p1y;
1166
- const by = 3 * (p2y - p1y) - cy;
1167
- const ay = 1 - cy - by;
1168
- function sampleCurveY(t) {
1169
- return ((ay * t + by) * t + cy) * t;
1170
- }
1171
- return function(x) {
1172
- return sampleCurveY(solveCubicBezierX(p1x, p2x, x));
1173
- };
1174
- }
1175
- function lerp2(a, b, t) {
1176
- return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
1177
- }
1178
- function subdivideCubicBezier(p0, p1, p2, p3, t) {
1179
- const q0 = lerp2(p0, p1, t);
1180
- const q1 = lerp2(p1, p2, t);
1181
- const q2 = lerp2(p2, p3, t);
1182
- const r0 = lerp2(q0, q1, t);
1183
- const r1 = lerp2(q1, q2, t);
1184
- const s = lerp2(r0, r1, t);
1185
- return {
1186
- left: [p0, q0, r0, s],
1187
- right: [s, r1, q2, p3]
1188
- };
1189
- }
1190
- function splitEasing(easing, xFraction) {
1191
- if (!easing) return { left: void 0, right: void 0 };
1192
- if (xFraction <= 0) return { left: void 0, right: easing };
1193
- if (xFraction >= 1) return { left: easing, right: void 0 };
1194
- const [x1, y1, x2, y2] = easing;
1195
- const t = solveCubicBezierX(x1, x2, xFraction);
1196
- const p0 = [0, 0];
1197
- const p1 = [x1, y1];
1198
- const p2 = [x2, y2];
1199
- const p3 = [1, 1];
1200
- const { left, right } = subdivideCubicBezier(p0, p1, p2, p3, t);
1201
- const sx = left[3][0];
1202
- const sy = left[3][1];
1203
- let leftEasing;
1204
- if (sx > 1e-9 && Math.abs(sy) > 1e-9) {
1205
- leftEasing = [
1206
- left[1][0] / sx,
1207
- left[1][1] / sy,
1208
- left[2][0] / sx,
1209
- left[2][1] / sy
1210
- ];
1211
- }
1212
- let rightEasing;
1213
- const rx = 1 - sx;
1214
- const ry = 1 - sy;
1215
- if (rx > 1e-9 && Math.abs(ry) > 1e-9) {
1216
- rightEasing = [
1217
- (right[1][0] - sx) / rx,
1218
- (right[1][1] - sy) / ry,
1219
- (right[2][0] - sx) / rx,
1220
- (right[2][1] - sy) / ry
1221
- ];
1222
- }
1223
- return { left: leftEasing, right: rightEasing };
1224
- }
1225
- function reverseEasing(easing) {
1226
- if (!easing) return void 0;
1227
- return [1 - easing[2], 1 - easing[3], 1 - easing[0], 1 - easing[1]];
1228
- }
1229
- function toRGBA(color) {
1230
- const r = Math.round(color[0] * 255);
1231
- const g = Math.round(color[1] * 255);
1232
- const b = Math.round(color[2] * 255);
1233
- return color.length === 4 ? "rgba(" + r + "," + g + "," + b + "," + color[3] + ")" : "rgb(" + r + "," + g + "," + b + ")";
1234
- }
1235
- function parseRgba(s) {
1236
- var _a;
1237
- const inner = (_a = s.match(/rgba?\((.*)\)/)) == null ? void 0 : _a[1];
1238
- if (!inner) throw new Error("Invalid rgb/rgba format");
1239
- const parts = inner.split(",").map((v) => +v.trim());
1240
- return [parts[0] / 255, parts[1] / 255, parts[2] / 255, ...parts[3] !== void 0 ? [parts[3]] : []];
1241
- }
1242
- function parseHex(s) {
1243
- const hex = s.slice(1);
1244
- const isShort = hex.length <= 4;
1245
- const r = isShort ? hex[0] + hex[0] : hex.slice(0, 2);
1246
- const g = isShort ? hex[1] + hex[1] : hex.slice(2, 4);
1247
- const b = isShort ? hex[2] + hex[2] : hex.slice(4, 6);
1248
- const a = hex.length === 4 ? hex[3] + hex[3] : hex.length === 8 ? hex.slice(6, 8) : null;
1249
- const result = [
1250
- parseInt(r, 16) / 255,
1251
- parseInt(g, 16) / 255,
1252
- parseInt(b, 16) / 255
1253
- ];
1254
- if (a !== null) {
1255
- result.push(parseInt(a, 16) / 255);
1256
- }
1257
- return result;
1258
- }
1259
- function parseColor(s) {
1260
- if (!s) return void 0;
1261
- if (Array.isArray(s)) return s;
1262
- if (typeof s !== "string") return void 0;
1263
- if (s.startsWith("#")) {
1264
- return parseHex(s);
1265
- } else if (s.startsWith("rgb")) {
1266
- return parseRgba(s);
1267
- } else {
1268
- console.warn("Unsupported color format: " + s);
1269
- }
1270
- return void 0;
1271
- }
1272
- var COLOUR_ATTR_NAMES = /* @__PURE__ */ new Set(["color", "fill", "flood-color", "lighting-color", "stop-color", "stroke"]);
1273
- var TRANSFORM_FN_NAMES = /* @__PURE__ */ new Set(["translate", "rotate", "scale", "skew"]);
1274
- var PCT_BASED_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
1275
- function composeTransformParts(parts, opts) {
1276
- var _a;
1277
- if (!parts) return "";
1278
- const withUnits = (_a = opts == null ? void 0 : opts.withUnits) != null ? _a : true;
1279
- const segs = [];
1280
- const t = parts.translate;
1281
- const o = parts.origin;
1282
- const r = parts.rotate;
1283
- const k = parts.skew;
1284
- const s = parts.scale;
1285
- const tu = withUnits ? "px" : "";
1286
- const ru = withUnits ? "deg" : "";
1287
- if (t) segs.push("translate(" + t[0] + tu + "," + t[1] + tu + ")");
1288
- if (o) segs.push("translate(" + o[0] + tu + "," + o[1] + tu + ")");
1289
- if (r !== void 0 && r !== null) segs.push("rotate(" + r + ru + ")");
1290
- if (k !== void 0 && k !== null) segs.push("skewX(" + k + ru + ")");
1291
- if (s) segs.push("scale(" + s[0] + "," + s[1] + ")");
1292
- if (o) segs.push("translate(" + -o[0] + tu + "," + -o[1] + tu + ")");
1293
- return segs.join("");
1294
- }
1295
- var STYLE_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
1296
- var DEFAULT_DURATION_MS = 1e3;
1297
- function kebabToCamelCaseWord(kebab) {
1298
- return kebab.includes("-") ? kebab.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) : kebab;
1299
- }
1300
- function isCamelCaseWord(word) {
1301
- return !word.includes("-") && /[a-z][A-Z]/.test(word);
1302
- }
1303
- var SVG_CAMEL_CASE_ATTRS = /* @__PURE__ */ new Set([
1304
- // Transform/positioning
1305
- "viewBox",
1306
- "preserveAspectRatio",
1307
- // Gradient
1308
- "gradientUnits",
1309
- "gradientTransform",
1310
- "spreadMethod",
1311
- // Pattern
1312
- "patternUnits",
1313
- "patternContentUnits",
1314
- "patternTransform",
1315
- // Clipping/masking
1316
- "clipPathUnits",
1317
- "maskUnits",
1318
- "maskContentUnits",
1319
- // Marker (SVG spec keeps these camelCase, like viewBox)
1320
- "markerUnits",
1321
- "markerWidth",
1322
- "markerHeight",
1323
- "refX",
1324
- "refY",
1325
- // Text
1326
- "textLength",
1327
- "lengthAdjust",
1328
- "startOffset",
1329
- // Filter
1330
- "filterUnits",
1331
- "primitiveUnits",
1332
- "tableValues",
1333
- // feFuncR/G/B/A transfer table (type="table")
1334
- "stdDeviation",
1335
- "baseFrequency",
1336
- "numOctaves",
1337
- "surfaceScale",
1338
- "diffuseConstant",
1339
- "specularConstant",
1340
- "specularExponent",
1341
- "kernelMatrix",
1342
- "kernelUnitLength",
1343
- "edgeMode",
1344
- "preserveAlpha",
1345
- "targetX",
1346
- "targetY"
1347
- // // Animation
1348
- // 'attributeName',
1349
- // 'attributeType',
1350
- // 'calcMode',
1351
- // 'keyTimes',
1352
- // 'keySplines',
1353
- // 'repeatCount',
1354
- // 'repeatDur'
1416
+ var PxGradientStopSchema = implementsInterface()(px.object({
1417
+ offset: px.number(),
1418
+ color: px.string()
1419
+ }));
1420
+ var PxAnimatableGradientStopsSchema = px.union([
1421
+ px.array(PxGradientStopSchema),
1422
+ px.object({ value: px.array(PxGradientStopSchema) }),
1423
+ PxPropertyAnimationSchema
1355
1424
  ]);
1356
- function camelCaseToKebabWordIfNeeded(camel) {
1357
- return SVG_CAMEL_CASE_ATTRS.has(camel) ? camel : camel.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
1358
- }
1359
- function clamp(value, min, max) {
1360
- return Math.max(min, Math.min(value, max));
1361
- }
1362
- function bezier2D_pointAt(P0, P1, P2, P3, t) {
1363
- if (t <= 0) return [P0[0], P0[1]];
1364
- if (t >= 1) return [P3[0], P3[1]];
1365
- const u = 1 - t;
1366
- const u2 = u * u;
1367
- const u3 = u2 * u;
1368
- const t2 = t * t;
1369
- const t3 = t2 * t;
1370
- const w0 = u3;
1371
- const w1 = 3 * t * u2;
1372
- const w2 = 3 * t2 * u;
1373
- const w3 = t3;
1374
- return [
1375
- w0 * P0[0] + w1 * P1[0] + w2 * P2[0] + w3 * P3[0],
1376
- w0 * P0[1] + w1 * P1[1] + w2 * P2[1] + w3 * P3[1]
1377
- ];
1378
- }
1379
- var BEZIER_T_NUDGE = 1e-4;
1380
- function bezier2D_derivativeAt(P0, P1, P2, P3, t) {
1381
- const result = _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t);
1382
- if (result[0] === 0 && result[1] === 0) {
1383
- const nudgedT = t < 0.5 ? t + BEZIER_T_NUDGE : t - BEZIER_T_NUDGE;
1384
- return _bezier2D_derivativeAtRaw(P0, P1, P2, P3, nudgedT);
1385
- }
1386
- return result;
1387
- }
1388
- function _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t) {
1389
- const u = 1 - t;
1390
- const a = 3 * u * u;
1391
- const b = 6 * t * u;
1392
- const c = 3 * t * t;
1393
- return [
1394
- a * (P1[0] - P0[0]) + b * (P2[0] - P1[0]) + c * (P3[0] - P2[0]),
1395
- a * (P1[1] - P0[1]) + b * (P2[1] - P1[1]) + c * (P3[1] - P2[1])
1396
- ];
1397
- }
1398
- function bezier2D_arcLengthLUT(P0, P1, P2, P3, steps = 100) {
1399
- const n = steps + 1;
1400
- const ts = new Float64Array(n);
1401
- const ds = new Float64Array(n);
1402
- let prev = bezier2D_pointAt(P0, P1, P2, P3, 0);
1403
- ts[0] = 0;
1404
- ds[0] = 0;
1405
- let cum = 0;
1406
- for (let i = 1; i < n; i++) {
1407
- const t = i / steps;
1408
- const cur = bezier2D_pointAt(P0, P1, P2, P3, t);
1409
- const dx = cur[0] - prev[0];
1410
- const dy = cur[1] - prev[1];
1411
- cum += Math.sqrt(dx * dx + dy * dy);
1412
- ts[i] = t;
1413
- ds[i] = cum;
1414
- prev = cur;
1415
- }
1416
- return { ts, ds };
1417
- }
1418
- function bezier2D_tForDistance(lut, distance) {
1419
- const { ts, ds } = lut;
1420
- const last = ds.length - 1;
1421
- if (distance <= 0) return ts[0];
1422
- if (distance >= ds[last]) return ts[last];
1423
- let lo = 1;
1424
- let hi = last;
1425
- while (lo < hi) {
1426
- const mid = lo + hi >>> 1;
1427
- if (ds[mid] < distance) lo = mid + 1;
1428
- else hi = mid;
1429
- }
1430
- const dPrev = ds[hi - 1];
1431
- const dCur = ds[hi];
1432
- const span = dCur - dPrev;
1433
- const frac = span > 0 ? (distance - dPrev) / span : 0;
1434
- return ts[hi - 1] + frac * (ts[hi] - ts[hi - 1]);
1435
- }
1436
- function bezier2D_arcAtT(lut, t) {
1437
- const { ts, ds } = lut;
1438
- const last = ts.length - 1;
1439
- if (t <= ts[0]) return ds[0];
1440
- if (t >= ts[last]) return ds[last];
1441
- let lo = 1, hi = last;
1442
- while (lo < hi) {
1443
- const mid = lo + hi >>> 1;
1444
- if (ts[mid] < t) lo = mid + 1;
1445
- else hi = mid;
1446
- }
1447
- const tPrev = ts[hi - 1];
1448
- const span = ts[hi] - tPrev;
1449
- const frac = span > 0 ? (t - tPrev) / span : 0;
1450
- return ds[hi - 1] + frac * (ds[hi] - ds[hi - 1]);
1425
+ var PxFillGradientEffectSchema = implementsInterface()(px.object({
1426
+ // Contextual kind the `type` convention, see `PxNodeBase.type`.
1427
+ type: px.enum([PxGradientType.linear, PxGradientType.radial]),
1428
+ p1: PxAnimatableVec2Schema.optional(),
1429
+ p2: PxAnimatableVec2Schema.optional(),
1430
+ c: PxAnimatableVec2Schema.optional(),
1431
+ r: PxAnimatableNumberSchema.optional(),
1432
+ fp: PxAnimatableVec2Schema.optional(),
1433
+ stops: PxAnimatableGradientStopsSchema.optional(),
1434
+ gradientUnits: px.enum([PxGradientUnits.userSpaceOnUse, PxGradientUnits.objectBoundingBox]).optional(),
1435
+ spreadMethod: px.enum([PxGradientSpreadMethod.pad, PxGradientSpreadMethod.reflect, PxGradientSpreadMethod.repeat]).optional(),
1436
+ gradientTransform: px.string().optional()
1437
+ }));
1438
+ var PxStrokeGradientEffectSchema = PxFillGradientEffectSchema;
1439
+ var PxTextPathEffectSchema = implementsInterface()(px.object({
1440
+ path: px.string(),
1441
+ pathOverflow: px.enum([PxPathOverflow.clip, PxPathOverflow.extend]).optional(),
1442
+ lengthAdjust: px.enum([PxLengthAdjust.spacing, PxLengthAdjust.spacingAndGlyphs]).optional(),
1443
+ method: px.enum([PxTextPathMethod.align, PxTextPathMethod.stretch]).optional(),
1444
+ spacing: px.enum([PxTextPathSpacing.auto, PxTextPathSpacing.exact]).optional(),
1445
+ startOffset: PxAnimatableNumberSchema.optional(),
1446
+ textLength: PxAnimatableNumberSchema.optional()
1447
+ }));
1448
+ var PxTextEffectSchema = implementsInterface()(px.object({
1449
+ useGlyphs: px.boolean().optional()
1450
+ }));
1451
+ var PxEffectsSchema = implementsInterface()(px.object({
1452
+ transformBy: PxTransformByEffectSchema.optional(),
1453
+ repeater: PxRepeaterEffectSchema.optional(),
1454
+ maskedBy: PxMaskedByEffectSchema.optional(),
1455
+ clipPath: PxClipPathEffectSchema.optional(),
1456
+ trimPath: PxTrimPathEffectSchema.optional(),
1457
+ clone: PxCloneEffectSchema.optional(),
1458
+ fillGradient: PxFillGradientEffectSchema.optional(),
1459
+ strokeGradient: PxStrokeGradientEffectSchema.optional(),
1460
+ textPath: PxTextPathEffectSchema.optional(),
1461
+ text: PxTextEffectSchema.optional()
1462
+ }));
1463
+ function validateNodeEffects(root, opts) {
1464
+ const warnings = [];
1465
+ const walk = (node, path) => {
1466
+ if (node && node.effects) {
1467
+ const ctx = { errors: [], warnings: [], strict: !!(opts == null ? void 0 : opts.strict) };
1468
+ const ok = PxEffectsSchema.isValid(node.effects, ctx, [path + ".effects"]);
1469
+ if (!ok) {
1470
+ for (const err of ctx.errors) warnings.push(err);
1471
+ }
1472
+ }
1473
+ if (node && Array.isArray(node.children)) {
1474
+ node.children.forEach((c, i) => walk(c, path + ".children[" + i + "]"));
1475
+ }
1476
+ };
1477
+ walk(root, "root");
1478
+ return warnings;
1451
1479
  }
1452
- function invertEasing(easing) {
1453
- if (!easing) return (y) => y;
1454
- const flipped = [easing[1], easing[0], easing[3], easing[2]];
1455
- return cubicBezier(flipped);
1480
+ var PxNodeBase = px.openObject({
1481
+ // CONVENTION (SCHEMA-DESIGN R1 / issues N4): `type` is the ONE word for "what
1482
+ // kind of thing is this", discriminated by its CARRIER — here the node TAG
1483
+ // (`rect`, `text`), and inside a sub-object that object's kind (`clone.type`,
1484
+ // `fillGradient.type`, editor `preset.type`). Each sits in its own object, so
1485
+ // the carrier disambiguates completely; synonyms (`cloneKind`, `presetShape`)
1486
+ // would add words that all mean "type" and still need the carrier to read.
1487
+ // Guarding a `type` SLOT against a wrong VALUE is the job of strict enums
1488
+ // (issues V3), never of distinct key names.
1489
+ type: px.string(),
1490
+ id: px.string().optional(),
1491
+ meta: px.any().optional(),
1492
+ // Player-effects bucket emitted by the Editor's lightweight design format.
1493
+ // Consumed and removed by `applyPlayerEffects` before any other normalisation
1494
+ // (see `createAnimatorImpl`), so downstream code never sees it.
1495
+ effects: PxEffectsSchema.optional(),
1496
+ // `PxElementAnimation` (not just `PxAnimationDefinition`) — accepts
1497
+ // string ref / array of refs / inline definition / mixed array; mirrors
1498
+ // `animator.animateById` map values and what `processNode` resolves at runtime.
1499
+ animate: PxElementAnimationSchema.optional(),
1500
+ style: px.union([px.string(), px.record(px.union([px.string(), px.number()]))]).optional()
1501
+ }, PxAttrValueSchema);
1502
+ var PxNodeSchema = px.openObject(__spreadProps2(__spreadValues2({}, PxNodeBase._shape), {
1503
+ children: px.lazy(() => px.array(PxNodeSchema), []).optional()
1504
+ }), PxAttrValueSchema);
1505
+ var PxSvgNodeExtra = px.object({
1506
+ // `"100%"` and other SVG length strings are legal here — a number-only slot rejected
1507
+ // real documents (e.g. apple-store-look-14-main.json) at the root <svg>.
1508
+ width: px.union([px.number(), px.string()]).optional(),
1509
+ height: px.union([px.number(), px.string()]).optional(),
1510
+ viewBox: px.string().optional(),
1511
+ animator: PxAnimatorConfigSchema.optional()
1512
+ });
1513
+ var PxAnimatedSvgDocumentSchema = px.openObject(__spreadProps2(__spreadValues2(__spreadValues2({}, PxNodeBase._shape), PxSvgNodeExtra._shape), {
1514
+ type: px.literal("svg"),
1515
+ // override string → literal to require 'svg'
1516
+ children: px.array(PxNodeSchema).optional()
1517
+ }), PxAttrValueSchema);
1518
+ var PxBezierPathSchema = implementsInterface()(px.object({
1519
+ v: px.array(px.array(px.number())),
1520
+ i: px.array(px.array(px.number())).optional(),
1521
+ o: px.array(px.array(px.number())).optional(),
1522
+ c: px.boolean().optional()
1523
+ }));
1524
+ function isPxElementFileFormatDeep(fileJson) {
1525
+ const valid = PxAnimatedSvgDocumentSchema.isValid(fileJson);
1526
+ return { valid, errors: valid ? [] : ["Document failed schema validation"] };
1456
1527
  }
1457
1528
  var _idCounter = 0;
1458
1529
  function generateUniqueId() {
@@ -6152,7 +6223,13 @@ function createFrameLoopAnimator(doc, adapter, callbacks, rootElement) {
6152
6223
  const api = __spreadProps(__spreadValues({}, basicApi), {
6153
6224
  "getRootElement": () => rootElement || null
6154
6225
  });
6155
- if (config.trigger) setupAnimationTriggers(api, config.trigger);
6226
+ if (config.trigger) {
6227
+ if (isScrollTimeline(config)) {
6228
+ console.warn("scroll timeline: `animator.trigger` is ignored (triggers do not apply to scroll-driven playback)");
6229
+ } else {
6230
+ setupAnimationTriggers(api, config.trigger);
6231
+ }
6232
+ }
6156
6233
  return api;
6157
6234
  }
6158
6235
  function createDomAdapter(rootElement) {
@@ -6280,7 +6357,7 @@ function convertToWebApiKeyframes(animDef, unsupportedSet, config) {
6280
6357
  }
6281
6358
  return result;
6282
6359
  }
6283
- function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsupportedAttrs) {
6360
+ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsupportedAttrs, scrollTimeline) {
6284
6361
  var _a;
6285
6362
  const config = getAnimatorConfig(doc) || {};
6286
6363
  if (!rootElement) {
@@ -6339,7 +6416,12 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6339
6416
  if (keyframes.length > 0) {
6340
6417
  try {
6341
6418
  const effect = new KeyframeEffect(element, keyframes, effectOptions);
6342
- const anim = new Animation(effect, document.timeline);
6419
+ const anim = new Animation(effect, scrollTimeline ? scrollTimeline.timeline : document.timeline);
6420
+ if (scrollTimeline) {
6421
+ const a = anim;
6422
+ if (scrollTimeline.rangeStart) a.rangeStart = scrollTimeline.rangeStart;
6423
+ if (scrollTimeline.rangeEnd) a.rangeEnd = scrollTimeline.rangeEnd;
6424
+ }
6343
6425
  if (callbacks == null ? void 0 : callbacks.onFinish) anim.onfinish = () => {
6344
6426
  var _a2;
6345
6427
  if (finishNotified) return;
@@ -6433,11 +6515,136 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6433
6515
  }
6434
6516
  };
6435
6517
  if (config.trigger) {
6436
- setupAnimationTriggers(api, config.trigger);
6518
+ if (config.timelineSource === "scroll") {
6519
+ console.warn("scroll timeline: `animator.trigger` is ignored (triggers do not apply to scroll-driven playback)");
6520
+ } else {
6521
+ setupAnimationTriggers(api, config.trigger);
6522
+ }
6523
+ }
6524
+ if (scrollTimeline) {
6525
+ animations.forEach((a) => a.play());
6437
6526
  }
6438
6527
  return api;
6439
6528
  }
6440
6529
 
6530
+ // src/PxScrollDriver.ts
6531
+ function nativeRangeOffset(point, defaultFraction, view) {
6532
+ var _a, _b, _c;
6533
+ const fraction = typeof (point == null ? void 0 : point.fraction) === "number" ? point.fraction : defaultFraction;
6534
+ const pct = (_b = (_a = globalThis.CSS) == null ? void 0 : _a.percent) == null ? void 0 : _b.call(_a, fraction * 100);
6535
+ if (pct === void 0) return void 0;
6536
+ return view ? { rangeName: (_c = point == null ? void 0 : point.phase) != null ? _c : "cover", offset: pct } : { offset: pct };
6537
+ }
6538
+ function createNativeScrollTimeline(subject, config) {
6539
+ var _a, _b, _c, _d;
6540
+ if (!config || !isScrollTimeline(config)) return null;
6541
+ const scroll = config.scroll || {};
6542
+ const kind = (_a = scroll.kind) != null ? _a : "view";
6543
+ const g = globalThis;
6544
+ const view = kind === "view";
6545
+ const Ctor = view ? g.ViewTimeline : g.ScrollTimeline;
6546
+ if (typeof Ctor !== "function") return null;
6547
+ const axis = (_b = scroll.axis) != null ? _b : "block";
6548
+ let timeline;
6549
+ try {
6550
+ if (view) {
6551
+ timeline = new Ctor({ subject, axis });
6552
+ } else {
6553
+ const source = scroll.source === "root" ? documentScroller() : findNearestScroller(subject, "y") || findNearestScroller(subject, "x") || documentScroller();
6554
+ timeline = new Ctor({ source, axis });
6555
+ }
6556
+ } catch (e) {
6557
+ console.warn("scroll timeline: native timeline construction failed \u2014 falling back to the custom driver", e);
6558
+ return null;
6559
+ }
6560
+ return {
6561
+ timeline,
6562
+ rangeStart: nativeRangeOffset((_c = scroll.range) == null ? void 0 : _c.start, 0, view),
6563
+ rangeEnd: nativeRangeOffset((_d = scroll.range) == null ? void 0 : _d.end, 1, view)
6564
+ };
6565
+ }
6566
+ function findNearestScroller(el, axis) {
6567
+ for (let p = el.parentElement; p; p = p.parentElement) {
6568
+ const style = getComputedStyle(p);
6569
+ const overflow = axis === "y" ? style.overflowY : style.overflowX;
6570
+ if (overflow === "auto" || overflow === "scroll" || overflow === "hidden" || overflow === "overlay") {
6571
+ return p;
6572
+ }
6573
+ }
6574
+ return null;
6575
+ }
6576
+ function documentScroller() {
6577
+ return document.scrollingElement || document.documentElement;
6578
+ }
6579
+ function createScrollDriver(subject, config, onProgress) {
6580
+ var _a;
6581
+ if (!config || !isScrollTimeline(config)) return null;
6582
+ const scroll = config.scroll || {};
6583
+ const kind = (_a = scroll.kind) != null ? _a : "view";
6584
+ const nearest = findNearestScroller(subject, "y") || findNearestScroller(subject, "x");
6585
+ const scroller = kind === "scroll" && scroll.source === "root" ? documentScroller() : nearest || documentScroller();
6586
+ const isRootScroller = scroller === documentScroller();
6587
+ const axis = scrollResolveAxis(scroll.axis, getComputedStyle(scroller).writingMode);
6588
+ const compute = () => {
6589
+ if (kind === "scroll") {
6590
+ const offset = axis === "y" ? scroller.scrollTop : scroller.scrollLeft;
6591
+ const maxOffset = axis === "y" ? scroller.scrollHeight - scroller.clientHeight : scroller.scrollWidth - scroller.clientWidth;
6592
+ return scrollOffsetProgress(offset, maxOffset, scroll.range);
6593
+ }
6594
+ const subjectRect = subject.getBoundingClientRect();
6595
+ let portStart, portSize;
6596
+ if (isRootScroller) {
6597
+ portStart = 0;
6598
+ portSize = axis === "y" ? document.documentElement.clientHeight : document.documentElement.clientWidth;
6599
+ } else {
6600
+ const portRect = scroller.getBoundingClientRect();
6601
+ portStart = axis === "y" ? portRect.top : portRect.left;
6602
+ portSize = axis === "y" ? scroller.clientHeight : scroller.clientWidth;
6603
+ }
6604
+ const subjectStart = (axis === "y" ? subjectRect.top : subjectRect.left) - portStart;
6605
+ const subjectSize = axis === "y" ? subjectRect.height : subjectRect.width;
6606
+ return scrollViewProgress(subjectStart, subjectSize, portSize, scroll.range);
6607
+ };
6608
+ let rafId = null;
6609
+ let destroyed = false;
6610
+ const tick = () => {
6611
+ rafId = null;
6612
+ if (destroyed) return;
6613
+ onProgress(compute());
6614
+ };
6615
+ const schedule = () => {
6616
+ if (destroyed || rafId !== null) return;
6617
+ rafId = requestAnimationFrame(tick);
6618
+ };
6619
+ const scrollTarget = isRootScroller ? window : scroller;
6620
+ scrollTarget.addEventListener("scroll", schedule, { passive: true });
6621
+ window.addEventListener("resize", schedule, { passive: true });
6622
+ let resizeObserver;
6623
+ if (typeof ResizeObserver !== "undefined") {
6624
+ resizeObserver = new ResizeObserver(schedule);
6625
+ resizeObserver.observe(subject);
6626
+ if (!isRootScroller) resizeObserver.observe(scroller);
6627
+ }
6628
+ const driver = {
6629
+ destroy: () => {
6630
+ if (destroyed) return;
6631
+ destroyed = true;
6632
+ scrollTarget.removeEventListener("scroll", schedule);
6633
+ window.removeEventListener("resize", schedule);
6634
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
6635
+ if (rafId !== null) {
6636
+ cancelAnimationFrame(rafId);
6637
+ rafId = null;
6638
+ }
6639
+ },
6640
+ refresh: () => {
6641
+ if (!destroyed) onProgress(compute());
6642
+ }
6643
+ };
6644
+ driver.refresh();
6645
+ return driver;
6646
+ }
6647
+
6441
6648
  // src/PxAnimatorBind.ts
6442
6649
  function finaliseAnimator(animatorConfig, callbacks, make) {
6443
6650
  let apiRef;
@@ -6460,6 +6667,44 @@ function finaliseAnimator(animatorConfig, callbacks, make) {
6460
6667
  }
6461
6668
  function bindWithEngineChoice(doc, adapter, callbacks, rootElement) {
6462
6669
  const animatorConfig = getAnimatorConfig(doc) || {};
6670
+ if (isScrollTimeline(animatorConfig)) {
6671
+ return finaliseAnimator(animatorConfig, callbacks, (cb) => {
6672
+ var _a, _b;
6673
+ if (animatorConfig.mode !== PxAnimatorMode.frames && ((_a = animatorConfig.scroll) == null ? void 0 : _a.driver) === "native" && rootElement) {
6674
+ const native = createNativeScrollTimeline(rootElement, animatorConfig);
6675
+ if (native) {
6676
+ const api2 = createWebApiAnimator(
6677
+ doc,
6678
+ cb,
6679
+ rootElement,
6680
+ animatorConfig.mode === PxAnimatorMode.waapi,
6681
+ native
6682
+ );
6683
+ if (api2) return api2;
6684
+ }
6685
+ }
6686
+ const api = (animatorConfig.mode !== PxAnimatorMode.frames ? createWebApiAnimator(doc, cb, rootElement, animatorConfig.mode === PxAnimatorMode.waapi) : null) || createFrameLoopAnimator(doc, adapter, cb, rootElement);
6687
+ const subject = ((_b = api.getRootElement) == null ? void 0 : _b.call(api)) || rootElement;
6688
+ if (subject) {
6689
+ const totalMs = scrollTotalDurationMs(animatorConfig);
6690
+ const driver = createScrollDriver(
6691
+ subject,
6692
+ animatorConfig,
6693
+ (progress) => api.setCurrentTime(progress * totalMs)
6694
+ );
6695
+ if (driver) {
6696
+ const destroy = api.destroy.bind(api);
6697
+ api.destroy = () => {
6698
+ driver.destroy();
6699
+ destroy();
6700
+ };
6701
+ }
6702
+ } else {
6703
+ console.warn("scroll timeline: no root element to observe \u2014 animation will stay at frame 0");
6704
+ }
6705
+ return api;
6706
+ });
6707
+ }
6463
6708
  return finaliseAnimator(animatorConfig, callbacks, (cb) => {
6464
6709
  if (animatorConfig.mode === PxAnimatorMode.frames) {
6465
6710
  return createFrameLoopAnimator(doc, adapter, cb, rootElement);