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