@real-router/core 0.9.0 → 0.11.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 +0 -8
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/metafile-cjs.json +1 -1
- package/dist/esm/index.d.mts +1 -2
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/metafile-esm.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -391,14 +391,6 @@ Get a single router option by name.\
|
|
|
391
391
|
Returns: option value\
|
|
392
392
|
[Wiki](https://github.com/greydragon888/real-router/wiki/getOption)
|
|
393
393
|
|
|
394
|
-
#### `router.setOption(name: string, value: unknown): void`
|
|
395
|
-
|
|
396
|
-
Set a router option. Must be called before `start()`.\
|
|
397
|
-
`name: string` — option name\
|
|
398
|
-
`value: unknown` — option value\
|
|
399
|
-
Returns: `void`\
|
|
400
|
-
[Wiki](https://github.com/greydragon888/real-router/wiki/setOption)
|
|
401
|
-
|
|
402
394
|
---
|
|
403
395
|
|
|
404
396
|
### Other
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -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,
|
|
37
|
+
* - OptionsNamespace: getOptions, getOption (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
|
shouldUpdateNode(nodeName: string): (toState: State, fromState?: State) => boolean;
|
|
77
77
|
getOptions(): Options;
|
|
78
78
|
getOption<K extends keyof Options>(option: K): Options[K];
|
|
79
|
-
setOption(option: keyof Options, value: Options[keyof Options]): this;
|
|
80
79
|
isActive(): boolean;
|
|
81
80
|
start(...args: [] | [done: DoneFn] | [startPathOrState: string | State] | [startPathOrState: string | State, done: DoneFn]): this;
|
|
82
81
|
stop(): this;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=require("@real-router/logger"),t=["replace","reload","skipTransition","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 l(e){return"string"==typeof e}function u(e){return"boolean"==typeof e}function d(e,t){return e in t}function h(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 f(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 p(e,t){if(!c(e))throw new TypeError(`[${t}] Invalid state structure: ${f(e)}. Expected State object with name, params, and path properties.`)}var g=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"}),m={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},v="onStart",w="onStop",y="onTransitionStart",b="onTransitionCancel",T="onTransitionSuccess",S="onTransitionError",R={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},E={maxDependencies:100,maxPlugins:50,maxMiddleware:50,maxListeners:1e4,maxEventDepth:5,maxLifecycleHandlers:200},A={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}},O=new WeakSet;function $(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)$(t);else for(const t in e)$(e[t])}function P(e){return e?(O.has(e)||($(e),O.add(e)),e):e}function N(e){switch(e){case"never":return"never";case"always":return"always";default:return"default"}}function C(e){const t={trailingSlashMode:N(e.trailingSlash),queryParamsMode:e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding};return void 0!==e.queryParams&&(t.queryParams=e.queryParams),t}function D(e){return{warn:Math.floor(.2*e),error:Math.floor(.5*e)}}var j=class{#e=Object.create(null);#t=E;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 ${f(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=E.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: "${f(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.`)}},k=new Set([R.ROUTER_START,R.TRANSITION_START,R.TRANSITION_SUCCESS,R.TRANSITION_ERROR,R.TRANSITION_CANCEL,R.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 I=class t{#n={};#i=null;#t=E;static validateEventName(e){if(!k.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 R.TRANSITION_START:case R.TRANSITION_CANCEL:M(e,this.#s(e),t,r);break;case R.TRANSITION_ERROR:case R.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(R.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??={[R.ROUTER_START]:0,[R.TRANSITION_START]:0,[R.TRANSITION_SUCCESS]:0,[R.TRANSITION_ERROR]:0,[R.TRANSITION_CANCEL]:0,[R.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}`)}},x={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},F={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"]},_=new Set(["defaultRoute","defaultParams"]);function U(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&U(r)}return e}function z(e,t,r){const n=x[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 ${f(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(!d(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 F&&function(e,t,r){const n=F[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(A,r))throw new TypeError(`[router.${t}]: unknown limit: "${r}"`);void 0!==n&&q(r,n,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function q(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=A[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 W=class{#c;#l=!1;constructor(e={}){this.#c=U({...x,...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(x,e))throw new ReferenceError(`[router.${t}]: option "${e}" not found`)}(e,t)}static validateNotLocked(e,t){!function(e,t){if(e&&!_.has(t))throw new Error("[router.setOption] Options cannot be changed after router.start(). Only defaultRoute/defaultParams can be changed after start.")}(e,t)}static validateOptionValue(e,t,r){z(e,t,r)}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 ${f(e)}`);for(const[r,n]of Object.entries(e))d(r,x)?void 0!==n&&z(r,n,t):V(r,n,t)}(e,t)}get(){return this.#c}getOption(e){return this.#c[e]}set(e,t){const r=t&&"object"==typeof t&&t.constructor===Object?{...t}:t;this.#c=U({...this.#c,[e]:r})}isLocked(){return this.#l}lock(){this.#l=!0}unlock(){this.#l=!1}};function B(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>B(e,t[r]))}var H=class{#u=0;#d=void 0;#h=void 0;#f;#p=new Map;get#g(){if(!this.#f)throw new Error("[real-router] StateNamespace: dependencies not initialized");return this.#f}static validateMakeStateArgs(e,t,r,n){if(!l(e))throw new TypeError(`[router.makeState] Invalid name: ${f(e)}. Expected string.`);if(void 0!==t&&!s(t))throw new TypeError(`[router.makeState] Invalid params: ${f(t)}. Expected plain object.`);if(void 0!==r&&!l(r))throw new TypeError(`[router.makeState] Invalid path: ${f(r)}. Expected string.`);if(void 0!==n&&"number"!=typeof n)throw new TypeError(`[router.makeState] Invalid forceId: ${f(n)}. Expected number.`)}static validateAreStatesEqualArgs(e,t,r){if(null!=e&&p(e,"areStatesEqual"),null!=t&&p(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${f(r)}. Expected boolean.`)}get(){return this.#d}set(e){this.#h=this.#d,e?Object.isFrozen(e)?this.#d=e:this.#d=P(e):this.#d=void 0}getPrevious(){return this.#h}setDependencies(e){this.#f=e}makeState(e,t,r,n,i){const a=n?{...n,id:i??++this.#u,params:n.params,options:n.options,redirected:n.redirected}:void 0,o=this.#g.getDefaultParams();let s;return s=Object.hasOwn(o,e)?{...o[e],...t}:t?{...t}:{},P({name:e,params:s,path:r??this.#g.buildPath(e,t),meta:a})}makeNotFoundState(e,t){return this.makeState(m.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.#m(e.name)).every(r=>B(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&&B(e.params[r],t.params[r]))}#m(e){const t=this.#p.get(e);if(void 0!==t)return t;const r=this.#g.getUrlParams(e);return this.#p.set(e,r),r}};function Q(e){return e.name||"anonymous"}var G=class{#v=new Set;#w=new Map;#y;#f;#t=E;get#b(){if(!this.#y)throw new Error("[real-router] MiddlewareNamespace: router not initialized");return this.#y}get#g(){if(!this.#f)throw new Error("[real-router] MiddlewareNamespace: dependencies not initialized");return this.#f}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 ${f(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 ${f(e)}. Factory: ${Q(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: ${Q(t)}`)}(e,t)}static validateMiddlewareLimit(e,t,r){!function(e,t,r=E.maxMiddleware){if(0!==r&&e+t>r)throw new Error(`[router.useMiddleware] Middleware limit exceeded (${r}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating middleware.`)}(e,t,r)}setRouter(e){this.#y=e}setDependencies(e){this.#f=e}setLimits(e){this.#t=e}count(){return this.#v.size}initialize(...e){const t=[];for(const r of e){const e=r(this.#b,this.#g.getDependency);t.push({factory:r,middleware:e})}return t}commit(e){this.#T(e.length);for(const{factory:t,middleware:r}of e)this.#v.add(t),this.#w.set(t,r);let t=!1;return()=>{if(!t){t=!0;for(const{factory:t}of e)this.#v.delete(t),this.#w.delete(t)}}}clear(){this.#v.clear(),this.#w.clear()}getFactories(){return[...this.#v]}getFunctions(){return[...this.#w.values()]}#T(t){const r=this.#t.maxMiddleware;if(0===r)return;const n=t+this.#v.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.`)}},K={[v]:R.ROUTER_START,[w]:R.ROUTER_STOP,[T]:R.TRANSITION_SUCCESS,[y]:R.TRANSITION_START,[S]:R.TRANSITION_ERROR,[b]:R.TRANSITION_CANCEL},Z=Object.keys(K).filter(e=>d(e,K)),J="router.usePlugin",Y=class t{#S=new Set;#y;#f;#t=E;get#b(){if(!this.#y)throw new Error("[real-router] PluginsNamespace: router not initialized");return this.#y}get#g(){if(!this.#f)throw new Error("[real-router] PluginsNamespace: dependencies not initialized");return this.#f}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 ${f(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&&!d(t,K))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=E.maxPlugins){if(0!==r&&e+t>r)throw new Error(`[router.usePlugin] Plugin limit exceeded (${r})`)}(e,t,r)}static validateNoDuplicatePlugins(e,t){for(const r of e)if(t(r))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setRouter(e){this.#y=e}setDependencies(e){this.#f=e}setLimits(e){this.#t=e}count(){return this.#S.size}use(...t){if(this.#T(t.length),1===t.length){const r=t[0],n=this.#R(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.#E(t),n=[];try{for(const e of r){const t=this.#R(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)}#T(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`)}#E(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}#R(r){const n=r(this.#b,this.#g.getDependency);t.validatePlugin(n),Object.freeze(n);const i=[];for(const t of Z)t in n&&("function"==typeof n[t]?(i.push(this.#g.addEventListener(K[t],n[t])),"onStart"===t&&this.#g.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()}}},X=class{#A=new Map;#O=new Map;#$=new Map;#P=new Map;#N=new Set;#y;#f;#t=E;get#b(){if(!this.#y)throw new Error("[real-router] RouteLifecycleNamespace: router not initialized");return this.#y}get#g(){if(!this.#f)throw new Error("[real-router] RouteLifecycleNamespace: dependencies not initialized");return this.#f}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 ${f(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=E.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.#y=e}setDependencies(e){this.#f=e}setLimits(e){this.#t=e}isRegistering(e){return this.#N.has(e)}countCanActivate(){return this.#O.size}countCanDeactivate(){return this.#A.size}hasCanActivate(e){return this.#O.has(e)}hasCanDeactivate(e){return this.#A.has(e)}registerCanActivate(e,t,r){this.#C("activate",e,t,this.#O,this.#P,"canActivate",r)}registerCanDeactivate(e,t,r){this.#C("deactivate",e,t,this.#A,this.#$,"canDeactivate",r)}clearCanActivate(e,t=!1){this.#O.delete(e),this.#P.delete(e)}clearCanDeactivate(e,t=!1){this.#A.delete(e),this.#$.delete(e)}clearAll(){this.#O.clear(),this.#P.clear(),this.#A.clear(),this.#$.clear()}getFactories(){const e={},t={};for(const[t,r]of this.#A)e[t]=r;for(const[e,r]of this.#O)t[e]=r;return[e,t]}getFunctions(){return[this.#$,this.#P]}#C(t,r,n,i,a,o,s){s?e.logger.warn(`router.${o}`,`Overwriting existing ${t} handler for route "${r}"`):this.#T(i.size+1,o);const c=u(n)?function(e){const t=()=>e;return()=>t}(n):n;i.set(r,c),this.#N.add(r);try{const e=c(this.#b,this.#g.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${o}] Factory must return a function, got ${f(e)}`);a.set(r,e)}catch(e){throw i.delete(r),e}finally{this.#N.delete(r)}}#T(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 ee(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=ee(t,a);a.children.push(e)}return a}function te(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 t=r[e];n=n.children.find(e=>e.name===t)}return{parent:n,finalName:r.at(-1)}}function re(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var ne=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,ie=/\?(.+)$/;function ae(e,t,r){const n=[],i=[],a=function(e){const t=[],r=[],n=[],i={},a=new Map,o=ie.exec(e);if(null!==o){const t=o[1].split("&");for(const e of t){const t=e.trim();t.length>0&&(r.push(t),i[t]="query")}e=e.slice(0,o.index)}let s;for(;null!==(s=ne.exec(e));){const e=s[2],r=s[3];if("*"===s[1])n.push(e),t.push(e),i[e]="url";else if(t.push(e),i[e]="url",r){const t=`^${re(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),o={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:new Map,paramMeta:a,nonAbsoluteChildren:[],fullName:"",staticPath:null,paramTypeMap:{}};for(const e of a.urlParams)o.paramTypeMap[e]="url";for(const e of a.queryParams)o.paramTypeMap[e]="query";o.fullName=function(e){return e.parent?.name?`${e.parent.fullName}.${e.name}`:e.name}(o);for(const t of e.children){const e=ae(t,o,r);n.push(e),e.absolute||i.push(e)}return o.children=function(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}(n),o.nonAbsoluteChildren=i,o.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.push(a),a=a.parent;i.reverse();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:o+e.path}return o=e.absolute?e.path:o+e.path,o.replaceAll(/\/{2,}/g,"/")}(o),r&&(Object.freeze(o.nonAbsoluteChildren),Object.freeze(o.paramTypeMap),Object.freeze(o.children),Object.freeze(o)),o}function oe(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=ee({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=ee(e,n);n.children.push(t)}else i.push(e);for(const e of i){const{parent:t,finalName:r}=te(n,e.name),i=ee({name:r,path:e.path,children:e.children},t);t.children.push(i)}return n}(e,t,r);return function(e,t=!0){return ae(e,null,t)}(i,!n?.skipFreeze)}}}function se(e,t,r,n){return oe(e,t).addMany(r).build(n)}var ce=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)},le=e=>encodeURIComponent(e),ue={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${le(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${le(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${le(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>le(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}},he={default:{encode:e=>e},hidden:{encode:()=>""}},fe=(e,t,r)=>({boolean:de[t],null:he[r],array:ue[e]}),pe={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:de.none,null:he.default,array:ue.none}},ge=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return pe;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:fe(t,r,n)}},me=e=>encodeURIComponent(e),ve=(e,t,r)=>{const n=me(e);switch(typeof t){case"string":case"number":default:return`${n}=${me(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}=${me(t)}`}};function we(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:l}=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,ce(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=ce(e);return t.boolean.decodeValue(n)})(n?e.slice(t+1,r):void 0,i):n?ce(e.slice(t+1,r)):null}(e,a,r,o,i),l)}function ye(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}function be(e,t,r){for(const[n,{pattern:i,constraint:a}]of t){const t=String(e[n]);if(!i.test(t)){const e=a?a.replaceAll(/(^<)|(>$)/g,""):"[^/]+";throw new Error(`Parameter '${n}' of '${r}' has invalid format: got '${t}', expected to match '${e}'`)}}}var Te=/[^\w!$'()*+,.:;|~-]/gu,Se=/[^\w!$'()*+,.:;|~-]/u,Re={default:e=>Se.test(e)?e.replaceAll(Te,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},Ee={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e},Ae=(e,t,r)=>{const n=Re[t],i=String(e);if(!r)return n(i);const a=i.split("/");let o=n(a[0]);for(let e=1;e<a.length;e++)o+="/"+n(a[e]);return o},Oe=/(\/|^)([:*][^/?<]*)(<[^>]+>)?(\?)?(?=[/.]|$)/g;function $e(e,t){return e.replaceAll(Oe,(e,r,n,i,a)=>{const o=n.startsWith("*");let s;s=o?n.length>1?n.slice(1):"wild":n.slice(1);const c=t[s];return void 0!==c?r+c:void 0!==a||o?"":r+n})}var Pe=class extends Error{constructor(e){super(e),this.name="RouteNodeError",Object.setPrototypeOf(this,new.target.prototype)}},Ne=class extends Pe{routeName;constructor(e,t){super(e),this.name="RouteNotFoundError",this.routeName=t}},Ce=Object.freeze([]);function De(e,t,r){const{queryParamsMode:n="default",trailingSlashMode:i="default"}=r,a=function(e){let t=null,r=null;for(const n of e){const{queryParams:e,urlParams:i,spatParams:a}=n.paramMeta;if(e.length>0){t??=[];for(const r of e)t.push(r)}if(i.length>0||a.length>0){r??=[];for(const e of i)r.push(e);for(const e of a)r.push(e)}}return{searchParams:t??Ce,nonSearchParams:r??Ce}}(e),o=function(e,t,r){if("loose"!==r)return e.searchParams;const n=[...e.searchParams],i=new Set(e.searchParams),a=new Set(e.nonSearchParams);for(const e in t)!Object.hasOwn(t,e)||i.has(e)||a.has(e)||n.push(e);return n}(a,t,n),s=function(e,t,r){const n={};for(const r of e)r in t&&(n[r]=t[r]);return((e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=ge(t),i=[];for(const t of r){const r=e[t];if(void 0===r)continue;const a=ve(t,r,n);a&&i.push(a)}return i.join("&")})(n,r.queryParams)}(o,t,r),c=function(e,t,r){let n="";const i=r.urlParamsEncoding??"default",a=r.ignoreConstraints??!1;for(const r of e){const{constraintPatterns:e,urlParams:o,spatParams:s}=r.paramMeta;e.size>0&&!a&&be(t,e,r.path);const c=je(t,o,s,i),l=$e(r.paramMeta.pathPattern,c);n=r.absolute?l:n+l}return n.includes("//")?n.replaceAll(/\/{2,}/g,"/"):n}(e,t,r);return l=c,("always"===(u=i)?l.endsWith("/")?l:`${l}/`:"never"===u&&"/"!==l&&l.endsWith("/")?l.slice(0,-1):l)+(s?`?${s}`:"");var l,u}function je(e,t,r,n){const i={};for(const a of t){const t=e[a];if(null!=t){const e=r.includes(a),o="object"==typeof t?JSON.stringify(t):String(t);i[a]=Ae(o,n,e)}}return i}function ke(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=>ke(e))),t}var Me=(()=>{const e=function(){};return e.prototype=Object.create(null),Object.freeze(e.prototype),e})();function Ie(e){const[t,...r]=e.split("/");return""===r[r.length-1]?r.slice(0,-1):r}function xe(e,t){const r=new Me;for(const[n,i]of t){const t=n<0?e.slice(-(n+1)).join("/"):e[n];if("string"==typeof i)r[i]=t;else{const e=t.match(i);if(e)for(const t in e.groups)r[t]=e.groups[t]}}return r}function Fe(e){const t=e.replace(/:(\w+)/g,(e,t)=>`(?<${t}>[^/]+)`).replace(/\./g,"\\.");return new RegExp(`^${t}$`)}function Le(e,t="",r,n){47===r.charCodeAt(r.length-1)&&(r=r.slice(0,-1));const i=e.static[r];if(i&&i.methods){const e=i.methods[t]||i.methods[""];if(void 0!==e)return e[0]}const a=Ie(r),o=_e(e,e.root,t,a,0)?.[0];if(void 0!==o)return{data:o.data,params:o.paramsMap?xe(a,o.paramsMap):void 0}}function _e(e,t,r,n,i){if(i===n.length){if(t.methods){const e=t.methods[r]||t.methods[""];if(e)return e}if(t.param&&t.param.methods){const e=t.param.methods[r]||t.param.methods[""];if(e){const t=e[0].paramsMap;if(t?.[t?.length-1]?.[2])return e}}if(t.wildcard&&t.wildcard.methods){const e=t.wildcard.methods[r]||t.wildcard.methods[""];if(e){const t=e[0].paramsMap;if(t?.[t?.length-1]?.[2])return e}}return}const a=n[i];if(t.static){const o=t.static[a];if(o){const t=_e(e,o,r,n,i+1);if(t)return t}}if(t.param){const o=_e(e,t.param,r,n,i+1);if(o){if(t.param.hasRegexParam){const e=o.find(e=>e.paramsRegexp[i]?.test(a))||o.find(e=>!e.paramsRegexp[i]);return e?[e]:void 0}return o}}if(t.wildcard&&t.wildcard.methods)return t.wildcard.methods[r]||t.wildcard.methods[""]}var Ue=/[\u0080-\uFFFF]/,ze=class{#b=function(){return{root:{key:""},static:new Me}}();#D=new Map;#j=new Map;registerTree(e,t=""){this.#k(e,t,[])}match(e,t){const r=""===e?"/":e;if(!r.startsWith("/")||this.#M(r))return;const n=r.indexOf("?"),i=-1===n?r:r.slice(0,n),a=-1===n?"":r.slice(n+1),o=t?.strictTrailingSlash?i:this.#I(i),s=Le(this.#b,"GET",o);if(!s)return;const c=s.data;if(!this.#x(o,c,t))return;const l=s.params?{...s.params}:{};if(this.#F(l,t?.urlParamsEncoding??"default"),!c.hasConstraints||this.#L(l,c.constraintPatterns,i)){if(a&&!this.#_(l,a,c.declaredQueryParamsSet,t))return;return{segments:c.matchSegments,buildSegments:c.segments,params:l,meta:c.meta}}}getSegmentsByName(e){return this.#D.get(e)}getMetaByName(e){return this.#j.get(e)}hasRoute(e){return this.#D.has(e)}#x(e,t,r){return!r?.strictTrailingSlash||(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#F(e,t){if("none"===t)return;const r=Ee[t];for(const t in e){const n=e[t];"string"==typeof n&&n.includes("%")&&(e[t]=r(n))}}#L(e,t,r){try{return be(e,t,r),!0}catch{return!1}}#_(e,t,r,n){const i=this.#U(t,n?.queryParams);if("strict"!==(n?.queryParamsMode??"default"))return Object.assign(e,i),!0;for(const e of Object.keys(i))if(!r.has(e))return!1;for(const t of r)t in i&&(e[t]=i[t]);return!0}#k(e,t,r){r.push(e);const n=this.#z(e.absolute?"":t,e.path),i=this.#V(n),a=this.#I(i);if(e.fullName){const t=this.#q(r),n=i.length>1&&i.endsWith("/"),o=r.filter(e=>""!==e.path),s=Object.freeze([...o]),c=this.#W(o),l=c?Object.freeze([...o,c]):s,u=this.#B(o),d={};for(const e of l)d[e.fullName]=e.paramTypeMap;const h={matchSegments:l,segments:s,declaredQueryParams:t,hasTrailingSlash:n,hasConstraints:u.size>0,constraintPatterns:u,declaredQueryParamsSet:new Set(t),meta:Object.freeze(d)};this.#D.set(e.fullName,s),this.#j.set(e.fullName,h.meta),function(e,t="",r,n){t=t.toUpperCase(),47!==r.charCodeAt(0)&&(r=`/${r}`);const i=Ie(r=r.replace(/\\:/g,"%3A"));let a=e.root,o=0;const s=[],c=[];for(let e=0;e<i.length;e++){let t=i[e];if(t.startsWith("**")){a.wildcard||(a.wildcard={key:"**"}),a=a.wildcard,s.push([-(e+1),t.split(":")[1]||"_",2===t.length]);break}if("*"===t||t.includes(":")){if(a.param||(a.param={key:"*"}),a=a.param,"*"===t)s.push([e,"_"+o++,!0]);else if(t.includes(":",1)){const r=Fe(t);c[e]=r,a.hasRegexParam=!0,s.push([e,r,!1])}else s.push([e,t.slice(1),!1]);continue}"\\*"===t?t=i[e]="*":"\\*\\*"===t&&(t=i[e]="**");const r=a.static?.[t];if(r)a=r;else{const e={key:t};a.static||(a.static=new Me),a.static[t]=e,a=e}}const l=s.length>0;a.methods||(a.methods=new Me),a.methods[t]??=[],a.methods[t].push({data:n||null,paramsRegexp:c,paramsMap:l?s:void 0}),l||(e.static["/"+i.join("/")]=a)}(this.#b,"GET",a,h)}const o=n;for(const t of e.children.values())this.#k(t,o,r);r.pop()}#q(e){const t=[];for(const r of e)r.paramMeta.queryParams.length>0&&t.push(...r.paramMeta.queryParams);return t}#B(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(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}#z(e,t){if(""===e)return t;if(e.startsWith("?")){if(""===t)return e;const r=t.indexOf("?");if(-1!==r){const n=t.slice(0,r),i=t.slice(r+1);return`${n}?${e.slice(1)}&${i}`}return`${t}${e}`}if(""===t)return e;const r=e.indexOf("?"),n=t.indexOf("?");if(-1!==r){const i=e.slice(0,r),a=e.slice(r+1);return-1!==n?`${i}${t.slice(0,n)}?${a}&${t.slice(n+1)}`:`${i}${t}?${a}`}return-1!==n?e+t.slice(0,n)+t.slice(n):e+t}#V(e){const t=e.indexOf("?");let r=-1===t?e:e.slice(0,t);return r=r.replaceAll(/<[^>]+>/g,""),r=r.replaceAll(/\*([^/?]+)/g,"**:$1"),r=r.replaceAll(/\*(?=[/?]|$)/g,"**"),r}#U(e,t){return((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),we(e,r,i,t),r=i+1}}(e,t),t}(r);const n=ge(t),i={};let a=0;const o=r.length;for(;a<o;){let e=r.indexOf("&",a);-1===e&&(e=o),we(r,a,e,i,n.strategies),a=e+1}return i})(e,t)}#M(e){return Ue.test(e)}#W(e){const t=e.at(-1);if(t)return t.nonAbsoluteChildren.find(e=>""!==e.path&&/^\/(\?|$)/.test(e.path))}};function Ve(e,t){return new TypeError(`[router.${e}] ${t}`)}var qe=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/,We=/\S/;function Be(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function He(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 ${Be(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${Be(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 ${Be(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!We.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("@@")&&!qe.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,Ve(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw Ve(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw Ve(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw Ve(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 new Error(`[router.${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){const n=a.split(".");let i=e;for(const e of n)if(i=i.children.get(e),!i)throw new Error(`[router.${r}] Parent route "${a}" does not exist for route "${t}"`);return}throw new Error(`[router.${r}] Parent route "${a}" does not exist for route "${t}"`)}}(r,c,t,i),r&&c&&function(e,t,r){const n=t.split(".");let i=e;for(const e of n)if(i=i.children.get(e),!i)return;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 l=o.path;let u=n;if(s.includes(".")&&!n){const e=s.split(".");e.pop(),u=e.join(".")}if(r&&function(e,t,r){let n=e;if(""!==t){const e=t.split(".");for(const t of e)if(n=n.children.get(t),!n)return}for(const e of n.children.values())if(e.path===r)throw new Error(`Path "${r}" is already defined`)}(r,u,l),a&&function(e,t,r){const n=e.get(t);if(n?.has(r))throw new Error(`Path "${r}" is already defined`);n?n.add(r):e.set(t,new Set([r]))}(a,u,l),void 0!==o.children){if(!Array.isArray(o.children))throw new TypeError(`[router.${t}] Route "${s}" children must be an array, got ${Be(o.children)}`);for(const e of o.children)He(e,t,r,c,i,a)}}var Qe=new Set;function Ge(e){return{...C(e),strictTrailingSlash:"strict"===e.trailingSlash,strongMatching:!1}}function Ke(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>Ke(e))),t}function Ze(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}.`)&&Ze(i.children,t,a))return!0}return!1}function Je(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function Ye(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 ${f(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 ${f(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 ${f(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(e.children)for(const r of e.children)Ye(r,`${t}.${r.name}`)}function Xe(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 et(e){const t=new Set;for(const r of e)for(const e of Xe(r))t.add(e);return t}function tt(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 tt(i.children,t,e,a)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function rt(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 rt(n.children,e))r.add(t)}return r}function nt(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,i]of nt(n.children,e))r.set(t,i)}return r}function it(e,t,r,n){return t?function(e){const t=new Set;for(const r of e){for(const e of r.paramMeta.urlParams)t.add(e);for(const e of r.paramMeta.spatParams)t.add(e)}return t}(ye(r,e)):et(tt(n,e))}function at(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=et(tt(r,e)),c=[...it(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 ot(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 st(e,t,r){const n=rt(e),i=nt(e),a={...t};for(const[e,t]of i)a[e]=t;for(const[t,a]of i)at(t,a,e,n,r);for(const e of Object.keys(a))ot(e,a)}function ct(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}var lt=".";function ut(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function dt(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 ht(e){if(!e)return[""];const t=e.indexOf(lt);if(-1===t)return[e];const r=e.indexOf(lt,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(lt,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(lt,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(lt),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 ft(e,t){if(!t)return{intersection:"",toActivate:ht(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:ht(e.name),toDeactivate:ut(ht(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:ht(e.name),toDeactivate:ut(ht(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=ht(e.name),a=ht(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=dt(i,e),c=dt(o,t),l=Object.keys(s),u=Object.keys(c);if(l.length!==u.length)return a;for(const e of l)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 pt=Object.freeze({}),gt=class{#H=[];#Q=function(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null)}}();#G=Object.create(null);#K=new Map;#Z="";#J;#Y;#X;#ee;#f;#te;#re;get#g(){if(!this.#f)throw new Error("[real-router] RoutesNamespace: dependencies not initialized");return this.#f}constructor(e=[],t=!1){this.#re=t;for(const t of e)this.#H.push(Ke(t));this.#J=se("",this.#Z,this.#H),this.#Y=new ze,this.#Y.registerTree(this.#J),this.#ne(e),t?this.#ie():this.#ae()}static validateRemoveRouteArgs(e){!function(e){h(e,"removeRoute")}(e)}static validateSetRootPathArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${f(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 ${f(t)}`);Ye(t,t.name)}}(e)}static validateIsActiveRouteArgs(e,t,r,n){!function(e,t,r,n){if(!l(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(!l(e))throw new TypeError(`[router.${r}] Invalid routeName: ${f(e)}. Expected string.`);if(!s(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${f(t)}. Expected plain object.`)}(e,t,r)}static validateUpdateRouteBasicArgs(e,t){!function(e,t){if(h(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 ${f(t)}`)}(e,t)}static validateUpdateRoutePropertyTypes(e,t,r,n){!function(e,t,r,n){if(null!=e&&!l(e))throw new TypeError(`[real-router] updateRoute: forwardTo must be a string or null, got ${f(e)}`);if(null!=t&&("object"!=typeof t||Array.isArray(t)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${f(t)}`);if(null!=r){if("function"!=typeof r)throw new TypeError("[real-router] updateRoute: decodeParams must be a function or null, got "+typeof r);if("AsyncFunction"===r.constructor.name||r.toString().includes("__awaiter"))throw new TypeError("[real-router] updateRoute: decodeParams cannot be an async function")}if(null!=n){if("function"!=typeof n)throw new TypeError("[real-router] updateRoute: encodeParams must be a function or null, got "+typeof n);if("AsyncFunction"===n.constructor.name||n.toString().includes("__awaiter"))throw new TypeError("[real-router] updateRoute: encodeParams cannot be an async function")}}(e,t,r,n)}static validateBuildPathArgs(e){!function(e){if(!l(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(!l(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e)}static validateShouldUpdateNodeArgs(e){!function(e){if(!l(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)He(r,"addRoute",t,"",n,i);t&&r&&st(e,r,t)}(e,t,r)}setDependencies(e){this.#f=e;for(const[t,r]of this.#K)e.canActivate(t,r);this.#K.clear()}setLifecycleNamespace(e){this.#te=e}getRootPath(){return this.#Z}getTree(){return this.#J}getForwardRecord(){return this.#Q.forwardMap}setRootPath(e){this.#Z=e,this.#oe()}hasRoute(e){return this.#Y.hasRoute(e)}getRoute(e){const t=this.#Y.getSegmentsByName(e);if(!t)return;const r=ke(this.#se(t));return this.#ce(r,e)}addRoutes(e){for(const t of e)this.#H.push(Ke(t));this.#ne(e),this.#oe(),this.#le()}removeRoute(e){return!!Ze(this.#H,e)&&(this.#ue(e),this.#oe(),this.#le(),!0)}updateRouteConfig(e,t){if(void 0!==t.forwardTo&&(null===t.forwardTo?delete this.#Q.forwardMap[e]:this.#Q.forwardMap[e]=t.forwardTo,this.#le()),void 0!==t.defaultParams&&(null===t.defaultParams?delete this.#Q.defaultParams[e]:this.#Q.defaultParams[e]=t.defaultParams),void 0!==t.decodeParams)if(null===t.decodeParams)delete this.#Q.decoders[e];else{const r=t.decodeParams;this.#Q.decoders[e]=e=>r(e)??e}if(void 0!==t.encodeParams)if(null===t.encodeParams)delete this.#Q.encoders[e];else{const r=t.encodeParams;this.#Q.encoders[e]=e=>r(e)??e}}clearRoutes(){this.#H.length=0;for(const e in this.#Q.decoders)delete this.#Q.decoders[e];for(const e in this.#Q.encoders)delete this.#Q.encoders[e];for(const e in this.#Q.defaultParams)delete this.#Q.defaultParams[e];for(const e in this.#Q.forwardMap)delete this.#Q.forwardMap[e];for(const e in this.#G)delete this.#G[e];this.#oe()}buildPath(e,t,r,n){if(e===m.UNKNOWN_ROUTE)return l(t?.path)?t.path:"";const i=Object.hasOwn(this.#Q.defaultParams,e)?{...this.#Q.defaultParams[e],...t}:t??{},a="function"==typeof this.#Q.encoders[e]?this.#Q.encoders[e]({...i}):i,o=this.#X??C(r);return function(e,t,r={},n={},i){if(i)return De(i,r,n);const a=function(e){for(const t in e)if(Object.hasOwn(e,t))return!0;return!1}(r),o=function(e){return void 0!==e.trailingSlashMode&&"default"!==e.trailingSlashMode||void 0!==e.queryParamsMode&&"default"!==e.queryParamsMode||void 0!==e.queryParams||void 0!==e.urlParamsEncoding&&"default"!==e.urlParamsEncoding}(n);if(!a&&!o){const r=function(e,t){if(t.includes(".")){const r=ye(e,t),n=r?.at(-1)?.staticPath;return n??null}return e.children.get(t)?.staticPath??null}(e,t);if(null!==r)return r}const s=ye(e,t);if(!s)throw new Ne(`[route-node][buildPath] '${t}' is not defined`,t);return De(s,r,n)}(this.#J,e,a,o,n)}matchPath(e,t,r){const n=r,i=this.#ee??(this.#ee=Ge(n)),a=this.#Y.match(e,i);if(a){const r=ct(a),{name:i,params:o,meta:s}=r,c="function"==typeof this.#Q.decoders[i]?this.#Q.decoders[i](o):o,{name:l,params:u}=this.forwardState(i,c);let d=e;return n.rewritePathOnMatch&&(d=this.buildPath(l,u,n,l===i?a.buildSegments:void 0)),this.#g.makeState(l,u,d,{params:s,options:pt,source:t,redirected:!1})}}forwardState(e,t){const r=this.#G[e]??e,n=Object.hasOwn(this.#Q.defaultParams,e)?{...this.#Q.defaultParams[e],...t}:t;return r!==e&&Object.hasOwn(this.#Q.defaultParams,r)?{name:r,params:{...this.#Q.defaultParams[r],...n}}:{name:r,params:n}}buildStateResolved(e,t){const r=this.#Y.getSegmentsByName(e);if(r)return ct({segments:r,params:t,meta:this.#Y.getMetaByName(e)??{}},e)}buildStateWithSegmentsResolved(e,t){const r=this.#Y.getSegmentsByName(e);if(r)return{state:ct({segments:r,params:t,meta:this.#Y.getMetaByName(e)??{}},e),segments:r}}initBuildOptionsCache(e){this.#X=C(e),this.#ee=Ge(e)}clearBuildOptionsCache(){this.#X=void 0,this.#ee=void 0}isActiveRoute(e,t={},r=!1,n=!0){Qe.has(e)||(h(e,"isActiveRoute"),Qe.add(e));const i=this.#g.getState();if(!i)return!1;const a=i.name;if(a!==e&&!a.startsWith(`${e}.`)&&!e.startsWith(`${a}.`))return!1;const o=this.#Q.defaultParams[e];if(r||a===e){const r=o?{...o,...t}:t;return this.#g.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}=ft(t,r);return e===n||!!i.includes(e)||a.includes(e)}}getConfig(){return this.#Q}getUrlParams(e){const t=this.#Y.getSegmentsByName(e);return t?this.#de(t):[]}getResolvedForwardMap(){return this.#G}setResolvedForwardMap(e){Object.assign(this.#G,e)}cloneRoutes(){return[...this.#J.children.values()].map(e=>ke(e))}validateForwardToParamCompatibility(e,t){const r="validateForwardToParamCompatibility",n=this.#he(e,r),i=this.#he(t,r),a=this.#fe(n),o=this.#de(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){ot(e,{...this.#Q.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){if(!this.hasRoute(t))throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);this.validateForwardToParamCompatibility(e,t),this.validateForwardToCycle(e,t)}}#oe(){this.#J=se("",this.#Z,this.#H),this.#Y=new ze,this.#Y.registerTree(this.#J)}#he(e,t){const r=this.#Y.getSegmentsByName(e);if(!r)throw new ReferenceError(`[real-router] ${t}: route "${e}" does not exist`);return r}#se(e){const t=e.at(-1);if(!t)throw new Error("[real-router] Internal error: empty segments array");return t}#fe(e){const t=new Set;for(const r of e)for(const e of r.paramMeta.urlParams)t.add(e);return t}#de(e){const t=[];for(const r of e)for(const e of r.paramMeta.urlParams)t.push(e);return t}#le(){this.#re?this.#ie():this.#ae()}#ae(){for(const e in this.#G)delete this.#G[e];for(const e of Object.keys(this.#Q.forwardMap))this.#G[e]=ot(e,this.#Q.forwardMap)}#ie(){for(const e in this.#G)delete this.#G[e];for(const e of Object.keys(this.#Q.forwardMap)){let t=e;for(;this.#Q.forwardMap[t];)t=this.#Q.forwardMap[t];this.#G[e]=t}}#ue(e){const t=t=>t===e||t.startsWith(`${e}.`);if(Je(this.#Q.decoders,t),Je(this.#Q.encoders,t),Je(this.#Q.defaultParams,t),Je(this.#Q.forwardMap,t),Je(this.#Q.forwardMap,e=>t(this.#Q.forwardMap[e])),this.#te){const[e,r]=this.#te.getFactories();for(const e of Object.keys(r))t(e)&&this.#te.clearCanActivate(e,!0);for(const r of Object.keys(e))t(r)&&this.#te.clearCanDeactivate(r,!0)}}#ne(e,t=""){for(const r of e){const e=t?`${t}.${r.name}`:r.name;this.#pe(r,e),r.children&&this.#ne(r.children,e)}}#pe(e,t){e.canActivate&&(this.#f?this.#f.canActivate(t,e.canActivate):this.#K.set(t,e.canActivate)),e.forwardTo&&this.#ge(e,t),e.decodeParams&&(this.#Q.decoders[t]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(this.#Q.encoders[t]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(this.#Q.defaultParams[t]=e.defaultParams)}#ge(t,r){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 "${t.forwardTo}".`),this.#Q.forwardMap[r]=t.forwardTo}#ce(e,t){const r={name:e.name,path:e.path},n=this.#Q.forwardMap[t];if(n&&(r.forwardTo=n),t in this.#Q.defaultParams&&(r.defaultParams=this.#Q.defaultParams[t]),t in this.#Q.decoders&&(r.decodeParams=this.#Q.decoders[t]),t in this.#Q.encoders&&(r.encodeParams=this.#Q.encoders[t]),this.#te){const[,e]=this.#te.getFactories();t in e&&(r.canActivate=e[t])}return e.children&&(r.children=e.children.map(e=>this.#ce(e,`${t}.${e.name}`))),r}},mt=()=>{};function vt(t,...r){try{t(...r)}catch(t){e.logger.error("router.navigate","Error in navigation callback:",t)}}var wt={log:0,warn:1,error:2},yt={all:0,"warn-error":1,"error-only":2,none:3},bt=new class{#Q={level:"all",callbackIgnoresLevel:!1};#me=0;configure(e){if(void 0!==e.level){if(!(e.level in yt))throw new Error(`Invalid log level: "${e.level}". Valid levels are: ${Object.keys(yt).join(", ")}`);this.#Q.level=e.level,this.#me=yt[e.level]}"callback"in e&&(this.#Q.callback=e.callback),void 0!==e.callbackIgnoresLevel&&(this.#Q.callbackIgnoresLevel=e.callbackIgnoresLevel)}getConfig(){return{level:this.#Q.level,callback:this.#Q.callback,callbackIgnoresLevel:this.#Q.callbackIgnoresLevel}}log(e,t,...r){this.#ve("log",e,t,r)}warn(e,t,...r){this.#ve("warn",e,t,r)}error(e,t,...r){this.#ve("error",e,t,r)}#ve(e,t,r,n){if("none"===this.#Q.level&&!this.#Q.callbackIgnoresLevel)return;const i=wt[e]<this.#me;i||this.#we(e,t,r,n),this.#ye(e,t,r,i,n)}#we(e,t,r,n){"undefined"!=typeof console&&"function"==typeof console[e]&&console[e](t?`[${t}] ${r}`:r,...n)}#ye(e,t,r,n,i){if(this.#Q.callback&&(this.#Q.callbackIgnoresLevel||!n))try{this.#Q.callback(e,t,r,...i)}catch(e){"undefined"!=typeof console&&"function"==typeof console.error&&console.error("[Logger] Error in callback:",e)}}},Tt=(e,t)=>{if(t)return t.setCode(e),t},St=(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}},Rt=new Set(Object.values(g)),Et=new Set(["code","segment","path","redirect"]),At=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),Ot=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(Et.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);At.has(e)||(this[e]=t)}}setCode(e){this.code=e,Rt.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(Et.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);At.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}},$t=(e,t,r)=>{const n=r?{segment:r}:{};var i;void 0!==e&&("boolean"!=typeof e?c(e)?t(void 0,e):"object"==typeof(i=e)&&null!==i&&"then"in i&&"function"==typeof i.then?e.then(e=>{"boolean"==typeof e?e?t():t(new Ot(g.TRANSITION_ERR,n)):t(void 0,e)},e=>{let r=n;e instanceof Error?(r={...n,message:e.message,stack:e.stack},"cause"in e&&void 0!==e.cause&&(r.cause=e.cause)):e&&"object"==typeof e&&(r={...n,...e}),t(new Ot(g.TRANSITION_ERR,r))}):t(new Ot(g.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})):e?t():t(new Ot(g.TRANSITION_ERR,n)))};function Pt(e,t,r,n){try{e(t,r)}catch(e){bt.error(n,"Error in callback:",e)}}var Nt=new Set(["code","segment","path","redirect"]);function Ct(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))Nt.has(r)||(t[r]=n);return{...r,...t}}return r}var Dt="core:lifecycle",jt=(e,t,r,n,i,a,o)=>{let s=t;const l=n.filter(t=>e.has(t));if(0===l.length)return void Pt(o,void 0,s,Dt);let u=0;const d=(e,t)=>{if(e)if(e.redirect){const t=new Ot(i,{message:"Guards cannot redirect. Use middleware for redirects.",attemptedRedirect:e.redirect});h(t)}else h(e);else h(void 0,t)},h=(t,n)=>{if(a())return void Pt(o,new Ot(g.TRANSITION_CANCELLED),s,Dt);if(t)return void Pt(o,Tt(i,t),s,Dt);if(n&&n!==s&&c(n)){if(n.name!==s.name){const e=new Ot(i,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:n.name,params:n.params,path:n.path}});return void Pt(o,e,s,Dt)}(n.params!==s.params||n.path!==s.path)&&bt.error("core:transition","Warning: State mutated during transition",{from:s,to:n}),s=St(n,s)}if(u>=l.length)return void Pt(o,void 0,s,Dt);const h=l[u++],f=e.get(h);try{const e=f(s,r,d);$t(e,d,h)}catch(e){d(new Ot(g.TRANSITION_ERR,Ct(e,h)))}};h()},kt="core:middleware";function Mt(e,t,r,n,i){let a=!1,o=!1;const[s,l]=e.getLifecycleFunctions(),u=e.getMiddlewareFunctions(),d=t.name===m.UNKNOWN_ROUTE,h=()=>a||!e.isActive(),f=(e,r)=>{o||(o=!0,i(e,r??t))};return(()=>{const{toDeactivate:i,toActivate:a}=ft(t,r),o=!d&&a.length>0,p=u.length>0,m=(n,i)=>{if(n)f(n,i);else{if(r){const n=ht(t.name),i=ht(r.name),a=new Set(n);for(const t of i)!a.has(t)&&s.has(t)&&e.clearCanDeactivate(t)}f(void 0,i)}},v=(e,t)=>{e?f(e,t):((e,t)=>{p?((e,t,r,n,i)=>{let a=t,o=0;const s=(e,t)=>{e?l(e):l(void 0,t)},l=(t,l)=>{if(n())return void Pt(i,new Ot(g.TRANSITION_CANCELLED),a,kt);if(t)return void Pt(i,Tt(g.TRANSITION_ERR,t),a,kt);if(l&&l!==a&&c(l)&&((l.name!==a.name||l.params!==a.params||l.path!==a.path)&&bt.error(kt,"Warning: State mutated during middleware execution",{from:a,to:l}),a=St(l,a)),o>=e.length)return void Pt(i,void 0,a,kt);const u=e[o++];try{const e=u(a,r,s);$t(e,s)}catch(e){s(new Ot(g.TRANSITION_ERR,Ct(e)))}};l()})(u,e,r,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,m)};var w;w=(e,t)=>{e?f(e,t):((e,t)=>{o?jt(l,e,r,a,g.CANNOT_ACTIVATE,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,v)},r&&!n.forceDeactivate&&i.length>0?jt(s,t,r,i,g.CANNOT_DEACTIVATE,h,w):w(void 0,t)})(),()=>{a||o||(a=!0,f(new Ot(g.TRANSITION_CANCELLED)))}}var It=()=>{},xt=Object.freeze({}),Ft=Object.freeze({});var Lt=class{isRouterStarted;#be=!1;#Te=null;#f;#Se;get#g(){if(!this.#f)throw new Error("[real-router] NavigationNamespace: dependencies not initialized");return this.#f}get#Re(){if(!this.#Se)throw new Error("[real-router] NavigationNamespace: transition dependencies not initialized");return this.#Se}static validateNavigateArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${f(e)}`)}(e)}static validateNavigateToStateArgs(e,t,r,n,i){!function(e,t,r,n,i){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 ${f(r)}`);if("function"!=typeof n)throw new TypeError(`[router.navigateToState] Invalid callback: expected function, got ${f(n)}`);if("boolean"!=typeof i)throw new TypeError(`[router.navigateToState] Invalid emitSuccess: expected boolean, got ${f(i)}`)}(e,t,r,n,i)}static validateNavigateToDefaultArgs(e,t){!function(e,t){if(void 0!==e&&"function"!=typeof e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${f(e)}. Expected NavigationOptions object or callback function.`);if(void 0!==t&&"function"!=typeof t)throw new TypeError(`[router.navigateToDefault] Invalid callback: expected function, got ${f(t)}`)}(e,t)}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: ${f(e)}. Expected NavigationOptions object.`)}(e,r)}static parseNavigateArgs(e,t,r){return function(e,t,r){if("function"==typeof e)return{params:xt,opts:Ft,callback:e};const n=e??xt;return"function"==typeof t?{params:n,opts:Ft,callback:t}:{params:n,opts:t??Ft,callback:r??It}}(e,t,r)}static parseNavigateToDefaultArgs(e,t){return function(e,t){return"function"==typeof e?{opts:Ft,callback:e}:{opts:e??Ft,callback:t??It}}(e,t)}setDependencies(e){this.#f=e}setTransitionDependencies(e){this.#Se=e}isNavigating(){return this.isRouterStarted()&&this.#be}cancel(){this.#Te&&(this.#Te(),this.#Te=null),this.#be=!1}navigateToState(t,r,n,i,a){const o=this.#g,s=this.#Re;return this.#be&&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.#be=!0,o.invokeEventListeners(R.TRANSITION_START,t,r),this.#Te=Mt(s,t,r,n,(e,s)=>{if(this.#be=!1,this.#Te=null,e)e.code===g.TRANSITION_CANCELLED?o.invokeEventListeners(R.TRANSITION_CANCEL,t,r):o.invokeEventListeners(R.TRANSITION_ERROR,t,r,e),vt(i,e);else if(s.name===m.UNKNOWN_ROUTE||o.hasRoute(s.name))o.setState(s),a&&o.invokeEventListeners(R.TRANSITION_SUCCESS,s,r,n),vt(i,void 0,s);else{const e=new Ot(g.ROUTE_NOT_FOUND,{routeName:s.name});vt(i,e),o.invokeEventListeners(R.TRANSITION_ERROR,void 0,o.getState(),e)}}),this.#Te}navigate(e,t,r,n){const i=this.#g;if(!this.isRouterStarted())return vt(n,new Ot(g.ROUTER_NOT_STARTED)),mt;const a=i.buildStateWithSegments(e,t);if(!a){const e=new Ot(g.ROUTE_NOT_FOUND);return vt(n,e),i.invokeEventListeners(R.TRANSITION_ERROR,void 0,i.getState(),e),mt}const{state:o,segments:s}=a,c=i.makeState(o.name,o.params,i.buildPath(o.name,o.params,s),{params:o.meta,options:r,redirected:r.redirected??!1});if(r.skipTransition)return vt(n,void 0,c),mt;const l=i.getState();if(!r.reload&&!r.force&&i.areStatesEqual(l,c,!1)){const e=new Ot(g.SAME_STATES);return vt(n,e),i.invokeEventListeners(R.TRANSITION_ERROR,c,l,e),mt}return this.navigateToState(c,l,r,n,!0)}navigateToDefault(e,t){const r=this.#g.getOptions();return r.defaultRoute?this.navigate(r.defaultRoute,r.defaultParams,e,t):mt}},_t=()=>{},Ut=new Ot(g.NO_START_PATH_OR_STATE),zt=new Ot(g.ROUTER_ALREADY_STARTED),Vt=class{navigateToState;#Ee=!1;#Ae=!1;#f;get#g(){if(!this.#f)throw new Error("[real-router] RouterLifecycleNamespace: dependencies not initialized");return this.#f}static validateStartArgs(e){if(e.length>2)throw new Error("[router.start] Invalid number of arguments. Expected 0-2 arguments.")}setDependencies(e){this.#f=e}isStarted(){return this.#Ee}isActive(){return this.#Ae}start(...t){const r=this.#g,n=r.getOptions(),[i,a]=(e=>{const[t,r]=e;return t?"function"==typeof t?[void 0,t]:[t,r??_t]:[void 0,_t]})(t);let o=!1;if(this.#Ee||this.#Ae)return o=!0,void a(zt);if(!i&&!n.defaultRoute)return o=!0,r.hasListeners(R.TRANSITION_ERROR)&&r.invokeEventListeners(R.TRANSITION_ERROR,void 0,void 0,Ut),void a(Ut);this.#Ae=!0;const s={replace:!0},l=(t,n,i=!1)=>{t?(this.#Ae=!1,i&&r.hasListeners(R.TRANSITION_ERROR)&&r.invokeEventListeners(R.TRANSITION_ERROR,void 0,void 0,t)):(this.#Ee=!0,r.invokeEventListeners(R.ROUTER_START),r.invokeEventListeners(R.TRANSITION_SUCCESS,n,void 0,{replace:!0})),((t,r)=>{o?e.logger.warn("real-router","Callback already invoked"):(o=!0,a(t,r))})(t,n)},u=(e,t={})=>{this.navigateToState(e,void 0,t,(e,t)=>{l(e,t)},!1)},d=i??n.defaultRoute,h=((e,t)=>{if("string"==typeof e)return t.matchPath(e);if(c(e)){try{t.buildPath(e.name,e.params)}catch{return}return e}})(d,r),f="string"==typeof d?d:"";h?u(h,s):n.defaultRoute&&!i?((e,t,n)=>{const i=r.buildState(e,t);if(!i)return void l(new Ot(g.ROUTE_NOT_FOUND,{routeName:e}),void 0,!0);const a=r.makeState(i.name,i.params,r.buildPath(i.name,i.params),{params:i.meta,options:n,redirected:!1});u(a,n)})(n.defaultRoute,n.defaultParams,s):n.allowNotFound?u(r.makeNotFoundState(f,s),s):l(new Ot(g.ROUTE_NOT_FOUND,{path:f}),void 0,!0)}stop(){const e=this.#g;this.#Ae=!1,this.#Ee&&(this.#Ee=!1,e.setState(),e.invokeEventListeners(R.ROUTER_STOP))}},qt=class{#Oe;#$e;get#Pe(){if(!this.#Oe)throw new Error("[real-router] CloneNamespace: getCloneData not initialized");return this.#Oe}get#Ne(){if(!this.#$e)throw new Error("[real-router] CloneNamespace: applyConfig not initialized");return this.#$e}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 ${f(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.#Oe=e,this.#$e=t}clone(e,t){const r=this.#Pe(),n={...r.dependencies,...e},i=t(r.routes,r.options,n);for(const[e,t]of Object.entries(r.canDeactivateFactories))i.canDeactivate(e,t);for(const[e,t]of Object.entries(r.canActivateFactories))i.canActivate(e,t);return r.middlewareFactories.length>0&&i.useMiddleware(...r.middlewareFactories),r.pluginFactories.length>0&&i.usePlugin(...r.pluginFactories),this.#Ne(i,r.routeConfig,r.resolvedForwardMap),i}},Wt=new Set(["all","warn-error","error-only"]);var Bt=class t{#c;#t;#e;#Ce;#De;#je;#ke;#Me;#S;#Ie;#xe;#Fe;#Le=null;#re;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)||!Wt.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),W.validateOptions(r,"constructor");const i=r.noValidate??!1;i||j.validateDependenciesObject(n,"constructor"),!i&&t.length>0&&(gt.validateAddRouteArgs(t),gt.validateRoutes(t)),this.#c=new W(r),this.#t=function(e={}){return{...E,...e}}(r.limits),this.#e=new j(n),this.#Ce=new I,this.#De=new H,this.#je=new gt(t,i),this.#ke=new X,this.#Me=new G,this.#S=new Y,this.#Ie=new Lt,this.#xe=new Vt,this.#Fe=new qt,this.#re=i,this.#_e(),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.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.getOptions=this.getOptions.bind(this),this.getOption=this.getOption.bind(this),this.setOption=this.setOption.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.canDeactivate=this.canDeactivate.bind(this),this.canActivate=this.canActivate.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.#re||(gt.validateAddRouteArgs(t),gt.validateRoutes(t,this.#je.getTree(),this.#je.getForwardRecord())),this.#je.addRoutes(t),this}removeRoute(t){return this.#re||gt.validateRemoveRouteArgs(t),this.#je.validateRemoveRoute(t,this.#De.get()?.name,this.#Ie.isNavigating())?(this.#je.removeRoute(t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),this):this}clearRoutes(){return this.#je.validateClearRoutes(this.#Ie.isNavigating())?(this.#je.clearRoutes(),this.#ke.clearAll(),this.#De.set(void 0),this):this}getRoute(e){return this.#re||h(e,"getRoute"),this.#je.getRoute(e)}hasRoute(e){return this.#re||h(e,"hasRoute"),this.#je.hasRoute(e)}updateRoute(t,r){this.#re||gt.validateUpdateRouteBasicArgs(t,r);const{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:o,canActivate:s}=r;return this.#re||gt.validateUpdateRoutePropertyTypes(n,i,a,o),this.#Ie.isNavigating()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),this.#re||this.#je.validateUpdateRoute(t,n),this.#je.updateRouteConfig(t,{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:o}),void 0!==s&&(null===s?this.#ke.clearCanActivate(t,!0):this.canActivate(t,s)),this}isActiveRoute(t,r,n,i){return this.#re||gt.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.#je.isActiveRoute(t,r,n,i)}buildPath(e,t){return this.#re||gt.validateBuildPathArgs(e),this.#je.buildPath(e,t,this.#c.get())}matchPath(e,t){return this.#re||gt.validateMatchPathArgs(e),this.#je.matchPath(e,t,this.#c.get())}setRootPath(e){this.#re||gt.validateSetRootPathArgs(e),this.#je.setRootPath(e)}getRootPath(){return this.#je.getRootPath()}makeState(e,t,r,n,i){return this.#re||H.validateMakeStateArgs(e,t,r,i),this.#De.makeState(e,t,r,n,i)}getState(){return this.#De.get()}getPreviousState(){return this.#De.getPrevious()}areStatesEqual(e,t,r=!0){return this.#re||H.validateAreStatesEqualArgs(e,t,r),this.#De.areStatesEqual(e,t,r)}forwardState(e,t){return this.#re||gt.validateStateBuilderArgs(e,t,"forwardState"),this.#je.forwardState(e,t)}buildState(e,t){this.#re||gt.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:n}=this.forwardState(e,t);return this.#je.buildStateResolved(r,n)}shouldUpdateNode(e){return this.#re||gt.validateShouldUpdateNodeArgs(e),this.#je.shouldUpdateNode(e)}getOptions(){return this.#c.get()}getOption(e){return this.#re||(W.validateOptionName(e,"getOption"),W.validateOptionExists(e,"getOption")),this.#c.getOption(e)}setOption(e,t){return this.#re||(W.validateOptionName(e,"setOption"),W.validateOptionExists(e,"setOption"),W.validateNotLocked(this.#c.isLocked(),e),W.validateOptionValue(e,t,"setOption")),this.#c.set(e,t),this}isActive(){return this.#xe.isActive()}start(...e){return this.#re||Vt.validateStartArgs(e),this.#c.lock(),this.#je.initBuildOptionsCache(this.#c.get()),this.#xe.start(...e),this}stop(){return this.#xe.stop(),this.#je.clearBuildOptionsCache(),this.#c.unlock(),this}canDeactivate(e,t){this.#re||(h(e,"canDeactivate"),X.validateHandler(t,"canDeactivate"),X.validateNotRegistering(this.#ke.isRegistering(e),e,"canDeactivate"));const r=this.#ke.hasCanDeactivate(e);return r||this.#re||X.validateHandlerLimit(this.#ke.countCanDeactivate()+1,"canDeactivate",this.#t.maxLifecycleHandlers),this.#ke.registerCanDeactivate(e,t,r),this}canActivate(e,t){this.#re||(h(e,"canActivate"),X.validateHandler(t,"canActivate"),X.validateNotRegistering(this.#ke.isRegistering(e),e,"canActivate"));const r=this.#ke.hasCanActivate(e);return r||this.#re||X.validateHandlerLimit(this.#ke.countCanActivate()+1,"canActivate",this.#t.maxLifecycleHandlers),this.#ke.registerCanActivate(e,t,r),this}usePlugin(...e){return this.#re||(Y.validateUsePluginArgs(e),Y.validatePluginLimit(this.#S.count(),e.length,this.#t.maxPlugins),Y.validateNoDuplicatePlugins(e,this.#S.has.bind(this.#S))),this.#S.use(...e)}useMiddleware(...e){this.#re||(G.validateUseMiddlewareArgs(e),G.validateNoDuplicates(e,this.#Me.getFactories()),G.validateMiddlewareLimit(this.#Me.count(),e.length,this.#t.maxMiddleware));const t=this.#Me.initialize(...e);if(!this.#re)for(const{middleware:e,factory:r}of t)G.validateMiddleware(e,r);return this.#Me.commit(t)}clearMiddleware(){return this.#Me.clear(),this}setDependency(e,t){return this.#re||j.validateSetDependencyArgs(e),this.#e.set(e,t),this}setDependencies(e){return this.#re||(j.validateDependenciesObject(e,"setDependencies"),j.validateDependencyLimit(this.#e.count(),Object.keys(e).length,"setDependencies",this.#t.maxDependencies)),this.#e.setMultiple(e),this}getDependency(e){this.#re||j.validateName(e,"getDependency");const t=this.#e.get(e);return this.#re||j.validateDependencyExists(t,e),t}getDependencies(){return this.#e.getAll()}removeDependency(e){return this.#re||j.validateName(e,"removeDependency"),this.#e.remove(e),this}hasDependency(e){return this.#re||j.validateName(e,"hasDependency"),this.#e.has(e)}resetDependencies(){return this.#e.reset(),this}addEventListener(e,t){return this.#re||I.validateListenerArgs(e,t),this.#Ce.addEventListener(e,t)}navigate(e,t,r,n){this.#re||Lt.validateNavigateArgs(e);const{params:i,opts:a,callback:o}=Lt.parseNavigateArgs(t,r,n);return this.#re||Lt.validateNavigationOptions(a,"navigate"),this.#Ie.navigate(e,i,a,o)}navigateToDefault(e,t){this.#re||Lt.validateNavigateToDefaultArgs(e,t);const{opts:r,callback:n}=Lt.parseNavigateToDefaultArgs(e,t);return this.#re||Lt.validateNavigationOptions(r,"navigateToDefault"),this.#Ie.navigateToDefault(r,n)}navigateToState(e,t,r,n,i){return this.#re||Lt.validateNavigateToStateArgs(e,t,r,n,i),this.#Ie.navigateToState(e,t,r,n,i)}subscribe(e){return this.#re||I.validateSubscribeListener(e),this.#Ce.subscribe(e)}clone(e){return this.#re||qt.validateCloneArgs(e),this.#Fe.clone(e,(e,r,n)=>new t(e,r,n))}getNavigator(){return this.#Le??=Object.freeze({navigate:this.navigate,getState:this.getState,isActiveRoute:this.isActiveRoute,subscribe:this.subscribe}),this.#Le}#_e(){this.#e.setLimits(this.#t),this.#S.setLimits(this.#t),this.#Me.setLimits(this.#t),this.#Ce.setLimits(this.#t),this.#ke.setLimits(this.#t),this.#ke.setRouter(this),this.#ke.setDependencies({getDependency:e=>this.#e.get(e)}),this.#je.setDependencies({canActivate:(e,t)=>{this.canActivate(e,t)},makeState:(e,t,r,n)=>this.#De.makeState(e,t,r,n),getState:()=>this.#De.get(),areStatesEqual:(e,t,r)=>this.#De.areStatesEqual(e,t,r)}),this.#je.setLifecycleNamespace(this.#ke),this.#Me.setRouter(this),this.#Me.setDependencies({getDependency:e=>this.#e.get(e)}),this.#S.setRouter(this),this.#S.setDependencies({addEventListener:(e,t)=>this.#Ce.addEventListener(e,t),isStarted:()=>this.#xe.isStarted(),getDependency:e=>this.#e.get(e)}),this.#Ie.setDependencies({getOptions:()=>this.#c.get(),hasRoute:e=>this.#je.hasRoute(e),getState:()=>this.#De.get(),setState:e=>{this.#De.set(e)},buildStateWithSegments:(e,t)=>{const{name:r,params:n}=this.forwardState(e,t);return this.#je.buildStateWithSegmentsResolved(r,n)},makeState:(e,t,r,n)=>this.#De.makeState(e,t,r,n),buildPath:(e,t,r)=>this.#je.buildPath(e,t,this.#c.get(),r),areStatesEqual:(e,t,r)=>this.#De.areStatesEqual(e,t,r),invokeEventListeners:(e,t,r,n)=>{this.#Ce.invoke(e,t,r,n)}}),this.#Ie.setTransitionDependencies({getLifecycleFunctions:()=>this.#ke.getFunctions(),getMiddlewareFunctions:()=>this.#Me.getFunctions(),isActive:()=>this.#xe.isActive(),clearCanDeactivate:e=>{this.#ke.clearCanDeactivate(e)}}),this.#xe.setDependencies({getOptions:()=>this.#c.get(),hasListeners:e=>this.#Ce.hasListeners(e),invokeEventListeners:(e,t,r,n)=>{this.#Ce.invoke(e,t,r,n)},buildState:(e,t)=>this.buildState(e,t),makeState:(e,t,r,n)=>this.#De.makeState(e,t,r,n),buildPath:(e,t)=>this.buildPath(e,t),makeNotFoundState:(e,t)=>this.#De.makeNotFoundState(e,t),setState:e=>{this.#De.set(e)},matchPath:(e,t)=>this.#je.matchPath(e,t,this.#c.get())}),this.#De.setDependencies({getDefaultParams:()=>this.#je.getConfig().defaultParams,buildPath:(e,t)=>this.#je.buildPath(e,t,this.#c.get()),getUrlParams:e=>this.#je.getUrlParams(e)}),this.#Ie.isRouterStarted=()=>this.#xe.isStarted(),this.#xe.navigateToState=(e,t,r,n,i)=>this.#Ie.navigateToState(e,t,r,n,i),this.#Fe.setCallbacks(()=>{const[e,t]=this.#ke.getFactories();return{routes:this.#je.cloneRoutes(),options:{...this.#c.get()},dependencies:this.#e.getAll(),canDeactivateFactories:e,canActivateFactories:t,middlewareFactories:this.#Me.getFactories(),pluginFactories:this.#S.getAll(),routeConfig:this.#je.getConfig(),resolvedForwardMap:this.#je.getResolvedForwardMap()}},(e,t,r)=>{const n=e,i=n.#je.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),n.#je.setResolvedForwardMap({...r})})}};exports.Router=Bt,exports.RouterError=Ot,exports.constants=m,exports.createRouter=(e=[],t={},r={})=>new Bt(e,t,r),exports.errorCodes=g,exports.events=R;//# sourceMappingURL=index.js.map
|
|
1
|
+
var e=require("@real-router/logger"),t=["replace","reload","skipTransition","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 l(e){return"string"==typeof e}function u(e){return"boolean"==typeof e}function d(e,t){return e in t}function h(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 f(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 p(e,t){if(!c(e))throw new TypeError(`[${t}] Invalid state structure: ${f(e)}. Expected State object with name, params, and path properties.`)}var g=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"}),m={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},v="onStart",w="onStop",y="onTransitionStart",b="onTransitionCancel",S="onTransitionSuccess",T="onTransitionError",R={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},E={maxDependencies:100,maxPlugins:50,maxMiddleware:50,maxListeners:1e4,maxEventDepth:5,maxLifecycleHandlers:200},A={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}},O=new WeakSet;function $(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)$(t);else for(const t in e)$(e[t])}function P(e){return e?(O.has(e)||($(e),O.add(e)),e):e}function N(e){return{warn:Math.floor(.2*e),error:Math.floor(.5*e)}}var C=class{#e=Object.create(null);#t=E;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 ${f(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=E.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: "${f(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}=N(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.`)}},D=new Set([R.ROUTER_START,R.TRANSITION_START,R.TRANSITION_SUCCESS,R.TRANSITION_ERROR,R.TRANSITION_CANCEL,R.ROUTER_STOP]);function j(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=E;static validateEventName(e){if(!D.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 R.TRANSITION_START:case R.TRANSITION_CANCEL:j(e,this.#s(e),t,r);break;case R.TRANSITION_ERROR:case R.TRANSITION_SUCCESS:j(e,this.#s(e),t,r,n);break;default:j(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(R.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??={[R.ROUTER_START]:0,[R.TRANSITION_START]:0,[R.TRANSITION_SUCCESS]:0,[R.TRANSITION_ERROR]:0,[R.TRANSITION_CANCEL]:0,[R.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}`)}},I={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},M={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},F={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 L(e,t){return"function"==typeof e?e(t):e}function _(e,t,r){if("function"==typeof t&&("defaultRoute"===e||"defaultParams"===e))return;const n=I[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 ${f(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(!d(r,F)){const e=Object.keys(F).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],i=F[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 M&&function(e,t,r){const n=M[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 U(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(A,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=A[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 V=class{#c;constructor(e={}){this.#c=x({...I,...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(I,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 ${f(e)}`);for(const[r,n]of Object.entries(e))d(r,I)?void 0!==n&&_(r,n,t):U(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{#l=0;#u=void 0;#d=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(!l(e))throw new TypeError(`[router.makeState] Invalid name: ${f(e)}. Expected string.`);if(void 0!==t&&!s(t))throw new TypeError(`[router.makeState] Invalid params: ${f(t)}. Expected plain object.`);if(void 0!==r&&!l(r))throw new TypeError(`[router.makeState] Invalid path: ${f(r)}. Expected string.`);if(void 0!==n&&"number"!=typeof n)throw new TypeError(`[router.makeState] Invalid forceId: ${f(n)}. Expected number.`)}static validateAreStatesEqualArgs(e,t,r){if(null!=e&&p(e,"areStatesEqual"),null!=t&&p(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${f(r)}. Expected boolean.`)}get(){return this.#u}set(e){this.#d=this.#u,e?Object.isFrozen(e)?this.#u=e:this.#u=P(e):this.#u=void 0}getPrevious(){return this.#d}setDependencies(e){this.#h=e}makeState(e,t,r,n,i){const a=n?{...n,id:i??++this.#l,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}:{},P({name:e,params:s,path:r??this.#p.buildPath(e,t),meta:a})}makeNotFoundState(e,t){return this.makeState(m.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 H(e){return e.name||"anonymous"}var B=class{#m=new Set;#v=new Map;#w;#h;#t=E;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 ${f(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 ${f(e)}. Factory: ${H(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: ${H(t)}`)}(e,t)}static validateMiddlewareLimit(e,t,r){!function(e,t,r=E.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}=N(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={[v]:R.ROUTER_START,[w]:R.ROUTER_STOP,[S]:R.TRANSITION_SUCCESS,[y]:R.TRANSITION_START,[T]:R.TRANSITION_ERROR,[b]:R.TRANSITION_CANCEL},K=Object.keys(Q).filter(e=>d(e,Q)),G="router.usePlugin",J=class t{#S=new Set;#w;#h;#t=E;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 ${f(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&&!d(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=E.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(G,"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(G,"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(G,"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}=N(r);n>=a?e.logger.error(G,`${n} plugins registered!`):n>=i&&e.logger.warn(G,`${n} plugins registered`)}#R(t){const r=new Set;for(const n of t)r.has(n)?e.logger.warn(G,"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(G,"Router already started, onStart will not be called")):e.logger.warn(G,`Property '${t}' is not a function, skipping`));return()=>{for(const e of i)e();"function"==typeof n.teardown&&n.teardown()}}},Z=class{#E=new Map;#A=new Map;#O=new Map;#$=new Map;#P=new Set;#w;#h;#t=E;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 ${f(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=E.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,t=!1){this.#A.delete(e),this.#$.delete(e)}clearCanDeactivate(e,t=!1){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.#$]}#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 ${f(e)}`);a.set(r,e)}catch(e){throw i.delete(r),e}finally{this.#P.delete(r)}}#b(t,r){const n=this.#t.maxLifecycleHandlers;if(0===n)return;const{warn:i,error:a}=N(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 Y(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=Y(t,a);a.children.push(e)}return a}function X(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 ee(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var te=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,re=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,ne=/\?(.+)$/,ie=/[^\w!$'()*+,.:;|~-]/gu,ae=/[^\w!$'()*+,.:;|~-]/u,oe={default:e=>ae.test(e)?e.replaceAll(ie,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},se={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function ce(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function le(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function ue(e){const t={};if(0===e.length)return t;const r=e.split("&");for(const e of r){const r=e.indexOf("=");-1===r?t[e]="":t[e.slice(0,r)]=e.slice(r+1)}return t}function de(e){const t=[];for(const r of Object.keys(e)){const n=e[r],i=encodeURIComponent(r);t.push(""===n?i:`${i}=${encodeURIComponent(String(n))}`)}return t.join("&")}function he(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function fe(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(!he(r)||!he(n))return!1;t+=3}else t++;return!0}var pe=/<[^>]*>/g;function ge(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,l=(o?c:s).replaceAll(pe,""),u=o?l:(h=l,""===(d=r)?h:""===h?d:d+h);var d,h;let f=i;a||(f=function(e,t,r,n,i,a){const o=(m=n,le(r)===le(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),l=le(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),d=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?le(n):l,{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,l=0;for(;null!==(c=s.exec(e));){const t=c[1],n="?"===c[2];a.push(e.slice(l,c.index));const s=i.has(t);o.push({paramName:t,isOptional:n,encoder:s?e=>{const t=oe[r],n=e.split("/");let i=t(n[0]);for(let e=1;e<n.length;e++)i+=`/${t(n[e])}`;return i}:oe[r]}),l=c.index+c[0].length}return a.push(e.slice(l)),{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:d,hasConstraints:d.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=le(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=ve(e,i,n.slice(a,r)),a=r+1}return i}(i=e,i.root,r)).slashChildRoute=n;const a=le(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=le(r);"/"!==n?me(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,l,t),g}(e,t,u,o?"":r,n,i));for(const r of t.children.values())ge(e,r,u,n,f);a||n.pop()}function me(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(pe,"").replace(/\?$/,"");return t.paramChild??={node:ce(),name:n},me(e,t.paramChild.node,r,s+1,i),void(s>=a?t.route??=i:me(e,t,r,s+1,i))}t=ve(e,t,c),n=s+1}t.route=i}function ve(e,t,r){if(r.startsWith("*")){const e=r.slice(1);return t.splatChild??={node:ce(),name:e},t.splatChild.node}if(r.startsWith(":")){const e=r.slice(1).replaceAll(pe,"").replace(/\?$/,"");return t.paramChild??={node:ce(),name:e},t.paramChild.node}const n=e.options.caseSensitive?r:r.toLowerCase();return n in t.staticChildren||(t.staticChildren[n]=ce()),t.staticChildren[n]}var we=/[\u0080-\uFFFF]/,ye=class{get options(){return this.#C}#C;#D=ce();#j=new Map;#k=new Map;#I=new Map;#M=new Map;#F="";#x=[];constructor(e){this.#C={caseSensitive:e?.caseSensitive??!0,strictTrailingSlash:e?.strictTrailingSlash??!1,strictQueryParams:e?.strictQueryParams??!1,urlParamsEncoding:e?.urlParamsEncoding??"default",parseQueryString:e?.parseQueryString??ue,buildQueryString:e?.buildQueryString??de}}registerTree(e){this.#x=e.paramMeta.queryParams,ge({root:this.#D,options:this.#C,routesByName:this.#j,segmentsByName:this.#k,metaByName:this.#I,staticCache:this.#M,rootQueryParams:this.#x},e,"",[],null)}match(e){const t=this.#L(e);if(!t)return;const[r,n,i]=t,a=this.#C.caseSensitive?n:n.toLowerCase(),o=this.#M.get(a);if(o){if(this.#C.strictTrailingSlash&&!this.#_(r,o))return;return this.#U(o,{},i)}const s={},c=this.#z(n,s);return!c||this.#C.strictTrailingSlash&&!this.#_(r,c)||c.hasConstraints&&!this.#V(s,c)||!this.#q(s)?void 0:this.#U(c,s,i)}buildPath(e,t,r){const n=this.#j.get(e);if(!n)throw new Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);n.hasConstraints&&t&&this.#W(n,e,t);const i=this.#H(n,t),a=this.#B(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.#I.get(e)}hasRoute(e){return this.#j.has(e)}setRootPath(e){this.#F=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}'`)}}}#H(e,t){const r=e.buildStaticParts,n=e.buildParamSlots;if(0===n.length)return this.#F+r[0];let i=this.#F+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}#B(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)}#L(e){if(""===e&&(e="/"),!e.startsWith("/"))return;const t=e.indexOf("#");if(-1!==t&&(e=e.slice(0,t)),we.test(e))return;if(this.#F.length>0){if(!e.startsWith(this.#F))return;e=e.slice(this.#F.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,le(n),i]}#U(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}}#_(e,t){return(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#z(e,t){return 1===e.length?this.#D.slashChildRoute??this.#D.route:this.#K(this.#D,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 l;if(c in i.staticChildren)l=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}l=i.paramChild.node,n[i.paramChild.name]=s}i=l,r=o+1}return i.slashChildRoute??i.route}#q(e){const t=this.#C.urlParamsEncoding;if("none"===t)return!0;const r=se[t];for(const t in e){const n=e[t];if(n.includes("%")){if(!fe(n))return!1;e[t]=r(n)}}return!0}#V(e,t){for(const[r,n]of t.constraintPatterns)if(!n.pattern.test(e[r]))return!1;return!0}};function be(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function Se(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}function Te(e,t,r){const n=function(e){const t=[],r=[],n=[],i={},a=new Map,o=e.replaceAll(re,"$1"),s=ne.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=te.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=`^${ee(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=Te(a,t,r);n.push(e),e.absolute||i.push(e)}return{childrenMap:Se(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:be(o,e.path)}return e.absolute?e.path:be(o,e.path)}(a),r&&(Object.freeze(s),Object.freeze(i),Object.freeze(a.children),Object.freeze(a)),a}function Re(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=Y({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=Y(e,n);n.children.push(t)}else i.push(e);for(const e of i){const{parent:t,finalName:r}=X(n,e.name),i=Y({name:r,path:e.path,children:e.children},t);t.children.push(i)}return n}(e,t,r);return function(e,t=!0){return Te(e,null,t)}(i,!n?.skipFreeze)}}}function Ee(e,t,r,n){return Re(e,t).addMany(r).build(n)}function Ae(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=>Ae(e))),t}var Oe=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)},$e=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)},Pe={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${$e(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${$e(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${$e(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>$e(e)).join(",")}`}},Ne={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:()=>""}},De=(e,t,r)=>({boolean:Ne[t],null:Ce[r],array:Pe[e]}),je={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:Ne.none,null:Ce.default,array:Pe.none}},ke=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return je;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:De(t,r,n)}},Ie=e=>encodeURIComponent(e),Me=(e,t,r)=>{const n=Ie(e);switch(typeof t){case"string":case"number":default:return`${n}=${Ie(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}=${Ie(t)}`}};function Fe(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:l}=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,Oe(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=Oe(e);return t.boolean.decodeValue(n)})(n?e.slice(t+1,r):void 0,i):n?Oe(e.slice(t+1,r)):null}(e,a,r,o,i),l)}function xe(e){const t=e?.queryParams;return new ye({...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),Fe(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),Fe(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=Me(t,r,n);a&&i.push(a)}return i.join("&")})(e,t)})}function Le(e,t){return new TypeError(`[router.${e}] ${t}`)}var _e=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/,Ue=/\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 Ve(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(!Ue.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("@@")&&!_e.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,Le(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw Le(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw Le(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw Le(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 Le(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(!Ve(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(Ve(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 l=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:Ve(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,l,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,l,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 He(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>He(e))),t}function Be(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}.`)&&Be(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 ${f(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 ${f(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 ${f(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(e.children)for(const r of e.children)Ke(r,`${t}.${r.name}`)}function Ge(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 Je(e){const t=new Set;for(const r of e)for(const e of Ge(r))t.add(e);return t}function Ze(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 Ze(i.children,t,e,a)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function Ye(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 Ye(n.children,e))r.add(t)}return r}function Xe(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,i]of Xe(n.children,e))r.set(t,i)}return r}function et(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 Je(Ze(n,e))}function tt(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=Je(Ze(r,e)),c=[...et(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 rt(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 nt(e,t,r){const n=Ye(e),i=Xe(e),a={...t};for(const[e,t]of i)a[e]=t;for(const[t,a]of i)tt(t,a,e,n,r);for(const e of Object.keys(a))rt(e,a)}function it(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}var at=".";function ot(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function st(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 ct(e){if(!e)return[""];const t=e.indexOf(at);if(-1===t)return[e];const r=e.indexOf(at,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(at,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(at,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(at),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 lt(e,t){if(!t)return{intersection:"",toActivate:ct(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:ct(e.name),toDeactivate:ot(ct(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:ct(e.name),toDeactivate:ot(ct(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=ct(e.name),a=ct(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=st(i,e),c=st(o,t),l=Object.keys(s),u=Object.keys(c);if(l.length!==u.length)return a;for(const e of l)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 ut=Object.freeze({}),dt=class{#G=[];#J=function(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null)}}();#Z=Object.create(null);#Y=new Map;#X="";#ee;#te;#re;#h;#ne;#ie;get#p(){if(!this.#h)throw new Error("[real-router] RoutesNamespace: dependencies not initialized");return this.#h}constructor(e=[],t=!1,r){this.#ie=t,this.#re=r;for(const t of e)this.#G.push(He(t));this.#ee=Ee("",this.#X,this.#G),this.#te=xe(r),this.#te.registerTree(this.#ee),this.#ae(e),t?this.#oe():this.#se()}static validateRemoveRouteArgs(e){!function(e){h(e,"removeRoute")}(e)}static validateSetRootPathArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${f(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 ${f(t)}`);Ke(t,t.name)}}(e)}static validateIsActiveRouteArgs(e,t,r,n){!function(e,t,r,n){if(!l(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(!l(e))throw new TypeError(`[router.${r}] Invalid routeName: ${f(e)}. Expected string.`);if(!s(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${f(t)}. Expected plain object.`)}(e,t,r)}static validateUpdateRouteBasicArgs(e,t){!function(e,t){if(h(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 ${f(t)}`)}(e,t)}static validateUpdateRoutePropertyTypes(e,t,r,n){!function(e,t,r,n){if(null!=e&&!l(e))throw new TypeError(`[real-router] updateRoute: forwardTo must be a string or null, got ${f(e)}`);if(null!=t&&("object"!=typeof t||Array.isArray(t)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${f(t)}`);if(null!=r){if("function"!=typeof r)throw new TypeError("[real-router] updateRoute: decodeParams must be a function or null, got "+typeof r);if("AsyncFunction"===r.constructor.name||r.toString().includes("__awaiter"))throw new TypeError("[real-router] updateRoute: decodeParams cannot be an async function")}if(null!=n){if("function"!=typeof n)throw new TypeError("[real-router] updateRoute: encodeParams must be a function or null, got "+typeof n);if("AsyncFunction"===n.constructor.name||n.toString().includes("__awaiter"))throw new TypeError("[real-router] updateRoute: encodeParams cannot be an async function")}}(e,t,r,n)}static validateBuildPathArgs(e){!function(e){if(!l(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(!l(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e)}static validateShouldUpdateNodeArgs(e){!function(e){if(!l(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&&nt(e,r,t)}(e,t,r)}setDependencies(e){this.#h=e;for(const[t,r]of this.#Y)e.canActivate(t,r);this.#Y.clear()}setLifecycleNamespace(e){this.#ne=e}getRootPath(){return this.#X}getTree(){return this.#ee}getForwardRecord(){return this.#J.forwardMap}setRootPath(e){this.#X=e,this.#ce()}hasRoute(e){return this.#te.hasRoute(e)}getRoute(e){const t=this.#te.getSegmentsByName(e);if(!t)return;const r=Ae(this.#le(t));return this.#ue(r,e)}addRoutes(e){for(const t of e)this.#G.push(He(t));this.#ae(e),this.#ce(),this.#de()}removeRoute(e){return!!Be(this.#G,e)&&(this.#he(e),this.#ce(),this.#de(),!0)}updateRouteConfig(e,t){if(void 0!==t.forwardTo&&(null===t.forwardTo?delete this.#J.forwardMap[e]:this.#J.forwardMap[e]=t.forwardTo,this.#de()),void 0!==t.defaultParams&&(null===t.defaultParams?delete this.#J.defaultParams[e]:this.#J.defaultParams[e]=t.defaultParams),void 0!==t.decodeParams)if(null===t.decodeParams)delete this.#J.decoders[e];else{const r=t.decodeParams;this.#J.decoders[e]=e=>r(e)??e}if(void 0!==t.encodeParams)if(null===t.encodeParams)delete this.#J.encoders[e];else{const r=t.encodeParams;this.#J.encoders[e]=e=>r(e)??e}}clearRoutes(){this.#G.length=0;for(const e in this.#J.decoders)delete this.#J.decoders[e];for(const e in this.#J.encoders)delete this.#J.encoders[e];for(const e in this.#J.defaultParams)delete this.#J.defaultParams[e];for(const e in this.#J.forwardMap)delete this.#J.forwardMap[e];for(const e in this.#Z)delete this.#Z[e];this.#ce()}buildPath(e,t,r){if(e===m.UNKNOWN_ROUTE)return l(t?.path)?t.path:"";const n=Object.hasOwn(this.#J.defaultParams,e)?{...this.#J.defaultParams[e],...t}:t??{},i="function"==typeof this.#J.encoders[e]?this.#J.encoders[e]({...n}):n,a=r?.trailingSlash;return this.#te.buildPath(e,i,{trailingSlash:"never"===a||"always"===a?a:void 0,queryParamsMode:r?.queryParamsMode})}matchPath(e,t,r){const n=r,i=this.#te.match(e);if(!i)return;const a=it(i),{name:o,params:s,meta:c}=a,l="function"==typeof this.#J.decoders[o]?this.#J.decoders[o](s):s,{name:u,params:d}=this.forwardState(o,l);let h=e;if(n.rewritePathOnMatch){const e="function"==typeof this.#J.encoders[u]?this.#J.encoders[u]({...d}):d,t=n.trailingSlash;h=this.#te.buildPath(u,e,{trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:n.queryParamsMode})}return this.#p.makeState(u,d,h,{params:c,options:ut,source:t,redirected:!1})}forwardState(e,t){const r=this.#Z[e]??e,n=Object.hasOwn(this.#J.defaultParams,e)?{...this.#J.defaultParams[e],...t}:t;return r!==e&&Object.hasOwn(this.#J.defaultParams,r)?{name:r,params:{...this.#J.defaultParams[r],...n}}:{name:r,params:n}}buildStateResolved(e,t){const r=this.#te.getSegmentsByName(e);if(r)return it({segments:r,params:t,meta:this.#te.getMetaByName(e)??{}},e)}buildStateWithSegmentsResolved(e,t){const r=this.#te.getSegmentsByName(e);if(r)return{state:it({segments:r,params:t,meta:this.#te.getMetaByName(e)??{}},e),segments:r}}isActiveRoute(e,t={},r=!1,n=!0){We.has(e)||(h(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.#J.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}=lt(t,r);return e===n||!!i.includes(e)||a.includes(e)}}getConfig(){return this.#J}getUrlParams(e){const t=this.#te.getSegmentsByName(e);return t?this.#fe(t):[]}getResolvedForwardMap(){return this.#Z}setResolvedForwardMap(e){Object.assign(this.#Z,e)}cloneRoutes(){return[...this.#ee.children.values()].map(e=>Ae(e))}validateForwardToParamCompatibility(e,t){const r="validateForwardToParamCompatibility",n=this.#pe(e,r),i=this.#pe(t,r),a=this.#ge(n),o=this.#fe(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){rt(e,{...this.#J.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){if(!this.hasRoute(t))throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);this.validateForwardToParamCompatibility(e,t),this.validateForwardToCycle(e,t)}}#ce(){this.#ee=Ee("",this.#X,this.#G),this.#te=xe(this.#re),this.#te.registerTree(this.#ee)}#pe(e,t){const r=this.#te.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}#ge(e){const t=new Set;for(const r of e)for(const e of r.paramMeta.urlParams)t.add(e);return t}#fe(e){const t=[];for(const r of e)for(const e of r.paramMeta.urlParams)t.push(e);return t}#de(){this.#ie?this.#oe():this.#se()}#se(){for(const e in this.#Z)delete this.#Z[e];for(const e of Object.keys(this.#J.forwardMap))this.#Z[e]=rt(e,this.#J.forwardMap)}#oe(){for(const e in this.#Z)delete this.#Z[e];for(const e of Object.keys(this.#J.forwardMap)){let t=e;for(;this.#J.forwardMap[t];)t=this.#J.forwardMap[t];this.#Z[e]=t}}#he(e){const t=t=>t===e||t.startsWith(`${e}.`);if(Qe(this.#J.decoders,t),Qe(this.#J.encoders,t),Qe(this.#J.defaultParams,t),Qe(this.#J.forwardMap,t),Qe(this.#J.forwardMap,e=>t(this.#J.forwardMap[e])),this.#ne){const[e,r]=this.#ne.getFactories();for(const e of Object.keys(r))t(e)&&this.#ne.clearCanActivate(e,!0);for(const r of Object.keys(e))t(r)&&this.#ne.clearCanDeactivate(r,!0)}}#ae(e,t=""){for(const r of e){const e=t?`${t}.${r.name}`:r.name;this.#me(r,e),r.children&&this.#ae(r.children,e)}}#me(e,t){e.canActivate&&(this.#h?this.#h.canActivate(t,e.canActivate):this.#Y.set(t,e.canActivate)),e.forwardTo&&this.#ve(e,t),e.decodeParams&&(this.#J.decoders[t]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(this.#J.encoders[t]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(this.#J.defaultParams[t]=e.defaultParams)}#ve(t,r){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 "${t.forwardTo}".`),this.#J.forwardMap[r]=t.forwardTo}#ue(e,t){const r={name:e.name,path:e.path},n=this.#J.forwardMap[t];if(n&&(r.forwardTo=n),t in this.#J.defaultParams&&(r.defaultParams=this.#J.defaultParams[t]),t in this.#J.decoders&&(r.decodeParams=this.#J.decoders[t]),t in this.#J.encoders&&(r.encodeParams=this.#J.encoders[t]),this.#ne){const[,e]=this.#ne.getFactories();t in e&&(r.canActivate=e[t])}return e.children&&(r.children=e.children.map(e=>this.#ue(e,`${t}.${e.name}`))),r}},ht=()=>{};function ft(t,...r){try{t(...r)}catch(t){e.logger.error("router.navigate","Error in navigation callback:",t)}}var pt={log:0,warn:1,error:2},gt={all:0,"warn-error":1,"error-only":2,none:3},mt=new class{#J={level:"all",callbackIgnoresLevel:!1};#we=0;configure(e){if(void 0!==e.level){if(!(e.level in gt))throw new Error(`Invalid log level: "${e.level}". Valid levels are: ${Object.keys(gt).join(", ")}`);this.#J.level=e.level,this.#we=gt[e.level]}"callback"in e&&(this.#J.callback=e.callback),void 0!==e.callbackIgnoresLevel&&(this.#J.callbackIgnoresLevel=e.callbackIgnoresLevel)}getConfig(){return{level:this.#J.level,callback:this.#J.callback,callbackIgnoresLevel:this.#J.callbackIgnoresLevel}}log(e,t,...r){this.#ye("log",e,t,r)}warn(e,t,...r){this.#ye("warn",e,t,r)}error(e,t,...r){this.#ye("error",e,t,r)}#ye(e,t,r,n){if("none"===this.#J.level&&!this.#J.callbackIgnoresLevel)return;const i=pt[e]<this.#we;i||this.#be(e,t,r,n),this.#Se(e,t,r,i,n)}#be(e,t,r,n){"undefined"!=typeof console&&"function"==typeof console[e]&&console[e](t?`[${t}] ${r}`:r,...n)}#Se(e,t,r,n,i){if(this.#J.callback&&(this.#J.callbackIgnoresLevel||!n))try{this.#J.callback(e,t,r,...i)}catch(e){"undefined"!=typeof console&&"function"==typeof console.error&&console.error("[Logger] Error in callback:",e)}}},vt=(e,t)=>{if(t)return t.setCode(e),t},wt=(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}},yt=new Set(Object.values(g)),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}},Rt=(e,t,r)=>{const n=r?{segment:r}:{};var i;void 0!==e&&("boolean"!=typeof e?c(e)?t(void 0,e):"object"==typeof(i=e)&&null!==i&&"then"in i&&"function"==typeof i.then?e.then(e=>{"boolean"==typeof e?e?t():t(new Tt(g.TRANSITION_ERR,n)):t(void 0,e)},e=>{let r=n;e instanceof Error?(r={...n,message:e.message,stack:e.stack},"cause"in e&&void 0!==e.cause&&(r.cause=e.cause)):e&&"object"==typeof e&&(r={...n,...e}),t(new Tt(g.TRANSITION_ERR,r))}):t(new Tt(g.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})):e?t():t(new Tt(g.TRANSITION_ERR,n)))};function Et(e,t,r,n){try{e(t,r)}catch(e){mt.error(n,"Error in callback:",e)}}var At=new Set(["code","segment","path","redirect"]);function Ot(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))At.has(r)||(t[r]=n);return{...r,...t}}return r}var $t="core:lifecycle",Pt=(e,t,r,n,i,a,o)=>{let s=t;const l=n.filter(t=>e.has(t));if(0===l.length)return void Et(o,void 0,s,$t);let u=0;const d=(e,t)=>{if(e)if(e.redirect){const t=new Tt(i,{message:"Guards cannot redirect. Use middleware for redirects.",attemptedRedirect:e.redirect});h(t)}else h(e);else h(void 0,t)},h=(t,n)=>{if(a())return void Et(o,new Tt(g.TRANSITION_CANCELLED),s,$t);if(t)return void Et(o,vt(i,t),s,$t);if(n&&n!==s&&c(n)){if(n.name!==s.name){const e=new Tt(i,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:n.name,params:n.params,path:n.path}});return void Et(o,e,s,$t)}(n.params!==s.params||n.path!==s.path)&&mt.error("core:transition","Warning: State mutated during transition",{from:s,to:n}),s=wt(n,s)}if(u>=l.length)return void Et(o,void 0,s,$t);const h=l[u++],f=e.get(h);try{const e=f(s,r,d);Rt(e,d,h)}catch(e){d(new Tt(g.TRANSITION_ERR,Ot(e,h)))}};h()},Nt="core:middleware";function Ct(e,t,r,n,i){let a=!1,o=!1;const[s,l]=e.getLifecycleFunctions(),u=e.getMiddlewareFunctions(),d=t.name===m.UNKNOWN_ROUTE,h=()=>a||!e.isActive(),f=(e,r)=>{o||(o=!0,i(e,r??t))};return(()=>{const{toDeactivate:i,toActivate:a}=lt(t,r),o=!d&&a.length>0,p=u.length>0,m=(n,i)=>{if(n)f(n,i);else{if(r){const n=ct(t.name),i=ct(r.name),a=new Set(n);for(const t of i)!a.has(t)&&s.has(t)&&e.clearCanDeactivate(t)}f(void 0,i)}},v=(e,t)=>{e?f(e,t):((e,t)=>{p?((e,t,r,n,i)=>{let a=t,o=0;const s=(e,t)=>{e?l(e):l(void 0,t)},l=(t,l)=>{if(n())return void Et(i,new Tt(g.TRANSITION_CANCELLED),a,Nt);if(t)return void Et(i,vt(g.TRANSITION_ERR,t),a,Nt);if(l&&l!==a&&c(l)&&((l.name!==a.name||l.params!==a.params||l.path!==a.path)&&mt.error(Nt,"Warning: State mutated during middleware execution",{from:a,to:l}),a=wt(l,a)),o>=e.length)return void Et(i,void 0,a,Nt);const u=e[o++];try{const e=u(a,r,s);Rt(e,s)}catch(e){s(new Tt(g.TRANSITION_ERR,Ot(e)))}};l()})(u,e,r,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,m)};var w;w=(e,t)=>{e?f(e,t):((e,t)=>{o?Pt(l,e,r,a,g.CANNOT_ACTIVATE,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,v)},r&&!n.forceDeactivate&&i.length>0?Pt(s,t,r,i,g.CANNOT_DEACTIVATE,h,w):w(void 0,t)})(),()=>{a||o||(a=!0,f(new Tt(g.TRANSITION_CANCELLED)))}}var Dt=()=>{},jt=Object.freeze({}),kt=Object.freeze({});var It=class{isRouterStarted;#Te=!1;#Re=null;#h;#Ee;get#p(){if(!this.#h)throw new Error("[real-router] NavigationNamespace: dependencies not initialized");return this.#h}get#Ae(){if(!this.#Ee)throw new Error("[real-router] NavigationNamespace: transition dependencies not initialized");return this.#Ee}static validateNavigateArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${f(e)}`)}(e)}static validateNavigateToStateArgs(e,t,r,n,i){!function(e,t,r,n,i){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 ${f(r)}`);if("function"!=typeof n)throw new TypeError(`[router.navigateToState] Invalid callback: expected function, got ${f(n)}`);if("boolean"!=typeof i)throw new TypeError(`[router.navigateToState] Invalid emitSuccess: expected boolean, got ${f(i)}`)}(e,t,r,n,i)}static validateNavigateToDefaultArgs(e,t){!function(e,t){if(void 0!==e&&"function"!=typeof e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${f(e)}. Expected NavigationOptions object or callback function.`);if(void 0!==t&&"function"!=typeof t)throw new TypeError(`[router.navigateToDefault] Invalid callback: expected function, got ${f(t)}`)}(e,t)}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: ${f(e)}. Expected NavigationOptions object.`)}(e,r)}static parseNavigateArgs(e,t,r){return function(e,t,r){if("function"==typeof e)return{params:jt,opts:kt,callback:e};const n=e??jt;return"function"==typeof t?{params:n,opts:kt,callback:t}:{params:n,opts:t??kt,callback:r??Dt}}(e,t,r)}static parseNavigateToDefaultArgs(e,t){return function(e,t){return"function"==typeof e?{opts:kt,callback:e}:{opts:e??kt,callback:t??Dt}}(e,t)}setDependencies(e){this.#h=e}setTransitionDependencies(e){this.#Ee=e}isNavigating(){return this.isRouterStarted()&&this.#Te}cancel(){this.#Re&&(this.#Re(),this.#Re=null),this.#Te=!1}navigateToState(t,r,n,i,a){const o=this.#p,s=this.#Ae;return this.#Te&&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.#Te=!0,o.invokeEventListeners(R.TRANSITION_START,t,r),this.#Re=Ct(s,t,r,n,(e,s)=>{if(this.#Te=!1,this.#Re=null,e)e.code===g.TRANSITION_CANCELLED?o.invokeEventListeners(R.TRANSITION_CANCEL,t,r):o.invokeEventListeners(R.TRANSITION_ERROR,t,r,e),ft(i,e);else if(s.name===m.UNKNOWN_ROUTE||o.hasRoute(s.name))o.setState(s),a&&o.invokeEventListeners(R.TRANSITION_SUCCESS,s,r,n),ft(i,void 0,s);else{const e=new Tt(g.ROUTE_NOT_FOUND,{routeName:s.name});ft(i,e),o.invokeEventListeners(R.TRANSITION_ERROR,void 0,o.getState(),e)}}),this.#Re}navigate(e,t,r,n){const i=this.#p;if(!this.isRouterStarted())return ft(n,new Tt(g.ROUTER_NOT_STARTED)),ht;const a=i.buildStateWithSegments(e,t);if(!a){const e=new Tt(g.ROUTE_NOT_FOUND);return ft(n,e),i.invokeEventListeners(R.TRANSITION_ERROR,void 0,i.getState(),e),ht}const{state:o}=a,s=i.makeState(o.name,o.params,i.buildPath(o.name,o.params),{params:o.meta,options:r,redirected:r.redirected??!1});if(r.skipTransition)return ft(n,void 0,s),ht;const c=i.getState();if(!r.reload&&!r.force&&i.areStatesEqual(c,s,!1)){const e=new Tt(g.SAME_STATES);return ft(n,e),i.invokeEventListeners(R.TRANSITION_ERROR,s,c,e),ht}return this.navigateToState(s,c,r,n,!0)}navigateToDefault(e,t){const r=this.#p,n=r.getOptions();if(!n.defaultRoute)return ht;const i=L(n.defaultRoute,r.getDependency);if(!i)return ht;const a=L(n.defaultParams,r.getDependency);return this.navigate(i,a,e,t)}},Mt=()=>{},Ft=new Tt(g.NO_START_PATH_OR_STATE),xt=new Tt(g.ROUTER_ALREADY_STARTED),Lt=class{navigateToState;#Oe=!1;#$e=!1;#h;get#p(){if(!this.#h)throw new Error("[real-router] RouterLifecycleNamespace: dependencies not initialized");return this.#h}static validateStartArgs(e){if(e.length>2)throw new Error("[router.start] Invalid number of arguments. Expected 0-2 arguments.")}setDependencies(e){this.#h=e}isStarted(){return this.#Oe}isActive(){return this.#$e}start(...t){const r=this.#p,n=r.getOptions(),[i,a]=(e=>{const[t,r]=e;return t?"function"==typeof t?[void 0,t]:[t,r??Mt]:[void 0,Mt]})(t);let o=!1;if(this.#Oe||this.#$e)return o=!0,void a(xt);if(!i&&!n.defaultRoute)return o=!0,r.hasListeners(R.TRANSITION_ERROR)&&r.invokeEventListeners(R.TRANSITION_ERROR,void 0,void 0,Ft),void a(Ft);this.#$e=!0;const s={replace:!0},l=(t,n,i=!1)=>{t?(this.#$e=!1,i&&r.hasListeners(R.TRANSITION_ERROR)&&r.invokeEventListeners(R.TRANSITION_ERROR,void 0,void 0,t)):(this.#Oe=!0,r.invokeEventListeners(R.ROUTER_START),r.invokeEventListeners(R.TRANSITION_SUCCESS,n,void 0,{replace:!0})),((t,r)=>{o?e.logger.warn("real-router","Callback already invoked"):(o=!0,a(t,r))})(t,n)},u=(e,t={})=>{this.navigateToState(e,void 0,t,(e,t)=>{l(e,t)},!1)};let d,h;void 0===i?(d=L(n.defaultRoute,r.getDependency),h=d):h=i;const f=((e,t)=>{if("string"==typeof e)return t.matchPath(e);if(c(e)){try{t.buildPath(e.name,e.params)}catch{return}return e}})(h,r),p="string"==typeof h?h:"";f?u(f,s):n.defaultRoute&&!i&&void 0!==d?((e,t,n)=>{const i=r.buildState(e,t);if(!i)return void l(new Tt(g.ROUTE_NOT_FOUND,{routeName:e}),void 0,!0);const a=r.makeState(i.name,i.params,r.buildPath(i.name,i.params),{params:i.meta,options:n,redirected:!1});u(a,n)})(d,L(n.defaultParams,r.getDependency),s):n.allowNotFound?u(r.makeNotFoundState(p,s),s):l(new Tt(g.ROUTE_NOT_FOUND,{path:p}),void 0,!0)}stop(){const e=this.#p;this.#$e=!1,this.#Oe&&(this.#Oe=!1,e.setState(),e.invokeEventListeners(R.ROUTER_STOP))}},_t=class{#Pe;#Ne;get#Ce(){if(!this.#Pe)throw new Error("[real-router] CloneNamespace: getCloneData not initialized");return this.#Pe}get#De(){if(!this.#Ne)throw new Error("[real-router] CloneNamespace: applyConfig not initialized");return this.#Ne}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 ${f(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.#Pe=e,this.#Ne=t}clone(e,t){const r=this.#Ce(),n={...r.dependencies,...e},i=t(r.routes,r.options,n);for(const[e,t]of Object.entries(r.canDeactivateFactories))i.canDeactivate(e,t);for(const[e,t]of Object.entries(r.canActivateFactories))i.canActivate(e,t);return r.middlewareFactories.length>0&&i.useMiddleware(...r.middlewareFactories),r.pluginFactories.length>0&&i.usePlugin(...r.pluginFactories),this.#De(i,r.routeConfig,r.resolvedForwardMap),i}},Ut=new Set(["all","warn-error","error-only"]);var zt=class t{#c;#t;#e;#je;#ke;#Ie;#Me;#Fe;#S;#xe;#Le;#_e;#Ue=null;#ie;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)||!Ut.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),V.validateOptions(r,"constructor");const i=r.noValidate??!1;i||C.validateDependenciesObject(n,"constructor"),!i&&t.length>0&&(dt.validateAddRouteArgs(t),dt.validateRoutes(t)),this.#c=new V(r),this.#t=function(e={}){return{...E,...e}}(r.limits),this.#e=new C(n),this.#je=new k,this.#ke=new W,this.#Ie=new dt(t,i,function(e){return{strictTrailingSlash:"strict"===e.trailingSlash,strictQueryParams:"strict"===e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding,queryParams:e.queryParams??{}}}(this.#c.get())),this.#Me=new Z,this.#Fe=new B,this.#S=new J,this.#xe=new It,this.#Le=new Lt,this.#_e=new _t,this.#ie=i,this.#ze(),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.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.canDeactivate=this.canDeactivate.bind(this),this.canActivate=this.canActivate.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.#ie||(dt.validateAddRouteArgs(t),dt.validateRoutes(t,this.#Ie.getTree(),this.#Ie.getForwardRecord())),this.#Ie.addRoutes(t),this}removeRoute(t){return this.#ie||dt.validateRemoveRouteArgs(t),this.#Ie.validateRemoveRoute(t,this.#ke.get()?.name,this.#xe.isNavigating())?(this.#Ie.removeRoute(t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),this):this}clearRoutes(){return this.#Ie.validateClearRoutes(this.#xe.isNavigating())?(this.#Ie.clearRoutes(),this.#Me.clearAll(),this.#ke.set(void 0),this):this}getRoute(e){return this.#ie||h(e,"getRoute"),this.#Ie.getRoute(e)}hasRoute(e){return this.#ie||h(e,"hasRoute"),this.#Ie.hasRoute(e)}updateRoute(t,r){this.#ie||dt.validateUpdateRouteBasicArgs(t,r);const{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:o,canActivate:s}=r;return this.#ie||dt.validateUpdateRoutePropertyTypes(n,i,a,o),this.#xe.isNavigating()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),this.#ie||this.#Ie.validateUpdateRoute(t,n),this.#Ie.updateRouteConfig(t,{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:o}),void 0!==s&&(null===s?this.#Me.clearCanActivate(t,!0):this.canActivate(t,s)),this}isActiveRoute(t,r,n,i){return this.#ie||dt.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.#Ie.isActiveRoute(t,r,n,i)}buildPath(e,t){return this.#ie||dt.validateBuildPathArgs(e),this.#Ie.buildPath(e,t,this.#c.get())}matchPath(e,t){return this.#ie||dt.validateMatchPathArgs(e),this.#Ie.matchPath(e,t,this.#c.get())}setRootPath(e){this.#ie||dt.validateSetRootPathArgs(e),this.#Ie.setRootPath(e)}getRootPath(){return this.#Ie.getRootPath()}makeState(e,t,r,n,i){return this.#ie||W.validateMakeStateArgs(e,t,r,i),this.#ke.makeState(e,t,r,n,i)}getState(){return this.#ke.get()}getPreviousState(){return this.#ke.getPrevious()}areStatesEqual(e,t,r=!0){return this.#ie||W.validateAreStatesEqualArgs(e,t,r),this.#ke.areStatesEqual(e,t,r)}forwardState(e,t){return this.#ie||dt.validateStateBuilderArgs(e,t,"forwardState"),this.#Ie.forwardState(e,t)}buildState(e,t){this.#ie||dt.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:n}=this.forwardState(e,t);return this.#Ie.buildStateResolved(r,n)}shouldUpdateNode(e){return this.#ie||dt.validateShouldUpdateNodeArgs(e),this.#Ie.shouldUpdateNode(e)}getOptions(){return this.#c.get()}getOption(e){return this.#ie||(V.validateOptionName(e,"getOption"),V.validateOptionExists(e,"getOption")),this.#c.getOption(e)}isActive(){return this.#Le.isActive()}start(...e){return this.#ie||Lt.validateStartArgs(e),this.#Le.start(...e),this}stop(){return this.#Le.stop(),this}canDeactivate(e,t){this.#ie||(h(e,"canDeactivate"),Z.validateHandler(t,"canDeactivate"),Z.validateNotRegistering(this.#Me.isRegistering(e),e,"canDeactivate"));const r=this.#Me.hasCanDeactivate(e);return r||this.#ie||Z.validateHandlerLimit(this.#Me.countCanDeactivate()+1,"canDeactivate",this.#t.maxLifecycleHandlers),this.#Me.registerCanDeactivate(e,t,r),this}canActivate(e,t){this.#ie||(h(e,"canActivate"),Z.validateHandler(t,"canActivate"),Z.validateNotRegistering(this.#Me.isRegistering(e),e,"canActivate"));const r=this.#Me.hasCanActivate(e);return r||this.#ie||Z.validateHandlerLimit(this.#Me.countCanActivate()+1,"canActivate",this.#t.maxLifecycleHandlers),this.#Me.registerCanActivate(e,t,r),this}usePlugin(...e){return this.#ie||(J.validateUsePluginArgs(e),J.validatePluginLimit(this.#S.count(),e.length,this.#t.maxPlugins),J.validateNoDuplicatePlugins(e,this.#S.has.bind(this.#S))),this.#S.use(...e)}useMiddleware(...e){this.#ie||(B.validateUseMiddlewareArgs(e),B.validateNoDuplicates(e,this.#Fe.getFactories()),B.validateMiddlewareLimit(this.#Fe.count(),e.length,this.#t.maxMiddleware));const t=this.#Fe.initialize(...e);if(!this.#ie)for(const{middleware:e,factory:r}of t)B.validateMiddleware(e,r);return this.#Fe.commit(t)}clearMiddleware(){return this.#Fe.clear(),this}setDependency(e,t){return this.#ie||C.validateSetDependencyArgs(e),this.#e.set(e,t),this}setDependencies(e){return this.#ie||(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.#ie||C.validateName(e,"getDependency");const t=this.#e.get(e);return this.#ie||C.validateDependencyExists(t,e),t}getDependencies(){return this.#e.getAll()}removeDependency(e){return this.#ie||C.validateName(e,"removeDependency"),this.#e.remove(e),this}hasDependency(e){return this.#ie||C.validateName(e,"hasDependency"),this.#e.has(e)}resetDependencies(){return this.#e.reset(),this}addEventListener(e,t){return this.#ie||k.validateListenerArgs(e,t),this.#je.addEventListener(e,t)}navigate(e,t,r,n){this.#ie||It.validateNavigateArgs(e);const{params:i,opts:a,callback:o}=It.parseNavigateArgs(t,r,n);return this.#ie||It.validateNavigationOptions(a,"navigate"),this.#xe.navigate(e,i,a,o)}navigateToDefault(e,t){this.#ie||It.validateNavigateToDefaultArgs(e,t);const{opts:r,callback:n}=It.parseNavigateToDefaultArgs(e,t);return this.#ie||It.validateNavigationOptions(r,"navigateToDefault"),this.#xe.navigateToDefault(r,n)}navigateToState(e,t,r,n,i){return this.#ie||It.validateNavigateToStateArgs(e,t,r,n,i),this.#xe.navigateToState(e,t,r,n,i)}subscribe(e){return this.#ie||k.validateSubscribeListener(e),this.#je.subscribe(e)}clone(e){return this.#ie||_t.validateCloneArgs(e),this.#_e.clone(e,(e,r,n)=>new t(e,r,n))}getNavigator(){return this.#Ue??=Object.freeze({navigate:this.navigate,getState:this.getState,isActiveRoute:this.isActiveRoute,subscribe:this.subscribe}),this.#Ue}#ze(){this.#e.setLimits(this.#t),this.#S.setLimits(this.#t),this.#Fe.setLimits(this.#t),this.#je.setLimits(this.#t),this.#Me.setLimits(this.#t),this.#Me.setRouter(this),this.#Me.setDependencies({getDependency:e=>this.#e.get(e)}),this.#Ie.setDependencies({canActivate:(e,t)=>{this.canActivate(e,t)},makeState:(e,t,r,n)=>this.#ke.makeState(e,t,r,n),getState:()=>this.#ke.get(),areStatesEqual:(e,t,r)=>this.#ke.areStatesEqual(e,t,r)}),this.#Ie.setLifecycleNamespace(this.#Me),this.#Fe.setRouter(this),this.#Fe.setDependencies({getDependency:e=>this.#e.get(e)}),this.#S.setRouter(this),this.#S.setDependencies({addEventListener:(e,t)=>this.#je.addEventListener(e,t),isStarted:()=>this.#Le.isStarted(),getDependency:e=>this.#e.get(e)}),this.#xe.setDependencies({getOptions:()=>this.#c.get(),hasRoute:e=>this.#Ie.hasRoute(e),getState:()=>this.#ke.get(),setState:e=>{this.#ke.set(e)},buildStateWithSegments:(e,t)=>{const{name:r,params:n}=this.forwardState(e,t);return this.#Ie.buildStateWithSegmentsResolved(r,n)},makeState:(e,t,r,n)=>this.#ke.makeState(e,t,r,n),buildPath:(e,t)=>this.#Ie.buildPath(e,t,this.#c.get()),areStatesEqual:(e,t,r)=>this.#ke.areStatesEqual(e,t,r),invokeEventListeners:(e,t,r,n)=>{this.#je.invoke(e,t,r,n)},getDependency:e=>this.#e.get(e)}),this.#xe.setTransitionDependencies({getLifecycleFunctions:()=>this.#Me.getFunctions(),getMiddlewareFunctions:()=>this.#Fe.getFunctions(),isActive:()=>this.#Le.isActive(),clearCanDeactivate:e=>{this.#Me.clearCanDeactivate(e)}}),this.#Le.setDependencies({getOptions:()=>this.#c.get(),hasListeners:e=>this.#je.hasListeners(e),invokeEventListeners:(e,t,r,n)=>{this.#je.invoke(e,t,r,n)},buildState:(e,t)=>this.buildState(e,t),makeState:(e,t,r,n)=>this.#ke.makeState(e,t,r,n),buildPath:(e,t)=>this.buildPath(e,t),makeNotFoundState:(e,t)=>this.#ke.makeNotFoundState(e,t),setState:e=>{this.#ke.set(e)},matchPath:(e,t)=>this.#Ie.matchPath(e,t,this.#c.get()),getDependency:e=>this.#e.get(e)}),this.#ke.setDependencies({getDefaultParams:()=>this.#Ie.getConfig().defaultParams,buildPath:(e,t)=>this.#Ie.buildPath(e,t,this.#c.get()),getUrlParams:e=>this.#Ie.getUrlParams(e)}),this.#xe.isRouterStarted=()=>this.#Le.isStarted(),this.#Le.navigateToState=(e,t,r,n,i)=>this.#xe.navigateToState(e,t,r,n,i),this.#_e.setCallbacks(()=>{const[e,t]=this.#Me.getFactories();return{routes:this.#Ie.cloneRoutes(),options:{...this.#c.get()},dependencies:this.#e.getAll(),canDeactivateFactories:e,canActivateFactories:t,middlewareFactories:this.#Fe.getFactories(),pluginFactories:this.#S.getAll(),routeConfig:this.#Ie.getConfig(),resolvedForwardMap:this.#Ie.getResolvedForwardMap()}},(e,t,r)=>{const n=e,i=n.#Ie.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),n.#Ie.setResolvedForwardMap({...r})})}};exports.Router=zt,exports.RouterError=Tt,exports.constants=m,exports.createRouter=(e=[],t={},r={})=>new zt(e,t,r),exports.errorCodes=g,exports.events=R;//# sourceMappingURL=index.js.map
|