@real-router/core 0.36.2 → 0.37.0

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