react-idle-timer
Advanced tools
Comparing version
@@ -99,3 +99,3 @@ /// <reference types='react'/> | ||
export default class IdleTimer extends React.Component<IdleTimerProps> { | ||
export default class IdleTimer extends React.Component<IdleTimerClassProps> { | ||
/** | ||
@@ -194,2 +194,9 @@ * Alias to reset. | ||
interface IdleTimerClassProps extends IdleTimerProps { | ||
/** | ||
* React reference to the IdleTimer Component instance. | ||
*/ | ||
ref: (ref: IdleTimer) => any | ||
} | ||
interface IdleTimerProps { | ||
@@ -196,0 +203,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import{Component as e,useRef as t,useEffect as n,useMemo as r}from"react";import i from"prop-types";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function s(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}function u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function h(e,t){return!t||"object"!==l(t)&&"function"!=typeof t?u(e):t}function f(e){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function d(e,t,n,r,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void n(e)}s.done?t(u):Promise.resolve(u).then(r,i)}function p(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var o=e.apply(t,n);function a(e){d(o,r,i,a,s,"next",e)}function s(e){d(o,r,i,a,s,"throw",e)}a(void 0)}))}}function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}}(e,t)||function(e,t){if(e){if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?v(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var g,y=(function(e){var t=function(e){var t,n=Object.prototype,r=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function u(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=t&&t.prototype instanceof m?t:m,o=Object.create(i.prototype),a=new O(r||[]);return o._invoke=function(e,t,n){var r=h;return function(i,o){if(r===d)throw new Error("Generator is already running");if(r===p){if("throw"===i)throw o;return S()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var s=E(a,n);if(s){if(s===v)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===h)throw r=p,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=d;var u=l(e,t,n);if("normal"===u.type){if(r=n.done?p:f,u.arg===v)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=p,n.method="throw",n.arg=u.arg)}}}(e,n,a),o}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var h="suspendedStart",f="suspendedYield",d="executing",p="completed",v={};function m(){}function g(){}function y(){}var b={};b[o]=function(){return this};var w=Object.getPrototypeOf,_=w&&w(w(x([])));_&&_!==n&&r.call(_,o)&&(b=_);var T=y.prototype=m.prototype=Object.create(b);function k(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function A(e,t){function n(i,o,a,s){var u=l(e[i],e,o);if("throw"!==u.type){var c=u.arg,h=c.value;return h&&"object"==typeof h&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(h).then((function(e){c.value=e,a(c)}),(function(e){return n("throw",e,a,s)}))}s(u.arg)}var i;this._invoke=function(e,r){function o(){return new t((function(t,i){n(e,r,t,i)}))}return i=i?i.then(o,o):o()}}function E(e,n){var r=e.iterator[n.method];if(r===t){if(n.delegate=null,"throw"===n.method){if(e.iterator.return&&(n.method="return",n.arg=t,E(e,n),"throw"===n.method))return v;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var i=l(r,e.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,v;var o=i.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,v):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function I(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function L(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(I,this),this.reset(!0)}function x(e){if(e){var n=e[o];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,a=function n(){for(;++i<e.length;)if(r.call(e,i))return n.value=e[i],n.done=!1,n;return n.value=t,n.done=!0,n};return a.next=a}}return{next:S}}function S(){return{value:t,done:!0}}return g.prototype=T.constructor=y,y.constructor=g,g.displayName=u(y,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===g||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,u(e,s,"GeneratorFunction")),e.prototype=Object.create(T),e},e.awrap=function(e){return{__await:e}},k(A.prototype),A.prototype[a]=function(){return this},e.AsyncIterator=A,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var a=new A(c(t,n,r,i),o);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},k(T),u(T,s,"Generator"),T[o]=function(){return this},T.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=x,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(L),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function i(r,i){return s.type="throw",s.arg=e,n.next=r,i&&(n.method="next",n.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),L(n),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;L(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:x(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),v}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(g={exports:{}},g.exports),g.exports),b="object"===("undefined"==typeof window||"undefined"==typeof window?"undefined":l(window)),w=b?document:{},_=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange"];function T(e,t){var n;function r(){for(var r=arguments.length,i=new Array(r),o=0;o<r;o++)i[o]=arguments[o];n&&clearTimeout(n),n=setTimeout((function(){e.apply(void 0,i),n=null}),t)}return r.cancel=function(){clearTimeout(n)},r}function k(e,t){var n=0;return function(){var r=(new Date).getTime();if(!(r-n<t))return n=r,e.apply(void 0,arguments)}}var A=0,E=0;function I(){var e=(new Date).getTime();return e===A?1e3*e+ ++E:(A=e,E=0,1e3*e)}function L(){return Math.random().toString(36).substring(2)}function O(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return new Promise((function(t){return setTimeout(t,e)}))}function x(){return(new Date).getTime()}var S={create:function(e){var t={messagesCallback:null,bc:new BroadcastChannel(e)};return t.bc.onmessage=function(e){t.messagesCallback&&t.messagesCallback(e.data)},t},close:function(e){e.bc.close()},onMessage:function(e,t){e.messagesCallback=t},postMessage:function(e,t){try{return e.bc.postMessage(t,!1),Promise.resolve()}catch(e){return Promise.reject(e)}},canBeUsed:function(){return"function"==typeof BroadcastChannel},type:"broadcastChannel",averageResponseTime:function(){return 150},microSeconds:I},M=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:6e4;o(this,e),this.ttl=t,this.set=new Set,this.timeMap=new Map}return s(e,[{key:"has",value:function(e){return this.set.has(e)}},{key:"add",value:function(e){this.timeMap.set(e,x()),this.set.add(e),this._removeTooOldValues()}},{key:"clear",value:function(){this.set.clear(),this.timeMap.clear()}},{key:"_removeTooOldValues",value:function(){for(var e=x()-this.ttl,t=this.set[Symbol.iterator]();;){var n=t.next().value;if(!n)return;if(!(this.timeMap.get(n)<e))return;this.timeMap.delete(n),this.set.delete(n)}}}]),e}();function D(){var e;if("undefined"==typeof window)return null;try{e=window.localStorage,e=window["ie8-eventlistener/storage"]||window.localStorage}catch(e){}return e}function P(e,t){var n=e,r=function(e){e.key===n&&t(JSON.parse(e.newValue))};return window.addEventListener("storage",r),r}function j(){var e=D();if(!e)return!1;try{var t="__check";e.setItem(t,"works"),e.removeItem(t)}catch(e){return!1}return!0}var C={create:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!j())throw new Error("❌ localStorage cannot be used.");var n=L(),r=new M(t.removeTimeout),i={channelName:e,uuid:n,eMIs:r};return i.listener=P(e,(function(e){i.messagesCallback&&e.uuid!==n&&e.token&&!r.has(e.token)&&(e.data.time&&e.data.time<i.messagesCallbackTime||(r.add(e.token),i.messagesCallback(e.data)))})),i},close:function(e){var t;t=e.listener,window.removeEventListener("storage",t)},onMessage:function(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t},postMessage:function(e,t){return new Promise((function(n){var r=e.channelName,i={token:L(),time:(new Date).getTime(),data:t,uuid:e.uuid},o=JSON.stringify(i);D().setItem(r,o);var a=document.createEvent("Event");a.initEvent("storage",!0,!0),a.key=r,a.newValue=o,window.dispatchEvent(a),n()}))},canBeUsed:j,type:"localStorage",averageResponseTime:function(){var e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?240:120},microSeconds:I},N=new Set;var R={create:function(e){var t={name:e,messagesCallback:null};return N.add(t),t},close:function(e){N.delete(e)},onMessage:function(e,t){e.messagesCallback=t},postMessage:function(e,t){return new Promise((function(n){return setTimeout((function(){Array.from(N).filter((function(t){return t.name===e.name})).filter((function(t){return t!==e})).filter((function(e){return!!e.messagesCallback})).forEach((function(e){return e.messagesCallback(t)})),n()}),5)}))},canBeUsed:function(){return!0},type:"simulate",averageResponseTime:function(){return 5},microSeconds:I},B=[S,C];function Y(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.type){if("simulate"===e.type)return R;var t=B.find((function(t){return t.type===e.type}));if(t)return t;throw new Error("❌ Method ".concat(e.type," is not supported."))}var n=B.find((function(e){return e.canBeUsed()}));if(!n)throw new Error("❌ No method found ".concat(JSON.stringify(B.map((function(e){return e.type})))));return n}var F=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e),this.name=t,this.options=n,this.method=Y(this.options),this.closed=!1,this._isListening=!1,this._onMessageListener=null,this._addEventListeners={message:[],internal:[]},this._unSendMessagePromises=new Set,this._beforeClose=[],this._preparePromises=null,X(this)}return s(e,[{key:"postMessage",value:function(e){if(this.closed)throw new Error("❌ Cannot post message after channel has closed");return U(this,"message",e)}},{key:"postInternal",value:function(e){return U(this,"internal",e)}},{key:"onmessage",get:function(){return this._onMessageListener},set:function(e){var t={time:this.method.microSeconds(),fn:e};J(this,"message",this._onMessageListener),e&&"function"==typeof e?(this._onMessageListener=t,V(this,"message",t)):this._onMessageListener=null}},{key:"addEventListener",value:function(e,t){V(this,e,{time:this.method.microSeconds(),fn:t})}},{key:"removeEventListener",value:function(e,t){J(this,e,this._addEventListeners[e].find((function(e){return e.fn===t})))}},{key:"close",value:function(){var e=this;if(!this.closed){this.closed=!0;var t=this._preparePromises?this._preparePromises:Promise.resolve();return this._onMessageListener=null,this._addEventListeners.message=[],t.then((function(){return Promise.all(Array.from(e._unSendMessagePromises))})).then((function(){return Promise.all(e._beforeClose.map((function(e){return e()})))})).then((function(){return e.method.close(e._state)}))}}},{key:"type",get:function(){return this.method.type}},{key:"isClosed",value:function(){return this.closed}}]),e}();function U(e,t,n){var r={time:e.method.microSeconds(),type:t,data:n};return(e._preparePromises?e._preparePromises:Promise.resolve()).then((function(){var t=e.method.postMessage(e._state,r);return e._unSendMessagePromises.add(t),t.catch().then((function(){return e._unSendMessagePromises.delete(t)})),t}))}function X(e){var t,n=e.method.create(e.name,e.options);(t=n)&&"function"==typeof t.then?(e._preparePromises=n,n.then((function(t){e._state=t}))):e._state=n}function G(e){return e._addEventListeners.message.length>0||e._addEventListeners.internal.length>0}function V(e,t,n){e._addEventListeners[t].push(n),function(e){if(!e._isListening&&G(e)){var t=function(t){e._addEventListeners[t.type].forEach((function(e){t.time>=e.time&&e.fn(t.data)}))},n=e.method.microSeconds();e._preparePromises?e._preparePromises.then((function(){e._isListening=!0,e.method.onMessage(e._state,t,n)})):(e._isListening=!0,e.method.onMessage(e._state,t,n))}}(e)}function J(e,t,n){e._addEventListeners[t]=e._addEventListeners[t].filter((function(e){return e!==n})),function(e){if(e._isListening&&!G(e)){e._isListening=!1;var t=e.method.microSeconds();e.method.onMessage(e._state,null,t)}}(e)}var W=function(){function e(t,n){var r=this;o(this,e),this._channel=t,this._options=n,this.isLeader=!1,this.isDead=!1,this.token=L(),this._isApplying=!1,this._reApply=!1,this._unloadFns=[],this._listeners=[],this._intervals=[],this._duplicateListeners=function(){},this._duplicateCalled=!1,this._onBeforeDie=p(y.mark((function e(){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)})));var i=function(){var e=p(y.mark((function e(){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",r.die());case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();b&&(window.addEventListener("beforeUnload",i),window.addEventListener("unload",i),this._unloadFns.push(["beforeUnload",i]),this._unloadFns.push(["unload",i]))}var t;return s(e,[{key:"applyOnce",value:function(){var e=this;if(this.isLeader)return Promise.resolve(!1);if(this.isDead)return Promise.resolve(!1);if(this._isApplying)return this._reApply=!0,Promise.resolve(!1);this._isApplying=!0;var t=!1,n=function(n){"leader"===n.context&&n.token!==e.token&&("apply"===n.action&&n.token>e.token&&(t=!0),"tell"===n.action&&(t=!0))};return this._channel.addEventListener("internal",n),$(this,"apply").then((function(){return O(e._options.responseTime)})).then((function(){return t?Promise.reject(new Error):$(e,"apply")})).then((function(){return O(e._options.responseTime)})).then((function(){return t?Promise.reject(new Error):$(e)})).then((function(){return function(e){e.isLeader=!0;var t=function(t){"leader"===t.context&&"apply"===t.action&&$(e,"tell"),"leader"!==t.context||"tell"!==t.action||e._duplicateCalled||(e._duplicateCalled=!0,e._duplicateListeners(),$(e,"tell"))};return e._channel.addEventListener("internal",t),e._listeners.push(t),$(e,"tell")}(e)})).then((function(){return!0})).catch((function(){return!1})).then((function(t){return e._channel.removeEventListener("internal",n),e._isApplying=!1,!t&&e._reApply?(e._reApply=!1,e.applyOnce()):t}))}},{key:"awaitLeadership",value:function(){var e;return this._awaitLeadershipPromise||(this._awaitLeadershipPromise=(e=this).isLeader?Promise.resolve():new Promise((function(t){var n=!1;function r(){n||(n=!0,clearInterval(i),e._channel.removeEventListener("internal",o),t(!0))}e.applyOnce().then((function(){e.isLeader&&r()}));var i=setInterval((function(){e.applyOnce().then((function(){e.isLeader&&r()}))}),e._options.fallbackInterval);e._intervals.push(i);var o=function(t){"leader"===t.context&&"death"===t.action&&e.applyOnce().then((function(){e.isLeader&&r()}))};e._channel.addEventListener("internal",o),e._listeners.push(o)}))),this._awaitLeadershipPromise}},{key:"onDuplicate",get:function(){return this._duplicateListeners},set:function(e){this._duplicateListeners=e}},{key:"onBeforeDie",get:function(){return this._onBeforeDie},set:function(e){this._onBeforeDie=e}},{key:"die",value:(t=p(y.mark((function e(){var t=this;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isDead){e.next=2;break}return e.abrupt("return");case 2:return this.isDead=!0,e.next=5,this.onBeforeDie();case 5:return this._listeners.forEach((function(e){return t._channel.removeEventListener("internal",e)})),this._intervals.forEach((function(e){return clearInterval(e)})),this._unloadFns.forEach((function(e){b&&window.removeEventListener(e[0],e[1])})),e.abrupt("return",$(this,"death"));case 9:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();function $(e,t){var n={context:"leader",action:t,token:e.token};return e._channel.postInternal(n)}var q=function(e){var t=e.type,n=e.channelName,r=e.fallbackInterval,i=e.responseTime,o=e.emitOnAllTabs,a=e.callbacks,s=e.start,u=e.reset,c=e.pause,l=e.resume,h=new F(n,{type:t}),f=function(e,t){if(e._leaderElector)throw new Error("❌ MessageChannel already has a leader-elector");var n=new W(e,t);return e._beforeClose.push(p(y.mark((function e(){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.die());case 1:case"end":return e.stop()}}),e)})))),e._leaderElector=n,n}(h,{fallbackInterval:r,responseTime:i}),d={};d[f.token]=!1;var v=!1,g=!0,b=function(){return v};f.awaitLeadership().then((function(){v=!0})),h.addEventListener("message",(function(e){var t=m(e,2),n=t[0],r=t[1];switch(n){case"register":d[r]=!1;break;case"deregister":delete d[r];break;case"idle":w(r);break;case"active":_(r);break;case"emitIdle":a.onIdle();break;case"emitActive":a.onActive();break;case"start":s(!0);break;case"reset":u(!0);break;case"pause":c(!0);break;case"resume":l(!0)}}));var w=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f.token;d[e]=!0;var t=Object.values(d).every((function(e){return e}));!g&&t&&(g=!0,b()?(a.onIdle(),o&&T("emitIdle")):T("idle"))},_=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f.token;d[e]=!1;var t=Object.values(d).some((function(e){return!e}));g&&t&&(g=!1,b()?(a.onActive(),o&&T("emitActive")):T("active"))};f.onDuplicate=p(y.mark((function e(){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,f.die();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)}))),f.onBeforeDie=p(y.mark((function e(){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,T("deregister");case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));var T=function(){var e=p(y.mark((function e(t){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",h.postMessage([t,f.token]));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),k=function(){var e=p(y.mark((function e(){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,f.die();case 2:return e.next=4,h.close();case 4:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();return T("register"),{close:k,send:T,isLeader:b,idle:w,active:_,isAllIdle:function(){return g},setAllIdle:function(e){g=e}}};function z(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=f(e);if(t){var i=f(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return h(this,n)}}var H=function(t){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}(r,e);var n=z(r);function r(e){var t;if(o(this,r),(t=n.call(this,e)).state={idle:!1,oldDate:+new Date,lastActive:+new Date,lastIdle:null,idleTime:0,remaining:null,pageX:null,pageY:null},t.tId=null,t.eventsBound=!1,t.callbackRefs={},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0?t._onAction=T(e.onAction,e.debounce):e.throttle>0?t._onAction=k(e.onAction,e.throttle):t._onAction=e.onAction,e.eventsThrottle>0?t.handleEvent=k(t._handleEvent.bind(u(t)),e.eventsThrottle):t.handleEvent=t._handleEvent.bind(u(t)),e.startOnMount&&!e.startManually||(t.state.idle=!0),t._toggleIdleState=t._toggleIdleState.bind(u(t)),t.start=t.start.bind(u(t)),t.reset=t.reset.bind(u(t)),t.pause=t.pause.bind(u(t)),t.resume=t.resume.bind(u(t)),t.isIdle=t.isIdle.bind(u(t)),t.getRemainingTime=t.getRemainingTime.bind(u(t)),t.getElapsedTime=t.getElapsedTime.bind(u(t)),t.getLastActiveTime=t.getLastActiveTime.bind(u(t)),t.getLastIdleTime=t.getLastIdleTime.bind(u(t)),t.getTotalIdleTime=t.getTotalIdleTime.bind(u(t)),t.getTotalActiveTime=t.getTotalActiveTime.bind(u(t)),t}return s(r,[{key:"componentDidMount",value:function(){var e=this.props,t=e.startOnMount,n=e.startManually;this._setupTabManager(),n||(t?this.start():this._bindEvents())}},{key:"componentDidUpdate",value:function(e){e.debounce!==this.props.debounce&&this.props.debounce>0?(this._onAction.cancel&&this._onAction.cancel(),this._onAction=T(this.props.onAction,this.props.debounce)):e.throttle!==this.props.throttle&&this.props.throttle>0?(this._onAction.cancel&&this._onAction.cancel(),this._onAction=k(this.props.onAction,this.props.throttle)):(e.throttle&&0===this.props.throttle||e.debounce&&0===this.props.debounce)&&(this._onAction.cancel&&this._onAction.cancel(),this._onAction=this.props.onAction),e.eventsThrottle!==this.props.eventsThrottle&&(this._unbindEvents(),this.handleEvent=k(this._handleEvent.bind(this),this.props.eventsThrottle),this._bindEvents()),e.timeout!==this.props.timeout&&this.state.idle&&this.reset(),e.onActive!==this.props.onActive&&(this.callbackRefs.onActive=this.props.onActive),e.onIdle!==this.props.onIdle&&(this.callbackRefs.onIdle=this.props.onIdle)}},{key:"componentWillUnmount",value:function(){clearTimeout(this.tId),this._unbindEvents(!0),this._onAction.cancel&&this._onAction.cancel(),this.manager&&this.manager.close().catch(console.error)}},{key:"render",value:function(){return this.props.children||null}},{key:"_setupTabManager",value:function(){var e=this.props,t=e.crossTab,n=e.onIdle,r=e.onActive;if(this.callbackRefs={onIdle:n,onActive:r},t){var i=Object.assign({channelName:"idle-timer",fallbackInterval:2e3,responseTime:100,removeTimeout:6e4,emitOnAllTabs:!1},!0===t?{}:t),o=i.type,a=i.channelName,s=i.fallbackInterval,u=i.responseTime,c=i.emitOnAllTabs;this.manager=q({type:o,channelName:a,fallbackInterval:s,responseTime:u,emitOnAllTabs:c,callbacks:this.callbackRefs,start:this.start,reset:this.reset,pause:this.pause,resume:this.resume})}}},{key:"_bindEvents",value:function(){var e=this;if(b){var t=this.props,n=t.element,r=t.events,i=t.passive,o=t.capture;this.eventsBound||(r.forEach((function(t){n.addEventListener(t,e.handleEvent,{capture:o,passive:i})})),this.eventsBound=!0)}}},{key:"_unbindEvents",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(b){var n=this.props,r=n.element,i=n.events,o=n.passive,a=n.capture;(this.eventsBound||t)&&(i.forEach((function(t){r.removeEventListener(t,e.handleEvent,{capture:a,passive:o})})),this.eventsBound=!1)}}},{key:"_toggleIdleState",value:function(e){var t=this;this.setState((function(e){return{idle:!e.idle,lastIdle:e.idle?e.lastIdle:+new Date-t.props.timeout,idleTime:e.idle?e.idleTime+ +new Date-e.lastIdle:e.idleTime}}),(function(){var n=t.props,r=n.onActive,i=n.onIdle,o=n.stopOnIdle;t.state.idle?(o&&(clearTimeout(t.tId),t.tId=null,t._unbindEvents()),t.manager?t.manager.idle():i(e)):(t._bindEvents(),t.manager?t.manager.active():r(e))}))}},{key:"_handleEvent",value:function(e){var t=this.state,n=t.remaining,r=t.pageX,i=t.pageY,o=t.idle,a=this.props,s=a.timeout,u=a.stopOnIdle;if(this._onAction(e),!n){if("mousemove"===e.type){if(e.pageX===r&&e.pageY===i)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(this.getElapsedTime()<200)return}clearTimeout(this.tId),this.tId=null;var c=+new Date-this.getLastActiveTime();(o&&!u||!o&&c>s)&&this._toggleIdleState(e),this.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),o&&u||(this.tId=setTimeout(this._toggleIdleState,s))}}},{key:"start",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.setState({idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null}),this.manager&&(this.manager.setAllIdle(!1),!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("start"));var t=this.props.timeout;this.tId=setTimeout(this._toggleIdleState,t)}},{key:"reset",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.state.idle&&this.props.onActive(),this.manager&&(this.manager.setAllIdle(!1),!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("reset")),this.setState({idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null});var t=this.props.timeout;this.tId=setTimeout(this._toggleIdleState,t)}},{key:"pause",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.state.remaining;null===t&&(this._unbindEvents(),clearTimeout(this.tId),this.tId=null,this.manager&&!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("pause"),this.setState({remaining:this.getRemainingTime()}))}},{key:"resume",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.state,n=t.remaining,r=t.idle;null!==n&&(this._bindEvents(),this.manager&&!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("resume"),r||(this.tId=setTimeout(this._toggleIdleState,n),this.setState({remaining:null,lastActive:+new Date})))}},{key:"getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.lastActive,r=this.props.timeout;if(null!==t)return t<0?0:t;var i=r-(+new Date-n);return i<0?0:i}},{key:"getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"getLastIdleTime",value:function(){return this.state.lastIdle}},{key:"getTotalIdleTime",value:function(){var e=this.state,t=e.idle,n=e.lastIdle,r=e.idleTime;return t?+new Date-n+r:r}},{key:"getLastActiveTime",value:function(){return this.state.lastActive}},{key:"getTotalActiveTime",value:function(){return this.getElapsedTime()-this.getTotalIdleTime()}},{key:"isIdle",value:function(){return this.state.idle}},{key:"isLeader",value:function(){return!this.manager||this.manager.isLeader()}}]),r}();function K(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=e.timeout,o=void 0===i?12e5:i,a=e.element,s=void 0===a?w:a,u=e.events,c=void 0===u?_:u,l=e.onIdle,h=void 0===l?function(){}:l,f=e.onActive,d=void 0===f?function(){}:f,v=e.onAction,m=void 0===v?function(){}:v,g=e.debounce,A=void 0===g?0:g,E=e.throttle,I=void 0===E?0:E,L=e.eventsThrottle,O=void 0===L?200:L,x=e.startOnMount,S=void 0===x||x,M=e.startManually,D=void 0!==M&&M,P=e.stopOnIdle,j=void 0!==P&&P,C=e.capture,N=void 0===C||C,R=e.passive,B=void 0===R||R,Y=e.crossTab,F=void 0!==Y&&Y,U=t(!1),X=t(!0),G=t(+new Date),V=t(null),J=t(null),W=t(null),$=t(null),z=t(null),H=t(null),K=t(0),Q=t(!0),Z=t(o),ee=t(null);F&&(!0===F&&(F={}),F=Object.assign({channelName:"idle-timer",fallbackInterval:2e3,responseTime:100,removeTimeout:6e4,emitOnAllTabs:!1},F));var te=t(h),ne=t(d),re=t(m);n((function(){te.current=h}),[h]),n((function(){ne.current=d}),[d]),n((function(){re.current=m}),[m]);var ie=r((function(){function e(e){re.current(e)}return e.cancel&&e.cancel(),A>0?T(e,A):I>0?k(e,I):e}),[I,A]),oe=function(e){var t=!X.current;X.current=t,t?(j&&(clearTimeout($.current),$.current=null,ce()),H.current=+new Date-Z.current,ee.current?ee.current.idle():te.current(e)):(K.current+=+new Date-H.current,ue(),ee.current?ee.current.active():ne.current(e))},ae=function(e){if(ie(e),!V.current){if("mousemove"===e.type){if(e.pageX===J&&e.pageY===W)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(he()<200)return}clearTimeout($.current),$.current=null;var t=+new Date-pe();(X.current&&!j||!X.current&&t>Z.current)&&oe(e),z.current=+new Date,J.current=e.pageX,W.current=e.pageY,X.current||($.current=setTimeout(oe,Z.current))}},se=t(ae),ue=function(){b&&(U.current||(c.forEach((function(e){s.addEventListener(e,se.current,{capture:N,passive:B})})),U.current=!0))},ce=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];b&&(U.current||e)&&(c.forEach((function(e){s.removeEventListener(e,se.current,{capture:N,passive:B})})),U.current=!1)},le=function(){if(null!==V.current)return V.current<0?0:V.current;var e=Z.current-(+new Date-z.current);return e<0?0:e},he=function(){return+new Date-G.current},fe=function(){return H.current},de=function(){return X.current?+new Date-H.current+K.current:K.current},pe=function(){return z.current},ve=function(){return he()-de()},me=function(){return X.current},ge=function(){return!ee.current||ee.current.isLeader()},ye=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout($.current),$.current=null,ue(),X.current=!1,G.current=+new Date,z.current=+new Date,V.current=null,ee.current&&(ee.current.setAllIdle(!1),!e&&F.emitOnAllTabs&&ee.current.send("start")),$.current=setTimeout(oe,Z.current)},be=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout($.current),$.current=null,ue(),X.current&&ne.current(),X.current=!1,G.current=+new Date,z.current=+new Date,V.current=null,ee.current&&(ee.current.setAllIdle(!1),!e&&F.emitOnAllTabs&&ee.current.send("reset")),$.current=setTimeout(oe,Z.current)},we=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];null===V.current&&(ce(),clearTimeout($.current),$.current=null,V.current=le(),ee.current&&!e&&F.emitOnAllTabs&&ee.current.send("pause"))},_e=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];null!==V.current&&(ue(),X.current||($.current=setTimeout(oe,V.current),V.current=null,z.current=+new Date),ee.current&&!e&&F.emitOnAllTabs&&ee.current.send("resume"))};return n((function(){if(A>0&&I>0)throw new Error("onAction can either be throttled or debounced (not both)");return F&&(ee.current=q({type:F.type,channelName:F.channelName,fallbackInterval:F.fallbackInterval,responseTime:F.responseTime,emitOnAllTabs:F.emitOnAllTabs,callbacks:{onIdle:te.current,onActive:ne.current},start:ye,reset:be,pause:we,resume:_e})),D?p(y.mark((function e(){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(clearTimeout($.current),ce(!0),!F){e.next=5;break}return e.next=5,ee.current.close();case 5:case"end":return e.stop()}}),e)}))):(S?ye():ue(),p(y.mark((function e(){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(clearTimeout($.current),ce(!0),ie.cancel&&ie.cancel(),!F){e.next=6;break}return e.next=6,ee.current.close();case 6:case"end":return e.stop()}}),e)}))))}),[]),n((function(){var e=U.current;e&&ce(),se.current=O>0?k(ae,O):ae,e&&ue()}),[O]),n((function(){Z.current=o,!Q.current&&X.current&&be(),Q.current=!1}),[o]),{isIdle:me,isLeader:ge,start:ye,pause:we,reset:be,resume:_e,getLastIdleTime:fe,getTotalIdleTime:de,getLastActiveTime:pe,getTotalActiveTime:ve,getElapsedTime:he,getRemainingTime:le}}H.propTypes={timeout:i.number,events:i.arrayOf(i.string),onIdle:i.func,onActive:i.func,onAction:i.func,debounce:i.number,throttle:i.number,eventsThrottle:i.number,element:i.oneOfType([i.object,i.element]),startOnMount:i.bool,startManually:i.bool,stopOnIdle:i.bool,passive:i.bool,capture:i.bool,crossTab:i.oneOfType([i.bool,i.shape({type:i.oneOf(["broadcastChannel","localStorage","simulate"]),channelName:i.string,fallbackInterval:i.number,responseTime:i.number,removeTimeout:i.number,emitOnAllTabs:i.bool})])},H.defaultProps={timeout:12e5,element:w,events:_,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,eventsThrottle:200,startOnMount:!0,startManually:!1,stopOnIdle:!1,capture:!0,passive:!0,crossTab:!1},K.propTypes={timeout:i.number,events:i.arrayOf(i.string),onIdle:i.func,onActive:i.func,onAction:i.func,debounce:i.number,throttle:i.number,eventsThrottle:i.number,element:i.oneOfType([i.object,i.element]),startOnMount:i.bool,startManually:i.bool,stopOnIdle:i.bool,passive:i.bool,capture:i.bool,crossTab:i.oneOfType([i.bool,i.shape({type:i.oneOf(["broadcastChannel","localStorage","simulate"]),channelName:i.string,fallbackInterval:i.number,responseTime:i.number,removeTimeout:i.number,emitOnAllTabs:i.bool})])},K.defaultProps={timeout:12e5,element:w,events:_,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,eventsThrottle:200,startOnMount:!0,startManually:!1,stopOnIdle:!1,capture:!0,passive:!0,crossTab:!1};export default H;export{K as useIdleTimer}; | ||
import{Component as e,useRef as t,useEffect as n,useMemo as r}from"react";import i from"prop-types";function o(e){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t,n,r,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void n(e)}s.done?t(u):Promise.resolve(u).then(r,i)}function s(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var o=e.apply(t,n);function s(e){a(o,r,i,s,u,"next",e)}function u(e){a(o,r,i,s,u,"throw",e)}s(void 0)}))}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function l(e,t,n){return t&&c(e.prototype,t),n&&c(e,n),e}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function h(e,t){return(h=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function f(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function m(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?f(e):t}function p(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=d(e);if(t){var i=d(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return m(this,n)}}function v(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==n)return;var r,i,o=[],a=!0,s=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==n.return||n.return()}finally{if(s)throw i}}return o}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return g(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return g(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var b="object"===("undefined"==typeof window||"undefined"==typeof window?"undefined":o(window)),y=b?document:{},T=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange"];function _(e,t){var n;function r(){for(var r=arguments.length,i=new Array(r),o=0;o<r;o++)i[o]=arguments[o];n&&clearTimeout(n),n=setTimeout((function(){e.apply(void 0,i),n=null}),t)}return r.cancel=function(){clearTimeout(n)},r}function w(e,t){var n=0;return function(){var r=(new Date).getTime();if(!(r-n<t))return n=r,e.apply(void 0,arguments)}}var k=0,A=0;function I(){var e=(new Date).getTime();return e===k?1e3*e+ ++A:(k=e,A=0,1e3*e)}function E(){return Math.random().toString(36).substring(2)}function L(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return new Promise((function(t){return setTimeout(t,e)}))}function O(){return(new Date).getTime()}var M={create:function(e){var t={messagesCallback:null,bc:new BroadcastChannel(e)};return t.bc.onmessage=function(e){t.messagesCallback&&t.messagesCallback(e.data)},t},close:function(e){e.bc.close()},onMessage:function(e,t){e.messagesCallback=t},postMessage:function(e,t){try{return e.bc.postMessage(t,!1),Promise.resolve()}catch(e){return Promise.reject(e)}},canBeUsed:function(){return"function"==typeof BroadcastChannel},type:"broadcastChannel",averageResponseTime:function(){return 150},microSeconds:I},S=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:6e4;u(this,e),this.ttl=t,this.set=new Set,this.timeMap=new Map}return l(e,[{key:"has",value:function(e){return this.set.has(e)}},{key:"add",value:function(e){this.timeMap.set(e,O()),this.set.add(e),this._removeTooOldValues()}},{key:"clear",value:function(){this.set.clear(),this.timeMap.clear()}},{key:"_removeTooOldValues",value:function(){for(var e=O()-this.ttl,t=this.set[Symbol.iterator]();;){var n=t.next().value;if(!n)return;if(!(this.timeMap.get(n)<e))return;this.timeMap.delete(n),this.set.delete(n)}}}]),e}();function D(){var e;if("undefined"==typeof window)return null;try{e=window.localStorage,e=window["ie8-eventlistener/storage"]||window.localStorage}catch(e){}return e}function P(e,t){var n=e,r=function(e){e.key===n&&t(JSON.parse(e.newValue))};return window.addEventListener("storage",r),r}function R(){var e=D();if(!e)return!1;try{var t="__check";e.setItem(t,"works"),e.removeItem(t)}catch(e){return!1}return!0}var x={create:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!R())throw new Error("❌ localStorage cannot be used.");var n=E(),r=new S(t.removeTimeout),i={channelName:e,uuid:n,eMIs:r};return i.listener=P(e,(function(e){i.messagesCallback&&e.uuid!==n&&e.token&&!r.has(e.token)&&(e.data.time&&e.data.time<i.messagesCallbackTime||(r.add(e.token),i.messagesCallback(e.data)))})),i},close:function(e){var t;t=e.listener,window.removeEventListener("storage",t)},onMessage:function(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t},postMessage:function(e,t){return new Promise((function(n){var r=e.channelName,i={token:E(),time:(new Date).getTime(),data:t,uuid:e.uuid},o=JSON.stringify(i);D().setItem(r,o);var a=document.createEvent("Event");a.initEvent("storage",!0,!0),a.key=r,a.newValue=o,window.dispatchEvent(a),n()}))},canBeUsed:R,type:"localStorage",averageResponseTime:function(){var e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?240:120},microSeconds:I},C=new Set;var j={create:function(e){var t={name:e,messagesCallback:null};return C.add(t),t},close:function(e){C.delete(e)},onMessage:function(e,t){e.messagesCallback=t},postMessage:function(e,t){return new Promise((function(n){return setTimeout((function(){Array.from(C).filter((function(t){return t.name===e.name})).filter((function(t){return t!==e})).filter((function(e){return!!e.messagesCallback})).forEach((function(e){return e.messagesCallback(t)})),n()}),5)}))},canBeUsed:function(){return!0},type:"simulate",averageResponseTime:function(){return 5},microSeconds:I},B=[M,x];function N(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.type){if("simulate"===e.type)return j;var t=B.find((function(t){return t.type===e.type}));if(t)return t;throw new Error("❌ Method ".concat(e.type," is not supported."))}var n=B.find((function(e){return e.canBeUsed()}));if(!n)throw new Error("❌ No method found ".concat(JSON.stringify(B.map((function(e){return e.type})))));return n}var U=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};u(this,e),this.name=t,this.options=n,this.method=N(this.options),this.closed=!1,this._isListening=!1,this._onMessageListener=null,this._addEventListeners={message:[],internal:[]},this._unSendMessagePromises=new Set,this._beforeClose=[],this._preparePromises=null,Y(this)}return l(e,[{key:"postMessage",value:function(e){if(this.closed)throw new Error("❌ Cannot post message after channel has closed");return X(this,"message",e)}},{key:"postInternal",value:function(e){return X(this,"internal",e)}},{key:"onmessage",get:function(){return this._onMessageListener},set:function(e){var t={time:this.method.microSeconds(),fn:e};J(this,"message",this._onMessageListener),e&&"function"==typeof e?(this._onMessageListener=t,V(this,"message",t)):this._onMessageListener=null}},{key:"addEventListener",value:function(e,t){V(this,e,{time:this.method.microSeconds(),fn:t})}},{key:"removeEventListener",value:function(e,t){J(this,e,this._addEventListeners[e].find((function(e){return e.fn===t})))}},{key:"close",value:function(){var e=this;if(!this.closed){this.closed=!0;var t=this._preparePromises?this._preparePromises:Promise.resolve();return this._onMessageListener=null,this._addEventListeners.message=[],t.then((function(){return Promise.all(Array.from(e._unSendMessagePromises))})).then((function(){return Promise.all(e._beforeClose.map((function(e){return e()})))})).then((function(){return e.method.close(e._state)}))}}},{key:"type",get:function(){return this.method.type}},{key:"isClosed",value:function(){return this.closed}}]),e}();function X(e,t,n){var r={time:e.method.microSeconds(),type:t,data:n};return(e._preparePromises?e._preparePromises:Promise.resolve()).then((function(){var t=e.method.postMessage(e._state,r);return e._unSendMessagePromises.add(t),t.catch().then((function(){return e._unSendMessagePromises.delete(t)})),t}))}function Y(e){var t,n=e.method.create(e.name,e.options);(t=n)&&"function"==typeof t.then?(e._preparePromises=n,n.then((function(t){e._state=t}))):e._state=n}function F(e){return e._addEventListeners.message.length>0||e._addEventListeners.internal.length>0}function V(e,t,n){e._addEventListeners[t].push(n),function(e){if(!e._isListening&&F(e)){var t=function(t){e._addEventListeners[t.type].forEach((function(e){t.time>=e.time&&e.fn(t.data)}))},n=e.method.microSeconds();e._preparePromises?e._preparePromises.then((function(){e._isListening=!0,e.method.onMessage(e._state,t,n)})):(e._isListening=!0,e.method.onMessage(e._state,t,n))}}(e)}function J(e,t,n){e._addEventListeners[t]=e._addEventListeners[t].filter((function(e){return e!==n})),function(e){if(e._isListening&&!F(e)){e._isListening=!1;var t=e.method.microSeconds();e.method.onMessage(e._state,null,t)}}(e)}var W=function(){function e(t,n){var r=this;u(this,e),this._channel=t,this._options=n,this.isLeader=!1,this.isDead=!1,this.token=E(),this._isApplying=!1,this._reApply=!1,this._unloadFns=[],this._listeners=[],this._intervals=[],this._duplicateListeners=function(){},this._duplicateCalled=!1,this._onBeforeDie=s(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)})));var i=function(){var e=s(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",r.die());case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();b&&(window.addEventListener("beforeUnload",i),window.addEventListener("unload",i),this._unloadFns.push(["beforeUnload",i]),this._unloadFns.push(["unload",i]))}var t;return l(e,[{key:"applyOnce",value:function(){var e=this;if(this.isLeader)return Promise.resolve(!1);if(this.isDead)return Promise.resolve(!1);if(this._isApplying)return this._reApply=!0,Promise.resolve(!1);this._isApplying=!0;var t=!1,n=function(n){"leader"===n.context&&n.token!==e.token&&("apply"===n.action&&n.token>e.token&&(t=!0),"tell"===n.action&&(t=!0))};return this._channel.addEventListener("internal",n),$(this,"apply").then((function(){return L(e._options.responseTime)})).then((function(){return t?Promise.reject(new Error):$(e,"apply")})).then((function(){return L(e._options.responseTime)})).then((function(){return t?Promise.reject(new Error):$(e)})).then((function(){return function(e){e.isLeader=!0;var t=function(t){"leader"===t.context&&"apply"===t.action&&$(e,"tell"),"leader"!==t.context||"tell"!==t.action||e._duplicateCalled||(e._duplicateCalled=!0,e._duplicateListeners(),$(e,"tell"))};return e._channel.addEventListener("internal",t),e._listeners.push(t),$(e,"tell")}(e)})).then((function(){return!0})).catch((function(){return!1})).then((function(t){return e._channel.removeEventListener("internal",n),e._isApplying=!1,!t&&e._reApply?(e._reApply=!1,e.applyOnce()):t}))}},{key:"awaitLeadership",value:function(){var e;return this._awaitLeadershipPromise||(this._awaitLeadershipPromise=(e=this).isLeader?Promise.resolve():new Promise((function(t){var n=!1;function r(){n||(n=!0,clearInterval(i),e._channel.removeEventListener("internal",o),t(!0))}e.applyOnce().then((function(){e.isLeader&&r()}));var i=setInterval((function(){e.applyOnce().then((function(){e.isLeader&&r()}))}),e._options.fallbackInterval);e._intervals.push(i);var o=function(t){"leader"===t.context&&"death"===t.action&&e.applyOnce().then((function(){e.isLeader&&r()}))};e._channel.addEventListener("internal",o),e._listeners.push(o)}))),this._awaitLeadershipPromise}},{key:"onDuplicate",get:function(){return this._duplicateListeners},set:function(e){this._duplicateListeners=e}},{key:"onBeforeDie",get:function(){return this._onBeforeDie},set:function(e){this._onBeforeDie=e}},{key:"die",value:(t=s(regeneratorRuntime.mark((function e(){var t=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isDead){e.next=2;break}return e.abrupt("return");case 2:return this.isDead=!0,e.next=5,this.onBeforeDie();case 5:return this._listeners.forEach((function(e){return t._channel.removeEventListener("internal",e)})),this._intervals.forEach((function(e){return clearInterval(e)})),this._unloadFns.forEach((function(e){b&&window.removeEventListener(e[0],e[1])})),e.abrupt("return",$(this,"death"));case 9:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();function $(e,t){var n={context:"leader",action:t,token:e.token};return e._channel.postInternal(n)}var q=function(e){var t=e.type,n=e.channelName,r=e.fallbackInterval,i=e.responseTime,o=e.emitOnAllTabs,a=e.callbacks,u=e.start,c=e.reset,l=e.pause,d=e.resume,h=new U(n,{type:t}),f=function(e,t){if(e._leaderElector)throw new Error("❌ MessageChannel already has a leader-elector");var n=new W(e,t);return e._beforeClose.push(s(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.die());case 1:case"end":return e.stop()}}),e)})))),e._leaderElector=n,n}(h,{fallbackInterval:r,responseTime:i}),m={};m[f.token]=!1;var p=!1,g=!0,b=function(){return p};f.awaitLeadership().then((function(){p=!0})),h.addEventListener("message",(function(e){var t=v(e,2),n=t[0],r=t[1];switch(n){case"register":m[r]=!1;break;case"deregister":delete m[r];break;case"idle":y(r);break;case"active":T(r);break;case"emitIdle":a.onIdle();break;case"emitActive":a.onActive();break;case"start":u(!0);break;case"reset":c(!0);break;case"pause":l(!0);break;case"resume":d(!0)}}));var y=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f.token;m[e]=!0;var t=Object.values(m).every((function(e){return e}));!g&&t&&(g=!0,b()?(a.onIdle(),o&&_("emitIdle")):_("idle"))},T=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f.token;m[e]=!1;var t=Object.values(m).some((function(e){return!e}));g&&t&&(g=!1,b()?(a.onActive(),o&&_("emitActive")):_("active"))};f.onDuplicate=s(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,f.die();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)}))),f.onBeforeDie=s(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_("deregister");case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));var _=function(){var e=s(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",h.postMessage([t,f.token]));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),w=function(){var e=s(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,f.die();case 2:return e.next=4,h.close();case 4:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();return _("register"),{close:w,send:_,isLeader:b,idle:y,active:T,isAllIdle:function(){return g},setAllIdle:function(e){g=e}}},z=function(t){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&h(e,t)}(r,e);var n=p(r);function r(e){var t;if(u(this,r),(t=n.call(this,e)).state={idle:!1,oldDate:+new Date,lastActive:+new Date,lastIdle:null,idleTime:0,remaining:null,pageX:null,pageY:null},t.tId=null,t.eventsBound=!1,t.callbackRefs={},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0?t._onAction=_(e.onAction,e.debounce):e.throttle>0?t._onAction=w(e.onAction,e.throttle):t._onAction=e.onAction,e.eventsThrottle>0?t.handleEvent=w(t._handleEvent.bind(f(t)),e.eventsThrottle):t.handleEvent=t._handleEvent.bind(f(t)),e.startOnMount&&!e.startManually||(t.state.idle=!0),t._toggleIdleState=t._toggleIdleState.bind(f(t)),t.start=t.start.bind(f(t)),t.reset=t.reset.bind(f(t)),t.pause=t.pause.bind(f(t)),t.resume=t.resume.bind(f(t)),t.isIdle=t.isIdle.bind(f(t)),t.getRemainingTime=t.getRemainingTime.bind(f(t)),t.getElapsedTime=t.getElapsedTime.bind(f(t)),t.getLastActiveTime=t.getLastActiveTime.bind(f(t)),t.getLastIdleTime=t.getLastIdleTime.bind(f(t)),t.getTotalIdleTime=t.getTotalIdleTime.bind(f(t)),t.getTotalActiveTime=t.getTotalActiveTime.bind(f(t)),t}return l(r,[{key:"componentDidMount",value:function(){var e=this.props,t=e.startOnMount,n=e.startManually;this._setupTabManager(),n||(t?this.start():this._bindEvents())}},{key:"componentDidUpdate",value:function(e){e.debounce!==this.props.debounce&&this.props.debounce>0?(this._onAction.cancel&&this._onAction.cancel(),this._onAction=_(this.props.onAction,this.props.debounce)):e.throttle!==this.props.throttle&&this.props.throttle>0?(this._onAction.cancel&&this._onAction.cancel(),this._onAction=w(this.props.onAction,this.props.throttle)):(e.throttle&&0===this.props.throttle||e.debounce&&0===this.props.debounce)&&(this._onAction.cancel&&this._onAction.cancel(),this._onAction=this.props.onAction),e.eventsThrottle!==this.props.eventsThrottle&&(this._unbindEvents(),this.handleEvent=w(this._handleEvent.bind(this),this.props.eventsThrottle),this._bindEvents()),e.timeout!==this.props.timeout&&this.state.idle&&this.reset(),e.onActive!==this.props.onActive&&(this.callbackRefs.onActive=this.props.onActive),e.onIdle!==this.props.onIdle&&(this.callbackRefs.onIdle=this.props.onIdle)}},{key:"componentWillUnmount",value:function(){clearTimeout(this.tId),this._unbindEvents(!0),this._onAction.cancel&&this._onAction.cancel(),this.manager&&this.manager.close().catch(console.error)}},{key:"render",value:function(){return this.props.children||null}},{key:"_setupTabManager",value:function(){var e=this.props,t=e.crossTab,n=e.onIdle,r=e.onActive;if(this.callbackRefs={onIdle:n,onActive:r},t){var i=Object.assign({channelName:"idle-timer",fallbackInterval:2e3,responseTime:100,removeTimeout:6e4,emitOnAllTabs:!1},!0===t?{}:t),o=i.type,a=i.channelName,s=i.fallbackInterval,u=i.responseTime,c=i.emitOnAllTabs;this.manager=q({type:o,channelName:a,fallbackInterval:s,responseTime:u,emitOnAllTabs:c,callbacks:this.callbackRefs,start:this.start,reset:this.reset,pause:this.pause,resume:this.resume})}}},{key:"_bindEvents",value:function(){var e=this;if(b){var t=this.props,n=t.element,r=t.events,i=t.passive,o=t.capture;this.eventsBound||(r.forEach((function(t){n.addEventListener(t,e.handleEvent,{capture:o,passive:i})})),this.eventsBound=!0)}}},{key:"_unbindEvents",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(b){var n=this.props,r=n.element,i=n.events,o=n.passive,a=n.capture;(this.eventsBound||t)&&(i.forEach((function(t){r.removeEventListener(t,e.handleEvent,{capture:a,passive:o})})),this.eventsBound=!1)}}},{key:"_toggleIdleState",value:function(e){var t=this;this.setState((function(e){return{idle:!e.idle,lastIdle:e.idle?e.lastIdle:+new Date-t.props.timeout,idleTime:e.idle?e.idleTime+ +new Date-e.lastIdle:e.idleTime}}),(function(){var n=t.props,r=n.onActive,i=n.onIdle,o=n.stopOnIdle;t.state.idle?(o&&(clearTimeout(t.tId),t.tId=null,t._unbindEvents()),t.manager?t.manager.idle():i(e)):(t._bindEvents(),t.manager?t.manager.active():r(e))}))}},{key:"_handleEvent",value:function(e){var t=this.state,n=t.remaining,r=t.pageX,i=t.pageY,o=t.idle,a=this.props,s=a.timeout,u=a.stopOnIdle;if(this._onAction(e),!n){if("mousemove"===e.type){if(e.pageX===r&&e.pageY===i)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(this.getElapsedTime()<200)return}clearTimeout(this.tId),this.tId=null;var c=+new Date-this.getLastActiveTime();(o&&!u||!o&&c>s)&&this._toggleIdleState(e),this.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),o&&u||(this.tId=setTimeout(this._toggleIdleState,s))}}},{key:"start",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.setState({idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null}),this.manager&&(this.manager.setAllIdle(!1),!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("start"));var t=this.props.timeout;this.tId=setTimeout(this._toggleIdleState,t)}},{key:"reset",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.state.idle&&this.props.onActive(),this.manager&&(this.state.idle&&this.manager.current.active(),this.manager.setAllIdle(!1),!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("reset")),this.setState({idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null});var t=this.props.timeout;this.tId=setTimeout(this._toggleIdleState,t)}},{key:"pause",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.state.remaining;null===t&&(this._unbindEvents(),clearTimeout(this.tId),this.tId=null,this.manager&&!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("pause"),this.setState({remaining:this.getRemainingTime()}))}},{key:"resume",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.state,n=t.remaining,r=t.idle;null!==n&&(this._bindEvents(),this.manager&&!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("resume"),r||(this.tId=setTimeout(this._toggleIdleState,n),this.setState({remaining:null,lastActive:+new Date})))}},{key:"getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.lastActive,r=this.props.timeout;if(null!==t)return t<0?0:t;var i=r-(+new Date-n);return i<0?0:i}},{key:"getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"getLastIdleTime",value:function(){return this.state.lastIdle}},{key:"getTotalIdleTime",value:function(){var e=this.state,t=e.idle,n=e.lastIdle,r=e.idleTime;return t?+new Date-n+r:r}},{key:"getLastActiveTime",value:function(){return this.state.lastActive}},{key:"getTotalActiveTime",value:function(){return this.getElapsedTime()-this.getTotalIdleTime()}},{key:"isIdle",value:function(){return this.state.idle}},{key:"isLeader",value:function(){return!this.manager||this.manager.isLeader()}}]),r}();function G(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=e.timeout,o=void 0===i?12e5:i,a=e.element,u=void 0===a?y:a,c=e.events,l=void 0===c?T:c,d=e.onIdle,h=void 0===d?function(){}:d,f=e.onActive,m=void 0===f?function(){}:f,p=e.onAction,v=void 0===p?function(){}:p,g=e.debounce,k=void 0===g?0:g,A=e.throttle,I=void 0===A?0:A,E=e.eventsThrottle,L=void 0===E?200:E,O=e.startOnMount,M=void 0===O||O,S=e.startManually,D=void 0!==S&&S,P=e.stopOnIdle,R=void 0!==P&&P,x=e.capture,C=void 0===x||x,j=e.passive,B=void 0===j||j,N=e.crossTab,U=void 0!==N&&N,X=t(!1),Y=t(!0),F=t(+new Date),V=t(null),J=t(null),W=t(null),$=t(null),z=t(null),G=t(null),H=t(0),K=t(!0),Q=t(o),Z=t(null);U&&(!0===U&&(U={}),U=Object.assign({channelName:"idle-timer",fallbackInterval:2e3,responseTime:100,removeTimeout:6e4,emitOnAllTabs:!1},U));var ee=t(h),te=t(m),ne=t(v);n((function(){ee.current=h}),[h]),n((function(){te.current=m}),[m]),n((function(){ne.current=v}),[v]);var re=r((function(){function e(e){ne.current(e)}return e.cancel&&e.cancel(),k>0?_(e,k):I>0?w(e,I):e}),[I,k]),ie=function(e){var t=!Y.current;Y.current=t,t?(R&&(clearTimeout($.current),$.current=null,ue()),G.current=+new Date-Q.current,Z.current?Z.current.idle():ee.current(e)):(H.current+=+new Date-G.current,se(),Z.current?Z.current.active():te.current(e))},oe=function(e){if(re(e),!V.current){if("mousemove"===e.type){if(e.pageX===J&&e.pageY===W)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(le()<200)return}clearTimeout($.current),$.current=null;var t=+new Date-fe();(Y.current&&!R||!Y.current&&t>Q.current)&&ie(e),z.current=+new Date,J.current=e.pageX,W.current=e.pageY,Y.current||($.current=setTimeout(ie,Q.current))}},ae=t(oe),se=function(){b&&(X.current||(l.forEach((function(e){u.addEventListener(e,ae.current,{capture:C,passive:B})})),X.current=!0))},ue=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];b&&(X.current||e)&&(l.forEach((function(e){u.removeEventListener(e,ae.current,{capture:C,passive:B})})),X.current=!1)},ce=function(){if(null!==V.current)return V.current<0?0:V.current;var e=Q.current-(+new Date-z.current);return e<0?0:e},le=function(){return+new Date-F.current},de=function(){return G.current},he=function(){return Y.current?+new Date-G.current+H.current:H.current},fe=function(){return z.current},me=function(){return le()-he()},pe=function(){return Y.current},ve=function(){return!Z.current||Z.current.isLeader()},ge=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout($.current),$.current=null,se(),Y.current=!1,F.current=+new Date,z.current=+new Date,V.current=null,Z.current&&(Z.current.setAllIdle(!1),!e&&U.emitOnAllTabs&&Z.current.send("start")),$.current=setTimeout(ie,Q.current)},be=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout($.current),$.current=null,se(),Y.current&&te.current(),Y.current=!1,F.current=+new Date,z.current=+new Date,V.current=null,Z.current&&(Y.current&&Z.current.active(),Z.current.setAllIdle(!1),!e&&U.emitOnAllTabs&&Z.current.send("reset")),$.current=setTimeout(ie,Q.current)},ye=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];null===V.current&&(ue(),clearTimeout($.current),$.current=null,V.current=ce(),Z.current&&!e&&U.emitOnAllTabs&&Z.current.send("pause"))},Te=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];null!==V.current&&(se(),Y.current||($.current=setTimeout(ie,V.current),V.current=null,z.current=+new Date),Z.current&&!e&&U.emitOnAllTabs&&Z.current.send("resume"))};return n((function(){if(k>0&&I>0)throw new Error("onAction can either be throttled or debounced (not both)");return U&&(Z.current=q({type:U.type,channelName:U.channelName,fallbackInterval:U.fallbackInterval,responseTime:U.responseTime,emitOnAllTabs:U.emitOnAllTabs,callbacks:{onIdle:ee.current,onActive:te.current},start:ge,reset:be,pause:ye,resume:Te})),D?s(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(clearTimeout($.current),ue(!0),!U){e.next=5;break}return e.next=5,Z.current.close();case 5:case"end":return e.stop()}}),e)}))):(M?ge():se(),s(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(clearTimeout($.current),ue(!0),re.cancel&&re.cancel(),!U){e.next=6;break}return e.next=6,Z.current.close();case 6:case"end":return e.stop()}}),e)}))))}),[]),n((function(){var e=X.current;e&&ue(),ae.current=L>0?w(oe,L):oe,e&&se()}),[L]),n((function(){Q.current=o,!K.current&&Y.current&&be(),K.current=!1}),[o]),{isIdle:pe,isLeader:ve,start:ge,pause:ye,reset:be,resume:Te,getLastIdleTime:de,getTotalIdleTime:he,getLastActiveTime:fe,getTotalActiveTime:me,getElapsedTime:le,getRemainingTime:ce}}z.propTypes={timeout:i.number,events:i.arrayOf(i.string),onIdle:i.func,onActive:i.func,onAction:i.func,debounce:i.number,throttle:i.number,eventsThrottle:i.number,element:i.oneOfType([i.object,i.element]),startOnMount:i.bool,startManually:i.bool,stopOnIdle:i.bool,passive:i.bool,capture:i.bool,crossTab:i.oneOfType([i.bool,i.shape({type:i.oneOf(["broadcastChannel","localStorage","simulate"]),channelName:i.string,fallbackInterval:i.number,responseTime:i.number,removeTimeout:i.number,emitOnAllTabs:i.bool})])},z.defaultProps={timeout:12e5,element:y,events:T,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,eventsThrottle:200,startOnMount:!0,startManually:!1,stopOnIdle:!1,capture:!0,passive:!0,crossTab:!1},G.propTypes={timeout:i.number,events:i.arrayOf(i.string),onIdle:i.func,onActive:i.func,onAction:i.func,debounce:i.number,throttle:i.number,eventsThrottle:i.number,element:i.oneOfType([i.object,i.element]),startOnMount:i.bool,startManually:i.bool,stopOnIdle:i.bool,passive:i.bool,capture:i.bool,crossTab:i.oneOfType([i.bool,i.shape({type:i.oneOf(["broadcastChannel","localStorage","simulate"]),channelName:i.string,fallbackInterval:i.number,responseTime:i.number,removeTimeout:i.number,emitOnAllTabs:i.bool})])},G.defaultProps={timeout:12e5,element:y,events:T,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,eventsThrottle:200,startOnMount:!0,startManually:!1,stopOnIdle:!1,capture:!0,passive:!0,crossTab:!1};export default z;export{G as useIdleTimer}; | ||
//# sourceMappingURL=index.es.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(require("prop-types"));function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){return!t||"object"!==u(t)&&"function"!=typeof t?a(e):t}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t,n,r,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void n(e)}s.done?t(u):Promise.resolve(u).then(r,i)}function d(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var o=e.apply(t,n);function a(e){f(o,r,i,a,s,"next",e)}function s(e){f(o,r,i,a,s,"throw",e)}a(void 0)}))}}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}}(e,t)||function(e,t){if(e){if("string"==typeof e)return h(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?h(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var v,m=(function(e){var t=function(e){var t,n=Object.prototype,r=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function u(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=t&&t.prototype instanceof m?t:m,o=Object.create(i.prototype),a=new O(r||[]);return o._invoke=function(e,t,n){var r=f;return function(i,o){if(r===h)throw new Error("Generator is already running");if(r===p){if("throw"===i)throw o;return S()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var s=A(a,n);if(s){if(s===v)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===f)throw r=p,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=h;var u=l(e,t,n);if("normal"===u.type){if(r=n.done?p:d,u.arg===v)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=p,n.method="throw",n.arg=u.arg)}}}(e,n,a),o}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var f="suspendedStart",d="suspendedYield",h="executing",p="completed",v={};function m(){}function g(){}function y(){}var b={};b[o]=function(){return this};var w=Object.getPrototypeOf,_=w&&w(w(x([])));_&&_!==n&&r.call(_,o)&&(b=_);var T=y.prototype=m.prototype=Object.create(b);function k(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function E(e,t){function n(i,o,a,s){var u=l(e[i],e,o);if("throw"!==u.type){var c=u.arg,f=c.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(f).then((function(e){c.value=e,a(c)}),(function(e){return n("throw",e,a,s)}))}s(u.arg)}var i;this._invoke=function(e,r){function o(){return new t((function(t,i){n(e,r,t,i)}))}return i=i?i.then(o,o):o()}}function A(e,n){var r=e.iterator[n.method];if(r===t){if(n.delegate=null,"throw"===n.method){if(e.iterator.return&&(n.method="return",n.arg=t,A(e,n),"throw"===n.method))return v;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var i=l(r,e.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,v;var o=i.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,v):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function I(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function L(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(I,this),this.reset(!0)}function x(e){if(e){var n=e[o];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,a=function n(){for(;++i<e.length;)if(r.call(e,i))return n.value=e[i],n.done=!1,n;return n.value=t,n.done=!0,n};return a.next=a}}return{next:S}}function S(){return{value:t,done:!0}}return g.prototype=T.constructor=y,y.constructor=g,g.displayName=u(y,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===g||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,u(e,s,"GeneratorFunction")),e.prototype=Object.create(T),e},e.awrap=function(e){return{__await:e}},k(E.prototype),E.prototype[a]=function(){return this},e.AsyncIterator=E,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var a=new E(c(t,n,r,i),o);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},k(T),u(T,s,"Generator"),T[o]=function(){return this},T.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=x,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(L),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function i(r,i){return s.type="throw",s.arg=e,n.next=r,i&&(n.method="next",n.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),L(n),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;L(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:x(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),v}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(v={exports:{}},v.exports),v.exports),g="object"===("undefined"==typeof window||"undefined"==typeof window?"undefined":u(window)),y=g?document:{},b=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange"];function w(e,t){var n;function r(){for(var r=arguments.length,i=new Array(r),o=0;o<r;o++)i[o]=arguments[o];n&&clearTimeout(n),n=setTimeout((function(){e.apply(void 0,i),n=null}),t)}return r.cancel=function(){clearTimeout(n)},r}function _(e,t){var n=0;return function(){var r=(new Date).getTime();if(!(r-n<t))return n=r,e.apply(void 0,arguments)}}var T=0,k=0;function E(){var e=(new Date).getTime();return e===T?1e3*e+ ++k:(T=e,k=0,1e3*e)}function A(){return Math.random().toString(36).substring(2)}function I(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return new Promise((function(t){return setTimeout(t,e)}))}function L(){return(new Date).getTime()}var O={create:function(e){var t={messagesCallback:null,bc:new BroadcastChannel(e)};return t.bc.onmessage=function(e){t.messagesCallback&&t.messagesCallback(e.data)},t},close:function(e){e.bc.close()},onMessage:function(e,t){e.messagesCallback=t},postMessage:function(e,t){try{return e.bc.postMessage(t,!1),Promise.resolve()}catch(e){return Promise.reject(e)}},canBeUsed:function(){return"function"==typeof BroadcastChannel},type:"broadcastChannel",averageResponseTime:function(){return 150},microSeconds:E},x=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:6e4;r(this,e),this.ttl=t,this.set=new Set,this.timeMap=new Map}return o(e,[{key:"has",value:function(e){return this.set.has(e)}},{key:"add",value:function(e){this.timeMap.set(e,L()),this.set.add(e),this._removeTooOldValues()}},{key:"clear",value:function(){this.set.clear(),this.timeMap.clear()}},{key:"_removeTooOldValues",value:function(){for(var e=L()-this.ttl,t=this.set[Symbol.iterator]();;){var n=t.next().value;if(!n)return;if(!(this.timeMap.get(n)<e))return;this.timeMap.delete(n),this.set.delete(n)}}}]),e}();function S(){var e;if("undefined"==typeof window)return null;try{e=window.localStorage,e=window["ie8-eventlistener/storage"]||window.localStorage}catch(e){}return e}function M(e,t){var n=e,r=function(e){e.key===n&&t(JSON.parse(e.newValue))};return window.addEventListener("storage",r),r}function D(){var e=S();if(!e)return!1;try{var t="__check";e.setItem(t,"works"),e.removeItem(t)}catch(e){return!1}return!0}var P={create:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!D())throw new Error("❌ localStorage cannot be used.");var n=A(),r=new x(t.removeTimeout),i={channelName:e,uuid:n,eMIs:r};return i.listener=M(e,(function(e){i.messagesCallback&&e.uuid!==n&&e.token&&!r.has(e.token)&&(e.data.time&&e.data.time<i.messagesCallbackTime||(r.add(e.token),i.messagesCallback(e.data)))})),i},close:function(e){var t;t=e.listener,window.removeEventListener("storage",t)},onMessage:function(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t},postMessage:function(e,t){return new Promise((function(n){var r=e.channelName,i={token:A(),time:(new Date).getTime(),data:t,uuid:e.uuid},o=JSON.stringify(i);S().setItem(r,o);var a=document.createEvent("Event");a.initEvent("storage",!0,!0),a.key=r,a.newValue=o,window.dispatchEvent(a),n()}))},canBeUsed:D,type:"localStorage",averageResponseTime:function(){var e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?240:120},microSeconds:E},R=new Set;var j={create:function(e){var t={name:e,messagesCallback:null};return R.add(t),t},close:function(e){R.delete(e)},onMessage:function(e,t){e.messagesCallback=t},postMessage:function(e,t){return new Promise((function(n){return setTimeout((function(){Array.from(R).filter((function(t){return t.name===e.name})).filter((function(t){return t!==e})).filter((function(e){return!!e.messagesCallback})).forEach((function(e){return e.messagesCallback(t)})),n()}),5)}))},canBeUsed:function(){return!0},type:"simulate",averageResponseTime:function(){return 5},microSeconds:E},C=[O,P];function N(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.type){if("simulate"===e.type)return j;var t=C.find((function(t){return t.type===e.type}));if(t)return t;throw new Error("❌ Method ".concat(e.type," is not supported."))}var n=C.find((function(e){return e.canBeUsed()}));if(!n)throw new Error("❌ No method found ".concat(JSON.stringify(C.map((function(e){return e.type})))));return n}var B=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(this,e),this.name=t,this.options=n,this.method=N(this.options),this.closed=!1,this._isListening=!1,this._onMessageListener=null,this._addEventListeners={message:[],internal:[]},this._unSendMessagePromises=new Set,this._beforeClose=[],this._preparePromises=null,F(this)}return o(e,[{key:"postMessage",value:function(e){if(this.closed)throw new Error("❌ Cannot post message after channel has closed");return Y(this,"message",e)}},{key:"postInternal",value:function(e){return Y(this,"internal",e)}},{key:"onmessage",get:function(){return this._onMessageListener},set:function(e){var t={time:this.method.microSeconds(),fn:e};G(this,"message",this._onMessageListener),e&&"function"==typeof e?(this._onMessageListener=t,X(this,"message",t)):this._onMessageListener=null}},{key:"addEventListener",value:function(e,t){X(this,e,{time:this.method.microSeconds(),fn:t})}},{key:"removeEventListener",value:function(e,t){G(this,e,this._addEventListeners[e].find((function(e){return e.fn===t})))}},{key:"close",value:function(){var e=this;if(!this.closed){this.closed=!0;var t=this._preparePromises?this._preparePromises:Promise.resolve();return this._onMessageListener=null,this._addEventListeners.message=[],t.then((function(){return Promise.all(Array.from(e._unSendMessagePromises))})).then((function(){return Promise.all(e._beforeClose.map((function(e){return e()})))})).then((function(){return e.method.close(e._state)}))}}},{key:"type",get:function(){return this.method.type}},{key:"isClosed",value:function(){return this.closed}}]),e}();function Y(e,t,n){var r={time:e.method.microSeconds(),type:t,data:n};return(e._preparePromises?e._preparePromises:Promise.resolve()).then((function(){var t=e.method.postMessage(e._state,r);return e._unSendMessagePromises.add(t),t.catch().then((function(){return e._unSendMessagePromises.delete(t)})),t}))}function F(e){var t,n=e.method.create(e.name,e.options);(t=n)&&"function"==typeof t.then?(e._preparePromises=n,n.then((function(t){e._state=t}))):e._state=n}function U(e){return e._addEventListeners.message.length>0||e._addEventListeners.internal.length>0}function X(e,t,n){e._addEventListeners[t].push(n),function(e){if(!e._isListening&&U(e)){var t=function(t){e._addEventListeners[t.type].forEach((function(e){t.time>=e.time&&e.fn(t.data)}))},n=e.method.microSeconds();e._preparePromises?e._preparePromises.then((function(){e._isListening=!0,e.method.onMessage(e._state,t,n)})):(e._isListening=!0,e.method.onMessage(e._state,t,n))}}(e)}function G(e,t,n){e._addEventListeners[t]=e._addEventListeners[t].filter((function(e){return e!==n})),function(e){if(e._isListening&&!U(e)){e._isListening=!1;var t=e.method.microSeconds();e.method.onMessage(e._state,null,t)}}(e)}var V=function(){function e(t,n){var i=this;r(this,e),this._channel=t,this._options=n,this.isLeader=!1,this.isDead=!1,this.token=A(),this._isApplying=!1,this._reApply=!1,this._unloadFns=[],this._listeners=[],this._intervals=[],this._duplicateListeners=function(){},this._duplicateCalled=!1,this._onBeforeDie=d(m.mark((function e(){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)})));var o=function(){var e=d(m.mark((function e(){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",i.die());case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();g&&(window.addEventListener("beforeUnload",o),window.addEventListener("unload",o),this._unloadFns.push(["beforeUnload",o]),this._unloadFns.push(["unload",o]))}var t;return o(e,[{key:"applyOnce",value:function(){var e=this;if(this.isLeader)return Promise.resolve(!1);if(this.isDead)return Promise.resolve(!1);if(this._isApplying)return this._reApply=!0,Promise.resolve(!1);this._isApplying=!0;var t=!1,n=function(n){"leader"===n.context&&n.token!==e.token&&("apply"===n.action&&n.token>e.token&&(t=!0),"tell"===n.action&&(t=!0))};return this._channel.addEventListener("internal",n),J(this,"apply").then((function(){return I(e._options.responseTime)})).then((function(){return t?Promise.reject(new Error):J(e,"apply")})).then((function(){return I(e._options.responseTime)})).then((function(){return t?Promise.reject(new Error):J(e)})).then((function(){return function(e){e.isLeader=!0;var t=function(t){"leader"===t.context&&"apply"===t.action&&J(e,"tell"),"leader"!==t.context||"tell"!==t.action||e._duplicateCalled||(e._duplicateCalled=!0,e._duplicateListeners(),J(e,"tell"))};return e._channel.addEventListener("internal",t),e._listeners.push(t),J(e,"tell")}(e)})).then((function(){return!0})).catch((function(){return!1})).then((function(t){return e._channel.removeEventListener("internal",n),e._isApplying=!1,!t&&e._reApply?(e._reApply=!1,e.applyOnce()):t}))}},{key:"awaitLeadership",value:function(){var e;return this._awaitLeadershipPromise||(this._awaitLeadershipPromise=(e=this).isLeader?Promise.resolve():new Promise((function(t){var n=!1;function r(){n||(n=!0,clearInterval(i),e._channel.removeEventListener("internal",o),t(!0))}e.applyOnce().then((function(){e.isLeader&&r()}));var i=setInterval((function(){e.applyOnce().then((function(){e.isLeader&&r()}))}),e._options.fallbackInterval);e._intervals.push(i);var o=function(t){"leader"===t.context&&"death"===t.action&&e.applyOnce().then((function(){e.isLeader&&r()}))};e._channel.addEventListener("internal",o),e._listeners.push(o)}))),this._awaitLeadershipPromise}},{key:"onDuplicate",get:function(){return this._duplicateListeners},set:function(e){this._duplicateListeners=e}},{key:"onBeforeDie",get:function(){return this._onBeforeDie},set:function(e){this._onBeforeDie=e}},{key:"die",value:(t=d(m.mark((function e(){var t=this;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isDead){e.next=2;break}return e.abrupt("return");case 2:return this.isDead=!0,e.next=5,this.onBeforeDie();case 5:return this._listeners.forEach((function(e){return t._channel.removeEventListener("internal",e)})),this._intervals.forEach((function(e){return clearInterval(e)})),this._unloadFns.forEach((function(e){g&&window.removeEventListener(e[0],e[1])})),e.abrupt("return",J(this,"death"));case 9:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();function J(e,t){var n={context:"leader",action:t,token:e.token};return e._channel.postInternal(n)}var q=function(e){var t=e.type,n=e.channelName,r=e.fallbackInterval,i=e.responseTime,o=e.emitOnAllTabs,a=e.callbacks,s=e.start,u=e.reset,c=e.pause,l=e.resume,f=new B(n,{type:t}),h=function(e,t){if(e._leaderElector)throw new Error("❌ MessageChannel already has a leader-elector");var n=new V(e,t);return e._beforeClose.push(d(m.mark((function e(){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.die());case 1:case"end":return e.stop()}}),e)})))),e._leaderElector=n,n}(f,{fallbackInterval:r,responseTime:i}),v={};v[h.token]=!1;var g=!1,y=!0,b=function(){return g};h.awaitLeadership().then((function(){g=!0})),f.addEventListener("message",(function(e){var t=p(e,2),n=t[0],r=t[1];switch(n){case"register":v[r]=!1;break;case"deregister":delete v[r];break;case"idle":w(r);break;case"active":_(r);break;case"emitIdle":a.onIdle();break;case"emitActive":a.onActive();break;case"start":s(!0);break;case"reset":u(!0);break;case"pause":c(!0);break;case"resume":l(!0)}}));var w=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:h.token;v[e]=!0;var t=Object.values(v).every((function(e){return e}));!y&&t&&(y=!0,b()?(a.onIdle(),o&&T("emitIdle")):T("idle"))},_=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:h.token;v[e]=!1;var t=Object.values(v).some((function(e){return!e}));y&&t&&(y=!1,b()?(a.onActive(),o&&T("emitActive")):T("active"))};h.onDuplicate=d(m.mark((function e(){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,h.die();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)}))),h.onBeforeDie=d(m.mark((function e(){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,T("deregister");case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));var T=function(){var e=d(m.mark((function e(t){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",f.postMessage([t,h.token]));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),k=function(){var e=d(m.mark((function e(){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,h.die();case 2:return e.next=4,f.close();case 4:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();return T("register"),{close:k,send:T,isLeader:b,idle:w,active:_,isAllIdle:function(){return y},setAllIdle:function(e){y=e}}};function W(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=l(e);if(t){var i=l(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return c(this,n)}}var $=function(t){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}(i,e.Component);var n=W(i);function i(e){var t;if(r(this,i),(t=n.call(this,e)).state={idle:!1,oldDate:+new Date,lastActive:+new Date,lastIdle:null,idleTime:0,remaining:null,pageX:null,pageY:null},t.tId=null,t.eventsBound=!1,t.callbackRefs={},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0?t._onAction=w(e.onAction,e.debounce):e.throttle>0?t._onAction=_(e.onAction,e.throttle):t._onAction=e.onAction,e.eventsThrottle>0?t.handleEvent=_(t._handleEvent.bind(a(t)),e.eventsThrottle):t.handleEvent=t._handleEvent.bind(a(t)),e.startOnMount&&!e.startManually||(t.state.idle=!0),t._toggleIdleState=t._toggleIdleState.bind(a(t)),t.start=t.start.bind(a(t)),t.reset=t.reset.bind(a(t)),t.pause=t.pause.bind(a(t)),t.resume=t.resume.bind(a(t)),t.isIdle=t.isIdle.bind(a(t)),t.getRemainingTime=t.getRemainingTime.bind(a(t)),t.getElapsedTime=t.getElapsedTime.bind(a(t)),t.getLastActiveTime=t.getLastActiveTime.bind(a(t)),t.getLastIdleTime=t.getLastIdleTime.bind(a(t)),t.getTotalIdleTime=t.getTotalIdleTime.bind(a(t)),t.getTotalActiveTime=t.getTotalActiveTime.bind(a(t)),t}return o(i,[{key:"componentDidMount",value:function(){var e=this.props,t=e.startOnMount,n=e.startManually;this._setupTabManager(),n||(t?this.start():this._bindEvents())}},{key:"componentDidUpdate",value:function(e){e.debounce!==this.props.debounce&&this.props.debounce>0?(this._onAction.cancel&&this._onAction.cancel(),this._onAction=w(this.props.onAction,this.props.debounce)):e.throttle!==this.props.throttle&&this.props.throttle>0?(this._onAction.cancel&&this._onAction.cancel(),this._onAction=_(this.props.onAction,this.props.throttle)):(e.throttle&&0===this.props.throttle||e.debounce&&0===this.props.debounce)&&(this._onAction.cancel&&this._onAction.cancel(),this._onAction=this.props.onAction),e.eventsThrottle!==this.props.eventsThrottle&&(this._unbindEvents(),this.handleEvent=_(this._handleEvent.bind(this),this.props.eventsThrottle),this._bindEvents()),e.timeout!==this.props.timeout&&this.state.idle&&this.reset(),e.onActive!==this.props.onActive&&(this.callbackRefs.onActive=this.props.onActive),e.onIdle!==this.props.onIdle&&(this.callbackRefs.onIdle=this.props.onIdle)}},{key:"componentWillUnmount",value:function(){clearTimeout(this.tId),this._unbindEvents(!0),this._onAction.cancel&&this._onAction.cancel(),this.manager&&this.manager.close().catch(console.error)}},{key:"render",value:function(){return this.props.children||null}},{key:"_setupTabManager",value:function(){var e=this.props,t=e.crossTab,n=e.onIdle,r=e.onActive;if(this.callbackRefs={onIdle:n,onActive:r},t){var i=Object.assign({channelName:"idle-timer",fallbackInterval:2e3,responseTime:100,removeTimeout:6e4,emitOnAllTabs:!1},!0===t?{}:t),o=i.type,a=i.channelName,s=i.fallbackInterval,u=i.responseTime,c=i.emitOnAllTabs;this.manager=q({type:o,channelName:a,fallbackInterval:s,responseTime:u,emitOnAllTabs:c,callbacks:this.callbackRefs,start:this.start,reset:this.reset,pause:this.pause,resume:this.resume})}}},{key:"_bindEvents",value:function(){var e=this;if(g){var t=this.props,n=t.element,r=t.events,i=t.passive,o=t.capture;this.eventsBound||(r.forEach((function(t){n.addEventListener(t,e.handleEvent,{capture:o,passive:i})})),this.eventsBound=!0)}}},{key:"_unbindEvents",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(g){var n=this.props,r=n.element,i=n.events,o=n.passive,a=n.capture;(this.eventsBound||t)&&(i.forEach((function(t){r.removeEventListener(t,e.handleEvent,{capture:a,passive:o})})),this.eventsBound=!1)}}},{key:"_toggleIdleState",value:function(e){var t=this;this.setState((function(e){return{idle:!e.idle,lastIdle:e.idle?e.lastIdle:+new Date-t.props.timeout,idleTime:e.idle?e.idleTime+ +new Date-e.lastIdle:e.idleTime}}),(function(){var n=t.props,r=n.onActive,i=n.onIdle,o=n.stopOnIdle;t.state.idle?(o&&(clearTimeout(t.tId),t.tId=null,t._unbindEvents()),t.manager?t.manager.idle():i(e)):(t._bindEvents(),t.manager?t.manager.active():r(e))}))}},{key:"_handleEvent",value:function(e){var t=this.state,n=t.remaining,r=t.pageX,i=t.pageY,o=t.idle,a=this.props,s=a.timeout,u=a.stopOnIdle;if(this._onAction(e),!n){if("mousemove"===e.type){if(e.pageX===r&&e.pageY===i)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(this.getElapsedTime()<200)return}clearTimeout(this.tId),this.tId=null;var c=+new Date-this.getLastActiveTime();(o&&!u||!o&&c>s)&&this._toggleIdleState(e),this.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),o&&u||(this.tId=setTimeout(this._toggleIdleState,s))}}},{key:"start",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.setState({idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null}),this.manager&&(this.manager.setAllIdle(!1),!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("start"));var t=this.props.timeout;this.tId=setTimeout(this._toggleIdleState,t)}},{key:"reset",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.state.idle&&this.props.onActive(),this.manager&&(this.manager.setAllIdle(!1),!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("reset")),this.setState({idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null});var t=this.props.timeout;this.tId=setTimeout(this._toggleIdleState,t)}},{key:"pause",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.state.remaining;null===t&&(this._unbindEvents(),clearTimeout(this.tId),this.tId=null,this.manager&&!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("pause"),this.setState({remaining:this.getRemainingTime()}))}},{key:"resume",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.state,n=t.remaining,r=t.idle;null!==n&&(this._bindEvents(),this.manager&&!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("resume"),r||(this.tId=setTimeout(this._toggleIdleState,n),this.setState({remaining:null,lastActive:+new Date})))}},{key:"getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.lastActive,r=this.props.timeout;if(null!==t)return t<0?0:t;var i=r-(+new Date-n);return i<0?0:i}},{key:"getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"getLastIdleTime",value:function(){return this.state.lastIdle}},{key:"getTotalIdleTime",value:function(){var e=this.state,t=e.idle,n=e.lastIdle,r=e.idleTime;return t?+new Date-n+r:r}},{key:"getLastActiveTime",value:function(){return this.state.lastActive}},{key:"getTotalActiveTime",value:function(){return this.getElapsedTime()-this.getTotalIdleTime()}},{key:"isIdle",value:function(){return this.state.idle}},{key:"isLeader",value:function(){return!this.manager||this.manager.isLeader()}}]),i}();function z(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.timeout,r=void 0===n?12e5:n,i=t.element,o=void 0===i?y:i,a=t.events,s=void 0===a?b:a,u=t.onIdle,c=void 0===u?function(){}:u,l=t.onActive,f=void 0===l?function(){}:l,h=t.onAction,p=void 0===h?function(){}:h,v=t.debounce,T=void 0===v?0:v,k=t.throttle,E=void 0===k?0:k,A=t.eventsThrottle,I=void 0===A?200:A,L=t.startOnMount,O=void 0===L||L,x=t.startManually,S=void 0!==x&&x,M=t.stopOnIdle,D=void 0!==M&&M,P=t.capture,R=void 0===P||P,j=t.passive,C=void 0===j||j,N=t.crossTab,B=void 0!==N&&N,Y=e.useRef(!1),F=e.useRef(!0),U=e.useRef(+new Date),X=e.useRef(null),G=e.useRef(null),V=e.useRef(null),J=e.useRef(null),W=e.useRef(null),$=e.useRef(null),z=e.useRef(0),H=e.useRef(!0),K=e.useRef(r),Q=e.useRef(null);B&&(!0===B&&(B={}),B=Object.assign({channelName:"idle-timer",fallbackInterval:2e3,responseTime:100,removeTimeout:6e4,emitOnAllTabs:!1},B));var Z=e.useRef(c),ee=e.useRef(f),te=e.useRef(p);e.useEffect((function(){Z.current=c}),[c]),e.useEffect((function(){ee.current=f}),[f]),e.useEffect((function(){te.current=p}),[p]);var ne=e.useMemo((function(){function e(e){te.current(e)}return e.cancel&&e.cancel(),T>0?w(e,T):E>0?_(e,E):e}),[E,T]),re=function(e){var t=!F.current;F.current=t,t?(D&&(clearTimeout(J.current),J.current=null,se()),$.current=+new Date-K.current,Q.current?Q.current.idle():Z.current(e)):(z.current+=+new Date-$.current,ae(),Q.current?Q.current.active():ee.current(e))},ie=function(e){if(ne(e),!X.current){if("mousemove"===e.type){if(e.pageX===G&&e.pageY===V)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(ce()<200)return}clearTimeout(J.current),J.current=null;var t=+new Date-de();(F.current&&!D||!F.current&&t>K.current)&&re(e),W.current=+new Date,G.current=e.pageX,V.current=e.pageY,F.current||(J.current=setTimeout(re,K.current))}},oe=e.useRef(ie),ae=function(){g&&(Y.current||(s.forEach((function(e){o.addEventListener(e,oe.current,{capture:R,passive:C})})),Y.current=!0))},se=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];g&&(Y.current||e)&&(s.forEach((function(e){o.removeEventListener(e,oe.current,{capture:R,passive:C})})),Y.current=!1)},ue=function(){if(null!==X.current)return X.current<0?0:X.current;var e=K.current-(+new Date-W.current);return e<0?0:e},ce=function(){return+new Date-U.current},le=function(){return $.current},fe=function(){return F.current?+new Date-$.current+z.current:z.current},de=function(){return W.current},he=function(){return ce()-fe()},pe=function(){return F.current},ve=function(){return!Q.current||Q.current.isLeader()},me=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout(J.current),J.current=null,ae(),F.current=!1,U.current=+new Date,W.current=+new Date,X.current=null,Q.current&&(Q.current.setAllIdle(!1),!e&&B.emitOnAllTabs&&Q.current.send("start")),J.current=setTimeout(re,K.current)},ge=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout(J.current),J.current=null,ae(),F.current&&ee.current(),F.current=!1,U.current=+new Date,W.current=+new Date,X.current=null,Q.current&&(Q.current.setAllIdle(!1),!e&&B.emitOnAllTabs&&Q.current.send("reset")),J.current=setTimeout(re,K.current)},ye=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];null===X.current&&(se(),clearTimeout(J.current),J.current=null,X.current=ue(),Q.current&&!e&&B.emitOnAllTabs&&Q.current.send("pause"))},be=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];null!==X.current&&(ae(),F.current||(J.current=setTimeout(re,X.current),X.current=null,W.current=+new Date),Q.current&&!e&&B.emitOnAllTabs&&Q.current.send("resume"))};return e.useEffect((function(){if(T>0&&E>0)throw new Error("onAction can either be throttled or debounced (not both)");return B&&(Q.current=q({type:B.type,channelName:B.channelName,fallbackInterval:B.fallbackInterval,responseTime:B.responseTime,emitOnAllTabs:B.emitOnAllTabs,callbacks:{onIdle:Z.current,onActive:ee.current},start:me,reset:ge,pause:ye,resume:be})),S?d(m.mark((function e(){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(clearTimeout(J.current),se(!0),!B){e.next=5;break}return e.next=5,Q.current.close();case 5:case"end":return e.stop()}}),e)}))):(O?me():ae(),d(m.mark((function e(){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(clearTimeout(J.current),se(!0),ne.cancel&&ne.cancel(),!B){e.next=6;break}return e.next=6,Q.current.close();case 6:case"end":return e.stop()}}),e)}))))}),[]),e.useEffect((function(){var e=Y.current;e&&se(),oe.current=I>0?_(ie,I):ie,e&&ae()}),[I]),e.useEffect((function(){K.current=r,!H.current&&F.current&&ge(),H.current=!1}),[r]),{isIdle:pe,isLeader:ve,start:me,pause:ye,reset:ge,resume:be,getLastIdleTime:le,getTotalIdleTime:fe,getLastActiveTime:de,getTotalActiveTime:he,getElapsedTime:ce,getRemainingTime:ue}}$.propTypes={timeout:n.default.number,events:n.default.arrayOf(n.default.string),onIdle:n.default.func,onActive:n.default.func,onAction:n.default.func,debounce:n.default.number,throttle:n.default.number,eventsThrottle:n.default.number,element:n.default.oneOfType([n.default.object,n.default.element]),startOnMount:n.default.bool,startManually:n.default.bool,stopOnIdle:n.default.bool,passive:n.default.bool,capture:n.default.bool,crossTab:n.default.oneOfType([n.default.bool,n.default.shape({type:n.default.oneOf(["broadcastChannel","localStorage","simulate"]),channelName:n.default.string,fallbackInterval:n.default.number,responseTime:n.default.number,removeTimeout:n.default.number,emitOnAllTabs:n.default.bool})])},$.defaultProps={timeout:12e5,element:y,events:b,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,eventsThrottle:200,startOnMount:!0,startManually:!1,stopOnIdle:!1,capture:!0,passive:!0,crossTab:!1},z.propTypes={timeout:n.default.number,events:n.default.arrayOf(n.default.string),onIdle:n.default.func,onActive:n.default.func,onAction:n.default.func,debounce:n.default.number,throttle:n.default.number,eventsThrottle:n.default.number,element:n.default.oneOfType([n.default.object,n.default.element]),startOnMount:n.default.bool,startManually:n.default.bool,stopOnIdle:n.default.bool,passive:n.default.bool,capture:n.default.bool,crossTab:n.default.oneOfType([n.default.bool,n.default.shape({type:n.default.oneOf(["broadcastChannel","localStorage","simulate"]),channelName:n.default.string,fallbackInterval:n.default.number,responseTime:n.default.number,removeTimeout:n.default.number,emitOnAllTabs:n.default.bool})])},z.defaultProps={timeout:12e5,element:y,events:b,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,eventsThrottle:200,startOnMount:!0,startManually:!1,stopOnIdle:!1,capture:!0,passive:!0,crossTab:!1},exports.default=$,exports.useIdleTimer=z; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(require("prop-types"));function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,t,n,r,i,a,o){try{var s=e[a](o),u=s.value}catch(e){return void n(e)}s.done?t(u):Promise.resolve(u).then(r,i)}function a(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var o=e.apply(t,n);function s(e){i(o,r,a,s,u,"next",e)}function u(e){i(o,r,a,s,u,"throw",e)}s(void 0)}))}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function u(e,t,n){return t&&s(e.prototype,t),n&&s(e,n),e}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function f(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?f(e):t}function h(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=c(e);if(t){var i=c(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return d(this,n)}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==n)return;var r,i,a=[],o=!0,s=!1;try{for(n=n.call(e);!(o=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);o=!0);}catch(e){s=!0,i=e}finally{try{o||null==n.return||n.return()}finally{if(s)throw i}}return a}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return m(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return m(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var v="object"===("undefined"==typeof window||"undefined"==typeof window?"undefined":r(window)),g=v?document:{},b=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange"];function y(e,t){var n;function r(){for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];n&&clearTimeout(n),n=setTimeout((function(){e.apply(void 0,i),n=null}),t)}return r.cancel=function(){clearTimeout(n)},r}function T(e,t){var n=0;return function(){var r=(new Date).getTime();if(!(r-n<t))return n=r,e.apply(void 0,arguments)}}var _=0,w=0;function k(){var e=(new Date).getTime();return e===_?1e3*e+ ++w:(_=e,w=0,1e3*e)}function A(){return Math.random().toString(36).substring(2)}function I(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return new Promise((function(t){return setTimeout(t,e)}))}function E(){return(new Date).getTime()}var L={create:function(e){var t={messagesCallback:null,bc:new BroadcastChannel(e)};return t.bc.onmessage=function(e){t.messagesCallback&&t.messagesCallback(e.data)},t},close:function(e){e.bc.close()},onMessage:function(e,t){e.messagesCallback=t},postMessage:function(e,t){try{return e.bc.postMessage(t,!1),Promise.resolve()}catch(e){return Promise.reject(e)}},canBeUsed:function(){return"function"==typeof BroadcastChannel},type:"broadcastChannel",averageResponseTime:function(){return 150},microSeconds:k},O=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:6e4;o(this,e),this.ttl=t,this.set=new Set,this.timeMap=new Map}return u(e,[{key:"has",value:function(e){return this.set.has(e)}},{key:"add",value:function(e){this.timeMap.set(e,E()),this.set.add(e),this._removeTooOldValues()}},{key:"clear",value:function(){this.set.clear(),this.timeMap.clear()}},{key:"_removeTooOldValues",value:function(){for(var e=E()-this.ttl,t=this.set[Symbol.iterator]();;){var n=t.next().value;if(!n)return;if(!(this.timeMap.get(n)<e))return;this.timeMap.delete(n),this.set.delete(n)}}}]),e}();function M(){var e;if("undefined"==typeof window)return null;try{e=window.localStorage,e=window["ie8-eventlistener/storage"]||window.localStorage}catch(e){}return e}function R(e,t){var n=e,r=function(e){e.key===n&&t(JSON.parse(e.newValue))};return window.addEventListener("storage",r),r}function S(){var e=M();if(!e)return!1;try{var t="__check";e.setItem(t,"works"),e.removeItem(t)}catch(e){return!1}return!0}var D={create:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!S())throw new Error("❌ localStorage cannot be used.");var n=A(),r=new O(t.removeTimeout),i={channelName:e,uuid:n,eMIs:r};return i.listener=R(e,(function(e){i.messagesCallback&&e.uuid!==n&&e.token&&!r.has(e.token)&&(e.data.time&&e.data.time<i.messagesCallbackTime||(r.add(e.token),i.messagesCallback(e.data)))})),i},close:function(e){var t;t=e.listener,window.removeEventListener("storage",t)},onMessage:function(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t},postMessage:function(e,t){return new Promise((function(n){var r=e.channelName,i={token:A(),time:(new Date).getTime(),data:t,uuid:e.uuid},a=JSON.stringify(i);M().setItem(r,a);var o=document.createEvent("Event");o.initEvent("storage",!0,!0),o.key=r,o.newValue=a,window.dispatchEvent(o),n()}))},canBeUsed:S,type:"localStorage",averageResponseTime:function(){var e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?240:120},microSeconds:k},P=new Set;var x={create:function(e){var t={name:e,messagesCallback:null};return P.add(t),t},close:function(e){P.delete(e)},onMessage:function(e,t){e.messagesCallback=t},postMessage:function(e,t){return new Promise((function(n){return setTimeout((function(){Array.from(P).filter((function(t){return t.name===e.name})).filter((function(t){return t!==e})).filter((function(e){return!!e.messagesCallback})).forEach((function(e){return e.messagesCallback(t)})),n()}),5)}))},canBeUsed:function(){return!0},type:"simulate",averageResponseTime:function(){return 5},microSeconds:k},C=[L,D];function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.type){if("simulate"===e.type)return x;var t=C.find((function(t){return t.type===e.type}));if(t)return t;throw new Error("❌ Method ".concat(e.type," is not supported."))}var n=C.find((function(e){return e.canBeUsed()}));if(!n)throw new Error("❌ No method found ".concat(JSON.stringify(C.map((function(e){return e.type})))));return n}var B=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e),this.name=t,this.options=n,this.method=j(this.options),this.closed=!1,this._isListening=!1,this._onMessageListener=null,this._addEventListeners={message:[],internal:[]},this._unSendMessagePromises=new Set,this._beforeClose=[],this._preparePromises=null,U(this)}return u(e,[{key:"postMessage",value:function(e){if(this.closed)throw new Error("❌ Cannot post message after channel has closed");return N(this,"message",e)}},{key:"postInternal",value:function(e){return N(this,"internal",e)}},{key:"onmessage",get:function(){return this._onMessageListener},set:function(e){var t={time:this.method.microSeconds(),fn:e};F(this,"message",this._onMessageListener),e&&"function"==typeof e?(this._onMessageListener=t,Y(this,"message",t)):this._onMessageListener=null}},{key:"addEventListener",value:function(e,t){Y(this,e,{time:this.method.microSeconds(),fn:t})}},{key:"removeEventListener",value:function(e,t){F(this,e,this._addEventListeners[e].find((function(e){return e.fn===t})))}},{key:"close",value:function(){var e=this;if(!this.closed){this.closed=!0;var t=this._preparePromises?this._preparePromises:Promise.resolve();return this._onMessageListener=null,this._addEventListeners.message=[],t.then((function(){return Promise.all(Array.from(e._unSendMessagePromises))})).then((function(){return Promise.all(e._beforeClose.map((function(e){return e()})))})).then((function(){return e.method.close(e._state)}))}}},{key:"type",get:function(){return this.method.type}},{key:"isClosed",value:function(){return this.closed}}]),e}();function N(e,t,n){var r={time:e.method.microSeconds(),type:t,data:n};return(e._preparePromises?e._preparePromises:Promise.resolve()).then((function(){var t=e.method.postMessage(e._state,r);return e._unSendMessagePromises.add(t),t.catch().then((function(){return e._unSendMessagePromises.delete(t)})),t}))}function U(e){var t,n=e.method.create(e.name,e.options);(t=n)&&"function"==typeof t.then?(e._preparePromises=n,n.then((function(t){e._state=t}))):e._state=n}function X(e){return e._addEventListeners.message.length>0||e._addEventListeners.internal.length>0}function Y(e,t,n){e._addEventListeners[t].push(n),function(e){if(!e._isListening&&X(e)){var t=function(t){e._addEventListeners[t.type].forEach((function(e){t.time>=e.time&&e.fn(t.data)}))},n=e.method.microSeconds();e._preparePromises?e._preparePromises.then((function(){e._isListening=!0,e.method.onMessage(e._state,t,n)})):(e._isListening=!0,e.method.onMessage(e._state,t,n))}}(e)}function F(e,t,n){e._addEventListeners[t]=e._addEventListeners[t].filter((function(e){return e!==n})),function(e){if(e._isListening&&!X(e)){e._isListening=!1;var t=e.method.microSeconds();e.method.onMessage(e._state,null,t)}}(e)}var V=function(){function e(t,n){var r=this;o(this,e),this._channel=t,this._options=n,this.isLeader=!1,this.isDead=!1,this.token=A(),this._isApplying=!1,this._reApply=!1,this._unloadFns=[],this._listeners=[],this._intervals=[],this._duplicateListeners=function(){},this._duplicateCalled=!1,this._onBeforeDie=a(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)})));var i=function(){var e=a(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",r.die());case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();v&&(window.addEventListener("beforeUnload",i),window.addEventListener("unload",i),this._unloadFns.push(["beforeUnload",i]),this._unloadFns.push(["unload",i]))}var t;return u(e,[{key:"applyOnce",value:function(){var e=this;if(this.isLeader)return Promise.resolve(!1);if(this.isDead)return Promise.resolve(!1);if(this._isApplying)return this._reApply=!0,Promise.resolve(!1);this._isApplying=!0;var t=!1,n=function(n){"leader"===n.context&&n.token!==e.token&&("apply"===n.action&&n.token>e.token&&(t=!0),"tell"===n.action&&(t=!0))};return this._channel.addEventListener("internal",n),J(this,"apply").then((function(){return I(e._options.responseTime)})).then((function(){return t?Promise.reject(new Error):J(e,"apply")})).then((function(){return I(e._options.responseTime)})).then((function(){return t?Promise.reject(new Error):J(e)})).then((function(){return function(e){e.isLeader=!0;var t=function(t){"leader"===t.context&&"apply"===t.action&&J(e,"tell"),"leader"!==t.context||"tell"!==t.action||e._duplicateCalled||(e._duplicateCalled=!0,e._duplicateListeners(),J(e,"tell"))};return e._channel.addEventListener("internal",t),e._listeners.push(t),J(e,"tell")}(e)})).then((function(){return!0})).catch((function(){return!1})).then((function(t){return e._channel.removeEventListener("internal",n),e._isApplying=!1,!t&&e._reApply?(e._reApply=!1,e.applyOnce()):t}))}},{key:"awaitLeadership",value:function(){var e;return this._awaitLeadershipPromise||(this._awaitLeadershipPromise=(e=this).isLeader?Promise.resolve():new Promise((function(t){var n=!1;function r(){n||(n=!0,clearInterval(i),e._channel.removeEventListener("internal",a),t(!0))}e.applyOnce().then((function(){e.isLeader&&r()}));var i=setInterval((function(){e.applyOnce().then((function(){e.isLeader&&r()}))}),e._options.fallbackInterval);e._intervals.push(i);var a=function(t){"leader"===t.context&&"death"===t.action&&e.applyOnce().then((function(){e.isLeader&&r()}))};e._channel.addEventListener("internal",a),e._listeners.push(a)}))),this._awaitLeadershipPromise}},{key:"onDuplicate",get:function(){return this._duplicateListeners},set:function(e){this._duplicateListeners=e}},{key:"onBeforeDie",get:function(){return this._onBeforeDie},set:function(e){this._onBeforeDie=e}},{key:"die",value:(t=a(regeneratorRuntime.mark((function e(){var t=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isDead){e.next=2;break}return e.abrupt("return");case 2:return this.isDead=!0,e.next=5,this.onBeforeDie();case 5:return this._listeners.forEach((function(e){return t._channel.removeEventListener("internal",e)})),this._intervals.forEach((function(e){return clearInterval(e)})),this._unloadFns.forEach((function(e){v&&window.removeEventListener(e[0],e[1])})),e.abrupt("return",J(this,"death"));case 9:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();function J(e,t){var n={context:"leader",action:t,token:e.token};return e._channel.postInternal(n)}var q=function(e){var t=e.type,n=e.channelName,r=e.fallbackInterval,i=e.responseTime,o=e.emitOnAllTabs,s=e.callbacks,u=e.start,c=e.reset,l=e.pause,f=e.resume,d=new B(n,{type:t}),h=function(e,t){if(e._leaderElector)throw new Error("❌ MessageChannel already has a leader-elector");var n=new V(e,t);return e._beforeClose.push(a(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.die());case 1:case"end":return e.stop()}}),e)})))),e._leaderElector=n,n}(d,{fallbackInterval:r,responseTime:i}),m={};m[h.token]=!1;var v=!1,g=!0,b=function(){return v};h.awaitLeadership().then((function(){v=!0})),d.addEventListener("message",(function(e){var t=p(e,2),n=t[0],r=t[1];switch(n){case"register":m[r]=!1;break;case"deregister":delete m[r];break;case"idle":y(r);break;case"active":T(r);break;case"emitIdle":s.onIdle();break;case"emitActive":s.onActive();break;case"start":u(!0);break;case"reset":c(!0);break;case"pause":l(!0);break;case"resume":f(!0)}}));var y=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:h.token;m[e]=!0;var t=Object.values(m).every((function(e){return e}));!g&&t&&(g=!0,b()?(s.onIdle(),o&&_("emitIdle")):_("idle"))},T=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:h.token;m[e]=!1;var t=Object.values(m).some((function(e){return!e}));g&&t&&(g=!1,b()?(s.onActive(),o&&_("emitActive")):_("active"))};h.onDuplicate=a(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,h.die();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)}))),h.onBeforeDie=a(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_("deregister");case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));var _=function(){var e=a(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",d.postMessage([t,h.token]));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),w=function(){var e=a(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,h.die();case 2:return e.next=4,d.close();case 4:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();return _("register"),{close:w,send:_,isLeader:b,idle:y,active:T,isAllIdle:function(){return g},setAllIdle:function(e){g=e}}},W=function(t){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&l(e,t)}(r,e.Component);var n=h(r);function r(e){var t;if(o(this,r),(t=n.call(this,e)).state={idle:!1,oldDate:+new Date,lastActive:+new Date,lastIdle:null,idleTime:0,remaining:null,pageX:null,pageY:null},t.tId=null,t.eventsBound=!1,t.callbackRefs={},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0?t._onAction=y(e.onAction,e.debounce):e.throttle>0?t._onAction=T(e.onAction,e.throttle):t._onAction=e.onAction,e.eventsThrottle>0?t.handleEvent=T(t._handleEvent.bind(f(t)),e.eventsThrottle):t.handleEvent=t._handleEvent.bind(f(t)),e.startOnMount&&!e.startManually||(t.state.idle=!0),t._toggleIdleState=t._toggleIdleState.bind(f(t)),t.start=t.start.bind(f(t)),t.reset=t.reset.bind(f(t)),t.pause=t.pause.bind(f(t)),t.resume=t.resume.bind(f(t)),t.isIdle=t.isIdle.bind(f(t)),t.getRemainingTime=t.getRemainingTime.bind(f(t)),t.getElapsedTime=t.getElapsedTime.bind(f(t)),t.getLastActiveTime=t.getLastActiveTime.bind(f(t)),t.getLastIdleTime=t.getLastIdleTime.bind(f(t)),t.getTotalIdleTime=t.getTotalIdleTime.bind(f(t)),t.getTotalActiveTime=t.getTotalActiveTime.bind(f(t)),t}return u(r,[{key:"componentDidMount",value:function(){var e=this.props,t=e.startOnMount,n=e.startManually;this._setupTabManager(),n||(t?this.start():this._bindEvents())}},{key:"componentDidUpdate",value:function(e){e.debounce!==this.props.debounce&&this.props.debounce>0?(this._onAction.cancel&&this._onAction.cancel(),this._onAction=y(this.props.onAction,this.props.debounce)):e.throttle!==this.props.throttle&&this.props.throttle>0?(this._onAction.cancel&&this._onAction.cancel(),this._onAction=T(this.props.onAction,this.props.throttle)):(e.throttle&&0===this.props.throttle||e.debounce&&0===this.props.debounce)&&(this._onAction.cancel&&this._onAction.cancel(),this._onAction=this.props.onAction),e.eventsThrottle!==this.props.eventsThrottle&&(this._unbindEvents(),this.handleEvent=T(this._handleEvent.bind(this),this.props.eventsThrottle),this._bindEvents()),e.timeout!==this.props.timeout&&this.state.idle&&this.reset(),e.onActive!==this.props.onActive&&(this.callbackRefs.onActive=this.props.onActive),e.onIdle!==this.props.onIdle&&(this.callbackRefs.onIdle=this.props.onIdle)}},{key:"componentWillUnmount",value:function(){clearTimeout(this.tId),this._unbindEvents(!0),this._onAction.cancel&&this._onAction.cancel(),this.manager&&this.manager.close().catch(console.error)}},{key:"render",value:function(){return this.props.children||null}},{key:"_setupTabManager",value:function(){var e=this.props,t=e.crossTab,n=e.onIdle,r=e.onActive;if(this.callbackRefs={onIdle:n,onActive:r},t){var i=Object.assign({channelName:"idle-timer",fallbackInterval:2e3,responseTime:100,removeTimeout:6e4,emitOnAllTabs:!1},!0===t?{}:t),a=i.type,o=i.channelName,s=i.fallbackInterval,u=i.responseTime,c=i.emitOnAllTabs;this.manager=q({type:a,channelName:o,fallbackInterval:s,responseTime:u,emitOnAllTabs:c,callbacks:this.callbackRefs,start:this.start,reset:this.reset,pause:this.pause,resume:this.resume})}}},{key:"_bindEvents",value:function(){var e=this;if(v){var t=this.props,n=t.element,r=t.events,i=t.passive,a=t.capture;this.eventsBound||(r.forEach((function(t){n.addEventListener(t,e.handleEvent,{capture:a,passive:i})})),this.eventsBound=!0)}}},{key:"_unbindEvents",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(v){var n=this.props,r=n.element,i=n.events,a=n.passive,o=n.capture;(this.eventsBound||t)&&(i.forEach((function(t){r.removeEventListener(t,e.handleEvent,{capture:o,passive:a})})),this.eventsBound=!1)}}},{key:"_toggleIdleState",value:function(e){var t=this;this.setState((function(e){return{idle:!e.idle,lastIdle:e.idle?e.lastIdle:+new Date-t.props.timeout,idleTime:e.idle?e.idleTime+ +new Date-e.lastIdle:e.idleTime}}),(function(){var n=t.props,r=n.onActive,i=n.onIdle,a=n.stopOnIdle;t.state.idle?(a&&(clearTimeout(t.tId),t.tId=null,t._unbindEvents()),t.manager?t.manager.idle():i(e)):(t._bindEvents(),t.manager?t.manager.active():r(e))}))}},{key:"_handleEvent",value:function(e){var t=this.state,n=t.remaining,r=t.pageX,i=t.pageY,a=t.idle,o=this.props,s=o.timeout,u=o.stopOnIdle;if(this._onAction(e),!n){if("mousemove"===e.type){if(e.pageX===r&&e.pageY===i)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(this.getElapsedTime()<200)return}clearTimeout(this.tId),this.tId=null;var c=+new Date-this.getLastActiveTime();(a&&!u||!a&&c>s)&&this._toggleIdleState(e),this.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),a&&u||(this.tId=setTimeout(this._toggleIdleState,s))}}},{key:"start",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.setState({idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null}),this.manager&&(this.manager.setAllIdle(!1),!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("start"));var t=this.props.timeout;this.tId=setTimeout(this._toggleIdleState,t)}},{key:"reset",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.state.idle&&this.props.onActive(),this.manager&&(this.state.idle&&this.manager.current.active(),this.manager.setAllIdle(!1),!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("reset")),this.setState({idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null});var t=this.props.timeout;this.tId=setTimeout(this._toggleIdleState,t)}},{key:"pause",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.state.remaining;null===t&&(this._unbindEvents(),clearTimeout(this.tId),this.tId=null,this.manager&&!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("pause"),this.setState({remaining:this.getRemainingTime()}))}},{key:"resume",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.state,n=t.remaining,r=t.idle;null!==n&&(this._bindEvents(),this.manager&&!e&&this.props.crossTab.emitOnAllTabs&&this.manager.send("resume"),r||(this.tId=setTimeout(this._toggleIdleState,n),this.setState({remaining:null,lastActive:+new Date})))}},{key:"getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.lastActive,r=this.props.timeout;if(null!==t)return t<0?0:t;var i=r-(+new Date-n);return i<0?0:i}},{key:"getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"getLastIdleTime",value:function(){return this.state.lastIdle}},{key:"getTotalIdleTime",value:function(){var e=this.state,t=e.idle,n=e.lastIdle,r=e.idleTime;return t?+new Date-n+r:r}},{key:"getLastActiveTime",value:function(){return this.state.lastActive}},{key:"getTotalActiveTime",value:function(){return this.getElapsedTime()-this.getTotalIdleTime()}},{key:"isIdle",value:function(){return this.state.idle}},{key:"isLeader",value:function(){return!this.manager||this.manager.isLeader()}}]),r}();function $(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.timeout,r=void 0===n?12e5:n,i=t.element,o=void 0===i?g:i,s=t.events,u=void 0===s?b:s,c=t.onIdle,l=void 0===c?function(){}:c,f=t.onActive,d=void 0===f?function(){}:f,h=t.onAction,p=void 0===h?function(){}:h,m=t.debounce,_=void 0===m?0:m,w=t.throttle,k=void 0===w?0:w,A=t.eventsThrottle,I=void 0===A?200:A,E=t.startOnMount,L=void 0===E||E,O=t.startManually,M=void 0!==O&&O,R=t.stopOnIdle,S=void 0!==R&&R,D=t.capture,P=void 0===D||D,x=t.passive,C=void 0===x||x,j=t.crossTab,B=void 0!==j&&j,N=e.useRef(!1),U=e.useRef(!0),X=e.useRef(+new Date),Y=e.useRef(null),F=e.useRef(null),V=e.useRef(null),J=e.useRef(null),W=e.useRef(null),$=e.useRef(null),z=e.useRef(0),G=e.useRef(!0),H=e.useRef(r),K=e.useRef(null);B&&(!0===B&&(B={}),B=Object.assign({channelName:"idle-timer",fallbackInterval:2e3,responseTime:100,removeTimeout:6e4,emitOnAllTabs:!1},B));var Q=e.useRef(l),Z=e.useRef(d),ee=e.useRef(p);e.useEffect((function(){Q.current=l}),[l]),e.useEffect((function(){Z.current=d}),[d]),e.useEffect((function(){ee.current=p}),[p]);var te=e.useMemo((function(){function e(e){ee.current(e)}return e.cancel&&e.cancel(),_>0?y(e,_):k>0?T(e,k):e}),[k,_]),ne=function(e){var t=!U.current;U.current=t,t?(S&&(clearTimeout(J.current),J.current=null,oe()),$.current=+new Date-H.current,K.current?K.current.idle():Q.current(e)):(z.current+=+new Date-$.current,ae(),K.current?K.current.active():Z.current(e))},re=function(e){if(te(e),!Y.current){if("mousemove"===e.type){if(e.pageX===F&&e.pageY===V)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(ue()<200)return}clearTimeout(J.current),J.current=null;var t=+new Date-fe();(U.current&&!S||!U.current&&t>H.current)&&ne(e),W.current=+new Date,F.current=e.pageX,V.current=e.pageY,U.current||(J.current=setTimeout(ne,H.current))}},ie=e.useRef(re),ae=function(){v&&(N.current||(u.forEach((function(e){o.addEventListener(e,ie.current,{capture:P,passive:C})})),N.current=!0))},oe=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];v&&(N.current||e)&&(u.forEach((function(e){o.removeEventListener(e,ie.current,{capture:P,passive:C})})),N.current=!1)},se=function(){if(null!==Y.current)return Y.current<0?0:Y.current;var e=H.current-(+new Date-W.current);return e<0?0:e},ue=function(){return+new Date-X.current},ce=function(){return $.current},le=function(){return U.current?+new Date-$.current+z.current:z.current},fe=function(){return W.current},de=function(){return ue()-le()},he=function(){return U.current},pe=function(){return!K.current||K.current.isLeader()},me=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout(J.current),J.current=null,ae(),U.current=!1,X.current=+new Date,W.current=+new Date,Y.current=null,K.current&&(K.current.setAllIdle(!1),!e&&B.emitOnAllTabs&&K.current.send("start")),J.current=setTimeout(ne,H.current)},ve=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];clearTimeout(J.current),J.current=null,ae(),U.current&&Z.current(),U.current=!1,X.current=+new Date,W.current=+new Date,Y.current=null,K.current&&(U.current&&K.current.active(),K.current.setAllIdle(!1),!e&&B.emitOnAllTabs&&K.current.send("reset")),J.current=setTimeout(ne,H.current)},ge=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];null===Y.current&&(oe(),clearTimeout(J.current),J.current=null,Y.current=se(),K.current&&!e&&B.emitOnAllTabs&&K.current.send("pause"))},be=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];null!==Y.current&&(ae(),U.current||(J.current=setTimeout(ne,Y.current),Y.current=null,W.current=+new Date),K.current&&!e&&B.emitOnAllTabs&&K.current.send("resume"))};return e.useEffect((function(){if(_>0&&k>0)throw new Error("onAction can either be throttled or debounced (not both)");return B&&(K.current=q({type:B.type,channelName:B.channelName,fallbackInterval:B.fallbackInterval,responseTime:B.responseTime,emitOnAllTabs:B.emitOnAllTabs,callbacks:{onIdle:Q.current,onActive:Z.current},start:me,reset:ve,pause:ge,resume:be})),M?a(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(clearTimeout(J.current),oe(!0),!B){e.next=5;break}return e.next=5,K.current.close();case 5:case"end":return e.stop()}}),e)}))):(L?me():ae(),a(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(clearTimeout(J.current),oe(!0),te.cancel&&te.cancel(),!B){e.next=6;break}return e.next=6,K.current.close();case 6:case"end":return e.stop()}}),e)}))))}),[]),e.useEffect((function(){var e=N.current;e&&oe(),ie.current=I>0?T(re,I):re,e&&ae()}),[I]),e.useEffect((function(){H.current=r,!G.current&&U.current&&ve(),G.current=!1}),[r]),{isIdle:he,isLeader:pe,start:me,pause:ge,reset:ve,resume:be,getLastIdleTime:ce,getTotalIdleTime:le,getLastActiveTime:fe,getTotalActiveTime:de,getElapsedTime:ue,getRemainingTime:se}}W.propTypes={timeout:n.default.number,events:n.default.arrayOf(n.default.string),onIdle:n.default.func,onActive:n.default.func,onAction:n.default.func,debounce:n.default.number,throttle:n.default.number,eventsThrottle:n.default.number,element:n.default.oneOfType([n.default.object,n.default.element]),startOnMount:n.default.bool,startManually:n.default.bool,stopOnIdle:n.default.bool,passive:n.default.bool,capture:n.default.bool,crossTab:n.default.oneOfType([n.default.bool,n.default.shape({type:n.default.oneOf(["broadcastChannel","localStorage","simulate"]),channelName:n.default.string,fallbackInterval:n.default.number,responseTime:n.default.number,removeTimeout:n.default.number,emitOnAllTabs:n.default.bool})])},W.defaultProps={timeout:12e5,element:g,events:b,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,eventsThrottle:200,startOnMount:!0,startManually:!1,stopOnIdle:!1,capture:!0,passive:!0,crossTab:!1},$.propTypes={timeout:n.default.number,events:n.default.arrayOf(n.default.string),onIdle:n.default.func,onActive:n.default.func,onAction:n.default.func,debounce:n.default.number,throttle:n.default.number,eventsThrottle:n.default.number,element:n.default.oneOfType([n.default.object,n.default.element]),startOnMount:n.default.bool,startManually:n.default.bool,stopOnIdle:n.default.bool,passive:n.default.bool,capture:n.default.bool,crossTab:n.default.oneOfType([n.default.bool,n.default.shape({type:n.default.oneOf(["broadcastChannel","localStorage","simulate"]),channelName:n.default.string,fallbackInterval:n.default.number,responseTime:n.default.number,removeTimeout:n.default.number,emitOnAllTabs:n.default.bool})])},$.defaultProps={timeout:12e5,element:g,events:b,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,eventsThrottle:200,startOnMount:!0,startManually:!1,stopOnIdle:!1,capture:!0,passive:!0,crossTab:!1},exports.default=W,exports.useIdleTimer=$; | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "react-idle-timer", | ||
"version": "4.6.2", | ||
"version": "4.6.3-rc.1", | ||
"description": "Activity detection for React.js", | ||
@@ -49,22 +49,20 @@ "main": "./dist/index.min.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.13.15", | ||
"@babel/plugin-transform-runtime": "^7.13.15", | ||
"@babel/preset-env": "^7.13.15", | ||
"@babel/core": "^7.14.3", | ||
"@babel/preset-env": "^7.14.2", | ||
"@babel/preset-react": "^7.13.13", | ||
"@babel/runtime": "^7.13.10", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-commonjs": "^18.0.0", | ||
"@rollup/plugin-node-resolve": "^11.2.1", | ||
"@testing-library/react-hooks": "^5.1.1", | ||
"@rollup/plugin-commonjs": "^19.0.0", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"@testing-library/react-hooks": "^6.0.0", | ||
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.1", | ||
"babel-jest": "^26.6.3", | ||
"enzyme": "^3.11.0", | ||
"enzyme-adapter-react-16": "^1.15.6", | ||
"jest": "^26.6.3", | ||
"jest-esm-transformer": "^1.0.0", | ||
"prompt-list": "^3.2.0", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"regenerator-runtime": "^0.13.7", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.45.2", | ||
"rollup": "^2.48.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
@@ -78,5 +76,2 @@ "simulant": "^0.2.2", | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-transform-runtime" | ||
] | ||
@@ -83,0 +78,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
21
-8.7%0
-100%269004
-27.1%543
-6.86%3
50%