@real-router/core 0.22.0 → 0.23.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.
- package/README.md +1 -3
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/metafile-cjs.json +1 -1
- package/dist/esm/index.d.mts +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/metafile-esm.json +1 -1
- package/package.json +7 -5
- package/src/Router.ts +1174 -0
- package/src/RouterError.ts +324 -0
- package/src/constants.ts +112 -0
- package/src/createRouter.ts +32 -0
- package/src/fsm/index.ts +5 -0
- package/src/fsm/routerFSM.ts +129 -0
- package/src/getNavigator.ts +15 -0
- package/src/helpers.ts +194 -0
- package/src/index.ts +46 -0
- package/src/namespaces/CloneNamespace/CloneNamespace.ts +120 -0
- package/src/namespaces/CloneNamespace/index.ts +3 -0
- package/src/namespaces/CloneNamespace/types.ts +46 -0
- package/src/namespaces/DependenciesNamespace/DependenciesNamespace.ts +250 -0
- package/src/namespaces/DependenciesNamespace/index.ts +3 -0
- package/src/namespaces/DependenciesNamespace/validators.ts +105 -0
- package/src/namespaces/EventBusNamespace/EventBusNamespace.ts +272 -0
- package/src/namespaces/EventBusNamespace/index.ts +5 -0
- package/src/namespaces/EventBusNamespace/types.ts +11 -0
- package/src/namespaces/MiddlewareNamespace/MiddlewareNamespace.ts +206 -0
- package/src/namespaces/MiddlewareNamespace/index.ts +5 -0
- package/src/namespaces/MiddlewareNamespace/types.ts +28 -0
- package/src/namespaces/MiddlewareNamespace/validators.ts +96 -0
- package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +308 -0
- package/src/namespaces/NavigationNamespace/index.ts +5 -0
- package/src/namespaces/NavigationNamespace/transition/executeLifecycleHooks.ts +84 -0
- package/src/namespaces/NavigationNamespace/transition/executeMiddleware.ts +56 -0
- package/src/namespaces/NavigationNamespace/transition/index.ts +107 -0
- package/src/namespaces/NavigationNamespace/transition/makeError.ts +37 -0
- package/src/namespaces/NavigationNamespace/transition/mergeStates.ts +54 -0
- package/src/namespaces/NavigationNamespace/transition/processLifecycleResult.ts +81 -0
- package/src/namespaces/NavigationNamespace/transition/wrapSyncError.ts +82 -0
- package/src/namespaces/NavigationNamespace/types.ts +129 -0
- package/src/namespaces/NavigationNamespace/validators.ts +87 -0
- package/src/namespaces/OptionsNamespace/OptionsNamespace.ts +50 -0
- package/src/namespaces/OptionsNamespace/constants.ts +41 -0
- package/src/namespaces/OptionsNamespace/helpers.ts +51 -0
- package/src/namespaces/OptionsNamespace/index.ts +11 -0
- package/src/namespaces/OptionsNamespace/validators.ts +252 -0
- package/src/namespaces/PluginsNamespace/PluginsNamespace.ts +325 -0
- package/src/namespaces/PluginsNamespace/constants.ts +35 -0
- package/src/namespaces/PluginsNamespace/index.ts +7 -0
- package/src/namespaces/PluginsNamespace/types.ts +32 -0
- package/src/namespaces/PluginsNamespace/validators.ts +79 -0
- package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +389 -0
- package/src/namespaces/RouteLifecycleNamespace/index.ts +5 -0
- package/src/namespaces/RouteLifecycleNamespace/types.ts +17 -0
- package/src/namespaces/RouteLifecycleNamespace/validators.ts +65 -0
- package/src/namespaces/RouterLifecycleNamespace/RouterLifecycleNamespace.ts +140 -0
- package/src/namespaces/RouterLifecycleNamespace/constants.ts +25 -0
- package/src/namespaces/RouterLifecycleNamespace/index.ts +5 -0
- package/src/namespaces/RouterLifecycleNamespace/types.ts +23 -0
- package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +1482 -0
- package/src/namespaces/RoutesNamespace/constants.ts +14 -0
- package/src/namespaces/RoutesNamespace/helpers.ts +532 -0
- package/src/namespaces/RoutesNamespace/index.ts +9 -0
- package/src/namespaces/RoutesNamespace/stateBuilder.ts +70 -0
- package/src/namespaces/RoutesNamespace/types.ts +82 -0
- package/src/namespaces/RoutesNamespace/validators.ts +331 -0
- package/src/namespaces/StateNamespace/StateNamespace.ts +317 -0
- package/src/namespaces/StateNamespace/helpers.ts +43 -0
- package/src/namespaces/StateNamespace/index.ts +5 -0
- package/src/namespaces/StateNamespace/types.ts +15 -0
- package/src/namespaces/index.ts +42 -0
- package/src/transitionPath.ts +441 -0
- package/src/typeGuards.ts +74 -0
- package/src/types.ts +194 -0
- package/src/wiring/RouterWiringBuilder.ts +235 -0
- package/src/wiring/index.ts +7 -0
- package/src/wiring/types.ts +53 -0
- package/src/wiring/wireRouter.ts +29 -0
package/README.md
CHANGED
|
@@ -421,7 +421,6 @@ Clone router for SSR.\
|
|
|
421
421
|
Returns: `Router`\
|
|
422
422
|
[Wiki](https://github.com/greydragon888/real-router/wiki/clone)
|
|
423
423
|
|
|
424
|
-
|
|
425
424
|
---
|
|
426
425
|
|
|
427
426
|
## Plugin Development API
|
|
@@ -430,11 +429,10 @@ The following methods are designed for **plugin authors**. They provide low-leve
|
|
|
430
429
|
|
|
431
430
|
These methods are stable but intended for plugin development, not application code.
|
|
432
431
|
|
|
433
|
-
#### `router.matchPath(path: string
|
|
432
|
+
#### `router.matchPath(path: string): State | undefined`
|
|
434
433
|
|
|
435
434
|
Match URL path to route state.\
|
|
436
435
|
`path: string` — URL path to match\
|
|
437
|
-
`source?: string` — navigation source identifier\
|
|
438
436
|
Returns: `State | undefined`\
|
|
439
437
|
[Wiki](https://github.com/greydragon888/real-router/wiki/matchPath)
|
|
440
438
|
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ declare class Router<Dependencies extends DefaultDependencies = DefaultDependenc
|
|
|
62
62
|
updateRoute(name: string, updates: RouteConfigUpdate<Dependencies>): this;
|
|
63
63
|
isActiveRoute(name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean): boolean;
|
|
64
64
|
buildPath(route: string, params?: Params): string;
|
|
65
|
-
matchPath<P extends Params = Params, MP extends Params = Params>(path: string
|
|
65
|
+
matchPath<P extends Params = Params, MP extends Params = Params>(path: string): State<P, MP> | undefined;
|
|
66
66
|
setRootPath(rootPath: string): void;
|
|
67
67
|
getRootPath(): string;
|
|
68
68
|
makeState<P extends Params = Params, MP extends Params = Params>(name: string, params?: P, path?: string, meta?: StateMetaInput<MP>, forceId?: number): State<P, MP>;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=require("@real-router/logger"),t=require("@real-router/fsm"),r={maxListeners:0,warnListeners:0,maxEventDepth:0},i=class extends Error{},n=class{#e=new Map;#t=null;#r=r;#i;#n;constructor(e){e?.limits&&(this.#r=e.limits),this.#i=e?.onListenerError??null,this.#n=e?.onListenerWarn??null}static validateCallback(e,t){if("function"!=typeof e)throw new TypeError(`Expected callback to be a function for event ${t}`)}setLimits(e){this.#r=e}on(e,t){const r=this.#a(e);if(r.has(t))throw new Error(`Duplicate listener for "${e}"`);const{maxListeners:i,warnListeners:n}=this.#r;if(0!==n&&r.size===n&&this.#n?.(e,n),0!==i&&r.size>=i)throw new Error(`Listener limit (${i}) reached for "${e}"`);return r.add(t),()=>{this.off(e,t)}}off(e,t){this.#e.get(e)?.delete(t)}emit(e,...t){const r=this.#e.get(e);r&&0!==r.size&&(0!==this.#r.maxEventDepth?this.#s(r,e,t):this.#o(r,e,t))}clearAll(){this.#e.clear(),this.#t=null}listenerCount(e){return this.#e.get(e)?.size??0}#o(e,t,r){const i=[...e];for(const e of i)try{switch(r.length){case 0:e();break;case 1:e(r[0]);break;case 2:e(r[0],r[1]);break;case 3:e(r[0],r[1],r[2]);break;default:Function.prototype.apply.call(e,void 0,r)}}catch(e){this.#i?.(t,e)}}#s(e,t,r){this.#t??=new Map;const n=this.#t,a=n.get(t)??0;if(a>=this.#r.maxEventDepth)throw new i(`Maximum recursion depth (${this.#r.maxEventDepth}) exceeded for event: ${t}`);try{n.set(t,a+1);const s=[...e];for(const e of s)try{switch(r.length){case 0:e();break;case 1:e(r[0]);break;case 2:e(r[0],r[1]);break;case 3:e(r[0],r[1],r[2]);break;default:Function.prototype.apply.call(e,void 0,r)}}catch(e){if(e instanceof i)throw e;this.#i?.(t,e)}}finally{n.set(t,n.get(t)-1)}}#a(e){const t=this.#e.get(e);if(t)return t;const r=new Set;return this.#e.set(e,r),r}},a=["replace","reload","force","forceDeactivate","redirected"],s=/\S/,o=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function c(e,t){return new TypeError(`[router.${e}] ${t}`)}function d(e,t=new WeakSet){if(null==e)return!0;const r=typeof e;if("string"===r||"boolean"===r)return!0;if("number"===r)return Number.isFinite(e);if("function"===r||"symbol"===r)return!1;if(Array.isArray(e))return!t.has(e)&&(t.add(e),e.every(e=>d(e,t)));if("object"===r){if(t.has(e))return!1;t.add(e);const r=Object.getPrototypeOf(e);return(null===r||r===Object.prototype)&&Object.values(e).every(e=>d(e,t))}return!1}function u(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function l(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);if(null!==t&&t!==Object.prototype)return!1;let r=!1;for(const t in e){if(!Object.hasOwn(e,t))continue;const i=e[t];if(!u(i)){const e=typeof i;if("function"===e||"symbol"===e)return!1;r=!0;break}}return!r||d(e)}function h(e){return"object"==typeof e&&null!==e&&("string"==typeof(r=(t=e).name)&&(""===r||!(r.length>1e4)&&(!!r.startsWith("@@")||o.test(r)))&&"string"==typeof t.path&&l(t.params));var t,r}function f(e){return"string"==typeof e}function p(e){return"boolean"==typeof e}function m(e){return"object"==typeof e&&null!==e&&"then"in e&&"function"==typeof e.then}function g(e,t){return e in t}function w(e,t){if("string"!=typeof e)throw c(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!s.test(e))throw c(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw c(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!o.test(e))throw c(t,`Invalid route name "${e}". Each segment must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens. Segments are separated by dots (e.g., "users.profile").`)}}function v(e){return null===e?"null":Array.isArray(e)?`array[${e.length}]`:"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function y(e,t){if(!h(e))throw new TypeError(`[${t}] Invalid state structure: ${v(e)}. Expected State object with name, params, and path properties.`)}var b=Object.freeze({ROUTER_NOT_STARTED:"NOT_STARTED",NO_START_PATH_OR_STATE:"NO_START_PATH_OR_STATE",ROUTER_ALREADY_STARTED:"ALREADY_STARTED",ROUTE_NOT_FOUND:"ROUTE_NOT_FOUND",SAME_STATES:"SAME_STATES",CANNOT_DEACTIVATE:"CANNOT_DEACTIVATE",CANNOT_ACTIVATE:"CANNOT_ACTIVATE",TRANSITION_ERR:"TRANSITION_ERR",TRANSITION_CANCELLED:"CANCELLED",ROUTER_DISPOSED:"DISPOSED"}),T={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},S="onStart",R="onStop",A="onTransitionStart",E="onTransitionCancel",P="onTransitionSuccess",O="onTransitionError",$={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},D=new Set([$.ROUTER_START,$.TRANSITION_START,$.TRANSITION_SUCCESS,$.TRANSITION_ERROR,$.TRANSITION_CANCEL,$.ROUTER_STOP]),N={maxDependencies:100,maxPlugins:50,maxMiddleware:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},C={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxMiddleware:{min:0,max:1e3},maxListeners:{min:0,max:1e5},warnListeners:{min:0,max:1e5},maxEventDepth:{min:0,max:100},maxLifecycleHandlers:{min:0,max:1e4}},j="IDLE",M="STARTING",F="READY",x="TRANSITIONING",k="DISPOSED",I="START",L="STARTED",U="NAVIGATE",_="COMPLETE",B="FAIL",V="CANCEL",G="STOP",W="DISPOSE",q={initial:j,context:null,transitions:{[j]:{[I]:M,[W]:k},[M]:{[L]:F,[B]:j},[F]:{[U]:x,[B]:F,[G]:j},[x]:{[U]:x,[_]:F,[V]:F,[B]:F},[k]:{}}},z=new WeakSet;function H(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)H(t);else for(const t in e)H(e[t])}function Q(e){return e?(z.has(e)||(H(e),z.add(e)),e):e}function K(e){return{warn:Math.floor(.2*e),error:Math.floor(.5*e)}}var J=class{#c=Object.create(null);#r=N;constructor(e={}){this.setMultiple(e)}static validateName(e,t){!function(e,t){if("string"!=typeof e)throw new TypeError(`[router.${t}]: dependency name must be a string, got ${typeof e}`)}(e,t)}static validateSetDependencyArgs(e){!function(e){if("string"!=typeof e)throw new TypeError("[router.setDependency]: dependency name must be a string, got "+typeof e)}(e)}static validateDependenciesObject(e,t){!function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid argument: expected plain object, received ${v(e)}`);for(const r in e)if(Object.getOwnPropertyDescriptor(e,r)?.get)throw new TypeError(`[router.${t}] Getters not allowed: "${r}"`)}(e,t)}static validateDependencyExists(e,t){!function(e,t){if(void 0===e)throw new ReferenceError(`[router.getDependency]: dependency "${t}" not found`)}(e,t)}static validateDependencyLimit(e,t,r,i){!function(e,t,r,i=N.maxDependencies){if(0===i)return;const n=e+t;if(n>=i)throw new Error(`[router.${r}] Dependency limit exceeded (${i}). Current: ${n}. This is likely a bug in your code.`)}(e,t,r,i)}setLimits(e){this.#r=e}set(t,r){if(void 0===r)return!1;if(Object.hasOwn(this.#c,t)){const i=this.#c[t],n=i!==r,a=Number.isNaN(i)&&Number.isNaN(r);n&&!a&&e.logger.warn("router.setDependency","Router dependency already exists and is being overwritten:",t)}else this.#d("setDependency");return this.#c[t]=r,!0}setMultiple(t){const r=[];for(const e in t)void 0!==t[e]&&(Object.hasOwn(this.#c,e)&&r.push(e),this.#c[e]=t[e]);r.length>0&&e.logger.warn("router.setDependencies","Overwritten:",r.join(", "))}get(e){return this.#c[e]}getAll(){return{...this.#c}}count(){return Object.keys(this.#c).length}remove(t){Object.hasOwn(this.#c,t)||e.logger.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${v(t)}"`),delete this.#c[t]}has(e){return Object.hasOwn(this.#c,e)}reset(){for(const e in this.#c)delete this.#c[e]}#d(t){const r=this.#r.maxDependencies;if(0===r)return;const i=Object.keys(this.#c).length,{warn:n,error:a}=K(r);if(i===n)e.logger.warn(`router.${t}`,`${n} dependencies registered. Consider if all are necessary.`);else if(i===a)e.logger.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${r}.`);else if(i>=r)throw new Error(`[router.${t}] Dependency limit exceeded (${r}). Current: ${i}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}},Y={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},Z={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},X={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function ee(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&ee(r)}return e}function te(e,t){return"function"==typeof e?e(t):e}function re(e,t,r){if("function"==typeof t&&("defaultRoute"===e||"defaultParams"===e))return;const i=Y[e];if(i&&"object"==typeof i)return function(e,t,r){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${r}] Invalid type for "${t}": expected plain object, got ${v(e)}`);for(const i in e)if(Object.getOwnPropertyDescriptor(e,i)?.get)throw new TypeError(`[router.${r}] Getters not allowed in "${t}": "${i}"`)}(t,e,r),void("queryParams"===e&&function(e,t){for(const r in e){if(!g(r,X)){const e=Object.keys(X).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const i=e[r],n=X[r];if(!n.includes(i)){const e=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Invalid value for queryParams.${r}: expected one of ${e}, got "${String(i)}"`)}}}(t,r));if(typeof t!=typeof i)throw new TypeError(`[router.${r}] Invalid type for "${e}": expected ${typeof i}, got ${typeof t}`);e in Z&&function(e,t,r){const i=Z[e];if(!i.includes(t)){const n=i.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${n}, got "${String(t)}"`)}}(e,t,r)}function ie(e,t,r){if("limits"===e)return void 0!==t&&function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}]: invalid limits: expected plain object, got ${typeof e}`);for(const[r,i]of Object.entries(e)){if(!Object.hasOwn(C,r))throw new TypeError(`[router.${t}]: unknown limit: "${r}"`);void 0!==i&&ne(r,i,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function ne(e,t,r){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError(`[router.${r}]: limit "${e}" must be an integer, got ${String(t)}`);const i=C[e];if(t<i.min||t>i.max)throw new RangeError(`[router.${r}]: limit "${e}" must be between ${i.min} and ${i.max}, got ${t}`)}var ae=class{#u;constructor(e={}){this.#u=ee({...Y,...e})}static validateOptions(e,t){!function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid options: expected plain object, got ${v(e)}`);for(const[r,i]of Object.entries(e))g(r,Y)?void 0!==i&&re(r,i,t):ie(r,i,t)}(e,t)}get(){return this.#u}};function se(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>se(e,t[r]))}var oe=class{#l=0;#h=void 0;#f=void 0;#p;#m=new Map;static validateMakeStateArgs(e,t,r,i){if(!f(e))throw new TypeError(`[router.makeState] Invalid name: ${v(e)}. Expected string.`);if(void 0!==t&&!l(t))throw new TypeError(`[router.makeState] Invalid params: ${v(t)}. Expected plain object.`);if(void 0!==r&&!f(r))throw new TypeError(`[router.makeState] Invalid path: ${v(r)}. Expected string.`);if(void 0!==i&&"number"!=typeof i)throw new TypeError(`[router.makeState] Invalid forceId: ${v(i)}. Expected number.`)}static validateAreStatesEqualArgs(e,t,r){if(null!=e&&y(e,"areStatesEqual"),null!=t&&y(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${v(r)}. Expected boolean.`)}get(){return this.#h}set(e){this.#f=this.#h,this.#h=e?Q(e):void 0}getPrevious(){return this.#f}reset(){this.#h=void 0,this.#f=void 0,this.#m.clear(),this.#l=0}setDependencies(e){this.#p=e}makeState(e,t,r,i,n){const a=i?{...i,id:n??++this.#l,params:i.params,options:i.options,redirected:i.redirected}:void 0,s=this.#p.getDefaultParams();let o;return o=Object.hasOwn(s,e)?{...s[e],...t}:t?{...t}:{},Q({name:e,params:o,path:r??this.#p.buildPath(e,t),meta:a})}makeNotFoundState(e,t){return this.makeState(T.UNKNOWN_ROUTE,{path:e},e,{options:t,params:{},redirected:!1})}areStatesEqual(e,t,r=!0){if(!e||!t)return!!e==!!t;if(e.name!==t.name)return!1;if(r){const r=e.meta?.params??t.meta?.params;return(r?function(e){const t=[];for(const r in e){const i=e[r];for(const e in i)"url"===i[e]&&t.push(e)}return t}(r):this.#g(e.name)).every(r=>se(e.params[r],t.params[r]))}const i=Object.keys(e.params),n=Object.keys(t.params);return i.length===n.length&&i.every(r=>r in t.params&&se(e.params[r],t.params[r]))}#g(e){const t=this.#m.get(e);if(void 0!==t)return t;const r=this.#p.getUrlParams(e);return this.#m.set(e,r),r}};function ce(e){return e.name||"anonymous"}var de=class{#w=new Set;#v=new Map;#y;#p;#r=N;static validateUseMiddlewareArgs(e){!function(e){for(const[t,r]of e.entries())if("function"!=typeof r)throw new TypeError(`[router.useMiddleware] Expected middleware factory function at index ${t}, got ${v(r)}`)}(e)}static validateMiddleware(e,t){!function(e,t){if("function"!=typeof e)throw new TypeError(`[router.useMiddleware] Middleware factory must return a function, got ${v(e)}. Factory: ${ce(t)}`)}(e,t)}static validateNoDuplicates(e,t){!function(e,t){const r=new Set(t);for(const t of e)if(r.has(t))throw new Error(`[router.useMiddleware] Middleware factory already registered. To re-register, first unsubscribe the existing middleware. Factory: ${ce(t)}`)}(e,t)}static validateMiddlewareLimit(e,t,r){!function(e,t,r=N.maxMiddleware){if(0!==r&&e+t>r)throw new Error(`[router.useMiddleware] Middleware limit exceeded (${r}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating middleware.`)}(e,t,r)}setRouter(e){this.#y=e}setDependencies(e){this.#p=e}setLimits(e){this.#r=e}count(){return this.#w.size}initialize(...e){const t=[];for(const r of e){const e=r(this.#y,this.#p.getDependency);t.push({factory:r,middleware:e})}return t}commit(e){this.#b(e.length);for(const{factory:t,middleware:r}of e)this.#w.add(t),this.#v.set(t,r);let t=!1;return()=>{if(!t){t=!0;for(const{factory:t}of e)this.#w.delete(t),this.#v.delete(t)}}}getFactories(){return[...this.#w]}getFunctions(){return[...this.#v.values()]}clearAll(){this.#w.clear(),this.#v.clear()}#b(t){const r=this.#r.maxMiddleware;if(0===r)return;const i=t+this.#w.size,{warn:n,error:a}=K(r);i>=a?e.logger.error("router.useMiddleware",`${i} middleware registered! This is excessive and will impact performance. Hard limit at ${r}.`):i>=n&&e.logger.warn("router.useMiddleware",`${i} middleware registered. Consider if all are necessary.`)}},ue={[S]:$.ROUTER_START,[R]:$.ROUTER_STOP,[P]:$.TRANSITION_SUCCESS,[A]:$.TRANSITION_START,[O]:$.TRANSITION_ERROR,[E]:$.TRANSITION_CANCEL},le=Object.keys(ue).filter(e=>g(e,ue)),he="router.usePlugin",fe=class t{#T=new Set;#S=new Set;#y;#p;#r=N;static validateUsePluginArgs(e){!function(e){for(const t of e)if("function"!=typeof t)throw new TypeError("[router.usePlugin] Expected plugin factory function, got "+typeof t)}(e)}static validatePlugin(e){!function(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new TypeError(`[router.usePlugin] Plugin factory must return an object, got ${v(e)}`);if("function"==typeof e.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.");for(const t in e)if("teardown"!==t&&!g(t,ue))throw new TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}(e)}static validatePluginLimit(e,t,r){!function(e,t,r=N.maxPlugins){if(0!==r&&e+t>r)throw new Error(`[router.usePlugin] Plugin limit exceeded (${r})`)}(e,t,r)}static validateNoDuplicatePlugins(e,t){for(const r of e)if(t(r))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setRouter(e){this.#y=e}setDependencies(e){this.#p=e}setLimits(e){this.#r=e}count(){return this.#T.size}use(...t){if(this.#b(t.length),1===t.length){const r=t[0],i=this.#R(r);this.#T.add(r);let n=!1;const a=()=>{if(!n){n=!0,this.#T.delete(r),this.#S.delete(a);try{i()}catch(t){e.logger.error(he,"Error during cleanup:",t)}}};return this.#S.add(a),a}const r=this.#A(t),i=[];try{for(const e of r){const t=this.#R(e);i.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of i)try{t()}catch(t){e.logger.error(he,"Cleanup error:",t)}throw t}for(const{factory:e}of i)this.#T.add(e);let n=!1;const a=()=>{if(!n){n=!0,this.#S.delete(a);for(const{factory:e}of i)this.#T.delete(e);for(const{cleanup:t}of i)try{t()}catch(t){e.logger.error(he,"Error during cleanup:",t)}}};return this.#S.add(a),a}getAll(){return[...this.#T]}has(e){return this.#T.has(e)}disposeAll(){for(const e of this.#S)e();this.#T.clear(),this.#S.clear()}#b(t){const r=this.#r.maxPlugins;if(0===r)return;const i=t+this.#T.size,{warn:n,error:a}=K(r);i>=a?e.logger.error(he,`${i} plugins registered!`):i>=n&&e.logger.warn(he,`${i} plugins registered`)}#A(t){const r=new Set;for(const i of t)r.has(i)?e.logger.warn(he,"Duplicate factory in batch, will be registered once"):r.add(i);return r}#R(r){const i=r(this.#y,this.#p.getDependency);t.validatePlugin(i),Object.freeze(i);const n=[];for(const t of le)t in i&&("function"==typeof i[t]?(n.push(this.#p.addEventListener(ue[t],i[t])),"onStart"===t&&this.#p.canNavigate()&&e.logger.warn(he,"Router already started, onStart will not be called")):e.logger.warn(he,`Property '${t}' is not a function, skipping`));return()=>{for(const e of n)e();"function"==typeof i.teardown&&i.teardown()}}};function pe(e,t,r){if(e)throw new Error(`[router.${r}] Cannot modify route "${t}" during its own registration`)}function me(e,t,r=N.maxLifecycleHandlers){if(0!==r&&e>=r)throw new Error(`[router.${t}] Lifecycle handler limit exceeded (${r}). This indicates too many routes with individual handlers. Consider using middleware for cross-cutting concerns.`)}var ge=class{#E=new Map;#P=new Map;#O=new Map;#$=new Map;#D=new Set;#y;#p;#r=N;static validateHandler(e,t){!function(e,t){if(!p(e)&&"function"!=typeof e)throw new TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${v(e)}`)}(e,t)}setRouter(e){this.#y=e}setDependencies(e){this.#p=e}setLimits(e){this.#r=e}addCanActivate(e,t,r){r||pe(this.#D.has(e),e,"addActivateGuard");const i=this.#P.has(e);i||r||me(this.#P.size+1,"addActivateGuard",this.#r.maxLifecycleHandlers),this.#N("activate",e,t,this.#P,this.#$,"canActivate",i)}addCanDeactivate(e,t,r){r||pe(this.#D.has(e),e,"addDeactivateGuard");const i=this.#E.has(e);i||r||me(this.#E.size+1,"addDeactivateGuard",this.#r.maxLifecycleHandlers),this.#N("deactivate",e,t,this.#E,this.#O,"canDeactivate",i)}clearCanActivate(e){this.#P.delete(e),this.#$.delete(e)}clearCanDeactivate(e){this.#E.delete(e),this.#O.delete(e)}clearAll(){this.#P.clear(),this.#$.clear(),this.#E.clear(),this.#O.clear()}getFactories(){const e={},t={};for(const[t,r]of this.#E)e[t]=r;for(const[e,r]of this.#P)t[e]=r;return[e,t]}getFunctions(){return[this.#O,this.#$]}checkActivateGuardSync(e,t,r){return this.#C(this.#$,e,t,r,"checkActivateGuardSync")}checkDeactivateGuardSync(e,t,r){return this.#C(this.#O,e,t,r,"checkDeactivateGuardSync")}#N(t,r,i,n,a,s,o){o?e.logger.warn(`router.${s}`,`Overwriting existing ${t} handler for route "${r}"`):this.#b(n.size+1,s);const c=p(i)?function(e){const t=()=>e;return()=>t}(i):i;n.set(r,c),this.#D.add(r);try{const e=c(this.#y,this.#p.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${s}] Factory must return a function, got ${v(e)}`);a.set(r,e)}catch(e){throw n.delete(r),e}finally{this.#D.delete(r)}}#C(t,r,i,n,a){const s=t.get(r);if(!s)return!0;try{const t=s(i,n);return"boolean"==typeof t?t:!m(t)||(e.logger.warn(`router.${a}`,`Guard for "${r}" returned a Promise. Sync check cannot resolve async guards — returning false.`),!1)}catch{return!1}}#b(t,r){const i=this.#r.maxLifecycleHandlers;if(0===i)return;const{warn:n,error:a}=K(i);t>=a?e.logger.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at ${i}.`):t>=n&&e.logger.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}};function we(e,t){const r=e.path,i=r.startsWith("~"),n=i?r.slice(1):r,a={name:e.name,path:n,absolute:i,children:[],parent:t,nonAbsoluteChildren:[],fullName:""};if(e.children)for(const t of e.children){const e=we(t,a);a.children.push(e)}return a}function ve(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var ye=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,be=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,Te=/\?(.+)$/,Se=/[^\w!$'()*+,.:;|~-]/gu,Re=/[^\w!$'()*+,.:;|~-]/u,Ae={default:e=>Re.test(e)?e.replaceAll(Se,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},Ee={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function Pe(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function Oe(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function $e(e){const t={};if(0===e.length)return t;const r=e.split("&");for(const e of r){const r=e.indexOf("=");-1===r?t[e]="":t[e.slice(0,r)]=e.slice(r+1)}return t}function De(e){const t=[];for(const r of Object.keys(e)){const i=e[r],n=encodeURIComponent(r);t.push(""===i?n:`${n}=${encodeURIComponent(String(i))}`)}return t.join("&")}function Ne(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function Ce(e){let t=0;for(;t<e.length;)if("%"===e[t]){if(t+2>=e.length)return!1;const r=e.codePointAt(t+1)??0,i=e.codePointAt(t+2)??0;if(!Ne(r)||!Ne(i))return!1;t+=3}else t++;return!0}var je=/<[^>]*>/g;function Me(e,t,r,i,n){const a=""===t.fullName;a||i.push(t);const s=t.absolute,o=t.paramMeta.pathPattern,c=s&&o.startsWith("~")?o.slice(1):o,d=(s?c:o).replaceAll(je,""),u=s?d:(h=d,""===(l=r)?h:""===h?l:l+h);var l,h;let f=n;a||(f=function(e,t,r,i,n,a){const s=(g=i,Oe(r)===Oe(g)),o=Object.freeze([...n]),c=function(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return Object.freeze(t)}(o),d=Oe(r),u=function(e,t){const r=[];e.length>0&&r.push(...e);for(const e of t)e.paramMeta.queryParams.length>0&&r.push(...e.paramMeta.queryParams);return r}(e.rootQueryParams,n),l=function(e){const t=new Map;for(const r of e)for(const[e,i]of r.paramMeta.constraintPatterns)t.set(e,i);return t}(n),h=s?Oe(i):d,{buildStaticParts:f,buildParamSlots:p}=function(e,t,r){const i=new Set,n=new Set;for(const e of t){for(const t of e.paramMeta.urlParams)i.add(t);for(const t of e.paramMeta.spatParams)n.add(t)}if(0===i.size)return{buildStaticParts:[e],buildParamSlots:[]};const a=[],s=[],o=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,d=0;for(;null!==(c=o.exec(e));){const t=c[1],i="?"===c[2];a.push(e.slice(d,c.index));const o=n.has(t);s.push({paramName:t,isOptional:i,encoder:o?e=>{const t=Ae[r],i=e.split("/");let n=t(i[0]);for(let e=1;e<i.length;e++)n+=`/${t(i[e])}`;return n}:Ae[r]}),d=c.index+c[0].length}return a.push(e.slice(d)),{buildStaticParts:a,buildParamSlots:s}}(h,s?n.slice(0,-1):n,e.options.urlParamsEncoding),m={name:t.fullName,parent:a,depth:n.length-1,matchSegments:o,meta:c,declaredQueryParams:u,declaredQueryParamsSet:new Set(u),hasTrailingSlash:r.length>1&&r.endsWith("/"),constraintPatterns:l,hasConstraints:l.size>0,buildStaticParts:f,buildParamSlots:p};var g;return e.routesByName.set(t.fullName,m),e.segmentsByName.set(t.fullName,o),e.metaByName.set(t.fullName,c),s?function(e,t,r){var i,n;i=t,(function(e,t,r){const i=Oe(r);if("/"===i||""===i)return t;let n=t,a=1;const s=i.length;for(;a<=s;){const t=i.indexOf("/",a),r=-1===t?s:t;if(r<=a)break;n=xe(e,n,i.slice(a,r)),a=r+1}return n}(n=e,n.root,r)).slashChildRoute=i;const a=Oe(r),s=e.options.caseSensitive?a:a.toLowerCase();e.staticCache.has(s)&&e.staticCache.set(s,t)}(e,m,i):function(e,t,r,i,n){if(function(e,t,r){const i=Oe(r);"/"!==i?Fe(e,e.root,i,1,t):e.root.route=t}(e,t,r),0===n.paramMeta.urlParams.length){const r=e.options.caseSensitive?i:i.toLowerCase();e.staticCache.set(r,t)}}(e,m,r,d,t),m}(e,t,u,s?"":r,i,n));for(const r of t.children.values())Me(e,r,u,i,f);a||i.pop()}function Fe(e,t,r,i,n){const a=r.length;for(;i<=a;){const s=r.indexOf("/",i),o=-1===s?a:s,c=r.slice(i,o);if(c.endsWith("?")){const i=c.slice(1).replaceAll(je,"").replace(/\?$/,"");return t.paramChild??={node:Pe(),name:i},Fe(e,t.paramChild.node,r,o+1,n),void(o>=a?t.route??=n:Fe(e,t,r,o+1,n))}t=xe(e,t,c),i=o+1}t.route=n}function xe(e,t,r){if(r.startsWith("*")){const e=r.slice(1);return t.splatChild??={node:Pe(),name:e},t.splatChild.node}if(r.startsWith(":")){const e=r.slice(1).replaceAll(je,"").replace(/\?$/,"");return t.paramChild??={node:Pe(),name:e},t.paramChild.node}const i=e.options.caseSensitive?r:r.toLowerCase();return i in t.staticChildren||(t.staticChildren[i]=Pe()),t.staticChildren[i]}var ke=/[\u0080-\uFFFF]/,Ie=class{get options(){return this.#j}#j;#M=Pe();#F=new Map;#x=new Map;#k=new Map;#I=new Map;#L="";#U=[];constructor(e){this.#j={caseSensitive:e?.caseSensitive??!0,strictTrailingSlash:e?.strictTrailingSlash??!1,strictQueryParams:e?.strictQueryParams??!1,urlParamsEncoding:e?.urlParamsEncoding??"default",parseQueryString:e?.parseQueryString??$e,buildQueryString:e?.buildQueryString??De}}registerTree(e){this.#U=e.paramMeta.queryParams,Me({root:this.#M,options:this.#j,routesByName:this.#F,segmentsByName:this.#x,metaByName:this.#k,staticCache:this.#I,rootQueryParams:this.#U},e,"",[],null)}match(e){const t=this.#_(e);if(!t)return;const[r,i,n]=t,a=this.#j.caseSensitive?i:i.toLowerCase(),s=this.#I.get(a);if(s){if(this.#j.strictTrailingSlash&&!this.#B(r,s))return;return this.#V(s,{},n)}const o={},c=this.#G(i,o);return!c||this.#j.strictTrailingSlash&&!this.#B(r,c)||c.hasConstraints&&!this.#W(o,c)||!this.#q(o)?void 0:this.#V(c,o,n)}buildPath(e,t,r){const i=this.#F.get(e);if(!i)throw new Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);i.hasConstraints&&t&&this.#z(i,e,t);const n=this.#H(i,t),a=this.#Q(n,r?.trailingSlash),s=this.#K(i,t,r?.queryParamsMode);return a+(s?`?${s}`:"")}getSegmentsByName(e){return this.#x.get(e)}getMetaByName(e){return this.#k.get(e)}hasRoute(e){return this.#F.has(e)}setRootPath(e){this.#L=e}#z(e,t,r){for(const[i,n]of e.constraintPatterns){const e=r[i];if(null!=e){const r="object"==typeof e?JSON.stringify(e):String(e);if(!n.pattern.test(r))throw new Error(`[SegmentMatcher.buildPath] '${t}' — param '${i}' value '${r}' does not match constraint '${n.constraint}'`)}}}#H(e,t){const r=e.buildStaticParts,i=e.buildParamSlots;if(0===i.length)return this.#L+r[0];let n=this.#L+r[0];for(const[e,a]of i.entries()){const i=t?.[a.paramName];if(null==i){if(!a.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${a.paramName}'`);n.length>1&&n.endsWith("/")&&(n=n.slice(0,-1)),n+=r[e+1];continue}const s="object"==typeof i?JSON.stringify(i):String(i);n+=a.encoder(s)+r[e+1]}return n}#Q(e,t){return"always"!==t||e.endsWith("/")?"never"===t&&"/"!==e&&e.endsWith("/")?e.slice(0,-1):e:`${e}/`}#K(e,t,r){if(!t)return"";const i=[...e.declaredQueryParams];if("loose"===r){const r=new Set(e.buildParamSlots.map(e=>e.paramName));for(const n in t)!Object.hasOwn(t,n)||e.declaredQueryParamsSet.has(n)||r.has(n)||i.push(n)}const n={};for(const e of i)e in t&&(n[e]=t[e]);return 0===Object.keys(n).length?"":this.#j.buildQueryString(n)}#_(e){if(""===e&&(e="/"),!e.startsWith("/"))return;const t=e.indexOf("#");if(-1!==t&&(e=e.slice(0,t)),ke.test(e))return;if(this.#L.length>0){if(!e.startsWith(this.#L))return;e=e.slice(this.#L.length)||"/"}const r=e.indexOf("?"),i=-1===r?e:e.slice(0,r),n=-1===r?void 0:e.slice(r+1);return i.includes("//")?void 0:[i,Oe(i),n]}#V(e,t,r){if(void 0!==r){const i=this.#j.parseQueryString(r);if(this.#j.strictQueryParams){const t=e.declaredQueryParamsSet;for(const e of Object.keys(i))if(!t.has(e))return}for(const e of Object.keys(i))t[e]=i[e]}return{segments:e.matchSegments,params:t,meta:e.meta}}#B(e,t){return(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#G(e,t){return 1===e.length?this.#M.slashChildRoute??this.#M.route:this.#J(this.#M,e,1,t)}#J(e,t,r,i){let n=e;const a=t.length;for(;r<=a;){const e=t.indexOf("/",r),s=-1===e?a:e,o=t.slice(r,s),c=this.#j.caseSensitive?o:o.toLowerCase();let d;if(c in n.staticChildren)d=n.staticChildren[c];else{if(!n.paramChild){if(n.splatChild){const e={},a=this.#J(n.splatChild.node,t,r,e);return a?(Object.assign(i,e),a):(i[n.splatChild.name]=t.slice(r),n.splatChild.node.route)}return}d=n.paramChild.node,i[n.paramChild.name]=o}n=d,r=s+1}return n.slashChildRoute??n.route}#q(e){const t=this.#j.urlParamsEncoding;if("none"===t)return!0;const r=Ee[t];for(const t in e){const i=e[t];if(i.includes("%")){if(!Ce(i))return!1;e[t]=r(i)}}return!0}#W(e,t){for(const[r,i]of t.constraintPatterns)if(!i.pattern.test(e[r]))return!1;return!0}};function Le(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function Ue(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}function _e(e,t,r){const i=function(e){const t=[],r=[],i=[],n={},a=new Map,s=e.replaceAll(be,"$1"),o=Te.exec(s);if(null!==o){const t=o[1].split("&");for(const e of t){const t=e.trim();t.length>0&&(r.push(t),n[t]="query")}e=e.slice(0,o.index)}let c;for(;null!==(c=ye.exec(e));){const e=c[2],r=c[3];if("*"===c[1])i.push(e),t.push(e),n[e]="url";else if(t.push(e),n[e]="url",r){const t=`^${ve(r)}$`;a.set(e,{pattern:new RegExp(t),constraint:r})}}return{urlParams:t,queryParams:r,spatParams:i,paramTypeMap:n,constraintPatterns:a,pathPattern:e}}(e.path),n=function(e){const t={};for(const r of e.urlParams)t[r]="url";for(const r of e.queryParams)t[r]="query";return t}(i),a={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:void 0,paramMeta:i,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:n};a.fullName=function(e){return e.parent?.name?`${e.parent.fullName}.${e.name}`:e.name}(a);const{childrenMap:s,nonAbsoluteChildren:o}=function(e,t,r){const i=[],n=[];for(const a of e){const e=_e(a,t,r);i.push(e),e.absolute||n.push(e)}return{childrenMap:Ue(i),nonAbsoluteChildren:n}}(e.children,a,r);return a.children=s,a.nonAbsoluteChildren=o,a.staticPath=function(e){if(!e.path)return null;const{urlParams:t,queryParams:r,spatParams:i}=e.paramMeta;if(t.length>0||r.length>0||i.length>0)return null;const n=[];let a=e.parent;for(;a?.path;)n.unshift(a),a=a.parent;let s="";for(const e of n){const{urlParams:t,queryParams:r,spatParams:i}=e.paramMeta;if(t.length>0||r.length>0||i.length>0)return null;s=e.absolute?e.path:Le(s,e.path)}return e.absolute?e.path:Le(s,e.path)}(a),r&&(Object.freeze(o),Object.freeze(n),Object.freeze(a.children),Object.freeze(a)),a}function Be(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build(i){const n=function(e,t,r){const i=we({name:e,path:t},null);for(const e of r){const t=we(e,i);i.children.push(t)}return i}(e,t,r);return function(e,t=!0){return _e(e,null,t)}(n,!i?.skipFreeze)}}}function Ve(e,t,r,i){return Be(e,t).addMany(r).build(i)}function Ge(e){const t={name:e.name,path:e.absolute?`~${e.path}`:e.path};return e.children.size>0&&(t.children=[...e.children.values()].map(e=>Ge(e))),t}var We=e=>{const t=e.indexOf("%"),r=e.indexOf("+");if(-1===t&&-1===r)return e;const i=-1===r?e:e.split("+").join(" ");return-1===t?i:decodeURIComponent(i)},qe=e=>{const t=typeof e;if("string"!==t&&"number"!==t&&"boolean"!==t)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===t&&null===e?"null":t}`);return encodeURIComponent(e)},ze={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${qe(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${qe(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${qe(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>qe(e)).join(",")}`}},He={none:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:e=>e},string:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:e=>"true"===e||"false"!==e&&null,decodeValue:e=>e},"empty-true":{encode:(e,t)=>t?e:`${e}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:e=>e}},Qe={default:{encode:e=>e},hidden:{encode:()=>""}},Ke=(e,t,r)=>({boolean:He[t],null:Qe[r],array:ze[e]}),Je={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:He.none,null:Qe.default,array:ze.none}},Ye=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return Je;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",i=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:i,strategies:Ke(t,r,i)}},Ze=e=>encodeURIComponent(e),Xe=(e,t,r)=>{const i=Ze(e);switch(typeof t){case"string":case"number":default:return`${i}=${Ze(t)}`;case"boolean":return r.strategies.boolean.encode(i,t);case"object":return null===t?r.strategies.null.encode(i):Array.isArray(t)?r.strategies.array.encodeArray(i,t):`${i}=${Ze(t)}`}};function et(e,t,r,i,n){const a=e.indexOf("=",t),s=-1!==a&&a<r,o=e.slice(t,s?a:r),{name:c,hasBrackets:d}=function(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}(o);!function(e,t,r,i){const n=e[t];void 0===n?e[t]=i?[r]:r:Array.isArray(n)?n.push(r):e[t]=[n,r]}(i,We(c),function(e,t,r,i,n){return n?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const i=We(e);return t.boolean.decodeValue(i)})(i?e.slice(t+1,r):void 0,n):i?We(e.slice(t+1,r)):null}(e,a,r,s,n),d)}function tt(e){const t=e?.queryParams;return new Ie({...void 0===e?.caseSensitive?void 0:{caseSensitive:e.caseSensitive},...void 0===e?.strictTrailingSlash?void 0:{strictTrailingSlash:e.strictTrailingSlash},...void 0===e?.strictQueryParams?void 0:{strictQueryParams:e.strictQueryParams},...void 0===e?.urlParamsEncoding?void 0:{urlParamsEncoding:e.urlParamsEncoding},parseQueryString:e=>((e,t)=>{const r=(e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)})(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return function(e,t){let r=0;const i=e.length;for(;r<i;){let n=e.indexOf("&",r);-1===n&&(n=i),et(e,r,n,t),r=n+1}}(e,t),t}(r);const i=Ye(t),n={};let a=0;const s=r.length;for(;a<s;){let e=r.indexOf("&",a);-1===e&&(e=s),et(r,a,e,n,i.strategies),a=e+1}return n})(e,t),buildQueryString:e=>((e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const i=Ye(t),n=[];for(const t of r){const r=e[t];if(void 0===r)continue;const a=Xe(t,r,i);a&&n.push(a)}return n.join("&")})(e,t)})}function rt(e,t){return new TypeError(`[router.${e}] ${t}`)}var it=/^[A-Z_a-z][\w-]*$/,nt=/\S/;function at(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function st(e,t){if(!t.includes("."))return e.children.get(t);let r=e;for(const e of t.split("."))if(r=r.children.get(e),!r)return;return r}function ot(e,t,r,i="",n,a){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${at(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${at(e)}`);if(function(e){for(const t of Object.keys(e)){const r=Object.getOwnPropertyDescriptor(e,t);if(r&&(r.get||r.set))return!0}return!1}(e))throw new TypeError(`[router.${t}] Route must not have getters or setters`)}(e,t);const s=e;!function(e,t){if("string"!=typeof e.name)throw new TypeError(`[router.${t}] Route name must be a string, got ${at(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!nt.test(r))throw new TypeError(`[router.${t}] Route name cannot contain only whitespace`);if(r.length>1e4)throw new TypeError(`[router.${t}] Route name exceeds maximum length of 10000 characters`);if(!r.startsWith("@@")){if(r.includes("."))throw new TypeError(`[router.${t}] Route name "${r}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(!it.test(r))throw new TypeError(`[router.${t}] Invalid route name "${r}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}}(s,t),function(e,t,r,i){if("string"!=typeof e){let t;throw t=null===e?"null":Array.isArray(e)?"array":typeof e,rt(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw rt(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw rt(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw rt(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const n=i&&Object.values(i.paramTypeMap).includes("url");if(e.startsWith("~")&&n)throw rt(r,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}(s.path,s.name,t,r),function(e,t){if(void 0!==e.encodeParams&&"function"!=typeof e.encodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}(s,t),function(e,t){if(void 0!==e.decodeParams&&"function"!=typeof e.decodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}(s,t);const o=s.name,c=i?`${i}.${o}`:o;r&&c&&function(e,t,r){if(st(e,t))throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),n&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(n,c,t);const d=s.path,u=i;if(r&&function(e,t,r,i){const n=""===t?e:st(e,t);if(n)for(const e of n.children.values())if(e.path===r)throw new Error(`[router.${i}] Path "${r}" is already defined`)}(r,u,d,t),a&&function(e,t,r,i){const n=e.get(t);if(n?.has(r))throw new Error(`[router.${i}] Path "${r}" is already defined`);n?n.add(r):e.set(t,new Set([r]))}(a,u,d,t),void 0!==s.children){if(!Array.isArray(s.children))throw new TypeError(`[router.${t}] Route "${o}" children must be an array, got ${at(s.children)}`);for(const e of s.children)ot(e,t,r,c,n,a)}}var ct=new Set;function dt(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>dt(e))),t}function ut(e,t,r=""){for(let i=0;i<e.length;i++){const n=e[i],a=r?`${r}.${n.name}`:n.name;if(a===t)return e.splice(i,1),!0;if(n.children&&t.startsWith(`${a}.`)&&ut(n.children,t,a))return!0}return!1}function lt(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function ht(e,t){if(void 0!==e.canActivate&&"function"!=typeof e.canActivate)throw new TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${v(e.canActivate)}`);if(void 0!==e.canDeactivate&&"function"!=typeof e.canDeactivate)throw new TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${v(e.canDeactivate)}`);if(void 0!==e.defaultParams){const r=e.defaultParams;if(null===r||"object"!=typeof r||Array.isArray(r))throw new TypeError(`[router.addRoute] defaultParams must be an object for route "${t}", got ${v(e.defaultParams)}`)}if("AsyncFunction"===e.decodeParams?.constructor.name)throw new TypeError(`[router.addRoute] decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if("AsyncFunction"===e.encodeParams?.constructor.name)throw new TypeError(`[router.addRoute] encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(function(e,t){if(void 0!==e&&"function"==typeof e){const r="AsyncFunction"===e.constructor.name,i=e.toString().includes("__awaiter");if(r||i)throw new TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`)}}(e.forwardTo,t),e.children)for(const r of e.children)ht(r,`${t}.${r.name}`)}function ft(e){const t=new Set,r=/[*:]([A-Z_a-z]\w*)/g;let i;for(;null!==(i=r.exec(e));)t.add(i[1]);return t}function pt(e){const t=new Set;for(const r of e)for(const e of ft(r))t.add(e);return t}function mt(e,t,r="",i=[]){for(const n of e){const e=r?`${r}.${n.name}`:n.name,a=[...i,n.path];if(e===t)return a;if(n.children&&t.startsWith(`${e}.`))return mt(n.children,t,e,a)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function gt(e,t=""){const r=new Set;for(const i of e){const e=t?`${t}.${i.name}`:i.name;if(r.add(e),i.children)for(const t of gt(i.children,e))r.add(t)}return r}function wt(e,t=""){const r=new Map;for(const i of e){const e=t?`${t}.${i.name}`:i.name;if(i.forwardTo&&"string"==typeof i.forwardTo&&r.set(e,i.forwardTo),i.children)for(const[t,n]of wt(i.children,e))r.set(t,n)}return r}function vt(e,t,r,i){if(t){const t=function(e,t){const r=[],i=t.includes(".")?t.split("."):[t];""!==e.path&&r.push(e);let n=e;for(const e of i){const t=n.children.get(e);if(!t)return null;r.push(t),n=t}return r}(r,e);return function(e){const t=new Set;for(const r of e){for(const e of r.paramMeta.urlParams)t.add(e);for(const e of r.paramMeta.spatParams)t.add(e)}return t}(t)}return pt(mt(i,e))}function yt(e,t,r,i,n){const a=function(e,t){const r=t.split(".");let i=e;for(const e of r)if(i=i.children.get(e),!i)return!1;return!0}(n,t),s=i.has(t);if(!a&&!s)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const o=pt(mt(r,e)),c=[...vt(t,a,n,r)].filter(e=>!o.has(e));if(c.length>0)throw new Error(`[router.addRoute] forwardTo target "${t}" requires params [${c.join(", ")}] that are not available in source route "${e}"`)}function bt(e,t,r=100){const i=new Set,n=[e];let a=e;for(;t[a];){const e=t[a];if(i.has(e)){const t=n.indexOf(e),r=[...n.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(i.add(a),n.push(e),a=e,n.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${n.join(" → ")}`)}return a}function Tt(e,t,r){const i=gt(e),n=wt(e),a={...t};for(const[e,t]of n)a[e]=t;for(const[t,a]of n)yt(t,a,e,i,r);for(const e of Object.keys(a))bt(e,a)}function St(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}function Rt(e,t){if("AsyncFunction"===e.constructor.name||e.toString().includes("__awaiter"))throw new TypeError(`[real-router] updateRoute: ${t} cannot be an async function`)}function At(e,t){if(null!=e){if("function"!=typeof e)throw new TypeError(`[real-router] updateRoute: ${t} must be a function or null, got ${typeof e}`);Rt(e,t)}}var Et=".";function Pt(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function Ot(e,t){const r=t.meta?.params[e];if(!r||"object"!=typeof r)return{};const i={};for(const e in r){if(!Object.hasOwn(r,e))continue;if(void 0===r[e])continue;const n=t.params[e];null!=n&&("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n||(i[e]=String(n)))}return i}function $t(e){if(!e)return[""];const t=e.indexOf(Et);if(-1===t)return[e];const r=e.indexOf(Et,t+1);if(-1===r)return[e.slice(0,t),e];const i=e.indexOf(Et,r+1);return-1===i?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(Et,i+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,i),e]:function(e){const t=e.split(Et),r=t.length,i=[t[0]];let n=t[0].length;for(let a=1;a<r-1;a++)n+=1+t[a].length,i.push(e.slice(0,n));return i.push(e),i}(e)}function Dt(e,t){if(!t)return{intersection:"",toActivate:$t(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:$t(e.name),toDeactivate:Pt($t(t.name))};const r=void 0!==e.meta?.params,i=void 0!==t.meta?.params;if(!r&&!i)return{intersection:"",toActivate:$t(e.name),toDeactivate:Pt($t(t.name))};if(e.name===t.name&&r&&i){const r=e.meta&&0===Object.keys(e.meta.params).length,i=t.meta&&0===Object.keys(t.meta.params).length;if(r&&i)return{intersection:e.name,toActivate:[],toDeactivate:[]}}const n=$t(e.name),a=$t(t.name),s=function(e,t,r,i,n){for(let a=0;a<n;a++){const n=r[a],s=i[a];if(n!==s)return a;const o=Ot(n,e),c=Ot(s,t),d=Object.keys(o),u=Object.keys(c);if(d.length!==u.length)return a;for(const e of d)if(o[e]!==c[e])return a}return n}(e,t,n,a,Math.min(a.length,n.length)),o=[];for(let e=a.length-1;e>=s;e--)o.push(a[e]);const c=n.slice(s);return{intersection:s>0?a[s-1]:"",toDeactivate:o,toActivate:c}}var Nt=Object.freeze({}),Ct=class{#Y=[];#Z=function(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}();#X=Object.create(null);#ee=new Map;#te=new Map;#re="";#ie;#ne;#ae;#se;#oe;#ce;get#p(){if(!this.#se)throw new Error("[real-router] RoutesNamespace: dependencies not initialized");return this.#se}constructor(e=[],t=!1,r){this.#ce=t,this.#ae=r;for(const t of e)this.#Y.push(dt(t));this.#ie=Ve("",this.#re,this.#Y),this.#ne=tt(r),this.#ne.registerTree(this.#ie),this.#de(e),t?this.#ue():this.#le()}static validateRemoveRouteArgs(e){!function(e){w(e,"removeRoute")}(e)}static validateSetRootPathArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${v(e)}`)}(e)}static validateAddRouteArgs(e){!function(e){for(const t of e){if(null===t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`[router.addRoute] Route must be an object, got ${v(t)}`);ht(t,t.name)}}(e)}static validateParentOption(e){!function(e){if("string"!=typeof e||""===e)throw new TypeError(`[router.addRoute] parent option must be a non-empty string, got ${v(e)}`);w(e,"addRoute")}(e)}static validateIsActiveRouteArgs(e,t,r,i){!function(e,t,r,i){if(!f(e))throw new TypeError("Route name must be a string");if(void 0!==t&&!l(t))throw new TypeError("[router.isActiveRoute] Invalid params structure");if(void 0!==r&&"boolean"!=typeof r)throw new TypeError("[router.isActiveRoute] strictEquality must be a boolean, got "+typeof r);if(void 0!==i&&"boolean"!=typeof i)throw new TypeError("[router.isActiveRoute] ignoreQueryParams must be a boolean, got "+typeof i)}(e,t,r,i)}static validateStateBuilderArgs(e,t,r){!function(e,t,r){if(!f(e))throw new TypeError(`[router.${r}] Invalid routeName: ${v(e)}. Expected string.`);if(!l(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${v(t)}. Expected plain object.`)}(e,t,r)}static validateUpdateRouteBasicArgs(e,t){!function(e,t){if(w(e,"updateRoute"),""===e)throw new ReferenceError("[router.updateRoute] Invalid name: empty string. Cannot update root node.");if(null===t)throw new TypeError("[real-router] updateRoute: updates must be an object, got null");if("object"!=typeof t||Array.isArray(t))throw new TypeError(`[real-router] updateRoute: updates must be an object, got ${v(t)}`)}(e,t)}static validateUpdateRoutePropertyTypes(e,t,r,i){!function(e,t,r,i){if(null!=e){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError(`[real-router] updateRoute: forwardTo must be a string, function, or null, got ${v(e)}`);"function"==typeof e&&Rt(e,"forwardTo callback")}if(null!=t&&("object"!=typeof t||Array.isArray(t)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${v(t)}`);At(r,"decodeParams"),At(i,"encodeParams")}(e,t,r,i)}static validateBuildPathArgs(e){!function(e){if(!f(e)||""===e)throw new TypeError("[real-router] buildPath: route must be a non-empty string, got "+("string"==typeof e?'""':typeof e))}(e)}static validateMatchPathArgs(e){!function(e){if(!f(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e)}static validateShouldUpdateNodeArgs(e){!function(e){if(!f(e))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof e)}(e)}static validateRoutes(e,t,r,i){!function(e,t,r,i){if(i&&t){let e=t;for(const t of i.split("."))if(e=e.children.get(t),!e)throw new Error(`[router.addRoute] Parent route "${i}" does not exist`)}const n=new Set,a=new Map;for(const r of e)ot(r,"addRoute",t,i??"",n,a);t&&r&&Tt(e,r,t)}(e,t,r,i)}setDependencies(e){this.#se=e;for(const[t,r]of this.#ee)e.addActivateGuard(t,r);this.#ee.clear();for(const[t,r]of this.#te)e.addDeactivateGuard(t,r);this.#te.clear()}setLifecycleNamespace(e){this.#oe=e}getRootPath(){return this.#re}getTree(){return this.#ie}getForwardRecord(){return this.#Z.forwardMap}setRootPath(e){this.#re=e,this.#he()}hasRoute(e){return this.#ne.hasRoute(e)}getRoute(e){const t=this.#ne.getSegmentsByName(e);if(!t)return;const r=Ge(this.#fe(t));return this.#pe(r,e)}addRoutes(e,t){if(t){const r=this.#me(this.#Y,t);r.children??=[];for(const t of e)r.children.push(dt(t))}else for(const t of e)this.#Y.push(dt(t));this.#de(e,t??""),this.#he(),this.#ge()}removeRoute(e){return!!ut(this.#Y,e)&&(this.#we(e),this.#he(),this.#ge(),!0)}updateRouteConfig(e,t){if(void 0!==t.forwardTo&&this.#ve(e,t.forwardTo),void 0!==t.defaultParams&&(null===t.defaultParams?delete this.#Z.defaultParams[e]:this.#Z.defaultParams[e]=t.defaultParams),void 0!==t.decodeParams)if(null===t.decodeParams)delete this.#Z.decoders[e];else{const r=t.decodeParams;this.#Z.decoders[e]=e=>r(e)??e}if(void 0!==t.encodeParams)if(null===t.encodeParams)delete this.#Z.encoders[e];else{const r=t.encodeParams;this.#Z.encoders[e]=e=>r(e)??e}}clearRoutes(){this.#Y.length=0;for(const e in this.#Z.decoders)delete this.#Z.decoders[e];for(const e in this.#Z.encoders)delete this.#Z.encoders[e];for(const e in this.#Z.defaultParams)delete this.#Z.defaultParams[e];for(const e in this.#Z.forwardMap)delete this.#Z.forwardMap[e];for(const e in this.#Z.forwardFnMap)delete this.#Z.forwardFnMap[e];for(const e in this.#X)delete this.#X[e];this.#he()}buildPath(e,t,r){if(e===T.UNKNOWN_ROUTE)return f(t?.path)?t.path:"";const i=Object.hasOwn(this.#Z.defaultParams,e)?{...this.#Z.defaultParams[e],...t}:t??{},n="function"==typeof this.#Z.encoders[e]?this.#Z.encoders[e]({...i}):i,a=r?.trailingSlash;return this.#ne.buildPath(e,n,{trailingSlash:"never"===a||"always"===a?a:void 0,queryParamsMode:r?.queryParamsMode})}matchPath(e,t,r){const i=r,n=this.#ne.match(e);if(!n)return;const a=St(n),{name:s,params:o,meta:c}=a,d="function"==typeof this.#Z.decoders[s]?this.#Z.decoders[s](o):o,{name:u,params:l}=this.#p.forwardState(s,d);let h=e;if(i.rewritePathOnMatch){const e="function"==typeof this.#Z.encoders[u]?this.#Z.encoders[u]({...l}):l,t=i.trailingSlash;h=this.#ne.buildPath(u,e,{trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:i.queryParamsMode})}return this.#p.makeState(u,l,h,{params:c,options:Nt,source:t,redirected:!1})}forwardState(e,t){if(Object.hasOwn(this.#Z.forwardFnMap,e)){const r=this.#ye(e,t),i=this.#Z.forwardFnMap[e],n=this.#be(e,i,t);return{name:n,params:this.#ye(n,r)}}const r=this.#X[e]??e;if(r!==e&&Object.hasOwn(this.#Z.forwardFnMap,r)){const i=this.#ye(e,t),n=this.#Z.forwardFnMap[r],a=this.#be(r,n,t);return{name:a,params:this.#ye(a,i)}}if(r!==e){const i=this.#ye(e,t);return{name:r,params:this.#ye(r,i)}}return{name:e,params:this.#ye(e,t)}}buildStateResolved(e,t){const r=this.#ne.getSegmentsByName(e);if(r)return St({segments:r,params:t,meta:this.#ne.getMetaByName(e)},e)}buildStateWithSegmentsResolved(e,t){const r=this.#ne.getSegmentsByName(e);if(r)return{state:St({segments:r,params:t,meta:this.#ne.getMetaByName(e)},e),segments:r}}isActiveRoute(e,t={},r=!1,i=!0){ct.has(e)||(w(e,"isActiveRoute"),ct.add(e));const n=this.#p.getState();if(!n)return!1;const a=n.name;if(a!==e&&!a.startsWith(`${e}.`)&&!e.startsWith(`${a}.`))return!1;const s=this.#Z.defaultParams[e];if(r||a===e){const r=s?{...s,...t}:t;return this.#p.areStatesEqual({name:e,params:r,path:""},n,i)}const o=n.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(t,o)&&(!s||function(e,t,r){for(const i in e)if(!(i in r)&&e[i]!==t[i])return!1;return!0}(s,o,t))}shouldUpdateNode(e){return(t,r)=>{if(!t||"object"!=typeof t||!("name"in t))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(t.meta?.options.reload)return!0;if(""===e&&!r)return!0;const{intersection:i,toActivate:n,toDeactivate:a}=Dt(t,r);return e===i||!!n.includes(e)||a.includes(e)}}getConfig(){return this.#Z}getUrlParams(e){const t=this.#ne.getSegmentsByName(e);return t?this.#Te(t):[]}getResolvedForwardMap(){return this.#X}setResolvedForwardMap(e){Object.assign(this.#X,e)}applyClonedConfig(e,t){Object.assign(this.#Z.decoders,e.decoders),Object.assign(this.#Z.encoders,e.encoders),Object.assign(this.#Z.defaultParams,e.defaultParams),Object.assign(this.#Z.forwardMap,e.forwardMap),Object.assign(this.#Z.forwardFnMap,e.forwardFnMap),this.setResolvedForwardMap({...t})}cloneRoutes(){return[...this.#ie.children.values()].map(e=>Ge(e))}validateForwardToParamCompatibility(e,t){const r=this.#Se(e),i=this.#Se(t),n=this.#Re(r),a=this.#Te(i).filter(e=>!n.has(e));if(a.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${a.join(", ")}] that are not available in source route "${e}"`)}validateForwardToCycle(e,t){bt(e,{...this.#Z.forwardMap,[e]:t})}validateRemoveRoute(t,r,i){if(r){const i=r===t,n=r.startsWith(`${t}.`);if(i||n)return e.logger.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${i?"":` (current: "${r}")`}. Navigate away first.`),!1}return i&&e.logger.warn("router.removeRoute",`Route "${t}" removed while navigation is in progress. This may cause unexpected behavior.`),!0}validateClearRoutes(t){return!t||(e.logger.error("router.clearRoutes","Cannot clear routes while navigation is in progress. Wait for navigation to complete."),!1)}validateUpdateRoute(e,t){if(!this.hasRoute(e))throw new ReferenceError(`[real-router] updateRoute: route "${e}" does not exist`);if(null!=t&&"string"==typeof t){if(!this.hasRoute(t))throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);this.validateForwardToParamCompatibility(e,t),this.validateForwardToCycle(e,t)}}#ve(e,t){null===t?(delete this.#Z.forwardMap[e],delete this.#Z.forwardFnMap[e]):"string"==typeof t?(delete this.#Z.forwardFnMap[e],this.#Z.forwardMap[e]=t):(delete this.#Z.forwardMap[e],this.#Z.forwardFnMap[e]=t),this.#ge()}#ye(e,t){return Object.hasOwn(this.#Z.defaultParams,e)?{...this.#Z.defaultParams[e],...t}:t}#be(e,t,r){const i=new Set([e]);let n=t(this.#p.getDependency,r),a=0;if("string"!=typeof n)throw new TypeError("forwardTo callback must return a string, got "+typeof n);for(;a<100;){if(void 0===this.#ne.getSegmentsByName(n))throw new Error(`Route "${n}" does not exist`);if(i.has(n)){const e=[...i,n].join(" → ");throw new Error(`Circular forwardTo detected: ${e}`)}if(i.add(n),Object.hasOwn(this.#Z.forwardFnMap,n)){n=(0,this.#Z.forwardFnMap[n])(this.#p.getDependency,r),a++;continue}const e=this.#Z.forwardMap[n];if(void 0===e)return n;n=e,a++}throw new Error("forwardTo exceeds maximum depth of 100")}#he(){this.#ie=Ve("",this.#re,this.#Y),this.#ne=tt(this.#ae),this.#ne.registerTree(this.#ie)}#Se(e){return this.#ne.getSegmentsByName(e)}#fe(e){return e.at(-1)}#Re(e){const t=new Set;for(const r of e)for(const e of r.paramMeta.urlParams)t.add(e);return t}#Te(e){const t=[];for(const r of e)for(const e of r.paramMeta.urlParams)t.push(e);return t}#ge(){this.#ce?this.#ue():this.#le()}#le(){for(const e in this.#X)delete this.#X[e];for(const e of Object.keys(this.#Z.forwardMap))this.#X[e]=bt(e,this.#Z.forwardMap)}#ue(){for(const e in this.#X)delete this.#X[e];for(const e of Object.keys(this.#Z.forwardMap)){let t=e;for(;this.#Z.forwardMap[t];)t=this.#Z.forwardMap[t];this.#X[e]=t}}#we(e){const t=t=>t===e||t.startsWith(`${e}.`);lt(this.#Z.decoders,t),lt(this.#Z.encoders,t),lt(this.#Z.defaultParams,t),lt(this.#Z.forwardMap,t),lt(this.#Z.forwardFnMap,t),lt(this.#Z.forwardMap,e=>t(this.#Z.forwardMap[e]));const[r,i]=this.#oe.getFactories();for(const e of Object.keys(i))t(e)&&this.#oe.clearCanActivate(e);for(const e of Object.keys(r))t(e)&&this.#oe.clearCanDeactivate(e)}#de(e,t=""){for(const r of e){const e=t?`${t}.${r.name}`:r.name;this.#Ae(r,e),r.children&&this.#de(r.children,e)}}#Ae(e,t){e.canActivate&&(this.#se?this.#se.addActivateGuard(t,e.canActivate):this.#ee.set(t,e.canActivate)),e.canDeactivate&&(this.#se?this.#se.addDeactivateGuard(t,e.canDeactivate):this.#te.set(t,e.canDeactivate)),e.forwardTo&&this.#Ee(e,t),e.decodeParams&&(this.#Z.decoders[t]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(this.#Z.encoders[t]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(this.#Z.defaultParams[t]=e.defaultParams)}#me(e,t,r=""){for(const i of e){const e=r?`${r}.${i.name}`:i.name;if(e===t)return i;if(i.children&&t.startsWith(`${e}.`))return this.#me(i.children,t,e)}}#Ee(t,r){if(t.canActivate&&e.logger.warn("real-router",`Route "${r}" 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&&e.logger.warn("real-router",`Route "${r}" 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 e="AsyncFunction"===t.forwardTo.constructor.name,i=t.forwardTo.toString().includes("__awaiter");if(e||i)throw new TypeError(`forwardTo callback cannot be async for route "${r}". Async functions break matchPath/buildPath.`)}"string"==typeof t.forwardTo?this.#Z.forwardMap[r]=t.forwardTo:this.#Z.forwardFnMap[r]=t.forwardTo}#pe(e,t){const r={name:e.name,path:e.path},i=this.#Z.forwardFnMap[t],n=this.#Z.forwardMap[t];void 0!==i?r.forwardTo=i:void 0!==n&&(r.forwardTo=n),t in this.#Z.defaultParams&&(r.defaultParams=this.#Z.defaultParams[t]),t in this.#Z.decoders&&(r.decodeParams=this.#Z.decoders[t]),t in this.#Z.encoders&&(r.encodeParams=this.#Z.encoders[t]);const[a,s]=this.#oe.getFactories();return t in s&&(r.canActivate=s[t]),t in a&&(r.canDeactivate=a[t]),e.children&&(r.children=e.children.map(e=>this.#pe(e,`${t}.${e.name}`))),r}},jt=new Set(["code","segment","path","redirect"]),Mt=new Set(Object.values(b)),Ft=new Set(["code","segment","path","redirect"]),xt=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),kt=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:i,redirect:n,...a}={}){super(t??e),this.code=e,this.segment=r,this.path=i,this.redirect=n?function(e){if(!e)return e;if(null===(t=e)||"object"!=typeof t||"string"!=typeof t.name||"string"!=typeof t.path||"object"!=typeof t.params||null===t.params)throw new TypeError("[deepFreezeState] Expected valid State object, got: "+typeof e);var t;const r=structuredClone(e),i=new WeakSet;return function e(t){if(null===t||"object"!=typeof t)return;if(i.has(t))return;i.add(t),Object.freeze(t);const r=Array.isArray(t)?t:Object.values(t);for(const t of r)e(t)}(r),r}(n):void 0;for(const[e,t]of Object.entries(a)){if(Ft.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);xt.has(e)||(this[e]=t)}}setCode(e){this.code=e,Mt.has(this.message)&&(this.message=e)}setErrorInstance(e){if(!e)throw new TypeError("[RouterError.setErrorInstance] err parameter is required and must be an Error instance");this.message=e.message,this.cause=e.cause,this.stack=e.stack??""}setAdditionalFields(e){for(const[t,r]of Object.entries(e)){if(Ft.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);xt.has(t)||(this[t]=r)}}hasField(e){return e in this}getField(e){return this[e]}toJSON(){const e={code:this.code,message:this.message};void 0!==this.segment&&(e.segment=this.segment),void 0!==this.path&&(e.path=this.path),void 0!==this.redirect&&(e.redirect=this.redirect);const t=new Set(["code","message","segment","path","redirect","stack"]);for(const r in this)Object.hasOwn(this,r)&&!t.has(r)&&(e[r]=this[r]);return e}};function It(e,t,r){if(e instanceof kt)throw e.setCode(t),e;throw new kt(t,function(e,t){const r=t?{segment:t}:{};if(e instanceof Error)return{...r,message:e.message,stack:e.stack,..."cause"in e&&void 0!==e.cause&&{cause:e.cause}};if(e&&"object"==typeof e){const t={};for(const[r,i]of Object.entries(e))jt.has(r)||(t[r]=i);return{...r,...t}}return r}(e,r))}var Lt=(e,t)=>{const r=e.meta,i=t.meta,n=r?.params,a=i?.params,s=n&&a?{...n,...a}:n??a??{},o={id:1,options:{},redirected:!1,...i,...r,params:s};return{...e,meta:o}},Ut=async(e,t,r)=>{const i=r?{segment:r}:{};if(void 0===e)return t;if("boolean"==typeof e){if(e)return t;throw new kt(b.TRANSITION_ERR,i)}if(h(e))return e;if(m(e))try{const i=await e;return await Ut(i,t,r)}catch(e){throw new kt(b.TRANSITION_ERR,function(e,t){return e instanceof Error?{...t,message:e.message,stack:e.stack,..."cause"in e&&void 0!==e.cause&&{cause:e.cause}}:e&&"object"==typeof e?{...t,...e}:t}(e,i))}throw new kt(b.TRANSITION_ERR,{...i,message:"Invalid lifecycle result type: "+typeof e})},_t=async(t,r,i,n,a,s)=>{let o=r;const c=n.filter(e=>t.has(e));if(0===c.length)return o;for(const r of c){if(s())throw new kt(b.TRANSITION_CANCELLED);const n=t.get(r);try{const t=n(o,i),s=await Ut(t,o,r);if(s!==o&&h(s)){if(s.name!==o.name)throw new kt(a,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:s.name,params:s.params,path:s.path}});(s.params!==o.params||s.path!==o.path)&&e.logger.error("core:transition","Warning: State mutated during transition",{from:o,to:s}),o=Lt(s,o)}}catch(e){It(e,a,r)}}return o};var Bt=class t{#Pe;#p;#Oe;static validateNavigateArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${v(e)}`)}(e)}static validateNavigateToStateArgs(e,t,r){!function(e,t,r){if(!e||"object"!=typeof e||"string"!=typeof e.name||"string"!=typeof e.path)throw new TypeError("[router.navigateToState] Invalid toState: expected State object with name and path");if(void 0!==t&&(!t||"object"!=typeof t||"string"!=typeof t.name))throw new TypeError("[router.navigateToState] Invalid fromState: expected State object or undefined");if("object"!=typeof r||null===r)throw new TypeError(`[router.navigateToState] Invalid opts: expected NavigationOptions object, got ${v(r)}`)}(e,t,r)}static validateNavigateToDefaultArgs(e){!function(e){if(void 0!==e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${v(e)}. Expected NavigationOptions object.`)}(e)}static validateNavigationOptions(e,t){!function(e,t){if(!function(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=e;for(const e of a){const r=t[e];if(void 0!==r&&"boolean"!=typeof r)return!1}return!0}(e))throw new TypeError(`[router.${t}] Invalid options: ${v(e)}. Expected NavigationOptions object.`)}(e,t)}setCanNavigate(e){this.#Pe=e}setDependencies(e){this.#p=e}setTransitionDependencies(e){this.#Oe=e}async navigate(e,t,r){if(!this.#Pe())throw new kt(b.ROUTER_NOT_STARTED);const i=this.#p,n=i.buildStateWithSegments(e,t);if(!n){const e=new kt(b.ROUTE_NOT_FOUND);throw i.emitTransitionError(void 0,i.getState(),e),e}const{state:a}=n,s=i.makeState(a.name,a.params,i.buildPath(a.name,a.params),{params:a.meta,options:r,redirected:r.redirected??!1}),o=i.getState();if(!r.reload&&!r.force&&i.areStatesEqual(o,s,!1)){const e=new kt(b.SAME_STATES);throw i.emitTransitionError(s,o,e),e}return this.navigateToState(s,o,r)}async navigateToState(r,i,n){const a=this.#p,s=this.#Oe;s.isTransitioning()&&(e.logger.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use router.clone() to create isolated instance per request."),a.cancelNavigation()),a.startTransition(r,i);try{const{state:o,meta:c}=await async function(t,r,i,n){const[a,s]=t.getLifecycleFunctions(),o=t.getMiddlewareFunctions(),c=r.name===T.UNKNOWN_ROUTE,d=()=>!t.isActive(),{toDeactivate:u,toActivate:l,intersection:f}=Dt(r,i),p=!c&&l.length>0,m=o.length>0;let g=r;if(i&&!n.forceDeactivate&&u.length>0&&(g=await _t(a,r,i,u,b.CANNOT_DEACTIVATE,d)),d())throw new kt(b.TRANSITION_CANCELLED);if(p&&(g=await _t(s,g,i,l,b.CANNOT_ACTIVATE,d)),d())throw new kt(b.TRANSITION_CANCELLED);if(m&&(g=await(async(t,r,i,n)=>{let a=r;for(const r of t){if(n())throw new kt(b.TRANSITION_CANCELLED);try{const t=r(a,i),n=await Ut(t,a);n!==a&&h(n)&&((n.name!==a.name||n.params!==a.params||n.path!==a.path)&&e.logger.error("core:middleware","Warning: State mutated during middleware execution",{from:a,to:n}),a=Lt(n,a))}catch(e){It(e,b.TRANSITION_ERR)}}return a})(o,g,i,d)),d())throw new kt(b.TRANSITION_CANCELLED);if(i){const e=$t(r.name),n=$t(i.name);for(const r of n)!e.includes(r)&&a.has(r)&&t.clearCanDeactivate(r)}return{state:g,meta:{phase:"middleware",segments:{deactivated:u,activated:l,intersection:f}}}}(s,r,i,n);if(o.name===T.UNKNOWN_ROUTE||a.hasRoute(o.name)){const e=t.#$e(o,c,i);return a.setState(e),a.sendTransitionDone(e,i,n),e}{const e=new kt(b.ROUTE_NOT_FOUND,{routeName:o.name});throw a.sendTransitionError(o,i,e),e}}catch(e){throw this.#De(e,r,i),e}}async navigateToDefault(e){const t=this.#p,r=t.getOptions();if(!r.defaultRoute)throw new kt(b.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"});const i=te(r.defaultRoute,t.getDependency);if(!i)throw new kt(b.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"});const n=te(r.defaultParams,t.getDependency);return this.navigate(i,n,e)}static#$e(e,t,r){const i={phase:t.phase,...void 0!==r?.name&&{from:r.name},reason:"success",segments:t.segments};return Object.freeze(i.segments.deactivated),Object.freeze(i.segments.activated),Object.freeze(i.segments),Object.freeze(i),{...e,transition:i}}#De(e,t,r){const i=e;i.code!==b.TRANSITION_CANCELLED&&i.code!==b.ROUTE_NOT_FOUND&&(i.code===b.CANNOT_ACTIVATE||i.code===b.CANNOT_DEACTIVATE?this.#p.sendTransitionBlocked(t,r,i):this.#p.sendTransitionError(t,r,i))}},Vt=class{#Ne;#p;static validateStartArgs(e){if(1!==e.length||"string"!=typeof e[0])throw new Error("[router.start] Expected exactly 1 string argument (startPath).")}setNavigateToState(e){this.#Ne=e}setDependencies(e){this.#p=e}async start(e){const t=this.#p,r=t.getOptions(),i={replace:!0},n=t.matchPath(e);if(!n&&!r.allowNotFound){const r=new kt(b.ROUTE_NOT_FOUND,{path:e});throw t.emitTransitionError(void 0,void 0,r),r}let a;if(t.completeStart(),n)a=await this.#Ne(n,void 0,i);else{const r=t.makeNotFoundState(e,i);a=await this.#Ne(r,void 0,i)}return a}stop(){this.#p.setState()}},Gt=class{#Ce;static validateCloneArgs(e){if(void 0!==e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.clone] Invalid dependencies: expected plain object or undefined, received ${v(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[router.clone] Getters not allowed in dependencies: "${t}"`)}}setGetCloneData(e){this.#Ce=e}clone(e,t,r){const i=this.#Ce(),n={...i.dependencies,...e},a=t(i.routes,i.options,n);for(const[e,t]of Object.entries(i.canDeactivateFactories))a.addDeactivateGuard(e,t);for(const[e,t]of Object.entries(i.canActivateFactories))a.addActivateGuard(e,t);return i.middlewareFactories.length>0&&a.useMiddleware(...i.middlewareFactories),i.pluginFactories.length>0&&a.usePlugin(...i.pluginFactories),r(a,i.routeConfig,i.resolvedForwardMap),a}},Wt=class e{#je;#Me;#Fe;constructor(e){this.#je=e.routerFSM,this.#Me=e.emitter,this.#Fe=void 0,this.#xe()}static validateEventName(e){if(!D.has(e))throw new Error(`Invalid event name: ${String(e)}`)}static validateListenerArgs(t,r){if(e.validateEventName(t),"function"!=typeof r)throw new TypeError(`Expected callback to be a function for event ${t}`)}static validateSubscribeListener(e){if("function"!=typeof e)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#Me.emit($.ROUTER_START)}emitRouterStop(){this.#Me.emit($.ROUTER_STOP)}emitTransitionStart(e,t){this.#Me.emit($.TRANSITION_START,e,t)}emitTransitionSuccess(e,t,r){this.#Me.emit($.TRANSITION_SUCCESS,e,t,r)}emitTransitionError(e,t,r){this.#Me.emit($.TRANSITION_ERROR,e,t,r)}emitTransitionCancel(e,t){this.#Me.emit($.TRANSITION_CANCEL,e,t)}sendStart(){this.#je.send(I)}sendStop(){this.#je.send(G)}sendDispose(){this.#je.send(W)}completeStart(){this.#je.send(L)}beginTransition(e,t){this.#Fe=e,this.#je.send(U,{toState:e,fromState:t})}completeTransition(e,t,r={}){this.#je.send(_,{state:e,fromState:t,opts:r}),this.#Fe=void 0}failTransition(e,t,r){this.#je.send(B,{toState:e,fromState:t,error:r}),this.#Fe=void 0}cancelTransition(e,t){this.#je.send(V,{toState:e,fromState:t}),this.#Fe=void 0}emitOrFailTransitionError(e,t,r){this.#je.getState()===F?this.#je.send(B,{toState:e,fromState:t,error:r}):this.emitTransitionError(e,t,r)}canBeginTransition(){return this.#je.canSend(U)}canStart(){return this.#je.canSend(I)}canCancel(){return this.#je.canSend(V)}isActive(){const e=this.#je.getState();return e!==j&&e!==k}isDisposed(){return this.#je.getState()===k}isTransitioning(){return this.#je.getState()===x}isReady(){return this.#je.getState()===F}getCurrentToState(){return this.#Fe}addEventListener(e,t){return this.#Me.on(e,t)}subscribe(e){return this.#Me.on($.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}clearAll(){this.#Me.clearAll()}setLimits(e){this.#Me.setLimits(e)}cancelTransitionIfRunning(e){this.canCancel()&&this.cancelTransition(this.#Fe,e)}#xe(){const e=this.#je;e.on(M,L,()=>{this.emitRouterStart()}),e.on(F,G,()=>{this.emitRouterStop()}),e.on(F,U,e=>{this.emitTransitionStart(e.toState,e.fromState)}),e.on(x,_,e=>{this.emitTransitionSuccess(e.state,e.fromState,e.opts)}),e.on(x,V,e=>{this.emitTransitionCancel(e.toState,e.fromState)}),e.on(M,B,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(F,B,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(x,B,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)})}},qt=new kt(b.ROUTER_ALREADY_STARTED),zt=new Set(["all","warn-error","error-only"]);var Ht=class{router;options;limits;dependencies;state;routes;routeLifecycle;middleware;plugins;navigation;lifecycle;clone;eventBus;constructor(e){this.router=e.router,this.options=e.options,this.limits=e.limits,this.dependencies=e.dependencies,this.state=e.state,this.routes=e.routes,this.routeLifecycle=e.routeLifecycle,this.middleware=e.middleware,this.plugins=e.plugins,this.navigation=e.navigation,this.lifecycle=e.lifecycle,this.clone=e.clone,this.eventBus=e.eventBus}wireLimits(){this.dependencies.setLimits(this.limits),this.plugins.setLimits(this.limits),this.middleware.setLimits(this.limits),this.eventBus.setLimits({maxListeners:this.limits.maxListeners,warnListeners:this.limits.warnListeners,maxEventDepth:this.limits.maxEventDepth}),this.routeLifecycle.setLimits(this.limits)}wireRouteLifecycleDeps(){this.routeLifecycle.setRouter(this.router),this.routeLifecycle.setDependencies({getDependency:e=>this.dependencies.get(e)})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(e,t)=>{this.router.addActivateGuard(e,t)},addDeactivateGuard:(e,t)=>{this.router.addDeactivateGuard(e,t)},makeState:(e,t,r,i)=>this.state.makeState(e,t,r,i),getState:()=>this.state.get(),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependencies.get(e),forwardState:(e,t)=>this.router.forwardState(e,t)}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wireMiddlewareDeps(){this.middleware.setRouter(this.router),this.middleware.setDependencies({getDependency:e=>this.dependencies.get(e)})}wirePluginsDeps(){this.plugins.setRouter(this.router),this.plugins.setDependencies({addEventListener:(e,t)=>this.eventBus.addEventListener(e,t),canNavigate:()=>this.eventBus.canBeginTransition(),getDependency:e=>this.dependencies.get(e)})}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:e=>this.routes.hasRoute(e),getState:()=>this.state.get(),setState:e=>{this.state.set(e)},buildStateWithSegments:(e,t)=>{const{name:r,params:i}=this.router.forwardState(e,t);return this.routes.buildStateWithSegmentsResolved(r,i)},makeState:(e,t,r,i)=>this.state.makeState(e,t,r,i),buildPath:(e,t)=>this.routes.buildPath(e,t,this.options.get()),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependencies.get(e),startTransition:(e,t)=>{this.eventBus.beginTransition(e,t)},cancelNavigation:()=>{this.eventBus.cancelTransition(this.eventBus.getCurrentToState(),this.state.get())},sendTransitionDone:(e,t,r)=>{this.eventBus.completeTransition(e,t,r)},sendTransitionBlocked:(e,t,r)=>{this.eventBus.failTransition(e,t,r)},sendTransitionError:(e,t,r)=>{this.eventBus.failTransition(e,t,r)},emitTransitionError:(e,t,r)=>{this.eventBus.emitOrFailTransitionError(e,t,r)}}),this.navigation.setTransitionDependencies({getLifecycleFunctions:()=>this.routeLifecycle.getFunctions(),getMiddlewareFunctions:()=>this.middleware.getFunctions(),isActive:()=>this.router.isActive(),isTransitioning:()=>this.eventBus.isTransitioning(),clearCanDeactivate:e=>{this.routeLifecycle.clearCanDeactivate(e)}})}wireLifecycleDeps(){this.lifecycle.setDependencies({getOptions:()=>this.options.get(),makeNotFoundState:(e,t)=>this.state.makeNotFoundState(e,t),setState:e=>{this.state.set(e)},matchPath:(e,t)=>this.routes.matchPath(e,t,this.options.get()),completeStart:()=>{this.eventBus.completeStart()},emitTransitionError:(e,t,r)=>{this.eventBus.failTransition(e,t,r)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getConfig().defaultParams,buildPath:(e,t)=>this.routes.buildPath(e,t,this.options.get()),getUrlParams:e=>this.routes.getUrlParams(e)})}wireCloneCallbacks(){this.clone.setGetCloneData(()=>{const[e,t]=this.routeLifecycle.getFactories();return{routes:this.routes.cloneRoutes(),options:{...this.options.get()},dependencies:this.dependencies.getAll(),canDeactivateFactories:e,canActivateFactories:t,middlewareFactories:this.middleware.getFactories(),pluginFactories:this.plugins.getAll(),routeConfig:this.routes.getConfig(),resolvedForwardMap:this.routes.getResolvedForwardMap()}})}wireCyclicDeps(){this.navigation.setCanNavigate(()=>this.eventBus.canBeginTransition()),this.lifecycle.setNavigateToState((e,t,r)=>this.navigation.navigateToState(e,t,r))}},Qt=class r{#u;#r;#c;#ke;#Ie;#Le;#Ue;#T;#_e;#Be;#Ve;#Ge;#ce;constructor(r=[],i={},a={}){i.logger&&function(e){if("object"!=typeof e||null===e)throw new TypeError("Logger config must be an object");const t=e;for(const e of Object.keys(t))if("level"!==e&&"callback"!==e)throw new TypeError(`Unknown logger config property: "${e}"`);if("level"in t&&void 0!==t.level&&("string"!=typeof(r=t.level)||!zt.has(r)))throw new TypeError(`Invalid logger level: ${function(e){return"string"==typeof e?`"${e}"`:"object"==typeof e?JSON.stringify(e):String(e)}(t.level)}. Expected: "all" | "warn-error" | "error-only"`);var r;if("callback"in t&&void 0!==t.callback&&"function"!=typeof t.callback)throw new TypeError("Logger callback must be a function, got "+typeof t.callback);return!0}(i.logger)&&(e.logger.configure(i.logger),delete i.logger),ae.validateOptions(i,"constructor");const s=i.noValidate??!1;s||J.validateDependenciesObject(a,"constructor"),!s&&r.length>0&&(Ct.validateAddRouteArgs(r),Ct.validateRoutes(r)),this.#u=new ae(i),this.#r=function(e={}){return{...N,...e}}(i.limits),this.#c=new J(a),this.#ke=new oe,this.#Ie=new Ct(r,s,function(e){return{strictTrailingSlash:"strict"===e.trailingSlash,strictQueryParams:"strict"===e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding,queryParams:e.queryParams}}(this.#u.get())),this.#Le=new ge,this.#Ue=new de,this.#T=new fe,this.#_e=new Bt,this.#Be=new Vt,this.#Ve=new Gt,this.#ce=s;const o=new t.FSM(q),c=new n({onListenerError:(t,r)=>{e.logger.error("Router",`Error in listener for ${t}:`,r)},onListenerWarn:(t,r)=>{e.logger.warn("router.addEventListener",`Event "${t}" has ${r} listeners — possible memory leak`)}});var d;this.#Ge=new Wt({routerFSM:o,emitter:c}),(d=new Ht({router:this,options:this.#u,limits:this.#r,dependencies:this.#c,state:this.#ke,routes:this.#Ie,routeLifecycle:this.#Le,middleware:this.#Ue,plugins:this.#T,navigation:this.#_e,lifecycle:this.#Be,clone:this.#Ve,eventBus:this.#Ge})).wireLimits(),d.wireRouteLifecycleDeps(),d.wireRoutesDeps(),d.wireMiddlewareDeps(),d.wirePluginsDeps(),d.wireNavigationDeps(),d.wireLifecycleDeps(),d.wireStateDeps(),d.wireCloneCallbacks(),d.wireCyclicDeps(),this.addRoute=this.addRoute.bind(this),this.removeRoute=this.removeRoute.bind(this),this.clearRoutes=this.clearRoutes.bind(this),this.getRoute=this.getRoute.bind(this),this.hasRoute=this.hasRoute.bind(this),this.updateRoute=this.updateRoute.bind(this),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.matchPath=this.matchPath.bind(this),this.setRootPath=this.setRootPath.bind(this),this.getRootPath=this.getRootPath.bind(this),this.makeState=this.makeState.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.forwardState=this.forwardState.bind(this),this.buildState=this.buildState.bind(this),this.buildNavigationState=this.buildNavigationState.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.getOptions=this.getOptions.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.addActivateGuard=this.addActivateGuard.bind(this),this.addDeactivateGuard=this.addDeactivateGuard.bind(this),this.removeActivateGuard=this.removeActivateGuard.bind(this),this.removeDeactivateGuard=this.removeDeactivateGuard.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.useMiddleware=this.useMiddleware.bind(this),this.setDependency=this.setDependency.bind(this),this.setDependencies=this.setDependencies.bind(this),this.getDependency=this.getDependency.bind(this),this.getDependencies=this.getDependencies.bind(this),this.removeDependency=this.removeDependency.bind(this),this.hasDependency=this.hasDependency.bind(this),this.resetDependencies=this.resetDependencies.bind(this),this.addEventListener=this.addEventListener.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToState=this.navigateToState.bind(this),this.subscribe=this.subscribe.bind(this),this.clone=this.clone.bind(this)}addRoute(e,t){const r=Array.isArray(e)?e:[e],i=t?.parent;return this.#ce||(void 0!==i&&Ct.validateParentOption(i),Ct.validateAddRouteArgs(r),Ct.validateRoutes(r,this.#Ie.getTree(),this.#Ie.getForwardRecord(),i)),this.#Ie.addRoutes(r,i),this}removeRoute(t){return this.#ce||Ct.validateRemoveRouteArgs(t),this.#Ie.validateRemoveRoute(t,this.#ke.get()?.name,this.#Ge.isTransitioning())?(this.#Ie.removeRoute(t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),this):this}clearRoutes(){const e=this.#Ge.isTransitioning();return this.#Ie.validateClearRoutes(e)?(this.#Ie.clearRoutes(),this.#Le.clearAll(),this.#ke.set(void 0),this):this}getRoute(e){return this.#ce||w(e,"getRoute"),this.#Ie.getRoute(e)}hasRoute(e){return this.#ce||w(e,"hasRoute"),this.#Ie.hasRoute(e)}updateRoute(t,r){this.#ce||Ct.validateUpdateRouteBasicArgs(t,r);const{forwardTo:i,defaultParams:n,decodeParams:a,encodeParams:s,canActivate:o,canDeactivate:c}=r;return this.#ce||Ct.validateUpdateRoutePropertyTypes(i,n,a,s),this.#Ge.isTransitioning()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),this.#ce||this.#Ie.validateUpdateRoute(t,i),this.#Ie.updateRouteConfig(t,{forwardTo:i,defaultParams:n,decodeParams:a,encodeParams:s}),void 0!==o&&(null===o?this.#Le.clearCanActivate(t):this.addActivateGuard(t,o)),void 0!==c&&(null===c?this.#Le.clearCanDeactivate(t):this.addDeactivateGuard(t,c)),this}isActiveRoute(t,r,i,n){return this.#ce||Ct.validateIsActiveRouteArgs(t,r,i,n),""===t?(e.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#Ie.isActiveRoute(t,r,i,n)}buildPath(e,t){return this.#ce||Ct.validateBuildPathArgs(e),this.#Ie.buildPath(e,t,this.#u.get())}matchPath(e,t){return this.#ce||Ct.validateMatchPathArgs(e),this.#Ie.matchPath(e,t,this.#u.get())}setRootPath(e){this.#ce||Ct.validateSetRootPathArgs(e),this.#Ie.setRootPath(e)}getRootPath(){return this.#Ie.getRootPath()}makeState(e,t,r,i,n){return this.#ce||oe.validateMakeStateArgs(e,t,r,n),this.#ke.makeState(e,t,r,i,n)}getState(){return this.#ke.get()}getPreviousState(){return this.#ke.getPrevious()}areStatesEqual(e,t,r=!0){return this.#ce||oe.validateAreStatesEqualArgs(e,t,r),this.#ke.areStatesEqual(e,t,r)}forwardState(e,t){return this.#ce||Ct.validateStateBuilderArgs(e,t,"forwardState"),this.#Ie.forwardState(e,t)}buildState(e,t){this.#ce||Ct.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:i}=this.forwardState(e,t);return this.#Ie.buildStateResolved(r,i)}buildNavigationState(e,t={}){this.#ce||Ct.validateStateBuilderArgs(e,t,"buildNavigationState");const r=this.buildState(e,t);if(r)return this.makeState(r.name,r.params,this.buildPath(r.name,r.params),{params:r.meta,options:{},redirected:!1})}shouldUpdateNode(e){return this.#ce||Ct.validateShouldUpdateNodeArgs(e),this.#Ie.shouldUpdateNode(e)}getOptions(){return this.#u.get()}isActive(){return this.#Ge.isActive()}async start(e){if(this.#ce||Vt.validateStartArgs([e]),!this.#Ge.canStart())throw qt;this.#Ge.sendStart();try{return await this.#Be.start(e)}catch(e){throw this.#Ge.isReady()&&(this.#Be.stop(),this.#Ge.sendStop()),e}}stop(){return this.#Ge.cancelTransitionIfRunning(this.#ke.get()),this.#Ge.isReady()||this.#Ge.isTransitioning()?(this.#Be.stop(),this.#Ge.sendStop(),this):this}dispose(){this.#Ge.isDisposed()||(this.#Ge.cancelTransitionIfRunning(this.#ke.get()),(this.#Ge.isReady()||this.#Ge.isTransitioning())&&(this.#Be.stop(),this.#Ge.sendStop()),this.#Ge.sendDispose(),this.#Ge.clearAll(),this.#T.disposeAll(),this.#Ue.clearAll(),this.#Ie.clearRoutes(),this.#Le.clearAll(),this.#ke.reset(),this.#c.reset(),this.#We())}addDeactivateGuard(e,t){return this.#ce||(w(e,"addDeactivateGuard"),ge.validateHandler(t,"addDeactivateGuard")),this.#Le.addCanDeactivate(e,t,this.#ce),this}addActivateGuard(e,t){return this.#ce||(w(e,"addActivateGuard"),ge.validateHandler(t,"addActivateGuard")),this.#Le.addCanActivate(e,t,this.#ce),this}removeActivateGuard(e){this.#ce||w(e,"removeActivateGuard"),this.#Le.clearCanActivate(e)}removeDeactivateGuard(e){this.#ce||w(e,"removeDeactivateGuard"),this.#Le.clearCanDeactivate(e)}canNavigateTo(e,t){if(this.#ce||w(e,"canNavigateTo"),!this.hasRoute(e))return!1;const{name:r,params:i}=this.forwardState(e,t??{}),n=this.makeState(r,i),a=this.getState(),{toDeactivate:s,toActivate:o}=Dt(n,a);for(const e of s)if(!this.#Le.checkDeactivateGuardSync(e,n,a))return!1;for(const e of o)if(!this.#Le.checkActivateGuardSync(e,n,a))return!1;return!0}usePlugin(...e){return this.#ce||(fe.validateUsePluginArgs(e),fe.validatePluginLimit(this.#T.count(),e.length,this.#r.maxPlugins),fe.validateNoDuplicatePlugins(e,this.#T.has.bind(this.#T))),this.#T.use(...e)}useMiddleware(...e){this.#ce||(de.validateUseMiddlewareArgs(e),de.validateNoDuplicates(e,this.#Ue.getFactories()),de.validateMiddlewareLimit(this.#Ue.count(),e.length,this.#r.maxMiddleware));const t=this.#Ue.initialize(...e);if(!this.#ce)for(const{middleware:e,factory:r}of t)de.validateMiddleware(e,r);return this.#Ue.commit(t)}setDependency(e,t){return this.#ce||J.validateSetDependencyArgs(e),this.#c.set(e,t),this}setDependencies(e){return this.#ce||(J.validateDependenciesObject(e,"setDependencies"),J.validateDependencyLimit(this.#c.count(),Object.keys(e).length,"setDependencies",this.#r.maxDependencies)),this.#c.setMultiple(e),this}getDependency(e){this.#ce||J.validateName(e,"getDependency");const t=this.#c.get(e);return this.#ce||J.validateDependencyExists(t,e),t}getDependencies(){return this.#c.getAll()}removeDependency(e){return this.#ce||J.validateName(e,"removeDependency"),this.#c.remove(e),this}hasDependency(e){return this.#ce||J.validateName(e,"hasDependency"),this.#c.has(e)}resetDependencies(){return this.#c.reset(),this}addEventListener(e,t){return this.#ce||Wt.validateListenerArgs(e,t),this.#Ge.addEventListener(e,t)}subscribe(e){return this.#ce||Wt.validateSubscribeListener(e),this.#Ge.subscribe(e)}navigate(e,t,i){this.#ce||Bt.validateNavigateArgs(e);const n=i??{};this.#ce||Bt.validateNavigationOptions(n,"navigate");const a=this.#_e.navigate(e,t??{},n);return r.#qe(a),a}navigateToDefault(e){this.#ce||Bt.validateNavigateToDefaultArgs(e);const t=e??{};this.#ce||Bt.validateNavigationOptions(t,"navigateToDefault");const i=this.#_e.navigateToDefault(t);return r.#qe(i),i}navigateToState(e,t,r){return this.#ce||Bt.validateNavigateToStateArgs(e,t,r),this.#_e.navigateToState(e,t,r)}clone(e){return this.#ce||Gt.validateCloneArgs(e),this.#Ve.clone(e,(e,t,i)=>new r(e,t,i),(e,t,r)=>{e.#Ie.applyClonedConfig(t,r)})}static#ze=t=>{t instanceof kt&&(t.code===b.SAME_STATES||t.code===b.TRANSITION_CANCELLED||t.code===b.ROUTER_NOT_STARTED||t.code===b.ROUTE_NOT_FOUND)||e.logger.error("router.navigate","Unexpected navigation error",t)};static#qe(e){e.catch(r.#ze)}#We(){this.navigate=Kt,this.navigateToDefault=Kt,this.navigateToState=Kt,this.start=Kt,this.stop=Kt,this.addRoute=Kt,this.removeRoute=Kt,this.clearRoutes=Kt,this.updateRoute=Kt,this.addActivateGuard=Kt,this.addDeactivateGuard=Kt,this.removeActivateGuard=Kt,this.removeDeactivateGuard=Kt,this.usePlugin=Kt,this.useMiddleware=Kt,this.setDependency=Kt,this.setDependencies=Kt,this.removeDependency=Kt,this.resetDependencies=Kt,this.addEventListener=Kt,this.subscribe=Kt,this.setRootPath=Kt,this.clone=Kt,this.canNavigateTo=Kt}};function Kt(){throw new kt(b.ROUTER_DISPOSED)}exports.Router=Qt,exports.RouterError=kt,exports.constants=T,exports.createRouter=(e=[],t={},r={})=>new Qt(e,t,r),exports.errorCodes=b,exports.events=$,exports.getNavigator=e=>Object.freeze({navigate:e.navigate,getState:e.getState,isActiveRoute:e.isActiveRoute,canNavigateTo:e.canNavigateTo,subscribe:e.subscribe});//# sourceMappingURL=index.js.map
|
|
1
|
+
var e=require("@real-router/logger"),t=require("@real-router/fsm"),r={maxListeners:0,warnListeners:0,maxEventDepth:0},i=class extends Error{},n=class{#e=new Map;#t=null;#r=r;#i;#n;constructor(e){e?.limits&&(this.#r=e.limits),this.#i=e?.onListenerError??null,this.#n=e?.onListenerWarn??null}static validateCallback(e,t){if("function"!=typeof e)throw new TypeError(`Expected callback to be a function for event ${t}`)}setLimits(e){this.#r=e}on(e,t){const r=this.#a(e);if(r.has(t))throw new Error(`Duplicate listener for "${e}"`);const{maxListeners:i,warnListeners:n}=this.#r;if(0!==n&&r.size===n&&this.#n?.(e,n),0!==i&&r.size>=i)throw new Error(`Listener limit (${i}) reached for "${e}"`);return r.add(t),()=>{this.off(e,t)}}off(e,t){this.#e.get(e)?.delete(t)}emit(e,...t){const r=this.#e.get(e);r&&0!==r.size&&(0!==this.#r.maxEventDepth?this.#s(r,e,t):this.#o(r,e,t))}clearAll(){this.#e.clear(),this.#t=null}listenerCount(e){return this.#e.get(e)?.size??0}#o(e,t,r){const i=[...e];for(const e of i)try{this.#c(e,r)}catch(e){this.#i?.(t,e)}}#c(e,t){switch(t.length){case 0:e();break;case 1:e(t[0]);break;case 2:e(t[0],t[1]);break;case 3:e(t[0],t[1],t[2]);break;default:Function.prototype.apply.call(e,void 0,t)}}#s(e,t,r){this.#t??=new Map;const n=this.#t,a=n.get(t)??0;if(a>=this.#r.maxEventDepth)throw new i(`Maximum recursion depth (${this.#r.maxEventDepth}) exceeded for event: ${t}`);try{n.set(t,a+1);const s=[...e];for(const e of s)try{this.#c(e,r)}catch(e){if(e instanceof i)throw e;this.#i?.(t,e)}}finally{n.set(t,n.get(t)-1)}}#a(e){const t=this.#e.get(e);if(t)return t;const r=new Set;return this.#e.set(e,r),r}},a=["replace","reload","force","forceDeactivate","redirected"],s=/\S/,o=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function c(e,t){return new TypeError(`[router.${e}] ${t}`)}function d(e,t=new WeakSet){if(null==e)return!0;const r=typeof e;if("string"===r||"boolean"===r)return!0;if("number"===r)return Number.isFinite(e);if("function"===r||"symbol"===r)return!1;if(Array.isArray(e))return!t.has(e)&&(t.add(e),e.every(e=>d(e,t)));if("object"===r){if(t.has(e))return!1;t.add(e);const r=Object.getPrototypeOf(e);return(null===r||r===Object.prototype)&&Object.values(e).every(e=>d(e,t))}return!1}function u(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function l(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);if(null!==t&&t!==Object.prototype)return!1;let r=!1;for(const t in e){if(!Object.hasOwn(e,t))continue;const i=e[t];if(!u(i)){const e=typeof i;if("function"===e||"symbol"===e)return!1;r=!0;break}}return!r||d(e)}function h(e){return"object"==typeof e&&null!==e&&function(e){return function(e){return"string"==typeof e&&(""===e||!(e.length>1e4)&&(!!e.startsWith("@@")||o.test(e)))}(e.name)&&"string"==typeof e.path&&l(e.params)}(e)}function f(e){return"string"==typeof e}function p(e){return"boolean"==typeof e}function m(e){return"object"==typeof e&&null!==e&&"then"in e&&"function"==typeof e.then}function g(e,t){return e in t}function w(e,t){if("string"!=typeof e)throw c(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!s.test(e))throw c(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw c(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!o.test(e))throw c(t,`Invalid route name "${e}". Each segment must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens. Segments are separated by dots (e.g., "users.profile").`)}}function v(e){return null===e?"null":Array.isArray(e)?`array[${e.length}]`:"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function y(e,t){if(!h(e))throw new TypeError(`[${t}] Invalid state structure: ${v(e)}. Expected State object with name, params, and path properties.`)}var T=Object.freeze({ROUTER_NOT_STARTED:"NOT_STARTED",NO_START_PATH_OR_STATE:"NO_START_PATH_OR_STATE",ROUTER_ALREADY_STARTED:"ALREADY_STARTED",ROUTE_NOT_FOUND:"ROUTE_NOT_FOUND",SAME_STATES:"SAME_STATES",CANNOT_DEACTIVATE:"CANNOT_DEACTIVATE",CANNOT_ACTIVATE:"CANNOT_ACTIVATE",TRANSITION_ERR:"TRANSITION_ERR",TRANSITION_CANCELLED:"CANCELLED",ROUTER_DISPOSED:"DISPOSED"}),b={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},S="onStart",R="onStop",A="onTransitionStart",E="onTransitionCancel",P="onTransitionSuccess",O="onTransitionError",$={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},D=new Set([$.ROUTER_START,$.TRANSITION_START,$.TRANSITION_SUCCESS,$.TRANSITION_ERROR,$.TRANSITION_CANCEL,$.ROUTER_STOP]),N={maxDependencies:100,maxPlugins:50,maxMiddleware:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},C={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxMiddleware:{min:0,max:1e3},maxListeners:{min:0,max:1e5},warnListeners:{min:0,max:1e5},maxEventDepth:{min:0,max:100},maxLifecycleHandlers:{min:0,max:1e4}},j="IDLE",M="STARTING",F="READY",x="TRANSITIONING",I="DISPOSED",L="START",k="STARTED",U="NAVIGATE",_="COMPLETE",B="FAIL",V="CANCEL",G="STOP",q="DISPOSE",z={initial:j,context:null,transitions:{[j]:{[L]:M,[q]:I},[M]:{[k]:F,[B]:j},[F]:{[U]:x,[B]:F,[G]:j},[x]:{[U]:x,[_]:F,[V]:F,[B]:F},[I]:{}}},W=new WeakSet;function H(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)H(t);else for(const t in e)H(e[t])}function Q(e){return e?(W.has(e)||(H(e),W.add(e)),e):e}function K(e){return{warn:Math.floor(.2*e),error:Math.floor(.5*e)}}var J=class{#d=Object.create(null);#u=N;constructor(e={}){this.setMultiple(e)}static validateName(e,t){!function(e,t){if("string"!=typeof e)throw new TypeError(`[router.${t}]: dependency name must be a string, got ${typeof e}`)}(e,t)}static validateSetDependencyArgs(e){!function(e){if("string"!=typeof e)throw new TypeError("[router.setDependency]: dependency name must be a string, got "+typeof e)}(e)}static validateDependenciesObject(e,t){!function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid argument: expected plain object, received ${v(e)}`);for(const r in e)if(Object.getOwnPropertyDescriptor(e,r)?.get)throw new TypeError(`[router.${t}] Getters not allowed: "${r}"`)}(e,t)}static validateDependencyExists(e,t){!function(e,t){if(void 0===e)throw new ReferenceError(`[router.getDependency]: dependency "${t}" not found`)}(e,t)}static validateDependencyLimit(e,t,r,i){!function(e,t,r,i=N.maxDependencies){if(0===i)return;const n=e+t;if(n>=i)throw new Error(`[router.${r}] Dependency limit exceeded (${i}). Current: ${n}. This is likely a bug in your code.`)}(e,t,r,i)}setLimits(e){this.#u=e}set(t,r){if(void 0===r)return!1;if(Object.hasOwn(this.#d,t)){const i=this.#d[t],n=i!==r,a=Number.isNaN(i)&&Number.isNaN(r);n&&!a&&e.logger.warn("router.setDependency","Router dependency already exists and is being overwritten:",t)}else this.#l("setDependency");return this.#d[t]=r,!0}setMultiple(t){const r=[];for(const e in t)void 0!==t[e]&&(Object.hasOwn(this.#d,e)&&r.push(e),this.#d[e]=t[e]);r.length>0&&e.logger.warn("router.setDependencies","Overwritten:",r.join(", "))}get(e){return this.#d[e]}getAll(){return{...this.#d}}count(){return Object.keys(this.#d).length}remove(t){Object.hasOwn(this.#d,t)||e.logger.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${v(t)}"`),delete this.#d[t]}has(e){return Object.hasOwn(this.#d,e)}reset(){for(const e in this.#d)delete this.#d[e]}#l(t){const r=this.#u.maxDependencies;if(0===r)return;const i=Object.keys(this.#d).length,{warn:n,error:a}=K(r);if(i===n)e.logger.warn(`router.${t}`,`${n} dependencies registered. Consider if all are necessary.`);else if(i===a)e.logger.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${r}.`);else if(i>=r)throw new Error(`[router.${t}] Dependency limit exceeded (${r}). Current: ${i}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}},Y={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},Z={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},X={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function ee(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&ee(r)}return e}function te(e,t){return"function"==typeof e?e(t):e}function re(e,t,r){if("function"==typeof t&&("defaultRoute"===e||"defaultParams"===e))return;const i=Y[e];if(i&&"object"==typeof i)return function(e,t,r){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${r}] Invalid type for "${t}": expected plain object, got ${v(e)}`);for(const i in e)if(Object.getOwnPropertyDescriptor(e,i)?.get)throw new TypeError(`[router.${r}] Getters not allowed in "${t}": "${i}"`)}(t,e,r),void("queryParams"===e&&function(e,t){for(const r in e){if(!g(r,X)){const e=Object.keys(X).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const i=e[r],n=X[r];if(!n.includes(i)){const e=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Invalid value for queryParams.${r}: expected one of ${e}, got "${String(i)}"`)}}}(t,r));if(typeof t!=typeof i)throw new TypeError(`[router.${r}] Invalid type for "${e}": expected ${typeof i}, got ${typeof t}`);e in Z&&function(e,t,r){const i=Z[e];if(!i.includes(t)){const n=i.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${n}, got "${String(t)}"`)}}(e,t,r)}function ie(e,t,r){if("limits"===e)return void 0!==t&&function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}]: invalid limits: expected plain object, got ${typeof e}`);for(const[r,i]of Object.entries(e)){if(!Object.hasOwn(C,r))throw new TypeError(`[router.${t}]: unknown limit: "${r}"`);void 0!==i&&ne(r,i,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function ne(e,t,r){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError(`[router.${r}]: limit "${e}" must be an integer, got ${String(t)}`);const i=C[e];if(t<i.min||t>i.max)throw new RangeError(`[router.${r}]: limit "${e}" must be between ${i.min} and ${i.max}, got ${t}`)}var ae=class{#h;constructor(e={}){this.#h=ee({...Y,...e})}static validateOptions(e,t){!function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid options: expected plain object, got ${v(e)}`);for(const[r,i]of Object.entries(e))g(r,Y)?void 0!==i&&re(r,i,t):ie(r,i,t)}(e,t)}get(){return this.#h}};function se(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>se(e,t[r]))}var oe=class{#f=0;#p=void 0;#m=void 0;#g;#w=new Map;static validateMakeStateArgs(e,t,r,i){if(!f(e))throw new TypeError(`[router.makeState] Invalid name: ${v(e)}. Expected string.`);if(void 0!==t&&!l(t))throw new TypeError(`[router.makeState] Invalid params: ${v(t)}. Expected plain object.`);if(void 0!==r&&!f(r))throw new TypeError(`[router.makeState] Invalid path: ${v(r)}. Expected string.`);if(void 0!==i&&"number"!=typeof i)throw new TypeError(`[router.makeState] Invalid forceId: ${v(i)}. Expected number.`)}static validateAreStatesEqualArgs(e,t,r){if(null!=e&&y(e,"areStatesEqual"),null!=t&&y(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${v(r)}. Expected boolean.`)}get(){return this.#p}set(e){this.#m=this.#p,this.#p=e?Q(e):void 0}getPrevious(){return this.#m}reset(){this.#p=void 0,this.#m=void 0,this.#w.clear(),this.#f=0}setDependencies(e){this.#g=e}makeState(e,t,r,i,n){const a=i?{...i,id:n??++this.#f,params:i.params,options:i.options}:void 0,s=this.#g.getDefaultParams();let o;return o=Object.hasOwn(s,e)?{...s[e],...t}:t?{...t}:{},Q({name:e,params:o,path:r??this.#g.buildPath(e,t),meta:a})}makeNotFoundState(e,t){return this.makeState(b.UNKNOWN_ROUTE,{path:e},e,{options:t,params:{}})}areStatesEqual(e,t,r=!0){if(!e||!t)return!!e==!!t;if(e.name!==t.name)return!1;if(r){const r=e.meta?.params??t.meta?.params;return(r?function(e){const t=[];for(const r in e){const i=e[r];for(const e in i)"url"===i[e]&&t.push(e)}return t}(r):this.#v(e.name)).every(r=>se(e.params[r],t.params[r]))}const i=Object.keys(e.params),n=Object.keys(t.params);return i.length===n.length&&i.every(r=>r in t.params&&se(e.params[r],t.params[r]))}#v(e){const t=this.#w.get(e);if(void 0!==t)return t;const r=this.#g.getUrlParams(e);return this.#w.set(e,r),r}};function ce(e){return e.name||"anonymous"}var de=class{#y=new Set;#T=new Map;#b;#g;#u=N;static validateUseMiddlewareArgs(e){!function(e){for(const[t,r]of e.entries())if("function"!=typeof r)throw new TypeError(`[router.useMiddleware] Expected middleware factory function at index ${t}, got ${v(r)}`)}(e)}static validateMiddleware(e,t){!function(e,t){if("function"!=typeof e)throw new TypeError(`[router.useMiddleware] Middleware factory must return a function, got ${v(e)}. Factory: ${ce(t)}`)}(e,t)}static validateNoDuplicates(e,t){!function(e,t){const r=new Set(t);for(const t of e)if(r.has(t))throw new Error(`[router.useMiddleware] Middleware factory already registered. To re-register, first unsubscribe the existing middleware. Factory: ${ce(t)}`)}(e,t)}static validateMiddlewareLimit(e,t,r){!function(e,t,r=N.maxMiddleware){if(0!==r&&e+t>r)throw new Error(`[router.useMiddleware] Middleware limit exceeded (${r}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating middleware.`)}(e,t,r)}setRouter(e){this.#b=e}setDependencies(e){this.#g=e}setLimits(e){this.#u=e}count(){return this.#y.size}initialize(...e){const t=[];for(const r of e){const e=r(this.#b,this.#g.getDependency);t.push({factory:r,middleware:e})}return t}commit(e){this.#S(e.length);for(const{factory:t,middleware:r}of e)this.#y.add(t),this.#T.set(t,r);let t=!1;return()=>{if(!t){t=!0;for(const{factory:t}of e)this.#y.delete(t),this.#T.delete(t)}}}getFactories(){return[...this.#y]}getFunctions(){return[...this.#T.values()]}clearAll(){this.#y.clear(),this.#T.clear()}#S(t){const r=this.#u.maxMiddleware;if(0===r)return;const i=t+this.#y.size,{warn:n,error:a}=K(r);i>=a?e.logger.error("router.useMiddleware",`${i} middleware registered! This is excessive and will impact performance. Hard limit at ${r}.`):i>=n&&e.logger.warn("router.useMiddleware",`${i} middleware registered. Consider if all are necessary.`)}},ue={[S]:$.ROUTER_START,[R]:$.ROUTER_STOP,[P]:$.TRANSITION_SUCCESS,[A]:$.TRANSITION_START,[O]:$.TRANSITION_ERROR,[E]:$.TRANSITION_CANCEL},le=Object.keys(ue).filter(e=>g(e,ue)),he="router.usePlugin",fe=class t{#R=new Set;#A=new Set;#b;#g;#u=N;static validateUsePluginArgs(e){!function(e){for(const t of e)if("function"!=typeof t)throw new TypeError("[router.usePlugin] Expected plugin factory function, got "+typeof t)}(e)}static validatePlugin(e){!function(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new TypeError(`[router.usePlugin] Plugin factory must return an object, got ${v(e)}`);if("function"==typeof e.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.");for(const t in e)if("teardown"!==t&&!g(t,ue))throw new TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}(e)}static validatePluginLimit(e,t,r){!function(e,t,r=N.maxPlugins){if(0!==r&&e+t>r)throw new Error(`[router.usePlugin] Plugin limit exceeded (${r})`)}(e,t,r)}static validateNoDuplicatePlugins(e,t){for(const r of e)if(t(r))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setRouter(e){this.#b=e}setDependencies(e){this.#g=e}setLimits(e){this.#u=e}count(){return this.#R.size}use(...t){if(this.#S(t.length),1===t.length){const r=t[0],i=this.#E(r);this.#R.add(r);let n=!1;const a=()=>{if(!n){n=!0,this.#R.delete(r),this.#A.delete(a);try{i()}catch(t){e.logger.error(he,"Error during cleanup:",t)}}};return this.#A.add(a),a}const r=this.#P(t),i=[];try{for(const e of r){const t=this.#E(e);i.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of i)try{t()}catch(t){e.logger.error(he,"Cleanup error:",t)}throw t}for(const{factory:e}of i)this.#R.add(e);let n=!1;const a=()=>{if(!n){n=!0,this.#A.delete(a);for(const{factory:e}of i)this.#R.delete(e);for(const{cleanup:t}of i)try{t()}catch(t){e.logger.error(he,"Error during cleanup:",t)}}};return this.#A.add(a),a}getAll(){return[...this.#R]}has(e){return this.#R.has(e)}disposeAll(){for(const e of this.#A)e();this.#R.clear(),this.#A.clear()}#S(t){const r=this.#u.maxPlugins;if(0===r)return;const i=t+this.#R.size,{warn:n,error:a}=K(r);i>=a?e.logger.error(he,`${i} plugins registered!`):i>=n&&e.logger.warn(he,`${i} plugins registered`)}#P(t){const r=new Set;for(const i of t)r.has(i)?e.logger.warn(he,"Duplicate factory in batch, will be registered once"):r.add(i);return r}#E(r){const i=r(this.#b,this.#g.getDependency);t.validatePlugin(i),Object.freeze(i);const n=[];for(const t of le)t in i&&("function"==typeof i[t]?(n.push(this.#g.addEventListener(ue[t],i[t])),"onStart"===t&&this.#g.canNavigate()&&e.logger.warn(he,"Router already started, onStart will not be called")):e.logger.warn(he,`Property '${t}' is not a function, skipping`));return()=>{for(const e of n)e();"function"==typeof i.teardown&&i.teardown()}}};function pe(e,t,r){if(e)throw new Error(`[router.${r}] Cannot modify route "${t}" during its own registration`)}function me(e,t,r=N.maxLifecycleHandlers){if(0!==r&&e>=r)throw new Error(`[router.${t}] Lifecycle handler limit exceeded (${r}). This indicates too many routes with individual handlers. Consider using middleware for cross-cutting concerns.`)}var ge=class{#O=new Map;#$=new Map;#D=new Map;#N=new Map;#C=new Set;#b;#g;#u=N;static validateHandler(e,t){!function(e,t){if(!p(e)&&"function"!=typeof e)throw new TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${v(e)}`)}(e,t)}setRouter(e){this.#b=e}setDependencies(e){this.#g=e}setLimits(e){this.#u=e}addCanActivate(e,t,r){r||pe(this.#C.has(e),e,"addActivateGuard");const i=this.#$.has(e);i||r||me(this.#$.size+1,"addActivateGuard",this.#u.maxLifecycleHandlers),this.#j("activate",e,t,this.#$,this.#N,"canActivate",i)}addCanDeactivate(e,t,r){r||pe(this.#C.has(e),e,"addDeactivateGuard");const i=this.#O.has(e);i||r||me(this.#O.size+1,"addDeactivateGuard",this.#u.maxLifecycleHandlers),this.#j("deactivate",e,t,this.#O,this.#D,"canDeactivate",i)}clearCanActivate(e){this.#$.delete(e),this.#N.delete(e)}clearCanDeactivate(e){this.#O.delete(e),this.#D.delete(e)}clearAll(){this.#$.clear(),this.#N.clear(),this.#O.clear(),this.#D.clear()}getFactories(){const e={},t={};for(const[t,r]of this.#O)e[t]=r;for(const[e,r]of this.#$)t[e]=r;return[e,t]}getFunctions(){return[this.#D,this.#N]}checkActivateGuardSync(e,t,r){return this.#M(this.#N,e,t,r,"checkActivateGuardSync")}checkDeactivateGuardSync(e,t,r){return this.#M(this.#D,e,t,r,"checkDeactivateGuardSync")}#j(t,r,i,n,a,s,o){o?e.logger.warn(`router.${s}`,`Overwriting existing ${t} handler for route "${r}"`):this.#S(n.size+1,s);const c=p(i)?function(e){const t=()=>e;return()=>t}(i):i;n.set(r,c),this.#C.add(r);try{const e=c(this.#b,this.#g.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${s}] Factory must return a function, got ${v(e)}`);a.set(r,e)}catch(e){throw n.delete(r),e}finally{this.#C.delete(r)}}#M(t,r,i,n,a){const s=t.get(r);if(!s)return!0;try{const t=s(i,n);return"boolean"==typeof t?t:!m(t)||(e.logger.warn(`router.${a}`,`Guard for "${r}" returned a Promise. Sync check cannot resolve async guards — returning false.`),!1)}catch{return!1}}#S(t,r){const i=this.#u.maxLifecycleHandlers;if(0===i)return;const{warn:n,error:a}=K(i);t>=a?e.logger.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at ${i}.`):t>=n&&e.logger.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}};function we(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var ve=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,ye=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,Te=/\?(.+)$/,be=/[^\w!$'()*+,.:;|~-]/gu,Se=/[^\w!$'()*+,.:;|~-]/u,Re={default:e=>Se.test(e)?e.replaceAll(be,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},Ae={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function Ee(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function Pe(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function Oe(e){const t={};if(0===e.length)return t;const r=e.split("&");for(const e of r){const r=e.indexOf("=");-1===r?t[e]="":t[e.slice(0,r)]=e.slice(r+1)}return t}function $e(e){const t=[];for(const r of Object.keys(e)){const i=e[r],n=encodeURIComponent(r);t.push(""===i?n:`${n}=${encodeURIComponent(String(i))}`)}return t.join("&")}function De(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function Ne(e){let t=0;for(;t<e.length;)if("%"===e[t]){if(t+2>=e.length)return!1;const r=e.codePointAt(t+1)??0,i=e.codePointAt(t+2)??0;if(!De(r)||!De(i))return!1;t+=3}else t++;return!0}var Ce=/<[^>]*>/g;function je(e,t,r,i,n){const a=""===t.fullName;a||i.push(t);const s=t.absolute,o=t.paramMeta.pathPattern,c=s&&o.startsWith("~")?o.slice(1):o,d=(s?c:o).replaceAll(Ce,""),u=s?d:(h=d,""===(l=r)?h:""===h?l:l+h);var l,h;let f=n;a||(f=function(e,t,r,i,n,a){const s=(g=i,Pe(r)===Pe(g)),o=Object.freeze([...n]),c=function(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return Object.freeze(t)}(o),d=Pe(r),u=function(e,t){const r=[];e.length>0&&r.push(...e);for(const e of t)e.paramMeta.queryParams.length>0&&r.push(...e.paramMeta.queryParams);return r}(e.rootQueryParams,n),l=function(e){const t=new Map;for(const r of e)for(const[e,i]of r.paramMeta.constraintPatterns)t.set(e,i);return t}(n),h=s?Pe(i):d,{buildStaticParts:f,buildParamSlots:p}=function(e,t,r){const i=new Set,n=new Set;for(const e of t){for(const t of e.paramMeta.urlParams)i.add(t);for(const t of e.paramMeta.spatParams)n.add(t)}if(0===i.size)return{buildStaticParts:[e],buildParamSlots:[]};const a=[],s=[],o=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,d=0;for(;null!==(c=o.exec(e));){const t=c[1],i="?"===c[2];a.push(e.slice(d,c.index));const o=n.has(t);s.push({paramName:t,isOptional:i,encoder:o?e=>{const t=Re[r],i=e.split("/");let n=t(i[0]);for(let e=1;e<i.length;e++)n+=`/${t(i[e])}`;return n}:Re[r]}),d=c.index+c[0].length}return a.push(e.slice(d)),{buildStaticParts:a,buildParamSlots:s}}(h,s?n.slice(0,-1):n,e.options.urlParamsEncoding),m={name:t.fullName,parent:a,depth:n.length-1,matchSegments:o,meta:c,declaredQueryParams:u,declaredQueryParamsSet:new Set(u),hasTrailingSlash:r.length>1&&r.endsWith("/"),constraintPatterns:l,hasConstraints:l.size>0,buildStaticParts:f,buildParamSlots:p};var g;return e.routesByName.set(t.fullName,m),e.segmentsByName.set(t.fullName,o),e.metaByName.set(t.fullName,c),s?function(e,t,r){var i,n;i=t,(function(e,t,r){const i=Pe(r);if("/"===i||""===i)return t;let n=t,a=1;const s=i.length;for(;a<=s;){const t=i.indexOf("/",a),r=-1===t?s:t;if(r<=a)break;n=Fe(e,n,i.slice(a,r)),a=r+1}return n}(n=e,n.root,r)).slashChildRoute=i;const a=Pe(r),s=e.options.caseSensitive?a:a.toLowerCase();e.staticCache.has(s)&&e.staticCache.set(s,t)}(e,m,i):function(e,t,r,i,n){if(function(e,t,r){const i=Pe(r);"/"!==i?Me(e,e.root,i,1,t):e.root.route=t}(e,t,r),0===n.paramMeta.urlParams.length){const r=e.options.caseSensitive?i:i.toLowerCase();e.staticCache.set(r,t)}}(e,m,r,d,t),m}(e,t,u,s?"":r,i,n));for(const r of t.children.values())je(e,r,u,i,f);a||i.pop()}function Me(e,t,r,i,n){const a=r.length;for(;i<=a;){const s=r.indexOf("/",i),o=-1===s?a:s,c=r.slice(i,o);if(c.endsWith("?")){const i=c.slice(1).replaceAll(Ce,"").replace(/\?$/,"");return t.paramChild??={node:Ee(),name:i},Me(e,t.paramChild.node,r,o+1,n),void(o>=a?t.route??=n:Me(e,t,r,o+1,n))}t=Fe(e,t,c),i=o+1}t.route=n}function Fe(e,t,r){if(r.startsWith("*")){const e=r.slice(1);return t.splatChild??={node:Ee(),name:e},t.splatChild.node}if(r.startsWith(":")){const e=r.slice(1).replaceAll(Ce,"").replace(/\?$/,"");return t.paramChild??={node:Ee(),name:e},t.paramChild.node}const i=e.options.caseSensitive?r:r.toLowerCase();return i in t.staticChildren||(t.staticChildren[i]=Ee()),t.staticChildren[i]}var xe=/[\u0080-\uFFFF]/,Ie=class{get options(){return this.#e}#e;#t=Ee();#n=new Map;#a=new Map;#r=new Map;#s=new Map;#i="";#F=[];constructor(e){this.#e={caseSensitive:e?.caseSensitive??!0,strictTrailingSlash:e?.strictTrailingSlash??!1,strictQueryParams:e?.strictQueryParams??!1,urlParamsEncoding:e?.urlParamsEncoding??"default",parseQueryString:e?.parseQueryString??Oe,buildQueryString:e?.buildQueryString??$e}}registerTree(e){this.#F=e.paramMeta.queryParams,je({root:this.#t,options:this.#e,routesByName:this.#n,segmentsByName:this.#a,metaByName:this.#r,staticCache:this.#s,rootQueryParams:this.#F},e,"",[],null)}match(e){const t=this.#o(e);if(!t)return;const[r,i,n]=t,a=this.#e.caseSensitive?i:i.toLowerCase(),s=this.#s.get(a);if(s){if(this.#e.strictTrailingSlash&&!this.#c(r,s))return;return this.#x(s,{},n)}const o={},c=this.#I(i,o);return!c||this.#e.strictTrailingSlash&&!this.#c(r,c)||c.hasConstraints&&!this.#L(o,c)||!this.#k(o)?void 0:this.#x(c,o,n)}buildPath(e,t,r){const i=this.#n.get(e);if(!i)throw new Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);i.hasConstraints&&t&&this.#U(i,e,t);const n=this.#_(i,t),a=this.#B(n,r?.trailingSlash),s=this.#V(i,t,r?.queryParamsMode);return a+(s?`?${s}`:"")}getSegmentsByName(e){return this.#a.get(e)}getMetaByName(e){return this.#r.get(e)}hasRoute(e){return this.#n.has(e)}setRootPath(e){this.#i=e}#U(e,t,r){for(const[i,n]of e.constraintPatterns){const e=r[i];if(null!=e){const r="object"==typeof e?JSON.stringify(e):String(e);if(!n.pattern.test(r))throw new Error(`[SegmentMatcher.buildPath] '${t}' — param '${i}' value '${r}' does not match constraint '${n.constraint}'`)}}}#_(e,t){const r=e.buildStaticParts,i=e.buildParamSlots;if(0===i.length)return this.#i+r[0];let n=this.#i+r[0];for(const[e,a]of i.entries()){const i=t?.[a.paramName];if(null==i){if(!a.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${a.paramName}'`);n.length>1&&n.endsWith("/")&&(n=n.slice(0,-1)),n+=r[e+1];continue}const s="object"==typeof i?JSON.stringify(i):String(i);n+=a.encoder(s)+r[e+1]}return n}#B(e,t){return"always"!==t||e.endsWith("/")?"never"===t&&"/"!==e&&e.endsWith("/")?e.slice(0,-1):e:`${e}/`}#V(e,t,r){if(!t)return"";const i=[...e.declaredQueryParams];if("loose"===r){const r=new Set(e.buildParamSlots.map(e=>e.paramName));for(const n in t)!Object.hasOwn(t,n)||e.declaredQueryParamsSet.has(n)||r.has(n)||i.push(n)}const n={};for(const e of i)e in t&&(n[e]=t[e]);return 0===Object.keys(n).length?"":this.#e.buildQueryString(n)}#o(e){if(""===e&&(e="/"),!e.startsWith("/"))return;const t=e.indexOf("#");if(-1!==t&&(e=e.slice(0,t)),xe.test(e))return;if(this.#i.length>0){if(!e.startsWith(this.#i))return;e=e.slice(this.#i.length)||"/"}const r=e.indexOf("?"),i=-1===r?e:e.slice(0,r),n=-1===r?void 0:e.slice(r+1);return i.includes("//")?void 0:[i,Pe(i),n]}#x(e,t,r){if(void 0!==r){const i=this.#e.parseQueryString(r);if(this.#e.strictQueryParams){const t=e.declaredQueryParamsSet;for(const e of Object.keys(i))if(!t.has(e))return}for(const e of Object.keys(i))t[e]=i[e]}return{segments:e.matchSegments,params:t,meta:e.meta}}#c(e,t){return(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#I(e,t){return 1===e.length?this.#t.slashChildRoute??this.#t.route:this.#G(this.#t,e,1,t)}#G(e,t,r,i){let n=e;const a=t.length;for(;r<=a;){const e=t.indexOf("/",r),s=-1===e?a:e,o=t.slice(r,s),c=this.#e.caseSensitive?o:o.toLowerCase();let d;if(c in n.staticChildren)d=n.staticChildren[c];else{if(!n.paramChild){if(n.splatChild){const e={},a=this.#G(n.splatChild.node,t,r,e);return a?(Object.assign(i,e),a):(i[n.splatChild.name]=t.slice(r),n.splatChild.node.route)}return}d=n.paramChild.node,i[n.paramChild.name]=o}n=d,r=s+1}return n.slashChildRoute??n.route}#k(e){const t=this.#e.urlParamsEncoding;if("none"===t)return!0;const r=Ae[t];for(const t in e){const i=e[t];if(i.includes("%")){if(!Ne(i))return!1;e[t]=r(i)}}return!0}#L(e,t){for(const[r,i]of t.constraintPatterns)if(!i.pattern.test(e[r]))return!1;return!0}},Le=e=>{const t=e.indexOf("%"),r=e.indexOf("+");if(-1===t&&-1===r)return e;const i=-1===r?e:e.split("+").join(" ");return-1===t?i:decodeURIComponent(i)},ke=e=>{const t=typeof e;if("string"!==t&&"number"!==t&&"boolean"!==t)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===t&&null===e?"null":t}`);return encodeURIComponent(e)},Ue={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${ke(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${ke(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${ke(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>ke(e)).join(",")}`}},_e={none:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:e=>e},string:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:e=>"true"===e||"false"!==e&&null,decodeValue:e=>e},"empty-true":{encode:(e,t)=>t?e:`${e}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:e=>e}},Be={default:{encode:e=>e},hidden:{encode:()=>""}},Ve=(e,t,r)=>({boolean:_e[t],null:Be[r],array:Ue[e]}),Ge={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:_e.none,null:Be.default,array:Ue.none}},qe=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return Ge;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",i=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:i,strategies:Ve(t,r,i)}},ze=e=>encodeURIComponent(e),We=(e,t,r)=>{const i=ze(e);switch(typeof t){case"string":case"number":default:return`${i}=${ze(t)}`;case"boolean":return r.strategies.boolean.encode(i,t);case"object":return null===t?r.strategies.null.encode(i):Array.isArray(t)?r.strategies.array.encodeArray(i,t):`${i}=${ze(t)}`}};function He(e,t,r,i,n){const a=e.indexOf("=",t),s=-1!==a&&a<r,o=e.slice(t,s?a:r),{name:c,hasBrackets:d}=function(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}(o);var u,l,h,f,p;!function(e,t,r,i){const n=e[t];void 0===n?e[t]=i?[r]:r:Array.isArray(n)?n.push(r):e[t]=[n,r]}(i,Le(c),(u=e,l=a,h=r,f=s,p=n,p?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const i=Le(e);return t.boolean.decodeValue(i)})(f?u.slice(l+1,h):void 0,p):f?Le(u.slice(l+1,h)):null),d)}function Qe(e,t){const r=e.path,i=r.startsWith("~"),n=i?r.slice(1):r,a={name:e.name,path:n,absolute:i,children:[],parent:t,nonAbsoluteChildren:[],fullName:""};if(e.children)for(const t of e.children){const e=Qe(t,a);a.children.push(e)}return a}function Ke(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function Je(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}function Ye(e,t,r){const i=function(e){const t=[],r=[],i=[],n={},a=new Map,s=e.replaceAll(ye,"$1"),o=Te.exec(s);if(null!==o){const t=o[1].split("&");for(const e of t){const t=e.trim();t.length>0&&(r.push(t),n[t]="query")}e=e.slice(0,o.index)}let c;for(;null!==(c=ve.exec(e));){const e=c[2],r=c[3];if("*"===c[1])i.push(e),t.push(e),n[e]="url";else if(t.push(e),n[e]="url",r){const t=`^${we(r)}$`;a.set(e,{pattern:new RegExp(t),constraint:r})}}return{urlParams:t,queryParams:r,spatParams:i,paramTypeMap:n,constraintPatterns:a,pathPattern:e}}(e.path),n=function(e){const t={};for(const r of e.urlParams)t[r]="url";for(const r of e.queryParams)t[r]="query";return t}(i),a={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:void 0,paramMeta:i,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:n};var s;a.fullName=(s=a,s.parent?.name?`${s.parent.fullName}.${s.name}`:s.name);const{childrenMap:o,nonAbsoluteChildren:c}=function(e,t,r){const i=[],n=[];for(const a of e){const e=Ye(a,t,r);i.push(e),e.absolute||n.push(e)}return{childrenMap:Je(i),nonAbsoluteChildren:n}}(e.children,a,r);return a.children=o,a.nonAbsoluteChildren=c,a.staticPath=function(e){if(!e.path)return null;const{urlParams:t,queryParams:r,spatParams:i}=e.paramMeta;if(t.length>0||r.length>0||i.length>0)return null;const n=[];let a=e.parent;for(;a?.path;)n.unshift(a),a=a.parent;let s="";for(const e of n){const{urlParams:t,queryParams:r,spatParams:i}=e.paramMeta;if(t.length>0||r.length>0||i.length>0)return null;s=e.absolute?e.path:Ke(s,e.path)}return e.absolute?e.path:Ke(s,e.path)}(a),r&&(Object.freeze(c),Object.freeze(n),Object.freeze(a.children),Object.freeze(a)),a}function Ze(e,t,r,i){return function(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build:i=>function(e,t=!0){return Ye(e,null,t)}(function(e,t,r){const i=Qe({name:e,path:t},null);for(const e of r){const t=Qe(e,i);i.children.push(t)}return i}(e,t,r),!i?.skipFreeze)}}(e,t).addMany(r).build(i)}function Xe(e){const t={name:e.name,path:e.absolute?`~${e.path}`:e.path};return e.children.size>0&&(t.children=[...e.children.values()].map(e=>Xe(e))),t}function et(e){const t=e?.queryParams;return new Ie({...void 0===e?.caseSensitive?void 0:{caseSensitive:e.caseSensitive},...void 0===e?.strictTrailingSlash?void 0:{strictTrailingSlash:e.strictTrailingSlash},...void 0===e?.strictQueryParams?void 0:{strictQueryParams:e.strictQueryParams},...void 0===e?.urlParamsEncoding?void 0:{urlParamsEncoding:e.urlParamsEncoding},parseQueryString:e=>((e,t)=>{const r=(e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)})(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return function(e,t){let r=0;const i=e.length;for(;r<i;){let n=e.indexOf("&",r);-1===n&&(n=i),He(e,r,n,t),r=n+1}}(e,t),t}(r);const i=qe(t),n={};let a=0;const s=r.length;for(;a<s;){let e=r.indexOf("&",a);-1===e&&(e=s),He(r,a,e,n,i.strategies),a=e+1}return n})(e,t),buildQueryString:e=>((e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const i=qe(t),n=[];for(const t of r){const r=e[t];if(void 0===r)continue;const a=We(t,r,i);a&&n.push(a)}return n.join("&")})(e,t)})}function tt(e,t){return new TypeError(`[router.${e}] ${t}`)}var rt=/^[A-Z_a-z][\w-]*$/,it=/\S/;function nt(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function at(e,t){if(!t.includes("."))return e.children.get(t);let r=e;for(const e of t.split("."))if(r=r.children.get(e),!r)return;return r}function st(e,t,r,i="",n,a){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${nt(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${nt(e)}`);if(function(e){for(const t of Object.keys(e)){const r=Object.getOwnPropertyDescriptor(e,t);if(r&&(r.get||r.set))return!0}return!1}(e))throw new TypeError(`[router.${t}] Route must not have getters or setters`)}(e,t);const s=e;!function(e,t){if("string"!=typeof e.name)throw new TypeError(`[router.${t}] Route name must be a string, got ${nt(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!it.test(r))throw new TypeError(`[router.${t}] Route name cannot contain only whitespace`);if(r.length>1e4)throw new TypeError(`[router.${t}] Route name exceeds maximum length of 10000 characters`);if(!r.startsWith("@@")){if(r.includes("."))throw new TypeError(`[router.${t}] Route name "${r}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(!rt.test(r))throw new TypeError(`[router.${t}] Invalid route name "${r}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}}(s,t),function(e,t,r,i){if("string"!=typeof e){let t;throw t=null===e?"null":Array.isArray(e)?"array":typeof e,tt(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw tt(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw tt(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw tt(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const n=i&&Object.values(i.paramTypeMap).includes("url");if(e.startsWith("~")&&n)throw tt(r,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}(s.path,s.name,t,r),function(e,t){if(void 0!==e.encodeParams&&"function"!=typeof e.encodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}(s,t),function(e,t){if(void 0!==e.decodeParams&&"function"!=typeof e.decodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}(s,t);const o=s.name,c=i?`${i}.${o}`:o;r&&c&&function(e,t,r){if(at(e,t))throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),n&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(n,c,t);const d=s.path,u=i;if(r&&function(e,t,r,i){const n=""===t?e:at(e,t);if(n)for(const e of n.children.values())if(e.path===r)throw new Error(`[router.${i}] Path "${r}" is already defined`)}(r,u,d,t),a&&function(e,t,r,i){const n=e.get(t);if(n?.has(r))throw new Error(`[router.${i}] Path "${r}" is already defined`);n?n.add(r):e.set(t,new Set([r]))}(a,u,d,t),void 0!==s.children){if(!Array.isArray(s.children))throw new TypeError(`[router.${t}] Route "${o}" children must be an array, got ${nt(s.children)}`);for(const e of s.children)st(e,t,r,c,n,a)}}var ot=new Set;function ct(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>ct(e))),t}function dt(e,t,r=""){for(let i=0;i<e.length;i++){const n=e[i],a=r?`${r}.${n.name}`:n.name;if(a===t)return e.splice(i,1),!0;if(n.children&&t.startsWith(`${a}.`)&&dt(n.children,t,a))return!0}return!1}function ut(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function lt(e,t){if(void 0!==e.canActivate&&"function"!=typeof e.canActivate)throw new TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${v(e.canActivate)}`);if(void 0!==e.canDeactivate&&"function"!=typeof e.canDeactivate)throw new TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${v(e.canDeactivate)}`);if(void 0!==e.defaultParams){const r=e.defaultParams;if(null===r||"object"!=typeof r||Array.isArray(r))throw new TypeError(`[router.addRoute] defaultParams must be an object for route "${t}", got ${v(e.defaultParams)}`)}if("AsyncFunction"===e.decodeParams?.constructor.name)throw new TypeError(`[router.addRoute] decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if("AsyncFunction"===e.encodeParams?.constructor.name)throw new TypeError(`[router.addRoute] encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(function(e,t){if(void 0!==e&&"function"==typeof e){const r="AsyncFunction"===e.constructor.name,i=e.toString().includes("__awaiter");if(r||i)throw new TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`)}}(e.forwardTo,t),e.children)for(const r of e.children)lt(r,`${t}.${r.name}`)}function ht(e){const t=new Set,r=/[*:]([A-Z_a-z]\w*)/g;let i;for(;null!==(i=r.exec(e));)t.add(i[1]);return t}function ft(e){const t=new Set;for(const r of e)for(const e of ht(r))t.add(e);return t}function pt(e,t,r="",i=[]){for(const n of e){const e=r?`${r}.${n.name}`:n.name,a=[...i,n.path];if(e===t)return a;if(n.children&&t.startsWith(`${e}.`))return pt(n.children,t,e,a)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function mt(e,t=""){const r=new Set;for(const i of e){const e=t?`${t}.${i.name}`:i.name;if(r.add(e),i.children)for(const t of mt(i.children,e))r.add(t)}return r}function gt(e,t=""){const r=new Map;for(const i of e){const e=t?`${t}.${i.name}`:i.name;if(i.forwardTo&&"string"==typeof i.forwardTo&&r.set(e,i.forwardTo),i.children)for(const[t,n]of gt(i.children,e))r.set(t,n)}return r}function wt(e,t,r,i){return t?function(e){const t=new Set;for(const r of e){for(const e of r.paramMeta.urlParams)t.add(e);for(const e of r.paramMeta.spatParams)t.add(e)}return t}(function(e,t){const r=[],i=t.includes(".")?t.split("."):[t];""!==e.path&&r.push(e);let n=e;for(const e of i){const t=n.children.get(e);if(!t)return null;r.push(t),n=t}return r}(r,e)):ft(pt(i,e))}function vt(e,t,r,i,n){const a=function(e,t){const r=t.split(".");let i=e;for(const e of r)if(i=i.children.get(e),!i)return!1;return!0}(n,t),s=i.has(t);if(!a&&!s)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const o=ft(pt(r,e)),c=[...wt(t,a,n,r)].filter(e=>!o.has(e));if(c.length>0)throw new Error(`[router.addRoute] forwardTo target "${t}" requires params [${c.join(", ")}] that are not available in source route "${e}"`)}function yt(e,t,r=100){const i=new Set,n=[e];let a=e;for(;t[a];){const e=t[a];if(i.has(e)){const t=n.indexOf(e),r=[...n.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(i.add(a),n.push(e),a=e,n.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${n.join(" → ")}`)}return a}function Tt(e,t,r){const i=mt(e),n=gt(e),a={...t};for(const[e,t]of n)a[e]=t;for(const[t,a]of n)vt(t,a,e,i,r);for(const e of Object.keys(a))yt(e,a)}function bt(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}function St(e,t){if("AsyncFunction"===e.constructor.name||e.toString().includes("__awaiter"))throw new TypeError(`[real-router] updateRoute: ${t} cannot be an async function`)}function Rt(e,t){if(null!=e){if("function"!=typeof e)throw new TypeError(`[real-router] updateRoute: ${t} must be a function or null, got ${typeof e}`);St(e,t)}}var At=".";function Et(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function Pt(e,t){const r=t.meta?.params[e];if(!r||"object"!=typeof r)return{};const i={};for(const e in r){if(!Object.hasOwn(r,e))continue;if(void 0===r[e])continue;const n=t.params[e];null!=n&&("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n||(i[e]=String(n)))}return i}function Ot(e){if(!e)return[""];const t=e.indexOf(At);if(-1===t)return[e];const r=e.indexOf(At,t+1);if(-1===r)return[e.slice(0,t),e];const i=e.indexOf(At,r+1);return-1===i?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(At,i+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,i),e]:function(e){const t=e.split(At),r=t.length,i=[t[0]];let n=t[0].length;for(let a=1;a<r-1;a++)n+=1+t[a].length,i.push(e.slice(0,n));return i.push(e),i}(e)}function $t(e,t){if(!t)return{intersection:"",toActivate:Ot(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:Ot(e.name),toDeactivate:Et(Ot(t.name))};const r=void 0!==e.meta?.params,i=void 0!==t.meta?.params;if(!r&&!i)return{intersection:"",toActivate:Ot(e.name),toDeactivate:Et(Ot(t.name))};if(e.name===t.name&&r&&i){const r=e.meta&&0===Object.keys(e.meta.params).length,i=t.meta&&0===Object.keys(t.meta.params).length;if(r&&i)return{intersection:e.name,toActivate:[],toDeactivate:[]}}const n=Ot(e.name),a=Ot(t.name),s=function(e,t,r,i,n){for(let a=0;a<n;a++){const n=r[a],s=i[a];if(n!==s)return a;const o=Pt(n,e),c=Pt(s,t),d=Object.keys(o),u=Object.keys(c);if(d.length!==u.length)return a;for(const e of d)if(o[e]!==c[e])return a}return n}(e,t,n,a,Math.min(a.length,n.length)),o=[];for(let e=a.length-1;e>=s;e--)o.push(a[e]);const c=n.slice(s);return{intersection:s>0?a[s-1]:"",toDeactivate:o,toActivate:c}}var Dt=Object.freeze({}),Nt=class{#q=[];#z=function(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}();#W=Object.create(null);#H=new Map;#Q=new Map;#K="";#J;#Y;#Z;#X;#ee;#te;get#g(){if(!this.#X)throw new Error("[real-router] RoutesNamespace: dependencies not initialized");return this.#X}constructor(e=[],t=!1,r){this.#te=t,this.#Z=r;for(const t of e)this.#q.push(ct(t));this.#J=Ze("",this.#K,this.#q),this.#Y=et(r),this.#Y.registerTree(this.#J),this.#re(e),t?this.#ie():this.#ne()}static validateRemoveRouteArgs(e){!function(e){w(e,"removeRoute")}(e)}static validateSetRootPathArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${v(e)}`)}(e)}static validateAddRouteArgs(e){!function(e){for(const t of e){if(null===t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`[router.addRoute] Route must be an object, got ${v(t)}`);lt(t,t.name)}}(e)}static validateParentOption(e){!function(e){if("string"!=typeof e||""===e)throw new TypeError(`[router.addRoute] parent option must be a non-empty string, got ${v(e)}`);w(e,"addRoute")}(e)}static validateIsActiveRouteArgs(e,t,r,i){!function(e,t,r,i){if(!f(e))throw new TypeError("Route name must be a string");if(void 0!==t&&!l(t))throw new TypeError("[router.isActiveRoute] Invalid params structure");if(void 0!==r&&"boolean"!=typeof r)throw new TypeError("[router.isActiveRoute] strictEquality must be a boolean, got "+typeof r);if(void 0!==i&&"boolean"!=typeof i)throw new TypeError("[router.isActiveRoute] ignoreQueryParams must be a boolean, got "+typeof i)}(e,t,r,i)}static validateStateBuilderArgs(e,t,r){!function(e,t,r){if(!f(e))throw new TypeError(`[router.${r}] Invalid routeName: ${v(e)}. Expected string.`);if(!l(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${v(t)}. Expected plain object.`)}(e,t,r)}static validateUpdateRouteBasicArgs(e,t){!function(e,t){if(w(e,"updateRoute"),""===e)throw new ReferenceError("[router.updateRoute] Invalid name: empty string. Cannot update root node.");if(null===t)throw new TypeError("[real-router] updateRoute: updates must be an object, got null");if("object"!=typeof t||Array.isArray(t))throw new TypeError(`[real-router] updateRoute: updates must be an object, got ${v(t)}`)}(e,t)}static validateUpdateRoutePropertyTypes(e,t,r,i){!function(e,t,r,i){if(null!=e){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError(`[real-router] updateRoute: forwardTo must be a string, function, or null, got ${v(e)}`);"function"==typeof e&&St(e,"forwardTo callback")}if(null!=t&&("object"!=typeof t||Array.isArray(t)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${v(t)}`);Rt(r,"decodeParams"),Rt(i,"encodeParams")}(e,t,r,i)}static validateBuildPathArgs(e){!function(e){if(!f(e)||""===e)throw new TypeError("[real-router] buildPath: route must be a non-empty string, got "+("string"==typeof e?'""':typeof e))}(e)}static validateMatchPathArgs(e){!function(e){if(!f(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e)}static validateShouldUpdateNodeArgs(e){!function(e){if(!f(e))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof e)}(e)}static validateRoutes(e,t,r,i){!function(e,t,r,i){if(i&&t){let e=t;for(const t of i.split("."))if(e=e.children.get(t),!e)throw new Error(`[router.addRoute] Parent route "${i}" does not exist`)}const n=new Set,a=new Map;for(const r of e)st(r,"addRoute",t,i??"",n,a);t&&r&&Tt(e,r,t)}(e,t,r,i)}setDependencies(e){this.#X=e;for(const[t,r]of this.#H)e.addActivateGuard(t,r);this.#H.clear();for(const[t,r]of this.#Q)e.addDeactivateGuard(t,r);this.#Q.clear()}setLifecycleNamespace(e){this.#ee=e}getRootPath(){return this.#K}getTree(){return this.#J}getForwardRecord(){return this.#z.forwardMap}setRootPath(e){this.#K=e,this.#ae()}hasRoute(e){return this.#Y.hasRoute(e)}getRoute(e){const t=this.#Y.getSegmentsByName(e);if(!t)return;const r=Xe(this.#se(t));return this.#oe(r,e)}addRoutes(e,t){if(t){const r=this.#ce(this.#q,t);r.children??=[];for(const t of e)r.children.push(ct(t))}else for(const t of e)this.#q.push(ct(t));this.#re(e,t??""),this.#ae(),this.#de()}removeRoute(e){return!!dt(this.#q,e)&&(this.#ue(e),this.#ae(),this.#de(),!0)}updateRouteConfig(e,t){if(void 0!==t.forwardTo&&this.#le(e,t.forwardTo),void 0!==t.defaultParams&&(null===t.defaultParams?delete this.#z.defaultParams[e]:this.#z.defaultParams[e]=t.defaultParams),void 0!==t.decodeParams)if(null===t.decodeParams)delete this.#z.decoders[e];else{const r=t.decodeParams;this.#z.decoders[e]=e=>r(e)??e}if(void 0!==t.encodeParams)if(null===t.encodeParams)delete this.#z.encoders[e];else{const r=t.encodeParams;this.#z.encoders[e]=e=>r(e)??e}}clearRoutes(){this.#q.length=0;for(const e in this.#z.decoders)delete this.#z.decoders[e];for(const e in this.#z.encoders)delete this.#z.encoders[e];for(const e in this.#z.defaultParams)delete this.#z.defaultParams[e];for(const e in this.#z.forwardMap)delete this.#z.forwardMap[e];for(const e in this.#z.forwardFnMap)delete this.#z.forwardFnMap[e];for(const e in this.#W)delete this.#W[e];this.#ae()}buildPath(e,t,r){if(e===b.UNKNOWN_ROUTE)return f(t?.path)?t.path:"";const i=Object.hasOwn(this.#z.defaultParams,e)?{...this.#z.defaultParams[e],...t}:t??{},n="function"==typeof this.#z.encoders[e]?this.#z.encoders[e]({...i}):i,a=r?.trailingSlash;return this.#Y.buildPath(e,n,{trailingSlash:"never"===a||"always"===a?a:void 0,queryParamsMode:r?.queryParamsMode})}matchPath(e,t){const r=t,i=this.#Y.match(e);if(!i)return;const n=bt(i),{name:a,params:s,meta:o}=n,c="function"==typeof this.#z.decoders[a]?this.#z.decoders[a](s):s,{name:d,params:u}=this.#g.forwardState(a,c);let l=e;if(r.rewritePathOnMatch){const e="function"==typeof this.#z.encoders[d]?this.#z.encoders[d]({...u}):u,t=r.trailingSlash;l=this.#Y.buildPath(d,e,{trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:r.queryParamsMode})}return this.#g.makeState(d,u,l,{params:o,options:Dt})}forwardState(e,t){if(Object.hasOwn(this.#z.forwardFnMap,e)){const r=this.#he(e,t),i=this.#z.forwardFnMap[e],n=this.#fe(e,i,t);return{name:n,params:this.#he(n,r)}}const r=this.#W[e]??e;if(r!==e&&Object.hasOwn(this.#z.forwardFnMap,r)){const i=this.#he(e,t),n=this.#z.forwardFnMap[r],a=this.#fe(r,n,t);return{name:a,params:this.#he(a,i)}}if(r!==e){const i=this.#he(e,t);return{name:r,params:this.#he(r,i)}}return{name:e,params:this.#he(e,t)}}buildStateResolved(e,t){const r=this.#Y.getSegmentsByName(e);if(r)return bt({segments:r,params:t,meta:this.#Y.getMetaByName(e)},e)}buildStateWithSegmentsResolved(e,t){const r=this.#Y.getSegmentsByName(e);if(r)return{state:bt({segments:r,params:t,meta:this.#Y.getMetaByName(e)},e),segments:r}}isActiveRoute(e,t={},r=!1,i=!0){ot.has(e)||(w(e,"isActiveRoute"),ot.add(e));const n=this.#g.getState();if(!n)return!1;const a=n.name;if(a!==e&&!a.startsWith(`${e}.`)&&!e.startsWith(`${a}.`))return!1;const s=this.#z.defaultParams[e];if(r||a===e){const r=s?{...s,...t}:t;return this.#g.areStatesEqual({name:e,params:r,path:""},n,i)}const o=n.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(t,o)&&(!s||function(e,t,r){for(const i in e)if(!(i in r)&&e[i]!==t[i])return!1;return!0}(s,o,t))}shouldUpdateNode(e){return(t,r)=>{if(!t||"object"!=typeof t||!("name"in t))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(t.meta?.options.reload)return!0;if(""===e&&!r)return!0;const{intersection:i,toActivate:n,toDeactivate:a}=$t(t,r);return e===i||!!n.includes(e)||a.includes(e)}}getConfig(){return this.#z}getUrlParams(e){const t=this.#Y.getSegmentsByName(e);return t?this.#pe(t):[]}getResolvedForwardMap(){return this.#W}setResolvedForwardMap(e){Object.assign(this.#W,e)}applyClonedConfig(e,t){Object.assign(this.#z.decoders,e.decoders),Object.assign(this.#z.encoders,e.encoders),Object.assign(this.#z.defaultParams,e.defaultParams),Object.assign(this.#z.forwardMap,e.forwardMap),Object.assign(this.#z.forwardFnMap,e.forwardFnMap),this.setResolvedForwardMap({...t})}cloneRoutes(){return[...this.#J.children.values()].map(e=>Xe(e))}validateForwardToParamCompatibility(e,t){const r=this.#me(e),i=this.#me(t),n=this.#ge(r),a=this.#pe(i).filter(e=>!n.has(e));if(a.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${a.join(", ")}] that are not available in source route "${e}"`)}validateForwardToCycle(e,t){yt(e,{...this.#z.forwardMap,[e]:t})}validateRemoveRoute(t,r,i){if(r){const i=r===t,n=r.startsWith(`${t}.`);if(i||n)return e.logger.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${i?"":` (current: "${r}")`}. Navigate away first.`),!1}return i&&e.logger.warn("router.removeRoute",`Route "${t}" removed while navigation is in progress. This may cause unexpected behavior.`),!0}validateClearRoutes(t){return!t||(e.logger.error("router.clearRoutes","Cannot clear routes while navigation is in progress. Wait for navigation to complete."),!1)}validateUpdateRoute(e,t){if(!this.hasRoute(e))throw new ReferenceError(`[real-router] updateRoute: route "${e}" does not exist`);if(null!=t&&"string"==typeof t){if(!this.hasRoute(t))throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);this.validateForwardToParamCompatibility(e,t),this.validateForwardToCycle(e,t)}}#le(e,t){null===t?(delete this.#z.forwardMap[e],delete this.#z.forwardFnMap[e]):"string"==typeof t?(delete this.#z.forwardFnMap[e],this.#z.forwardMap[e]=t):(delete this.#z.forwardMap[e],this.#z.forwardFnMap[e]=t),this.#de()}#he(e,t){return Object.hasOwn(this.#z.defaultParams,e)?{...this.#z.defaultParams[e],...t}:t}#fe(e,t,r){const i=new Set([e]);let n=t(this.#g.getDependency,r),a=0;if("string"!=typeof n)throw new TypeError("forwardTo callback must return a string, got "+typeof n);for(;a<100;){if(void 0===this.#Y.getSegmentsByName(n))throw new Error(`Route "${n}" does not exist`);if(i.has(n)){const e=[...i,n].join(" → ");throw new Error(`Circular forwardTo detected: ${e}`)}if(i.add(n),Object.hasOwn(this.#z.forwardFnMap,n)){n=(0,this.#z.forwardFnMap[n])(this.#g.getDependency,r),a++;continue}const e=this.#z.forwardMap[n];if(void 0===e)return n;n=e,a++}throw new Error("forwardTo exceeds maximum depth of 100")}#ae(){this.#J=Ze("",this.#K,this.#q),this.#Y=et(this.#Z),this.#Y.registerTree(this.#J)}#me(e){return this.#Y.getSegmentsByName(e)}#se(e){return e.at(-1)}#ge(e){const t=new Set;for(const r of e)for(const e of r.paramMeta.urlParams)t.add(e);return t}#pe(e){const t=[];for(const r of e)for(const e of r.paramMeta.urlParams)t.push(e);return t}#de(){this.#te?this.#ie():this.#ne()}#ne(){for(const e in this.#W)delete this.#W[e];for(const e of Object.keys(this.#z.forwardMap))this.#W[e]=yt(e,this.#z.forwardMap)}#ie(){for(const e in this.#W)delete this.#W[e];for(const e of Object.keys(this.#z.forwardMap)){let t=e;for(;this.#z.forwardMap[t];)t=this.#z.forwardMap[t];this.#W[e]=t}}#ue(e){const t=t=>t===e||t.startsWith(`${e}.`);ut(this.#z.decoders,t),ut(this.#z.encoders,t),ut(this.#z.defaultParams,t),ut(this.#z.forwardMap,t),ut(this.#z.forwardFnMap,t),ut(this.#z.forwardMap,e=>t(this.#z.forwardMap[e]));const[r,i]=this.#ee.getFactories();for(const e of Object.keys(i))t(e)&&this.#ee.clearCanActivate(e);for(const e of Object.keys(r))t(e)&&this.#ee.clearCanDeactivate(e)}#re(e,t=""){for(const r of e){const e=t?`${t}.${r.name}`:r.name;this.#we(r,e),r.children&&this.#re(r.children,e)}}#we(e,t){e.canActivate&&(this.#X?this.#X.addActivateGuard(t,e.canActivate):this.#H.set(t,e.canActivate)),e.canDeactivate&&(this.#X?this.#X.addDeactivateGuard(t,e.canDeactivate):this.#Q.set(t,e.canDeactivate)),e.forwardTo&&this.#ve(e,t),e.decodeParams&&(this.#z.decoders[t]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(this.#z.encoders[t]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(this.#z.defaultParams[t]=e.defaultParams)}#ce(e,t,r=""){for(const i of e){const e=r?`${r}.${i.name}`:i.name;if(e===t)return i;if(i.children&&t.startsWith(`${e}.`))return this.#ce(i.children,t,e)}}#ve(t,r){if(t.canActivate&&e.logger.warn("real-router",`Route "${r}" 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&&e.logger.warn("real-router",`Route "${r}" 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 e="AsyncFunction"===t.forwardTo.constructor.name,i=t.forwardTo.toString().includes("__awaiter");if(e||i)throw new TypeError(`forwardTo callback cannot be async for route "${r}". Async functions break matchPath/buildPath.`)}"string"==typeof t.forwardTo?this.#z.forwardMap[r]=t.forwardTo:this.#z.forwardFnMap[r]=t.forwardTo}#oe(e,t){const r={name:e.name,path:e.path},i=this.#z.forwardFnMap[t],n=this.#z.forwardMap[t];void 0!==i?r.forwardTo=i:void 0!==n&&(r.forwardTo=n),t in this.#z.defaultParams&&(r.defaultParams=this.#z.defaultParams[t]),t in this.#z.decoders&&(r.decodeParams=this.#z.decoders[t]),t in this.#z.encoders&&(r.encodeParams=this.#z.encoders[t]);const[a,s]=this.#ee.getFactories();return t in s&&(r.canActivate=s[t]),t in a&&(r.canDeactivate=a[t]),e.children&&(r.children=e.children.map(e=>this.#oe(e,`${t}.${e.name}`))),r}},Ct=new Set(["code","segment","path","redirect"]),jt=new Set(Object.values(T)),Mt=new Set(["code","segment","path","redirect"]),Ft=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),xt=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:i,redirect:n,...a}={}){super(t??e),this.code=e,this.segment=r,this.path=i,this.redirect=n?function(e){if(!e)return e;if(null===(t=e)||"object"!=typeof t||"string"!=typeof t.name||"string"!=typeof t.path||"object"!=typeof t.params||null===t.params)throw new TypeError("[deepFreezeState] Expected valid State object, got: "+typeof e);var t;const r=structuredClone(e),i=new WeakSet;return function e(t){if(null===t||"object"!=typeof t)return;if(i.has(t))return;i.add(t),Object.freeze(t);const r=Array.isArray(t)?t:Object.values(t);for(const t of r)e(t)}(r),r}(n):void 0;for(const[e,t]of Object.entries(a)){if(Mt.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);Ft.has(e)||(this[e]=t)}}setCode(e){this.code=e,jt.has(this.message)&&(this.message=e)}setErrorInstance(e){if(!e)throw new TypeError("[RouterError.setErrorInstance] err parameter is required and must be an Error instance");this.message=e.message,this.cause=e.cause,this.stack=e.stack??""}setAdditionalFields(e){for(const[t,r]of Object.entries(e)){if(Mt.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);Ft.has(t)||(this[t]=r)}}hasField(e){return e in this}getField(e){return this[e]}toJSON(){const e={code:this.code,message:this.message};void 0!==this.segment&&(e.segment=this.segment),void 0!==this.path&&(e.path=this.path),void 0!==this.redirect&&(e.redirect=this.redirect);const t=new Set(["code","message","segment","path","redirect","stack"]);for(const r in this)Object.hasOwn(this,r)&&!t.has(r)&&(e[r]=this[r]);return e}};function It(e,t,r){if(e instanceof xt)throw e.setCode(t),e;throw new xt(t,function(e,t){const r=t?{segment:t}:{};if(e instanceof Error)return{...r,message:e.message,stack:e.stack,..."cause"in e&&void 0!==e.cause&&{cause:e.cause}};if(e&&"object"==typeof e){const t={};for(const[r,i]of Object.entries(e))Ct.has(r)||(t[r]=i);return{...r,...t}}return r}(e,r))}var Lt=(e,t)=>{const r=e.meta,i=t.meta,n=r?.params,a=i?.params,s=n&&a?{...n,...a}:n??a??{},o={id:1,options:{},...i,...r,params:s};return{...e,meta:o}},kt=async(e,t,r)=>{const i=r?{segment:r}:{};if(void 0===e)return t;if("boolean"==typeof e){if(e)return t;throw new xt(T.TRANSITION_ERR,i)}if(h(e))return e;if(m(e))try{const i=await e;return await kt(i,t,r)}catch(e){throw new xt(T.TRANSITION_ERR,function(e,t){return e instanceof Error?{...t,message:e.message,stack:e.stack,..."cause"in e&&void 0!==e.cause&&{cause:e.cause}}:e&&"object"==typeof e?{...t,...e}:t}(e,i))}throw new xt(T.TRANSITION_ERR,{...i,message:"Invalid lifecycle result type: "+typeof e})},Ut=async(t,r,i,n,a,s)=>{let o=r;const c=n.filter(e=>t.has(e));if(0===c.length)return o;for(const r of c){if(s())throw new xt(T.TRANSITION_CANCELLED);const n=t.get(r);try{const t=n(o,i),s=await kt(t,o,r);if(s!==o&&h(s)){if(s.name!==o.name)throw new xt(a,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:s.name,params:s.params,path:s.path}});(s.params!==o.params||s.path!==o.path)&&e.logger.error("core:transition","Warning: State mutated during transition",{from:o,to:s}),o=Lt(s,o)}}catch(e){It(e,a,r)}}return o};var _t=class t{#ye;#g;#Te;static validateNavigateArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${v(e)}`)}(e)}static validateNavigateToStateArgs(e,t,r){!function(e,t,r){if(!e||"object"!=typeof e||"string"!=typeof e.name||"string"!=typeof e.path)throw new TypeError("[router.navigateToState] Invalid toState: expected State object with name and path");if(void 0!==t&&(!t||"object"!=typeof t||"string"!=typeof t.name))throw new TypeError("[router.navigateToState] Invalid fromState: expected State object or undefined");if("object"!=typeof r||null===r)throw new TypeError(`[router.navigateToState] Invalid opts: expected NavigationOptions object, got ${v(r)}`)}(e,t,r)}static validateNavigateToDefaultArgs(e){!function(e){if(void 0!==e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${v(e)}. Expected NavigationOptions object.`)}(e)}static validateNavigationOptions(e,t){!function(e,t){if(!function(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=e;for(const e of a){const r=t[e];if(void 0!==r&&"boolean"!=typeof r)return!1}return!0}(e))throw new TypeError(`[router.${t}] Invalid options: ${v(e)}. Expected NavigationOptions object.`)}(e,t)}setCanNavigate(e){this.#ye=e}setDependencies(e){this.#g=e}setTransitionDependencies(e){this.#Te=e}async navigate(e,t,r){if(!this.#ye())throw new xt(T.ROUTER_NOT_STARTED);const i=this.#g,n=i.buildStateWithSegments(e,t);if(!n){const e=new xt(T.ROUTE_NOT_FOUND);throw i.emitTransitionError(void 0,i.getState(),e),e}const{state:a}=n,s=i.makeState(a.name,a.params,i.buildPath(a.name,a.params),{params:a.meta,options:r}),o=i.getState();if(!r.reload&&!r.force&&i.areStatesEqual(o,s,!1)){const e=new xt(T.SAME_STATES);throw i.emitTransitionError(s,o,e),e}return this.navigateToState(s,o,r)}async navigateToState(r,i,n){const a=this.#g,s=this.#Te;s.isTransitioning()&&(e.logger.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use router.clone() to create isolated instance per request."),a.cancelNavigation()),a.startTransition(r,i);try{const{state:o,meta:c}=await async function(t,r,i,n){const[a,s]=t.getLifecycleFunctions(),o=t.getMiddlewareFunctions(),c=r.name===b.UNKNOWN_ROUTE,d=()=>!t.isActive(),{toDeactivate:u,toActivate:l,intersection:f}=$t(r,i),p=!c&&l.length>0,m=o.length>0;let g=r;if(i&&!n.forceDeactivate&&u.length>0&&(g=await Ut(a,r,i,u,T.CANNOT_DEACTIVATE,d)),d())throw new xt(T.TRANSITION_CANCELLED);if(p&&(g=await Ut(s,g,i,l,T.CANNOT_ACTIVATE,d)),d())throw new xt(T.TRANSITION_CANCELLED);if(m&&(g=await(async(t,r,i,n)=>{let a=r;for(const r of t){if(n())throw new xt(T.TRANSITION_CANCELLED);try{const t=r(a,i),n=await kt(t,a);n!==a&&h(n)&&((n.name!==a.name||n.params!==a.params||n.path!==a.path)&&e.logger.error("core:middleware","Warning: State mutated during middleware execution",{from:a,to:n}),a=Lt(n,a))}catch(e){It(e,T.TRANSITION_ERR)}}return a})(o,g,i,d)),d())throw new xt(T.TRANSITION_CANCELLED);if(i){const e=Ot(r.name),n=Ot(i.name);for(const r of n)!e.includes(r)&&a.has(r)&&t.clearCanDeactivate(r)}return{state:g,meta:{phase:"middleware",segments:{deactivated:u,activated:l,intersection:f}}}}(s,r,i,n);if(o.name===b.UNKNOWN_ROUTE||a.hasRoute(o.name)){const e=t.#be(o,c,i);return a.setState(e),a.sendTransitionDone(e,i,n),e}{const e=new xt(T.ROUTE_NOT_FOUND,{routeName:o.name});throw a.sendTransitionError(o,i,e),e}}catch(e){throw this.#Se(e,r,i),e}}async navigateToDefault(e){const t=this.#g,r=t.getOptions();if(!r.defaultRoute)throw new xt(T.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"});const i=te(r.defaultRoute,t.getDependency);if(!i)throw new xt(T.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"});const n=te(r.defaultParams,t.getDependency);return this.navigate(i,n,e)}static#be(e,t,r){const i={phase:t.phase,...void 0!==r?.name&&{from:r.name},reason:"success",segments:t.segments};return Object.freeze(i.segments.deactivated),Object.freeze(i.segments.activated),Object.freeze(i.segments),Object.freeze(i),{...e,transition:i}}#Se(e,t,r){const i=e;i.code!==T.TRANSITION_CANCELLED&&i.code!==T.ROUTE_NOT_FOUND&&(i.code===T.CANNOT_ACTIVATE||i.code===T.CANNOT_DEACTIVATE?this.#g.sendTransitionBlocked(t,r,i):this.#g.sendTransitionError(t,r,i))}},Bt=class{#Re;#g;static validateStartArgs(e){if(1!==e.length||"string"!=typeof e[0])throw new Error("[router.start] Expected exactly 1 string argument (startPath).")}setNavigateToState(e){this.#Re=e}setDependencies(e){this.#g=e}async start(e){const t=this.#g,r=t.getOptions(),i={replace:!0},n=t.matchPath(e);if(!n&&!r.allowNotFound){const r=new xt(T.ROUTE_NOT_FOUND,{path:e});throw t.emitTransitionError(void 0,void 0,r),r}let a;if(t.completeStart(),n)a=await this.#Re(n,void 0,i);else{const r=t.makeNotFoundState(e,i);a=await this.#Re(r,void 0,i)}return a}stop(){this.#g.setState()}},Vt=class{#Ae;static validateCloneArgs(e){if(void 0!==e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.clone] Invalid dependencies: expected plain object or undefined, received ${v(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[router.clone] Getters not allowed in dependencies: "${t}"`)}}setGetCloneData(e){this.#Ae=e}clone(e,t,r){const i=this.#Ae(),n={...i.dependencies,...e},a=t(i.routes,i.options,n);for(const[e,t]of Object.entries(i.canDeactivateFactories))a.addDeactivateGuard(e,t);for(const[e,t]of Object.entries(i.canActivateFactories))a.addActivateGuard(e,t);return i.middlewareFactories.length>0&&a.useMiddleware(...i.middlewareFactories),i.pluginFactories.length>0&&a.usePlugin(...i.pluginFactories),r(a,i.routeConfig,i.resolvedForwardMap),a}},Gt=class e{#Ee;#Pe;#Oe;constructor(e){this.#Ee=e.routerFSM,this.#Pe=e.emitter,this.#Oe=void 0,this.#$e()}static validateEventName(e){if(!D.has(e))throw new Error(`Invalid event name: ${String(e)}`)}static validateListenerArgs(t,r){if(e.validateEventName(t),"function"!=typeof r)throw new TypeError(`Expected callback to be a function for event ${t}`)}static validateSubscribeListener(e){if("function"!=typeof e)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#Pe.emit($.ROUTER_START)}emitRouterStop(){this.#Pe.emit($.ROUTER_STOP)}emitTransitionStart(e,t){this.#Pe.emit($.TRANSITION_START,e,t)}emitTransitionSuccess(e,t,r){this.#Pe.emit($.TRANSITION_SUCCESS,e,t,r)}emitTransitionError(e,t,r){this.#Pe.emit($.TRANSITION_ERROR,e,t,r)}emitTransitionCancel(e,t){this.#Pe.emit($.TRANSITION_CANCEL,e,t)}sendStart(){this.#Ee.send(L)}sendStop(){this.#Ee.send(G)}sendDispose(){this.#Ee.send(q)}completeStart(){this.#Ee.send(k)}beginTransition(e,t){this.#Oe=e,this.#Ee.send(U,{toState:e,fromState:t})}completeTransition(e,t,r={}){this.#Ee.send(_,{state:e,fromState:t,opts:r}),this.#Oe=void 0}failTransition(e,t,r){this.#Ee.send(B,{toState:e,fromState:t,error:r}),this.#Oe=void 0}cancelTransition(e,t){this.#Ee.send(V,{toState:e,fromState:t}),this.#Oe=void 0}emitOrFailTransitionError(e,t,r){this.#Ee.getState()===F?this.#Ee.send(B,{toState:e,fromState:t,error:r}):this.emitTransitionError(e,t,r)}canBeginTransition(){return this.#Ee.canSend(U)}canStart(){return this.#Ee.canSend(L)}canCancel(){return this.#Ee.canSend(V)}isActive(){const e=this.#Ee.getState();return e!==j&&e!==I}isDisposed(){return this.#Ee.getState()===I}isTransitioning(){return this.#Ee.getState()===x}isReady(){return this.#Ee.getState()===F}getCurrentToState(){return this.#Oe}addEventListener(e,t){return this.#Pe.on(e,t)}subscribe(e){return this.#Pe.on($.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}clearAll(){this.#Pe.clearAll()}setLimits(e){this.#Pe.setLimits(e)}cancelTransitionIfRunning(e){this.canCancel()&&this.cancelTransition(this.#Oe,e)}#$e(){const e=this.#Ee;e.on(M,k,()=>{this.emitRouterStart()}),e.on(F,G,()=>{this.emitRouterStop()}),e.on(F,U,e=>{this.emitTransitionStart(e.toState,e.fromState)}),e.on(x,_,e=>{this.emitTransitionSuccess(e.state,e.fromState,e.opts)}),e.on(x,V,e=>{this.emitTransitionCancel(e.toState,e.fromState)}),e.on(M,B,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(F,B,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(x,B,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)})}},qt=new xt(T.ROUTER_ALREADY_STARTED),zt=new Set(["all","warn-error","error-only"]);var Wt=class{router;options;limits;dependencies;state;routes;routeLifecycle;middleware;plugins;navigation;lifecycle;clone;eventBus;constructor(e){this.router=e.router,this.options=e.options,this.limits=e.limits,this.dependencies=e.dependencies,this.state=e.state,this.routes=e.routes,this.routeLifecycle=e.routeLifecycle,this.middleware=e.middleware,this.plugins=e.plugins,this.navigation=e.navigation,this.lifecycle=e.lifecycle,this.clone=e.clone,this.eventBus=e.eventBus}wireLimits(){this.dependencies.setLimits(this.limits),this.plugins.setLimits(this.limits),this.middleware.setLimits(this.limits),this.eventBus.setLimits({maxListeners:this.limits.maxListeners,warnListeners:this.limits.warnListeners,maxEventDepth:this.limits.maxEventDepth}),this.routeLifecycle.setLimits(this.limits)}wireRouteLifecycleDeps(){this.routeLifecycle.setRouter(this.router),this.routeLifecycle.setDependencies({getDependency:e=>this.dependencies.get(e)})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(e,t)=>{this.router.addActivateGuard(e,t)},addDeactivateGuard:(e,t)=>{this.router.addDeactivateGuard(e,t)},makeState:(e,t,r,i)=>this.state.makeState(e,t,r,i),getState:()=>this.state.get(),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependencies.get(e),forwardState:(e,t)=>this.router.forwardState(e,t)}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wireMiddlewareDeps(){this.middleware.setRouter(this.router),this.middleware.setDependencies({getDependency:e=>this.dependencies.get(e)})}wirePluginsDeps(){this.plugins.setRouter(this.router),this.plugins.setDependencies({addEventListener:(e,t)=>this.eventBus.addEventListener(e,t),canNavigate:()=>this.eventBus.canBeginTransition(),getDependency:e=>this.dependencies.get(e)})}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:e=>this.routes.hasRoute(e),getState:()=>this.state.get(),setState:e=>{this.state.set(e)},buildStateWithSegments:(e,t)=>{const{name:r,params:i}=this.router.forwardState(e,t);return this.routes.buildStateWithSegmentsResolved(r,i)},makeState:(e,t,r,i)=>this.state.makeState(e,t,r,i),buildPath:(e,t)=>this.routes.buildPath(e,t,this.options.get()),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependencies.get(e),startTransition:(e,t)=>{this.eventBus.beginTransition(e,t)},cancelNavigation:()=>{this.eventBus.cancelTransition(this.eventBus.getCurrentToState(),this.state.get())},sendTransitionDone:(e,t,r)=>{this.eventBus.completeTransition(e,t,r)},sendTransitionBlocked:(e,t,r)=>{this.eventBus.failTransition(e,t,r)},sendTransitionError:(e,t,r)=>{this.eventBus.failTransition(e,t,r)},emitTransitionError:(e,t,r)=>{this.eventBus.emitOrFailTransitionError(e,t,r)}}),this.navigation.setTransitionDependencies({getLifecycleFunctions:()=>this.routeLifecycle.getFunctions(),getMiddlewareFunctions:()=>this.middleware.getFunctions(),isActive:()=>this.router.isActive(),isTransitioning:()=>this.eventBus.isTransitioning(),clearCanDeactivate:e=>{this.routeLifecycle.clearCanDeactivate(e)}})}wireLifecycleDeps(){this.lifecycle.setDependencies({getOptions:()=>this.options.get(),makeNotFoundState:(e,t)=>this.state.makeNotFoundState(e,t),setState:e=>{this.state.set(e)},matchPath:e=>this.routes.matchPath(e,this.options.get()),completeStart:()=>{this.eventBus.completeStart()},emitTransitionError:(e,t,r)=>{this.eventBus.failTransition(e,t,r)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getConfig().defaultParams,buildPath:(e,t)=>this.routes.buildPath(e,t,this.options.get()),getUrlParams:e=>this.routes.getUrlParams(e)})}wireCloneCallbacks(){this.clone.setGetCloneData(()=>{const[e,t]=this.routeLifecycle.getFactories();return{routes:this.routes.cloneRoutes(),options:{...this.options.get()},dependencies:this.dependencies.getAll(),canDeactivateFactories:e,canActivateFactories:t,middlewareFactories:this.middleware.getFactories(),pluginFactories:this.plugins.getAll(),routeConfig:this.routes.getConfig(),resolvedForwardMap:this.routes.getResolvedForwardMap()}})}wireCyclicDeps(){this.navigation.setCanNavigate(()=>this.eventBus.canBeginTransition()),this.lifecycle.setNavigateToState((e,t,r)=>this.navigation.navigateToState(e,t,r))}},Ht=class r{#h;#u;#d;#De;#Ne;#Ce;#je;#R;#Me;#Fe;#xe;#Ie;#te;constructor(r=[],i={},a={}){i.logger&&function(e){if("object"!=typeof e||null===e)throw new TypeError("Logger config must be an object");const t=e;for(const e of Object.keys(t))if("level"!==e&&"callback"!==e)throw new TypeError(`Unknown logger config property: "${e}"`);if("level"in t&&void 0!==t.level&&("string"!=typeof(r=t.level)||!zt.has(r)))throw new TypeError(`Invalid logger level: ${function(e){return"string"==typeof e?`"${e}"`:"object"==typeof e?JSON.stringify(e):String(e)}(t.level)}. Expected: "all" | "warn-error" | "error-only"`);var r;if("callback"in t&&void 0!==t.callback&&"function"!=typeof t.callback)throw new TypeError("Logger callback must be a function, got "+typeof t.callback);return!0}(i.logger)&&(e.logger.configure(i.logger),delete i.logger),ae.validateOptions(i,"constructor");const s=i.noValidate??!1;s||J.validateDependenciesObject(a,"constructor"),!s&&r.length>0&&(Nt.validateAddRouteArgs(r),Nt.validateRoutes(r)),this.#h=new ae(i),this.#u=function(e={}){return{...N,...e}}(i.limits),this.#d=new J(a),this.#De=new oe,this.#Ne=new Nt(r,s,function(e){return{strictTrailingSlash:"strict"===e.trailingSlash,strictQueryParams:"strict"===e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding,queryParams:e.queryParams}}(this.#h.get())),this.#Ce=new ge,this.#je=new de,this.#R=new fe,this.#Me=new _t,this.#Fe=new Bt,this.#xe=new Vt,this.#te=s;const o=new t.FSM(z),c=new n({onListenerError:(t,r)=>{e.logger.error("Router",`Error in listener for ${t}:`,r)},onListenerWarn:(t,r)=>{e.logger.warn("router.addEventListener",`Event "${t}" has ${r} listeners — possible memory leak`)}});var d;this.#Ie=new Gt({routerFSM:o,emitter:c}),(d=new Wt({router:this,options:this.#h,limits:this.#u,dependencies:this.#d,state:this.#De,routes:this.#Ne,routeLifecycle:this.#Ce,middleware:this.#je,plugins:this.#R,navigation:this.#Me,lifecycle:this.#Fe,clone:this.#xe,eventBus:this.#Ie})).wireLimits(),d.wireRouteLifecycleDeps(),d.wireRoutesDeps(),d.wireMiddlewareDeps(),d.wirePluginsDeps(),d.wireNavigationDeps(),d.wireLifecycleDeps(),d.wireStateDeps(),d.wireCloneCallbacks(),d.wireCyclicDeps(),this.addRoute=this.addRoute.bind(this),this.removeRoute=this.removeRoute.bind(this),this.clearRoutes=this.clearRoutes.bind(this),this.getRoute=this.getRoute.bind(this),this.hasRoute=this.hasRoute.bind(this),this.updateRoute=this.updateRoute.bind(this),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.matchPath=this.matchPath.bind(this),this.setRootPath=this.setRootPath.bind(this),this.getRootPath=this.getRootPath.bind(this),this.makeState=this.makeState.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.forwardState=this.forwardState.bind(this),this.buildState=this.buildState.bind(this),this.buildNavigationState=this.buildNavigationState.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.getOptions=this.getOptions.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.addActivateGuard=this.addActivateGuard.bind(this),this.addDeactivateGuard=this.addDeactivateGuard.bind(this),this.removeActivateGuard=this.removeActivateGuard.bind(this),this.removeDeactivateGuard=this.removeDeactivateGuard.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.useMiddleware=this.useMiddleware.bind(this),this.setDependency=this.setDependency.bind(this),this.setDependencies=this.setDependencies.bind(this),this.getDependency=this.getDependency.bind(this),this.getDependencies=this.getDependencies.bind(this),this.removeDependency=this.removeDependency.bind(this),this.hasDependency=this.hasDependency.bind(this),this.resetDependencies=this.resetDependencies.bind(this),this.addEventListener=this.addEventListener.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToState=this.navigateToState.bind(this),this.subscribe=this.subscribe.bind(this),this.clone=this.clone.bind(this)}addRoute(e,t){const r=Array.isArray(e)?e:[e],i=t?.parent;return this.#te||(void 0!==i&&Nt.validateParentOption(i),Nt.validateAddRouteArgs(r),Nt.validateRoutes(r,this.#Ne.getTree(),this.#Ne.getForwardRecord(),i)),this.#Ne.addRoutes(r,i),this}removeRoute(t){return this.#te||Nt.validateRemoveRouteArgs(t),this.#Ne.validateRemoveRoute(t,this.#De.get()?.name,this.#Ie.isTransitioning())?(this.#Ne.removeRoute(t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),this):this}clearRoutes(){const e=this.#Ie.isTransitioning();return this.#Ne.validateClearRoutes(e)?(this.#Ne.clearRoutes(),this.#Ce.clearAll(),this.#De.set(void 0),this):this}getRoute(e){return this.#te||w(e,"getRoute"),this.#Ne.getRoute(e)}hasRoute(e){return this.#te||w(e,"hasRoute"),this.#Ne.hasRoute(e)}updateRoute(t,r){this.#te||Nt.validateUpdateRouteBasicArgs(t,r);const{forwardTo:i,defaultParams:n,decodeParams:a,encodeParams:s,canActivate:o,canDeactivate:c}=r;return this.#te||Nt.validateUpdateRoutePropertyTypes(i,n,a,s),this.#Ie.isTransitioning()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),this.#te||this.#Ne.validateUpdateRoute(t,i),this.#Ne.updateRouteConfig(t,{forwardTo:i,defaultParams:n,decodeParams:a,encodeParams:s}),void 0!==o&&(null===o?this.#Ce.clearCanActivate(t):this.addActivateGuard(t,o)),void 0!==c&&(null===c?this.#Ce.clearCanDeactivate(t):this.addDeactivateGuard(t,c)),this}isActiveRoute(t,r,i,n){return this.#te||Nt.validateIsActiveRouteArgs(t,r,i,n),""===t?(e.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#Ne.isActiveRoute(t,r,i,n)}buildPath(e,t){return this.#te||Nt.validateBuildPathArgs(e),this.#Ne.buildPath(e,t,this.#h.get())}matchPath(e){return this.#te||Nt.validateMatchPathArgs(e),this.#Ne.matchPath(e,this.#h.get())}setRootPath(e){this.#te||Nt.validateSetRootPathArgs(e),this.#Ne.setRootPath(e)}getRootPath(){return this.#Ne.getRootPath()}makeState(e,t,r,i,n){return this.#te||oe.validateMakeStateArgs(e,t,r,n),this.#De.makeState(e,t,r,i,n)}getState(){return this.#De.get()}getPreviousState(){return this.#De.getPrevious()}areStatesEqual(e,t,r=!0){return this.#te||oe.validateAreStatesEqualArgs(e,t,r),this.#De.areStatesEqual(e,t,r)}forwardState(e,t){return this.#te||Nt.validateStateBuilderArgs(e,t,"forwardState"),this.#Ne.forwardState(e,t)}buildState(e,t){this.#te||Nt.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:i}=this.forwardState(e,t);return this.#Ne.buildStateResolved(r,i)}buildNavigationState(e,t={}){this.#te||Nt.validateStateBuilderArgs(e,t,"buildNavigationState");const r=this.buildState(e,t);if(r)return this.makeState(r.name,r.params,this.buildPath(r.name,r.params),{params:r.meta,options:{}})}shouldUpdateNode(e){return this.#te||Nt.validateShouldUpdateNodeArgs(e),this.#Ne.shouldUpdateNode(e)}getOptions(){return this.#h.get()}isActive(){return this.#Ie.isActive()}async start(e){if(this.#te||Bt.validateStartArgs([e]),!this.#Ie.canStart())throw qt;this.#Ie.sendStart();try{return await this.#Fe.start(e)}catch(e){throw this.#Ie.isReady()&&(this.#Fe.stop(),this.#Ie.sendStop()),e}}stop(){return this.#Ie.cancelTransitionIfRunning(this.#De.get()),this.#Ie.isReady()||this.#Ie.isTransitioning()?(this.#Fe.stop(),this.#Ie.sendStop(),this):this}dispose(){this.#Ie.isDisposed()||(this.#Ie.cancelTransitionIfRunning(this.#De.get()),(this.#Ie.isReady()||this.#Ie.isTransitioning())&&(this.#Fe.stop(),this.#Ie.sendStop()),this.#Ie.sendDispose(),this.#Ie.clearAll(),this.#R.disposeAll(),this.#je.clearAll(),this.#Ne.clearRoutes(),this.#Ce.clearAll(),this.#De.reset(),this.#d.reset(),this.#Le())}addDeactivateGuard(e,t){return this.#te||(w(e,"addDeactivateGuard"),ge.validateHandler(t,"addDeactivateGuard")),this.#Ce.addCanDeactivate(e,t,this.#te),this}addActivateGuard(e,t){return this.#te||(w(e,"addActivateGuard"),ge.validateHandler(t,"addActivateGuard")),this.#Ce.addCanActivate(e,t,this.#te),this}removeActivateGuard(e){this.#te||w(e,"removeActivateGuard"),this.#Ce.clearCanActivate(e)}removeDeactivateGuard(e){this.#te||w(e,"removeDeactivateGuard"),this.#Ce.clearCanDeactivate(e)}canNavigateTo(e,t){if(this.#te||w(e,"canNavigateTo"),!this.hasRoute(e))return!1;const{name:r,params:i}=this.forwardState(e,t??{}),n=this.makeState(r,i),a=this.getState(),{toDeactivate:s,toActivate:o}=$t(n,a);for(const e of s)if(!this.#Ce.checkDeactivateGuardSync(e,n,a))return!1;for(const e of o)if(!this.#Ce.checkActivateGuardSync(e,n,a))return!1;return!0}usePlugin(...e){return this.#te||(fe.validateUsePluginArgs(e),fe.validatePluginLimit(this.#R.count(),e.length,this.#u.maxPlugins),fe.validateNoDuplicatePlugins(e,this.#R.has.bind(this.#R))),this.#R.use(...e)}useMiddleware(...e){this.#te||(de.validateUseMiddlewareArgs(e),de.validateNoDuplicates(e,this.#je.getFactories()),de.validateMiddlewareLimit(this.#je.count(),e.length,this.#u.maxMiddleware));const t=this.#je.initialize(...e);if(!this.#te)for(const{middleware:e,factory:r}of t)de.validateMiddleware(e,r);return this.#je.commit(t)}setDependency(e,t){return this.#te||J.validateSetDependencyArgs(e),this.#d.set(e,t),this}setDependencies(e){return this.#te||(J.validateDependenciesObject(e,"setDependencies"),J.validateDependencyLimit(this.#d.count(),Object.keys(e).length,"setDependencies",this.#u.maxDependencies)),this.#d.setMultiple(e),this}getDependency(e){this.#te||J.validateName(e,"getDependency");const t=this.#d.get(e);return this.#te||J.validateDependencyExists(t,e),t}getDependencies(){return this.#d.getAll()}removeDependency(e){return this.#te||J.validateName(e,"removeDependency"),this.#d.remove(e),this}hasDependency(e){return this.#te||J.validateName(e,"hasDependency"),this.#d.has(e)}resetDependencies(){return this.#d.reset(),this}addEventListener(e,t){return this.#te||Gt.validateListenerArgs(e,t),this.#Ie.addEventListener(e,t)}subscribe(e){return this.#te||Gt.validateSubscribeListener(e),this.#Ie.subscribe(e)}navigate(e,t,i){this.#te||_t.validateNavigateArgs(e);const n=i??{};this.#te||_t.validateNavigationOptions(n,"navigate");const a=this.#Me.navigate(e,t??{},n);return r.#ke(a),a}navigateToDefault(e){this.#te||_t.validateNavigateToDefaultArgs(e);const t=e??{};this.#te||_t.validateNavigationOptions(t,"navigateToDefault");const i=this.#Me.navigateToDefault(t);return r.#ke(i),i}navigateToState(e,t,r){return this.#te||_t.validateNavigateToStateArgs(e,t,r),this.#Me.navigateToState(e,t,r)}clone(e){return this.#te||Vt.validateCloneArgs(e),this.#xe.clone(e,(e,t,i)=>new r(e,t,i),(e,t,r)=>{e.#Ne.applyClonedConfig(t,r)})}static#Ue=t=>{t instanceof xt&&(t.code===T.SAME_STATES||t.code===T.TRANSITION_CANCELLED||t.code===T.ROUTER_NOT_STARTED||t.code===T.ROUTE_NOT_FOUND)||e.logger.error("router.navigate","Unexpected navigation error",t)};static#ke(e){e.catch(r.#Ue)}#Le(){this.navigate=Qt,this.navigateToDefault=Qt,this.navigateToState=Qt,this.start=Qt,this.stop=Qt,this.addRoute=Qt,this.removeRoute=Qt,this.clearRoutes=Qt,this.updateRoute=Qt,this.addActivateGuard=Qt,this.addDeactivateGuard=Qt,this.removeActivateGuard=Qt,this.removeDeactivateGuard=Qt,this.usePlugin=Qt,this.useMiddleware=Qt,this.setDependency=Qt,this.setDependencies=Qt,this.removeDependency=Qt,this.resetDependencies=Qt,this.addEventListener=Qt,this.subscribe=Qt,this.setRootPath=Qt,this.clone=Qt,this.canNavigateTo=Qt}};function Qt(){throw new xt(T.ROUTER_DISPOSED)}exports.Router=Ht,exports.RouterError=xt,exports.constants=b,exports.createRouter=(e=[],t={},r={})=>new Ht(e,t,r),exports.errorCodes=T,exports.events=$,exports.getNavigator=e=>Object.freeze({navigate:e.navigate,getState:e.getState,isActiveRoute:e.isActiveRoute,canNavigateTo:e.canNavigateTo,subscribe:e.subscribe});//# sourceMappingURL=index.js.map
|