@remix-run/router
Advanced tools
Comparing version 0.0.0-experimental-f8cbf972 to 0.0.0-experimental-ff38e9e6
# `@remix-run/router` | ||
## 1.3.2 | ||
### Patch Changes | ||
- Remove inaccurate console warning for POP navigations and update active blocker logic ([#10030](https://github.com/remix-run/react-router/pull/10030)) | ||
- Only check for differing origin on absolute URL redirects ([#10033](https://github.com/remix-run/react-router/pull/10033)) | ||
## 1.3.1 | ||
@@ -4,0 +11,0 @@ |
@@ -7,2 +7,3 @@ export type { ActionFunction, ActionFunctionArgs, ActionFunctionWithMiddleware, ActionFunctionArgsWithMiddleware, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, TrackedPromise, FormEncType, FormMethod, JsonFunction, LoaderFunction, LoaderFunctionArgs, LoaderFunctionWithMiddleware, LoaderFunctionArgsWithMiddleware, MiddlewareContext, MiddlewareFunction, MiddlewareFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, Submission, } from "./utils"; | ||
/** @internal */ | ||
export { DeferredData as UNSAFE_DeferredData, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, createMiddlewareStore as UNSAFE_createMiddlewareStore, } from "./utils"; | ||
export type { InternalMiddlewareContext as UNSAFE_InternalMiddlewareContext } from "./utils"; | ||
export { DeferredData as UNSAFE_DeferredData, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, createMiddlewareStore as UNSAFE_createMiddlewareStore, getRouteAwareMiddlewareContext as UNSAFE_getRouteAwareMiddlewareContext, } from "./utils"; |
import type { History, Location, Path, To } from "./history"; | ||
import { Action as HistoryAction } from "./history"; | ||
import type { AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticRouteMatch, AgnosticRouteObject, FormEncType, FormMethod, MiddlewareContext, RouteData } from "./utils"; | ||
import type { AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticRouteMatch, AgnosticRouteObject, FormEncType, FormMethod, InternalMiddlewareContext, RouteData } from "./utils"; | ||
import { DeferredData } from "./utils"; | ||
@@ -245,3 +245,3 @@ /** | ||
hydrationData?: HydrationState; | ||
future?: FutureConfig; | ||
future?: Partial<FutureConfig>; | ||
} | ||
@@ -266,5 +266,9 @@ /** | ||
requestContext?: unknown; | ||
middlewareContext?: MiddlewareContext; | ||
} | ||
interface StaticHandlerQueryRouteOpts extends StaticHandlerQueryOpts { | ||
interface StaticHandlerQueryAndRenderOpts { | ||
middlewareContext?: InternalMiddlewareContext; | ||
} | ||
interface StaticHandlerQueryRouteOpts { | ||
requestContext?: unknown; | ||
middlewareContext?: InternalMiddlewareContext; | ||
routeId?: string; | ||
@@ -278,2 +282,3 @@ } | ||
query(request: Request, opts?: StaticHandlerQueryOpts): Promise<StaticHandlerContext | Response>; | ||
queryAndRender(request: Request, render: (context: StaticHandlerContext | Response) => Promise<Response>, opts?: StaticHandlerQueryAndRenderOpts): Promise<Response>; | ||
queryRoute(request: Request, opts?: StaticHandlerQueryRouteOpts): Promise<any>; | ||
@@ -280,0 +285,0 @@ } |
/** | ||
* @remix-run/router v0.0.0-experimental-f8cbf972 | ||
* @remix-run/router v0.0.0-experimental-ff38e9e6 | ||
* | ||
@@ -11,3 +11,3 @@ * Copyright (c) Remix Software Inc. | ||
*/ | ||
!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,t){return{usr:e.state,key:e.key,idx:t}}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(r,o,c,d){void 0===d&&(d={});let{window:u=document.defaultView,v5Compat:h=!1}=d,f=u.history,p=e.Action.Pop,m=null,g=v();function v(){return(f.state||{idx:null}).idx}function y(){p=e.Action.Pop;let t=v(),r=null==t?null:t-g;g=t,m&&m({action:p,location:b.location,delta:r})}function w(e){let t="null"!==u.location.origin?u.location.origin:u.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)}null==g&&(g=0,f.replaceState(t({},f.state,{idx:g}),""));let b={get action(){return p},get location(){return r(u,f)},listen(e){if(m)throw new Error("A history only accepts one active listener");return u.addEventListener(a,y),m=e,()=>{u.removeEventListener(a,y),m=null}},createHref:e=>o(u,e),createURL:w,encodeLocation(e){let t=w(e);return{pathname:t.pathname,search:t.search,hash:t.hash}},push:function(t,r){p=e.Action.Push;let a=s(b.location,t,r);c&&c(a,t),g=v()+1;let n=i(a,g),o=b.createHref(a);try{f.pushState(n,"",o)}catch(e){u.location.assign(o)}h&&m&&m({action:p,location:b.location,delta:1})},replace:function(t,r){p=e.Action.Replace;let a=s(b.location,t,r);c&&c(a,t),g=v();let n=i(a,g),o=b.createHref(a);f.replaceState(n,"",o),h&&m&&m({action:p,location:b.location,delta:0})},go:e=>f.go(e)};return b}let u;function h(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?h(e.children,i,a):void 0})}))}function f(e,t,r){void 0===r&&(r="/");let a=A(("string"==typeof t?c(t):t).pathname||"/",r);if(null==a)return null;let n=p(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=w(n[e],D(a));return o}function p(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+'".'),p(e.children,t,c,l)),(null!=e.path||e.index)&&t.push({path:l,score:y(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 m(e.path))o(e,t,r);else o(e,t)})),t}function m(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=m(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"}(u||(u={}));const g=/^:\w+$/,v=e=>"*"===e;function y(e,t){let r=e.split("/"),a=r.length;return r.some(v)&&(a+=-2),t&&(a+=2),r.filter((e=>!v(e))).reduce(((e,t)=>e+(g.test(t)?3:""===t?1:10)),a)}function w(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=b({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 b(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 D(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 A(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 E(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:k(a),hash:C(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 P(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=E(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(/^\/*/,"/"),k=e=>e&&"?"!==e?e.startsWith("?")?e:"?"+e:"",C=e=>e&&"#"!==e?e.startsWith("#")?e:"#"+e:"";class U extends Error{}class _{constructor(e,t){let r;this.pendingKeysSet=new Set,this.subscribers=new Set,this.deferredKeys=[],n(e&&"object"==typeof e&&!Array.isArray(e),"defer() only accepts plain objects"),this.abortPromise=new Promise(((e,t)=>r=t)),this.controller=new AbortController;let a=()=>r(new U("Deferred data aborted"));this.unlistenAbortSignal=()=>this.controller.signal.removeEventListener("abort",a),this.controller.signal.addEventListener("abort",a),this.data=Object.entries(e).reduce(((e,t)=>{let[r,a]=t;return Object.assign(e,{[r]:this.trackPromise(r,a)})}),{}),this.done&&this.unlistenAbortSignal(),this.init=t}trackPromise(e,t){if(!(t instanceof Promise))return t;this.deferredKeys.push(e),this.pendingKeysSet.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){return this.controller.signal.aborted&&r instanceof U?(this.unlistenAbortSignal(),Object.defineProperty(e,"_error",{get:()=>r}),Promise.reject(r)):(this.pendingKeysSet.delete(t),this.done&&this.unlistenAbortSignal(),r?(Object.defineProperty(e,"_error",{get:()=>r}),this.emit(!1,t),Promise.reject(r)):(Object.defineProperty(e,"_data",{get:()=>a}),this.emit(!1,t),a))}emit(e,t){this.subscribers.forEach((r=>r(e,t)))}subscribe(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}cancel(){this.controller.abort(),this.pendingKeysSet.forEach(((e,t)=>this.pendingKeysSet.delete(t))),this.emit(!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.pendingKeysSet.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]:T(a)})}),{})}get pendingKeys(){return Array.from(this.pendingKeysSet)}}function T(e){if(!function(e){return e instanceof Promise&&!0===e._tracked}(e))return e;if(e._error)throw e._error;return e._data}class j{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 O(e){return null!=e&&"number"==typeof e.status&&"string"==typeof e.statusText&&"boolean"==typeof e.internal&&"data"in e}class F{constructor(e){void 0!==e&&(this.defaultValue=e)}getDefaultValue(){if(void 0===this.defaultValue)throw new Error("Unable to find a value in the middleware context");return this.defaultValue}}function H(e){let t=new Map(null==e?void 0:e.entries());return{get:e=>t.has(e)?t.get(e):e.getDefaultValue(),set(e,r){if(void 0===r)throw new Error("You cannot set an undefined value in the middleware context");t.set(e,r)},next:()=>{},entries:()=>t.entries()}}const I={unstable_middleware:!1},q=["post","put","patch","delete"],W=new Set(q),$=["get",...q],N=new Set($),B=new Set([301,302,303,307,308]),z=new Set([307,308]),K={state:"idle",location:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},Y={state:"idle",data:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},V={state:"unblocked",proceed:void 0,reset:void 0,location:void 0},J=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,G="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,X=!G;const Q=Symbol("deferred");function Z(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&&!Re(t.formMethod))return{path:n,error:me(405,{method:t.formMethod})};if(t.formData&&(a={formMethod:t.formMethod||"get",formAction:ve(n),formEncType:t&&t.formEncType||"application/x-www-form-urlencoded",formData:t.formData},Ee(a.formMethod)))return{path:n,submission:a};let o=c(n),i=ce(t.formData);return r&&o.search&&Se(o.search)&&i.append("index",""),o.search="?"+i,{path:l(o),submission:a}}function ee(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 te(e,r,a,n,o,i,s,l,c,d,u){let h=d?Object.values(d)[0]:c?Object.values(c)[0]:void 0,f=e.createURL(r.location),p=e.createURL(o),m=i||f.toString()===p.toString()||f.search!==p.search,g=d?Object.keys(d)[0]:void 0,v=ee(a,g).filter(((e,a)=>{if(null==e.route.loader)return!1;if(function(e,t,r){let a=!t||r.route.id!==t.route.id,n=void 0===e[r.route.id];return a||n}(r.loaderData,r.matches[a],e)||s.some((t=>t===e.route.id)))return!0;let o=r.matches[a],i=e;return ae(e,t({currentUrl:f,currentParams:o.params,nextUrl:p,nextParams:i.params},n,{actionResult:h,defaultShouldRevalidate:m||re(o,i)}))})),y=[];return u&&u.forEach(((e,o)=>{if(a.some((t=>t.route.id===e.routeId)))if(l.includes(o))y.push(t({key:o},e));else{ae(e.match,t({currentUrl:f,currentParams:r.matches[r.matches.length-1].params,nextUrl:p,nextParams:a[a.length-1].params},n,{actionResult:h,defaultShouldRevalidate:m}))&&y.push(t({key:o},e))}})),[v,y]}function re(e,t){let r=e.route.path;return e.pathname!==t.pathname||null!=r&&r.endsWith("*")&&e.params["*"]!==t.params["*"]}function ae(e,t){if(e.route.shouldRevalidate){let r=e.route.shouldRevalidate(t);if("boolean"==typeof r)return r}return t.defaultShouldRevalidate}async function ne(e,t,r,a,n){if(e.signal.aborted)throw new Error("Request aborted");if(0===t.length)return a.next=()=>{throw new Error("You may only call `next()` once per middleware and you may not call it in an action or loader")},n({request:e,params:r,context:a});let o=!1,i=()=>(o=!0,ne(e,t.slice(1),r,a,n));if(!t[0].route.middleware)return i();a.next=i;let s=await t[0].route.middleware({request:e,params:r,context:a});return o?s:i()}function oe(){throw new Error("Middleware must be enabled via the `future.unstable_middleware` flag)")}const ie={get:oe,set:oe,next:oe};async function se(e,t,r,a,o,i,s,c,d,h){let f,p,m;void 0===o&&(o="/"),void 0===s&&(s=!1),void 0===c&&(c=!1);let g=new Promise(((e,t)=>m=t)),v=()=>m();t.signal.addEventListener("abort",v);try{let o=r.route[e];n(o,"Could not find the "+e+' to run on the "'+r.route.id+'" route');let s,l=a.findIndex((e=>e.route.id===r.route.id));s=i?ne(t,a.slice(0,l+1),a[0].params,H(h),o):o({request:t,params:r.params,context:d||ie}),p=await Promise.race([s,g]),n(void 0!==p,"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){f=u.error,p=e}finally{t.signal.removeEventListener("abort",v)}if(De(p)){let e,i=p.status;if(B.has(i)){let e=p.headers.get("Location");if(n(e,"Redirects returned/thrown from loaders/actions must have a Location header"),J.test(e)){if(!s){let r=new URL(t.url),a=e.startsWith("//")?new URL(r.protocol+e):new URL(e);a.origin===r.origin&&(e=a.pathname+a.search+a.hash)}}else{let i=S(e,P(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(s)throw p.headers.set("Location",e),p;return{type:u.redirect,status:i,location:e,revalidate:null!==p.headers.get("X-Remix-Revalidate")}}if(c)throw{type:f||u.data,response:p};let d=p.headers.get("Content-Type");return e=d&&/\bapplication\/json\b/.test(d)?await p.json():await p.text(),f===u.error?{type:f,error:new j(i,p.statusText,e),headers:p.headers}:{type:u.data,data:e,statusCode:p.status,headers:p.headers}}return f===u.error?{type:f,error:p}:p instanceof _?{type:u.deferred,deferredData:p}:{type:u.data,data:p}}function le(e,t,r,a){let n=e.createURL(ve(t)).toString(),o={signal:r};if(a&&Ee(a.formMethod)){let{formMethod:e,formEncType:t,formData:r}=a;o.method=e.toUpperCase(),o.body="application/x-www-form-urlencoded"===t?ce(r):r}return new Request(n,o)}function ce(e){let t=new URLSearchParams;for(let[r,a]of e.entries())t.append(r,a instanceof File?a.name:a);return t}function de(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(!be(r),"Cannot handle redirect results in processLoaderData"),we(r)){let t=fe(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=O(r.error)?r.error.status:500),r.headers&&(d[h]=r.headers)}else ye(r)?(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 ue(e,r,a,o,i,s,l,c){let{loaderData:d,errors:u}=de(r,a,o,i,c);for(let r=0;r<s.length;r++){let{key:a,match:o}=s[r];n(void 0!==l&&void 0!==l[r],"Did not find corresponding fetcher result");let i=l[r];if(we(i)){let r=fe(e.matches,o.route.id);u&&u[r.route.id]||(u=t({},u,{[r.route.id]:i.error})),e.fetchers.delete(a)}else if(be(i))n(!1,"Unhandled fetcher revalidation redirect");else if(ye(i))n(!1,"Unhandled fetcher deferred data");else{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 he(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 fe(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 pe(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 me(e,t){let{pathname:r,routeId:a,method:n,type:o}=void 0===t?{}:t,i="Unknown Server Error",s="Unknown @remix-run/router error";return 400===e?(i="Bad Request",n&&r&&a?s="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.':"defer-action"===o&&(s="defer() is not supported in actions")):403===e?(i="Forbidden",s='Route "'+a+'" does not match URL "'+r+'"'):404===e?(i="Not Found",s='No route matches URL "'+r+'"'):405===e&&(i="Method Not Allowed",n&&r&&a?s="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&&(s='Invalid request method "'+n.toUpperCase()+'"')),new j(e||500,i,new Error(s),!0)}function ge(e){for(let t=e.length-1;t>=0;t--){let r=e[t];if(be(r))return r}}function ve(e){return l(t({},"string"==typeof e?c(e):e,{hash:""}))}function ye(e){return e.type===u.deferred}function we(e){return e.type===u.error}function be(e){return(e&&e.type)===u.redirect}function De(e){return null!=e&&"number"==typeof e.status&&"string"==typeof e.statusText&&"object"==typeof e.headers&&void 0!==e.body}function Ae(e){if(!De(e))return!1;let t=e.status,r=e.headers.get("Location");return t>=300&&t<=399&&null!=r}function Re(e){return N.has(e)}function Ee(e){return W.has(e)}async function Me(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&&!re(c,l)&&void 0!==(o&&o[l.route.id]);ye(s)&&(n||d)&&await Pe(s,a,n).then((e=>{e&&(r[i]=e||r[i])}))}}async function Pe(e,t,r){if(void 0===r&&(r=!1),!await e.deferredData.resolveData(t)){if(r)try{return{type:u.data,data:e.deferredData.unwrappedData}}catch(e){return{type:u.error,error:e}}return{type:u.data,data:e.deferredData.data}}}function Se(e){return new URLSearchParams(e).getAll("index").some((e=>""===e))}function xe(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 Le(e,t){let r="string"==typeof t?c(t).search:t.search;if(e[e.length-1].route.index&&Se(r||""))return e[e.length-1];let a=P(e);return a[a.length-1]}e.AbortedDeferredError=U,e.ErrorResponse=j,e.IDLE_BLOCKER=V,e.IDLE_FETCHER=Y,e.IDLE_NAVIGATION=K,e.UNSAFE_DEFERRED_SYMBOL=Q,e.UNSAFE_DeferredData=_,e.UNSAFE_convertRoutesToDataRoutes=h,e.UNSAFE_createMiddlewareStore=H,e.UNSAFE_getPathContributingMatches=P,e.createBrowserHistory=function(e){return void 0===e&&(e={}),d((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={}),d((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}function g(e){return"string"==typeof e?e:l(e)}return{get index(){return d},get action(){return u},get location(){return p()},createHref:g,createURL:e=>new URL(g(e),"http://localhost"),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,delta:1})},replace(t,a){u=e.Action.Replace;let n=m(t,a);r[d]=n,i&&h&&h({action:u,location:n,delta:0})},go(t){u=e.Action.Pop;let a=f(d+t),n=r[a];d=a,h&&h({action:u,location:n,delta:t})},listen:e=>(h=e,()=>{h=null})}},e.createMiddlewareContext=function(e){return new F(e)},e.createPath=l,e.createRouter=function(r){n(r.routes.length>0,"You must provide a non-empty routes array to createRouter");let a=h(r.routes),o=t({},I,r.future),i=null,l=new Set,c=null,d=null,p=null,m=null!=r.hydrationData,g=f(a,r.history.location,r.basename),v=null;if(null==g){let e=me(404,{pathname:r.history.location.pathname}),{matches:t,route:n}=pe(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:K,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,blockers:new Map},A=e.Action.Pop,E=!1,M=!1,P=!1,S=[],x=[],L=new Map,k=0,C=-1,U=new Map,_=new Set,T=new Map,j=new Map,O=new Map,F=!1;function H(e){D=t({},D,e),l.forEach((e=>e(D)))}function q(a,n){var o,i;let s,l=null!=D.actionData&&null!=D.navigation.formMethod&&Ee(D.navigation.formMethod)&&"loading"===D.navigation.state&&!0!==(null==(o=a.state)?void 0:o._isRedirect);s=n.actionData?Object.keys(n.actionData).length>0?n.actionData:null:l?D.actionData:null;let c=n.loaderData?he(D.loaderData,n.loaderData,n.matches||[],n.errors):D.loaderData;for(let[e]of O)ie(e);let d=!0===E||null!=D.navigation.formMethod&&Ee(D.navigation.formMethod)&&!0!==(null==(i=a.state)?void 0:i._isRedirect);H(t({},n,{actionData:s,loaderData:c,historyAction:A,location:a,initialized:!0,navigation:K,revalidation:"idle",restoreScrollPosition:De(a,n.matches||D.matches),preventScrollReset:d,blockers:new Map(D.blockers)})),M||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,M=!1,P=!1,S=[],x=[]}async function W(i,s,l){w&&w.abort(),w=null,A=i,M=!0===(l&&l.startUninterruptedRevalidation),function(e,t){if(c&&d&&p){let r=t.map((e=>xe(e,D.loaderData))),a=d(e,r)||e.key;c[a]=p()}}(D.location,D.matches),E=!0===(l&&l.preventScrollReset);let h=l&&l.overrideNavigation,m=f(a,s,r.basename);if(!m){let e=me(404,{pathname:s.pathname}),{matches:t,route:r}=pe(a);return ve(),void q(s,{matches:t,loaderData:{},errors:{[r.id]:e}})}if(!(g=D.location,v=s,g.pathname!==v.pathname||g.search!==v.search||g.hash===v.hash||l&&l.submission&&Ee(l.submission.formMethod)))return void q(s,{matches:m});var g,v;w=new AbortController;let b,R,U=le(r.history,s,w.signal,l&&l.submission);if(l&&l.pendingError)R={[fe(m).route.id]:l.pendingError};else if(l&&l.submission&&Ee(l.submission.formMethod)){let r=await async function(r,a,n,i,s){let l;Q(),H({navigation:t({state:"submitting",location:a},n)});let c=Le(i,a);if(c.route.action){if(l=await se("action",r,c,i,y.basename,o.unstable_middleware),r.signal.aborted)return{shortCircuited:!0}}else l={type:u.error,error:me(405,{method:r.method,pathname:a.pathname,routeId:c.route.id})};if(be(l)){let e;return e=s&&null!=s.replace?s.replace:l.location===D.location.pathname+D.location.search,await N(D,l,{submission:n,replace:e}),{shortCircuited:!0}}if(we(l)){let t=fe(i,c.route.id);return!0!==(s&&s.replace)&&(A=e.Action.Push),{pendingActionData:{},pendingActionError:{[t.route.id]:l.error}}}if(ye(l))throw me(400,{type:"defer-action"});return{pendingActionData:{[c.route.id]:l.data}}}(U,s,l.submission,m,{replace:l.replace});if(r.shortCircuited)return;b=r.pendingActionData,R=r.pendingActionError,h=t({state:"loading",location:s},l.submission),U=new Request(U.url,{signal:U.signal})}let{shortCircuited:O,loaderData:F,errors:I}=await async function(e,a,o,i,s,l,c,d){let u=i;if(!u){u=t({state:"loading",location:a,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},s)}let h=s||(u.formMethod&&u.formAction&&u.formData&&u.formEncType?{formMethod:u.formMethod,formAction:u.formAction,formData:u.formData,formEncType:u.formEncType}:void 0),[f,p]=te(r.history,D,o,h,a,P,S,x,c,d,T);if(ve((e=>!(o&&o.some((t=>t.route.id===e)))||f&&f.some((t=>t.route.id===e)))),0===f.length&&0===p.length)return q(a,t({matches:o,loaderData:{},errors:d||null},c?{actionData:c}:{})),{shortCircuited:!0};if(!M){p.forEach((e=>{let t=D.fetchers.get(e.key),r={state:"loading",data:t&&t.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(e.key,r)}));let e=c||D.actionData;H(t({navigation:u},e?0===Object.keys(e).length?{actionData:null}:{actionData:e}:{},p.length>0?{fetchers:new Map(D.fetchers)}:{}))}C=++k,p.forEach((e=>L.set(e.key,w)));let{results:m,loaderResults:g,fetcherResults:v}=await B(D.matches,o,f,p,e);if(e.signal.aborted)return{shortCircuited:!0};p.forEach((e=>L.delete(e.key)));let y=ge(m);if(y)return await N(D,y,{replace:l}),{shortCircuited:!0};let{loaderData:b,errors:A}=ue(D,o,f,g,d,p,v,j);j.forEach(((e,t)=>{e.subscribe((r=>{(r||e.done)&&j.delete(t)}))})),function(){let e=[];for(let t of _){let r=D.fetchers.get(t);n(r,"Expected fetcher: "+t),"loading"===r.state&&(_.delete(t),e.push(t))}ne(e)}();let R=oe(C);return t({loaderData:b,errors:A},R||p.length>0?{fetchers:new Map(D.fetchers)}:{})}(U,s,m,h,l&&l.submission,l&&l.replace,b,R);O||(w=null,q(s,t({matches:m},b?{actionData:b}:{},{loaderData:F,errors:I})))}function $(e){return D.fetchers.get(e)||Y}async function N(a,o,i){var l;let{submission:c,replace:d,isFetchActionRedirect:u}=void 0===i?{}:i;o.revalidate&&(P=!0);let h=s(a.location,o.location,t({_isRedirect:!0},u?{_isFetchActionRedirect:!0}:{}));if(n(h,"Expected a location on the redirect navigation"),J.test(o.location)&&G&&void 0!==(null==(l=window)?void 0:l.location)){let e=r.history.createURL(o.location).origin;if(window.location.origin!==e)return void(d?window.location.replace(o.location):window.location.assign(o.location))}w=null;let f=!0===d?e.Action.Replace:e.Action.Push,{formMethod:p,formAction:m,formEncType:g,formData:v}=a.navigation;!c&&p&&m&&v&&g&&(c={formMethod:p,formAction:m,formEncType:g,formData:v}),z.has(o.status)&&c&&Ee(c.formMethod)?await W(f,h,{submission:t({},c,{formAction:o.location}),preventScrollReset:E}):await W(f,h,{overrideNavigation:{state:"loading",location:h,formMethod:c?c.formMethod:void 0,formAction:c?c.formAction:void 0,formEncType:c?c.formEncType:void 0,formData:c?c.formData:void 0},preventScrollReset:E})}async function B(e,t,a,n,i){let s=await Promise.all([...a.map((e=>se("loader",i,e,t,y.basename,o.unstable_middleware))),...n.map((e=>se("loader",le(r.history,e.path,i.signal),e.match,e.matches,y.basename,o.unstable_middleware)))]),l=s.slice(0,a.length),c=s.slice(a.length);return await Promise.all([Me(e,a,l,i.signal,!1,D.loaderData),Me(e,n.map((e=>e.match)),c,i.signal,!0)]),{results:s,loaderResults:l,fetcherResults:c}}function Q(){P=!0,S.push(...ve()),T.forEach(((e,t)=>{L.has(t)&&(x.push(t),ae(t))}))}function ee(e,t,r){let a=fe(D.matches,t);re(e),H({errors:{[a.route.id]:r},fetchers:new Map(D.fetchers)})}function re(e){L.has(e)&&ae(e),T.delete(e),U.delete(e),_.delete(e),D.fetchers.delete(e)}function ae(e){let t=L.get(e);n(t,"Expected fetch controller: "+e),t.abort(),L.delete(e)}function ne(e){for(let t of e){let e={state:"idle",data:$(t).data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(t,e)}}function oe(e){let t=[];for(let[r,a]of U)if(a<e){let e=D.fetchers.get(r);n(e,"Expected fetcher: "+r),"loading"===e.state&&(ae(r),U.delete(r),t.push(r))}return ne(t),t.length>0}function ie(e){D.blockers.delete(e),O.delete(e)}function ce(e,t){let r=D.blockers.get(e)||V;n("unblocked"===r.state&&"blocked"===t.state||"blocked"===r.state&&"blocked"===t.state||"blocked"===r.state&&"proceeding"===t.state||"blocked"===r.state&&"unblocked"===t.state||"proceeding"===r.state&&"unblocked"===t.state,"Invalid blocker state transition: "+r.state+" -> "+t.state),D.blockers.set(e,t),H({blockers:new Map(D.blockers)})}function de(e){let{currentLocation:t,nextLocation:r,historyAction:a}=e;if(0===O.size)return;O.size>1&&R(!1,"A router only supports one blocker at a time");let n=Array.from(O.entries()),[o,i]=n[n.length-1],s=D.blockers.get(o);return s&&"proceeding"===s.state?void 0:i({currentLocation:t,nextLocation:r,historyAction:a})?o:void 0}function ve(e){let t=[];return j.forEach(((r,a)=>{e&&!e(a)||(r.cancel(),t.push(a),j.delete(a))})),t}function De(e,t){if(c&&d&&p){let r=t.map((e=>xe(e,D.loaderData))),a=d(e,r)||e.key,n=c[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 i=r.history.listen((e=>{let{action:t,location:a,delta:n}=e;if(F)return void(F=!1);R(0===O.size||null!=n,"You are trying to use a blocker on a POP navigation to a location that was not created by @remix-run/router. This will fail silently in production. This can happen if you are navigating outside the router via `window.history.pushState`/`window.location.hash` instead of using router navigation APIs. This can also happen if you are using createHashRouter and the user manually changes the URL.");let o=de({currentLocation:D.location,nextLocation:a,historyAction:t});return o&&null!=n?(F=!0,r.history.go(-1*n),void ce(o,{state:"blocked",location:a,proceed(){ce(o,{state:"proceeding",proceed:void 0,reset:void 0,location:a}),r.history.go(n)},reset(){ie(o),H({blockers:new Map(y.state.blockers)})}})):W(t,a)})),D.initialized||W(e.Action.Pop,D.location),y},subscribe:function(e){return l.add(e),()=>l.delete(e)},enableScrollRestoration:function(e,t,r){if(c=e,p=t,d=r||(e=>e.key),!m&&D.navigation===K){m=!0;let e=De(D.location,D.matches);null!=e&&H({restoreScrollPosition:e})}return()=>{c=null,p=null,d=null}},navigate:async function a(n,o){if("number"==typeof n)return void r.history.go(n);let{path:i,submission:l,error:c}=Z(n,o),d=D.location,u=s(D.location,i,o&&o.state);u=t({},u,r.history.encodeLocation(u));let h=o&&null!=o.replace?o.replace:void 0,f=e.Action.Push;!0===h?f=e.Action.Replace:!1===h||null!=l&&Ee(l.formMethod)&&l.formAction===D.location.pathname+D.location.search&&(f=e.Action.Replace);let p=o&&"preventScrollReset"in o?!0===o.preventScrollReset:void 0,m=de({currentLocation:d,nextLocation:u,historyAction:f});if(!m)return await W(f,u,{submission:l,pendingError:c,preventScrollReset:p,replace:o&&o.replace});ce(m,{state:"blocked",location:u,proceed(){ce(m,{state:"proceeding",proceed:void 0,reset:void 0,location:u}),a(n,o)},reset(){ie(m),H({blockers:new Map(D.blockers)})}})},fetch:function(e,i,s,l){if(X)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.");L.has(e)&&ae(e);let c=f(a,s,r.basename);if(!c)return void ee(e,i,me(404,{pathname:s}));let{path:d,submission:u}=Z(s,l,!0),h=Le(c,d);return E=!0===(l&&l.preventScrollReset),u&&Ee(u.formMethod)?async function(e,i,s,l,c,d){if(Q(),T.delete(e),!l.route.action){let t=me(405,{method:d.formMethod,pathname:s,routeId:i});return void ee(e,i,t)}let u=D.fetchers.get(e),h=t({state:"submitting"},d,{data:u&&u.data," _hasFetcherDoneAnything ":!0});D.fetchers.set(e,h),H({fetchers:new Map(D.fetchers)});let p=new AbortController,m=le(r.history,s,p.signal,d);L.set(e,p);let g=await se("action",m,l,c,y.basename,o.unstable_middleware);if(m.signal.aborted)return void(L.get(e)===p&&L.delete(e));if(be(g)){L.delete(e),_.add(e);let r=t({state:"loading"},d,{data:void 0," _hasFetcherDoneAnything ":!0});return D.fetchers.set(e,r),H({fetchers:new Map(D.fetchers)}),N(D,g,{isFetchActionRedirect:!0})}if(we(g))return void ee(e,i,g.error);if(ye(g))throw me(400,{type:"defer-action"});let v=D.navigation.location||D.location,b=le(r.history,v,p.signal),R="idle"!==D.navigation.state?f(a,D.navigation.location,r.basename):D.matches;n(R,"Didn't find any matches after fetcher action");let E=++k;U.set(e,E);let M=t({state:"loading",data:g.data},d,{" _hasFetcherDoneAnything ":!0});D.fetchers.set(e,M);let[O,F]=te(r.history,D,R,d,v,P,S,x,{[l.route.id]:g.data},void 0,T);F.filter((t=>t.key!==e)).forEach((e=>{let t=e.key,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),L.set(t,p)})),H({fetchers:new Map(D.fetchers)});let{results:I,loaderResults:W,fetcherResults:$}=await B(D.matches,R,O,F,b);if(p.signal.aborted)return;U.delete(e),L.delete(e),F.forEach((e=>L.delete(e.key)));let z=ge(I);if(z)return N(D,z);let{loaderData:K,errors:Y}=ue(D,D.matches,O,W,void 0,F,$,j),V={state:"idle",data:g.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(e,V);let J=oe(E);"loading"===D.navigation.state&&E>C?(n(A,"Expected pending action"),w&&w.abort(),q(D.navigation.location,{matches:R,loaderData:K,errors:Y,fetchers:new Map(D.fetchers)})):(H(t({errors:Y,loaderData:he(D.loaderData,K,R,Y)},J?{fetchers:new Map(D.fetchers)}:{})),P=!1)}(e,i,d,h,c,u):(T.set(e,{routeId:i,path:d,match:h,matches:c}),async function(e,a,i,s,l,c){let d=D.fetchers.get(e),u=t({state:"loading",formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},c,{data:d&&d.data," _hasFetcherDoneAnything ":!0});D.fetchers.set(e,u),H({fetchers:new Map(D.fetchers)});let h=new AbortController,f=le(r.history,i,h.signal);L.set(e,h);let p=await se("loader",f,s,l,y.basename,o.unstable_middleware);ye(p)&&(p=await Pe(p,f.signal,!0)||p);L.get(e)===h&&L.delete(e);if(f.signal.aborted)return;if(be(p))return void await N(D,p);if(we(p)){let t=fe(D.matches,a);return D.fetchers.delete(e),void H({fetchers:new Map(D.fetchers),errors:{[t.route.id]:p.error}})}n(!ye(p),"Unhandled fetcher deferred data");let m={state:"idle",data:p.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(e,m),H({fetchers:new Map(D.fetchers)})}(e,i,d,h,c,u))},revalidate:function(){Q(),H({revalidation:"loading"}),"submitting"!==D.navigation.state&&("idle"!==D.navigation.state?W(A||D.historyAction,D.navigation.location,{overrideNavigation:D.navigation}):W(D.historyAction,D.location,{startUninterruptedRevalidation:!0}))},createHref:e=>r.history.createHref(e),encodeLocation:e=>r.history.encodeLocation(e),getFetcher:$,deleteFetcher:re,dispose:function(){i&&i(),l.clear(),w&&w.abort(),D.fetchers.forEach(((e,t)=>re(t))),D.blockers.forEach(((e,t)=>ie(t)))},getBlocker:function(e,t){let r=D.blockers.get(e)||V;return O.get(e)!==t&&O.set(e,t),r},deleteBlocker:ie,_internalFetchControllers:L,_internalActiveDeferreds:j},y},e.createStaticHandler=function(e,r){n(e.length>0,"You must provide a non-empty routes array to createStaticHandler");let a=h(e),o=(r?r.basename:null)||"/",i=t({},I,r&&r.future?r.future:null);async function c(e,r,a,s,l,c){n(e.signal,"query()/queryRoute() requests must contain an AbortController signal");try{if(Ee(e.method.toLowerCase())){let n=await async function(e,r,a,n,s,l){let c;if(a.route.action){if(c=await se("action",e,a,r,o,i.unstable_middleware,!0,l,n,s),e.signal.aborted){throw new Error((l?"queryRoute":"query")+"() call aborted")}}else{let t=me(405,{method:e.method,pathname:new URL(e.url).pathname,routeId:a.route.id});if(l)throw t;c={type:u.error,error:t}}if(be(c))throw new Response(null,{status:c.status,headers:{Location:c.location}});if(ye(c)){let e=me(400,{type:"defer-action"});if(l)throw e;c={type:u.error,error:e}}if(l){if(we(c))throw c.error;return{matches:[a],loaderData:{},actionData:{[a.route.id]:c.data},errors:null,statusCode:200,loaderHeaders:{},actionHeaders:{},activeDeferreds:null}}if(we(c)){let o=fe(r,a.route.id);return t({},await d(e,r,n,s,void 0,{[o.route.id]:c.error}),{statusCode:O(c.error)?c.error.status:500,actionData:null,actionHeaders:t({},c.headers?{[a.route.id]:c.headers}:{})})}let h=new Request(e.url,{headers:e.headers,redirect:e.redirect,signal:e.signal});return t({},await d(h,r,n,s),c.statusCode?{statusCode:c.statusCode}:{},{actionData:{[a.route.id]:c.data},actionHeaders:t({},c.headers?{[a.route.id]:c.headers}:{})})}(e,a,c||Le(a,r),s,l,null!=c);return n}let n=await d(e,a,s,l,c);return De(n)?n:t({},n,{actionData:null,actionHeaders:{}})}catch(e){if((h=e)&&De(h.response)&&(h.type===u.data||u.error)){if(e.type===u.error&&!Ae(e.response))throw e.response;return e.response}if(Ae(e))return e;throw e}var h}async function d(e,r,a,n,s,l){let c=null!=s;if(c&&(null==s||!s.route.loader))throw me(400,{method:e.method,pathname:new URL(e.url).pathname,routeId:null==s?void 0:s.route.id});let d=(s?[s]:ee(r,Object.keys(l||{})[0])).filter((e=>e.route.loader));if(0===d.length)return{matches:r,loaderData:r.reduce(((e,t)=>Object.assign(e,{[t.route.id]:null})),{}),errors:l||null,statusCode:200,loaderHeaders:{},activeDeferreds:null};let u=await Promise.all([...d.map((t=>se("loader",e,t,r,o,i.unstable_middleware,!0,c,a,n)))]);if(e.signal.aborted){throw new Error((c?"queryRoute":"query")+"() call aborted")}let h=new Map,f=de(r,d,u,l,h),p=new Set(d.map((e=>e.route.id)));return r.forEach((e=>{p.has(e.route.id)||(f.loaderData[e.route.id]=null)})),t({},f,{matches:r,activeDeferreds:h.size>0?Object.fromEntries(h.entries()):null})}return{dataRoutes:a,query:async function(e,r){let{requestContext:n,middlewareContext:i}=void 0===r?{}:r,d=new URL(e.url),u=e.method.toLowerCase(),h=s("",l(d),null,"default"),p=f(a,h,o);if(!Re(u)&&"head"!==u){let e=me(405,{method:u}),{matches:t,route:r}=pe(a);return{basename:o,location:h,matches:t,loaderData:{},actionData:null,errors:{[r.id]:e},statusCode:e.status,loaderHeaders:{},actionHeaders:{},activeDeferreds:null}}if(!p){let e=me(404,{pathname:h.pathname}),{matches:t,route:r}=pe(a);return{basename:o,location:h,matches:t,loaderData:{},actionData:null,errors:{[r.id]:e},statusCode:e.status,loaderHeaders:{},actionHeaders:{},activeDeferreds:null}}let m=await c(e,h,p,n,i);return De(m)?m:t({location:h,basename:o},m)},queryRoute:async function(e,t){let{routeId:r,requestContext:n,middlewareContext:i}=void 0===t?{}:t,d=new URL(e.url),u=e.method.toLowerCase(),h=s("",l(d),null,"default"),p=f(a,h,o);if(!Re(u)&&"head"!==u&&"options"!==u)throw me(405,{method:u});if(!p)throw me(404,{pathname:h.pathname});let m=r?p.find((e=>e.route.id===r)):Le(p,h);if(r&&!m)throw me(403,{pathname:h.pathname,routeId:r});if(!m)throw me(404,{pathname:h.pathname});let g=await c(e,h,p,n,i,m);if(De(g))return g;let v=g.errors?Object.values(g.errors)[0]:void 0;if(void 0!==v)throw v;if(g.actionData)return Object.values(g.actionData)[0];if(g.loaderData){var y;let e=Object.values(g.loaderData)[0];return null!=(y=g.activeDeferreds)&&y[m.route.id]&&(e[Q]=g.activeDeferreds[m.route.id]),e}}}},e.defer=function(e,t){return void 0===t&&(t={}),new _(e,"number"==typeof t?{status:t}:t)},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,a)=>{let o=t[r];return"?"===a?null==o?"":o:(null==o&&n(!1,'Missing ":'+r+'" param'),o)})).replace(/\/:(\w+)(\??)/g,((e,r,a)=>{let o=t[r];return"?"===a?null==o?"":"/"+o:(null==o&&n(!1,'Missing ":'+r+'" param'),"/"+o)})).replace(/\?/g,"").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=O,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=b,e.matchRoutes=f,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=E,e.resolveTo=S,e.stripBasename=A,e.warning=R,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!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,t){return{usr:e.state,key:e.key,idx:t}}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(r,o,c,d){void 0===d&&(d={});let{window:u=document.defaultView,v5Compat:h=!1}=d,f=u.history,p=e.Action.Pop,m=null,g=v();function v(){return(f.state||{idx:null}).idx}function y(){p=e.Action.Pop;let t=v(),r=null==t?null:t-g;g=t,m&&m({action:p,location:b.location,delta:r})}function w(e){let t="null"!==u.location.origin?u.location.origin:u.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)}null==g&&(g=0,f.replaceState(t({},f.state,{idx:g}),""));let b={get action(){return p},get location(){return r(u,f)},listen(e){if(m)throw new Error("A history only accepts one active listener");return u.addEventListener(a,y),m=e,()=>{u.removeEventListener(a,y),m=null}},createHref:e=>o(u,e),createURL:w,encodeLocation(e){let t=w(e);return{pathname:t.pathname,search:t.search,hash:t.hash}},push:function(t,r){p=e.Action.Push;let a=s(b.location,t,r);c&&c(a,t),g=v()+1;let n=i(a,g),o=b.createHref(a);try{f.pushState(n,"",o)}catch(e){u.location.assign(o)}h&&m&&m({action:p,location:b.location,delta:1})},replace:function(t,r){p=e.Action.Replace;let a=s(b.location,t,r);c&&c(a,t),g=v();let n=i(a,g),o=b.createHref(a);f.replaceState(n,"",o),h&&m&&m({action:p,location:b.location,delta:0})},go:e=>f.go(e)};return b}let u;function h(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?h(e.children,i,a):void 0})}))}function f(e,t,r){void 0===r&&(r="/");let a=A(("string"==typeof t?c(t):t).pathname||"/",r);if(null==a)return null;let n=p(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=w(n[e],D(a));return o}function p(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=S([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+'".'),p(e.children,t,c,l)),(null!=e.path||e.index)&&t.push({path:l,score:y(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 m(e.path))o(e,t,r);else o(e,t)})),t}function m(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=m(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"}(u||(u={}));const g=/^:\w+$/,v=e=>"*"===e;function y(e,t){let r=e.split("/"),a=r.length;return r.some(v)&&(a+=-2),t&&(a+=2),r.filter((e=>!v(e))).reduce(((e,t)=>e+(g.test(t)?3:""===t?1:10)),a)}function w(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=b({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:S([n,c.pathname]),pathnameBase:C(S([n,c.pathnameBase])),route:d}),"/"!==c.pathnameBase&&(n=S([n,c.pathnameBase]))}return o}function b(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 D(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 A(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 E(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:L(a),hash:k(n)}}function x(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 M(e){return e.filter(((e,t)=>0===t||e.route.path&&e.route.path.length>0))}function P(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("?"),x("?","pathname","search",i)),n(!i.pathname||!i.pathname.includes("#"),x("#","pathname","hash",i)),n(!i.search||!i.search.includes("#"),x("#","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=E(i,s),h=d&&"/"!==d&&d.endsWith("/"),f=(l||"."===d)&&a.endsWith("/");return u.pathname.endsWith("/")||!h&&!f||(u.pathname+="/"),u}const S=e=>e.join("/").replace(/\/\/+/g,"/"),C=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),L=e=>e&&"?"!==e?e.startsWith("?")?e:"?"+e:"",k=e=>e&&"#"!==e?e.startsWith("#")?e:"#"+e:"";class U extends Error{}class _{constructor(e,t){let r;this.pendingKeysSet=new Set,this.subscribers=new Set,this.deferredKeys=[],n(e&&"object"==typeof e&&!Array.isArray(e),"defer() only accepts plain objects"),this.abortPromise=new Promise(((e,t)=>r=t)),this.controller=new AbortController;let a=()=>r(new U("Deferred data aborted"));this.unlistenAbortSignal=()=>this.controller.signal.removeEventListener("abort",a),this.controller.signal.addEventListener("abort",a),this.data=Object.entries(e).reduce(((e,t)=>{let[r,a]=t;return Object.assign(e,{[r]:this.trackPromise(r,a)})}),{}),this.done&&this.unlistenAbortSignal(),this.init=t}trackPromise(e,t){if(!(t instanceof Promise))return t;this.deferredKeys.push(e),this.pendingKeysSet.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){return this.controller.signal.aborted&&r instanceof U?(this.unlistenAbortSignal(),Object.defineProperty(e,"_error",{get:()=>r}),Promise.reject(r)):(this.pendingKeysSet.delete(t),this.done&&this.unlistenAbortSignal(),r?(Object.defineProperty(e,"_error",{get:()=>r}),this.emit(!1,t),Promise.reject(r)):(Object.defineProperty(e,"_data",{get:()=>a}),this.emit(!1,t),a))}emit(e,t){this.subscribers.forEach((r=>r(e,t)))}subscribe(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}cancel(){this.controller.abort(),this.pendingKeysSet.forEach(((e,t)=>this.pendingKeysSet.delete(t))),this.emit(!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.pendingKeysSet.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]:j(a)})}),{})}get pendingKeys(){return Array.from(this.pendingKeysSet)}}function j(e){if(!function(e){return e instanceof Promise&&!0===e._tracked}(e))return e;if(e._error)throw e._error;return e._data}class T{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 O(e){return null!=e&&"number"==typeof e.status&&"string"==typeof e.statusText&&"boolean"==typeof e.internal&&"data"in e}class q{constructor(e){void 0!==e&&(this.defaultValue=e)}getDefaultValue(){if(void 0===this.defaultValue)throw new Error("Unable to find a value in the middleware context");return this.defaultValue}}function F(){let e=new Map;return{get(t,r){if(e.has(r)){let a=e.get(r),n=a.length-1;for(;n>=0;){if(a[n][0]<=t){return a[n][1]}n--}}return r.getDefaultValue()},set(t,r,a){if(void 0===a)throw new Error("You cannot set an undefined value in the middleware context");let n=e.get(r)||[];n.push([t,a]),e.set(r,n)},next:()=>{}}}function H(e,t,r){return{get:r=>e.get(t,r),set:(r,a)=>e.set(t,r,a),next:r}}const I={unstable_middleware:!1},W=["post","put","patch","delete"],$=new Set(W),N=["get",...W],B=new Set(N),z=new Set([301,302,303,307,308]),Y=new Set([307,308]),K={state:"idle",location:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},V={state:"idle",data:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},J={state:"unblocked",proceed:void 0,reset:void 0,location:void 0},G=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,X="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Q=!X;const Z=Symbol("deferred");function ee(e){if((t=e)&&Re(t.response)&&(t.type===u.data||u.error)){if(e.type===u.error&&!Ee(e.response))throw e.response;return e.response}var t;if(Ee(e))return e;throw e}function te(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&&!xe(t.formMethod))return{path:n,error:ve(405,{method:t.formMethod})};if(t.formData&&(a={formMethod:t.formMethod||"get",formAction:we(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),i=ue(t.formData);return r&&o.search&&Ce(o.search)&&i.append("index",""),o.search="?"+i,{path:l(o),submission:a}}function re(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 ae(e,r,a,n,o,i,s,l,c,d,u){let h=d?Object.values(d)[0]:c?Object.values(c)[0]:void 0,f=e.createURL(r.location),p=e.createURL(o),m=i||f.toString()===p.toString()||f.search!==p.search,g=d?Object.keys(d)[0]:void 0,v=re(a,g).filter(((e,a)=>{if(null==e.route.loader)return!1;if(function(e,t,r){let a=!t||r.route.id!==t.route.id,n=void 0===e[r.route.id];return a||n}(r.loaderData,r.matches[a],e)||s.some((t=>t===e.route.id)))return!0;let o=r.matches[a],i=e;return oe(e,t({currentUrl:f,currentParams:o.params,nextUrl:p,nextParams:i.params},n,{actionResult:h,defaultShouldRevalidate:m||ne(o,i)}))})),y=[];return u&&u.forEach(((e,o)=>{if(a.some((t=>t.route.id===e.routeId)))if(l.includes(o))y.push(t({key:o},e));else{oe(e.match,t({currentUrl:f,currentParams:r.matches[r.matches.length-1].params,nextUrl:p,nextParams:a[a.length-1].params},n,{actionResult:h,defaultShouldRevalidate:m}))&&y.push(t({key:o},e))}})),[v,y]}function ne(e,t){let r=e.route.path;return e.pathname!==t.pathname||null!=r&&r.endsWith("*")&&e.params["*"]!==t.params["*"]}function oe(e,t){if(e.route.shouldRevalidate){let r=e.route.shouldRevalidate(t);if("boolean"==typeof r)return r}return t.defaultShouldRevalidate}async function ie(e,t,r,a,n,o){if(e.signal.aborted)throw new Error("Request aborted");let i=t[r];if(!i)return o({request:e,params:a,context:H(n,r,(()=>{throw new Error("You can not call context.next() in a loader or action")}))});let s=!1,l=()=>{if(s)throw new Error("You may only call `next()` once per middleware");return s=!0,ie(e,t,r+1,a,n,o)};if(!i.route.middleware)return l();let c=await i.route.middleware({request:e,params:a,context:H(n,r,l)});return s?c:l()}function se(){throw new Error("Middleware must be enabled via the `future.unstable_middleware` flag)")}const le={get:se,set:se,next:se};async function ce(e,t,r,a,o,i,s,c,d,h){let f,p,m;void 0===o&&(o="/"),void 0===s&&(s=!1),void 0===c&&(c=!1);let g=new Promise(((e,t)=>m=t)),v=()=>m();t.signal.addEventListener("abort",v);try{let o=r.route[e];n(o,"Could not find the "+e+' to run on the "'+r.route.id+'" route');let s,l=a.findIndex((e=>e.route.id===r.route.id));s=i?ie(t,a.slice(0,l+1),0,a[0].params,h||F(),o):o({request:t,params:r.params,context:h?H(h,l,(()=>{throw new Error("You can not call context.next() in a loader or action")})):d||le}),p=await Promise.race([s,g]),n(void 0!==p,"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){f=u.error,p=e}finally{t.signal.removeEventListener("abort",v)}if(Re(p)){let e,i=p.status;if(z.has(i)){let e=p.headers.get("Location");if(n(e,"Redirects returned/thrown from loaders/actions must have a Location header"),G.test(e)){if(!s){let r=new URL(t.url),a=e.startsWith("//")?new URL(r.protocol+e):new URL(e);a.origin===r.origin&&(e=a.pathname+a.search+a.hash)}}else{let i=P(e,M(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:S([o,e])}e=l(i)}if(s)throw p.headers.set("Location",e),p;return{type:u.redirect,status:i,location:e,revalidate:null!==p.headers.get("X-Remix-Revalidate")}}if(c)throw{type:f||u.data,response:p};let d=p.headers.get("Content-Type");return e=d&&/\bapplication\/json\b/.test(d)?await p.json():await p.text(),f===u.error?{type:f,error:new T(i,p.statusText,e),headers:p.headers}:{type:u.data,data:e,statusCode:p.status,headers:p.headers}}return f===u.error?{type:f,error:p}:p instanceof _?{type:u.deferred,deferredData:p}:{type:u.data,data:p}}function de(e,t,r,a){let n=e.createURL(we(t)).toString(),o={signal:r};if(a&&Me(a.formMethod)){let{formMethod:e,formEncType:t,formData:r}=a;o.method=e.toUpperCase(),o.body="application/x-www-form-urlencoded"===t?ue(r):r}return new Request(n,o)}function ue(e){let t=new URLSearchParams;for(let[r,a]of e.entries())t.append(r,a instanceof File?a.name:a);return t}function he(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(!Ae(r),"Cannot handle redirect results in processLoaderData"),De(r)){let t=me(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=O(r.error)?r.error.status:500),r.headers&&(d[h]=r.headers)}else be(r)?(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 fe(e,r,a,o,i,s,l,c){let{loaderData:d,errors:u}=he(r,a,o,i,c);for(let r=0;r<s.length;r++){let{key:a,match: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=me(e.matches,o.route.id);u&&u[r.route.id]||(u=t({},u,{[r.route.id]:i.error})),e.fetchers.delete(a)}else if(Ae(i))n(!1,"Unhandled fetcher revalidation redirect");else if(be(i))n(!1,"Unhandled fetcher deferred data");else{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 pe(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 me(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 ge(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 ve(e,t){let{pathname:r,routeId:a,method:n,type:o}=void 0===t?{}:t,i="Unknown Server Error",s="Unknown @remix-run/router error";return 400===e?(i="Bad Request",n&&r&&a?s="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.':"defer-action"===o&&(s="defer() is not supported in actions")):403===e?(i="Forbidden",s='Route "'+a+'" does not match URL "'+r+'"'):404===e?(i="Not Found",s='No route matches URL "'+r+'"'):405===e&&(i="Method Not Allowed",n&&r&&a?s="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&&(s='Invalid request method "'+n.toUpperCase()+'"')),new T(e||500,i,new Error(s),!0)}function ye(e){for(let t=e.length-1;t>=0;t--){let r=e[t];if(Ae(r))return r}}function we(e){return l(t({},"string"==typeof e?c(e):e,{hash:""}))}function be(e){return e.type===u.deferred}function De(e){return e.type===u.error}function Ae(e){return(e&&e.type)===u.redirect}function Re(e){return null!=e&&"number"==typeof e.status&&"string"==typeof e.statusText&&"object"==typeof e.headers&&void 0!==e.body}function Ee(e){if(!Re(e))return!1;let t=e.status,r=e.headers.get("Location");return t>=300&&t<=399&&null!=r}function xe(e){return B.has(e)}function Me(e){return $.has(e)}async function Pe(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&&!ne(c,l)&&void 0!==(o&&o[l.route.id]);be(s)&&(n||d)&&await Se(s,a,n).then((e=>{e&&(r[i]=e||r[i])}))}}async function Se(e,t,r){if(void 0===r&&(r=!1),!await e.deferredData.resolveData(t)){if(r)try{return{type:u.data,data:e.deferredData.unwrappedData}}catch(e){return{type:u.error,error:e}}return{type:u.data,data:e.deferredData.data}}}function Ce(e){return new URLSearchParams(e).getAll("index").some((e=>""===e))}function Le(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 ke(e,t){let r="string"==typeof t?c(t).search:t.search;if(e[e.length-1].route.index&&Ce(r||""))return e[e.length-1];let a=M(e);return a[a.length-1]}e.AbortedDeferredError=U,e.ErrorResponse=T,e.IDLE_BLOCKER=J,e.IDLE_FETCHER=V,e.IDLE_NAVIGATION=K,e.UNSAFE_DEFERRED_SYMBOL=Z,e.UNSAFE_DeferredData=_,e.UNSAFE_convertRoutesToDataRoutes=h,e.UNSAFE_createMiddlewareStore=F,e.UNSAFE_getPathContributingMatches=M,e.UNSAFE_getRouteAwareMiddlewareContext=H,e.createBrowserHistory=function(e){return void 0===e&&(e={}),d((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={}),d((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}function g(e){return"string"==typeof e?e:l(e)}return{get index(){return d},get action(){return u},get location(){return p()},createHref:g,createURL:e=>new URL(g(e),"http://localhost"),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,delta:1})},replace(t,a){u=e.Action.Replace;let n=m(t,a);r[d]=n,i&&h&&h({action:u,location:n,delta:0})},go(t){u=e.Action.Pop;let a=f(d+t),n=r[a];d=a,h&&h({action:u,location:n,delta:t})},listen:e=>(h=e,()=>{h=null})}},e.createMiddlewareContext=function(e){return new q(e)},e.createPath=l,e.createRouter=function(r){n(r.routes.length>0,"You must provide a non-empty routes array to createRouter");let a=h(r.routes),o=t({},I,r.future),i=null,l=new Set,c=null,d=null,p=null,m=null!=r.hydrationData,g=f(a,r.history.location,r.basename),v=null;if(null==g){let e=ve(404,{pathname:r.history.location.pathname}),{matches:t,route:n}=ge(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:K,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,blockers:new Map},A=e.Action.Pop,E=!1,x=!1,M=!1,P=[],S=[],C=new Map,L=0,k=-1,U=new Map,_=new Set,j=new Map,T=new Map,O=new Map,q=!1;function F(e){D=t({},D,e),l.forEach((e=>e(D)))}function H(a,n){var o,i;let s,l=null!=D.actionData&&null!=D.navigation.formMethod&&Me(D.navigation.formMethod)&&"loading"===D.navigation.state&&!0!==(null==(o=a.state)?void 0:o._isRedirect);s=n.actionData?Object.keys(n.actionData).length>0?n.actionData:null:l?D.actionData:null;let c=n.loaderData?pe(D.loaderData,n.loaderData,n.matches||[],n.errors):D.loaderData;for(let[e]of O)ie(e);let d=!0===E||null!=D.navigation.formMethod&&Me(D.navigation.formMethod)&&!0!==(null==(i=a.state)?void 0:i._isRedirect);F(t({},n,{actionData:s,loaderData:c,historyAction:A,location:a,initialized:!0,navigation:K,revalidation:"idle",restoreScrollPosition:he(a,n.matches||D.matches),preventScrollReset:d,blockers:new Map(D.blockers)})),x||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,x=!1,M=!1,P=[],S=[]}async function W(i,s,l){w&&w.abort(),w=null,A=i,x=!0===(l&&l.startUninterruptedRevalidation),function(e,t){if(c&&d&&p){let r=t.map((e=>Le(e,D.loaderData))),a=d(e,r)||e.key;c[a]=p()}}(D.location,D.matches),E=!0===(l&&l.preventScrollReset);let h=l&&l.overrideNavigation,m=f(a,s,r.basename);if(!m){let e=ve(404,{pathname:s.pathname}),{matches:t,route:r}=ge(a);return ue(),void H(s,{matches:t,loaderData:{},errors:{[r.id]:e}})}if(!(g=D.location,v=s,g.pathname!==v.pathname||g.search!==v.search||g.hash===v.hash||l&&l.submission&&Me(l.submission.formMethod)))return void H(s,{matches:m});var g,v;w=new AbortController;let b,R,U=de(r.history,s,w.signal,l&&l.submission);if(l&&l.pendingError)R={[me(m).route.id]:l.pendingError};else if(l&&l.submission&&Me(l.submission.formMethod)){let r=await async function(r,a,n,i,s){let l;z(),F({navigation:t({state:"submitting",location:a},n)});let c=ke(i,a);if(c.route.action){if(l=await ce("action",r,c,i,y.basename,o.unstable_middleware),r.signal.aborted)return{shortCircuited:!0}}else l={type:u.error,error:ve(405,{method:r.method,pathname:a.pathname,routeId:c.route.id})};if(Ae(l)){let e;return e=s&&null!=s.replace?s.replace:l.location===D.location.pathname+D.location.search,await N(D,l,{submission:n,replace:e}),{shortCircuited:!0}}if(De(l)){let t=me(i,c.route.id);return!0!==(s&&s.replace)&&(A=e.Action.Push),{pendingActionData:{},pendingActionError:{[t.route.id]:l.error}}}if(be(l))throw ve(400,{type:"defer-action"});return{pendingActionData:{[c.route.id]:l.data}}}(U,s,l.submission,m,{replace:l.replace});if(r.shortCircuited)return;b=r.pendingActionData,R=r.pendingActionError,h=t({state:"loading",location:s},l.submission),U=new Request(U.url,{signal:U.signal})}let{shortCircuited:O,loaderData:q,errors:I}=await async function(e,a,o,i,s,l,c,d){let u=i;if(!u){u=t({state:"loading",location:a,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},s)}let h=s||(u.formMethod&&u.formAction&&u.formData&&u.formEncType?{formMethod:u.formMethod,formAction:u.formAction,formData:u.formData,formEncType:u.formEncType}:void 0),[f,p]=ae(r.history,D,o,h,a,M,P,S,c,d,j);if(ue((e=>!(o&&o.some((t=>t.route.id===e)))||f&&f.some((t=>t.route.id===e)))),0===f.length&&0===p.length)return H(a,t({matches:o,loaderData:{},errors:d||null},c?{actionData:c}:{})),{shortCircuited:!0};if(!x){p.forEach((e=>{let t=D.fetchers.get(e.key),r={state:"loading",data:t&&t.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(e.key,r)}));let e=c||D.actionData;F(t({navigation:u},e?0===Object.keys(e).length?{actionData:null}:{actionData:e}:{},p.length>0?{fetchers:new Map(D.fetchers)}:{}))}k=++L,p.forEach((e=>C.set(e.key,w)));let{results:m,loaderResults:g,fetcherResults:v}=await B(D.matches,o,f,p,e);if(e.signal.aborted)return{shortCircuited:!0};p.forEach((e=>C.delete(e.key)));let y=ye(m);if(y)return await N(D,y,{replace:l}),{shortCircuited:!0};let{loaderData:b,errors:A}=fe(D,o,f,g,d,p,v,T);T.forEach(((e,t)=>{e.subscribe((r=>{(r||e.done)&&T.delete(t)}))})),function(){let e=[];for(let t of _){let r=D.fetchers.get(t);n(r,"Expected fetcher: "+t),"loading"===r.state&&(_.delete(t),e.push(t))}ne(e)}();let R=oe(k);return t({loaderData:b,errors:A},R||p.length>0?{fetchers:new Map(D.fetchers)}:{})}(U,s,m,h,l&&l.submission,l&&l.replace,b,R);O||(w=null,H(s,t({matches:m},b?{actionData:b}:{},{loaderData:q,errors:I})))}function $(e){return D.fetchers.get(e)||V}async function N(a,o,i){var l;let{submission:c,replace:d,isFetchActionRedirect:u}=void 0===i?{}:i;o.revalidate&&(M=!0);let h=s(a.location,o.location,t({_isRedirect:!0},u?{_isFetchActionRedirect:!0}:{}));if(n(h,"Expected a location on the redirect navigation"),G.test(o.location)&&X&&void 0!==(null==(l=window)?void 0:l.location)){let e=r.history.createURL(o.location).origin;if(window.location.origin!==e)return void(d?window.location.replace(o.location):window.location.assign(o.location))}w=null;let f=!0===d?e.Action.Replace:e.Action.Push,{formMethod:p,formAction:m,formEncType:g,formData:v}=a.navigation;!c&&p&&m&&v&&g&&(c={formMethod:p,formAction:m,formEncType:g,formData:v}),Y.has(o.status)&&c&&Me(c.formMethod)?await W(f,h,{submission:t({},c,{formAction:o.location}),preventScrollReset:E}):await W(f,h,{overrideNavigation:{state:"loading",location:h,formMethod:c?c.formMethod:void 0,formAction:c?c.formAction:void 0,formEncType:c?c.formEncType:void 0,formData:c?c.formData:void 0},preventScrollReset:E})}async function B(e,t,a,n,i){let s=await Promise.all([...a.map((e=>ce("loader",i,e,t,y.basename,o.unstable_middleware))),...n.map((e=>ce("loader",de(r.history,e.path,i.signal),e.match,e.matches,y.basename,o.unstable_middleware)))]),l=s.slice(0,a.length),c=s.slice(a.length);return await Promise.all([Pe(e,a,l,i.signal,!1,D.loaderData),Pe(e,n.map((e=>e.match)),c,i.signal,!0)]),{results:s,loaderResults:l,fetcherResults:c}}function z(){M=!0,P.push(...ue()),j.forEach(((e,t)=>{C.has(t)&&(S.push(t),re(t))}))}function Z(e,t,r){let a=me(D.matches,t);ee(e),F({errors:{[a.route.id]:r},fetchers:new Map(D.fetchers)})}function ee(e){C.has(e)&&re(e),j.delete(e),U.delete(e),_.delete(e),D.fetchers.delete(e)}function re(e){let t=C.get(e);n(t,"Expected fetch controller: "+e),t.abort(),C.delete(e)}function ne(e){for(let t of e){let e={state:"idle",data:$(t).data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(t,e)}}function oe(e){let t=[];for(let[r,a]of U)if(a<e){let e=D.fetchers.get(r);n(e,"Expected fetcher: "+r),"loading"===e.state&&(re(r),U.delete(r),t.push(r))}return ne(t),t.length>0}function ie(e){D.blockers.delete(e),O.delete(e)}function se(e,t){let r=D.blockers.get(e)||J;n("unblocked"===r.state&&"blocked"===t.state||"blocked"===r.state&&"blocked"===t.state||"blocked"===r.state&&"proceeding"===t.state||"blocked"===r.state&&"unblocked"===t.state||"proceeding"===r.state&&"unblocked"===t.state,"Invalid blocker state transition: "+r.state+" -> "+t.state),D.blockers.set(e,t),F({blockers:new Map(D.blockers)})}function le(e){let{currentLocation:t,nextLocation:r,historyAction:a}=e;if(0===O.size)return;O.size>1&&R(!1,"A router only supports one blocker at a time");let n=Array.from(O.entries()),[o,i]=n[n.length-1],s=D.blockers.get(o);return s&&"proceeding"===s.state?void 0:i({currentLocation:t,nextLocation:r,historyAction:a})?o:void 0}function ue(e){let t=[];return T.forEach(((r,a)=>{e&&!e(a)||(r.cancel(),t.push(a),T.delete(a))})),t}function he(e,t){if(c&&d&&p){let r=t.map((e=>Le(e,D.loaderData))),a=d(e,r)||e.key,n=c[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 i=r.history.listen((e=>{let{action:t,location:a,delta:n}=e;if(q)return void(q=!1);R(0===O.size||null!=n,"You are trying to use a blocker on a POP navigation to a location that was not created by @remix-run/router. This will fail silently in production. This can happen if you are navigating outside the router via `window.history.pushState`/`window.location.hash` instead of using router navigation APIs. This can also happen if you are using createHashRouter and the user manually changes the URL.");let o=le({currentLocation:D.location,nextLocation:a,historyAction:t});return o&&null!=n?(q=!0,r.history.go(-1*n),void se(o,{state:"blocked",location:a,proceed(){se(o,{state:"proceeding",proceed:void 0,reset:void 0,location:a}),r.history.go(n)},reset(){ie(o),F({blockers:new Map(y.state.blockers)})}})):W(t,a)})),D.initialized||W(e.Action.Pop,D.location),y},subscribe:function(e){return l.add(e),()=>l.delete(e)},enableScrollRestoration:function(e,t,r){if(c=e,p=t,d=r||(e=>e.key),!m&&D.navigation===K){m=!0;let e=he(D.location,D.matches);null!=e&&F({restoreScrollPosition:e})}return()=>{c=null,p=null,d=null}},navigate:async function a(n,o){if("number"==typeof n)return void r.history.go(n);let{path:i,submission:l,error:c}=te(n,o),d=D.location,u=s(D.location,i,o&&o.state);u=t({},u,r.history.encodeLocation(u));let h=o&&null!=o.replace?o.replace:void 0,f=e.Action.Push;!0===h?f=e.Action.Replace:!1===h||null!=l&&Me(l.formMethod)&&l.formAction===D.location.pathname+D.location.search&&(f=e.Action.Replace);let p=o&&"preventScrollReset"in o?!0===o.preventScrollReset:void 0,m=le({currentLocation:d,nextLocation:u,historyAction:f});if(!m)return await W(f,u,{submission:l,pendingError:c,preventScrollReset:p,replace:o&&o.replace});se(m,{state:"blocked",location:u,proceed(){se(m,{state:"proceeding",proceed:void 0,reset:void 0,location:u}),a(n,o)},reset(){ie(m),F({blockers:new Map(D.blockers)})}})},fetch:function(e,i,s,l){if(Q)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.");C.has(e)&&re(e);let c=f(a,s,r.basename);if(!c)return void Z(e,i,ve(404,{pathname:s}));let{path:d,submission:u}=te(s,l,!0),h=ke(c,d);return E=!0===(l&&l.preventScrollReset),u&&Me(u.formMethod)?async function(e,i,s,l,c,d){if(z(),j.delete(e),!l.route.action){let t=ve(405,{method:d.formMethod,pathname:s,routeId:i});return void Z(e,i,t)}let u=D.fetchers.get(e),h=t({state:"submitting"},d,{data:u&&u.data," _hasFetcherDoneAnything ":!0});D.fetchers.set(e,h),F({fetchers:new Map(D.fetchers)});let p=new AbortController,m=de(r.history,s,p.signal,d);C.set(e,p);let g=await ce("action",m,l,c,y.basename,o.unstable_middleware);if(m.signal.aborted)return void(C.get(e)===p&&C.delete(e));if(Ae(g)){C.delete(e),_.add(e);let r=t({state:"loading"},d,{data:void 0," _hasFetcherDoneAnything ":!0});return D.fetchers.set(e,r),F({fetchers:new Map(D.fetchers)}),N(D,g,{isFetchActionRedirect:!0})}if(De(g))return void Z(e,i,g.error);if(be(g))throw ve(400,{type:"defer-action"});let v=D.navigation.location||D.location,b=de(r.history,v,p.signal),R="idle"!==D.navigation.state?f(a,D.navigation.location,r.basename):D.matches;n(R,"Didn't find any matches after fetcher action");let E=++L;U.set(e,E);let x=t({state:"loading",data:g.data},d,{" _hasFetcherDoneAnything ":!0});D.fetchers.set(e,x);let[O,q]=ae(r.history,D,R,d,v,M,P,S,{[l.route.id]:g.data},void 0,j);q.filter((t=>t.key!==e)).forEach((e=>{let t=e.key,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),C.set(t,p)})),F({fetchers:new Map(D.fetchers)});let{results:I,loaderResults:W,fetcherResults:$}=await B(D.matches,R,O,q,b);if(p.signal.aborted)return;U.delete(e),C.delete(e),q.forEach((e=>C.delete(e.key)));let Y=ye(I);if(Y)return N(D,Y);let{loaderData:K,errors:V}=fe(D,D.matches,O,W,void 0,q,$,T),J={state:"idle",data:g.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(e,J);let G=oe(E);"loading"===D.navigation.state&&E>k?(n(A,"Expected pending action"),w&&w.abort(),H(D.navigation.location,{matches:R,loaderData:K,errors:V,fetchers:new Map(D.fetchers)})):(F(t({errors:V,loaderData:pe(D.loaderData,K,R,V)},G?{fetchers:new Map(D.fetchers)}:{})),M=!1)}(e,i,d,h,c,u):(j.set(e,{routeId:i,path:d,match:h,matches:c}),async function(e,a,i,s,l,c){let d=D.fetchers.get(e),u=t({state:"loading",formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},c,{data:d&&d.data," _hasFetcherDoneAnything ":!0});D.fetchers.set(e,u),F({fetchers:new Map(D.fetchers)});let h=new AbortController,f=de(r.history,i,h.signal);C.set(e,h);let p=await ce("loader",f,s,l,y.basename,o.unstable_middleware);be(p)&&(p=await Se(p,f.signal,!0)||p);C.get(e)===h&&C.delete(e);if(f.signal.aborted)return;if(Ae(p))return void await N(D,p);if(De(p)){let t=me(D.matches,a);return D.fetchers.delete(e),void F({fetchers:new Map(D.fetchers),errors:{[t.route.id]:p.error}})}n(!be(p),"Unhandled fetcher deferred data");let m={state:"idle",data:p.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0," _hasFetcherDoneAnything ":!0};D.fetchers.set(e,m),F({fetchers:new Map(D.fetchers)})}(e,i,d,h,c,u))},revalidate:function(){z(),F({revalidation:"loading"}),"submitting"!==D.navigation.state&&("idle"!==D.navigation.state?W(A||D.historyAction,D.navigation.location,{overrideNavigation:D.navigation}):W(D.historyAction,D.location,{startUninterruptedRevalidation:!0}))},createHref:e=>r.history.createHref(e),encodeLocation:e=>r.history.encodeLocation(e),getFetcher:$,deleteFetcher:ee,dispose:function(){i&&i(),l.clear(),w&&w.abort(),D.fetchers.forEach(((e,t)=>ee(t))),D.blockers.forEach(((e,t)=>ie(t)))},getBlocker:function(e,t){let r=D.blockers.get(e)||J;return O.get(e)!==t&&O.set(e,t),r},deleteBlocker:ie,_internalFetchControllers:C,_internalActiveDeferreds:T},y},e.createStaticHandler=function(e,r){n(e.length>0,"You must provide a non-empty routes array to createStaticHandler");let a=h(e),o=(r?r.basename:null)||"/",i=t({},I,r&&r.future?r.future:null);function c(e){let t=new URL(e.url),r=e.method.toLowerCase(),n=s("",l(t),null,"default"),i=f(a,n,o);if(!xe(r)&&"head"!==r){let e=ve(405,{method:r}),{matches:t,route:i}=ge(a);return{shortCircuitContext:{basename:o,location:n,matches:t,loaderData:{},actionData:null,errors:{[i.id]:e},statusCode:e.status,loaderHeaders:{},actionHeaders:{},activeDeferreds:null}}}if(!i){let e=ve(404,{pathname:n.pathname}),{matches:t,route:r}=ge(a);return{shortCircuitContext:{basename:o,location:n,matches:t,loaderData:{},actionData:null,errors:{[r.id]:e},statusCode:e.status,loaderHeaders:{},actionHeaders:{},activeDeferreds:null}}}return{location:n,matches:i}}async function d(e,r,a,n,i){let s;try{if(Me(e.method.toLowerCase()))s=await async function(e,r,a,n,i){let s;if(a.route.action){if(s=await ce("action",e,a,r,o,!1,!0,!1,n,i),e.signal.aborted)throw new Error("query() call aborted")}else s={type:u.error,error:ve(405,{method:e.method,pathname:new URL(e.url).pathname,routeId:a.route.id})};if(Ae(s))throw new Response(null,{status:s.status,headers:{Location:s.location}});be(s)&&(s={type:u.error,error:ve(400,{type:"defer-action"})});if(De(s)){let o=me(r,a.route.id);return t({},await p(e,r,n,i,{[o.route.id]:s.error}),{statusCode:O(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 p(l,r,n,i),s.statusCode?{statusCode:s.statusCode}:{},{actionData:{[a.route.id]:s.data},actionHeaders:t({},s.headers?{[a.route.id]:s.headers}:{})})}(e,a,ke(a,r),n,i);else{s=t({},await p(e,a,n,i),{actionData:null,actionHeaders:{}})}}catch(e){return ee(e)}return t({location:r,basename:o},s)}async function p(e,r,a,n,i){let s=re(r,Object.keys(i||{})[0]).filter((e=>e.route.loader));if(0===s.length)return{matches:r,loaderData:r.reduce(((e,t)=>Object.assign(e,{[t.route.id]:null})),{}),errors:i||null,statusCode:200,loaderHeaders:{},activeDeferreds:null};let l=await Promise.all([...s.map((t=>ce("loader",e,t,r,o,!1,!0,!1,a,n)))]);if(e.signal.aborted)throw new Error("query() call aborted");let c=new Map,d=he(r,s,l,i,c),u=new Set(s.map((e=>e.route.id)));return r.forEach((e=>{u.has(e.route.id)||(d.loaderData[e.route.id]=null)})),t({},d,{matches:r,activeDeferreds:c.size>0?Object.fromEntries(c.entries()):null})}return{dataRoutes:a,query:async function(e,t){let{requestContext:r}=void 0===t?{}:t;n(e.signal,"query() requests must contain an AbortController signal"),n(!i.unstable_middleware,"staticHandler.query() cannot be used with middleware");let a=c(e);if("shortCircuitContext"in a)return a.shortCircuitContext;let{location:o,matches:s}=a;return d(e,o,s,r,void 0)},queryAndRender:async function(e,t,r){let{middlewareContext:a}=void 0===r?{}:r;n(e.signal,"query() requests must contain an AbortController signal");let o=c(e);if("shortCircuitContext"in o)return t(o.shortCircuitContext);let{location:s,matches:l}=o;if(!i.unstable_middleware){let r=await d(e,s,l);return t(r)}n(null!=t,"Using middleware with staticHandler.query() requires passing a render() function");let u=a||F();return await ie(e,l,0,l[0].params,u,(async()=>{let r=await d(e,s,l,void 0,u);return await t(r)}))},queryRoute:async function(e,r){let{routeId:c,requestContext:d,middlewareContext:u}=void 0===r?{}:r;n(e.signal,"queryRoute() requests must contain an AbortController signal");let h=new URL(e.url),p=e.method.toLowerCase(),m=s("",l(h),null,"default"),g=f(a,m,o);if(!xe(p)&&"head"!==p&&"options"!==p)throw ve(405,{method:p});if(!g)throw ve(404,{pathname:m.pathname});let v=c?g.find((e=>e.route.id===c)):ke(g,m);if(c&&!v)throw ve(403,{pathname:m.pathname,routeId:c});if(!v)throw ve(404,{pathname:m.pathname});try{if(Me(e.method.toLowerCase())){let t=await async function(e,t,r,a,n){if(!r.route.action)throw ve(405,{method:e.method,pathname:new URL(e.url).pathname,routeId:r.route.id});let s=await ce("action",e,r,t,o,i.unstable_middleware,!0,!0,a,n);if(e.signal.aborted)throw new Error("queryRoute() call aborted");if(Ae(s))throw new Response(null,{status:s.status,headers:{Location:s.location}});if(be(s))throw ve(400,{type:"defer-action"});if(De(s))throw s.error;return s.data}(e,g,v,d,u);return t}let r=await async function(e,r,a,n,s){if(null==s||!s.route.loader)throw ve(400,{method:e.method,pathname:new URL(e.url).pathname,routeId:null==s?void 0:s.route.id});let l=[s].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:null,statusCode:200,loaderHeaders:{},activeDeferreds:null};let c=await Promise.all([...l.map((t=>ce("loader",e,t,r,o,i.unstable_middleware,!0,!0,a,n)))]);if(e.signal.aborted)throw new Error("queryRoute() call aborted");let d=new Map,u=he(r,l,c,void 0,d),h=new Set(l.map((e=>e.route.id)));return r.forEach((e=>{h.has(e.route.id)||(u.loaderData[e.route.id]=null)})),t({},u,{matches:r,activeDeferreds:d.size>0?Object.fromEntries(d.entries()):null})}(e,g,d,u,v),a=r.errors?Object.values(r.errors)[0]:void 0;if(void 0!==a)throw a;if(r.loaderData){var y;let e=Object.values(r.loaderData)[0];return null!=(y=r.activeDeferreds)&&y[v.route.id]&&(e[Z]=r.activeDeferreds[v.route.id]),e}}catch(e){return ee(e)}}}},e.defer=function(e,t){return void 0===t&&(t={}),new _(e,"number"==typeof t?{status:t}:t)},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,a)=>{let o=t[r];return"?"===a?null==o?"":o:(null==o&&n(!1,'Missing ":'+r+'" param'),o)})).replace(/\/:(\w+)(\??)/g,((e,r,a)=>{let o=t[r];return"?"===a?null==o?"":"/"+o:(null==o&&n(!1,'Missing ":'+r+'" param'),"/"+o)})).replace(/\?/g,"").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=O,e.joinPaths=S,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=b,e.matchRoutes=f,e.normalizePathname=C,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=E,e.resolveTo=P,e.stripBasename=A,e.warning=R,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=router.umd.min.js.map |
@@ -434,5 +434,21 @@ import type { Location, Path, To } from "./history"; | ||
/** | ||
* Internal route-aware context object used to ensure parent loaders can't | ||
* access child middleware values in document requests | ||
*/ | ||
export interface InternalMiddlewareContext { | ||
/** | ||
* Retrieve a value from context | ||
*/ | ||
get<T>(idx: number, key: MiddlewareContextInstance<T>): T; | ||
/** | ||
* Set a value from context | ||
*/ | ||
set<T>(idx: number, key: MiddlewareContextInstance<T>, value: T): void; | ||
/** | ||
* Call any child middlewares and the destination loader/action | ||
*/ | ||
next: () => DataFunctionReturnValue; | ||
} | ||
/** | ||
* Context object passed through middleware functions and into action/loaders. | ||
* | ||
* Supports only key/value for now, eventually will be enhanced | ||
*/ | ||
@@ -452,10 +468,2 @@ export interface MiddlewareContext { | ||
next: () => DataFunctionReturnValue; | ||
/** | ||
* @internal | ||
* PRIVATE - DO NOT USE | ||
* | ||
* Return the entries - needed so we can copy values from the serverMiddleware | ||
* context into route-specific contexts | ||
*/ | ||
entries(): IterableIterator<[MiddlewareContextInstance<unknown>, unknown]>; | ||
} | ||
@@ -482,3 +490,4 @@ /** | ||
*/ | ||
export declare function createMiddlewareStore(initialMiddlewareContext?: MiddlewareContext): MiddlewareContext; | ||
export declare function createMiddlewareStore(): InternalMiddlewareContext; | ||
export declare function getRouteAwareMiddlewareContext(context: InternalMiddlewareContext, idx: number, next: MiddlewareContext["next"]): MiddlewareContext; | ||
export {}; |
@@ -88,2 +88,3 @@ export type { | ||
/** @internal */ | ||
export type { InternalMiddlewareContext as UNSAFE_InternalMiddlewareContext } from "./utils"; | ||
export { | ||
@@ -94,2 +95,3 @@ DeferredData as UNSAFE_DeferredData, | ||
createMiddlewareStore as UNSAFE_createMiddlewareStore, | ||
getRouteAwareMiddlewareContext as UNSAFE_getRouteAwareMiddlewareContext, | ||
} from "./utils"; |
{ | ||
"name": "@remix-run/router", | ||
"version": "0.0.0-experimental-f8cbf972", | ||
"version": "0.0.0-experimental-ff38e9e6", | ||
"description": "Nested/Data-driven/Framework-agnostic Routing", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
85
utils.ts
@@ -1472,5 +1472,22 @@ import type { Location, Path, To } from "./history"; | ||
/** | ||
* Internal route-aware context object used to ensure parent loaders can't | ||
* access child middleware values in document requests | ||
*/ | ||
export interface InternalMiddlewareContext { | ||
/** | ||
* Retrieve a value from context | ||
*/ | ||
get<T>(idx: number, key: MiddlewareContextInstance<T>): T; | ||
/** | ||
* Set a value from context | ||
*/ | ||
set<T>(idx: number, key: MiddlewareContextInstance<T>, value: T): void; | ||
/** | ||
* Call any child middlewares and the destination loader/action | ||
*/ | ||
next: () => DataFunctionReturnValue; | ||
} | ||
/** | ||
* Context object passed through middleware functions and into action/loaders. | ||
* | ||
* Supports only key/value for now, eventually will be enhanced | ||
*/ | ||
@@ -1490,10 +1507,2 @@ export interface MiddlewareContext { | ||
next: () => DataFunctionReturnValue; | ||
/** | ||
* @internal | ||
* PRIVATE - DO NOT USE | ||
* | ||
* Return the entries - needed so we can copy values from the serverMiddleware | ||
* context into route-specific contexts | ||
*/ | ||
entries(): IterableIterator<[MiddlewareContextInstance<unknown>, unknown]>; | ||
} | ||
@@ -1538,14 +1547,20 @@ | ||
*/ | ||
export function createMiddlewareStore( | ||
initialMiddlewareContext?: MiddlewareContext | ||
) { | ||
let store = new Map(initialMiddlewareContext?.entries()); | ||
let middlewareContext: MiddlewareContext = { | ||
get<T>(k: MiddlewareContextInstance<T>) { | ||
export function createMiddlewareStore() { | ||
let store = new Map(); | ||
let middlewareContext: InternalMiddlewareContext = { | ||
get<T>(idx: number, k: MiddlewareContextInstance<T>) { | ||
if (store.has(k)) { | ||
return store.get(k) as T; | ||
let arr = store.get(k) as [number, T][]; | ||
let i = arr.length - 1; | ||
while (i >= 0) { | ||
if (arr[i][0] <= idx) { | ||
let v = arr[i][1]; | ||
return v; | ||
} | ||
i--; | ||
} | ||
} | ||
return k.getDefaultValue(); | ||
}, | ||
set<T>(k: MiddlewareContextInstance<T>, v: T) { | ||
set<T>(idx: number, k: MiddlewareContextInstance<T>, v: T) { | ||
if (typeof v === "undefined") { | ||
@@ -1556,8 +1571,38 @@ throw new Error( | ||
} | ||
store.set(k, v); | ||
/* | ||
Document requests make this a bit tricky. Since we want call middlewares | ||
on a per-Request/Response basis, we only want to call them one time on | ||
document request even though we have multiple loaders to call in parallel. | ||
That means the execution looks something like on an /a/b/c document request | ||
where A*, B*, B* are the middlewares: | ||
A loader | ||
A* -> B* -> C* -> B loader -> HTML Response -> C* -> B* -> A* | ||
C loader | ||
However, we don't want to expose the results of B's middleware context.set() | ||
calls to A's loader since it's a child of A. So we actually track context | ||
get/set calls by the match index. We associate a set value with an index, | ||
and find the value at or above our own index when calling get above. | ||
*/ | ||
let arr: [number, T][] = store.get(k) || []; | ||
arr.push([idx, v]); | ||
store.set(k, arr); | ||
}, | ||
next: () => {}, | ||
entries: () => store.entries(), | ||
}; | ||
return middlewareContext; | ||
} | ||
export function getRouteAwareMiddlewareContext( | ||
context: InternalMiddlewareContext, | ||
idx: number, | ||
next: MiddlewareContext["next"] | ||
) { | ||
let routeAwareContext: MiddlewareContext = { | ||
get: (k) => context.get(idx, k), | ||
set: (k, v) => context.set(idx, k, v), | ||
next, | ||
}; | ||
return routeAwareContext; | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1993328
18005