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

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