@manyducks.co/dolla 2.0.0-alpha.3 → 2.0.0-alpha.30

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