@tanstack/router-core 0.0.1-beta.41 → 0.0.1-beta.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/actions.js +94 -0
  3. package/build/cjs/actions.js.map +1 -0
  4. package/build/cjs/history.js +163 -0
  5. package/build/cjs/history.js.map +1 -0
  6. package/build/cjs/index.js +18 -20
  7. package/build/cjs/index.js.map +1 -1
  8. package/build/cjs/interop.js +175 -0
  9. package/build/cjs/interop.js.map +1 -0
  10. package/build/cjs/path.js +4 -5
  11. package/build/cjs/path.js.map +1 -1
  12. package/build/cjs/route.js +16 -138
  13. package/build/cjs/route.js.map +1 -1
  14. package/build/cjs/routeConfig.js +1 -7
  15. package/build/cjs/routeConfig.js.map +1 -1
  16. package/build/cjs/routeMatch.js +194 -199
  17. package/build/cjs/routeMatch.js.map +1 -1
  18. package/build/cjs/router.js +726 -703
  19. package/build/cjs/router.js.map +1 -1
  20. package/build/cjs/store.js +54 -0
  21. package/build/cjs/store.js.map +1 -0
  22. package/build/esm/index.js +1305 -1114
  23. package/build/esm/index.js.map +1 -1
  24. package/build/stats-html.html +1 -1
  25. package/build/stats-react.json +229 -192
  26. package/build/types/index.d.ts +172 -109
  27. package/build/umd/index.development.js +1381 -2331
  28. package/build/umd/index.development.js.map +1 -1
  29. package/build/umd/index.production.js +1 -1
  30. package/build/umd/index.production.js.map +1 -1
  31. package/package.json +4 -4
  32. package/src/actions.ts +157 -0
  33. package/src/history.ts +199 -0
  34. package/src/index.ts +4 -7
  35. package/src/interop.ts +169 -0
  36. package/src/link.ts +2 -2
  37. package/src/route.ts +34 -239
  38. package/src/routeConfig.ts +3 -34
  39. package/src/routeInfo.ts +6 -21
  40. package/src/routeMatch.ts +270 -285
  41. package/src/router.ts +967 -963
  42. package/src/store.ts +52 -0
  43. package/build/cjs/sharedClone.js +0 -122
  44. package/build/cjs/sharedClone.js.map +0 -1
  45. package/src/sharedClone.ts +0 -118
@@ -8,5 +8,5 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RouterCore={})}(this,(function(t){"use strict";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(t[n]=a[n])}return t},e.apply(this,arguments)}var a;!function(t){t.Pop="POP",t.Push="PUSH",t.Replace="REPLACE"}(a||(a={}));var n="beforeunload",r="popstate";function o(t){void 0===t&&(t={});var o=t.window,s=void 0===o?document.defaultView:o,i=s.history;function f(){var t=s.location,e=t.pathname,a=t.search,n=t.hash,r=i.state||{};return[r.idx,{pathname:e,search:a,hash:n,state:r.usr||null,key:r.key||"default"}]}var p=null;s.addEventListener(r,(function(){if(p)w.call(p),p=null;else{var t=a.Pop,e=f(),n=e[0],r=e[1];if(w.length){if(null!=n){var o=g-n;o&&(p={action:t,location:r,retry:function(){A(-1*o)}},A(o))}}else x(t)}}));var v=a.Pop,m=f(),g=m[0],y=m[1],b=l(),w=l();function P(t){return"string"==typeof t?t:h(t)}function _(t,a){return void 0===a&&(a=null),e({pathname:y.pathname,hash:"",search:""},"string"==typeof t?d(t):t,{state:a,key:u()})}function L(t,e){return[{usr:t.state,key:t.key,idx:e},P(t)]}function M(t,e,a){return!w.length||(w.call({action:t,location:e,retry:a}),!1)}function x(t){v=t;var e=f();g=e[0],y=e[1],b.call({action:v,location:y})}function A(t){i.go(t)}null==g&&(g=0,i.replaceState(e({},i.state,{idx:g}),""));var S={get action(){return v},get location(){return y},createHref:P,push:function t(e,n){var r=a.Push,o=_(e,n);if(M(r,o,(function(){t(e,n)}))){var c=L(o,g+1),l=c[0],u=c[1];try{i.pushState(l,"",u)}catch(t){s.location.assign(u)}x(r)}},replace:function t(e,n){var r=a.Replace,o=_(e,n);if(M(r,o,(function(){t(e,n)}))){var s=L(o,g),c=s[0],l=s[1];i.replaceState(c,"",l),x(r)}},go:A,back:function(){A(-1)},forward:function(){A(1)},listen:function(t){return b.push(t)},block:function(t){var e=w.push(t);return 1===w.length&&s.addEventListener(n,c),function(){e(),w.length||s.removeEventListener(n,c)}}};return S}function s(t){void 0===t&&(t={});var n=t,r=n.initialEntries,o=void 0===r?["/"]:r,s=n.initialIndex,c=o.map((function(t){return e({pathname:"/",search:"",hash:"",state:null,key:u()},"string"==typeof t?d(t):t)})),f=i(null==s?c.length-1:s,0,c.length-1),p=a.Pop,v=c[f],m=l(),g=l();function y(t,a){return void 0===a&&(a=null),e({pathname:v.pathname,search:"",hash:""},"string"==typeof t?d(t):t,{state:a,key:u()})}function b(t,e,a){return!g.length||(g.call({action:t,location:e,retry:a}),!1)}function w(t,e){p=t,v=e,m.call({action:p,location:v})}function P(t){var e=i(f+t,0,c.length-1),n=a.Pop,r=c[e];b(n,r,(function(){P(t)}))&&(f=e,w(n,r))}var _={get index(){return f},get action(){return p},get location(){return v},createHref:function(t){return"string"==typeof t?t:h(t)},push:function t(e,n){var r=a.Push,o=y(e,n);b(r,o,(function(){t(e,n)}))&&(f+=1,c.splice(f,c.length,o),w(r,o))},replace:function t(e,n){var r=a.Replace,o=y(e,n);b(r,o,(function(){t(e,n)}))&&(c[f]=o,w(r,o))},go:P,back:function(){P(-1)},forward:function(){P(1)},listen:function(t){return m.push(t)},block:function(t){return g.push(t)}};return _}function i(t,e,a){return Math.min(Math.max(t,e),a)}function c(t){t.preventDefault(),t.returnValue=""}function l(){var t=[];return{get length(){return t.length},push:function(e){return t.push(e),function(){t=t.filter((function(t){return t!==e}))}},call:function(e){t.forEach((function(t){return t&&t(e)}))}}}function u(){return Math.random().toString(36).substr(2,8)}function h(t){var e=t.pathname,a=void 0===e?"/":e,n=t.search,r=void 0===n?"":n,o=t.hash,s=void 0===o?"":o;return r&&"?"!==r&&(a+="?"===r.charAt(0)?r:"?"+r),s&&"#"!==s&&(a+="#"===s.charAt(0)?s:"#"+s),a}function d(t){var e={};if(t){var a=t.indexOf("#");a>=0&&(e.hash=t.substr(a),t=t.substr(0,a));var n=t.indexOf("?");n>=0&&(e.search=t.substr(n),t=t.substr(0,n)),t&&(e.pathname=t)}return e}function f(t,e){if(!t)throw new Error("Invariant failed")}function p(t){return t[t.length-1]}function v(t,e){return"function"==typeof t?t(e):t}function m(t,e){return e.reduce(((e,a)=>(e[a]=t[a],e)),{})}function g(t){return y(t.filter(Boolean).join("/"))}function y(t){return t.replace(/\/{2,}/g,"/")}function b(t){return"/"===t?t:t.replace(/^\/{1,}/,"")}function w(t){return"/"===t?t:t.replace(/\/{1,}$/,"")}function P(t){return w(b(t))}function _(t,e,a){e=e.replace(new RegExp(`^${t}`),"/"),a=a.replace(new RegExp(`^${t}`),"/");let n=L(e);const r=L(a);r.forEach(((t,e)=>{if("/"===t.value)e?e===r.length-1&&n.push(t):n=[t];else if(".."===t.value){var a;n.length>1&&"/"===(null==(a=p(n))?void 0:a.value)&&n.pop(),n.pop()}else{if("."===t.value)return;n.push(t)}}));return y(g([t,...n.map((t=>t.value))]))}function L(t){if(!t)return[];const e=[];if("/"===(t=y(t)).slice(0,1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),!t)return e;const a=t.split("/").filter(Boolean);return e.push(...a.map((t=>t.startsWith("*")?{type:"wildcard",value:t}:"$"===t.charAt(0)?{type:"param",value:t}:{type:"pathname",value:t}))),"/"===t.slice(-1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),e}function M(t,e,a){return g(L(t).map((t=>"*"!==t.value||a?"param"===t.type?e[t.value.substring(1)]??"":t.value:"")))}function x(t,e,a){const n=A(t,e,a);if(!a.to||n)return n??{}}function A(t,e,a){if(!e.startsWith(t))return;const n=L(e="/"!=t?e.substring(t.length):e),r=L(`${a.to??"*"}`),o={};return(()=>{for(let t=0;t<Math.max(n.length,r.length);t++){const e=n[t],s=r[t],i=t===r.length-1,c=t===n.length-1;if(s){if("wildcard"===s.type)return!(null==e||!e.value)&&(o["*"]=g(n.slice(t).map((t=>t.value))),!0);if("pathname"===s.type){if("/"===s.value&&(null==e||!e.value))return!0;if(e)if(a.caseSensitive){if(s.value!==e.value)return!1}else if(s.value.toLowerCase()!==e.value.toLowerCase())return!1}if(!e)return!1;if("param"===s.type){if("/"===(null==e?void 0:e.value))return!1;"$"!==e.value.charAt(0)&&(o[s.value.substring(1)]=e.value)}}if(i&&!c)return!!a.fuzzy}return!0})()?o:void 0}function S(t,e){var a,n,r,o="";for(a in t)if(void 0!==(r=t[a]))if(Array.isArray(r))for(n=0;n<r.length;n++)o&&(o+="&"),o+=encodeURIComponent(a)+"="+encodeURIComponent(r[n]);else o&&(o+="&"),o+=encodeURIComponent(a)+"="+encodeURIComponent(r);return(e||"")+o}function R(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||("0"===e.charAt(0)?e:0*+e==0?+e:e))}function I(t){for(var e,a,n={},r=t.split("&");e=r.shift();)void 0!==n[a=(e=e.split("=")).shift()]?n[a]=[].concat(n[a],R(e.shift())):n[a]=R(e.shift());return n}var E=void 0,O=null,j=0,C=null;function D(){if(C){for(let t=0;t<C.length;t++)C[t].get();C=null}}function k(t){C=[];let e=t();return D(),e}var F=Symbol("store-raw"),T=Symbol("track"),$=Symbol("store-proxy"),N=Symbol("store-node");function U(t){let e=t[$];if(!e&&(Object.defineProperty(t,$,{value:e=new Proxy(t,J)}),!Array.isArray(t))){const a=Object.keys(t),n=Object.getOwnPropertyDescriptors(t);for(let r=0,o=a.length;r<o;r++){const o=a[r];if(n[o].get){const a=n[o].get.bind(e);Object.defineProperty(t,o,{enumerable:n[o].enumerable,get:a})}}}return e}function B(t){let e;return null!=t&&"object"==typeof t&&(t[$]||!(e=Object.getPrototypeOf(t))||e===Object.prototype||Array.isArray(t))}function H(t,e=new Set){let a,n,r,o;if(a=null!=t&&t[F])return a;if(!B(t)||e.has(t))return t;if(Array.isArray(t)){Object.isFrozen(t)?t=t.slice(0):e.add(t);for(let a=0,o=t.length;a<o;a++)r=t[a],(n=H(r,e))!==r&&(t[a]=n)}else{Object.isFrozen(t)?t=Object.assign({},t):e.add(t);const a=Object.keys(t),s=Object.getOwnPropertyDescriptors(t);for(let i=0,c=a.length;i<c;i++)o=a[i],s[o].get||(r=t[o],(n=H(r,e))!==r&&(t[o]=n))}return t}function G(t){let e=t[N];return e||Object.defineProperty(t,N,{value:e={}}),e}function z(t,e,a){return t[e]||(t[e]=V(a))}function K(t){if(E){const e=G(t);(e._||(e._=V())).get()}}function V(t){const e=new class{value;fn;observers=null;sources=null;state;effect;cleanups=null;alwaysUpdate=!1;constructor(t,e){0!=e?(this.fn=t,this.value=void 0,this.state=2,console.error("Memos and effects must be wrapped in a createRoot"),this.effect=2==e,this.effect&&this.update()):(this.fn=void 0,this.value=t,this.state=0,this.effect=!1)}get(){return E&&(!O&&E.sources&&E.sources[j]==this?j++:O?O.push(this):O=[this]),this.fn&&this.updateIfNecessary(),this.value}set(t){const e=!C,a="function"==typeof t?t(this.value):t;if((this.value!==a||this.alwaysUpdate)&&this.observers)for(let t=0;t<this.observers.length;t++)this.observers[t].stale(2);return this.value=a,e&&D(),a}stale(t){if(this.state<t&&(0===this.state&&this.effect&&(C?C.push(this):C=[this]),this.state=t,this.observers))for(let t=0;t<this.observers.length;t++)this.observers[t].stale(1)}update(){const t=this.value,e=E,a=O,n=j;E=this,O=null,j=0;try{if(this.cleanups&&(this.cleanups.forEach((t=>t())),this.cleanups=null),this.value=this.fn(),O){if(this.removeParentObservers(j),this.sources&&j>0){this.sources.length=j+O.length;for(let t=0;t<O.length;t++)this.sources[j+t]=O[t]}else this.sources=O;for(let t=j;t<this.sources.length;t++){const e=this.sources[t];e.observers?e.observers.push(this):e.observers=[this]}}else this.sources&&j<this.sources.length&&(this.removeParentObservers(j),this.sources.length=j)}finally{O=a,E=e,j=n}if((t!==this.value||this.alwaysUpdate)&&this.observers)for(let t=0;t<this.observers.length;t++)this.observers[t].state=2;this.state=0}updateIfNecessary(){if(1===this.state)for(const t of this.sources)if(t.updateIfNecessary(),2===this.state)break;2===this.state&&this.update(),this.state=0}removeParentObservers(t){if(this.sources)for(let e=t;e<this.sources.length;e++){const t=this.sources[e],a=t.observers.findIndex((t=>t===this));t.observers[a]=t.observers[t.observers.length-1],t.observers.pop()}}destroy(){this.cleanups&&(this.cleanups.forEach((t=>t())),this.cleanups=null),this.removeParentObservers(0)}}(t,0);return e.alwaysUpdate=!0,e}var W=!1,J={get(t,e,a){if(e===F)return t;if(e===$)return a;if(e===T)return K(t),a;const n=G(t),r=n.hasOwnProperty(e);let o=r?n[e].get():t[e];if(e===N||"__proto__"===e)return o;if(!r){const a=Object.getOwnPropertyDescriptor(t,e);!E||"function"==typeof o&&!t.hasOwnProperty(e)||a&&a.get||(o=z(n,e,o).get())}return B(o)?U(o):o},has(t,e){return e===F||e===$||e===T||e===N||"__proto__"===e||(this.get(t,e,t),e in t)},set:(t,e,a)=>(W&&q(t,e,H(a)),!0),deleteProperty:(t,e)=>(W&&q(t,e,void 0,!0),!0),ownKeys:function(t){return K(t),Reflect.ownKeys(t)},getOwnPropertyDescriptor:function(t,e){const a=Reflect.getOwnPropertyDescriptor(t,e);return a&&!a.get&&a.configurable&&e!==$&&e!==N?(delete a.value,delete a.writable,a.get=()=>t[$][e],a):a}};function q(t,e,a,n=!1){if(!n&&t[e]===a)return;const r=t[e],o=t.length;n?delete t[e]:t[e]=a;const s=G(t);let i;(i=z(s,e,r))&&i.set((()=>a)),Array.isArray(t)&&t.length!==o&&(i=z(s,"length",o))&&i.set(t.length),(i=s._)&&i.set()}function X(t){const e=U(H(t));return[e,t=>{k((()=>{try{W=!0,t(e)}finally{W=!1}}))}]}function Q(t,e,a,n,r){const{id:o,routeId:s,path:i,fullPath:c}=t;let l={routeInfo:void 0,routeId:o,routeRouteId:s,originalIndex:a,routePath:i,fullPath:c,options:e,router:r,childRoutes:void 0,parentRoute:n,get action(){let t=r.store.actions[o]||(r.setStore((e=>{e.actions[o]={submissions:[],submit:async(e,a)=>{if(!l)return;const n=(null==a?void 0:a.invalidate)??!0,[s,i]=X({submittedAt:Date.now(),status:"pending",submission:e,isMulti:!(null==a||!a.multi)});r.setStore((e=>{null!=a&&a.multi||(e.actions[o].submissions=t.submissions.filter((t=>t.isMulti))),e.actions[o].current=s,e.actions[o].latest=s,e.actions[o].submissions.push(s)}));try{const t=await(null==l.options.action?void 0:l.options.action(e));return i((e=>{e.data=t})),n&&(r.invalidateRoute({to:".",fromCurrent:!0}),await r.reload()),i((t=>{t.status="success"})),t}catch(t){console.error(t),i((e=>{e.error=t,e.status="error"}))}}}})),r.store.actions[o]);return t},get loader(){return r.store.loaders[o]||(r.setStore((t=>{t.loaders[o]={pending:[],fetch:async t=>{if(!l)return;const e={loadedAt:Date.now(),loaderContext:t};r.setStore((t=>{t.loaders[o].current=e,t.loaders[o].latest=e,t.loaders[o].pending.push(e)}));try{return await(null==l.options.loader?void 0:l.options.loader(t))}finally{r.setStore((t=>{t.loaders[o].pending=t.loaders[o].pending.filter((t=>t!==e))}))}}}})),r.store.loaders[o])}};return null==r.options.createRoute||r.options.createRoute({router:r,route:l}),l}const Y="__root__",Z=function(t,e,a,n,r){void 0===t&&(t={}),void 0===a&&(a=!0),a&&(t.path=Y),n===Y&&(n="");let o=a?Y:t.path;o&&"/"!==o&&(o=P(o));const s=o||t.id;let i=g([n,s]);o===Y&&(o="/"),i!==Y&&(i=g(["/",i]));const c=i===Y?"/":w(g([r,o]));return{id:i,routeId:s,path:o,fullPath:c,options:t,children:e,addChildren:e=>Z(t,e,!1,n,r),createRoute:t=>Z(t,void 0,!1,i,c),generate:()=>{f(!1)}}};function tt(t,e,a){const n=new Map;return function t(e,a){if(e===a)return e;if(n.has(a))return n.get(a);const r=Array.isArray(e),o=Array.isArray(a),s=et(e),i=et(a),c=r&&o;if(c||s&&i){const r=c?e.length:Object.keys(e).length,o=c?a:Object.keys(a),s=o.length,i=c?[]:{};let l=0;for(let t=0;t<s;t++){const a=c?t:o[t];i[a]===e[a]&&l++}if(r===s&&l===r)return n.set(a,e),e;n.set(a,i);for(let n=0;n<s;n++){const r=c?n:o[n];"function"==typeof o[n]?i[r]=e[r]:i[r]=t(e[r],a[r]),i[r]===e[r]&&l++}return i}if(o){const e=[];n.set(a,e);for(let n=0;n<a.length;n++)e[n]=t(void 0,a[n]);return e}if(i){const e={};n.set(a,e);const r=Object.keys(a);for(let n=0;n<r.length;n++){const o=r[n];e[o]=t(void 0,a[o])}return e}return a}(t,e)}function et(t){if(!at(t))return!1;const e=t.constructor;if(void 0===e)return!0;const a=e.prototype;return!!at(a)&&!!a.hasOwnProperty("isPrototypeOf")}function at(t){return"[object Object]"===Object.prototype.toString.call(t)}const nt=["component","errorComponent","pendingComponent"];function rt(t,e,a){let n,r,o="",s=()=>{};function i(){l((t=>{var e;t.loaderData=tt(t.loaderData,{...null==(e=c.parentMatch)?void 0:e.store.loaderData,...t.routeLoaderData})}))}const[c,l]=X({routeSearch:{},search:{},status:"idle",routeLoaderData:{},loaderData:{},isFetching:!1,invalid:!1,invalidAt:1/0,get isInvalid(){const t=Date.now();return this.invalid||this.invalidAt<t}}),u={...e,...a,store:c,router:t,childMatches:[],__:{setParentMatch:t=>{k((()=>{l((e=>{e.parentMatch=t})),i()}))},abortController:new AbortController,validate:()=>{var e;const a=(null==(e=c.parentMatch)?void 0:e.store.search)??t.store.currentLocation.search;try{const t=c.routeSearch,e="object"==typeof u.options.validateSearch?u.options.validateSearch.parse:u.options.validateSearch;let n=tt(t,(null==e?void 0:e(a))??{});k((()=>{t!==n&&l((t=>t.invalid=!0)),l((t=>{t.routeSearch=n,t.search=tt(a,{...a,...n})}))})),nt.map((async t=>{const e=u.options[t];"function"!=typeof u.__[t]&&(u.__[t]=e)}))}catch(t){console.error(t);const e=new Error("Invalid search params found",{cause:t});return e.code="INVALID_SEARCH_PARAMS",void l((t=>{t.status="error",t.error=e}))}}},cancel:()=>{var t;null==(t=u.__.abortController)||t.abort()},invalidate:()=>{l((t=>t.invalid=!0))},hasLoaders:()=>!(!e.options.loader&&!nt.some((t=>{var a;return null==(a=e.options[t])?void 0:a.preload}))),load:async e=>{const a=Date.now(),n=null!=e&&e.preload?Math.max(null==e?void 0:e.maxAge,null==e?void 0:e.gcMaxAge):0;if(null!=e&&e.preload&&n>0){if(t.store.currentMatches.find((t=>t.matchId===u.matchId)))return;t.store.matchCache[u.matchId]={gc:a+e.gcMaxAge,match:u}}if("success"===c.status&&c.isInvalid||"error"===c.status||"idle"===c.status){const t=null!=e&&e.preload?null==e?void 0:e.maxAge:void 0;await u.fetch({maxAge:t})}},fetch:async e=>{const a=""+Date.now()+Math.random();o=a;const h=async()=>{if(a!==o)return new Promise((()=>{}))};k((()=>{"idle"===c.status&&l((t=>t.status="loading")),l((t=>t.invalid=!1))})),u.__.loadPromise=new Promise((async a=>{l((t=>t.isFetching=!0)),s=a,n=(async()=>{await Promise.all(nt.map((async e=>{var a;const n=u.options[e];null!=(a=u.__[e])&&a.preload&&(u.__[e]=await t.options.loadComponent(n))})))})(),r=Promise.resolve().then((async()=>{try{if(u.options.loader){const e=await t.loadMatchData(u);await h(),a=e,k((()=>{l((t=>{t.routeLoaderData=tt(t.routeLoaderData,a)})),i()}))}return l((a=>{a.error=void 0,a.status="success",a.updatedAt=Date.now(),a.invalidAt=a.updatedAt+((null==e?void 0:e.maxAge)??u.options.loaderMaxAge??t.options.defaultLoaderMaxAge??0)})),c.routeLoaderData}catch(t){throw await h(),l((e=>{e.error=t,e.status="error",e.updatedAt=Date.now()})),t}var a}));const o=async()=>{await h(),l((t=>t.isFetching=!1)),delete u.__.loadPromise,s()};try{await Promise.all([n,r.catch((()=>{}))]),o()}catch{o()}})),await u.__.loadPromise,await h()}};return u.hasLoaders()||l((t=>t.status="success")),u}const ot=it(JSON.parse),st=ct(JSON.stringify);function it(t){return e=>{"?"===e.substring(0,1)&&(e=e.substring(1));let a=I(e);for(let e in a){const n=a[e];if("string"==typeof n)try{a[e]=t(n)}catch(t){}}return a}}function ct(t){return e=>{(e={...e})&&Object.keys(e).forEach((a=>{const n=e[a];if(void 0===n||void 0===n)delete e[a];else if(n&&"object"==typeof n&&null!==n)try{e[a]=t(n)}catch(t){}}));const a=S(e).toString();return a?`?${a}`:""}}var lt;const ut="undefined"==typeof window||!(null!=(lt=window.document)&&lt.createElement);function ht(){return{status:"idle",latestLocation:null,currentLocation:null,currentMatches:[],actions:{},loaders:{},lastUpdated:Date.now(),matchCache:{},get isFetching(){return"loading"===this.status||this.currentMatches.some((t=>t.store.isFetching))},get isPreloading(){return Object.values(this.matchCache).some((t=>t.match.store.isFetching&&!this.currentMatches.find((e=>e.matchId===t.match.matchId))))}}}t.cleanPath=y,t.createBrowserHistory=o,t.createHashHistory=function(t){void 0===t&&(t={});var o=t.window,s=void 0===o?document.defaultView:o,i=s.history;function f(){var t=d(s.location.hash.substr(1)),e=t.pathname,a=void 0===e?"/":e,n=t.search,r=void 0===n?"":n,o=t.hash,c=void 0===o?"":o,l=i.state||{};return[l.idx,{pathname:a,search:r,hash:c,state:l.usr||null,key:l.key||"default"}]}var p=null;function v(){if(p)P.call(p),p=null;else{var t=a.Pop,e=f(),n=e[0],r=e[1];if(P.length){if(null!=n){var o=y-n;o&&(p={action:t,location:r,retry:function(){S(-1*o)}},S(o))}}else A(t)}}s.addEventListener(r,v),s.addEventListener("hashchange",(function(){h(f()[1])!==h(b)&&v()}));var m=a.Pop,g=f(),y=g[0],b=g[1],w=l(),P=l();function _(t){return function(){var t=document.querySelector("base"),e="";if(t&&t.getAttribute("href")){var a=s.location.href,n=a.indexOf("#");e=-1===n?a:a.slice(0,n)}return e}()+"#"+("string"==typeof t?t:h(t))}function L(t,a){return void 0===a&&(a=null),e({pathname:b.pathname,hash:"",search:""},"string"==typeof t?d(t):t,{state:a,key:u()})}function M(t,e){return[{usr:t.state,key:t.key,idx:e},_(t)]}function x(t,e,a){return!P.length||(P.call({action:t,location:e,retry:a}),!1)}function A(t){m=t;var e=f();y=e[0],b=e[1],w.call({action:m,location:b})}function S(t){i.go(t)}null==y&&(y=0,i.replaceState(e({},i.state,{idx:y}),""));var R={get action(){return m},get location(){return b},createHref:_,push:function t(e,n){var r=a.Push,o=L(e,n);if(x(r,o,(function(){t(e,n)}))){var c=M(o,y+1),l=c[0],u=c[1];try{i.pushState(l,"",u)}catch(t){s.location.assign(u)}A(r)}},replace:function t(e,n){var r=a.Replace,o=L(e,n);if(x(r,o,(function(){t(e,n)}))){var s=M(o,y),c=s[0],l=s[1];i.replaceState(c,"",l),A(r)}},go:S,back:function(){S(-1)},forward:function(){S(1)},listen:function(t){return w.push(t)},block:function(t){var e=P.push(t);return 1===P.length&&s.addEventListener(n,c),function(){e(),P.length||s.removeEventListener(n,c)}}};return R},t.createMemoryHistory=s,t.createRoute=Q,t.createRouteConfig=Z,t.createRouteMatch=rt,t.createRouter=function(t){const e={defaultLoaderGcMaxAge:3e5,defaultLoaderMaxAge:0,defaultPreloadMaxAge:2e3,defaultPreloadDelay:50,context:void 0,...t,stringifySearch:(null==t?void 0:t.stringifySearch)??st,parseSearch:(null==t?void 0:t.parseSearch)??ot},[a,n]=X(ht());let r,i=Date.now(),c=()=>{};function l(){b.load()}function u(t,e){const a=b.options.parseSearch(t.search);return{pathname:t.pathname,searchStr:t.search,search:tt(null==e?void 0:e.search,a),hash:t.hash.split("#").reverse()[0]??"",href:`${t.pathname}${t.search}${t.hash}`,state:t.state,key:t.key}}function h(t){return function(t,e){const a=""+Date.now()+Math.random();let n="replace";e||(n="push");u(b.history.location).href!==t.href||t.key||(n="replace");return b.history[n]({pathname:t.pathname,hash:t.hash,search:t.searchStr},{id:a,...t.state}),r=new Promise((t=>{const e=c;c=()=>{e(),t()}}))}(b.buildNext(t),t.replace)}function d(t){var e,n,r,o;void 0===t&&(t={});const s=t.fromCurrent?a.latestLocation.pathname:t.from??a.latestLocation.pathname;let i=_(b.basepath??"/",s,`${t.to??"."}`);const c=b.matchRoutes(a.latestLocation.pathname,{strictParseParams:!0}),l=b.matchRoutes(i),u={...null==(e=p(c))?void 0:e.params};let h=!0===(t.params??!0)?u:v(t.params,u);h&&l.map((t=>t.options.stringifyParams)).filter(Boolean).forEach((t=>{Object.assign({},h,t(h))})),i=M(i,h??{});const d=null!=(n=t.__preSearchFilters)&&n.length?t.__preSearchFilters.reduce(((t,e)=>e(t)),a.latestLocation.search):a.latestLocation.search,f=!0===t.search?d:t.search?v(t.search,d)??{}:null!=(r=t.__preSearchFilters)&&r.length?d:{},m=null!=(o=t.__postSearchFilters)&&o.length?t.__postSearchFilters.reduce(((t,e)=>e(t)),f):f,g=tt(a.latestLocation.search,m),y=b.options.stringifySearch(g);let w=!0===t.hash?a.latestLocation.hash:v(t.hash,a.latestLocation.hash);return w=w?`#${w}`:"",{pathname:i,search:g,searchStr:y,state:a.latestLocation.state,hash:w,href:`${i}${y}${w}`,key:t.key}}const b={types:void 0,history:(null==t?void 0:t.history)||(ut?s():o()),store:a,setStore:n,options:e,basepath:"",routeTree:void 0,routesById:{},reset:()=>{n((t=>Object.assign(t,ht())))},getRoute:t=>b.routesById[t],dehydrate:()=>({store:{...m(a,["latestLocation","currentLocation","status","lastUpdated"]),currentMatches:a.currentMatches.map((t=>({matchId:t.matchId,store:m(t.store,["status","routeLoaderData","isInvalid","invalidAt"])})))},context:b.options.context}),hydrate:t=>{n((e=>{b.options.context=t.context;const a=b.matchRoutes(t.store.latestLocation.pathname,{strictParseParams:!0});a.forEach(((e,a)=>{const n=t.store.currentMatches[a];f(n&&n.matchId===e.matchId),Object.assign(e,n)})),a.forEach((t=>t.__.validate())),Object.assign(e,{...t.store,currentMatches:a})}))},mount:()=>{if(!ut){a.currentMatches.length||b.load();const t=b.history.listen((t=>{b.load(u(t.location,a.latestLocation))}));return window.addEventListener&&(window.addEventListener("visibilitychange",l,!1),window.addEventListener("focus",l,!1)),()=>{t(),window.removeEventListener&&(window.removeEventListener("visibilitychange",l),window.removeEventListener("focus",l))}}return()=>{}},update:t=>{const e=(null==t?void 0:t.history)!==b.history;a.latestLocation&&!e||(null!=t&&t.history&&(b.history=t.history),n((t=>{t.latestLocation=u(b.history.location),t.currentLocation=t.latestLocation}))),Object.assign(b.options,t);const{basepath:r,routeConfig:o}=b.options;return b.basepath=`/${P(r??"")??""}`,o&&(b.routesById={},b.routeTree=function(t){const e=(t,a)=>t.map(((t,n)=>{const r=Q(t,t.options,n,a,b);if(b.routesById[r.routeId])throw new Error;b.routesById[r.routeId]=r;const o=t.children;return r.childRoutes=null!=o&&o.length?e(o,r):void 0,r}));return e([t])[0]}(o)),b},cancelMatches:()=>{[...a.currentMatches,...a.pendingMatches||[]].forEach((t=>{t.cancel()}))},load:async t=>{let e=Date.now();const o=e;let s;i=o,b.cancelMatches(),k((()=>{t&&n((e=>{e.latestLocation=t})),s=b.matchRoutes(a.latestLocation.pathname,{strictParseParams:!0}),console.log("set loading",s),n((t=>{t.status="loading",t.pendingMatches=s,t.pendingLocation=a.latestLocation}))}));try{await b.loadMatches(s)}catch(t){console.log(t),f(!1)}if(i!==o)return r;const l=a.currentMatches,u=[],h=[];l.forEach((t=>{s.find((e=>e.matchId===t.matchId))?h.push(t):u.push(t)}));const d=s.filter((t=>!l.find((e=>e.matchId===t.matchId))));e=Date.now(),u.forEach((t=>{null==t.__.onExit||t.__.onExit({params:t.params,search:t.store.routeSearch}),"error"!==t.store.status||t.store.isFetching||(t.store.status="idle",t.store.error=void 0);const n=Math.max(t.options.loaderGcMaxAge??b.options.defaultLoaderGcMaxAge??0,t.options.loaderMaxAge??b.options.defaultLoaderMaxAge??0);n>0&&(a.matchCache[t.matchId]={gc:n==1/0?Number.MAX_SAFE_INTEGER:e+n,match:t})})),h.forEach((t=>{null==t.options.onTransition||t.options.onTransition({params:t.params,search:t.store.routeSearch})})),d.forEach((t=>{t.__.onExit=null==t.options.onLoaded?void 0:t.options.onLoaded({params:t.params,search:t.store.search}),delete a.matchCache[t.matchId]})),i===o&&(s.forEach((t=>{t.action&&(t.action.current=void 0,t.action.submissions=[])})),n((t=>{console.log("set",s),Object.assign(t,{status:"idle",currentLocation:a.latestLocation,currentMatches:s,pendingLocation:void 0,pendingMatches:void 0})})),c())},cleanMatchCache:()=>{const t=Date.now();n((e=>{Object.keys(e.matchCache).forEach((a=>{const n=e.matchCache[a];"loading"!==n.match.store.status&&(n.gc>0&&n.gc>t||delete e.matchCache[a])}))}))},loadRoute:async function(t){void 0===t&&(t=a.latestLocation);const e=b.buildNext(t),n=b.matchRoutes(e.pathname,{strictParseParams:!0});return await b.loadMatches(n),n},preloadRoute:async function(t,e){void 0===t&&(t=a.latestLocation);const n=b.buildNext(t),r=b.matchRoutes(n.pathname,{strictParseParams:!0});return await b.loadMatches(r,{preload:!0,maxAge:e.maxAge??b.options.defaultPreloadMaxAge??b.options.defaultLoaderMaxAge??0,gcMaxAge:e.gcMaxAge??b.options.defaultPreloadGcMaxAge??b.options.defaultLoaderGcMaxAge??0}),r},matchRoutes:(t,e)=>{b.cleanMatchCache();const n=[];if(!b.routeTree)return n;const r=[...a.currentMatches,...a.pendingMatches??[]],o=async s=>{var i;const c=p(n);let l=(null==c?void 0:c.params)??{};const u=(null==b.options.filterRoutes?void 0:b.options.filterRoutes(s))??s;let h=[];const d=(a,n)=>(n.some((n=>{var r,o;if(!n.routePath&&null!=(r=n.childRoutes)&&r.length)return d([...h,n],n.childRoutes);const s=!!("/"!==n.routePath||null!=(o=n.childRoutes)&&o.length),i=x(b.basepath,t,{to:n.fullPath,fuzzy:s,caseSensitive:n.options.caseSensitive??b.options.caseSensitive});if(i){let t;try{t=(null==n.options.parseParams?void 0:n.options.parseParams(i))??i}catch(t){if(null!=e&&e.strictParseParams)throw t}l={...l,...t}}return i&&(h=[...a,n]),!!h.length})),!!h.length);if(d([],u),!h.length)return;h.forEach((t=>{var e;const o=M(t.routePath,l),s=M(t.routeId,l,!0),i=r.find((t=>t.matchId===s))||(null==(e=a.matchCache[s])?void 0:e.match)||rt(b,t,{parentMatch:c,matchId:s,params:l,pathname:g([b.basepath,o])});n.push(i)}));const f=p(h);null!=(i=f.childRoutes)&&i.length&&o(f.childRoutes)};return o([b.routeTree]),function(t){t.forEach(((e,a)=>{const n=t[a-1];n?e.__.setParentMatch(n):e.__.setParentMatch(void 0)}))}(n),n},loadMatches:async(t,e)=>{t.forEach((async t=>{t.__.validate()})),await Promise.all(t.map((async t=>{try{await(null==t.options.beforeLoad?void 0:t.options.beforeLoad({router:b,match:t}))}catch(a){throw null!=e&&e.preload||null==t.options.onLoadError||t.options.onLoadError(a),a}})));const a=t.map((async t=>{var a;const n=t.store.search;null!=(a=n.__data)&&a.matchId&&n.__data.matchId!==t.matchId||(t.load(e),"success"!==t.store.status&&t.__.loadPromise&&await t.__.loadPromise)}));await Promise.all(a)},loadMatchData:async t=>{if(ut||!b.options.useServerData)return await(null==t.options.loader?void 0:t.options.loader({params:t.params,search:t.store.routeSearch,signal:t.__.abortController.signal}))||{};{const e=b.buildNext({to:".",search:e=>({...e??{},__data:{matchId:t.matchId}})}),a=await fetch(e.href,{method:"GET"});if(a.ok)return a.json();throw new Error("Failed to fetch match data")}},invalidateRoute:t=>{const e=b.buildNext(t),n=b.matchRoutes(e.pathname).map((t=>t.matchId));[...a.currentMatches,...a.pendingMatches??[]].forEach((t=>{n.includes(t.matchId)&&t.invalidate()}))},reload:()=>h({fromCurrent:!0,replace:!0,search:!0}),resolvePath:(t,e)=>_(b.basepath,t,y(e)),matchRoute:(t,e)=>{t={...t,to:t.to?b.resolvePath(t.from??"",t.to):void 0};const n=b.buildNext(t);return null!=e&&e.pending?!!a.pendingLocation&&!!x(b.basepath,a.pendingLocation.pathname,{...e,to:n.pathname}):x(b.basepath,a.currentLocation.pathname,{...e,to:n.pathname})},navigate:async t=>{let{from:e,to:a=".",search:n,hash:r,replace:o,params:s}=t;const i=String(a),c=String(e);let l;try{new URL(`${i}`),l=!0}catch(t){}return f(!l),h({from:c,to:i,search:n,hash:r,replace:o,params:s})},buildLink:t=>{let{from:e,to:n=".",search:r,params:o,hash:s,target:i,replace:c,activeOptions:l,preload:u,preloadMaxAge:d,preloadGcMaxAge:f,preloadDelay:p,disabled:v}=t;try{return new URL(`${n}`),{type:"external",href:n}}catch(t){}const m={from:e,to:n,search:r,params:o,hash:s,replace:c},g=b.buildNext(m);u=u??b.options.defaultPreload;const y=p??b.options.defaultPreloadDelay??0,w=a.currentLocation.pathname===g.pathname,P=a.currentLocation.pathname.split("/"),_=g.pathname.split("/").every(((t,e)=>t===P[e])),L=a.currentLocation.hash===g.hash,M=null!=l&&l.exact?w:_,x=null==l||!l.includeHash||L;return{type:"internal",next:g,handleFocus:t=>{u&&b.preloadRoute(m,{maxAge:d,gcMaxAge:f}).catch((t=>{console.log(t),console.warn("Error preloading route! ☝️")}))},handleClick:t=>{v||function(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}(t)||t.defaultPrevented||i&&"_self"!==i||0!==t.button||(t.preventDefault(),!w||r||s||b.invalidateRoute(m),h(m))},handleEnter:t=>{const e=t.target||{};if(u){if(e.preloadTimeout)return;e.preloadTimeout=setTimeout((()=>{e.preloadTimeout=null,b.preloadRoute(m,{maxAge:d,gcMaxAge:f}).catch((t=>{console.log(t),console.warn("Error preloading route! ☝️")}))}),y)}},handleLeave:t=>{const e=t.target||{};e.preloadTimeout&&(clearTimeout(e.preloadTimeout),e.preloadTimeout=null)},isActive:M&&x,disabled:v}},buildNext:t=>{const e=d(t),a=b.matchRoutes(e.pathname),n=a.map((t=>t.options.preSearchFilters??[])).flat().filter(Boolean),r=a.map((t=>t.options.postSearchFilters??[])).flat().filter(Boolean);return d({...t,__preSearchFilters:n,__postSearchFilters:r})}};return b.update(t),null==b.options.createRouter||b.options.createRouter(b),b},t.decode=I,t.defaultParseSearch=ot,t.defaultStringifySearch=st,t.encode=S,t.functionalUpdate=v,t.interpolatePath=M,t.invariant=f,t.joinPaths=g,t.last=p,t.matchByPath=A,t.matchPathname=x,t.parsePathname=L,t.parseSearchWith=it,t.pick=m,t.resolvePath=_,t.rootRouteId=Y,t.sharedClone=tt,t.stringifySearchWith=ct,t.trimPath=P,t.trimPathLeft=b,t.trimPathRight=w,t.warning=function(t,e){if(t){"undefined"!=typeof console&&console.warn(e);try{throw new Error(e)}catch{}}return!0},Object.defineProperty(t,"__esModule",{value:!0})}));
11
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RouterCore={})}(this,(function(t){"use strict";function e(t,e){if(!t)throw new Error("Invariant failed")}const r="popstate";function a(t){let e=t.getLocation(),r=()=>{},a=new Set;const o=()=>{e=t.getLocation(),a.forEach((t=>t()))};return{get location(){return e},listen:e=>(0===a.size&&(r=t.listener(o)),a.add(e),()=>{a.delete(e),0===a.size&&r()}),push:(e,r)=>{t.pushState(e,r),o()},replace:(e,r)=>{t.replaceState(e,r),o()},go:e=>{t.go(e),o()},back:()=>{t.back(),o()},forward:()=>{t.forward(),o()}}}function o(t){const e=t?.getHref??(()=>`${window.location.pathname}${window.location.hash}${window.location.search}`),o=t?.createHref??(t=>t);return a({getLocation:()=>n(e(),history.state),listener:t=>(window.addEventListener(r,t),()=>{window.removeEventListener(r,t)}),pushState:(t,e)=>{window.history.pushState({...e,key:i()},"",o(t))},replaceState:(t,e)=>{window.history.replaceState({...e,key:i()},"",o(t))},back:()=>window.history.back(),forward:()=>window.history.forward(),go:t=>window.history.go(t)})}function s(t={initialEntries:["/"]}){const e=t.initialEntries;let o=t.initialIndex??e.length-1,s={};return a({getLocation:()=>n(e[o],s),listener:t=>(window.addEventListener(r,t),()=>{window.removeEventListener(r,t)}),pushState:(t,r)=>{s={...r,key:i()},e.push(t),o++},replaceState:(t,r)=>{s={...r,key:i()},e[o]=t},back:()=>{o--},forward:()=>{o=Math.min(o+1,e.length-1)},go:t=>window.history.go(t)})}function n(t,e){let r=t.indexOf("#"),a=t.indexOf("?");const o=Math.min(r,a);return{href:t,pathname:o>-1?t.substring(0,o):t,hash:r>-1?t.substring(r,a):"",search:a>-1?t.substring(a):"",state:e}}function i(){return(Math.random()+1).toString(36).substring(7)}function c(t){return t[t.length-1]}function h(t,e){return function(t){return"function"==typeof t}(t)?t(e):t}function u(t,e){return e.reduce(((e,r)=>(e[r]=t[r],e)),{})}function l(t){return d(t.filter(Boolean).join("/"))}function d(t){return t.replace(/\/{2,}/g,"/")}function f(t){return"/"===t?t:t.replace(/^\/{1,}/,"")}function p(t){return"/"===t?t:t.replace(/\/{1,}$/,"")}function m(t){return p(f(t))}function g(t,e,r){e=e.replace(new RegExp(`^${t}`),"/"),r=r.replace(new RegExp(`^${t}`),"/");let a=v(e);const o=v(r);o.forEach(((t,e)=>{if("/"===t.value)e?e===o.length-1&&a.push(t):a=[t];else if(".."===t.value)a.length>1&&"/"===c(a)?.value&&a.pop(),a.pop();else{if("."===t.value)return;a.push(t)}}));const s=l([t,...a.map((t=>t.value))]);return d(s)}function v(t){if(!t)return[];const e=[];if("/"===(t=d(t)).slice(0,1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),!t)return e;const r=t.split("/").filter(Boolean);return e.push(...r.map((t=>t.startsWith("*")?{type:"wildcard",value:t}:"$"===t.charAt(0)?{type:"param",value:t}:{type:"pathname",value:t}))),"/"===t.slice(-1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),e}function y(t,e,r){return l(v(t).map((t=>"*"!==t.value||r?"param"===t.type?e[t.value.substring(1)]??"":t.value:"")))}function b(t,e,r){const a=w(t,e,r);if(!r.to||a)return a??{}}function w(t,e,r){if(!e.startsWith(t))return;const a=v(e="/"!=t?e.substring(t.length):e),o=v(`${r.to??"*"}`),s={};let n=(()=>{for(let t=0;t<Math.max(a.length,o.length);t++){const e=a[t],n=o[t],i=t===o.length-1,c=t===a.length-1;if(n){if("wildcard"===n.type)return!!e?.value&&(s["*"]=l(a.slice(t).map((t=>t.value))),!0);if("pathname"===n.type){if("/"===n.value&&!e?.value)return!0;if(e)if(r.caseSensitive){if(n.value!==e.value)return!1}else if(n.value.toLowerCase()!==e.value.toLowerCase())return!1}if(!e)return!1;if("param"===n.type){if("/"===e?.value)return!1;"$"!==e.value.charAt(0)&&(s[n.value.substring(1)]=e.value)}}if(i&&!c)return!!r.fuzzy}return!0})();return n?s:void 0}function S(t,e){var r,a,o,s="";for(r in t)if(void 0!==(o=t[r]))if(Array.isArray(o))for(a=0;a<o.length;a++)s&&(s+="&"),s+=encodeURIComponent(r)+"="+encodeURIComponent(o[a]);else s&&(s+="&"),s+=encodeURIComponent(r)+"="+encodeURIComponent(o);return(e||"")+s}function P(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||("0"===e.charAt(0)?e:0*+e==0?+e:e))}function L(t){for(var e,r,a={},o=t.split("&");e=o.shift();)void 0!==a[r=(e=e.split("=")).shift()]?a[r]=[].concat(a[r],P(e.shift())):a[r]=P(e.shift());return a}class A{constructor(t,e,r,a,o){Object.assign(this,{...t,originalIndex:r,options:e,getRouter:()=>o,childRoutes:void 0,getParentRoute:()=>a}),o.options.createRoute?.({router:o,route:this})}}const _="__root__",M=(t={},r=[],a=!0,o,s)=>{a&&(t.path=_),o===_&&(o="");let n=a?_:t.path;n&&"/"!==n&&(n=m(n));const i=n||t.id;let c=l([o,i]);n===_&&(n="/"),c!==_&&(c=l(["/",c]));const h=c===_?"/":p(l([s,n]));return{id:c,routeId:i,path:n,fullPath:h,options:t,children:r,addChildren:e=>M(t,e,!1,o,s),createRoute:t=>M(t,void 0,!1,c,h),generate:()=>{e(!1)}}};function x(t){for(var e=arguments.length,r=Array(e>1?e-1:0),a=1;a<e;a++)r[a-1]=arguments[a];throw Error("[Immer] minified error nr: "+t+(r.length?" "+r.map((function(t){return"'"+t+"'"})).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function E(t){return!!t&&!!t[ft]}function O(t){var e;return!!t&&(function(t){if(!t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);if(null===e)return!0;var r=Object.hasOwnProperty.call(e,"constructor")&&e.constructor;return r===Object||"function"==typeof r&&Function.toString.call(r)===pt}(t)||Array.isArray(t)||!!t[dt]||!!(null===(e=t.constructor)||void 0===e?void 0:e[dt])||F(t)||C(t))}function D(t,e,r){void 0===r&&(r=!1),0===R(t)?(r?Object.keys:mt)(t).forEach((function(a){r&&"symbol"==typeof a||e(a,t[a],t)})):t.forEach((function(r,a){return e(a,r,t)}))}function R(t){var e=t[ft];return e?e.i>3?e.i-4:e.i:Array.isArray(t)?1:F(t)?2:C(t)?3:0}function j(t,e){return 2===R(t)?t.has(e):Object.prototype.hasOwnProperty.call(t,e)}function I(t,e,r){var a=R(t);2===a?t.set(e,r):3===a?(t.delete(e),t.add(r)):t[e]=r}function F(t){return ct&&t instanceof Map}function C(t){return ht&&t instanceof Set}function k(t){return t.o||t.t}function $(t){if(Array.isArray(t))return Array.prototype.slice.call(t);var e=gt(t);delete e[ft];for(var r=mt(e),a=0;a<r.length;a++){var o=r[a],s=e[o];!1===s.writable&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(e[o]={configurable:!0,writable:!0,enumerable:s.enumerable,value:t[o]})}return Object.create(Object.getPrototypeOf(t),e)}function T(t,e){return void 0===e&&(e=!1),z(t)||E(t)||!O(t)||(R(t)>1&&(t.set=t.add=t.clear=t.delete=N),Object.freeze(t),e&&D(t,(function(t,e){return T(e,!0)}),!0)),t}function N(){x(2)}function z(t){return null==t||"object"!=typeof t||Object.isFrozen(t)}function U(t){var e=vt[t];return e||x(18,t),e}function B(){return nt}function H(t,e){e&&(U("Patches"),t.u=[],t.s=[],t.v=e)}function K(t){G(t),t.p.forEach(J),t.p=null}function G(t){t===nt&&(nt=t.l)}function W(t){return nt={p:[],l:nt,h:t,m:!0,_:0}}function J(t){var e=t[ft];0===e.i||1===e.i?e.j():e.O=!0}function X(t,e){e._=e.p.length;var r=e.p[0],a=void 0!==t&&t!==r;return e.h.g||U("ES5").S(e,t,a),a?(r[ft].P&&(K(e),x(4)),O(t)&&(t=q(e,t),e.l||Q(e,t)),e.u&&U("Patches").M(r[ft].t,t,e.u,e.s)):t=q(e,r,[]),K(e),e.u&&e.v(e.u,e.s),t!==lt?t:void 0}function q(t,e,r){if(z(e))return e;var a=e[ft];if(!a)return D(e,(function(o,s){return V(t,a,e,o,s,r)}),!0),e;if(a.A!==t)return e;if(!a.P)return Q(t,a.t,!0),a.t;if(!a.I){a.I=!0,a.A._--;var o=4===a.i||5===a.i?a.o=$(a.k):a.o;D(3===a.i?new Set(o):o,(function(e,s){return V(t,a,o,e,s,r)})),Q(t,o,!1),r&&t.u&&U("Patches").R(a,r,t.u,t.s)}return a.o}function V(t,e,r,a,o,s){if(E(o)){var n=q(t,o,s&&e&&3!==e.i&&!j(e.D,a)?s.concat(a):void 0);if(I(r,a,n),!E(n))return;t.m=!1}if(O(o)&&!z(o)){if(!t.h.F&&t._<1)return;q(t,o),e&&e.A.l||Q(t,o)}}function Q(t,e,r){void 0===r&&(r=!1),t.h.F&&t.m&&T(e,r)}function Y(t,e){var r=t[ft];return(r?k(r):t)[e]}function Z(t,e){if(e in t)for(var r=Object.getPrototypeOf(t);r;){var a=Object.getOwnPropertyDescriptor(r,e);if(a)return a;r=Object.getPrototypeOf(r)}}function tt(t){t.P||(t.P=!0,t.l&&tt(t.l))}function et(t){t.o||(t.o=$(t.t))}function rt(t,e,r){var a=F(e)?U("MapSet").N(e,r):C(e)?U("MapSet").T(e,r):t.g?function(t,e){var r=Array.isArray(t),a={i:r?1:0,A:e?e.A:B(),P:!1,I:!1,D:{},l:e,t:t,k:null,o:null,j:null,C:!1},o=a,s=yt;r&&(o=[a],s=bt);var n=Proxy.revocable(o,s),i=n.revoke,c=n.proxy;return a.k=c,a.j=i,c}(e,r):U("ES5").J(e,r);return(r?r.A:B()).p.push(a),a}function at(t){return E(t)||x(22,t),function t(e){if(!O(e))return e;var r,a=e[ft],o=R(e);if(a){if(!a.P&&(a.i<4||!U("ES5").K(a)))return a.t;a.I=!0,r=ot(e,o),a.I=!1}else r=ot(e,o);return D(r,(function(e,o){a&&function(t,e){return 2===R(t)?t.get(e):t[e]}(a.t,e)===o||I(r,e,t(o))})),3===o?new Set(r):r}(t)}function ot(t,e){switch(e){case 2:return new Map(t);case 3:return Array.from(t)}return $(t)}var st,nt,it="undefined"!=typeof Symbol&&"symbol"==typeof Symbol("x"),ct="undefined"!=typeof Map,ht="undefined"!=typeof Set,ut="undefined"!=typeof Proxy&&void 0!==Proxy.revocable&&"undefined"!=typeof Reflect,lt=it?Symbol.for("immer-nothing"):((st={})["immer-nothing"]=!0,st),dt=it?Symbol.for("immer-draftable"):"__$immer_draftable",ft=it?Symbol.for("immer-state"):"__$immer_state",pt=""+Object.prototype.constructor,mt="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Object.getOwnPropertyNames,gt=Object.getOwnPropertyDescriptors||function(t){var e={};return mt(t).forEach((function(r){e[r]=Object.getOwnPropertyDescriptor(t,r)})),e},vt={},yt={get:function(t,e){if(e===ft)return t;var r=k(t);if(!j(r,e))return function(t,e,r){var a,o=Z(e,r);return o?"value"in o?o.value:null===(a=o.get)||void 0===a?void 0:a.call(t.k):void 0}(t,r,e);var a=r[e];return t.I||!O(a)?a:a===Y(t.t,e)?(et(t),t.o[e]=rt(t.A.h,a,t)):a},has:function(t,e){return e in k(t)},ownKeys:function(t){return Reflect.ownKeys(k(t))},set:function(t,e,r){var a=Z(k(t),e);if(null==a?void 0:a.set)return a.set.call(t.k,r),!0;if(!t.P){var o=Y(k(t),e),s=null==o?void 0:o[ft];if(s&&s.t===r)return t.o[e]=r,t.D[e]=!1,!0;if(function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}(r,o)&&(void 0!==r||j(t.t,e)))return!0;et(t),tt(t)}return t.o[e]===r&&"number"!=typeof r&&(void 0!==r||e in t.o)||(t.o[e]=r,t.D[e]=!0,!0)},deleteProperty:function(t,e){return void 0!==Y(t.t,e)||e in t.t?(t.D[e]=!1,et(t),tt(t)):delete t.D[e],t.o&&delete t.o[e],!0},getOwnPropertyDescriptor:function(t,e){var r=k(t),a=Reflect.getOwnPropertyDescriptor(r,e);return a?{writable:!0,configurable:1!==t.i||"length"!==e,enumerable:a.enumerable,value:r[e]}:a},defineProperty:function(){x(11)},getPrototypeOf:function(t){return Object.getPrototypeOf(t.t)},setPrototypeOf:function(){x(12)}},bt={};D(yt,(function(t,e){bt[t]=function(){return arguments[0]=arguments[0][0],e.apply(this,arguments)}})),bt.deleteProperty=function(t,e){return bt.set.call(this,t,e,void 0)},bt.set=function(t,e,r){return yt.set.call(this,t[0],e,r,t[0])};var wt=function(){function t(t){var e=this;this.g=ut,this.F=!0,this.produce=function(t,r,a){if("function"==typeof t&&"function"!=typeof r){var o=r;r=t;var s=e;return function(t){var e=this;void 0===t&&(t=o);for(var a=arguments.length,n=Array(a>1?a-1:0),i=1;i<a;i++)n[i-1]=arguments[i];return s.produce(t,(function(t){var a;return(a=r).call.apply(a,[e,t].concat(n))}))}}var n;if("function"!=typeof r&&x(6),void 0!==a&&"function"!=typeof a&&x(7),O(t)){var i=W(e),c=rt(e,t,void 0),h=!0;try{n=r(c),h=!1}finally{h?K(i):G(i)}return"undefined"!=typeof Promise&&n instanceof Promise?n.then((function(t){return H(i,a),X(t,i)}),(function(t){throw K(i),t})):(H(i,a),X(n,i))}if(!t||"object"!=typeof t){if(void 0===(n=r(t))&&(n=t),n===lt&&(n=void 0),e.F&&T(n,!0),a){var u=[],l=[];U("Patches").M(t,n,u,l),a(u,l)}return n}x(21,t)},this.produceWithPatches=function(t,r){if("function"==typeof t)return function(r){for(var a=arguments.length,o=Array(a>1?a-1:0),s=1;s<a;s++)o[s-1]=arguments[s];return e.produceWithPatches(r,(function(e){return t.apply(void 0,[e].concat(o))}))};var a,o,s=e.produce(t,r,(function(t,e){a=t,o=e}));return"undefined"!=typeof Promise&&s instanceof Promise?s.then((function(t){return[t,a,o]})):[s,a,o]},"boolean"==typeof(null==t?void 0:t.useProxies)&&this.setUseProxies(t.useProxies),"boolean"==typeof(null==t?void 0:t.autoFreeze)&&this.setAutoFreeze(t.autoFreeze)}var e=t.prototype;return e.createDraft=function(t){O(t)||x(8),E(t)&&(t=at(t));var e=W(this),r=rt(this,t,void 0);return r[ft].C=!0,G(e),r},e.finishDraft=function(t,e){var r=(t&&t[ft]).A;return H(r,e),X(void 0,r)},e.setAutoFreeze=function(t){this.F=t},e.setUseProxies=function(t){t&&!ut&&x(20),this.g=t},e.applyPatches=function(t,e){var r;for(r=e.length-1;r>=0;r--){var a=e[r];if(0===a.path.length&&"replace"===a.op){t=a.value;break}}r>-1&&(e=e.slice(r+1));var o=U("Patches").$;return E(t)?o(t,e):this.produce(t,(function(t){return o(t,e)}))},t}(),St=new wt,Pt=St.produce;St.produceWithPatches.bind(St);var Lt=St.setAutoFreeze.bind(St);St.setUseProxies.bind(St),St.applyPatches.bind(St),St.createDraft.bind(St),St.finishDraft.bind(St),Lt(!1);let At=[],_t=!1;function Mt(){_t||(At.forEach((t=>t())),At=[])}function xt(t,e){const r=new Set,a={state:t,subscribe:t=>(r.add(t),()=>r.delete(t)),setState:t=>{const o=a.state;a.state=Pt((e=>{t(e)}))(o),e&&console.log(a.state),At.push((()=>r.forEach((t=>t(a.state,o))))),Mt()}};return a}function Et(t){_t=!0,t(),_t=!1,Mt()}function Ot(t,e){if(t===e)return t;const r=e,a=Array.isArray(t)&&Array.isArray(r);if(a||Dt(t)&&Dt(r)){const e=a?t.length:Object.keys(t).length,o=a?r:Object.keys(r),s=o.length,n=a?[]:{};let i=0;for(let e=0;e<s;e++){const s=a?e:o[e];n[s]=Ot(t[s],r[s]),n[s]===t[s]&&i++}return e===s&&i===e?t:n}return r}function Dt(t){if(!Rt(t))return!1;const e=t.constructor;if(void 0===e)return!0;const r=e.prototype;return!!Rt(r)&&!!r.hasOwnProperty("isPrototypeOf")}function Rt(t){return"[object Object]"===Object.prototype.toString.call(t)}const jt=["component","errorComponent","pendingComponent"];class It{abortController=new AbortController;#t="";#e=()=>{};onLoaderDataListeners=new Set;constructor(t,e,r){Object.assign(this,{route:e,router:t,matchId:r.matchId,pathname:r.pathname,params:r.params,store:xt({routeSearch:{},search:{},status:"idle",routeLoaderData:{},loaderData:{},isFetching:!1,invalid:!1,invalidAt:1/0})}),this.__hasLoaders()||this.store.setState((t=>t.status="success"))}#r=t=>{Et((()=>{this.store.setState((e=>{e.routeLoaderData=t})),this.#a()}))};cancel=()=>{this.abortController?.abort()};load=async t=>{const e=Date.now(),r=t?.preload?Math.max(t?.maxAge,t?.gcMaxAge):0;if(t?.preload&&r>0){if(this.router.store.state.currentMatches.find((t=>t.id===this.id)))return;this.router.store.setState((r=>{r.matchCache[this.id]={gc:e+t.gcMaxAge,match:this}}))}if("success"===this.store.state.status&&this.getIsInvalid()||"error"===this.store.state.status||"idle"===this.store.state.status){const e=t?.preload?t?.maxAge:void 0;await this.fetch({maxAge:e})}};fetch=async t=>(this.__loadPromise=new Promise((async e=>{const r=""+Date.now()+Math.random();this.#t=r;const a=()=>r!==this.#t?this.__loadPromise?.then((()=>e())):void 0;let o;Et((()=>{"idle"===this.store.state.status&&this.store.setState((t=>t.status="loading")),this.store.setState((t=>t.invalid=!1))})),this.store.setState((t=>t.isFetching=!0)),this.#e=e;const s=(async()=>{await Promise.all(jt.map((async t=>{const e=this.route.options[t];this[t]?.preload&&(this[t]=await this.router.options.loadComponent(e))})))})(),n=Promise.resolve().then((async()=>{try{if(this.route.options.loader){const t=await this.router.loadMatchData(this);if(o=a())return o;this.#r(t)}return this.store.setState((e=>{e.error=void 0,e.status="success",e.updatedAt=Date.now(),e.invalidAt=e.updatedAt+(t?.maxAge??this.route.options.loaderMaxAge??this.router.options.defaultLoaderMaxAge??0)})),this.store.state.routeLoaderData}catch(t){if(o=a())return o;throw this.store.setState((e=>{e.error=t,e.status="error",e.updatedAt=Date.now()})),t}})),i=async()=>{if(o=a())return o;this.store.setState((t=>t.isFetching=!1)),this.#e(),delete this.__loadPromise};try{await Promise.all([s,n.catch((()=>{}))]),i()}catch{i()}})),this.__loadPromise);invalidate=async()=>{this.store.setState((t=>t.invalid=!0)),this.router.store.state.currentMatches.find((t=>t.id===this.id))&&await this.load()};__hasLoaders=()=>!(!this.route.options.loader&&!jt.some((t=>this.route.options[t]?.preload)));getIsInvalid=()=>{const t=Date.now();return this.store.state.invalid||this.store.state.invalidAt<t};#a=()=>{this.store.setState((t=>{t.loaderData=Ot(t.loaderData,{...this.parentMatch?.store.state.loaderData,...t.routeLoaderData})})),this.onLoaderDataListeners.forEach((t=>t()))};__setParentMatch=t=>{!this.parentMatch&&t&&(this.parentMatch=t,this.parentMatch.__onLoaderData((()=>{this.#a()})))};__onLoaderData=t=>{this.onLoaderDataListeners.add(t)};__validate=()=>{const t=this.parentMatch?.store.state.search??this.router.store.state.latestLocation.search;try{const e=this.store.state.routeSearch;let r=("object"==typeof this.route.options.validateSearch?this.route.options.validateSearch.parse:this.route.options.validateSearch)?.(t)??{};Et((()=>{e!==r&&this.store.setState((t=>t.invalid=!0)),this.store.setState((e=>{e.routeSearch=r,e.search={...t,...r}}))})),jt.map((async t=>{const e=this.route.options[t];"function"!=typeof this[t]&&(this[t]=e)}))}catch(t){console.error(t);const e=new Error("Invalid search params found",{cause:t});return e.code="INVALID_SEARCH_PARAMS",void this.store.setState((t=>{t.status="error",t.error=e}))}}}const Ft=kt(JSON.parse),Ct=$t(JSON.stringify);function kt(t){return e=>{"?"===e.substring(0,1)&&(e=e.substring(1));let r=L(e);for(let e in r){const a=r[e];if("string"==typeof a)try{r[e]=t(a)}catch(t){}}return r}}function $t(t){return e=>{(e={...e})&&Object.keys(e).forEach((r=>{const a=e[r];if(void 0===a||void 0===a)delete e[r];else if(a&&"object"==typeof a&&null!==a)try{e[r]=t(a)}catch(t){}}));const r=S(e).toString();return r?`?${r}`:""}}const Tt=async({router:t,routeMatch:e})=>{const r=t.buildNext({to:".",search:t=>({...t??{},__data:{matchId:e.id}})}),a=await fetch(r.href,{method:"GET",signal:e.abortController.signal});if(a.ok)return a.json();throw new Error("Failed to fetch match data")};const Nt="undefined"==typeof window||!window.document.createElement;function zt(){return{status:"idle",latestLocation:null,currentLocation:null,currentMatches:[],loaders:{},lastUpdated:Date.now(),matchCache:{},get isFetching(){return"loading"===this.status||this.currentMatches.some((t=>t.store.state.isFetching))},get isPreloading(){return Object.values(this.matchCache).some((t=>t.match.store.state.isFetching&&!this.currentMatches.find((e=>e.id===t.match.id))))}}}t.Route=A,t.RouteMatch=It,t.Router=class{startedLoadingAt=Date.now();resolveNavigation=()=>{};constructor(t){this.options={defaultLoaderGcMaxAge:3e5,defaultLoaderMaxAge:0,defaultPreloadMaxAge:2e3,defaultPreloadDelay:50,context:void 0,...t,stringifySearch:t?.stringifySearch??Ct,parseSearch:t?.parseSearch??Ft,fetchServerDataFn:t?.fetchServerDataFn??Tt},this.history=this.options?.history??Nt?s():o(),this.store=xt(zt()),this.basepath="",this.update(t),this.options.createRouter?.(this)}reset=()=>{this.store.setState((t=>Object.assign(t,zt())))};mount=()=>{if(!Nt){this.store.state.currentMatches.length||this.load();const t=this.history.listen((()=>{this.load(this.#o(this.store.state.latestLocation))})),e="visibilitychange",r="focus";return window.addEventListener&&(window.addEventListener(e,this.#s,!1),window.addEventListener(r,this.#s,!1)),()=>{t(),window.removeEventListener&&(window.removeEventListener(e,this.#s),window.removeEventListener(r,this.#s))}}return()=>{}};update=t=>{this.store.state.latestLocation||this.store.setState((t=>{t.latestLocation=this.#o(),t.currentLocation=t.latestLocation})),Object.assign(this.options,t);const{basepath:e,routeConfig:r}=this.options;return this.basepath=`/${m(e??"")??""}`,r&&(this.routesById={},this.routeTree=this.#n(r)),this};buildNext=t=>{const e=this.#i(t),r=this.matchRoutes(e.pathname),a=r.map((t=>t.route.options.preSearchFilters??[])).flat().filter(Boolean),o=r.map((t=>t.route.options.postSearchFilters??[])).flat().filter(Boolean);return this.#i({...t,__preSearchFilters:a,__postSearchFilters:o})};cancelMatches=()=>{[...this.store.state.currentMatches,...this.store.state.pendingMatches||[]].forEach((t=>{t.cancel()}))};load=async t=>{let r=Date.now();const a=r;let o;this.startedLoadingAt=a,this.cancelMatches(),Et((()=>{t&&this.store.setState((e=>{e.latestLocation=t})),o=this.matchRoutes(this.store.state.latestLocation.pathname,{strictParseParams:!0}),this.store.setState((t=>{t.status="loading",t.pendingMatches=o,t.pendingLocation=this.store.state.latestLocation}))}));try{await this.loadMatches(o)}catch(t){console.warn(t),e(!1)}if(this.startedLoadingAt!==a)return this.navigationPromise;const s=this.store.state.currentMatches,n=[],i=[];s.forEach((t=>{o.find((e=>e.id===t.id))?i.push(t):n.push(t)}));const c=o.filter((t=>!s.find((e=>e.id===t.id))));r=Date.now(),n.forEach((t=>{t.__onExit?.({params:t.params,search:t.store.state.routeSearch}),"error"!==t.store.state.status||t.store.state.isFetching||t.store.setState((t=>{t.status="idle",t.error=void 0}));const e=Math.max(t.route.options.loaderGcMaxAge??this.options.defaultLoaderGcMaxAge??0,t.route.options.loaderMaxAge??this.options.defaultLoaderMaxAge??0);e>0&&this.store.setState((a=>{a.matchCache[t.id]={gc:e==1/0?Number.MAX_SAFE_INTEGER:r+e,match:t}}))})),i.forEach((t=>{t.route.options.onTransition?.({params:t.params,search:t.store.state.routeSearch})})),c.forEach((t=>{t.__onExit=t.route.options.onLoaded?.({params:t.params,search:t.store.state.search}),delete this.store.state.matchCache[t.id]})),this.store.setState((t=>{Object.assign(t,{status:"idle",currentLocation:this.store.state.latestLocation,currentMatches:o,pendingLocation:void 0,pendingMatches:void 0})})),this.options.onRouteChange?.(),this.resolveNavigation()};cleanMatchCache=()=>{const t=Date.now();this.store.setState((e=>{Object.keys(e.matchCache).forEach((r=>{const a=e.matchCache[r];"loading"!==a.match.store.state.status&&(a.gc>0&&a.gc>t||delete e.matchCache[r])}))}))};getRoute=t=>{const r=this.routesById[t];return e(r),r};loadRoute=async(t=this.store.state.latestLocation)=>{const e=this.buildNext(t),r=this.matchRoutes(e.pathname,{strictParseParams:!0});return await this.loadMatches(r),r};preloadRoute=async(t=this.store.state.latestLocation,e)=>{const r=this.buildNext(t),a=this.matchRoutes(r.pathname,{strictParseParams:!0});return await this.loadMatches(a,{preload:!0,maxAge:e.maxAge??this.options.defaultPreloadMaxAge??this.options.defaultLoaderMaxAge??0,gcMaxAge:e.gcMaxAge??this.options.defaultPreloadGcMaxAge??this.options.defaultLoaderGcMaxAge??0}),a};matchRoutes=(t,e)=>{const r=[];if(!this.routeTree)return r;const a=[...this.store.state.currentMatches,...this.store.state.pendingMatches??[]],o=async s=>{let n=c(r)?.params??{};const i=this.options.filterRoutes?.(s)??s;let h=[];const u=(r,a)=>(a.some((a=>{if(!a.path&&a.childRoutes?.length)return u([...h,a],a.childRoutes);const o=!("/"===a.path&&!a.childRoutes?.length),s=b(this.basepath,t,{to:a.fullPath,fuzzy:o,caseSensitive:a.options.caseSensitive??this.options.caseSensitive});if(s){let t;try{t=a.options.parseParams?.(s)??s}catch(t){if(e?.strictParseParams)throw t}n={...n,...t}}return s&&(h=[...r,a]),!!h.length})),!!h.length);if(u([],i),!h.length)return;h.forEach((t=>{const e=y(t.path,n),o=y(t.id,n,!0),s=a.find((t=>t.id===o))||this.store.state.matchCache[o]?.match||new It(this,t,{matchId:o,params:n,pathname:l([this.basepath,e])});r.push(s)}));const d=c(h);d.childRoutes?.length&&o(d.childRoutes)};return o([this.routeTree]),function(t){t.forEach(((e,r)=>{const a=t[r-1];a&&e.__setParentMatch(a)}))}(r),r};loadMatches=async(t,e)=>{this.cleanMatchCache(),t.forEach((async t=>{t.__validate()})),await Promise.all(t.map((async t=>{try{await(t.route.options.beforeLoad?.({router:this,match:t}))}catch(r){throw e?.preload||t.route.options.onLoadError?.(r),r}})));const r=t.map((async(r,a)=>{const o=t[1],s=r.store.state.search;s.__data?.matchId&&s.__data.matchId!==r.id||(r.load(e),"success"!==r.store.state.status&&r.__loadPromise&&await r.__loadPromise,o&&await o.__loadPromise)}));await Promise.all(r)};loadMatchData=async t=>Nt||!this.options.useServerData?await(t.route.options.loader?.({params:t.params,search:t.store.state.routeSearch,signal:t.abortController.signal}))||{}:this.options.fetchServerDataFn({router:this,routeMatch:t});invalidateRoute=async t=>{const e=this.buildNext(t),r=this.matchRoutes(e.pathname).map((t=>t.id));await Promise.allSettled([...this.store.state.currentMatches,...this.store.state.pendingMatches??[]].map((async t=>{if(r.includes(t.id))return t.invalidate()})))};reload=()=>{this.navigate({fromCurrent:!0,replace:!0,search:!0})};resolvePath=(t,e)=>g(this.basepath,t,d(e));navigate=async({from:t,to:r=".",search:a,hash:o,replace:s,params:n})=>{const i=String(r),c=String(t);let h;try{new URL(`${i}`),h=!0}catch(t){}return e(!h),this.#c({from:c,to:i,search:a,hash:o,replace:s,params:n})};matchRoute=(t,e)=>{t={...t,to:t.to?this.resolvePath(t.from??"",t.to):void 0};const r=this.buildNext(t);return e?.pending?!!this.store.state.pendingLocation&&b(this.basepath,this.store.state.pendingLocation.pathname,{...e,to:r.pathname}):b(this.basepath,this.store.state.currentLocation.pathname,{...e,to:r.pathname})};buildLink=({from:t,to:e=".",search:r,params:a,hash:o,target:s,replace:n,activeOptions:i,preload:c,preloadMaxAge:h,preloadGcMaxAge:u,preloadDelay:l,disabled:d})=>{try{return new URL(`${e}`),{type:"external",href:e}}catch(t){}const f={from:t,to:e,search:r,params:a,hash:o,replace:n},p=this.buildNext(f);c=c??this.options.defaultPreload;const m=l??this.options.defaultPreloadDelay??0,g=this.store.state.currentLocation.pathname===p.pathname,v=this.store.state.currentLocation.pathname.split("/"),y=p.pathname.split("/").every(((t,e)=>t===v[e])),b=this.store.state.currentLocation.hash===p.hash;return{type:"internal",next:p,handleFocus:t=>{c&&this.preloadRoute(f,{maxAge:h,gcMaxAge:u}).catch((t=>{console.warn(t),console.warn("Error preloading route! ☝️")}))},handleClick:t=>{d||function(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}(t)||t.defaultPrevented||s&&"_self"!==s||0!==t.button||(t.preventDefault(),!g||r||o||this.invalidateRoute(f),this.#c(f))},handleEnter:t=>{const e=t.target||{};if(c){if(e.preloadTimeout)return;e.preloadTimeout=setTimeout((()=>{e.preloadTimeout=null,this.preloadRoute(f,{maxAge:h,gcMaxAge:u}).catch((t=>{console.warn(t),console.warn("Error preloading route! ☝️")}))}),m)}},handleLeave:t=>{const e=t.target||{};e.preloadTimeout&&(clearTimeout(e.preloadTimeout),e.preloadTimeout=null)},isActive:(i?.exact?g:y)&&(!i?.includeHash||b),disabled:d}};dehydrate=()=>({state:{...u(this.store.state,["latestLocation","currentLocation","status","lastUpdated"]),currentMatches:this.store.state.currentMatches.map((t=>({matchId:t.id,state:{...u(t.store.state,["status","routeLoaderData","invalidAt","invalid"])}})))},context:this.options.context});hydrate=t=>{this.store.setState((r=>{this.options.context=t.context;const a=this.matchRoutes(t.state.latestLocation.pathname,{strictParseParams:!0});a.forEach(((r,a)=>{const o=t.state.currentMatches[a];e(o&&o.matchId===r.id),Object.assign(r,o)})),a.forEach((t=>t.__validate())),Object.assign(r,{...t.state,currentMatches:a})}))};getLoader=t=>{const e=t.from||"/",r=this.getRoute(e);if(!r)return;let a=this.store.state.loaders[e]||(()=>(this.store.setState((t=>{t.loaders[e]={pending:[],fetch:async t=>{if(!r)return;const a={loadedAt:Date.now(),loaderContext:t};this.store.setState((t=>{t.loaders[e].current=a,t.loaders[e].latest=a,t.loaders[e].pending.push(a)}));try{return await(r.options.loader?.(t))}finally{this.store.setState((t=>{t.loaders[e].pending=t.loaders[e].pending.filter((t=>t!==a))}))}}}})),this.store.state.loaders[e]))();return a};#n=t=>{const e=(t,r)=>t.map(((t,a)=>{const o=t.options,s=new A(t,o,a,r,this);if(this.routesById[s.id])throw new Error;this.routesById[s.id]=s;const n=t.children;return s.childRoutes=n.length?e(n,s):void 0,s}));return e([t])[0]};#o=t=>{let{pathname:e,search:r,hash:a,state:o}=this.history.location;const s=this.options.parseSearch(r);return console.log({pathname:e,searchStr:r,search:Ot(t?.search,s),hash:a.split("#").reverse()[0]??"",href:`${e}${r}${a}`,state:o,key:o?.key||"__init__"}),{pathname:e,searchStr:r,search:Ot(t?.search,s),hash:a.split("#").reverse()[0]??"",href:`${e}${r}${a}`,state:o,key:o?.key||"__init__"}};#s=()=>{this.load()};#i=(t={})=>{const e=t.fromCurrent?this.store.state.latestLocation.pathname:t.from??this.store.state.latestLocation.pathname;let r=g(this.basepath??"/",e,`${t.to??"."}`);const a=this.matchRoutes(this.store.state.latestLocation.pathname,{strictParseParams:!0}),o=this.matchRoutes(r),s={...c(a)?.params};let n=!0===(t.params??!0)?s:h(t.params,s);n&&o.map((t=>t.route.options.stringifyParams)).filter(Boolean).forEach((t=>{Object.assign({},n,t(n))})),r=y(r,n??{});const i=t.__preSearchFilters?.length?t.__preSearchFilters?.reduce(((t,e)=>e(t)),this.store.state.latestLocation.search):this.store.state.latestLocation.search,u=!0===t.search?i:t.search?h(t.search,i)??{}:t.__preSearchFilters?.length?i:{},l=t.__postSearchFilters?.length?t.__postSearchFilters.reduce(((t,e)=>e(t)),u):u,d=Ot(this.store.state.latestLocation.search,l),f=this.options.stringifySearch(d);let p=!0===t.hash?this.store.state.latestLocation.hash:h(t.hash,this.store.state.latestLocation.hash);return p=p?`#${p}`:"",{pathname:r,search:d,searchStr:f,state:this.store.state.latestLocation.state,hash:p,href:`${r}${f}${p}`,key:t.key}};#c=t=>{const e=this.buildNext(t),r=""+Date.now()+Math.random();this.navigateTimeout&&clearTimeout(this.navigateTimeout);let a="replace";t.replace||(a="push");this.store.state.latestLocation.href===e.href&&!e.key&&(a="replace");const o=`${e.pathname}${e.searchStr}${e.hash?`#${e.hash}`:""}`;return this.history["push"===a?"push":"replace"](o,{id:r,...e.state}),this.load(this.#o(this.store.state.latestLocation)),this.navigationPromise=new Promise((t=>{const e=this.resolveNavigation;this.resolveNavigation=()=>{e(),t()}}))}},t.batch=Et,t.cleanPath=d,t.createAction=function(t){const r=xt({submissions:[]},t.debug);return{options:t,store:r,reset:()=>{r.setState((t=>{t.submissions=[]}))},submit:async a=>{const o={submittedAt:Date.now(),status:"pending",payload:a,invalidate:()=>{s((t=>{t.isInvalid=!0}))},getIsLatest:()=>r.state.submissions[r.state.submissions.length-1]?.submittedAt===o.submittedAt},s=t=>{r.setState((r=>{const a=r.submissions.find((t=>t.submittedAt===o.submittedAt));e(a),t(a)}))};r.setState((e=>{e.submissions.push(o),e.submissions.reverse(),e.submissions=e.submissions.slice(0,t.maxSubmissions??10),e.submissions.reverse()}));const n=async()=>{t.onEachSettled?.(o),o.getIsLatest()&&await(t.onLatestSettled?.(o))};try{const e=await(t.action?.(o.payload));return s((t=>{t.response=e})),await(t.onEachSuccess?.(o)),o.getIsLatest()&&await(t.onLatestSuccess?.(o)),await n(),s((t=>{t.status="success"})),e}catch(e){throw console.error(e),s((t=>{t.error=e})),await(t.onEachError?.(o)),o.getIsLatest()&&await(t.onLatestError?.(o)),await n(),s((t=>{t.status="error"})),e}}}},t.createBrowserHistory=o,t.createHashHistory=function(){return o({getHref:()=>window.location.hash.substring(1),createHref:t=>`#${t}`})},t.createMemoryHistory=s,t.createRouteConfig=M,t.createStore=xt,t.decode=L,t.defaultFetchServerDataFn=Tt,t.defaultParseSearch=Ft,t.defaultStringifySearch=Ct,t.encode=S,t.functionalUpdate=h,t.interpolatePath=y,t.invariant=e,t.joinPaths=l,t.last=c,t.matchByPath=w,t.matchPathname=b,t.parsePathname=v,t.parseSearchWith=kt,t.pick=u,t.replaceEqualDeep=Ot,t.resolvePath=g,t.rootRouteId=_,t.stringifySearchWith=$t,t.trackDeep=function(t){const e=new Set;return JSON.stringify(t,((t,r)=>{if("function"!=typeof r){if("object"==typeof r&&null!==r){if(e.has(r))return;e.add(r)}return r}})),t},t.trimPath=m,t.trimPathLeft=f,t.trimPathRight=p,t.warning=function(t,e){if(t){"undefined"!=typeof console&&console.warn(e);try{throw new Error(e)}catch{}}return!0},Object.defineProperty(t,"__esModule",{value:!0})}));
12
12
  //# sourceMappingURL=index.production.js.map