@vielzeug/wayfinder 3.1.0 → 26.10.1
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.
- package/README.md +1 -1
- package/dist/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +1 -6
- package/dist/_dev.js.map +1 -1
- package/dist/_navigation.cjs +1 -1
- package/dist/_navigation.cjs.map +1 -1
- package/dist/_navigation.js +1 -20
- package/dist/_navigation.js.map +1 -1
- package/dist/compile.cjs +1 -1
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.js +1 -46
- package/dist/compile.js.map +1 -1
- package/dist/context.cjs +1 -1
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -59
- package/dist/context.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +4 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -17
- package/dist/errors.js.map +1 -1
- package/dist/guards.cjs +1 -1
- package/dist/guards.cjs.map +1 -1
- package/dist/guards.js +1 -9
- package/dist/guards.js.map +1 -1
- package/dist/history.cjs +1 -1
- package/dist/history.cjs.map +1 -1
- package/dist/history.d.ts +7 -0
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +1 -99
- package/dist/history.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/middleware.cjs +1 -1
- package/dist/middleware.cjs.map +1 -1
- package/dist/middleware.d.ts +1 -1
- package/dist/middleware.js +1 -9
- package/dist/middleware.js.map +1 -1
- package/dist/path.cjs +1 -1
- package/dist/path.cjs.map +1 -1
- package/dist/path.d.ts +1 -1
- package/dist/path.js +1 -132
- package/dist/path.js.map +1 -1
- package/dist/phase-mirror.cjs +2 -0
- package/dist/phase-mirror.cjs.map +1 -0
- package/dist/phase-mirror.d.ts +51 -0
- package/dist/phase-mirror.d.ts.map +1 -0
- package/dist/phase-mirror.js +2 -0
- package/dist/phase-mirror.js.map +1 -0
- package/dist/route-signals.cjs +2 -0
- package/dist/route-signals.cjs.map +1 -0
- package/dist/route-signals.d.ts +23 -0
- package/dist/route-signals.d.ts.map +1 -0
- package/dist/route-signals.js +2 -0
- package/dist/route-signals.js.map +1 -0
- package/dist/router.cjs +1 -1
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.ts +8 -2
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +1 -475
- package/dist/router.js.map +1 -1
- package/dist/types.d.ts +12 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/wayfinder.cjs +1 -1
- package/dist/wayfinder.cjs.map +1 -1
- package/dist/wayfinder.iife.js +1 -1
- package/dist/wayfinder.iife.js.map +1 -1
- package/dist/wayfinder.js +1 -1
- package/dist/wayfinder.js.map +1 -1
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -55,4 +55,4 @@ await router.navigate({ name: 'dashboard.settings' });
|
|
|
55
55
|
|
|
56
56
|
## License
|
|
57
57
|
|
|
58
|
-
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu)
|
|
58
|
+
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu): part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
|
package/dist/_dev.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function warn(e){}function error(e,...t){}exports.error=error,exports.warn=warn;
|
|
2
2
|
//# sourceMappingURL=_dev.cjs.map
|
package/dist/_dev.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __WAYFINDER_PROD__?: boolean }).__WAYFINDER_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/wayfinder] ${msg}`);\n}\n\n/** @internal */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/wayfinder] ${msg}`, ...args);\n}\n"],"mappings":"AAGA,SAAgB,
|
|
1
|
+
{"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __WAYFINDER_PROD__?: boolean }).__WAYFINDER_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/wayfinder] ${msg}`);\n}\n\n/** @internal */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/wayfinder] ${msg}`, ...args);\n}\n"],"mappings":"AAGA,SAAgB,KAAK,EAAmB,CAExC,CAGA,SAAgB,MAAM,EAAa,GAAG,EAAuB,CAE7D"}
|
package/dist/_dev.js
CHANGED
package/dist/_dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __WAYFINDER_PROD__?: boolean }).__WAYFINDER_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/wayfinder] ${msg}`);\n}\n\n/** @internal */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/wayfinder] ${msg}`, ...args);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __WAYFINDER_PROD__?: boolean }).__WAYFINDER_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/wayfinder] ${msg}`);\n}\n\n/** @internal */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/wayfinder] ${msg}`, ...args);\n}\n"],"mappings":"AAGA,SAAgB,KAAK,EAAmB,CAExC,CAGA,SAAgB,MAAM,EAAa,GAAG,EAAuB,CAE7D"}
|
package/dist/_navigation.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function createNavigationCoordinator(){let e;return{begin(){e?.abort();let t=new AbortController;return e=t,{isCurrent:()=>e===t&&!t.signal.aborted,signal:t.signal}},invalidate(t){e?.abort(t),e=void 0}}}exports.createNavigationCoordinator=createNavigationCoordinator;
|
|
2
2
|
//# sourceMappingURL=_navigation.cjs.map
|
package/dist/_navigation.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_navigation.cjs","names":[],"sources":["../src/_navigation.ts"],"sourcesContent":["export type NavigationAttempt = {\n isCurrent(): boolean;\n readonly signal: AbortSignal;\n};\n\n/** Coordinates navigation ownership so stale work cannot commit router state. */\nexport function createNavigationCoordinator() {\n let active: AbortController | undefined;\n\n return {\n begin(): NavigationAttempt {\n active?.abort();\n\n const controller = new AbortController();\n\n active = controller;\n\n return {\n isCurrent: () => active === controller && !controller.signal.aborted,\n signal: controller.signal,\n };\n },\n\n invalidate(reason?: unknown): void {\n active?.abort(reason);\n active = undefined;\n },\n };\n}\n"],"mappings":"AAMA,SAAgB,
|
|
1
|
+
{"version":3,"file":"_navigation.cjs","names":[],"sources":["../src/_navigation.ts"],"sourcesContent":["export type NavigationAttempt = {\n isCurrent(): boolean;\n readonly signal: AbortSignal;\n};\n\n/** Coordinates navigation ownership so stale work cannot commit router state. */\nexport function createNavigationCoordinator() {\n let active: AbortController | undefined;\n\n return {\n begin(): NavigationAttempt {\n active?.abort();\n\n const controller = new AbortController();\n\n active = controller;\n\n return {\n isCurrent: () => active === controller && !controller.signal.aborted,\n signal: controller.signal,\n };\n },\n\n invalidate(reason?: unknown): void {\n active?.abort(reason);\n active = undefined;\n },\n };\n}\n"],"mappings":"AAMA,SAAgB,6BAA8B,CAC5C,IAAI,EAEJ,MAAO,CACL,OAA2B,CACzB,GAAQ,MAAM,EAEd,IAAM,EAAa,IAAI,gBAIvB,MAFA,GAAS,EAEF,CACL,cAAiB,IAAW,GAAc,CAAC,EAAW,OAAO,QAC7D,OAAQ,EAAW,MACrB,CACF,EAEA,WAAW,EAAwB,CACjC,GAAQ,MAAM,CAAM,EACpB,EAAS,IAAA,EACX,CACF,CACF"}
|
package/dist/_navigation.js
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
function e() {
|
|
3
|
-
let e;
|
|
4
|
-
return {
|
|
5
|
-
begin() {
|
|
6
|
-
e?.abort();
|
|
7
|
-
let t = new AbortController();
|
|
8
|
-
return e = t, {
|
|
9
|
-
isCurrent: () => e === t && !t.signal.aborted,
|
|
10
|
-
signal: t.signal
|
|
11
|
-
};
|
|
12
|
-
},
|
|
13
|
-
invalidate(t) {
|
|
14
|
-
e?.abort(t), e = void 0;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
export { e as createNavigationCoordinator };
|
|
20
|
-
|
|
1
|
+
function createNavigationCoordinator(){let e;return{begin(){e?.abort();let t=new AbortController;return e=t,{isCurrent:()=>e===t&&!t.signal.aborted,signal:t.signal}},invalidate(t){e?.abort(t),e=void 0}}}export{createNavigationCoordinator};
|
|
21
2
|
//# sourceMappingURL=_navigation.js.map
|
package/dist/_navigation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_navigation.js","names":[],"sources":["../src/_navigation.ts"],"sourcesContent":["export type NavigationAttempt = {\n isCurrent(): boolean;\n readonly signal: AbortSignal;\n};\n\n/** Coordinates navigation ownership so stale work cannot commit router state. */\nexport function createNavigationCoordinator() {\n let active: AbortController | undefined;\n\n return {\n begin(): NavigationAttempt {\n active?.abort();\n\n const controller = new AbortController();\n\n active = controller;\n\n return {\n isCurrent: () => active === controller && !controller.signal.aborted,\n signal: controller.signal,\n };\n },\n\n invalidate(reason?: unknown): void {\n active?.abort(reason);\n active = undefined;\n },\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"_navigation.js","names":[],"sources":["../src/_navigation.ts"],"sourcesContent":["export type NavigationAttempt = {\n isCurrent(): boolean;\n readonly signal: AbortSignal;\n};\n\n/** Coordinates navigation ownership so stale work cannot commit router state. */\nexport function createNavigationCoordinator() {\n let active: AbortController | undefined;\n\n return {\n begin(): NavigationAttempt {\n active?.abort();\n\n const controller = new AbortController();\n\n active = controller;\n\n return {\n isCurrent: () => active === controller && !controller.signal.aborted,\n signal: controller.signal,\n };\n },\n\n invalidate(reason?: unknown): void {\n active?.abort(reason);\n active = undefined;\n },\n };\n}\n"],"mappings":"AAMA,SAAgB,6BAA8B,CAC5C,IAAI,EAEJ,MAAO,CACL,OAA2B,CACzB,GAAQ,MAAM,EAEd,IAAM,EAAa,IAAI,gBAIvB,MAFA,GAAS,EAEF,CACL,cAAiB,IAAW,GAAc,CAAC,EAAW,OAAO,QAC7D,OAAQ,EAAW,MACrB,CACF,EAEA,WAAW,EAAwB,CACjC,GAAQ,MAAM,CAAM,EACpB,EAAS,IAAA,EACX,CACF,CACF"}
|
package/dist/compile.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./errors.cjs"),t=require("./path.cjs");require("./_dev.cjs");function
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./path.cjs");require("./_dev.cjs");function compileRoutes(n){let r=[],compile=(n,i,a,o,s)=>{if(i.index&&i.path!==void 0)throw new e.WayfinderConfigError(`Route "${n}" cannot define both index and path`);if(!i.index&&i.path===void 0)throw new e.WayfinderConfigError(`Route "${n}" must define path or set index: true`);let c=i.index?a:t.normalizePath(i.path?t.joinPaths(a,i.path):a),l=[...o,{dataFn:i.data,name:n,onError:i.onError}],u=[...s,...i.middleware??[]];if(i.children)for(let[e,t]of Object.entries(i.children))compile(`${n}.${e}`,t,c,l,u);if(i.redirect!==void 0||!i.children||i.data!==void 0){let e=l[l.length-1];r.push({branchDefs:l,coerceSearch:i.coerceSearch,leaf:e,matcher:t.compilePathMatcher(c),ownMiddleware:u,path:c,redirect:i.redirect})}};for(let[e,t]of Object.entries(n.routes))compile(e,t,`/`,[],[]);let i=new Set;for(let t of r){if(i.has(t.leaf.name))throw new e.WayfinderConfigError(`Duplicate route name: "${t.leaf.name}". A top-level route key must not coincide with a nested route's dot-notation name.`);i.add(t.leaf.name)}let a=!1;for(let e of r){let t=e.path===`/*`||e.path.endsWith(`/*`)||e.path.includes(`:`)&&e.path.endsWith(`*`);a&&!t&&`${e.leaf.name}${e.path}`,t&&(a=!0)}return{records:r,routesByName:new Map(r.map(e=>[e.leaf.name,e]))}}exports.compileRoutes=compileRoutes;
|
|
2
2
|
//# sourceMappingURL=compile.cjs.map
|
package/dist/compile.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.cjs","names":[],"sources":["../src/compile.ts"],"sourcesContent":["import { warn } from './_dev';\nimport {
|
|
1
|
+
{"version":3,"file":"compile.cjs","names":[],"sources":["../src/compile.ts"],"sourcesContent":["import { warn } from './_dev';\nimport { WayfinderConfigError } from './errors';\nimport { compilePathMatcher, joinPaths, normalizePath } from './path';\nimport type { Middleware, RouteBranchDef, RouteDefinition, RouteRecord, RouterOptions, RouteTable } from './types';\n\nexport type CompiledRoutes = {\n records: readonly RouteRecord[];\n routesByName: ReadonlyMap<string, RouteRecord>;\n};\n\nexport function compileRoutes<TRoutes extends RouteTable>(options: RouterOptions<TRoutes>): CompiledRoutes {\n const records: RouteRecord[] = [];\n\n const compile = (\n name: string,\n route: RouteDefinition,\n ancestorPath: string,\n ancestorBranchDefs: RouteBranchDef[],\n ancestorMiddleware: RouteRecord['ownMiddleware'],\n ): void => {\n if (route.index && route.path !== undefined) {\n throw new WayfinderConfigError(`Route \"${name}\" cannot define both index and path`);\n }\n\n if (!route.index && route.path === undefined) {\n throw new WayfinderConfigError(`Route \"${name}\" must define path or set index: true`);\n }\n\n const ownPath = route.index\n ? ancestorPath\n : normalizePath(route.path ? joinPaths(ancestorPath, route.path) : ancestorPath);\n\n const branchDefs: RouteBranchDef[] = [\n ...ancestorBranchDefs,\n {\n dataFn: route.data,\n name,\n onError: route.onError as RouteBranchDef['onError'],\n },\n ];\n\n const ownMiddleware: Middleware[] = [\n ...ancestorMiddleware,\n ...((route.middleware ?? []) as unknown as Middleware[]),\n ];\n\n if (route.children) {\n for (const [childName, childRoute] of Object.entries(route.children)) {\n compile(`${name}.${childName}`, childRoute, ownPath, branchDefs, ownMiddleware);\n }\n }\n\n // Emit a record for leaf routes (no children) and routes with data or redirect.\n // A bare parent-only route (children but no data/redirect) is not emitted as a leaf.\n if (route.redirect !== undefined || !route.children || route.data !== undefined) {\n const leaf = branchDefs[branchDefs.length - 1]!;\n\n records.push({\n branchDefs,\n coerceSearch: route.coerceSearch,\n leaf,\n matcher: compilePathMatcher(ownPath),\n ownMiddleware,\n path: ownPath,\n redirect: route.redirect,\n });\n }\n };\n\n for (const [name, route] of Object.entries(options.routes)) {\n compile(name, route, '/', [], []);\n }\n\n // Validate duplicate names.\n const namesSeen = new Set<string>();\n\n for (const record of records) {\n if (namesSeen.has(record.leaf.name)) {\n throw new WayfinderConfigError(\n `Duplicate route name: \"${record.leaf.name}\". A top-level route key must not coincide with a nested route's dot-notation name.`,\n );\n }\n\n namesSeen.add(record.leaf.name);\n }\n\n // Warn when a catch-all or wildcard-param route precedes more specific routes.\n // Routes match in array order (object key order), so a wildcard placed too early silently shadows later routes.\n let wildcardSeen = false;\n\n for (const record of records) {\n const isCatchAll =\n record.path === '/*' || record.path.endsWith('/*') || (record.path.includes(':') && record.path.endsWith('*'));\n\n if (wildcardSeen && !isCatchAll) {\n warn(\n `Route \"${record.leaf.name}\" (${record.path}) is defined after a wildcard/catch-all route and will never match. Move specific routes before wildcards.`,\n );\n }\n\n if (isCatchAll) wildcardSeen = true;\n }\n\n return {\n records,\n routesByName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AAO,KAAK,KAAK,oFAC7C,EAGF,EAAU,IAAI,EAAO,KAAK,IAAI,CAChC,CAIA,IAAI,EAAe,GAEnB,IAAK,IAAM,KAAU,EAAS,CAC5B,IAAM,EACJ,EAAO,OAAS,MAAQ,EAAO,KAAK,SAAS,IAAI,GAAM,EAAO,KAAK,SAAS,GAAG,GAAK,EAAO,KAAK,SAAS,GAAG,EAE1G,GAAgB,CAAC,GAEjB,GAAU,EAAO,KAAK,KAAtB,EAAgC,EAAO,KAAvC,EAIA,IAAY,EAAe,GACjC,CAEA,MAAO,CACL,UACA,aAAc,IAAI,IAAI,EAAQ,IAAK,GAAM,CAAC,EAAE,KAAK,KAAM,CAAC,CAAC,CAAC,CAC5D,CACF"}
|
package/dist/compile.js
CHANGED
|
@@ -1,47 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { compilePathMatcher as t, joinPaths as n, normalizePath as r } from "./path.js";
|
|
3
|
-
import "./_dev.js";
|
|
4
|
-
//#region src/compile.ts
|
|
5
|
-
function i(i) {
|
|
6
|
-
let a = [], o = (i, s, c, l, u) => {
|
|
7
|
-
if (s.index && s.path !== void 0) throw new e(`Route "${i}" cannot define both index and path`);
|
|
8
|
-
if (!s.index && s.path === void 0) throw new e(`Route "${i}" must define path or set index: true`);
|
|
9
|
-
let d = s.index ? c : r(s.path ? n(c, s.path) : c), f = [...l, {
|
|
10
|
-
dataFn: s.data,
|
|
11
|
-
name: i,
|
|
12
|
-
onError: s.onError
|
|
13
|
-
}], p = [...u, ...s.middleware ?? []];
|
|
14
|
-
if (s.children) for (let [e, t] of Object.entries(s.children)) o(`${i}.${e}`, t, d, f, p);
|
|
15
|
-
if (s.redirect !== void 0 || !s.children || s.data !== void 0) {
|
|
16
|
-
let e = f[f.length - 1];
|
|
17
|
-
a.push({
|
|
18
|
-
branchDefs: f,
|
|
19
|
-
coerceSearch: s.coerceSearch,
|
|
20
|
-
leaf: e,
|
|
21
|
-
matcher: t(d),
|
|
22
|
-
ownMiddleware: p,
|
|
23
|
-
path: d,
|
|
24
|
-
redirect: s.redirect
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
for (let [e, t] of Object.entries(i.routes)) o(e, t, "/", [], []);
|
|
29
|
-
let s = /* @__PURE__ */ new Set();
|
|
30
|
-
for (let t of a) {
|
|
31
|
-
if (s.has(t.leaf.name)) throw new e(`Duplicate route name: "${t.leaf.name}". A top-level route key must not coincide with a nested route's dot-notation name.`);
|
|
32
|
-
s.add(t.leaf.name);
|
|
33
|
-
}
|
|
34
|
-
let c = !1;
|
|
35
|
-
for (let e of a) {
|
|
36
|
-
let t = e.path === "/*" || e.path.endsWith("/*") || e.path.includes(":") && e.path.endsWith("*");
|
|
37
|
-
c && !t && `${e.leaf.name}${e.path}`, t && (c = !0);
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
records: a,
|
|
41
|
-
routesByName: new Map(a.map((e) => [e.leaf.name, e]))
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
//#endregion
|
|
45
|
-
export { i as compileRoutes };
|
|
46
|
-
|
|
1
|
+
import{WayfinderConfigError as e}from"./errors.js";import{compilePathMatcher as t,joinPaths as n,normalizePath as r}from"./path.js";import"./_dev.js";function compileRoutes(i){let a=[],compile=(i,o,s,c,l)=>{if(o.index&&o.path!==void 0)throw new e(`Route "${i}" cannot define both index and path`);if(!o.index&&o.path===void 0)throw new e(`Route "${i}" must define path or set index: true`);let u=o.index?s:r(o.path?n(s,o.path):s),d=[...c,{dataFn:o.data,name:i,onError:o.onError}],f=[...l,...o.middleware??[]];if(o.children)for(let[e,t]of Object.entries(o.children))compile(`${i}.${e}`,t,u,d,f);if(o.redirect!==void 0||!o.children||o.data!==void 0){let e=d[d.length-1];a.push({branchDefs:d,coerceSearch:o.coerceSearch,leaf:e,matcher:t(u),ownMiddleware:f,path:u,redirect:o.redirect})}};for(let[e,t]of Object.entries(i.routes))compile(e,t,`/`,[],[]);let o=new Set;for(let t of a){if(o.has(t.leaf.name))throw new e(`Duplicate route name: "${t.leaf.name}". A top-level route key must not coincide with a nested route's dot-notation name.`);o.add(t.leaf.name)}let s=!1;for(let e of a){let t=e.path===`/*`||e.path.endsWith(`/*`)||e.path.includes(`:`)&&e.path.endsWith(`*`);s&&!t&&`${e.leaf.name}${e.path}`,t&&(s=!0)}return{records:a,routesByName:new Map(a.map(e=>[e.leaf.name,e]))}}export{compileRoutes};
|
|
47
2
|
//# sourceMappingURL=compile.js.map
|
package/dist/compile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.js","names":[],"sources":["../src/compile.ts"],"sourcesContent":["import { warn } from './_dev';\nimport {
|
|
1
|
+
{"version":3,"file":"compile.js","names":[],"sources":["../src/compile.ts"],"sourcesContent":["import { warn } from './_dev';\nimport { WayfinderConfigError } from './errors';\nimport { compilePathMatcher, joinPaths, normalizePath } from './path';\nimport type { Middleware, RouteBranchDef, RouteDefinition, RouteRecord, RouterOptions, RouteTable } from './types';\n\nexport type CompiledRoutes = {\n records: readonly RouteRecord[];\n routesByName: ReadonlyMap<string, RouteRecord>;\n};\n\nexport function compileRoutes<TRoutes extends RouteTable>(options: RouterOptions<TRoutes>): CompiledRoutes {\n const records: RouteRecord[] = [];\n\n const compile = (\n name: string,\n route: RouteDefinition,\n ancestorPath: string,\n ancestorBranchDefs: RouteBranchDef[],\n ancestorMiddleware: RouteRecord['ownMiddleware'],\n ): void => {\n if (route.index && route.path !== undefined) {\n throw new WayfinderConfigError(`Route \"${name}\" cannot define both index and path`);\n }\n\n if (!route.index && route.path === undefined) {\n throw new WayfinderConfigError(`Route \"${name}\" must define path or set index: true`);\n }\n\n const ownPath = route.index\n ? ancestorPath\n : normalizePath(route.path ? joinPaths(ancestorPath, route.path) : ancestorPath);\n\n const branchDefs: RouteBranchDef[] = [\n ...ancestorBranchDefs,\n {\n dataFn: route.data,\n name,\n onError: route.onError as RouteBranchDef['onError'],\n },\n ];\n\n const ownMiddleware: Middleware[] = [\n ...ancestorMiddleware,\n ...((route.middleware ?? []) as unknown as Middleware[]),\n ];\n\n if (route.children) {\n for (const [childName, childRoute] of Object.entries(route.children)) {\n compile(`${name}.${childName}`, childRoute, ownPath, branchDefs, ownMiddleware);\n }\n }\n\n // Emit a record for leaf routes (no children) and routes with data or redirect.\n // A bare parent-only route (children but no data/redirect) is not emitted as a leaf.\n if (route.redirect !== undefined || !route.children || route.data !== undefined) {\n const leaf = branchDefs[branchDefs.length - 1]!;\n\n records.push({\n branchDefs,\n coerceSearch: route.coerceSearch,\n leaf,\n matcher: compilePathMatcher(ownPath),\n ownMiddleware,\n path: ownPath,\n redirect: route.redirect,\n });\n }\n };\n\n for (const [name, route] of Object.entries(options.routes)) {\n compile(name, route, '/', [], []);\n }\n\n // Validate duplicate names.\n const namesSeen = new Set<string>();\n\n for (const record of records) {\n if (namesSeen.has(record.leaf.name)) {\n throw new WayfinderConfigError(\n `Duplicate route name: \"${record.leaf.name}\". A top-level route key must not coincide with a nested route's dot-notation name.`,\n );\n }\n\n namesSeen.add(record.leaf.name);\n }\n\n // Warn when a catch-all or wildcard-param route precedes more specific routes.\n // Routes match in array order (object key order), so a wildcard placed too early silently shadows later routes.\n let wildcardSeen = false;\n\n for (const record of records) {\n const isCatchAll =\n record.path === '/*' || record.path.endsWith('/*') || (record.path.includes(':') && record.path.endsWith('*'));\n\n if (wildcardSeen && !isCatchAll) {\n warn(\n `Route \"${record.leaf.name}\" (${record.path}) is defined after a wildcard/catch-all route and will never match. Move specific routes before wildcards.`,\n );\n }\n\n if (isCatchAll) wildcardSeen = true;\n }\n\n return {\n records,\n routesByName: new Map(records.map((r) => [r.leaf.name, r])),\n };\n}\n"],"mappings":"sJAUA,SAAgB,cAA0C,EAAiD,CACzG,IAAM,EAAyB,CAAC,EAE1B,SACJ,EACA,EACA,EACA,EACA,IACS,CACT,GAAI,EAAM,OAAS,EAAM,OAAS,IAAA,GAChC,MAAM,IAAI,EAAqB,UAAU,EAAK,o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GAEjB,GAAU,EAAO,KAAK,KAAtB,EAAgC,EAAO,KAAvC,EAIA,IAAY,EAAe,GACjC,CAEA,MAAO,CACL,UACA,aAAc,IAAI,IAAI,EAAQ,IAAK,GAAM,CAAC,EAAE,KAAK,KAAM,CAAC,CAAC,CAAC,CAC5D,CACF"}
|
package/dist/context.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./errors.cjs");require("./_dev.cjs");function
|
|
1
|
+
const e=require("./errors.cjs");require("./_dev.cjs");function createRouteState(e){return{error:e.error,location:e.location,matches:e.matches,status:e.status}}function buildMatchBranch(e,t,n,r){return e.map((e,i)=>({data:r[i],name:e.name,params:{...t},pathname:n}))}function createRouteContext(e,t,n,r,i){return{hash:e.hash,historyState:e.historyState,locals:{},matches:r,navigate:i,params:n,pathname:e.pathname,query:t}}async function executeMiddlewarePipeline(t,n,r,i){let a=!1;async function dispatch(o){if(o<n.length){let r=!1;try{await n[o]?.(t,async()=>{if(r)throw new e.WayfinderApiError(`next() called multiple times`);r=!0,await dispatch(o+1)})}catch(e){throw i?.(e)??e}return}a=!0,await r()}return await dispatch(0),a}function reportError(e,t,n){if(n){n(e,t);return}}exports.buildMatchBranch=buildMatchBranch,exports.createRouteContext=createRouteContext,exports.createRouteState=createRouteState,exports.executeMiddlewarePipeline=executeMiddlewarePipeline,exports.reportError=reportError;
|
|
2
2
|
//# sourceMappingURL=context.cjs.map
|
package/dist/context.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.cjs","names":[],"sources":["../src/context.ts"],"sourcesContent":["import { error as logError } from './_dev';\nimport { WayfinderApiError } from './errors';\nimport type {\n Middleware,\n NavigationStatus,\n ResolvedQueryParams,\n RouteBranchDef,\n RouteContext,\n RouteLocation,\n RouteMatch,\n RouteMatchBranch,\n RouteParams,\n RouterErrorContext,\n RouteState,\n RouteTable,\n} from './types';\n\n// ─── Route state ──────────────────────────────────────────────────────────────\n\n/** No defensive deep-copy
|
|
1
|
+
{"version":3,"file":"context.cjs","names":[],"sources":["../src/context.ts"],"sourcesContent":["import { error as logError } from './_dev';\nimport { WayfinderApiError } from './errors';\nimport type {\n Middleware,\n NavigationStatus,\n ResolvedQueryParams,\n RouteBranchDef,\n RouteContext,\n RouteLocation,\n RouteMatch,\n RouteMatchBranch,\n RouteParams,\n RouterErrorContext,\n RouteState,\n RouteTable,\n} from './types';\n\n// ─── Route state ──────────────────────────────────────────────────────────────\n\n/** No defensive deep-copy: RouteState is typed readonly; callers always pass fresh objects. */\nexport function createRouteState(input: {\n error?: unknown;\n location: RouteLocation;\n matches: RouteMatchBranch;\n status: NavigationStatus;\n}): RouteState {\n return {\n error: input.error,\n location: input.location,\n matches: input.matches,\n status: input.status,\n };\n}\n\n/**\n * Build a RouteMatchBranch from compiled defs and data results.\n */\nexport function buildMatchBranch(\n branchDefs: readonly RouteBranchDef[],\n params: RouteParams,\n pathname: string,\n dataResults: unknown[],\n): RouteMatchBranch {\n return branchDefs.map(\n (def, i): RouteMatch => ({\n data: dataResults[i],\n name: def.name,\n params: { ...params },\n pathname,\n }),\n );\n}\n\n// ─── Context factory ──────────────────────────────────────────────────────────\n\nexport function createRouteContext<TRoutes extends RouteTable>(\n location: RouteLocation,\n resolvedQuery: ResolvedQueryParams,\n params: RouteParams,\n matches: RouteMatchBranch,\n navigate: RouteContext<RouteParams, TRoutes>['navigate'],\n): RouteContext<RouteParams, TRoutes> {\n return {\n hash: location.hash,\n historyState: location.historyState,\n locals: {},\n matches,\n navigate,\n params,\n pathname: location.pathname,\n query: resolvedQuery,\n };\n}\n\n// ─── Middleware pipeline ──────────────────────────────────────────────────────\n\nexport async function executeMiddlewarePipeline<TRoutes extends RouteTable>(\n context: RouteContext<RouteParams, TRoutes>,\n middleware: readonly Middleware<TRoutes>[],\n terminal: () => Promise<void>,\n wrapMiddlewareError?: (error: unknown) => unknown,\n): Promise<boolean> {\n let terminalRan = false;\n\n async function dispatch(index: number): Promise<void> {\n if (index < middleware.length) {\n let called = false;\n\n try {\n await middleware[index]?.(context, async () => {\n if (called) throw new WayfinderApiError('next() called multiple times');\n\n called = true;\n await dispatch(index + 1);\n });\n } catch (error) {\n throw wrapMiddlewareError?.(error) ?? error;\n }\n\n return;\n }\n\n terminalRan = true;\n await terminal();\n }\n\n await dispatch(0);\n\n return terminalRan;\n}\n\n// ─── Error reporting ──────────────────────────────────────────────────────────\n\nexport function reportError(\n error: unknown,\n context: RouterErrorContext,\n onError?: (e: unknown, ctx: RouterErrorContext) => void,\n): void {\n if (onError) {\n onError(error, context);\n\n return;\n }\n\n logError('Unhandled router error. Provide an onError callback to handle errors explicitly:', error);\n}\n"],"mappings":"sDAoBA,SAAgB,iBAAiB,EAKlB,CACb,MAAO,CACL,MAAO,EAAM,MACb,SAAU,EAAM,SAChB,QAAS,EAAM,QACf,OAAQ,EAAM,MAChB,CACF,CAKA,SAAgB,iBACd,EACA,EACA,EACA,EACkB,CAClB,OAAO,EAAW,KACf,EAAK,KAAmB,CACvB,KAAM,EAAY,GAClB,KAAM,EAAI,KACV,OAAQ,CAAE,GAAG,CAAO,EACpB,UACF,EACF,CACF,CAIA,SAAgB,mBACd,EACA,EACA,EACA,EACA,EACoC,CACpC,MAAO,CACL,KAAM,EAAS,KACf,aAAc,EAAS,aACvB,OAAQ,CAAC,EACT,UACA,WACA,SACA,SAAU,EAAS,SACnB,MAAO,CACT,CACF,CAIA,eAAsB,0BACpB,EACA,EACA,EACA,EACkB,CAClB,IAAI,EAAc,GAElB,eAAe,SAAS,EAA8B,CACpD,GAAI,EAAQ,EAAW,OAAQ,CAC7B,IAAI,EAAS,GAEb,GAAI,CACF,MAAM,EAAW,EAAM,GAAG,EAAS,SAAY,CAC7C,GAAI,EAAQ,MAAM,IAAI,EAAA,kBAAkB,8BAA8B,EAEtE,EAAS,GACT,MAAM,SAAS,EAAQ,CAAC,CAC1B,CAAC,CACH,OAAS,EAAO,CACd,MAAM,IAAsB,CAAK,GAAK,CACxC,CAEA,MACF,CAEA,EAAc,GACd,MAAM,EAAS,CACjB,CAIA,OAFA,MAAM,SAAS,CAAC,EAET,CACT,CAIA,SAAgB,YACd,EACA,EACA,EACM,CACN,GAAI,EAAS,CACX,EAAQ,EAAO,CAAO,EAEtB,MACF,CAGF"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Middleware, NavigationStatus, ResolvedQueryParams, RouteBranchDef, RouteContext, RouteLocation, RouteMatchBranch, RouteParams, RouterErrorContext, RouteState, RouteTable } from './types';
|
|
2
|
-
/** No defensive deep-copy
|
|
2
|
+
/** No defensive deep-copy: RouteState is typed readonly; callers always pass fresh objects. */
|
|
3
3
|
export declare function createRouteState(input: {
|
|
4
4
|
error?: unknown;
|
|
5
5
|
location: RouteLocation;
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,aAAa,EAEb,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,UAAU,EACX,MAAM,SAAS,CAAC;AAIjB
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,aAAa,EAEb,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,UAAU,EACX,MAAM,SAAS,CAAC;AAIjB,+FAA+F;AAC/F,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,MAAM,EAAE,gBAAgB,CAAC;CAC1B,GAAG,UAAU,CAOb;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,SAAS,cAAc,EAAE,EACrC,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,OAAO,EAAE,GACrB,gBAAgB,CASlB;AAID,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,UAAU,EAC3D,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,mBAAmB,EAClC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GACvD,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAWpC;AAID,wBAAsB,yBAAyB,CAAC,OAAO,SAAS,UAAU,EACxE,OAAO,EAAE,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,EAC3C,UAAU,EAAE,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,EAC1C,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAC7B,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,GAChD,OAAO,CAAC,OAAO,CAAC,CA4BlB;AAID,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,kBAAkB,EAC3B,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,KAAK,IAAI,GACtD,IAAI,CAQN"}
|
package/dist/context.js
CHANGED
|
@@ -1,60 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./_dev.js";
|
|
3
|
-
//#region src/context.ts
|
|
4
|
-
function t(e) {
|
|
5
|
-
return {
|
|
6
|
-
error: e.error,
|
|
7
|
-
location: e.location,
|
|
8
|
-
matches: e.matches,
|
|
9
|
-
status: e.status
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
function n(e, t, n, r) {
|
|
13
|
-
return e.map((e, i) => ({
|
|
14
|
-
data: r[i],
|
|
15
|
-
name: e.name,
|
|
16
|
-
params: { ...t },
|
|
17
|
-
pathname: n
|
|
18
|
-
}));
|
|
19
|
-
}
|
|
20
|
-
function r(e, t, n, r, i) {
|
|
21
|
-
return {
|
|
22
|
-
hash: e.hash,
|
|
23
|
-
historyState: e.historyState,
|
|
24
|
-
locals: {},
|
|
25
|
-
matches: r,
|
|
26
|
-
navigate: i,
|
|
27
|
-
params: n,
|
|
28
|
-
pathname: e.pathname,
|
|
29
|
-
query: t
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
async function i(t, n, r, i) {
|
|
33
|
-
let a = !1;
|
|
34
|
-
async function o(s) {
|
|
35
|
-
if (s < n.length) {
|
|
36
|
-
let r = !1;
|
|
37
|
-
try {
|
|
38
|
-
await n[s]?.(t, async () => {
|
|
39
|
-
if (r) throw new e("next() called multiple times");
|
|
40
|
-
r = !0, await o(s + 1);
|
|
41
|
-
});
|
|
42
|
-
} catch (e) {
|
|
43
|
-
throw i?.(e) ?? e;
|
|
44
|
-
}
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
a = !0, await r();
|
|
48
|
-
}
|
|
49
|
-
return await o(0), a;
|
|
50
|
-
}
|
|
51
|
-
function a(e, t, n) {
|
|
52
|
-
if (n) {
|
|
53
|
-
n(e, t);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
export { n as buildMatchBranch, r as createRouteContext, t as createRouteState, i as executeMiddlewarePipeline, a as reportError };
|
|
59
|
-
|
|
1
|
+
import{WayfinderApiError as e}from"./errors.js";import"./_dev.js";function createRouteState(e){return{error:e.error,location:e.location,matches:e.matches,status:e.status}}function buildMatchBranch(e,t,n,r){return e.map((e,i)=>({data:r[i],name:e.name,params:{...t},pathname:n}))}function createRouteContext(e,t,n,r,i){return{hash:e.hash,historyState:e.historyState,locals:{},matches:r,navigate:i,params:n,pathname:e.pathname,query:t}}async function executeMiddlewarePipeline(t,n,r,i){let a=!1;async function dispatch(o){if(o<n.length){let r=!1;try{await n[o]?.(t,async()=>{if(r)throw new e(`next() called multiple times`);r=!0,await dispatch(o+1)})}catch(e){throw i?.(e)??e}return}a=!0,await r()}return await dispatch(0),a}function reportError(e,t,n){if(n){n(e,t);return}}export{buildMatchBranch,createRouteContext,createRouteState,executeMiddlewarePipeline,reportError};
|
|
60
2
|
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import { error as logError } from './_dev';\nimport { WayfinderApiError } from './errors';\nimport type {\n Middleware,\n NavigationStatus,\n ResolvedQueryParams,\n RouteBranchDef,\n RouteContext,\n RouteLocation,\n RouteMatch,\n RouteMatchBranch,\n RouteParams,\n RouterErrorContext,\n RouteState,\n RouteTable,\n} from './types';\n\n// ─── Route state ──────────────────────────────────────────────────────────────\n\n/** No defensive deep-copy
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import { error as logError } from './_dev';\nimport { WayfinderApiError } from './errors';\nimport type {\n Middleware,\n NavigationStatus,\n ResolvedQueryParams,\n RouteBranchDef,\n RouteContext,\n RouteLocation,\n RouteMatch,\n RouteMatchBranch,\n RouteParams,\n RouterErrorContext,\n RouteState,\n RouteTable,\n} from './types';\n\n// ─── Route state ──────────────────────────────────────────────────────────────\n\n/** No defensive deep-copy: RouteState is typed readonly; callers always pass fresh objects. */\nexport function createRouteState(input: {\n error?: unknown;\n location: RouteLocation;\n matches: RouteMatchBranch;\n status: NavigationStatus;\n}): RouteState {\n return {\n error: input.error,\n location: input.location,\n matches: input.matches,\n status: input.status,\n };\n}\n\n/**\n * Build a RouteMatchBranch from compiled defs and data results.\n */\nexport function buildMatchBranch(\n branchDefs: readonly RouteBranchDef[],\n params: RouteParams,\n pathname: string,\n dataResults: unknown[],\n): RouteMatchBranch {\n return branchDefs.map(\n (def, i): RouteMatch => ({\n data: dataResults[i],\n name: def.name,\n params: { ...params },\n pathname,\n }),\n );\n}\n\n// ─── Context factory ──────────────────────────────────────────────────────────\n\nexport function createRouteContext<TRoutes extends RouteTable>(\n location: RouteLocation,\n resolvedQuery: ResolvedQueryParams,\n params: RouteParams,\n matches: RouteMatchBranch,\n navigate: RouteContext<RouteParams, TRoutes>['navigate'],\n): RouteContext<RouteParams, TRoutes> {\n return {\n hash: location.hash,\n historyState: location.historyState,\n locals: {},\n matches,\n navigate,\n params,\n pathname: location.pathname,\n query: resolvedQuery,\n };\n}\n\n// ─── Middleware pipeline ──────────────────────────────────────────────────────\n\nexport async function executeMiddlewarePipeline<TRoutes extends RouteTable>(\n context: RouteContext<RouteParams, TRoutes>,\n middleware: readonly Middleware<TRoutes>[],\n terminal: () => Promise<void>,\n wrapMiddlewareError?: (error: unknown) => unknown,\n): Promise<boolean> {\n let terminalRan = false;\n\n async function dispatch(index: number): Promise<void> {\n if (index < middleware.length) {\n let called = false;\n\n try {\n await middleware[index]?.(context, async () => {\n if (called) throw new WayfinderApiError('next() called multiple times');\n\n called = true;\n await dispatch(index + 1);\n });\n } catch (error) {\n throw wrapMiddlewareError?.(error) ?? error;\n }\n\n return;\n }\n\n terminalRan = true;\n await terminal();\n }\n\n await dispatch(0);\n\n return terminalRan;\n}\n\n// ─── Error reporting ──────────────────────────────────────────────────────────\n\nexport function reportError(\n error: unknown,\n context: RouterErrorContext,\n onError?: (e: unknown, ctx: RouterErrorContext) => void,\n): void {\n if (onError) {\n onError(error, context);\n\n return;\n }\n\n logError('Unhandled router error. Provide an onError callback to handle errors explicitly:', error);\n}\n"],"mappings":"kEAoBA,SAAgB,iBAAiB,EAKlB,CACb,MAAO,CACL,MAAO,EAAM,MACb,SAAU,EAAM,SAChB,QAAS,EAAM,QACf,OAAQ,EAAM,MAChB,CACF,CAKA,SAAgB,iBACd,EACA,EACA,EACA,EACkB,CAClB,OAAO,EAAW,KACf,EAAK,KAAmB,CACvB,KAAM,EAAY,GAClB,KAAM,EAAI,KACV,OAAQ,CAAE,GAAG,CAAO,EACpB,UACF,EACF,CACF,CAIA,SAAgB,mBACd,EACA,EACA,EACA,EACA,EACoC,CACpC,MAAO,CACL,KAAM,EAAS,KACf,aAAc,EAAS,aACvB,OAAQ,CAAC,EACT,UACA,WACA,SACA,SAAU,EAAS,SACnB,MAAO,CACT,CACF,CAIA,eAAsB,0BACpB,EACA,EACA,EACA,EACkB,CAClB,IAAI,EAAc,GAElB,eAAe,SAAS,EAA8B,CACpD,GAAI,EAAQ,EAAW,OAAQ,CAC7B,IAAI,EAAS,GAEb,GAAI,CACF,MAAM,EAAW,EAAM,GAAG,EAAS,SAAY,CAC7C,GAAI,EAAQ,MAAM,IAAI,EAAkB,8BAA8B,EAEtE,EAAS,GACT,MAAM,SAAS,EAAQ,CAAC,CAC1B,CAAC,CACH,OAAS,EAAO,CACd,MAAM,IAAsB,CAAK,GAAK,CACxC,CAEA,MACF,CAEA,EAAc,GACd,MAAM,EAAS,CACjB,CAIA,OAFA,MAAM,SAAS,CAAC,EAET,CACT,CAIA,SAAgB,YACd,EACA,EACA,EACM,CACN,GAAI,EAAS,CACX,EAAQ,EAAO,CAAO,EAEtB,MACF,CAGF"}
|
package/dist/errors.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var WayfinderError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},WayfinderDisposedError=class extends WayfinderError{constructor(){super(`Router is disposed`)}},WayfinderConfigError=class extends WayfinderError{},WayfinderRouteError=class extends WayfinderError{},WayfinderRedirectLoopError=class extends WayfinderError{constructor(){super(`Redirect loop detected`)}},WayfinderApiError=class extends WayfinderError{};exports.WayfinderApiError=WayfinderApiError,exports.WayfinderConfigError=WayfinderConfigError,exports.WayfinderDisposedError=WayfinderDisposedError,exports.WayfinderError=WayfinderError,exports.WayfinderRedirectLoopError=WayfinderRedirectLoopError,exports.WayfinderRouteError=WayfinderRouteError;
|
|
2
2
|
//# sourceMappingURL=errors.cjs.map
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all wayfinder errors. Use `instanceof WayfinderError` to catch any router-originated error. */\nexport class WayfinderError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when any router method is called after the router has been disposed. */\nexport class WayfinderDisposedError extends WayfinderError {\n constructor() {\n super('Router is disposed');\n }\n}\n\n/** Thrown when a route or path definition is malformed. */\nexport class WayfinderRouteError extends WayfinderError {}\n\n/** Thrown when the router detects an infinite redirect loop. */\nexport class WayfinderRedirectLoopError extends WayfinderError {\n constructor() {\n super('Redirect loop detected');\n }\n}\n\n/** Thrown on API misuse (e.g. calling next() multiple times). */\nexport class WayfinderApiError extends WayfinderError {}\n"],"mappings":"AACA,IAAa,
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all wayfinder errors. Use `instanceof WayfinderError` to catch any router-originated error. */\nexport class WayfinderError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when any router method is called after the router has been disposed. */\nexport class WayfinderDisposedError extends WayfinderError {\n constructor() {\n super('Router is disposed');\n }\n}\n\n/** Thrown when a route or path definition is malformed at `createRouter()` time. */\nexport class WayfinderConfigError extends WayfinderError {}\n\n/** Thrown when a route or path is malformed at navigation time (unknown name, missing param). */\nexport class WayfinderRouteError extends WayfinderError {}\n\n/** Thrown when the router detects an infinite redirect loop. */\nexport class WayfinderRedirectLoopError extends WayfinderError {\n constructor() {\n super('Redirect loop detected');\n }\n}\n\n/** Thrown on API misuse (e.g. calling next() multiple times). */\nexport class WayfinderApiError extends WayfinderError {}\n"],"mappings":"AACA,IAAa,eAAb,cAAoC,KAAM,CACxC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,uBAAb,cAA4C,cAAe,CACzD,aAAc,CACZ,MAAM,oBAAoB,CAC5B,CACF,EAGa,qBAAb,cAA0C,cAAe,CAAC,EAG7C,oBAAb,cAAyC,cAAe,CAAC,EAG5C,2BAAb,cAAgD,cAAe,CAC7D,aAAc,CACZ,MAAM,wBAAwB,CAChC,CACF,EAGa,kBAAb,cAAuC,cAAe,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -6,7 +6,10 @@ export declare class WayfinderError extends Error {
|
|
|
6
6
|
export declare class WayfinderDisposedError extends WayfinderError {
|
|
7
7
|
constructor();
|
|
8
8
|
}
|
|
9
|
-
/** Thrown when a route or path definition is malformed. */
|
|
9
|
+
/** Thrown when a route or path definition is malformed at `createRouter()` time. */
|
|
10
|
+
export declare class WayfinderConfigError extends WayfinderError {
|
|
11
|
+
}
|
|
12
|
+
/** Thrown when a route or path is malformed at navigation time (unknown name, missing param). */
|
|
10
13
|
export declare class WayfinderRouteError extends WayfinderError {
|
|
11
14
|
}
|
|
12
15
|
/** Thrown when the router detects an infinite redirect loop. */
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,kFAAkF;AAClF,qBAAa,sBAAuB,SAAQ,cAAc;;CAIzD;AAED,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,kFAAkF;AAClF,qBAAa,sBAAuB,SAAQ,cAAc;;CAIzD;AAED,oFAAoF;AACpF,qBAAa,oBAAqB,SAAQ,cAAc;CAAG;AAE3D,iGAAiG;AACjG,qBAAa,mBAAoB,SAAQ,cAAc;CAAG;AAE1D,gEAAgE;AAChE,qBAAa,0BAA2B,SAAQ,cAAc;;CAI7D;AAED,iEAAiE;AACjE,qBAAa,iBAAkB,SAAQ,cAAc;CAAG"}
|
package/dist/errors.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var e = class extends Error {
|
|
3
|
-
constructor(e, t) {
|
|
4
|
-
super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
|
|
5
|
-
}
|
|
6
|
-
}, t = class extends e {
|
|
7
|
-
constructor() {
|
|
8
|
-
super("Router is disposed");
|
|
9
|
-
}
|
|
10
|
-
}, n = class extends e {}, r = class extends e {
|
|
11
|
-
constructor() {
|
|
12
|
-
super("Redirect loop detected");
|
|
13
|
-
}
|
|
14
|
-
}, i = class extends e {};
|
|
15
|
-
//#endregion
|
|
16
|
-
export { i as WayfinderApiError, t as WayfinderDisposedError, e as WayfinderError, r as WayfinderRedirectLoopError, n as WayfinderRouteError };
|
|
17
|
-
|
|
1
|
+
var WayfinderError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},WayfinderDisposedError=class extends WayfinderError{constructor(){super(`Router is disposed`)}},WayfinderConfigError=class extends WayfinderError{},WayfinderRouteError=class extends WayfinderError{},WayfinderRedirectLoopError=class extends WayfinderError{constructor(){super(`Redirect loop detected`)}},WayfinderApiError=class extends WayfinderError{};export{WayfinderApiError,WayfinderConfigError,WayfinderDisposedError,WayfinderError,WayfinderRedirectLoopError,WayfinderRouteError};
|
|
18
2
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all wayfinder errors. Use `instanceof WayfinderError` to catch any router-originated error. */\nexport class WayfinderError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when any router method is called after the router has been disposed. */\nexport class WayfinderDisposedError extends WayfinderError {\n constructor() {\n super('Router is disposed');\n }\n}\n\n/** Thrown when a route or path definition is malformed. */\nexport class WayfinderRouteError extends WayfinderError {}\n\n/** Thrown when the router detects an infinite redirect loop. */\nexport class WayfinderRedirectLoopError extends WayfinderError {\n constructor() {\n super('Redirect loop detected');\n }\n}\n\n/** Thrown on API misuse (e.g. calling next() multiple times). */\nexport class WayfinderApiError extends WayfinderError {}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all wayfinder errors. Use `instanceof WayfinderError` to catch any router-originated error. */\nexport class WayfinderError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when any router method is called after the router has been disposed. */\nexport class WayfinderDisposedError extends WayfinderError {\n constructor() {\n super('Router is disposed');\n }\n}\n\n/** Thrown when a route or path definition is malformed at `createRouter()` time. */\nexport class WayfinderConfigError extends WayfinderError {}\n\n/** Thrown when a route or path is malformed at navigation time (unknown name, missing param). */\nexport class WayfinderRouteError extends WayfinderError {}\n\n/** Thrown when the router detects an infinite redirect loop. */\nexport class WayfinderRedirectLoopError extends WayfinderError {\n constructor() {\n super('Redirect loop detected');\n }\n}\n\n/** Thrown on API misuse (e.g. calling next() multiple times). */\nexport class WayfinderApiError extends WayfinderError {}\n"],"mappings":"AACA,IAAa,eAAb,cAAoC,KAAM,CACxC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,uBAAb,cAA4C,cAAe,CACzD,aAAc,CACZ,MAAM,oBAAoB,CAC5B,CACF,EAGa,qBAAb,cAA0C,cAAe,CAAC,EAG7C,oBAAb,cAAyC,cAAe,CAAC,EAG5C,2BAAb,cAAgD,cAAe,CAC7D,aAAc,CACZ,MAAM,wBAAwB,CAChC,CACF,EAGa,kBAAb,cAAuC,cAAe,CAAC"}
|
package/dist/guards.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
async function
|
|
1
|
+
async function runLeaveBlockers(e,t,n){let r=new Set(t),i=[...e];for(let{handler:e,routes:t}of i)if((t===void 0||t.some(e=>r.has(e)))&&!await e(n))return!1;return!0}exports.runLeaveBlockers=runLeaveBlockers;
|
|
2
2
|
//# sourceMappingURL=guards.cjs.map
|
package/dist/guards.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.cjs","names":[],"sources":["../src/guards.ts"],"sourcesContent":["import type { BeforeLeaveBlocker, NavigationDestination } from './types';\n\n/**\n * A registered leave guard. `routes` scopes the guard to navigations that depart from\n * any route whose name appears in the array (matched against any node in the active branch,\n * not just the leaf). When `routes` is omitted the guard fires on every navigation.\n */\nexport type RegisteredBlocker = {\n handler: BeforeLeaveBlocker;\n routes?: string[];\n};\n\n/**\n * Run all registered leave blockers in registration order.\n * Guards whose `routes` filter does not overlap the current active match names are skipped.\n * Returns `false` as soon as any blocker returns `false`; returns `true` if all pass.\n *\n * A snapshot of the blocker set is taken before iteration so that guards added or removed\n * during execution do not affect the current run.\n *\n * `destination` is passed to each blocker so guards can make context-aware decisions.\n */\nexport async function runLeaveBlockers(\n blockers: ReadonlySet<RegisteredBlocker>,\n activeMatchNames: readonly string[],\n destination: NavigationDestination,\n): Promise<boolean> {\n const activeNames = new Set(activeMatchNames);\n // Snapshot so that removals during iteration don't skip entries.\n const snapshot = [...blockers];\n\n for (const { handler, routes } of snapshot) {\n if (routes !== undefined && !routes.some((name) => activeNames.has(name))) continue;\n\n const allowed = await handler(destination);\n\n if (!allowed) return false;\n }\n\n return true;\n}\n"],"mappings":"AAsBA,eAAsB,
|
|
1
|
+
{"version":3,"file":"guards.cjs","names":[],"sources":["../src/guards.ts"],"sourcesContent":["import type { BeforeLeaveBlocker, NavigationDestination } from './types';\n\n/**\n * A registered leave guard. `routes` scopes the guard to navigations that depart from\n * any route whose name appears in the array (matched against any node in the active branch,\n * not just the leaf). When `routes` is omitted the guard fires on every navigation.\n */\nexport type RegisteredBlocker = {\n handler: BeforeLeaveBlocker;\n routes?: string[];\n};\n\n/**\n * Run all registered leave blockers in registration order.\n * Guards whose `routes` filter does not overlap the current active match names are skipped.\n * Returns `false` as soon as any blocker returns `false`; returns `true` if all pass.\n *\n * A snapshot of the blocker set is taken before iteration so that guards added or removed\n * during execution do not affect the current run.\n *\n * `destination` is passed to each blocker so guards can make context-aware decisions.\n */\nexport async function runLeaveBlockers(\n blockers: ReadonlySet<RegisteredBlocker>,\n activeMatchNames: readonly string[],\n destination: NavigationDestination,\n): Promise<boolean> {\n const activeNames = new Set(activeMatchNames);\n // Snapshot so that removals during iteration don't skip entries.\n const snapshot = [...blockers];\n\n for (const { handler, routes } of snapshot) {\n if (routes !== undefined && !routes.some((name) => activeNames.has(name))) continue;\n\n const allowed = await handler(destination);\n\n if (!allowed) return false;\n }\n\n return true;\n}\n"],"mappings":"AAsBA,eAAsB,iBACpB,EACA,EACA,EACkB,CAClB,IAAM,EAAc,IAAI,IAAI,CAAgB,EAEtC,EAAW,CAAC,GAAG,CAAQ,EAE7B,IAAK,GAAM,CAAE,UAAS,YAAY,EAC5B,QAAW,IAAA,IAAc,EAAO,KAAM,GAAS,EAAY,IAAI,CAAI,CAAC,IAIpE,CAAC,MAFiB,EAAQ,CAAW,EAE3B,MAAO,GAGvB,MAAO,EACT"}
|
package/dist/guards.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
async function e(e, t, n) {
|
|
3
|
-
let r = new Set(t), i = [...e];
|
|
4
|
-
for (let { handler: e, routes: t } of i) if ((t === void 0 || t.some((e) => r.has(e))) && !await e(n)) return !1;
|
|
5
|
-
return !0;
|
|
6
|
-
}
|
|
7
|
-
//#endregion
|
|
8
|
-
export { e as runLeaveBlockers };
|
|
9
|
-
|
|
1
|
+
async function runLeaveBlockers(e,t,n){let r=new Set(t),i=[...e];for(let{handler:e,routes:t}of i)if((t===void 0||t.some(e=>r.has(e)))&&!await e(n))return!1;return!0}export{runLeaveBlockers};
|
|
10
2
|
//# sourceMappingURL=guards.js.map
|
package/dist/guards.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.js","names":[],"sources":["../src/guards.ts"],"sourcesContent":["import type { BeforeLeaveBlocker, NavigationDestination } from './types';\n\n/**\n * A registered leave guard. `routes` scopes the guard to navigations that depart from\n * any route whose name appears in the array (matched against any node in the active branch,\n * not just the leaf). When `routes` is omitted the guard fires on every navigation.\n */\nexport type RegisteredBlocker = {\n handler: BeforeLeaveBlocker;\n routes?: string[];\n};\n\n/**\n * Run all registered leave blockers in registration order.\n * Guards whose `routes` filter does not overlap the current active match names are skipped.\n * Returns `false` as soon as any blocker returns `false`; returns `true` if all pass.\n *\n * A snapshot of the blocker set is taken before iteration so that guards added or removed\n * during execution do not affect the current run.\n *\n * `destination` is passed to each blocker so guards can make context-aware decisions.\n */\nexport async function runLeaveBlockers(\n blockers: ReadonlySet<RegisteredBlocker>,\n activeMatchNames: readonly string[],\n destination: NavigationDestination,\n): Promise<boolean> {\n const activeNames = new Set(activeMatchNames);\n // Snapshot so that removals during iteration don't skip entries.\n const snapshot = [...blockers];\n\n for (const { handler, routes } of snapshot) {\n if (routes !== undefined && !routes.some((name) => activeNames.has(name))) continue;\n\n const allowed = await handler(destination);\n\n if (!allowed) return false;\n }\n\n return true;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"guards.js","names":[],"sources":["../src/guards.ts"],"sourcesContent":["import type { BeforeLeaveBlocker, NavigationDestination } from './types';\n\n/**\n * A registered leave guard. `routes` scopes the guard to navigations that depart from\n * any route whose name appears in the array (matched against any node in the active branch,\n * not just the leaf). When `routes` is omitted the guard fires on every navigation.\n */\nexport type RegisteredBlocker = {\n handler: BeforeLeaveBlocker;\n routes?: string[];\n};\n\n/**\n * Run all registered leave blockers in registration order.\n * Guards whose `routes` filter does not overlap the current active match names are skipped.\n * Returns `false` as soon as any blocker returns `false`; returns `true` if all pass.\n *\n * A snapshot of the blocker set is taken before iteration so that guards added or removed\n * during execution do not affect the current run.\n *\n * `destination` is passed to each blocker so guards can make context-aware decisions.\n */\nexport async function runLeaveBlockers(\n blockers: ReadonlySet<RegisteredBlocker>,\n activeMatchNames: readonly string[],\n destination: NavigationDestination,\n): Promise<boolean> {\n const activeNames = new Set(activeMatchNames);\n // Snapshot so that removals during iteration don't skip entries.\n const snapshot = [...blockers];\n\n for (const { handler, routes } of snapshot) {\n if (routes !== undefined && !routes.some((name) => activeNames.has(name))) continue;\n\n const allowed = await handler(destination);\n\n if (!allowed) return false;\n }\n\n return true;\n}\n"],"mappings":"AAsBA,eAAsB,iBACpB,EACA,EACA,EACkB,CAClB,IAAM,EAAc,IAAI,IAAI,CAAgB,EAEtC,EAAW,CAAC,GAAG,CAAQ,EAE7B,IAAK,GAAM,CAAE,UAAS,YAAY,EAC5B,QAAW,IAAA,IAAc,EAAO,KAAM,GAAS,EAAY,IAAI,CAAI,CAAC,IAIpE,CAAC,MAFiB,EAAQ,CAAW,EAE3B,MAAO,GAGvB,MAAO,EACT"}
|
package/dist/history.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./path.cjs");function
|
|
1
|
+
const e=require("./path.cjs");function createBrowserHistory(){return{back(){window.history.back()},get location(){return{hash:window.location.hash,pathname:window.location.pathname,search:window.location.search,state:window.history.state}},onPopstate(e){return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},push(e,t){window.history.pushState(t,``,e)},replace(e,t){window.history.replaceState(t,``,e)}}}function createHashHistory(t={}){let n=e.normalizePath(t.base??`/`),r=n===`/`?`/`:`${n}/`,location=()=>{let t=new URL(window.location.hash.slice(1)||`/`,`http://localhost`);return{hash:t.hash,pathname:e.joinPaths(n,t.pathname),search:t.search,state:window.history.state}},destination=t=>{let i=new URL(t,`http://localhost`),a=e.stripBase(i.pathname,n);return`${r}#${a}${i.search}${i.hash}`};return{back(){window.history.back()},href:destination,get location(){return location()},onPopstate(e){return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},push(e,t){window.history.pushState(t,``,destination(e))},replace(e,t){window.history.replaceState(t,``,destination(e))}}}function createHistoryForBase(e){return e===`/`?createBrowserHistory():createHashHistory({base:e})}function createMemoryHistory(e=`/`){let t=new URL(e,`http://localhost`),n=[{hash:t.hash,pathname:t.pathname,search:t.search,state:null}],r=0,i=new Set;return{back(){r<=0||(--r,i.forEach(e=>{e()}))},get location(){return n[r]},onPopstate(e){return i.add(e),()=>i.delete(e)},push(e,t=null){let i=new URL(e,`http://localhost`);n.splice(r+1),n.push({hash:i.hash,pathname:i.pathname,search:i.search,state:t}),r=n.length-1},replace(e,t=null){let i=new URL(e,`http://localhost`);n[r]={hash:i.hash,pathname:i.pathname,search:i.search,state:t}}}}exports.createBrowserHistory=createBrowserHistory,exports.createHashHistory=createHashHistory,exports.createHistoryForBase=createHistoryForBase,exports.createMemoryHistory=createMemoryHistory;
|
|
2
2
|
//# sourceMappingURL=history.cjs.map
|
package/dist/history.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.cjs","names":[],"sources":["../src/history.ts"],"sourcesContent":["import { joinPaths, normalizePath, stripBase } from './path';\nimport type { HistoryDriver } from './types';\n\n/** Creates a history driver backed by the browser History API. */\nexport function createBrowserHistory(): HistoryDriver {\n return {\n back() {\n window.history.back();\n },\n get location() {\n return {\n hash: window.location.hash,\n pathname: window.location.pathname,\n search: window.location.search,\n // State lives on window.history.state, not window.location.\n state: window.history.state,\n };\n },\n onPopstate(listener) {\n window.addEventListener('popstate', listener);\n\n return () => window.removeEventListener('popstate', listener);\n },\n push(url, state) {\n window.history.pushState(state, '', url);\n },\n replace(url, state) {\n window.history.replaceState(state, '', url);\n },\n };\n}\n\nexport type HashHistoryOptions = { base?: string };\n\nexport function createHashHistory(options: HashHistoryOptions = {}): HistoryDriver {\n const base = normalizePath(options.base ?? '/');\n const baseRoot = base === '/' ? '/' : `${base}/`;\n const location = () => {\n const parsed = new URL(window.location.hash.slice(1) || '/', 'http://localhost');\n\n return {\n hash: parsed.hash,\n pathname: joinPaths(base, parsed.pathname),\n search: parsed.search,\n state: window.history.state,\n };\n };\n const destination = (url: string) => {\n const parsed = new URL(url, 'http://localhost');\n const pathname = stripBase(parsed.pathname, base);\n\n return `${baseRoot}#${pathname}${parsed.search}${parsed.hash}`;\n };\n\n return {\n back() {\n window.history.back();\n },\n get location() {\n return location();\n },\n onPopstate(listener) {\n window.addEventListener('popstate', listener);\n\n return () => window.removeEventListener('popstate', listener);\n },\n push(url, state) {\n window.history.pushState(state, '', destination(url));\n },\n replace(url, state) {\n window.history.replaceState(state, '', destination(url));\n },\n };\n}\n\ntype MemoryLocation = { hash: string; pathname: string; search: string; state: unknown };\n\n/**\n * Creates an in-memory history driver. Suitable for SSR, tests, and non-browser environments.\n *\n * Semantics mirror the browser History API:\n * - `push()` and `replace()` update the location silently (no listener notification),\n * matching `pushState`/`replaceState` which do not fire `popstate`.\n * - `back()` moves one entry back and notifies subscribers, matching a browser back-button press.\n */\nexport function createMemoryHistory(initialPath = '/'): HistoryDriver {\n const parsed = new URL(initialPath, 'http://localhost');\n const stack: MemoryLocation[] = [\n { hash: parsed.hash, pathname: parsed.pathname, search: parsed.search, state: null },\n ];\n let cursor = 0;\n const listeners = new Set<() => void>();\n\n return {\n back() {\n if (cursor <= 0) return;\n\n cursor -= 1;\n listeners.forEach((l) => {\n l();\n });\n },\n get location(): MemoryLocation {\n return stack[cursor]!;\n },\n onPopstate(listener) {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n },\n push(url, state = null) {\n const p = new URL(url, 'http://localhost');\n\n stack.splice(cursor + 1);\n stack.push({ hash: p.hash, pathname: p.pathname, search: p.search, state });\n cursor = stack.length - 1;\n // Silent
|
|
1
|
+
{"version":3,"file":"history.cjs","names":[],"sources":["../src/history.ts"],"sourcesContent":["import { joinPaths, normalizePath, stripBase } from './path';\nimport type { HistoryDriver } from './types';\n\n/** Creates a history driver backed by the browser History API. */\nexport function createBrowserHistory(): HistoryDriver {\n return {\n back() {\n window.history.back();\n },\n get location() {\n return {\n hash: window.location.hash,\n pathname: window.location.pathname,\n search: window.location.search,\n // State lives on window.history.state, not window.location.\n state: window.history.state,\n };\n },\n onPopstate(listener) {\n window.addEventListener('popstate', listener);\n\n return () => window.removeEventListener('popstate', listener);\n },\n push(url, state) {\n window.history.pushState(state, '', url);\n },\n replace(url, state) {\n window.history.replaceState(state, '', url);\n },\n };\n}\n\nexport type HashHistoryOptions = { base?: string };\n\nexport function createHashHistory(options: HashHistoryOptions = {}): HistoryDriver {\n const base = normalizePath(options.base ?? '/');\n const baseRoot = base === '/' ? '/' : `${base}/`;\n const location = () => {\n const parsed = new URL(window.location.hash.slice(1) || '/', 'http://localhost');\n\n return {\n hash: parsed.hash,\n pathname: joinPaths(base, parsed.pathname),\n search: parsed.search,\n state: window.history.state,\n };\n };\n const destination = (url: string) => {\n const parsed = new URL(url, 'http://localhost');\n const pathname = stripBase(parsed.pathname, base);\n\n return `${baseRoot}#${pathname}${parsed.search}${parsed.hash}`;\n };\n\n return {\n back() {\n window.history.back();\n },\n /** Anchor-ready form of an internal URL: the hash driver stores routes behind `#`. */\n href: destination,\n get location() {\n return location();\n },\n onPopstate(listener) {\n window.addEventListener('popstate', listener);\n\n return () => window.removeEventListener('popstate', listener);\n },\n push(url, state) {\n window.history.pushState(state, '', destination(url));\n },\n replace(url, state) {\n window.history.replaceState(state, '', destination(url));\n },\n };\n}\n\n/**\n * Picks the history driver for a deployment base path: a site at the origin root\n * (`'/'`) gets real History-API paths; an app deployed under a sub-path\n * (`import.meta.env.BASE_URL` like `'/demos/voyage/'`) gets the hash driver, so\n * deep links survive a static host that cannot rewrite the base path to the app.\n */\nexport function createHistoryForBase(base: string): HistoryDriver {\n return base === '/' ? createBrowserHistory() : createHashHistory({ base });\n}\n\ntype MemoryLocation = { hash: string; pathname: string; search: string; state: unknown };\n\n/**\n * Creates an in-memory history driver. Suitable for SSR, tests, and non-browser environments.\n *\n * Semantics mirror the browser History API:\n * - `push()` and `replace()` update the location silently (no listener notification),\n * matching `pushState`/`replaceState` which do not fire `popstate`.\n * - `back()` moves one entry back and notifies subscribers, matching a browser back-button press.\n */\nexport function createMemoryHistory(initialPath = '/'): HistoryDriver {\n const parsed = new URL(initialPath, 'http://localhost');\n const stack: MemoryLocation[] = [\n { hash: parsed.hash, pathname: parsed.pathname, search: parsed.search, state: null },\n ];\n let cursor = 0;\n const listeners = new Set<() => void>();\n\n return {\n back() {\n if (cursor <= 0) return;\n\n cursor -= 1;\n listeners.forEach((l) => {\n l();\n });\n },\n get location(): MemoryLocation {\n return stack[cursor]!;\n },\n onPopstate(listener) {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n },\n push(url, state = null) {\n const p = new URL(url, 'http://localhost');\n\n stack.splice(cursor + 1);\n stack.push({ hash: p.hash, pathname: p.pathname, search: p.search, state });\n cursor = stack.length - 1;\n // Silent: mirrors browser pushState semantics. Router drives navigation via #handleRoute directly.\n },\n replace(url, state = null) {\n const p = new URL(url, 'http://localhost');\n\n stack[cursor] = { hash: p.hash, pathname: p.pathname, search: p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
|
7
7
|
export declare function createHashHistory(options?: HashHistoryOptions): HistoryDriver;
|
|
8
|
+
/**
|
|
9
|
+
* Picks the history driver for a deployment base path: a site at the origin root
|
|
10
|
+
* (`'/'`) gets real History-API paths; an app deployed under a sub-path
|
|
11
|
+
* (`import.meta.env.BASE_URL` like `'/demos/voyage/'`) gets the hash driver, so
|
|
12
|
+
* deep links survive a static host that cannot rewrite the base path to the app.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createHistoryForBase(base: string): HistoryDriver;
|
|
8
15
|
/**
|
|
9
16
|
* Creates an in-memory history driver. Suitable for SSR, tests, and non-browser environments.
|
|
10
17
|
*
|
package/dist/history.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,kEAAkE;AAClE,wBAAgB,oBAAoB,IAAI,aAAa,CA0BpD;AAED,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,kBAAuB,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,kEAAkE;AAClE,wBAAgB,oBAAoB,IAAI,aAAa,CA0BpD;AAED,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,kBAAuB,GAAG,aAAa,CAyCjF;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAEhE;AAID;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,SAAM,GAAG,aAAa,CAwCpE"}
|