@real-router/core 0.18.0 → 0.20.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 CHANGED
@@ -203,12 +203,6 @@ router.useMiddleware((router) => (toState, fromState, done) => {
203
203
  });
204
204
  ```
205
205
 
206
- #### `router.clearMiddleware()`
207
-
208
- Clear all middleware.\
209
- Returns: `void`\
210
- [Wiki](https://github.com/greydragon888/real-router/wiki/clearMiddleware)
211
-
212
206
  ---
213
207
 
214
208
  ## Advanced API
@@ -384,13 +378,6 @@ Get all router options.\
384
378
  Returns: `Options`\
385
379
  [Wiki](https://github.com/greydragon888/real-router/wiki/getOptions)
386
380
 
387
- #### `router.getOption(name: keyof Options): unknown`
388
-
389
- Get a single router option by name.\
390
- `name: keyof Options` — option name\
391
- Returns: option value\
392
- [Wiki](https://github.com/greydragon888/real-router/wiki/getOption)
393
-
394
381
  ---
395
382
 
396
383
  ### Other
@@ -34,7 +34,7 @@ type EventMethodMap = {
34
34
  * Router class with integrated namespace architecture.
35
35
  *
36
36
  * All functionality is provided by namespace classes:
37
- * - OptionsNamespace: getOptions, getOption (immutable)
37
+ * - OptionsNamespace: getOptions (immutable)
38
38
  * - DependenciesNamespace: get/set/remove dependencies
39
39
  * - ObservableNamespace: event listeners, subscribe
40
40
  * - StateNamespace: state storage (getState, setState, getPreviousState)
@@ -76,7 +76,6 @@ declare class Router<Dependencies extends DefaultDependencies = DefaultDependenc
76
76
  buildNavigationState(name: string, params?: Params): State | undefined;
77
77
  shouldUpdateNode(nodeName: string): (toState: State, fromState?: State) => boolean;
78
78
  getOptions(): Options;
79
- getOption<K extends keyof Options>(option: K): Options[K];
80
79
  isActive(): boolean;
81
80
  start(startPath: string): Promise<State>;
82
81
  stop(): this;
@@ -87,7 +86,6 @@ declare class Router<Dependencies extends DefaultDependencies = DefaultDependenc
87
86
  canNavigateTo(name: string, params?: Params): boolean;
88
87
  usePlugin(...plugins: PluginFactory<Dependencies>[]): Unsubscribe;
89
88
  useMiddleware(...middlewares: MiddlewareFactory<Dependencies>[]): Unsubscribe;
90
- clearMiddleware(): this;
91
89
  setDependency<K extends keyof Dependencies & string>(dependencyName: K, dependency: Dependencies[K]): this;
92
90
  setDependencies(deps: Dependencies): this;
93
91
  getDependency<K extends keyof Dependencies>(key: K): Dependencies[K];
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- var e=require("@real-router/logger"),t=["replace","reload","force","forceDeactivate","redirected"],r=/\S/,n=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function i(e,t){return new TypeError(`[router.${e}] ${t}`)}function a(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=>a(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=>a(e,t))}return!1}function o(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function s(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 n=e[t];if(!o(n)){const e=typeof n;if("function"===e||"symbol"===e)return!1;r=!0;break}}return!r||a(e)}function c(e){return"object"==typeof e&&null!==e&&("string"==typeof(r=(t=e).name)&&(""===r||!(r.length>1e4)&&(!!r.startsWith("@@")||n.test(r)))&&"string"==typeof t.path&&s(t.params));var t,r}function d(e){return"string"==typeof e}function u(e){return"boolean"==typeof e}function l(e){return"object"==typeof e&&null!==e&&"then"in e&&"function"==typeof e.then}function h(e,t){return e in t}function f(e,t){if("string"!=typeof e)throw i(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!r.test(e))throw i(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw i(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!n.test(e))throw i(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 p(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 g(e,t){if(!c(e))throw new TypeError(`[${t}] Invalid state structure: ${p(e)}. Expected State object with name, params, and path properties.`)}var m=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"}),v={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},w="onStart",y="onStop",b="onTransitionStart",S="onTransitionCancel",T="onTransitionSuccess",R="onTransitionError",E={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},A={maxDependencies:100,maxPlugins:50,maxMiddleware:50,maxListeners:1e4,maxEventDepth:5,maxLifecycleHandlers:200},O={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxMiddleware:{min:0,max:1e3},maxListeners:{min:0,max:1e5},maxEventDepth:{min:0,max:100},maxLifecycleHandlers:{min:0,max:1e4}},$=new WeakSet;function P(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)P(t);else for(const t in e)P(e[t])}function N(e){return e?($.has(e)||(P(e),$.add(e)),e):e}function D(e){return{warn:Math.floor(.2*e),error:Math.floor(.5*e)}}var C=class{#e=Object.create(null);#t=A;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 ${p(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,n){!function(e,t,r,n=A.maxDependencies){if(0===n)return;const i=e+t;if(i>=n)throw new Error(`[router.${r}] Dependency limit exceeded (${n}). Current: ${i}. This is likely a bug in your code.`)}(e,t,r,n)}setLimits(e){this.#t=e}set(t,r){if(void 0===r)return!1;if(Object.hasOwn(this.#e,t)){const n=this.#e[t],i=n!==r,a=Number.isNaN(n)&&Number.isNaN(r);i&&!a&&e.logger.warn("router.setDependency","Router dependency already exists and is being overwritten:",t)}else this.#r("setDependency");return this.#e[t]=r,!0}setMultiple(t){const r=[];for(const e in t)void 0!==t[e]&&(Object.hasOwn(this.#e,e)&&r.push(e),this.#e[e]=t[e]);r.length>0&&e.logger.warn("router.setDependencies","Overwritten:",r.join(", "))}get(e){return this.#e[e]}getAll(){return{...this.#e}}count(){return Object.keys(this.#e).length}remove(t){Object.hasOwn(this.#e,t)||e.logger.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${p(t)}"`),delete this.#e[t]}has(e){return Object.hasOwn(this.#e,e)}reset(){for(const e in this.#e)delete this.#e[e]}#r(t){const r=this.#t.maxDependencies;if(0===r)return;const n=Object.keys(this.#e).length,{warn:i,error:a}=D(r);if(n===i)e.logger.warn(`router.${t}`,`${i} dependencies registered. Consider if all are necessary.`);else if(n===a)e.logger.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${r}.`);else if(n>=r)throw new Error(`[router.${t}] Dependency limit exceeded (${r}). Current: ${n}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}},j=new Set([E.ROUTER_START,E.TRANSITION_START,E.TRANSITION_SUCCESS,E.TRANSITION_ERROR,E.TRANSITION_CANCEL,E.ROUTER_STOP]);function M(t,r,...n){if(0===r.size)return;const i=[...r];for(const r of i)try{Function.prototype.apply.call(r,void 0,n)}catch(r){e.logger.error("Router",`Error in listener for ${t}:`,r)}}var k=class t{#n={};#i=null;#t=A;static validateEventName(e){if(!j.has(e))throw new Error(`Invalid event name: ${String(e)}`)}static validateCallback(e,t){if("function"!=typeof e)throw new TypeError(`Expected callback to be a function for event ${t}`)}static validateListenerArgs(e,r){t.validateEventName(e),t.validateCallback(r,e)}static validateSubscribeListener(e){if("function"!=typeof e)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}setLimits(e){this.#t=e}invoke(e,t,r,n){this.#a(e);const i=this.#o();try{switch(i[e]++,e){case E.TRANSITION_START:case E.TRANSITION_CANCEL:M(e,this.#s(e),t,r);break;case E.TRANSITION_ERROR:case E.TRANSITION_SUCCESS:M(e,this.#s(e),t,r,n);break;default:M(e,this.#s(e))}}finally{i[e]--}}hasListeners(e){const t=this.#n[e];return void 0!==t&&t.size>0}removeEventListener(t,r){const n=this.#n[t];n&&0!==n.size&&(n.delete(r)||e.logger.warn("Router",`Attempted to remove non-existent listener for "${t}". This might indicate a memory leak or incorrect cleanup logic.`))}addEventListener(t,r){const n=this.#s(t);if(n.has(r))throw new Error(`[router.addEventListener] Listener already exists for event "${t}". Each listener function can only be registered once per event. Store the returned unsubscribe function to remove the listener.`);const i=this.#t.maxListeners;if(1e3===n.size&&e.logger.warn("router.addEventListener",`Warning: Event "${t}" has ${n.size} listeners. This might indicate a memory leak.`),0!==i&&n.size>=i)throw new Error(`[router.addEventListener] Maximum listener limit (${i}) reached for event "${t}". This is a critical memory leak. The application is creating listeners exponentially. Check for loops or recursive calls that register listeners.`);return n.add(r),()=>{this.removeEventListener(t,r)}}subscribe(e){return this.addEventListener(E.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}#s(e){const t=this.#n[e];if(t)return t;const r=new Set;return this.#n[e]=r,r}#o(){return this.#i??={[E.ROUTER_START]:0,[E.TRANSITION_START]:0,[E.TRANSITION_SUCCESS]:0,[E.TRANSITION_ERROR]:0,[E.TRANSITION_CANCEL]:0,[E.ROUTER_STOP]:0},this.#i}#a(e){const t=this.#t.maxEventDepth;if(0!==t&&this.#o()[e]>=t)throw new Error(`[Router] Maximum recursion depth (${t}) exceeded for event: ${e}`)}},F={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},I={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},L={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function x(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&x(r)}return e}function _(e,t){return"function"==typeof e?e(t):e}function U(e,t,r){if("function"==typeof t&&("defaultRoute"===e||"defaultParams"===e))return;const n=F[e];if(n&&"object"==typeof n)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 ${p(e)}`);for(const n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw new TypeError(`[router.${r}] Getters not allowed in "${t}": "${n}"`)}(t,e,r),void("queryParams"===e&&function(e,t){for(const r in e){if(!h(r,L)){const e=Object.keys(L).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],i=L[r];if(!i.includes(n)){const e=i.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Invalid value for queryParams.${r}: expected one of ${e}, got "${String(n)}"`)}}}(t,r));if(typeof t!=typeof n)throw new TypeError(`[router.${r}] Invalid type for "${e}": expected ${typeof n}, got ${typeof t}`);e in I&&function(e,t,r){const n=I[e];if(!n.includes(t)){const i=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${i}, got "${String(t)}"`)}}(e,t,r)}function V(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,n]of Object.entries(e)){if(!Object.hasOwn(O,r))throw new TypeError(`[router.${t}]: unknown limit: "${r}"`);void 0!==n&&z(r,n,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function z(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 n=O[e];if(t<n.min||t>n.max)throw new RangeError(`[router.${r}]: limit "${e}" must be between ${n.min} and ${n.max}, got ${t}`)}var G=class{#c;constructor(e={}){this.#c=x({...F,...e})}static validateOptionName(e,t){!function(e,t){if("string"!=typeof e)throw new TypeError(`[router.${t}]: option name must be a string, got ${typeof e}`)}(e,t)}static validateOptionExists(e,t){!function(e,t){if(!Object.hasOwn(F,e))throw new ReferenceError(`[router.${t}]: option "${e}" not found`)}(e,t)}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 ${p(e)}`);for(const[r,n]of Object.entries(e))h(r,F)?void 0!==n&&U(r,n,t):V(r,n,t)}(e,t)}get(){return this.#c}getOption(e){return this.#c[e]}};function q(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>q(e,t[r]))}var W=class{#d=0;#u=void 0;#l=void 0;#h;#f=new Map;get#p(){if(!this.#h)throw new Error("[real-router] StateNamespace: dependencies not initialized");return this.#h}static validateMakeStateArgs(e,t,r,n){if(!d(e))throw new TypeError(`[router.makeState] Invalid name: ${p(e)}. Expected string.`);if(void 0!==t&&!s(t))throw new TypeError(`[router.makeState] Invalid params: ${p(t)}. Expected plain object.`);if(void 0!==r&&!d(r))throw new TypeError(`[router.makeState] Invalid path: ${p(r)}. Expected string.`);if(void 0!==n&&"number"!=typeof n)throw new TypeError(`[router.makeState] Invalid forceId: ${p(n)}. Expected number.`)}static validateAreStatesEqualArgs(e,t,r){if(null!=e&&g(e,"areStatesEqual"),null!=t&&g(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${p(r)}. Expected boolean.`)}get(){return this.#u}set(e){this.#l=this.#u,e?Object.isFrozen(e)?this.#u=e:this.#u=N(e):this.#u=void 0}getPrevious(){return this.#l}setDependencies(e){this.#h=e}makeState(e,t,r,n,i){const a=n?{...n,id:i??++this.#d,params:n.params,options:n.options,redirected:n.redirected}:void 0,o=this.#p.getDefaultParams();let s;return s=Object.hasOwn(o,e)?{...o[e],...t}:t?{...t}:{},N({name:e,params:s,path:r??this.#p.buildPath(e,t),meta:a})}makeNotFoundState(e,t){return this.makeState(v.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 n=e[r];for(const e in n)"url"===n[e]&&t.push(e)}return t}(r):this.#g(e.name)).every(r=>q(e.params[r],t.params[r]))}const n=Object.keys(e.params),i=Object.keys(t.params);return n.length===i.length&&n.every(r=>r in t.params&&q(e.params[r],t.params[r]))}#g(e){const t=this.#f.get(e);if(void 0!==t)return t;const r=this.#p.getUrlParams(e);return this.#f.set(e,r),r}};function B(e){return e.name||"anonymous"}var H=class{#m=new Set;#v=new Map;#w;#h;#t=A;get#y(){if(!this.#w)throw new Error("[real-router] MiddlewareNamespace: router not initialized");return this.#w}get#p(){if(!this.#h)throw new Error("[real-router] MiddlewareNamespace: dependencies not initialized");return this.#h}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 ${p(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 ${p(e)}. Factory: ${B(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: ${B(t)}`)}(e,t)}static validateMiddlewareLimit(e,t,r){!function(e,t,r=A.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.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#t=e}count(){return this.#m.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.#m.add(t),this.#v.set(t,r);let t=!1;return()=>{if(!t){t=!0;for(const{factory:t}of e)this.#m.delete(t),this.#v.delete(t)}}}clear(){this.#m.clear(),this.#v.clear()}getFactories(){return[...this.#m]}getFunctions(){return[...this.#v.values()]}#b(t){const r=this.#t.maxMiddleware;if(0===r)return;const n=t+this.#m.size,{warn:i,error:a}=D(r);n>=a?e.logger.error("router.useMiddleware",`${n} middleware registered! This is excessive and will impact performance. Hard limit at ${r}.`):n>=i&&e.logger.warn("router.useMiddleware",`${n} middleware registered. Consider if all are necessary.`)}},Q={[w]:E.ROUTER_START,[y]:E.ROUTER_STOP,[T]:E.TRANSITION_SUCCESS,[b]:E.TRANSITION_START,[R]:E.TRANSITION_ERROR,[S]:E.TRANSITION_CANCEL},K=Object.keys(Q).filter(e=>h(e,Q)),J="router.usePlugin",Z=class t{#S=new Set;#w;#h;#t=A;get#y(){if(!this.#w)throw new Error("[real-router] PluginsNamespace: router not initialized");return this.#w}get#p(){if(!this.#h)throw new Error("[real-router] PluginsNamespace: dependencies not initialized");return this.#h}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 ${p(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&&!h(t,Q))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=A.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.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#t=e}count(){return this.#S.size}use(...t){if(this.#b(t.length),1===t.length){const r=t[0],n=this.#T(r);this.#S.add(r);let i=!1;return()=>{if(!i){i=!0,this.#S.delete(r);try{n()}catch(t){e.logger.error(J,"Error during cleanup:",t)}}}}const r=this.#R(t),n=[];try{for(const e of r){const t=this.#T(e);n.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(J,"Cleanup error:",t)}throw t}for(const{factory:e}of n)this.#S.add(e);let i=!1;return()=>{if(!i){i=!0;for(const{factory:e}of n)this.#S.delete(e);for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(J,"Error during cleanup:",t)}}}}getAll(){return[...this.#S]}has(e){return this.#S.has(e)}#b(t){const r=this.#t.maxPlugins;if(0===r)return;const n=t+this.#S.size,{warn:i,error:a}=D(r);n>=a?e.logger.error(J,`${n} plugins registered!`):n>=i&&e.logger.warn(J,`${n} plugins registered`)}#R(t){const r=new Set;for(const n of t)r.has(n)?e.logger.warn(J,"Duplicate factory in batch, will be registered once"):r.add(n);return r}#T(r){const n=r(this.#y,this.#p.getDependency);t.validatePlugin(n),Object.freeze(n);const i=[];for(const t of K)t in n&&("function"==typeof n[t]?(i.push(this.#p.addEventListener(Q[t],n[t])),"onStart"===t&&this.#p.isStarted()&&e.logger.warn(J,"Router already started, onStart will not be called")):e.logger.warn(J,`Property '${t}' is not a function, skipping`));return()=>{for(const e of i)e();"function"==typeof n.teardown&&n.teardown()}}},Y=class{#E=new Map;#A=new Map;#O=new Map;#$=new Map;#P=new Set;#w;#h;#t=A;get#y(){if(!this.#w)throw new Error("[real-router] RouteLifecycleNamespace: router not initialized");return this.#w}get#p(){if(!this.#h)throw new Error("[real-router] RouteLifecycleNamespace: dependencies not initialized");return this.#h}static validateHandler(e,t){!function(e,t){if(!u(e)&&"function"!=typeof e)throw new TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${p(e)}`)}(e,t)}static validateNotRegistering(e,t,r){!function(e,t,r){if(e)throw new Error(`[router.${r}] Cannot modify route "${t}" during its own registration`)}(e,t,r)}static validateHandlerLimit(e,t,r){!function(e,t,r=A.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.`)}(e,t,r)}setRouter(e){this.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#t=e}isRegistering(e){return this.#P.has(e)}countCanActivate(){return this.#A.size}countCanDeactivate(){return this.#E.size}hasCanActivate(e){return this.#A.has(e)}hasCanDeactivate(e){return this.#E.has(e)}registerCanActivate(e,t,r){this.#N("activate",e,t,this.#A,this.#$,"canActivate",r)}registerCanDeactivate(e,t,r){this.#N("deactivate",e,t,this.#E,this.#O,"canDeactivate",r)}clearCanActivate(e){this.#A.delete(e),this.#$.delete(e)}clearCanDeactivate(e){this.#E.delete(e),this.#O.delete(e)}clearAll(){this.#A.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.#A)t[e]=r;return[e,t]}getFunctions(){return[this.#O,this.#$]}checkActivateGuardSync(e,t,r){return this.#D(this.#$,e,t,r,"checkActivateGuardSync")}checkDeactivateGuardSync(e,t,r){return this.#D(this.#O,e,t,r,"checkDeactivateGuardSync")}#N(t,r,n,i,a,o,s){s?e.logger.warn(`router.${o}`,`Overwriting existing ${t} handler for route "${r}"`):this.#b(i.size+1,o);const c=u(n)?function(e){const t=()=>e;return()=>t}(n):n;i.set(r,c),this.#P.add(r);try{const e=c(this.#y,this.#p.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${o}] Factory must return a function, got ${p(e)}`);a.set(r,e)}catch(e){throw i.delete(r),e}finally{this.#P.delete(r)}}#D(t,r,n,i,a){const o=t.get(r);if(!o)return!0;try{const t=o(n,i);return"boolean"==typeof t?t:!l(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 n=this.#t.maxLifecycleHandlers;if(0===n)return;const{warn:i,error:a}=D(n);t>=a?e.logger.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at ${n}.`):t>=i&&e.logger.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}};function X(e,t){const r=e.path,n=r.startsWith("~"),i=n?r.slice(1):r,a={name:e.name,path:i,absolute:n,children:[],parent:t,nonAbsoluteChildren:[],fullName:""};if(e.children)for(const t of e.children){const e=X(t,a);a.children.push(e)}return a}function ee(e,t){const r=t.split(".");if(1===r.length)return{parent:e,finalName:t};let n=e;for(let e=0;e<r.length-1;e++){const i=r[e],a=n.children.find(e=>e.name===i);if(!a)throw new Error(`[buildTree] Parent segment "${i}" not found in "${t}"`);n=a}const i=r.at(-1);if(!i)throw new Error(`[buildTree] Empty route name segments in "${t}"`);return{parent:n,finalName:i}}function te(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var re=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,ne=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,ie=/\?(.+)$/,ae=/[^\w!$'()*+,.:;|~-]/gu,oe=/[^\w!$'()*+,.:;|~-]/u,se={default:e=>oe.test(e)?e.replaceAll(ae,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},ce={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function de(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function ue(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function le(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 he(e){const t=[];for(const r of Object.keys(e)){const n=e[r],i=encodeURIComponent(r);t.push(""===n?i:`${i}=${encodeURIComponent(String(n))}`)}return t.join("&")}function fe(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function pe(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,n=e.codePointAt(t+2)??0;if(!fe(r)||!fe(n))return!1;t+=3}else t++;return!0}var ge=/<[^>]*>/g;function me(e,t,r,n,i){const a=""===t.fullName;a||n.push(t);const o=t.absolute,s=t.paramMeta.pathPattern,c=o&&s.startsWith("~")?s.slice(1):s,d=(o?c:s).replaceAll(ge,""),u=o?d:(h=d,""===(l=r)?h:""===h?l:l+h);var l,h;let f=i;a||(f=function(e,t,r,n,i,a){const o=(m=n,ue(r)===ue(m)),s=Object.freeze([...i]),c=function(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return Object.freeze(t)}(s),d=ue(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,i),l=function(e){const t=new Map;for(const r of e)for(const[e,n]of r.paramMeta.constraintPatterns)t.set(e,n);return t}(i),h=o?ue(n):d,{buildStaticParts:f,buildParamSlots:p}=function(e,t,r){const n=new Set,i=new Set;for(const e of t){for(const t of e.paramMeta.urlParams)n.add(t);for(const t of e.paramMeta.spatParams)i.add(t)}if(0===n.size)return{buildStaticParts:[e],buildParamSlots:[]};const a=[],o=[],s=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,d=0;for(;null!==(c=s.exec(e));){const t=c[1],n="?"===c[2];a.push(e.slice(d,c.index));const s=i.has(t);o.push({paramName:t,isOptional:n,encoder:s?e=>{const t=se[r],n=e.split("/");let i=t(n[0]);for(let e=1;e<n.length;e++)i+=`/${t(n[e])}`;return i}:se[r]}),d=c.index+c[0].length}return a.push(e.slice(d)),{buildStaticParts:a,buildParamSlots:o}}(h,o?i.slice(0,-1):i,e.options.urlParamsEncoding),g={name:t.fullName,parent:a,depth:i.length-1,matchSegments:s,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 m;return e.routesByName.set(t.fullName,g),e.segmentsByName.set(t.fullName,s),e.metaByName.set(t.fullName,c),o?function(e,t,r){var n,i;n=t,(function(e,t,r){const n=ue(r);if("/"===n||""===n)return t;let i=t,a=1;const o=n.length;for(;a<=o;){const t=n.indexOf("/",a),r=-1===t?o:t;if(r<=a)break;i=we(e,i,n.slice(a,r)),a=r+1}return i}(i=e,i.root,r)).slashChildRoute=n;const a=ue(r),o=e.options.caseSensitive?a:a.toLowerCase();e.staticCache.has(o)&&e.staticCache.set(o,t)}(e,g,n):function(e,t,r,n,i){if(function(e,t,r){const n=ue(r);"/"!==n?ve(e,e.root,n,1,t):e.root.route=t}(e,t,r),0===i.paramMeta.urlParams.length){const r=e.options.caseSensitive?n:n.toLowerCase();e.staticCache.set(r,t)}}(e,g,r,d,t),g}(e,t,u,o?"":r,n,i));for(const r of t.children.values())me(e,r,u,n,f);a||n.pop()}function ve(e,t,r,n,i){const a=r.length;for(;n<=a;){const o=r.indexOf("/",n),s=-1===o?a:o,c=r.slice(n,s);if(c.endsWith("?")){const n=c.slice(1).replaceAll(ge,"").replace(/\?$/,"");return t.paramChild??={node:de(),name:n},ve(e,t.paramChild.node,r,s+1,i),void(s>=a?t.route??=i:ve(e,t,r,s+1,i))}t=we(e,t,c),n=s+1}t.route=i}function we(e,t,r){if(r.startsWith("*")){const e=r.slice(1);return t.splatChild??={node:de(),name:e},t.splatChild.node}if(r.startsWith(":")){const e=r.slice(1).replaceAll(ge,"").replace(/\?$/,"");return t.paramChild??={node:de(),name:e},t.paramChild.node}const n=e.options.caseSensitive?r:r.toLowerCase();return n in t.staticChildren||(t.staticChildren[n]=de()),t.staticChildren[n]}var ye=/[\u0080-\uFFFF]/,be=class{get options(){return this.#C}#C;#j=de();#M=new Map;#k=new Map;#F=new Map;#I=new Map;#L="";#x=[];constructor(e){this.#C={caseSensitive:e?.caseSensitive??!0,strictTrailingSlash:e?.strictTrailingSlash??!1,strictQueryParams:e?.strictQueryParams??!1,urlParamsEncoding:e?.urlParamsEncoding??"default",parseQueryString:e?.parseQueryString??le,buildQueryString:e?.buildQueryString??he}}registerTree(e){this.#x=e.paramMeta.queryParams,me({root:this.#j,options:this.#C,routesByName:this.#M,segmentsByName:this.#k,metaByName:this.#F,staticCache:this.#I,rootQueryParams:this.#x},e,"",[],null)}match(e){const t=this.#_(e);if(!t)return;const[r,n,i]=t,a=this.#C.caseSensitive?n:n.toLowerCase(),o=this.#I.get(a);if(o){if(this.#C.strictTrailingSlash&&!this.#U(r,o))return;return this.#V(o,{},i)}const s={},c=this.#z(n,s);return!c||this.#C.strictTrailingSlash&&!this.#U(r,c)||c.hasConstraints&&!this.#G(s,c)||!this.#q(s)?void 0:this.#V(c,s,i)}buildPath(e,t,r){const n=this.#M.get(e);if(!n)throw new Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);n.hasConstraints&&t&&this.#W(n,e,t);const i=this.#B(n,t),a=this.#H(i,r?.trailingSlash),o=this.#Q(n,t,r?.queryParamsMode);return a+(o?`?${o}`:"")}getSegmentsByName(e){return this.#k.get(e)}getMetaByName(e){return this.#F.get(e)}hasRoute(e){return this.#M.has(e)}setRootPath(e){this.#L=e}#W(e,t,r){for(const[n,i]of e.constraintPatterns){const e=r[n];if(null!=e){const r="object"==typeof e?JSON.stringify(e):String(e);if(!i.pattern.test(r))throw new Error(`[SegmentMatcher.buildPath] '${t}' — param '${n}' value '${r}' does not match constraint '${i.constraint}'`)}}}#B(e,t){const r=e.buildStaticParts,n=e.buildParamSlots;if(0===n.length)return this.#L+r[0];let i=this.#L+r[0];for(const[e,a]of n.entries()){const n=t?.[a.paramName];if(null==n){if(!a.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${a.paramName}'`);i.length>1&&i.endsWith("/")&&(i=i.slice(0,-1)),i+=r[e+1];continue}const o="object"==typeof n?JSON.stringify(n):String(n);i+=a.encoder(o)+r[e+1]}return i}#H(e,t){return"always"!==t||e.endsWith("/")?"never"===t&&"/"!==e&&e.endsWith("/")?e.slice(0,-1):e:`${e}/`}#Q(e,t,r){if(!t)return"";const n=[...e.declaredQueryParams];if("loose"===r){const r=new Set(e.buildParamSlots.map(e=>e.paramName));for(const i in t)!Object.hasOwn(t,i)||e.declaredQueryParamsSet.has(i)||r.has(i)||n.push(i)}const i={};for(const e of n)e in t&&(i[e]=t[e]);return 0===Object.keys(i).length?"":this.#C.buildQueryString(i)}#_(e){if(""===e&&(e="/"),!e.startsWith("/"))return;const t=e.indexOf("#");if(-1!==t&&(e=e.slice(0,t)),ye.test(e))return;if(this.#L.length>0){if(!e.startsWith(this.#L))return;e=e.slice(this.#L.length)||"/"}const r=e.indexOf("?"),n=-1===r?e:e.slice(0,r),i=-1===r?void 0:e.slice(r+1);return n.includes("//")?void 0:[n,ue(n),i]}#V(e,t,r){if(void 0!==r){const n=this.#C.parseQueryString(r);if(this.#C.strictQueryParams){const t=e.declaredQueryParamsSet;for(const e of Object.keys(n))if(!t.has(e))return}for(const e of Object.keys(n))t[e]=n[e]}return{segments:e.matchSegments,params:t,meta:e.meta}}#U(e,t){return(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#z(e,t){return 1===e.length?this.#j.slashChildRoute??this.#j.route:this.#K(this.#j,e,1,t)}#K(e,t,r,n){let i=e;const a=t.length;for(;r<=a;){const e=t.indexOf("/",r),o=-1===e?a:e,s=t.slice(r,o),c=this.#C.caseSensitive?s:s.toLowerCase();let d;if(c in i.staticChildren)d=i.staticChildren[c];else{if(!i.paramChild){if(i.splatChild){const e={},a=this.#K(i.splatChild.node,t,r,e);return a?(Object.assign(n,e),a):(n[i.splatChild.name]=t.slice(r),i.splatChild.node.route)}return}d=i.paramChild.node,n[i.paramChild.name]=s}i=d,r=o+1}return i.slashChildRoute??i.route}#q(e){const t=this.#C.urlParamsEncoding;if("none"===t)return!0;const r=ce[t];for(const t in e){const n=e[t];if(n.includes("%")){if(!pe(n))return!1;e[t]=r(n)}}return!0}#G(e,t){for(const[r,n]of t.constraintPatterns)if(!n.pattern.test(e[r]))return!1;return!0}};function Se(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function Te(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}function Re(e,t,r){const n=function(e){const t=[],r=[],n=[],i={},a=new Map,o=e.replaceAll(ne,"$1"),s=ie.exec(o);if(null!==s){const t=s[1].split("&");for(const e of t){const t=e.trim();t.length>0&&(r.push(t),i[t]="query")}e=e.slice(0,s.index)}let c;for(;null!==(c=re.exec(e));){const e=c[2],r=c[3];if("*"===c[1])n.push(e),t.push(e),i[e]="url";else if(t.push(e),i[e]="url",r){const t=`^${te(r)}$`;a.set(e,{pattern:new RegExp(t),constraint:r})}}return{urlParams:t,queryParams:r,spatParams:n,paramTypeMap:i,constraintPatterns:a,pathPattern:e}}(e.path),i=function(e){const t={};for(const r of e.urlParams)t[r]="url";for(const r of e.queryParams)t[r]="query";return t}(n),a={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:void 0,paramMeta:n,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:i};a.fullName=function(e){return e.parent?.name?`${e.parent.fullName}.${e.name}`:e.name}(a);const{childrenMap:o,nonAbsoluteChildren:s}=function(e,t,r){const n=[],i=[];for(const a of e){const e=Re(a,t,r);n.push(e),e.absolute||i.push(e)}return{childrenMap:Te(n),nonAbsoluteChildren:i}}(e.children,a,r);return a.children=o,a.nonAbsoluteChildren=s,a.staticPath=function(e){if(!e.path)return null;const{urlParams:t,queryParams:r,spatParams:n}=e.paramMeta;if(t.length>0||r.length>0||n.length>0)return null;const i=[];let a=e.parent;for(;a?.path;)i.unshift(a),a=a.parent;let o="";for(const e of i){const{urlParams:t,queryParams:r,spatParams:n}=e.paramMeta;if(t.length>0||r.length>0||n.length>0)return null;o=e.absolute?e.path:Se(o,e.path)}return e.absolute?e.path:Se(o,e.path)}(a),r&&(Object.freeze(s),Object.freeze(i),Object.freeze(a.children),Object.freeze(a)),a}function Ee(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build(n){const i=function(e,t,r){const n=X({name:e,path:t},null),i=[];for(const e of r)if(e.name.includes("."))i.push(e);else if(e.children&&e.children.length>0){const t=X(e,n);n.children.push(t)}else i.push(e);for(const e of i){const{parent:t,finalName:r}=ee(n,e.name),i=X({name:r,path:e.path,children:e.children},t);t.children.push(i)}return n}(e,t,r);return function(e,t=!0){return Re(e,null,t)}(i,!n?.skipFreeze)}}}function Ae(e,t,r,n){return Ee(e,t).addMany(r).build(n)}function Oe(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=>Oe(e))),t}var $e=e=>{const t=e.indexOf("%"),r=e.indexOf("+");if(-1===t&&-1===r)return e;const n=-1===r?e:e.split("+").join(" ");return-1===t?n:decodeURIComponent(n)},Pe=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)},Ne={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${Pe(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${Pe(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${Pe(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>Pe(e)).join(",")}`}},De={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}},Ce={default:{encode:e=>e},hidden:{encode:()=>""}},je=(e,t,r)=>({boolean:De[t],null:Ce[r],array:Ne[e]}),Me={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:De.none,null:Ce.default,array:Ne.none}},ke=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return Me;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:je(t,r,n)}},Fe=e=>encodeURIComponent(e),Ie=(e,t,r)=>{const n=Fe(e);switch(typeof t){case"string":case"number":default:return`${n}=${Fe(t)}`;case"boolean":return r.strategies.boolean.encode(n,t);case"object":return null===t?r.strategies.null.encode(n):Array.isArray(t)?r.strategies.array.encodeArray(n,t):`${n}=${Fe(t)}`}};function Le(e,t,r,n,i){const a=e.indexOf("=",t),o=-1!==a&&a<r,s=e.slice(t,o?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}}(s);!function(e,t,r,n){const i=e[t];void 0===i?e[t]=n?[r]:r:Array.isArray(i)?i.push(r):e[t]=[i,r]}(n,$e(c),function(e,t,r,n,i){return i?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const n=$e(e);return t.boolean.decodeValue(n)})(n?e.slice(t+1,r):void 0,i):n?$e(e.slice(t+1,r)):null}(e,a,r,o,i),d)}function xe(e){const t=e?.queryParams;return new be({...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 n=e.length;for(;r<n;){let i=e.indexOf("&",r);-1===i&&(i=n),Le(e,r,i,t),r=i+1}}(e,t),t}(r);const n=ke(t),i={};let a=0;const o=r.length;for(;a<o;){let e=r.indexOf("&",a);-1===e&&(e=o),Le(r,a,e,i,n.strategies),a=e+1}return i})(e,t),buildQueryString:e=>((e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=ke(t),i=[];for(const t of r){const r=e[t];if(void 0===r)continue;const a=Ie(t,r,n);a&&i.push(a)}return i.join("&")})(e,t)})}function _e(e,t){return new TypeError(`[router.${e}] ${t}`)}var Ue=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/,Ve=/\S/;function ze(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function Ge(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 qe(e,t,r,n="",i,a){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${ze(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${ze(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 o=e;!function(e,t){if("string"!=typeof e.name)throw new TypeError(`[router.${t}] Route name must be a string, got ${ze(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!Ve.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("@@")&&!Ue.test(r))throw new TypeError(`[router.${t}] Invalid route name "${r}". 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").`)}(o,t),function(e,t,r,n){if("string"!=typeof e){let t;throw t=null===e?"null":Array.isArray(e)?"array":typeof e,_e(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw _e(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw _e(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw _e(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const i=n&&Object.values(n.paramTypeMap).includes("url");if(e.startsWith("~")&&i)throw _e(r,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}(o.path,o.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`)}(o,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`)}(o,t);const s=o.name,c=n?`${n}.${s}`:s;!n&&c.includes(".")&&function(e,t,r,n){const i=t.split(".");i.pop();const a=i.join(".");if(!n?.has(a)){if(!e)throw new Error(`[router.${r}] Parent route "${a}" does not exist for route "${t}"`);if(!Ge(e,a))throw new Error(`[router.${r}] Parent route "${a}" does not exist for route "${t}"`)}}(r,c,t,i),r&&c&&function(e,t,r){if(Ge(e,t))throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),i&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(i,c,t);const d=o.path;let u=n;if(s.includes(".")&&!n){const e=s.split(".");e.pop(),u=e.join(".")}if(r&&function(e,t,r,n){const i=""===t?e:Ge(e,t);if(i)for(const e of i.children.values())if(e.path===r)throw new Error(`[router.${n}] Path "${r}" is already defined`)}(r,u,d,t),a&&function(e,t,r,n){const i=e.get(t);if(i?.has(r))throw new Error(`[router.${n}] Path "${r}" is already defined`);i?i.add(r):e.set(t,new Set([r]))}(a,u,d,t),void 0!==o.children){if(!Array.isArray(o.children))throw new TypeError(`[router.${t}] Route "${s}" children must be an array, got ${ze(o.children)}`);for(const e of o.children)qe(e,t,r,c,i,a)}}var We=new Set;function Be(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>Be(e))),t}function He(e,t,r=""){for(let n=0;n<e.length;n++){const i=e[n],a=r?`${r}.${i.name}`:i.name;if(a===t)return e.splice(n,1),!0;if(i.children&&t.startsWith(`${a}.`)&&He(i.children,t,a))return!0}return!1}function Qe(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function Ke(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 ${p(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 ${p(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 ${p(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){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError(`[router.addRoute] forwardTo must be a string or function for route "${t}", got ${p(e)}`);if("function"==typeof e){const r="AsyncFunction"===e.constructor.name,n=e.toString().includes("__awaiter");if(r||n)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)Ke(r,`${t}.${r.name}`)}function Je(e){const t=new Set,r=/[*:]([A-Z_a-z]\w*)/g;let n;for(;null!==(n=r.exec(e));)t.add(n[1]);return t}function Ze(e){const t=new Set;for(const r of e)for(const e of Je(r))t.add(e);return t}function Ye(e,t,r="",n=[]){for(const i of e){const e=r?`${r}.${i.name}`:i.name,a=[...n,i.path];if(e===t)return a;if(i.children&&t.startsWith(`${e}.`))return Ye(i.children,t,e,a)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function Xe(e,t=""){const r=new Set;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(r.add(e),n.children)for(const t of Xe(n.children,e))r.add(t)}return r}function et(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&"string"==typeof n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,i]of et(n.children,e))r.set(t,i)}return r}function tt(e,t,r,n){if(t){const t=function(e,t){const r=[],n=t.includes(".")?t.split("."):[t];""!==e.path&&r.push(e);let i=e;for(const e of n){const t=i.children.get(e);if(!t)return null;r.push(t),i=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 Ze(Ye(n,e))}function rt(e,t,r,n,i){const a=function(e,t){const r=t.split(".");let n=e;for(const e of r)if(n=n.children.get(e),!n)return!1;return!0}(i,t),o=n.has(t);if(!a&&!o)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const s=Ze(Ye(r,e)),c=[...tt(t,a,i,r)].filter(e=>!s.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 nt(e,t,r=100){const n=new Set,i=[e];let a=e;for(;t[a];){const e=t[a];if(n.has(e)){const t=i.indexOf(e),r=[...i.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(a),i.push(e),a=e,i.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${i.join(" → ")}`)}return a}function it(e,t,r){const n=Xe(e),i=et(e),a={...t};for(const[e,t]of i)a[e]=t;for(const[t,a]of i)rt(t,a,e,n,r);for(const e of Object.keys(a))nt(e,a)}function at(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}function ot(e,t){if("AsyncFunction"===e.constructor.name||e.toString().includes("__awaiter"))throw new TypeError(`[real-router] updateRoute: ${t} cannot be an async function`)}function st(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}`);ot(e,t)}}var ct=".";function dt(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function ut(e,t){const r=t.meta?.params[e];if(!r||"object"!=typeof r)return{};const n={};for(const e in r){if(!Object.hasOwn(r,e))continue;if(void 0===r[e])continue;const i=t.params[e];null!=i&&("string"!=typeof i&&"number"!=typeof i&&"boolean"!=typeof i||(n[e]=String(i)))}return n}function lt(e){if(!e)return[""];const t=e.indexOf(ct);if(-1===t)return[e];const r=e.indexOf(ct,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(ct,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(ct,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(ct),r=t.length,n=[t[0]];let i=t[0].length;for(let a=1;a<r-1;a++)i+=1+t[a].length,n.push(e.slice(0,i));return n.push(e),n}(e)}function ht(e,t){if(!t)return{intersection:"",toActivate:lt(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:lt(e.name),toDeactivate:dt(lt(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:lt(e.name),toDeactivate:dt(lt(t.name))};if(e.name===t.name&&r&&n){const r=e.meta&&0===Object.keys(e.meta.params).length,n=t.meta&&0===Object.keys(t.meta.params).length;if(r&&n)return{intersection:e.name,toActivate:[],toDeactivate:[]}}const i=lt(e.name),a=lt(t.name),o=function(e,t,r,n,i){for(let a=0;a<i;a++){const i=r[a],o=n[a];if(i!==o)return a;const s=ut(i,e),c=ut(o,t),d=Object.keys(s),u=Object.keys(c);if(d.length!==u.length)return a;for(const e of d)if(s[e]!==c[e])return a}return i}(e,t,i,a,Math.min(a.length,i.length)),s=[];for(let e=a.length-1;e>=o;e--)s.push(a[e]);const c=i.slice(o);return{intersection:o>0?a[o-1]:"",toDeactivate:s,toActivate:c}}var ft=Object.freeze({}),pt=class{#J=[];#Z=function(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}();#Y=Object.create(null);#X=new Map;#ee=new Map;#te="";#re;#ne;#ie;#h;#ae;#oe;get#p(){if(!this.#h)throw new Error("[real-router] RoutesNamespace: dependencies not initialized");return this.#h}constructor(e=[],t=!1,r){this.#oe=t,this.#ie=r;for(const t of e)this.#J.push(Be(t));this.#re=Ae("",this.#te,this.#J),this.#ne=xe(r),this.#ne.registerTree(this.#re),this.#se(e),t?this.#ce():this.#de()}static validateRemoveRouteArgs(e){!function(e){f(e,"removeRoute")}(e)}static validateSetRootPathArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${p(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 ${p(t)}`);Ke(t,t.name)}}(e)}static validateIsActiveRouteArgs(e,t,r,n){!function(e,t,r,n){if(!d(e))throw new TypeError("Route name must be a string");if(void 0!==t&&!s(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!==n&&"boolean"!=typeof n)throw new TypeError("[router.isActiveRoute] ignoreQueryParams must be a boolean, got "+typeof n)}(e,t,r,n)}static validateStateBuilderArgs(e,t,r){!function(e,t,r){if(!d(e))throw new TypeError(`[router.${r}] Invalid routeName: ${p(e)}. Expected string.`);if(!s(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${p(t)}. Expected plain object.`)}(e,t,r)}static validateUpdateRouteBasicArgs(e,t){!function(e,t){if(f(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 ${p(t)}`)}(e,t)}static validateUpdateRoutePropertyTypes(e,t,r,n){!function(e,t,r,n){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 ${p(e)}`);"function"==typeof e&&ot(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 ${p(t)}`);st(r,"decodeParams"),st(n,"encodeParams")}(e,t,r,n)}static validateBuildPathArgs(e){!function(e){if(!d(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(!d(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e)}static validateShouldUpdateNodeArgs(e){!function(e){if(!d(e))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof e)}(e)}static validateRoutes(e,t,r){!function(e,t,r){const n=new Set,i=new Map;for(const r of e)qe(r,"addRoute",t,"",n,i);t&&r&&it(e,r,t)}(e,t,r)}setDependencies(e){this.#h=e;for(const[t,r]of this.#X)e.addActivateGuard(t,r);this.#X.clear();for(const[t,r]of this.#ee)e.addDeactivateGuard(t,r);this.#ee.clear()}setLifecycleNamespace(e){this.#ae=e}getRootPath(){return this.#te}getTree(){return this.#re}getForwardRecord(){return this.#Z.forwardMap}setRootPath(e){this.#te=e,this.#ue()}hasRoute(e){return this.#ne.hasRoute(e)}getRoute(e){const t=this.#ne.getSegmentsByName(e);if(!t)return;const r=Oe(this.#le(t));return this.#he(r,e)}addRoutes(e){for(const t of e)this.#J.push(Be(t));this.#se(e),this.#ue(),this.#fe()}removeRoute(e){return!!He(this.#J,e)&&(this.#pe(e),this.#ue(),this.#fe(),!0)}updateRouteConfig(e,t){if(void 0!==t.forwardTo&&this.#ge(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.#J.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.#Y)delete this.#Y[e];this.#ue()}buildPath(e,t,r){if(e===v.UNKNOWN_ROUTE)return d(t?.path)?t.path:"";const n=Object.hasOwn(this.#Z.defaultParams,e)?{...this.#Z.defaultParams[e],...t}:t??{},i="function"==typeof this.#Z.encoders[e]?this.#Z.encoders[e]({...n}):n,a=r?.trailingSlash;return this.#ne.buildPath(e,i,{trailingSlash:"never"===a||"always"===a?a:void 0,queryParamsMode:r?.queryParamsMode})}matchPath(e,t,r){const n=r,i=this.#ne.match(e);if(!i)return;const a=at(i),{name:o,params:s,meta:c}=a,d="function"==typeof this.#Z.decoders[o]?this.#Z.decoders[o](s):s,{name:u,params:l}=this.#p.forwardState(o,d);let h=e;if(n.rewritePathOnMatch){const e="function"==typeof this.#Z.encoders[u]?this.#Z.encoders[u]({...l}):l,t=n.trailingSlash;h=this.#ne.buildPath(u,e,{trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:n.queryParamsMode})}return this.#p.makeState(u,l,h,{params:c,options:ft,source:t,redirected:!1})}forwardState(e,t){if(Object.hasOwn(this.#Z.forwardFnMap,e)){const r=this.#me(e,t),n=this.#Z.forwardFnMap[e],i=this.#ve(e,n,t);return{name:i,params:this.#me(i,r)}}const r=this.#Y[e]??e;if(r!==e&&Object.hasOwn(this.#Z.forwardFnMap,r)){const n=this.#me(e,t),i=this.#Z.forwardFnMap[r],a=this.#ve(r,i,t);return{name:a,params:this.#me(a,n)}}if(r!==e){const n=this.#me(e,t);return{name:r,params:this.#me(r,n)}}return{name:e,params:this.#me(e,t)}}buildStateResolved(e,t){const r=this.#ne.getSegmentsByName(e);if(r)return at({segments:r,params:t,meta:this.#ne.getMetaByName(e)??{}},e)}buildStateWithSegmentsResolved(e,t){const r=this.#ne.getSegmentsByName(e);if(r)return{state:at({segments:r,params:t,meta:this.#ne.getMetaByName(e)??{}},e),segments:r}}isActiveRoute(e,t={},r=!1,n=!0){We.has(e)||(f(e,"isActiveRoute"),We.add(e));const i=this.#p.getState();if(!i)return!1;const a=i.name;if(a!==e&&!a.startsWith(`${e}.`)&&!e.startsWith(`${a}.`))return!1;const o=this.#Z.defaultParams[e];if(r||a===e){const r=o?{...o,...t}:t;return this.#p.areStatesEqual({name:e,params:r,path:""},i,n)}const s=i.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(t,s)&&(!o||function(e,t,r){for(const n in e)if(!(n in r)&&e[n]!==t[n])return!1;return!0}(o,s,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:n,toActivate:i,toDeactivate:a}=ht(t,r);return e===n||!!i.includes(e)||a.includes(e)}}getConfig(){return this.#Z}getUrlParams(e){const t=this.#ne.getSegmentsByName(e);return t?this.#we(t):[]}getResolvedForwardMap(){return this.#Y}setResolvedForwardMap(e){Object.assign(this.#Y,e)}cloneRoutes(){return[...this.#re.children.values()].map(e=>Oe(e))}validateForwardToParamCompatibility(e,t){const r="validateForwardToParamCompatibility",n=this.#ye(e,r),i=this.#ye(t,r),a=this.#be(n),o=this.#we(i).filter(e=>!a.has(e));if(o.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${o.join(", ")}] that are not available in source route "${e}"`)}validateForwardToCycle(e,t){nt(e,{...this.#Z.forwardMap,[e]:t})}validateRemoveRoute(t,r,n){if(r){const n=r===t,i=r.startsWith(`${t}.`);if(n||i)return e.logger.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${n?"":` (current: "${r}")`}. Navigate away first.`),!1}return n&&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)}}#ge(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.#fe()}#me(e,t){return Object.hasOwn(this.#Z.defaultParams,e)?{...this.#Z.defaultParams[e],...t}:t}#ve(e,t,r){const n=new Set([e]);let i=t(this.#p.getDependency,r),a=0;if("string"!=typeof i)throw new TypeError("forwardTo callback must return a string, got "+typeof i);for(;a<100;){if(void 0===this.#ne.getSegmentsByName(i))throw new Error(`Route "${i}" does not exist`);if(n.has(i)){const e=[...n,i].join(" → ");throw new Error(`Circular forwardTo detected: ${e}`)}if(n.add(i),Object.hasOwn(this.#Z.forwardFnMap,i)){if(i=(0,this.#Z.forwardFnMap[i])(this.#p.getDependency,r),"string"!=typeof i)throw new TypeError("forwardTo callback must return a string, got "+typeof i);a++;continue}const e=this.#Z.forwardMap[i];if(void 0===e)return i;i=e,a++}throw new Error("forwardTo exceeds maximum depth of 100")}#ue(){this.#re=Ae("",this.#te,this.#J),this.#ne=xe(this.#ie),this.#ne.registerTree(this.#re)}#ye(e,t){const r=this.#ne.getSegmentsByName(e);if(!r)throw new ReferenceError(`[real-router] ${t}: route "${e}" does not exist`);return r}#le(e){const t=e.at(-1);if(!t)throw new Error("[real-router] Internal error: empty segments array");return t}#be(e){const t=new Set;for(const r of e)for(const e of r.paramMeta.urlParams)t.add(e);return t}#we(e){const t=[];for(const r of e)for(const e of r.paramMeta.urlParams)t.push(e);return t}#fe(){this.#oe?this.#ce():this.#de()}#de(){for(const e in this.#Y)delete this.#Y[e];for(const e of Object.keys(this.#Z.forwardMap))this.#Y[e]=nt(e,this.#Z.forwardMap)}#ce(){for(const e in this.#Y)delete this.#Y[e];for(const e of Object.keys(this.#Z.forwardMap)){let t=e;for(;this.#Z.forwardMap[t];)t=this.#Z.forwardMap[t];this.#Y[e]=t}}#pe(e){const t=t=>t===e||t.startsWith(`${e}.`);if(Qe(this.#Z.decoders,t),Qe(this.#Z.encoders,t),Qe(this.#Z.defaultParams,t),Qe(this.#Z.forwardMap,t),Qe(this.#Z.forwardFnMap,t),Qe(this.#Z.forwardMap,e=>t(this.#Z.forwardMap[e])),this.#ae){const[e,r]=this.#ae.getFactories();for(const e of Object.keys(r))t(e)&&this.#ae.clearCanActivate(e);for(const r of Object.keys(e))t(r)&&this.#ae.clearCanDeactivate(r)}}#se(e,t=""){for(const r of e){const e=t?`${t}.${r.name}`:r.name;this.#Se(r,e),r.children&&this.#se(r.children,e)}}#Se(e,t){e.canActivate&&(this.#h?this.#h.addActivateGuard(t,e.canActivate):this.#X.set(t,e.canActivate)),e.canDeactivate&&(this.#h?this.#h.addDeactivateGuard(t,e.canDeactivate):this.#ee.set(t,e.canDeactivate)),e.forwardTo&&this.#Te(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)}#Te(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,n=t.forwardTo.toString().includes("__awaiter");if(e||n)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}#he(e,t){const r={name:e.name,path:e.path},n=this.#Z.forwardFnMap[t],i=this.#Z.forwardMap[t];if(void 0!==n?r.forwardTo=n:void 0!==i&&(r.forwardTo=i),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]),this.#ae){const[e,n]=this.#ae.getFactories();t in n&&(r.canActivate=n[t]),t in e&&(r.canDeactivate=e[t])}return e.children&&(r.children=e.children.map(e=>this.#he(e,`${t}.${e.name}`))),r}},gt={log:0,warn:1,error:2},mt={all:0,"warn-error":1,"error-only":2,none:3},vt=new class{#Z={level:"all",callbackIgnoresLevel:!1};#Re=0;configure(e){if(void 0!==e.level){if(!(e.level in mt))throw new Error(`Invalid log level: "${e.level}". Valid levels are: ${Object.keys(mt).join(", ")}`);this.#Z.level=e.level,this.#Re=mt[e.level]}"callback"in e&&(this.#Z.callback=e.callback),void 0!==e.callbackIgnoresLevel&&(this.#Z.callbackIgnoresLevel=e.callbackIgnoresLevel)}getConfig(){return{level:this.#Z.level,callback:this.#Z.callback,callbackIgnoresLevel:this.#Z.callbackIgnoresLevel}}log(e,t,...r){this.#Ee("log",e,t,r)}warn(e,t,...r){this.#Ee("warn",e,t,r)}error(e,t,...r){this.#Ee("error",e,t,r)}#Ee(e,t,r,n){if("none"===this.#Z.level&&!this.#Z.callbackIgnoresLevel)return;const i=gt[e]<this.#Re;i||this.#Ae(e,t,r,n),this.#Oe(e,t,r,i,n)}#Ae(e,t,r,n){"undefined"!=typeof console&&"function"==typeof console[e]&&console[e](t?`[${t}] ${r}`:r,...n)}#Oe(e,t,r,n,i){if(this.#Z.callback&&(this.#Z.callbackIgnoresLevel||!n))try{this.#Z.callback(e,t,r,...i)}catch(e){"undefined"!=typeof console&&"function"==typeof console.error&&console.error("[Logger] Error in callback:",e)}}},wt=new Set(["code","segment","path","redirect"]),yt=new Set(Object.values(m)),bt=new Set(["code","segment","path","redirect"]),St=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),Tt=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:n,redirect:i,...a}={}){super(t??e),this.code=e,this.segment=r,this.path=n,this.redirect=i?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),n=new WeakSet;return function e(t){if(null===t||"object"!=typeof t)return;if(n.has(t))return;n.add(t),Object.freeze(t);const r=Array.isArray(t)?t:Object.values(t);for(const t of r)e(t)}(r),r}(i):void 0;for(const[e,t]of Object.entries(a)){if(bt.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);St.has(e)||(this[e]=t)}}setCode(e){this.code=e,yt.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(bt.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);St.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 Rt(e,t,r){if(e instanceof Tt){const r=((e,t)=>{if(t)return t.setCode(e),t})(t,e);if(r)throw r}throw new Tt(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,n]of Object.entries(e))wt.has(r)||(t[r]=n);return{...r,...t}}return r}(e,r))}var Et=(e,t)=>{const r=e.meta,n=t.meta,i=r?.params,a=n?.params,o=i&&a?{...i,...a}:i??a??{},s={id:1,options:{},redirected:!1,...n,...r,params:o};return{...e,meta:s}},At=async(e,t,r)=>{const n=r?{segment:r}:{};if(void 0===e)return t;if("boolean"==typeof e){if(e)return t;throw new Tt(m.TRANSITION_ERR,n)}if(c(e))return e;if(l(e))try{const n=await e;return await At(n,t,r)}catch(e){throw new Tt(m.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,n))}throw new Tt(m.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})},Ot=async(e,t,r,n,i,a)=>{let o=t;const s=n.filter(t=>e.has(t));if(0===s.length)return o;for(const t of s){if(a())throw new Tt(m.TRANSITION_CANCELLED);const n=e.get(t);try{const e=n(o,r),a=await At(e,o,t);if(a!==o&&c(a)){if(a.name!==o.name)throw new Tt(i,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:a.name,params:a.params,path:a.path}});(a.params!==o.params||a.path!==o.path)&&vt.error("core:transition","Warning: State mutated during transition",{from:o,to:a}),o=Et(a,o)}}catch(e){Rt(e,i,t)}}return o};var $t=class{isRouterStarted;#$e=!1;#h;#Pe;get#p(){if(!this.#h)throw new Error("[real-router] NavigationNamespace: dependencies not initialized");return this.#h}get#Ne(){if(!this.#Pe)throw new Error("[real-router] NavigationNamespace: transition dependencies not initialized");return this.#Pe}static validateNavigateArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${p(e)}`)}(e)}static validateNavigateToStateArgs(e,t,r,n){!function(e,t,r,n){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 ${p(r)}`);if("boolean"!=typeof n)throw new TypeError(`[router.navigateToState] Invalid emitSuccess: expected boolean, got ${p(n)}`)}(e,t,r,n)}static validateNavigateToDefaultArgs(e){!function(e){if(void 0!==e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${p(e)}. Expected NavigationOptions object.`)}(e)}static validateNavigationOptions(e,r){!function(e,r){if(!function(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const r=e;for(const e of t){const t=r[e];if(void 0!==t&&"boolean"!=typeof t)return!1}return!0}(e))throw new TypeError(`[router.${r}] Invalid options: ${p(e)}. Expected NavigationOptions object.`)}(e,r)}setDependencies(e){this.#h=e}setTransitionDependencies(e){this.#Pe=e}isNavigating(){return this.isRouterStarted()&&this.#$e}cancel(){this.#$e=!1}async navigateToState(t,r,n,i){const a=this.#p,o=this.#Ne;this.#$e&&e.logger.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use router.clone() to create isolated instance per request."),this.cancel(),this.#$e=!0,a.invokeEventListeners(E.TRANSITION_START,t,r);try{const e=await async function(e,t,r,n){const[i,a]=e.getLifecycleFunctions(),o=e.getMiddlewareFunctions(),s=t.name===v.UNKNOWN_ROUTE,d=()=>!e.isActive(),{toDeactivate:u,toActivate:l}=ht(t,r),h=!s&&l.length>0,f=o.length>0;let p=t;if(r&&!n.forceDeactivate&&u.length>0&&(p=await Ot(i,t,r,u,m.CANNOT_DEACTIVATE,d)),d())throw new Tt(m.TRANSITION_CANCELLED);if(h&&(p=await Ot(a,p,r,l,m.CANNOT_ACTIVATE,d)),d())throw new Tt(m.TRANSITION_CANCELLED);if(f&&(p=await(async(e,t,r,n)=>{let i=t;for(const t of e){if(n())throw new Tt(m.TRANSITION_CANCELLED);try{const e=t(i,r),n=await At(e,i);n!==i&&c(n)&&((n.name!==i.name||n.params!==i.params||n.path!==i.path)&&vt.error("core:middleware","Warning: State mutated during middleware execution",{from:i,to:n}),i=Et(n,i))}catch(e){Rt(e,m.TRANSITION_ERR)}}return i})(o,p,r,d)),d())throw new Tt(m.TRANSITION_CANCELLED);if(r){const n=lt(t.name),a=lt(r.name),o=new Set(n);for(const t of a)!o.has(t)&&i.has(t)&&e.clearCanDeactivate(t)}return p}(o,t,r,n);if(e.name===v.UNKNOWN_ROUTE||a.hasRoute(e.name))return a.setState(e),i&&a.invokeEventListeners(E.TRANSITION_SUCCESS,e,r,n),e;throw new Tt(m.ROUTE_NOT_FOUND,{routeName:e.name})}catch(e){throw e instanceof Tt?e.code===m.TRANSITION_CANCELLED?a.invokeEventListeners(E.TRANSITION_CANCEL,t,r):e.code===m.ROUTE_NOT_FOUND?a.invokeEventListeners(E.TRANSITION_ERROR,void 0,a.getState(),e):a.invokeEventListeners(E.TRANSITION_ERROR,t,r,e):a.invokeEventListeners(E.TRANSITION_ERROR,t,r,e),e}finally{this.#$e=!1}}navigate(t,r,n){const i=this.#p;if(!this.isRouterStarted()){const e=new Tt(m.ROUTER_NOT_STARTED);return Promise.reject(e)}let a;try{a=i.buildStateWithSegments(t,r)}catch(e){return Promise.reject(e)}if(!a){const e=new Tt(m.ROUTE_NOT_FOUND);return i.invokeEventListeners(E.TRANSITION_ERROR,void 0,i.getState(),e),Promise.reject(e)}const{state:o}=a,s=i.makeState(o.name,o.params,i.buildPath(o.name,o.params),{params:o.meta,options:n,redirected:n.redirected??!1}),c=i.getState();if(!n.reload&&!n.force&&i.areStatesEqual(c,s,!1)){const e=new Tt(m.SAME_STATES);i.invokeEventListeners(E.TRANSITION_ERROR,s,c,e);const t=Promise.reject(e);return t.catch(()=>{}),t}const d=this.navigateToState(s,c,n,!0);return d.catch(t=>{t instanceof Tt&&(t.code===m.SAME_STATES||t.code===m.TRANSITION_CANCELLED)||e.logger.error("router.navigate","Unexpected navigation error",t)}),d}navigateToDefault(e){const t=this.#p,r=t.getOptions();if(!r.defaultRoute)return Promise.reject(new Tt(m.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"}));const n=_(r.defaultRoute,t.getDependency);if(!n)return Promise.reject(new Tt(m.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"}));const i=_(r.defaultParams,t.getDependency);return this.navigate(n,i,e)}},Pt=new Tt(m.ROUTER_ALREADY_STARTED),Nt=class{navigateToState;#De=!1;#Ce=!1;#h;get#p(){if(!this.#h)throw new Error("[real-router] RouterLifecycleNamespace: dependencies not initialized");return this.#h}static validateStartArgs(e){if(1!==e.length||"string"!=typeof e[0])throw new Error("[router.start] Expected exactly 1 string argument (startPath).")}setDependencies(e){this.#h=e}isStarted(){return this.#De}isActive(){return this.#Ce}async start(e){const t=this.#p,r=t.getOptions();if(this.#De||this.#Ce)throw Pt;this.#Ce=!0;const n={replace:!0};try{const i=t.matchPath(e);let a;if(i)a=await this.navigateToState(i,void 0,n,!1);else{if(!r.allowNotFound){const r=new Tt(m.ROUTE_NOT_FOUND,{path:e});throw t.hasListeners(E.TRANSITION_ERROR)&&t.invokeEventListeners(E.TRANSITION_ERROR,void 0,void 0,r),r}{const r=t.makeNotFoundState(e,n);a=await this.navigateToState(r,void 0,n,!1)}}return this.#De=!0,t.invokeEventListeners(E.ROUTER_START),t.invokeEventListeners(E.TRANSITION_SUCCESS,a,void 0,{replace:!0}),a}catch(e){throw this.#Ce=!1,e}}stop(){const e=this.#p;this.#Ce=!1,this.#De&&(this.#De=!1,e.setState(),e.invokeEventListeners(E.ROUTER_STOP))}},Dt=class{#je;#Me;get#ke(){if(!this.#je)throw new Error("[real-router] CloneNamespace: getCloneData not initialized");return this.#je}get#Fe(){if(!this.#Me)throw new Error("[real-router] CloneNamespace: applyConfig not initialized");return this.#Me}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 ${p(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[router.clone] Getters not allowed in dependencies: "${t}"`)}}setCallbacks(e,t){this.#je=e,this.#Me=t}clone(e,t){const r=this.#ke(),n={...r.dependencies,...e},i=t(r.routes,r.options,n);for(const[e,t]of Object.entries(r.canDeactivateFactories))i.addDeactivateGuard(e,t);for(const[e,t]of Object.entries(r.canActivateFactories))i.addActivateGuard(e,t);return r.middlewareFactories.length>0&&i.useMiddleware(...r.middlewareFactories),r.pluginFactories.length>0&&i.usePlugin(...r.pluginFactories),this.#Fe(i,r.routeConfig,r.resolvedForwardMap),i}},Ct=new Set(["all","warn-error","error-only"]);var jt=class t{#c;#t;#e;#Ie;#Le;#xe;#_e;#Ue;#S;#Ve;#ze;#Ge;#oe;constructor(t=[],r={},n={}){r.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)||!Ct.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}(r.logger)&&(e.logger.configure(r.logger),delete r.logger),G.validateOptions(r,"constructor");const i=r.noValidate??!1;i||C.validateDependenciesObject(n,"constructor"),!i&&t.length>0&&(pt.validateAddRouteArgs(t),pt.validateRoutes(t)),this.#c=new G(r),this.#t=function(e={}){return{...A,...e}}(r.limits),this.#e=new C(n),this.#Ie=new k,this.#Le=new W,this.#xe=new pt(t,i,function(e){return{strictTrailingSlash:"strict"===e.trailingSlash,strictQueryParams:"strict"===e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding,queryParams:e.queryParams??{}}}(this.#c.get())),this.#_e=new Y,this.#Ue=new H,this.#S=new Z,this.#Ve=new $t,this.#ze=new Nt,this.#Ge=new Dt,this.#oe=i,this.#qe(),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.getOption=this.getOption.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.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.clearMiddleware=this.clearMiddleware.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){const t=Array.isArray(e)?e:[e];return this.#oe||(pt.validateAddRouteArgs(t),pt.validateRoutes(t,this.#xe.getTree(),this.#xe.getForwardRecord())),this.#xe.addRoutes(t),this}removeRoute(t){return this.#oe||pt.validateRemoveRouteArgs(t),this.#xe.validateRemoveRoute(t,this.#Le.get()?.name,this.#Ve.isNavigating())?(this.#xe.removeRoute(t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),this):this}clearRoutes(){return this.#xe.validateClearRoutes(this.#Ve.isNavigating())?(this.#xe.clearRoutes(),this.#_e.clearAll(),this.#Le.set(void 0),this):this}getRoute(e){return this.#oe||f(e,"getRoute"),this.#xe.getRoute(e)}hasRoute(e){return this.#oe||f(e,"hasRoute"),this.#xe.hasRoute(e)}updateRoute(t,r){this.#oe||pt.validateUpdateRouteBasicArgs(t,r);const{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:o,canActivate:s,canDeactivate:c}=r;return this.#oe||pt.validateUpdateRoutePropertyTypes(n,i,a,o),this.#Ve.isNavigating()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),this.#oe||this.#xe.validateUpdateRoute(t,n),this.#xe.updateRouteConfig(t,{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:o}),void 0!==s&&(null===s?this.#_e.clearCanActivate(t):this.addActivateGuard(t,s)),void 0!==c&&(null===c?this.#_e.clearCanDeactivate(t):this.addDeactivateGuard(t,c)),this}isActiveRoute(t,r,n,i){return this.#oe||pt.validateIsActiveRouteArgs(t,r,n,i),""===t?(e.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#xe.isActiveRoute(t,r,n,i)}buildPath(e,t){return this.#oe||pt.validateBuildPathArgs(e),this.#xe.buildPath(e,t,this.#c.get())}matchPath(e,t){return this.#oe||pt.validateMatchPathArgs(e),this.#xe.matchPath(e,t,this.#c.get())}setRootPath(e){this.#oe||pt.validateSetRootPathArgs(e),this.#xe.setRootPath(e)}getRootPath(){return this.#xe.getRootPath()}makeState(e,t,r,n,i){return this.#oe||W.validateMakeStateArgs(e,t,r,i),this.#Le.makeState(e,t,r,n,i)}getState(){return this.#Le.get()}getPreviousState(){return this.#Le.getPrevious()}areStatesEqual(e,t,r=!0){return this.#oe||W.validateAreStatesEqualArgs(e,t,r),this.#Le.areStatesEqual(e,t,r)}forwardState(e,t){return this.#oe||pt.validateStateBuilderArgs(e,t,"forwardState"),this.#xe.forwardState(e,t)}buildState(e,t){this.#oe||pt.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:n}=this.forwardState(e,t);return this.#xe.buildStateResolved(r,n)}buildNavigationState(e,t={}){this.#oe||pt.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.#oe||pt.validateShouldUpdateNodeArgs(e),this.#xe.shouldUpdateNode(e)}getOptions(){return this.#c.get()}getOption(e){return this.#oe||(G.validateOptionName(e,"getOption"),G.validateOptionExists(e,"getOption")),this.#c.getOption(e)}isActive(){return this.#ze.isActive()}start(e){return this.#oe||Nt.validateStartArgs([e]),this.#ze.start(e)}stop(){return this.#ze.stop(),this}addDeactivateGuard(e,t){this.#oe||(f(e,"addDeactivateGuard"),Y.validateHandler(t,"addDeactivateGuard"),Y.validateNotRegistering(this.#_e.isRegistering(e),e,"addDeactivateGuard"));const r=this.#_e.hasCanDeactivate(e);return r||this.#oe||Y.validateHandlerLimit(this.#_e.countCanDeactivate()+1,"addDeactivateGuard",this.#t.maxLifecycleHandlers),this.#_e.registerCanDeactivate(e,t,r),this}addActivateGuard(e,t){this.#oe||(f(e,"addActivateGuard"),Y.validateHandler(t,"addActivateGuard"),Y.validateNotRegistering(this.#_e.isRegistering(e),e,"addActivateGuard"));const r=this.#_e.hasCanActivate(e);return r||this.#oe||Y.validateHandlerLimit(this.#_e.countCanActivate()+1,"addActivateGuard",this.#t.maxLifecycleHandlers),this.#_e.registerCanActivate(e,t,r),this}removeActivateGuard(e){this.#oe||f(e,"removeActivateGuard"),this.#_e.clearCanActivate(e)}removeDeactivateGuard(e){this.#oe||f(e,"removeDeactivateGuard"),this.#_e.clearCanDeactivate(e)}canNavigateTo(e,t){if(this.#oe||f(e,"canNavigateTo"),!this.hasRoute(e))return!1;const{name:r,params:n}=this.forwardState(e,t??{}),i=this.makeState(r,n),a=this.getState(),{toDeactivate:o,toActivate:s}=ht(i,a);for(const e of o)if(!this.#_e.checkDeactivateGuardSync(e,i,a))return!1;for(const e of s)if(!this.#_e.checkActivateGuardSync(e,i,a))return!1;return!0}usePlugin(...e){return this.#oe||(Z.validateUsePluginArgs(e),Z.validatePluginLimit(this.#S.count(),e.length,this.#t.maxPlugins),Z.validateNoDuplicatePlugins(e,this.#S.has.bind(this.#S))),this.#S.use(...e)}useMiddleware(...e){this.#oe||(H.validateUseMiddlewareArgs(e),H.validateNoDuplicates(e,this.#Ue.getFactories()),H.validateMiddlewareLimit(this.#Ue.count(),e.length,this.#t.maxMiddleware));const t=this.#Ue.initialize(...e);if(!this.#oe)for(const{middleware:e,factory:r}of t)H.validateMiddleware(e,r);return this.#Ue.commit(t)}clearMiddleware(){return this.#Ue.clear(),this}setDependency(e,t){return this.#oe||C.validateSetDependencyArgs(e),this.#e.set(e,t),this}setDependencies(e){return this.#oe||(C.validateDependenciesObject(e,"setDependencies"),C.validateDependencyLimit(this.#e.count(),Object.keys(e).length,"setDependencies",this.#t.maxDependencies)),this.#e.setMultiple(e),this}getDependency(e){this.#oe||C.validateName(e,"getDependency");const t=this.#e.get(e);return this.#oe||C.validateDependencyExists(t,e),t}getDependencies(){return this.#e.getAll()}removeDependency(e){return this.#oe||C.validateName(e,"removeDependency"),this.#e.remove(e),this}hasDependency(e){return this.#oe||C.validateName(e,"hasDependency"),this.#e.has(e)}resetDependencies(){return this.#e.reset(),this}addEventListener(e,t){return this.#oe||k.validateListenerArgs(e,t),this.#Ie.addEventListener(e,t)}navigate(e,t,r){this.#oe||$t.validateNavigateArgs(e);const n=r??{};return this.#oe||$t.validateNavigationOptions(n,"navigate"),this.#Ve.navigate(e,t??{},n)}navigateToDefault(e){this.#oe||$t.validateNavigateToDefaultArgs(e);const t=e??{};return this.#oe||$t.validateNavigationOptions(t,"navigateToDefault"),this.#Ve.navigateToDefault(t)}navigateToState(e,t,r,n){return this.#oe||$t.validateNavigateToStateArgs(e,t,r,n),this.#Ve.navigateToState(e,t,r,n)}cancel(){this.#Ve.cancel()}subscribe(e){return this.#oe||k.validateSubscribeListener(e),this.#Ie.subscribe(e)}clone(e){return this.#oe||Dt.validateCloneArgs(e),this.#Ge.clone(e,(e,r,n)=>new t(e,r,n))}#qe(){this.#e.setLimits(this.#t),this.#S.setLimits(this.#t),this.#Ue.setLimits(this.#t),this.#Ie.setLimits(this.#t),this.#_e.setLimits(this.#t),this.#_e.setRouter(this),this.#_e.setDependencies({getDependency:e=>this.#e.get(e)}),this.#xe.setDependencies({addActivateGuard:(e,t)=>{this.addActivateGuard(e,t)},addDeactivateGuard:(e,t)=>{this.addDeactivateGuard(e,t)},makeState:(e,t,r,n)=>this.#Le.makeState(e,t,r,n),getState:()=>this.#Le.get(),areStatesEqual:(e,t,r)=>this.#Le.areStatesEqual(e,t,r),getDependency:e=>this.#e.get(e),forwardState:(e,t)=>this.forwardState(e,t)}),this.#xe.setLifecycleNamespace(this.#_e),this.#Ue.setRouter(this),this.#Ue.setDependencies({getDependency:e=>this.#e.get(e)}),this.#S.setRouter(this),this.#S.setDependencies({addEventListener:(e,t)=>this.#Ie.addEventListener(e,t),isStarted:()=>this.#ze.isStarted(),getDependency:e=>this.#e.get(e)}),this.#Ve.setDependencies({getOptions:()=>this.#c.get(),hasRoute:e=>this.#xe.hasRoute(e),getState:()=>this.#Le.get(),setState:e=>{this.#Le.set(e)},buildStateWithSegments:(e,t)=>{const{name:r,params:n}=this.forwardState(e,t);return this.#xe.buildStateWithSegmentsResolved(r,n)},makeState:(e,t,r,n)=>this.#Le.makeState(e,t,r,n),buildPath:(e,t)=>this.#xe.buildPath(e,t,this.#c.get()),areStatesEqual:(e,t,r)=>this.#Le.areStatesEqual(e,t,r),invokeEventListeners:(e,t,r,n)=>{this.#Ie.invoke(e,t,r,n)},getDependency:e=>this.#e.get(e)}),this.#Ve.setTransitionDependencies({getLifecycleFunctions:()=>this.#_e.getFunctions(),getMiddlewareFunctions:()=>this.#Ue.getFunctions(),isActive:()=>this.#ze.isActive(),clearCanDeactivate:e=>{this.#_e.clearCanDeactivate(e)}}),this.#ze.setDependencies({getOptions:()=>this.#c.get(),hasListeners:e=>this.#Ie.hasListeners(e),invokeEventListeners:(e,t,r,n)=>{this.#Ie.invoke(e,t,r,n)},makeNotFoundState:(e,t)=>this.#Le.makeNotFoundState(e,t),setState:e=>{this.#Le.set(e)},matchPath:(e,t)=>this.#xe.matchPath(e,t,this.#c.get())}),this.#Le.setDependencies({getDefaultParams:()=>this.#xe.getConfig().defaultParams,buildPath:(e,t)=>this.#xe.buildPath(e,t,this.#c.get()),getUrlParams:e=>this.#xe.getUrlParams(e)}),this.#Ve.isRouterStarted=()=>this.#ze.isStarted(),this.#ze.navigateToState=(e,t,r,n)=>this.#Ve.navigateToState(e,t,r,n),this.#Ge.setCallbacks(()=>{const[e,t]=this.#_e.getFactories();return{routes:this.#xe.cloneRoutes(),options:{...this.#c.get()},dependencies:this.#e.getAll(),canDeactivateFactories:e,canActivateFactories:t,middlewareFactories:this.#Ue.getFactories(),pluginFactories:this.#S.getAll(),routeConfig:this.#xe.getConfig(),resolvedForwardMap:this.#xe.getResolvedForwardMap()}},(e,t,r)=>{const n=e,i=n.#xe.getConfig();Object.assign(i.decoders,t.decoders),Object.assign(i.encoders,t.encoders),Object.assign(i.defaultParams,t.defaultParams),Object.assign(i.forwardMap,t.forwardMap),Object.assign(i.forwardFnMap,t.forwardFnMap),n.#xe.setResolvedForwardMap({...r})})}};exports.Router=jt,exports.RouterError=Tt,exports.constants=v,exports.createRouter=(e=[],t={},r={})=>new jt(e,t,r),exports.errorCodes=m,exports.events=E,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=["replace","reload","force","forceDeactivate","redirected"],r=/\S/,n=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function i(e,t){return new TypeError(`[router.${e}] ${t}`)}function a(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=>a(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=>a(e,t))}return!1}function o(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function s(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 n=e[t];if(!o(n)){const e=typeof n;if("function"===e||"symbol"===e)return!1;r=!0;break}}return!r||a(e)}function c(e){return"object"==typeof e&&null!==e&&("string"==typeof(r=(t=e).name)&&(""===r||!(r.length>1e4)&&(!!r.startsWith("@@")||n.test(r)))&&"string"==typeof t.path&&s(t.params));var t,r}function d(e){return"string"==typeof e}function u(e){return"boolean"==typeof e}function l(e){return"object"==typeof e&&null!==e&&"then"in e&&"function"==typeof e.then}function h(e,t){return e in t}function f(e,t){if("string"!=typeof e)throw i(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!r.test(e))throw i(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw i(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!n.test(e))throw i(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 p(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 g(e,t){if(!c(e))throw new TypeError(`[${t}] Invalid state structure: ${p(e)}. Expected State object with name, params, and path properties.`)}var m=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"}),v={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},w="onStart",y="onStop",b="onTransitionStart",S="onTransitionCancel",T="onTransitionSuccess",R="onTransitionError",E={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},A={maxDependencies:100,maxPlugins:50,maxMiddleware:50,maxListeners:1e4,maxEventDepth:5,maxLifecycleHandlers:200},$={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxMiddleware:{min:0,max:1e3},maxListeners:{min:0,max:1e5},maxEventDepth:{min:0,max:100},maxLifecycleHandlers:{min:0,max:1e4}},P=new WeakSet;function O(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)O(t);else for(const t in e)O(e[t])}function N(e){return e?(P.has(e)||(O(e),P.add(e)),e):e}function D(e){return{warn:Math.floor(.2*e),error:Math.floor(.5*e)}}var C=class{#e=Object.create(null);#t=A;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 ${p(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,n){!function(e,t,r,n=A.maxDependencies){if(0===n)return;const i=e+t;if(i>=n)throw new Error(`[router.${r}] Dependency limit exceeded (${n}). Current: ${i}. This is likely a bug in your code.`)}(e,t,r,n)}setLimits(e){this.#t=e}set(t,r){if(void 0===r)return!1;if(Object.hasOwn(this.#e,t)){const n=this.#e[t],i=n!==r,a=Number.isNaN(n)&&Number.isNaN(r);i&&!a&&e.logger.warn("router.setDependency","Router dependency already exists and is being overwritten:",t)}else this.#r("setDependency");return this.#e[t]=r,!0}setMultiple(t){const r=[];for(const e in t)void 0!==t[e]&&(Object.hasOwn(this.#e,e)&&r.push(e),this.#e[e]=t[e]);r.length>0&&e.logger.warn("router.setDependencies","Overwritten:",r.join(", "))}get(e){return this.#e[e]}getAll(){return{...this.#e}}count(){return Object.keys(this.#e).length}remove(t){Object.hasOwn(this.#e,t)||e.logger.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${p(t)}"`),delete this.#e[t]}has(e){return Object.hasOwn(this.#e,e)}reset(){for(const e in this.#e)delete this.#e[e]}#r(t){const r=this.#t.maxDependencies;if(0===r)return;const n=Object.keys(this.#e).length,{warn:i,error:a}=D(r);if(n===i)e.logger.warn(`router.${t}`,`${i} dependencies registered. Consider if all are necessary.`);else if(n===a)e.logger.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${r}.`);else if(n>=r)throw new Error(`[router.${t}] Dependency limit exceeded (${r}). Current: ${n}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}},j=new Set([E.ROUTER_START,E.TRANSITION_START,E.TRANSITION_SUCCESS,E.TRANSITION_ERROR,E.TRANSITION_CANCEL,E.ROUTER_STOP]);function M(t,r,...n){if(0===r.size)return;const i=[...r];for(const r of i)try{Function.prototype.apply.call(r,void 0,n)}catch(r){e.logger.error("Router",`Error in listener for ${t}:`,r)}}var k=class t{#n={};#i=null;#t=A;static validateEventName(e){if(!j.has(e))throw new Error(`Invalid event name: ${String(e)}`)}static validateCallback(e,t){if("function"!=typeof e)throw new TypeError(`Expected callback to be a function for event ${t}`)}static validateListenerArgs(e,r){t.validateEventName(e),t.validateCallback(r,e)}static validateSubscribeListener(e){if("function"!=typeof e)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}setLimits(e){this.#t=e}invoke(e,t,r,n){this.#a(e);const i=this.#o();try{switch(i[e]++,e){case E.TRANSITION_START:case E.TRANSITION_CANCEL:M(e,this.#s(e),t,r);break;case E.TRANSITION_ERROR:case E.TRANSITION_SUCCESS:M(e,this.#s(e),t,r,n);break;default:M(e,this.#s(e))}}finally{i[e]--}}hasListeners(e){const t=this.#n[e];return void 0!==t&&t.size>0}removeEventListener(t,r){const n=this.#n[t];n&&0!==n.size&&(n.delete(r)||e.logger.warn("Router",`Attempted to remove non-existent listener for "${t}". This might indicate a memory leak or incorrect cleanup logic.`))}addEventListener(t,r){const n=this.#s(t);if(n.has(r))throw new Error(`[router.addEventListener] Listener already exists for event "${t}". Each listener function can only be registered once per event. Store the returned unsubscribe function to remove the listener.`);const i=this.#t.maxListeners;if(1e3===n.size&&e.logger.warn("router.addEventListener",`Warning: Event "${t}" has ${n.size} listeners. This might indicate a memory leak.`),0!==i&&n.size>=i)throw new Error(`[router.addEventListener] Maximum listener limit (${i}) reached for event "${t}". This is a critical memory leak. The application is creating listeners exponentially. Check for loops or recursive calls that register listeners.`);return n.add(r),()=>{this.removeEventListener(t,r)}}subscribe(e){return this.addEventListener(E.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}#s(e){const t=this.#n[e];if(t)return t;const r=new Set;return this.#n[e]=r,r}#o(){return this.#i??={[E.ROUTER_START]:0,[E.TRANSITION_START]:0,[E.TRANSITION_SUCCESS]:0,[E.TRANSITION_ERROR]:0,[E.TRANSITION_CANCEL]:0,[E.ROUTER_STOP]:0},this.#i}#a(e){const t=this.#t.maxEventDepth;if(0!==t&&this.#o()[e]>=t)throw new Error(`[Router] Maximum recursion depth (${t}) exceeded for event: ${e}`)}},F={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},I={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},L={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function x(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&x(r)}return e}function _(e,t){return"function"==typeof e?e(t):e}function U(e,t,r){if("function"==typeof t&&("defaultRoute"===e||"defaultParams"===e))return;const n=F[e];if(n&&"object"==typeof n)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 ${p(e)}`);for(const n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw new TypeError(`[router.${r}] Getters not allowed in "${t}": "${n}"`)}(t,e,r),void("queryParams"===e&&function(e,t){for(const r in e){if(!h(r,L)){const e=Object.keys(L).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],i=L[r];if(!i.includes(n)){const e=i.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Invalid value for queryParams.${r}: expected one of ${e}, got "${String(n)}"`)}}}(t,r));if(typeof t!=typeof n)throw new TypeError(`[router.${r}] Invalid type for "${e}": expected ${typeof n}, got ${typeof t}`);e in I&&function(e,t,r){const n=I[e];if(!n.includes(t)){const i=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${i}, got "${String(t)}"`)}}(e,t,r)}function V(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,n]of Object.entries(e)){if(!Object.hasOwn($,r))throw new TypeError(`[router.${t}]: unknown limit: "${r}"`);void 0!==n&&z(r,n,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function z(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 n=$[e];if(t<n.min||t>n.max)throw new RangeError(`[router.${r}]: limit "${e}" must be between ${n.min} and ${n.max}, got ${t}`)}var G=class{#c;constructor(e={}){this.#c=x({...F,...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 ${p(e)}`);for(const[r,n]of Object.entries(e))h(r,F)?void 0!==n&&U(r,n,t):V(r,n,t)}(e,t)}get(){return this.#c}};function q(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>q(e,t[r]))}var W=class{#d=0;#u=void 0;#l=void 0;#h;#f=new Map;get#p(){if(!this.#h)throw new Error("[real-router] StateNamespace: dependencies not initialized");return this.#h}static validateMakeStateArgs(e,t,r,n){if(!d(e))throw new TypeError(`[router.makeState] Invalid name: ${p(e)}. Expected string.`);if(void 0!==t&&!s(t))throw new TypeError(`[router.makeState] Invalid params: ${p(t)}. Expected plain object.`);if(void 0!==r&&!d(r))throw new TypeError(`[router.makeState] Invalid path: ${p(r)}. Expected string.`);if(void 0!==n&&"number"!=typeof n)throw new TypeError(`[router.makeState] Invalid forceId: ${p(n)}. Expected number.`)}static validateAreStatesEqualArgs(e,t,r){if(null!=e&&g(e,"areStatesEqual"),null!=t&&g(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${p(r)}. Expected boolean.`)}get(){return this.#u}set(e){this.#l=this.#u,e?Object.isFrozen(e)?this.#u=e:this.#u=N(e):this.#u=void 0}getPrevious(){return this.#l}setDependencies(e){this.#h=e}makeState(e,t,r,n,i){const a=n?{...n,id:i??++this.#d,params:n.params,options:n.options,redirected:n.redirected}:void 0,o=this.#p.getDefaultParams();let s;return s=Object.hasOwn(o,e)?{...o[e],...t}:t?{...t}:{},N({name:e,params:s,path:r??this.#p.buildPath(e,t),meta:a})}makeNotFoundState(e,t){return this.makeState(v.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 n=e[r];for(const e in n)"url"===n[e]&&t.push(e)}return t}(r):this.#g(e.name)).every(r=>q(e.params[r],t.params[r]))}const n=Object.keys(e.params),i=Object.keys(t.params);return n.length===i.length&&n.every(r=>r in t.params&&q(e.params[r],t.params[r]))}#g(e){const t=this.#f.get(e);if(void 0!==t)return t;const r=this.#p.getUrlParams(e);return this.#f.set(e,r),r}};function B(e){return e.name||"anonymous"}var H=class{#m=new Set;#v=new Map;#w;#h;#t=A;get#y(){if(!this.#w)throw new Error("[real-router] MiddlewareNamespace: router not initialized");return this.#w}get#p(){if(!this.#h)throw new Error("[real-router] MiddlewareNamespace: dependencies not initialized");return this.#h}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 ${p(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 ${p(e)}. Factory: ${B(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: ${B(t)}`)}(e,t)}static validateMiddlewareLimit(e,t,r){!function(e,t,r=A.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.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#t=e}count(){return this.#m.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.#m.add(t),this.#v.set(t,r);let t=!1;return()=>{if(!t){t=!0;for(const{factory:t}of e)this.#m.delete(t),this.#v.delete(t)}}}getFactories(){return[...this.#m]}getFunctions(){return[...this.#v.values()]}#b(t){const r=this.#t.maxMiddleware;if(0===r)return;const n=t+this.#m.size,{warn:i,error:a}=D(r);n>=a?e.logger.error("router.useMiddleware",`${n} middleware registered! This is excessive and will impact performance. Hard limit at ${r}.`):n>=i&&e.logger.warn("router.useMiddleware",`${n} middleware registered. Consider if all are necessary.`)}},Q={[w]:E.ROUTER_START,[y]:E.ROUTER_STOP,[T]:E.TRANSITION_SUCCESS,[b]:E.TRANSITION_START,[R]:E.TRANSITION_ERROR,[S]:E.TRANSITION_CANCEL},K=Object.keys(Q).filter(e=>h(e,Q)),J="router.usePlugin",Z=class t{#S=new Set;#w;#h;#t=A;get#y(){if(!this.#w)throw new Error("[real-router] PluginsNamespace: router not initialized");return this.#w}get#p(){if(!this.#h)throw new Error("[real-router] PluginsNamespace: dependencies not initialized");return this.#h}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 ${p(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&&!h(t,Q))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=A.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.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#t=e}count(){return this.#S.size}use(...t){if(this.#b(t.length),1===t.length){const r=t[0],n=this.#T(r);this.#S.add(r);let i=!1;return()=>{if(!i){i=!0,this.#S.delete(r);try{n()}catch(t){e.logger.error(J,"Error during cleanup:",t)}}}}const r=this.#R(t),n=[];try{for(const e of r){const t=this.#T(e);n.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(J,"Cleanup error:",t)}throw t}for(const{factory:e}of n)this.#S.add(e);let i=!1;return()=>{if(!i){i=!0;for(const{factory:e}of n)this.#S.delete(e);for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(J,"Error during cleanup:",t)}}}}getAll(){return[...this.#S]}has(e){return this.#S.has(e)}#b(t){const r=this.#t.maxPlugins;if(0===r)return;const n=t+this.#S.size,{warn:i,error:a}=D(r);n>=a?e.logger.error(J,`${n} plugins registered!`):n>=i&&e.logger.warn(J,`${n} plugins registered`)}#R(t){const r=new Set;for(const n of t)r.has(n)?e.logger.warn(J,"Duplicate factory in batch, will be registered once"):r.add(n);return r}#T(r){const n=r(this.#y,this.#p.getDependency);t.validatePlugin(n),Object.freeze(n);const i=[];for(const t of K)t in n&&("function"==typeof n[t]?(i.push(this.#p.addEventListener(Q[t],n[t])),"onStart"===t&&this.#p.isStarted()&&e.logger.warn(J,"Router already started, onStart will not be called")):e.logger.warn(J,`Property '${t}' is not a function, skipping`));return()=>{for(const e of i)e();"function"==typeof n.teardown&&n.teardown()}}},Y=class{#E=new Map;#A=new Map;#$=new Map;#P=new Map;#O=new Set;#w;#h;#t=A;get#y(){if(!this.#w)throw new Error("[real-router] RouteLifecycleNamespace: router not initialized");return this.#w}get#p(){if(!this.#h)throw new Error("[real-router] RouteLifecycleNamespace: dependencies not initialized");return this.#h}static validateHandler(e,t){!function(e,t){if(!u(e)&&"function"!=typeof e)throw new TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${p(e)}`)}(e,t)}static validateNotRegistering(e,t,r){!function(e,t,r){if(e)throw new Error(`[router.${r}] Cannot modify route "${t}" during its own registration`)}(e,t,r)}static validateHandlerLimit(e,t,r){!function(e,t,r=A.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.`)}(e,t,r)}setRouter(e){this.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#t=e}isRegistering(e){return this.#O.has(e)}countCanActivate(){return this.#A.size}countCanDeactivate(){return this.#E.size}hasCanActivate(e){return this.#A.has(e)}hasCanDeactivate(e){return this.#E.has(e)}registerCanActivate(e,t,r){this.#N("activate",e,t,this.#A,this.#P,"canActivate",r)}registerCanDeactivate(e,t,r){this.#N("deactivate",e,t,this.#E,this.#$,"canDeactivate",r)}clearCanActivate(e){this.#A.delete(e),this.#P.delete(e)}clearCanDeactivate(e){this.#E.delete(e),this.#$.delete(e)}clearAll(){this.#A.clear(),this.#P.clear(),this.#E.clear(),this.#$.clear()}getFactories(){const e={},t={};for(const[t,r]of this.#E)e[t]=r;for(const[e,r]of this.#A)t[e]=r;return[e,t]}getFunctions(){return[this.#$,this.#P]}checkActivateGuardSync(e,t,r){return this.#D(this.#P,e,t,r,"checkActivateGuardSync")}checkDeactivateGuardSync(e,t,r){return this.#D(this.#$,e,t,r,"checkDeactivateGuardSync")}#N(t,r,n,i,a,o,s){s?e.logger.warn(`router.${o}`,`Overwriting existing ${t} handler for route "${r}"`):this.#b(i.size+1,o);const c=u(n)?function(e){const t=()=>e;return()=>t}(n):n;i.set(r,c),this.#O.add(r);try{const e=c(this.#y,this.#p.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${o}] Factory must return a function, got ${p(e)}`);a.set(r,e)}catch(e){throw i.delete(r),e}finally{this.#O.delete(r)}}#D(t,r,n,i,a){const o=t.get(r);if(!o)return!0;try{const t=o(n,i);return"boolean"==typeof t?t:!l(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 n=this.#t.maxLifecycleHandlers;if(0===n)return;const{warn:i,error:a}=D(n);t>=a?e.logger.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at ${n}.`):t>=i&&e.logger.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}};function X(e,t){const r=e.path,n=r.startsWith("~"),i=n?r.slice(1):r,a={name:e.name,path:i,absolute:n,children:[],parent:t,nonAbsoluteChildren:[],fullName:""};if(e.children)for(const t of e.children){const e=X(t,a);a.children.push(e)}return a}function ee(e,t){const r=t.split(".");if(1===r.length)return{parent:e,finalName:t};let n=e;for(let e=0;e<r.length-1;e++){const i=r[e],a=n.children.find(e=>e.name===i);if(!a)throw new Error(`[buildTree] Parent segment "${i}" not found in "${t}"`);n=a}const i=r.at(-1);if(!i)throw new Error(`[buildTree] Empty route name segments in "${t}"`);return{parent:n,finalName:i}}function te(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var re=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,ne=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,ie=/\?(.+)$/,ae=/[^\w!$'()*+,.:;|~-]/gu,oe=/[^\w!$'()*+,.:;|~-]/u,se={default:e=>oe.test(e)?e.replaceAll(ae,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},ce={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function de(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function ue(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function le(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 he(e){const t=[];for(const r of Object.keys(e)){const n=e[r],i=encodeURIComponent(r);t.push(""===n?i:`${i}=${encodeURIComponent(String(n))}`)}return t.join("&")}function fe(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function pe(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,n=e.codePointAt(t+2)??0;if(!fe(r)||!fe(n))return!1;t+=3}else t++;return!0}var ge=/<[^>]*>/g;function me(e,t,r,n,i){const a=""===t.fullName;a||n.push(t);const o=t.absolute,s=t.paramMeta.pathPattern,c=o&&s.startsWith("~")?s.slice(1):s,d=(o?c:s).replaceAll(ge,""),u=o?d:(h=d,""===(l=r)?h:""===h?l:l+h);var l,h;let f=i;a||(f=function(e,t,r,n,i,a){const o=(m=n,ue(r)===ue(m)),s=Object.freeze([...i]),c=function(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return Object.freeze(t)}(s),d=ue(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,i),l=function(e){const t=new Map;for(const r of e)for(const[e,n]of r.paramMeta.constraintPatterns)t.set(e,n);return t}(i),h=o?ue(n):d,{buildStaticParts:f,buildParamSlots:p}=function(e,t,r){const n=new Set,i=new Set;for(const e of t){for(const t of e.paramMeta.urlParams)n.add(t);for(const t of e.paramMeta.spatParams)i.add(t)}if(0===n.size)return{buildStaticParts:[e],buildParamSlots:[]};const a=[],o=[],s=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,d=0;for(;null!==(c=s.exec(e));){const t=c[1],n="?"===c[2];a.push(e.slice(d,c.index));const s=i.has(t);o.push({paramName:t,isOptional:n,encoder:s?e=>{const t=se[r],n=e.split("/");let i=t(n[0]);for(let e=1;e<n.length;e++)i+=`/${t(n[e])}`;return i}:se[r]}),d=c.index+c[0].length}return a.push(e.slice(d)),{buildStaticParts:a,buildParamSlots:o}}(h,o?i.slice(0,-1):i,e.options.urlParamsEncoding),g={name:t.fullName,parent:a,depth:i.length-1,matchSegments:s,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 m;return e.routesByName.set(t.fullName,g),e.segmentsByName.set(t.fullName,s),e.metaByName.set(t.fullName,c),o?function(e,t,r){var n,i;n=t,(function(e,t,r){const n=ue(r);if("/"===n||""===n)return t;let i=t,a=1;const o=n.length;for(;a<=o;){const t=n.indexOf("/",a),r=-1===t?o:t;if(r<=a)break;i=we(e,i,n.slice(a,r)),a=r+1}return i}(i=e,i.root,r)).slashChildRoute=n;const a=ue(r),o=e.options.caseSensitive?a:a.toLowerCase();e.staticCache.has(o)&&e.staticCache.set(o,t)}(e,g,n):function(e,t,r,n,i){if(function(e,t,r){const n=ue(r);"/"!==n?ve(e,e.root,n,1,t):e.root.route=t}(e,t,r),0===i.paramMeta.urlParams.length){const r=e.options.caseSensitive?n:n.toLowerCase();e.staticCache.set(r,t)}}(e,g,r,d,t),g}(e,t,u,o?"":r,n,i));for(const r of t.children.values())me(e,r,u,n,f);a||n.pop()}function ve(e,t,r,n,i){const a=r.length;for(;n<=a;){const o=r.indexOf("/",n),s=-1===o?a:o,c=r.slice(n,s);if(c.endsWith("?")){const n=c.slice(1).replaceAll(ge,"").replace(/\?$/,"");return t.paramChild??={node:de(),name:n},ve(e,t.paramChild.node,r,s+1,i),void(s>=a?t.route??=i:ve(e,t,r,s+1,i))}t=we(e,t,c),n=s+1}t.route=i}function we(e,t,r){if(r.startsWith("*")){const e=r.slice(1);return t.splatChild??={node:de(),name:e},t.splatChild.node}if(r.startsWith(":")){const e=r.slice(1).replaceAll(ge,"").replace(/\?$/,"");return t.paramChild??={node:de(),name:e},t.paramChild.node}const n=e.options.caseSensitive?r:r.toLowerCase();return n in t.staticChildren||(t.staticChildren[n]=de()),t.staticChildren[n]}var ye=/[\u0080-\uFFFF]/,be=class{get options(){return this.#C}#C;#j=de();#M=new Map;#k=new Map;#F=new Map;#I=new Map;#L="";#x=[];constructor(e){this.#C={caseSensitive:e?.caseSensitive??!0,strictTrailingSlash:e?.strictTrailingSlash??!1,strictQueryParams:e?.strictQueryParams??!1,urlParamsEncoding:e?.urlParamsEncoding??"default",parseQueryString:e?.parseQueryString??le,buildQueryString:e?.buildQueryString??he}}registerTree(e){this.#x=e.paramMeta.queryParams,me({root:this.#j,options:this.#C,routesByName:this.#M,segmentsByName:this.#k,metaByName:this.#F,staticCache:this.#I,rootQueryParams:this.#x},e,"",[],null)}match(e){const t=this.#_(e);if(!t)return;const[r,n,i]=t,a=this.#C.caseSensitive?n:n.toLowerCase(),o=this.#I.get(a);if(o){if(this.#C.strictTrailingSlash&&!this.#U(r,o))return;return this.#V(o,{},i)}const s={},c=this.#z(n,s);return!c||this.#C.strictTrailingSlash&&!this.#U(r,c)||c.hasConstraints&&!this.#G(s,c)||!this.#q(s)?void 0:this.#V(c,s,i)}buildPath(e,t,r){const n=this.#M.get(e);if(!n)throw new Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);n.hasConstraints&&t&&this.#W(n,e,t);const i=this.#B(n,t),a=this.#H(i,r?.trailingSlash),o=this.#Q(n,t,r?.queryParamsMode);return a+(o?`?${o}`:"")}getSegmentsByName(e){return this.#k.get(e)}getMetaByName(e){return this.#F.get(e)}hasRoute(e){return this.#M.has(e)}setRootPath(e){this.#L=e}#W(e,t,r){for(const[n,i]of e.constraintPatterns){const e=r[n];if(null!=e){const r="object"==typeof e?JSON.stringify(e):String(e);if(!i.pattern.test(r))throw new Error(`[SegmentMatcher.buildPath] '${t}' — param '${n}' value '${r}' does not match constraint '${i.constraint}'`)}}}#B(e,t){const r=e.buildStaticParts,n=e.buildParamSlots;if(0===n.length)return this.#L+r[0];let i=this.#L+r[0];for(const[e,a]of n.entries()){const n=t?.[a.paramName];if(null==n){if(!a.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${a.paramName}'`);i.length>1&&i.endsWith("/")&&(i=i.slice(0,-1)),i+=r[e+1];continue}const o="object"==typeof n?JSON.stringify(n):String(n);i+=a.encoder(o)+r[e+1]}return i}#H(e,t){return"always"!==t||e.endsWith("/")?"never"===t&&"/"!==e&&e.endsWith("/")?e.slice(0,-1):e:`${e}/`}#Q(e,t,r){if(!t)return"";const n=[...e.declaredQueryParams];if("loose"===r){const r=new Set(e.buildParamSlots.map(e=>e.paramName));for(const i in t)!Object.hasOwn(t,i)||e.declaredQueryParamsSet.has(i)||r.has(i)||n.push(i)}const i={};for(const e of n)e in t&&(i[e]=t[e]);return 0===Object.keys(i).length?"":this.#C.buildQueryString(i)}#_(e){if(""===e&&(e="/"),!e.startsWith("/"))return;const t=e.indexOf("#");if(-1!==t&&(e=e.slice(0,t)),ye.test(e))return;if(this.#L.length>0){if(!e.startsWith(this.#L))return;e=e.slice(this.#L.length)||"/"}const r=e.indexOf("?"),n=-1===r?e:e.slice(0,r),i=-1===r?void 0:e.slice(r+1);return n.includes("//")?void 0:[n,ue(n),i]}#V(e,t,r){if(void 0!==r){const n=this.#C.parseQueryString(r);if(this.#C.strictQueryParams){const t=e.declaredQueryParamsSet;for(const e of Object.keys(n))if(!t.has(e))return}for(const e of Object.keys(n))t[e]=n[e]}return{segments:e.matchSegments,params:t,meta:e.meta}}#U(e,t){return(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#z(e,t){return 1===e.length?this.#j.slashChildRoute??this.#j.route:this.#K(this.#j,e,1,t)}#K(e,t,r,n){let i=e;const a=t.length;for(;r<=a;){const e=t.indexOf("/",r),o=-1===e?a:e,s=t.slice(r,o),c=this.#C.caseSensitive?s:s.toLowerCase();let d;if(c in i.staticChildren)d=i.staticChildren[c];else{if(!i.paramChild){if(i.splatChild){const e={},a=this.#K(i.splatChild.node,t,r,e);return a?(Object.assign(n,e),a):(n[i.splatChild.name]=t.slice(r),i.splatChild.node.route)}return}d=i.paramChild.node,n[i.paramChild.name]=s}i=d,r=o+1}return i.slashChildRoute??i.route}#q(e){const t=this.#C.urlParamsEncoding;if("none"===t)return!0;const r=ce[t];for(const t in e){const n=e[t];if(n.includes("%")){if(!pe(n))return!1;e[t]=r(n)}}return!0}#G(e,t){for(const[r,n]of t.constraintPatterns)if(!n.pattern.test(e[r]))return!1;return!0}};function Se(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function Te(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}function Re(e,t,r){const n=function(e){const t=[],r=[],n=[],i={},a=new Map,o=e.replaceAll(ne,"$1"),s=ie.exec(o);if(null!==s){const t=s[1].split("&");for(const e of t){const t=e.trim();t.length>0&&(r.push(t),i[t]="query")}e=e.slice(0,s.index)}let c;for(;null!==(c=re.exec(e));){const e=c[2],r=c[3];if("*"===c[1])n.push(e),t.push(e),i[e]="url";else if(t.push(e),i[e]="url",r){const t=`^${te(r)}$`;a.set(e,{pattern:new RegExp(t),constraint:r})}}return{urlParams:t,queryParams:r,spatParams:n,paramTypeMap:i,constraintPatterns:a,pathPattern:e}}(e.path),i=function(e){const t={};for(const r of e.urlParams)t[r]="url";for(const r of e.queryParams)t[r]="query";return t}(n),a={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:void 0,paramMeta:n,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:i};a.fullName=function(e){return e.parent?.name?`${e.parent.fullName}.${e.name}`:e.name}(a);const{childrenMap:o,nonAbsoluteChildren:s}=function(e,t,r){const n=[],i=[];for(const a of e){const e=Re(a,t,r);n.push(e),e.absolute||i.push(e)}return{childrenMap:Te(n),nonAbsoluteChildren:i}}(e.children,a,r);return a.children=o,a.nonAbsoluteChildren=s,a.staticPath=function(e){if(!e.path)return null;const{urlParams:t,queryParams:r,spatParams:n}=e.paramMeta;if(t.length>0||r.length>0||n.length>0)return null;const i=[];let a=e.parent;for(;a?.path;)i.unshift(a),a=a.parent;let o="";for(const e of i){const{urlParams:t,queryParams:r,spatParams:n}=e.paramMeta;if(t.length>0||r.length>0||n.length>0)return null;o=e.absolute?e.path:Se(o,e.path)}return e.absolute?e.path:Se(o,e.path)}(a),r&&(Object.freeze(s),Object.freeze(i),Object.freeze(a.children),Object.freeze(a)),a}function Ee(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build(n){const i=function(e,t,r){const n=X({name:e,path:t},null),i=[];for(const e of r)if(e.name.includes("."))i.push(e);else if(e.children&&e.children.length>0){const t=X(e,n);n.children.push(t)}else i.push(e);for(const e of i){const{parent:t,finalName:r}=ee(n,e.name),i=X({name:r,path:e.path,children:e.children},t);t.children.push(i)}return n}(e,t,r);return function(e,t=!0){return Re(e,null,t)}(i,!n?.skipFreeze)}}}function Ae(e,t,r,n){return Ee(e,t).addMany(r).build(n)}function $e(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=>$e(e))),t}var Pe=e=>{const t=e.indexOf("%"),r=e.indexOf("+");if(-1===t&&-1===r)return e;const n=-1===r?e:e.split("+").join(" ");return-1===t?n:decodeURIComponent(n)},Oe=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)},Ne={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${Oe(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${Oe(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${Oe(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>Oe(e)).join(",")}`}},De={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}},Ce={default:{encode:e=>e},hidden:{encode:()=>""}},je=(e,t,r)=>({boolean:De[t],null:Ce[r],array:Ne[e]}),Me={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:De.none,null:Ce.default,array:Ne.none}},ke=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return Me;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:je(t,r,n)}},Fe=e=>encodeURIComponent(e),Ie=(e,t,r)=>{const n=Fe(e);switch(typeof t){case"string":case"number":default:return`${n}=${Fe(t)}`;case"boolean":return r.strategies.boolean.encode(n,t);case"object":return null===t?r.strategies.null.encode(n):Array.isArray(t)?r.strategies.array.encodeArray(n,t):`${n}=${Fe(t)}`}};function Le(e,t,r,n,i){const a=e.indexOf("=",t),o=-1!==a&&a<r,s=e.slice(t,o?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}}(s);!function(e,t,r,n){const i=e[t];void 0===i?e[t]=n?[r]:r:Array.isArray(i)?i.push(r):e[t]=[i,r]}(n,Pe(c),function(e,t,r,n,i){return i?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const n=Pe(e);return t.boolean.decodeValue(n)})(n?e.slice(t+1,r):void 0,i):n?Pe(e.slice(t+1,r)):null}(e,a,r,o,i),d)}function xe(e){const t=e?.queryParams;return new be({...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 n=e.length;for(;r<n;){let i=e.indexOf("&",r);-1===i&&(i=n),Le(e,r,i,t),r=i+1}}(e,t),t}(r);const n=ke(t),i={};let a=0;const o=r.length;for(;a<o;){let e=r.indexOf("&",a);-1===e&&(e=o),Le(r,a,e,i,n.strategies),a=e+1}return i})(e,t),buildQueryString:e=>((e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=ke(t),i=[];for(const t of r){const r=e[t];if(void 0===r)continue;const a=Ie(t,r,n);a&&i.push(a)}return i.join("&")})(e,t)})}function _e(e,t){return new TypeError(`[router.${e}] ${t}`)}var Ue=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/,Ve=/\S/;function ze(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function Ge(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 qe(e,t,r,n="",i,a){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${ze(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${ze(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 o=e;!function(e,t){if("string"!=typeof e.name)throw new TypeError(`[router.${t}] Route name must be a string, got ${ze(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!Ve.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("@@")&&!Ue.test(r))throw new TypeError(`[router.${t}] Invalid route name "${r}". 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").`)}(o,t),function(e,t,r,n){if("string"!=typeof e){let t;throw t=null===e?"null":Array.isArray(e)?"array":typeof e,_e(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw _e(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw _e(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw _e(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const i=n&&Object.values(n.paramTypeMap).includes("url");if(e.startsWith("~")&&i)throw _e(r,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}(o.path,o.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`)}(o,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`)}(o,t);const s=o.name,c=n?`${n}.${s}`:s;!n&&c.includes(".")&&function(e,t,r,n){const i=t.split(".");i.pop();const a=i.join(".");if(!n?.has(a)){if(!e)throw new Error(`[router.${r}] Parent route "${a}" does not exist for route "${t}"`);if(!Ge(e,a))throw new Error(`[router.${r}] Parent route "${a}" does not exist for route "${t}"`)}}(r,c,t,i),r&&c&&function(e,t,r){if(Ge(e,t))throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),i&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(i,c,t);const d=o.path;let u=n;if(s.includes(".")&&!n){const e=s.split(".");e.pop(),u=e.join(".")}if(r&&function(e,t,r,n){const i=""===t?e:Ge(e,t);if(i)for(const e of i.children.values())if(e.path===r)throw new Error(`[router.${n}] Path "${r}" is already defined`)}(r,u,d,t),a&&function(e,t,r,n){const i=e.get(t);if(i?.has(r))throw new Error(`[router.${n}] Path "${r}" is already defined`);i?i.add(r):e.set(t,new Set([r]))}(a,u,d,t),void 0!==o.children){if(!Array.isArray(o.children))throw new TypeError(`[router.${t}] Route "${s}" children must be an array, got ${ze(o.children)}`);for(const e of o.children)qe(e,t,r,c,i,a)}}var We=new Set;function Be(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>Be(e))),t}function He(e,t,r=""){for(let n=0;n<e.length;n++){const i=e[n],a=r?`${r}.${i.name}`:i.name;if(a===t)return e.splice(n,1),!0;if(i.children&&t.startsWith(`${a}.`)&&He(i.children,t,a))return!0}return!1}function Qe(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function Ke(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 ${p(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 ${p(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 ${p(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){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError(`[router.addRoute] forwardTo must be a string or function for route "${t}", got ${p(e)}`);if("function"==typeof e){const r="AsyncFunction"===e.constructor.name,n=e.toString().includes("__awaiter");if(r||n)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)Ke(r,`${t}.${r.name}`)}function Je(e){const t=new Set,r=/[*:]([A-Z_a-z]\w*)/g;let n;for(;null!==(n=r.exec(e));)t.add(n[1]);return t}function Ze(e){const t=new Set;for(const r of e)for(const e of Je(r))t.add(e);return t}function Ye(e,t,r="",n=[]){for(const i of e){const e=r?`${r}.${i.name}`:i.name,a=[...n,i.path];if(e===t)return a;if(i.children&&t.startsWith(`${e}.`))return Ye(i.children,t,e,a)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function Xe(e,t=""){const r=new Set;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(r.add(e),n.children)for(const t of Xe(n.children,e))r.add(t)}return r}function et(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&"string"==typeof n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,i]of et(n.children,e))r.set(t,i)}return r}function tt(e,t,r,n){if(t){const t=function(e,t){const r=[],n=t.includes(".")?t.split("."):[t];""!==e.path&&r.push(e);let i=e;for(const e of n){const t=i.children.get(e);if(!t)return null;r.push(t),i=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 Ze(Ye(n,e))}function rt(e,t,r,n,i){const a=function(e,t){const r=t.split(".");let n=e;for(const e of r)if(n=n.children.get(e),!n)return!1;return!0}(i,t),o=n.has(t);if(!a&&!o)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const s=Ze(Ye(r,e)),c=[...tt(t,a,i,r)].filter(e=>!s.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 nt(e,t,r=100){const n=new Set,i=[e];let a=e;for(;t[a];){const e=t[a];if(n.has(e)){const t=i.indexOf(e),r=[...i.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(a),i.push(e),a=e,i.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${i.join(" → ")}`)}return a}function it(e,t,r){const n=Xe(e),i=et(e),a={...t};for(const[e,t]of i)a[e]=t;for(const[t,a]of i)rt(t,a,e,n,r);for(const e of Object.keys(a))nt(e,a)}function at(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}function ot(e,t){if("AsyncFunction"===e.constructor.name||e.toString().includes("__awaiter"))throw new TypeError(`[real-router] updateRoute: ${t} cannot be an async function`)}function st(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}`);ot(e,t)}}var ct=".";function dt(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function ut(e,t){const r=t.meta?.params[e];if(!r||"object"!=typeof r)return{};const n={};for(const e in r){if(!Object.hasOwn(r,e))continue;if(void 0===r[e])continue;const i=t.params[e];null!=i&&("string"!=typeof i&&"number"!=typeof i&&"boolean"!=typeof i||(n[e]=String(i)))}return n}function lt(e){if(!e)return[""];const t=e.indexOf(ct);if(-1===t)return[e];const r=e.indexOf(ct,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(ct,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(ct,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(ct),r=t.length,n=[t[0]];let i=t[0].length;for(let a=1;a<r-1;a++)i+=1+t[a].length,n.push(e.slice(0,i));return n.push(e),n}(e)}function ht(e,t){if(!t)return{intersection:"",toActivate:lt(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:lt(e.name),toDeactivate:dt(lt(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:lt(e.name),toDeactivate:dt(lt(t.name))};if(e.name===t.name&&r&&n){const r=e.meta&&0===Object.keys(e.meta.params).length,n=t.meta&&0===Object.keys(t.meta.params).length;if(r&&n)return{intersection:e.name,toActivate:[],toDeactivate:[]}}const i=lt(e.name),a=lt(t.name),o=function(e,t,r,n,i){for(let a=0;a<i;a++){const i=r[a],o=n[a];if(i!==o)return a;const s=ut(i,e),c=ut(o,t),d=Object.keys(s),u=Object.keys(c);if(d.length!==u.length)return a;for(const e of d)if(s[e]!==c[e])return a}return i}(e,t,i,a,Math.min(a.length,i.length)),s=[];for(let e=a.length-1;e>=o;e--)s.push(a[e]);const c=i.slice(o);return{intersection:o>0?a[o-1]:"",toDeactivate:s,toActivate:c}}var ft=Object.freeze({}),pt=class{#J=[];#Z=function(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}();#Y=Object.create(null);#X=new Map;#ee=new Map;#te="";#re;#ne;#ie;#h;#ae;#oe;get#p(){if(!this.#h)throw new Error("[real-router] RoutesNamespace: dependencies not initialized");return this.#h}constructor(e=[],t=!1,r){this.#oe=t,this.#ie=r;for(const t of e)this.#J.push(Be(t));this.#re=Ae("",this.#te,this.#J),this.#ne=xe(r),this.#ne.registerTree(this.#re),this.#se(e),t?this.#ce():this.#de()}static validateRemoveRouteArgs(e){!function(e){f(e,"removeRoute")}(e)}static validateSetRootPathArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${p(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 ${p(t)}`);Ke(t,t.name)}}(e)}static validateIsActiveRouteArgs(e,t,r,n){!function(e,t,r,n){if(!d(e))throw new TypeError("Route name must be a string");if(void 0!==t&&!s(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!==n&&"boolean"!=typeof n)throw new TypeError("[router.isActiveRoute] ignoreQueryParams must be a boolean, got "+typeof n)}(e,t,r,n)}static validateStateBuilderArgs(e,t,r){!function(e,t,r){if(!d(e))throw new TypeError(`[router.${r}] Invalid routeName: ${p(e)}. Expected string.`);if(!s(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${p(t)}. Expected plain object.`)}(e,t,r)}static validateUpdateRouteBasicArgs(e,t){!function(e,t){if(f(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 ${p(t)}`)}(e,t)}static validateUpdateRoutePropertyTypes(e,t,r,n){!function(e,t,r,n){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 ${p(e)}`);"function"==typeof e&&ot(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 ${p(t)}`);st(r,"decodeParams"),st(n,"encodeParams")}(e,t,r,n)}static validateBuildPathArgs(e){!function(e){if(!d(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(!d(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e)}static validateShouldUpdateNodeArgs(e){!function(e){if(!d(e))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof e)}(e)}static validateRoutes(e,t,r){!function(e,t,r){const n=new Set,i=new Map;for(const r of e)qe(r,"addRoute",t,"",n,i);t&&r&&it(e,r,t)}(e,t,r)}setDependencies(e){this.#h=e;for(const[t,r]of this.#X)e.addActivateGuard(t,r);this.#X.clear();for(const[t,r]of this.#ee)e.addDeactivateGuard(t,r);this.#ee.clear()}setLifecycleNamespace(e){this.#ae=e}getRootPath(){return this.#te}getTree(){return this.#re}getForwardRecord(){return this.#Z.forwardMap}setRootPath(e){this.#te=e,this.#ue()}hasRoute(e){return this.#ne.hasRoute(e)}getRoute(e){const t=this.#ne.getSegmentsByName(e);if(!t)return;const r=$e(this.#le(t));return this.#he(r,e)}addRoutes(e){for(const t of e)this.#J.push(Be(t));this.#se(e),this.#ue(),this.#fe()}removeRoute(e){return!!He(this.#J,e)&&(this.#pe(e),this.#ue(),this.#fe(),!0)}updateRouteConfig(e,t){if(void 0!==t.forwardTo&&this.#ge(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.#J.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.#Y)delete this.#Y[e];this.#ue()}buildPath(e,t,r){if(e===v.UNKNOWN_ROUTE)return d(t?.path)?t.path:"";const n=Object.hasOwn(this.#Z.defaultParams,e)?{...this.#Z.defaultParams[e],...t}:t??{},i="function"==typeof this.#Z.encoders[e]?this.#Z.encoders[e]({...n}):n,a=r?.trailingSlash;return this.#ne.buildPath(e,i,{trailingSlash:"never"===a||"always"===a?a:void 0,queryParamsMode:r?.queryParamsMode})}matchPath(e,t,r){const n=r,i=this.#ne.match(e);if(!i)return;const a=at(i),{name:o,params:s,meta:c}=a,d="function"==typeof this.#Z.decoders[o]?this.#Z.decoders[o](s):s,{name:u,params:l}=this.#p.forwardState(o,d);let h=e;if(n.rewritePathOnMatch){const e="function"==typeof this.#Z.encoders[u]?this.#Z.encoders[u]({...l}):l,t=n.trailingSlash;h=this.#ne.buildPath(u,e,{trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:n.queryParamsMode})}return this.#p.makeState(u,l,h,{params:c,options:ft,source:t,redirected:!1})}forwardState(e,t){if(Object.hasOwn(this.#Z.forwardFnMap,e)){const r=this.#me(e,t),n=this.#Z.forwardFnMap[e],i=this.#ve(e,n,t);return{name:i,params:this.#me(i,r)}}const r=this.#Y[e]??e;if(r!==e&&Object.hasOwn(this.#Z.forwardFnMap,r)){const n=this.#me(e,t),i=this.#Z.forwardFnMap[r],a=this.#ve(r,i,t);return{name:a,params:this.#me(a,n)}}if(r!==e){const n=this.#me(e,t);return{name:r,params:this.#me(r,n)}}return{name:e,params:this.#me(e,t)}}buildStateResolved(e,t){const r=this.#ne.getSegmentsByName(e);if(r)return at({segments:r,params:t,meta:this.#ne.getMetaByName(e)??{}},e)}buildStateWithSegmentsResolved(e,t){const r=this.#ne.getSegmentsByName(e);if(r)return{state:at({segments:r,params:t,meta:this.#ne.getMetaByName(e)??{}},e),segments:r}}isActiveRoute(e,t={},r=!1,n=!0){We.has(e)||(f(e,"isActiveRoute"),We.add(e));const i=this.#p.getState();if(!i)return!1;const a=i.name;if(a!==e&&!a.startsWith(`${e}.`)&&!e.startsWith(`${a}.`))return!1;const o=this.#Z.defaultParams[e];if(r||a===e){const r=o?{...o,...t}:t;return this.#p.areStatesEqual({name:e,params:r,path:""},i,n)}const s=i.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(t,s)&&(!o||function(e,t,r){for(const n in e)if(!(n in r)&&e[n]!==t[n])return!1;return!0}(o,s,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:n,toActivate:i,toDeactivate:a}=ht(t,r);return e===n||!!i.includes(e)||a.includes(e)}}getConfig(){return this.#Z}getUrlParams(e){const t=this.#ne.getSegmentsByName(e);return t?this.#we(t):[]}getResolvedForwardMap(){return this.#Y}setResolvedForwardMap(e){Object.assign(this.#Y,e)}cloneRoutes(){return[...this.#re.children.values()].map(e=>$e(e))}validateForwardToParamCompatibility(e,t){const r="validateForwardToParamCompatibility",n=this.#ye(e,r),i=this.#ye(t,r),a=this.#be(n),o=this.#we(i).filter(e=>!a.has(e));if(o.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${o.join(", ")}] that are not available in source route "${e}"`)}validateForwardToCycle(e,t){nt(e,{...this.#Z.forwardMap,[e]:t})}validateRemoveRoute(t,r,n){if(r){const n=r===t,i=r.startsWith(`${t}.`);if(n||i)return e.logger.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${n?"":` (current: "${r}")`}. Navigate away first.`),!1}return n&&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)}}#ge(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.#fe()}#me(e,t){return Object.hasOwn(this.#Z.defaultParams,e)?{...this.#Z.defaultParams[e],...t}:t}#ve(e,t,r){const n=new Set([e]);let i=t(this.#p.getDependency,r),a=0;if("string"!=typeof i)throw new TypeError("forwardTo callback must return a string, got "+typeof i);for(;a<100;){if(void 0===this.#ne.getSegmentsByName(i))throw new Error(`Route "${i}" does not exist`);if(n.has(i)){const e=[...n,i].join(" → ");throw new Error(`Circular forwardTo detected: ${e}`)}if(n.add(i),Object.hasOwn(this.#Z.forwardFnMap,i)){if(i=(0,this.#Z.forwardFnMap[i])(this.#p.getDependency,r),"string"!=typeof i)throw new TypeError("forwardTo callback must return a string, got "+typeof i);a++;continue}const e=this.#Z.forwardMap[i];if(void 0===e)return i;i=e,a++}throw new Error("forwardTo exceeds maximum depth of 100")}#ue(){this.#re=Ae("",this.#te,this.#J),this.#ne=xe(this.#ie),this.#ne.registerTree(this.#re)}#ye(e,t){const r=this.#ne.getSegmentsByName(e);if(!r)throw new ReferenceError(`[real-router] ${t}: route "${e}" does not exist`);return r}#le(e){const t=e.at(-1);if(!t)throw new Error("[real-router] Internal error: empty segments array");return t}#be(e){const t=new Set;for(const r of e)for(const e of r.paramMeta.urlParams)t.add(e);return t}#we(e){const t=[];for(const r of e)for(const e of r.paramMeta.urlParams)t.push(e);return t}#fe(){this.#oe?this.#ce():this.#de()}#de(){for(const e in this.#Y)delete this.#Y[e];for(const e of Object.keys(this.#Z.forwardMap))this.#Y[e]=nt(e,this.#Z.forwardMap)}#ce(){for(const e in this.#Y)delete this.#Y[e];for(const e of Object.keys(this.#Z.forwardMap)){let t=e;for(;this.#Z.forwardMap[t];)t=this.#Z.forwardMap[t];this.#Y[e]=t}}#pe(e){const t=t=>t===e||t.startsWith(`${e}.`);if(Qe(this.#Z.decoders,t),Qe(this.#Z.encoders,t),Qe(this.#Z.defaultParams,t),Qe(this.#Z.forwardMap,t),Qe(this.#Z.forwardFnMap,t),Qe(this.#Z.forwardMap,e=>t(this.#Z.forwardMap[e])),this.#ae){const[e,r]=this.#ae.getFactories();for(const e of Object.keys(r))t(e)&&this.#ae.clearCanActivate(e);for(const r of Object.keys(e))t(r)&&this.#ae.clearCanDeactivate(r)}}#se(e,t=""){for(const r of e){const e=t?`${t}.${r.name}`:r.name;this.#Se(r,e),r.children&&this.#se(r.children,e)}}#Se(e,t){e.canActivate&&(this.#h?this.#h.addActivateGuard(t,e.canActivate):this.#X.set(t,e.canActivate)),e.canDeactivate&&(this.#h?this.#h.addDeactivateGuard(t,e.canDeactivate):this.#ee.set(t,e.canDeactivate)),e.forwardTo&&this.#Te(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)}#Te(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,n=t.forwardTo.toString().includes("__awaiter");if(e||n)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}#he(e,t){const r={name:e.name,path:e.path},n=this.#Z.forwardFnMap[t],i=this.#Z.forwardMap[t];if(void 0!==n?r.forwardTo=n:void 0!==i&&(r.forwardTo=i),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]),this.#ae){const[e,n]=this.#ae.getFactories();t in n&&(r.canActivate=n[t]),t in e&&(r.canDeactivate=e[t])}return e.children&&(r.children=e.children.map(e=>this.#he(e,`${t}.${e.name}`))),r}},gt={log:0,warn:1,error:2},mt={all:0,"warn-error":1,"error-only":2,none:3},vt=new class{#Z={level:"all",callbackIgnoresLevel:!1};#Re=0;configure(e){if(void 0!==e.level){if(!(e.level in mt))throw new Error(`Invalid log level: "${e.level}". Valid levels are: ${Object.keys(mt).join(", ")}`);this.#Z.level=e.level,this.#Re=mt[e.level]}"callback"in e&&(this.#Z.callback=e.callback),void 0!==e.callbackIgnoresLevel&&(this.#Z.callbackIgnoresLevel=e.callbackIgnoresLevel)}getConfig(){return{level:this.#Z.level,callback:this.#Z.callback,callbackIgnoresLevel:this.#Z.callbackIgnoresLevel}}log(e,t,...r){this.#Ee("log",e,t,r)}warn(e,t,...r){this.#Ee("warn",e,t,r)}error(e,t,...r){this.#Ee("error",e,t,r)}#Ee(e,t,r,n){if("none"===this.#Z.level&&!this.#Z.callbackIgnoresLevel)return;const i=gt[e]<this.#Re;i||this.#Ae(e,t,r,n),this.#$e(e,t,r,i,n)}#Ae(e,t,r,n){"undefined"!=typeof console&&"function"==typeof console[e]&&console[e](t?`[${t}] ${r}`:r,...n)}#$e(e,t,r,n,i){if(this.#Z.callback&&(this.#Z.callbackIgnoresLevel||!n))try{this.#Z.callback(e,t,r,...i)}catch(e){"undefined"!=typeof console&&"function"==typeof console.error&&console.error("[Logger] Error in callback:",e)}}},wt=new Set(["code","segment","path","redirect"]),yt=new Set(Object.values(m)),bt=new Set(["code","segment","path","redirect"]),St=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),Tt=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:n,redirect:i,...a}={}){super(t??e),this.code=e,this.segment=r,this.path=n,this.redirect=i?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),n=new WeakSet;return function e(t){if(null===t||"object"!=typeof t)return;if(n.has(t))return;n.add(t),Object.freeze(t);const r=Array.isArray(t)?t:Object.values(t);for(const t of r)e(t)}(r),r}(i):void 0;for(const[e,t]of Object.entries(a)){if(bt.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);St.has(e)||(this[e]=t)}}setCode(e){this.code=e,yt.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(bt.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);St.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 Rt(e,t,r){if(e instanceof Tt){const r=((e,t)=>{if(t)return t.setCode(e),t})(t,e);if(r)throw r}throw new Tt(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,n]of Object.entries(e))wt.has(r)||(t[r]=n);return{...r,...t}}return r}(e,r))}var Et=(e,t)=>{const r=e.meta,n=t.meta,i=r?.params,a=n?.params,o=i&&a?{...i,...a}:i??a??{},s={id:1,options:{},redirected:!1,...n,...r,params:o};return{...e,meta:s}},At=async(e,t,r)=>{const n=r?{segment:r}:{};if(void 0===e)return t;if("boolean"==typeof e){if(e)return t;throw new Tt(m.TRANSITION_ERR,n)}if(c(e))return e;if(l(e))try{const n=await e;return await At(n,t,r)}catch(e){throw new Tt(m.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,n))}throw new Tt(m.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})},$t=async(e,t,r,n,i,a)=>{let o=t;const s=n.filter(t=>e.has(t));if(0===s.length)return o;for(const t of s){if(a())throw new Tt(m.TRANSITION_CANCELLED);const n=e.get(t);try{const e=n(o,r),a=await At(e,o,t);if(a!==o&&c(a)){if(a.name!==o.name)throw new Tt(i,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:a.name,params:a.params,path:a.path}});(a.params!==o.params||a.path!==o.path)&&vt.error("core:transition","Warning: State mutated during transition",{from:o,to:a}),o=Et(a,o)}}catch(e){Rt(e,i,t)}}return o};var Pt=class{isRouterStarted;#Pe=!1;#h;#Oe;get#p(){if(!this.#h)throw new Error("[real-router] NavigationNamespace: dependencies not initialized");return this.#h}get#Ne(){if(!this.#Oe)throw new Error("[real-router] NavigationNamespace: transition dependencies not initialized");return this.#Oe}static validateNavigateArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${p(e)}`)}(e)}static validateNavigateToStateArgs(e,t,r,n){!function(e,t,r,n){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 ${p(r)}`);if("boolean"!=typeof n)throw new TypeError(`[router.navigateToState] Invalid emitSuccess: expected boolean, got ${p(n)}`)}(e,t,r,n)}static validateNavigateToDefaultArgs(e){!function(e){if(void 0!==e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${p(e)}. Expected NavigationOptions object.`)}(e)}static validateNavigationOptions(e,r){!function(e,r){if(!function(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const r=e;for(const e of t){const t=r[e];if(void 0!==t&&"boolean"!=typeof t)return!1}return!0}(e))throw new TypeError(`[router.${r}] Invalid options: ${p(e)}. Expected NavigationOptions object.`)}(e,r)}setDependencies(e){this.#h=e}setTransitionDependencies(e){this.#Oe=e}isNavigating(){return this.isRouterStarted()&&this.#Pe}cancel(){this.#Pe=!1}async navigateToState(t,r,n,i){const a=this.#p,o=this.#Ne;this.#Pe&&e.logger.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use router.clone() to create isolated instance per request."),this.cancel(),this.#Pe=!0,a.invokeEventListeners(E.TRANSITION_START,t,r);try{const e=await async function(e,t,r,n){const[i,a]=e.getLifecycleFunctions(),o=e.getMiddlewareFunctions(),s=t.name===v.UNKNOWN_ROUTE,d=()=>!e.isActive(),{toDeactivate:u,toActivate:l}=ht(t,r),h=!s&&l.length>0,f=o.length>0;let p=t;if(r&&!n.forceDeactivate&&u.length>0&&(p=await $t(i,t,r,u,m.CANNOT_DEACTIVATE,d)),d())throw new Tt(m.TRANSITION_CANCELLED);if(h&&(p=await $t(a,p,r,l,m.CANNOT_ACTIVATE,d)),d())throw new Tt(m.TRANSITION_CANCELLED);if(f&&(p=await(async(e,t,r,n)=>{let i=t;for(const t of e){if(n())throw new Tt(m.TRANSITION_CANCELLED);try{const e=t(i,r),n=await At(e,i);n!==i&&c(n)&&((n.name!==i.name||n.params!==i.params||n.path!==i.path)&&vt.error("core:middleware","Warning: State mutated during middleware execution",{from:i,to:n}),i=Et(n,i))}catch(e){Rt(e,m.TRANSITION_ERR)}}return i})(o,p,r,d)),d())throw new Tt(m.TRANSITION_CANCELLED);if(r){const n=lt(t.name),a=lt(r.name),o=new Set(n);for(const t of a)!o.has(t)&&i.has(t)&&e.clearCanDeactivate(t)}return p}(o,t,r,n);if(e.name===v.UNKNOWN_ROUTE||a.hasRoute(e.name))return a.setState(e),i&&a.invokeEventListeners(E.TRANSITION_SUCCESS,e,r,n),e;throw new Tt(m.ROUTE_NOT_FOUND,{routeName:e.name})}catch(e){throw e instanceof Tt?e.code===m.TRANSITION_CANCELLED?a.invokeEventListeners(E.TRANSITION_CANCEL,t,r):e.code===m.ROUTE_NOT_FOUND?a.invokeEventListeners(E.TRANSITION_ERROR,void 0,a.getState(),e):a.invokeEventListeners(E.TRANSITION_ERROR,t,r,e):a.invokeEventListeners(E.TRANSITION_ERROR,t,r,e),e}finally{this.#Pe=!1}}navigate(t,r,n){const i=this.#p;if(!this.isRouterStarted()){const e=new Tt(m.ROUTER_NOT_STARTED);return Promise.reject(e)}let a;try{a=i.buildStateWithSegments(t,r)}catch(e){return Promise.reject(e)}if(!a){const e=new Tt(m.ROUTE_NOT_FOUND);return i.invokeEventListeners(E.TRANSITION_ERROR,void 0,i.getState(),e),Promise.reject(e)}const{state:o}=a,s=i.makeState(o.name,o.params,i.buildPath(o.name,o.params),{params:o.meta,options:n,redirected:n.redirected??!1}),c=i.getState();if(!n.reload&&!n.force&&i.areStatesEqual(c,s,!1)){const e=new Tt(m.SAME_STATES);i.invokeEventListeners(E.TRANSITION_ERROR,s,c,e);const t=Promise.reject(e);return t.catch(()=>{}),t}const d=this.navigateToState(s,c,n,!0);return d.catch(t=>{t instanceof Tt&&(t.code===m.SAME_STATES||t.code===m.TRANSITION_CANCELLED)||e.logger.error("router.navigate","Unexpected navigation error",t)}),d}navigateToDefault(e){const t=this.#p,r=t.getOptions();if(!r.defaultRoute)return Promise.reject(new Tt(m.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"}));const n=_(r.defaultRoute,t.getDependency);if(!n)return Promise.reject(new Tt(m.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"}));const i=_(r.defaultParams,t.getDependency);return this.navigate(n,i,e)}},Ot=new Tt(m.ROUTER_ALREADY_STARTED),Nt=class{navigateToState;#De=!1;#Ce=!1;#h;get#p(){if(!this.#h)throw new Error("[real-router] RouterLifecycleNamespace: dependencies not initialized");return this.#h}static validateStartArgs(e){if(1!==e.length||"string"!=typeof e[0])throw new Error("[router.start] Expected exactly 1 string argument (startPath).")}setDependencies(e){this.#h=e}isStarted(){return this.#De}isActive(){return this.#Ce}async start(e){const t=this.#p,r=t.getOptions();if(this.#De||this.#Ce)throw Ot;this.#Ce=!0;const n={replace:!0};try{const i=t.matchPath(e);let a;if(i)a=await this.navigateToState(i,void 0,n,!1);else{if(!r.allowNotFound){const r=new Tt(m.ROUTE_NOT_FOUND,{path:e});throw t.hasListeners(E.TRANSITION_ERROR)&&t.invokeEventListeners(E.TRANSITION_ERROR,void 0,void 0,r),r}{const r=t.makeNotFoundState(e,n);a=await this.navigateToState(r,void 0,n,!1)}}return this.#De=!0,t.invokeEventListeners(E.ROUTER_START),t.invokeEventListeners(E.TRANSITION_SUCCESS,a,void 0,{replace:!0}),a}catch(e){throw this.#Ce=!1,e}}stop(){const e=this.#p;this.#Ce=!1,this.#De&&(this.#De=!1,e.setState(),e.invokeEventListeners(E.ROUTER_STOP))}},Dt=class{#je;#Me;get#ke(){if(!this.#je)throw new Error("[real-router] CloneNamespace: getCloneData not initialized");return this.#je}get#Fe(){if(!this.#Me)throw new Error("[real-router] CloneNamespace: applyConfig not initialized");return this.#Me}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 ${p(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[router.clone] Getters not allowed in dependencies: "${t}"`)}}setCallbacks(e,t){this.#je=e,this.#Me=t}clone(e,t){const r=this.#ke(),n={...r.dependencies,...e},i=t(r.routes,r.options,n);for(const[e,t]of Object.entries(r.canDeactivateFactories))i.addDeactivateGuard(e,t);for(const[e,t]of Object.entries(r.canActivateFactories))i.addActivateGuard(e,t);return r.middlewareFactories.length>0&&i.useMiddleware(...r.middlewareFactories),r.pluginFactories.length>0&&i.usePlugin(...r.pluginFactories),this.#Fe(i,r.routeConfig,r.resolvedForwardMap),i}},Ct=new Set(["all","warn-error","error-only"]);var jt=class t{#c;#t;#e;#Ie;#Le;#xe;#_e;#Ue;#S;#Ve;#ze;#Ge;#oe;constructor(t=[],r={},n={}){r.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)||!Ct.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}(r.logger)&&(e.logger.configure(r.logger),delete r.logger),G.validateOptions(r,"constructor");const i=r.noValidate??!1;i||C.validateDependenciesObject(n,"constructor"),!i&&t.length>0&&(pt.validateAddRouteArgs(t),pt.validateRoutes(t)),this.#c=new G(r),this.#t=function(e={}){return{...A,...e}}(r.limits),this.#e=new C(n),this.#Ie=new k,this.#Le=new W,this.#xe=new pt(t,i,function(e){return{strictTrailingSlash:"strict"===e.trailingSlash,strictQueryParams:"strict"===e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding,queryParams:e.queryParams??{}}}(this.#c.get())),this.#_e=new Y,this.#Ue=new H,this.#S=new Z,this.#Ve=new Pt,this.#ze=new Nt,this.#Ge=new Dt,this.#oe=i,this.#qe(),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.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){const t=Array.isArray(e)?e:[e];return this.#oe||(pt.validateAddRouteArgs(t),pt.validateRoutes(t,this.#xe.getTree(),this.#xe.getForwardRecord())),this.#xe.addRoutes(t),this}removeRoute(t){return this.#oe||pt.validateRemoveRouteArgs(t),this.#xe.validateRemoveRoute(t,this.#Le.get()?.name,this.#Ve.isNavigating())?(this.#xe.removeRoute(t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),this):this}clearRoutes(){return this.#xe.validateClearRoutes(this.#Ve.isNavigating())?(this.#xe.clearRoutes(),this.#_e.clearAll(),this.#Le.set(void 0),this):this}getRoute(e){return this.#oe||f(e,"getRoute"),this.#xe.getRoute(e)}hasRoute(e){return this.#oe||f(e,"hasRoute"),this.#xe.hasRoute(e)}updateRoute(t,r){this.#oe||pt.validateUpdateRouteBasicArgs(t,r);const{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:o,canActivate:s,canDeactivate:c}=r;return this.#oe||pt.validateUpdateRoutePropertyTypes(n,i,a,o),this.#Ve.isNavigating()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),this.#oe||this.#xe.validateUpdateRoute(t,n),this.#xe.updateRouteConfig(t,{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:o}),void 0!==s&&(null===s?this.#_e.clearCanActivate(t):this.addActivateGuard(t,s)),void 0!==c&&(null===c?this.#_e.clearCanDeactivate(t):this.addDeactivateGuard(t,c)),this}isActiveRoute(t,r,n,i){return this.#oe||pt.validateIsActiveRouteArgs(t,r,n,i),""===t?(e.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#xe.isActiveRoute(t,r,n,i)}buildPath(e,t){return this.#oe||pt.validateBuildPathArgs(e),this.#xe.buildPath(e,t,this.#c.get())}matchPath(e,t){return this.#oe||pt.validateMatchPathArgs(e),this.#xe.matchPath(e,t,this.#c.get())}setRootPath(e){this.#oe||pt.validateSetRootPathArgs(e),this.#xe.setRootPath(e)}getRootPath(){return this.#xe.getRootPath()}makeState(e,t,r,n,i){return this.#oe||W.validateMakeStateArgs(e,t,r,i),this.#Le.makeState(e,t,r,n,i)}getState(){return this.#Le.get()}getPreviousState(){return this.#Le.getPrevious()}areStatesEqual(e,t,r=!0){return this.#oe||W.validateAreStatesEqualArgs(e,t,r),this.#Le.areStatesEqual(e,t,r)}forwardState(e,t){return this.#oe||pt.validateStateBuilderArgs(e,t,"forwardState"),this.#xe.forwardState(e,t)}buildState(e,t){this.#oe||pt.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:n}=this.forwardState(e,t);return this.#xe.buildStateResolved(r,n)}buildNavigationState(e,t={}){this.#oe||pt.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.#oe||pt.validateShouldUpdateNodeArgs(e),this.#xe.shouldUpdateNode(e)}getOptions(){return this.#c.get()}isActive(){return this.#ze.isActive()}start(e){return this.#oe||Nt.validateStartArgs([e]),this.#ze.start(e)}stop(){return this.#ze.stop(),this}addDeactivateGuard(e,t){this.#oe||(f(e,"addDeactivateGuard"),Y.validateHandler(t,"addDeactivateGuard"),Y.validateNotRegistering(this.#_e.isRegistering(e),e,"addDeactivateGuard"));const r=this.#_e.hasCanDeactivate(e);return r||this.#oe||Y.validateHandlerLimit(this.#_e.countCanDeactivate()+1,"addDeactivateGuard",this.#t.maxLifecycleHandlers),this.#_e.registerCanDeactivate(e,t,r),this}addActivateGuard(e,t){this.#oe||(f(e,"addActivateGuard"),Y.validateHandler(t,"addActivateGuard"),Y.validateNotRegistering(this.#_e.isRegistering(e),e,"addActivateGuard"));const r=this.#_e.hasCanActivate(e);return r||this.#oe||Y.validateHandlerLimit(this.#_e.countCanActivate()+1,"addActivateGuard",this.#t.maxLifecycleHandlers),this.#_e.registerCanActivate(e,t,r),this}removeActivateGuard(e){this.#oe||f(e,"removeActivateGuard"),this.#_e.clearCanActivate(e)}removeDeactivateGuard(e){this.#oe||f(e,"removeDeactivateGuard"),this.#_e.clearCanDeactivate(e)}canNavigateTo(e,t){if(this.#oe||f(e,"canNavigateTo"),!this.hasRoute(e))return!1;const{name:r,params:n}=this.forwardState(e,t??{}),i=this.makeState(r,n),a=this.getState(),{toDeactivate:o,toActivate:s}=ht(i,a);for(const e of o)if(!this.#_e.checkDeactivateGuardSync(e,i,a))return!1;for(const e of s)if(!this.#_e.checkActivateGuardSync(e,i,a))return!1;return!0}usePlugin(...e){return this.#oe||(Z.validateUsePluginArgs(e),Z.validatePluginLimit(this.#S.count(),e.length,this.#t.maxPlugins),Z.validateNoDuplicatePlugins(e,this.#S.has.bind(this.#S))),this.#S.use(...e)}useMiddleware(...e){this.#oe||(H.validateUseMiddlewareArgs(e),H.validateNoDuplicates(e,this.#Ue.getFactories()),H.validateMiddlewareLimit(this.#Ue.count(),e.length,this.#t.maxMiddleware));const t=this.#Ue.initialize(...e);if(!this.#oe)for(const{middleware:e,factory:r}of t)H.validateMiddleware(e,r);return this.#Ue.commit(t)}setDependency(e,t){return this.#oe||C.validateSetDependencyArgs(e),this.#e.set(e,t),this}setDependencies(e){return this.#oe||(C.validateDependenciesObject(e,"setDependencies"),C.validateDependencyLimit(this.#e.count(),Object.keys(e).length,"setDependencies",this.#t.maxDependencies)),this.#e.setMultiple(e),this}getDependency(e){this.#oe||C.validateName(e,"getDependency");const t=this.#e.get(e);return this.#oe||C.validateDependencyExists(t,e),t}getDependencies(){return this.#e.getAll()}removeDependency(e){return this.#oe||C.validateName(e,"removeDependency"),this.#e.remove(e),this}hasDependency(e){return this.#oe||C.validateName(e,"hasDependency"),this.#e.has(e)}resetDependencies(){return this.#e.reset(),this}addEventListener(e,t){return this.#oe||k.validateListenerArgs(e,t),this.#Ie.addEventListener(e,t)}navigate(e,t,r){this.#oe||Pt.validateNavigateArgs(e);const n=r??{};return this.#oe||Pt.validateNavigationOptions(n,"navigate"),this.#Ve.navigate(e,t??{},n)}navigateToDefault(e){this.#oe||Pt.validateNavigateToDefaultArgs(e);const t=e??{};return this.#oe||Pt.validateNavigationOptions(t,"navigateToDefault"),this.#Ve.navigateToDefault(t)}navigateToState(e,t,r,n){return this.#oe||Pt.validateNavigateToStateArgs(e,t,r,n),this.#Ve.navigateToState(e,t,r,n)}cancel(){this.#Ve.cancel()}subscribe(e){return this.#oe||k.validateSubscribeListener(e),this.#Ie.subscribe(e)}clone(e){return this.#oe||Dt.validateCloneArgs(e),this.#Ge.clone(e,(e,r,n)=>new t(e,r,n))}#qe(){this.#e.setLimits(this.#t),this.#S.setLimits(this.#t),this.#Ue.setLimits(this.#t),this.#Ie.setLimits(this.#t),this.#_e.setLimits(this.#t),this.#_e.setRouter(this),this.#_e.setDependencies({getDependency:e=>this.#e.get(e)}),this.#xe.setDependencies({addActivateGuard:(e,t)=>{this.addActivateGuard(e,t)},addDeactivateGuard:(e,t)=>{this.addDeactivateGuard(e,t)},makeState:(e,t,r,n)=>this.#Le.makeState(e,t,r,n),getState:()=>this.#Le.get(),areStatesEqual:(e,t,r)=>this.#Le.areStatesEqual(e,t,r),getDependency:e=>this.#e.get(e),forwardState:(e,t)=>this.forwardState(e,t)}),this.#xe.setLifecycleNamespace(this.#_e),this.#Ue.setRouter(this),this.#Ue.setDependencies({getDependency:e=>this.#e.get(e)}),this.#S.setRouter(this),this.#S.setDependencies({addEventListener:(e,t)=>this.#Ie.addEventListener(e,t),isStarted:()=>this.#ze.isStarted(),getDependency:e=>this.#e.get(e)}),this.#Ve.setDependencies({getOptions:()=>this.#c.get(),hasRoute:e=>this.#xe.hasRoute(e),getState:()=>this.#Le.get(),setState:e=>{this.#Le.set(e)},buildStateWithSegments:(e,t)=>{const{name:r,params:n}=this.forwardState(e,t);return this.#xe.buildStateWithSegmentsResolved(r,n)},makeState:(e,t,r,n)=>this.#Le.makeState(e,t,r,n),buildPath:(e,t)=>this.#xe.buildPath(e,t,this.#c.get()),areStatesEqual:(e,t,r)=>this.#Le.areStatesEqual(e,t,r),invokeEventListeners:(e,t,r,n)=>{this.#Ie.invoke(e,t,r,n)},getDependency:e=>this.#e.get(e)}),this.#Ve.setTransitionDependencies({getLifecycleFunctions:()=>this.#_e.getFunctions(),getMiddlewareFunctions:()=>this.#Ue.getFunctions(),isActive:()=>this.#ze.isActive(),clearCanDeactivate:e=>{this.#_e.clearCanDeactivate(e)}}),this.#ze.setDependencies({getOptions:()=>this.#c.get(),hasListeners:e=>this.#Ie.hasListeners(e),invokeEventListeners:(e,t,r,n)=>{this.#Ie.invoke(e,t,r,n)},makeNotFoundState:(e,t)=>this.#Le.makeNotFoundState(e,t),setState:e=>{this.#Le.set(e)},matchPath:(e,t)=>this.#xe.matchPath(e,t,this.#c.get())}),this.#Le.setDependencies({getDefaultParams:()=>this.#xe.getConfig().defaultParams,buildPath:(e,t)=>this.#xe.buildPath(e,t,this.#c.get()),getUrlParams:e=>this.#xe.getUrlParams(e)}),this.#Ve.isRouterStarted=()=>this.#ze.isStarted(),this.#ze.navigateToState=(e,t,r,n)=>this.#Ve.navigateToState(e,t,r,n),this.#Ge.setCallbacks(()=>{const[e,t]=this.#_e.getFactories();return{routes:this.#xe.cloneRoutes(),options:{...this.#c.get()},dependencies:this.#e.getAll(),canDeactivateFactories:e,canActivateFactories:t,middlewareFactories:this.#Ue.getFactories(),pluginFactories:this.#S.getAll(),routeConfig:this.#xe.getConfig(),resolvedForwardMap:this.#xe.getResolvedForwardMap()}},(e,t,r)=>{const n=e,i=n.#xe.getConfig();Object.assign(i.decoders,t.decoders),Object.assign(i.encoders,t.encoders),Object.assign(i.defaultParams,t.defaultParams),Object.assign(i.forwardMap,t.forwardMap),Object.assign(i.forwardFnMap,t.forwardFnMap),n.#xe.setResolvedForwardMap({...r})})}};exports.Router=jt,exports.RouterError=Tt,exports.constants=v,exports.createRouter=(e=[],t={},r={})=>new jt(e,t,r),exports.errorCodes=m,exports.events=E,exports.getNavigator=e=>Object.freeze({navigate:e.navigate,getState:e.getState,isActiveRoute:e.isActiveRoute,canNavigateTo:e.canNavigateTo,subscribe:e.subscribe});//# sourceMappingURL=index.js.map