@tanstack/router-core 0.0.1-beta.14 → 0.0.1-beta.146

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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/fileRoute.js +29 -0
  3. package/build/cjs/fileRoute.js.map +1 -0
  4. package/build/cjs/history.js +226 -0
  5. package/build/cjs/history.js.map +1 -0
  6. package/build/cjs/index.js +78 -0
  7. package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
  8. package/build/cjs/{packages/router-core/src/path.js → path.js} +45 -56
  9. package/build/cjs/path.js.map +1 -0
  10. package/build/cjs/{packages/router-core/src/qss.js → qss.js} +10 -16
  11. package/build/cjs/qss.js.map +1 -0
  12. package/build/cjs/route.js +103 -0
  13. package/build/cjs/route.js.map +1 -0
  14. package/build/cjs/router.js +1102 -0
  15. package/build/cjs/router.js.map +1 -0
  16. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +11 -13
  17. package/build/cjs/searchParams.js.map +1 -0
  18. package/build/cjs/{packages/router-core/src/utils.js → utils.js} +54 -64
  19. package/build/cjs/utils.js.map +1 -0
  20. package/build/esm/index.js +1403 -2096
  21. package/build/esm/index.js.map +1 -1
  22. package/build/stats-html.html +59 -49
  23. package/build/stats-react.json +203 -234
  24. package/build/types/index.d.ts +603 -422
  25. package/build/umd/index.development.js +1629 -2218
  26. package/build/umd/index.development.js.map +1 -1
  27. package/build/umd/index.production.js +13 -2
  28. package/build/umd/index.production.js.map +1 -1
  29. package/package.json +11 -7
  30. package/src/fileRoute.ts +122 -0
  31. package/src/history.ts +292 -0
  32. package/src/index.ts +3 -10
  33. package/src/link.ts +118 -113
  34. package/src/path.ts +37 -17
  35. package/src/qss.ts +1 -2
  36. package/src/route.ts +891 -218
  37. package/src/routeInfo.ts +121 -197
  38. package/src/router.ts +1481 -1018
  39. package/src/searchParams.ts +1 -1
  40. package/src/utils.ts +80 -49
  41. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  42. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  43. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  44. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  45. package/build/cjs/node_modules/history/index.js +0 -815
  46. package/build/cjs/node_modules/history/index.js.map +0 -1
  47. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  48. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  49. package/build/cjs/packages/router-core/src/index.js +0 -58
  50. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  51. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  52. package/build/cjs/packages/router-core/src/route.js +0 -147
  53. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  54. package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
  55. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  56. package/build/cjs/packages/router-core/src/routeMatch.js +0 -226
  57. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  58. package/build/cjs/packages/router-core/src/router.js +0 -832
  59. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  60. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  61. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
  62. package/src/frameworks.ts +0 -11
  63. package/src/routeConfig.ts +0 -489
  64. package/src/routeMatch.ts +0 -312
@@ -1,5 +1,5 @@
1
1
  /**
2
- * router-core
2
+ * @tanstack/router-core/src/index.ts
3
3
  *
4
4
  * Copyright (c) TanStack
5
5
  *
@@ -8,5 +8,16 @@
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",o="popstate";function r(t){void 0===t&&(t={});var r=t.window,i=void 0===r?document.defaultView:r,s=i.history;function f(){var t=i.location,e=t.pathname,a=t.search,n=t.hash,o=s.state||{};return[o.idx,{pathname:e,search:a,hash:n,state:o.usr||null,key:o.key||"default"}]}var p=null;i.addEventListener(o,(function(){if(p)P.call(p),p=null;else{var t=a.Pop,e=f(),n=e[0],o=e[1];if(P.length){if(null!=n){var r=g-n;r&&(p={action:t,location:o,retry:function(){I(-1*r)}},I(r))}}else A(t)}}));var m=a.Pop,v=f(),g=v[0],y=v[1],_=c(),P=c();function b(t){return"string"==typeof t?t:h(t)}function w(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 x(t,e){return[{usr:t.state,key:t.key,idx:e},b(t)]}function R(t,e,a){return!P.length||(P.call({action:t,location:e,retry:a}),!1)}function A(t){m=t;var e=f();g=e[0],y=e[1],_.call({action:m,location:y})}function I(t){s.go(t)}null==g&&(g=0,s.replaceState(e({},s.state,{idx:g}),""));var S={get action(){return m},get location(){return y},createHref:b,push:function t(e,n){var o=a.Push,r=w(e,n);if(R(o,r,(function(){t(e,n)}))){var l=x(r,g+1),c=l[0],u=l[1];try{s.pushState(c,"",u)}catch(t){i.location.assign(u)}A(o)}},replace:function t(e,n){var o=a.Replace,r=w(e,n);if(R(o,r,(function(){t(e,n)}))){var i=x(r,g),l=i[0],c=i[1];s.replaceState(l,"",c),A(o)}},go:I,back:function(){I(-1)},forward:function(){I(1)},listen:function(t){return _.push(t)},block:function(t){var e=P.push(t);return 1===P.length&&i.addEventListener(n,l),function(){e(),P.length||i.removeEventListener(n,l)}}};return S}function i(t){void 0===t&&(t={});var n=t,o=n.initialEntries,r=void 0===o?["/"]:o,i=n.initialIndex,l=r.map((function(t){return e({pathname:"/",search:"",hash:"",state:null,key:u()},"string"==typeof t?d(t):t)})),f=s(null==i?l.length-1:i,0,l.length-1),p=a.Pop,m=l[f],v=c(),g=c();function y(t,a){return void 0===a&&(a=null),e({pathname:m.pathname,search:"",hash:""},"string"==typeof t?d(t):t,{state:a,key:u()})}function _(t,e,a){return!g.length||(g.call({action:t,location:e,retry:a}),!1)}function P(t,e){p=t,m=e,v.call({action:p,location:m})}function b(t){var e=s(f+t,0,l.length-1),n=a.Pop,o=l[e];_(n,o,(function(){b(t)}))&&(f=e,P(n,o))}var w={get index(){return f},get action(){return p},get location(){return m},createHref:function(t){return"string"==typeof t?t:h(t)},push:function t(e,n){var o=a.Push,r=y(e,n);_(o,r,(function(){t(e,n)}))&&(f+=1,l.splice(f,l.length,r),P(o,r))},replace:function t(e,n){var o=a.Replace,r=y(e,n);_(o,r,(function(){t(e,n)}))&&(l[f]=r,P(o,r))},go:b,back:function(){b(-1)},forward:function(){b(1)},listen:function(t){return v.push(t)},block:function(t){return g.push(t)}};return w}function s(t,e,a){return Math.min(Math.max(t,e),a)}function l(t){t.preventDefault(),t.returnValue=""}function c(){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,o=void 0===n?"":n,r=t.hash,i=void 0===r?"":r;return o&&"?"!==o&&(a+="?"===o.charAt(0)?o:"?"+o),i&&"#"!==i&&(a+="#"===i.charAt(0)?i:"#"+i),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,e){if(t===e)return t;const a=Array.isArray(t)&&Array.isArray(e);if(a||m(t)&&m(e)){const n=a?t.length:Object.keys(t).length,o=a?e:Object.keys(e),r=o.length,i=a?[]:{};let s=0;for(let n=0;n<r;n++){const r=a?n:o[n];i[r]=p(t[r],e[r]),i[r]===t[r]&&s++}return n===r&&s===n?t:i}return e}function m(t){if(!v(t))return!1;const e=t.constructor;if(void 0===e)return!0;const a=e.prototype;return!!v(a)&&!!a.hasOwnProperty("isPrototypeOf")}function v(t){return"[object Object]"===Object.prototype.toString.call(t)}function g(t){return t[t.length-1]}function y(t,e){return"function"==typeof t?t(e):t}function _(t,e){return e.reduce(((e,a)=>(e[a]=t[a],e)),{})}function P(t){return b(t.filter(Boolean).join("/"))}function b(t){return t.replace(/\/{2,}/g,"/")}function w(t){return"/"===t?t:t.replace(/^\/{1,}/,"")}function x(t){return"/"===t?t:t.replace(/\/{1,}$/,"")}function R(t){return x(w(t))}function A(t,e,a){e=e.replace(new RegExp("^"+t),"/"),a=a.replace(new RegExp("^"+t),"/");let n=I(e);const o=I(a);o.forEach(((t,e)=>{if("/"===t.value)e?e===o.length-1&&n.push(t):n=[t];else if(".."===t.value){var a;n.length>1&&"/"===(null==(a=g(n))?void 0:a.value)&&n.pop(),n.pop()}else{if("."===t.value)return;n.push(t)}}));return b(P([t,...n.map((t=>t.value))]))}function I(t){if(!t)return[];const e=[];if("/"===(t=b(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 S(t,e,a){return P(I(t).map((t=>{return"*"!==t.value||a?"param"===t.type?null!=(n=e[t.value.substring(1)])?n:"":t.value:"";var n})))}function L(t,e){const a=E(t,e);if(!e.to||a)return null!=a?a:{}}function E(t,e){var a;const n=I(t),o=I(""+(null!=(a=e.to)?a:"*")),r={};return(()=>{for(let t=0;t<Math.max(n.length,o.length);t++){const a=n[t],i=o[t],s=t===o.length-1,l=t===n.length-1;if(i){if("wildcard"===i.type)return!(null==a||!a.value)&&(r["*"]=P(n.slice(t).map((t=>t.value))),!0);if("pathname"===i.type){if("/"===i.value&&(null==a||!a.value))return!0;if(a)if(e.caseSensitive){if(i.value!==a.value)return!1}else if(i.value.toLowerCase()!==a.value.toLowerCase())return!1}if(!a)return!1;if("param"===i.type){if("/"===(null==a?void 0:a.value))return!1;a.value.startsWith(":")||(r[i.value.substring(1)]=a.value)}}if(s&&!l)return!!e.fuzzy}return!0})()?r:void 0}function M(t,e){var a,n,o,r="";for(a in t)if(void 0!==(o=t[a]))if(Array.isArray(o))for(n=0;n<o.length;n++)r&&(r+="&"),r+=encodeURIComponent(a)+"="+encodeURIComponent(o[n]);else r&&(r+="&"),r+=encodeURIComponent(a)+"="+encodeURIComponent(o);return(e||"")+r}function C(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||("0"===e.charAt(0)?e:0*+e==0?+e:e))}function k(t){for(var e,a,n={},o=t.split("&");e=o.shift();)void 0!==n[a=(e=e.split("=")).shift()]?n[a]=[].concat(n[a],C(e.shift())):n[a]=C(e.shift());return n}function D(){return D=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},D.apply(this,arguments)}function O(t,e,a,n){const{id:o,routeId:r,path:i,fullPath:s}=t,l=n.state.actions[o]||(n.state.actions[o]={submissions:[],submit:async(t,e)=>{var a;if(!u)return;const o=null==(a=null==e?void 0:e.invalidate)||a;null!=e&&e.multi||(l.submissions=l.submissions.filter((t=>t.isMulti)));const r={submittedAt:Date.now(),status:"pending",submission:t,isMulti:!(null==e||!e.multi)};l.current=r,l.latest=r,l.submissions.push(r),n.notify();try{const e=await(null==u.options.action?void 0:u.options.action(t));return r.data=e,o&&(n.invalidateRoute({to:".",fromCurrent:!0}),await n.reload()),r.status="success",e}catch(t){console.error(t),r.error=t,r.status="error"}finally{n.notify()}}},n.state.actions[o]),c=n.state.loaders[o]||(n.state.loaders[o]={pending:[],fetch:async t=>{if(!u)return;const e={loadedAt:Date.now(),loaderContext:t};c.current=e,c.latest=e,c.pending.push(e),n.notify();try{return await(null==u.options.loader?void 0:u.options.loader(t))}finally{c.pending=c.pending.filter((t=>t!==e)),n.notify()}}},n.state.loaders[o]);let u={routeId:o,routeRouteId:r,routePath:i,fullPath:s,options:e,router:n,childRoutes:void 0,parentRoute:a,action:l,loader:c,buildLink:t=>n.buildLink(D({},t,{from:s})),navigate:t=>n.navigate(D({},t,{from:s})),matchRoute:(t,e)=>n.matchRoute(D({},t,{from:s}),e)};return null==n.options.createRoute||n.options.createRoute({router:n,route:u}),u}const F="__root__",j=["component","errorComponent","pendingComponent"];function T(t,e,a){const n=D({},e,a,{router:t,routeSearch:{},search:{},childMatches:[],status:"idle",routeLoaderData:{},loaderData:{},isFetching:!1,isInvalid:!1,invalidAt:1/0,getIsInvalid:()=>{const t=Date.now();return n.isInvalid||n.invalidAt<t},__:{abortController:new AbortController,latestId:"",resolve:()=>{},notify:()=>{n.__.resolve(),n.router.notify()},validate:()=>{var e,a;const o=null!=(e=null==(a=n.parentMatch)?void 0:a.search)?e:t.location.search;try{var r;const t=n.routeSearch,e="object"==typeof n.options.validateSearch?n.options.validateSearch.parse:n.options.validateSearch;let a=p(t,null!=(r=null==e?void 0:e(o))?r:{});t!==a&&(n.isInvalid=!0),n.routeSearch=a,n.search=p(o,D({},o,a)),j.map((async t=>{const e=n.options[t];"function"!=typeof n.__[t]&&(n.__[t]=e)}))}catch(t){console.error(t);const e=new Error("Invalid search params found",{cause:t});return e.code="INVALID_SEARCH_PARAMS",n.status="error",void(n.error=e)}}},cancel:()=>{var t;null==(t=n.__.abortController)||t.abort()},invalidate:()=>{n.isInvalid=!0},hasLoaders:()=>!(!e.options.loader&&!j.some((t=>{var a;return null==(a=e.options[t])?void 0:a.preload}))),load:async e=>{const a=Date.now(),o=null!=e&&e.preload?Math.max(null==e?void 0:e.maxAge,null==e?void 0:e.gcMaxAge):0;if(null!=e&&e.preload&&o>0){if(t.state.matches.find((t=>t.matchId===n.matchId)))return;t.matchCache[n.matchId]={gc:a+e.gcMaxAge,match:n}}if("success"===n.status&&n.getIsInvalid()||"error"===n.status||"idle"===n.status){const t=null!=e&&e.preload?null==e?void 0:e.maxAge:void 0;await n.fetch({maxAge:t})}},fetch:async e=>{const a=""+Date.now()+Math.random();if(n.__.latestId=a,"idle"===n.status&&(n.status="loading"),n.isInvalid=!1,n.__.loadPromise=new Promise((async o=>{n.isFetching=!0,n.__.resolve=o,n.__.componentsPromise=(async()=>{await Promise.all(j.map((async e=>{var a;const o=n.options[e];null!=(a=n.__[e])&&a.preload&&(n.__[e]=await t.options.loadComponent(o))})))})(),n.__.dataPromise=Promise.resolve().then((async()=>{try{var o,r,i;if(n.options.loader){const t=await n.options.loader({params:n.params,search:n.routeSearch,signal:n.__.abortController.signal});if(a!==n.__.latestId)return n.__.loadPromise;n.routeLoaderData=p(n.routeLoaderData,t)}n.error=void 0,n.status="success",n.updatedAt=Date.now(),n.invalidAt=n.updatedAt+(null!=(o=null!=(r=null!=(i=null==e?void 0:e.maxAge)?i:n.options.loaderMaxAge)?r:t.options.defaultLoaderMaxAge)?o:0)}catch(t){if(a!==n.__.latestId)return n.__.loadPromise;n.error=t,n.status="error",n.updatedAt=Date.now()}}));try{if(await Promise.all([n.__.componentsPromise,n.__.dataPromise]),a!==n.__.latestId)return n.__.loadPromise}finally{if(a!==n.__.latestId)return n.__.loadPromise;n.isFetching=!1,n.__.notify()}})),await n.__.loadPromise,a!==n.__.latestId)return n.__.loadPromise;delete n.__.loadPromise}});return n.hasLoaders()||(n.status="success"),n}const N=U(JSON.parse),B=H(JSON.stringify);function U(t){return e=>{"?"===e.substring(0,1)&&(e=e.substring(1));let a=k(e);for(let e in a){const n=a[e];if("string"==typeof n)try{a[e]=t(n)}catch(t){}}return a}}function H(t){return e=>{(e=D({},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=M(e).toString();return a?"?"+a:""}}var G;const z="undefined"==typeof window||!(null!=(G=window.document)&&G.createElement);function K(){return{status:"idle",location:null,matches:[],actions:{},loaders:{},lastUpdated:Date.now(),isFetching:!1,isPreloading:!1}}function V(t){t.forEach(((e,a)=>{const n=t[a-1];n&&(e.loaderData=p(e.loaderData,D({},n.loaderData,e.routeLoaderData)))}))}t.cleanPath=b,t.createBrowserHistory=r,t.createHashHistory=function(t){void 0===t&&(t={});var r=t.window,i=void 0===r?document.defaultView:r,s=i.history;function f(){var t=d(i.location.hash.substr(1)),e=t.pathname,a=void 0===e?"/":e,n=t.search,o=void 0===n?"":n,r=t.hash,l=void 0===r?"":r,c=s.state||{};return[c.idx,{pathname:a,search:o,hash:l,state:c.usr||null,key:c.key||"default"}]}var p=null;function m(){if(p)b.call(p),p=null;else{var t=a.Pop,e=f(),n=e[0],o=e[1];if(b.length){if(null!=n){var r=y-n;r&&(p={action:t,location:o,retry:function(){S(-1*r)}},S(r))}}else I(t)}}i.addEventListener(o,m),i.addEventListener("hashchange",(function(){h(f()[1])!==h(_)&&m()}));var v=a.Pop,g=f(),y=g[0],_=g[1],P=c(),b=c();function w(t){return function(){var t=document.querySelector("base"),e="";if(t&&t.getAttribute("href")){var a=i.location.href,n=a.indexOf("#");e=-1===n?a:a.slice(0,n)}return e}()+"#"+("string"==typeof t?t:h(t))}function x(t,a){return void 0===a&&(a=null),e({pathname:_.pathname,hash:"",search:""},"string"==typeof t?d(t):t,{state:a,key:u()})}function R(t,e){return[{usr:t.state,key:t.key,idx:e},w(t)]}function A(t,e,a){return!b.length||(b.call({action:t,location:e,retry:a}),!1)}function I(t){v=t;var e=f();y=e[0],_=e[1],P.call({action:v,location:_})}function S(t){s.go(t)}null==y&&(y=0,s.replaceState(e({},s.state,{idx:y}),""));var L={get action(){return v},get location(){return _},createHref:w,push:function t(e,n){var o=a.Push,r=x(e,n);if(A(o,r,(function(){t(e,n)}))){var l=R(r,y+1),c=l[0],u=l[1];try{s.pushState(c,"",u)}catch(t){i.location.assign(u)}I(o)}},replace:function t(e,n){var o=a.Replace,r=x(e,n);if(A(o,r,(function(){t(e,n)}))){var i=R(r,y),l=i[0],c=i[1];s.replaceState(l,"",c),I(o)}},go:S,back:function(){S(-1)},forward:function(){S(1)},listen:function(t){return P.push(t)},block:function(t){var e=b.push(t);return 1===b.length&&i.addEventListener(n,l),function(){e(),b.length||i.removeEventListener(n,l)}}};return L},t.createMemoryHistory=i,t.createRoute=O,t.createRouteConfig=function t(e,a,n,o,r){void 0===e&&(e={}),void 0===n&&(n=!0),n&&(e.path=F),o===F&&(o="");let i=n?F:e.path;i&&"/"!==i&&(i=R(i));const s=i||e.id;let l=P([o,s]);i===F&&(i="/"),l!==F&&(l=P(["/",l]));const c=l===F?"/":x(P([r,i]));return{id:l,routeId:s,path:i,fullPath:c,options:e,children:a,createChildren:a=>t(e,a((e=>t(e,void 0,!1,l,c))),!1,o,r),addChildren:a=>t(e,a,!1,o,r),createRoute:e=>t(e,void 0,!1,l,c)}},t.createRouteMatch=T,t.createRouter=function(t){var e,a;const n=(null==t?void 0:t.history)||(z?i():r()),o=D({defaultLoaderGcMaxAge:3e5,defaultLoaderMaxAge:0,defaultPreloadMaxAge:2e3,defaultPreloadDelay:50},t,{stringifySearch:null!=(e=null==t?void 0:t.stringifySearch)?e:B,parseSearch:null!=(a=null==t?void 0:t.parseSearch)?a:N});let s={history:n,options:o,listeners:[],basepath:"",routeTree:void 0,routesById:{},location:void 0,allRouteInfo:void 0,navigationPromise:Promise.resolve(),resolveNavigation:()=>{},matchCache:{},state:K(),reset:()=>{s.state=K(),s.notify()},startedLoadingAt:Date.now(),subscribe:t=>(s.listeners.push(t),()=>{s.listeners=s.listeners.filter((e=>e!==t))}),getRoute:t=>s.routesById[t],notify:()=>{const t="loading"===s.state.status||s.state.matches.some((t=>t.isFetching)),e=Object.values(s.matchCache).some((t=>t.match.isFetching&&!s.state.matches.find((e=>e.matchId===t.match.matchId))));s.state.isFetching===t&&s.state.isPreloading===e||(s.state=D({},s.state,{isFetching:t,isPreloading:e})),V(s.state.matches),s.listeners.forEach((t=>t(s)))},dehydrateState:()=>D({},_(s.state,["status","location","lastUpdated"]),{matches:s.state.matches.map((t=>_(t,["matchId","status","routeLoaderData","loaderData","isInvalid","invalidAt"])))}),hydrateState:t=>{const e=s.matchRoutes(s.location.pathname,{strictParseParams:!0});e.forEach(((e,a)=>{const n=t.matches[a];f(n),Object.assign(e,n)})),e.forEach((t=>t.__.validate())),s.state=D({},s.state,t,{matches:e})},mount:()=>{const t=s.__.buildLocation({to:".",search:!0,hash:!0});t.href!==s.location.href&&s.__.commitLocation(t,!0),s.state.matches.length||s.load();const e=s.history.listen((t=>{s.load(s.__.parseLocation(t.location,s.location))}));return!z&&window.addEventListener&&(window.addEventListener("visibilitychange",s.onFocus,!1),window.addEventListener("focus",s.onFocus,!1)),()=>{e(),!z&&window.removeEventListener&&(window.removeEventListener("visibilitychange",s.onFocus),window.removeEventListener("focus",s.onFocus))}},onFocus:()=>{s.load()},update:t=>{const e=(null==t?void 0:t.history)!==s.history;s.location&&!e||(null!=t&&t.history&&(s.history=t.history),s.location=s.__.parseLocation(s.history.location),s.state.location=s.location),Object.assign(s.options,t);const{basepath:a,routeConfig:n}=s.options;return s.basepath=b("/"+(null!=a?a:"")),n&&(s.routesById={},s.routeTree=s.__.buildRouteTree(n)),s},cancelMatches:()=>{var t,e;[...s.state.matches,...null!=(t=null==(e=s.state.pending)?void 0:e.matches)?t:[]].forEach((t=>{t.cancel()}))},load:async t=>{const e=Math.random();s.startedLoadingAt=e,t&&(s.location=t),s.cancelMatches();const a=s.matchRoutes(s.location.pathname,{strictParseParams:!0});if("undefined"!=typeof document?s.state=D({},s.state,{pending:{matches:a,location:s.location},status:"loading"}):s.state=D({},s.state,{matches:a,location:s.location,status:"loading"}),s.notify(),await s.loadMatches(a),s.startedLoadingAt!==e)return s.navigationPromise;const n=s.state.matches,o=[],r=[];n.forEach((t=>{a.find((e=>e.matchId===t.matchId))?r.push(t):o.push(t)}));const i=a.filter((t=>!n.find((e=>e.matchId===t.matchId)))),l=Date.now();o.forEach((t=>{var e,a,n,o;null==t.__.onExit||t.__.onExit({params:t.params,search:t.routeSearch}),"error"!==t.status||t.isFetching||(t.status="idle",t.error=void 0);const r=Math.max(null!=(e=null!=(a=t.options.loaderGcMaxAge)?a:s.options.defaultLoaderGcMaxAge)?e:0,null!=(n=null!=(o=t.options.loaderMaxAge)?o:s.options.defaultLoaderMaxAge)?n:0);r>0&&(s.matchCache[t.matchId]={gc:r==1/0?Number.MAX_SAFE_INTEGER:l+r,match:t})})),r.forEach((t=>{null==t.options.onTransition||t.options.onTransition({params:t.params,search:t.routeSearch})})),i.forEach((t=>{t.__.onExit=null==t.options.onMatch?void 0:t.options.onMatch({params:t.params,search:t.search}),delete s.matchCache[t.matchId]})),s.startedLoadingAt===e&&(a.forEach((t=>{t.action&&(t.action.current=void 0,t.action.submissions=[])})),s.state=D({},s.state,{location:s.location,matches:a,pending:void 0,status:"idle"}),s.notify(),s.resolveNavigation())},cleanMatchCache:()=>{const t=Date.now();Object.keys(s.matchCache).forEach((e=>{const a=s.matchCache[e];"loading"!==a.match.status&&(a.gc>0&&a.gc>t||delete s.matchCache[e])}))},loadRoute:async function(t){void 0===t&&(t=s.location);const e=s.buildNext(t),a=s.matchRoutes(e.pathname,{strictParseParams:!0});return await s.loadMatches(a),a},preloadRoute:async function(t,e){var a,n,o,r,i,l;void 0===t&&(t=s.location);const c=s.buildNext(t),u=s.matchRoutes(c.pathname,{strictParseParams:!0});return await s.loadMatches(u,{preload:!0,maxAge:null!=(a=null!=(n=null!=(o=e.maxAge)?o:s.options.defaultPreloadMaxAge)?n:s.options.defaultLoaderMaxAge)?a:0,gcMaxAge:null!=(r=null!=(i=null!=(l=e.gcMaxAge)?l:s.options.defaultPreloadGcMaxAge)?i:s.options.defaultLoaderGcMaxAge)?r:0}),u},matchRoutes:(t,e)=>{var a,n;s.cleanMatchCache();const o=[];if(!s.routeTree)return o;const r=[...s.state.matches,...null!=(a=null==(n=s.state.pending)?void 0:n.matches)?a:[]],i=async a=>{var n,l,c;const u=g(o);let h=null!=(n=null==u?void 0:u.params)?n:{};const d=null!=(l=null==s.options.filterRoutes?void 0:s.options.filterRoutes(a))?l:a;let f=[];const p=(a,n)=>(n.some((n=>{var o,r,i;if(!n.routePath&&null!=(o=n.childRoutes)&&o.length)return p([...f,n],n.childRoutes);const l=!!("/"!==n.routePath||null!=(r=n.childRoutes)&&r.length),c=L(t,{to:n.fullPath,fuzzy:l,caseSensitive:null!=(i=n.options.caseSensitive)?i:s.options.caseSensitive});if(c){let t;try{var u;t=null!=(u=null==n.options.parseParams?void 0:n.options.parseParams(c))?u:c}catch(t){if(null!=e&&e.strictParseParams)throw t}h=D({},h,t)}return c&&(f=[...a,n]),!!f.length})),!!f.length);if(p([],d),!f.length)return;f.forEach((e=>{var a;const n=S(e.routePath,h),i=S(e.routeId,h,!0),l=r.find((t=>t.matchId===i))||(null==(a=s.matchCache[i])?void 0:a.match)||T(s,e,{matchId:i,params:h,pathname:P([t,n])});o.push(l)}));const m=g(f);null!=(c=m.childRoutes)&&c.length&&i(m.childRoutes)};return i([s.routeTree]),V(o),o},loadMatches:async(t,e)=>{const a=t.map((async t=>{t.__.validate(),t.load(e),t.__.loadPromise&&await t.__.loadPromise}));s.notify(),await Promise.all(a)},invalidateRoute:t=>{var e,a;const n=s.buildNext(t),o=s.matchRoutes(n.pathname).map((t=>t.matchId));[...s.state.matches,...null!=(e=null==(a=s.state.pending)?void 0:a.matches)?e:[]].forEach((t=>{o.includes(t.matchId)&&t.invalidate()}))},reload:()=>s.__.navigate({fromCurrent:!0,replace:!0,search:!0}),resolvePath:(t,e)=>A(s.basepath,t,b(e)),matchRoute:(t,e)=>{var a;t=D({},t,{to:t.to?s.resolvePath(null!=(a=t.from)?a:"",t.to):void 0});const n=s.buildNext(t);var o;return null!=e&&e.pending?!(null==(o=s.state.pending)||!o.location)&&!!L(s.state.pending.location.pathname,D({},e,{to:n.pathname})):!!L(s.state.location.pathname,D({},e,{to:n.pathname}))},navigate:async t=>{let{from:e,to:a=".",search:n,hash:o,replace:r,params:i}=t;const l=String(a),c=String(e);let u;try{new URL(""+l),u=!0}catch(t){}return f(!u),s.__.navigate({from:c,to:l,search:n,hash:o,replace:r,params:i})},buildLink:t=>{var e,a;let{from:n,to:o=".",search:r,params:i,hash:l,target:c,replace:u,activeOptions:h,preload:d,preloadMaxAge:f,preloadGcMaxAge:p,preloadDelay:m,disabled:v}=t;try{return new URL(""+o),{type:"external",href:o}}catch(t){}const g={from:n,to:o,search:r,params:i,hash:l,replace:u},y=s.buildNext(g);d=null!=(e=d)?e:s.options.defaultPreload;const _=null!=(a=null!=m?m:s.options.defaultPreloadDelay)?a:0,P=s.state.location.pathname===y.pathname,b=s.state.location.pathname.split("/"),w=y.pathname.split("/").every(((t,e)=>t===b[e])),x=s.state.location.hash===y.hash,R=null!=h&&h.exact?P:w,A=null==h||!h.includeHash||x;return{type:"internal",next:y,handleFocus:t=>{d&&s.preloadRoute(g,{maxAge:f,gcMaxAge:p})},handleClick:t=>{v||function(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}(t)||t.defaultPrevented||c&&"_self"!==c||0!==t.button||(t.preventDefault(),!P||r||l||s.invalidateRoute(g),s.__.navigate(g))},handleEnter:t=>{const e=t.target||{};if(d){if(e.preloadTimeout)return;e.preloadTimeout=setTimeout((()=>{e.preloadTimeout=null,s.preloadRoute(g,{maxAge:f,gcMaxAge:p})}),_)}},handleLeave:t=>{const e=t.target||{};e.preloadTimeout&&(clearTimeout(e.preloadTimeout),e.preloadTimeout=null)},isActive:R&&A,disabled:v}},buildNext:t=>{const e=s.__.buildLocation(t),a=s.matchRoutes(e.pathname),n=a.map((t=>{var e;return null!=(e=t.options.preSearchFilters)?e:[]})).flat().filter(Boolean),o=a.map((t=>{var e;return null!=(e=t.options.postSearchFilters)?e:[]})).flat().filter(Boolean);return s.__.buildLocation(D({},t,{__preSearchFilters:n,__postSearchFilters:o}))},__:{buildRouteTree:t=>{const e=(t,a)=>t.map((t=>{const n=O(t,t.options,a,s);if(s.routesById[n.routeId])throw new Error;s.routesById[n.routeId]=n;const o=t.children;return n.childRoutes=null!=o&&o.length?e(o,n):void 0,n}));return e([t])[0]},parseLocation:(t,e)=>{var a;const n=s.options.parseSearch(t.search);return{pathname:t.pathname,searchStr:t.search,search:p(null==e?void 0:e.search,n),hash:null!=(a=t.hash.split("#").reverse()[0])?a:"",href:""+t.pathname+t.search+t.hash,state:t.state,key:t.key}},navigate:t=>{const e=s.buildNext(t);return s.__.commitLocation(e,t.replace)},buildLocation:function(t){var e,a,n,o,r,i,l,c,u;void 0===t&&(t={});const h=t.fromCurrent?s.location.pathname:null!=(e=t.from)?e:s.location.pathname;let d=A(null!=(a=s.basepath)?a:"/",h,""+(null!=(n=t.to)?n:"."));const f=s.matchRoutes(s.location.pathname,{strictParseParams:!0}),m=s.matchRoutes(d),v=D({},null==(o=g(f))?void 0:o.params);let _=!0===(null==(r=t.params)||r)?v:y(t.params,v);_&&m.map((t=>t.options.stringifyParams)).filter(Boolean).forEach((t=>{Object.assign({},_,t(_))})),d=S(d,null!=_?_:{});const P=null!=(i=t.__preSearchFilters)&&i.length?t.__preSearchFilters.reduce(((t,e)=>e(t)),s.location.search):s.location.search,b=!0===t.search?P:t.search?null!=(l=y(t.search,P))?l:{}:null!=(c=t.__preSearchFilters)&&c.length?P:{},w=null!=(u=t.__postSearchFilters)&&u.length?t.__postSearchFilters.reduce(((t,e)=>e(t)),b):b,x=p(s.location.search,w),R=s.options.stringifySearch(x);let I=!0===t.hash?s.location.hash:y(t.hash,s.location.hash);return I=I?"#"+I:"",{pathname:d,search:x,searchStr:R,state:s.location.state,hash:I,href:""+d+R+I,key:t.key}},commitLocation:(t,e)=>{const a=""+Date.now()+Math.random();s.navigateTimeout&&clearTimeout(s.navigateTimeout);let o="replace";e||(o="push");return s.__.parseLocation(n.location).href===t.href&&!t.key&&(o="replace"),"replace"===o?n.replace({pathname:t.pathname,hash:t.hash,search:t.searchStr},{id:a}):n.push({pathname:t.pathname,hash:t.hash,search:t.searchStr},{id:a}),s.navigationPromise=new Promise((t=>{const e=s.resolveNavigation;s.resolveNavigation=()=>{e(),t()}})),s.navigationPromise}}};return s.update(t),null==s.options.createRouter||s.options.createRouter(s),s},t.decode=k,t.defaultParseSearch=N,t.defaultStringifySearch=B,t.encode=M,t.functionalUpdate=y,t.interpolatePath=S,t.invariant=f,t.joinPaths=P,t.last=g,t.matchByPath=E,t.matchPathname=L,t.parsePathname=I,t.parseSearchWith=U,t.pick=_,t.replaceEqualDeep=p,t.resolvePath=A,t.rootRouteId=F,t.stringifySearchWith=H,t.trimPath=R,t.trimPathLeft=w,t.trimPathRight=x,t.warning=function(t,e){if(t){"undefined"!=typeof console&&console.warn(e);try{throw new Error(e)}catch(t){}}return!0},Object.defineProperty(t,"__esModule",{value:!0})}));
11
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("use-sync-external-store/shim/with-selector")):"function"==typeof define&&define.amd?define(["exports","use-sync-external-store/shim/with-selector"],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 s="pushstate",a="popstate",r="beforeunload",o=t=>(t.preventDefault(),t.returnValue=""),i=()=>{removeEventListener(r,o,{capture:!0})};function n(t){let e=t.getLocation(),s=()=>{},a=new Set,n=[],h=[];const c=()=>{if(n.length)n[0]?.(c,(()=>{n=[],i()}));else{for(;h.length;)h.shift()?.();t.listener||u()}},l=t=>{h.push(t),c()},u=()=>{e=t.getLocation(),a.forEach((t=>t()))};return{get location(){return e},listen:e=>(0===a.size&&(s="function"==typeof t.listener?t.listener(u):()=>{}),a.add(e),()=>{a.delete(e),0===a.size&&s()}),push:(e,s)=>{l((()=>{t.pushState(e,s)}))},replace:(e,s)=>{l((()=>{t.replaceState(e,s)}))},go:e=>{l((()=>{t.go(e)}))},back:()=>{l((()=>{t.back()}))},forward:()=>{l((()=>{t.forward()}))},createHref:e=>t.createHref(e),block:t=>(n.push(t),1===n.length&&addEventListener(r,o,{capture:!0}),()=>{n=n.filter((e=>e!==t)),n.length||i()})}}function h(t){const e=t?.getHref??(()=>`${window.location.pathname}${window.location.search}${window.location.hash}`),r=t?.createHref??(t=>t);return n({getLocation:()=>l(e(),history.state),listener:t=>{window.addEventListener(s,t),window.addEventListener(a,t);var e=window.history.pushState;window.history.pushState=function(){let s=e.apply(history,arguments);return t(),s};var r=window.history.replaceState;return window.history.replaceState=function(){let e=r.apply(history,arguments);return t(),e},()=>{window.history.pushState=e,window.history.replaceState=r,window.removeEventListener(s,t),window.removeEventListener(a,t)}},pushState:(t,e)=>{window.history.pushState({...e,key:u()},"",r(t))},replaceState:(t,e)=>{window.history.replaceState({...e,key:u()},"",r(t))},back:()=>window.history.back(),forward:()=>window.history.forward(),go:t=>window.history.go(t),createHref:t=>r(t)})}function c(t={initialEntries:["/"]}){const e=t.initialEntries;let s=t.initialIndex??e.length-1,a={};return n({getLocation:()=>l(e[s],a),listener:!1,pushState:(t,r)=>{a={...r,key:u()},e.push(t),s++},replaceState:(t,r)=>{a={...r,key:u()},e[s]=t},back:()=>{s--},forward:()=>{s=Math.min(s+1,e.length-1)},go:t=>window.history.go(t),createHref:t=>t})}function l(t,e){let s=t.indexOf("#"),a=t.indexOf("?");return{href:t,pathname:t.substring(0,s>0?a>0?Math.min(s,a):s:a>0?a:t.length),hash:s>-1?t.substring(s):"",search:a>-1?t.slice(a,-1===s?void 0:s):"",state:e}}function u(){return(Math.random()+1).toString(36).substring(7)}function d(t){return t[t.length-1]}function p(t,e){return"function"==typeof t?t(e):t}function f(t,e){return e.reduce(((e,s)=>(e[s]=t[s],e)),{})}function m(t,e){if(t===e)return t;const s=e,a=Array.isArray(t)&&Array.isArray(s);if(a||y(t)&&y(s)){const e=a?t.length:Object.keys(t).length,r=a?s:Object.keys(s),o=r.length,i=a?[]:{};let n=0;for(let e=0;e<o;e++){const o=a?e:r[e];i[o]=m(t[o],s[o]),i[o]===t[o]&&n++}return e===o&&n===e?t:i}return s}function y(t){if(!g(t))return!1;const e=t.constructor;if(void 0===e)return!0;const s=e.prototype;return!!g(s)&&!!s.hasOwnProperty("isPrototypeOf")}function g(t){return"[object Object]"===Object.prototype.toString.call(t)}function v(t,e){return t===e||typeof t==typeof e&&(y(t)&&y(e)?!Object.keys(e).some((s=>!v(t[s],e[s]))):!(!Array.isArray(t)||!Array.isArray(e))&&(t.length===e.length&&t.every(((t,s)=>v(t,e[s])))))}function w(t){return _(t.filter(Boolean).join("/"))}function _(t){return t.replace(/\/{2,}/g,"/")}function R(t){return"/"===t?t:t.replace(/^\/{1,}/,"")}function b(t){return"/"===t?t:t.replace(/\/{1,}$/,"")}function I(t){return b(R(t))}function S(t,e,s){e=e.replace(new RegExp(`^${t}`),"/"),s=s.replace(new RegExp(`^${t}`),"/");let a=x(e);const r=x(s);r.forEach(((t,e)=>{if("/"===t.value)e?e===r.length-1&&a.push(t):a=[t];else if(".."===t.value)a.length>1&&"/"===d(a)?.value&&a.pop(),a.pop();else{if("."===t.value)return;a.push(t)}}));return _(w([t,...a.map((t=>t.value))]))}function x(t){if(!t)return[];const e=[];if("/"===(t=_(t)).slice(0,1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),!t)return e;const s=t.split("/").filter(Boolean);return e.push(...s.map((t=>"$"===t||"*"===t?{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 P(t,e,s=!1){return w(x(t).map((t=>{if("wildcard"===t.type){const a=e[t.value];return s?`${t.value}${a??""}`:a}return"param"===t.type?e[t.value.substring(1)]??"":t.value})))}function E(t,e,s){const a=M(t,e,s);if(!s.to||a)return a??{}}function M(t,e,s){e="/"!=t?e.substring(t.length):e;const a=`${s.to??"$"}`,r=x(e),o=x(a);e.startsWith("/")||r.unshift({type:"pathname",value:"/"}),a.startsWith("/")||o.unshift({type:"pathname",value:"/"});const i={};return(()=>{for(let t=0;t<Math.max(r.length,o.length);t++){const e=r[t],a=o[t],n=t>=r.length-1,h=t>=o.length-1;if(a){if("wildcard"===a.type)return!!e?.value&&(i["*"]=w(r.slice(t).map((t=>t.value))),!0);if("pathname"===a.type){if("/"===a.value&&!e?.value)return!0;if(e)if(s.caseSensitive){if(a.value!==e.value)return!1}else if(a.value.toLowerCase()!==e.value.toLowerCase())return!1}if(!e)return!1;if("param"===a.type){if("/"===e?.value)return!1;"$"!==e.value.charAt(0)&&(i[a.value.substring(1)]=e.value)}}if(!n&&h)return!!s.fuzzy}return!0})()?i:void 0}function L(t,e){var s,a,r,o="";for(s in t)if(void 0!==(r=t[s]))if(Array.isArray(r))for(a=0;a<r.length;a++)o&&(o+="&"),o+=encodeURIComponent(s)+"="+encodeURIComponent(r[a]);else o&&(o+="&"),o+=encodeURIComponent(s)+"="+encodeURIComponent(r);return(e||"")+o}function A(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||(0*+e==0&&+e+""===e?+e:e))}function D(t){for(var e,s,a={},r=t.split("&");e=r.shift();)void 0!==a[s=(e=e.split("=")).shift()]?a[s]=[].concat(a[s],A(e.shift())):a[s]=A(e.shift());return a}const $="__root__";class B{constructor(t){this.options=t||{},this.isRoot=!t?.getParentRoute,B.__onInit(this)}init=t=>{this.originalIndex=t.originalIndex,this.router=t.router;const s=this.options,a=!s?.path&&!s?.id;this.parentRoute=this.options?.getParentRoute?.(),a?this.path=$:e(this.parentRoute);let r=a?$:s.path;r&&"/"!==r&&(r=I(r));const o=s?.id||r;let i=a?$:w([this.parentRoute.id===$?"":this.parentRoute.id,o]);r===$&&(r="/"),i!==$&&(i=w(["/",i]));const n=i===$?"/":w([this.parentRoute.fullPath,r]);this.path=r,this.id=i,this.fullPath=n,this.to=n};addChildren=t=>(this.children=t,this);update=t=>(Object.assign(this.options,t),this);static __onInit=t=>{}}class O extends B{constructor(t){super(t)}}
12
+ /**
13
+ * @tanstack/store/src/index.ts
14
+ *
15
+ * Copyright (c) TanStack
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE.md file in the root directory of this source tree.
19
+ *
20
+ * @license MIT
21
+ */
22
+ class C{listeners=new Set;_batching=!1;_flushing=0;_nextPriority=null;constructor(t,e){this.state=t,this.options=e}subscribe=t=>{this.listeners.add(t);const e=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),e?.()}};setState=(t,e)=>{const s=this.state;this.state=this.options?.updateFn?this.options.updateFn(s)(t):t(s);const a=e?.priority??this.options?.defaultPriority??"high";null===this._nextPriority||"high"===this._nextPriority?this._nextPriority=a:this._nextPriority=this.options?.defaultPriority??"high",this.options?.onUpdate?.({priority:this._nextPriority}),this._flush()};_flush=()=>{if(this._batching)return;const t=++this._flushing;this.listeners.forEach((e=>{this._flushing===t&&e({priority:this._nextPriority??"high"})}))};batch=t=>{if(this._batching)return t();this._batching=!0,t(),this._batching=!1,this._flush()}}const T=k(JSON.parse),H=j(JSON.stringify);function k(t){return e=>{"?"===e.substring(0,1)&&(e=e.substring(1));let s=D(e);for(let e in s){const a=s[e];if("string"==typeof a)try{s[e]=t(a)}catch(t){}}return s}}function j(t){return e=>{(e={...e})&&Object.keys(e).forEach((s=>{const a=e[s];if(void 0===a||void 0===a)delete e[s];else if(a&&"object"==typeof a&&null!==a)try{e[s]=t(a)}catch(t){}}));const s=L(e).toString();return s?`?${s}`:""}}const F=["component","errorComponent","pendingComponent"];const N="undefined"==typeof window||!window.document.createElement;function U(){return{status:"idle",isFetching:!1,resolvedLocation:null,location:null,matchesById:{},matchIds:[],pendingMatchIds:[],matches:[],pendingMatches:[],lastUpdated:Date.now()}}function J(t){return!!t?.isRedirect}class W extends Error{}class z extends Error{}t.FileRoute=class{constructor(t){this.path=t}createRoute=t=>{const e=new B(t);return e.isRoot=!1,e}},t.PathParamError=z,t.RootRoute=O,t.Route=B,t.Router=class{#t;constructor(t){this.options={defaultPreloadDelay:50,context:void 0,...t,stringifySearch:t?.stringifySearch??H,parseSearch:t?.parseSearch??T},this.__store=new C(U(),{onUpdate:()=>{const t=this.state;this.state=this.__store.state;const e=t.matchesById!==this.state.matchesById;let s,a;e||(s=t.matchIds.length!==this.state.matchIds.length||t.matchIds.some(((t,e)=>t!==this.state.matchIds[e])),a=t.pendingMatchIds.length!==this.state.pendingMatchIds.length||t.pendingMatchIds.some(((t,e)=>t!==this.state.pendingMatchIds[e]))),(e||s)&&(this.state.matches=this.state.matchIds.map((t=>this.state.matchesById[t]))),(e||a)&&(this.state.pendingMatches=this.state.pendingMatchIds.map((t=>this.state.matchesById[t]))),this.state.isFetching=[...this.state.matches,...this.state.pendingMatches].some((t=>t.isFetching))},defaultPriority:"low"}),this.state=this.__store.state,this.update(t);const e=this.buildNext({hash:!0,fromCurrent:!0,search:!0,state:!0});this.state.location.href!==e.href&&this.#e({...e,replace:!0})}reset=()=>{this.__store.setState((t=>Object.assign(t,U())))};mount=()=>{this.safeLoad()};update=t=>{if(this.options={...this.options,...t,context:{...this.options.context,...t?.context}},!this.history||this.options.history&&this.options.history!==this.history){this.#t&&this.#t(),this.history=this.options.history??(N?c():h());const t=this.#s();this.__store.setState((e=>({...e,resolvedLocation:t,location:t}))),this.#t=this.history.listen((()=>{this.safeLoad({next:this.#s(this.state.location)})}))}const{basepath:e,routeTree:s}=this.options;return this.basepath=`/${I(e??"")??""}`,s&&s!==this.routeTree&&this.#a(s),this};buildNext=t=>{const e=this.#r(t),s=this.matchRoutes(e.pathname,e.search);return this.#r({...t,__matches:s})};cancelMatches=()=>{this.state.matches.forEach((t=>{this.cancelMatch(t.id)}))};cancelMatch=t=>{this.getRouteMatch(t)?.abortController?.abort()};safeLoad=t=>this.load(t).catch((t=>{}));latestLoadPromise=Promise.resolve();load=async t=>{const e=new Promise((async(s,a)=>{let r;const o=()=>this.latestLoadPromise!==e?this.latestLoadPromise:void 0;let i;this.__store.batch((()=>{t?.next&&this.__store.setState((e=>({...e,location:t.next}))),i=this.matchRoutes(this.state.location.pathname,this.state.location.search,{throwOnError:t?.throwOnError,debug:!0}),this.__store.setState((t=>({...t,status:"pending",pendingMatchIds:i.map((t=>t.id)),matchesById:this.#o(t.matchesById,i)})))}));try{if(await this.loadMatches(i),r=o())return await r;const t=this.state.resolvedLocation;this.__store.setState((t=>({...t,status:"idle",resolvedLocation:t.location,matchIds:t.pendingMatchIds,pendingMatchIds:[]}))),t.href!==this.state.location.href&&this.options.onRouteChange?.(),s()}catch(t){if(r=o())return await r;a(t)}}));return this.latestLoadPromise=e,this.latestLoadPromise};#o=(t,e)=>{const s={...t};let a=!1;return e.forEach((t=>{s[t.id]||(a=!0,s[t.id]=t)})),a?s:t};getRoute=t=>{const s=this.routesById[t];return e(s),s};preloadRoute=async(t=this.state.location)=>{const e=this.buildNext(t),s=this.matchRoutes(e.pathname,e.search,{throwOnError:!0});return this.__store.setState((t=>({...t,matchesById:this.#o(t.matchesById,s)}))),await this.loadMatches(s,{preload:!0,maxAge:t.maxAge}),s};cleanMatches=()=>{const t=Date.now(),e=Object.values(this.state.matchesById).filter((e=>{const s=this.getRoute(e.routeId);return!this.state.matchIds.includes(e.id)&&!this.state.pendingMatchIds.includes(e.id)&&e.preloadInvalidAt<t&&(!s.options.gcMaxAge||e.updatedAt+s.options.gcMaxAge<t)})).map((t=>t.id));e.length&&this.__store.setState((t=>{const s={...t.matchesById};return e.forEach((t=>{delete s[t]})),{...t,matchesById:s}}))};matchRoutes=(t,e,s)=>{let a={},r=this.flatRoutes.find((e=>{const s=E(this.basepath,t,{to:e.fullPath,caseSensitive:e.options.caseSensitive??this.options.caseSensitive});return!!s&&(a=s,!0)}))||this.routesById.__root__,o=[r];for(;r?.parentRoute;)r=r.parentRoute,r&&o.unshift(r);let i={};const n=o.map((t=>{let r,o;try{r=t.options.parseParams?.(a)??a}catch(t){if(o=new z(t.message,{cause:t}),s?.throwOnError)throw o}Object.assign(i,r);const n=P(t.path,i),h=t.options.key?t.options.key({params:i,search:e})??"":"",c=h?JSON.stringify(h):"",l=P(t.id,i,!0)+c,u=this.getRouteMatch(l);if(u)return{...u};const d=!(!t.options.loader&&!F.some((e=>t.options[e]?.preload)));return{id:l,key:c,routeId:t.id,params:i,pathname:w([this.basepath,n]),updatedAt:Date.now(),invalidAt:1/0,preloadInvalidAt:1/0,routeSearch:{},search:{},status:d?"idle":"success",isFetching:!1,invalid:!1,error:void 0,paramsError:o,searchError:void 0,loaderData:void 0,loadPromise:Promise.resolve(),routeContext:void 0,context:void 0,abortController:new AbortController,fetchedAt:0}}));return n.forEach(((t,a)=>{const r=n[a-1],o=this.getRoute(t.routeId),i=(()=>{const a={search:r?.search??e,routeSearch:r?.routeSearch??e};try{const e=("object"==typeof o.options.validateSearch?o.options.validateSearch.parse:o.options.validateSearch)?.(a.search)??{},s={...a.search,...e};return{routeSearch:m(t.routeSearch,e),search:m(t.search,s)}}catch(e){if(t.searchError=new W(e.message,{cause:e}),s?.throwOnError)throw t.searchError;return a}})(),h=(()=>{try{const e=o.options.getContext?.({parentContext:r?.routeContext??{},context:r?.context??this?.options.context??{},params:t.params,search:t.search})||{};return{context:{...r?.context??this?.options.context,...e},routeContext:e}}catch(t){throw o.options.onError?.(t),t}})();Object.assign(t,{...i,...h})})),n};loadMatches=async(t,e)=>{let s;this.cleanMatches();try{await Promise.all(t.map((async(t,a)=>{const r=this.getRoute(t.routeId);e?.preload||this.setRouteMatch(t.id,(e=>({...e,routeSearch:t.routeSearch,search:t.search,routeContext:t.routeContext,context:t.context,error:t.error,paramsError:t.paramsError,searchError:t.searchError,params:t.params})));const o=(e,o)=>{if(s=s??a,o=o||r.options.onError,J(e))throw e;try{o?.(e)}catch(t){if(e=t,J(t))throw t}this.setRouteMatch(t.id,(t=>({...t,error:e,status:"error",updatedAt:Date.now()})))};t.paramsError&&o(t.paramsError,r.options.onParseParamsError),t.searchError&&o(t.searchError,r.options.onValidateSearchError);try{await(r.options.beforeLoad?.({...t,preload:!!e?.preload}))}catch(t){o(t,r.options.onBeforeLoadError)}})))}catch(t){throw e?.preload||this.navigate(t),t}const a=t.slice(0,s),r=[];a.forEach(((t,s)=>{r.push((async()=>{const a=r[s-1],o=this.getRoute(t.routeId);if(t.isFetching||"success"===t.status&&!this.getIsInvalid({matchId:t.id,preload:e?.preload}))return this.getRouteMatch(t.id)?.loadPromise;const i=Date.now(),n=()=>{const e=this.getRouteMatch(t.id);return e&&e.fetchedAt!==i?e.loadPromise:void 0},h=(async()=>{let s;const r=Promise.all(F.map((async t=>{const e=o.options[t];e?.preload&&await e.preload()}))),i=o.options.loader?.({...t,preload:!!e?.preload,parentMatchPromise:a}),h=t=>!!J(t)&&(e?.preload||this.navigate(t),!0);try{const[a,o]=await Promise.all([r,i]);if(s=n())return await s;this.setRouteMatchData(t.id,(()=>o),e)}catch(e){if(s=n())return await s;if(h(e))return;const a=o.options.onLoadError??o.options.onError;let r=e;try{a?.(e)}catch(t){if(r=t,h(t))return}this.setRouteMatch(t.id,(t=>({...t,error:r,status:"error",isFetching:!1,updatedAt:Date.now()})))}})();this.setRouteMatch(t.id,(t=>({...t,status:"success"!==t.status?"pending":t.status,isFetching:!0,loadPromise:h,fetchedAt:i,invalid:!1}))),await h})())})),await Promise.all(r)};reload=()=>this.navigate({fromCurrent:!0,replace:!0,search:!0});resolvePath=(t,e)=>S(this.basepath,t,_(e));navigate=async({from:t,to:s="",search:a,hash:r,replace:o,params:i})=>{const n=String(s),h=void 0===t?t:String(t);let c;try{new URL(`${n}`),c=!0}catch(t){}return e(!c),this.#e({from:h,to:n,search:a,hash:r,replace:o,params:i})};matchRoute=(t,e)=>{t={...t,to:t.to?this.resolvePath(t.from??"",t.to):void 0};const s=this.buildNext(t);if(e?.pending&&"pending"!==this.state.status)return!1;const a=e?.pending?this.state.location:this.state.resolvedLocation;if(!a)return!1;const r=E(this.basepath,a.pathname,{...e,to:s.pathname});return!!r&&(e?.includeSearch??1?!!v(a.search,s.search)&&r:r)};buildLink=({from:t,to:e=".",search:s,params:a,hash:r,target:o,replace:i,activeOptions:n,preload:h,preloadDelay:c,disabled:l})=>{try{return new URL(`${e}`),{type:"external",href:e}}catch(t){}const u={from:t,to:e,search:s,params:a,hash:r,replace:i},d=this.buildNext(u);h=h??this.options.defaultPreload;const p=c??this.options.defaultPreloadDelay??0,f=this.state.location.pathname.split("/"),m=d.pathname.split("/").every(((t,e)=>t===f[e])),y=n?.exact?this.state.location.pathname===d.pathname:m,g=!n?.includeHash||this.state.location.hash===d.hash,w=!(n?.includeSearch??1)||v(this.state.location.search,d.search);return{type:"internal",next:d,handleFocus:t=>{h&&this.preloadRoute(u).catch((t=>{console.warn(t),console.warn("Error preloading route! ☝️")}))},handleClick:t=>{l||function(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}(t)||t.defaultPrevented||o&&"_self"!==o||0!==t.button||(t.preventDefault(),this.#e(u))},handleEnter:t=>{const e=t.target||{};if(h){if(e.preloadTimeout)return;e.preloadTimeout=setTimeout((()=>{e.preloadTimeout=null,this.preloadRoute(u).catch((t=>{console.warn(t),console.warn("Error preloading route! ☝️")}))}),p)}},handleLeave:t=>{const e=t.target||{};e.preloadTimeout&&(clearTimeout(e.preloadTimeout),e.preloadTimeout=null)},handleTouchStart:t=>{this.preloadRoute(u).catch((t=>{console.warn(t),console.warn("Error preloading route! ☝️")}))},isActive:y&&g&&w,disabled:l}};dehydrate=()=>({state:f(this.state,["location","status","lastUpdated"])});hydrate=async t=>{let s=t;"undefined"!=typeof document&&(s=window.__TSR_DEHYDRATED__),e(s);const a=s;this.dehydratedData=a.payload,this.options.hydrate?.(a.payload),this.__store.setState((t=>({...t,...a.router.state,resolvedLocation:a.router.state.location}))),await this.load()};injectedHtml=[];injectHtml=async t=>{this.injectedHtml.push(t)};dehydrateData=(t,e)=>{if("undefined"==typeof document){const s="string"==typeof t?t:JSON.stringify(t);return this.injectHtml((async()=>{const t=`__TSR_DEHYDRATED__${s}`,a="function"==typeof e?await e():e;return`<script id='${t}' suppressHydrationWarning>window["__TSR_DEHYDRATED__${r=s,r.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"')}"] = ${JSON.stringify(a)}\n ;(() => {\n var el = document.getElementById('${t}')\n el.parentElement.removeChild(el)\n })()\n <\/script>`;var r})),()=>this.hydrateData(t)}return()=>{}};hydrateData=t=>{if("undefined"!=typeof document){const e="string"==typeof t?t:JSON.stringify(t);return window[`__TSR_DEHYDRATED__${e}`]}};#a=t=>{this.routeTree=t,this.routesById={},this.routesByPath={},this.flatRoutes=[];const s=t=>{t.forEach(((t,a)=>{t.init({originalIndex:a,router:this});if(e(!this.routesById[t.id],String(t.id)),this.routesById[t.id]=t,!t.isRoot&&t.path){const e=b(t.fullPath);this.routesByPath[e]&&!t.fullPath.endsWith("/")||(this.routesByPath[e]=t)}const r=t.children;r?.length&&s(r)}))};s([t]),this.flatRoutes=Object.values(this.routesByPath).map(((t,e)=>{const s=I(t.fullPath),a=x(s);for(;a.length>1&&"/"===a[0]?.value;)a.shift();const r=a.map((t=>"param"===t.type?.5:"wildcard"===t.type?.25:1));return{child:t,trimmed:s,parsed:a,index:e,score:r}})).sort(((t,e)=>{let s="/"===t.trimmed?1:"/"===e.trimmed?-1:0;if(0!==s)return s;const a=Math.min(t.score.length,e.score.length);if(t.score.length!==e.score.length)return e.score.length-t.score.length;for(let s=0;s<a;s++)if(t.score[s]!==e.score[s])return e.score[s]-t.score[s];for(let s=0;s<a;s++)if(t.parsed[s].value!==e.parsed[s].value)return t.parsed[s].value>e.parsed[s].value?1:-1;return t.trimmed!==e.trimmed?t.trimmed>e.trimmed?1:-1:t.index-e.index})).map(((t,e)=>(t.child.rank=e,t.child)))};#s=t=>{let{pathname:e,search:s,hash:a,state:r}=this.history.location;const o=this.options.parseSearch(s);return{pathname:e,searchStr:s,search:m(t?.search,o),hash:a.split("#").reverse()[0]??"",href:`${e}${s}${a}`,state:r,key:r?.key||"__init__"}};#r=(t={})=>{t.fromCurrent=t.fromCurrent??""===t.to;const e=t.fromCurrent?this.state.location.pathname:t.from??this.state.location.pathname;let s=S(this.basepath??"/",e,`${t.to??""}`);const a={...d(this.matchRoutes(this.state.location.pathname,this.state.location.search))?.params};let r=!0===(t.params??!0)?a:p(t.params,a);r&&t.__matches?.map((t=>this.getRoute(t.routeId).options.stringifyParams)).filter(Boolean).forEach((t=>{r={...r,...t(r)}})),s=P(s,r??{});const o=t.__matches?.map((t=>this.getRoute(t.routeId).options.preSearchFilters??[])).flat().filter(Boolean)??[],i=t.__matches?.map((t=>this.getRoute(t.routeId).options.postSearchFilters??[])).flat().filter(Boolean)??[],n=o?.length?o?.reduce(((t,e)=>e(t)),this.state.location.search):this.state.location.search,h=!0===t.search?n:t.search?p(t.search,n)??{}:o?.length?n:{},c=i?.length?i.reduce(((t,e)=>e(t)),h):h,l=m(this.state.location.search,c),u=this.options.stringifySearch(l),f=!0===t.hash?this.state.location.hash:p(t.hash,this.state.location.hash),y=f?`#${f}`:"";return{pathname:s,search:l,searchStr:u,state:!0===t.state?this.state.location.state:p(t.state,this.state.location.state),hash:f,href:this.history.createHref(`${s}${u}${y}`),key:t.key}};#e=async t=>{const e=this.buildNext(t),s=""+Date.now()+Math.random();this.navigateTimeout&&clearTimeout(this.navigateTimeout);let a="replace";t.replace||(a="push");this.state.location.href===e.href&&!e.key&&(a="replace");const r=`${e.pathname}${e.searchStr}${e.hash?`#${e.hash}`:""}`;return this.history["push"===a?"push":"replace"](r,{id:s,...e.state}),this.latestLoadPromise};getRouteMatch=t=>this.state.matchesById[t];setRouteMatch=(t,e)=>{this.__store.setState((s=>({...s,matchesById:{...s.matchesById,[t]:e(s.matchesById[t])}})))};setRouteMatchData=(t,e,s)=>{const a=this.getRouteMatch(t);if(!a)return;const r=this.getRoute(a.routeId),o=s?.updatedAt??Date.now(),i=o+(s?.maxAge??r.options.preloadMaxAge??this.options.defaultPreloadMaxAge??5e3),n=o+(s?.maxAge??r.options.maxAge??this.options.defaultMaxAge??1/0);this.setRouteMatch(t,(t=>({...t,error:void 0,status:"success",isFetching:!1,updatedAt:Date.now(),loaderData:p(e,t.loaderData),preloadInvalidAt:i,invalidAt:n}))),this.state.matches.find((e=>e.id===t))};invalidate=async t=>{if(t?.matchId){this.setRouteMatch(t.matchId,(t=>({...t,invalid:!0})));const e=this.state.matches.findIndex((e=>e.id===t.matchId)),s=this.state.matches[e+1];if(s)return this.invalidate({matchId:s.id,reload:!1})}else this.__store.batch((()=>{Object.values(this.state.matchesById).forEach((t=>{this.setRouteMatch(t.id,(t=>({...t,invalid:!0})))}))}));if(t?.reload??1)return this.reload()};getIsInvalid=t=>{if(!t?.matchId)return!!this.state.matches.find((e=>this.getIsInvalid({matchId:e.id,preload:t?.preload})));const e=this.getRouteMatch(t?.matchId);if(!e)return!1;const s=Date.now();return e.invalid||(t?.preload?e.preloadInvalidAt:e.invalidAt)<s}},t.RouterContext=class{constructor(){}createRootRoute=t=>new O(t)},t.SearchParamError=W,t.cleanPath=_,t.componentTypes=F,t.createBrowserHistory=h,t.createHashHistory=function(){return h({getHref:()=>window.location.hash.substring(1),createHref:t=>`#${t}`})},t.createMemoryHistory=c,t.decode=D,t.defaultParseSearch=T,t.defaultStringifySearch=H,t.encode=L,t.functionalUpdate=p,t.interpolatePath=P,t.invariant=e,t.isPlainObject=y,t.isRedirect=J,t.joinPaths=w,t.last=d,t.lazyFn=function(t,e){return async(...s)=>(await t())[e||"default"](...s)},t.matchByPath=M,t.matchPathname=E,t.parsePathname=x,t.parseSearchWith=k,t.partialDeepEqual=v,t.pick=f,t.redirect=function(t){return t.isRedirect=!0,t},t.replaceEqualDeep=m,t.resolvePath=S,t.rootRouteId=$,t.stringifySearchWith=j,t.trimPath=I,t.trimPathLeft=R,t.trimPathRight=b,t.warning=function(t,e){},Object.defineProperty(t,"__esModule",{value:!0})}));
12
23
  //# sourceMappingURL=index.production.js.map