@real-router/core 0.3.0 → 0.4.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"];function r(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}var n=/\S/,a=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function i(e,t){return new TypeError(`[router.${e}] ${t}`)}function o(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=>o(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=>o(e,t))}return!1}function s(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function c(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);if(null!==t&&t!==Object.prototype)return!1;let r=!1;for(const t in e){if(!Object.hasOwn(e,t))continue;const n=e[t];if(!s(n)){const e=typeof n;if("function"===e||"symbol"===e)return!1;r=!0;break}}return!r||o(e)}function u(e){return"object"==typeof e&&null!==e&&("string"==typeof(r=(t=e).name)&&(""===r||!(r.length>1e4)&&(!!r.startsWith("@@")||a.test(r)))&&"string"==typeof t.path&&c(t.params));var t,r}function l(e){return"string"==typeof e}function d(e){return"boolean"==typeof e}function h(e,t){return e in t}function f(e,t){if("string"!=typeof e)throw i(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!n.test(e))throw i(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw i(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!a.test(e))throw i(t,`Invalid route name "${e}". Each segment must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens. Segments are separated by dots (e.g., "users.profile").`)}}function p(e){return null===e?"null":Array.isArray(e)?`array[${e.length}]`:"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function g(e,t){if(!u(e))throw new TypeError(`[${t}] Invalid state structure: ${p(e)}. Expected State object with name, params, and path properties.`)}var m=100,v=class{#e=Object.create(null);constructor(e={}){this.setMultiple(e)}static validateName(e,t){if("string"!=typeof e)throw new TypeError(`[router.${t}]: dependency name must be a string, got ${typeof e}`)}static validateSetDependencyArgs(e){if("string"!=typeof e)throw new TypeError("[router.setDependency]: dependency name must be a string, got "+typeof e)}static validateDependenciesObject(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid argument: expected plain object, received ${p(e)}`);for(const r in e)if(Object.getOwnPropertyDescriptor(e,r)?.get)throw new TypeError(`[router.${t}] Getters not allowed: "${r}"`)}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=Object.keys(this.#e).length+Object.keys(t).length;if(r>=m)throw new Error(`[router.setDependencies] Dependency limit exceeded (100). Current: ${r}. This is likely a bug in your code.`);const n=[];for(const e in t)void 0!==t[e]&&(Object.hasOwn(this.#e,e)&&n.push(e),this.#e[e]=t[e]);n.length>0&&e.logger.warn("router.setDependencies","Overwritten:",n.join(", "))}get(e){const t=this.#e[e];if(void 0===t)throw new ReferenceError(`[router.getDependency]: dependency "${String(e)}" not found`);return t}getAll(){return{...this.#e}}remove(t){Object.hasOwn(this.#e,t)||e.logger.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${p(t)}"`),delete this.#e[t]}has(e){return Object.hasOwn(this.#e,e)}reset(){for(const e in this.#e)delete this.#e[e]}#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>=m)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.`)}},y=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"}),w={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},b="onStart",T="onStop",S="onTransitionStart",R="onTransitionCancel",E="onTransitionSuccess",P="onTransitionError",A={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},O=new Set([A.ROUTER_START,A.TRANSITION_START,A.TRANSITION_SUCCESS,A.TRANSITION_ERROR,A.TRANSITION_CANCEL,A.ROUTER_STOP]);function $(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)}}function N(e,t){if(!e)throw new TypeError(`[router.invokeEventListeners] toState is required for event "${t}"`);if(!u(e))throw new TypeError(`[router.invokeEventListeners] toState is invalid for event "${t}". Expected State object with name, path, and params.`)}function C(e,t){if(e&&!u(e))throw new TypeError(`[router.invokeEventListeners] fromState is invalid for event "${t}". Expected State object with name, path, and params.`)}var k=new WeakSet;function j(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)j(t);else for(const t in e)j(e[t])}function I(e){return e?(k.has(e)||(j(e),k.add(e)),e):e}function D(e){switch(e){case"never":return"never";case"always":return"always";default:return"default"}}function x(e){const t={trailingSlashMode:D(e.trailingSlash),queryParamsMode:e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding};return void 0!==e.queryParams&&(t.queryParams=e.queryParams),t}var F=new Set(Object.values(y)),M=new Set(["code","segment","path","redirect"]),L=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),_=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(M.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);L.has(e)||(this[e]=t)}}setCode(e){this.code=e,F.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(M.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);L.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}},U="function"==typeof Symbol&&Symbol.observable||"@@observable",q=class t{#r={};#n=null;#a=new WeakMap;#i=null;static validateEventName(e){if(!O.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)")}static validateInvokeArgs(e,n,a,i){switch(t.validateEventName(e),e){case A.TRANSITION_START:case A.TRANSITION_CANCEL:N(n,e),C(a,e);break;case A.TRANSITION_ERROR:if(function(e,t){if(e&&!u(e))throw new TypeError(`[router.invokeEventListeners] toState is invalid for event "${t}". Expected State object with name, path, and params.`)}(n,e),C(a,e),!i)throw new TypeError(`[router.invokeEventListeners] error is required for event "${e}"`);if(!(i instanceof _))throw new TypeError(`[router.invokeEventListeners] error must be a RouterError instance for event "${e}". Got: ${"object"==typeof i?i.constructor.name:typeof i}`);break;case A.TRANSITION_SUCCESS:if(N(n,e),C(a,e),!i)throw new TypeError(`[router.invokeEventListeners] options is required for event "${e}"`);if(i instanceof _)throw new TypeError(`[router.invokeEventListeners] options cannot be a RouterError for event "${e}". Use TRANSITION_ERROR event for errors.`);if(!r(i))throw new TypeError(`[router.invokeEventListeners] options is invalid for event "${e}". Expected NavigationOptions object.`)}}setGetState(e){this.#i=e}invoke(e,t,r,n){this.#o(e);const a=this.#s();try{switch(a[e]++,e){case A.TRANSITION_START:case A.TRANSITION_CANCEL:$(e,this.#c(e),t,r);break;case A.TRANSITION_ERROR:case A.TRANSITION_SUCCESS:$(e,this.#c(e),t,r,n);break;default:$(e,this.#c(e))}}finally{a[e]--}}hasListeners(e){if(!O.has(e))return!1;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(A.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}observable(){const e={[U]:()=>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(A.TRANSITION_SUCCESS,(e,t)=>{c({route:e,previousRoute:t})}),l=()=>{if(s)return;s=!0;const t=this.#a.get(n);if(t&&(t.active=!1),u(),n.complete)try{n.complete()}catch(t){e.logger.error("router.observable","Error in observer.complete:",t)}};if(this.#a.set(n,{unsubscribe:l,active:!0}),i&&i.addEventListener("abort",l,{once:!0}),o&&this.#i){const e=this.#i();e&&queueMicrotask(()=>{c({route:e,previousRoute:void 0})})}return{unsubscribe:l,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??={[A.ROUTER_START]:0,[A.TRANSITION_START]:0,[A.TRANSITION_SUCCESS]:0,[A.TRANSITION_ERROR]:0,[A.TRANSITION_CANCEL]:0,[A.ROUTER_STOP]:0},this.#n}#o(e){if(this.#s()[e]>=5)throw new Error(`[Router] Maximum recursion depth (5) exceeded for event: ${e}`)}},W={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},caseSensitive:!1,urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0},z={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},B={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]},V=new Set(["defaultRoute","defaultParams"]),H=(e,t)=>new ReferenceError(`[router.${e}]: option "${t}" not found`);function Q(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&Q(r)}return e}var Z=class e{#l;#d=!1;constructor(e={}){this.#l=Q({...W,...e})}static validateOptionName(e,t){if("string"!=typeof e)throw new TypeError(`[router.${t}]: option name must be a string, got ${typeof e}`)}static validatePlainObject(e,t,r){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${r}] Invalid type for "${t}": expected plain object, got ${p(e)}`);for(const n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw new TypeError(`[router.${r}] Getters not allowed in "${t}": "${n}"`)}static validateQueryParams(e,t){for(const r in e){if(!h(r,B)){const e=Object.keys(B).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],a=B[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)}"`)}}}static validateEnumOption(e,t,r){const n=z[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)}"`)}}static validateOptionValue(t,r,n){if(!Object.hasOwn(W,t))return;const a=W[t];if(a&&"object"==typeof a)return e.validatePlainObject(r,t,n),void("queryParams"===t&&e.validateQueryParams(r,n));if(typeof r!=typeof a)throw new TypeError(`[router.${n}] Invalid type for "${t}": expected ${typeof a}, got ${typeof r}`);t in z&&e.validateEnumOption(t,r,n)}static validateOptions(t,r){if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError(`[router.${r}] Invalid options: expected plain object, got ${p(t)}`);for(const[n,a]of Object.entries(t)){if(!h(n,W))throw new TypeError(`[router.${r}] Unknown option: "${n}"`);void 0!==a&&e.validateOptionValue(n,a,r)}}get(){return this.#l}getOption(e){if(!Object.hasOwn(this.#l,e))throw H("getOption",e);return this.#l[e]}set(e,t){if(this.#d&&!V.has(e))throw new Error("[router.setOption] Options cannot be changed after router.start(). Only defaultRoute/defaultParams can be changed after start.");if(!Object.hasOwn(this.#l,e))throw H("setOption",e);const r=t&&"object"==typeof t&&t.constructor===Object?{...t}:t;this.#l=Q({...this.#l,[e]:r})}lock(){this.#d=!0}unlock(){this.#d=!1}};function G(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>G(e,t[r]))}var K=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: ${p(e)}. Expected string.`);if(void 0!==t&&!c(t))throw new TypeError(`[router.makeState] Invalid params: ${p(t)}. Expected plain object.`);if(void 0!==r&&!l(r))throw new TypeError(`[router.makeState] Invalid path: ${p(r)}. Expected string.`);if(void 0!==n&&"number"!=typeof n)throw new TypeError(`[router.makeState] Invalid forceId: ${p(n)}. Expected number.`)}static validateAreStatesEqualArgs(e,t,r){if(null!=e&&g(e,"areStatesEqual"),null!=t&&g(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${p(r)}. Expected boolean.`)}static validateAreStatesDescendantsArgs(e,t){g(e,"areStatesDescendants"),g(t,"areStatesDescendants")}static validateMakeNotFoundStateArgs(e,t){if(!l(e))throw new TypeError(`[router.makeNotFoundState] Invalid path: ${p(e)}. Expected string.`);if(void 0!==t&&!r(t))throw new TypeError(`[router.makeNotFoundState] Invalid options: ${p(t)}. Expected NavigationOptions object.`)}get(){return this.#f}set(e){this.#p=this.#f,e?Object.isFrozen(e)?this.#f=e:this.#f=I(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}),I({name:e,params:c,path:r??this.#g.buildPath(e,t),meta:i})}makeNotFoundState(e,t){return this.makeState(w.UNKNOWN_ROUTE,{path:e},e,t?{options:t,params:{},redirected:!1}:void 0)}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=>G(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&&G(e.params[r],t.params[r]))}areStatesDescendants(t,r){return e.logger.warn("real-router","areStatesDescendants is deprecated and will be removed in the next major version. Use router.isActiveRoute() instead."),!!r.name.startsWith(`${t.name}.`)&&Object.keys(t.params).every(e=>G(t.params[e],r.params[e]))}#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 J(e){return e.name||"anonymous"}var Y=class t{#y=new Set;#w=new Map;#b;static validateUseMiddlewareArgs(e){for(const[t,r]of e.entries())if("function"!=typeof r)throw new TypeError(`[router.useMiddleware] Expected middleware factory function at index ${t}, got ${p(r)}`)}static validateMiddleware(e,t){if("function"!=typeof e)throw new TypeError(`[router.useMiddleware] Middleware factory must return a function, got ${p(e)}. Factory: ${J(t)}`)}setRouter(e){this.#b=e}use(...r){this.#T(r.length);for(const e of r)if(this.#y.has(e))throw new Error(`[router.useMiddleware] Middleware factory already registered. To re-register, first unsubscribe the existing middleware. Factory: ${J(e)}`);const n=[];try{for(const e of r){const r=e(this.#b,this.#b.getDependency.bind(this.#b));t.validateMiddleware(r,e),n.push({factory:e,middleware:r})}}catch(t){throw e.logger.error("router.useMiddleware","Failed to initialize middleware, rolling back",t),t}for(const{factory:e,middleware:t}of n)this.#y.add(e),this.#w.set(e,t);return()=>{for(const{factory:t}of n)this.#y.delete(t)||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(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;if(r>50)throw new Error(`[router.useMiddleware] Middleware limit exceeded (50). Current: ${this.#y.size}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating middleware.`);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.`)}},X={[b]:A.ROUTER_START,[T]:A.ROUTER_STOP,[E]:A.TRANSITION_SUCCESS,[S]:A.TRANSITION_START,[P]:A.TRANSITION_ERROR,[R]:A.TRANSITION_CANCEL},ee=Object.keys(X).filter(e=>h(e,X)),te="router.usePlugin",re=class t{#S=new Set;#b;static validateUsePluginArgs(e){for(const t of e)if("function"!=typeof t)throw new TypeError("[router.usePlugin] Expected plugin factory function, got "+typeof t)}static validatePlugin(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new TypeError(`[router.usePlugin] Plugin factory must return an object, got ${p(e)}`);if("function"==typeof e.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.");for(const t in e)if("teardown"!==t&&!h(t,X))throw new TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}setRouter(e){this.#b=e}use(...t){this.#T(t.length);const r=this.#R(t),n=[];try{for(const e of r){const t=this.#E(e);n.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(te,"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(te,"Error during cleanup:",t)}}}}getAll(){return[...this.#S]}#T(t){const r=t+this.#S.size;if(r>50)throw new Error("[router.usePlugin] Plugin limit exceeded (50)");r>=25?e.logger.error(te,`${r} plugins registered!`):r>=10&&e.logger.warn(te,`${r} plugins registered`)}#R(t){const r=new Set;for(const n of t){if(this.#S.has(n))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.");r.has(n)?e.logger.warn(te,"Duplicate factory in batch, will be registered once"):r.add(n)}return r}#E(r){const n=this.#b,a=r(n,n.getDependency.bind(n));t.validatePlugin(a),Object.freeze(a);const i=[];for(const t of ee)t in a&&("function"==typeof a[t]?(i.push(n.addEventListener(X[t],a[t])),"onStart"===t&&n.isStarted()&&e.logger.warn(te,"Router already started, onStart will not be called")):e.logger.warn(te,`Property '${t}' is not a function, skipping`));return()=>{for(const e of i)e();"function"==typeof a.teardown&&a.teardown()}}},ne=class{#P=new Map;#A=new Map;#O=new Map;#$=new Map;#N=new Set;#b;static validateHandler(e,t){if(!d(e)&&"function"!=typeof e)throw new TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${p(e)}`)}setRouter(e){this.#b=e}registerCanActivate(e,t){this.#C("activate",e,t,this.#A,this.#$,"canActivate")}registerCanDeactivate(e,t){this.#C("deactivate",e,t,this.#P,this.#O,"canDeactivate")}clearCanActivate(t,r=!1){if(this.#N.has(t))throw new Error(`[router.clearCanActivate] Cannot modify route "${t}" during its own registration`);const n=this.#A.delete(t),a=this.#$.delete(t);r||n||a||e.logger.warn("router.clearCanActivate",`No canActivate handler found for route "${t}"`)}clearCanDeactivate(t,r=!1){if(this.#N.has(t))throw new Error(`[router.clearCanDeactivate] Cannot modify route "${t}" during its own registration`);const n=this.#P.delete(t),a=this.#O.delete(t);r||n||a||e.logger.warn("router.clearCanDeactivate",`No canDeactivate handler found for route "${t}"`)}clearAll(){this.#A.clear(),this.#$.clear(),this.#P.clear(),this.#O.clear()}getFactories(){const e={},t={};for(const[t,r]of this.#P)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){if(this.#N.has(r))throw new Error(`[router.${o}] Cannot modify route "${r}" during its own registration`);a.has(r)?e.logger.warn(`router.${o}`,`Overwriting existing ${t} handler for route "${r}"`):this.#k(a.size+1,o);const s=d(n)?function(e){const t=()=>e;return()=>t}(n):n;a.set(r,s),this.#N.add(r);try{const e=s(this.#b,this.#b.getDependency.bind(this.#b));if("function"!=typeof e)throw new TypeError(`[router.${o}] Factory must return a function, got ${p(e)}`);i.set(r,e)}catch(e){throw a.delete(r),e}finally{this.#N.delete(r)}}#k(t,r){if(t>=200)throw new Error(`[router.${r}] Lifecycle handler limit exceeded (200). This indicates too many routes with individual handlers. Consider using middleware for cross-cutting concerns.`);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.`)}},ae=e=>{const t=e.indexOf("%"),r=e.indexOf("+");if(-1===t&&-1===r)return e;const n=-1===r?e:e.split("+").join(" ");return-1===t?n:decodeURIComponent(n)},ie=e=>encodeURIComponent(e),oe={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${ie(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${ie(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${ie(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>ie(e)).join(",")}`}},se={none:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:e=>e},string:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:e=>"true"===e||"false"!==e&&null,decodeValue:e=>e},"empty-true":{encode:(e,t)=>t?e:`${e}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:e=>e}},ce={default:{encode:e=>e},hidden:{encode:()=>""}},ue=(e,t,r)=>({boolean:se[t],null:ce[r],array:oe[e]}),le={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:se.none,null:ce.default,array:oe.none}},de=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return le;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:ue(t,r,n)}},he=e=>encodeURIComponent(e),fe=(e,t,r)=>{const n=he(e);switch(typeof t){case"string":case"number":default:return`${n}=${he(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}=${he(t)}`}},pe=e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)};function ge(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}function me(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}=ge(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,ae(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=ae(e);return t.boolean.decodeValue(n)})(n?e.slice(t+1,r):void 0,a):n?ae(e.slice(t+1,r)):null}(e,i,r,o,a),u)}var ve=(e,t)=>{const r=pe(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return ye(e,t),t}(r);const n=de(t),a={};let i=0;const o=r.length;for(;i<o;){let e=r.indexOf("&",i);-1===e&&(e=o),me(r,i,e,a,n.strategies),i=e+1}return a};function ye(e,t){let r=0;const n=e.length;for(;r<n;){let a=e.indexOf("&",r);-1===a&&(a=n),me(e,r,a,t),r=a+1}}var we=(e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=de(t),a=[];for(const t of r){const r=e[t];if(void 0===r)continue;const i=fe(t,r,n);i&&a.push(i)}return a.join("&")},be=/[^\w!$'()*+,.:;|~-]/gu,Te=/[^\w!$'()*+,.:;|~-]/u,Se={default:e=>Te.test(e)?e.replaceAll(be,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e,legacy:encodeURI},Re={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e,legacy:decodeURIComponent},Ee={urlParamsEncoding:"default"},Pe={withQueryParams:String.raw`(\?.*$|$)`,withoutQueryParams:"$"},Ae=String.raw`([/?.;]|$)`,Oe=String.raw`[a-zA-Z0-9_.~%':|=+*@$-]+`,$e=e=>`(${e?e.replaceAll(/(^<|>$)/g,""):Oe})`,Ne=[{name:"url-parameter",pattern:/^:([\w-]*[\dA-Za-z])(<(.+?)>)?/,regex:e=>new RegExp($e(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]}=${$e(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])}],Ce=(e,t,r)=>{const n=Se[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},ke=(e,t)=>Re[t](e),je=(e,t=[])=>{if(!Ne.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&&je(e.slice(n[0].length),t),!0)}))throw new Error(`Could not parse path '${e}'`);return t},Ie=e=>null!=e,De=e=>"string"==typeof e||"number"==typeof e||"boolean"==typeof e,xe=e=>!!Ie(e)&&(!!De(e)||!!Array.isArray(e)&&e.every(e=>De(e))),Fe=(e,t,r="")=>{const n=e[t];return e[t]=void 0===n?r:[n,r],e},Me=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={...Ee,...t},this.tokens=je(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+Ae)(r),s=this.hasQueryParams?Pe.withQueryParams:Pe.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("^"+$e(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=ve(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=ve(e,t?.queryParams??this.options.queryParams);for(const e in i)this.isQueryParam(e)&&Fe(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];xe(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=>Ce(e,r,n)):Ce(e,r,n)}validateRequiredParams(e){const t=this.urlParams.filter(t=>!Ie(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=we(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]]=ke(n[e+1],r);return a}},Le=function(e){return new Me(e)};function _e(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?Le(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=_e(t,i);i.children.push(e)}return i}function Ue(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 qe=new Map;function We(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 ze(e,t){for(const r of e.children)r.absolute&&t.push(r),ze(r,t)}function Be(e){const t=[];return ze(e,t),t}function Ve(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:qe};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=Ve(t,n,r);n.children.push(e),n.childrenByName.set(e.name,e),e.absolute||n.nonAbsoluteChildren.push(e)}return n.absoluteDescendants=Be(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 qe;const r=new Map;for(const t of e){const e=We(t.path);if(null!==e){const n=r.get(e);n?n.push(t):r.set(e,[t])}}if(0===r.size)return qe;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 He(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 Qe(e){!function(e){if(e.length<=1)return;const t=new Map;for(const[r,n]of e.entries()){const e=He(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)Qe(t)}var Ze=class extends Error{constructor(e){super(e),this.name="RouteNodeError",Object.setPrototypeOf(this,new.target.prototype)}},Ge=class extends Ze{duplicateValue;duplicateType;constructor(e,t,r){super(e),this.name="DuplicateRouteError",this.duplicateValue=t,this.duplicateType=r}},Ke=class extends Ze{constructor(e){super(e),this.name="InvalidRouteError"}},Je=class extends Ze{routeName;constructor(e,t){super(e),this.name="RouteNotFoundError",this.routeName=t}};function Ye(e){if(!e.name||"string"!=typeof e.name)throw new Ke("Route definition must have a 'name' property of type string.");if("string"!=typeof e.path)throw new Ke(`Route "${e.name}" must have a 'path' property of type string.`)}function Xe(e,t){if(t.has(e))throw new Ge(`Duplicate route name "${e}" found.`,e,"name");t.add(e)}function et(e,t,r){const n=r.get(t);if(n?.has(e))throw new Ge(`Path "${e}" is already defined`,e,"path");n?n.add(e):r.set(t,new Set([e]))}function tt(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){Ye(i);const e=a?`${a}.${i.name}`:i.name;Xe(e,t),et(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=_e({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=_e(e,n);n.children.push(t)}else a.push(e);for(const e of a){const{parent:t,finalName:r}=Ue(n,e.name),a=_e({name:r,path:e.path,children:e.children},t);t.children.push(a)}return n}(e,t,r);return n?.skipSort||Qe(a),function(e,t=!0){return Ve(e,null,t)}(a,!n?.skipFreeze)}}}function rt(e,t,r,n){return tt(e,t).addMany(r).build(n)}var nt=/^\/(\?|$)/,at=/\/$/,it=/^\/\?/;function ot(e){const t=e.startsWith("/")?1:0,r=e.charAt(t);return":"===r||"*"===r||""===r||"("===e.charAt(t)}var st={caseSensitive:!1,strictTrailingSlash:!1},ct={caseSensitive:!1,strictTrailingSlash:!0},ut={caseSensitive:!0,strictTrailingSlash:!1},lt={caseSensitive:!0,strictTrailingSlash:!0},dt={caseSensitive:!1,delimited:!0},ht={caseSensitive:!0,delimited:!0},ft={caseSensitive:!1,delimited:!1},pt={caseSensitive:!0,delimited:!1},gt={queryParamsMode:"default",strictTrailingSlash:!1,strongMatching:!0,caseSensitive:!1,queryParams:void 0,urlParamsEncoding:void 0,fullTestOptions:st,partialTestOptions:dt,buildOptions:{ignoreSearch:!0}};function mt(e,t,r,n,a,i){for(const o of e){if(i&&!ot(o.path))continue;const e=vt(o,t,r,n,!1,a);if(void 0!==e)return e}return null}function vt(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(at,"")),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(it,"?"));const{querystring:s}=((e,t,r)=>{const n=pe(e);if(""===n)return{querystring:"",removedParams:{}};if(0===t.length)return{querystring:e.startsWith("?")?e:n,removedParams:{}};const a=de(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}=ge(r);o.has(n)?c.push(e):s.push(e)});const u=s.join("&");return{querystring:i&&u?`?${u}`:u,removedParams:ve(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&&ye(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 mt(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=mt(c,t,r,n,a,!1);if(null!==e)return e}return mt(o,t,r,n,a,!0)}(e,r,t,n,i):t}(e,r,d,n,a,l)}function yt(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 wt=Object.freeze([]);function bt(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return t}function Tt(e){const t={name:e.name,path:e.absolute?`~${e.path}`:e.path};return e.children.length>0&&(t.children=e.children.map(e=>Tt(e))),t}function St(e,t){return new TypeError(`[router.${e}] ${t}`)}var Rt=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/,Et=/\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 At(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(!Et.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("@@")&&!Rt.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,St(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw St(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw St(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw St(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 ${Pt(o.children)}`);for(const e of o.children)At(e,t,r,c,a,i)}}var Ot=new Set;function $t(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>$t(e))),t}function Nt(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}.`)&&Nt(a.children,t,i))return!0}return!1}function Ct(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function kt(e,t){if(void 0!==e.canActivate&&"function"!=typeof e.canActivate)throw new TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${p(e.canActivate)}`);if(void 0!==e.canDeactivate&&"function"!=typeof e.canDeactivate)throw new TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${p(e.canDeactivate)}`);if(void 0!==e.defaultParams){const r=e.defaultParams;if(null===r||"object"!=typeof r||Array.isArray(r))throw new TypeError(`[router.addRoute] defaultParams must be an object for route "${t}", got ${p(e.defaultParams)}`)}if("AsyncFunction"===e.decodeParams?.constructor.name)throw new TypeError(`[router.addRoute] decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if("AsyncFunction"===e.encodeParams?.constructor.name)throw new TypeError(`[router.addRoute] encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(e.children)for(const r of e.children)kt(r,`${t}.${r.name}`)}function jt(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 It(e){const t=new Set;for(const r of e)for(const e of jt(r))t.add(e);return t}function Dt(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 Dt(a.children,t,e,i)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function xt(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 xt(n.children,e))r.add(t)}return r}function Ft(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 Ft(n.children,e))r.set(t,a)}return r}function Mt(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}(yt(r,e)):It(Dt(n,e))}function Lt(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=It(Dt(r,e)),c=[...Mt(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 Ut(e,t,r){const n=xt(e),a=Ft(e),i={...t};for(const[e,t]of a)i[e]=t;for(const[t,i]of a)Lt(t,i,e,n,r);for(const e of Object.keys(i))_t(e,i)}function qt(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:bt(e.segments)}}var Wt=".";function zt(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function Bt(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 Vt(e){if(!e)return[""];const t=e.indexOf(Wt);if(-1===t)return[e];const r=e.indexOf(Wt,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(Wt,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(Wt,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(Wt),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 Ht(e,t){if(!t)return{intersection:"",toActivate:Vt(e.name),toDeactivate:[]};if((e.meta?.options??{}).reload)return{intersection:"",toActivate:Vt(e.name),toDeactivate:zt(Vt(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:Vt(e.name),toDeactivate:zt(Vt(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=Vt(e.name),i=Vt(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=Bt(a,e),c=Bt(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 Qt=class{#j=[];#I=function(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null)}}();#D=Object.create(null);#x=new Map;#F="";#M;#L;#b;#_;constructor(e=[]){for(const t of e)this.#j.push($t(t));this.#M=rt("",this.#F,this.#j),this.#U(e),this.#q()}static validateRemoveRouteArgs(e){!function(e){f(e,"removeRoute")}(e)}static validateSetRootPathArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${p(e)}`)}(e)}static validateAddRouteArgs(e){!function(e){for(const t of e){if(null===t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`[router.addRoute] Route must be an object, got ${p(t)}`);kt(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&&!c(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 validateForwardArgs(e,t){!function(e,t){if(!l(e)||""===e)throw new TypeError(`[router.forward] Invalid fromRoute: ${p(e)}. Expected non-empty string.`);if(!l(t)||""===t)throw new TypeError(`[router.forward] Invalid toRoute: ${p(t)}. Expected non-empty string.`)}(e,t)}static validateStateBuilderArgs(e,t,r){!function(e,t,r){if(!l(e))throw new TypeError(`[router.${r}] Invalid routeName: ${p(e)}. Expected string.`);if(!c(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${p(t)}. Expected plain object.`)}(e,t,r)}static validateUpdateRouteBasicArgs(e,t){!function(e,t){if(f(e,"updateRoute"),""===e)throw new ReferenceError("[router.updateRoute] Invalid name: empty string. Cannot update root node.");if(null===t)throw new TypeError("[real-router] updateRoute: updates must be an object, got null");if("object"!=typeof t||Array.isArray(t))throw new TypeError(`[real-router] updateRoute: updates must be an object, got ${p(t)}`)}(e,t)}static validateUpdateRoutePropertyTypes(e,t,r,n){!function(e,t,r,n){if(null!=e&&!l(e))throw new TypeError(`[real-router] updateRoute: forwardTo must be a string or null, got ${p(e)}`);if(null!=t&&("object"!=typeof t||Array.isArray(t)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${p(t)}`);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)}setRouter(e){this.#b=e;for(const[t,r]of this.#x)e.canActivate(t,r);this.#x.clear()}setLifecycleNamespace(e){this.#_=e}getRootPath(){return this.#F}setRootPath(e){this.#F=e,this.#W(!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=yt(this.#M,e);if(!t)return;const r=Tt(t.at(-1));return this.#z(r,e)}addRoutes(e){this.#B(e);for(const t of e)this.#j.push($t(t));this.#U(e),this.#W(!0),this.#q()}removeRoute(e){return!!Nt(this.#j,e)&&(this.#V(e),this.#W(!0),this.#q(),!0)}updateRouteConfig(e,t){if(void 0!==t.forwardTo&&(null===t.forwardTo?delete this.#I.forwardMap[e]:this.#I.forwardMap[e]=t.forwardTo,this.#q()),void 0!==t.defaultParams&&(null===t.defaultParams?delete this.#I.defaultParams[e]:this.#I.defaultParams[e]=t.defaultParams),void 0!==t.decodeParams)if(null===t.decodeParams)delete this.#I.decoders[e];else{const r=t.decodeParams;this.#I.decoders[e]=e=>r(e)??e}if(void 0!==t.encodeParams)if(null===t.encodeParams)delete this.#I.encoders[e];else{const r=t.encodeParams;this.#I.encoders[e]=e=>r(e)??e}}clearRoutes(){this.#j.length=0;for(const e in this.#I.decoders)delete this.#I.decoders[e];for(const e in this.#I.encoders)delete this.#I.encoders[e];for(const e in this.#I.defaultParams)delete this.#I.defaultParams[e];for(const e in this.#I.forwardMap)delete this.#I.forwardMap[e];for(const e in this.#D)delete this.#D[e];this.#W(!0)}buildPath(e,t,r){if(e===w.UNKNOWN_ROUTE)return l(t?.path)?t.path:"";const n=Object.hasOwn(this.#I.defaultParams,e)?{...this.#I.defaultParams[e],...t}:t??{},a="function"==typeof this.#I.encoders[e]?this.#I.encoders[e]({...n}):n,i=this.#L??x(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=yt(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=yt(e,t);if(!o)throw new Je(`[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??wt,nonSearchParams:r??wt}}(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 we(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{...x(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?gt: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?lt:ut:t?ct:st}(a,r):{caseSensitive:a,strictTrailingSlash:r,queryParams:i,urlParamsEncoding:o},partialTestOptions:s?function(e,t){return e?t?ht:pt:t?dt:ft}(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=vt(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&&nt.test(e.parser.path));return o&&i.push(o),{segments:i,params:a.params}}(this.#M,e,a);if(i){const r=qt(i),{name:a,params:o,meta:s}=r,c="function"==typeof this.#I.decoders[a]?this.#I.decoders[a](o):o,{name:u,params:l}=this.forwardState(a,c),d=n.rewritePathOnMatch?this.buildPath(u,l,n):e;return this.#b.makeState(u,l,d,{params:s,options:{},source:t,redirected:!1})}}forwardState(e,t){const r=this.#D[e]??e,n=Object.hasOwn(this.#I.defaultParams,e)?{...this.#I.defaultParams[e],...t}:{...t};return r!==e&&Object.hasOwn(this.#I.defaultParams,r)?{name:r,params:{...this.#I.defaultParams[r],...n}}:{name:r,params:n}}buildStateResolved(e,t){const r=yt(this.#M,e);if(r)return qt({segments:r,params:t},e)}buildStateWithSegmentsResolved(e,t){const r=yt(this.#M,e);if(r)return{state:qt({segments:r,params:t},e),segments:r}}initBuildOptionsCache(e){this.#L=x(e)}clearBuildOptionsCache(){this.#L=void 0}isActiveRoute(e,t={},r=!1,n=!0){Ot.has(e)||(f(e,"isActiveRoute"),Ot.add(e));const a=this.#b.getState();if(!a)return!1;const i=a.name;if(i!==e&&!i.startsWith(`${e}.`)&&!e.startsWith(`${i}.`))return!1;const o=this.#I.defaultParams[e];if(r||i===e){const r={name:e,params:o?{...o,...t}:t,path:""};return this.#b?.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}=Ht(t,r);return e===n||!!a.includes(e)||i.includes(e)}}getConfig(){return this.#I}getUrlParams(e){const t=yt(this.#M,e);return t?this.#H(t):[]}getResolvedForwardMap(){return this.#D}setResolvedForwardMap(e){Object.assign(this.#D,e)}cloneRoutes(){return this.#M.children.map(e=>Tt(e))}validateForwardToParamCompatibility(e,t,r="updateRoute"){const n=yt(this.#M,e),a=yt(this.#M,t),i=this.#Q(n),o=this.#H(a).filter(e=>!i.has(e));if(o.length>0)throw new Error(`[real-router] ${r}: ${"forward"===r?"target route":"forwardTo target"} "${t}" requires params [${o.join(", ")}] that are not available in source route "${e}"`)}validateForwardToCycle(e,t){_t(e,{...this.#I.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)}}forward(e,t){if(!this.hasRoute(e))throw new Error(`[real-router] forward: source route "${e}" does not exist`);if(!this.hasRoute(t))throw new Error(`[real-router] forward: target route "${t}" does not exist`);this.validateForwardToParamCompatibility(e,t,"forward"),this.validateForwardToCycle(e,t),this.#I.forwardMap[e]=t,this.#D[e]=_t(e,this.#I.forwardMap)}#W(e=!1){this.#M=rt("",this.#F,this.#j,{skipValidation:e})}#Q(e){const t=new Set;for(const r of e)for(const e of r.parser.urlParams)t.add(e);return t}#H(e){const t=[];for(const r of e)for(const e of r.parser.urlParams)t.push(e);return t}#q(){for(const e in this.#D)delete this.#D[e];for(const e of Object.keys(this.#I.forwardMap))this.#D[e]=_t(e,this.#I.forwardMap)}#V(e){const t=t=>t===e||t.startsWith(`${e}.`);if(Ct(this.#I.decoders,t),Ct(this.#I.encoders,t),Ct(this.#I.defaultParams,t),Ct(this.#I.forwardMap,t),Ct(this.#I.forwardMap,e=>t(this.#I.forwardMap[e])),this.#_){const[e,r]=this.#_.getFactories();for(const e of Object.keys(r))t(e)&&this.#_.clearCanActivate(e,!0);for(const r of Object.keys(e))t(r)&&this.#_.clearCanDeactivate(r,!0)}}#U(e,t=""){for(const r of e){const e=t?`${t}.${r.name}`:r.name;this.#Z(r,e),r.children&&this.#U(r.children,e)}}#Z(e,t){e.canActivate&&(this.#b?this.#b.canActivate(t,e.canActivate):this.#x.set(t,e.canActivate)),e.forwardTo&&this.#G(e,t),e.decodeParams&&(this.#I.decoders[t]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(this.#I.encoders[t]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(this.#I.defaultParams[t]=e.defaultParams)}#G(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.#I.forwardMap[r]=t.forwardTo}#z(e,t){const r={name:e.name,path:e.path},n=this.#I.forwardMap[t];if(n&&(r.forwardTo=n),t in this.#I.defaultParams&&(r.defaultParams=this.#I.defaultParams[t]),t in this.#I.decoders&&(r.decodeParams=this.#I.decoders[t]),t in this.#I.encoders&&(r.encodeParams=this.#I.encoders[t]),this.#_){const[,e]=this.#_.getFactories();t in e&&(r.canActivate=e[t])}return e.children&&(r.children=e.children.map(e=>this.#z(e,`${t}.${e.name}`))),r}#B(e){const t=new Set,r=new Map;for(const n of e)At(n,"addRoute",this.#M,"",t,r);Ut(e,this.#I.forwardMap,this.#M)}},Zt={log:0,warn:1,error:2},Gt={all:0,"warn-error":1,"error-only":2,none:3},Kt=new class{#I={level:"all",callbackIgnoresLevel:!1};#K=0;configure(e){if(void 0!==e.level){if(!(e.level in Gt))throw new Error(`Invalid log level: "${e.level}". Valid levels are: ${Object.keys(Gt).join(", ")}`);this.#I.level=e.level,this.#K=Gt[e.level]}"callback"in e&&(this.#I.callback=e.callback),void 0!==e.callbackIgnoresLevel&&(this.#I.callbackIgnoresLevel=e.callbackIgnoresLevel)}getConfig(){return{level:this.#I.level,callback:this.#I.callback,callbackIgnoresLevel:this.#I.callbackIgnoresLevel}}log(e,t,...r){this.#J("log",e,t,r)}warn(e,t,...r){this.#J("warn",e,t,r)}error(e,t,...r){this.#J("error",e,t,r)}#J(e,t,r,n){if("none"===this.#I.level&&!this.#I.callbackIgnoresLevel)return;const a=Zt[e]<this.#K;a||this.#Y(e,t,r,n),this.#X(e,t,r,a,n)}#Y(e,t,r,n){"undefined"!=typeof console&&"function"==typeof console[e]&&console[e](t?`[${t}] ${r}`:r,...n)}#X(e,t,r,n,a){if(this.#I.callback&&(this.#I.callbackIgnoresLevel||!n))try{this.#I.callback(e,t,r,...a)}catch(e){"undefined"!=typeof console&&"function"==typeof console.error&&console.error("[Logger] Error in callback:",e)}}},Jt=(e,t)=>{if(t)return t.setCode(e),t},Yt=(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}},Xt=(e,t,r)=>{const n=r?{segment:r}:{};var a;void 0!==e&&("boolean"!=typeof e?u(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 _(y.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 _(y.TRANSITION_ERR,r))}):t(new _(y.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})):e?t():t(new _(y.TRANSITION_ERR,n)))};function er(e,t,r,n){try{e(t,r)}catch(e){Kt.error(n,"Error in callback:",e)}}var tr=new Set(["code","segment","path","redirect"]);function rr(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))tr.has(r)||(t[r]=n);return{...r,...t}}return r}var nr="core:lifecycle",ar=(e,t,r,n,a,i,o)=>{let s=t;const c=n.filter(t=>e.has(t));if(0===c.length)return void er(o,void 0,s,nr);let l=0;const d=(e,t)=>{if(e)if(e.redirect){const t=new _(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 er(o,new _(y.TRANSITION_CANCELLED),s,nr);if(t)return void er(o,Jt(a,t),s,nr);if(n&&n!==s&&u(n)){if(n.name!==s.name){const e=new _(a,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:n.name,params:n.params,path:n.path}});return void er(o,e,s,nr)}(n.params!==s.params||n.path!==s.path)&&Kt.error("core:transition","Warning: State mutated during transition",{from:s,to:n}),s=Yt(n,s)}if(l>=c.length)return void er(o,void 0,s,nr);const h=c[l++],f=e.get(h);try{const e=f(s,r,d);Xt(e,d,h)}catch(e){d(new _(y.TRANSITION_ERR,rr(e,h)))}};h()},ir="core:middleware";function or(e,t,r,n,a){let i=!1,o=!1;const[s,c]=e.getLifecycleFunctions(),l=e.getMiddlewareFunctions(),d=t.name===w.UNKNOWN_ROUTE,h=()=>i||!e.isActive(),f=(e,r)=>{o||(o=!0,a(e,r??t))};return(()=>{const{toDeactivate:a,toActivate:i}=Ht(t,r),o=!d&&i.length>0,p=l.length>0,g=(n,a)=>{if(n)f(n,a);else{if(r){const n=Vt(t.name),a=Vt(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?c(e):c(void 0,t)},c=(t,c)=>{if(n())return void er(a,new _(y.TRANSITION_CANCELLED),i,ir);if(t)return void er(a,Jt(y.TRANSITION_ERR,t),i,ir);if(c&&c!==i&&u(c)&&((c.name!==i.name||c.params!==i.params||c.path!==i.path)&&Kt.error(ir,"Warning: State mutated during middleware execution",{from:i,to:c}),i=Yt(c,i)),o>=e.length)return void er(a,void 0,i,ir);const l=e[o++];try{const e=l(i,r,s);Xt(e,s)}catch(e){s(new _(y.TRANSITION_ERR,rr(e)))}};c()})(l,e,r,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,g)};var v;v=(e,t)=>{e?f(e,t):((e,t)=>{o?ar(c,e,r,i,y.CANNOT_ACTIVATE,h,(e,r)=>{t(e,r)}):t(void 0,e)})(t,m)},r&&!n.forceDeactivate&&a.length>0?ar(s,t,r,a,y.CANNOT_DEACTIVATE,h,v):v(void 0,t)})(),()=>{i||o||(i=!0,f(new _(y.TRANSITION_CANCELLED)))}}var sr=()=>{};function cr(t,...r){try{t(...r)}catch(t){e.logger.error("router.navigate","Error in navigation callback:",t)}}var ur=class{isRouterStarted;#ee=!1;#te=null;#b;static validateNavigateArgs(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${p(e)}`)}static validateNavigateToStateArgs(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 ${p(r)}`);if("function"!=typeof n)throw new TypeError(`[router.navigateToState] Invalid callback: expected function, got ${p(n)}`);if("boolean"!=typeof a)throw new TypeError(`[router.navigateToState] Invalid emitSuccess: expected boolean, got ${p(a)}`)}static validateNavigateToDefaultArgs(e,t){if(void 0!==e&&"function"!=typeof e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${p(e)}. Expected NavigationOptions object or callback function.`);if(void 0!==t&&"function"!=typeof t)throw new TypeError(`[router.navigateToDefault] Invalid callback: expected function, got ${p(t)}`)}setRouter(e){this.#b=e}isNavigating(){return this.isRouterStarted()&&this.#ee}cancel(){this.#te&&(this.#te(),this.#te=null),this.#ee=!1}navigateToState(t,r,n,a,i){const o=this.#b;return this.#ee&&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.#ee=!0,o.invokeEventListeners(A.TRANSITION_START,t,r),this.#te=or(o,t,r,n,(e,s)=>{if(this.#ee=!1,this.#te=null,e)e.code===y.TRANSITION_CANCELLED?o.invokeEventListeners(A.TRANSITION_CANCEL,t,r):o.invokeEventListeners(A.TRANSITION_ERROR,t,r,e),cr(a,e);else if(s.name===w.UNKNOWN_ROUTE||o.hasRoute(s.name))o.setState(s),i&&o.invokeEventListeners(A.TRANSITION_SUCCESS,s,r,n),cr(a,void 0,s);else{const e=new _(y.ROUTE_NOT_FOUND,{routeName:s.name});cr(a,e),o.invokeEventListeners(A.TRANSITION_ERROR,void 0,o.getState(),e)}}),this.#te}navigate(e,t,n,a){const i=this.#b,{params:o,opts:s,callback:c}=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??sr}}(t,n,a);if(!this.isRouterStarted())return cr(c,new _(y.ROUTER_NOT_STARTED)),sr;if(!r(s))throw new TypeError(`[router.navigate] Invalid options: ${p(s)}. Expected NavigationOptions object.`);const u=i.buildStateWithSegments(e,o);if(!u){const e=new _(y.ROUTE_NOT_FOUND);return cr(c,e),i.invokeEventListeners(A.TRANSITION_ERROR,void 0,i.getState(),e),sr}const{state:l}=u,d=i.makeState(l.name,l.params,i.buildPath(l.name,l.params),{params:l.meta,options:s,redirected:s.redirected??!1});if(s.skipTransition)return cr(c,void 0,d),sr;const h=i.getState();if(!s.reload&&!s.force&&i.areStatesEqual(h,d,!1)){const e=new _(y.SAME_STATES);return cr(c,e),i.invokeEventListeners(A.TRANSITION_ERROR,d,h,e),sr}return this.navigateToState(d,h,s,c,!0)}navigateToDefault(e,t){const n=this.#b.getOptions();if(!n.defaultRoute)return sr;let a={},i=sr;if("function"==typeof e?i=e:e&&(a=e,i=t??sr),!r(a))throw new TypeError(`[router.navigateToDefault] Invalid options: ${p(a)}. Expected NavigationOptions object.`);return this.navigate(n.defaultRoute,n.defaultParams,a,i)}},lr=()=>{},dr=new _(y.NO_START_PATH_OR_STATE),hr=new _(y.ROUTER_ALREADY_STARTED),fr=class{navigateToState;#re=!1;#ne=!1;#b;static validateStartArgs(e){if(e.length>2)throw new Error("[router.start] Invalid number of arguments. Expected 0-2 arguments.")}setRouter(e){this.#b=e}isStarted(){return this.#re}isActive(){return this.#ne}start(...t){const r=this.#b,n=r.getOptions(),[a,i]=(e=>{const[t,r]=e;return t?"function"==typeof t?[void 0,t]:[t,r??lr]:[void 0,lr]})(t);let o=!1;if(this.#re||this.#ne)return o=!0,void i(hr);if(!a&&!n.defaultRoute)return o=!0,r.hasListeners(A.TRANSITION_ERROR)&&r.invokeEventListeners(A.TRANSITION_ERROR,void 0,void 0,dr),void i(dr);this.#ne=!0;const s={replace:!0},c=(t,n,a=!1)=>{t?(this.#ne=!1,a&&r.hasListeners(A.TRANSITION_ERROR)&&r.invokeEventListeners(A.TRANSITION_ERROR,void 0,void 0,t)):(this.#re=!0,r.invokeEventListeners(A.ROUTER_START),r.invokeEventListeners(A.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)=>{c(e,t)},!1)},d=a??n.defaultRoute,h=((e,t)=>{if("string"==typeof e)return t.matchPath(e);if(u(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 c(new _(y.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):c(new _(y.ROUTE_NOT_FOUND,{path:f}),void 0,!0)}stop(){const e=this.#b;this.#ne=!1,this.#re&&(this.#re=!1,e.setState(),e.invokeEventListeners(A.ROUTER_STOP))}},pr=class{#ae;#ie;static validateCloneArgs(e){if(void 0!==e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.clone] Invalid dependencies: expected plain object or undefined, received ${p(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[router.clone] Getters not allowed in dependencies: "${t}"`)}}setCallbacks(e,t){this.#ae=e,this.#ie=t}clone(e,t){const r=this.#ae(),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.#ie(a,r.routeConfig,r.resolvedForwardMap),a}},gr=new Set(["all","warn-error","error-only"]);var mr=class t{#l;#e;#oe;#se;#ce;#ue;#le;#S;#de;#he;#fe;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)||!gr.has(r)))throw new TypeError(`Invalid logger level: ${function(e){return"string"==typeof e?`"${e}"`:"object"==typeof e?JSON.stringify(e):String(e)}(t.level)}. Expected: "all" | "warn-error" | "error-only"`);var r;if("callback"in t&&void 0!==t.callback&&"function"!=typeof t.callback)throw new TypeError("Logger callback must be a function, got "+typeof t.callback);return!0}(r.logger)&&(e.logger.configure(r.logger),delete r.logger),Z.validateOptions(r,"constructor"),v.validateDependenciesObject(n,"constructor"),this.#l=new Z(r),this.#e=new v(n),this.#oe=new q,this.#se=new K,this.#ce=new Qt(t),this.#ue=new ne,this.#le=new Y,this.#S=new re,this.#de=new ur,this.#he=new fr,this.#fe=new pr,this.#pe(),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.makeNotFoundState=this.makeNotFoundState.bind(this),this.getState=this.getState.bind(this),this.setState=this.setState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.areStatesDescendants=this.areStatesDescendants.bind(this),this.forwardState=this.forwardState.bind(this),this.buildState=this.buildState.bind(this),this.buildStateWithSegments=this.buildStateWithSegments.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.isStarted=this.isStarted.bind(this),this.isActive=this.isActive.bind(this),this.isNavigating=this.isNavigating.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.canDeactivate=this.canDeactivate.bind(this),this.clearCanDeactivate=this.clearCanDeactivate.bind(this),this.canActivate=this.canActivate.bind(this),this.clearCanActivate=this.clearCanActivate.bind(this),this.getLifecycleFactories=this.getLifecycleFactories.bind(this),this.getLifecycleFunctions=this.getLifecycleFunctions.bind(this),this.usePlugin=this.usePlugin.bind(this),this.getPlugins=this.getPlugins.bind(this),this.useMiddleware=this.useMiddleware.bind(this),this.clearMiddleware=this.clearMiddleware.bind(this),this.getMiddlewareFactories=this.getMiddlewareFactories.bind(this),this.getMiddlewareFunctions=this.getMiddlewareFunctions.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.invokeEventListeners=this.invokeEventListeners.bind(this),this.hasListeners=this.hasListeners.bind(this),this.removeEventListener=this.removeEventListener.bind(this),this.addEventListener=this.addEventListener.bind(this),this.forward=this.forward.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 Qt.validateAddRouteArgs(t),this.#ce.addRoutes(t),this}removeRoute(t){return Qt.validateRemoveRouteArgs(t),this.#ce.validateRemoveRoute(t,this.#se.get()?.name,this.#de.isNavigating())?(this.#ce.removeRoute(t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),this):this}clearRoutes(){return this.#ce.validateClearRoutes(this.#de.isNavigating())?(this.#ce.clearRoutes(),this.#ue.clearAll(),this.#se.set(void 0),this):this}getRoute(e){return f(e,"getRoute"),this.#ce.getRoute(e)}hasRoute(e){return f(e,"hasRoute"),this.#ce.hasRoute(e)}updateRoute(t,r){Qt.validateUpdateRouteBasicArgs(t,r);const{forwardTo:n,defaultParams:a,decodeParams:i,encodeParams:o,canActivate:s}=r;return Qt.validateUpdateRoutePropertyTypes(n,a,i,o),this.#de.isNavigating()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),this.#ce.validateUpdateRoute(t,n),this.#ce.updateRouteConfig(t,{forwardTo:n,defaultParams:a,decodeParams:i,encodeParams:o}),void 0!==s&&(null===s?this.#ue.clearCanActivate(t,!0):this.#ue.registerCanActivate(t,s)),this}isActiveRoute(t,r,n,a){return Qt.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.#ce.isActiveRoute(t,r,n,a)}buildPath(e,t){return Qt.validateBuildPathArgs(e),this.#ce.buildPath(e,t,this.#l.get())}matchPath(e,t){return Qt.validateMatchPathArgs(e),this.#ce.matchPath(e,t,this.#l.get())}setRootPath(e){Qt.validateSetRootPathArgs(e),this.#ce.setRootPath(e)}getRootPath(){return this.#ce.getRootPath()}makeState(e,t,r,n,a){return K.validateMakeStateArgs(e,t,r,a),this.#se.makeState(e,t,r,n,a)}makeNotFoundState(e,t){return K.validateMakeNotFoundStateArgs(e,t),this.#se.makeNotFoundState(e,t)}getState(){return this.#se.get()}setState(e){void 0!==e&&g(e,"router.setState"),this.#se.set(e)}getPreviousState(){return this.#se.getPrevious()}areStatesEqual(e,t,r=!0){return K.validateAreStatesEqualArgs(e,t,r),this.#se.areStatesEqual(e,t,r)}areStatesDescendants(e,t){return K.validateAreStatesDescendantsArgs(e,t),this.#se.areStatesDescendants(e,t)}forwardState(e,t){return Qt.validateStateBuilderArgs(e,t,"forwardState"),this.#ce.forwardState(e,t)}buildState(e,t){Qt.validateStateBuilderArgs(e,t,"buildState");const{name:r,params:n}=this.forwardState(e,t);return this.#ce.buildStateResolved(r,n)}buildStateWithSegments(e,t){Qt.validateStateBuilderArgs(e,t,"buildStateWithSegments");const{name:r,params:n}=this.forwardState(e,t);return this.#ce.buildStateWithSegmentsResolved(r,n)}shouldUpdateNode(e){return Qt.validateShouldUpdateNodeArgs(e),this.#ce.shouldUpdateNode(e)}getOptions(){return this.#l.get()}getOption(e){return Z.validateOptionName(e,"getOption"),this.#l.getOption(e)}setOption(e,t){return Z.validateOptionName(e,"setOption"),Z.validateOptionValue(e,t,"setOption"),this.#l.set(e,t),this}isStarted(){return this.#he.isStarted()}isActive(){return this.#he.isActive()}isNavigating(){return this.#de.isNavigating()}start(...e){return fr.validateStartArgs(e),this.#l.lock(),this.#ce.initBuildOptionsCache(this.#l.get()),this.#he.start(...e),this}stop(){return this.#he.stop(),this.#ce.clearBuildOptionsCache(),this.#l.unlock(),this}canDeactivate(e,t){return f(e,"canDeactivate"),ne.validateHandler(t,"canDeactivate"),this.#ue.registerCanDeactivate(e,t),this}clearCanDeactivate(e,t){return f(e,"clearCanDeactivate"),this.#ue.clearCanDeactivate(e,t),this}canActivate(e,t){return f(e,"canActivate"),ne.validateHandler(t,"canActivate"),this.#ue.registerCanActivate(e,t),this}clearCanActivate(e,t){return f(e,"clearCanActivate"),this.#ue.clearCanActivate(e,t),this}getLifecycleFactories(){return this.#ue.getFactories()}getLifecycleFunctions(){return this.#ue.getFunctions()}usePlugin(...e){return re.validateUsePluginArgs(e),this.#S.use(...e)}getPlugins(){return this.#S.getAll()}useMiddleware(...e){return Y.validateUseMiddlewareArgs(e),this.#le.use(...e)}clearMiddleware(){return this.#le.clear(),this}getMiddlewareFactories(){return this.#le.getFactories()}getMiddlewareFunctions(){return this.#le.getFunctions()}setDependency(e,t){return v.validateSetDependencyArgs(e),this.#e.set(e,t),this}setDependencies(e){return v.validateDependenciesObject(e,"setDependencies"),this.#e.setMultiple(e),this}getDependency(e){return v.validateName(e,"getDependency"),this.#e.get(e)}getDependencies(){return this.#e.getAll()}removeDependency(e){return v.validateName(e,"removeDependency"),this.#e.remove(e),this}hasDependency(e){return v.validateName(e,"hasDependency"),this.#e.has(e)}resetDependencies(){return this.#e.reset(),this}invokeEventListeners(e,t,r,n){q.validateInvokeArgs(e,t,r,n),this.#oe.invoke(e,t,r,n)}hasListeners(e){return this.#oe.hasListeners(e)}removeEventListener(e,t){q.validateListenerArgs(e,t),this.#oe.removeEventListener(e,t)}addEventListener(e,t){return q.validateListenerArgs(e,t),this.#oe.addEventListener(e,t)}forward(e,t){return Qt.validateForwardArgs(e,t),this.#ce.forward(e,t),this}navigate(e,t,r,n){return ur.validateNavigateArgs(e),this.#de.navigate(e,t,r,n)}navigateToDefault(e,t){return ur.validateNavigateToDefaultArgs(e,t),this.#de.navigateToDefault(e,t)}navigateToState(e,t,r,n,a){return ur.validateNavigateToStateArgs(e,t,r,n,a),this.#de.navigateToState(e,t,r,n,a)}subscribe(e){return q.validateSubscribeListener(e),this.#oe.subscribe(e)}[Symbol.observable](){return this.#oe.observable()}"@@observable"(){return this.#oe.observable()}clone(e){return pr.validateCloneArgs(e),this.#fe.clone(e,(e,r,n)=>new t(e,r,n))}#pe(){this.#ue.setRouter(this),this.#ce.setRouter(this),this.#ce.setLifecycleNamespace(this.#ue),this.#le.setRouter(this),this.#S.setRouter(this),this.#de.setRouter(this),this.#he.setRouter(this),this.#oe.setGetState(()=>this.getState()),this.#se.setDependencies({getDefaultParams:()=>this.#ce.getConfig().defaultParams,buildPath:(e,t)=>this.#ce.buildPath(e,t,this.#l.get()),getUrlParams:e=>this.#ce.getUrlParams(e)}),this.#de.isRouterStarted=()=>this.#he.isStarted(),this.#he.navigateToState=(e,t,r,n,a)=>this.navigateToState(e,t,r,n,a),this.#fe.setCallbacks(()=>{const[e,t]=this.#ue.getFactories();return{routes:this.#ce.cloneRoutes(),options:{...this.#l.get()},dependencies:this.#e.getAll(),canDeactivateFactories:e,canActivateFactories:t,middlewareFactories:this.#le.getFactories(),pluginFactories:this.#S.getAll(),routeConfig:this.#ce.getConfig(),resolvedForwardMap:this.#ce.getResolvedForwardMap()}},(e,t,r)=>{const n=e,a=n.#ce.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.#ce.setResolvedForwardMap({...r})})}};exports.Router=mr,exports.RouterError=_,exports.constants=w,exports.createRouter=(e=[],t={},r={})=>new mr(e,t,r),exports.errorCodes=y,exports.events=A;//# 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 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