@manyducks.co/dolla 2.0.0-alpha.6 → 2.0.0-alpha.61

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 (118) hide show
  1. package/README.md +86 -591
  2. package/dist/core/context.d.ts +142 -0
  3. package/dist/core/env.d.ts +3 -0
  4. package/dist/core/index.d.ts +21 -0
  5. package/dist/core/logger.d.ts +42 -0
  6. package/dist/core/logger.test.d.ts +0 -0
  7. package/dist/core/markup.d.ts +104 -0
  8. package/dist/core/markup.test.d.ts +0 -0
  9. package/dist/core/mount.d.ts +15 -0
  10. package/dist/core/mount.test.d.ts +0 -0
  11. package/dist/core/nodes/_markup.d.ts +36 -0
  12. package/dist/core/nodes/dom.d.ts +13 -0
  13. package/dist/core/nodes/dynamic.d.ts +22 -0
  14. package/dist/core/nodes/element.d.ts +25 -0
  15. package/dist/core/nodes/portal.d.ts +18 -0
  16. package/dist/core/nodes/repeat.d.ts +27 -0
  17. package/dist/core/nodes/view.d.ts +25 -0
  18. package/dist/core/ref.d.ts +18 -0
  19. package/dist/core/ref.test.d.ts +1 -0
  20. package/dist/core/signals.d.ts +58 -0
  21. package/dist/core/signals.test.d.ts +1 -0
  22. package/dist/{views → core/views}/default-crash-view.d.ts +11 -4
  23. package/dist/core/views/fragment.d.ts +7 -0
  24. package/dist/fragment-BahD_BJA.js +7 -0
  25. package/dist/fragment-BahD_BJA.js.map +1 -0
  26. package/dist/hooks/index.d.ts +64 -0
  27. package/dist/hooks/index.test.d.ts +1 -0
  28. package/dist/hooks.js +69 -0
  29. package/dist/hooks.js.map +1 -0
  30. package/dist/{modules/http.d.ts → http/index.d.ts} +3 -5
  31. package/dist/http.js +163 -0
  32. package/dist/http.js.map +1 -0
  33. package/dist/i18n/index.d.ts +134 -0
  34. package/dist/i18n.js +318 -0
  35. package/dist/i18n.js.map +1 -0
  36. package/dist/index.js +98 -1388
  37. package/dist/index.js.map +1 -1
  38. package/dist/jsx-dev-runtime.d.ts +3 -2
  39. package/dist/jsx-dev-runtime.js +5 -12
  40. package/dist/jsx-dev-runtime.js.map +1 -1
  41. package/dist/jsx-runtime.d.ts +4 -3
  42. package/dist/jsx-runtime.js +9 -15
  43. package/dist/jsx-runtime.js.map +1 -1
  44. package/dist/logger-Bl496yfY.js +91 -0
  45. package/dist/logger-Bl496yfY.js.map +1 -0
  46. package/dist/markup-CX27GJ1M.js +1030 -0
  47. package/dist/markup-CX27GJ1M.js.map +1 -0
  48. package/dist/ref-BD79iqlg.js +15 -0
  49. package/dist/ref-BD79iqlg.js.map +1 -0
  50. package/dist/router/index.d.ts +2 -0
  51. package/dist/router/router.d.ts +160 -0
  52. package/dist/{routing.d.ts → router/router.utils.d.ts} +17 -3
  53. package/dist/router/router.utils.test.d.ts +1 -0
  54. package/dist/router-CjCkk4dA.js +543 -0
  55. package/dist/router-CjCkk4dA.js.map +1 -0
  56. package/dist/router.js +8 -0
  57. package/dist/router.js.map +1 -0
  58. package/dist/signals-gCwiIe5X.js +450 -0
  59. package/dist/signals-gCwiIe5X.js.map +1 -0
  60. package/dist/typeChecking-CbltMOUt.js +71 -0
  61. package/dist/typeChecking-CbltMOUt.js.map +1 -0
  62. package/dist/typeChecking.d.ts +2 -98
  63. package/dist/typeChecking.test.d.ts +1 -0
  64. package/dist/types.d.ts +98 -25
  65. package/dist/utils.d.ts +20 -3
  66. package/docs/hooks.md +211 -0
  67. package/docs/http.md +29 -0
  68. package/docs/i18n.md +43 -0
  69. package/docs/index.md +10 -0
  70. package/docs/markup.md +16 -0
  71. package/docs/mixins.md +32 -0
  72. package/docs/ref.md +93 -0
  73. package/docs/router.md +80 -0
  74. package/docs/setup.md +31 -0
  75. package/docs/signals.md +166 -0
  76. package/docs/state.md +141 -0
  77. package/docs/stores.md +62 -0
  78. package/docs/views.md +208 -0
  79. package/examples/webcomponent/index.html +14 -0
  80. package/examples/webcomponent/main.js +165 -0
  81. package/index.d.ts +2 -2
  82. package/notes/TODO.md +6 -0
  83. package/notes/atomic.md +452 -0
  84. package/notes/context-routes.md +61 -0
  85. package/notes/custom-nodes.md +17 -0
  86. package/notes/effection-idea.md +34 -0
  87. package/notes/elimination.md +33 -0
  88. package/notes/mixins.md +22 -0
  89. package/notes/molecule.md +35 -0
  90. package/notes/observable.md +180 -0
  91. package/notes/readme-scratch.md +45 -7
  92. package/notes/route-middleware.md +42 -0
  93. package/notes/scratch.md +353 -6
  94. package/notes/splitting.md +5 -0
  95. package/notes/stores.md +79 -0
  96. package/package.json +31 -12
  97. package/vite.config.js +6 -11
  98. package/build.js +0 -34
  99. package/dist/index.d.ts +0 -21
  100. package/dist/markup.d.ts +0 -100
  101. package/dist/modules/dolla.d.ts +0 -111
  102. package/dist/modules/language.d.ts +0 -41
  103. package/dist/modules/render.d.ts +0 -17
  104. package/dist/modules/router.d.ts +0 -152
  105. package/dist/nodes/cond.d.ts +0 -26
  106. package/dist/nodes/html.d.ts +0 -31
  107. package/dist/nodes/observer.d.ts +0 -29
  108. package/dist/nodes/outlet.d.ts +0 -22
  109. package/dist/nodes/portal.d.ts +0 -19
  110. package/dist/nodes/repeat.d.ts +0 -34
  111. package/dist/nodes/text.d.ts +0 -19
  112. package/dist/passthrough-CW8Ezjg-.js +0 -1244
  113. package/dist/passthrough-CW8Ezjg-.js.map +0 -1
  114. package/dist/state.d.ts +0 -101
  115. package/dist/view.d.ts +0 -50
  116. package/dist/views/passthrough.d.ts +0 -5
  117. package/tests/state.test.js +0 -135
  118. /package/dist/{routing.test.d.ts → core/context.test.d.ts} +0 -0
@@ -0,0 +1,1030 @@
1
+ var it = Object.defineProperty;
2
+ var B = (i) => {
3
+ throw TypeError(i);
4
+ };
5
+ var nt = (i, o, t) => o in i ? it(i, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[o] = t;
6
+ var a = (i, o, t) => nt(i, typeof o != "symbol" ? o + "" : o, t), V = (i, o, t) => o.has(i) || B("Cannot " + t);
7
+ var O = (i, o, t) => (V(i, o, "read from private field"), t ? t.call(i) : o.get(i)), j = (i, o, t) => o.has(i) ? B("Cannot add the same private member more than once") : o instanceof WeakSet ? o.add(i) : o.set(i, t), T = (i, o, t, e) => (V(i, o, "write to private field"), e ? e.call(i, t) : o.set(i, t), t);
8
+ import { c as m, t as rt, i as C, b as D } from "./typeChecking-CbltMOUt.js";
9
+ import { u as I, g as x, f as Y, h as M, e as v, t as J, o as ct, i as at, b as ht, $ as _, d as ut } from "./signals-gCwiIe5X.js";
10
+ import { c as lt, g as dt } from "./logger-Bl496yfY.js";
11
+ var g = /* @__PURE__ */ ((i) => (i[i.WILL_MOUNT = 0] = "WILL_MOUNT", i[i.DID_MOUNT = 1] = "DID_MOUNT", i[i.WILL_UNMOUNT = 2] = "WILL_UNMOUNT", i[i.DID_UNMOUNT = 3] = "DID_UNMOUNT", i[i.DISPOSE = 4] = "DISPOSE", i))(g || {});
12
+ const U = Symbol("name"), d = Symbol("lifecycle"), b = Symbol("parent"), y = Symbol("stores"), w = Symbol("state");
13
+ class ft {
14
+ constructor(o) {
15
+ a(this, "context");
16
+ a(this, "state", 0);
17
+ a(this, "listeners", /* @__PURE__ */ new Map());
18
+ a(this, "bound");
19
+ this.context = o;
20
+ }
21
+ /**
22
+ * Listen for a certain event to be emitted. Listeners are called when the event results in a state change.
23
+ */
24
+ on(o, t) {
25
+ const e = this.listeners.get(o);
26
+ e ? e.add(t) : this.listeners.set(o, /* @__PURE__ */ new Set([t]));
27
+ }
28
+ /**
29
+ * Stop a particular listener from being called when an event is emitted.
30
+ */
31
+ off(o, t) {
32
+ const e = this.listeners.get(o);
33
+ e && (e.delete(t), e.size === 0 && this.listeners.delete(o));
34
+ }
35
+ /**
36
+ * Advance the lifecycle state machine.
37
+ */
38
+ emit(o) {
39
+ switch (o) {
40
+ case 0: {
41
+ this.state < 1 ? (this.state = 1, this.notify(o)) : this.context.crash(new Error(`Tried to WILL_MOUNT context at state ${this.state}`));
42
+ break;
43
+ }
44
+ case 1: {
45
+ this.state >= 1 && this.state < 2 ? (this.state = 2, this.notify(o)) : this.context.crash(new Error(`Tried to WILL_UNMOUNT context at state ${this.state}`));
46
+ break;
47
+ }
48
+ case 2: {
49
+ this.state >= 2 && this.state < 3 ? (this.notify(o), this.state = 3) : this.context.crash(new Error(`Tried to WILL_UNMOUNT context at state ${this.state}`));
50
+ break;
51
+ }
52
+ case 3: {
53
+ this.state >= 3 && this.state < 4 ? (this.state = 4 % 4, this.notify(o)) : this.context.crash(new Error(`Tried to DID_UNMOUNT context at state ${this.state}`));
54
+ break;
55
+ }
56
+ case 4: {
57
+ this.state === 0 ? (this.notify(o), this.listeners.clear(), this.bound = void 0, this.context[w] = void 0, this.context[y] = void 0, this.state = 5) : this.context.crash(new Error(`Tried to DISPOSE context at state ${this.state}`));
58
+ break;
59
+ }
60
+ }
61
+ }
62
+ /**
63
+ * Bind `context` to this lifecycle; when any event is emitted here it will be emitted for `context` as well.
64
+ */
65
+ bind(o) {
66
+ this.bound ? this.bound.add(o) : this.bound = /* @__PURE__ */ new Set([o]);
67
+ }
68
+ /**
69
+ * Call all the event's listeners and re-emit to bound contexts.
70
+ */
71
+ notify(o) {
72
+ const t = this.listeners.get(o);
73
+ if (t)
74
+ for (const e of t)
75
+ e();
76
+ if (this.bound)
77
+ for (const e of this.bound)
78
+ e[d].emit(o);
79
+ }
80
+ }
81
+ var z, F, H, Z, K, N;
82
+ K = U, Z = d, H = b, F = y, z = w;
83
+ const L = class L {
84
+ constructor(o, t) {
85
+ j(this, N);
86
+ a(this, K);
87
+ a(this, Z, new ft(this));
88
+ a(this, H);
89
+ a(this, F);
90
+ a(this, z);
91
+ T(this, N, o), this[U] = I(o);
92
+ const e = lt(() => x(O(this, N)), t == null ? void 0 : t.logger), s = Object.getOwnPropertyDescriptors(e);
93
+ for (const n in s)
94
+ Object.defineProperty(this, n, s[n]);
95
+ }
96
+ get isMounted() {
97
+ const { state: o } = this[d];
98
+ return o >= 2 && o < 4;
99
+ }
100
+ /**
101
+ * Returns a new Context with this one as its parent.
102
+ */
103
+ static linked(o, t, e) {
104
+ const s = new L(t, e);
105
+ return s[b] = o, e != null && e.bindLifecycleToParent && o[d].bind(s), s;
106
+ }
107
+ /**
108
+ * Emit a lifecycle event to `context`.
109
+ */
110
+ static emit(o, t) {
111
+ o[d].emit(t);
112
+ }
113
+ /**
114
+ * Traverses _parent contexts until arriving at one that doesn't have a parent itself.
115
+ * Returns null if this context is the parent.
116
+ */
117
+ static getRoot(o) {
118
+ let t = o[b];
119
+ for (; t != null && t[b]; )
120
+ t = t[b];
121
+ return t ?? null;
122
+ }
123
+ /**
124
+ * Returns the current name of this context.
125
+ */
126
+ getName() {
127
+ return I(O(this, N));
128
+ }
129
+ /**
130
+ * Sets a new name for this context.
131
+ */
132
+ setName(o) {
133
+ T(this, N, o), this[U] = I(o);
134
+ }
135
+ /**
136
+ * Creates an instance of a store and attaches it to this context.
137
+ */
138
+ addStore(o, t) {
139
+ var s;
140
+ if ((s = this[y]) != null && s.get(o)) {
141
+ let n = o.name ? `'${o.name}'` : "this store";
142
+ throw this.crash(new Error(`An instance of ${n} was already added on this context.`));
143
+ }
144
+ const e = L.linked(this, o.name, {
145
+ bindLifecycleToParent: !0,
146
+ logger: { tag: Y(), tagName: "uid" }
147
+ });
148
+ try {
149
+ this[y] || (this[y] = /* @__PURE__ */ new Map());
150
+ const n = M(e), c = o.call(e, t, e);
151
+ M(n), this[y].set(o, c);
152
+ } catch (n) {
153
+ throw this.crash(n);
154
+ }
155
+ return this;
156
+ }
157
+ /**
158
+ * Retrieves the nearest instance of `store`. If this context doesn't have it, the parent context is checked. This process continues until either:
159
+ * 1. An instance of the store is found and returned.
160
+ * 2. No instance is found and an error is thrown.
161
+ */
162
+ getStore(o) {
163
+ var s;
164
+ if (!m(o))
165
+ throw new Error("Invalid store.");
166
+ let t = this, e;
167
+ for (; e = (s = t[y]) == null ? void 0 : s.get(o), e == null && t[b] != null; )
168
+ t = t[b];
169
+ if (e == null)
170
+ throw this.crash(new Error(`Store '${o.name}' is not provided by this context.`));
171
+ return e;
172
+ }
173
+ /**
174
+ * Schedule a callback function to run just before this context is mounted.
175
+ */
176
+ beforeMount(o) {
177
+ return this[d].on(0, o), () => this[d].off(0, o);
178
+ }
179
+ /**
180
+ * Schedule a callback function to run after this context is mounted.
181
+ */
182
+ onMount(o) {
183
+ return this[d].on(1, o), () => this[d].off(1, o);
184
+ }
185
+ /**
186
+ * Schedule a callback function to run just before this context is unmounted.
187
+ */
188
+ beforeUnmount(o) {
189
+ return this[d].on(2, o), () => this[d].off(2, o);
190
+ }
191
+ /**
192
+ * Schedule a callback function to run after this context is unmounted.
193
+ */
194
+ onUnmount(o) {
195
+ return this[d].on(3, o), () => this[d].off(3, o);
196
+ }
197
+ effect(o) {
198
+ const t = () => {
199
+ try {
200
+ return o();
201
+ } catch (e) {
202
+ this.error(e), e instanceof Error ? this.crash(e) : typeof e == "string" ? this.crash(new Error(e)) : this.crash(new Error("Unknown error thrown in effect callback"));
203
+ }
204
+ };
205
+ if (this[d].state >= 1) {
206
+ const e = v(t);
207
+ return this[d].on(3, e), e;
208
+ } else {
209
+ let e, s = !1;
210
+ return this[d].on(0, () => {
211
+ s || (e = v(t), this[d].on(3, e));
212
+ }), () => {
213
+ e != null && (s = !0, e());
214
+ };
215
+ }
216
+ }
217
+ getState(o, t) {
218
+ var e;
219
+ if (arguments.length > 0) {
220
+ let s = this, n;
221
+ for (; n = (e = s[w]) == null ? void 0 : e.get(o), n === void 0 && s[b] != null; )
222
+ s = s[b];
223
+ if (n === void 0) {
224
+ if (arguments.length > 1)
225
+ return t;
226
+ throw new Error(`Expected a value for '${String(o)}' but got undefined.`);
227
+ }
228
+ return n;
229
+ } else {
230
+ let s = this;
231
+ const n = [];
232
+ for (; s[w] && n.push(...s[w].entries()), s[b] != null; )
233
+ s = s[b];
234
+ return new Map(n.reverse());
235
+ }
236
+ }
237
+ setState(...o) {
238
+ if (this[w] || (this[w] = /* @__PURE__ */ new Map()), o.length === 2)
239
+ this[w].set(o[0], o[1]);
240
+ else if (rt(o[0]) === "array")
241
+ for (const [t, e] of o[0])
242
+ e === void 0 ? this[w].delete(t) : this[w].set(t, e);
243
+ else
244
+ throw new Error("Invalid arguments.");
245
+ return this;
246
+ }
247
+ };
248
+ N = new WeakMap();
249
+ let f = L;
250
+ function Lt(i, o) {
251
+ return new f(i, o);
252
+ }
253
+ class k {
254
+ /**
255
+ * Returns a single DOM node to represent this MarkupNode's position in the DOM.
256
+ * Usually the parent element, but it can be an empty Text node used as a marker.
257
+ *
258
+ * It only needs to be defined while the node is mounted, so it can be created in the `mount` function.
259
+ */
260
+ getRoot() {
261
+ throw new Error("getRoot method is not implemented");
262
+ }
263
+ /**
264
+ * Returns true while this node is mounted.
265
+ */
266
+ isMounted() {
267
+ throw new Error("isMounted method is not implemented");
268
+ }
269
+ /**
270
+ * Mount this node to a `parent` element.
271
+ * If passed, this node will be mounted as the next sibling of `after`.
272
+ */
273
+ mount(o, t) {
274
+ throw new Error("mount method is not implemented");
275
+ }
276
+ /**
277
+ * Unmount this MarkupNode from its parent element.
278
+ *
279
+ * The `skipDOM` option can be passed as an optimization when unmounting a parent node.
280
+ * A value of `true` indicates that no DOM operations need to happen because the parent is already being unmounted.
281
+ *
282
+ * @param skipDOM - No DOM updates will be performed when true. Lifecycle methods will be called regardless.
283
+ */
284
+ unmount(o) {
285
+ throw new Error("unmount method is not implemented");
286
+ }
287
+ /**
288
+ * Moves a node without unmounting and remounting (if the browser supports Element.moveBefore).
289
+ */
290
+ move(o, t) {
291
+ throw new Error("move method is not implemented");
292
+ }
293
+ }
294
+ class $ extends k {
295
+ constructor(t) {
296
+ super();
297
+ a(this, "root");
298
+ this.root = t;
299
+ }
300
+ getRoot() {
301
+ return this.root;
302
+ }
303
+ isMounted() {
304
+ return this.root.parentNode != null;
305
+ }
306
+ mount(t, e) {
307
+ t.insertBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null);
308
+ }
309
+ unmount(t = !1) {
310
+ !t && this.root.parentNode && this.root.parentNode.removeChild(this.root);
311
+ }
312
+ move(t, e) {
313
+ if ("moveBefore" in t && this.root instanceof Element)
314
+ try {
315
+ t.moveBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null);
316
+ } catch {
317
+ this.mount(t, e);
318
+ }
319
+ else
320
+ this.mount(t, e);
321
+ }
322
+ }
323
+ class A extends k {
324
+ constructor(t, e) {
325
+ super();
326
+ a(this, "root", document.createTextNode(""));
327
+ a(this, "children", []);
328
+ a(this, "context");
329
+ a(this, "$slot");
330
+ a(this, "unsubscribe");
331
+ this.context = t, this.$slot = e;
332
+ }
333
+ getRoot() {
334
+ return this.root;
335
+ }
336
+ isMounted() {
337
+ return this.root.parentElement != null;
338
+ }
339
+ mount(t, e) {
340
+ this.isMounted() || (t.insertBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null), this.unsubscribe = v(() => {
341
+ try {
342
+ const s = this.$slot();
343
+ I(() => {
344
+ this.update(J(s));
345
+ });
346
+ } catch (s) {
347
+ this.context.crash(s);
348
+ }
349
+ }));
350
+ }
351
+ unmount(t = !1) {
352
+ var e, s;
353
+ (e = this.unsubscribe) == null || e.call(this), this.isMounted() && (this.cleanup(t), (s = this.root.parentNode) == null || s.removeChild(this.root));
354
+ }
355
+ move(t, e) {
356
+ var s, n, c;
357
+ if ("moveBefore" in t)
358
+ try {
359
+ t.moveBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null);
360
+ for (let r = 0; r < this.children.length; r++)
361
+ this.children[r].move(t, ((s = this.children[r - 1]) == null ? void 0 : s.getRoot()) ?? this.root);
362
+ t.moveBefore(this.root, ((c = (n = this.children.at(-1)) == null ? void 0 : n.getRoot()) == null ? void 0 : c.nextSibling) ?? null);
363
+ } catch {
364
+ this.mount(t, e);
365
+ }
366
+ else
367
+ this.mount(t, e);
368
+ }
369
+ cleanup(t) {
370
+ for (const e of this.children)
371
+ e.isMounted() && e.unmount(t);
372
+ this.children.length = 0;
373
+ }
374
+ update(t) {
375
+ var c, r, h;
376
+ if (this.cleanup(!1), t.length === 0 || !this.isMounted()) return;
377
+ const e = W(this.context, t);
378
+ for (const u of e) {
379
+ const l = ((c = this.children.at(-1)) == null ? void 0 : c.getRoot()) || this.root;
380
+ u.mount(this.root.parentElement, l), this.children.push(u);
381
+ }
382
+ const s = this.root.parentElement, n = ((h = (r = this.children.at(-1)) == null ? void 0 : r.getRoot()) == null ? void 0 : h.nextSibling) ?? null;
383
+ "moveBefore" in s ? s.moveBefore(this.root, n) : s.insertBefore(this.root, n);
384
+ }
385
+ }
386
+ const Q = Symbol("ViewNode");
387
+ class X extends k {
388
+ /**
389
+ * @param context - Parent contenxt to link to.
390
+ * @param view - View function to mount.
391
+ * @param props - Props to pass to view function.
392
+ */
393
+ constructor(t, e, s) {
394
+ super();
395
+ a(this, "uniqueId", Y());
396
+ a(this, "context");
397
+ a(this, "props");
398
+ a(this, "view");
399
+ a(this, "node");
400
+ this.context = f.linked(t, e.name ?? "anonymous view", {
401
+ logger: {
402
+ tag: this.uniqueId,
403
+ tagName: "uid"
404
+ }
405
+ }), this.context.setState(Q, this), this.props = s, this.view = e;
406
+ }
407
+ getRoot() {
408
+ var t;
409
+ return (t = this.node) == null ? void 0 : t.getRoot();
410
+ }
411
+ isMounted() {
412
+ var t;
413
+ return ((t = this.node) == null ? void 0 : t.isMounted()) ?? !1;
414
+ }
415
+ mount(t, e) {
416
+ const s = this.isMounted();
417
+ if (!s) {
418
+ const { context: n, props: c, view: r } = this;
419
+ try {
420
+ const h = M(n), u = r.call(n, c, n);
421
+ M(h), u != null && u !== !1 && (this.node = ot(u, n));
422
+ } catch (h) {
423
+ throw h instanceof Error && n.crash(h), h;
424
+ }
425
+ f.emit(this.context, g.WILL_MOUNT);
426
+ }
427
+ this.node && this.node.mount(t, e), s || f.emit(this.context, g.DID_MOUNT);
428
+ }
429
+ unmount(t = !1) {
430
+ f.emit(this.context, g.WILL_UNMOUNT), this.node && this.node.unmount(t), f.emit(this.context, g.DID_UNMOUNT), f.emit(this.context, g.DISPOSE);
431
+ }
432
+ move(t, e) {
433
+ var s;
434
+ (s = this.node) == null || s.move(t, e);
435
+ }
436
+ }
437
+ const mt = (i) => /^on[A-Z]/.test(i), P = Symbol("HTML.isSVG"), pt = ["class", "className", "ref", "mixin", "children"];
438
+ class bt extends k {
439
+ constructor(t, e, s) {
440
+ super();
441
+ a(this, "root");
442
+ a(this, "tag");
443
+ a(this, "props");
444
+ a(this, "context");
445
+ a(this, "childNodes", []);
446
+ a(this, "unsubscribers", []);
447
+ // Track the ref so we can nullify it on unmount.
448
+ a(this, "ref");
449
+ // Prevents 'onClickOutside' handlers from firing in the same cycle in which the element is connected.
450
+ a(this, "canClickAway", !1);
451
+ if (this.tag = e, this.props = s, this.context = f.linked(t, q.bind(this)), e.toLowerCase() === "svg" && this.context.setState(P, !0), this.context.getState(P, !1) ? this.root = document.createElementNS("http://www.w3.org/2000/svg", e) : this.root = document.createElement(e), dt() === "development") {
452
+ const c = this.context.getState(Q, null);
453
+ c && (this.root.dataset.view = c.context.getName());
454
+ }
455
+ if (s.mixin)
456
+ for (const c of J(s.mixin)) {
457
+ const r = f.linked(this.context, q.bind(this), {
458
+ bindLifecycleToParent: !0,
459
+ logger: { tagName: c.name === "mixin" ? void 0 : "mixin", tag: c.name }
460
+ }), h = M(r);
461
+ c(this.root, r), M(h);
462
+ }
463
+ const n = s.className ?? s.class;
464
+ if (this.applyProps(this.root, s), s.style && this.applyStyles(this.root, s.style, this.unsubscribers), n && this.applyClasses(this.root, n, this.unsubscribers), s.ref)
465
+ if (m(s.ref))
466
+ this.ref = s.ref, this.ref(this.root);
467
+ else
468
+ throw new Error("Expected ref to be a function. Got: " + s.ref);
469
+ s.children && (this.childNodes = W(this.context, s.children));
470
+ }
471
+ getRoot() {
472
+ return this.root;
473
+ }
474
+ isMounted() {
475
+ return this.context.isMounted;
476
+ }
477
+ mount(t, e) {
478
+ const s = this.isMounted();
479
+ if (!s) {
480
+ f.emit(this.context, g.WILL_MOUNT);
481
+ for (let n = 0; n < this.childNodes.length; n++) {
482
+ const c = this.childNodes[n], r = n > 0 ? this.childNodes[n - 1].getRoot() : void 0;
483
+ c.mount(this.root, r);
484
+ }
485
+ }
486
+ t.insertBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null), this.canClickAway = !0, s || f.emit(this.context, g.DID_MOUNT);
487
+ }
488
+ unmount(t = !1) {
489
+ var e;
490
+ f.emit(this.context, g.WILL_UNMOUNT), t || (e = this.root.parentNode) == null || e.removeChild(this.root);
491
+ for (const s of this.childNodes)
492
+ s.unmount(!0);
493
+ this.canClickAway = !1;
494
+ for (const s of this.unsubscribers)
495
+ s();
496
+ this.unsubscribers.length = 0, this.ref && this.ref(void 0), f.emit(this.context, g.DID_UNMOUNT), f.emit(this.context, g.DISPOSE);
497
+ }
498
+ move(t, e) {
499
+ if ("moveBefore" in t)
500
+ try {
501
+ t.moveBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null);
502
+ } catch {
503
+ this.mount(t, e);
504
+ }
505
+ else
506
+ this.mount(t, e);
507
+ }
508
+ attachProp(t, e) {
509
+ m(t) ? this.unsubscribers.push(
510
+ v(() => {
511
+ try {
512
+ e(t());
513
+ } catch (s) {
514
+ this.context.error(s), this.context.crash(s);
515
+ }
516
+ })
517
+ ) : e(t);
518
+ }
519
+ applyProps(t, e) {
520
+ for (const s in ct(pt, e)) {
521
+ const n = e[s];
522
+ if (s === "on:clickoutside" || s === "onClickOutside" || s === "onclickoutside") {
523
+ const c = (h) => {
524
+ this.canClickAway && !t.contains(h.target) && n(h);
525
+ }, r = { capture: !0 };
526
+ window.addEventListener("click", c, r), this.unsubscribers.push(() => {
527
+ window.removeEventListener("click", c, r);
528
+ });
529
+ } else if (s.startsWith("prop:")) {
530
+ const c = s.substring(5);
531
+ this.attachProp(n, (r) => {
532
+ t[c] = r;
533
+ });
534
+ } else if (s.startsWith("on:")) {
535
+ const c = s.substring(3);
536
+ let r;
537
+ m(n) ? (t.addEventListener(c, n), this.unsubscribers.push(() => {
538
+ t.removeEventListener(c, n);
539
+ })) : this.attachProp(n, (h) => {
540
+ !h && r ? t.removeEventListener(c, r) : h != null && (r && r !== h && t.removeEventListener(c, r), t.addEventListener(c, h)), r = h;
541
+ });
542
+ } else if (s.startsWith("attr:")) {
543
+ const c = s.substring(5).toLowerCase();
544
+ this.attachProp(n, (r) => {
545
+ r != null ? t.setAttribute(c, String(r)) : t.removeAttribute(c);
546
+ });
547
+ } else if (m(n) && mt(s)) {
548
+ const c = s.slice(2).toLowerCase(), r = n;
549
+ t.addEventListener(c, r), this.unsubscribers.push(() => {
550
+ t.removeEventListener(c, r);
551
+ });
552
+ } else if (s.startsWith("on") && m(n) && gt.includes(s.substring(2)))
553
+ t[s] = n, this.unsubscribers.push(() => {
554
+ t[s] = void 0;
555
+ });
556
+ else if (s.includes("-"))
557
+ this.attachProp(n, (c) => {
558
+ c == null ? t.removeAttribute(s) : t.setAttribute(s, String(c));
559
+ });
560
+ else if (this.context.getState(P, !1))
561
+ this.attachProp(n, (c) => {
562
+ c != null ? t.setAttribute(s, String(e[s])) : t.removeAttribute(s);
563
+ });
564
+ else
565
+ switch (s) {
566
+ case "contentEditable":
567
+ case "value":
568
+ this.attachProp(n, (r) => {
569
+ t[s] = String(r);
570
+ });
571
+ break;
572
+ case "for":
573
+ this.attachProp(n, (r) => {
574
+ t.htmlFor = r;
575
+ });
576
+ break;
577
+ case "innerHTML":
578
+ this.attachProp(n, (r) => {
579
+ t.innerHTML = r;
580
+ });
581
+ break;
582
+ case "title":
583
+ this.attachProp(n, (r) => {
584
+ r == null ? t.removeAttribute(s) : t.setAttribute(s, String(r));
585
+ });
586
+ case "checked":
587
+ this.attachProp(n, (r) => {
588
+ t.checked = r, r ? t.setAttribute("checked", "") : t.removeAttribute("checked");
589
+ });
590
+ break;
591
+ case "dataset":
592
+ let c = {};
593
+ this.attachProp(n, (r) => {
594
+ if (C(r)) {
595
+ const h = {};
596
+ for (const u in r)
597
+ h[at(u)] = String(r[u]);
598
+ for (const u in c)
599
+ Object.hasOwn(h, u) || (delete t.dataset[u], delete c[u]);
600
+ for (const u in h)
601
+ c[u] !== h[u] && (t.dataset[u] = h[u], c[u] = h[u]);
602
+ } else
603
+ for (const h in c)
604
+ delete t.dataset[h];
605
+ });
606
+ break;
607
+ case "autocomplete":
608
+ case "autocapitalize":
609
+ this.attachProp(n, (r) => {
610
+ typeof r == "string" ? t[s] = r : r ? t[s] = "on" : t[s] = "off";
611
+ });
612
+ break;
613
+ default: {
614
+ this.attachProp(n, (r) => {
615
+ t[s] = r;
616
+ });
617
+ break;
618
+ }
619
+ }
620
+ }
621
+ }
622
+ applyStyles(t, e, s) {
623
+ const n = [];
624
+ if (m(e)) {
625
+ let c;
626
+ const r = v(() => {
627
+ m(c) && c(), t.style.cssText = "", c = this.applyStyles(t, x(e), s);
628
+ });
629
+ s.push(r), n.push(r);
630
+ } else {
631
+ const c = et(e);
632
+ for (const r in c) {
633
+ const { value: h, priority: u } = c[r];
634
+ if (m(h)) {
635
+ const l = v(() => {
636
+ x(h) ? t.style.setProperty(r, String(x(h)), u) : t.style.removeProperty(r);
637
+ });
638
+ s.push(l), n.push(l);
639
+ } else h != null && t.style.setProperty(r, String(h));
640
+ }
641
+ }
642
+ return function() {
643
+ for (const r of n)
644
+ r(), s.splice(s.indexOf(r), 1);
645
+ };
646
+ }
647
+ applyClasses(t, e, s) {
648
+ const n = [];
649
+ if (m(e)) {
650
+ let c;
651
+ const r = v(() => {
652
+ m(c) && c(), t.removeAttribute("class"), c = this.applyClasses(t, x(e), s);
653
+ });
654
+ s.push(r), n.push(r);
655
+ } else {
656
+ const c = tt(e);
657
+ for (const r in c) {
658
+ const h = c[r];
659
+ if (m(h)) {
660
+ const u = v(() => {
661
+ x(h) ? t.classList.add(r) : t.classList.remove(r);
662
+ });
663
+ s.push(u), n.push(u);
664
+ } else h && t.classList.add(r);
665
+ }
666
+ }
667
+ return function() {
668
+ for (const r of n)
669
+ r(), s.splice(s.indexOf(r), 1);
670
+ };
671
+ }
672
+ }
673
+ function tt(i) {
674
+ let o = {};
675
+ if (D(i)) {
676
+ const t = i.split(" ");
677
+ for (const e of t)
678
+ o[e] = !0;
679
+ } else C(i) ? Object.assign(o, i) : Array.isArray(i) && Array.from(i).filter(Boolean).forEach((t) => {
680
+ Object.assign(o, tt(t));
681
+ });
682
+ return delete o.undefined, o;
683
+ }
684
+ function et(i) {
685
+ let o = {};
686
+ if (D(i)) {
687
+ const t = i.split(";").filter((e) => e.trim() !== "");
688
+ for (const e of t) {
689
+ const [s, n] = e.split(":"), c = {
690
+ value: n
691
+ };
692
+ n.includes("!important") ? (c.priority = "important", c.value = n.replace("!important", "").trim()) : c.value = n.trim(), o[G(s.trim())] = c;
693
+ }
694
+ }
695
+ if (C(i))
696
+ for (const t in i)
697
+ t.startsWith("--") ? o[t] = { value: i[t] } : o[G(t)] = { value: i[t] };
698
+ else Array.isArray(i) && Array.from(i).filter((t) => t != null).forEach((t) => {
699
+ Object.assign(o, et(t));
700
+ });
701
+ return o;
702
+ }
703
+ function q() {
704
+ const i = this.getRoot();
705
+ if (i == null) return this.tag;
706
+ let o = this.getRoot().tagName.toLowerCase();
707
+ if (i.id && (o += `#${i.id}`), i.classList.length > 0)
708
+ for (const t of i.classList.values())
709
+ o += `.${t}`;
710
+ return o;
711
+ }
712
+ function G(i) {
713
+ return i.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (o, t) => (t ? "-" : "") + o.toLowerCase());
714
+ }
715
+ const gt = [
716
+ // Element
717
+ "animationcancel",
718
+ "animationend",
719
+ "animationiteration",
720
+ "animationstart",
721
+ "auxclick",
722
+ "beforeinput",
723
+ "beforematch",
724
+ "beforexrselect",
725
+ "blur",
726
+ "click",
727
+ "compositionend",
728
+ "compositionstart",
729
+ "compositionupdate",
730
+ "contentvisibilityautostatechange",
731
+ "contextmenu",
732
+ "copy",
733
+ "cut",
734
+ "dblclick",
735
+ "focus",
736
+ "focusin",
737
+ "focusout",
738
+ "fullscreenchange",
739
+ "fullscreenerror",
740
+ "gotpointercapture",
741
+ "input",
742
+ "keydown",
743
+ "keyup",
744
+ "lostpointercapture",
745
+ "mousedown",
746
+ "mouseenter",
747
+ "mouseleave",
748
+ "mousemove",
749
+ "mouseout",
750
+ "mouseover",
751
+ "mouseup",
752
+ "paste",
753
+ "pointercancel",
754
+ "pointerdown",
755
+ "pointerenter",
756
+ "pointerleave",
757
+ "pointermove",
758
+ "pointerout",
759
+ "pointerover",
760
+ "pointerrawupdate",
761
+ "pointerup",
762
+ "scroll",
763
+ "scrollend",
764
+ "scrollsnapchange",
765
+ "scrollsnapchanging",
766
+ "securitypolicyviolation",
767
+ "touchcancel",
768
+ "touchend",
769
+ "touchmove",
770
+ "touchstart",
771
+ "transitioncancel",
772
+ "transitionend",
773
+ "transitionrun",
774
+ "transitionstart",
775
+ "webkitmouseforcechanged",
776
+ "webkitmouseforcedown",
777
+ "webkitmouseforceup",
778
+ "webkimouseforcewillbegin",
779
+ "wheel",
780
+ // HTMLElement
781
+ "beforetoggle",
782
+ "change",
783
+ "command",
784
+ "drag",
785
+ "dragend",
786
+ "dragenter",
787
+ "dragleave",
788
+ "dragover",
789
+ "dragstart",
790
+ "drop",
791
+ "error",
792
+ "load",
793
+ "toggle",
794
+ // HTMLInputElement
795
+ "cancel",
796
+ "invalid",
797
+ "search",
798
+ "select",
799
+ "selectionchange",
800
+ // HTMLFormElement
801
+ "formdata",
802
+ "reset",
803
+ "submit"
804
+ ];
805
+ class wt extends k {
806
+ constructor(t, e, s) {
807
+ super();
808
+ a(this, "context");
809
+ a(this, "value");
810
+ a(this, "parent");
811
+ a(this, "node");
812
+ this.context = t, this.value = e, this.parent = s;
813
+ }
814
+ getRoot() {
815
+ var t;
816
+ return (t = this.node) == null ? void 0 : t.getRoot();
817
+ }
818
+ isMounted() {
819
+ return this.node ? this.node.isMounted() : !1;
820
+ }
821
+ mount(t, e) {
822
+ const s = ot(this.value, this.context);
823
+ this.node = s, s.mount(this.parent);
824
+ }
825
+ unmount(t = !1) {
826
+ var e;
827
+ (e = this.node) != null && e.isMounted() && this.node.unmount(!1);
828
+ }
829
+ move(t, e) {
830
+ }
831
+ }
832
+ class vt extends k {
833
+ constructor(t, e, s, n) {
834
+ super();
835
+ a(this, "root", document.createTextNode(""));
836
+ a(this, "context");
837
+ a(this, "items");
838
+ a(this, "key");
839
+ a(this, "render");
840
+ a(this, "unsubscribe", null);
841
+ a(this, "connectedItems", /* @__PURE__ */ new Map());
842
+ this.context = t, this.items = e, this.key = s, this.render = n;
843
+ }
844
+ getRoot() {
845
+ return this.root;
846
+ }
847
+ isMounted() {
848
+ return this.root.parentElement != null;
849
+ }
850
+ mount(t, e) {
851
+ this.isMounted() || (t.insertBefore(this.root, (e == null ? void 0 : e.nextSibling) ?? null), this.unsubscribe = v(() => {
852
+ let s = this.items();
853
+ s == null && (s = [], this.context.warn("repeat() received empty value for items", s)), I(() => {
854
+ this._update(Array.from(s));
855
+ });
856
+ }));
857
+ }
858
+ unmount(t = !1) {
859
+ var e;
860
+ this.unsubscribe && (this.unsubscribe(), this.unsubscribe = null), !t && this.isMounted() && ((e = this.root.parentNode) == null || e.removeChild(this.root)), this._cleanup(t);
861
+ }
862
+ move(t, e) {
863
+ return this.mount(t, e);
864
+ }
865
+ _cleanup(t) {
866
+ for (const e of this.connectedItems.values())
867
+ e.node.unmount(t);
868
+ this.connectedItems.clear();
869
+ }
870
+ _update(t) {
871
+ var r, h, u;
872
+ if (t.length === 0 || !this.isMounted())
873
+ return this._cleanup(!1);
874
+ const e = /* @__PURE__ */ new Map();
875
+ let s = 0;
876
+ for (const l of t) {
877
+ const p = this.key(l, s);
878
+ e.set(p, {
879
+ key: p,
880
+ value: l,
881
+ index: s++
882
+ });
883
+ }
884
+ const n = [];
885
+ for (const l of this.connectedItems.values())
886
+ !e.has(l.key) && l.node.isMounted() && l.node.unmount(!1);
887
+ ht(() => {
888
+ for (const l of e.values()) {
889
+ const p = this.connectedItems.get(l.key);
890
+ if (p && p.node.isMounted())
891
+ p.$item(l.value), p.$index(l.index), n[l.index] = p;
892
+ else {
893
+ const S = _(l.value, { equals: ut }), E = _(l.index);
894
+ n[l.index] = {
895
+ key: l.key,
896
+ $item: S,
897
+ $index: E,
898
+ node: new X(this.context, yt, {
899
+ $item: () => S(),
900
+ $index: () => E(),
901
+ render: this.render
902
+ })
903
+ };
904
+ }
905
+ }
906
+ });
907
+ for (let l = 0; l < n.length; l++) {
908
+ const p = n[l], S = ((r = n[l - 1]) == null ? void 0 : r.node.getRoot()) ?? this.root, E = this.connectedItems.get(p.key);
909
+ E && E.node.isMounted() ? p.node.move(this.root.parentElement, S) : p.node.mount(this.root.parentElement, S);
910
+ }
911
+ this.connectedItems.clear();
912
+ for (const l of n)
913
+ this.connectedItems.set(l.key, l);
914
+ const c = ((h = n.at(-1)) == null ? void 0 : h.node.getRoot()) ?? this.root;
915
+ (u = this.root.parentNode) == null || u.insertBefore(this.root, c.nextSibling);
916
+ }
917
+ }
918
+ const xt = "dolla.RepeatItemView";
919
+ function yt(i, o) {
920
+ return o.setName(xt), i.render.call(o, i.$item, i.$index, o);
921
+ }
922
+ class st {
923
+ constructor(o, t) {
924
+ /**
925
+ * 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.
926
+ * DOM nodes can be created by name, such as HTML elements like "div", "ul" or "span", SVG elements like ""
927
+ */
928
+ a(this, "type");
929
+ /**
930
+ * Data that will be passed to a new MarkupNode instance when it is constructed.
931
+ * Includes a `children` prop if children were passed.
932
+ */
933
+ a(this, "props");
934
+ this.type = o, this.props = t;
935
+ }
936
+ }
937
+ var Nt = /* @__PURE__ */ ((i) => (i.DOM = "$dom", i.Dynamic = "$dynamic", i.Portal = "$portal", i.Repeat = "$repeat", i))(Nt || {});
938
+ function R(i, o) {
939
+ return new st(i, o ?? {});
940
+ }
941
+ function kt(i, o, t) {
942
+ return R("$dynamic", {
943
+ source: _(() => {
944
+ const e = x(i);
945
+ return e && o ? o : !e && t ? t : null;
946
+ })
947
+ });
948
+ }
949
+ function Ot(i, o, t) {
950
+ return kt(i, t, o);
951
+ }
952
+ function Tt(i, o, t) {
953
+ return R("$repeat", { items: () => x(i), key: o, render: t });
954
+ }
955
+ function Ut(i, o) {
956
+ return R("$portal", { parent: i, content: o });
957
+ }
958
+ function ot(i, o = new f("$")) {
959
+ const t = W(o, i);
960
+ return t.length === 1 ? t[0] : new A(o, () => t);
961
+ }
962
+ function W(i, ...o) {
963
+ const t = o.flat(1 / 0), e = [];
964
+ for (const s of t)
965
+ if (!(s == null || s === !1)) {
966
+ if (s instanceof Node) {
967
+ e.push(new $(s));
968
+ continue;
969
+ }
970
+ if (s instanceof st)
971
+ if (m(s.type)) {
972
+ e.push(new X(i, s.type, s.props));
973
+ continue;
974
+ } else if (D(s.type))
975
+ switch (s.type) {
976
+ case "$dom": {
977
+ const n = s.props;
978
+ e.push(new $(n.value));
979
+ continue;
980
+ }
981
+ case "$dynamic": {
982
+ const n = s.props;
983
+ e.push(new A(i, n.source));
984
+ continue;
985
+ }
986
+ case "$portal": {
987
+ const n = s.props;
988
+ e.push(new wt(i, n.content, n.parent));
989
+ continue;
990
+ }
991
+ case "$repeat": {
992
+ const n = s.props;
993
+ e.push(new vt(i, n.items, n.key, n.render));
994
+ continue;
995
+ }
996
+ default:
997
+ e.push(new bt(i, s.type, s.props));
998
+ continue;
999
+ }
1000
+ else
1001
+ throw new TypeError(`Expected a string or view function. Got: ${s.type}`);
1002
+ if (s instanceof k) {
1003
+ e.push(s);
1004
+ continue;
1005
+ }
1006
+ if (m(s)) {
1007
+ e.push(new A(i, s));
1008
+ continue;
1009
+ }
1010
+ e.push(new $(document.createTextNode(String(s))));
1011
+ }
1012
+ return e;
1013
+ }
1014
+ export {
1015
+ f as C,
1016
+ A as D,
1017
+ g as L,
1018
+ k as M,
1019
+ X as V,
1020
+ Tt as a,
1021
+ Nt as b,
1022
+ Lt as c,
1023
+ st as d,
1024
+ R as m,
1025
+ Ut as p,
1026
+ ot as r,
1027
+ Ot as u,
1028
+ kt as w
1029
+ };
1030
+ //# sourceMappingURL=markup-CX27GJ1M.js.map