@real-router/core 0.40.1 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/cjs/{Router-B-Pev7K2.d.ts → Router-DoJ3NWsT.d.ts} +1 -1
  2. package/dist/cjs/{RouterValidator-mx2Zooya.d.ts → RouterValidator-CaIeCVeB.d.ts} +1 -1
  3. package/dist/cjs/api.d.ts +1 -1
  4. package/dist/cjs/api.js +1 -1
  5. package/dist/cjs/api.js.map +1 -1
  6. package/dist/cjs/index.d.ts +3 -3
  7. package/dist/cjs/index.js +1 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/metafile-cjs.json +1 -1
  10. package/dist/cjs/utils.js +1 -1
  11. package/dist/cjs/utils.js.map +1 -1
  12. package/dist/cjs/validation.d.ts +4 -4
  13. package/dist/cjs/validation.js.map +1 -1
  14. package/dist/esm/{Router-B-Pev7K2.d.mts → Router-DoJ3NWsT.d.mts} +1 -1
  15. package/dist/esm/{RouterValidator-mx2Zooya.d.mts → RouterValidator-CaIeCVeB.d.mts} +1 -1
  16. package/dist/esm/api.d.mts +1 -1
  17. package/dist/esm/api.mjs +1 -1
  18. package/dist/esm/{chunk-5QXFUUDL.mjs → chunk-EPF2YSMX.mjs} +1 -1
  19. package/dist/esm/{chunk-5QXFUUDL.mjs.map → chunk-EPF2YSMX.mjs.map} +1 -1
  20. package/dist/esm/chunk-UPJLWPEL.mjs +1 -0
  21. package/dist/esm/chunk-UPJLWPEL.mjs.map +1 -0
  22. package/dist/esm/{chunk-QUUNDESP.mjs → chunk-UUG7DSTN.mjs} +1 -1
  23. package/dist/esm/chunk-UUG7DSTN.mjs.map +1 -0
  24. package/dist/esm/chunk-XQJDGUQE.mjs +1 -0
  25. package/dist/esm/chunk-XQJDGUQE.mjs.map +1 -0
  26. package/dist/esm/index.d.mts +3 -3
  27. package/dist/esm/index.mjs +1 -1
  28. package/dist/esm/metafile-esm.json +1 -1
  29. package/dist/esm/utils.mjs +1 -1
  30. package/dist/esm/validation.d.mts +4 -4
  31. package/dist/esm/validation.mjs +1 -1
  32. package/package.json +2 -2
  33. package/src/Router.ts +4 -6
  34. package/src/api/getPluginApi.ts +2 -3
  35. package/src/helpers.ts +0 -1
  36. package/src/index.ts +0 -1
  37. package/src/internals.ts +4 -5
  38. package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +0 -1
  39. package/src/namespaces/OptionsNamespace/helpers.ts +0 -1
  40. package/src/namespaces/RouterLifecycleNamespace/types.ts +1 -3
  41. package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +3 -3
  42. package/src/namespaces/RoutesNamespace/types.ts +2 -2
  43. package/src/namespaces/StateNamespace/StateNamespace.ts +30 -34
  44. package/src/namespaces/StateNamespace/helpers.ts +8 -27
  45. package/src/stateMetaStore.ts +15 -0
  46. package/src/transitionPath.ts +13 -16
  47. package/src/types/RouterValidator.ts +0 -1
  48. package/src/wiring/RouterWiringBuilder.ts +1 -1
  49. package/dist/esm/chunk-HHIXK5UM.mjs +0 -1
  50. package/dist/esm/chunk-HHIXK5UM.mjs.map +0 -1
  51. package/dist/esm/chunk-MNRZAE7T.mjs +0 -1
  52. package/dist/esm/chunk-MNRZAE7T.mjs.map +0 -1
  53. package/dist/esm/chunk-QUUNDESP.mjs.map +0 -1
@@ -1,5 +1,7 @@
1
1
  // packages/core/src/transitionPath.ts
2
2
 
3
+ import { getStateMetaParams } from "./stateMetaStore";
4
+
3
5
  import type { State } from "@real-router/types";
4
6
 
5
7
  /**
@@ -96,10 +98,11 @@ function isPrimitive(value: unknown): value is PrimitiveParam {
96
98
  */
97
99
  function segmentParamsEqual(
98
100
  name: string,
101
+ toMetaParams: Record<string, unknown>,
99
102
  toState: State,
100
103
  fromState: State,
101
104
  ): boolean {
102
- const keys = toState.meta?.params[name];
105
+ const keys = toMetaParams[name];
103
106
 
104
107
  if (!keys || typeof keys !== "object") {
105
108
  return true;
@@ -125,6 +128,7 @@ function segmentParamsEqual(
125
128
  * Finds the point where two state paths diverge based on segments and parameters.
126
129
  * Compares both segment names and their parameters to find the first difference.
127
130
  *
131
+ * @param toMetaParams - Cached meta.params from toState (avoids per-segment WeakMap lookup)
128
132
  * @param toState - Target state
129
133
  * @param fromState - Source state
130
134
  * @param toStateIds - Segment IDs for target state
@@ -133,6 +137,7 @@ function segmentParamsEqual(
133
137
  * @returns Index of first difference, or maxI if all checked segments match
134
138
  */
135
139
  function pointOfDifference(
140
+ toMetaParams: Record<string, unknown>,
136
141
  toState: State,
137
142
  fromState: State,
138
143
  toStateIds: string[],
@@ -148,7 +153,7 @@ function pointOfDifference(
148
153
  return i;
149
154
  }
150
155
 
151
- if (!segmentParamsEqual(toSegment, toState, fromState)) {
156
+ if (!segmentParamsEqual(toSegment, toMetaParams, toState, fromState)) {
152
157
  return i;
153
158
  }
154
159
  }
@@ -339,13 +344,12 @@ function computeTransitionPath(
339
344
  };
340
345
  }
341
346
 
342
- // ===== FAST PATH 3: Missing meta or meta.params requires full reload =====
343
- // Check if meta or meta.params is actually missing (not just empty)
344
- const toHasMeta = toState.meta?.params !== undefined;
345
- const fromHasMeta = fromState.meta?.params !== undefined;
347
+ // ===== FAST PATH 3: Missing meta requires full reload =====
348
+ // Single WeakMap lookup per state, reused in pointOfDifference/segmentParamsEqual
349
+ const toMetaParams = getStateMetaParams(toState);
350
+ const fromMetaParams = getStateMetaParams(fromState);
346
351
 
347
- if (!toHasMeta && !fromHasMeta) {
348
- // Both states missing meta.params - require full reload
352
+ if (!toMetaParams && !fromMetaParams) {
349
353
  return {
350
354
  intersection: EMPTY_INTERSECTION,
351
355
  toActivate: nameToIDs(toState.name),
@@ -354,14 +358,12 @@ function computeTransitionPath(
354
358
  }
355
359
 
356
360
  // ===== STANDARD PATH: Routes with parameters =====
357
- // Use original algorithm for complex cases with parameters
358
361
  const toStateIds = nameToIDs(toState.name);
359
362
  const fromStateIds = nameToIDs(fromState.name);
360
363
  const maxI = Math.min(fromStateIds.length, toStateIds.length);
361
364
 
362
- // Find where paths diverge based on segments and parameters
363
- // not obvious validate toState and fromState
364
365
  const i = pointOfDifference(
366
+ (toMetaParams ?? fromMetaParams) as Record<string, unknown>,
365
367
  toState,
366
368
  fromState,
367
369
  toStateIds,
@@ -402,12 +404,7 @@ function computeTransitionPath(
402
404
  export function getTransitionPath(
403
405
  toState: State,
404
406
  fromState?: State,
405
- reload?: boolean,
406
407
  ): TransitionPath {
407
- if (reload) {
408
- return computeTransitionPath(toState, fromState);
409
- }
410
-
411
408
  if (
412
409
  cached1Result !== null &&
413
410
  toState === cached1To &&
@@ -136,7 +136,6 @@ export interface RouterValidator {
136
136
  name: unknown,
137
137
  params: unknown,
138
138
  path: unknown,
139
- forceId: unknown,
140
139
  ) => void;
141
140
  validateAreStatesEqualArgs: (
142
141
  s1: unknown,
@@ -149,7 +149,7 @@ export class RouterWiringBuilder<
149
149
 
150
150
  const path = ctx.buildPath(name, params);
151
151
 
152
- return this.state.makeState(name, params, path, meta, undefined, true);
152
+ return this.state.makeState(name, params, path, meta, true);
153
153
  },
154
154
  resolveDefault: () => {
155
155
  const options = this.options.get();
@@ -1 +0,0 @@
1
- import{RouterError as t,errorCodes as e}from"./chunk-5QXFUUDL.mjs";import{getInternals as a}from"./chunk-QUUNDESP.mjs";function r(a){if(a())throw new t(e.ROUTER_DISPOSED)}function o(o){const s=a(o);return{makeState:(t,e,a,r,o)=>(s.validator?.state.validateMakeStateArgs(t,e,a,o),s.makeState(t,e,a,r?.params,o)),buildState:(t,e)=>{s.validator?.routes.validateStateBuilderArgs(t,e,"buildState");const{name:a,params:r}=s.forwardState(t,e);return s.buildStateResolved(a,r)},forwardState:(t,e)=>(s.validator?.routes.validateStateBuilderArgs(t,e,"forwardState"),s.forwardState(t,e)),matchPath:t=>(s.validator?.routes.validateMatchPathArgs(t),s.matchPath(t,s.getOptions())),setRootPath:t=>{r(s.isDisposed),s.validator?.routes.validateSetRootPathArgs(t),s.setRootPath(t)},getRootPath:s.getRootPath,addEventListener:(t,e)=>(r(s.isDisposed),s.validator?.eventBus.validateListenerArgs(t,e),s.addEventListener(t,e)),buildNavigationState:(t,e={})=>{s.validator?.routes.validateStateBuilderArgs(t,e,"buildNavigationState");const{name:a,params:r}=s.forwardState(t,e),o=s.buildStateResolved(a,r);if(o)return s.makeState(o.name,o.params,s.buildPath(o.name,o.params),o.meta)},getOptions:s.getOptions,getTree:s.getTree,addInterceptor:(t,e)=>{r(s.isDisposed),s.validator?.plugins.validateAddInterceptorArgs(t,e);let a=s.interceptors.get(t);return a||(a=[],s.interceptors.set(t,a)),a.push(e),()=>{const t=a.indexOf(e);-1!==t&&a.splice(t,1)}},getRouteConfig:t=>{const e=s.routeGetStore();if(e.matcher.hasRoute(t))return e.routeCustomFields[t]},extendRouter:a=>{r(s.isDisposed);const i=Object.keys(a);for(const a of i)if(a in o)throw new t(e.PLUGIN_CONFLICT,{message:`Cannot extend router: property "${a}" already exists`});for(const t of i)o[t]=a[t];const n={keys:i};s.routerExtensions.push(n);let d=!1;return()=>{if(d)return;d=!0;for(const t of n.keys)delete o[t];const t=s.routerExtensions.indexOf(n);-1!==t&&s.routerExtensions.splice(t,1)}}}}export{o as getPluginApi,r as throwIfDisposed};//# sourceMappingURL=chunk-HHIXK5UM.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/api/helpers.ts","../../src/api/getPluginApi.ts"],"names":[],"mappings":"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","file":"chunk-HHIXK5UM.mjs","sourcesContent":["// packages/core/src/api/helpers.ts\n\nimport { errorCodes } from \"../constants\";\nimport { RouterError } from \"../RouterError\";\n\nexport function throwIfDisposed(isDisposed: () => boolean): void {\n if (isDisposed()) {\n throw new RouterError(errorCodes.ROUTER_DISPOSED);\n }\n}\n","import { throwIfDisposed } from \"./helpers\";\nimport { errorCodes } from \"../constants\";\nimport { getInternals } from \"../internals\";\nimport { RouterError } from \"../RouterError\";\n\nimport type { PluginApi } from \"./types\";\nimport type { DefaultDependencies, Params, Router } from \"@real-router/types\";\n\nexport function getPluginApi<\n Dependencies extends DefaultDependencies = DefaultDependencies,\n>(router: Router<Dependencies>): PluginApi {\n const ctx = getInternals(router);\n\n return {\n makeState: (name, params, path, meta, forceId) => {\n ctx.validator?.state.validateMakeStateArgs(name, params, path, forceId);\n\n return ctx.makeState(\n name,\n params,\n path,\n meta?.params as\n | Record<string, Record<string, \"url\" | \"query\">>\n | undefined,\n forceId,\n );\n },\n buildState: (routeName, routeParams) => {\n ctx.validator?.routes.validateStateBuilderArgs(\n routeName,\n routeParams,\n \"buildState\",\n );\n\n const { name, params } = ctx.forwardState(routeName, routeParams);\n\n return ctx.buildStateResolved(name, params);\n },\n forwardState: <P extends Params = Params>(\n routeName: string,\n routeParams: P,\n ) => {\n ctx.validator?.routes.validateStateBuilderArgs(\n routeName,\n routeParams,\n \"forwardState\",\n );\n\n return ctx.forwardState(routeName, routeParams);\n },\n matchPath: (path) => {\n ctx.validator?.routes.validateMatchPathArgs(path);\n\n return ctx.matchPath(path, ctx.getOptions());\n },\n setRootPath: (rootPath) => {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.routes.validateSetRootPathArgs(rootPath);\n\n ctx.setRootPath(rootPath);\n },\n getRootPath: ctx.getRootPath,\n addEventListener: (eventName, cb) => {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.eventBus.validateListenerArgs(eventName, cb);\n\n return ctx.addEventListener(eventName, cb);\n },\n buildNavigationState: (name, params = {}) => {\n ctx.validator?.routes.validateStateBuilderArgs(\n name,\n params,\n \"buildNavigationState\",\n );\n\n const { name: resolvedName, params: resolvedParams } = ctx.forwardState(\n name,\n params,\n );\n const routeInfo = ctx.buildStateResolved(resolvedName, resolvedParams);\n\n if (!routeInfo) {\n return;\n }\n\n return ctx.makeState(\n routeInfo.name,\n routeInfo.params,\n ctx.buildPath(routeInfo.name, routeInfo.params),\n routeInfo.meta,\n );\n },\n getOptions: ctx.getOptions,\n getTree: ctx.getTree,\n addInterceptor: (method, fn) => {\n throwIfDisposed(ctx.isDisposed);\n ctx.validator?.plugins.validateAddInterceptorArgs(method, fn);\n let list = ctx.interceptors.get(method);\n\n if (!list) {\n list = [];\n ctx.interceptors.set(method, list);\n }\n\n list.push(fn);\n\n return () => {\n const index = list.indexOf(fn);\n\n if (index !== -1) {\n list.splice(index, 1);\n }\n };\n },\n getRouteConfig: (name) => {\n const store = ctx.routeGetStore();\n\n if (!store.matcher.hasRoute(name)) {\n return;\n }\n\n return store.routeCustomFields[name];\n },\n extendRouter: (extensions: Record<string, unknown>) => {\n throwIfDisposed(ctx.isDisposed);\n\n const keys = Object.keys(extensions);\n\n for (const key of keys) {\n if (key in router) {\n throw new RouterError(errorCodes.PLUGIN_CONFLICT, {\n message: `Cannot extend router: property \"${key}\" already exists`,\n });\n }\n }\n\n for (const key of keys) {\n (router as Record<string, unknown>)[key] = extensions[key];\n }\n\n const extensionRecord = { keys };\n\n ctx.routerExtensions.push(extensionRecord);\n\n let removed = false;\n\n return () => {\n if (removed) {\n return;\n }\n\n removed = true;\n\n for (const key of extensionRecord.keys) {\n delete (router as Record<string, unknown>)[key];\n }\n\n const idx = ctx.routerExtensions.indexOf(extensionRecord);\n\n if (idx !== -1) {\n ctx.routerExtensions.splice(idx, 1);\n }\n };\n },\n };\n}\n"]}
@@ -1 +0,0 @@
1
- import{plugins as t,events as e,RouterError as n,errorCodes as i,constants as s,createLimits as r,EMPTY_PARAMS as a,DEFAULT_LIMITS as o,freezeStateInPlace as c}from"./chunk-5QXFUUDL.mjs";import{registerInternals as u,createInterceptable as l,createInterceptable2 as h,getInternals as d}from"./chunk-QUUNDESP.mjs";import{logger as f}from"@real-router/logger";import{FSM as p}from"@real-router/fsm";function m(t,e,n=100){const i=new Set,s=[t];let r=t;for(;e[r];){const t=e[r];if(i.has(t)){const e=s.indexOf(t),n=[...s.slice(e),t];throw new Error(`Circular forwardTo: ${n.join(" → ")}`)}if(i.add(r),s.push(t),r=t,s.length>n)throw new Error(`forwardTo chain exceeds maximum depth (${n}): ${s.join(" → ")}`)}return r}var g={maxListeners:0,warnListeners:0,maxEventDepth:0},v=class extends Error{},S=class{#t=new Map;#e=null;#n=g;#i;#s;constructor(t){t?.limits&&(this.#n=t.limits),this.#i=t?.onListenerError??null,this.#s=t?.onListenerWarn??null}static validateCallback(t,e){if("function"!=typeof t)throw new TypeError(`Expected callback to be a function for event ${e}`)}setLimits(t){this.#n=t}on(t,e){const n=this.#r(t);if(n.has(e))throw new Error(`Duplicate listener for "${t}"`);const{maxListeners:i,warnListeners:s}=this.#n;if(0!==s&&n.size===s&&this.#s?.(t,s),0!==i&&n.size>=i)throw new Error(`Listener limit (${i}) reached for "${t}"`);return n.add(e),()=>{this.off(t,e)}}off(t,e){this.#t.get(t)?.delete(e)}emit(t,e,n,i,s){const r=this.#t.get(t);if(!r||0===r.size)return;const a=arguments.length-1;0!==this.#n.maxEventDepth?this.#a(r,t,a,e,n,i,s):this.#o(r,t,a,e,n,i,s)}clearAll(){this.#t.clear(),this.#e=null}listenerCount(t){return this.#t.get(t)?.size??0}#o(t,e,n,i,s,r,a){if(1===t.size){const[o]=t;try{this.#c(o,n,i,s,r,a)}catch(t){this.#i?.(e,t)}return}const o=[...t];for(const t of o)try{this.#c(t,n,i,s,r,a)}catch(t){this.#i?.(e,t)}}#c(t,e,n,i,s,r){switch(e){case 0:t();break;case 1:t(n);break;case 2:t(n,i);break;case 3:t(n,i,s);break;default:t(n,i,s,r)}}#a(t,e,n,i,s,r,a){this.#e??=new Map;const o=this.#e,c=o.get(e)??0;if(c>=this.#n.maxEventDepth)throw new v(`Maximum recursion depth (${this.#n.maxEventDepth}) exceeded for event: ${e}`);try{o.set(e,c+1);const u=1===t.size?t:[...t];for(const t of u)try{this.#c(t,n,i,s,r,a)}catch(t){if(t instanceof v)throw t;this.#i?.(e,t)}}finally{o.set(e,o.get(e)-1)}}#r(t){const e=this.#t.get(t);if(e)return e;const n=new Set;return this.#t.set(t,n),n}},y="IDLE",T="STARTING",w="READY",b="TRANSITIONING",N="DISPOSED",P="START",A="STARTED",O="NAVIGATE",E="COMPLETE",R="FAIL",C="CANCEL",D="STOP",F="DISPOSE",j={initial:y,context:null,transitions:{[y]:{[P]:T,[F]:N},[T]:{[A]:w,[R]:y},[w]:{[O]:b,[R]:w,[D]:y},[b]:{[O]:b,[E]:w,[C]:w,[R]:w},[N]:{}}};function L(t,e){for(const n of t){if(null===n||"object"!=typeof n||Array.isArray(n))throw new TypeError("route must be a non-array object");e?.routes.guardRouteCallbacks(n),e?.routes.guardNoAsyncCallbacks(n);const t=n.children;t&&L(t,e)}}var I={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0};function M(t){Object.freeze(t);for(const e of Object.keys(t)){const n=t[e];n&&"object"==typeof n&&n.constructor===Object&&M(n)}return t}function U(t,e){return"function"==typeof t?t(e):t}var $=class{#u;constructor(t={}){this.#u=M({...I,...t})}static validateOptionsIsObject(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("[router.constructor] options must be a plain object")}(t)}get(){return this.#u}};function B(t,e){return t===e||!(!Array.isArray(t)||!Array.isArray(e))&&t.length===e.length&&t.every((t,n)=>B(t,e[n]))}var _=class{#l=0;#h=void 0;#d=void 0;#f;#p=new Map;get(){return this.#h}set(t){this.#d=this.#h,this.#h=t?c(t):void 0}getPrevious(){return this.#d}reset(){this.#h=void 0,this.#d=void 0,this.#p.clear(),this.#l=0}setDependencies(t){this.#f=t}makeState(t,e,n,i,s,r){const o=i?{id:s??++this.#l,params:i}:void 0,u=this.#f.getDefaultParams();let l;l=Object.hasOwn(u,t)?{...u[t],...e}:e&&e!==a?{...e}:a;const h={name:t,params:l,path:n??this.#f.buildPath(t,e),meta:o};return r?h:c(h)}areStatesEqual(t,e,n=!0){if(!t||!e)return!!t==!!e;if(t.name!==e.name)return!1;if(n){const n=t.meta?.params??e.meta?.params;return(n?function(t){const e=[];for(const n in t){const i=t[n];for(const t in i)"url"===i[t]&&e.push(t)}return e}(n):this.#m(t.name)).every(n=>B(t.params[n],e.params[n]))}const i=Object.keys(t.params),s=Object.keys(e.params);return i.length===s.length&&i.every(n=>n in e.params&&B(t.params[n],e.params[n]))}#m(t){const e=this.#p.get(t);if(void 0!==e)return e;const n=this.#f.getUrlParams(t);return this.#p.set(t,n),n}},k={[t.ROUTER_START]:e.ROUTER_START,[t.ROUTER_STOP]:e.ROUTER_STOP,[t.TRANSITION_SUCCESS]:e.TRANSITION_SUCCESS,[t.TRANSITION_START]:e.TRANSITION_START,[t.TRANSITION_ERROR]:e.TRANSITION_ERROR,[t.TRANSITION_CANCEL]:e.TRANSITION_CANCEL},x=Object.keys(k),z="router.usePlugin",G=class t{#g=new Set;#v=new Set;#f;#S=o;#y=null;static validatePlugin(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("[router.usePlugin] Plugin factory must return an object, got "+typeof t);if("function"==typeof t.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.")}(t)}static validateNoDuplicatePlugins(t,e){for(const n of t)if(e(n))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setDependencies(t){this.#f=t}setLimits(t){this.#S=t,this.#S}setValidatorGetter(t){this.#y=t}count(){return this.#g.size}use(...t){if(this.#y?.()?.plugins.validateCountThresholds(this.#g.size+t.length),1===t.length){const e=t[0],n=this.#T(e);this.#g.add(e);let i=!1;const s=()=>{if(!i){i=!0,this.#g.delete(e),this.#v.delete(s);try{n()}catch(t){f.error(z,"Error during cleanup:",t)}}};return this.#v.add(s),s}const e=this.#w(t),n=[];try{for(const t of e){const e=this.#T(t);n.push({factory:t,cleanup:e})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){f.error(z,"Cleanup error:",t)}throw t}for(const{factory:t}of n)this.#g.add(t);let i=!1;const s=()=>{if(!i){i=!0,this.#v.delete(s);for(const{factory:t}of n)this.#g.delete(t);for(const{cleanup:t}of n)try{t()}catch(t){f.error(z,"Error during cleanup:",t)}}};return this.#v.add(s),s}getAll(){return[...this.#g]}has(t){return this.#g.has(t)}disposeAll(){for(const t of this.#v)t();this.#g.clear(),this.#v.clear()}#w(t){const e=new Set;for(const n of t)e.has(n)?this.#y?.()?.plugins.warnBatchDuplicates(t):e.add(n);return e}#T(e){const n=this.#f.compileFactory(e);t.validatePlugin(n),this.#y?.()?.plugins.validatePluginKeys(n),Object.freeze(n);const i=[];for(const t of x)t in n&&("function"==typeof n[t]?(i.push(this.#f.addEventListener(k[t],n[t])),"onStart"===t&&this.#f.canNavigate()&&this.#y?.()?.plugins.warnPluginAfterStart(t)):this.#y?.()?.plugins.warnPluginMethodType(t));return()=>{for(const t of i)t();"function"==typeof n.teardown&&n.teardown()}}},q=class{#b=new Map;#N=new Map;#P=new Map;#A=new Map;#O=[this.#P,this.#A];#E=new Set;#R=new Set;#C=new Set;#f;#S=o;#y=null;setDependencies(t){this.#f=t}setLimits(t){this.#S=t,this.#S}setValidatorGetter(t){this.#y=t}getHandlerCount(t){return"activate"===t?this.#N.size:this.#b.size}addCanActivate(t,e,n=!1){n?this.#R.add(t):this.#R.delete(t);const i=this.#N.has(t);this.#D("activate",t,e,this.#N,this.#A,"canActivate",i)}addCanDeactivate(t,e,n=!1){n?this.#C.add(t):this.#C.delete(t);const i=this.#b.has(t);this.#D("deactivate",t,e,this.#b,this.#P,"canDeactivate",i)}clearCanActivate(t){this.#N.delete(t),this.#A.delete(t),this.#R.delete(t)}clearCanDeactivate(t){this.#b.delete(t),this.#P.delete(t),this.#C.delete(t)}clearAll(){this.#N.clear(),this.#A.clear(),this.#b.clear(),this.#P.clear(),this.#R.clear(),this.#C.clear()}clearDefinitionGuards(){for(const t of this.#R)this.#N.delete(t),this.#A.delete(t);for(const t of this.#C)this.#b.delete(t),this.#P.delete(t);this.#R.clear(),this.#C.clear()}getFactories(){const t={},e={};for(const[e,n]of this.#b)t[e]=n;for(const[t,n]of this.#N)e[t]=n;return[t,e]}getFunctions(){return this.#O}canNavigateTo(t,e,n,i){for(const e of t)if(!this.#F(this.#P,e,n,i,"canNavigateTo"))return!1;for(const t of e)if(!this.#F(this.#A,t,n,i,"canNavigateTo"))return!1;return!0}#D(t,e,n,i,s,r,a){a?this.#y?.()?.lifecycle.warnOverwrite(e,t,r):this.#y?.()?.lifecycle.validateCountThresholds(i.size+1,r);const o="boolean"==typeof n?function(t){const e=()=>t;return()=>e}(n):n;i.set(e,o),this.#E.add(e);try{const t=this.#f.compileFactory(o);if("function"!=typeof t)throw new TypeError(`[router.${r}] Factory must return a function, got ${typeof t}`);s.set(e,t)}catch(t){throw i.delete(e),t}finally{this.#E.delete(e)}}#F(t,e,n,i,s){const r=t.get(e);if(!r)return!0;try{const t=r(n,i);return"boolean"==typeof t?t:(this.#y?.()?.lifecycle.warnAsyncGuardSync(e,s),!1)}catch{return!1}}};function W(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function Q(t){const e={name:t.name,path:t.path};return t.children&&(e.children=t.children.map(t=>Q(t))),e}function V(t,e,n=""){for(let i=0;i<t.length;i++){const s=t[i],r=n?`${n}.${s.name}`:s.name;if(r===e)return t.splice(i,1),!0;if(s.children&&e.startsWith(`${r}.`)&&V(s.children,e,r))return!0}return!1}function K(t,e){for(const n of Object.keys(t))e(n)&&delete t[n]}function H(t){return`(${t.replaceAll(/(^<|>$)/g,"")})`}var J=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,Y=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,X=/\?(.+)$/,Z=/[^\w!$'()*+,.:;|~-]/gu,tt=/[^\w!$'()*+,.:;|~-]/u,et={default:t=>tt.test(t)?t.replaceAll(Z,t=>encodeURIComponent(t)):t,uri:encodeURI,uriComponent:encodeURIComponent,none:t=>t},nt={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:t=>t};function it(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function st(t){return t.length>1&&t.endsWith("/")?t.slice(0,-1):t}function rt(t){const e={};if(0===t.length)return e;const n=t.split("&");for(const t of n){const n=t.indexOf("=");-1===n?e[t]="":e[t.slice(0,n)]=t.slice(n+1)}return e}function at(t){const e=[];for(const n of Object.keys(t)){const i=t[n],s=encodeURIComponent(n);e.push(""===i?s:`${s}=${encodeURIComponent(String(i))}`)}return e.join("&")}function ot(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function ct(t){let e=0;for(;e<t.length;)if("%"===t[e]){if(e+2>=t.length)return!1;const n=t.codePointAt(e+1)??0,i=t.codePointAt(e+2)??0;if(!ot(n)||!ot(i))return!1;e+=3}else e++;return!0}var ut=/<[^>]*>/g;function lt(t,e,n,i,s){const r=""===e.fullName;r||i.push(e);const a=e.absolute,o=e.paramMeta.pathPattern,c=a&&o.startsWith("~")?o.slice(1):o,u=(a?c:o).replaceAll(ut,""),l=a?u:(d=u,""===(h=n)?d:""===d?h:h+d);var h,d;let f=s;r||(f=function(t,e,n,i,s,r){const a=(g=i,st(n)===st(g)),o=Object.freeze([...s]),c=function(t){const e={};for(const n of t)e[n.fullName]=n.paramTypeMap;return Object.freeze(e)}(o),u=st(n),l=function(t,e){const n=[];t.length>0&&n.push(...t);for(const t of e)t.paramMeta.queryParams.length>0&&n.push(...t.paramMeta.queryParams);return n}(t.rootQueryParams,s),h=function(t){const e=new Map;for(const n of t)for(const[t,i]of n.paramMeta.constraintPatterns)e.set(t,i);return e}(s),d=a?st(i):u,{buildStaticParts:f,buildParamSlots:p}=function(t,e,n){const i=new Set,s=new Set;for(const t of e){for(const e of t.paramMeta.urlParams)i.add(e);for(const e of t.paramMeta.spatParams)s.add(e)}if(0===i.size)return{buildStaticParts:[t],buildParamSlots:[]};const r=[],a=[],o=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,u=0;for(;null!==(c=o.exec(t));){const e=c[1],i="?"===c[2];r.push(t.slice(u,c.index));const o=s.has(e);a.push({paramName:e,isOptional:i,encoder:o?t=>{const e=et[n],i=t.split("/");let s=e(i[0]);for(let t=1;t<i.length;t++)s+=`/${e(i[t])}`;return s}:et[n]}),u=c.index+c[0].length}return r.push(t.slice(u)),{buildStaticParts:r,buildParamSlots:a}}(d,a?s.slice(0,-1):s,t.options.urlParamsEncoding),m={name:e.fullName,parent:r,depth:s.length-1,matchSegments:o,meta:c,declaredQueryParams:l,declaredQueryParamsSet:new Set(l),hasTrailingSlash:n.length>1&&n.endsWith("/"),constraintPatterns:h,hasConstraints:h.size>0,buildStaticParts:f,buildParamSlots:p,buildParamNamesSet:new Set(p.map(t=>t.paramName))};var g;return t.routesByName.set(e.fullName,m),t.segmentsByName.set(e.fullName,o),t.metaByName.set(e.fullName,c),a?function(t,e,n){var i,s;i=e,(function(t,e,n){const i=st(n);if("/"===i||""===i)return e;let s=e,r=1;const a=i.length;for(;r<=a;){const e=i.indexOf("/",r),n=-1===e?a:e;if(n<=r)break;s=dt(t,s,i.slice(r,n)),r=n+1}return s}(s=t,s.root,n)).slashChildRoute=i;const r=st(n),a=t.options.caseSensitive?r:r.toLowerCase();t.staticCache.has(a)&&t.staticCache.set(a,e)}(t,m,i):function(t,e,n,i,s){if(function(t,e,n){const i=st(n);"/"!==i?ht(t,t.root,i,1,e):t.root.route=e}(t,e,n),0===s.paramMeta.urlParams.length){const n=t.options.caseSensitive?i:i.toLowerCase();t.staticCache.set(n,e)}}(t,m,n,u,e),m}(t,e,l,a?"":n,i,s));for(const n of e.children.values())lt(t,n,l,i,f);r||i.pop()}function ht(t,e,n,i,s){const r=n.length;for(;i<=r;){const a=n.indexOf("/",i),o=-1===a?r:a,c=n.slice(i,o);if(c.endsWith("?")){const i=c.slice(1).replaceAll(ut,"").replace(/\?$/,"");return e.paramChild??={node:it(),name:i},ht(t,e.paramChild.node,n,o+1,s),void(o>=r?e.route??=s:ht(t,e,n,o+1,s))}e=dt(t,e,c),i=o+1}e.route=s}function dt(t,e,n){if(n.startsWith("*")){const t=n.slice(1);return e.splatChild??={node:it(),name:t},e.splatChild.node}if(n.startsWith(":")){const t=n.slice(1).replaceAll(ut,"").replace(/\?$/,"");return e.paramChild??={node:it(),name:t},e.paramChild.node}const i=t.options.caseSensitive?n:n.toLowerCase();return i in e.staticChildren||(e.staticChildren[i]=it()),e.staticChildren[i]}var ft=/[\u0080-\uFFFF]/,pt=class{get options(){return this.#t}#t;#e=it();#s=new Map;#r=new Map;#n=new Map;#a=new Map;#i="";#j=[];constructor(t){this.#t={caseSensitive:t?.caseSensitive??!0,strictTrailingSlash:t?.strictTrailingSlash??!1,strictQueryParams:t?.strictQueryParams??!1,urlParamsEncoding:t?.urlParamsEncoding??"default",parseQueryString:t?.parseQueryString??rt,buildQueryString:t?.buildQueryString??at}}registerTree(t){this.#j=t.paramMeta.queryParams,lt({root:this.#e,options:this.#t,routesByName:this.#s,segmentsByName:this.#r,metaByName:this.#n,staticCache:this.#a,rootQueryParams:this.#j},t,"",[],null)}match(t){const e=this.#c(t);if(!e)return;const[n,i,s]=e,r=this.#t.caseSensitive?i:i.toLowerCase(),a=this.#a.get(r);if(a){if(this.#t.strictTrailingSlash&&!this.#o(n,a))return;return this.#L(a,{},s)}const o={},c=this.#I(i,o);return!c||this.#t.strictTrailingSlash&&!this.#o(n,c)||c.hasConstraints&&!this.#M(o,c)||!this.#U(o)?void 0:this.#L(c,o,s)}buildPath(t,e,n){const i=this.#s.get(t);if(!i)throw new Error(`[SegmentMatcher.buildPath] '${t}' is not defined`);i.hasConstraints&&e&&this.#$(i,t,e);const s=this.#B(i,e),r=this.#_(s,n?.trailingSlash),a=this.#k(i,e,n?.queryParamsMode);return r+(a?`?${a}`:"")}getSegmentsByName(t){return this.#r.get(t)}getMetaByName(t){return this.#n.get(t)}hasRoute(t){return this.#s.has(t)}setRootPath(t){this.#i=t}#$(t,e,n){for(const[i,s]of t.constraintPatterns){const t=n[i];if(null!=t){const n="object"==typeof t?JSON.stringify(t):String(t);if(!s.pattern.test(n))throw new Error(`[SegmentMatcher.buildPath] '${e}' — param '${i}' value '${n}' does not match constraint '${s.constraint}'`)}}}#B(t,e){const n=t.buildStaticParts,i=t.buildParamSlots;if(0===i.length)return this.#i+n[0];let s=this.#i+n[0];for(const[t,r]of i.entries()){const i=e?.[r.paramName];if(null==i){if(!r.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${r.paramName}'`);s.length>1&&s.endsWith("/")&&(s=s.slice(0,-1)),s+=n[t+1];continue}const a="object"==typeof i?JSON.stringify(i):String(i);s+=r.encoder(a)+n[t+1]}return s}#_(t,e){return"always"!==e||t.endsWith("/")?"never"===e&&"/"!==t&&t.endsWith("/")?t.slice(0,-1):t:`${t}/`}#k(t,e,n){if(!e)return"";const i={};let s=!1;for(const n of t.declaredQueryParams)n in e&&(i[n]=e[n],s=!0);if("loose"===n)for(const n in e)!Object.hasOwn(e,n)||t.declaredQueryParamsSet.has(n)||t.buildParamNamesSet.has(n)||(i[n]=e[n],s=!0);return s?this.#t.buildQueryString(i):""}#c(t){if(""===t&&(t="/"),!t.startsWith("/"))return;const e=t.indexOf("#");if(-1!==e&&(t=t.slice(0,e)),ft.test(t))return;if(this.#i.length>0){if(!t.startsWith(this.#i))return;t=t.slice(this.#i.length)||"/"}const n=t.indexOf("?"),i=-1===n?t:t.slice(0,n),s=-1===n?void 0:t.slice(n+1);return i.includes("//")?void 0:[i,st(i),s]}#L(t,e,n){if(void 0!==n){const i=this.#t.parseQueryString(n);if(this.#t.strictQueryParams){const e=t.declaredQueryParamsSet;for(const t of Object.keys(i))if(!e.has(t))return}for(const t of Object.keys(i))e[t]=i[t]}return{segments:t.matchSegments,params:e,meta:t.meta}}#o(t,e){return(t.length>1&&t.endsWith("/"))===e.hasTrailingSlash}#I(t,e){return 1===t.length?this.#e.slashChildRoute??this.#e.route:this.#x(this.#e,t,1,e)}#x(t,e,n,i){let s=t;const r=e.length;for(;n<=r;){const t=e.indexOf("/",n),a=-1===t?r:t,o=e.slice(n,a),c=this.#t.caseSensitive?o:o.toLowerCase();let u;if(c in s.staticChildren)u=s.staticChildren[c];else{if(!s.paramChild){if(s.splatChild){const t={},r=this.#x(s.splatChild.node,e,n,t);return r?(Object.assign(i,t),r):(i[s.splatChild.name]=e.slice(n),s.splatChild.node.route)}return}u=s.paramChild.node,i[s.paramChild.name]=o}s=u,n=a+1}return s.slashChildRoute??s.route}#U(t){const e=this.#t.urlParamsEncoding;if("none"===e)return!0;const n=nt[e];for(const e in t){const i=t[e];if(i.includes("%")){if(!ct(i))return!1;t[e]=n(i)}}return!0}#M(t,e){for(const[n,i]of e.constraintPatterns)if(!i.pattern.test(t[n]))return!1;return!0}},mt=t=>{const e=t.indexOf("%"),n=t.indexOf("+");if(-1===e&&-1===n)return t;const i=-1===n?t:t.split("+").join(" ");return-1===e?i:decodeURIComponent(i)},gt=t=>{const e=typeof t;if("string"!==e&&"number"!==e&&"boolean"!==e)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===e&&null===t?"null":e}`);return encodeURIComponent(t)},vt={none:{encodeArray:(t,e)=>e.map(e=>`${t}=${gt(e)}`).join("&")},brackets:{encodeArray:(t,e)=>e.map(e=>`${t}[]=${gt(e)}`).join("&")},index:{encodeArray:(t,e)=>e.map((e,n)=>`${t}[${n}]=${gt(e)}`).join("&")},comma:{encodeArray:(t,e)=>`${t}=${e.map(t=>gt(t)).join(",")}`}},St={none:{encode:(t,e)=>`${t}=${e}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:t=>t},string:{encode:(t,e)=>`${t}=${e}`,decodeUndefined:()=>null,decodeRaw:t=>"true"===t||"false"!==t&&null,decodeValue:t=>t},"empty-true":{encode:(t,e)=>e?t:`${t}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:t=>t}},yt={default:{encode:t=>t},hidden:{encode:()=>""}},Tt=(t,e,n)=>({boolean:St[e],null:yt[n],array:vt[t]}),wt={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:St.none,null:yt.default,array:vt.none}},bt=t=>{if(!t||void 0===t.arrayFormat&&void 0===t.booleanFormat&&void 0===t.nullFormat)return wt;const e=t.arrayFormat??"none",n=t.booleanFormat??"none",i=t.nullFormat??"default";return{arrayFormat:e,booleanFormat:n,nullFormat:i,strategies:Tt(e,n,i)}},Nt=t=>encodeURIComponent(t),Pt=(t,e,n)=>{const i=Nt(t);switch(typeof e){case"string":case"number":default:return`${i}=${Nt(e)}`;case"boolean":return n.strategies.boolean.encode(i,e);case"object":return null===e?n.strategies.null.encode(i):Array.isArray(e)?n.strategies.array.encodeArray(i,e):`${i}=${Nt(e)}`}};function At(t,e,n,i,s){const r=t.indexOf("=",e),a=-1!==r&&r<n,o=t.slice(e,a?r:n),{name:c,hasBrackets:u}=function(t){const e=t.indexOf("[");return-1===e?{name:t,hasBrackets:!1}:{name:t.slice(0,e),hasBrackets:!0}}(o);var l,h,d,f,p;!function(t,e,n,i){const s=t[e];void 0===s?t[e]=i?[n]:n:Array.isArray(s)?s.push(n):t[e]=[s,n]}(i,mt(c),(l=t,h=r,d=n,f=a,p=s,p?((t,e)=>{if(void 0===t)return e.boolean.decodeUndefined();const n=e.boolean.decodeRaw(t);if(null!==n)return n;const i=mt(t);return e.boolean.decodeValue(i)})(f?l.slice(h+1,d):void 0,p):f?mt(l.slice(h+1,d)):null),u)}function Ot(t,e){const n=t.path,i=n.startsWith("~"),s=i?n.slice(1):n,r={name:t.name,path:s,absolute:i,children:[],parent:e,nonAbsoluteChildren:[],fullName:""};if(t.children)for(const e of t.children){const t=Ot(e,r);r.children.push(t)}return r}function Et(t,e){return t.endsWith("/")&&e.startsWith("/")?t+e.slice(1):t+e}function Rt(t){const e=new Map;for(const n of t)e.set(n.name,n);return e}function Ct(t,e,n){const i=function(t){const e=[],n=[],i=[],s={},r=new Map,a=t.replaceAll(Y,"$1"),o=X.exec(a);if(null!==o){const e=o[1].split("&");for(const t of e){const e=t.trim();e.length>0&&(n.push(e),s[e]="query")}t=t.slice(0,o.index)}let c;for(;null!==(c=J.exec(t));){const t=c[2],n=c[3];if("*"===c[1])i.push(t),e.push(t),s[t]="url";else if(e.push(t),s[t]="url",n){const e=`^${H(n)}$`;r.set(t,{pattern:new RegExp(e),constraint:n})}}return{urlParams:e,queryParams:n,spatParams:i,paramTypeMap:s,constraintPatterns:r,pathPattern:t}}(t.path),s=function(t){const e={};for(const n of t.urlParams)e[n]="url";for(const n of t.queryParams)e[n]="query";return e}(i),r={name:t.name,path:t.path,absolute:t.absolute,parent:e,children:void 0,paramMeta:i,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:s};var a;r.fullName=(a=r,a.parent?.name?`${a.parent.fullName}.${a.name}`:a.name);const{childrenMap:o,nonAbsoluteChildren:c}=function(t,e,n){const i=[],s=[];for(const r of t){const t=Ct(r,e,n);i.push(t),t.absolute||s.push(t)}return{childrenMap:Rt(i),nonAbsoluteChildren:s}}(t.children,r,n);return r.children=o,r.nonAbsoluteChildren=c,r.staticPath=function(t){if(!t.path)return null;const{urlParams:e,queryParams:n,spatParams:i}=t.paramMeta;if(e.length>0||n.length>0||i.length>0)return null;const s=[];let r=t.parent;for(;r?.path;)s.unshift(r),r=r.parent;let a="";for(const t of s){const{urlParams:e,queryParams:n,spatParams:i}=t.paramMeta;if(e.length>0||n.length>0||i.length>0)return null;a=t.absolute?t.path:Et(a,t.path)}return t.absolute?t.path:Et(a,t.path)}(r),n&&(Object.freeze(c),Object.freeze(s),Object.freeze(r.children),Object.freeze(r)),r}function Dt(t,e,n,i){return function(t,e){const n=[];return{add(t){return n.push(t),this},addMany(t){return n.push(...t),this},build:i=>function(t,e=!0){return Ct(t,null,e)}(function(t,e,n){const i=Ot({name:t,path:e},null);for(const t of n){const e=Ot(t,i);i.children.push(e)}return i}(t,e,n),!i?.skipFreeze)}}(t,e).addMany(n).build(i)}function Ft(t){const e={name:t.name,path:t.absolute?`~${t.path}`:t.path};return t.children.size>0&&(e.children=[...t.children.values()].map(t=>Ft(t))),e}function jt(t){return[...t.children.values()].map(t=>Ft(t))}function Lt(t){const e=t?.queryParams;return new pt({...void 0===t?.caseSensitive?void 0:{caseSensitive:t.caseSensitive},...void 0===t?.strictTrailingSlash?void 0:{strictTrailingSlash:t.strictTrailingSlash},...void 0===t?.strictQueryParams?void 0:{strictQueryParams:t.strictQueryParams},...void 0===t?.urlParamsEncoding?void 0:{urlParamsEncoding:t.urlParamsEncoding},parseQueryString:t=>((t,e)=>{const n=(t=>{const e=t.indexOf("?");return-1===e?t:t.slice(e+1)})(t);if(""===n||"?"===n)return{};if(!e)return function(t){const e={};return function(t,e){let n=0;const i=t.length;for(;n<i;){let s=t.indexOf("&",n);-1===s&&(s=i),At(t,n,s,e),n=s+1}}(t,e),e}(n);const i=bt(e),s={};let r=0;const a=n.length;for(;r<a;){let t=n.indexOf("&",r);-1===t&&(t=a),At(n,r,t,s,i.strategies),r=t+1}return s})(t,e),buildQueryString:t=>((t,e)=>{const n=Object.keys(t);if(0===n.length)return"";const i=bt(e),s=[];for(const e of n){const n=t[e];if(void 0===n)continue;const r=Pt(e,n,i);r&&s.push(r)}return s.join("&")})(t,e)})}function It(t,e,n){const i=Dt("",e,t),s=Lt(n);return s.registerTree(i),{tree:i,matcher:s}}function Mt(t){const e=It(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher,t.resolvedForwardMap=_t(t.config)}function Ut(t){const e=It(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher}function $t(t){Bt(t),Ut(t)}function Bt(t){t.definitions.length=0,Object.assign(t.config,W()),t.resolvedForwardMap=Object.create(null),t.routeCustomFields=Object.create(null)}function _t(t){const e=Object.create(null);for(const n of Object.keys(t.forwardMap))e[n]=m(n,t.forwardMap);return e}function kt(t,e,n,i,s,r,a){const o=new Set(["name","path","children","canActivate","canDeactivate","forwardTo","encodeParams","decodeParams","defaultParams"]),c=Object.fromEntries(Object.entries(t).filter(([t])=>!o.has(t)));Object.keys(c).length>0&&(i[e]=c),t.canActivate&&(a?a.addActivateGuard(e,t.canActivate):s.set(e,t.canActivate)),t.canDeactivate&&(a?a.addDeactivateGuard(e,t.canDeactivate):r.set(e,t.canDeactivate)),t.forwardTo&&function(t,e,n){if(t.canActivate&&f.warn("real-router",`Route "${e}" has both forwardTo and canActivate. canActivate will be ignored because forwardTo creates a redirect (industry standard). Move canActivate to the target route "${"string"==typeof t.forwardTo?t.forwardTo:"[dynamic]"}".`),t.canDeactivate&&f.warn("real-router",`Route "${e}" has both forwardTo and canDeactivate. canDeactivate will be ignored because forwardTo creates a redirect (industry standard). Move canDeactivate to the target route "${"string"==typeof t.forwardTo?t.forwardTo:"[dynamic]"}".`),"function"==typeof t.forwardTo){const n="AsyncFunction"===t.forwardTo.constructor.name,i=t.forwardTo.toString().includes("__awaiter");if(n||i)throw new TypeError(`forwardTo callback cannot be async for route "${e}". Async functions break matchPath/buildPath.`)}"string"==typeof t.forwardTo?n.forwardMap[e]=t.forwardTo:n.forwardFnMap[e]=t.forwardTo}(t,e,n),t.decodeParams&&(n.decoders[e]=e=>t.decodeParams?.(e)??e),t.encodeParams&&(n.encoders[e]=e=>t.encodeParams?.(e)??e),t.defaultParams&&(n.defaultParams[e]=t.defaultParams)}function xt(t,e,n,i,s,r,a=""){for(const o of t){const t=a?`${a}.${o.name}`:o.name;kt(o,t,e,n,i,s,r),o.children&&xt(o.children,e,n,i,s,r,t)}}var zt=".",Gt=[];function qt(t){const e=[];for(let n=t.length-1;n>=0;n--)e.push(t[n]);return e}function Wt(t){const e=typeof t;return"string"===e||"number"===e||"boolean"===e}function Qt(t,e,n){const i=e.meta?.params[t];if(!i||"object"!=typeof i)return!0;for(const t of Object.keys(i)){const i=e.params[t],s=n.params[t];if(Wt(i)&&Wt(s)&&String(i)!==String(s))return!1}return!0}Object.freeze(Gt);var Vt,Kt,Ht=new Map;function Jt(t){const e=Ht.get(t);if(e)return e;const n=function(t){if(!t)return[""];const e=t.indexOf(zt);if(-1===e)return[t];const n=t.indexOf(zt,e+1);if(-1===n)return[t.slice(0,e),t];const i=t.indexOf(zt,n+1);if(-1===i)return[t.slice(0,e),t.slice(0,n),t];return-1===t.indexOf(zt,i+1)?[t.slice(0,e),t.slice(0,n),t.slice(0,i),t]:function(t){const e=t.split(zt),n=e.length,i=[e[0]];let s=e[0].length;for(let r=1;r<n-1;r++)s+=1+e[r].length,i.push(t.slice(0,s));return i.push(t),i}(t)}(t);return Object.freeze(n),Ht.set(t,n),n}var Yt,Xt,Zt=null,te=null;function ee(t,e){if(!e)return{intersection:"",toActivate:Jt(t.name),toDeactivate:Gt};if(void 0===t.meta?.params&&void 0===e.meta?.params)return{intersection:"",toActivate:Jt(t.name),toDeactivate:qt(Jt(e.name))};const n=Jt(t.name),i=Jt(e.name),s=function(t,e,n,i,s){for(let r=0;r<s;r++){const s=n[r];if(s!==i[r])return r;if(!Qt(s,t,e))return r}return s}(t,e,n,i,Math.min(i.length,n.length));let r;if(s>=i.length)r=Gt;else if(0===s&&1===i.length)r=i;else{r=[];for(let t=i.length-1;t>=s;t--)r.push(i[t])}const a=0===s?n:n.slice(s);return{intersection:s>0?i[s-1]:"",toDeactivate:r,toActivate:a}}function ne(t,e,n){if(n)return ee(t,e);if(null!==Zt&&t===Vt&&e===Kt)return Zt;if(null!==te&&t===Yt&&e===Xt)return te;const i=ee(t,e);return Yt=Vt,Xt=Kt,te=Zt,Vt=t,Kt=e,Zt=i,i}function ie(t,e){var n;return{name:e??(n=t.segments,n.at(-1)?.fullName??""),params:t.params,meta:t.meta}}var se=class{#z;#G;get#f(){return this.#z.depsStore}constructor(t=[],e){this.#z=function(t,e){const n=[],i=W(),s=Object.create(null),r=new Map,a=new Map;for(const e of t)n.push(Q(e));const{tree:o,matcher:c}=It(n,"",e);return xt(t,i,s,r,a,void 0,""),{definitions:n,config:i,tree:o,matcher:c,resolvedForwardMap:_t(i),routeCustomFields:s,rootPath:"",matcherOptions:e,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:r,pendingCanDeactivate:a,treeOperations:{commitTreeChanges:Mt,resetStore:$t,nodeToDefinition:Ft}}}(t,e)}static shouldUpdateNode(t){return(e,n)=>{if(!e||"object"!=typeof e||!("name"in e))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(e.transition?.reload)return!0;if(""===t&&!n)return!0;const{intersection:i,toActivate:s,toDeactivate:r}=ne(e,n);return t===i||!!s.includes(t)||r.includes(t)}}setDependencies(t){this.#z.depsStore=t;for(const[e,n]of this.#z.pendingCanActivate)t.addActivateGuard(e,n);this.#z.pendingCanActivate.clear();for(const[e,n]of this.#z.pendingCanDeactivate)t.addDeactivateGuard(e,n);this.#z.pendingCanDeactivate.clear()}setLifecycleNamespace(t){this.#z.lifecycleNamespace=t}setRootPath(t){this.#z.rootPath=t,Ut(this.#z)}hasRoute(t){return this.#z.matcher.hasRoute(t)}clearRoutes(){$t(this.#z)}buildPath(t,e,n){if(t===s.UNKNOWN_ROUTE)return"string"==typeof e?.path?e.path:"";const i=Object.hasOwn(this.#z.config.defaultParams,t)?{...this.#z.config.defaultParams[t],...e}:e??{},r="function"==typeof this.#z.config.encoders[t]?this.#z.config.encoders[t]({...i}):i;return this.#z.matcher.buildPath(t,r,this.#q(n))}matchPath(t,e){const n=e,i=this.#z.matcher.match(t);if(!i)return;const s=ie(i),{name:r,params:a,meta:o}=s,c="function"==typeof this.#z.config.decoders[r]?this.#z.config.decoders[r](a):a,{name:u,params:l}=this.#f.forwardState(r,c);let h=t;if(n.rewritePathOnMatch){const t="function"==typeof this.#z.config.encoders[u]?this.#z.config.encoders[u]({...l}):l,e=n.trailingSlash;h=this.#z.matcher.buildPath(u,t,{trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:n.queryParamsMode})}return this.#f.makeState(u,l,h,o)}forwardState(t,e){if(Object.hasOwn(this.#z.config.forwardFnMap,t)){const n=this.#W(t,e),i=this.#z.config.forwardFnMap[t],s=this.#Q(t,i,e);return{name:s,params:this.#W(s,n)}}const n=this.#z.resolvedForwardMap[t]??t;if(n!==t&&Object.hasOwn(this.#z.config.forwardFnMap,n)){const i=this.#W(t,e),s=this.#z.config.forwardFnMap[n],r=this.#Q(n,s,e);return{name:r,params:this.#W(r,i)}}if(n!==t){const i=this.#W(t,e);return{name:n,params:this.#W(n,i)}}return{name:t,params:this.#W(t,e)}}buildStateResolved(t,e){const n=this.#z.matcher.getSegmentsByName(t);if(n)return ie({segments:n,params:e,meta:this.#z.matcher.getMetaByName(t)},t)}isActiveRoute(t,e={},n=!1,i=!0){const s=this.#f.getState();if(!s)return!1;const r=s.name;if(r!==t&&!r.startsWith(`${t}.`)&&!t.startsWith(`${r}.`))return!1;const a=this.#z.config.defaultParams[t];if(n||r===t){const n=a?{...a,...e}:e;return this.#f.areStatesEqual({name:t,params:n,path:""},s,i)}const o=s.params;return!!function(t,e){for(const n in t)if(t[n]!==e[n])return!1;return!0}(e,o)&&(!a||function(t,e,n){for(const i in t)if(!(i in n)&&t[i]!==e[i])return!1;return!0}(a,o,e))}getMetaForState(t){return this.#z.matcher.hasRoute(t)?this.#z.matcher.getMetaByName(t):void 0}getUrlParams(t){const e=this.#z.matcher.getSegmentsByName(t);return e?function(t){const e=[];for(const n of t)for(const t of n.paramMeta.urlParams)e.push(t);return e}(e):[]}getStore(){return this.#z}#W(t,e){return Object.hasOwn(this.#z.config.defaultParams,t)?{...this.#z.config.defaultParams[t],...e}:e}#q(t){if(this.#G)return this.#G;const e=t?.trailingSlash;return this.#G=Object.freeze({trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:t?.queryParamsMode}),this.#G}#Q(t,e,n){const i=new Set([t]);let s=e(this.#f.getDependency,n),r=0;if("string"!=typeof s)throw new TypeError("forwardTo callback must return a string, got "+typeof s);for(;r<100;){if(void 0===this.#z.matcher.getSegmentsByName(s))throw new Error(`Route "${s}" does not exist`);if(i.has(s)){const t=[...i,s].join(" → ");throw new Error(`Circular forwardTo detected: ${t}`)}if(i.add(s),Object.hasOwn(this.#z.config.forwardFnMap,s)){s=(0,this.#z.config.forwardFnMap[s])(this.#f.getDependency,n),r++;continue}const t=this.#z.config.forwardMap[s];if(void 0===t)return s;s=t,r++}throw new Error("forwardTo exceeds maximum depth of 100")}},re=new n(i.ROUTER_NOT_STARTED),ae=new n(i.ROUTE_NOT_FOUND),oe=new n(i.SAME_STATES),ce=Promise.reject(re),ue=Promise.reject(ae),le=Promise.reject(oe);function he(t,e){const{toState:r,fromState:a,opts:o,toDeactivate:u,toActivate:l,intersection:h}=e;if(r.name!==s.UNKNOWN_ROUTE&&!t.hasRoute(r.name)){const e=new n(i.ROUTE_NOT_FOUND,{routeName:r.name});throw t.sendTransitionFail(r,a,e),e}if(a)for(const n of u)!l.includes(n)&&e.canDeactivateFunctions.has(n)&&t.clearCanDeactivate(n);r.transition=function(t,e,n,i,s){const r={phase:"activating",reason:"success",segments:{deactivated:n,activated:i,intersection:s}};return void 0!==t?.name&&(r.from=t.name),void 0!==e.reload&&(r.reload=e.reload),void 0!==e.redirected&&(r.redirected=e.redirected),r}(a,o,u,l,h);const d=c(r);t.setState(d);const f=void 0===o.signal?o:function({signal:t,...e}){return e}(o);return t.sendTransitionDone(d,a,f),d}function de(t,e,n,s){e.code!==i.TRANSITION_CANCELLED&&e.code!==i.ROUTE_NOT_FOUND&&t.sendTransitionFail(n,s,e)}function fe(t,e,s){if(t instanceof DOMException&&"AbortError"===t.name)throw new n(i.TRANSITION_CANCELLED);!function(t,e,i){if(t instanceof n)throw t.setCode(e),t;throw new n(e,function(t,e){const n={segment:e};if(t instanceof Error)return{...n,message:t.message,stack:t.stack,..."cause"in t&&void 0!==t.cause&&{cause:t.cause}};if(t&&"object"==typeof t){const e={};for(const[n,i]of Object.entries(t))pe.has(n)||(e[n]=i);return{...n,...e}}return n}(t,i))}(t,e,s)}ce.catch(()=>{}),ue.catch(()=>{}),le.catch(()=>{});var pe=new Set(["code","segment","path","redirect"]);async function me(t,e,i){let s;try{s=await t}catch(t){return void fe(t,e,i)}if(!s)throw new n(e,{segment:i})}async function ge(t,e,s,r,a,o,c,u,l,h){await me(l,s,h);for(let l=u;l<e.length;l++){if(!c())throw new n(i.TRANSITION_CANCELLED);const u=e[l],h=t.get(u);if(!h)continue;let d=!1;try{d=h(r,a,o)}catch(t){fe(t,s,u)}if(d instanceof Promise)await me(d,s,u);else if(!d)throw new n(s,{segment:u})}}function ve(t,e,s,r,a,o,c){for(const[u,l]of e.entries()){if(!c())throw new n(i.TRANSITION_CANCELLED);const h=t.get(l);if(!h)continue;let d=!1;try{d=h(r,a,o)}catch(t){fe(t,s,l)}if(d instanceof Promise)return ge(t,e,s,r,a,o,c,u+1,d,l);if(!d)throw new n(s,{segment:l})}}var Se=[s.UNKNOWN_ROUTE];Object.freeze(Se);var ye={replace:!0};Object.freeze(ye);var Te=class{lastSyncResolved=!1;lastSyncRejected=!1;#f;#V=null;#K=0;setDependencies(t){this.#f=t}navigate(t,e,r){this.lastSyncResolved=!1;const a=this.#f;if(!a.canNavigate())return this.lastSyncRejected=!0,ce;let o,c,u=!1,l=null;try{if(o=a.buildNavigateState(t,e),!o)return a.emitTransitionError(void 0,a.getState(),ae),this.lastSyncRejected=!0,ue;if(c=a.getState(),r=function(t,e){return e?.name!==s.UNKNOWN_ROUTE||t.replace?t:{...t,replace:!0}}(r,c),function(t,e,n){return!!t&&!e.reload&&!e.force&&t.path===n.path}(c,r,o))return a.emitTransitionError(o,c,oe),this.lastSyncRejected=!0,le;if(this.#H(),r.signal?.aborted)throw new n(i.TRANSITION_CANCELLED,{reason:r.signal.reason});const h=++this.#K;if(a.startTransition(o,c),u=!0,this.#K!==h)throw new n(i.TRANSITION_CANCELLED);const[d,f]=a.getLifecycleFunctions(),p=o.name===s.UNKNOWN_ROUTE,{toDeactivate:m,toActivate:g,intersection:v}=ne(o,c,r.reload),S=c&&!r.forceDeactivate&&m.length>0,y=!p&&g.length>0;if(d.size>0||f.size>0){l=new AbortController,this.#V=l;const t=()=>this.#K===h&&a.isActive(),e=function(t,e,s,r,a,o,c,u,l,h){if(a){const a=ve(t,s,i.CANNOT_DEACTIVATE,c,u,l,h);if(void 0!==a)return async function(t,e,s,r,a,o,c,u){if(await t,!u())throw new n(i.TRANSITION_CANCELLED);if(r){const t=ve(e,s,i.CANNOT_ACTIVATE,a,o,c,u);if(void 0!==t&&await t,!u())throw new n(i.TRANSITION_CANCELLED)}}(a,e,r,o,c,u,l,h)}if(!h())throw new n(i.TRANSITION_CANCELLED);if(o)return ve(e,r,i.CANNOT_ACTIVATE,c,u,l,h)}(d,f,m,g,!!S,y,o,c,l.signal,t);if(void 0!==e)return this.#J(e,{toState:o,fromState:c,opts:r,toDeactivate:m,toActivate:g,intersection:v,canDeactivateFunctions:d},l,h);if(!t())throw new n(i.TRANSITION_CANCELLED);this.#Y(l)}return this.lastSyncResolved=!0,Promise.resolve(he(a,{toState:o,fromState:c,opts:r,toDeactivate:m,toActivate:g,intersection:v,canDeactivateFunctions:d}))}catch(t){return this.#X(t,l,u,o,c),Promise.reject(t)}}navigateToDefault(t){const e=this.#f;if(!e.getOptions().defaultRoute)return Promise.reject(new n(i.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"}));const{route:s,params:r}=e.resolveDefault();return s?this.navigate(s,r,t):Promise.reject(new n(i.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"}))}navigateToNotFound(t){this.#H();const e=this.#f.getState(),n=e?Jt(e.name).toReversed():[];Object.freeze(n);const i={deactivated:n,activated:Se,intersection:""};Object.freeze(i);const r={phase:"activating",...e&&{from:e.name},reason:"success",segments:i};Object.freeze(r);const a={name:s.UNKNOWN_ROUTE,params:{},path:t,transition:r};return Object.freeze(a),this.#f.setState(a),this.#f.emitTransitionSuccess(a,e,ye),a}abortCurrentNavigation(){this.#V?.abort(new n(i.TRANSITION_CANCELLED)),this.#V=null}async#J(t,e,s,r){const a=this.#f,o=()=>this.#K===r&&!s.signal.aborted&&a.isActive();try{if(e.opts.signal){if(e.opts.signal.aborted)throw new n(i.TRANSITION_CANCELLED,{reason:e.opts.signal.reason});e.opts.signal.addEventListener("abort",()=>{s.abort(e.opts.signal?.reason)},{once:!0,signal:s.signal})}if(await t,!o())throw new n(i.TRANSITION_CANCELLED);return he(a,e)}catch(t){throw de(a,t,e.toState,e.fromState),t}finally{this.#Y(s)}}#X(t,e,n,i,s){e&&this.#Y(e),n&&i&&de(this.#f,t,i,s)}#Y(t){t.abort(),this.#V===t&&(this.#V=null)}#H(){this.#f.isTransitioning()&&(f.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use cloneRouter() to create isolated instance per request."),this.#V?.abort(new n(i.TRANSITION_CANCELLED)),this.#f.cancelNavigation())}},we={replace:!0};Object.freeze(we);var be=class{#f;setDependencies(t){this.#f=t}async start(t){const e=this.#f,s=e.getOptions(),r=e.matchPath(t);if(!r&&!s.allowNotFound){const s=new n(i.ROUTE_NOT_FOUND,{path:t});throw e.emitTransitionError(void 0,void 0,s),s}return e.completeStart(),r?e.navigate(r.name,r.params,we):e.navigateToNotFound(t)}stop(){this.#f.clearState()}},Ne=class{#Z;#tt;#et;#nt;#it;#st;constructor(t){this.#Z=t.routerFSM,this.#tt=t.emitter,this.#et=void 0,this.#rt()}static validateSubscribeListener(t){if("function"!=typeof t)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#tt.emit(e.ROUTER_START)}emitRouterStop(){this.#tt.emit(e.ROUTER_STOP)}emitTransitionStart(t,n){this.#tt.emit(e.TRANSITION_START,t,n)}emitTransitionSuccess(t,n,i){this.#tt.emit(e.TRANSITION_SUCCESS,t,n,i)}emitTransitionError(t,n,i){this.#tt.emit(e.TRANSITION_ERROR,t,n,i)}emitTransitionCancel(t,n){this.#tt.emit(e.TRANSITION_CANCEL,t,n)}sendStart(){this.#Z.send(P)}sendStop(){this.#Z.send(D)}sendDispose(){this.#Z.send(F)}sendStarted(){this.#Z.send(A)}sendNavigate(t,e){this.#et=t,this.#Z.forceState(b),this.emitTransitionStart(t,e)}sendComplete(t,e,n={}){this.#Z.forceState(w),this.emitTransitionSuccess(t,e,n),this.#et===t&&(this.#et=void 0)}sendFail(t,e,n){const i=this.#et;this.#nt=t,this.#it=e,this.#st=n,this.#Z.send(R),this.#et===i&&(this.#et=void 0)}sendFailSafe(t,e,n){this.isReady()?this.sendFail(t,e,n):this.emitTransitionError(t,e,n)}sendCancel(t,e){const n=this.#et;this.#nt=t,this.#it=e,this.#Z.send(C),this.#et===n&&(this.#et=void 0)}canBeginTransition(){return this.#Z.canSend(O)}canStart(){return this.#Z.canSend(P)}canCancel(){return this.#Z.canSend(C)}isActive(){const t=this.#Z.getState();return t!==y&&t!==N}isDisposed(){return this.#Z.getState()===N}isTransitioning(){return this.#Z.getState()===b}isReady(){return this.#Z.getState()===w}getCurrentToState(){return this.#et}addEventListener(t,e){return this.#tt.on(t,e)}subscribe(t){return this.#tt.on(e.TRANSITION_SUCCESS,(e,n)=>{t({route:e,previousRoute:n})})}clearAll(){this.#tt.clearAll()}setLimits(t){this.#tt.setLimits(t)}sendCancelIfTransitioning(t){this.canCancel()&&this.sendCancel(this.#et,t)}#at(){this.emitTransitionError(this.#nt,this.#it,this.#st)}#rt(){const t=this.#Z;t.on(T,A,()=>{this.emitRouterStart()}),t.on(w,D,()=>{this.emitRouterStop()}),t.on(b,C,()=>{const t=this.#nt;void 0!==t&&this.emitTransitionCancel(t,this.#it)}),t.on(T,R,()=>{this.#at()}),t.on(w,R,()=>{this.#at()}),t.on(b,R,()=>{this.#at()})}},Pe=new n(i.ROUTER_ALREADY_STARTED),Ae=new Set(["all","warn-error","error-only"]);var Oe=class{router;options;limits;dependenciesStore;state;routes;routeLifecycle;plugins;navigation;lifecycle;eventBus;constructor(t){this.router=t.router,this.options=t.options,this.limits=t.limits,this.dependenciesStore=t.dependenciesStore,this.state=t.state,this.routes=t.routes,this.routeLifecycle=t.routeLifecycle,this.plugins=t.plugins,this.navigation=t.navigation,this.lifecycle=t.lifecycle,this.eventBus=t.eventBus}wireLimits(){this.dependenciesStore.limits=this.limits,this.plugins.setLimits(this.limits),this.eventBus.setLimits({maxListeners:this.limits.maxListeners,warnListeners:this.limits.warnListeners,maxEventDepth:this.limits.maxEventDepth}),this.routeLifecycle.setLimits(this.limits)}wireRouteLifecycleDeps(){const t={compileFactory:this.createCompileFactory()};this.routeLifecycle.setDependencies(t),this.routeLifecycle.setValidatorGetter(()=>{try{return d(this.router).validator}catch{return null}})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(t,e)=>{this.routeLifecycle.addCanActivate(t,e,!0)},addDeactivateGuard:(t,e)=>{this.routeLifecycle.addCanDeactivate(t,e,!0)},makeState:(t,e,n,i)=>this.state.makeState(t,e,n,i),getState:()=>this.state.get(),areStatesEqual:(t,e,n)=>this.state.areStatesEqual(t,e,n),getDependency:t=>this.dependenciesStore.dependencies[t],forwardState:(t,e)=>{const n=d(this.router);return n.validator?.routes.validateStateBuilderArgs(t,e,"forwardState"),n.forwardState(t,e)}}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wirePluginsDeps(){const t={addEventListener:(t,e)=>this.eventBus.addEventListener(t,e),canNavigate:()=>this.eventBus.canBeginTransition(),compileFactory:this.createCompileFactory()};this.plugins.setDependencies(t),this.plugins.setValidatorGetter(()=>{try{return d(this.router).validator}catch{return null}})}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:t=>this.routes.hasRoute(t),getState:()=>this.state.get(),setState:t=>{this.state.set(t)},buildNavigateState:(t,e)=>{const n=d(this.router);n.validator?.routes.validateStateBuilderArgs(t,e,"navigate");const{name:i,params:s}=n.forwardState(t,e),r=this.routes.getMetaForState(i);if(void 0===r)return;const a=n.buildPath(i,s);return this.state.makeState(i,s,a,r,void 0,!0)},resolveDefault:()=>{const t=this.options.get();return{route:U(t.defaultRoute,t=>this.dependenciesStore.dependencies[t]),params:U(t.defaultParams,t=>this.dependenciesStore.dependencies[t])}},startTransition:(t,e)=>{this.eventBus.sendNavigate(t,e)},cancelNavigation:()=>{const t=this.eventBus.getCurrentToState();void 0!==t&&this.eventBus.sendCancel(t,this.state.get())},sendTransitionDone:(t,e,n)=>{this.eventBus.sendComplete(t,e,n)},sendTransitionFail:(t,e,n)=>{this.eventBus.sendFail(t,e,n)},emitTransitionError:(t,e,n)=>{this.eventBus.sendFailSafe(t,e,n)},emitTransitionSuccess:(t,e,n)=>{this.eventBus.emitTransitionSuccess(t,e,n)},canNavigate:()=>this.eventBus.canBeginTransition(),getLifecycleFunctions:()=>this.routeLifecycle.getFunctions(),isActive:()=>this.router.isActive(),isTransitioning:()=>this.eventBus.isTransitioning(),clearCanDeactivate:t=>{this.routeLifecycle.clearCanDeactivate(t)}})}wireLifecycleDeps(){this.lifecycle.setDependencies({getOptions:()=>this.options.get(),navigate:(t,e,n)=>this.navigation.navigate(t,e,n),navigateToNotFound:t=>this.navigation.navigateToNotFound(t),clearState:()=>{this.state.set(void 0)},matchPath:t=>this.routes.matchPath(t,this.options.get()),completeStart:()=>{this.eventBus.sendStarted()},emitTransitionError:(t,e,n)=>{this.eventBus.sendFail(t,e,n)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(t,e)=>d(this.router).buildPath(t,e),getUrlParams:t=>this.routes.getUrlParams(t)})}createCompileFactory(){const{router:t,dependenciesStore:e}=this;return n=>n(t,t=>e.dependencies[t])}},Ee=Object.freeze({}),Re=class t{#u;#S;#ot;#ct;#ut;#lt;#g;#ht;#dt;#ft;constructor(t=[],e={},n={}){e.logger&&function(t){if("object"!=typeof t||null===t)throw new TypeError("Logger config must be an object");const e=t;for(const t of Object.keys(e))if("level"!==t&&"callback"!==t)throw new TypeError(`Unknown logger config property: "${t}"`);if("level"in e&&void 0!==e.level&&("string"!=typeof(n=e.level)||!Ae.has(n)))throw new TypeError(`Invalid logger level: ${function(t){return"string"==typeof t?`"${t}"`:"object"==typeof t?JSON.stringify(t):String(t)}(e.level)}. Expected: "all" | "warn-error" | "error-only"`);var n;if("callback"in e&&void 0!==e.callback&&"function"!=typeof e.callback)throw new TypeError("Logger callback must be a function, got "+typeof e.callback);return!0}(e.logger)&&(f.configure(e.logger),delete e.logger),$.validateOptionsIsObject(e),function(t){if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError("dependencies must be a plain object");for(const e in t)if(Object.getOwnPropertyDescriptor(t,e)?.get)throw new TypeError(`dependencies cannot contain getters: "${e}"`)}(n),t.length>0&&L(t),this.#u=new $(e),this.#S=r(e.limits),this.#ot=function(t={}){const e=Object.create(null);for(const n in t)void 0!==t[n]&&(e[n]=t[n]);return{dependencies:e,limits:o}}(n),this.#ct=new _,this.#ut=new se(t,function(t){return{strictTrailingSlash:"strict"===t.trailingSlash,strictQueryParams:"strict"===t.queryParamsMode,urlParamsEncoding:t.urlParamsEncoding,queryParams:t.queryParams}}(this.#u.get())),this.#lt=new q,this.#g=new G,this.#ht=new Te,this.#dt=new be;const i=new p(j),s=new S({onListenerError:(t,e)=>{f.error("Router",`Error in listener for ${t}:`,e)},onListenerWarn:(t,e)=>{f.warn("router.addEventListener",`Event "${t}" has ${e} listeners — possible memory leak`)}});var c;this.#ft=new Ne({routerFSM:i,emitter:s}),(c=new Oe({router:this,options:this.#u,limits:this.#S,dependenciesStore:this.#ot,state:this.#ct,routes:this.#ut,routeLifecycle:this.#lt,plugins:this.#g,navigation:this.#ht,lifecycle:this.#dt,eventBus:this.#ft})).wireLimits(),c.wireRouteLifecycleDeps(),c.wireRoutesDeps(),c.wirePluginsDeps(),c.wireNavigationDeps(),c.wireLifecycleDeps(),c.wireStateDeps();const d=new Map;u(this,{makeState:(t,e,n,i,s)=>this.#ct.makeState(t,e,n,i,s),forwardState:h("forwardState",(t,e)=>this.#ut.forwardState(t,e),d),buildStateResolved:(t,e)=>this.#ut.buildStateResolved(t,e),matchPath:(t,e)=>this.#ut.matchPath(t,e),getOptions:()=>this.#u.get(),addEventListener:(t,e)=>this.#ft.addEventListener(t,e),buildPath:h("buildPath",(t,e)=>this.#ut.buildPath(t,e??a,this.#u.get()),d),start:l("start",t=>this.#dt.start(t),d),interceptors:d,setRootPath:t=>{this.#ut.setRootPath(t)},getRootPath:()=>this.#ut.getStore().rootPath,getTree:()=>this.#ut.getStore().tree,isDisposed:()=>this.#ft.isDisposed(),validator:null,dependenciesGetStore:()=>this.#ot,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#ot.dependencies}),getLifecycleFactories:()=>this.#lt.getFactories(),getPluginFactories:()=>this.#g.getAll(),routeGetStore:()=>this.#ut.getStore(),getStateName:()=>this.#ct.get()?.name,isTransitioning:()=>this.#ft.isTransitioning(),clearState:()=>{this.#ct.set(void 0)},setState:t=>{this.#ct.set(t)},routerExtensions:[]}),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.dispose=this.dispose.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToNotFound=this.navigateToNotFound.bind(this),this.subscribe=this.subscribe.bind(this)}isActiveRoute(t,e,n,i){return d(this).validator?.routes.validateIsActiveRouteArgs(t,e,n,i),d(this).validator?.routes.validateRouteName(t,"isActiveRoute"),""===t?(f.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#ut.isActiveRoute(t,e,n,i)}buildPath(t,e){const n=d(this);return n.validator?.routes.validateBuildPathArgs(t),n.validator?.navigation.validateParams(e,"buildPath"),n.buildPath(t,e)}getState(){return this.#ct.get()}getPreviousState(){return this.#ct.getPrevious()}areStatesEqual(t,e,n=!0){return d(this).validator?.state.validateAreStatesEqualArgs(t,e,n),this.#ct.areStatesEqual(t,e,n)}shouldUpdateNode(t){return d(this).validator?.routes.validateShouldUpdateNodeArgs(t),se.shouldUpdateNode(t)}isActive(){return this.#ft.isActive()}start(e){if(!this.#ft.canStart())return Promise.reject(Pe);d(this).validator?.navigation.validateStartArgs(e),this.#ft.sendStart();const n=d(this).start(e).catch(t=>{throw this.#ft.isReady()&&(this.#dt.stop(),this.#ft.sendStop()),t});return t.#pt(n),n}stop(){return this.#ht.abortCurrentNavigation(),this.#ft.sendCancelIfTransitioning(this.#ct.get()),this.#ft.isReady()||this.#ft.isTransitioning()?(this.#dt.stop(),this.#ft.sendStop(),this):this}dispose(){if(this.#ft.isDisposed())return;this.#ht.abortCurrentNavigation(),this.#ft.sendCancelIfTransitioning(this.#ct.get()),(this.#ft.isReady()||this.#ft.isTransitioning())&&(this.#dt.stop(),this.#ft.sendStop()),this.#ft.sendDispose(),this.#ft.clearAll(),this.#g.disposeAll();const t=d(this);for(const e of t.routerExtensions)for(const t of e.keys)delete this[t];t.routerExtensions.length=0,this.#ut.clearRoutes(),this.#lt.clearAll(),this.#ct.reset(),this.#ot.dependencies=Object.create(null),this.#mt()}canNavigateTo(t,e){const n=d(this);if(n.validator?.routes.validateRouteName(t,"canNavigateTo"),n.validator?.navigation.validateParams(e,"canNavigateTo"),!this.#ut.hasRoute(t))return!1;const{name:i,params:s}=n.forwardState(t,e??{}),r=this.#ct.makeState(i,s),a=this.#ct.get(),{toDeactivate:o,toActivate:c}=ne(r,a);return this.#lt.canNavigateTo(o,c,r,a)}usePlugin(...t){const e=t.filter(Boolean);if(0===e.length)return()=>{};const n=d(this);n.validator?.plugins.validatePluginLimit(this.#g.count(),this.#S);for(const t of e)n.validator?.plugins.validateNoDuplicatePlugins(t,this.#g.getAll());return this.#g.use(...e)}subscribe(t){return Ne.validateSubscribeListener(t),this.#ft.subscribe(t)}navigate(e,n,i){const s=d(this);s.validator?.navigation.validateNavigateArgs(e),s.validator?.navigation.validateParams(n,"navigate");const r=i??Ee;s.validator?.navigation.validateNavigationOptions(r,"navigate");const o=this.#ht.navigate(e,n??a,r);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:t.#pt(o),o}navigateToDefault(e){const n=d(this);n.validator?.navigation.validateNavigateToDefaultArgs(e);const i=e??Ee;n.validator?.navigation.validateNavigationOptions(i,"navigateToDefault");const s=this.#ht.navigateToDefault(i);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:t.#pt(s),s}navigateToNotFound(t){if(!this.#ft.isActive())throw new n(i.ROUTER_NOT_STARTED);if(void 0!==t&&"string"!=typeof t)throw new TypeError("[router.navigateToNotFound] path must be a string, got "+typeof t);const e=t??this.#ct.get().path;return this.#ht.navigateToNotFound(e)}static#gt=t=>{t instanceof n&&(t.code===i.SAME_STATES||t.code===i.TRANSITION_CANCELLED||t.code===i.ROUTER_NOT_STARTED||t.code===i.ROUTE_NOT_FOUND)||f.error("router.navigate","Unexpected navigation error",t)};static#pt(e){e.catch(t.#gt)}#mt(){this.navigate=Ce,this.navigateToDefault=Ce,this.navigateToNotFound=Ce,this.start=Ce,this.stop=Ce,this.usePlugin=Ce,this.subscribe=Ce,this.canNavigateTo=Ce}};function Ce(){throw new n(i.ROUTER_DISPOSED)}export{Re as Router,K as clearConfigEntries,Bt as clearRouteData,jt as f,L as guardRouteStructure,_t as refreshForwardMap,xt as registerAllRouteHandlers,V as removeFromDefinitions,m as resolveForwardChain,Q as sanitizeRoute};//# sourceMappingURL=chunk-MNRZAE7T.mjs.map