@real-router/core 0.40.0 → 0.40.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api.js +1 -1
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/metafile-cjs.json +1 -1
- package/dist/esm/api.mjs +1 -1
- package/dist/esm/{chunk-RA5VYM7M.mjs → chunk-MNRZAE7T.mjs} +1 -1
- package/dist/esm/chunk-MNRZAE7T.mjs.map +1 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/metafile-esm.json +1 -1
- package/package.json +3 -2
- package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +2 -3
- package/src/namespaces/NavigationNamespace/types.ts +0 -7
- package/src/wiring/RouterWiringBuilder.ts +0 -2
- package/dist/esm/chunk-RA5VYM7M.mjs.map +0 -1
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},i=class extends Error{},r=class{#t=new Map;#e=null;#n=n;#i;#r;constructor(t){t?.limits&&(this.#n=t.limits),this.#i=t?.onListenerError??null,this.#r=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:i,warnListeners:r}=this.#n;if(0!==r&&n.size===r&&this.#r?.(t,r),0!==i&&n.size>=i)throw new Error(`Listener limit (${i}) reached for "${t}"`);return n.add(e),()=>{this.off(t,e)}}off(t,e){this.#t.get(t)?.delete(e)}emit(t,e,n,i,r){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,i,r):this.#o(s,t,a,e,n,i,r)}clearAll(){this.#t.clear(),this.#e=null}listenerCount(t){return this.#t.get(t)?.size??0}#o(t,e,n,i,r,s,a){if(1===t.size){const[o]=t;try{this.#c(o,n,i,r,s,a)}catch(t){this.#i?.(e,t)}return}const o=[...t];for(const t of o)try{this.#c(t,n,i,r,s,a)}catch(t){this.#i?.(e,t)}}#c(t,e,n,i,r,s){switch(e){case 0:t();break;case 1:t(n);break;case 2:t(n,i);break;case 3:t(n,i,r);break;default:t(n,i,r,s)}}#a(t,e,n,r,s,a,o){this.#e??=new Map;const c=this.#e,u=c.get(e)??0;if(u>=this.#n.maxEventDepth)throw new i(`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,r,s,a,o)}catch(t){if(t instanceof i)throw t;this.#i?.(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 i=e;for(const e of t){const t=i;i=(...n)=>e(t,...n)}return i(...n)}function $(t,e,n){return(i,r)=>{const s=n.get(t);return s&&0!==s.length?U(s,e,[i,r]):e(i,r)}}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,i,r,s){const a=i?{id:r??++this.#l,params:i}: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 i=t[n];for(const t in i)"url"===i[t]&&e.push(t)}return e}(n):this.#g(t.name)).every(n=>q(t.params[n],e.params[n]))}const i=Object.keys(t.params),r=Object.keys(e.params);return i.length===r.length&&i.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],i=this.#y(n);this.#m.add(n);let r=!1;const s=()=>{if(!r){r=!0,this.#m.delete(n),this.#v.delete(s);try{i()}catch(e){t.logger.error(Q,"Error during cleanup:",e)}}};return this.#v.add(s),s}const n=this.#w(e),i=[];try{for(const t of n){const e=this.#y(t);i.push({factory:t,cleanup:e})}}catch(e){for(const{cleanup:e}of i)try{e()}catch(e){t.logger.error(Q,"Cleanup error:",e)}throw e}for(const{factory:t}of i)this.#m.add(t);let r=!1;const s=()=>{if(!r){r=!0,this.#v.delete(s);for(const{factory:t}of i)this.#m.delete(t);for(const{cleanup:e}of i)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 i=[];for(const t of V)t in n&&("function"==typeof n[t]?(i.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 i)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 i=this.#N.has(t);this.#D("activate",t,e,this.#N,this.#O,"canActivate",i)}addCanDeactivate(t,e,n=!1){n?this.#C.add(t):this.#C.delete(t);const i=this.#b.has(t);this.#D("deactivate",t,e,this.#b,this.#A,"canDeactivate",i)}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,i){for(const e of t)if(!this.#F(this.#A,e,n,i,"canNavigateTo"))return!1;for(const t of e)if(!this.#F(this.#O,t,n,i,"canNavigateTo"))return!1;return!0}#D(t,e,n,i,r,s,a){a?this.#T?.()?.lifecycle.warnOverwrite(e,t,s):this.#T?.()?.lifecycle.validateCountThresholds(i.size+1,s);const o="boolean"==typeof n?function(t){const e=()=>t;return()=>e}(n):n;i.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}`);r.set(e,t)}catch(t){throw i.delete(e),t}finally{this.#P.delete(e)}}#F(t,e,n,i,r){const s=t.get(e);if(!s)return!0;try{const t=s(n,i);return"boolean"==typeof t?t:(this.#T?.()?.lifecycle.warnAsyncGuardSync(e,r),!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,it=/[^\w!$'()*+,.:;|~-]/u,rt={default:t=>it.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 i=t[n],r=encodeURIComponent(n);e.push(""===i?r:`${r}=${encodeURIComponent(String(i))}`)}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,i=t.codePointAt(e+2)??0;if(!lt(n)||!lt(i))return!1;e+=3}else e++;return!0}var dt=/<[^>]*>/g;function ft(t,e,n,i,r){const s=""===e.fullName;s||i.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=r;s||(f=function(t,e,n,i,r,s){const a=(m=i,ot(n)===ot(m)),o=Object.freeze([...r]),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,r),h=function(t){const e=new Map;for(const n of t)for(const[t,i]of n.paramMeta.constraintPatterns)e.set(t,i);return e}(r),d=a?ot(i):u,{buildStaticParts:f,buildParamSlots:p}=function(t,e,n){const i=new Set,r=new Set;for(const t of e){for(const e of t.paramMeta.urlParams)i.add(e);for(const e of t.paramMeta.spatParams)r.add(e)}if(0===i.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],i="?"===c[2];s.push(t.slice(u,c.index));const o=r.has(e);a.push({paramName:e,isOptional:i,encoder:o?t=>{const e=rt[n],i=t.split("/");let r=e(i[0]);for(let t=1;t<i.length;t++)r+=`/${e(i[t])}`;return r}:rt[n]}),u=c.index+c[0].length}return s.push(t.slice(u)),{buildStaticParts:s,buildParamSlots:a}}(d,a?r.slice(0,-1):r,t.options.urlParamsEncoding),g={name:e.fullName,parent:s,depth:r.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 i,r;i=e,(function(t,e,n){const i=ot(n);if("/"===i||""===i)return e;let r=e,s=1;const a=i.length;for(;s<=a;){const e=i.indexOf("/",s),n=-1===e?a:e;if(n<=s)break;r=gt(t,r,i.slice(s,n)),s=n+1}return r}(r=t,r.root,n)).slashChildRoute=i;const s=ot(n),a=t.options.caseSensitive?s:s.toLowerCase();t.staticCache.has(a)&&t.staticCache.set(a,e)}(t,g,i):function(t,e,n,i,r){if(function(t,e,n){const i=ot(n);"/"!==i?pt(t,t.root,i,1,e):t.root.route=e}(t,e,n),0===r.paramMeta.urlParams.length){const n=t.options.caseSensitive?i:i.toLowerCase();t.staticCache.set(n,e)}}(t,g,n,u,e),g}(t,e,l,a?"":n,i,r));for(const n of e.children.values())ft(t,n,l,i,f);s||i.pop()}function pt(t,e,n,i,r){const s=n.length;for(;i<=s;){const a=n.indexOf("/",i),o=-1===a?s:a,c=n.slice(i,o);if(c.endsWith("?")){const i=c.slice(1).replaceAll(dt,"").replace(/\?$/,"");return e.paramChild??={node:at(),name:i},pt(t,e.paramChild.node,n,o+1,r),void(o>=s?e.route??=r:pt(t,e,n,o+1,r))}e=gt(t,e,c),i=o+1}e.route=r}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 i=t.options.caseSensitive?n:n.toLowerCase();return i in e.staticChildren||(e.staticChildren[i]=at()),e.staticChildren[i]}var mt=/[\u0080-\uFFFF]/,vt=class{get options(){return this.#t}#t;#e=at();#r=new Map;#s=new Map;#n=new Map;#a=new Map;#i="";#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.#r,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,i,r]=e,s=this.#t.caseSensitive?i:i.toLowerCase(),a=this.#a.get(s);if(a){if(this.#t.strictTrailingSlash&&!this.#o(n,a))return;return this.#L(a,{},r)}const o={},c=this.#I(i,o);return!c||this.#t.strictTrailingSlash&&!this.#o(n,c)||c.hasConstraints&&!this.#_(o,c)||!this.#M(o)?void 0:this.#L(c,o,r)}buildPath(t,e,n){const i=this.#r.get(t);if(!i)throw new Error(`[SegmentMatcher.buildPath] '${t}' is not defined`);i.hasConstraints&&e&&this.#U(i,t,e);const r=this.#$(i,e),s=this.#B(r,n?.trailingSlash),a=this.#x(i,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.#r.has(t)}setRootPath(t){this.#i=t}#U(t,e,n){for(const[i,r]of t.constraintPatterns){const t=n[i];if(null!=t){const n="object"==typeof t?JSON.stringify(t):String(t);if(!r.pattern.test(n))throw new Error(`[SegmentMatcher.buildPath] '${e}' — param '${i}' value '${n}' does not match constraint '${r.constraint}'`)}}}#$(t,e){const n=t.buildStaticParts,i=t.buildParamSlots;if(0===i.length)return this.#i+n[0];let r=this.#i+n[0];for(const[t,s]of i.entries()){const i=e?.[s.paramName];if(null==i){if(!s.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${s.paramName}'`);r.length>1&&r.endsWith("/")&&(r=r.slice(0,-1)),r+=n[t+1];continue}const a="object"==typeof i?JSON.stringify(i):String(i);r+=s.encoder(a)+n[t+1]}return r}#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 i={};let r=!1;for(const n of t.declaredQueryParams)n in e&&(i[n]=e[n],r=!0);if("loose"===n)for(const n in e)!Object.hasOwn(e,n)||t.declaredQueryParamsSet.has(n)||t.buildParamNamesSet.has(n)||(i[n]=e[n],r=!0);return r?this.#t.buildQueryString(i):""}#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.#i.length>0){if(!t.startsWith(this.#i))return;t=t.slice(this.#i.length)||"/"}const n=t.indexOf("?"),i=-1===n?t:t.slice(0,n),r=-1===n?void 0:t.slice(n+1);return i.includes("//")?void 0:[i,ot(i),r]}#L(t,e,n){if(void 0!==n){const i=this.#t.parseQueryString(n);if(this.#t.strictQueryParams){const e=t.declaredQueryParamsSet;for(const t of Object.keys(i))if(!e.has(t))return}for(const t of Object.keys(i))e[t]=i[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,i){let r=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 r.staticChildren)u=r.staticChildren[c];else{if(!r.paramChild){if(r.splatChild){const t={},s=this.#k(r.splatChild.node,e,n,t);return s?(Object.assign(i,t),s):(i[r.splatChild.name]=e.slice(n),r.splatChild.node.route)}return}u=r.paramChild.node,i[r.paramChild.name]=o}r=u,n=a+1}return r.slashChildRoute??r.route}#M(t){const e=this.#t.urlParamsEncoding;if("none"===e)return!0;const n=st[e];for(const e in t){const i=t[e];if(i.includes("%")){if(!ht(i))return!1;t[e]=n(i)}}return!0}#_(t,e){for(const[n,i]of e.constraintPatterns)if(!i.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 i=-1===n?t:t.split("+").join(" ");return-1===e?i:decodeURIComponent(i)},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",i=t.nullFormat??"default";return{arrayFormat:e,booleanFormat:n,nullFormat:i,strategies:Nt(e,n,i)}},Et=t=>encodeURIComponent(t),Pt=(t,e,n)=>{const i=Et(t);switch(typeof e){case"string":case"number":default:return`${i}=${Et(e)}`;case"boolean":return n.strategies.boolean.encode(i,e);case"object":return null===e?n.strategies.null.encode(i):Array.isArray(e)?n.strategies.array.encodeArray(i,e):`${i}=${Et(e)}`}};function Rt(t,e,n,i,r){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,i){const r=t[e];void 0===r?t[e]=i?[n]:n:Array.isArray(r)?r.push(n):t[e]=[r,n]}(i,St(c),(l=t,h=s,d=n,f=a,p=r,p?((t,e)=>{if(void 0===t)return e.boolean.decodeUndefined();const n=e.boolean.decodeRaw(t);if(null!==n)return n;const i=St(t);return e.boolean.decodeValue(i)})(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,i=n.startsWith("~"),r=i?n.slice(1):n,s={name:t.name,path:r,absolute:i,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 i=function(t){const e=[],n=[],i=[],r={},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),r[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])i.push(t),e.push(t),r[t]="url";else if(e.push(t),r[t]="url",n){const e=`^${X(n)}$`;s.set(t,{pattern:new RegExp(e),constraint:n})}}return{urlParams:e,queryParams:n,spatParams:i,paramTypeMap:r,constraintPatterns:s,pathPattern:t}}(t.path),r=function(t){const e={};for(const n of t.urlParams)e[n]="url";for(const n of t.queryParams)e[n]="query";return e}(i),s={name:t.name,path:t.path,absolute:t.absolute,parent:e,children:void 0,paramMeta:i,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:r};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 i=[],r=[];for(const s of t){const t=jt(s,e,n);i.push(t),t.absolute||r.push(t)}return{childrenMap:Ft(i),nonAbsoluteChildren:r}}(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:i}=t.paramMeta;if(e.length>0||n.length>0||i.length>0)return null;const r=[];let s=t.parent;for(;s?.path;)r.unshift(s),s=s.parent;let a="";for(const t of r){const{urlParams:e,queryParams:n,spatParams:i}=t.paramMeta;if(e.length>0||n.length>0||i.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(r),Object.freeze(s.children),Object.freeze(s)),s}function Lt(t,e,n,i){return function(t,e){const n=[];return{add(t){return n.push(t),this},addMany(t){return n.push(...t),this},build:i=>function(t,e=!0){return jt(t,null,e)}(function(t,e,n){const i=Ct({name:t,path:e},null);for(const t of n){const e=Ct(t,i);i.children.push(e)}return i}(t,e,n),!i?.skipFreeze)}}(t,e).addMany(n).build(i)}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 i=t.length;for(;n<i;){let r=t.indexOf("&",n);-1===r&&(r=i),Rt(t,n,r,e),n=r+1}}(t,e),e}(n);const i=Ot(e),r={};let s=0;const a=n.length;for(;s<a;){let t=n.indexOf("&",s);-1===t&&(t=a),Rt(n,s,t,r,i.strategies),s=t+1}return r})(t,e),buildQueryString:t=>((t,e)=>{const n=Object.keys(t);if(0===n.length)return"";const i=Ot(e),r=[];for(const e of n){const n=t[e];if(void 0===n)continue;const s=Pt(e,n,i);s&&r.push(s)}return r.join("&")})(t,e)})}function Mt(t,e,n=100){const i=new Set,r=[t];let s=t;for(;e[s];){const t=e[s];if(i.has(t)){const e=r.indexOf(t),n=[...r.slice(e),t];throw new Error(`Circular forwardTo: ${n.join(" → ")}`)}if(i.add(s),r.push(t),s=t,r.length>n)throw new Error(`forwardTo chain exceeds maximum depth (${n}): ${r.join(" → ")}`)}return s}function Ut(t,e,n){const i=Lt("",e,t),r=_t(n);return r.registerTree(i),{tree:i,matcher:r}}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,i,r,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&&(r[n]=u),e.canActivate&&s.set(n,e.canActivate),e.canDeactivate&&a.set(n,e.canDeactivate),e.forwardTo&&function(e,n,i){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,i=e.forwardTo.toString().includes("__awaiter");if(t||i)throw new TypeError(`forwardTo callback cannot be async for route "${n}". Async functions break matchPath/buildPath.`)}"string"==typeof e.forwardTo?i.forwardMap[n]=e.forwardTo:i.forwardFnMap[n]=e.forwardTo}(e,n,i),e.decodeParams&&(i.decoders[n]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(i.encoders[n]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(i.defaultParams[n]=e.defaultParams)}function qt(t,e,n,i,r,s,a=""){for(const o of t){const t=a?`${a}.${o.name}`:o.name;zt(o,t,e,n,i,r),o.children&&qt(o.children,e,n,i,r,s,t)}}function Gt(t,e){const n=[],i=J(),r=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,i,r,s,a,void 0,""),{definitions:n,config:i,tree:o,matcher:c,resolvedForwardMap:kt(i),routeCustomFields:r,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 i=e.meta?.params[t];if(!i||"object"!=typeof i)return!0;for(const t of Object.keys(i)){const i=e.params[t],r=n.params[t];if(Kt(i)&&Kt(r)&&String(i)!==String(r))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 i=t.indexOf(Wt,n+1);if(-1===i)return[t.slice(0,e),t.slice(0,n),t];return-1===t.indexOf(Wt,i+1)?[t.slice(0,e),t.slice(0,n),t.slice(0,i),t]:function(t){const e=t.split(Wt),n=e.length,i=[e[0]];let r=e[0].length;for(let s=1;s<n-1;s++)r+=1+e[s].length,i.push(t.slice(0,r));return i.push(t),i}(t)}(t);return Object.freeze(n),Xt.set(t,n),n}var te,ee,ne=null,ie=null;function re(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),i=Zt(e.name),r=function(t,e,n,i,r){for(let s=0;s<r;s++){const r=n[s];if(r!==i[s])return s;if(!Ht(r,t,e))return s}return r}(t,e,n,i,Math.min(i.length,n.length));let s;if(r>=i.length)s=Vt;else if(0===r&&1===i.length)s=i;else{s=[];for(let t=i.length-1;t>=r;t--)s.push(i[t])}const a=0===r?n:n.slice(r);return{intersection:r>0?i[r-1]:"",toDeactivate:s,toActivate:a}}function se(t,e,n){if(n)return re(t,e);if(null!==ne&&t===Jt&&e===Yt)return ne;if(null!==ie&&t===te&&e===ee)return ie;const i=re(t,e);return te=Jt,ee=Yt,ie=ne,Jt=t,Yt=e,ne=i,i}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:i,toActivate:r,toDeactivate:s}=se(e,n);return t===i||!!r.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 i=Object.hasOwn(this.#z.config.defaultParams,t)?{...this.#z.config.defaultParams[t],...e}:e??{},r="function"==typeof this.#z.config.encoders[t]?this.#z.config.encoders[t]({...i}):i;return this.#z.matcher.buildPath(t,r,this.#G(n))}matchPath(t,e){const n=e,i=this.#z.matcher.match(t);if(!i)return;const r=ae(i),{name:s,params:a,meta:o}=r,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),i=this.#z.config.forwardFnMap[t],r=this.#V(t,i,e);return{name:r,params:this.#W(r,n)}}const n=this.#z.resolvedForwardMap[t]??t;if(n!==t&&Object.hasOwn(this.#z.config.forwardFnMap,n)){const i=this.#W(t,e),r=this.#z.config.forwardFnMap[n],s=this.#V(n,r,e);return{name:s,params:this.#W(s,i)}}if(n!==t){const i=this.#W(t,e);return{name:n,params:this.#W(n,i)}}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,i=!0){const r=this.#f.getState();if(!r)return!1;const s=r.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:""},r,i)}const o=r.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 i in t)if(!(i in n)&&t[i]!==e[i])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 i=new Set([t]);let r=e(this.#f.getDependency,n),s=0;if("string"!=typeof r)throw new TypeError("forwardTo callback must return a string, got "+typeof r);for(;s<100;){if(void 0===this.#z.matcher.getSegmentsByName(r))throw new Error(`Route "${r}" does not exist`);if(i.has(r)){const t=[...i,r].join(" → ");throw new Error(`Circular forwardTo detected: ${t}`)}if(i.add(r),Object.hasOwn(this.#z.config.forwardFnMap,r)){r=(0,this.#z.config.forwardFnMap[r])(this.#f.getDependency,n),s++;continue}const t=this.#z.config.forwardMap[r];if(void 0===t)return r;r=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:i,redirect:r,...s}={}){super(e??t),this.code=t,this.segment=n,this.path=i,this.redirect=r?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),i=new WeakSet;return function t(e){if(null===e||"object"!=typeof e)return;if(i.has(e))return;i.add(e),Object.freeze(e);const n=Array.isArray(e)?e:Object.values(e);for(const e of n)t(e)}(n),n}(r):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:i,opts:r,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,i,e),e}if(i)for(const n of a)!c.includes(n)&&e.canDeactivateFunctions.has(n)&&t.clearCanDeactivate(n);n.transition=function(t,e,n,i,r){const s={phase:"activating",reason:"success",segments:{deactivated:n,activated:i,intersection:r}};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}(i,r,a,c,u);const l=I(n);t.setState(l);const h=void 0===r.signal?r:function({signal:t,...e}){return e}(r);return t.sendTransitionDone(l,i,h),l}function Te(t,e,n,i){e.code!==s.TRANSITION_CANCELLED&&e.code!==s.ROUTE_NOT_FOUND&&t.sendTransitionFail(n,i,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,i]of Object.entries(t))we.has(n)||(e[n]=i);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 i;try{i=await t}catch(t){return void ye(t,e,n)}if(!i)throw new he(e,{segment:n})}async function Ne(t,e,n,i,r,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(i,r,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,i,r,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(i,r,a)}catch(t){ye(t,n,u)}if(h instanceof Promise)return Ne(t,e,n,i,r,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 i=this.#f;if(!i.canNavigate())return this.lastSyncRejected=!0,ge;let r,a,c=!1,u=null;try{if(r=i.buildNavigateState(t,e),!r)return i.emitTransitionError(void 0,i.getState(),fe),this.lastSyncRejected=!0,me;if(a=i.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,r))return i.emitTransitionError(r,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(i.startTransition(r,a),c=!0,this.#K!==l)throw new he(s.TRANSITION_CANCELLED);const[h,d]=i.getLifecycleFunctions(),f=r.name===o.UNKNOWN_ROUTE,{toDeactivate:p,toActivate:g,intersection:m}=se(r,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&&i.isActive(),e=function(t,e,n,i,r,a,o,c,u,l){if(r){const r=Ae(t,n,s.CANNOT_DEACTIVATE,o,c,u,l);if(void 0!==r)return async function(t,e,n,i,r,a,o,c){if(await t,!c())throw new he(s.TRANSITION_CANCELLED);if(i){const t=Ae(e,n,s.CANNOT_ACTIVATE,r,a,o,c);if(void 0!==t&&await t,!c())throw new he(s.TRANSITION_CANCELLED)}}(r,e,i,a,o,c,u,l)}if(!l())throw new he(s.TRANSITION_CANCELLED);if(a)return Ae(e,i,s.CANNOT_ACTIVATE,o,c,u,l)}(h,d,p,g,!!v,S,r,a,u.signal,t);if(void 0!==e)return this.#J(e,{toState:r,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(i,{toState:r,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h}))}catch(t){return this.#X(t,u,c,r,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:i}=e.resolveDefault();return n?this.navigate(n,i,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 i={deactivated:n,activated:Oe,intersection:""};Object.freeze(i);const r={phase:"activating",...e&&{from:e.name},reason:"success",segments:i};Object.freeze(r);const s={name:o.UNKNOWN_ROUTE,params:{},path:t,transition:r};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,i){const r=this.#f,a=()=>this.#K===i&&!n.signal.aborted&&r.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(r,e)}catch(t){throw Te(r,t,e.toState,e.fromState),t}finally{this.#Y(n)}}#X(t,e,n,i,r){e&&this.#Y(e),n&&i&&Te(this.#f,t,i,r)}#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(),i=e.matchPath(t);if(!i&&!n.allowNotFound){const n=new he(s.ROUTE_NOT_FOUND,{path:t});throw e.emitTransitionError(void 0,void 0,n),n}return e.completeStart(),i?e.navigate(i.name,i.params,Re):e.navigateToNotFound(t)}stop(){this.#f.clearState()}},De=class{#Z;#tt;#et;#nt;#it;#rt;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 i=this.#et;this.#nt=t,this.#it=e,this.#rt=n,this.#Z.send(E),this.#et===i&&(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.#it=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.#it,this.#rt)}#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.#it)}),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,i)=>this.state.makeState(t,e,n,i),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:i,params:r}=n.forwardState(t,e),s=this.routes.getMetaForState(i);if(void 0===s)return;const a=n.buildPath(i,r);return this.state.makeState(i,r,a,s,void 0,!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])}},Ie=Object.freeze({}),_e=class n{#u;#S;#ot;#ct;#ut;#lt;#m;#ht;#dt;#ft;constructor(n=[],i={},s={}){i.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}(i.logger)&&(t.logger.configure(i.logger),delete i.logger),z.validateOptionsIsObject(i),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(i),this.#S=function(t={}){return{...g,...t}}(i.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 r({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,i,r)=>this.#ct.makeState(t,e,n,i,r),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,i,r){return M(this).validator?.routes.validateIsActiveRouteArgs(e,n,i,r),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,i,r)}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:i,params:r}=n.forwardState(t,e??{}),s=this.#ct.makeState(i,r),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,i){const r=M(this);r.validator?.navigation.validateNavigateArgs(t),r.validator?.navigation.validateParams(e,"navigate");const s=i??Ie;r.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 i=t??Ie;e.validator?.navigation.validateNavigationOptions(i,"navigateToDefault");const r=this.#ht.navigateToDefault(i);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:n.#pt(r),r}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
|