@manyducks.co/dolla 2.0.0-alpha.5 → 2.0.0-alpha.51

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