"use strict";!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).HistoryLibrary={})}(this,(function(t){function n(){return(n=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e,o=arguments[n];for(e in o)Object.prototype.hasOwnProperty.call(o,e)&&(t[e]=o[e])}return t}).apply(this,arguments)}function e(t){t.preventDefault(),t.returnValue=""}function o(){var t=[];return{get length(){return t.length},push:function(n){return t.push(n),function(){t=t.filter((function(t){return t!==n}))}},call:function(n){t.forEach((function(t){return t&&t(n)}))}}}function r(){return Math.random().toString(36).substr(2,8)}function i(t){var n=t.pathname,e=t.search;return(void 0===n?"/":n)+(void 0===e?"":e)+(void 0===(t=t.hash)?"":t)}function a(t){var n={};if(t){var e=t.indexOf("#");0<=e&&(n.hash=t.substr(e),t=t.substr(0,e)),0<=(e=t.indexOf("?"))&&(n.search=t.substr(e),t=t.substr(0,e)),t&&(n.pathname=t)}return n}var c;t.Action=void 0,(c=t.Action||(t.Action={})).Pop="POP",c.Push="PUSH",c.Replace="REPLACE",t.createBrowserHistory=function(c){function u(){var t=d.location,n=p.state||{};return[n.idx,{pathname:t.pathname,search:t.search,hash:t.hash,state:n.usr||null,key:n.key||"default"}]}function l(t){return"string"==typeof t?t:i(t)}function s(t,e){return void 0===e&&(e=null),n({},b,"string"==typeof t?a(t):t,{state:e,key:r()})}function f(t){y=t,t=u(),g=t[0],b=t[1],k.call({action:y,location:b})}function h(t){p.go(t)}void 0===c&&(c={});var d=void 0===(c=c.window)?document.defaultView:c,p=d.history,v=null;d.addEventListener("popstate",(function(){if(v)m.call(v),v=null;else{var n=t.Action.Pop,e=u(),o=e[0];if(e=e[1],m.length){if(null!=o){var r=g-o;r&&(v={action:n,location:e,retry:function(){h(-1*r)}},h(r))}}else f(n)}}));var y=t.Action.Pop,g=(c=u())[0],b=c[1],k=o(),m=o();return null==g&&(g=0,p.replaceState(n({},p.state,{idx:g}),"")),{get action(){return y},get location(){return b},createHref:l,push:function n(e,o){var r=t.Action.Push,i=s(e,o);if(!m.length||(m.call({action:r,location:i,retry:function(){n(e,o)}}),0)){var a=[{usr:i.state,key:i.key,idx:g+1},l(i)];i=a[0],a=a[1];try{p.pushState(i,"",a)}catch(t){d.location.assign(a)}f(r)}},replace:function n(e,o){var r=t.Action.Replace,i=s(e,o);m.length&&(m.call({action:r,location:i,retry:function(){n(e,o)}}),1)||(i=[{usr:i.state,key:i.key,idx:g},l(i)],p.replaceState(i[0],"",i[1]),f(r))},go:h,back:function(){h(-1)},forward:function(){h(1)},listen:function(t){return k.push(t)},block:function(t){var n=m.push(t);return 1===m.length&&d.addEventListener("beforeunload",e),function(){n(),m.length||d.removeEventListener("beforeunload",e)}}}},t.createHashHistory=function(c){function u(){var t=a(p.location.hash.substr(1)),n=t.pathname,e=t.search;t=t.hash;var o=v.state||{};return[o.idx,{pathname:void 0===n?"/":n,search:void 0===e?"":e,hash:void 0===t?"":t,state:o.usr||null,key:o.key||"default"}]}function l(){if(y)P.call(y),y=null;else{var n=t.Action.Pop,e=u(),o=e[0];if(e=e[1],P.length){if(null!=o){var r=b-o;r&&(y={action:n,location:e,retry:function(){d(-1*r)}},d(r))}}else h(n)}}function s(t){var n=document.querySelector("base"),e="";return n&&n.getAttribute("href")&&(e=-1===(e=(n=p.location.href).indexOf("#"))?n:n.slice(0,e)),e+"#"+("string"==typeof t?t:i(t))}function f(t,e){return void 0===e&&(e=null),n({},k,"string"==typeof t?a(t):t,{state:e,key:r()})}function h(t){g=t,t=u(),b=t[0],k=t[1],m.call({action:g,location:k})}function d(t){v.go(t)}void 0===c&&(c={});var p=void 0===(c=c.window)?document.defaultView:c,v=p.history,y=null;p.addEventListener("popstate",l),p.addEventListener("hashchange",(function(){i(u()[1])!==i(k)&&l()}));var g=t.Action.Pop,b=(c=u())[0],k=c[1],m=o(),P=o();return null==b&&(b=0,v.replaceState(n({},v.state,{idx:b}),"")),{get action(){return g},get location(){return k},createHref:s,push:function n(e,o){var r=t.Action.Push,i=f(e,o);if(!P.length||(P.call({action:r,location:i,retry:function(){n(e,o)}}),0)){var a=[{usr:i.state,key:i.key,idx:b+1},s(i)];i=a[0],a=a[1];try{v.pushState(i,"",a)}catch(t){p.location.assign(a)}h(r)}},replace:function n(e,o){var r=t.Action.Replace,i=f(e,o);P.length&&(P.call({action:r,location:i,retry:function(){n(e,o)}}),1)||(i=[{usr:i.state,key:i.key,idx:b},s(i)],v.replaceState(i[0],"",i[1]),h(r))},go:d,back:function(){d(-1)},forward:function(){d(1)},listen:function(t){return m.push(t)},block:function(t){var n=P.push(t);return 1===P.length&&p.addEventListener("beforeunload",e),function(){n(),P.length||p.removeEventListener("beforeunload",e)}}}},t.createMemoryHistory=function(e){function c(t,e){return void 0===e&&(e=null),n({},v,"string"==typeof t?a(t):t,{state:e,key:r()})}function u(t,n,e){return!g.length||(g.call({action:t,location:n,retry:e}),!1)}function l(t,n){p=t,v=n,y.call({action:p,location:v})}function s(n){var e=Math.min(Math.max(d+n,0),h.length-1),o=t.Action.Pop,r=h[e];u(o,r,(function(){s(n)}))&&(d=e,l(o,r))}void 0===e&&(e={});var f=e;e=f.initialEntries,f=f.initialIndex;var h=(void 0===e?["/"]:e).map((function(t){return n({pathname:"/",search:"",hash:"",state:null,key:r()},"string"==typeof t?a(t):t)})),d=Math.min(Math.max(null==f?h.length-1:f,0),h.length-1),p=t.Action.Pop,v=h[d],y=o(),g=o();return{get index(){return d},get action(){return p},get location(){return v},createHref:function(t){return"string"==typeof t?t:i(t)},push:function n(e,o){var r=t.Action.Push,i=c(e,o);u(r,i,(function(){n(e,o)}))&&(d+=1,h.splice(d,h.length,i),l(r,i))},replace:function n(e,o){var r=t.Action.Replace,i=c(e,o);u(r,i,(function(){n(e,o)}))&&(h[d]=i,l(r,i))},go:s,back:function(){s(-1)},forward:function(){s(1)},listen:function(t){return y.push(t)},block:function(t){return g.push(t)}}},t.createPath=i,t.parsePath=a,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=history.production.min.js.map
