@remix-run/router 1.2.1-pre.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -2
- package/dist/router.cjs.js +6 -12
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +6 -12
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +6 -12
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/router.ts +5 -8
package/dist/router.umd.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.2.1
|
|
2
|
+
* @remix-run/router v1.2.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RemixRouter={})}(this,(function(e){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},t.apply(this,arguments)}var r;e.Action=void 0,(r=e.Action||(e.Action={})).Pop="POP",r.Push="PUSH",r.Replace="REPLACE";const a="popstate";function n(e,t){if(!1===e||null==e)throw new Error(t)}function o(e,t){if(!e){"undefined"!=typeof console&&console.warn(t);try{throw new Error(t)}catch(e){}}}function i(e){return{usr:e.state,key:e.key}}function s(e,r,a,n){return void 0===a&&(a=null),t({pathname:"string"==typeof e?e:e.pathname,search:"",hash:""},"string"==typeof r?c(r):r,{state:a,key:r&&r.key||n||Math.random().toString(36).substr(2,8)})}function l(e){let{pathname:t="/",search:r="",hash:a=""}=e;return r&&"?"!==r&&(t+="?"===r.charAt(0)?r:"?"+r),a&&"#"!==a&&(t+="#"===a.charAt(0)?a:"#"+a),t}function c(e){let t={};if(e){let r=e.indexOf("#");r>=0&&(t.hash=e.substr(r),e=e.substr(0,r));let a=e.indexOf("?");a>=0&&(t.search=e.substr(a),e=e.substr(0,a)),e&&(t.pathname=e)}return t}function d(e){let t="undefined"!=typeof window&&void 0!==window.location&&"null"!==window.location.origin?window.location.origin:window.location.href,r="string"==typeof e?e:l(e);return n(t,"No window.location.(origin|href) available to create URL for href: "+r),new URL(r,t)}function u(t,r,n,o){void 0===o&&(o={});let{window:c=document.defaultView,v5Compat:u=!1}=o,h=c.history,f=e.Action.Pop,p=null;function m(){f=e.Action.Pop,p&&p({action:f,location:g.location})}let g={get action(){return f},get location(){return t(c,h)},listen(e){if(p)throw new Error("A history only accepts one active listener");return c.addEventListener(a,m),p=e,()=>{c.removeEventListener(a,m),p=null}},createHref:e=>r(c,e),encodeLocation(e){let t=d("string"==typeof e?e:l(e));return{pathname:t.pathname,search:t.search,hash:t.hash}},push:function(t,r){f=e.Action.Push;let a=s(g.location,t,r);n&&n(a,t);let o=i(a),l=g.createHref(a);try{h.pushState(o,"",l)}catch(e){c.location.assign(l)}u&&p&&p({action:f,location:g.location})},replace:function(t,r){f=e.Action.Replace;let a=s(g.location,t,r);n&&n(a,t);let o=i(a),l=g.createHref(a);h.replaceState(o,"",l),u&&p&&p({action:f,location:g.location})},go:e=>h.go(e)};return g}let h;function f(e,r,a){return void 0===r&&(r=[]),void 0===a&&(a=new Set),e.map(((e,o)=>{let i=[...r,o],s="string"==typeof e.id?e.id:i.join("-");if(n(!0!==e.index||!e.children,"Cannot specify children on an index route"),n(!a.has(s),'Found a route id collision on id "'+s+"\". Route id's must be globally unique within Data Router usages"),a.add(s),function(e){return!0===e.index}(e)){return t({},e,{id:s})}return t({},e,{id:s,children:e.children?f(e.children,i,a):void 0})}))}function p(e,t,r){void 0===r&&(r="/");let a=E(("string"==typeof t?c(t):t).pathname||"/",r);if(null==a)return null;let n=m(e);!function(e){e.sort(((e,t)=>e.score!==t.score?t.score-e.score:function(e,t){return e.length===t.length&&e.slice(0,-1).every(((e,r)=>e===t[r]))?e[e.length-1]-t[t.length-1]:0}(e.routesMeta.map((e=>e.childrenIndex)),t.routesMeta.map((e=>e.childrenIndex)))))}(n);let o=null;for(let e=0;null==o&&e<n.length;++e)o=b(n[e],A(a));return o}function m(e,t,r,a){void 0===t&&(t=[]),void 0===r&&(r=[]),void 0===a&&(a="");let o=(e,o,i)=>{let s={relativePath:void 0===i?e.path||"":i,caseSensitive:!0===e.caseSensitive,childrenIndex:o,route:e};s.relativePath.startsWith("/")&&(n(s.relativePath.startsWith(a),'Absolute route path "'+s.relativePath+'" nested under path "'+a+'" is not valid. An absolute child route path must start with the combined path of all its parent routes.'),s.relativePath=s.relativePath.slice(a.length));let l=x([a,s.relativePath]),c=r.concat(s);e.children&&e.children.length>0&&(n(!0!==e.index,'Index routes must not have child routes. Please remove all child routes from route path "'+l+'".'),m(e.children,t,c,l)),(null!=e.path||e.index)&&t.push({path:l,score:w(l,e.index),routesMeta:c})};return e.forEach(((e,t)=>{var r;if(""!==e.path&&null!=(r=e.path)&&r.includes("?"))for(let r of g(e.path))o(e,t,r);else o(e,t)})),t}function g(e){let t=e.split("/");if(0===t.length)return[];let[r,...a]=t,n=r.endsWith("?"),o=r.replace(/\?$/,"");if(0===a.length)return n?[o,""]:[o];let i=g(a.join("/")),s=[];return s.push(...i.map((e=>""===e?o:[o,e].join("/")))),n&&s.push(...i),s.map((t=>e.startsWith("/")&&""===t?"/":t))}!function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"}(h||(h={}));const v=/^:\w+$/,y=e=>"*"===e;function w(e,t){let r=e.split("/"),a=r.length;return r.some(y)&&(a+=-2),t&&(a+=2),r.filter((e=>!y(e))).reduce(((e,t)=>e+(v.test(t)?3:""===t?1:10)),a)}function b(e,t){let{routesMeta:r}=e,a={},n="/",o=[];for(let e=0;e<r.length;++e){let i=r[e],s=e===r.length-1,l="/"===n?t:t.slice(n.length)||"/",c=D({path:i.relativePath,caseSensitive:i.caseSensitive,end:s},l);if(!c)return null;Object.assign(a,c.params);let d=i.route;o.push({params:a,pathname:x([n,c.pathname]),pathnameBase:L(x([n,c.pathnameBase])),route:d}),"/"!==c.pathnameBase&&(n=x([n,c.pathnameBase]))}return o}function D(e,t){"string"==typeof e&&(e={path:e,caseSensitive:!1,end:!0});let[r,a]=function(e,t,r){void 0===t&&(t=!1);void 0===r&&(r=!0);R("*"===e||!e.endsWith("*")||e.endsWith("/*"),'Route path "'+e+'" will be treated as if it were "'+e.replace(/\*$/,"/*")+'" because the `*` character must always follow a `/` in the pattern. To get rid of this warning, please change the route path to "'+e.replace(/\*$/,"/*")+'".');let a=[],n="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^$?{}|()[\]]/g,"\\$&").replace(/\/:(\w+)/g,((e,t)=>(a.push(t),"/([^\\/]+)")));e.endsWith("*")?(a.push("*"),n+="*"===e||"/*"===e?"(.*)$":"(?:\\/(.+)|\\/*)$"):r?n+="\\/*$":""!==e&&"/"!==e&&(n+="(?:(?=\\/|$))");return[new RegExp(n,t?void 0:"i"),a]}(e.path,e.caseSensitive,e.end),n=t.match(r);if(!n)return null;let o=n[0],i=o.replace(/(.)\/+$/,"$1"),s=n.slice(1);return{params:a.reduce(((e,t,r)=>{if("*"===t){let e=s[r]||"";i=o.slice(0,o.length-e.length).replace(/(.)\/+$/,"$1")}return e[t]=function(e,t){try{return decodeURIComponent(e)}catch(r){return R(!1,'The value for the URL param "'+t+'" will not be decoded because the string "'+e+'" is a malformed URL segment. This is probably due to a bad percent encoding ('+r+")."),e}}(s[r]||"",t),e}),{}),pathname:o,pathnameBase:i,pattern:e}}function A(e){try{return decodeURI(e)}catch(t){return R(!1,'The URL path "'+e+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent encoding ('+t+")."),e}}function E(e,t){if("/"===t)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let r=t.endsWith("/")?t.length-1:t.length,a=e.charAt(r);return a&&"/"!==a?null:e.slice(r)||"/"}function R(e,t){if(!e){"undefined"!=typeof console&&console.warn(t);try{throw new Error(t)}catch(e){}}}function P(e,t){void 0===t&&(t="/");let{pathname:r,search:a="",hash:n=""}="string"==typeof e?c(e):e,o=r?r.startsWith("/")?r:function(e,t){let r=t.replace(/\/+$/,"").split("/");return e.split("/").forEach((e=>{".."===e?r.length>1&&r.pop():"."!==e&&r.push(e)})),r.length>1?r.join("/"):"/"}(r,t):t;return{pathname:o,search:T(a),hash:j(n)}}function M(e,t,r,a){return"Cannot include a '"+e+"' character in a manually specified `to."+t+"` field ["+JSON.stringify(a)+"]. Please separate it out to the `to."+r+'` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.'}function C(e){return e.filter(((e,t)=>0===t||e.route.path&&e.route.path.length>0))}function S(e,r,a,o){let i;void 0===o&&(o=!1),"string"==typeof e?i=c(e):(i=t({},e),n(!i.pathname||!i.pathname.includes("?"),M("?","pathname","search",i)),n(!i.pathname||!i.pathname.includes("#"),M("#","pathname","hash",i)),n(!i.search||!i.search.includes("#"),M("#","search","hash",i)));let s,l=""===e||""===i.pathname,d=l?"/":i.pathname;if(o||null==d)s=a;else{let e=r.length-1;if(d.startsWith("..")){let t=d.split("/");for(;".."===t[0];)t.shift(),e-=1;i.pathname=t.join("/")}s=e>=0?r[e]:"/"}let u=P(i,s),h=d&&"/"!==d&&d.endsWith("/"),f=(l||"."===d)&&a.endsWith("/");return u.pathname.endsWith("/")||!h&&!f||(u.pathname+="/"),u}const x=e=>e.join("/").replace(/\/\/+/g,"/"),L=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),T=e=>e&&"?"!==e?e.startsWith("?")?e:"?"+e:"",j=e=>e&&"#"!==e?e.startsWith("#")?e:"#"+e:"";class O extends Error{}class U{constructor(e){let t;this.pendingKeys=new Set,this.subscriber=void 0,n(e&&"object"==typeof e&&!Array.isArray(e),"defer() only accepts plain objects"),this.abortPromise=new Promise(((e,r)=>t=r)),this.controller=new AbortController;let r=()=>t(new O("Deferred data aborted"));this.unlistenAbortSignal=()=>this.controller.signal.removeEventListener("abort",r),this.controller.signal.addEventListener("abort",r),this.data=Object.entries(e).reduce(((e,t)=>{let[r,a]=t;return Object.assign(e,{[r]:this.trackPromise(r,a)})}),{})}trackPromise(e,t){if(!(t instanceof Promise))return t;this.pendingKeys.add(e);let r=Promise.race([t,this.abortPromise]).then((t=>this.onSettle(r,e,null,t)),(t=>this.onSettle(r,e,t)));return r.catch((()=>{})),Object.defineProperty(r,"_tracked",{get:()=>!0}),r}onSettle(e,t,r,a){if(this.controller.signal.aborted&&r instanceof O)return this.unlistenAbortSignal(),Object.defineProperty(e,"_error",{get:()=>r}),Promise.reject(r);this.pendingKeys.delete(t),this.done&&this.unlistenAbortSignal();const n=this.subscriber;return r?(Object.defineProperty(e,"_error",{get:()=>r}),n&&n(!1),Promise.reject(r)):(Object.defineProperty(e,"_data",{get:()=>a}),n&&n(!1),a)}subscribe(e){this.subscriber=e}cancel(){this.controller.abort(),this.pendingKeys.forEach(((e,t)=>this.pendingKeys.delete(t)));let e=this.subscriber;e&&e(!0)}async resolveData(e){let t=!1;if(!this.done){let r=()=>this.cancel();e.addEventListener("abort",r),t=await new Promise((t=>{this.subscribe((a=>{e.removeEventListener("abort",r),(a||this.done)&&t(a)}))}))}return t}get done(){return 0===this.pendingKeys.size}get unwrappedData(){return n(null!==this.data&&this.done,"Can only unwrap data on initialized and settled deferreds"),Object.entries(this.data).reduce(((e,t)=>{let[r,a]=t;return Object.assign(e,{[r]:_(a)})}),{})}}function _(e){if(!function(e){return e instanceof Promise&&!0===e._tracked}(e))return e;if(e._error)throw e._error;return e._data}class H{constructor(e,t,r,a){void 0===a&&(a=!1),this.status=e,this.statusText=t||"",this.internal=a,r instanceof Error?(this.data=r.toString(),this.error=r):this.data=r}}function F(e){return e instanceof H}const k=["post","put","patch","delete"],q=new Set(k),I=["get",...k],W=new Set(I),$=new Set([301,302,303,307,308]),N=new Set([307,308]),B={state:"idle",location:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},z={state:"idle",data:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},K=!("undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement);function Y(e,t,r){void 0===r&&(r=!1);let a,n="string"==typeof e?e:l(e);if(!t||!function(e){return null!=e&&"formData"in e}(t))return{path:n};if(t.formMethod&&!pe(t.formMethod))return{path:n,error:ie(405,{method:t.formMethod})};if(t.formData&&(a={formMethod:t.formMethod||"get",formAction:le(n),formEncType:t&&t.formEncType||"application/x-www-form-urlencoded",formData:t.formData},me(a.formMethod)))return{path:n,submission:a};let o=c(n);try{let e=ee(t.formData);r&&o.search&&ye(o.search)&&e.append("index",""),o.search="?"+e}catch(e){return{path:n,error:ie(400)}}return{path:l(o),submission:a}}function J(e,t){let r=e;if(t){let a=e.findIndex((e=>e.route.id===t));a>=0&&(r=e.slice(0,a))}return r}function G(e,t,r,a,n,o,i,s,l,c){let d=l?Object.values(l)[0]:s?Object.values(s)[0]:void 0,u=J(t,l?Object.keys(l)[0]:void 0).filter(((t,i)=>null!=t.route.loader&&(function(e,t,r){let a=!t||r.route.id!==t.route.id,n=void 0===e[r.route.id];return a||n}(e.loaderData,e.matches[i],t)||o.some((e=>e===t.route.id))||X(e.location,e.matches[i],r,a,t,n,d)))),h=[];return c&&c.forEach(((e,t)=>{let[a,o,s]=e;if(i.includes(t))h.push([t,a,o,s]);else if(n){X(a,o,r,a,o,n,d)&&h.push([t,a,o,s])}})),[u,h]}function V(e,t){let r=e.route.path;return e.pathname!==t.pathname||r&&r.endsWith("*")&&e.params["*"]!==t.params["*"]}function X(e,r,a,n,o,i,s){let l=d(e),c=r.params,u=d(n),h=o.params,f=V(r,o)||l.toString()===u.toString()||l.search!==u.search||i;if(o.route.shouldRevalidate){let e=o.route.shouldRevalidate(t({currentUrl:l,currentParams:c,nextUrl:u,nextParams:h},a,{actionResult:s,defaultShouldRevalidate:f}));if("boolean"==typeof e)return e}return f}async function Q(e,t,r,a,o,i,s,c){let d,u,f;void 0===o&&(o="/"),void 0===i&&(i=!1),void 0===s&&(s=!1);let p=new Promise(((e,t)=>f=t)),m=()=>f();t.signal.addEventListener("abort",m);try{let a=r.route[e];n(a,"Could not find the "+e+' to run on the "'+r.route.id+'" route'),u=await Promise.race([a({request:t,params:r.params,context:c}),p]),n(void 0!==u,"You defined "+("action"===e?"an action":"a loader")+' for route "'+r.route.id+"\" but didn't return anything from your `"+e+"` function. Please return a value or `null`.")}catch(e){d=h.error,u=e}finally{t.signal.removeEventListener("abort",m)}if(he(u)){let e,c=u.status;if($.has(c)){let e=u.headers.get("Location");if(n(e,"Redirects returned/thrown from loaders/actions must have a Location header"),!(/^[a-z+]+:\/\//i.test(e)||e.startsWith("//"))){let i=S(e,C(a.slice(0,a.indexOf(r)+1)).map((e=>e.pathnameBase)),new URL(t.url).pathname);if(n(l(i),"Unable to resolve redirect location: "+e),o){let e=i.pathname;i.pathname="/"===e?o:x([o,e])}e=l(i)}if(i)throw u.headers.set("Location",e),u;return{type:h.redirect,status:c,location:e,revalidate:null!==u.headers.get("X-Remix-Revalidate")}}if(s)throw{type:d||h.data,response:u};let f=u.headers.get("Content-Type");return e=f&&/\bapplication\/json\b/.test(f)?await u.json():await u.text(),d===h.error?{type:d,error:new H(c,u.statusText,e),headers:u.headers}:{type:h.data,data:e,statusCode:u.status,headers:u.headers}}return d===h.error?{type:d,error:u}:u instanceof U?{type:h.deferred,deferredData:u}:{type:h.data,data:u}}function Z(e,t,r){let a=d(le(e)).toString(),n={signal:t};if(r&&me(r.formMethod)){let{formMethod:e,formEncType:t,formData:a}=r;n.method=e.toUpperCase(),n.body="application/x-www-form-urlencoded"===t?ee(a):a}return new Request(a,n)}function ee(e){let t=new URLSearchParams;for(let[r,a]of e.entries())n("string"==typeof a,'File inputs are not supported with encType "application/x-www-form-urlencoded", please use "multipart/form-data" instead.'),t.append(r,a);return t}function te(e,t,r,a,o){let i,s={},l=null,c=!1,d={};return r.forEach(((r,u)=>{let h=t[u].route.id;if(n(!ue(r),"Cannot handle redirect results in processLoaderData"),de(r)){let t=ne(e,h),n=r.error;a&&(n=Object.values(a)[0],a=void 0),l=l||{},null==l[t.route.id]&&(l[t.route.id]=n),s[h]=void 0,c||(c=!0,i=F(r.error)?r.error.status:500),r.headers&&(d[h]=r.headers)}else ce(r)?(o&&o.set(h,r.deferredData),s[h]=r.deferredData.data):(s[h]=r.data,null==r.statusCode||200===r.statusCode||c||(i=r.statusCode),r.headers&&(d[h]=r.headers))})),a&&(l=a,s[Object.keys(a)[0]]=void 0),{loaderData:s,errors:l,statusCode:i||200,loaderHeaders:d}}function re(e,r,a,o,i,s,l,c){let{loaderData:d,errors:u}=te(r,a,o,i,c);for(let r=0;r<s.length;r++){let[a,,o]=s[r];n(void 0!==l&&void 0!==l[r],"Did not find corresponding fetcher result");let i=l[r];if(de(i)){let r=ne(e.matches,o.route.id);u&&u[r.route.id]||(u=t({},u,{[r.route.id]:i.error})),e.fetchers.delete(a)}else{if(ue(i))throw new Error("Unhandled fetcher revalidation redirect");if(ce(i))throw new Error("Unhandled fetcher deferred data");{let t={state:"idle",data:i.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};e.fetchers.set(a,t)}}}return{loaderData:d,errors:u}}function ae(e,r,a,n){let o=t({},r);for(let t of a){let a=t.route.id;if(r.hasOwnProperty(a)?void 0!==r[a]&&(o[a]=r[a]):void 0!==e[a]&&(o[a]=e[a]),n&&n.hasOwnProperty(a))break}return o}function ne(e,t){return(t?e.slice(0,e.findIndex((e=>e.route.id===t))+1):[...e]).reverse().find((e=>!0===e.route.hasErrorBoundary))||e[0]}function oe(e){let t=e.find((e=>e.index||!e.path||"/"===e.path))||{id:"__shim-error-route__"};return{matches:[{params:{},pathname:"",pathnameBase:"",route:t}],route:t}}function ie(e,t){let{pathname:r,routeId:a,method:n}=void 0===t?{}:t,o="Unknown Server Error",i="Unknown @remix-run/router error";return 400===e?(o="Bad Request",i=n&&r&&a?"You made a "+n+' request to "'+r+'" but did not provide a `loader` for route "'+a+'", so there is no way to handle the request.':"Cannot submit binary form data using GET"):403===e?(o="Forbidden",i='Route "'+a+'" does not match URL "'+r+'"'):404===e?(o="Not Found",i='No route matches URL "'+r+'"'):405===e&&(o="Method Not Allowed",n&&r&&a?i="You made a "+n.toUpperCase()+' request to "'+r+'" but did not provide an `action` for route "'+a+'", so there is no way to handle the request.':n&&(i='Invalid request method "'+n.toUpperCase()+'"')),new H(e||500,o,new Error(i),!0)}function se(e){for(let t=e.length-1;t>=0;t--){let r=e[t];if(ue(r))return r}}function le(e){return l(t({},"string"==typeof e?c(e):e,{hash:""}))}function ce(e){return e.type===h.deferred}function de(e){return e.type===h.error}function ue(e){return(e&&e.type)===h.redirect}function he(e){return null!=e&&"number"==typeof e.status&&"string"==typeof e.statusText&&"object"==typeof e.headers&&void 0!==e.body}function fe(e){if(!he(e))return!1;let t=e.status,r=e.headers.get("Location");return t>=300&&t<=399&&null!=r}function pe(e){return W.has(e)}function me(e){return q.has(e)}async function ge(e,t,r,a,n,o){for(let i=0;i<r.length;i++){let s=r[i],l=t[i],c=e.find((e=>e.route.id===l.route.id)),d=null!=c&&!V(c,l)&&void 0!==(o&&o[l.route.id]);ce(s)&&(n||d)&&await ve(s,a,n).then((e=>{e&&(r[i]=e||r[i])}))}}async function ve(e,t,r){if(void 0===r&&(r=!1),!await e.deferredData.resolveData(t)){if(r)try{return{type:h.data,data:e.deferredData.unwrappedData}}catch(e){return{type:h.error,error:e}}return{type:h.data,data:e.deferredData.data}}}function ye(e){return new URLSearchParams(e).getAll("index").some((e=>""===e))}function we(e,t){let{route:r,pathname:a,params:n}=e;return{id:r.id,pathname:a,params:n,data:t[r.id],handle:r.handle}}function be(e,t){let r="string"==typeof t?c(t).search:t.search;if(e[e.length-1].route.index&&ye(r||""))return e[e.length-1];let a=C(e);return a[a.length-1]}e.AbortedDeferredError=O,e.ErrorResponse=H,e.IDLE_FETCHER=z,e.IDLE_NAVIGATION=B,e.UNSAFE_convertRoutesToDataRoutes=f,e.UNSAFE_getPathContributingMatches=C,e.createBrowserHistory=function(e){return void 0===e&&(e={}),u((function(e,t){let{pathname:r,search:a,hash:n}=e.location;return s("",{pathname:r,search:a,hash:n},t.state&&t.state.usr||null,t.state&&t.state.key||"default")}),(function(e,t){return"string"==typeof t?t:l(t)}),null,e)},e.createHashHistory=function(e){return void 0===e&&(e={}),u((function(e,t){let{pathname:r="/",search:a="",hash:n=""}=c(e.location.hash.substr(1));return s("",{pathname:r,search:a,hash:n},t.state&&t.state.usr||null,t.state&&t.state.key||"default")}),(function(e,t){let r=e.document.querySelector("base"),a="";if(r&&r.getAttribute("href")){let t=e.location.href,r=t.indexOf("#");a=-1===r?t:t.slice(0,r)}return a+"#"+("string"==typeof t?t:l(t))}),(function(e,t){o("/"===e.pathname.charAt(0),"relative pathnames are not supported in hash history.push("+JSON.stringify(t)+")")}),e)},e.createMemoryHistory=function(t){void 0===t&&(t={});let r,{initialEntries:a=["/"],initialIndex:n,v5Compat:i=!1}=t;r=a.map(((e,t)=>m(e,"string"==typeof e?null:e.state,0===t?"default":void 0)));let d=f(null==n?r.length-1:n),u=e.Action.Pop,h=null;function f(e){return Math.min(Math.max(e,0),r.length-1)}function p(){return r[d]}function m(e,t,a){void 0===t&&(t=null);let n=s(r?p().pathname:"/",e,t,a);return o("/"===n.pathname.charAt(0),"relative pathnames are not supported in memory history: "+JSON.stringify(e)),n}return{get index(){return d},get action(){return u},get location(){return p()},createHref:e=>"string"==typeof e?e:l(e),encodeLocation(e){let t="string"==typeof e?c(e):e;return{pathname:t.pathname||"",search:t.search||"",hash:t.hash||""}},push(t,a){u=e.Action.Push;let n=m(t,a);d+=1,r.splice(d,r.length,n),i&&h&&h({action:u,location:n})},replace(t,a){u=e.Action.Replace;let n=m(t,a);r[d]=n,i&&h&&h({action:u,location:n})},go(t){u=e.Action.Pop,d=f(d+t),h&&h({action:u,location:p()})},listen:e=>(h=e,()=>{h=null})}},e.createPath=l,e.createRouter=function(r){n(r.routes.length>0,"You must provide a non-empty routes array to createRouter");let a=f(r.routes),o=null,i=new Set,l=null,c=null,u=null,m=null!=r.hydrationData,g=p(a,r.history.location,r.basename),v=null;if(null==g){let e=ie(404,{pathname:r.history.location.pathname}),{matches:t,route:n}=oe(a);g=t,v={[n.id]:e}}let y,w,b=!g.some((e=>e.route.loader))||null!=r.hydrationData,D={historyAction:r.history.action,location:r.history.location,matches:g,initialized:b,navigation:B,restoreScrollPosition:null==r.hydrationData&&null,preventScrollReset:!1,revalidation:"idle",loaderData:r.hydrationData&&r.hydrationData.loaderData||{},actionData:r.hydrationData&&r.hydrationData.actionData||null,errors:r.hydrationData&&r.hydrationData.errors||v,fetchers:new Map},A=e.Action.Pop,E=!1,R=!1,P=!1,M=[],C=[],S=new Map,x=0,L=-1,T=new Map,j=new Set,O=new Map,U=new Map;function _(e){D=t({},D,e),i.forEach((e=>e(D)))}function H(a,n){var o;let i,s=null!=D.actionData&&null!=D.navigation.formMethod&&"loading"===D.navigation.state&&(null==(o=D.navigation.formAction)?void 0:o.split("?")[0])===a.pathname;i=n.actionData?Object.keys(n.actionData).length>0?n.actionData:null:s?D.actionData:null,_(t({},n,{actionData:i,loaderData:n.loaderData?ae(D.loaderData,n.loaderData,n.matches||[],n.errors):D.loaderData,historyAction:A,location:a,initialized:!0,navigation:B,revalidation:"idle",restoreScrollPosition:!D.navigation.formData&&le(a,n.matches||D.matches),preventScrollReset:E})),R||A===e.Action.Pop||(A===e.Action.Push?r.history.push(a,a.state):A===e.Action.Replace&&r.history.replace(a,a.state)),A=e.Action.Pop,E=!1,R=!1,P=!1,M=[],C=[]}async function F(o,i,s){w&&w.abort(),w=null,A=o,R=!0===(s&&s.startUninterruptedRevalidation),function(e,t){if(l&&c&&u){let r=t.map((e=>we(e,D.loaderData))),a=c(e,r)||e.key;l[a]=u()}}(D.location,D.matches),E=!0===(s&&s.preventScrollReset);let d=s&&s.overrideNavigation,f=p(a,i,r.basename);if(!f){let e=ie(404,{pathname:i.pathname}),{matches:t,route:r}=oe(a);return te(),void H(i,{matches:t,loaderData:{},errors:{[r.id]:e}})}if(m=D.location,g=i,m.pathname===g.pathname&&m.search===g.search&&m.hash!==g.hash)return void H(i,{matches:f});var m,g;w=new AbortController;let v,b,T=Z(i,w.signal,s&&s.submission);if(s&&s.pendingError)b={[ne(f).route.id]:s.pendingError};else if(s&&s.submission&&me(s.submission.formMethod)){let r=await async function(r,a,n,o,i){let s;W(),_({navigation:t({state:"submitting",location:a},n)});let l=be(o,a);if(l.route.action){if(s=await Q("action",r,l,o,y.basename),r.signal.aborted)return{shortCircuited:!0}}else s={type:h.error,error:ie(405,{method:r.method,pathname:a.pathname,routeId:l.route.id})};if(ue(s)){let e;return e=i&&null!=i.replace?i.replace:s.location===D.location.pathname+D.location.search,await q(D,s,{submission:n,replace:e}),{shortCircuited:!0}}if(de(s)){let t=ne(o,l.route.id);return!0!==(i&&i.replace)&&(A=e.Action.Push),{pendingActionData:{},pendingActionError:{[t.route.id]:s.error}}}if(ce(s))throw new Error("defer() is not supported in actions");return{pendingActionData:{[l.route.id]:s.data}}}(T,i,s.submission,f,{replace:s.replace});if(r.shortCircuited)return;v=r.pendingActionData,b=r.pendingActionError,d=t({state:"loading",location:i},s.submission),T=new Request(T.url,{signal:T.signal})}let{shortCircuited:F,loaderData:k,errors:$}=await async function(e,r,a,o,i,s,l,c){let d=o;if(!d){d=t({state:"loading",location:r,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},i)}let u=i||(d.formMethod&&d.formAction&&d.formData&&d.formEncType?{formMethod:d.formMethod,formAction:d.formAction,formData:d.formData,formEncType:d.formEncType}:void 0),[h,f]=G(D,a,u,r,P,M,C,l,c,O);if(te((e=>!(a&&a.some((t=>t.route.id===e)))||h&&h.some((t=>t.route.id===e)))),0===h.length&&0===f.length)return H(r,t({matches:a,loaderData:{},errors:c||null},l?{actionData:l}:{})),{shortCircuited:!0};if(!R){f.forEach((e=>{let[t]=e,r=D.fetchers.get(t),a={state:"loading",data:r&&r.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(t,a)}));let e=l||D.actionData;_(t({navigation:d},e?0===Object.keys(e).length?{actionData:null}:{actionData:e}:{},f.length>0?{fetchers:new Map(D.fetchers)}:{}))}L=++x,f.forEach((e=>{let[t]=e;return S.set(t,w)}));let{results:p,loaderResults:m,fetcherResults:g}=await I(D.matches,a,h,f,e);if(e.signal.aborted)return{shortCircuited:!0};f.forEach((e=>{let[t]=e;return S.delete(t)}));let v=se(p);if(v)return await q(D,v,{replace:s}),{shortCircuited:!0};let{loaderData:y,errors:b}=re(D,a,h,m,c,f,g,U);U.forEach(((e,t)=>{e.subscribe((r=>{(r||e.done)&&U.delete(t)}))})),function(){let e=[];for(let t of j){let r=D.fetchers.get(t);n(r,"Expected fetcher: "+t),"loading"===r.state&&(j.delete(t),e.push(t))}X(e)}();let A=ee(L);return t({loaderData:y,errors:b},A||f.length>0?{fetchers:new Map(D.fetchers)}:{})}(T,i,f,d,s&&s.submission,s&&s.replace,v,b);F||(w=null,H(i,t({matches:f},v?{actionData:v}:{},{loaderData:k,errors:$})))}function k(e){return D.fetchers.get(e)||z}async function q(r,a,o){var i;let{submission:l,replace:c,isFetchActionRedirect:u}=void 0===o?{}:o;a.revalidate&&(P=!0);let h=s(r.location,a.location,t({_isRedirect:!0},u?{_isFetchActionRedirect:!0}:{}));if(n(h,"Expected a location on the redirect navigation"),void 0!==(null==(i=window)?void 0:i.location)){let e=d(a.location).origin;if(window.location.origin!==e)return void(c?window.location.replace(a.location):window.location.assign(a.location))}w=null;let f=!0===c?e.Action.Replace:e.Action.Push,{formMethod:p,formAction:m,formEncType:g,formData:v}=r.navigation;!l&&p&&m&&v&&g&&(l={formMethod:p,formAction:m,formEncType:g,formData:v}),N.has(a.status)&&l&&me(l.formMethod)?await F(f,h,{submission:t({},l,{formAction:a.location})}):await F(f,h,{overrideNavigation:{state:"loading",location:h,formMethod:l?l.formMethod:void 0,formAction:l?l.formAction:void 0,formEncType:l?l.formEncType:void 0,formData:l?l.formData:void 0}})}async function I(e,t,r,a,n){let o=await Promise.all([...r.map((e=>Q("loader",n,e,t,y.basename))),...a.map((e=>{let[,t,r,a]=e;return Q("loader",Z(t,n.signal),r,a,y.basename)}))]),i=o.slice(0,r.length),s=o.slice(r.length);return await Promise.all([ge(e,r,i,n.signal,!1,D.loaderData),ge(e,a.map((e=>{let[,,t]=e;return t})),s,n.signal,!0)]),{results:o,loaderResults:i,fetcherResults:s}}function W(){P=!0,M.push(...te()),O.forEach(((e,t)=>{S.has(t)&&(C.push(t),V(t))}))}function $(e,t,r){let a=ne(D.matches,t);J(e),_({errors:{[a.route.id]:r},fetchers:new Map(D.fetchers)})}function J(e){S.has(e)&&V(e),O.delete(e),T.delete(e),j.delete(e),D.fetchers.delete(e)}function V(e){let t=S.get(e);n(t,"Expected fetch controller: "+e),t.abort(),S.delete(e)}function X(e){for(let t of e){let e={state:"idle",data:k(t).data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(t,e)}}function ee(e){let t=[];for(let[r,a]of T)if(a<e){let e=D.fetchers.get(r);n(e,"Expected fetcher: "+r),"loading"===e.state&&(V(r),T.delete(r),t.push(r))}return X(t),t.length>0}function te(e){let t=[];return U.forEach(((r,a)=>{e&&!e(a)||(r.cancel(),t.push(a),U.delete(a))})),t}function le(e,t){if(l&&c&&u){let r=t.map((e=>we(e,D.loaderData))),a=c(e,r)||e.key,n=l[a];if("number"==typeof n)return n}return null}return y={get basename(){return r.basename},get state(){return D},get routes(){return a},initialize:function(){return o=r.history.listen((e=>{let{action:t,location:r}=e;return F(t,r)})),D.initialized||F(e.Action.Pop,D.location),y},subscribe:function(e){return i.add(e),()=>i.delete(e)},enableScrollRestoration:function(e,t,r){if(l=e,u=t,c=r||(e=>e.key),!m&&D.navigation===B){m=!0;let e=le(D.location,D.matches);null!=e&&_({restoreScrollPosition:e})}return()=>{l=null,u=null,c=null}},navigate:async function(a,n){if("number"==typeof a)return void r.history.go(a);let{path:o,submission:i,error:l}=Y(a,n),c=s(D.location,o,n&&n.state);c=t({},c,r.history.encodeLocation(c));let d=n&&null!=n.replace?n.replace:void 0,u=e.Action.Push;!0===d?u=e.Action.Replace:!1===d||null!=i&&me(i.formMethod)&&i.formAction===D.location.pathname+D.location.search&&(u=e.Action.Replace);let h=n&&"preventScrollReset"in n?!0===n.preventScrollReset:void 0;return await F(u,c,{submission:i,pendingError:l,preventScrollReset:h,replace:n&&n.replace})},fetch:function(e,o,i,s){if(K)throw new Error("router.fetch() was called during the server render, but it shouldn't be. You are likely calling a useFetcher() method in the body of your component. Try moving it to a useEffect or a callback.");S.has(e)&&V(e);let l=p(a,i,r.basename);if(!l)return void $(e,o,ie(404,{pathname:i}));let{path:c,submission:d}=Y(i,s,!0),u=be(l,c);d&&me(d.formMethod)?async function(e,o,i,s,l,c){if(W(),O.delete(e),!s.route.action){let t=ie(405,{method:c.formMethod,pathname:i,routeId:o});return void $(e,o,t)}let d=D.fetchers.get(e),u=t({state:"submitting"},c,{data:d&&d.data," _hasFetcherDoneAnything ":!0});D.fetchers.set(e,u),_({fetchers:new Map(D.fetchers)});let h=new AbortController,f=Z(i,h.signal,c);S.set(e,h);let m=await Q("action",f,s,l,y.basename);if(f.signal.aborted)return void(S.get(e)===h&&S.delete(e));if(ue(m)){S.delete(e),j.add(e);let r=t({state:"loading"},c,{data:void 0," _hasFetcherDoneAnything ":!0});return D.fetchers.set(e,r),_({fetchers:new Map(D.fetchers)}),q(D,m,{submission:c,isFetchActionRedirect:!0})}if(de(m))return void $(e,o,m.error);ce(m)&&n(!1,"defer() is not supported in actions");let g=D.navigation.location||D.location,v=Z(g,h.signal),b="idle"!==D.navigation.state?p(a,D.navigation.location,r.basename):D.matches;n(b,"Didn't find any matches after fetcher action");let E=++x;T.set(e,E);let R=t({state:"loading",data:m.data},c,{" _hasFetcherDoneAnything ":!0});D.fetchers.set(e,R);let[F,k]=G(D,b,c,g,P,M,C,{[s.route.id]:m.data},void 0,O);k.filter((t=>{let[r]=t;return r!==e})).forEach((e=>{let[t]=e,r=D.fetchers.get(t),a={state:"loading",data:r&&r.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(t,a),S.set(t,h)})),_({fetchers:new Map(D.fetchers)});let{results:N,loaderResults:B,fetcherResults:z}=await I(D.matches,b,F,k,v);if(h.signal.aborted)return;T.delete(e),S.delete(e),k.forEach((e=>{let[t]=e;return S.delete(t)}));let K=se(N);if(K)return q(D,K,{submission:c});let{loaderData:Y,errors:J}=re(D,D.matches,F,B,void 0,k,z,U),V={state:"idle",data:m.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(e,V);let X=ee(E);"loading"===D.navigation.state&&E>L?(n(A,"Expected pending action"),w&&w.abort(),H(D.navigation.location,{matches:b,loaderData:Y,errors:J,fetchers:new Map(D.fetchers)})):(_(t({errors:J,loaderData:ae(D.loaderData,Y,b,J)},X?{fetchers:new Map(D.fetchers)}:{})),P=!1)}(e,o,c,u,l,d):(O.set(e,[c,u,l]),async function(e,r,a,o,i,s){let l=D.fetchers.get(e),c=t({state:"loading",formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},s,{data:l&&l.data," _hasFetcherDoneAnything ":!0});D.fetchers.set(e,c),_({fetchers:new Map(D.fetchers)});let d=new AbortController,u=Z(a,d.signal);S.set(e,d);let h=await Q("loader",u,o,i,y.basename);ce(h)&&(h=await ve(h,u.signal,!0)||h);S.get(e)===d&&S.delete(e);if(u.signal.aborted)return;if(ue(h))return void await q(D,h);if(de(h)){let t=ne(D.matches,r);return D.fetchers.delete(e),void _({fetchers:new Map(D.fetchers),errors:{[t.route.id]:h.error}})}n(!ce(h),"Unhandled fetcher deferred data");let f={state:"idle",data:h.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(e,f),_({fetchers:new Map(D.fetchers)})}(e,o,c,u,l,d))},revalidate:function(){W(),_({revalidation:"loading"}),"submitting"!==D.navigation.state&&("idle"!==D.navigation.state?F(A||D.historyAction,D.navigation.location,{overrideNavigation:D.navigation}):F(D.historyAction,D.location,{startUninterruptedRevalidation:!0}))},createHref:e=>r.history.createHref(e),encodeLocation:e=>r.history.encodeLocation(e),getFetcher:k,deleteFetcher:J,dispose:function(){o&&o(),i.clear(),w&&w.abort(),D.fetchers.forEach(((e,t)=>J(t)))},_internalFetchControllers:S,_internalActiveDeferreds:U},y},e.createStaticHandler=function(e,r){n(e.length>0,"You must provide a non-empty routes array to createStaticHandler");let a=f(e),o=(r?r.basename:null)||"/";async function i(e,r,a,i,s){n(e.signal,"query()/queryRoute() requests must contain an AbortController signal");try{if(me(e.method.toLowerCase())){let n=await async function(e,r,a,n,i){let s;if(a.route.action){if(s=await Q("action",e,a,r,o,!0,i,n),e.signal.aborted){throw new Error((i?"queryRoute":"query")+"() call aborted")}}else{let t=ie(405,{method:e.method,pathname:new URL(e.url).pathname,routeId:a.route.id});if(i)throw t;s={type:h.error,error:t}}if(ue(s))throw new Response(null,{status:s.status,headers:{Location:s.location}});if(ce(s))throw new Error("defer() is not supported in actions");if(i){if(de(s))throw s.error;return{matches:[a],loaderData:{},actionData:{[a.route.id]:s.data},errors:null,statusCode:200,loaderHeaders:{},actionHeaders:{}}}if(de(s)){let o=ne(r,a.route.id);return t({},await c(e,r,n,void 0,{[o.route.id]:s.error}),{statusCode:F(s.error)?s.error.status:500,actionData:null,actionHeaders:t({},s.headers?{[a.route.id]:s.headers}:{})})}let l=new Request(e.url,{headers:e.headers,redirect:e.redirect,signal:e.signal});return t({},await c(l,r,n),s.statusCode?{statusCode:s.statusCode}:{},{actionData:{[a.route.id]:s.data},actionHeaders:t({},s.headers?{[a.route.id]:s.headers}:{})})}(e,a,s||be(a,r),i,null!=s);return n}let n=await c(e,a,i,s);return he(n)?n:t({},n,{actionData:null,actionHeaders:{}})}catch(e){if((l=e)&&he(l.response)&&(l.type===h.data||h.error)){if(e.type===h.error&&!fe(e.response))throw e.response;return e.response}if(fe(e))return e;throw e}var l}async function c(e,r,a,n,i){let s=null!=n;if(s&&(null==n||!n.route.loader))throw ie(400,{method:e.method,pathname:new URL(e.url).pathname,routeId:null==n?void 0:n.route.id});let l=(n?[n]:J(r,Object.keys(i||{})[0])).filter((e=>e.route.loader));if(0===l.length)return{matches:r,loaderData:r.reduce(((e,t)=>Object.assign(e,{[t.route.id]:null})),{}),errors:i||null,statusCode:200,loaderHeaders:{}};let c=await Promise.all([...l.map((t=>Q("loader",e,t,r,o,!0,s,a)))]);if(e.signal.aborted){throw new Error((s?"queryRoute":"query")+"() call aborted")}let d=new Set;c.forEach(((e,t)=>{d.add(l[t].route.id),ce(e)&&e.deferredData.cancel()}));let u=te(r,l,c,i);return r.forEach((e=>{d.has(e.route.id)||(u.loaderData[e.route.id]=null)})),t({},u,{matches:r})}return{dataRoutes:a,query:async function(e,r){let{requestContext:n}=void 0===r?{}:r,c=new URL(e.url),d=e.method.toLowerCase(),u=s("",l(c),null,"default"),h=p(a,u,o);if(!pe(d)&&"head"!==d){let e=ie(405,{method:d}),{matches:t,route:r}=oe(a);return{basename:o,location:u,matches:t,loaderData:{},actionData:null,errors:{[r.id]:e},statusCode:e.status,loaderHeaders:{},actionHeaders:{}}}if(!h){let e=ie(404,{pathname:u.pathname}),{matches:t,route:r}=oe(a);return{basename:o,location:u,matches:t,loaderData:{},actionData:null,errors:{[r.id]:e},statusCode:e.status,loaderHeaders:{},actionHeaders:{}}}let f=await i(e,u,h,n);return he(f)?f:t({location:u,basename:o},f)},queryRoute:async function(e,t){let{routeId:r,requestContext:n}=void 0===t?{}:t,c=new URL(e.url),d=e.method.toLowerCase(),u=s("",l(c),null,"default"),h=p(a,u,o);if(!pe(d)&&"head"!==d)throw ie(405,{method:d});if(!h)throw ie(404,{pathname:u.pathname});let f=r?h.find((e=>e.route.id===r)):be(h,u);if(r&&!f)throw ie(403,{pathname:u.pathname,routeId:r});if(!f)throw ie(404,{pathname:u.pathname});let m=await i(e,u,h,n,f);if(he(m))return m;let g=m.errors?Object.values(m.errors)[0]:void 0;if(void 0!==g)throw g;let v=[m.actionData,m.loaderData].find((e=>e));return Object.values(v||{})[0]}}},e.defer=function(e){return new U(e)},e.generatePath=function(e,t){void 0===t&&(t={});let r=e;return r.endsWith("*")&&"*"!==r&&!r.endsWith("/*")&&(R(!1,'Route path "'+r+'" will be treated as if it were "'+r.replace(/\*$/,"/*")+'" because the `*` character must always follow a `/` in the pattern. To get rid of this warning, please change the route path to "'+r.replace(/\*$/,"/*")+'".'),r=r.replace(/\*$/,"/*")),r.replace(/^:(\w+)/g,((e,r)=>(n(null!=t[r],'Missing ":'+r+'" param'),t[r]))).replace(/\/:(\w+)/g,((e,r)=>(n(null!=t[r],'Missing ":'+r+'" param'),"/"+t[r]))).replace(/(\/?)\*/,((e,r,a,n)=>null==t["*"]?"/*"===n?"/":"":""+r+t["*"]))},e.getStaticContextFromError=function(e,r,a){return t({},r,{statusCode:500,errors:{[r._deepestRenderedBoundaryId||e[0].id]:a}})},e.getToPathname=function(e){return""===e||""===e.pathname?"/":"string"==typeof e?c(e).pathname:e.pathname},e.invariant=n,e.isRouteErrorResponse=F,e.joinPaths=x,e.json=function(e,r){void 0===r&&(r={});let a="number"==typeof r?{status:r}:r,n=new Headers(a.headers);return n.has("Content-Type")||n.set("Content-Type","application/json; charset=utf-8"),new Response(JSON.stringify(e),t({},a,{headers:n}))},e.matchPath=D,e.matchRoutes=p,e.normalizePathname=L,e.parsePath=c,e.redirect=function(e,r){void 0===r&&(r=302);let a=r;"number"==typeof a?a={status:a}:void 0===a.status&&(a.status=302);let n=new Headers(a.headers);return n.set("Location",e),new Response(null,t({},a,{headers:n}))},e.resolvePath=P,e.resolveTo=S,e.stripBasename=E,e.warning=R,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
11
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RemixRouter={})}(this,(function(e){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},t.apply(this,arguments)}var r;e.Action=void 0,(r=e.Action||(e.Action={})).Pop="POP",r.Push="PUSH",r.Replace="REPLACE";const a="popstate";function n(e,t){if(!1===e||null==e)throw new Error(t)}function o(e,t){if(!e){"undefined"!=typeof console&&console.warn(t);try{throw new Error(t)}catch(e){}}}function i(e){return{usr:e.state,key:e.key}}function s(e,r,a,n){return void 0===a&&(a=null),t({pathname:"string"==typeof e?e:e.pathname,search:"",hash:""},"string"==typeof r?c(r):r,{state:a,key:r&&r.key||n||Math.random().toString(36).substr(2,8)})}function l(e){let{pathname:t="/",search:r="",hash:a=""}=e;return r&&"?"!==r&&(t+="?"===r.charAt(0)?r:"?"+r),a&&"#"!==a&&(t+="#"===a.charAt(0)?a:"#"+a),t}function c(e){let t={};if(e){let r=e.indexOf("#");r>=0&&(t.hash=e.substr(r),e=e.substr(0,r));let a=e.indexOf("?");a>=0&&(t.search=e.substr(a),e=e.substr(0,a)),e&&(t.pathname=e)}return t}function d(e){let t="undefined"!=typeof window&&void 0!==window.location&&"null"!==window.location.origin?window.location.origin:window.location.href,r="string"==typeof e?e:l(e);return n(t,"No window.location.(origin|href) available to create URL for href: "+r),new URL(r,t)}function u(t,r,n,o){void 0===o&&(o={});let{window:c=document.defaultView,v5Compat:u=!1}=o,h=c.history,f=e.Action.Pop,p=null;function m(){f=e.Action.Pop,p&&p({action:f,location:g.location})}let g={get action(){return f},get location(){return t(c,h)},listen(e){if(p)throw new Error("A history only accepts one active listener");return c.addEventListener(a,m),p=e,()=>{c.removeEventListener(a,m),p=null}},createHref:e=>r(c,e),encodeLocation(e){let t=d("string"==typeof e?e:l(e));return{pathname:t.pathname,search:t.search,hash:t.hash}},push:function(t,r){f=e.Action.Push;let a=s(g.location,t,r);n&&n(a,t);let o=i(a),l=g.createHref(a);try{h.pushState(o,"",l)}catch(e){c.location.assign(l)}u&&p&&p({action:f,location:g.location})},replace:function(t,r){f=e.Action.Replace;let a=s(g.location,t,r);n&&n(a,t);let o=i(a),l=g.createHref(a);h.replaceState(o,"",l),u&&p&&p({action:f,location:g.location})},go:e=>h.go(e)};return g}let h;function f(e,r,a){return void 0===r&&(r=[]),void 0===a&&(a=new Set),e.map(((e,o)=>{let i=[...r,o],s="string"==typeof e.id?e.id:i.join("-");if(n(!0!==e.index||!e.children,"Cannot specify children on an index route"),n(!a.has(s),'Found a route id collision on id "'+s+"\". Route id's must be globally unique within Data Router usages"),a.add(s),function(e){return!0===e.index}(e)){return t({},e,{id:s})}return t({},e,{id:s,children:e.children?f(e.children,i,a):void 0})}))}function p(e,t,r){void 0===r&&(r="/");let a=E(("string"==typeof t?c(t):t).pathname||"/",r);if(null==a)return null;let n=m(e);!function(e){e.sort(((e,t)=>e.score!==t.score?t.score-e.score:function(e,t){return e.length===t.length&&e.slice(0,-1).every(((e,r)=>e===t[r]))?e[e.length-1]-t[t.length-1]:0}(e.routesMeta.map((e=>e.childrenIndex)),t.routesMeta.map((e=>e.childrenIndex)))))}(n);let o=null;for(let e=0;null==o&&e<n.length;++e)o=b(n[e],A(a));return o}function m(e,t,r,a){void 0===t&&(t=[]),void 0===r&&(r=[]),void 0===a&&(a="");let o=(e,o,i)=>{let s={relativePath:void 0===i?e.path||"":i,caseSensitive:!0===e.caseSensitive,childrenIndex:o,route:e};s.relativePath.startsWith("/")&&(n(s.relativePath.startsWith(a),'Absolute route path "'+s.relativePath+'" nested under path "'+a+'" is not valid. An absolute child route path must start with the combined path of all its parent routes.'),s.relativePath=s.relativePath.slice(a.length));let l=x([a,s.relativePath]),c=r.concat(s);e.children&&e.children.length>0&&(n(!0!==e.index,'Index routes must not have child routes. Please remove all child routes from route path "'+l+'".'),m(e.children,t,c,l)),(null!=e.path||e.index)&&t.push({path:l,score:w(l,e.index),routesMeta:c})};return e.forEach(((e,t)=>{var r;if(""!==e.path&&null!=(r=e.path)&&r.includes("?"))for(let r of g(e.path))o(e,t,r);else o(e,t)})),t}function g(e){let t=e.split("/");if(0===t.length)return[];let[r,...a]=t,n=r.endsWith("?"),o=r.replace(/\?$/,"");if(0===a.length)return n?[o,""]:[o];let i=g(a.join("/")),s=[];return s.push(...i.map((e=>""===e?o:[o,e].join("/")))),n&&s.push(...i),s.map((t=>e.startsWith("/")&&""===t?"/":t))}!function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"}(h||(h={}));const v=/^:\w+$/,y=e=>"*"===e;function w(e,t){let r=e.split("/"),a=r.length;return r.some(y)&&(a+=-2),t&&(a+=2),r.filter((e=>!y(e))).reduce(((e,t)=>e+(v.test(t)?3:""===t?1:10)),a)}function b(e,t){let{routesMeta:r}=e,a={},n="/",o=[];for(let e=0;e<r.length;++e){let i=r[e],s=e===r.length-1,l="/"===n?t:t.slice(n.length)||"/",c=D({path:i.relativePath,caseSensitive:i.caseSensitive,end:s},l);if(!c)return null;Object.assign(a,c.params);let d=i.route;o.push({params:a,pathname:x([n,c.pathname]),pathnameBase:L(x([n,c.pathnameBase])),route:d}),"/"!==c.pathnameBase&&(n=x([n,c.pathnameBase]))}return o}function D(e,t){"string"==typeof e&&(e={path:e,caseSensitive:!1,end:!0});let[r,a]=function(e,t,r){void 0===t&&(t=!1);void 0===r&&(r=!0);R("*"===e||!e.endsWith("*")||e.endsWith("/*"),'Route path "'+e+'" will be treated as if it were "'+e.replace(/\*$/,"/*")+'" because the `*` character must always follow a `/` in the pattern. To get rid of this warning, please change the route path to "'+e.replace(/\*$/,"/*")+'".');let a=[],n="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^$?{}|()[\]]/g,"\\$&").replace(/\/:(\w+)/g,((e,t)=>(a.push(t),"/([^\\/]+)")));e.endsWith("*")?(a.push("*"),n+="*"===e||"/*"===e?"(.*)$":"(?:\\/(.+)|\\/*)$"):r?n+="\\/*$":""!==e&&"/"!==e&&(n+="(?:(?=\\/|$))");return[new RegExp(n,t?void 0:"i"),a]}(e.path,e.caseSensitive,e.end),n=t.match(r);if(!n)return null;let o=n[0],i=o.replace(/(.)\/+$/,"$1"),s=n.slice(1);return{params:a.reduce(((e,t,r)=>{if("*"===t){let e=s[r]||"";i=o.slice(0,o.length-e.length).replace(/(.)\/+$/,"$1")}return e[t]=function(e,t){try{return decodeURIComponent(e)}catch(r){return R(!1,'The value for the URL param "'+t+'" will not be decoded because the string "'+e+'" is a malformed URL segment. This is probably due to a bad percent encoding ('+r+")."),e}}(s[r]||"",t),e}),{}),pathname:o,pathnameBase:i,pattern:e}}function A(e){try{return decodeURI(e)}catch(t){return R(!1,'The URL path "'+e+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent encoding ('+t+")."),e}}function E(e,t){if("/"===t)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let r=t.endsWith("/")?t.length-1:t.length,a=e.charAt(r);return a&&"/"!==a?null:e.slice(r)||"/"}function R(e,t){if(!e){"undefined"!=typeof console&&console.warn(t);try{throw new Error(t)}catch(e){}}}function P(e,t){void 0===t&&(t="/");let{pathname:r,search:a="",hash:n=""}="string"==typeof e?c(e):e,o=r?r.startsWith("/")?r:function(e,t){let r=t.replace(/\/+$/,"").split("/");return e.split("/").forEach((e=>{".."===e?r.length>1&&r.pop():"."!==e&&r.push(e)})),r.length>1?r.join("/"):"/"}(r,t):t;return{pathname:o,search:T(a),hash:j(n)}}function M(e,t,r,a){return"Cannot include a '"+e+"' character in a manually specified `to."+t+"` field ["+JSON.stringify(a)+"]. Please separate it out to the `to."+r+'` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.'}function C(e){return e.filter(((e,t)=>0===t||e.route.path&&e.route.path.length>0))}function S(e,r,a,o){let i;void 0===o&&(o=!1),"string"==typeof e?i=c(e):(i=t({},e),n(!i.pathname||!i.pathname.includes("?"),M("?","pathname","search",i)),n(!i.pathname||!i.pathname.includes("#"),M("#","pathname","hash",i)),n(!i.search||!i.search.includes("#"),M("#","search","hash",i)));let s,l=""===e||""===i.pathname,d=l?"/":i.pathname;if(o||null==d)s=a;else{let e=r.length-1;if(d.startsWith("..")){let t=d.split("/");for(;".."===t[0];)t.shift(),e-=1;i.pathname=t.join("/")}s=e>=0?r[e]:"/"}let u=P(i,s),h=d&&"/"!==d&&d.endsWith("/"),f=(l||"."===d)&&a.endsWith("/");return u.pathname.endsWith("/")||!h&&!f||(u.pathname+="/"),u}const x=e=>e.join("/").replace(/\/\/+/g,"/"),L=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),T=e=>e&&"?"!==e?e.startsWith("?")?e:"?"+e:"",j=e=>e&&"#"!==e?e.startsWith("#")?e:"#"+e:"";class O extends Error{}class _{constructor(e){let t;this.pendingKeys=new Set,this.subscriber=void 0,n(e&&"object"==typeof e&&!Array.isArray(e),"defer() only accepts plain objects"),this.abortPromise=new Promise(((e,r)=>t=r)),this.controller=new AbortController;let r=()=>t(new O("Deferred data aborted"));this.unlistenAbortSignal=()=>this.controller.signal.removeEventListener("abort",r),this.controller.signal.addEventListener("abort",r),this.data=Object.entries(e).reduce(((e,t)=>{let[r,a]=t;return Object.assign(e,{[r]:this.trackPromise(r,a)})}),{})}trackPromise(e,t){if(!(t instanceof Promise))return t;this.pendingKeys.add(e);let r=Promise.race([t,this.abortPromise]).then((t=>this.onSettle(r,e,null,t)),(t=>this.onSettle(r,e,t)));return r.catch((()=>{})),Object.defineProperty(r,"_tracked",{get:()=>!0}),r}onSettle(e,t,r,a){if(this.controller.signal.aborted&&r instanceof O)return this.unlistenAbortSignal(),Object.defineProperty(e,"_error",{get:()=>r}),Promise.reject(r);this.pendingKeys.delete(t),this.done&&this.unlistenAbortSignal();const n=this.subscriber;return r?(Object.defineProperty(e,"_error",{get:()=>r}),n&&n(!1),Promise.reject(r)):(Object.defineProperty(e,"_data",{get:()=>a}),n&&n(!1),a)}subscribe(e){this.subscriber=e}cancel(){this.controller.abort(),this.pendingKeys.forEach(((e,t)=>this.pendingKeys.delete(t)));let e=this.subscriber;e&&e(!0)}async resolveData(e){let t=!1;if(!this.done){let r=()=>this.cancel();e.addEventListener("abort",r),t=await new Promise((t=>{this.subscribe((a=>{e.removeEventListener("abort",r),(a||this.done)&&t(a)}))}))}return t}get done(){return 0===this.pendingKeys.size}get unwrappedData(){return n(null!==this.data&&this.done,"Can only unwrap data on initialized and settled deferreds"),Object.entries(this.data).reduce(((e,t)=>{let[r,a]=t;return Object.assign(e,{[r]:U(a)})}),{})}}function U(e){if(!function(e){return e instanceof Promise&&!0===e._tracked}(e))return e;if(e._error)throw e._error;return e._data}class H{constructor(e,t,r,a){void 0===a&&(a=!1),this.status=e,this.statusText=t||"",this.internal=a,r instanceof Error?(this.data=r.toString(),this.error=r):this.data=r}}function F(e){return e instanceof H}const k=["post","put","patch","delete"],q=new Set(k),I=["get",...k],W=new Set(I),$=new Set([301,302,303,307,308]),N=new Set([307,308]),B={state:"idle",location:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},z={state:"idle",data:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},K=!("undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement);function Y(e,t,r){void 0===r&&(r=!1);let a,n="string"==typeof e?e:l(e);if(!t||!function(e){return null!=e&&"formData"in e}(t))return{path:n};if(t.formMethod&&!pe(t.formMethod))return{path:n,error:ie(405,{method:t.formMethod})};if(t.formData&&(a={formMethod:t.formMethod||"get",formAction:le(n),formEncType:t&&t.formEncType||"application/x-www-form-urlencoded",formData:t.formData},me(a.formMethod)))return{path:n,submission:a};let o=c(n);try{let e=ee(t.formData);r&&o.search&&ye(o.search)&&e.append("index",""),o.search="?"+e}catch(e){return{path:n,error:ie(400)}}return{path:l(o),submission:a}}function J(e,t){let r=e;if(t){let a=e.findIndex((e=>e.route.id===t));a>=0&&(r=e.slice(0,a))}return r}function G(e,t,r,a,n,o,i,s,l,c){let d=l?Object.values(l)[0]:s?Object.values(s)[0]:void 0,u=J(t,l?Object.keys(l)[0]:void 0).filter(((t,i)=>null!=t.route.loader&&(function(e,t,r){let a=!t||r.route.id!==t.route.id,n=void 0===e[r.route.id];return a||n}(e.loaderData,e.matches[i],t)||o.some((e=>e===t.route.id))||X(e.location,e.matches[i],r,a,t,n,d)))),h=[];return c&&c.forEach(((e,t)=>{let[a,o,s]=e;if(i.includes(t))h.push([t,a,o,s]);else if(n){X(a,o,r,a,o,n,d)&&h.push([t,a,o,s])}})),[u,h]}function V(e,t){let r=e.route.path;return e.pathname!==t.pathname||r&&r.endsWith("*")&&e.params["*"]!==t.params["*"]}function X(e,r,a,n,o,i,s){let l=d(e),c=r.params,u=d(n),h=o.params,f=V(r,o)||l.toString()===u.toString()||l.search!==u.search||i;if(o.route.shouldRevalidate){let e=o.route.shouldRevalidate(t({currentUrl:l,currentParams:c,nextUrl:u,nextParams:h},a,{actionResult:s,defaultShouldRevalidate:f}));if("boolean"==typeof e)return e}return f}async function Q(e,t,r,a,o,i,s,c){let d,u,f;void 0===o&&(o="/"),void 0===i&&(i=!1),void 0===s&&(s=!1);let p=new Promise(((e,t)=>f=t)),m=()=>f();t.signal.addEventListener("abort",m);try{let a=r.route[e];n(a,"Could not find the "+e+' to run on the "'+r.route.id+'" route'),u=await Promise.race([a({request:t,params:r.params,context:c}),p]),n(void 0!==u,"You defined "+("action"===e?"an action":"a loader")+' for route "'+r.route.id+"\" but didn't return anything from your `"+e+"` function. Please return a value or `null`.")}catch(e){d=h.error,u=e}finally{t.signal.removeEventListener("abort",m)}if(he(u)){let e,c=u.status;if($.has(c)){let e=u.headers.get("Location");if(n(e,"Redirects returned/thrown from loaders/actions must have a Location header"),!(/^[a-z+]+:\/\//i.test(e)||e.startsWith("//"))){let i=S(e,C(a.slice(0,a.indexOf(r)+1)).map((e=>e.pathnameBase)),new URL(t.url).pathname);if(n(l(i),"Unable to resolve redirect location: "+e),o){let e=i.pathname;i.pathname="/"===e?o:x([o,e])}e=l(i)}if(i)throw u.headers.set("Location",e),u;return{type:h.redirect,status:c,location:e,revalidate:null!==u.headers.get("X-Remix-Revalidate")}}if(s)throw{type:d||h.data,response:u};let f=u.headers.get("Content-Type");return e=f&&/\bapplication\/json\b/.test(f)?await u.json():await u.text(),d===h.error?{type:d,error:new H(c,u.statusText,e),headers:u.headers}:{type:h.data,data:e,statusCode:u.status,headers:u.headers}}return d===h.error?{type:d,error:u}:u instanceof _?{type:h.deferred,deferredData:u}:{type:h.data,data:u}}function Z(e,t,r){let a=d(le(e)).toString(),n={signal:t};if(r&&me(r.formMethod)){let{formMethod:e,formEncType:t,formData:a}=r;n.method=e.toUpperCase(),n.body="application/x-www-form-urlencoded"===t?ee(a):a}return new Request(a,n)}function ee(e){let t=new URLSearchParams;for(let[r,a]of e.entries())n("string"==typeof a,'File inputs are not supported with encType "application/x-www-form-urlencoded", please use "multipart/form-data" instead.'),t.append(r,a);return t}function te(e,t,r,a,o){let i,s={},l=null,c=!1,d={};return r.forEach(((r,u)=>{let h=t[u].route.id;if(n(!ue(r),"Cannot handle redirect results in processLoaderData"),de(r)){let t=ne(e,h),n=r.error;a&&(n=Object.values(a)[0],a=void 0),l=l||{},null==l[t.route.id]&&(l[t.route.id]=n),s[h]=void 0,c||(c=!0,i=F(r.error)?r.error.status:500),r.headers&&(d[h]=r.headers)}else ce(r)?(o&&o.set(h,r.deferredData),s[h]=r.deferredData.data):(s[h]=r.data,null==r.statusCode||200===r.statusCode||c||(i=r.statusCode),r.headers&&(d[h]=r.headers))})),a&&(l=a,s[Object.keys(a)[0]]=void 0),{loaderData:s,errors:l,statusCode:i||200,loaderHeaders:d}}function re(e,r,a,o,i,s,l,c){let{loaderData:d,errors:u}=te(r,a,o,i,c);for(let r=0;r<s.length;r++){let[a,,o]=s[r];n(void 0!==l&&void 0!==l[r],"Did not find corresponding fetcher result");let i=l[r];if(de(i)){let r=ne(e.matches,o.route.id);u&&u[r.route.id]||(u=t({},u,{[r.route.id]:i.error})),e.fetchers.delete(a)}else{if(ue(i))throw new Error("Unhandled fetcher revalidation redirect");if(ce(i))throw new Error("Unhandled fetcher deferred data");{let t={state:"idle",data:i.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};e.fetchers.set(a,t)}}}return{loaderData:d,errors:u}}function ae(e,r,a,n){let o=t({},r);for(let t of a){let a=t.route.id;if(r.hasOwnProperty(a)?void 0!==r[a]&&(o[a]=r[a]):void 0!==e[a]&&(o[a]=e[a]),n&&n.hasOwnProperty(a))break}return o}function ne(e,t){return(t?e.slice(0,e.findIndex((e=>e.route.id===t))+1):[...e]).reverse().find((e=>!0===e.route.hasErrorBoundary))||e[0]}function oe(e){let t=e.find((e=>e.index||!e.path||"/"===e.path))||{id:"__shim-error-route__"};return{matches:[{params:{},pathname:"",pathnameBase:"",route:t}],route:t}}function ie(e,t){let{pathname:r,routeId:a,method:n}=void 0===t?{}:t,o="Unknown Server Error",i="Unknown @remix-run/router error";return 400===e?(o="Bad Request",i=n&&r&&a?"You made a "+n+' request to "'+r+'" but did not provide a `loader` for route "'+a+'", so there is no way to handle the request.':"Cannot submit binary form data using GET"):403===e?(o="Forbidden",i='Route "'+a+'" does not match URL "'+r+'"'):404===e?(o="Not Found",i='No route matches URL "'+r+'"'):405===e&&(o="Method Not Allowed",n&&r&&a?i="You made a "+n.toUpperCase()+' request to "'+r+'" but did not provide an `action` for route "'+a+'", so there is no way to handle the request.':n&&(i='Invalid request method "'+n.toUpperCase()+'"')),new H(e||500,o,new Error(i),!0)}function se(e){for(let t=e.length-1;t>=0;t--){let r=e[t];if(ue(r))return r}}function le(e){return l(t({},"string"==typeof e?c(e):e,{hash:""}))}function ce(e){return e.type===h.deferred}function de(e){return e.type===h.error}function ue(e){return(e&&e.type)===h.redirect}function he(e){return null!=e&&"number"==typeof e.status&&"string"==typeof e.statusText&&"object"==typeof e.headers&&void 0!==e.body}function fe(e){if(!he(e))return!1;let t=e.status,r=e.headers.get("Location");return t>=300&&t<=399&&null!=r}function pe(e){return W.has(e)}function me(e){return q.has(e)}async function ge(e,t,r,a,n,o){for(let i=0;i<r.length;i++){let s=r[i],l=t[i],c=e.find((e=>e.route.id===l.route.id)),d=null!=c&&!V(c,l)&&void 0!==(o&&o[l.route.id]);ce(s)&&(n||d)&&await ve(s,a,n).then((e=>{e&&(r[i]=e||r[i])}))}}async function ve(e,t,r){if(void 0===r&&(r=!1),!await e.deferredData.resolveData(t)){if(r)try{return{type:h.data,data:e.deferredData.unwrappedData}}catch(e){return{type:h.error,error:e}}return{type:h.data,data:e.deferredData.data}}}function ye(e){return new URLSearchParams(e).getAll("index").some((e=>""===e))}function we(e,t){let{route:r,pathname:a,params:n}=e;return{id:r.id,pathname:a,params:n,data:t[r.id],handle:r.handle}}function be(e,t){let r="string"==typeof t?c(t).search:t.search;if(e[e.length-1].route.index&&ye(r||""))return e[e.length-1];let a=C(e);return a[a.length-1]}e.AbortedDeferredError=O,e.ErrorResponse=H,e.IDLE_FETCHER=z,e.IDLE_NAVIGATION=B,e.UNSAFE_convertRoutesToDataRoutes=f,e.UNSAFE_getPathContributingMatches=C,e.createBrowserHistory=function(e){return void 0===e&&(e={}),u((function(e,t){let{pathname:r,search:a,hash:n}=e.location;return s("",{pathname:r,search:a,hash:n},t.state&&t.state.usr||null,t.state&&t.state.key||"default")}),(function(e,t){return"string"==typeof t?t:l(t)}),null,e)},e.createHashHistory=function(e){return void 0===e&&(e={}),u((function(e,t){let{pathname:r="/",search:a="",hash:n=""}=c(e.location.hash.substr(1));return s("",{pathname:r,search:a,hash:n},t.state&&t.state.usr||null,t.state&&t.state.key||"default")}),(function(e,t){let r=e.document.querySelector("base"),a="";if(r&&r.getAttribute("href")){let t=e.location.href,r=t.indexOf("#");a=-1===r?t:t.slice(0,r)}return a+"#"+("string"==typeof t?t:l(t))}),(function(e,t){o("/"===e.pathname.charAt(0),"relative pathnames are not supported in hash history.push("+JSON.stringify(t)+")")}),e)},e.createMemoryHistory=function(t){void 0===t&&(t={});let r,{initialEntries:a=["/"],initialIndex:n,v5Compat:i=!1}=t;r=a.map(((e,t)=>m(e,"string"==typeof e?null:e.state,0===t?"default":void 0)));let d=f(null==n?r.length-1:n),u=e.Action.Pop,h=null;function f(e){return Math.min(Math.max(e,0),r.length-1)}function p(){return r[d]}function m(e,t,a){void 0===t&&(t=null);let n=s(r?p().pathname:"/",e,t,a);return o("/"===n.pathname.charAt(0),"relative pathnames are not supported in memory history: "+JSON.stringify(e)),n}return{get index(){return d},get action(){return u},get location(){return p()},createHref:e=>"string"==typeof e?e:l(e),encodeLocation(e){let t="string"==typeof e?c(e):e;return{pathname:t.pathname||"",search:t.search||"",hash:t.hash||""}},push(t,a){u=e.Action.Push;let n=m(t,a);d+=1,r.splice(d,r.length,n),i&&h&&h({action:u,location:n})},replace(t,a){u=e.Action.Replace;let n=m(t,a);r[d]=n,i&&h&&h({action:u,location:n})},go(t){u=e.Action.Pop,d=f(d+t),h&&h({action:u,location:p()})},listen:e=>(h=e,()=>{h=null})}},e.createPath=l,e.createRouter=function(r){n(r.routes.length>0,"You must provide a non-empty routes array to createRouter");let a=f(r.routes),o=null,i=new Set,l=null,c=null,u=null,m=null!=r.hydrationData,g=p(a,r.history.location,r.basename),v=null;if(null==g){let e=ie(404,{pathname:r.history.location.pathname}),{matches:t,route:n}=oe(a);g=t,v={[n.id]:e}}let y,w,b=!g.some((e=>e.route.loader))||null!=r.hydrationData,D={historyAction:r.history.action,location:r.history.location,matches:g,initialized:b,navigation:B,restoreScrollPosition:null==r.hydrationData&&null,preventScrollReset:!1,revalidation:"idle",loaderData:r.hydrationData&&r.hydrationData.loaderData||{},actionData:r.hydrationData&&r.hydrationData.actionData||null,errors:r.hydrationData&&r.hydrationData.errors||v,fetchers:new Map},A=e.Action.Pop,E=!1,R=!1,P=!1,M=[],C=[],S=new Map,x=0,L=-1,T=new Map,j=new Set,O=new Map,_=new Map;function U(e){D=t({},D,e),i.forEach((e=>e(D)))}function H(a,n){var o;let i,s=null!=D.actionData&&null!=D.navigation.formMethod&&me(D.navigation.formMethod)&&"loading"===D.navigation.state&&!0!==(null==(o=a.state)?void 0:o._isRedirect);i=n.actionData?Object.keys(n.actionData).length>0?n.actionData:null:s?D.actionData:null,U(t({},n,{actionData:i,loaderData:n.loaderData?ae(D.loaderData,n.loaderData,n.matches||[],n.errors):D.loaderData,historyAction:A,location:a,initialized:!0,navigation:B,revalidation:"idle",restoreScrollPosition:!D.navigation.formData&&le(a,n.matches||D.matches),preventScrollReset:E})),R||A===e.Action.Pop||(A===e.Action.Push?r.history.push(a,a.state):A===e.Action.Replace&&r.history.replace(a,a.state)),A=e.Action.Pop,E=!1,R=!1,P=!1,M=[],C=[]}async function F(o,i,s){w&&w.abort(),w=null,A=o,R=!0===(s&&s.startUninterruptedRevalidation),function(e,t){if(l&&c&&u){let r=t.map((e=>we(e,D.loaderData))),a=c(e,r)||e.key;l[a]=u()}}(D.location,D.matches),E=!0===(s&&s.preventScrollReset);let d=s&&s.overrideNavigation,f=p(a,i,r.basename);if(!f){let e=ie(404,{pathname:i.pathname}),{matches:t,route:r}=oe(a);return te(),void H(i,{matches:t,loaderData:{},errors:{[r.id]:e}})}if(m=D.location,g=i,m.pathname===g.pathname&&m.search===g.search&&m.hash!==g.hash)return void H(i,{matches:f});var m,g;w=new AbortController;let v,b,T=Z(i,w.signal,s&&s.submission);if(s&&s.pendingError)b={[ne(f).route.id]:s.pendingError};else if(s&&s.submission&&me(s.submission.formMethod)){let r=await async function(r,a,n,o,i){let s;W(),U({navigation:t({state:"submitting",location:a},n)});let l=be(o,a);if(l.route.action){if(s=await Q("action",r,l,o,y.basename),r.signal.aborted)return{shortCircuited:!0}}else s={type:h.error,error:ie(405,{method:r.method,pathname:a.pathname,routeId:l.route.id})};if(ue(s)){let e;return e=i&&null!=i.replace?i.replace:s.location===D.location.pathname+D.location.search,await q(D,s,{submission:n,replace:e}),{shortCircuited:!0}}if(de(s)){let t=ne(o,l.route.id);return!0!==(i&&i.replace)&&(A=e.Action.Push),{pendingActionData:{},pendingActionError:{[t.route.id]:s.error}}}if(ce(s))throw new Error("defer() is not supported in actions");return{pendingActionData:{[l.route.id]:s.data}}}(T,i,s.submission,f,{replace:s.replace});if(r.shortCircuited)return;v=r.pendingActionData,b=r.pendingActionError,d=t({state:"loading",location:i},s.submission),T=new Request(T.url,{signal:T.signal})}let{shortCircuited:F,loaderData:k,errors:$}=await async function(e,r,a,o,i,s,l,c){let d=o;if(!d){d=t({state:"loading",location:r,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},i)}let u=i||(d.formMethod&&d.formAction&&d.formData&&d.formEncType?{formMethod:d.formMethod,formAction:d.formAction,formData:d.formData,formEncType:d.formEncType}:void 0),[h,f]=G(D,a,u,r,P,M,C,l,c,O);if(te((e=>!(a&&a.some((t=>t.route.id===e)))||h&&h.some((t=>t.route.id===e)))),0===h.length&&0===f.length)return H(r,t({matches:a,loaderData:{},errors:c||null},l?{actionData:l}:{})),{shortCircuited:!0};if(!R){f.forEach((e=>{let[t]=e,r=D.fetchers.get(t),a={state:"loading",data:r&&r.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(t,a)}));let e=l||D.actionData;U(t({navigation:d},e?0===Object.keys(e).length?{actionData:null}:{actionData:e}:{},f.length>0?{fetchers:new Map(D.fetchers)}:{}))}L=++x,f.forEach((e=>{let[t]=e;return S.set(t,w)}));let{results:p,loaderResults:m,fetcherResults:g}=await I(D.matches,a,h,f,e);if(e.signal.aborted)return{shortCircuited:!0};f.forEach((e=>{let[t]=e;return S.delete(t)}));let v=se(p);if(v)return await q(D,v,{replace:s}),{shortCircuited:!0};let{loaderData:y,errors:b}=re(D,a,h,m,c,f,g,_);_.forEach(((e,t)=>{e.subscribe((r=>{(r||e.done)&&_.delete(t)}))})),function(){let e=[];for(let t of j){let r=D.fetchers.get(t);n(r,"Expected fetcher: "+t),"loading"===r.state&&(j.delete(t),e.push(t))}X(e)}();let A=ee(L);return t({loaderData:y,errors:b},A||f.length>0?{fetchers:new Map(D.fetchers)}:{})}(T,i,f,d,s&&s.submission,s&&s.replace,v,b);F||(w=null,H(i,t({matches:f},v?{actionData:v}:{},{loaderData:k,errors:$})))}function k(e){return D.fetchers.get(e)||z}async function q(r,a,o){var i;let{submission:l,replace:c,isFetchActionRedirect:u}=void 0===o?{}:o;a.revalidate&&(P=!0);let h=s(r.location,a.location,t({_isRedirect:!0},u?{_isFetchActionRedirect:!0}:{}));if(n(h,"Expected a location on the redirect navigation"),void 0!==(null==(i=window)?void 0:i.location)){let e=d(a.location).origin;if(window.location.origin!==e)return void(c?window.location.replace(a.location):window.location.assign(a.location))}w=null;let f=!0===c?e.Action.Replace:e.Action.Push,{formMethod:p,formAction:m,formEncType:g,formData:v}=r.navigation;!l&&p&&m&&v&&g&&(l={formMethod:p,formAction:m,formEncType:g,formData:v}),N.has(a.status)&&l&&me(l.formMethod)?await F(f,h,{submission:t({},l,{formAction:a.location})}):await F(f,h,{overrideNavigation:{state:"loading",location:h,formMethod:l?l.formMethod:void 0,formAction:l?l.formAction:void 0,formEncType:l?l.formEncType:void 0,formData:l?l.formData:void 0}})}async function I(e,t,r,a,n){let o=await Promise.all([...r.map((e=>Q("loader",n,e,t,y.basename))),...a.map((e=>{let[,t,r,a]=e;return Q("loader",Z(t,n.signal),r,a,y.basename)}))]),i=o.slice(0,r.length),s=o.slice(r.length);return await Promise.all([ge(e,r,i,n.signal,!1,D.loaderData),ge(e,a.map((e=>{let[,,t]=e;return t})),s,n.signal,!0)]),{results:o,loaderResults:i,fetcherResults:s}}function W(){P=!0,M.push(...te()),O.forEach(((e,t)=>{S.has(t)&&(C.push(t),V(t))}))}function $(e,t,r){let a=ne(D.matches,t);J(e),U({errors:{[a.route.id]:r},fetchers:new Map(D.fetchers)})}function J(e){S.has(e)&&V(e),O.delete(e),T.delete(e),j.delete(e),D.fetchers.delete(e)}function V(e){let t=S.get(e);n(t,"Expected fetch controller: "+e),t.abort(),S.delete(e)}function X(e){for(let t of e){let e={state:"idle",data:k(t).data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(t,e)}}function ee(e){let t=[];for(let[r,a]of T)if(a<e){let e=D.fetchers.get(r);n(e,"Expected fetcher: "+r),"loading"===e.state&&(V(r),T.delete(r),t.push(r))}return X(t),t.length>0}function te(e){let t=[];return _.forEach(((r,a)=>{e&&!e(a)||(r.cancel(),t.push(a),_.delete(a))})),t}function le(e,t){if(l&&c&&u){let r=t.map((e=>we(e,D.loaderData))),a=c(e,r)||e.key,n=l[a];if("number"==typeof n)return n}return null}return y={get basename(){return r.basename},get state(){return D},get routes(){return a},initialize:function(){return o=r.history.listen((e=>{let{action:t,location:r}=e;return F(t,r)})),D.initialized||F(e.Action.Pop,D.location),y},subscribe:function(e){return i.add(e),()=>i.delete(e)},enableScrollRestoration:function(e,t,r){if(l=e,u=t,c=r||(e=>e.key),!m&&D.navigation===B){m=!0;let e=le(D.location,D.matches);null!=e&&U({restoreScrollPosition:e})}return()=>{l=null,u=null,c=null}},navigate:async function(a,n){if("number"==typeof a)return void r.history.go(a);let{path:o,submission:i,error:l}=Y(a,n),c=s(D.location,o,n&&n.state);c=t({},c,r.history.encodeLocation(c));let d=n&&null!=n.replace?n.replace:void 0,u=e.Action.Push;!0===d?u=e.Action.Replace:!1===d||null!=i&&me(i.formMethod)&&i.formAction===D.location.pathname+D.location.search&&(u=e.Action.Replace);let h=n&&"preventScrollReset"in n?!0===n.preventScrollReset:void 0;return await F(u,c,{submission:i,pendingError:l,preventScrollReset:h,replace:n&&n.replace})},fetch:function(e,o,i,s){if(K)throw new Error("router.fetch() was called during the server render, but it shouldn't be. You are likely calling a useFetcher() method in the body of your component. Try moving it to a useEffect or a callback.");S.has(e)&&V(e);let l=p(a,i,r.basename);if(!l)return void $(e,o,ie(404,{pathname:i}));let{path:c,submission:d}=Y(i,s,!0),u=be(l,c);d&&me(d.formMethod)?async function(e,o,i,s,l,c){if(W(),O.delete(e),!s.route.action){let t=ie(405,{method:c.formMethod,pathname:i,routeId:o});return void $(e,o,t)}let d=D.fetchers.get(e),u=t({state:"submitting"},c,{data:d&&d.data," _hasFetcherDoneAnything ":!0});D.fetchers.set(e,u),U({fetchers:new Map(D.fetchers)});let h=new AbortController,f=Z(i,h.signal,c);S.set(e,h);let m=await Q("action",f,s,l,y.basename);if(f.signal.aborted)return void(S.get(e)===h&&S.delete(e));if(ue(m)){S.delete(e),j.add(e);let r=t({state:"loading"},c,{data:void 0," _hasFetcherDoneAnything ":!0});return D.fetchers.set(e,r),U({fetchers:new Map(D.fetchers)}),q(D,m,{isFetchActionRedirect:!0})}if(de(m))return void $(e,o,m.error);ce(m)&&n(!1,"defer() is not supported in actions");let g=D.navigation.location||D.location,v=Z(g,h.signal),b="idle"!==D.navigation.state?p(a,D.navigation.location,r.basename):D.matches;n(b,"Didn't find any matches after fetcher action");let E=++x;T.set(e,E);let R=t({state:"loading",data:m.data},c,{" _hasFetcherDoneAnything ":!0});D.fetchers.set(e,R);let[F,k]=G(D,b,c,g,P,M,C,{[s.route.id]:m.data},void 0,O);k.filter((t=>{let[r]=t;return r!==e})).forEach((e=>{let[t]=e,r=D.fetchers.get(t),a={state:"loading",data:r&&r.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(t,a),S.set(t,h)})),U({fetchers:new Map(D.fetchers)});let{results:N,loaderResults:B,fetcherResults:z}=await I(D.matches,b,F,k,v);if(h.signal.aborted)return;T.delete(e),S.delete(e),k.forEach((e=>{let[t]=e;return S.delete(t)}));let K=se(N);if(K)return q(D,K);let{loaderData:Y,errors:J}=re(D,D.matches,F,B,void 0,k,z,_),V={state:"idle",data:m.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(e,V);let X=ee(E);"loading"===D.navigation.state&&E>L?(n(A,"Expected pending action"),w&&w.abort(),H(D.navigation.location,{matches:b,loaderData:Y,errors:J,fetchers:new Map(D.fetchers)})):(U(t({errors:J,loaderData:ae(D.loaderData,Y,b,J)},X?{fetchers:new Map(D.fetchers)}:{})),P=!1)}(e,o,c,u,l,d):(O.set(e,[c,u,l]),async function(e,r,a,o,i,s){let l=D.fetchers.get(e),c=t({state:"loading",formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},s,{data:l&&l.data," _hasFetcherDoneAnything ":!0});D.fetchers.set(e,c),U({fetchers:new Map(D.fetchers)});let d=new AbortController,u=Z(a,d.signal);S.set(e,d);let h=await Q("loader",u,o,i,y.basename);ce(h)&&(h=await ve(h,u.signal,!0)||h);S.get(e)===d&&S.delete(e);if(u.signal.aborted)return;if(ue(h))return void await q(D,h);if(de(h)){let t=ne(D.matches,r);return D.fetchers.delete(e),void U({fetchers:new Map(D.fetchers),errors:{[t.route.id]:h.error}})}n(!ce(h),"Unhandled fetcher deferred data");let f={state:"idle",data:h.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(e,f),U({fetchers:new Map(D.fetchers)})}(e,o,c,u,l,d))},revalidate:function(){W(),U({revalidation:"loading"}),"submitting"!==D.navigation.state&&("idle"!==D.navigation.state?F(A||D.historyAction,D.navigation.location,{overrideNavigation:D.navigation}):F(D.historyAction,D.location,{startUninterruptedRevalidation:!0}))},createHref:e=>r.history.createHref(e),encodeLocation:e=>r.history.encodeLocation(e),getFetcher:k,deleteFetcher:J,dispose:function(){o&&o(),i.clear(),w&&w.abort(),D.fetchers.forEach(((e,t)=>J(t)))},_internalFetchControllers:S,_internalActiveDeferreds:_},y},e.createStaticHandler=function(e,r){n(e.length>0,"You must provide a non-empty routes array to createStaticHandler");let a=f(e),o=(r?r.basename:null)||"/";async function i(e,r,a,i,s){n(e.signal,"query()/queryRoute() requests must contain an AbortController signal");try{if(me(e.method.toLowerCase())){let n=await async function(e,r,a,n,i){let s;if(a.route.action){if(s=await Q("action",e,a,r,o,!0,i,n),e.signal.aborted){throw new Error((i?"queryRoute":"query")+"() call aborted")}}else{let t=ie(405,{method:e.method,pathname:new URL(e.url).pathname,routeId:a.route.id});if(i)throw t;s={type:h.error,error:t}}if(ue(s))throw new Response(null,{status:s.status,headers:{Location:s.location}});if(ce(s))throw new Error("defer() is not supported in actions");if(i){if(de(s))throw s.error;return{matches:[a],loaderData:{},actionData:{[a.route.id]:s.data},errors:null,statusCode:200,loaderHeaders:{},actionHeaders:{}}}if(de(s)){let o=ne(r,a.route.id);return t({},await c(e,r,n,void 0,{[o.route.id]:s.error}),{statusCode:F(s.error)?s.error.status:500,actionData:null,actionHeaders:t({},s.headers?{[a.route.id]:s.headers}:{})})}let l=new Request(e.url,{headers:e.headers,redirect:e.redirect,signal:e.signal});return t({},await c(l,r,n),s.statusCode?{statusCode:s.statusCode}:{},{actionData:{[a.route.id]:s.data},actionHeaders:t({},s.headers?{[a.route.id]:s.headers}:{})})}(e,a,s||be(a,r),i,null!=s);return n}let n=await c(e,a,i,s);return he(n)?n:t({},n,{actionData:null,actionHeaders:{}})}catch(e){if((l=e)&&he(l.response)&&(l.type===h.data||h.error)){if(e.type===h.error&&!fe(e.response))throw e.response;return e.response}if(fe(e))return e;throw e}var l}async function c(e,r,a,n,i){let s=null!=n;if(s&&(null==n||!n.route.loader))throw ie(400,{method:e.method,pathname:new URL(e.url).pathname,routeId:null==n?void 0:n.route.id});let l=(n?[n]:J(r,Object.keys(i||{})[0])).filter((e=>e.route.loader));if(0===l.length)return{matches:r,loaderData:r.reduce(((e,t)=>Object.assign(e,{[t.route.id]:null})),{}),errors:i||null,statusCode:200,loaderHeaders:{}};let c=await Promise.all([...l.map((t=>Q("loader",e,t,r,o,!0,s,a)))]);if(e.signal.aborted){throw new Error((s?"queryRoute":"query")+"() call aborted")}let d=new Set;c.forEach(((e,t)=>{d.add(l[t].route.id),ce(e)&&e.deferredData.cancel()}));let u=te(r,l,c,i);return r.forEach((e=>{d.has(e.route.id)||(u.loaderData[e.route.id]=null)})),t({},u,{matches:r})}return{dataRoutes:a,query:async function(e,r){let{requestContext:n}=void 0===r?{}:r,c=new URL(e.url),d=e.method.toLowerCase(),u=s("",l(c),null,"default"),h=p(a,u,o);if(!pe(d)&&"head"!==d){let e=ie(405,{method:d}),{matches:t,route:r}=oe(a);return{basename:o,location:u,matches:t,loaderData:{},actionData:null,errors:{[r.id]:e},statusCode:e.status,loaderHeaders:{},actionHeaders:{}}}if(!h){let e=ie(404,{pathname:u.pathname}),{matches:t,route:r}=oe(a);return{basename:o,location:u,matches:t,loaderData:{},actionData:null,errors:{[r.id]:e},statusCode:e.status,loaderHeaders:{},actionHeaders:{}}}let f=await i(e,u,h,n);return he(f)?f:t({location:u,basename:o},f)},queryRoute:async function(e,t){let{routeId:r,requestContext:n}=void 0===t?{}:t,c=new URL(e.url),d=e.method.toLowerCase(),u=s("",l(c),null,"default"),h=p(a,u,o);if(!pe(d)&&"head"!==d)throw ie(405,{method:d});if(!h)throw ie(404,{pathname:u.pathname});let f=r?h.find((e=>e.route.id===r)):be(h,u);if(r&&!f)throw ie(403,{pathname:u.pathname,routeId:r});if(!f)throw ie(404,{pathname:u.pathname});let m=await i(e,u,h,n,f);if(he(m))return m;let g=m.errors?Object.values(m.errors)[0]:void 0;if(void 0!==g)throw g;let v=[m.actionData,m.loaderData].find((e=>e));return Object.values(v||{})[0]}}},e.defer=function(e){return new _(e)},e.generatePath=function(e,t){void 0===t&&(t={});let r=e;return r.endsWith("*")&&"*"!==r&&!r.endsWith("/*")&&(R(!1,'Route path "'+r+'" will be treated as if it were "'+r.replace(/\*$/,"/*")+'" because the `*` character must always follow a `/` in the pattern. To get rid of this warning, please change the route path to "'+r.replace(/\*$/,"/*")+'".'),r=r.replace(/\*$/,"/*")),r.replace(/^:(\w+)/g,((e,r)=>(n(null!=t[r],'Missing ":'+r+'" param'),t[r]))).replace(/\/:(\w+)/g,((e,r)=>(n(null!=t[r],'Missing ":'+r+'" param'),"/"+t[r]))).replace(/(\/?)\*/,((e,r,a,n)=>null==t["*"]?"/*"===n?"/":"":""+r+t["*"]))},e.getStaticContextFromError=function(e,r,a){return t({},r,{statusCode:500,errors:{[r._deepestRenderedBoundaryId||e[0].id]:a}})},e.getToPathname=function(e){return""===e||""===e.pathname?"/":"string"==typeof e?c(e).pathname:e.pathname},e.invariant=n,e.isRouteErrorResponse=F,e.joinPaths=x,e.json=function(e,r){void 0===r&&(r={});let a="number"==typeof r?{status:r}:r,n=new Headers(a.headers);return n.has("Content-Type")||n.set("Content-Type","application/json; charset=utf-8"),new Response(JSON.stringify(e),t({},a,{headers:n}))},e.matchPath=D,e.matchRoutes=p,e.normalizePathname=L,e.parsePath=c,e.redirect=function(e,r){void 0===r&&(r=302);let a=r;"number"==typeof a?a={status:a}:void 0===a.status&&(a.status=302);let n=new Headers(a.headers);return n.set("Location",e),new Response(null,t({},a,{headers:n}))},e.resolvePath=P,e.resolveTo=S,e.stripBasename=E,e.warning=R,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
12
12
|
//# sourceMappingURL=router.umd.min.js.map
|