@manyducks.co/dolla 2.0.0-alpha.41 → 2.0.0-alpha.43

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,1529 @@
1
+ var Oe = Object.defineProperty;
2
+ var oe = (t) => {
3
+ throw TypeError(t);
4
+ };
5
+ var $e = (t, e, s) => e in t ? Oe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
6
+ var l = (t, e, s) => $e(t, typeof e != "symbol" ? e + "" : e, s), F = (t, e, s) => e.has(t) || oe("Cannot " + s);
7
+ var w = (t, e, s) => (F(t, e, "read from private field"), s ? s.call(t) : e.get(t)), L = (t, e, s) => e.has(t) ? oe("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), $ = (t, e, s, n) => (F(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s), ue = (t, e, s) => (F(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 ye({
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 re = c.dep.subs;
63
+ if (c = re.prevSub, re.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: ft,
267
+ propagate: lt,
268
+ updateDirtyFlag: Ie,
269
+ startTracking: ve,
270
+ endTracking: we,
271
+ processEffectNotifications: at,
272
+ processComputedUpdate: dt,
273
+ processPendingInnerEffects: be
274
+ } = ye({
275
+ updateComputed(t) {
276
+ ve(t);
277
+ try {
278
+ const e = t.currentValue, s = t.getter(e);
279
+ return e !== s ? (t.currentValue = s, !0) : !1;
280
+ } finally {
281
+ we(t);
282
+ }
283
+ },
284
+ notifyEffect(t) {
285
+ return "isScope" in t ? _e(t) : Ve(t);
286
+ }
287
+ });
288
+ function je(t) {
289
+ ve(t);
290
+ try {
291
+ t.fn();
292
+ } finally {
293
+ we(t);
294
+ }
295
+ }
296
+ function Ve(t) {
297
+ const e = t.flags;
298
+ return e & 32 || e & 64 && Ie(t, e) ? je(t) : be(t, t.flags), !0;
299
+ }
300
+ function _e(t) {
301
+ return t.flags & 128 ? (be(t, t.flags), !0) : !1;
302
+ }
303
+ function A(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 _(t) {
319
+ return Array.isArray(t);
320
+ }
321
+ function X(t, e) {
322
+ return _(e) && e.every((s) => t(s));
323
+ }
324
+ function ht(t, e, s) {
325
+ if (X(t, e))
326
+ return !0;
327
+ throw new TypeError(G(e, s));
328
+ }
329
+ function O(t) {
330
+ return typeof t == "string";
331
+ }
332
+ function pt(t, e) {
333
+ if (O(t))
334
+ return !0;
335
+ throw new TypeError(G(t, e ?? "Expected a string. Got type: %t, value: %v"));
336
+ }
337
+ function E(t) {
338
+ return A(t) === "function";
339
+ }
340
+ function qe(t) {
341
+ return typeof t == "number" && !isNaN(t);
342
+ }
343
+ function mt(...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(G(i, s));
348
+ };
349
+ return t.length < 2 ? n : n(t[1]);
350
+ }
351
+ function J(t) {
352
+ return t != null && typeof t == "object" && !_(t);
353
+ }
354
+ function gt(t, e) {
355
+ if (J(t))
356
+ return !0;
357
+ throw new TypeError(G(t, e));
358
+ }
359
+ function G(t, e) {
360
+ var i;
361
+ const s = A(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: Ue,
368
+ updateDirtyFlag: ze,
369
+ startTracking: Y,
370
+ endTracking: ee,
371
+ processEffectNotifications: Re,
372
+ processComputedUpdate: Be,
373
+ processPendingInnerEffects: Ge
374
+ } = ye({
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 && ze(t, e) ? Ne(t) : Ge(t, t.flags), !0;
388
+ }
389
+ });
390
+ let g;
391
+ const C = [];
392
+ let W = !1;
393
+ function Fe() {
394
+ W || (W = !0, queueMicrotask(() => {
395
+ W = !1;
396
+ for (let t = 0; t < C.length; t++) {
397
+ const e = C[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
+ C.length = 0;
406
+ }));
407
+ }
408
+ function Ne(t) {
409
+ C.push(t), Fe();
410
+ }
411
+ function We() {
412
+ Y(this), ee(this), queueMicrotask(() => {
413
+ C.splice(C.indexOf(this), 1);
414
+ });
415
+ }
416
+ const xe = [];
417
+ function Ze() {
418
+ xe.push(g), g = void 0;
419
+ }
420
+ function He() {
421
+ g = xe.pop();
422
+ }
423
+ var b, j;
424
+ class Me {
425
+ constructor(e, s) {
426
+ L(this, b);
427
+ L(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 && (Ue(s), Re());
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 D, V, B, ke;
511
+ class Ee {
512
+ constructor(e, s) {
513
+ L(this, B);
514
+ L(this, D);
515
+ L(this, V);
516
+ l(this, "name");
517
+ $(this, V, e), $(this, D, {
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: ue(this, B, ke).bind(this)
526
+ }), s != null && s.name && (this.name = s.name);
527
+ }
528
+ get() {
529
+ return g !== void 0 && (Q(w(this, D), g), P.push(this)), this.peek();
530
+ }
531
+ peek() {
532
+ const e = w(this, D), s = e.flags;
533
+ return s & (M.Dirty | M.PendingComputed) && Be(e, s), e.currentValue;
534
+ }
535
+ /**
536
+ * @deprecated use `get()`
537
+ */
538
+ get value() {
539
+ return this.peek();
540
+ }
541
+ }
542
+ D = new WeakMap(), V = new WeakMap(), B = new WeakSet(), ke = 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 Me || t instanceof Ee;
548
+ }
549
+ function K(t, e) {
550
+ return new Me(t, e);
551
+ }
552
+ function te(t, e) {
553
+ return new Ee(t, e);
554
+ }
555
+ function Ke(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) => Ke(t, s);
562
+ }
563
+ function I(t) {
564
+ return y(t) ? t.get() : t;
565
+ }
566
+ function yt(t) {
567
+ return y(t) ? t.peek() : t;
568
+ }
569
+ function se(t) {
570
+ Ze(), t(), He();
571
+ }
572
+ function vt(t) {
573
+ T = t;
574
+ }
575
+ function v(t) {
576
+ const e = {
577
+ fn: t,
578
+ subs: void 0,
579
+ subsTail: void 0,
580
+ deps: void 0,
581
+ depsTail: void 0,
582
+ flags: M.Effect
583
+ };
584
+ return g !== void 0 && Q(e, g), Ne(e), We.bind(e);
585
+ }
586
+ const wt = () => {
587
+ };
588
+ let Z = 1;
589
+ function Se() {
590
+ return Z = Z % Number.MAX_SAFE_INTEGER + 1, Z.toString(36) + Date.now().toString(36);
591
+ }
592
+ function bt(t, e) {
593
+ return Object.is(t, e);
594
+ }
595
+ function Nt(t, e) {
596
+ if (Object.is(t, e)) return !0;
597
+ const s = A(t);
598
+ if (s !== A(e))
599
+ return !1;
600
+ switch (s) {
601
+ case "object":
602
+ let n = 0;
603
+ for (const i in t) {
604
+ if (t[i] !== e[i]) return !1;
605
+ n++;
606
+ }
607
+ return Object.keys(e).length === n;
608
+ case "array":
609
+ if (t.length !== e.length) return !1;
610
+ for (let i = 0; i < t.length; i++)
611
+ if (t[i] !== e[i]) return !1;
612
+ return !0;
613
+ case "map":
614
+ if (t.size !== e.size) return !1;
615
+ for (const i of t.keys())
616
+ if (t[i] !== e[i]) return !1;
617
+ return !0;
618
+ case "set":
619
+ if (E(t.symmetricDifference))
620
+ return t.symmetricDifference(e).size === 0;
621
+ for (const i of t.keys())
622
+ if (t[i] !== e.get(i)) return !1;
623
+ return !0;
624
+ }
625
+ return !1;
626
+ }
627
+ function H(t, e) {
628
+ if (t === e) return !0;
629
+ if (t && e && typeof t == "object" && typeof e == "object") {
630
+ if (t.constructor !== e.constructor) return !1;
631
+ var s, n, i;
632
+ if (Array.isArray(t)) {
633
+ if (s = t.length, s != e.length) return !1;
634
+ for (n = s; n-- !== 0; ) if (!H(t[n], e[n])) return !1;
635
+ return !0;
636
+ }
637
+ if (t instanceof Map && e instanceof Map) {
638
+ if (t.size !== e.size) return !1;
639
+ for (n of t.entries()) if (!e.has(n[0])) return !1;
640
+ for (n of t.entries()) if (!H(n[1], e.get(n[0]))) return !1;
641
+ return !0;
642
+ }
643
+ if (t instanceof Set && e instanceof Set) {
644
+ if (t.size !== e.size) return !1;
645
+ for (n of t.entries()) if (!e.has(n[0])) return !1;
646
+ return !0;
647
+ }
648
+ if (ArrayBuffer.isView(t) && ArrayBuffer.isView(e)) {
649
+ if (s = t.length, s != e.length) return !1;
650
+ for (n = s; n-- !== 0; ) if (t[n] !== e[n]) return !1;
651
+ return !0;
652
+ }
653
+ if (t.constructor === RegExp) return t.source === e.source && t.flags === e.flags;
654
+ if (t.valueOf !== Object.prototype.valueOf) return t.valueOf() === e.valueOf();
655
+ if (t.toString !== Object.prototype.toString) return t.toString() === e.toString();
656
+ if (i = Object.keys(t), s = i.length, s !== Object.keys(e).length) return !1;
657
+ for (n = s; n-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(e, i[n])) return !1;
658
+ for (n = s; n-- !== 0; ) {
659
+ var o = i[n];
660
+ if (!H(t[o], e[o])) return !1;
661
+ }
662
+ return !0;
663
+ }
664
+ return t !== t && e !== e;
665
+ }
666
+ function Xe(t, e) {
667
+ const s = {};
668
+ for (const n in e)
669
+ t.includes(n) || (s[n] = e[n]);
670
+ return s;
671
+ }
672
+ function xt(t) {
673
+ let e = 0;
674
+ for (let s = 0; s < t.length; s++)
675
+ e = (e + t.charCodeAt(s) * 10) % 360;
676
+ return `oklch(0.68 0.15 ${e}deg)`;
677
+ }
678
+ function Mt(t) {
679
+ if (t instanceof RegExp)
680
+ return (n) => t.test(n);
681
+ const e = {
682
+ positive: [],
683
+ negative: []
684
+ }, s = t.split(",").map((n) => n.trim()).filter((n) => n !== "");
685
+ for (let n of s) {
686
+ let i = "positive";
687
+ n.startsWith("-") && (i = "negative", n = n.slice(1)), n === "*" ? e[i].push(function() {
688
+ return !0;
689
+ }) : n.endsWith("*") ? e[i].push(function(o) {
690
+ return o.startsWith(n.slice(0, n.length - 1));
691
+ }) : e[i].push(function(o) {
692
+ return o === n;
693
+ });
694
+ }
695
+ return function(n) {
696
+ const { positive: i, negative: o } = e;
697
+ return !(o.some((f) => f(n)) || i.length > 0 && !i.some((f) => f(n)));
698
+ };
699
+ }
700
+ const k = Symbol.for("DollaMarkupElement"), Et = Symbol.for("DollaRouter");
701
+ function kt(t, e) {
702
+ return e.outlet();
703
+ }
704
+ function Je(t) {
705
+ for (var e, s, n = arguments, i = 1, o = "", f = "", a = [0], m = function(c) {
706
+ 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 = "";
707
+ }, r = 0; r < t.length; r++) {
708
+ r && (i === 1 && m(), m(r));
709
+ 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 === `
710
+ ` || e === "\r" ? (m(), i = 2) : o += e), i === 3 && o === "!--" && (i = 4, a = a[0]);
711
+ }
712
+ return m(), a.length > 2 ? a.slice(1) : a[1];
713
+ }
714
+ var le;
715
+ le = k;
716
+ class ce {
717
+ constructor(e) {
718
+ l(this, le, !0);
719
+ l(this, "domNode");
720
+ this.domNode = e;
721
+ }
722
+ get isMounted() {
723
+ return this.domNode.parentNode != null;
724
+ }
725
+ mount(e, s) {
726
+ e.insertBefore(this.domNode, (s == null ? void 0 : s.nextSibling) ?? null);
727
+ }
728
+ unmount(e = !1) {
729
+ this.domNode.parentNode && !e && this.domNode.parentNode.removeChild(this.domNode);
730
+ }
731
+ }
732
+ var ae;
733
+ ae = k;
734
+ class Qe {
735
+ constructor(e) {
736
+ l(this, ae, !0);
737
+ l(this, "domNode", document.createTextNode(""));
738
+ l(this, "children", []);
739
+ l(this, "elementContext");
740
+ l(this, "source");
741
+ l(this, "unsubscribe");
742
+ this.source = e.source, this.elementContext = e.elementContext;
743
+ }
744
+ get isMounted() {
745
+ return this.domNode.parentNode != null;
746
+ }
747
+ mount(e, s) {
748
+ this.isMounted || (e.insertBefore(this.domNode, (s == null ? void 0 : s.nextSibling) ?? null), this.unsubscribe = v(() => {
749
+ const n = this.source.get();
750
+ if (!Pe(n))
751
+ throw console.error(n), new TypeError(
752
+ `Dynamic received invalid value to render. Got type: ${A(n)}, value: ${n}`
753
+ );
754
+ se(() => {
755
+ this.update(_(n) ? n : [n]);
756
+ });
757
+ }));
758
+ }
759
+ unmount(e = !1) {
760
+ var s, n;
761
+ (s = this.unsubscribe) == null || s.call(this), this.isMounted && (this.cleanup(e), (n = this.domNode.parentNode) == null || n.removeChild(this.domNode));
762
+ }
763
+ cleanup(e) {
764
+ for (const s of this.children)
765
+ s.unmount(e);
766
+ this.children = [];
767
+ }
768
+ update(e) {
769
+ var o, f, a;
770
+ if (this.cleanup(!1), e == null || e.length === 0 || !this.isMounted)
771
+ return;
772
+ const s = e.flatMap((m) => De(m) ? m : S(this.elementContext, ne(m)));
773
+ for (const m of s) {
774
+ const r = ((o = this.children.at(-1)) == null ? void 0 : o.domNode) || this.domNode;
775
+ m.mount(this.domNode.parentNode, r), this.children.push(m);
776
+ }
777
+ const n = this.domNode.parentNode, i = ((a = (f = this.children.at(-1)) == null ? void 0 : f.domNode) == null ? void 0 : a.nextSibling) ?? null;
778
+ n.insertBefore(this.domNode, i);
779
+ }
780
+ }
781
+ const Ye = (t) => /^on[A-Z]/.test(t);
782
+ var de;
783
+ de = k;
784
+ class et {
785
+ constructor({ tag: e, props: s, children: n, elementContext: i }) {
786
+ l(this, de, !0);
787
+ l(this, "domNode");
788
+ l(this, "props");
789
+ l(this, "childMarkup", []);
790
+ l(this, "children", []);
791
+ l(this, "unsubscribers", []);
792
+ l(this, "elementContext");
793
+ // Track the ref so we can nullify it on unmount.
794
+ l(this, "ref");
795
+ // Prevents 'onClickOutside' handlers from firing in the same cycle in which the element is connected.
796
+ l(this, "canClickAway", !1);
797
+ if (e.toLowerCase() === "svg" && (i = {
798
+ ...i,
799
+ isSVG: !0
800
+ }), 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)
801
+ if (E(s.ref))
802
+ this.ref = s.ref, this.ref(this.domNode);
803
+ else
804
+ throw new Error("Expected ref to be a function. Got: " + s.ref);
805
+ this.props = {
806
+ ...Xe(["ref", "class", "className"], s),
807
+ class: s.className ?? s.class
808
+ }, n && (this.childMarkup = n), this.elementContext = i;
809
+ }
810
+ get isMounted() {
811
+ return this.domNode.parentNode != null;
812
+ }
813
+ mount(e, s) {
814
+ if (e == null)
815
+ throw new Error(`HTML element requires a parent element as the first argument to connect. Got: ${e}`);
816
+ if (!this.isMounted) {
817
+ this.childMarkup.length > 0 && (this.children = S(this.elementContext, this.childMarkup));
818
+ for (let n = 0; n < this.children.length; n++) {
819
+ const i = this.children[n], o = n > 0 ? this.children[n - 1].domNode : void 0;
820
+ i.mount(this.domNode, o);
821
+ }
822
+ 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);
823
+ }
824
+ e.insertBefore(this.domNode, (s == null ? void 0 : s.nextSibling) ?? null), setTimeout(() => {
825
+ this.canClickAway = !0;
826
+ }, 0);
827
+ }
828
+ unmount(e = !1) {
829
+ var s;
830
+ if (this.isMounted) {
831
+ e || (s = this.domNode.parentNode) == null || s.removeChild(this.domNode);
832
+ for (const n of this.children)
833
+ n.unmount(!0);
834
+ this.ref && this.ref(void 0), this.canClickAway = !1;
835
+ for (const n of this.unsubscribers)
836
+ n();
837
+ this.unsubscribers.length = 0;
838
+ }
839
+ }
840
+ attachProp(e, s) {
841
+ y(e) ? this.unsubscribers.push(
842
+ v(() => {
843
+ s(e.get());
844
+ })
845
+ ) : s(e);
846
+ }
847
+ applyProps(e, s) {
848
+ for (const n in s) {
849
+ const i = s[n];
850
+ if (n === "on:clickoutside" || n === "onClickOutside" || n === "onclickoutside") {
851
+ const o = (a) => {
852
+ this.canClickAway && !e.contains(a.target) && (y(i) ? i.peek()(a) : i(a));
853
+ }, f = { capture: !0 };
854
+ window.addEventListener("click", o, f), this.unsubscribers.push(() => {
855
+ window.removeEventListener("click", o, f);
856
+ });
857
+ } else if (Ye(n)) {
858
+ const o = n.slice(2).toLowerCase(), f = y(i) ? (a) => i.peek()(a) : i;
859
+ e.addEventListener(o, f), this.unsubscribers.push(() => {
860
+ e.removeEventListener(o, f);
861
+ });
862
+ } else if (n.includes("-"))
863
+ this.attachProp(i, (o) => {
864
+ o == null ? e.removeAttribute(n) : e.setAttribute(n, String(o));
865
+ });
866
+ else if (!tt.includes(n))
867
+ if (this.elementContext.isSVG)
868
+ this.attachProp(i, (o) => {
869
+ o != null ? e.setAttribute(n, String(s[n])) : e.removeAttribute(n);
870
+ });
871
+ else
872
+ switch (n) {
873
+ case "contentEditable":
874
+ case "value":
875
+ this.attachProp(i, (o) => {
876
+ e[n] = String(o);
877
+ });
878
+ break;
879
+ case "for":
880
+ this.attachProp(i, (o) => {
881
+ e.htmlFor = o;
882
+ });
883
+ break;
884
+ case "checked":
885
+ this.attachProp(i, (o) => {
886
+ e.checked = o, o ? e.setAttribute("checked", "") : e.removeAttribute("checked");
887
+ });
888
+ break;
889
+ case "autocomplete":
890
+ case "autocapitalize":
891
+ this.attachProp(i, (o) => {
892
+ typeof o == "string" ? e[n] = o : o ? e[n] = "on" : e[n] = "off";
893
+ });
894
+ break;
895
+ default: {
896
+ if (n.startsWith("prop:")) {
897
+ const o = n.substring(5);
898
+ this.attachProp(i, (f) => {
899
+ e[o] = f;
900
+ });
901
+ } else if (n.startsWith("on:")) {
902
+ const o = n.substring(3);
903
+ let f;
904
+ this.attachProp(i, (a) => {
905
+ !a && f ? e.removeEventListener(o, f) : a != null && (f && f !== a && e.removeEventListener(o, f), e.addEventListener(o, a)), f = a;
906
+ });
907
+ } else if (n.startsWith("attr:")) {
908
+ const o = n.substring(5).toLowerCase();
909
+ this.attachProp(i, (f) => {
910
+ f != null ? e.setAttribute(o, String(f)) : e.removeAttribute(o);
911
+ });
912
+ } else
913
+ this.attachProp(i, (o) => {
914
+ e[n] = o;
915
+ });
916
+ break;
917
+ }
918
+ }
919
+ }
920
+ }
921
+ applyStyles(e, s, n) {
922
+ const i = [];
923
+ if (y(s)) {
924
+ let o;
925
+ const f = v(() => {
926
+ E(o) && o(), e.style.cssText = "", o = this.applyStyles(e, I(s), n);
927
+ });
928
+ n.push(f), i.push(f);
929
+ } else {
930
+ const o = Le(s);
931
+ for (const f in o) {
932
+ const { value: a, priority: m } = o[f];
933
+ if (y(a)) {
934
+ const r = v(() => {
935
+ a.get() ? e.style.setProperty(f, String(a.get()), m) : e.style.removeProperty(f);
936
+ });
937
+ n.push(r), i.push(r);
938
+ } else a != null && e.style.setProperty(f, String(a));
939
+ }
940
+ }
941
+ return function() {
942
+ for (const f of i)
943
+ f(), n.splice(n.indexOf(f), 1);
944
+ };
945
+ }
946
+ applyClasses(e, s, n) {
947
+ const i = [];
948
+ if (y(s)) {
949
+ let o;
950
+ const f = v(() => {
951
+ E(o) && o(), e.removeAttribute("class"), o = this.applyClasses(e, I(s), n);
952
+ });
953
+ n.push(f), i.push(f);
954
+ } else {
955
+ const o = Te(s);
956
+ for (const f in o) {
957
+ const a = o[f];
958
+ if (y(a)) {
959
+ const m = v(() => {
960
+ I(a) ? e.classList.add(f) : e.classList.remove(f);
961
+ });
962
+ n.push(m), i.push(m);
963
+ } else a && e.classList.add(f);
964
+ }
965
+ }
966
+ return function() {
967
+ for (const f of i)
968
+ f(), n.splice(n.indexOf(f), 1);
969
+ };
970
+ }
971
+ }
972
+ function Te(t) {
973
+ let e = {};
974
+ if (O(t)) {
975
+ const s = t.split(" ");
976
+ for (const n of s)
977
+ e[n] = !0;
978
+ } else J(t) ? Object.assign(e, t) : Array.isArray(t) && Array.from(t).filter(Boolean).forEach((s) => {
979
+ Object.assign(e, Te(s));
980
+ });
981
+ return delete e.undefined, e;
982
+ }
983
+ function Le(t) {
984
+ let e = {};
985
+ if (O(t)) {
986
+ const s = t.split(";").filter((n) => n.trim() !== "");
987
+ for (const n of s) {
988
+ const [i, o] = n.split(":"), f = {
989
+ value: o
990
+ };
991
+ o.includes("!important") ? (f.priority = "important", f.value = o.replace("!important", "").trim()) : f.value = o.trim(), e[fe(i.trim())] = f;
992
+ }
993
+ }
994
+ if (J(t))
995
+ for (const s in t)
996
+ s.startsWith("--") ? e[s] = { value: t[s] } : e[fe(s)] = { value: t[s] };
997
+ else Array.isArray(t) && Array.from(t).filter((s) => s != null).forEach((s) => {
998
+ Object.assign(e, Le(s));
999
+ });
1000
+ return e;
1001
+ }
1002
+ function fe(t) {
1003
+ return t.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (e, s) => (s ? "-" : "") + e.toLowerCase());
1004
+ }
1005
+ const tt = ["ref", "children", "class", "style", "data"];
1006
+ let st = class {
1007
+ constructor(e) {
1008
+ l(this, "store");
1009
+ this.store = e;
1010
+ const s = Object.getOwnPropertyDescriptors(this.store.logger);
1011
+ for (const n in s)
1012
+ n !== "setName" && Object.defineProperty(this, n, s[n]);
1013
+ }
1014
+ get isMounted() {
1015
+ return this.store.isMounted;
1016
+ }
1017
+ get name() {
1018
+ return this.store.name || this.store.id;
1019
+ }
1020
+ set name(e) {
1021
+ this.store.name = e, this.store.logger.setName(e);
1022
+ }
1023
+ get(e) {
1024
+ if (E(e)) {
1025
+ let s = this.store.elementContext, n;
1026
+ for (; n = s.stores.get(e), n == null && s.parent != null; )
1027
+ s = s.parent;
1028
+ if (n == null)
1029
+ throw new U(`Store '${e.name}' is not provided on this context.`);
1030
+ return n.value;
1031
+ } else
1032
+ throw new U("Invalid store.");
1033
+ }
1034
+ onMount(e) {
1035
+ this.store.lifecycleListeners.mount.push(e);
1036
+ }
1037
+ onUnmount(e) {
1038
+ this.store.lifecycleListeners.unmount.push(e);
1039
+ }
1040
+ effect(e) {
1041
+ const s = this.store;
1042
+ if (s.isMounted) {
1043
+ const n = v(e);
1044
+ return s.lifecycleListeners.unmount.push(n), n;
1045
+ } else {
1046
+ let n, i = !1;
1047
+ return s.lifecycleListeners.mount.push(() => {
1048
+ i || (n = v(e), s.lifecycleListeners.unmount.push(n));
1049
+ }), () => {
1050
+ n != null && (i = !0, n());
1051
+ };
1052
+ }
1053
+ }
1054
+ };
1055
+ class nt {
1056
+ constructor(e, s) {
1057
+ l(this, "fn");
1058
+ l(this, "_options");
1059
+ /**
1060
+ * Value is guaranteed to be set after `attach` is called.
1061
+ */
1062
+ l(this, "value");
1063
+ l(this, "isMounted", !1);
1064
+ l(this, "elementContext");
1065
+ l(this, "lifecycleListeners", { mount: [], unmount: [] });
1066
+ l(this, "logger");
1067
+ l(this, "id", Se());
1068
+ l(this, "name");
1069
+ this.fn = e, this.name = e.name, this._options = s;
1070
+ }
1071
+ /**
1072
+ * Attaches this Store to the elementContext.
1073
+ * Returns false if there was already an instance attached, and true otherwise.
1074
+ */
1075
+ attach(e) {
1076
+ if (e.stores.has(this.fn))
1077
+ return !1;
1078
+ this.elementContext = e, this.logger = e.root.createLogger(this.name);
1079
+ const s = new st(this);
1080
+ try {
1081
+ this.value = this.fn.call(s, this._options, s);
1082
+ } catch (n) {
1083
+ throw this.logger.crash(n), n;
1084
+ }
1085
+ return e.stores.set(this.fn, this), !0;
1086
+ }
1087
+ handleMount() {
1088
+ this.isMounted = !0;
1089
+ for (const e of this.lifecycleListeners.mount)
1090
+ e();
1091
+ this.lifecycleListeners.mount.length = 0;
1092
+ }
1093
+ handleUnmount() {
1094
+ this.isMounted = !1;
1095
+ for (const e of this.lifecycleListeners.unmount)
1096
+ e();
1097
+ this.lifecycleListeners.unmount.length = 0;
1098
+ }
1099
+ }
1100
+ class U extends Error {
1101
+ }
1102
+ class it {
1103
+ constructor(e) {
1104
+ l(this, "view");
1105
+ this.view = e;
1106
+ const s = Object.getOwnPropertyDescriptors(this.view.logger);
1107
+ for (const n in s)
1108
+ n !== "setName" && Object.defineProperty(this, n, s[n]);
1109
+ }
1110
+ get uid() {
1111
+ return this.view.uniqueId;
1112
+ }
1113
+ get isMounted() {
1114
+ return this.view.isMounted;
1115
+ }
1116
+ get name() {
1117
+ return this.view.elementContext.viewName || this.uid;
1118
+ }
1119
+ set name(e) {
1120
+ this.view.elementContext.viewName = e, this.view.logger.setName(e);
1121
+ }
1122
+ provide(e, s) {
1123
+ const n = new nt(e, s);
1124
+ if (n.attach(this.view.elementContext))
1125
+ return this.view.lifecycleListeners.mount.push(() => {
1126
+ n.handleMount();
1127
+ }), this.view.lifecycleListeners.unmount.push(() => {
1128
+ n.handleUnmount();
1129
+ }), n.value;
1130
+ {
1131
+ let o = e.name ? `'${e.name}'` : "this store";
1132
+ return this.view.logger.warn(`An instance of ${o} was already attached to this context.`), this.get(e);
1133
+ }
1134
+ }
1135
+ get(e) {
1136
+ if (E(e)) {
1137
+ let s = this.view.elementContext, n;
1138
+ for (; n = s.stores.get(e), n == null && s.parent != null; )
1139
+ s = s.parent;
1140
+ if (n == null)
1141
+ throw new U(`Store '${e.name}' is not provided on this context.`);
1142
+ return n.value;
1143
+ } else
1144
+ throw new U("Invalid store.");
1145
+ }
1146
+ beforeMount(e) {
1147
+ this.view.lifecycleListeners.beforeMount.push(e);
1148
+ }
1149
+ onMount(e) {
1150
+ this.view.lifecycleListeners.mount.push(e);
1151
+ }
1152
+ beforeUnmount(e) {
1153
+ this.view.lifecycleListeners.beforeUnmount.push(e);
1154
+ }
1155
+ onUnmount(e) {
1156
+ this.view.lifecycleListeners.unmount.push(e);
1157
+ }
1158
+ effect(e) {
1159
+ if (this.view.isMounted) {
1160
+ const s = v(e);
1161
+ return this.view.lifecycleListeners.unmount.push(s), s;
1162
+ } else {
1163
+ let s, n = !1;
1164
+ return this.view.lifecycleListeners.mount.push(() => {
1165
+ n || (s = v(e), this.view.lifecycleListeners.unmount.push(s));
1166
+ }), () => {
1167
+ s != null && (n = !0, s());
1168
+ };
1169
+ }
1170
+ }
1171
+ outlet() {
1172
+ return N("$outlet", { children: this.view.children });
1173
+ }
1174
+ }
1175
+ var he;
1176
+ he = k;
1177
+ const ie = class ie {
1178
+ constructor(e, s, n, i = []) {
1179
+ l(this, he, !0);
1180
+ l(this, "uniqueId", Se());
1181
+ l(this, "elementContext");
1182
+ l(this, "logger");
1183
+ l(this, "props");
1184
+ l(this, "fn");
1185
+ l(this, "element");
1186
+ l(this, "childMarkup");
1187
+ l(this, "children", K([]));
1188
+ l(this, "lifecycleListeners", { beforeMount: [], mount: [], beforeUnmount: [], unmount: [] });
1189
+ l(this, "isMounted", !1);
1190
+ this.elementContext = {
1191
+ ...e,
1192
+ parent: e,
1193
+ viewName: s.name,
1194
+ stores: /* @__PURE__ */ new Map()
1195
+ }, this.logger = e.root.createLogger(s.name || "🌇 anonymous view", { uid: this.uniqueId }), this.props = n, this.fn = s, this.childMarkup = i;
1196
+ }
1197
+ /*===============================*\
1198
+ || "Public" API ||
1199
+ \*===============================*/
1200
+ get domNode() {
1201
+ var e;
1202
+ return (e = this.element) == null ? void 0 : e.domNode;
1203
+ }
1204
+ mount(e, s) {
1205
+ const n = this.isMounted;
1206
+ if (!n) {
1207
+ this._initialize();
1208
+ for (const i of this.lifecycleListeners.beforeMount)
1209
+ i();
1210
+ }
1211
+ this.element && this.element.mount(e, s), n || (this.isMounted = !0, requestAnimationFrame(() => {
1212
+ for (const i of this.lifecycleListeners.mount)
1213
+ i();
1214
+ }));
1215
+ }
1216
+ unmount(e = !1) {
1217
+ for (const s of this.lifecycleListeners.beforeUnmount)
1218
+ s();
1219
+ this.element && this.element.unmount(e), this.isMounted = !1;
1220
+ for (const s of this.lifecycleListeners.unmount)
1221
+ s();
1222
+ this.lifecycleListeners.beforeMount.length = 0, this.lifecycleListeners.mount.length = 0, this.lifecycleListeners.beforeUnmount.length = 0, this.lifecycleListeners.unmount.length = 0;
1223
+ }
1224
+ setChildView(e) {
1225
+ this.childMarkup = [];
1226
+ const s = new ie(this.elementContext, e, {});
1227
+ return this.children.set([s]), s;
1228
+ }
1229
+ /*===============================*\
1230
+ || Internal ||
1231
+ \*===============================*/
1232
+ _initialize() {
1233
+ const e = new it(this);
1234
+ let s;
1235
+ try {
1236
+ s = this.fn.call(e, this.props, e), this.childMarkup.length && this.children.set(S(this.elementContext, this.childMarkup));
1237
+ } catch (n) {
1238
+ throw n instanceof Error && this.logger.crash(n), n;
1239
+ }
1240
+ if (s !== null) if (s instanceof Node)
1241
+ this.element = q(S(this.elementContext, N("$node", { value: s })));
1242
+ else if (y(s))
1243
+ this.element = q(
1244
+ S(this.elementContext, N("$dynamic", { source: s }))
1245
+ );
1246
+ else if (R(s) || X(R, s))
1247
+ this.element = q(S(this.elementContext, s));
1248
+ else {
1249
+ const n = new TypeError(
1250
+ `Expected '${this.fn.name}' function to return a DOM node, Markup element, Readable or null. Got: ${A(s)}`
1251
+ );
1252
+ this.logger.crash(n);
1253
+ }
1254
+ }
1255
+ };
1256
+ let z = ie;
1257
+ var pe;
1258
+ pe = k;
1259
+ class rt {
1260
+ constructor({ elementContext: e, items: s, renderFn: n, keyFn: i }) {
1261
+ l(this, pe, !0);
1262
+ l(this, "domNode", document.createTextNode(""));
1263
+ l(this, "items");
1264
+ l(this, "unsubscribe", null);
1265
+ l(this, "connectedItems", []);
1266
+ l(this, "elementContext");
1267
+ l(this, "renderFn");
1268
+ l(this, "keyFn");
1269
+ this.elementContext = e, this.items = s, this.renderFn = n, this.keyFn = i;
1270
+ }
1271
+ get isMounted() {
1272
+ return this.domNode.parentNode != null;
1273
+ }
1274
+ mount(e, s) {
1275
+ this.isMounted || (e.insertBefore(this.domNode, (s == null ? void 0 : s.nextSibling) ?? null), this.unsubscribe = v(() => {
1276
+ let n = this.items.get();
1277
+ n == null && (n = [], console.log("list received empty value", n, this)), se(() => {
1278
+ this._update(Array.from(n));
1279
+ });
1280
+ }));
1281
+ }
1282
+ unmount(e = !1) {
1283
+ var s;
1284
+ this.unsubscribe && (this.unsubscribe(), this.unsubscribe = null), !e && this.isMounted && ((s = this.domNode.parentNode) == null || s.removeChild(this.domNode)), this._cleanup(e);
1285
+ }
1286
+ _cleanup(e) {
1287
+ for (const s of this.connectedItems)
1288
+ s.element.unmount(e);
1289
+ this.connectedItems = [];
1290
+ }
1291
+ _update(e) {
1292
+ var f, a, m;
1293
+ if (e.length === 0 || !this.isMounted)
1294
+ return this._cleanup(!1);
1295
+ const s = [];
1296
+ let n = 0;
1297
+ for (const r of e)
1298
+ s.push({
1299
+ key: this.keyFn(r, n),
1300
+ value: r,
1301
+ index: n++
1302
+ });
1303
+ const i = [];
1304
+ for (const r of this.connectedItems)
1305
+ s.find((c) => c.key === r.key) || r.element.unmount(!1);
1306
+ for (const r of s) {
1307
+ const u = this.connectedItems.find((c) => c.key === r.key);
1308
+ if (u)
1309
+ u.item.set(r.value), u.index.set(r.index), i[r.index] = u;
1310
+ else {
1311
+ const c = K(r.value), h = K(r.index);
1312
+ i[r.index] = {
1313
+ key: r.key,
1314
+ item: c,
1315
+ index: h,
1316
+ element: new z(this.elementContext, ot, {
1317
+ item: te(() => c.get()),
1318
+ index: h,
1319
+ renderFn: this.renderFn
1320
+ })
1321
+ };
1322
+ }
1323
+ }
1324
+ for (let r = 0; r < i.length; r++) {
1325
+ const u = i[r], c = ((f = i[r - 1]) == null ? void 0 : f.element.domNode) ?? this.domNode;
1326
+ u.element.mount(this.domNode.parentNode, c);
1327
+ }
1328
+ this.connectedItems = i;
1329
+ const o = ((a = i.at(-1)) == null ? void 0 : a.element.domNode) ?? this.domNode;
1330
+ (m = this.domNode.parentNode) == null || m.insertBefore(this.domNode, o.nextSibling);
1331
+ }
1332
+ }
1333
+ function ot(t, e) {
1334
+ return e.name = "@ListItem", t.renderFn.call(e, t.item, t.index, e);
1335
+ }
1336
+ var me;
1337
+ me = k;
1338
+ class Ce {
1339
+ constructor(e) {
1340
+ l(this, me, !0);
1341
+ l(this, "domNode", document.createTextNode(""));
1342
+ l(this, "isMounted", !1);
1343
+ l(this, "source");
1344
+ l(this, "elements", []);
1345
+ l(this, "unsubscribe");
1346
+ this.source = e;
1347
+ }
1348
+ mount(e, s) {
1349
+ this.isMounted || (this.isMounted = !0, e.insertBefore(this.domNode, (s == null ? void 0 : s.nextSibling) ?? null), y(this.source) ? this.unsubscribe = v(() => {
1350
+ const n = I(this.source);
1351
+ se(() => {
1352
+ this.update(n);
1353
+ });
1354
+ }) : this.update(this.elements));
1355
+ }
1356
+ unmount(e = !1) {
1357
+ this.unsubscribe && (this.unsubscribe(), this.unsubscribe = void 0), this.isMounted && (this.cleanup(e), this.isMounted = !1);
1358
+ }
1359
+ cleanup(e) {
1360
+ for (const s of this.elements)
1361
+ s.unmount(e);
1362
+ this.elements = [];
1363
+ }
1364
+ update(e) {
1365
+ var s, n;
1366
+ if (this.cleanup(!1), e.length > 0) {
1367
+ for (let i = 0; i < e.length; i++) {
1368
+ const o = e[i], f = i > 0 ? this.elements[i - 1] : void 0;
1369
+ o.mount(this.domNode.parentElement, f == null ? void 0 : f.domNode), this.elements.push(o);
1370
+ }
1371
+ (n = this.domNode.parentNode) == null || n.insertBefore(this.domNode, ((s = this.elements.at(-1)) == null ? void 0 : s.domNode) ?? null);
1372
+ }
1373
+ }
1374
+ }
1375
+ var ge;
1376
+ ge = k;
1377
+ class ut {
1378
+ constructor(e) {
1379
+ l(this, ge, !0);
1380
+ l(this, "config");
1381
+ l(this, "element");
1382
+ this.config = e;
1383
+ }
1384
+ get isMounted() {
1385
+ return this.element ? this.element.isMounted : !1;
1386
+ }
1387
+ mount(e, s) {
1388
+ const { content: n, parent: i } = this.config;
1389
+ De(n) ? this.element = n : this.element = q(S(this.config.elementContext, ne(n))), this.element.mount(i);
1390
+ }
1391
+ unmount(e = !1) {
1392
+ var s;
1393
+ (s = this.element) != null && s.isMounted && this.element.unmount(e);
1394
+ }
1395
+ }
1396
+ function R(t) {
1397
+ return t instanceof Ae;
1398
+ }
1399
+ function De(t) {
1400
+ return (t == null ? void 0 : t[k]) === !0;
1401
+ }
1402
+ function ne(t) {
1403
+ return _(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 }));
1404
+ }
1405
+ function N(t, e, ...s) {
1406
+ return new Ae(t, e, ...s);
1407
+ }
1408
+ class Ae {
1409
+ constructor(e, s, ...n) {
1410
+ l(this, "type");
1411
+ l(this, "props");
1412
+ l(this, "children");
1413
+ this.type = e, this.props = s, this.children = ne(n);
1414
+ }
1415
+ }
1416
+ const Tt = Je.bind(N);
1417
+ function Lt(t, e, s) {
1418
+ return N("$dynamic", {
1419
+ source: te(() => {
1420
+ const n = I(t);
1421
+ return n && e ? e : !n && s ? s : null;
1422
+ })
1423
+ });
1424
+ }
1425
+ function Ct(t, e, s) {
1426
+ return N("$list", { items: te(() => t), keyFn: e, renderFn: s });
1427
+ }
1428
+ function Dt(t, e) {
1429
+ return N("$portal", { parent: t, content: e });
1430
+ }
1431
+ function S(t, e) {
1432
+ return (_(e) ? e : [e]).map((n) => {
1433
+ if (E(n.type))
1434
+ return new z(t, n.type, n.props, n.children);
1435
+ if (O(n.type))
1436
+ switch (n.type) {
1437
+ case "$node": {
1438
+ const i = n.props;
1439
+ return new ce(i.value);
1440
+ }
1441
+ case "$text": {
1442
+ const i = n.props;
1443
+ return new ce(document.createTextNode(String(i.value)));
1444
+ }
1445
+ case "$list": {
1446
+ const i = n.props;
1447
+ return new rt({
1448
+ items: i.items,
1449
+ keyFn: i.keyFn,
1450
+ renderFn: i.renderFn,
1451
+ elementContext: t
1452
+ });
1453
+ }
1454
+ case "$dynamic": {
1455
+ const i = n.props;
1456
+ return new Qe({
1457
+ source: i.source,
1458
+ elementContext: t
1459
+ });
1460
+ }
1461
+ case "$outlet": {
1462
+ const i = n.props;
1463
+ return new Ce(i.children);
1464
+ }
1465
+ case "$portal": {
1466
+ const i = n.props;
1467
+ return new ut({
1468
+ content: i.content,
1469
+ parent: i.parent,
1470
+ elementContext: t
1471
+ });
1472
+ }
1473
+ default:
1474
+ if (n.type.startsWith("$"))
1475
+ throw new Error(`Unknown markup type: ${n.type}`);
1476
+ return new et({
1477
+ tag: n.type,
1478
+ props: n.props ?? {},
1479
+ children: n.children,
1480
+ elementContext: t
1481
+ });
1482
+ }
1483
+ else
1484
+ throw new TypeError(`Expected a string or view function. Got: ${n.type}`);
1485
+ });
1486
+ }
1487
+ function q(t) {
1488
+ return t.length === 1 ? t[0] : new Ce(t);
1489
+ }
1490
+ function Pe(t) {
1491
+ return t == null || t === !1 || O(t) || qe(t) || R(t) || y(t) || X(Pe, t);
1492
+ }
1493
+ export {
1494
+ vt as A,
1495
+ bt as B,
1496
+ Dt as C,
1497
+ Ct as D,
1498
+ Et as I,
1499
+ kt as P,
1500
+ nt as S,
1501
+ z as V,
1502
+ ht as a,
1503
+ pt as b,
1504
+ K as c,
1505
+ te as d,
1506
+ gt as e,
1507
+ O as f,
1508
+ J as g,
1509
+ H as h,
1510
+ E as i,
1511
+ I as j,
1512
+ Lt as k,
1513
+ Tt as l,
1514
+ Mt as m,
1515
+ U as n,
1516
+ mt as o,
1517
+ N as p,
1518
+ q,
1519
+ S as r,
1520
+ Nt as s,
1521
+ A as t,
1522
+ wt as u,
1523
+ xt as v,
1524
+ v as w,
1525
+ Ke as x,
1526
+ yt as y,
1527
+ se as z
1528
+ };
1529
+ //# sourceMappingURL=markup-CSJbSI8_.js.map