LocalCDN-Firefox-Chrome-Brave/resources/history/5.2.0/history.min.jsm

3 lines
6.0 KiB
JavaScript

"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})}));
//# sourceMappingURL=history.production.min.js.map