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