@manyducks.co/dolla 2.0.0-alpha.40 → 2.0.0-alpha.42

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,1518 @@
1
+ var $e = Object.defineProperty;
2
+ var ue = (t) => {
3
+ throw TypeError(t);
4
+ };
5
+ var Ie = (t, e, s) => e in t ? $e(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
6
+ var l = (t, e, s) => Ie(t, typeof e != "symbol" ? e + "" : e, s), G = (t, e, s) => e.has(t) || ue("Cannot " + s);
7
+ var w = (t, e, s) => (G(t, e, "read from private field"), s ? s.call(t) : e.get(t)), C = (t, e, s) => e.has(t) ? ue("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), $ = (t, e, s, n) => (G(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s), ce = (t, e, s) => (G(t, e, "access private method"), s);
8
+ var M = /* @__PURE__ */ ((t) => (t[t.Computed = 1] = "Computed", t[t.Effect = 2] = "Effect", t[t.Tracking = 4] = "Tracking", t[t.Notified = 8] = "Notified", t[t.Recursed = 16] = "Recursed", t[t.Dirty = 32] = "Dirty", t[t.PendingComputed = 64] = "PendingComputed", t[t.PendingEffect = 128] = "PendingEffect", t[t.Propagated = 224] = "Propagated", t))(M || {});
9
+ function ve({
10
+ updateComputed: t,
11
+ notifyEffect: e
12
+ }) {
13
+ let s, n;
14
+ return {
15
+ /**
16
+ * Links a given dependency and subscriber if they are not already linked.
17
+ *
18
+ * @param dep - The dependency to be linked.
19
+ * @param sub - The subscriber that depends on this dependency.
20
+ * @returns The newly created link object if the two are not already linked; otherwise `undefined`.
21
+ */
22
+ link(r, u) {
23
+ const c = u.depsTail;
24
+ if (c !== void 0 && c.dep === r)
25
+ return;
26
+ const h = c !== void 0 ? c.nextDep : u.deps;
27
+ if (h !== void 0 && h.dep === r) {
28
+ u.depsTail = h;
29
+ return;
30
+ }
31
+ const d = r.subsTail;
32
+ if (!(d !== void 0 && d.sub === u && a(d, u)))
33
+ return i(r, u, h, c);
34
+ },
35
+ /**
36
+ * Traverses and marks subscribers starting from the provided link.
37
+ *
38
+ * It sets flags (e.g., Dirty, PendingComputed, PendingEffect) on each subscriber
39
+ * to indicate which ones require re-computation or effect processing.
40
+ * This function should be called after a signal's value changes.
41
+ *
42
+ * @param link - The starting link from which propagation begins.
43
+ */
44
+ propagate(r) {
45
+ let u = 32, c = r, h = 0;
46
+ e: do {
47
+ const d = r.sub, p = d.flags;
48
+ if (!(p & 244) && (d.flags = p | u | 8, !0) || p & 16 && !(p & 4) && (d.flags = p & -17 | u | 8, !0) || !(p & 224) && a(r, d) && (d.flags = p | 16 | u | 8, d.subs !== void 0)) {
49
+ const x = d.subs;
50
+ if (x !== void 0) {
51
+ x.nextSub !== void 0 ? (x.prevSub = c, r = c = x, u = 64, ++h) : (r = x, u = p & 2 ? 128 : 64);
52
+ continue;
53
+ }
54
+ p & 2 && (n !== void 0 ? n.depsTail.nextDep = d.deps : s = d, n = d);
55
+ } else p & (4 | u) ? !(p & u) && p & 224 && a(r, d) && (d.flags = p | u) : (d.flags = p | u | 8, (p & 10) === 2 && (n !== void 0 ? n.depsTail.nextDep = d.deps : s = d, n = d));
56
+ if ((r = c.nextSub) !== void 0) {
57
+ c = r, u = h ? 64 : 32;
58
+ continue;
59
+ }
60
+ for (; h; ) {
61
+ --h;
62
+ const oe = c.dep.subs;
63
+ if (c = oe.prevSub, oe.prevSub = void 0, (r = c.nextSub) !== void 0) {
64
+ c = r, u = h ? 64 : 32;
65
+ continue e;
66
+ }
67
+ }
68
+ break;
69
+ } while (!0);
70
+ },
71
+ /**
72
+ * Prepares the given subscriber to track new dependencies.
73
+ *
74
+ * It resets the subscriber's internal pointers (e.g., depsTail) and
75
+ * sets its flags to indicate it is now tracking dependency links.
76
+ *
77
+ * @param sub - The subscriber to start tracking.
78
+ */
79
+ startTracking(r) {
80
+ r.depsTail = void 0, r.flags = r.flags & -249 | 4;
81
+ },
82
+ /**
83
+ * Concludes tracking of dependencies for the specified subscriber.
84
+ *
85
+ * It clears or unlinks any tracked dependency information, then
86
+ * updates the subscriber's flags to indicate tracking is complete.
87
+ *
88
+ * @param sub - The subscriber whose tracking is ending.
89
+ */
90
+ endTracking(r) {
91
+ const u = r.depsTail;
92
+ if (u !== void 0) {
93
+ const c = u.nextDep;
94
+ c !== void 0 && (m(c), u.nextDep = void 0);
95
+ } else r.deps !== void 0 && (m(r.deps), r.deps = void 0);
96
+ r.flags &= -5;
97
+ },
98
+ /**
99
+ * Updates the dirty flag for the given subscriber based on its dependencies.
100
+ *
101
+ * If the subscriber has any pending computeds, this function sets the Dirty flag
102
+ * and returns `true`. Otherwise, it clears the PendingComputed flag and returns `false`.
103
+ *
104
+ * @param sub - The subscriber to update.
105
+ * @param flags - The current flag set for this subscriber.
106
+ * @returns `true` if the subscriber is marked as Dirty; otherwise `false`.
107
+ */
108
+ updateDirtyFlag(r, u) {
109
+ return o(r.deps) ? (r.flags = u | 32, !0) : (r.flags = u & -65, !1);
110
+ },
111
+ /**
112
+ * Updates the computed subscriber if necessary before its value is accessed.
113
+ *
114
+ * If the subscriber is marked Dirty or PendingComputed, this function runs
115
+ * the provided updateComputed logic and triggers a shallowPropagate for any
116
+ * downstream subscribers if an actual update occurs.
117
+ *
118
+ * @param computed - The computed subscriber to update.
119
+ * @param flags - The current flag set for this subscriber.
120
+ */
121
+ processComputedUpdate(r, u) {
122
+ if ((u & 32 || (o(r.deps) || (r.flags = u & -65, !1))) && t(r)) {
123
+ const c = r.subs;
124
+ c !== void 0 && f(c);
125
+ }
126
+ },
127
+ /**
128
+ * Ensures all pending internal effects for the given subscriber are processed.
129
+ *
130
+ * This should be called after an effect decides not to re-run itself but may still
131
+ * have dependencies flagged with PendingEffect. If the subscriber is flagged with
132
+ * PendingEffect, this function clears that flag and invokes `notifyEffect` on any
133
+ * related dependencies marked as Effect and Propagated, processing pending effects.
134
+ *
135
+ * @param sub - The subscriber which may have pending effects.
136
+ * @param flags - The current flags on the subscriber to check.
137
+ */
138
+ processPendingInnerEffects(r, u) {
139
+ if (u & 128) {
140
+ r.flags = u & -129;
141
+ let c = r.deps;
142
+ do {
143
+ const h = c.dep;
144
+ "flags" in h && h.flags & 2 && h.flags & 224 && e(h), c = c.nextDep;
145
+ } while (c !== void 0);
146
+ }
147
+ },
148
+ /**
149
+ * Processes queued effect notifications after a batch operation finishes.
150
+ *
151
+ * Iterates through all queued effects, calling notifyEffect on each.
152
+ * If an effect remains partially handled, its flags are updated, and future
153
+ * notifications may be triggered until fully handled.
154
+ */
155
+ processEffectNotifications() {
156
+ for (; s !== void 0; ) {
157
+ const r = s, u = r.depsTail, c = u.nextDep;
158
+ c !== void 0 ? (u.nextDep = void 0, s = c.sub) : (s = void 0, n = void 0), e(r) || (r.flags &= -9);
159
+ }
160
+ }
161
+ };
162
+ function i(r, u, c, h) {
163
+ const d = {
164
+ dep: r,
165
+ sub: u,
166
+ nextDep: c,
167
+ prevSub: void 0,
168
+ nextSub: void 0
169
+ };
170
+ if (h === void 0 ? u.deps = d : h.nextDep = d, r.subs === void 0)
171
+ r.subs = d;
172
+ else {
173
+ const p = r.subsTail;
174
+ d.prevSub = p, p.nextSub = d;
175
+ }
176
+ return u.depsTail = d, r.subsTail = d, d;
177
+ }
178
+ function o(r) {
179
+ let u = 0, c;
180
+ e: do {
181
+ c = !1;
182
+ const h = r.dep;
183
+ if ("flags" in h) {
184
+ const d = h.flags;
185
+ if ((d & 33) === 33) {
186
+ if (t(h)) {
187
+ const p = h.subs;
188
+ p.nextSub !== void 0 && f(p), c = !0;
189
+ }
190
+ } else if ((d & 65) === 65) {
191
+ const p = h.subs;
192
+ p.nextSub !== void 0 && (p.prevSub = r), r = h.deps, ++u;
193
+ continue;
194
+ }
195
+ }
196
+ if (!c && r.nextDep !== void 0) {
197
+ r = r.nextDep;
198
+ continue;
199
+ }
200
+ if (u) {
201
+ let d = r.sub;
202
+ do {
203
+ --u;
204
+ const p = d.subs;
205
+ if (c) {
206
+ if (t(d)) {
207
+ (r = p.prevSub) !== void 0 ? (p.prevSub = void 0, f(d.subs), d = r.sub) : d = p.sub;
208
+ continue;
209
+ }
210
+ } else
211
+ d.flags &= -65;
212
+ if ((r = p.prevSub) !== void 0) {
213
+ if (p.prevSub = void 0, r.nextDep !== void 0) {
214
+ r = r.nextDep;
215
+ continue e;
216
+ }
217
+ d = r.sub;
218
+ } else {
219
+ if ((r = p.nextDep) !== void 0)
220
+ continue e;
221
+ d = p.sub;
222
+ }
223
+ c = !1;
224
+ } while (u);
225
+ }
226
+ return c;
227
+ } while (!0);
228
+ }
229
+ function f(r) {
230
+ do {
231
+ const u = r.sub, c = u.flags;
232
+ (c & 96) === 64 && (u.flags = c | 32 | 8, (c & 10) === 2 && (n !== void 0 ? n.depsTail.nextDep = u.deps : s = u, n = u)), r = r.nextSub;
233
+ } while (r !== void 0);
234
+ }
235
+ function a(r, u) {
236
+ const c = u.depsTail;
237
+ if (c !== void 0) {
238
+ let h = u.deps;
239
+ do {
240
+ if (h === r)
241
+ return !0;
242
+ if (h === c)
243
+ break;
244
+ h = h.nextDep;
245
+ } while (h !== void 0);
246
+ }
247
+ return !1;
248
+ }
249
+ function m(r) {
250
+ do {
251
+ const u = r.dep, c = r.nextDep, h = r.nextSub, d = r.prevSub;
252
+ if (h !== void 0 ? h.prevSub = d : u.subsTail = d, d !== void 0 ? d.nextSub = h : u.subs = h, u.subs === void 0 && "deps" in u) {
253
+ const p = u.flags;
254
+ p & 32 || (u.flags = p | 32);
255
+ const x = u.deps;
256
+ if (x !== void 0) {
257
+ r = x, u.depsTail.nextDep = c, u.deps = void 0, u.depsTail = void 0;
258
+ continue;
259
+ }
260
+ }
261
+ r = c;
262
+ } while (r !== void 0);
263
+ }
264
+ }
265
+ var {
266
+ link: ct,
267
+ propagate: ft,
268
+ updateDirtyFlag: je,
269
+ startTracking: we,
270
+ endTracking: be,
271
+ processEffectNotifications: lt,
272
+ processComputedUpdate: at,
273
+ processPendingInnerEffects: Ne
274
+ } = ve({
275
+ updateComputed(t) {
276
+ we(t);
277
+ try {
278
+ const e = t.currentValue, s = t.getter(e);
279
+ return e !== s ? (t.currentValue = s, !0) : !1;
280
+ } finally {
281
+ be(t);
282
+ }
283
+ },
284
+ notifyEffect(t) {
285
+ return "isScope" in t ? _e(t) : qe(t);
286
+ }
287
+ });
288
+ function Ve(t) {
289
+ we(t);
290
+ try {
291
+ t.fn();
292
+ } finally {
293
+ be(t);
294
+ }
295
+ }
296
+ function qe(t) {
297
+ const e = t.flags;
298
+ return e & 32 || e & 64 && je(t, e) ? Ve(t) : Ne(t, t.flags), !0;
299
+ }
300
+ function _e(t) {
301
+ return t.flags & 128 ? (Ne(t, t.flags), !0) : !1;
302
+ }
303
+ function D(t) {
304
+ const e = typeof t;
305
+ switch (e) {
306
+ case "undefined":
307
+ return e;
308
+ case "number":
309
+ return isNaN(t) ? "NaN" : e;
310
+ case "function":
311
+ return /^\s*class\s+/.test(t.toString()) ? "class" : e;
312
+ case "object":
313
+ return t === null ? "null" : t instanceof Promise ? "promise" : t instanceof Map ? "map" : t instanceof Set ? "set" : Array.isArray(t) ? "array" : e;
314
+ default:
315
+ return e;
316
+ }
317
+ }
318
+ function q(t) {
319
+ return Array.isArray(t);
320
+ }
321
+ function X(t, e) {
322
+ return q(e) && e.every((s) => t(s));
323
+ }
324
+ function dt(t, e, s) {
325
+ if (X(t, e))
326
+ return !0;
327
+ throw new TypeError(F(e, s));
328
+ }
329
+ function O(t) {
330
+ return typeof t == "string";
331
+ }
332
+ function ht(t, e) {
333
+ if (O(t))
334
+ return !0;
335
+ throw new TypeError(F(t, e ?? "Expected a string. Got type: %t, value: %v"));
336
+ }
337
+ function E(t) {
338
+ return D(t) === "function";
339
+ }
340
+ function Ue(t) {
341
+ return typeof t == "number" && !isNaN(t);
342
+ }
343
+ function pt(...t) {
344
+ const e = t[0], s = O(t[2]) ? t[2] : `Expected instance of ${e.name}. Got type: %t, value: %v`, n = (i) => {
345
+ if (i instanceof e)
346
+ return !0;
347
+ throw new TypeError(F(i, s));
348
+ };
349
+ return t.length < 2 ? n : n(t[1]);
350
+ }
351
+ function J(t) {
352
+ return t != null && typeof t == "object" && !q(t);
353
+ }
354
+ function mt(t, e) {
355
+ if (J(t))
356
+ return !0;
357
+ throw new TypeError(F(t, e));
358
+ }
359
+ function F(t, e) {
360
+ var i;
361
+ const s = D(t), n = ((i = t == null ? void 0 : t.toString) == null ? void 0 : i.call(t)) || String(t);
362
+ return e.replaceAll("%t", s).replaceAll("%v", n);
363
+ }
364
+ let T, P = [];
365
+ const {
366
+ link: Q,
367
+ propagate: ze,
368
+ updateDirtyFlag: Re,
369
+ startTracking: Y,
370
+ endTracking: ee,
371
+ processEffectNotifications: Be,
372
+ processComputedUpdate: Fe,
373
+ processPendingInnerEffects: Ge
374
+ } = ve({
375
+ updateComputed(t) {
376
+ const e = g;
377
+ g = t, P.length = 0, Y(t);
378
+ try {
379
+ const s = t.currentValue, n = t.getter(s);
380
+ return t.equals(s, n) ? !1 : (t.currentValue = n, !0);
381
+ } finally {
382
+ g = e, T !== void 0 && (T(P), T = void 0), ee(t);
383
+ }
384
+ },
385
+ notifyEffect(t) {
386
+ const e = t.flags;
387
+ return e & M.Dirty || e & M.PendingComputed && Re(t, e) ? xe(t) : Ge(t, t.flags), !0;
388
+ }
389
+ });
390
+ let g;
391
+ const L = [];
392
+ let W = !1;
393
+ function We() {
394
+ W || (W = !0, queueMicrotask(() => {
395
+ W = !1;
396
+ for (let t = 0; t < L.length; t++) {
397
+ const e = L[t], s = g;
398
+ g = e, P.length = 0, Y(e);
399
+ try {
400
+ e.fn();
401
+ } finally {
402
+ g = s, ee(e), T !== void 0 && (T(P), T = void 0);
403
+ }
404
+ }
405
+ L.length = 0;
406
+ }));
407
+ }
408
+ function xe(t) {
409
+ L.push(t), We();
410
+ }
411
+ function Ze() {
412
+ Y(this), ee(this), queueMicrotask(() => {
413
+ L.splice(L.indexOf(this), 1);
414
+ });
415
+ }
416
+ const Me = [];
417
+ function te() {
418
+ Me.push(g), g = void 0;
419
+ }
420
+ function se() {
421
+ g = Me.pop();
422
+ }
423
+ var b, j;
424
+ class Ee {
425
+ constructor(e, s) {
426
+ C(this, b);
427
+ C(this, j);
428
+ l(this, "name");
429
+ $(this, b, {
430
+ currentValue: e,
431
+ subs: void 0,
432
+ subsTail: void 0
433
+ }), $(this, j, (s == null ? void 0 : s.equals) ?? Object.is), s != null && s.name && (this.name = s.name);
434
+ }
435
+ /**
436
+ * Returns the latest value. The signal is tracked as a dependency if called within `effect` or `compose`.
437
+ */
438
+ get() {
439
+ return g !== void 0 && (Q(w(this, b), g), P.push(this)), w(this, b).currentValue;
440
+ }
441
+ /**
442
+ * Returns the latest value. The signal is NOT tracked if called within `effect` or `compose`.
443
+ */
444
+ peek() {
445
+ return w(this, b).currentValue;
446
+ }
447
+ /**
448
+ * Replaces the current value with `next`.
449
+ *
450
+ * @example
451
+ * const count = atom(0);
452
+ * count.set(2);
453
+ * count.set(count.get() + 1);
454
+ */
455
+ set(e) {
456
+ if (!w(this, j).call(this, w(this, b).currentValue, e)) {
457
+ w(this, b).currentValue = e;
458
+ const s = w(this, b).subs;
459
+ s !== void 0 && (ze(s), Be());
460
+ }
461
+ }
462
+ /**
463
+ * Passes the current value to `fn` and sets the return value as the next value.
464
+ *
465
+ * @example
466
+ * const count = atom(0);
467
+ * count.update((current) => current + 1);
468
+ * count.update((current) => current * 5);
469
+ *
470
+ * // Also works very well with Immer `produce` for complex objects.
471
+ * const items = atom([{ name: "Alice", age: 26 }, { name: "Bob", age: 33 }]);
472
+ *
473
+ * // Without Immer:
474
+ * items.update((current) => {
475
+ * // Return a new array with Bob's age increased by 1.
476
+ * const newItems = [...current];
477
+ * newItems[1] = {
478
+ * ...newItems[1],
479
+ * age: newItems[1].age + 1
480
+ * };
481
+ * return newItems;
482
+ * });
483
+ *
484
+ * // With Immer:
485
+ * import { produce } from "immer";
486
+ *
487
+ * items.update(produce((draft) => {
488
+ * // Mutate draft to increase Bob's age by 1.
489
+ * // Results in a new object with this patch applied.
490
+ * draft[1].age++;
491
+ * }));
492
+ */
493
+ update(e) {
494
+ this.set(e(this.peek()));
495
+ }
496
+ /**
497
+ * @deprecated use `get()`
498
+ */
499
+ get value() {
500
+ return this.peek();
501
+ }
502
+ /**
503
+ * @deprecated use `set()`
504
+ */
505
+ set value(e) {
506
+ this.set(e);
507
+ }
508
+ }
509
+ b = new WeakMap(), j = new WeakMap();
510
+ var A, V, B, Se;
511
+ class ke {
512
+ constructor(e, s) {
513
+ C(this, B);
514
+ C(this, A);
515
+ C(this, V);
516
+ l(this, "name");
517
+ $(this, V, e), $(this, A, {
518
+ currentValue: void 0,
519
+ equals: (s == null ? void 0 : s.equals) ?? Object.is,
520
+ subs: void 0,
521
+ subsTail: void 0,
522
+ deps: void 0,
523
+ depsTail: void 0,
524
+ flags: M.Computed | M.Dirty,
525
+ getter: ce(this, B, Se).bind(this)
526
+ }), s != null && s.name && (this.name = s.name);
527
+ }
528
+ get() {
529
+ return g !== void 0 && (Q(w(this, A), g), P.push(this)), this.peek();
530
+ }
531
+ peek() {
532
+ const e = w(this, A), s = e.flags;
533
+ return s & (M.Dirty | M.PendingComputed) && Fe(e, s), e.currentValue;
534
+ }
535
+ /**
536
+ * @deprecated use `get()`
537
+ */
538
+ get value() {
539
+ return this.peek();
540
+ }
541
+ }
542
+ A = new WeakMap(), V = new WeakMap(), B = new WeakSet(), Se = function(e) {
543
+ let s = w(this, V).call(this, e);
544
+ return y(s) && (s = s.get()), s;
545
+ };
546
+ function y(t) {
547
+ return t instanceof Ee || t instanceof ke;
548
+ }
549
+ function K(t, e) {
550
+ return new Ee(t, e);
551
+ }
552
+ function ne(t, e) {
553
+ return new ke(t, e);
554
+ }
555
+ function He(t, e) {
556
+ if (E(e))
557
+ t.update(e);
558
+ else if (arguments.length > 1)
559
+ t.set(e);
560
+ else
561
+ return (s) => He(t, s);
562
+ }
563
+ function I(t) {
564
+ return y(t) ? t.get() : t;
565
+ }
566
+ function gt(t) {
567
+ return y(t) ? t.peek() : t;
568
+ }
569
+ function yt(t) {
570
+ T = t;
571
+ }
572
+ function v(t) {
573
+ const e = {
574
+ fn: t,
575
+ subs: void 0,
576
+ subsTail: void 0,
577
+ deps: void 0,
578
+ depsTail: void 0,
579
+ flags: M.Effect
580
+ };
581
+ return g !== void 0 && Q(e, g), xe(e), Ze.bind(e);
582
+ }
583
+ const vt = () => {
584
+ };
585
+ let Z = 1;
586
+ function Te() {
587
+ return Z = Z % Number.MAX_SAFE_INTEGER + 1, Z.toString(36) + Date.now().toString(36);
588
+ }
589
+ function wt(t, e) {
590
+ return Object.is(t, e);
591
+ }
592
+ function bt(t, e) {
593
+ if (Object.is(t, e)) return !0;
594
+ const s = D(t);
595
+ if (s !== D(e))
596
+ return !1;
597
+ switch (s) {
598
+ case "object":
599
+ let n = 0;
600
+ for (const i in t) {
601
+ if (t[i] !== e[i]) return !1;
602
+ n++;
603
+ }
604
+ return Object.keys(e).length === n;
605
+ case "array":
606
+ if (t.length !== e.length) return !1;
607
+ for (let i = 0; i < t.length; i++)
608
+ if (t[i] !== e[i]) return !1;
609
+ return !0;
610
+ case "map":
611
+ if (t.size !== e.size) return !1;
612
+ for (const i of t.keys())
613
+ if (t[i] !== e[i]) return !1;
614
+ return !0;
615
+ case "set":
616
+ if (E(t.symmetricDifference))
617
+ return t.symmetricDifference(e).size === 0;
618
+ for (const i of t.keys())
619
+ if (t[i] !== e.get(i)) return !1;
620
+ return !0;
621
+ }
622
+ return !1;
623
+ }
624
+ function H(t, e) {
625
+ if (t === e) return !0;
626
+ if (t && e && typeof t == "object" && typeof e == "object") {
627
+ if (t.constructor !== e.constructor) return !1;
628
+ var s, n, i;
629
+ if (Array.isArray(t)) {
630
+ if (s = t.length, s != e.length) return !1;
631
+ for (n = s; n-- !== 0; ) if (!H(t[n], e[n])) return !1;
632
+ return !0;
633
+ }
634
+ if (t instanceof Map && e instanceof Map) {
635
+ if (t.size !== e.size) return !1;
636
+ for (n of t.entries()) if (!e.has(n[0])) return !1;
637
+ for (n of t.entries()) if (!H(n[1], e.get(n[0]))) return !1;
638
+ return !0;
639
+ }
640
+ if (t instanceof Set && e instanceof Set) {
641
+ if (t.size !== e.size) return !1;
642
+ for (n of t.entries()) if (!e.has(n[0])) return !1;
643
+ return !0;
644
+ }
645
+ if (ArrayBuffer.isView(t) && ArrayBuffer.isView(e)) {
646
+ if (s = t.length, s != e.length) return !1;
647
+ for (n = s; n-- !== 0; ) if (t[n] !== e[n]) return !1;
648
+ return !0;
649
+ }
650
+ if (t.constructor === RegExp) return t.source === e.source && t.flags === e.flags;
651
+ if (t.valueOf !== Object.prototype.valueOf) return t.valueOf() === e.valueOf();
652
+ if (t.toString !== Object.prototype.toString) return t.toString() === e.toString();
653
+ if (i = Object.keys(t), s = i.length, s !== Object.keys(e).length) return !1;
654
+ for (n = s; n-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(e, i[n])) return !1;
655
+ for (n = s; n-- !== 0; ) {
656
+ var o = i[n];
657
+ if (!H(t[o], e[o])) return !1;
658
+ }
659
+ return !0;
660
+ }
661
+ return t !== t && e !== e;
662
+ }
663
+ function Ke(t, e) {
664
+ const s = {};
665
+ for (const n in e)
666
+ t.includes(n) || (s[n] = e[n]);
667
+ return s;
668
+ }
669
+ function Nt(t) {
670
+ let e = 0;
671
+ for (let s = 0; s < t.length; s++)
672
+ e = (e + t.charCodeAt(s) * 10) % 360;
673
+ return `oklch(0.68 0.15 ${e}deg)`;
674
+ }
675
+ function xt(t) {
676
+ if (t instanceof RegExp)
677
+ return (n) => t.test(n);
678
+ const e = {
679
+ positive: [],
680
+ negative: []
681
+ }, s = t.split(",").map((n) => n.trim()).filter((n) => n !== "");
682
+ for (let n of s) {
683
+ let i = "positive";
684
+ n.startsWith("-") && (i = "negative", n = n.slice(1)), n === "*" ? e[i].push(function() {
685
+ return !0;
686
+ }) : n.endsWith("*") ? e[i].push(function(o) {
687
+ return o.startsWith(n.slice(0, n.length - 1));
688
+ }) : e[i].push(function(o) {
689
+ return o === n;
690
+ });
691
+ }
692
+ return function(n) {
693
+ const { positive: i, negative: o } = e;
694
+ return !(o.some((f) => f(n)) || i.length > 0 && !i.some((f) => f(n)));
695
+ };
696
+ }
697
+ const k = Symbol.for("DollaMarkupElement"), Mt = Symbol.for("DollaRouter");
698
+ function Et(t, e) {
699
+ return e.outlet();
700
+ }
701
+ function Xe(t) {
702
+ for (var e, s, n = arguments, i = 1, o = "", f = "", a = [0], m = function(c) {
703
+ i === 1 && (c || (o = o.replace(/^\s*\n\s*|\s*\n\s*$/g, ""))) ? a.push(c ? n[c] : o) : i === 3 && (c || o) ? (a[1] = c ? n[c] : o, i = 2) : i === 2 && o === "..." && c ? a[2] = Object.assign(a[2] || {}, n[c]) : i === 2 && o && !c ? (a[2] = a[2] || {})[o] = !0 : i >= 5 && (i === 5 ? ((a[2] = a[2] || {})[s] = c ? o ? o + n[c] : n[c] : o, i = 6) : (c || o) && (a[2][s] += c ? o + n[c] : o)), o = "";
704
+ }, r = 0; r < t.length; r++) {
705
+ r && (i === 1 && m(), m(r));
706
+ for (var u = 0; u < t[r].length; u++) e = t[r][u], i === 1 ? e === "<" ? (m(), a = [a, "", null], i = 3) : o += e : i === 4 ? o === "--" && e === ">" ? (i = 1, o = "") : o = e + o[0] : f ? e === f ? f = "" : o += e : e === '"' || e === "'" ? f = e : e === ">" ? (m(), i = 1) : i && (e === "=" ? (i = 5, s = o, o = "") : e === "/" && (i < 5 || t[r][u + 1] === ">") ? (m(), i === 3 && (a = a[0]), i = a, (a = a[0]).push(this.apply(null, i.slice(1))), i = 0) : e === " " || e === " " || e === `
707
+ ` || e === "\r" ? (m(), i = 2) : o += e), i === 3 && o === "!--" && (i = 4, a = a[0]);
708
+ }
709
+ return m(), a.length > 2 ? a.slice(1) : a[1];
710
+ }
711
+ var ae;
712
+ ae = k;
713
+ class fe {
714
+ constructor(e) {
715
+ l(this, ae, !0);
716
+ l(this, "domNode");
717
+ this.domNode = e;
718
+ }
719
+ get isMounted() {
720
+ return this.domNode.parentNode != null;
721
+ }
722
+ mount(e, s) {
723
+ e.insertBefore(this.domNode, (s == null ? void 0 : s.nextSibling) ?? null);
724
+ }
725
+ unmount(e = !1) {
726
+ this.domNode.parentNode && !e && this.domNode.parentNode.removeChild(this.domNode);
727
+ }
728
+ }
729
+ var de;
730
+ de = k;
731
+ class Je {
732
+ constructor(e) {
733
+ l(this, de, !0);
734
+ l(this, "domNode", document.createTextNode(""));
735
+ l(this, "children", []);
736
+ l(this, "elementContext");
737
+ l(this, "source");
738
+ l(this, "unsubscribe");
739
+ this.source = e.source, this.elementContext = e.elementContext;
740
+ }
741
+ get isMounted() {
742
+ return this.domNode.parentNode != null;
743
+ }
744
+ mount(e, s) {
745
+ this.isMounted || (e.insertBefore(this.domNode, (s == null ? void 0 : s.nextSibling) ?? null), this.unsubscribe = v(() => {
746
+ const n = this.source.get();
747
+ if (!Oe(n))
748
+ throw console.error(n), new TypeError(
749
+ `Dynamic received invalid value to render. Got type: ${D(n)}, value: ${n}`
750
+ );
751
+ te(), this.update(q(n) ? n : [n]), se();
752
+ }));
753
+ }
754
+ unmount(e = !1) {
755
+ var s, n;
756
+ (s = this.unsubscribe) == null || s.call(this), this.isMounted && (this.cleanup(e), (n = this.domNode.parentNode) == null || n.removeChild(this.domNode));
757
+ }
758
+ cleanup(e) {
759
+ for (const s of this.children)
760
+ s.unmount(e);
761
+ this.children = [];
762
+ }
763
+ update(e) {
764
+ var o, f, a;
765
+ if (this.cleanup(!1), e == null || e.length === 0 || !this.isMounted)
766
+ return;
767
+ const s = e.flatMap((m) => De(m) ? m : S(this.elementContext, ie(m)));
768
+ for (const m of s) {
769
+ const r = ((o = this.children.at(-1)) == null ? void 0 : o.domNode) || this.domNode;
770
+ m.mount(this.domNode.parentNode, r), this.children.push(m);
771
+ }
772
+ const n = this.domNode.parentNode, i = ((a = (f = this.children.at(-1)) == null ? void 0 : f.domNode) == null ? void 0 : a.nextSibling) ?? null;
773
+ n.insertBefore(this.domNode, i);
774
+ }
775
+ }
776
+ const Qe = (t) => /^on[A-Z]/.test(t);
777
+ var he;
778
+ he = k;
779
+ class Ye {
780
+ constructor({ tag: e, props: s, children: n, elementContext: i }) {
781
+ l(this, he, !0);
782
+ l(this, "domNode");
783
+ l(this, "props");
784
+ l(this, "childMarkup", []);
785
+ l(this, "children", []);
786
+ l(this, "unsubscribers", []);
787
+ l(this, "elementContext");
788
+ // Track the ref so we can nullify it on unmount.
789
+ l(this, "ref");
790
+ // Prevents 'onClickOutside' handlers from firing in the same cycle in which the element is connected.
791
+ l(this, "canClickAway", !1);
792
+ if (e.toLowerCase() === "svg" && (i = {
793
+ ...i,
794
+ isSVG: !0
795
+ }), i.isSVG ? this.domNode = document.createElementNS("http://www.w3.org/2000/svg", e) : this.domNode = document.createElement(e), i.root.getEnv() === "development" && i.viewName && (this.domNode.dataset.view = i.viewName), s.ref)
796
+ if (E(s.ref))
797
+ this.ref = s.ref, this.ref(this.domNode);
798
+ else
799
+ throw new Error("Expected ref to be a function. Got: " + s.ref);
800
+ this.props = {
801
+ ...Ke(["ref", "class", "className"], s),
802
+ class: s.className ?? s.class
803
+ }, n && (this.childMarkup = n), this.elementContext = i;
804
+ }
805
+ get isMounted() {
806
+ return this.domNode.parentNode != null;
807
+ }
808
+ mount(e, s) {
809
+ if (e == null)
810
+ throw new Error(`HTML element requires a parent element as the first argument to connect. Got: ${e}`);
811
+ if (!this.isMounted) {
812
+ this.childMarkup.length > 0 && (this.children = S(this.elementContext, this.childMarkup));
813
+ for (let n = 0; n < this.children.length; n++) {
814
+ const i = this.children[n], o = n > 0 ? this.children[n - 1].domNode : void 0;
815
+ i.mount(this.domNode, o);
816
+ }
817
+ this.applyProps(this.domNode, this.props), this.props.style && this.applyStyles(this.domNode, this.props.style, this.unsubscribers), this.props.class && this.applyClasses(this.domNode, this.props.class, this.unsubscribers);
818
+ }
819
+ e.insertBefore(this.domNode, (s == null ? void 0 : s.nextSibling) ?? null), setTimeout(() => {
820
+ this.canClickAway = !0;
821
+ }, 0);
822
+ }
823
+ unmount(e = !1) {
824
+ var s;
825
+ if (this.isMounted) {
826
+ e || (s = this.domNode.parentNode) == null || s.removeChild(this.domNode);
827
+ for (const n of this.children)
828
+ n.unmount(!0);
829
+ this.ref && this.ref(void 0), this.canClickAway = !1;
830
+ for (const n of this.unsubscribers)
831
+ n();
832
+ this.unsubscribers.length = 0;
833
+ }
834
+ }
835
+ attachProp(e, s) {
836
+ y(e) ? this.unsubscribers.push(v(() => s(e.get()))) : s(e);
837
+ }
838
+ applyProps(e, s) {
839
+ for (const n in s) {
840
+ const i = s[n];
841
+ if (n === "attributes") {
842
+ const o = i;
843
+ for (const f in o)
844
+ this.attachProp(o[f], (a) => {
845
+ a == null ? e.removeAttribute(f) : e.setAttribute(f, String(a));
846
+ });
847
+ } else if (n === "onClickOutside" || n === "onclickoutside") {
848
+ const o = (a) => {
849
+ this.canClickAway && !e.contains(a.target) && (y(i) ? i.peek()(a) : i(a));
850
+ }, f = { capture: !0 };
851
+ window.addEventListener("click", o, f), this.unsubscribers.push(() => {
852
+ window.removeEventListener("click", o, f);
853
+ });
854
+ } else if (Qe(n)) {
855
+ const o = n.slice(2).toLowerCase(), f = y(i) ? (a) => i.peek()(a) : i;
856
+ e.addEventListener(o, f), this.unsubscribers.push(() => {
857
+ e.removeEventListener(o, f);
858
+ });
859
+ } else if (n.includes("-"))
860
+ this.attachProp(i, (o) => {
861
+ o == null ? e.removeAttribute(n) : e.setAttribute(n, String(o));
862
+ });
863
+ else if (!et.includes(n))
864
+ if (this.elementContext.isSVG)
865
+ this.attachProp(i, (o) => {
866
+ o != null ? e.setAttribute(n, String(s[n])) : e.removeAttribute(n);
867
+ });
868
+ else
869
+ switch (n) {
870
+ case "contentEditable":
871
+ case "value":
872
+ this.attachProp(i, (o) => {
873
+ e[n] = String(o);
874
+ });
875
+ break;
876
+ case "for":
877
+ this.attachProp(i, (o) => {
878
+ e.htmlFor = o;
879
+ });
880
+ break;
881
+ case "checked":
882
+ this.attachProp(i, (o) => {
883
+ e.checked = o, o ? e.setAttribute("checked", "") : e.removeAttribute("checked");
884
+ });
885
+ break;
886
+ // Attribute-aliased props
887
+ case "exportParts":
888
+ case "part":
889
+ case "translate":
890
+ case "type":
891
+ case "title": {
892
+ const o = n.toLowerCase();
893
+ this.attachProp(i, (f) => {
894
+ f == null ? e.removeAttribute(o) : e.setAttribute(o, String(f));
895
+ });
896
+ break;
897
+ }
898
+ case "autocomplete":
899
+ case "autocapitalize":
900
+ this.attachProp(i, (o) => {
901
+ typeof o == "string" ? e.autocomplete = o : o ? e.autocomplete = "on" : e.autocomplete = "off";
902
+ });
903
+ break;
904
+ default: {
905
+ this.attachProp(i, (o) => {
906
+ e[n] = o;
907
+ });
908
+ break;
909
+ }
910
+ }
911
+ }
912
+ }
913
+ applyStyles(e, s, n) {
914
+ const i = [];
915
+ if (y(s)) {
916
+ let o;
917
+ const f = v(() => {
918
+ E(o) && o(), e.style.cssText = "", o = this.applyStyles(e, I(s), n);
919
+ });
920
+ n.push(f), i.push(f);
921
+ } else {
922
+ const o = Le(s);
923
+ for (const f in o) {
924
+ const { value: a, priority: m } = o[f];
925
+ if (y(a)) {
926
+ const r = v(() => {
927
+ a.get() ? e.style.setProperty(f, String(a.get()), m) : e.style.removeProperty(f);
928
+ });
929
+ n.push(r), i.push(r);
930
+ } else a != null && e.style.setProperty(f, String(a));
931
+ }
932
+ }
933
+ return function() {
934
+ for (const f of i)
935
+ f(), n.splice(n.indexOf(f), 1);
936
+ };
937
+ }
938
+ applyClasses(e, s, n) {
939
+ const i = [];
940
+ if (y(s)) {
941
+ let o;
942
+ const f = v(() => {
943
+ E(o) && o(), e.removeAttribute("class"), o = this.applyClasses(e, I(s), n);
944
+ });
945
+ n.push(f), i.push(f);
946
+ } else {
947
+ const o = Ce(s);
948
+ for (const f in o) {
949
+ const a = o[f];
950
+ if (y(a)) {
951
+ const m = v(() => {
952
+ I(a) ? e.classList.add(f) : e.classList.remove(f);
953
+ });
954
+ n.push(m), i.push(m);
955
+ } else a && e.classList.add(f);
956
+ }
957
+ }
958
+ return function() {
959
+ for (const f of i)
960
+ f(), n.splice(n.indexOf(f), 1);
961
+ };
962
+ }
963
+ }
964
+ function Ce(t) {
965
+ let e = {};
966
+ if (O(t)) {
967
+ const s = t.split(" ");
968
+ for (const n of s)
969
+ e[n] = !0;
970
+ } else J(t) ? Object.assign(e, t) : Array.isArray(t) && Array.from(t).filter(Boolean).forEach((s) => {
971
+ Object.assign(e, Ce(s));
972
+ });
973
+ return delete e.undefined, e;
974
+ }
975
+ function Le(t) {
976
+ let e = {};
977
+ if (O(t)) {
978
+ const s = t.split(";").filter((n) => n.trim() !== "");
979
+ for (const n of s) {
980
+ const [i, o] = n.split(":"), f = {
981
+ value: o
982
+ };
983
+ o.includes("!important") ? (f.priority = "important", f.value = o.replace("!important", "").trim()) : f.value = o.trim(), e[le(i.trim())] = f;
984
+ }
985
+ }
986
+ if (J(t))
987
+ for (const s in t)
988
+ s.startsWith("--") ? e[s] = { value: t[s] } : e[le(s)] = { value: t[s] };
989
+ else Array.isArray(t) && Array.from(t).filter((s) => s != null).forEach((s) => {
990
+ Object.assign(e, Le(s));
991
+ });
992
+ return e;
993
+ }
994
+ function le(t) {
995
+ return t.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (e, s) => (s ? "-" : "") + e.toLowerCase());
996
+ }
997
+ const et = ["ref", "children", "class", "style", "data"];
998
+ let tt = class {
999
+ constructor(e) {
1000
+ l(this, "store");
1001
+ this.store = e;
1002
+ const s = Object.getOwnPropertyDescriptors(this.store.logger);
1003
+ for (const n in s)
1004
+ n !== "setName" && Object.defineProperty(this, n, s[n]);
1005
+ }
1006
+ get isMounted() {
1007
+ return this.store.isMounted;
1008
+ }
1009
+ get name() {
1010
+ return this.store.name || this.store.id;
1011
+ }
1012
+ set name(e) {
1013
+ this.store.name = e, this.store.logger.setName(e);
1014
+ }
1015
+ get(e) {
1016
+ if (E(e)) {
1017
+ let s = this.store.elementContext, n;
1018
+ for (; n = s.stores.get(e), n == null && s.parent != null; )
1019
+ s = s.parent;
1020
+ if (n == null)
1021
+ throw new U(`Store '${e.name}' is not provided on this context.`);
1022
+ return n.value;
1023
+ } else
1024
+ throw new U("Invalid store.");
1025
+ }
1026
+ onMount(e) {
1027
+ this.store.lifecycleListeners.mount.push(e);
1028
+ }
1029
+ onUnmount(e) {
1030
+ this.store.lifecycleListeners.unmount.push(e);
1031
+ }
1032
+ effect(e) {
1033
+ const s = this.store;
1034
+ if (s.isMounted) {
1035
+ const n = v(e);
1036
+ return s.lifecycleListeners.unmount.push(n), n;
1037
+ } else {
1038
+ let n, i = !1;
1039
+ return s.lifecycleListeners.mount.push(() => {
1040
+ i || (n = v(e), s.lifecycleListeners.unmount.push(n));
1041
+ }), () => {
1042
+ n != null && (i = !0, n());
1043
+ };
1044
+ }
1045
+ }
1046
+ };
1047
+ class st {
1048
+ constructor(e, s) {
1049
+ l(this, "fn");
1050
+ l(this, "_options");
1051
+ /**
1052
+ * Value is guaranteed to be set after `attach` is called.
1053
+ */
1054
+ l(this, "value");
1055
+ l(this, "isMounted", !1);
1056
+ l(this, "elementContext");
1057
+ l(this, "lifecycleListeners", { mount: [], unmount: [] });
1058
+ l(this, "logger");
1059
+ l(this, "id", Te());
1060
+ l(this, "name");
1061
+ this.fn = e, this.name = e.name, this._options = s;
1062
+ }
1063
+ /**
1064
+ * Attaches this Store to the elementContext.
1065
+ * Returns false if there was already an instance attached, and true otherwise.
1066
+ */
1067
+ attach(e) {
1068
+ if (e.stores.has(this.fn))
1069
+ return !1;
1070
+ this.elementContext = e, this.logger = e.root.createLogger(this.name);
1071
+ const s = new tt(this);
1072
+ try {
1073
+ this.value = this.fn.call(s, this._options, s);
1074
+ } catch (n) {
1075
+ throw this.logger.crash(n), n;
1076
+ }
1077
+ return e.stores.set(this.fn, this), !0;
1078
+ }
1079
+ handleMount() {
1080
+ this.isMounted = !0;
1081
+ for (const e of this.lifecycleListeners.mount)
1082
+ e();
1083
+ this.lifecycleListeners.mount.length = 0;
1084
+ }
1085
+ handleUnmount() {
1086
+ this.isMounted = !1;
1087
+ for (const e of this.lifecycleListeners.unmount)
1088
+ e();
1089
+ this.lifecycleListeners.unmount.length = 0;
1090
+ }
1091
+ }
1092
+ class U extends Error {
1093
+ }
1094
+ class nt {
1095
+ constructor(e) {
1096
+ l(this, "view");
1097
+ this.view = e;
1098
+ const s = Object.getOwnPropertyDescriptors(this.view.logger);
1099
+ for (const n in s)
1100
+ n !== "setName" && Object.defineProperty(this, n, s[n]);
1101
+ }
1102
+ get uid() {
1103
+ return this.view.uniqueId;
1104
+ }
1105
+ get isMounted() {
1106
+ return this.view.isMounted;
1107
+ }
1108
+ get name() {
1109
+ return this.view.elementContext.viewName || this.uid;
1110
+ }
1111
+ set name(e) {
1112
+ this.view.elementContext.viewName = e, this.view.logger.setName(e);
1113
+ }
1114
+ provide(e, s) {
1115
+ const n = new st(e, s);
1116
+ if (n.attach(this.view.elementContext))
1117
+ return this.view.lifecycleListeners.mount.push(() => {
1118
+ n.handleMount();
1119
+ }), this.view.lifecycleListeners.unmount.push(() => {
1120
+ n.handleUnmount();
1121
+ }), n.value;
1122
+ {
1123
+ let o = e.name ? `'${e.name}'` : "this store";
1124
+ return this.view.logger.warn(`An instance of ${o} was already attached to this context.`), this.get(e);
1125
+ }
1126
+ }
1127
+ get(e) {
1128
+ if (E(e)) {
1129
+ let s = this.view.elementContext, n;
1130
+ for (; n = s.stores.get(e), n == null && s.parent != null; )
1131
+ s = s.parent;
1132
+ if (n == null)
1133
+ throw new U(`Store '${e.name}' is not provided on this context.`);
1134
+ return n.value;
1135
+ } else
1136
+ throw new U("Invalid store.");
1137
+ }
1138
+ beforeMount(e) {
1139
+ this.view.lifecycleListeners.beforeMount.push(e);
1140
+ }
1141
+ onMount(e) {
1142
+ this.view.lifecycleListeners.mount.push(e);
1143
+ }
1144
+ beforeUnmount(e) {
1145
+ this.view.lifecycleListeners.beforeUnmount.push(e);
1146
+ }
1147
+ onUnmount(e) {
1148
+ this.view.lifecycleListeners.unmount.push(e);
1149
+ }
1150
+ effect(e) {
1151
+ if (this.view.isMounted) {
1152
+ const s = v(e);
1153
+ return this.view.lifecycleListeners.unmount.push(s), s;
1154
+ } else {
1155
+ let s, n = !1;
1156
+ return this.view.lifecycleListeners.mount.push(() => {
1157
+ n || (s = v(e), this.view.lifecycleListeners.unmount.push(s));
1158
+ }), () => {
1159
+ s != null && (n = !0, s());
1160
+ };
1161
+ }
1162
+ }
1163
+ outlet() {
1164
+ return N("$outlet", { children: this.view.children });
1165
+ }
1166
+ }
1167
+ var pe;
1168
+ pe = k;
1169
+ const re = class re {
1170
+ constructor(e, s, n, i = []) {
1171
+ l(this, pe, !0);
1172
+ l(this, "uniqueId", Te());
1173
+ l(this, "elementContext");
1174
+ l(this, "logger");
1175
+ l(this, "props");
1176
+ l(this, "fn");
1177
+ l(this, "element");
1178
+ l(this, "childMarkup");
1179
+ l(this, "children", K([]));
1180
+ l(this, "lifecycleListeners", { beforeMount: [], mount: [], beforeUnmount: [], unmount: [] });
1181
+ l(this, "isMounted", !1);
1182
+ this.elementContext = {
1183
+ ...e,
1184
+ parent: e,
1185
+ viewName: s.name,
1186
+ stores: /* @__PURE__ */ new Map()
1187
+ }, this.logger = e.root.createLogger(s.name || "🌇 anonymous view", { uid: this.uniqueId }), this.props = n, this.fn = s, this.childMarkup = i;
1188
+ }
1189
+ /*===============================*\
1190
+ || "Public" API ||
1191
+ \*===============================*/
1192
+ get domNode() {
1193
+ var e;
1194
+ return (e = this.element) == null ? void 0 : e.domNode;
1195
+ }
1196
+ mount(e, s) {
1197
+ const n = this.isMounted;
1198
+ if (!n) {
1199
+ this._initialize();
1200
+ for (const i of this.lifecycleListeners.beforeMount)
1201
+ i();
1202
+ }
1203
+ this.element && this.element.mount(e, s), n || (this.isMounted = !0, requestAnimationFrame(() => {
1204
+ for (const i of this.lifecycleListeners.mount)
1205
+ i();
1206
+ }));
1207
+ }
1208
+ unmount(e = !1) {
1209
+ for (const s of this.lifecycleListeners.beforeUnmount)
1210
+ s();
1211
+ this.element && this.element.unmount(e), this.isMounted = !1;
1212
+ for (const s of this.lifecycleListeners.unmount)
1213
+ s();
1214
+ this.lifecycleListeners.beforeMount.length = 0, this.lifecycleListeners.mount.length = 0, this.lifecycleListeners.beforeUnmount.length = 0, this.lifecycleListeners.unmount.length = 0;
1215
+ }
1216
+ setChildView(e) {
1217
+ this.childMarkup = [];
1218
+ const s = new re(this.elementContext, e, {});
1219
+ return this.children.set([s]), s;
1220
+ }
1221
+ /*===============================*\
1222
+ || Internal ||
1223
+ \*===============================*/
1224
+ _initialize() {
1225
+ const e = new nt(this);
1226
+ let s;
1227
+ try {
1228
+ s = this.fn.call(e, this.props, e), this.childMarkup.length && this.children.set(S(this.elementContext, this.childMarkup));
1229
+ } catch (n) {
1230
+ throw n instanceof Error && this.logger.crash(n), n;
1231
+ }
1232
+ if (s !== null) if (s instanceof Node)
1233
+ this.element = _(S(this.elementContext, N("$node", { value: s })));
1234
+ else if (y(s))
1235
+ this.element = _(
1236
+ S(this.elementContext, N("$dynamic", { source: s }))
1237
+ );
1238
+ else if (R(s) || X(R, s))
1239
+ this.element = _(S(this.elementContext, s));
1240
+ else {
1241
+ const n = new TypeError(
1242
+ `Expected '${this.fn.name}' function to return a DOM node, Markup element, Readable or null. Got: ${D(s)}`
1243
+ );
1244
+ this.logger.crash(n);
1245
+ }
1246
+ }
1247
+ };
1248
+ let z = re;
1249
+ var me;
1250
+ me = k;
1251
+ class it {
1252
+ constructor({ elementContext: e, items: s, renderFn: n, keyFn: i }) {
1253
+ l(this, me, !0);
1254
+ l(this, "domNode", document.createTextNode(""));
1255
+ l(this, "items");
1256
+ l(this, "unsubscribe", null);
1257
+ l(this, "connectedItems", []);
1258
+ l(this, "elementContext");
1259
+ l(this, "renderFn");
1260
+ l(this, "keyFn");
1261
+ this.elementContext = e, this.items = s, this.renderFn = n, this.keyFn = i;
1262
+ }
1263
+ get isMounted() {
1264
+ return this.domNode.parentNode != null;
1265
+ }
1266
+ mount(e, s) {
1267
+ this.isMounted || (e.insertBefore(this.domNode, (s == null ? void 0 : s.nextSibling) ?? null), this.unsubscribe = v(() => {
1268
+ let n = this.items.get();
1269
+ n == null && (n = [], console.log("list received empty value", n, this)), requestAnimationFrame(() => {
1270
+ te(), this._update(Array.from(n)), se();
1271
+ });
1272
+ }));
1273
+ }
1274
+ unmount(e = !1) {
1275
+ var s;
1276
+ this.unsubscribe && (this.unsubscribe(), this.unsubscribe = null), !e && this.isMounted && ((s = this.domNode.parentNode) == null || s.removeChild(this.domNode)), this._cleanup(e);
1277
+ }
1278
+ _cleanup(e) {
1279
+ for (const s of this.connectedItems)
1280
+ s.element.unmount(e);
1281
+ this.connectedItems = [];
1282
+ }
1283
+ _update(e) {
1284
+ var f, a, m;
1285
+ if (e.length === 0 || !this.isMounted)
1286
+ return this._cleanup(!1);
1287
+ const s = [];
1288
+ let n = 0;
1289
+ for (const r of e)
1290
+ s.push({
1291
+ key: this.keyFn(r, n),
1292
+ value: r,
1293
+ index: n++
1294
+ });
1295
+ const i = [];
1296
+ for (const r of this.connectedItems)
1297
+ s.find((c) => c.key === r.key) || r.element.unmount(!1);
1298
+ for (const r of s) {
1299
+ const u = this.connectedItems.find((c) => c.key === r.key);
1300
+ if (u)
1301
+ u.item.set(r.value), u.index.set(r.index), i[r.index] = u;
1302
+ else {
1303
+ const c = K(r.value), h = K(r.index);
1304
+ i[r.index] = {
1305
+ key: r.key,
1306
+ item: c,
1307
+ index: h,
1308
+ element: new z(this.elementContext, rt, {
1309
+ item: ne(() => c.get()),
1310
+ index: h,
1311
+ renderFn: this.renderFn
1312
+ })
1313
+ };
1314
+ }
1315
+ }
1316
+ for (let r = 0; r < i.length; r++) {
1317
+ const u = i[r], c = ((f = i[r - 1]) == null ? void 0 : f.element.domNode) ?? this.domNode;
1318
+ u.element.mount(this.domNode.parentNode, c);
1319
+ }
1320
+ this.connectedItems = i;
1321
+ const o = ((a = i.at(-1)) == null ? void 0 : a.element.domNode) ?? this.domNode;
1322
+ (m = this.domNode.parentNode) == null || m.insertBefore(this.domNode, o.nextSibling);
1323
+ }
1324
+ }
1325
+ function rt(t, e) {
1326
+ return e.name = "@ListItem", t.renderFn.call(e, t.item, t.index, e);
1327
+ }
1328
+ var ge;
1329
+ ge = k;
1330
+ class Ae {
1331
+ constructor(e) {
1332
+ l(this, ge, !0);
1333
+ l(this, "domNode", document.createTextNode(""));
1334
+ l(this, "isMounted", !1);
1335
+ l(this, "source");
1336
+ l(this, "elements", []);
1337
+ l(this, "unsubscribe");
1338
+ this.source = e;
1339
+ }
1340
+ mount(e, s) {
1341
+ this.isMounted || (this.isMounted = !0, e.insertBefore(this.domNode, (s == null ? void 0 : s.nextSibling) ?? null), y(this.source) ? this.unsubscribe = v(() => {
1342
+ const n = I(this.source);
1343
+ te(), this.update(n), se();
1344
+ }) : this.update(this.elements));
1345
+ }
1346
+ unmount(e = !1) {
1347
+ this.unsubscribe && (this.unsubscribe(), this.unsubscribe = void 0), this.isMounted && (this.cleanup(e), this.isMounted = !1);
1348
+ }
1349
+ cleanup(e) {
1350
+ for (const s of this.elements)
1351
+ s.unmount(e);
1352
+ this.elements = [];
1353
+ }
1354
+ update(e) {
1355
+ var s, n;
1356
+ if (this.cleanup(!1), e.length > 0) {
1357
+ for (let i = 0; i < e.length; i++) {
1358
+ const o = e[i], f = i > 0 ? this.elements[i - 1] : void 0;
1359
+ o.mount(this.domNode.parentElement, f == null ? void 0 : f.domNode), this.elements.push(o);
1360
+ }
1361
+ (n = this.domNode.parentNode) == null || n.insertBefore(this.domNode, ((s = this.elements.at(-1)) == null ? void 0 : s.domNode) ?? null);
1362
+ }
1363
+ }
1364
+ }
1365
+ var ye;
1366
+ ye = k;
1367
+ class ot {
1368
+ constructor(e) {
1369
+ l(this, ye, !0);
1370
+ l(this, "config");
1371
+ l(this, "element");
1372
+ this.config = e;
1373
+ }
1374
+ get isMounted() {
1375
+ return this.element ? this.element.isMounted : !1;
1376
+ }
1377
+ mount(e, s) {
1378
+ const { content: n, parent: i } = this.config;
1379
+ De(n) ? this.element = n : this.element = _(S(this.config.elementContext, ie(n))), this.element.mount(i);
1380
+ }
1381
+ unmount(e = !1) {
1382
+ var s;
1383
+ (s = this.element) != null && s.isMounted && this.element.unmount(e);
1384
+ }
1385
+ }
1386
+ function R(t) {
1387
+ return t instanceof Pe;
1388
+ }
1389
+ function De(t) {
1390
+ return (t == null ? void 0 : t[k]) === !0;
1391
+ }
1392
+ function ie(t) {
1393
+ return q(t) || (t = [t]), t.flat(1 / 0).filter((e) => e != null && e !== !1).map((e) => R(e) ? e : e instanceof Node ? N("$node", { value: e }) : y(e) ? N("$dynamic", { source: e }) : N("$text", { value: e }));
1394
+ }
1395
+ function N(t, e, ...s) {
1396
+ return new Pe(t, e, ...s);
1397
+ }
1398
+ class Pe {
1399
+ constructor(e, s, ...n) {
1400
+ l(this, "type");
1401
+ l(this, "props");
1402
+ l(this, "children");
1403
+ this.type = e, this.props = s, this.children = ie(n);
1404
+ }
1405
+ }
1406
+ const St = Xe.bind(N);
1407
+ function Tt(t, e, s) {
1408
+ return N("$dynamic", {
1409
+ source: ne(() => {
1410
+ const n = I(t);
1411
+ return n && e ? e : !n && s ? s : null;
1412
+ })
1413
+ });
1414
+ }
1415
+ function Ct(t, e, s) {
1416
+ return N("$list", { items: ne(() => t), keyFn: e, renderFn: s });
1417
+ }
1418
+ function Lt(t, e) {
1419
+ return N("$portal", { parent: t, content: e });
1420
+ }
1421
+ function S(t, e) {
1422
+ return (q(e) ? e : [e]).map((n) => {
1423
+ if (E(n.type))
1424
+ return new z(t, n.type, n.props, n.children);
1425
+ if (O(n.type))
1426
+ switch (n.type) {
1427
+ case "$node": {
1428
+ const i = n.props;
1429
+ return new fe(i.value);
1430
+ }
1431
+ case "$text": {
1432
+ const i = n.props;
1433
+ return new fe(document.createTextNode(String(i.value)));
1434
+ }
1435
+ case "$list": {
1436
+ const i = n.props;
1437
+ return new it({
1438
+ items: i.items,
1439
+ keyFn: i.keyFn,
1440
+ renderFn: i.renderFn,
1441
+ elementContext: t
1442
+ });
1443
+ }
1444
+ case "$dynamic": {
1445
+ const i = n.props;
1446
+ return new Je({
1447
+ source: i.source,
1448
+ elementContext: t
1449
+ });
1450
+ }
1451
+ case "$outlet": {
1452
+ const i = n.props;
1453
+ return new Ae(i.children);
1454
+ }
1455
+ case "$portal": {
1456
+ const i = n.props;
1457
+ return new ot({
1458
+ content: i.content,
1459
+ parent: i.parent,
1460
+ elementContext: t
1461
+ });
1462
+ }
1463
+ default:
1464
+ if (n.type.startsWith("$"))
1465
+ throw new Error(`Unknown markup type: ${n.type}`);
1466
+ return new Ye({
1467
+ tag: n.type,
1468
+ props: n.props ?? {},
1469
+ children: n.children,
1470
+ elementContext: t
1471
+ });
1472
+ }
1473
+ else
1474
+ throw new TypeError(`Expected a string or view function. Got: ${n.type}`);
1475
+ });
1476
+ }
1477
+ function _(t) {
1478
+ return t.length === 1 ? t[0] : new Ae(t);
1479
+ }
1480
+ function Oe(t) {
1481
+ return t == null || t === !1 || O(t) || Ue(t) || R(t) || y(t) || X(Oe, t);
1482
+ }
1483
+ export {
1484
+ wt as A,
1485
+ Lt as B,
1486
+ Ct as C,
1487
+ Mt as I,
1488
+ Et as P,
1489
+ st as S,
1490
+ z as V,
1491
+ dt as a,
1492
+ ht as b,
1493
+ K as c,
1494
+ ne as d,
1495
+ mt as e,
1496
+ O as f,
1497
+ J as g,
1498
+ H as h,
1499
+ E as i,
1500
+ I as j,
1501
+ Tt as k,
1502
+ St as l,
1503
+ xt as m,
1504
+ U as n,
1505
+ pt as o,
1506
+ N as p,
1507
+ _ as q,
1508
+ S as r,
1509
+ bt as s,
1510
+ D as t,
1511
+ vt as u,
1512
+ Nt as v,
1513
+ v as w,
1514
+ He as x,
1515
+ gt as y,
1516
+ yt as z
1517
+ };
1518
+ //# sourceMappingURL=markup-DQdkb3ri.js.map