@ssgoi/core 2.5.5 → 3.0.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.
Files changed (68) hide show
  1. package/dist/animator/animate/css-runner.d.ts +17 -0
  2. package/dist/animator/animate/css-runner.d.ts.map +1 -0
  3. package/dist/animator/animate/index.d.ts +42 -0
  4. package/dist/animator/animate/index.d.ts.map +1 -0
  5. package/dist/animator/animate/tick-runner.d.ts +16 -0
  6. package/dist/animator/animate/tick-runner.d.ts.map +1 -0
  7. package/dist/animator/animate/types.d.ts +31 -0
  8. package/dist/animator/animate/types.d.ts.map +1 -0
  9. package/dist/animator/animation.d.ts +57 -0
  10. package/dist/animator/animation.d.ts.map +1 -0
  11. package/dist/animator/index.d.ts +34 -33
  12. package/dist/animator/index.d.ts.map +1 -1
  13. package/dist/animator/multi-animator.d.ts +98 -0
  14. package/dist/animator/multi-animator.d.ts.map +1 -0
  15. package/dist/animator/spring-core.d.ts +63 -0
  16. package/dist/animator/spring-core.d.ts.map +1 -0
  17. package/dist/index.cjs +2 -2
  18. package/dist/index.js +700 -818
  19. package/dist/ssgoi-transition/create-ssgoi-transition-context.d.ts.map +1 -1
  20. package/dist/ssgoi-transition/create-swipe-detector.d.ts +1 -0
  21. package/dist/ssgoi-transition/create-swipe-detector.d.ts.map +1 -1
  22. package/dist/transition/create-transition-callback.d.ts +2 -2
  23. package/dist/transition/create-transition-callback.d.ts.map +1 -1
  24. package/dist/transition/transition-strategy.d.ts +28 -17
  25. package/dist/transition/transition-strategy.d.ts.map +1 -1
  26. package/dist/transition/transition.d.ts +2 -18
  27. package/dist/transition/transition.d.ts.map +1 -1
  28. package/dist/transitions/blur.d.ts +5 -5
  29. package/dist/transitions/blur.d.ts.map +1 -1
  30. package/dist/transitions/bounce.d.ts +5 -5
  31. package/dist/transitions/bounce.d.ts.map +1 -1
  32. package/dist/transitions/fade.d.ts +5 -5
  33. package/dist/transitions/fade.d.ts.map +1 -1
  34. package/dist/transitions/fly.d.ts +5 -5
  35. package/dist/transitions/fly.d.ts.map +1 -1
  36. package/dist/transitions/index.cjs +1 -1
  37. package/dist/transitions/index.js +206 -207
  38. package/dist/transitions/mask.d.ts +5 -5
  39. package/dist/transitions/mask.d.ts.map +1 -1
  40. package/dist/transitions/none.d.ts +3 -3
  41. package/dist/transitions/none.d.ts.map +1 -1
  42. package/dist/transitions/rotate.d.ts +5 -5
  43. package/dist/transitions/rotate.d.ts.map +1 -1
  44. package/dist/transitions/scale.d.ts +5 -5
  45. package/dist/transitions/scale.d.ts.map +1 -1
  46. package/dist/transitions/slide.d.ts +5 -5
  47. package/dist/transitions/slide.d.ts.map +1 -1
  48. package/dist/types.cjs +1 -1
  49. package/dist/types.d.ts +142 -102
  50. package/dist/types.d.ts.map +1 -1
  51. package/dist/types.js +69 -6
  52. package/dist/view-transitions/blind.d.ts +0 -1
  53. package/dist/view-transitions/blind.d.ts.map +1 -1
  54. package/dist/view-transitions/drill.d.ts.map +1 -1
  55. package/dist/view-transitions/fade.d.ts.map +1 -1
  56. package/dist/view-transitions/hero.d.ts.map +1 -1
  57. package/dist/view-transitions/index.cjs +13 -13
  58. package/dist/view-transitions/index.js +499 -492
  59. package/dist/view-transitions/scroll.d.ts.map +1 -1
  60. package/dist/view-transitions/slide.d.ts.map +1 -1
  61. package/dist/view-transitions/strip.d.ts.map +1 -1
  62. package/package.json +1 -1
  63. package/dist/animator/animate.d.ts +0 -35
  64. package/dist/animator/animate.d.ts.map +0 -1
  65. package/dist/animator/animation-scheduler.d.ts +0 -47
  66. package/dist/animator/animation-scheduler.d.ts.map +0 -1
  67. package/dist/test-utils.d.ts +0 -46
  68. package/dist/test-utils.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,65 +1,65 @@
1
- var _ = Object.defineProperty;
2
- var F = (n, t, e) => t in n ? _(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var m = (n, t, e) => F(n, typeof t != "symbol" ? t + "" : t, e);
4
- import { isMultiSpring as V } from "./types.js";
5
- import { isSingleSpring as at } from "./types.js";
6
- import { j as lt } from "./jaemin-BWkrXq0V.js";
7
- class $ {
1
+ var $ = Object.defineProperty;
2
+ var j = (i, n, t) => n in i ? $(i, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[n] = t;
3
+ var d = (i, n, t) => j(i, typeof n != "symbol" ? n + "" : n, t);
4
+ import { normalizeToMultiSpring as V, normalizeMultiSpringSchedule as M } from "./types.js";
5
+ import { isCssAnimation as vt, isMultiSpring as St, isSingleSpring as Ct, isTickAnimation as At, validateAnimationMode as Et, validateSpringItem as Tt } from "./types.js";
6
+ import { j as bt } from "./jaemin-BWkrXq0V.js";
7
+ class W {
8
8
  constructor() {
9
- m(this, "listeners", /* @__PURE__ */ new Set());
10
- m(this, "rafId", null);
11
- m(this, "isRunning", !1);
9
+ d(this, "listeners", /* @__PURE__ */ new Set());
10
+ d(this, "rafId", null);
11
+ d(this, "isRunning", !1);
12
12
  // Timing
13
- m(this, "startTime", Date.now());
14
- m(this, "lastUpdate", this.startTime);
15
- m(this, "elapsed", 0);
13
+ d(this, "startTime", Date.now());
14
+ d(this, "lastUpdate", this.startTime);
15
+ d(this, "elapsed", 0);
16
16
  // Lag smoothing (mobile optimization)
17
- m(this, "lagThreshold", 500);
17
+ d(this, "lagThreshold", 500);
18
18
  // ms - detect tab switches, backgrounding
19
- m(this, "adjustedLag", 33);
19
+ d(this, "adjustedLag", 33);
20
20
  // ms - max time jump to prevent animation skip
21
- m(this, "maxDeltaTime", 33);
21
+ d(this, "maxDeltaTime", 33);
22
22
  // ms - clamp for physics stability (30fps minimum)
23
23
  // FPS throttling
24
- m(this, "gap", 1e3 / 240);
24
+ d(this, "gap", 1e3 / 240);
25
25
  // max 240fps
26
- m(this, "nextTime", this.gap);
27
- m(this, "tick", () => {
28
- const t = Date.now();
29
- let i = t - this.lastUpdate;
30
- i > this.lagThreshold || i < 0 ? (this.startTime += i - this.adjustedLag, i = this.adjustedLag) : i > this.maxDeltaTime && (i = this.maxDeltaTime), this.lastUpdate = t;
31
- const r = t - this.startTime, o = r - this.nextTime;
26
+ d(this, "nextTime", this.gap);
27
+ d(this, "tick", () => {
28
+ const n = Date.now();
29
+ let e = n - this.lastUpdate;
30
+ e > this.lagThreshold || e < 0 ? (this.startTime += e - this.adjustedLag, e = this.adjustedLag) : e > this.maxDeltaTime && (e = this.maxDeltaTime), this.lastUpdate = n;
31
+ const r = n - this.startTime, o = r - this.nextTime;
32
32
  if (o > 0) {
33
- const s = i / 1e3;
34
- this.elapsed = r / 1e3, this.nextTime += o + (o >= this.gap ? 4 : this.gap - o), this.listeners.forEach((d) => {
35
- d(s, this.elapsed);
33
+ const s = e / 1e3;
34
+ this.elapsed = r / 1e3, this.nextTime += o + (o >= this.gap ? 4 : this.gap - o), this.listeners.forEach((a) => {
35
+ a(s, this.elapsed);
36
36
  });
37
37
  }
38
38
  this.listeners.size > 0 ? this.rafId = requestAnimationFrame(this.tick) : (this.isRunning = !1, this.rafId = null);
39
39
  });
40
40
  }
41
- subscribe(t) {
42
- return this.listeners.add(t), this.isRunning || (this.isRunning = !0, this.rafId = requestAnimationFrame(this.tick)), () => {
43
- this.unsubscribe(t);
41
+ subscribe(n) {
42
+ return this.listeners.add(n), this.isRunning || (this.isRunning = !0, this.rafId = requestAnimationFrame(this.tick)), () => {
43
+ this.unsubscribe(n);
44
44
  };
45
45
  }
46
- unsubscribe(t) {
47
- this.listeners.delete(t), this.listeners.size === 0 && this.rafId !== null && (cancelAnimationFrame(this.rafId), this.isRunning = !1, this.rafId = null);
46
+ unsubscribe(n) {
47
+ this.listeners.delete(n), this.listeners.size === 0 && this.rafId !== null && (cancelAnimationFrame(this.rafId), this.isRunning = !1, this.rafId = null);
48
48
  }
49
49
  /**
50
50
  * Configure lag smoothing behavior
51
51
  * @param threshold - Time threshold to detect lag (default: 500ms)
52
52
  * @param adjustedLag - Max time jump when lag detected (default: 33ms)
53
53
  */
54
- lagSmoothing(t, e) {
55
- this.lagThreshold = t, this.adjustedLag = Math.min(e, t);
54
+ lagSmoothing(n, t) {
55
+ this.lagThreshold = n, this.adjustedLag = Math.min(t, n);
56
56
  }
57
57
  /**
58
58
  * Set maximum FPS
59
59
  * @param fps - Target FPS (default: 240)
60
60
  */
61
- fps(t) {
62
- this.gap = 1e3 / t, this.nextTime = this.elapsed * 1e3 + this.gap;
61
+ fps(n) {
62
+ this.gap = 1e3 / n, this.nextTime = this.elapsed * 1e3 + this.gap;
63
63
  }
64
64
  getListenerCount() {
65
65
  return this.listeners.size;
@@ -68,1016 +68,898 @@ class $ {
68
68
  return this.elapsed;
69
69
  }
70
70
  }
71
- const I = new $();
72
- function k(n) {
71
+ const P = new W();
72
+ function z(i) {
73
+ const n = i.stiffness, t = i.damping, e = 1, r = Math.sqrt(n / e), o = t / (2 * Math.sqrt(n * e));
74
+ return { omega: r, zeta: o };
75
+ }
76
+ function _(i, n, t, e) {
77
+ const { omega: r, zeta: o } = t, { position: s, velocity: a } = i, c = Math.min(e, 0.033), u = -2 * c * o * r * a, h = c * r * r * (n - s), l = a + u + h;
78
+ return {
79
+ position: s + c * l,
80
+ velocity: l
81
+ };
82
+ }
83
+ const K = 0.01, U = 0.01, H = 0.05;
84
+ function N(i, n) {
85
+ const t = Math.abs(n - i.position), e = Math.abs(i.velocity);
86
+ return t < K && e < U;
87
+ }
88
+ function G(i) {
73
89
  const {
74
- from: t,
75
- to: e,
76
- stiffness: i,
77
- damping: r,
78
- mass: o,
79
- velocity: s = 0,
80
- onUpdate: d,
81
- onComplete: l
82
- } = n;
83
- let h = t, u = s, a = !0;
84
- const p = Math.sqrt(i / o), c = r / (2 * Math.sqrt(i * o)), g = 0.01, w = 0.01;
85
- let f = 0;
86
- const y = 0.05, S = (T) => {
87
- if (!a) return;
88
- const C = Math.min(T, 0.033), v = -2 * C * c * p * u, b = C * p * p * (e - h);
89
- u += v + b, h += C * u;
90
- const E = Math.abs(e - h), A = Math.abs(u);
91
- if (E < g && A < w) {
92
- if (f += C, f >= y) {
93
- h = e, u = 0, a = !1, d(h), I.unsubscribe(S), l();
94
- return;
90
+ from: n,
91
+ to: t,
92
+ spring: e,
93
+ velocity: r = 0,
94
+ onUpdate: o,
95
+ onComplete: s,
96
+ onStart: a
97
+ } = i;
98
+ let c = { position: n, velocity: r }, u = !0, h = 0, l = !1;
99
+ const g = z(e), w = (p) => {
100
+ if (u) {
101
+ if (l || (l = !0, a == null || a()), c = _(c, t, g, p), N(c, t)) {
102
+ if (h += Math.min(p, 0.033), h >= H) {
103
+ c = { position: t, velocity: 0 }, u = !1, o(c.position), P.unsubscribe(w), s();
104
+ return;
105
+ }
106
+ } else
107
+ h = 0;
108
+ o(c.position);
109
+ }
110
+ };
111
+ return P.subscribe(w), {
112
+ stop: () => {
113
+ u && (u = !1, P.unsubscribe(w));
114
+ },
115
+ getPosition: () => c.position,
116
+ getVelocity: () => c.velocity,
117
+ isRunning: () => u
118
+ };
119
+ }
120
+ const b = 1e3 / 60;
121
+ function B(i, n, t, e = 0) {
122
+ const r = z(t), o = 600;
123
+ let s = { position: i, velocity: e }, a = 0;
124
+ const c = [];
125
+ for (let u = 0; u < o; u++) {
126
+ const h = u * b;
127
+ if (c.push({
128
+ time: h,
129
+ position: s.position,
130
+ velocity: s.velocity
131
+ }), s = _(s, n, r, b / 1e3), N(s, n)) {
132
+ if (a += b / 1e3, a >= H) {
133
+ c.push({
134
+ time: (u + 1) * b,
135
+ position: n,
136
+ velocity: 0
137
+ });
138
+ break;
95
139
  }
96
140
  } else
97
- f = 0;
98
- d(h);
141
+ a = 0;
142
+ }
143
+ return c;
144
+ }
145
+ function O(i, n) {
146
+ if (i.length === 0)
147
+ return { position: 0, velocity: 0 };
148
+ const t = i[0], e = i[i.length - 1];
149
+ if (n <= 0)
150
+ return { position: t.position, velocity: t.velocity };
151
+ if (n >= e.time)
152
+ return { position: e.position, velocity: e.velocity };
153
+ let r = 0, o = i.length - 1;
154
+ for (; r < o - 1; ) {
155
+ const u = Math.floor((r + o) / 2);
156
+ i[u].time <= n ? r = u : o = u;
157
+ }
158
+ const s = i[r], a = i[o], c = (n - s.time) / (a.time - s.time);
159
+ return {
160
+ position: s.position + (a.position - s.position) * c,
161
+ velocity: s.velocity + (a.velocity - s.velocity) * c
99
162
  };
100
- return I.subscribe(S), {
163
+ }
164
+ function J(i, n) {
165
+ return i.map((t) => n(t.position));
166
+ }
167
+ function Q(i) {
168
+ const {
169
+ element: n,
170
+ from: t,
171
+ to: e,
172
+ spring: r,
173
+ velocity: o = 0,
174
+ style: s,
175
+ onComplete: a,
176
+ onStart: c
177
+ } = i, u = B(t, e, r, o);
178
+ if (u.length === 0)
179
+ return c == null || c(), a(), {
180
+ stop: () => {
181
+ },
182
+ getPosition: () => e,
183
+ getVelocity: () => 0,
184
+ isRunning: () => !1
185
+ };
186
+ const h = J(u, s), l = u[u.length - 1], g = l.time, w = n.animate(h, {
187
+ duration: g,
188
+ fill: "forwards",
189
+ easing: "linear"
190
+ // Spring physics already applied in keyframes
191
+ });
192
+ let p = !0;
193
+ const y = performance.now();
194
+ return c == null || c(), w.onfinish = () => {
195
+ p && (p = !1, a());
196
+ }, {
101
197
  stop: () => {
102
- a && (a = !1, I.unsubscribe(S));
103
- }
198
+ p && (p = !1, w.cancel());
199
+ },
200
+ getPosition: () => {
201
+ if (!p)
202
+ return l.position;
203
+ const m = performance.now() - y;
204
+ return O(u, m).position;
205
+ },
206
+ getVelocity: () => {
207
+ if (!p)
208
+ return 0;
209
+ const m = performance.now() - y;
210
+ return O(u, m).velocity;
211
+ },
212
+ isRunning: () => p
104
213
  };
105
214
  }
106
- class O {
215
+ function Z(i) {
216
+ const { from: n, to: t, spring: e, velocity: r, onComplete: o, onStart: s, tick: a, css: c } = i;
217
+ if (a && c)
218
+ throw new Error("Cannot use both 'tick' and 'css' options together");
219
+ return !a && !c ? (s == null || s(), o(), {
220
+ stop: () => {
221
+ },
222
+ getPosition: () => t,
223
+ getVelocity: () => 0,
224
+ isRunning: () => !1
225
+ }) : c ? Q({
226
+ element: c.element,
227
+ from: n,
228
+ to: t,
229
+ spring: e,
230
+ velocity: r,
231
+ style: c.style,
232
+ onComplete: o,
233
+ onStart: s
234
+ }) : G({
235
+ from: n,
236
+ to: t,
237
+ spring: e,
238
+ velocity: r,
239
+ onUpdate: a,
240
+ onComplete: o,
241
+ onStart: s
242
+ });
243
+ }
244
+ class X {
245
+ }
246
+ class I extends X {
107
247
  constructor(t) {
108
- m(this, "options");
109
- m(this, "currentValue");
110
- m(this, "velocity");
111
- m(this, "isAnimating", !1);
112
- m(this, "controls", null);
113
- // For object animations
114
- m(this, "animationMap", null);
115
- m(this, "activeAnimations", /* @__PURE__ */ new Set());
116
- m(this, "completedAnimations", /* @__PURE__ */ new Set());
117
- m(this, "updatedProperties", /* @__PURE__ */ new Set());
118
- m(this, "animate", (t = !1) => {
119
- !this.isAnimating && this.options.onStart && this.options.onStart(), this.isAnimating = !0;
120
- const e = t ? this.options.from : this.options.to;
121
- if (typeof this.currentValue == "object" && this.currentValue !== null) {
122
- this.animateObject(e);
123
- return;
124
- }
125
- let i = this.currentValue, r = performance.now();
126
- const o = {
127
- from: this.currentValue,
128
- to: e,
129
- stiffness: this.options.spring.stiffness,
130
- damping: this.options.spring.damping,
131
- mass: 1
132
- };
133
- typeof this.velocity == "number" && (o.velocity = this.velocity * 1e3), this.controls = k({
134
- ...o,
135
- onUpdate: (s) => {
136
- const d = performance.now(), l = (d - r) / 1e3;
137
- if (l > 0) {
138
- if (typeof s == "number" && typeof i == "number") {
139
- const h = (s - i) / l;
140
- this.velocity = h / 1e3;
141
- } else if (typeof s == "object" && s !== null) {
142
- const h = {};
143
- Object.keys(s).forEach((u) => {
144
- const a = s[u], p = i[u];
145
- if (typeof a == "number" && typeof p == "number") {
146
- const c = (a - p) / l;
147
- h[u] = c / 1e3;
148
- }
149
- }), this.velocity = h;
150
- }
151
- i = s, r = d;
152
- }
153
- this.currentValue = s, this.options.onUpdate(s);
154
- },
155
- onComplete: () => {
156
- this.currentValue = e, this.isAnimating = !1, this.controls = null, typeof this.velocity == "object" && this.velocity !== null ? Object.keys(this.velocity).forEach((s) => {
157
- this.velocity[s] = 0;
158
- }) : this.velocity = 0, this.options.onComplete();
159
- }
160
- });
161
- });
162
- m(this, "animateObject", (t) => {
163
- const e = this.currentValue, i = Object.keys(e);
164
- this.animationMap = /* @__PURE__ */ new Map(), this.activeAnimations.clear(), this.completedAnimations.clear(), this.updatedProperties.clear();
165
- const r = { ...e }, o = {};
166
- let s = !1;
167
- const d = () => {
168
- const l = i.filter((u) => !this.completedAnimations.has(u));
169
- if (l.every(
170
- (u) => this.updatedProperties.has(u)
171
- ) && l.length > 0) {
172
- if (typeof this.velocity == "object" && this.velocity) {
173
- const u = performance.now();
174
- Object.keys(r).forEach((a) => {
175
- if (o[a]) {
176
- const p = (u - o[a]) / 1e3, c = this.currentValue[a], g = r[a];
177
- typeof c == "number" && typeof g == "number" && p > 0 && (this.velocity[a] = (g - c) / p / 1e3);
178
- }
179
- o[a] = u;
180
- });
181
- }
182
- this.currentValue = { ...r }, this.options.onUpdate(this.currentValue), this.updatedProperties.clear(), !s && this.options.onStart && (s = !0, this.options.onStart());
183
- }
184
- };
185
- i.forEach((l) => {
186
- this.activeAnimations.add(l);
187
- const h = {
188
- from: e[l],
189
- to: t[l],
190
- stiffness: this.options.spring.stiffness,
191
- damping: this.options.spring.damping,
192
- mass: 1
193
- };
194
- typeof this.velocity == "object" && this.velocity && l in this.velocity && (h.velocity = this.velocity[l] * 1e3);
195
- const u = k({
196
- ...h,
197
- onUpdate: (a) => {
198
- r[l] = a, this.updatedProperties.add(l), d();
199
- },
200
- onComplete: () => {
201
- this.completedAnimations.add(l), this.updatedProperties.delete(l), this.completedAnimations.size === i.length && (this.currentValue = t, this.isAnimating = !1, this.animationMap = null, typeof this.velocity == "object" && this.velocity && Object.keys(this.velocity).forEach((a) => {
202
- this.velocity[a] = 0;
203
- }), this.options.onComplete());
204
- }
205
- });
206
- this.animationMap.set(l, u);
207
- });
208
- });
209
- if (this.options = {
248
+ super();
249
+ d(this, "options");
250
+ d(this, "controls", null);
251
+ d(this, "isAnimating", !1);
252
+ d(this, "currentValue");
253
+ d(this, "currentVelocity", 0);
254
+ if (t.tick && t.css)
255
+ throw new Error("Cannot use both 'tick' and 'css' options together");
256
+ this.options = {
210
257
  from: t.from ?? 0,
211
258
  to: t.to ?? 1,
212
- spring: t.spring ?? { stiffness: 100, damping: 10 },
213
- onUpdate: t.onUpdate ?? (() => {
214
- }),
259
+ spring: t.spring ?? { stiffness: 300, damping: 30 },
260
+ tick: t.tick,
261
+ css: t.css,
215
262
  onComplete: t.onComplete ?? (() => {
216
263
  }),
217
264
  onStart: t.onStart
218
- }, this.currentValue = this.options.from, typeof this.options.from == "object" && this.options.from !== null) {
219
- const e = {};
220
- Object.keys(this.options.from).forEach((i) => {
221
- e[i] = 0;
222
- }), this.velocity = e;
223
- } else
224
- this.velocity = 0;
265
+ }, this.currentValue = this.options.from;
266
+ }
267
+ runAnimation(t) {
268
+ this.isAnimating = !0, this.controls = Z({
269
+ from: this.currentValue,
270
+ to: t,
271
+ spring: this.options.spring,
272
+ velocity: this.currentVelocity,
273
+ tick: this.options.tick,
274
+ css: this.options.css,
275
+ onStart: this.options.onStart,
276
+ onComplete: () => {
277
+ this.currentValue = t, this.currentVelocity = 0, this.isAnimating = !1, this.controls = null, this.options.onComplete();
278
+ }
279
+ });
225
280
  }
226
- // Animation control methods
227
281
  forward() {
228
- this.stop(), this.animate(!1);
282
+ this.stop(), this.runAnimation(this.options.to);
229
283
  }
230
284
  backward() {
231
- this.stop(), this.animate(!0);
285
+ this.stop(), this.runAnimation(this.options.from);
232
286
  }
233
287
  reverse() {
234
288
  const t = this.options.from;
235
- if (this.options.from = this.options.to, this.options.to = t, this.isAnimating) {
236
- const e = this.shouldReverse();
237
- this.stop(), this.animate(!e);
238
- }
239
- }
240
- shouldReverse() {
241
- return typeof this.currentValue == "number" && typeof this.options.from == "number" && typeof this.options.to == "number" ? this.currentValue > (this.options.from + this.options.to) / 2 : !1;
289
+ this.options.from = this.options.to, this.options.to = t, this.isAnimating && (this.stop(), this.runAnimation(this.options.to));
242
290
  }
243
291
  stop() {
244
- this.isAnimating = !1, this.controls && (this.controls.stop(), this.controls = null), this.animationMap && (this.animationMap.forEach((t) => {
245
- t.stop();
246
- }), this.animationMap.clear(), this.animationMap = null), this.updatedProperties.clear();
292
+ this.controls && (this.currentValue = this.controls.getPosition(), this.currentVelocity = this.controls.getVelocity(), this.controls.stop(), this.controls = null), this.isAnimating = !1;
247
293
  }
248
- // State getters
249
294
  getVelocity() {
250
- return this.velocity;
295
+ var t;
296
+ return ((t = this.controls) == null ? void 0 : t.getVelocity()) ?? this.currentVelocity;
251
297
  }
252
298
  getCurrentValue() {
253
- return this.currentValue;
299
+ var t;
300
+ return ((t = this.controls) == null ? void 0 : t.getPosition()) ?? this.currentValue;
254
301
  }
255
302
  getIsAnimating() {
256
303
  return this.isAnimating;
257
304
  }
258
305
  getCurrentState() {
259
306
  return {
260
- type: "single",
261
- position: this.currentValue,
262
- velocity: this.velocity,
307
+ position: this.getCurrentValue(),
308
+ velocity: this.getVelocity(),
263
309
  from: this.options.from,
264
310
  to: this.options.to
265
311
  };
266
312
  }
267
- // State setters
268
- setVelocity(t) {
269
- this.velocity = t;
270
- }
271
313
  setValue(t) {
272
314
  this.currentValue = t;
273
315
  }
274
- // Configuration
316
+ setVelocity(t) {
317
+ this.currentVelocity = t;
318
+ }
275
319
  updateOptions(t) {
276
- if (this.options = { ...this.options, ...t }, this.isAnimating && this.controls) {
277
- const e = this.shouldReverse();
278
- this.stop(), this.animate(!e);
279
- }
320
+ this.options = { ...this.options, ...t };
280
321
  }
281
- // Static factory method
282
322
  static fromState(t, e) {
283
- const i = new O(e);
284
- return i.setValue(t.position), i.setVelocity(t.velocity), i;
323
+ const r = new I(e);
324
+ return r.setValue(t.position), r.setVelocity(t.velocity), r;
285
325
  }
286
326
  }
287
- class j {
327
+ class x extends X {
288
328
  constructor(t) {
289
- m(this, "config");
290
- m(this, "animators", /* @__PURE__ */ new Map());
291
- m(this, "springOrder", []);
292
- m(this, "completedCount", 0);
293
- m(this, "completedAnimators", /* @__PURE__ */ new Set());
294
- m(this, "direction", "forward");
295
- m(this, "idCounter", 0);
296
- m(this, "timeoutIds", []);
297
- this.config = t, this.initializeAnimators();
329
+ super();
330
+ d(this, "config");
331
+ d(this, "animators", /* @__PURE__ */ new Map());
332
+ d(this, "springOrder", []);
333
+ d(this, "completedCount", 0);
334
+ d(this, "completedAnimators", /* @__PURE__ */ new Set());
335
+ d(this, "direction", "forward");
336
+ d(this, "idCounter", 0);
337
+ d(this, "rafId", null);
338
+ d(this, "element");
339
+ d(this, "from");
340
+ d(this, "to");
341
+ this.config = t.config, this.from = t.from, this.to = t.to, this.element = t.element, this.initializeAnimators();
298
342
  }
299
343
  generateId() {
300
344
  return `spring_${this.idCounter++}`;
301
345
  }
302
346
  initializeAnimators() {
303
347
  this.config.springs.forEach((t) => {
304
- const e = this.generateId(), i = new O({
305
- from: t.from,
306
- to: t.to,
348
+ const e = this.generateId(), r = new I({
349
+ from: this.from,
350
+ to: this.to,
307
351
  spring: t.spring,
308
- onUpdate: t.tick,
352
+ tick: t.tick,
353
+ css: t.css && this.element ? { element: this.element, style: t.css } : void 0,
309
354
  onComplete: () => this.onAnimatorComplete(e),
310
355
  onStart: t.onStart
311
356
  });
312
357
  this.animators.set(e, {
313
358
  id: e,
314
359
  item: t,
315
- animator: i,
316
- startTime: null
360
+ animator: r,
361
+ started: !1
317
362
  }), this.springOrder.push(e);
318
363
  });
319
364
  }
320
365
  /**
321
- * Normalize schedule configuration to unified internal representation
322
- * Uses discriminated union and early return pattern
323
- *
324
- * @param direction - "forward" or "backward" direction
366
+ * Calculate progress of an animator (0-1)
367
+ * Progress = |position - from| / |to - from|
325
368
  */
326
- normalizeSchedule(t) {
327
- const e = this.config.schedule ?? "overlap";
328
- return this.springOrder.map((i, r) => {
329
- const o = this.animators.get(i);
330
- if (!o)
331
- throw new Error(
332
- `AnimationScheduler: animator with id "${i}" not found during normalization`
333
- );
334
- if (e === "overlap")
335
- return {
336
- type: "offset",
337
- id: i,
338
- delay: 0
339
- };
340
- if (e === "wait")
341
- return t === "forward" && r === 0 ? {
342
- type: "offset",
343
- id: i,
344
- delay: 0
345
- } : t === "backward" && r === this.springOrder.length - 1 ? {
346
- type: "offset",
347
- id: i,
348
- delay: 0
349
- } : {
350
- type: "wait",
351
- id: i
352
- };
353
- const s = o.item.offset ?? 0;
354
- if (t === "forward")
355
- return {
356
- type: "offset",
357
- id: i,
358
- delay: s
359
- };
360
- const d = this.animators.size === 0 ? 0 : Math.max(
361
- ...Array.from(this.animators.values()).map(
362
- (l) => l.item.offset ?? 0
363
- )
364
- );
365
- return {
366
- type: "offset",
367
- id: i,
368
- delay: d - s
369
- };
370
- });
369
+ getAnimatorProgress(t) {
370
+ const e = t.animator.getCurrentState(), r = Math.abs(e.to - e.from);
371
+ return r === 0 ? 1 : Math.abs(e.position - e.from) / r;
372
+ }
373
+ /**
374
+ * Get order of springs based on direction
375
+ * Forward: 0, 1, 2, ...
376
+ * Backward: n-1, n-2, ..., 0
377
+ */
378
+ getOrderedIds() {
379
+ return this.direction === "forward" ? this.springOrder : [...this.springOrder].reverse();
371
380
  }
372
381
  onAnimatorComplete(t) {
373
- var i, r, o, s, d, l;
382
+ var r, o, s, a, c, u;
374
383
  const e = this.animators.get(t);
375
- if (!e) {
376
- console.warn(
377
- `AnimationScheduler: animator with id "${t}" not found on completion`
378
- );
379
- return;
380
- }
381
- this.completedAnimators.has(t) || (this.completedAnimators.add(t), this.completedCount++, (r = (i = e.item).onComplete) == null || r.call(i), (s = (o = this.config).onProgress) == null || s.call(o, this.completedCount, this.config.springs.length), this.handleWaitModeChaining(t), this.completedCount === this.config.springs.length && ((l = (d = this.config).onEnd) == null || l.call(d)));
384
+ !e || this.completedAnimators.has(t) || (this.completedAnimators.add(t), this.completedCount++, (o = (r = e.item).onComplete) == null || o.call(r), (a = (s = this.config).onProgress) == null || a.call(s, this.completedCount, this.config.springs.length), this.completedCount === this.config.springs.length && (this.stopScheduler(), (u = (c = this.config).onEnd) == null || u.call(c)));
382
385
  }
383
386
  /**
384
- * Handle wait mode chaining: start next/previous spring after completion
387
+ * Check and start springs based on previous spring's progress
388
+ * Called on each frame while animation is running
385
389
  */
386
- handleWaitModeChaining(t) {
387
- if (this.config.schedule !== "wait")
388
- return;
389
- const e = this.springOrder.indexOf(t);
390
- if (this.direction === "forward") {
391
- const o = this.springOrder[e + 1];
392
- if (!o)
393
- return;
394
- const s = this.animators.get(o);
395
- s && s.startTime === null && this.startAnimator(o);
396
- return;
390
+ checkAndStartSprings() {
391
+ const t = this.getOrderedIds();
392
+ for (let e = 0; e < t.length; e++) {
393
+ const r = t[e], o = this.animators.get(r);
394
+ if (!o || o.started) continue;
395
+ if (e === 0) {
396
+ this.startAnimator(r);
397
+ continue;
398
+ }
399
+ const s = t[e - 1], a = this.animators.get(s);
400
+ if (!a || !a.started) continue;
401
+ const c = this.getAnimatorProgress(a), u = o.item.normalizedOffset;
402
+ c >= u && this.startAnimator(r);
397
403
  }
398
- const i = this.springOrder[e - 1];
399
- if (!i)
400
- return;
401
- const r = this.animators.get(i);
402
- r && r.startTime === null && this.startBackwardAnimator(i);
403
404
  }
404
405
  startAnimator(t) {
405
406
  const e = this.animators.get(t);
406
- if (!e) {
407
- console.warn(
408
- `AnimationScheduler: animator with id "${t}" not found on start`
409
- );
410
- return;
411
- }
412
- if (e.startTime !== null) {
413
- console.warn(
414
- `AnimationScheduler: animator with id "${t}" already started`
415
- );
416
- return;
417
- }
418
- e.startTime = Date.now(), e.animator.forward();
407
+ !e || e.started || (e.started = !0, this.direction === "forward" ? e.animator.forward() : e.animator.backward());
419
408
  }
420
- startBackwardAnimator(t) {
421
- const e = this.animators.get(t);
422
- if (!e) {
423
- console.warn(
424
- `AnimationScheduler: animator with id "${t}" not found on backward start`
425
- );
426
- return;
427
- }
428
- if (e.startTime !== null) {
429
- console.warn(
430
- `AnimationScheduler: animator with id "${t}" already started`
431
- );
432
- return;
433
- }
434
- e.startTime = Date.now(), e.animator.backward();
409
+ /**
410
+ * Start the scheduler loop that checks spring progress
411
+ */
412
+ startScheduler() {
413
+ const t = () => {
414
+ this.checkAndStartSprings(), this.getIsAnimating() && (this.rafId = requestAnimationFrame(t));
415
+ };
416
+ this.rafId = requestAnimationFrame(t);
417
+ }
418
+ stopScheduler() {
419
+ this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null);
420
+ }
421
+ getFirstAnimator() {
422
+ var e;
423
+ const t = this.springOrder[0];
424
+ return t ? ((e = this.animators.get(t)) == null ? void 0 : e.animator) ?? null : null;
435
425
  }
436
426
  forward() {
437
- var e, i;
438
- this.stop(), this.direction = "forward", this.completedCount = 0, this.completedAnimators.clear(), (i = (e = this.config).onStart) == null || i.call(e), this.normalizeSchedule("forward").forEach((r) => {
439
- if (r.type === "wait")
440
- return;
441
- if (r.delay === 0) {
442
- this.startAnimator(r.id);
443
- return;
444
- }
445
- const o = window.setTimeout(
446
- () => this.startAnimator(r.id),
447
- r.delay
448
- );
449
- this.timeoutIds.push(o);
450
- });
427
+ var t, e;
428
+ this.stop(), this.direction = "forward", this.completedCount = 0, this.completedAnimators.clear(), this.resetStartedFlags(), (e = (t = this.config).onStart) == null || e.call(t), this.startScheduler();
451
429
  }
452
430
  backward() {
453
- var e, i;
454
- this.stop(), this.direction = "backward", this.completedCount = 0, this.completedAnimators.clear(), (i = (e = this.config).onStart) == null || i.call(e), this.normalizeSchedule("backward").forEach((r) => {
455
- if (r.type === "wait")
456
- return;
457
- if (r.delay === 0) {
458
- this.startBackwardAnimator(r.id);
459
- return;
460
- }
461
- const o = window.setTimeout(
462
- () => this.startBackwardAnimator(r.id),
463
- r.delay
464
- );
465
- this.timeoutIds.push(o);
431
+ var t, e;
432
+ this.stop(), this.direction = "backward", this.completedCount = 0, this.completedAnimators.clear(), this.resetStartedFlags(), (e = (t = this.config).onStart) == null || e.call(t), this.startScheduler();
433
+ }
434
+ resetStartedFlags() {
435
+ this.animators.forEach((t) => {
436
+ t.started = !1;
466
437
  });
467
438
  }
468
439
  stop() {
469
- this.timeoutIds.forEach((t) => clearTimeout(t)), this.timeoutIds = [], this.animators.forEach((t) => {
470
- t.animator.stop(), t.startTime = null;
440
+ this.stopScheduler(), this.animators.forEach((t) => {
441
+ t.animator.stop(), t.started = !1;
471
442
  });
472
443
  }
473
- reverse(t) {
474
- ((t == null ? void 0 : t.offsetMode) ?? "immediate") !== "immediate" && console.warn(
475
- 'AnimationScheduler.reverse(): Only "immediate" offsetMode is currently supported. Falling back to "immediate".'
476
- ), this.direction = this.direction === "forward" ? "backward" : "forward", this.animators.forEach((i) => {
477
- if (i.startTime === null)
478
- return;
479
- const r = i.animator.getCurrentState();
480
- if (r.type !== "single")
444
+ reverse() {
445
+ this.direction = this.direction === "forward" ? "backward" : "forward", this.animators.forEach((t) => {
446
+ if (!t.started)
481
447
  return;
482
- if (r.position === r.to) {
483
- const s = O.fromState(
484
- {
485
- position: 1,
486
- velocity: 0
487
- },
448
+ const e = t.animator.getCurrentState();
449
+ if (e.position === e.to) {
450
+ const o = t.item.css && this.element ? { element: this.element, style: t.item.css } : void 0, s = I.fromState(
451
+ { position: this.to, velocity: 0 },
488
452
  {
489
- from: i.item.to ?? 1,
490
- to: i.item.from ?? 0,
491
- spring: i.item.spring,
492
- onUpdate: i.item.tick,
493
- onComplete: () => this.onAnimatorComplete(i.id),
494
- onStart: i.item.onStart
453
+ from: this.to,
454
+ to: this.from,
455
+ spring: t.item.spring,
456
+ tick: t.item.tick,
457
+ css: o,
458
+ onComplete: () => this.onAnimatorComplete(t.id),
459
+ onStart: t.item.onStart
495
460
  }
496
461
  );
497
- s.forward(), i.animator = s;
498
- return;
499
- }
500
- i.animator.reverse();
462
+ s.forward(), t.animator = s;
463
+ } else
464
+ t.animator.reverse();
501
465
  });
502
466
  }
503
467
  getCurrentState() {
504
- return {
505
- type: "multi",
506
- completed: this.completedCount,
507
- total: this.config.springs.length,
508
- direction: this.direction
468
+ const t = this.getFirstAnimator();
469
+ return t ? t.getCurrentState() : {
470
+ position: 0,
471
+ velocity: 0,
472
+ from: 0,
473
+ to: 1
509
474
  };
510
475
  }
476
+ /**
477
+ * Get current position value from first animator
478
+ */
479
+ getCurrentValue() {
480
+ const t = this.getFirstAnimator();
481
+ return (t == null ? void 0 : t.getCurrentValue()) ?? 0;
482
+ }
483
+ /**
484
+ * Get current velocity from first animator
485
+ */
486
+ getVelocity() {
487
+ const t = this.getFirstAnimator();
488
+ return (t == null ? void 0 : t.getVelocity()) ?? 0;
489
+ }
490
+ /**
491
+ * Set position value on first animator
492
+ * TODO: Support per-spring control
493
+ */
494
+ setValue(t) {
495
+ const e = this.getFirstAnimator();
496
+ e == null || e.setValue(t);
497
+ }
498
+ /**
499
+ * Set velocity on first animator
500
+ * TODO: Support per-spring control
501
+ */
502
+ setVelocity(t) {
503
+ const e = this.getFirstAnimator();
504
+ e == null || e.setVelocity(t);
505
+ }
506
+ /**
507
+ * Check if any animation is currently running
508
+ */
509
+ getIsAnimating() {
510
+ for (const t of this.animators.values())
511
+ if (t.animator.getIsAnimating())
512
+ return !0;
513
+ return !1;
514
+ }
515
+ /**
516
+ * Create MultiAnimator from existing state
517
+ * Uses first animator's state for initialization
518
+ */
519
+ static fromState(t, e) {
520
+ const r = new x(e);
521
+ return r.setValue(t.position), r.setVelocity(t.velocity), r;
522
+ }
511
523
  }
512
- const U = Symbol.for("TRANSITION_STRATEGY"), H = (n) => ({
513
- runIn: async (t) => {
514
- const { currentAnimation: e } = n;
515
- if (e && e.direction === "out") {
516
- const s = e.controller.getCurrentState();
517
- if (e.controller.stop(), s.type === "multi")
518
- return e.controller.reverse(), {
519
- state: {
520
- position: 0,
521
- velocity: 0
522
- },
523
- from: 0,
524
- to: 1,
525
- direction: "forward"
526
- };
527
- if (t.out) {
528
- const d = await t.out, { from: l = 1, to: h = 0 } = d;
524
+ const Y = Symbol.for("TRANSITION_STRATEGY"), tt = (i) => ({
525
+ runIn: async (n) => {
526
+ const { currentAnimation: t } = i;
527
+ if (t && t.direction === "out") {
528
+ const r = t.controller.getCurrentValue(), o = t.controller.getVelocity();
529
+ if (t.controller.stop(), n.out)
529
530
  return {
530
- config: d,
531
- state: {
532
- position: s.position,
533
- velocity: s.velocity
534
- },
535
- from: l,
536
- // OUT animation's from
537
- to: h,
538
- // OUT animation's to
531
+ config: n.out,
532
+ state: { position: r, velocity: o },
533
+ from: 1,
534
+ to: 0,
539
535
  direction: "backward"
540
- // Will actually go 0→1
536
+ // Will actually go 0→1 (backward means toward 'from')
541
537
  };
542
- }
543
538
  }
544
- const i = await t.in;
545
- if (!i)
546
- return {
547
- state: {
548
- position: 0,
549
- velocity: 0
550
- },
551
- from: 0,
552
- to: 1,
553
- direction: "forward"
554
- };
555
- if ("springs" in i)
556
- return {
557
- config: i,
558
- state: {
559
- position: 0,
560
- velocity: 0
561
- },
562
- from: 0,
563
- to: 1,
564
- direction: "forward"
565
- };
566
- const { from: r = 0, to: o = 1 } = i;
567
- return {
568
- config: i,
539
+ const e = n.in;
540
+ return e ? {
541
+ config: e,
569
542
  state: {
570
- position: r,
543
+ position: 0,
571
544
  velocity: 0
572
545
  },
573
- from: r,
574
- to: o,
546
+ from: 0,
547
+ to: 1,
548
+ direction: "forward"
549
+ } : {
550
+ state: {
551
+ position: 0,
552
+ velocity: 0
553
+ },
554
+ from: 0,
555
+ to: 1,
575
556
  direction: "forward"
576
557
  };
577
558
  },
578
- runOut: async (t) => {
579
- const { currentAnimation: e } = n;
580
- if (e && e.direction === "in") {
581
- const s = e.controller.getCurrentState();
582
- if (e.controller.stop(), s.type === "multi")
583
- return e.controller.reverse(), {
584
- state: {
585
- position: 1,
586
- velocity: 0
587
- },
588
- from: 1,
589
- to: 0,
590
- direction: "forward"
591
- };
592
- if (t.in) {
593
- const d = await t.in, { from: l = 0, to: h = 1 } = d;
559
+ runOut: async (n) => {
560
+ const { currentAnimation: t } = i;
561
+ if (t && t.direction === "in") {
562
+ const r = t.controller.getCurrentValue(), o = t.controller.getVelocity();
563
+ if (t.controller.stop(), n.in)
594
564
  return {
595
- config: d,
596
- state: {
597
- position: s.position,
598
- velocity: s.velocity
599
- },
600
- from: l,
601
- // IN animation's from
602
- to: h,
603
- // IN animation's to
565
+ config: n.in,
566
+ state: { position: r, velocity: o },
567
+ from: 0,
568
+ to: 1,
604
569
  direction: "backward"
605
- // Will actually go 1→0
570
+ // Will actually go 1→0 (backward means toward 'from')
606
571
  };
607
- }
608
572
  }
609
- const i = await t.out;
610
- if (!i)
611
- return {
612
- state: {
613
- position: 1,
614
- velocity: 0
615
- },
616
- from: 1,
617
- to: 0,
618
- direction: "forward"
619
- };
620
- if ("springs" in i)
621
- return {
622
- config: i,
623
- state: {
624
- position: 1,
625
- velocity: 0
626
- },
627
- from: 1,
628
- to: 0,
629
- direction: "forward"
630
- };
631
- const { from: r = 1, to: o = 0 } = i;
632
- return {
633
- config: i,
573
+ const e = n.out;
574
+ return e ? {
575
+ config: e,
576
+ state: {
577
+ position: 1,
578
+ velocity: 0
579
+ },
580
+ from: 1,
581
+ to: 0,
582
+ direction: "forward"
583
+ } : {
634
584
  state: {
635
- position: r,
585
+ position: 1,
636
586
  velocity: 0
637
587
  },
638
- from: r,
639
- to: o,
588
+ from: 1,
589
+ to: 0,
640
590
  direction: "forward"
641
591
  };
642
592
  }
643
- }), N = () => ({
644
- runIn: async (n) => {
645
- const t = await n.in;
646
- if (!t)
647
- return {
648
- state: {
649
- position: 0,
650
- velocity: 0
651
- },
652
- from: 0,
653
- to: 1,
654
- direction: "forward"
655
- };
656
- if ("springs" in t)
657
- return {
658
- config: t,
659
- state: {
660
- position: 0,
661
- velocity: 0
662
- },
663
- from: 0,
664
- to: 1,
665
- direction: "forward"
666
- };
667
- const { from: e = 0, to: i = 1 } = t;
668
- return {
669
- config: t,
593
+ }), et = () => ({
594
+ runIn: async (i) => {
595
+ const n = i.in;
596
+ return n ? {
597
+ config: n,
670
598
  state: {
671
- position: e,
599
+ position: 0,
672
600
  velocity: 0
673
601
  },
674
- from: e,
675
- to: i,
602
+ from: 0,
603
+ to: 1,
604
+ direction: "forward"
605
+ } : {
606
+ state: {
607
+ position: 0,
608
+ velocity: 0
609
+ },
610
+ from: 0,
611
+ to: 1,
676
612
  direction: "forward"
677
613
  };
678
614
  },
679
- runOut: async (n) => {
680
- const t = await n.out;
681
- if (!t)
682
- return {
683
- state: {
684
- position: 1,
685
- velocity: 0
686
- },
687
- from: 1,
688
- to: 0,
689
- direction: "forward"
690
- };
691
- if ("springs" in t)
692
- return {
693
- config: t,
694
- state: {
695
- position: 1,
696
- velocity: 0
697
- },
698
- from: 1,
699
- to: 0,
700
- direction: "forward"
701
- };
702
- const { from: e = 1, to: i = 0 } = t;
703
- return {
704
- config: t,
615
+ runOut: async (i) => {
616
+ const n = i.out;
617
+ return n ? {
618
+ config: n,
705
619
  state: {
706
- position: e,
620
+ position: 1,
707
621
  velocity: 0
708
622
  },
709
- from: e,
710
- to: i,
623
+ from: 1,
624
+ to: 0,
625
+ direction: "forward"
626
+ } : {
627
+ state: {
628
+ position: 1,
629
+ velocity: 0
630
+ },
631
+ from: 1,
632
+ to: 0,
711
633
  direction: "forward"
712
634
  };
713
635
  }
714
636
  });
715
- function W(n, t) {
716
- var u;
717
- let e = null, i = null, r = null, o = null;
637
+ function nt(i, n) {
638
+ var h;
639
+ let t = null, e = null, r = null, o = null;
718
640
  const s = {
719
641
  get currentAnimation() {
720
- return e;
721
- }
722
- }, d = ((u = t == null ? void 0 : t.strategy) == null ? void 0 : u.call(t, s)) || H(s), l = async (a) => {
723
- var S, T, C;
724
- i && (i.remove(), i = null);
725
- const p = n(), c = p.in && await p.in(a), g = !(t != null && t.strategy) && p.out ? p.out(a) : void 0;
726
- if (!c)
727
- return;
728
- if (V(c)) {
729
- const v = {
730
- in: Promise.resolve(c),
731
- out: g && Promise.resolve(g)
732
- };
733
- if (!(await d.runIn(v)).config) {
734
- e && (e.direction = "in");
735
- return;
736
- }
737
- (S = c.prepare) == null || S.call(c, a), c.wait && await c.wait();
738
- const E = new j({
739
- ...c,
740
- onEnd: () => {
741
- var A;
742
- e = null, (A = c.onEnd) == null || A.call(c);
743
- }
744
- });
745
- e = {
746
- controller: E,
747
- direction: "in"
748
- }, E.forward();
749
- return;
642
+ return t;
750
643
  }
751
- const w = {
752
- in: Promise.resolve(c),
753
- out: g && Promise.resolve(g)
754
- }, f = await d.runIn(w);
755
- if (!f.config)
644
+ }, a = ((h = n == null ? void 0 : n.strategy) == null ? void 0 : h.call(n, s)) || tt(s), c = async (l) => {
645
+ var C;
646
+ e && (e.remove(), e = null);
647
+ const g = i(), w = g.in && await g.in(l), p = !(n != null && n.strategy) && g.out ? await g.out(l) : void 0;
648
+ if (!w)
756
649
  return;
757
- if ("springs" in f.config) {
758
- console.error("Unexpected MultiSpringConfig in single-spring path");
650
+ const y = {
651
+ in: V(w),
652
+ out: p ? V(p) : void 0
653
+ }, m = await a.runIn(y);
654
+ if (!m.config) {
655
+ t && (t.direction = "in");
759
656
  return;
760
657
  }
761
- (C = (T = f.config).prepare) == null || C.call(T, a), f.config.wait && await f.config.wait();
762
- const y = O.fromState(f.state, {
763
- from: f.from,
764
- to: f.to,
765
- spring: f.config.spring,
766
- onStart: f.config.onStart,
767
- onUpdate: f.config.tick,
768
- onComplete: () => {
769
- var v, b;
770
- e = null, (b = (v = f.config) == null ? void 0 : v.onEnd) == null || b.call(v);
658
+ const f = m.config;
659
+ (C = f.prepare) == null || C.call(f, l), f.wait && await f.wait();
660
+ const S = M({
661
+ ...f,
662
+ onEnd: () => {
663
+ var A;
664
+ t = null, (A = f.onEnd) == null || A.call(f);
771
665
  }
666
+ }), v = x.fromState(m.state, {
667
+ config: S,
668
+ from: m.from,
669
+ to: m.to,
670
+ element: l
772
671
  });
773
- e = { controller: y, direction: "in" }, f.direction === "forward" ? y.forward() : y.backward();
774
- }, h = async (a) => {
775
- var S, T, C;
776
- i = a;
777
- const p = n(), c = p.out && await p.out(a);
778
- if (!c)
672
+ t = { controller: v, direction: "in" }, m.direction === "forward" ? v.forward() : v.backward();
673
+ }, u = async (l) => {
674
+ var A;
675
+ e = l;
676
+ const g = i(), w = !(n != null && n.strategy) && g.in ? await g.in(l) : void 0, p = g.out && await g.out(l);
677
+ if (!p)
779
678
  return;
780
- if (V(c)) {
781
- const v = {
782
- in: void 0,
783
- // Don't fetch IN config for exit transitions
784
- out: Promise.resolve(c)
785
- };
786
- if (!(await d.runOut(v)).config) {
787
- e && (e.direction = "out"), i && (i.remove(), i = null);
788
- return;
789
- }
790
- (S = c.prepare) == null || S.call(c, a), y(), c.wait && await c.wait();
791
- const E = new j({
792
- ...c,
793
- onEnd: () => {
794
- var A, P;
795
- (A = c.onEnd) == null || A.call(c), i && (i.remove(), i = null), e = null, (P = t == null ? void 0 : t.onCleanupEnd) == null || P.call(t);
796
- }
797
- });
798
- e = {
799
- controller: E,
800
- direction: "out"
801
- }, E.forward();
802
- return;
803
- }
804
- const g = {
805
- in: void 0,
806
- // Don't fetch IN config for exit transitions
807
- out: Promise.resolve(c)
808
- }, w = await d.runOut(g);
809
- if (!w.config)
810
- return;
811
- if ("springs" in w.config) {
812
- console.error("Unexpected MultiSpringConfig in single-spring path");
679
+ const y = {
680
+ in: w ? V(w) : void 0,
681
+ out: V(p)
682
+ }, m = await a.runOut(y);
683
+ if (!m.config) {
684
+ t && (t.direction = "out"), e && (e.remove(), e = null);
813
685
  return;
814
686
  }
815
- (C = (T = w.config).prepare) == null || C.call(T, a), y(), w.config.wait && await w.config.wait();
816
- const f = O.fromState(w.state, {
817
- from: w.from,
818
- to: w.to,
819
- spring: w.config.spring,
820
- onStart: w.config.onStart,
821
- onUpdate: w.config.tick,
822
- onComplete: () => {
823
- var v, b, E;
824
- (b = (v = w.config) == null ? void 0 : v.onEnd) == null || b.call(v), i && (i.remove(), i = null), e = null, (E = t == null ? void 0 : t.onCleanupEnd) == null || E.call(t);
687
+ const f = m.config;
688
+ (A = f.prepare) == null || A.call(f, l), C(), f.wait && await f.wait();
689
+ const S = M({
690
+ ...f,
691
+ onEnd: () => {
692
+ var T, E;
693
+ (T = f.onEnd) == null || T.call(f), e && (e.remove(), e = null), t = null, (E = n == null ? void 0 : n.onCleanupEnd) == null || E.call(n);
825
694
  }
695
+ }), v = x.fromState(m.state, {
696
+ config: S,
697
+ from: m.from,
698
+ to: m.to,
699
+ element: l
826
700
  });
827
- e = { controller: f, direction: "out" }, w.direction === "forward" ? f.forward() : f.backward();
828
- function y() {
829
- !r || !i || (o && r.contains(o) ? r.insertBefore(i, o) : r.appendChild(i));
701
+ t = { controller: v, direction: "out" }, m.direction === "forward" ? v.forward() : v.backward();
702
+ function C() {
703
+ !r || !e || (o && r.contains(o) ? r.insertBefore(e, o) : r.appendChild(e));
830
704
  }
831
705
  };
832
- return (a) => {
833
- if (a)
834
- return r = a.parentElement, o = a.nextElementSibling, l(a), () => {
835
- if (a.isConnected) {
836
- const p = a.cloneNode(!0);
837
- h(p);
706
+ return (l) => {
707
+ if (l)
708
+ return r = l.parentElement, o = l.nextElementSibling, c(l), () => {
709
+ if (l.isConnected) {
710
+ const g = l.cloneNode(!0);
711
+ u(g);
838
712
  } else
839
- h(a);
713
+ u(l);
840
714
  };
841
715
  };
842
716
  }
843
- const Y = 3, X = (n) => {
844
- if (!n) return null;
845
- const t = n.split(`
846
- `).map((e) => e.trim());
847
- for (let e = Y; e < Math.min(t.length, 6); e++) {
848
- const i = t[e], r = i == null ? void 0 : i.match(/\(?([^):]+):(\d+):(\d+)\)?$/);
717
+ const it = 3, ot = (i) => {
718
+ if (!i) return null;
719
+ const n = i.split(`
720
+ `).map((t) => t.trim());
721
+ for (let t = it; t < Math.min(n.length, 6); t++) {
722
+ const e = n[t], r = e == null ? void 0 : e.match(/\(?([^):]+):(\d+):(\d+)\)?$/);
849
723
  if (!r)
850
724
  continue;
851
- const o = r[1] ?? "", s = r[2] ?? "0", d = r[3] ?? "0";
852
- return { file: o.split(/[\\/]/).pop() || o, line: s, column: d };
725
+ const o = r[1] ?? "", s = r[2] ?? "0", a = r[3] ?? "0";
726
+ return { file: o.split(/[\\/]/).pop() || o, line: s, column: a };
853
727
  }
854
728
  return null;
855
- }, M = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map();
856
- function B(n, t, e) {
857
- M.set(n, t);
858
- let i = R.get(n);
859
- return i || (i = W(
729
+ }, R = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map();
730
+ function rt(i, n, t) {
731
+ R.set(i, n);
732
+ let e = F.get(i);
733
+ return e || (e = nt(
860
734
  () => {
861
- const r = M.get(n);
862
- return r || (console.warn(`Transition "${String(n)}" not found`), {});
735
+ const r = R.get(i);
736
+ return r || (console.warn(`Transition "${String(i)}" not found`), {});
863
737
  },
864
738
  {
865
- strategy: e,
866
- onCleanupEnd: () => z(n)
739
+ strategy: t,
740
+ onCleanupEnd: () => q(i)
867
741
  }
868
- ), R.set(n, i), i);
742
+ ), F.set(i, e), e);
869
743
  }
870
- function z(n) {
871
- M.delete(n), R.delete(n);
744
+ function q(i) {
745
+ R.delete(i), F.delete(i);
872
746
  }
873
- function K() {
874
- const n = X(new Error().stack);
875
- return n ? `auto_${n.file}_${n.line}_${n.column}` : Symbol(`ssgoi_auto_${Date.now()}`);
747
+ function st() {
748
+ const i = ot(new Error().stack);
749
+ return i ? `auto_${i.file}_${i.line}_${i.column}` : Symbol(`ssgoi_auto_${Date.now()}`);
876
750
  }
877
- const D = globalThis.FinalizationRegistry, L = D ? (
751
+ const L = globalThis.FinalizationRegistry, D = L ? (
878
752
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
879
- new D((n) => {
753
+ new L((i) => {
880
754
  try {
881
- z(n);
755
+ q(i);
882
756
  } catch {
883
757
  }
884
758
  })
885
759
  ) : void 0;
886
- function nt(n) {
887
- const t = n.key ?? K();
888
- if (n.ref && L)
760
+ function gt(i) {
761
+ const n = i.key ?? st();
762
+ if (i.ref && D)
889
763
  try {
890
- L.register(n.ref, t);
764
+ D.register(i.ref, n);
891
765
  } catch {
892
766
  }
893
- return B(
894
- t,
767
+ return rt(
768
+ n,
895
769
  {
896
- in: n.in,
897
- out: n.out
770
+ in: i.in,
771
+ out: i.out
898
772
  },
899
- n[U]
773
+ i[Y]
900
774
  );
901
775
  }
902
- function q(n) {
903
- const t = n.filter((e) => e.symmetric).map((e) => ({
904
- from: e.to,
905
- to: e.from,
906
- transition: e.transition
776
+ function ct(i) {
777
+ const n = i.filter((t) => t.symmetric).map((t) => ({
778
+ from: t.to,
779
+ to: t.from,
780
+ transition: t.transition
907
781
  }));
908
- return [...n, ...t];
782
+ return [...i, ...n];
909
783
  }
910
- function G(n) {
911
- let t = !1, e = 0, i = 0, r = !1;
912
- const o = 50, s = 50, d = (c) => {
913
- if (!n) return;
914
- const g = c.touches[0];
915
- g && (r = g.clientX < s, r && (e = g.clientX, i = g.clientY));
916
- }, l = (c) => {
917
- if (!n || !r || t) return;
918
- const g = c.touches[0];
919
- if (!g) return;
920
- const w = g.clientX - e, f = g.clientY - i;
921
- w > o && Math.abs(w) > Math.abs(f) && (t = !0, setTimeout(() => {
922
- t = !1;
923
- }, 500));
924
- }, h = () => {
925
- n && (r = !1, e = 0, i = 0);
784
+ function at(i) {
785
+ let n = !1, t = 0, e = 0, r = !1;
786
+ const o = 50, s = (p) => {
787
+ if (!i) return;
788
+ const y = p.touches[0];
789
+ y && (r = y.clientX < o, r && (t = y.clientX, e = y.clientY));
790
+ }, a = (p) => {
791
+ if (!i || !r) return;
792
+ const y = p.touches[0];
793
+ if (!y) return;
794
+ const m = y.clientX - t, f = y.clientY - e;
795
+ m > window.outerWidth / 2 - 5 && Math.abs(m) > Math.abs(f) ? n = !0 : n = !1;
796
+ }, c = () => {
797
+ i && (r = !1, t = 0, e = 0);
798
+ }, u = () => n, h = () => {
799
+ typeof window > "u" || i && (window.addEventListener("touchstart", s, { passive: !0 }), window.addEventListener("touchmove", a, { passive: !0 }), window.addEventListener("touchend", c, { passive: !0 }));
800
+ }, l = () => {
801
+ typeof window > "u" || (window.removeEventListener("touchstart", s), window.removeEventListener("touchmove", a), window.removeEventListener("touchend", c));
926
802
  };
803
+ let g = 0;
927
804
  return {
928
- initialize: () => {
929
- typeof window > "u" || n && (window.addEventListener("touchstart", d, { passive: !0 }), window.addEventListener("touchmove", l, { passive: !0 }), window.addEventListener("touchend", h, { passive: !0 }));
930
- },
931
- cleanup: () => {
932
- typeof window > "u" || (window.removeEventListener("touchstart", d), window.removeEventListener("touchmove", l), window.removeEventListener("touchend", h));
933
- },
934
- isSwipePending: () => t
805
+ initialize: h,
806
+ cleanup: l,
807
+ isSwipePending: u,
808
+ resetSwipeDetection: () => {
809
+ g++, g > 1 && (g = 0, n = !1);
810
+ }
935
811
  };
936
812
  }
937
- const J = (n) => {
938
- let t = n.parentElement;
939
- for (; t && t !== document.body; ) {
940
- const e = window.getComputedStyle(t), i = e.overflow + e.overflowY + e.overflowX;
941
- if (i.includes("auto") || i.includes("scroll") || t.scrollHeight > t.clientHeight || t.scrollWidth > t.clientWidth)
942
- return t;
943
- t = t.parentElement;
813
+ const lt = (i) => {
814
+ let n = i.parentElement;
815
+ for (; n && n !== document.body; ) {
816
+ const t = window.getComputedStyle(n), e = t.overflow + t.overflowY + t.overflowX;
817
+ if (e.includes("auto") || e.includes("scroll") || n.scrollHeight > n.clientHeight || n.scrollWidth > n.clientWidth)
818
+ return n;
819
+ n = n.parentElement;
944
820
  }
945
821
  return document.documentElement;
946
- }, Q = (n) => {
947
- let t = n.parentElement;
948
- for (; t && t !== document.body; ) {
949
- const e = window.getComputedStyle(t).position;
950
- if (e === "relative" || e === "absolute" || e === "fixed" || e === "sticky")
951
- return t;
952
- t = t.parentElement;
822
+ }, ut = (i) => {
823
+ let n = i.parentElement;
824
+ for (; n && n !== document.body; ) {
825
+ const t = window.getComputedStyle(n).position;
826
+ if (t === "relative" || t === "absolute" || t === "fixed" || t === "sticky")
827
+ return n;
828
+ n = n.parentElement;
953
829
  }
954
830
  return document.body;
955
831
  };
956
- function Z() {
957
- let n = null, t = null;
958
- const e = /* @__PURE__ */ new Map();
959
- let i = null;
832
+ function ft() {
833
+ let i = null, n = null;
834
+ const t = /* @__PURE__ */ new Map();
835
+ let e = null;
960
836
  const r = () => {
961
- n && i && e.set(i, {
962
- x: n.scrollLeft,
963
- y: n.scrollTop
837
+ i && e && t.set(e, {
838
+ x: i.scrollLeft,
839
+ y: i.scrollTop
964
840
  });
965
841
  };
966
842
  return {
967
- initializeContext: (u, a) => {
968
- t = u, n || (n = J(u), (n === document.documentElement ? window : n).addEventListener("scroll", r, {
843
+ initializeContext: (h, l) => {
844
+ n = h, i || (i = lt(h), (i === document.documentElement ? window : i).addEventListener("scroll", r, {
969
845
  passive: !0
970
- })), i = a;
846
+ })), e = l;
971
847
  },
972
- calculateScrollOffset: (u, a) => {
973
- const p = u && e.has(u) ? e.get(u) : { x: 0, y: 0 }, c = a && e.has(a) ? e.get(a) : { x: 0, y: 0 };
848
+ calculateScrollOffset: (h, l) => {
849
+ const g = h && t.has(h) ? t.get(h) : { x: 0, y: 0 }, w = l && t.has(l) ? t.get(l) : { x: 0, y: 0 };
974
850
  return {
975
- x: -c.x + p.x,
976
- y: -c.y + p.y
851
+ x: -w.x + g.x,
852
+ y: -w.y + g.y
977
853
  };
978
854
  },
979
- getScrollContainer: () => n,
980
- getPositionedParentElement: () => t ? Q(t) : document.body,
981
- getScrollPosition: (u) => u && e.has(u) ? e.get(u) : { x: 0, y: 0 }
855
+ getScrollContainer: () => i,
856
+ getPositionedParentElement: () => n ? ut(n) : document.body,
857
+ getScrollPosition: (h) => h && t.has(h) ? t.get(h) : { x: 0, y: 0 }
982
858
  };
983
859
  }
984
- function x(n, t) {
985
- if (t === "*")
860
+ function k(i, n) {
861
+ if (n === "*")
986
862
  return !0;
987
- if (t.endsWith("/*")) {
988
- const e = t.slice(0, -2);
989
- return n === e || n.startsWith(e + "/");
863
+ if (n.endsWith("/*")) {
864
+ const t = n.slice(0, -2);
865
+ return i === t || i.startsWith(t + "/");
990
866
  }
991
- return n === t;
867
+ return i === n;
992
868
  }
993
- function tt(n, t, e) {
994
- for (const i of e)
995
- if (x(n, i.from) && x(t, i.to))
996
- return i.transition;
997
- for (const i of e)
998
- if ((i.from === "*" || x(n, i.from)) && (i.to === "*" || x(t, i.to)))
999
- return i.transition;
869
+ function mt(i, n, t) {
870
+ for (const e of t)
871
+ if (k(i, e.from) && k(n, e.to))
872
+ return e.transition;
873
+ for (const e of t)
874
+ if ((e.from === "*" || k(i, e.from)) && (e.to === "*" || k(n, e.to)))
875
+ return e.transition;
1000
876
  return null;
1001
877
  }
1002
- function ot(n) {
878
+ function pt(i) {
1003
879
  const {
1004
- transitions: t = [],
1005
- defaultTransition: e,
1006
- middleware: i = (f, y) => ({ from: f, to: y }),
880
+ transitions: n = [],
881
+ defaultTransition: t,
882
+ middleware: e = (m, f) => ({ from: m, to: f }),
1007
883
  // Identity function as default
1008
884
  skipOnIosSwipe: r = !0
1009
885
  // Default to true - skip animations on iOS swipe
1010
- } = n;
886
+ } = i;
1011
887
  let o = null;
1012
- const s = q(t), {
1013
- initializeContext: d,
1014
- calculateScrollOffset: l,
1015
- getScrollContainer: h,
1016
- getPositionedParentElement: u,
1017
- getScrollPosition: a
1018
- } = Z(), p = G(r);
1019
- p.initialize();
1020
- function c() {
888
+ const s = ct(n), {
889
+ initializeContext: a,
890
+ calculateScrollOffset: c,
891
+ getScrollContainer: u,
892
+ getPositionedParentElement: h,
893
+ getScrollPosition: l
894
+ } = ft(), g = at(r);
895
+ g.initialize();
896
+ function w() {
1021
897
  if (o != null && o.from && (o != null && o.to)) {
1022
- const { from: f, to: y } = i(
898
+ const { from: m, to: f } = e(
1023
899
  o.from,
1024
900
  o.to
1025
- ), T = tt(
901
+ ), v = mt(
902
+ m,
1026
903
  f,
1027
- y,
1028
904
  s
1029
- ) || e, C = l(
905
+ ) || t, C = c(
1030
906
  o.from,
1031
907
  o.to
1032
- ), v = {
908
+ ), A = {
1033
909
  scrollOffset: C,
1034
- scroll: a(o.from),
910
+ scroll: l(o.from),
1035
911
  get scrollingElement() {
1036
- return h() || document.documentElement;
912
+ return u() || document.documentElement;
1037
913
  },
1038
914
  get positionedParent() {
1039
- return u();
915
+ return h();
1040
916
  }
1041
- }, b = {
917
+ }, T = {
1042
918
  scrollOffset: C,
1043
919
  get scroll() {
1044
- return o ? a(o.to) : { x: 0, y: 0 };
920
+ return o ? l(o.to) : { x: 0, y: 0 };
1045
921
  },
1046
922
  get scrollingElement() {
1047
- return h() || document.documentElement;
923
+ return u() || document.documentElement;
1048
924
  },
1049
925
  get positionedParent() {
1050
- return u();
926
+ return h();
1051
927
  }
1052
928
  };
1053
- T && (T.out && o.outResolve && o.outResolve(
1054
- (E) => T.out(E, v)
1055
- ), T.in && o.inResolve && o.inResolve(
1056
- (E) => T.in(E, b)
929
+ v && (v.out && o.outResolve && o.outResolve(
930
+ (E) => v.out(E, A)
931
+ ), v.in && o.inResolve && o.inResolve(
932
+ (E) => v.in(E, T)
1057
933
  )), o = null;
1058
934
  }
1059
935
  }
1060
- const g = async (f, y) => p.isSwipePending() ? () => ({}) : y === "in" && (!o || !o.from) ? () => ({}) : (o || (o = {}), y === "out" ? (o.from = f, new Promise((S) => {
1061
- o.outResolve = S, c();
1062
- })) : (o.to = f, new Promise((S) => {
1063
- o.inResolve = S, c();
936
+ const p = async (m, f) => g.isSwipePending() ? (g.resetSwipeDetection(), () => ({})) : f === "in" && (!o || !o.from) ? () => ({}) : (o || (o = {}), f === "out" ? (o.from = m, new Promise((S) => {
937
+ o.outResolve = S, w();
938
+ })) : (o.to = m, new Promise((S) => {
939
+ o.inResolve = S, w();
1064
940
  })));
1065
- return (f) => ({
1066
- key: f,
1067
- in: async (y) => (d(y, f), (await g(f, "in"))(y)),
1068
- out: async (y) => (await g(f, "out"))(y),
941
+ return (m) => ({
942
+ key: m,
943
+ in: async (f) => (a(f, m), (await p(m, "in"))(f)),
944
+ out: async (f) => (await p(m, "out"))(f),
1069
945
  // Add page transition strategy for page-level transitions
1070
- [U]: N
946
+ [Y]: et
1071
947
  });
1072
948
  }
1073
949
  export {
1074
- U as TRANSITION_STRATEGY,
1075
- H as createDefaultStrategy,
1076
- N as createPageTransitionStrategy,
1077
- ot as createSggoiTransitionContext,
1078
- K as generateAutoKey,
1079
- V as isMultiSpring,
1080
- at as isSingleSpring,
1081
- lt as jaeminInternal,
1082
- nt as transition
950
+ Y as TRANSITION_STRATEGY,
951
+ tt as createDefaultStrategy,
952
+ et as createPageTransitionStrategy,
953
+ pt as createSggoiTransitionContext,
954
+ st as generateAutoKey,
955
+ vt as isCssAnimation,
956
+ St as isMultiSpring,
957
+ Ct as isSingleSpring,
958
+ At as isTickAnimation,
959
+ bt as jaeminInternal,
960
+ M as normalizeMultiSpringSchedule,
961
+ V as normalizeToMultiSpring,
962
+ gt as transition,
963
+ Et as validateAnimationMode,
964
+ Tt as validateSpringItem
1083
965
  };