@real-router/core 0.40.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/cjs/{Router-B-Pev7K2.d.ts → Router-DoJ3NWsT.d.ts} +1 -1
  2. package/dist/cjs/{RouterValidator-mx2Zooya.d.ts → RouterValidator-CaIeCVeB.d.ts} +1 -1
  3. package/dist/cjs/api.d.ts +1 -1
  4. package/dist/cjs/api.js +1 -1
  5. package/dist/cjs/api.js.map +1 -1
  6. package/dist/cjs/index.d.ts +3 -3
  7. package/dist/cjs/index.js +1 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/metafile-cjs.json +1 -1
  10. package/dist/cjs/utils.js +1 -1
  11. package/dist/cjs/utils.js.map +1 -1
  12. package/dist/cjs/validation.d.ts +4 -4
  13. package/dist/cjs/validation.js.map +1 -1
  14. package/dist/esm/{Router-B-Pev7K2.d.mts → Router-DoJ3NWsT.d.mts} +1 -1
  15. package/dist/esm/{RouterValidator-mx2Zooya.d.mts → RouterValidator-CaIeCVeB.d.mts} +1 -1
  16. package/dist/esm/api.d.mts +1 -1
  17. package/dist/esm/api.mjs +1 -1
  18. package/dist/esm/{chunk-5QXFUUDL.mjs → chunk-EPF2YSMX.mjs} +1 -1
  19. package/dist/esm/{chunk-5QXFUUDL.mjs.map → chunk-EPF2YSMX.mjs.map} +1 -1
  20. package/dist/esm/chunk-UPJLWPEL.mjs +1 -0
  21. package/dist/esm/chunk-UPJLWPEL.mjs.map +1 -0
  22. package/dist/esm/{chunk-QUUNDESP.mjs → chunk-UUG7DSTN.mjs} +1 -1
  23. package/dist/esm/chunk-UUG7DSTN.mjs.map +1 -0
  24. package/dist/esm/chunk-XQJDGUQE.mjs +1 -0
  25. package/dist/esm/chunk-XQJDGUQE.mjs.map +1 -0
  26. package/dist/esm/index.d.mts +3 -3
  27. package/dist/esm/index.mjs +1 -1
  28. package/dist/esm/metafile-esm.json +1 -1
  29. package/dist/esm/utils.mjs +1 -1
  30. package/dist/esm/validation.d.mts +4 -4
  31. package/dist/esm/validation.mjs +1 -1
  32. package/package.json +4 -3
  33. package/src/Router.ts +4 -6
  34. package/src/api/getPluginApi.ts +2 -3
  35. package/src/helpers.ts +0 -1
  36. package/src/index.ts +0 -1
  37. package/src/internals.ts +4 -5
  38. package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +2 -4
  39. package/src/namespaces/NavigationNamespace/types.ts +0 -7
  40. package/src/namespaces/OptionsNamespace/helpers.ts +0 -1
  41. package/src/namespaces/RouterLifecycleNamespace/types.ts +1 -3
  42. package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +3 -3
  43. package/src/namespaces/RoutesNamespace/types.ts +2 -2
  44. package/src/namespaces/StateNamespace/StateNamespace.ts +30 -34
  45. package/src/namespaces/StateNamespace/helpers.ts +8 -27
  46. package/src/stateMetaStore.ts +15 -0
  47. package/src/transitionPath.ts +13 -16
  48. package/src/types/RouterValidator.ts +0 -1
  49. package/src/wiring/RouterWiringBuilder.ts +1 -3
  50. package/dist/esm/chunk-HHIXK5UM.mjs +0 -1
  51. package/dist/esm/chunk-HHIXK5UM.mjs.map +0 -1
  52. package/dist/esm/chunk-QUUNDESP.mjs.map +0 -1
  53. package/dist/esm/chunk-RA5VYM7M.mjs +0 -1
  54. package/dist/esm/chunk-RA5VYM7M.mjs.map +0 -1
@@ -1,7 +1,7 @@
1
- export { B as BuildStateResultWithSegments, R as RouterValidator } from './RouterValidator-mx2Zooya.js';
2
- import { R as Router } from './Router-B-Pev7K2.js';
1
+ export { B as BuildStateResultWithSegments, R as RouterValidator } from './RouterValidator-CaIeCVeB.js';
2
+ import { R as Router } from './Router-DoJ3NWsT.js';
3
3
  import { ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventToNameMap, State, DefaultDependencies, Route, Options, Router as Router$1, Navigator } from '@real-router/types';
4
- export { Config, DefaultDependencies, GuardFn, GuardFnFactory, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginFactory, Route, RouteConfigUpdate, SimpleState, State, StateMeta, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
4
+ export { Config, DefaultDependencies, GuardFn, GuardFnFactory, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginFactory, Route, RouteConfigUpdate, SimpleState, State, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
5
5
  export { R as RouteTree } from './index.d-y2b-8_3Y.js';
6
6
 
7
7
  type ConstantsKeys = "UNKNOWN_ROUTE";
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- var t=require("@real-router/logger"),e=require("@real-router/fsm"),n={maxListeners:0,warnListeners:0,maxEventDepth:0},r=class extends Error{},i=class{#t=new Map;#e=null;#n=n;#r;#i;constructor(t){t?.limits&&(this.#n=t.limits),this.#r=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.#n=t}on(t,e){const n=this.#s(t);if(n.has(e))throw new Error(`Duplicate listener for "${t}"`);const{maxListeners:r,warnListeners:i}=this.#n;if(0!==i&&n.size===i&&this.#i?.(t,i),0!==r&&n.size>=r)throw new Error(`Listener limit (${r}) reached for "${t}"`);return n.add(e),()=>{this.off(t,e)}}off(t,e){this.#t.get(t)?.delete(e)}emit(t,e,n,r,i){const s=this.#t.get(t);if(!s||0===s.size)return;const a=arguments.length-1;0!==this.#n.maxEventDepth?this.#a(s,t,a,e,n,r,i):this.#o(s,t,a,e,n,r,i)}clearAll(){this.#t.clear(),this.#e=null}listenerCount(t){return this.#t.get(t)?.size??0}#o(t,e,n,r,i,s,a){if(1===t.size){const[o]=t;try{this.#c(o,n,r,i,s,a)}catch(t){this.#r?.(e,t)}return}const o=[...t];for(const t of o)try{this.#c(t,n,r,i,s,a)}catch(t){this.#r?.(e,t)}}#c(t,e,n,r,i,s){switch(e){case 0:t();break;case 1:t(n);break;case 2:t(n,r);break;case 3:t(n,r,i);break;default:t(n,r,i,s)}}#a(t,e,n,i,s,a,o){this.#e??=new Map;const c=this.#e,u=c.get(e)??0;if(u>=this.#n.maxEventDepth)throw new r(`Maximum recursion depth (${this.#n.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,n,i,s,a,o)}catch(t){if(t instanceof r)throw t;this.#r?.(e,t)}}finally{c.set(e,c.get(e)-1)}}#s(t){const e=this.#t.get(t);if(e)return e;const n=new Set;return this.#t.set(t,n),n}},s=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"}),a="@@router/UNKNOWN_ROUTE",o={UNKNOWN_ROUTE:a},c="onStart",u="onStop",l="onTransitionStart",h="onTransitionCancel",d="onTransitionSuccess",f="onTransitionError",p={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},g={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},m=Object.freeze({}),v="IDLE",S="STARTING",T="READY",y="TRANSITIONING",w="DISPOSED",b="START",N="STARTED",A="NAVIGATE",O="COMPLETE",E="FAIL",P="CANCEL",R="STOP",C="DISPOSE",D={initial:v,context:null,transitions:{[v]:{[b]:S,[C]:w},[S]:{[N]:T,[E]:v},[T]:{[A]:y,[E]:T,[R]:v},[y]:{[A]:y,[O]:T,[P]:T,[E]:T},[w]:{}}};function F(t,e){for(const e of t){if(null===e||"object"!=typeof e||Array.isArray(e))throw new TypeError("route must be a non-array object");const t=e.children;t&&F(t)}}var j=new WeakSet;function L(t){if(null!==t&&"object"==typeof t&&!Object.isFrozen(t))if(Object.freeze(t),Array.isArray(t))for(const e of t)L(e);else for(const e in t)L(t[e])}function I(t){return t?(j.has(t)||(L(t),j.add(t)),t):t}var _=new WeakMap;function M(t){const e=_.get(t);if(!e)throw new TypeError("[real-router] Invalid router instance — not found in internals registry");return e}function U(t,e,n){let r=e;for(const e of t){const t=r;r=(...n)=>e(t,...n)}return r(...n)}function $(t,e,n){return(r,i)=>{const s=n.get(t);return s&&0!==s.length?U(s,e,[r,i]):e(r,i)}}var B={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0};function x(t){Object.freeze(t);for(const e of Object.keys(t)){const n=t[e];n&&"object"==typeof n&&n.constructor===Object&&x(n)}return t}function k(t,e){return"function"==typeof t?t(e):t}var z=class{#u;constructor(t={}){this.#u=x({...B,...t})}static validateOptionsIsObject(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("[router.constructor] options must be a plain object")}(t)}get(){return this.#u}};function q(t,e){return t===e||!(!Array.isArray(t)||!Array.isArray(e))&&t.length===e.length&&t.every((t,n)=>q(t,e[n]))}var G=class{#l=0;#h=void 0;#d=void 0;#f;#p=new Map;get(){return this.#h}set(t){this.#d=this.#h,this.#h=t?I(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,n,r,i,s){const a=r?{id:i??++this.#l,params:r}:void 0,o=this.#f.getDefaultParams();let c;c=Object.hasOwn(o,t)?{...o[t],...e}:e&&e!==m?{...e}:m;const u={name:t,params:c,path:n??this.#f.buildPath(t,e),meta:a};return s?u:I(u)}areStatesEqual(t,e,n=!0){if(!t||!e)return!!t==!!e;if(t.name!==e.name)return!1;if(n){const n=t.meta?.params??e.meta?.params;return(n?function(t){const e=[];for(const n in t){const r=t[n];for(const t in r)"url"===r[t]&&e.push(t)}return e}(n):this.#g(t.name)).every(n=>q(t.params[n],e.params[n]))}const r=Object.keys(t.params),i=Object.keys(e.params);return r.length===i.length&&r.every(n=>n in e.params&&q(t.params[n],e.params[n]))}#g(t){const e=this.#p.get(t);if(void 0!==e)return e;const n=this.#f.getUrlParams(t);return this.#p.set(t,n),n}},W={[c]:p.ROUTER_START,[u]:p.ROUTER_STOP,[d]:p.TRANSITION_SUCCESS,[l]:p.TRANSITION_START,[f]:p.TRANSITION_ERROR,[h]:p.TRANSITION_CANCEL},V=Object.keys(W),Q="router.usePlugin",K=class e{#m=new Set;#v=new Set;#f;#S=g;#T=null;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 "+typeof 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.")}(t)}static validateNoDuplicatePlugins(t,e){for(const n of t)if(e(n))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.#S=t,this.#S}setValidatorGetter(t){this.#T=t}count(){return this.#m.size}use(...e){if(this.#T?.()?.plugins.validateCountThresholds(this.#m.size+e.length),1===e.length){const n=e[0],r=this.#y(n);this.#m.add(n);let i=!1;const s=()=>{if(!i){i=!0,this.#m.delete(n),this.#v.delete(s);try{r()}catch(e){t.logger.error(Q,"Error during cleanup:",e)}}};return this.#v.add(s),s}const n=this.#w(e),r=[];try{for(const t of n){const e=this.#y(t);r.push({factory:t,cleanup:e})}}catch(e){for(const{cleanup:e}of r)try{e()}catch(e){t.logger.error(Q,"Cleanup error:",e)}throw e}for(const{factory:t}of r)this.#m.add(t);let i=!1;const s=()=>{if(!i){i=!0,this.#v.delete(s);for(const{factory:t}of r)this.#m.delete(t);for(const{cleanup:e}of r)try{e()}catch(e){t.logger.error(Q,"Error during cleanup:",e)}}};return this.#v.add(s),s}getAll(){return[...this.#m]}has(t){return this.#m.has(t)}disposeAll(){for(const t of this.#v)t();this.#m.clear(),this.#v.clear()}#w(t){const e=new Set;for(const n of t)e.has(n)?this.#T?.()?.plugins.warnBatchDuplicates(t):e.add(n);return e}#y(t){const n=this.#f.compileFactory(t);e.validatePlugin(n),this.#T?.()?.plugins.validatePluginKeys(n),Object.freeze(n);const r=[];for(const t of V)t in n&&("function"==typeof n[t]?(r.push(this.#f.addEventListener(W[t],n[t])),"onStart"===t&&this.#f.canNavigate()&&this.#T?.()?.plugins.warnPluginAfterStart(t)):this.#T?.()?.plugins.warnPluginMethodType(t));return()=>{for(const t of r)t();"function"==typeof n.teardown&&n.teardown()}}},H=class{#b=new Map;#N=new Map;#A=new Map;#O=new Map;#E=[this.#A,this.#O];#P=new Set;#R=new Set;#C=new Set;#f;#S=g;#T=null;setDependencies(t){this.#f=t}setLimits(t){this.#S=t,this.#S}setValidatorGetter(t){this.#T=t}getHandlerCount(t){return"activate"===t?this.#N.size:this.#b.size}addCanActivate(t,e,n=!1){n?this.#R.add(t):this.#R.delete(t);const r=this.#N.has(t);this.#D("activate",t,e,this.#N,this.#O,"canActivate",r)}addCanDeactivate(t,e,n=!1){n?this.#C.add(t):this.#C.delete(t);const r=this.#b.has(t);this.#D("deactivate",t,e,this.#b,this.#A,"canDeactivate",r)}clearCanActivate(t){this.#N.delete(t),this.#O.delete(t),this.#R.delete(t)}clearCanDeactivate(t){this.#b.delete(t),this.#A.delete(t),this.#C.delete(t)}clearAll(){this.#N.clear(),this.#O.clear(),this.#b.clear(),this.#A.clear(),this.#R.clear(),this.#C.clear()}clearDefinitionGuards(){for(const t of this.#R)this.#N.delete(t),this.#O.delete(t);for(const t of this.#C)this.#b.delete(t),this.#A.delete(t);this.#R.clear(),this.#C.clear()}getFactories(){const t={},e={};for(const[e,n]of this.#b)t[e]=n;for(const[t,n]of this.#N)e[t]=n;return[t,e]}getFunctions(){return this.#E}canNavigateTo(t,e,n,r){for(const e of t)if(!this.#F(this.#A,e,n,r,"canNavigateTo"))return!1;for(const t of e)if(!this.#F(this.#O,t,n,r,"canNavigateTo"))return!1;return!0}#D(t,e,n,r,i,s,a){a?this.#T?.()?.lifecycle.warnOverwrite(e,t,s):this.#T?.()?.lifecycle.validateCountThresholds(r.size+1,s);const o="boolean"==typeof n?function(t){const e=()=>t;return()=>e}(n):n;r.set(e,o),this.#P.add(e);try{const t=this.#f.compileFactory(o);if("function"!=typeof t)throw new TypeError(`[router.${s}] Factory must return a function, got ${typeof t}`);i.set(e,t)}catch(t){throw r.delete(e),t}finally{this.#P.delete(e)}}#F(t,e,n,r,i){const s=t.get(e);if(!s)return!0;try{const t=s(n,r);return"boolean"==typeof t?t:(this.#T?.()?.lifecycle.warnAsyncGuardSync(e,i),!1)}catch{return!1}}};function J(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function Y(t){const e={name:t.name,path:t.path};return t.children&&(e.children=t.children.map(t=>Y(t))),e}function X(t){return`(${t.replaceAll(/(^<|>$)/g,"")})`}var Z=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,tt=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,et=/\?(.+)$/,nt=/[^\w!$'()*+,.:;|~-]/gu,rt=/[^\w!$'()*+,.:;|~-]/u,it={default:t=>rt.test(t)?t.replaceAll(nt,t=>encodeURIComponent(t)):t,uri:encodeURI,uriComponent:encodeURIComponent,none:t=>t},st={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 ot(t){return t.length>1&&t.endsWith("/")?t.slice(0,-1):t}function ct(t){const e={};if(0===t.length)return e;const n=t.split("&");for(const t of n){const n=t.indexOf("=");-1===n?e[t]="":e[t.slice(0,n)]=t.slice(n+1)}return e}function ut(t){const e=[];for(const n of Object.keys(t)){const r=t[n],i=encodeURIComponent(n);e.push(""===r?i:`${i}=${encodeURIComponent(String(r))}`)}return e.join("&")}function lt(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function ht(t){let e=0;for(;e<t.length;)if("%"===t[e]){if(e+2>=t.length)return!1;const n=t.codePointAt(e+1)??0,r=t.codePointAt(e+2)??0;if(!lt(n)||!lt(r))return!1;e+=3}else e++;return!0}var dt=/<[^>]*>/g;function ft(t,e,n,r,i){const s=""===e.fullName;s||r.push(e);const a=e.absolute,o=e.paramMeta.pathPattern,c=a&&o.startsWith("~")?o.slice(1):o,u=(a?c:o).replaceAll(dt,""),l=a?u:(d=u,""===(h=n)?d:""===d?h:h+d);var h,d;let f=i;s||(f=function(t,e,n,r,i,s){const a=(m=r,ot(n)===ot(m)),o=Object.freeze([...i]),c=function(t){const e={};for(const n of t)e[n.fullName]=n.paramTypeMap;return Object.freeze(e)}(o),u=ot(n),l=function(t,e){const n=[];t.length>0&&n.push(...t);for(const t of e)t.paramMeta.queryParams.length>0&&n.push(...t.paramMeta.queryParams);return n}(t.rootQueryParams,i),h=function(t){const e=new Map;for(const n of t)for(const[t,r]of n.paramMeta.constraintPatterns)e.set(t,r);return e}(i),d=a?ot(r):u,{buildStaticParts:f,buildParamSlots:p}=function(t,e,n){const r=new Set,i=new Set;for(const t of e){for(const e of t.paramMeta.urlParams)r.add(e);for(const e of t.paramMeta.spatParams)i.add(e)}if(0===r.size)return{buildStaticParts:[t],buildParamSlots:[]};const s=[],a=[],o=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,u=0;for(;null!==(c=o.exec(t));){const e=c[1],r="?"===c[2];s.push(t.slice(u,c.index));const o=i.has(e);a.push({paramName:e,isOptional:r,encoder:o?t=>{const e=it[n],r=t.split("/");let i=e(r[0]);for(let t=1;t<r.length;t++)i+=`/${e(r[t])}`;return i}:it[n]}),u=c.index+c[0].length}return s.push(t.slice(u)),{buildStaticParts:s,buildParamSlots:a}}(d,a?i.slice(0,-1):i,t.options.urlParamsEncoding),g={name:e.fullName,parent:s,depth:i.length-1,matchSegments:o,meta:c,declaredQueryParams:l,declaredQueryParamsSet:new Set(l),hasTrailingSlash:n.length>1&&n.endsWith("/"),constraintPatterns:h,hasConstraints:h.size>0,buildStaticParts:f,buildParamSlots:p,buildParamNamesSet:new Set(p.map(t=>t.paramName))};var m;return t.routesByName.set(e.fullName,g),t.segmentsByName.set(e.fullName,o),t.metaByName.set(e.fullName,c),a?function(t,e,n){var r,i;r=e,(function(t,e,n){const r=ot(n);if("/"===r||""===r)return e;let i=e,s=1;const a=r.length;for(;s<=a;){const e=r.indexOf("/",s),n=-1===e?a:e;if(n<=s)break;i=gt(t,i,r.slice(s,n)),s=n+1}return i}(i=t,i.root,n)).slashChildRoute=r;const s=ot(n),a=t.options.caseSensitive?s:s.toLowerCase();t.staticCache.has(a)&&t.staticCache.set(a,e)}(t,g,r):function(t,e,n,r,i){if(function(t,e,n){const r=ot(n);"/"!==r?pt(t,t.root,r,1,e):t.root.route=e}(t,e,n),0===i.paramMeta.urlParams.length){const n=t.options.caseSensitive?r:r.toLowerCase();t.staticCache.set(n,e)}}(t,g,n,u,e),g}(t,e,l,a?"":n,r,i));for(const n of e.children.values())ft(t,n,l,r,f);s||r.pop()}function pt(t,e,n,r,i){const s=n.length;for(;r<=s;){const a=n.indexOf("/",r),o=-1===a?s:a,c=n.slice(r,o);if(c.endsWith("?")){const r=c.slice(1).replaceAll(dt,"").replace(/\?$/,"");return e.paramChild??={node:at(),name:r},pt(t,e.paramChild.node,n,o+1,i),void(o>=s?e.route??=i:pt(t,e,n,o+1,i))}e=gt(t,e,c),r=o+1}e.route=i}function gt(t,e,n){if(n.startsWith("*")){const t=n.slice(1);return e.splatChild??={node:at(),name:t},e.splatChild.node}if(n.startsWith(":")){const t=n.slice(1).replaceAll(dt,"").replace(/\?$/,"");return e.paramChild??={node:at(),name:t},e.paramChild.node}const r=t.options.caseSensitive?n:n.toLowerCase();return r in e.staticChildren||(e.staticChildren[r]=at()),e.staticChildren[r]}var mt=/[\u0080-\uFFFF]/,vt=class{get options(){return this.#t}#t;#e=at();#i=new Map;#s=new Map;#n=new Map;#a=new Map;#r="";#j=[];constructor(t){this.#t={caseSensitive:t?.caseSensitive??!0,strictTrailingSlash:t?.strictTrailingSlash??!1,strictQueryParams:t?.strictQueryParams??!1,urlParamsEncoding:t?.urlParamsEncoding??"default",parseQueryString:t?.parseQueryString??ct,buildQueryString:t?.buildQueryString??ut}}registerTree(t){this.#j=t.paramMeta.queryParams,ft({root:this.#e,options:this.#t,routesByName:this.#i,segmentsByName:this.#s,metaByName:this.#n,staticCache:this.#a,rootQueryParams:this.#j},t,"",[],null)}match(t){const e=this.#c(t);if(!e)return;const[n,r,i]=e,s=this.#t.caseSensitive?r:r.toLowerCase(),a=this.#a.get(s);if(a){if(this.#t.strictTrailingSlash&&!this.#o(n,a))return;return this.#L(a,{},i)}const o={},c=this.#I(r,o);return!c||this.#t.strictTrailingSlash&&!this.#o(n,c)||c.hasConstraints&&!this.#_(o,c)||!this.#M(o)?void 0:this.#L(c,o,i)}buildPath(t,e,n){const r=this.#i.get(t);if(!r)throw new Error(`[SegmentMatcher.buildPath] '${t}' is not defined`);r.hasConstraints&&e&&this.#U(r,t,e);const i=this.#$(r,e),s=this.#B(i,n?.trailingSlash),a=this.#x(r,e,n?.queryParamsMode);return s+(a?`?${a}`:"")}getSegmentsByName(t){return this.#s.get(t)}getMetaByName(t){return this.#n.get(t)}hasRoute(t){return this.#i.has(t)}setRootPath(t){this.#r=t}#U(t,e,n){for(const[r,i]of t.constraintPatterns){const t=n[r];if(null!=t){const n="object"==typeof t?JSON.stringify(t):String(t);if(!i.pattern.test(n))throw new Error(`[SegmentMatcher.buildPath] '${e}' — param '${r}' value '${n}' does not match constraint '${i.constraint}'`)}}}#$(t,e){const n=t.buildStaticParts,r=t.buildParamSlots;if(0===r.length)return this.#r+n[0];let i=this.#r+n[0];for(const[t,s]of r.entries()){const r=e?.[s.paramName];if(null==r){if(!s.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${s.paramName}'`);i.length>1&&i.endsWith("/")&&(i=i.slice(0,-1)),i+=n[t+1];continue}const a="object"==typeof r?JSON.stringify(r):String(r);i+=s.encoder(a)+n[t+1]}return i}#B(t,e){return"always"!==e||t.endsWith("/")?"never"===e&&"/"!==t&&t.endsWith("/")?t.slice(0,-1):t:`${t}/`}#x(t,e,n){if(!e)return"";const r={};let i=!1;for(const n of t.declaredQueryParams)n in e&&(r[n]=e[n],i=!0);if("loose"===n)for(const n in e)!Object.hasOwn(e,n)||t.declaredQueryParamsSet.has(n)||t.buildParamNamesSet.has(n)||(r[n]=e[n],i=!0);return i?this.#t.buildQueryString(r):""}#c(t){if(""===t&&(t="/"),!t.startsWith("/"))return;const e=t.indexOf("#");if(-1!==e&&(t=t.slice(0,e)),mt.test(t))return;if(this.#r.length>0){if(!t.startsWith(this.#r))return;t=t.slice(this.#r.length)||"/"}const n=t.indexOf("?"),r=-1===n?t:t.slice(0,n),i=-1===n?void 0:t.slice(n+1);return r.includes("//")?void 0:[r,ot(r),i]}#L(t,e,n){if(void 0!==n){const r=this.#t.parseQueryString(n);if(this.#t.strictQueryParams){const e=t.declaredQueryParamsSet;for(const t of Object.keys(r))if(!e.has(t))return}for(const t of Object.keys(r))e[t]=r[t]}return{segments:t.matchSegments,params:e,meta:t.meta}}#o(t,e){return(t.length>1&&t.endsWith("/"))===e.hasTrailingSlash}#I(t,e){return 1===t.length?this.#e.slashChildRoute??this.#e.route:this.#k(this.#e,t,1,e)}#k(t,e,n,r){let i=t;const s=e.length;for(;n<=s;){const t=e.indexOf("/",n),a=-1===t?s:t,o=e.slice(n,a),c=this.#t.caseSensitive?o:o.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,n,t);return s?(Object.assign(r,t),s):(r[i.splatChild.name]=e.slice(n),i.splatChild.node.route)}return}u=i.paramChild.node,r[i.paramChild.name]=o}i=u,n=a+1}return i.slashChildRoute??i.route}#M(t){const e=this.#t.urlParamsEncoding;if("none"===e)return!0;const n=st[e];for(const e in t){const r=t[e];if(r.includes("%")){if(!ht(r))return!1;t[e]=n(r)}}return!0}#_(t,e){for(const[n,r]of e.constraintPatterns)if(!r.pattern.test(t[n]))return!1;return!0}},St=t=>{const e=t.indexOf("%"),n=t.indexOf("+");if(-1===e&&-1===n)return t;const r=-1===n?t:t.split("+").join(" ");return-1===e?r:decodeURIComponent(r)},Tt=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)},yt={none:{encodeArray:(t,e)=>e.map(e=>`${t}=${Tt(e)}`).join("&")},brackets:{encodeArray:(t,e)=>e.map(e=>`${t}[]=${Tt(e)}`).join("&")},index:{encodeArray:(t,e)=>e.map((e,n)=>`${t}[${n}]=${Tt(e)}`).join("&")},comma:{encodeArray:(t,e)=>`${t}=${e.map(t=>Tt(t)).join(",")}`}},wt={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:()=>""}},Nt=(t,e,n)=>({boolean:wt[e],null:bt[n],array:yt[t]}),At={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:wt.none,null:bt.default,array:yt.none}},Ot=t=>{if(!t||void 0===t.arrayFormat&&void 0===t.booleanFormat&&void 0===t.nullFormat)return At;const e=t.arrayFormat??"none",n=t.booleanFormat??"none",r=t.nullFormat??"default";return{arrayFormat:e,booleanFormat:n,nullFormat:r,strategies:Nt(e,n,r)}},Et=t=>encodeURIComponent(t),Pt=(t,e,n)=>{const r=Et(t);switch(typeof e){case"string":case"number":default:return`${r}=${Et(e)}`;case"boolean":return n.strategies.boolean.encode(r,e);case"object":return null===e?n.strategies.null.encode(r):Array.isArray(e)?n.strategies.array.encodeArray(r,e):`${r}=${Et(e)}`}};function Rt(t,e,n,r,i){const s=t.indexOf("=",e),a=-1!==s&&s<n,o=t.slice(e,a?s:n),{name:c,hasBrackets:u}=function(t){const e=t.indexOf("[");return-1===e?{name:t,hasBrackets:!1}:{name:t.slice(0,e),hasBrackets:!0}}(o);var l,h,d,f,p;!function(t,e,n,r){const i=t[e];void 0===i?t[e]=r?[n]:n:Array.isArray(i)?i.push(n):t[e]=[i,n]}(r,St(c),(l=t,h=s,d=n,f=a,p=i,p?((t,e)=>{if(void 0===t)return e.boolean.decodeUndefined();const n=e.boolean.decodeRaw(t);if(null!==n)return n;const r=St(t);return e.boolean.decodeValue(r)})(f?l.slice(h+1,d):void 0,p):f?St(l.slice(h+1,d)):null),u)}function Ct(t,e){const n=t.path,r=n.startsWith("~"),i=r?n.slice(1):n,s={name:t.name,path:i,absolute:r,children:[],parent:e,nonAbsoluteChildren:[],fullName:""};if(t.children)for(const e of t.children){const t=Ct(e,s);s.children.push(t)}return s}function Dt(t,e){return t.endsWith("/")&&e.startsWith("/")?t+e.slice(1):t+e}function Ft(t){const e=new Map;for(const n of t)e.set(n.name,n);return e}function jt(t,e,n){const r=function(t){const e=[],n=[],r=[],i={},s=new Map,a=t.replaceAll(tt,"$1"),o=et.exec(a);if(null!==o){const e=o[1].split("&");for(const t of e){const e=t.trim();e.length>0&&(n.push(e),i[e]="query")}t=t.slice(0,o.index)}let c;for(;null!==(c=Z.exec(t));){const t=c[2],n=c[3];if("*"===c[1])r.push(t),e.push(t),i[t]="url";else if(e.push(t),i[t]="url",n){const e=`^${X(n)}$`;s.set(t,{pattern:new RegExp(e),constraint:n})}}return{urlParams:e,queryParams:n,spatParams:r,paramTypeMap:i,constraintPatterns:s,pathPattern:t}}(t.path),i=function(t){const e={};for(const n of t.urlParams)e[n]="url";for(const n of t.queryParams)e[n]="query";return e}(r),s={name:t.name,path:t.path,absolute:t.absolute,parent:e,children:void 0,paramMeta:r,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:i};var a;s.fullName=(a=s,a.parent?.name?`${a.parent.fullName}.${a.name}`:a.name);const{childrenMap:o,nonAbsoluteChildren:c}=function(t,e,n){const r=[],i=[];for(const s of t){const t=jt(s,e,n);r.push(t),t.absolute||i.push(t)}return{childrenMap:Ft(r),nonAbsoluteChildren:i}}(t.children,s,n);return s.children=o,s.nonAbsoluteChildren=c,s.staticPath=function(t){if(!t.path)return null;const{urlParams:e,queryParams:n,spatParams:r}=t.paramMeta;if(e.length>0||n.length>0||r.length>0)return null;const i=[];let s=t.parent;for(;s?.path;)i.unshift(s),s=s.parent;let a="";for(const t of i){const{urlParams:e,queryParams:n,spatParams:r}=t.paramMeta;if(e.length>0||n.length>0||r.length>0)return null;a=t.absolute?t.path:Dt(a,t.path)}return t.absolute?t.path:Dt(a,t.path)}(s),n&&(Object.freeze(c),Object.freeze(i),Object.freeze(s.children),Object.freeze(s)),s}function Lt(t,e,n,r){return function(t,e){const n=[];return{add(t){return n.push(t),this},addMany(t){return n.push(...t),this},build:r=>function(t,e=!0){return jt(t,null,e)}(function(t,e,n){const r=Ct({name:t,path:e},null);for(const t of n){const e=Ct(t,r);r.children.push(e)}return r}(t,e,n),!r?.skipFreeze)}}(t,e).addMany(n).build(r)}function It(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=>It(t))),e}function _t(t){const e=t?.queryParams;return new vt({...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 n=(t=>{const e=t.indexOf("?");return-1===e?t:t.slice(e+1)})(t);if(""===n||"?"===n)return{};if(!e)return function(t){const e={};return function(t,e){let n=0;const r=t.length;for(;n<r;){let i=t.indexOf("&",n);-1===i&&(i=r),Rt(t,n,i,e),n=i+1}}(t,e),e}(n);const r=Ot(e),i={};let s=0;const a=n.length;for(;s<a;){let t=n.indexOf("&",s);-1===t&&(t=a),Rt(n,s,t,i,r.strategies),s=t+1}return i})(t,e),buildQueryString:t=>((t,e)=>{const n=Object.keys(t);if(0===n.length)return"";const r=Ot(e),i=[];for(const e of n){const n=t[e];if(void 0===n)continue;const s=Pt(e,n,r);s&&i.push(s)}return i.join("&")})(t,e)})}function Mt(t,e,n=100){const r=new Set,i=[t];let s=t;for(;e[s];){const t=e[s];if(r.has(t)){const e=i.indexOf(t),n=[...i.slice(e),t];throw new Error(`Circular forwardTo: ${n.join(" → ")}`)}if(r.add(s),i.push(t),s=t,i.length>n)throw new Error(`forwardTo chain exceeds maximum depth (${n}): ${i.join(" → ")}`)}return s}function Ut(t,e,n){const r=Lt("",e,t),i=_t(n);return i.registerTree(r),{tree:r,matcher:i}}function $t(t){const e=Ut(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher,t.resolvedForwardMap=kt(t.config)}function Bt(t){const e=Ut(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher}function xt(t){!function(t){t.definitions.length=0,Object.assign(t.config,J()),t.resolvedForwardMap=Object.create(null),t.routeCustomFields=Object.create(null)}(t),Bt(t)}function kt(t){const e=Object.create(null);for(const n of Object.keys(t.forwardMap))e[n]=Mt(n,t.forwardMap);return e}function zt(e,n,r,i,s,a,o){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[n]=u),e.canActivate&&s.set(n,e.canActivate),e.canDeactivate&&a.set(n,e.canDeactivate),e.forwardTo&&function(e,n,r){if(e.canActivate&&t.logger.warn("real-router",`Route "${n}" 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 "${n}" 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,r=e.forwardTo.toString().includes("__awaiter");if(t||r)throw new TypeError(`forwardTo callback cannot be async for route "${n}". Async functions break matchPath/buildPath.`)}"string"==typeof e.forwardTo?r.forwardMap[n]=e.forwardTo:r.forwardFnMap[n]=e.forwardTo}(e,n,r),e.decodeParams&&(r.decoders[n]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(r.encoders[n]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(r.defaultParams[n]=e.defaultParams)}function qt(t,e,n,r,i,s,a=""){for(const o of t){const t=a?`${a}.${o.name}`:o.name;zt(o,t,e,n,r,i),o.children&&qt(o.children,e,n,r,i,s,t)}}function Gt(t,e){const n=[],r=J(),i=Object.create(null),s=new Map,a=new Map;for(const e of t)n.push(Y(e));const{tree:o,matcher:c}=Ut(n,"",e);return qt(t,r,i,s,a,void 0,""),{definitions:n,config:r,tree:o,matcher:c,resolvedForwardMap:kt(r),routeCustomFields:i,rootPath:"",matcherOptions:e,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:s,pendingCanDeactivate:a,treeOperations:{commitTreeChanges:$t,resetStore:xt,nodeToDefinition:It}}}var Wt=".",Vt=[];function Qt(t){const e=[];for(let n=t.length-1;n>=0;n--)e.push(t[n]);return e}function Kt(t){const e=typeof t;return"string"===e||"number"===e||"boolean"===e}function Ht(t,e,n){const r=e.meta?.params[t];if(!r||"object"!=typeof r)return!0;for(const t of Object.keys(r)){const r=e.params[t],i=n.params[t];if(Kt(r)&&Kt(i)&&String(r)!==String(i))return!1}return!0}Object.freeze(Vt);var Jt,Yt,Xt=new Map;function Zt(t){const e=Xt.get(t);if(e)return e;const n=function(t){if(!t)return[""];const e=t.indexOf(Wt);if(-1===e)return[t];const n=t.indexOf(Wt,e+1);if(-1===n)return[t.slice(0,e),t];const r=t.indexOf(Wt,n+1);if(-1===r)return[t.slice(0,e),t.slice(0,n),t];return-1===t.indexOf(Wt,r+1)?[t.slice(0,e),t.slice(0,n),t.slice(0,r),t]:function(t){const e=t.split(Wt),n=e.length,r=[e[0]];let i=e[0].length;for(let s=1;s<n-1;s++)i+=1+e[s].length,r.push(t.slice(0,i));return r.push(t),r}(t)}(t);return Object.freeze(n),Xt.set(t,n),n}var te,ee,ne=null,re=null;function ie(t,e){if(!e)return{intersection:"",toActivate:Zt(t.name),toDeactivate:Vt};if(void 0===t.meta?.params&&void 0===e.meta?.params)return{intersection:"",toActivate:Zt(t.name),toDeactivate:Qt(Zt(e.name))};const n=Zt(t.name),r=Zt(e.name),i=function(t,e,n,r,i){for(let s=0;s<i;s++){const i=n[s];if(i!==r[s])return s;if(!Ht(i,t,e))return s}return i}(t,e,n,r,Math.min(r.length,n.length));let s;if(i>=r.length)s=Vt;else if(0===i&&1===r.length)s=r;else{s=[];for(let t=r.length-1;t>=i;t--)s.push(r[t])}const a=0===i?n:n.slice(i);return{intersection:i>0?r[i-1]:"",toDeactivate:s,toActivate:a}}function se(t,e,n){if(n)return ie(t,e);if(null!==ne&&t===Jt&&e===Yt)return ne;if(null!==re&&t===te&&e===ee)return re;const r=ie(t,e);return te=Jt,ee=Yt,re=ne,Jt=t,Yt=e,ne=r,r}function ae(t,e){var n;return{name:e??(n=t.segments,n.at(-1)?.fullName??""),params:t.params,meta:t.meta}}var oe=class{#z;#q;get#f(){return this.#z.depsStore}constructor(t=[],e){this.#z=Gt(t,e)}static shouldUpdateNode(t){return(e,n)=>{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&&!n)return!0;const{intersection:r,toActivate:i,toDeactivate:s}=se(e,n);return t===r||!!i.includes(t)||s.includes(t)}}setDependencies(t){this.#z.depsStore=t;for(const[e,n]of this.#z.pendingCanActivate)t.addActivateGuard(e,n);this.#z.pendingCanActivate.clear();for(const[e,n]of this.#z.pendingCanDeactivate)t.addDeactivateGuard(e,n);this.#z.pendingCanDeactivate.clear()}setLifecycleNamespace(t){this.#z.lifecycleNamespace=t}setRootPath(t){this.#z.rootPath=t,Bt(this.#z)}hasRoute(t){return this.#z.matcher.hasRoute(t)}clearRoutes(){xt(this.#z)}buildPath(t,e,n){if(t===o.UNKNOWN_ROUTE)return"string"==typeof e?.path?e.path:"";const r=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]({...r}):r;return this.#z.matcher.buildPath(t,i,this.#G(n))}matchPath(t,e){const n=e,r=this.#z.matcher.match(t);if(!r)return;const i=ae(r),{name:s,params:a,meta:o}=i,c="function"==typeof this.#z.config.decoders[s]?this.#z.config.decoders[s](a):a,{name:u,params:l}=this.#f.forwardState(s,c);let h=t;if(n.rewritePathOnMatch){const t="function"==typeof this.#z.config.encoders[u]?this.#z.config.encoders[u]({...l}):l,e=n.trailingSlash;h=this.#z.matcher.buildPath(u,t,{trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:n.queryParamsMode})}return this.#f.makeState(u,l,h,o)}forwardState(t,e){if(Object.hasOwn(this.#z.config.forwardFnMap,t)){const n=this.#W(t,e),r=this.#z.config.forwardFnMap[t],i=this.#V(t,r,e);return{name:i,params:this.#W(i,n)}}const n=this.#z.resolvedForwardMap[t]??t;if(n!==t&&Object.hasOwn(this.#z.config.forwardFnMap,n)){const r=this.#W(t,e),i=this.#z.config.forwardFnMap[n],s=this.#V(n,i,e);return{name:s,params:this.#W(s,r)}}if(n!==t){const r=this.#W(t,e);return{name:n,params:this.#W(n,r)}}return{name:t,params:this.#W(t,e)}}buildStateResolved(t,e){const n=this.#z.matcher.getSegmentsByName(t);if(n)return ae({segments:n,params:e,meta:this.#z.matcher.getMetaByName(t)},t)}isActiveRoute(t,e={},n=!1,r=!0){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 a=this.#z.config.defaultParams[t];if(n||s===t){const n=a?{...a,...e}:e;return this.#f.areStatesEqual({name:t,params:n,path:""},i,r)}const o=i.params;return!!function(t,e){for(const n in t)if(t[n]!==e[n])return!1;return!0}(e,o)&&(!a||function(t,e,n){for(const r in t)if(!(r in n)&&t[r]!==e[r])return!1;return!0}(a,o,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 n of t)for(const t of n.paramMeta.urlParams)e.push(t);return e}(e):[]}getStore(){return this.#z}#W(t,e){return Object.hasOwn(this.#z.config.defaultParams,t)?{...this.#z.config.defaultParams[t],...e}:e}#G(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,n){const r=new Set([t]);let i=e(this.#f.getDependency,n),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(r.has(i)){const t=[...r,i].join(" → ");throw new Error(`Circular forwardTo detected: ${t}`)}if(r.add(i),Object.hasOwn(this.#z.config.forwardFnMap,i)){i=(0,this.#z.config.forwardFnMap[i])(this.#f.getDependency,n),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")}},ce=new Set(Object.values(s)),ue=new Set(["code","segment","path","redirect"]),le=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),he=class extends Error{segment;path;redirect;code;constructor(t,{message:e,segment:n,path:r,redirect:i,...s}={}){super(e??t),this.code=t,this.segment=n,this.path=r,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 n=structuredClone(t),r=new WeakSet;return function t(e){if(null===e||"object"!=typeof e)return;if(r.has(e))return;r.add(e),Object.freeze(e);const n=Array.isArray(e)?e:Object.values(e);for(const e of n)t(e)}(n),n}(i):void 0;for(const[t,e]of Object.entries(s)){if(ue.has(t))throw new TypeError(`[RouterError] Cannot set reserved property "${t}"`);le.has(t)||(this[t]=e)}}setCode(t){this.code=t,ce.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,n]of Object.entries(t)){if(ue.has(e))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${e}"`);le.has(e)||(this[e]=n)}}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 n in this)Object.hasOwn(this,n)&&!e.has(n)&&(t[n]=this[n]);return t}},de=new he(s.ROUTER_NOT_STARTED),fe=new he(s.ROUTE_NOT_FOUND),pe=new he(s.SAME_STATES),ge=Promise.reject(de),me=Promise.reject(fe),ve=Promise.reject(pe);function Se(t,e){const{toState:n,fromState:r,opts:i,toDeactivate:a,toActivate:c,intersection:u}=e;if(n.name!==o.UNKNOWN_ROUTE&&!t.hasRoute(n.name)){const e=new he(s.ROUTE_NOT_FOUND,{routeName:n.name});throw t.sendTransitionFail(n,r,e),e}if(r)for(const n of a)!c.includes(n)&&e.canDeactivateFunctions.has(n)&&t.clearCanDeactivate(n);n.transition=function(t,e,n,r,i){const s={phase:"activating",reason:"success",segments:{deactivated:n,activated:r,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}(r,i,a,c,u);const l=I(n);t.setState(l);const h=void 0===i.signal?i:function({signal:t,...e}){return e}(i);return t.sendTransitionDone(l,r,h),l}function Te(t,e,n,r){e.code!==s.TRANSITION_CANCELLED&&e.code!==s.ROUTE_NOT_FOUND&&t.sendTransitionFail(n,r,e)}function ye(t,e,n){if(t instanceof DOMException&&"AbortError"===t.name)throw new he(s.TRANSITION_CANCELLED);!function(t,e,n){if(t instanceof he)throw t.setCode(e),t;throw new he(e,function(t,e){const n={segment:e};if(t instanceof Error)return{...n,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[n,r]of Object.entries(t))we.has(n)||(e[n]=r);return{...n,...e}}return n}(t,n))}(t,e,n)}ge.catch(()=>{}),me.catch(()=>{}),ve.catch(()=>{});var we=new Set(["code","segment","path","redirect"]);async function be(t,e,n){let r;try{r=await t}catch(t){return void ye(t,e,n)}if(!r)throw new he(e,{segment:n})}async function Ne(t,e,n,r,i,a,o,c,u,l){await be(u,n,l);for(let u=c;u<e.length;u++){if(!o())throw new he(s.TRANSITION_CANCELLED);const c=e[u],l=t.get(c);if(!l)continue;let h=!1;try{h=l(r,i,a)}catch(t){ye(t,n,c)}if(h instanceof Promise)await be(h,n,c);else if(!h)throw new he(n,{segment:c})}}function Ae(t,e,n,r,i,a,o){for(const[c,u]of e.entries()){if(!o())throw new he(s.TRANSITION_CANCELLED);const l=t.get(u);if(!l)continue;let h=!1;try{h=l(r,i,a)}catch(t){ye(t,n,u)}if(h instanceof Promise)return Ne(t,e,n,r,i,a,o,c+1,h,u);if(!h)throw new he(n,{segment:u})}}var Oe=[o.UNKNOWN_ROUTE];Object.freeze(Oe);var Ee={replace:!0};Object.freeze(Ee);var Pe=class{lastSyncResolved=!1;lastSyncRejected=!1;#f;#Q=null;#K=0;setDependencies(t){this.#f=t}navigate(t,e,n){this.lastSyncResolved=!1;const r=this.#f;if(!r.canNavigate())return this.lastSyncRejected=!0,ge;let i,a,c=!1,u=null;try{if(i=r.buildNavigateState(t,e),!i)return r.emitTransitionError(void 0,r.getState(),fe),this.lastSyncRejected=!0,me;if(a=r.getState(),n=function(t,e){return e?.name!==o.UNKNOWN_ROUTE||t.replace?t:{...t,replace:!0}}(n,a),function(t,e,n,r){return!!t&&!e.reload&&!e.force&&r(t,n,!1)}(a,n,i,r.areStatesEqual))return r.emitTransitionError(i,a,pe),this.lastSyncRejected=!0,ve;if(this.#H(),n.signal?.aborted)throw new he(s.TRANSITION_CANCELLED,{reason:n.signal.reason});const l=++this.#K;if(r.startTransition(i,a),c=!0,this.#K!==l)throw new he(s.TRANSITION_CANCELLED);const[h,d]=r.getLifecycleFunctions(),f=i.name===o.UNKNOWN_ROUTE,{toDeactivate:p,toActivate:g,intersection:m}=se(i,a,n.reload),v=a&&!n.forceDeactivate&&p.length>0,S=!f&&g.length>0;if(h.size>0||d.size>0){u=new AbortController,this.#Q=u;const t=()=>this.#K===l&&r.isActive(),e=function(t,e,n,r,i,a,o,c,u,l){if(i){const i=Ae(t,n,s.CANNOT_DEACTIVATE,o,c,u,l);if(void 0!==i)return async function(t,e,n,r,i,a,o,c){if(await t,!c())throw new he(s.TRANSITION_CANCELLED);if(r){const t=Ae(e,n,s.CANNOT_ACTIVATE,i,a,o,c);if(void 0!==t&&await t,!c())throw new he(s.TRANSITION_CANCELLED)}}(i,e,r,a,o,c,u,l)}if(!l())throw new he(s.TRANSITION_CANCELLED);if(a)return Ae(e,r,s.CANNOT_ACTIVATE,o,c,u,l)}(h,d,p,g,!!v,S,i,a,u.signal,t);if(void 0!==e)return this.#J(e,{toState:i,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h},u,l);if(!t())throw new he(s.TRANSITION_CANCELLED);this.#Y(u)}return this.lastSyncResolved=!0,Promise.resolve(Se(r,{toState:i,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h}))}catch(t){return this.#X(t,u,c,i,a),Promise.reject(t)}}navigateToDefault(t){const e=this.#f;if(!e.getOptions().defaultRoute)return Promise.reject(new he(s.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"}));const{route:n,params:r}=e.resolveDefault();return n?this.navigate(n,r,t):Promise.reject(new he(s.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"}))}navigateToNotFound(t){this.#H();const e=this.#f.getState(),n=e?Zt(e.name).toReversed():[];Object.freeze(n);const r={deactivated:n,activated:Oe,intersection:""};Object.freeze(r);const i={phase:"activating",...e&&{from:e.name},reason:"success",segments:r};Object.freeze(i);const s={name:o.UNKNOWN_ROUTE,params:{},path:t,transition:i};return Object.freeze(s),this.#f.setState(s),this.#f.emitTransitionSuccess(s,e,Ee),s}abortCurrentNavigation(){this.#Q?.abort(new he(s.TRANSITION_CANCELLED)),this.#Q=null}async#J(t,e,n,r){const i=this.#f,a=()=>this.#K===r&&!n.signal.aborted&&i.isActive();try{if(e.opts.signal){if(e.opts.signal.aborted)throw new he(s.TRANSITION_CANCELLED,{reason:e.opts.signal.reason});e.opts.signal.addEventListener("abort",()=>{n.abort(e.opts.signal?.reason)},{once:!0,signal:n.signal})}if(await t,!a())throw new he(s.TRANSITION_CANCELLED);return Se(i,e)}catch(t){throw Te(i,t,e.toState,e.fromState),t}finally{this.#Y(n)}}#X(t,e,n,r,i){e&&this.#Y(e),n&&r&&Te(this.#f,t,r,i)}#Y(t){t.abort(),this.#Q===t&&(this.#Q=null)}#H(){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 he(s.TRANSITION_CANCELLED)),this.#f.cancelNavigation())}},Re={replace:!0};Object.freeze(Re);var Ce=class{#f;setDependencies(t){this.#f=t}async start(t){const e=this.#f,n=e.getOptions(),r=e.matchPath(t);if(!r&&!n.allowNotFound){const n=new he(s.ROUTE_NOT_FOUND,{path:t});throw e.emitTransitionError(void 0,void 0,n),n}return e.completeStart(),r?e.navigate(r.name,r.params,Re):e.navigateToNotFound(t)}stop(){this.#f.clearState()}},De=class{#Z;#tt;#et;#nt;#rt;#it;constructor(t){this.#Z=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(p.ROUTER_START)}emitRouterStop(){this.#tt.emit(p.ROUTER_STOP)}emitTransitionStart(t,e){this.#tt.emit(p.TRANSITION_START,t,e)}emitTransitionSuccess(t,e,n){this.#tt.emit(p.TRANSITION_SUCCESS,t,e,n)}emitTransitionError(t,e,n){this.#tt.emit(p.TRANSITION_ERROR,t,e,n)}emitTransitionCancel(t,e){this.#tt.emit(p.TRANSITION_CANCEL,t,e)}sendStart(){this.#Z.send(b)}sendStop(){this.#Z.send(R)}sendDispose(){this.#Z.send(C)}sendStarted(){this.#Z.send(N)}sendNavigate(t,e){this.#et=t,this.#Z.forceState(y),this.emitTransitionStart(t,e)}sendComplete(t,e,n={}){this.#Z.forceState(T),this.emitTransitionSuccess(t,e,n),this.#et===t&&(this.#et=void 0)}sendFail(t,e,n){const r=this.#et;this.#nt=t,this.#rt=e,this.#it=n,this.#Z.send(E),this.#et===r&&(this.#et=void 0)}sendFailSafe(t,e,n){this.isReady()?this.sendFail(t,e,n):this.emitTransitionError(t,e,n)}sendCancel(t,e){const n=this.#et;this.#nt=t,this.#rt=e,this.#Z.send(P),this.#et===n&&(this.#et=void 0)}canBeginTransition(){return this.#Z.canSend(A)}canStart(){return this.#Z.canSend(b)}canCancel(){return this.#Z.canSend(P)}isActive(){const t=this.#Z.getState();return t!==v&&t!==w}isDisposed(){return this.#Z.getState()===w}isTransitioning(){return this.#Z.getState()===y}isReady(){return this.#Z.getState()===T}getCurrentToState(){return this.#et}addEventListener(t,e){return this.#tt.on(t,e)}subscribe(t){return this.#tt.on(p.TRANSITION_SUCCESS,(e,n)=>{t({route:e,previousRoute:n})})}clearAll(){this.#tt.clearAll()}setLimits(t){this.#tt.setLimits(t)}sendCancelIfTransitioning(t){this.canCancel()&&this.sendCancel(this.#et,t)}#at(){this.emitTransitionError(this.#nt,this.#rt,this.#it)}#st(){const t=this.#Z;t.on(S,N,()=>{this.emitRouterStart()}),t.on(T,R,()=>{this.emitRouterStop()}),t.on(y,P,()=>{const t=this.#nt;void 0!==t&&this.emitTransitionCancel(t,this.#rt)}),t.on(S,E,()=>{this.#at()}),t.on(T,E,()=>{this.#at()}),t.on(y,E,()=>{this.#at()})}},Fe=new he(s.ROUTER_ALREADY_STARTED),je=new Set(["all","warn-error","error-only"]);var Le=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),this.routeLifecycle.setValidatorGetter(()=>{try{return M(this.router).validator}catch{return null}})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(t,e)=>{this.routeLifecycle.addCanActivate(t,e,!0)},addDeactivateGuard:(t,e)=>{this.routeLifecycle.addCanDeactivate(t,e,!0)},makeState:(t,e,n,r)=>this.state.makeState(t,e,n,r),getState:()=>this.state.get(),areStatesEqual:(t,e,n)=>this.state.areStatesEqual(t,e,n),getDependency:t=>this.dependenciesStore.dependencies[t],forwardState:(t,e)=>{const n=M(this.router);return n.validator?.routes.validateStateBuilderArgs(t,e,"forwardState"),n.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),this.plugins.setValidatorGetter(()=>{try{return M(this.router).validator}catch{return null}})}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 n=M(this.router);n.validator?.routes.validateStateBuilderArgs(t,e,"navigate");const{name:r,params:i}=n.forwardState(t,e),s=this.routes.getMetaForState(r);if(void 0===s)return;const a=n.buildPath(r,i);return this.state.makeState(r,i,a,s,void 0,!0)},areStatesEqual:(t,e,n)=>this.state.areStatesEqual(t,e,n),resolveDefault:()=>{const t=this.options.get();return{route:k(t.defaultRoute,t=>this.dependenciesStore.dependencies[t]),params:k(t.defaultParams,t=>this.dependenciesStore.dependencies[t])}},startTransition:(t,e)=>{this.eventBus.sendNavigate(t,e)},cancelNavigation:()=>{const t=this.eventBus.getCurrentToState();void 0!==t&&this.eventBus.sendCancel(t,this.state.get())},sendTransitionDone:(t,e,n)=>{this.eventBus.sendComplete(t,e,n)},sendTransitionFail:(t,e,n)=>{this.eventBus.sendFail(t,e,n)},emitTransitionError:(t,e,n)=>{this.eventBus.sendFailSafe(t,e,n)},emitTransitionSuccess:(t,e,n)=>{this.eventBus.emitTransitionSuccess(t,e,n)},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,n)=>this.navigation.navigate(t,e,n),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,n)=>{this.eventBus.sendFail(t,e,n)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(t,e)=>M(this.router).buildPath(t,e),getUrlParams:t=>this.routes.getUrlParams(t)})}createCompileFactory(){const{router:t,dependenciesStore:e}=this;return n=>n(t,t=>e.dependencies[t])}},Ie=Object.freeze({}),_e=class n{#u;#S;#ot;#ct;#ut;#lt;#m;#ht;#dt;#ft;constructor(n=[],r={},s={}){r.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(n=e.level)||!je.has(n)))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 n;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}(r.logger)&&(t.logger.configure(r.logger),delete r.logger),z.validateOptionsIsObject(r),function(t){if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError("dependencies must be a plain object");for(const e in t)if(Object.getOwnPropertyDescriptor(t,e)?.get)throw new TypeError(`dependencies cannot contain getters: "${e}"`)}(s),n.length>0&&F(n),this.#u=new z(r),this.#S=function(t={}){return{...g,...t}}(r.limits),this.#ot=function(t={}){const e=Object.create(null);for(const n in t)void 0!==t[n]&&(e[n]=t[n]);return{dependencies:e,limits:g}}(s),this.#ct=new G,this.#ut=new oe(n,function(t){return{strictTrailingSlash:"strict"===t.trailingSlash,strictQueryParams:"strict"===t.queryParamsMode,urlParamsEncoding:t.urlParamsEncoding,queryParams:t.queryParams}}(this.#u.get())),this.#lt=new H,this.#m=new K,this.#ht=new Pe,this.#dt=new Ce;const a=new e.FSM(D),o=new i({onListenerError:(e,n)=>{t.logger.error("Router",`Error in listener for ${e}:`,n)},onListenerWarn:(e,n)=>{t.logger.warn("router.addEventListener",`Event "${e}" has ${n} listeners — possible memory leak`)}});var c;this.#ft=new De({routerFSM:a,emitter:o}),(c=new Le({router:this,options:this.#u,limits:this.#S,dependenciesStore:this.#ot,state:this.#ct,routes:this.#ut,routeLifecycle:this.#lt,plugins:this.#m,navigation:this.#ht,lifecycle:this.#dt,eventBus:this.#ft})).wireLimits(),c.wireRouteLifecycleDeps(),c.wireRoutesDeps(),c.wirePluginsDeps(),c.wireNavigationDeps(),c.wireLifecycleDeps(),c.wireStateDeps();const u=new Map;var l,h,d;l={makeState:(t,e,n,r,i)=>this.#ct.makeState(t,e,n,r,i),forwardState:$("forwardState",(t,e)=>this.#ut.forwardState(t,e),u),buildStateResolved:(t,e)=>this.#ut.buildStateResolved(t,e),matchPath:(t,e)=>this.#ut.matchPath(t,e),getOptions:()=>this.#u.get(),addEventListener:(t,e)=>this.#ft.addEventListener(t,e),buildPath:$("buildPath",(t,e)=>this.#ut.buildPath(t,e??m,this.#u.get()),u),start:(h=t=>this.#dt.start(t),d=u,(...t)=>{const e=d.get("start");return e&&0!==e.length?U(e,h,t):h(...t)}),interceptors:u,setRootPath:t=>{this.#ut.setRootPath(t)},getRootPath:()=>this.#ut.getStore().rootPath,getTree:()=>this.#ut.getStore().tree,isDisposed:()=>this.#ft.isDisposed(),validator:null,dependenciesGetStore:()=>this.#ot,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#ot.dependencies}),getLifecycleFactories:()=>this.#lt.getFactories(),getPluginFactories:()=>this.#m.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:[]},_.set(this,l),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.dispose=this.dispose.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToNotFound=this.navigateToNotFound.bind(this),this.subscribe=this.subscribe.bind(this)}isActiveRoute(e,n,r,i){return M(this).validator?.routes.validateIsActiveRouteArgs(e,n,r,i),M(this).validator?.routes.validateRouteName(e,"isActiveRoute"),""===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,n,r,i)}buildPath(t,e){const n=M(this);return n.validator?.routes.validateBuildPathArgs(t),n.validator?.navigation.validateParams(e,"buildPath"),n.buildPath(t,e)}getState(){return this.#ct.get()}getPreviousState(){return this.#ct.getPrevious()}areStatesEqual(t,e,n=!0){return M(this).validator?.state.validateAreStatesEqualArgs(t,e,n),this.#ct.areStatesEqual(t,e,n)}shouldUpdateNode(t){return M(this).validator?.routes.validateShouldUpdateNodeArgs(t),oe.shouldUpdateNode(t)}isActive(){return this.#ft.isActive()}start(t){if(!this.#ft.canStart())return Promise.reject(Fe);M(this).validator?.navigation.validateStartArgs(t),this.#ft.sendStart();const e=M(this).start(t).catch(t=>{throw this.#ft.isReady()&&(this.#dt.stop(),this.#ft.sendStop()),t});return n.#pt(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.#m.disposeAll();const t=M(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.#ot.dependencies=Object.create(null),this.#gt()}canNavigateTo(t,e){const n=M(this);if(n.validator?.routes.validateRouteName(t,"canNavigateTo"),n.validator?.navigation.validateParams(e,"canNavigateTo"),!this.#ut.hasRoute(t))return!1;const{name:r,params:i}=n.forwardState(t,e??{}),s=this.#ct.makeState(r,i),a=this.#ct.get(),{toDeactivate:o,toActivate:c}=se(s,a);return this.#lt.canNavigateTo(o,c,s,a)}usePlugin(...t){const e=t.filter(Boolean);if(0===e.length)return()=>{};const n=M(this);n.validator?.plugins.validatePluginLimit(this.#m.count(),this.#S);for(const t of e)n.validator?.plugins.validateNoDuplicatePlugins(t,this.#m.getAll());return this.#m.use(...e)}subscribe(t){return De.validateSubscribeListener(t),this.#ft.subscribe(t)}navigate(t,e,r){const i=M(this);i.validator?.navigation.validateNavigateArgs(t),i.validator?.navigation.validateParams(e,"navigate");const s=r??Ie;i.validator?.navigation.validateNavigationOptions(s,"navigate");const a=this.#ht.navigate(t,e??m,s);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:n.#pt(a),a}navigateToDefault(t){const e=M(this);e.validator?.navigation.validateNavigateToDefaultArgs(t);const r=t??Ie;e.validator?.navigation.validateNavigationOptions(r,"navigateToDefault");const i=this.#ht.navigateToDefault(r);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:n.#pt(i),i}navigateToNotFound(t){if(!this.#ft.isActive())throw new he(s.ROUTER_NOT_STARTED);if(void 0!==t&&"string"!=typeof t)throw new TypeError("[router.navigateToNotFound] path must be a string, got "+typeof t);const e=t??this.#ct.get().path;return this.#ht.navigateToNotFound(e)}static#mt=e=>{e instanceof he&&(e.code===s.SAME_STATES||e.code===s.TRANSITION_CANCELLED||e.code===s.ROUTER_NOT_STARTED||e.code===s.ROUTE_NOT_FOUND)||t.logger.error("router.navigate","Unexpected navigation error",e)};static#pt(t){t.catch(n.#mt)}#gt(){this.navigate=Me,this.navigateToDefault=Me,this.navigateToNotFound=Me,this.start=Me,this.stop=Me,this.usePlugin=Me,this.subscribe=Me,this.canNavigateTo=Me}};function Me(){throw new he(s.ROUTER_DISPOSED)}var Ue=new WeakMap;exports.Router=_e,exports.RouterError=he,exports.UNKNOWN_ROUTE=a,exports.constants=o,exports.createRouter=(t=[],e={},n={})=>new _e(t,e,n),exports.errorCodes=s,exports.events=p,exports.getNavigator=t=>{let e=Ue.get(t);return e||(e=Object.freeze({navigate:t.navigate,getState:t.getState,isActiveRoute:t.isActiveRoute,canNavigateTo:t.canNavigateTo,subscribe:t.subscribe}),Ue.set(t,e)),e},exports.resolveForwardChain=Mt;//# sourceMappingURL=index.js.map
1
+ var t=require("@real-router/logger"),e=require("@real-router/fsm"),n={maxListeners:0,warnListeners:0,maxEventDepth:0},r=class extends Error{},i=class{#t=new Map;#e=null;#n=n;#r;#i;constructor(t){t?.limits&&(this.#n=t.limits),this.#r=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.#n=t}on(t,e){const n=this.#s(t);if(n.has(e))throw new Error(`Duplicate listener for "${t}"`);const{maxListeners:r,warnListeners:i}=this.#n;if(0!==i&&n.size===i&&this.#i?.(t,i),0!==r&&n.size>=r)throw new Error(`Listener limit (${r}) reached for "${t}"`);return n.add(e),()=>{this.off(t,e)}}off(t,e){this.#t.get(t)?.delete(e)}emit(t,e,n,r,i){const s=this.#t.get(t);if(!s||0===s.size)return;const a=arguments.length-1;0!==this.#n.maxEventDepth?this.#a(s,t,a,e,n,r,i):this.#o(s,t,a,e,n,r,i)}clearAll(){this.#t.clear(),this.#e=null}listenerCount(t){return this.#t.get(t)?.size??0}#o(t,e,n,r,i,s,a){if(1===t.size){const[o]=t;try{this.#c(o,n,r,i,s,a)}catch(t){this.#r?.(e,t)}return}const o=[...t];for(const t of o)try{this.#c(t,n,r,i,s,a)}catch(t){this.#r?.(e,t)}}#c(t,e,n,r,i,s){switch(e){case 0:t();break;case 1:t(n);break;case 2:t(n,r);break;case 3:t(n,r,i);break;default:t(n,r,i,s)}}#a(t,e,n,i,s,a,o){this.#e??=new Map;const c=this.#e,u=c.get(e)??0;if(u>=this.#n.maxEventDepth)throw new r(`Maximum recursion depth (${this.#n.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,n,i,s,a,o)}catch(t){if(t instanceof r)throw t;this.#r?.(e,t)}}finally{c.set(e,c.get(e)-1)}}#s(t){const e=this.#t.get(t);if(e)return e;const n=new Set;return this.#t.set(t,n),n}},s=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"}),a="@@router/UNKNOWN_ROUTE",o={UNKNOWN_ROUTE:a},c="onStart",u="onStop",l="onTransitionStart",h="onTransitionCancel",d="onTransitionSuccess",f="onTransitionError",p={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},g={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},m=Object.freeze({}),v="IDLE",S="STARTING",T="READY",y="TRANSITIONING",w="DISPOSED",b="START",N="STARTED",A="NAVIGATE",O="COMPLETE",E="FAIL",P="CANCEL",R="STOP",C="DISPOSE",D={initial:v,context:null,transitions:{[v]:{[b]:S,[C]:w},[S]:{[N]:T,[E]:v},[T]:{[A]:y,[E]:T,[R]:v},[y]:{[A]:y,[O]:T,[P]:T,[E]:T},[w]:{}}};function F(t,e){for(const e of t){if(null===e||"object"!=typeof e||Array.isArray(e))throw new TypeError("route must be a non-array object");const t=e.children;t&&F(t)}}var j=new WeakSet;function L(t){if(null!==t&&"object"==typeof t&&!Object.isFrozen(t))if(Object.freeze(t),Array.isArray(t))for(const e of t)L(e);else for(const e in t)L(t[e])}function I(t){return t?(j.has(t)||(L(t),j.add(t)),t):t}var _=new WeakMap;function M(t){const e=_.get(t);if(!e)throw new TypeError("[real-router] Invalid router instance — not found in internals registry");return e}function U(t,e,n){let r=e;for(const e of t){const t=r;r=(...n)=>e(t,...n)}return r(...n)}function $(t,e,n){return(r,i)=>{const s=n.get(t);return s&&0!==s.length?U(s,e,[r,i]):e(r,i)}}var B={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0};function x(t){Object.freeze(t);for(const e of Object.keys(t)){const n=t[e];n&&"object"==typeof n&&n.constructor===Object&&x(n)}return t}function k(t,e){return"function"==typeof t?t(e):t}var z=class{#u;constructor(t={}){this.#u=x({...B,...t})}static validateOptionsIsObject(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("[router.constructor] options must be a plain object")}(t)}get(){return this.#u}};function q(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!q(t[n],e[n]))return!1;return!0}return!1}var G=new WeakMap;function W(t){return G.get(t)}var V=class{#l=void 0;#h=void 0;#d;#f=new Map;get(){return this.#l}set(t){this.#h=this.#l,this.#l=t?I(t):void 0}getPrevious(){return this.#h}reset(){this.#l=void 0,this.#h=void 0,this.#f.clear()}setDependencies(t){this.#d=t}makeState(t,e,n,r,i){const s=this.#d.getDefaultParams();let a;a=Object.hasOwn(s,t)?{...s[t],...e}:e&&e!==m?{...e}:m;const o={name:t,params:a,path:n??this.#d.buildPath(t,e)};return r&&function(t,e){G.set(t,e)}(o,r),i?o:I(o)}areStatesEqual(t,e,n=!0){if(!t||!e)return!!t==!!e;if(t.name!==e.name)return!1;if(n){const n=this.#p(t.name);for(const r of n)if(!q(t.params[r],e.params[r]))return!1;return!0}const r=Object.keys(t.params),i=Object.keys(e.params);if(r.length!==i.length)return!1;for(const n of r)if(!(n in e.params)||!q(t.params[n],e.params[n]))return!1;return!0}#p(t){const e=this.#f.get(t);if(void 0!==e)return e;const n=this.#d.getUrlParams(t);return this.#f.set(t,n),n}},Q={[c]:p.ROUTER_START,[u]:p.ROUTER_STOP,[d]:p.TRANSITION_SUCCESS,[l]:p.TRANSITION_START,[f]:p.TRANSITION_ERROR,[h]:p.TRANSITION_CANCEL},K=Object.keys(Q),H="router.usePlugin",J=class e{#g=new Set;#m=new Set;#d;#v=g;#S=null;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 "+typeof 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.")}(t)}static validateNoDuplicatePlugins(t,e){for(const n of t)if(e(n))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setDependencies(t){this.#d=t}setLimits(t){this.#v=t,this.#v}setValidatorGetter(t){this.#S=t}count(){return this.#g.size}use(...e){if(this.#S?.()?.plugins.validateCountThresholds(this.#g.size+e.length),1===e.length){const n=e[0],r=this.#T(n);this.#g.add(n);let i=!1;const s=()=>{if(!i){i=!0,this.#g.delete(n),this.#m.delete(s);try{r()}catch(e){t.logger.error(H,"Error during cleanup:",e)}}};return this.#m.add(s),s}const n=this.#y(e),r=[];try{for(const t of n){const e=this.#T(t);r.push({factory:t,cleanup:e})}}catch(e){for(const{cleanup:e}of r)try{e()}catch(e){t.logger.error(H,"Cleanup error:",e)}throw e}for(const{factory:t}of r)this.#g.add(t);let i=!1;const s=()=>{if(!i){i=!0,this.#m.delete(s);for(const{factory:t}of r)this.#g.delete(t);for(const{cleanup:e}of r)try{e()}catch(e){t.logger.error(H,"Error during cleanup:",e)}}};return this.#m.add(s),s}getAll(){return[...this.#g]}has(t){return this.#g.has(t)}disposeAll(){for(const t of this.#m)t();this.#g.clear(),this.#m.clear()}#y(t){const e=new Set;for(const n of t)e.has(n)?this.#S?.()?.plugins.warnBatchDuplicates(t):e.add(n);return e}#T(t){const n=this.#d.compileFactory(t);e.validatePlugin(n),this.#S?.()?.plugins.validatePluginKeys(n),Object.freeze(n);const r=[];for(const t of K)t in n&&("function"==typeof n[t]?(r.push(this.#d.addEventListener(Q[t],n[t])),"onStart"===t&&this.#d.canNavigate()&&this.#S?.()?.plugins.warnPluginAfterStart(t)):this.#S?.()?.plugins.warnPluginMethodType(t));return()=>{for(const t of r)t();"function"==typeof n.teardown&&n.teardown()}}},Y=class{#w=new Map;#b=new Map;#N=new Map;#A=new Map;#O=[this.#N,this.#A];#E=new Set;#P=new Set;#R=new Set;#d;#v=g;#S=null;setDependencies(t){this.#d=t}setLimits(t){this.#v=t,this.#v}setValidatorGetter(t){this.#S=t}getHandlerCount(t){return"activate"===t?this.#b.size:this.#w.size}addCanActivate(t,e,n=!1){n?this.#P.add(t):this.#P.delete(t);const r=this.#b.has(t);this.#C("activate",t,e,this.#b,this.#A,"canActivate",r)}addCanDeactivate(t,e,n=!1){n?this.#R.add(t):this.#R.delete(t);const r=this.#w.has(t);this.#C("deactivate",t,e,this.#w,this.#N,"canDeactivate",r)}clearCanActivate(t){this.#b.delete(t),this.#A.delete(t),this.#P.delete(t)}clearCanDeactivate(t){this.#w.delete(t),this.#N.delete(t),this.#R.delete(t)}clearAll(){this.#b.clear(),this.#A.clear(),this.#w.clear(),this.#N.clear(),this.#P.clear(),this.#R.clear()}clearDefinitionGuards(){for(const t of this.#P)this.#b.delete(t),this.#A.delete(t);for(const t of this.#R)this.#w.delete(t),this.#N.delete(t);this.#P.clear(),this.#R.clear()}getFactories(){const t={},e={};for(const[e,n]of this.#w)t[e]=n;for(const[t,n]of this.#b)e[t]=n;return[t,e]}getFunctions(){return this.#O}canNavigateTo(t,e,n,r){for(const e of t)if(!this.#D(this.#N,e,n,r,"canNavigateTo"))return!1;for(const t of e)if(!this.#D(this.#A,t,n,r,"canNavigateTo"))return!1;return!0}#C(t,e,n,r,i,s,a){a?this.#S?.()?.lifecycle.warnOverwrite(e,t,s):this.#S?.()?.lifecycle.validateCountThresholds(r.size+1,s);const o="boolean"==typeof n?function(t){const e=()=>t;return()=>e}(n):n;r.set(e,o),this.#E.add(e);try{const t=this.#d.compileFactory(o);if("function"!=typeof t)throw new TypeError(`[router.${s}] Factory must return a function, got ${typeof t}`);i.set(e,t)}catch(t){throw r.delete(e),t}finally{this.#E.delete(e)}}#D(t,e,n,r,i){const s=t.get(e);if(!s)return!0;try{const t=s(n,r);return"boolean"==typeof t?t:(this.#S?.()?.lifecycle.warnAsyncGuardSync(e,i),!1)}catch{return!1}}};function X(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function Z(t){const e={name:t.name,path:t.path};return t.children&&(e.children=t.children.map(t=>Z(t))),e}function tt(t){return`(${t.replaceAll(/(^<|>$)/g,"")})`}var et=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,nt=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,rt=/\?(.+)$/,it=/[^\w!$'()*+,.:;|~-]/gu,st=/[^\w!$'()*+,.:;|~-]/u,at={default:t=>st.test(t)?t.replaceAll(it,t=>encodeURIComponent(t)):t,uri:encodeURI,uriComponent:encodeURIComponent,none:t=>t},ot={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:t=>t};function ct(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function ut(t){return t.length>1&&t.endsWith("/")?t.slice(0,-1):t}function lt(t){const e={};if(0===t.length)return e;const n=t.split("&");for(const t of n){const n=t.indexOf("=");-1===n?e[t]="":e[t.slice(0,n)]=t.slice(n+1)}return e}function ht(t){const e=[];for(const n of Object.keys(t)){const r=t[n],i=encodeURIComponent(n);e.push(""===r?i:`${i}=${encodeURIComponent(String(r))}`)}return e.join("&")}function dt(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function ft(t){let e=0;for(;e<t.length;)if("%"===t[e]){if(e+2>=t.length)return!1;const n=t.codePointAt(e+1)??0,r=t.codePointAt(e+2)??0;if(!dt(n)||!dt(r))return!1;e+=3}else e++;return!0}var pt=/<[^>]*>/g;function gt(t,e,n,r,i){const s=""===e.fullName;s||r.push(e);const a=e.absolute,o=e.paramMeta.pathPattern,c=a&&o.startsWith("~")?o.slice(1):o,u=(a?c:o).replaceAll(pt,""),l=a?u:(d=u,""===(h=n)?d:""===d?h:h+d);var h,d;let f=i;s||(f=function(t,e,n,r,i,s){const a=(m=r,ut(n)===ut(m)),o=Object.freeze([...i]),c=function(t){const e={};for(const n of t)e[n.fullName]=n.paramTypeMap;return Object.freeze(e)}(o),u=ut(n),l=function(t,e){const n=[];t.length>0&&n.push(...t);for(const t of e)t.paramMeta.queryParams.length>0&&n.push(...t.paramMeta.queryParams);return n}(t.rootQueryParams,i),h=function(t){const e=new Map;for(const n of t)for(const[t,r]of n.paramMeta.constraintPatterns)e.set(t,r);return e}(i),d=a?ut(r):u,{buildStaticParts:f,buildParamSlots:p}=function(t,e,n){const r=new Set,i=new Set;for(const t of e){for(const e of t.paramMeta.urlParams)r.add(e);for(const e of t.paramMeta.spatParams)i.add(e)}if(0===r.size)return{buildStaticParts:[t],buildParamSlots:[]};const s=[],a=[],o=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,u=0;for(;null!==(c=o.exec(t));){const e=c[1],r="?"===c[2];s.push(t.slice(u,c.index));const o=i.has(e);a.push({paramName:e,isOptional:r,encoder:o?t=>{const e=at[n],r=t.split("/");let i=e(r[0]);for(let t=1;t<r.length;t++)i+=`/${e(r[t])}`;return i}:at[n]}),u=c.index+c[0].length}return s.push(t.slice(u)),{buildStaticParts:s,buildParamSlots:a}}(d,a?i.slice(0,-1):i,t.options.urlParamsEncoding),g={name:e.fullName,parent:s,depth:i.length-1,matchSegments:o,meta:c,declaredQueryParams:l,declaredQueryParamsSet:new Set(l),hasTrailingSlash:n.length>1&&n.endsWith("/"),constraintPatterns:h,hasConstraints:h.size>0,buildStaticParts:f,buildParamSlots:p,buildParamNamesSet:new Set(p.map(t=>t.paramName))};var m;return t.routesByName.set(e.fullName,g),t.segmentsByName.set(e.fullName,o),t.metaByName.set(e.fullName,c),a?function(t,e,n){var r,i;r=e,(function(t,e,n){const r=ut(n);if("/"===r||""===r)return e;let i=e,s=1;const a=r.length;for(;s<=a;){const e=r.indexOf("/",s),n=-1===e?a:e;if(n<=s)break;i=vt(t,i,r.slice(s,n)),s=n+1}return i}(i=t,i.root,n)).slashChildRoute=r;const s=ut(n),a=t.options.caseSensitive?s:s.toLowerCase();t.staticCache.has(a)&&t.staticCache.set(a,e)}(t,g,r):function(t,e,n,r,i){if(function(t,e,n){const r=ut(n);"/"!==r?mt(t,t.root,r,1,e):t.root.route=e}(t,e,n),0===i.paramMeta.urlParams.length){const n=t.options.caseSensitive?r:r.toLowerCase();t.staticCache.set(n,e)}}(t,g,n,u,e),g}(t,e,l,a?"":n,r,i));for(const n of e.children.values())gt(t,n,l,r,f);s||r.pop()}function mt(t,e,n,r,i){const s=n.length;for(;r<=s;){const a=n.indexOf("/",r),o=-1===a?s:a,c=n.slice(r,o);if(c.endsWith("?")){const r=c.slice(1).replaceAll(pt,"").replace(/\?$/,"");return e.paramChild??={node:ct(),name:r},mt(t,e.paramChild.node,n,o+1,i),void(o>=s?e.route??=i:mt(t,e,n,o+1,i))}e=vt(t,e,c),r=o+1}e.route=i}function vt(t,e,n){if(n.startsWith("*")){const t=n.slice(1);return e.splatChild??={node:ct(),name:t},e.splatChild.node}if(n.startsWith(":")){const t=n.slice(1).replaceAll(pt,"").replace(/\?$/,"");return e.paramChild??={node:ct(),name:t},e.paramChild.node}const r=t.options.caseSensitive?n:n.toLowerCase();return r in e.staticChildren||(e.staticChildren[r]=ct()),e.staticChildren[r]}var St=/[\u0080-\uFFFF]/,Tt=class{get options(){return this.#t}#t;#e=ct();#i=new Map;#s=new Map;#n=new Map;#a=new Map;#r="";#F=[];constructor(t){this.#t={caseSensitive:t?.caseSensitive??!0,strictTrailingSlash:t?.strictTrailingSlash??!1,strictQueryParams:t?.strictQueryParams??!1,urlParamsEncoding:t?.urlParamsEncoding??"default",parseQueryString:t?.parseQueryString??lt,buildQueryString:t?.buildQueryString??ht}}registerTree(t){this.#F=t.paramMeta.queryParams,gt({root:this.#e,options:this.#t,routesByName:this.#i,segmentsByName:this.#s,metaByName:this.#n,staticCache:this.#a,rootQueryParams:this.#F},t,"",[],null)}match(t){const e=this.#c(t);if(!e)return;const[n,r,i]=e,s=this.#t.caseSensitive?r:r.toLowerCase(),a=this.#a.get(s);if(a){if(this.#t.strictTrailingSlash&&!this.#o(n,a))return;return this.#j(a,{},i)}const o={},c=this.#L(r,o);return!c||this.#t.strictTrailingSlash&&!this.#o(n,c)||c.hasConstraints&&!this.#I(o,c)||!this.#_(o)?void 0:this.#j(c,o,i)}buildPath(t,e,n){const r=this.#i.get(t);if(!r)throw new Error(`[SegmentMatcher.buildPath] '${t}' is not defined`);r.hasConstraints&&e&&this.#M(r,t,e);const i=this.#U(r,e),s=this.#$(i,n?.trailingSlash),a=this.#B(r,e,n?.queryParamsMode);return s+(a?`?${a}`:"")}getSegmentsByName(t){return this.#s.get(t)}getMetaByName(t){return this.#n.get(t)}hasRoute(t){return this.#i.has(t)}setRootPath(t){this.#r=t}#M(t,e,n){for(const[r,i]of t.constraintPatterns){const t=n[r];if(null!=t){const n="object"==typeof t?JSON.stringify(t):String(t);if(!i.pattern.test(n))throw new Error(`[SegmentMatcher.buildPath] '${e}' — param '${r}' value '${n}' does not match constraint '${i.constraint}'`)}}}#U(t,e){const n=t.buildStaticParts,r=t.buildParamSlots;if(0===r.length)return this.#r+n[0];let i=this.#r+n[0];for(const[t,s]of r.entries()){const r=e?.[s.paramName];if(null==r){if(!s.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${s.paramName}'`);i.length>1&&i.endsWith("/")&&(i=i.slice(0,-1)),i+=n[t+1];continue}const a="object"==typeof r?JSON.stringify(r):String(r);i+=s.encoder(a)+n[t+1]}return i}#$(t,e){return"always"!==e||t.endsWith("/")?"never"===e&&"/"!==t&&t.endsWith("/")?t.slice(0,-1):t:`${t}/`}#B(t,e,n){if(!e)return"";const r={};let i=!1;for(const n of t.declaredQueryParams)n in e&&(r[n]=e[n],i=!0);if("loose"===n)for(const n in e)!Object.hasOwn(e,n)||t.declaredQueryParamsSet.has(n)||t.buildParamNamesSet.has(n)||(r[n]=e[n],i=!0);return i?this.#t.buildQueryString(r):""}#c(t){if(""===t&&(t="/"),!t.startsWith("/"))return;const e=t.indexOf("#");if(-1!==e&&(t=t.slice(0,e)),St.test(t))return;if(this.#r.length>0){if(!t.startsWith(this.#r))return;t=t.slice(this.#r.length)||"/"}const n=t.indexOf("?"),r=-1===n?t:t.slice(0,n),i=-1===n?void 0:t.slice(n+1);return r.includes("//")?void 0:[r,ut(r),i]}#j(t,e,n){if(void 0!==n){const r=this.#t.parseQueryString(n);if(this.#t.strictQueryParams){const e=t.declaredQueryParamsSet;for(const t of Object.keys(r))if(!e.has(t))return}for(const t of Object.keys(r))e[t]=r[t]}return{segments:t.matchSegments,params:e,meta:t.meta}}#o(t,e){return(t.length>1&&t.endsWith("/"))===e.hasTrailingSlash}#L(t,e){return 1===t.length?this.#e.slashChildRoute??this.#e.route:this.#x(this.#e,t,1,e)}#x(t,e,n,r){let i=t;const s=e.length;for(;n<=s;){const t=e.indexOf("/",n),a=-1===t?s:t,o=e.slice(n,a),c=this.#t.caseSensitive?o:o.toLowerCase();let u;if(c in i.staticChildren)u=i.staticChildren[c];else{if(!i.paramChild){if(i.splatChild){const t={},s=this.#x(i.splatChild.node,e,n,t);return s?(Object.assign(r,t),s):(r[i.splatChild.name]=e.slice(n),i.splatChild.node.route)}return}u=i.paramChild.node,r[i.paramChild.name]=o}i=u,n=a+1}return i.slashChildRoute??i.route}#_(t){const e=this.#t.urlParamsEncoding;if("none"===e)return!0;const n=ot[e];for(const e in t){const r=t[e];if(r.includes("%")){if(!ft(r))return!1;t[e]=n(r)}}return!0}#I(t,e){for(const[n,r]of e.constraintPatterns)if(!r.pattern.test(t[n]))return!1;return!0}},yt=t=>{const e=t.indexOf("%"),n=t.indexOf("+");if(-1===e&&-1===n)return t;const r=-1===n?t:t.split("+").join(" ");return-1===e?r:decodeURIComponent(r)},wt=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}=${wt(e)}`).join("&")},brackets:{encodeArray:(t,e)=>e.map(e=>`${t}[]=${wt(e)}`).join("&")},index:{encodeArray:(t,e)=>e.map((e,n)=>`${t}[${n}]=${wt(e)}`).join("&")},comma:{encodeArray:(t,e)=>`${t}=${e.map(t=>wt(t)).join(",")}`}},Nt={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}},At={default:{encode:t=>t},hidden:{encode:()=>""}},Ot=(t,e,n)=>({boolean:Nt[e],null:At[n],array:bt[t]}),Et={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:Nt.none,null:At.default,array:bt.none}},Pt=t=>{if(!t||void 0===t.arrayFormat&&void 0===t.booleanFormat&&void 0===t.nullFormat)return Et;const e=t.arrayFormat??"none",n=t.booleanFormat??"none",r=t.nullFormat??"default";return{arrayFormat:e,booleanFormat:n,nullFormat:r,strategies:Ot(e,n,r)}},Rt=t=>encodeURIComponent(t),Ct=(t,e,n)=>{const r=Rt(t);switch(typeof e){case"string":case"number":default:return`${r}=${Rt(e)}`;case"boolean":return n.strategies.boolean.encode(r,e);case"object":return null===e?n.strategies.null.encode(r):Array.isArray(e)?n.strategies.array.encodeArray(r,e):`${r}=${Rt(e)}`}};function Dt(t,e,n,r,i){const s=t.indexOf("=",e),a=-1!==s&&s<n,o=t.slice(e,a?s:n),{name:c,hasBrackets:u}=function(t){const e=t.indexOf("[");return-1===e?{name:t,hasBrackets:!1}:{name:t.slice(0,e),hasBrackets:!0}}(o);var l,h,d,f,p;!function(t,e,n,r){const i=t[e];void 0===i?t[e]=r?[n]:n:Array.isArray(i)?i.push(n):t[e]=[i,n]}(r,yt(c),(l=t,h=s,d=n,f=a,p=i,p?((t,e)=>{if(void 0===t)return e.boolean.decodeUndefined();const n=e.boolean.decodeRaw(t);if(null!==n)return n;const r=yt(t);return e.boolean.decodeValue(r)})(f?l.slice(h+1,d):void 0,p):f?yt(l.slice(h+1,d)):null),u)}function Ft(t,e){const n=t.path,r=n.startsWith("~"),i=r?n.slice(1):n,s={name:t.name,path:i,absolute:r,children:[],parent:e,nonAbsoluteChildren:[],fullName:""};if(t.children)for(const e of t.children){const t=Ft(e,s);s.children.push(t)}return s}function jt(t,e){return t.endsWith("/")&&e.startsWith("/")?t+e.slice(1):t+e}function Lt(t){const e=new Map;for(const n of t)e.set(n.name,n);return e}function It(t,e,n){const r=function(t){const e=[],n=[],r=[],i={},s=new Map,a=t.replaceAll(nt,"$1"),o=rt.exec(a);if(null!==o){const e=o[1].split("&");for(const t of e){const e=t.trim();e.length>0&&(n.push(e),i[e]="query")}t=t.slice(0,o.index)}let c;for(;null!==(c=et.exec(t));){const t=c[2],n=c[3];if("*"===c[1])r.push(t),e.push(t),i[t]="url";else if(e.push(t),i[t]="url",n){const e=`^${tt(n)}$`;s.set(t,{pattern:new RegExp(e),constraint:n})}}return{urlParams:e,queryParams:n,spatParams:r,paramTypeMap:i,constraintPatterns:s,pathPattern:t}}(t.path),i=function(t){const e={};for(const n of t.urlParams)e[n]="url";for(const n of t.queryParams)e[n]="query";return e}(r),s={name:t.name,path:t.path,absolute:t.absolute,parent:e,children:void 0,paramMeta:r,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:i};var a;s.fullName=(a=s,a.parent?.name?`${a.parent.fullName}.${a.name}`:a.name);const{childrenMap:o,nonAbsoluteChildren:c}=function(t,e,n){const r=[],i=[];for(const s of t){const t=It(s,e,n);r.push(t),t.absolute||i.push(t)}return{childrenMap:Lt(r),nonAbsoluteChildren:i}}(t.children,s,n);return s.children=o,s.nonAbsoluteChildren=c,s.staticPath=function(t){if(!t.path)return null;const{urlParams:e,queryParams:n,spatParams:r}=t.paramMeta;if(e.length>0||n.length>0||r.length>0)return null;const i=[];let s=t.parent;for(;s?.path;)i.unshift(s),s=s.parent;let a="";for(const t of i){const{urlParams:e,queryParams:n,spatParams:r}=t.paramMeta;if(e.length>0||n.length>0||r.length>0)return null;a=t.absolute?t.path:jt(a,t.path)}return t.absolute?t.path:jt(a,t.path)}(s),n&&(Object.freeze(c),Object.freeze(i),Object.freeze(s.children),Object.freeze(s)),s}function _t(t,e,n,r){return function(t,e){const n=[];return{add(t){return n.push(t),this},addMany(t){return n.push(...t),this},build:r=>function(t,e=!0){return It(t,null,e)}(function(t,e,n){const r=Ft({name:t,path:e},null);for(const t of n){const e=Ft(t,r);r.children.push(e)}return r}(t,e,n),!r?.skipFreeze)}}(t,e).addMany(n).build(r)}function Mt(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=>Mt(t))),e}function Ut(t){const e=t?.queryParams;return new Tt({...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 n=(t=>{const e=t.indexOf("?");return-1===e?t:t.slice(e+1)})(t);if(""===n||"?"===n)return{};if(!e)return function(t){const e={};return function(t,e){let n=0;const r=t.length;for(;n<r;){let i=t.indexOf("&",n);-1===i&&(i=r),Dt(t,n,i,e),n=i+1}}(t,e),e}(n);const r=Pt(e),i={};let s=0;const a=n.length;for(;s<a;){let t=n.indexOf("&",s);-1===t&&(t=a),Dt(n,s,t,i,r.strategies),s=t+1}return i})(t,e),buildQueryString:t=>((t,e)=>{const n=Object.keys(t);if(0===n.length)return"";const r=Pt(e),i=[];for(const e of n){const n=t[e];if(void 0===n)continue;const s=Ct(e,n,r);s&&i.push(s)}return i.join("&")})(t,e)})}function $t(t,e,n=100){const r=new Set,i=[t];let s=t;for(;e[s];){const t=e[s];if(r.has(t)){const e=i.indexOf(t),n=[...i.slice(e),t];throw new Error(`Circular forwardTo: ${n.join(" → ")}`)}if(r.add(s),i.push(t),s=t,i.length>n)throw new Error(`forwardTo chain exceeds maximum depth (${n}): ${i.join(" → ")}`)}return s}function Bt(t,e,n){const r=_t("",e,t),i=Ut(n);return i.registerTree(r),{tree:r,matcher:i}}function xt(t){const e=Bt(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher,t.resolvedForwardMap=qt(t.config)}function kt(t){const e=Bt(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher}function zt(t){!function(t){t.definitions.length=0,Object.assign(t.config,X()),t.resolvedForwardMap=Object.create(null),t.routeCustomFields=Object.create(null)}(t),kt(t)}function qt(t){const e=Object.create(null);for(const n of Object.keys(t.forwardMap))e[n]=$t(n,t.forwardMap);return e}function Gt(e,n,r,i,s,a,o){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[n]=u),e.canActivate&&s.set(n,e.canActivate),e.canDeactivate&&a.set(n,e.canDeactivate),e.forwardTo&&function(e,n,r){if(e.canActivate&&t.logger.warn("real-router",`Route "${n}" 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 "${n}" 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,r=e.forwardTo.toString().includes("__awaiter");if(t||r)throw new TypeError(`forwardTo callback cannot be async for route "${n}". Async functions break matchPath/buildPath.`)}"string"==typeof e.forwardTo?r.forwardMap[n]=e.forwardTo:r.forwardFnMap[n]=e.forwardTo}(e,n,r),e.decodeParams&&(r.decoders[n]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(r.encoders[n]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(r.defaultParams[n]=e.defaultParams)}function Wt(t,e,n,r,i,s,a=""){for(const o of t){const t=a?`${a}.${o.name}`:o.name;Gt(o,t,e,n,r,i),o.children&&Wt(o.children,e,n,r,i,s,t)}}function Vt(t,e){const n=[],r=X(),i=Object.create(null),s=new Map,a=new Map;for(const e of t)n.push(Z(e));const{tree:o,matcher:c}=Bt(n,"",e);return Wt(t,r,i,s,a,void 0,""),{definitions:n,config:r,tree:o,matcher:c,resolvedForwardMap:qt(r),routeCustomFields:i,rootPath:"",matcherOptions:e,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:s,pendingCanDeactivate:a,treeOperations:{commitTreeChanges:xt,resetStore:zt,nodeToDefinition:Mt}}}var Qt=".",Kt=[];function Ht(t){const e=[];for(let n=t.length-1;n>=0;n--)e.push(t[n]);return e}function Jt(t){const e=typeof t;return"string"===e||"number"===e||"boolean"===e}function Yt(t,e,n,r){const i=e[t];if(!i||"object"!=typeof i)return!0;for(const t of Object.keys(i)){const e=n.params[t],i=r.params[t];if(Jt(e)&&Jt(i)&&String(e)!==String(i))return!1}return!0}Object.freeze(Kt);var Xt,Zt,te=new Map;function ee(t){const e=te.get(t);if(e)return e;const n=function(t){if(!t)return[""];const e=t.indexOf(Qt);if(-1===e)return[t];const n=t.indexOf(Qt,e+1);if(-1===n)return[t.slice(0,e),t];const r=t.indexOf(Qt,n+1);if(-1===r)return[t.slice(0,e),t.slice(0,n),t];return-1===t.indexOf(Qt,r+1)?[t.slice(0,e),t.slice(0,n),t.slice(0,r),t]:function(t){const e=t.split(Qt),n=e.length,r=[e[0]];let i=e[0].length;for(let s=1;s<n-1;s++)i+=1+e[s].length,r.push(t.slice(0,i));return r.push(t),r}(t)}(t);return Object.freeze(n),te.set(t,n),n}var ne,re,ie=null,se=null;function ae(t,e){if(null!==ie&&t===Xt&&e===Zt)return ie;if(null!==se&&t===ne&&e===re)return se;const n=function(t,e){if(!e)return{intersection:"",toActivate:ee(t.name),toDeactivate:Kt};const n=W(t),r=W(e);if(!n&&!r)return{intersection:"",toActivate:ee(t.name),toDeactivate:Ht(ee(e.name))};const i=ee(t.name),s=ee(e.name),a=function(t,e,n,r,i,s){for(let a=0;a<s;a++){const s=r[a];if(s!==i[a])return a;if(!Yt(s,t,e,n))return a}return s}(n??r,t,e,i,s,Math.min(s.length,i.length));let o;if(a>=s.length)o=Kt;else if(0===a&&1===s.length)o=s;else{o=[];for(let t=s.length-1;t>=a;t--)o.push(s[t])}const c=0===a?i:i.slice(a);return{intersection:a>0?s[a-1]:"",toDeactivate:o,toActivate:c}}(t,e);return ne=Xt,re=Zt,se=ie,Xt=t,Zt=e,ie=n,n}function oe(t,e){var n;return{name:e??(n=t.segments,n.at(-1)?.fullName??""),params:t.params,meta:t.meta}}var ce=class{#k;#z;get#d(){return this.#k.depsStore}constructor(t=[],e){this.#k=Vt(t,e)}static shouldUpdateNode(t){return(e,n)=>{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&&!n)return!0;const{intersection:r,toActivate:i,toDeactivate:s}=ae(e,n);return t===r||!!i.includes(t)||s.includes(t)}}setDependencies(t){this.#k.depsStore=t;for(const[e,n]of this.#k.pendingCanActivate)t.addActivateGuard(e,n);this.#k.pendingCanActivate.clear();for(const[e,n]of this.#k.pendingCanDeactivate)t.addDeactivateGuard(e,n);this.#k.pendingCanDeactivate.clear()}setLifecycleNamespace(t){this.#k.lifecycleNamespace=t}setRootPath(t){this.#k.rootPath=t,kt(this.#k)}hasRoute(t){return this.#k.matcher.hasRoute(t)}clearRoutes(){zt(this.#k)}buildPath(t,e,n){if(t===o.UNKNOWN_ROUTE)return"string"==typeof e?.path?e.path:"";const r=Object.hasOwn(this.#k.config.defaultParams,t)?{...this.#k.config.defaultParams[t],...e}:e??{},i="function"==typeof this.#k.config.encoders[t]?this.#k.config.encoders[t]({...r}):r;return this.#k.matcher.buildPath(t,i,this.#q(n))}matchPath(t,e){const n=e,r=this.#k.matcher.match(t);if(!r)return;const i=oe(r),{name:s,params:a,meta:o}=i,c="function"==typeof this.#k.config.decoders[s]?this.#k.config.decoders[s](a):a,{name:u,params:l}=this.#d.forwardState(s,c);let h=t;if(n.rewritePathOnMatch){const t="function"==typeof this.#k.config.encoders[u]?this.#k.config.encoders[u]({...l}):l,e=n.trailingSlash;h=this.#k.matcher.buildPath(u,t,{trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:n.queryParamsMode})}return this.#d.makeState(u,l,h,o)}forwardState(t,e){if(Object.hasOwn(this.#k.config.forwardFnMap,t)){const n=this.#G(t,e),r=this.#k.config.forwardFnMap[t],i=this.#W(t,r,e);return{name:i,params:this.#G(i,n)}}const n=this.#k.resolvedForwardMap[t]??t;if(n!==t&&Object.hasOwn(this.#k.config.forwardFnMap,n)){const r=this.#G(t,e),i=this.#k.config.forwardFnMap[n],s=this.#W(n,i,e);return{name:s,params:this.#G(s,r)}}if(n!==t){const r=this.#G(t,e);return{name:n,params:this.#G(n,r)}}return{name:t,params:this.#G(t,e)}}buildStateResolved(t,e){const n=this.#k.matcher.getSegmentsByName(t);if(n)return oe({segments:n,params:e,meta:this.#k.matcher.getMetaByName(t)},t)}isActiveRoute(t,e={},n=!1,r=!0){const i=this.#d.getState();if(!i)return!1;const s=i.name;if(s!==t&&!s.startsWith(`${t}.`)&&!t.startsWith(`${s}.`))return!1;const a=this.#k.config.defaultParams[t];if(n||s===t){const n=a?{...a,...e}:e;return this.#d.areStatesEqual({name:t,params:n,path:""},i,r)}const o=i.params;return!!function(t,e){for(const n in t)if(t[n]!==e[n])return!1;return!0}(e,o)&&(!a||function(t,e,n){for(const r in t)if(!(r in n)&&t[r]!==e[r])return!1;return!0}(a,o,e))}getMetaForState(t){return this.#k.matcher.hasRoute(t)?this.#k.matcher.getMetaByName(t):void 0}getUrlParams(t){const e=this.#k.matcher.getSegmentsByName(t);return e?function(t){const e=[];for(const n of t)for(const t of n.paramMeta.urlParams)e.push(t);return e}(e):[]}getStore(){return this.#k}#G(t,e){return Object.hasOwn(this.#k.config.defaultParams,t)?{...this.#k.config.defaultParams[t],...e}:e}#q(t){if(this.#z)return this.#z;const e=t?.trailingSlash;return this.#z=Object.freeze({trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:t?.queryParamsMode}),this.#z}#W(t,e,n){const r=new Set([t]);let i=e(this.#d.getDependency,n),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.#k.matcher.getSegmentsByName(i))throw new Error(`Route "${i}" does not exist`);if(r.has(i)){const t=[...r,i].join(" → ");throw new Error(`Circular forwardTo detected: ${t}`)}if(r.add(i),Object.hasOwn(this.#k.config.forwardFnMap,i)){i=(0,this.#k.config.forwardFnMap[i])(this.#d.getDependency,n),s++;continue}const t=this.#k.config.forwardMap[i];if(void 0===t)return i;i=t,s++}throw new Error("forwardTo exceeds maximum depth of 100")}},ue=new Set(Object.values(s)),le=new Set(["code","segment","path","redirect"]),he=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),de=class extends Error{segment;path;redirect;code;constructor(t,{message:e,segment:n,path:r,redirect:i,...s}={}){super(e??t),this.code=t,this.segment=n,this.path=r,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 n=structuredClone(t),r=new WeakSet;return function t(e){if(null===e||"object"!=typeof e)return;if(r.has(e))return;r.add(e),Object.freeze(e);const n=Array.isArray(e)?e:Object.values(e);for(const e of n)t(e)}(n),n}(i):void 0;for(const[t,e]of Object.entries(s)){if(le.has(t))throw new TypeError(`[RouterError] Cannot set reserved property "${t}"`);he.has(t)||(this[t]=e)}}setCode(t){this.code=t,ue.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,n]of Object.entries(t)){if(le.has(e))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${e}"`);he.has(e)||(this[e]=n)}}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 n in this)Object.hasOwn(this,n)&&!e.has(n)&&(t[n]=this[n]);return t}},fe=new de(s.ROUTER_NOT_STARTED),pe=new de(s.ROUTE_NOT_FOUND),ge=new de(s.SAME_STATES),me=Promise.reject(fe),ve=Promise.reject(pe),Se=Promise.reject(ge);function Te(t,e){const{toState:n,fromState:r,opts:i,toDeactivate:a,toActivate:c,intersection:u}=e;if(n.name!==o.UNKNOWN_ROUTE&&!t.hasRoute(n.name)){const e=new de(s.ROUTE_NOT_FOUND,{routeName:n.name});throw t.sendTransitionFail(n,r,e),e}if(r)for(const n of a)!c.includes(n)&&e.canDeactivateFunctions.has(n)&&t.clearCanDeactivate(n);n.transition=function(t,e,n,r,i){const s={phase:"activating",reason:"success",segments:{deactivated:n,activated:r,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}(r,i,a,c,u);const l=I(n);t.setState(l);const h=void 0===i.signal?i:function({signal:t,...e}){return e}(i);return t.sendTransitionDone(l,r,h),l}function ye(t,e,n,r){e.code!==s.TRANSITION_CANCELLED&&e.code!==s.ROUTE_NOT_FOUND&&t.sendTransitionFail(n,r,e)}function we(t,e,n){if(t instanceof DOMException&&"AbortError"===t.name)throw new de(s.TRANSITION_CANCELLED);!function(t,e,n){if(t instanceof de)throw t.setCode(e),t;throw new de(e,function(t,e){const n={segment:e};if(t instanceof Error)return{...n,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[n,r]of Object.entries(t))be.has(n)||(e[n]=r);return{...n,...e}}return n}(t,n))}(t,e,n)}me.catch(()=>{}),ve.catch(()=>{}),Se.catch(()=>{});var be=new Set(["code","segment","path","redirect"]);async function Ne(t,e,n){let r;try{r=await t}catch(t){return void we(t,e,n)}if(!r)throw new de(e,{segment:n})}async function Ae(t,e,n,r,i,a,o,c,u,l){await Ne(u,n,l);for(let u=c;u<e.length;u++){if(!o())throw new de(s.TRANSITION_CANCELLED);const c=e[u],l=t.get(c);if(!l)continue;let h=!1;try{h=l(r,i,a)}catch(t){we(t,n,c)}if(h instanceof Promise)await Ne(h,n,c);else if(!h)throw new de(n,{segment:c})}}function Oe(t,e,n,r,i,a,o){for(const[c,u]of e.entries()){if(!o())throw new de(s.TRANSITION_CANCELLED);const l=t.get(u);if(!l)continue;let h=!1;try{h=l(r,i,a)}catch(t){we(t,n,u)}if(h instanceof Promise)return Ae(t,e,n,r,i,a,o,c+1,h,u);if(!h)throw new de(n,{segment:u})}}var Ee=[o.UNKNOWN_ROUTE];Object.freeze(Ee);var Pe={replace:!0};Object.freeze(Pe);var Re=class{lastSyncResolved=!1;lastSyncRejected=!1;#d;#V=null;#Q=0;setDependencies(t){this.#d=t}navigate(t,e,n){this.lastSyncResolved=!1;const r=this.#d;if(!r.canNavigate())return this.lastSyncRejected=!0,me;let i,a,c=!1,u=null;try{if(i=r.buildNavigateState(t,e),!i)return r.emitTransitionError(void 0,r.getState(),pe),this.lastSyncRejected=!0,ve;if(a=r.getState(),n=function(t,e){return e?.name!==o.UNKNOWN_ROUTE||t.replace?t:{...t,replace:!0}}(n,a),function(t,e,n){return!!t&&!e.reload&&!e.force&&t.path===n.path}(a,n,i))return r.emitTransitionError(i,a,ge),this.lastSyncRejected=!0,Se;if(this.#K(),n.signal?.aborted)throw new de(s.TRANSITION_CANCELLED,{reason:n.signal.reason});const l=++this.#Q;if(r.startTransition(i,a),c=!0,this.#Q!==l)throw new de(s.TRANSITION_CANCELLED);const[h,d]=r.getLifecycleFunctions(),f=i.name===o.UNKNOWN_ROUTE,{toDeactivate:p,toActivate:g,intersection:m}=ae(i,a),v=a&&!n.forceDeactivate&&p.length>0,S=!f&&g.length>0;if(h.size>0||d.size>0){u=new AbortController,this.#V=u;const t=()=>this.#Q===l&&r.isActive(),e=function(t,e,n,r,i,a,o,c,u,l){if(i){const i=Oe(t,n,s.CANNOT_DEACTIVATE,o,c,u,l);if(void 0!==i)return async function(t,e,n,r,i,a,o,c){if(await t,!c())throw new de(s.TRANSITION_CANCELLED);if(r){const t=Oe(e,n,s.CANNOT_ACTIVATE,i,a,o,c);if(void 0!==t&&await t,!c())throw new de(s.TRANSITION_CANCELLED)}}(i,e,r,a,o,c,u,l)}if(!l())throw new de(s.TRANSITION_CANCELLED);if(a)return Oe(e,r,s.CANNOT_ACTIVATE,o,c,u,l)}(h,d,p,g,!!v,S,i,a,u.signal,t);if(void 0!==e)return this.#H(e,{toState:i,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h},u,l);if(!t())throw new de(s.TRANSITION_CANCELLED);this.#J(u)}return this.lastSyncResolved=!0,Promise.resolve(Te(r,{toState:i,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h}))}catch(t){return this.#Y(t,u,c,i,a),Promise.reject(t)}}navigateToDefault(t){const e=this.#d;if(!e.getOptions().defaultRoute)return Promise.reject(new de(s.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"}));const{route:n,params:r}=e.resolveDefault();return n?this.navigate(n,r,t):Promise.reject(new de(s.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"}))}navigateToNotFound(t){this.#K();const e=this.#d.getState(),n=e?ee(e.name).toReversed():[];Object.freeze(n);const r={deactivated:n,activated:Ee,intersection:""};Object.freeze(r);const i={phase:"activating",...e&&{from:e.name},reason:"success",segments:r};Object.freeze(i);const s={name:o.UNKNOWN_ROUTE,params:{},path:t,transition:i};return Object.freeze(s),this.#d.setState(s),this.#d.emitTransitionSuccess(s,e,Pe),s}abortCurrentNavigation(){this.#V?.abort(new de(s.TRANSITION_CANCELLED)),this.#V=null}async#H(t,e,n,r){const i=this.#d,a=()=>this.#Q===r&&!n.signal.aborted&&i.isActive();try{if(e.opts.signal){if(e.opts.signal.aborted)throw new de(s.TRANSITION_CANCELLED,{reason:e.opts.signal.reason});e.opts.signal.addEventListener("abort",()=>{n.abort(e.opts.signal?.reason)},{once:!0,signal:n.signal})}if(await t,!a())throw new de(s.TRANSITION_CANCELLED);return Te(i,e)}catch(t){throw ye(i,t,e.toState,e.fromState),t}finally{this.#J(n)}}#Y(t,e,n,r,i){e&&this.#J(e),n&&r&&ye(this.#d,t,r,i)}#J(t){t.abort(),this.#V===t&&(this.#V=null)}#K(){this.#d.isTransitioning()&&(t.logger.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use cloneRouter() to create isolated instance per request."),this.#V?.abort(new de(s.TRANSITION_CANCELLED)),this.#d.cancelNavigation())}},Ce={replace:!0};Object.freeze(Ce);var De=class{#d;setDependencies(t){this.#d=t}async start(t){const e=this.#d,n=e.getOptions(),r=e.matchPath(t);if(!r&&!n.allowNotFound){const n=new de(s.ROUTE_NOT_FOUND,{path:t});throw e.emitTransitionError(void 0,void 0,n),n}return e.completeStart(),r?e.navigate(r.name,r.params,Ce):e.navigateToNotFound(t)}stop(){this.#d.clearState()}},Fe=class{#X;#Z;#tt;#et;#nt;#rt;constructor(t){this.#X=t.routerFSM,this.#Z=t.emitter,this.#tt=void 0,this.#it()}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.#Z.emit(p.ROUTER_START)}emitRouterStop(){this.#Z.emit(p.ROUTER_STOP)}emitTransitionStart(t,e){this.#Z.emit(p.TRANSITION_START,t,e)}emitTransitionSuccess(t,e,n){this.#Z.emit(p.TRANSITION_SUCCESS,t,e,n)}emitTransitionError(t,e,n){this.#Z.emit(p.TRANSITION_ERROR,t,e,n)}emitTransitionCancel(t,e){this.#Z.emit(p.TRANSITION_CANCEL,t,e)}sendStart(){this.#X.send(b)}sendStop(){this.#X.send(R)}sendDispose(){this.#X.send(C)}sendStarted(){this.#X.send(N)}sendNavigate(t,e){this.#tt=t,this.#X.forceState(y),this.emitTransitionStart(t,e)}sendComplete(t,e,n={}){this.#X.forceState(T),this.emitTransitionSuccess(t,e,n),this.#tt===t&&(this.#tt=void 0)}sendFail(t,e,n){const r=this.#tt;this.#et=t,this.#nt=e,this.#rt=n,this.#X.send(E),this.#tt===r&&(this.#tt=void 0)}sendFailSafe(t,e,n){this.isReady()?this.sendFail(t,e,n):this.emitTransitionError(t,e,n)}sendCancel(t,e){const n=this.#tt;this.#et=t,this.#nt=e,this.#X.send(P),this.#tt===n&&(this.#tt=void 0)}canBeginTransition(){return this.#X.canSend(A)}canStart(){return this.#X.canSend(b)}canCancel(){return this.#X.canSend(P)}isActive(){const t=this.#X.getState();return t!==v&&t!==w}isDisposed(){return this.#X.getState()===w}isTransitioning(){return this.#X.getState()===y}isReady(){return this.#X.getState()===T}getCurrentToState(){return this.#tt}addEventListener(t,e){return this.#Z.on(t,e)}subscribe(t){return this.#Z.on(p.TRANSITION_SUCCESS,(e,n)=>{t({route:e,previousRoute:n})})}clearAll(){this.#Z.clearAll()}setLimits(t){this.#Z.setLimits(t)}sendCancelIfTransitioning(t){this.canCancel()&&this.sendCancel(this.#tt,t)}#st(){this.emitTransitionError(this.#et,this.#nt,this.#rt)}#it(){const t=this.#X;t.on(S,N,()=>{this.emitRouterStart()}),t.on(T,R,()=>{this.emitRouterStop()}),t.on(y,P,()=>{const t=this.#et;void 0!==t&&this.emitTransitionCancel(t,this.#nt)}),t.on(S,E,()=>{this.#st()}),t.on(T,E,()=>{this.#st()}),t.on(y,E,()=>{this.#st()})}},je=new de(s.ROUTER_ALREADY_STARTED),Le=new Set(["all","warn-error","error-only"]);var Ie=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),this.routeLifecycle.setValidatorGetter(()=>{try{return M(this.router).validator}catch{return null}})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(t,e)=>{this.routeLifecycle.addCanActivate(t,e,!0)},addDeactivateGuard:(t,e)=>{this.routeLifecycle.addCanDeactivate(t,e,!0)},makeState:(t,e,n,r)=>this.state.makeState(t,e,n,r),getState:()=>this.state.get(),areStatesEqual:(t,e,n)=>this.state.areStatesEqual(t,e,n),getDependency:t=>this.dependenciesStore.dependencies[t],forwardState:(t,e)=>{const n=M(this.router);return n.validator?.routes.validateStateBuilderArgs(t,e,"forwardState"),n.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),this.plugins.setValidatorGetter(()=>{try{return M(this.router).validator}catch{return null}})}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 n=M(this.router);n.validator?.routes.validateStateBuilderArgs(t,e,"navigate");const{name:r,params:i}=n.forwardState(t,e),s=this.routes.getMetaForState(r);if(void 0===s)return;const a=n.buildPath(r,i);return this.state.makeState(r,i,a,s,!0)},resolveDefault:()=>{const t=this.options.get();return{route:k(t.defaultRoute,t=>this.dependenciesStore.dependencies[t]),params:k(t.defaultParams,t=>this.dependenciesStore.dependencies[t])}},startTransition:(t,e)=>{this.eventBus.sendNavigate(t,e)},cancelNavigation:()=>{const t=this.eventBus.getCurrentToState();void 0!==t&&this.eventBus.sendCancel(t,this.state.get())},sendTransitionDone:(t,e,n)=>{this.eventBus.sendComplete(t,e,n)},sendTransitionFail:(t,e,n)=>{this.eventBus.sendFail(t,e,n)},emitTransitionError:(t,e,n)=>{this.eventBus.sendFailSafe(t,e,n)},emitTransitionSuccess:(t,e,n)=>{this.eventBus.emitTransitionSuccess(t,e,n)},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,n)=>this.navigation.navigate(t,e,n),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,n)=>{this.eventBus.sendFail(t,e,n)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(t,e)=>M(this.router).buildPath(t,e),getUrlParams:t=>this.routes.getUrlParams(t)})}createCompileFactory(){const{router:t,dependenciesStore:e}=this;return n=>n(t,t=>e.dependencies[t])}},_e=Object.freeze({}),Me=class n{#u;#v;#at;#ot;#ct;#ut;#g;#lt;#ht;#dt;constructor(n=[],r={},s={}){r.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(n=e.level)||!Le.has(n)))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 n;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}(r.logger)&&(t.logger.configure(r.logger),delete r.logger),z.validateOptionsIsObject(r),function(t){if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError("dependencies must be a plain object");for(const e in t)if(Object.getOwnPropertyDescriptor(t,e)?.get)throw new TypeError(`dependencies cannot contain getters: "${e}"`)}(s),n.length>0&&F(n),this.#u=new z(r),this.#v=function(t={}){return{...g,...t}}(r.limits),this.#at=function(t={}){const e=Object.create(null);for(const n in t)void 0!==t[n]&&(e[n]=t[n]);return{dependencies:e,limits:g}}(s),this.#ot=new V,this.#ct=new ce(n,function(t){return{strictTrailingSlash:"strict"===t.trailingSlash,strictQueryParams:"strict"===t.queryParamsMode,urlParamsEncoding:t.urlParamsEncoding,queryParams:t.queryParams}}(this.#u.get())),this.#ut=new Y,this.#g=new J,this.#lt=new Re,this.#ht=new De;const a=new e.FSM(D),o=new i({onListenerError:(e,n)=>{t.logger.error("Router",`Error in listener for ${e}:`,n)},onListenerWarn:(e,n)=>{t.logger.warn("router.addEventListener",`Event "${e}" has ${n} listeners — possible memory leak`)}});var c;this.#dt=new Fe({routerFSM:a,emitter:o}),(c=new Ie({router:this,options:this.#u,limits:this.#v,dependenciesStore:this.#at,state:this.#ot,routes:this.#ct,routeLifecycle:this.#ut,plugins:this.#g,navigation:this.#lt,lifecycle:this.#ht,eventBus:this.#dt})).wireLimits(),c.wireRouteLifecycleDeps(),c.wireRoutesDeps(),c.wirePluginsDeps(),c.wireNavigationDeps(),c.wireLifecycleDeps(),c.wireStateDeps();const u=new Map;var l,h,d;l={makeState:(t,e,n,r)=>this.#ot.makeState(t,e,n,r),forwardState:$("forwardState",(t,e)=>this.#ct.forwardState(t,e),u),buildStateResolved:(t,e)=>this.#ct.buildStateResolved(t,e),matchPath:(t,e)=>this.#ct.matchPath(t,e),getOptions:()=>this.#u.get(),addEventListener:(t,e)=>this.#dt.addEventListener(t,e),buildPath:$("buildPath",(t,e)=>this.#ct.buildPath(t,e??m,this.#u.get()),u),start:(h=t=>this.#ht.start(t),d=u,(...t)=>{const e=d.get("start");return e&&0!==e.length?U(e,h,t):h(...t)}),interceptors:u,setRootPath:t=>{this.#ct.setRootPath(t)},getRootPath:()=>this.#ct.getStore().rootPath,getTree:()=>this.#ct.getStore().tree,isDisposed:()=>this.#dt.isDisposed(),validator:null,dependenciesGetStore:()=>this.#at,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#at.dependencies}),getLifecycleFactories:()=>this.#ut.getFactories(),getPluginFactories:()=>this.#g.getAll(),routeGetStore:()=>this.#ct.getStore(),getStateName:()=>this.#ot.get()?.name,isTransitioning:()=>this.#dt.isTransitioning(),clearState:()=>{this.#ot.set(void 0)},setState:t=>{this.#ot.set(t)},routerExtensions:[]},_.set(this,l),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.dispose=this.dispose.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToNotFound=this.navigateToNotFound.bind(this),this.subscribe=this.subscribe.bind(this)}isActiveRoute(e,n,r,i){return M(this).validator?.routes.validateIsActiveRouteArgs(e,n,r,i),M(this).validator?.routes.validateRouteName(e,"isActiveRoute"),""===e?(t.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#ct.isActiveRoute(e,n,r,i)}buildPath(t,e){const n=M(this);return n.validator?.routes.validateBuildPathArgs(t),n.validator?.navigation.validateParams(e,"buildPath"),n.buildPath(t,e)}getState(){return this.#ot.get()}getPreviousState(){return this.#ot.getPrevious()}areStatesEqual(t,e,n=!0){return M(this).validator?.state.validateAreStatesEqualArgs(t,e,n),this.#ot.areStatesEqual(t,e,n)}shouldUpdateNode(t){return M(this).validator?.routes.validateShouldUpdateNodeArgs(t),ce.shouldUpdateNode(t)}isActive(){return this.#dt.isActive()}start(t){if(!this.#dt.canStart())return Promise.reject(je);M(this).validator?.navigation.validateStartArgs(t),this.#dt.sendStart();const e=M(this).start(t).catch(t=>{throw this.#dt.isReady()&&(this.#ht.stop(),this.#dt.sendStop()),t});return n.#ft(e),e}stop(){return this.#lt.abortCurrentNavigation(),this.#dt.sendCancelIfTransitioning(this.#ot.get()),this.#dt.isReady()||this.#dt.isTransitioning()?(this.#ht.stop(),this.#dt.sendStop(),this):this}dispose(){if(this.#dt.isDisposed())return;this.#lt.abortCurrentNavigation(),this.#dt.sendCancelIfTransitioning(this.#ot.get()),(this.#dt.isReady()||this.#dt.isTransitioning())&&(this.#ht.stop(),this.#dt.sendStop()),this.#dt.sendDispose(),this.#dt.clearAll(),this.#g.disposeAll();const t=M(this);for(const e of t.routerExtensions)for(const t of e.keys)delete this[t];t.routerExtensions.length=0,this.#ct.clearRoutes(),this.#ut.clearAll(),this.#ot.reset(),this.#at.dependencies=Object.create(null),this.#pt()}canNavigateTo(t,e){const n=M(this);if(n.validator?.routes.validateRouteName(t,"canNavigateTo"),n.validator?.navigation.validateParams(e,"canNavigateTo"),!this.#ct.hasRoute(t))return!1;const{name:r,params:i}=n.forwardState(t,e??{}),s=this.#ot.makeState(r,i),a=this.#ot.get(),{toDeactivate:o,toActivate:c}=ae(s,a);return this.#ut.canNavigateTo(o,c,s,a)}usePlugin(...t){const e=t.filter(Boolean);if(0===e.length)return()=>{};const n=M(this);n.validator?.plugins.validatePluginLimit(this.#g.count(),this.#v);for(const t of e)n.validator?.plugins.validateNoDuplicatePlugins(t,this.#g.getAll());return this.#g.use(...e)}subscribe(t){return Fe.validateSubscribeListener(t),this.#dt.subscribe(t)}navigate(t,e,r){const i=M(this);i.validator?.navigation.validateNavigateArgs(t),i.validator?.navigation.validateParams(e,"navigate");const s=r??_e;i.validator?.navigation.validateNavigationOptions(s,"navigate");const a=this.#lt.navigate(t,e??m,s);return this.#lt.lastSyncResolved?this.#lt.lastSyncResolved=!1:this.#lt.lastSyncRejected?this.#lt.lastSyncRejected=!1:n.#ft(a),a}navigateToDefault(t){const e=M(this);e.validator?.navigation.validateNavigateToDefaultArgs(t);const r=t??_e;e.validator?.navigation.validateNavigationOptions(r,"navigateToDefault");const i=this.#lt.navigateToDefault(r);return this.#lt.lastSyncResolved?this.#lt.lastSyncResolved=!1:this.#lt.lastSyncRejected?this.#lt.lastSyncRejected=!1:n.#ft(i),i}navigateToNotFound(t){if(!this.#dt.isActive())throw new de(s.ROUTER_NOT_STARTED);if(void 0!==t&&"string"!=typeof t)throw new TypeError("[router.navigateToNotFound] path must be a string, got "+typeof t);const e=t??this.#ot.get().path;return this.#lt.navigateToNotFound(e)}static#gt=e=>{e instanceof de&&(e.code===s.SAME_STATES||e.code===s.TRANSITION_CANCELLED||e.code===s.ROUTER_NOT_STARTED||e.code===s.ROUTE_NOT_FOUND)||t.logger.error("router.navigate","Unexpected navigation error",e)};static#ft(t){t.catch(n.#gt)}#pt(){this.navigate=Ue,this.navigateToDefault=Ue,this.navigateToNotFound=Ue,this.start=Ue,this.stop=Ue,this.usePlugin=Ue,this.subscribe=Ue,this.canNavigateTo=Ue}};function Ue(){throw new de(s.ROUTER_DISPOSED)}var $e=new WeakMap;exports.Router=Me,exports.RouterError=de,exports.UNKNOWN_ROUTE=a,exports.constants=o,exports.createRouter=(t=[],e={},n={})=>new Me(t,e,n),exports.errorCodes=s,exports.events=p,exports.getNavigator=t=>{let e=$e.get(t);return e||(e=Object.freeze({navigate:t.navigate,getState:t.getState,isActiveRoute:t.isActiveRoute,canNavigateTo:t.canNavigateTo,subscribe:t.subscribe}),$e.set(t,e)),e},exports.resolveForwardChain=$t;//# sourceMappingURL=index.js.map