@real-router/core 0.2.1 → 0.2.2

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{isObjKey as e,getTypeDescription as t,isString as r,isNavigationOptions as n,validateRouteName as o,validateState as a,isParams as i,isState as s,isBoolean as c,isPromise as u}from"type-guards";import{logger as d}from"logger";import{getSegmentsByName as f,buildPath as l,matchSegments as p,createRouteTree as m,routeTreeToDefinitions as h,nodeToDefinition as w,hasSegmentsByName as v,getMetaFromSegments as y,validateRoute as g}from"route-tree";var T=Symbol("real-router.routeTree"),E=Symbol("real-router.routeDefinitions"),S=Symbol("real-router.resolvedForwardMap"),b=Symbol("real-router.rootPath"),R=Symbol("real-router.config"),O=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"}),N={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},A="onStart",$="onStop",I="onTransitionStart",P="onTransitionCancel",_="onTransitionSuccess",k="onTransitionError",j={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},C=new WeakSet;function D(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)D(t);else for(const t in e)D(e[t])}function x(e){return e?(C.has(e)||(D(e),C.add(e)),e):e}function L(e){switch(e){case"never":return"never";case"always":return"always";default:return"default"}}function M(e){const t={trailingSlashMode:L(e.trailingSlash),queryParamsMode:e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding};return void 0!==e.queryParams&&(t.queryParams=e.queryParams),t}var U=new Set(Object.values(O)),F=new Set(["code","segment","path","redirect"]),W=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),q=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:n,redirect:o,...a}={}){super(t??e),this.code=e,this.segment=r,this.path=n,this.redirect=o?function(e){if(!e)return e;if(null===(t=e)||"object"!=typeof t||"string"!=typeof t.name||"string"!=typeof t.path||"object"!=typeof t.params||null===t.params)throw new TypeError("[deepFreezeState] Expected valid State object, got: "+typeof e);var t;const r=structuredClone(e),n=new WeakSet;return function e(t){if(null===t||"object"!=typeof t)return;if(n.has(t))return;n.add(t),Object.freeze(t);const r=Array.isArray(t)?t:Object.values(t);for(const t of r)e(t)}(r),r}(o):void 0;for(const[e,t]of Object.entries(a)){if(F.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);W.has(e)||(this[e]=t)}}setCode(e){this.code=e,U.has(this.message)&&(this.message=e)}setErrorInstance(e){if(!e)throw new TypeError("[RouterError.setErrorInstance] err parameter is required and must be an Error instance");this.message=e.message,this.cause=e.cause,this.stack=e.stack??""}setAdditionalFields(e){for(const[t,r]of Object.entries(e)){if(F.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);W.has(t)||(this[t]=r)}}hasField(e){return e in this}getField(e){return this[e]}toJSON(){const e={code:this.code,message:this.message};void 0!==this.segment&&(e.segment=this.segment),void 0!==this.path&&(e.path=this.path),void 0!==this.redirect&&(e.redirect=this.redirect);const t=new Set(["code","message","segment","path","redirect","stack"]);for(const r in this)Object.hasOwn(this,r)&&!t.has(r)&&(e[r]=this[r]);return e}};function z(e,t){if("string"!=typeof t)throw new TypeError(`[router.${e}]: dependency name must be a string, got ${typeof t}`)}function V(e,t){const r=Object.keys(e).length;if(20===r)d.warn(`router.${t}`,"20 dependencies registered. Consider if all are necessary.");else if(50===r)d.error(`router.${t}`,"50 dependencies registered! This indicates architectural problems. Hard limit at 100.");else if(r>=100)throw new Error(`[router.${t}] Dependency limit exceeded (100). Current: ${r}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}function H(e){return e.name?e.name:"anonymous"}function K(e,r){if("function"!=typeof e)throw new TypeError(`[router.useMiddleware] Middleware factory must return a function, got ${t(e)}. Factory: ${H(r)}`)}function G(e){const r=new Set,n=new Map;return e.useMiddleware=(...o)=>{!function(e,t){const r=e+t;if(r>50)throw new Error(`[router.useMiddleware] Middleware limit exceeded (50). Current: ${t}, Attempting to add: ${e}. This indicates an architectural problem. Consider consolidating middleware.`);r>=30?d.error("router.useMiddleware",`${r} middleware registered! This is excessive and will impact performance. Hard limit at 50.`):r>=15&&d.warn("router.useMiddleware",`${r} middleware registered. Consider if all are necessary.`)}(o.length,r.size),o.forEach((e,n)=>{if(function(e,r){if("function"!=typeof e)throw new TypeError(`[router.useMiddleware] Expected middleware factory function at index ${r}, got ${t(e)}`)}(e,n),r.has(e))throw new Error(`[router.useMiddleware] Middleware factory already registered. To re-register, first unsubscribe the existing middleware. Factory: ${H(e)}`)});const a=[];try{for(const t of o){const r=t(e,e.getDependency);K(r,t),a.push({factory:t,middleware:r})}}catch(e){throw d.error("router.useMiddleware","Failed to initialize middleware, rolling back",e),e}for(const{factory:e,middleware:t}of a)r.add(e),n.set(e,t);return()=>{for(const{factory:e}of a)r.delete(e)||d.warn("router.useMiddleware","Attempted to remove non-existent middleware factory. This might indicate a memory leak or incorrect cleanup logic."),n.delete(e)}},e.clearMiddleware=()=>(r.clear(),n.clear(),e),e.getMiddlewareFactories=()=>[...r],e.getMiddlewareFunctions=()=>[...n.values()],e}var J=(e,t)=>{if(t)return t.setCode(e),t},Y=(e,t)=>{const r=e.meta,n=t.meta,o=r?.params,a=n?.params,i=o&&a?{...o,...a}:o??a??{},s={id:1,options:{},redirected:!1,...n,...r,params:i};return{...e,meta:s}},B=(e,t,r)=>{const n=r?{segment:r}:{};void 0!==e&&("boolean"!=typeof e?s(e)?t(void 0,e):u(e)?e.then(e=>{"boolean"==typeof e?e?t():t(new q(O.TRANSITION_ERR,n)):t(void 0,e)},e=>{let r=n;e instanceof Error?(r={...n,message:e.message,stack:e.stack},"cause"in e&&void 0!==e.cause&&(r.cause=e.cause)):e&&"object"==typeof e&&(r={...n,...e}),t(new q(O.TRANSITION_ERR,r))}):t(new q(O.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})):e?t():t(new q(O.TRANSITION_ERR,n)))},Q=new Set(["code","segment","path","redirect"]);function Z(e,t){const r=t?{segment:t}:{};if(e instanceof Error)return{...r,message:e.message,stack:e.stack,..."cause"in e&&void 0!==e.cause&&{cause:e.cause}};if(e&&"object"==typeof e){const t={};for(const[r,n]of Object.entries(e))Q.has(r)||(t[r]=n);return{...r,...t}}return r}function X(e,t,r){try{e(t,r)}catch(e){d.error("core:lifecycle","Error in lifecycle callback:",e)}}var ee=(e,t,r,n,o,a,i)=>{let c=t;const u=n.filter(t=>e.has(t));if(0===u.length)return void X(i,void 0,c);let f=0;const l=(e,t)=>{if(e)if(e.redirect){const t=new q(o,{message:"Guards cannot redirect. Use middleware for redirects.",attemptedRedirect:e.redirect});p(t)}else p(e);else p(void 0,t)},p=(t,n)=>{if(a())return void X(i,new q(O.TRANSITION_CANCELLED),c);if(t)return void X(i,J(o,t),c);if(n&&n!==c&&s(n)){if(n.name!==c.name){const e=new q(o,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:n.name,params:n.params,path:n.path}});return void X(i,e,c)}(n.params!==c.params||n.path!==c.path)&&d.error("core:transition","Warning: State mutated during transition",{from:c,to:n}),c=Y(n,c)}if(f>=u.length)return void X(i,void 0,c);const p=u[f++],m=e.get(p);try{const e=m.call(null,c,r,l);B(e,l,p)}catch(e){l(new q(O.TRANSITION_ERR,Z(e,p)))}};p()};function te(e,t,r){try{e(t,r)}catch(e){d.error("real-router:middleware","Error in middleware callback:",e)}}var re=".";function ne(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function oe(e,t){const r=t.meta?.params[e];if(!r||"object"!=typeof r)return{};const n={};for(const e in r){if(!Object.hasOwn(r,e))continue;if(void 0===r[e])continue;const o=t.params[e];null!=o&&("string"==typeof o||"number"==typeof o||"boolean"==typeof o?n[e]=String(o):d.warn("transitionPath.extractSegmentParams",`Unsupported param type for key "${e}": ${typeof o}. Only primitives (string, number, boolean) are supported.`,typeof o))}return n}function ae(e){if(!e)return[""];const t=e.indexOf(re);if(-1===t)return[e];const r=e.indexOf(re,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(re,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(re,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(re),r=t.length,n=[t[0]];let o=t[0].length;for(let a=1;a<r-1;a++)o+=1+t[a].length,n.push(e.slice(0,o));return n.push(e),n}(e)}function ie(e,t){if(a(e,"getTransitionPath"),!t)return{intersection:"",toActivate:ae(e.name),toDeactivate:[]};if(a(t,"getTransitionPath"),(e.meta?.options??{}).reload)return{intersection:"",toActivate:ae(e.name),toDeactivate:ne(ae(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:ae(e.name),toDeactivate:ne(ae(t.name))};if(e.name===t.name&&r&&n){const r=e.meta&&0===Object.keys(e.meta.params).length,n=t.meta&&0===Object.keys(t.meta.params).length;if(r&&n)return{intersection:e.name,toActivate:[],toDeactivate:[]}}const o=ae(e.name),i=ae(t.name),s=function(e,t,r,n,o){for(let a=0;a<o;a++){const o=r[a],i=n[a];if(o!==i)return a;const s=oe(o,e),c=oe(i,t),u=Object.keys(s),d=Object.keys(c);if(u.length!==d.length)return a;for(const e of u)if(s[e]!==c[e])return a}return o}(e,t,o,i,Math.min(i.length,o.length)),c=[];for(let e=i.length-1;e>=s;e--)c.push(i[e]);const u=o.slice(s);return{intersection:s>0?i[s-1]:"",toDeactivate:c,toActivate:u}}function se(e,t,r,n,o){let a=!1,i=!1;const[c,u]=e.getLifecycleFunctions(),f=e.getMiddlewareFunctions(),l=t.name===N.UNKNOWN_ROUTE,p=()=>a||!e.isActive(),m=(e,r)=>{i||(i=!0,o(e,r??t))};return(()=>{const{toDeactivate:o,toActivate:a}=ie(t,r),i=!l&&a.length>0,h=f.length>0;var w;w=(n,o)=>{n?m(n,o):((e,t)=>{i?ee(u,e,r,a,O.CANNOT_ACTIVATE,p,(e,r)=>{t(e,r)}):t(void 0,e)})(o,(n,o)=>{n?m(n,o):((e,t)=>{h?((e,t,r,n,o)=>{let a=t,i=0;const c=(e,t)=>{e?u(e):u(void 0,t)},u=(t,u)=>{if(n())return void te(o,new q(O.TRANSITION_CANCELLED),a);if(t)return void te(o,J(O.TRANSITION_ERR,t),a);if(u&&u!==a&&s(u)&&((u.name!==a.name||u.params!==a.params||u.path!==a.path)&&d.error("real-router:middleware","Warning: State mutated during middleware execution",{from:a,to:u}),a=Y(u,a)),i>=e.length)return void te(o,void 0,a);const f=e[i++];try{const e=f.call(null,a,r,c);B(e,c)}catch(e){c(new q(O.TRANSITION_ERR,Z(e)))}};u()})(f,e,r,p,(e,r)=>{t(e,r)}):t(void 0,e)})(o,(n,o)=>{if(n)m(n,o);else{if(r){const n=ae(t.name),o=ae(r.name),a=new Set(n);for(const t of o)!a.has(t)&&c.has(t)&&e.clearCanDeactivate(t)}m(void 0,o)}})})},r&&!n.forceDeactivate&&o.length>0?ee(c,t,r,o,O.CANNOT_DEACTIVATE,p,w):w(void 0,t)})(),()=>{a||i||(a=!0,m(new q(O.TRANSITION_CANCELLED)))}}var ce=()=>{};function ue(e,...t){try{e(...t)}catch(e){d.error("router.navigate","Error in navigation callback:",e)}}function de(e){let r=null,o=!1;return e.navigate=function(r,o,a,i){const{params:s,opts:c,callback:u}=function(e,t,r){if("function"==typeof e)return{params:{},opts:{},callback:e};const n=e??{};return"function"==typeof t?{params:n,opts:{},callback:t}:{params:n,opts:t??{},callback:r??ce}}(o,a,i);if(!e.isStarted())return ue(u,new q(O.ROUTER_NOT_STARTED)),ce;if(!n(c))throw new TypeError(`[router.navigate] Invalid options: ${t(c)}. Expected NavigationOptions object.`);const d=e.buildStateWithSegments(r,s);if(!d){const t=new q(O.ROUTE_NOT_FOUND);return ue(u,t),e.invokeEventListeners(j.TRANSITION_ERROR,void 0,e.getState(),t),ce}const{state:f,segments:l}=d,p=e.makeState(f.name,f.params,e.buildPathWithSegments(f.name,f.params,l),{params:f.meta,options:c,redirected:c.redirected??!1});if(c.skipTransition)return ue(u,void 0,p),ce;const m=e.getState();if(!c.reload&&!c.force&&e.areStatesEqual(m,p,!1)){const t=new q(O.SAME_STATES);return ue(u,t),e.invokeEventListeners(j.TRANSITION_ERROR,p,m,t),ce}return e.navigateToState(p,m,c,u,!0)},e.navigateToDefault=function(r,o){const a=e.getOptions();if(!a.defaultRoute)return ce;let i={},s=ce;if("function"==typeof r?s=r:r&&(i=r,s=o??ce),!n(i))throw new TypeError(`[router.navigateToDefault] Invalid options: ${t(i)}. Expected NavigationOptions object.`);return e.navigate(a.defaultRoute,a.defaultParams,i,s)},e.navigateToState=(t,n,a,i,s)=>(o&&d.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use router.clone() to create isolated instance per request."),r&&(r(),r=null),o=!1,o=!0,e.invokeEventListeners(j.TRANSITION_START,t,n),r=se(e,t,n,a,(c,u)=>{if(o=!1,r=null,c)c.code===O.TRANSITION_CANCELLED?e.invokeEventListeners(j.TRANSITION_CANCEL,t,n):e.invokeEventListeners(j.TRANSITION_ERROR,t,n,c),ue(i,c);else if(u.name===N.UNKNOWN_ROUTE||e.hasRoute(u.name))e.setState(u),s&&e.invokeEventListeners(j.TRANSITION_SUCCESS,u,n,a),ue(i,void 0,u);else{const t=new q(O.ROUTE_NOT_FOUND,{routeName:u.name});ue(i,t),e.invokeEventListeners(j.TRANSITION_ERROR,void 0,e.getState(),t)}}),r),e.isNavigating=()=>e.isStarted()&&o,e}function fe(e,t,...r){if(0===t.size)return;const n=[...t];for(const t of n)try{Function.prototype.apply.call(t,void 0,r)}catch(t){d.error("Router",`Error in listener for ${e}:`,t)}}function le(e){const t={};function r(e){const r=t[e];if(r)return r;const n=new Set;return t[e]=n,n}let o=null;const a=()=>(o??={[j.ROUTER_START]:0,[j.TRANSITION_START]:0,[j.TRANSITION_SUCCESS]:0,[j.TRANSITION_ERROR]:0,[j.TRANSITION_CANCEL]:0,[j.ROUTER_STOP]:0},o),i=new Set([j.ROUTER_START,j.TRANSITION_START,j.TRANSITION_SUCCESS,j.TRANSITION_ERROR,j.TRANSITION_CANCEL,j.ROUTER_STOP]),c=(e,t)=>{if(!i.has(e))throw new Error(`Invalid event name: ${e}`);if("function"!=typeof t)throw new TypeError(`Expected callback to be a function for event ${e}`)};e.invokeEventListeners=(e,t,o,c)=>{(e=>{if(!i.has(e))throw new Error(`Invalid event name: ${e}`);if(a()[e]>=5)throw new Error(`[Router] Maximum recursion depth (5) exceeded for event: ${e}`)})(e);const u=a();try{switch(u[e]++,e){case j.TRANSITION_START:case j.TRANSITION_CANCEL:if(!t)throw new TypeError(`[router.invokeEventListeners] toState is required for event "${e}"`);if(!s(t))throw new TypeError(`[router.invokeEventListeners] toState is invalid for event "${e}". Expected State object with name, path, and params.`);if(o&&!s(o))throw new TypeError(`[router.invokeEventListeners] fromState is invalid for event "${e}". Expected State object with name, path, and params.`);fe(e,r(e),t,o);break;case j.TRANSITION_ERROR:if(t&&!s(t))throw new TypeError(`[router.invokeEventListeners] toState is invalid for event "${e}". Expected State object with name, path, and params.`);if(o&&!s(o))throw new TypeError(`[router.invokeEventListeners] fromState is invalid for event "${e}". Expected State object with name, path, and params.`);if(!c)throw new TypeError(`[router.invokeEventListeners] error is required for event "${e}"`);if(!(c instanceof q))throw new TypeError(`[router.invokeEventListeners] error must be a RouterError instance for event "${e}". Got: ${"object"==typeof c?c.constructor.name:typeof c}`);fe(e,r(e),t,o,c);break;case j.TRANSITION_SUCCESS:if(!t)throw new TypeError(`[router.invokeEventListeners] toState is required for event "${e}"`);if(!s(t))throw new TypeError(`[router.invokeEventListeners] toState is invalid for event "${e}". Expected State object with name, path, and params.`);if(o&&!s(o))throw new TypeError(`[router.invokeEventListeners] fromState is invalid for event "${e}". Expected State object with name, path, and params.`);if(!c)throw new TypeError(`[router.invokeEventListeners] options is required for event "${e}"`);if(c instanceof q)throw new TypeError(`[router.invokeEventListeners] options cannot be a RouterError for event "${e}". Use TRANSITION_ERROR event for errors.`);if(!n(c))throw new TypeError(`[router.invokeEventListeners] options is invalid for event "${e}". Expected NavigationOptions object.`);fe(e,r(e),t,o,c);break;default:fe(e,r(e))}}finally{u[e]--}},e.hasListeners=e=>{if(!i.has(e))return!1;const r=t[e];return void 0!==r&&r.size>0},e.removeEventListener=(e,r)=>{c(e,r);const n=t[e];n&&0!==n.size&&(n.delete(r)||d.warn("Router",`Attempted to remove non-existent listener for "${e}". This might indicate a memory leak or incorrect cleanup logic.`))},e.addEventListener=(t,n)=>{c(t,n);const o=r(t);if(o.has(n))throw new Error(`[router.addEventListener] Listener already exists for event "${t}". Each listener function can only be registered once per event. Store the returned unsubscribe function to remove the listener.`);if(1e3===o.size&&d.warn("router.addEventListener",`Warning: Event "${t}" has ${o.size} listeners. This might indicate a memory leak.`),o.size>=1e4)throw new Error(`[router.addEventListener] Maximum listener limit (10000) reached for event "${t}". This is a critical memory leak. The application is creating listeners exponentially. Check for loops or recursive calls that register listeners.`);return o.add(n),()=>{e.removeEventListener(t,n)}},e.subscribe=function(t){if("function"!=typeof t)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use router[Symbol.observable]().subscribe(observer)");return e.addEventListener(j.TRANSITION_SUCCESS,(e,r)=>{t({route:e,previousRoute:r})})};const u="function"==typeof Symbol&&Symbol.observable||"@@observable",f=new WeakMap;return e[u]=function(){return{subscribe(t,r={}){const n="function"==typeof t?{next:t}:t,o=f.get(n);if(o?.active)return d.warn("router.observable","Duplicate subscription prevented. Same observer already subscribed."),{unsubscribe:o.unsubscribe,get closed(){return!o.active}};const{signal:a,replay:i=!0}=r;if(a?.aborted)return{unsubscribe:()=>{},closed:!0};let s=!1;const c=e=>{if(!s&&n.next)try{n.next(e)}catch(e){if(d.error("router.observable","Error in observer.next:",e),n.error)try{n.error(e)}catch(e){d.error("router.observable","Error in observer.error:",e)}}},u=e.addEventListener(j.TRANSITION_SUCCESS,(e,t)=>{c({route:e,previousRoute:t})}),l={unsubscribe:()=>{if(!s&&(s=!0,l.active=!1,u(),n.complete))try{n.complete()}catch(e){d.error("router.observable","Error in observer.complete:",e)}},active:!0};if(f.set(n,l),a&&a.addEventListener("abort",()=>{l.unsubscribe()},{once:!0}),i){const t=e.getState();t&&queueMicrotask(()=>{c({route:t,previousRoute:void 0})})}return{unsubscribe:l.unsubscribe,get closed(){return s}}},[u](){return this}}},e}var pe={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},caseSensitive:!1,urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0},me={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},he={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function we(r,n,o,a){if(o&&"object"==typeof o)return function(e,r,n){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${n}] Invalid type for "${r}": expected plain object, got ${t(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[router.${n}] Getters not allowed in "${r}": "${t}"`)}(n,r,a),void("queryParams"===r&&function(t,r){for(const n in t){if(!e(n,he)){const e=Object.keys(he).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Unknown queryParams key: "${n}". Valid keys: ${e}`)}const o=t[n],a=he[n];if(!a.includes(o)){const e=a.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for queryParams.${n}: expected one of ${e}, got "${String(o)}"`)}}}(n,a));if(typeof n!=typeof o)throw new TypeError(`[router.${a}] Invalid type for "${r}": expected ${typeof o}, got ${typeof n}`);r in me&&function(e,t,r){const n=me[e];if(!n.includes(t)){const o=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${o}, got "${String(t)}"`)}}(r,n,a)}function ve(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&ve(r)}return e}var ye="router.usePlugin",ge={[A]:j.ROUTER_START,[$]:j.ROUTER_STOP,[_]:j.TRANSITION_SUCCESS,[I]:j.TRANSITION_START,[k]:j.TRANSITION_ERROR,[P]:j.TRANSITION_CANCEL},Te=Object.keys(ge).filter(t=>e(t,ge));function Ee(r){const n=new Set;function o(n){const o=n(r,r.getDependency);(r=>{if(!r||"object"!=typeof r||Array.isArray(r))throw new TypeError(`[router.usePlugin] Plugin factory must return an object, got ${t(r)}`);if("function"==typeof r.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.");for(const t in r)if("teardown"!==t&&!e(t,ge))throw new TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)})(o),Object.freeze(o);const a=[];for(const e of Te)e in o&&("function"==typeof o[e]?(a.push(r.addEventListener(ge[e],o[e])),e===A&&r.isStarted()&&d.warn(ye,"Router already started, onStart will not be called")):d.warn(ye,`Property '${e}' is not a function, skipping`));return()=>{a.forEach(e=>{e()}),"function"==typeof o.teardown&&o.teardown()}}return r.getPlugins=()=>[...n],r.usePlugin=(...e)=>{((e,t)=>{const r=e+t;if(r>50)throw new Error("[router.usePlugin] Plugin limit exceeded (50)");r>=25?d.error(ye,`${r} plugins registered!`):r>=10&&d.warn(ye,`${r} plugins registered`)})(e.length,n.size);const t=function(e,t){const r=new Set;for(const n of e){if("function"!=typeof n)throw new TypeError("[router.usePlugin] Expected plugin factory function, got "+typeof n);if(t.has(n))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.");r.has(n)?d.warn(ye,"Duplicate factory in batch, will be registered once"):r.add(n)}return r}(e,n),r=[];try{for(const e of t){const t=o(e);r.push({factory:e,cleanup:t})}}catch(e){for(const{cleanup:e}of r)try{e()}catch(e){d.error(ye,"Cleanup error:",e)}throw e}for(const{factory:e}of r)n.add(e);let a=!1;return()=>{if(!a){a=!0;for(const{factory:e}of r)n.delete(e);for(const{cleanup:e}of r)try{e()}catch(e){d.error(ye,"Error during cleanup:",e)}}}},r}function Se(e,r){if(!c(e)&&"function"!=typeof e)throw new TypeError(`[router.${r}] Handler must be a boolean or factory function, got ${t(e)}`)}function be(e){const r=new Map,n=new Map,a=new Map,i=new Map,s=new Set;function u(r,n,o,a,i,u){if(s.has(n))throw new Error(`[router.${u}] Cannot modify route "${n}" during its own registration`);a.has(n)?d.warn(`router.${u}`,`Overwriting existing ${r} handler for route "${n}"`):function(e,t){if(e>=200)throw new Error(`[router.${t}] Lifecycle handler limit exceeded (200). This indicates too many routes with individual handlers. Consider using middleware for cross-cutting concerns.`);e>=100?d.error(`router.${t}`,`${e} lifecycle handlers registered! This is excessive. Hard limit at 200.`):e>=50&&d.warn(`router.${t}`,`${e} lifecycle handlers registered. Consider consolidating logic.`)}(a.size+1,u);const f=c(o)?function(e){const t=()=>e;return()=>t}(o):o;a.set(n,f),s.add(n);try{const r=f(e,e.getDependency);if("function"!=typeof r)throw new TypeError(`[router.${u}] Factory must return a function, got ${t(r)}`);i.set(n,r)}catch(e){throw a.delete(n),e}finally{s.delete(n)}}return e.getLifecycleFactories=()=>{const e={},t={};for(const[t,n]of r)e[t]=n;for(const[e,r]of n)t[e]=r;return[e,t]},e.getLifecycleFunctions=()=>[a,i],e.canActivate=(t,r)=>(o(t,"canActivate"),Se(r,"canActivate"),u("activate",t,r,n,i,"canActivate"),e),e.canDeactivate=(t,n)=>(o(t,"canDeactivate"),Se(n,"canDeactivate"),u("deactivate",t,n,r,a,"canDeactivate"),e),e.clearCanDeactivate=(t,n=!1)=>{if(o(t,"clearCanDeactivate"),s.has(t))throw new Error(`[router.clearCanDeactivate] Cannot modify route "${t}" during its own registration`);const i=r.delete(t),c=a.delete(t);return n||i||c||d.warn("router.clearCanDeactivate",`No canDeactivate handler found for route "${t}"`),e},e.clearCanActivate=(t,r=!1)=>{if(o(t,"clearCanActivate"),s.has(t))throw new Error(`[router.clearCanActivate] Cannot modify route "${t}" during its own registration`);const a=n.delete(t),c=i.delete(t);return r||a||c||d.warn("router.clearCanActivate",`No canActivate handler found for route "${t}"`),e},e}function Re(e){return e[T]}function Oe(e,t){e[T]=t}function Ne(e){return e[S]}function Ae(e,t){e[S]=t}function $e(e){return e[R]}function Ie(e,t){const r=t??function(e){let t="";for(const r of e)r.name&&(t&&(t+="."),t+=r.name);return t}(e.segments);return{name:r,params:e.params,meta:y(e.segments)}}var Pe=Symbol("real-router.buildOptionsCache");function _e(e){return e.buildPath=(t,n)=>{if(!r(t)||""===t)throw new TypeError("[real-router] buildPath: route must be a non-empty string, got "+("string"==typeof t?'""':typeof t));if(t===N.UNKNOWN_ROUTE)return r(n?.path)?n.path:"";const o=$e(e),a=Object.hasOwn(o.defaultParams,t)?{...o.defaultParams[t],...n}:n??{},i="function"==typeof o.encoders[t]?o.encoders[t]({...a}):a,s=e[Pe]??M(e.getOptions());return l(Re(e),t,i,s)},e.buildPathWithSegments=(t,n,o)=>{if(!r(t)||""===t)throw new TypeError("[real-router] buildPathWithSegments: route must be a non-empty string, got "+("string"==typeof t?'""':typeof t));if(t===N.UNKNOWN_ROUTE)return r(n.path)?n.path:"";const a=$e(e),i=Object.hasOwn(a.defaultParams,t)?{...a.defaultParams[t],...n}:n,s="function"==typeof a.encoders[t]?a.encoders[t]({...i}):i,c=e[Pe]??M(e.getOptions());return l(Re(e),t,s,c,o)},e.matchPath=(t,n)=>{if(!r(t))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof t);const o=e.getOptions(),a=function(e){return{...M(e),caseSensitive:e.caseSensitive,strictTrailingSlash:"strict"===e.trailingSlash,strongMatching:!1}}(o),i=p(Re(e),t,a);if(i){const r=Ie(i),{name:a,params:s,meta:c}=r,{decoders:u}=$e(e),d="function"==typeof u[a]?u[a](s):s,{name:f,params:l}=e.forwardState(a,d),p=o.rewritePathOnMatch?e.buildPath(f,l):t;return e.makeState(f,l,p,{params:c,options:{},source:n,redirected:!1})}},e.setRootPath=t=>{const r=e;r[b]=t,Oe(e,m("",t,r[E],{skipValidation:!0}))},e.getRootPath=()=>e[b]||"",e}var ke=()=>{},je=new q(O.NO_START_PATH_OR_STATE),Ce=new q(O.ROUTER_ALREADY_STARTED),De=Symbol("started"),xe=Symbol("active");function Le(e){e[De]=!1,e[xe]=!1;const t=()=>{e[xe]=!1};return e.isStarted=()=>!!e[De],e.isActive=()=>!!e[xe],e.start=(...r)=>{const n=e.getOptions(),[o,a]=(e=>{if(e.length>2)throw new Error("Invalid number of arguments");const[t,r]=e;return t?"function"==typeof t?[void 0,t]:[t,r??ke]:[void 0,ke]})(r);let i=!1;if(e.isStarted()||e.isActive())return i=!0,a(Ce),e;if(!o&&!n.defaultRoute)return i=!0,e.hasListeners(j.TRANSITION_ERROR)&&e.invokeEventListeners(j.TRANSITION_ERROR,void 0,void 0,je),a(je),e;e[xe]=!0;const c=(t,r={})=>{e.navigateToState(t,void 0,r,(e,t)=>{f(e,t)},!1)},u={replace:!0},f=(r,n,o=!1)=>{r?(t(),o&&e.hasListeners(j.TRANSITION_ERROR)&&e.invokeEventListeners(j.TRANSITION_ERROR,void 0,void 0,r)):(e[De]=!0,e.invokeEventListeners(j.ROUTER_START),e.invokeEventListeners(j.TRANSITION_SUCCESS,n,void 0,{replace:!0})),((e,t)=>{i?d.warn("real-router","Callback already invoked"):(i=!0,a(e,t))})(r,n)},l=o??n.defaultRoute,p=((e,t)=>{if("string"==typeof e)return t.matchPath(e);if(s(e)){try{t.buildPath(e.name,e.params)}catch{return}return e}})(l,e),m="string"==typeof l?l:"";return(void 0!==p||n.allowNotFound||n.defaultRoute&&!o)&&function(e,t){delete e[Pe],e[Pe]=M(t)}(e,n),p?c(p,u):n.defaultRoute&&!o?((t,r,n)=>{const o=e.buildState(t,r);if(!o)return void f(new q(O.ROUTE_NOT_FOUND,{routeName:t}),void 0,!0);const a=e.makeState(o.name,o.params,e.buildPath(o.name,o.params),{params:o.meta,options:n,redirected:!1});c(a,n)})(n.defaultRoute,n.defaultParams,u):n.allowNotFound?c(e.makeNotFoundState(m,u),u):f(new q(O.ROUTE_NOT_FOUND,{path:m}),void 0,!0),e},e.stop=()=>(t(),e.isStarted()&&(e[De]=!1,e.setState(void 0),e.invokeEventListeners(j.ROUTER_STOP)),e),e}function Me(e,r){if(void 0!==e.canActivate&&"function"!=typeof e.canActivate)throw new TypeError(`[router.addRoute] canActivate must be a function for route "${r}", got ${t(e.canActivate)}`);if(void 0!==e.defaultParams){const n=e.defaultParams;if(null===n||"object"!=typeof n||Array.isArray(n))throw new TypeError(`[router.addRoute] defaultParams must be an object for route "${r}", got ${t(e.defaultParams)}`)}if(e.children)for(const t of e.children)Me(t,`${r}.${t.name}`)}function Ue(e){const t=new Set;for(const r of e){const e=r.parser;for(const r of e.urlParams)t.add(r);for(const r of e.spatParams)t.add(r)}return t}function Fe(e){const t=new Set,r=/[*:]([A-Z_a-z]\w*)/g;let n;for(;null!==(n=r.exec(e));)t.add(n[1]);return t}function We(e,t,r="",n=[]){for(const o of e){const e=r?`${r}.${o.name}`:o.name,a=[...n,o.path];if(e===t)return a;if(o.children&&t.startsWith(`${e}.`))return We(o.children,t,e,a)}}function qe(e){const t=new Set;for(const r of e)for(const e of Fe(r))t.add(e);return t}function ze(e,t=""){const r=new Set;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(r.add(e),n.children)for(const t of ze(n.children,e))r.add(t)}return r}function Ve(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,o]of Ve(n.children,e))r.set(t,o)}return r}function He(e,t,r,n,o){const a=function(e,t){const r=t.split(".");let n=e;for(const e of r)if(n=n.childrenByName.get(e),!n)return!1;return!0}(o,t),i=n.has(t);if(!a&&!i)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const s=qe(We(r,e)),c=function(e,t,r,n){return t?Ue(f(r,e)):qe(We(n,e))}(t,a,o,r),u=[...c].filter(e=>!s.has(e));if(u.length>0)throw new Error(`[router.addRoute] forwardTo target "${t}" requires params [${u.join(", ")}] that are not available in source route "${e}"`)}function Ke(e,t,r){const n=ze(e),o=Ve(e),a={...t};for(const[e,t]of o)a[e]=t;for(const[t,a]of o)He(t,a,e,n,r);for(const e of Object.keys(a))Je(e,a)}function Ge(e,t){e.canActivate&&t.canActivate(e.name,e.canActivate)}function Je(e,t,r=100){const n=new Set,o=[e];let a=e;for(;t[a];){const e=t[a];if(n.has(e)){const t=o.indexOf(e),r=[...o.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(a),o.push(e),a=e,o.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${o.join(" → ")}`)}return a}function Ye(e){const{forwardMap:t}=$e(e),r={};for(const e of Object.keys(t))r[e]=Je(e,t);Ae(e,r)}function Be(e,t){e.forwardTo&&(e.canActivate&&d.warn("real-router",`Route "${e.name}" has both forwardTo and canActivate. canActivate will be ignored because forwardTo creates a redirect (industry standard). Move canActivate to the target route "${e.forwardTo}".`),$e(t).forwardMap[e.name]=e.forwardTo)}function Qe(e,t){const r=$e(t);e.decodeParams&&(r.decoders[e.name]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(r.encoders[e.name]=t=>e.encodeParams?.(t)??t)}function Ze(e,t){e.defaultParams&&($e(t).defaultParams[e.name]=e.defaultParams)}function Xe(e,t,r=""){for(const n of e){const e=r?`${r}.${n.name}`:n.name,o={...n,name:e};Ge(o,t),Be(o,t),Qe(o,t),Ze(o,t),n.children&&Xe(n.children,t,e)}}function et(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function tt(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>tt(e))),t}function rt(e,t,r=""){for(let n=0;n<e.length;n++){const o=e[n],a=r?`${r}.${o.name}`:o.name;if(a===t)return e.splice(n,1),!0;if(o.children&&t.startsWith(`${a}.`)&&rt(o.children,t,a))return!0}return!1}function nt(e,t,r){void 0!==r&&(null===r?delete e[t]:e[t]=r)}var ot=new Set;function at(e){return e.isActiveRoute=(r,n={},a=!1,s=!0)=>{if(ot.has(r)||(o(r,"isActiveRoute"),ot.add(r)),function(e){if(!i(e))throw new TypeError(`[router.isActiveRoute] Invalid params structure: ${t(e)}`)}(n),void 0!==a&&"boolean"!=typeof a)throw new TypeError("[router.isActiveRoute] strictEquality must be a boolean, got "+typeof a);if(void 0!==s&&"boolean"!=typeof s)throw new TypeError("[router.isActiveRoute] ignoreQueryParams must be a boolean, got "+typeof s);if(""===r)return d.warn("real-router",'isActiveRoute("") called with empty string. The root node is not considered active for any named route. To check if router has active state, use: router.getState() !== undefined'),!1;const c=e.getState();if(!c)return!1;const u=c.name;if(u!==r&&!u.startsWith(`${r}.`)&&!r.startsWith(`${u}.`))return!1;const f=$e(e).defaultParams[r];if(a||u===r){const t=f?{...f,...n}:n;return e.areStatesEqual({name:r,params:t,path:""},c,s)}const l=c.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(n,l)&&(!f||function(e,t,r){for(const n in e)if(!(n in r)&&e[n]!==t[n])return!1;return!0}(f,l,n))},e.shouldUpdateNode=e=>{if(!r(e))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof e);return(t,r)=>{if(!t||"object"!=typeof t||!("name"in t))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(t.meta?.options.reload)return!0;if(""===e&&!r)return!0;const{intersection:n,toActivate:o,toDeactivate:a}=ie(t,r);return e===n||!!o.includes(e)||a.includes(e)}},e.clone=(t={})=>{const r=Re(e),n=lt(h(r),e.getOptions(),t);n.useMiddleware(...e.getMiddlewareFactories()),n.usePlugin(...e.getPlugins());const o=$e(e);!function(e,t){e[R]=t}(n,{decoders:{...o.decoders},encoders:{...o.encoders},defaultParams:structuredClone(o.defaultParams),forwardMap:{...o.forwardMap}}),Ae(n,{...Ne(e)});const[a,i]=e.getLifecycleFactories();for(const e of Object.keys(a))n.canDeactivate(e,a[e]);for(const e of Object.keys(i))n.canActivate(e,i[e]);return n},e}function it(e){return null===e?"null":Array.isArray(e)?"array":typeof e}function st(e,t){if(null!=e){if("function"!=typeof e)throw new TypeError(`[real-router] updateRoute: ${t} must be a function or null, got ${typeof e}`);if("AsyncFunction"===e.constructor.name)throw new TypeError(`[real-router] updateRoute: ${t} cannot be an async function`)}}function ct(e){return t=>{const r=function(e){return t=>{const r=e=>e===t||e.startsWith(`${t}.`),n=$e(e);et(n.decoders,r),et(n.encoders,r),et(n.defaultParams,r),et(n.forwardMap,r),et(n.forwardMap,e=>r(n.forwardMap[e]));const[o,a]=e.getLifecycleFactories();for(const t of Object.keys(a))r(t)&&e.clearCanActivate(t,!0);for(const t of Object.keys(o))r(t)&&e.clearCanDeactivate(t,!0)}}(t),n=(a=$e(t).forwardMap,(e,t,r,n)=>{const o=f(n,t);if(!o)throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);const i=Ue(r),s=[...Ue(o)].filter(e=>!i.has(e));if(s.length>0)throw new Error(`[real-router] updateRoute: forwardTo target "${t}" requires params [${s.join(", ")}] that are not available in source route "${e}"`);a[e]=t});var a;t.forward=(e,r)=>{d.warn("router.forward","Method is deprecated. Use `forwardTo` property in route configuration instead.");const n=Re(t),o=f(n,e);if(!o)throw new Error(`[real-router] forward: source route "${e}" does not exist`);const a=f(n,r);if(!a)throw new Error(`[real-router] forward: target route "${r}" does not exist`);const i=Ue(o),s=Ue(a),c=[];for(const e of s)i.has(e)||c.push(e);if(c.length>0)throw new Error(`[real-router] forward: target route "${r}" requires params [${c.join(", ")}] that are not available in source route "${e}"`);return $e(t).forwardMap[e]=r,Ye(t),t};const i=t,s=e.map(e=>tt(e));function c(e,r=!1){Oe(t,m("",i[b],e,{skipValidation:r}))}function u(){return Re(t)}return i[b]="",Oe(t,m("",i[b],s)),Ae(t,{}),i[E]=s,Xe(e,t),Ye(t),t.addRoute=e=>{const r=Array.isArray(e)?[...e]:[e];!function(e){const r=new Set,n=new Map;for(const t of e)g(t,"addRoute",u(),"",r,n),Me(t,t.name);Ke(e,$e(t).forwardMap,u())}(r);for(const e of r)s.push(tt(e));return Xe(r,t),c(s,!0),Ye(t),t},t.removeRoute=e=>{o(e,"removeRoute");const n=t.getState();if(n){const r=n.name,o=r===e,a=r.startsWith(`${e}.`);if(o||a)return d.warn("router.removeRoute",`Cannot remove route "${e}" — it is currently active${o?"":` (current: "${r}")`}. Navigate away first.`),t}return t.isNavigating()&&d.warn("router.removeRoute",`Route "${e}" removed while navigation is in progress. This may cause unexpected behavior.`),rt(s,e)?(r(e),c(s,!0),Ye(t),t):(d.warn("router.removeRoute",`Route "${e}" not found. No changes made.`),t)},t.clearRoutes=()=>{if(t.isNavigating())return d.error("router.clearRoutes","Cannot clear routes while navigation is in progress. Wait for navigation to complete."),t;s.length=0;const e=$e(t);for(const t in e.decoders)delete e.decoders[t];for(const t in e.encoders)delete e.encoders[t];for(const t in e.defaultParams)delete e.defaultParams[t];for(const t in e.forwardMap)delete e.forwardMap[t];const[r,n]=t.getLifecycleFactories();for(const e in n)t.clearCanActivate(e,!0);for(const e in r)t.clearCanDeactivate(e,!0);return t.setState(void 0),c(s,!0),Ye(t),t},t.getRoute=e=>{o(e,"getRoute");const r=u(),n=f(r,e);if(!n)return;const a=n.at(-1),i=w(a),[,s]=t.getLifecycleFactories(),c=function(e,t){const r=(n,o)=>{const a={name:n.name,path:n.path},i=e.forwardMap[o];return i&&(a.forwardTo=i),o in e.defaultParams&&(a.defaultParams=e.defaultParams[o]),o in e.decoders&&(a.decodeParams=e.decoders[o]),o in e.encoders&&(a.encodeParams=e.encoders[o]),o in t&&(a.canActivate=t[o]),n.children&&(a.children=n.children.map(e=>r(e,`${o}.${e.name}`))),a};return r}($e(t),s);return c(i,e)},t.hasRoute=e=>{o(e,"hasRoute");const t=u();return v(t,e)},t.updateRoute=(e,r)=>{o(e,"updateRoute"),function(e){if(null===e||"object"!=typeof e||Array.isArray(e))throw new TypeError(`[real-router] updateRoute: updates must be an object, got ${it(e)}`)}(r);const a=u(),i=f(a,e);if(!i)throw new ReferenceError(`[real-router] updateRoute: route "${e}" does not exist`);t.isNavigating()&&d.error("router.updateRoute",`Route "${e}" config modified while navigation is in progress. Changes will apply immediately and may affect the current transition.`);const s=$e(t),{forwardTo:c,defaultParams:l,decodeParams:p,encodeParams:m,canActivate:h}=r;return null!=c&&Je(e,{...s.forwardMap,[e]:c}),function(e){if(null!=e&&("object"!=typeof e||Array.isArray(e)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${it(e)}`)}(l),st(p,"decodeParams"),st(m,"encodeParams"),void 0!==c&&(null===c?delete s.forwardMap[e]:n(e,c,i,a),Ye(t)),nt(s.defaultParams,e,l),nt(s.decoders,e,p),nt(s.encoders,e,m),void 0!==h&&(null===h?t.clearCanActivate(e,!0):t.canActivate(e,h)),t},t}}function ut(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>ut(e,t[r]))}function dt(e){let o,s,c=0;const u=()=>Re(e),l=new Map;return e.getState=()=>o,e.setState=e=>{void 0!==e&&a(e,"router.setState"),s=o,o=e?Object.isFrozen(e)?e:x(e):void 0},e.getPreviousState=()=>s,e.makeState=(n,o,a,s,u)=>{if(!r(n))throw new TypeError(`[router.makeState] Invalid name: ${t(n)}. Expected string.`);if(void 0!==o&&!i(o))throw new TypeError(`[router.makeState] Invalid params: ${t(o)}. Expected plain object.`);if(void 0!==a&&!r(a))throw new TypeError(`[router.makeState] Invalid path: ${t(a)}. Expected string.`);if(void 0!==u&&"number"!=typeof u)throw new TypeError(`[router.makeState] Invalid forceId: ${t(u)}. Expected number.`);const d=s?{...s,id:u??++c,params:s.params,options:s.options,redirected:s.redirected}:void 0,f=$e(e).defaultParams;let l;return l=Object.hasOwn(f,n)?{...f[n],...o}:o?{...o}:{},x({name:n,params:l,path:a??e.buildPath(n,o),meta:d})},e.makeNotFoundState=(o,a)=>{if(!r(o))throw new TypeError(`[router.makeNotFoundState] Invalid path: ${t(o)}. Expected string.`);if(void 0!==a&&!n(a))throw new TypeError(`[router.makeNotFoundState] Invalid options: ${t(a)}. Expected NavigationOptions object.`);return e.makeState(N.UNKNOWN_ROUTE,{path:o},o,a?{options:a,params:{},redirected:!1}:void 0)},e.areStatesEqual=(e,t,r=!0)=>{if(!e||!t)return!!e==!!t;if(e.name!==t.name)return!1;if(r){const r=e.meta?.params??t.meta?.params;return(r?function(e){const t=[];for(const r in e){const n=e[r];for(const e in n)"url"===n[e]&&t.push(e)}return t}(r):(e=>{const t=l.get(e);if(void 0!==t)return t;const r=f(u(),e);if(!r)return l.set(e,[]),[];const n=r.flatMap(e=>e.parser?e.parser.urlParams:[]);return l.set(e,n),n})(e.name)).every(r=>ut(e.params[r],t.params[r]))}const n=Object.keys(e.params),o=Object.keys(t.params);return n.length===o.length&&n.every(r=>r in t.params&&ut(e.params[r],t.params[r]))},e.areStatesDescendants=(e,t)=>(a(e,"areStatesDescendants"),a(t,"areStatesDescendants"),d.warn("real-router","areStatesDescendants is deprecated and will be removed in the next major version. Use router.isActiveRoute() instead."),!!t.name.startsWith(`${e.name}.`)&&Object.keys(e.params).every(r=>ut(e.params[r],t.params[r]))),e.forwardState=(n,o)=>{if(!r(n))throw new TypeError(`[router.forwardState] Invalid routeName: ${t(n)}. Expected string.`);if(!i(o))throw new TypeError(`[router.forwardState] Invalid routeParams: ${t(o)}. Expected plain object.`);const a=Ne(e)[n]??n,{defaultParams:s}=$e(e),c=Object.hasOwn(s,n),u=Object.hasOwn(s,a);let d;return d=c&&u?{...s[n],...s[a],...o}:c?{...s[n],...o}:u?{...s[a],...o}:o,{name:a,params:d}},e.buildState=(n,o)=>{if(!r(n))throw new TypeError(`[router.buildState] Invalid routeName: ${t(n)}. Expected string.`);if(!i(o))throw new TypeError(`[router.buildState] Invalid routeParams: ${t(o)}. Expected plain object.`);const{name:a,params:s}=e.forwardState(n,o),c=f(u(),a);if(c)return Ie({segments:c,params:s},a)},e.buildStateWithSegments=(n,o)=>{if(!r(n))throw new TypeError(`[router.buildStateWithSegments] Invalid routeName: ${t(n)}. Expected string.`);if(!i(o))throw new TypeError(`[router.buildStateWithSegments] Invalid routeParams: ${t(o)}. Expected plain object.`);const{name:a,params:s}=e.forwardState(n,o),c=f(u(),a);if(c)return{state:Ie({segments:c,params:s},a),segments:c}},e}var ft=new Set(["all","warn-error","error-only"]);var lt=(n=[],o={},a={})=>{o.logger&&function(e){if("object"!=typeof e||null===e)throw new TypeError("Logger config must be an object");const t=e;for(const e of Object.keys(t))if("level"!==e&&"callback"!==e)throw new TypeError(`Unknown logger config property: "${e}"`);if("level"in t&&void 0!==t.level&&("string"!=typeof(r=t.level)||!ft.has(r)))throw new TypeError(`Invalid logger level: ${function(e){return"string"==typeof e?`"${e}"`:"object"==typeof e?JSON.stringify(e):String(e)}(t.level)}. Expected: "all" | "warn-error" | "error-only"`);var r;if("callback"in t&&void 0!==t.callback&&"function"!=typeof t.callback)throw new TypeError("Logger callback must be a function, got "+typeof t.callback);return!0}(o.logger)&&(d.configure(o.logger),delete o.logger);const i={[R]:{decoders:{},encoders:{},defaultParams:{},forwardMap:{}}};return((...e)=>t=>e.reduce((e,t)=>t(e),t))(function(t){return n=>{for(const[r,n]of Object.entries(t)){if(!e(r,pe))throw new TypeError(`[router.options] Unknown option: "${r}"`);void 0!==n&&we(r,n,pe[r],"withOptions")}let o=ve({...pe,...t});return n.getOptions=()=>o,n.setOption=(e,t)=>{if(!r(e))throw new TypeError("[router.setOption]: option name must be a string, got "+typeof e);if(n.isStarted()&&"defaultRoute"!==e&&"defaultParams"!==e)throw new Error("[router.setOption] Options cannot be changed after router.start(). Only defaultRoute/defaultParams can be changed after start.");if(!Object.hasOwn(o,e))throw new ReferenceError(`[router.setOption]: option "${e}" not found`);we(e,t,pe[e],"setOption");const a=t&&"object"==typeof t&&t.constructor===Object?{...t}:t;return o=ve({...o,[e]:a}),n},n}}(o),function(e){const r=e=>{if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.setDependencies] Invalid argument: expected plain object, received ${t(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[router.setDependencies] Getters not allowed: "${t}"`);V({...n,...e},"setDependencies");const r=[];for(const t in e)void 0!==e[t]&&(Object.hasOwn(n,t)&&r.push(t),n[t]=e[t]);r.length>0&&d.warn("router.setDependencies","Overwritten:",r.join(", "))},n=Object.create(null);return r(e),e=>(e.setDependency=(t,r)=>{if(void 0===r)return e;if(z("setDependency",t),Object.hasOwn(n,t)){const e=n[t],o=e!==r,a=Number.isNaN(e)&&Number.isNaN(r);o&&!a&&d.warn("router.setDependency","Router dependency already exists and is being overwritten:",t)}else V(n,"setDependency");return n[t]=r,e},e.setDependencies=t=>(r(t),e),e.getDependency=e=>{z("getDependency",e);const t=n[e];if(void 0===t)throw new ReferenceError(`[router.getDependency]: dependency "${String(e)}" not found`);return t},e.getDependencies=()=>({...n}),e.removeDependency=r=>(Object.hasOwn(n,r)||d.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${t(r)}"`),delete n[r],e),e.hasDependency=e=>Object.hasOwn(n,e),e.resetDependencies=()=>{for(const e in n)delete n[e];return e},e)}(a),le,dt,Le,be,de,Ee,G,function(e){return t=>[ct(e),_e,at].reduce((e,t)=>t(e),t)}(n))(i)};export{q as RouterError,N as constants,lt as createRouter,O as errorCodes,j as events};//# sourceMappingURL=index.mjs.map
1
+ import{logger as e}from"@real-router/logger";var t=Symbol("real-router.routeTree"),r=Symbol("real-router.routeDefinitions"),n=Symbol("real-router.resolvedForwardMap"),o=Symbol("real-router.rootPath"),a=Symbol("real-router.config"),i=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"}),s={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},c="onStart",u="onStop",l="onTransitionStart",d="onTransitionCancel",f="onTransitionSuccess",p="onTransitionError",h={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},m=["replace","reload","skipTransition","force","forceDeactivate","redirected"];function g(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=e;for(const e of m){const r=t[e];if(void 0!==r&&"boolean"!=typeof r)return!1}return!0}var y=/\S/,w=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function v(e,t){return new TypeError(`[router.${e}] ${t}`)}function b(e,t=new WeakSet){if(null==e)return!0;const r=typeof e;if("string"===r||"boolean"===r)return!0;if("number"===r)return Number.isFinite(e);if("function"===r||"symbol"===r)return!1;if(Array.isArray(e))return!t.has(e)&&(t.add(e),e.every(e=>b(e,t)));if("object"===r){if(t.has(e))return!1;t.add(e);const r=Object.getPrototypeOf(e);return(null===r||r===Object.prototype)&&Object.values(e).every(e=>b(e,t))}return!1}function T(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function E(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);if(null!==t&&t!==Object.prototype)return!1;let r=!1;for(const t in e){if(!Object.hasOwn(e,t))continue;const n=e[t];if(!T(n)){const e=typeof n;if("function"===e||"symbol"===e)return!1;r=!0;break}}return!r||b(e)}function S(e){return"object"==typeof e&&null!==e&&("string"==typeof(r=(t=e).name)&&(""===r||!(r.length>1e4)&&(!!r.startsWith("@@")||w.test(r)))&&"string"==typeof t.path&&E(t.params));var t,r}function R(e){return"string"==typeof e}function O(e){return"boolean"==typeof e}function P(e,t){return e in t}function $(e,t){if("string"!=typeof e)throw v(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!y.test(e))throw v(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw v(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!w.test(e))throw v(t,`Invalid route name "${e}". Each segment must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens. Segments are separated by dots (e.g., "users.profile").`)}}function A(e){return null===e?"null":Array.isArray(e)?`array[${e.length}]`:"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function N(e,t){if(!S(e))throw new TypeError(`[${t}] Invalid state structure: ${A(e)}. Expected State object with name, params, and path properties.`)}var j=new WeakSet;function x(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)x(t);else for(const t in e)x(e[t])}function I(e){return e?(j.has(e)||(x(e),j.add(e)),e):e}function C(e){switch(e){case"never":return"never";case"always":return"always";default:return"default"}}function k(e){const t={trailingSlashMode:C(e.trailingSlash),queryParamsMode:e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding};return void 0!==e.queryParams&&(t.queryParams=e.queryParams),t}var _=new Set(Object.values(i)),M=new Set(["code","segment","path","redirect"]),D=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),U=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:n,redirect:o,...a}={}){super(t??e),this.code=e,this.segment=r,this.path=n,this.redirect=o?function(e){if(!e)return e;if(null===(t=e)||"object"!=typeof t||"string"!=typeof t.name||"string"!=typeof t.path||"object"!=typeof t.params||null===t.params)throw new TypeError("[deepFreezeState] Expected valid State object, got: "+typeof e);var t;const r=structuredClone(e),n=new WeakSet;return function e(t){if(null===t||"object"!=typeof t)return;if(n.has(t))return;n.add(t),Object.freeze(t);const r=Array.isArray(t)?t:Object.values(t);for(const t of r)e(t)}(r),r}(o):void 0;for(const[e,t]of Object.entries(a)){if(M.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);D.has(e)||(this[e]=t)}}setCode(e){this.code=e,_.has(this.message)&&(this.message=e)}setErrorInstance(e){if(!e)throw new TypeError("[RouterError.setErrorInstance] err parameter is required and must be an Error instance");this.message=e.message,this.cause=e.cause,this.stack=e.stack??""}setAdditionalFields(e){for(const[t,r]of Object.entries(e)){if(M.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);D.has(t)||(this[t]=r)}}hasField(e){return e in this}getField(e){return this[e]}toJSON(){const e={code:this.code,message:this.message};void 0!==this.segment&&(e.segment=this.segment),void 0!==this.path&&(e.path=this.path),void 0!==this.redirect&&(e.redirect=this.redirect);const t=new Set(["code","message","segment","path","redirect","stack"]);for(const r in this)Object.hasOwn(this,r)&&!t.has(r)&&(e[r]=this[r]);return e}};function L(e,t){if("string"!=typeof t)throw new TypeError(`[router.${e}]: dependency name must be a string, got ${typeof t}`)}function q(t,r){const n=Object.keys(t).length;if(20===n)e.warn(`router.${r}`,"20 dependencies registered. Consider if all are necessary.");else if(50===n)e.error(`router.${r}`,"50 dependencies registered! This indicates architectural problems. Hard limit at 100.");else if(n>=100)throw new Error(`[router.${r}] Dependency limit exceeded (100). Current: ${n}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}function F(e){return e.name?e.name:"anonymous"}function W(e,t){if("function"!=typeof e)throw new TypeError(`[router.useMiddleware] Middleware factory must return a function, got ${A(e)}. Factory: ${F(t)}`)}function z(t){const r=new Set,n=new Map;return t.useMiddleware=(...o)=>{!function(t,r){const n=t+r;if(n>50)throw new Error(`[router.useMiddleware] Middleware limit exceeded (50). Current: ${r}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating middleware.`);n>=30?e.error("router.useMiddleware",`${n} middleware registered! This is excessive and will impact performance. Hard limit at 50.`):n>=15&&e.warn("router.useMiddleware",`${n} middleware registered. Consider if all are necessary.`)}(o.length,r.size),o.forEach((e,t)=>{if(function(e,t){if("function"!=typeof e)throw new TypeError(`[router.useMiddleware] Expected middleware factory function at index ${t}, got ${A(e)}`)}(e,t),r.has(e))throw new Error(`[router.useMiddleware] Middleware factory already registered. To re-register, first unsubscribe the existing middleware. Factory: ${F(e)}`)});const a=[];try{for(const e of o){const r=e(t,t.getDependency);W(r,e),a.push({factory:e,middleware:r})}}catch(t){throw e.error("router.useMiddleware","Failed to initialize middleware, rolling back",t),t}for(const{factory:e,middleware:t}of a)r.add(e),n.set(e,t);return()=>{for(const{factory:t}of a)r.delete(t)||e.warn("router.useMiddleware","Attempted to remove non-existent middleware factory. This might indicate a memory leak or incorrect cleanup logic."),n.delete(t)}},t.clearMiddleware=()=>(r.clear(),n.clear(),t),t.getMiddlewareFactories=()=>[...r],t.getMiddlewareFunctions=()=>[...n.values()],t}var B=(e,t)=>{if(t)return t.setCode(e),t},V=(e,t)=>{const r=e.meta,n=t.meta,o=r?.params,a=n?.params,i=o&&a?{...o,...a}:o??a??{},s={id:1,options:{},redirected:!1,...n,...r,params:i};return{...e,meta:s}},Q=(e,t,r)=>{const n=r?{segment:r}:{};var o;void 0!==e&&("boolean"!=typeof e?S(e)?t(void 0,e):"object"==typeof(o=e)&&null!==o&&"then"in o&&"function"==typeof o.then?e.then(e=>{"boolean"==typeof e?e?t():t(new U(i.TRANSITION_ERR,n)):t(void 0,e)},e=>{let r=n;e instanceof Error?(r={...n,message:e.message,stack:e.stack},"cause"in e&&void 0!==e.cause&&(r.cause=e.cause)):e&&"object"==typeof e&&(r={...n,...e}),t(new U(i.TRANSITION_ERR,r))}):t(new U(i.TRANSITION_ERR,{...n,message:"Invalid lifecycle result type: "+typeof e})):e?t():t(new U(i.TRANSITION_ERR,n)))},Z=new Set(["code","segment","path","redirect"]);function H(e,t){const r=t?{segment:t}:{};if(e instanceof Error)return{...r,message:e.message,stack:e.stack,..."cause"in e&&void 0!==e.cause&&{cause:e.cause}};if(e&&"object"==typeof e){const t={};for(const[r,n]of Object.entries(e))Z.has(r)||(t[r]=n);return{...r,...t}}return r}function K(t,r,n){try{t(r,n)}catch(t){e.error("core:lifecycle","Error in lifecycle callback:",t)}}var G=(t,r,n,o,a,s,c)=>{let u=r;const l=o.filter(e=>t.has(e));if(0===l.length)return void K(c,void 0,u);let d=0;const f=(e,t)=>{if(e)if(e.redirect){const t=new U(a,{message:"Guards cannot redirect. Use middleware for redirects.",attemptedRedirect:e.redirect});p(t)}else p(e);else p(void 0,t)},p=(r,o)=>{if(s())return void K(c,new U(i.TRANSITION_CANCELLED),u);if(r)return void K(c,B(a,r),u);if(o&&o!==u&&S(o)){if(o.name!==u.name){const e=new U(a,{message:"Guards cannot redirect to different route. Use middleware.",attemptedRedirect:{name:o.name,params:o.params,path:o.path}});return void K(c,e,u)}(o.params!==u.params||o.path!==u.path)&&e.error("core:transition","Warning: State mutated during transition",{from:u,to:o}),u=V(o,u)}if(d>=l.length)return void K(c,void 0,u);const p=l[d++],h=t.get(p);try{const e=h.call(null,u,n,f);Q(e,f,p)}catch(e){f(new U(i.TRANSITION_ERR,H(e,p)))}};p()};function J(t,r,n){try{t(r,n)}catch(t){e.error("real-router:middleware","Error in middleware callback:",t)}}var Y=".";function X(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function ee(t,r){const n=r.meta?.params[t];if(!n||"object"!=typeof n)return{};const o={};for(const t in n){if(!Object.hasOwn(n,t))continue;if(void 0===n[t])continue;const a=r.params[t];null!=a&&("string"==typeof a||"number"==typeof a||"boolean"==typeof a?o[t]=String(a):e.warn("transitionPath.extractSegmentParams",`Unsupported param type for key "${t}": ${typeof a}. Only primitives (string, number, boolean) are supported.`,typeof a))}return o}function te(e){if(!e)return[""];const t=e.indexOf(Y);if(-1===t)return[e];const r=e.indexOf(Y,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(Y,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(Y,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(Y),r=t.length,n=[t[0]];let o=t[0].length;for(let a=1;a<r-1;a++)o+=1+t[a].length,n.push(e.slice(0,o));return n.push(e),n}(e)}function re(e,t){if(N(e,"getTransitionPath"),!t)return{intersection:"",toActivate:te(e.name),toDeactivate:[]};if(N(t,"getTransitionPath"),(e.meta?.options??{}).reload)return{intersection:"",toActivate:te(e.name),toDeactivate:X(te(t.name))};const r=void 0!==e.meta?.params,n=void 0!==t.meta?.params;if(!r&&!n)return{intersection:"",toActivate:te(e.name),toDeactivate:X(te(t.name))};if(e.name===t.name&&r&&n){const r=e.meta&&0===Object.keys(e.meta.params).length,n=t.meta&&0===Object.keys(t.meta.params).length;if(r&&n)return{intersection:e.name,toActivate:[],toDeactivate:[]}}const o=te(e.name),a=te(t.name),i=function(e,t,r,n,o){for(let a=0;a<o;a++){const o=r[a],i=n[a];if(o!==i)return a;const s=ee(o,e),c=ee(i,t),u=Object.keys(s),l=Object.keys(c);if(u.length!==l.length)return a;for(const e of u)if(s[e]!==c[e])return a}return o}(e,t,o,a,Math.min(a.length,o.length)),s=[];for(let e=a.length-1;e>=i;e--)s.push(a[e]);const c=o.slice(i);return{intersection:i>0?a[i-1]:"",toDeactivate:s,toActivate:c}}function ne(t,r,n,o,a){let c=!1,u=!1;const[l,d]=t.getLifecycleFunctions(),f=t.getMiddlewareFunctions(),p=r.name===s.UNKNOWN_ROUTE,h=()=>c||!t.isActive(),m=(e,t)=>{u||(u=!0,a(e,t??r))};return(()=>{const{toDeactivate:a,toActivate:s}=re(r,n),c=!p&&s.length>0,u=f.length>0;var g;g=(o,a)=>{o?m(o,a):((e,t)=>{c?G(d,e,n,s,i.CANNOT_ACTIVATE,h,(e,r)=>{t(e,r)}):t(void 0,e)})(a,(o,a)=>{o?m(o,a):((t,r)=>{u?((t,r,n,o,a)=>{let s=r,c=0;const u=(e,t)=>{e?l(e):l(void 0,t)},l=(r,l)=>{if(o())return void J(a,new U(i.TRANSITION_CANCELLED),s);if(r)return void J(a,B(i.TRANSITION_ERR,r),s);if(l&&l!==s&&S(l)&&((l.name!==s.name||l.params!==s.params||l.path!==s.path)&&e.error("real-router:middleware","Warning: State mutated during middleware execution",{from:s,to:l}),s=V(l,s)),c>=t.length)return void J(a,void 0,s);const d=t[c++];try{const e=d.call(null,s,n,u);Q(e,u)}catch(e){u(new U(i.TRANSITION_ERR,H(e)))}};l()})(f,t,n,h,(e,t)=>{r(e,t)}):r(void 0,t)})(a,(e,o)=>{if(e)m(e,o);else{if(n){const e=te(r.name),o=te(n.name),a=new Set(e);for(const e of o)!a.has(e)&&l.has(e)&&t.clearCanDeactivate(e)}m(void 0,o)}})})},n&&!o.forceDeactivate&&a.length>0?G(l,r,n,a,i.CANNOT_DEACTIVATE,h,g):g(void 0,r)})(),()=>{c||u||(c=!0,m(new U(i.TRANSITION_CANCELLED)))}}var oe=()=>{};function ae(t,...r){try{t(...r)}catch(t){e.error("router.navigate","Error in navigation callback:",t)}}function ie(t){let r=null,n=!1;return t.navigate=function(e,r,n,o){const{params:a,opts:s,callback:c}=function(e,t,r){if("function"==typeof e)return{params:{},opts:{},callback:e};const n=e??{};return"function"==typeof t?{params:n,opts:{},callback:t}:{params:n,opts:t??{},callback:r??oe}}(r,n,o);if(!t.isStarted())return ae(c,new U(i.ROUTER_NOT_STARTED)),oe;if(!g(s))throw new TypeError(`[router.navigate] Invalid options: ${A(s)}. Expected NavigationOptions object.`);const u=t.buildStateWithSegments(e,a);if(!u){const e=new U(i.ROUTE_NOT_FOUND);return ae(c,e),t.invokeEventListeners(h.TRANSITION_ERROR,void 0,t.getState(),e),oe}const{state:l,segments:d}=u,f=t.makeState(l.name,l.params,t.buildPathWithSegments(l.name,l.params,d),{params:l.meta,options:s,redirected:s.redirected??!1});if(s.skipTransition)return ae(c,void 0,f),oe;const p=t.getState();if(!s.reload&&!s.force&&t.areStatesEqual(p,f,!1)){const e=new U(i.SAME_STATES);return ae(c,e),t.invokeEventListeners(h.TRANSITION_ERROR,f,p,e),oe}return t.navigateToState(f,p,s,c,!0)},t.navigateToDefault=function(e,r){const n=t.getOptions();if(!n.defaultRoute)return oe;let o={},a=oe;if("function"==typeof e?a=e:e&&(o=e,a=r??oe),!g(o))throw new TypeError(`[router.navigateToDefault] Invalid options: ${A(o)}. Expected NavigationOptions object.`);return t.navigate(n.defaultRoute,n.defaultParams,o,a)},t.navigateToState=(o,a,c,u,l)=>(n&&e.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use router.clone() to create isolated instance per request."),r&&(r(),r=null),n=!1,n=!0,t.invokeEventListeners(h.TRANSITION_START,o,a),r=ne(t,o,a,c,(e,d)=>{if(n=!1,r=null,e)e.code===i.TRANSITION_CANCELLED?t.invokeEventListeners(h.TRANSITION_CANCEL,o,a):t.invokeEventListeners(h.TRANSITION_ERROR,o,a,e),ae(u,e);else if(d.name===s.UNKNOWN_ROUTE||t.hasRoute(d.name))t.setState(d),l&&t.invokeEventListeners(h.TRANSITION_SUCCESS,d,a,c),ae(u,void 0,d);else{const e=new U(i.ROUTE_NOT_FOUND,{routeName:d.name});ae(u,e),t.invokeEventListeners(h.TRANSITION_ERROR,void 0,t.getState(),e)}}),r),t.isNavigating=()=>t.isStarted()&&n,t}function se(t,r,...n){if(0===r.size)return;const o=[...r];for(const r of o)try{Function.prototype.apply.call(r,void 0,n)}catch(r){e.error("Router",`Error in listener for ${t}:`,r)}}function ce(t){const r={};function n(e){const t=r[e];if(t)return t;const n=new Set;return r[e]=n,n}let o=null;const a=()=>(o??={[h.ROUTER_START]:0,[h.TRANSITION_START]:0,[h.TRANSITION_SUCCESS]:0,[h.TRANSITION_ERROR]:0,[h.TRANSITION_CANCEL]:0,[h.ROUTER_STOP]:0},o),i=new Set([h.ROUTER_START,h.TRANSITION_START,h.TRANSITION_SUCCESS,h.TRANSITION_ERROR,h.TRANSITION_CANCEL,h.ROUTER_STOP]),s=(e,t)=>{if(!i.has(e))throw new Error(`Invalid event name: ${e}`);if("function"!=typeof t)throw new TypeError(`Expected callback to be a function for event ${e}`)};t.invokeEventListeners=(e,t,r,o)=>{(e=>{if(!i.has(e))throw new Error(`Invalid event name: ${e}`);if(a()[e]>=5)throw new Error(`[Router] Maximum recursion depth (5) exceeded for event: ${e}`)})(e);const s=a();try{switch(s[e]++,e){case h.TRANSITION_START:case h.TRANSITION_CANCEL:if(!t)throw new TypeError(`[router.invokeEventListeners] toState is required for event "${e}"`);if(!S(t))throw new TypeError(`[router.invokeEventListeners] toState is invalid for event "${e}". Expected State object with name, path, and params.`);if(r&&!S(r))throw new TypeError(`[router.invokeEventListeners] fromState is invalid for event "${e}". Expected State object with name, path, and params.`);se(e,n(e),t,r);break;case h.TRANSITION_ERROR:if(t&&!S(t))throw new TypeError(`[router.invokeEventListeners] toState is invalid for event "${e}". Expected State object with name, path, and params.`);if(r&&!S(r))throw new TypeError(`[router.invokeEventListeners] fromState is invalid for event "${e}". Expected State object with name, path, and params.`);if(!o)throw new TypeError(`[router.invokeEventListeners] error is required for event "${e}"`);if(!(o instanceof U))throw new TypeError(`[router.invokeEventListeners] error must be a RouterError instance for event "${e}". Got: ${"object"==typeof o?o.constructor.name:typeof o}`);se(e,n(e),t,r,o);break;case h.TRANSITION_SUCCESS:if(!t)throw new TypeError(`[router.invokeEventListeners] toState is required for event "${e}"`);if(!S(t))throw new TypeError(`[router.invokeEventListeners] toState is invalid for event "${e}". Expected State object with name, path, and params.`);if(r&&!S(r))throw new TypeError(`[router.invokeEventListeners] fromState is invalid for event "${e}". Expected State object with name, path, and params.`);if(!o)throw new TypeError(`[router.invokeEventListeners] options is required for event "${e}"`);if(o instanceof U)throw new TypeError(`[router.invokeEventListeners] options cannot be a RouterError for event "${e}". Use TRANSITION_ERROR event for errors.`);if(!g(o))throw new TypeError(`[router.invokeEventListeners] options is invalid for event "${e}". Expected NavigationOptions object.`);se(e,n(e),t,r,o);break;default:se(e,n(e))}}finally{s[e]--}},t.hasListeners=e=>{if(!i.has(e))return!1;const t=r[e];return void 0!==t&&t.size>0},t.removeEventListener=(t,n)=>{s(t,n);const o=r[t];o&&0!==o.size&&(o.delete(n)||e.warn("Router",`Attempted to remove non-existent listener for "${t}". This might indicate a memory leak or incorrect cleanup logic.`))},t.addEventListener=(r,o)=>{s(r,o);const a=n(r);if(a.has(o))throw new Error(`[router.addEventListener] Listener already exists for event "${r}". Each listener function can only be registered once per event. Store the returned unsubscribe function to remove the listener.`);if(1e3===a.size&&e.warn("router.addEventListener",`Warning: Event "${r}" has ${a.size} listeners. This might indicate a memory leak.`),a.size>=1e4)throw new Error(`[router.addEventListener] Maximum listener limit (10000) reached for event "${r}". This is a critical memory leak. The application is creating listeners exponentially. Check for loops or recursive calls that register listeners.`);return a.add(o),()=>{t.removeEventListener(r,o)}},t.subscribe=function(e){if("function"!=typeof e)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use router[Symbol.observable]().subscribe(observer)");return t.addEventListener(h.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})};const c="function"==typeof Symbol&&Symbol.observable||"@@observable",u=new WeakMap;return t[c]=function(){return{subscribe(r,n={}){const o="function"==typeof r?{next:r}:r,a=u.get(o);if(a?.active)return e.warn("router.observable","Duplicate subscription prevented. Same observer already subscribed."),{unsubscribe:a.unsubscribe,get closed(){return!a.active}};const{signal:i,replay:s=!0}=n;if(i?.aborted)return{unsubscribe:()=>{},closed:!0};let c=!1;const l=t=>{if(!c&&o.next)try{o.next(t)}catch(t){if(e.error("router.observable","Error in observer.next:",t),o.error)try{o.error(t)}catch(t){e.error("router.observable","Error in observer.error:",t)}}},d=t.addEventListener(h.TRANSITION_SUCCESS,(e,t)=>{l({route:e,previousRoute:t})}),f={unsubscribe:()=>{if(!c&&(c=!0,f.active=!1,d(),o.complete))try{o.complete()}catch(t){e.error("router.observable","Error in observer.complete:",t)}},active:!0};if(u.set(o,f),i&&i.addEventListener("abort",()=>{f.unsubscribe()},{once:!0}),s){const e=t.getState();e&&queueMicrotask(()=>{l({route:e,previousRoute:void 0})})}return{unsubscribe:f.unsubscribe,get closed(){return c}}},[c](){return this}}},t}var ue={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},caseSensitive:!1,urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0},le={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},de={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function fe(e,t,r,n){if(r&&"object"==typeof r)return function(e,t,r){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${r}] Invalid type for "${t}": expected plain object, got ${A(e)}`);for(const n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw new TypeError(`[router.${r}] Getters not allowed in "${t}": "${n}"`)}(t,e,n),void("queryParams"===e&&function(e,t){for(const r in e){if(!P(r,de)){const e=Object.keys(de).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],o=de[r];if(!o.includes(n)){const e=o.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Invalid value for queryParams.${r}: expected one of ${e}, got "${String(n)}"`)}}}(t,n));if(typeof t!=typeof r)throw new TypeError(`[router.${n}] Invalid type for "${e}": expected ${typeof r}, got ${typeof t}`);e in le&&function(e,t,r){const n=le[e];if(!n.includes(t)){const o=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${o}, got "${String(t)}"`)}}(e,t,n)}function pe(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&pe(r)}return e}var he="router.usePlugin",me={[c]:h.ROUTER_START,[u]:h.ROUTER_STOP,[f]:h.TRANSITION_SUCCESS,[l]:h.TRANSITION_START,[p]:h.TRANSITION_ERROR,[d]:h.TRANSITION_CANCEL},ge=Object.keys(me).filter(e=>P(e,me));function ye(t){const r=new Set;function n(r){const n=r(t,t.getDependency);(e=>{if(!e||"object"!=typeof e||Array.isArray(e))throw new TypeError(`[router.usePlugin] Plugin factory must return an object, got ${A(e)}`);if("function"==typeof e.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.");for(const t in e)if("teardown"!==t&&!P(t,me))throw new TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)})(n),Object.freeze(n);const o=[];for(const r of ge)r in n&&("function"==typeof n[r]?(o.push(t.addEventListener(me[r],n[r])),r===c&&t.isStarted()&&e.warn(he,"Router already started, onStart will not be called")):e.warn(he,`Property '${r}' is not a function, skipping`));return()=>{o.forEach(e=>{e()}),"function"==typeof n.teardown&&n.teardown()}}return t.getPlugins=()=>[...r],t.usePlugin=(...t)=>{((t,r)=>{const n=t+r;if(n>50)throw new Error("[router.usePlugin] Plugin limit exceeded (50)");n>=25?e.error(he,`${n} plugins registered!`):n>=10&&e.warn(he,`${n} plugins registered`)})(t.length,r.size);const o=function(t,r){const n=new Set;for(const o of t){if("function"!=typeof o)throw new TypeError("[router.usePlugin] Expected plugin factory function, got "+typeof o);if(r.has(o))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.");n.has(o)?e.warn(he,"Duplicate factory in batch, will be registered once"):n.add(o)}return n}(t,r),a=[];try{for(const e of o){const t=n(e);a.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of a)try{t()}catch(t){e.error(he,"Cleanup error:",t)}throw t}for(const{factory:e}of a)r.add(e);let i=!1;return()=>{if(!i){i=!0;for(const{factory:e}of a)r.delete(e);for(const{cleanup:t}of a)try{t()}catch(t){e.error(he,"Error during cleanup:",t)}}}},t}function we(e,t){if(!O(e)&&"function"!=typeof e)throw new TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${A(e)}`)}function ve(t){const r=new Map,n=new Map,o=new Map,a=new Map,i=new Set;function s(r,n,o,a,s,c){if(i.has(n))throw new Error(`[router.${c}] Cannot modify route "${n}" during its own registration`);a.has(n)?e.warn(`router.${c}`,`Overwriting existing ${r} handler for route "${n}"`):function(t,r){if(t>=200)throw new Error(`[router.${r}] Lifecycle handler limit exceeded (200). This indicates too many routes with individual handlers. Consider using middleware for cross-cutting concerns.`);t>=100?e.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at 200.`):t>=50&&e.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}(a.size+1,c);const u=O(o)?function(e){const t=()=>e;return()=>t}(o):o;a.set(n,u),i.add(n);try{const e=u(t,t.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${c}] Factory must return a function, got ${A(e)}`);s.set(n,e)}catch(e){throw a.delete(n),e}finally{i.delete(n)}}return t.getLifecycleFactories=()=>{const e={},t={};for(const[t,n]of r)e[t]=n;for(const[e,r]of n)t[e]=r;return[e,t]},t.getLifecycleFunctions=()=>[o,a],t.canActivate=(e,r)=>($(e,"canActivate"),we(r,"canActivate"),s("activate",e,r,n,a,"canActivate"),t),t.canDeactivate=(e,n)=>($(e,"canDeactivate"),we(n,"canDeactivate"),s("deactivate",e,n,r,o,"canDeactivate"),t),t.clearCanDeactivate=(n,a=!1)=>{if($(n,"clearCanDeactivate"),i.has(n))throw new Error(`[router.clearCanDeactivate] Cannot modify route "${n}" during its own registration`);const s=r.delete(n),c=o.delete(n);return a||s||c||e.warn("router.clearCanDeactivate",`No canDeactivate handler found for route "${n}"`),t},t.clearCanActivate=(r,o=!1)=>{if($(r,"clearCanActivate"),i.has(r))throw new Error(`[router.clearCanActivate] Cannot modify route "${r}" during its own registration`);const s=n.delete(r),c=a.delete(r);return o||s||c||e.warn("router.clearCanActivate",`No canActivate handler found for route "${r}"`),t},t}var be=e=>{const t=e.indexOf("%"),r=e.indexOf("+");if(-1===t&&-1===r)return e;const n=-1===r?e:e.split("+").join(" ");return-1===t?n:decodeURIComponent(n)},Te=e=>encodeURIComponent(e),Ee={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${Te(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${Te(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${Te(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>Te(e)).join(",")}`}},Se={none:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:e=>e},string:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:e=>"true"===e||"false"!==e&&null,decodeValue:e=>e},"empty-true":{encode:(e,t)=>t?e:`${e}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:e=>e}},Re={default:{encode:e=>e},hidden:{encode:()=>""}},Oe=(e,t,r)=>({boolean:Se[t],null:Re[r],array:Ee[e]}),Pe={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:Se.none,null:Re.default,array:Ee.none}},$e=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return Pe;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:Oe(t,r,n)}},Ae=e=>encodeURIComponent(e),Ne=(e,t,r)=>{const n=Ae(e);switch(typeof t){case"string":case"number":default:return`${n}=${Ae(t)}`;case"boolean":return r.strategies.boolean.encode(n,t);case"object":return null===t?r.strategies.null.encode(n):Array.isArray(t)?r.strategies.array.encodeArray(n,t):`${n}=${Ae(t)}`}},je=e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)};function xe(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}function Ie(e,t,r,n,o){const a=e.indexOf("=",t),i=-1!==a&&a<r,s=e.slice(t,i?a:r),{name:c,hasBrackets:u}=xe(s);!function(e,t,r,n){const o=e[t];void 0===o?e[t]=n?[r]:r:Array.isArray(o)?o.push(r):e[t]=[o,r]}(n,be(c),function(e,t,r,n,o){return o?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const n=be(e);return t.boolean.decodeValue(n)})(n?e.slice(t+1,r):void 0,o):n?be(e.slice(t+1,r)):null}(e,a,r,i,o),u)}var Ce=(e,t)=>{const r=je(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return ke(e,t),t}(r);const n=$e(t),o={};let a=0;const i=r.length;for(;a<i;){let e=r.indexOf("&",a);-1===e&&(e=i),Ie(r,a,e,o,n.strategies),a=e+1}return o};function ke(e,t){let r=0;const n=e.length;for(;r<n;){let o=e.indexOf("&",r);-1===o&&(o=n),Ie(e,r,o,t),r=o+1}}var _e=(e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=$e(t),o=[];for(const t of r){const r=e[t];if(void 0===r)continue;const a=Ne(t,r,n);a&&o.push(a)}return o.join("&")},Me=/[^\w!$'()*+,.:;|~-]/gu,De=/[^\w!$'()*+,.:;|~-]/u,Ue={default:e=>De.test(e)?e.replaceAll(Me,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e,legacy:encodeURI},Le={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e,legacy:decodeURIComponent},qe={urlParamsEncoding:"default"},Fe={withQueryParams:String.raw`(\?.*$|$)`,withoutQueryParams:"$"},We=String.raw`([/?.;]|$)`,ze=String.raw`[a-zA-Z0-9_.~%':|=+*@$-]+`,Be=e=>`(${e?e.replaceAll(/(^<|>$)/g,""):ze})`,Ve=[{name:"url-parameter",pattern:/^:([\w-]*[\dA-Za-z])(<(.+?)>)?/,regex:e=>new RegExp(Be(e[2]))},{name:"url-parameter-splat",pattern:/^\*([\w-]*[\dA-Za-z])/,regex:/([^?]*)/},{name:"url-parameter-matrix",pattern:/^;([\w-]*[\dA-Za-z])(<(.+?)>)?/,regex:e=>new RegExp(`;${e[1]}=${Be(e[2])}`)},{name:"query-parameter",pattern:/^[&?]:?([\w-]*[\dA-Za-z])/},{name:"delimiter",pattern:/^([/?])/,regex:e=>new RegExp(`\\${e[0]}`)},{name:"sub-delimiter",pattern:/^([!&.;_-])/,regex:e=>new RegExp(e[0])},{name:"fragment",pattern:/^([\dA-Za-z]+)/,regex:e=>new RegExp(e[0])}],Qe=(e,t,r)=>{const n=Ue[t],o=String(e);if(!r)return n(o);const a=o.split("/");let i=n(a[0]);for(let e=1;e<a.length;e++)i+="/"+n(a[e]);return i},Ze=(e,t)=>Le[t](e),He=(e,t=[])=>{if(!Ve.some(r=>{const n=r.pattern.exec(e);return!!n&&(t.push({type:r.name,match:n[0],val:n.slice(1,2),otherVal:n.slice(2),regex:"function"==typeof r.regex?r.regex(n):r.regex}),n[0].length<e.length&&He(e.slice(n[0].length),t),!0)}))throw new Error(`Could not parse path '${e}'`);return t},Ke=e=>null!=e,Ge=e=>"string"==typeof e||"number"==typeof e||"boolean"==typeof e,Je=e=>!!Ke(e)&&(!!Ge(e)||!!Array.isArray(e)&&e.every(e=>Ge(e))),Ye=(e,t,r="")=>{const n=e[t];return e[t]=void 0===n?r:[n,r],e},Xe=class e{path;tokens;hasUrlParams;hasSpatParam;hasMatrixParams;hasQueryParams;options;spatParams;urlParams;queryParams;params;source;regexCache;constraintPatterns;buildOptionsCache;compiledBuildPattern;constructor(e,t){if(!e)throw new Error("Missing path in Path constructor");this.path=e,this.options={...qe,...t},this.tokens=He(e),this.hasUrlParams=this.tokens.some(e=>e.type.startsWith("url-parameter")),this.hasSpatParam=this.tokens.some(e=>e.type.endsWith("splat")),this.hasMatrixParams=this.tokens.some(e=>e.type.endsWith("matrix")),this.hasQueryParams=this.tokens.some(e=>e.type.startsWith("query-parameter")),this.spatParams=this.getParams("url-parameter-splat"),this.urlParams=this.getParams(/^url-parameter/),this.queryParams=this.getParams("query-parameter"),this.params=[...this.urlParams,...this.queryParams];let r="";for(const e of this.tokens)void 0!==e.regex&&(r+=e.regex.source);this.source=r;const n=(e=>"\\/"===e?e:e.replace(/\\\/$/,"")+"(?:\\/)?")(r),o=r,a=r,i=(e=>/(\/)$/.test(e)?e:e+We)(r),s=this.hasQueryParams?Fe.withQueryParams:Fe.withoutQueryParams;this.regexCache={test:{sensitive:new RegExp("^"+n+s),insensitive:new RegExp("^"+n+s,"i")},testStrict:{sensitive:new RegExp("^"+o+s),insensitive:new RegExp("^"+o+s,"i")},partial:{sensitive:new RegExp("^"+a),insensitive:new RegExp("^"+a,"i")},partialDelimited:{sensitive:new RegExp("^"+i),insensitive:new RegExp("^"+i,"i")}},this.constraintPatterns=new Map;const c=this.tokens.filter(e=>e.type.startsWith("url-parameter")&&!e.type.endsWith("-splat"));for(const e of c){const t=e.val[0],r=e.otherVal[0],n=new RegExp("^"+Be(r)+"$");this.constraintPatterns.set(t,{pattern:n,constraint:r})}this.buildOptionsCache={ignoreConstraints:!1,ignoreSearch:!1,queryParams:this.options.queryParams??{},urlParamsEncoding:this.options.urlParamsEncoding};const u=this.tokens.filter(e=>!e.type.startsWith("query-parameter")),l=[],d=[];let f="";for(const e of u)e.type.startsWith("url-parameter")&&"url-parameter-matrix"!==e.type?(l.push(f),f="",d.push(e.val[0])):"url-parameter-matrix"===e.type?(f+=";"+e.val[0]+"=",l.push(f),f="",d.push(e.val[0])):f+=e.match;l.push(f),this.compiledBuildPattern={staticParts:l,paramNames:d,pattern:e}}static createPath(t,r){return new e(t,r)}isQueryParam(e){return this.queryParams.includes(e)}isSpatParam(e){return this.spatParams.includes(e)}test(e,t){const r=t?.caseSensitive??!1,n=t?.strictTrailingSlash?this.regexCache.testStrict:this.regexCache.test,o=this.urlTestWithRegex(e,r?n.sensitive:n.insensitive,t?.urlParamsEncoding??this.options.urlParamsEncoding);if(!o||!this.hasQueryParams)return o;const a=Ce(e,t?.queryParams??this.options.queryParams);let i=!1;for(const e in a)this.isQueryParam(e)?o[e]=a[e]:i=!0;return i?null:o}partialTest(e,t){const r=t?.caseSensitive??!1,n=t?.delimited??1?this.regexCache.partialDelimited:this.regexCache.partial,o=this.urlTestWithRegex(e,r?n.sensitive:n.insensitive,t?.urlParamsEncoding??this.options.urlParamsEncoding);if(!o)return o;if(!this.hasQueryParams)return o;const a=Ce(e,t?.queryParams??this.options.queryParams);for(const e in a)this.isQueryParam(e)&&Ye(o,e,a[e]);return o}build(e={},t){const r=t?{ignoreConstraints:t.ignoreConstraints??!1,ignoreSearch:t.ignoreSearch??!1,queryParams:t.queryParams??this.buildOptionsCache.queryParams,urlParamsEncoding:t.urlParamsEncoding??this.buildOptionsCache.urlParamsEncoding}:this.buildOptionsCache,n=this.encodeUrlParams(e,r.urlParamsEncoding);this.validateRequiredParams(e),r.ignoreConstraints||this.validateConstraints(n);const o=this.buildBasePath(n);return r.ignoreSearch?o:this.buildWithSearch(o,e,r.queryParams)}encodeUrlParams(e,t){const r={};for(const n of Object.keys(e)){if(this.isQueryParam(n))continue;const o=e[n];Je(o)&&(r[n]=this.encodeParamValue(o,n,t))}return r}encodeParamValue(e,t,r){if("boolean"==typeof e)return e;const n=this.isSpatParam(t);return Array.isArray(e)?e.map(e=>Qe(e,r,n)):Qe(e,r,n)}validateRequiredParams(e){const t=this.urlParams.filter(t=>!Ke(e[t]));if(t.length>0)throw new Error("Cannot build path: '"+this.path+"' requires missing parameters { "+t.join(", ")+" }")}validateConstraints(e){for(const[t,{pattern:r,constraint:n}]of this.constraintPatterns){const o=String(e[t]);if(!r.test(o)){const e=n?n.replaceAll(/(^<)|(>$)/g,""):"[^/]+";throw new Error(`Parameter '${t}' of '${this.path}' has invalid format: got '${o}', expected to match '${e}'`)}}}buildBasePath(e){return function(e,t){const{staticParts:r,paramNames:n}=e;if(0===n.length)return r[0];let o=r[0];for(const[e,a]of n.entries())o+=String(t[a])+r[e+1];return o}(this.compiledBuildPattern,e)}buildWithSearch(e,t,r){const n={};for(const e of this.queryParams)e in t&&(n[e]=t[e]);const o=_e(n,r);return o?e+"?"+o:e}getParams(e){const t=[],r=e instanceof RegExp;for(const n of this.tokens)(r?e.test(n.type):n.type===e)&&t.push(n.val[0]);return t}urlTestWithRegex(e,t,r){const n=t.exec(e);if(!n)return null;if(0===this.urlParams.length)return{};const o={};for(let e=0;e<this.urlParams.length;e++)o[this.urlParams[e]]=Ze(n[e+1],r);return o}},et=function(e){return new Xe(e)};function tt(e,t){const r=e.path,n=r.startsWith("~"),o=n?r.slice(1):r,a={name:e.name,path:o,absolute:n,parser:o?et(o):null,children:[],parent:t,nonAbsoluteChildren:[],absoluteDescendants:[],childrenByName:new Map,parentSegments:[],fullName:"",staticChildrenByFirstSegment:new Map};if(e.children)for(const t of e.children){const e=tt(t,a);a.children.push(e)}return a}function rt(e,t){const r=t.split(".");if(1===r.length)return{parent:e,finalName:t};let n=e;for(let e=0;e<r.length-1;e++){const t=r[e];n=n.children.find(e=>e.name===t)}return{parent:n,finalName:r.at(-1)}}var nt=new Map;function ot(e){const t=e.startsWith("/")?1:0;let r=e.indexOf("/",t);const n=e.indexOf("?",t);-1!==n&&(-1===r||n<r)&&(r=n);const o=-1===r?e.slice(t):e.slice(t,r);return""===o||o.startsWith(":")||o.startsWith("*")||o.includes("(")?null:o.toLowerCase()}function at(e,t){for(const r of e.children)r.absolute&&t.push(r),at(r,t)}function it(e){const t=[];return at(e,t),t}function st(e,t,r){const n={name:e.name,path:e.path,absolute:e.absolute,parser:e.parser,parent:t,children:[],nonAbsoluteChildren:[],absoluteDescendants:[],childrenByName:new Map,parentSegments:[],fullName:"",staticPath:null,paramTypeMap:{},staticChildrenByFirstSegment:nt};if(e.parser){for(const t of e.parser.urlParams)n.paramTypeMap[t]="url";for(const t of e.parser.queryParams)n.paramTypeMap[t]="query"}n.fullName=function(e){return e.parent?.name?`${e.parent.fullName}.${e.name}`:e.name}(n);for(const t of e.children){const e=st(t,n,r);n.children.push(e),n.childrenByName.set(e.name,e),e.absolute||n.nonAbsoluteChildren.push(e)}return n.absoluteDescendants=it(n),n.parentSegments=function(e){const t=[];let r=e.parent;for(;r?.parser;)t.push(r),r=r.parent;return t.reverse(),t}(n),n.staticPath=function(e){const t=e.parser;if(!t)return null;if(t.hasUrlParams||t.hasQueryParams||t.hasSpatParam)return null;let r="";for(const t of e.parentSegments){const e=t.parser;if(e.hasUrlParams||e.hasQueryParams||e.hasSpatParam)return null;r=t.absolute?t.path:r+t.path}return r=e.absolute?e.path:r+e.path,r.replaceAll(/\/{2,}/g,"/")}(n),n.staticChildrenByFirstSegment=function(e,t){if(0===e.length)return nt;const r=new Map;for(const t of e){const e=ot(t.path);if(null!==e){const n=r.get(e);n?n.push(t):r.set(e,[t])}}if(0===r.size)return nt;if(t)for(const[e,t]of r)r.set(e,Object.freeze(t));return r}(n.nonAbsoluteChildren,r),r&&(Object.freeze(n.children),Object.freeze(n.nonAbsoluteChildren),Object.freeze(n.absoluteDescendants),Object.freeze(n.parentSegments),Object.freeze(n.paramTypeMap),Object.freeze(n)),n}function ct(e){let t="",r=0;for(const n of e)"<"===n?r++:">"===n?r--:0===r&&(t+=n);return function(e){return e.endsWith("/")&&e.length>1?e.slice(0,-1):e}(t.split("?")[0])}function ut(e){!function(e){if(e.length<=1)return;const t=new Map;for(const[r,n]of e.entries()){const e=ct(n.path),o=e.split("/"),a=o.at(-1);t.set(n,{normalizedPath:e,segmentCount:o.length-1,lastSegmentLength:a.length,originalIndex:r})}e.sort((e,r)=>{const n=t.get(e),o=t.get(r);if("/"===n.normalizedPath)return 1;if("/"===o.normalizedPath)return-1;if(e.parser.hasSpatParam)return 1;if(r.parser.hasSpatParam)return-1;if(n.segmentCount<o.segmentCount)return 1;if(n.segmentCount>o.segmentCount)return-1;const a=e.parser.urlParams.length,i=r.parser.urlParams.length;return a<i?-1:a>i||n.lastSegmentLength<o.lastSegmentLength?1:n.lastSegmentLength>o.lastSegmentLength?-1:n.originalIndex-o.originalIndex})}(e.children);for(const t of e.children)ut(t)}var lt=class extends Error{constructor(e){super(e),this.name="RouteNodeError",Object.setPrototypeOf(this,new.target.prototype)}},dt=class extends lt{duplicateValue;duplicateType;constructor(e,t,r){super(e),this.name="DuplicateRouteError",this.duplicateValue=t,this.duplicateType=r}},ft=class extends lt{constructor(e){super(e),this.name="InvalidRouteError"}},pt=class extends lt{routeName;constructor(e,t){super(e),this.name="RouteNotFoundError",this.routeName=t}};function ht(e){if(!e.name||"string"!=typeof e.name)throw new ft("Route definition must have a 'name' property of type string.");if("string"!=typeof e.path)throw new ft(`Route "${e.name}" must have a 'path' property of type string.`)}function mt(e,t){if(t.has(e))throw new dt(`Duplicate route name "${e}" found.`,e,"name");t.add(e)}function gt(e,t,r){const n=r.get(t);if(n?.has(e))throw new dt(`Path "${e}" is already defined`,e,"path");n?n.add(e):r.set(t,new Set([e]))}function yt(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build(n){n?.skipValidation||function(e){const t=new Set,r=new Map,n=[{routes:e,parentPrefix:""}];for(;n.length>0;){const{routes:e,parentPrefix:o}=n.pop();for(const a of e){ht(a);const e=o?`${o}.${a.name}`:a.name;mt(e,t),gt(a.path,o,r),a.children&&a.children.length>0&&n.push({routes:a.children,parentPrefix:e})}}}(r);const o=function(e,t,r){const n=tt({name:e,path:t},null),o=[];for(const e of r)if(e.name.includes("."))o.push(e);else if(e.children&&e.children.length>0){const t=tt(e,n);n.children.push(t)}else o.push(e);for(const e of o){const{parent:t,finalName:r}=rt(n,e.name),o=tt({name:r,path:e.path,children:e.children},t);t.children.push(o)}return n}(e,t,r);return n?.skipSort||ut(o),function(e,t=!0){return st(e,null,t)}(o,!n?.skipFreeze)}}}function wt(e,t,r,n){return yt(e,t).addMany(r).build(n)}var vt=/^\/(\?|$)/,bt=/\/$/,Tt=/^\/\?/;function Et(e){const t=e.startsWith("/")?1:0,r=e.charAt(t);return":"===r||"*"===r||""===r||"("===e.charAt(t)}var St={caseSensitive:!1,strictTrailingSlash:!1},Rt={caseSensitive:!1,strictTrailingSlash:!0},Ot={caseSensitive:!0,strictTrailingSlash:!1},Pt={caseSensitive:!0,strictTrailingSlash:!0},$t={caseSensitive:!1,delimited:!0},At={caseSensitive:!0,delimited:!0},Nt={caseSensitive:!1,delimited:!1},jt={caseSensitive:!0,delimited:!1},xt={queryParamsMode:"default",strictTrailingSlash:!1,strongMatching:!0,caseSensitive:!1,queryParams:void 0,urlParamsEncoding:void 0,fullTestOptions:St,partialTestOptions:$t,buildOptions:{ignoreSearch:!0}};function It(e,t,r,n,o,a){for(const i of e){if(a&&!Et(i.path))continue;const e=Ct(i,t,r,n,!1,o);if(void 0!==e)return e}return null}function Ct(e,t,r,n,o,a){const i=e.parser,s=function(e,t,r){return"/"===r&&"/"===t?`/${e}`:e}(t,e.path,a),c=function(e,t,r,n){if(0===e.children.length){const e=t.test(r,n.fullTestOptions);if(e)return e}return t.partialTest(r,n.partialTestOptions)}(e,i,s,n);if(!c)return;const u=0===e.children.length,l=function(e,t,r,n){let o=e.build(t,r.buildOptions);return!r.strictTrailingSlash&&n&&(o=o.replace(bt,"")),o}(i,c,n,u),d=function(e,t,r,n,o,a){let i=e.slice(t.length);!r.strictTrailingSlash&&n&&(i=i.replace(Tt,"?"));const{querystring:s}=((e,t,r)=>{const n=je(e);if(""===n)return{querystring:"",removedParams:{}};if(0===t.length)return{querystring:e.startsWith("?")?e:n,removedParams:{}};const o=$e(r),a=e.startsWith("?"),i=new Set(t),s=[],c=[];!function(e,t){let r=0;const n=e.length;for(;r<n;){let o=e.indexOf("&",r);-1===o&&(o=n),t(e.slice(r,o)),r=o+1}}(n,e=>{const t=e.indexOf("="),r=-1===t?e:e.slice(0,t),{name:n}=xe(r);i.has(n)?c.push(e):s.push(e)});const u=s.join("&");return{querystring:a&&u?`?${u}`:u,removedParams:Ce(c.join("&"),o)}})(function(e){const t=e.indexOf("?");return-1===t?"":e.slice(t+1)}(e.slice(t.length)),a.queryParams,r.queryParams);return i=function(e){const t=e.indexOf("?");return-1===t?e:e.slice(0,t)}(i)+(s?`?${s}`:""),r.strictTrailingSlash||o||"/"!==i||t.endsWith("/")||(i=""),i}(s,l,n,u,o,i);return r.segments.push(e),Object.assign(r.params,c),function(e,t,r,n,o,a){return o||0!==r.length?function(e,t,r){return!r&&"strict"!==t.queryParamsMode&&e.startsWith("?")}(r,n,o)?function(e,t){return r=t.slice(1),n=e.params,""!==r&&ke(r,n),e;var r,n}(t,r):0===e.nonAbsoluteChildren.length?null:function(e,t,r,n,o){const a=e.staticChildrenByFirstSegment,i=e.nonAbsoluteChildren;if(0===a.size)return It(i,t,r,n,o,!1);const s=function(e){let t=e.indexOf("/",1);const r=e.indexOf("?",1);return-1!==r&&(-1===t||r<t)&&(t=r),(-1===t?e.slice(1):e.slice(1,t)).toLowerCase()}(t),c=a.get(s);if(c){const e=It(c,t,r,n,o,!1);if(null!==e)return e}return It(i,t,r,n,o,!0)}(e,r,t,n,a):t}(e,r,d,n,o,l)}function kt(e,t){const r=[],n=t.includes(".")?t.split("."):[t];e.parser&&r.push(e);let o=e;for(const e of n){const t=o.childrenByName.get(e);if(!t)return null;r.push(t),o=t}return r}var _t=Object.freeze([]);function Mt(e,t,r={},n={},o){if(o)return Dt(o,r,n);const a=function(e){for(const t in e)if(Object.hasOwn(e,t))return!0;return!1}(r),i=function(e){return void 0!==e.trailingSlashMode&&"default"!==e.trailingSlashMode||void 0!==e.queryParamsMode&&"default"!==e.queryParamsMode||void 0!==e.queryParams||void 0!==e.urlParamsEncoding&&"default"!==e.urlParamsEncoding}(n);if(!a&&!i){const r=function(e,t){if(t.includes(".")){const r=kt(e,t),n=r?.at(-1)?.staticPath;return n??null}return e.childrenByName.get(t)?.staticPath??null}(e,t);if(null!==r)return r}const s=kt(e,t);if(!s)throw new pt(`[route-node][buildPath] '${t}' is not defined`,t);return Dt(s,r,n)}function Dt(e,t,r){const{queryParamsMode:n="default",trailingSlashMode:o="default"}=r,a=function(e){let t=null,r=null;for(const n of e){const e=n.parser;if(e.queryParams.length>0){t??=[];for(let r=0;r<e.queryParams.length;r++)t.push(e.queryParams[r])}if(e.urlParams.length>0||e.spatParams.length>0){r??=[];for(let t=0;t<e.urlParams.length;t++)r.push(e.urlParams[t]);for(let t=0;t<e.spatParams.length;t++)r.push(e.spatParams[t])}}return{searchParams:t??_t,nonSearchParams:r??_t}}(e),i=function(e,t,r){if("loose"!==r)return e.searchParams;const n=[...e.searchParams],o=new Set(e.searchParams),a=new Set(e.nonSearchParams);for(const e in t)!Object.hasOwn(t,e)||o.has(e)||a.has(e)||n.push(e);return n}(a,t,n),s=function(e,t,r){const n={};for(const r of e)r in t&&(n[r]=t[r]);return _e(n,r.queryParams)}(i,t,r),c=function(e,t,r){const n={ignoreSearch:!0,queryParams:r.queryParams,urlParamsEncoding:r.urlParamsEncoding};let o="";for(const r of e){const e=r.parser.build(t,n);o=r.absolute?e:o+e}return o.replaceAll(/\/{2,}/g,"/")}(e,t,r);return u=c,("always"===(l=o)?u.endsWith("/")?u:`${u}/`:"never"===l&&"/"!==u&&u.endsWith("/")?u.slice(0,-1):u)+(s?`?${s}`:"");var u,l}function Ut(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return t}function Lt(e){const t={name:e.name,path:e.absolute?`~${e.path}`:e.path};return e.children.length>0&&(t.children=e.children.map(e=>Lt(e))),t}function qt(e,t){return new TypeError(`[router.${e}] ${t}`)}var Ft=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/,Wt=/\S/;function zt(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function Bt(e,t,r,n="",o,a){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${zt(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${zt(e)}`);if(function(e){for(const t of Object.keys(e)){const r=Object.getOwnPropertyDescriptor(e,t);if(r&&(r.get||r.set))return!0}return!1}(e))throw new TypeError(`[router.${t}] Route must not have getters or setters`)}(e,t);const i=e;!function(e,t){if("string"!=typeof e.name)throw new TypeError(`[router.${t}] Route name must be a string, got ${zt(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!Wt.test(r))throw new TypeError(`[router.${t}] Route name cannot contain only whitespace`);if(r.length>1e4)throw new TypeError(`[router.${t}] Route name exceeds maximum length of 10000 characters`);if(!r.startsWith("@@")&&!Ft.test(r))throw new TypeError(`[router.${t}] Invalid route name "${r}". Each segment must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens. Segments are separated by dots (e.g., "users.profile").`)}(i,t),function(e,t,r,n){if("string"!=typeof e){let t;throw t=null===e?"null":Array.isArray(e)?"array":typeof e,qt(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw qt(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw qt(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw qt(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const o=n?.parser&&("urlParams"in n.parser&&n.parser.urlParams.length>0||"hasUrlParams"in n.parser&&n.parser.hasUrlParams);if(e.startsWith("~")&&o)throw new Error(`[router.${r}] Absolute path "${e}" cannot be used under parent route with URL parameters`)}(i.path,i.name,t,r),function(e,t){if(void 0!==e.encodeParams&&"function"!=typeof e.encodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}(i,t),function(e,t){if(void 0!==e.decodeParams&&"function"!=typeof e.decodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}(i,t);const s=i.name,c=n?`${n}.${s}`:s;!n&&c.includes(".")&&function(e,t,r,n){const o=t.split(".");o.pop();const a=o.join(".");if(!n?.has(a)){if(e){const n=a.split(".");let o=e;for(const e of n)if(o=o.childrenByName.get(e),!o)throw new Error(`[router.${r}] Parent route "${a}" does not exist for route "${t}"`);return}throw new Error(`[router.${r}] Parent route "${a}" does not exist for route "${t}"`)}}(r,c,t,o),r&&c&&function(e,t,r){const n=t.split(".");let o=e;for(const e of n)if(o=o.childrenByName.get(e),!o)return;throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),o&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(o,c,t);const u=i.path;let l=n;if(s.includes(".")&&!n){const e=s.split(".");e.pop(),l=e.join(".")}if(r&&function(e,t,r){let n=e;if(""!==t){const e=t.split(".");for(const t of e)if(n=n.childrenByName.get(t),!n)return}for(const e of n.children)if(e.path===r)throw new Error(`Path "${r}" is already defined`)}(r,l,u),a&&function(e,t,r){const n=e.get(t);if(n?.has(r))throw new Error(`Path "${r}" is already defined`);n?n.add(r):e.set(t,new Set([r]))}(a,l,u),void 0!==i.children){if(!Array.isArray(i.children))throw new TypeError(`[router.${t}] Route "${s}" children must be an array, got ${zt(i.children)}`);for(const e of i.children)Bt(e,t,r,c,o,a)}}function Vt(e){return e[t]}function Qt(e,r){e[t]=r}function Zt(e){return e[n]}function Ht(e,t){e[n]=t}function Kt(e){return e[a]}function Gt(e,t){const r=t??function(e){let t="";for(const r of e)r.name&&(t&&(t+="."),t+=r.name);return t}(e.segments);return{name:r,params:e.params,meta:Ut(e.segments)}}var Jt=Symbol("real-router.buildOptionsCache");function Yt(e){return e.buildPath=(t,r)=>{if(!R(t)||""===t)throw new TypeError("[real-router] buildPath: route must be a non-empty string, got "+("string"==typeof t?'""':typeof t));if(t===s.UNKNOWN_ROUTE)return R(r?.path)?r.path:"";const n=Kt(e),o=Object.hasOwn(n.defaultParams,t)?{...n.defaultParams[t],...r}:r??{},a="function"==typeof n.encoders[t]?n.encoders[t]({...o}):o,i=e[Jt]??k(e.getOptions());return Mt(Vt(e),t,a,i)},e.buildPathWithSegments=(t,r,n)=>{if(!R(t)||""===t)throw new TypeError("[real-router] buildPathWithSegments: route must be a non-empty string, got "+("string"==typeof t?'""':typeof t));if(t===s.UNKNOWN_ROUTE)return R(r.path)?r.path:"";const o=Kt(e),a=Object.hasOwn(o.defaultParams,t)?{...o.defaultParams[t],...r}:r,i="function"==typeof o.encoders[t]?o.encoders[t]({...a}):a,c=e[Jt]??k(e.getOptions());return Mt(Vt(e),t,i,c,n)},e.matchPath=(t,r)=>{if(!R(t))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof t);const n=e.getOptions(),o=function(e){return{...k(e),caseSensitive:e.caseSensitive,strictTrailingSlash:"strict"===e.trailingSlash,strongMatching:!1}}(n),a=function(e,t,r={}){let n=t;""!==n||r.strictTrailingSlash||(n="/");const o=function(e,t,r){const n=[];if(e.parser){n.push(e);for(let t=0;t<e.absoluteDescendants.length;t++)n.push(e.absoluteDescendants[t])}else for(const t of e.children){n.push(t);for(let e=0;e<t.absoluteDescendants.length;e++)n.push(t.absoluteDescendants[e])}const o=function(e){return void 0===e.queryParamsMode&&void 0===e.strictTrailingSlash&&void 0===e.strongMatching&&void 0===e.caseSensitive&&void 0===e.queryParams&&void 0===e.urlParamsEncoding&&void 0===e.trailingSlashMode||void 0!==e.trailingSlashMode&&void 0===e.queryParamsMode&&void 0===e.strictTrailingSlash&&void 0===e.strongMatching&&void 0===e.caseSensitive&&void 0===e.queryParams&&void 0===e.urlParamsEncoding?xt:function(e){const t=e.queryParamsMode??"default",r=e.strictTrailingSlash??!1,n=e.strongMatching??!0,o=e.caseSensitive??!1,{queryParams:a,urlParamsEncoding:i}=e,s=void 0===a&&void 0===i;return{queryParamsMode:t,strictTrailingSlash:r,strongMatching:n,caseSensitive:o,queryParams:a,urlParamsEncoding:i,fullTestOptions:s?function(e,t){return e?t?Pt:Ot:t?Rt:St}(o,r):{caseSensitive:o,strictTrailingSlash:r,queryParams:a,urlParamsEncoding:i},partialTestOptions:s?function(e,t){return e?t?At:jt:t?$t:Nt}(o,n):{caseSensitive:o,delimited:n,queryParams:a,urlParamsEncoding:i},buildOptions:{ignoreSearch:!0,urlParamsEncoding:i}}}(e)}(r);return function(e,t,r,n){const o=1===e.length&&""===e[0].name;for(const a of e){const e=Ct(a,t,r,n,o,void 0);if(void 0!==e)return e}return null}(n,t,{segments:[],params:{}},o)}(e,n,r);if(!o)return null;const a=o.segments;if(a[0]?.absolute){const e=a[0].parentSegments;for(let t=e.length-1;t>=0;t--)a.unshift(e[t])}const i=a.at(-1).nonAbsoluteChildren.find(e=>e.parser&&vt.test(e.parser.path));return i&&a.push(i),{segments:a,params:o.params}}(Vt(e),t,o);if(a){const o=Gt(a),{name:i,params:s,meta:c}=o,{decoders:u}=Kt(e),l="function"==typeof u[i]?u[i](s):s,{name:d,params:f}=e.forwardState(i,l),p=n.rewritePathOnMatch?e.buildPath(d,f):t;return e.makeState(d,f,p,{params:c,options:{},source:r,redirected:!1})}},e.setRootPath=t=>{const n=e;n[o]=t,Qt(e,wt("",t,n[r],{skipValidation:!0}))},e.getRootPath=()=>e[o]||"",e}var Xt=()=>{},er=new U(i.NO_START_PATH_OR_STATE),tr=new U(i.ROUTER_ALREADY_STARTED),rr=Symbol("started"),nr=Symbol("active");function or(t){t[rr]=!1,t[nr]=!1;const r=()=>{t[nr]=!1};return t.isStarted=()=>!!t[rr],t.isActive=()=>!!t[nr],t.start=(...n)=>{const o=t.getOptions(),[a,s]=(e=>{if(e.length>2)throw new Error("Invalid number of arguments");const[t,r]=e;return t?"function"==typeof t?[void 0,t]:[t,r??Xt]:[void 0,Xt]})(n);let c=!1;if(t.isStarted()||t.isActive())return c=!0,s(tr),t;if(!a&&!o.defaultRoute)return c=!0,t.hasListeners(h.TRANSITION_ERROR)&&t.invokeEventListeners(h.TRANSITION_ERROR,void 0,void 0,er),s(er),t;t[nr]=!0;const u=(e,r={})=>{t.navigateToState(e,void 0,r,(e,t)=>{d(e,t)},!1)},l={replace:!0},d=(n,o,a=!1)=>{n?(r(),a&&t.hasListeners(h.TRANSITION_ERROR)&&t.invokeEventListeners(h.TRANSITION_ERROR,void 0,void 0,n)):(t[rr]=!0,t.invokeEventListeners(h.ROUTER_START),t.invokeEventListeners(h.TRANSITION_SUCCESS,o,void 0,{replace:!0})),((t,r)=>{c?e.warn("real-router","Callback already invoked"):(c=!0,s(t,r))})(n,o)},f=a??o.defaultRoute,p=((e,t)=>{if("string"==typeof e)return t.matchPath(e);if(S(e)){try{t.buildPath(e.name,e.params)}catch{return}return e}})(f,t),m="string"==typeof f?f:"";return(void 0!==p||o.allowNotFound||o.defaultRoute&&!a)&&function(e,t){delete e[Jt],e[Jt]=k(t)}(t,o),p?u(p,l):o.defaultRoute&&!a?((e,r,n)=>{const o=t.buildState(e,r);if(!o)return void d(new U(i.ROUTE_NOT_FOUND,{routeName:e}),void 0,!0);const a=t.makeState(o.name,o.params,t.buildPath(o.name,o.params),{params:o.meta,options:n,redirected:!1});u(a,n)})(o.defaultRoute,o.defaultParams,l):o.allowNotFound?u(t.makeNotFoundState(m,l),l):d(new U(i.ROUTE_NOT_FOUND,{path:m}),void 0,!0),t},t.stop=()=>(r(),t.isStarted()&&(t[rr]=!1,t.setState(void 0),t.invokeEventListeners(h.ROUTER_STOP)),t),t}function ar(e,t){if(void 0!==e.canActivate&&"function"!=typeof e.canActivate)throw new TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${A(e.canActivate)}`);if(void 0!==e.defaultParams){const r=e.defaultParams;if(null===r||"object"!=typeof r||Array.isArray(r))throw new TypeError(`[router.addRoute] defaultParams must be an object for route "${t}", got ${A(e.defaultParams)}`)}if(e.children)for(const r of e.children)ar(r,`${t}.${r.name}`)}function ir(e){const t=new Set;for(const r of e){const e=r.parser;for(const r of e.urlParams)t.add(r);for(const r of e.spatParams)t.add(r)}return t}function sr(e){const t=new Set,r=/[*:]([A-Z_a-z]\w*)/g;let n;for(;null!==(n=r.exec(e));)t.add(n[1]);return t}function cr(e,t,r="",n=[]){for(const o of e){const e=r?`${r}.${o.name}`:o.name,a=[...n,o.path];if(e===t)return a;if(o.children&&t.startsWith(`${e}.`))return cr(o.children,t,e,a)}}function ur(e){const t=new Set;for(const r of e)for(const e of sr(r))t.add(e);return t}function lr(e,t=""){const r=new Set;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(r.add(e),n.children)for(const t of lr(n.children,e))r.add(t)}return r}function dr(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,o]of dr(n.children,e))r.set(t,o)}return r}function fr(e,t,r,n,o){const a=function(e,t){const r=t.split(".");let n=e;for(const e of r)if(n=n.childrenByName.get(e),!n)return!1;return!0}(o,t),i=n.has(t);if(!a&&!i)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const s=ur(cr(r,e)),c=function(e,t,r,n){return t?ir(kt(r,e)):ur(cr(n,e))}(t,a,o,r),u=[...c].filter(e=>!s.has(e));if(u.length>0)throw new Error(`[router.addRoute] forwardTo target "${t}" requires params [${u.join(", ")}] that are not available in source route "${e}"`)}function pr(e,t,r){const n=lr(e),o=dr(e),a={...t};for(const[e,t]of o)a[e]=t;for(const[t,a]of o)fr(t,a,e,n,r);for(const e of Object.keys(a))mr(e,a)}function hr(e,t){e.canActivate&&t.canActivate(e.name,e.canActivate)}function mr(e,t,r=100){const n=new Set,o=[e];let a=e;for(;t[a];){const e=t[a];if(n.has(e)){const t=o.indexOf(e),r=[...o.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(a),o.push(e),a=e,o.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${o.join(" → ")}`)}return a}function gr(e){const{forwardMap:t}=Kt(e),r={};for(const e of Object.keys(t))r[e]=mr(e,t);Ht(e,r)}function yr(t,r){t.forwardTo&&(t.canActivate&&e.warn("real-router",`Route "${t.name}" has both forwardTo and canActivate. canActivate will be ignored because forwardTo creates a redirect (industry standard). Move canActivate to the target route "${t.forwardTo}".`),Kt(r).forwardMap[t.name]=t.forwardTo)}function wr(e,t){const r=Kt(t);e.decodeParams&&(r.decoders[e.name]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(r.encoders[e.name]=t=>e.encodeParams?.(t)??t)}function vr(e,t){e.defaultParams&&(Kt(t).defaultParams[e.name]=e.defaultParams)}function br(e,t,r=""){for(const n of e){const e=r?`${r}.${n.name}`:n.name,o={...n,name:e};hr(o,t),yr(o,t),wr(o,t),vr(o,t),n.children&&br(n.children,t,e)}}function Tr(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function Er(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>Er(e))),t}function Sr(e,t,r=""){for(let n=0;n<e.length;n++){const o=e[n],a=r?`${r}.${o.name}`:o.name;if(a===t)return e.splice(n,1),!0;if(o.children&&t.startsWith(`${a}.`)&&Sr(o.children,t,a))return!0}return!1}function Rr(e,t,r){void 0!==r&&(null===r?delete e[t]:e[t]=r)}var Or=new Set;function Pr(t){return t.isActiveRoute=(r,n={},o=!1,a=!0)=>{if(Or.has(r)||($(r,"isActiveRoute"),Or.add(r)),function(e){if(!E(e))throw new TypeError(`[router.isActiveRoute] Invalid params structure: ${A(e)}`)}(n),void 0!==o&&"boolean"!=typeof o)throw new TypeError("[router.isActiveRoute] strictEquality must be a boolean, got "+typeof o);if(void 0!==a&&"boolean"!=typeof a)throw new TypeError("[router.isActiveRoute] ignoreQueryParams must be a boolean, got "+typeof a);if(""===r)return e.warn("real-router",'isActiveRoute("") called with empty string. The root node is not considered active for any named route. To check if router has active state, use: router.getState() !== undefined'),!1;const i=t.getState();if(!i)return!1;const s=i.name;if(s!==r&&!s.startsWith(`${r}.`)&&!r.startsWith(`${s}.`))return!1;const c=Kt(t).defaultParams[r];if(o||s===r){const e=c?{...c,...n}:n;return t.areStatesEqual({name:r,params:e,path:""},i,a)}const u=i.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(n,u)&&(!c||function(e,t,r){for(const n in e)if(!(n in r)&&e[n]!==t[n])return!1;return!0}(c,u,n))},t.shouldUpdateNode=e=>{if(!R(e))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof e);return(t,r)=>{if(!t||"object"!=typeof t||!("name"in t))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(t.meta?.options.reload)return!0;if(""===e&&!r)return!0;const{intersection:n,toActivate:o,toDeactivate:a}=re(t,r);return e===n||!!o.includes(e)||a.includes(e)}},t.clone=(e={})=>{const r=Vt(t),n=Cr(function(e){return e.children.map(e=>Lt(e))}(r),t.getOptions(),e);n.useMiddleware(...t.getMiddlewareFactories()),n.usePlugin(...t.getPlugins());const o=Kt(t);!function(e,t){e[a]=t}(n,{decoders:{...o.decoders},encoders:{...o.encoders},defaultParams:structuredClone(o.defaultParams),forwardMap:{...o.forwardMap}}),Ht(n,{...Zt(t)});const[i,s]=t.getLifecycleFactories();for(const e of Object.keys(i))n.canDeactivate(e,i[e]);for(const e of Object.keys(s))n.canActivate(e,s[e]);return n},t}function $r(e){return null===e?"null":Array.isArray(e)?"array":typeof e}function Ar(e,t){if(null!=e){if("function"!=typeof e)throw new TypeError(`[real-router] updateRoute: ${t} must be a function or null, got ${typeof e}`);if("AsyncFunction"===e.constructor.name)throw new TypeError(`[real-router] updateRoute: ${t} cannot be an async function`)}}function Nr(t){return n=>{const a=function(e){return t=>{const r=e=>e===t||e.startsWith(`${t}.`),n=Kt(e);Tr(n.decoders,r),Tr(n.encoders,r),Tr(n.defaultParams,r),Tr(n.forwardMap,r),Tr(n.forwardMap,e=>r(n.forwardMap[e]));const[o,a]=e.getLifecycleFactories();for(const t of Object.keys(a))r(t)&&e.clearCanActivate(t,!0);for(const t of Object.keys(o))r(t)&&e.clearCanDeactivate(t,!0)}}(n),i=(s=Kt(n).forwardMap,(e,t,r,n)=>{const o=kt(n,t);if(!o)throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);const a=ir(r),i=[...ir(o)].filter(e=>!a.has(e));if(i.length>0)throw new Error(`[real-router] updateRoute: forwardTo target "${t}" requires params [${i.join(", ")}] that are not available in source route "${e}"`);s[e]=t});var s;n.forward=(t,r)=>{e.warn("router.forward","Method is deprecated. Use `forwardTo` property in route configuration instead.");const o=Vt(n),a=kt(o,t);if(!a)throw new Error(`[real-router] forward: source route "${t}" does not exist`);const i=kt(o,r);if(!i)throw new Error(`[real-router] forward: target route "${r}" does not exist`);const s=ir(a),c=ir(i),u=[];for(const e of c)s.has(e)||u.push(e);if(u.length>0)throw new Error(`[real-router] forward: target route "${r}" requires params [${u.join(", ")}] that are not available in source route "${t}"`);return Kt(n).forwardMap[t]=r,gr(n),n};const c=n,u=t.map(e=>Er(e));function l(e,t=!1){Qt(n,wt("",c[o],e,{skipValidation:t}))}function d(){return Vt(n)}return c[o]="",Qt(n,wt("",c[o],u)),Ht(n,{}),c[r]=u,br(t,n),gr(n),n.addRoute=e=>{const t=Array.isArray(e)?[...e]:[e];!function(e){const t=new Set,r=new Map;for(const n of e)Bt(n,"addRoute",d(),"",t,r),ar(n,n.name);pr(e,Kt(n).forwardMap,d())}(t);for(const e of t)u.push(Er(e));return br(t,n),l(u,!0),gr(n),n},n.removeRoute=t=>{$(t,"removeRoute");const r=n.getState();if(r){const o=r.name,a=o===t,i=o.startsWith(`${t}.`);if(a||i)return e.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${a?"":` (current: "${o}")`}. Navigate away first.`),n}return n.isNavigating()&&e.warn("router.removeRoute",`Route "${t}" removed while navigation is in progress. This may cause unexpected behavior.`),Sr(u,t)?(a(t),l(u,!0),gr(n),n):(e.warn("router.removeRoute",`Route "${t}" not found. No changes made.`),n)},n.clearRoutes=()=>{if(n.isNavigating())return e.error("router.clearRoutes","Cannot clear routes while navigation is in progress. Wait for navigation to complete."),n;u.length=0;const t=Kt(n);for(const e in t.decoders)delete t.decoders[e];for(const e in t.encoders)delete t.encoders[e];for(const e in t.defaultParams)delete t.defaultParams[e];for(const e in t.forwardMap)delete t.forwardMap[e];const[r,o]=n.getLifecycleFactories();for(const e in o)n.clearCanActivate(e,!0);for(const e in r)n.clearCanDeactivate(e,!0);return n.setState(void 0),l(u,!0),gr(n),n},n.getRoute=e=>{$(e,"getRoute");const t=kt(d(),e);if(!t)return;const r=Lt(t.at(-1)),[,o]=n.getLifecycleFactories(),a=function(e,t){const r=(n,o)=>{const a={name:n.name,path:n.path},i=e.forwardMap[o];return i&&(a.forwardTo=i),o in e.defaultParams&&(a.defaultParams=e.defaultParams[o]),o in e.decoders&&(a.decodeParams=e.decoders[o]),o in e.encoders&&(a.encodeParams=e.encoders[o]),o in t&&(a.canActivate=t[o]),n.children&&(a.children=n.children.map(e=>r(e,`${o}.${e.name}`))),a};return r}(Kt(n),o);return a(r,e)},n.hasRoute=e=>($(e,"hasRoute"),function(e,t){const r=t.includes(".")?t.split("."):[t];let n=e;for(const e of r){const t=n.childrenByName.get(e);if(!t)return!1;n=t}return!0}(d(),e)),n.updateRoute=(t,r)=>{$(t,"updateRoute"),function(e){if(null===e||"object"!=typeof e||Array.isArray(e))throw new TypeError(`[real-router] updateRoute: updates must be an object, got ${$r(e)}`)}(r);const o=d(),a=kt(o,t);if(!a)throw new ReferenceError(`[real-router] updateRoute: route "${t}" does not exist`);n.isNavigating()&&e.error("router.updateRoute",`Route "${t}" config modified while navigation is in progress. Changes will apply immediately and may affect the current transition.`);const s=Kt(n),{forwardTo:c,defaultParams:u,decodeParams:l,encodeParams:f,canActivate:p}=r;return null!=c&&mr(t,{...s.forwardMap,[t]:c}),function(e){if(null!=e&&("object"!=typeof e||Array.isArray(e)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${$r(e)}`)}(u),Ar(l,"decodeParams"),Ar(f,"encodeParams"),void 0!==c&&(null===c?delete s.forwardMap[t]:i(t,c,a,o),gr(n)),Rr(s.defaultParams,t,u),Rr(s.decoders,t,l),Rr(s.encoders,t,f),void 0!==p&&(null===p?n.clearCanActivate(t,!0):n.canActivate(t,p)),n},n}}function jr(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>jr(e,t[r]))}function xr(t){let r,n,o=0;const a=()=>Vt(t),i=new Map;return t.getState=()=>r,t.setState=e=>{void 0!==e&&N(e,"router.setState"),n=r,r=e?Object.isFrozen(e)?e:I(e):void 0},t.getPreviousState=()=>n,t.makeState=(e,r,n,a,i)=>{if(!R(e))throw new TypeError(`[router.makeState] Invalid name: ${A(e)}. Expected string.`);if(void 0!==r&&!E(r))throw new TypeError(`[router.makeState] Invalid params: ${A(r)}. Expected plain object.`);if(void 0!==n&&!R(n))throw new TypeError(`[router.makeState] Invalid path: ${A(n)}. Expected string.`);if(void 0!==i&&"number"!=typeof i)throw new TypeError(`[router.makeState] Invalid forceId: ${A(i)}. Expected number.`);const s=a?{...a,id:i??++o,params:a.params,options:a.options,redirected:a.redirected}:void 0,c=Kt(t).defaultParams;let u;return u=Object.hasOwn(c,e)?{...c[e],...r}:r?{...r}:{},I({name:e,params:u,path:n??t.buildPath(e,r),meta:s})},t.makeNotFoundState=(e,r)=>{if(!R(e))throw new TypeError(`[router.makeNotFoundState] Invalid path: ${A(e)}. Expected string.`);if(void 0!==r&&!g(r))throw new TypeError(`[router.makeNotFoundState] Invalid options: ${A(r)}. Expected NavigationOptions object.`);return t.makeState(s.UNKNOWN_ROUTE,{path:e},e,r?{options:r,params:{},redirected:!1}:void 0)},t.areStatesEqual=(e,t,r=!0)=>{if(!e||!t)return!!e==!!t;if(e.name!==t.name)return!1;if(r){const r=e.meta?.params??t.meta?.params;return(r?function(e){const t=[];for(const r in e){const n=e[r];for(const e in n)"url"===n[e]&&t.push(e)}return t}(r):(e=>{const t=i.get(e);if(void 0!==t)return t;const r=kt(a(),e);if(!r)return i.set(e,[]),[];const n=r.flatMap(e=>e.parser?e.parser.urlParams:[]);return i.set(e,n),n})(e.name)).every(r=>jr(e.params[r],t.params[r]))}const n=Object.keys(e.params),o=Object.keys(t.params);return n.length===o.length&&n.every(r=>r in t.params&&jr(e.params[r],t.params[r]))},t.areStatesDescendants=(t,r)=>(N(t,"areStatesDescendants"),N(r,"areStatesDescendants"),e.warn("real-router","areStatesDescendants is deprecated and will be removed in the next major version. Use router.isActiveRoute() instead."),!!r.name.startsWith(`${t.name}.`)&&Object.keys(t.params).every(e=>jr(t.params[e],r.params[e]))),t.forwardState=(e,r)=>{if(!R(e))throw new TypeError(`[router.forwardState] Invalid routeName: ${A(e)}. Expected string.`);if(!E(r))throw new TypeError(`[router.forwardState] Invalid routeParams: ${A(r)}. Expected plain object.`);const n=Zt(t)[e]??e,{defaultParams:o}=Kt(t),a=Object.hasOwn(o,e),i=Object.hasOwn(o,n);let s;return s=a&&i?{...o[e],...o[n],...r}:a?{...o[e],...r}:i?{...o[n],...r}:r,{name:n,params:s}},t.buildState=(e,r)=>{if(!R(e))throw new TypeError(`[router.buildState] Invalid routeName: ${A(e)}. Expected string.`);if(!E(r))throw new TypeError(`[router.buildState] Invalid routeParams: ${A(r)}. Expected plain object.`);const{name:n,params:o}=t.forwardState(e,r),i=kt(a(),n);if(i)return Gt({segments:i,params:o},n)},t.buildStateWithSegments=(e,r)=>{if(!R(e))throw new TypeError(`[router.buildStateWithSegments] Invalid routeName: ${A(e)}. Expected string.`);if(!E(r))throw new TypeError(`[router.buildStateWithSegments] Invalid routeParams: ${A(r)}. Expected plain object.`);const{name:n,params:o}=t.forwardState(e,r),i=kt(a(),n);if(i)return{state:Gt({segments:i,params:o},n),segments:i}},t}var Ir=new Set(["all","warn-error","error-only"]);var Cr=(t=[],r={},n={})=>{r.logger&&function(e){if("object"!=typeof e||null===e)throw new TypeError("Logger config must be an object");const t=e;for(const e of Object.keys(t))if("level"!==e&&"callback"!==e)throw new TypeError(`Unknown logger config property: "${e}"`);if("level"in t&&void 0!==t.level&&("string"!=typeof(r=t.level)||!Ir.has(r)))throw new TypeError(`Invalid logger level: ${function(e){return"string"==typeof e?`"${e}"`:"object"==typeof e?JSON.stringify(e):String(e)}(t.level)}. Expected: "all" | "warn-error" | "error-only"`);var r;if("callback"in t&&void 0!==t.callback&&"function"!=typeof t.callback)throw new TypeError("Logger callback must be a function, got "+typeof t.callback);return!0}(r.logger)&&(e.configure(r.logger),delete r.logger);const o={[a]:{decoders:{},encoders:{},defaultParams:{},forwardMap:{}}};return((...e)=>t=>e.reduce((e,t)=>t(e),t))(function(e){return t=>{for(const[t,r]of Object.entries(e)){if(!P(t,ue))throw new TypeError(`[router.options] Unknown option: "${t}"`);void 0!==r&&fe(t,r,ue[t],"withOptions")}let r=pe({...ue,...e});return t.getOptions=()=>r,t.setOption=(e,n)=>{if(!R(e))throw new TypeError("[router.setOption]: option name must be a string, got "+typeof e);if(t.isStarted()&&"defaultRoute"!==e&&"defaultParams"!==e)throw new Error("[router.setOption] Options cannot be changed after router.start(). Only defaultRoute/defaultParams can be changed after start.");if(!Object.hasOwn(r,e))throw new ReferenceError(`[router.setOption]: option "${e}" not found`);fe(e,n,ue[e],"setOption");const o=n&&"object"==typeof n&&n.constructor===Object?{...n}:n;return r=pe({...r,[e]:o}),t},t}}(r),function(t){const r=t=>{if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError(`[router.setDependencies] Invalid argument: expected plain object, received ${A(t)}`);for(const e in t)if(Object.getOwnPropertyDescriptor(t,e)?.get)throw new TypeError(`[router.setDependencies] Getters not allowed: "${e}"`);q({...n,...t},"setDependencies");const r=[];for(const e in t)void 0!==t[e]&&(Object.hasOwn(n,e)&&r.push(e),n[e]=t[e]);r.length>0&&e.warn("router.setDependencies","Overwritten:",r.join(", "))},n=Object.create(null);return r(t),t=>(t.setDependency=(r,o)=>{if(void 0===o)return t;if(L("setDependency",r),Object.hasOwn(n,r)){const t=n[r],a=t!==o,i=Number.isNaN(t)&&Number.isNaN(o);a&&!i&&e.warn("router.setDependency","Router dependency already exists and is being overwritten:",r)}else q(n,"setDependency");return n[r]=o,t},t.setDependencies=e=>(r(e),t),t.getDependency=e=>{L("getDependency",e);const t=n[e];if(void 0===t)throw new ReferenceError(`[router.getDependency]: dependency "${String(e)}" not found`);return t},t.getDependencies=()=>({...n}),t.removeDependency=r=>(Object.hasOwn(n,r)||e.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${A(r)}"`),delete n[r],t),t.hasDependency=e=>Object.hasOwn(n,e),t.resetDependencies=()=>{for(const e in n)delete n[e];return t},t)}(n),ce,xr,or,ve,ie,ye,z,function(e){return t=>[Nr(e),Yt,Pr].reduce((e,t)=>t(e),t)}(t))(o)};export{U as RouterError,s as constants,Cr as createRouter,i as errorCodes,h as events};//# sourceMappingURL=index.mjs.map