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

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