Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

history

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

history - npm Package Compare versions

Comparing version 5.2.0 to 5.3.0-pre.0

404

browser.js

@@ -1,8 +0,398 @@

function p(){p=Object.assign||function(c){for(var f=1;f<arguments.length;f++){var g=arguments[f],m;for(m in g)Object.prototype.hasOwnProperty.call(g,m)&&(c[m]=g[m])}return c};return p.apply(this,arguments)}var u,x=u||(u={});x.Pop="POP";x.Push="PUSH";x.Replace="REPLACE";var A="production"!==process.env.NODE_ENV?function(c){return Object.freeze(c)}:function(c){return c};function B(c,f){if(!c){"undefined"!==typeof console&&console.warn(f);try{throw Error(f);}catch(g){}}}
function C(c){c.preventDefault();c.returnValue=""}function G(){var c=[];return{get length(){return c.length},push:function(f){c.push(f);return function(){c=c.filter(function(g){return g!==f})}},call:function(f){c.forEach(function(g){return g&&g(f)})}}}
var H=function(c){function f(){var a=q.location,b=r.state||{};return[b.idx,A({pathname:a.pathname,search:a.search,hash:a.hash,state:b.usr||null,key:b.key||"default"})]}function g(a){if("string"===typeof a)var b=a;else{b=a.pathname;b=void 0===b?"/":b;var e=a.search;e=void 0===e?"":e;a=a.hash;a=void 0===a?"":a;e&&"?"!==e&&(b+="?"===e.charAt(0)?e:"?"+e);a&&"#"!==a&&(b+="#"===a.charAt(0)?a:"#"+a)}return b}function m(a,b){void 0===b&&(b=null);var e=p,k={pathname:v.pathname,hash:"",search:""};if("string"===
typeof a){var d={};if(a){var h=a.indexOf("#");0<=h&&(d.hash=a.substr(h),a=a.substr(0,h));h=a.indexOf("?");0<=h&&(d.search=a.substr(h),a=a.substr(0,h));a&&(d.pathname=a)}a=d}return A(e(k,a,{state:b,key:Math.random().toString(36).substr(2,8)}))}function y(a){z=a;a=f();n=a[0];v=a[1];D.call({action:z,location:v})}function E(a,b){function e(){E(a,b)}var k=u.Push,d=m(a,b);if(!l.length||(l.call({action:k,location:d,retry:e}),!1)){var h=[{usr:d.state,key:d.key,idx:n+1},g(d)];d=h[0];h=h[1];try{r.pushState(d,
"",h)}catch(I){q.location.assign(h)}y(k)}}function F(a,b){function e(){F(a,b)}var k=u.Replace,d=m(a,b);l.length&&(l.call({action:k,location:d,retry:e}),1)||(d=[{usr:d.state,key:d.key,idx:n},g(d)],r.replaceState(d[0],"",d[1]),y(k))}function t(a){r.go(a)}void 0===c&&(c={});c=c.window;var q=void 0===c?document.defaultView:c,r=q.history,w=null;q.addEventListener("popstate",function(){if(w)l.call(w),w=null;else{var a=u.Pop,b=f(),e=b[0];b=b[1];if(l.length)if(null!=e){var k=n-e;k&&(w={action:a,location:b,
retry:function(){t(-1*k)}},t(k))}else"production"!==process.env.NODE_ENV?B(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):void 0;else y(a)}});var z=u.Pop;c=f();var n=c[0],v=c[1],D=G(),l=G();null==n&&(n=0,r.replaceState(p({},r.state,{idx:n}),""));return{get action(){return z},
get location(){return v},createHref:g,push:E,replace:F,go:t,back:function(){t(-1)},forward:function(){t(1)},listen:function(a){return D.push(a)},block:function(a){var b=l.push(a);1===l.length&&q.addEventListener("beforeunload",C);return function(){b();l.length||q.removeEventListener("beforeunload",C)}}}}();export default H
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
/**
* Actions represent the type of change to a location value.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
*/
var Action;
(function (Action) {
/**
* A POP indicates a change to an arbitrary index in the history stack, such
* as a back or forward navigation. It does not describe the direction of the
* navigation, only that the current index changed.
*
* Note: This is the default action for newly created history objects.
*/
Action["Pop"] = "POP";
/**
* A PUSH indicates a new entry being added to the history stack, such as when
* a link is clicked and a new page loads. When this happens, all subsequent
* entries in the stack are lost.
*/
Action["Push"] = "PUSH";
/**
* A REPLACE indicates the entry at the current index in the history stack
* being replaced by a new one.
*/
Action["Replace"] = "REPLACE";
})(Action || (Action = {}));
var readOnly = process.env.NODE_ENV !== "production" ? function (obj) {
return Object.freeze(obj);
} : function (obj) {
return obj;
};
function warning(cond, message) {
if (!cond) {
// eslint-disable-next-line no-console
if (typeof console !== 'undefined') console.warn(message);
try {
// Welcome to debugging history!
//
// This error is thrown as a convenience so you can more easily
// find the source for a warning that appears in the console by
// enabling "pause on exceptions" in your JavaScript debugger.
throw new Error(message); // eslint-disable-next-line no-empty
} catch (e) {}
}
}
var BeforeUnloadEventType = 'beforeunload';
var PopStateEventType = 'popstate';
/**
* Browser history stores the location in regular URLs. This is the standard for
* most web apps, but it requires some configuration on the server to ensure you
* serve the same app at multiple URLs.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
*/
function createBrowserHistory(options) {
if (options === void 0) {
options = {};
}
var _options = options,
_options$window = _options.window,
window = _options$window === void 0 ? document.defaultView : _options$window;
var globalHistory = window.history;
function getIndexAndLocation() {
var _window$location = window.location,
pathname = _window$location.pathname,
search = _window$location.search,
hash = _window$location.hash;
var state = globalHistory.state || {};
return [state.idx, readOnly({
pathname: pathname,
search: search,
hash: hash,
state: state.usr || null,
key: state.key || 'default'
})];
}
var blockedPopTx = null;
function handlePop() {
if (blockedPopTx) {
blockers.call(blockedPopTx);
blockedPopTx = null;
} else {
var nextAction = Action.Pop;
var _getIndexAndLocation = getIndexAndLocation(),
nextIndex = _getIndexAndLocation[0],
nextLocation = _getIndexAndLocation[1];
if (blockers.length) {
if (nextIndex != null) {
var delta = index - nextIndex;
if (delta) {
// Revert the POP
blockedPopTx = {
action: nextAction,
location: nextLocation,
retry: function retry() {
go(delta * -1);
}
};
go(delta);
}
} else {
// Trying to POP to a location with no index. We did not create
// this location, so we can't effectively block the navigation.
process.env.NODE_ENV !== "production" ? warning(false, // TODO: Write up a doc that explains our blocking strategy in
// detail and link to it here so people can understand better what
// is going on and how to avoid it.
"You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
}
} else {
applyTx(nextAction);
}
}
}
window.addEventListener(PopStateEventType, handlePop);
var action = Action.Pop;
var _getIndexAndLocation2 = getIndexAndLocation(),
index = _getIndexAndLocation2[0],
location = _getIndexAndLocation2[1];
var listeners = createEvents();
var blockers = createEvents();
if (index == null) {
index = 0;
globalHistory.replaceState(_extends({}, globalHistory.state, {
idx: index
}), '');
}
function createHref(to) {
return typeof to === 'string' ? to : createPath(to);
} // state defaults to `null` because `window.history.state` does
function getNextLocation(to, state) {
if (state === void 0) {
state = null;
}
return readOnly(_extends({
pathname: location.pathname,
hash: '',
search: ''
}, typeof to === 'string' ? parsePath(to) : to, {
state: state,
key: createKey()
}));
}
function getHistoryStateAndUrl(nextLocation, index) {
return [{
usr: nextLocation.state,
key: nextLocation.key,
idx: index
}, createHref(nextLocation)];
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action: action,
location: location,
retry: retry
}), false);
}
function applyTx(nextAction) {
action = nextAction;
var _getIndexAndLocation3 = getIndexAndLocation();
index = _getIndexAndLocation3[0];
location = _getIndexAndLocation3[1];
listeners.call({
action: action,
location: location
});
}
function push(to, state) {
var nextAction = Action.Push;
var nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1),
historyState = _getHistoryStateAndUr[0],
url = _getHistoryStateAndUr[1]; // TODO: Support forced reloading
// try...catch because iOS limits us to 100 pushState calls :/
try {
globalHistory.pushState(historyState, '', url);
} catch (error) {
// They are going to lose state here, but there is no real
// way to warn them about it since the page will refresh...
window.location.assign(url);
}
applyTx(nextAction);
}
}
function replace(to, state) {
var nextAction = Action.Replace;
var nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index),
historyState = _getHistoryStateAndUr2[0],
url = _getHistoryStateAndUr2[1]; // TODO: Support forced reloading
globalHistory.replaceState(historyState, '', url);
applyTx(nextAction);
}
}
function go(delta) {
globalHistory.go(delta);
}
var history = {
get action() {
return action;
},
get location() {
return location;
},
createHref: createHref,
push: push,
replace: replace,
go: go,
back: function back() {
go(-1);
},
forward: function forward() {
go(1);
},
listen: function listen(listener) {
return listeners.push(listener);
},
block: function block(blocker) {
var unblock = blockers.push(blocker);
if (blockers.length === 1) {
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
return function () {
unblock(); // Remove the beforeunload listener so the document may
// still be salvageable in the pagehide event.
// See https://html.spec.whatwg.org/#unloading-documents
if (!blockers.length) {
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
};
}
};
return history;
}
function promptBeforeUnload(event) {
// Cancel the event.
event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
event.returnValue = '';
}
function createEvents() {
var handlers = [];
return {
get length() {
return handlers.length;
},
push: function push(fn) {
handlers.push(fn);
return function () {
handlers = handlers.filter(function (handler) {
return handler !== fn;
});
};
},
call: function call(arg) {
handlers.forEach(function (fn) {
return fn && fn(arg);
});
}
};
}
function createKey() {
return Math.random().toString(36).substr(2, 8);
}
/**
* Creates a string URL path from the given pathname, search, and hash components.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
*/
function createPath(_ref) {
var _ref$pathname = _ref.pathname,
pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
_ref$search = _ref.search,
search = _ref$search === void 0 ? '' : _ref$search,
_ref$hash = _ref.hash,
hash = _ref$hash === void 0 ? '' : _ref$hash;
if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
return pathname;
}
/**
* Parses a string URL path into its separate pathname, search, and hash components.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
*/
function parsePath(path) {
var parsedPath = {};
if (path) {
var hashIndex = path.indexOf('#');
if (hashIndex >= 0) {
parsedPath.hash = path.substr(hashIndex);
path = path.substr(0, hashIndex);
}
var searchIndex = path.indexOf('?');
if (searchIndex >= 0) {
parsedPath.search = path.substr(searchIndex);
path = path.substr(0, searchIndex);
}
if (path) {
parsedPath.pathname = path;
}
}
return parsedPath;
}
/**
* Create a default instance for the current document.
*/
var browser = createBrowserHistory();
export { browser as default };
//# sourceMappingURL=browser.js.map

@@ -1,9 +0,431 @@

function p(){p=Object.assign||function(a){for(var d=1;d<arguments.length;d++){var c=arguments[d],l;for(l in c)Object.prototype.hasOwnProperty.call(c,l)&&(a[l]=c[l])}return a};return p.apply(this,arguments)}var v,x=v||(v={});x.Pop="POP";x.Push="PUSH";x.Replace="REPLACE";var y="production"!==process.env.NODE_ENV?function(a){return Object.freeze(a)}:function(a){return a};function z(a,d){if(!a){"undefined"!==typeof console&&console.warn(d);try{throw Error(d);}catch(c){}}}
function C(a){a.preventDefault();a.returnValue=""}function D(){var a=[];return{get length(){return a.length},push:function(d){a.push(d);return function(){a=a.filter(function(c){return c!==d})}},call:function(d){a.forEach(function(c){return c&&c(d)})}}}function E(a){var d=a.pathname;d=void 0===d?"/":d;var c=a.search;c=void 0===c?"":c;a=a.hash;a=void 0===a?"":a;c&&"?"!==c&&(d+="?"===c.charAt(0)?c:"?"+c);a&&"#"!==a&&(d+="#"===a.charAt(0)?a:"#"+a);return d}
function F(a){var d={};if(a){var c=a.indexOf("#");0<=c&&(d.hash=a.substr(c),a=a.substr(0,c));c=a.indexOf("?");0<=c&&(d.search=a.substr(c),a=a.substr(0,c));a&&(d.pathname=a)}return d}
var K=function(a){function d(){var b=F(m.location.hash.substr(1)),e=b.pathname,g=b.search;b=b.hash;var h=q.state||{};return[h.idx,y({pathname:void 0===e?"/":e,search:void 0===g?"":g,hash:void 0===b?"":b,state:h.usr||null,key:h.key||"default"})]}function c(){if(w)k.call(w),w=null;else{var b=v.Pop,e=d(),g=e[0];e=e[1];if(k.length)if(null!=g){var h=n-g;h&&(w={action:b,location:e,retry:function(){r(-1*h)}},r(h))}else"production"!==process.env.NODE_ENV?z(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
void 0;else A(b)}}function l(b){var e=document.querySelector("base"),g="";e&&e.getAttribute("href")&&(e=m.location.href,g=e.indexOf("#"),g=-1===g?e:e.slice(0,g));return g+"#"+("string"===typeof b?b:E(b))}function G(b,e){void 0===e&&(e=null);return y(p({pathname:t.pathname,hash:"",search:""},"string"===typeof b?F(b):b,{state:e,key:Math.random().toString(36).substr(2,8)}))}function A(b){B=b;b=d();n=b[0];t=b[1];H.call({action:B,location:t})}function I(b,e){function g(){I(b,e)}var h=v.Push,f=G(b,e);"production"!==
process.env.NODE_ENV?z("/"===f.pathname.charAt(0),"Relative pathnames are not supported in hash history.push("+JSON.stringify(b)+")"):void 0;if(!k.length||(k.call({action:h,location:f,retry:g}),!1)){var u=[{usr:f.state,key:f.key,idx:n+1},l(f)];f=u[0];u=u[1];try{q.pushState(f,"",u)}catch(L){m.location.assign(u)}A(h)}}function J(b,e){function g(){J(b,e)}var h=v.Replace,f=G(b,e);"production"!==process.env.NODE_ENV?z("/"===f.pathname.charAt(0),"Relative pathnames are not supported in hash history.replace("+
JSON.stringify(b)+")"):void 0;k.length&&(k.call({action:h,location:f,retry:g}),1)||(f=[{usr:f.state,key:f.key,idx:n},l(f)],q.replaceState(f[0],"",f[1]),A(h))}function r(b){q.go(b)}void 0===a&&(a={});a=a.window;var m=void 0===a?document.defaultView:a,q=m.history,w=null;m.addEventListener("popstate",c);m.addEventListener("hashchange",function(){var b=d()[1];E(b)!==E(t)&&c()});var B=v.Pop;a=d();var n=a[0],t=a[1],H=D(),k=D();null==n&&(n=0,q.replaceState(p({},q.state,{idx:n}),""));return{get action(){return B},
get location(){return t},createHref:l,push:I,replace:J,go:r,back:function(){r(-1)},forward:function(){r(1)},listen:function(b){return H.push(b)},block:function(b){var e=k.push(b);1===k.length&&m.addEventListener("beforeunload",C);return function(){e();k.length||m.removeEventListener("beforeunload",C)}}}}();export default K
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
/**
* Actions represent the type of change to a location value.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
*/
var Action;
(function (Action) {
/**
* A POP indicates a change to an arbitrary index in the history stack, such
* as a back or forward navigation. It does not describe the direction of the
* navigation, only that the current index changed.
*
* Note: This is the default action for newly created history objects.
*/
Action["Pop"] = "POP";
/**
* A PUSH indicates a new entry being added to the history stack, such as when
* a link is clicked and a new page loads. When this happens, all subsequent
* entries in the stack are lost.
*/
Action["Push"] = "PUSH";
/**
* A REPLACE indicates the entry at the current index in the history stack
* being replaced by a new one.
*/
Action["Replace"] = "REPLACE";
})(Action || (Action = {}));
var readOnly = process.env.NODE_ENV !== "production" ? function (obj) {
return Object.freeze(obj);
} : function (obj) {
return obj;
};
function warning(cond, message) {
if (!cond) {
// eslint-disable-next-line no-console
if (typeof console !== 'undefined') console.warn(message);
try {
// Welcome to debugging history!
//
// This error is thrown as a convenience so you can more easily
// find the source for a warning that appears in the console by
// enabling "pause on exceptions" in your JavaScript debugger.
throw new Error(message); // eslint-disable-next-line no-empty
} catch (e) {}
}
}
var BeforeUnloadEventType = 'beforeunload';
var HashChangeEventType = 'hashchange';
var PopStateEventType = 'popstate';
/**
* Hash history stores the location in window.location.hash. This makes it ideal
* for situations where you don't want to send the location to the server for
* some reason, either because you do cannot configure it or the URL space is
* reserved for something else.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
*/
function createHashHistory(options) {
if (options === void 0) {
options = {};
}
var _options2 = options,
_options2$window = _options2.window,
window = _options2$window === void 0 ? document.defaultView : _options2$window;
var globalHistory = window.history;
function getIndexAndLocation() {
var _parsePath = parsePath(window.location.hash.substr(1)),
_parsePath$pathname = _parsePath.pathname,
pathname = _parsePath$pathname === void 0 ? '/' : _parsePath$pathname,
_parsePath$search = _parsePath.search,
search = _parsePath$search === void 0 ? '' : _parsePath$search,
_parsePath$hash = _parsePath.hash,
hash = _parsePath$hash === void 0 ? '' : _parsePath$hash;
var state = globalHistory.state || {};
return [state.idx, readOnly({
pathname: pathname,
search: search,
hash: hash,
state: state.usr || null,
key: state.key || 'default'
})];
}
var blockedPopTx = null;
function handlePop() {
if (blockedPopTx) {
blockers.call(blockedPopTx);
blockedPopTx = null;
} else {
var nextAction = Action.Pop;
var _getIndexAndLocation4 = getIndexAndLocation(),
nextIndex = _getIndexAndLocation4[0],
nextLocation = _getIndexAndLocation4[1];
if (blockers.length) {
if (nextIndex != null) {
var delta = index - nextIndex;
if (delta) {
// Revert the POP
blockedPopTx = {
action: nextAction,
location: nextLocation,
retry: function retry() {
go(delta * -1);
}
};
go(delta);
}
} else {
// Trying to POP to a location with no index. We did not create
// this location, so we can't effectively block the navigation.
process.env.NODE_ENV !== "production" ? warning(false, // TODO: Write up a doc that explains our blocking strategy in
// detail and link to it here so people can understand better
// what is going on and how to avoid it.
"You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
}
} else {
applyTx(nextAction);
}
}
}
window.addEventListener(PopStateEventType, handlePop); // popstate does not fire on hashchange in IE 11 and old (trident) Edge
// https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event
window.addEventListener(HashChangeEventType, function () {
var _getIndexAndLocation5 = getIndexAndLocation(),
nextLocation = _getIndexAndLocation5[1]; // Ignore extraneous hashchange events.
if (createPath(nextLocation) !== createPath(location)) {
handlePop();
}
});
var action = Action.Pop;
var _getIndexAndLocation6 = getIndexAndLocation(),
index = _getIndexAndLocation6[0],
location = _getIndexAndLocation6[1];
var listeners = createEvents();
var blockers = createEvents();
if (index == null) {
index = 0;
globalHistory.replaceState(_extends({}, globalHistory.state, {
idx: index
}), '');
}
function getBaseHref() {
var base = document.querySelector('base');
var href = '';
if (base && base.getAttribute('href')) {
var url = window.location.href;
var hashIndex = url.indexOf('#');
href = hashIndex === -1 ? url : url.slice(0, hashIndex);
}
return href;
}
function createHref(to) {
return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to));
}
function getNextLocation(to, state) {
if (state === void 0) {
state = null;
}
return readOnly(_extends({
pathname: location.pathname,
hash: '',
search: ''
}, typeof to === 'string' ? parsePath(to) : to, {
state: state,
key: createKey()
}));
}
function getHistoryStateAndUrl(nextLocation, index) {
return [{
usr: nextLocation.state,
key: nextLocation.key,
idx: index
}, createHref(nextLocation)];
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action: action,
location: location,
retry: retry
}), false);
}
function applyTx(nextAction) {
action = nextAction;
var _getIndexAndLocation7 = getIndexAndLocation();
index = _getIndexAndLocation7[0];
location = _getIndexAndLocation7[1];
listeners.call({
action: action,
location: location
});
}
function push(to, state) {
var nextAction = Action.Push;
var nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
process.env.NODE_ENV !== "production" ? warning(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.push(" + JSON.stringify(to) + ")") : void 0;
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr3 = getHistoryStateAndUrl(nextLocation, index + 1),
historyState = _getHistoryStateAndUr3[0],
url = _getHistoryStateAndUr3[1]; // TODO: Support forced reloading
// try...catch because iOS limits us to 100 pushState calls :/
try {
globalHistory.pushState(historyState, '', url);
} catch (error) {
// They are going to lose state here, but there is no real
// way to warn them about it since the page will refresh...
window.location.assign(url);
}
applyTx(nextAction);
}
}
function replace(to, state) {
var nextAction = Action.Replace;
var nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
process.env.NODE_ENV !== "production" ? warning(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(to) + ")") : void 0;
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr4 = getHistoryStateAndUrl(nextLocation, index),
historyState = _getHistoryStateAndUr4[0],
url = _getHistoryStateAndUr4[1]; // TODO: Support forced reloading
globalHistory.replaceState(historyState, '', url);
applyTx(nextAction);
}
}
function go(delta) {
globalHistory.go(delta);
}
var history = {
get action() {
return action;
},
get location() {
return location;
},
createHref: createHref,
push: push,
replace: replace,
go: go,
back: function back() {
go(-1);
},
forward: function forward() {
go(1);
},
listen: function listen(listener) {
return listeners.push(listener);
},
block: function block(blocker) {
var unblock = blockers.push(blocker);
if (blockers.length === 1) {
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
return function () {
unblock(); // Remove the beforeunload listener so the document may
// still be salvageable in the pagehide event.
// See https://html.spec.whatwg.org/#unloading-documents
if (!blockers.length) {
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
};
}
};
return history;
}
function promptBeforeUnload(event) {
// Cancel the event.
event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
event.returnValue = '';
}
function createEvents() {
var handlers = [];
return {
get length() {
return handlers.length;
},
push: function push(fn) {
handlers.push(fn);
return function () {
handlers = handlers.filter(function (handler) {
return handler !== fn;
});
};
},
call: function call(arg) {
handlers.forEach(function (fn) {
return fn && fn(arg);
});
}
};
}
function createKey() {
return Math.random().toString(36).substr(2, 8);
}
/**
* Creates a string URL path from the given pathname, search, and hash components.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
*/
function createPath(_ref) {
var _ref$pathname = _ref.pathname,
pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
_ref$search = _ref.search,
search = _ref$search === void 0 ? '' : _ref$search,
_ref$hash = _ref.hash,
hash = _ref$hash === void 0 ? '' : _ref$hash;
if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
return pathname;
}
/**
* Parses a string URL path into its separate pathname, search, and hash components.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
*/
function parsePath(path) {
var parsedPath = {};
if (path) {
var hashIndex = path.indexOf('#');
if (hashIndex >= 0) {
parsedPath.hash = path.substr(hashIndex);
path = path.substr(0, hashIndex);
}
var searchIndex = path.indexOf('?');
if (searchIndex >= 0) {
parsedPath.search = path.substr(searchIndex);
path = path.substr(0, searchIndex);
}
if (path) {
parsedPath.pathname = path;
}
}
return parsedPath;
}
/**
* Create a default instance for the current document.
*/
var hash = createHashHistory();
export { hash as default };
//# sourceMappingURL=hash.js.map

@@ -1,16 +0,744 @@

var p,C=p||(p={});C.Pop="POP";C.Push="PUSH";C.Replace="REPLACE";function D(e,f){if(!e){"undefined"!==typeof console&&console.warn(f);try{throw Error(f);}catch(g){}}}function E(e){e.preventDefault();e.returnValue=""}function F(){let e=[];return{get length(){return e.length},push(f){e.push(f);return function(){e=e.filter(g=>g!==f)}},call(f){e.forEach(g=>g&&g(f))}}}function H(){return Math.random().toString(36).substr(2,8)}
function I({pathname:e="/",search:f="",hash:g=""}){f&&"?"!==f&&(e+="?"===f.charAt(0)?f:"?"+f);g&&"#"!==g&&(e+="#"===g.charAt(0)?g:"#"+g);return e}function J(e){let f={};if(e){var g=e.indexOf("#");0<=g&&(f.hash=e.substr(g),e=e.substr(0,g));g=e.indexOf("?");0<=g&&(f.search=e.substr(g),e=e.substr(0,g));e&&(f.pathname=e)}return f}
function createBrowserHistory(e={}){function f(){let {pathname:b,search:a,hash:d}=q.location,h=k.state||{};return[h.idx,Object.freeze({pathname:b,search:a,hash:d,state:h.usr||null,key:h.key||"default"})]}function g(b){return"string"===typeof b?b:I(b)}function w(b,a=null){return Object.freeze(Object.assign(Object.assign({pathname:r.pathname,hash:"",search:""},"string"===typeof b?J(b):b),{state:a,key:H()}))}function z(b){u=b;[n,r]=f();v.call({action:u,location:r})}function A(b,a){function d(){A(b,
a)}let h=p.Push,l=w(b,a);if(!c.length||(c.call({action:h,location:l,retry:d}),!1)){let [t,B]=[{usr:l.state,key:l.key,idx:n+1},g(l)];try{k.pushState(t,"",B)}catch(G){q.location.assign(B)}z(h)}}function x(b,a){function d(){x(b,a)}let h=p.Replace,l=w(b,a);if(!c.length||(c.call({action:h,location:l,retry:d}),!1)){let [t,B]=[{usr:l.state,key:l.key,idx:n},g(l)];k.replaceState(t,"",B);z(h)}}function y(b){k.go(b)}let {window:q=document.defaultView}=e,k=q.history,m=null;q.addEventListener("popstate",function(){if(m)c.call(m),
m=null;else{let b=p.Pop,[a,d]=f();if(c.length)if(null!=a){let h=n-a;h&&(m={action:b,location:d,retry(){y(-1*h)}},y(h))}else D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");else z(b)}});let u=p.Pop,[n,r]=f(),v=F(),c=F();null==n&&(n=0,k.replaceState(Object.assign(Object.assign({},
k.state),{idx:n}),""));return{get action(){return u},get location(){return r},createHref:g,push:A,replace:x,go:y,back(){y(-1)},forward(){y(1)},listen(b){return v.push(b)},block(b){let a=c.push(b);1===c.length&&q.addEventListener("beforeunload",E);return function(){a();c.length||q.removeEventListener("beforeunload",E)}}}};
function createHashHistory(e={}){function f(){let {pathname:a="/",search:d="",hash:h=""}=J(k.location.hash.substr(1)),l=m.state||{};return[l.idx,Object.freeze({pathname:a,search:d,hash:h,state:l.usr||null,key:l.key||"default"})]}function g(){if(u)b.call(u),u=null;else{let a=p.Pop,[d,h]=f();if(b.length)if(null!=d){let l=r-d;l&&(u={action:a,location:h,retry(){q(-1*l)}},q(l))}else D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");
else A(a)}}function w(a){var d=document.querySelector("base"),h="";d&&d.getAttribute("href")&&(d=k.location.href,h=d.indexOf("#"),h=-1===h?d:d.slice(0,h));return h+"#"+("string"===typeof a?a:I(a))}function z(a,d=null){return Object.freeze(Object.assign(Object.assign({pathname:v.pathname,hash:"",search:""},"string"===typeof a?J(a):a),{state:d,key:H()}))}function A(a){n=a;[r,v]=f();c.call({action:n,location:v})}function x(a,d){function h(){x(a,d)}let l=p.Push,t=z(a,d);D("/"===t.pathname.charAt(0),`Relative pathnames are not supported in hash history.push(${JSON.stringify(a)})`);
if(!b.length||(b.call({action:l,location:t,retry:h}),!1)){let [B,G]=[{usr:t.state,key:t.key,idx:r+1},w(t)];try{m.pushState(B,"",G)}catch(K){k.location.assign(G)}A(l)}}function y(a,d){function h(){y(a,d)}let l=p.Replace,t=z(a,d);D("/"===t.pathname.charAt(0),`Relative pathnames are not supported in hash history.replace(${JSON.stringify(a)})`);if(!b.length||(b.call({action:l,location:t,retry:h}),!1)){let [B,G]=[{usr:t.state,key:t.key,idx:r},w(t)];m.replaceState(B,"",G);A(l)}}function q(a){m.go(a)}let {window:k=
document.defaultView}=e,m=k.history,u=null;k.addEventListener("popstate",g);k.addEventListener("hashchange",()=>{let [,a]=f();I(a)!==I(v)&&g()});let n=p.Pop,[r,v]=f(),c=F(),b=F();null==r&&(r=0,m.replaceState(Object.assign(Object.assign({},m.state),{idx:r}),""));return{get action(){return n},get location(){return v},createHref:w,push:x,replace:y,go:q,back(){q(-1)},forward(){q(1)},listen(a){return c.push(a)},block(a){let d=b.push(a);1===b.length&&k.addEventListener("beforeunload",E);return function(){d();
b.length||k.removeEventListener("beforeunload",E)}}}};
function createMemoryHistory(e={}){function f(c,b=null){return Object.freeze(Object.assign(Object.assign({pathname:n.pathname,search:"",hash:""},"string"===typeof c?J(c):c),{state:b,key:H()}))}function g(c,b,a){return!v.length||(v.call({action:c,location:b,retry:a}),!1)}function w(c,b){u=c;n=b;r.call({action:u,location:n})}function z(c,b){let a=p.Push,d=f(c,b);D("/"===n.pathname.charAt(0),`Relative pathnames are not supported in memory history.push(${JSON.stringify(c)})`);g(a,d,function(){z(c,
b)})&&(m+=1,k.splice(m,k.length,d),w(a,d))}function A(c,b){let a=p.Replace,d=f(c,b);D("/"===n.pathname.charAt(0),`Relative pathnames are not supported in memory history.replace(${JSON.stringify(c)})`);g(a,d,function(){A(c,b)})&&(k[m]=d,w(a,d))}function x(c){let b=Math.min(Math.max(m+c,0),k.length-1),a=p.Pop,d=k[b];g(a,d,function(){x(c)})&&(m=b,w(a,d))}let {initialEntries:y=["/"],initialIndex:q}=e,k=y.map(c=>{let b=Object.freeze(Object.assign({pathname:"/",search:"",hash:"",state:null,key:H()},"string"===
typeof c?J(c):c));D("/"===b.pathname.charAt(0),`Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: ${JSON.stringify(c)})`);return b}),m=Math.min(Math.max(null==q?k.length-1:q,0),k.length-1),u=p.Pop,n=k[m],r=F(),v=F();return{get index(){return m},get action(){return u},get location(){return n},createHref:function(c){return"string"===typeof c?c:I(c)},push:z,replace:A,go:x,back(){x(-1)},forward(){x(1)},listen(c){return r.push(c)},block(c){return v.push(c)}}};
export{p as Action,createBrowserHistory,createHashHistory,createMemoryHistory,I as createPath,J as parsePath}
/**
* Actions represent the type of change to a location value.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
*/
var Action;
(function (Action) {
/**
* A POP indicates a change to an arbitrary index in the history stack, such
* as a back or forward navigation. It does not describe the direction of the
* navigation, only that the current index changed.
*
* Note: This is the default action for newly created history objects.
*/
Action["Pop"] = "POP";
/**
* A PUSH indicates a new entry being added to the history stack, such as when
* a link is clicked and a new page loads. When this happens, all subsequent
* entries in the stack are lost.
*/
Action["Push"] = "PUSH";
/**
* A REPLACE indicates the entry at the current index in the history stack
* being replaced by a new one.
*/
Action["Replace"] = "REPLACE";
})(Action || (Action = {}));
const readOnly = obj => Object.freeze(obj) ;
function warning(cond, message) {
if (!cond) {
// eslint-disable-next-line no-console
if (typeof console !== 'undefined') console.warn(message);
try {
// Welcome to debugging history!
//
// This error is thrown as a convenience so you can more easily
// find the source for a warning that appears in the console by
// enabling "pause on exceptions" in your JavaScript debugger.
throw new Error(message); // eslint-disable-next-line no-empty
} catch (e) {}
}
}
const BeforeUnloadEventType = 'beforeunload';
const HashChangeEventType = 'hashchange';
const PopStateEventType = 'popstate';
/**
* Browser history stores the location in regular URLs. This is the standard for
* most web apps, but it requires some configuration on the server to ensure you
* serve the same app at multiple URLs.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
*/
function createBrowserHistory(options = {}) {
let {
window = document.defaultView
} = options;
let globalHistory = window.history;
function getIndexAndLocation() {
let {
pathname,
search,
hash
} = window.location;
let state = globalHistory.state || {};
return [state.idx, readOnly({
pathname,
search,
hash,
state: state.usr || null,
key: state.key || 'default'
})];
}
let blockedPopTx = null;
function handlePop() {
if (blockedPopTx) {
blockers.call(blockedPopTx);
blockedPopTx = null;
} else {
let nextAction = Action.Pop;
let [nextIndex, nextLocation] = getIndexAndLocation();
if (blockers.length) {
if (nextIndex != null) {
let delta = index - nextIndex;
if (delta) {
// Revert the POP
blockedPopTx = {
action: nextAction,
location: nextLocation,
retry() {
go(delta * -1);
}
};
go(delta);
}
} else {
// Trying to POP to a location with no index. We did not create
// this location, so we can't effectively block the navigation.
warning(false, // TODO: Write up a doc that explains our blocking strategy in
// detail and link to it here so people can understand better what
// is going on and how to avoid it.
`You are trying to block a POP navigation to a location that was not ` + `created by the history library. The block will fail silently in ` + `production, but in general you should do all navigation with the ` + `history library (instead of using window.history.pushState directly) ` + `to avoid this situation.`) ;
}
} else {
applyTx(nextAction);
}
}
}
window.addEventListener(PopStateEventType, handlePop);
let action = Action.Pop;
let [index, location] = getIndexAndLocation();
let listeners = createEvents();
let blockers = createEvents();
if (index == null) {
index = 0;
globalHistory.replaceState(Object.assign(Object.assign({}, globalHistory.state), {
idx: index
}), '');
}
function createHref(to) {
return typeof to === 'string' ? to : createPath(to);
} // state defaults to `null` because `window.history.state` does
function getNextLocation(to, state = null) {
return readOnly(Object.assign(Object.assign({
pathname: location.pathname,
hash: '',
search: ''
}, typeof to === 'string' ? parsePath(to) : to), {
state,
key: createKey()
}));
}
function getHistoryStateAndUrl(nextLocation, index) {
return [{
usr: nextLocation.state,
key: nextLocation.key,
idx: index
}, createHref(nextLocation)];
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action,
location,
retry
}), false);
}
function applyTx(nextAction) {
action = nextAction;
[index, location] = getIndexAndLocation();
listeners.call({
action,
location
});
}
function push(to, state) {
let nextAction = Action.Push;
let nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
if (allowTx(nextAction, nextLocation, retry)) {
let [historyState, url] = getHistoryStateAndUrl(nextLocation, index + 1); // TODO: Support forced reloading
// try...catch because iOS limits us to 100 pushState calls :/
try {
globalHistory.pushState(historyState, '', url);
} catch (error) {
// They are going to lose state here, but there is no real
// way to warn them about it since the page will refresh...
window.location.assign(url);
}
applyTx(nextAction);
}
}
function replace(to, state) {
let nextAction = Action.Replace;
let nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
if (allowTx(nextAction, nextLocation, retry)) {
let [historyState, url] = getHistoryStateAndUrl(nextLocation, index); // TODO: Support forced reloading
globalHistory.replaceState(historyState, '', url);
applyTx(nextAction);
}
}
function go(delta) {
globalHistory.go(delta);
}
let history = {
get action() {
return action;
},
get location() {
return location;
},
createHref,
push,
replace,
go,
back() {
go(-1);
},
forward() {
go(1);
},
listen(listener) {
return listeners.push(listener);
},
block(blocker) {
let unblock = blockers.push(blocker);
if (blockers.length === 1) {
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
return function () {
unblock(); // Remove the beforeunload listener so the document may
// still be salvageable in the pagehide event.
// See https://html.spec.whatwg.org/#unloading-documents
if (!blockers.length) {
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
};
}
};
return history;
}
/**
* Hash history stores the location in window.location.hash. This makes it ideal
* for situations where you don't want to send the location to the server for
* some reason, either because you do cannot configure it or the URL space is
* reserved for something else.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
*/
function createHashHistory(options = {}) {
let {
window = document.defaultView
} = options;
let globalHistory = window.history;
function getIndexAndLocation() {
let {
pathname = '/',
search = '',
hash = ''
} = parsePath(window.location.hash.substr(1));
let state = globalHistory.state || {};
return [state.idx, readOnly({
pathname,
search,
hash,
state: state.usr || null,
key: state.key || 'default'
})];
}
let blockedPopTx = null;
function handlePop() {
if (blockedPopTx) {
blockers.call(blockedPopTx);
blockedPopTx = null;
} else {
let nextAction = Action.Pop;
let [nextIndex, nextLocation] = getIndexAndLocation();
if (blockers.length) {
if (nextIndex != null) {
let delta = index - nextIndex;
if (delta) {
// Revert the POP
blockedPopTx = {
action: nextAction,
location: nextLocation,
retry() {
go(delta * -1);
}
};
go(delta);
}
} else {
// Trying to POP to a location with no index. We did not create
// this location, so we can't effectively block the navigation.
warning(false, // TODO: Write up a doc that explains our blocking strategy in
// detail and link to it here so people can understand better
// what is going on and how to avoid it.
`You are trying to block a POP navigation to a location that was not ` + `created by the history library. The block will fail silently in ` + `production, but in general you should do all navigation with the ` + `history library (instead of using window.history.pushState directly) ` + `to avoid this situation.`) ;
}
} else {
applyTx(nextAction);
}
}
}
window.addEventListener(PopStateEventType, handlePop); // popstate does not fire on hashchange in IE 11 and old (trident) Edge
// https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event
window.addEventListener(HashChangeEventType, () => {
let [, nextLocation] = getIndexAndLocation(); // Ignore extraneous hashchange events.
if (createPath(nextLocation) !== createPath(location)) {
handlePop();
}
});
let action = Action.Pop;
let [index, location] = getIndexAndLocation();
let listeners = createEvents();
let blockers = createEvents();
if (index == null) {
index = 0;
globalHistory.replaceState(Object.assign(Object.assign({}, globalHistory.state), {
idx: index
}), '');
}
function getBaseHref() {
let base = document.querySelector('base');
let href = '';
if (base && base.getAttribute('href')) {
let url = window.location.href;
let hashIndex = url.indexOf('#');
href = hashIndex === -1 ? url : url.slice(0, hashIndex);
}
return href;
}
function createHref(to) {
return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to));
}
function getNextLocation(to, state = null) {
return readOnly(Object.assign(Object.assign({
pathname: location.pathname,
hash: '',
search: ''
}, typeof to === 'string' ? parsePath(to) : to), {
state,
key: createKey()
}));
}
function getHistoryStateAndUrl(nextLocation, index) {
return [{
usr: nextLocation.state,
key: nextLocation.key,
idx: index
}, createHref(nextLocation)];
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action,
location,
retry
}), false);
}
function applyTx(nextAction) {
action = nextAction;
[index, location] = getIndexAndLocation();
listeners.call({
action,
location
});
}
function push(to, state) {
let nextAction = Action.Push;
let nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
warning(nextLocation.pathname.charAt(0) === '/', `Relative pathnames are not supported in hash history.push(${JSON.stringify(to)})`) ;
if (allowTx(nextAction, nextLocation, retry)) {
let [historyState, url] = getHistoryStateAndUrl(nextLocation, index + 1); // TODO: Support forced reloading
// try...catch because iOS limits us to 100 pushState calls :/
try {
globalHistory.pushState(historyState, '', url);
} catch (error) {
// They are going to lose state here, but there is no real
// way to warn them about it since the page will refresh...
window.location.assign(url);
}
applyTx(nextAction);
}
}
function replace(to, state) {
let nextAction = Action.Replace;
let nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
warning(nextLocation.pathname.charAt(0) === '/', `Relative pathnames are not supported in hash history.replace(${JSON.stringify(to)})`) ;
if (allowTx(nextAction, nextLocation, retry)) {
let [historyState, url] = getHistoryStateAndUrl(nextLocation, index); // TODO: Support forced reloading
globalHistory.replaceState(historyState, '', url);
applyTx(nextAction);
}
}
function go(delta) {
globalHistory.go(delta);
}
let history = {
get action() {
return action;
},
get location() {
return location;
},
createHref,
push,
replace,
go,
back() {
go(-1);
},
forward() {
go(1);
},
listen(listener) {
return listeners.push(listener);
},
block(blocker) {
let unblock = blockers.push(blocker);
if (blockers.length === 1) {
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
return function () {
unblock(); // Remove the beforeunload listener so the document may
// still be salvageable in the pagehide event.
// See https://html.spec.whatwg.org/#unloading-documents
if (!blockers.length) {
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
};
}
};
return history;
}
/**
* Memory history stores the current location in memory. It is designed for use
* in stateful non-browser environments like tests and React Native.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#creatememoryhistory
*/
function createMemoryHistory(options = {}) {
let {
initialEntries = ['/'],
initialIndex
} = options;
let entries = initialEntries.map(entry => {
let location = readOnly(Object.assign({
pathname: '/',
search: '',
hash: '',
state: null,
key: createKey()
}, typeof entry === 'string' ? parsePath(entry) : entry));
warning(location.pathname.charAt(0) === '/', `Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: ${JSON.stringify(entry)})`) ;
return location;
});
let index = clamp(initialIndex == null ? entries.length - 1 : initialIndex, 0, entries.length - 1);
let action = Action.Pop;
let location = entries[index];
let listeners = createEvents();
let blockers = createEvents();
function createHref(to) {
return typeof to === 'string' ? to : createPath(to);
}
function getNextLocation(to, state = null) {
return readOnly(Object.assign(Object.assign({
pathname: location.pathname,
search: '',
hash: ''
}, typeof to === 'string' ? parsePath(to) : to), {
state,
key: createKey()
}));
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action,
location,
retry
}), false);
}
function applyTx(nextAction, nextLocation) {
action = nextAction;
location = nextLocation;
listeners.call({
action,
location
});
}
function push(to, state) {
let nextAction = Action.Push;
let nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
warning(location.pathname.charAt(0) === '/', `Relative pathnames are not supported in memory history.push(${JSON.stringify(to)})`) ;
if (allowTx(nextAction, nextLocation, retry)) {
index += 1;
entries.splice(index, entries.length, nextLocation);
applyTx(nextAction, nextLocation);
}
}
function replace(to, state) {
let nextAction = Action.Replace;
let nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
warning(location.pathname.charAt(0) === '/', `Relative pathnames are not supported in memory history.replace(${JSON.stringify(to)})`) ;
if (allowTx(nextAction, nextLocation, retry)) {
entries[index] = nextLocation;
applyTx(nextAction, nextLocation);
}
}
function go(delta) {
let nextIndex = clamp(index + delta, 0, entries.length - 1);
let nextAction = Action.Pop;
let nextLocation = entries[nextIndex];
function retry() {
go(delta);
}
if (allowTx(nextAction, nextLocation, retry)) {
index = nextIndex;
applyTx(nextAction, nextLocation);
}
}
let history = {
get index() {
return index;
},
get action() {
return action;
},
get location() {
return location;
},
createHref,
push,
replace,
go,
back() {
go(-1);
},
forward() {
go(1);
},
listen(listener) {
return listeners.push(listener);
},
block(blocker) {
return blockers.push(blocker);
}
};
return history;
} ////////////////////////////////////////////////////////////////////////////////
// UTILS
////////////////////////////////////////////////////////////////////////////////
function clamp(n, lowerBound, upperBound) {
return Math.min(Math.max(n, lowerBound), upperBound);
}
function promptBeforeUnload(event) {
// Cancel the event.
event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
event.returnValue = '';
}
function createEvents() {
let handlers = [];
return {
get length() {
return handlers.length;
},
push(fn) {
handlers.push(fn);
return function () {
handlers = handlers.filter(handler => handler !== fn);
};
},
call(arg) {
handlers.forEach(fn => fn && fn(arg));
}
};
}
function createKey() {
return Math.random().toString(36).substr(2, 8);
}
/**
* Creates a string URL path from the given pathname, search, and hash components.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
*/
function createPath({
pathname = '/',
search = '',
hash = ''
}) {
if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
return pathname;
}
/**
* Parses a string URL path into its separate pathname, search, and hash components.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
*/
function parsePath(path) {
let parsedPath = {};
if (path) {
let hashIndex = path.indexOf('#');
if (hashIndex >= 0) {
parsedPath.hash = path.substr(hashIndex);
path = path.substr(0, hashIndex);
}
let searchIndex = path.indexOf('?');
if (searchIndex >= 0) {
parsedPath.search = path.substr(searchIndex);
path = path.substr(0, searchIndex);
}
if (path) {
parsedPath.pathname = path;
}
}
return parsedPath;
}
export { Action, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, parsePath };
//# sourceMappingURL=history.development.js.map

2

history.production.min.js

@@ -1,2 +0,2 @@

var t,e=t||(t={});function n(t){t.preventDefault(),t.returnValue=""}function a(){let t=[];return{get length(){return t.length},push:e=>(t.push(e),function(){t=t.filter((t=>t!==e))}),call(e){t.forEach((t=>t&&t(e)))}}}function r(){return Math.random().toString(36).substr(2,8)}function l({pathname:t="/",search:e="",hash:n=""}){return e&&"?"!==e&&(t+="?"===e.charAt(0)?e:"?"+e),n&&"#"!==n&&(t+="#"===n.charAt(0)?n:"#"+n),t}function i(t){let 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 c(e={}){function c(){let{pathname:t,search:e,hash:n}=f.location,a=p.state||{};return[a.idx,{pathname:t,search:e,hash:n,state:a.usr||null,key:a.key||"default"}]}function o(t){return"string"==typeof t?t:l(t)}function s(t,e=null){return Object.assign(Object.assign({pathname:b.pathname,hash:"",search:""},"string"==typeof t?i(t):t),{state:e,key:r()})}function u(t){d=t,[y,b]=c(),m.call({action:d,location:b})}function h(t){p.go(t)}let{window:f=document.defaultView}=e,p=f.history,g=null;f.addEventListener("popstate",(function(){if(g)k.call(g),g=null;else{let e=t.Pop,[n,a]=c();if(k.length){if(null!=n){let t=y-n;t&&(g={action:e,location:a,retry(){h(-1*t)}},h(t))}}else u(e)}}));let d=t.Pop,[y,b]=c(),m=a(),k=a();return null==y&&(y=0,p.replaceState(Object.assign(Object.assign({},p.state),{idx:y}),"")),{get action(){return d},get location(){return b},createHref:o,push:function e(n,a){let r=t.Push,l=s(n,a);if(!k.length||(k.call({action:r,location:l,retry:function(){e(n,a)}}),0)){let[t,e]=[{usr:l.state,key:l.key,idx:y+1},o(l)];try{p.pushState(t,"",e)}catch(i){f.location.assign(e)}u(r)}},replace:function e(n,a){let r=t.Replace,l=s(n,a);if(!k.length||(k.call({action:r,location:l,retry:function(){e(n,a)}}),0)){let[t,e]=[{usr:l.state,key:l.key,idx:y},o(l)];p.replaceState(t,"",e),u(r)}},go:h,back(){h(-1)},forward(){h(1)},listen:t=>m.push(t),block(t){let e=k.push(t);return 1===k.length&&f.addEventListener("beforeunload",n),function(){e(),k.length||f.removeEventListener("beforeunload",n)}}}}function o(e={}){function c(){let{pathname:t="/",search:e="",hash:n=""}=i(p.location.hash.substr(1)),a=g.state||{};return[a.idx,{pathname:t,search:e,hash:n,state:a.usr||null,key:a.key||"default"}]}function o(){if(d)P.call(d),d=null;else{let e=t.Pop,[n,a]=c();if(P.length){if(null!=n){let t=b-n;t&&(d={action:e,location:a,retry(){f(-1*t)}},f(t))}}else h(e)}}function s(t){var e=document.querySelector("base"),n="";return e&&e.getAttribute("href")&&(n=-1===(n=(e=p.location.href).indexOf("#"))?e:e.slice(0,n)),n+"#"+("string"==typeof t?t:l(t))}function u(t,e=null){return Object.assign(Object.assign({pathname:m.pathname,hash:"",search:""},"string"==typeof t?i(t):t),{state:e,key:r()})}function h(t){y=t,[b,m]=c(),k.call({action:y,location:m})}function f(t){g.go(t)}let{window:p=document.defaultView}=e,g=p.history,d=null;p.addEventListener("popstate",o),p.addEventListener("hashchange",(()=>{let[,t]=c();l(t)!==l(m)&&o()}));let y=t.Pop,[b,m]=c(),k=a(),P=a();return null==b&&(b=0,g.replaceState(Object.assign(Object.assign({},g.state),{idx:b}),"")),{get action(){return y},get location(){return m},createHref:s,push:function e(n,a){let r=t.Push,l=u(n,a);if(!P.length||(P.call({action:r,location:l,retry:function(){e(n,a)}}),0)){let[t,e]=[{usr:l.state,key:l.key,idx:b+1},s(l)];try{g.pushState(t,"",e)}catch(i){p.location.assign(e)}h(r)}},replace:function e(n,a){let r=t.Replace,l=u(n,a);if(!P.length||(P.call({action:r,location:l,retry:function(){e(n,a)}}),0)){let[t,e]=[{usr:l.state,key:l.key,idx:b},s(l)];g.replaceState(t,"",e),h(r)}},go:f,back(){f(-1)},forward(){f(1)},listen:t=>k.push(t),block(t){let e=P.push(t);return 1===P.length&&p.addEventListener("beforeunload",n),function(){e(),P.length||p.removeEventListener("beforeunload",n)}}}}function s(e={}){function n(t,e=null){return Object.assign(Object.assign({pathname:d.pathname,search:"",hash:""},"string"==typeof t?i(t):t),{state:e,key:r()})}function c(t,e,n){return!b.length||(b.call({action:t,location:e,retry:n}),!1)}function o(t,e){g=t,d=e,y.call({action:g,location:d})}function s(e){let n=Math.min(Math.max(p+e,0),f.length-1),a=t.Pop,r=f[n];c(a,r,(function(){s(e)}))&&(p=n,o(a,r))}let{initialEntries:u=["/"],initialIndex:h}=e,f=u.map((t=>Object.assign({pathname:"/",search:"",hash:"",state:null,key:r()},"string"==typeof t?i(t):t))),p=Math.min(Math.max(null==h?f.length-1:h,0),f.length-1),g=t.Pop,d=f[p],y=a(),b=a();return{get index(){return p},get action(){return g},get location(){return d},createHref:function(t){return"string"==typeof t?t:l(t)},push:function e(a,r){let l=t.Push,i=n(a,r);c(l,i,(function(){e(a,r)}))&&(p+=1,f.splice(p,f.length,i),o(l,i))},replace:function e(a,r){let l=t.Replace,i=n(a,r);c(l,i,(function(){e(a,r)}))&&(f[p]=i,o(l,i))},go:s,back(){s(-1)},forward(){s(1)},listen:t=>y.push(t),block:t=>b.push(t)}}e.Pop="POP",e.Push="PUSH",e.Replace="REPLACE";export{t as Action,c as createBrowserHistory,o as createHashHistory,s as createMemoryHistory,l as createPath,i as parsePath};
var t;!function(t){t.Pop="POP",t.Push="PUSH",t.Replace="REPLACE"}(t||(t={}));function e(e={}){let{window:n=document.defaultView}=e,a=n.history;function r(){let{pathname:t,search:e,hash:r}=n.location,l=a.state||{};return[l.idx,{pathname:t,search:e,hash:r,state:l.usr||null,key:l.key||"default"}]}let s=null;n.addEventListener("popstate",(function(){if(s)d.call(s),s=null;else{let e=t.Pop,[n,a]=r();if(d.length){if(null!=n){let t=f-n;t&&(s={action:e,location:a,retry(){P(-1*t)}},P(t))}}else O(e)}}));let h=t.Pop,[f,p]=r(),g=i(),d=i();function b(t){return"string"==typeof t?t:c(t)}function y(t,e=null){return Object.assign(Object.assign({pathname:p.pathname,hash:"",search:""},"string"==typeof t?u(t):t),{state:e,key:o()})}function m(t,e){return[{usr:t.state,key:t.key,idx:e},b(t)]}function k(t,e,n){return!d.length||(d.call({action:t,location:e,retry:n}),!1)}function O(t){h=t,[f,p]=r(),g.call({action:h,location:p})}function P(t){a.go(t)}return null==f&&(f=0,a.replaceState(Object.assign(Object.assign({},a.state),{idx:f}),"")),{get action(){return h},get location(){return p},createHref:b,push:function e(r,l){let i=t.Push,o=y(r,l);if(k(i,o,(function(){e(r,l)}))){let[t,e]=m(o,f+1);try{a.pushState(t,"",e)}catch(c){n.location.assign(e)}O(i)}},replace:function e(n,r){let l=t.Replace,i=y(n,r);if(k(l,i,(function(){e(n,r)}))){let[t,e]=m(i,f);a.replaceState(t,"",e),O(l)}},go:P,back(){P(-1)},forward(){P(1)},listen:t=>g.push(t),block(t){let e=d.push(t);return 1===d.length&&n.addEventListener("beforeunload",l),function(){e(),d.length||n.removeEventListener("beforeunload",l)}}}}function n(e={}){let{window:n=document.defaultView}=e,a=n.history;function r(){let{pathname:t="/",search:e="",hash:r=""}=u(n.location.hash.substr(1)),l=a.state||{};return[l.idx,{pathname:t,search:e,hash:r,state:l.usr||null,key:l.key||"default"}]}let s=null;function h(){if(s)b.call(s),s=null;else{let e=t.Pop,[n,a]=r();if(b.length){if(null!=n){let t=p-n;t&&(s={action:e,location:a,retry(){x(-1*t)}},x(t))}}else P(e)}}n.addEventListener("popstate",h),n.addEventListener("hashchange",(()=>{let[,t]=r();c(t)!==c(g)&&h()}));let f=t.Pop,[p,g]=r(),d=i(),b=i();function y(t){return function(){let t=document.querySelector("base"),e="";if(t&&t.getAttribute("href")){let t=n.location.href,a=t.indexOf("#");e=-1===a?t:t.slice(0,a)}return e}()+"#"+("string"==typeof t?t:c(t))}function m(t,e=null){return Object.assign(Object.assign({pathname:g.pathname,hash:"",search:""},"string"==typeof t?u(t):t),{state:e,key:o()})}function k(t,e){return[{usr:t.state,key:t.key,idx:e},y(t)]}function O(t,e,n){return!b.length||(b.call({action:t,location:e,retry:n}),!1)}function P(t){f=t,[p,g]=r(),d.call({action:f,location:g})}function x(t){a.go(t)}return null==p&&(p=0,a.replaceState(Object.assign(Object.assign({},a.state),{idx:p}),"")),{get action(){return f},get location(){return g},createHref:y,push:function e(r,l){let i=t.Push,o=m(r,l);if(O(i,o,(function(){e(r,l)}))){let[t,e]=k(o,p+1);try{a.pushState(t,"",e)}catch(c){n.location.assign(e)}P(i)}},replace:function e(n,r){let l=t.Replace,i=m(n,r);if(O(l,i,(function(){e(n,r)}))){let[t,e]=k(i,p);a.replaceState(t,"",e),P(l)}},go:x,back(){x(-1)},forward(){x(1)},listen:t=>d.push(t),block(t){let e=b.push(t);return 1===b.length&&n.addEventListener("beforeunload",l),function(){e(),b.length||n.removeEventListener("beforeunload",l)}}}}function a(e={}){let{initialEntries:n=["/"],initialIndex:a}=e,l=n.map((t=>Object.assign({pathname:"/",search:"",hash:"",state:null,key:o()},"string"==typeof t?u(t):t))),s=r(null==a?l.length-1:a,0,l.length-1),h=t.Pop,f=l[s],p=i(),g=i();function d(t,e=null){return Object.assign(Object.assign({pathname:f.pathname,search:"",hash:""},"string"==typeof t?u(t):t),{state:e,key:o()})}function b(t,e,n){return!g.length||(g.call({action:t,location:e,retry:n}),!1)}function y(t,e){h=t,f=e,p.call({action:h,location:f})}function m(e){let n=r(s+e,0,l.length-1),a=t.Pop,i=l[n];b(a,i,(function(){m(e)}))&&(s=n,y(a,i))}return{get index(){return s},get action(){return h},get location(){return f},createHref:function(t){return"string"==typeof t?t:c(t)},push:function e(n,a){let r=t.Push,i=d(n,a);b(r,i,(function(){e(n,a)}))&&(s+=1,l.splice(s,l.length,i),y(r,i))},replace:function e(n,a){let r=t.Replace,i=d(n,a);b(r,i,(function(){e(n,a)}))&&(l[s]=i,y(r,i))},go:m,back(){m(-1)},forward(){m(1)},listen:t=>p.push(t),block:t=>g.push(t)}}function r(t,e,n){return Math.min(Math.max(t,e),n)}function l(t){t.preventDefault(),t.returnValue=""}function i(){let t=[];return{get length(){return t.length},push:e=>(t.push(e),function(){t=t.filter((t=>t!==e))}),call(e){t.forEach((t=>t&&t(e)))}}}function o(){return Math.random().toString(36).substr(2,8)}function c({pathname:t="/",search:e="",hash:n=""}){return e&&"?"!==e&&(t+="?"===e.charAt(0)?e:"?"+e),n&&"#"!==n&&(t+="#"===n.charAt(0)?n:"#"+n),t}function u(t){let e={};if(t){let n=t.indexOf("#");n>=0&&(e.hash=t.substr(n),t=t.substr(0,n));let a=t.indexOf("?");a>=0&&(e.search=t.substr(a),t=t.substr(0,a)),t&&(e.pathname=t)}return e}export{t as Action,e as createBrowserHistory,n as createHashHistory,a as createMemoryHistory,c as createPath,u as parsePath};
//# sourceMappingURL=history.production.min.js.map

@@ -1,17 +0,797 @@

import _extends from'@babel/runtime/helpers/esm/extends';var r,B=r||(r={});B.Pop="POP";B.Push="PUSH";B.Replace="REPLACE";var C="production"!==process.env.NODE_ENV?function(b){return Object.freeze(b)}:function(b){return b};function D(b,h){if(!b){"undefined"!==typeof console&&console.warn(h);try{throw Error(h);}catch(e){}}}function E(b){b.preventDefault();b.returnValue=""}
function F(){var b=[];return{get length(){return b.length},push:function(h){b.push(h);return function(){b=b.filter(function(e){return e!==h})}},call:function(h){b.forEach(function(e){return e&&e(h)})}}}function H(){return Math.random().toString(36).substr(2,8)}function I(b){var h=b.pathname;h=void 0===h?"/":h;var e=b.search;e=void 0===e?"":e;b=b.hash;b=void 0===b?"":b;e&&"?"!==e&&(h+="?"===e.charAt(0)?e:"?"+e);b&&"#"!==b&&(h+="#"===b.charAt(0)?b:"#"+b);return h}
function J(b){var h={};if(b){var e=b.indexOf("#");0<=e&&(h.hash=b.substr(e),b=b.substr(0,e));e=b.indexOf("?");0<=e&&(h.search=b.substr(e),b=b.substr(0,e));b&&(h.pathname=b)}return h}
function createBrowserHistory(b){function h(){var c=p.location,a=m.state||{};return[a.idx,C({pathname:c.pathname,search:c.search,hash:c.hash,state:a.usr||null,key:a.key||"default"})]}function e(c){return"string"===typeof c?c:I(c)}function x(c,a){void 0===a&&(a=null);return C(_extends({pathname:q.pathname,hash:"",search:""},"string"===typeof c?J(c):c,{state:a,key:H()}))}function z(c){t=c;c=h();v=c[0];q=c[1];d.call({action:t,location:q})}function A(c,a){function f(){A(c,a)}var l=r.Push,k=x(c,
a);if(!g.length||(g.call({action:l,location:k,retry:f}),!1)){var n=[{usr:k.state,key:k.key,idx:v+1},e(k)];k=n[0];n=n[1];try{m.pushState(k,"",n)}catch(G){p.location.assign(n)}z(l)}}function y(c,a){function f(){y(c,a)}var l=r.Replace,k=x(c,a);g.length&&(g.call({action:l,location:k,retry:f}),1)||(k=[{usr:k.state,key:k.key,idx:v},e(k)],m.replaceState(k[0],"",k[1]),z(l))}function w(c){m.go(c)}void 0===b&&(b={});b=b.window;var p=void 0===b?document.defaultView:b,m=p.history,u=null;p.addEventListener("popstate",
function(){if(u)g.call(u),u=null;else{var c=r.Pop,a=h(),f=a[0];a=a[1];if(g.length)if(null!=f){var l=v-f;l&&(u={action:c,location:a,retry:function(){w(-1*l)}},w(l))}else"production"!==process.env.NODE_ENV?D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
void 0;else z(c)}});var t=r.Pop;b=h();var v=b[0],q=b[1],d=F(),g=F();null==v&&(v=0,m.replaceState(_extends({},m.state,{idx:v}),""));return{get action(){return t},get location(){return q},createHref:e,push:A,replace:y,go:w,back:function(){w(-1)},forward:function(){w(1)},listen:function(c){return d.push(c)},block:function(c){var a=g.push(c);1===g.length&&p.addEventListener("beforeunload",E);return function(){a();g.length||p.removeEventListener("beforeunload",E)}}}};
function createHashHistory(b){function h(){var a=J(m.location.hash.substr(1)),f=a.pathname,l=a.search;a=a.hash;var k=u.state||{};return[k.idx,C({pathname:void 0===f?"/":f,search:void 0===l?"":l,hash:void 0===a?"":a,state:k.usr||null,key:k.key||"default"})]}function e(){if(t)c.call(t),t=null;else{var a=r.Pop,f=h(),l=f[0];f=f[1];if(c.length)if(null!=l){var k=q-l;k&&(t={action:a,location:f,retry:function(){p(-1*k)}},p(k))}else"production"!==process.env.NODE_ENV?D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
void 0;else A(a)}}function x(a){var f=document.querySelector("base"),l="";f&&f.getAttribute("href")&&(f=m.location.href,l=f.indexOf("#"),l=-1===l?f:f.slice(0,l));return l+"#"+("string"===typeof a?a:I(a))}function z(a,f){void 0===f&&(f=null);return C(_extends({pathname:d.pathname,hash:"",search:""},"string"===typeof a?J(a):a,{state:f,key:H()}))}function A(a){v=a;a=h();q=a[0];d=a[1];g.call({action:v,location:d})}function y(a,f){function l(){y(a,f)}var k=r.Push,n=z(a,f);"production"!==process.env.NODE_ENV?
D("/"===n.pathname.charAt(0),"Relative pathnames are not supported in hash history.push("+JSON.stringify(a)+")"):void 0;if(!c.length||(c.call({action:k,location:n,retry:l}),!1)){var G=[{usr:n.state,key:n.key,idx:q+1},x(n)];n=G[0];G=G[1];try{u.pushState(n,"",G)}catch(K){m.location.assign(G)}A(k)}}function w(a,f){function l(){w(a,f)}var k=r.Replace,n=z(a,f);"production"!==process.env.NODE_ENV?D("/"===n.pathname.charAt(0),"Relative pathnames are not supported in hash history.replace("+JSON.stringify(a)+
")"):void 0;c.length&&(c.call({action:k,location:n,retry:l}),1)||(n=[{usr:n.state,key:n.key,idx:q},x(n)],u.replaceState(n[0],"",n[1]),A(k))}function p(a){u.go(a)}void 0===b&&(b={});b=b.window;var m=void 0===b?document.defaultView:b,u=m.history,t=null;m.addEventListener("popstate",e);m.addEventListener("hashchange",function(){var a=h()[1];I(a)!==I(d)&&e()});var v=r.Pop;b=h();var q=b[0],d=b[1],g=F(),c=F();null==q&&(q=0,u.replaceState(_extends({},u.state,{idx:q}),""));return{get action(){return v},get location(){return d},
createHref:x,push:y,replace:w,go:p,back:function(){p(-1)},forward:function(){p(1)},listen:function(a){return g.push(a)},block:function(a){var f=c.push(a);1===c.length&&m.addEventListener("beforeunload",E);return function(){f();c.length||m.removeEventListener("beforeunload",E)}}}};
function createMemoryHistory(b){function h(d,g){void 0===g&&(g=null);return C(_extends({pathname:t.pathname,search:"",hash:""},"string"===typeof d?J(d):d,{state:g,key:H()}))}function e(d,g,c){return!q.length||(q.call({action:d,location:g,retry:c}),!1)}function x(d,g){u=d;t=g;v.call({action:u,location:t})}function z(d,g){var c=r.Push,a=h(d,g);"production"!==process.env.NODE_ENV?D("/"===t.pathname.charAt(0),"Relative pathnames are not supported in memory history.push("+JSON.stringify(d)+")"):
void 0;e(c,a,function(){z(d,g)})&&(m+=1,p.splice(m,p.length,a),x(c,a))}function A(d,g){var c=r.Replace,a=h(d,g);"production"!==process.env.NODE_ENV?D("/"===t.pathname.charAt(0),"Relative pathnames are not supported in memory history.replace("+JSON.stringify(d)+")"):void 0;e(c,a,function(){A(d,g)})&&(p[m]=a,x(c,a))}function y(d){var g=Math.min(Math.max(m+d,0),p.length-1),c=r.Pop,a=p[g];e(c,a,function(){y(d)})&&(m=g,x(c,a))}void 0===b&&(b={});var w=b;b=w.initialEntries;w=w.initialIndex;var p=(void 0===
b?["/"]:b).map(function(d){var g=C(_extends({pathname:"/",search:"",hash:"",state:null,key:H()},"string"===typeof d?J(d):d));"production"!==process.env.NODE_ENV?D("/"===g.pathname.charAt(0),"Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: "+JSON.stringify(d)+")"):void 0;return g}),m=Math.min(Math.max(null==w?p.length-1:w,0),p.length-1),u=r.Pop,t=p[m],v=F(),q=F();return{get index(){return m},get action(){return u},get location(){return t},createHref:function(d){return"string"===
typeof d?d:I(d)},push:z,replace:A,go:y,back:function(){y(-1)},forward:function(){y(1)},listen:function(d){return v.push(d)},block:function(d){return q.push(d)}}};export{r as Action,createBrowserHistory,createHashHistory,createMemoryHistory,I as createPath,J as parsePath}
import _extends from '@babel/runtime/helpers/esm/extends';
/**
* Actions represent the type of change to a location value.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
*/
var Action;
(function (Action) {
/**
* A POP indicates a change to an arbitrary index in the history stack, such
* as a back or forward navigation. It does not describe the direction of the
* navigation, only that the current index changed.
*
* Note: This is the default action for newly created history objects.
*/
Action["Pop"] = "POP";
/**
* A PUSH indicates a new entry being added to the history stack, such as when
* a link is clicked and a new page loads. When this happens, all subsequent
* entries in the stack are lost.
*/
Action["Push"] = "PUSH";
/**
* A REPLACE indicates the entry at the current index in the history stack
* being replaced by a new one.
*/
Action["Replace"] = "REPLACE";
})(Action || (Action = {}));
var readOnly = process.env.NODE_ENV !== "production" ? function (obj) {
return Object.freeze(obj);
} : function (obj) {
return obj;
};
function warning(cond, message) {
if (!cond) {
// eslint-disable-next-line no-console
if (typeof console !== 'undefined') console.warn(message);
try {
// Welcome to debugging history!
//
// This error is thrown as a convenience so you can more easily
// find the source for a warning that appears in the console by
// enabling "pause on exceptions" in your JavaScript debugger.
throw new Error(message); // eslint-disable-next-line no-empty
} catch (e) {}
}
}
var BeforeUnloadEventType = 'beforeunload';
var HashChangeEventType = 'hashchange';
var PopStateEventType = 'popstate';
/**
* Browser history stores the location in regular URLs. This is the standard for
* most web apps, but it requires some configuration on the server to ensure you
* serve the same app at multiple URLs.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
*/
function createBrowserHistory(options) {
if (options === void 0) {
options = {};
}
var _options = options,
_options$window = _options.window,
window = _options$window === void 0 ? document.defaultView : _options$window;
var globalHistory = window.history;
function getIndexAndLocation() {
var _window$location = window.location,
pathname = _window$location.pathname,
search = _window$location.search,
hash = _window$location.hash;
var state = globalHistory.state || {};
return [state.idx, readOnly({
pathname: pathname,
search: search,
hash: hash,
state: state.usr || null,
key: state.key || 'default'
})];
}
var blockedPopTx = null;
function handlePop() {
if (blockedPopTx) {
blockers.call(blockedPopTx);
blockedPopTx = null;
} else {
var nextAction = Action.Pop;
var _getIndexAndLocation = getIndexAndLocation(),
nextIndex = _getIndexAndLocation[0],
nextLocation = _getIndexAndLocation[1];
if (blockers.length) {
if (nextIndex != null) {
var delta = index - nextIndex;
if (delta) {
// Revert the POP
blockedPopTx = {
action: nextAction,
location: nextLocation,
retry: function retry() {
go(delta * -1);
}
};
go(delta);
}
} else {
// Trying to POP to a location with no index. We did not create
// this location, so we can't effectively block the navigation.
process.env.NODE_ENV !== "production" ? warning(false, // TODO: Write up a doc that explains our blocking strategy in
// detail and link to it here so people can understand better what
// is going on and how to avoid it.
"You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
}
} else {
applyTx(nextAction);
}
}
}
window.addEventListener(PopStateEventType, handlePop);
var action = Action.Pop;
var _getIndexAndLocation2 = getIndexAndLocation(),
index = _getIndexAndLocation2[0],
location = _getIndexAndLocation2[1];
var listeners = createEvents();
var blockers = createEvents();
if (index == null) {
index = 0;
globalHistory.replaceState(_extends({}, globalHistory.state, {
idx: index
}), '');
}
function createHref(to) {
return typeof to === 'string' ? to : createPath(to);
} // state defaults to `null` because `window.history.state` does
function getNextLocation(to, state) {
if (state === void 0) {
state = null;
}
return readOnly(_extends({
pathname: location.pathname,
hash: '',
search: ''
}, typeof to === 'string' ? parsePath(to) : to, {
state: state,
key: createKey()
}));
}
function getHistoryStateAndUrl(nextLocation, index) {
return [{
usr: nextLocation.state,
key: nextLocation.key,
idx: index
}, createHref(nextLocation)];
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action: action,
location: location,
retry: retry
}), false);
}
function applyTx(nextAction) {
action = nextAction;
var _getIndexAndLocation3 = getIndexAndLocation();
index = _getIndexAndLocation3[0];
location = _getIndexAndLocation3[1];
listeners.call({
action: action,
location: location
});
}
function push(to, state) {
var nextAction = Action.Push;
var nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1),
historyState = _getHistoryStateAndUr[0],
url = _getHistoryStateAndUr[1]; // TODO: Support forced reloading
// try...catch because iOS limits us to 100 pushState calls :/
try {
globalHistory.pushState(historyState, '', url);
} catch (error) {
// They are going to lose state here, but there is no real
// way to warn them about it since the page will refresh...
window.location.assign(url);
}
applyTx(nextAction);
}
}
function replace(to, state) {
var nextAction = Action.Replace;
var nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index),
historyState = _getHistoryStateAndUr2[0],
url = _getHistoryStateAndUr2[1]; // TODO: Support forced reloading
globalHistory.replaceState(historyState, '', url);
applyTx(nextAction);
}
}
function go(delta) {
globalHistory.go(delta);
}
var history = {
get action() {
return action;
},
get location() {
return location;
},
createHref: createHref,
push: push,
replace: replace,
go: go,
back: function back() {
go(-1);
},
forward: function forward() {
go(1);
},
listen: function listen(listener) {
return listeners.push(listener);
},
block: function block(blocker) {
var unblock = blockers.push(blocker);
if (blockers.length === 1) {
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
return function () {
unblock(); // Remove the beforeunload listener so the document may
// still be salvageable in the pagehide event.
// See https://html.spec.whatwg.org/#unloading-documents
if (!blockers.length) {
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
};
}
};
return history;
}
/**
* Hash history stores the location in window.location.hash. This makes it ideal
* for situations where you don't want to send the location to the server for
* some reason, either because you do cannot configure it or the URL space is
* reserved for something else.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
*/
function createHashHistory(options) {
if (options === void 0) {
options = {};
}
var _options2 = options,
_options2$window = _options2.window,
window = _options2$window === void 0 ? document.defaultView : _options2$window;
var globalHistory = window.history;
function getIndexAndLocation() {
var _parsePath = parsePath(window.location.hash.substr(1)),
_parsePath$pathname = _parsePath.pathname,
pathname = _parsePath$pathname === void 0 ? '/' : _parsePath$pathname,
_parsePath$search = _parsePath.search,
search = _parsePath$search === void 0 ? '' : _parsePath$search,
_parsePath$hash = _parsePath.hash,
hash = _parsePath$hash === void 0 ? '' : _parsePath$hash;
var state = globalHistory.state || {};
return [state.idx, readOnly({
pathname: pathname,
search: search,
hash: hash,
state: state.usr || null,
key: state.key || 'default'
})];
}
var blockedPopTx = null;
function handlePop() {
if (blockedPopTx) {
blockers.call(blockedPopTx);
blockedPopTx = null;
} else {
var nextAction = Action.Pop;
var _getIndexAndLocation4 = getIndexAndLocation(),
nextIndex = _getIndexAndLocation4[0],
nextLocation = _getIndexAndLocation4[1];
if (blockers.length) {
if (nextIndex != null) {
var delta = index - nextIndex;
if (delta) {
// Revert the POP
blockedPopTx = {
action: nextAction,
location: nextLocation,
retry: function retry() {
go(delta * -1);
}
};
go(delta);
}
} else {
// Trying to POP to a location with no index. We did not create
// this location, so we can't effectively block the navigation.
process.env.NODE_ENV !== "production" ? warning(false, // TODO: Write up a doc that explains our blocking strategy in
// detail and link to it here so people can understand better
// what is going on and how to avoid it.
"You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
}
} else {
applyTx(nextAction);
}
}
}
window.addEventListener(PopStateEventType, handlePop); // popstate does not fire on hashchange in IE 11 and old (trident) Edge
// https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event
window.addEventListener(HashChangeEventType, function () {
var _getIndexAndLocation5 = getIndexAndLocation(),
nextLocation = _getIndexAndLocation5[1]; // Ignore extraneous hashchange events.
if (createPath(nextLocation) !== createPath(location)) {
handlePop();
}
});
var action = Action.Pop;
var _getIndexAndLocation6 = getIndexAndLocation(),
index = _getIndexAndLocation6[0],
location = _getIndexAndLocation6[1];
var listeners = createEvents();
var blockers = createEvents();
if (index == null) {
index = 0;
globalHistory.replaceState(_extends({}, globalHistory.state, {
idx: index
}), '');
}
function getBaseHref() {
var base = document.querySelector('base');
var href = '';
if (base && base.getAttribute('href')) {
var url = window.location.href;
var hashIndex = url.indexOf('#');
href = hashIndex === -1 ? url : url.slice(0, hashIndex);
}
return href;
}
function createHref(to) {
return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to));
}
function getNextLocation(to, state) {
if (state === void 0) {
state = null;
}
return readOnly(_extends({
pathname: location.pathname,
hash: '',
search: ''
}, typeof to === 'string' ? parsePath(to) : to, {
state: state,
key: createKey()
}));
}
function getHistoryStateAndUrl(nextLocation, index) {
return [{
usr: nextLocation.state,
key: nextLocation.key,
idx: index
}, createHref(nextLocation)];
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action: action,
location: location,
retry: retry
}), false);
}
function applyTx(nextAction) {
action = nextAction;
var _getIndexAndLocation7 = getIndexAndLocation();
index = _getIndexAndLocation7[0];
location = _getIndexAndLocation7[1];
listeners.call({
action: action,
location: location
});
}
function push(to, state) {
var nextAction = Action.Push;
var nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
process.env.NODE_ENV !== "production" ? warning(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.push(" + JSON.stringify(to) + ")") : void 0;
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr3 = getHistoryStateAndUrl(nextLocation, index + 1),
historyState = _getHistoryStateAndUr3[0],
url = _getHistoryStateAndUr3[1]; // TODO: Support forced reloading
// try...catch because iOS limits us to 100 pushState calls :/
try {
globalHistory.pushState(historyState, '', url);
} catch (error) {
// They are going to lose state here, but there is no real
// way to warn them about it since the page will refresh...
window.location.assign(url);
}
applyTx(nextAction);
}
}
function replace(to, state) {
var nextAction = Action.Replace;
var nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
process.env.NODE_ENV !== "production" ? warning(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(to) + ")") : void 0;
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr4 = getHistoryStateAndUrl(nextLocation, index),
historyState = _getHistoryStateAndUr4[0],
url = _getHistoryStateAndUr4[1]; // TODO: Support forced reloading
globalHistory.replaceState(historyState, '', url);
applyTx(nextAction);
}
}
function go(delta) {
globalHistory.go(delta);
}
var history = {
get action() {
return action;
},
get location() {
return location;
},
createHref: createHref,
push: push,
replace: replace,
go: go,
back: function back() {
go(-1);
},
forward: function forward() {
go(1);
},
listen: function listen(listener) {
return listeners.push(listener);
},
block: function block(blocker) {
var unblock = blockers.push(blocker);
if (blockers.length === 1) {
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
return function () {
unblock(); // Remove the beforeunload listener so the document may
// still be salvageable in the pagehide event.
// See https://html.spec.whatwg.org/#unloading-documents
if (!blockers.length) {
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
};
}
};
return history;
}
/**
* Memory history stores the current location in memory. It is designed for use
* in stateful non-browser environments like tests and React Native.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#creatememoryhistory
*/
function createMemoryHistory(options) {
if (options === void 0) {
options = {};
}
var _options3 = options,
_options3$initialEntr = _options3.initialEntries,
initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
initialIndex = _options3.initialIndex;
var entries = initialEntries.map(function (entry) {
var location = readOnly(_extends({
pathname: '/',
search: '',
hash: '',
state: null,
key: createKey()
}, typeof entry === 'string' ? parsePath(entry) : entry));
process.env.NODE_ENV !== "production" ? warning(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: " + JSON.stringify(entry) + ")") : void 0;
return location;
});
var index = clamp(initialIndex == null ? entries.length - 1 : initialIndex, 0, entries.length - 1);
var action = Action.Pop;
var location = entries[index];
var listeners = createEvents();
var blockers = createEvents();
function createHref(to) {
return typeof to === 'string' ? to : createPath(to);
}
function getNextLocation(to, state) {
if (state === void 0) {
state = null;
}
return readOnly(_extends({
pathname: location.pathname,
search: '',
hash: ''
}, typeof to === 'string' ? parsePath(to) : to, {
state: state,
key: createKey()
}));
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action: action,
location: location,
retry: retry
}), false);
}
function applyTx(nextAction, nextLocation) {
action = nextAction;
location = nextLocation;
listeners.call({
action: action,
location: location
});
}
function push(to, state) {
var nextAction = Action.Push;
var nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
process.env.NODE_ENV !== "production" ? warning(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.push(" + JSON.stringify(to) + ")") : void 0;
if (allowTx(nextAction, nextLocation, retry)) {
index += 1;
entries.splice(index, entries.length, nextLocation);
applyTx(nextAction, nextLocation);
}
}
function replace(to, state) {
var nextAction = Action.Replace;
var nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
process.env.NODE_ENV !== "production" ? warning(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.replace(" + JSON.stringify(to) + ")") : void 0;
if (allowTx(nextAction, nextLocation, retry)) {
entries[index] = nextLocation;
applyTx(nextAction, nextLocation);
}
}
function go(delta) {
var nextIndex = clamp(index + delta, 0, entries.length - 1);
var nextAction = Action.Pop;
var nextLocation = entries[nextIndex];
function retry() {
go(delta);
}
if (allowTx(nextAction, nextLocation, retry)) {
index = nextIndex;
applyTx(nextAction, nextLocation);
}
}
var history = {
get index() {
return index;
},
get action() {
return action;
},
get location() {
return location;
},
createHref: createHref,
push: push,
replace: replace,
go: go,
back: function back() {
go(-1);
},
forward: function forward() {
go(1);
},
listen: function listen(listener) {
return listeners.push(listener);
},
block: function block(blocker) {
return blockers.push(blocker);
}
};
return history;
} ////////////////////////////////////////////////////////////////////////////////
// UTILS
////////////////////////////////////////////////////////////////////////////////
function clamp(n, lowerBound, upperBound) {
return Math.min(Math.max(n, lowerBound), upperBound);
}
function promptBeforeUnload(event) {
// Cancel the event.
event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
event.returnValue = '';
}
function createEvents() {
var handlers = [];
return {
get length() {
return handlers.length;
},
push: function push(fn) {
handlers.push(fn);
return function () {
handlers = handlers.filter(function (handler) {
return handler !== fn;
});
};
},
call: function call(arg) {
handlers.forEach(function (fn) {
return fn && fn(arg);
});
}
};
}
function createKey() {
return Math.random().toString(36).substr(2, 8);
}
/**
* Creates a string URL path from the given pathname, search, and hash components.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
*/
function createPath(_ref) {
var _ref$pathname = _ref.pathname,
pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
_ref$search = _ref.search,
search = _ref$search === void 0 ? '' : _ref$search,
_ref$hash = _ref.hash,
hash = _ref$hash === void 0 ? '' : _ref$hash;
if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
return pathname;
}
/**
* Parses a string URL path into its separate pathname, search, and hash components.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
*/
function parsePath(path) {
var parsedPath = {};
if (path) {
var hashIndex = path.indexOf('#');
if (hashIndex >= 0) {
parsedPath.hash = path.substr(hashIndex);
path = path.substr(0, hashIndex);
}
var searchIndex = path.indexOf('?');
if (searchIndex >= 0) {
parsedPath.search = path.substr(searchIndex);
path = path.substr(0, searchIndex);
}
if (path) {
parsedPath.pathname = path;
}
}
return parsedPath;
}
export { Action, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, parsePath };
//# sourceMappingURL=index.js.map
{
"name": "history",
"version": "5.2.0",
"version": "5.3.0-pre.0",
"description": "Manage session history with JavaScript",

@@ -5,0 +5,0 @@ "author": "Remix Software <hello@remix.run>",

@@ -1,16 +0,825 @@

'use strict';(function(l,y){"object"===typeof exports&&"undefined"!==typeof module?y(exports):"function"===typeof define&&define.amd?define(["exports"],y):(l="undefined"!==typeof globalThis?globalThis:l||self,y(l.HistoryLibrary={}))})(this,function(l){function y(){y=Object.assign||function(b){for(var f=1;f<arguments.length;f++){var e=arguments[f],t;for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&(b[t]=e[t])}return b};return y.apply(this,arguments)}function C(b,f){if(!b){"undefined"!==typeof console&&
console.warn(f);try{throw Error(f);}catch(e){}}}function H(b){b.preventDefault();b.returnValue=""}function D(){var b=[];return{get length(){return b.length},push:function(f){b.push(f);return function(){b=b.filter(function(e){return e!==f})}},call:function(f){b.forEach(function(e){return e&&e(f)})}}}function I(){return Math.random().toString(36).substr(2,8)}function E(b){var f=b.pathname;f=void 0===f?"/":f;var e=b.search;e=void 0===e?"":e;b=b.hash;b=void 0===b?"":b;e&&"?"!==e&&(f+="?"===e.charAt(0)?
e:"?"+e);b&&"#"!==b&&(f+="#"===b.charAt(0)?b:"#"+b);return f}function F(b){var f={};if(b){var e=b.indexOf("#");0<=e&&(f.hash=b.substr(e),b=b.substr(0,e));e=b.indexOf("?");0<=e&&(f.search=b.substr(e),b=b.substr(0,e));b&&(f.pathname=b)}return f}l.Action=void 0;(function(b){b.Pop="POP";b.Push="PUSH";b.Replace="REPLACE"})(l.Action||(l.Action={}));l.createBrowserHistory=function(b){function f(){var c=q.location,a=n.state||{};return[a.idx,Object.freeze({pathname:c.pathname,search:c.search,hash:c.hash,state:a.usr||
null,key:a.key||"default"})]}function e(c){return"string"===typeof c?c:E(c)}function t(c,a){void 0===a&&(a=null);return Object.freeze(y({pathname:r.pathname,hash:"",search:""},"string"===typeof c?F(c):c,{state:a,key:I()}))}function A(c){u=c;c=f();w=c[0];r=c[1];d.call({action:u,location:r})}function B(c,a){function g(){B(c,a)}var m=l.Action.Push,k=t(c,a);if(!h.length||(h.call({action:m,location:k,retry:g}),!1)){var p=[{usr:k.state,key:k.key,idx:w+1},e(k)];k=p[0];p=p[1];try{n.pushState(k,"",p)}catch(G){q.location.assign(p)}A(m)}}
function z(c,a){function g(){z(c,a)}var m=l.Action.Replace,k=t(c,a);h.length&&(h.call({action:m,location:k,retry:g}),1)||(k=[{usr:k.state,key:k.key,idx:w},e(k)],n.replaceState(k[0],"",k[1]),A(m))}function x(c){n.go(c)}void 0===b&&(b={});b=b.window;var q=void 0===b?document.defaultView:b,n=q.history,v=null;q.addEventListener("popstate",function(){if(v)h.call(v),v=null;else{var c=l.Action.Pop,a=f(),g=a[0];a=a[1];if(h.length)if(null!=g){var m=w-g;m&&(v={action:c,location:a,retry:function(){x(-1*m)}},
x(m))}else C(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");else A(c)}});var u=l.Action.Pop;b=f();var w=b[0],r=b[1],d=D(),h=D();null==w&&(w=0,n.replaceState(y({},n.state,{idx:w}),""));return{get action(){return u},get location(){return r},createHref:e,
push:B,replace:z,go:x,back:function(){x(-1)},forward:function(){x(1)},listen:function(c){return d.push(c)},block:function(c){var a=h.push(c);1===h.length&&q.addEventListener("beforeunload",H);return function(){a();h.length||q.removeEventListener("beforeunload",H)}}}};l.createHashHistory=function(b){function f(){var a=F(n.location.hash.substr(1)),g=a.pathname,m=a.search;a=a.hash;var k=v.state||{};return[k.idx,Object.freeze({pathname:void 0===g?"/":g,search:void 0===m?"":m,hash:void 0===a?"":a,state:k.usr||
null,key:k.key||"default"})]}function e(){if(u)c.call(u),u=null;else{var a=l.Action.Pop,g=f(),m=g[0];g=g[1];if(c.length)if(null!=m){var k=r-m;k&&(u={action:a,location:g,retry:function(){q(-1*k)}},q(k))}else C(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");
else B(a)}}function t(a){var g=document.querySelector("base"),m="";g&&g.getAttribute("href")&&(g=n.location.href,m=g.indexOf("#"),m=-1===m?g:g.slice(0,m));return m+"#"+("string"===typeof a?a:E(a))}function A(a,g){void 0===g&&(g=null);return Object.freeze(y({pathname:d.pathname,hash:"",search:""},"string"===typeof a?F(a):a,{state:g,key:I()}))}function B(a){w=a;a=f();r=a[0];d=a[1];h.call({action:w,location:d})}function z(a,g){function m(){z(a,g)}var k=l.Action.Push,p=A(a,g);C("/"===p.pathname.charAt(0),
"Relative pathnames are not supported in hash history.push("+JSON.stringify(a)+")");if(!c.length||(c.call({action:k,location:p,retry:m}),!1)){var G=[{usr:p.state,key:p.key,idx:r+1},t(p)];p=G[0];G=G[1];try{v.pushState(p,"",G)}catch(J){n.location.assign(G)}B(k)}}function x(a,g){function m(){x(a,g)}var k=l.Action.Replace,p=A(a,g);C("/"===p.pathname.charAt(0),"Relative pathnames are not supported in hash history.replace("+JSON.stringify(a)+")");c.length&&(c.call({action:k,location:p,retry:m}),1)||(p=
[{usr:p.state,key:p.key,idx:r},t(p)],v.replaceState(p[0],"",p[1]),B(k))}function q(a){v.go(a)}void 0===b&&(b={});b=b.window;var n=void 0===b?document.defaultView:b,v=n.history,u=null;n.addEventListener("popstate",e);n.addEventListener("hashchange",function(){var a=f()[1];E(a)!==E(d)&&e()});var w=l.Action.Pop;b=f();var r=b[0],d=b[1],h=D(),c=D();null==r&&(r=0,v.replaceState(y({},v.state,{idx:r}),""));return{get action(){return w},get location(){return d},createHref:t,push:z,replace:x,go:q,back:function(){q(-1)},
forward:function(){q(1)},listen:function(a){return h.push(a)},block:function(a){var g=c.push(a);1===c.length&&n.addEventListener("beforeunload",H);return function(){g();c.length||n.removeEventListener("beforeunload",H)}}}};l.createMemoryHistory=function(b){function f(d,h){void 0===h&&(h=null);return Object.freeze(y({pathname:u.pathname,search:"",hash:""},"string"===typeof d?F(d):d,{state:h,key:I()}))}function e(d,h,c){return!r.length||(r.call({action:d,location:h,retry:c}),!1)}function t(d,h){v=d;
u=h;w.call({action:v,location:u})}function A(d,h){var c=l.Action.Push,a=f(d,h);C("/"===u.pathname.charAt(0),"Relative pathnames are not supported in memory history.push("+JSON.stringify(d)+")");e(c,a,function(){A(d,h)})&&(n+=1,q.splice(n,q.length,a),t(c,a))}function B(d,h){var c=l.Action.Replace,a=f(d,h);C("/"===u.pathname.charAt(0),"Relative pathnames are not supported in memory history.replace("+JSON.stringify(d)+")");e(c,a,function(){B(d,h)})&&(q[n]=a,t(c,a))}function z(d){var h=Math.min(Math.max(n+
d,0),q.length-1),c=l.Action.Pop,a=q[h];e(c,a,function(){z(d)})&&(n=h,t(c,a))}void 0===b&&(b={});var x=b;b=x.initialEntries;x=x.initialIndex;var q=(void 0===b?["/"]:b).map(function(d){var h=Object.freeze(y({pathname:"/",search:"",hash:"",state:null,key:I()},"string"===typeof d?F(d):d));C("/"===h.pathname.charAt(0),"Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: "+JSON.stringify(d)+")");return h}),n=Math.min(Math.max(null==x?q.length-1:x,0),q.length-
1),v=l.Action.Pop,u=q[n],w=D(),r=D();return{get index(){return n},get action(){return v},get location(){return u},createHref:function(d){return"string"===typeof d?d:E(d)},push:A,replace:B,go:z,back:function(){z(-1)},forward:function(){z(1)},listen:function(d){return w.push(d)},block:function(d){return r.push(d)}}};l.createPath=E;l.parsePath=F;Object.defineProperty(l,"__esModule",{value:!0})})
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.HistoryLibrary = {}));
}(this, (function (exports) { 'use strict';
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
/**
* Actions represent the type of change to a location value.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
*/
exports.Action = void 0;
(function (Action) {
/**
* A POP indicates a change to an arbitrary index in the history stack, such
* as a back or forward navigation. It does not describe the direction of the
* navigation, only that the current index changed.
*
* Note: This is the default action for newly created history objects.
*/
Action["Pop"] = "POP";
/**
* A PUSH indicates a new entry being added to the history stack, such as when
* a link is clicked and a new page loads. When this happens, all subsequent
* entries in the stack are lost.
*/
Action["Push"] = "PUSH";
/**
* A REPLACE indicates the entry at the current index in the history stack
* being replaced by a new one.
*/
Action["Replace"] = "REPLACE";
})(exports.Action || (exports.Action = {}));
var readOnly = function (obj) {
return Object.freeze(obj);
} ;
function warning(cond, message) {
if (!cond) {
// eslint-disable-next-line no-console
if (typeof console !== 'undefined') console.warn(message);
try {
// Welcome to debugging history!
//
// This error is thrown as a convenience so you can more easily
// find the source for a warning that appears in the console by
// enabling "pause on exceptions" in your JavaScript debugger.
throw new Error(message); // eslint-disable-next-line no-empty
} catch (e) {}
}
}
var BeforeUnloadEventType = 'beforeunload';
var HashChangeEventType = 'hashchange';
var PopStateEventType = 'popstate';
/**
* Browser history stores the location in regular URLs. This is the standard for
* most web apps, but it requires some configuration on the server to ensure you
* serve the same app at multiple URLs.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
*/
function createBrowserHistory(options) {
if (options === void 0) {
options = {};
}
var _options = options,
_options$window = _options.window,
window = _options$window === void 0 ? document.defaultView : _options$window;
var globalHistory = window.history;
function getIndexAndLocation() {
var _window$location = window.location,
pathname = _window$location.pathname,
search = _window$location.search,
hash = _window$location.hash;
var state = globalHistory.state || {};
return [state.idx, readOnly({
pathname: pathname,
search: search,
hash: hash,
state: state.usr || null,
key: state.key || 'default'
})];
}
var blockedPopTx = null;
function handlePop() {
if (blockedPopTx) {
blockers.call(blockedPopTx);
blockedPopTx = null;
} else {
var nextAction = exports.Action.Pop;
var _getIndexAndLocation = getIndexAndLocation(),
nextIndex = _getIndexAndLocation[0],
nextLocation = _getIndexAndLocation[1];
if (blockers.length) {
if (nextIndex != null) {
var delta = index - nextIndex;
if (delta) {
// Revert the POP
blockedPopTx = {
action: nextAction,
location: nextLocation,
retry: function retry() {
go(delta * -1);
}
};
go(delta);
}
} else {
// Trying to POP to a location with no index. We did not create
// this location, so we can't effectively block the navigation.
warning(false, // TODO: Write up a doc that explains our blocking strategy in
// detail and link to it here so people can understand better what
// is going on and how to avoid it.
"You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") ;
}
} else {
applyTx(nextAction);
}
}
}
window.addEventListener(PopStateEventType, handlePop);
var action = exports.Action.Pop;
var _getIndexAndLocation2 = getIndexAndLocation(),
index = _getIndexAndLocation2[0],
location = _getIndexAndLocation2[1];
var listeners = createEvents();
var blockers = createEvents();
if (index == null) {
index = 0;
globalHistory.replaceState(_extends({}, globalHistory.state, {
idx: index
}), '');
}
function createHref(to) {
return typeof to === 'string' ? to : createPath(to);
} // state defaults to `null` because `window.history.state` does
function getNextLocation(to, state) {
if (state === void 0) {
state = null;
}
return readOnly(_extends({
pathname: location.pathname,
hash: '',
search: ''
}, typeof to === 'string' ? parsePath(to) : to, {
state: state,
key: createKey()
}));
}
function getHistoryStateAndUrl(nextLocation, index) {
return [{
usr: nextLocation.state,
key: nextLocation.key,
idx: index
}, createHref(nextLocation)];
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action: action,
location: location,
retry: retry
}), false);
}
function applyTx(nextAction) {
action = nextAction;
var _getIndexAndLocation3 = getIndexAndLocation();
index = _getIndexAndLocation3[0];
location = _getIndexAndLocation3[1];
listeners.call({
action: action,
location: location
});
}
function push(to, state) {
var nextAction = exports.Action.Push;
var nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1),
historyState = _getHistoryStateAndUr[0],
url = _getHistoryStateAndUr[1]; // TODO: Support forced reloading
// try...catch because iOS limits us to 100 pushState calls :/
try {
globalHistory.pushState(historyState, '', url);
} catch (error) {
// They are going to lose state here, but there is no real
// way to warn them about it since the page will refresh...
window.location.assign(url);
}
applyTx(nextAction);
}
}
function replace(to, state) {
var nextAction = exports.Action.Replace;
var nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index),
historyState = _getHistoryStateAndUr2[0],
url = _getHistoryStateAndUr2[1]; // TODO: Support forced reloading
globalHistory.replaceState(historyState, '', url);
applyTx(nextAction);
}
}
function go(delta) {
globalHistory.go(delta);
}
var history = {
get action() {
return action;
},
get location() {
return location;
},
createHref: createHref,
push: push,
replace: replace,
go: go,
back: function back() {
go(-1);
},
forward: function forward() {
go(1);
},
listen: function listen(listener) {
return listeners.push(listener);
},
block: function block(blocker) {
var unblock = blockers.push(blocker);
if (blockers.length === 1) {
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
return function () {
unblock(); // Remove the beforeunload listener so the document may
// still be salvageable in the pagehide event.
// See https://html.spec.whatwg.org/#unloading-documents
if (!blockers.length) {
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
};
}
};
return history;
}
/**
* Hash history stores the location in window.location.hash. This makes it ideal
* for situations where you don't want to send the location to the server for
* some reason, either because you do cannot configure it or the URL space is
* reserved for something else.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
*/
function createHashHistory(options) {
if (options === void 0) {
options = {};
}
var _options2 = options,
_options2$window = _options2.window,
window = _options2$window === void 0 ? document.defaultView : _options2$window;
var globalHistory = window.history;
function getIndexAndLocation() {
var _parsePath = parsePath(window.location.hash.substr(1)),
_parsePath$pathname = _parsePath.pathname,
pathname = _parsePath$pathname === void 0 ? '/' : _parsePath$pathname,
_parsePath$search = _parsePath.search,
search = _parsePath$search === void 0 ? '' : _parsePath$search,
_parsePath$hash = _parsePath.hash,
hash = _parsePath$hash === void 0 ? '' : _parsePath$hash;
var state = globalHistory.state || {};
return [state.idx, readOnly({
pathname: pathname,
search: search,
hash: hash,
state: state.usr || null,
key: state.key || 'default'
})];
}
var blockedPopTx = null;
function handlePop() {
if (blockedPopTx) {
blockers.call(blockedPopTx);
blockedPopTx = null;
} else {
var nextAction = exports.Action.Pop;
var _getIndexAndLocation4 = getIndexAndLocation(),
nextIndex = _getIndexAndLocation4[0],
nextLocation = _getIndexAndLocation4[1];
if (blockers.length) {
if (nextIndex != null) {
var delta = index - nextIndex;
if (delta) {
// Revert the POP
blockedPopTx = {
action: nextAction,
location: nextLocation,
retry: function retry() {
go(delta * -1);
}
};
go(delta);
}
} else {
// Trying to POP to a location with no index. We did not create
// this location, so we can't effectively block the navigation.
warning(false, // TODO: Write up a doc that explains our blocking strategy in
// detail and link to it here so people can understand better
// what is going on and how to avoid it.
"You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") ;
}
} else {
applyTx(nextAction);
}
}
}
window.addEventListener(PopStateEventType, handlePop); // popstate does not fire on hashchange in IE 11 and old (trident) Edge
// https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event
window.addEventListener(HashChangeEventType, function () {
var _getIndexAndLocation5 = getIndexAndLocation(),
nextLocation = _getIndexAndLocation5[1]; // Ignore extraneous hashchange events.
if (createPath(nextLocation) !== createPath(location)) {
handlePop();
}
});
var action = exports.Action.Pop;
var _getIndexAndLocation6 = getIndexAndLocation(),
index = _getIndexAndLocation6[0],
location = _getIndexAndLocation6[1];
var listeners = createEvents();
var blockers = createEvents();
if (index == null) {
index = 0;
globalHistory.replaceState(_extends({}, globalHistory.state, {
idx: index
}), '');
}
function getBaseHref() {
var base = document.querySelector('base');
var href = '';
if (base && base.getAttribute('href')) {
var url = window.location.href;
var hashIndex = url.indexOf('#');
href = hashIndex === -1 ? url : url.slice(0, hashIndex);
}
return href;
}
function createHref(to) {
return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to));
}
function getNextLocation(to, state) {
if (state === void 0) {
state = null;
}
return readOnly(_extends({
pathname: location.pathname,
hash: '',
search: ''
}, typeof to === 'string' ? parsePath(to) : to, {
state: state,
key: createKey()
}));
}
function getHistoryStateAndUrl(nextLocation, index) {
return [{
usr: nextLocation.state,
key: nextLocation.key,
idx: index
}, createHref(nextLocation)];
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action: action,
location: location,
retry: retry
}), false);
}
function applyTx(nextAction) {
action = nextAction;
var _getIndexAndLocation7 = getIndexAndLocation();
index = _getIndexAndLocation7[0];
location = _getIndexAndLocation7[1];
listeners.call({
action: action,
location: location
});
}
function push(to, state) {
var nextAction = exports.Action.Push;
var nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
warning(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.push(" + JSON.stringify(to) + ")") ;
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr3 = getHistoryStateAndUrl(nextLocation, index + 1),
historyState = _getHistoryStateAndUr3[0],
url = _getHistoryStateAndUr3[1]; // TODO: Support forced reloading
// try...catch because iOS limits us to 100 pushState calls :/
try {
globalHistory.pushState(historyState, '', url);
} catch (error) {
// They are going to lose state here, but there is no real
// way to warn them about it since the page will refresh...
window.location.assign(url);
}
applyTx(nextAction);
}
}
function replace(to, state) {
var nextAction = exports.Action.Replace;
var nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
warning(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(to) + ")") ;
if (allowTx(nextAction, nextLocation, retry)) {
var _getHistoryStateAndUr4 = getHistoryStateAndUrl(nextLocation, index),
historyState = _getHistoryStateAndUr4[0],
url = _getHistoryStateAndUr4[1]; // TODO: Support forced reloading
globalHistory.replaceState(historyState, '', url);
applyTx(nextAction);
}
}
function go(delta) {
globalHistory.go(delta);
}
var history = {
get action() {
return action;
},
get location() {
return location;
},
createHref: createHref,
push: push,
replace: replace,
go: go,
back: function back() {
go(-1);
},
forward: function forward() {
go(1);
},
listen: function listen(listener) {
return listeners.push(listener);
},
block: function block(blocker) {
var unblock = blockers.push(blocker);
if (blockers.length === 1) {
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
return function () {
unblock(); // Remove the beforeunload listener so the document may
// still be salvageable in the pagehide event.
// See https://html.spec.whatwg.org/#unloading-documents
if (!blockers.length) {
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
};
}
};
return history;
}
/**
* Memory history stores the current location in memory. It is designed for use
* in stateful non-browser environments like tests and React Native.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#creatememoryhistory
*/
function createMemoryHistory(options) {
if (options === void 0) {
options = {};
}
var _options3 = options,
_options3$initialEntr = _options3.initialEntries,
initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
initialIndex = _options3.initialIndex;
var entries = initialEntries.map(function (entry) {
var location = readOnly(_extends({
pathname: '/',
search: '',
hash: '',
state: null,
key: createKey()
}, typeof entry === 'string' ? parsePath(entry) : entry));
warning(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: " + JSON.stringify(entry) + ")") ;
return location;
});
var index = clamp(initialIndex == null ? entries.length - 1 : initialIndex, 0, entries.length - 1);
var action = exports.Action.Pop;
var location = entries[index];
var listeners = createEvents();
var blockers = createEvents();
function createHref(to) {
return typeof to === 'string' ? to : createPath(to);
}
function getNextLocation(to, state) {
if (state === void 0) {
state = null;
}
return readOnly(_extends({
pathname: location.pathname,
search: '',
hash: ''
}, typeof to === 'string' ? parsePath(to) : to, {
state: state,
key: createKey()
}));
}
function allowTx(action, location, retry) {
return !blockers.length || (blockers.call({
action: action,
location: location,
retry: retry
}), false);
}
function applyTx(nextAction, nextLocation) {
action = nextAction;
location = nextLocation;
listeners.call({
action: action,
location: location
});
}
function push(to, state) {
var nextAction = exports.Action.Push;
var nextLocation = getNextLocation(to, state);
function retry() {
push(to, state);
}
warning(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.push(" + JSON.stringify(to) + ")") ;
if (allowTx(nextAction, nextLocation, retry)) {
index += 1;
entries.splice(index, entries.length, nextLocation);
applyTx(nextAction, nextLocation);
}
}
function replace(to, state) {
var nextAction = exports.Action.Replace;
var nextLocation = getNextLocation(to, state);
function retry() {
replace(to, state);
}
warning(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.replace(" + JSON.stringify(to) + ")") ;
if (allowTx(nextAction, nextLocation, retry)) {
entries[index] = nextLocation;
applyTx(nextAction, nextLocation);
}
}
function go(delta) {
var nextIndex = clamp(index + delta, 0, entries.length - 1);
var nextAction = exports.Action.Pop;
var nextLocation = entries[nextIndex];
function retry() {
go(delta);
}
if (allowTx(nextAction, nextLocation, retry)) {
index = nextIndex;
applyTx(nextAction, nextLocation);
}
}
var history = {
get index() {
return index;
},
get action() {
return action;
},
get location() {
return location;
},
createHref: createHref,
push: push,
replace: replace,
go: go,
back: function back() {
go(-1);
},
forward: function forward() {
go(1);
},
listen: function listen(listener) {
return listeners.push(listener);
},
block: function block(blocker) {
return blockers.push(blocker);
}
};
return history;
} ////////////////////////////////////////////////////////////////////////////////
// UTILS
////////////////////////////////////////////////////////////////////////////////
function clamp(n, lowerBound, upperBound) {
return Math.min(Math.max(n, lowerBound), upperBound);
}
function promptBeforeUnload(event) {
// Cancel the event.
event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
event.returnValue = '';
}
function createEvents() {
var handlers = [];
return {
get length() {
return handlers.length;
},
push: function push(fn) {
handlers.push(fn);
return function () {
handlers = handlers.filter(function (handler) {
return handler !== fn;
});
};
},
call: function call(arg) {
handlers.forEach(function (fn) {
return fn && fn(arg);
});
}
};
}
function createKey() {
return Math.random().toString(36).substr(2, 8);
}
/**
* Creates a string URL path from the given pathname, search, and hash components.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
*/
function createPath(_ref) {
var _ref$pathname = _ref.pathname,
pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
_ref$search = _ref.search,
search = _ref$search === void 0 ? '' : _ref$search,
_ref$hash = _ref.hash,
hash = _ref$hash === void 0 ? '' : _ref$hash;
if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
return pathname;
}
/**
* Parses a string URL path into its separate pathname, search, and hash components.
*
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
*/
function parsePath(path) {
var parsedPath = {};
if (path) {
var hashIndex = path.indexOf('#');
if (hashIndex >= 0) {
parsedPath.hash = path.substr(hashIndex);
path = path.substr(0, hashIndex);
}
var searchIndex = path.indexOf('?');
if (searchIndex >= 0) {
parsedPath.search = path.substr(searchIndex);
path = path.substr(0, searchIndex);
}
if (path) {
parsedPath.pathname = path;
}
}
return parsedPath;
}
exports.createBrowserHistory = createBrowserHistory;
exports.createHashHistory = createHashHistory;
exports.createMemoryHistory = createMemoryHistory;
exports.createPath = createPath;
exports.parsePath = parsePath;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=history.development.js.map

@@ -1,2 +0,2 @@

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

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 not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc