@nil-/xit 0.1.26 → 0.1.28

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