@manyducks.co/dolla 2.0.0-alpha.55 → 2.0.0-alpha.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/core/context.d.ts +38 -25
  2. package/dist/core/env.d.ts +2 -8
  3. package/dist/core/index.d.ts +3 -5
  4. package/dist/core/logger.d.ts +2 -2
  5. package/dist/core/markup.d.ts +43 -42
  6. package/dist/core/mount.d.ts +1 -1
  7. package/dist/core/nodes/dom.d.ts +6 -6
  8. package/dist/core/nodes/dynamic.d.ts +13 -15
  9. package/dist/core/nodes/html.d.ts +9 -21
  10. package/dist/core/nodes/portal.d.ts +8 -12
  11. package/dist/core/nodes/repeat.d.ts +13 -18
  12. package/dist/core/nodes/view.d.ts +10 -23
  13. package/dist/core/ref.d.ts +2 -6
  14. package/dist/core/symbols.d.ts +1 -1
  15. package/dist/core/views/default-crash-view.d.ts +1 -1
  16. package/dist/core/views/fragment.d.ts +1 -2
  17. package/dist/fragment-BahD_BJA.js +7 -0
  18. package/dist/fragment-BahD_BJA.js.map +1 -0
  19. package/dist/http.js +1 -1
  20. package/dist/i18n.js +2 -2
  21. package/dist/index.js +41 -41
  22. package/dist/index.js.map +1 -1
  23. package/dist/jsx-dev-runtime.d.ts +1 -1
  24. package/dist/jsx-dev-runtime.js +2 -2
  25. package/dist/jsx-runtime.d.ts +2 -2
  26. package/dist/jsx-runtime.js +2 -2
  27. package/dist/{logger-CXdzxt1e.js → logger-sSxIw5od.js} +100 -100
  28. package/dist/logger-sSxIw5od.js.map +1 -0
  29. package/dist/markup-DS7yYBga.js +844 -0
  30. package/dist/markup-DS7yYBga.js.map +1 -0
  31. package/dist/router/index.d.ts +1 -1
  32. package/dist/router/router.d.ts +6 -6
  33. package/dist/{router-B-rtBG7i.js → router-D43DV_bv.js} +184 -183
  34. package/dist/router-D43DV_bv.js.map +1 -0
  35. package/dist/router.js +1 -1
  36. package/dist/router.js.map +1 -1
  37. package/dist/{typeChecking-lgllKIVq.js → typeChecking-BJ-ymQ2F.js} +5 -10
  38. package/dist/{typeChecking-lgllKIVq.js.map → typeChecking-BJ-ymQ2F.js.map} +1 -1
  39. package/dist/types.d.ts +12 -13
  40. package/package.json +1 -1
  41. package/dist/core/nodes/fragment.d.ts +0 -19
  42. package/dist/core/nodes/outlet.d.ts +0 -19
  43. package/dist/fragment-VXM-P2tT.js +0 -7
  44. package/dist/fragment-VXM-P2tT.js.map +0 -1
  45. package/dist/logger-CXdzxt1e.js.map +0 -1
  46. package/dist/markup-yTuFdC0t.js +0 -923
  47. package/dist/markup-yTuFdC0t.js.map +0 -1
  48. package/dist/router-B-rtBG7i.js.map +0 -1
@@ -0,0 +1,844 @@
1
+ var Y = Object.defineProperty;
2
+ var P = (o) => {
3
+ throw TypeError(o);
4
+ };
5
+ var tt = (o, t, e) => t in o ? Y(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
6
+ var c = (o, t, e) => tt(o, typeof t != "symbol" ? t + "" : t, e), C = (o, t, e) => t.has(o) || P("Cannot " + e);
7
+ var d = (o, t, e) => (C(o, t, "read from private field"), e ? e.call(o) : t.get(o)), L = (o, t, e) => t.has(o) ? P("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(o) : t.set(o, e), v = (o, t, e, s) => (C(o, t, "write to private field"), s ? s.call(o, e) : t.set(o, e), e);
8
+ import { c as u, t as et, g as z, b as U, i as F } from "./typeChecking-BJ-ymQ2F.js";
9
+ import { p as k, f as st, g, j as R, e as p, b as it, k as nt, $ as O, d as ot } from "./logger-sSxIw5od.js";
10
+ var m = /* @__PURE__ */ ((o) => (o[o.WILL_MOUNT = 0] = "WILL_MOUNT", o[o.DID_MOUNT = 1] = "DID_MOUNT", o[o.WILL_UNMOUNT = 2] = "WILL_UNMOUNT", o[o.DID_UNMOUNT = 3] = "DID_UNMOUNT", o))(m || {}), l;
11
+ class rt {
12
+ constructor() {
13
+ c(this, "state", 0);
14
+ c(this, "dependents", 0);
15
+ L(this, l, {});
16
+ }
17
+ on(t, e) {
18
+ d(this, l)[t] ? d(this, l)[t].indexOf(e) === -1 && d(this, l)[t].push(e) : d(this, l)[t] = [e];
19
+ }
20
+ off(t, e) {
21
+ d(this, l)[t] && (d(this, l)[t].splice(d(this, l)[t].indexOf(e), 1), d(this, l)[t].length === 0 && delete d(this, l)[t]);
22
+ }
23
+ notify(t) {
24
+ if (d(this, l)[t])
25
+ for (const e of d(this, l)[t])
26
+ e();
27
+ }
28
+ emit(t, e = !1) {
29
+ switch (t) {
30
+ case 0: {
31
+ e && this.dependents++, this.state < 1 && (this.state = e ? 2 : 1, this.notify(t));
32
+ break;
33
+ }
34
+ case 1: {
35
+ this.state >= 1 && this.state < 3 && (this.state += 2, this.notify(t));
36
+ break;
37
+ }
38
+ case 2: {
39
+ e ? (this.dependents--, this.dependents || this.emit(
40
+ 2
41
+ /* WILL_UNMOUNT */
42
+ )) : this.state >= 3 && this.state < 5 && (this.notify(t), this.state += 2);
43
+ break;
44
+ }
45
+ case 3: {
46
+ e ? !this.dependents && this.state === 6 && this.emit(
47
+ 3
48
+ /* DID_UNMOUNT */
49
+ ) : this.state >= 5 && this.state < 7 && (this.state = 7 % 7, this.notify(t));
50
+ break;
51
+ }
52
+ }
53
+ }
54
+ dispose() {
55
+ this.emit(
56
+ 2
57
+ /* WILL_UNMOUNT */
58
+ ), this.emit(
59
+ 3
60
+ /* DID_UNMOUNT */
61
+ ), v(this, l, {});
62
+ }
63
+ }
64
+ l = new WeakMap();
65
+ var w;
66
+ const S = class S {
67
+ constructor(t, e) {
68
+ L(this, w);
69
+ c(this, "_name");
70
+ c(this, "_lifecycle", new rt());
71
+ c(this, "_parent");
72
+ c(this, "_stores");
73
+ c(this, "_state");
74
+ v(this, w, t), this._name = k(t);
75
+ const s = st(() => g(d(this, w)), e == null ? void 0 : e.logger), i = Object.getOwnPropertyDescriptors(s);
76
+ for (const n in i)
77
+ Object.defineProperty(this, n, i[n]);
78
+ }
79
+ get isMounted() {
80
+ const { state: t } = this._lifecycle;
81
+ return t >= 3 && t < 7;
82
+ }
83
+ /**
84
+ * Returns a new Context with this one as its parent.
85
+ */
86
+ static linked(t, e, s) {
87
+ const i = new S(e, s);
88
+ return i._parent = t, s != null && s.bindLifecycleToParent ? (t._lifecycle.on(0, () => {
89
+ i._lifecycle.emit(
90
+ 0
91
+ /* WILL_MOUNT */
92
+ );
93
+ }), t._lifecycle.on(1, () => {
94
+ i._lifecycle.emit(
95
+ 1
96
+ /* DID_MOUNT */
97
+ );
98
+ }), t._lifecycle.on(2, () => {
99
+ i._lifecycle.emit(
100
+ 2
101
+ /* WILL_UNMOUNT */
102
+ );
103
+ }), t._lifecycle.on(3, () => {
104
+ i._lifecycle.emit(
105
+ 3
106
+ /* DID_UNMOUNT */
107
+ );
108
+ })) : (i._lifecycle.on(0, () => {
109
+ t._lifecycle.emit(0, !0);
110
+ }), i._lifecycle.on(1, () => {
111
+ t._lifecycle.emit(1, !0);
112
+ }), i._lifecycle.on(2, () => {
113
+ t._lifecycle.emit(2, !0);
114
+ }), i._lifecycle.on(3, () => {
115
+ t._lifecycle.emit(3, !0);
116
+ })), i;
117
+ }
118
+ static emit(t, e) {
119
+ e._lifecycle.emit(t);
120
+ }
121
+ /**
122
+ * Returns the current name of this context.
123
+ */
124
+ getName() {
125
+ return k(d(this, w));
126
+ }
127
+ /**
128
+ * Sets a new name for this context.
129
+ */
130
+ setName(t) {
131
+ v(this, w, t), this._name = k(t);
132
+ }
133
+ addStore(t, e) {
134
+ var i;
135
+ if ((i = this._stores) != null && i.get(t)) {
136
+ let n = t.name ? `'${t.name}'` : "this store";
137
+ return this.warn(`An instance of ${n} was already added on this context.`), this;
138
+ }
139
+ const s = S.linked(this, t.name, {
140
+ bindLifecycleToParent: !0,
141
+ logger: { tag: R(), tagName: "uid" }
142
+ });
143
+ try {
144
+ this._stores || (this._stores = /* @__PURE__ */ new Map());
145
+ const n = t.call(s, e, s);
146
+ this._stores.set(t, n);
147
+ } catch (n) {
148
+ throw this.crash(n);
149
+ }
150
+ return this;
151
+ }
152
+ getStore(t) {
153
+ var i;
154
+ if (!u(t))
155
+ throw new D("Invalid store.");
156
+ let e = this, s;
157
+ for (; s = (i = e._stores) == null ? void 0 : i.get(t), s == null && e._parent != null; )
158
+ e = e._parent;
159
+ if (s == null)
160
+ throw this.crash(new D(`Store '${t.name}' is not provided by this context.`));
161
+ return s;
162
+ }
163
+ /**
164
+ * Schedule a callback function to run just before this context is mounted.
165
+ */
166
+ beforeMount(t) {
167
+ return this._lifecycle.on(0, t), () => this._lifecycle.off(0, t);
168
+ }
169
+ /**
170
+ * Schedule a callback function to run after this context is mounted.
171
+ */
172
+ onMount(t) {
173
+ return this._lifecycle.on(1, t), () => this._lifecycle.off(1, t);
174
+ }
175
+ /**
176
+ * Schedule a callback function to run just before this context is unmounted.
177
+ */
178
+ beforeUnmount(t) {
179
+ return this._lifecycle.on(2, t), () => this._lifecycle.off(2, t);
180
+ }
181
+ /**
182
+ * Schedule a callback function to run after this context is unmounted.
183
+ */
184
+ onUnmount(t) {
185
+ return this._lifecycle.on(3, t), () => this._lifecycle.off(3, t);
186
+ }
187
+ effect(t) {
188
+ const e = () => {
189
+ try {
190
+ return t();
191
+ } catch (s) {
192
+ this.error(s), s instanceof Error ? this.crash(s) : typeof s == "string" ? this.crash(new Error(s)) : this.crash(new Error("Unknown error thrown in effect callback"));
193
+ }
194
+ };
195
+ if (this._lifecycle.state >= 1) {
196
+ const s = p(e);
197
+ return this._lifecycle.on(3, s), s;
198
+ } else {
199
+ let s, i = !1;
200
+ return this._lifecycle.on(0, () => {
201
+ i || (s = p(e), this._lifecycle.on(3, s));
202
+ }), () => {
203
+ s != null && (i = !0, s());
204
+ };
205
+ }
206
+ }
207
+ getState(t, e) {
208
+ var s;
209
+ if (arguments.length > 0) {
210
+ let i = this, n;
211
+ for (; n = (s = i._state) == null ? void 0 : s.get(t), n === void 0 && i._parent != null; )
212
+ i = i._parent;
213
+ if (n === void 0) {
214
+ if (arguments.length > 1)
215
+ return e;
216
+ throw new Error(`Expected a value for '${String(t)}' but got undefined.`);
217
+ }
218
+ return n;
219
+ } else {
220
+ let i = this;
221
+ const n = [];
222
+ for (; i._state && n.push(...i._state.entries()), i._parent != null; )
223
+ i = i._parent;
224
+ return new Map(n.reverse());
225
+ }
226
+ }
227
+ setState() {
228
+ if (this._state || (this._state = /* @__PURE__ */ new Map()), arguments.length === 2)
229
+ this._state.set(arguments[0], arguments[1]);
230
+ else if (et(arguments[0]) === "array")
231
+ for (const [t, e] of arguments[0])
232
+ e === void 0 ? this._state.delete(t) : this._state.set(t, e);
233
+ else
234
+ throw new Error("Invalid arguments.");
235
+ return this;
236
+ }
237
+ };
238
+ w = new WeakMap();
239
+ let f = S;
240
+ function wt(o, t) {
241
+ return new f(o, t);
242
+ }
243
+ class D extends Error {
244
+ }
245
+ const x = Symbol.for("dollaMarkupNode");
246
+ var W;
247
+ W = x;
248
+ class N {
249
+ constructor(t) {
250
+ c(this, W, !0);
251
+ c(this, "root");
252
+ this.root = t;
253
+ }
254
+ get isMounted() {
255
+ return this.root.parentNode != null;
256
+ }
257
+ mount(t, e) {
258
+ t.insertBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null);
259
+ }
260
+ unmount(t = !1) {
261
+ this.root.parentNode && !t && this.root.parentNode.removeChild(this.root);
262
+ }
263
+ }
264
+ var B;
265
+ B = x;
266
+ class M {
267
+ constructor(t, e) {
268
+ c(this, B, !0);
269
+ c(this, "root", document.createTextNode(""));
270
+ c(this, "children", []);
271
+ c(this, "context");
272
+ c(this, "$slot");
273
+ c(this, "unsubscribe");
274
+ this.context = t, this.$slot = e;
275
+ }
276
+ get isMounted() {
277
+ return this.root.parentNode != null;
278
+ }
279
+ mount(t, e) {
280
+ this.isMounted || (t.insertBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null), this.unsubscribe = p(() => {
281
+ try {
282
+ const s = this.$slot();
283
+ k(() => {
284
+ this.update(z(s) ? s : [s]);
285
+ });
286
+ } catch (s) {
287
+ this.context.error(s), this.context.crash(s);
288
+ }
289
+ }));
290
+ }
291
+ unmount(t = !1) {
292
+ var e, s;
293
+ (e = this.unsubscribe) == null || e.call(this), this.isMounted && (this.cleanup(t), (s = this.root.parentNode) == null || s.removeChild(this.root));
294
+ }
295
+ cleanup(t) {
296
+ for (const e of this.children)
297
+ e.unmount(t);
298
+ this.children = [];
299
+ }
300
+ update(t) {
301
+ var s;
302
+ if (this.cleanup(!1), t.length === 0 || !this.isMounted) return;
303
+ const e = A(this.context, t);
304
+ for (const i of e) {
305
+ const n = ((s = this.children.at(-1)) == null ? void 0 : s.root) || this.root;
306
+ i.mount(this.root.parentNode, n), this.children.push(i);
307
+ }
308
+ this.moveMarker();
309
+ }
310
+ /**
311
+ * Move marker node to end of children.
312
+ */
313
+ moveMarker() {
314
+ var s, i;
315
+ const t = this.root.parentNode, e = ((i = (s = this.children.at(-1)) == null ? void 0 : s.root) == null ? void 0 : i.nextSibling) ?? null;
316
+ "moveBefore" in t ? t.moveBefore(this.root, e) : t.insertBefore(this.root, e);
317
+ }
318
+ }
319
+ const H = Symbol("View");
320
+ var j;
321
+ j = x;
322
+ class Z {
323
+ constructor(t, e, s, i) {
324
+ c(this, j, !0);
325
+ c(this, "uniqueId", R());
326
+ c(this, "context");
327
+ c(this, "props");
328
+ c(this, "fn");
329
+ c(this, "node");
330
+ this.context = f.linked(t, e.name ?? "anonymous view", {
331
+ logger: {
332
+ tag: this.uniqueId,
333
+ tagName: "uid"
334
+ }
335
+ }), this.context.setState(H, this), this.props = { ...s, children: i }, this.fn = e;
336
+ }
337
+ /*===============================*\
338
+ || "Public" API ||
339
+ \*===============================*/
340
+ get root() {
341
+ var t;
342
+ return (t = this.node) == null ? void 0 : t.root;
343
+ }
344
+ get isMounted() {
345
+ return this.context.isMounted;
346
+ }
347
+ mount(t, e) {
348
+ const s = this.isMounted;
349
+ s || (this._initialize(), f.emit(m.WILL_MOUNT, this.context)), this.node && this.node.mount(t, e), s || f.emit(m.DID_MOUNT, this.context);
350
+ }
351
+ unmount(t = !1) {
352
+ f.emit(m.WILL_UNMOUNT, this.context), this.node && this.node.unmount(t), f.emit(m.DID_UNMOUNT, this.context);
353
+ }
354
+ /*===============================*\
355
+ || Internal ||
356
+ \*===============================*/
357
+ _initialize() {
358
+ const { context: t, props: e, fn: s } = this;
359
+ let i;
360
+ try {
361
+ i = s.call(t, e, t);
362
+ } catch (n) {
363
+ throw n instanceof Error && t.crash(n), n;
364
+ }
365
+ i == null || (i instanceof Node ? this.node = new N(i) : u(i) ? this.node = new M(t, i) : this.node = X(i, t));
366
+ }
367
+ }
368
+ const ct = (o) => /^on[A-Z]/.test(o), I = Symbol("HTML.isSVG");
369
+ var q;
370
+ q = x;
371
+ class at {
372
+ constructor(t, e, s, i) {
373
+ c(this, q, !0);
374
+ c(this, "root");
375
+ c(this, "context");
376
+ c(this, "props");
377
+ c(this, "children");
378
+ c(this, "childNodes", []);
379
+ c(this, "unsubscribers", []);
380
+ // Track the ref so we can nullify it on unmount.
381
+ c(this, "ref");
382
+ // Prevents 'onClickOutside' handlers from firing in the same cycle in which the element is connected.
383
+ c(this, "canClickAway", !1);
384
+ if (this.context = f.linked(t, e), e.toLowerCase() === "svg" && this.context.setState(I, !0), this.context.getState(I, !1) ? this.root = document.createElementNS("http://www.w3.org/2000/svg", e) : this.root = document.createElement(e), it() === "development") {
385
+ const n = this.context.getState(H, null);
386
+ n && (this.root.dataset.view = n.context.getName());
387
+ }
388
+ if (s.ref)
389
+ if (u(s.ref))
390
+ this.ref = s.ref, this.ref(this.root);
391
+ else
392
+ throw new Error("Expected ref to be a function. Got: " + s.ref);
393
+ if (s.mixin) {
394
+ const n = z(s.mixin) ? s.mixin : [s.mixin];
395
+ for (const r of n)
396
+ r(
397
+ this.root,
398
+ f.linked(this.context, () => ht(this), {
399
+ bindLifecycleToParent: !0,
400
+ logger: { tagName: r.name === "mixin" ? void 0 : "mixin", tag: r.name }
401
+ })
402
+ );
403
+ }
404
+ this.props = {
405
+ ...nt(["ref", "class", "className", "mixin"], s),
406
+ class: s.className ?? s.class
407
+ }, this.children = i;
408
+ }
409
+ get isMounted() {
410
+ return this.root.parentNode != null;
411
+ }
412
+ mount(t, e) {
413
+ if (t == null)
414
+ throw new Error(`HTML element requires a parent element as the first argument to connect. Got: ${t}`);
415
+ const s = this.isMounted;
416
+ if (!s) {
417
+ f.emit(m.WILL_MOUNT, this.context), this.children && this.children.length > 0 && (this.childNodes = A(this.context, this.children));
418
+ for (let i = 0; i < this.childNodes.length; i++) {
419
+ const n = this.childNodes[i], r = i > 0 ? this.childNodes[i - 1].root : void 0;
420
+ n.mount(this.root, r);
421
+ }
422
+ this.applyProps(this.root, this.props), this.props.style && this.applyStyles(this.root, this.props.style, this.unsubscribers), this.props.class && this.applyClasses(this.root, this.props.class, this.unsubscribers);
423
+ }
424
+ t.insertBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null), queueMicrotask(() => {
425
+ this.canClickAway = !0, s || f.emit(m.DID_MOUNT, this.context);
426
+ });
427
+ }
428
+ unmount(t = !1) {
429
+ var e;
430
+ if (this.isMounted) {
431
+ f.emit(m.WILL_UNMOUNT, this.context), t || (e = this.root.parentNode) == null || e.removeChild(this.root);
432
+ for (const s of this.childNodes)
433
+ s.unmount(!0);
434
+ this.canClickAway = !1;
435
+ for (const s of this.unsubscribers)
436
+ s();
437
+ this.unsubscribers.length = 0, this.ref && this.ref(void 0), f.emit(m.DID_UNMOUNT, this.context);
438
+ }
439
+ }
440
+ attachProp(t, e) {
441
+ u(t) ? this.unsubscribers.push(
442
+ p(() => {
443
+ try {
444
+ e(t());
445
+ } catch (s) {
446
+ this.context.error(s), this.context.crash(s);
447
+ }
448
+ })
449
+ ) : e(t);
450
+ }
451
+ applyProps(t, e) {
452
+ for (const s in e) {
453
+ const i = e[s];
454
+ if (s === "on:clickoutside" || s === "onClickOutside" || s === "onclickoutside") {
455
+ const n = (h) => {
456
+ this.canClickAway && !t.contains(h.target) && i(h);
457
+ }, r = { capture: !0 };
458
+ window.addEventListener("click", n, r), this.unsubscribers.push(() => {
459
+ window.removeEventListener("click", n, r);
460
+ });
461
+ } else if (u(i) && ct(s)) {
462
+ const n = s.slice(2).toLowerCase(), r = i;
463
+ t.addEventListener(n, r), this.unsubscribers.push(() => {
464
+ t.removeEventListener(n, r);
465
+ });
466
+ } else if (u(i) && ut.includes(s)) {
467
+ const n = s.substring(2);
468
+ t.addEventListener(n, i), this.unsubscribers.push(() => {
469
+ t.removeEventListener(n, i);
470
+ });
471
+ } else if (s.includes("-"))
472
+ this.attachProp(i, (n) => {
473
+ n == null ? t.removeAttribute(s) : t.setAttribute(s, String(n));
474
+ });
475
+ else if (!lt.includes(s))
476
+ if (this.context.getState(I, !1))
477
+ this.attachProp(i, (n) => {
478
+ n != null ? t.setAttribute(s, String(e[s])) : t.removeAttribute(s);
479
+ });
480
+ else
481
+ switch (s) {
482
+ case "contentEditable":
483
+ case "value":
484
+ this.attachProp(i, (n) => {
485
+ t[s] = String(n);
486
+ });
487
+ break;
488
+ case "for":
489
+ this.attachProp(i, (n) => {
490
+ t.htmlFor = n;
491
+ });
492
+ break;
493
+ case "title":
494
+ this.attachProp(i, (n) => {
495
+ n == null ? t.removeAttribute(s) : t.setAttribute(s, String(n));
496
+ });
497
+ case "checked":
498
+ this.attachProp(i, (n) => {
499
+ t.checked = n, n ? t.setAttribute("checked", "") : t.removeAttribute("checked");
500
+ });
501
+ break;
502
+ case "autocomplete":
503
+ case "autocapitalize":
504
+ this.attachProp(i, (n) => {
505
+ typeof n == "string" ? t[s] = n : n ? t[s] = "on" : t[s] = "off";
506
+ });
507
+ break;
508
+ default: {
509
+ if (s.startsWith("prop:")) {
510
+ const n = s.substring(5);
511
+ this.attachProp(i, (r) => {
512
+ t[n] = r;
513
+ });
514
+ } else if (s.startsWith("on:")) {
515
+ const n = s.substring(3);
516
+ let r;
517
+ u(i) ? (t.addEventListener(n, i), this.unsubscribers.push(() => {
518
+ t.removeEventListener(n, i);
519
+ })) : this.attachProp(i, (h) => {
520
+ !h && r ? t.removeEventListener(n, r) : h != null && (r && r !== h && t.removeEventListener(n, r), t.addEventListener(n, h)), r = h;
521
+ });
522
+ } else if (s.startsWith("attr:")) {
523
+ const n = s.substring(5).toLowerCase();
524
+ this.attachProp(i, (r) => {
525
+ r != null ? t.setAttribute(n, String(r)) : t.removeAttribute(n);
526
+ });
527
+ } else
528
+ this.attachProp(i, (n) => {
529
+ t[s] = n;
530
+ });
531
+ break;
532
+ }
533
+ }
534
+ }
535
+ }
536
+ applyStyles(t, e, s) {
537
+ const i = [];
538
+ if (u(e)) {
539
+ let n;
540
+ const r = p(() => {
541
+ u(n) && n(), t.style.cssText = "", n = this.applyStyles(t, g(e), s);
542
+ });
543
+ s.push(r), i.push(r);
544
+ } else {
545
+ const n = J(e);
546
+ for (const r in n) {
547
+ const { value: h, priority: b } = n[r];
548
+ if (u(h)) {
549
+ const a = p(() => {
550
+ g(h) ? t.style.setProperty(r, String(g(h)), b) : t.style.removeProperty(r);
551
+ });
552
+ s.push(a), i.push(a);
553
+ } else h != null && t.style.setProperty(r, String(h));
554
+ }
555
+ }
556
+ return function() {
557
+ for (const r of i)
558
+ r(), s.splice(s.indexOf(r), 1);
559
+ };
560
+ }
561
+ applyClasses(t, e, s) {
562
+ const i = [];
563
+ if (u(e)) {
564
+ let n;
565
+ const r = p(() => {
566
+ u(n) && n(), t.removeAttribute("class"), n = this.applyClasses(t, g(e), s);
567
+ });
568
+ s.push(r), i.push(r);
569
+ } else {
570
+ const n = K(e);
571
+ for (const r in n) {
572
+ const h = n[r];
573
+ if (u(h)) {
574
+ const b = p(() => {
575
+ g(h) ? t.classList.add(r) : t.classList.remove(r);
576
+ });
577
+ s.push(b), i.push(b);
578
+ } else h && t.classList.add(r);
579
+ }
580
+ }
581
+ return function() {
582
+ for (const r of i)
583
+ r(), s.splice(s.indexOf(r), 1);
584
+ };
585
+ }
586
+ }
587
+ function K(o) {
588
+ let t = {};
589
+ if (U(o)) {
590
+ const e = o.split(" ");
591
+ for (const s of e)
592
+ t[s] = !0;
593
+ } else F(o) ? Object.assign(t, o) : Array.isArray(o) && Array.from(o).filter(Boolean).forEach((e) => {
594
+ Object.assign(t, K(e));
595
+ });
596
+ return delete t.undefined, t;
597
+ }
598
+ function J(o) {
599
+ let t = {};
600
+ if (U(o)) {
601
+ const e = o.split(";").filter((s) => s.trim() !== "");
602
+ for (const s of e) {
603
+ const [i, n] = s.split(":"), r = {
604
+ value: n
605
+ };
606
+ n.includes("!important") ? (r.priority = "important", r.value = n.replace("!important", "").trim()) : r.value = n.trim(), t[$(i.trim())] = r;
607
+ }
608
+ }
609
+ if (F(o))
610
+ for (const e in o)
611
+ e.startsWith("--") ? t[e] = { value: o[e] } : t[$(e)] = { value: o[e] };
612
+ else Array.isArray(o) && Array.from(o).filter((e) => e != null).forEach((e) => {
613
+ Object.assign(t, J(e));
614
+ });
615
+ return t;
616
+ }
617
+ function ht(o) {
618
+ let t = o.root.tagName.toLowerCase();
619
+ if (o.root.id && (t += `#${o.root.id}`), o.root.classList.length > 0)
620
+ for (const e of o.root.classList.values())
621
+ t += `.${e}`;
622
+ return t;
623
+ }
624
+ function $(o) {
625
+ return o.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (t, e) => (e ? "-" : "") + t.toLowerCase());
626
+ }
627
+ const lt = ["ref", "children", "class", "style", "data", "mixin"], ut = ["onsubmit", "onclick", "ontransitionend"];
628
+ var V;
629
+ V = x;
630
+ class ft {
631
+ constructor(t, e, s) {
632
+ c(this, V, !0);
633
+ c(this, "context");
634
+ c(this, "content");
635
+ c(this, "parent");
636
+ c(this, "element");
637
+ this.context = t, this.content = e, this.parent = s;
638
+ }
639
+ get isMounted() {
640
+ return this.element ? this.element.isMounted : !1;
641
+ }
642
+ mount(t, e) {
643
+ this.element = X(this.content, this.context), this.element.mount(this.parent);
644
+ }
645
+ unmount(t = !1) {
646
+ var e;
647
+ (e = this.element) != null && e.isMounted && this.element.unmount(!1);
648
+ }
649
+ }
650
+ var G;
651
+ G = x;
652
+ class dt {
653
+ constructor(t, e, s, i) {
654
+ c(this, G, !0);
655
+ c(this, "root", document.createTextNode(""));
656
+ c(this, "context");
657
+ c(this, "items");
658
+ c(this, "key");
659
+ c(this, "render");
660
+ c(this, "unsubscribe", null);
661
+ c(this, "connectedItems", []);
662
+ this.context = t, this.items = e, this.key = s, this.render = i;
663
+ }
664
+ get isMounted() {
665
+ return this.root.parentNode != null;
666
+ }
667
+ mount(t, e) {
668
+ this.isMounted || (t.insertBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null), this.unsubscribe = p(() => {
669
+ let s = this.items();
670
+ s == null && (s = [], this.context.warn("repeat() received empty value for items", s)), k(() => {
671
+ this._update(Array.from(s));
672
+ });
673
+ }));
674
+ }
675
+ unmount(t = !1) {
676
+ var e;
677
+ this.unsubscribe && (this.unsubscribe(), this.unsubscribe = null), !t && this.isMounted && ((e = this.root.parentNode) == null || e.removeChild(this.root)), this._cleanup(t);
678
+ }
679
+ _cleanup(t) {
680
+ for (const e of this.connectedItems)
681
+ e.node.unmount(t);
682
+ this.connectedItems = [];
683
+ }
684
+ _update(t) {
685
+ var r, h, b;
686
+ if (t.length === 0 || !this.isMounted)
687
+ return this._cleanup(!1);
688
+ const e = [];
689
+ let s = 0;
690
+ for (const a of t)
691
+ e.push({
692
+ key: this.key(a, s),
693
+ value: a,
694
+ index: s++
695
+ });
696
+ const i = [];
697
+ for (const a of this.connectedItems)
698
+ e.find((y) => y.key === a.key) || a.node.unmount(!1);
699
+ for (const a of e) {
700
+ const _ = this.connectedItems.find((y) => y.key === a.key);
701
+ if (_)
702
+ _.item(a.value), _.index(a.index), i[a.index] = _;
703
+ else {
704
+ const y = O(a.value, { equals: ot }), E = O(a.index);
705
+ i[a.index] = {
706
+ key: a.key,
707
+ item: y,
708
+ index: E,
709
+ node: new Z(this.context, pt, {
710
+ item: () => y(),
711
+ index: () => E(),
712
+ renderFn: this.render
713
+ })
714
+ };
715
+ }
716
+ }
717
+ for (let a = 0; a < i.length; a++) {
718
+ const _ = i[a], y = ((r = i[a - 1]) == null ? void 0 : r.node.root) ?? this.root;
719
+ _.node.mount(this.root.parentNode, y);
720
+ }
721
+ this.connectedItems = i;
722
+ const n = ((h = i.at(-1)) == null ? void 0 : h.node.root) ?? this.root;
723
+ (b = this.root.parentNode) == null || b.insertBefore(this.root, n.nextSibling);
724
+ }
725
+ }
726
+ function pt(o, t) {
727
+ return t.setName("@RepeatItem"), o.renderFn.call(t, o.item, o.index, t);
728
+ }
729
+ class Q {
730
+ constructor(t, e, ...s) {
731
+ /**
732
+ * In the case of a view, type will be the View function itself. It can also hold an identifier for special nodes like "$cond", "$repeat", etc.
733
+ * DOM nodes can be created by name, such as HTML elements like "div", "ul" or "span", SVG elements like ""
734
+ */
735
+ c(this, "type");
736
+ /**
737
+ * Data that will be passed to a new MarkupNode instance when it is constructed.
738
+ */
739
+ c(this, "props");
740
+ /**
741
+ *
742
+ */
743
+ c(this, "children");
744
+ this.type = t, this.props = e, this.children = s;
745
+ }
746
+ }
747
+ function mt(o) {
748
+ return (o == null ? void 0 : o[x]) === !0;
749
+ }
750
+ function T(o, t, ...e) {
751
+ return new Q(o, t, ...e);
752
+ }
753
+ function yt(o, t, e) {
754
+ return T("$dynamic", {
755
+ source: O(() => {
756
+ const s = g(o);
757
+ return s && t ? t : !s && e ? e : null;
758
+ })
759
+ });
760
+ }
761
+ function xt(o, t, e) {
762
+ return yt(o, e, t);
763
+ }
764
+ function Nt(o, t, e) {
765
+ return T("$repeat", { items: () => g(o), key: t, render: e });
766
+ }
767
+ function kt(o, t) {
768
+ return T("$portal", { parent: o, content: t });
769
+ }
770
+ function X(o, t = new f("$")) {
771
+ const e = A(t, [o]);
772
+ return e.length === 1 ? e[0] : new M(t, () => e);
773
+ }
774
+ function A(o, ...t) {
775
+ const e = t.flat(1 / 0), s = [];
776
+ for (const i of e)
777
+ if (!(i == null || i === !1)) {
778
+ if (i instanceof Node) {
779
+ s.push(new N(i));
780
+ continue;
781
+ }
782
+ if (i instanceof Q)
783
+ if (u(i.type)) {
784
+ s.push(new Z(o, i.type, i.props, i.children));
785
+ continue;
786
+ } else if (U(i.type))
787
+ switch (i.type) {
788
+ case "$dom": {
789
+ const n = i.props;
790
+ s.push(new N(n.value));
791
+ continue;
792
+ }
793
+ case "$text": {
794
+ const n = i.props;
795
+ s.push(new N(document.createTextNode(String(n.value))));
796
+ continue;
797
+ }
798
+ case "$repeat": {
799
+ const n = i.props;
800
+ s.push(new dt(o, n.items, n.key, n.render));
801
+ continue;
802
+ }
803
+ case "$dynamic": {
804
+ const n = i.props;
805
+ s.push(new M(o, n.source));
806
+ continue;
807
+ }
808
+ case "$portal": {
809
+ const n = i.props;
810
+ s.push(new ft(o, n.content, n.parent));
811
+ continue;
812
+ }
813
+ default:
814
+ s.push(new at(o, i.type, i.props ?? {}, i.children));
815
+ continue;
816
+ }
817
+ else
818
+ throw new TypeError(`Expected a string or view function. Got: ${i.type}`);
819
+ if (mt(i)) {
820
+ s.push(i);
821
+ continue;
822
+ }
823
+ if (u(i)) {
824
+ s.push(new M(o, i));
825
+ continue;
826
+ }
827
+ s.push(new N(document.createTextNode(String(i))));
828
+ }
829
+ return s;
830
+ }
831
+ export {
832
+ f as C,
833
+ M as D,
834
+ m as L,
835
+ Z as V,
836
+ Nt as a,
837
+ wt as c,
838
+ T as m,
839
+ kt as p,
840
+ X as r,
841
+ xt as u,
842
+ yt as w
843
+ };
844
+ //# sourceMappingURL=markup-DS7yYBga.js.map