@vielzeug/wayfinder 1.0.4 → 1.0.5

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/dist/_dev.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=!globalThis.__WAYFINDER_PROD__;function t(t){e&&console.warn(`[@vielzeug/wayfinder] ${t}`)}function n(t,...n){e&&console.error(`[@vielzeug/wayfinder] ${t}`,...n)}exports.error=n,exports.warn=t;
1
+ function e(e){}function t(e,...t){}exports.error=t,exports.warn=e;
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\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AAAA,IAAM,EAAQ,CAAE,WAAgD,mBAGhE,SAAgB,EAAK,EAAmB,CAClC,GAAO,QAAQ,KAAK,yBAAyB,GAAK,CACxD,CAGA,SAAgB,EAAM,EAAa,GAAG,EAAuB,CACvD,GAAO,QAAQ,MAAM,yBAAyB,IAAO,GAAG,CAAI,CAClE"}
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\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AAGA,SAAgB,EAAK,EAAmB,CAExC,CAGA,SAAgB,EAAM,EAAa,GAAG,EAAuB,CAE7D"}
package/dist/_dev.js CHANGED
@@ -1,12 +1,7 @@
1
1
  //#region src/_dev.ts
2
- var e = !globalThis.__WAYFINDER_PROD__;
3
- function t(t) {
4
- e && console.warn(`[@vielzeug/wayfinder] ${t}`);
5
- }
6
- function n(t, ...n) {
7
- e && console.error(`[@vielzeug/wayfinder] ${t}`, ...n);
8
- }
2
+ function e(e) {}
3
+ function t(e, ...t) {}
9
4
  //#endregion
10
- export { n as error, t as warn };
5
+ export { t as error, e as warn };
11
6
 
12
7
  //# sourceMappingURL=_dev.js.map
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\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":";AAAA,IAAM,IAAQ,CAAE,WAAgD;AAGhE,SAAgB,EAAK,GAAmB;CACtC,AAAI,KAAO,QAAQ,KAAK,yBAAyB,GAAK;AACxD;AAGA,SAAgB,EAAM,GAAa,GAAG,GAAuB;CAC3D,AAAI,KAAO,QAAQ,MAAM,yBAAyB,KAAO,GAAG,CAAI;AAClE"}
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\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":";AAGA,SAAgB,EAAK,GAAmB,CAExC;AAGA,SAAgB,EAAM,GAAa,GAAG,GAAuB,CAE7D"}
package/dist/compile.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./_dev.cjs"),t=require("./errors.cjs"),n=require("./path.cjs");function r(r){let i=[],a=(e,r,o,s,c)=>{if(r.index&&r.path!==void 0)throw new t.WayfinderRouteError(`Route "${e}" cannot define both index and path`);if(!r.index&&r.path===void 0)throw new t.WayfinderRouteError(`Route "${e}" must define path or set index: true`);let l=r.index?o:n.normalizePath(r.path?n.joinPaths(o,r.path):o),u=[...s,{component:r.component,dataFn:r.data,lazy:r.lazy,meta:r.meta,name:e,onError:r.onError}],d=[...c,...r.middleware??[]];if(r.children)for(let[t,n]of Object.entries(r.children))a(`${e}.${t}`,n,l,u,d);if(r.lazy!==void 0||r.redirect!==void 0||!r.children||r.data!==void 0){let e=u[u.length-1];i.push({branchDefs:u,coerceSearch:r.coerceSearch,leaf:e,matcher:n.compilePathMatcher(l),ownMiddleware:d,path:l,redirect:r.redirect})}};for(let[e,t]of Object.entries(r.routes))a(e,t,`/`,[],[]);let o=new Set;for(let e of i){if(o.has(e.leaf.name))throw new t.WayfinderRouteError(`Duplicate route name: "${e.leaf.name}". A top-level route key must not coincide with a nested route's dot-notation name.`);o.add(e.leaf.name)}let s=!1;for(let t of i){let n=t.path===`/*`||t.path.endsWith(`/*`)||t.path.includes(`:`)&&t.path.endsWith(`*`);s&&!n&&e.warn(`Route "${t.leaf.name}" (${t.path}) is defined after a wildcard/catch-all route and will never match. Move specific routes before wildcards.`),n&&(s=!0)}return{records:i,routesByName:new Map(i.map(e=>[e.leaf.name,e]))}}exports.compileRoutes=r;
1
+ require("./_dev.cjs");const e=require("./errors.cjs"),t=require("./path.cjs");function n(n){let r=[],i=(n,a,o,s,c)=>{if(a.index&&a.path!==void 0)throw new e.WayfinderRouteError(`Route "${n}" cannot define both index and path`);if(!a.index&&a.path===void 0)throw new e.WayfinderRouteError(`Route "${n}" must define path or set index: true`);let l=a.index?o:t.normalizePath(a.path?t.joinPaths(o,a.path):o),u=[...s,{component:a.component,dataFn:a.data,lazy:a.lazy,meta:a.meta,name:n,onError:a.onError}],d=[...c,...a.middleware??[]];if(a.children)for(let[e,t]of Object.entries(a.children))i(`${n}.${e}`,t,l,u,d);if(a.lazy!==void 0||a.redirect!==void 0||!a.children||a.data!==void 0){let e=u[u.length-1];r.push({branchDefs:u,coerceSearch:a.coerceSearch,leaf:e,matcher:t.compilePathMatcher(l),ownMiddleware:d,path:l,redirect:a.redirect})}};for(let[e,t]of Object.entries(n.routes))i(e,t,`/`,[],[]);let a=new Set;for(let t of r){if(a.has(t.leaf.name))throw new e.WayfinderRouteError(`Duplicate route name: "${t.leaf.name}". A top-level route key must not coincide with a nested route's dot-notation name.`);a.add(t.leaf.name)}let o=!1;for(let e of r){let t=e.path===`/*`||e.path.endsWith(`/*`)||e.path.includes(`:`)&&e.path.endsWith(`*`);o&&!t&&`${e.leaf.name}${e.path}`,t&&(o=!0)}return{records:r,routesByName:new Map(r.map(e=>[e.leaf.name,e]))}}exports.compileRoutes=n;
2
2
  //# sourceMappingURL=compile.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.cjs","names":[],"sources":["../src/compile.ts"],"sourcesContent":["import type { Middleware, RouteBranchDef, RouteDefinition, RouteRecord, RouterOptions, RouteTable } from './types';\n\nimport { warn } from './_dev';\nimport { WayfinderRouteError } from './errors';\nimport { compilePathMatcher, joinPaths, normalizePath } from './path';\n\nexport type CompiledRoutes<TMeta = unknown, TComponent = unknown> = {\n records: readonly RouteRecord<TMeta, TComponent>[];\n routesByName: ReadonlyMap<string, RouteRecord<TMeta, TComponent>>;\n};\n\nexport function compileRoutes<TRoutes extends RouteTable, TMeta, TComponent>(\n options: RouterOptions<TRoutes, TMeta, TComponent>,\n): CompiledRoutes<TMeta, TComponent> {\n const records: RouteRecord<TMeta, TComponent>[] = [];\n\n const compile = (\n name: string,\n route: RouteDefinition,\n ancestorPath: string,\n ancestorBranchDefs: RouteBranchDef<TMeta, TComponent>[],\n ancestorMiddleware: RouteRecord<TMeta, TComponent>['ownMiddleware'],\n ): void => {\n if (route.index && route.path !== undefined) {\n throw new WayfinderRouteError(`Route \"${name}\" cannot define both index and path`);\n }\n\n if (!route.index && route.path === undefined) {\n throw new WayfinderRouteError(`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<TMeta, TComponent>[] = [\n ...ancestorBranchDefs,\n {\n component: route.component as TComponent | undefined,\n dataFn: route.data,\n lazy: route.lazy as RouteBranchDef<TMeta, TComponent>['lazy'],\n meta: route.meta as TMeta | undefined,\n name,\n onError: route.onError as RouteBranchDef<TMeta, TComponent>['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 // R9: emit a record for leaf routes (no children), redirects, lazy routes, and routes with data.\n // A bare parent-only route (children but no data/lazy/redirect) is not emitted as a leaf.\n if (route.lazy !== undefined || 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 WayfinderRouteError(\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":"gFAWA,SAAgB,EACd,EACmC,CACnC,IAAM,EAA4C,CAAC,EAE7C,GACJ,EACA,EACA,EACA,EACA,IACS,CACT,GAAI,EAAM,OAAS,EAAM,OAAS,IAAA,GAChC,MAAM,IAAI,EAAA,oBAAoB,UAAU,EAAK,oCAAoC,EAGnF,GAAI,CAAC,EAAM,OAAS,EAAM,OAAS,IAAA,GACjC,MAAM,IAAI,EAAA,oBAAoB,UAAU,EAAK,sCAAsC,EAGrF,IAAM,EAAU,EAAM,MAClB,EACA,EAAA,cAAc,EAAM,KAAO,EAAA,UAAU,EAAc,EAAM,IAAI,EAAI,CAAY,EAE3E,EAAkD,CACtD,GAAG,EACH,CACE,UAAW,EAAM,UACjB,OAAQ,EAAM,KACd,KAAM,EAAM,KACZ,KAAM,EAAM,KACZ,OACA,QAAS,EAAM,OACjB,CACF,EAEM,EAA8B,CAClC,GAAG,EACH,GAAK,EAAM,YAAc,CAAC,CAC5B,EAEA,GAAI,EAAM,SACR,IAAK,GAAM,CAAC,EAAW,KAAe,OAAO,QAAQ,EAAM,QAAQ,EACjE,EAAQ,GAAG,EAAK,GAAG,IAAa,EAAY,EAAS,EAAY,CAAa,EAMlF,GAAI,EAAM,OAAS,IAAA,IAAa,EAAM,WAAa,IAAA,IAAa,CAAC,EAAM,UAAY,EAAM,OAAS,IAAA,GAAW,CAC3G,IAAM,EAAO,EAAW,EAAW,OAAS,GAE5C,EAAQ,KAAK,CACX,aACA,aAAc,EAAM,aACpB,OACA,QAAS,EAAA,mBAAmB,CAAO,EACnC,gBACA,KAAM,EACN,SAAU,EAAM,QAClB,CAAC,CACH,CACF,EAEA,IAAK,GAAM,CAAC,EAAM,KAAU,OAAO,QAAQ,EAAQ,MAAM,EACvD,EAAQ,EAAM,EAAO,IAAK,CAAC,EAAG,CAAC,CAAC,EAIlC,IAAM,EAAY,IAAI,IAEtB,IAAK,IAAM,KAAU,EAAS,CAC5B,GAAI,EAAU,IAAI,EAAO,KAAK,IAAI,EAChC,MAAM,IAAI,EAAA,oBACR,0BAA0B,EAAO,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,GACnB,EAAA,KACE,UAAU,EAAO,KAAK,KAAK,KAAK,EAAO,KAAK,2GAC9C,EAGE,IAAY,EAAe,GACjC,CAEA,MAAO,CACL,UACA,aAAc,IAAI,IAAI,EAAQ,IAAK,GAAM,CAAC,EAAE,KAAK,KAAM,CAAC,CAAC,CAAC,CAC5D,CACF"}
1
+ {"version":3,"file":"compile.cjs","names":[],"sources":["../src/compile.ts"],"sourcesContent":["import type { Middleware, RouteBranchDef, RouteDefinition, RouteRecord, RouterOptions, RouteTable } from './types';\n\nimport { warn } from './_dev';\nimport { WayfinderRouteError } from './errors';\nimport { compilePathMatcher, joinPaths, normalizePath } from './path';\n\nexport type CompiledRoutes<TMeta = unknown, TComponent = unknown> = {\n records: readonly RouteRecord<TMeta, TComponent>[];\n routesByName: ReadonlyMap<string, RouteRecord<TMeta, TComponent>>;\n};\n\nexport function compileRoutes<TRoutes extends RouteTable, TMeta, TComponent>(\n options: RouterOptions<TRoutes, TMeta, TComponent>,\n): CompiledRoutes<TMeta, TComponent> {\n const records: RouteRecord<TMeta, TComponent>[] = [];\n\n const compile = (\n name: string,\n route: RouteDefinition,\n ancestorPath: string,\n ancestorBranchDefs: RouteBranchDef<TMeta, TComponent>[],\n ancestorMiddleware: RouteRecord<TMeta, TComponent>['ownMiddleware'],\n ): void => {\n if (route.index && route.path !== undefined) {\n throw new WayfinderRouteError(`Route \"${name}\" cannot define both index and path`);\n }\n\n if (!route.index && route.path === undefined) {\n throw new WayfinderRouteError(`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<TMeta, TComponent>[] = [\n ...ancestorBranchDefs,\n {\n component: route.component as TComponent | undefined,\n dataFn: route.data,\n lazy: route.lazy as RouteBranchDef<TMeta, TComponent>['lazy'],\n meta: route.meta as TMeta | undefined,\n name,\n onError: route.onError as RouteBranchDef<TMeta, TComponent>['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 // R9: emit a record for leaf routes (no children), redirects, lazy routes, and routes with data.\n // A bare parent-only route (children but no data/lazy/redirect) is not emitted as a leaf.\n if (route.lazy !== undefined || 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 WayfinderRouteError(\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":"8EAWA,SAAgB,EACd,EACmC,CACnC,IAAM,EAA4C,CAAC,EAE7C,GACJ,EACA,EACA,EACA,EACA,IACS,CACT,GAAI,EAAM,OAAS,EAAM,OAAS,IAAA,GAChC,MAAM,IAAI,EAAA,oBAAoB,UAAU,EAAK,oCAAoC,EAGnF,GAAI,CAAC,EAAM,OAAS,EAAM,OAAS,IAAA,GACjC,MAAM,IAAI,EAAA,oBAAoB,UAAU,EAAK,sCAAsC,EAGrF,IAAM,EAAU,EAAM,MAClB,EACA,EAAA,cAAc,EAAM,KAAO,EAAA,UAAU,EAAc,EAAM,IAAI,EAAI,CAAY,EAE3E,EAAkD,CACtD,GAAG,EACH,CACE,UAAW,EAAM,UACjB,OAAQ,EAAM,KACd,KAAM,EAAM,KACZ,KAAM,EAAM,KACZ,OACA,QAAS,EAAM,OACjB,CACF,EAEM,EAA8B,CAClC,GAAG,EACH,GAAK,EAAM,YAAc,CAAC,CAC5B,EAEA,GAAI,EAAM,SACR,IAAK,GAAM,CAAC,EAAW,KAAe,OAAO,QAAQ,EAAM,QAAQ,EACjE,EAAQ,GAAG,EAAK,GAAG,IAAa,EAAY,EAAS,EAAY,CAAa,EAMlF,GAAI,EAAM,OAAS,IAAA,IAAa,EAAM,WAAa,IAAA,IAAa,CAAC,EAAM,UAAY,EAAM,OAAS,IAAA,GAAW,CAC3G,IAAM,EAAO,EAAW,EAAW,OAAS,GAE5C,EAAQ,KAAK,CACX,aACA,aAAc,EAAM,aACpB,OACA,QAAS,EAAA,mBAAmB,CAAO,EACnC,gBACA,KAAM,EACN,SAAU,EAAM,QAClB,CAAC,CACH,CACF,EAEA,IAAK,GAAM,CAAC,EAAM,KAAU,OAAO,QAAQ,EAAQ,MAAM,EACvD,EAAQ,EAAM,EAAO,IAAK,CAAC,EAAG,CAAC,CAAC,EAIlC,IAAM,EAAY,IAAI,IAEtB,IAAK,IAAM,KAAU,EAAS,CAC5B,GAAI,EAAU,IAAI,EAAO,KAAK,IAAI,EAChC,MAAM,IAAI,EAAA,oBACR,0BAA0B,EAAO,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,50 +1,50 @@
1
- import { warn as e } from "./_dev.js";
2
- import { WayfinderRouteError as t } from "./errors.js";
3
- import { compilePathMatcher as n, joinPaths as r, normalizePath as i } from "./path.js";
1
+ import "./_dev.js";
2
+ import { WayfinderRouteError as e } from "./errors.js";
3
+ import { compilePathMatcher as t, joinPaths as n, normalizePath as r } from "./path.js";
4
4
  //#region src/compile.ts
5
- function a(a) {
6
- let o = [], s = (e, a, c, l, u) => {
7
- if (a.index && a.path !== void 0) throw new t(`Route "${e}" cannot define both index and path`);
8
- if (!a.index && a.path === void 0) throw new t(`Route "${e}" must define path or set index: true`);
9
- let d = a.index ? c : i(a.path ? r(c, a.path) : c), f = [...l, {
10
- component: a.component,
11
- dataFn: a.data,
12
- lazy: a.lazy,
13
- meta: a.meta,
14
- name: e,
15
- onError: a.onError
16
- }], p = [...u, ...a.middleware ?? []];
17
- if (a.children) for (let [t, n] of Object.entries(a.children)) s(`${e}.${t}`, n, d, f, p);
18
- if (a.lazy !== void 0 || a.redirect !== void 0 || !a.children || a.data !== void 0) {
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
+ component: s.component,
11
+ dataFn: s.data,
12
+ lazy: s.lazy,
13
+ meta: s.meta,
14
+ name: i,
15
+ onError: s.onError
16
+ }], p = [...u, ...s.middleware ?? []];
17
+ if (s.children) for (let [e, t] of Object.entries(s.children)) o(`${i}.${e}`, t, d, f, p);
18
+ if (s.lazy !== void 0 || s.redirect !== void 0 || !s.children || s.data !== void 0) {
19
19
  let e = f[f.length - 1];
20
- o.push({
20
+ a.push({
21
21
  branchDefs: f,
22
- coerceSearch: a.coerceSearch,
22
+ coerceSearch: s.coerceSearch,
23
23
  leaf: e,
24
- matcher: n(d),
24
+ matcher: t(d),
25
25
  ownMiddleware: p,
26
26
  path: d,
27
- redirect: a.redirect
27
+ redirect: s.redirect
28
28
  });
29
29
  }
30
30
  };
31
- for (let [e, t] of Object.entries(a.routes)) s(e, t, "/", [], []);
32
- let c = /* @__PURE__ */ new Set();
33
- for (let e of o) {
34
- if (c.has(e.leaf.name)) throw new t(`Duplicate route name: "${e.leaf.name}". A top-level route key must not coincide with a nested route's dot-notation name.`);
35
- c.add(e.leaf.name);
31
+ for (let [e, t] of Object.entries(i.routes)) o(e, t, "/", [], []);
32
+ let s = /* @__PURE__ */ new Set();
33
+ for (let t of a) {
34
+ 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.`);
35
+ s.add(t.leaf.name);
36
36
  }
37
- let l = !1;
38
- for (let t of o) {
39
- let n = t.path === "/*" || t.path.endsWith("/*") || t.path.includes(":") && t.path.endsWith("*");
40
- l && !n && e(`Route "${t.leaf.name}" (${t.path}) is defined after a wildcard/catch-all route and will never match. Move specific routes before wildcards.`), n && (l = !0);
37
+ let c = !1;
38
+ for (let e of a) {
39
+ let t = e.path === "/*" || e.path.endsWith("/*") || e.path.includes(":") && e.path.endsWith("*");
40
+ c && !t && `${e.leaf.name}${e.path}`, t && (c = !0);
41
41
  }
42
42
  return {
43
- records: o,
44
- routesByName: new Map(o.map((e) => [e.leaf.name, e]))
43
+ records: a,
44
+ routesByName: new Map(a.map((e) => [e.leaf.name, e]))
45
45
  };
46
46
  }
47
47
  //#endregion
48
- export { a as compileRoutes };
48
+ export { i as compileRoutes };
49
49
 
50
50
  //# sourceMappingURL=compile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.js","names":[],"sources":["../src/compile.ts"],"sourcesContent":["import type { Middleware, RouteBranchDef, RouteDefinition, RouteRecord, RouterOptions, RouteTable } from './types';\n\nimport { warn } from './_dev';\nimport { WayfinderRouteError } from './errors';\nimport { compilePathMatcher, joinPaths, normalizePath } from './path';\n\nexport type CompiledRoutes<TMeta = unknown, TComponent = unknown> = {\n records: readonly RouteRecord<TMeta, TComponent>[];\n routesByName: ReadonlyMap<string, RouteRecord<TMeta, TComponent>>;\n};\n\nexport function compileRoutes<TRoutes extends RouteTable, TMeta, TComponent>(\n options: RouterOptions<TRoutes, TMeta, TComponent>,\n): CompiledRoutes<TMeta, TComponent> {\n const records: RouteRecord<TMeta, TComponent>[] = [];\n\n const compile = (\n name: string,\n route: RouteDefinition,\n ancestorPath: string,\n ancestorBranchDefs: RouteBranchDef<TMeta, TComponent>[],\n ancestorMiddleware: RouteRecord<TMeta, TComponent>['ownMiddleware'],\n ): void => {\n if (route.index && route.path !== undefined) {\n throw new WayfinderRouteError(`Route \"${name}\" cannot define both index and path`);\n }\n\n if (!route.index && route.path === undefined) {\n throw new WayfinderRouteError(`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<TMeta, TComponent>[] = [\n ...ancestorBranchDefs,\n {\n component: route.component as TComponent | undefined,\n dataFn: route.data,\n lazy: route.lazy as RouteBranchDef<TMeta, TComponent>['lazy'],\n meta: route.meta as TMeta | undefined,\n name,\n onError: route.onError as RouteBranchDef<TMeta, TComponent>['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 // R9: emit a record for leaf routes (no children), redirects, lazy routes, and routes with data.\n // A bare parent-only route (children but no data/lazy/redirect) is not emitted as a leaf.\n if (route.lazy !== undefined || 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 WayfinderRouteError(\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":";;;;AAWA,SAAgB,EACd,GACmC;CACnC,IAAM,IAA4C,CAAC,GAE7C,KACJ,GACA,GACA,GACA,GACA,MACS;EACT,IAAI,EAAM,SAAS,EAAM,SAAS,KAAA,GAChC,MAAM,IAAI,EAAoB,UAAU,EAAK,oCAAoC;EAGnF,IAAI,CAAC,EAAM,SAAS,EAAM,SAAS,KAAA,GACjC,MAAM,IAAI,EAAoB,UAAU,EAAK,sCAAsC;EAGrF,IAAM,IAAU,EAAM,QAClB,IACA,EAAc,EAAM,OAAO,EAAU,GAAc,EAAM,IAAI,IAAI,CAAY,GAE3E,IAAkD,CACtD,GAAG,GACH;GACE,WAAW,EAAM;GACjB,QAAQ,EAAM;GACd,MAAM,EAAM;GACZ,MAAM,EAAM;GACZ;GACA,SAAS,EAAM;EACjB,CACF,GAEM,IAA8B,CAClC,GAAG,GACH,GAAK,EAAM,cAAc,CAAC,CAC5B;EAEA,IAAI,EAAM,UACR,KAAK,IAAM,CAAC,GAAW,MAAe,OAAO,QAAQ,EAAM,QAAQ,GACjE,EAAQ,GAAG,EAAK,GAAG,KAAa,GAAY,GAAS,GAAY,CAAa;EAMlF,IAAI,EAAM,SAAS,KAAA,KAAa,EAAM,aAAa,KAAA,KAAa,CAAC,EAAM,YAAY,EAAM,SAAS,KAAA,GAAW;GAC3G,IAAM,IAAO,EAAW,EAAW,SAAS;GAE5C,EAAQ,KAAK;IACX;IACA,cAAc,EAAM;IACpB;IACA,SAAS,EAAmB,CAAO;IACnC;IACA,MAAM;IACN,UAAU,EAAM;GAClB,CAAC;EACH;CACF;CAEA,KAAK,IAAM,CAAC,GAAM,MAAU,OAAO,QAAQ,EAAQ,MAAM,GACvD,EAAQ,GAAM,GAAO,KAAK,CAAC,GAAG,CAAC,CAAC;CAIlC,IAAM,oBAAY,IAAI,IAAY;CAElC,KAAK,IAAM,KAAU,GAAS;EAC5B,IAAI,EAAU,IAAI,EAAO,KAAK,IAAI,GAChC,MAAM,IAAI,EACR,0BAA0B,EAAO,KAAK,KAAK,oFAC7C;EAGF,EAAU,IAAI,EAAO,KAAK,IAAI;CAChC;CAIA,IAAI,IAAe;CAEnB,KAAK,IAAM,KAAU,GAAS;EAC5B,IAAM,IACJ,EAAO,SAAS,QAAQ,EAAO,KAAK,SAAS,IAAI,KAAM,EAAO,KAAK,SAAS,GAAG,KAAK,EAAO,KAAK,SAAS,GAAG;EAQ9G,AANI,KAAgB,CAAC,KACnB,EACE,UAAU,EAAO,KAAK,KAAK,KAAK,EAAO,KAAK,2GAC9C,GAGE,MAAY,IAAe;CACjC;CAEA,OAAO;EACL;EACA,cAAc,IAAI,IAAI,EAAQ,KAAK,MAAM,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC;CAC5D;AACF"}
1
+ {"version":3,"file":"compile.js","names":[],"sources":["../src/compile.ts"],"sourcesContent":["import type { Middleware, RouteBranchDef, RouteDefinition, RouteRecord, RouterOptions, RouteTable } from './types';\n\nimport { warn } from './_dev';\nimport { WayfinderRouteError } from './errors';\nimport { compilePathMatcher, joinPaths, normalizePath } from './path';\n\nexport type CompiledRoutes<TMeta = unknown, TComponent = unknown> = {\n records: readonly RouteRecord<TMeta, TComponent>[];\n routesByName: ReadonlyMap<string, RouteRecord<TMeta, TComponent>>;\n};\n\nexport function compileRoutes<TRoutes extends RouteTable, TMeta, TComponent>(\n options: RouterOptions<TRoutes, TMeta, TComponent>,\n): CompiledRoutes<TMeta, TComponent> {\n const records: RouteRecord<TMeta, TComponent>[] = [];\n\n const compile = (\n name: string,\n route: RouteDefinition,\n ancestorPath: string,\n ancestorBranchDefs: RouteBranchDef<TMeta, TComponent>[],\n ancestorMiddleware: RouteRecord<TMeta, TComponent>['ownMiddleware'],\n ): void => {\n if (route.index && route.path !== undefined) {\n throw new WayfinderRouteError(`Route \"${name}\" cannot define both index and path`);\n }\n\n if (!route.index && route.path === undefined) {\n throw new WayfinderRouteError(`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<TMeta, TComponent>[] = [\n ...ancestorBranchDefs,\n {\n component: route.component as TComponent | undefined,\n dataFn: route.data,\n lazy: route.lazy as RouteBranchDef<TMeta, TComponent>['lazy'],\n meta: route.meta as TMeta | undefined,\n name,\n onError: route.onError as RouteBranchDef<TMeta, TComponent>['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 // R9: emit a record for leaf routes (no children), redirects, lazy routes, and routes with data.\n // A bare parent-only route (children but no data/lazy/redirect) is not emitted as a leaf.\n if (route.lazy !== undefined || 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 WayfinderRouteError(\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":";;;;AAWA,SAAgB,EACd,GACmC;CACnC,IAAM,IAA4C,CAAC,GAE7C,KACJ,GACA,GACA,GACA,GACA,MACS;EACT,IAAI,EAAM,SAAS,EAAM,SAAS,KAAA,GAChC,MAAM,IAAI,EAAoB,UAAU,EAAK,oCAAoC;EAGnF,IAAI,CAAC,EAAM,SAAS,EAAM,SAAS,KAAA,GACjC,MAAM,IAAI,EAAoB,UAAU,EAAK,sCAAsC;EAGrF,IAAM,IAAU,EAAM,QAClB,IACA,EAAc,EAAM,OAAO,EAAU,GAAc,EAAM,IAAI,IAAI,CAAY,GAE3E,IAAkD,CACtD,GAAG,GACH;GACE,WAAW,EAAM;GACjB,QAAQ,EAAM;GACd,MAAM,EAAM;GACZ,MAAM,EAAM;GACZ;GACA,SAAS,EAAM;EACjB,CACF,GAEM,IAA8B,CAClC,GAAG,GACH,GAAK,EAAM,cAAc,CAAC,CAC5B;EAEA,IAAI,EAAM,UACR,KAAK,IAAM,CAAC,GAAW,MAAe,OAAO,QAAQ,EAAM,QAAQ,GACjE,EAAQ,GAAG,EAAK,GAAG,KAAa,GAAY,GAAS,GAAY,CAAa;EAMlF,IAAI,EAAM,SAAS,KAAA,KAAa,EAAM,aAAa,KAAA,KAAa,CAAC,EAAM,YAAY,EAAM,SAAS,KAAA,GAAW;GAC3G,IAAM,IAAO,EAAW,EAAW,SAAS;GAE5C,EAAQ,KAAK;IACX;IACA,cAAc,EAAM;IACpB;IACA,SAAS,EAAmB,CAAO;IACnC;IACA,MAAM;IACN,UAAU,EAAM;GAClB,CAAC;EACH;CACF;CAEA,KAAK,IAAM,CAAC,GAAM,MAAU,OAAO,QAAQ,EAAQ,MAAM,GACvD,EAAQ,GAAM,GAAO,KAAK,CAAC,GAAG,CAAC,CAAC;CAIlC,IAAM,oBAAY,IAAI,IAAY;CAElC,KAAK,IAAM,KAAU,GAAS;EAC5B,IAAI,EAAU,IAAI,EAAO,KAAK,IAAI,GAChC,MAAM,IAAI,EACR,0BAA0B,EAAO,KAAK,KAAK,oFAC7C;EAGF,EAAU,IAAI,EAAO,KAAK,IAAI;CAChC;CAIA,IAAI,IAAe;CAEnB,KAAK,IAAM,KAAU,GAAS;EAC5B,IAAM,IACJ,EAAO,SAAS,QAAQ,EAAO,KAAK,SAAS,IAAI,KAAM,EAAO,KAAK,SAAS,GAAG,KAAK,EAAO,KAAK,SAAS,GAAG;EAQ9G,AANI,KAAgB,CAAC,KAEjB,GAAU,EAAO,KAAK,KAAtB,EAAgC,EAAO,KAAvC,GAIA,MAAY,IAAe;CACjC;CAEA,OAAO;EACL;EACA,cAAc,IAAI,IAAI,EAAQ,KAAK,MAAM,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC;CAC5D;AACF"}
package/dist/context.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./_dev.cjs"),t=require("./errors.cjs");function n(e){return{error:e.error,location:e.location,matches:e.matches,status:e.status}}function r(e,t,n,r,i){return e.map((e,a)=>({component:e.component,data:r[a],meta:e.meta,name:e.name,params:{...t},pathname:n,status:i?.[a]??`idle`}))}function i(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 a(e,n,r){async function i(a){if(a<n.length){let r=!1;await n[a](e,async()=>{if(r)throw new t.WayfinderApiError(`next() called multiple times`);r=!0,await i(a+1)});return}await r()}await i(0)}function o(t,n,r){if(r){r(t,n);return}e.error(`Unhandled router error. Provide an onError callback to handle errors explicitly:`,t)}exports.buildMatchBranch=r,exports.createRouteContext=i,exports.createRouteState=n,exports.executeMiddlewarePipeline=a,exports.reportError=o;
1
+ require("./_dev.cjs");const e=require("./errors.cjs");function t(e){return{error:e.error,location:e.location,matches:e.matches,status:e.status}}function n(e,t,n,r,i){return e.map((e,a)=>({component:e.component,data:r[a],meta:e.meta,name:e.name,params:{...t},pathname:n,status:i?.[a]??`idle`}))}function r(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 i(t,n,r){async function i(a){if(a<n.length){let r=!1;await n[a](t,async()=>{if(r)throw new e.WayfinderApiError(`next() called multiple times`);r=!0,await i(a+1)});return}await r()}await i(0)}function a(e,t,n){if(n){n(e,t);return}}exports.buildMatchBranch=n,exports.createRouteContext=r,exports.createRouteState=t,exports.executeMiddlewarePipeline=i,exports.reportError=a;
2
2
  //# sourceMappingURL=context.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.cjs","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type {\n MatchStatus,\n Middleware,\n NavigationStatus,\n ResolvedQueryParams,\n RouteBranchDef,\n RouteContext,\n RouteLocation,\n RouteMatchBranch,\n RouteParams,\n RouterErrorContext,\n RouteState,\n RouteTable,\n} from './types';\n\nimport { error as logError } from './_dev';\nimport { WayfinderApiError } from './errors';\n\n// ─── Route state ──────────────────────────────────────────────────────────────\n\n/** R5: No defensive deep-copy — RouteState is typed readonly; callers always pass fresh objects. */\nexport function createRouteState<TMeta = unknown, TComponent = unknown>(input: {\n error?: unknown;\n location: RouteLocation;\n matches: RouteMatchBranch<TMeta, TComponent>;\n status: NavigationStatus;\n}): RouteState<TMeta, TComponent> {\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, data results, and optional per-node statuses.\n * F1: Each node carries its own `status` for fine-grained nested layout feedback.\n */\nexport function buildMatchBranch<TMeta = unknown, TComponent = unknown>(\n branchDefs: readonly RouteBranchDef<TMeta, TComponent>[],\n params: RouteParams,\n pathname: string,\n dataResults: unknown[],\n statuses?: readonly MatchStatus[],\n): RouteMatchBranch<TMeta, TComponent> {\n return branchDefs.map((def, i): RouteMatchBranch<TMeta, TComponent>[number] => ({\n component: def.component as TComponent,\n data: dataResults[i],\n meta: def.meta as TMeta,\n name: def.name,\n params: { ...params },\n pathname,\n status: statuses?.[i] ?? 'idle',\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): Promise<void> {\n async function dispatch(index: number): Promise<void> {\n if (index < middleware.length) {\n let called = false;\n\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\n return;\n }\n\n await terminal();\n }\n\n await dispatch(0);\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":"wDAqBA,SAAgB,EAAwD,EAKtC,CAChC,MAAO,CACL,MAAO,EAAM,MACb,SAAU,EAAM,SAChB,QAAS,EAAM,QACf,OAAQ,EAAM,MAChB,CACF,CAMA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACqC,CACrC,OAAO,EAAW,KAAK,EAAK,KAAoD,CAC9E,UAAW,EAAI,UACf,KAAM,EAAY,GAClB,KAAM,EAAI,KACV,KAAM,EAAI,KACV,OAAQ,CAAE,GAAG,CAAO,EACpB,WACA,OAAQ,IAAW,IAAM,MAC3B,EAAE,CACJ,CAIA,SAAgB,EACd,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,EACpB,EACA,EACA,EACe,CACf,eAAe,EAAS,EAA8B,CACpD,GAAI,EAAQ,EAAW,OAAQ,CAC7B,IAAI,EAAS,GAEb,MAAM,EAAW,EAAM,CAAE,EAAS,SAAY,CAC5C,GAAI,EAAQ,MAAM,IAAI,EAAA,kBAAkB,8BAA8B,EAEtE,EAAS,GACT,MAAM,EAAS,EAAQ,CAAC,CAC1B,CAAC,EAED,MACF,CAEA,MAAM,EAAS,CACjB,CAEA,MAAM,EAAS,CAAC,CAClB,CAIA,SAAgB,EACd,EACA,EACA,EACM,CACN,GAAI,EAAS,CACX,EAAQ,EAAO,CAAO,EAEtB,MACF,CAEA,EAAA,MAAS,mFAAoF,CAAK,CACpG"}
1
+ {"version":3,"file":"context.cjs","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type {\n MatchStatus,\n Middleware,\n NavigationStatus,\n ResolvedQueryParams,\n RouteBranchDef,\n RouteContext,\n RouteLocation,\n RouteMatchBranch,\n RouteParams,\n RouterErrorContext,\n RouteState,\n RouteTable,\n} from './types';\n\nimport { error as logError } from './_dev';\nimport { WayfinderApiError } from './errors';\n\n// ─── Route state ──────────────────────────────────────────────────────────────\n\n/** R5: No defensive deep-copy — RouteState is typed readonly; callers always pass fresh objects. */\nexport function createRouteState<TMeta = unknown, TComponent = unknown>(input: {\n error?: unknown;\n location: RouteLocation;\n matches: RouteMatchBranch<TMeta, TComponent>;\n status: NavigationStatus;\n}): RouteState<TMeta, TComponent> {\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, data results, and optional per-node statuses.\n * F1: Each node carries its own `status` for fine-grained nested layout feedback.\n */\nexport function buildMatchBranch<TMeta = unknown, TComponent = unknown>(\n branchDefs: readonly RouteBranchDef<TMeta, TComponent>[],\n params: RouteParams,\n pathname: string,\n dataResults: unknown[],\n statuses?: readonly MatchStatus[],\n): RouteMatchBranch<TMeta, TComponent> {\n return branchDefs.map((def, i): RouteMatchBranch<TMeta, TComponent>[number] => ({\n component: def.component as TComponent,\n data: dataResults[i],\n meta: def.meta as TMeta,\n name: def.name,\n params: { ...params },\n pathname,\n status: statuses?.[i] ?? 'idle',\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): Promise<void> {\n async function dispatch(index: number): Promise<void> {\n if (index < middleware.length) {\n let called = false;\n\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\n return;\n }\n\n await terminal();\n }\n\n await dispatch(0);\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":"sDAqBA,SAAgB,EAAwD,EAKtC,CAChC,MAAO,CACL,MAAO,EAAM,MACb,SAAU,EAAM,SAChB,QAAS,EAAM,QACf,OAAQ,EAAM,MAChB,CACF,CAMA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACqC,CACrC,OAAO,EAAW,KAAK,EAAK,KAAoD,CAC9E,UAAW,EAAI,UACf,KAAM,EAAY,GAClB,KAAM,EAAI,KACV,KAAM,EAAI,KACV,OAAQ,CAAE,GAAG,CAAO,EACpB,WACA,OAAQ,IAAW,IAAM,MAC3B,EAAE,CACJ,CAIA,SAAgB,EACd,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,EACpB,EACA,EACA,EACe,CACf,eAAe,EAAS,EAA8B,CACpD,GAAI,EAAQ,EAAW,OAAQ,CAC7B,IAAI,EAAS,GAEb,MAAM,EAAW,EAAM,CAAE,EAAS,SAAY,CAC5C,GAAI,EAAQ,MAAM,IAAI,EAAA,kBAAkB,8BAA8B,EAEtE,EAAS,GACT,MAAM,EAAS,EAAQ,CAAC,CAC1B,CAAC,EAED,MACF,CAEA,MAAM,EAAS,CACjB,CAEA,MAAM,EAAS,CAAC,CAClB,CAIA,SAAgB,EACd,EACA,EACA,EACM,CACN,GAAI,EAAS,CACX,EAAQ,EAAO,CAAO,EAEtB,MACF,CAGF"}
package/dist/context.js CHANGED
@@ -1,7 +1,7 @@
1
- import { error as e } from "./_dev.js";
2
- import { WayfinderApiError as t } from "./errors.js";
1
+ import "./_dev.js";
2
+ import { WayfinderApiError as e } from "./errors.js";
3
3
  //#region src/context.ts
4
- function n(e) {
4
+ function t(e) {
5
5
  return {
6
6
  error: e.error,
7
7
  location: e.location,
@@ -9,7 +9,7 @@ function n(e) {
9
9
  status: e.status
10
10
  };
11
11
  }
12
- function r(e, t, n, r, i) {
12
+ function n(e, t, n, r, i) {
13
13
  return e.map((e, a) => ({
14
14
  component: e.component,
15
15
  data: r[a],
@@ -20,7 +20,7 @@ function r(e, t, n, r, i) {
20
20
  status: i?.[a] ?? "idle"
21
21
  }));
22
22
  }
23
- function i(e, t, n, r, i) {
23
+ function r(e, t, n, r, i) {
24
24
  return {
25
25
  hash: e.hash,
26
26
  historyState: e.historyState,
@@ -32,12 +32,12 @@ function i(e, t, n, r, i) {
32
32
  query: t
33
33
  };
34
34
  }
35
- async function a(e, n, r) {
35
+ async function i(t, n, r) {
36
36
  async function i(a) {
37
37
  if (a < n.length) {
38
38
  let r = !1;
39
- await n[a](e, async () => {
40
- if (r) throw new t("next() called multiple times");
39
+ await n[a](t, async () => {
40
+ if (r) throw new e("next() called multiple times");
41
41
  r = !0, await i(a + 1);
42
42
  });
43
43
  return;
@@ -46,14 +46,13 @@ async function a(e, n, r) {
46
46
  }
47
47
  await i(0);
48
48
  }
49
- function o(t, n, r) {
50
- if (r) {
51
- r(t, n);
49
+ function a(e, t, n) {
50
+ if (n) {
51
+ n(e, t);
52
52
  return;
53
53
  }
54
- e("Unhandled router error. Provide an onError callback to handle errors explicitly:", t);
55
54
  }
56
55
  //#endregion
57
- export { r as buildMatchBranch, i as createRouteContext, n as createRouteState, a as executeMiddlewarePipeline, o as reportError };
56
+ export { n as buildMatchBranch, r as createRouteContext, t as createRouteState, i as executeMiddlewarePipeline, a as reportError };
58
57
 
59
58
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type {\n MatchStatus,\n Middleware,\n NavigationStatus,\n ResolvedQueryParams,\n RouteBranchDef,\n RouteContext,\n RouteLocation,\n RouteMatchBranch,\n RouteParams,\n RouterErrorContext,\n RouteState,\n RouteTable,\n} from './types';\n\nimport { error as logError } from './_dev';\nimport { WayfinderApiError } from './errors';\n\n// ─── Route state ──────────────────────────────────────────────────────────────\n\n/** R5: No defensive deep-copy — RouteState is typed readonly; callers always pass fresh objects. */\nexport function createRouteState<TMeta = unknown, TComponent = unknown>(input: {\n error?: unknown;\n location: RouteLocation;\n matches: RouteMatchBranch<TMeta, TComponent>;\n status: NavigationStatus;\n}): RouteState<TMeta, TComponent> {\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, data results, and optional per-node statuses.\n * F1: Each node carries its own `status` for fine-grained nested layout feedback.\n */\nexport function buildMatchBranch<TMeta = unknown, TComponent = unknown>(\n branchDefs: readonly RouteBranchDef<TMeta, TComponent>[],\n params: RouteParams,\n pathname: string,\n dataResults: unknown[],\n statuses?: readonly MatchStatus[],\n): RouteMatchBranch<TMeta, TComponent> {\n return branchDefs.map((def, i): RouteMatchBranch<TMeta, TComponent>[number] => ({\n component: def.component as TComponent,\n data: dataResults[i],\n meta: def.meta as TMeta,\n name: def.name,\n params: { ...params },\n pathname,\n status: statuses?.[i] ?? 'idle',\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): Promise<void> {\n async function dispatch(index: number): Promise<void> {\n if (index < middleware.length) {\n let called = false;\n\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\n return;\n }\n\n await terminal();\n }\n\n await dispatch(0);\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":";;;AAqBA,SAAgB,EAAwD,GAKtC;CAChC,OAAO;EACL,OAAO,EAAM;EACb,UAAU,EAAM;EAChB,SAAS,EAAM;EACf,QAAQ,EAAM;CAChB;AACF;AAMA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACqC;CACrC,OAAO,EAAW,KAAK,GAAK,OAAoD;EAC9E,WAAW,EAAI;EACf,MAAM,EAAY;EAClB,MAAM,EAAI;EACV,MAAM,EAAI;EACV,QAAQ,EAAE,GAAG,EAAO;EACpB;EACA,QAAQ,IAAW,MAAM;CAC3B,EAAE;AACJ;AAIA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACoC;CACpC,OAAO;EACL,MAAM,EAAS;EACf,cAAc,EAAS;EACvB,QAAQ,CAAC;EACT;EACA;EACA;EACA,UAAU,EAAS;EACnB,OAAO;CACT;AACF;AAIA,eAAsB,EACpB,GACA,GACA,GACe;CACf,eAAe,EAAS,GAA8B;EACpD,IAAI,IAAQ,EAAW,QAAQ;GAC7B,IAAI,IAAS;GAEb,MAAM,EAAW,EAAM,CAAE,GAAS,YAAY;IAC5C,IAAI,GAAQ,MAAM,IAAI,EAAkB,8BAA8B;IAGtE,AADA,IAAS,IACT,MAAM,EAAS,IAAQ,CAAC;GAC1B,CAAC;GAED;EACF;EAEA,MAAM,EAAS;CACjB;CAEA,MAAM,EAAS,CAAC;AAClB;AAIA,SAAgB,EACd,GACA,GACA,GACM;CACN,IAAI,GAAS;EACX,EAAQ,GAAO,CAAO;EAEtB;CACF;CAEA,EAAS,oFAAoF,CAAK;AACpG"}
1
+ {"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type {\n MatchStatus,\n Middleware,\n NavigationStatus,\n ResolvedQueryParams,\n RouteBranchDef,\n RouteContext,\n RouteLocation,\n RouteMatchBranch,\n RouteParams,\n RouterErrorContext,\n RouteState,\n RouteTable,\n} from './types';\n\nimport { error as logError } from './_dev';\nimport { WayfinderApiError } from './errors';\n\n// ─── Route state ──────────────────────────────────────────────────────────────\n\n/** R5: No defensive deep-copy — RouteState is typed readonly; callers always pass fresh objects. */\nexport function createRouteState<TMeta = unknown, TComponent = unknown>(input: {\n error?: unknown;\n location: RouteLocation;\n matches: RouteMatchBranch<TMeta, TComponent>;\n status: NavigationStatus;\n}): RouteState<TMeta, TComponent> {\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, data results, and optional per-node statuses.\n * F1: Each node carries its own `status` for fine-grained nested layout feedback.\n */\nexport function buildMatchBranch<TMeta = unknown, TComponent = unknown>(\n branchDefs: readonly RouteBranchDef<TMeta, TComponent>[],\n params: RouteParams,\n pathname: string,\n dataResults: unknown[],\n statuses?: readonly MatchStatus[],\n): RouteMatchBranch<TMeta, TComponent> {\n return branchDefs.map((def, i): RouteMatchBranch<TMeta, TComponent>[number] => ({\n component: def.component as TComponent,\n data: dataResults[i],\n meta: def.meta as TMeta,\n name: def.name,\n params: { ...params },\n pathname,\n status: statuses?.[i] ?? 'idle',\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): Promise<void> {\n async function dispatch(index: number): Promise<void> {\n if (index < middleware.length) {\n let called = false;\n\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\n return;\n }\n\n await terminal();\n }\n\n await dispatch(0);\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":";;;AAqBA,SAAgB,EAAwD,GAKtC;CAChC,OAAO;EACL,OAAO,EAAM;EACb,UAAU,EAAM;EAChB,SAAS,EAAM;EACf,QAAQ,EAAM;CAChB;AACF;AAMA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACqC;CACrC,OAAO,EAAW,KAAK,GAAK,OAAoD;EAC9E,WAAW,EAAI;EACf,MAAM,EAAY;EAClB,MAAM,EAAI;EACV,MAAM,EAAI;EACV,QAAQ,EAAE,GAAG,EAAO;EACpB;EACA,QAAQ,IAAW,MAAM;CAC3B,EAAE;AACJ;AAIA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACoC;CACpC,OAAO;EACL,MAAM,EAAS;EACf,cAAc,EAAS;EACvB,QAAQ,CAAC;EACT;EACA;EACA;EACA,UAAU,EAAS;EACnB,OAAO;CACT;AACF;AAIA,eAAsB,EACpB,GACA,GACA,GACe;CACf,eAAe,EAAS,GAA8B;EACpD,IAAI,IAAQ,EAAW,QAAQ;GAC7B,IAAI,IAAS;GAEb,MAAM,EAAW,EAAM,CAAE,GAAS,YAAY;IAC5C,IAAI,GAAQ,MAAM,IAAI,EAAkB,8BAA8B;IAGtE,AADA,IAAS,IACT,MAAM,EAAS,IAAQ,CAAC;GAC1B,CAAC;GAED;EACF;EAEA,MAAM,EAAS;CACjB;CAEA,MAAM,EAAS,CAAC;AAClB;AAIA,SAAgB,EACd,GACA,GACA,GACM;CACN,IAAI,GAAS;EACX,EAAQ,GAAO,CAAO;EAEtB;CACF;AAGF"}
@@ -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 static is(err: unknown): err is WayfinderError {\n return err instanceof WayfinderError;\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,EAAb,MAAa,UAAuB,KAAM,CACxC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,IAAI,OAAO,KACvB,OAAO,eAAe,KAAM,IAAI,OAAO,SAAS,CAClD,CAEA,OAAO,GAAG,EAAqC,CAC7C,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAA4C,CAAe,CACzD,aAAc,CACZ,MAAM,oBAAoB,CAC5B,CACF,EAGa,EAAb,cAAyC,CAAe,CAAC,EAG5C,EAAb,cAAgD,CAAe,CAC7D,aAAc,CACZ,MAAM,wBAAwB,CAChC,CACF,EAGa,EAAb,cAAuC,CAAe,CAAC"}
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 static is(err: unknown): err is WayfinderError {\n return err instanceof WayfinderError;\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,EAAb,MAAa,UAAuB,KAAM,CACxC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CAEA,OAAO,GAAG,EAAqC,CAC7C,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAA4C,CAAe,CACzD,aAAc,CACZ,MAAM,oBAAoB,CAC5B,CACF,EAGa,EAAb,cAAyC,CAAe,CAAC,EAG5C,EAAb,cAAgD,CAAe,CAC7D,aAAc,CACZ,MAAM,wBAAwB,CAChC,CACF,EAGa,EAAb,cAAuC,CAAe,CAAC"}
@@ -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 static is(err: unknown): err is WayfinderError {\n return err instanceof WayfinderError;\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,IAAb,MAAa,UAAuB,MAAM;CACxC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,IAAI,OAAO,MACvB,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;CAClD;CAEA,OAAO,GAAG,GAAqC;EAC7C,OAAO,aAAe;CACxB;AACF,GAGa,IAAb,cAA4C,EAAe;CACzD,cAAc;EACZ,MAAM,oBAAoB;CAC5B;AACF,GAGa,IAAb,cAAyC,EAAe,CAAC,GAG5C,IAAb,cAAgD,EAAe;CAC7D,cAAc;EACZ,MAAM,wBAAwB;CAChC;AACF,GAGa,IAAb,cAAuC,EAAe,CAAC"}
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 static is(err: unknown): err is WayfinderError {\n return err instanceof WayfinderError;\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,IAAb,MAAa,UAAuB,MAAM;CACxC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;CAEA,OAAO,GAAG,GAAqC;EAC7C,OAAO,aAAe;CACxB;AACF,GAGa,IAAb,cAA4C,EAAe;CACzD,cAAc;EACZ,MAAM,oBAAoB;CAC5B;AACF,GAGa,IAAb,cAAyC,EAAe,CAAC,GAG5C,IAAb,cAAgD,EAAe;CAC7D,cAAc;EACZ,MAAM,wBAAwB;CAChC;AACF,GAGa,IAAb,cAAuC,EAAe,CAAC"}
package/dist/router.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./errors.cjs"),t=require("./path.cjs"),n=require("./compile.cjs"),r=require("./context.cjs"),i=require("./guards.cjs"),a=require("./history.cjs"),o=require("./hydration.cjs"),s=require("./preload.cjs");function c(t,n){let r=n.get(t);if(r)return r;let i=[...n.keys()].join(`, `);throw new e.WayfinderRouteError(i?`Unknown route name: ${t}. Available routes: ${i}`:`Unknown route name: ${t}`)}function l(e,n,r=`/`){if(`path`in e)return e.path;let i=t.buildUrl(r,c(e.name,n).path,e.params,e.query);return e.hash?`${i}#${e.hash}`:i}var u=Symbol(`wayfinder.errorContext`);function d(e,t){typeof e==`object`&&e&&(e[u]=t)}function f(e){if(typeof e==`object`&&e)return e[u]}function p(e){return typeof e==`object`&&!!e&&typeof e[Symbol.asyncIterator]==`function`&&typeof e.next==`function`&&typeof e.return==`function`}var m=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=null;#u=new Set;#d;#f=!1;#p=new AbortController;#m=`/`;#h=new Set;#g;#_;#v;#y;constructor(e){let i=n.compileRoutes(e);if(this.#e=t.normalizePath(e.base??`/`),this.#t=e.middleware??[],this.#n=e.coerceSearch,this.#r=e.history??a.createBrowserHistory(),this.#s=e.viewTransition??!1,this.#o=e.scroll,this.#c=e.onError,this.#i=i.records,this.#a=i.routesByName,this.#_=o.createHydrationManager(),this.#v=s.createPreloadManager(),this.#d=r.createRouteState({location:{hash:``,historyState:null,pathname:`/`,query:{}},matches:[],status:`idle`}),e.notFound){let t=e.notFound,n={component:t.component,dataFn:t.data,meta:t.meta,name:`__notFound__`};this.#g={branchDefs:[n],leaf:n,matcher:{paramNames:[],pattern:/(?:)/,prefixPattern:/(?:)/},ownMiddleware:t.middleware??[],path:`/*`}}else this.#g=null;this.#y=this.#x();let{hash:c,pathname:l,search:u}=this.#r.location;this.#m=`${l}${u}${c}`,this.#w(this.#F(),{source:`initial-navigation`})}getSnapshot(){return this.#d}subscribe(e){return this.#b(),this.#h.add(e),()=>{this.#h.delete(e)}}navigate(e,t){let n=l(typeof e==`string`?{path:e}:e,this.#a);return this.#z(n,t)}url(e,n,r){let i=c(e,this.#a);return t.buildUrl(this.#e,i.path,n,r)}isActive(e,n={}){let r=c(e,this.#a),i=this.#d.location.pathname;return n.exact??!1?t.matchRouteFor(i,[r]).record!=null:t.matchesPrefix(i,r)}resolve(e){let n=t.stripBase(t.normalizePath(e),this.#e),{params:i,record:a}=t.matchRouteFor(n,this.#i);if(!a||a.redirect)return null;let o=this.#_.effectiveDefs(a),s=r.buildMatchBranch(o,i,n,o.map(()=>void 0));return s.length?s:null}async match(e,t){let n=await this.#k(e);if(n.type!==`matched`)return null;let{location:i,params:a,record:o,resolvedQuery:s}=n,c=this.#_.effectiveDefs(o),l=c.some(e=>e.dataFn!=null),u=c.map(()=>void 0),d,f=`idle`;if(l){let e=t?.signal??new AbortController().signal,n=r.createRouteContext(i,s,a,r.buildMatchBranch(c,a,i.pathname,u),()=>Promise.resolve());try{u=await this.#D(c,n,e)}catch(e){d=e,f=`error`}}return r.createRouteState({error:d,location:i,matches:r.buildMatchBranch(c,a,i.pathname,u),status:f})}waitFor(e){return this.#b(),new Promise((t,n)=>{let r=t=>t.status===`idle`&&t.matches.some(t=>t.name===e);if(this.#d.status===`error`){n(this.#d.error);return}if(r(this.#d)){t(this.#d);return}let i=this.subscribe(e=>{r(e)?(i(),t(e)):e.status===`error`&&(i(),n(e.error))});this.#p.signal.addEventListener(`abort`,()=>{i(),n(this.#p.signal.reason)},{once:!0})})}async preload(e,n,r){this.#b();let i=c(e,this.#a),a=t.buildPreloadKey(this.#e,i.path,n,r),o=this.#v.getInflight(a);if(o)return o;let s=this.#A(a,this.#p.signal,r).finally(()=>{this.#v.untrack(a)});this.#v.track(a,s);try{return await s}catch(e){throw this.#c&&this.#C(e,{source:`preload`}),e}}beforeLeave(e,t){this.#b();let n={handler:e,routes:t?.routes};return this.#u.add(n),()=>{this.#u.delete(n)}}get disposalSignal(){return this.#p.signal}get disposed(){return this.#f}dispose(){this.#f||(this.#f=!0,this.#u.clear(),this.#h.clear(),this.#l?.abort(),this.#l=null,this.#y(),this.#p.abort(new e.WayfinderDisposedError))}[Symbol.dispose](){this.dispose()}#b(){if(this.#f)throw new e.WayfinderDisposedError}#x(){return this.#r.onPopstate(()=>{let{hash:e,pathname:t,search:n}=this.#r.location,r=`${t}${n}${e}`,i=this.#m;r!==i&&this.#w(this.#S(r,i),{source:`history-listener`})})}async#S(e,n){let r=this.#d.matches.map(e=>e.name),a=new URL(e,`http://localhost`),o=t.stripBase(a.pathname,this.#e),{params:s,record:c}=t.matchRouteFor(o,this.#i),l={name:c?.leaf.name,params:s,pathname:o,query:t.parseQuery(a.search)};if(!await i.runLeaveBlockers(this.#u,r,l)){this.#r.replace(n,this.#d.location.historyState);return}this.#m=e,await this.#F()}#C(e,t){r.reportError(e,t,this.#c)}#w(e,t){e.catch(e=>{this.#C(e,f(e)??t)})}#T(){this.#h.forEach(e=>e(this.#d))}async#E(e,t){let n;for(;;){if(t.aborted)return await e.return(void 0).catch(()=>void 0),n;let{done:r,value:i}=await e.next();if(r)return i??n;n=i}}async#D(e,t,n){return Promise.all(e.map(async e=>{if(!e.dataFn)return;let r=e.dataFn,i=r({...t,signal:n});try{return p(i)?await this.#E(i,n):await i}catch(r){if(e.onError)return e.onError(r,{...t,signal:n});throw r}}))}async#O(e,t,n,i,a,o){let s=e.map(e=>{if(!e.dataFn)return;let r=e.dataFn;return r({...t,signal:n})}),c=[],l=await Promise.all(s.map(async(r,i)=>{if(p(r)){c.push(i);return}if(r!==void 0)try{return await r}catch(r){let a=e[i];if(a.onError)return a.onError(r,{...t,signal:n});throw r}}));if(c.length===0)return l;let u=[...l],d=(t,n)=>{if(!i())return;u[n]=t;let s=e.map((e,t)=>c.includes(t)?`streaming`:`idle`);this.#d=r.createRouteState({location:a,matches:r.buildMatchBranch(e,o,a.pathname,u,s),status:`streaming`}),this.#T()};return await Promise.all(c.map(async r=>{let a=s[r];try{u[r]=await this.#M(a,r,n,i,d)}catch(i){let a=e[r];if(a.onError)u[r]=await a.onError(i,{...t,signal:n});else throw i}})),u}async#k(n){let r=n;for(let e=0;e<5;e+=1){let e=new URL(r,`http://localhost`),n={hash:e.hash.replace(/^#/,``),historyState:null,pathname:t.stripBase(e.pathname,this.#e),query:t.parseQuery(e.search)},i=await this.#j(n);if(i.type!==`redirect`)return i;r=this.#L(i.redirectTo)}throw new e.WayfinderRedirectLoopError}async#A(e,n,i){let a=await this.#k(e);if(a.type!==`matched`)return;let{location:o,params:s,record:c,resolvedQuery:l}=a,u=this.#_.effectiveDefs(c);if(!u.some(e=>e.dataFn!=null))return;let d=r.createRouteContext(o,l,s,r.buildMatchBranch(u,s,o.pathname,u.map(()=>void 0)),()=>Promise.resolve()),f=await this.#D(u,d,n);this.#v.set(t.buildPreloadKey(this.#e,c.path,s,i??o.query),f)}async#j(e){let{params:n,record:i}=t.matchRouteFor(e.pathname,this.#i);if(!i)return{location:e,params:n,type:`unmatched`};if(i.redirect)return{location:e,params:n,redirectTo:l(i.redirect,this.#a,this.#e),type:`redirect`};let a=e.query,o=i.coerceSearch??this.#n;if(o)try{a=o(e.query)}catch(t){this.#C(t,{source:`coerce-search`}),a=e.query}await this.#_.hydrate(i);let s=this.#_.effectiveDefs(i);return{branch:r.buildMatchBranch(s,n,e.pathname,s.map(()=>void 0)),location:e,params:n,record:i,resolvedQuery:a,type:`matched`}}async#M(e,t,n,r,i){let a;try{for(;;){if(n.aborted||!r())return await e.return(void 0),a;let{done:o,value:s}=await e.next();if(o)return s??a;a=s,i(s,t)}}catch(t){throw await e.return(void 0).catch(()=>void 0),t}}async#N(e,n,i,a,o,s,c){if(!c())return;let l=this.#_.effectiveDefs(e),u=l.some(e=>e.dataFn!=null),f=l.map(()=>void 0);if(u){let o=t.buildPreloadKey(this.#e,e.path,a,i.query),u=this.#v.consume(o);if(u)f=u;else{let t=l.map(e=>e.dataFn?`loading`:`idle`);this.#d=r.createRouteState({location:i,matches:r.buildMatchBranch(l,a,i.pathname,f,t),status:`loading`}),this.#T();try{f=await this.#O(l,n,s,c,i,a)}catch(t){throw this.#d=r.createRouteState({error:t,location:i,matches:r.buildMatchBranch(l,a,i.pathname,f),status:`error`}),d(t,{routeName:e.leaf.name,source:`data-loader`}),t}}}c()&&(this.#d=r.createRouteState({location:i,matches:r.buildMatchBranch(l,a,i.pathname,f),status:`idle`}))}async#P(e,t){if((t??this.#s)&&typeof document<`u`){let t=document;if(t.startViewTransition){await t.startViewTransition(e).finished;return}}await e()}async#F(e,n=0){this.#l?.abort();let i=new AbortController;this.#l=i;let a=this.#d,o=()=>!i.signal.aborted&&!this.#f,s=t.readLocation(this.#e,this.#r),c=await this.#j(s);if(!o())return;if(c.type===`redirect`){await this.#R(c.redirectTo,!0,n);return}if(c.type===`unmatched`){if(this.#g){let t=r.buildMatchBranch([this.#g.leaf],{},s.pathname,[void 0]),n=!1,c=s.query;if(this.#n)try{c=this.#n(s.query)}catch(e){this.#C(e,{source:`coerce-search`})}let l=async()=>{if(!o())return;let e=r.createRouteContext(s,c,{},t,(e,t)=>this.navigate(e,t));await r.executeMiddlewarePipeline(e,[...this.#t,...this.#g.ownMiddleware],async()=>{n=!0,await this.#N(this.#g,e,s,{},t,i.signal,o)})};try{await this.#P(l,e)}finally{o()&&n&&(this.#T(),this.#I(this.#d,a))}return}this.#d=r.createRouteState({location:c.location,matches:[],status:`idle`}),this.#T(),this.#I(this.#d,a);return}let{branch:l,location:u,params:d,record:f,resolvedQuery:p}=c,m=!1,h=async()=>{if(!o())return;let e=r.createRouteContext(u,p,d,l,(e,t)=>this.navigate(e,t));await r.executeMiddlewarePipeline(e,[...this.#t,...f.ownMiddleware],async()=>{m=!0,await this.#N(f,e,u,d,l,i.signal,o)})};try{await this.#P(h,e)}finally{o()&&m&&(this.#T(),this.#I(this.#d,a))}}#I(e,t){if(!this.#o||typeof window>`u`)return;let n=this.#o(e,t);if(n!==`preserve`){if(n===`top`){window.scrollTo(0,0);return}window.scrollTo(n.x,n.y)}}#L(e){let n=new URL(e,`http://localhost`),r=t.stripBase(n.pathname,this.#e);return`${t.joinPaths(this.#e,r)}${n.search}${n.hash}`}async#R(t,n=!0,r=0){if(r>=5)throw new e.WayfinderRedirectLoopError;let i=this.#L(t);this.#m=i,n?this.#r.replace(i):this.#r.push(i),await this.#F(void 0,r+1)}async#z(e,n={}){this.#b();let r=this.#L(e);if(!n.force&&r===this.#m)return;let a=this.#m,o=this.#d.matches.map(e=>e.name),s=new URL(r,`http://localhost`),c=t.stripBase(s.pathname,this.#e),{params:l,record:u}=t.matchRouteFor(c,this.#i),d={name:u?.leaf.name,params:l,pathname:c,query:t.parseQuery(s.search)};if(await i.runLeaveBlockers(this.#u,o,d)){this.#m=r,n.replace?this.#r.replace(r,n.state):this.#r.push(r,n.state);try{await this.#F(n.viewTransition)}catch(e){throw this.#m=a,e}}}};function h(e){return new m(e)}exports.createRouter=h;
1
+ const e=require("./errors.cjs"),t=require("./path.cjs"),n=require("./compile.cjs"),r=require("./context.cjs"),i=require("./guards.cjs"),a=require("./history.cjs"),o=require("./hydration.cjs"),s=require("./preload.cjs");function c(t,n){let r=n.get(t);if(r)return r;let i=[...n.keys()].join(`, `);throw new e.WayfinderRouteError(i?`Unknown route name: ${t}. Available routes: ${i}`:`Unknown route name: ${t}`)}function l(e,n,r=`/`){if(`path`in e)return e.path;let i=c(e.name,n),a=t.buildUrl(r,i.path,e.params,e.query);return e.hash?`${a}#${e.hash}`:a}var u=Symbol(`wayfinder.errorContext`);function d(e,t){typeof e==`object`&&e&&(e[u]=t)}function f(e){if(typeof e==`object`&&e)return e[u]}function p(e){return typeof e==`object`&&!!e&&typeof e[Symbol.asyncIterator]==`function`&&typeof e.next==`function`&&typeof e.return==`function`}var m=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=null;#u=new Set;#d;#f=!1;#p=new AbortController;#m=`/`;#h=new Set;#g;#_;#v;#y;constructor(e){let i=n.compileRoutes(e);if(this.#e=t.normalizePath(e.base??`/`),this.#t=e.middleware??[],this.#n=e.coerceSearch,this.#r=e.history??a.createBrowserHistory(),this.#s=e.viewTransition??!1,this.#o=e.scroll,this.#c=e.onError,this.#i=i.records,this.#a=i.routesByName,this.#_=o.createHydrationManager(),this.#v=s.createPreloadManager(),this.#d=r.createRouteState({location:{hash:``,historyState:null,pathname:`/`,query:{}},matches:[],status:`idle`}),e.notFound){let t=e.notFound,n={component:t.component,dataFn:t.data,meta:t.meta,name:`__notFound__`};this.#g={branchDefs:[n],leaf:n,matcher:{paramNames:[],pattern:/(?:)/,prefixPattern:/(?:)/},ownMiddleware:t.middleware??[],path:`/*`}}else this.#g=null;this.#y=this.#x();let{hash:c,pathname:l,search:u}=this.#r.location;this.#m=`${l}${u}${c}`,this.#w(this.#F(),{source:`initial-navigation`})}getSnapshot(){return this.#d}subscribe(e){return this.#b(),this.#h.add(e),()=>{this.#h.delete(e)}}navigate(e,t){let n=l(typeof e==`string`?{path:e}:e,this.#a);return this.#z(n,t)}url(e,n,r){let i=c(e,this.#a);return t.buildUrl(this.#e,i.path,n,r)}isActive(e,n={}){let r=c(e,this.#a),i=this.#d.location.pathname;return n.exact??!1?t.matchRouteFor(i,[r]).record!=null:t.matchesPrefix(i,r)}resolve(e){let n=t.stripBase(t.normalizePath(e),this.#e),{params:i,record:a}=t.matchRouteFor(n,this.#i);if(!a||a.redirect)return null;let o=this.#_.effectiveDefs(a),s=r.buildMatchBranch(o,i,n,o.map(()=>void 0));return s.length?s:null}async match(e,t){let n=await this.#k(e);if(n.type!==`matched`)return null;let{location:i,params:a,record:o,resolvedQuery:s}=n,c=this.#_.effectiveDefs(o),l=c.some(e=>e.dataFn!=null),u=c.map(()=>void 0),d,f=`idle`;if(l){let e=t?.signal??new AbortController().signal,n=r.buildMatchBranch(c,a,i.pathname,u),o=r.createRouteContext(i,s,a,n,()=>Promise.resolve());try{u=await this.#D(c,o,e)}catch(e){d=e,f=`error`}}return r.createRouteState({error:d,location:i,matches:r.buildMatchBranch(c,a,i.pathname,u),status:f})}waitFor(e){return this.#b(),new Promise((t,n)=>{let r=t=>t.status===`idle`&&t.matches.some(t=>t.name===e);if(this.#d.status===`error`){n(this.#d.error);return}if(r(this.#d)){t(this.#d);return}let i=this.subscribe(e=>{r(e)?(i(),t(e)):e.status===`error`&&(i(),n(e.error))});this.#p.signal.addEventListener(`abort`,()=>{i(),n(this.#p.signal.reason)},{once:!0})})}async preload(e,n,r){this.#b();let i=c(e,this.#a),a=t.buildPreloadKey(this.#e,i.path,n,r),o=this.#v.getInflight(a);if(o)return o;let s=this.#A(a,this.#p.signal,r).finally(()=>{this.#v.untrack(a)});this.#v.track(a,s);try{return await s}catch(e){throw this.#c&&this.#C(e,{source:`preload`}),e}}beforeLeave(e,t){this.#b();let n={handler:e,routes:t?.routes};return this.#u.add(n),()=>{this.#u.delete(n)}}get disposalSignal(){return this.#p.signal}get disposed(){return this.#f}dispose(){this.#f||(this.#f=!0,this.#u.clear(),this.#h.clear(),this.#l?.abort(),this.#l=null,this.#y(),this.#p.abort(new e.WayfinderDisposedError))}[Symbol.dispose](){this.dispose()}#b(){if(this.#f)throw new e.WayfinderDisposedError}#x(){return this.#r.onPopstate(()=>{let{hash:e,pathname:t,search:n}=this.#r.location,r=`${t}${n}${e}`,i=this.#m;r!==i&&this.#w(this.#S(r,i),{source:`history-listener`})})}async#S(e,n){let r=this.#d.matches.map(e=>e.name),a=new URL(e,`http://localhost`),o=t.stripBase(a.pathname,this.#e),{params:s,record:c}=t.matchRouteFor(o,this.#i),l={name:c?.leaf.name,params:s,pathname:o,query:t.parseQuery(a.search)};if(!await i.runLeaveBlockers(this.#u,r,l)){this.#r.replace(n,this.#d.location.historyState);return}this.#m=e,await this.#F()}#C(e,t){r.reportError(e,t,this.#c)}#w(e,t){e.catch(e=>{this.#C(e,f(e)??t)})}#T(){this.#h.forEach(e=>e(this.#d))}async#E(e,t){let n;for(;;){if(t.aborted)return await e.return(void 0).catch(()=>void 0),n;let{done:r,value:i}=await e.next();if(r)return i??n;n=i}}async#D(e,t,n){return Promise.all(e.map(async e=>{if(!e.dataFn)return;let r=e.dataFn,i=r({...t,signal:n});try{return p(i)?await this.#E(i,n):await i}catch(r){if(e.onError)return e.onError(r,{...t,signal:n});throw r}}))}async#O(e,t,n,i,a,o){let s=e.map(e=>{if(!e.dataFn)return;let r=e.dataFn;return r({...t,signal:n})}),c=[],l=await Promise.all(s.map(async(r,i)=>{if(p(r)){c.push(i);return}if(r!==void 0)try{return await r}catch(r){let a=e[i];if(a.onError)return a.onError(r,{...t,signal:n});throw r}}));if(c.length===0)return l;let u=[...l],d=(t,n)=>{if(!i())return;u[n]=t;let s=e.map((e,t)=>c.includes(t)?`streaming`:`idle`);this.#d=r.createRouteState({location:a,matches:r.buildMatchBranch(e,o,a.pathname,u,s),status:`streaming`}),this.#T()};return await Promise.all(c.map(async r=>{let a=s[r];try{u[r]=await this.#M(a,r,n,i,d)}catch(i){let a=e[r];if(a.onError)u[r]=await a.onError(i,{...t,signal:n});else throw i}})),u}async#k(n){let r=n;for(let e=0;e<5;e+=1){let e=new URL(r,`http://localhost`),n={hash:e.hash.replace(/^#/,``),historyState:null,pathname:t.stripBase(e.pathname,this.#e),query:t.parseQuery(e.search)},i=await this.#j(n);if(i.type!==`redirect`)return i;r=this.#L(i.redirectTo)}throw new e.WayfinderRedirectLoopError}async#A(e,n,i){let a=await this.#k(e);if(a.type!==`matched`)return;let{location:o,params:s,record:c,resolvedQuery:l}=a,u=this.#_.effectiveDefs(c);if(!u.some(e=>e.dataFn!=null))return;let d=r.buildMatchBranch(u,s,o.pathname,u.map(()=>void 0)),f=r.createRouteContext(o,l,s,d,()=>Promise.resolve()),p=await this.#D(u,f,n);this.#v.set(t.buildPreloadKey(this.#e,c.path,s,i??o.query),p)}async#j(e){let{params:n,record:i}=t.matchRouteFor(e.pathname,this.#i);if(!i)return{location:e,params:n,type:`unmatched`};if(i.redirect)return{location:e,params:n,redirectTo:l(i.redirect,this.#a,this.#e),type:`redirect`};let a=e.query,o=i.coerceSearch??this.#n;if(o)try{a=o(e.query)}catch(t){this.#C(t,{source:`coerce-search`}),a=e.query}await this.#_.hydrate(i);let s=this.#_.effectiveDefs(i);return{branch:r.buildMatchBranch(s,n,e.pathname,s.map(()=>void 0)),location:e,params:n,record:i,resolvedQuery:a,type:`matched`}}async#M(e,t,n,r,i){let a;try{for(;;){if(n.aborted||!r())return await e.return(void 0),a;let{done:o,value:s}=await e.next();if(o)return s??a;a=s,i(s,t)}}catch(t){throw await e.return(void 0).catch(()=>void 0),t}}async#N(e,n,i,a,o,s,c){if(!c())return;let l=this.#_.effectiveDefs(e),u=l.some(e=>e.dataFn!=null),f=l.map(()=>void 0);if(u){let o=t.buildPreloadKey(this.#e,e.path,a,i.query),u=this.#v.consume(o);if(u)f=u;else{let t=l.map(e=>e.dataFn?`loading`:`idle`);this.#d=r.createRouteState({location:i,matches:r.buildMatchBranch(l,a,i.pathname,f,t),status:`loading`}),this.#T();try{f=await this.#O(l,n,s,c,i,a)}catch(t){throw this.#d=r.createRouteState({error:t,location:i,matches:r.buildMatchBranch(l,a,i.pathname,f),status:`error`}),d(t,{routeName:e.leaf.name,source:`data-loader`}),t}}}c()&&(this.#d=r.createRouteState({location:i,matches:r.buildMatchBranch(l,a,i.pathname,f),status:`idle`}))}async#P(e,t){if((t??this.#s)&&typeof document<`u`){let t=document;if(t.startViewTransition){await t.startViewTransition(e).finished;return}}await e()}async#F(e,n=0){this.#l?.abort();let i=new AbortController;this.#l=i;let a=this.#d,o=()=>!i.signal.aborted&&!this.#f,s=t.readLocation(this.#e,this.#r),c=await this.#j(s);if(!o())return;if(c.type===`redirect`){await this.#R(c.redirectTo,!0,n);return}if(c.type===`unmatched`){if(this.#g){let t=[this.#g.leaf],n=r.buildMatchBranch(t,{},s.pathname,[void 0]),c=!1,l=s.query;if(this.#n)try{l=this.#n(s.query)}catch(e){this.#C(e,{source:`coerce-search`})}let u=async()=>{if(!o())return;let e=r.createRouteContext(s,l,{},n,(e,t)=>this.navigate(e,t));await r.executeMiddlewarePipeline(e,[...this.#t,...this.#g.ownMiddleware],async()=>{c=!0,await this.#N(this.#g,e,s,{},n,i.signal,o)})};try{await this.#P(u,e)}finally{o()&&c&&(this.#T(),this.#I(this.#d,a))}return}this.#d=r.createRouteState({location:c.location,matches:[],status:`idle`}),this.#T(),this.#I(this.#d,a);return}let{branch:l,location:u,params:d,record:f,resolvedQuery:p}=c,m=!1,h=async()=>{if(!o())return;let e=r.createRouteContext(u,p,d,l,(e,t)=>this.navigate(e,t));await r.executeMiddlewarePipeline(e,[...this.#t,...f.ownMiddleware],async()=>{m=!0,await this.#N(f,e,u,d,l,i.signal,o)})};try{await this.#P(h,e)}finally{o()&&m&&(this.#T(),this.#I(this.#d,a))}}#I(e,t){if(!this.#o||typeof window>`u`)return;let n=this.#o(e,t);if(n!==`preserve`){if(n===`top`){window.scrollTo(0,0);return}window.scrollTo(n.x,n.y)}}#L(e){let n=new URL(e,`http://localhost`),r=t.stripBase(n.pathname,this.#e);return`${t.joinPaths(this.#e,r)}${n.search}${n.hash}`}async#R(t,n=!0,r=0){if(r>=5)throw new e.WayfinderRedirectLoopError;let i=this.#L(t);this.#m=i,n?this.#r.replace(i):this.#r.push(i),await this.#F(void 0,r+1)}async#z(e,n={}){this.#b();let r=this.#L(e);if(!n.force&&r===this.#m)return;let a=this.#m,o=this.#d.matches.map(e=>e.name),s=new URL(r,`http://localhost`),c=t.stripBase(s.pathname,this.#e),{params:l,record:u}=t.matchRouteFor(c,this.#i),d={name:u?.leaf.name,params:l,pathname:c,query:t.parseQuery(s.search)};if(await i.runLeaveBlockers(this.#u,o,d)){this.#m=r,n.replace?this.#r.replace(r,n.state):this.#r.push(r,n.state);try{await this.#F(n.viewTransition)}catch(e){throw this.#m=a,e}}}};function h(e){return new m(e)}exports.createRouter=h;
2
2
  //# sourceMappingURL=router.cjs.map