13 lines
7.7 KiB
JavaScript
13 lines
7.7 KiB
JavaScript
|
/**
|
||
|
* React Router v6.3.0
|
||
|
*
|
||
|
* 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
|
||
|
*/
|
||
|
import{parsePath as e,createMemoryHistory as t,Action as n}from"history";export{Action as NavigationType,createPath,parsePath}from"history";import{createContext as a,useContext as r,useMemo as l,useRef as i,useEffect as s,useCallback as o,createElement as h,useState as c,useLayoutEffect as u,Children as p,isValidElement as m,Fragment as f}from"react";const g=a(null),d=a(null),v=a({outlet:null,matches:[]});function y(e,t){if(!e)throw new Error(t)}function x(e,t={}){return e.replace(/:(\w+)/g,((e,n)=>(null==t[n]&&y(!1),t[n]))).replace(/\/*\*$/,(e=>null==t["*"]?"":t["*"].replace(/^\/*/,"/")))}function S(t,n,a="/"){let r=O(("string"==typeof n?e(n):n).pathname||"/",a);if(null==r)return null;let l=$(t);!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)))))}(l);let i=null;for(let e=0;null==i&&e<l.length;++e)i=B(l[e],r);return i}function $(e,t=[],n=[],a=""){return e.forEach(((e,r)=>{let l={relativePath:e.path||"",caseSensitive:!0===e.caseSensitive,childrenIndex:r,route:e};l.relativePath.startsWith("/")&&(l.relativePath.startsWith(a)||y(!1),l.relativePath=l.relativePath.slice(a.length));let i=j([a,l.relativePath]),s=n.concat(l);e.children&&e.children.length>0&&(!0===e.index&&y(!1),$(e.children,t,s,i)),(null!=e.path||e.index)&&t.push({path:i,score:b(i,e.index),routesMeta:s})})),t}const P=/^:\w+$/,W=e=>"*"===e;function b(e,t){let n=e.split("/"),a=n.length;return n.some(W)&&(a+=-2),t&&(a+=2),n.filter((e=>!W(e))).reduce(((e,t)=>e+(P.test(t)?3:""===t?1:10)),a)}function B(e,t){let{routesMeta:n}=e,a={},r="/",l=[];for(let i=0;i<n.length;++i){let e=n[i],s=i===n.length-1,o="/"===r?t:t.slice(r.length)||"/",h=E({path:e.relativePath,caseSensitive:e.caseSensitive,end:s},o);if(!h)return null;Object.assign(a,h.params);let c=e.route;l.push({params:a,pathname:j([r,h.pathname]),pathnameBase:A(j([r,h.pathnameBase])),route:c}),"/"!==h.pathnameBase&&(r=j([r,h.pathnameBase]))}return l}function E(e,t){"string"==typeof e&&(e={path:e,caseSensitive:!1,end:!0});let[n,a]=function(e,t=!1,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 l=r[0],i=l.replace(/(.)\/+$/,"$1"),s=r.slice(1);return{params:a.reduce(((e,t,n)=>{if("*"===t){let e=s[n]||"";i=l.slice(0,l.length-e.length).replace(/(.)\/+$/,"$1")}return e[t]=function(e,t){try{return decodeURIComponent(e)}catch(n){return e}}(s[n]||""),e}),{}),pathname:l,pathnameBase:i,pattern:e}}function N(t,n="/"){let{pathname:a,search:r="",hash:l=""}="string"==typeof t?e(t):t,i=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,n):n;return{pathname:i,search:C(r),hash:I(l)}}function w(t,n,a){let r,l="string"==typeof t?e(t):t,i=""===t||""===l.pathname?"/":l.pathname;if(null==i)r=a;else{let e=n.length-1;if(i.startsWith("..")){let t=i.split("/");for(;".."===t[0];)t.shift(),e-=1;l.pathname=t.join("/")}r=e>=0?n[e]:"/"}let s=N(l,r);return i&&"/"!==i&&i.endsWith("/")&&!s.pathname.endsWith("/")&&(s.pathname+="/"),s}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 j=e=>e.join("/").replace(/\/\/+/g,"/"),A=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),C=e=>e&&"?"!==e?e.startsWith("?")?e:"?"+e:"",I=e=>e&&"#"!==e?e.startsWith("#")?e:"#"+e:"";function T(t){F()||y(!1);let{basename:n,navigator:a}=r(g),{hash:l,pathname:i,search:s}=q(t),o=i;if("/"!==n){let a=function(t){return""===t||""===t.pathname?"/":"string"==typeof t?e(t).pathname:t.pathname}(t),r=null!=
|
||
|
//# sourceMappingURL=react-router.production.min.js.map
|