/** * React Router v6.2.2 * * Copyright (c) Remix Software Inc. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("history")):"function"==typeof define&&define.amd?define(["exports","react","history"],t):t((e=e||self).ReactRouter={},e.React,e.HistoryLibrary)}(this,(function(e,t,n){"use strict";function a(e,t){if(!e)throw new Error(t)}const r=t.createContext(null),i=t.createContext(null),l=t.createContext({outlet:null,matches:[]});function o(e){a(!1)}function s(e){let{basename:l="/",children:o=null,location:s,navigationType:c=n.Action.Pop,navigator:h,static:p=!1}=e;u()&&a(!1);let f=N(l),m=t.useMemo((()=>({basename:f,navigator:h,static:p})),[f,h,p]);"string"==typeof s&&(s=n.parsePath(s));let{pathname:d="/",search:g="",hash:v="",state:y=null,key:x="default"}=s,P=t.useMemo((()=>{let e=O(d,f);return null==e?null:{pathname:e,search:g,hash:v,state:y,key:x}}),[f,d,g,v,y,x]);return null==P?null:t.createElement(r.Provider,{value:m},t.createElement(i.Provider,{children:o,value:{location:P,navigationType:c}}))}function u(){return null!=t.useContext(i)}function c(){return u()||a(!1),t.useContext(i).location}function h(){u()||a(!1);let{basename:e,navigator:n}=t.useContext(r),{matches:i}=t.useContext(l),{pathname:o}=c(),s=JSON.stringify(i.map((e=>e.pathnameBase))),h=t.useRef(!1);return t.useEffect((()=>{h.current=!0})),t.useCallback((function(t,a){if(void 0===a&&(a={}),!h.current)return;if("number"==typeof t)return void n.go(t);let r=$(t,JSON.parse(s),o);"/"!==e&&(r.pathname=M([e,r.pathname])),(a.replace?n.replace:n.push)(r,a.state)}),[e,n,s,o])}const p=t.createContext(null);function f(e){let n=t.useContext(l).outlet;return n?t.createElement(p.Provider,{value:e},n):n}function m(e){let{matches:n}=t.useContext(l),{pathname:a}=c(),r=JSON.stringify(n.map((e=>e.pathnameBase)));return t.useMemo((()=>$(e,JSON.parse(r),a)),[e,r,a])}function d(e,r){u()||a(!1);let i,{matches:o}=t.useContext(l),s=o[o.length-1],h=s?s.params:{},p=(s&&s.pathname,s?s.pathnameBase:"/"),f=(s&&s.route,c());if(r){var m;let e="string"==typeof r?n.parsePath(r):r;"/"===p||(null==(m=e.pathname)?void 0:m.startsWith(p))||a(!1),i=e}else i=f;let d=i.pathname||"/",g=v(e,{pathname:"/"===p?d:d.slice(p.length)||"/"});return E(g&&g.map((e=>Object.assign({},e,{params:Object.assign({},h,e.params),pathname:M([p,e.pathname]),pathnameBase:"/"===e.pathnameBase?p:M([p,e.pathnameBase])}))),o)}function g(e){let n=[];return t.Children.forEach(e,(e=>{if(!t.isValidElement(e))return;if(e.type===t.Fragment)return void n.push.apply(n,g(e.props.children));e.type!==o&&a(!1);let r={caseSensitive:e.props.caseSensitive,element:e.props.element,index:e.props.index,path:e.props.path};e.props.children&&(r.children=g(e.props.children)),n.push(r)})),n}function v(e,t,a){void 0===a&&(a="/");let r=O(("string"==typeof t?n.parsePath(t):t).pathname||"/",a);if(null==r)return null;let i=y(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,n)=>e===t[n]))?e[e.length-1]-t[t.length-1]:0}(e.routesMeta.map((e=>e.childrenIndex)),t.routesMeta.map((e=>e.childrenIndex)))))}(i);let l=null;for(let e=0;null==l&&e{let l={relativePath:e.path||"",caseSensitive:!0===e.caseSensitive,childrenIndex:i,route:e};l.relativePath.startsWith("/")&&(l.relativePath.startsWith(r)||a(!1),l.relativePath=l.relativePath.slice(r.length));let o=M([r,l.relativePath]),s=n.concat(l);e.children&&e.children.length>0&&(!0===e.index&&a(!1),y(e.children,t,s,o)),(null!=e.path||e.index)&&t.push({path:o,score:C(o,e.index),routesMeta:s})})),t}const x=/^:\w+$/,P=e=>"*"===e;function C(e,t){let n=e.split("/"),a=n.length;return n.some(P)&&(a+=-2),t&&(a+=2),n.filter((e=>!P(e))).reduce(((e,t)=>e+(x.test(t)?3:""===t?1:10)),a)}function b(e,t){let{routesMeta:n}=e,a={},r="/",i=[];for(let e=0;et.createElement(l.Provider,{children:void 0!==r.route.element?r.route.element:a,value:{outlet:a,matches:n.concat(e.slice(0,i+1))}})),null)}function R(e,t){"string"==typeof e&&(e={path:e,caseSensitive:!1,end:!0});let[n,a]=function(e,t,n){void 0===t&&(t=!1);void 0===n&&(n=!0);let a=[],r="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^$?{}|()[\]]/g,"\\$&").replace(/:(\w+)/g,((e,t)=>(a.push(t),"([^\\/]+)")));e.endsWith("*")?(a.push("*"),r+="*"===e||"/*"===e?"(.*)$":"(?:\\/(.+)|\\/*)$"):r+=n?"\\/*$":"(?:(?=[.~-]|%[0-9A-F]{2})|\\b|\\/|$)";return[new RegExp(r,t?void 0:"i"),a]}(e.path,e.caseSensitive,e.end),r=t.match(n);if(!r)return null;let i=r[0],l=i.replace(/(.)\/+$/,"$1"),o=r.slice(1);return{params:a.reduce(((e,t,n)=>{if("*"===t){let e=o[n]||"";l=i.slice(0,i.length-e.length).replace(/(.)\/+$/,"$1")}return e[t]=function(e,t){try{return decodeURIComponent(e)}catch(t){return e}}(o[n]||""),e}),{}),pathname:i,pathnameBase:l,pattern:e}}function S(e,t){void 0===t&&(t="/");let{pathname:a,search:r="",hash:i=""}="string"==typeof e?n.parsePath(e):e,l=a?a.startsWith("/")?a:function(e,t){let n=t.replace(/\/+$/,"").split("/");return e.split("/").forEach((e=>{".."===e?n.length>1&&n.pop():"."!==e&&n.push(e)})),n.length>1?n.join("/"):"/"}(a,t):t;return{pathname:l,search:W(r),hash:j(i)}}function $(e,t,a){let r,i="string"==typeof e?n.parsePath(e):e,l=""===e||""===i.pathname?"/":i.pathname;if(null==l)r=a;else{let e=t.length-1;if(l.startsWith("..")){let t=l.split("/");for(;".."===t[0];)t.shift(),e-=1;i.pathname=t.join("/")}r=e>=0?t[e]:"/"}let o=S(i,r);return l&&"/"!==l&&l.endsWith("/")&&!o.pathname.endsWith("/")&&(o.pathname+="/"),o}function O(e,t){if("/"===t)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=e.charAt(t.length);return n&&"/"!==n?null:e.slice(t.length)||"/"}const M=e=>e.join("/").replace(/\/\/+/g,"/"),N=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),W=e=>e&&"?"!==e?e.startsWith("?")?e:"?"+e:"",j=e=>e&&"#"!==e?e.startsWith("#")?e:"#"+e:"";Object.defineProperty(e,"NavigationType",{enumerable:!0,get:function(){return n.Action}}),Object.defineProperty(e,"createPath",{enumerable:!0,get:function(){return n.createPath}}),Object.defineProperty(e,"parsePath",{enumerable:!0,get:function(){return n.parsePath}}),e.MemoryRouter=function(e){let{basename:a,children:r,initialEntries:i,initialIndex:l}=e,o=t.useRef();null==o.current&&(o.current=n.createMemoryHistory({initialEntries:i,initialIndex:l}));let u=o.current,[c,h]=t.useState({action:u.action,location:u.location});return t.useLayoutEffect((()=>u.listen(h)),[u]),t.createElement(s,{basename:a,children:r,location:c.location,navigationType:c.action,navigator:u})},e.Navigate=function(e){let{to:n,replace:r,state:i}=e;u()||a(!1);let l=h();return t.useEffect((()=>{l(n,{replace:r,state:i})})),null},e.Outlet=function(e){return f(e.context)},e.Route=o,e.Router=s,e.Routes=function(e){let{children:t,location:n}=e;return d(g(t),n)},e.UNSAFE_LocationContext=i,e.UNSAFE_NavigationContext=r,e.UNSAFE_RouteContext=l,e.createRoutesFromChildren=g,e.generatePath=function(e,t){return void 0===t&&(t={}),e.replace(/:(\w+)/g,((e,n)=>(null==t[n]&&a(!1),t[n]))).replace(/\/*\*$/,(e=>null==t["*"]?"":t["*"].replace(/^\/*/,"/")))},e.matchPath=R,e.matchRoutes=v,e.renderMatches=function(e){return E(e)},e.resolvePath=S,e.useHref=function(e){u()||a(!1);let{basename:i,navigator:l}=t.useContext(r),{hash:o,pathname:s,search:c}=m(e),h=s;if("/"!==i){let t=function(e){return""===e||""===e.pathname?"/":"string"==typeof e?n.parsePath(e).pathname:e.pathname}(e),a=null!=t&&t.endsWith("/");h="/"===s?i+(a?"/":""):M([i,s])}return l.createHref({pathname:h,search:c,hash:o})},e.useInRouterContext=u,e.useLocation=c,e.useMatch=function(e){u()||a(!1);let{pathname:n}=c();return t.useMemo((()=>R(e,n)),[n,e])},e.useNavigate=h,e.useNavigationType=function(){return t.useContext(i).navigationType},e.useOutlet=f,e.useOutletContext=function(){return t.useContext(p)},e.useParams=function(){let{matches:e}=t.useContext(l),n=e[e.length-1];return n?n.params:{}},e.useResolvedPath=m,e.useRoutes=d,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=react-router.production.min.js.map