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