@manyducks.co/dolla 2.0.0-alpha.9 → 2.0.0

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 (108) hide show
  1. package/README.md +222 -512
  2. package/dist/core/app.d.ts +24 -0
  3. package/dist/core/context.d.ts +147 -0
  4. package/dist/core/env.d.ts +3 -0
  5. package/dist/core/hooks.d.ts +70 -0
  6. package/dist/core/hooks.test.d.ts +1 -0
  7. package/dist/core/index.d.ts +25 -0
  8. package/dist/core/logger.d.ts +42 -0
  9. package/dist/core/logger.test.d.ts +0 -0
  10. package/dist/core/markup.d.ts +82 -0
  11. package/dist/core/markup.test.d.ts +0 -0
  12. package/dist/core/nodes/_markup.d.ts +36 -0
  13. package/dist/core/nodes/dom.d.ts +13 -0
  14. package/dist/core/nodes/dynamic.d.ts +22 -0
  15. package/dist/core/nodes/element.d.ts +27 -0
  16. package/dist/core/nodes/portal.d.ts +18 -0
  17. package/dist/core/nodes/repeat.d.ts +27 -0
  18. package/dist/core/nodes/view.d.ts +25 -0
  19. package/dist/core/ref.d.ts +19 -0
  20. package/dist/core/ref.test.d.ts +1 -0
  21. package/dist/core/signals.d.ts +100 -0
  22. package/dist/core/signals.test.d.ts +1 -0
  23. package/dist/{views → core/views}/default-crash-view.d.ts +11 -4
  24. package/dist/core/views/for.d.ts +21 -0
  25. package/dist/core/views/fragment.d.ts +7 -0
  26. package/dist/core/views/portal.d.ts +16 -0
  27. package/dist/core/views/show.d.ts +25 -0
  28. package/dist/fragment-BahD_BJA.js +7 -0
  29. package/dist/fragment-BahD_BJA.js.map +1 -0
  30. package/dist/{modules/http.d.ts → http/index.d.ts} +3 -5
  31. package/dist/http.js +150 -0
  32. package/dist/http.js.map +1 -0
  33. package/dist/i18n/index.d.ts +134 -0
  34. package/dist/i18n.js +309 -0
  35. package/dist/i18n.js.map +1 -0
  36. package/dist/index-DRJlxs-Q.js +535 -0
  37. package/dist/index-DRJlxs-Q.js.map +1 -0
  38. package/dist/index.js +160 -1414
  39. package/dist/index.js.map +1 -1
  40. package/dist/jsx-dev-runtime.d.ts +3 -2
  41. package/dist/jsx-dev-runtime.js +5 -12
  42. package/dist/jsx-dev-runtime.js.map +1 -1
  43. package/dist/jsx-runtime.d.ts +4 -3
  44. package/dist/jsx-runtime.js +9 -15
  45. package/dist/jsx-runtime.js.map +1 -1
  46. package/dist/logger-Aqi9m1CF.js +565 -0
  47. package/dist/logger-Aqi9m1CF.js.map +1 -0
  48. package/dist/markup-8jNhoqDe.js +1089 -0
  49. package/dist/markup-8jNhoqDe.js.map +1 -0
  50. package/dist/router/hooks.d.ts +2 -0
  51. package/dist/router/index.d.ts +3 -0
  52. package/dist/router/router.d.ts +166 -0
  53. package/dist/{routing.d.ts → router/router.utils.d.ts} +17 -3
  54. package/dist/router/router.utils.test.d.ts +1 -0
  55. package/dist/router.js +6 -0
  56. package/dist/router.js.map +1 -0
  57. package/dist/typeChecking-5kmX0ulW.js +65 -0
  58. package/dist/typeChecking-5kmX0ulW.js.map +1 -0
  59. package/dist/typeChecking.d.ts +2 -98
  60. package/dist/typeChecking.test.d.ts +1 -0
  61. package/dist/types.d.ts +97 -25
  62. package/dist/utils.d.ts +25 -3
  63. package/docs/buildless.md +132 -0
  64. package/docs/components.md +238 -0
  65. package/docs/hooks.md +356 -0
  66. package/docs/http.md +178 -0
  67. package/docs/i18n.md +220 -0
  68. package/docs/index.md +10 -0
  69. package/docs/markup.md +136 -0
  70. package/docs/mixins.md +176 -0
  71. package/docs/ref.md +77 -0
  72. package/docs/router.md +281 -0
  73. package/docs/setup.md +137 -0
  74. package/docs/signals.md +262 -0
  75. package/docs/stores.md +113 -0
  76. package/docs/views.md +356 -0
  77. package/index.d.ts +2 -2
  78. package/notes/atomic.md +452 -0
  79. package/notes/elimination.md +33 -0
  80. package/notes/observable.md +180 -0
  81. package/notes/scratch.md +346 -14
  82. package/notes/splitting.md +5 -0
  83. package/package.json +29 -15
  84. package/vite.config.js +5 -11
  85. package/build.js +0 -34
  86. package/dist/index.d.ts +0 -21
  87. package/dist/markup.d.ts +0 -108
  88. package/dist/modules/dolla.d.ts +0 -111
  89. package/dist/modules/i18n.d.ts +0 -59
  90. package/dist/modules/render.d.ts +0 -17
  91. package/dist/modules/router.d.ts +0 -152
  92. package/dist/nodes/cond.d.ts +0 -26
  93. package/dist/nodes/html.d.ts +0 -31
  94. package/dist/nodes/observer.d.ts +0 -29
  95. package/dist/nodes/outlet.d.ts +0 -22
  96. package/dist/nodes/portal.d.ts +0 -19
  97. package/dist/nodes/repeat.d.ts +0 -34
  98. package/dist/nodes/text.d.ts +0 -19
  99. package/dist/passthrough-9kwwjgWk.js +0 -1279
  100. package/dist/passthrough-9kwwjgWk.js.map +0 -1
  101. package/dist/state.d.ts +0 -101
  102. package/dist/view.d.ts +0 -65
  103. package/dist/views/passthrough.d.ts +0 -5
  104. package/notes/context-vars.md +0 -21
  105. package/notes/readme-scratch.md +0 -222
  106. package/notes/route-middleware.md +0 -42
  107. package/tests/state.test.js +0 -135
  108. /package/dist/{routing.test.d.ts → core/context.test.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,1428 +1,174 @@
1
- var gt = Object.defineProperty;
2
- var Ze = (a) => {
3
- throw TypeError(a);
4
- };
5
- var mt = (a, e, t) => e in a ? gt(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
6
- var L = (a, e, t) => mt(a, typeof e != "symbol" ? e + "" : e, t), ze = (a, e, t) => e.has(a) || Ze("Cannot " + t);
7
- var n = (a, e, t) => (ze(a, e, "read from private field"), t ? t.call(a) : e.get(a)), h = (a, e, t) => e.has(a) ? Ze("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(a) : e.set(a, t), g = (a, e, t, r) => (ze(a, e, "write to private field"), r ? r.call(a, t) : e.set(a, t), t), P = (a, e, t) => (ze(a, e, "access private method"), t);
8
- var et = (a, e, t, r) => ({
9
- set _(i) {
10
- g(a, e, i, t);
11
- },
12
- get _() {
13
- return n(a, e, r);
14
- }
15
- });
16
- import { h as tt, c as wt, i as Ge, t as Be, a as yt, d as ae, b as bt, e as Xe, f as U, g as K, j as lt, k as vt, w as ut, P as ht, l as rt, m as $t, n as Et, v as kt, o as Lt, p as Pt, q as nt, r as at, s as St, u as Te, x as Ae, y as Rt, z as Nt, A as xt } from "./passthrough-9kwwjgWk.js";
17
- import { B as rr, C as nr, D as ar } from "./passthrough-9kwwjgWk.js";
18
- function Ot(a) {
19
- return tt`
20
- <div
21
- style=${{
22
- backgroundColor: "#880000",
23
- color: "#fff",
24
- padding: "2rem",
25
- position: "fixed",
26
- inset: 0,
27
- fontSize: "20px"
28
- }}
29
- >
30
- <h1 style=${{ marginBottom: "0.5rem" }}>The app has crashed</h1>
31
- <p style=${{ marginBottom: "0.25rem" }}>
32
- <span style=${{ fontFamily: "monospace" }}>${a.loggerName}</span>
33
- ${wt(a.uid, tt`<span style=${{ fontFamily: "monospace", opacity: 0.5 }}> [uid: ${a.uid}]</span>`)}
34
- ${" "}says:
35
- </p>
36
- <blockquote
37
- style=${{
38
- backgroundColor: "#991111",
39
- padding: "0.25em",
40
- borderRadius: "6px",
41
- fontFamily: "monospace",
42
- marginBottom: "1rem"
43
- }}
44
- >
45
- <span
46
- style=${{
47
- display: "inline-block",
48
- backgroundColor: "red",
49
- padding: "0.1em 0.4em",
50
- marginRight: "0.5em",
51
- borderRadius: "4px",
52
- fontSize: "0.9em",
53
- fontWeight: "bold"
54
- }}
55
- >
56
- ${a.error.name}
57
- </span>
58
- ${a.error.message}
59
- </blockquote>
60
-
61
- <p>Please see the browser console for details.</p>
62
- </div>
63
- `;
64
- }
65
- var J, Fe, M, C;
66
- class Mt {
67
- constructor() {
68
- h(this, M);
69
- h(this, J, []);
70
- h(this, Fe, Tt());
71
- }
72
- /**
73
- * Adds a new middleware that will apply to subsequent requests.
74
- * Returns a function to remove this middleware.
75
- *
76
- * @param middleware - A middleware function that will intercept requests.
77
- */
78
- use(e) {
79
- return n(this, J).push(e), () => {
80
- n(this, J).splice(n(this, J).indexOf(e), 1);
81
- };
82
- }
83
- async get(e, t) {
84
- return P(this, M, C).call(this, "get", e, t);
85
- }
86
- async put(e, t) {
87
- return P(this, M, C).call(this, "put", e, t);
88
- }
89
- async patch(e, t) {
90
- return P(this, M, C).call(this, "patch", e, t);
91
- }
92
- async post(e, t) {
93
- return P(this, M, C).call(this, "post", e, t);
94
- }
95
- async delete(e, t) {
96
- return P(this, M, C).call(this, "delete", e, t);
97
- }
98
- async head(e, t) {
99
- return P(this, M, C).call(this, "head", e, t);
100
- }
101
- async options(e, t) {
102
- return P(this, M, C).call(this, "options", e, t);
103
- }
104
- async trace(e, t) {
105
- return P(this, M, C).call(this, "trace", e, t);
106
- }
107
- }
108
- J = new WeakMap(), Fe = new WeakMap(), M = new WeakSet(), C = async function(e, t, r) {
109
- return Dt({
110
- ...r,
111
- method: e,
112
- uri: t,
113
- middleware: n(this, J),
114
- fetch: n(this, Fe)
115
- });
116
- };
117
- function Tt() {
118
- if (typeof window < "u" && window.fetch)
119
- return window.fetch.bind(window);
120
- if (typeof global < "u" && global.fetch)
121
- return global.fetch.bind(global);
122
- throw new Error("Running in neither browser nor node. Please run this app in one of the supported environments.");
123
- }
124
- class At extends Error {
125
- constructor(t) {
126
- const { status: r, statusText: i, method: s, uri: o } = t, f = `${r} ${i}: Request failed (${s.toUpperCase()} ${o})`;
127
- super(f);
128
- L(this, "response");
129
- this.response = t;
130
- }
131
- }
132
- async function Dt(a) {
133
- const { headers: e, query: t, fetch: r, middleware: i } = a, s = {
134
- method: a.method,
135
- uri: a.uri,
136
- get sameOrigin() {
137
- return !s.uri.startsWith("http");
1
+ import { R as f, c as d, M as g, a as w, U as y } from "./index-DRJlxs-Q.js";
2
+ import { t as b, i as x } from "./typeChecking-5kmX0ulW.js";
3
+ import { c as n, C as r, V as m, L as i, u as h, R as N, M as k, a as E, D as M } from "./markup-8jNhoqDe.js";
4
+ import { d as I, b as _, e as j, r as A, m as B, k as W, h as z, l as K, n as G, j as H, f as J, g as Q, i as X } from "./markup-8jNhoqDe.js";
5
+ import { o as S, r as u, g as l } from "./logger-Aqi9m1CF.js";
6
+ import { b as Z, i as ee, d as te, e as se, f as ne, m as ae, h as re, j as oe, k as ie, a as le, s as ce, c as ue, u as he, w as me } from "./logger-Aqi9m1CF.js";
7
+ import { F as R } from "./fragment-BahD_BJA.js";
8
+ function U(e) {
9
+ return n("div", {
10
+ style: {
11
+ backgroundColor: "#880000",
12
+ color: "#fff",
13
+ padding: "2rem",
14
+ position: "fixed",
15
+ inset: 0,
16
+ fontSize: "20px"
138
17
  },
139
- query: new URLSearchParams(),
140
- headers: new Headers(),
141
- body: a.body
142
- };
143
- if (e)
144
- if (e instanceof Map || e instanceof Headers)
145
- e.forEach((c, w) => {
146
- s.headers.set(w, c);
147
- });
148
- else if (e != null && typeof e == "object" && !Array.isArray(e))
149
- for (const c in e) {
150
- const w = e[c];
151
- w instanceof Date ? s.headers.set(c, w.toISOString()) : w != null && s.headers.set(c, String(w));
152
- }
153
- else
154
- throw new TypeError(`Unknown headers type. Got: ${e}`);
155
- if (t)
156
- if (t instanceof Map || t instanceof URLSearchParams)
157
- t.forEach((c, w) => {
158
- s.query.set(w, c);
159
- });
160
- else if (t != null && typeof t == "object" && !Array.isArray(t))
161
- for (const c in t) {
162
- const w = t[c];
163
- w instanceof Date ? s.query.set(c, w.toISOString()) : w != null && s.query.set(c, String(w));
164
- }
165
- else
166
- throw new TypeError(`Unknown query params type. Got: ${t}`);
167
- let o;
168
- const f = async () => {
169
- const c = s.query.toString(), w = c.length > 0 ? s.uri + "?" + c : s.uri;
170
- let y;
171
- !s.headers.has("content-type") && Ge(s.body) ? (s.headers.set("content-type", "application/json"), y = JSON.stringify(s.body)) : y = s.body;
172
- const m = await r(w, {
173
- method: s.method,
174
- headers: s.headers,
175
- body: y
176
- }), d = Object.fromEntries(m.headers.entries()), b = d["content-type"];
177
- let $;
178
- b != null && b.includes("application/json") ? $ = await m.json() : b != null && b.includes("application/x-www-form-urlencoded") ? $ = await m.formData() : $ = await m.text(), o = {
179
- method: s.method,
180
- uri: s.uri,
181
- status: m.status,
182
- statusText: m.statusText,
183
- headers: d,
184
- body: $
185
- };
186
- };
187
- if (i.length > 0) {
188
- const c = (w = 0) => {
189
- const y = i[w], m = i[w + 1] ? c(w + 1) : f;
190
- return async () => y(s, async () => (await m(), o));
191
- };
192
- await c()();
193
- } else
194
- await f();
195
- if (o.status < 200 || o.status >= 400)
196
- throw new At(o);
197
- return o;
198
- }
199
- class jt {
200
- constructor(e, t) {
201
- L(this, "dolla");
202
- L(this, "config");
203
- L(this, "strings");
204
- this.config = e, this.dolla = t;
205
- }
206
- async load() {
207
- if (this.strings == null) {
208
- if (Xe(this.config.fetch)) {
209
- const e = await this.config.fetch();
210
- if (Ge(e))
211
- this.strings = e;
212
- else
213
- throw new Error(`Fetch function did not return an object of language strings: ${e}`);
214
- } else if (U(this.config.path)) {
215
- const e = await this.dolla.http.get(this.config.path);
216
- if (e.status >= 200 && e.status < 300)
217
- if (Ge(e.body))
218
- this.strings = e.body;
219
- else
220
- throw new Error(
221
- `Language path '${this.config.path}' did not return an object of language strings: ${e.body}`
222
- );
223
- else
224
- throw new Error("HTTP request failed.");
225
- }
226
- }
227
- if (this.strings == null)
228
- throw new Error("Language could not be loaded.");
229
- return this.strings;
230
- }
231
- }
232
- var ye, Y, N, ie, be, ve, oe, $e, Ie, ft;
233
- class Ct {
234
- constructor(e) {
235
- h(this, Ie);
236
- h(this, ye);
237
- h(this, Y);
238
- h(this, N, /* @__PURE__ */ new Map());
239
- h(this, ie, []);
240
- h(this, be, "auto");
241
- L(this, "$locale");
242
- h(this, ve);
243
- h(this, oe);
244
- h(this, $e);
245
- g(this, ye, e), g(this, Y, e.createLogger("dolla/i18n"));
246
- const [t, r] = K(), [i, s] = K();
247
- this.$locale = t, g(this, ve, r), g(this, oe, i), g(this, $e, s), e.beforeMount(async () => {
248
- n(this, N).size > 0 && await this.setLocale(n(this, be));
249
- });
250
- }
251
- get locales() {
252
- return [...n(this, N).keys()];
253
- }
254
- setup(e) {
255
- if (e.translations.forEach((t) => {
256
- n(this, N).set(t.locale, new jt(t, n(this, ye)));
257
- }), e.locale && e.locale !== "auto") {
258
- if (!e.translations.some((r) => r.locale === e.locale))
259
- throw new Error(`Initial locale '${e.locale}' is not registered in the locales array.`);
260
- g(this, be, e.locale);
261
- }
262
- n(this, Y).info(
263
- `${n(this, N).size} language${n(this, N).size === 1 ? "" : "s"} supported: '${[...n(this, N).keys()].join("', '")}'`
264
- );
265
- }
266
- async setLocale(e) {
267
- var i;
268
- let t;
269
- if (e === "auto") {
270
- let s = [];
271
- if (typeof navigator == "object") {
272
- const o = navigator;
273
- ((i = o.languages) == null ? void 0 : i.length) > 0 ? s.push(...o.languages) : o.language ? s.push(o.language) : o.browserLanguage ? s.push(o.browserLanguage) : o.userLanguage && s.push(o.userLanguage);
274
- }
275
- for (const o of s)
276
- n(this, N).has(o) && (t = o);
277
- } else
278
- n(this, N).has(e) && (t = e);
279
- if (t == null) {
280
- const s = n(this, N).keys().next().value;
281
- s && (t = s);
282
- }
283
- if (!t || !n(this, N).has(t))
284
- throw new Error(`Language '${e}' is not configured for this app.`);
285
- const r = n(this, N).get(t);
286
- try {
287
- const s = await r.load();
288
- n(this, $e).call(this, s), n(this, ve).call(this, t), n(this, Y).info("set language to " + t);
289
- } catch (s) {
290
- s instanceof Error && n(this, Y).crash(s);
291
- }
292
- }
293
- /**
294
- * Returns a State containing the value at `key`.
295
-
296
- * @param key - Key to the translated value.
297
- * @param values - A map of {{placeholder}} names and the values to replace them with.
298
- */
299
- t(e, t) {
300
- if (this === void 0)
301
- throw new Error(
302
- `The 't' function cannot be destructured. If you need a standalone version you can import it like so: 'import { t } from "@manyducks.co/dolla"'`
303
- );
304
- if (!this.$locale.get())
305
- return qt;
306
- const r = P(this, Ie, ft).call(this, e, t);
307
- if (r)
308
- return r;
309
- if (t) {
310
- const s = {};
311
- for (const [f, c] of Object.entries(t))
312
- yt(c) && (s[f] = c);
313
- const o = Object.entries(s);
314
- if (o.length > 0) {
315
- const f = o.map((w) => w[1]), c = ae([n(this, oe), ...f], (w, ...y) => {
316
- const m = y.map(($, D) => o[D]), d = {
317
- ...t
318
- };
319
- for (let $ = 0; $ < m.length; $++) {
320
- const D = m[$][0];
321
- d[D] = y[$];
322
- }
323
- const b = it(w, e) || `[NO TRANSLATION: ${e}]`;
324
- return st(b, d);
325
- });
326
- return n(this, ie).push([e, t, c]), c;
327
- }
328
- }
329
- const i = ae([n(this, oe)], (s) => {
330
- let o = it(s, e) || `[NO TRANSLATION: ${e}]`;
331
- return t && (o = st(o, t)), o;
332
- });
333
- return n(this, ie).push([e, t, i]), i;
334
- }
335
- /**
336
- * Format a number in the current locale.
337
- */
338
- formatNumber(e, t) {
339
- return new Intl.NumberFormat(this.$locale.get(), t).format(e);
340
- }
341
- /**
342
- * Format a number in the current locale and get the result as a State that will update if the locale changes.
343
- */
344
- formatNumber$(e, t) {
345
- return ae([this.$locale, e], (r, i) => this.formatNumber(i, t));
346
- }
347
- formatDate(e, t) {
348
- return new Intl.DateTimeFormat(this.$locale.get(), t).format(new Date(e));
349
- }
350
- formatDate$(e, t) {
351
- return ae([this.$locale, e], (r, i) => this.formatDate(i, t));
352
- }
353
- formatList(e, t) {
354
- return new Intl.ListFormat(this.$locale.get(), t).format(e);
355
- }
356
- formatList$(e, t) {
357
- return ae([this.$locale, e], (r, i) => this.formatList(i, t));
358
- }
359
- }
360
- ye = new WeakMap(), Y = new WeakMap(), N = new WeakMap(), ie = new WeakMap(), be = new WeakMap(), ve = new WeakMap(), oe = new WeakMap(), $e = new WeakMap(), Ie = new WeakSet(), // formatRelativeTime(): string {
361
- // }
362
- // formatRelativeTime$(): State<string> {
363
- // }
364
- ft = function(e, t) {
365
- for (const r of n(this, ie))
366
- if (r[0] === e && bt(r[1], t))
367
- return r[2];
368
- };
369
- const qt = Be("[NO LANGUAGE SET]");
370
- function st(a, e) {
371
- for (const t in e)
372
- a = a.replace(`{{${t}}}`, String(e[t]));
373
- return a;
374
- }
375
- function it(a, e) {
376
- const t = String(e).split(/[\.\[\]]/).filter((i) => i.trim() !== "");
377
- let r = a;
378
- for (; t.length > 0; ) {
379
- const i = t.shift();
380
- r != null ? r = r[i] : r = void 0;
381
- }
382
- return r;
383
- }
384
- var X, Ee, _, H, ce, q, le, De;
385
- class Vt {
386
- constructor(e) {
387
- h(this, le);
388
- h(this, X);
389
- h(this, Ee);
390
- // Keyed updates ensure only the most recent callback queued with a certain key
391
- // will be called, keeping DOM operations to a minimum.
392
- h(this, _, /* @__PURE__ */ new Map());
393
- // All unkeyed updates are run on every batch.
394
- h(this, H, []);
395
- // All read callbacks are run before updates on every batch.
396
- h(this, ce, []);
397
- h(this, q, !1);
398
- g(this, X, e), g(this, Ee, e.createLogger("dolla/render"));
399
- }
400
- /**
401
- * Queues a callback to run in the next render batch.
402
- * Running your DOM mutations in update callbacks reduces layout thrashing.
403
- * Returns a Promise that resolves once the callback has run.
404
- */
405
- update(e, t) {
406
- return new Promise((r) => {
407
- t ? n(this, _).set(t, () => {
408
- e(), r();
409
- }) : n(this, H).push(() => {
410
- e(), r();
411
- }), !n(this, q) && n(this, X).isMounted && (g(this, q, !0), P(this, le, De).call(this));
412
- });
413
- }
414
- /**
415
- * Queues a callback that reads DOM information to run after the next render batch,
416
- * ensuring all writes have been performed before reading.
417
- * Returns a Promise that resolves once the callback has run.
418
- */
419
- async read(e) {
420
- return new Promise((t) => {
421
- n(this, ce).push(() => {
422
- e(), t();
423
- }), !n(this, q) && n(this, X).isMounted && (g(this, q, !0), P(this, le, De).call(this));
424
- });
425
- }
426
- }
427
- X = new WeakMap(), Ee = new WeakMap(), _ = new WeakMap(), H = new WeakMap(), ce = new WeakMap(), q = new WeakMap(), le = new WeakSet(), De = function() {
428
- const e = n(this, _).size + n(this, H).length;
429
- if ((!n(this, X).isMounted || e === 0) && g(this, q, !1), !n(this, q)) {
430
- for (const t of n(this, ce))
431
- t();
432
- g(this, ce, []);
433
- return;
434
- }
435
- requestAnimationFrame(() => {
436
- n(this, Ee).info(`Batching ${n(this, _).size + n(this, H).length} queued DOM update(s).`);
437
- for (const t of n(this, _).values())
438
- t();
439
- n(this, _).clear();
440
- for (const t of n(this, H))
441
- t();
442
- g(this, H, []), P(this, le, De).call(this);
18
+ children: [
19
+ n("h1", { style: { marginBottom: "0.5rem" }, children: "The app has crashed" }),
20
+ n("p", {
21
+ style: { marginBottom: "0.25rem" },
22
+ children: [
23
+ n("span", {
24
+ style: { fontFamily: "monospace" },
25
+ children: e.loggerName
26
+ }),
27
+ e.tag && n("span", {
28
+ style: { fontFamily: "monospace", opacity: 0.5 },
29
+ children: ` [${e.tagName ? `${e.tagName}: ` : ""}${e.tag}]`
30
+ }),
31
+ " says:"
32
+ ]
33
+ }),
34
+ n("blockquote", {
35
+ style: {
36
+ backgroundColor: "#991111",
37
+ padding: "0.25em",
38
+ borderRadius: "6px",
39
+ fontFamily: "monospace",
40
+ marginBottom: "1rem"
41
+ },
42
+ children: [
43
+ n("span", {
44
+ style: {
45
+ display: "inline-block",
46
+ backgroundColor: "red",
47
+ padding: "0.1em 0.4em",
48
+ marginRight: "0.5em",
49
+ borderRadius: "4px",
50
+ fontSize: "0.9em",
51
+ fontWeight: "bold"
52
+ },
53
+ children: e.error.name
54
+ }),
55
+ e.error.message
56
+ ]
57
+ }),
58
+ n("p", { children: "Please see the browser console for details." })
59
+ ]
443
60
  });
444
- };
445
- function de() {
446
- return de = Object.assign ? Object.assign.bind() : function(a) {
447
- for (var e = 1; e < arguments.length; e++) {
448
- var t = arguments[e];
449
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (a[r] = t[r]);
450
- }
451
- return a;
452
- }, de.apply(null, arguments);
453
- }
454
- var A;
455
- (function(a) {
456
- a.Pop = "POP", a.Push = "PUSH", a.Replace = "REPLACE";
457
- })(A || (A = {}));
458
- var Ve = process.env.NODE_ENV !== "production" ? function(a) {
459
- return Object.freeze(a);
460
- } : function(a) {
461
- return a;
462
- };
463
- function je(a, e) {
464
- if (!a) {
465
- typeof console < "u" && console.warn(e);
466
- try {
467
- throw new Error(e);
468
- } catch {
469
- }
470
- }
471
61
  }
472
- var Ue = "beforeunload", Ut = "hashchange", dt = "popstate";
473
- function _t(a) {
474
- a === void 0 && (a = {});
475
- var e = a, t = e.window, r = t === void 0 ? document.defaultView : t, i = r.history;
476
- function s() {
477
- var p = r.location, l = p.pathname, u = p.search, v = p.hash, E = i.state || {};
478
- return [E.idx, Ve({
479
- pathname: l,
480
- search: u,
481
- hash: v,
482
- state: E.usr || null,
483
- key: E.key || "default"
484
- })];
485
- }
486
- var o = null;
487
- function f() {
488
- if (o)
489
- b.call(o), o = null;
490
- else {
491
- var p = A.Pop, l = s(), u = l[0], v = l[1];
492
- if (b.length)
493
- if (u != null) {
494
- var E = y - u;
495
- E && (o = {
496
- action: p,
497
- location: v,
498
- retry: function() {
499
- V(E * -1);
500
- }
501
- }, V(E));
502
- } else
503
- process.env.NODE_ENV !== "production" && je(
504
- !1,
505
- // TODO: Write up a doc that explains our blocking strategy in
506
- // detail and link to it here so people can understand better what
507
- // is going on and how to avoid it.
508
- "You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."
509
- );
510
- else
511
- re(p);
512
- }
513
- }
514
- r.addEventListener(dt, f);
515
- var c = A.Pop, w = s(), y = w[0], m = w[1], d = He(), b = He();
516
- y == null && (y = 0, i.replaceState(de({}, i.state, {
517
- idx: y
518
- }), ""));
519
- function $(p) {
520
- return typeof p == "string" ? p : Ce(p);
62
+ class c {
63
+ #n;
64
+ #e;
65
+ #r;
66
+ #t;
67
+ #s = !1;
68
+ #o = U;
69
+ #a = [];
70
+ get context() {
71
+ return this.#e;
521
72
  }
522
- function D(p, l) {
523
- return l === void 0 && (l = null), Ve(de({
524
- pathname: m.pathname,
525
- hash: "",
526
- search: ""
527
- }, typeof p == "string" ? Qe(p) : p, {
528
- state: l,
529
- key: pt()
530
- }));
531
- }
532
- function pe(p, l) {
533
- return [{
534
- usr: p.state,
535
- key: p.key,
536
- idx: l
537
- }, $(p)];
538
- }
539
- function ge(p, l, u) {
540
- return !b.length || (b.call({
541
- action: p,
542
- location: l,
543
- retry: u
544
- }), !1);
545
- }
546
- function re(p) {
547
- c = p;
548
- var l = s();
549
- y = l[0], m = l[1], d.call({
550
- action: c,
551
- location: m
552
- });
553
- }
554
- function ne(p, l) {
555
- var u = A.Push, v = D(p, l);
556
- function E() {
557
- ne(p, l);
558
- }
559
- if (ge(u, v, E)) {
560
- var S = pe(v, y + 1), x = S[0], T = S[1];
561
- try {
562
- i.pushState(x, "", T);
563
- } catch {
564
- r.location.assign(T);
565
- }
566
- re(u);
567
- }
568
- }
569
- function me(p, l) {
570
- var u = A.Replace, v = D(p, l);
571
- function E() {
572
- me(p, l);
573
- }
574
- if (ge(u, v, E)) {
575
- var S = pe(v, y), x = S[0], T = S[1];
576
- i.replaceState(x, "", T), re(u);
577
- }
578
- }
579
- function V(p) {
580
- i.go(p);
73
+ constructor(t) {
74
+ this.#r = t.view ?? R, this.#t = t.router, this.#e = t.context ?? new r("App");
581
75
  }
582
- var Q = {
583
- get action() {
584
- return c;
585
- },
586
- get location() {
587
- return m;
588
- },
589
- createHref: $,
590
- push: ne,
591
- replace: me,
592
- go: V,
593
- back: function() {
594
- V(-1);
595
- },
596
- forward: function() {
597
- V(1);
598
- },
599
- listen: function(l) {
600
- return d.push(l);
601
- },
602
- block: function(l) {
603
- var u = b.push(l);
604
- return b.length === 1 && r.addEventListener(Ue, _e), function() {
605
- u(), b.length || r.removeEventListener(Ue, _e);
606
- };
607
- }
608
- };
609
- return Q;
610
- }
611
- function Ht(a) {
612
- a === void 0 && (a = {});
613
- var e = a, t = e.window, r = t === void 0 ? document.defaultView : t, i = r.history;
614
- function s() {
615
- var l = Qe(r.location.hash.substr(1)), u = l.pathname, v = u === void 0 ? "/" : u, E = l.search, S = E === void 0 ? "" : E, x = l.hash, T = x === void 0 ? "" : x, j = i.state || {};
616
- return [j.idx, Ve({
617
- pathname: v,
618
- search: S,
619
- hash: T,
620
- state: j.usr || null,
621
- key: j.key || "default"
622
- })];
76
+ setCrashView(t) {
77
+ return this.#o = t, this;
623
78
  }
624
- var o = null;
625
- function f() {
626
- if (o)
627
- b.call(o), o = null;
628
- else {
629
- var l = A.Pop, u = s(), v = u[0], E = u[1];
630
- if (b.length)
631
- if (v != null) {
632
- var S = y - v;
633
- S && (o = {
634
- action: l,
635
- location: E,
636
- retry: function() {
637
- Q(S * -1);
638
- }
639
- }, Q(S));
640
- } else
641
- process.env.NODE_ENV !== "production" && je(
642
- !1,
643
- // TODO: Write up a doc that explains our blocking strategy in
644
- // detail and link to it here so people can understand better
645
- // what is going on and how to avoid it.
646
- "You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."
647
- );
648
- else
649
- ne(l);
650
- }
79
+ async mount(t) {
80
+ if (this.#s) return Promise.resolve();
81
+ const s = this.#i(t);
82
+ this.#a.push(
83
+ S((a) => {
84
+ this.#s && this.unmount(), new m(this.#e, this.#o, a).mount(s);
85
+ })
86
+ ), r.emit(this.#e, i.WILL_MOUNT), this.#t ? (this.#n = await this.#t[g](s, this.#e), this.#e.setState(w, this.#t)) : this.#n = new m(this.#e, this.#r, {}), this.#n.mount(s), this.#s = !0, r.emit(this.#e, i.DID_MOUNT);
651
87
  }
652
- r.addEventListener(dt, f), r.addEventListener(Ut, function() {
653
- var l = s(), u = l[1];
654
- Ce(u) !== Ce(m) && f();
88
+ async unmount() {
89
+ if (!this.#s) return Promise.resolve();
90
+ r.emit(this.#e, i.WILL_UNMOUNT), this.#s = !1, this.#n.unmount(!1), this.#t && await this.#t[y]();
91
+ for (const t of this.#a)
92
+ t();
93
+ this.#a = [], r.emit(this.#e, i.DID_UNMOUNT);
94
+ }
95
+ #i(t) {
96
+ if (typeof t == "string") {
97
+ const s = document.querySelector(t);
98
+ if (!s)
99
+ throw new Error(`Selector '${t}' did not many any element.`);
100
+ return s;
101
+ } else {
102
+ if (t instanceof Element)
103
+ return t;
104
+ throw new Error("Expected a selector string or DOM element.");
105
+ }
106
+ }
107
+ }
108
+ function D(e, t) {
109
+ return e instanceof f ? new c({ ...t, router: e }) : b(e) === "object" ? new c({ ...t, router: d(e) }) : new c({ ...t, view: e });
110
+ }
111
+ const v = (e) => e;
112
+ function P(e) {
113
+ const t = h("For");
114
+ return new N(t, u(e.each), e.key ?? v, e.children);
115
+ }
116
+ function p(e) {
117
+ const t = h("Portal");
118
+ if (x(e.into)) {
119
+ if (document.querySelector(e.into) == null)
120
+ throw t.crash(new Error(`Portal: selector '${e.into}' did not match any element`));
121
+ } else
122
+ e.into;
123
+ return new k(E.Portal, {
124
+ parent: e.into,
125
+ content: e.children
655
126
  });
656
- var c = A.Pop, w = s(), y = w[0], m = w[1], d = He(), b = He();
657
- y == null && (y = 0, i.replaceState(de({}, i.state, {
658
- idx: y
659
- }), ""));
660
- function $() {
661
- var l = document.querySelector("base"), u = "";
662
- if (l && l.getAttribute("href")) {
663
- var v = r.location.href, E = v.indexOf("#");
664
- u = E === -1 ? v : v.slice(0, E);
665
- }
666
- return u;
667
- }
668
- function D(l) {
669
- return $() + "#" + (typeof l == "string" ? l : Ce(l));
670
- }
671
- function pe(l, u) {
672
- return u === void 0 && (u = null), Ve(de({
673
- pathname: m.pathname,
674
- hash: "",
675
- search: ""
676
- }, typeof l == "string" ? Qe(l) : l, {
677
- state: u,
678
- key: pt()
679
- }));
680
- }
681
- function ge(l, u) {
682
- return [{
683
- usr: l.state,
684
- key: l.key,
685
- idx: u
686
- }, D(l)];
687
- }
688
- function re(l, u, v) {
689
- return !b.length || (b.call({
690
- action: l,
691
- location: u,
692
- retry: v
693
- }), !1);
694
- }
695
- function ne(l) {
696
- c = l;
697
- var u = s();
698
- y = u[0], m = u[1], d.call({
699
- action: c,
700
- location: m
701
- });
702
- }
703
- function me(l, u) {
704
- var v = A.Push, E = pe(l, u);
705
- function S() {
706
- me(l, u);
707
- }
708
- if (process.env.NODE_ENV !== "production" && je(E.pathname.charAt(0) === "/", "Relative pathnames are not supported in hash history.push(" + JSON.stringify(l) + ")"), re(v, E, S)) {
709
- var x = ge(E, y + 1), T = x[0], j = x[1];
710
- try {
711
- i.pushState(T, "", j);
712
- } catch {
713
- r.location.assign(j);
714
- }
715
- ne(v);
716
- }
717
- }
718
- function V(l, u) {
719
- var v = A.Replace, E = pe(l, u);
720
- function S() {
721
- V(l, u);
722
- }
723
- if (process.env.NODE_ENV !== "production" && je(E.pathname.charAt(0) === "/", "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(l) + ")"), re(v, E, S)) {
724
- var x = ge(E, y), T = x[0], j = x[1];
725
- i.replaceState(T, "", j), ne(v);
726
- }
727
- }
728
- function Q(l) {
729
- i.go(l);
730
- }
731
- var p = {
732
- get action() {
733
- return c;
734
- },
735
- get location() {
736
- return m;
737
- },
738
- createHref: D,
739
- push: me,
740
- replace: V,
741
- go: Q,
742
- back: function() {
743
- Q(-1);
744
- },
745
- forward: function() {
746
- Q(1);
747
- },
748
- listen: function(u) {
749
- return d.push(u);
750
- },
751
- block: function(u) {
752
- var v = b.push(u);
753
- return b.length === 1 && r.addEventListener(Ue, _e), function() {
754
- v(), b.length || r.removeEventListener(Ue, _e);
755
- };
756
- }
757
- };
758
- return p;
759
- }
760
- function _e(a) {
761
- a.preventDefault(), a.returnValue = "";
762
- }
763
- function He() {
764
- var a = [];
765
- return {
766
- get length() {
767
- return a.length;
768
- },
769
- push: function(t) {
770
- return a.push(t), function() {
771
- a = a.filter(function(r) {
772
- return r !== t;
773
- });
774
- };
775
- },
776
- call: function(t) {
777
- a.forEach(function(r) {
778
- return r && r(t);
779
- });
780
- }
781
- };
782
- }
783
- function pt() {
784
- return Math.random().toString(36).substr(2, 8);
785
- }
786
- function Ce(a) {
787
- var e = a.pathname, t = e === void 0 ? "/" : e, r = a.search, i = r === void 0 ? "" : r, s = a.hash, o = s === void 0 ? "" : s;
788
- return i && i !== "?" && (t += i.charAt(0) === "?" ? i : "?" + i), o && o !== "#" && (t += o.charAt(0) === "#" ? o : "#" + o), t;
789
- }
790
- function Qe(a) {
791
- var e = {};
792
- if (a) {
793
- var t = a.indexOf("#");
794
- t >= 0 && (e.hash = a.substr(t), a = a.substr(0, t));
795
- var r = a.indexOf("?");
796
- r >= 0 && (e.search = a.substr(r), a = a.substr(0, r)), a && (e.pathname = a);
797
- }
798
- return e;
799
- }
800
- function we(a) {
801
- return lt(a, "Expected `path` to be a string. Got type: %t, value: %v"), a.split("/").map((e) => e.trim()).filter((e) => e !== "");
802
127
  }
803
- function se(a) {
804
- var t;
805
- vt(
806
- (r) => Xe(r == null ? void 0 : r.toString),
807
- a,
808
- "Expected `parts` to be an array of objects with a .toString() method. Got type: %t, value: %v"
809
- ), a = a.filter((r) => r).flatMap(String);
810
- let e = (t = a.shift()) == null ? void 0 : t.toString();
811
- if (e) {
812
- for (const r of a.map((i) => i.toString()))
813
- r.startsWith(".") ? e = qe(e, r) : e[e.length - 1] !== "/" ? r[0] !== "/" ? e += "/" + r : e += r : r[0] === "/" ? e += r.slice(1) : e += r;
814
- e && e !== "/" && e.endsWith("/") && (e = e.slice(0, e.length - 1));
815
- }
816
- return e ?? "";
817
- }
818
- function qe(a, e) {
819
- if (lt(a, "Expected `base` to be a string. Got type: %t, value: %v"), e == null && (e = a, a = ""), e.startsWith("/"))
820
- return e;
821
- let t = a;
822
- for (; ; )
823
- if (e.startsWith("..")) {
824
- for (let r = t.length; r > 0; --r)
825
- if (t[r] === "/" || r === 0) {
826
- t = t.slice(0, r), e = e.replace(/^\.\.\/?/, "");
827
- break;
828
- }
829
- } else if (e.startsWith("."))
830
- e = e.replace(/^\.\/?/, "");
831
- else
832
- break;
833
- return se([t, e]);
834
- }
835
- function Ke(a) {
836
- if (!a) return {};
837
- a.startsWith("?") && (a = a.slice(1));
838
- const e = a.split("&").filter((t) => t.trim() !== "").map((t) => {
839
- const [r, i] = t.split("=").map((s) => s.trim());
840
- return i.toLowerCase() === "true" ? [r, !0] : i.toLowerCase() === "false" ? [r, !1] : isNaN(Number(i)) ? [r, i] : [r, Number(i)];
128
+ function q(e) {
129
+ const t = h("Show"), s = e.when ? u(e.when) : null, a = e.unless ? u(e.unless) : null;
130
+ return new M(t, () => {
131
+ let o = !0;
132
+ return s != null && a != null ? o = l(s) && !l(a) : s != null ? o = l(s) : a != null && (o = !l(a)), o ? e.children : e.fallback;
841
133
  });
842
- return Object.fromEntries(e);
843
- }
844
- function ot(a, e, t = {}) {
845
- var o;
846
- const [r, i] = e.split("?"), s = we(r);
847
- e: for (const f of a) {
848
- const { fragments: c } = f;
849
- if (!(((o = c[c.length - 1]) == null ? void 0 : o.type) === 3) && c.length !== s.length || t.willMatch && !t.willMatch(f))
850
- continue e;
851
- const y = [];
852
- t: for (let d = 0; d < c.length; d++) {
853
- const b = s[d], $ = c[d];
854
- if (b == null && $.type !== 3)
855
- continue e;
856
- switch ($.type) {
857
- case 1:
858
- if ($.name.toLowerCase() === b.toLowerCase()) {
859
- y.push($);
860
- break;
861
- } else
862
- continue e;
863
- case 2:
864
- y.push({ ...$, value: b });
865
- break;
866
- case 3:
867
- y.push({ ...$, value: s.slice(d).join("/") });
868
- break t;
869
- case 4:
870
- if (isNaN(Number(b)))
871
- continue e;
872
- y.push({ ...$, value: Number(b) });
873
- break;
874
- default:
875
- throw new Error(`Unknown fragment type: ${$.type}`);
876
- }
877
- }
878
- const m = /* @__PURE__ */ Object.create(null);
879
- for (const d of y)
880
- d.type === 2 && (m[d.name] = decodeURIComponent(d.value)), d.type === 4 && (m[d.name] = d.value), d.type === 3 && (m.wildcard = "/" + decodeURIComponent(d.value));
881
- return {
882
- path: "/" + y.map((d) => d.value).join("/"),
883
- pattern: "/" + c.map((d) => d.type === 2 ? `{${d.name}}` : d.type === 4 ? `{#${d.name}}` : d.name).join("/"),
884
- params: m,
885
- query: Ke(i),
886
- meta: f.meta
887
- };
888
- }
889
- }
890
- function Ft(a) {
891
- const e = [], t = [], r = [], i = [];
892
- for (const o of a) {
893
- const { fragments: f } = o;
894
- f.some(
895
- (c) => c.type === 3
896
- /* Wildcard */
897
- ) ? i.push(o) : f.some(
898
- (c) => c.type === 4
899
- /* NumericParam */
900
- ) ? t.push(o) : f.some(
901
- (c) => c.type === 2
902
- /* Param */
903
- ) ? r.push(o) : e.push(o);
904
- }
905
- const s = (o, f) => o.fragments.length > f.fragments.length ? -1 : 1;
906
- return e.sort(s), t.sort(s), r.sort(s), i.sort(s), [...e, ...t, ...r, ...i];
907
- }
908
- function It(a) {
909
- const e = we(a), t = [];
910
- for (let r = 0; r < e.length; r++) {
911
- const i = e[r];
912
- if (i === "*") {
913
- if (r !== e.length - 1)
914
- throw new Error(`Wildcard must be at the end of a pattern. Received: ${a}`);
915
- t.push({
916
- type: 3,
917
- name: "*",
918
- value: null
919
- });
920
- } else i.at(0) === "{" && i.at(-1) === "}" ? t.push({
921
- type: i[1] === "#" ? 4 : 2,
922
- name: i[1] === "#" ? i.slice(2, -1) : i.slice(1, -1),
923
- value: null
924
- }) : t.push({
925
- type: 1,
926
- name: i,
927
- value: i
928
- });
929
- }
930
- return t;
931
- }
932
- var ke, O, Z, k, We, F, Le, ee, I, ue, he, fe, Pe, B, Je, Ye;
933
- class Wt {
934
- constructor(e, t) {
935
- h(this, B);
936
- h(this, ke);
937
- h(this, O);
938
- h(this, Z);
939
- h(this, k);
940
- h(this, We, 0);
941
- h(this, F, []);
942
- h(this, Le);
943
- h(this, ee, []);
944
- // Callbacks that need to be called on unmount.
945
- h(this, I, []);
946
- /**
947
- * The currently matched route pattern, if any.
948
- */
949
- L(this, "$pattern");
950
- h(this, ue);
951
- /**
952
- * The current URL path.
953
- */
954
- L(this, "$path");
955
- h(this, he);
956
- /**
957
- * The current named path params.
958
- */
959
- L(this, "$params");
960
- h(this, fe);
961
- /**
962
- * The current query params. Changes to this object will be reflected in the URL.
963
- */
964
- L(this, "$query");
965
- h(this, Pe);
966
- g(this, ke, e), g(this, O, e.createLogger("dolla/router")), g(this, Z, t);
967
- const [r, i] = K(null), [s, o] = K(""), [f, c] = K({}), [w, y] = K(
968
- Ke(typeof window > "u" ? "" : window.location.search ?? "")
969
- );
970
- this.$pattern = r, g(this, ue, i), this.$path = s, g(this, he, o), this.$params = f, g(this, fe, c), this.$query = w, g(this, Pe, y), e.beforeMount(() => {
971
- n(this, k) != null && (n(this, I).push(
972
- ut([w], (m) => {
973
- const d = new URLSearchParams();
974
- for (const $ in m)
975
- d.set($, String(m[$]));
976
- const b = "?" + d.toString();
977
- b != n(this, k).location.search && n(this, k).replace({
978
- pathname: n(this, k).location.pathname,
979
- search: b
980
- });
981
- })
982
- ), n(this, I).push(n(this, k).listen(P(this, B, Ye).bind(this))), P(this, B, Ye).call(this, n(this, k)), n(this, I).push(
983
- Bt(n(this, Z).rootElement, (m) => {
984
- let d = m.getAttribute("href");
985
- n(this, O).info("Intercepted link click", m, d), /^https?:\/\/|^\//.test(d) || (d = se([n(this, k).location.pathname, d])), n(this, k).push(d);
986
- })
987
- ), n(this, O).info("Intercepting <a> clicks within root element:", n(this, Z).rootElement));
988
- }), e.onUnmount(() => {
989
- for (; n(this, I).length > 0; )
990
- n(this, I).pop()();
991
- });
992
- }
993
- setup(e) {
994
- if (n(this, ke).isMounted) {
995
- n(this, O).crash(
996
- new Error("Dolla is already mounted. Router setup must be called before Dolla.mount is called.")
997
- );
998
- return;
999
- }
1000
- e.style === "hash" ? g(this, k, Ht()) : g(this, k, _t()), g(this, ee, Ft(
1001
- e.routes.flatMap((t) => P(this, B, Je).call(this, t)).map((t) => ({
1002
- pattern: t.pattern,
1003
- meta: t.meta,
1004
- fragments: It(t.pattern)
1005
- }))
1006
- ));
1007
- for (const t of n(this, ee))
1008
- if (t.meta.redirect) {
1009
- let r;
1010
- if (!Xe(t.meta.redirect)) if (U(t.meta.redirect)) {
1011
- if (r = t.meta.redirect, !ot(n(this, ee), r, {
1012
- willMatch(s) {
1013
- return s !== t;
1014
- }
1015
- }))
1016
- throw new Error(
1017
- `Found a redirect to an undefined URL. From '${t.pattern}' to '${t.meta.redirect}'`
1018
- );
1019
- } else
1020
- throw new TypeError(`Expected a string or redirect function. Got: ${t.meta.redirect}`);
1021
- }
1022
- }
1023
- /**
1024
- * Navigates to another route.
1025
- *
1026
- * @example
1027
- * navigate("/login"); // navigate to `/login`
1028
- * navigate(["/users", 215], { replace: true }); // replace current history entry with `/users/215`
1029
- */
1030
- go(e, t = {}) {
1031
- if (n(this, k) == null) {
1032
- n(this, O).crash(
1033
- new Error(
1034
- "Router.go was called, but the router was never configured! Run 'Dolla.router.setup' before 'Dolla.mount' to configure routes."
1035
- )
1036
- );
1037
- return;
1038
- }
1039
- let r;
1040
- Array.isArray(e) ? r = se(e) : r = e.toString(), r = qe(n(this, k).location.pathname, r), t.preserveQuery && (r += n(this, k).location.search), t.replace ? n(this, k).replace(r) : n(this, k).push(r);
1041
- }
1042
- /**
1043
- * Navigate backward. Pass a number of steps to hit the back button that many times.
1044
- */
1045
- back(e = 1) {
1046
- if (n(this, k) == null) {
1047
- n(this, O).crash(
1048
- new Error(
1049
- "Router.back was called, but the router was never configured! Run 'Dolla.router.setup' before 'Dolla.mount' to configure routes."
1050
- )
1051
- );
1052
- return;
1053
- }
1054
- n(this, k).go(-e);
1055
- }
1056
- /**
1057
- * Navigate forward. Pass a number of steps to hit the forward button that many times.
1058
- */
1059
- forward(e = 1) {
1060
- if (n(this, k) == null) {
1061
- n(this, O).crash(
1062
- new Error(
1063
- "Router.forward was called, but the router was never configured! Run 'Dolla.router.setup' before 'Dolla.mount' to configure routes."
1064
- )
1065
- );
1066
- return;
1067
- }
1068
- n(this, k).go(e);
1069
- }
1070
- }
1071
- ke = new WeakMap(), O = new WeakMap(), Z = new WeakMap(), k = new WeakMap(), We = new WeakMap(), F = new WeakMap(), Le = new WeakMap(), ee = new WeakMap(), I = new WeakMap(), ue = new WeakMap(), he = new WeakMap(), fe = new WeakMap(), Pe = new WeakMap(), B = new WeakSet(), /**
1072
- * Parses a route definition object into a set of matchable routes.
1073
- *
1074
- * @param route - Route config object.
1075
- * @param layers - Array of parent layers. Passed when this function calls itself on nested routes.
1076
- */
1077
- Je = function(e, t = [], r = []) {
1078
- if (!(typeof e == "object" && !Array.isArray(e)) || typeof e.path != "string")
1079
- throw new TypeError(`Route configs must be objects with a 'path' string property. Got: ${e}`);
1080
- if (e.redirect && e.routes)
1081
- throw new Error("Route cannot have both a 'redirect' and nested 'routes'.");
1082
- if (e.redirect && e.view)
1083
- throw new Error("Route cannot have both a 'redirect' and a 'view'.");
1084
- if (!e.view && !e.routes && !e.redirect)
1085
- throw new Error("Route must have a 'view', a 'redirect', or a set of nested 'routes'.");
1086
- let i = [];
1087
- for (const c of t)
1088
- i.push(...we(c.path));
1089
- i.push(...we(e.path)), i[i.length - 1] === "*" && i.pop();
1090
- const s = [];
1091
- if (e.redirect) {
1092
- let c = e.redirect;
1093
- return U(c) && (c = qe(se(i), c), c.startsWith("/") || (c = "/" + c)), s.push({
1094
- pattern: "/" + se([...i, ...we(e.path)]),
1095
- meta: {
1096
- redirect: c
1097
- }
1098
- }), s;
1099
- }
1100
- let o = ht;
1101
- if (typeof e.view == "function")
1102
- o = e.view;
1103
- else if (e.view)
1104
- throw new TypeError(`Route '${e.path}' expected a view function or undefined. Got: ${e.view}`);
1105
- const f = { id: et(this, We)._++, view: o };
1106
- if (e.routes)
1107
- for (const c of e.routes)
1108
- s.push(...P(this, B, Je).call(this, c, [...t, e], [...r, f]));
1109
- else
1110
- s.push({
1111
- pattern: parent ? se([...t.map((c) => c.path), e.path]) : e.path,
1112
- meta: {
1113
- pattern: e.path,
1114
- layers: [...r, f],
1115
- beforeMatch: e.beforeMatch
1116
- }
1117
- });
1118
- return s;
1119
- }, Ye = async function({ location: e }) {
1120
- e.search !== n(this, Le) && (g(this, Le, e.search), n(this, Pe).call(this, Ke(e.search)));
1121
- const t = ot(n(this, ee), e.pathname);
1122
- if (!t) {
1123
- n(this, ue).call(this, null), n(this, he).call(this, e.pathname), n(this, fe).call(this, {
1124
- wildcard: e.pathname
1125
- });
1126
- return;
1127
- }
1128
- if (t.meta.beforeMatch && await t.meta.beforeMatch({
1129
- // TODO: Allow setting context variables from here.
1130
- redirect: (r) => {
1131
- throw new Error("Redirect not yet implemented.");
1132
- }
1133
- }), t.meta.redirect != null)
1134
- if (typeof t.meta.redirect == "string") {
1135
- const r = Qt(t.meta.redirect, t.params);
1136
- n(this, O).info(`↩️ redirecting from '${t.path}' to '${r}'`), n(this, k).replace(r);
1137
- } else if (typeof t.meta.redirect == "function") {
1138
- const r = {
1139
- path: t.path,
1140
- pattern: t.pattern,
1141
- params: t.params,
1142
- query: t.query
1143
- };
1144
- let i = await t.meta.redirect(r);
1145
- if (typeof i != "string")
1146
- throw new Error("Redirect function must return a path to redirect to.");
1147
- i.startsWith("/") || (i = qe(t.path, i)), n(this, O).info(`Redirecting to: '${i}'`), n(this, k).replace(i);
1148
- } else
1149
- throw new TypeError("Redirect must either be a path string or a function.");
1150
- else if (n(this, O).info(`📍 navigating to '${t.path}'`), n(this, he).call(this, t.path), n(this, fe).call(this, t.params), t.pattern !== this.$pattern.get()) {
1151
- n(this, ue).call(this, t.pattern);
1152
- const r = t.meta.layers;
1153
- for (let i = 0; i < r.length; i++) {
1154
- const s = r[i], o = n(this, F)[i];
1155
- if ((o == null ? void 0 : o.id) !== s.id) {
1156
- g(this, F, n(this, F).slice(0, i));
1157
- const f = n(this, F).at(-1);
1158
- o && o.node.isMounted && o.node.unmount();
1159
- let c;
1160
- f ? c = f.node.setChildView(s.view) : c = n(this, Z).rootView.setChildView(s.view), n(this, F).push({ id: s.id, node: c });
1161
- }
1162
- }
1163
- }
1164
- };
1165
- const zt = /(noopener|noreferrer) (noopener|noreferrer)/, Gt = /^[\w-_]+:/;
1166
- function Bt(a, e, t = window) {
1167
- function r(s) {
1168
- return !s || s === a ? null : s.localName !== "a" || s.href === void 0 ? r(s.parentNode) : s;
1169
- }
1170
- function i(s) {
1171
- if (s.button && s.button !== 0 || s.ctrlKey || s.metaKey || s.altKey || s.shiftKey || s.defaultPrevented)
1172
- return;
1173
- const o = r(s.target);
1174
- o && (t.location.protocol !== o.protocol || t.location.hostname !== o.hostname || t.location.port !== o.port || o.hasAttribute("data-router-ignore") || o.hasAttribute("download") || o.getAttribute("target") === "_blank" && zt.test(o.getAttribute("rel")) || Gt.test(o.getAttribute("href")) || (s.preventDefault(), e(o)));
1175
- }
1176
- return a.addEventListener("click", i), function() {
1177
- a.removeEventListener("click", i);
1178
- };
1179
- }
1180
- function Qt(a, e) {
1181
- for (const t in e) {
1182
- const r = e[t].toString();
1183
- a = a.replace(`{${t}}`, r).replace(`{#${t}}`, r);
1184
- }
1185
- return a;
1186
- }
1187
- var W, Se, z, te, Re, Ne, xe, Oe, Me, R, G;
1188
- class Kt {
1189
- constructor() {
1190
- L(this, "http");
1191
- L(this, "i18n");
1192
- L(this, "render");
1193
- L(this, "router");
1194
- h(this, W, !1);
1195
- h(this, Se, "production");
1196
- h(this, z);
1197
- h(this, te);
1198
- h(this, Re, Ot);
1199
- h(this, Ne, []);
1200
- h(this, xe, []);
1201
- h(this, Oe, []);
1202
- h(this, Me, []);
1203
- h(this, R, {
1204
- info: "development",
1205
- log: "development",
1206
- warn: "development",
1207
- error: !0
1208
- });
1209
- h(this, G, rt("*,-dolla/*"));
1210
- L(this, "createState", K);
1211
- L(this, "createSettableState", $t);
1212
- L(this, "toSettableState", Et);
1213
- L(this, "toState", Be);
1214
- L(this, "valueOf", kt);
1215
- L(this, "derive", ae);
1216
- L(this, "watch", ut);
1217
- L(this, "createRef", Lt);
1218
- L(this, "isRef", Pt);
1219
- const e = this;
1220
- this.http = new Mt(), this.i18n = new Ct(this), this.render = new Vt(this), this.router = new Wt(this, {
1221
- get rootElement() {
1222
- return n(e, z);
1223
- },
1224
- get rootView() {
1225
- return n(e, te);
1226
- }
1227
- });
1228
- }
1229
- /**
1230
- * True when the app is connected to a DOM node and displayed to the user.
1231
- */
1232
- get isMounted() {
1233
- return n(this, W);
1234
- }
1235
- /**
1236
- * Get the current environment that this app is running in.
1237
- * Environment affects which log messages will print and how much debugging info is included in the DOM.
1238
- */
1239
- getEnv() {
1240
- return n(this, Se);
1241
- }
1242
- /**
1243
- * Sets the environment that this app is running in.
1244
- * Environment affects which log messages will print and how much debugging info is included in the DOM.
1245
- */
1246
- setEnv(e) {
1247
- g(this, Se, e);
1248
- }
1249
- /**
1250
- * Sets the view that will be shown when the `crash` method is called on any logger.
1251
- * When a crash is reported the app will be unmounted and replaced with this crash page.
1252
- */
1253
- setCrashView(e) {
1254
- g(this, Re, e);
1255
- }
1256
- async mount(e, t) {
1257
- if (n(this, W))
1258
- throw new Error("Dolla is already mounted.");
1259
- if (U(e)) {
1260
- const i = document.querySelector(e);
1261
- nt(HTMLElement, i, `Selector '${e}' did not match any element.`), g(this, z, i);
1262
- } else
1263
- nt(HTMLElement, e, "Expected an HTML element or a selector string. Got type: %t, value: %v"), g(this, z, e);
1264
- let r;
1265
- t ? r = at(t) : r = at(ht), g(this, te, this.constructView(r.type, r.props)), await Promise.all(n(this, Ne).map((i) => i())), n(this, te).mount(n(this, z)), g(this, W, !0);
1266
- for (const i of n(this, xe))
1267
- i();
1268
- }
1269
- async unmount() {
1270
- var e;
1271
- if (n(this, W)) {
1272
- await Promise.all(n(this, Oe).map((t) => t())), (e = n(this, te)) == null || e.unmount(), g(this, W, !1);
1273
- for (const t of n(this, Me))
1274
- t();
1275
- }
1276
- }
1277
- /**
1278
- * Registers a `callback` to run after `Dolla.mount` is called, before the app is mounted. If `callback` returns a Promise,
1279
- * it will be awaited before mounting finishes. Use this to perform initial setup before the app is displayed to the user.
1280
- */
1281
- beforeMount(e) {
1282
- n(this, Ne).push(e);
1283
- }
1284
- /**
1285
- * Registers a `callback` to run after the app is mounted.
1286
- */
1287
- onMount(e) {
1288
- n(this, xe).push(e);
1289
- }
1290
- /**
1291
- * Registers a `callback` to run after `Dolla.unmount` is called, before the app is unmounted. If `callback` returns a Promise,
1292
- * it will be awaited before unmounting finishes. Use this to perform cleanup.
1293
- */
1294
- beforeUnmount(e) {
1295
- n(this, Oe).push(e);
1296
- }
1297
- /**
1298
- * Registers a `callback` to run after the app is unmounted.
1299
- */
1300
- onUnmount(e) {
1301
- n(this, Me).push(e);
1302
- }
1303
- /**
1304
- * Update log type toggles. Values that are not passed will remain unchanged.
1305
- */
1306
- setLoggles(e) {
1307
- for (const t in e) {
1308
- const r = e[t];
1309
- r && (n(this, R)[t] = r);
1310
- }
1311
- }
1312
- setLogFilter(e) {
1313
- g(this, G, rt(e));
1314
- }
1315
- createLogger(e, t) {
1316
- const r = Be(e), i = (t == null ? void 0 : t.console) ?? St(), s = this;
1317
- return {
1318
- get info() {
1319
- var f;
1320
- const o = r.get();
1321
- if (n(s, R).info === !1 || U(n(s, R).info) && n(s, R).info !== s.getEnv() || !n(f = s, G).call(f, o))
1322
- return Te;
1323
- {
1324
- let c = `%c${o}`;
1325
- return t != null && t.uid ? c += ` %c[uid: %c${t.uid}%c]` : c += "%c%c%c", i.info.bind(
1326
- i,
1327
- c,
1328
- `color:${Ae(c)};font-weight:bold`,
1329
- "color:#777",
1330
- "color:#aaa",
1331
- "color:#777"
1332
- );
1333
- }
1334
- },
1335
- get log() {
1336
- var f;
1337
- const o = r.get();
1338
- if (n(s, R).log === !1 || U(n(s, R).log) && n(s, R).log !== s.getEnv() || !n(f = s, G).call(f, o))
1339
- return Te;
1340
- {
1341
- let c = `%c${o}`;
1342
- return t != null && t.uid ? c += ` %c[uid: %c${t.uid}%c]` : c += "%c%c%c", i.log.bind(
1343
- i,
1344
- c,
1345
- `color:${Ae(c)};font-weight:bold`,
1346
- "color:#777",
1347
- "color:#aaa",
1348
- "color:#777"
1349
- );
1350
- }
1351
- },
1352
- get warn() {
1353
- var f;
1354
- const o = r.get();
1355
- if (n(s, R).warn === !1 || U(n(s, R).warn) && n(s, R).warn !== s.getEnv() || !n(f = s, G).call(f, o))
1356
- return Te;
1357
- {
1358
- let c = `%c${o}`;
1359
- return t != null && t.uid ? c += ` %c[uid: %c${t.uid}%c]` : c += "%c%c%c", i.warn.bind(
1360
- i,
1361
- c,
1362
- `color:${Ae(c)};font-weight:bold`,
1363
- "color:#777",
1364
- "color:#aaa",
1365
- "color:#777"
1366
- );
1367
- }
1368
- },
1369
- get error() {
1370
- var f;
1371
- const o = r.get();
1372
- if (n(s, R).error === !1 || U(n(s, R).error) && n(s, R).error !== s.getEnv() || !n(f = s, G).call(f, o))
1373
- return Te;
1374
- {
1375
- let c = `%c${o}`;
1376
- return t != null && t.uid ? c += ` %c[uid: %c${t.uid}%c]` : c += "%c%c%c", i.error.bind(
1377
- i,
1378
- c,
1379
- `color:${Ae(c)};font-weight:bold`,
1380
- "color:#777",
1381
- "color:#aaa",
1382
- "color:#777"
1383
- );
1384
- }
1385
- },
1386
- crash(o) {
1387
- throw s.isMounted && (s.unmount(), s.constructView(n(s, Re), {
1388
- error: o,
1389
- loggerName: r.get(),
1390
- uid: t == null ? void 0 : t.uid
1391
- }).mount(n(s, z))), o;
1392
- }
1393
- };
1394
- }
1395
- /**
1396
- *
1397
- */
1398
- constructView(e, t, r = []) {
1399
- return Rt({ root: this, data: {} }, e, t, r);
1400
- }
1401
- /**
1402
- *
1403
- */
1404
- constructMarkup(e) {
1405
- return Nt(xt({ root: this, data: {} }, e));
1406
- }
1407
134
  }
1408
- W = new WeakMap(), Se = new WeakMap(), z = new WeakMap(), te = new WeakMap(), Re = new WeakMap(), Ne = new WeakMap(), xe = new WeakMap(), Oe = new WeakMap(), Me = new WeakMap(), R = new WeakMap(), G = new WeakMap();
1409
- const ct = new Kt(), Zt = ct.i18n.t.bind(ct.i18n);
1410
135
  export {
1411
- wt as cond,
1412
- at as createMarkup,
1413
- Lt as createRef,
1414
- $t as createSettableState,
1415
- rr as createSetter,
1416
- K as createState,
1417
- ct as default,
1418
- ae as derive,
1419
- tt as html,
1420
- Pt as isRef,
1421
- nr as portal,
1422
- ar as repeat,
1423
- Zt as t,
1424
- Et as toSettableState,
1425
- Be as toState,
1426
- kt as valueOf
136
+ P as For,
137
+ k as Markup,
138
+ I as MarkupNode,
139
+ p as Portal,
140
+ q as Show,
141
+ Z as batch,
142
+ D as createApp,
143
+ _ as createContext,
144
+ ee as createLogger,
145
+ n as createMarkup,
146
+ te as deepEqual,
147
+ se as effect,
148
+ l as get,
149
+ ne as getEnv,
150
+ ae as memo,
151
+ S as onLoggerCrash,
152
+ u as readable,
153
+ j as ref,
154
+ A as render,
155
+ re as setEnv,
156
+ oe as setLogFilter,
157
+ ie as setLogLevels,
158
+ le as shallowEqual,
159
+ ce as signal,
160
+ ue as strictEqual,
161
+ he as untracked,
162
+ h as useContext,
163
+ B as useEffect,
164
+ W as useMemo,
165
+ z as useMount,
166
+ K as useReducer,
167
+ G as useRef,
168
+ H as useSignal,
169
+ J as useStore,
170
+ Q as useStoreProvider,
171
+ X as useUnmount,
172
+ me as writable
1427
173
  };
1428
174
  //# sourceMappingURL=index.js.map