@manyducks.co/dolla 2.0.0-alpha.64 → 2.0.0-alpha.65

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 (55) hide show
  1. package/dist/core/app.d.ts +24 -0
  2. package/dist/core/index.d.ts +2 -2
  3. package/dist/core/nodes/element.d.ts +1 -0
  4. package/dist/core/scheduler.d.ts +12 -4
  5. package/dist/core/signals.d.ts +10 -9
  6. package/dist/hooks/index.d.ts +2 -2
  7. package/dist/hooks.js +1 -1
  8. package/dist/hooks.js.map +1 -1
  9. package/dist/http.js +1 -1
  10. package/dist/i18n.js +3 -3
  11. package/dist/index-Bh8JrCt1.js +556 -0
  12. package/dist/index-Bh8JrCt1.js.map +1 -0
  13. package/dist/index.js +113 -70
  14. package/dist/index.js.map +1 -1
  15. package/dist/jsx-dev-runtime.js +1 -1
  16. package/dist/jsx-runtime.js +1 -1
  17. package/dist/{logger-B7RBYtzP.js → logger-BuZRMjzE.js} +5 -5
  18. package/dist/{logger-B7RBYtzP.js.map → logger-BuZRMjzE.js.map} +1 -1
  19. package/dist/markup-DsJHUuod.js +1179 -0
  20. package/dist/markup-DsJHUuod.js.map +1 -0
  21. package/dist/router/hooks.d.ts +2 -0
  22. package/dist/router/index.d.ts +1 -0
  23. package/dist/router/router.d.ts +1 -0
  24. package/dist/router.js +3 -5
  25. package/dist/router.js.map +1 -1
  26. package/dist/{signals-DbDmN2gr.js → signals-BDlRtifZ.js} +264 -255
  27. package/dist/signals-BDlRtifZ.js.map +1 -0
  28. package/dist/typeChecking-D0-H8_Xm.js +62 -0
  29. package/dist/{typeChecking-CbltMOUt.js.map → typeChecking-D0-H8_Xm.js.map} +1 -1
  30. package/dist/utils.d.ts +5 -0
  31. package/docs/components.md +21 -0
  32. package/docs/hooks.md +3 -3
  33. package/docs/signals.md +67 -53
  34. package/docs/stores.md +13 -4
  35. package/package.json +4 -4
  36. package/dist/core/mount.d.ts +0 -15
  37. package/dist/core/mount.test.d.ts +0 -0
  38. package/dist/markup-DeZDwQ9F.js +0 -1117
  39. package/dist/markup-DeZDwQ9F.js.map +0 -1
  40. package/dist/router-C35XmU3k.js +0 -543
  41. package/dist/router-C35XmU3k.js.map +0 -1
  42. package/dist/signals-DbDmN2gr.js.map +0 -1
  43. package/dist/typeChecking-CbltMOUt.js +0 -71
  44. package/docs/state.md +0 -141
  45. package/examples/webcomponent/index.html +0 -14
  46. package/examples/webcomponent/main.js +0 -165
  47. package/notes/TODO.md +0 -6
  48. package/notes/context-routes.md +0 -61
  49. package/notes/custom-nodes.md +0 -17
  50. package/notes/effection-idea.md +0 -34
  51. package/notes/mixins.md +0 -22
  52. package/notes/molecule.md +0 -35
  53. package/notes/readme-scratch.md +0 -260
  54. package/notes/route-middleware.md +0 -42
  55. package/notes/stores.md +0 -79
@@ -0,0 +1,556 @@
1
+ var rt = Object.defineProperty;
2
+ var H = (r) => {
3
+ throw TypeError(r);
4
+ };
5
+ var nt = (r, t, e) => t in r ? rt(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
6
+ var x = (r, t, e) => nt(r, typeof t != "symbol" ? t + "" : t, e), G = (r, t, e) => t.has(r) || H("Cannot " + e);
7
+ var l = (r, t, e) => (G(r, t, "read from private field"), e ? e.call(r) : t.get(r)), b = (r, t, e) => t.has(r) ? H("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e), q = (r, t, e, n) => (G(r, t, "write to private field"), n ? n.call(r, e) : t.set(r, e), e), g = (r, t, e) => (G(r, t, "access private method"), e);
8
+ var D = (r, t, e, n) => ({
9
+ set _(i) {
10
+ q(r, t, i, e);
11
+ },
12
+ get _() {
13
+ return l(r, t, n);
14
+ }
15
+ });
16
+ import { c as st } from "./logger-BuZRMjzE.js";
17
+ import { D as at, V as it, m as ot, d as ct } from "./markup-DsJHUuod.js";
18
+ import { w as F, m as U, d as lt, s as B, u as J, b as ht, h as ut } from "./signals-BDlRtifZ.js";
19
+ import { c as ft, d as Y, b as Q, e as pt, f as X, i as dt, a as A, g as mt } from "./typeChecking-D0-H8_Xm.js";
20
+ function W(r) {
21
+ return Y(r, "Expected `path` to be a string. Got type: %t, value: %v"), r.split("/").map((t) => t.trim()).filter((t) => t !== "");
22
+ }
23
+ function N(r) {
24
+ var e;
25
+ ft(
26
+ (n) => Q(n == null ? void 0 : n.toString),
27
+ r,
28
+ "Expected `parts` to be an array of objects with a .toString() method. Got type: %t, value: %v"
29
+ ), r = r.filter((n) => n).flatMap(String);
30
+ let t = (e = r.shift()) == null ? void 0 : e.toString();
31
+ if (t) {
32
+ for (const n of r.map((i) => i.toString()))
33
+ n.startsWith(".") ? t = I(t, n) : t[t.length - 1] !== "/" ? n[0] !== "/" ? t += "/" + n : t += n : n[0] === "/" ? t += n.slice(1) : t += n;
34
+ t && t !== "/" && t.endsWith("/") && (t = t.slice(0, t.length - 1));
35
+ }
36
+ return t ?? "";
37
+ }
38
+ function I(r, t) {
39
+ if (Y(r, "Expected `base` to be a string. Got type: %t, value: %v"), t == null && (t = r, r = ""), t.startsWith("/"))
40
+ return t;
41
+ let e = r;
42
+ for (; ; )
43
+ if (t.startsWith("..")) {
44
+ for (let n = e.length; n > 0; --n)
45
+ if (e[n] === "/" || n === 0) {
46
+ e = e.slice(0, n), t = t.replace(/^\.\.\/?/, "");
47
+ break;
48
+ }
49
+ } else if (t.startsWith("."))
50
+ t = t.replace(/^\.\/?/, "");
51
+ else
52
+ break;
53
+ return N([e, t]);
54
+ }
55
+ function wt(r) {
56
+ if (!r) return {};
57
+ r.startsWith("?") && (r = r.slice(1));
58
+ const t = r.split("&").filter((e) => e.trim() !== "").map(
59
+ (e) => e.split("=").map((n) => n.trim()).slice(0, 2)
60
+ );
61
+ return Object.fromEntries(t);
62
+ }
63
+ function Z(r, t, e = {}) {
64
+ var s;
65
+ const [n, i] = t.split("?"), a = W(n);
66
+ t: for (const h of r) {
67
+ const { fragments: o } = h;
68
+ if (!(((s = o[o.length - 1]) == null ? void 0 : s.type) === 3) && o.length !== a.length || e.willMatch && !e.willMatch(h))
69
+ continue t;
70
+ const u = [];
71
+ e: for (let c = 0; c < o.length; c++) {
72
+ const f = a[c], m = o[c];
73
+ if (f == null && m.type !== 3)
74
+ continue t;
75
+ switch (m.type) {
76
+ case 1:
77
+ if (m.name.toLowerCase() === f.toLowerCase()) {
78
+ u.push(m);
79
+ break;
80
+ } else
81
+ continue t;
82
+ case 2:
83
+ u.push({ ...m, value: f });
84
+ break;
85
+ case 3:
86
+ u.push({ ...m, value: a.slice(c).join("/") });
87
+ break e;
88
+ case 4:
89
+ if (isNaN(Number(f)))
90
+ continue t;
91
+ u.push({ ...m, value: f });
92
+ break;
93
+ default:
94
+ throw new Error(`Unknown fragment type: ${m.type}`);
95
+ }
96
+ }
97
+ const p = {};
98
+ for (const c of u)
99
+ c.type === 2 && (p[c.name] = decodeURIComponent(c.value)), c.type === 4 && (p[c.name] = String(c.value)), c.type === 3 && (p.wildcard = "/" + decodeURIComponent(c.value));
100
+ return {
101
+ path: "/" + u.map((c) => c.value).join("/"),
102
+ pattern: "/" + o.map((c) => c.type === 2 ? `{${c.name}}` : c.type === 4 ? `{#${c.name}}` : c.name).join("/"),
103
+ params: p,
104
+ query: wt(i),
105
+ meta: h.meta
106
+ };
107
+ }
108
+ }
109
+ function yt(r) {
110
+ const t = [], e = [], n = [], i = [];
111
+ for (const s of r) {
112
+ const { fragments: h } = s;
113
+ h.some(
114
+ (o) => o.type === 3
115
+ /* Wildcard */
116
+ ) ? i.push(s) : h.some(
117
+ (o) => o.type === 4
118
+ /* NumericParam */
119
+ ) ? e.push(s) : h.some(
120
+ (o) => o.type === 2
121
+ /* Param */
122
+ ) ? n.push(s) : t.push(s);
123
+ }
124
+ const a = (s, h) => s.fragments.length > h.fragments.length ? -1 : 1;
125
+ return t.sort(a), e.sort(a), n.sort(a), i.sort(a), [...t, ...e, ...n, ...i];
126
+ }
127
+ function gt(r) {
128
+ const t = W(r), e = [];
129
+ for (let n = 0; n < t.length; n++) {
130
+ const i = t[n];
131
+ if (i === "*") {
132
+ if (n !== t.length - 1)
133
+ throw new Error(`Wildcard must be at the end of a pattern. Received: ${r}`);
134
+ e.push({
135
+ type: 3,
136
+ name: "*",
137
+ value: null
138
+ });
139
+ } else i.at(0) === "{" && i.at(-1) === "}" ? e.push({
140
+ type: i[1] === "#" ? 4 : 2,
141
+ name: i[1] === "#" ? i.slice(2, -1) : i.slice(1, -1),
142
+ value: null
143
+ }) : e.push({
144
+ type: 1,
145
+ name: i,
146
+ value: i
147
+ });
148
+ }
149
+ return e;
150
+ }
151
+ const bt = /(noopener|noreferrer) (noopener|noreferrer)/, $t = /^[\w-_]+:/;
152
+ function vt(r, t, e = window) {
153
+ function n(a) {
154
+ return !a || a === r ? null : a.localName !== "a" || a.href === void 0 ? n(a.parentNode) : a;
155
+ }
156
+ function i(a) {
157
+ if (a.button && a.button !== 0 || a.ctrlKey || a.metaKey || a.altKey || a.shiftKey || a.defaultPrevented)
158
+ return;
159
+ const s = n(a.target);
160
+ s && (e.location.protocol !== s.protocol || e.location.hostname !== s.hostname || e.location.port !== s.port || s.hasAttribute("data-router-ignore") || s.hasAttribute("download") || s.getAttribute("target") === "_blank" && bt.test(s.getAttribute("rel")) || $t.test(s.getAttribute("href")) || (a.preventDefault(), t(s)));
161
+ }
162
+ return r.addEventListener("click", i), function() {
163
+ r.removeEventListener("click", i);
164
+ };
165
+ }
166
+ function kt(r, t) {
167
+ for (const e in t) {
168
+ const n = t[e].toString();
169
+ r = r.replace(`{${e}}`, n).replace(`{#${e}}`, n);
170
+ }
171
+ return r;
172
+ }
173
+ const Et = Symbol("Router"), Rt = Symbol(), St = Symbol();
174
+ var S, T, v, L, C, P, k, M, $, w, _, tt, et, O, K, V;
175
+ class qt {
176
+ constructor(t) {
177
+ b(this, w);
178
+ b(this, S, st("dolla.router"));
179
+ b(this, T, 0);
180
+ b(this, v, []);
181
+ b(this, L, []);
182
+ b(this, C, !1);
183
+ b(this, P);
184
+ /**
185
+ * Use hash routing when true. Configured in router options.
186
+ */
187
+ b(this, k, !1);
188
+ /**
189
+ * Cleanup functions to call on unmount.
190
+ */
191
+ b(this, M, []);
192
+ /**
193
+ * The current match object (internal).
194
+ */
195
+ b(this, $, F());
196
+ /**
197
+ * The current match object.
198
+ */
199
+ x(this, "$match", U(
200
+ () => {
201
+ const t = l(this, $).call(this);
202
+ if (t)
203
+ return {
204
+ path: t.path,
205
+ pattern: t.pattern,
206
+ params: { ...t.params },
207
+ query: { ...t.query },
208
+ data: t.meta.data ?? {}
209
+ };
210
+ },
211
+ { equals: lt }
212
+ ));
213
+ /**
214
+ * The currently matched route pattern, if any.
215
+ */
216
+ x(this, "$pattern", U(() => {
217
+ var t;
218
+ return (t = l(this, $).call(this)) == null ? void 0 : t.pattern;
219
+ }));
220
+ /**
221
+ * The current URL path.
222
+ */
223
+ x(this, "$path", U(() => {
224
+ var t;
225
+ return ((t = l(this, $).call(this)) == null ? void 0 : t.path) ?? window.location.pathname;
226
+ }));
227
+ /**
228
+ * The current named path params.
229
+ */
230
+ x(this, "$params", U(() => {
231
+ var t;
232
+ return ((t = l(this, $).call(this)) == null ? void 0 : t.params) ?? {};
233
+ }, { equals: B }));
234
+ /**
235
+ * The current query params.
236
+ */
237
+ x(this, "$query", U(() => {
238
+ var t;
239
+ return ((t = l(this, $).call(this)) == null ? void 0 : t.query) ?? {};
240
+ }, { equals: B }));
241
+ pt(t, "Options must be an object. Got: %t"), t.hash && q(this, k, !0), q(this, L, yt(
242
+ t.routes.flatMap((e) => g(this, w, V).call(this, e)).map((e) => ({
243
+ pattern: e.pattern,
244
+ meta: e.meta,
245
+ fragments: gt(e.pattern)
246
+ }))
247
+ )), Mt(l(this, L));
248
+ }
249
+ async [Rt](t, e) {
250
+ const n = F();
251
+ q(this, P, {
252
+ id: D(this, T)._++,
253
+ node: new at(e, n),
254
+ context: e,
255
+ $slot: n
256
+ });
257
+ const i = () => g(this, w, O).call(this);
258
+ return window.addEventListener("popstate", i), l(this, M).push(() => window.removeEventListener("popstate", i)), l(this, M).push(
259
+ vt(t, (a) => {
260
+ l(this, S).info("intercepted click on <a> tag", a);
261
+ const s = a.getAttribute("href"), h = a.getAttribute("data-router-preserve-query");
262
+ this.go(s, {
263
+ preserveQuery: xt(h)
264
+ });
265
+ })
266
+ ), l(this, S).info("will intercept clicks on <a> tags within parent element:", t), q(this, C, !0), await g(this, w, O).call(this), l(this, P).node;
267
+ }
268
+ async [St]() {
269
+ for (const t of l(this, M))
270
+ t();
271
+ l(this, M).length = 0;
272
+ }
273
+ /**
274
+ * Navigate backward. Pass a number of steps to hit the back button that many times.
275
+ */
276
+ back(t = 1) {
277
+ window.history.go(-t);
278
+ }
279
+ /**
280
+ * Navigate forward. Pass a number of steps to hit the forward button that many times.
281
+ */
282
+ forward(t = 1) {
283
+ window.history.go(t);
284
+ }
285
+ /**
286
+ * Navigates to another route.
287
+ *
288
+ * @example
289
+ * router.go("/login"); // navigate to `/login`
290
+ * router.go["/users", 215], { replace: true }); // replace current history entry with `/users/215`
291
+ */
292
+ go(t, e = {}) {
293
+ let n;
294
+ Array.isArray(t) ? n = N(t) : n = t.toString(), n = I(window.location.pathname, n), e.replace ? g(this, w, tt).call(this, n, e) : g(this, w, _).call(this, n, e);
295
+ }
296
+ /**
297
+ * Updates query params, keeping existing ones and applying new ones. Removes the query param if value is set to `null`.
298
+ */
299
+ updateQuery(t) {
300
+ const e = J(l(this, $)), n = { ...this.$query() };
301
+ for (const s in t) {
302
+ const h = t[s];
303
+ h === null ? delete n[s] : n[s] = h.toString();
304
+ }
305
+ let i = [];
306
+ for (const s in n)
307
+ i.push(`${s}=${n[s]}`);
308
+ const a = i.length > 0 ? "?" + i.join("&") : "";
309
+ l(this, $).set({ ...e, query: n }), window.history.replaceState(null, "", l(this, k) ? "/#" + e.path + a : e.path + a);
310
+ }
311
+ }
312
+ S = new WeakMap(), T = new WeakMap(), v = new WeakMap(), L = new WeakMap(), C = new WeakMap(), P = new WeakMap(), k = new WeakMap(), M = new WeakMap(), $ = new WeakMap(), w = new WeakSet(), _ = function(t, e) {
313
+ l(this, S).info("(push)", t), window.history.pushState(null, "", l(this, k) ? "/#" + t : t), g(this, w, O).call(this, t, e);
314
+ }, tt = function(t, e) {
315
+ l(this, S).info("(replace)", t), window.history.replaceState(null, "", l(this, k) ? "/#" + t : t), g(this, w, O).call(this, t, e);
316
+ }, et = function() {
317
+ return l(this, k) ? new URL(window.location.hash.slice(1), window.location.origin) : new URL(window.location.pathname, window.location.origin);
318
+ }, O = async function(t, e = {}) {
319
+ const n = l(this, S), i = t ? new URL(t, window.location.origin) : g(this, w, et).call(this), { match: a, journey: s, state: h } = await g(this, w, K).call(this, i);
320
+ for (let p = 0; p < s.length; p++) {
321
+ const c = s[p], f = `(update: step ${p + 1} of ${s.length})`;
322
+ switch (c.kind) {
323
+ case "match":
324
+ n == null || n.info(`${f} 📍 ${c.message}`);
325
+ break;
326
+ case "redirect":
327
+ n == null || n.info(`${f} ↩️ ${c.message}`);
328
+ break;
329
+ case "miss":
330
+ n == null || n.info(`${f} 💀 ${c.message}`);
331
+ break;
332
+ }
333
+ }
334
+ if (!a) {
335
+ if (l(this, C))
336
+ throw n.crash(new Lt(`Failed to match route '${i.pathname}'`));
337
+ return;
338
+ }
339
+ let o = a.query, d = [];
340
+ if (e.preserveQuery === !0)
341
+ o = Object.assign({}, this.$query(), a.query);
342
+ else if (X(e.preserveQuery)) {
343
+ const p = {}, c = this.$query();
344
+ for (const f in c)
345
+ e.preserveQuery.includes(f) && (p[f] = c[f]);
346
+ o = Object.assign({}, p, a.query);
347
+ }
348
+ for (const p in o)
349
+ d.push(`${p}=${o[p]}`);
350
+ const u = d.length > 0 ? "?" + d.join("&") : "";
351
+ return (a.path !== location.pathname || location.search !== u) && window.history.replaceState(null, "", l(this, k) ? "/#" + a.path + u : a.path + u), ht(() => {
352
+ const p = J(this.$pattern);
353
+ if (l(this, $).set({ ...a, query: o }), a.pattern === p) {
354
+ for (const f of l(this, v)) {
355
+ const m = h.get(f.id);
356
+ m && f.context.setState(m);
357
+ }
358
+ return;
359
+ }
360
+ const c = a.meta.layers;
361
+ n.info("mounting", a);
362
+ for (let f = 0; f < c.length; f++) {
363
+ const m = c[f], y = l(this, v)[f];
364
+ if ((y == null ? void 0 : y.id) !== m.id) {
365
+ q(this, v, l(this, v).slice(0, f)), y == null || y.node.unmount();
366
+ const E = l(this, v).at(-1) ?? l(this, P), R = F(), j = new it(E.context, m.view, {
367
+ children: ot(ct.Dynamic, { source: R })
368
+ }), z = h.get(m.id);
369
+ z && j.context.setState(z), l(this, v).push({
370
+ id: m.id,
371
+ node: j,
372
+ context: j.context,
373
+ $slot: R
374
+ }), E.$slot.set(j);
375
+ } else {
376
+ const E = h.get(y.id);
377
+ E && y.context.setState(E);
378
+ }
379
+ }
380
+ }), { match: a, journey: s };
381
+ }, K = async function(t, e = [], n = /* @__PURE__ */ new Map()) {
382
+ return new Promise((i, a) => {
383
+ var d;
384
+ const s = Z(l(this, L), t.pathname);
385
+ if (!s)
386
+ return i({
387
+ match: null,
388
+ journey: [...e, { kind: "miss", message: `no match for '${t.pathname}'` }],
389
+ state: n
390
+ });
391
+ let h = s.meta.redirect;
392
+ const o = async () => {
393
+ if (h != null) {
394
+ let u;
395
+ if (A(h))
396
+ u = kt(h, s.params);
397
+ else if (Q(h)) {
398
+ const p = {
399
+ path: s.path,
400
+ pattern: s.pattern,
401
+ params: s.params,
402
+ query: s.query,
403
+ data: s.meta.data ?? {}
404
+ };
405
+ if (u = await h(p), !A(u))
406
+ return a(new Error("Redirect function must return a path to redirect to."));
407
+ u.startsWith("/") || (u = I(s.path, u));
408
+ } else
409
+ return a(new TypeError("Redirect must either be a path string or a function."));
410
+ i(
411
+ g(this, w, K).call(this, new URL(u, window.location.origin), [
412
+ ...e,
413
+ { kind: "redirect", message: `redirecting '${s.path}' -> '${u}'` }
414
+ ])
415
+ );
416
+ } else
417
+ i({ match: s, journey: [...e, { kind: "match", message: `matched route '${s.path}'` }], state: n });
418
+ };
419
+ if ((d = s.meta.beforeMatch) != null && d.length) {
420
+ const u = s.meta.beforeMatch;
421
+ let p = -1;
422
+ const c = () => {
423
+ if (p++, p === u.length)
424
+ o();
425
+ else {
426
+ let f = !1;
427
+ const m = u[p].fn({
428
+ path: s.path,
429
+ pattern: s.pattern,
430
+ params: s.params,
431
+ query: s.query,
432
+ data: s.meta.data ?? {},
433
+ setState: (...y) => {
434
+ const E = u[p].layerId, R = [];
435
+ if (y.length === 1 && mt(X, y[0]))
436
+ R.push(...y[0]);
437
+ else if (y.length === 2)
438
+ R.push([y[0], y[1]]);
439
+ else
440
+ throw new Error("Invalid arguments.");
441
+ n.get(E) ? R.push(...R) : n.set(E, R);
442
+ },
443
+ redirect: (y) => {
444
+ h = y, f = !0, o();
445
+ }
446
+ });
447
+ f || (m instanceof Promise ? m.then(c) : c());
448
+ }
449
+ };
450
+ c();
451
+ } else
452
+ o();
453
+ });
454
+ }, /**
455
+ * Parses a route definition object into a set of matchable routes.
456
+ *
457
+ * @param route - Route config object.
458
+ * @param layers - Array of parent layers. Passed when this function calls itself on nested routes.
459
+ */
460
+ V = function(t, e = [], n = []) {
461
+ if (!dt(t) || !A(t.path))
462
+ throw new TypeError(`Route configs must be objects with a 'path' string property. Got: ${t}`);
463
+ if (t.redirect && t.routes)
464
+ throw new Error("Route cannot have both a 'redirect' and nested 'routes'.");
465
+ if (t.redirect && t.view)
466
+ throw new Error("Route cannot have both a 'redirect' and a 'view'.");
467
+ if (!t.view && !t.routes && !t.redirect)
468
+ throw new Error("Route must have a 'view', a 'redirect', or a set of nested 'routes'.");
469
+ let i = [];
470
+ for (const o of e)
471
+ i.push(...W(o.path));
472
+ i.push(...W(t.path)), i[i.length - 1] === "*" && i.pop();
473
+ const a = [];
474
+ if (t.redirect) {
475
+ let o = t.redirect;
476
+ A(o) && (o = I(N(i), o), o.startsWith("/") || (o = "/" + o));
477
+ const d = {
478
+ pattern: "/" + N([...i, ...W(t.path)]),
479
+ meta: {
480
+ redirect: o
481
+ }
482
+ };
483
+ return a.push(d), a;
484
+ }
485
+ let s = (o) => o.children;
486
+ if (Q(t.view))
487
+ s = t.view;
488
+ else if (t.view)
489
+ throw new TypeError(`Route '${t.path}' expected a view function or undefined. Got: ${t.view}`);
490
+ const h = { id: D(this, T)._++, view: s };
491
+ if (t.routes)
492
+ for (const o of t.routes)
493
+ a.push(...g(this, w, V).call(this, o, [...e, t], [...n, h]));
494
+ else {
495
+ const o = {
496
+ pattern: e.length ? N([...e.map((d) => d.path), t.path]) : t.path,
497
+ meta: {
498
+ pattern: t.path,
499
+ layers: [...n, h],
500
+ // Store the layer ID with each beforeMatch so we can correlate which context needs to get any state that is set.
501
+ beforeMatch: e.flatMap((d, u) => d.beforeMatch ? { fn: d.beforeMatch, layerId: n[u].id } : null).concat(t.beforeMatch ? { fn: t.beforeMatch, layerId: h.id } : null).filter((d) => d != null)
502
+ }
503
+ };
504
+ if (t.data) {
505
+ const d = e.at(-1);
506
+ d ? o.meta.data = { ...d.data, ...t.data } : o.meta.data = t.data;
507
+ }
508
+ a.push(o);
509
+ }
510
+ return a;
511
+ };
512
+ function Mt(r) {
513
+ for (const t of r)
514
+ if (t.meta.redirect) {
515
+ let e;
516
+ if (!Q(t.meta.redirect)) if (A(t.meta.redirect)) {
517
+ if (e = t.meta.redirect, !Z(r, e, {
518
+ willMatch(i) {
519
+ return i !== t;
520
+ }
521
+ }))
522
+ throw new Error(`Found a redirect to an undefined URL. From '${t.pattern}' to '${t.meta.redirect}'`);
523
+ } else
524
+ throw new TypeError(`Expected a string or redirect function. Got: ${t.meta.redirect}`);
525
+ }
526
+ }
527
+ function xt(r) {
528
+ if (r === null)
529
+ return !1;
530
+ if (r === !0 || r === !1)
531
+ return r;
532
+ if (typeof r == "string")
533
+ return r = r.trim(), r === "" || r === "true" ? !0 : r === "false" ? !1 : r.split(",").map((t) => t.trim()).filter((t) => t.length > 0);
534
+ throw new Error(`Invalid type for data-router-preserve-query attribute: ${typeof r} (value: ${r})`);
535
+ }
536
+ class Lt extends Error {
537
+ }
538
+ function Ot() {
539
+ const r = ut();
540
+ if (!r) throw new Error("Hooks can only be called in the body of a View, Store or Mixin.");
541
+ const t = r.getState(Et, { fallback: null });
542
+ if (!t) throw new Error("useRoute can only be called within an app that uses a router.");
543
+ return t;
544
+ }
545
+ function Wt(r) {
546
+ return new qt(r);
547
+ }
548
+ export {
549
+ Rt as M,
550
+ qt as R,
551
+ St as U,
552
+ Et as a,
553
+ Wt as c,
554
+ Ot as u
555
+ };
556
+ //# sourceMappingURL=index-Bh8JrCt1.js.map