UNPKG

@karltud123/react-idle-timer

Version:
2 lines (1 loc) 30.4 kB
var br=Object.create;var De=Object.defineProperty;var Tr=Object.getOwnPropertyDescriptor;var Er=Object.getOwnPropertyNames;var Ir=Object.getPrototypeOf,xr=Object.prototype.hasOwnProperty;var Or=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}},Sr=function(e,r){for(var t in r)De(e,t,{get:r[t],enumerable:!0})},kt=function(e,r,t,o){if(r&&typeof r=="object"||typeof r=="function")for(var n=Er(r),f=0,c=n.length,u;f<c;f++)u=n[f],!xr.call(e,u)&&u!==t&&De(e,u,{get:function(m){return r[m]}.bind(null,u),enumerable:!(o=Tr(r,u))||o.enumerable});return e};var Ze=function(e,r,t){return t=e!=null?br(Ir(e)):{},kt(r||!e||!e.__esModule?De(t,"default",{value:e,enumerable:!0}):t,e)},Lr=function(e){return kt(De({},"__esModule",{value:!0}),e)};var Gt=Or(function(Ve,Vt){(function(e,r){typeof Ve=="object"&&typeof Vt!="undefined"?r(Ve):typeof define=="function"&&define.amd?define(["exports"],r):(e=typeof globalThis!="undefined"?globalThis:e||self,r(e.fastUniqueNumbers={}))})(Ve,function(e){"use strict";var r=function(E){return function(x){var v=E(x);return x.add(v),v}},t=function(E){return function(x,v){return E.set(x,v),v}},o=Number.MAX_SAFE_INTEGER===void 0?9007199254740991:Number.MAX_SAFE_INTEGER,n=536870912,f=n*2,c=function(E,x){return function(v){var D=x.get(v),b=D===void 0?v.size:D<f?D+1:0;if(!v.has(b))return E(v,b);if(v.size<n){for(;v.has(b);)b=Math.floor(Math.random()*f);return E(v,b)}if(v.size>o)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;v.has(b);)b=Math.floor(Math.random()*o);return E(v,b)}},u=new WeakMap,m=t(u),p=c(m,u),s=r(p);e.addUniqueNumber=s,e.generateUniqueNumber=p})});var Rr={};Sr(Rr,{DEFAULT_EVENTS:function(){return We},IdleTimerComponent:function(){return Ct},IdleTimerConsumer:function(){return sr},IdleTimerContext:function(){return Oe},IdleTimerProvider:function(){return ur},createMocks:function(){return Kt},useIdleTimer:function(){return se},useIdleTimerContext:function(){return cr},withIdleTimer:function(){return Mt},workerTimers:function(){return fe}});module.exports=Lr(Rr);function q(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Ne(e,r){return r!=null&&typeof Symbol!="undefined"&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](e):Ne(e,r)}function W(e,r){if(!Ne(e,r))throw new TypeError("Cannot call a class as a function")}function Ue(e,r){return Ue=Object.setPrototypeOf||function(o,n){return o.__proto__=n,o},Ue(e,r)}function et(e,r){if(typeof r!="function"&&r!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&Ue(e,r)}function h(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function tt(e){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{},o=Object.keys(t);typeof Object.getOwnPropertySymbols=="function"&&(o=o.concat(Object.getOwnPropertySymbols(t).filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable}))),o.forEach(function(n){h(e,n,t[n])})}return e}function Ee(e){return Ee=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},Ee(e)}function At(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function Be(e){"@swc/helpers - typeof";return e&&typeof Symbol!="undefined"&&e.constructor===Symbol?"symbol":typeof e}function Rt(e,r){return r&&(Be(r)==="object"||typeof r=="function")?r:q(e)}function rt(e){var r=At();return function(){var o=Ee(e),n;if(r){var f=Ee(this).constructor;n=Reflect.construct(o,arguments,f)}else n=o.apply(this,arguments);return Rt(this,n)}}var ue=Ze(require("react"));function Mt(e){return(0,ue.forwardRef)(function(t,o){var n=tt({},t),f=se(n);return typeof o=="function"?o(f):o&&(o.current=f),ue.default.createElement(e,tt({},t,f))})}var Pr=function(e){"use strict";et(t,e);var r=rt(t);function t(){return W(this,t),r.apply(this,arguments)}return t}(ue.Component),Ct=function(e){"use strict";et(t,e);var r=rt(t);function t(o){W(this,t);var n;return n=r.call(this,o),n.onPresenceChange&&o.setOnPresenceChange(n.onPresenceChange.bind(q(n))),n.onPrompt&&o.setOnPrompt(n.onPrompt.bind(q(n))),n.onIdle&&o.setOnIdle(n.onIdle.bind(q(n))),n.onActive&&o.setOnActive(n.onActive.bind(q(n))),n.onAction&&o.setOnAction(n.onAction.bind(q(n))),n.onMessage&&o.setOnMessage(n.onMessage.bind(q(n))),n}return t}(Pr);function Ie(e,r){(r==null||r>e.length)&&(r=e.length);for(var t=0,o=new Array(r);t<r;t++)o[t]=e[t];return o}function jt(e){if(Array.isArray(e))return Ie(e)}function Dt(e){if(typeof Symbol!="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Nt(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function Ut(e,r){if(e){if(typeof e=="string")return Ie(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor&&(t=e.constructor.name),t==="Map"||t==="Set")return Array.from(t);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return Ie(e,r)}}function I(e){return jt(e)||Dt(e)||Ut(e)||Nt()}var a=require("react");function Bt(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function ce(e,r,t){return r&&Bt(e.prototype,r),t&&Bt(e,t),e}var xe=Ze(Gt());var Ft=function(e){return e.method!==void 0&&e.method==="call"};var qt=function(e){return e.error===null&&typeof e.id=="number"};var Wt=function(e){var r=new Map([[0,function(){}]]),t=new Map([[0,function(){}]]),o=new Map,n=new Worker(e);n.addEventListener("message",function(p){var s=p.data;if(Ft(s)){var _=s.params,E=_.timerId,x=_.timerType;if(x==="interval"){var v=r.get(E);if(typeof v=="number"){var D=o.get(v);if(D===void 0||D.timerId!==E||D.timerType!==x)throw new Error("The timer is in an undefined state.")}else if(typeof v!="undefined")v();else throw new Error("The timer is in an undefined state.")}else if(x==="timeout"){var b=t.get(E);if(typeof b=="number"){var ee=o.get(b);if(ee===void 0||ee.timerId!==E||ee.timerType!==x)throw new Error("The timer is in an undefined state.")}else if(typeof b!="undefined")b(),t.delete(E);else throw new Error("The timer is in an undefined state.")}}else if(qt(s)){var J=s.id,te=o.get(J);if(te===void 0)throw new Error("The timer is in an undefined state.");var H=te.timerId,Se=te.timerType;o.delete(J),Se==="interval"?r.delete(H):t.delete(H)}else{var re=s.error.message;throw new Error(re)}});var f=function(p){var s=(0,xe.generateUniqueNumber)(o);o.set(s,{timerId:p,timerType:"interval"}),r.set(p,s),n.postMessage({id:s,method:"clear",params:{timerId:p,timerType:"interval"}})},c=function(p){var s=(0,xe.generateUniqueNumber)(o);o.set(s,{timerId:p,timerType:"timeout"}),t.set(p,s),n.postMessage({id:s,method:"clear",params:{timerId:p,timerType:"timeout"}})},u=function(p,s){var _=(0,xe.generateUniqueNumber)(r);return r.set(_,function(){p(),typeof r.get(_)=="function"&&n.postMessage({id:null,method:"set",params:{delay:s,now:performance.now(),timerId:_,timerType:"interval"}})}),n.postMessage({id:null,method:"set",params:{delay:s,now:performance.now(),timerId:_,timerType:"interval"}}),_},m=function(p,s){var _=(0,xe.generateUniqueNumber)(t);return t.set(_,p),n.postMessage({id:null,method:"set",params:{delay:s,now:performance.now(),timerId:_,timerType:"timeout"}}),_};return{clearInterval:f,clearTimeout:c,setInterval:u,setTimeout:m}};var Yt=function(e,r){var t=null;return function(){if(t!==null)return t;var o=new Blob([r],{type:"application/javascript; charset=utf-8"}),n=URL.createObjectURL(o);return t=e(n),setTimeout(function(){return URL.revokeObjectURL(n)}),t}};var zt='(()=>{"use strict";const e=new Map,t=new Map,r=(e,t)=>{let r,o;const i=performance.now();r=i,o=e-Math.max(0,i-t);return{expected:r+o,remainingDelay:o}},o=(e,t,r,i)=>{const s=performance.now();s>r?postMessage({id:null,method:"call",params:{timerId:t,timerType:i}}):e.set(t,setTimeout(o,r-s,e,t,r,i))};addEventListener("message",(i=>{let{data:s}=i;try{if("clear"===s.method){const{id:r,params:{timerId:o,timerType:i}}=s;if("interval"===i)(t=>{const r=e.get(t);if(void 0===r)throw new Error(\'There is no interval scheduled with the given id "\'.concat(t,\'".\'));clearTimeout(r),e.delete(t)})(o),postMessage({error:null,id:r});else{if("timeout"!==i)throw new Error(\'The given type "\'.concat(i,\'" is not supported\'));(e=>{const r=t.get(e);if(void 0===r)throw new Error(\'There is no timeout scheduled with the given id "\'.concat(e,\'".\'));clearTimeout(r),t.delete(e)})(o),postMessage({error:null,id:r})}}else{if("set"!==s.method)throw new Error(\'The given method "\'.concat(s.method,\'" is not supported\'));{const{params:{delay:i,now:n,timerId:a,timerType:d}}=s;if("interval"===d)((t,i,s)=>{const{expected:n,remainingDelay:a}=r(t,s);e.set(i,setTimeout(o,a,e,i,n,"interval"))})(i,a,n);else{if("timeout"!==d)throw new Error(\'The given type "\'.concat(d,\'" is not supported\'));((e,i,s)=>{const{expected:n,remainingDelay:a}=r(e,s);t.set(i,setTimeout(o,a,t,i,n,"timeout"))})(i,a,n)}}}}catch(e){postMessage({error:{message:e.message},id:s.id,result:null})}}))})();';var Ge=Yt(Wt,zt),Jt=function(e){return Ge().clearInterval(e)},Ht=function(e){return Ge().clearTimeout(e)},Xt=function(e,r){return Ge().setInterval(e,r)},$t=function(e,r){return Ge().setTimeout(e,r)};var A=(typeof window=="undefined"||typeof window=="undefined"?"undefined":Be(window))==="object";var w={setTimeout:A?setTimeout.bind(window):setTimeout,clearTimeout:A?clearTimeout.bind(window):clearTimeout,setInterval:A?setInterval.bind(window):setInterval,clearInterval:A?clearInterval.bind(window):clearInterval},fe={setTimeout:$t,clearTimeout:Ht,setInterval:Xt,clearInterval:Jt};function Kt(){w.setTimeout=setTimeout,w.clearTimeout=clearTimeout,w.setInterval=setInterval,w.clearInterval=clearInterval,fe.setTimeout=setTimeout,fe.clearTimeout=clearTimeout,fe.setInterval=setInterval,fe.clearInterval=clearInterval}function Qt(e){w.setTimeout=e.setTimeout,w.clearTimeout=e.clearTimeout,w.setInterval=e.setInterval,w.clearInterval=e.clearInterval}var le={},Ar=function(){"use strict";function e(r){W(this,e),h(this,"name",void 0),h(this,"closed",!1),h(this,"mc",new MessageChannel),this.name=r,le[r]=le[r]||[],le[r].push(this),this.mc.port1.start(),this.mc.port2.start(),this.onStorage=this.onStorage.bind(this),window.addEventListener("storage",this.onStorage)}return ce(e,[{key:"onStorage",value:function(t){if(t.storageArea===window.localStorage&&t.key.substring(0,this.name.length)===this.name&&t.newValue!==null){var o=JSON.parse(t.newValue);this.mc.port2.postMessage(o)}}},{key:"postMessage",value:function(t){var o=this;if(this.closed)throw new Error("InvalidStateError");var n=JSON.stringify(t),f="".concat(this.name,":").concat(String(Date.now())).concat(String(Math.random()));window.localStorage.setItem(f,n),w.setTimeout(function(){window.localStorage.removeItem(f)},500),le[this.name].forEach(function(c){c!==o&&c.mc.port2.postMessage(JSON.parse(n))})}},{key:"close",value:function(){if(!this.closed){this.closed=!0,this.mc.port1.close(),this.mc.port2.close(),window.removeEventListener("storage",this.onStorage);var t=le[this.name].indexOf(this);le[this.name].splice(t,1)}}},{key:"onmessage",get:function(){return this.mc.port1.onmessage},set:function(t){this.mc.port1.onmessage=t}},{key:"onmessageerror",get:function(){return this.mc.port1.onmessageerror},set:function(t){this.mc.port1.onmessageerror=t}},{key:"addEventListener",value:function(t,o){return this.mc.port1.addEventListener(t,o)}},{key:"removeEventListener",value:function(t,o){return this.mc.port1.removeEventListener(t,o)}},{key:"dispatchEvent",value:function(t){return this.mc.port1.dispatchEvent(t)}}]),e}(),Zt=typeof window=="undefined"?void 0:typeof window.BroadcastChannel=="function"?window.BroadcastChannel:Ar;function er(e,r,t,o,n,f,c){try{var u=e[f](c),m=u.value}catch(p){t(p);return}u.done?r(m):Promise.resolve(m).then(o,n)}function tr(e){return function(){var r=this,t=arguments;return new Promise(function(o,n){var f=e.apply(r,t);function c(m){er(f,o,n,c,u,"next",m)}function u(m){er(f,o,n,c,u,"throw",m)}c(void 0)})}}function Fe(e,r){var t=function(s){return function(_){return o([s,_])}},o=function(s){if(f)throw new TypeError("Generator is already executing.");for(;m&&(m=0,s[0]&&(n=0)),n;)try{if(f=1,c&&(u=s[0]&2?c.return:s[0]?c.throw||((u=c.return)&&u.call(c),0):c.next)&&!(u=u.call(c,s[1])).done)return u;switch(c=0,u&&(s=[s[0]&2,u.value]),s[0]){case 0:case 1:u=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,c=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if(u=n.trys,!(u=u.length>0&&u[u.length-1])&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!u||s[1]>u[0]&&s[1]<u[3])){n.label=s[1];break}if(s[0]===6&&n.label<u[1]){n.label=u[1],u=s;break}if(u&&n.label<u[2]){n.label=u[2],n.ops.push(s);break}u[2]&&n.ops.pop(),n.trys.pop();continue}s=r.call(e,n)}catch(_){s=[6,_],c=0}finally{f=u=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}},n={label:0,sent:function(){if(u[0]&1)throw u[1];return u[1]},trys:[],ops:[]},f,c,u,m;return m={next:t(0),throw:t(1),return:t(2)},typeof Symbol=="function"&&(m[Symbol.iterator]=function(){return this}),m}function rr(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return new Promise(function(r){return w.setTimeout(r,e)})}function qe(){return Math.random().toString(36).substring(2)}var d;(function(e){e[e.APPLY=0]="APPLY",e[e.TELL=1]="TELL",e[e.CLOSE=2]="CLOSE",e[e.REGISTER=3]="REGISTER",e[e.DEREGISTER=4]="DEREGISTER",e[e.IDLE=5]="IDLE",e[e.ACTIVE=6]="ACTIVE",e[e.PROMPT=7]="PROMPT",e[e.START=8]="START",e[e.RESET=9]="RESET",e[e.ACTIVATE=10]="ACTIVATE",e[e.PAUSE=11]="PAUSE",e[e.RESUME=12]="RESUME",e[e.MESSAGE=13]="MESSAGE"})(d||(d={}));var nr=function(){"use strict";function e(r,t){W(this,e),h(this,"options",void 0),h(this,"channel",void 0),h(this,"token",qe()),h(this,"isLeader",!1),h(this,"isDead",!1),h(this,"isApplying",!1),h(this,"reApply",!1),h(this,"intervals",[]),h(this,"listeners",[]),h(this,"deferred",void 0),this.channel=r,this.options=t,this.apply=this.apply.bind(this),this.awaitLeadership=this.awaitLeadership.bind(this),this.sendAction=this.sendAction.bind(this)}return ce(e,[{key:"apply",value:function(){var t=this;return tr(function(){var o,n,f;return Fe(this,function(c){switch(c.label){case 0:if(t.isLeader)return[2,!1];if(t.isDead)return[2,!1];if(t.isApplying)return t.reApply=!0,[2,!1];t.isApplying=!0,o=!1,n=function(u){var m=u.data,p=m.token,s=m.action;p!==t.token&&(s===d.APPLY&&p>t.token&&(o=!0),s===d.TELL&&(o=!0))},t.channel.addEventListener("message",n),c.label=1;case 1:return c.trys.push([1,3,,4]),t.sendAction(d.APPLY),[4,rr(t.options.responseTime)];case 2:return c.sent(),t.channel.removeEventListener("message",n),t.isApplying=!1,o?t.reApply?[2,t.apply()]:[2,!1]:(t.assumeLead(),[2,!0]);case 3:return f=c.sent(),[2,!1];case 4:return[2]}})})()}},{key:"awaitLeadership",value:function(){var t=this;if(this.isLeader)return Promise.resolve();var o=!1,n=null;return new Promise(function(f){var c=function(){if(!o){o=!0;try{w.clearInterval(n)}catch(p){}var m=t.intervals.indexOf(n);m>=0&&t.intervals.splice(m,1),t.channel.removeEventListener("message",u),f()}};n=w.setInterval(function(){t.apply().then(function(){t.isLeader&&c()})},t.options.fallbackInterval),t.intervals.push(n);var u=function(m){var p=m.data.action;p===d.CLOSE&&t.apply().then(function(){t.isLeader&&c()})};t.channel.addEventListener("message",u)})}},{key:"sendAction",value:function(t){this.channel.postMessage({action:t,token:this.token})}},{key:"assumeLead",value:function(){var t=this;this.isLeader=!0;var o=function(n){var f=n.data.action;f===d.APPLY&&t.sendAction(d.TELL)};return this.channel.addEventListener("message",o),this.listeners.push(o),this.sendAction(d.TELL)}},{key:"waitForLeadership",value:function(){return this.deferred?this.deferred:(this.deferred=this.awaitLeadership(),this.deferred)}},{key:"close",value:function(){var t=this;if(!this.isDead){this.isDead=!0,this.isLeader=!1,this.sendAction(d.CLOSE);try{this.listeners.forEach(function(o){return t.channel.removeEventListener("message",o)}),this.intervals.forEach(function(o){return w.clearInterval(o)})}catch(o){}}}}]),e}();var P;(function(e){e[e.PROMPTED=0]="PROMPTED",e[e.ACTIVE=1]="ACTIVE",e[e.IDLE=2]="IDLE"})(P||(P={}));var or=function(){"use strict";function e(r){var t=this;W(this,e),h(this,"channel",void 0),h(this,"options",void 0),h(this,"elector",void 0),h(this,"token",qe()),h(this,"registry",new Map),h(this,"allIdle",!1),h(this,"isLastActive",!1);var o=r.channelName;if(this.options=r,this.channel=new Zt(o),this.registry.set(this.token,P.ACTIVE),r.leaderElection){var n={fallbackInterval:2e3,responseTime:100};this.elector=new nr(this.channel,n),this.elector.waitForLeadership()}this.channel.addEventListener("message",function(f){var c=f.data,u=c.action,m=c.token,p=c.data;switch(u){case d.REGISTER:t.registry.set(m,P.IDLE);break;case d.DEREGISTER:t.registry.delete(m);break;case d.IDLE:t.idle(m);break;case d.ACTIVE:t.active(m);break;case d.PROMPT:t.prompt(m);break;case d.START:t.start(m);break;case d.RESET:t.reset(m);break;case d.ACTIVATE:t.activate(m);break;case d.PAUSE:t.pause(m);break;case d.RESUME:t.resume(m);break;case d.MESSAGE:t.options.onMessage(p);break}}),this.send(d.REGISTER)}return ce(e,[{key:"isLeader",get:function(){if(!this.elector)throw new Error('\u274C Leader election is not enabled. To Enable it set the "leaderElection" property to true.');return this.elector.isLeader}},{key:"prompt",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.registry.set(t,P.PROMPTED);var o=I(this.registry.values()).every(function(n){return n===P.PROMPTED});t===this.token&&this.send(d.PROMPT),o&&this.options.onPrompt()}},{key:"idle",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.registry.set(t,P.IDLE);var o=I(this.registry.values()).every(function(n){return n===P.IDLE});t===this.token&&this.send(d.IDLE),!this.allIdle&&o&&(this.allIdle=!0,this.options.onIdle())}},{key:"active",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.allIdle=!1,this.registry.set(t,P.ACTIVE);var o=I(this.registry.values()).some(function(n){return n===P.ACTIVE});t===this.token&&this.send(d.ACTIVE),o&&this.options.onActive(),this.isLastActive=t===this.token}},{key:"start",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.allIdle=!1,this.registry.set(t,P.ACTIVE),t===this.token?this.send(d.START):this.options.start(!0),this.isLastActive=t===this.token}},{key:"reset",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.allIdle=!1,this.registry.set(t,P.ACTIVE),t===this.token?this.send(d.RESET):this.options.reset(!0),this.isLastActive=t===this.token}},{key:"activate",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.allIdle=!1,this.registry.set(t,P.ACTIVE),t===this.token?this.send(d.ACTIVATE):this.options.activate(!0),this.isLastActive=t===this.token}},{key:"pause",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;t===this.token?this.send(d.PAUSE):this.options.pause(!0)}},{key:"resume",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;t===this.token?this.send(d.RESUME):this.options.resume(!0)}},{key:"message",value:function(t){try{this.channel.postMessage({action:d.MESSAGE,token:this.token,data:t})}catch(o){}}},{key:"send",value:function(t){try{this.channel.postMessage({action:t,token:this.token})}catch(o){}}},{key:"close",value:function(){this.options.leaderElection&&this.elector.close(),this.send(d.DEREGISTER),this.channel.close()}}]),e}();var ir=A?document:null,We=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange","focus"];function ar(e,r){var t=function(){for(var f=arguments.length,c=new Array(f),u=0;u<f;u++)c[u]=arguments[u];o&&clearTimeout(o),o=setTimeout(function(){e.apply(void 0,I(c)),o=null},r)},o;return t.cancel=function(){clearTimeout(o)},t}function Ye(e,r){var t=0;return function(){for(var o=arguments.length,n=new Array(o),f=0;f<o;f++)n[f]=arguments[f];var c=new Date().getTime();if(!(c-t<r))return t=c,e.apply(void 0,I(n))}}var g=function(){return Date.now()};var me=2147483647;function se(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=e.timeout,t=r===void 0?1e3*60*20:r,o=e.promptTimeout,n=o===void 0?0:o,f=e.promptBeforeIdle,c=f===void 0?0:f,u=e.element,m=u===void 0?ir:u,p=e.events,s=p===void 0?We:p,_=e.timers,E=_===void 0?void 0:_,x=e.immediateEvents,v=x===void 0?[]:x,D=e.onPresenceChange,b=D===void 0?function(){}:D,ee=e.onPrompt,J=ee===void 0?function(){}:ee,te=e.onIdle,H=te===void 0?function(){}:te,Se=e.onActive,re=Se===void 0?function(){}:Se,nt=e.onAction,Le=nt===void 0?function(){}:nt,ot=e.onMessage,pe=ot===void 0?function(){}:ot,it=e.debounce,ve=it===void 0?0:it,at=e.throttle,he=at===void 0?0:at,ut=e.eventsThrottle,ze=ut===void 0?200:ut,st=e.startOnMount,_e=st===void 0?!0:st,ct=e.startManually,U=ct===void 0?!1:ct,ft=e.stopOnIdle,Pe=ft===void 0?!1:ft,lt=e.crossTab,ne=lt===void 0?!1:lt,mt=e.name,dt=mt===void 0?"idle-timer":mt,pt=e.syncTimers,ye=pt===void 0?0:pt,vt=e.leaderElection,ht=vt===void 0?!1:vt,_t=e.disabled,N=_t===void 0?!1:_t,yt=(0,a.useRef)(g()),ke=(0,a.useRef)(g()),O=(0,a.useRef)(null),R=(0,a.useRef)(null),Y=(0,a.useRef)(0),ge=(0,a.useRef)(0),B=(0,a.useRef)(0),k=(0,a.useRef)(0),y=(0,a.useRef)(!1),T=(0,a.useRef)(!1),V=(0,a.useRef)(!1),G=(0,a.useRef)(!0),we=(0,a.useRef)(!1),F=(0,a.useRef)(null),l=(0,a.useRef)(null),M=(0,a.useRef)(t),X=(0,a.useRef)(0);(0,a.useEffect)(function(){if(n&&console.warn("\u26A0\uFE0F IdleTimer -- The `promptTimeout` property has been deprecated in favor of `promptBeforeIdle`. It will be removed in the next major release."),c&&n)throw new Error("\u274C Both promptTimeout and promptBeforeIdle can not be set. The promptTimeout property will be deprecated in a future version.");if(t>=me)throw new Error("\u274C The value for the timeout property must fit in a 32 bit signed integer, ".concat(me,"."));if(n>=me)throw new Error("\u274C The value for the promptTimeout property must fit in a 32 bit signed integer, ".concat(me,"."));if(c>=me)throw new Error("\u274C The value for the promptBeforeIdle property must fit in a 32 bit signed integer, ".concat(me,"."));if(c>=t)throw new Error("\u274C The value for the promptBeforeIdle property must be less than the timeout property, ".concat(t,"."));if(c?(M.current=t-c,X.current=c):(M.current=t,X.current=n),!G.current){if(U||N)return;y.current&&(oe.current(null,L),l.current&&l.current.active()),Z()}},[t,n,c,U,N]);var gt=(0,a.useRef)(Pe);(0,a.useEffect)(function(){gt.current=Pe},[Pe]);var wt=(0,a.useRef)(v),be=(0,a.useRef)(m),Je=(0,a.useRef)(I(new Set(I(s).concat(I(v))).values())),C=(0,a.useRef)(N);(0,a.useEffect)(function(){C.current=N,!G.current&&(N?je():U||Z())},[N]);var Te=(0,a.useRef)(b);(0,a.useEffect)(function(){Te.current=b},[b]);var Ae=(0,a.useRef)(J);(0,a.useEffect)(function(){Ae.current=J},[J]);var Re=(0,a.useRef)(H);(0,a.useEffect)(function(){Re.current=H},[H]);var oe=(0,a.useRef)(re);(0,a.useEffect)(function(){oe.current=re},[re]);var Me=(0,a.useRef)(Le);(0,a.useEffect)(function(){Me.current=Le},[Le]);var ie=(0,a.useRef)(pe);(0,a.useEffect)(function(){ie.current=pe},[pe]);var $=(0,a.useMemo)(function(){var i=function(S,ae){return Me.current(S,ae)};return ve>0?ar(i,ve):he>0?Ye(i,he):i},[he,ve]),bt=(0,a.useRef)();(0,a.useEffect)(function(){ne&&ye&&(bt.current=Ye(function(){l.current.active()},ye))},[ne,ye]);var j=function(){F.current!==null&&(w.clearTimeout(F.current),F.current=null)},K=function(i){var S=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0;j(),F.current=w.setTimeout(Xe,i||M.current),S&&(R.current=g())},Tt=function(i){!T.current&&!y.current&&(Ae.current(i,L),Te.current({type:"active",prompted:!0},L)),k.current=0,B.current=g(),T.current=!0,K(X.current,!1)},Et=function(){j(),y.current||(Re.current(null,L),Te.current({type:"idle"},L)),y.current=!0,O.current=g(),gt.current?Q():T.current&&(B.current=0,T.current=!1)},He=function(i){j(),(y.current||T.current)&&(oe.current(i,L),Te.current({type:"active",prompted:!1},L)),T.current=!1,B.current=0,y.current=!1,Y.current+=g()-O.current,ge.current+=g()-O.current,z(),K()},Xe=function(i){var S=!y.current;if(S){$.cancel&&$.cancel();var ae=g()-R.current,wr=M.current+X.current<ae;if(!wr&&X.current>0&&!T.current){l.current?l.current.prompt():Tt(i);return}l.current?l.current.idle():Et();return}l.current?l.current.active():He(i)},$e=function(i){if(!_e&&!R.current&&(R.current=g(),oe.current(null,L)),$(i,L),!T.current){if(j(),!y.current&&wt.current.includes(i.type)){Xe(i);return}var S=g()-R.current;if(y.current&&!Pe||!y.current&&S>=M.current){Xe(i);return}V.current=!1,k.current=0,B.current=0,K(),ne&&ye&&bt.current()}},Ce=(0,a.useRef)($e);(0,a.useEffect)(function(){var i=we.current;i&&Q(),ze>0?Ce.current=Ye($e,ze):Ce.current=$e,i&&z()},[ze,he,ve,Me,ne,ye]);var z=function(){A&&be.current&&(we.current||(Je.current.forEach(function(i){be.current.addEventListener(i,Ce.current,{capture:!0,passive:!0})}),we.current=!0))},Q=function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;A&&be.current&&(we.current||i)&&(Je.current.forEach(function(S){be.current.removeEventListener(S,Ce.current,{capture:!0})}),we.current=!1)},Z=(0,a.useCallback)(function(i){return C.current?!1:(j(),z(),y.current=!1,T.current=!1,V.current=!1,k.current=0,B.current=0,l.current&&!i&&l.current.start(),K(),!0)},[F,y,C,M,l]),Ke=(0,a.useCallback)(function(i){return C.current?!1:(j(),z(),ke.current=g(),Y.current+=g()-O.current,ge.current+=g()-O.current,Y.current=0,y.current=!1,T.current=!1,V.current=!1,k.current=0,B.current=0,l.current&&!i&&l.current.reset(),U||K(),!0)},[F,y,M,U,C,l]),It=(0,a.useCallback)(function(i){return C.current?!1:(j(),z(),(y.current||T.current)&&He(),y.current=!1,T.current=!1,V.current=!1,k.current=0,B.current=0,ke.current=g(),l.current&&!i&&l.current.activate(),K(),!0)},[F,y,T,C,M,l]),je=(0,a.useCallback)(function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;return C.current||V.current?!1:(k.current=xt(),V.current=!0,Q(),j(),l.current&&!i&&l.current.pause(),!0)},[F,C,l]),Qe=(0,a.useCallback)(function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;return C.current||!V.current?!1:(V.current=!1,T.current||z(),y.current||K(k.current),B.current&&(B.current=g()),l.current&&!i&&l.current.resume(),!0)},[F,M,C,k,l]),fr=(0,a.useCallback)(function(i,S){return l.current?(S&&ie.current(i,L),l.current.message(i)):S&&ie.current(i,L),!0},[pe]),lr=(0,a.useCallback)(function(){return y.current},[y]),mr=(0,a.useCallback)(function(){return T.current},[T]),dr=(0,a.useCallback)(function(){return l.current?l.current.isLeader:null},[l]),pr=(0,a.useCallback)(function(){return l.current?l.current.isLastActive:null},[l]),vr=(0,a.useCallback)(function(){return l.current?l.current.token:null},[l]),xt=(0,a.useCallback)(function(){if(V.current)return k.current;var i=k.current?k.current:X.current+M.current,S=R.current?g()-R.current:0,ae=Math.floor(i-S);return ae<0?0:Math.abs(ae)},[M,X,T,k,R]),Ot=(0,a.useCallback)(function(){return Math.round(g()-ke.current)},[ke]),St=(0,a.useCallback)(function(){return Math.round(g()-yt.current)},[yt]),hr=(0,a.useCallback)(function(){return O.current?new Date(O.current):null},[O]),_r=(0,a.useCallback)(function(){return R.current?new Date(R.current):null},[R]),Lt=(0,a.useCallback)(function(){return y.current?Math.round(g()-O.current+Y.current):Math.round(Y.current)},[O,Y]),Pt=(0,a.useCallback)(function(){return y.current?Math.round(g()-O.current+ge.current):Math.round(ge.current)},[O,ge]),yr=(0,a.useCallback)(function(){var i=Math.round(Ot()-Lt());return i>=0?i:0},[O,Y]),gr=(0,a.useCallback)(function(){var i=Math.round(St()-Pt());return i>=0?i:0},[O,Y]);(0,a.useEffect)(function(){if(ve>0&&he>0)throw new Error("\u274C onAction can either be throttled or debounced, not both.");E&&Qt(E);var i=function(){l.current&&l.current.close(),$.cancel&&$.cancel(),j(),Q(!0)};return A&&window.addEventListener("beforeunload",i),function(){A&&window.removeEventListener("beforeunload",i),l.current&&l.current.close(),$.cancel&&$.cancel(),j(),Q(!0)}},[]),(0,a.useEffect)(function(){l.current&&l.current.close(),ne?l.current=new or({channelName:dt,leaderElection:ht,onPrompt:function(){Tt()},onIdle:function(){Et()},onActive:function(){He()},onMessage:function(i){ie.current(i,L)},start:Z,reset:Ke,activate:It,pause:je,resume:Qe}):l.current=null},[ne,dt,ht,Ae,Re,oe,ie,Z,Ke,je,Qe]),(0,a.useEffect)(function(){G.current||(j(),Q(!0)),!(U||N)&&(_e?Z():z())},[U,_e,N,G]),(0,a.useEffect)(function(){if(!G.current){var i=I(new Set(I(s).concat(I(v))).values());if(Q(),Je.current=i,be.current=m,wt.current=v,U||N)return;_e?Z():z()}},[m,JSON.stringify(s),JSON.stringify(v),G,N,U,_e]),(0,a.useEffect)(function(){G.current&&(G.current=!1)},[G]);var L={message:fr,start:Z,reset:Ke,activate:It,pause:je,resume:Qe,isIdle:lr,isPrompted:mr,isLeader:dr,isLastActiveTab:pr,getTabId:vr,getRemainingTime:xt,getElapsedTime:Ot,getTotalElapsedTime:St,getLastIdleTime:hr,getLastActiveTime:_r,getIdleTime:Lt,getTotalIdleTime:Pt,getActiveTime:yr,getTotalActiveTime:gr,setOnPresenceChange:function(i){b=i,Te.current=i},setOnPrompt:function(i){J=i,Ae.current=i},setOnIdle:function(i){H=i,Re.current=i},setOnActive:function(i){re=i,oe.current=i},setOnAction:function(i){Le=i,Me.current=i},setOnMessage:function(i){pe=i,ie.current=i}};return L}var de=Ze(require("react"));var Oe=(0,de.createContext)(null);function ur(e){var r=se(e);return de.default.createElement(Oe.Provider,{value:r},e.children)}var sr=Oe.Consumer;function cr(){return(0,de.useContext)(Oe)}