@pixodesk/svg-animator-react 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.umd.js CHANGED
@@ -1815,114 +1815,582 @@ var PixodeskAnimatorReact = (() => {
1815
1815
  return a;
1816
1816
  };
1817
1817
  var __spreadProps2 = (a, b) => __defProps2(a, __getOwnPropDescs2(b));
1818
- function pathStr(path) {
1819
- if (!path.length) return ".";
1820
- let result = "";
1821
- for (const seg of path) {
1822
- if (seg.startsWith("[")) result += seg;
1823
- else result += (result ? "." : "") + seg;
1824
- }
1825
- return result;
1826
- }
1827
- var Base = class {
1828
- _canSanitize(raw) {
1829
- return this.isValid(raw);
1818
+ function bezierToSvgPath(path, forceCurves = false) {
1819
+ var _a, _b, _c, _d;
1820
+ const v = path.v;
1821
+ const i = path.i;
1822
+ const o = path.o;
1823
+ const c = path.c;
1824
+ if (!v.length) return "";
1825
+ const d = [];
1826
+ const len = v.length;
1827
+ d.push("M" + v[0][0] + "," + v[0][1]);
1828
+ for (let idx = 1; idx < len; idx++) {
1829
+ const prevV = v[idx - 1];
1830
+ const prevO = (_a = o == null ? void 0 : o[idx - 1]) != null ? _a : prevV;
1831
+ const currI = (_b = i == null ? void 0 : i[idx]) != null ? _b : v[idx];
1832
+ const currV = v[idx];
1833
+ const isLine = !forceCurves && (prevO[0] === prevV[0] && prevO[1] === prevV[1]) && (currI[0] === currV[0] && currI[1] === currV[1]);
1834
+ if (isLine) {
1835
+ d.push("L" + currV[0] + "," + currV[1]);
1836
+ } else {
1837
+ d.push("C" + prevO[0] + "," + prevO[1] + "," + currI[0] + "," + currI[1] + "," + currV[0] + "," + currV[1]);
1838
+ }
1830
1839
  }
1831
- optional() {
1832
- return new Optional(this);
1840
+ if (c && len > 0) {
1841
+ const lastV = v[len - 1];
1842
+ const lastO = (_c = o == null ? void 0 : o[len - 1]) != null ? _c : lastV;
1843
+ const firstI = (_d = i == null ? void 0 : i[0]) != null ? _d : v[0];
1844
+ const firstV = v[0];
1845
+ const isLine = !forceCurves && (lastO[0] === lastV[0] && lastO[1] === lastV[1]) && (firstI[0] === firstV[0] && firstI[1] === firstV[1]);
1846
+ if (!isLine) {
1847
+ d.push("C" + lastO[0] + "," + lastO[1] + "," + firstI[0] + "," + firstI[1] + "," + firstV[0] + "," + firstV[1]);
1848
+ }
1849
+ d.push("z");
1833
1850
  }
1834
- };
1835
- var Optional = class extends Base {
1836
- constructor(inner) {
1837
- super();
1838
- this.inner = inner;
1839
- this._default = void 0;
1851
+ return d.join("");
1852
+ }
1853
+ function interpolateNum(a, b, t) {
1854
+ return a + (b - a) * t;
1855
+ }
1856
+ function interpolateVec(a, b, t) {
1857
+ const res = [];
1858
+ const count = Math.max(a.length, b.length);
1859
+ for (let i = 0; i < count; i++) {
1860
+ res[i] = interpolateNum(a[i] || 0, b[i] || 0, t);
1840
1861
  }
1841
- sanitize(raw) {
1842
- if (raw === void 0 || raw === null) return void 0;
1843
- return this.inner._canSanitize(raw) ? this.inner.sanitize(raw) : void 0;
1862
+ return res;
1863
+ }
1864
+ function interpolateColor(a, b, t) {
1865
+ return [
1866
+ interpolateNum(a[0] || 0, b[0] || 0, t),
1867
+ interpolateNum(a[1] || 0, b[1] || 0, t),
1868
+ interpolateNum(a[2] || 0, b[2] || 0, t),
1869
+ interpolateNum(a[3] === void 0 ? 1 : a[3], b[3] === void 0 ? 1 : b[3], t)
1870
+ ];
1871
+ }
1872
+ function interpolateBeziers(paths1, paths2, progress) {
1873
+ const count = Math.max(paths1.length, paths2.length);
1874
+ const res = [];
1875
+ for (let i = 0; i < count; i++) {
1876
+ res.push(interpolateBezier(paths1[i], paths2[i], progress));
1844
1877
  }
1845
- isValid(raw, ctx, path) {
1846
- if (raw === void 0 || raw === null) return true;
1847
- return this.inner.isValid(raw, ctx, path);
1878
+ return res;
1879
+ }
1880
+ function interpolateBezier(path1, path2, progress) {
1881
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1882
+ if (!path1 || !path2) return path1 || path2 || { v: [] };
1883
+ const t = Math.min(Math.max(progress, 0), 1);
1884
+ const len = Math.min(path1.v.length, path2.v.length);
1885
+ const v = [];
1886
+ const i = [];
1887
+ const o = [];
1888
+ for (let idx = 0; idx < len; idx++) {
1889
+ const v1 = path1.v[idx];
1890
+ const v2 = path2.v[idx];
1891
+ v.push(interpolateVec(v1, v2, t));
1892
+ const i1 = (_b = (_a = path1.i) == null ? void 0 : _a[idx]) != null ? _b : v1;
1893
+ const i2 = (_d = (_c = path2.i) == null ? void 0 : _c[idx]) != null ? _d : v2;
1894
+ i.push(interpolateVec(i1, i2, t));
1895
+ const o1 = (_f = (_e = path1.o) == null ? void 0 : _e[idx]) != null ? _f : v1;
1896
+ const o2 = (_h = (_g = path2.o) == null ? void 0 : _g[idx]) != null ? _h : v2;
1897
+ o.push(interpolateVec(o1, o2, t));
1848
1898
  }
1849
- _canSanitize(raw) {
1850
- return raw === void 0 || raw === null || this.inner._canSanitize(raw);
1899
+ return { v, i: i.length ? i : void 0, o: o.length ? o : void 0, c: (_i = path1.c) != null ? _i : path2.c };
1900
+ }
1901
+ function remap(value, inMin, inMax, outMin, outMax) {
1902
+ if (inMax === inMin) return outMin;
1903
+ const t = (value - inMin) / (inMax - inMin);
1904
+ return outMin + t * (outMax - outMin);
1905
+ }
1906
+ function solveCubicBezierX(p1x, p2x, x) {
1907
+ if (x <= 0) return 0;
1908
+ if (x >= 1) return 1;
1909
+ const cx = 3 * p1x;
1910
+ const bx = 3 * (p2x - p1x) - cx;
1911
+ const ax = 1 - cx - bx;
1912
+ function sampleX(t) {
1913
+ return ((ax * t + bx) * t + cx) * t;
1851
1914
  }
1852
- };
1853
- var Str = class extends Base {
1854
- constructor(_default = "") {
1855
- super();
1856
- this._default = _default;
1915
+ function sampleDX(t) {
1916
+ return (3 * ax * t + 2 * bx) * t + cx;
1857
1917
  }
1858
- sanitize(raw) {
1859
- return typeof raw === "string" ? raw : this._default;
1918
+ let t2 = x;
1919
+ let t0 = 0;
1920
+ let t1 = 1;
1921
+ for (let i = 0; i < 8; i++) {
1922
+ const x2 = sampleX(t2) - x;
1923
+ if (Math.abs(x2) < 1e-6) return t2;
1924
+ const d2 = sampleDX(t2);
1925
+ if (Math.abs(d2) < 1e-6) break;
1926
+ t2 -= x2 / d2;
1860
1927
  }
1861
- isValid(raw, ctx, path) {
1862
- if (typeof raw === "string") return true;
1863
- ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected string, got " + typeof raw);
1864
- return false;
1928
+ t2 = x;
1929
+ while (t0 < t1) {
1930
+ const x2 = sampleX(t2);
1931
+ if (Math.abs(x2 - x) < 1e-6) return t2;
1932
+ if (x > x2) t0 = t2;
1933
+ else t1 = t2;
1934
+ t2 = (t1 + t0) / 2;
1865
1935
  }
1866
- };
1867
- var Num = class extends Base {
1868
- constructor(_default = 0) {
1869
- super();
1870
- this._default = _default;
1936
+ return t2;
1937
+ }
1938
+ function cubicBezier(easing) {
1939
+ const [p1x, p1y, p2x, p2y] = easing;
1940
+ const cy = 3 * p1y;
1941
+ const by = 3 * (p2y - p1y) - cy;
1942
+ const ay = 1 - cy - by;
1943
+ function sampleCurveY(t) {
1944
+ return ((ay * t + by) * t + cy) * t;
1871
1945
  }
1872
- sanitize(raw) {
1873
- return typeof raw === "number" && isFinite(raw) ? raw : this._default;
1946
+ return function(x) {
1947
+ return sampleCurveY(solveCubicBezierX(p1x, p2x, x));
1948
+ };
1949
+ }
1950
+ function lerp2(a, b, t) {
1951
+ return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
1952
+ }
1953
+ function subdivideCubicBezier(p0, p1, p2, p3, t) {
1954
+ const q0 = lerp2(p0, p1, t);
1955
+ const q1 = lerp2(p1, p2, t);
1956
+ const q2 = lerp2(p2, p3, t);
1957
+ const r0 = lerp2(q0, q1, t);
1958
+ const r1 = lerp2(q1, q2, t);
1959
+ const s = lerp2(r0, r1, t);
1960
+ return {
1961
+ left: [p0, q0, r0, s],
1962
+ right: [s, r1, q2, p3]
1963
+ };
1964
+ }
1965
+ function splitEasing(easing, xFraction) {
1966
+ if (!easing) return { left: void 0, right: void 0 };
1967
+ if (xFraction <= 0) return { left: void 0, right: easing };
1968
+ if (xFraction >= 1) return { left: easing, right: void 0 };
1969
+ const [x1, y1, x2, y2] = easing;
1970
+ const t = solveCubicBezierX(x1, x2, xFraction);
1971
+ const p0 = [0, 0];
1972
+ const p1 = [x1, y1];
1973
+ const p2 = [x2, y2];
1974
+ const p3 = [1, 1];
1975
+ const { left, right } = subdivideCubicBezier(p0, p1, p2, p3, t);
1976
+ const sx = left[3][0];
1977
+ const sy = left[3][1];
1978
+ let leftEasing;
1979
+ if (sx > 1e-9 && Math.abs(sy) > 1e-9) {
1980
+ leftEasing = [
1981
+ left[1][0] / sx,
1982
+ left[1][1] / sy,
1983
+ left[2][0] / sx,
1984
+ left[2][1] / sy
1985
+ ];
1874
1986
  }
1875
- isValid(raw, ctx, path) {
1876
- if (typeof raw === "number" && isFinite(raw)) return true;
1877
- ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected finite number, got " + JSON.stringify(raw));
1878
- return false;
1987
+ let rightEasing;
1988
+ const rx = 1 - sx;
1989
+ const ry = 1 - sy;
1990
+ if (rx > 1e-9 && Math.abs(ry) > 1e-9) {
1991
+ rightEasing = [
1992
+ (right[1][0] - sx) / rx,
1993
+ (right[1][1] - sy) / ry,
1994
+ (right[2][0] - sx) / rx,
1995
+ (right[2][1] - sy) / ry
1996
+ ];
1879
1997
  }
1880
- };
1881
- var Bool = class extends Base {
1882
- constructor(_default = false) {
1883
- super();
1884
- this._default = _default;
1998
+ return { left: leftEasing, right: rightEasing };
1999
+ }
2000
+ function reverseEasing(easing) {
2001
+ if (!easing) return void 0;
2002
+ return [1 - easing[2], 1 - easing[3], 1 - easing[0], 1 - easing[1]];
2003
+ }
2004
+ function toRGBA(color) {
2005
+ const r = Math.round(color[0] * 255);
2006
+ const g = Math.round(color[1] * 255);
2007
+ const b = Math.round(color[2] * 255);
2008
+ return color.length === 4 ? "rgba(" + r + "," + g + "," + b + "," + color[3] + ")" : "rgb(" + r + "," + g + "," + b + ")";
2009
+ }
2010
+ function parseRgba(s) {
2011
+ var _a;
2012
+ const inner = (_a = s.match(/rgba?\((.*)\)/)) == null ? void 0 : _a[1];
2013
+ if (!inner) throw new Error("Invalid rgb/rgba format");
2014
+ const parts = inner.split(",").map((v) => +v.trim());
2015
+ return [parts[0] / 255, parts[1] / 255, parts[2] / 255, ...parts[3] !== void 0 ? [parts[3]] : []];
2016
+ }
2017
+ function parseHex(s) {
2018
+ const hex = s.slice(1);
2019
+ const isShort = hex.length <= 4;
2020
+ const r = isShort ? hex[0] + hex[0] : hex.slice(0, 2);
2021
+ const g = isShort ? hex[1] + hex[1] : hex.slice(2, 4);
2022
+ const b = isShort ? hex[2] + hex[2] : hex.slice(4, 6);
2023
+ const a = hex.length === 4 ? hex[3] + hex[3] : hex.length === 8 ? hex.slice(6, 8) : null;
2024
+ const result = [
2025
+ parseInt(r, 16) / 255,
2026
+ parseInt(g, 16) / 255,
2027
+ parseInt(b, 16) / 255
2028
+ ];
2029
+ if (a !== null) {
2030
+ result.push(parseInt(a, 16) / 255);
1885
2031
  }
1886
- sanitize(raw) {
1887
- return typeof raw === "boolean" ? raw : this._default;
2032
+ return result;
2033
+ }
2034
+ function parseColor(s) {
2035
+ if (!s) return void 0;
2036
+ if (Array.isArray(s)) return s;
2037
+ if (typeof s !== "string") return void 0;
2038
+ if (s.startsWith("#")) {
2039
+ return parseHex(s);
2040
+ } else if (s.startsWith("rgb")) {
2041
+ return parseRgba(s);
2042
+ } else {
2043
+ console.warn("Unsupported color format: " + s);
1888
2044
  }
1889
- isValid(raw, ctx, path) {
1890
- if (typeof raw === "boolean") return true;
1891
- ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected boolean, got " + typeof raw);
1892
- return false;
2045
+ return void 0;
2046
+ }
2047
+ var COLOUR_ATTR_NAMES = /* @__PURE__ */ new Set(["color", "fill", "flood-color", "lighting-color", "stop-color", "stroke"]);
2048
+ var TRANSFORM_FN_NAMES = /* @__PURE__ */ new Set(["translate", "rotate", "scale", "skew"]);
2049
+ var PCT_BASED_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
2050
+ function composeTransformParts(parts, opts) {
2051
+ var _a;
2052
+ if (!parts) return "";
2053
+ const withUnits = (_a = opts == null ? void 0 : opts.withUnits) != null ? _a : true;
2054
+ const segs = [];
2055
+ const t = parts.translate;
2056
+ const o = parts.origin;
2057
+ const r = parts.rotate;
2058
+ const k = parts.skew;
2059
+ const s = parts.scale;
2060
+ const tu = withUnits ? "px" : "";
2061
+ const ru = withUnits ? "deg" : "";
2062
+ if (t) segs.push("translate(" + t[0] + tu + "," + t[1] + tu + ")");
2063
+ if (o) segs.push("translate(" + o[0] + tu + "," + o[1] + tu + ")");
2064
+ if (r !== void 0 && r !== null) segs.push("rotate(" + r + ru + ")");
2065
+ if (k !== void 0 && k !== null) segs.push("skewX(" + k + ru + ")");
2066
+ if (s) segs.push("scale(" + s[0] + "," + s[1] + ")");
2067
+ if (o) segs.push("translate(" + -o[0] + tu + "," + -o[1] + tu + ")");
2068
+ return segs.join("");
2069
+ }
2070
+ var STYLE_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
2071
+ var DEFAULT_DURATION_MS = 1e3;
2072
+ function kebabToCamelCaseWord(kebab) {
2073
+ return kebab.includes("-") ? kebab.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) : kebab;
2074
+ }
2075
+ function isCamelCaseWord(word) {
2076
+ return !word.includes("-") && /[a-z][A-Z]/.test(word);
2077
+ }
2078
+ var SVG_CAMEL_CASE_ATTRS = /* @__PURE__ */ new Set([
2079
+ // Transform/positioning
2080
+ "viewBox",
2081
+ "preserveAspectRatio",
2082
+ // Gradient
2083
+ "gradientUnits",
2084
+ "gradientTransform",
2085
+ "spreadMethod",
2086
+ // Pattern
2087
+ "patternUnits",
2088
+ "patternContentUnits",
2089
+ "patternTransform",
2090
+ // Clipping/masking
2091
+ "clipPathUnits",
2092
+ "maskUnits",
2093
+ "maskContentUnits",
2094
+ // Marker (SVG spec keeps these camelCase, like viewBox)
2095
+ "markerUnits",
2096
+ "markerWidth",
2097
+ "markerHeight",
2098
+ "refX",
2099
+ "refY",
2100
+ // Text
2101
+ "textLength",
2102
+ "lengthAdjust",
2103
+ "startOffset",
2104
+ // Filter
2105
+ "filterUnits",
2106
+ "primitiveUnits",
2107
+ "tableValues",
2108
+ // feFuncR/G/B/A transfer table (type="table")
2109
+ "stdDeviation",
2110
+ "baseFrequency",
2111
+ "numOctaves",
2112
+ "surfaceScale",
2113
+ "diffuseConstant",
2114
+ "specularConstant",
2115
+ "specularExponent",
2116
+ "kernelMatrix",
2117
+ "kernelUnitLength",
2118
+ "edgeMode",
2119
+ "preserveAlpha",
2120
+ "targetX",
2121
+ "targetY"
2122
+ // // Animation
2123
+ // 'attributeName',
2124
+ // 'attributeType',
2125
+ // 'calcMode',
2126
+ // 'keyTimes',
2127
+ // 'keySplines',
2128
+ // 'repeatCount',
2129
+ // 'repeatDur'
2130
+ ]);
2131
+ function camelCaseToKebabWordIfNeeded(camel) {
2132
+ return SVG_CAMEL_CASE_ATTRS.has(camel) ? camel : camel.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
2133
+ }
2134
+ function clamp(value, min, max) {
2135
+ return Math.max(min, Math.min(value, max));
2136
+ }
2137
+ function bezier2D_pointAt(P0, P1, P2, P3, t) {
2138
+ if (t <= 0) return [P0[0], P0[1]];
2139
+ if (t >= 1) return [P3[0], P3[1]];
2140
+ const u = 1 - t;
2141
+ const u2 = u * u;
2142
+ const u3 = u2 * u;
2143
+ const t2 = t * t;
2144
+ const t3 = t2 * t;
2145
+ const w0 = u3;
2146
+ const w1 = 3 * t * u2;
2147
+ const w2 = 3 * t2 * u;
2148
+ const w3 = t3;
2149
+ return [
2150
+ w0 * P0[0] + w1 * P1[0] + w2 * P2[0] + w3 * P3[0],
2151
+ w0 * P0[1] + w1 * P1[1] + w2 * P2[1] + w3 * P3[1]
2152
+ ];
2153
+ }
2154
+ var BEZIER_T_NUDGE = 1e-4;
2155
+ function bezier2D_derivativeAt(P0, P1, P2, P3, t) {
2156
+ const result = _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t);
2157
+ if (result[0] === 0 && result[1] === 0) {
2158
+ const nudgedT = t < 0.5 ? t + BEZIER_T_NUDGE : t - BEZIER_T_NUDGE;
2159
+ return _bezier2D_derivativeAtRaw(P0, P1, P2, P3, nudgedT);
2160
+ }
2161
+ return result;
2162
+ }
2163
+ function _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t) {
2164
+ const u = 1 - t;
2165
+ const a = 3 * u * u;
2166
+ const b = 6 * t * u;
2167
+ const c = 3 * t * t;
2168
+ return [
2169
+ a * (P1[0] - P0[0]) + b * (P2[0] - P1[0]) + c * (P3[0] - P2[0]),
2170
+ a * (P1[1] - P0[1]) + b * (P2[1] - P1[1]) + c * (P3[1] - P2[1])
2171
+ ];
2172
+ }
2173
+ function bezier2D_arcLengthLUT(P0, P1, P2, P3, steps = 100) {
2174
+ const n = steps + 1;
2175
+ const ts = new Float64Array(n);
2176
+ const ds = new Float64Array(n);
2177
+ let prev = bezier2D_pointAt(P0, P1, P2, P3, 0);
2178
+ ts[0] = 0;
2179
+ ds[0] = 0;
2180
+ let cum = 0;
2181
+ for (let i = 1; i < n; i++) {
2182
+ const t = i / steps;
2183
+ const cur = bezier2D_pointAt(P0, P1, P2, P3, t);
2184
+ const dx = cur[0] - prev[0];
2185
+ const dy = cur[1] - prev[1];
2186
+ cum += Math.sqrt(dx * dx + dy * dy);
2187
+ ts[i] = t;
2188
+ ds[i] = cum;
2189
+ prev = cur;
2190
+ }
2191
+ return { ts, ds };
2192
+ }
2193
+ function bezier2D_tForDistance(lut, distance) {
2194
+ const { ts, ds } = lut;
2195
+ const last = ds.length - 1;
2196
+ if (distance <= 0) return ts[0];
2197
+ if (distance >= ds[last]) return ts[last];
2198
+ let lo = 1;
2199
+ let hi = last;
2200
+ while (lo < hi) {
2201
+ const mid = lo + hi >>> 1;
2202
+ if (ds[mid] < distance) lo = mid + 1;
2203
+ else hi = mid;
2204
+ }
2205
+ const dPrev = ds[hi - 1];
2206
+ const dCur = ds[hi];
2207
+ const span = dCur - dPrev;
2208
+ const frac = span > 0 ? (distance - dPrev) / span : 0;
2209
+ return ts[hi - 1] + frac * (ts[hi] - ts[hi - 1]);
2210
+ }
2211
+ function bezier2D_arcAtT(lut, t) {
2212
+ const { ts, ds } = lut;
2213
+ const last = ts.length - 1;
2214
+ if (t <= ts[0]) return ds[0];
2215
+ if (t >= ts[last]) return ds[last];
2216
+ let lo = 1, hi = last;
2217
+ while (lo < hi) {
2218
+ const mid = lo + hi >>> 1;
2219
+ if (ts[mid] < t) lo = mid + 1;
2220
+ else hi = mid;
2221
+ }
2222
+ const tPrev = ts[hi - 1];
2223
+ const span = ts[hi] - tPrev;
2224
+ const frac = span > 0 ? (t - tPrev) / span : 0;
2225
+ return ds[hi - 1] + frac * (ds[hi] - ds[hi - 1]);
2226
+ }
2227
+ function invertEasing(easing) {
2228
+ if (!easing) return (y) => y;
2229
+ const flipped = [easing[1], easing[0], easing[3], easing[2]];
2230
+ return cubicBezier(flipped);
2231
+ }
2232
+ function isScrollTimeline(config) {
2233
+ return (config == null ? void 0 : config.timelineSource) === "scroll";
2234
+ }
2235
+ function scrollTotalDurationMs(config) {
2236
+ const duration = typeof (config == null ? void 0 : config.duration) === "number" && config.duration > 0 ? config.duration : DEFAULT_DURATION_MS;
2237
+ const iterations = typeof (config == null ? void 0 : config.iterations) === "number" && config.iterations > 0 ? config.iterations : 1;
2238
+ return duration * iterations;
2239
+ }
2240
+ function scrollPhaseInterval(phase, subjectSize, scrollportSize) {
2241
+ const s = subjectSize, vp = scrollportSize;
2242
+ switch (phase) {
2243
+ case "cover":
2244
+ return [0, s + vp];
2245
+ case "entry":
2246
+ return [0, Math.min(s, vp)];
2247
+ case "contain":
2248
+ return [Math.min(s, vp), Math.max(s, vp)];
2249
+ case "exit":
2250
+ return [Math.max(s, vp), s + vp];
2251
+ case "entry-crossing":
2252
+ return [0, s];
2253
+ case "exit-crossing":
2254
+ return [vp, s + vp];
2255
+ }
2256
+ }
2257
+ var DEFAULT_PHASE = "cover";
2258
+ function resolveRangePointU(point, defaultFraction, subjectSize, scrollportSize) {
2259
+ var _a;
2260
+ const [u0, u1] = scrollPhaseInterval((_a = point == null ? void 0 : point.phase) != null ? _a : DEFAULT_PHASE, subjectSize, scrollportSize);
2261
+ const fraction = typeof (point == null ? void 0 : point.fraction) === "number" ? point.fraction : defaultFraction;
2262
+ return u0 + fraction * (u1 - u0);
2263
+ }
2264
+ function scrollViewProgress(subjectStart, subjectSize, scrollportSize, range) {
2265
+ const u = scrollportSize - subjectStart;
2266
+ const uStart = resolveRangePointU(range == null ? void 0 : range.start, 0, subjectSize, scrollportSize);
2267
+ const uEnd = resolveRangePointU(range == null ? void 0 : range.end, 1, subjectSize, scrollportSize);
2268
+ if (uEnd <= uStart) return u >= uEnd ? 1 : 0;
2269
+ return clamp((u - uStart) / (uEnd - uStart), 0, 1);
2270
+ }
2271
+ function scrollOffsetProgress(offset, maxOffset, range) {
2272
+ var _a, _b;
2273
+ const raw = maxOffset > 0 ? clamp(offset / maxOffset, 0, 1) : 1;
2274
+ const start = typeof ((_a = range == null ? void 0 : range.start) == null ? void 0 : _a.fraction) === "number" ? range.start.fraction : 0;
2275
+ const end = typeof ((_b = range == null ? void 0 : range.end) == null ? void 0 : _b.fraction) === "number" ? range.end.fraction : 1;
2276
+ if (end <= start) return raw >= end ? 1 : 0;
2277
+ return clamp((raw - start) / (end - start), 0, 1);
2278
+ }
2279
+ function scrollResolveAxis(axis, writingMode) {
2280
+ const a = axis != null ? axis : "block";
2281
+ if (a === "x" || a === "y") return a;
2282
+ const vertical = !!writingMode && writingMode.startsWith("vertical");
2283
+ if (a === "inline") return vertical ? "y" : "x";
2284
+ return vertical ? "x" : "y";
2285
+ }
2286
+ function pathStr(path) {
2287
+ if (!path.length) return ".";
2288
+ let result = "";
2289
+ for (const seg of path) {
2290
+ if (seg.startsWith("[")) result += seg;
2291
+ else result += (result ? "." : "") + seg;
2292
+ }
2293
+ return result;
2294
+ }
2295
+ var Base = class {
2296
+ _canSanitize(raw) {
2297
+ return this.isValid(raw);
2298
+ }
2299
+ optional() {
2300
+ return new Optional(this);
1893
2301
  }
1894
2302
  };
1895
- var Literal = class extends Base {
1896
- constructor(value) {
2303
+ var Optional = class extends Base {
2304
+ constructor(inner) {
1897
2305
  super();
1898
- this.value = value;
1899
- this._default = value;
2306
+ this.inner = inner;
2307
+ this._default = void 0;
1900
2308
  }
1901
2309
  sanitize(raw) {
1902
- return raw === this.value ? this.value : this._default;
2310
+ if (raw === void 0 || raw === null) return void 0;
2311
+ return this.inner._canSanitize(raw) ? this.inner.sanitize(raw) : void 0;
1903
2312
  }
1904
2313
  isValid(raw, ctx, path) {
1905
- if (raw === this.value) return true;
1906
- ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected " + JSON.stringify(this.value) + ", got " + JSON.stringify(raw));
1907
- return false;
2314
+ if (raw === void 0 || raw === null) return true;
2315
+ return this.inner.isValid(raw, ctx, path);
2316
+ }
2317
+ _canSanitize(raw) {
2318
+ return raw === void 0 || raw === null || this.inner._canSanitize(raw);
1908
2319
  }
1909
2320
  };
1910
- var Enum = class extends Base {
1911
- constructor(values, defaultVal) {
2321
+ var Str = class extends Base {
2322
+ constructor(_default = "") {
1912
2323
  super();
1913
- this.values = values;
1914
- this._default = defaultVal != null ? defaultVal : values[0];
2324
+ this._default = _default;
1915
2325
  }
1916
2326
  sanitize(raw) {
1917
- return this.values.includes(raw) ? raw : this._default;
2327
+ return typeof raw === "string" ? raw : this._default;
1918
2328
  }
1919
2329
  isValid(raw, ctx, path) {
1920
- if (this.values.includes(raw)) return true;
1921
- 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));
2330
+ if (typeof raw === "string") return true;
2331
+ ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected string, got " + typeof raw);
1922
2332
  return false;
1923
2333
  }
1924
2334
  };
1925
- var Union = class extends Base {
2335
+ var Num = class extends Base {
2336
+ constructor(_default = 0) {
2337
+ super();
2338
+ this._default = _default;
2339
+ }
2340
+ sanitize(raw) {
2341
+ return typeof raw === "number" && isFinite(raw) ? raw : this._default;
2342
+ }
2343
+ isValid(raw, ctx, path) {
2344
+ if (typeof raw === "number" && isFinite(raw)) return true;
2345
+ ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected finite number, got " + JSON.stringify(raw));
2346
+ return false;
2347
+ }
2348
+ };
2349
+ var Bool = class extends Base {
2350
+ constructor(_default = false) {
2351
+ super();
2352
+ this._default = _default;
2353
+ }
2354
+ sanitize(raw) {
2355
+ return typeof raw === "boolean" ? raw : this._default;
2356
+ }
2357
+ isValid(raw, ctx, path) {
2358
+ if (typeof raw === "boolean") return true;
2359
+ ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected boolean, got " + typeof raw);
2360
+ return false;
2361
+ }
2362
+ };
2363
+ var Literal = class extends Base {
2364
+ constructor(value) {
2365
+ super();
2366
+ this.value = value;
2367
+ this._default = value;
2368
+ }
2369
+ sanitize(raw) {
2370
+ return raw === this.value ? this.value : this._default;
2371
+ }
2372
+ isValid(raw, ctx, path) {
2373
+ if (raw === this.value) return true;
2374
+ ctx == null ? void 0 : ctx.errors.push(pathStr(path != null ? path : []) + ": expected " + JSON.stringify(this.value) + ", got " + JSON.stringify(raw));
2375
+ return false;
2376
+ }
2377
+ };
2378
+ var Enum = class extends Base {
2379
+ constructor(values, defaultVal) {
2380
+ super();
2381
+ this.values = values;
2382
+ this._default = defaultVal != null ? defaultVal : values[0];
2383
+ }
2384
+ sanitize(raw) {
2385
+ return this.values.includes(raw) ? raw : this._default;
2386
+ }
2387
+ isValid(raw, ctx, path) {
2388
+ if (this.values.includes(raw)) return true;
2389
+ 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));
2390
+ return false;
2391
+ }
2392
+ };
2393
+ var Union = class extends Base {
1926
2394
  constructor(schemas, defaultVal) {
1927
2395
  super();
1928
2396
  this.schemas = schemas;
@@ -2459,6 +2927,22 @@ var PixodeskAnimatorReact = (() => {
2459
2927
  styles: px.record(px.any()).optional(),
2460
2928
  glyphs: px.record(PxGlyphFontSchema).optional()
2461
2929
  }));
2930
+ var PX_SCROLL_PHASES = ["cover", "contain", "entry", "exit", "entry-crossing", "exit-crossing"];
2931
+ var PxScrollRangePointSchema = implementsInterface()(px.object({
2932
+ phase: px.enum(PX_SCROLL_PHASES).optional(),
2933
+ fraction: px.number().optional()
2934
+ }));
2935
+ var PxScrollRangeSchema = px.object({
2936
+ start: PxScrollRangePointSchema.optional(),
2937
+ end: PxScrollRangePointSchema.optional()
2938
+ });
2939
+ var PxScrollSchema = implementsInterface()(px.object({
2940
+ driver: px.enum(["custom", "native"]).optional(),
2941
+ kind: px.enum(["view", "scroll"]).optional(),
2942
+ axis: px.enum(["block", "inline", "x", "y"]).optional(),
2943
+ source: px.enum(["nearest", "root"]).optional(),
2944
+ range: PxScrollRangeSchema.optional()
2945
+ }));
2462
2946
  var PxAnimatorConfigSchema = implementsInterface()(px.object({
2463
2947
  mode: px.enum([PxAnimatorMode.auto, PxAnimatorMode.waapi, PxAnimatorMode.frames]).optional(),
2464
2948
  duration: px.number().optional(),
@@ -2474,6 +2958,7 @@ var PixodeskAnimatorReact = (() => {
2474
2958
  definitions: PxDefsSchema.optional(),
2475
2959
  animateById: px.record(PxElementAnimationSchema).optional(),
2476
2960
  timelineSource: px.string().optional(),
2961
+ scroll: PxScrollSchema.optional(),
2477
2962
  debugInstName: px.string().optional()
2478
2963
  }));
2479
2964
  var PxBindingSchema = implementsInterface()(px.object({
@@ -2552,529 +3037,115 @@ var PixodeskAnimatorReact = (() => {
2552
3037
  type: px.enum([PxCloneType.content]).optional(),
2553
3038
  sourceId: px.string().optional(),
2554
3039
  retime: PxRetimeEffectSchema.optional()
2555
- }));
2556
- var PxGradientStopSchema = implementsInterface()(px.object({
2557
- offset: px.number(),
2558
- color: px.string()
2559
- }));
2560
- var PxAnimatableGradientStopsSchema = px.union([
2561
- px.array(PxGradientStopSchema),
2562
- px.object({ value: px.array(PxGradientStopSchema) }),
2563
- PxPropertyAnimationSchema
2564
- ]);
2565
- var PxFillGradientEffectSchema = implementsInterface()(px.object({
2566
- // Contextual kind — the `type` convention, see `PxNodeBase.type`.
2567
- type: px.enum([PxGradientType.linear, PxGradientType.radial]),
2568
- p1: PxAnimatableVec2Schema.optional(),
2569
- p2: PxAnimatableVec2Schema.optional(),
2570
- c: PxAnimatableVec2Schema.optional(),
2571
- r: PxAnimatableNumberSchema.optional(),
2572
- fp: PxAnimatableVec2Schema.optional(),
2573
- stops: PxAnimatableGradientStopsSchema.optional(),
2574
- gradientUnits: px.enum([PxGradientUnits.userSpaceOnUse, PxGradientUnits.objectBoundingBox]).optional(),
2575
- spreadMethod: px.enum([PxGradientSpreadMethod.pad, PxGradientSpreadMethod.reflect, PxGradientSpreadMethod.repeat]).optional(),
2576
- gradientTransform: px.string().optional()
2577
- }));
2578
- var PxStrokeGradientEffectSchema = PxFillGradientEffectSchema;
2579
- var PxTextPathEffectSchema = implementsInterface()(px.object({
2580
- path: px.string(),
2581
- pathOverflow: px.enum([PxPathOverflow.clip, PxPathOverflow.extend]).optional(),
2582
- lengthAdjust: px.enum([PxLengthAdjust.spacing, PxLengthAdjust.spacingAndGlyphs]).optional(),
2583
- method: px.enum([PxTextPathMethod.align, PxTextPathMethod.stretch]).optional(),
2584
- spacing: px.enum([PxTextPathSpacing.auto, PxTextPathSpacing.exact]).optional(),
2585
- startOffset: PxAnimatableNumberSchema.optional(),
2586
- textLength: PxAnimatableNumberSchema.optional()
2587
- }));
2588
- var PxTextEffectSchema = implementsInterface()(px.object({
2589
- useGlyphs: px.boolean().optional()
2590
- }));
2591
- var PxEffectsSchema = implementsInterface()(px.object({
2592
- transformBy: PxTransformByEffectSchema.optional(),
2593
- repeater: PxRepeaterEffectSchema.optional(),
2594
- maskedBy: PxMaskedByEffectSchema.optional(),
2595
- clipPath: PxClipPathEffectSchema.optional(),
2596
- trimPath: PxTrimPathEffectSchema.optional(),
2597
- clone: PxCloneEffectSchema.optional(),
2598
- fillGradient: PxFillGradientEffectSchema.optional(),
2599
- strokeGradient: PxStrokeGradientEffectSchema.optional(),
2600
- textPath: PxTextPathEffectSchema.optional(),
2601
- text: PxTextEffectSchema.optional()
2602
- }));
2603
- function validateNodeEffects(root, opts) {
2604
- const warnings = [];
2605
- const walk = (node, path) => {
2606
- if (node && node.effects) {
2607
- const ctx = { errors: [], warnings: [], strict: !!(opts == null ? void 0 : opts.strict) };
2608
- const ok = PxEffectsSchema.isValid(node.effects, ctx, [path + ".effects"]);
2609
- if (!ok) {
2610
- for (const err of ctx.errors) warnings.push(err);
2611
- }
2612
- }
2613
- if (node && Array.isArray(node.children)) {
2614
- node.children.forEach((c, i) => walk(c, path + ".children[" + i + "]"));
2615
- }
2616
- };
2617
- walk(root, "root");
2618
- return warnings;
2619
- }
2620
- var PxNodeBase = px.openObject({
2621
- // CONVENTION (SCHEMA-DESIGN R1 / issues N4): `type` is the ONE word for "what
2622
- // kind of thing is this", discriminated by its CARRIER — here the node TAG
2623
- // (`rect`, `text`), and inside a sub-object that object's kind (`clone.type`,
2624
- // `fillGradient.type`, editor `preset.type`). Each sits in its own object, so
2625
- // the carrier disambiguates completely; synonyms (`cloneKind`, `presetShape`)
2626
- // would add words that all mean "type" and still need the carrier to read.
2627
- // Guarding a `type` SLOT against a wrong VALUE is the job of strict enums
2628
- // (issues V3), never of distinct key names.
2629
- type: px.string(),
2630
- id: px.string().optional(),
2631
- meta: px.any().optional(),
2632
- // Player-effects bucket emitted by the Editor's lightweight design format.
2633
- // Consumed and removed by `applyPlayerEffects` before any other normalisation
2634
- // (see `createAnimatorImpl`), so downstream code never sees it.
2635
- effects: PxEffectsSchema.optional(),
2636
- // `PxElementAnimation` (not just `PxAnimationDefinition`) — accepts
2637
- // string ref / array of refs / inline definition / mixed array; mirrors
2638
- // `animator.animateById` map values and what `processNode` resolves at runtime.
2639
- animate: PxElementAnimationSchema.optional(),
2640
- style: px.union([px.string(), px.record(px.union([px.string(), px.number()]))]).optional()
2641
- }, PxAttrValueSchema);
2642
- var PxNodeSchema = px.openObject(__spreadProps2(__spreadValues2({}, PxNodeBase._shape), {
2643
- children: px.lazy(() => px.array(PxNodeSchema), []).optional()
2644
- }), PxAttrValueSchema);
2645
- var PxSvgNodeExtra = px.object({
2646
- // `"100%"` and other SVG length strings are legal here — a number-only slot rejected
2647
- // real documents (e.g. apple-store-look-14-main.json) at the root <svg>.
2648
- width: px.union([px.number(), px.string()]).optional(),
2649
- height: px.union([px.number(), px.string()]).optional(),
2650
- viewBox: px.string().optional(),
2651
- animator: PxAnimatorConfigSchema.optional()
2652
- });
2653
- var PxAnimatedSvgDocumentSchema = px.openObject(__spreadProps2(__spreadValues2(__spreadValues2({}, PxNodeBase._shape), PxSvgNodeExtra._shape), {
2654
- type: px.literal("svg"),
2655
- // override string → literal to require 'svg'
2656
- children: px.array(PxNodeSchema).optional()
2657
- }), PxAttrValueSchema);
2658
- var PxBezierPathSchema = implementsInterface()(px.object({
2659
- v: px.array(px.array(px.number())),
2660
- i: px.array(px.array(px.number())).optional(),
2661
- o: px.array(px.array(px.number())).optional(),
2662
- c: px.boolean().optional()
2663
- }));
2664
- function bezierToSvgPath(path, forceCurves = false) {
2665
- var _a, _b, _c, _d;
2666
- const v = path.v;
2667
- const i = path.i;
2668
- const o = path.o;
2669
- const c = path.c;
2670
- if (!v.length) return "";
2671
- const d = [];
2672
- const len = v.length;
2673
- d.push("M" + v[0][0] + "," + v[0][1]);
2674
- for (let idx = 1; idx < len; idx++) {
2675
- const prevV = v[idx - 1];
2676
- const prevO = (_a = o == null ? void 0 : o[idx - 1]) != null ? _a : prevV;
2677
- const currI = (_b = i == null ? void 0 : i[idx]) != null ? _b : v[idx];
2678
- const currV = v[idx];
2679
- const isLine = !forceCurves && (prevO[0] === prevV[0] && prevO[1] === prevV[1]) && (currI[0] === currV[0] && currI[1] === currV[1]);
2680
- if (isLine) {
2681
- d.push("L" + currV[0] + "," + currV[1]);
2682
- } else {
2683
- d.push("C" + prevO[0] + "," + prevO[1] + "," + currI[0] + "," + currI[1] + "," + currV[0] + "," + currV[1]);
2684
- }
2685
- }
2686
- if (c && len > 0) {
2687
- const lastV = v[len - 1];
2688
- const lastO = (_c = o == null ? void 0 : o[len - 1]) != null ? _c : lastV;
2689
- const firstI = (_d = i == null ? void 0 : i[0]) != null ? _d : v[0];
2690
- const firstV = v[0];
2691
- const isLine = !forceCurves && (lastO[0] === lastV[0] && lastO[1] === lastV[1]) && (firstI[0] === firstV[0] && firstI[1] === firstV[1]);
2692
- if (!isLine) {
2693
- d.push("C" + lastO[0] + "," + lastO[1] + "," + firstI[0] + "," + firstI[1] + "," + firstV[0] + "," + firstV[1]);
2694
- }
2695
- d.push("z");
2696
- }
2697
- return d.join("");
2698
- }
2699
- function interpolateNum(a, b, t) {
2700
- return a + (b - a) * t;
2701
- }
2702
- function interpolateVec(a, b, t) {
2703
- const res = [];
2704
- const count = Math.max(a.length, b.length);
2705
- for (let i = 0; i < count; i++) {
2706
- res[i] = interpolateNum(a[i] || 0, b[i] || 0, t);
2707
- }
2708
- return res;
2709
- }
2710
- function interpolateColor(a, b, t) {
2711
- return [
2712
- interpolateNum(a[0] || 0, b[0] || 0, t),
2713
- interpolateNum(a[1] || 0, b[1] || 0, t),
2714
- interpolateNum(a[2] || 0, b[2] || 0, t),
2715
- interpolateNum(a[3] === void 0 ? 1 : a[3], b[3] === void 0 ? 1 : b[3], t)
2716
- ];
2717
- }
2718
- function interpolateBeziers(paths1, paths2, progress) {
2719
- const count = Math.max(paths1.length, paths2.length);
2720
- const res = [];
2721
- for (let i = 0; i < count; i++) {
2722
- res.push(interpolateBezier(paths1[i], paths2[i], progress));
2723
- }
2724
- return res;
2725
- }
2726
- function interpolateBezier(path1, path2, progress) {
2727
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2728
- if (!path1 || !path2) return path1 || path2 || { v: [] };
2729
- const t = Math.min(Math.max(progress, 0), 1);
2730
- const len = Math.min(path1.v.length, path2.v.length);
2731
- const v = [];
2732
- const i = [];
2733
- const o = [];
2734
- for (let idx = 0; idx < len; idx++) {
2735
- const v1 = path1.v[idx];
2736
- const v2 = path2.v[idx];
2737
- v.push(interpolateVec(v1, v2, t));
2738
- const i1 = (_b = (_a = path1.i) == null ? void 0 : _a[idx]) != null ? _b : v1;
2739
- const i2 = (_d = (_c = path2.i) == null ? void 0 : _c[idx]) != null ? _d : v2;
2740
- i.push(interpolateVec(i1, i2, t));
2741
- const o1 = (_f = (_e = path1.o) == null ? void 0 : _e[idx]) != null ? _f : v1;
2742
- const o2 = (_h = (_g = path2.o) == null ? void 0 : _g[idx]) != null ? _h : v2;
2743
- o.push(interpolateVec(o1, o2, t));
2744
- }
2745
- return { v, i: i.length ? i : void 0, o: o.length ? o : void 0, c: (_i = path1.c) != null ? _i : path2.c };
2746
- }
2747
- function remap(value, inMin, inMax, outMin, outMax) {
2748
- if (inMax === inMin) return outMin;
2749
- const t = (value - inMin) / (inMax - inMin);
2750
- return outMin + t * (outMax - outMin);
2751
- }
2752
- function solveCubicBezierX(p1x, p2x, x) {
2753
- if (x <= 0) return 0;
2754
- if (x >= 1) return 1;
2755
- const cx = 3 * p1x;
2756
- const bx = 3 * (p2x - p1x) - cx;
2757
- const ax = 1 - cx - bx;
2758
- function sampleX(t) {
2759
- return ((ax * t + bx) * t + cx) * t;
2760
- }
2761
- function sampleDX(t) {
2762
- return (3 * ax * t + 2 * bx) * t + cx;
2763
- }
2764
- let t2 = x;
2765
- let t0 = 0;
2766
- let t1 = 1;
2767
- for (let i = 0; i < 8; i++) {
2768
- const x2 = sampleX(t2) - x;
2769
- if (Math.abs(x2) < 1e-6) return t2;
2770
- const d2 = sampleDX(t2);
2771
- if (Math.abs(d2) < 1e-6) break;
2772
- t2 -= x2 / d2;
2773
- }
2774
- t2 = x;
2775
- while (t0 < t1) {
2776
- const x2 = sampleX(t2);
2777
- if (Math.abs(x2 - x) < 1e-6) return t2;
2778
- if (x > x2) t0 = t2;
2779
- else t1 = t2;
2780
- t2 = (t1 + t0) / 2;
2781
- }
2782
- return t2;
2783
- }
2784
- function cubicBezier(easing) {
2785
- const [p1x, p1y, p2x, p2y] = easing;
2786
- const cy = 3 * p1y;
2787
- const by = 3 * (p2y - p1y) - cy;
2788
- const ay = 1 - cy - by;
2789
- function sampleCurveY(t) {
2790
- return ((ay * t + by) * t + cy) * t;
2791
- }
2792
- return function(x) {
2793
- return sampleCurveY(solveCubicBezierX(p1x, p2x, x));
2794
- };
2795
- }
2796
- function lerp2(a, b, t) {
2797
- return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
2798
- }
2799
- function subdivideCubicBezier(p0, p1, p2, p3, t) {
2800
- const q0 = lerp2(p0, p1, t);
2801
- const q1 = lerp2(p1, p2, t);
2802
- const q2 = lerp2(p2, p3, t);
2803
- const r0 = lerp2(q0, q1, t);
2804
- const r1 = lerp2(q1, q2, t);
2805
- const s = lerp2(r0, r1, t);
2806
- return {
2807
- left: [p0, q0, r0, s],
2808
- right: [s, r1, q2, p3]
2809
- };
2810
- }
2811
- function splitEasing(easing, xFraction) {
2812
- if (!easing) return { left: void 0, right: void 0 };
2813
- if (xFraction <= 0) return { left: void 0, right: easing };
2814
- if (xFraction >= 1) return { left: easing, right: void 0 };
2815
- const [x1, y1, x2, y2] = easing;
2816
- const t = solveCubicBezierX(x1, x2, xFraction);
2817
- const p0 = [0, 0];
2818
- const p1 = [x1, y1];
2819
- const p2 = [x2, y2];
2820
- const p3 = [1, 1];
2821
- const { left, right } = subdivideCubicBezier(p0, p1, p2, p3, t);
2822
- const sx = left[3][0];
2823
- const sy = left[3][1];
2824
- let leftEasing;
2825
- if (sx > 1e-9 && Math.abs(sy) > 1e-9) {
2826
- leftEasing = [
2827
- left[1][0] / sx,
2828
- left[1][1] / sy,
2829
- left[2][0] / sx,
2830
- left[2][1] / sy
2831
- ];
2832
- }
2833
- let rightEasing;
2834
- const rx = 1 - sx;
2835
- const ry = 1 - sy;
2836
- if (rx > 1e-9 && Math.abs(ry) > 1e-9) {
2837
- rightEasing = [
2838
- (right[1][0] - sx) / rx,
2839
- (right[1][1] - sy) / ry,
2840
- (right[2][0] - sx) / rx,
2841
- (right[2][1] - sy) / ry
2842
- ];
2843
- }
2844
- return { left: leftEasing, right: rightEasing };
2845
- }
2846
- function reverseEasing(easing) {
2847
- if (!easing) return void 0;
2848
- return [1 - easing[2], 1 - easing[3], 1 - easing[0], 1 - easing[1]];
2849
- }
2850
- function toRGBA(color) {
2851
- const r = Math.round(color[0] * 255);
2852
- const g = Math.round(color[1] * 255);
2853
- const b = Math.round(color[2] * 255);
2854
- return color.length === 4 ? "rgba(" + r + "," + g + "," + b + "," + color[3] + ")" : "rgb(" + r + "," + g + "," + b + ")";
2855
- }
2856
- function parseRgba(s) {
2857
- var _a;
2858
- const inner = (_a = s.match(/rgba?\((.*)\)/)) == null ? void 0 : _a[1];
2859
- if (!inner) throw new Error("Invalid rgb/rgba format");
2860
- const parts = inner.split(",").map((v) => +v.trim());
2861
- return [parts[0] / 255, parts[1] / 255, parts[2] / 255, ...parts[3] !== void 0 ? [parts[3]] : []];
2862
- }
2863
- function parseHex(s) {
2864
- const hex = s.slice(1);
2865
- const isShort = hex.length <= 4;
2866
- const r = isShort ? hex[0] + hex[0] : hex.slice(0, 2);
2867
- const g = isShort ? hex[1] + hex[1] : hex.slice(2, 4);
2868
- const b = isShort ? hex[2] + hex[2] : hex.slice(4, 6);
2869
- const a = hex.length === 4 ? hex[3] + hex[3] : hex.length === 8 ? hex.slice(6, 8) : null;
2870
- const result = [
2871
- parseInt(r, 16) / 255,
2872
- parseInt(g, 16) / 255,
2873
- parseInt(b, 16) / 255
2874
- ];
2875
- if (a !== null) {
2876
- result.push(parseInt(a, 16) / 255);
2877
- }
2878
- return result;
2879
- }
2880
- function parseColor(s) {
2881
- if (!s) return void 0;
2882
- if (Array.isArray(s)) return s;
2883
- if (typeof s !== "string") return void 0;
2884
- if (s.startsWith("#")) {
2885
- return parseHex(s);
2886
- } else if (s.startsWith("rgb")) {
2887
- return parseRgba(s);
2888
- } else {
2889
- console.warn("Unsupported color format: " + s);
2890
- }
2891
- return void 0;
2892
- }
2893
- var COLOUR_ATTR_NAMES = /* @__PURE__ */ new Set(["color", "fill", "flood-color", "lighting-color", "stop-color", "stroke"]);
2894
- var TRANSFORM_FN_NAMES = /* @__PURE__ */ new Set(["translate", "rotate", "scale", "skew"]);
2895
- var PCT_BASED_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
2896
- function composeTransformParts(parts, opts) {
2897
- var _a;
2898
- if (!parts) return "";
2899
- const withUnits = (_a = opts == null ? void 0 : opts.withUnits) != null ? _a : true;
2900
- const segs = [];
2901
- const t = parts.translate;
2902
- const o = parts.origin;
2903
- const r = parts.rotate;
2904
- const k = parts.skew;
2905
- const s = parts.scale;
2906
- const tu = withUnits ? "px" : "";
2907
- const ru = withUnits ? "deg" : "";
2908
- if (t) segs.push("translate(" + t[0] + tu + "," + t[1] + tu + ")");
2909
- if (o) segs.push("translate(" + o[0] + tu + "," + o[1] + tu + ")");
2910
- if (r !== void 0 && r !== null) segs.push("rotate(" + r + ru + ")");
2911
- if (k !== void 0 && k !== null) segs.push("skewX(" + k + ru + ")");
2912
- if (s) segs.push("scale(" + s[0] + "," + s[1] + ")");
2913
- if (o) segs.push("translate(" + -o[0] + tu + "," + -o[1] + tu + ")");
2914
- return segs.join("");
2915
- }
2916
- var STYLE_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
2917
- var DEFAULT_DURATION_MS = 1e3;
2918
- function kebabToCamelCaseWord(kebab) {
2919
- return kebab.includes("-") ? kebab.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) : kebab;
2920
- }
2921
- function isCamelCaseWord(word) {
2922
- return !word.includes("-") && /[a-z][A-Z]/.test(word);
2923
- }
2924
- var SVG_CAMEL_CASE_ATTRS = /* @__PURE__ */ new Set([
2925
- // Transform/positioning
2926
- "viewBox",
2927
- "preserveAspectRatio",
2928
- // Gradient
2929
- "gradientUnits",
2930
- "gradientTransform",
2931
- "spreadMethod",
2932
- // Pattern
2933
- "patternUnits",
2934
- "patternContentUnits",
2935
- "patternTransform",
2936
- // Clipping/masking
2937
- "clipPathUnits",
2938
- "maskUnits",
2939
- "maskContentUnits",
2940
- // Marker (SVG spec keeps these camelCase, like viewBox)
2941
- "markerUnits",
2942
- "markerWidth",
2943
- "markerHeight",
2944
- "refX",
2945
- "refY",
2946
- // Text
2947
- "textLength",
2948
- "lengthAdjust",
2949
- "startOffset",
2950
- // Filter
2951
- "filterUnits",
2952
- "primitiveUnits",
2953
- "tableValues",
2954
- // feFuncR/G/B/A transfer table (type="table")
2955
- "stdDeviation",
2956
- "baseFrequency",
2957
- "numOctaves",
2958
- "surfaceScale",
2959
- "diffuseConstant",
2960
- "specularConstant",
2961
- "specularExponent",
2962
- "kernelMatrix",
2963
- "kernelUnitLength",
2964
- "edgeMode",
2965
- "preserveAlpha",
2966
- "targetX",
2967
- "targetY"
2968
- // // Animation
2969
- // 'attributeName',
2970
- // 'attributeType',
2971
- // 'calcMode',
2972
- // 'keyTimes',
2973
- // 'keySplines',
2974
- // 'repeatCount',
2975
- // 'repeatDur'
3040
+ }));
3041
+ var PxGradientStopSchema = implementsInterface()(px.object({
3042
+ offset: px.number(),
3043
+ color: px.string()
3044
+ }));
3045
+ var PxAnimatableGradientStopsSchema = px.union([
3046
+ px.array(PxGradientStopSchema),
3047
+ px.object({ value: px.array(PxGradientStopSchema) }),
3048
+ PxPropertyAnimationSchema
2976
3049
  ]);
2977
- function camelCaseToKebabWordIfNeeded(camel) {
2978
- return SVG_CAMEL_CASE_ATTRS.has(camel) ? camel : camel.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
2979
- }
2980
- function clamp(value, min, max) {
2981
- return Math.max(min, Math.min(value, max));
2982
- }
2983
- function bezier2D_pointAt(P0, P1, P2, P3, t) {
2984
- if (t <= 0) return [P0[0], P0[1]];
2985
- if (t >= 1) return [P3[0], P3[1]];
2986
- const u = 1 - t;
2987
- const u2 = u * u;
2988
- const u3 = u2 * u;
2989
- const t2 = t * t;
2990
- const t3 = t2 * t;
2991
- const w0 = u3;
2992
- const w1 = 3 * t * u2;
2993
- const w2 = 3 * t2 * u;
2994
- const w3 = t3;
2995
- return [
2996
- w0 * P0[0] + w1 * P1[0] + w2 * P2[0] + w3 * P3[0],
2997
- w0 * P0[1] + w1 * P1[1] + w2 * P2[1] + w3 * P3[1]
2998
- ];
2999
- }
3000
- var BEZIER_T_NUDGE = 1e-4;
3001
- function bezier2D_derivativeAt(P0, P1, P2, P3, t) {
3002
- const result = _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t);
3003
- if (result[0] === 0 && result[1] === 0) {
3004
- const nudgedT = t < 0.5 ? t + BEZIER_T_NUDGE : t - BEZIER_T_NUDGE;
3005
- return _bezier2D_derivativeAtRaw(P0, P1, P2, P3, nudgedT);
3006
- }
3007
- return result;
3008
- }
3009
- function _bezier2D_derivativeAtRaw(P0, P1, P2, P3, t) {
3010
- const u = 1 - t;
3011
- const a = 3 * u * u;
3012
- const b = 6 * t * u;
3013
- const c = 3 * t * t;
3014
- return [
3015
- a * (P1[0] - P0[0]) + b * (P2[0] - P1[0]) + c * (P3[0] - P2[0]),
3016
- a * (P1[1] - P0[1]) + b * (P2[1] - P1[1]) + c * (P3[1] - P2[1])
3017
- ];
3018
- }
3019
- function bezier2D_arcLengthLUT(P0, P1, P2, P3, steps = 100) {
3020
- const n = steps + 1;
3021
- const ts = new Float64Array(n);
3022
- const ds = new Float64Array(n);
3023
- let prev = bezier2D_pointAt(P0, P1, P2, P3, 0);
3024
- ts[0] = 0;
3025
- ds[0] = 0;
3026
- let cum = 0;
3027
- for (let i = 1; i < n; i++) {
3028
- const t = i / steps;
3029
- const cur = bezier2D_pointAt(P0, P1, P2, P3, t);
3030
- const dx = cur[0] - prev[0];
3031
- const dy = cur[1] - prev[1];
3032
- cum += Math.sqrt(dx * dx + dy * dy);
3033
- ts[i] = t;
3034
- ds[i] = cum;
3035
- prev = cur;
3036
- }
3037
- return { ts, ds };
3038
- }
3039
- function bezier2D_tForDistance(lut, distance) {
3040
- const { ts, ds } = lut;
3041
- const last = ds.length - 1;
3042
- if (distance <= 0) return ts[0];
3043
- if (distance >= ds[last]) return ts[last];
3044
- let lo = 1;
3045
- let hi = last;
3046
- while (lo < hi) {
3047
- const mid = lo + hi >>> 1;
3048
- if (ds[mid] < distance) lo = mid + 1;
3049
- else hi = mid;
3050
- }
3051
- const dPrev = ds[hi - 1];
3052
- const dCur = ds[hi];
3053
- const span = dCur - dPrev;
3054
- const frac = span > 0 ? (distance - dPrev) / span : 0;
3055
- return ts[hi - 1] + frac * (ts[hi] - ts[hi - 1]);
3056
- }
3057
- function bezier2D_arcAtT(lut, t) {
3058
- const { ts, ds } = lut;
3059
- const last = ts.length - 1;
3060
- if (t <= ts[0]) return ds[0];
3061
- if (t >= ts[last]) return ds[last];
3062
- let lo = 1, hi = last;
3063
- while (lo < hi) {
3064
- const mid = lo + hi >>> 1;
3065
- if (ts[mid] < t) lo = mid + 1;
3066
- else hi = mid;
3067
- }
3068
- const tPrev = ts[hi - 1];
3069
- const span = ts[hi] - tPrev;
3070
- const frac = span > 0 ? (t - tPrev) / span : 0;
3071
- return ds[hi - 1] + frac * (ds[hi] - ds[hi - 1]);
3072
- }
3073
- function invertEasing(easing) {
3074
- if (!easing) return (y) => y;
3075
- const flipped = [easing[1], easing[0], easing[3], easing[2]];
3076
- return cubicBezier(flipped);
3050
+ var PxFillGradientEffectSchema = implementsInterface()(px.object({
3051
+ // Contextual kind the `type` convention, see `PxNodeBase.type`.
3052
+ type: px.enum([PxGradientType.linear, PxGradientType.radial]),
3053
+ p1: PxAnimatableVec2Schema.optional(),
3054
+ p2: PxAnimatableVec2Schema.optional(),
3055
+ c: PxAnimatableVec2Schema.optional(),
3056
+ r: PxAnimatableNumberSchema.optional(),
3057
+ fp: PxAnimatableVec2Schema.optional(),
3058
+ stops: PxAnimatableGradientStopsSchema.optional(),
3059
+ gradientUnits: px.enum([PxGradientUnits.userSpaceOnUse, PxGradientUnits.objectBoundingBox]).optional(),
3060
+ spreadMethod: px.enum([PxGradientSpreadMethod.pad, PxGradientSpreadMethod.reflect, PxGradientSpreadMethod.repeat]).optional(),
3061
+ gradientTransform: px.string().optional()
3062
+ }));
3063
+ var PxStrokeGradientEffectSchema = PxFillGradientEffectSchema;
3064
+ var PxTextPathEffectSchema = implementsInterface()(px.object({
3065
+ path: px.string(),
3066
+ pathOverflow: px.enum([PxPathOverflow.clip, PxPathOverflow.extend]).optional(),
3067
+ lengthAdjust: px.enum([PxLengthAdjust.spacing, PxLengthAdjust.spacingAndGlyphs]).optional(),
3068
+ method: px.enum([PxTextPathMethod.align, PxTextPathMethod.stretch]).optional(),
3069
+ spacing: px.enum([PxTextPathSpacing.auto, PxTextPathSpacing.exact]).optional(),
3070
+ startOffset: PxAnimatableNumberSchema.optional(),
3071
+ textLength: PxAnimatableNumberSchema.optional()
3072
+ }));
3073
+ var PxTextEffectSchema = implementsInterface()(px.object({
3074
+ useGlyphs: px.boolean().optional()
3075
+ }));
3076
+ var PxEffectsSchema = implementsInterface()(px.object({
3077
+ transformBy: PxTransformByEffectSchema.optional(),
3078
+ repeater: PxRepeaterEffectSchema.optional(),
3079
+ maskedBy: PxMaskedByEffectSchema.optional(),
3080
+ clipPath: PxClipPathEffectSchema.optional(),
3081
+ trimPath: PxTrimPathEffectSchema.optional(),
3082
+ clone: PxCloneEffectSchema.optional(),
3083
+ fillGradient: PxFillGradientEffectSchema.optional(),
3084
+ strokeGradient: PxStrokeGradientEffectSchema.optional(),
3085
+ textPath: PxTextPathEffectSchema.optional(),
3086
+ text: PxTextEffectSchema.optional()
3087
+ }));
3088
+ function validateNodeEffects(root, opts) {
3089
+ const warnings = [];
3090
+ const walk = (node, path) => {
3091
+ if (node && node.effects) {
3092
+ const ctx = { errors: [], warnings: [], strict: !!(opts == null ? void 0 : opts.strict) };
3093
+ const ok = PxEffectsSchema.isValid(node.effects, ctx, [path + ".effects"]);
3094
+ if (!ok) {
3095
+ for (const err of ctx.errors) warnings.push(err);
3096
+ }
3097
+ }
3098
+ if (node && Array.isArray(node.children)) {
3099
+ node.children.forEach((c, i) => walk(c, path + ".children[" + i + "]"));
3100
+ }
3101
+ };
3102
+ walk(root, "root");
3103
+ return warnings;
3077
3104
  }
3105
+ var PxNodeBase = px.openObject({
3106
+ // CONVENTION (SCHEMA-DESIGN R1 / issues N4): `type` is the ONE word for "what
3107
+ // kind of thing is this", discriminated by its CARRIER — here the node TAG
3108
+ // (`rect`, `text`), and inside a sub-object that object's kind (`clone.type`,
3109
+ // `fillGradient.type`, editor `preset.type`). Each sits in its own object, so
3110
+ // the carrier disambiguates completely; synonyms (`cloneKind`, `presetShape`)
3111
+ // would add words that all mean "type" and still need the carrier to read.
3112
+ // Guarding a `type` SLOT against a wrong VALUE is the job of strict enums
3113
+ // (issues V3), never of distinct key names.
3114
+ type: px.string(),
3115
+ id: px.string().optional(),
3116
+ meta: px.any().optional(),
3117
+ // Player-effects bucket emitted by the Editor's lightweight design format.
3118
+ // Consumed and removed by `applyPlayerEffects` before any other normalisation
3119
+ // (see `createAnimatorImpl`), so downstream code never sees it.
3120
+ effects: PxEffectsSchema.optional(),
3121
+ // `PxElementAnimation` (not just `PxAnimationDefinition`) — accepts
3122
+ // string ref / array of refs / inline definition / mixed array; mirrors
3123
+ // `animator.animateById` map values and what `processNode` resolves at runtime.
3124
+ animate: PxElementAnimationSchema.optional(),
3125
+ style: px.union([px.string(), px.record(px.union([px.string(), px.number()]))]).optional()
3126
+ }, PxAttrValueSchema);
3127
+ var PxNodeSchema = px.openObject(__spreadProps2(__spreadValues2({}, PxNodeBase._shape), {
3128
+ children: px.lazy(() => px.array(PxNodeSchema), []).optional()
3129
+ }), PxAttrValueSchema);
3130
+ var PxSvgNodeExtra = px.object({
3131
+ // `"100%"` and other SVG length strings are legal here — a number-only slot rejected
3132
+ // real documents (e.g. apple-store-look-14-main.json) at the root <svg>.
3133
+ width: px.union([px.number(), px.string()]).optional(),
3134
+ height: px.union([px.number(), px.string()]).optional(),
3135
+ viewBox: px.string().optional(),
3136
+ animator: PxAnimatorConfigSchema.optional()
3137
+ });
3138
+ var PxAnimatedSvgDocumentSchema = px.openObject(__spreadProps2(__spreadValues2(__spreadValues2({}, PxNodeBase._shape), PxSvgNodeExtra._shape), {
3139
+ type: px.literal("svg"),
3140
+ // override string → literal to require 'svg'
3141
+ children: px.array(PxNodeSchema).optional()
3142
+ }), PxAttrValueSchema);
3143
+ var PxBezierPathSchema = implementsInterface()(px.object({
3144
+ v: px.array(px.array(px.number())),
3145
+ i: px.array(px.array(px.number())).optional(),
3146
+ o: px.array(px.array(px.number())).optional(),
3147
+ c: px.boolean().optional()
3148
+ }));
3078
3149
  var _idCounter = 0;
3079
3150
  function generateUniqueId() {
3080
3151
  const timestamp = Date.now().toString(36);
@@ -7430,7 +7501,13 @@ var PixodeskAnimatorReact = (() => {
7430
7501
  const api = __spreadProps(__spreadValues({}, basicApi), {
7431
7502
  "getRootElement": () => rootElement || null
7432
7503
  });
7433
- if (config.trigger) setupAnimationTriggers(api, config.trigger);
7504
+ if (config.trigger) {
7505
+ if (isScrollTimeline(config)) {
7506
+ console.warn("scroll timeline: `animator.trigger` is ignored (triggers do not apply to scroll-driven playback)");
7507
+ } else {
7508
+ setupAnimationTriggers(api, config.trigger);
7509
+ }
7510
+ }
7434
7511
  return api;
7435
7512
  }
7436
7513
  function createDomAdapter(rootElement) {
@@ -7556,7 +7633,7 @@ var PixodeskAnimatorReact = (() => {
7556
7633
  }
7557
7634
  return result;
7558
7635
  }
7559
- function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsupportedAttrs) {
7636
+ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsupportedAttrs, scrollTimeline) {
7560
7637
  var _a;
7561
7638
  const config = getAnimatorConfig(doc) || {};
7562
7639
  if (!rootElement) {
@@ -7615,7 +7692,12 @@ var PixodeskAnimatorReact = (() => {
7615
7692
  if (keyframes.length > 0) {
7616
7693
  try {
7617
7694
  const effect = new KeyframeEffect(element, keyframes, effectOptions);
7618
- const anim = new Animation(effect, document.timeline);
7695
+ const anim = new Animation(effect, scrollTimeline ? scrollTimeline.timeline : document.timeline);
7696
+ if (scrollTimeline) {
7697
+ const a = anim;
7698
+ if (scrollTimeline.rangeStart) a.rangeStart = scrollTimeline.rangeStart;
7699
+ if (scrollTimeline.rangeEnd) a.rangeEnd = scrollTimeline.rangeEnd;
7700
+ }
7619
7701
  if (callbacks == null ? void 0 : callbacks.onFinish) anim.onfinish = () => {
7620
7702
  var _a2;
7621
7703
  if (finishNotified) return;
@@ -7709,10 +7791,133 @@ var PixodeskAnimatorReact = (() => {
7709
7791
  }
7710
7792
  };
7711
7793
  if (config.trigger) {
7712
- setupAnimationTriggers(api, config.trigger);
7794
+ if (config.timelineSource === "scroll") {
7795
+ console.warn("scroll timeline: `animator.trigger` is ignored (triggers do not apply to scroll-driven playback)");
7796
+ } else {
7797
+ setupAnimationTriggers(api, config.trigger);
7798
+ }
7799
+ }
7800
+ if (scrollTimeline) {
7801
+ animations.forEach((a) => a.play());
7713
7802
  }
7714
7803
  return api;
7715
7804
  }
7805
+ function nativeRangeOffset(point, defaultFraction, view) {
7806
+ var _a, _b, _c;
7807
+ const fraction = typeof (point == null ? void 0 : point.fraction) === "number" ? point.fraction : defaultFraction;
7808
+ const pct = (_b = (_a = globalThis.CSS) == null ? void 0 : _a.percent) == null ? void 0 : _b.call(_a, fraction * 100);
7809
+ if (pct === void 0) return void 0;
7810
+ return view ? { rangeName: (_c = point == null ? void 0 : point.phase) != null ? _c : "cover", offset: pct } : { offset: pct };
7811
+ }
7812
+ function createNativeScrollTimeline(subject, config) {
7813
+ var _a, _b, _c, _d;
7814
+ if (!config || !isScrollTimeline(config)) return null;
7815
+ const scroll = config.scroll || {};
7816
+ const kind = (_a = scroll.kind) != null ? _a : "view";
7817
+ const g = globalThis;
7818
+ const view = kind === "view";
7819
+ const Ctor = view ? g.ViewTimeline : g.ScrollTimeline;
7820
+ if (typeof Ctor !== "function") return null;
7821
+ const axis = (_b = scroll.axis) != null ? _b : "block";
7822
+ let timeline;
7823
+ try {
7824
+ if (view) {
7825
+ timeline = new Ctor({ subject, axis });
7826
+ } else {
7827
+ const source = scroll.source === "root" ? documentScroller() : findNearestScroller(subject, "y") || findNearestScroller(subject, "x") || documentScroller();
7828
+ timeline = new Ctor({ source, axis });
7829
+ }
7830
+ } catch (e) {
7831
+ console.warn("scroll timeline: native timeline construction failed \u2014 falling back to the custom driver", e);
7832
+ return null;
7833
+ }
7834
+ return {
7835
+ timeline,
7836
+ rangeStart: nativeRangeOffset((_c = scroll.range) == null ? void 0 : _c.start, 0, view),
7837
+ rangeEnd: nativeRangeOffset((_d = scroll.range) == null ? void 0 : _d.end, 1, view)
7838
+ };
7839
+ }
7840
+ function findNearestScroller(el, axis) {
7841
+ for (let p = el.parentElement; p; p = p.parentElement) {
7842
+ const style = getComputedStyle(p);
7843
+ const overflow = axis === "y" ? style.overflowY : style.overflowX;
7844
+ if (overflow === "auto" || overflow === "scroll" || overflow === "hidden" || overflow === "overlay") {
7845
+ return p;
7846
+ }
7847
+ }
7848
+ return null;
7849
+ }
7850
+ function documentScroller() {
7851
+ return document.scrollingElement || document.documentElement;
7852
+ }
7853
+ function createScrollDriver(subject, config, onProgress) {
7854
+ var _a;
7855
+ if (!config || !isScrollTimeline(config)) return null;
7856
+ const scroll = config.scroll || {};
7857
+ const kind = (_a = scroll.kind) != null ? _a : "view";
7858
+ const nearest = findNearestScroller(subject, "y") || findNearestScroller(subject, "x");
7859
+ const scroller = kind === "scroll" && scroll.source === "root" ? documentScroller() : nearest || documentScroller();
7860
+ const isRootScroller = scroller === documentScroller();
7861
+ const axis = scrollResolveAxis(scroll.axis, getComputedStyle(scroller).writingMode);
7862
+ const compute = () => {
7863
+ if (kind === "scroll") {
7864
+ const offset = axis === "y" ? scroller.scrollTop : scroller.scrollLeft;
7865
+ const maxOffset = axis === "y" ? scroller.scrollHeight - scroller.clientHeight : scroller.scrollWidth - scroller.clientWidth;
7866
+ return scrollOffsetProgress(offset, maxOffset, scroll.range);
7867
+ }
7868
+ const subjectRect = subject.getBoundingClientRect();
7869
+ let portStart, portSize;
7870
+ if (isRootScroller) {
7871
+ portStart = 0;
7872
+ portSize = axis === "y" ? document.documentElement.clientHeight : document.documentElement.clientWidth;
7873
+ } else {
7874
+ const portRect = scroller.getBoundingClientRect();
7875
+ portStart = axis === "y" ? portRect.top : portRect.left;
7876
+ portSize = axis === "y" ? scroller.clientHeight : scroller.clientWidth;
7877
+ }
7878
+ const subjectStart = (axis === "y" ? subjectRect.top : subjectRect.left) - portStart;
7879
+ const subjectSize = axis === "y" ? subjectRect.height : subjectRect.width;
7880
+ return scrollViewProgress(subjectStart, subjectSize, portSize, scroll.range);
7881
+ };
7882
+ let rafId = null;
7883
+ let destroyed = false;
7884
+ const tick = () => {
7885
+ rafId = null;
7886
+ if (destroyed) return;
7887
+ onProgress(compute());
7888
+ };
7889
+ const schedule = () => {
7890
+ if (destroyed || rafId !== null) return;
7891
+ rafId = requestAnimationFrame(tick);
7892
+ };
7893
+ const scrollTarget = isRootScroller ? window : scroller;
7894
+ scrollTarget.addEventListener("scroll", schedule, { passive: true });
7895
+ window.addEventListener("resize", schedule, { passive: true });
7896
+ let resizeObserver;
7897
+ if (typeof ResizeObserver !== "undefined") {
7898
+ resizeObserver = new ResizeObserver(schedule);
7899
+ resizeObserver.observe(subject);
7900
+ if (!isRootScroller) resizeObserver.observe(scroller);
7901
+ }
7902
+ const driver = {
7903
+ destroy: () => {
7904
+ if (destroyed) return;
7905
+ destroyed = true;
7906
+ scrollTarget.removeEventListener("scroll", schedule);
7907
+ window.removeEventListener("resize", schedule);
7908
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
7909
+ if (rafId !== null) {
7910
+ cancelAnimationFrame(rafId);
7911
+ rafId = null;
7912
+ }
7913
+ },
7914
+ refresh: () => {
7915
+ if (!destroyed) onProgress(compute());
7916
+ }
7917
+ };
7918
+ driver.refresh();
7919
+ return driver;
7920
+ }
7716
7921
  function finaliseAnimator(animatorConfig, callbacks, make) {
7717
7922
  let apiRef;
7718
7923
  let effectiveCallbacks = callbacks;
@@ -7734,6 +7939,44 @@ var PixodeskAnimatorReact = (() => {
7734
7939
  }
7735
7940
  function bindWithEngineChoice(doc, adapter, callbacks, rootElement) {
7736
7941
  const animatorConfig = getAnimatorConfig(doc) || {};
7942
+ if (isScrollTimeline(animatorConfig)) {
7943
+ return finaliseAnimator(animatorConfig, callbacks, (cb) => {
7944
+ var _a, _b;
7945
+ if (animatorConfig.mode !== PxAnimatorMode.frames && ((_a = animatorConfig.scroll) == null ? void 0 : _a.driver) === "native" && rootElement) {
7946
+ const native = createNativeScrollTimeline(rootElement, animatorConfig);
7947
+ if (native) {
7948
+ const api2 = createWebApiAnimator(
7949
+ doc,
7950
+ cb,
7951
+ rootElement,
7952
+ animatorConfig.mode === PxAnimatorMode.waapi,
7953
+ native
7954
+ );
7955
+ if (api2) return api2;
7956
+ }
7957
+ }
7958
+ const api = (animatorConfig.mode !== PxAnimatorMode.frames ? createWebApiAnimator(doc, cb, rootElement, animatorConfig.mode === PxAnimatorMode.waapi) : null) || createFrameLoopAnimator(doc, adapter, cb, rootElement);
7959
+ const subject = ((_b = api.getRootElement) == null ? void 0 : _b.call(api)) || rootElement;
7960
+ if (subject) {
7961
+ const totalMs = scrollTotalDurationMs(animatorConfig);
7962
+ const driver = createScrollDriver(
7963
+ subject,
7964
+ animatorConfig,
7965
+ (progress) => api.setCurrentTime(progress * totalMs)
7966
+ );
7967
+ if (driver) {
7968
+ const destroy = api.destroy.bind(api);
7969
+ api.destroy = () => {
7970
+ driver.destroy();
7971
+ destroy();
7972
+ };
7973
+ }
7974
+ } else {
7975
+ console.warn("scroll timeline: no root element to observe \u2014 animation will stay at frame 0");
7976
+ }
7977
+ return api;
7978
+ });
7979
+ }
7737
7980
  return finaliseAnimator(animatorConfig, callbacks, (cb) => {
7738
7981
  if (animatorConfig.mode === PxAnimatorMode.frames) {
7739
7982
  return createFrameLoopAnimator(doc, adapter, cb, rootElement);