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

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 (50) hide show
  1. package/README.md +1 -12
  2. package/dist/core/context.d.ts +80 -54
  3. package/dist/core/index.d.ts +8 -8
  4. package/dist/core/logger.d.ts +1 -1
  5. package/dist/core/markup.d.ts +10 -10
  6. package/dist/core/mount.d.ts +11 -6
  7. package/dist/core/nodes/dynamic.d.ts +3 -3
  8. package/dist/core/nodes/html.d.ts +5 -5
  9. package/dist/core/nodes/outlet.d.ts +3 -4
  10. package/dist/core/nodes/portal.d.ts +2 -2
  11. package/dist/core/nodes/repeat.d.ts +6 -6
  12. package/dist/core/nodes/view.d.ts +13 -81
  13. package/dist/core/symbols.d.ts +0 -2
  14. package/dist/core/views/fragment.d.ts +2 -2
  15. package/dist/fragment-VXM-P2tT.js +7 -0
  16. package/dist/fragment-VXM-P2tT.js.map +1 -0
  17. package/dist/http.js +1 -1
  18. package/dist/i18n.js +14 -14
  19. package/dist/i18n.js.map +1 -1
  20. package/dist/index.js +45 -59
  21. package/dist/index.js.map +1 -1
  22. package/dist/jsx-dev-runtime.js +8 -8
  23. package/dist/jsx-dev-runtime.js.map +1 -1
  24. package/dist/jsx-runtime.js +9 -9
  25. package/dist/jsx-runtime.js.map +1 -1
  26. package/dist/{logger-CBfhf3fA.js → logger-CXdzxt1e.js} +74 -73
  27. package/dist/{logger-CBfhf3fA.js.map → logger-CXdzxt1e.js.map} +1 -1
  28. package/dist/markup-yTuFdC0t.js +923 -0
  29. package/dist/markup-yTuFdC0t.js.map +1 -0
  30. package/dist/router/router.d.ts +9 -6
  31. package/dist/router-B-rtBG7i.js +488 -0
  32. package/dist/router-B-rtBG7i.js.map +1 -0
  33. package/dist/router.js +1 -1
  34. package/dist/router.js.map +1 -1
  35. package/dist/{typeChecking-EAVNeFyB.js → typeChecking-lgllKIVq.js} +5 -5
  36. package/dist/{typeChecking-EAVNeFyB.js.map → typeChecking-lgllKIVq.js.map} +1 -1
  37. package/dist/types.d.ts +1 -1
  38. package/docs/mixins.md +1 -1
  39. package/docs/ref.md +93 -0
  40. package/notes/scratch.md +24 -0
  41. package/package.json +2 -2
  42. package/dist/core/mixin.d.ts +0 -62
  43. package/dist/core/store.d.ts +0 -57
  44. package/dist/core/views/passthrough.d.ts +0 -5
  45. package/dist/fragment-CmWsN-4Y.js +0 -8
  46. package/dist/fragment-CmWsN-4Y.js.map +0 -1
  47. package/dist/router-BoJac1lD.js +0 -482
  48. package/dist/router-BoJac1lD.js.map +0 -1
  49. package/dist/view-BKpHFpWG.js +0 -1044
  50. package/dist/view-BKpHFpWG.js.map +0 -1
@@ -1,1044 +0,0 @@
1
- var ee = Object.defineProperty;
2
- var te = (i, e, t) => e in i ? ee(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var r = (i, e, t) => te(i, typeof e != "symbol" ? e + "" : e, t);
4
- import { t as R, g as f, c as h, i as C, b as $, h as se, j as z } from "./typeChecking-EAVNeFyB.js";
5
- import { e as a, p as w, g as y, j as A, $ as x, f as P, b as ne, k as ie, d as oe } from "./logger-CBfhf3fA.js";
6
- const W = /* @__PURE__ */ new Map(), S = {
7
- stores: W
8
- }, p = Symbol.for("DollaMarkupElement");
9
- var F;
10
- F = p;
11
- class O {
12
- constructor(e) {
13
- r(this, F, !0);
14
- r(this, "domNode");
15
- this.domNode = e;
16
- }
17
- get isMounted() {
18
- return this.domNode.parentNode != null;
19
- }
20
- mount(e, t) {
21
- e.insertBefore(this.domNode, (t == null ? void 0 : t.nextSibling) ?? null);
22
- }
23
- unmount(e = !1) {
24
- this.domNode.parentNode && !e && this.domNode.parentNode.removeChild(this.domNode);
25
- }
26
- }
27
- var T;
28
- T = p;
29
- class re {
30
- constructor(e) {
31
- r(this, T, !0);
32
- r(this, "domNode", document.createTextNode(""));
33
- r(this, "children", []);
34
- r(this, "elementContext");
35
- r(this, "source");
36
- r(this, "unsubscribe");
37
- this.source = e.source, this.elementContext = e.elementContext;
38
- }
39
- get isMounted() {
40
- return this.domNode.parentNode != null;
41
- }
42
- mount(e, t) {
43
- this.isMounted || (e.insertBefore(this.domNode, (t == null ? void 0 : t.nextSibling) ?? null), this.unsubscribe = a(() => {
44
- try {
45
- const s = this.source();
46
- if (!Y(s))
47
- throw console.error(s), new TypeError(
48
- `Dynamic received invalid value to render. Got type: ${R(s)}, value: ${s}`
49
- );
50
- w(() => {
51
- this.update(f(s) ? s : [s]);
52
- });
53
- } catch (s) {
54
- const n = this.elementContext.view.logger;
55
- n.error(s), n.crash(s);
56
- }
57
- }));
58
- }
59
- unmount(e = !1) {
60
- var t, s;
61
- (t = this.unsubscribe) == null || t.call(this), this.isMounted && (this.cleanup(e), (s = this.domNode.parentNode) == null || s.removeChild(this.domNode));
62
- }
63
- cleanup(e) {
64
- for (const t of this.children)
65
- t.unmount(e);
66
- this.children = [];
67
- }
68
- update(e) {
69
- var o, c, u;
70
- if (this.cleanup(!1), e == null || e.length === 0 || !this.isMounted)
71
- return;
72
- const t = e.flatMap((d) => Q(d) ? d : N(this.elementContext, M(d)));
73
- for (const d of t) {
74
- const l = ((o = this.children.at(-1)) == null ? void 0 : o.domNode) || this.domNode;
75
- d.mount(this.domNode.parentNode, l), this.children.push(d);
76
- }
77
- const s = this.domNode.parentNode, n = ((u = (c = this.children.at(-1)) == null ? void 0 : c.domNode) == null ? void 0 : u.nextSibling) ?? null;
78
- "moveBefore" in s ? s.moveBefore(this.domNode, n) : s.insertBefore(this.domNode, n);
79
- }
80
- }
81
- var j;
82
- j = p;
83
- class Z {
84
- constructor(e) {
85
- r(this, j, !0);
86
- r(this, "domNode", document.createTextNode(""));
87
- r(this, "isMounted", !1);
88
- r(this, "source");
89
- r(this, "elements", []);
90
- r(this, "unsubscribe");
91
- this.source = e;
92
- }
93
- mount(e, t) {
94
- this.isMounted || (this.isMounted = !0, e.insertBefore(this.domNode, (t == null ? void 0 : t.nextSibling) ?? null), h(this.source) ? this.unsubscribe = a(() => {
95
- const s = y(this.source);
96
- w(() => {
97
- this.update(s);
98
- });
99
- }) : this.update(this.elements));
100
- }
101
- unmount(e = !1) {
102
- this.unsubscribe && (this.unsubscribe(), this.unsubscribe = void 0), this.isMounted && (this.cleanup(e), this.isMounted = !1);
103
- }
104
- cleanup(e) {
105
- for (const t of this.elements)
106
- t.unmount(e);
107
- this.elements = [];
108
- }
109
- update(e) {
110
- var t, s;
111
- if (this.cleanup(!1), e.length > 0) {
112
- for (let n = 0; n < e.length; n++) {
113
- const o = e[n], c = n > 0 ? this.elements[n - 1] : void 0;
114
- o.mount(this.domNode.parentElement, c == null ? void 0 : c.domNode), this.elements.push(o);
115
- }
116
- (s = this.domNode.parentNode) == null || s.insertBefore(this.domNode, ((t = this.elements.at(-1)) == null ? void 0 : t.domNode) ?? null);
117
- }
118
- }
119
- }
120
- let ce = class {
121
- constructor(e) {
122
- r(this, "store");
123
- this.store = e;
124
- const t = Object.getOwnPropertyDescriptors(this.store.logger);
125
- for (const s in t)
126
- s !== "setName" && Object.defineProperty(this, s, t[s]);
127
- }
128
- get isMounted() {
129
- return this.store.isMounted;
130
- }
131
- get name() {
132
- return w(this.store.name) || this.store.id;
133
- }
134
- set name(e) {
135
- this.store.name(e);
136
- }
137
- get(e) {
138
- if (h(e)) {
139
- let t = this.store.elementContext, s;
140
- for (; s = t.stores.get(e), s == null && t.parent != null; )
141
- t = t.parent;
142
- if (s == null)
143
- throw new g(`Store '${e.name}' is not provided on this context.`);
144
- return s.value;
145
- } else
146
- throw new g("Invalid store.");
147
- }
148
- onMount(e) {
149
- this.store.lifecycleListeners.mount.push(e);
150
- }
151
- onUnmount(e) {
152
- this.store.lifecycleListeners.unmount.push(e);
153
- }
154
- effect(e) {
155
- const t = this.store, s = () => {
156
- try {
157
- return e();
158
- } catch (n) {
159
- n instanceof Error ? this.crash(n) : typeof n == "string" ? this.crash(new Error(n)) : (this.error(n), this.crash(new Error("Unknown error thrown in effect callback")));
160
- }
161
- };
162
- if (t.isMounted) {
163
- const n = a(s);
164
- return t.lifecycleListeners.unmount.push(n), n;
165
- } else {
166
- let n, o = !1;
167
- return t.lifecycleListeners.mount.push(() => {
168
- o || (n = a(s), t.lifecycleListeners.unmount.push(n));
169
- }), () => {
170
- n != null && (o = !0, n());
171
- };
172
- }
173
- }
174
- };
175
- class H {
176
- constructor(e, t) {
177
- r(this, "fn");
178
- r(this, "_options");
179
- /**
180
- * Value is guaranteed to be set after `attach` is called.
181
- */
182
- r(this, "value");
183
- r(this, "isMounted", !1);
184
- r(this, "elementContext");
185
- r(this, "lifecycleListeners", { mount: [], unmount: [] });
186
- r(this, "logger");
187
- r(this, "id", A());
188
- r(this, "name", x(""));
189
- this.fn = e, this.name(e.name), this._options = t;
190
- }
191
- /**
192
- * Attaches this Store to the elementContext.
193
- * Returns false if there was already an instance attached, and true otherwise.
194
- */
195
- attach(e) {
196
- if (e.stores.has(this.fn))
197
- return !1;
198
- this.elementContext = e, this.logger = P(this.name, { tag: this.id, tagName: "uid" });
199
- const t = new ce(this);
200
- try {
201
- this.value = this.fn.call(t, this._options, t);
202
- } catch (s) {
203
- throw this.logger.crash(s), s;
204
- }
205
- return e.stores.set(this.fn, this), !0;
206
- }
207
- handleMount() {
208
- this.isMounted = !0;
209
- for (const e of this.lifecycleListeners.mount)
210
- e();
211
- this.lifecycleListeners.mount.length = 0;
212
- }
213
- handleUnmount() {
214
- this.isMounted = !1;
215
- for (const e of this.lifecycleListeners.unmount)
216
- e();
217
- this.lifecycleListeners.unmount.length = 0;
218
- }
219
- }
220
- class g extends Error {
221
- }
222
- const Ee = Object.freeze({
223
- provide(i, e) {
224
- const t = new H(i, e);
225
- if (t.attach(S))
226
- return t.value;
227
- {
228
- let n = i.name ? `'${i.name}'` : "this store";
229
- return console.warn(`An instance of ${n} is already attached.`), this.get(i);
230
- }
231
- },
232
- get(i) {
233
- if (h(i)) {
234
- const e = S.stores.get(i);
235
- if (e == null) {
236
- let t = i.name ? `'${i.name}'` : "this store";
237
- throw new g(`No instance of ${t} is provided.`);
238
- } else
239
- return e.value;
240
- } else
241
- throw new g("Invalid store.");
242
- }
243
- });
244
- function ue(i) {
245
- let e = i.domNode.tagName.toLowerCase();
246
- if (i.domNode.id && (e += `#${i.domNode.id}`), i.domNode.classList.length > 0)
247
- for (const t of i.domNode.classList.values())
248
- e += `.${t}`;
249
- return e;
250
- }
251
- let le = class {
252
- constructor(e, t) {
253
- r(this, "html");
254
- r(this, "controller");
255
- r(this, "uid", A());
256
- this.html = e, this.controller = t;
257
- const s = P(() => ue(e), { tag: "mixin" }), n = Object.getOwnPropertyDescriptors(s);
258
- for (const o in n)
259
- Object.defineProperty(this, o, n[o]);
260
- }
261
- get isMounted() {
262
- return this.html.isMounted;
263
- }
264
- get(e) {
265
- if (h(e)) {
266
- let t = this.html.elementContext, s;
267
- for (; s = t.stores.get(e), s == null && t.parent != null; )
268
- t = t.parent;
269
- if (s == null)
270
- throw new g(`Store '${e.name}' is not provided on this context.`);
271
- return s.value;
272
- } else
273
- throw new g("Invalid store.");
274
- }
275
- beforeMount(e) {
276
- this.controller.lifecycleListeners.beforeMount.push(e);
277
- }
278
- onMount(e) {
279
- this.controller.lifecycleListeners.mount.push(e);
280
- }
281
- beforeUnmount(e) {
282
- this.controller.lifecycleListeners.beforeUnmount.push(e);
283
- }
284
- onUnmount(e) {
285
- this.controller.lifecycleListeners.unmount.push(e);
286
- }
287
- effect(e) {
288
- const t = () => {
289
- try {
290
- return e();
291
- } catch (s) {
292
- 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"));
293
- }
294
- };
295
- if (this.html.isMounted) {
296
- const s = a(t);
297
- return this.controller.lifecycleListeners.unmount.push(s), s;
298
- } else {
299
- let s, n = !1;
300
- return this.controller.lifecycleListeners.mount.push(() => {
301
- n || (s = a(t), this.controller.lifecycleListeners.unmount.push(s));
302
- }), () => {
303
- s != null && (n = !0, s());
304
- };
305
- }
306
- }
307
- };
308
- class he {
309
- constructor(e, t) {
310
- r(this, "context");
311
- r(this, "lifecycleListeners", {
312
- beforeMount: [],
313
- mount: [],
314
- beforeUnmount: [],
315
- unmount: []
316
- });
317
- this.context = new le(e, this);
318
- for (const s of t)
319
- s(e.domNode, this.context);
320
- }
321
- beforeMount() {
322
- try {
323
- for (const e of this.lifecycleListeners.beforeMount)
324
- e();
325
- } catch (e) {
326
- this.context.crash(e);
327
- }
328
- }
329
- onMount() {
330
- try {
331
- for (const e of this.lifecycleListeners.mount)
332
- e();
333
- } catch (e) {
334
- this.context.crash(e);
335
- }
336
- }
337
- beforeUnmount() {
338
- try {
339
- for (const e of this.lifecycleListeners.beforeUnmount)
340
- e();
341
- } catch (e) {
342
- this.context.crash(e);
343
- }
344
- }
345
- onUnmount() {
346
- try {
347
- for (const e of this.lifecycleListeners.unmount)
348
- e();
349
- } catch (e) {
350
- this.context.crash(e);
351
- }
352
- }
353
- }
354
- const ae = (i) => /^on[A-Z]/.test(i);
355
- var B;
356
- B = p;
357
- class de {
358
- constructor({ tag: e, props: t, children: s, elementContext: n }) {
359
- r(this, B, !0);
360
- r(this, "domNode");
361
- r(this, "elementContext");
362
- r(this, "props");
363
- r(this, "childMarkup", []);
364
- r(this, "children", []);
365
- r(this, "unsubscribers", []);
366
- r(this, "mixin");
367
- r(this, "logger");
368
- // Track the ref so we can nullify it on unmount.
369
- r(this, "ref");
370
- // Prevents 'onClickOutside' handlers from firing in the same cycle in which the element is connected.
371
- r(this, "canClickAway", !1);
372
- if (e.toLowerCase() === "svg" && (n = {
373
- ...n,
374
- isSVG: !0
375
- }), this.logger = n.view.logger, n.isSVG ? this.domNode = document.createElementNS("http://www.w3.org/2000/svg", e) : this.domNode = document.createElement(e), ne() === "development" && w(n.view.name) && (this.domNode.dataset.view = w(n.view.name)), t.ref)
376
- if (h(t.ref))
377
- this.ref = t.ref, this.ref(this.domNode);
378
- else
379
- throw new Error("Expected ref to be a function. Got: " + t.ref);
380
- t.mixin && (this.mixin = new he(this, f(t.mixin) ? t.mixin : [t.mixin])), this.props = {
381
- ...ie(["ref", "class", "className", "mixin"], t),
382
- class: t.className ?? t.class
383
- }, s && (this.childMarkup = M(s)), this.elementContext = n;
384
- }
385
- get isMounted() {
386
- return this.domNode.parentNode != null;
387
- }
388
- mount(e, t) {
389
- if (e == null)
390
- throw new Error(`HTML element requires a parent element as the first argument to connect. Got: ${e}`);
391
- const s = this.isMounted;
392
- if (!s) {
393
- this.mixin && this.mixin.beforeMount(), this.childMarkup.length > 0 && (this.children = N(this.elementContext, this.childMarkup));
394
- for (let n = 0; n < this.children.length; n++) {
395
- const o = this.children[n], c = n > 0 ? this.children[n - 1].domNode : void 0;
396
- o.mount(this.domNode, c);
397
- }
398
- this.applyProps(this.domNode, this.props), this.props.style && this.applyStyles(this.domNode, this.props.style, this.unsubscribers), this.props.class && this.applyClasses(this.domNode, this.props.class, this.unsubscribers);
399
- }
400
- e.insertBefore(this.domNode, (t == null ? void 0 : t.nextSibling) ?? null), queueMicrotask(() => {
401
- this.canClickAway = !0, this.mixin && !s && this.mixin.onMount();
402
- });
403
- }
404
- unmount(e = !1) {
405
- var t;
406
- if (this.isMounted) {
407
- this.mixin && this.mixin.beforeUnmount(), e || (t = this.domNode.parentNode) == null || t.removeChild(this.domNode);
408
- for (const s of this.children)
409
- s.unmount(!0);
410
- this.canClickAway = !1;
411
- for (const s of this.unsubscribers)
412
- s();
413
- this.unsubscribers.length = 0, this.ref && this.ref(void 0), this.mixin && this.mixin.onUnmount();
414
- }
415
- }
416
- attachProp(e, t) {
417
- h(e) ? this.unsubscribers.push(
418
- a(() => {
419
- try {
420
- t(e());
421
- } catch (s) {
422
- this.logger.error(s), this.logger.crash(s);
423
- }
424
- })
425
- ) : t(e);
426
- }
427
- applyProps(e, t) {
428
- for (const s in t) {
429
- const n = t[s];
430
- if (s === "on:clickoutside" || s === "onClickOutside" || s === "onclickoutside") {
431
- const o = (u) => {
432
- this.canClickAway && !e.contains(u.target) && n(u);
433
- }, c = { capture: !0 };
434
- window.addEventListener("click", o, c), this.unsubscribers.push(() => {
435
- window.removeEventListener("click", o, c);
436
- });
437
- } else if (h(n) && ae(s)) {
438
- const o = s.slice(2).toLowerCase(), c = n;
439
- e.addEventListener(o, c), this.unsubscribers.push(() => {
440
- e.removeEventListener(o, c);
441
- });
442
- } else if (h(n) && me.includes(s)) {
443
- const o = s.substring(2);
444
- e.addEventListener(o, n), this.unsubscribers.push(() => {
445
- e.removeEventListener(o, n);
446
- });
447
- } else if (s.includes("-"))
448
- this.attachProp(n, (o) => {
449
- o == null ? e.removeAttribute(s) : e.setAttribute(s, String(o));
450
- });
451
- else if (!fe.includes(s))
452
- if (this.elementContext.isSVG)
453
- this.attachProp(n, (o) => {
454
- o != null ? e.setAttribute(s, String(t[s])) : e.removeAttribute(s);
455
- });
456
- else
457
- switch (s) {
458
- case "contentEditable":
459
- case "value":
460
- this.attachProp(n, (o) => {
461
- e[s] = String(o);
462
- });
463
- break;
464
- case "for":
465
- this.attachProp(n, (o) => {
466
- e.htmlFor = o;
467
- });
468
- break;
469
- case "title":
470
- this.attachProp(n, (o) => {
471
- o == null ? e.removeAttribute(s) : e.setAttribute(s, String(o));
472
- });
473
- case "checked":
474
- this.attachProp(n, (o) => {
475
- e.checked = o, o ? e.setAttribute("checked", "") : e.removeAttribute("checked");
476
- });
477
- break;
478
- case "autocomplete":
479
- case "autocapitalize":
480
- this.attachProp(n, (o) => {
481
- typeof o == "string" ? e[s] = o : o ? e[s] = "on" : e[s] = "off";
482
- });
483
- break;
484
- default: {
485
- if (s.startsWith("prop:")) {
486
- const o = s.substring(5);
487
- this.attachProp(n, (c) => {
488
- e[o] = c;
489
- });
490
- } else if (s.startsWith("on:")) {
491
- const o = s.substring(3);
492
- let c;
493
- h(n) ? (e.addEventListener(o, n), this.unsubscribers.push(() => {
494
- e.removeEventListener(o, n);
495
- })) : this.attachProp(n, (u) => {
496
- !u && c ? e.removeEventListener(o, c) : u != null && (c && c !== u && e.removeEventListener(o, c), e.addEventListener(o, u)), c = u;
497
- });
498
- } else if (s.startsWith("attr:")) {
499
- const o = s.substring(5).toLowerCase();
500
- this.attachProp(n, (c) => {
501
- c != null ? e.setAttribute(o, String(c)) : e.removeAttribute(o);
502
- });
503
- } else
504
- this.attachProp(n, (o) => {
505
- e[s] = o;
506
- });
507
- break;
508
- }
509
- }
510
- }
511
- }
512
- applyStyles(e, t, s) {
513
- const n = [];
514
- if (h(t)) {
515
- let o;
516
- const c = a(() => {
517
- h(o) && o(), e.style.cssText = "", o = this.applyStyles(e, y(t), s);
518
- });
519
- s.push(c), n.push(c);
520
- } else {
521
- const o = J(t);
522
- for (const c in o) {
523
- const { value: u, priority: d } = o[c];
524
- if (h(u)) {
525
- const l = a(() => {
526
- y(u) ? e.style.setProperty(c, String(y(u)), d) : e.style.removeProperty(c);
527
- });
528
- s.push(l), n.push(l);
529
- } else u != null && e.style.setProperty(c, String(u));
530
- }
531
- }
532
- return function() {
533
- for (const c of n)
534
- c(), s.splice(s.indexOf(c), 1);
535
- };
536
- }
537
- applyClasses(e, t, s) {
538
- const n = [];
539
- if (h(t)) {
540
- let o;
541
- const c = a(() => {
542
- h(o) && o(), e.removeAttribute("class"), o = this.applyClasses(e, y(t), s);
543
- });
544
- s.push(c), n.push(c);
545
- } else {
546
- const o = K(t);
547
- for (const c in o) {
548
- const u = o[c];
549
- if (h(u)) {
550
- const d = a(() => {
551
- y(u) ? e.classList.add(c) : e.classList.remove(c);
552
- });
553
- s.push(d), n.push(d);
554
- } else u && e.classList.add(c);
555
- }
556
- }
557
- return function() {
558
- for (const c of n)
559
- c(), s.splice(s.indexOf(c), 1);
560
- };
561
- }
562
- }
563
- function K(i) {
564
- let e = {};
565
- if (C(i)) {
566
- const t = i.split(" ");
567
- for (const s of t)
568
- e[s] = !0;
569
- } else $(i) ? Object.assign(e, i) : Array.isArray(i) && Array.from(i).filter(Boolean).forEach((t) => {
570
- Object.assign(e, K(t));
571
- });
572
- return delete e.undefined, e;
573
- }
574
- function J(i) {
575
- let e = {};
576
- if (C(i)) {
577
- const t = i.split(";").filter((s) => s.trim() !== "");
578
- for (const s of t) {
579
- const [n, o] = s.split(":"), c = {
580
- value: o
581
- };
582
- o.includes("!important") ? (c.priority = "important", c.value = o.replace("!important", "").trim()) : c.value = o.trim(), e[_(n.trim())] = c;
583
- }
584
- }
585
- if ($(i))
586
- for (const t in i)
587
- t.startsWith("--") ? e[t] = { value: i[t] } : e[_(t)] = { value: i[t] };
588
- else Array.isArray(i) && Array.from(i).filter((t) => t != null).forEach((t) => {
589
- Object.assign(e, J(t));
590
- });
591
- return e;
592
- }
593
- function _(i) {
594
- return i.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (e, t) => (t ? "-" : "") + e.toLowerCase());
595
- }
596
- const fe = ["ref", "children", "class", "style", "data", "mixin"], me = ["onsubmit", "onclick", "ontransitionend"];
597
- var V;
598
- V = p;
599
- class pe {
600
- constructor(e) {
601
- r(this, V, !0);
602
- r(this, "domNode", document.createTextNode(""));
603
- r(this, "isMounted", !1);
604
- r(this, "view");
605
- r(this, "mountedView");
606
- r(this, "unsubscribe");
607
- this.view = e;
608
- }
609
- mount(e, t) {
610
- this.isMounted || (this.isMounted = !0, e.insertBefore(this.domNode, (t == null ? void 0 : t.nextSibling) ?? null), this.unsubscribe = a(() => {
611
- const s = this.view();
612
- w(() => {
613
- this.update(s);
614
- });
615
- }));
616
- }
617
- unmount(e = !1) {
618
- this.unsubscribe && (this.unsubscribe(), this.unsubscribe = void 0), this.isMounted && (this.cleanup(e), this.isMounted = !1);
619
- }
620
- cleanup(e) {
621
- this.mountedView && this.mountedView.unmount(e), this.mountedView = void 0;
622
- }
623
- update(e) {
624
- this.cleanup(!1), e && (e.mount(this.domNode.parentElement, this.domNode), this.mountedView = e);
625
- }
626
- }
627
- var q;
628
- q = p;
629
- class be {
630
- constructor(e) {
631
- r(this, q, !0);
632
- r(this, "config");
633
- r(this, "element");
634
- this.config = e;
635
- }
636
- get isMounted() {
637
- return this.element ? this.element.isMounted : !1;
638
- }
639
- mount(e, t) {
640
- const { content: s, parent: n } = this.config;
641
- Q(s) ? this.element = s : this.element = k(N(this.config.elementContext, M(s))), this.element.mount(n);
642
- }
643
- unmount(e = !1) {
644
- var t;
645
- (t = this.element) != null && t.isMounted && this.element.unmount(!1);
646
- }
647
- }
648
- var D;
649
- D = p;
650
- class ye {
651
- constructor({ elementContext: e, items: t, renderFn: s, keyFn: n }) {
652
- r(this, D, !0);
653
- r(this, "domNode", document.createTextNode(""));
654
- r(this, "items");
655
- r(this, "unsubscribe", null);
656
- r(this, "connectedItems", []);
657
- r(this, "elementContext");
658
- r(this, "renderFn");
659
- r(this, "keyFn");
660
- this.elementContext = e, this.items = t, this.renderFn = s, this.keyFn = n;
661
- }
662
- get isMounted() {
663
- return this.domNode.parentNode != null;
664
- }
665
- mount(e, t) {
666
- this.isMounted || (e.insertBefore(this.domNode, (t == null ? void 0 : t.nextSibling) ?? null), this.unsubscribe = a(() => {
667
- let s = this.items();
668
- s == null && (s = [], console.log("repeat received empty value", s, this)), w(() => {
669
- this._update(Array.from(s));
670
- });
671
- }));
672
- }
673
- unmount(e = !1) {
674
- var t;
675
- this.unsubscribe && (this.unsubscribe(), this.unsubscribe = null), !e && this.isMounted && ((t = this.domNode.parentNode) == null || t.removeChild(this.domNode)), this._cleanup(e);
676
- }
677
- _cleanup(e) {
678
- for (const t of this.connectedItems)
679
- t.element.unmount(e);
680
- this.connectedItems = [];
681
- }
682
- _update(e) {
683
- var c, u, d;
684
- if (e.length === 0 || !this.isMounted)
685
- return this._cleanup(!1);
686
- const t = [];
687
- let s = 0;
688
- for (const l of e)
689
- t.push({
690
- key: this.keyFn(l, s),
691
- value: l,
692
- index: s++
693
- });
694
- const n = [];
695
- for (const l of this.connectedItems)
696
- t.find((b) => b.key === l.key) || l.element.unmount(!1);
697
- for (const l of t) {
698
- const v = this.connectedItems.find((b) => b.key === l.key);
699
- if (v)
700
- v.item(l.value), v.index(l.index), n[l.index] = v;
701
- else {
702
- const b = x(l.value, { equals: oe }), I = x(l.index);
703
- n[l.index] = {
704
- key: l.key,
705
- item: b,
706
- index: I,
707
- element: new L(this.elementContext, we, {
708
- item: () => b(),
709
- index: () => I(),
710
- renderFn: this.renderFn
711
- })
712
- };
713
- }
714
- }
715
- for (let l = 0; l < n.length; l++) {
716
- const v = n[l], b = ((c = n[l - 1]) == null ? void 0 : c.element.domNode) ?? this.domNode;
717
- v.element.mount(this.domNode.parentNode, b);
718
- }
719
- this.connectedItems = n;
720
- const o = ((u = n.at(-1)) == null ? void 0 : u.element.domNode) ?? this.domNode;
721
- (d = this.domNode.parentNode) == null || d.insertBefore(this.domNode, o.nextSibling);
722
- }
723
- }
724
- function we(i, e) {
725
- return e.name = "@RepeatItem", i.renderFn.call(e, i.item, i.index, e);
726
- }
727
- function E(i) {
728
- return i instanceof X;
729
- }
730
- function Q(i) {
731
- return (i == null ? void 0 : i[p]) === !0;
732
- }
733
- function M(i) {
734
- f(i) || (i = [i]);
735
- const e = [];
736
- for (const t of i)
737
- if (!(t == null || t === !1)) {
738
- if (t instanceof Node) {
739
- e.push(m("$node", { value: t }));
740
- continue;
741
- }
742
- if (E(t)) {
743
- e.push(t);
744
- continue;
745
- }
746
- if (h(t)) {
747
- e.push(m("$dynamic", { source: t }));
748
- continue;
749
- }
750
- if (f(t)) {
751
- e.push(...M(t));
752
- continue;
753
- }
754
- e.push(m("$text", { value: t }));
755
- }
756
- return e;
757
- }
758
- function Se(i) {
759
- return k(N(S, i));
760
- }
761
- function m(i, e, ...t) {
762
- return new X(i, e, ...t);
763
- }
764
- class X {
765
- constructor(e, t, ...s) {
766
- r(this, "type");
767
- r(this, "props");
768
- r(this, "children");
769
- this.type = e, this.props = t, this.children = s;
770
- }
771
- }
772
- function ge(i, e, t) {
773
- return m("$dynamic", {
774
- source: x(() => {
775
- const s = y(i);
776
- return s && e ? e : !s && t ? t : null;
777
- })
778
- });
779
- }
780
- function $e(i, e, t) {
781
- return ge(i, t, e);
782
- }
783
- function Ae(i, e, t) {
784
- return m("$repeat", { items: () => y(i), keyFn: e, renderFn: t });
785
- }
786
- function Pe(i, e) {
787
- return m("$portal", { parent: i, content: e });
788
- }
789
- function N(i, e) {
790
- return (f(e) ? e : [e]).map((s) => {
791
- if (h(s.type))
792
- return new L(i, s.type, s.props, s.children);
793
- if (C(s.type))
794
- switch (s.type) {
795
- case "$node": {
796
- const n = s.props;
797
- return new O(n.value);
798
- }
799
- case "$text": {
800
- const n = s.props;
801
- return new O(document.createTextNode(String(n.value)));
802
- }
803
- case "$repeat": {
804
- const n = s.props;
805
- return new ye({
806
- items: n.items,
807
- keyFn: n.keyFn,
808
- renderFn: n.renderFn,
809
- elementContext: i
810
- });
811
- }
812
- case "$dynamic": {
813
- const n = s.props;
814
- return new re({
815
- source: n.source,
816
- elementContext: i
817
- });
818
- }
819
- case "$fragment": {
820
- const n = s.props;
821
- return new Z(n.children);
822
- }
823
- case "$outlet": {
824
- const n = s.props;
825
- return new pe(n.view);
826
- }
827
- case "$portal": {
828
- const n = s.props;
829
- return new be({
830
- content: n.content,
831
- parent: n.parent,
832
- elementContext: i
833
- });
834
- }
835
- default:
836
- return new de({
837
- tag: s.type,
838
- props: s.props ?? {},
839
- children: s.children,
840
- elementContext: i
841
- });
842
- }
843
- else
844
- throw new TypeError(`Expected a string or view function. Got: ${s.type}`);
845
- });
846
- }
847
- function k(i) {
848
- return i.length === 1 ? i[0] : new Z(i);
849
- }
850
- function Y(i) {
851
- return i == null || i === !1 || h(i) || C(i) || se(i) || E(i) || z(Y, i);
852
- }
853
- class ve {
854
- constructor(e) {
855
- r(this, "view");
856
- this.view = e;
857
- const t = Object.getOwnPropertyDescriptors(this.view.logger);
858
- for (const s in t)
859
- s !== "setName" && Object.defineProperty(this, s, t[s]);
860
- }
861
- get uid() {
862
- return this.view.uniqueId;
863
- }
864
- get isMounted() {
865
- return this.view.isMounted;
866
- }
867
- get name() {
868
- return w(this.view.name) || this.uid;
869
- }
870
- set name(e) {
871
- this.view.name(e);
872
- }
873
- provide(e, t) {
874
- const s = new H(e, t);
875
- if (s.attach(this.view.elementContext))
876
- return this.view.lifecycleListeners.mount.push(() => {
877
- s.handleMount();
878
- }), this.view.lifecycleListeners.unmount.push(() => {
879
- s.handleUnmount();
880
- }), s.value;
881
- {
882
- let o = e.name ? `'${e.name}'` : "this store";
883
- return this.view.logger.warn(`An instance of ${o} was already attached to this context.`), this.get(e);
884
- }
885
- }
886
- get(e) {
887
- if (h(e)) {
888
- let t = this.view.elementContext, s;
889
- for (; s = t.stores.get(e), s == null && t.parent != null; )
890
- t = t.parent;
891
- if (s == null)
892
- throw new g(`Store '${e.name}' is not provided on this context.`);
893
- return s.value;
894
- } else
895
- throw new g("Invalid store.");
896
- }
897
- beforeMount(e) {
898
- this.view.lifecycleListeners.beforeMount.push(e);
899
- }
900
- onMount(e) {
901
- this.view.lifecycleListeners.mount.push(e);
902
- }
903
- beforeUnmount(e) {
904
- this.view.lifecycleListeners.beforeUnmount.push(e);
905
- }
906
- onUnmount(e) {
907
- this.view.lifecycleListeners.unmount.push(e);
908
- }
909
- effect(e) {
910
- const t = () => {
911
- try {
912
- return e();
913
- } catch (s) {
914
- 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"));
915
- }
916
- };
917
- if (this.view.isMounted) {
918
- const s = a(t);
919
- return this.view.lifecycleListeners.unmount.push(s), s;
920
- } else {
921
- let s, n = !1;
922
- return this.view.lifecycleListeners.mount.push(() => {
923
- n || (s = a(t), this.view.lifecycleListeners.unmount.push(s));
924
- }), () => {
925
- s != null && (n = !0, s());
926
- };
927
- }
928
- }
929
- outlet() {
930
- return m("$outlet", { view: this.view.elementContext.route });
931
- }
932
- }
933
- var G;
934
- G = p;
935
- const U = class U {
936
- constructor(e, t, s, n) {
937
- r(this, G, !0);
938
- r(this, "uniqueId", A());
939
- r(this, "elementContext");
940
- r(this, "logger");
941
- r(this, "props");
942
- r(this, "fn");
943
- r(this, "element");
944
- r(this, "name", x(""));
945
- r(this, "context");
946
- r(this, "lifecycleListeners", { beforeMount: [], mount: [], beforeUnmount: [], unmount: [] });
947
- r(this, "isMounted", !1);
948
- this.name(t.name || "🌇 anonymous view"), this.elementContext = {
949
- ...e,
950
- parent: e,
951
- view: this,
952
- stores: /* @__PURE__ */ new Map(),
953
- route: x()
954
- }, this.logger = P(this.name, { tag: this.uniqueId, tagName: "uid" }), this.props = {
955
- ...s,
956
- children: n
957
- }, this.fn = t, this.context = new ve(this);
958
- }
959
- /*===============================*\
960
- || "Public" API ||
961
- \*===============================*/
962
- get domNode() {
963
- var e;
964
- return (e = this.element) == null ? void 0 : e.domNode;
965
- }
966
- mount(e, t) {
967
- const s = this.isMounted;
968
- if (!s) {
969
- this._initialize();
970
- for (const n of this.lifecycleListeners.beforeMount)
971
- n();
972
- }
973
- this.element && this.element.mount(e, t), s || (this.isMounted = !0, requestAnimationFrame(() => {
974
- for (const n of this.lifecycleListeners.mount)
975
- n();
976
- }));
977
- }
978
- unmount(e = !1) {
979
- for (const t of this.lifecycleListeners.beforeUnmount)
980
- t();
981
- this.element && this.element.unmount(e), this.isMounted = !1;
982
- for (const t of this.lifecycleListeners.unmount)
983
- t();
984
- this.lifecycleListeners.beforeMount.length = 0, this.lifecycleListeners.mount.length = 0, this.lifecycleListeners.beforeUnmount.length = 0, this.lifecycleListeners.unmount.length = 0;
985
- }
986
- setRouteView(e) {
987
- const t = new U(this.elementContext, e, {});
988
- return this.elementContext.route(t), t;
989
- }
990
- /*===============================*\
991
- || Internal ||
992
- \*===============================*/
993
- _initialize() {
994
- const { context: e } = this;
995
- let t;
996
- try {
997
- t = this.fn.call(e, this.props, e);
998
- } catch (s) {
999
- throw s instanceof Error && this.logger.crash(s), s;
1000
- }
1001
- if (t !== null) if (t instanceof Node)
1002
- this.element = k(N(this.elementContext, m("$node", { value: t })));
1003
- else if (h(t))
1004
- this.element = k(
1005
- N(this.elementContext, m("$dynamic", { source: t }))
1006
- );
1007
- else if (E(t) || z(E, t))
1008
- this.element = k(N(this.elementContext, t));
1009
- else {
1010
- const s = new TypeError(
1011
- `Expected '${this.fn.name}' function to return a DOM node, Markup element, Signal or null. Got: ${R(t)}`
1012
- );
1013
- this.logger.crash(s);
1014
- }
1015
- }
1016
- };
1017
- let L = U;
1018
- const Ne = {
1019
- stores: W
1020
- };
1021
- function Ue(...i) {
1022
- if (h(i[0])) {
1023
- const e = i[0], t = f(i[1]) ? {} : i[1], s = f(i[2]) ? i[2] : f(i[1]) ? i[1] : [];
1024
- return new L(Ne, e, t, M(s));
1025
- } else if ($(i[0]) && h(i[1])) {
1026
- const e = i[0], t = i[1], s = f(i[2]) ? {} : i[2], n = f(i[3]) ? i[3] : f(i[2]) ? i[2] : [];
1027
- return new L(e, t, s, n ? M(n) : []);
1028
- } else
1029
- throw new TypeError(
1030
- "Unexpected arguments; expected view, props and children, or context, view, props and children."
1031
- );
1032
- }
1033
- export {
1034
- Ee as S,
1035
- Ae as a,
1036
- Se as b,
1037
- Ue as c,
1038
- m,
1039
- Pe as p,
1040
- S as r,
1041
- $e as u,
1042
- ge as w
1043
- };
1044
- //# sourceMappingURL=view-BKpHFpWG.js.map