@real-router/core 0.8.0 → 0.10.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 -9
- 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 -4
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
|
|
@@ -492,7 +484,6 @@ interface Options {
|
|
|
492
484
|
defaultRoute: string; // Default route name (default: "")
|
|
493
485
|
defaultParams: Params; // Default route params (default: {})
|
|
494
486
|
trailingSlash: "strict" | "never" | "always" | "preserve"; // (default: "preserve")
|
|
495
|
-
caseSensitive: boolean; // Case-sensitive matching (default: false)
|
|
496
487
|
urlParamsEncoding: "default" | "uri" | "uriComponent" | "none"; // (default: "default")
|
|
497
488
|
queryParamsMode: "default" | "strict" | "loose"; // (default: "loose")
|
|
498
489
|
queryParams?: QueryParamsOptions; // Query parameter parsing options
|
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 s(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function o(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(!s(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&&o(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",y="onStop",w="onTransitionStart",b="onTransitionCancel",T="onTransitionSuccess",R="onTransitionError",S={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},P={maxDependencies:100,maxPlugins:50,maxMiddleware:50,maxListeners:1e4,maxEventDepth:5,maxLifecycleHandlers:200},E={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}},A=new WeakSet;function O(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)O(t);else for(const t in e)O(e[t])}function $(e){return e?(A.has(e)||(O(e),A.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 k=class{#e=Object.create(null);#t=P;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=P.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.`)}},x=new Set([S.ROUTER_START,S.TRANSITION_START,S.TRANSITION_SUCCESS,S.TRANSITION_ERROR,S.TRANSITION_CANCEL,S.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 I=class t{#n={};#i=null;#t=P;static validateEventName(e){if(!x.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.#s();try{switch(i[e]++,e){case S.TRANSITION_START:case S.TRANSITION_CANCEL:j(e,this.#o(e),t,r);break;case S.TRANSITION_ERROR:case S.TRANSITION_SUCCESS:j(e,this.#o(e),t,r,n);break;default:j(e,this.#o(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.#o(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(S.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}#o(e){const t=this.#n[e];if(t)return t;const r=new Set;return this.#n[e]=r,r}#s(){return this.#i??={[S.ROUTER_START]:0,[S.TRANSITION_START]:0,[S.TRANSITION_SUCCESS]:0,[S.TRANSITION_ERROR]:0,[S.TRANSITION_CANCEL]:0,[S.ROUTER_STOP]:0},this.#i}#a(e){const t=this.#t.maxEventDepth;if(0!==t&&this.#s()[e]>=t)throw new Error(`[Router] Maximum recursion depth (${t}) exceeded for event: ${e}`)}},M={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},caseSensitive:!1,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 q(e,t,r){const n=M[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(E,r))throw new TypeError(`[router.${t}]: unknown limit: "${r}"`);void 0!==n&&z(r,n,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function z(e,t,r){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError(`[router.${r}]: limit "${e}" must be an integer, got ${String(t)}`);const n=E[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({...M,...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(M,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){q(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,M)?void 0!==n&&q(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;static validateMakeStateArgs(e,t,r,n){if(!l(e))throw new TypeError(`[router.makeState] Invalid name: ${f(e)}. Expected string.`);if(void 0!==t&&!o(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=$(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,s=this.#f.getDefaultParams();let o;return o=Object.hasOwn(s,e)?{...s[e],...t}:t?{...t}:{},$({name:e,params:o,path:r??this.#f.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=>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]))}#g(e){const t=this.#p.get(e);if(void 0!==t)return t;const r=this.#f.getUrlParams(e);return this.#p.set(e,r),r}};function Q(e){return e.name||"anonymous"}var Z=class{#m=new Set;#v=new Map;#y;#f;#t=P;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=P.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.#m.size}initialize(...e){const t=[];for(const r of e){const e=r(this.#y,this.#f.getDependency);t.push({factory:r,middleware:e})}return t}commit(e){this.#w(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()]}#w(t){const r=this.#t.maxMiddleware;if(0===r)return;const n=t+this.#m.size,{warn:i,error:a}=D(r);n>=a?e.logger.error("router.useMiddleware",`${n} middleware registered! This is excessive and will impact performance. Hard limit at ${r}.`):n>=i&&e.logger.warn("router.useMiddleware",`${n} middleware registered. Consider if all are necessary.`)}},K={[v]:S.ROUTER_START,[y]:S.ROUTER_STOP,[T]:S.TRANSITION_SUCCESS,[w]:S.TRANSITION_START,[R]:S.TRANSITION_ERROR,[b]:S.TRANSITION_CANCEL},G=Object.keys(K).filter(e=>d(e,K)),J="router.usePlugin",Y=class t{#b=new Set;#y;#f;#t=P;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=P.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.#b.size}use(...t){if(this.#w(t.length),1===t.length){const r=t[0],n=this.#T(r);this.#b.add(r);let i=!1;return()=>{if(!i){i=!0,this.#b.delete(r);try{n()}catch(t){e.logger.error(J,"Error during cleanup:",t)}}}}const r=this.#R(t),n=[];try{for(const e of r){const t=this.#T(e);n.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(J,"Cleanup error:",t)}throw t}for(const{factory:e}of n)this.#b.add(e);let i=!1;return()=>{if(!i){i=!0;for(const{factory:e}of n)this.#b.delete(e);for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(J,"Error during cleanup:",t)}}}}getAll(){return[...this.#b]}has(e){return this.#b.has(e)}#w(t){const r=this.#t.maxPlugins;if(0===r)return;const n=t+this.#b.size,{warn:i,error:a}=D(r);n>=a?e.logger.error(J,`${n} plugins registered!`):n>=i&&e.logger.warn(J,`${n} plugins registered`)}#R(t){const r=new Set;for(const n of t)r.has(n)?e.logger.warn(J,"Duplicate factory in batch, will be registered once"):r.add(n);return r}#T(r){const n=this.#y,i=this.#f,a=r(n,i.getDependency);t.validatePlugin(a),Object.freeze(a);const s=[];for(const t of G)t in a&&("function"==typeof a[t]?(s.push(i.addEventListener(K[t],a[t])),"onStart"===t&&i.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 s)e();"function"==typeof a.teardown&&a.teardown()}}},X=class{#S=new Map;#P=new Map;#E=new Map;#A=new Map;#O=new Set;#y;#f;#t=P;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=P.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.#O.has(e)}countCanActivate(){return this.#P.size}countCanDeactivate(){return this.#S.size}hasCanActivate(e){return this.#P.has(e)}hasCanDeactivate(e){return this.#S.has(e)}registerCanActivate(e,t,r){this.#$("activate",e,t,this.#P,this.#A,"canActivate",r)}registerCanDeactivate(e,t,r){this.#$("deactivate",e,t,this.#S,this.#E,"canDeactivate",r)}clearCanActivate(e,t=!1){this.#P.delete(e),this.#A.delete(e)}clearCanDeactivate(e,t=!1){this.#S.delete(e),this.#E.delete(e)}clearAll(){this.#P.clear(),this.#A.clear(),this.#S.clear(),this.#E.clear()}getFactories(){const e={},t={};for(const[t,r]of this.#S)e[t]=r;for(const[e,r]of this.#P)t[e]=r;return[e,t]}getFunctions(){return[this.#E,this.#A]}#$(t,r,n,i,a,s,o){o?e.logger.warn(`router.${s}`,`Overwriting existing ${t} handler for route "${r}"`):this.#w(i.size+1,s);const c=u(n)?function(e){const t=()=>e;return()=>t}(n):n;i.set(r,c),this.#O.add(r);try{const e=c(this.#y,this.#f.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${s}] Factory must return a function, got ${f(e)}`);a.set(r,e)}catch(e){throw i.delete(r),e}finally{this.#O.delete(r)}}#w(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.`)}},ee=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)},te=e=>encodeURIComponent(e),re={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${te(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${te(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${te(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>te(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}},ie={default:{encode:e=>e},hidden:{encode:()=>""}},ae=(e,t,r)=>({boolean:ne[t],null:ie[r],array:re[e]}),se={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:ne.none,null:ie.default,array:re.none}},oe=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return se;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:ae(t,r,n)}},ce=e=>encodeURIComponent(e),le=(e,t,r)=>{const n=ce(e);switch(typeof t){case"string":case"number":default:return`${n}=${ce(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}=${ce(t)}`}},ue=e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)};function de(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}function he(e,t,r,n,i){const a=e.indexOf("=",t),s=-1!==a&&a<r,o=e.slice(t,s?a:r),{name:c,hasBrackets:l}=de(o);!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,ee(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=ee(e);return t.boolean.decodeValue(n)})(n?e.slice(t+1,r):void 0,i):n?ee(e.slice(t+1,r)):null}(e,a,r,s,i),l)}var fe=(e,t)=>{const r=ue(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return pe(e,t),t}(r);const n=oe(t),i={};let a=0;const s=r.length;for(;a<s;){let e=r.indexOf("&",a);-1===e&&(e=s),he(r,a,e,i,n.strategies),a=e+1}return i};function pe(e,t){let r=0;const n=e.length;for(;r<n;){let i=e.indexOf("&",r);-1===i&&(i=n),he(e,r,i,t),r=i+1}}var ge=(e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=oe(t),i=[];for(const t of r){const r=e[t];if(void 0===r)continue;const a=le(t,r,n);a&&i.push(a)}return i.join("&")},me=/[^\w!$'()*+,.:;|~-]/gu,ve=/[^\w!$'()*+,.:;|~-]/u,ye={default:e=>ve.test(e)?e.replaceAll(me,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e,legacy:encodeURI},we={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e,legacy:decodeURIComponent},be={urlParamsEncoding:"default"},Te={withQueryParams:String.raw`(\?.*$|$)`,withoutQueryParams:"$"},Re=String.raw`([/?.;]|$)`,Se=String.raw`[a-zA-Z0-9_.~%':|=+*@$-]+`,Pe=e=>`(${e?e.replaceAll(/(^<|>$)/g,""):Se})`,Ee=[{name:"url-parameter",pattern:/^:([\w-]*[\dA-Za-z])(<(.+?)>)?/,regex:e=>new RegExp(Pe(e[2]))},{name:"url-parameter-splat",pattern:/^\*([\w-]*[\dA-Za-z])/,regex:/([^?]*)/},{name:"url-parameter-matrix",pattern:/^;([\w-]*[\dA-Za-z])(<(.+?)>)?/,regex:e=>new RegExp(`;${e[1]}=${Pe(e[2])}`)},{name:"query-parameter",pattern:/^[&?]:?([\w-]*[\dA-Za-z])/},{name:"delimiter",pattern:/^([/?])/,regex:e=>new RegExp(`\\${e[0]}`)},{name:"sub-delimiter",pattern:/^([!&.;_-])/,regex:e=>new RegExp(e[0])},{name:"fragment",pattern:/^([\dA-Za-z]+)/,regex:e=>new RegExp(e[0])}],Ae=(e,t,r)=>{const n=ye[t],i=String(e);if(!r)return n(i);const a=i.split("/");let s=n(a[0]);for(let e=1;e<a.length;e++)s+="/"+n(a[e]);return s},Oe=(e,t)=>we[t](e),$e=(e,t=[])=>{if(!Ee.some(r=>{const n=r.pattern.exec(e);return!!n&&(t.push({type:r.name,match:n[0],val:n.slice(1,2),otherVal:n.slice(2),regex:"function"==typeof r.regex?r.regex(n):r.regex}),n[0].length<e.length&&$e(e.slice(n[0].length),t),!0)}))throw new Error(`Could not parse path '${e}'`);return t},Ne=e=>null!=e,Ce=e=>"string"==typeof e||"number"==typeof e||"boolean"==typeof e,De=e=>!!Ne(e)&&(!!Ce(e)||!!Array.isArray(e)&&e.every(e=>Ce(e))),ke=(e,t,r="")=>{const n=e[t];return e[t]=void 0===n?r:[n,r],e},xe=class e{path;tokens;hasUrlParams;hasSpatParam;hasMatrixParams;hasQueryParams;options;spatParams;urlParams;queryParams;params;source;regexCache;constraintPatterns;buildOptionsCache;compiledBuildPattern;constructor(e,t){if(!e)throw new Error("Missing path in Path constructor");this.path=e,this.options={...be,...t},this.tokens=$e(e),this.hasUrlParams=this.tokens.some(e=>e.type.startsWith("url-parameter")),this.hasSpatParam=this.tokens.some(e=>e.type.endsWith("splat")),this.hasMatrixParams=this.tokens.some(e=>e.type.endsWith("matrix")),this.hasQueryParams=this.tokens.some(e=>e.type.startsWith("query-parameter")),this.spatParams=this.getParams("url-parameter-splat"),this.urlParams=this.getParams(/^url-parameter/),this.queryParams=this.getParams("query-parameter"),this.params=[...this.urlParams,...this.queryParams];let r="";for(const e of this.tokens)void 0!==e.regex&&(r+=e.regex.source);this.source=r;const n=(e=>"\\/"===e?e:e.replace(/\\\/$/,"")+"(?:\\/)?")(r),i=r,a=r,s=(e=>/(\/)$/.test(e)?e:e+Re)(r),o=this.hasQueryParams?Te.withQueryParams:Te.withoutQueryParams;this.regexCache={test:{sensitive:new RegExp("^"+n+o),insensitive:new RegExp("^"+n+o,"i")},testStrict:{sensitive:new RegExp("^"+i+o),insensitive:new RegExp("^"+i+o,"i")},partial:{sensitive:new RegExp("^"+a),insensitive:new RegExp("^"+a,"i")},partialDelimited:{sensitive:new RegExp("^"+s),insensitive:new RegExp("^"+s,"i")}},this.constraintPatterns=new Map;const c=this.tokens.filter(e=>e.type.startsWith("url-parameter")&&!e.type.endsWith("-splat"));for(const e of c){const t=e.val[0],r=e.otherVal[0],n=new RegExp("^"+Pe(r)+"$");this.constraintPatterns.set(t,{pattern:n,constraint:r})}this.buildOptionsCache={ignoreConstraints:!1,ignoreSearch:!1,queryParams:this.options.queryParams??{},urlParamsEncoding:this.options.urlParamsEncoding};const l=this.tokens.filter(e=>!e.type.startsWith("query-parameter")),u=[],d=[];let h="";for(const e of l)e.type.startsWith("url-parameter")&&"url-parameter-matrix"!==e.type?(u.push(h),h="",d.push(e.val[0])):"url-parameter-matrix"===e.type?(h+=";"+e.val[0]+"=",u.push(h),h="",d.push(e.val[0])):h+=e.match;u.push(h),this.compiledBuildPattern={staticParts:u,paramNames:d,pattern:e}}static createPath(t,r){return new e(t,r)}isQueryParam(e){return this.queryParams.includes(e)}isSpatParam(e){return this.spatParams.includes(e)}test(e,t){const r=t?.caseSensitive??!1,n=t?.strictTrailingSlash?this.regexCache.testStrict:this.regexCache.test,i=this.urlTestWithRegex(e,r?n.sensitive:n.insensitive,t?.urlParamsEncoding??this.options.urlParamsEncoding);if(!i||!this.hasQueryParams)return i;const a=fe(e,t?.queryParams??this.options.queryParams);let s=!1;for(const e in a)this.isQueryParam(e)?i[e]=a[e]:s=!0;return s?null:i}partialTest(e,t){const r=t?.caseSensitive??!1,n=t?.delimited??1?this.regexCache.partialDelimited:this.regexCache.partial,i=this.urlTestWithRegex(e,r?n.sensitive:n.insensitive,t?.urlParamsEncoding??this.options.urlParamsEncoding);if(!i)return i;if(!this.hasQueryParams)return i;const a=fe(e,t?.queryParams??this.options.queryParams);for(const e in a)this.isQueryParam(e)&&ke(i,e,a[e]);return i}build(e={},t){const r=t?{ignoreConstraints:t.ignoreConstraints??!1,ignoreSearch:t.ignoreSearch??!1,queryParams:t.queryParams??this.buildOptionsCache.queryParams,urlParamsEncoding:t.urlParamsEncoding??this.buildOptionsCache.urlParamsEncoding}:this.buildOptionsCache,n=this.encodeUrlParams(e,r.urlParamsEncoding);this.validateRequiredParams(e),r.ignoreConstraints||this.validateConstraints(n);const i=this.buildBasePath(n);return r.ignoreSearch?i:this.buildWithSearch(i,e,r.queryParams)}encodeUrlParams(e,t){const r={};for(const n of Object.keys(e)){if(this.isQueryParam(n))continue;const i=e[n];De(i)&&(r[n]=this.encodeParamValue(i,n,t))}return r}encodeParamValue(e,t,r){if("boolean"==typeof e)return e;const n=this.isSpatParam(t);return Array.isArray(e)?e.map(e=>Ae(e,r,n)):Ae(e,r,n)}validateRequiredParams(e){const t=this.urlParams.filter(t=>!Ne(e[t]));if(t.length>0)throw new Error("Cannot build path: '"+this.path+"' requires missing parameters { "+t.join(", ")+" }")}validateConstraints(e){for(const[t,{pattern:r,constraint:n}]of this.constraintPatterns){const i=String(e[t]);if(!r.test(i)){const e=n?n.replaceAll(/(^<)|(>$)/g,""):"[^/]+";throw new Error(`Parameter '${t}' of '${this.path}' has invalid format: got '${i}', expected to match '${e}'`)}}}buildBasePath(e){return function(e,t){const{staticParts:r,paramNames:n}=e;if(0===n.length)return r[0];let i=r[0];for(const[e,a]of n.entries())i+=String(t[a])+r[e+1];return i}(this.compiledBuildPattern,e)}buildWithSearch(e,t,r){const n={};for(const e of this.queryParams)e in t&&(n[e]=t[e]);const i=ge(n,r);return i?e+"?"+i:e}getParams(e){const t=[],r=e instanceof RegExp;for(const n of this.tokens)(r?e.test(n.type):n.type===e)&&t.push(n.val[0]);return t}urlTestWithRegex(e,t,r){const n=t.exec(e);if(!n)return null;if(0===this.urlParams.length)return{};const i={};for(let e=0;e<this.urlParams.length;e++)i[this.urlParams[e]]=Oe(n[e+1],r);return i}},je=function(e){return new xe(e)};function Ie(e,t){const r=e.path,n=r.startsWith("~"),i=n?r.slice(1):r,a={name:e.name,path:i,absolute:n,parser:i?je(i):null,children:[],parent:t,nonAbsoluteChildren:[],absoluteDescendants:[],childrenByName:new Map,parentSegments:[],fullName:"",staticChildrenByFirstSegment:new Map};if(e.children)for(const t of e.children){const e=Ie(t,a);a.children.push(e)}return a}function Me(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)}}var Fe=new Map;function Le(e){const t=e.startsWith("/")?1:0;let r=e.indexOf("/",t);const n=e.indexOf("?",t);-1!==n&&(-1===r||n<r)&&(r=n);const i=-1===r?e.slice(t):e.slice(t,r);return""===i||i.startsWith(":")||i.startsWith("*")||i.includes("(")?null:i.toLowerCase()}function _e(e,t){for(const r of e.children)r.absolute&&t.push(r),_e(r,t)}function Ue(e){const t=[];return _e(e,t),t}function qe(e,t,r){const n={name:e.name,path:e.path,absolute:e.absolute,parser:e.parser,parent:t,children:[],nonAbsoluteChildren:[],absoluteDescendants:[],childrenByName:new Map,parentSegments:[],fullName:"",staticPath:null,paramTypeMap:{},staticChildrenByFirstSegment:Fe};if(e.parser){for(const t of e.parser.urlParams)n.paramTypeMap[t]="url";for(const t of e.parser.queryParams)n.paramTypeMap[t]="query"}n.fullName=function(e){return e.parent?.name?`${e.parent.fullName}.${e.name}`:e.name}(n);for(const t of e.children){const e=qe(t,n,r);n.children.push(e),n.childrenByName.set(e.name,e),e.absolute||n.nonAbsoluteChildren.push(e)}return n.absoluteDescendants=Ue(n),n.parentSegments=function(e){const t=[];let r=e.parent;for(;r?.parser;)t.push(r),r=r.parent;return t.reverse(),t}(n),n.staticPath=function(e){const t=e.parser;if(!t)return null;if(t.hasUrlParams||t.hasQueryParams||t.hasSpatParam)return null;let r="";for(const t of e.parentSegments){const e=t.parser;if(e.hasUrlParams||e.hasQueryParams||e.hasSpatParam)return null;r=t.absolute?t.path:r+t.path}return r=e.absolute?e.path:r+e.path,r.replaceAll(/\/{2,}/g,"/")}(n),n.staticChildrenByFirstSegment=function(e,t){if(0===e.length)return Fe;const r=new Map;for(const t of e){const e=Le(t.path);if(null!==e){const n=r.get(e);n?n.push(t):r.set(e,[t])}}if(0===r.size)return Fe;if(t)for(const[e,t]of r)r.set(e,Object.freeze(t));return r}(n.nonAbsoluteChildren,r),r&&(Object.freeze(n.children),Object.freeze(n.nonAbsoluteChildren),Object.freeze(n.absoluteDescendants),Object.freeze(n.parentSegments),Object.freeze(n.paramTypeMap),Object.freeze(n)),n}function Ve(e){let t="",r=0;for(const n of e)"<"===n?r++:">"===n?r--:0===r&&(t+=n);return function(e){return e.endsWith("/")&&e.length>1?e.slice(0,-1):e}(t.split("?")[0])}function ze(e){!function(e){if(e.length<=1)return;const t=new Map;for(const[r,n]of e.entries()){const e=Ve(n.path),i=e.split("/"),a=i.at(-1);t.set(n,{normalizedPath:e,segmentCount:i.length-1,lastSegmentLength:a.length,originalIndex:r})}e.sort((e,r)=>{const n=t.get(e),i=t.get(r);if("/"===n.normalizedPath)return 1;if("/"===i.normalizedPath)return-1;if(e.parser.hasSpatParam)return 1;if(r.parser.hasSpatParam)return-1;if(n.segmentCount<i.segmentCount)return 1;if(n.segmentCount>i.segmentCount)return-1;const a=e.parser.urlParams.length,s=r.parser.urlParams.length;return a<s?-1:a>s||n.lastSegmentLength<i.lastSegmentLength?1:n.lastSegmentLength>i.lastSegmentLength?-1:n.originalIndex-i.originalIndex})}(e.children);for(const t of e.children)ze(t)}function We(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=Ie({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=Ie(e,n);n.children.push(t)}else i.push(e);for(const e of i){const{parent:t,finalName:r}=Me(n,e.name),i=Ie({name:r,path:e.path,children:e.children},t);t.children.push(i)}return n}(e,t,r);return n?.skipSort||ze(i),function(e,t=!0){return qe(e,null,t)}(i,!n?.skipFreeze)}}}function Be(e,t,r,n){return We(e,t).addMany(r).build(n)}var He=/^\/(\?|$)/,Qe=/\/$/,Ze=/^\/\?/;function Ke(e){const t=e.startsWith("/")?1:0,r=e.charAt(t);return":"===r||"*"===r||""===r||"("===e.charAt(t)}var Ge={caseSensitive:!1,strictTrailingSlash:!1},Je={caseSensitive:!1,strictTrailingSlash:!0},Ye={caseSensitive:!0,strictTrailingSlash:!1},Xe={caseSensitive:!0,strictTrailingSlash:!0},et={caseSensitive:!1,delimited:!0},tt={caseSensitive:!0,delimited:!0},rt={caseSensitive:!1,delimited:!1},nt={caseSensitive:!0,delimited:!1},it={queryParamsMode:"default",strictTrailingSlash:!1,strongMatching:!0,caseSensitive:!1,queryParams:void 0,urlParamsEncoding:void 0,fullTestOptions:Ge,partialTestOptions:et,buildOptions:{ignoreSearch:!0}};function at(e,t,r,n,i,a){for(const s of e){if(a&&!Ke(s.path))continue;const e=st(s,t,r,n,!1,i);if(void 0!==e)return e}return null}function st(e,t,r,n,i,a){const s=e.parser,o=function(e,t,r){return"/"===r&&"/"===t?`/${e}`:e}(t,e.path,a),c=function(e,t,r,n){if(0===e.children.length){const e=t.test(r,n.fullTestOptions);if(e)return e}return t.partialTest(r,n.partialTestOptions)}(e,s,o,n);if(!c)return;const l=0===e.children.length,u=function(e,t,r,n){let i=e.build(t,r.buildOptions);return!r.strictTrailingSlash&&n&&(i=i.replace(Qe,"")),i}(s,c,n,l),d=function(e,t,r,n,i,a){let s=e.slice(t.length);!r.strictTrailingSlash&&n&&(s=s.replace(Ze,"?"));const{querystring:o}=((e,t,r)=>{const n=ue(e);if(""===n)return{querystring:"",removedParams:{}};if(0===t.length)return{querystring:e.startsWith("?")?e:n,removedParams:{}};const i=oe(r),a=e.startsWith("?"),s=new Set(t),o=[],c=[];!function(e,t){let r=0;const n=e.length;for(;r<n;){let i=e.indexOf("&",r);-1===i&&(i=n),t(e.slice(r,i)),r=i+1}}(n,e=>{const t=e.indexOf("="),r=-1===t?e:e.slice(0,t),{name:n}=de(r);s.has(n)?c.push(e):o.push(e)});const l=o.join("&");return{querystring:a&&l?`?${l}`:l,removedParams:fe(c.join("&"),i)}})(function(e){const t=e.indexOf("?");return-1===t?"":e.slice(t+1)}(e.slice(t.length)),a.queryParams,r.queryParams);return s=function(e){const t=e.indexOf("?");return-1===t?e:e.slice(0,t)}(s)+(o?`?${o}`:""),r.strictTrailingSlash||i||"/"!==s||t.endsWith("/")||(s=""),s}(o,u,n,l,i,s);return r.segments.push(e),Object.assign(r.params,c),function(e,t,r,n,i,a){return i||0!==r.length?function(e,t,r){return!r&&"strict"!==t.queryParamsMode&&e.startsWith("?")}(r,n,i)?function(e,t){return r=t.slice(1),n=e.params,""!==r&&pe(r,n),e;var r,n}(t,r):0===e.nonAbsoluteChildren.length?null:function(e,t,r,n,i){const a=e.staticChildrenByFirstSegment,s=e.nonAbsoluteChildren;if(0===a.size)return at(s,t,r,n,i,!1);const o=function(e){let t=e.indexOf("/",1);const r=e.indexOf("?",1);return-1!==r&&(-1===t||r<t)&&(t=r),(-1===t?e.slice(1):e.slice(1,t)).toLowerCase()}(t),c=a.get(o);if(c){const e=at(c,t,r,n,i,!1);if(null!==e)return e}return at(s,t,r,n,i,!0)}(e,r,t,n,a):t}(e,r,d,n,i,u)}function ot(e,t){const r=[],n=t.includes(".")?t.split("."):[t];e.parser&&r.push(e);let i=e;for(const e of n){const t=i.childrenByName.get(e);if(!t)return null;r.push(t),i=t}return r}var ct=class extends Error{constructor(e){super(e),this.name="RouteNodeError",Object.setPrototypeOf(this,new.target.prototype)}},lt=class extends ct{routeName;constructor(e,t){super(e),this.name="RouteNotFoundError",this.routeName=t}},ut=Object.freeze([]);function dt(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 e=n.parser;if(e.queryParams.length>0){t??=[];for(let r=0;r<e.queryParams.length;r++)t.push(e.queryParams[r])}if(e.urlParams.length>0||e.spatParams.length>0){r??=[];for(let t=0;t<e.urlParams.length;t++)r.push(e.urlParams[t]);for(let t=0;t<e.spatParams.length;t++)r.push(e.spatParams[t])}}return{searchParams:t??ut,nonSearchParams:r??ut}}(e),s=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),o=function(e,t,r){const n={};for(const r of e)r in t&&(n[r]=t[r]);return ge(n,r.queryParams)}(s,t,r),c=function(e,t,r){const n={ignoreSearch:!0,queryParams:r.queryParams,urlParamsEncoding:r.urlParamsEncoding};let i="";for(const r of e){const e=r.parser.build(t,n);i=r.absolute?e:i+e}return i.replaceAll(/\/{2,}/g,"/")}(e,t,r);return l=c,("always"===(u=i)?l.endsWith("/")?l:`${l}/`:"never"===u&&"/"!==l&&l.endsWith("/")?l.slice(0,-1):l)+(o?`?${o}`:"");var l,u}function ht(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return t}function ft(e){const t={name:e.name,path:e.absolute?`~${e.path}`:e.path};return e.children.length>0&&(t.children=e.children.map(e=>ft(e))),t}function pt(e,t){return new TypeError(`[router.${e}] ${t}`)}var gt=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/,mt=/\S/;function vt(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function yt(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 ${vt(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${vt(e)}`);if(function(e){for(const t of Object.keys(e)){const r=Object.getOwnPropertyDescriptor(e,t);if(r&&(r.get||r.set))return!0}return!1}(e))throw new TypeError(`[router.${t}] Route must not have getters or setters`)}(e,t);const s=e;!function(e,t){if("string"!=typeof e.name)throw new TypeError(`[router.${t}] Route name must be a string, got ${vt(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!mt.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("@@")&&!gt.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").`)}(s,t),function(e,t,r,n){if("string"!=typeof e){let t;throw t=null===e?"null":Array.isArray(e)?"array":typeof e,pt(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw pt(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw pt(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw pt(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const i=n?.parser&&("urlParams"in n.parser&&n.parser.urlParams.length>0||"hasUrlParams"in n.parser&&n.parser.hasUrlParams);if(e.startsWith("~")&&i)throw new Error(`[router.${r}] Absolute path "${e}" cannot be used under parent route with URL parameters`)}(s.path,s.name,t,r),function(e,t){if(void 0!==e.encodeParams&&"function"!=typeof e.encodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}(s,t),function(e,t){if(void 0!==e.decodeParams&&"function"!=typeof e.decodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}(s,t);const o=s.name,c=n?`${n}.${o}`:o;!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.childrenByName.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.childrenByName.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=s.path;let u=n;if(o.includes(".")&&!n){const e=o.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.childrenByName.get(t),!n)return}for(const e of n.children)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!==s.children){if(!Array.isArray(s.children))throw new TypeError(`[router.${t}] Route "${o}" children must be an array, got ${vt(s.children)}`);for(const e of s.children)yt(e,t,r,c,i,a)}}var wt=new Set;function bt(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>bt(e))),t}function Tt(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}.`)&&Tt(i.children,t,a))return!0}return!1}function Rt(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function St(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)St(r,`${t}.${r.name}`)}function Pt(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 Pt(r))t.add(e);return t}function At(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 At(i.children,t,e,a)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function Ot(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 Ot(n.children,e))r.add(t)}return r}function $t(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 $t(n.children,e))r.set(t,i)}return r}function Nt(e,t,r,n){return t?function(e){const t=new Set;for(const r of e){for(const e of r.parser.urlParams)t.add(e);for(const e of r.parser.spatParams)t.add(e)}return t}(ot(r,e)):Et(At(n,e))}function Ct(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.childrenByName.get(e),!n)return!1;return!0}(i,t),s=n.has(t);if(!a&&!s)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const o=Et(At(r,e)),c=[...Nt(t,a,i,r)].filter(e=>!o.has(e));if(c.length>0)throw new Error(`[router.addRoute] forwardTo target "${t}" requires params [${c.join(", ")}] that are not available in source route "${e}"`)}function Dt(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 kt(e,t,r){const n=Ot(e),i=$t(e),a={...t};for(const[e,t]of i)a[e]=t;for(const[t,a]of i)Ct(t,a,e,n,r);for(const e of Object.keys(a))Dt(e,a)}function xt(e,t){const r=t??function(e){let t="";for(const r of e)r.name&&(t&&(t+="."),t+=r.name);return t}(e.segments);return{name:r,params:e.params,meta:ht(e.segments)}}var jt=".";function It(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function Mt(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 Ft(e){if(!e)return[""];const t=e.indexOf(jt);if(-1===t)return[e];const r=e.indexOf(jt,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(jt,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(jt,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(jt),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:Ft(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:Ft(e.name),toDeactivate:It(Ft(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:Ft(e.name),toDeactivate:It(Ft(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=Ft(e.name),a=Ft(t.name),s=function(e,t,r,n,i){for(let a=0;a<i;a++){const i=r[a],s=n[a];if(i!==s)return a;const o=Mt(i,e),c=Mt(s,t),l=Object.keys(o),u=Object.keys(c);if(l.length!==u.length)return a;for(const e of l)if(o[e]!==c[e])return a}return i}(e,t,i,a,Math.min(a.length,i.length)),o=[];for(let e=a.length-1;e>=s;e--)o.push(a[e]);const c=i.slice(s);return{intersection:s>0?a[s-1]:"",toDeactivate:o,toActivate:c}}var _t=class{#N=[];#C=function(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null)}}();#D=Object.create(null);#k=new Map;#x="";#j;#I;#f;#M;#F;constructor(e=[],t=!1){this.#F=t;for(const t of e)this.#N.push(bt(t));this.#j=Be("",this.#x,this.#N),this.#L(e),t?this.#_():this.#U()}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)}`);St(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&&!o(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(!o(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)yt(r,"addRoute",t,"",n,i);t&&r&&kt(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.#M=e}getRootPath(){return this.#x}getTree(){return this.#j}getForwardRecord(){return this.#C.forwardMap}setRootPath(e){this.#x=e,this.#q()}hasRoute(e){return function(e,t){const r=t.includes(".")?t.split("."):[t];let n=e;for(const e of r){const t=n.childrenByName.get(e);if(!t)return!1;n=t}return!0}(this.#j,e)}getRoute(e){const t=ot(this.#j,e);if(!t)return;const r=ft(t.at(-1));return this.#V(r,e)}addRoutes(e){for(const t of e)this.#N.push(bt(t));this.#L(e),this.#q(),this.#z()}removeRoute(e){return!!Tt(this.#N,e)&&(this.#W(e),this.#q(),this.#z(),!0)}updateRouteConfig(e,t){if(void 0!==t.forwardTo&&(null===t.forwardTo?delete this.#C.forwardMap[e]:this.#C.forwardMap[e]=t.forwardTo,this.#z()),void 0!==t.defaultParams&&(null===t.defaultParams?delete this.#C.defaultParams[e]:this.#C.defaultParams[e]=t.defaultParams),void 0!==t.decodeParams)if(null===t.decodeParams)delete this.#C.decoders[e];else{const r=t.decodeParams;this.#C.decoders[e]=e=>r(e)??e}if(void 0!==t.encodeParams)if(null===t.encodeParams)delete this.#C.encoders[e];else{const r=t.encodeParams;this.#C.encoders[e]=e=>r(e)??e}}clearRoutes(){this.#N.length=0;for(const e in this.#C.decoders)delete this.#C.decoders[e];for(const e in this.#C.encoders)delete this.#C.encoders[e];for(const e in this.#C.defaultParams)delete this.#C.defaultParams[e];for(const e in this.#C.forwardMap)delete this.#C.forwardMap[e];for(const e in this.#D)delete this.#D[e];this.#q()}buildPath(e,t,r,n){if(e===m.UNKNOWN_ROUTE)return l(t?.path)?t.path:"";const i=Object.hasOwn(this.#C.defaultParams,e)?{...this.#C.defaultParams[e],...t}:t??{},a="function"==typeof this.#C.encoders[e]?this.#C.encoders[e]({...i}):i,s=this.#I??C(r);return function(e,t,r={},n={},i){if(i)return dt(i,r,n);const a=function(e){for(const t in e)if(Object.hasOwn(e,t))return!0;return!1}(r),s=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&&!s){const r=function(e,t){if(t.includes(".")){const r=ot(e,t),n=r?.at(-1)?.staticPath;return n??null}return e.childrenByName.get(t)?.staticPath??null}(e,t);if(null!==r)return r}const o=ot(e,t);if(!o)throw new lt(`[route-node][buildPath] '${t}' is not defined`,t);return dt(o,r,n)}(this.#j,e,a,s,n)}matchPath(e,t,r){const n=r,i=function(e){return{...C(e),caseSensitive:e.caseSensitive,strictTrailingSlash:"strict"===e.trailingSlash,strongMatching:!1}}(n),a=function(e,t,r={}){let n=t;""!==n||r.strictTrailingSlash||(n="/");const i=function(e,t,r){const n=[];if(e.parser){n.push(e);for(let t=0;t<e.absoluteDescendants.length;t++)n.push(e.absoluteDescendants[t])}else for(const t of e.children){n.push(t);for(let e=0;e<t.absoluteDescendants.length;e++)n.push(t.absoluteDescendants[e])}const i=function(e){return void 0===e.queryParamsMode&&void 0===e.strictTrailingSlash&&void 0===e.strongMatching&&void 0===e.caseSensitive&&void 0===e.queryParams&&void 0===e.urlParamsEncoding&&void 0===e.trailingSlashMode||void 0!==e.trailingSlashMode&&void 0===e.queryParamsMode&&void 0===e.strictTrailingSlash&&void 0===e.strongMatching&&void 0===e.caseSensitive&&void 0===e.queryParams&&void 0===e.urlParamsEncoding?it:function(e){const t=e.queryParamsMode??"default",r=e.strictTrailingSlash??!1,n=e.strongMatching??!0,i=e.caseSensitive??!1,{queryParams:a,urlParamsEncoding:s}=e,o=void 0===a&&void 0===s;return{queryParamsMode:t,strictTrailingSlash:r,strongMatching:n,caseSensitive:i,queryParams:a,urlParamsEncoding:s,fullTestOptions:o?function(e,t){return e?t?Xe:Ye:t?Je:Ge}(i,r):{caseSensitive:i,strictTrailingSlash:r,queryParams:a,urlParamsEncoding:s},partialTestOptions:o?function(e,t){return e?t?tt:nt:t?et:rt}(i,n):{caseSensitive:i,delimited:n,queryParams:a,urlParamsEncoding:s},buildOptions:{ignoreSearch:!0,urlParamsEncoding:s}}}(e)}(r);return function(e,t,r,n){const i=1===e.length&&""===e[0].name;for(const a of e){const e=st(a,t,r,n,i,void 0);if(void 0!==e)return e}return null}(n,t,{segments:[],params:{}},i)}(e,n,r);if(!i)return null;const a=i.segments;if(a[0]?.absolute){const e=a[0].parentSegments;for(let t=e.length-1;t>=0;t--)a.unshift(e[t])}const s=a.at(-1).nonAbsoluteChildren.find(e=>e.parser&&He.test(e.parser.path));return s&&a.push(s),{segments:a,params:i.params}}(this.#j,e,i);if(a){const r=xt(a),{name:i,params:s,meta:o}=r,c="function"==typeof this.#C.decoders[i]?this.#C.decoders[i](s):s,{name:l,params:u}=this.forwardState(i,c),d=n.rewritePathOnMatch?this.buildPath(l,u,n):e;return this.#f.makeState(l,u,d,{params:o,options:{},source:t,redirected:!1})}}forwardState(e,t){const r=this.#D[e]??e,n=Object.hasOwn(this.#C.defaultParams,e)?{...this.#C.defaultParams[e],...t}:{...t};return r!==e&&Object.hasOwn(this.#C.defaultParams,r)?{name:r,params:{...this.#C.defaultParams[r],...n}}:{name:r,params:n}}buildStateResolved(e,t){const r=ot(this.#j,e);if(r)return xt({segments:r,params:t},e)}buildStateWithSegmentsResolved(e,t){const r=ot(this.#j,e);if(r)return{state:xt({segments:r,params:t},e),segments:r}}initBuildOptionsCache(e){this.#I=C(e)}clearBuildOptionsCache(){this.#I=void 0}isActiveRoute(e,t={},r=!1,n=!0){wt.has(e)||(h(e,"isActiveRoute"),wt.add(e));const i=this.#f.getState();if(!i)return!1;const a=i.name;if(a!==e&&!a.startsWith(`${e}.`)&&!e.startsWith(`${a}.`))return!1;const s=this.#C.defaultParams[e];if(r||a===e){const r={name:e,params:s?{...s,...t}:t,path:""};return this.#f?.areStatesEqual(r,i,n)??!1}const o=i.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(t,o)&&(!s||function(e,t,r){for(const n in e)if(!(n in r)&&e[n]!==t[n])return!1;return!0}(s,o,t))}shouldUpdateNode(e){return(t,r)=>{if(!t||"object"!=typeof t||!("name"in t))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(t.meta?.options.reload)return!0;if(""===e&&!r)return!0;const{intersection:n,toActivate:i,toDeactivate:a}=Lt(t,r);return e===n||!!i.includes(e)||a.includes(e)}}getConfig(){return this.#C}getUrlParams(e){const t=ot(this.#j,e);return t?this.#B(t):[]}getResolvedForwardMap(){return this.#D}setResolvedForwardMap(e){Object.assign(this.#D,e)}cloneRoutes(){return this.#j.children.map(e=>ft(e))}validateForwardToParamCompatibility(e,t){const r=ot(this.#j,e),n=ot(this.#j,t),i=this.#H(r),a=this.#B(n).filter(e=>!i.has(e));if(a.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${a.join(", ")}] that are not available in source route "${e}"`)}validateForwardToCycle(e,t){Dt(e,{...this.#C.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)}}#q(){this.#j=Be("",this.#x,this.#N)}#H(e){const t=new Set;for(const r of e)for(const e of r.parser.urlParams)t.add(e);return t}#B(e){const t=[];for(const r of e)for(const e of r.parser.urlParams)t.push(e);return t}#z(){this.#F?this.#_():this.#U()}#U(){for(const e in this.#D)delete this.#D[e];for(const e of Object.keys(this.#C.forwardMap))this.#D[e]=Dt(e,this.#C.forwardMap)}#_(){for(const e in this.#D)delete this.#D[e];for(const e of Object.keys(this.#C.forwardMap)){let t=e;for(;this.#C.forwardMap[t];)t=this.#C.forwardMap[t];this.#D[e]=t}}#W(e){const t=t=>t===e||t.startsWith(`${e}.`);if(Rt(this.#C.decoders,t),Rt(this.#C.encoders,t),Rt(this.#C.defaultParams,t),Rt(this.#C.forwardMap,t),Rt(this.#C.forwardMap,e=>t(this.#C.forwardMap[e])),this.#M){const[e,r]=this.#M.getFactories();for(const e of Object.keys(r))t(e)&&this.#M.clearCanActivate(e,!0);for(const r of Object.keys(e))t(r)&&this.#M.clearCanDeactivate(r,!0)}}#L(e,t=""){for(const r of e){const e=t?`${t}.${r.name}`:r.name;this.#Q(r,e),r.children&&this.#L(r.children,e)}}#Q(e,t){e.canActivate&&(this.#f?this.#f.canActivate(t,e.canActivate):this.#k.set(t,e.canActivate)),e.forwardTo&&this.#Z(e,t),e.decodeParams&&(this.#C.decoders[t]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(this.#C.encoders[t]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(this.#C.defaultParams[t]=e.defaultParams)}#Z(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.#C.forwardMap[r]=t.forwardTo}#V(e,t){const r={name:e.name,path:e.path},n=this.#C.forwardMap[t];if(n&&(r.forwardTo=n),t in this.#C.defaultParams&&(r.defaultParams=this.#C.defaultParams[t]),t in this.#C.decoders&&(r.decodeParams=this.#C.decoders[t]),t in this.#C.encoders&&(r.encodeParams=this.#C.encoders[t]),this.#M){const[,e]=this.#M.getFactories();t in e&&(r.canActivate=e[t])}return e.children&&(r.children=e.children.map(e=>this.#V(e,`${t}.${e.name}`))),r}},Ut=()=>{};function qt(t,...r){try{t(...r)}catch(t){e.logger.error("router.navigate","Error in navigation callback:",t)}}var Vt={log:0,warn:1,error:2},zt={all:0,"warn-error":1,"error-only":2,none:3},Wt=new class{#C={level:"all",callbackIgnoresLevel:!1};#K=0;configure(e){if(void 0!==e.level){if(!(e.level in zt))throw new Error(`Invalid log level: "${e.level}". Valid levels are: ${Object.keys(zt).join(", ")}`);this.#C.level=e.level,this.#K=zt[e.level]}"callback"in e&&(this.#C.callback=e.callback),void 0!==e.callbackIgnoresLevel&&(this.#C.callbackIgnoresLevel=e.callbackIgnoresLevel)}getConfig(){return{level:this.#C.level,callback:this.#C.callback,callbackIgnoresLevel:this.#C.callbackIgnoresLevel}}log(e,t,...r){this.#G("log",e,t,r)}warn(e,t,...r){this.#G("warn",e,t,r)}error(e,t,...r){this.#G("error",e,t,r)}#G(e,t,r,n){if("none"===this.#C.level&&!this.#C.callbackIgnoresLevel)return;const i=Vt[e]<this.#K;i||this.#J(e,t,r,n),this.#Y(e,t,r,i,n)}#J(e,t,r,n){"undefined"!=typeof console&&"function"==typeof console[e]&&console[e](t?`[${t}] ${r}`:r,...n)}#Y(e,t,r,n,i){if(this.#C.callback&&(this.#C.callbackIgnoresLevel||!n))try{this.#C.callback(e,t,r,...i)}catch(e){"undefined"!=typeof console&&"function"==typeof console.error&&console.error("[Logger] Error in callback:",e)}}},Bt=(e,t)=>{if(t)return t.setCode(e),t},Ht=(e,t)=>{const r=e.meta,n=t.meta,i=r?.params,a=n?.params,s=i&&a?{...i,...a}:i??a??{},o={id:1,options:{},redirected:!1,...n,...r,params:s};return{...e,meta:o}},Qt=new Set(Object.values(g)),Zt=new Set(["code","segment","path","redirect"]),Kt=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),Gt=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(Zt.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);Kt.has(e)||(this[e]=t)}}setCode(e){this.code=e,Qt.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(Zt.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);Kt.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}},Jt=(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 Gt(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 Gt(g.TRANSITION_ERR,r))}):t(new Gt(g.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})):e?t():t(new Gt(g.TRANSITION_ERR,n)))};function Yt(e,t,r,n){try{e(t,r)}catch(e){Wt.error(n,"Error in callback:",e)}}var Xt=new Set(["code","segment","path","redirect"]);function er(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))Xt.has(r)||(t[r]=n);return{...r,...t}}return r}var tr="core:lifecycle",rr=(e,t,r,n,i,a,s)=>{let o=t;const l=n.filter(t=>e.has(t));if(0===l.length)return void Yt(s,void 0,o,tr);let u=0;const d=(e,t)=>{if(e)if(e.redirect){const t=new Gt(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 Yt(s,new Gt(g.TRANSITION_CANCELLED),o,tr);if(t)return void Yt(s,Bt(i,t),o,tr);if(n&&n!==o&&c(n)){if(n.name!==o.name){const e=new Gt(i,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:n.name,params:n.params,path:n.path}});return void Yt(s,e,o,tr)}(n.params!==o.params||n.path!==o.path)&&Wt.error("core:transition","Warning: State mutated during transition",{from:o,to:n}),o=Ht(n,o)}if(u>=l.length)return void Yt(s,void 0,o,tr);const h=l[u++],f=e.get(h);try{const e=f(o,r,d);Jt(e,d,h)}catch(e){d(new Gt(g.TRANSITION_ERR,er(e,h)))}};h()},nr="core:middleware";function ir(e,t,r,n,i){let a=!1,s=!1;const[o,l]=e.getLifecycleFunctions(),u=e.getMiddlewareFunctions(),d=t.name===m.UNKNOWN_ROUTE,h=()=>a||!e.isActive(),f=(e,r)=>{s||(s=!0,i(e,r??t))};return(()=>{const{toDeactivate:i,toActivate:a}=Lt(t,r),s=!d&&a.length>0,p=u.length>0,m=(n,i)=>{if(n)f(n,i);else{if(r){const n=Ft(t.name),i=Ft(r.name),a=new Set(n);for(const t of i)!a.has(t)&&o.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,s=0;const o=(e,t)=>{e?l(e):l(void 0,t)},l=(t,l)=>{if(n())return void Yt(i,new Gt(g.TRANSITION_CANCELLED),a,nr);if(t)return void Yt(i,Bt(g.TRANSITION_ERR,t),a,nr);if(l&&l!==a&&c(l)&&((l.name!==a.name||l.params!==a.params||l.path!==a.path)&&Wt.error(nr,"Warning: State mutated during middleware execution",{from:a,to:l}),a=Ht(l,a)),s>=e.length)return void Yt(i,void 0,a,nr);const u=e[s++];try{const e=u(a,r,o);Jt(e,o)}catch(e){o(new Gt(g.TRANSITION_ERR,er(e)))}};l()})(u,e,r,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,m)};var y;y=(e,t)=>{e?f(e,t):((e,t)=>{s?rr(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?rr(o,t,r,i,g.CANNOT_DEACTIVATE,h,y):y(void 0,t)})(),()=>{a||s||(a=!0,f(new Gt(g.TRANSITION_CANCELLED)))}}var ar=()=>{},sr=Object.freeze({}),or=Object.freeze({});var cr=class{isRouterStarted;#X=!1;#ee=null;#f;#te;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:sr,opts:or,callback:e};const n=e??sr;return"function"==typeof t?{params:n,opts:or,callback:t}:{params:n,opts:t??or,callback:r??ar}}(e,t,r)}static parseNavigateToDefaultArgs(e,t){return function(e,t){return"function"==typeof e?{opts:or,callback:e}:{opts:e??or,callback:t??ar}}(e,t)}setDependencies(e){this.#f=e}setTransitionDependencies(e){this.#te=e}isNavigating(){return this.isRouterStarted()&&this.#X}cancel(){this.#ee&&(this.#ee(),this.#ee=null),this.#X=!1}navigateToState(t,r,n,i,a){const s=this.#f,o=this.#te;return this.#X&&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.#X=!0,s.invokeEventListeners(S.TRANSITION_START,t,r),this.#ee=ir(o,t,r,n,(e,o)=>{if(this.#X=!1,this.#ee=null,e)e.code===g.TRANSITION_CANCELLED?s.invokeEventListeners(S.TRANSITION_CANCEL,t,r):s.invokeEventListeners(S.TRANSITION_ERROR,t,r,e),qt(i,e);else if(o.name===m.UNKNOWN_ROUTE||s.hasRoute(o.name))s.setState(o),a&&s.invokeEventListeners(S.TRANSITION_SUCCESS,o,r,n),qt(i,void 0,o);else{const e=new Gt(g.ROUTE_NOT_FOUND,{routeName:o.name});qt(i,e),s.invokeEventListeners(S.TRANSITION_ERROR,void 0,s.getState(),e)}}),this.#ee}navigate(e,t,r,n){const i=this.#f;if(!this.isRouterStarted())return qt(n,new Gt(g.ROUTER_NOT_STARTED)),Ut;const a=i.buildStateWithSegments(e,t);if(!a){const e=new Gt(g.ROUTE_NOT_FOUND);return qt(n,e),i.invokeEventListeners(S.TRANSITION_ERROR,void 0,i.getState(),e),Ut}const{state:s,segments:o}=a,c=i.makeState(s.name,s.params,i.buildPath(s.name,s.params,o),{params:s.meta,options:r,redirected:r.redirected??!1});if(r.skipTransition)return qt(n,void 0,c),Ut;const l=i.getState();if(!r.reload&&!r.force&&i.areStatesEqual(l,c,!1)){const e=new Gt(g.SAME_STATES);return qt(n,e),i.invokeEventListeners(S.TRANSITION_ERROR,c,l,e),Ut}return this.navigateToState(c,l,r,n,!0)}navigateToDefault(e,t){const r=this.#f.getOptions();return r.defaultRoute?this.navigate(r.defaultRoute,r.defaultParams,e,t):Ut}},lr=()=>{},ur=new Gt(g.NO_START_PATH_OR_STATE),dr=new Gt(g.ROUTER_ALREADY_STARTED),hr=class{navigateToState;#re=!1;#ne=!1;#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.#re}isActive(){return this.#ne}start(...t){const r=this.#f,n=r.getOptions(),[i,a]=(e=>{const[t,r]=e;return t?"function"==typeof t?[void 0,t]:[t,r??lr]:[void 0,lr]})(t);let s=!1;if(this.#re||this.#ne)return s=!0,void a(dr);if(!i&&!n.defaultRoute)return s=!0,r.hasListeners(S.TRANSITION_ERROR)&&r.invokeEventListeners(S.TRANSITION_ERROR,void 0,void 0,ur),void a(ur);this.#ne=!0;const o={replace:!0},l=(t,n,i=!1)=>{t?(this.#ne=!1,i&&r.hasListeners(S.TRANSITION_ERROR)&&r.invokeEventListeners(S.TRANSITION_ERROR,void 0,void 0,t)):(this.#re=!0,r.invokeEventListeners(S.ROUTER_START),r.invokeEventListeners(S.TRANSITION_SUCCESS,n,void 0,{replace:!0})),((t,r)=>{s?e.logger.warn("real-router","Callback already invoked"):(s=!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,o):n.defaultRoute&&!i?((e,t,n)=>{const i=r.buildState(e,t);if(!i)return void l(new Gt(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,o):n.allowNotFound?u(r.makeNotFoundState(f,o),o):l(new Gt(g.ROUTE_NOT_FOUND,{path:f}),void 0,!0)}stop(){const e=this.#f;this.#ne=!1,this.#re&&(this.#re=!1,e.setState(),e.invokeEventListeners(S.ROUTER_STOP))}},fr=class{#ie;#ae;static validateCloneArgs(e){if(void 0!==e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.clone] Invalid dependencies: expected plain object or undefined, received ${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.#ie=e,this.#ae=t}clone(e,t){const r=this.#ie(),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.#ae(i,r.routeConfig,r.resolvedForwardMap),i}},pr=new Set(["all","warn-error","error-only"]);var gr=class t{#c;#t;#e;#se;#oe;#ce;#le;#ue;#b;#de;#he;#fe;#pe=null;#F;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)||!pr.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||k.validateDependenciesObject(n,"constructor"),!i&&t.length>0&&(_t.validateAddRouteArgs(t),_t.validateRoutes(t)),this.#c=new W(r),this.#t=function(e={}){return{...P,...e}}(r.limits),this.#e=new k(n),this.#se=new I,this.#oe=new H,this.#ce=new _t(t,i),this.#le=new X,this.#ue=new Z,this.#b=new Y,this.#de=new cr,this.#he=new hr,this.#fe=new fr,this.#F=i,this.#ge(),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.#F||(_t.validateAddRouteArgs(t),_t.validateRoutes(t,this.#ce.getTree(),this.#ce.getForwardRecord())),this.#ce.addRoutes(t),this}removeRoute(t){return this.#F||_t.validateRemoveRouteArgs(t),this.#ce.validateRemoveRoute(t,this.#oe.get()?.name,this.#de.isNavigating())?(this.#ce.removeRoute(t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),this):this}clearRoutes(){return this.#ce.validateClearRoutes(this.#de.isNavigating())?(this.#ce.clearRoutes(),this.#le.clearAll(),this.#oe.set(void 0),this):this}getRoute(e){return this.#F||h(e,"getRoute"),this.#ce.getRoute(e)}hasRoute(e){return this.#F||h(e,"hasRoute"),this.#ce.hasRoute(e)}updateRoute(t,r){this.#F||_t.validateUpdateRouteBasicArgs(t,r);const{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:s,canActivate:o}=r;return this.#F||_t.validateUpdateRoutePropertyTypes(n,i,a,s),this.#de.isNavigating()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),this.#F||this.#ce.validateUpdateRoute(t,n),this.#ce.updateRouteConfig(t,{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:s}),void 0!==o&&(null===o?this.#le.clearCanActivate(t,!0):this.canActivate(t,o)),this}isActiveRoute(t,r,n,i){return this.#F||_t.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.#ce.isActiveRoute(t,r,n,i)}buildPath(e,t){return this.#F||_t.validateBuildPathArgs(e),this.#ce.buildPath(e,t,this.#c.get())}matchPath(e,t){return this.#F||_t.validateMatchPathArgs(e),this.#ce.matchPath(e,t,this.#c.get())}setRootPath(e){this.#F||_t.validateSetRootPathArgs(e),this.#ce.setRootPath(e)}getRootPath(){return this.#ce.getRootPath()}makeState(e,t,r,n,i){return this.#F||H.validateMakeStateArgs(e,t,r,i),this.#oe.makeState(e,t,r,n,i)}getState(){return this.#oe.get()}getPreviousState(){return this.#oe.getPrevious()}areStatesEqual(e,t,r=!0){return this.#F||H.validateAreStatesEqualArgs(e,t,r),this.#oe.areStatesEqual(e,t,r)}forwardState(e,t){return this.#F||_t.validateStateBuilderArgs(e,t,"forwardState"),this.#ce.forwardState(e,t)}buildState(e,t){this.#F||_t.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:n}=this.forwardState(e,t);return this.#ce.buildStateResolved(r,n)}shouldUpdateNode(e){return this.#F||_t.validateShouldUpdateNodeArgs(e),this.#ce.shouldUpdateNode(e)}getOptions(){return this.#c.get()}getOption(e){return this.#F||(W.validateOptionName(e,"getOption"),W.validateOptionExists(e,"getOption")),this.#c.getOption(e)}setOption(e,t){return this.#F||(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.#he.isActive()}start(...e){return this.#F||hr.validateStartArgs(e),this.#c.lock(),this.#ce.initBuildOptionsCache(this.#c.get()),this.#he.start(...e),this}stop(){return this.#he.stop(),this.#ce.clearBuildOptionsCache(),this.#c.unlock(),this}canDeactivate(e,t){this.#F||(h(e,"canDeactivate"),X.validateHandler(t,"canDeactivate"),X.validateNotRegistering(this.#le.isRegistering(e),e,"canDeactivate"));const r=this.#le.hasCanDeactivate(e);return r||this.#F||X.validateHandlerLimit(this.#le.countCanDeactivate()+1,"canDeactivate",this.#t.maxLifecycleHandlers),this.#le.registerCanDeactivate(e,t,r),this}canActivate(e,t){this.#F||(h(e,"canActivate"),X.validateHandler(t,"canActivate"),X.validateNotRegistering(this.#le.isRegistering(e),e,"canActivate"));const r=this.#le.hasCanActivate(e);return r||this.#F||X.validateHandlerLimit(this.#le.countCanActivate()+1,"canActivate",this.#t.maxLifecycleHandlers),this.#le.registerCanActivate(e,t,r),this}usePlugin(...e){return this.#F||(Y.validateUsePluginArgs(e),Y.validatePluginLimit(this.#b.count(),e.length,this.#t.maxPlugins),Y.validateNoDuplicatePlugins(e,this.#b.has.bind(this.#b))),this.#b.use(...e)}useMiddleware(...e){this.#F||(Z.validateUseMiddlewareArgs(e),Z.validateNoDuplicates(e,this.#ue.getFactories()),Z.validateMiddlewareLimit(this.#ue.count(),e.length,this.#t.maxMiddleware));const t=this.#ue.initialize(...e);if(!this.#F)for(const{middleware:e,factory:r}of t)Z.validateMiddleware(e,r);return this.#ue.commit(t)}clearMiddleware(){return this.#ue.clear(),this}setDependency(e,t){return this.#F||k.validateSetDependencyArgs(e),this.#e.set(e,t),this}setDependencies(e){return this.#F||(k.validateDependenciesObject(e,"setDependencies"),k.validateDependencyLimit(this.#e.count(),Object.keys(e).length,"setDependencies",this.#t.maxDependencies)),this.#e.setMultiple(e),this}getDependency(e){this.#F||k.validateName(e,"getDependency");const t=this.#e.get(e);return this.#F||k.validateDependencyExists(t,e),t}getDependencies(){return this.#e.getAll()}removeDependency(e){return this.#F||k.validateName(e,"removeDependency"),this.#e.remove(e),this}hasDependency(e){return this.#F||k.validateName(e,"hasDependency"),this.#e.has(e)}resetDependencies(){return this.#e.reset(),this}addEventListener(e,t){return this.#F||I.validateListenerArgs(e,t),this.#se.addEventListener(e,t)}navigate(e,t,r,n){this.#F||cr.validateNavigateArgs(e);const{params:i,opts:a,callback:s}=cr.parseNavigateArgs(t,r,n);return this.#F||cr.validateNavigationOptions(a,"navigate"),this.#de.navigate(e,i,a,s)}navigateToDefault(e,t){this.#F||cr.validateNavigateToDefaultArgs(e,t);const{opts:r,callback:n}=cr.parseNavigateToDefaultArgs(e,t);return this.#F||cr.validateNavigationOptions(r,"navigateToDefault"),this.#de.navigateToDefault(r,n)}navigateToState(e,t,r,n,i){return this.#F||cr.validateNavigateToStateArgs(e,t,r,n,i),this.#de.navigateToState(e,t,r,n,i)}subscribe(e){return this.#F||I.validateSubscribeListener(e),this.#se.subscribe(e)}clone(e){return this.#F||fr.validateCloneArgs(e),this.#fe.clone(e,(e,r,n)=>new t(e,r,n))}getNavigator(){return this.#pe??=Object.freeze({navigate:this.navigate,getState:this.getState,isActiveRoute:this.isActiveRoute,subscribe:this.subscribe}),this.#pe}#ge(){this.#e.setLimits(this.#t),this.#b.setLimits(this.#t),this.#ue.setLimits(this.#t),this.#se.setLimits(this.#t),this.#le.setLimits(this.#t),this.#le.setRouter(this),this.#le.setDependencies({getDependency:e=>this.#e.get(e)}),this.#ce.setDependencies({canActivate:(e,t)=>{this.canActivate(e,t)},makeState:(e,t,r,n)=>this.#oe.makeState(e,t,r,n),getState:()=>this.#oe.get(),areStatesEqual:(e,t,r)=>this.#oe.areStatesEqual(e,t,r)}),this.#ce.setLifecycleNamespace(this.#le),this.#ue.setRouter(this),this.#ue.setDependencies({getDependency:e=>this.#e.get(e)}),this.#b.setRouter(this),this.#b.setDependencies({addEventListener:(e,t)=>this.#se.addEventListener(e,t),isStarted:()=>this.#he.isStarted(),getDependency:e=>this.#e.get(e)}),this.#de.setDependencies({getOptions:()=>this.#c.get(),hasRoute:e=>this.#ce.hasRoute(e),getState:()=>this.#oe.get(),setState:e=>{this.#oe.set(e)},buildStateWithSegments:(e,t)=>{const{name:r,params:n}=this.forwardState(e,t);return this.#ce.buildStateWithSegmentsResolved(r,n)},makeState:(e,t,r,n)=>this.#oe.makeState(e,t,r,n),buildPath:(e,t,r)=>this.#ce.buildPath(e,t,this.#c.get(),r),areStatesEqual:(e,t,r)=>this.#oe.areStatesEqual(e,t,r),invokeEventListeners:(e,t,r,n)=>{this.#se.invoke(e,t,r,n)}}),this.#de.setTransitionDependencies({getLifecycleFunctions:()=>this.#le.getFunctions(),getMiddlewareFunctions:()=>this.#ue.getFunctions(),isActive:()=>this.#he.isActive(),clearCanDeactivate:e=>{this.#le.clearCanDeactivate(e)}}),this.#he.setDependencies({getOptions:()=>this.#c.get(),hasListeners:e=>this.#se.hasListeners(e),invokeEventListeners:(e,t,r,n)=>{this.#se.invoke(e,t,r,n)},buildState:(e,t)=>this.buildState(e,t),makeState:(e,t,r,n)=>this.#oe.makeState(e,t,r,n),buildPath:(e,t)=>this.buildPath(e,t),makeNotFoundState:(e,t)=>this.#oe.makeNotFoundState(e,t),setState:e=>{this.#oe.set(e)},matchPath:(e,t)=>this.#ce.matchPath(e,t,this.#c.get())}),this.#oe.setDependencies({getDefaultParams:()=>this.#ce.getConfig().defaultParams,buildPath:(e,t)=>this.#ce.buildPath(e,t,this.#c.get()),getUrlParams:e=>this.#ce.getUrlParams(e)}),this.#de.isRouterStarted=()=>this.#he.isStarted(),this.#he.navigateToState=(e,t,r,n,i)=>this.#de.navigateToState(e,t,r,n,i),this.#fe.setCallbacks(()=>{const[e,t]=this.#le.getFactories();return{routes:this.#ce.cloneRoutes(),options:{...this.#c.get()},dependencies:this.#e.getAll(),canDeactivateFactories:e,canActivateFactories:t,middlewareFactories:this.#ue.getFactories(),pluginFactories:this.#b.getAll(),routeConfig:this.#ce.getConfig(),resolvedForwardMap:this.#ce.getResolvedForwardMap()}},(e,t,r)=>{const n=e,i=n.#ce.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.#ce.setResolvedForwardMap({...r})})}};exports.Router=gr,exports.RouterError=Gt,exports.constants=m,exports.createRouter=(e=[],t={},r={})=>new gr(e,t,r),exports.errorCodes=g,exports.events=S;//# 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,r){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 _(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&&U(r,n,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function U(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 z=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&&L(r,n,t):_(r,n,t)}(e,t)}get(){return this.#c}getOption(e){return this.#c[e]}};function V(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>V(e,t[r]))}var q=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=>V(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&&V(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 W(e){return e.name||"anonymous"}var H=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: ${W(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: ${W(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.`)}},B={[v]:R.ROUTER_START,[w]:R.ROUTER_STOP,[S]:R.TRANSITION_SUCCESS,[y]:R.TRANSITION_START,[T]:R.TRANSITION_ERROR,[b]:R.TRANSITION_CANCEL},Q=Object.keys(B).filter(e=>d(e,B)),K="router.usePlugin",G=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,B))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(K,"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(K,"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(K,"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(K,`${n} plugins registered!`):n>=i&&e.logger.warn(K,`${n} plugins registered`)}#R(t){const r=new Set;for(const n of t)r.has(n)?e.logger.warn(K,"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 Q)t in n&&("function"==typeof n[t]?(i.push(this.#p.addEventListener(B[t],n[t])),"onStart"===t&&this.#p.isStarted()&&e.logger.warn(K,"Router already started, onStart will not be called")):e.logger.warn(K,`Property '${t}' is not a function, skipping`));return()=>{for(const e of i)e();"function"==typeof n.teardown&&n.teardown()}}},J=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 Z(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=Z(t,a);a.children.push(e)}return a}function Y(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 X(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var ee=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,te=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,re=/\?(.+)$/,ne=/[^\w!$'()*+,.:;|~-]/gu,ie=/[^\w!$'()*+,.:;|~-]/u,ae={default:e=>ie.test(e)?e.replaceAll(ne,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},oe={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function se(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function ce(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function le(e){const t={};if(0===e.length)return t;const r=e.split("&");for(const e of r){const r=e.indexOf("=");-1===r?t[e]="":t[e.slice(0,r)]=e.slice(r+1)}return t}function ue(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 de(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function he(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(!de(r)||!de(n))return!1;t+=3}else t++;return!0}var fe=/<[^>]*>/g;function pe(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(fe,""),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,ce(r)===ce(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=ce(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?ce(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=ae[r],n=e.split("/");let i=t(n[0]);for(let e=1;e<n.length;e++)i+=`/${t(n[e])}`;return i}:ae[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=ce(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=me(e,i,n.slice(a,r)),a=r+1}return i}(i=e,i.root,r)).slashChildRoute=n;const a=ce(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=ce(r);"/"!==n?ge(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())pe(e,r,u,n,f);a||n.pop()}function ge(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(fe,"").replace(/\?$/,"");return t.paramChild??={node:se(),name:n},ge(e,t.paramChild.node,r,s+1,i),void(s>=a?t.route??=i:ge(e,t,r,s+1,i))}t=me(e,t,c),n=s+1}t.route=i}function me(e,t,r){if(r.startsWith("*")){const e=r.slice(1);return t.splatChild??={node:se(),name:e},t.splatChild.node}if(r.startsWith(":")){const e=r.slice(1).replaceAll(fe,"").replace(/\?$/,"");return t.paramChild??={node:se(),name:e},t.paramChild.node}const n=e.options.caseSensitive?r:r.toLowerCase();return n in t.staticChildren||(t.staticChildren[n]=se()),t.staticChildren[n]}var ve=/[\u0080-\uFFFF]/,we=class{get options(){return this.#C}#C;#D=se();#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??le,buildQueryString:e?.buildQueryString??ue}}registerTree(e){this.#x=e.paramMeta.queryParams,pe({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)),ve.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,ce(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=oe[t];for(const t in e){const n=e[t];if(n.includes("%")){if(!he(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 ye(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function be(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}function Se(e,t,r){const n=function(e){const t=[],r=[],n=[],i={},a=new Map,o=e.replaceAll(te,"$1"),s=re.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=ee.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=`^${X(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=Se(a,t,r);n.push(e),e.absolute||i.push(e)}return{childrenMap:be(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:ye(o,e.path)}return e.absolute?e.path:ye(o,e.path)}(a),r&&(Object.freeze(s),Object.freeze(i),Object.freeze(a.children),Object.freeze(a)),a}function Te(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=Z({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=Z(e,n);n.children.push(t)}else i.push(e);for(const e of i){const{parent:t,finalName:r}=Y(n,e.name),i=Z({name:r,path:e.path,children:e.children},t);t.children.push(i)}return n}(e,t,r);return function(e,t=!0){return Se(e,null,t)}(i,!n?.skipFreeze)}}}function Re(e,t,r,n){return Te(e,t).addMany(r).build(n)}function Ee(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=>Ee(e))),t}var Ae=e=>{const t=e.indexOf("%"),r=e.indexOf("+");if(-1===t&&-1===r)return e;const n=-1===r?e:e.split("+").join(" ");return-1===t?n:decodeURIComponent(n)},Oe=e=>{const t=typeof e;if("string"!==t&&"number"!==t&&"boolean"!==t)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===t&&null===e?"null":t}`);return encodeURIComponent(e)},$e={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${Oe(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${Oe(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${Oe(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>Oe(e)).join(",")}`}},Pe={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}},Ne={default:{encode:e=>e},hidden:{encode:()=>""}},Ce=(e,t,r)=>({boolean:Pe[t],null:Ne[r],array:$e[e]}),De={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:Pe.none,null:Ne.default,array:$e.none}},je=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return De;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:Ce(t,r,n)}},ke=e=>encodeURIComponent(e),Ie=(e,t,r)=>{const n=ke(e);switch(typeof t){case"string":case"number":default:return`${n}=${ke(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}=${ke(t)}`}};function Me(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,Ae(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=Ae(e);return t.boolean.decodeValue(n)})(n?e.slice(t+1,r):void 0,i):n?Ae(e.slice(t+1,r)):null}(e,a,r,o,i),l)}function Fe(e){const t=e?.queryParams;return new we({...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),Me(e,r,i,t),r=i+1}}(e,t),t}(r);const n=je(t),i={};let a=0;const o=r.length;for(;a<o;){let e=r.indexOf("&",a);-1===e&&(e=o),Me(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=je(t),i=[];for(const t of r){const r=e[t];if(void 0===r)continue;const a=Ie(t,r,n);a&&i.push(a)}return i.join("&")})(e,t)})}function xe(e,t){return new TypeError(`[router.${e}] ${t}`)}var Le=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/,_e=/\S/;function Ue(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function ze(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 Ve(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 ${Ue(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${Ue(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 ${Ue(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!_e.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("@@")&&!Le.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,xe(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw xe(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw xe(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw xe(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 xe(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(!ze(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(ze(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:ze(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 ${Ue(o.children)}`);for(const e of o.children)Ve(e,t,r,c,i,a)}}var qe=new Set;function We(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>We(e))),t}function He(e,t,r=""){for(let n=0;n<e.length;n++){const i=e[n],a=r?`${r}.${i.name}`:i.name;if(a===t)return e.splice(n,1),!0;if(i.children&&t.startsWith(`${a}.`)&&He(i.children,t,a))return!0}return!1}function Be(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function Qe(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)Qe(r,`${t}.${r.name}`)}function Ke(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 Ge(e){const t=new Set;for(const r of e)for(const e of Ke(r))t.add(e);return t}function Je(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 Je(i.children,t,e,a)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function Ze(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 Ze(n.children,e))r.add(t)}return r}function Ye(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 Ye(n.children,e))r.set(t,i)}return r}function Xe(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 Ge(Je(n,e))}function et(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=Ge(Je(r,e)),c=[...Xe(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 tt(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 rt(e,t,r){const n=Ze(e),i=Ye(e),a={...t};for(const[e,t]of i)a[e]=t;for(const[t,a]of i)et(t,a,e,n,r);for(const e of Object.keys(a))tt(e,a)}function nt(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}var it=".";function at(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function ot(e,t){const r=t.meta?.params[e];if(!r||"object"!=typeof r)return{};const 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 st(e){if(!e)return[""];const t=e.indexOf(it);if(-1===t)return[e];const r=e.indexOf(it,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(it,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(it,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(it),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 ct(e,t){if(!t)return{intersection:"",toActivate:st(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:st(e.name),toDeactivate:at(st(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:st(e.name),toDeactivate:at(st(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=st(e.name),a=st(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=ot(i,e),c=ot(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 lt=Object.freeze({}),ut=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(We(t));this.#ee=Re("",this.#X,this.#G),this.#te=Fe(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)}`);Qe(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)Ve(r,"addRoute",t,"",n,i);t&&r&&rt(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=Ee(this.#le(t));return this.#ue(r,e)}addRoutes(e){for(const t of e)this.#G.push(We(t));this.#ae(e),this.#ce(),this.#de()}removeRoute(e){return!!He(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=nt(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:lt,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 nt({segments:r,params:t,meta:this.#te.getMetaByName(e)??{}},e)}buildStateWithSegmentsResolved(e,t){const r=this.#te.getSegmentsByName(e);if(r)return{state:nt({segments:r,params:t,meta:this.#te.getMetaByName(e)??{}},e),segments:r}}isActiveRoute(e,t={},r=!1,n=!0){qe.has(e)||(h(e,"isActiveRoute"),qe.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}=ct(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=>Ee(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){tt(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=Re("",this.#X,this.#G),this.#te=Fe(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]=tt(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(Be(this.#J.decoders,t),Be(this.#J.encoders,t),Be(this.#J.defaultParams,t),Be(this.#J.forwardMap,t),Be(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}},dt=()=>{};function ht(t,...r){try{t(...r)}catch(t){e.logger.error("router.navigate","Error in navigation callback:",t)}}var ft={log:0,warn:1,error:2},pt={all:0,"warn-error":1,"error-only":2,none:3},gt=new class{#J={level:"all",callbackIgnoresLevel:!1};#we=0;configure(e){if(void 0!==e.level){if(!(e.level in pt))throw new Error(`Invalid log level: "${e.level}". Valid levels are: ${Object.keys(pt).join(", ")}`);this.#J.level=e.level,this.#we=pt[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=ft[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)}}},mt=(e,t)=>{if(t)return t.setCode(e),t},vt=(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}},wt=new Set(Object.values(g)),yt=new Set(["code","segment","path","redirect"]),bt=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),St=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(yt.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);bt.has(e)||(this[e]=t)}}setCode(e){this.code=e,wt.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(yt.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);bt.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}},Tt=(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 St(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 St(g.TRANSITION_ERR,r))}):t(new St(g.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})):e?t():t(new St(g.TRANSITION_ERR,n)))};function Rt(e,t,r,n){try{e(t,r)}catch(e){gt.error(n,"Error in callback:",e)}}var Et=new Set(["code","segment","path","redirect"]);function At(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))Et.has(r)||(t[r]=n);return{...r,...t}}return r}var Ot="core:lifecycle",$t=(e,t,r,n,i,a,o)=>{let s=t;const l=n.filter(t=>e.has(t));if(0===l.length)return void Rt(o,void 0,s,Ot);let u=0;const d=(e,t)=>{if(e)if(e.redirect){const t=new St(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 Rt(o,new St(g.TRANSITION_CANCELLED),s,Ot);if(t)return void Rt(o,mt(i,t),s,Ot);if(n&&n!==s&&c(n)){if(n.name!==s.name){const e=new St(i,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:n.name,params:n.params,path:n.path}});return void Rt(o,e,s,Ot)}(n.params!==s.params||n.path!==s.path)&>.error("core:transition","Warning: State mutated during transition",{from:s,to:n}),s=vt(n,s)}if(u>=l.length)return void Rt(o,void 0,s,Ot);const h=l[u++],f=e.get(h);try{const e=f(s,r,d);Tt(e,d,h)}catch(e){d(new St(g.TRANSITION_ERR,At(e,h)))}};h()},Pt="core:middleware";function Nt(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}=ct(t,r),o=!d&&a.length>0,p=u.length>0,m=(n,i)=>{if(n)f(n,i);else{if(r){const n=st(t.name),i=st(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 Rt(i,new St(g.TRANSITION_CANCELLED),a,Pt);if(t)return void Rt(i,mt(g.TRANSITION_ERR,t),a,Pt);if(l&&l!==a&&c(l)&&((l.name!==a.name||l.params!==a.params||l.path!==a.path)&>.error(Pt,"Warning: State mutated during middleware execution",{from:a,to:l}),a=vt(l,a)),o>=e.length)return void Rt(i,void 0,a,Pt);const u=e[o++];try{const e=u(a,r,s);Tt(e,s)}catch(e){s(new St(g.TRANSITION_ERR,At(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?$t(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?$t(s,t,r,i,g.CANNOT_DEACTIVATE,h,w):w(void 0,t)})(),()=>{a||o||(a=!0,f(new St(g.TRANSITION_CANCELLED)))}}var Ct=()=>{},Dt=Object.freeze({}),jt=Object.freeze({});var kt=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:Dt,opts:jt,callback:e};const n=e??Dt;return"function"==typeof t?{params:n,opts:jt,callback:t}:{params:n,opts:t??jt,callback:r??Ct}}(e,t,r)}static parseNavigateToDefaultArgs(e,t){return function(e,t){return"function"==typeof e?{opts:jt,callback:e}:{opts:e??jt,callback:t??Ct}}(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=Nt(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),ht(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),ht(i,void 0,s);else{const e=new St(g.ROUTE_NOT_FOUND,{routeName:s.name});ht(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 ht(n,new St(g.ROUTER_NOT_STARTED)),dt;const a=i.buildStateWithSegments(e,t);if(!a){const e=new St(g.ROUTE_NOT_FOUND);return ht(n,e),i.invokeEventListeners(R.TRANSITION_ERROR,void 0,i.getState(),e),dt}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 ht(n,void 0,s),dt;const c=i.getState();if(!r.reload&&!r.force&&i.areStatesEqual(c,s,!1)){const e=new St(g.SAME_STATES);return ht(n,e),i.invokeEventListeners(R.TRANSITION_ERROR,s,c,e),dt}return this.navigateToState(s,c,r,n,!0)}navigateToDefault(e,t){const r=this.#p.getOptions();return r.defaultRoute?this.navigate(r.defaultRoute,r.defaultParams,e,t):dt}},It=()=>{},Mt=new St(g.NO_START_PATH_OR_STATE),Ft=new St(g.ROUTER_ALREADY_STARTED),xt=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??It]:[void 0,It]})(t);let o=!1;if(this.#Oe||this.#$e)return o=!0,void a(Ft);if(!i&&!n.defaultRoute)return o=!0,r.hasListeners(R.TRANSITION_ERROR)&&r.invokeEventListeners(R.TRANSITION_ERROR,void 0,void 0,Mt),void a(Mt);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)},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 St(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 St(g.ROUTE_NOT_FOUND,{path:f}),void 0,!0)}stop(){const e=this.#p;this.#$e=!1,this.#Oe&&(this.#Oe=!1,e.setState(),e.invokeEventListeners(R.ROUTER_STOP))}},Lt=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}},_t=new Set(["all","warn-error","error-only"]);var Ut=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)||!_t.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),z.validateOptions(r,"constructor");const i=r.noValidate??!1;i||C.validateDependenciesObject(n,"constructor"),!i&&t.length>0&&(ut.validateAddRouteArgs(t),ut.validateRoutes(t)),this.#c=new z(r),this.#t=function(e={}){return{...E,...e}}(r.limits),this.#e=new C(n),this.#je=new k,this.#ke=new q,this.#Ie=new ut(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 J,this.#Fe=new H,this.#S=new G,this.#xe=new kt,this.#Le=new xt,this.#_e=new Lt,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||(ut.validateAddRouteArgs(t),ut.validateRoutes(t,this.#Ie.getTree(),this.#Ie.getForwardRecord())),this.#Ie.addRoutes(t),this}removeRoute(t){return this.#ie||ut.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||ut.validateUpdateRouteBasicArgs(t,r);const{forwardTo:n,defaultParams:i,decodeParams:a,encodeParams:o,canActivate:s}=r;return this.#ie||ut.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||ut.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||ut.validateBuildPathArgs(e),this.#Ie.buildPath(e,t,this.#c.get())}matchPath(e,t){return this.#ie||ut.validateMatchPathArgs(e),this.#Ie.matchPath(e,t,this.#c.get())}setRootPath(e){this.#ie||ut.validateSetRootPathArgs(e),this.#Ie.setRootPath(e)}getRootPath(){return this.#Ie.getRootPath()}makeState(e,t,r,n,i){return this.#ie||q.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||q.validateAreStatesEqualArgs(e,t,r),this.#ke.areStatesEqual(e,t,r)}forwardState(e,t){return this.#ie||ut.validateStateBuilderArgs(e,t,"forwardState"),this.#Ie.forwardState(e,t)}buildState(e,t){this.#ie||ut.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:n}=this.forwardState(e,t);return this.#Ie.buildStateResolved(r,n)}shouldUpdateNode(e){return this.#ie||ut.validateShouldUpdateNodeArgs(e),this.#Ie.shouldUpdateNode(e)}getOptions(){return this.#c.get()}getOption(e){return this.#ie||(z.validateOptionName(e,"getOption"),z.validateOptionExists(e,"getOption")),this.#c.getOption(e)}isActive(){return this.#Le.isActive()}start(...e){return this.#ie||xt.validateStartArgs(e),this.#Le.start(...e),this}stop(){return this.#Le.stop(),this}canDeactivate(e,t){this.#ie||(h(e,"canDeactivate"),J.validateHandler(t,"canDeactivate"),J.validateNotRegistering(this.#Me.isRegistering(e),e,"canDeactivate"));const r=this.#Me.hasCanDeactivate(e);return r||this.#ie||J.validateHandlerLimit(this.#Me.countCanDeactivate()+1,"canDeactivate",this.#t.maxLifecycleHandlers),this.#Me.registerCanDeactivate(e,t,r),this}canActivate(e,t){this.#ie||(h(e,"canActivate"),J.validateHandler(t,"canActivate"),J.validateNotRegistering(this.#Me.isRegistering(e),e,"canActivate"));const r=this.#Me.hasCanActivate(e);return r||this.#ie||J.validateHandlerLimit(this.#Me.countCanActivate()+1,"canActivate",this.#t.maxLifecycleHandlers),this.#Me.registerCanActivate(e,t,r),this}usePlugin(...e){return this.#ie||(G.validateUsePluginArgs(e),G.validatePluginLimit(this.#S.count(),e.length,this.#t.maxPlugins),G.validateNoDuplicatePlugins(e,this.#S.has.bind(this.#S))),this.#S.use(...e)}useMiddleware(...e){this.#ie||(H.validateUseMiddlewareArgs(e),H.validateNoDuplicates(e,this.#Fe.getFactories()),H.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)H.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||kt.validateNavigateArgs(e);const{params:i,opts:a,callback:o}=kt.parseNavigateArgs(t,r,n);return this.#ie||kt.validateNavigationOptions(a,"navigate"),this.#xe.navigate(e,i,a,o)}navigateToDefault(e,t){this.#ie||kt.validateNavigateToDefaultArgs(e,t);const{opts:r,callback:n}=kt.parseNavigateToDefaultArgs(e,t);return this.#ie||kt.validateNavigationOptions(r,"navigateToDefault"),this.#xe.navigateToDefault(r,n)}navigateToState(e,t,r,n,i){return this.#ie||kt.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||Lt.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)}}),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())}),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=Ut,exports.RouterError=St,exports.constants=m,exports.createRouter=(e=[],t={},r={})=>new Ut(e,t,r),exports.errorCodes=g,exports.events=R;//# sourceMappingURL=index.js.map
|