@vielzeug/wayfinder 1.0.5 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +8 -2
  2. package/dist/_dev.cjs.map +1 -1
  3. package/dist/_dev.js.map +1 -1
  4. package/dist/_navigation.cjs +2 -0
  5. package/dist/_navigation.cjs.map +1 -0
  6. package/dist/_navigation.d.ts +10 -0
  7. package/dist/_navigation.d.ts.map +1 -0
  8. package/dist/_navigation.js +21 -0
  9. package/dist/_navigation.js.map +1 -0
  10. package/dist/compile.cjs.map +1 -1
  11. package/dist/compile.d.ts.map +1 -1
  12. package/dist/compile.js.map +1 -1
  13. package/dist/context.cjs +1 -1
  14. package/dist/context.cjs.map +1 -1
  15. package/dist/context.d.ts +5 -5
  16. package/dist/context.d.ts.map +1 -1
  17. package/dist/context.js +7 -6
  18. package/dist/context.js.map +1 -1
  19. package/dist/devtools.cjs.map +1 -1
  20. package/dist/devtools.d.ts.map +1 -1
  21. package/dist/devtools.js.map +1 -1
  22. package/dist/errors.cjs +1 -1
  23. package/dist/errors.cjs.map +1 -1
  24. package/dist/errors.d.ts +0 -1
  25. package/dist/errors.d.ts.map +1 -1
  26. package/dist/errors.js +1 -4
  27. package/dist/errors.js.map +1 -1
  28. package/dist/guards.cjs.map +1 -1
  29. package/dist/guards.d.ts +1 -1
  30. package/dist/guards.js.map +1 -1
  31. package/dist/history.cjs +1 -1
  32. package/dist/history.cjs.map +1 -1
  33. package/dist/history.d.ts.map +1 -1
  34. package/dist/history.js +3 -1
  35. package/dist/history.js.map +1 -1
  36. package/dist/index.d.ts +3 -3
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/path.cjs +1 -1
  39. package/dist/path.cjs.map +1 -1
  40. package/dist/path.d.ts.map +1 -1
  41. package/dist/path.js +6 -2
  42. package/dist/path.js.map +1 -1
  43. package/dist/router.cjs +1 -1
  44. package/dist/router.cjs.map +1 -1
  45. package/dist/router.d.ts +10 -13
  46. package/dist/router.d.ts.map +1 -1
  47. package/dist/router.js +167 -145
  48. package/dist/router.js.map +1 -1
  49. package/dist/types.d.ts +13 -14
  50. package/dist/types.d.ts.map +1 -1
  51. package/dist/wayfinder.cjs +1 -1
  52. package/dist/wayfinder.cjs.map +1 -1
  53. package/dist/wayfinder.iife.js +1 -1
  54. package/dist/wayfinder.iife.js.map +1 -1
  55. package/dist/wayfinder.js +1 -1
  56. package/dist/wayfinder.js.map +1 -1
  57. package/package.json +33 -28
package/dist/router.js CHANGED
@@ -1,34 +1,35 @@
1
- import { WayfinderDisposedError as e, WayfinderRedirectLoopError as t, WayfinderRouteError as n } from "./errors.js";
2
- import { buildPreloadKey as r, buildUrl as i, joinPaths as a, matchRouteFor as o, matchesPrefix as s, normalizePath as c, parseQuery as l, readLocation as u, stripBase as d } from "./path.js";
3
- import { compileRoutes as f } from "./compile.js";
4
- import { buildMatchBranch as p, createRouteContext as m, createRouteState as h, executeMiddlewarePipeline as g, reportError as _ } from "./context.js";
5
- import { runLeaveBlockers as v } from "./guards.js";
6
- import { createBrowserHistory as y } from "./history.js";
7
- import { createHydrationManager as b } from "./hydration.js";
8
- import { createPreloadManager as x } from "./preload.js";
1
+ import { createNavigationCoordinator as e } from "./_navigation.js";
2
+ import { WayfinderDisposedError as t, WayfinderRedirectLoopError as n, WayfinderRouteError as r } from "./errors.js";
3
+ import { buildPreloadKey as i, buildUrl as a, joinPaths as o, matchRouteFor as s, matchesPrefix as c, normalizePath as l, parseQuery as u, readLocation as d, stripBase as f } from "./path.js";
4
+ import { compileRoutes as p } from "./compile.js";
5
+ import { buildMatchBranch as m, createRouteContext as h, createRouteState as g, executeMiddlewarePipeline as _, reportError as v } from "./context.js";
6
+ import { runLeaveBlockers as y } from "./guards.js";
7
+ import { createBrowserHistory as b } from "./history.js";
8
+ import { createHydrationManager as x } from "./hydration.js";
9
+ import { createPreloadManager as S } from "./preload.js";
9
10
  //#region src/router.ts
10
- function S(e, t) {
11
- let r = t.get(e);
12
- if (r) return r;
11
+ function C(e, t) {
12
+ let n = t.get(e);
13
+ if (n) return n;
13
14
  let i = [...t.keys()].join(", ");
14
- throw new n(i ? `Unknown route name: ${e}. Available routes: ${i}` : `Unknown route name: ${e}`);
15
+ throw new r(i ? `Unknown route name: ${e}. Available routes: ${i}` : `Unknown route name: ${e}`);
15
16
  }
16
- function C(e, t, n = "/") {
17
+ function w(e, t, n = "/") {
17
18
  if ("path" in e) return e.path;
18
- let r = S(e.name, t), a = i(n, r.path, e.params, e.query);
19
- return e.hash ? `${a}#${e.hash}` : a;
19
+ let r = C(e.name, t), i = a(n, r.path, e.params, e.query);
20
+ return e.hash ? `${i}#${e.hash}` : i;
20
21
  }
21
- var w = Symbol("wayfinder.errorContext");
22
- function T(e, t) {
23
- typeof e == "object" && e && (e[w] = t);
24
- }
25
- function E(e) {
26
- if (typeof e == "object" && e) return e[w];
22
+ var T = Symbol("wayfinder.errorContext");
23
+ function E(e, t) {
24
+ typeof e == "object" && e && (e[T] = t);
27
25
  }
28
26
  function D(e) {
27
+ if (typeof e == "object" && e) return e[T];
28
+ }
29
+ function O(e) {
29
30
  return typeof e == "object" && !!e && typeof e[Symbol.asyncIterator] == "function" && typeof e.next == "function" && typeof e.return == "function";
30
31
  }
31
- var O = class {
32
+ var k = class {
32
33
  #e;
33
34
  #t;
34
35
  #n;
@@ -38,8 +39,8 @@ var O = class {
38
39
  #o;
39
40
  #s;
40
41
  #c;
41
- #l = null;
42
- #u = /* @__PURE__ */ new Set();
42
+ #l = /* @__PURE__ */ new Set();
43
+ #u = e();
43
44
  #d;
44
45
  #f = !1;
45
46
  #p = new AbortController();
@@ -49,9 +50,10 @@ var O = class {
49
50
  #_;
50
51
  #v;
51
52
  #y;
53
+ ready;
52
54
  constructor(e) {
53
- let t = f(e);
54
- if (this.#e = c(e.base ?? "/"), this.#t = e.middleware ?? [], this.#n = e.coerceSearch, this.#r = e.history ?? y(), this.#s = e.viewTransition ?? !1, this.#o = e.scroll, this.#c = e.onError, this.#i = t.records, this.#a = t.routesByName, this.#_ = b(), this.#v = x(), this.#d = h({
55
+ let t = p(e);
56
+ if (this.#e = l(e.base ?? "/"), this.#t = e.middleware ?? [], this.#n = e.coerceSearch, this.#r = e.history ?? b(), this.#s = e.viewTransition ?? !1, this.#o = e.scroll, this.#c = e.onError, this.#i = t.records, this.#a = t.routesByName, this.#_ = x(), this.#v = S(), this.#d = g({
55
57
  location: {
56
58
  hash: "",
57
59
  historyState: null,
@@ -81,7 +83,13 @@ var O = class {
81
83
  } else this.#g = null;
82
84
  this.#y = this.#x();
83
85
  let { hash: n, pathname: r, search: i } = this.#r.location;
84
- this.#m = `${r}${i}${n}`, this.#w(this.#F(), { source: "initial-navigation" });
86
+ this.#m = `${r}${i}${n}`;
87
+ let a = this.#u.begin();
88
+ this.ready = this.#F(a, d(this.#e, this.#r), (e, t) => {
89
+ if (!a.isCurrent()) return;
90
+ let n = this.#z(e);
91
+ t && this.#r.replace(n, e.historyState), this.#m = n;
92
+ }, void 0, 0, !1).then(() => void 0), this.#w(this.ready, { source: "initial-navigation" }), this.beforeLeave = this.beforeLeave.bind(this), this.dispose = this.dispose.bind(this), this.getSnapshot = this.getSnapshot.bind(this), this.isActive = this.isActive.bind(this), this.load = this.load.bind(this), this.match = this.match.bind(this), this.navigate = this.navigate.bind(this), this.preload = this.preload.bind(this), this.subscribe = this.subscribe.bind(this), this.url = this.url.bind(this), this.waitFor = this.waitFor.bind(this);
85
93
  }
86
94
  getSnapshot() {
87
95
  return this.#d;
@@ -92,39 +100,39 @@ var O = class {
92
100
  };
93
101
  }
94
102
  navigate(e, t) {
95
- let n = C(typeof e == "string" ? { path: e } : e, this.#a);
96
- return this.#z(n, t);
103
+ let n = w(typeof e == "string" ? { path: e } : e, this.#a);
104
+ return this.#V(n, t);
97
105
  }
98
106
  url(e, t, n) {
99
- let r = S(e, this.#a);
100
- return i(this.#e, r.path, t, n);
107
+ let r = C(e, this.#a);
108
+ return a(this.#e, r.path, t, n);
101
109
  }
102
110
  isActive(e, t = {}) {
103
- let n = S(e, this.#a), r = this.#d.location.pathname;
104
- return t.exact ?? !1 ? o(r, [n]).record != null : s(r, n);
111
+ let n = C(e, this.#a), r = this.#d.location.pathname;
112
+ return t.exact ?? !1 ? s(r, [n]).record != null : c(r, n);
105
113
  }
106
- resolve(e) {
107
- let t = d(c(e), this.#e), { params: n, record: r } = o(t, this.#i);
114
+ match(e) {
115
+ let t = f(l(e), this.#e), { params: n, record: r } = s(t, this.#i);
108
116
  if (!r || r.redirect) return null;
109
- let i = this.#_.effectiveDefs(r), a = p(i, n, t, i.map(() => void 0));
117
+ let i = this.#_.effectiveDefs(r), a = m(i, n, t, i.map(() => void 0));
110
118
  return a.length ? a : null;
111
119
  }
112
- async match(e, t) {
120
+ async load(e, t) {
113
121
  let n = await this.#k(e);
114
122
  if (n.type !== "matched") return null;
115
123
  let { location: r, params: i, record: a, resolvedQuery: o } = n, s = this.#_.effectiveDefs(a), c = s.some((e) => e.dataFn != null), l = s.map(() => void 0), u, d = "idle";
116
124
  if (c) {
117
- let e = t?.signal ?? new AbortController().signal, n = p(s, i, r.pathname, l), a = m(r, o, i, n, () => Promise.resolve());
125
+ let e = t?.signal ?? new AbortController().signal, n = m(s, i, r.pathname, l), a = h(r, o, i, n, () => Promise.resolve());
118
126
  try {
119
127
  l = await this.#D(s, a, e);
120
128
  } catch (e) {
121
129
  u = e, d = "error";
122
130
  }
123
131
  }
124
- return h({
132
+ return g({
125
133
  error: u,
126
134
  location: r,
127
- matches: p(s, i, r.pathname, l),
135
+ matches: m(s, i, r.pathname, l),
128
136
  status: d
129
137
  });
130
138
  }
@@ -149,7 +157,7 @@ var O = class {
149
157
  }
150
158
  async preload(e, t, n) {
151
159
  this.#b();
152
- let i = S(e, this.#a), a = r(this.#e, i.path, t, n), o = this.#v.getInflight(a);
160
+ let r = C(e, this.#a), a = i(this.#e, r.path, t, n), o = this.#v.getInflight(a);
153
161
  if (o) return o;
154
162
  let s = this.#A(a, this.#p.signal, n).finally(() => {
155
163
  this.#v.untrack(a);
@@ -167,8 +175,8 @@ var O = class {
167
175
  handler: e,
168
176
  routes: t?.routes
169
177
  };
170
- return this.#u.add(n), () => {
171
- this.#u.delete(n);
178
+ return this.#l.add(n), () => {
179
+ this.#l.delete(n);
172
180
  };
173
181
  }
174
182
  get disposalSignal() {
@@ -178,13 +186,13 @@ var O = class {
178
186
  return this.#f;
179
187
  }
180
188
  dispose() {
181
- this.#f || (this.#f = !0, this.#u.clear(), this.#h.clear(), this.#l?.abort(), this.#l = null, this.#y(), this.#p.abort(new e()));
189
+ this.#f || (this.#f = !0, this.#l.clear(), this.#h.clear(), this.#u.invalidate(new t()), this.#y(), this.#p.abort(new t()));
182
190
  }
183
191
  [Symbol.dispose]() {
184
192
  this.dispose();
185
193
  }
186
194
  #b() {
187
- if (this.#f) throw new e();
195
+ if (this.#f) throw new t();
188
196
  }
189
197
  #x() {
190
198
  return this.#r.onPopstate(() => {
@@ -193,28 +201,31 @@ var O = class {
193
201
  });
194
202
  }
195
203
  async #S(e, t) {
196
- let n = this.#d.matches.map((e) => e.name), r = new URL(e, "http://localhost"), i = d(r.pathname, this.#e), { params: a, record: s } = o(i, this.#i), c = {
197
- name: s?.leaf.name,
198
- params: a,
199
- pathname: i,
200
- query: l(r.search)
201
- };
202
- if (!await v(this.#u, n, c)) {
204
+ let n = this.#u.begin(), r = this.#d.matches.map((e) => e.name), i = this.#B(e), a = await y(this.#l, r, i);
205
+ if (!n.isCurrent()) return;
206
+ if (!a) {
203
207
  this.#r.replace(t, this.#d.location.historyState);
204
208
  return;
205
209
  }
206
- this.#m = e, await this.#F();
210
+ let o = await this.#F(n, d(this.#e, this.#r), (e, t) => {
211
+ if (!n.isCurrent()) return;
212
+ let r = this.#z(e);
213
+ t && this.#r.replace(r, e.historyState), this.#m = r;
214
+ }, void 0, 0, !1);
215
+ n.isCurrent() && !o && this.#r.replace(t, this.#d.location.historyState);
207
216
  }
208
217
  #C(e, t) {
209
- _(e, t, this.#c);
218
+ v(e, t, this.#c);
210
219
  }
211
220
  #w(e, t) {
212
221
  e.catch((e) => {
213
- this.#C(e, E(e) ?? t);
222
+ this.#C(e, D(e) ?? t);
214
223
  });
215
224
  }
216
225
  #T() {
217
- this.#h.forEach((e) => e(this.#d));
226
+ this.#h.forEach((e) => {
227
+ e(this.#d);
228
+ });
218
229
  }
219
230
  async #E(e, t) {
220
231
  let n;
@@ -233,7 +244,7 @@ var O = class {
233
244
  signal: n
234
245
  });
235
246
  try {
236
- return D(i) ? await this.#E(i, n) : await i;
247
+ return O(i) ? await this.#E(i, n) : await i;
237
248
  } catch (r) {
238
249
  if (e.onError) return e.onError(r, {
239
250
  ...t,
@@ -252,7 +263,7 @@ var O = class {
252
263
  signal: n
253
264
  });
254
265
  }), s = [], c = await Promise.all(o.map(async (r, i) => {
255
- if (D(r)) {
266
+ if (O(r)) {
256
267
  s.push(i);
257
268
  return;
258
269
  }
@@ -272,9 +283,9 @@ var O = class {
272
283
  if (!r()) return;
273
284
  l[n] = t;
274
285
  let o = e.map((e, t) => s.includes(t) ? "streaming" : "idle");
275
- this.#d = h({
286
+ this.#d = g({
276
287
  location: i,
277
- matches: p(e, a, i.pathname, l, o),
288
+ matches: m(e, a, i.pathname, l, o),
278
289
  status: "streaming"
279
290
  }), this.#T();
280
291
  };
@@ -293,29 +304,29 @@ var O = class {
293
304
  })), l;
294
305
  }
295
306
  async #k(e) {
296
- let n = e;
307
+ let t = e;
297
308
  for (let e = 0; e < 5; e += 1) {
298
- let e = new URL(n, "http://localhost"), t = {
309
+ let e = new URL(t, "http://localhost"), n = {
299
310
  hash: e.hash.replace(/^#/, ""),
300
311
  historyState: null,
301
- pathname: d(e.pathname, this.#e),
302
- query: l(e.search)
303
- }, r = await this.#j(t);
312
+ pathname: f(e.pathname, this.#e),
313
+ query: u(e.search)
314
+ }, r = await this.#j(n);
304
315
  if (r.type !== "redirect") return r;
305
- n = this.#L(r.redirectTo);
316
+ t = this.#L(r.redirectTo);
306
317
  }
307
- throw new t();
318
+ throw new n();
308
319
  }
309
320
  async #A(e, t, n) {
310
- let i = await this.#k(e);
311
- if (i.type !== "matched") return;
312
- let { location: a, params: o, record: s, resolvedQuery: c } = i, l = this.#_.effectiveDefs(s);
321
+ let r = await this.#k(e);
322
+ if (r.type !== "matched") return;
323
+ let { location: a, params: o, record: s, resolvedQuery: c } = r, l = this.#_.effectiveDefs(s);
313
324
  if (!l.some((e) => e.dataFn != null)) return;
314
- let u = p(l, o, a.pathname, l.map(() => void 0)), d = m(a, c, o, u, () => Promise.resolve()), f = await this.#D(l, d, t);
315
- this.#v.set(r(this.#e, s.path, o, n ?? a.query), f);
325
+ let u = m(l, o, a.pathname, l.map(() => void 0)), d = h(a, c, o, u, () => Promise.resolve()), f = await this.#D(l, d, t);
326
+ this.#v.set(i(this.#e, s.path, o, n ?? a.query), f);
316
327
  }
317
328
  async #j(e) {
318
- let { params: t, record: n } = o(e.pathname, this.#i);
329
+ let { params: t, record: n } = s(e.pathname, this.#i);
319
330
  if (!n) return {
320
331
  location: e,
321
332
  params: t,
@@ -324,7 +335,7 @@ var O = class {
324
335
  if (n.redirect) return {
325
336
  location: e,
326
337
  params: t,
327
- redirectTo: C(n.redirect, this.#a, this.#e),
338
+ redirectTo: w(n.redirect, this.#a, this.#e),
328
339
  type: "redirect"
329
340
  };
330
341
  let r = e.query, i = n.coerceSearch ?? this.#n;
@@ -336,7 +347,7 @@ var O = class {
336
347
  await this.#_.hydrate(n);
337
348
  let a = this.#_.effectiveDefs(n);
338
349
  return {
339
- branch: p(a, t, e.pathname, a.map(() => void 0)),
350
+ branch: m(a, t, e.pathname, a.map(() => void 0)),
340
351
  location: e,
341
352
  params: t,
342
353
  record: n,
@@ -357,37 +368,38 @@ var O = class {
357
368
  throw await e.return(void 0).catch(() => void 0), t;
358
369
  }
359
370
  }
360
- async #N(e, t, n, i, a, o, s) {
361
- if (!s()) return;
362
- let c = this.#_.effectiveDefs(e), l = c.some((e) => e.dataFn != null), u = c.map(() => void 0);
363
- if (l) {
364
- let a = r(this.#e, e.path, i, n.query), l = this.#v.consume(a);
365
- if (l) u = l;
371
+ async #N(e, t, n, r, a, o) {
372
+ if (!o()) return;
373
+ let s = this.#_.effectiveDefs(e), c = s.some((e) => e.dataFn != null), l = s.map(() => void 0);
374
+ if (c) {
375
+ let c = i(this.#e, e.path, r, n.query), u = this.#v.consume(c);
376
+ if (u) l = u;
366
377
  else {
367
- let r = c.map((e) => e.dataFn ? "loading" : "idle");
368
- this.#d = h({
378
+ let i = s.map((e) => e.dataFn ? "loading" : "idle");
379
+ this.#d = g({
369
380
  location: n,
370
- matches: p(c, i, n.pathname, u, r),
381
+ matches: m(s, r, n.pathname, l, i),
371
382
  status: "loading"
372
383
  }), this.#T();
373
384
  try {
374
- u = await this.#O(c, t, o, s, n, i);
385
+ l = await this.#O(s, t, a, o, n, r);
375
386
  } catch (t) {
376
- throw this.#d = h({
387
+ if (!o()) return;
388
+ throw this.#d = g({
377
389
  error: t,
378
390
  location: n,
379
- matches: p(c, i, n.pathname, u),
391
+ matches: m(s, r, n.pathname, l),
380
392
  status: "error"
381
- }), T(t, {
393
+ }), E(t, {
382
394
  routeName: e.leaf.name,
383
395
  source: "data-loader"
384
396
  }), t;
385
397
  }
386
398
  }
387
399
  }
388
- s() && (this.#d = h({
400
+ o() && (this.#d = g({
389
401
  location: n,
390
- matches: p(c, i, n.pathname, u),
402
+ matches: m(s, r, n.pathname, l),
391
403
  status: "idle"
392
404
  }));
393
405
  }
@@ -401,57 +413,54 @@ var O = class {
401
413
  }
402
414
  await e();
403
415
  }
404
- async #F(e, t = 0) {
405
- this.#l?.abort();
406
- let n = new AbortController();
407
- this.#l = n;
408
- let r = this.#d, i = () => !n.signal.aborted && !this.#f, a = u(this.#e, this.#r), o = await this.#j(a);
409
- if (!i()) return;
410
- if (o.type === "redirect") {
411
- await this.#R(o.redirectTo, !0, t);
412
- return;
416
+ async #F(e, t, r, i, a = 0, o = !1) {
417
+ let s = this.#d, c = () => e.isCurrent() && !this.#f, l = await this.#j(t);
418
+ if (!c()) return !1;
419
+ if (l.type === "redirect") {
420
+ if (a >= 5) throw new n();
421
+ return this.#F(e, this.#R(l.redirectTo, t.historyState), r, i, a + 1, !0);
413
422
  }
414
- if (o.type === "unmatched") {
423
+ if (l.type === "unmatched") {
415
424
  if (this.#g) {
416
- let t = [this.#g.leaf], o = p(t, {}, a.pathname, [void 0]), s = !1, c = a.query;
425
+ let n = [this.#g.leaf], a = m(n, {}, t.pathname, [void 0]), l = !1, u = !1, d = t.query;
417
426
  if (this.#n) try {
418
- c = this.#n(a.query);
427
+ d = this.#n(t.query);
419
428
  } catch (e) {
420
429
  this.#C(e, { source: "coerce-search" });
421
430
  }
422
- let l = async () => {
423
- if (!i()) return;
424
- let e = m(a, c, {}, o, (e, t) => this.navigate(e, t));
425
- await g(e, [...this.#t, ...this.#g.ownMiddleware], async () => {
426
- s = !0, await this.#N(this.#g, e, a, {}, o, n.signal, i);
431
+ let f = async () => {
432
+ if (!c()) return;
433
+ let n = h(t, d, {}, a, (e, t) => this.navigate(e, t));
434
+ u = await _(n, [...this.#t, ...this.#g.ownMiddleware], async () => {
435
+ c() && (l = !0, r(t, o), c() && await this.#N(this.#g, n, t, {}, e.signal, c));
427
436
  });
428
437
  };
429
438
  try {
430
- await this.#P(l, e);
439
+ await this.#P(f, i);
431
440
  } finally {
432
- i() && s && (this.#T(), this.#I(this.#d, r));
441
+ c() && l && (this.#T(), this.#I(this.#d, s));
433
442
  }
434
- return;
443
+ return u && l;
435
444
  }
436
- this.#d = h({
437
- location: o.location,
445
+ return !c() || (r(l.location, o), !c()) ? !1 : (this.#d = g({
446
+ location: l.location,
438
447
  matches: [],
439
448
  status: "idle"
440
- }), this.#T(), this.#I(this.#d, r);
441
- return;
449
+ }), this.#T(), this.#I(this.#d, s), !0);
442
450
  }
443
- let { branch: s, location: c, params: l, record: d, resolvedQuery: f } = o, _ = !1, v = async () => {
444
- if (!i()) return;
445
- let e = m(c, f, l, s, (e, t) => this.navigate(e, t));
446
- await g(e, [...this.#t, ...d.ownMiddleware], async () => {
447
- _ = !0, await this.#N(d, e, c, l, s, n.signal, i);
451
+ let { branch: u, location: d, params: f, record: p, resolvedQuery: v } = l, y = !1, b = !1, x = async () => {
452
+ if (!c()) return;
453
+ let t = h(d, v, f, u, (e, t) => this.navigate(e, t));
454
+ b = await _(t, [...this.#t, ...p.ownMiddleware], async () => {
455
+ c() && (y = !0, r(d, o), c() && await this.#N(p, t, d, f, e.signal, c));
448
456
  });
449
457
  };
450
458
  try {
451
- await this.#P(v, e);
459
+ await this.#P(x, i);
452
460
  } finally {
453
- i() && _ && (this.#T(), this.#I(this.#d, r));
461
+ c() && y && (this.#T(), this.#I(this.#d, s));
454
462
  }
463
+ return b && y;
455
464
  }
456
465
  #I(e, t) {
457
466
  if (!this.#o || typeof window > "u") return;
@@ -465,38 +474,51 @@ var O = class {
465
474
  }
466
475
  }
467
476
  #L(e) {
468
- let t = new URL(e, "http://localhost"), n = d(t.pathname, this.#e);
469
- return `${a(this.#e, n)}${t.search}${t.hash}`;
477
+ let t = new URL(e, "http://localhost"), n = f(t.pathname, this.#e);
478
+ return `${o(this.#e, n)}${t.search}${t.hash}`;
470
479
  }
471
- async #R(e, n = !0, r = 0) {
472
- if (r >= 5) throw new t();
473
- let i = this.#L(e);
474
- this.#m = i, n ? this.#r.replace(i) : this.#r.push(i), await this.#F(void 0, r + 1);
480
+ #R(e, t) {
481
+ let n = new URL(this.#L(e), "http://localhost");
482
+ return {
483
+ hash: n.hash.replace(/^#/, ""),
484
+ historyState: t,
485
+ pathname: f(n.pathname, this.#e),
486
+ query: u(n.search)
487
+ };
475
488
  }
476
- async #z(e, t = {}) {
489
+ #z(e) {
490
+ let t = new URLSearchParams();
491
+ for (let [n, r] of Object.entries(e.query)) Array.isArray(r) ? r.forEach((e) => {
492
+ t.append(n, e);
493
+ }) : t.set(n, r);
494
+ let n = t.toString(), r = e.hash ? `#${e.hash}` : "";
495
+ return `${o(this.#e, e.pathname)}${n ? `?${n}` : ""}${r}`;
496
+ }
497
+ #B(e) {
498
+ let t = new URL(e, "http://localhost"), n = f(t.pathname, this.#e), { params: r, record: i } = s(n, this.#i);
499
+ return {
500
+ name: i?.leaf.name,
501
+ params: r,
502
+ pathname: n,
503
+ query: u(t.search)
504
+ };
505
+ }
506
+ async #V(e, t = {}) {
477
507
  this.#b();
478
508
  let n = this.#L(e);
479
509
  if (!t.force && n === this.#m) return;
480
- let r = this.#m, i = this.#d.matches.map((e) => e.name), a = new URL(n, "http://localhost"), s = d(a.pathname, this.#e), { params: c, record: u } = o(s, this.#i), f = {
481
- name: u?.leaf.name,
482
- params: c,
483
- pathname: s,
484
- query: l(a.search)
485
- };
486
- if (await v(this.#u, i, f)) {
487
- this.#m = n, t.replace ? this.#r.replace(n, t.state) : this.#r.push(n, t.state);
488
- try {
489
- await this.#F(t.viewTransition);
490
- } catch (e) {
491
- throw this.#m = r, e;
492
- }
493
- }
510
+ let r = this.#u.begin(), i = this.#d.matches.map((e) => e.name), a = await y(this.#l, i, this.#B(n));
511
+ !r.isCurrent() || !a || await this.#F(r, this.#R(n, t.state), (e, t) => {
512
+ if (!r.isCurrent()) return;
513
+ let n = this.#z(e);
514
+ t ? this.#r.replace(n, e.historyState) : this.#r.push(n, e.historyState), this.#m = n;
515
+ }, t.viewTransition, 0, t.replace ?? !1);
494
516
  }
495
517
  };
496
- function k(e) {
497
- return new O(e);
518
+ function A(e) {
519
+ return new k(e);
498
520
  }
499
521
  //#endregion
500
- export { k as createRouter };
522
+ export { A as createRouter };
501
523
 
502
524
  //# sourceMappingURL=router.js.map