UNPKG

@karltud123/react-idle-timer

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