@manyducks.co/dolla 2.0.0-alpha.27 → 2.0.0-alpha.29

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