@tanstack/router-core 0.0.1-beta.52 → 0.0.1-beta.53

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.
@@ -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(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 r=t.initialIndex??e.length-1,o={};return a({getLocation:()=>n(e[r],o),listener:()=>()=>{},pushState:(t,a)=>{o={...a,key:i()},e.push(t),r++},replaceState:(t,a)=>{o={...a,key:i()},e[r]=t},back:()=>{r--},forward:()=>{r=Math.min(r+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=y(e);const o=y(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 y(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 v(t,e,r){return l(y(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=y(e="/"!=t?e.substring(t.length):e),o=y(`${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 D(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])||I(t)||C(t))}function E(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:I(t)?2:C(t)?3:0}function j(t,e){return 2===R(t)?t.has(e):Object.prototype.hasOwnProperty.call(t,e)}function F(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 I(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),H(t)||D(t)||!O(t)||(R(t)>1&&(t.set=t.add=t.clear=t.delete=N),Object.freeze(t),e&&E(t,(function(t,e){return T(e,!0)}),!0)),t}function N(){x(2)}function H(t){return null==t||"object"!=typeof t||Object.isFrozen(t)}function z(t){var e=yt[t];return e||x(18,t),e}function U(){return nt}function B(t,e){e&&(z("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||z("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&&z("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(H(e))return e;var a=e[ft];if(!a)return E(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;E(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&&z("Patches").R(a,r,t.u,t.s)}return a.o}function V(t,e,r,a,o,s){if(D(o)){var n=q(t,o,s&&e&&3!==e.i&&!j(e.D,a)?s.concat(a):void 0);if(F(r,a,n),!D(n))return;t.m=!1}if(O(o)&&!H(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=I(e)?z("MapSet").N(e,r):C(e)?z("MapSet").T(e,r):t.g?function(t,e){var r=Array.isArray(t),a={i:r?1:0,A:e?e.A:U(),P:!1,I:!1,D:{},l:e,t:t,k:null,o:null,j:null,C:!1},o=a,s=vt;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):z("ES5").J(e,r);return(r?r.A:U()).p.push(a),a}function at(t){return D(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||!z("ES5").K(a)))return a.t;a.I=!0,r=ot(e,o),a.I=!1}else r=ot(e,o);return E(r,(function(e,o){a&&function(t,e){return 2===R(t)?t.get(e):t[e]}(a.t,e)===o||F(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},yt={},vt={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={};E(vt,(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 vt.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 B(i,a),X(t,i)}),(function(t){throw K(i),t})):(B(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=[];z("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),D(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 B(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=z("Patches").$;return D(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 Dt(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||Et(t)&&Et(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 Et(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 Ft{abortController=new AbortController;#t="";#e=()=>{};onLoaderDataListeners=new Set;constructor(t,e,r){Object.assign(this,{route:e,router:t,id:r.id,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"))}setLoaderData=t=>{Dt((()=>{this.store.setState((e=>{e.routeLoaderData=t})),this.#r()}))};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;Dt((()=>{"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.setLoaderData(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};#r=()=>{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.#r()})))};__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)??{};Dt((()=>{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 It=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 Ht(){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=Ft,t.Router=class{#a;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??It,fetchServerDataFn:t?.fetchServerDataFn??Tt},this.store=xt(Ht()),this.basepath="",this.update(t),this.options.Router?.(this)}reset=()=>{this.store.setState((t=>Object.assign(t,Ht())))};mount=()=>{if(!Nt){this.store.state.currentMatches.length||this.load();const t="visibilitychange",e="focus";return window.addEventListener&&(window.addEventListener(t,this.#o,!1),window.addEventListener(e,this.#o,!1)),()=>{window.removeEventListener&&(window.removeEventListener(t,this.#o),window.removeEventListener(e,this.#o))}}return()=>{}};update=t=>{Object.assign(this.options,t),(!this.history||this.options.history&&this.options.history!==this.history)&&(this.#a&&this.#a(),this.history=this.options.history??(Nt?s():o()),this.store.setState((t=>{t.latestLocation=this.#s(),t.currentLocation=t.latestLocation})),this.#a=this.history.listen((()=>{this.load(this.#s(this.store.state.latestLocation))})));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(),Dt((()=>{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=v(t.path,n),o=v(t.id,n,!0),s=a.find((t=>t.id===o))||this.store.state.matchCache[o]?.match||new Ft(this,t,{id: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=>{if(Nt||!this.options.useServerData)return await(t.route.options.loader?.({params:t.params,search:t.store.state.routeSearch,signal:t.abortController.signal}))||{};return await 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,y=this.store.state.currentLocation.pathname.split("/"),v=p.pathname.split("/").every(((t,e)=>t===y[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:v)&&(!i?.includeHash||b),disabled:d}};dehydrate=()=>({state:{...u(this.store.state,["latestLocation","currentLocation","status","lastUpdated"]),currentMatches:this.store.state.currentMatches.map((t=>({id: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.id===r.id),r.store.setState((t=>{Object.assign(t,o.state)})),r.setLoaderData(o.state.routeLoaderData)})),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]};#s=t=>{let{pathname:e,search:r,hash:a,state:o}=this.history.location;const s=this.options.parseSearch(r);return{pathname:e,searchStr:r,search:Ot(t?.search,s),hash:a.split("#").reverse()[0]??"",href:`${e}${r}${a}`,state:o,key:o?.key||"__init__"}};#o=()=>{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=v(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.navigationPromise=new Promise((t=>{const e=this.resolveNavigation;this.resolveNavigation=()=>{e(),t()}}))}},t.batch=Dt,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=It,t.defaultStringifySearch=Ct,t.encode=S,t.functionalUpdate=h,t.interpolatePath=v,t.invariant=e,t.joinPaths=l,t.last=c,t.matchByPath=w,t.matchPathname=b,t.parsePathname=y,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})}));
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 r=t.initialIndex??e.length-1,o={};return a({getLocation:()=>n(e[r],o),listener:()=>()=>{},pushState:(t,a)=>{o={...a,key:i()},e.push(t),r++},replaceState:(t,a)=>{o={...a,key:i()},e[r]=t},back:()=>{r--},forward:()=>{r=Math.min(r+1,e.length-1)},go:t=>window.history.go(t)})}function n(t,e){let r=t.indexOf("#"),a=t.indexOf("?");return{href:t,pathname:t.substring(0,r>0?a>0?Math.min(r,a):r:a>0?a:t.length),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=y(e);const o=y(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 y(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 v(t,e,r){return l(y(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=y(e="/"!=t?e.substring(t.length):e),o=y(`${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 D(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])||I(t)||C(t))}function E(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:I(t)?2:C(t)?3:0}function j(t,e){return 2===R(t)?t.has(e):Object.prototype.hasOwnProperty.call(t,e)}function F(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 I(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),H(t)||D(t)||!O(t)||(R(t)>1&&(t.set=t.add=t.clear=t.delete=N),Object.freeze(t),e&&E(t,(function(t,e){return T(e,!0)}),!0)),t}function N(){x(2)}function H(t){return null==t||"object"!=typeof t||Object.isFrozen(t)}function z(t){var e=yt[t];return e||x(18,t),e}function U(){return nt}function B(t,e){e&&(z("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||z("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&&z("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(H(e))return e;var a=e[ft];if(!a)return E(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;E(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&&z("Patches").R(a,r,t.u,t.s)}return a.o}function V(t,e,r,a,o,s){if(D(o)){var n=q(t,o,s&&e&&3!==e.i&&!j(e.D,a)?s.concat(a):void 0);if(F(r,a,n),!D(n))return;t.m=!1}if(O(o)&&!H(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=I(e)?z("MapSet").N(e,r):C(e)?z("MapSet").T(e,r):t.g?function(t,e){var r=Array.isArray(t),a={i:r?1:0,A:e?e.A:U(),P:!1,I:!1,D:{},l:e,t:t,k:null,o:null,j:null,C:!1},o=a,s=vt;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):z("ES5").J(e,r);return(r?r.A:U()).p.push(a),a}function at(t){return D(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||!z("ES5").K(a)))return a.t;a.I=!0,r=ot(e,o),a.I=!1}else r=ot(e,o);return E(r,(function(e,o){a&&function(t,e){return 2===R(t)?t.get(e):t[e]}(a.t,e)===o||F(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},yt={},vt={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={};E(vt,(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 vt.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 B(i,a),X(t,i)}),(function(t){throw K(i),t})):(B(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=[];z("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),D(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 B(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=z("Patches").$;return D(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 Dt(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||Et(t)&&Et(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 Et(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 Ft{abortController=new AbortController;#t="";#e=()=>{};onLoaderDataListeners=new Set;constructor(t,e,r){Object.assign(this,{route:e,router:t,id:r.id,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"))}setLoaderData=t=>{Dt((()=>{this.store.setState((e=>{e.routeLoaderData=t})),this.#r()}))};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;Dt((()=>{"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.setLoaderData(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};#r=()=>{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.#r()})))};__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)??{};Dt((()=>{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 It=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 Ht(){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=Ft,t.Router=class{#a;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??It,fetchServerDataFn:t?.fetchServerDataFn??Tt},this.store=xt(Ht()),this.basepath="",this.update(t),this.options.Router?.(this)}reset=()=>{this.store.setState((t=>Object.assign(t,Ht())))};mount=()=>{if(!Nt){this.store.state.currentMatches.length||this.load();const t="visibilitychange",e="focus";return window.addEventListener&&(window.addEventListener(t,this.#o,!1),window.addEventListener(e,this.#o,!1)),()=>{window.removeEventListener&&(window.removeEventListener(t,this.#o),window.removeEventListener(e,this.#o))}}return()=>{}};update=t=>{Object.assign(this.options,t),(!this.history||this.options.history&&this.options.history!==this.history)&&(this.#a&&this.#a(),this.history=this.options.history??(Nt?s():o()),this.store.setState((t=>{t.latestLocation=this.#s(),t.currentLocation=t.latestLocation})),this.#a=this.history.listen((()=>{this.load(this.#s(this.store.state.latestLocation))})));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(),Dt((()=>{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=v(t.path,n),o=v(t.id,n,!0),s=a.find((t=>t.id===o))||this.store.state.matchCache[o]?.match||new Ft(this,t,{id: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=>{if(Nt||!this.options.useServerData)return await(t.route.options.loader?.({params:t.params,search:t.store.state.routeSearch,signal:t.abortController.signal}))||{};return await 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,y=this.store.state.currentLocation.pathname.split("/"),v=p.pathname.split("/").every(((t,e)=>t===y[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:v)&&(!i?.includeHash||b),disabled:d}};dehydrate=()=>({state:{...u(this.store.state,["latestLocation","currentLocation","status","lastUpdated"]),currentMatches:this.store.state.currentMatches.map((t=>({id: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.id===r.id),r.store.setState((t=>{Object.assign(t,o.state)})),r.setLoaderData(o.state.routeLoaderData)})),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]};#s=t=>{let{pathname:e,search:r,hash:a,state:o}=this.history.location;const s=this.options.parseSearch(r);return{pathname:e,searchStr:r,search:Ot(t?.search,s),hash:a.split("#").reverse()[0]??"",href:`${e}${r}${a}`,state:o,key:o?.key||"__init__"}};#o=()=>{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=v(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.navigationPromise=new Promise((t=>{const e=this.resolveNavigation;this.resolveNavigation=()=>{e(),t()}}))}},t.batch=Dt,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=It,t.defaultStringifySearch=Ct,t.encode=S,t.functionalUpdate=h,t.interpolatePath=v,t.invariant=e,t.joinPaths=l,t.last=c,t.matchByPath=w,t.matchPathname=b,t.parsePathname=y,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