@mkbabb/keyframes.js 4.2.0 → 4.3.0

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/keyframes.js CHANGED
@@ -1,7 +1,10 @@
1
- import { a as e, c as t, d as n, g as r, h as i, i as a, l as o, m as s, n as c, o as l, p as u, r as d, t as f, u as p } from "./timeline-CPT7qUV1.js";
2
- import { n as m, r as h, t as g } from "./springTimingFunction-DMb11kBe.js";
1
+ import { _ as e, a as t, c as n, f as r, g as i, i as a, l as o, m as s, n as c, o as l, p as u, r as d, s as f, t as p, u as m, v as h, y as g } from "./timeline-BjcmprQ6.js";
2
+ import { t as _ } from "./binarySearch-DOP8erk-.js";
3
+ import { n as v, t as y } from "./springTimingFunction-CcJEvGwN.js";
4
+ import { n as b, t as x } from "./decay-BvNmFk51.js";
5
+ import { t as S } from "./sequence-COn8zk5o.js";
3
6
  //#region src/animation/numeric.ts
4
- var _ = class {
7
+ var C = class {
5
8
  keyframes;
6
9
  segments;
7
10
  positions;
@@ -9,17 +12,17 @@ var _ = class {
9
12
  _duration;
10
13
  _respectReducedMotion;
11
14
  _easingFn;
12
- _playback = new l();
13
- constructor(e, t) {
14
- if (e.length < 2) throw Error("NumericAnimation requires at least 2 keyframes.");
15
- this.keyframes = e.map((e) => ({ ...e })), this._duration = t?.duration ?? 0, this._respectReducedMotion = t?.respectReducedMotion ?? !1;
16
- let n = t?.timingFunction;
17
- if (typeof n == "string") throw new i("timingFunction", n, "NumericAnimation accepts a callable TimingFunction or a typed Easing; resolve a string name first via `await resolveEasing(name)`.");
18
- if (this._easingFn = n == null ? (e) => e : s(n).fn, t?.positions) {
19
- if (t.positions.length !== e.length) throw Error("positions length must match keyframes length.");
20
- this.positions = t.positions;
21
- } else this.positions = e.map((t, n) => n / (e.length - 1) * 100);
22
- this.result = { ...e[0] }, this.segments = this.buildSegments();
15
+ _playback = new o();
16
+ constructor(t, n) {
17
+ if (t.length < 2) throw Error("NumericAnimation requires at least 2 keyframes.");
18
+ this.keyframes = t.map((e) => ({ ...e })), this._duration = n?.duration ?? 0, this._respectReducedMotion = n?.respectReducedMotion ?? !1;
19
+ let r = n?.timingFunction;
20
+ if (typeof r == "string") throw new h("timingFunction", r, "NumericAnimation accepts a callable TimingFunction or a typed Easing; resolve a string name first via `await resolveEasing(name)`.");
21
+ if (this._easingFn = r == null ? (e) => e : e(r).fn, n?.positions) {
22
+ if (n.positions.length !== t.length) throw Error("positions length must match keyframes length.");
23
+ this.positions = n.positions;
24
+ } else this.positions = t.map((e, n) => n / (t.length - 1) * 100);
25
+ this.result = { ...t[0] }, this.segments = this.buildSegments();
23
26
  }
24
27
  buildSegments() {
25
28
  let e = [];
@@ -38,10 +41,10 @@ var _ = class {
38
41
  };
39
42
  }
40
43
  at(e) {
41
- let r = t(e, 0, 1) * 100, i = n(this.segments, r, (e) => e.startPos, (e) => e.stopPos);
42
- i === -1 && (i = this.segments.length - 1);
43
- let a = this.segments[i], s = p(t(r, a.startPos, a.stopPos), a.startPos, a.stopPos, 0, 1), c = a.timingFunction(s);
44
- for (let e = 0; e < a.keys.length; e++) this.result[a.keys[e]] = o(a.startVals[e], a.stopVals[e], c);
44
+ let t = r(e, 0, 1) * 100, n = _(this.segments, t, (e) => e.startPos, (e) => e.stopPos);
45
+ n === -1 && (n = this.segments.length - 1);
46
+ let i = this.segments[n], a = s(r(t, i.startPos, i.stopPos), i.startPos, i.stopPos, 0, 1), o = i.timingFunction(a);
47
+ for (let e = 0; e < i.keys.length; e++) this.result[i.keys[e]] = u(i.startVals[e], i.stopVals[e], o);
45
48
  return this.result;
46
49
  }
47
50
  updateKeyframe(e, t) {
@@ -58,7 +61,7 @@ var _ = class {
58
61
  stop() {
59
62
  this._playback.stop();
60
63
  }
61
- }, v = (e) => {
64
+ }, w = (e) => {
62
65
  if (e instanceof HTMLElement) {
63
66
  let t = e.getBoundingClientRect();
64
67
  return {
@@ -69,7 +72,7 @@ var _ = class {
69
72
  };
70
73
  }
71
74
  return e;
72
- }, y = class {
75
+ }, T = class {
73
76
  animation;
74
77
  transformOrigin;
75
78
  timingFunction;
@@ -78,8 +81,8 @@ var _ = class {
78
81
  this.transformOrigin = n?.transformOrigin ?? "top left", this.timingFunction = n?.timingFunction, this.duration = n?.duration ?? 0, this.measure(e, t);
79
82
  }
80
83
  measure(e, t) {
81
- let n = v(e), r = v(t), i = r.x - n.x, a = r.y - n.y, o = n.width === 0 ? 1 : r.width / n.width, s = n.height === 0 ? 1 : r.height / n.height;
82
- return this.animation = new _([{
84
+ let n = w(e), r = w(t), i = r.x - n.x, a = r.y - n.y, o = n.width === 0 ? 1 : r.width / n.width, s = n.height === 0 ? 1 : r.height / n.height;
85
+ return this.animation = new C([{
83
86
  translateX: 0,
84
87
  translateY: 0,
85
88
  scaleX: 1,
@@ -113,35 +116,35 @@ var _ = class {
113
116
  stop() {
114
117
  this.animation.stop();
115
118
  }
116
- }, b = (e, n) => {
117
- if (typeof e == "number") return t(e, 0, Math.max(0, n - 1));
119
+ }, E = (e, t) => {
120
+ if (typeof e == "number") return r(e, 0, Math.max(0, t - 1));
118
121
  switch (e) {
119
122
  case "first": return 0;
120
- case "last": return n - 1;
121
- case "center": return (n - 1) / 2;
123
+ case "last": return t - 1;
124
+ case "center": return (t - 1) / 2;
122
125
  case "edges": return -1;
123
126
  }
124
- }, x = (e, t, n) => n === "edges" ? Math.min(e, t - 1 - e) : Math.abs(e - b(n, t)), S = (e, t) => {
127
+ }, D = (e, t, n) => n === "edges" ? Math.min(e, t - 1 - e) : Math.abs(e - E(n, t)), O = (e, t) => {
125
128
  if (e <= 1) return 0;
126
129
  if (t === "edges") return Math.floor((e - 1) / 2);
127
- let n = b(t, e);
130
+ let n = E(t, e);
128
131
  return Math.max(n, e - 1 - n);
129
132
  };
130
- function C(e, t = {}) {
131
- let { each: n = 100, from: r = "first", ease: a } = t;
132
- if (typeof a == "string") throw new i("ease", a, "stagger accepts a callable TimingFunction or a typed Easing; resolve a string name first via `await resolveEasing(name)`.");
133
- let o = a ? s(a).fn : void 0, c = typeof e == "number" ? e : e.length, l = (e, t) => {
133
+ function k(t, n = {}) {
134
+ let { each: r = 100, from: i = "first", ease: a } = n;
135
+ if (typeof a == "string") throw new h("ease", a, "stagger accepts a callable TimingFunction or a typed Easing; resolve a string name first via `await resolveEasing(name)`.");
136
+ let o = a ? e(a).fn : void 0, s = typeof t == "number" ? t : t.length, c = (e, t) => {
134
137
  if (t <= 1) return 0;
135
- let i = S(t, r);
136
- if (i === 0) return 0;
137
- let a = x(e, t, r);
138
- return o ? o(a / i) * n * i : a * n;
139
- }, u = ((e, t = c) => l(e, t));
140
- return u.delays = (e = c) => Array.from({ length: e }, (t, n) => l(n, e)), u;
138
+ let n = O(t, i);
139
+ if (n === 0) return 0;
140
+ let a = D(e, t, i);
141
+ return o ? o(a / n) * r * n : a * r;
142
+ }, l = ((e, t = s) => c(e, t));
143
+ return l.delays = (e = s) => Array.from({ length: e }, (t, n) => c(n, e)), l;
141
144
  }
142
145
  //#endregion
143
146
  //#region src/animation/flip.ts
144
- var w = 300, T = (e) => {
147
+ var A = 300, j = (e) => {
145
148
  let t = e.getBoundingClientRect();
146
149
  return {
147
150
  x: t.x,
@@ -149,21 +152,21 @@ var w = 300, T = (e) => {
149
152
  width: t.width,
150
153
  height: t.height
151
154
  };
152
- }, E = (e, t) => {
155
+ }, M = (e, t) => {
153
156
  let n = e.at(1), r = n.translateX, i = n.translateY, a = n.scaleX, o = n.scaleY, s = e.at(t);
154
157
  return `translate(${s.translateX - r}px, ${s.translateY - i}px) scale(${a === 0 ? 1 : s.scaleX / a}, ${o === 0 ? 1 : s.scaleY / o})`;
155
- }, D = (e, t, n, r) => (e.style.transformOrigin = r, e.style.transform = E(t, 0), n <= 0 ? (e.style.transform = E(t, 1), Promise.resolve()) : new l().play(n, (n) => {
156
- e.style.transform = E(t, n);
158
+ }, N = (e, t, n, r) => (e.style.transformOrigin = r, e.style.transform = M(t, 0), n <= 0 ? (e.style.transform = M(t, 1), Promise.resolve()) : new o().play(n, (n) => {
159
+ e.style.transform = M(t, n);
157
160
  }));
158
- function O(e, t, n = {}) {
159
- let { duration: r = w, timingFunction: i, transformOrigin: a = "top left" } = n, o = T(e);
160
- return t(), D(e, new y(o, T(e), {
161
+ function P(e, t, n = {}) {
162
+ let { duration: r = A, timingFunction: i, transformOrigin: a = "top left" } = n, o = j(e);
163
+ return t(), N(e, new T(o, j(e), {
161
164
  ...i === void 0 ? {} : { timingFunction: i },
162
165
  transformOrigin: a
163
166
  }), r, a);
164
167
  }
165
- function k(e, t, n = {}) {
166
- let { duration: r = w, timingFunction: i, transformOrigin: a = "top left" } = n, o = new y(T(e), T(t), {
168
+ function F(e, t, n = {}) {
169
+ let { duration: r = A, timingFunction: i, transformOrigin: a = "top left" } = n, o = new T(j(e), j(t), {
167
170
  ...i === void 0 ? {} : { timingFunction: i },
168
171
  duration: r,
169
172
  transformOrigin: a
@@ -172,7 +175,7 @@ function k(e, t, n = {}) {
172
175
  }
173
176
  //#endregion
174
177
  //#region src/animation/drag.ts
175
- var A = 100, j = class {
178
+ var I = 100, L = class {
176
179
  spring;
177
180
  axis;
178
181
  transform;
@@ -186,7 +189,7 @@ var A = 100, j = class {
186
189
  onPointerMove = (e) => this.handleMove(e);
187
190
  onPointerUp = (e) => this.handleUp(e);
188
191
  constructor(e) {
189
- this.axis = e?.axis ?? "x", this.transform = e?.transform ?? ((e) => e), this.velocityWindow = e?.velocityWindow ?? A, this.spring = e?.spring ?? new h(e?.springOptions);
192
+ this.axis = e?.axis ?? "x", this.transform = e?.transform ?? ((e) => e), this.velocityWindow = e?.velocityWindow ?? I, this.spring = e?.spring ?? new t(e?.springOptions);
190
193
  }
191
194
  get dragging() {
192
195
  return this.capturedPointerId !== void 0;
@@ -262,194 +265,22 @@ var A = 100, j = class {
262
265
  return r <= 0 ? 0 : (n.value - t.value) / r * 1e3;
263
266
  }
264
267
  };
265
- function M(e, t) {
266
- let n = new j(t);
268
+ function R(e, t) {
269
+ let n = new L(t);
267
270
  return n.attach(e), n;
268
271
  }
269
272
  //#endregion
270
- //#region src/animation/decay.ts
271
- var N = 5;
272
- function P(e) {
273
- let t = e.initial ?? 0, n = e.velocity, r = e.friction ?? N;
274
- if (r <= 0) throw Error("decay() requires a friction coefficient > 0.");
275
- let i = t + n / r;
276
- return (e) => {
277
- if (e <= 0) return {
278
- value: t,
279
- velocity: n
280
- };
281
- let a = Math.exp(-r * e);
282
- return {
283
- value: i - n / r * a,
284
- velocity: n * a
285
- };
286
- };
287
- }
288
- function F(e) {
289
- let t = e.friction ?? N;
290
- if (t <= 0) throw Error("decayRest() requires a friction coefficient > 0.");
291
- return (e.initial ?? 0) + e.velocity / t;
292
- }
293
- //#endregion
294
- //#region src/animation/sequence.ts
295
- var I = class {
296
- entries = [];
297
- labels = /* @__PURE__ */ new Map();
298
- cursor = 0;
299
- _time = 0;
300
- respectReducedMotion;
301
- playback = new l();
302
- _boundFrame;
303
- _resolvePlay = null;
304
- _playOrigin = void 0;
305
- _playingPromise = null;
306
- _rate = 1;
307
- _repeatCount = 1;
308
- _yoyoOn = !1;
309
- _paused = !1;
310
- _lastClock = void 0;
311
- constructor(e) {
312
- this.respectReducedMotion = e?.respectReducedMotion ?? !1, this._boundFrame = this._frame.bind(this);
313
- }
314
- get duration() {
315
- let e = 0;
316
- for (let t of this.entries) {
317
- let n = t.at + t.animation.options.duration;
318
- n > e && (e = n);
319
- }
320
- return e;
321
- }
322
- get time() {
323
- return this._time;
324
- }
325
- get progress() {
326
- return this.duration === 0 ? 0 : this._time / this.duration;
327
- }
328
- set progress(e) {
329
- this.seek(t(e, 0, 1) * this.duration);
330
- }
331
- get rate() {
332
- return this._rate;
333
- }
334
- label(e, t) {
335
- return this.labels.set(e, this.resolvePosition(t)), this;
336
- }
337
- add(e, t) {
338
- let n = this.resolvePosition(t);
339
- return this.entries.push({
340
- animation: e,
341
- at: n
342
- }), this.entries.sort((e, t) => e.at - t.at), this.cursor = n + e.options.duration, this;
343
- }
344
- resolvePosition(e) {
345
- if (e === void 0) return this.cursor;
346
- if (typeof e == "number") return e;
347
- let t = /^([+-])=(\d*\.?\d+)$/.exec(e);
348
- if (t) {
349
- let e = t[1] === "+" ? 1 : -1;
350
- return this.cursor + e * Number.parseFloat(t[2]);
351
- }
352
- let n = this.labels.get(e);
353
- if (n === void 0) throw Error(`Sequence: unknown position "${e}". Register it with .label("${e}", at) first, or pass a number / "+=n" / "-=n".`);
354
- return n;
355
- }
356
- seek(e) {
357
- return this._time = e, this._applyAt(e), this;
358
- }
359
- _applyAt(e) {
360
- for (let { animation: n, at: r } of this.entries) {
361
- let i = t(e - r, 0, n.options.duration);
362
- n.interpFrames(i, !0);
363
- }
364
- }
365
- _fold(e) {
366
- let n = this.duration;
367
- if (n <= 0) return 0;
368
- let r = t(e, 0, n * this._repeatCount), i = Math.floor(r / n), a = r - i * n;
369
- return a === 0 && i > 0 && (--i, a = n), this._yoyoOn && i % 2 == 1 ? n - a : a;
370
- }
371
- setTargets(...e) {
372
- for (let { animation: t } of this.entries) t.setTargets(...e);
373
- return this;
374
- }
375
- get finished() {
376
- return this._playingPromise ?? Promise.resolve();
377
- }
378
- play() {
379
- if (this._playingPromise) return this._playingPromise;
380
- if (this.respectReducedMotion && L()) return this.seek(this.duration), Promise.resolve();
381
- for (let { animation: e, at: t } of this.entries) e.startTime = t, e.started = !0, e.managed = !0;
382
- this._time = 0, this._paused = !1, this._playOrigin = void 0, this._lastClock = void 0;
383
- let e = new Promise((e) => {
384
- this._resolvePlay = e, this.playback.loop(this._boundFrame);
385
- });
386
- return this._playingPromise = e, e.finally(() => {
387
- this._playingPromise = null;
388
- }), e;
389
- }
390
- async _frame(e) {
391
- this._playOrigin === void 0 && (this._playOrigin = this._rate === 0 ? e : e - this._time / this._rate), this._lastClock = e;
392
- let t = (e - this._playOrigin) * this._rate, n = this.duration * this._repeatCount, r = this._rate >= 0 ? t >= n : t <= 0, i = r ? this._rate >= 0 ? this._restPhase() : 0 : this._fold(t);
393
- if (this._time = i, this._isForwardMonotone()) for (let { animation: e, at: t } of this.entries) i >= t && i - t < e.options.duration && await e.advanceTo(i);
394
- if (this._applyAt(i), r) {
395
- this._settle();
396
- let e = this._resolvePlay;
397
- return this._resolvePlay = null, e?.(), !1;
398
- }
399
- return !0;
400
- }
401
- _isForwardMonotone() {
402
- return this._rate === 1 && this._repeatCount === 1 && !this._yoyoOn;
403
- }
404
- _restPhase() {
405
- let e = this.duration;
406
- return this._yoyoOn && (this._repeatCount - 1) % 2 == 1 ? 0 : e;
407
- }
408
- _reanchor() {
409
- if (!this._playingPromise) return;
410
- let e = this._lastClock;
411
- if (e === void 0) {
412
- this._playOrigin = void 0;
413
- return;
414
- }
415
- this._playOrigin = this._rate === 0 ? e : e - this._time / this._rate;
416
- }
417
- _settle() {
418
- for (let { animation: e } of this.entries) e.managed = !1, e.started = !1, e.startTime = void 0;
419
- this._playOrigin = void 0, this._lastClock = void 0, this._paused = !1;
420
- }
421
- stop() {
422
- this.playback.stop(), this._settle();
423
- let e = this._resolvePlay;
424
- return this._resolvePlay = null, e?.(), this;
425
- }
426
- pause() {
427
- return !this._playingPromise || this._paused ? this : (this._paused = !0, this.playback.stop(), this._playOrigin = void 0, this);
428
- }
429
- resume() {
430
- return !this._playingPromise || !this._paused ? this : (this._paused = !1, this._playOrigin = void 0, this._lastClock = void 0, this.playback.loop(this._boundFrame), this);
431
- }
432
- timeScale(e) {
433
- if (!Number.isFinite(e)) throw Error(`Sequence.timeScale(n): n must be a finite number, got ${e}.`);
434
- return this._rate = e, this._reanchor(), this;
435
- }
436
- reverse() {
437
- return this._rate = -this._rate, this._reanchor(), this;
438
- }
439
- repeat(e) {
440
- if (e !== Infinity && (!Number.isInteger(e) || e < 1)) throw Error(`Sequence.repeat(count): count must be a positive integer or Infinity, got ${e}.`);
441
- return this._repeatCount = e, this;
442
- }
443
- yoyo(e = !0) {
444
- return this._yoyoOn = e, this;
445
- }
446
- }, L = () => typeof matchMedia == "function" && matchMedia("(prefers-reduced-motion: reduce)").matches, R = async () => {
447
- let [e, t, n, r, i] = await Promise.all([
448
- import("./engine-Gk4Q7ltr.js"),
449
- import("./animate-WjeAtXAe.js"),
450
- import("./motion-path-DQ73oD2j.js"),
451
- import("./draw-svg-Dm9f0vTl.js"),
452
- import("./animations-WlZvjmDT.js")
273
+ //#region src/animation/index.ts
274
+ var z = async () => {
275
+ let [e, t, n, r, i, a, o, s] = await Promise.all([
276
+ import("./engine-BKm1GcJT.js"),
277
+ import("./animate-D5KoLKwi.js"),
278
+ import("./motion-path-CqmlG74k.js"),
279
+ import("./draw-svg-CF2cTJj-.js"),
280
+ import("./ingest-BFBYGTH-.js"),
281
+ import("./scroll-scene-JpRpH1uU.js"),
282
+ import("./compile-C0xOTIC4.js"),
283
+ import("./animations-DaMcGoCd.js")
453
284
  ]);
454
285
  return Object.assign({
455
286
  animate: t.animate,
@@ -457,8 +288,23 @@ var I = class {
457
288
  fromMotionPath: n.fromMotionPath,
458
289
  DrawSVG: r.DrawSVG,
459
290
  fromDrawSVG: r.fromDrawSVG,
460
- presets: i
291
+ fromStyleSheets: i.fromStyleSheets,
292
+ fromLiveAnimations: i.fromLiveAnimations,
293
+ resolveLiveKeyframes: i.resolveLiveKeyframes,
294
+ adoptRunning: i.adoptRunning,
295
+ ScrollScene: a.ScrollScene,
296
+ createScrollScene: a.createScrollScene,
297
+ parseScrollCSS: a.parseScrollCSS,
298
+ parseScrollTimeline: a.parseScrollTimeline,
299
+ parseScrollRange: a.parseScrollRange,
300
+ serializeScrollOptions: a.serializeScrollOptions,
301
+ roundTripScrollCSS: a.roundTripScrollCSS,
302
+ dispatchScrollBackend: a.dispatchScrollBackend,
303
+ resolveRange: a.resolveRange,
304
+ pinCSS: a.pinCSS,
305
+ compileToCSS: o.compileToCSS,
306
+ presets: s
461
307
  }, e);
462
308
  };
463
309
  //#endregion
464
- export { i as AnimationOptionError, j as Draggable, y as ElementMorph, f as ManualTimeline, _ as NumericAnimation, l as RAFPlayback, c as ScrollTimeline, I as Sequence, e as SmoothProgress, h as SpringProgress, d as Timeline, r as UnknownEasingError, a as createNativeTimeline, P as decay, F as decayRest, M as drag, O as flip, k as flipShared, R as loadAnimationEngine, u as resolveEasing, m as springLinearStops, g as springTimingFunction, C as stagger, s as toEasing };
310
+ export { h as AnimationOptionError, L as Draggable, T as ElementMorph, p as ManualTimeline, C as NumericAnimation, o as RAFPlayback, c as ScrollTimeline, S as Sequence, n as SmoothProgress, t as SpringProgress, d as Timeline, g as UnknownEasingError, a as createNativeTimeline, x as decay, b as decayRest, R as drag, P as flip, F as flipShared, z as loadAnimationEngine, l as probeVelocity, m as reducedMotionScale, f as reseatToSpring, i as resolveEasing, v as springLinearStops, y as springTimingFunction, k as stagger, e as toEasing };
@@ -1,4 +1,4 @@
1
- import { CSSKeyframesAnimation as e } from "./engine-Gk4Q7ltr.js";
1
+ import { CSSKeyframesAnimation as e } from "./engine-BKm1GcJT.js";
2
2
  //#region src/animation/motion-path.ts
3
3
  var t = (e) => typeof e == "number" ? `${e}%` : e;
4
4
  function n(n, r) {
@@ -0,0 +1,197 @@
1
+ import { a as e, c as t, f as n, i as r } from "./timeline-BjcmprQ6.js";
2
+ import { n as i } from "./decay-BvNmFk51.js";
3
+ import { n as a, t as o } from "./waapi-Bd5QadtA.js";
4
+ import { extractTimelineOptions as s, parseAnimationRange as c, parseAnimationTimeline as l, parseCSSStylesheet as u, serializeTimelineOptions as d } from "@mkbabb/value.js";
5
+ //#region src/animation/scroll-grammar.ts
6
+ function f(e) {
7
+ return l(e);
8
+ }
9
+ function p(e) {
10
+ return c(e);
11
+ }
12
+ function m(e) {
13
+ return s(typeof e == "string" ? u(e) : e);
14
+ }
15
+ function h(e) {
16
+ return d(e);
17
+ }
18
+ function g(e) {
19
+ let t = m(e);
20
+ return {
21
+ options: t,
22
+ declarations: h(t)
23
+ };
24
+ }
25
+ //#endregion
26
+ //#region src/animation/scroll-scene.ts
27
+ var _ = {
28
+ normal: {
29
+ start: 0,
30
+ end: 1
31
+ },
32
+ cover: {
33
+ start: .25,
34
+ end: .75
35
+ },
36
+ contain: {
37
+ start: .375,
38
+ end: .625
39
+ },
40
+ entry: {
41
+ start: 0,
42
+ end: .25
43
+ },
44
+ exit: {
45
+ start: .75,
46
+ end: 1
47
+ },
48
+ "entry-crossing": {
49
+ start: 0,
50
+ end: .25
51
+ },
52
+ "exit-crossing": {
53
+ start: .75,
54
+ end: 1
55
+ }
56
+ };
57
+ function v(e) {
58
+ if (e == null) return null;
59
+ let t = e.trim();
60
+ if (t.endsWith("%")) {
61
+ let e = Number.parseFloat(t.slice(0, -1));
62
+ return Number.isFinite(e) ? e / 100 : null;
63
+ }
64
+ return null;
65
+ }
66
+ function y(e, t) {
67
+ if (e == null) return t;
68
+ let n = v(e.offset);
69
+ if (n != null) {
70
+ if (e.phase != null && e.phase !== "normal") {
71
+ let t = _[e.phase];
72
+ return t.start + n * (t.end - t.start);
73
+ }
74
+ return n;
75
+ }
76
+ return e.phase == null ? t : _[e.phase].start;
77
+ }
78
+ function b(e) {
79
+ if (e == null) return {
80
+ start: 0,
81
+ end: 1
82
+ };
83
+ let t = y(e.start, 0), n = y(e.end, 1);
84
+ return n > t ? {
85
+ start: t,
86
+ end: n
87
+ } : {
88
+ start: 0,
89
+ end: 1
90
+ };
91
+ }
92
+ function x(e) {
93
+ let { animation: t, nativeSpec: n, scrub: i, snap: s, velocity: c } = e;
94
+ if (i) return {
95
+ backend: "js",
96
+ reason: "scrub smoothing requested (native scroll has no SmoothProgress smoother)"
97
+ };
98
+ if (s) return {
99
+ backend: "js",
100
+ reason: "physics snap requested (native scroll has no decay/spring settle)"
101
+ };
102
+ if (c) return {
103
+ backend: "js",
104
+ reason: "scroll velocity / non-DOM driving requested (JS-only capability)"
105
+ };
106
+ if (t == null || n == null) return {
107
+ backend: "js",
108
+ reason: "non-DOM target or no native timeline spec (the universal JS driver)"
109
+ };
110
+ let l = a(t);
111
+ if (!l.eligible) return {
112
+ backend: "js",
113
+ reason: l.reason
114
+ };
115
+ if (r(n) == null) return {
116
+ backend: "js",
117
+ reason: "native scroll/view timeline unavailable (feature absent)"
118
+ };
119
+ let u = o(t, n);
120
+ return u.attached ? {
121
+ backend: "native",
122
+ attachment: u
123
+ } : {
124
+ backend: "js",
125
+ reason: u.reason
126
+ };
127
+ }
128
+ function S(e) {
129
+ let t = ["position: sticky;"];
130
+ return e?.bottom == null ? t.push(`top: ${e?.top ?? 0}px;`) : t.push(`bottom: ${e.bottom}px;`), t.join(" ");
131
+ }
132
+ var C = class {
133
+ resolvedRange;
134
+ snapPoints;
135
+ snapSpring;
136
+ scrubSeconds;
137
+ smoother;
138
+ rawScroll = 0;
139
+ localProgress = 0;
140
+ wasInside = !1;
141
+ subscribers = new Map([["enter", /* @__PURE__ */ new Set()], ["leave", /* @__PURE__ */ new Set()]]);
142
+ constructor(r = {}) {
143
+ if (this.resolvedRange = b(r.range), this.scrubSeconds = r.scrub ?? 0, this.snapPoints = r.snap != null && r.snap.length > 0 ? r.snap : void 0, this.scrubSeconds > 0) {
144
+ let e = n(1 / (this.scrubSeconds * 60 + 1), .01, 1);
145
+ this.smoother = new t({
146
+ damping: e,
147
+ clamp: !0,
148
+ ...r.smoothing
149
+ });
150
+ }
151
+ this.snapPoints != null && (this.snapSpring = new e({ ...r.snapSpring }));
152
+ }
153
+ get range() {
154
+ return this.resolvedRange;
155
+ }
156
+ scrollProgress(e) {
157
+ this.rawScroll = n(e, 0, 1);
158
+ let { start: t, end: r } = this.resolvedRange, i = r - t, a = i > 0 ? n((this.rawScroll - t) / i, 0, 1) : 0, o = this.rawScroll >= t && this.rawScroll <= r;
159
+ return o && !this.wasInside && this.fire("enter", a), !o && this.wasInside && this.fire("leave", a), this.wasInside = o, this.smoother ? (this.smoother.setTarget(a), this.localProgress = this.smoother.current) : this.localProgress = a, this.localProgress;
160
+ }
161
+ tick(e) {
162
+ return this.smoother && (this.smoother.tickDt(e), this.localProgress = this.smoother.current), this.localProgress;
163
+ }
164
+ get progress() {
165
+ return this.localProgress;
166
+ }
167
+ get settled() {
168
+ return this.smoother == null || this.smoother.settled;
169
+ }
170
+ snapTo(e = 0) {
171
+ if (this.snapPoints == null || this.snapSpring == null) return null;
172
+ let t = n(i({
173
+ initial: this.localProgress,
174
+ velocity: e
175
+ }), 0, 1), r = this.snapPoints[0], a = Math.abs(t - r);
176
+ for (let e of this.snapPoints) {
177
+ let n = Math.abs(t - e);
178
+ n < a && (a = n, r = e);
179
+ }
180
+ return this.snapSpring.reset(this.localProgress, e), this.snapSpring.target = r, r;
181
+ }
182
+ tickSnap(e) {
183
+ return this.snapSpring && !this.snapSpring.settled && (this.snapSpring.tickDt(e), this.localProgress = this.snapSpring.value), this.localProgress;
184
+ }
185
+ on(e, t) {
186
+ let n = this.subscribers.get(e);
187
+ return n.add(t), () => n.delete(t);
188
+ }
189
+ fire(e, t) {
190
+ for (let n of this.subscribers.get(e)) n(t);
191
+ }
192
+ };
193
+ function w(e = {}) {
194
+ return new C(e);
195
+ }
196
+ //#endregion
197
+ export { C as ScrollScene, w as createScrollScene, x as dispatchScrollBackend, m as parseScrollCSS, p as parseScrollRange, f as parseScrollTimeline, S as pinCSS, b as resolveRange, g as roundTripScrollCSS, h as serializeScrollOptions };