@manyducks.co/dolla 2.0.0-alpha.26 → 2.0.0-alpha.28

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