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

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