@nil-/xit 0.2.3 → 0.2.4

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.
@@ -0,0 +1,3 @@
1
+ const d = "5";
2
+ var e;
3
+ typeof window < "u" && ((e = window.__svelte ?? (window.__svelte = {})).v ?? (e.v = /* @__PURE__ */ new Set())).add(d);
@@ -0,0 +1,460 @@
1
+ var et = (e) => {
2
+ throw TypeError(e);
3
+ };
4
+ var X = (e, t, s) => t.has(e) || et("Cannot " + s);
5
+ var r = (e, t, s) => (X(e, t, "read from private field"), s ? s.call(e) : t.get(e)), a = (e, t, s) => t.has(e) ? et("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), h = (e, t, s, n) => (X(e, t, "write to private field"), n ? n.call(e, s) : t.set(e, s), s), st = (e, t, s) => (X(e, t, "access private method"), s);
6
+ import "./internal/client.js";
7
+ import { o as dt, b as S, c as rt, a as g, k as ut, n as lt, g as _ } from "./index.js";
8
+ import { c as mt, w as nt } from "./store.js";
9
+ import { linear as it } from "./easing.js";
10
+ const pt = () => performance.now(), l = {
11
+ // don't access requestAnimationFrame eagerly outside method
12
+ // this allows basic testing of user code without JSDOM
13
+ // bunder will eval and remove ternary when the user's app is built
14
+ tick: (
15
+ /** @param {any} _ */
16
+ (e) => requestAnimationFrame(e)
17
+ ),
18
+ now: () => pt(),
19
+ tasks: /* @__PURE__ */ new Set()
20
+ };
21
+ function ot() {
22
+ const e = l.now();
23
+ l.tasks.forEach((t) => {
24
+ t.c(e) || (l.tasks.delete(t), t.f());
25
+ }), l.tasks.size !== 0 && l.tick(ot);
26
+ }
27
+ function U(e) {
28
+ let t;
29
+ return l.tasks.size === 0 && l.tick(ot), {
30
+ promise: new Promise((s) => {
31
+ l.tasks.add(t = { c: e, f: s });
32
+ }),
33
+ abort() {
34
+ l.tasks.delete(t);
35
+ }
36
+ };
37
+ }
38
+ var V, B;
39
+ class gt {
40
+ /**
41
+ *
42
+ * @param {() => T} fn
43
+ * @param {(update: () => void) => void} onsubscribe
44
+ */
45
+ constructor(t, s) {
46
+ a(this, V);
47
+ a(this, B);
48
+ h(this, V, t), h(this, B, mt(s));
49
+ }
50
+ get current() {
51
+ return r(this, B).call(this), r(this, V).call(this);
52
+ }
53
+ }
54
+ V = new WeakMap(), B = new WeakMap();
55
+ const bt = /\(.+\)/;
56
+ class yt extends gt {
57
+ /**
58
+ * @param {string} query A media query string
59
+ * @param {boolean} [fallback] Fallback value for the server
60
+ */
61
+ constructor(t, s) {
62
+ let n = bt.test(t) ? t : `(${t})`;
63
+ const o = window.matchMedia(n);
64
+ super(
65
+ () => o.matches,
66
+ (i) => dt(o, "change", i)
67
+ );
68
+ }
69
+ }
70
+ function J(e) {
71
+ return Object.prototype.toString.call(e) === "[object Date]";
72
+ }
73
+ function K(e, t, s, n) {
74
+ if (typeof s == "number" || J(s)) {
75
+ const o = n - s, i = (s - t) / (e.dt || 1 / 60), f = e.opts.stiffness * o, c = e.opts.damping * i, d = (f - c) * e.inv_mass, m = (i + d) * e.dt;
76
+ return Math.abs(m) < e.opts.precision && Math.abs(o) < e.opts.precision ? n : (e.settled = !1, J(s) ? new Date(s.getTime() + m) : s + m);
77
+ } else {
78
+ if (Array.isArray(s))
79
+ return s.map(
80
+ (o, i) => (
81
+ // @ts-ignore
82
+ K(e, t[i], s[i], n[i])
83
+ )
84
+ );
85
+ if (typeof s == "object") {
86
+ const o = {};
87
+ for (const i in s)
88
+ o[i] = K(e, t[i], s[i], n[i]);
89
+ return o;
90
+ } else
91
+ throw new Error(`Cannot spring ${typeof s} values`);
92
+ }
93
+ }
94
+ function wt(e, t = {}) {
95
+ const s = nt(e), { stiffness: n = 0.15, damping: o = 0.8, precision: i = 0.01 } = t;
96
+ let f, c, d, m = (
97
+ /** @type {T} */
98
+ e
99
+ ), b = (
100
+ /** @type {T | undefined} */
101
+ e
102
+ ), u = 1, P = 0, y = !1;
103
+ function A(O, w = {}) {
104
+ b = O;
105
+ const ct = d = {};
106
+ return e == null || w.hard || E.stiffness >= 1 && E.damping >= 1 ? (y = !0, f = l.now(), m = O, s.set(e = b), Promise.resolve()) : (w.soft && (P = 1 / ((w.soft === !0 ? 0.5 : +w.soft) * 60), u = 0), c || (f = l.now(), y = !1, c = U((Q) => {
107
+ if (y)
108
+ return y = !1, c = null, !1;
109
+ u = Math.min(u + P, 1);
110
+ const at = Math.min(Q - f, 1e3 / 30), W = {
111
+ inv_mass: u,
112
+ opts: E,
113
+ settled: !0,
114
+ dt: at * 60 / 1e3
115
+ }, ht = K(W, m, e, b);
116
+ return f = Q, m = /** @type {T} */
117
+ e, s.set(e = /** @type {T} */
118
+ ht), W.settled && (c = null), !W.settled;
119
+ })), new Promise((Q) => {
120
+ c.promise.then(() => {
121
+ ct === d && Q();
122
+ });
123
+ }));
124
+ }
125
+ const E = {
126
+ set: A,
127
+ update: (O, w) => A(O(
128
+ /** @type {T} */
129
+ b,
130
+ /** @type {T} */
131
+ e
132
+ ), w),
133
+ subscribe: s.subscribe,
134
+ stiffness: n,
135
+ damping: o,
136
+ precision: i
137
+ };
138
+ return E;
139
+ }
140
+ var z, D, T, p, j, C, q, R, G, k, x, N, ft;
141
+ const v = class v {
142
+ /**
143
+ * @param {T} value
144
+ * @param {SpringOpts} [options]
145
+ */
146
+ constructor(t, s = {}) {
147
+ a(this, N);
148
+ a(this, z, S(0.15));
149
+ a(this, D, S(0.8));
150
+ a(this, T, S(0.01));
151
+ a(this, p, S(
152
+ /** @type {T} */
153
+ void 0
154
+ ));
155
+ a(this, j, S(
156
+ /** @type {T} */
157
+ void 0
158
+ ));
159
+ a(this, C);
160
+ a(this, q, 0);
161
+ a(this, R, 1);
162
+ a(this, G, 0);
163
+ /** @type {import('../internal/client/types').Task | null} */
164
+ a(this, k, null);
165
+ /** @type {ReturnType<typeof deferred> | null} */
166
+ a(this, x, null);
167
+ r(this, p).v = r(this, j).v = t, typeof s.stiffness == "number" && (r(this, z).v = I(s.stiffness, 0, 1)), typeof s.damping == "number" && (r(this, D).v = I(s.damping, 0, 1)), typeof s.precision == "number" && (r(this, T).v = s.precision);
168
+ }
169
+ /**
170
+ * Create a spring whose value is bound to the return value of `fn`. This must be called
171
+ * inside an effect root (for example, during component initialisation).
172
+ *
173
+ * ```svelte
174
+ * <script>
175
+ * import { Spring } from 'svelte/motion';
176
+ *
177
+ * let { number } = $props();
178
+ *
179
+ * const spring = Spring.of(() => number);
180
+ * <\/script>
181
+ * ```
182
+ * @template U
183
+ * @param {() => U} fn
184
+ * @param {SpringOpts} [options]
185
+ */
186
+ static of(t, s) {
187
+ const n = new v(t(), s);
188
+ return rt(() => {
189
+ n.set(t());
190
+ }), n;
191
+ }
192
+ /**
193
+ * Sets `spring.target` to `value` and returns a `Promise` that resolves if and when `spring.current` catches up to it.
194
+ *
195
+ * If `options.instant` is `true`, `spring.current` immediately matches `spring.target`.
196
+ *
197
+ * If `options.preserveMomentum` is provided, the spring will continue on its current trajectory for
198
+ * the specified number of milliseconds. This is useful for things like 'fling' gestures.
199
+ *
200
+ * @param {T} value
201
+ * @param {SpringUpdateOpts} [options]
202
+ */
203
+ set(t, s) {
204
+ var o, i;
205
+ if ((o = r(this, x)) == null || o.reject(new Error("Aborted")), s != null && s.instant || r(this, p).v === void 0)
206
+ return (i = r(this, k)) == null || i.abort(), h(this, k, null), g(r(this, p), g(r(this, j), t)), h(this, C, t), Promise.resolve();
207
+ s != null && s.preserveMomentum && (h(this, R, 0), h(this, G, s.preserveMomentum));
208
+ var n = h(this, x, ut());
209
+ return n.promise.catch(lt), st(this, N, ft).call(this, t).then(() => {
210
+ n === r(this, x) && n.resolve(void 0);
211
+ }), n.promise;
212
+ }
213
+ get current() {
214
+ return _(r(this, p));
215
+ }
216
+ get damping() {
217
+ return _(r(this, D));
218
+ }
219
+ set damping(t) {
220
+ g(r(this, D), I(t, 0, 1));
221
+ }
222
+ get precision() {
223
+ return _(r(this, T));
224
+ }
225
+ set precision(t) {
226
+ g(r(this, T), t);
227
+ }
228
+ get stiffness() {
229
+ return _(r(this, z));
230
+ }
231
+ set stiffness(t) {
232
+ g(r(this, z), I(t, 0, 1));
233
+ }
234
+ get target() {
235
+ return _(r(this, j));
236
+ }
237
+ set target(t) {
238
+ this.set(t);
239
+ }
240
+ };
241
+ z = new WeakMap(), D = new WeakMap(), T = new WeakMap(), p = new WeakMap(), j = new WeakMap(), C = new WeakMap(), q = new WeakMap(), R = new WeakMap(), G = new WeakMap(), k = new WeakMap(), x = new WeakMap(), N = new WeakSet(), /** @param {T} value */
242
+ ft = function(t) {
243
+ var n;
244
+ if (g(r(this, j), t), (n = r(this, p)).v ?? (n.v = t), r(this, C) ?? h(this, C, r(this, p).v), !r(this, k)) {
245
+ h(this, q, l.now());
246
+ var s = 1e3 / (r(this, G) * 60);
247
+ r(this, k) ?? h(this, k, U((o) => {
248
+ h(this, R, Math.min(r(this, R) + s, 1));
249
+ const i = Math.min(o - r(this, q), 1e3 / 30), f = {
250
+ inv_mass: r(this, R),
251
+ opts: {
252
+ stiffness: r(this, z).v,
253
+ damping: r(this, D).v,
254
+ precision: r(this, T).v
255
+ },
256
+ settled: !0,
257
+ dt: i * 60 / 1e3
258
+ };
259
+ var c = K(f, r(this, C), r(this, p).v, r(this, j).v);
260
+ return h(this, C, r(this, p).v), h(this, q, o), g(r(this, p), c), f.settled && h(this, k, null), !f.settled;
261
+ }));
262
+ }
263
+ return r(this, k).promise;
264
+ };
265
+ let Y = v;
266
+ function I(e, t, s) {
267
+ return Math.max(t, Math.min(s, e));
268
+ }
269
+ function L(e, t) {
270
+ if (e === t || e !== e) return () => e;
271
+ const s = typeof e;
272
+ if (s !== typeof t || Array.isArray(e) !== Array.isArray(t))
273
+ throw new Error("Cannot interpolate values of different type");
274
+ if (Array.isArray(e)) {
275
+ const n = (
276
+ /** @type {Array<any>} */
277
+ t.map((o, i) => L(
278
+ /** @type {Array<any>} */
279
+ e[i],
280
+ o
281
+ ))
282
+ );
283
+ return (o) => n.map((i) => i(o));
284
+ }
285
+ if (s === "object") {
286
+ if (!e || !t)
287
+ throw new Error("Object cannot be null");
288
+ if (J(e) && J(t)) {
289
+ const i = e.getTime(), c = t.getTime() - i;
290
+ return (d) => new Date(i + d * c);
291
+ }
292
+ const n = Object.keys(t), o = {};
293
+ return n.forEach((i) => {
294
+ o[i] = L(e[i], t[i]);
295
+ }), (i) => {
296
+ const f = {};
297
+ return n.forEach((c) => {
298
+ f[c] = o[c](i);
299
+ }), f;
300
+ };
301
+ }
302
+ if (s === "number") {
303
+ const n = (
304
+ /** @type {number} */
305
+ t - /** @type {number} */
306
+ e
307
+ );
308
+ return (o) => e + o * n;
309
+ }
310
+ return () => t;
311
+ }
312
+ function kt(e, t = {}) {
313
+ const s = nt(e);
314
+ let n, o = e;
315
+ function i(f, c) {
316
+ if (o = f, e == null)
317
+ return s.set(e = f), Promise.resolve();
318
+ let d = n, m = !1, {
319
+ delay: b = 0,
320
+ duration: u = 400,
321
+ easing: P = it,
322
+ interpolate: y = L
323
+ } = { ...t, ...c };
324
+ if (u === 0)
325
+ return d && (d.abort(), d = null), s.set(e = o), Promise.resolve();
326
+ const A = l.now() + b;
327
+ let E;
328
+ return n = U((O) => {
329
+ if (O < A) return !0;
330
+ m || (E = y(
331
+ /** @type {any} */
332
+ e,
333
+ f
334
+ ), typeof u == "function" && (u = u(
335
+ /** @type {any} */
336
+ e,
337
+ f
338
+ )), m = !0), d && (d.abort(), d = null);
339
+ const w = O - A;
340
+ return w > /** @type {number} */
341
+ u ? (s.set(e = f), !1) : (s.set(e = E(P(w / u))), !0);
342
+ }), n.promise;
343
+ }
344
+ return {
345
+ set: i,
346
+ update: (f, c) => i(f(
347
+ /** @type {any} */
348
+ o,
349
+ /** @type {any} */
350
+ e
351
+ ), c),
352
+ subscribe: s.subscribe
353
+ };
354
+ }
355
+ var M, F, H, $;
356
+ const tt = class tt {
357
+ /**
358
+ * @param {T} value
359
+ * @param {TweenedOptions<T>} options
360
+ */
361
+ constructor(t, s = {}) {
362
+ a(this, M, S(
363
+ /** @type {T} */
364
+ void 0
365
+ ));
366
+ a(this, F, S(
367
+ /** @type {T} */
368
+ void 0
369
+ ));
370
+ /** @type {TweenedOptions<T>} */
371
+ a(this, H);
372
+ /** @type {import('../internal/client/types').Task | null} */
373
+ a(this, $, null);
374
+ r(this, M).v = r(this, F).v = t, h(this, H, s);
375
+ }
376
+ /**
377
+ * Create a tween whose value is bound to the return value of `fn`. This must be called
378
+ * inside an effect root (for example, during component initialisation).
379
+ *
380
+ * ```svelte
381
+ * <script>
382
+ * import { Tween } from 'svelte/motion';
383
+ *
384
+ * let { number } = $props();
385
+ *
386
+ * const tween = Tween.of(() => number);
387
+ * <\/script>
388
+ * ```
389
+ * @template U
390
+ * @param {() => U} fn
391
+ * @param {TweenedOptions<U>} [options]
392
+ */
393
+ static of(t, s) {
394
+ const n = new tt(t(), s);
395
+ return rt(() => {
396
+ n.set(t());
397
+ }), n;
398
+ }
399
+ /**
400
+ * Sets `tween.target` to `value` and returns a `Promise` that resolves if and when `tween.current` catches up to it.
401
+ *
402
+ * If `options` are provided, they will override the tween's defaults.
403
+ * @param {T} value
404
+ * @param {TweenedOptions<T>} [options]
405
+ * @returns
406
+ */
407
+ set(t, s) {
408
+ var u;
409
+ g(r(this, F), t);
410
+ let {
411
+ delay: n = 0,
412
+ duration: o = 400,
413
+ easing: i = it,
414
+ interpolate: f = L
415
+ } = { ...r(this, H), ...s };
416
+ if (o === 0)
417
+ return (u = r(this, $)) == null || u.abort(), g(r(this, M), t), Promise.resolve();
418
+ const c = l.now() + n;
419
+ let d, m = !1, b = r(this, $);
420
+ return h(this, $, U((P) => {
421
+ if (P < c)
422
+ return !0;
423
+ if (!m) {
424
+ m = !0;
425
+ const A = r(this, M).v;
426
+ d = f(A, t), typeof o == "function" && (o = o(A, t)), b == null || b.abort();
427
+ }
428
+ const y = P - c;
429
+ return y > /** @type {number} */
430
+ o ? (g(r(this, M), t), !1) : (g(r(this, M), d(i(y / /** @type {number} */
431
+ o))), !0);
432
+ })), r(this, $).promise;
433
+ }
434
+ get current() {
435
+ return _(r(this, M));
436
+ }
437
+ get target() {
438
+ return _(r(this, F));
439
+ }
440
+ set target(t) {
441
+ this.set(t);
442
+ }
443
+ };
444
+ M = new WeakMap(), F = new WeakMap(), H = new WeakMap(), $ = new WeakMap();
445
+ let Z = tt;
446
+ const Mt = /* @__PURE__ */ new yt(
447
+ "(prefers-reduced-motion: reduce)"
448
+ ), St = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
449
+ __proto__: null,
450
+ Spring: Y,
451
+ Tween: Z,
452
+ prefersReducedMotion: Mt,
453
+ spring: wt,
454
+ tweened: kt
455
+ }, Symbol.toStringTag, { value: "Module" }));
456
+ export {
457
+ St as i,
458
+ U as l,
459
+ l as r
460
+ };
@@ -0,0 +1,173 @@
1
+ import { n as l, u as w, s as B, r as C, a as E, e as j, g as M, b as P, c as k, t as T, d as y, f as h, h as m, i as S, j as $ } from "./index.js";
2
+ import "./internal/client.js";
3
+ function q(e, r, n) {
4
+ if (e == null)
5
+ return r(void 0), n && n(void 0), l;
6
+ const t = w(
7
+ () => e.subscribe(
8
+ r,
9
+ // @ts-expect-error
10
+ n
11
+ )
12
+ );
13
+ return t.unsubscribe ? () => t.unsubscribe() : t;
14
+ }
15
+ const b = [];
16
+ function x(e, r) {
17
+ return {
18
+ subscribe: v(e, r).subscribe
19
+ };
20
+ }
21
+ function v(e, r = l) {
22
+ let n = null;
23
+ const t = /* @__PURE__ */ new Set();
24
+ function i(u) {
25
+ if (B(e, u) && (e = u, n)) {
26
+ const a = !b.length;
27
+ for (const s of t)
28
+ s[1](), b.push(s, e);
29
+ if (a) {
30
+ for (let s = 0; s < b.length; s += 2)
31
+ b[s][0](b[s + 1]);
32
+ b.length = 0;
33
+ }
34
+ }
35
+ }
36
+ function c(u) {
37
+ i(u(
38
+ /** @type {T} */
39
+ e
40
+ ));
41
+ }
42
+ function o(u, a = l) {
43
+ const s = [u, a];
44
+ return t.add(s), t.size === 1 && (n = r(i, c) || l), u(
45
+ /** @type {T} */
46
+ e
47
+ ), () => {
48
+ t.delete(s), t.size === 0 && n && (n(), n = null);
49
+ };
50
+ }
51
+ return { set: i, update: c, subscribe: o };
52
+ }
53
+ function D(e, r, n) {
54
+ const t = !Array.isArray(e), i = t ? [e] : e;
55
+ if (!i.every(Boolean))
56
+ throw new Error("derived() expects stores as input, got a falsy value");
57
+ const c = r.length < 2;
58
+ return x(n, (o, u) => {
59
+ let a = !1;
60
+ const s = [];
61
+ let d = 0, _ = l;
62
+ const g = () => {
63
+ if (d)
64
+ return;
65
+ _();
66
+ const f = r(t ? s[0] : s, o, u);
67
+ c ? o(f) : _ = typeof f == "function" ? f : l;
68
+ }, A = i.map(
69
+ (f, p) => q(
70
+ f,
71
+ (O) => {
72
+ s[p] = O, d &= ~(1 << p), a && g();
73
+ },
74
+ () => {
75
+ d |= 1 << p;
76
+ }
77
+ )
78
+ );
79
+ return a = !0, g(), function() {
80
+ C(A), _(), a = !1;
81
+ };
82
+ });
83
+ }
84
+ function F(e) {
85
+ return {
86
+ // @ts-expect-error TODO i suspect the bind is unnecessary
87
+ subscribe: e.subscribe.bind(e)
88
+ };
89
+ }
90
+ function z(e) {
91
+ let r;
92
+ return q(e, (n) => r = n)(), r;
93
+ }
94
+ function G(e) {
95
+ E(e, e.v + 1);
96
+ }
97
+ function H(e) {
98
+ let r = 0, n = P(0), t;
99
+ return () => {
100
+ j() && (M(n), k(() => (r === 0 && (t = w(() => e(() => G(n)))), r += 1, () => {
101
+ T().then(() => {
102
+ r -= 1, r === 0 && (t == null || t(), t = void 0);
103
+ });
104
+ })));
105
+ };
106
+ }
107
+ function I(e, r) {
108
+ var n = S, t = h, i = e();
109
+ const c = v(i, (o) => {
110
+ var u = i !== e(), a, s = h, d = S;
111
+ y(t), m(n);
112
+ try {
113
+ a = $(() => {
114
+ k(() => {
115
+ const _ = e();
116
+ u && o(_);
117
+ });
118
+ });
119
+ } finally {
120
+ y(s), m(d);
121
+ }
122
+ return u = !0, a;
123
+ });
124
+ return r ? {
125
+ set: r,
126
+ update: (o) => r(o(e())),
127
+ subscribe: c.subscribe
128
+ } : {
129
+ subscribe: c.subscribe
130
+ };
131
+ }
132
+ function J(e) {
133
+ let r;
134
+ const n = H((i) => {
135
+ let c = !1;
136
+ const o = e.subscribe((u) => {
137
+ r = u, c && i();
138
+ });
139
+ return c = !0, o;
140
+ });
141
+ function t() {
142
+ return j() ? (n(), r) : z(e);
143
+ }
144
+ return "set" in e ? {
145
+ get current() {
146
+ return t();
147
+ },
148
+ set current(i) {
149
+ e.set(i);
150
+ }
151
+ } : {
152
+ get current() {
153
+ return t();
154
+ }
155
+ };
156
+ }
157
+ const N = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
158
+ __proto__: null,
159
+ derived: D,
160
+ fromStore: J,
161
+ get: z,
162
+ readable: x,
163
+ readonly: F,
164
+ toStore: I,
165
+ writable: v
166
+ }, Symbol.toStringTag, { value: "Module" }));
167
+ export {
168
+ H as c,
169
+ z as g,
170
+ N as i,
171
+ q as s,
172
+ v as w
173
+ };