@real-router/core 0.4.0 → 0.5.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 a(e,t){return new TypeError(`[router.${e}] ${t}`)}function i(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=>i(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=>i(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||i(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 u(e){return"string"==typeof e}function l(e){return"boolean"==typeof e}function d(e,t){return e in t}function h(e,t){if("string"!=typeof e)throw a(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!r.test(e))throw a(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw a(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!n.test(e))throw a(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=100,m=class{#e=Object.create(null);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){!function(e,t,r){const n=e+t;if(n>=g)throw new Error(`[router.${r}] Dependency limit exceeded (100). Current: ${n}. This is likely a bug in your code.`)}(e,t,r)}set(t,r){if(void 0===r)return!1;if(Object.hasOwn(this.#e,t)){const n=this.#e[t],a=n!==r,i=Number.isNaN(n)&&Number.isNaN(r);a&&!i&&e.logger.warn("router.setDependency","Router dependency already exists and is being overwritten:",t)}else this.#t("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]}#t(t){const r=Object.keys(this.#e).length;if(20===r)e.logger.warn(`router.${t}`,"20 dependencies registered. Consider if all are necessary.");else if(50===r)e.logger.error(`router.${t}`,"50 dependencies registered! This indicates architectural problems. Hard limit at 100.");else if(r>=g)throw new Error(`[router.${t}] Dependency limit exceeded (100). Current: ${r}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}},v=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"}),y={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},w="onStart",b="onStop",T="onTransitionStart",S="onTransitionCancel",R="onTransitionSuccess",P="onTransitionError",E={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},A=new Set([E.ROUTER_START,E.TRANSITION_START,E.TRANSITION_SUCCESS,E.TRANSITION_ERROR,E.TRANSITION_CANCEL,E.ROUTER_STOP]);function O(t,r,...n){if(0===r.size)return;const a=[...r];for(const r of a)try{Function.prototype.apply.call(r,void 0,n)}catch(r){e.logger.error("Router",`Error in listener for ${t}:`,r)}}var $="function"==typeof Symbol&&Symbol.observable||"@@observable",N=class t{#r={};#n=null;#a=new WeakMap;#i=null;static validateEventName(e){if(!A.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 router[Symbol.observable]().subscribe(observer)")}setGetState(e){this.#i=e}invoke(e,t,r,n){this.#o(e);const a=this.#s();try{switch(a[e]++,e){case E.TRANSITION_START:case E.TRANSITION_CANCEL:O(e,this.#c(e),t,r);break;case E.TRANSITION_ERROR:case E.TRANSITION_SUCCESS:O(e,this.#c(e),t,r,n);break;default:O(e,this.#c(e))}}finally{a[e]--}}hasListeners(e){const t=this.#r[e];return void 0!==t&&t.size>0}removeEventListener(t,r){const n=this.#r[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.#c(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.`);if(1e3===n.size&&e.logger.warn("router.addEventListener",`Warning: Event "${t}" has ${n.size} listeners. This might indicate a memory leak.`),n.size>=1e4)throw new Error(`[router.addEventListener] Maximum listener limit (10000) reached for event "${t}". This is a critical memory leak. The application is creating listeners exponentially. Check for loops or recursive calls that register listeners.`);return n.add(r),()=>{this.removeEventListener(t,r)}}subscribe(e){return this.addEventListener(E.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}observable(){const e={[$]:()=>e,subscribe:this.#u.bind(this),"@@observable":()=>e};return e}#u(t,r={}){const n="function"==typeof t?{next:t}:t,a=this.#a.get(n);if(a?.active)return e.logger.warn("router.observable","Duplicate subscription prevented. Same observer already subscribed."),{unsubscribe:a.unsubscribe,get closed(){return!a.active}};const{signal:i,replay:o=!0}=r;if(i?.aborted)return{unsubscribe:()=>{},closed:!0};let s=!1;const c=t=>{if(!s&&n.next)try{n.next(t)}catch(t){if(e.logger.error("router.observable","Error in observer.next:",t),n.error)try{n.error(t)}catch(t){e.logger.error("router.observable","Error in observer.error:",t)}}},u=this.addEventListener(E.TRANSITION_SUCCESS,(e,t)=>{c({route:e,previousRoute:t})}),l={unsubscribe:void 0,active:!0},d=()=>{if(!s&&(s=!0,l.active=!1,u(),n.complete))try{n.complete()}catch(t){e.logger.error("router.observable","Error in observer.complete:",t)}};if(l.unsubscribe=d,this.#a.set(n,l),i&&i.addEventListener("abort",d,{once:!0}),o&&this.#i){const e=this.#i();e&&queueMicrotask(()=>{c({route:e,previousRoute:void 0})})}return{unsubscribe:d,get closed(){return s}}}#c(e){const t=this.#r[e];if(t)return t;const r=new Set;return this.#r[e]=r,r}#s(){return this.#n??={[E.ROUTER_START]:0,[E.TRANSITION_START]:0,[E.TRANSITION_SUCCESS]:0,[E.TRANSITION_ERROR]:0,[E.TRANSITION_CANCEL]:0,[E.ROUTER_STOP]:0},this.#n}#o(e){if(this.#s()[e]>=5)throw new Error(`[Router] Maximum recursion depth (5) exceeded for event: ${e}`)}},C={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},caseSensitive:!1,urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0},k={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},D={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]},j=new Set(["defaultRoute","defaultParams"]);function I(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&I(r)}return e}function x(e,t,r){const n=C[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,D)){const e=Object.keys(D).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],a=D[r];if(!a.includes(n)){const e=a.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 k&&function(e,t,r){const n=k[e];if(!n.includes(t)){const a=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${a}, got "${String(t)}"`)}}(e,t,r)}var M=class{#l;#d=!1;constructor(e={}){this.#l=I({...C,...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(C,e))throw new ReferenceError(`[router.${t}]: option "${e}" not found`)}(e,t)}static validateNotLocked(e,t){!function(e,t){if(e&&!j.has(t))throw new Error("[router.setOption] Options cannot be changed after router.start(). Only defaultRoute/defaultParams can be changed after start.")}(e,t)}static validateOptionValue(e,t,r){x(e,t,r)}static validateOptions(e,t){!function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid options: expected plain object, got ${f(e)}`);for(const[r,n]of Object.entries(e)){if(!d(r,C))throw new TypeError(`[router.${t}] Unknown option: "${r}"`);void 0!==n&&x(r,n,t)}}(e,t)}get(){return this.#l}getOption(e){return this.#l[e]}set(e,t){const r=t&&"object"==typeof t&&t.constructor===Object?{...t}:t;this.#l=I({...this.#l,[e]:r})}isLocked(){return this.#d}lock(){this.#d=!0}unlock(){this.#d=!1}};function F(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>F(e,t[r]))}var L=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 U(e){return e?(L.has(e)||(_(e),L.add(e)),e):e}function q(e){switch(e){case"never":return"never";case"always":return"always";default:return"default"}}function z(e){const t={trailingSlashMode:q(e.trailingSlash),queryParamsMode:e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding};return void 0!==e.queryParams&&(t.queryParams=e.queryParams),t}var W=class{#h=0;#f=void 0;#p=void 0;#g;#m=new Map;static validateMakeStateArgs(e,t,r,n){if(!u(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&&!u(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.#f}set(e){this.#p=this.#f,e?Object.isFrozen(e)?this.#f=e:this.#f=U(e):this.#f=void 0}getPrevious(){return this.#p}setDependencies(e){this.#g=e}makeState(e,t,r,n,a){const i=n?{...n,id:a??++this.#h,params:n.params,options:n.options,redirected:n.redirected}:void 0,o=this.#g.getDefaultParams(),s=e.split(".");let c={};for(let e=1;e<=s.length;e++){const t=s.slice(0,e).join(".");Object.hasOwn(o,t)&&(c={...c,...o[t]})}return t&&(c={...c,...t}),U({name:e,params:c,path:r??this.#g.buildPath(e,t),meta:i})}makeNotFoundState(e,t){return this.makeState(y.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.#v(e.name)).every(r=>F(e.params[r],t.params[r]))}const n=Object.keys(e.params),a=Object.keys(t.params);return n.length===a.length&&n.every(r=>r in t.params&&F(e.params[r],t.params[r]))}#v(e){const t=this.#m.get(e);if(void 0!==t)return t;const r=this.#g.getUrlParams(e);return this.#m.set(e,r),r}};function B(e){return e.name||"anonymous"}var H=class{#y=new Set;#w=new Map;#b;#g;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: ${B(t)}`)}(e,t)}static validateNoDuplicates(e,t){!function(e,t){const r=new Set(t);for(const t of e)if(r.has(t))throw new Error(`[router.useMiddleware] Middleware factory already registered. To re-register, first unsubscribe the existing middleware. Factory: ${B(t)}`)}(e,t)}static validateMiddlewareLimit(e,t){!function(e,t){if(e+t>50)throw new Error(`[router.useMiddleware] Middleware limit exceeded (50). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating middleware.`)}(e,t)}setRouter(e){this.#b=e}setDependencies(e){this.#g=e}count(){return this.#y.size}initialize(...e){const t=[];for(const r of e){const e=r(this.#b,this.#g.getDependency);t.push({factory:r,middleware:e})}return t}commit(t){this.#T(t.length);for(const{factory:e,middleware:r}of t)this.#y.add(e),this.#w.set(e,r);return()=>{for(const{factory:r}of t)this.#y.delete(r)||e.logger.warn("router.useMiddleware","Attempted to remove non-existent middleware factory. This might indicate a memory leak or incorrect cleanup logic."),this.#w.delete(r)}}clear(){this.#y.clear(),this.#w.clear()}getFactories(){return[...this.#y]}getFunctions(){return[...this.#w.values()]}#T(t){const r=t+this.#y.size;r>=30?e.logger.error("router.useMiddleware",`${r} middleware registered! This is excessive and will impact performance. Hard limit at 50.`):r>=15&&e.logger.warn("router.useMiddleware",`${r} middleware registered. Consider if all are necessary.`)}},V={[w]:E.ROUTER_START,[b]:E.ROUTER_STOP,[R]:E.TRANSITION_SUCCESS,[T]:E.TRANSITION_START,[P]:E.TRANSITION_ERROR,[S]:E.TRANSITION_CANCEL},Q=Object.keys(V).filter(e=>d(e,V)),Z="router.usePlugin",G=class t{#S=new Set;#b;#g;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,V))throw new TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}(e)}static validatePluginLimit(e,t){!function(e,t){if(e+t>50)throw new Error("[router.usePlugin] Plugin limit exceeded (50)")}(e,t)}static validateNoDuplicatePlugins(e,t){!function(e,t){const r=new Set(t);for(const t of e)if(r.has(t))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}(e,t)}setRouter(e){this.#b=e}setDependencies(e){this.#g=e}count(){return this.#S.size}use(...t){this.#T(t.length);const r=this.#R(t),n=[];try{for(const e of r){const t=this.#P(e);n.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(Z,"Cleanup error:",t)}throw t}for(const{factory:e}of n)this.#S.add(e);let a=!1;return()=>{if(!a){a=!0;for(const{factory:e}of n)this.#S.delete(e);for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(Z,"Error during cleanup:",t)}}}}getAll(){return[...this.#S]}#T(t){const r=t+this.#S.size;r>=25?e.logger.error(Z,`${r} plugins registered!`):r>=10&&e.logger.warn(Z,`${r} plugins registered`)}#R(t){const r=new Set;for(const n of t)r.has(n)?e.logger.warn(Z,"Duplicate factory in batch, will be registered once"):r.add(n);return r}#P(r){const n=this.#b,a=this.#g,i=r(n,a.getDependency);t.validatePlugin(i),Object.freeze(i);const o=[];for(const t of Q)t in i&&("function"==typeof i[t]?(o.push(a.addEventListener(V[t],i[t])),"onStart"===t&&a.isStarted()&&e.logger.warn(Z,"Router already started, onStart will not be called")):e.logger.warn(Z,`Property '${t}' is not a function, skipping`));return()=>{for(const e of o)e();"function"==typeof i.teardown&&i.teardown()}}},K=class{#E=new Map;#A=new Map;#O=new Map;#$=new Map;#N=new Set;#b;#g;static validateHandler(e,t){!function(e,t){if(!l(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){!function(e,t){if(e>=200)throw new Error(`[router.${t}] Lifecycle handler limit exceeded (200). This indicates too many routes with individual handlers. Consider using middleware for cross-cutting concerns.`)}(e,t)}setRouter(e){this.#b=e}setDependencies(e){this.#g=e}isRegistering(e){return this.#N.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.#C("activate",e,t,this.#A,this.#$,"canActivate",r)}registerCanDeactivate(e,t,r){this.#C("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.#$]}#C(t,r,n,a,i,o,s){s?e.logger.warn(`router.${o}`,`Overwriting existing ${t} handler for route "${r}"`):this.#T(a.size+1,o);const c=l(n)?function(e){const t=()=>e;return()=>t}(n):n;a.set(r,c),this.#N.add(r);try{const e=c(this.#b,this.#g.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${o}] Factory must return a function, got ${f(e)}`);i.set(r,e)}catch(e){throw a.delete(r),e}finally{this.#N.delete(r)}}#T(t,r){t>=100?e.logger.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at 200.`):t>=50&&e.logger.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}},J=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)},Y=e=>encodeURIComponent(e),X={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${Y(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${Y(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${Y(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>Y(e)).join(",")}`}},ee={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}},te={default:{encode:e=>e},hidden:{encode:()=>""}},re=(e,t,r)=>({boolean:ee[t],null:te[r],array:X[e]}),ne={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:ee.none,null:te.default,array:X.none}},ae=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return ne;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:re(t,r,n)}},ie=e=>encodeURIComponent(e),oe=(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)}`}},se=e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)};function ce(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}function ue(e,t,r,n,a){const i=e.indexOf("=",t),o=-1!==i&&i<r,s=e.slice(t,o?i:r),{name:c,hasBrackets:u}=ce(s);!function(e,t,r,n){const a=e[t];void 0===a?e[t]=n?[r]:r:Array.isArray(a)?a.push(r):e[t]=[a,r]}(n,J(c),function(e,t,r,n,a){return a?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const n=J(e);return t.boolean.decodeValue(n)})(n?e.slice(t+1,r):void 0,a):n?J(e.slice(t+1,r)):null}(e,i,r,o,a),u)}var le=(e,t)=>{const r=se(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return de(e,t),t}(r);const n=ae(t),a={};let i=0;const o=r.length;for(;i<o;){let e=r.indexOf("&",i);-1===e&&(e=o),ue(r,i,e,a,n.strategies),i=e+1}return a};function de(e,t){let r=0;const n=e.length;for(;r<n;){let a=e.indexOf("&",r);-1===a&&(a=n),ue(e,r,a,t),r=a+1}}var he=(e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=ae(t),a=[];for(const t of r){const r=e[t];if(void 0===r)continue;const i=oe(t,r,n);i&&a.push(i)}return a.join("&")},fe=/[^\w!$'()*+,.:;|~-]/gu,pe=/[^\w!$'()*+,.:;|~-]/u,ge={default:e=>pe.test(e)?e.replaceAll(fe,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e,legacy:encodeURI},me={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e,legacy:decodeURIComponent},ve={urlParamsEncoding:"default"},ye={withQueryParams:String.raw`(\?.*$|$)`,withoutQueryParams:"$"},we=String.raw`([/?.;]|$)`,be=String.raw`[a-zA-Z0-9_.~%':|=+*@$-]+`,Te=e=>`(${e?e.replaceAll(/(^<|>$)/g,""):be})`,Se=[{name:"url-parameter",pattern:/^:([\w-]*[\dA-Za-z])(<(.+?)>)?/,regex:e=>new RegExp(Te(e[2]))},{name:"url-parameter-splat",pattern:/^\*([\w-]*[\dA-Za-z])/,regex:/([^?]*)/},{name:"url-parameter-matrix",pattern:/^;([\w-]*[\dA-Za-z])(<(.+?)>)?/,regex:e=>new RegExp(`;${e[1]}=${Te(e[2])}`)},{name:"query-parameter",pattern:/^[&?]:?([\w-]*[\dA-Za-z])/},{name:"delimiter",pattern:/^([/?])/,regex:e=>new RegExp(`\\${e[0]}`)},{name:"sub-delimiter",pattern:/^([!&.;_-])/,regex:e=>new RegExp(e[0])},{name:"fragment",pattern:/^([\dA-Za-z]+)/,regex:e=>new RegExp(e[0])}],Re=(e,t,r)=>{const n=ge[t],a=String(e);if(!r)return n(a);const i=a.split("/");let o=n(i[0]);for(let e=1;e<i.length;e++)o+="/"+n(i[e]);return o},Pe=(e,t)=>me[t](e),Ee=(e,t=[])=>{if(!Se.some(r=>{const n=r.pattern.exec(e);return!!n&&(t.push({type:r.name,match:n[0],val:n.slice(1,2),otherVal:n.slice(2),regex:"function"==typeof r.regex?r.regex(n):r.regex}),n[0].length<e.length&&Ee(e.slice(n[0].length),t),!0)}))throw new Error(`Could not parse path '${e}'`);return t},Ae=e=>null!=e,Oe=e=>"string"==typeof e||"number"==typeof e||"boolean"==typeof e,$e=e=>!!Ae(e)&&(!!Oe(e)||!!Array.isArray(e)&&e.every(e=>Oe(e))),Ne=(e,t,r="")=>{const n=e[t];return e[t]=void 0===n?r:[n,r],e},Ce=class e{path;tokens;hasUrlParams;hasSpatParam;hasMatrixParams;hasQueryParams;options;spatParams;urlParams;queryParams;params;source;regexCache;constraintPatterns;buildOptionsCache;compiledBuildPattern;constructor(e,t){if(!e)throw new Error("Missing path in Path constructor");this.path=e,this.options={...ve,...t},this.tokens=Ee(e),this.hasUrlParams=this.tokens.some(e=>e.type.startsWith("url-parameter")),this.hasSpatParam=this.tokens.some(e=>e.type.endsWith("splat")),this.hasMatrixParams=this.tokens.some(e=>e.type.endsWith("matrix")),this.hasQueryParams=this.tokens.some(e=>e.type.startsWith("query-parameter")),this.spatParams=this.getParams("url-parameter-splat"),this.urlParams=this.getParams(/^url-parameter/),this.queryParams=this.getParams("query-parameter"),this.params=[...this.urlParams,...this.queryParams];let r="";for(const e of this.tokens)void 0!==e.regex&&(r+=e.regex.source);this.source=r;const n=(e=>"\\/"===e?e:e.replace(/\\\/$/,"")+"(?:\\/)?")(r),a=r,i=r,o=(e=>/(\/)$/.test(e)?e:e+we)(r),s=this.hasQueryParams?ye.withQueryParams:ye.withoutQueryParams;this.regexCache={test:{sensitive:new RegExp("^"+n+s),insensitive:new RegExp("^"+n+s,"i")},testStrict:{sensitive:new RegExp("^"+a+s),insensitive:new RegExp("^"+a+s,"i")},partial:{sensitive:new RegExp("^"+i),insensitive:new RegExp("^"+i,"i")},partialDelimited:{sensitive:new RegExp("^"+o),insensitive:new RegExp("^"+o,"i")}},this.constraintPatterns=new Map;const c=this.tokens.filter(e=>e.type.startsWith("url-parameter")&&!e.type.endsWith("-splat"));for(const e of c){const t=e.val[0],r=e.otherVal[0],n=new RegExp("^"+Te(r)+"$");this.constraintPatterns.set(t,{pattern:n,constraint:r})}this.buildOptionsCache={ignoreConstraints:!1,ignoreSearch:!1,queryParams:this.options.queryParams??{},urlParamsEncoding:this.options.urlParamsEncoding};const u=this.tokens.filter(e=>!e.type.startsWith("query-parameter")),l=[],d=[];let h="";for(const e of u)e.type.startsWith("url-parameter")&&"url-parameter-matrix"!==e.type?(l.push(h),h="",d.push(e.val[0])):"url-parameter-matrix"===e.type?(h+=";"+e.val[0]+"=",l.push(h),h="",d.push(e.val[0])):h+=e.match;l.push(h),this.compiledBuildPattern={staticParts:l,paramNames:d,pattern:e}}static createPath(t,r){return new e(t,r)}isQueryParam(e){return this.queryParams.includes(e)}isSpatParam(e){return this.spatParams.includes(e)}test(e,t){const r=t?.caseSensitive??!1,n=t?.strictTrailingSlash?this.regexCache.testStrict:this.regexCache.test,a=this.urlTestWithRegex(e,r?n.sensitive:n.insensitive,t?.urlParamsEncoding??this.options.urlParamsEncoding);if(!a||!this.hasQueryParams)return a;const i=le(e,t?.queryParams??this.options.queryParams);let o=!1;for(const e in i)this.isQueryParam(e)?a[e]=i[e]:o=!0;return o?null:a}partialTest(e,t){const r=t?.caseSensitive??!1,n=t?.delimited??1?this.regexCache.partialDelimited:this.regexCache.partial,a=this.urlTestWithRegex(e,r?n.sensitive:n.insensitive,t?.urlParamsEncoding??this.options.urlParamsEncoding);if(!a)return a;if(!this.hasQueryParams)return a;const i=le(e,t?.queryParams??this.options.queryParams);for(const e in i)this.isQueryParam(e)&&Ne(a,e,i[e]);return a}build(e={},t){const r=t?{ignoreConstraints:t.ignoreConstraints??!1,ignoreSearch:t.ignoreSearch??!1,queryParams:t.queryParams??this.buildOptionsCache.queryParams,urlParamsEncoding:t.urlParamsEncoding??this.buildOptionsCache.urlParamsEncoding}:this.buildOptionsCache,n=this.encodeUrlParams(e,r.urlParamsEncoding);this.validateRequiredParams(e),r.ignoreConstraints||this.validateConstraints(n);const a=this.buildBasePath(n);return r.ignoreSearch?a:this.buildWithSearch(a,e,r.queryParams)}encodeUrlParams(e,t){const r={};for(const n of Object.keys(e)){if(this.isQueryParam(n))continue;const a=e[n];$e(a)&&(r[n]=this.encodeParamValue(a,n,t))}return r}encodeParamValue(e,t,r){if("boolean"==typeof e)return e;const n=this.isSpatParam(t);return Array.isArray(e)?e.map(e=>Re(e,r,n)):Re(e,r,n)}validateRequiredParams(e){const t=this.urlParams.filter(t=>!Ae(e[t]));if(t.length>0)throw new Error("Cannot build path: '"+this.path+"' requires missing parameters { "+t.join(", ")+" }")}validateConstraints(e){for(const[t,{pattern:r,constraint:n}]of this.constraintPatterns){const a=String(e[t]);if(!r.test(a)){const e=n?n.replaceAll(/(^<)|(>$)/g,""):"[^/]+";throw new Error(`Parameter '${t}' of '${this.path}' has invalid format: got '${a}', expected to match '${e}'`)}}}buildBasePath(e){return function(e,t){const{staticParts:r,paramNames:n}=e;if(0===n.length)return r[0];let a=r[0];for(const[e,i]of n.entries())a+=String(t[i])+r[e+1];return a}(this.compiledBuildPattern,e)}buildWithSearch(e,t,r){const n={};for(const e of this.queryParams)e in t&&(n[e]=t[e]);const a=he(n,r);return a?e+"?"+a:e}getParams(e){const t=[],r=e instanceof RegExp;for(const n of this.tokens)(r?e.test(n.type):n.type===e)&&t.push(n.val[0]);return t}urlTestWithRegex(e,t,r){const n=t.exec(e);if(!n)return null;if(0===this.urlParams.length)return{};const a={};for(let e=0;e<this.urlParams.length;e++)a[this.urlParams[e]]=Pe(n[e+1],r);return a}},ke=function(e){return new Ce(e)};function De(e,t){const r=e.path,n=r.startsWith("~"),a=n?r.slice(1):r,i={name:e.name,path:a,absolute:n,parser:a?ke(a):null,children:[],parent:t,nonAbsoluteChildren:[],absoluteDescendants:[],childrenByName:new Map,parentSegments:[],fullName:"",staticChildrenByFirstSegment:new Map};if(e.children)for(const t of e.children){const e=De(t,i);i.children.push(e)}return i}function je(e,t){const r=t.split(".");if(1===r.length)return{parent:e,finalName:t};let n=e;for(let e=0;e<r.length-1;e++){const t=r[e];n=n.children.find(e=>e.name===t)}return{parent:n,finalName:r.at(-1)}}var Ie=new Map;function xe(e){const t=e.startsWith("/")?1:0;let r=e.indexOf("/",t);const n=e.indexOf("?",t);-1!==n&&(-1===r||n<r)&&(r=n);const a=-1===r?e.slice(t):e.slice(t,r);return""===a||a.startsWith(":")||a.startsWith("*")||a.includes("(")?null:a.toLowerCase()}function Me(e,t){for(const r of e.children)r.absolute&&t.push(r),Me(r,t)}function Fe(e){const t=[];return Me(e,t),t}function Le(e,t,r){const n={name:e.name,path:e.path,absolute:e.absolute,parser:e.parser,parent:t,children:[],nonAbsoluteChildren:[],absoluteDescendants:[],childrenByName:new Map,parentSegments:[],fullName:"",staticPath:null,paramTypeMap:{},staticChildrenByFirstSegment:Ie};if(e.parser){for(const t of e.parser.urlParams)n.paramTypeMap[t]="url";for(const t of e.parser.queryParams)n.paramTypeMap[t]="query"}n.fullName=function(e){return e.parent?.name?`${e.parent.fullName}.${e.name}`:e.name}(n);for(const t of e.children){const e=Le(t,n,r);n.children.push(e),n.childrenByName.set(e.name,e),e.absolute||n.nonAbsoluteChildren.push(e)}return n.absoluteDescendants=Fe(n),n.parentSegments=function(e){const t=[];let r=e.parent;for(;r?.parser;)t.push(r),r=r.parent;return t.reverse(),t}(n),n.staticPath=function(e){const t=e.parser;if(!t)return null;if(t.hasUrlParams||t.hasQueryParams||t.hasSpatParam)return null;let r="";for(const t of e.parentSegments){const e=t.parser;if(e.hasUrlParams||e.hasQueryParams||e.hasSpatParam)return null;r=t.absolute?t.path:r+t.path}return r=e.absolute?e.path:r+e.path,r.replaceAll(/\/{2,}/g,"/")}(n),n.staticChildrenByFirstSegment=function(e,t){if(0===e.length)return Ie;const r=new Map;for(const t of e){const e=xe(t.path);if(null!==e){const n=r.get(e);n?n.push(t):r.set(e,[t])}}if(0===r.size)return Ie;if(t)for(const[e,t]of r)r.set(e,Object.freeze(t));return r}(n.nonAbsoluteChildren,r),r&&(Object.freeze(n.children),Object.freeze(n.nonAbsoluteChildren),Object.freeze(n.absoluteDescendants),Object.freeze(n.parentSegments),Object.freeze(n.paramTypeMap),Object.freeze(n)),n}function _e(e){let t="",r=0;for(const n of e)"<"===n?r++:">"===n?r--:0===r&&(t+=n);return function(e){return e.endsWith("/")&&e.length>1?e.slice(0,-1):e}(t.split("?")[0])}function Ue(e){!function(e){if(e.length<=1)return;const t=new Map;for(const[r,n]of e.entries()){const e=_e(n.path),a=e.split("/"),i=a.at(-1);t.set(n,{normalizedPath:e,segmentCount:a.length-1,lastSegmentLength:i.length,originalIndex:r})}e.sort((e,r)=>{const n=t.get(e),a=t.get(r);if("/"===n.normalizedPath)return 1;if("/"===a.normalizedPath)return-1;if(e.parser.hasSpatParam)return 1;if(r.parser.hasSpatParam)return-1;if(n.segmentCount<a.segmentCount)return 1;if(n.segmentCount>a.segmentCount)return-1;const i=e.parser.urlParams.length,o=r.parser.urlParams.length;return i<o?-1:i>o||n.lastSegmentLength<a.lastSegmentLength?1:n.lastSegmentLength>a.lastSegmentLength?-1:n.originalIndex-a.originalIndex})}(e.children);for(const t of e.children)Ue(t)}var qe=class extends Error{constructor(e){super(e),this.name="RouteNodeError",Object.setPrototypeOf(this,new.target.prototype)}},ze=class extends qe{duplicateValue;duplicateType;constructor(e,t,r){super(e),this.name="DuplicateRouteError",this.duplicateValue=t,this.duplicateType=r}},We=class extends qe{constructor(e){super(e),this.name="InvalidRouteError"}},Be=class extends qe{routeName;constructor(e,t){super(e),this.name="RouteNotFoundError",this.routeName=t}};function He(e){if(!e.name||"string"!=typeof e.name)throw new We("Route definition must have a 'name' property of type string.");if("string"!=typeof e.path)throw new We(`Route "${e.name}" must have a 'path' property of type string.`)}function Ve(e,t){if(t.has(e))throw new ze(`Duplicate route name "${e}" found.`,e,"name");t.add(e)}function Qe(e,t,r){const n=r.get(t);if(n?.has(e))throw new ze(`Path "${e}" is already defined`,e,"path");n?n.add(e):r.set(t,new Set([e]))}function Ze(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build(n){n?.skipValidation||function(e){const t=new Set,r=new Map,n=[{routes:e,parentPrefix:""}];for(;n.length>0;){const{routes:e,parentPrefix:a}=n.pop();for(const i of e){He(i);const e=a?`${a}.${i.name}`:i.name;Ve(e,t),Qe(i.path,a,r),i.children&&i.children.length>0&&n.push({routes:i.children,parentPrefix:e})}}}(r);const a=function(e,t,r){const n=De({name:e,path:t},null),a=[];for(const e of r)if(e.name.includes("."))a.push(e);else if(e.children&&e.children.length>0){const t=De(e,n);n.children.push(t)}else a.push(e);for(const e of a){const{parent:t,finalName:r}=je(n,e.name),a=De({name:r,path:e.path,children:e.children},t);t.children.push(a)}return n}(e,t,r);return n?.skipSort||Ue(a),function(e,t=!0){return Le(e,null,t)}(a,!n?.skipFreeze)}}}function Ge(e,t,r,n){return Ze(e,t).addMany(r).build(n)}var Ke=/^\/(\?|$)/,Je=/\/$/,Ye=/^\/\?/;function Xe(e){const t=e.startsWith("/")?1:0,r=e.charAt(t);return":"===r||"*"===r||""===r||"("===e.charAt(t)}var et={caseSensitive:!1,strictTrailingSlash:!1},tt={caseSensitive:!1,strictTrailingSlash:!0},rt={caseSensitive:!0,strictTrailingSlash:!1},nt={caseSensitive:!0,strictTrailingSlash:!0},at={caseSensitive:!1,delimited:!0},it={caseSensitive:!0,delimited:!0},ot={caseSensitive:!1,delimited:!1},st={caseSensitive:!0,delimited:!1},ct={queryParamsMode:"default",strictTrailingSlash:!1,strongMatching:!0,caseSensitive:!1,queryParams:void 0,urlParamsEncoding:void 0,fullTestOptions:et,partialTestOptions:at,buildOptions:{ignoreSearch:!0}};function ut(e,t,r,n,a,i){for(const o of e){if(i&&!Xe(o.path))continue;const e=lt(o,t,r,n,!1,a);if(void 0!==e)return e}return null}function lt(e,t,r,n,a,i){const o=e.parser,s=function(e,t,r){return"/"===r&&"/"===t?`/${e}`:e}(t,e.path,i),c=function(e,t,r,n){if(0===e.children.length){const e=t.test(r,n.fullTestOptions);if(e)return e}return t.partialTest(r,n.partialTestOptions)}(e,o,s,n);if(!c)return;const u=0===e.children.length,l=function(e,t,r,n){let a=e.build(t,r.buildOptions);return!r.strictTrailingSlash&&n&&(a=a.replace(Je,"")),a}(o,c,n,u),d=function(e,t,r,n,a,i){let o=e.slice(t.length);!r.strictTrailingSlash&&n&&(o=o.replace(Ye,"?"));const{querystring:s}=((e,t,r)=>{const n=se(e);if(""===n)return{querystring:"",removedParams:{}};if(0===t.length)return{querystring:e.startsWith("?")?e:n,removedParams:{}};const a=ae(r),i=e.startsWith("?"),o=new Set(t),s=[],c=[];!function(e,t){let r=0;const n=e.length;for(;r<n;){let a=e.indexOf("&",r);-1===a&&(a=n),t(e.slice(r,a)),r=a+1}}(n,e=>{const t=e.indexOf("="),r=-1===t?e:e.slice(0,t),{name:n}=ce(r);o.has(n)?c.push(e):s.push(e)});const u=s.join("&");return{querystring:i&&u?`?${u}`:u,removedParams:le(c.join("&"),a)}})(function(e){const t=e.indexOf("?");return-1===t?"":e.slice(t+1)}(e.slice(t.length)),i.queryParams,r.queryParams);return o=function(e){const t=e.indexOf("?");return-1===t?e:e.slice(0,t)}(o)+(s?`?${s}`:""),r.strictTrailingSlash||a||"/"!==o||t.endsWith("/")||(o=""),o}(s,l,n,u,a,o);return r.segments.push(e),Object.assign(r.params,c),function(e,t,r,n,a,i){return a||0!==r.length?function(e,t,r){return!r&&"strict"!==t.queryParamsMode&&e.startsWith("?")}(r,n,a)?function(e,t){return r=t.slice(1),n=e.params,""!==r&&de(r,n),e;var r,n}(t,r):0===e.nonAbsoluteChildren.length?null:function(e,t,r,n,a){const i=e.staticChildrenByFirstSegment,o=e.nonAbsoluteChildren;if(0===i.size)return ut(o,t,r,n,a,!1);const s=function(e){let t=e.indexOf("/",1);const r=e.indexOf("?",1);return-1!==r&&(-1===t||r<t)&&(t=r),(-1===t?e.slice(1):e.slice(1,t)).toLowerCase()}(t),c=i.get(s);if(c){const e=ut(c,t,r,n,a,!1);if(null!==e)return e}return ut(o,t,r,n,a,!0)}(e,r,t,n,i):t}(e,r,d,n,a,l)}function dt(e,t){const r=[],n=t.includes(".")?t.split("."):[t];e.parser&&r.push(e);let a=e;for(const e of n){const t=a.childrenByName.get(e);if(!t)return null;r.push(t),a=t}return r}var ht=Object.freeze([]);function ft(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return t}function pt(e){const t={name:e.name,path:e.absolute?`~${e.path}`:e.path};return e.children.length>0&&(t.children=e.children.map(e=>pt(e))),t}function gt(e,t){return new TypeError(`[router.${e}] ${t}`)}var mt=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/,vt=/\S/;function yt(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function wt(e,t,r,n="",a,i){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${yt(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${yt(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 ${yt(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!vt.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("@@")&&!mt.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,gt(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw gt(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw gt(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw gt(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const a=n?.parser&&("urlParams"in n.parser&&n.parser.urlParams.length>0||"hasUrlParams"in n.parser&&n.parser.hasUrlParams);if(e.startsWith("~")&&a)throw new Error(`[router.${r}] Absolute path "${e}" cannot be used under parent route with URL parameters`)}(o.path,o.name,t,r),function(e,t){if(void 0!==e.encodeParams&&"function"!=typeof e.encodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}(o,t),function(e,t){if(void 0!==e.decodeParams&&"function"!=typeof e.decodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}(o,t);const s=o.name,c=n?`${n}.${s}`:s;!n&&c.includes(".")&&function(e,t,r,n){const a=t.split(".");a.pop();const i=a.join(".");if(!n?.has(i)){if(e){const n=i.split(".");let a=e;for(const e of n)if(a=a.childrenByName.get(e),!a)throw new Error(`[router.${r}] Parent route "${i}" does not exist for route "${t}"`);return}throw new Error(`[router.${r}] Parent route "${i}" does not exist for route "${t}"`)}}(r,c,t,a),r&&c&&function(e,t,r){const n=t.split(".");let a=e;for(const e of n)if(a=a.childrenByName.get(e),!a)return;throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),a&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(a,c,t);const u=o.path;let l=n;if(s.includes(".")&&!n){const e=s.split(".");e.pop(),l=e.join(".")}if(r&&function(e,t,r){let n=e;if(""!==t){const e=t.split(".");for(const t of e)if(n=n.childrenByName.get(t),!n)return}for(const e of n.children)if(e.path===r)throw new Error(`Path "${r}" is already defined`)}(r,l,u),i&&function(e,t,r){const n=e.get(t);if(n?.has(r))throw new Error(`Path "${r}" is already defined`);n?n.add(r):e.set(t,new Set([r]))}(i,l,u),void 0!==o.children){if(!Array.isArray(o.children))throw new TypeError(`[router.${t}] Route "${s}" children must be an array, got ${yt(o.children)}`);for(const e of o.children)wt(e,t,r,c,a,i)}}var bt=new Set;function Tt(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>Tt(e))),t}function St(e,t,r=""){for(let n=0;n<e.length;n++){const a=e[n],i=r?`${r}.${a.name}`:a.name;if(i===t)return e.splice(n,1),!0;if(a.children&&t.startsWith(`${i}.`)&&St(a.children,t,i))return!0}return!1}function Rt(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function Pt(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)Pt(r,`${t}.${r.name}`)}function Et(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 At(e){const t=new Set;for(const r of e)for(const e of Et(r))t.add(e);return t}function Ot(e,t,r="",n=[]){for(const a of e){const e=r?`${r}.${a.name}`:a.name,i=[...n,a.path];if(e===t)return i;if(a.children&&t.startsWith(`${e}.`))return Ot(a.children,t,e,i)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function $t(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 $t(n.children,e))r.add(t)}return r}function Nt(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,a]of Nt(n.children,e))r.set(t,a)}return r}function Ct(e,t,r,n){return t?function(e){const t=new Set;for(const r of e){for(const e of r.parser.urlParams)t.add(e);for(const e of r.parser.spatParams)t.add(e)}return t}(dt(r,e)):At(Ot(n,e))}function kt(e,t,r,n,a){const i=function(e,t){const r=t.split(".");let n=e;for(const e of r)if(n=n.childrenByName.get(e),!n)return!1;return!0}(a,t),o=n.has(t);if(!i&&!o)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const s=At(Ot(r,e)),c=[...Ct(t,i,a,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 Dt(e,t,r=100){const n=new Set,a=[e];let i=e;for(;t[i];){const e=t[i];if(n.has(e)){const t=a.indexOf(e),r=[...a.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(i),a.push(e),i=e,a.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${a.join(" → ")}`)}return i}function jt(e,t,r){const n=$t(e),a=Nt(e),i={...t};for(const[e,t]of a)i[e]=t;for(const[t,i]of a)kt(t,i,e,n,r);for(const e of Object.keys(i))Dt(e,i)}function It(e,t){const r=t??function(e){let t="";for(const r of e)r.name&&(t&&(t+="."),t+=r.name);return t}(e.segments);return{name:r,params:e.params,meta:ft(e.segments)}}var xt=".";function Mt(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function Ft(t,r){const n=r.meta?.params[t];if(!n||"object"!=typeof n)return{};const a={};for(const t in n){if(!Object.hasOwn(n,t))continue;if(void 0===n[t])continue;const i=r.params[t];null!=i&&("string"==typeof i||"number"==typeof i||"boolean"==typeof i?a[t]=String(i):e.logger.warn("transitionPath.extractSegmentParams",`Unsupported param type for key "${t}": ${typeof i}. Only primitives (string, number, boolean) are supported.`,typeof i))}return a}function Lt(e){if(!e)return[""];const t=e.indexOf(xt);if(-1===t)return[e];const r=e.indexOf(xt,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(xt,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(xt,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(xt),r=t.length,n=[t[0]];let a=t[0].length;for(let i=1;i<r-1;i++)a+=1+t[i].length,n.push(e.slice(0,a));return n.push(e),n}(e)}function _t(e,t){if(!t)return{intersection:"",toActivate:Lt(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:Lt(e.name),toDeactivate:Mt(Lt(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:Lt(e.name),toDeactivate:Mt(Lt(t.name))};if(e.name===t.name&&r&&n){const r=e.meta&&0===Object.keys(e.meta.params).length,n=t.meta&&0===Object.keys(t.meta.params).length;if(r&&n)return{intersection:e.name,toActivate:[],toDeactivate:[]}}const a=Lt(e.name),i=Lt(t.name),o=function(e,t,r,n,a){for(let i=0;i<a;i++){const a=r[i],o=n[i];if(a!==o)return i;const s=Ft(a,e),c=Ft(o,t),u=Object.keys(s),l=Object.keys(c);if(u.length!==l.length)return i;for(const e of u)if(s[e]!==c[e])return i}return a}(e,t,a,i,Math.min(i.length,a.length)),s=[];for(let e=i.length-1;e>=o;e--)s.push(i[e]);const c=a.slice(o);return{intersection:o>0?i[o-1]:"",toDeactivate:s,toActivate:c}}var Ut=class{#k=[];#D=function(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null)}}();#j=Object.create(null);#I=new Map;#x="";#M;#F;#g;#L;constructor(e=[]){for(const t of e)this.#k.push(Tt(t));this.#M=Ge("",this.#x,this.#k),this.#_(e),this.#U()}static validateRemoveRouteArgs(e){!function(e){h(e,"removeRoute")}(e)}static validateSetRootPathArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${f(e)}`)}(e)}static validateAddRouteArgs(e){!function(e){for(const t of e){if(null===t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`[router.addRoute] Route must be an object, got ${f(t)}`);Pt(t,t.name)}}(e)}static validateIsActiveRouteArgs(e,t,r,n){!function(e,t,r,n){if(!u(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(!u(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&&!u(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(!u(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(!u(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e)}static validateShouldUpdateNodeArgs(e){!function(e){if(!u(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,a=new Map;for(const r of e)wt(r,"addRoute",t,"",n,a);jt(e,r,t)}(e,t,r)}setDependencies(e){this.#g=e;for(const[t,r]of this.#I)e.canActivate(t,r);this.#I.clear()}setLifecycleNamespace(e){this.#L=e}getRootPath(){return this.#x}getTree(){return this.#M}getForwardRecord(){return this.#D.forwardMap}setRootPath(e){this.#x=e,this.#q(!0)}hasRoute(e){return function(e,t){const r=t.includes(".")?t.split("."):[t];let n=e;for(const e of r){const t=n.childrenByName.get(e);if(!t)return!1;n=t}return!0}(this.#M,e)}getRoute(e){const t=dt(this.#M,e);if(!t)return;const r=pt(t.at(-1));return this.#z(r,e)}addRoutes(e){for(const t of e)this.#k.push(Tt(t));this.#_(e),this.#q(!0),this.#U()}removeRoute(e){return!!St(this.#k,e)&&(this.#W(e),this.#q(!0),this.#U(),!0)}updateRouteConfig(e,t){if(void 0!==t.forwardTo&&(null===t.forwardTo?delete this.#D.forwardMap[e]:this.#D.forwardMap[e]=t.forwardTo,this.#U()),void 0!==t.defaultParams&&(null===t.defaultParams?delete this.#D.defaultParams[e]:this.#D.defaultParams[e]=t.defaultParams),void 0!==t.decodeParams)if(null===t.decodeParams)delete this.#D.decoders[e];else{const r=t.decodeParams;this.#D.decoders[e]=e=>r(e)??e}if(void 0!==t.encodeParams)if(null===t.encodeParams)delete this.#D.encoders[e];else{const r=t.encodeParams;this.#D.encoders[e]=e=>r(e)??e}}clearRoutes(){this.#k.length=0;for(const e in this.#D.decoders)delete this.#D.decoders[e];for(const e in this.#D.encoders)delete this.#D.encoders[e];for(const e in this.#D.defaultParams)delete this.#D.defaultParams[e];for(const e in this.#D.forwardMap)delete this.#D.forwardMap[e];for(const e in this.#j)delete this.#j[e];this.#q(!0)}buildPath(e,t,r){if(e===y.UNKNOWN_ROUTE)return u(t?.path)?t.path:"";const n=Object.hasOwn(this.#D.defaultParams,e)?{...this.#D.defaultParams[e],...t}:t??{},a="function"==typeof this.#D.encoders[e]?this.#D.encoders[e]({...n}):n,i=this.#F??z(r);return function(e,t,r={},n={}){const a=function(e){for(const t in e)if(Object.hasOwn(e,t))return!0;return!1}(r),i=function(e){return void 0!==e.trailingSlashMode&&"default"!==e.trailingSlashMode||void 0!==e.queryParamsMode&&"default"!==e.queryParamsMode||void 0!==e.queryParams||void 0!==e.urlParamsEncoding&&"default"!==e.urlParamsEncoding}(n);if(!a&&!i){const r=function(e,t){if(t.includes(".")){const r=dt(e,t),n=r?.at(-1)?.staticPath;return n??null}return e.childrenByName.get(t)?.staticPath??null}(e,t);if(null!==r)return r}const o=dt(e,t);if(!o)throw new Be(`[route-node][buildPath] '${t}' is not defined`,t);return function(e,t,r){const{queryParamsMode:n="default",trailingSlashMode:a="default"}=r,i=function(e){let t=null,r=null;for(const n of e){const e=n.parser;if(e.queryParams.length>0){t??=[];for(let r=0;r<e.queryParams.length;r++)t.push(e.queryParams[r])}if(e.urlParams.length>0||e.spatParams.length>0){r??=[];for(let t=0;t<e.urlParams.length;t++)r.push(e.urlParams[t]);for(let t=0;t<e.spatParams.length;t++)r.push(e.spatParams[t])}}return{searchParams:t??ht,nonSearchParams:r??ht}}(e),o=function(e,t,r){if("loose"!==r)return e.searchParams;const n=[...e.searchParams],a=new Set(e.searchParams),i=new Set(e.nonSearchParams);for(const e in t)!Object.hasOwn(t,e)||a.has(e)||i.has(e)||n.push(e);return n}(i,t,n),s=function(e,t,r){const n={};for(const r of e)r in t&&(n[r]=t[r]);return he(n,r.queryParams)}(o,t,r),c=function(e,t,r){const n={ignoreSearch:!0,queryParams:r.queryParams,urlParamsEncoding:r.urlParamsEncoding};let a="";for(const r of e){const e=r.parser.build(t,n);a=r.absolute?e:a+e}return a.replaceAll(/\/{2,}/g,"/")}(e,t,r);return u=c,("always"===(l=a)?u.endsWith("/")?u:`${u}/`:"never"===l&&"/"!==u&&u.endsWith("/")?u.slice(0,-1):u)+(s?`?${s}`:"");var u,l}(o,r,n)}(this.#M,e,a,i)}matchPath(e,t,r){const n=r,a=function(e){return{...z(e),caseSensitive:e.caseSensitive,strictTrailingSlash:"strict"===e.trailingSlash,strongMatching:!1}}(n),i=function(e,t,r={}){let n=t;""!==n||r.strictTrailingSlash||(n="/");const a=function(e,t,r){const n=[];if(e.parser){n.push(e);for(let t=0;t<e.absoluteDescendants.length;t++)n.push(e.absoluteDescendants[t])}else for(const t of e.children){n.push(t);for(let e=0;e<t.absoluteDescendants.length;e++)n.push(t.absoluteDescendants[e])}const a=function(e){return void 0===e.queryParamsMode&&void 0===e.strictTrailingSlash&&void 0===e.strongMatching&&void 0===e.caseSensitive&&void 0===e.queryParams&&void 0===e.urlParamsEncoding&&void 0===e.trailingSlashMode||void 0!==e.trailingSlashMode&&void 0===e.queryParamsMode&&void 0===e.strictTrailingSlash&&void 0===e.strongMatching&&void 0===e.caseSensitive&&void 0===e.queryParams&&void 0===e.urlParamsEncoding?ct:function(e){const t=e.queryParamsMode??"default",r=e.strictTrailingSlash??!1,n=e.strongMatching??!0,a=e.caseSensitive??!1,{queryParams:i,urlParamsEncoding:o}=e,s=void 0===i&&void 0===o;return{queryParamsMode:t,strictTrailingSlash:r,strongMatching:n,caseSensitive:a,queryParams:i,urlParamsEncoding:o,fullTestOptions:s?function(e,t){return e?t?nt:rt:t?tt:et}(a,r):{caseSensitive:a,strictTrailingSlash:r,queryParams:i,urlParamsEncoding:o},partialTestOptions:s?function(e,t){return e?t?it:st:t?at:ot}(a,n):{caseSensitive:a,delimited:n,queryParams:i,urlParamsEncoding:o},buildOptions:{ignoreSearch:!0,urlParamsEncoding:o}}}(e)}(r);return function(e,t,r,n){const a=1===e.length&&""===e[0].name;for(const i of e){const e=lt(i,t,r,n,a,void 0);if(void 0!==e)return e}return null}(n,t,{segments:[],params:{}},a)}(e,n,r);if(!a)return null;const i=a.segments;if(i[0]?.absolute){const e=i[0].parentSegments;for(let t=e.length-1;t>=0;t--)i.unshift(e[t])}const o=i.at(-1).nonAbsoluteChildren.find(e=>e.parser&&Ke.test(e.parser.path));return o&&i.push(o),{segments:i,params:a.params}}(this.#M,e,a);if(i){const r=It(i),{name:a,params:o,meta:s}=r,c="function"==typeof this.#D.decoders[a]?this.#D.decoders[a](o):o,{name:u,params:l}=this.forwardState(a,c),d=n.rewritePathOnMatch?this.buildPath(u,l,n):e;return this.#g.makeState(u,l,d,{params:s,options:{},source:t,redirected:!1})}}forwardState(e,t){const r=this.#j[e]??e,n=Object.hasOwn(this.#D.defaultParams,e)?{...this.#D.defaultParams[e],...t}:{...t};return r!==e&&Object.hasOwn(this.#D.defaultParams,r)?{name:r,params:{...this.#D.defaultParams[r],...n}}:{name:r,params:n}}buildStateResolved(e,t){const r=dt(this.#M,e);if(r)return It({segments:r,params:t},e)}buildStateWithSegmentsResolved(e,t){const r=dt(this.#M,e);if(r)return{state:It({segments:r,params:t},e),segments:r}}initBuildOptionsCache(e){this.#F=z(e)}clearBuildOptionsCache(){this.#F=void 0}isActiveRoute(e,t={},r=!1,n=!0){bt.has(e)||(h(e,"isActiveRoute"),bt.add(e));const a=this.#g.getState();if(!a)return!1;const i=a.name;if(i!==e&&!i.startsWith(`${e}.`)&&!e.startsWith(`${i}.`))return!1;const o=this.#D.defaultParams[e];if(r||i===e){const r={name:e,params:o?{...o,...t}:t,path:""};return this.#g?.areStatesEqual(r,a,n)??!1}const s=a.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:a,toDeactivate:i}=_t(t,r);return e===n||!!a.includes(e)||i.includes(e)}}getConfig(){return this.#D}getUrlParams(e){const t=dt(this.#M,e);return t?this.#B(t):[]}getResolvedForwardMap(){return this.#j}setResolvedForwardMap(e){Object.assign(this.#j,e)}cloneRoutes(){return this.#M.children.map(e=>pt(e))}validateForwardToParamCompatibility(e,t){const r=dt(this.#M,e),n=dt(this.#M,t),a=this.#H(r),i=this.#B(n).filter(e=>!a.has(e));if(i.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${i.join(", ")}] that are not available in source route "${e}"`)}validateForwardToCycle(e,t){Dt(e,{...this.#D.forwardMap,[e]:t})}validateRemoveRoute(t,r,n){if(r){const n=r===t,a=r.startsWith(`${t}.`);if(n||a)return e.logger.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${n?"":` (current: "${r}")`}. Navigate away first.`),!1}return n&&e.logger.warn("router.removeRoute",`Route "${t}" removed while navigation is in progress. This may cause unexpected behavior.`),!0}validateClearRoutes(t){return!t||(e.logger.error("router.clearRoutes","Cannot clear routes while navigation is in progress. Wait for navigation to complete."),!1)}validateUpdateRoute(e,t){if(!this.hasRoute(e))throw new ReferenceError(`[real-router] updateRoute: route "${e}" does not exist`);if(null!=t){if(!this.hasRoute(t))throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);this.validateForwardToParamCompatibility(e,t),this.validateForwardToCycle(e,t)}}#q(e=!1){this.#M=Ge("",this.#x,this.#k,{skipValidation:e})}#H(e){const t=new Set;for(const r of e)for(const e of r.parser.urlParams)t.add(e);return t}#B(e){const t=[];for(const r of e)for(const e of r.parser.urlParams)t.push(e);return t}#U(){for(const e in this.#j)delete this.#j[e];for(const e of Object.keys(this.#D.forwardMap))this.#j[e]=Dt(e,this.#D.forwardMap)}#W(e){const t=t=>t===e||t.startsWith(`${e}.`);if(Rt(this.#D.decoders,t),Rt(this.#D.encoders,t),Rt(this.#D.defaultParams,t),Rt(this.#D.forwardMap,t),Rt(this.#D.forwardMap,e=>t(this.#D.forwardMap[e])),this.#L){const[e,r]=this.#L.getFactories();for(const e of Object.keys(r))t(e)&&this.#L.clearCanActivate(e,!0);for(const r of Object.keys(e))t(r)&&this.#L.clearCanDeactivate(r,!0)}}#_(e,t=""){for(const r of e){const e=t?`${t}.${r.name}`:r.name;this.#V(r,e),r.children&&this.#_(r.children,e)}}#V(e,t){e.canActivate&&(this.#g?this.#g.canActivate(t,e.canActivate):this.#I.set(t,e.canActivate)),e.forwardTo&&this.#Q(e,t),e.decodeParams&&(this.#D.decoders[t]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(this.#D.encoders[t]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(this.#D.defaultParams[t]=e.defaultParams)}#Q(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.#D.forwardMap[r]=t.forwardTo}#z(e,t){const r={name:e.name,path:e.path},n=this.#D.forwardMap[t];if(n&&(r.forwardTo=n),t in this.#D.defaultParams&&(r.defaultParams=this.#D.defaultParams[t]),t in this.#D.decoders&&(r.decodeParams=this.#D.decoders[t]),t in this.#D.encoders&&(r.encodeParams=this.#D.encoders[t]),this.#L){const[,e]=this.#L.getFactories();t in e&&(r.canActivate=e[t])}return e.children&&(r.children=e.children.map(e=>this.#z(e,`${t}.${e.name}`))),r}},qt=()=>{};function zt(t,...r){try{t(...r)}catch(t){e.logger.error("router.navigate","Error in navigation callback:",t)}}var Wt={log:0,warn:1,error:2},Bt={all:0,"warn-error":1,"error-only":2,none:3},Ht=new class{#D={level:"all",callbackIgnoresLevel:!1};#Z=0;configure(e){if(void 0!==e.level){if(!(e.level in Bt))throw new Error(`Invalid log level: "${e.level}". Valid levels are: ${Object.keys(Bt).join(", ")}`);this.#D.level=e.level,this.#Z=Bt[e.level]}"callback"in e&&(this.#D.callback=e.callback),void 0!==e.callbackIgnoresLevel&&(this.#D.callbackIgnoresLevel=e.callbackIgnoresLevel)}getConfig(){return{level:this.#D.level,callback:this.#D.callback,callbackIgnoresLevel:this.#D.callbackIgnoresLevel}}log(e,t,...r){this.#G("log",e,t,r)}warn(e,t,...r){this.#G("warn",e,t,r)}error(e,t,...r){this.#G("error",e,t,r)}#G(e,t,r,n){if("none"===this.#D.level&&!this.#D.callbackIgnoresLevel)return;const a=Wt[e]<this.#Z;a||this.#K(e,t,r,n),this.#J(e,t,r,a,n)}#K(e,t,r,n){"undefined"!=typeof console&&"function"==typeof console[e]&&console[e](t?`[${t}] ${r}`:r,...n)}#J(e,t,r,n,a){if(this.#D.callback&&(this.#D.callbackIgnoresLevel||!n))try{this.#D.callback(e,t,r,...a)}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},Qt=(e,t)=>{const r=e.meta,n=t.meta,a=r?.params,i=n?.params,o=a&&i?{...a,...i}:a??i??{},s={id:1,options:{},redirected:!1,...n,...r,params:o};return{...e,meta:s}},Zt=new Set(Object.values(v)),Gt=new Set(["code","segment","path","redirect"]),Kt=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),Jt=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:n,redirect:a,...i}={}){super(t??e),this.code=e,this.segment=r,this.path=n,this.redirect=a?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}(a):void 0;for(const[e,t]of Object.entries(i)){if(Gt.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);Kt.has(e)||(this[e]=t)}}setCode(e){this.code=e,Zt.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(Gt.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);Kt.has(t)||(this[t]=r)}}hasField(e){return e in this}getField(e){return this[e]}toJSON(){const e={code:this.code,message:this.message};void 0!==this.segment&&(e.segment=this.segment),void 0!==this.path&&(e.path=this.path),void 0!==this.redirect&&(e.redirect=this.redirect);const t=new Set(["code","message","segment","path","redirect","stack"]);for(const r in this)Object.hasOwn(this,r)&&!t.has(r)&&(e[r]=this[r]);return e}},Yt=(e,t,r)=>{const n=r?{segment:r}:{};var a;void 0!==e&&("boolean"!=typeof e?c(e)?t(void 0,e):"object"==typeof(a=e)&&null!==a&&"then"in a&&"function"==typeof a.then?e.then(e=>{"boolean"==typeof e?e?t():t(new Jt(v.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 Jt(v.TRANSITION_ERR,r))}):t(new Jt(v.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})):e?t():t(new Jt(v.TRANSITION_ERR,n)))};function Xt(e,t,r,n){try{e(t,r)}catch(e){Ht.error(n,"Error in callback:",e)}}var er=new Set(["code","segment","path","redirect"]);function tr(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))er.has(r)||(t[r]=n);return{...r,...t}}return r}var rr="core:lifecycle",nr=(e,t,r,n,a,i,o)=>{let s=t;const u=n.filter(t=>e.has(t));if(0===u.length)return void Xt(o,void 0,s,rr);let l=0;const d=(e,t)=>{if(e)if(e.redirect){const t=new Jt(a,{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(i())return void Xt(o,new Jt(v.TRANSITION_CANCELLED),s,rr);if(t)return void Xt(o,Vt(a,t),s,rr);if(n&&n!==s&&c(n)){if(n.name!==s.name){const e=new Jt(a,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:n.name,params:n.params,path:n.path}});return void Xt(o,e,s,rr)}(n.params!==s.params||n.path!==s.path)&&Ht.error("core:transition","Warning: State mutated during transition",{from:s,to:n}),s=Qt(n,s)}if(l>=u.length)return void Xt(o,void 0,s,rr);const h=u[l++],f=e.get(h);try{const e=f(s,r,d);Yt(e,d,h)}catch(e){d(new Jt(v.TRANSITION_ERR,tr(e,h)))}};h()},ar="core:middleware";function ir(e,t,r,n,a){let i=!1,o=!1;const[s,u]=e.getLifecycleFunctions(),l=e.getMiddlewareFunctions(),d=t.name===y.UNKNOWN_ROUTE,h=()=>i||!e.isActive(),f=(e,r)=>{o||(o=!0,a(e,r??t))};return(()=>{const{toDeactivate:a,toActivate:i}=_t(t,r),o=!d&&i.length>0,p=l.length>0,g=(n,a)=>{if(n)f(n,a);else{if(r){const n=Lt(t.name),a=Lt(r.name),i=new Set(n);for(const t of a)!i.has(t)&&s.has(t)&&e.clearCanDeactivate(t)}f(void 0,a)}},m=(e,t)=>{e?f(e,t):((e,t)=>{p?((e,t,r,n,a)=>{let i=t,o=0;const s=(e,t)=>{e?u(e):u(void 0,t)},u=(t,u)=>{if(n())return void Xt(a,new Jt(v.TRANSITION_CANCELLED),i,ar);if(t)return void Xt(a,Vt(v.TRANSITION_ERR,t),i,ar);if(u&&u!==i&&c(u)&&((u.name!==i.name||u.params!==i.params||u.path!==i.path)&&Ht.error(ar,"Warning: State mutated during middleware execution",{from:i,to:u}),i=Qt(u,i)),o>=e.length)return void Xt(a,void 0,i,ar);const l=e[o++];try{const e=l(i,r,s);Yt(e,s)}catch(e){s(new Jt(v.TRANSITION_ERR,tr(e)))}};u()})(l,e,r,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,g)};var y;y=(e,t)=>{e?f(e,t):((e,t)=>{o?nr(u,e,r,i,v.CANNOT_ACTIVATE,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,m)},r&&!n.forceDeactivate&&a.length>0?nr(s,t,r,a,v.CANNOT_DEACTIVATE,h,y):y(void 0,t)})(),()=>{i||o||(i=!0,f(new Jt(v.TRANSITION_CANCELLED)))}}var or=()=>{};var sr=class{isRouterStarted;#Y=!1;#X=null;#g;#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,a){!function(e,t,r,n,a){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 a)throw new TypeError(`[router.navigateToState] Invalid emitSuccess: expected boolean, got ${f(a)}`)}(e,t,r,n,a)}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:{},opts:{},callback:e};const n=e??{};return"function"==typeof t?{params:n,opts:{},callback:t}:{params:n,opts:t??{},callback:r??or}}(e,t,r)}static parseNavigateToDefaultArgs(e,t){return function(e,t){return"function"==typeof e?{opts:{},callback:e}:{opts:e??{},callback:t??or}}(e,t)}setDependencies(e){this.#g=e}setTransitionDependencies(e){this.#ee=e}isNavigating(){return this.isRouterStarted()&&this.#Y}cancel(){this.#X&&(this.#X(),this.#X=null),this.#Y=!1}navigateToState(t,r,n,a,i){const o=this.#g,s=this.#ee;return this.#Y&&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.#Y=!0,o.invokeEventListeners(E.TRANSITION_START,t,r),this.#X=ir(s,t,r,n,(e,s)=>{if(this.#Y=!1,this.#X=null,e)e.code===v.TRANSITION_CANCELLED?o.invokeEventListeners(E.TRANSITION_CANCEL,t,r):o.invokeEventListeners(E.TRANSITION_ERROR,t,r,e),zt(a,e);else if(s.name===y.UNKNOWN_ROUTE||o.hasRoute(s.name))o.setState(s),i&&o.invokeEventListeners(E.TRANSITION_SUCCESS,s,r,n),zt(a,void 0,s);else{const e=new Jt(v.ROUTE_NOT_FOUND,{routeName:s.name});zt(a,e),o.invokeEventListeners(E.TRANSITION_ERROR,void 0,o.getState(),e)}}),this.#X}navigate(e,t,r,n){const a=this.#g;if(!this.isRouterStarted())return zt(n,new Jt(v.ROUTER_NOT_STARTED)),qt;const i=a.buildStateWithSegments(e,t);if(!i){const e=new Jt(v.ROUTE_NOT_FOUND);return zt(n,e),a.invokeEventListeners(E.TRANSITION_ERROR,void 0,a.getState(),e),qt}const{state:o}=i,s=a.makeState(o.name,o.params,a.buildPath(o.name,o.params),{params:o.meta,options:r,redirected:r.redirected??!1});if(r.skipTransition)return zt(n,void 0,s),qt;const c=a.getState();if(!r.reload&&!r.force&&a.areStatesEqual(c,s,!1)){const e=new Jt(v.SAME_STATES);return zt(n,e),a.invokeEventListeners(E.TRANSITION_ERROR,s,c,e),qt}return this.navigateToState(s,c,r,n,!0)}navigateToDefault(e,t){const r=this.#g.getOptions();return r.defaultRoute?this.navigate(r.defaultRoute,r.defaultParams,e,t):qt}},cr=()=>{},ur=new Jt(v.NO_START_PATH_OR_STATE),lr=new Jt(v.ROUTER_ALREADY_STARTED),dr=class{navigateToState;#te=!1;#re=!1;#g;static validateStartArgs(e){if(e.length>2)throw new Error("[router.start] Invalid number of arguments. Expected 0-2 arguments.")}setDependencies(e){this.#g=e}isStarted(){return this.#te}isActive(){return this.#re}start(...t){const r=this.#g,n=r.getOptions(),[a,i]=(e=>{const[t,r]=e;return t?"function"==typeof t?[void 0,t]:[t,r??cr]:[void 0,cr]})(t);let o=!1;if(this.#te||this.#re)return o=!0,void i(lr);if(!a&&!n.defaultRoute)return o=!0,r.hasListeners(E.TRANSITION_ERROR)&&r.invokeEventListeners(E.TRANSITION_ERROR,void 0,void 0,ur),void i(ur);this.#re=!0;const s={replace:!0},u=(t,n,a=!1)=>{t?(this.#re=!1,a&&r.hasListeners(E.TRANSITION_ERROR)&&r.invokeEventListeners(E.TRANSITION_ERROR,void 0,void 0,t)):(this.#te=!0,r.invokeEventListeners(E.ROUTER_START),r.invokeEventListeners(E.TRANSITION_SUCCESS,n,void 0,{replace:!0})),((t,r)=>{o?e.logger.warn("real-router","Callback already invoked"):(o=!0,i(t,r))})(t,n)},l=(e,t={})=>{this.navigateToState(e,void 0,t,(e,t)=>{u(e,t)},!1)},d=a??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?l(h,s):n.defaultRoute&&!a?((e,t,n)=>{const a=r.buildState(e,t);if(!a)return void u(new Jt(v.ROUTE_NOT_FOUND,{routeName:e}),void 0,!0);const i=r.makeState(a.name,a.params,r.buildPath(a.name,a.params),{params:a.meta,options:n,redirected:!1});l(i,n)})(n.defaultRoute,n.defaultParams,s):n.allowNotFound?l(r.makeNotFoundState(f,s),s):u(new Jt(v.ROUTE_NOT_FOUND,{path:f}),void 0,!0)}stop(){const e=this.#g;this.#re=!1,this.#te&&(this.#te=!1,e.setState(),e.invokeEventListeners(E.ROUTER_STOP))}},hr=class{#ne;#ae;static validateCloneArgs(e){if(void 0!==e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.clone] Invalid dependencies: expected plain object or undefined, received ${f(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[router.clone] Getters not allowed in dependencies: "${t}"`)}}setCallbacks(e,t){this.#ne=e,this.#ae=t}clone(e,t){const r=this.#ne(),n={...r.dependencies,...e},a=t(r.routes,r.options,n);for(const[e,t]of Object.entries(r.canDeactivateFactories))a.canDeactivate(e,t);for(const[e,t]of Object.entries(r.canActivateFactories))a.canActivate(e,t);return r.middlewareFactories.length>0&&a.useMiddleware(...r.middlewareFactories),r.pluginFactories.length>0&&a.usePlugin(...r.pluginFactories),this.#ae(a,r.routeConfig,r.resolvedForwardMap),a}},fr=new Set(["all","warn-error","error-only"]);var pr=class t{#l;#e;#ie;#oe;#se;#ce;#ue;#S;#le;#de;#he;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)||!fr.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),M.validateOptions(r,"constructor"),m.validateDependenciesObject(n,"constructor"),this.#l=new M(r),this.#e=new m(n),this.#ie=new N,this.#oe=new W,this.#se=new Ut(t),this.#ce=new K,this.#ue=new H,this.#S=new G,this.#le=new sr,this.#de=new dr,this.#he=new hr,this.#fe(),this.addRoute=this.addRoute.bind(this),this.removeRoute=this.removeRoute.bind(this),this.clearRoutes=this.clearRoutes.bind(this),this.getRoute=this.getRoute.bind(this),this.hasRoute=this.hasRoute.bind(this),this.updateRoute=this.updateRoute.bind(this),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.matchPath=this.matchPath.bind(this),this.setRootPath=this.setRootPath.bind(this),this.getRootPath=this.getRootPath.bind(this),this.makeState=this.makeState.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.forwardState=this.forwardState.bind(this),this.buildState=this.buildState.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.getOptions=this.getOptions.bind(this),this.getOption=this.getOption.bind(this),this.setOption=this.setOption.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.canDeactivate=this.canDeactivate.bind(this),this.canActivate=this.canActivate.bind(this),this.usePlugin=this.usePlugin.bind(this),this.useMiddleware=this.useMiddleware.bind(this),this.clearMiddleware=this.clearMiddleware.bind(this),this.setDependency=this.setDependency.bind(this),this.setDependencies=this.setDependencies.bind(this),this.getDependency=this.getDependency.bind(this),this.getDependencies=this.getDependencies.bind(this),this.removeDependency=this.removeDependency.bind(this),this.hasDependency=this.hasDependency.bind(this),this.resetDependencies=this.resetDependencies.bind(this),this.addEventListener=this.addEventListener.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToState=this.navigateToState.bind(this),this.subscribe=this.subscribe.bind(this),this.clone=this.clone.bind(this)}addRoute(e){const t=Array.isArray(e)?e:[e];return Ut.validateAddRouteArgs(t),Ut.validateRoutes(t,this.#se.getTree(),this.#se.getForwardRecord()),this.#se.addRoutes(t),this}removeRoute(t){return Ut.validateRemoveRouteArgs(t),this.#se.validateRemoveRoute(t,this.#oe.get()?.name,this.#le.isNavigating())?(this.#se.removeRoute(t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),this):this}clearRoutes(){return this.#se.validateClearRoutes(this.#le.isNavigating())?(this.#se.clearRoutes(),this.#ce.clearAll(),this.#oe.set(void 0),this):this}getRoute(e){return h(e,"getRoute"),this.#se.getRoute(e)}hasRoute(e){return h(e,"hasRoute"),this.#se.hasRoute(e)}updateRoute(t,r){Ut.validateUpdateRouteBasicArgs(t,r);const{forwardTo:n,defaultParams:a,decodeParams:i,encodeParams:o,canActivate:s}=r;return Ut.validateUpdateRoutePropertyTypes(n,a,i,o),this.#le.isNavigating()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),this.#se.validateUpdateRoute(t,n),this.#se.updateRouteConfig(t,{forwardTo:n,defaultParams:a,decodeParams:i,encodeParams:o}),void 0!==s&&(null===s?this.#ce.clearCanActivate(t,!0):this.canActivate(t,s)),this}isActiveRoute(t,r,n,a){return Ut.validateIsActiveRouteArgs(t,r,n,a),""===t?(e.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#se.isActiveRoute(t,r,n,a)}buildPath(e,t){return Ut.validateBuildPathArgs(e),this.#se.buildPath(e,t,this.#l.get())}matchPath(e,t){return Ut.validateMatchPathArgs(e),this.#se.matchPath(e,t,this.#l.get())}setRootPath(e){Ut.validateSetRootPathArgs(e),this.#se.setRootPath(e)}getRootPath(){return this.#se.getRootPath()}makeState(e,t,r,n,a){return W.validateMakeStateArgs(e,t,r,a),this.#oe.makeState(e,t,r,n,a)}getState(){return this.#oe.get()}getPreviousState(){return this.#oe.getPrevious()}areStatesEqual(e,t,r=!0){return W.validateAreStatesEqualArgs(e,t,r),this.#oe.areStatesEqual(e,t,r)}forwardState(e,t){return Ut.validateStateBuilderArgs(e,t,"forwardState"),this.#se.forwardState(e,t)}buildState(e,t){Ut.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:n}=this.forwardState(e,t);return this.#se.buildStateResolved(r,n)}shouldUpdateNode(e){return Ut.validateShouldUpdateNodeArgs(e),this.#se.shouldUpdateNode(e)}getOptions(){return this.#l.get()}getOption(e){return M.validateOptionName(e,"getOption"),M.validateOptionExists(e,"getOption"),this.#l.getOption(e)}setOption(e,t){return M.validateOptionName(e,"setOption"),M.validateOptionExists(e,"setOption"),M.validateNotLocked(this.#l.isLocked(),e),M.validateOptionValue(e,t,"setOption"),this.#l.set(e,t),this}isActive(){return this.#de.isActive()}start(...e){return dr.validateStartArgs(e),this.#l.lock(),this.#se.initBuildOptionsCache(this.#l.get()),this.#de.start(...e),this}stop(){return this.#de.stop(),this.#se.clearBuildOptionsCache(),this.#l.unlock(),this}canDeactivate(e,t){h(e,"canDeactivate"),K.validateHandler(t,"canDeactivate"),K.validateNotRegistering(this.#ce.isRegistering(e),e,"canDeactivate");const r=this.#ce.hasCanDeactivate(e);return r||K.validateHandlerLimit(this.#ce.countCanDeactivate()+1,"canDeactivate"),this.#ce.registerCanDeactivate(e,t,r),this}canActivate(e,t){h(e,"canActivate"),K.validateHandler(t,"canActivate"),K.validateNotRegistering(this.#ce.isRegistering(e),e,"canActivate");const r=this.#ce.hasCanActivate(e);return r||K.validateHandlerLimit(this.#ce.countCanActivate()+1,"canActivate"),this.#ce.registerCanActivate(e,t,r),this}usePlugin(...e){return G.validateUsePluginArgs(e),G.validatePluginLimit(this.#S.count(),e.length),G.validateNoDuplicatePlugins(e,this.#S.getAll()),this.#S.use(...e)}useMiddleware(...e){H.validateUseMiddlewareArgs(e),H.validateNoDuplicates(e,this.#ue.getFactories()),H.validateMiddlewareLimit(this.#ue.count(),e.length);const t=this.#ue.initialize(...e);for(const{middleware:e,factory:r}of t)H.validateMiddleware(e,r);return this.#ue.commit(t)}clearMiddleware(){return this.#ue.clear(),this}setDependency(e,t){return m.validateSetDependencyArgs(e),this.#e.set(e,t),this}setDependencies(e){return m.validateDependenciesObject(e,"setDependencies"),m.validateDependencyLimit(this.#e.count(),Object.keys(e).length,"setDependencies"),this.#e.setMultiple(e),this}getDependency(e){m.validateName(e,"getDependency");const t=this.#e.get(e);return m.validateDependencyExists(t,e),t}getDependencies(){return this.#e.getAll()}removeDependency(e){return m.validateName(e,"removeDependency"),this.#e.remove(e),this}hasDependency(e){return m.validateName(e,"hasDependency"),this.#e.has(e)}resetDependencies(){return this.#e.reset(),this}addEventListener(e,t){return N.validateListenerArgs(e,t),this.#ie.addEventListener(e,t)}navigate(e,t,r,n){sr.validateNavigateArgs(e);const{params:a,opts:i,callback:o}=sr.parseNavigateArgs(t,r,n);return sr.validateNavigationOptions(i,"navigate"),this.#le.navigate(e,a,i,o)}navigateToDefault(e,t){sr.validateNavigateToDefaultArgs(e,t);const{opts:r,callback:n}=sr.parseNavigateToDefaultArgs(e,t);return sr.validateNavigationOptions(r,"navigateToDefault"),this.#le.navigateToDefault(r,n)}navigateToState(e,t,r,n,a){return sr.validateNavigateToStateArgs(e,t,r,n,a),this.#le.navigateToState(e,t,r,n,a)}subscribe(e){return N.validateSubscribeListener(e),this.#ie.subscribe(e)}[Symbol.observable](){return this.#ie.observable()}"@@observable"(){return this.#ie.observable()}clone(e){return hr.validateCloneArgs(e),this.#he.clone(e,(e,r,n)=>new t(e,r,n))}#fe(){this.#ce.setRouter(this),this.#ce.setDependencies({getDependency:e=>this.#e.get(e)}),this.#se.setDependencies({canActivate:(e,t)=>{this.canActivate(e,t)},makeState:(e,t,r,n)=>this.#oe.makeState(e,t,r,n),getState:()=>this.#oe.get(),areStatesEqual:(e,t,r)=>this.#oe.areStatesEqual(e,t,r)}),this.#se.setLifecycleNamespace(this.#ce),this.#ue.setRouter(this),this.#ue.setDependencies({getDependency:e=>this.#e.get(e)}),this.#S.setRouter(this),this.#S.setDependencies({addEventListener:(e,t)=>this.#ie.addEventListener(e,t),isStarted:()=>this.#de.isStarted(),getDependency:e=>this.#e.get(e)}),this.#le.setDependencies({getOptions:()=>this.#l.get(),hasRoute:e=>this.#se.hasRoute(e),getState:()=>this.#oe.get(),setState:e=>{this.#oe.set(e)},buildStateWithSegments:(e,t)=>{Ut.validateStateBuilderArgs(e,t,"buildStateWithSegments");const{name:r,params:n}=this.forwardState(e,t);return this.#se.buildStateWithSegmentsResolved(r,n)},makeState:(e,t,r,n)=>this.#oe.makeState(e,t,r,n),buildPath:(e,t)=>this.buildPath(e,t),areStatesEqual:(e,t,r)=>this.#oe.areStatesEqual(e,t,r),invokeEventListeners:(e,t,r,n)=>{this.#ie.invoke(e,t,r,n)}}),this.#le.setTransitionDependencies({getLifecycleFunctions:()=>this.#ce.getFunctions(),getMiddlewareFunctions:()=>this.#ue.getFunctions(),isActive:()=>this.#de.isActive(),clearCanDeactivate:e=>{this.#ce.clearCanDeactivate(e)}}),this.#de.setDependencies({getOptions:()=>this.#l.get(),hasListeners:e=>this.#ie.hasListeners(e),invokeEventListeners:(e,t,r,n)=>{this.#ie.invoke(e,t,r,n)},buildState:(e,t)=>this.buildState(e,t),makeState:(e,t,r,n)=>this.#oe.makeState(e,t,r,n),buildPath:(e,t)=>this.buildPath(e,t),makeNotFoundState:(e,t)=>this.#oe.makeNotFoundState(e,t),setState:e=>{this.#oe.set(e)},matchPath:(e,t)=>this.#se.matchPath(e,t,this.#l.get())}),this.#ie.setGetState(()=>this.#oe.get()),this.#oe.setDependencies({getDefaultParams:()=>this.#se.getConfig().defaultParams,buildPath:(e,t)=>this.#se.buildPath(e,t,this.#l.get()),getUrlParams:e=>this.#se.getUrlParams(e)}),this.#le.isRouterStarted=()=>this.#de.isStarted(),this.#de.navigateToState=(e,t,r,n,a)=>this.#le.navigateToState(e,t,r,n,a),this.#he.setCallbacks(()=>{const[e,t]=this.#ce.getFactories();return{routes:this.#se.cloneRoutes(),options:{...this.#l.get()},dependencies:this.#e.getAll(),canDeactivateFactories:e,canActivateFactories:t,middlewareFactories:this.#ue.getFactories(),pluginFactories:this.#S.getAll(),routeConfig:this.#se.getConfig(),resolvedForwardMap:this.#se.getResolvedForwardMap()}},(e,t,r)=>{const n=e,a=n.#se.getConfig();Object.assign(a.decoders,t.decoders),Object.assign(a.encoders,t.encoders),Object.assign(a.defaultParams,t.defaultParams),Object.assign(a.forwardMap,t.forwardMap),n.#se.setResolvedForwardMap({...r})})}};exports.Router=pr,exports.RouterError=Jt,exports.constants=y,exports.createRouter=(e=[],t={},r={})=>new pr(e,t,r),exports.errorCodes=v,exports.events=E;//# 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 a(e,t){return new TypeError(`[router.${e}] ${t}`)}function i(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=>i(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=>i(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||i(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 a(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!r.test(e))throw a(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw a(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!n.test(e))throw a(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=100,m=class{#e=Object.create(null);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){!function(e,t,r){const n=e+t;if(n>=g)throw new Error(`[router.${r}] Dependency limit exceeded (100). Current: ${n}. This is likely a bug in your code.`)}(e,t,r)}set(t,r){if(void 0===r)return!1;if(Object.hasOwn(this.#e,t)){const n=this.#e[t],a=n!==r,i=Number.isNaN(n)&&Number.isNaN(r);a&&!i&&e.logger.warn("router.setDependency","Router dependency already exists and is being overwritten:",t)}else this.#t("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]}#t(t){const r=Object.keys(this.#e).length;if(20===r)e.logger.warn(`router.${t}`,"20 dependencies registered. Consider if all are necessary.");else if(50===r)e.logger.error(`router.${t}`,"50 dependencies registered! This indicates architectural problems. Hard limit at 100.");else if(r>=g)throw new Error(`[router.${t}] Dependency limit exceeded (100). Current: ${r}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}},v=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"}),y={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},w="onStart",b="onStop",T="onTransitionStart",S="onTransitionCancel",R="onTransitionSuccess",P="onTransitionError",E={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},A=new Set([E.ROUTER_START,E.TRANSITION_START,E.TRANSITION_SUCCESS,E.TRANSITION_ERROR,E.TRANSITION_CANCEL,E.ROUTER_STOP]);function O(t,r,...n){if(0===r.size)return;const a=[...r];for(const r of a)try{Function.prototype.apply.call(r,void 0,n)}catch(r){e.logger.error("Router",`Error in listener for ${t}:`,r)}}var $="function"==typeof Symbol&&Symbol.observable||"@@observable",N=class t{#r={};#n=null;#a=new WeakMap;#i=null;static validateEventName(e){if(!A.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 router[Symbol.observable]().subscribe(observer)")}setGetState(e){this.#i=e}invoke(e,t,r,n){this.#o(e);const a=this.#s();try{switch(a[e]++,e){case E.TRANSITION_START:case E.TRANSITION_CANCEL:O(e,this.#c(e),t,r);break;case E.TRANSITION_ERROR:case E.TRANSITION_SUCCESS:O(e,this.#c(e),t,r,n);break;default:O(e,this.#c(e))}}finally{a[e]--}}hasListeners(e){const t=this.#r[e];return void 0!==t&&t.size>0}removeEventListener(t,r){const n=this.#r[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.#c(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.`);if(1e3===n.size&&e.logger.warn("router.addEventListener",`Warning: Event "${t}" has ${n.size} listeners. This might indicate a memory leak.`),n.size>=1e4)throw new Error(`[router.addEventListener] Maximum listener limit (10000) reached for event "${t}". This is a critical memory leak. The application is creating listeners exponentially. Check for loops or recursive calls that register listeners.`);return n.add(r),()=>{this.removeEventListener(t,r)}}subscribe(e){return this.addEventListener(E.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}observable(){const e={[$]:()=>e,subscribe:this.#l.bind(this),"@@observable":()=>e};return e}#l(t,r={}){const n="function"==typeof t?{next:t}:t,a=this.#a.get(n);if(a?.active)return e.logger.warn("router.observable","Duplicate subscription prevented. Same observer already subscribed."),{unsubscribe:a.unsubscribe,get closed(){return!a.active}};const{signal:i,replay:o=!0}=r;if(i?.aborted)return{unsubscribe:()=>{},closed:!0};let s=!1;const c=t=>{if(!s&&n.next)try{n.next(t)}catch(t){if(e.logger.error("router.observable","Error in observer.next:",t),n.error)try{n.error(t)}catch(t){e.logger.error("router.observable","Error in observer.error:",t)}}},l=this.addEventListener(E.TRANSITION_SUCCESS,(e,t)=>{c({route:e,previousRoute:t})}),u={unsubscribe:void 0,active:!0},d=()=>{if(!s&&(s=!0,u.active=!1,l(),n.complete))try{n.complete()}catch(t){e.logger.error("router.observable","Error in observer.complete:",t)}};if(u.unsubscribe=d,this.#a.set(n,u),i&&i.addEventListener("abort",d,{once:!0}),o&&this.#i){const e=this.#i();e&&queueMicrotask(()=>{c({route:e,previousRoute:void 0})})}return{unsubscribe:d,get closed(){return s}}}#c(e){const t=this.#r[e];if(t)return t;const r=new Set;return this.#r[e]=r,r}#s(){return this.#n??={[E.ROUTER_START]:0,[E.TRANSITION_START]:0,[E.TRANSITION_SUCCESS]:0,[E.TRANSITION_ERROR]:0,[E.TRANSITION_CANCEL]:0,[E.ROUTER_STOP]:0},this.#n}#o(e){if(this.#s()[e]>=5)throw new Error(`[Router] Maximum recursion depth (5) exceeded for event: ${e}`)}},C={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},caseSensitive:!1,urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},k={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},D={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]},j=new Set(["defaultRoute","defaultParams"]);function I(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&I(r)}return e}function x(e,t,r){const n=C[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,D)){const e=Object.keys(D).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],a=D[r];if(!a.includes(n)){const e=a.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 k&&function(e,t,r){const n=k[e];if(!n.includes(t)){const a=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${a}, got "${String(t)}"`)}}(e,t,r)}var M=class{#u;#d=!1;constructor(e={}){this.#u=I({...C,...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(C,e))throw new ReferenceError(`[router.${t}]: option "${e}" not found`)}(e,t)}static validateNotLocked(e,t){!function(e,t){if(e&&!j.has(t))throw new Error("[router.setOption] Options cannot be changed after router.start(). Only defaultRoute/defaultParams can be changed after start.")}(e,t)}static validateOptionValue(e,t,r){x(e,t,r)}static validateOptions(e,t){!function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid options: expected plain object, got ${f(e)}`);for(const[r,n]of Object.entries(e)){if(!d(r,C))throw new TypeError(`[router.${t}] Unknown option: "${r}"`);void 0!==n&&x(r,n,t)}}(e,t)}get(){return this.#u}getOption(e){return this.#u[e]}set(e,t){const r=t&&"object"==typeof t&&t.constructor===Object?{...t}:t;this.#u=I({...this.#u,[e]:r})}isLocked(){return this.#d}lock(){this.#d=!0}unlock(){this.#d=!1}};function F(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>F(e,t[r]))}var L=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 U(e){return e?(L.has(e)||(_(e),L.add(e)),e):e}function q(e){switch(e){case"never":return"never";case"always":return"always";default:return"default"}}function V(e){const t={trailingSlashMode:q(e.trailingSlash),queryParamsMode:e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding};return void 0!==e.queryParams&&(t.queryParams=e.queryParams),t}var z=class{#h=0;#f=void 0;#p=void 0;#g;#m=new Map;static validateMakeStateArgs(e,t,r,n){if(!l(e))throw new TypeError(`[router.makeState] Invalid name: ${f(e)}. Expected string.`);if(void 0!==t&&!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.#f}set(e){this.#p=this.#f,e?Object.isFrozen(e)?this.#f=e:this.#f=U(e):this.#f=void 0}getPrevious(){return this.#p}setDependencies(e){this.#g=e}makeState(e,t,r,n,a){const i=n?{...n,id:a??++this.#h,params:n.params,options:n.options,redirected:n.redirected}:void 0,o=this.#g.getDefaultParams();let s;return s=Object.hasOwn(o,e)?{...o[e],...t}:t?{...t}:{},U({name:e,params:s,path:r??this.#g.buildPath(e,t),meta:i})}makeNotFoundState(e,t){return this.makeState(y.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.#v(e.name)).every(r=>F(e.params[r],t.params[r]))}const n=Object.keys(e.params),a=Object.keys(t.params);return n.length===a.length&&n.every(r=>r in t.params&&F(e.params[r],t.params[r]))}#v(e){const t=this.#m.get(e);if(void 0!==t)return t;const r=this.#g.getUrlParams(e);return this.#m.set(e,r),r}};function W(e){return e.name||"anonymous"}var B=class{#y=new Set;#w=new Map;#b;#g;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){!function(e,t){if(e+t>50)throw new Error(`[router.useMiddleware] Middleware limit exceeded (50). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating middleware.`)}(e,t)}setRouter(e){this.#b=e}setDependencies(e){this.#g=e}count(){return this.#y.size}initialize(...e){const t=[];for(const r of e){const e=r(this.#b,this.#g.getDependency);t.push({factory:r,middleware:e})}return t}commit(e){this.#T(e.length);for(const{factory:t,middleware:r}of e)this.#y.add(t),this.#w.set(t,r);let t=!1;return()=>{if(!t){t=!0;for(const{factory:t}of e)this.#y.delete(t),this.#w.delete(t)}}}clear(){this.#y.clear(),this.#w.clear()}getFactories(){return[...this.#y]}getFunctions(){return[...this.#w.values()]}#T(t){const r=t+this.#y.size;r>=30?e.logger.error("router.useMiddleware",`${r} middleware registered! This is excessive and will impact performance. Hard limit at 50.`):r>=15&&e.logger.warn("router.useMiddleware",`${r} middleware registered. Consider if all are necessary.`)}},H={[w]:E.ROUTER_START,[b]:E.ROUTER_STOP,[R]:E.TRANSITION_SUCCESS,[T]:E.TRANSITION_START,[P]:E.TRANSITION_ERROR,[S]:E.TRANSITION_CANCEL},Q=Object.keys(H).filter(e=>d(e,H)),Z="router.usePlugin",G=class t{#S=new Set;#b;#g;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,H))throw new TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}(e)}static validatePluginLimit(e,t){!function(e,t){if(e+t>50)throw new Error("[router.usePlugin] Plugin limit exceeded (50)")}(e,t)}static validateNoDuplicatePlugins(e,t){for(const r of e)if(t(r))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setRouter(e){this.#b=e}setDependencies(e){this.#g=e}count(){return this.#S.size}use(...t){if(this.#T(t.length),1===t.length){const r=t[0],n=this.#R(r);this.#S.add(r);let a=!1;return()=>{if(!a){a=!0,this.#S.delete(r);try{n()}catch(t){e.logger.error(Z,"Error during cleanup:",t)}}}}const r=this.#P(t),n=[];try{for(const e of r){const t=this.#R(e);n.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(Z,"Cleanup error:",t)}throw t}for(const{factory:e}of n)this.#S.add(e);let a=!1;return()=>{if(!a){a=!0;for(const{factory:e}of n)this.#S.delete(e);for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(Z,"Error during cleanup:",t)}}}}getAll(){return[...this.#S]}has(e){return this.#S.has(e)}#T(t){const r=t+this.#S.size;r>=25?e.logger.error(Z,`${r} plugins registered!`):r>=10&&e.logger.warn(Z,`${r} plugins registered`)}#P(t){const r=new Set;for(const n of t)r.has(n)?e.logger.warn(Z,"Duplicate factory in batch, will be registered once"):r.add(n);return r}#R(r){const n=this.#b,a=this.#g,i=r(n,a.getDependency);t.validatePlugin(i),Object.freeze(i);const o=[];for(const t of Q)t in i&&("function"==typeof i[t]?(o.push(a.addEventListener(H[t],i[t])),"onStart"===t&&a.isStarted()&&e.logger.warn(Z,"Router already started, onStart will not be called")):e.logger.warn(Z,`Property '${t}' is not a function, skipping`));return()=>{for(const e of o)e();"function"==typeof i.teardown&&i.teardown()}}},K=class{#E=new Map;#A=new Map;#O=new Map;#$=new Map;#N=new Set;#b;#g;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){!function(e,t){if(e>=200)throw new Error(`[router.${t}] Lifecycle handler limit exceeded (200). This indicates too many routes with individual handlers. Consider using middleware for cross-cutting concerns.`)}(e,t)}setRouter(e){this.#b=e}setDependencies(e){this.#g=e}isRegistering(e){return this.#N.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.#C("activate",e,t,this.#A,this.#$,"canActivate",r)}registerCanDeactivate(e,t,r){this.#C("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.#$]}#C(t,r,n,a,i,o,s){s?e.logger.warn(`router.${o}`,`Overwriting existing ${t} handler for route "${r}"`):this.#T(a.size+1,o);const c=u(n)?function(e){const t=()=>e;return()=>t}(n):n;a.set(r,c),this.#N.add(r);try{const e=c(this.#b,this.#g.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${o}] Factory must return a function, got ${f(e)}`);i.set(r,e)}catch(e){throw a.delete(r),e}finally{this.#N.delete(r)}}#T(t,r){t>=100?e.logger.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at 200.`):t>=50&&e.logger.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}},J=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)},Y=e=>encodeURIComponent(e),X={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${Y(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${Y(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${Y(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>Y(e)).join(",")}`}},ee={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}},te={default:{encode:e=>e},hidden:{encode:()=>""}},re=(e,t,r)=>({boolean:ee[t],null:te[r],array:X[e]}),ne={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:ee.none,null:te.default,array:X.none}},ae=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return ne;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:re(t,r,n)}},ie=e=>encodeURIComponent(e),oe=(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)}`}},se=e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)};function ce(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}function le(e,t,r,n,a){const i=e.indexOf("=",t),o=-1!==i&&i<r,s=e.slice(t,o?i:r),{name:c,hasBrackets:l}=ce(s);!function(e,t,r,n){const a=e[t];void 0===a?e[t]=n?[r]:r:Array.isArray(a)?a.push(r):e[t]=[a,r]}(n,J(c),function(e,t,r,n,a){return a?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const n=J(e);return t.boolean.decodeValue(n)})(n?e.slice(t+1,r):void 0,a):n?J(e.slice(t+1,r)):null}(e,i,r,o,a),l)}var ue=(e,t)=>{const r=se(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return de(e,t),t}(r);const n=ae(t),a={};let i=0;const o=r.length;for(;i<o;){let e=r.indexOf("&",i);-1===e&&(e=o),le(r,i,e,a,n.strategies),i=e+1}return a};function de(e,t){let r=0;const n=e.length;for(;r<n;){let a=e.indexOf("&",r);-1===a&&(a=n),le(e,r,a,t),r=a+1}}var he=(e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=ae(t),a=[];for(const t of r){const r=e[t];if(void 0===r)continue;const i=oe(t,r,n);i&&a.push(i)}return a.join("&")},fe=/[^\w!$'()*+,.:;|~-]/gu,pe=/[^\w!$'()*+,.:;|~-]/u,ge={default:e=>pe.test(e)?e.replaceAll(fe,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e,legacy:encodeURI},me={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e,legacy:decodeURIComponent},ve={urlParamsEncoding:"default"},ye={withQueryParams:String.raw`(\?.*$|$)`,withoutQueryParams:"$"},we=String.raw`([/?.;]|$)`,be=String.raw`[a-zA-Z0-9_.~%':|=+*@$-]+`,Te=e=>`(${e?e.replaceAll(/(^<|>$)/g,""):be})`,Se=[{name:"url-parameter",pattern:/^:([\w-]*[\dA-Za-z])(<(.+?)>)?/,regex:e=>new RegExp(Te(e[2]))},{name:"url-parameter-splat",pattern:/^\*([\w-]*[\dA-Za-z])/,regex:/([^?]*)/},{name:"url-parameter-matrix",pattern:/^;([\w-]*[\dA-Za-z])(<(.+?)>)?/,regex:e=>new RegExp(`;${e[1]}=${Te(e[2])}`)},{name:"query-parameter",pattern:/^[&?]:?([\w-]*[\dA-Za-z])/},{name:"delimiter",pattern:/^([/?])/,regex:e=>new RegExp(`\\${e[0]}`)},{name:"sub-delimiter",pattern:/^([!&.;_-])/,regex:e=>new RegExp(e[0])},{name:"fragment",pattern:/^([\dA-Za-z]+)/,regex:e=>new RegExp(e[0])}],Re=(e,t,r)=>{const n=ge[t],a=String(e);if(!r)return n(a);const i=a.split("/");let o=n(i[0]);for(let e=1;e<i.length;e++)o+="/"+n(i[e]);return o},Pe=(e,t)=>me[t](e),Ee=(e,t=[])=>{if(!Se.some(r=>{const n=r.pattern.exec(e);return!!n&&(t.push({type:r.name,match:n[0],val:n.slice(1,2),otherVal:n.slice(2),regex:"function"==typeof r.regex?r.regex(n):r.regex}),n[0].length<e.length&&Ee(e.slice(n[0].length),t),!0)}))throw new Error(`Could not parse path '${e}'`);return t},Ae=e=>null!=e,Oe=e=>"string"==typeof e||"number"==typeof e||"boolean"==typeof e,$e=e=>!!Ae(e)&&(!!Oe(e)||!!Array.isArray(e)&&e.every(e=>Oe(e))),Ne=(e,t,r="")=>{const n=e[t];return e[t]=void 0===n?r:[n,r],e},Ce=class e{path;tokens;hasUrlParams;hasSpatParam;hasMatrixParams;hasQueryParams;options;spatParams;urlParams;queryParams;params;source;regexCache;constraintPatterns;buildOptionsCache;compiledBuildPattern;constructor(e,t){if(!e)throw new Error("Missing path in Path constructor");this.path=e,this.options={...ve,...t},this.tokens=Ee(e),this.hasUrlParams=this.tokens.some(e=>e.type.startsWith("url-parameter")),this.hasSpatParam=this.tokens.some(e=>e.type.endsWith("splat")),this.hasMatrixParams=this.tokens.some(e=>e.type.endsWith("matrix")),this.hasQueryParams=this.tokens.some(e=>e.type.startsWith("query-parameter")),this.spatParams=this.getParams("url-parameter-splat"),this.urlParams=this.getParams(/^url-parameter/),this.queryParams=this.getParams("query-parameter"),this.params=[...this.urlParams,...this.queryParams];let r="";for(const e of this.tokens)void 0!==e.regex&&(r+=e.regex.source);this.source=r;const n=(e=>"\\/"===e?e:e.replace(/\\\/$/,"")+"(?:\\/)?")(r),a=r,i=r,o=(e=>/(\/)$/.test(e)?e:e+we)(r),s=this.hasQueryParams?ye.withQueryParams:ye.withoutQueryParams;this.regexCache={test:{sensitive:new RegExp("^"+n+s),insensitive:new RegExp("^"+n+s,"i")},testStrict:{sensitive:new RegExp("^"+a+s),insensitive:new RegExp("^"+a+s,"i")},partial:{sensitive:new RegExp("^"+i),insensitive:new RegExp("^"+i,"i")},partialDelimited:{sensitive:new RegExp("^"+o),insensitive:new RegExp("^"+o,"i")}},this.constraintPatterns=new Map;const c=this.tokens.filter(e=>e.type.startsWith("url-parameter")&&!e.type.endsWith("-splat"));for(const e of c){const t=e.val[0],r=e.otherVal[0],n=new RegExp("^"+Te(r)+"$");this.constraintPatterns.set(t,{pattern:n,constraint:r})}this.buildOptionsCache={ignoreConstraints:!1,ignoreSearch:!1,queryParams:this.options.queryParams??{},urlParamsEncoding:this.options.urlParamsEncoding};const l=this.tokens.filter(e=>!e.type.startsWith("query-parameter")),u=[],d=[];let h="";for(const e of l)e.type.startsWith("url-parameter")&&"url-parameter-matrix"!==e.type?(u.push(h),h="",d.push(e.val[0])):"url-parameter-matrix"===e.type?(h+=";"+e.val[0]+"=",u.push(h),h="",d.push(e.val[0])):h+=e.match;u.push(h),this.compiledBuildPattern={staticParts:u,paramNames:d,pattern:e}}static createPath(t,r){return new e(t,r)}isQueryParam(e){return this.queryParams.includes(e)}isSpatParam(e){return this.spatParams.includes(e)}test(e,t){const r=t?.caseSensitive??!1,n=t?.strictTrailingSlash?this.regexCache.testStrict:this.regexCache.test,a=this.urlTestWithRegex(e,r?n.sensitive:n.insensitive,t?.urlParamsEncoding??this.options.urlParamsEncoding);if(!a||!this.hasQueryParams)return a;const i=ue(e,t?.queryParams??this.options.queryParams);let o=!1;for(const e in i)this.isQueryParam(e)?a[e]=i[e]:o=!0;return o?null:a}partialTest(e,t){const r=t?.caseSensitive??!1,n=t?.delimited??1?this.regexCache.partialDelimited:this.regexCache.partial,a=this.urlTestWithRegex(e,r?n.sensitive:n.insensitive,t?.urlParamsEncoding??this.options.urlParamsEncoding);if(!a)return a;if(!this.hasQueryParams)return a;const i=ue(e,t?.queryParams??this.options.queryParams);for(const e in i)this.isQueryParam(e)&&Ne(a,e,i[e]);return a}build(e={},t){const r=t?{ignoreConstraints:t.ignoreConstraints??!1,ignoreSearch:t.ignoreSearch??!1,queryParams:t.queryParams??this.buildOptionsCache.queryParams,urlParamsEncoding:t.urlParamsEncoding??this.buildOptionsCache.urlParamsEncoding}:this.buildOptionsCache,n=this.encodeUrlParams(e,r.urlParamsEncoding);this.validateRequiredParams(e),r.ignoreConstraints||this.validateConstraints(n);const a=this.buildBasePath(n);return r.ignoreSearch?a:this.buildWithSearch(a,e,r.queryParams)}encodeUrlParams(e,t){const r={};for(const n of Object.keys(e)){if(this.isQueryParam(n))continue;const a=e[n];$e(a)&&(r[n]=this.encodeParamValue(a,n,t))}return r}encodeParamValue(e,t,r){if("boolean"==typeof e)return e;const n=this.isSpatParam(t);return Array.isArray(e)?e.map(e=>Re(e,r,n)):Re(e,r,n)}validateRequiredParams(e){const t=this.urlParams.filter(t=>!Ae(e[t]));if(t.length>0)throw new Error("Cannot build path: '"+this.path+"' requires missing parameters { "+t.join(", ")+" }")}validateConstraints(e){for(const[t,{pattern:r,constraint:n}]of this.constraintPatterns){const a=String(e[t]);if(!r.test(a)){const e=n?n.replaceAll(/(^<)|(>$)/g,""):"[^/]+";throw new Error(`Parameter '${t}' of '${this.path}' has invalid format: got '${a}', expected to match '${e}'`)}}}buildBasePath(e){return function(e,t){const{staticParts:r,paramNames:n}=e;if(0===n.length)return r[0];let a=r[0];for(const[e,i]of n.entries())a+=String(t[i])+r[e+1];return a}(this.compiledBuildPattern,e)}buildWithSearch(e,t,r){const n={};for(const e of this.queryParams)e in t&&(n[e]=t[e]);const a=he(n,r);return a?e+"?"+a:e}getParams(e){const t=[],r=e instanceof RegExp;for(const n of this.tokens)(r?e.test(n.type):n.type===e)&&t.push(n.val[0]);return t}urlTestWithRegex(e,t,r){const n=t.exec(e);if(!n)return null;if(0===this.urlParams.length)return{};const a={};for(let e=0;e<this.urlParams.length;e++)a[this.urlParams[e]]=Pe(n[e+1],r);return a}},ke=function(e){return new Ce(e)};function De(e,t){const r=e.path,n=r.startsWith("~"),a=n?r.slice(1):r,i={name:e.name,path:a,absolute:n,parser:a?ke(a):null,children:[],parent:t,nonAbsoluteChildren:[],absoluteDescendants:[],childrenByName:new Map,parentSegments:[],fullName:"",staticChildrenByFirstSegment:new Map};if(e.children)for(const t of e.children){const e=De(t,i);i.children.push(e)}return i}function je(e,t){const r=t.split(".");if(1===r.length)return{parent:e,finalName:t};let n=e;for(let e=0;e<r.length-1;e++){const t=r[e];n=n.children.find(e=>e.name===t)}return{parent:n,finalName:r.at(-1)}}var Ie=new Map;function xe(e){const t=e.startsWith("/")?1:0;let r=e.indexOf("/",t);const n=e.indexOf("?",t);-1!==n&&(-1===r||n<r)&&(r=n);const a=-1===r?e.slice(t):e.slice(t,r);return""===a||a.startsWith(":")||a.startsWith("*")||a.includes("(")?null:a.toLowerCase()}function Me(e,t){for(const r of e.children)r.absolute&&t.push(r),Me(r,t)}function Fe(e){const t=[];return Me(e,t),t}function Le(e,t,r){const n={name:e.name,path:e.path,absolute:e.absolute,parser:e.parser,parent:t,children:[],nonAbsoluteChildren:[],absoluteDescendants:[],childrenByName:new Map,parentSegments:[],fullName:"",staticPath:null,paramTypeMap:{},staticChildrenByFirstSegment:Ie};if(e.parser){for(const t of e.parser.urlParams)n.paramTypeMap[t]="url";for(const t of e.parser.queryParams)n.paramTypeMap[t]="query"}n.fullName=function(e){return e.parent?.name?`${e.parent.fullName}.${e.name}`:e.name}(n);for(const t of e.children){const e=Le(t,n,r);n.children.push(e),n.childrenByName.set(e.name,e),e.absolute||n.nonAbsoluteChildren.push(e)}return n.absoluteDescendants=Fe(n),n.parentSegments=function(e){const t=[];let r=e.parent;for(;r?.parser;)t.push(r),r=r.parent;return t.reverse(),t}(n),n.staticPath=function(e){const t=e.parser;if(!t)return null;if(t.hasUrlParams||t.hasQueryParams||t.hasSpatParam)return null;let r="";for(const t of e.parentSegments){const e=t.parser;if(e.hasUrlParams||e.hasQueryParams||e.hasSpatParam)return null;r=t.absolute?t.path:r+t.path}return r=e.absolute?e.path:r+e.path,r.replaceAll(/\/{2,}/g,"/")}(n),n.staticChildrenByFirstSegment=function(e,t){if(0===e.length)return Ie;const r=new Map;for(const t of e){const e=xe(t.path);if(null!==e){const n=r.get(e);n?n.push(t):r.set(e,[t])}}if(0===r.size)return Ie;if(t)for(const[e,t]of r)r.set(e,Object.freeze(t));return r}(n.nonAbsoluteChildren,r),r&&(Object.freeze(n.children),Object.freeze(n.nonAbsoluteChildren),Object.freeze(n.absoluteDescendants),Object.freeze(n.parentSegments),Object.freeze(n.paramTypeMap),Object.freeze(n)),n}function _e(e){let t="",r=0;for(const n of e)"<"===n?r++:">"===n?r--:0===r&&(t+=n);return function(e){return e.endsWith("/")&&e.length>1?e.slice(0,-1):e}(t.split("?")[0])}function Ue(e){!function(e){if(e.length<=1)return;const t=new Map;for(const[r,n]of e.entries()){const e=_e(n.path),a=e.split("/"),i=a.at(-1);t.set(n,{normalizedPath:e,segmentCount:a.length-1,lastSegmentLength:i.length,originalIndex:r})}e.sort((e,r)=>{const n=t.get(e),a=t.get(r);if("/"===n.normalizedPath)return 1;if("/"===a.normalizedPath)return-1;if(e.parser.hasSpatParam)return 1;if(r.parser.hasSpatParam)return-1;if(n.segmentCount<a.segmentCount)return 1;if(n.segmentCount>a.segmentCount)return-1;const i=e.parser.urlParams.length,o=r.parser.urlParams.length;return i<o?-1:i>o||n.lastSegmentLength<a.lastSegmentLength?1:n.lastSegmentLength>a.lastSegmentLength?-1:n.originalIndex-a.originalIndex})}(e.children);for(const t of e.children)Ue(t)}function qe(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build(n){const a=function(e,t,r){const n=De({name:e,path:t},null),a=[];for(const e of r)if(e.name.includes("."))a.push(e);else if(e.children&&e.children.length>0){const t=De(e,n);n.children.push(t)}else a.push(e);for(const e of a){const{parent:t,finalName:r}=je(n,e.name),a=De({name:r,path:e.path,children:e.children},t);t.children.push(a)}return n}(e,t,r);return n?.skipSort||Ue(a),function(e,t=!0){return Le(e,null,t)}(a,!n?.skipFreeze)}}}function Ve(e,t,r,n){return qe(e,t).addMany(r).build(n)}var ze=/^\/(\?|$)/,We=/\/$/,Be=/^\/\?/;function He(e){const t=e.startsWith("/")?1:0,r=e.charAt(t);return":"===r||"*"===r||""===r||"("===e.charAt(t)}var Qe={caseSensitive:!1,strictTrailingSlash:!1},Ze={caseSensitive:!1,strictTrailingSlash:!0},Ge={caseSensitive:!0,strictTrailingSlash:!1},Ke={caseSensitive:!0,strictTrailingSlash:!0},Je={caseSensitive:!1,delimited:!0},Ye={caseSensitive:!0,delimited:!0},Xe={caseSensitive:!1,delimited:!1},et={caseSensitive:!0,delimited:!1},tt={queryParamsMode:"default",strictTrailingSlash:!1,strongMatching:!0,caseSensitive:!1,queryParams:void 0,urlParamsEncoding:void 0,fullTestOptions:Qe,partialTestOptions:Je,buildOptions:{ignoreSearch:!0}};function rt(e,t,r,n,a,i){for(const o of e){if(i&&!He(o.path))continue;const e=nt(o,t,r,n,!1,a);if(void 0!==e)return e}return null}function nt(e,t,r,n,a,i){const o=e.parser,s=function(e,t,r){return"/"===r&&"/"===t?`/${e}`:e}(t,e.path,i),c=function(e,t,r,n){if(0===e.children.length){const e=t.test(r,n.fullTestOptions);if(e)return e}return t.partialTest(r,n.partialTestOptions)}(e,o,s,n);if(!c)return;const l=0===e.children.length,u=function(e,t,r,n){let a=e.build(t,r.buildOptions);return!r.strictTrailingSlash&&n&&(a=a.replace(We,"")),a}(o,c,n,l),d=function(e,t,r,n,a,i){let o=e.slice(t.length);!r.strictTrailingSlash&&n&&(o=o.replace(Be,"?"));const{querystring:s}=((e,t,r)=>{const n=se(e);if(""===n)return{querystring:"",removedParams:{}};if(0===t.length)return{querystring:e.startsWith("?")?e:n,removedParams:{}};const a=ae(r),i=e.startsWith("?"),o=new Set(t),s=[],c=[];!function(e,t){let r=0;const n=e.length;for(;r<n;){let a=e.indexOf("&",r);-1===a&&(a=n),t(e.slice(r,a)),r=a+1}}(n,e=>{const t=e.indexOf("="),r=-1===t?e:e.slice(0,t),{name:n}=ce(r);o.has(n)?c.push(e):s.push(e)});const l=s.join("&");return{querystring:i&&l?`?${l}`:l,removedParams:ue(c.join("&"),a)}})(function(e){const t=e.indexOf("?");return-1===t?"":e.slice(t+1)}(e.slice(t.length)),i.queryParams,r.queryParams);return o=function(e){const t=e.indexOf("?");return-1===t?e:e.slice(0,t)}(o)+(s?`?${s}`:""),r.strictTrailingSlash||a||"/"!==o||t.endsWith("/")||(o=""),o}(s,u,n,l,a,o);return r.segments.push(e),Object.assign(r.params,c),function(e,t,r,n,a,i){return a||0!==r.length?function(e,t,r){return!r&&"strict"!==t.queryParamsMode&&e.startsWith("?")}(r,n,a)?function(e,t){return r=t.slice(1),n=e.params,""!==r&&de(r,n),e;var r,n}(t,r):0===e.nonAbsoluteChildren.length?null:function(e,t,r,n,a){const i=e.staticChildrenByFirstSegment,o=e.nonAbsoluteChildren;if(0===i.size)return rt(o,t,r,n,a,!1);const s=function(e){let t=e.indexOf("/",1);const r=e.indexOf("?",1);return-1!==r&&(-1===t||r<t)&&(t=r),(-1===t?e.slice(1):e.slice(1,t)).toLowerCase()}(t),c=i.get(s);if(c){const e=rt(c,t,r,n,a,!1);if(null!==e)return e}return rt(o,t,r,n,a,!0)}(e,r,t,n,i):t}(e,r,d,n,a,u)}function at(e,t){const r=[],n=t.includes(".")?t.split("."):[t];e.parser&&r.push(e);let a=e;for(const e of n){const t=a.childrenByName.get(e);if(!t)return null;r.push(t),a=t}return r}var it=class extends Error{constructor(e){super(e),this.name="RouteNodeError",Object.setPrototypeOf(this,new.target.prototype)}},ot=class extends it{routeName;constructor(e,t){super(e),this.name="RouteNotFoundError",this.routeName=t}},st=Object.freeze([]);function ct(e,t,r){const{queryParamsMode:n="default",trailingSlashMode:a="default"}=r,i=function(e){let t=null,r=null;for(const n of e){const e=n.parser;if(e.queryParams.length>0){t??=[];for(let r=0;r<e.queryParams.length;r++)t.push(e.queryParams[r])}if(e.urlParams.length>0||e.spatParams.length>0){r??=[];for(let t=0;t<e.urlParams.length;t++)r.push(e.urlParams[t]);for(let t=0;t<e.spatParams.length;t++)r.push(e.spatParams[t])}}return{searchParams:t??st,nonSearchParams:r??st}}(e),o=function(e,t,r){if("loose"!==r)return e.searchParams;const n=[...e.searchParams],a=new Set(e.searchParams),i=new Set(e.nonSearchParams);for(const e in t)!Object.hasOwn(t,e)||a.has(e)||i.has(e)||n.push(e);return n}(i,t,n),s=function(e,t,r){const n={};for(const r of e)r in t&&(n[r]=t[r]);return he(n,r.queryParams)}(o,t,r),c=function(e,t,r){const n={ignoreSearch:!0,queryParams:r.queryParams,urlParamsEncoding:r.urlParamsEncoding};let a="";for(const r of e){const e=r.parser.build(t,n);a=r.absolute?e:a+e}return a.replaceAll(/\/{2,}/g,"/")}(e,t,r);return l=c,("always"===(u=a)?l.endsWith("/")?l:`${l}/`:"never"===u&&"/"!==l&&l.endsWith("/")?l.slice(0,-1):l)+(s?`?${s}`:"");var l,u}function lt(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return t}function ut(e){const t={name:e.name,path:e.absolute?`~${e.path}`:e.path};return e.children.length>0&&(t.children=e.children.map(e=>ut(e))),t}function dt(e,t){return new TypeError(`[router.${e}] ${t}`)}var ht=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/,ft=/\S/;function pt(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function gt(e,t,r,n="",a,i){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${pt(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${pt(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 ${pt(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!ft.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("@@")&&!ht.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,dt(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw dt(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw dt(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw dt(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const a=n?.parser&&("urlParams"in n.parser&&n.parser.urlParams.length>0||"hasUrlParams"in n.parser&&n.parser.hasUrlParams);if(e.startsWith("~")&&a)throw new Error(`[router.${r}] Absolute path "${e}" cannot be used under parent route with URL parameters`)}(o.path,o.name,t,r),function(e,t){if(void 0!==e.encodeParams&&"function"!=typeof e.encodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}(o,t),function(e,t){if(void 0!==e.decodeParams&&"function"!=typeof e.decodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}(o,t);const s=o.name,c=n?`${n}.${s}`:s;!n&&c.includes(".")&&function(e,t,r,n){const a=t.split(".");a.pop();const i=a.join(".");if(!n?.has(i)){if(e){const n=i.split(".");let a=e;for(const e of n)if(a=a.childrenByName.get(e),!a)throw new Error(`[router.${r}] Parent route "${i}" does not exist for route "${t}"`);return}throw new Error(`[router.${r}] Parent route "${i}" does not exist for route "${t}"`)}}(r,c,t,a),r&&c&&function(e,t,r){const n=t.split(".");let a=e;for(const e of n)if(a=a.childrenByName.get(e),!a)return;throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),a&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(a,c,t);const l=o.path;let u=n;if(s.includes(".")&&!n){const e=s.split(".");e.pop(),u=e.join(".")}if(r&&function(e,t,r){let n=e;if(""!==t){const e=t.split(".");for(const t of e)if(n=n.childrenByName.get(t),!n)return}for(const e of n.children)if(e.path===r)throw new Error(`Path "${r}" is already defined`)}(r,u,l),i&&function(e,t,r){const n=e.get(t);if(n?.has(r))throw new Error(`Path "${r}" is already defined`);n?n.add(r):e.set(t,new Set([r]))}(i,u,l),void 0!==o.children){if(!Array.isArray(o.children))throw new TypeError(`[router.${t}] Route "${s}" children must be an array, got ${pt(o.children)}`);for(const e of o.children)gt(e,t,r,c,a,i)}}var mt=new Set;function vt(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>vt(e))),t}function yt(e,t,r=""){for(let n=0;n<e.length;n++){const a=e[n],i=r?`${r}.${a.name}`:a.name;if(i===t)return e.splice(n,1),!0;if(a.children&&t.startsWith(`${i}.`)&&yt(a.children,t,i))return!0}return!1}function wt(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function bt(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)bt(r,`${t}.${r.name}`)}function Tt(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 St(e){const t=new Set;for(const r of e)for(const e of Tt(r))t.add(e);return t}function Rt(e,t,r="",n=[]){for(const a of e){const e=r?`${r}.${a.name}`:a.name,i=[...n,a.path];if(e===t)return i;if(a.children&&t.startsWith(`${e}.`))return Rt(a.children,t,e,i)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function Pt(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 Pt(n.children,e))r.add(t)}return r}function Et(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,a]of Et(n.children,e))r.set(t,a)}return r}function At(e,t,r,n){return t?function(e){const t=new Set;for(const r of e){for(const e of r.parser.urlParams)t.add(e);for(const e of r.parser.spatParams)t.add(e)}return t}(at(r,e)):St(Rt(n,e))}function Ot(e,t,r,n,a){const i=function(e,t){const r=t.split(".");let n=e;for(const e of r)if(n=n.childrenByName.get(e),!n)return!1;return!0}(a,t),o=n.has(t);if(!i&&!o)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const s=St(Rt(r,e)),c=[...At(t,i,a,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 $t(e,t,r=100){const n=new Set,a=[e];let i=e;for(;t[i];){const e=t[i];if(n.has(e)){const t=a.indexOf(e),r=[...a.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(i),a.push(e),i=e,a.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${a.join(" → ")}`)}return i}function Nt(e,t,r){const n=Pt(e),a=Et(e),i={...t};for(const[e,t]of a)i[e]=t;for(const[t,i]of a)Ot(t,i,e,n,r);for(const e of Object.keys(i))$t(e,i)}function Ct(e,t){const r=t??function(e){let t="";for(const r of e)r.name&&(t&&(t+="."),t+=r.name);return t}(e.segments);return{name:r,params:e.params,meta:lt(e.segments)}}var kt=".";function Dt(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function jt(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 a=t.params[e];null!=a&&("string"!=typeof a&&"number"!=typeof a&&"boolean"!=typeof a||(n[e]=String(a)))}return n}function It(e){if(!e)return[""];const t=e.indexOf(kt);if(-1===t)return[e];const r=e.indexOf(kt,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(kt,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(kt,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(kt),r=t.length,n=[t[0]];let a=t[0].length;for(let i=1;i<r-1;i++)a+=1+t[i].length,n.push(e.slice(0,a));return n.push(e),n}(e)}function xt(e,t){if(!t)return{intersection:"",toActivate:It(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:It(e.name),toDeactivate:Dt(It(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:It(e.name),toDeactivate:Dt(It(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 a=It(e.name),i=It(t.name),o=function(e,t,r,n,a){for(let i=0;i<a;i++){const a=r[i],o=n[i];if(a!==o)return i;const s=jt(a,e),c=jt(o,t),l=Object.keys(s),u=Object.keys(c);if(l.length!==u.length)return i;for(const e of l)if(s[e]!==c[e])return i}return a}(e,t,a,i,Math.min(i.length,a.length)),s=[];for(let e=i.length-1;e>=o;e--)s.push(i[e]);const c=a.slice(o);return{intersection:o>0?i[o-1]:"",toDeactivate:s,toActivate:c}}var Mt=class{#k=[];#D=function(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null)}}();#j=Object.create(null);#I=new Map;#x="";#M;#F;#g;#L;#_;constructor(e=[],t=!1){this.#_=t;for(const t of e)this.#k.push(vt(t));this.#M=Ve("",this.#x,this.#k),this.#U(e),t?this.#q():this.#V()}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)}`);bt(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,a=new Map;for(const r of e)gt(r,"addRoute",t,"",n,a);t&&r&&Nt(e,r,t)}(e,t,r)}setDependencies(e){this.#g=e;for(const[t,r]of this.#I)e.canActivate(t,r);this.#I.clear()}setLifecycleNamespace(e){this.#L=e}getRootPath(){return this.#x}getTree(){return this.#M}getForwardRecord(){return this.#D.forwardMap}setRootPath(e){this.#x=e,this.#z()}hasRoute(e){return function(e,t){const r=t.includes(".")?t.split("."):[t];let n=e;for(const e of r){const t=n.childrenByName.get(e);if(!t)return!1;n=t}return!0}(this.#M,e)}getRoute(e){const t=at(this.#M,e);if(!t)return;const r=ut(t.at(-1));return this.#W(r,e)}addRoutes(e){for(const t of e)this.#k.push(vt(t));this.#U(e),this.#z(),this.#B()}removeRoute(e){return!!yt(this.#k,e)&&(this.#H(e),this.#z(),this.#B(),!0)}updateRouteConfig(e,t){if(void 0!==t.forwardTo&&(null===t.forwardTo?delete this.#D.forwardMap[e]:this.#D.forwardMap[e]=t.forwardTo,this.#B()),void 0!==t.defaultParams&&(null===t.defaultParams?delete this.#D.defaultParams[e]:this.#D.defaultParams[e]=t.defaultParams),void 0!==t.decodeParams)if(null===t.decodeParams)delete this.#D.decoders[e];else{const r=t.decodeParams;this.#D.decoders[e]=e=>r(e)??e}if(void 0!==t.encodeParams)if(null===t.encodeParams)delete this.#D.encoders[e];else{const r=t.encodeParams;this.#D.encoders[e]=e=>r(e)??e}}clearRoutes(){this.#k.length=0;for(const e in this.#D.decoders)delete this.#D.decoders[e];for(const e in this.#D.encoders)delete this.#D.encoders[e];for(const e in this.#D.defaultParams)delete this.#D.defaultParams[e];for(const e in this.#D.forwardMap)delete this.#D.forwardMap[e];for(const e in this.#j)delete this.#j[e];this.#z()}buildPath(e,t,r,n){if(e===y.UNKNOWN_ROUTE)return l(t?.path)?t.path:"";const a=Object.hasOwn(this.#D.defaultParams,e)?{...this.#D.defaultParams[e],...t}:t??{},i="function"==typeof this.#D.encoders[e]?this.#D.encoders[e]({...a}):a,o=this.#F??V(r);return function(e,t,r={},n={},a){if(a)return ct(a,r,n);const i=function(e){for(const t in e)if(Object.hasOwn(e,t))return!0;return!1}(r),o=function(e){return void 0!==e.trailingSlashMode&&"default"!==e.trailingSlashMode||void 0!==e.queryParamsMode&&"default"!==e.queryParamsMode||void 0!==e.queryParams||void 0!==e.urlParamsEncoding&&"default"!==e.urlParamsEncoding}(n);if(!i&&!o){const r=function(e,t){if(t.includes(".")){const r=at(e,t),n=r?.at(-1)?.staticPath;return n??null}return e.childrenByName.get(t)?.staticPath??null}(e,t);if(null!==r)return r}const s=at(e,t);if(!s)throw new ot(`[route-node][buildPath] '${t}' is not defined`,t);return ct(s,r,n)}(this.#M,e,i,o,n)}matchPath(e,t,r){const n=r,a=function(e){return{...V(e),caseSensitive:e.caseSensitive,strictTrailingSlash:"strict"===e.trailingSlash,strongMatching:!1}}(n),i=function(e,t,r={}){let n=t;""!==n||r.strictTrailingSlash||(n="/");const a=function(e,t,r){const n=[];if(e.parser){n.push(e);for(let t=0;t<e.absoluteDescendants.length;t++)n.push(e.absoluteDescendants[t])}else for(const t of e.children){n.push(t);for(let e=0;e<t.absoluteDescendants.length;e++)n.push(t.absoluteDescendants[e])}const a=function(e){return void 0===e.queryParamsMode&&void 0===e.strictTrailingSlash&&void 0===e.strongMatching&&void 0===e.caseSensitive&&void 0===e.queryParams&&void 0===e.urlParamsEncoding&&void 0===e.trailingSlashMode||void 0!==e.trailingSlashMode&&void 0===e.queryParamsMode&&void 0===e.strictTrailingSlash&&void 0===e.strongMatching&&void 0===e.caseSensitive&&void 0===e.queryParams&&void 0===e.urlParamsEncoding?tt:function(e){const t=e.queryParamsMode??"default",r=e.strictTrailingSlash??!1,n=e.strongMatching??!0,a=e.caseSensitive??!1,{queryParams:i,urlParamsEncoding:o}=e,s=void 0===i&&void 0===o;return{queryParamsMode:t,strictTrailingSlash:r,strongMatching:n,caseSensitive:a,queryParams:i,urlParamsEncoding:o,fullTestOptions:s?function(e,t){return e?t?Ke:Ge:t?Ze:Qe}(a,r):{caseSensitive:a,strictTrailingSlash:r,queryParams:i,urlParamsEncoding:o},partialTestOptions:s?function(e,t){return e?t?Ye:et:t?Je:Xe}(a,n):{caseSensitive:a,delimited:n,queryParams:i,urlParamsEncoding:o},buildOptions:{ignoreSearch:!0,urlParamsEncoding:o}}}(e)}(r);return function(e,t,r,n){const a=1===e.length&&""===e[0].name;for(const i of e){const e=nt(i,t,r,n,a,void 0);if(void 0!==e)return e}return null}(n,t,{segments:[],params:{}},a)}(e,n,r);if(!a)return null;const i=a.segments;if(i[0]?.absolute){const e=i[0].parentSegments;for(let t=e.length-1;t>=0;t--)i.unshift(e[t])}const o=i.at(-1).nonAbsoluteChildren.find(e=>e.parser&&ze.test(e.parser.path));return o&&i.push(o),{segments:i,params:a.params}}(this.#M,e,a);if(i){const r=Ct(i),{name:a,params:o,meta:s}=r,c="function"==typeof this.#D.decoders[a]?this.#D.decoders[a](o):o,{name:l,params:u}=this.forwardState(a,c),d=n.rewritePathOnMatch?this.buildPath(l,u,n):e;return this.#g.makeState(l,u,d,{params:s,options:{},source:t,redirected:!1})}}forwardState(e,t){const r=this.#j[e]??e,n=Object.hasOwn(this.#D.defaultParams,e)?{...this.#D.defaultParams[e],...t}:{...t};return r!==e&&Object.hasOwn(this.#D.defaultParams,r)?{name:r,params:{...this.#D.defaultParams[r],...n}}:{name:r,params:n}}buildStateResolved(e,t){const r=at(this.#M,e);if(r)return Ct({segments:r,params:t},e)}buildStateWithSegmentsResolved(e,t){const r=at(this.#M,e);if(r)return{state:Ct({segments:r,params:t},e),segments:r}}initBuildOptionsCache(e){this.#F=V(e)}clearBuildOptionsCache(){this.#F=void 0}isActiveRoute(e,t={},r=!1,n=!0){mt.has(e)||(h(e,"isActiveRoute"),mt.add(e));const a=this.#g.getState();if(!a)return!1;const i=a.name;if(i!==e&&!i.startsWith(`${e}.`)&&!e.startsWith(`${i}.`))return!1;const o=this.#D.defaultParams[e];if(r||i===e){const r={name:e,params:o?{...o,...t}:t,path:""};return this.#g?.areStatesEqual(r,a,n)??!1}const s=a.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:a,toDeactivate:i}=xt(t,r);return e===n||!!a.includes(e)||i.includes(e)}}getConfig(){return this.#D}getUrlParams(e){const t=at(this.#M,e);return t?this.#Q(t):[]}getResolvedForwardMap(){return this.#j}setResolvedForwardMap(e){Object.assign(this.#j,e)}cloneRoutes(){return this.#M.children.map(e=>ut(e))}validateForwardToParamCompatibility(e,t){const r=at(this.#M,e),n=at(this.#M,t),a=this.#Z(r),i=this.#Q(n).filter(e=>!a.has(e));if(i.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${i.join(", ")}] that are not available in source route "${e}"`)}validateForwardToCycle(e,t){$t(e,{...this.#D.forwardMap,[e]:t})}validateRemoveRoute(t,r,n){if(r){const n=r===t,a=r.startsWith(`${t}.`);if(n||a)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)}}#z(){this.#M=Ve("",this.#x,this.#k)}#Z(e){const t=new Set;for(const r of e)for(const e of r.parser.urlParams)t.add(e);return t}#Q(e){const t=[];for(const r of e)for(const e of r.parser.urlParams)t.push(e);return t}#B(){this.#_?this.#q():this.#V()}#V(){for(const e in this.#j)delete this.#j[e];for(const e of Object.keys(this.#D.forwardMap))this.#j[e]=$t(e,this.#D.forwardMap)}#q(){for(const e in this.#j)delete this.#j[e];for(const e of Object.keys(this.#D.forwardMap)){let t=e;for(;this.#D.forwardMap[t];)t=this.#D.forwardMap[t];this.#j[e]=t}}#H(e){const t=t=>t===e||t.startsWith(`${e}.`);if(wt(this.#D.decoders,t),wt(this.#D.encoders,t),wt(this.#D.defaultParams,t),wt(this.#D.forwardMap,t),wt(this.#D.forwardMap,e=>t(this.#D.forwardMap[e])),this.#L){const[e,r]=this.#L.getFactories();for(const e of Object.keys(r))t(e)&&this.#L.clearCanActivate(e,!0);for(const r of Object.keys(e))t(r)&&this.#L.clearCanDeactivate(r,!0)}}#U(e,t=""){for(const r of e){const e=t?`${t}.${r.name}`:r.name;this.#G(r,e),r.children&&this.#U(r.children,e)}}#G(e,t){e.canActivate&&(this.#g?this.#g.canActivate(t,e.canActivate):this.#I.set(t,e.canActivate)),e.forwardTo&&this.#K(e,t),e.decodeParams&&(this.#D.decoders[t]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(this.#D.encoders[t]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(this.#D.defaultParams[t]=e.defaultParams)}#K(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.#D.forwardMap[r]=t.forwardTo}#W(e,t){const r={name:e.name,path:e.path},n=this.#D.forwardMap[t];if(n&&(r.forwardTo=n),t in this.#D.defaultParams&&(r.defaultParams=this.#D.defaultParams[t]),t in this.#D.decoders&&(r.decodeParams=this.#D.decoders[t]),t in this.#D.encoders&&(r.encodeParams=this.#D.encoders[t]),this.#L){const[,e]=this.#L.getFactories();t in e&&(r.canActivate=e[t])}return e.children&&(r.children=e.children.map(e=>this.#W(e,`${t}.${e.name}`))),r}},Ft=()=>{};function Lt(t,...r){try{t(...r)}catch(t){e.logger.error("router.navigate","Error in navigation callback:",t)}}var _t={log:0,warn:1,error:2},Ut={all:0,"warn-error":1,"error-only":2,none:3},qt=new class{#D={level:"all",callbackIgnoresLevel:!1};#J=0;configure(e){if(void 0!==e.level){if(!(e.level in Ut))throw new Error(`Invalid log level: "${e.level}". Valid levels are: ${Object.keys(Ut).join(", ")}`);this.#D.level=e.level,this.#J=Ut[e.level]}"callback"in e&&(this.#D.callback=e.callback),void 0!==e.callbackIgnoresLevel&&(this.#D.callbackIgnoresLevel=e.callbackIgnoresLevel)}getConfig(){return{level:this.#D.level,callback:this.#D.callback,callbackIgnoresLevel:this.#D.callbackIgnoresLevel}}log(e,t,...r){this.#Y("log",e,t,r)}warn(e,t,...r){this.#Y("warn",e,t,r)}error(e,t,...r){this.#Y("error",e,t,r)}#Y(e,t,r,n){if("none"===this.#D.level&&!this.#D.callbackIgnoresLevel)return;const a=_t[e]<this.#J;a||this.#X(e,t,r,n),this.#ee(e,t,r,a,n)}#X(e,t,r,n){"undefined"!=typeof console&&"function"==typeof console[e]&&console[e](t?`[${t}] ${r}`:r,...n)}#ee(e,t,r,n,a){if(this.#D.callback&&(this.#D.callbackIgnoresLevel||!n))try{this.#D.callback(e,t,r,...a)}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},zt=(e,t)=>{const r=e.meta,n=t.meta,a=r?.params,i=n?.params,o=a&&i?{...a,...i}:a??i??{},s={id:1,options:{},redirected:!1,...n,...r,params:o};return{...e,meta:s}},Wt=new Set(Object.values(v)),Bt=new Set(["code","segment","path","redirect"]),Ht=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),Qt=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:n,redirect:a,...i}={}){super(t??e),this.code=e,this.segment=r,this.path=n,this.redirect=a?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}(a):void 0;for(const[e,t]of Object.entries(i)){if(Bt.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);Ht.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(Bt.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);Ht.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}},Zt=(e,t,r)=>{const n=r?{segment:r}:{};var a;void 0!==e&&("boolean"!=typeof e?c(e)?t(void 0,e):"object"==typeof(a=e)&&null!==a&&"then"in a&&"function"==typeof a.then?e.then(e=>{"boolean"==typeof e?e?t():t(new Qt(v.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 Qt(v.TRANSITION_ERR,r))}):t(new Qt(v.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})):e?t():t(new Qt(v.TRANSITION_ERR,n)))};function Gt(e,t,r,n){try{e(t,r)}catch(e){qt.error(n,"Error in callback:",e)}}var Kt=new Set(["code","segment","path","redirect"]);function Jt(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))Kt.has(r)||(t[r]=n);return{...r,...t}}return r}var Yt="core:lifecycle",Xt=(e,t,r,n,a,i,o)=>{let s=t;const l=n.filter(t=>e.has(t));if(0===l.length)return void Gt(o,void 0,s,Yt);let u=0;const d=(e,t)=>{if(e)if(e.redirect){const t=new Qt(a,{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(i())return void Gt(o,new Qt(v.TRANSITION_CANCELLED),s,Yt);if(t)return void Gt(o,Vt(a,t),s,Yt);if(n&&n!==s&&c(n)){if(n.name!==s.name){const e=new Qt(a,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:n.name,params:n.params,path:n.path}});return void Gt(o,e,s,Yt)}(n.params!==s.params||n.path!==s.path)&&qt.error("core:transition","Warning: State mutated during transition",{from:s,to:n}),s=zt(n,s)}if(u>=l.length)return void Gt(o,void 0,s,Yt);const h=l[u++],f=e.get(h);try{const e=f(s,r,d);Zt(e,d,h)}catch(e){d(new Qt(v.TRANSITION_ERR,Jt(e,h)))}};h()},er="core:middleware";function tr(e,t,r,n,a){let i=!1,o=!1;const[s,l]=e.getLifecycleFunctions(),u=e.getMiddlewareFunctions(),d=t.name===y.UNKNOWN_ROUTE,h=()=>i||!e.isActive(),f=(e,r)=>{o||(o=!0,a(e,r??t))};return(()=>{const{toDeactivate:a,toActivate:i}=xt(t,r),o=!d&&i.length>0,p=u.length>0,g=(n,a)=>{if(n)f(n,a);else{if(r){const n=It(t.name),a=It(r.name),i=new Set(n);for(const t of a)!i.has(t)&&s.has(t)&&e.clearCanDeactivate(t)}f(void 0,a)}},m=(e,t)=>{e?f(e,t):((e,t)=>{p?((e,t,r,n,a)=>{let i=t,o=0;const s=(e,t)=>{e?l(e):l(void 0,t)},l=(t,l)=>{if(n())return void Gt(a,new Qt(v.TRANSITION_CANCELLED),i,er);if(t)return void Gt(a,Vt(v.TRANSITION_ERR,t),i,er);if(l&&l!==i&&c(l)&&((l.name!==i.name||l.params!==i.params||l.path!==i.path)&&qt.error(er,"Warning: State mutated during middleware execution",{from:i,to:l}),i=zt(l,i)),o>=e.length)return void Gt(a,void 0,i,er);const u=e[o++];try{const e=u(i,r,s);Zt(e,s)}catch(e){s(new Qt(v.TRANSITION_ERR,Jt(e)))}};l()})(u,e,r,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,g)};var y;y=(e,t)=>{e?f(e,t):((e,t)=>{o?Xt(l,e,r,i,v.CANNOT_ACTIVATE,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,m)},r&&!n.forceDeactivate&&a.length>0?Xt(s,t,r,a,v.CANNOT_DEACTIVATE,h,y):y(void 0,t)})(),()=>{i||o||(i=!0,f(new Qt(v.TRANSITION_CANCELLED)))}}var rr=()=>{},nr=Object.freeze({}),ar=Object.freeze({});var ir=class{isRouterStarted;#te=!1;#re=null;#g;#ne;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,a){!function(e,t,r,n,a){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 a)throw new TypeError(`[router.navigateToState] Invalid emitSuccess: expected boolean, got ${f(a)}`)}(e,t,r,n,a)}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:nr,opts:ar,callback:e};const n=e??nr;return"function"==typeof t?{params:n,opts:ar,callback:t}:{params:n,opts:t??ar,callback:r??rr}}(e,t,r)}static parseNavigateToDefaultArgs(e,t){return function(e,t){return"function"==typeof e?{opts:ar,callback:e}:{opts:e??ar,callback:t??rr}}(e,t)}setDependencies(e){this.#g=e}setTransitionDependencies(e){this.#ne=e}isNavigating(){return this.isRouterStarted()&&this.#te}cancel(){this.#re&&(this.#re(),this.#re=null),this.#te=!1}navigateToState(t,r,n,a,i){const o=this.#g,s=this.#ne;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(E.TRANSITION_START,t,r),this.#re=tr(s,t,r,n,(e,s)=>{if(this.#te=!1,this.#re=null,e)e.code===v.TRANSITION_CANCELLED?o.invokeEventListeners(E.TRANSITION_CANCEL,t,r):o.invokeEventListeners(E.TRANSITION_ERROR,t,r,e),Lt(a,e);else if(s.name===y.UNKNOWN_ROUTE||o.hasRoute(s.name))o.setState(s),i&&o.invokeEventListeners(E.TRANSITION_SUCCESS,s,r,n),Lt(a,void 0,s);else{const e=new Qt(v.ROUTE_NOT_FOUND,{routeName:s.name});Lt(a,e),o.invokeEventListeners(E.TRANSITION_ERROR,void 0,o.getState(),e)}}),this.#re}navigate(e,t,r,n){const a=this.#g;if(!this.isRouterStarted())return Lt(n,new Qt(v.ROUTER_NOT_STARTED)),Ft;const i=a.buildStateWithSegments(e,t);if(!i){const e=new Qt(v.ROUTE_NOT_FOUND);return Lt(n,e),a.invokeEventListeners(E.TRANSITION_ERROR,void 0,a.getState(),e),Ft}const{state:o,segments:s}=i,c=a.makeState(o.name,o.params,a.buildPath(o.name,o.params,s),{params:o.meta,options:r,redirected:r.redirected??!1});if(r.skipTransition)return Lt(n,void 0,c),Ft;const l=a.getState();if(!r.reload&&!r.force&&a.areStatesEqual(l,c,!1)){const e=new Qt(v.SAME_STATES);return Lt(n,e),a.invokeEventListeners(E.TRANSITION_ERROR,c,l,e),Ft}return this.navigateToState(c,l,r,n,!0)}navigateToDefault(e,t){const r=this.#g.getOptions();return r.defaultRoute?this.navigate(r.defaultRoute,r.defaultParams,e,t):Ft}},or=()=>{},sr=new Qt(v.NO_START_PATH_OR_STATE),cr=new Qt(v.ROUTER_ALREADY_STARTED),lr=class{navigateToState;#ae=!1;#ie=!1;#g;static validateStartArgs(e){if(e.length>2)throw new Error("[router.start] Invalid number of arguments. Expected 0-2 arguments.")}setDependencies(e){this.#g=e}isStarted(){return this.#ae}isActive(){return this.#ie}start(...t){const r=this.#g,n=r.getOptions(),[a,i]=(e=>{const[t,r]=e;return t?"function"==typeof t?[void 0,t]:[t,r??or]:[void 0,or]})(t);let o=!1;if(this.#ae||this.#ie)return o=!0,void i(cr);if(!a&&!n.defaultRoute)return o=!0,r.hasListeners(E.TRANSITION_ERROR)&&r.invokeEventListeners(E.TRANSITION_ERROR,void 0,void 0,sr),void i(sr);this.#ie=!0;const s={replace:!0},l=(t,n,a=!1)=>{t?(this.#ie=!1,a&&r.hasListeners(E.TRANSITION_ERROR)&&r.invokeEventListeners(E.TRANSITION_ERROR,void 0,void 0,t)):(this.#ae=!0,r.invokeEventListeners(E.ROUTER_START),r.invokeEventListeners(E.TRANSITION_SUCCESS,n,void 0,{replace:!0})),((t,r)=>{o?e.logger.warn("real-router","Callback already invoked"):(o=!0,i(t,r))})(t,n)},u=(e,t={})=>{this.navigateToState(e,void 0,t,(e,t)=>{l(e,t)},!1)},d=a??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&&!a?((e,t,n)=>{const a=r.buildState(e,t);if(!a)return void l(new Qt(v.ROUTE_NOT_FOUND,{routeName:e}),void 0,!0);const i=r.makeState(a.name,a.params,r.buildPath(a.name,a.params),{params:a.meta,options:n,redirected:!1});u(i,n)})(n.defaultRoute,n.defaultParams,s):n.allowNotFound?u(r.makeNotFoundState(f,s),s):l(new Qt(v.ROUTE_NOT_FOUND,{path:f}),void 0,!0)}stop(){const e=this.#g;this.#ie=!1,this.#ae&&(this.#ae=!1,e.setState(),e.invokeEventListeners(E.ROUTER_STOP))}},ur=class{#oe;#se;static validateCloneArgs(e){if(void 0!==e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.clone] Invalid dependencies: expected plain object or undefined, received ${f(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[router.clone] Getters not allowed in dependencies: "${t}"`)}}setCallbacks(e,t){this.#oe=e,this.#se=t}clone(e,t){const r=this.#oe(),n={...r.dependencies,...e},a=t(r.routes,r.options,n);for(const[e,t]of Object.entries(r.canDeactivateFactories))a.canDeactivate(e,t);for(const[e,t]of Object.entries(r.canActivateFactories))a.canActivate(e,t);return r.middlewareFactories.length>0&&a.useMiddleware(...r.middlewareFactories),r.pluginFactories.length>0&&a.usePlugin(...r.pluginFactories),this.#se(a,r.routeConfig,r.resolvedForwardMap),a}},dr=new Set(["all","warn-error","error-only"]);var hr=class t{#u;#e;#ce;#le;#ue;#de;#he;#S;#fe;#pe;#ge;#_;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)||!dr.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),M.validateOptions(r,"constructor");const a=r.noValidate??!1;a||m.validateDependenciesObject(n,"constructor"),!a&&t.length>0&&(Mt.validateAddRouteArgs(t),Mt.validateRoutes(t)),this.#u=new M(r),this.#e=new m(n),this.#ce=new N,this.#le=new z,this.#ue=new Mt(t,a),this.#de=new K,this.#he=new B,this.#S=new G,this.#fe=new ir,this.#pe=new lr,this.#ge=new ur,this.#_=a,this.#me(),this.addRoute=this.addRoute.bind(this),this.removeRoute=this.removeRoute.bind(this),this.clearRoutes=this.clearRoutes.bind(this),this.getRoute=this.getRoute.bind(this),this.hasRoute=this.hasRoute.bind(this),this.updateRoute=this.updateRoute.bind(this),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.matchPath=this.matchPath.bind(this),this.setRootPath=this.setRootPath.bind(this),this.getRootPath=this.getRootPath.bind(this),this.makeState=this.makeState.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.forwardState=this.forwardState.bind(this),this.buildState=this.buildState.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.getOptions=this.getOptions.bind(this),this.getOption=this.getOption.bind(this),this.setOption=this.setOption.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.canDeactivate=this.canDeactivate.bind(this),this.canActivate=this.canActivate.bind(this),this.usePlugin=this.usePlugin.bind(this),this.useMiddleware=this.useMiddleware.bind(this),this.clearMiddleware=this.clearMiddleware.bind(this),this.setDependency=this.setDependency.bind(this),this.setDependencies=this.setDependencies.bind(this),this.getDependency=this.getDependency.bind(this),this.getDependencies=this.getDependencies.bind(this),this.removeDependency=this.removeDependency.bind(this),this.hasDependency=this.hasDependency.bind(this),this.resetDependencies=this.resetDependencies.bind(this),this.addEventListener=this.addEventListener.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToState=this.navigateToState.bind(this),this.subscribe=this.subscribe.bind(this),this.clone=this.clone.bind(this)}addRoute(e){const t=Array.isArray(e)?e:[e];return this.#_||(Mt.validateAddRouteArgs(t),Mt.validateRoutes(t,this.#ue.getTree(),this.#ue.getForwardRecord())),this.#ue.addRoutes(t),this}removeRoute(t){return this.#_||Mt.validateRemoveRouteArgs(t),this.#ue.validateRemoveRoute(t,this.#le.get()?.name,this.#fe.isNavigating())?(this.#ue.removeRoute(t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),this):this}clearRoutes(){return this.#ue.validateClearRoutes(this.#fe.isNavigating())?(this.#ue.clearRoutes(),this.#de.clearAll(),this.#le.set(void 0),this):this}getRoute(e){return this.#_||h(e,"getRoute"),this.#ue.getRoute(e)}hasRoute(e){return this.#_||h(e,"hasRoute"),this.#ue.hasRoute(e)}updateRoute(t,r){this.#_||Mt.validateUpdateRouteBasicArgs(t,r);const{forwardTo:n,defaultParams:a,decodeParams:i,encodeParams:o,canActivate:s}=r;return this.#_||Mt.validateUpdateRoutePropertyTypes(n,a,i,o),this.#fe.isNavigating()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),this.#_||this.#ue.validateUpdateRoute(t,n),this.#ue.updateRouteConfig(t,{forwardTo:n,defaultParams:a,decodeParams:i,encodeParams:o}),void 0!==s&&(null===s?this.#de.clearCanActivate(t,!0):this.canActivate(t,s)),this}isActiveRoute(t,r,n,a){return this.#_||Mt.validateIsActiveRouteArgs(t,r,n,a),""===t?(e.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#ue.isActiveRoute(t,r,n,a)}buildPath(e,t){return this.#_||Mt.validateBuildPathArgs(e),this.#ue.buildPath(e,t,this.#u.get())}matchPath(e,t){return this.#_||Mt.validateMatchPathArgs(e),this.#ue.matchPath(e,t,this.#u.get())}setRootPath(e){this.#_||Mt.validateSetRootPathArgs(e),this.#ue.setRootPath(e)}getRootPath(){return this.#ue.getRootPath()}makeState(e,t,r,n,a){return this.#_||z.validateMakeStateArgs(e,t,r,a),this.#le.makeState(e,t,r,n,a)}getState(){return this.#le.get()}getPreviousState(){return this.#le.getPrevious()}areStatesEqual(e,t,r=!0){return this.#_||z.validateAreStatesEqualArgs(e,t,r),this.#le.areStatesEqual(e,t,r)}forwardState(e,t){return this.#_||Mt.validateStateBuilderArgs(e,t,"forwardState"),this.#ue.forwardState(e,t)}buildState(e,t){this.#_||Mt.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:n}=this.forwardState(e,t);return this.#ue.buildStateResolved(r,n)}shouldUpdateNode(e){return this.#_||Mt.validateShouldUpdateNodeArgs(e),this.#ue.shouldUpdateNode(e)}getOptions(){return this.#u.get()}getOption(e){return this.#_||(M.validateOptionName(e,"getOption"),M.validateOptionExists(e,"getOption")),this.#u.getOption(e)}setOption(e,t){return this.#_||(M.validateOptionName(e,"setOption"),M.validateOptionExists(e,"setOption"),M.validateNotLocked(this.#u.isLocked(),e),M.validateOptionValue(e,t,"setOption")),this.#u.set(e,t),this}isActive(){return this.#pe.isActive()}start(...e){return this.#_||lr.validateStartArgs(e),this.#u.lock(),this.#ue.initBuildOptionsCache(this.#u.get()),this.#pe.start(...e),this}stop(){return this.#pe.stop(),this.#ue.clearBuildOptionsCache(),this.#u.unlock(),this}canDeactivate(e,t){this.#_||(h(e,"canDeactivate"),K.validateHandler(t,"canDeactivate"),K.validateNotRegistering(this.#de.isRegistering(e),e,"canDeactivate"));const r=this.#de.hasCanDeactivate(e);return r||this.#_||K.validateHandlerLimit(this.#de.countCanDeactivate()+1,"canDeactivate"),this.#de.registerCanDeactivate(e,t,r),this}canActivate(e,t){this.#_||(h(e,"canActivate"),K.validateHandler(t,"canActivate"),K.validateNotRegistering(this.#de.isRegistering(e),e,"canActivate"));const r=this.#de.hasCanActivate(e);return r||this.#_||K.validateHandlerLimit(this.#de.countCanActivate()+1,"canActivate"),this.#de.registerCanActivate(e,t,r),this}usePlugin(...e){return this.#_||(G.validateUsePluginArgs(e),G.validatePluginLimit(this.#S.count(),e.length),G.validateNoDuplicatePlugins(e,this.#S.has.bind(this.#S))),this.#S.use(...e)}useMiddleware(...e){this.#_||(B.validateUseMiddlewareArgs(e),B.validateNoDuplicates(e,this.#he.getFactories()),B.validateMiddlewareLimit(this.#he.count(),e.length));const t=this.#he.initialize(...e);if(!this.#_)for(const{middleware:e,factory:r}of t)B.validateMiddleware(e,r);return this.#he.commit(t)}clearMiddleware(){return this.#he.clear(),this}setDependency(e,t){return this.#_||m.validateSetDependencyArgs(e),this.#e.set(e,t),this}setDependencies(e){return this.#_||(m.validateDependenciesObject(e,"setDependencies"),m.validateDependencyLimit(this.#e.count(),Object.keys(e).length,"setDependencies")),this.#e.setMultiple(e),this}getDependency(e){this.#_||m.validateName(e,"getDependency");const t=this.#e.get(e);return this.#_||m.validateDependencyExists(t,e),t}getDependencies(){return this.#e.getAll()}removeDependency(e){return this.#_||m.validateName(e,"removeDependency"),this.#e.remove(e),this}hasDependency(e){return this.#_||m.validateName(e,"hasDependency"),this.#e.has(e)}resetDependencies(){return this.#e.reset(),this}addEventListener(e,t){return this.#_||N.validateListenerArgs(e,t),this.#ce.addEventListener(e,t)}navigate(e,t,r,n){this.#_||ir.validateNavigateArgs(e);const{params:a,opts:i,callback:o}=ir.parseNavigateArgs(t,r,n);return this.#_||ir.validateNavigationOptions(i,"navigate"),this.#fe.navigate(e,a,i,o)}navigateToDefault(e,t){this.#_||ir.validateNavigateToDefaultArgs(e,t);const{opts:r,callback:n}=ir.parseNavigateToDefaultArgs(e,t);return this.#_||ir.validateNavigationOptions(r,"navigateToDefault"),this.#fe.navigateToDefault(r,n)}navigateToState(e,t,r,n,a){return this.#_||ir.validateNavigateToStateArgs(e,t,r,n,a),this.#fe.navigateToState(e,t,r,n,a)}subscribe(e){return this.#_||N.validateSubscribeListener(e),this.#ce.subscribe(e)}[Symbol.observable](){return this.#ce.observable()}"@@observable"(){return this.#ce.observable()}clone(e){return this.#_||ur.validateCloneArgs(e),this.#ge.clone(e,(e,r,n)=>new t(e,r,n))}#me(){this.#de.setRouter(this),this.#de.setDependencies({getDependency:e=>this.#e.get(e)}),this.#ue.setDependencies({canActivate:(e,t)=>{this.canActivate(e,t)},makeState:(e,t,r,n)=>this.#le.makeState(e,t,r,n),getState:()=>this.#le.get(),areStatesEqual:(e,t,r)=>this.#le.areStatesEqual(e,t,r)}),this.#ue.setLifecycleNamespace(this.#de),this.#he.setRouter(this),this.#he.setDependencies({getDependency:e=>this.#e.get(e)}),this.#S.setRouter(this),this.#S.setDependencies({addEventListener:(e,t)=>this.#ce.addEventListener(e,t),isStarted:()=>this.#pe.isStarted(),getDependency:e=>this.#e.get(e)}),this.#fe.setDependencies({getOptions:()=>this.#u.get(),hasRoute:e=>this.#ue.hasRoute(e),getState:()=>this.#le.get(),setState:e=>{this.#le.set(e)},buildStateWithSegments:(e,t)=>{const{name:r,params:n}=this.forwardState(e,t);return this.#ue.buildStateWithSegmentsResolved(r,n)},makeState:(e,t,r,n)=>this.#le.makeState(e,t,r,n),buildPath:(e,t,r)=>this.#ue.buildPath(e,t,this.#u.get(),r),areStatesEqual:(e,t,r)=>this.#le.areStatesEqual(e,t,r),invokeEventListeners:(e,t,r,n)=>{this.#ce.invoke(e,t,r,n)}}),this.#fe.setTransitionDependencies({getLifecycleFunctions:()=>this.#de.getFunctions(),getMiddlewareFunctions:()=>this.#he.getFunctions(),isActive:()=>this.#pe.isActive(),clearCanDeactivate:e=>{this.#de.clearCanDeactivate(e)}}),this.#pe.setDependencies({getOptions:()=>this.#u.get(),hasListeners:e=>this.#ce.hasListeners(e),invokeEventListeners:(e,t,r,n)=>{this.#ce.invoke(e,t,r,n)},buildState:(e,t)=>this.buildState(e,t),makeState:(e,t,r,n)=>this.#le.makeState(e,t,r,n),buildPath:(e,t)=>this.buildPath(e,t),makeNotFoundState:(e,t)=>this.#le.makeNotFoundState(e,t),setState:e=>{this.#le.set(e)},matchPath:(e,t)=>this.#ue.matchPath(e,t,this.#u.get())}),this.#ce.setGetState(()=>this.#le.get()),this.#le.setDependencies({getDefaultParams:()=>this.#ue.getConfig().defaultParams,buildPath:(e,t)=>this.#ue.buildPath(e,t,this.#u.get()),getUrlParams:e=>this.#ue.getUrlParams(e)}),this.#fe.isRouterStarted=()=>this.#pe.isStarted(),this.#pe.navigateToState=(e,t,r,n,a)=>this.#fe.navigateToState(e,t,r,n,a),this.#ge.setCallbacks(()=>{const[e,t]=this.#de.getFactories();return{routes:this.#ue.cloneRoutes(),options:{...this.#u.get()},dependencies:this.#e.getAll(),canDeactivateFactories:e,canActivateFactories:t,middlewareFactories:this.#he.getFactories(),pluginFactories:this.#S.getAll(),routeConfig:this.#ue.getConfig(),resolvedForwardMap:this.#ue.getResolvedForwardMap()}},(e,t,r)=>{const n=e,a=n.#ue.getConfig();Object.assign(a.decoders,t.decoders),Object.assign(a.encoders,t.encoders),Object.assign(a.defaultParams,t.defaultParams),Object.assign(a.forwardMap,t.forwardMap),n.#ue.setResolvedForwardMap({...r})})}};exports.Router=hr,exports.RouterError=Qt,exports.constants=y,exports.createRouter=(e=[],t={},r={})=>new hr(e,t,r),exports.errorCodes=v,exports.events=E;//# sourceMappingURL=index.js.map
|