@ssgoi/react 0.0.7 → 2.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.
package/dist/index.js CHANGED
@@ -1,774 +1,8 @@
1
- import { r as Lt } from "./utils-DR41YsAh-mLT5vDuI.js";
2
- import { jsx as mt } from "react/jsx-runtime";
3
- import { createContext as Bt, useContext as Wt, useMemo as Gt } from "react";
4
- var Ht = Object.defineProperty, zt = (t, e, n) => e in t ? Ht(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, j = (t, e, n) => zt(t, typeof e != "symbol" ? e + "" : e, n);
5
- function dt(t, e) {
6
- var n = {};
7
- for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && e.indexOf(r) < 0 && (n[r] = t[r]);
8
- if (t != null && typeof Object.getOwnPropertySymbols == "function")
9
- for (var o = 0, r = Object.getOwnPropertySymbols(t); o < r.length; o++)
10
- e.indexOf(r[o]) < 0 && Object.prototype.propertyIsEnumerable.call(t, r[o]) && (n[r[o]] = t[r[o]]);
11
- return n;
12
- }
13
- var _ = function() {
14
- }, E = function() {
15
- };
16
- process.env.NODE_ENV !== "production" && (_ = function(t, e) {
17
- !t && typeof console < "u" && console.warn(e);
18
- }, E = function(t, e) {
19
- if (!t)
20
- throw new Error(e);
21
- });
22
- const H = (t, e, n) => Math.min(Math.max(n, t), e), B = 1e-3, Jt = 0.01, at = 10, Kt = 0.05, Qt = 1;
23
- function Xt({ duration: t = 800, bounce: e = 0.25, velocity: n = 0, mass: r = 1 }) {
24
- let o, a;
25
- _(t <= at * 1e3, "Spring duration must be 10 seconds or less");
26
- let s = 1 - e;
27
- s = H(Kt, Qt, s), t = H(Jt, at, t / 1e3), s < 1 ? (o = (u) => {
28
- const h = u * s, m = h * t, i = h - n, l = z(u, s), p = Math.exp(-m);
29
- return B - i / l * p;
30
- }, a = (u) => {
31
- const h = u * s * t, m = h * n + n, i = Math.pow(s, 2) * Math.pow(u, 2) * t, l = Math.exp(-h), p = z(Math.pow(u, 2), s);
32
- return (-o(u) + B > 0 ? -1 : 1) * ((m - i) * l) / p;
33
- }) : (o = (u) => {
34
- const h = Math.exp(-u * t), m = (u - n) * t + 1;
35
- return -B + h * m;
36
- }, a = (u) => {
37
- const h = Math.exp(-u * t), m = (n - u) * (t * t);
38
- return h * m;
39
- });
40
- const f = 5 / t, c = Zt(o, a, f);
41
- if (t = t * 1e3, isNaN(c))
42
- return {
43
- stiffness: 100,
44
- damping: 10,
45
- duration: t
46
- };
47
- {
48
- const u = Math.pow(c, 2) * r;
49
- return {
50
- stiffness: u,
51
- damping: s * 2 * Math.sqrt(r * u),
52
- duration: t
53
- };
54
- }
55
- }
56
- const Yt = 12;
57
- function Zt(t, e, n) {
58
- let r = n;
59
- for (let o = 1; o < Yt; o++)
60
- r = r - t(r) / e(r);
61
- return r;
62
- }
63
- function z(t, e) {
64
- return t * Math.sqrt(1 - e * e);
65
- }
66
- const _t = ["duration", "bounce"], te = ["stiffness", "damping", "mass"];
67
- function it(t, e) {
68
- return e.some((n) => t[n] !== void 0);
69
- }
70
- function ee(t) {
71
- let e = Object.assign({ velocity: 0, stiffness: 100, damping: 10, mass: 1, isResolvedFromDuration: !1 }, t);
72
- if (!it(t, te) && it(t, _t)) {
73
- const n = Xt(t);
74
- e = Object.assign(Object.assign(Object.assign({}, e), n), { velocity: 0, mass: 1 }), e.isResolvedFromDuration = !0;
75
- }
76
- return e;
77
- }
78
- function tt(t) {
79
- var { from: e = 0, to: n = 1, restSpeed: r = 2, restDelta: o } = t, a = dt(t, ["from", "to", "restSpeed", "restDelta"]);
80
- const s = { done: !1, value: e };
81
- let { stiffness: f, damping: c, mass: u, velocity: h, duration: m, isResolvedFromDuration: i } = ee(a), l = lt, p = lt;
82
- function y() {
83
- const b = h ? -(h / 1e3) : 0, d = n - e, g = c / (2 * Math.sqrt(f * u)), w = Math.sqrt(f / u) / 1e3;
84
- if (o === void 0 && (o = Math.min(Math.abs(n - e) / 100, 0.4)), g < 1) {
85
- const v = z(w, g);
86
- l = (M) => {
87
- const x = Math.exp(-g * w * M);
88
- return n - x * ((b + g * w * d) / v * Math.sin(v * M) + d * Math.cos(v * M));
89
- }, p = (M) => {
90
- const x = Math.exp(-g * w * M);
91
- return g * w * x * (Math.sin(v * M) * (b + g * w * d) / v + d * Math.cos(v * M)) - x * (Math.cos(v * M) * (b + g * w * d) - v * d * Math.sin(v * M));
92
- };
93
- } else if (g === 1)
94
- l = (v) => n - Math.exp(-w * v) * (d + (b + w * d) * v);
95
- else {
96
- const v = w * Math.sqrt(g * g - 1);
97
- l = (M) => {
98
- const x = Math.exp(-g * w * M), A = Math.min(v * M, 300);
99
- return n - x * ((b + g * w * d) * Math.sinh(A) + v * d * Math.cosh(A)) / v;
100
- };
101
- }
102
- }
103
- return y(), {
104
- next: (b) => {
105
- const d = l(b);
106
- if (i)
107
- s.done = b >= m;
108
- else {
109
- const g = p(b) * 1e3, w = Math.abs(g) <= r, v = Math.abs(n - d) <= o;
110
- s.done = w && v;
111
- }
112
- return s.value = s.done ? n : d, s;
113
- },
114
- flipTarget: () => {
115
- h = -h, [e, n] = [n, e], y();
116
- }
117
- };
118
- }
119
- tt.needsInterpolation = (t, e) => typeof t == "string" || typeof e == "string";
120
- const lt = (t) => 0, gt = (t, e, n) => {
121
- const r = e - t;
122
- return r === 0 ? 1 : (n - t) / r;
123
- }, et = (t, e, n) => -n * t + n * e + t, vt = (t, e) => (n) => Math.max(Math.min(n, e), t), R = (t) => t % 1 ? Number(t.toFixed(5)) : t, D = /(-)?([\d]*\.?[\d])+/g, J = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2}(-?[\d\.]+%?)\s*[\,\/]?\s*[\d\.]*%?\))/gi, ne = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2}(-?[\d\.]+%?)\s*[\,\/]?\s*[\d\.]*%?\))$/i;
124
- function T(t) {
125
- return typeof t == "string";
126
- }
127
- const U = {
128
- test: (t) => typeof t == "number",
129
- parse: parseFloat,
130
- transform: (t) => t
131
- }, yt = Object.assign(Object.assign({}, U), { transform: vt(0, 1) });
132
- Object.assign(Object.assign({}, U), { default: 1 });
133
- const re = (t) => ({
134
- test: (e) => T(e) && e.endsWith(t) && e.split(" ").length === 1,
135
- parse: parseFloat,
136
- transform: (e) => `${e}${t}`
137
- }), V = re("%");
138
- Object.assign(Object.assign({}, V), { parse: (t) => V.parse(t) / 100, transform: (t) => V.transform(t * 100) });
139
- const nt = (t, e) => (n) => !!(T(n) && ne.test(n) && n.startsWith(t) || e && Object.prototype.hasOwnProperty.call(n, e)), bt = (t, e, n) => (r) => {
140
- if (!T(r))
141
- return r;
142
- const [o, a, s, f] = r.match(D);
143
- return {
144
- [t]: parseFloat(o),
145
- [e]: parseFloat(a),
146
- [n]: parseFloat(s),
147
- alpha: f !== void 0 ? parseFloat(f) : 1
148
- };
149
- }, S = {
150
- test: nt("hsl", "hue"),
151
- parse: bt("hue", "saturation", "lightness"),
152
- transform: ({ hue: t, saturation: e, lightness: n, alpha: r = 1 }) => "hsla(" + Math.round(t) + ", " + V.transform(R(e)) + ", " + V.transform(R(n)) + ", " + R(yt.transform(r)) + ")"
153
- }, oe = vt(0, 255), W = Object.assign(Object.assign({}, U), { transform: (t) => Math.round(oe(t)) }), O = {
154
- test: nt("rgb", "red"),
155
- parse: bt("red", "green", "blue"),
156
- transform: ({ red: t, green: e, blue: n, alpha: r = 1 }) => "rgba(" + W.transform(t) + ", " + W.transform(e) + ", " + W.transform(n) + ", " + R(yt.transform(r)) + ")"
157
- };
158
- function se(t) {
159
- let e = "", n = "", r = "", o = "";
160
- return t.length > 5 ? (e = t.substr(1, 2), n = t.substr(3, 2), r = t.substr(5, 2), o = t.substr(7, 2)) : (e = t.substr(1, 1), n = t.substr(2, 1), r = t.substr(3, 1), o = t.substr(4, 1), e += e, n += n, r += r, o += o), {
161
- red: parseInt(e, 16),
162
- green: parseInt(n, 16),
163
- blue: parseInt(r, 16),
164
- alpha: o ? parseInt(o, 16) / 255 : 1
165
- };
166
- }
167
- const K = {
168
- test: nt("#"),
169
- parse: se,
170
- transform: O.transform
171
- }, $ = {
172
- test: (t) => O.test(t) || K.test(t) || S.test(t),
173
- parse: (t) => O.test(t) ? O.parse(t) : S.test(t) ? S.parse(t) : K.parse(t),
174
- transform: (t) => T(t) ? t : t.hasOwnProperty("red") ? O.transform(t) : S.transform(t)
175
- }, wt = "${c}", Mt = "${n}";
176
- function ae(t) {
177
- var e, n, r, o;
178
- return isNaN(t) && T(t) && ((n = (e = t.match(D)) === null || e === void 0 ? void 0 : e.length) !== null && n !== void 0 ? n : 0) + ((o = (r = t.match(J)) === null || r === void 0 ? void 0 : r.length) !== null && o !== void 0 ? o : 0) > 0;
179
- }
180
- function xt(t) {
181
- typeof t == "number" && (t = `${t}`);
182
- const e = [];
183
- let n = 0;
184
- const r = t.match(J);
185
- r && (n = r.length, t = t.replace(J, wt), e.push(...r.map($.parse)));
186
- const o = t.match(D);
187
- return o && (t = t.replace(D, Mt), e.push(...o.map(U.parse))), { values: e, numColors: n, tokenised: t };
188
- }
189
- function Ot(t) {
190
- return xt(t).values;
191
- }
192
- function St(t) {
193
- const { values: e, numColors: n, tokenised: r } = xt(t), o = e.length;
194
- return (a) => {
195
- let s = r;
196
- for (let f = 0; f < o; f++)
197
- s = s.replace(f < n ? wt : Mt, f < n ? $.transform(a[f]) : R(a[f]));
198
- return s;
199
- };
200
- }
201
- const ie = (t) => typeof t == "number" ? 0 : t;
202
- function le(t) {
203
- const e = Ot(t);
204
- return St(t)(e.map(ie));
205
- }
206
- const At = { test: ae, parse: Ot, createTransformer: St, getAnimatableNone: le };
207
- function G(t, e, n) {
208
- return n < 0 && (n += 1), n > 1 && (n -= 1), n < 1 / 6 ? t + (e - t) * 6 * n : n < 1 / 2 ? e : n < 2 / 3 ? t + (e - t) * (2 / 3 - n) * 6 : t;
209
- }
210
- function ut({ hue: t, saturation: e, lightness: n, alpha: r }) {
211
- t /= 360, e /= 100, n /= 100;
212
- let o = 0, a = 0, s = 0;
213
- if (!e)
214
- o = a = s = n;
215
- else {
216
- const f = n < 0.5 ? n * (1 + e) : n + e - n * e, c = 2 * n - f;
217
- o = G(c, f, t + 1 / 3), a = G(c, f, t), s = G(c, f, t - 1 / 3);
218
- }
219
- return {
220
- red: Math.round(o * 255),
221
- green: Math.round(a * 255),
222
- blue: Math.round(s * 255),
223
- alpha: r
224
- };
225
- }
226
- const ue = (t, e, n) => {
227
- const r = t * t, o = e * e;
228
- return Math.sqrt(Math.max(0, n * (o - r) + r));
229
- }, ce = [K, O, S], ct = (t) => ce.find((e) => e.test(t)), ft = (t) => `'${t}' is not an animatable color. Use the equivalent color code instead.`, jt = (t, e) => {
230
- let n = ct(t), r = ct(e);
231
- E(!!n, ft(t)), E(!!r, ft(e));
232
- let o = n.parse(t), a = r.parse(e);
233
- n === S && (o = ut(o), n = O), r === S && (a = ut(a), r = O);
234
- const s = Object.assign({}, o);
235
- return (f) => {
236
- for (const c in s)
237
- c !== "alpha" && (s[c] = ue(o[c], a[c], f));
238
- return s.alpha = et(o.alpha, a.alpha, f), n.transform(s);
239
- };
240
- }, fe = (t) => typeof t == "number", pe = (t, e) => (n) => e(t(n)), Ct = (...t) => t.reduce(pe);
241
- function Rt(t, e) {
242
- return fe(t) ? (n) => et(t, e, n) : $.test(t) ? jt(t, e) : Pt(t, e);
243
- }
244
- const Vt = (t, e) => {
245
- const n = [...t], r = n.length, o = t.map((a, s) => Rt(a, e[s]));
246
- return (a) => {
247
- for (let s = 0; s < r; s++)
248
- n[s] = o[s](a);
249
- return n;
250
- };
251
- }, he = (t, e) => {
252
- const n = Object.assign(Object.assign({}, t), e), r = {};
253
- for (const o in n)
254
- t[o] !== void 0 && e[o] !== void 0 && (r[o] = Rt(t[o], e[o]));
255
- return (o) => {
256
- for (const a in r)
257
- n[a] = r[a](o);
258
- return n;
259
- };
260
- };
261
- function pt(t) {
262
- const e = At.parse(t), n = e.length;
263
- let r = 0, o = 0, a = 0;
264
- for (let s = 0; s < n; s++)
265
- r || typeof e[s] == "number" ? r++ : e[s].hue !== void 0 ? a++ : o++;
266
- return { parsed: e, numNumbers: r, numRGB: o, numHSL: a };
267
- }
268
- const Pt = (t, e) => {
269
- const n = At.createTransformer(e), r = pt(t), o = pt(e);
270
- return r.numHSL === o.numHSL && r.numRGB === o.numRGB && r.numNumbers >= o.numNumbers ? Ct(Vt(r.parsed, o.parsed), n) : (_(!0, `Complex values '${t}' and '${e}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition.`), (a) => `${a > 0 ? e : t}`);
271
- }, me = (t, e) => (n) => et(t, e, n);
272
- function de(t) {
273
- if (typeof t == "number")
274
- return me;
275
- if (typeof t == "string")
276
- return $.test(t) ? jt : Pt;
277
- if (Array.isArray(t))
278
- return Vt;
279
- if (typeof t == "object")
280
- return he;
281
- }
282
- function ge(t, e, n) {
283
- const r = [], o = n || de(t[0]), a = t.length - 1;
284
- for (let s = 0; s < a; s++) {
285
- let f = o(t[s], t[s + 1]);
286
- if (e) {
287
- const c = Array.isArray(e) ? e[s] : e;
288
- f = Ct(c, f);
289
- }
290
- r.push(f);
291
- }
292
- return r;
293
- }
294
- function ve([t, e], [n]) {
295
- return (r) => n(gt(t, e, r));
296
- }
297
- function ye(t, e) {
298
- const n = t.length, r = n - 1;
299
- return (o) => {
300
- let a = 0, s = !1;
301
- if (o <= t[0] ? s = !0 : o >= t[r] && (a = r - 1, s = !0), !s) {
302
- let c = 1;
303
- for (; c < n && !(t[c] > o || c === r); c++)
304
- ;
305
- a = c - 1;
306
- }
307
- const f = gt(t[a], t[a + 1], o);
308
- return e[a](f);
309
- };
310
- }
311
- function Et(t, e, { clamp: n = !0, ease: r, mixer: o } = {}) {
312
- const a = t.length;
313
- E(a === e.length, "Both input and output ranges must be the same length"), E(!r || !Array.isArray(r) || r.length === a - 1, "Array of easing functions must be of length `input.length - 1`, as it applies to the transitions **between** the defined values."), t[0] > t[a - 1] && (t = [].concat(t), e = [].concat(e), t.reverse(), e.reverse());
314
- const s = ge(e, r, o), f = a === 2 ? ve(t, s) : ye(t, s);
315
- return n ? (c) => f(H(t[0], t[a - 1], c)) : f;
316
- }
317
- const be = (t) => (e) => e <= 0.5 ? t(2 * e) / 2 : (2 - t(2 * (1 - e))) / 2, we = (t) => (e) => Math.pow(e, t), Me = we(2), xe = be(Me);
318
- function Oe(t, e) {
319
- return t.map(() => e || xe).splice(0, t.length - 1);
320
- }
321
- function Se(t) {
322
- const e = t.length;
323
- return t.map((n, r) => r !== 0 ? r / (e - 1) : 0);
324
- }
325
- function Ae(t, e) {
326
- return t.map((n) => n * e);
327
- }
328
- function N({ from: t = 0, to: e = 1, ease: n, offset: r, duration: o = 300 }) {
329
- const a = { done: !1, value: t }, s = Array.isArray(e) ? e : [t, e], f = Ae(r && r.length === s.length ? r : Se(s), o);
330
- function c() {
331
- return Et(f, s, {
332
- ease: Array.isArray(n) ? n : Oe(s, n)
333
- });
334
- }
335
- let u = c();
336
- return {
337
- next: (h) => (a.value = u(h), a.done = h >= o, a),
338
- flipTarget: () => {
339
- s.reverse(), u = c();
340
- }
341
- };
342
- }
343
- function je({ velocity: t = 0, from: e = 0, power: n = 0.8, timeConstant: r = 350, restDelta: o = 0.5, modifyTarget: a }) {
344
- const s = { done: !1, value: e };
345
- let f = n * t;
346
- const c = e + f, u = a === void 0 ? c : a(c);
347
- return u !== c && (f = u - e), {
348
- next: (h) => {
349
- const m = -f * Math.exp(-h / r);
350
- return s.done = !(m > o || m < -o), s.value = s.done ? u : u + m, s;
351
- },
352
- flipTarget: () => {
353
- }
354
- };
355
- }
356
- const ht = { keyframes: N, spring: tt, decay: je };
357
- function Ce(t) {
358
- if (Array.isArray(t.to))
359
- return N;
360
- if (ht[t.type])
361
- return ht[t.type];
362
- const e = new Set(Object.keys(t));
363
- return e.has("ease") || e.has("duration") && !e.has("dampingRatio") ? N : e.has("dampingRatio") || e.has("stiffness") || e.has("mass") || e.has("damping") || e.has("restSpeed") || e.has("restDelta") ? tt : N;
364
- }
365
- const kt = 1 / 60 * 1e3, Re = typeof performance < "u" ? () => performance.now() : () => Date.now(), Tt = typeof window < "u" ? (t) => window.requestAnimationFrame(t) : (t) => setTimeout(() => t(Re()), kt);
366
- function Ve(t) {
367
- let e = [], n = [], r = 0, o = !1, a = !1;
368
- const s = /* @__PURE__ */ new WeakSet(), f = {
369
- schedule: (c, u = !1, h = !1) => {
370
- const m = h && o, i = m ? e : n;
371
- return u && s.add(c), i.indexOf(c) === -1 && (i.push(c), m && o && (r = e.length)), c;
372
- },
373
- cancel: (c) => {
374
- const u = n.indexOf(c);
375
- u !== -1 && n.splice(u, 1), s.delete(c);
376
- },
377
- process: (c) => {
378
- if (o) {
379
- a = !0;
380
- return;
381
- }
382
- if (o = !0, [e, n] = [n, e], n.length = 0, r = e.length, r)
383
- for (let u = 0; u < r; u++) {
384
- const h = e[u];
385
- h(c), s.has(h) && (f.schedule(h), t());
386
- }
387
- o = !1, a && (a = !1, f.process(c));
388
- }
389
- };
390
- return f;
391
- }
392
- const Pe = 40;
393
- let Q = !0, k = !1, X = !1;
394
- const P = {
395
- delta: 0,
396
- timestamp: 0
397
- }, I = [
398
- "read",
399
- "update",
400
- "preRender",
401
- "render",
402
- "postRender"
403
- ], q = I.reduce((t, e) => (t[e] = Ve(() => k = !0), t), {}), Ee = I.reduce((t, e) => {
404
- const n = q[e];
405
- return t[e] = (r, o = !1, a = !1) => (k || Ie(), n.schedule(r, o, a)), t;
406
- }, {}), ke = I.reduce((t, e) => (t[e] = q[e].cancel, t), {});
407
- I.reduce((t, e) => (t[e] = () => q[e].process(P), t), {});
408
- const Te = (t) => q[t].process(P), It = (t) => {
409
- k = !1, P.delta = Q ? kt : Math.max(Math.min(t - P.timestamp, Pe), 1), P.timestamp = t, X = !0, I.forEach(Te), X = !1, k && (Q = !1, Tt(It));
410
- }, Ie = () => {
411
- k = !0, Q = !0, X || Tt(It);
412
- };
413
- function Ft(t, e, n = 0) {
414
- return t - e - n;
415
- }
416
- function Fe(t, e, n = 0, r = !0) {
417
- return r ? Ft(e + -t, e, n) : e - (t - e) + n;
418
- }
419
- function Ne(t, e, n, r) {
420
- return r ? t >= e + n : t <= -n;
421
- }
422
- const De = (t) => {
423
- const e = ({ delta: n }) => t(n);
424
- return {
425
- start: () => Ee.update(e, !0),
426
- stop: () => ke.update(e)
427
- };
428
- };
429
- function Ue(t) {
430
- var e, n, { from: r, autoplay: o = !0, driver: a = De, elapsed: s = 0, repeat: f = 0, repeatType: c = "loop", repeatDelay: u = 0, onPlay: h, onStop: m, onComplete: i, onRepeat: l, onUpdate: p } = t, y = dt(t, ["from", "autoplay", "driver", "elapsed", "repeat", "repeatType", "repeatDelay", "onPlay", "onStop", "onComplete", "onRepeat", "onUpdate"]);
431
- let { to: b } = y, d, g = 0, w = y.duration, v, M = !1, x = !0, A;
432
- const rt = Ce(y);
433
- !((n = (e = rt).needsInterpolation) === null || n === void 0) && n.call(e, r, b) && (A = Et([0, 100], [r, b], {
434
- clamp: !1
435
- }), r = 0, b = 100);
436
- const ot = rt(Object.assign(Object.assign({}, y), { from: r, to: b }));
437
- function Dt() {
438
- g++, c === "reverse" ? (x = g % 2 === 0, s = Fe(s, w, u, x)) : (s = Ft(s, w, u), c === "mirror" && ot.flipTarget()), M = !1, l && l();
439
- }
440
- function Ut() {
441
- d.stop(), i && i();
442
- }
443
- function $t(L) {
444
- if (x || (L = -L), s += L, !M) {
445
- const st = ot.next(Math.max(0, s));
446
- v = st.value, A && (v = A(v)), M = x ? st.done : s <= 0;
447
- }
448
- p?.(v), M && (g === 0 && (w ?? (w = s)), g < f ? Ne(s, w, u, x) && Dt() : Ut());
449
- }
450
- function qt() {
451
- h?.(), d = a($t), d.start();
452
- }
453
- return o && qt(), {
454
- stop: () => {
455
- m?.(), d.stop();
456
- }
457
- };
458
- }
459
- class C {
460
- constructor(e) {
461
- j(this, "options"), j(this, "currentValue"), j(this, "velocity", 0), j(this, "isAnimating", !1), j(this, "controls", null), j(this, "animate", (n = !1) => {
462
- !this.isAnimating && this.options.onStart && this.options.onStart(), this.isAnimating = !0;
463
- const r = n ? this.options.from : this.options.to;
464
- let o = this.currentValue, a = performance.now();
465
- this.controls = Ue({
466
- from: this.currentValue,
467
- to: r,
468
- velocity: this.velocity * 1e3,
469
- // Convert to px/s
470
- stiffness: this.options.spring.stiffness,
471
- damping: this.options.spring.damping,
472
- mass: 1,
473
- onUpdate: (s) => {
474
- const f = performance.now(), c = (f - a) / 1e3;
475
- if (c > 0) {
476
- const u = (s - o) / c;
477
- this.velocity = u / 1e3, o = s, a = f;
478
- }
479
- this.currentValue = s, this.options.onUpdate(s);
480
- },
481
- onComplete: () => {
482
- this.currentValue = r, this.isAnimating = !1, this.controls = null, this.velocity = 0, this.options.onComplete();
483
- }
484
- });
485
- }), this.options = {
486
- from: e.from ?? 0,
487
- to: e.to ?? 1,
488
- spring: e.spring ?? { stiffness: 100, damping: 10 },
489
- onUpdate: e.onUpdate ?? (() => {
490
- }),
491
- onComplete: e.onComplete ?? (() => {
492
- }),
493
- onStart: e.onStart
494
- }, this.currentValue = this.options.from;
495
- }
496
- // Animation control methods
497
- forward() {
498
- this.stop(), this.animate(!1);
499
- }
500
- backward() {
501
- this.stop(), this.animate(!0);
502
- }
503
- reverse() {
504
- const e = this.options.from;
505
- if (this.options.from = this.options.to, this.options.to = e, this.isAnimating) {
506
- const n = this.currentValue > (this.options.from + this.options.to) / 2;
507
- this.stop(), this.animate(!n);
508
- }
509
- }
510
- stop() {
511
- this.isAnimating = !1, this.controls && (this.controls.stop(), this.controls = null);
512
- }
513
- // State getters
514
- getVelocity() {
515
- return this.velocity;
516
- }
517
- getCurrentValue() {
518
- return this.currentValue;
519
- }
520
- getIsAnimating() {
521
- return this.isAnimating;
522
- }
523
- getCurrentState() {
524
- return {
525
- position: this.currentValue,
526
- velocity: this.velocity
527
- };
528
- }
529
- // State setters
530
- setVelocity(e) {
531
- this.velocity = e;
532
- }
533
- setValue(e) {
534
- this.currentValue = e;
535
- }
536
- // Configuration
537
- updateOptions(e) {
538
- if (this.options = { ...this.options, ...e }, this.isAnimating && this.controls) {
539
- const n = this.currentValue < this.options.to;
540
- this.stop(), this.animate(!n);
541
- }
542
- }
543
- // Static factory method
544
- static fromState(e, n) {
545
- const r = new C(n);
546
- return r.setValue(e.position), r.setVelocity(e.velocity), r;
547
- }
548
- }
549
- function $e(t, e) {
550
- let n = null, r = null, o = null, a = null, s = !1;
551
- const f = async (u) => {
552
- var h;
553
- if (n && n.getIsAnimating() && !s) {
554
- const m = n.getCurrentState();
555
- n.stop(), r && (r.remove(), r = null), s = !0;
556
- const i = t();
557
- if (!i.out) return;
558
- const l = await Promise.resolve(i.out(u));
559
- n = C.fromState(m, {
560
- from: 1,
561
- to: 0,
562
- spring: l.spring,
563
- onStart: l.onStart,
564
- onUpdate: (p) => {
565
- var y;
566
- (y = l.tick) == null || y.call(l, p);
567
- },
568
- onComplete: () => {
569
- var p;
570
- n = null, s = !1, (p = l.onEnd) == null || p.call(l);
571
- }
572
- }), n.backward();
573
- return;
574
- }
575
- if (!n || !n.getIsAnimating()) {
576
- s = !0;
577
- const m = t();
578
- if (!m.in) return;
579
- const i = await Promise.resolve(m.in(u));
580
- (h = i.prepare) == null || h.call(i, u), n = new C({
581
- from: 0,
582
- to: 1,
583
- spring: i.spring,
584
- onStart: i.onStart,
585
- onUpdate: (l) => {
586
- var p;
587
- (p = i.tick) == null || p.call(i, l);
588
- },
589
- onComplete: () => {
590
- var l;
591
- n = null, s = !1, (l = i.onEnd) == null || l.call(i);
592
- }
593
- }), n.forward();
594
- }
595
- };
596
- function c(u) {
597
- const h = () => {
598
- !o || !r || (a && o.contains(a) ? o.insertBefore(r, a) : o.appendChild(r));
599
- }, m = () => {
600
- var l;
601
- r && (r.remove(), r = null), n = null, s = !1, (l = e?.onCleanupEnd) == null || l.call(e);
602
- }, i = t();
603
- if (r = u.cloneNode(!0), n && n.getIsAnimating() && s) {
604
- const l = n.getCurrentState();
605
- if (n.stop(), s = !1, !i.in) {
606
- r = null, m();
607
- return;
608
- }
609
- Promise.resolve(i.in(r)).then(async (p) => {
610
- var y;
611
- const b = r && await ((y = i.out) == null ? void 0 : y.call(i, r));
612
- b != null && b.prepare && r && b.prepare(r), h(), n = C.fromState(l, {
613
- from: 0,
614
- to: 1,
615
- spring: p.spring,
616
- onStart: p.onStart,
617
- onUpdate: (d) => {
618
- var g;
619
- (g = p.tick) == null || g.call(p, d);
620
- },
621
- onComplete: () => {
622
- var d;
623
- (d = p.onEnd) == null || d.call(p), m();
624
- }
625
- }), n.backward();
626
- });
627
- return;
628
- }
629
- if (!n || !n.getIsAnimating() || !s) {
630
- if (s = !1, !i.out) {
631
- r = null, m();
632
- return;
633
- }
634
- Promise.resolve(i.out(r)).then((l) => {
635
- var p;
636
- r && ((p = l.prepare) == null || p.call(l, r)), h(), n = new C({
637
- from: 1,
638
- to: 0,
639
- spring: l.spring,
640
- onStart: l.onStart,
641
- onUpdate: (y) => {
642
- var b;
643
- (b = l.tick) == null || b.call(l, y);
644
- },
645
- onComplete: () => {
646
- var y;
647
- (y = l.onEnd) == null || y.call(l), m();
648
- }
649
- }), n.forward();
650
- });
651
- }
652
- }
653
- return (u) => u ? (o = u.parentElement, a = u.nextElementSibling, t().in && f(u), () => {
654
- c(u);
655
- }) : void 0;
656
- }
657
- const Y = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Map();
658
- function qe(t, e) {
659
- Y.set(t, e);
660
- let n = Z.get(t);
661
- return n || (n = $e(
662
- () => Y.get(t) || (console.warn(`Transition "${String(t)}" not found`), {}),
663
- {
664
- onCleanupEnd: () => Le(t)
665
- }
666
- ), Z.set(t, n), n);
667
- }
668
- function Le(t) {
669
- Y.delete(t), Z.delete(t);
670
- }
671
- function Be(t) {
672
- return qe(t.key, {
673
- in: t.in,
674
- out: t.out
675
- });
676
- }
677
- function We(t) {
678
- let e = null;
679
- const n = [...t.transitions], r = [];
680
- for (const i of t.transitions)
681
- i.symmetric && (n.some(
682
- (l) => l.from === i.to && l.to === i.from
683
- ) || r.push({
684
- from: i.to,
685
- to: i.from,
686
- transition: i.transition
687
- // Don't add symmetric flag to the reverse to avoid infinite loop
688
- }));
689
- n.push(...r);
690
- let o = null;
691
- const a = /* @__PURE__ */ new Map();
692
- let s = null;
693
- const f = () => {
694
- o && s && a.set(s, {
695
- x: o.scrollLeft,
696
- y: o.scrollTop
697
- });
698
- }, c = (i, l) => {
699
- o || (o = Lt(i), o.addEventListener("scroll", f, {
700
- passive: !0
701
- })), s = l;
702
- }, u = () => {
703
- const i = e?.from, l = e?.to, p = i && a.has(i) ? a.get(i) : { x: 0, y: 0 }, y = l && a.has(l) ? a.get(l) : { x: 0, y: 0 };
704
- return {
705
- x: -y.x + p.x,
706
- y: -y.y + p.y
707
- };
708
- };
709
- function h() {
710
- if (e != null && e.from && e != null && e.to) {
711
- const i = Ge(
712
- e.from,
713
- e.to,
714
- n
715
- ) || t.defaultTransition, l = { scrollOffset: u() };
716
- i && (i.out && e.outResolve && e.outResolve(
717
- (p) => i.out(p, l)
718
- ), i.in && e.inResolve && e.inResolve(
719
- (p) => i.in(p, l)
720
- )), e = null;
721
- }
722
- }
723
- const m = async (i, l) => l === "in" && (!e || !e.from) ? () => ({}) : (e || (e = {}), l === "out" ? (e.from = i, new Promise((p) => {
724
- e.outResolve = p, h();
725
- })) : (e.to = i, new Promise((p) => {
726
- e.inResolve = p, h();
727
- })));
728
- return (i) => ({
729
- key: i,
730
- in: async (l) => (c(l, i), (await m(i, "in"))(l)),
731
- out: async (l) => (await m(i, "out"))(l)
732
- });
733
- }
734
- function Ge(t, e, n) {
735
- for (const r of n)
736
- if (F(t, r.from) && F(e, r.to))
737
- return r.transition;
738
- for (const r of n)
739
- if ((r.from === "*" || F(t, r.from)) && (r.to === "*" || F(e, r.to)))
740
- return r.transition;
741
- return null;
742
- }
743
- function F(t, e) {
744
- if (e === "*")
745
- return !0;
746
- if (e.endsWith("/*")) {
747
- const n = e.slice(0, -2);
748
- return t === n || t.startsWith(n + "/");
749
- }
750
- return t === e;
751
- }
752
- const He = Be, Nt = Bt(null), ze = Nt.Provider, Je = () => {
753
- const t = Wt(Nt);
754
- if (!t)
755
- throw new Error("useSsgoi must be used within SsgoiProvider");
756
- return t;
757
- }, Ye = ({ config: t, children: e }) => {
758
- const n = Gt(
759
- () => We(t),
760
- [t]
761
- );
762
- return /* @__PURE__ */ mt(ze, { value: n, children: e });
763
- }, Ze = ({
764
- children: t,
765
- id: e
766
- }) => {
767
- const n = Je();
768
- return /* @__PURE__ */ mt("div", { ref: He(n(e)), "data-ssgoi-transition": e, children: t });
769
- };
1
+ import { transition as i } from "@ssgoi/core";
2
+ import { Ssgoi as n } from "./ssgoi.js";
3
+ import { SsgoiTransition as e } from "./ssgoi-transition.js";
770
4
  export {
771
- Ye as Ssgoi,
772
- Ze as SsgoiTransition,
773
- He as transition
5
+ n as Ssgoi,
6
+ e as SsgoiTransition,
7
+ i as transition
774
8
  };