@real-router/core 0.35.0 → 0.35.1

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.
@@ -1 +1 @@
1
- import{logger as e}from"@real-router/logger";import{FSM as t}from"@real-router/fsm";var r={maxListeners:0,warnListeners:0,maxEventDepth:0},n=class extends Error{},o=class{#e=new Map;#t=null;#r=r;#n;#o;constructor(e){e?.limits&&(this.#r=e.limits),this.#n=e?.onListenerError??null,this.#o=e?.onListenerWarn??null}static validateCallback(e,t){if("function"!=typeof e)throw new TypeError(`Expected callback to be a function for event ${t}`)}setLimits(e){this.#r=e}on(e,t){const r=this.#i(e);if(r.has(t))throw new Error(`Duplicate listener for "${e}"`);const{maxListeners:n,warnListeners:o}=this.#r;if(0!==o&&r.size===o&&this.#o?.(e,o),0!==n&&r.size>=n)throw new Error(`Listener limit (${n}) reached for "${e}"`);return r.add(t),()=>{this.off(e,t)}}off(e,t){this.#e.get(e)?.delete(t)}emit(e,...t){const r=this.#e.get(e);r&&0!==r.size&&(0!==this.#r.maxEventDepth?this.#a(r,e,t):this.#s(r,e,t))}clearAll(){this.#e.clear(),this.#t=null}listenerCount(e){return this.#e.get(e)?.size??0}#s(e,t,r){const n=[...e];for(const e of n)try{this.#c(e,r)}catch(e){this.#n?.(t,e)}}#c(e,t){switch(t.length){case 0:e();break;case 1:e(t[0]);break;case 2:e(t[0],t[1]);break;case 3:e(t[0],t[1],t[2]);break;default:Function.prototype.apply.call(e,void 0,t)}}#a(e,t,r){this.#t??=new Map;const o=this.#t,i=o.get(t)??0;if(i>=this.#r.maxEventDepth)throw new n(`Maximum recursion depth (${this.#r.maxEventDepth}) exceeded for event: ${t}`);try{o.set(t,i+1);const a=[...e];for(const e of a)try{this.#c(e,r)}catch(e){if(e instanceof n)throw e;this.#n?.(t,e)}}finally{o.set(t,o.get(t)-1)}}#i(e){const t=this.#e.get(e);if(t)return t;const r=new Set;return this.#e.set(e,r),r}},i=["replace","reload","force","forceDeactivate","redirected"],a=/\S/,s=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function c(e,t){return new TypeError(`[router.${e}] ${t}`)}function u(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=>u(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=>u(e,t))}return!1}function d(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function l(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(!d(n)){const e=typeof n;if("function"===e||"symbol"===e)return!1;r=!0;break}}return!r||u(e)}function f(e){return"string"==typeof e}function h(e){return"boolean"==typeof e}function p(e,t){return e in t}function m(e,t){if("string"!=typeof e)throw c(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!a.test(e))throw c(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw c(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!s.test(e))throw c(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 g(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 v(e,t){if(!function(e){return"object"==typeof e&&null!==e&&function(e){return function(e){return"string"==typeof e&&(""===e||!(e.length>1e4)&&(!!e.startsWith("@@")||s.test(e)))}(e.name)&&"string"==typeof e.path&&l(e.params)}(e)}(e))throw new TypeError(`[${t}] Invalid state structure: ${g(e)}. Expected State object with name, params, and path properties.`)}var w=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",ROUTER_DISPOSED:"DISPOSED",PLUGIN_CONFLICT:"PLUGIN_CONFLICT"}),y="@@router/UNKNOWN_ROUTE",T={UNKNOWN_ROUTE:y},S="onStart",b="onStop",E="onTransitionStart",O="onTransitionCancel",A="onTransitionSuccess",P="onTransitionError",R={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},$=new Set([R.ROUTER_START,R.TRANSITION_START,R.TRANSITION_SUCCESS,R.TRANSITION_ERROR,R.TRANSITION_CANCEL,R.ROUTER_STOP]),N={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},D={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxListeners:{min:0,max:1e5},warnListeners:{min:0,max:1e5},maxEventDepth:{min:0,max:100},maxLifecycleHandlers:{min:0,max:1e4}},C="IDLE",j="STARTING",F="READY",x="TRANSITIONING",I="DISPOSED",L="START",M="STARTED",_="NAVIGATE",k="COMPLETE",U="FAIL",B="CANCEL",G="STOP",V="DISPOSE",z={initial:C,context:null,transitions:{[C]:{[L]:j,[V]:I},[j]:{[M]:F,[U]:C},[F]:{[_]:x,[U]:F,[G]:C},[x]:{[_]:x,[k]:F,[B]:F,[U]:F},[I]:{}}},q=new WeakSet;function W(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)W(t);else for(const t in e)W(e[t])}function Q(e){return e?(q.has(e)||(W(e),q.add(e)),e):e}function H(e){return{warn:Math.floor(.2*e),error:Math.floor(.5*e)}}var K=new WeakMap;function J(e){const t=K.get(e);if(!t)throw new TypeError("[real-router] Invalid router instance — not found in internals registry");return t}function Y(e,t,r){return(...n)=>{const o=r.get(e);return o&&0!==o.length?function(e,t,r){let n=t;for(const t of e){const e=n;n=(...r)=>t(e,...r)}return n(...r)}(o,t,n):t(...n)}}var Z={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},X={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},ee={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function te(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&te(r)}return e}function re(e,t){return"function"==typeof e?e(t):e}function ne(e,t,r){if("function"==typeof t&&("defaultRoute"===e||"defaultParams"===e))return;const n=Z[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 ${g(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(!p(r,ee)){const e=Object.keys(ee).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],o=ee[r];if(!o.includes(n)){const e=o.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 X&&function(e,t,r){const n=X[e];if(!n.includes(t)){const o=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${o}, got "${String(t)}"`)}}(e,t,r)}function oe(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(D,r))throw new TypeError(`[router.${t}]: unknown limit: "${r}"`);void 0!==n&&ie(r,n,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function ie(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=D[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 ae=class{#u;constructor(e={}){this.#u=te({...Z,...e})}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 ${g(e)}`);for(const[r,n]of Object.entries(e))p(r,Z)?void 0!==n&&ne(r,n,t):oe(r,n,t)}(e,t)}get(){return this.#u}};function se(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>se(e,t[r]))}var ce=class{#d=0;#l=void 0;#f=void 0;#h;#p=new Map;static validateAreStatesEqualArgs(e,t,r){if(null!=e&&v(e,"areStatesEqual"),null!=t&&v(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${g(r)}. Expected boolean.`)}get(){return this.#l}set(e){this.#f=this.#l,this.#l=e?Q(e):void 0}getPrevious(){return this.#f}reset(){this.#l=void 0,this.#f=void 0,this.#p.clear(),this.#d=0}setDependencies(e){this.#h=e}makeState(e,t,r,n,o){const i=n?{...n,id:o??++this.#d,params:n.params}:void 0,a=this.#h.getDefaultParams();let s;return s=Object.hasOwn(a,e)?{...a[e],...t}:t?{...t}:{},Q({name:e,params:s,path:r??this.#h.buildPath(e,t),meta:i})}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=>se(e.params[r],t.params[r]))}const n=Object.keys(e.params),o=Object.keys(t.params);return n.length===o.length&&n.every(r=>r in t.params&&se(e.params[r],t.params[r]))}#m(e){const t=this.#p.get(e);if(void 0!==t)return t;const r=this.#h.getUrlParams(e);return this.#p.set(e,r),r}},ue={[S]:R.ROUTER_START,[b]:R.ROUTER_STOP,[A]:R.TRANSITION_SUCCESS,[E]:R.TRANSITION_START,[P]:R.TRANSITION_ERROR,[O]:R.TRANSITION_CANCEL},de=Object.keys(ue).filter(e=>p(e,ue)),le="router.usePlugin",fe=class t{#g=new Set;#v=new Set;#w;#h;#y=N;static validateUsePluginArgs(e){!function(e){for(const[t,r]of e.entries())if("function"!=typeof r)throw new TypeError(`[router.usePlugin] Expected plugin factory function at index ${t}, got ${g(r)}`)}(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 ${g(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&&!p(t,ue))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=N.maxPlugins){if(0!==r&&e+t>r)throw new Error(`[router.usePlugin] Plugin limit exceeded (${r}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`)}(e,t,r)}static validateNoDuplicatePlugins(e,t){for(const r of e)if(t(r))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setRouter(e){this.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#y=e}count(){return this.#g.size}use(...t){if(this.#T(t.length),1===t.length){const r=t[0],n=this.#S(r);this.#g.add(r);let o=!1;const i=()=>{if(!o){o=!0,this.#g.delete(r),this.#v.delete(i);try{n()}catch(t){e.error(le,"Error during cleanup:",t)}}};return this.#v.add(i),i}const r=this.#b(t),n=[];try{for(const e of r){const t=this.#S(e);n.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){e.error(le,"Cleanup error:",t)}throw t}for(const{factory:e}of n)this.#g.add(e);let o=!1;const i=()=>{if(!o){o=!0,this.#v.delete(i);for(const{factory:e}of n)this.#g.delete(e);for(const{cleanup:t}of n)try{t()}catch(t){e.error(le,"Error during cleanup:",t)}}};return this.#v.add(i),i}getAll(){return[...this.#g]}has(e){return this.#g.has(e)}disposeAll(){for(const e of this.#v)e();this.#g.clear(),this.#v.clear()}#T(t){const r=this.#y.maxPlugins;if(0===r)return;const n=t+this.#g.size,{warn:o,error:i}=H(r);n>=i?e.error(le,`${n} plugins registered! This is excessive and will impact performance. Hard limit at ${r}.`):n>=o&&e.warn(le,`${n} plugins registered. Consider if all are necessary.`)}#b(t){const r=new Set;for(const n of t)r.has(n)?e.warn(le,"Duplicate factory in batch, will be registered once"):r.add(n);return r}#S(r){const n=r(this.#w,this.#h.getDependency);t.validatePlugin(n),Object.freeze(n);const o=[];for(const t of de)t in n&&("function"==typeof n[t]?(o.push(this.#h.addEventListener(ue[t],n[t])),"onStart"===t&&this.#h.canNavigate()&&e.warn(le,"Router already started, onStart will not be called")):e.warn(le,`Property '${t}' is not a function, skipping`));return()=>{for(const e of o)e();"function"==typeof n.teardown&&n.teardown()}}};function he(e,t){if(!h(e)&&"function"!=typeof e)throw new TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${g(e)}`)}function pe(e,t,r){if(e)throw new Error(`[router.${r}] Cannot modify route "${t}" during its own registration`)}function me(e,t,r=N.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 plugins for cross-cutting concerns.`)}var ge=class{#E=new Map;#O=new Map;#A=new Map;#P=new Map;#R=new Set;#$=new Set;#N=new Set;#w;#h;#y=N;setRouter(e){this.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#y=e}addCanActivate(e,t,r,n=!1){n?this.#$.add(e):this.#$.delete(e),r||pe(this.#R.has(e),e,"addActivateGuard");const o=this.#O.has(e);o||r||me(this.#O.size+1,"addActivateGuard",this.#y.maxLifecycleHandlers),this.#D("activate",e,t,this.#O,this.#P,"canActivate",o)}addCanDeactivate(e,t,r,n=!1){n?this.#N.add(e):this.#N.delete(e),r||pe(this.#R.has(e),e,"addDeactivateGuard");const o=this.#E.has(e);o||r||me(this.#E.size+1,"addDeactivateGuard",this.#y.maxLifecycleHandlers),this.#D("deactivate",e,t,this.#E,this.#A,"canDeactivate",o)}clearCanActivate(e){this.#O.delete(e),this.#P.delete(e),this.#$.delete(e)}clearCanDeactivate(e){this.#E.delete(e),this.#A.delete(e),this.#N.delete(e)}clearAll(){this.#O.clear(),this.#P.clear(),this.#E.clear(),this.#A.clear(),this.#$.clear(),this.#N.clear()}clearDefinitionGuards(){for(const e of this.#$)this.#O.delete(e),this.#P.delete(e);for(const e of this.#N)this.#E.delete(e),this.#A.delete(e);this.#$.clear(),this.#N.clear()}getFactories(){const e={},t={};for(const[t,r]of this.#E)e[t]=r;for(const[e,r]of this.#O)t[e]=r;return[e,t]}getFunctions(){return[this.#A,this.#P]}checkActivateGuardSync(e,t,r){return this.#C(this.#P,e,t,r,"checkActivateGuardSync")}checkDeactivateGuardSync(e,t,r){return this.#C(this.#A,e,t,r,"checkDeactivateGuardSync")}#D(t,r,n,o,i,a,s){s?e.warn(`router.${a}`,`Overwriting existing ${t} handler for route "${r}"`):this.#T(o.size+1,a);const c=h(n)?function(e){const t=()=>e;return()=>t}(n):n;o.set(r,c),this.#R.add(r);try{const e=c(this.#w,this.#h.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${a}] Factory must return a function, got ${g(e)}`);i.set(r,e)}catch(e){throw o.delete(r),e}finally{this.#R.delete(r)}}#C(t,r,n,o,i){const a=t.get(r);if(!a)return!0;try{const t=a(n,o);return"boolean"==typeof t?t:(e.warn(`router.${i}`,`Guard for "${r}" returned a Promise. Sync check cannot resolve async guards — returning false.`),!1)}catch{return!1}}#T(t,r){const n=this.#y.maxLifecycleHandlers;if(0===n)return;const{warn:o,error:i}=H(n);t>=i?e.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at ${n}.`):t>=o&&e.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}},ve=new Set;function we(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function ye(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>ye(e))),t}function Te(e,t,r=""){for(let n=0;n<e.length;n++){const o=e[n],i=r?`${r}.${o.name}`:o.name;if(i===t)return e.splice(n,1),!0;if(o.children&&t.startsWith(`${i}.`)&&Te(o.children,t,i))return!0}return!1}function Se(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function be(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var Ee=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,Oe=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,Ae=/\?(.+)$/,Pe=/[^\w!$'()*+,.:;|~-]/gu,Re=/[^\w!$'()*+,.:;|~-]/u,$e={default:e=>Re.test(e)?e.replaceAll(Pe,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},Ne={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function De(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function Ce(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function je(e){const t={};if(0===e.length)return t;const r=e.split("&");for(const e of r){const r=e.indexOf("=");-1===r?t[e]="":t[e.slice(0,r)]=e.slice(r+1)}return t}function Fe(e){const t=[];for(const r of Object.keys(e)){const n=e[r],o=encodeURIComponent(r);t.push(""===n?o:`${o}=${encodeURIComponent(String(n))}`)}return t.join("&")}function xe(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function Ie(e){let t=0;for(;t<e.length;)if("%"===e[t]){if(t+2>=e.length)return!1;const r=e.codePointAt(t+1)??0,n=e.codePointAt(t+2)??0;if(!xe(r)||!xe(n))return!1;t+=3}else t++;return!0}var Le=/<[^>]*>/g;function Me(e,t,r,n,o){const i=""===t.fullName;i||n.push(t);const a=t.absolute,s=t.paramMeta.pathPattern,c=a&&s.startsWith("~")?s.slice(1):s,u=(a?c:s).replaceAll(Le,""),d=a?u:(f=u,""===(l=r)?f:""===f?l:l+f);var l,f;let h=o;i||(h=function(e,t,r,n,o,i){const a=(g=n,Ce(r)===Ce(g)),s=Object.freeze([...o]),c=function(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return Object.freeze(t)}(s),u=Ce(r),d=function(e,t){const r=[];e.length>0&&r.push(...e);for(const e of t)e.paramMeta.queryParams.length>0&&r.push(...e.paramMeta.queryParams);return r}(e.rootQueryParams,o),l=function(e){const t=new Map;for(const r of e)for(const[e,n]of r.paramMeta.constraintPatterns)t.set(e,n);return t}(o),f=a?Ce(n):u,{buildStaticParts:h,buildParamSlots:p}=function(e,t,r){const n=new Set,o=new Set;for(const e of t){for(const t of e.paramMeta.urlParams)n.add(t);for(const t of e.paramMeta.spatParams)o.add(t)}if(0===n.size)return{buildStaticParts:[e],buildParamSlots:[]};const i=[],a=[],s=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,u=0;for(;null!==(c=s.exec(e));){const t=c[1],n="?"===c[2];i.push(e.slice(u,c.index));const s=o.has(t);a.push({paramName:t,isOptional:n,encoder:s?e=>{const t=$e[r],n=e.split("/");let o=t(n[0]);for(let e=1;e<n.length;e++)o+=`/${t(n[e])}`;return o}:$e[r]}),u=c.index+c[0].length}return i.push(e.slice(u)),{buildStaticParts:i,buildParamSlots:a}}(f,a?o.slice(0,-1):o,e.options.urlParamsEncoding),m={name:t.fullName,parent:i,depth:o.length-1,matchSegments:s,meta:c,declaredQueryParams:d,declaredQueryParamsSet:new Set(d),hasTrailingSlash:r.length>1&&r.endsWith("/"),constraintPatterns:l,hasConstraints:l.size>0,buildStaticParts:h,buildParamSlots:p,buildParamNamesSet:new Set(p.map(e=>e.paramName))};var g;return e.routesByName.set(t.fullName,m),e.segmentsByName.set(t.fullName,s),e.metaByName.set(t.fullName,c),a?function(e,t,r){var n,o;n=t,(function(e,t,r){const n=Ce(r);if("/"===n||""===n)return t;let o=t,i=1;const a=n.length;for(;i<=a;){const t=n.indexOf("/",i),r=-1===t?a:t;if(r<=i)break;o=ke(e,o,n.slice(i,r)),i=r+1}return o}(o=e,o.root,r)).slashChildRoute=n;const i=Ce(r),a=e.options.caseSensitive?i:i.toLowerCase();e.staticCache.has(a)&&e.staticCache.set(a,t)}(e,m,n):function(e,t,r,n,o){if(function(e,t,r){const n=Ce(r);"/"!==n?_e(e,e.root,n,1,t):e.root.route=t}(e,t,r),0===o.paramMeta.urlParams.length){const r=e.options.caseSensitive?n:n.toLowerCase();e.staticCache.set(r,t)}}(e,m,r,u,t),m}(e,t,d,a?"":r,n,o));for(const r of t.children.values())Me(e,r,d,n,h);i||n.pop()}function _e(e,t,r,n,o){const i=r.length;for(;n<=i;){const a=r.indexOf("/",n),s=-1===a?i:a,c=r.slice(n,s);if(c.endsWith("?")){const n=c.slice(1).replaceAll(Le,"").replace(/\?$/,"");return t.paramChild??={node:De(),name:n},_e(e,t.paramChild.node,r,s+1,o),void(s>=i?t.route??=o:_e(e,t,r,s+1,o))}t=ke(e,t,c),n=s+1}t.route=o}function ke(e,t,r){if(r.startsWith("*")){const e=r.slice(1);return t.splatChild??={node:De(),name:e},t.splatChild.node}if(r.startsWith(":")){const e=r.slice(1).replaceAll(Le,"").replace(/\?$/,"");return t.paramChild??={node:De(),name:e},t.paramChild.node}const n=e.options.caseSensitive?r:r.toLowerCase();return n in t.staticChildren||(t.staticChildren[n]=De()),t.staticChildren[n]}var Ue=/[\u0080-\uFFFF]/,Be=class{get options(){return this.#e}#e;#t=De();#o=new Map;#i=new Map;#r=new Map;#a=new Map;#n="";#j=[];constructor(e){this.#e={caseSensitive:e?.caseSensitive??!0,strictTrailingSlash:e?.strictTrailingSlash??!1,strictQueryParams:e?.strictQueryParams??!1,urlParamsEncoding:e?.urlParamsEncoding??"default",parseQueryString:e?.parseQueryString??je,buildQueryString:e?.buildQueryString??Fe}}registerTree(e){this.#j=e.paramMeta.queryParams,Me({root:this.#t,options:this.#e,routesByName:this.#o,segmentsByName:this.#i,metaByName:this.#r,staticCache:this.#a,rootQueryParams:this.#j},e,"",[],null)}match(e){const t=this.#s(e);if(!t)return;const[r,n,o]=t,i=this.#e.caseSensitive?n:n.toLowerCase(),a=this.#a.get(i);if(a){if(this.#e.strictTrailingSlash&&!this.#c(r,a))return;return this.#F(a,{},o)}const s={},c=this.#x(n,s);return!c||this.#e.strictTrailingSlash&&!this.#c(r,c)||c.hasConstraints&&!this.#I(s,c)||!this.#L(s)?void 0:this.#F(c,s,o)}buildPath(e,t,r){const n=this.#o.get(e);if(!n)throw new Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);n.hasConstraints&&t&&this.#M(n,e,t);const o=this.#_(n,t),i=this.#k(o,r?.trailingSlash),a=this.#U(n,t,r?.queryParamsMode);return i+(a?`?${a}`:"")}getSegmentsByName(e){return this.#i.get(e)}getMetaByName(e){return this.#r.get(e)}hasRoute(e){return this.#o.has(e)}setRootPath(e){this.#n=e}#M(e,t,r){for(const[n,o]of e.constraintPatterns){const e=r[n];if(null!=e){const r="object"==typeof e?JSON.stringify(e):String(e);if(!o.pattern.test(r))throw new Error(`[SegmentMatcher.buildPath] '${t}' — param '${n}' value '${r}' does not match constraint '${o.constraint}'`)}}}#_(e,t){const r=e.buildStaticParts,n=e.buildParamSlots;if(0===n.length)return this.#n+r[0];let o=this.#n+r[0];for(const[e,i]of n.entries()){const n=t?.[i.paramName];if(null==n){if(!i.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${i.paramName}'`);o.length>1&&o.endsWith("/")&&(o=o.slice(0,-1)),o+=r[e+1];continue}const a="object"==typeof n?JSON.stringify(n):String(n);o+=i.encoder(a)+r[e+1]}return o}#k(e,t){return"always"!==t||e.endsWith("/")?"never"===t&&"/"!==e&&e.endsWith("/")?e.slice(0,-1):e:`${e}/`}#U(e,t,r){if(!t)return"";const n={};let o=!1;for(const r of e.declaredQueryParams)r in t&&(n[r]=t[r],o=!0);if("loose"===r)for(const r in t)!Object.hasOwn(t,r)||e.declaredQueryParamsSet.has(r)||e.buildParamNamesSet.has(r)||(n[r]=t[r],o=!0);return o?this.#e.buildQueryString(n):""}#s(e){if(""===e&&(e="/"),!e.startsWith("/"))return;const t=e.indexOf("#");if(-1!==t&&(e=e.slice(0,t)),Ue.test(e))return;if(this.#n.length>0){if(!e.startsWith(this.#n))return;e=e.slice(this.#n.length)||"/"}const r=e.indexOf("?"),n=-1===r?e:e.slice(0,r),o=-1===r?void 0:e.slice(r+1);return n.includes("//")?void 0:[n,Ce(n),o]}#F(e,t,r){if(void 0!==r){const n=this.#e.parseQueryString(r);if(this.#e.strictQueryParams){const t=e.declaredQueryParamsSet;for(const e of Object.keys(n))if(!t.has(e))return}for(const e of Object.keys(n))t[e]=n[e]}return{segments:e.matchSegments,params:t,meta:e.meta}}#c(e,t){return(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#x(e,t){return 1===e.length?this.#t.slashChildRoute??this.#t.route:this.#B(this.#t,e,1,t)}#B(e,t,r,n){let o=e;const i=t.length;for(;r<=i;){const e=t.indexOf("/",r),a=-1===e?i:e,s=t.slice(r,a),c=this.#e.caseSensitive?s:s.toLowerCase();let u;if(c in o.staticChildren)u=o.staticChildren[c];else{if(!o.paramChild){if(o.splatChild){const e={},i=this.#B(o.splatChild.node,t,r,e);return i?(Object.assign(n,e),i):(n[o.splatChild.name]=t.slice(r),o.splatChild.node.route)}return}u=o.paramChild.node,n[o.paramChild.name]=s}o=u,r=a+1}return o.slashChildRoute??o.route}#L(e){const t=this.#e.urlParamsEncoding;if("none"===t)return!0;const r=Ne[t];for(const t in e){const n=e[t];if(n.includes("%")){if(!Ie(n))return!1;e[t]=r(n)}}return!0}#I(e,t){for(const[r,n]of t.constraintPatterns)if(!n.pattern.test(e[r]))return!1;return!0}},Ge=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)},Ve=e=>{const t=typeof e;if("string"!==t&&"number"!==t&&"boolean"!==t)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===t&&null===e?"null":t}`);return encodeURIComponent(e)},ze={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${Ve(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${Ve(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${Ve(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>Ve(e)).join(",")}`}},qe={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}},We={default:{encode:e=>e},hidden:{encode:()=>""}},Qe=(e,t,r)=>({boolean:qe[t],null:We[r],array:ze[e]}),He={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:qe.none,null:We.default,array:ze.none}},Ke=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return He;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:Qe(t,r,n)}},Je=e=>encodeURIComponent(e),Ye=(e,t,r)=>{const n=Je(e);switch(typeof t){case"string":case"number":default:return`${n}=${Je(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}=${Je(t)}`}};function Ze(e,t,r,n,o){const i=e.indexOf("=",t),a=-1!==i&&i<r,s=e.slice(t,a?i:r),{name:c,hasBrackets:u}=function(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}(s);var d,l,f,h,p;!function(e,t,r,n){const o=e[t];void 0===o?e[t]=n?[r]:r:Array.isArray(o)?o.push(r):e[t]=[o,r]}(n,Ge(c),(d=e,l=i,f=r,h=a,p=o,p?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const n=Ge(e);return t.boolean.decodeValue(n)})(h?d.slice(l+1,f):void 0,p):h?Ge(d.slice(l+1,f)):null),u)}function Xe(e,t){const r=e.path,n=r.startsWith("~"),o=n?r.slice(1):r,i={name:e.name,path:o,absolute:n,children:[],parent:t,nonAbsoluteChildren:[],fullName:""};if(e.children)for(const t of e.children){const e=Xe(t,i);i.children.push(e)}return i}function et(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function tt(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}function rt(e,t,r){const n=function(e){const t=[],r=[],n=[],o={},i=new Map,a=e.replaceAll(Oe,"$1"),s=Ae.exec(a);if(null!==s){const t=s[1].split("&");for(const e of t){const t=e.trim();t.length>0&&(r.push(t),o[t]="query")}e=e.slice(0,s.index)}let c;for(;null!==(c=Ee.exec(e));){const e=c[2],r=c[3];if("*"===c[1])n.push(e),t.push(e),o[e]="url";else if(t.push(e),o[e]="url",r){const t=`^${be(r)}$`;i.set(e,{pattern:new RegExp(t),constraint:r})}}return{urlParams:t,queryParams:r,spatParams:n,paramTypeMap:o,constraintPatterns:i,pathPattern:e}}(e.path),o=function(e){const t={};for(const r of e.urlParams)t[r]="url";for(const r of e.queryParams)t[r]="query";return t}(n),i={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:void 0,paramMeta:n,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:o};var a;i.fullName=(a=i,a.parent?.name?`${a.parent.fullName}.${a.name}`:a.name);const{childrenMap:s,nonAbsoluteChildren:c}=function(e,t,r){const n=[],o=[];for(const i of e){const e=rt(i,t,r);n.push(e),e.absolute||o.push(e)}return{childrenMap:tt(n),nonAbsoluteChildren:o}}(e.children,i,r);return i.children=s,i.nonAbsoluteChildren=c,i.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 o=[];let i=e.parent;for(;i?.path;)o.unshift(i),i=i.parent;let a="";for(const e of o){const{urlParams:t,queryParams:r,spatParams:n}=e.paramMeta;if(t.length>0||r.length>0||n.length>0)return null;a=e.absolute?e.path:et(a,e.path)}return e.absolute?e.path:et(a,e.path)}(i),r&&(Object.freeze(c),Object.freeze(o),Object.freeze(i.children),Object.freeze(i)),i}function nt(e,t,r,n){return function(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build:n=>function(e,t=!0){return rt(e,null,t)}(function(e,t,r){const n=Xe({name:e,path:t},null);for(const e of r){const t=Xe(e,n);n.children.push(t)}return n}(e,t,r),!n?.skipFreeze)}}(e,t).addMany(r).build(n)}function ot(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=>ot(e))),t}function it(e){const t=e?.queryParams;return new Be({...void 0===e?.caseSensitive?void 0:{caseSensitive:e.caseSensitive},...void 0===e?.strictTrailingSlash?void 0:{strictTrailingSlash:e.strictTrailingSlash},...void 0===e?.strictQueryParams?void 0:{strictQueryParams:e.strictQueryParams},...void 0===e?.urlParamsEncoding?void 0:{urlParamsEncoding:e.urlParamsEncoding},parseQueryString:e=>((e,t)=>{const r=(e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)})(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return function(e,t){let r=0;const n=e.length;for(;r<n;){let o=e.indexOf("&",r);-1===o&&(o=n),Ze(e,r,o,t),r=o+1}}(e,t),t}(r);const n=Ke(t),o={};let i=0;const a=r.length;for(;i<a;){let e=r.indexOf("&",i);-1===e&&(e=a),Ze(r,i,e,o,n.strategies),i=e+1}return o})(e,t),buildQueryString:e=>((e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=Ke(t),o=[];for(const t of r){const r=e[t];if(void 0===r)continue;const i=Ye(t,r,n);i&&o.push(i)}return o.join("&")})(e,t)})}function at(e,t){return new TypeError(`[router.${e}] ${t}`)}var st=/^[A-Z_a-z][\w-]*$/,ct=/\S/;function ut(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function dt(e,t){if(!t.includes("."))return e.children.get(t);let r=e;for(const e of t.split("."))if(r=r.children.get(e),!r)return;return r}function lt(e,t,r,n="",o,i){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${ut(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${ut(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 a=e;!function(e,t){if("string"!=typeof e.name)throw new TypeError(`[router.${t}] Route name must be a string, got ${ut(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!ct.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("@@")){if(r.includes("."))throw new TypeError(`[router.${t}] Route name "${r}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(!st.test(r))throw new TypeError(`[router.${t}] Invalid route name "${r}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}}(a,t),function(e,t,r,n){if("string"!=typeof e){let t;throw t=null===e?"null":Array.isArray(e)?"array":typeof e,at(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw at(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw at(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw at(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const o=n&&Object.values(n.paramTypeMap).includes("url");if(e.startsWith("~")&&o)throw at(r,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}(a.path,a.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`)}(a,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`)}(a,t);const s=a.name,c=n?`${n}.${s}`:s;r&&c&&function(e,t,r){if(dt(e,t))throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),o&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(o,c,t);const u=a.path,d=n;if(r&&function(e,t,r,n){const o=""===t?e:dt(e,t);if(o)for(const e of o.children.values())if(e.path===r)throw new Error(`[router.${n}] Path "${r}" is already defined`)}(r,d,u,t),i&&function(e,t,r,n){const o=e.get(t);if(o?.has(r))throw new Error(`[router.${n}] Path "${r}" is already defined`);o?o.add(r):e.set(t,new Set([r]))}(i,d,u,t),void 0!==a.children){if(!Array.isArray(a.children))throw new TypeError(`[router.${t}] Route "${s}" children must be an array, got ${ut(a.children)}`);for(const e of a.children)lt(e,t,r,c,o,i)}}function ft(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 ${g(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 ${g(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 ${g(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(function(e,t){if(void 0!==e&&"function"==typeof e){const r="AsyncFunction"===e.constructor.name,n=e.toString().includes("__awaiter");if(r||n)throw new TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`)}}(e.forwardTo,t),e.children)for(const r of e.children)ft(r,`${t}.${r.name}`)}function ht(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 pt(e){const t=new Set;for(const r of e)for(const e of ht(r))t.add(e);return t}function mt(e,t,r="",n=[]){for(const o of e){const e=r?`${r}.${o.name}`:o.name,i=[...n,o.path];if(e===t)return i;if(o.children&&t.startsWith(`${e}.`))return mt(o.children,t,e,i)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function gt(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 gt(n.children,e))r.add(t)}return r}function vt(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&"string"==typeof n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,o]of vt(n.children,e))r.set(t,o)}return r}function wt(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}(function(e,t){const r=[],n=t.includes(".")?t.split("."):[t];""!==e.path&&r.push(e);let o=e;for(const e of n){const t=o.children.get(e);if(!t)return null;r.push(t),o=t}return r}(r,e)):pt(mt(n,e))}function yt(e,t,r,n,o){const i=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}(o,t),a=n.has(t);if(!i&&!a)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const s=pt(mt(r,e)),c=[...wt(t,i,o,r)].filter(e=>!s.has(e));if(c.length>0)throw new Error(`[router.addRoute] forwardTo target "${t}" requires params [${c.join(", ")}] that are not available in source route "${e}"`)}function Tt(e,t,r=100){const n=new Set,o=[e];let i=e;for(;t[i];){const e=t[i];if(n.has(e)){const t=o.indexOf(e),r=[...o.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(i),o.push(e),i=e,o.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${o.join(" → ")}`)}return i}function St(e,t,r){const n=gt(e),o=vt(e),i={...t};for(const[e,t]of o)i[e]=t;for(const[t,i]of o)yt(t,i,e,n,r);for(const e of Object.keys(i))Tt(e,i)}function bt(e,t){if(e.startsWith("@@"))throw new Error(`[router.${t}] Route name "${e}" uses the reserved "@@" prefix. Routes with this prefix are internal and cannot be modified through the public API.`)}function Et(e,t){for(const r of e)r&&"object"==typeof r&&"string"==typeof r.name&&(bt(r.name,t),r.children&&Et(r.children,t))}function Ot(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 ${g(t)}`);ft(t,t.name)}}function At(e,t,r){if(!f(e))throw new TypeError(`[router.${r}] Invalid routeName: ${g(e)}. Expected string.`);if(!l(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${g(t)}. Expected plain object.`)}function Pt(e,t){if("AsyncFunction"===e.constructor.name||e.toString().includes("__awaiter"))throw new TypeError(`[real-router] updateRoute: ${t} cannot be an async function`)}function Rt(e,t){if(null!=e){if("function"!=typeof e)throw new TypeError(`[real-router] updateRoute: ${t} must be a function or null, got ${typeof e}`);Pt(e,t)}}function $t(e,t,r,n){if(n&&t){let e=t;for(const t of n.split("."))if(e=e.children.get(t),!e)throw new Error(`[router.addRoute] Parent route "${n}" does not exist`)}const o=new Set,i=new Map;for(const r of e)lt(r,"addRoute",t,n??"",o,i);t&&r&&St(e,r,t)}function Nt(t){return!t||(e.error("router.clearRoutes","Cannot clear routes while navigation is in progress. Wait for navigation to complete."),!1)}function Dt(e,t,r,n,o){if(!r(e))throw new ReferenceError(`[real-router] updateRoute: route "${e}" does not exist`);if(null!=t&&"string"==typeof t){if(!r(t))throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);(function(e,t,r){const n=r.getSegmentsByName(e),o=r.getSegmentsByName(t),i=function(e){const t=new Set;for(const r of e)for(const e of r.paramMeta.urlParams)t.add(e);return t}(n),a=[];for(const e of o)for(const t of e.paramMeta.urlParams)a.push(t);const s=a.filter(e=>!i.has(e));if(s.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${s.join(", ")}] that are not available in source route "${e}"`)})(e,t,n),function(e,t,r){Tt(e,{...r.forwardMap,[e]:t})}(e,t,o)}}function Ct(e,t,r){const n=nt("",t,e),o=it(r);return o.registerTree(n),{tree:n,matcher:o}}function jt(e,t){const r=Ct(e.definitions,e.rootPath,e.matcherOptions);e.tree=r.tree,e.matcher=r.matcher,e.resolvedForwardMap=Lt(e.config,t)}function Ft(e){const t=Ct(e.definitions,e.rootPath,e.matcherOptions);e.tree=t.tree,e.matcher=t.matcher}function xt(e){It(e),Ft(e)}function It(e){e.definitions.length=0,Object.assign(e.config,we()),e.resolvedForwardMap=Object.create(null),e.routeCustomFields=Object.create(null)}function Lt(e,t){return t?_t(e):Mt(e)}function Mt(e){const t=Object.create(null);for(const r of Object.keys(e.forwardMap))t[r]=Tt(r,e.forwardMap);return t}function _t(e){const t=Object.create(null);for(const r of Object.keys(e.forwardMap)){let n=r;for(;e.forwardMap[n];)n=e.forwardMap[n];t[r]=n}return t}function kt(t,r,n,o,i,a,s){const c=new Set(["name","path","children","canActivate","canDeactivate","forwardTo","encodeParams","decodeParams","defaultParams"]),u=Object.fromEntries(Object.entries(t).filter(([e])=>!c.has(e)));Object.keys(u).length>0&&(o[r]=u),t.canActivate&&(s?s.addActivateGuard(r,t.canActivate):i.set(r,t.canActivate)),t.canDeactivate&&(s?s.addDeactivateGuard(r,t.canDeactivate):a.set(r,t.canDeactivate)),t.forwardTo&&function(t,r,n){if(t.canActivate&&e.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 "${"string"==typeof t.forwardTo?t.forwardTo:"[dynamic]"}".`),t.canDeactivate&&e.warn("real-router",`Route "${r}" has both forwardTo and canDeactivate. canDeactivate will be ignored because forwardTo creates a redirect (industry standard). Move canDeactivate to the target route "${"string"==typeof t.forwardTo?t.forwardTo:"[dynamic]"}".`),"function"==typeof t.forwardTo){const e="AsyncFunction"===t.forwardTo.constructor.name,n=t.forwardTo.toString().includes("__awaiter");if(e||n)throw new TypeError(`forwardTo callback cannot be async for route "${r}". Async functions break matchPath/buildPath.`)}"string"==typeof t.forwardTo?n.forwardMap[r]=t.forwardTo:n.forwardFnMap[r]=t.forwardTo}(t,r,n),t.decodeParams&&(n.decoders[r]=e=>t.decodeParams?.(e)??e),t.encodeParams&&(n.encoders[r]=e=>t.encodeParams?.(e)??e),t.defaultParams&&(n.defaultParams[r]=t.defaultParams)}function Ut(e,t,r,n,o,i,a=""){for(const s of e){const e=a?`${a}.${s.name}`:s.name;kt(s,e,t,r,n,o,i),s.children&&Ut(s.children,t,r,n,o,i,e)}}var Bt,Gt,Vt=".";function zt(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function qt(e){const t=typeof e;return"string"===t||"number"===t||"boolean"===t}function Wt(e,t,r){const n=t.meta?.params[e];if(!n||"object"!=typeof n)return!0;for(const e of Object.keys(n)){const n=t.params[e],o=r.params[e];if(qt(n)&&qt(o)&&String(n)!==String(o))return!1}return!0}function Qt(e){if(!e)return[""];const t=e.indexOf(Vt);if(-1===t)return[e];const r=e.indexOf(Vt,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(Vt,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(Vt,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(Vt),r=t.length,n=[t[0]];let o=t[0].length;for(let i=1;i<r-1;i++)o+=1+t[i].length,n.push(e.slice(0,o));return n.push(e),n}(e)}var Ht=null;function Kt(e,t){if(!t)return{intersection:"",toActivate:Qt(e.name),toDeactivate:[]};if(void 0===e.meta?.params&&void 0===t.meta?.params)return{intersection:"",toActivate:Qt(e.name),toDeactivate:zt(Qt(t.name))};const r=Qt(e.name),n=Qt(t.name),o=function(e,t,r,n,o){for(let i=0;i<o;i++){const o=r[i];if(o!==n[i])return i;if(!Wt(o,e,t))return i}return o}(e,t,r,n,Math.min(n.length,r.length)),i=[];for(let e=n.length-1;e>=o;e--)i.push(n[e]);const a=r.slice(o);return{intersection:o>0?n[o-1]:"",toDeactivate:i,toActivate:a}}function Jt(e,t,r){if(r?.reload)return Kt(e,t);if(null!==Ht&&e===Bt&&t===Gt)return Ht;const n=Kt(e,t);return Bt=e,Gt=t,Ht=n,n}function Yt(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}var Zt=class{#G;get#h(){return this.#G.depsStore}constructor(e=[],t=!1,r){this.#G=function(e,t,r){const n=[],o=we(),i=Object.create(null),a=new Map,s=new Map;for(const t of e)n.push(ye(t));const{tree:c,matcher:u}=Ct(n,"",r);return Ut(e,o,i,a,s,void 0,""),{definitions:n,config:o,tree:c,matcher:u,resolvedForwardMap:t?_t(o):Mt(o),routeCustomFields:i,rootPath:"",matcherOptions:r,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:a,pendingCanDeactivate:s,treeOperations:{commitTreeChanges:jt,resetStore:xt,nodeToDefinition:ot,validateRoutes:$t}}}(e,t,r)}static 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.transition?.reload)return!0;if(""===e&&!r)return!0;const{intersection:n,toActivate:o,toDeactivate:i}=Jt(t,r);return e===n||!!o.includes(e)||i.includes(e)}}setDependencies(e){this.#G.depsStore=e;for(const[t,r]of this.#G.pendingCanActivate)e.addActivateGuard(t,r);this.#G.pendingCanActivate.clear();for(const[t,r]of this.#G.pendingCanDeactivate)e.addDeactivateGuard(t,r);this.#G.pendingCanDeactivate.clear()}setLifecycleNamespace(e){this.#G.lifecycleNamespace=e}setRootPath(e){this.#G.rootPath=e,Ft(this.#G)}hasRoute(e){return this.#G.matcher.hasRoute(e)}clearRoutes(){xt(this.#G)}buildPath(e,t,r){if(e===T.UNKNOWN_ROUTE)return f(t?.path)?t.path:"";const n=Object.hasOwn(this.#G.config.defaultParams,e)?{...this.#G.config.defaultParams[e],...t}:t??{},o="function"==typeof this.#G.config.encoders[e]?this.#G.config.encoders[e]({...n}):n,i=r?.trailingSlash;return this.#G.matcher.buildPath(e,o,{trailingSlash:"never"===i||"always"===i?i:void 0,queryParamsMode:r?.queryParamsMode})}matchPath(e,t){const r=t,n=this.#G.matcher.match(e);if(!n)return;const o=Yt(n),{name:i,params:a,meta:s}=o,c="function"==typeof this.#G.config.decoders[i]?this.#G.config.decoders[i](a):a,{name:u,params:d}=this.#h.forwardState(i,c);let l=e;if(r.rewritePathOnMatch){const e="function"==typeof this.#G.config.encoders[u]?this.#G.config.encoders[u]({...d}):d,t=r.trailingSlash;l=this.#G.matcher.buildPath(u,e,{trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:r.queryParamsMode})}return this.#h.makeState(u,d,l,{params:s})}forwardState(e,t){if(Object.hasOwn(this.#G.config.forwardFnMap,e)){const r=this.#V(e,t),n=this.#G.config.forwardFnMap[e],o=this.#z(e,n,t);return{name:o,params:this.#V(o,r)}}const r=this.#G.resolvedForwardMap[e]??e;if(r!==e&&Object.hasOwn(this.#G.config.forwardFnMap,r)){const n=this.#V(e,t),o=this.#G.config.forwardFnMap[r],i=this.#z(r,o,t);return{name:i,params:this.#V(i,n)}}if(r!==e){const n=this.#V(e,t);return{name:r,params:this.#V(r,n)}}return{name:e,params:this.#V(e,t)}}buildStateResolved(e,t){const r=this.#G.matcher.getSegmentsByName(e);if(r)return Yt({segments:r,params:t,meta:this.#G.matcher.getMetaByName(e)},e)}buildStateWithSegmentsResolved(e,t){const r=this.#G.matcher.getSegmentsByName(e);if(r)return{state:Yt({segments:r,params:t,meta:this.#G.matcher.getMetaByName(e)},e),segments:r}}isActiveRoute(e,t={},r=!1,n=!0){ve.has(e)||(m(e,"isActiveRoute"),ve.add(e));const o=this.#h.getState();if(!o)return!1;const i=o.name;if(i!==e&&!i.startsWith(`${e}.`)&&!e.startsWith(`${i}.`))return!1;const a=this.#G.config.defaultParams[e];if(r||i===e){const r=a?{...a,...t}:t;return this.#h.areStatesEqual({name:e,params:r,path:""},o,n)}const s=o.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(t,s)&&(!a||function(e,t,r){for(const n in e)if(!(n in r)&&e[n]!==t[n])return!1;return!0}(a,s,t))}getUrlParams(e){const t=this.#G.matcher.getSegmentsByName(e);return t?function(e){const t=[];for(const r of e)for(const e of r.paramMeta.urlParams)t.push(e);return t}(t):[]}getStore(){return this.#G}#V(e,t){return Object.hasOwn(this.#G.config.defaultParams,e)?{...this.#G.config.defaultParams[e],...t}:t}#z(e,t,r){const n=new Set([e]);let o=t(this.#h.getDependency,r),i=0;if("string"!=typeof o)throw new TypeError("forwardTo callback must return a string, got "+typeof o);for(;i<100;){if(void 0===this.#G.matcher.getSegmentsByName(o))throw new Error(`Route "${o}" does not exist`);if(n.has(o)){const e=[...n,o].join(" → ");throw new Error(`Circular forwardTo detected: ${e}`)}if(n.add(o),Object.hasOwn(this.#G.config.forwardFnMap,o)){o=(0,this.#G.config.forwardFnMap[o])(this.#h.getDependency,r),i++;continue}const e=this.#G.config.forwardMap[o];if(void 0===e)return o;o=e,i++}throw new Error("forwardTo exceeds maximum depth of 100")}},Xt=new Set(Object.values(w)),er=new Set(["code","segment","path","redirect"]),tr=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),rr=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:n,redirect:o,...i}={}){super(t??e),this.code=e,this.segment=r,this.path=n,this.redirect=o?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}(o):void 0;for(const[e,t]of Object.entries(i)){if(er.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);tr.has(e)||(this[e]=t)}}setCode(e){this.code=e,Xt.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(er.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);tr.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}};function nr(e,t,r){if(e instanceof rr)throw e.setCode(t),e;throw new rr(t,function(e,t){const r={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))or.has(r)||(t[r]=n);return{...r,...t}}return r}(e,r))}var or=new Set(["code","segment","path","redirect"]);async function ir(e,t,r,n,o,i,a){const s=n.filter(t=>e.has(t));if(0===s.length)return;let c;for(const n of s){if(i())throw new rr(w.TRANSITION_CANCELLED);const s=e.get(n);try{c=await s(t,r,a)}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)throw new rr(w.TRANSITION_CANCELLED,{reason:a.reason});nr(e,o,n)}if(!c)throw new rr(o,{segment:n})}}var ar=[T.UNKNOWN_ROUTE];Object.freeze(ar);var sr={replace:!0};Object.freeze(sr);var cr=class{#q;#h;#W;#Q=null;static validateNavigateArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${g(e)}`)}(e)}static validateNavigateToDefaultArgs(e){!function(e){if(void 0!==e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}(e)}static validateNavigationOptions(e,t){!function(e,t){if(!function(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=e;for(const e of i){const r=t[e];if(void 0!==r&&"boolean"!=typeof r)return!1}const r=t.signal;return!(void 0!==r&&!(r instanceof AbortSignal))}(e))throw new TypeError(`[router.${t}] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}(e,t)}setCanNavigate(e){this.#q=e}setDependencies(e){this.#h=e}setTransitionDependencies(e){this.#W=e}async navigate(t,r,n){if(!this.#q())throw new rr(w.ROUTER_NOT_STARTED);const o=this.#h,i=o.buildStateWithSegments(t,r);if(!i){const e=new rr(w.ROUTE_NOT_FOUND);throw o.emitTransitionError(void 0,o.getState(),e),e}const{state:a}=i,s=o.makeState(a.name,a.params,o.buildPath(a.name,a.params),{params:a.meta}),c=o.getState();if(n=function(e,t){return t?.name!==T.UNKNOWN_ROUTE||e.replace?e:{...e,replace:!0}}(n,c),c&&!n.reload&&!n.force&&o.areStatesEqual(c,s,!1)){const e=new rr(w.SAME_STATES);throw o.emitTransitionError(s,c,e),e}const u=this.#W;u.isTransitioning()&&(e.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use cloneRouter() to create isolated instance per request."),this.#Q?.abort(new rr(w.TRANSITION_CANCELLED)),o.cancelNavigation());const d=new AbortController;if(this.#Q=d,n.signal){if(n.signal.aborted)throw this.#Q=null,new rr(w.TRANSITION_CANCELLED,{reason:n.signal.reason});n.signal.addEventListener("abort",()=>{d.abort(n.signal?.reason)},{once:!0,signal:d.signal})}o.startTransition(s,c);try{const{state:e,meta:t}=await async function(e,t,r,n,o){const[i,a]=e.getLifecycleFunctions(),s=t.name===T.UNKNOWN_ROUTE,c=()=>o.aborted||!e.isActive(),{toDeactivate:u,toActivate:d,intersection:l}=Jt(t,r,void 0===n.reload?void 0:{reload:n.reload}),f=!s&&d.length>0;if(r&&!n.forceDeactivate&&u.length>0&&await ir(i,t,r,u,w.CANNOT_DEACTIVATE,c,o),c())throw new rr(w.TRANSITION_CANCELLED);if(f&&await ir(a,t,r,d,w.CANNOT_ACTIVATE,c,o),c())throw new rr(w.TRANSITION_CANCELLED);if(r)for(const t of u)!d.includes(t)&&i.has(t)&&e.clearCanDeactivate(t);return{state:t,meta:{phase:"activating",segments:{deactivated:u,activated:d,intersection:l}}}}(u,s,c,n,d.signal);if(e.name===T.UNKNOWN_ROUTE||o.hasRoute(e.name)){const r=function(e,t,r,n){const o={phase:t.phase,...void 0!==r?.name&&{from:r.name},reason:"success",segments:t.segments,...void 0!==n.reload&&{reload:n.reload},...void 0!==n.redirected&&{redirected:n.redirected}};return Object.freeze(o.segments.deactivated),Object.freeze(o.segments.activated),Object.freeze(o.segments),Object.freeze(o),{...e,transition:o}}(e,t,c,n);o.setState(r);const i=void 0===n.signal?n:function({signal:e,...t}){return t}(n);return o.sendTransitionDone(r,c,i),r}{const t=new rr(w.ROUTE_NOT_FOUND,{routeName:e.name});throw o.sendTransitionError(e,c,t),t}}catch(e){throw function(e,t,r,n){const o=t;o.code!==w.TRANSITION_CANCELLED&&o.code!==w.ROUTE_NOT_FOUND&&(o.code===w.CANNOT_ACTIVATE||o.code===w.CANNOT_DEACTIVATE?e.sendTransitionBlocked(r,n,o):e.sendTransitionError(r,n,o))}(o,e,s,c),e}finally{d.abort(),this.#Q===d&&(this.#Q=null)}}async navigateToDefault(e){const t=this.#h,r=t.getOptions();if(!r.defaultRoute)throw new rr(w.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"});const n=re(r.defaultRoute,t.getDependency);if(!n)throw new rr(w.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"});const o=re(r.defaultParams,t.getDependency);return this.navigate(n,o,e)}navigateToNotFound(e){const t=this.#h.getState(),r=t?Qt(t.name).toReversed():[];Object.freeze(r);const n={deactivated:r,activated:ar,intersection:""};Object.freeze(n);const o={phase:"activating",...t&&{from:t.name},reason:"success",segments:n};Object.freeze(o);const i={name:T.UNKNOWN_ROUTE,params:{},path:e,transition:o};return Object.freeze(i),this.#h.setState(i),this.#h.emitTransitionSuccess(i,t,sr),i}abortCurrentNavigation(){this.#Q?.abort(new rr(w.TRANSITION_CANCELLED)),this.#Q=null}},ur={replace:!0};Object.freeze(ur);var dr=class{#h;static validateStartArgs(e){if(1!==e.length||"string"!=typeof e[0])throw new Error("[router.start] Expected exactly 1 string argument (startPath).")}setDependencies(e){this.#h=e}async start(e){const t=this.#h,r=t.getOptions(),n=t.matchPath(e);if(!n&&!r.allowNotFound){const r=new rr(w.ROUTE_NOT_FOUND,{path:e});throw t.emitTransitionError(void 0,void 0,r),r}return t.completeStart(),n?t.navigate(n.name,n.params,ur):t.navigateToNotFound(e)}stop(){this.#h.clearState()}},lr=class{#H;#K;#J;constructor(e){this.#H=e.routerFSM,this.#K=e.emitter,this.#J=void 0,this.#Y()}static validateSubscribeListener(e){if("function"!=typeof e)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#K.emit(R.ROUTER_START)}emitRouterStop(){this.#K.emit(R.ROUTER_STOP)}emitTransitionStart(e,t){this.#K.emit(R.TRANSITION_START,e,t)}emitTransitionSuccess(e,t,r){this.#K.emit(R.TRANSITION_SUCCESS,e,t,r)}emitTransitionError(e,t,r){this.#K.emit(R.TRANSITION_ERROR,e,t,r)}emitTransitionCancel(e,t){this.#K.emit(R.TRANSITION_CANCEL,e,t)}sendStart(){this.#H.send(L)}sendStop(){this.#H.send(G)}sendDispose(){this.#H.send(V)}completeStart(){this.#H.send(M)}beginTransition(e,t){this.#J=e,this.#H.send(_,{toState:e,fromState:t})}completeTransition(e,t,r={}){this.#H.send(k,{state:e,fromState:t,opts:r}),this.#J=void 0}failTransition(e,t,r){this.#H.send(U,{toState:e,fromState:t,error:r}),this.#J=void 0}cancelTransition(e,t){this.#H.send(B,{toState:e,fromState:t}),this.#J=void 0}emitOrFailTransitionError(e,t,r){this.#H.getState()===F?this.#H.send(U,{toState:e,fromState:t,error:r}):this.emitTransitionError(e,t,r)}canBeginTransition(){return this.#H.canSend(_)}canStart(){return this.#H.canSend(L)}canCancel(){return this.#H.canSend(B)}isActive(){const e=this.#H.getState();return e!==C&&e!==I}isDisposed(){return this.#H.getState()===I}isTransitioning(){return this.#H.getState()===x}isReady(){return this.#H.getState()===F}getCurrentToState(){return this.#J}addEventListener(e,t){return this.#K.on(e,t)}subscribe(e){return this.#K.on(R.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}clearAll(){this.#K.clearAll()}setLimits(e){this.#K.setLimits(e)}cancelTransitionIfRunning(e){this.canCancel()&&this.cancelTransition(this.#J,e)}#Y(){const e=this.#H;e.on(j,M,()=>{this.emitRouterStart()}),e.on(F,G,()=>{this.emitRouterStop()}),e.on(F,_,e=>{this.emitTransitionStart(e.toState,e.fromState)}),e.on(x,k,e=>{this.emitTransitionSuccess(e.state,e.fromState,e.opts)}),e.on(x,B,e=>{this.emitTransitionCancel(e.toState,e.fromState)}),e.on(j,U,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(F,U,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(x,U,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)})}};function fr(e,t){if("string"!=typeof e)throw new TypeError(`[router.${t}]: dependency name must be a string, got ${typeof e}`)}function hr(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid argument: expected plain object, received ${g(e)}`);for(const r in e)if(Object.getOwnPropertyDescriptor(e,r)?.get)throw new TypeError(`[router.${t}] Getters not allowed: "${r}"`)}var pr=new rr(w.ROUTER_ALREADY_STARTED),mr=new Set(["all","warn-error","error-only"]);var gr=class{router;options;limits;dependenciesStore;state;routes;routeLifecycle;plugins;navigation;lifecycle;eventBus;constructor(e){this.router=e.router,this.options=e.options,this.limits=e.limits,this.dependenciesStore=e.dependenciesStore,this.state=e.state,this.routes=e.routes,this.routeLifecycle=e.routeLifecycle,this.plugins=e.plugins,this.navigation=e.navigation,this.lifecycle=e.lifecycle,this.eventBus=e.eventBus}wireLimits(){this.dependenciesStore.limits=this.limits,this.plugins.setLimits(this.limits),this.eventBus.setLimits({maxListeners:this.limits.maxListeners,warnListeners:this.limits.warnListeners,maxEventDepth:this.limits.maxEventDepth}),this.routeLifecycle.setLimits(this.limits)}wireRouteLifecycleDeps(){this.routeLifecycle.setRouter(this.router),this.routeLifecycle.setDependencies({getDependency:e=>this.dependenciesStore.dependencies[e]})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(e,t)=>{this.routeLifecycle.addCanActivate(e,t,!0,!0)},addDeactivateGuard:(e,t)=>{this.routeLifecycle.addCanDeactivate(e,t,!0,!0)},makeState:(e,t,r,n)=>this.state.makeState(e,t,r,n),getState:()=>this.state.get(),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependenciesStore.dependencies[e],forwardState:(e,t)=>{const r=J(this.router);return r.noValidate||At(e,t,"forwardState"),r.forwardState(e,t)}}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wirePluginsDeps(){this.plugins.setRouter(this.router),this.plugins.setDependencies({addEventListener:(e,t)=>this.eventBus.addEventListener(e,t),canNavigate:()=>this.eventBus.canBeginTransition(),getDependency:e=>this.dependenciesStore.dependencies[e]})}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:e=>this.routes.hasRoute(e),getState:()=>this.state.get(),setState:e=>{this.state.set(e)},buildStateWithSegments:(e,t)=>{const r=J(this.router);r.noValidate||At(e,t,"navigate");const{name:n,params:o}=r.forwardState(e,t);return this.routes.buildStateWithSegmentsResolved(n,o)},makeState:(e,t,r,n)=>this.state.makeState(e,t,r,n),buildPath:(e,t)=>J(this.router).buildPath(e,t),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependenciesStore.dependencies[e],startTransition:(e,t)=>{this.eventBus.beginTransition(e,t)},cancelNavigation:()=>{this.eventBus.cancelTransition(this.eventBus.getCurrentToState(),this.state.get())},sendTransitionDone:(e,t,r)=>{this.eventBus.completeTransition(e,t,r)},sendTransitionBlocked:(e,t,r)=>{this.eventBus.failTransition(e,t,r)},sendTransitionError:(e,t,r)=>{this.eventBus.failTransition(e,t,r)},emitTransitionError:(e,t,r)=>{this.eventBus.emitOrFailTransitionError(e,t,r)},emitTransitionSuccess:(e,t,r)=>{this.eventBus.emitTransitionSuccess(e,t,r)}}),this.navigation.setCanNavigate(()=>this.eventBus.canBeginTransition()),this.navigation.setTransitionDependencies({getLifecycleFunctions:()=>this.routeLifecycle.getFunctions(),isActive:()=>this.router.isActive(),isTransitioning:()=>this.eventBus.isTransitioning(),clearCanDeactivate:e=>{this.routeLifecycle.clearCanDeactivate(e)}})}wireLifecycleDeps(){this.lifecycle.setDependencies({getOptions:()=>this.options.get(),navigate:(e,t,r)=>this.navigation.navigate(e,t,r),navigateToNotFound:e=>this.navigation.navigateToNotFound(e),clearState:()=>{this.state.set(void 0)},matchPath:e=>this.routes.matchPath(e,this.options.get()),completeStart:()=>{this.eventBus.completeStart()},emitTransitionError:(e,t,r)=>{this.eventBus.failTransition(e,t,r)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(e,t)=>J(this.router).buildPath(e,t),getUrlParams:e=>this.routes.getUrlParams(e)})}},vr=class r{#u;#y;#Z;#X;#ee;#te;#g;#re;#ne;#oe;#ie;constructor(r=[],n={},i={}){n.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)||!mr.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}(n.logger)&&(e.configure(n.logger),delete n.logger),ae.validateOptions(n,"constructor");const a=n.noValidate??!1;a||hr(i,"constructor"),!a&&r.length>0&&(Ot(r),$t(r)),this.#u=new ae(n),this.#y=function(e={}){return{...N,...e}}(n.limits),this.#Z=function(e={}){const t=Object.create(null);for(const r in e)void 0!==e[r]&&(t[r]=e[r]);return{dependencies:t,limits:N}}(i),this.#X=new ce,this.#ee=new Zt(r,a,function(e){return{strictTrailingSlash:"strict"===e.trailingSlash,strictQueryParams:"strict"===e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding,queryParams:e.queryParams}}(this.#u.get())),this.#te=new ge,this.#g=new fe,this.#re=new cr,this.#ne=new dr,this.#ie=a;const s=new t(z),c=new o({onListenerError:(t,r)=>{e.error("Router",`Error in listener for ${t}:`,r)},onListenerWarn:(t,r)=>{e.warn("router.addEventListener",`Event "${t}" has ${r} listeners — possible memory leak`)}});var u;this.#oe=new lr({routerFSM:s,emitter:c}),(u=new gr({router:this,options:this.#u,limits:this.#y,dependenciesStore:this.#Z,state:this.#X,routes:this.#ee,routeLifecycle:this.#te,plugins:this.#g,navigation:this.#re,lifecycle:this.#ne,eventBus:this.#oe})).wireLimits(),u.wireRouteLifecycleDeps(),u.wireRoutesDeps(),u.wirePluginsDeps(),u.wireNavigationDeps(),u.wireLifecycleDeps(),u.wireStateDeps();const d=new Map;var l;l={makeState:(e,t,r,n,o)=>this.#X.makeState(e,t,r,n,o),forwardState:Y("forwardState",(e,t)=>this.#ee.forwardState(e,t),d),buildStateResolved:(e,t)=>this.#ee.buildStateResolved(e,t),matchPath:(e,t)=>this.#ee.matchPath(e,t),getOptions:()=>this.#u.get(),addEventListener:(e,t)=>this.#oe.addEventListener(e,t),buildPath:Y("buildPath",(e,t)=>this.#ee.buildPath(e,t??{},this.#u.get()),d),start:Y("start",e=>(a||dr.validateStartArgs([e]),this.#ne.start(e)),d),interceptors:d,setRootPath:e=>{this.#ee.setRootPath(e)},getRootPath:()=>this.#ee.getStore().rootPath,getTree:()=>this.#ee.getStore().tree,isDisposed:()=>this.#oe.isDisposed(),noValidate:a,dependenciesGetStore:()=>this.#Z,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#Z.dependencies}),getLifecycleFactories:()=>this.#te.getFactories(),getPluginFactories:()=>this.#g.getAll(),routeGetStore:()=>this.#ee.getStore(),getStateName:()=>this.#X.get()?.name,isTransitioning:()=>this.#oe.isTransitioning(),clearState:()=>{this.#X.set(void 0)},setState:e=>{this.#X.set(e)},routerExtensions:[]},K.set(this,l),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.dispose=this.dispose.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToNotFound=this.navigateToNotFound.bind(this),this.subscribe=this.subscribe.bind(this)}isActiveRoute(t,r,n,o){return this.#ie||function(e,t,r,n){if(!f(e))throw new TypeError("Route name must be a string");if(void 0!==t&&!l(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)}(t,r,n,o),""===t?(e.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#ee.isActiveRoute(t,r,n,o)}buildPath(e,t){return this.#ie||function(e){if(!f(e)||""===e)throw new TypeError("[real-router] buildPath: route must be a non-empty string, got "+("string"==typeof e?'""':typeof e))}(e),J(this).buildPath(e,t)}getState(){return this.#X.get()}getPreviousState(){return this.#X.getPrevious()}areStatesEqual(e,t,r=!0){return this.#ie||ce.validateAreStatesEqualArgs(e,t,r),this.#X.areStatesEqual(e,t,r)}shouldUpdateNode(e){return this.#ie||function(e){if(!f(e))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof e)}(e),Zt.shouldUpdateNode(e)}isActive(){return this.#oe.isActive()}start(e){if(!this.#oe.canStart())return Promise.reject(pr);this.#oe.sendStart();const t=J(this).start(e).catch(e=>{throw this.#oe.isReady()&&(this.#ne.stop(),this.#oe.sendStop()),e});return r.#ae(t),t}stop(){return this.#re.abortCurrentNavigation(),this.#oe.cancelTransitionIfRunning(this.#X.get()),this.#oe.isReady()||this.#oe.isTransitioning()?(this.#ne.stop(),this.#oe.sendStop(),this):this}dispose(){if(this.#oe.isDisposed())return;this.#re.abortCurrentNavigation(),this.#oe.cancelTransitionIfRunning(this.#X.get()),(this.#oe.isReady()||this.#oe.isTransitioning())&&(this.#ne.stop(),this.#oe.sendStop()),this.#oe.sendDispose(),this.#oe.clearAll(),this.#g.disposeAll();const e=J(this);for(const t of e.routerExtensions)for(const e of t.keys)delete this[e];e.routerExtensions.length=0,this.#ee.clearRoutes(),this.#te.clearAll(),this.#X.reset(),this.#Z.dependencies=Object.create(null),this.#se()}canNavigateTo(e,t){if(this.#ie||m(e,"canNavigateTo"),!this.#ee.hasRoute(e))return!1;const r=J(this),{name:n,params:o}=r.forwardState(e,t??{}),i=this.#X.makeState(n,o),a=this.#X.get(),{toDeactivate:s,toActivate:c}=Jt(i,a);for(const e of s)if(!this.#te.checkDeactivateGuardSync(e,i,a))return!1;for(const e of c)if(!this.#te.checkActivateGuardSync(e,i,a))return!1;return!0}usePlugin(...e){return this.#ie||(fe.validateUsePluginArgs(e),fe.validatePluginLimit(this.#g.count(),e.length,this.#y.maxPlugins),fe.validateNoDuplicatePlugins(e,this.#g.has.bind(this.#g))),this.#g.use(...e)}subscribe(e){return this.#ie||lr.validateSubscribeListener(e),this.#oe.subscribe(e)}navigate(e,t,n){this.#ie||cr.validateNavigateArgs(e);const o=n??{};this.#ie||cr.validateNavigationOptions(o,"navigate");const i=this.#re.navigate(e,t??{},o);return r.#ae(i),i}navigateToDefault(e){this.#ie||cr.validateNavigateToDefaultArgs(e);const t=e??{};this.#ie||cr.validateNavigationOptions(t,"navigateToDefault");const n=this.#re.navigateToDefault(t);return r.#ae(n),n}navigateToNotFound(e){if(!this.#oe.isActive())throw new rr(w.ROUTER_NOT_STARTED);const t=e??this.#X.get().path;return this.#re.navigateToNotFound(t)}static#ce=t=>{t instanceof rr&&(t.code===w.SAME_STATES||t.code===w.TRANSITION_CANCELLED||t.code===w.ROUTER_NOT_STARTED||t.code===w.ROUTE_NOT_FOUND)||e.error("router.navigate","Unexpected navigation error",t)};static#ae(e){e.catch(r.#ce)}#se(){this.navigate=wr,this.navigateToDefault=wr,this.navigateToNotFound=wr,this.start=wr,this.stop=wr,this.usePlugin=wr,this.subscribe=wr,this.canNavigateTo=wr}};function wr(){throw new rr(w.ROUTER_DISPOSED)}var yr=(e=[],t={},r={})=>new vr(e,t,r),Tr=e=>Object.freeze({navigate:e.navigate,getState:e.getState,isActiveRoute:e.isActiveRoute,canNavigateTo:e.canNavigateTo,subscribe:e.subscribe});function Sr(e){if(e())throw new rr(w.ROUTER_DISPOSED)}function br(e){const t=J(e);return{makeState:(e,r,n,o,i)=>(t.noValidate||function(e,t,r,n){if(!f(e))throw new TypeError(`[router.makeState] Invalid name: ${g(e)}. Expected string.`);if(void 0!==t&&!l(t))throw new TypeError(`[router.makeState] Invalid params: ${g(t)}. Expected plain object.`);if(void 0!==r&&!f(r))throw new TypeError(`[router.makeState] Invalid path: ${g(r)}. Expected string.`);if(void 0!==n&&"number"!=typeof n)throw new TypeError(`[router.makeState] Invalid forceId: ${g(n)}. Expected number.`)}(e,r,n,i),t.makeState(e,r,n,o,i)),buildState:(e,r)=>{t.noValidate||At(e,r,"buildState");const{name:n,params:o}=t.forwardState(e,r);return t.buildStateResolved(n,o)},forwardState:(e,r)=>(t.noValidate||At(e,r,"forwardState"),t.forwardState(e,r)),matchPath:e=>(t.noValidate||function(e){if(!f(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e),t.matchPath(e,t.getOptions())),setRootPath:e=>{Sr(t.isDisposed),t.noValidate||function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${g(e)}`)}(e),t.setRootPath(e)},getRootPath:t.getRootPath,addEventListener:(e,r)=>(Sr(t.isDisposed),t.noValidate||function(e,t){if(function(e){if(!$.has(e))throw new Error(`Invalid event name: ${String(e)}`)}(e),"function"!=typeof t)throw new TypeError(`Expected callback to be a function for event ${e}`)}(e,r),t.addEventListener(e,r)),buildNavigationState:(e,r={})=>{t.noValidate||At(e,r,"buildNavigationState");const{name:n,params:o}=t.forwardState(e,r),i=t.buildStateResolved(n,o);if(i)return t.makeState(i.name,i.params,t.buildPath(i.name,i.params),{params:i.meta})},getOptions:t.getOptions,getTree:t.getTree,addInterceptor:(e,r)=>{Sr(t.isDisposed);let n=t.interceptors.get(e);return n||(n=[],t.interceptors.set(e,n)),n.push(r),()=>{const e=n.indexOf(r);-1!==e&&n.splice(e,1)}},extendRouter:r=>{Sr(t.isDisposed);const n=Object.keys(r);for(const t of n)if(t in e)throw new rr(w.PLUGIN_CONFLICT,{message:`Cannot extend router: property "${t}" already exists`});for(const t of n)e[t]=r[t];const o={keys:n};t.routerExtensions.push(o);let i=!1;return()=>{if(i)return;i=!0;for(const t of o.keys)delete e[t];const r=t.routerExtensions.indexOf(o);-1!==r&&t.routerExtensions.splice(r,1)}}}}function Er(e,t,r=""){for(const n of e){const e=r?`${r}.${n.name}`:n.name;if(e===t)return n;if(n.children&&t.startsWith(`${e}.`))return Er(n.children,t,e)}}function Or(e,t,r,n){const o={name:e.name,path:e.path},i=r.forwardFnMap[t],a=r.forwardMap[t];void 0!==i?o.forwardTo=i:void 0!==a&&(o.forwardTo=a),t in r.defaultParams&&(o.defaultParams=r.defaultParams[t]),t in r.decoders&&(o.decodeParams=r.decoders[t]),t in r.encoders&&(o.encodeParams=r.encoders[t]);const[s,c]=n;return t in c&&(o.canActivate=c[t]),t in s&&(o.canDeactivate=s[t]),e.children&&(o.children=e.children.map(e=>Or(e,`${t}.${e.name}`,r,n))),o}function Ar(e,t,r,n){if(n){const t=Er(e.definitions,n);t.children??=[];for(const e of r)t.children.push(ye(e))}else for(const t of r)e.definitions.push(ye(t));Ut(r,e.config,e.routeCustomFields,e.pendingCanActivate,e.pendingCanDeactivate,e.depsStore,n??""),e.treeOperations.commitTreeChanges(e,t)}function Pr(e,t,r){return!!Te(e.definitions,r)&&(function(e,t,r,n){const o=t=>t===e||t.startsWith(`${e}.`);Se(t.decoders,o),Se(t.encoders,o),Se(t.defaultParams,o),Se(t.forwardMap,o),Se(t.forwardFnMap,o),Se(r,o),Se(t.forwardMap,e=>o(t.forwardMap[e]));const[i,a]=n.getFactories();for(const e of Object.keys(a))o(e)&&n.clearCanActivate(e);for(const e of Object.keys(i))o(e)&&n.clearCanDeactivate(e)}(r,e.config,e.routeCustomFields,e.lifecycleNamespace),e.treeOperations.commitTreeChanges(e,t),!0)}function Rr(e,t){const r=e.matcher.getSegmentsByName(t);if(!r)return;const n=r.at(-1),o=e.treeOperations.nodeToDefinition(n),i=e.lifecycleNamespace.getFactories();return Or(o,t,e.config,i)}function $r(e){if(e())throw new rr(w.ROUTER_DISPOSED)}function Nr(t){const r=J(t),n=r.routeGetStore(),o=r.noValidate;return{add:(e,t)=>{$r(r.isDisposed);const i=Array.isArray(e)?e:[e],a=t?.parent;r.noValidate||(void 0!==a&&function(e){if("string"!=typeof e||""===e)throw new TypeError(`[router.addRoute] parent option must be a non-empty string, got ${g(e)}`);m(e,"addRoute")}(a),Et(i,"addRoute"),Ot(i),n.treeOperations.validateRoutes(i,n.tree,n.config.forwardMap,a)),Ar(n,o,i,a)},remove:t=>{$r(r.isDisposed),r.noValidate||(function(e){m(e,"removeRoute")}(t),bt(t,"removeRoute"));const i=function(t,r,n){if(r){const n=r===t,o=r.startsWith(`${t}.`);if(n||o)return e.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${n?"":` (current: "${r}")`}. Navigate away first.`),!1}return n&&e.warn("router.removeRoute",`Route "${t}" removed while navigation is in progress. This may cause unexpected behavior.`),!0}(t,r.getStateName(),r.isTransitioning());i&&(Pr(n,o,t)||e.warn("router.removeRoute",`Route "${t}" not found. No changes made.`))},update:(t,i)=>{$r(r.isDisposed),r.noValidate||(function(e,t){if(m(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 ${g(t)}`)}(t,i),bt(t,"updateRoute"));const{forwardTo:a,defaultParams:s,decodeParams:c,encodeParams:u,canActivate:d,canDeactivate:l}=i;r.noValidate||function(e,t,r,n){if(null!=e){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError(`[real-router] updateRoute: forwardTo must be a string, function, or null, got ${g(e)}`);"function"==typeof e&&Pt(e,"forwardTo callback")}if(null!=t&&("object"!=typeof t||Array.isArray(t)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${g(t)}`);Rt(r,"decodeParams"),Rt(n,"encodeParams")}(a,s,c,u),r.isTransitioning()&&e.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),r.noValidate||Dt(t,a,e=>n.matcher.hasRoute(e),n.matcher,n.config),function(e,t,r,n){if(void 0!==n.forwardTo&&(e.resolvedForwardMap=function(e,t,r,n,o){return null===t?(delete r.forwardMap[e],delete r.forwardFnMap[e]):"string"==typeof t?(delete r.forwardFnMap[e],r.forwardMap[e]=t):(delete r.forwardMap[e],r.forwardFnMap[e]=t),o(r,n)}(r,n.forwardTo,e.config,t,Lt)),void 0!==n.defaultParams&&(null===n.defaultParams?delete e.config.defaultParams[r]:e.config.defaultParams[r]=n.defaultParams),void 0!==n.decodeParams)if(null===n.decodeParams)delete e.config.decoders[r];else{const t=n.decodeParams;e.config.decoders[r]=e=>t(e)??e}if(void 0!==n.encodeParams)if(null===n.encodeParams)delete e.config.encoders[r];else{const t=n.encodeParams;e.config.encoders[r]=e=>t(e)??e}}(n,o,t,{forwardTo:a,defaultParams:s,decodeParams:c,encodeParams:u}),void 0!==d&&(null===d?n.lifecycleNamespace.clearCanActivate(t):n.lifecycleNamespace.addCanActivate(t,d,o,!0)),void 0!==l&&(null===l?n.lifecycleNamespace.clearCanDeactivate(t):n.lifecycleNamespace.addCanDeactivate(t,l,o,!0))},clear:()=>{$r(r.isDisposed),Nt(r.isTransitioning())&&(n.treeOperations.resetStore(n),n.lifecycleNamespace.clearAll(),r.clearState())},has:e=>(r.noValidate||m(e,"hasRoute"),n.matcher.hasRoute(e)),get:e=>(r.noValidate||m(e,"getRoute"),Rr(n,e)),getConfig:e=>function(e,t){if(e.matcher.hasRoute(t))return e.routeCustomFields[t]}(n,e),replace:e=>{$r(r.isDisposed);const i=Array.isArray(e)?e:[e];if(!Nt(r.isTransitioning()))return;r.noValidate||(Et(i,"replaceRoutes"),Ot(i),n.treeOperations.validateRoutes(i));const a=t.getState()?.path;!function(e,t,r,n,o){It(e),e.lifecycleNamespace.clearDefinitionGuards();for(const t of r)e.definitions.push(ye(t));if(Ut(r,e.config,e.routeCustomFields,e.pendingCanActivate,e.pendingCanDeactivate,e.depsStore,""),e.treeOperations.commitTreeChanges(e,t),void 0!==o){const e=n.matchPath(o,n.getOptions());e?n.setState(e):n.clearState()}}(n,o,i,r,a)}}}function Dr(e){if(e())throw new rr(w.ROUTER_DISPOSED)}function Cr(t){const r=J(t);return{get:e=>{r.noValidate||fr(e,"getDependency");const t=r.dependenciesGetStore().dependencies[e];return r.noValidate||function(e,t){if(void 0===e)throw new ReferenceError(`[router.getDependency]: dependency "${t}" not found`)}(t,e),t},getAll:()=>({...r.dependenciesGetStore().dependencies}),set:(t,n)=>{Dr(r.isDisposed),r.noValidate||function(e){if("string"!=typeof e)throw new TypeError("[router.setDependency]: dependency name must be a string, got "+typeof e)}(t),function(t,r,n){if(void 0===n)return!1;if(Object.hasOwn(t.dependencies,r)){const o=t.dependencies[r],i=o!==n,a=Number.isNaN(o)&&Number.isNaN(n);i&&!a&&e.warn("router.setDependency","Router dependency already exists and is being overwritten:",r)}else!function(t,r){const n=t.limits.maxDependencies;if(0===n)return;const o=Object.keys(t.dependencies).length,{warn:i,error:a}=H(n);if(o===i)e.warn(`router.${r}`,`${i} dependencies registered. Consider if all are necessary.`);else if(o===a)e.error(`router.${r}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${n}.`);else if(o>=n)throw new Error(`[router.${r}] Dependency limit exceeded (${n}). Current: ${o}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}(t,"setDependency");t.dependencies[r]=n}(r.dependenciesGetStore(),t,n)},setAll:t=>{Dr(r.isDisposed);const n=r.dependenciesGetStore();r.noValidate||(hr(t,"setDependencies"),function(e,t,r,n=N.maxDependencies){if(0===n)return;const o=e+t;if(o>=n)throw new Error(`[router.${"setDependencies"}] Dependency limit exceeded (${n}). Current: ${o}. This is likely a bug in your code.`)}(Object.keys(n.dependencies).length,Object.keys(t).length,0,n.limits.maxDependencies)),function(t,r){const n=[];for(const e in r)void 0!==r[e]&&(Object.hasOwn(t.dependencies,e)&&n.push(e),t.dependencies[e]=r[e]);n.length>0&&e.warn("router.setDependencies","Overwritten:",n.join(", "))}(n,t)},remove:t=>{Dr(r.isDisposed),r.noValidate||fr(t,"removeDependency");const n=r.dependenciesGetStore();Object.hasOwn(n.dependencies,t)||e.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${g(t)}"`),delete n.dependencies[t]},reset:()=>{Dr(r.isDisposed),r.dependenciesGetStore().dependencies=Object.create(null)},has:e=>(r.noValidate||fr(e,"hasDependency"),Object.hasOwn(r.dependenciesGetStore().dependencies,e))}}function jr(e){if(e())throw new rr(w.ROUTER_DISPOSED)}function Fr(e){const t=J(e),r=t.routeGetStore().lifecycleNamespace;return{addActivateGuard(e,n){jr(t.isDisposed),t.noValidate||(m(e,"addActivateGuard"),he(n,"addActivateGuard")),r.addCanActivate(e,n,t.noValidate)},addDeactivateGuard(e,n){jr(t.isDisposed),t.noValidate||(m(e,"addDeactivateGuard"),he(n,"addDeactivateGuard")),r.addCanDeactivate(e,n,t.noValidate)},removeActivateGuard(e){jr(t.isDisposed),t.noValidate||m(e,"removeActivateGuard"),r.clearCanActivate(e)},removeDeactivateGuard(e){jr(t.isDisposed),t.noValidate||m(e,"removeDeactivateGuard"),r.clearCanDeactivate(e)}}}function xr(e,t){const r=J(e);if(r.isDisposed())throw new rr(w.ROUTER_DISPOSED);r.noValidate||function(e){if(void 0!==e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${g(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}(t);const n=r.routeGetStore(),o=[...n.tree.children.values()].map(e=>ot(e)),i=n.config,a=n.resolvedForwardMap,s=n.routeCustomFields,c=r.cloneOptions(),u=r.cloneDependencies(),[d,l]=r.getLifecycleFactories(),f=r.getPluginFactories(),h={...u,...t},p=new vr(o,c,h),m=Fr(p);for(const[e,t]of Object.entries(d))m.addDeactivateGuard(e,t);for(const[e,t]of Object.entries(l))m.addActivateGuard(e,t);f.length>0&&p.usePlugin(...f);const v=J(p).routeGetStore();return Object.assign(v.config.decoders,i.decoders),Object.assign(v.config.encoders,i.encoders),Object.assign(v.config.defaultParams,i.defaultParams),Object.assign(v.config.forwardMap,i.forwardMap),Object.assign(v.config.forwardFnMap,i.forwardFnMap),Object.assign(v.resolvedForwardMap,a),Object.assign(v.routeCustomFields,s),p}export{vr as Router,rr as RouterError,y as UNKNOWN_ROUTE,xr as cloneRouter,T as constants,yr as createRouter,w as errorCodes,R as events,Cr as getDependenciesApi,Fr as getLifecycleApi,Tr as getNavigator,br as getPluginApi,Nr as getRoutesApi};//# sourceMappingURL=index.mjs.map
1
+ import{logger as e}from"@real-router/logger";import{FSM as t}from"@real-router/fsm";var r={maxListeners:0,warnListeners:0,maxEventDepth:0},n=class extends Error{},o=class{#e=new Map;#t=null;#r=r;#n;#o;constructor(e){e?.limits&&(this.#r=e.limits),this.#n=e?.onListenerError??null,this.#o=e?.onListenerWarn??null}static validateCallback(e,t){if("function"!=typeof e)throw new TypeError(`Expected callback to be a function for event ${t}`)}setLimits(e){this.#r=e}on(e,t){const r=this.#i(e);if(r.has(t))throw new Error(`Duplicate listener for "${e}"`);const{maxListeners:n,warnListeners:o}=this.#r;if(0!==o&&r.size===o&&this.#o?.(e,o),0!==n&&r.size>=n)throw new Error(`Listener limit (${n}) reached for "${e}"`);return r.add(t),()=>{this.off(e,t)}}off(e,t){this.#e.get(e)?.delete(t)}emit(e,...t){const r=this.#e.get(e);r&&0!==r.size&&(0!==this.#r.maxEventDepth?this.#a(r,e,t):this.#s(r,e,t))}clearAll(){this.#e.clear(),this.#t=null}listenerCount(e){return this.#e.get(e)?.size??0}#s(e,t,r){const n=[...e];for(const e of n)try{this.#c(e,r)}catch(e){this.#n?.(t,e)}}#c(e,t){switch(t.length){case 0:e();break;case 1:e(t[0]);break;case 2:e(t[0],t[1]);break;case 3:e(t[0],t[1],t[2]);break;default:Function.prototype.apply.call(e,void 0,t)}}#a(e,t,r){this.#t??=new Map;const o=this.#t,i=o.get(t)??0;if(i>=this.#r.maxEventDepth)throw new n(`Maximum recursion depth (${this.#r.maxEventDepth}) exceeded for event: ${t}`);try{o.set(t,i+1);const a=[...e];for(const e of a)try{this.#c(e,r)}catch(e){if(e instanceof n)throw e;this.#n?.(t,e)}}finally{o.set(t,o.get(t)-1)}}#i(e){const t=this.#e.get(e);if(t)return t;const r=new Set;return this.#e.set(e,r),r}},i=["replace","reload","force","forceDeactivate","redirected"],a=/\S/,s=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function c(e,t){return new TypeError(`[router.${e}] ${t}`)}function u(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=>u(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=>u(e,t))}return!1}function d(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function l(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(!d(n)){const e=typeof n;if("function"===e||"symbol"===e)return!1;r=!0;break}}return!r||u(e)}function f(e){return"string"==typeof e}function h(e){return"boolean"==typeof e}function p(e,t){return e in t}function m(e,t){if("string"!=typeof e)throw c(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!a.test(e))throw c(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw c(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!s.test(e))throw c(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 g(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 v(e,t){if(!function(e){return"object"==typeof e&&null!==e&&function(e){return function(e){return"string"==typeof e&&(""===e||!(e.length>1e4)&&(!!e.startsWith("@@")||s.test(e)))}(e.name)&&"string"==typeof e.path&&l(e.params)}(e)}(e))throw new TypeError(`[${t}] Invalid state structure: ${g(e)}. Expected State object with name, params, and path properties.`)}var w=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",ROUTER_DISPOSED:"DISPOSED",PLUGIN_CONFLICT:"PLUGIN_CONFLICT"}),y="@@router/UNKNOWN_ROUTE",b={UNKNOWN_ROUTE:y},S="onStart",T="onStop",E="onTransitionStart",O="onTransitionCancel",P="onTransitionSuccess",A="onTransitionError",R={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},$=new Set([R.ROUTER_START,R.TRANSITION_START,R.TRANSITION_SUCCESS,R.TRANSITION_ERROR,R.TRANSITION_CANCEL,R.ROUTER_STOP]),N={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},D={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxListeners:{min:0,max:1e5},warnListeners:{min:0,max:1e5},maxEventDepth:{min:0,max:100},maxLifecycleHandlers:{min:0,max:1e4}},C="IDLE",j="STARTING",F="READY",x="TRANSITIONING",I="DISPOSED",L="START",M="STARTED",_="NAVIGATE",k="COMPLETE",U="FAIL",B="CANCEL",G="STOP",V="DISPOSE",z={initial:C,context:null,transitions:{[C]:{[L]:j,[V]:I},[j]:{[M]:F,[U]:C},[F]:{[_]:x,[U]:F,[G]:C},[x]:{[_]:x,[k]:F,[B]:F,[U]:F},[I]:{}}},q=new WeakSet;function W(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)W(t);else for(const t in e)W(e[t])}function Q(e){return e?(q.has(e)||(W(e),q.add(e)),e):e}function H(e){return{warn:Math.floor(.2*e),error:Math.floor(.5*e)}}var K=new WeakMap;function J(e){const t=K.get(e);if(!t)throw new TypeError("[real-router] Invalid router instance — not found in internals registry");return t}function Y(e,t,r){return(...n)=>{const o=r.get(e);return o&&0!==o.length?function(e,t,r){let n=t;for(const t of e){const e=n;n=(...r)=>t(e,...r)}return n(...r)}(o,t,n):t(...n)}}var Z={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},X={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},ee={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function te(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&te(r)}return e}function re(e,t){return"function"==typeof e?e(t):e}function ne(e,t,r){if("function"==typeof t&&("defaultRoute"===e||"defaultParams"===e))return;const n=Z[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 ${g(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(!p(r,ee)){const e=Object.keys(ee).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],o=ee[r];if(!o.includes(n)){const e=o.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 X&&function(e,t,r){const n=X[e];if(!n.includes(t)){const o=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${o}, got "${String(t)}"`)}}(e,t,r)}function oe(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(D,r))throw new TypeError(`[router.${t}]: unknown limit: "${r}"`);void 0!==n&&ie(r,n,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function ie(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=D[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 ae=class{#u;constructor(e={}){this.#u=te({...Z,...e})}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 ${g(e)}`);for(const[r,n]of Object.entries(e))p(r,Z)?void 0!==n&&ne(r,n,t):oe(r,n,t)}(e,t)}get(){return this.#u}};function se(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>se(e,t[r]))}var ce=class{#d=0;#l=void 0;#f=void 0;#h;#p=new Map;static validateAreStatesEqualArgs(e,t,r){if(null!=e&&v(e,"areStatesEqual"),null!=t&&v(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${g(r)}. Expected boolean.`)}get(){return this.#l}set(e){this.#f=this.#l,this.#l=e?Q(e):void 0}getPrevious(){return this.#f}reset(){this.#l=void 0,this.#f=void 0,this.#p.clear(),this.#d=0}setDependencies(e){this.#h=e}makeState(e,t,r,n,o){const i=n?{...n,id:o??++this.#d,params:n.params}:void 0,a=this.#h.getDefaultParams();let s;return s=Object.hasOwn(a,e)?{...a[e],...t}:t?{...t}:{},Q({name:e,params:s,path:r??this.#h.buildPath(e,t),meta:i})}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=>se(e.params[r],t.params[r]))}const n=Object.keys(e.params),o=Object.keys(t.params);return n.length===o.length&&n.every(r=>r in t.params&&se(e.params[r],t.params[r]))}#m(e){const t=this.#p.get(e);if(void 0!==t)return t;const r=this.#h.getUrlParams(e);return this.#p.set(e,r),r}},ue={[S]:R.ROUTER_START,[T]:R.ROUTER_STOP,[P]:R.TRANSITION_SUCCESS,[E]:R.TRANSITION_START,[A]:R.TRANSITION_ERROR,[O]:R.TRANSITION_CANCEL},de=Object.keys(ue).filter(e=>p(e,ue)),le="router.usePlugin",fe=class t{#g=new Set;#v=new Set;#h;#w=N;static validateUsePluginArgs(e){!function(e){for(const[t,r]of e.entries())if("function"!=typeof r)throw new TypeError(`[router.usePlugin] Expected plugin factory function at index ${t}, got ${g(r)}`)}(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 ${g(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&&!p(t,ue))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=N.maxPlugins){if(0!==r&&e+t>r)throw new Error(`[router.usePlugin] Plugin limit exceeded (${r}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`)}(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.")}setDependencies(e){this.#h=e}setLimits(e){this.#w=e}count(){return this.#g.size}use(...t){if(this.#y(t.length),1===t.length){const r=t[0],n=this.#b(r);this.#g.add(r);let o=!1;const i=()=>{if(!o){o=!0,this.#g.delete(r),this.#v.delete(i);try{n()}catch(t){e.error(le,"Error during cleanup:",t)}}};return this.#v.add(i),i}const r=this.#S(t),n=[];try{for(const e of r){const t=this.#b(e);n.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){e.error(le,"Cleanup error:",t)}throw t}for(const{factory:e}of n)this.#g.add(e);let o=!1;const i=()=>{if(!o){o=!0,this.#v.delete(i);for(const{factory:e}of n)this.#g.delete(e);for(const{cleanup:t}of n)try{t()}catch(t){e.error(le,"Error during cleanup:",t)}}};return this.#v.add(i),i}getAll(){return[...this.#g]}has(e){return this.#g.has(e)}disposeAll(){for(const e of this.#v)e();this.#g.clear(),this.#v.clear()}#y(t){const r=this.#w.maxPlugins;if(0===r)return;const n=t+this.#g.size,{warn:o,error:i}=H(r);n>=i?e.error(le,`${n} plugins registered! This is excessive and will impact performance. Hard limit at ${r}.`):n>=o&&e.warn(le,`${n} plugins registered. Consider if all are necessary.`)}#S(t){const r=new Set;for(const n of t)r.has(n)?e.warn(le,"Duplicate factory in batch, will be registered once"):r.add(n);return r}#b(r){const n=this.#h.compileFactory(r);t.validatePlugin(n),Object.freeze(n);const o=[];for(const t of de)t in n&&("function"==typeof n[t]?(o.push(this.#h.addEventListener(ue[t],n[t])),"onStart"===t&&this.#h.canNavigate()&&e.warn(le,"Router already started, onStart will not be called")):e.warn(le,`Property '${t}' is not a function, skipping`));return()=>{for(const e of o)e();"function"==typeof n.teardown&&n.teardown()}}};function he(e,t){if(!h(e)&&"function"!=typeof e)throw new TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${g(e)}`)}function pe(e,t,r){if(e)throw new Error(`[router.${r}] Cannot modify route "${t}" during its own registration`)}function me(e,t,r=N.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 plugins for cross-cutting concerns.`)}var ge=class{#T=new Map;#E=new Map;#O=new Map;#P=new Map;#A=new Set;#R=new Set;#$=new Set;#h;#w=N;setDependencies(e){this.#h=e}setLimits(e){this.#w=e}addCanActivate(e,t,r,n=!1){n?this.#R.add(e):this.#R.delete(e),r||pe(this.#A.has(e),e,"addActivateGuard");const o=this.#E.has(e);o||r||me(this.#E.size+1,"addActivateGuard",this.#w.maxLifecycleHandlers),this.#N("activate",e,t,this.#E,this.#P,"canActivate",o)}addCanDeactivate(e,t,r,n=!1){n?this.#$.add(e):this.#$.delete(e),r||pe(this.#A.has(e),e,"addDeactivateGuard");const o=this.#T.has(e);o||r||me(this.#T.size+1,"addDeactivateGuard",this.#w.maxLifecycleHandlers),this.#N("deactivate",e,t,this.#T,this.#O,"canDeactivate",o)}clearCanActivate(e){this.#E.delete(e),this.#P.delete(e),this.#R.delete(e)}clearCanDeactivate(e){this.#T.delete(e),this.#O.delete(e),this.#$.delete(e)}clearAll(){this.#E.clear(),this.#P.clear(),this.#T.clear(),this.#O.clear(),this.#R.clear(),this.#$.clear()}clearDefinitionGuards(){for(const e of this.#R)this.#E.delete(e),this.#P.delete(e);for(const e of this.#$)this.#T.delete(e),this.#O.delete(e);this.#R.clear(),this.#$.clear()}getFactories(){const e={},t={};for(const[t,r]of this.#T)e[t]=r;for(const[e,r]of this.#E)t[e]=r;return[e,t]}getFunctions(){return[this.#O,this.#P]}canNavigateTo(e,t,r,n){for(const t of e)if(!this.#D(this.#O,t,r,n,"canNavigateTo"))return!1;for(const e of t)if(!this.#D(this.#P,e,r,n,"canNavigateTo"))return!1;return!0}#N(t,r,n,o,i,a,s){s?e.warn(`router.${a}`,`Overwriting existing ${t} handler for route "${r}"`):this.#y(o.size+1,a);const c=h(n)?function(e){const t=()=>e;return()=>t}(n):n;o.set(r,c),this.#A.add(r);try{const e=this.#h.compileFactory(c);if("function"!=typeof e)throw new TypeError(`[router.${a}] Factory must return a function, got ${g(e)}`);i.set(r,e)}catch(e){throw o.delete(r),e}finally{this.#A.delete(r)}}#D(t,r,n,o,i){const a=t.get(r);if(!a)return!0;try{const t=a(n,o);return"boolean"==typeof t?t:(e.warn(`router.${i}`,`Guard for "${r}" returned a Promise. Sync check cannot resolve async guards — returning false.`),!1)}catch{return!1}}#y(t,r){const n=this.#w.maxLifecycleHandlers;if(0===n)return;const{warn:o,error:i}=H(n);t>=i?e.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at ${n}.`):t>=o&&e.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}},ve=new Set;function we(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function ye(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>ye(e))),t}function be(e,t,r=""){for(let n=0;n<e.length;n++){const o=e[n],i=r?`${r}.${o.name}`:o.name;if(i===t)return e.splice(n,1),!0;if(o.children&&t.startsWith(`${i}.`)&&be(o.children,t,i))return!0}return!1}function Se(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function Te(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var Ee=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,Oe=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,Pe=/\?(.+)$/,Ae=/[^\w!$'()*+,.:;|~-]/gu,Re=/[^\w!$'()*+,.:;|~-]/u,$e={default:e=>Re.test(e)?e.replaceAll(Ae,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},Ne={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function De(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function Ce(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function je(e){const t={};if(0===e.length)return t;const r=e.split("&");for(const e of r){const r=e.indexOf("=");-1===r?t[e]="":t[e.slice(0,r)]=e.slice(r+1)}return t}function Fe(e){const t=[];for(const r of Object.keys(e)){const n=e[r],o=encodeURIComponent(r);t.push(""===n?o:`${o}=${encodeURIComponent(String(n))}`)}return t.join("&")}function xe(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function Ie(e){let t=0;for(;t<e.length;)if("%"===e[t]){if(t+2>=e.length)return!1;const r=e.codePointAt(t+1)??0,n=e.codePointAt(t+2)??0;if(!xe(r)||!xe(n))return!1;t+=3}else t++;return!0}var Le=/<[^>]*>/g;function Me(e,t,r,n,o){const i=""===t.fullName;i||n.push(t);const a=t.absolute,s=t.paramMeta.pathPattern,c=a&&s.startsWith("~")?s.slice(1):s,u=(a?c:s).replaceAll(Le,""),d=a?u:(f=u,""===(l=r)?f:""===f?l:l+f);var l,f;let h=o;i||(h=function(e,t,r,n,o,i){const a=(g=n,Ce(r)===Ce(g)),s=Object.freeze([...o]),c=function(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return Object.freeze(t)}(s),u=Ce(r),d=function(e,t){const r=[];e.length>0&&r.push(...e);for(const e of t)e.paramMeta.queryParams.length>0&&r.push(...e.paramMeta.queryParams);return r}(e.rootQueryParams,o),l=function(e){const t=new Map;for(const r of e)for(const[e,n]of r.paramMeta.constraintPatterns)t.set(e,n);return t}(o),f=a?Ce(n):u,{buildStaticParts:h,buildParamSlots:p}=function(e,t,r){const n=new Set,o=new Set;for(const e of t){for(const t of e.paramMeta.urlParams)n.add(t);for(const t of e.paramMeta.spatParams)o.add(t)}if(0===n.size)return{buildStaticParts:[e],buildParamSlots:[]};const i=[],a=[],s=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,u=0;for(;null!==(c=s.exec(e));){const t=c[1],n="?"===c[2];i.push(e.slice(u,c.index));const s=o.has(t);a.push({paramName:t,isOptional:n,encoder:s?e=>{const t=$e[r],n=e.split("/");let o=t(n[0]);for(let e=1;e<n.length;e++)o+=`/${t(n[e])}`;return o}:$e[r]}),u=c.index+c[0].length}return i.push(e.slice(u)),{buildStaticParts:i,buildParamSlots:a}}(f,a?o.slice(0,-1):o,e.options.urlParamsEncoding),m={name:t.fullName,parent:i,depth:o.length-1,matchSegments:s,meta:c,declaredQueryParams:d,declaredQueryParamsSet:new Set(d),hasTrailingSlash:r.length>1&&r.endsWith("/"),constraintPatterns:l,hasConstraints:l.size>0,buildStaticParts:h,buildParamSlots:p,buildParamNamesSet:new Set(p.map(e=>e.paramName))};var g;return e.routesByName.set(t.fullName,m),e.segmentsByName.set(t.fullName,s),e.metaByName.set(t.fullName,c),a?function(e,t,r){var n,o;n=t,(function(e,t,r){const n=Ce(r);if("/"===n||""===n)return t;let o=t,i=1;const a=n.length;for(;i<=a;){const t=n.indexOf("/",i),r=-1===t?a:t;if(r<=i)break;o=ke(e,o,n.slice(i,r)),i=r+1}return o}(o=e,o.root,r)).slashChildRoute=n;const i=Ce(r),a=e.options.caseSensitive?i:i.toLowerCase();e.staticCache.has(a)&&e.staticCache.set(a,t)}(e,m,n):function(e,t,r,n,o){if(function(e,t,r){const n=Ce(r);"/"!==n?_e(e,e.root,n,1,t):e.root.route=t}(e,t,r),0===o.paramMeta.urlParams.length){const r=e.options.caseSensitive?n:n.toLowerCase();e.staticCache.set(r,t)}}(e,m,r,u,t),m}(e,t,d,a?"":r,n,o));for(const r of t.children.values())Me(e,r,d,n,h);i||n.pop()}function _e(e,t,r,n,o){const i=r.length;for(;n<=i;){const a=r.indexOf("/",n),s=-1===a?i:a,c=r.slice(n,s);if(c.endsWith("?")){const n=c.slice(1).replaceAll(Le,"").replace(/\?$/,"");return t.paramChild??={node:De(),name:n},_e(e,t.paramChild.node,r,s+1,o),void(s>=i?t.route??=o:_e(e,t,r,s+1,o))}t=ke(e,t,c),n=s+1}t.route=o}function ke(e,t,r){if(r.startsWith("*")){const e=r.slice(1);return t.splatChild??={node:De(),name:e},t.splatChild.node}if(r.startsWith(":")){const e=r.slice(1).replaceAll(Le,"").replace(/\?$/,"");return t.paramChild??={node:De(),name:e},t.paramChild.node}const n=e.options.caseSensitive?r:r.toLowerCase();return n in t.staticChildren||(t.staticChildren[n]=De()),t.staticChildren[n]}var Ue=/[\u0080-\uFFFF]/,Be=class{get options(){return this.#e}#e;#t=De();#o=new Map;#i=new Map;#r=new Map;#a=new Map;#n="";#C=[];constructor(e){this.#e={caseSensitive:e?.caseSensitive??!0,strictTrailingSlash:e?.strictTrailingSlash??!1,strictQueryParams:e?.strictQueryParams??!1,urlParamsEncoding:e?.urlParamsEncoding??"default",parseQueryString:e?.parseQueryString??je,buildQueryString:e?.buildQueryString??Fe}}registerTree(e){this.#C=e.paramMeta.queryParams,Me({root:this.#t,options:this.#e,routesByName:this.#o,segmentsByName:this.#i,metaByName:this.#r,staticCache:this.#a,rootQueryParams:this.#C},e,"",[],null)}match(e){const t=this.#s(e);if(!t)return;const[r,n,o]=t,i=this.#e.caseSensitive?n:n.toLowerCase(),a=this.#a.get(i);if(a){if(this.#e.strictTrailingSlash&&!this.#c(r,a))return;return this.#j(a,{},o)}const s={},c=this.#F(n,s);return!c||this.#e.strictTrailingSlash&&!this.#c(r,c)||c.hasConstraints&&!this.#x(s,c)||!this.#I(s)?void 0:this.#j(c,s,o)}buildPath(e,t,r){const n=this.#o.get(e);if(!n)throw new Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);n.hasConstraints&&t&&this.#L(n,e,t);const o=this.#M(n,t),i=this.#_(o,r?.trailingSlash),a=this.#k(n,t,r?.queryParamsMode);return i+(a?`?${a}`:"")}getSegmentsByName(e){return this.#i.get(e)}getMetaByName(e){return this.#r.get(e)}hasRoute(e){return this.#o.has(e)}setRootPath(e){this.#n=e}#L(e,t,r){for(const[n,o]of e.constraintPatterns){const e=r[n];if(null!=e){const r="object"==typeof e?JSON.stringify(e):String(e);if(!o.pattern.test(r))throw new Error(`[SegmentMatcher.buildPath] '${t}' — param '${n}' value '${r}' does not match constraint '${o.constraint}'`)}}}#M(e,t){const r=e.buildStaticParts,n=e.buildParamSlots;if(0===n.length)return this.#n+r[0];let o=this.#n+r[0];for(const[e,i]of n.entries()){const n=t?.[i.paramName];if(null==n){if(!i.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${i.paramName}'`);o.length>1&&o.endsWith("/")&&(o=o.slice(0,-1)),o+=r[e+1];continue}const a="object"==typeof n?JSON.stringify(n):String(n);o+=i.encoder(a)+r[e+1]}return o}#_(e,t){return"always"!==t||e.endsWith("/")?"never"===t&&"/"!==e&&e.endsWith("/")?e.slice(0,-1):e:`${e}/`}#k(e,t,r){if(!t)return"";const n={};let o=!1;for(const r of e.declaredQueryParams)r in t&&(n[r]=t[r],o=!0);if("loose"===r)for(const r in t)!Object.hasOwn(t,r)||e.declaredQueryParamsSet.has(r)||e.buildParamNamesSet.has(r)||(n[r]=t[r],o=!0);return o?this.#e.buildQueryString(n):""}#s(e){if(""===e&&(e="/"),!e.startsWith("/"))return;const t=e.indexOf("#");if(-1!==t&&(e=e.slice(0,t)),Ue.test(e))return;if(this.#n.length>0){if(!e.startsWith(this.#n))return;e=e.slice(this.#n.length)||"/"}const r=e.indexOf("?"),n=-1===r?e:e.slice(0,r),o=-1===r?void 0:e.slice(r+1);return n.includes("//")?void 0:[n,Ce(n),o]}#j(e,t,r){if(void 0!==r){const n=this.#e.parseQueryString(r);if(this.#e.strictQueryParams){const t=e.declaredQueryParamsSet;for(const e of Object.keys(n))if(!t.has(e))return}for(const e of Object.keys(n))t[e]=n[e]}return{segments:e.matchSegments,params:t,meta:e.meta}}#c(e,t){return(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#F(e,t){return 1===e.length?this.#t.slashChildRoute??this.#t.route:this.#U(this.#t,e,1,t)}#U(e,t,r,n){let o=e;const i=t.length;for(;r<=i;){const e=t.indexOf("/",r),a=-1===e?i:e,s=t.slice(r,a),c=this.#e.caseSensitive?s:s.toLowerCase();let u;if(c in o.staticChildren)u=o.staticChildren[c];else{if(!o.paramChild){if(o.splatChild){const e={},i=this.#U(o.splatChild.node,t,r,e);return i?(Object.assign(n,e),i):(n[o.splatChild.name]=t.slice(r),o.splatChild.node.route)}return}u=o.paramChild.node,n[o.paramChild.name]=s}o=u,r=a+1}return o.slashChildRoute??o.route}#I(e){const t=this.#e.urlParamsEncoding;if("none"===t)return!0;const r=Ne[t];for(const t in e){const n=e[t];if(n.includes("%")){if(!Ie(n))return!1;e[t]=r(n)}}return!0}#x(e,t){for(const[r,n]of t.constraintPatterns)if(!n.pattern.test(e[r]))return!1;return!0}},Ge=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)},Ve=e=>{const t=typeof e;if("string"!==t&&"number"!==t&&"boolean"!==t)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===t&&null===e?"null":t}`);return encodeURIComponent(e)},ze={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${Ve(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${Ve(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${Ve(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>Ve(e)).join(",")}`}},qe={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}},We={default:{encode:e=>e},hidden:{encode:()=>""}},Qe=(e,t,r)=>({boolean:qe[t],null:We[r],array:ze[e]}),He={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:qe.none,null:We.default,array:ze.none}},Ke=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return He;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:Qe(t,r,n)}},Je=e=>encodeURIComponent(e),Ye=(e,t,r)=>{const n=Je(e);switch(typeof t){case"string":case"number":default:return`${n}=${Je(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}=${Je(t)}`}};function Ze(e,t,r,n,o){const i=e.indexOf("=",t),a=-1!==i&&i<r,s=e.slice(t,a?i:r),{name:c,hasBrackets:u}=function(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}(s);var d,l,f,h,p;!function(e,t,r,n){const o=e[t];void 0===o?e[t]=n?[r]:r:Array.isArray(o)?o.push(r):e[t]=[o,r]}(n,Ge(c),(d=e,l=i,f=r,h=a,p=o,p?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const n=Ge(e);return t.boolean.decodeValue(n)})(h?d.slice(l+1,f):void 0,p):h?Ge(d.slice(l+1,f)):null),u)}function Xe(e,t){const r=e.path,n=r.startsWith("~"),o=n?r.slice(1):r,i={name:e.name,path:o,absolute:n,children:[],parent:t,nonAbsoluteChildren:[],fullName:""};if(e.children)for(const t of e.children){const e=Xe(t,i);i.children.push(e)}return i}function et(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function tt(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}function rt(e,t,r){const n=function(e){const t=[],r=[],n=[],o={},i=new Map,a=e.replaceAll(Oe,"$1"),s=Pe.exec(a);if(null!==s){const t=s[1].split("&");for(const e of t){const t=e.trim();t.length>0&&(r.push(t),o[t]="query")}e=e.slice(0,s.index)}let c;for(;null!==(c=Ee.exec(e));){const e=c[2],r=c[3];if("*"===c[1])n.push(e),t.push(e),o[e]="url";else if(t.push(e),o[e]="url",r){const t=`^${Te(r)}$`;i.set(e,{pattern:new RegExp(t),constraint:r})}}return{urlParams:t,queryParams:r,spatParams:n,paramTypeMap:o,constraintPatterns:i,pathPattern:e}}(e.path),o=function(e){const t={};for(const r of e.urlParams)t[r]="url";for(const r of e.queryParams)t[r]="query";return t}(n),i={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:void 0,paramMeta:n,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:o};var a;i.fullName=(a=i,a.parent?.name?`${a.parent.fullName}.${a.name}`:a.name);const{childrenMap:s,nonAbsoluteChildren:c}=function(e,t,r){const n=[],o=[];for(const i of e){const e=rt(i,t,r);n.push(e),e.absolute||o.push(e)}return{childrenMap:tt(n),nonAbsoluteChildren:o}}(e.children,i,r);return i.children=s,i.nonAbsoluteChildren=c,i.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 o=[];let i=e.parent;for(;i?.path;)o.unshift(i),i=i.parent;let a="";for(const e of o){const{urlParams:t,queryParams:r,spatParams:n}=e.paramMeta;if(t.length>0||r.length>0||n.length>0)return null;a=e.absolute?e.path:et(a,e.path)}return e.absolute?e.path:et(a,e.path)}(i),r&&(Object.freeze(c),Object.freeze(o),Object.freeze(i.children),Object.freeze(i)),i}function nt(e,t,r,n){return function(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build:n=>function(e,t=!0){return rt(e,null,t)}(function(e,t,r){const n=Xe({name:e,path:t},null);for(const e of r){const t=Xe(e,n);n.children.push(t)}return n}(e,t,r),!n?.skipFreeze)}}(e,t).addMany(r).build(n)}function ot(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=>ot(e))),t}function it(e){const t=e?.queryParams;return new Be({...void 0===e?.caseSensitive?void 0:{caseSensitive:e.caseSensitive},...void 0===e?.strictTrailingSlash?void 0:{strictTrailingSlash:e.strictTrailingSlash},...void 0===e?.strictQueryParams?void 0:{strictQueryParams:e.strictQueryParams},...void 0===e?.urlParamsEncoding?void 0:{urlParamsEncoding:e.urlParamsEncoding},parseQueryString:e=>((e,t)=>{const r=(e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)})(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return function(e,t){let r=0;const n=e.length;for(;r<n;){let o=e.indexOf("&",r);-1===o&&(o=n),Ze(e,r,o,t),r=o+1}}(e,t),t}(r);const n=Ke(t),o={};let i=0;const a=r.length;for(;i<a;){let e=r.indexOf("&",i);-1===e&&(e=a),Ze(r,i,e,o,n.strategies),i=e+1}return o})(e,t),buildQueryString:e=>((e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=Ke(t),o=[];for(const t of r){const r=e[t];if(void 0===r)continue;const i=Ye(t,r,n);i&&o.push(i)}return o.join("&")})(e,t)})}function at(e,t){return new TypeError(`[router.${e}] ${t}`)}var st=/^[A-Z_a-z][\w-]*$/,ct=/\S/;function ut(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function dt(e,t){if(!t.includes("."))return e.children.get(t);let r=e;for(const e of t.split("."))if(r=r.children.get(e),!r)return;return r}function lt(e,t,r,n="",o,i){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${ut(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${ut(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 a=e;!function(e,t){if("string"!=typeof e.name)throw new TypeError(`[router.${t}] Route name must be a string, got ${ut(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!ct.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("@@")){if(r.includes("."))throw new TypeError(`[router.${t}] Route name "${r}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(!st.test(r))throw new TypeError(`[router.${t}] Invalid route name "${r}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}}(a,t),function(e,t,r,n){if("string"!=typeof e){let t;throw t=null===e?"null":Array.isArray(e)?"array":typeof e,at(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw at(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw at(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw at(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const o=n&&Object.values(n.paramTypeMap).includes("url");if(e.startsWith("~")&&o)throw at(r,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}(a.path,a.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`)}(a,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`)}(a,t);const s=a.name,c=n?`${n}.${s}`:s;r&&c&&function(e,t,r){if(dt(e,t))throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),o&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(o,c,t);const u=a.path,d=n;if(r&&function(e,t,r,n){const o=""===t?e:dt(e,t);if(o)for(const e of o.children.values())if(e.path===r)throw new Error(`[router.${n}] Path "${r}" is already defined`)}(r,d,u,t),i&&function(e,t,r,n){const o=e.get(t);if(o?.has(r))throw new Error(`[router.${n}] Path "${r}" is already defined`);o?o.add(r):e.set(t,new Set([r]))}(i,d,u,t),void 0!==a.children){if(!Array.isArray(a.children))throw new TypeError(`[router.${t}] Route "${s}" children must be an array, got ${ut(a.children)}`);for(const e of a.children)lt(e,t,r,c,o,i)}}function ft(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 ${g(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 ${g(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 ${g(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(function(e,t){if(void 0!==e&&"function"==typeof e){const r="AsyncFunction"===e.constructor.name,n=e.toString().includes("__awaiter");if(r||n)throw new TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`)}}(e.forwardTo,t),e.children)for(const r of e.children)ft(r,`${t}.${r.name}`)}function ht(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 pt(e){const t=new Set;for(const r of e)for(const e of ht(r))t.add(e);return t}function mt(e,t,r="",n=[]){for(const o of e){const e=r?`${r}.${o.name}`:o.name,i=[...n,o.path];if(e===t)return i;if(o.children&&t.startsWith(`${e}.`))return mt(o.children,t,e,i)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function gt(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 gt(n.children,e))r.add(t)}return r}function vt(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&"string"==typeof n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,o]of vt(n.children,e))r.set(t,o)}return r}function wt(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}(function(e,t){const r=[],n=t.includes(".")?t.split("."):[t];""!==e.path&&r.push(e);let o=e;for(const e of n){const t=o.children.get(e);if(!t)return null;r.push(t),o=t}return r}(r,e)):pt(mt(n,e))}function yt(e,t,r,n,o){const i=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}(o,t),a=n.has(t);if(!i&&!a)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const s=pt(mt(r,e)),c=[...wt(t,i,o,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 bt(e,t,r=100){const n=new Set,o=[e];let i=e;for(;t[i];){const e=t[i];if(n.has(e)){const t=o.indexOf(e),r=[...o.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(i),o.push(e),i=e,o.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${o.join(" → ")}`)}return i}function St(e,t,r){const n=gt(e),o=vt(e),i={...t};for(const[e,t]of o)i[e]=t;for(const[t,i]of o)yt(t,i,e,n,r);for(const e of Object.keys(i))bt(e,i)}function Tt(e,t){if(e.startsWith("@@"))throw new Error(`[router.${t}] Route name "${e}" uses the reserved "@@" prefix. Routes with this prefix are internal and cannot be modified through the public API.`)}function Et(e,t){for(const r of e)r&&"object"==typeof r&&"string"==typeof r.name&&(Tt(r.name,t),r.children&&Et(r.children,t))}function Ot(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 ${g(t)}`);ft(t,t.name)}}function Pt(e,t,r){if(!f(e))throw new TypeError(`[router.${r}] Invalid routeName: ${g(e)}. Expected string.`);if(!l(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${g(t)}. Expected plain object.`)}function At(e,t){if("AsyncFunction"===e.constructor.name||e.toString().includes("__awaiter"))throw new TypeError(`[real-router] updateRoute: ${t} cannot be an async function`)}function Rt(e,t){if(null!=e){if("function"!=typeof e)throw new TypeError(`[real-router] updateRoute: ${t} must be a function or null, got ${typeof e}`);At(e,t)}}function $t(e,t,r,n){if(n&&t){let e=t;for(const t of n.split("."))if(e=e.children.get(t),!e)throw new Error(`[router.addRoute] Parent route "${n}" does not exist`)}const o=new Set,i=new Map;for(const r of e)lt(r,"addRoute",t,n??"",o,i);t&&r&&St(e,r,t)}function Nt(t){return!t||(e.error("router.clearRoutes","Cannot clear routes while navigation is in progress. Wait for navigation to complete."),!1)}function Dt(e,t,r,n,o){if(!r(e))throw new ReferenceError(`[real-router] updateRoute: route "${e}" does not exist`);if(null!=t&&"string"==typeof t){if(!r(t))throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);(function(e,t,r){const n=r.getSegmentsByName(e),o=r.getSegmentsByName(t),i=function(e){const t=new Set;for(const r of e)for(const e of r.paramMeta.urlParams)t.add(e);return t}(n),a=[];for(const e of o)for(const t of e.paramMeta.urlParams)a.push(t);const s=a.filter(e=>!i.has(e));if(s.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${s.join(", ")}] that are not available in source route "${e}"`)})(e,t,n),function(e,t,r){bt(e,{...r.forwardMap,[e]:t})}(e,t,o)}}function Ct(e,t,r){const n=nt("",t,e),o=it(r);return o.registerTree(n),{tree:n,matcher:o}}function jt(e,t){const r=Ct(e.definitions,e.rootPath,e.matcherOptions);e.tree=r.tree,e.matcher=r.matcher,e.resolvedForwardMap=Lt(e.config,t)}function Ft(e){const t=Ct(e.definitions,e.rootPath,e.matcherOptions);e.tree=t.tree,e.matcher=t.matcher}function xt(e){It(e),Ft(e)}function It(e){e.definitions.length=0,Object.assign(e.config,we()),e.resolvedForwardMap=Object.create(null),e.routeCustomFields=Object.create(null)}function Lt(e,t){return t?_t(e):Mt(e)}function Mt(e){const t=Object.create(null);for(const r of Object.keys(e.forwardMap))t[r]=bt(r,e.forwardMap);return t}function _t(e){const t=Object.create(null);for(const r of Object.keys(e.forwardMap)){let n=r;for(;e.forwardMap[n];)n=e.forwardMap[n];t[r]=n}return t}function kt(t,r,n,o,i,a,s){const c=new Set(["name","path","children","canActivate","canDeactivate","forwardTo","encodeParams","decodeParams","defaultParams"]),u=Object.fromEntries(Object.entries(t).filter(([e])=>!c.has(e)));Object.keys(u).length>0&&(o[r]=u),t.canActivate&&(s?s.addActivateGuard(r,t.canActivate):i.set(r,t.canActivate)),t.canDeactivate&&(s?s.addDeactivateGuard(r,t.canDeactivate):a.set(r,t.canDeactivate)),t.forwardTo&&function(t,r,n){if(t.canActivate&&e.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 "${"string"==typeof t.forwardTo?t.forwardTo:"[dynamic]"}".`),t.canDeactivate&&e.warn("real-router",`Route "${r}" has both forwardTo and canDeactivate. canDeactivate will be ignored because forwardTo creates a redirect (industry standard). Move canDeactivate to the target route "${"string"==typeof t.forwardTo?t.forwardTo:"[dynamic]"}".`),"function"==typeof t.forwardTo){const e="AsyncFunction"===t.forwardTo.constructor.name,n=t.forwardTo.toString().includes("__awaiter");if(e||n)throw new TypeError(`forwardTo callback cannot be async for route "${r}". Async functions break matchPath/buildPath.`)}"string"==typeof t.forwardTo?n.forwardMap[r]=t.forwardTo:n.forwardFnMap[r]=t.forwardTo}(t,r,n),t.decodeParams&&(n.decoders[r]=e=>t.decodeParams?.(e)??e),t.encodeParams&&(n.encoders[r]=e=>t.encodeParams?.(e)??e),t.defaultParams&&(n.defaultParams[r]=t.defaultParams)}function Ut(e,t,r,n,o,i,a=""){for(const s of e){const e=a?`${a}.${s.name}`:s.name;kt(s,e,t,r,n,o,i),s.children&&Ut(s.children,t,r,n,o,i,e)}}var Bt,Gt,Vt=".";function zt(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function qt(e){const t=typeof e;return"string"===t||"number"===t||"boolean"===t}function Wt(e,t,r){const n=t.meta?.params[e];if(!n||"object"!=typeof n)return!0;for(const e of Object.keys(n)){const n=t.params[e],o=r.params[e];if(qt(n)&&qt(o)&&String(n)!==String(o))return!1}return!0}function Qt(e){if(!e)return[""];const t=e.indexOf(Vt);if(-1===t)return[e];const r=e.indexOf(Vt,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(Vt,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(Vt,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(Vt),r=t.length,n=[t[0]];let o=t[0].length;for(let i=1;i<r-1;i++)o+=1+t[i].length,n.push(e.slice(0,o));return n.push(e),n}(e)}var Ht=null;function Kt(e,t){if(!t)return{intersection:"",toActivate:Qt(e.name),toDeactivate:[]};if(void 0===e.meta?.params&&void 0===t.meta?.params)return{intersection:"",toActivate:Qt(e.name),toDeactivate:zt(Qt(t.name))};const r=Qt(e.name),n=Qt(t.name),o=function(e,t,r,n,o){for(let i=0;i<o;i++){const o=r[i];if(o!==n[i])return i;if(!Wt(o,e,t))return i}return o}(e,t,r,n,Math.min(n.length,r.length)),i=[];for(let e=n.length-1;e>=o;e--)i.push(n[e]);const a=r.slice(o);return{intersection:o>0?n[o-1]:"",toDeactivate:i,toActivate:a}}function Jt(e,t,r){if(r?.reload)return Kt(e,t);if(null!==Ht&&e===Bt&&t===Gt)return Ht;const n=Kt(e,t);return Bt=e,Gt=t,Ht=n,n}function Yt(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}var Zt=class{#B;get#h(){return this.#B.depsStore}constructor(e=[],t=!1,r){this.#B=function(e,t,r){const n=[],o=we(),i=Object.create(null),a=new Map,s=new Map;for(const t of e)n.push(ye(t));const{tree:c,matcher:u}=Ct(n,"",r);return Ut(e,o,i,a,s,void 0,""),{definitions:n,config:o,tree:c,matcher:u,resolvedForwardMap:t?_t(o):Mt(o),routeCustomFields:i,rootPath:"",matcherOptions:r,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:a,pendingCanDeactivate:s,treeOperations:{commitTreeChanges:jt,resetStore:xt,nodeToDefinition:ot,validateRoutes:$t}}}(e,t,r)}static 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.transition?.reload)return!0;if(""===e&&!r)return!0;const{intersection:n,toActivate:o,toDeactivate:i}=Jt(t,r);return e===n||!!o.includes(e)||i.includes(e)}}setDependencies(e){this.#B.depsStore=e;for(const[t,r]of this.#B.pendingCanActivate)e.addActivateGuard(t,r);this.#B.pendingCanActivate.clear();for(const[t,r]of this.#B.pendingCanDeactivate)e.addDeactivateGuard(t,r);this.#B.pendingCanDeactivate.clear()}setLifecycleNamespace(e){this.#B.lifecycleNamespace=e}setRootPath(e){this.#B.rootPath=e,Ft(this.#B)}hasRoute(e){return this.#B.matcher.hasRoute(e)}clearRoutes(){xt(this.#B)}buildPath(e,t,r){if(e===b.UNKNOWN_ROUTE)return f(t?.path)?t.path:"";const n=Object.hasOwn(this.#B.config.defaultParams,e)?{...this.#B.config.defaultParams[e],...t}:t??{},o="function"==typeof this.#B.config.encoders[e]?this.#B.config.encoders[e]({...n}):n,i=r?.trailingSlash;return this.#B.matcher.buildPath(e,o,{trailingSlash:"never"===i||"always"===i?i:void 0,queryParamsMode:r?.queryParamsMode})}matchPath(e,t){const r=t,n=this.#B.matcher.match(e);if(!n)return;const o=Yt(n),{name:i,params:a,meta:s}=o,c="function"==typeof this.#B.config.decoders[i]?this.#B.config.decoders[i](a):a,{name:u,params:d}=this.#h.forwardState(i,c);let l=e;if(r.rewritePathOnMatch){const e="function"==typeof this.#B.config.encoders[u]?this.#B.config.encoders[u]({...d}):d,t=r.trailingSlash;l=this.#B.matcher.buildPath(u,e,{trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:r.queryParamsMode})}return this.#h.makeState(u,d,l,{params:s})}forwardState(e,t){if(Object.hasOwn(this.#B.config.forwardFnMap,e)){const r=this.#G(e,t),n=this.#B.config.forwardFnMap[e],o=this.#V(e,n,t);return{name:o,params:this.#G(o,r)}}const r=this.#B.resolvedForwardMap[e]??e;if(r!==e&&Object.hasOwn(this.#B.config.forwardFnMap,r)){const n=this.#G(e,t),o=this.#B.config.forwardFnMap[r],i=this.#V(r,o,t);return{name:i,params:this.#G(i,n)}}if(r!==e){const n=this.#G(e,t);return{name:r,params:this.#G(r,n)}}return{name:e,params:this.#G(e,t)}}buildStateResolved(e,t){const r=this.#B.matcher.getSegmentsByName(e);if(r)return Yt({segments:r,params:t,meta:this.#B.matcher.getMetaByName(e)},e)}buildStateWithSegmentsResolved(e,t){const r=this.#B.matcher.getSegmentsByName(e);if(r)return{state:Yt({segments:r,params:t,meta:this.#B.matcher.getMetaByName(e)},e),segments:r}}isActiveRoute(e,t={},r=!1,n=!0){ve.has(e)||(m(e,"isActiveRoute"),ve.add(e));const o=this.#h.getState();if(!o)return!1;const i=o.name;if(i!==e&&!i.startsWith(`${e}.`)&&!e.startsWith(`${i}.`))return!1;const a=this.#B.config.defaultParams[e];if(r||i===e){const r=a?{...a,...t}:t;return this.#h.areStatesEqual({name:e,params:r,path:""},o,n)}const s=o.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(t,s)&&(!a||function(e,t,r){for(const n in e)if(!(n in r)&&e[n]!==t[n])return!1;return!0}(a,s,t))}getUrlParams(e){const t=this.#B.matcher.getSegmentsByName(e);return t?function(e){const t=[];for(const r of e)for(const e of r.paramMeta.urlParams)t.push(e);return t}(t):[]}getStore(){return this.#B}#G(e,t){return Object.hasOwn(this.#B.config.defaultParams,e)?{...this.#B.config.defaultParams[e],...t}:t}#V(e,t,r){const n=new Set([e]);let o=t(this.#h.getDependency,r),i=0;if("string"!=typeof o)throw new TypeError("forwardTo callback must return a string, got "+typeof o);for(;i<100;){if(void 0===this.#B.matcher.getSegmentsByName(o))throw new Error(`Route "${o}" does not exist`);if(n.has(o)){const e=[...n,o].join(" → ");throw new Error(`Circular forwardTo detected: ${e}`)}if(n.add(o),Object.hasOwn(this.#B.config.forwardFnMap,o)){o=(0,this.#B.config.forwardFnMap[o])(this.#h.getDependency,r),i++;continue}const e=this.#B.config.forwardMap[o];if(void 0===e)return o;o=e,i++}throw new Error("forwardTo exceeds maximum depth of 100")}},Xt=new Set(Object.values(w)),er=new Set(["code","segment","path","redirect"]),tr=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),rr=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:n,redirect:o,...i}={}){super(t??e),this.code=e,this.segment=r,this.path=n,this.redirect=o?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}(o):void 0;for(const[e,t]of Object.entries(i)){if(er.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);tr.has(e)||(this[e]=t)}}setCode(e){this.code=e,Xt.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(er.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);tr.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}};function nr(e,t,r){if(e instanceof rr)throw e.setCode(t),e;throw new rr(t,function(e,t){const r={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))or.has(r)||(t[r]=n);return{...r,...t}}return r}(e,r))}var or=new Set(["code","segment","path","redirect"]);async function ir(e,t,r,n,o,i,a){const s=n.filter(t=>e.has(t));if(0===s.length)return;let c;for(const n of s){if(i())throw new rr(w.TRANSITION_CANCELLED);const s=e.get(n);try{c=await s(t,r,a)}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)throw new rr(w.TRANSITION_CANCELLED,{reason:a.reason});nr(e,o,n)}if(!c)throw new rr(o,{segment:n})}}var ar=[b.UNKNOWN_ROUTE];Object.freeze(ar);var sr={replace:!0};Object.freeze(sr);var cr=class{#h;#z=null;static validateNavigateArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${g(e)}`)}(e)}static validateNavigateToDefaultArgs(e){!function(e){if(void 0!==e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}(e)}static validateNavigationOptions(e,t){!function(e,t){if(!function(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=e;for(const e of i){const r=t[e];if(void 0!==r&&"boolean"!=typeof r)return!1}const r=t.signal;return!(void 0!==r&&!(r instanceof AbortSignal))}(e))throw new TypeError(`[router.${t}] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}(e,t)}setDependencies(e){this.#h=e}async navigate(e,t,r){if(!this.#h.canNavigate())throw new rr(w.ROUTER_NOT_STARTED);const n=this.#h,o=n.buildStateWithSegments(e,t);if(!o){const e=new rr(w.ROUTE_NOT_FOUND);throw n.emitTransitionError(void 0,n.getState(),e),e}const{state:i}=o,a=n.makeState(i.name,i.params,n.buildPath(i.name,i.params),{params:i.meta}),s=n.getState();if(r=function(e,t){return t?.name!==b.UNKNOWN_ROUTE||e.replace?e:{...e,replace:!0}}(r,s),s&&!r.reload&&!r.force&&n.areStatesEqual(s,a,!1)){const e=new rr(w.SAME_STATES);throw n.emitTransitionError(a,s,e),e}this.#q();const c=new AbortController;if(this.#z=c,r.signal){if(r.signal.aborted)throw this.#z=null,new rr(w.TRANSITION_CANCELLED,{reason:r.signal.reason});r.signal.addEventListener("abort",()=>{c.abort(r.signal?.reason)},{once:!0,signal:c.signal})}n.startTransition(a,s);try{const{state:e,meta:t}=await async function(e,t,r,n,o){const[i,a]=e.getLifecycleFunctions(),s=t.name===b.UNKNOWN_ROUTE,c=()=>o.aborted||!e.isActive(),{toDeactivate:u,toActivate:d,intersection:l}=Jt(t,r,void 0===n.reload?void 0:{reload:n.reload}),f=!s&&d.length>0;if(r&&!n.forceDeactivate&&u.length>0&&await ir(i,t,r,u,w.CANNOT_DEACTIVATE,c,o),c())throw new rr(w.TRANSITION_CANCELLED);if(f&&await ir(a,t,r,d,w.CANNOT_ACTIVATE,c,o),c())throw new rr(w.TRANSITION_CANCELLED);if(r)for(const t of u)!d.includes(t)&&i.has(t)&&e.clearCanDeactivate(t);return{state:t,meta:{phase:"activating",segments:{deactivated:u,activated:d,intersection:l}}}}(n,a,s,r,c.signal);if(e.name===b.UNKNOWN_ROUTE||n.hasRoute(e.name)){const o=function(e,t,r,n){const o={phase:t.phase,...void 0!==r?.name&&{from:r.name},reason:"success",segments:t.segments,...void 0!==n.reload&&{reload:n.reload},...void 0!==n.redirected&&{redirected:n.redirected}};return Object.freeze(o.segments.deactivated),Object.freeze(o.segments.activated),Object.freeze(o.segments),Object.freeze(o),{...e,transition:o}}(e,t,s,r);n.setState(o);const i=void 0===r.signal?r:function({signal:e,...t}){return t}(r);return n.sendTransitionDone(o,s,i),o}{const t=new rr(w.ROUTE_NOT_FOUND,{routeName:e.name});throw n.sendTransitionFail(e,s,t),t}}catch(e){throw function(e,t,r,n){t.code!==w.TRANSITION_CANCELLED&&t.code!==w.ROUTE_NOT_FOUND&&e.sendTransitionFail(r,n,t)}(n,e,a,s),e}finally{c.abort(),this.#z===c&&(this.#z=null)}}async navigateToDefault(e){const t=this.#h;if(!t.getOptions().defaultRoute)throw new rr(w.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"});const{route:r,params:n}=t.resolveDefault();if(!r)throw new rr(w.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"});return this.navigate(r,n,e)}navigateToNotFound(e){this.#q();const t=this.#h.getState(),r=t?Qt(t.name).toReversed():[];Object.freeze(r);const n={deactivated:r,activated:ar,intersection:""};Object.freeze(n);const o={phase:"activating",...t&&{from:t.name},reason:"success",segments:n};Object.freeze(o);const i={name:b.UNKNOWN_ROUTE,params:{},path:e,transition:o};return Object.freeze(i),this.#h.setState(i),this.#h.emitTransitionSuccess(i,t,sr),i}abortCurrentNavigation(){this.#z?.abort(new rr(w.TRANSITION_CANCELLED)),this.#z=null}#q(){this.#h.isTransitioning()&&(e.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use cloneRouter() to create isolated instance per request."),this.#z?.abort(new rr(w.TRANSITION_CANCELLED)),this.#h.cancelNavigation())}},ur={replace:!0};Object.freeze(ur);var dr=class{#h;static validateStartArgs(e){if(1!==e.length||"string"!=typeof e[0])throw new Error("[router.start] Expected exactly 1 string argument (startPath).")}setDependencies(e){this.#h=e}async start(e){const t=this.#h,r=t.getOptions(),n=t.matchPath(e);if(!n&&!r.allowNotFound){const r=new rr(w.ROUTE_NOT_FOUND,{path:e});throw t.emitTransitionError(void 0,void 0,r),r}return t.completeStart(),n?t.navigate(n.name,n.params,ur):t.navigateToNotFound(e)}stop(){this.#h.clearState()}},lr=class{#W;#Q;#H;constructor(e){this.#W=e.routerFSM,this.#Q=e.emitter,this.#H=void 0,this.#K()}static validateSubscribeListener(e){if("function"!=typeof e)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#Q.emit(R.ROUTER_START)}emitRouterStop(){this.#Q.emit(R.ROUTER_STOP)}emitTransitionStart(e,t){this.#Q.emit(R.TRANSITION_START,e,t)}emitTransitionSuccess(e,t,r){this.#Q.emit(R.TRANSITION_SUCCESS,e,t,r)}emitTransitionError(e,t,r){this.#Q.emit(R.TRANSITION_ERROR,e,t,r)}emitTransitionCancel(e,t){this.#Q.emit(R.TRANSITION_CANCEL,e,t)}sendStart(){this.#W.send(L)}sendStop(){this.#W.send(G)}sendDispose(){this.#W.send(V)}sendStarted(){this.#W.send(M)}sendNavigate(e,t){this.#H=e,this.#W.send(_,{toState:e,fromState:t})}sendComplete(e,t,r={}){this.#W.send(k,{state:e,fromState:t,opts:r}),this.#H=void 0}sendFail(e,t,r){this.#W.send(U,{toState:e,fromState:t,error:r}),this.#H=void 0}sendFailSafe(e,t,r){this.isReady()?this.sendFail(e,t,r):this.emitTransitionError(e,t,r)}sendCancel(e,t){this.#W.send(B,{toState:e,fromState:t}),this.#H=void 0}canBeginTransition(){return this.#W.canSend(_)}canStart(){return this.#W.canSend(L)}canCancel(){return this.#W.canSend(B)}isActive(){const e=this.#W.getState();return e!==C&&e!==I}isDisposed(){return this.#W.getState()===I}isTransitioning(){return this.#W.getState()===x}isReady(){return this.#W.getState()===F}getCurrentToState(){return this.#H}addEventListener(e,t){return this.#Q.on(e,t)}subscribe(e){return this.#Q.on(R.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}clearAll(){this.#Q.clearAll()}setLimits(e){this.#Q.setLimits(e)}sendCancelIfTransitioning(e){this.canCancel()&&this.sendCancel(this.#H,e)}#K(){const e=this.#W;e.on(j,M,()=>{this.emitRouterStart()}),e.on(F,G,()=>{this.emitRouterStop()}),e.on(F,_,e=>{this.emitTransitionStart(e.toState,e.fromState)}),e.on(x,k,e=>{this.emitTransitionSuccess(e.state,e.fromState,e.opts)}),e.on(x,B,e=>{this.emitTransitionCancel(e.toState,e.fromState)}),e.on(j,U,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(F,U,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(x,U,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)})}};function fr(e,t){if("string"!=typeof e)throw new TypeError(`[router.${t}]: dependency name must be a string, got ${typeof e}`)}function hr(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid argument: expected plain object, received ${g(e)}`);for(const r in e)if(Object.getOwnPropertyDescriptor(e,r)?.get)throw new TypeError(`[router.${t}] Getters not allowed: "${r}"`)}var pr=new rr(w.ROUTER_ALREADY_STARTED),mr=new Set(["all","warn-error","error-only"]);var gr=class{router;options;limits;dependenciesStore;state;routes;routeLifecycle;plugins;navigation;lifecycle;eventBus;constructor(e){this.router=e.router,this.options=e.options,this.limits=e.limits,this.dependenciesStore=e.dependenciesStore,this.state=e.state,this.routes=e.routes,this.routeLifecycle=e.routeLifecycle,this.plugins=e.plugins,this.navigation=e.navigation,this.lifecycle=e.lifecycle,this.eventBus=e.eventBus}wireLimits(){this.dependenciesStore.limits=this.limits,this.plugins.setLimits(this.limits),this.eventBus.setLimits({maxListeners:this.limits.maxListeners,warnListeners:this.limits.warnListeners,maxEventDepth:this.limits.maxEventDepth}),this.routeLifecycle.setLimits(this.limits)}wireRouteLifecycleDeps(){const e={compileFactory:this.createCompileFactory()};this.routeLifecycle.setDependencies(e)}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(e,t)=>{this.routeLifecycle.addCanActivate(e,t,!0,!0)},addDeactivateGuard:(e,t)=>{this.routeLifecycle.addCanDeactivate(e,t,!0,!0)},makeState:(e,t,r,n)=>this.state.makeState(e,t,r,n),getState:()=>this.state.get(),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependenciesStore.dependencies[e],forwardState:(e,t)=>{const r=J(this.router);return r.noValidate||Pt(e,t,"forwardState"),r.forwardState(e,t)}}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wirePluginsDeps(){const e={addEventListener:(e,t)=>this.eventBus.addEventListener(e,t),canNavigate:()=>this.eventBus.canBeginTransition(),compileFactory:this.createCompileFactory()};this.plugins.setDependencies(e)}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:e=>this.routes.hasRoute(e),getState:()=>this.state.get(),setState:e=>{this.state.set(e)},buildStateWithSegments:(e,t)=>{const r=J(this.router);r.noValidate||Pt(e,t,"navigate");const{name:n,params:o}=r.forwardState(e,t);return this.routes.buildStateWithSegmentsResolved(n,o)},makeState:(e,t,r,n)=>this.state.makeState(e,t,r,n),buildPath:(e,t)=>J(this.router).buildPath(e,t),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),resolveDefault:()=>{const e=this.options.get();return{route:re(e.defaultRoute,e=>this.dependenciesStore.dependencies[e]),params:re(e.defaultParams,e=>this.dependenciesStore.dependencies[e])}},startTransition:(e,t)=>{this.eventBus.sendNavigate(e,t)},cancelNavigation:()=>{this.eventBus.sendCancel(this.eventBus.getCurrentToState(),this.state.get())},sendTransitionDone:(e,t,r)=>{this.eventBus.sendComplete(e,t,r)},sendTransitionFail:(e,t,r)=>{this.eventBus.sendFail(e,t,r)},emitTransitionError:(e,t,r)=>{this.eventBus.sendFailSafe(e,t,r)},emitTransitionSuccess:(e,t,r)=>{this.eventBus.emitTransitionSuccess(e,t,r)},canNavigate:()=>this.eventBus.canBeginTransition(),getLifecycleFunctions:()=>this.routeLifecycle.getFunctions(),isActive:()=>this.router.isActive(),isTransitioning:()=>this.eventBus.isTransitioning(),clearCanDeactivate:e=>{this.routeLifecycle.clearCanDeactivate(e)}})}wireLifecycleDeps(){this.lifecycle.setDependencies({getOptions:()=>this.options.get(),navigate:(e,t,r)=>this.navigation.navigate(e,t,r),navigateToNotFound:e=>this.navigation.navigateToNotFound(e),clearState:()=>{this.state.set(void 0)},matchPath:e=>this.routes.matchPath(e,this.options.get()),completeStart:()=>{this.eventBus.sendStarted()},emitTransitionError:(e,t,r)=>{this.eventBus.sendFail(e,t,r)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(e,t)=>J(this.router).buildPath(e,t),getUrlParams:e=>this.routes.getUrlParams(e)})}createCompileFactory(){const{router:e,dependenciesStore:t}=this;return r=>r(e,e=>t.dependencies[e])}},vr=class r{#u;#w;#J;#Y;#Z;#X;#g;#ee;#te;#re;#ne;constructor(r=[],n={},i={}){n.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)||!mr.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}(n.logger)&&(e.configure(n.logger),delete n.logger),ae.validateOptions(n,"constructor");const a=n.noValidate??!1;a||hr(i,"constructor"),!a&&r.length>0&&(Ot(r),$t(r)),this.#u=new ae(n),this.#w=function(e={}){return{...N,...e}}(n.limits),this.#J=function(e={}){const t=Object.create(null);for(const r in e)void 0!==e[r]&&(t[r]=e[r]);return{dependencies:t,limits:N}}(i),this.#Y=new ce,this.#Z=new Zt(r,a,function(e){return{strictTrailingSlash:"strict"===e.trailingSlash,strictQueryParams:"strict"===e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding,queryParams:e.queryParams}}(this.#u.get())),this.#X=new ge,this.#g=new fe,this.#ee=new cr,this.#te=new dr,this.#ne=a;const s=new t(z),c=new o({onListenerError:(t,r)=>{e.error("Router",`Error in listener for ${t}:`,r)},onListenerWarn:(t,r)=>{e.warn("router.addEventListener",`Event "${t}" has ${r} listeners — possible memory leak`)}});var u;this.#re=new lr({routerFSM:s,emitter:c}),(u=new gr({router:this,options:this.#u,limits:this.#w,dependenciesStore:this.#J,state:this.#Y,routes:this.#Z,routeLifecycle:this.#X,plugins:this.#g,navigation:this.#ee,lifecycle:this.#te,eventBus:this.#re})).wireLimits(),u.wireRouteLifecycleDeps(),u.wireRoutesDeps(),u.wirePluginsDeps(),u.wireNavigationDeps(),u.wireLifecycleDeps(),u.wireStateDeps();const d=new Map;var l;l={makeState:(e,t,r,n,o)=>this.#Y.makeState(e,t,r,n,o),forwardState:Y("forwardState",(e,t)=>this.#Z.forwardState(e,t),d),buildStateResolved:(e,t)=>this.#Z.buildStateResolved(e,t),matchPath:(e,t)=>this.#Z.matchPath(e,t),getOptions:()=>this.#u.get(),addEventListener:(e,t)=>this.#re.addEventListener(e,t),buildPath:Y("buildPath",(e,t)=>this.#Z.buildPath(e,t??{},this.#u.get()),d),start:Y("start",e=>(a||dr.validateStartArgs([e]),this.#te.start(e)),d),interceptors:d,setRootPath:e=>{this.#Z.setRootPath(e)},getRootPath:()=>this.#Z.getStore().rootPath,getTree:()=>this.#Z.getStore().tree,isDisposed:()=>this.#re.isDisposed(),noValidate:a,dependenciesGetStore:()=>this.#J,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#J.dependencies}),getLifecycleFactories:()=>this.#X.getFactories(),getPluginFactories:()=>this.#g.getAll(),routeGetStore:()=>this.#Z.getStore(),getStateName:()=>this.#Y.get()?.name,isTransitioning:()=>this.#re.isTransitioning(),clearState:()=>{this.#Y.set(void 0)},setState:e=>{this.#Y.set(e)},routerExtensions:[]},K.set(this,l),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.dispose=this.dispose.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToNotFound=this.navigateToNotFound.bind(this),this.subscribe=this.subscribe.bind(this)}isActiveRoute(t,r,n,o){return this.#ne||function(e,t,r,n){if(!f(e))throw new TypeError("Route name must be a string");if(void 0!==t&&!l(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)}(t,r,n,o),""===t?(e.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#Z.isActiveRoute(t,r,n,o)}buildPath(e,t){return this.#ne||function(e){if(!f(e)||""===e)throw new TypeError("[real-router] buildPath: route must be a non-empty string, got "+("string"==typeof e?'""':typeof e))}(e),J(this).buildPath(e,t)}getState(){return this.#Y.get()}getPreviousState(){return this.#Y.getPrevious()}areStatesEqual(e,t,r=!0){return this.#ne||ce.validateAreStatesEqualArgs(e,t,r),this.#Y.areStatesEqual(e,t,r)}shouldUpdateNode(e){return this.#ne||function(e){if(!f(e))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof e)}(e),Zt.shouldUpdateNode(e)}isActive(){return this.#re.isActive()}start(e){if(!this.#re.canStart())return Promise.reject(pr);this.#re.sendStart();const t=J(this).start(e).catch(e=>{throw this.#re.isReady()&&(this.#te.stop(),this.#re.sendStop()),e});return r.#oe(t),t}stop(){return this.#ee.abortCurrentNavigation(),this.#re.sendCancelIfTransitioning(this.#Y.get()),this.#re.isReady()||this.#re.isTransitioning()?(this.#te.stop(),this.#re.sendStop(),this):this}dispose(){if(this.#re.isDisposed())return;this.#ee.abortCurrentNavigation(),this.#re.sendCancelIfTransitioning(this.#Y.get()),(this.#re.isReady()||this.#re.isTransitioning())&&(this.#te.stop(),this.#re.sendStop()),this.#re.sendDispose(),this.#re.clearAll(),this.#g.disposeAll();const e=J(this);for(const t of e.routerExtensions)for(const e of t.keys)delete this[e];e.routerExtensions.length=0,this.#Z.clearRoutes(),this.#X.clearAll(),this.#Y.reset(),this.#J.dependencies=Object.create(null),this.#ie()}canNavigateTo(e,t){if(this.#ne||m(e,"canNavigateTo"),!this.#Z.hasRoute(e))return!1;const r=J(this),{name:n,params:o}=r.forwardState(e,t??{}),i=this.#Y.makeState(n,o),a=this.#Y.get(),{toDeactivate:s,toActivate:c}=Jt(i,a);return this.#X.canNavigateTo(s,c,i,a)}usePlugin(...e){return this.#ne||(fe.validateUsePluginArgs(e),fe.validatePluginLimit(this.#g.count(),e.length,this.#w.maxPlugins),fe.validateNoDuplicatePlugins(e,this.#g.has.bind(this.#g))),this.#g.use(...e)}subscribe(e){return this.#ne||lr.validateSubscribeListener(e),this.#re.subscribe(e)}navigate(e,t,n){this.#ne||cr.validateNavigateArgs(e);const o=n??{};this.#ne||cr.validateNavigationOptions(o,"navigate");const i=this.#ee.navigate(e,t??{},o);return r.#oe(i),i}navigateToDefault(e){this.#ne||cr.validateNavigateToDefaultArgs(e);const t=e??{};this.#ne||cr.validateNavigationOptions(t,"navigateToDefault");const n=this.#ee.navigateToDefault(t);return r.#oe(n),n}navigateToNotFound(e){if(!this.#re.isActive())throw new rr(w.ROUTER_NOT_STARTED);const t=e??this.#Y.get().path;return this.#ee.navigateToNotFound(t)}static#ae=t=>{t instanceof rr&&(t.code===w.SAME_STATES||t.code===w.TRANSITION_CANCELLED||t.code===w.ROUTER_NOT_STARTED||t.code===w.ROUTE_NOT_FOUND)||e.error("router.navigate","Unexpected navigation error",t)};static#oe(e){e.catch(r.#ae)}#ie(){this.navigate=wr,this.navigateToDefault=wr,this.navigateToNotFound=wr,this.start=wr,this.stop=wr,this.usePlugin=wr,this.subscribe=wr,this.canNavigateTo=wr}};function wr(){throw new rr(w.ROUTER_DISPOSED)}var yr=(e=[],t={},r={})=>new vr(e,t,r),br=e=>Object.freeze({navigate:e.navigate,getState:e.getState,isActiveRoute:e.isActiveRoute,canNavigateTo:e.canNavigateTo,subscribe:e.subscribe});function Sr(e){if(e())throw new rr(w.ROUTER_DISPOSED)}function Tr(e){const t=J(e);return{makeState:(e,r,n,o,i)=>(t.noValidate||function(e,t,r,n){if(!f(e))throw new TypeError(`[router.makeState] Invalid name: ${g(e)}. Expected string.`);if(void 0!==t&&!l(t))throw new TypeError(`[router.makeState] Invalid params: ${g(t)}. Expected plain object.`);if(void 0!==r&&!f(r))throw new TypeError(`[router.makeState] Invalid path: ${g(r)}. Expected string.`);if(void 0!==n&&"number"!=typeof n)throw new TypeError(`[router.makeState] Invalid forceId: ${g(n)}. Expected number.`)}(e,r,n,i),t.makeState(e,r,n,o,i)),buildState:(e,r)=>{t.noValidate||Pt(e,r,"buildState");const{name:n,params:o}=t.forwardState(e,r);return t.buildStateResolved(n,o)},forwardState:(e,r)=>(t.noValidate||Pt(e,r,"forwardState"),t.forwardState(e,r)),matchPath:e=>(t.noValidate||function(e){if(!f(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e),t.matchPath(e,t.getOptions())),setRootPath:e=>{Sr(t.isDisposed),t.noValidate||function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${g(e)}`)}(e),t.setRootPath(e)},getRootPath:t.getRootPath,addEventListener:(e,r)=>(Sr(t.isDisposed),t.noValidate||function(e,t){if(function(e){if(!$.has(e))throw new Error(`Invalid event name: ${String(e)}`)}(e),"function"!=typeof t)throw new TypeError(`Expected callback to be a function for event ${e}`)}(e,r),t.addEventListener(e,r)),buildNavigationState:(e,r={})=>{t.noValidate||Pt(e,r,"buildNavigationState");const{name:n,params:o}=t.forwardState(e,r),i=t.buildStateResolved(n,o);if(i)return t.makeState(i.name,i.params,t.buildPath(i.name,i.params),{params:i.meta})},getOptions:t.getOptions,getTree:t.getTree,addInterceptor:(e,r)=>{Sr(t.isDisposed);let n=t.interceptors.get(e);return n||(n=[],t.interceptors.set(e,n)),n.push(r),()=>{const e=n.indexOf(r);-1!==e&&n.splice(e,1)}},extendRouter:r=>{Sr(t.isDisposed);const n=Object.keys(r);for(const t of n)if(t in e)throw new rr(w.PLUGIN_CONFLICT,{message:`Cannot extend router: property "${t}" already exists`});for(const t of n)e[t]=r[t];const o={keys:n};t.routerExtensions.push(o);let i=!1;return()=>{if(i)return;i=!0;for(const t of o.keys)delete e[t];const r=t.routerExtensions.indexOf(o);-1!==r&&t.routerExtensions.splice(r,1)}}}}function Er(e,t,r=""){for(const n of e){const e=r?`${r}.${n.name}`:n.name;if(e===t)return n;if(n.children&&t.startsWith(`${e}.`))return Er(n.children,t,e)}}function Or(e,t,r,n){const o={name:e.name,path:e.path},i=r.forwardFnMap[t],a=r.forwardMap[t];void 0!==i?o.forwardTo=i:void 0!==a&&(o.forwardTo=a),t in r.defaultParams&&(o.defaultParams=r.defaultParams[t]),t in r.decoders&&(o.decodeParams=r.decoders[t]),t in r.encoders&&(o.encodeParams=r.encoders[t]);const[s,c]=n;return t in c&&(o.canActivate=c[t]),t in s&&(o.canDeactivate=s[t]),e.children&&(o.children=e.children.map(e=>Or(e,`${t}.${e.name}`,r,n))),o}function Pr(e,t,r,n){if(n){const t=Er(e.definitions,n);t.children??=[];for(const e of r)t.children.push(ye(e))}else for(const t of r)e.definitions.push(ye(t));Ut(r,e.config,e.routeCustomFields,e.pendingCanActivate,e.pendingCanDeactivate,e.depsStore,n??""),e.treeOperations.commitTreeChanges(e,t)}function Ar(e,t,r){return!!be(e.definitions,r)&&(function(e,t,r,n){const o=t=>t===e||t.startsWith(`${e}.`);Se(t.decoders,o),Se(t.encoders,o),Se(t.defaultParams,o),Se(t.forwardMap,o),Se(t.forwardFnMap,o),Se(r,o),Se(t.forwardMap,e=>o(t.forwardMap[e]));const[i,a]=n.getFactories();for(const e of Object.keys(a))o(e)&&n.clearCanActivate(e);for(const e of Object.keys(i))o(e)&&n.clearCanDeactivate(e)}(r,e.config,e.routeCustomFields,e.lifecycleNamespace),e.treeOperations.commitTreeChanges(e,t),!0)}function Rr(e,t){const r=e.matcher.getSegmentsByName(t);if(!r)return;const n=r.at(-1),o=e.treeOperations.nodeToDefinition(n),i=e.lifecycleNamespace.getFactories();return Or(o,t,e.config,i)}function $r(t){const r=J(t),n=r.routeGetStore(),o=r.noValidate;return{add:(e,t)=>{Sr(r.isDisposed);const i=Array.isArray(e)?e:[e],a=t?.parent;r.noValidate||(void 0!==a&&function(e){if("string"!=typeof e||""===e)throw new TypeError(`[router.addRoute] parent option must be a non-empty string, got ${g(e)}`);m(e,"addRoute")}(a),Et(i,"addRoute"),Ot(i),n.treeOperations.validateRoutes(i,n.tree,n.config.forwardMap,a)),Pr(n,o,i,a)},remove:t=>{Sr(r.isDisposed),r.noValidate||(function(e){m(e,"removeRoute")}(t),Tt(t,"removeRoute"));const i=function(t,r,n){if(r){const n=r===t,o=r.startsWith(`${t}.`);if(n||o)return e.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${n?"":` (current: "${r}")`}. Navigate away first.`),!1}return n&&e.warn("router.removeRoute",`Route "${t}" removed while navigation is in progress. This may cause unexpected behavior.`),!0}(t,r.getStateName(),r.isTransitioning());i&&(Ar(n,o,t)||e.warn("router.removeRoute",`Route "${t}" not found. No changes made.`))},update:(t,i)=>{Sr(r.isDisposed),r.noValidate||(function(e,t){if(m(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 ${g(t)}`)}(t,i),Tt(t,"updateRoute"));const{forwardTo:a,defaultParams:s,decodeParams:c,encodeParams:u,canActivate:d,canDeactivate:l}=i;r.noValidate||function(e,t,r,n){if(null!=e){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError(`[real-router] updateRoute: forwardTo must be a string, function, or null, got ${g(e)}`);"function"==typeof e&&At(e,"forwardTo callback")}if(null!=t&&("object"!=typeof t||Array.isArray(t)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${g(t)}`);Rt(r,"decodeParams"),Rt(n,"encodeParams")}(a,s,c,u),r.isTransitioning()&&e.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),r.noValidate||Dt(t,a,e=>n.matcher.hasRoute(e),n.matcher,n.config),function(e,t,r,n){if(void 0!==n.forwardTo&&(e.resolvedForwardMap=function(e,t,r,n,o){return null===t?(delete r.forwardMap[e],delete r.forwardFnMap[e]):"string"==typeof t?(delete r.forwardFnMap[e],r.forwardMap[e]=t):(delete r.forwardMap[e],r.forwardFnMap[e]=t),o(r,n)}(r,n.forwardTo,e.config,t,Lt)),void 0!==n.defaultParams&&(null===n.defaultParams?delete e.config.defaultParams[r]:e.config.defaultParams[r]=n.defaultParams),void 0!==n.decodeParams)if(null===n.decodeParams)delete e.config.decoders[r];else{const t=n.decodeParams;e.config.decoders[r]=e=>t(e)??e}if(void 0!==n.encodeParams)if(null===n.encodeParams)delete e.config.encoders[r];else{const t=n.encodeParams;e.config.encoders[r]=e=>t(e)??e}}(n,o,t,{forwardTo:a,defaultParams:s,decodeParams:c,encodeParams:u}),void 0!==d&&(null===d?n.lifecycleNamespace.clearCanActivate(t):n.lifecycleNamespace.addCanActivate(t,d,o,!0)),void 0!==l&&(null===l?n.lifecycleNamespace.clearCanDeactivate(t):n.lifecycleNamespace.addCanDeactivate(t,l,o,!0))},clear:()=>{Sr(r.isDisposed),Nt(r.isTransitioning())&&(n.treeOperations.resetStore(n),n.lifecycleNamespace.clearAll(),r.clearState())},has:e=>(r.noValidate||m(e,"hasRoute"),n.matcher.hasRoute(e)),get:e=>(r.noValidate||m(e,"getRoute"),Rr(n,e)),getConfig:e=>function(e,t){if(e.matcher.hasRoute(t))return e.routeCustomFields[t]}(n,e),replace:e=>{Sr(r.isDisposed);const i=Array.isArray(e)?e:[e];if(!Nt(r.isTransitioning()))return;r.noValidate||(Et(i,"replaceRoutes"),Ot(i),n.treeOperations.validateRoutes(i));const a=t.getState()?.path;!function(e,t,r,n,o){It(e),e.lifecycleNamespace.clearDefinitionGuards();for(const t of r)e.definitions.push(ye(t));if(Ut(r,e.config,e.routeCustomFields,e.pendingCanActivate,e.pendingCanDeactivate,e.depsStore,""),e.treeOperations.commitTreeChanges(e,t),void 0!==o){const e=n.matchPath(o,n.getOptions());e?n.setState(e):n.clearState()}}(n,o,i,r,a)}}}function Nr(t){const r=J(t);return{get:e=>{r.noValidate||fr(e,"getDependency");const t=r.dependenciesGetStore().dependencies[e];return r.noValidate||function(e,t){if(void 0===e)throw new ReferenceError(`[router.getDependency]: dependency "${t}" not found`)}(t,e),t},getAll:()=>({...r.dependenciesGetStore().dependencies}),set:(t,n)=>{Sr(r.isDisposed),r.noValidate||function(e){if("string"!=typeof e)throw new TypeError("[router.setDependency]: dependency name must be a string, got "+typeof e)}(t),function(t,r,n){if(void 0===n)return!1;if(Object.hasOwn(t.dependencies,r)){const o=t.dependencies[r],i=o!==n,a=Number.isNaN(o)&&Number.isNaN(n);i&&!a&&e.warn("router.setDependency","Router dependency already exists and is being overwritten:",r)}else!function(t,r){const n=t.limits.maxDependencies;if(0===n)return;const o=Object.keys(t.dependencies).length,{warn:i,error:a}=H(n);if(o===i)e.warn(`router.${r}`,`${i} dependencies registered. Consider if all are necessary.`);else if(o===a)e.error(`router.${r}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${n}.`);else if(o>=n)throw new Error(`[router.${r}] Dependency limit exceeded (${n}). Current: ${o}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}(t,"setDependency");t.dependencies[r]=n}(r.dependenciesGetStore(),t,n)},setAll:t=>{Sr(r.isDisposed);const n=r.dependenciesGetStore();r.noValidate||(hr(t,"setDependencies"),function(e,t,r,n=N.maxDependencies){if(0===n)return;const o=e+t;if(o>=n)throw new Error(`[router.${"setDependencies"}] Dependency limit exceeded (${n}). Current: ${o}. This is likely a bug in your code.`)}(Object.keys(n.dependencies).length,Object.keys(t).length,0,n.limits.maxDependencies)),function(t,r){const n=[];for(const e in r)void 0!==r[e]&&(Object.hasOwn(t.dependencies,e)&&n.push(e),t.dependencies[e]=r[e]);n.length>0&&e.warn("router.setDependencies","Overwritten:",n.join(", "))}(n,t)},remove:t=>{Sr(r.isDisposed),r.noValidate||fr(t,"removeDependency");const n=r.dependenciesGetStore();Object.hasOwn(n.dependencies,t)||e.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${g(t)}"`),delete n.dependencies[t]},reset:()=>{Sr(r.isDisposed),r.dependenciesGetStore().dependencies=Object.create(null)},has:e=>(r.noValidate||fr(e,"hasDependency"),Object.hasOwn(r.dependenciesGetStore().dependencies,e))}}function Dr(e){const t=J(e),r=t.routeGetStore().lifecycleNamespace;return{addActivateGuard(e,n){Sr(t.isDisposed),t.noValidate||(m(e,"addActivateGuard"),he(n,"addActivateGuard")),r.addCanActivate(e,n,t.noValidate)},addDeactivateGuard(e,n){Sr(t.isDisposed),t.noValidate||(m(e,"addDeactivateGuard"),he(n,"addDeactivateGuard")),r.addCanDeactivate(e,n,t.noValidate)},removeActivateGuard(e){Sr(t.isDisposed),t.noValidate||m(e,"removeActivateGuard"),r.clearCanActivate(e)},removeDeactivateGuard(e){Sr(t.isDisposed),t.noValidate||m(e,"removeDeactivateGuard"),r.clearCanDeactivate(e)}}}function Cr(e,t){const r=J(e);if(r.isDisposed())throw new rr(w.ROUTER_DISPOSED);r.noValidate||function(e){if(void 0!==e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${g(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}(t);const n=r.routeGetStore(),o=[...n.tree.children.values()].map(e=>ot(e)),i=n.config,a=n.resolvedForwardMap,s=n.routeCustomFields,c=r.cloneOptions(),u=r.cloneDependencies(),[d,l]=r.getLifecycleFactories(),f=r.getPluginFactories(),h={...u,...t},p=new vr(o,c,h),m=Dr(p);for(const[e,t]of Object.entries(d))m.addDeactivateGuard(e,t);for(const[e,t]of Object.entries(l))m.addActivateGuard(e,t);f.length>0&&p.usePlugin(...f);const v=J(p).routeGetStore();return Object.assign(v.config.decoders,i.decoders),Object.assign(v.config.encoders,i.encoders),Object.assign(v.config.defaultParams,i.defaultParams),Object.assign(v.config.forwardMap,i.forwardMap),Object.assign(v.config.forwardFnMap,i.forwardFnMap),Object.assign(v.resolvedForwardMap,a),Object.assign(v.routeCustomFields,s),p}export{vr as Router,rr as RouterError,y as UNKNOWN_ROUTE,Cr as cloneRouter,b as constants,yr as createRouter,w as errorCodes,R as events,Nr as getDependenciesApi,Dr as getLifecycleApi,br as getNavigator,Tr as getPluginApi,$r as getRoutesApi};//# sourceMappingURL=index.mjs.map