UNPKG

react-location

Version:
13 lines (12 loc) 24.3 kB
/** * react-location * * Copyright (c) TanStack * * 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(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactLocation={},t.React)}(this,(function(t,e){"use strict";function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var r=n(e);function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function o(t,e){if(null==t)return{};var n,r,a={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||(a[n]=t[n]);return a}function i(){return i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},i.apply(this,arguments)}function u(t,e){return u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},u(t,e)}function c(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,u(t,e)}function l(){return l=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},l.apply(this,arguments)}var s,f=s||(s={});f.Pop="POP",f.Push="PUSH",f.Replace="REPLACE";function h(t){t.preventDefault(),t.returnValue=""}function d(){var t=[];return{get length(){return t.length},push:function(e){return t.push(e),function(){t=t.filter((function(t){return t!==e}))}},call:function(e){t.forEach((function(t){return t&&t(e)}))}}}function p(){return Math.random().toString(36).substr(2,8)}function v(t){var e=t.pathname,n=t.search;return(void 0===e?"/":e)+(void 0===n?"":n)+(void 0===(t=t.hash)?"":t)}function m(t){var e={};if(t){var n=t.indexOf("#");0<=n&&(e.hash=t.substr(n),t=t.substr(0,n)),0<=(n=t.indexOf("?"))&&(e.search=t.substr(n),t=t.substr(0,n)),t&&(e.pathname=t)}return e}function g(t){function e(){var t=i.location,e=u.state||{};return[e.idx,{pathname:t.pathname,search:t.search,hash:t.hash,state:e.usr||null,key:e.key||"default"}]}function n(t){return"string"==typeof t?t:v(t)}function r(t,e){return void 0===e&&(e=null),l({},y,"string"==typeof t?m(t):t,{state:e,key:p()})}function a(t){f=t,t=e(),g=t[0],y=t[1],b.call({action:f,location:y})}function o(t){u.go(t)}void 0===t&&(t={});var i=void 0===(t=t.window)?document.defaultView:t,u=i.history,c=null;i.addEventListener("popstate",(function(){if(c)P.call(c),c=null;else{var t=s.Pop,n=e(),r=n[0];if(n=n[1],P.length){if(null!=r){var i=g-r;i&&(c={action:t,location:n,retry:function(){o(-1*i)}},o(i))}}else a(t)}}));var f=s.Pop,g=(t=e())[0],y=t[1],b=d(),P=d();return null==g&&(g=0,u.replaceState(l({},u.state,{idx:g}),"")),{get action(){return f},get location(){return y},createHref:n,push:function t(e,o){var c=s.Push,l=r(e,o);if(!P.length||(P.call({action:c,location:l,retry:function(){t(e,o)}}),0)){var f=[{usr:l.state,key:l.key,idx:g+1},n(l)];l=f[0],f=f[1];try{u.pushState(l,"",f)}catch(t){i.location.assign(f)}a(c)}},replace:function t(e,o){var i=s.Replace,c=r(e,o);P.length&&(P.call({action:i,location:c,retry:function(){t(e,o)}}),1)||(c=[{usr:c.state,key:c.key,idx:g},n(c)],u.replaceState(c[0],"",c[1]),a(i))},go:o,back:function(){o(-1)},forward:function(){o(1)},listen:function(t){return b.push(t)},block:function(t){var e=P.push(t);return 1===P.length&&i.addEventListener("beforeunload",h),function(){e(),P.length||i.removeEventListener("beforeunload",h)}}}}function y(t){function e(t,e){return void 0===e&&(e=null),l({},f,"string"==typeof t?m(t):t,{state:e,key:p()})}function n(t,e,n){return!g.length||(g.call({action:t,location:e,retry:n}),!1)}function r(t,e){c=t,f=e,h.call({action:c,location:f})}function a(t){var e=Math.min(Math.max(u+t,0),i.length-1),o=s.Pop,c=i[e];n(o,c,(function(){a(t)}))&&(u=e,r(o,c))}void 0===t&&(t={});var o=t;t=o.initialEntries,o=o.initialIndex;var i=(void 0===t?["/"]:t).map((function(t){return l({pathname:"/",search:"",hash:"",state:null,key:p()},"string"==typeof t?m(t):t)})),u=Math.min(Math.max(null==o?i.length-1:o,0),i.length-1),c=s.Pop,f=i[u],h=d(),g=d();return{get index(){return u},get action(){return c},get location(){return f},createHref:function(t){return"string"==typeof t?t:v(t)},push:function t(a,o){var c=s.Push,l=e(a,o);n(c,l,(function(){t(a,o)}))&&(u+=1,i.splice(u,i.length,l),r(c,l))},replace:function t(a,o){var c=s.Replace,l=e(a,o);n(c,l,(function(){t(a,o)}))&&(i[u]=l,r(c,l))},go:a,back:function(){a(-1)},forward:function(){a(1)},listen:function(t){return h.push(t)},block:function(t){return g.push(t)}}}var b=["children","location"],P=["location"],w=["basepath","routes"],E=["to","search","hash","children","target","style","replace","onClick","onMouseEnter","className","getActiveProps","getInactiveProps","activeOptions","preload","disabled","_ref"],x=["style","className"],M=["style","className"],k=["pending"],L=["children"];function O(t,e,n){return n?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function R(){}function S(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];try{return Promise.resolve(t.apply(this,e))}catch(t){return Promise.reject(t)}}}var A=r.createContext(null),j=r.createContext(null),C=r.createContext(null),N=Boolean("undefined"!=typeof window&&window.document&&window.document.createElement),T=N?r.useLayoutEffect:r.useEffect,_=function(){function t(){this.listeners=[]}var e=t.prototype;return e.subscribe=function(t){var e=this;return this.listeners.push(t),function(){e.listeners=e.listeners.filter((function(e){return e!==t}))}},e.notify=function(){this.listeners.forEach((function(t){return t()}))},t}(),D=function(t){function e(e){var n,r,a;return(a=t.call(this)||this).isTransitioning=!1,a.history=(null==e?void 0:e.history)||(N?g():y()),a.stringifySearch=null!=(n=null==e?void 0:e.stringifySearch)?n:ht,a.parseSearch=null!=(r=null==e?void 0:e.parseSearch)?r:dt,a.current=a.parseLocation(a.history.location),a.destroy=a.history.listen((function(t){a.current=a.parseLocation(t.location,a.current),a.notify()})),a}c(e,t);var n=e.prototype;return n.buildNext=function(t,e){var n,r,a;void 0===t&&(t="/"),void 0===e&&(e={});var o=i({},this.current,e.from),u=ut(t,o.pathname,""+(null!=(n=e.to)?n:".")),c=null!=(r=!0===e.search?o.search:nt(e.search,o.search))?r:{},l=null!=(a=e.__searchFilters)&&a.length?e.__searchFilters.reduce((function(t,e){return e(t,c)}),o.search):c,s=lt(o.search,l),f=this.stringifySearch(s),h=nt(e.hash,o.hash);return{pathname:u,search:s,searchStr:f,hash:h=h?"#"+h:"",href:""+u+f+h,key:e.key}},n.navigate=function(t,e){var n=this;this.current=t,this.navigateTimeout&&clearTimeout(this.navigateTimeout);var r="replace";this.nextAction||(r=e?"replace":"push"),e||(r="push"),this.nextAction=r,this.navigateTimeout=setTimeout((function(){var t=n.nextAction;return delete n.nextAction,n.parseLocation(n.history.location).href===n.current.href&&!n.current.key&&(t="replace"),"replace"===t?n.history.replace({pathname:n.current.pathname,hash:n.current.hash,search:n.current.searchStr}):n.history.push({pathname:n.current.pathname,hash:n.current.hash,search:n.current.searchStr})}),16)},n.parseLocation=function(t,e){var n,r=this.parseSearch(t.search);return{pathname:t.pathname,searchStr:t.search,search:lt(null==e?void 0:e.search,r),hash:null!=(n=t.hash.split("#").reverse()[0])?n:"",href:""+t.pathname+t.search+t.hash,key:t.key}},e}(_);function B(t){return r.createElement(j.Provider,t)}var H=function(t){function e(e){var n,r=e.location,u=o(e,P);return(n=t.call(this)||this).routesById={},n.update=function(t){var e=t.basepath,r=t.routes,u=o(t,w);Object.assign(a(n),u),n.basepath=at("/"+(null!=e?e:"")),n.routesById={};n.routes=function t(e,r){return e.map((function(e){var a,o,c,l,s=null!=(a=e.path)?a:"*",f=rt(["root"===(null==r?void 0:r.id)?"":null==r?void 0:r.id,(null==s?void 0:s.replace(/(.)\/$/,"$1"))+(e.id?"-"+e.id:"")]);if(e=i({},e,{pendingMs:null!=(o=e.pendingMs)?o:null==u?void 0:u.defaultPendingMs,pendingMinMs:null!=(c=e.pendingMinMs)?c:null==u?void 0:u.defaultPendingMinMs,id:f}),n.routesById[f])throw new Error;return n.routesById[f]=e,e.children=null!=(l=e.children)&&l.length?t(e.children,e):void 0,e}))}(r),n.rootMatch={id:"root",params:{},search:{},pathname:n.basepath,route:null,ownData:{},data:{},isLoading:!1,status:"resolved"}},n.setState=function(t){var e=t({state:n.state,pending:n.pending});n.state=e.state,n.pending=e.pending,n.cleanMatchCache(),n.notify()},n.matchCache={},n.cleanMatchCache=function(){var t,e,r,o,i,u=[].concat(null!=(t=null==(e=a(n))?void 0:e.state.matches)?t:[],null!=(r=null==(o=a(n))||null==(i=o.pending)?void 0:i.matches)?r:[]).map((function(t){return t.id}));Object.values(n.matchCache).forEach((function(t){var e;if(t.updatedAt&&!u.includes(t.id)){var r=Date.now()-(null!=(e=t.updatedAt)?e:0);(!t.maxAge||r>t.maxAge)&&(t.route.unloader&&t.route.unloader(t),delete n.matchCache[t.id])}}))},n.updateLocation=function(t){var e;return{promise:new Promise((function(r){var o=new z(a(n),t);n.setState((function(t){return i({},t,{pending:{location:o.location,matches:o.matches}})})),e=o.subscribe((function(){var t=n.state.matches;t.filter((function(t){return!o.matches.find((function(e){return e.id===t.id}))})).forEach((function(t){null==t.onExit||t.onExit(t)})),t.filter((function(t){return o.matches.find((function(e){return e.id===t.id}))})).forEach((function(t){null==t.route.onTransition||t.route.onTransition(t)})),o.matches.filter((function(e){return!t.find((function(t){return t.id===e.id}))})).forEach((function(t){t.onExit=null==t.route.onMatch?void 0:t.route.onMatch(t)})),n.setState((function(t){return i({},t,{state:{location:o.location,matches:o.matches},pending:void 0})})),r()})),o.loadData(),o.startPending()})),unsubscribe:e}},n.update(u),n.state={location:r.current,matches:[]},r.subscribe((function(){return n.notify()})),n}return c(e,t),e}(_);function I(){var t=r.useContext(A);return et(!!t,"useLocation must be used within a <ReactLocation />"),t.location}var U=function(t){var e=this;this.status="loading",this.ownData={},this.data={},this.isLoading=!1,this.notify=function(t){var n;null==(n=e.matchLoader)||n.preNotify(t)},this.assignMatchLoader=function(t){e.matchLoader=t},this.startPending=function(){e.pendingTimeout&&clearTimeout(e.pendingTimeout),void 0!==e.route.pendingMs&&(e.pendingTimeout=setTimeout((function(){"loading"===e.status&&(e.status="pending"),null==e.notify||e.notify(),void 0!==e.route.pendingMinMs&&(e.pendingMinPromise=new Promise((function(t){return setTimeout(t,e.route.pendingMinMs)})))}),e.route.pendingMs))},this.load=function(t){var n,r;if(e.maxAge=null!=(n=null!=(r=t.maxAge)?r:e.route.loaderMaxAge)?n:t.router.defaultLoaderMaxAge,!e.loaderPromise){var a=e.route.import;e.loaderPromise=(a?a({params:e.params,search:e.search}).then((function(t){e.route=i({},e.route,t)})):Promise.resolve()).then((function(){var n=[];["element","errorElement","pendingElement"].forEach((function(t){var r=e.route[t];e[t]||("function"==typeof r?n.push(r(e).then((function(n){e[t]=n}))):e[t]=e.route[t])}));var r=e.route.loader,a=r?new Promise(S((function(n){var a=function(t){e.status="resolved",e.ownData=t,e.error=void 0},o=function(t){console.error(t),e.status="rejected",e.error=t},i=function(){e.isLoading=!1,e.startPending=void 0,clearTimeout(undefined),n(e.ownData),null==e.notify||e.notify(!0)};return function(t){if(t&&t.then)return t.then(R)}(function(t,e){try{var n=t()}catch(t){return e(t)}return n&&n.then?n.then(void 0,e):n}((function(){return e.isLoading=!0,O(r(e,{parentMatch:t.parentMatch,dispatch:S((function(t){return"resolve"===t.type?a(t.data):"reject"===t.type?o(t.error):"loading"===t.type?e.isLoading=!0:"maxAge"===t.type&&(e.maxAge=t.maxAge),e.updatedAt=Date.now(),null==e.notify||e.notify(!0),O()}))}),(function(t){return a(t),O(e.pendingMinPromise,(function(){i()}))}))}),(function(t){o(t),i()})))}))):Promise.resolve().then((function(){e.status="resolved"}));return Promise.all([].concat(n,[a])).then((function(){e.updatedAt=Date.now()}))})).then((function(){return e.ownData}))}},Object.assign(this,t)},z=function(t){function e(e,n){var r;(r=t.call(this)||this).status="pending",r.preNotify=function(t){var e;t||(r.status="resolved"),null==(e=r.matches)||e.forEach((function(t,n){var r,a=null==e?void 0:e[n-1];t.data=i({},null!=(r=null==a?void 0:a.data)?r:{},t.ownData)})),r.notify()},r.loadData=S((function(t){var e,n=(void 0===t?{}:t).maxAge;if(r.router.cleanMatchCache(),null!=(e=r.matches)&&e.length)return r.firstRenderPromises=[],r.matches.forEach((function(t,e){var o,i,u=null==(o=r.matches)?void 0:o[e-1];null==t.assignMatchLoader||t.assignMatchLoader(a(r)),null==t.load||t.load({maxAge:n,parentMatch:u,router:r.router}),null==(i=r.firstRenderPromises)||i.push(t.loaderPromise)})),Promise.all(r.firstRenderPromises).then((function(){return r.preNotify(),r.matches}));r.preNotify()})),r.load=S((function(t){var e=(void 0===t?{}:t).maxAge;return r.loadData({maxAge:e})})),r.startPending=S((function(){return r.matches.forEach((function(t){return null==t.startPending?void 0:t.startPending()})),O()})),r.router=e,r.location=n,r.matches=[];var o=K(r.router,r.location);return r.matches=null==o?void 0:o.map((function(t){return r.router.matchCache[t.id]||(r.router.matchCache[t.id]=new U(t)),r.router.matchCache[t.id]})),r}return c(e,t),e}(_);function F(){var t=r.useContext(C);if(!t)throw et(!0,"You are trying to use useRouter() outside of ReactLocation!"),new Error;return t.router}function K(t,e){if(!t.routes.length)return[];var n=[],r=S((function(a,o){var u,c=o.pathname,l=o.params,s=(null!=t&&t.filterRoutes?null==t?void 0:t.filterRoutes(a):a).find((function(n){var r,a,o=rt([c,n.path]),u=!!("/"!==n.path||null!=(r=n.children)&&r.length),s=X(e,{to:o,search:n.search,fuzzy:u,caseSensitive:null!=(a=n.caseSensitive)?a:t.caseSensitive});return s&&(l=i({},l,s)),!!s}));if(s){var f=V(s.path,l);c=rt([c,f]);var h={id:V(s.id,l,!0),route:s,params:l,pathname:c,search:e.search};return n.push(h),null!=(u=s.children)&&u.length&&r(s.children,h),O()}}));return r(t.routes,t.rootMatch),n}function V(t,e,n){return rt(it(t).map((function(t){return"*"!==t.value||n?"param"===t.type?null!=(r=e[t.value.substring(1)])?r:"":t.value:"";var r})))}function q(){var t=I(),e=$(),n=F(),r=Y();return ct(S((function(a,o){var u;void 0===a&&(a=t.current);var c=r(i({},a,{from:null!=(u=a.from)?u:{pathname:e.pathname}}));return new z(n,c).load(o)})))}function J(){return r.useContext(j)}function $(){var t;return null==(t=J())?void 0:t[0]}function W(){var t=I(),e=$(),n=Y();return ct((function(r){var a,o=r.search,i=r.hash,u=r.replace,c=r.from,l=r.to,s=r.fromCurrent;s=null!=(a=s)?a:void 0===l;var f=n({to:l,search:o,hash:i,from:s?t.current:null!=c?c:{pathname:e.pathname}});t.navigate(f,u)}))}function Y(){var t=I(),e=F();return ct((function(n){var r=t.buildNext(e.basepath,n),a=K(e,r).map((function(t){var e;return null!=(e=t.route.searchFilters)?e:[]})).flat().filter(Boolean);return t.buildNext(e.basepath,i({},n,{__searchFilters:a}))}))}function G(){var t,e=F(),n=J();n[0];var a=n.slice(1),o=a[0];if(!o)return null;var i=null!=(t=o.errorElement)?t:e.defaultErrorElement,u=function(){var t,n;if("rejected"===o.status){if(i)return i;if(!e.useErrorBoundary)return"An unknown error occured!";throw o.error}var a=null!=(t=o.pendingElement)?t:e.defaultPendingElement;if("loading"===o.status)return null;if("pending"===o.status&&(o.route.pendingMs||a))return null!=a?a:null;var u=null!=(n=o.element)?n:e.defaultElement;return null!=u?u:r.createElement(G,null)}();return r.createElement(B,{value:a},u)}function Q(){var t=F(),e=$();return ct((function(n){return ut(t.basepath,e.pathname,at(n))}))}function X(t,e){var n=ot(t,e),r=function(t,e){return!(!e.search||!e.search(t.search))}(t,e);if((!e.to||n)&&(!e.search||r))return null!=n?n:{}}function Z(){var t=F(),e=Q();return ct((function(n){var r=n.pending,a=o(n,k);if(a=i({},a,{to:a.to?e(""+a.to):void 0}),r){var u;if(null==(u=t.pending)||!u.location)return;return X(t.pending.location,a)}return X(t.state.location,a)}))}function tt(t,e){var n=I();r.useEffect((function(){if(e){var r=n.history.block((function(e){window.confirm(t)?(r(),e.retry()):n.current.pathname=window.location.pathname}));return r}}),[e,n,t])}function et(t,e){if(!t){"undefined"!=typeof console&&console.warn(e);try{throw new Error(e)}catch(t){}}}function nt(t,e){return"function"==typeof t?t(e):t}function rt(t){return at(t.filter(Boolean).join("/"))}function at(t){return(""+t).replace(/\/{2,}/g,"/")}function ot(t,e){var n,r=it(t.pathname),a=it(""+(null!=(n=e.to)?n:"*")),o={};return function(){for(var t=0;t<Math.max(r.length,a.length);t++){var n=r[t],i=a[t],u=t===a.length-1,c=t===r.length-1;if(i){if("wildcard"===i.type)return!(null==n||!n.value)&&(o["*"]=rt(r.slice(t).map((function(t){return t.value}))),!0);if("pathname"===i.type){if("/"===i.value&&(null==n||!n.value))return!0;if(n)if(e.caseSensitive){if(i.value!==n.value)return!1}else if(i.value.toLowerCase()!==n.value.toLowerCase())return!1}if(!n)return!1;"param"===i.type&&(o[i.value.substring(1)]=n.value)}if(u&&!c)return!!e.fuzzy}return!0}()?o:void 0}function it(t){if(!t)return[];var e=[];if("/"===(t=at(t)).slice(0,1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),!t)return e;var n=t.split("/").filter(Boolean);return e.push.apply(e,n.map((function(t){return t.startsWith("*")?{type:"wildcard",value:t}:":"===t.charAt(0)?{type:"param",value:t}:{type:"pathname",value:t}}))),"/"===t.slice(-1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),e}function ut(t,e,n){e=e.replace(new RegExp("^"+t),"/"),n=n.replace(new RegExp("^"+t),"/");var r=it(e),a=it(n);return a.forEach((function(t,e){if("/"===t.value)e?e===a.length-1&&r.push(t):r=[t];else if(".."===t.value)r.pop();else{if("."===t.value)return;r.push(t)}})),at(rt([t].concat(r.map((function(t){return t.value})))))}function ct(t){var e=r.useRef(),n=r.useRef(t);return n.current=t,e.current||(e.current=function(){return n.current.apply(n,arguments)}),e.current}function lt(t,e){if(t===e)return t;var n=Array.isArray(t)&&Array.isArray(e);if(n||st(t)&&st(e)){for(var r=n?t.length:Object.keys(t).length,a=n?e:Object.keys(e),o=a.length,i=n?[]:{},u=0,c=0;c<o;c++){var l=n?c:a[c];i[l]=lt(t[l],e[l]),i[l]===t[l]&&u++}return r===o&&u===r?t:i}return e}function st(t){if(!ft(t))return!1;var e=t.constructor;if(void 0===e)return!0;var n=e.prototype;return!!ft(n)&&!!n.hasOwnProperty("isPrototypeOf")}function ft(t){return"[object Object]"===Object.prototype.toString.call(t)}function ht(t){(t=i({},t))&&Object.keys(t).forEach((function(e){var n=t[e];if(void 0===n||void 0===n)delete t[e];else if(n&&"object"==typeof n&&null!==n)try{t[e]=JSON.stringify(n)}catch(t){}}));var e=new URLSearchParams(t).toString();return e?"?"+e:""}function dt(t){"?"===t.substring(0,1)&&(t=t.substring(1));var e=Object.fromEntries(new URLSearchParams(t).entries());for(var n in e){var r=e[n];try{e[n]=JSON.parse(r)}catch(t){}}return e}t.Link=function(t){var e,n=t.to,a=void 0===n?".":n,u=t.search,c=t.hash,l=t.children,s=t.target,f=t.style,h=void 0===f?{}:f,d=t.replace,p=t.onClick,v=t.onMouseEnter,m=t.className,g=void 0===m?"":m,y=t.getActiveProps,b=void 0===y?function(){return{}}:y,P=t.getInactiveProps,w=void 0===P?function(){return{}}:P,k=t.activeOptions,L=t.preload,O=t.disabled,R=t._ref,S=o(t,E),A=q(),j=$(),C=I(),N=F(),T=W(),_=Y();L=null!=(e=L)?e:N.defaultLinkPreloadMaxAge;try{et(!1,"<Link /> should not be used for external URLs like: "+new URL(""+a).href)}catch(t){}var D=_({to:a,search:u,hash:c,from:{pathname:j.pathname}}),B=C.current.pathname===D.pathname,H=C.current.pathname.split("/"),U=D.pathname.split("/").every((function(t,e){return t===H[e]})),z=C.current.hash===D.hash,K=null!=k&&k.exact?B:U,V=null==k||!k.includeHash||z,J=K&&V,G=J?b():{},Q=G.style,X=void 0===Q?{}:Q,Z=G.className,tt=void 0===Z?"":Z,nt=o(G,x),rt=J?{}:w(),at=rt.style,ot=void 0===at?{}:at,it=rt.className,ut=void 0===it?"":it,ct=o(rt,M);return r.createElement("a",i({ref:R,href:O?void 0:D.href,onClick:function(t){p&&p(t),function(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}(t)||t.defaultPrevented||s&&"_self"!==s||0!==t.button||(t.preventDefault(),T({to:a,search:u,hash:c,replace:d,from:{pathname:j.pathname}}))},onMouseEnter:function(t){v&&v(t),L&&L>0&&A({to:a,search:u,hash:c},{maxAge:L})},target:s,style:i({},h,X,ot),className:[g,tt,ut].filter(Boolean).join(" ")||void 0},O?{role:"link","aria-disabled":!0}:void 0,S,nt,ct,{children:"function"==typeof l?l({isActive:J}):l}))},t.MatchRoute=function(t){var e=t.children,n=o(t,L),r=Z()(n);return"function"==typeof e?e(r):r?e:null},t.MatchesProvider=B,t.Navigate=function(t){var e=W();return T((function(){e(t)}),[e]),null},t.Outlet=G,t.Prompt=function(t){var e=t.message,n=t.when,r=t.children;return tt(e,null==n||n),null!=r?r:null},t.ReactLocation=D,t.RouteMatch=U,t.Router=function(t){var e=t.children,n=t.location,a=o(t,b),i=r.useRef(null);i.current||(i.current=new H({location:n,routes:a.routes}));var u=i.current,c=r.useReducer((function(){return{}}),{}),l=c[0],s=c[1];u.update(a),T((function(){return u.subscribe((function(){s()}))}),[]),T((function(){return u.updateLocation(n.current).unsubscribe}),[n.current.key]);var f=r.useMemo((function(){return{router:u}}),[l]);return r.createElement(A.Provider,{value:{location:n}},r.createElement(C.Provider,{value:f},r.createElement(B,{value:[u.rootMatch].concat(u.state.matches)},null!=e?e:r.createElement(G,null))))},t.RouterInstance=H,t.cleanPath=at,t.createBrowserHistory=g,t.createHashHistory=function(t){function e(){var t=m(u.location.hash.substr(1)),e=t.pathname,n=t.search;t=t.hash;var r=c.state||{};return[r.idx,{pathname:void 0===e?"/":e,search:void 0===n?"":n,hash:void 0===t?"":t,state:r.usr||null,key:r.key||"default"}]}function n(){if(f)w.call(f),f=null;else{var t=s.Pop,n=e(),r=n[0];if(n=n[1],w.length){if(null!=r){var a=y-r;a&&(f={action:t,location:n,retry:function(){i(-1*a)}},i(a))}}else o(t)}}function r(t){var e=document.querySelector("base"),n="";return e&&e.getAttribute("href")&&(n=-1===(n=(e=u.location.href).indexOf("#"))?e:e.slice(0,n)),n+"#"+("string"==typeof t?t:v(t))}function a(t,e){return void 0===e&&(e=null),l({},b,"string"==typeof t?m(t):t,{state:e,key:p()})}function o(t){g=t,t=e(),y=t[0],b=t[1],P.call({action:g,location:b})}function i(t){c.go(t)}void 0===t&&(t={});var u=void 0===(t=t.window)?document.defaultView:t,c=u.history,f=null;u.addEventListener("popstate",n),u.addEventListener("hashchange",(function(){v(e()[1])!==v(b)&&n()}));var g=s.Pop,y=(t=e())[0],b=t[1],P=d(),w=d();return null==y&&(y=0,c.replaceState(l({},c.state,{idx:y}),"")),{get action(){return g},get location(){return b},createHref:r,push:function t(e,n){var i=s.Push,l=a(e,n);if(!w.length||(w.call({action:i,location:l,retry:function(){t(e,n)}}),0)){var f=[{usr:l.state,key:l.key,idx:y+1},r(l)];l=f[0],f=f[1];try{c.pushState(l,"",f)}catch(t){u.location.assign(f)}o(i)}},replace:function t(e,n){var i=s.Replace,u=a(e,n);w.length&&(w.call({action:i,location:u,retry:function(){t(e,n)}}),1)||(u=[{usr:u.state,key:u.key,idx:y},r(u)],c.replaceState(u[0],"",u[1]),o(i))},go:i,back:function(){i(-1)},forward:function(){i(1)},listen:function(t){return P.push(t)},block:function(t){var e=w.push(t);return 1===w.length&&u.addEventListener("beforeunload",h),function(){e(),w.length||u.removeEventListener("beforeunload",h)}}}},t.createMemoryHistory=y,t.defaultParseSearch=dt,t.defaultStringifySearch=ht,t.functionalUpdate=nt,t.matchByPath=ot,t.matchRoute=X,t.matchRoutes=K,t.parsePathname=it,t.resolvePath=ut,t.useLoadRoute=q,t.useLocation=I,t.useMatch=$,t.useMatchRoute=Z,t.useMatches=J,t.useNavigate=W,t.useParentMatches=function(){var t=F(),e=$(),n=t.state.matches;return n.slice(0,n.findIndex((function(t){return t.id===e.id}))-1)},t.usePrompt=tt,t.useResolvePath=Q,t.useRouter=F,t.useSearch=function(){return I().current.search},Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=index.production.js.map