@manyducks.co/dolla 2.0.0-alpha.32 → 2.0.0-alpha.34

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