📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP →

react-idle-timer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-idle-timer - npm Package Compare versions

Comparing version

to
5.6.2

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

var kt=Object.create,he=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var St=Object.getPrototypeOf,Ot=Object.prototype.hasOwnProperty;var Ye=t=>he(t,"__esModule",{value:!0});var Ct=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Rt=(t,e)=>{for(var i in e)he(t,i,{get:e[i],enumerable:!0})},Dt=(t,e,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of At(e))!Ot.call(t,o)&&o!=="default"&&he(t,o,{get:()=>e[o],enumerable:!(i=xt(e,o))||i.enumerable});return t},ve=t=>Dt(Ye(he(t!=null?kt(St(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var Ke=Ct((Te,Xe)=>{(function(t,e){typeof Te=="object"&&typeof Xe!="undefined"?e(Te):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t.fastUniqueNumbers={}))})(Te,function(t){"use strict";var e=function(d){return function(h){var s=d(h);return h.add(s),s}},i=function(d){return function(h,s){return d.set(h,s),s}},o=Number.MAX_SAFE_INTEGER===void 0?9007199254740991:Number.MAX_SAFE_INTEGER,c=536870912,m=c*2,b=function(d,h){return function(s){var W=h.get(s),g=W===void 0?s.size:W<m?W+1:0;if(!s.has(g))return d(s,g);if(s.size<c){for(;s.has(g);)g=Math.floor(Math.random()*m);return d(s,g)}if(s.size>o)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;s.has(g);)g=Math.floor(Math.random()*o);return d(s,g)}},O=new WeakMap,U=i(O),p=b(U,O),u=e(p);t.addUniqueNumber=u,t.generateUniqueNumber=p,Object.defineProperty(t,"__esModule",{value:!0})})});Ye(exports);Rt(exports,{DEFAULT_EVENTS:()=>be,IdleTimerComponent:()=>Se,IdleTimerConsumer:()=>ht,IdleTimerContext:()=>le,IdleTimerProvider:()=>ft,createMocks:()=>at,useIdleTimer:()=>K,useIdleTimerContext:()=>vt,withIdleTimer:()=>Je,workerTimers:()=>Q});var X=ve(require("react"));function Je(t){return(0,X.forwardRef)(function(i,o){let c={...i},m=K(c);return typeof o=="function"?o(m):o&&(o.current=m),X.default.createElement(t,{...i,...m})})}var ze=class extends X.Component{},Se=class extends ze{constructor(e){super(e);this.onPresenceChange&&e.setOnPresenceChange(this.onPresenceChange.bind(this)),this.onPrompt&&e.setOnPrompt(this.onPrompt.bind(this)),this.onIdle&&e.setOnIdle(this.onIdle.bind(this)),this.onActive&&e.setOnActive(this.onActive.bind(this)),this.onAction&&e.setOnAction(this.onAction.bind(this)),this.onMessage&&e.setOnMessage(this.onMessage.bind(this))}};var n=ve(require("react"));var se=ve(Ke());var Qe=t=>t.method!==void 0&&t.method==="call";var Ze=t=>t.error===null&&typeof t.id=="number";var et=t=>{let e=new Map([[0,()=>{}]]),i=new Map([[0,()=>{}]]),o=new Map,c=new Worker(t);return c.addEventListener("message",({data:p})=>{if(Qe(p)){let{params:{timerId:u,timerType:f}}=p;if(f==="interval"){let d=e.get(u);if(typeof d=="number"){let h=o.get(d);if(h===void 0||h.timerId!==u||h.timerType!==f)throw new Error("The timer is in an undefined state.")}else if(typeof d!="undefined")d();else throw new Error("The timer is in an undefined state.")}else if(f==="timeout"){let d=i.get(u);if(typeof d=="number"){let h=o.get(d);if(h===void 0||h.timerId!==u||h.timerType!==f)throw new Error("The timer is in an undefined state.")}else if(typeof d!="undefined")d(),i.delete(u);else throw new Error("The timer is in an undefined state.")}}else if(Ze(p)){let{id:u}=p,f=o.get(u);if(f===void 0)throw new Error("The timer is in an undefined state.");let{timerId:d,timerType:h}=f;o.delete(u),h==="interval"?e.delete(d):i.delete(d)}else{let{error:{message:u}}=p;throw new Error(u)}}),{clearInterval:p=>{let u=(0,se.generateUniqueNumber)(o);o.set(u,{timerId:p,timerType:"interval"}),e.set(p,u),c.postMessage({id:u,method:"clear",params:{timerId:p,timerType:"interval"}})},clearTimeout:p=>{let u=(0,se.generateUniqueNumber)(o);o.set(u,{timerId:p,timerType:"timeout"}),i.set(p,u),c.postMessage({id:u,method:"clear",params:{timerId:p,timerType:"timeout"}})},setInterval:(p,u)=>{let f=(0,se.generateUniqueNumber)(e);return e.set(f,()=>{p(),typeof e.get(f)=="function"&&c.postMessage({id:null,method:"set",params:{delay:u,now:performance.now(),timerId:f,timerType:"interval"}})}),c.postMessage({id:null,method:"set",params:{delay:u,now:performance.now(),timerId:f,timerType:"interval"}}),f},setTimeout:(p,u)=>{let f=(0,se.generateUniqueNumber)(i);return i.set(f,p),c.postMessage({id:null,method:"set",params:{delay:u,now:performance.now(),timerId:f,timerType:"timeout"}}),f}}};var ae=null,tt=(t,e)=>()=>{if(ae!==null)return ae;let i=new Blob([e],{type:"application/javascript; charset=utf-8"}),o=URL.createObjectURL(i);return ae=t(o),ae.setTimeout(()=>URL.revokeObjectURL(o),0),ae};var rt=`(()=>{"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 Ie=tt(et,rt),nt=t=>Ie().clearInterval(t),it=t=>Ie().clearTimeout(t),ot=(t,e)=>Ie().setInterval(t,e),st=(t,e)=>Ie().setTimeout(t,e);var k=(typeof window=="undefined"?"undefined":typeof window)=="object";var I={setTimeout:k?setTimeout.bind(window):setTimeout,clearTimeout:k?clearTimeout.bind(window):clearTimeout,setInterval:k?setInterval.bind(window):setInterval,clearInterval:k?clearInterval.bind(window):clearInterval},Q={setTimeout:st,clearTimeout:it,setInterval:ot,clearInterval:nt};function at(){I.setTimeout=setTimeout,I.clearTimeout=clearTimeout,I.setInterval=setInterval,I.clearInterval=clearInterval,Q.setTimeout=setTimeout,Q.clearTimeout=clearTimeout,Q.setInterval=setInterval,Q.clearInterval=clearInterval}function lt(t){I.setTimeout=t.setTimeout,I.clearTimeout=t.clearTimeout,I.setInterval=t.setInterval,I.clearInterval=t.clearInterval}var Z={},ct=class{constructor(e){this.closed=!1;this.mc=new MessageChannel;this.name=e,Z[e]=Z[e]||[],Z[e].push(this),this.mc.port1.start(),this.mc.port2.start(),this.onStorage=this.onStorage.bind(this),window.addEventListener("storage",this.onStorage)}onStorage(e){if(e.storageArea!==window.localStorage||e.key.substring(0,this.name.length)!==this.name||e.newValue===null)return;let i=JSON.parse(e.newValue);this.mc.port2.postMessage(i)}postMessage(e){if(this.closed)throw new Error("InvalidStateError");let i=JSON.stringify(e),o=`${this.name}:${String(Date.now())}${String(Math.random())}`;window.localStorage.setItem(o,i),I.setTimeout(()=>{window.localStorage.removeItem(o)},500),Z[this.name].forEach(c=>{c!==this&&c.mc.port2.postMessage(JSON.parse(i))})}close(){if(this.closed)return;this.closed=!0,this.mc.port1.close(),this.mc.port2.close(),window.removeEventListener("storage",this.onStorage);let e=Z[this.name].indexOf(this);Z[this.name].splice(e,1)}get onmessage(){return this.mc.port1.onmessage}set onmessage(e){this.mc.port1.onmessage=e}get onmessageerror(){return this.mc.port1.onmessageerror}set onmessageerror(e){this.mc.port1.onmessageerror=e}addEventListener(e,i){return this.mc.port1.addEventListener(e,i)}removeEventListener(e,i){return this.mc.port1.removeEventListener(e,i)}dispatchEvent(e){return this.mc.port1.dispatchEvent(e)}},ut=typeof window=="undefined"?void 0:typeof window.BroadcastChannel=="function"?window.BroadcastChannel:ct;function mt(t=0){return new Promise(e=>I.setTimeout(e,t))}function Ee(){return Math.random().toString(36).substring(2)}var l;(function(s){s[s.APPLY=0]="APPLY",s[s.TELL=1]="TELL",s[s.CLOSE=2]="CLOSE",s[s.REGISTER=3]="REGISTER",s[s.DEREGISTER=4]="DEREGISTER",s[s.IDLE=5]="IDLE",s[s.ACTIVE=6]="ACTIVE",s[s.PROMPT=7]="PROMPT",s[s.START=8]="START",s[s.RESET=9]="RESET",s[s.ACTIVATE=10]="ACTIVATE",s[s.PAUSE=11]="PAUSE",s[s.RESUME=12]="RESUME",s[s.MESSAGE=13]="MESSAGE"})(l||(l={}));var Oe=class{constructor(e,i){this.token=Ee();this.isLeader=!1;this.isDead=!1;this.isApplying=!1;this.reApply=!1;this.intervals=[];this.listeners=[];this.channel=e,this.options=i,this.apply=this.apply.bind(this),this.awaitLeadership=this.awaitLeadership.bind(this),this.sendAction=this.sendAction.bind(this)}async apply(){if(this.isLeader||this.isDead)return!1;if(this.isApplying)return this.reApply=!0,!1;this.isApplying=!0;let e=!1,i=o=>{let{token:c,action:m}=o.data;c!==this.token&&(m===l.APPLY&&c>this.token&&(e=!0),m===l.TELL&&(e=!0))};this.channel.addEventListener("message",i);try{return this.sendAction(l.APPLY),await mt(this.options.responseTime),this.channel.removeEventListener("message",i),this.isApplying=!1,e?this.reApply?this.apply():!1:(this.assumeLead(),!0)}catch{return!1}}awaitLeadership(){if(this.isLeader)return Promise.resolve();let e=!1,i=null;return new Promise(o=>{let c=()=>{if(e)return;e=!0;try{I.clearInterval(i)}catch{}let b=this.intervals.indexOf(i);b>=0&&this.intervals.splice(b,1),this.channel.removeEventListener("message",m),o()};i=I.setInterval(()=>{this.apply().then(()=>{this.isLeader&&c()})},this.options.fallbackInterval),this.intervals.push(i);let m=b=>{let{action:O}=b.data;O===l.CLOSE&&this.apply().then(()=>{this.isLeader&&c()})};this.channel.addEventListener("message",m)})}sendAction(e){this.channel.postMessage({action:e,token:this.token})}assumeLead(){this.isLeader=!0;let e=i=>{let{action:o}=i.data;o===l.APPLY&&this.sendAction(l.TELL)};return this.channel.addEventListener("message",e),this.listeners.push(e),this.sendAction(l.TELL)}waitForLeadership(){return this.deferred?this.deferred:(this.deferred=this.awaitLeadership(),this.deferred)}close(){if(!this.isDead){this.isDead=!0,this.isLeader=!1,this.sendAction(l.CLOSE);try{this.listeners.forEach(e=>this.channel.removeEventListener("message",e)),this.intervals.forEach(e=>I.clearInterval(e))}catch{}}}};var P;(function(o){o[o.PROMPTED=0]="PROMPTED",o[o.ACTIVE=1]="ACTIVE",o[o.IDLE=2]="IDLE"})(P||(P={}));var Ce=class{constructor(e){this.token=Ee();this.registry=new Map;this.allIdle=!1;this.isLastActive=!1;let{channelName:i}=e;if(this.options=e,this.channel=new ut(i),this.registry.set(this.token,1),e.leaderElection){let o={fallbackInterval:2e3,responseTime:100};this.elector=new Oe(this.channel,o),this.elector.waitForLeadership()}this.channel.addEventListener("message",o=>{let{action:c,token:m,data:b}=o.data;switch(c){case l.REGISTER:this.registry.set(m,2);break;case l.DEREGISTER:this.registry.delete(m);break;case l.IDLE:this.idle(m);break;case l.ACTIVE:this.active(m);break;case l.PROMPT:this.prompt(m);break;case l.START:this.start(m);break;case l.RESET:this.reset(m);break;case l.ACTIVATE:this.activate(m);break;case l.PAUSE:this.pause(m);break;case l.RESUME:this.resume(m);break;case l.MESSAGE:this.options.onMessage(b);break}}),this.send(l.REGISTER)}get isLeader(){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}prompt(e=this.token){this.registry.set(e,0);let i=[...this.registry.values()].every(o=>o===0);e===this.token&&this.send(l.PROMPT),i&&this.options.onPrompt()}idle(e=this.token){this.registry.set(e,2);let i=[...this.registry.values()].every(o=>o===2);e===this.token&&this.send(l.IDLE),!this.allIdle&&i&&(this.allIdle=!0,this.options.onIdle())}active(e=this.token){this.allIdle=!1,this.registry.set(e,1);let i=[...this.registry.values()].some(o=>o===1);e===this.token&&this.send(l.ACTIVE),i&&this.options.onActive(),this.isLastActive=e===this.token}start(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(l.START):this.options.start(!0),this.isLastActive=e===this.token}reset(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(l.RESET):this.options.reset(!0),this.isLastActive=e===this.token}activate(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(l.ACTIVATE):this.options.activate(!0),this.isLastActive=e===this.token}pause(e=this.token){e===this.token?this.send(l.PAUSE):this.options.pause(!0)}resume(e=this.token){e===this.token?this.send(l.RESUME):this.options.resume(!0)}message(e){try{this.channel.postMessage({action:l.MESSAGE,token:this.token,data:e})}catch{}}send(e){try{this.channel.postMessage({action:e,token:this.token})}catch{}}close(){this.options.leaderElection&&this.elector.close(),this.send(l.DEREGISTER),this.channel.close()}};var dt=k?document:null,be=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange","focus"];function pt(t,e){let i;function o(...c){i&&clearTimeout(i),i=setTimeout(()=>{t(...c),i=null},e)}return o.cancel=function(){clearTimeout(i)},o}function ge(t,e){let i=0;return function(...o){let c=new Date().getTime();if(!(c-i<e))return i=c,t(...o)}}var T=()=>Date.now();var ee=2147483647;function K({timeout:t=1e3*60*20,promptTimeout:e=0,promptBeforeIdle:i=0,element:o=dt,events:c=be,timers:m=void 0,immediateEvents:b=[],onPresenceChange:O=()=>{},onPrompt:U=()=>{},onIdle:p=()=>{},onActive:u=()=>{},onAction:f=()=>{},onMessage:d=()=>{},debounce:h=0,throttle:s=0,eventsThrottle:W=200,startOnMount:g=!0,startManually:H=!1,stopOnIdle:ce=!1,crossTab:j=!1,name:Re="idle-timer",syncTimers:re=0,leaderElection:De=!1}={}){let He=(0,n.useRef)(T()),ue=(0,n.useRef)(T()),y=(0,n.useRef)(null),x=(0,n.useRef)(null),N=(0,n.useRef)(0),ne=(0,n.useRef)(0),C=(0,n.useRef)(0),M=(0,n.useRef)(0),v=(0,n.useRef)(!1),E=(0,n.useRef)(!1),R=(0,n.useRef)(!1),_=(0,n.useRef)(!0),ie=(0,n.useRef)(!1),D=(0,n.useRef)(null),a=(0,n.useRef)(null),A=(0,n.useRef)(t),B=(0,n.useRef)(0);(0,n.useEffect)(()=>{if(e&&console.warn("\u26A0\uFE0F IdleTimer -- The `promptTimeout` property has been deprecated in favor of `promptBeforeIdle`. It will be removed in the next major release."),i&&e)throw new Error("\u274C Both promptTimeout and promptBeforeIdle can not be set. The promptTimeout property will be deprecated in a future version.");if(t>=ee)throw new Error(`\u274C The value for the timeout property must fit in a 32 bit signed integer, ${ee}.`);if(e>=ee)throw new Error(`\u274C The value for the promptTimeout property must fit in a 32 bit signed integer, ${ee}.`);if(i>=ee)throw new Error(`\u274C The value for the promptBeforeIdle property must fit in a 32 bit signed integer, ${ee}.`);if(i>=t)throw new Error(`\u274C The value for the promptBeforeIdle property must be less than the timeout property, ${t}.`);if(i?(A.current=t-i,B.current=i):(A.current=t,B.current=e),!_.current){if(H)return;v.current&&($.current(null,w),a.current&&a.current.active()),J()}},[t,e,i,H]);let Ne=(0,n.useRef)(ce);(0,n.useEffect)(()=>{Ne.current=ce},[ce]);let _e=(0,n.useRef)(b),ye=(0,n.useRef)(o),we=(0,n.useRef)([...new Set([...c,...b]).values()]),oe=(0,n.useRef)(O);(0,n.useEffect)(()=>{oe.current=O},[O]);let me=(0,n.useRef)(U);(0,n.useEffect)(()=>{me.current=U},[U]);let de=(0,n.useRef)(p);(0,n.useEffect)(()=>{de.current=p},[p]);let $=(0,n.useRef)(u);(0,n.useEffect)(()=>{$.current=u},[u]);let pe=(0,n.useRef)(f);(0,n.useEffect)(()=>{pe.current=f},[f]);let Y=(0,n.useRef)(d);(0,n.useEffect)(()=>{Y.current=d},[d]);let V=(0,n.useMemo)(()=>{let r=(L,z)=>pe.current(L,z);return h>0?pt(r,h):s>0?ge(r,s):r},[s,h]),Fe=(0,n.useRef)();(0,n.useEffect)(()=>{j&&re&&(Fe.current=ge(()=>{a.current.active()},re))},[j,re]);let S=()=>{D.current!==null&&(I.clearTimeout(D.current),D.current=null)},G=(r,L=!0)=>{S(),D.current=I.setTimeout(Pe,r||A.current),L&&(x.current=T())},Ue=r=>{!E.current&&!v.current&&(me.current(r,w),oe.current({type:"active",prompted:!0},w)),M.current=0,C.current=T(),E.current=!0,G(B.current,!1)},We=()=>{S(),v.current||(de.current(null,w),oe.current({type:"idle"},w)),v.current=!0,y.current=T(),Ne.current?q():E.current&&(C.current=0,E.current=!1)},Le=r=>{S(),(v.current||E.current)&&($.current(r,w),oe.current({type:"active",prompted:!1},w)),E.current=!1,C.current=0,v.current=!1,N.current+=T()-y.current,ne.current+=T()-y.current,F(),G()},Pe=r=>{if(!v.current){V.cancel&&V.cancel();let z=T()-x.current;if(!(A.current+B.current<z)&&B.current>0&&!E.current){a.current?a.current.prompt():Ue(r);return}a.current?a.current.idle():We();return}a.current?a.current.active():Le(r)},Me=r=>{if(!g&&!x.current&&(x.current=T(),$.current(null,w)),V(r,w),E.current)return;if(S(),!v.current&&_e.current.includes(r.type)){Pe(r);return}let L=T()-x.current;if(v.current&&!ce||!v.current&&L>=A.current){Pe(r);return}R.current=!1,M.current=0,C.current=0,G(),j&&re&&Fe.current()},fe=(0,n.useRef)(Me);(0,n.useEffect)(()=>{let r=ie.current;r&&q(),W>0?fe.current=ge(Me,W):fe.current=Me,r&&F()},[W,s,h,pe,j,re]);let F=()=>{!k||ie.current||(we.current.forEach(r=>{ye.current.addEventListener(r,fe.current,{capture:!0,passive:!0})}),ie.current=!0)},q=(r=!1)=>{!k||(ie.current||r)&&(we.current.forEach(L=>{ye.current.removeEventListener(L,fe.current,{capture:!0})}),ie.current=!1)},J=(0,n.useCallback)(r=>{S(),F(),v.current=!1,E.current=!1,R.current=!1,M.current=0,C.current=0,a.current&&!r&&a.current.start(),G()},[D,v,A,a]),ke=(0,n.useCallback)(r=>{S(),F(),ue.current=T(),N.current+=T()-y.current,ne.current+=T()-y.current,N.current=0,v.current=!1,E.current=!1,R.current=!1,M.current=0,C.current=0,a.current&&!r&&a.current.reset(),H||G()},[D,v,A,H,a]),Be=(0,n.useCallback)(r=>{S(),F(),(v.current||E.current)&&Le(),v.current=!1,E.current=!1,R.current=!1,M.current=0,C.current=0,ue.current=T(),a.current&&!r&&a.current.activate(),G()},[D,v,E,A,a]),xe=(0,n.useCallback)((r=!1)=>R.current?!1:(M.current=Ve(),R.current=!0,q(),S(),a.current&&!r&&a.current.pause(),!0),[D,a]),Ae=(0,n.useCallback)((r=!1)=>R.current?(R.current=!1,E.current||F(),v.current||G(M.current),C.current&&(C.current=T()),a.current&&!r&&a.current.resume(),!0):!1,[D,A,M,a]),Tt=(0,n.useCallback)((r,L)=>{a.current?(L&&Y.current(r,w),a.current.message(r)):L&&Y.current(r,w)},[d]),It=(0,n.useCallback)(()=>v.current,[v]),Et=(0,n.useCallback)(()=>E.current,[E]),bt=(0,n.useCallback)(()=>a.current?a.current.isLeader:null,[a]),gt=(0,n.useCallback)(()=>a.current?a.current.isLastActive:null,[a]),yt=(0,n.useCallback)(()=>a.current?a.current.token:null,[a]),Ve=(0,n.useCallback)(()=>{if(R.current)return M.current;let r=M.current?M.current:B.current+A.current,L=x.current?T()-x.current:0,z=Math.floor(r-L);return z<0?0:Math.abs(z)},[A,B,E,M,x]),Ge=(0,n.useCallback)(()=>Math.round(T()-ue.current),[ue]),qe=(0,n.useCallback)(()=>Math.round(T()-He.current),[He]),wt=(0,n.useCallback)(()=>y.current?new Date(y.current):null,[y]),Lt=(0,n.useCallback)(()=>x.current?new Date(x.current):null,[x]),je=(0,n.useCallback)(()=>v.current?Math.round(T()-y.current+N.current):Math.round(N.current),[y,N]),$e=(0,n.useCallback)(()=>v.current?Math.round(T()-y.current+ne.current):Math.round(ne.current),[y,ne]),Pt=(0,n.useCallback)(()=>{let r=Math.round(Ge()-je());return r>=0?r:0},[y,N]),Mt=(0,n.useCallback)(()=>{let r=Math.round(qe()-$e());return r>=0?r:0},[y,N]);(0,n.useEffect)(()=>{if(h>0&&s>0)throw new Error("\u274C onAction can either be throttled or debounced, not both.");m&&lt(m);let r=()=>{a.current&&a.current.close(),V.cancel&&V.cancel(),S(),q(!0)};return k&&window.addEventListener("beforeunload",r),()=>{k&&window.removeEventListener("beforeunload",r),a.current&&a.current.close(),V.cancel&&V.cancel(),S(),q(!0)}},[]),(0,n.useEffect)(()=>{a.current&&a.current.close(),j?a.current=new Ce({channelName:Re,leaderElection:De,onPrompt:()=>{Ue()},onIdle:()=>{We()},onActive:()=>{Le()},onMessage:r=>{Y.current(r,w)},start:J,reset:ke,activate:Be,pause:xe,resume:Ae}):a.current=null},[j,Re,De,me,de,$,Y,J,ke,xe,Ae]),(0,n.useEffect)(()=>{_.current||(S(),q(!0)),!H&&(g?J():F())},[H,g,_]),(0,n.useEffect)(()=>{if(!_.current){let r=[...new Set([...c,...b]).values()];if(q(),we.current=r,ye.current=o,_e.current=b,H)return;g?J():F()}},[o,JSON.stringify(c),JSON.stringify(b),_,H,g]),(0,n.useEffect)(()=>{_.current&&(_.current=!1)},[_]);let w={message:Tt,start:J,reset:ke,activate:Be,pause:xe,resume:Ae,isIdle:It,isPrompted:Et,isLeader:bt,isLastActiveTab:gt,getTabId:yt,getRemainingTime:Ve,getElapsedTime:Ge,getTotalElapsedTime:qe,getLastIdleTime:wt,getLastActiveTime:Lt,getIdleTime:je,getTotalIdleTime:$e,getActiveTime:Pt,getTotalActiveTime:Mt,setOnPresenceChange:r=>{O=r,oe.current=r},setOnPrompt:r=>{U=r,me.current=r},setOnIdle:r=>{p=r,de.current=r},setOnActive:r=>{u=r,$.current=r},setOnAction:r=>{f=r,pe.current=r},setOnMessage:r=>{d=r,Y.current=r}};return w}var te=ve(require("react"));var le=(0,te.createContext)(null);function ft(t){let e=K(t);return te.default.createElement(le.Provider,{value:e},t.children)}var ht=le.Consumer;function vt(){return(0,te.useContext)(le)}
var kt=Object.create,ve=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var St=Object.getPrototypeOf,Ot=Object.prototype.hasOwnProperty;var Ye=t=>ve(t,"__esModule",{value:!0});var Ct=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Rt=(t,e)=>{for(var i in e)ve(t,i,{get:e[i],enumerable:!0})},Dt=(t,e,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of At(e))!Ot.call(t,o)&&o!=="default"&&ve(t,o,{get:()=>e[o],enumerable:!(i=xt(e,o))||i.enumerable});return t},Te=t=>Dt(Ye(ve(t!=null?kt(St(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var Ke=Ct((Ie,Xe)=>{(function(t,e){typeof Ie=="object"&&typeof Xe!="undefined"?e(Ie):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t.fastUniqueNumbers={}))})(Ie,function(t){"use strict";var e=function(d){return function(h){var s=d(h);return h.add(s),s}},i=function(d){return function(h,s){return d.set(h,s),s}},o=Number.MAX_SAFE_INTEGER===void 0?9007199254740991:Number.MAX_SAFE_INTEGER,c=536870912,m=c*2,b=function(d,h){return function(s){var W=h.get(s),g=W===void 0?s.size:W<m?W+1:0;if(!s.has(g))return d(s,g);if(s.size<c){for(;s.has(g);)g=Math.floor(Math.random()*m);return d(s,g)}if(s.size>o)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;s.has(g);)g=Math.floor(Math.random()*o);return d(s,g)}},O=new WeakMap,U=i(O),p=b(U,O),u=e(p);t.addUniqueNumber=u,t.generateUniqueNumber=p,Object.defineProperty(t,"__esModule",{value:!0})})});Ye(exports);Rt(exports,{DEFAULT_EVENTS:()=>ge,IdleTimerComponent:()=>Se,IdleTimerConsumer:()=>ht,IdleTimerContext:()=>ce,IdleTimerProvider:()=>ft,createMocks:()=>at,useIdleTimer:()=>K,useIdleTimerContext:()=>vt,withIdleTimer:()=>Je,workerTimers:()=>Q});var X=Te(require("react"));function Je(t){return(0,X.forwardRef)(function(i,o){let c={...i},m=K(c);return typeof o=="function"?o(m):o&&(o.current=m),X.default.createElement(t,{...i,...m})})}var ze=class extends X.Component{},Se=class extends ze{constructor(e){super(e);this.onPresenceChange&&e.setOnPresenceChange(this.onPresenceChange.bind(this)),this.onPrompt&&e.setOnPrompt(this.onPrompt.bind(this)),this.onIdle&&e.setOnIdle(this.onIdle.bind(this)),this.onActive&&e.setOnActive(this.onActive.bind(this)),this.onAction&&e.setOnAction(this.onAction.bind(this)),this.onMessage&&e.setOnMessage(this.onMessage.bind(this))}};var n=Te(require("react"));var ae=Te(Ke());var Qe=t=>t.method!==void 0&&t.method==="call";var Ze=t=>t.error===null&&typeof t.id=="number";var et=t=>{let e=new Map([[0,()=>{}]]),i=new Map([[0,()=>{}]]),o=new Map,c=new Worker(t);return c.addEventListener("message",({data:p})=>{if(Qe(p)){let{params:{timerId:u,timerType:f}}=p;if(f==="interval"){let d=e.get(u);if(typeof d=="number"){let h=o.get(d);if(h===void 0||h.timerId!==u||h.timerType!==f)throw new Error("The timer is in an undefined state.")}else if(typeof d!="undefined")d();else throw new Error("The timer is in an undefined state.")}else if(f==="timeout"){let d=i.get(u);if(typeof d=="number"){let h=o.get(d);if(h===void 0||h.timerId!==u||h.timerType!==f)throw new Error("The timer is in an undefined state.")}else if(typeof d!="undefined")d(),i.delete(u);else throw new Error("The timer is in an undefined state.")}}else if(Ze(p)){let{id:u}=p,f=o.get(u);if(f===void 0)throw new Error("The timer is in an undefined state.");let{timerId:d,timerType:h}=f;o.delete(u),h==="interval"?e.delete(d):i.delete(d)}else{let{error:{message:u}}=p;throw new Error(u)}}),{clearInterval:p=>{let u=(0,ae.generateUniqueNumber)(o);o.set(u,{timerId:p,timerType:"interval"}),e.set(p,u),c.postMessage({id:u,method:"clear",params:{timerId:p,timerType:"interval"}})},clearTimeout:p=>{let u=(0,ae.generateUniqueNumber)(o);o.set(u,{timerId:p,timerType:"timeout"}),i.set(p,u),c.postMessage({id:u,method:"clear",params:{timerId:p,timerType:"timeout"}})},setInterval:(p,u)=>{let f=(0,ae.generateUniqueNumber)(e);return e.set(f,()=>{p(),typeof e.get(f)=="function"&&c.postMessage({id:null,method:"set",params:{delay:u,now:performance.now(),timerId:f,timerType:"interval"}})}),c.postMessage({id:null,method:"set",params:{delay:u,now:performance.now(),timerId:f,timerType:"interval"}}),f},setTimeout:(p,u)=>{let f=(0,ae.generateUniqueNumber)(i);return i.set(f,p),c.postMessage({id:null,method:"set",params:{delay:u,now:performance.now(),timerId:f,timerType:"timeout"}}),f}}};var le=null,tt=(t,e)=>()=>{if(le!==null)return le;let i=new Blob([e],{type:"application/javascript; charset=utf-8"}),o=URL.createObjectURL(i);return le=t(o),le.setTimeout(()=>URL.revokeObjectURL(o),0),le};var rt=`(()=>{"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 Ee=tt(et,rt),nt=t=>Ee().clearInterval(t),it=t=>Ee().clearTimeout(t),ot=(t,e)=>Ee().setInterval(t,e),st=(t,e)=>Ee().setTimeout(t,e);var k=(typeof window=="undefined"?"undefined":typeof window)=="object";var I={setTimeout:k?setTimeout.bind(window):setTimeout,clearTimeout:k?clearTimeout.bind(window):clearTimeout,setInterval:k?setInterval.bind(window):setInterval,clearInterval:k?clearInterval.bind(window):clearInterval},Q={setTimeout:st,clearTimeout:it,setInterval:ot,clearInterval:nt};function at(){I.setTimeout=setTimeout,I.clearTimeout=clearTimeout,I.setInterval=setInterval,I.clearInterval=clearInterval,Q.setTimeout=setTimeout,Q.clearTimeout=clearTimeout,Q.setInterval=setInterval,Q.clearInterval=clearInterval}function lt(t){I.setTimeout=t.setTimeout,I.clearTimeout=t.clearTimeout,I.setInterval=t.setInterval,I.clearInterval=t.clearInterval}var Z={},ct=class{constructor(e){this.closed=!1;this.mc=new MessageChannel;this.name=e,Z[e]=Z[e]||[],Z[e].push(this),this.mc.port1.start(),this.mc.port2.start(),this.onStorage=this.onStorage.bind(this),window.addEventListener("storage",this.onStorage)}onStorage(e){if(e.storageArea!==window.localStorage||e.key.substring(0,this.name.length)!==this.name||e.newValue===null)return;let i=JSON.parse(e.newValue);this.mc.port2.postMessage(i)}postMessage(e){if(this.closed)throw new Error("InvalidStateError");let i=JSON.stringify(e),o=`${this.name}:${String(Date.now())}${String(Math.random())}`;window.localStorage.setItem(o,i),I.setTimeout(()=>{window.localStorage.removeItem(o)},500),Z[this.name].forEach(c=>{c!==this&&c.mc.port2.postMessage(JSON.parse(i))})}close(){if(this.closed)return;this.closed=!0,this.mc.port1.close(),this.mc.port2.close(),window.removeEventListener("storage",this.onStorage);let e=Z[this.name].indexOf(this);Z[this.name].splice(e,1)}get onmessage(){return this.mc.port1.onmessage}set onmessage(e){this.mc.port1.onmessage=e}get onmessageerror(){return this.mc.port1.onmessageerror}set onmessageerror(e){this.mc.port1.onmessageerror=e}addEventListener(e,i){return this.mc.port1.addEventListener(e,i)}removeEventListener(e,i){return this.mc.port1.removeEventListener(e,i)}dispatchEvent(e){return this.mc.port1.dispatchEvent(e)}},ut=typeof window=="undefined"?void 0:typeof window.BroadcastChannel=="function"?window.BroadcastChannel:ct;function mt(t=0){return new Promise(e=>I.setTimeout(e,t))}function be(){return Math.random().toString(36).substring(2)}var l;(function(s){s[s.APPLY=0]="APPLY",s[s.TELL=1]="TELL",s[s.CLOSE=2]="CLOSE",s[s.REGISTER=3]="REGISTER",s[s.DEREGISTER=4]="DEREGISTER",s[s.IDLE=5]="IDLE",s[s.ACTIVE=6]="ACTIVE",s[s.PROMPT=7]="PROMPT",s[s.START=8]="START",s[s.RESET=9]="RESET",s[s.ACTIVATE=10]="ACTIVATE",s[s.PAUSE=11]="PAUSE",s[s.RESUME=12]="RESUME",s[s.MESSAGE=13]="MESSAGE"})(l||(l={}));var Oe=class{constructor(e,i){this.token=be();this.isLeader=!1;this.isDead=!1;this.isApplying=!1;this.reApply=!1;this.intervals=[];this.listeners=[];this.channel=e,this.options=i,this.apply=this.apply.bind(this),this.awaitLeadership=this.awaitLeadership.bind(this),this.sendAction=this.sendAction.bind(this)}async apply(){if(this.isLeader||this.isDead)return!1;if(this.isApplying)return this.reApply=!0,!1;this.isApplying=!0;let e=!1,i=o=>{let{token:c,action:m}=o.data;c!==this.token&&(m===l.APPLY&&c>this.token&&(e=!0),m===l.TELL&&(e=!0))};this.channel.addEventListener("message",i);try{return this.sendAction(l.APPLY),await mt(this.options.responseTime),this.channel.removeEventListener("message",i),this.isApplying=!1,e?this.reApply?this.apply():!1:(this.assumeLead(),!0)}catch{return!1}}awaitLeadership(){if(this.isLeader)return Promise.resolve();let e=!1,i=null;return new Promise(o=>{let c=()=>{if(e)return;e=!0;try{I.clearInterval(i)}catch{}let b=this.intervals.indexOf(i);b>=0&&this.intervals.splice(b,1),this.channel.removeEventListener("message",m),o()};i=I.setInterval(()=>{this.apply().then(()=>{this.isLeader&&c()})},this.options.fallbackInterval),this.intervals.push(i);let m=b=>{let{action:O}=b.data;O===l.CLOSE&&this.apply().then(()=>{this.isLeader&&c()})};this.channel.addEventListener("message",m)})}sendAction(e){this.channel.postMessage({action:e,token:this.token})}assumeLead(){this.isLeader=!0;let e=i=>{let{action:o}=i.data;o===l.APPLY&&this.sendAction(l.TELL)};return this.channel.addEventListener("message",e),this.listeners.push(e),this.sendAction(l.TELL)}waitForLeadership(){return this.deferred?this.deferred:(this.deferred=this.awaitLeadership(),this.deferred)}close(){if(!this.isDead){this.isDead=!0,this.isLeader=!1,this.sendAction(l.CLOSE);try{this.listeners.forEach(e=>this.channel.removeEventListener("message",e)),this.intervals.forEach(e=>I.clearInterval(e))}catch{}}}};var P;(function(o){o[o.PROMPTED=0]="PROMPTED",o[o.ACTIVE=1]="ACTIVE",o[o.IDLE=2]="IDLE"})(P||(P={}));var Ce=class{constructor(e){this.token=be();this.registry=new Map;this.allIdle=!1;this.isLastActive=!1;let{channelName:i}=e;if(this.options=e,this.channel=new ut(i),this.registry.set(this.token,1),e.leaderElection){let o={fallbackInterval:2e3,responseTime:100};this.elector=new Oe(this.channel,o),this.elector.waitForLeadership()}this.channel.addEventListener("message",o=>{let{action:c,token:m,data:b}=o.data;switch(c){case l.REGISTER:this.registry.set(m,2);break;case l.DEREGISTER:this.registry.delete(m);break;case l.IDLE:this.idle(m);break;case l.ACTIVE:this.active(m);break;case l.PROMPT:this.prompt(m);break;case l.START:this.start(m);break;case l.RESET:this.reset(m);break;case l.ACTIVATE:this.activate(m);break;case l.PAUSE:this.pause(m);break;case l.RESUME:this.resume(m);break;case l.MESSAGE:this.options.onMessage(b);break}}),this.send(l.REGISTER)}get isLeader(){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}prompt(e=this.token){this.registry.set(e,0);let i=[...this.registry.values()].every(o=>o===0);e===this.token&&this.send(l.PROMPT),i&&this.options.onPrompt()}idle(e=this.token){this.registry.set(e,2);let i=[...this.registry.values()].every(o=>o===2);e===this.token&&this.send(l.IDLE),!this.allIdle&&i&&(this.allIdle=!0,this.options.onIdle())}active(e=this.token){this.allIdle=!1,this.registry.set(e,1);let i=[...this.registry.values()].some(o=>o===1);e===this.token&&this.send(l.ACTIVE),i&&this.options.onActive(),this.isLastActive=e===this.token}start(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(l.START):this.options.start(!0),this.isLastActive=e===this.token}reset(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(l.RESET):this.options.reset(!0),this.isLastActive=e===this.token}activate(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(l.ACTIVATE):this.options.activate(!0),this.isLastActive=e===this.token}pause(e=this.token){e===this.token?this.send(l.PAUSE):this.options.pause(!0)}resume(e=this.token){e===this.token?this.send(l.RESUME):this.options.resume(!0)}message(e){try{this.channel.postMessage({action:l.MESSAGE,token:this.token,data:e})}catch{}}send(e){try{this.channel.postMessage({action:e,token:this.token})}catch{}}close(){this.options.leaderElection&&this.elector.close(),this.send(l.DEREGISTER),this.channel.close()}};var dt=k?document:null,ge=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange","focus"];function pt(t,e){let i;function o(...c){i&&clearTimeout(i),i=setTimeout(()=>{t(...c),i=null},e)}return o.cancel=function(){clearTimeout(i)},o}function ye(t,e){let i=0;return function(...o){let c=new Date().getTime();if(!(c-i<e))return i=c,t(...o)}}var T=()=>Date.now();var ee=2147483647;function K({timeout:t=1e3*60*20,promptTimeout:e=0,promptBeforeIdle:i=0,element:o=dt,events:c=ge,timers:m=void 0,immediateEvents:b=[],onPresenceChange:O=()=>{},onPrompt:U=()=>{},onIdle:p=()=>{},onActive:u=()=>{},onAction:f=()=>{},onMessage:d=()=>{},debounce:h=0,throttle:s=0,eventsThrottle:W=200,startOnMount:g=!0,startManually:H=!1,stopOnIdle:ue=!1,crossTab:j=!1,name:Re="idle-timer",syncTimers:re=0,leaderElection:De=!1}={}){let He=(0,n.useRef)(T()),me=(0,n.useRef)(T()),y=(0,n.useRef)(null),x=(0,n.useRef)(null),N=(0,n.useRef)(0),ne=(0,n.useRef)(0),C=(0,n.useRef)(0),M=(0,n.useRef)(0),v=(0,n.useRef)(!1),E=(0,n.useRef)(!1),R=(0,n.useRef)(!1),_=(0,n.useRef)(!0),ie=(0,n.useRef)(!1),D=(0,n.useRef)(null),a=(0,n.useRef)(null),A=(0,n.useRef)(t),B=(0,n.useRef)(0);(0,n.useEffect)(()=>{if(e&&console.warn("\u26A0\uFE0F IdleTimer -- The `promptTimeout` property has been deprecated in favor of `promptBeforeIdle`. It will be removed in the next major release."),i&&e)throw new Error("\u274C Both promptTimeout and promptBeforeIdle can not be set. The promptTimeout property will be deprecated in a future version.");if(t>=ee)throw new Error(`\u274C The value for the timeout property must fit in a 32 bit signed integer, ${ee}.`);if(e>=ee)throw new Error(`\u274C The value for the promptTimeout property must fit in a 32 bit signed integer, ${ee}.`);if(i>=ee)throw new Error(`\u274C The value for the promptBeforeIdle property must fit in a 32 bit signed integer, ${ee}.`);if(i>=t)throw new Error(`\u274C The value for the promptBeforeIdle property must be less than the timeout property, ${t}.`);if(i?(A.current=t-i,B.current=i):(A.current=t,B.current=e),!_.current){if(H)return;v.current&&($.current(null,w),a.current&&a.current.active()),J()}},[t,e,i,H]);let Ne=(0,n.useRef)(ue);(0,n.useEffect)(()=>{Ne.current=ue},[ue]);let _e=(0,n.useRef)(b),oe=(0,n.useRef)(o),we=(0,n.useRef)([...new Set([...c,...b]).values()]),se=(0,n.useRef)(O);(0,n.useEffect)(()=>{se.current=O},[O]);let de=(0,n.useRef)(U);(0,n.useEffect)(()=>{de.current=U},[U]);let pe=(0,n.useRef)(p);(0,n.useEffect)(()=>{pe.current=p},[p]);let $=(0,n.useRef)(u);(0,n.useEffect)(()=>{$.current=u},[u]);let fe=(0,n.useRef)(f);(0,n.useEffect)(()=>{fe.current=f},[f]);let Y=(0,n.useRef)(d);(0,n.useEffect)(()=>{Y.current=d},[d]);let V=(0,n.useMemo)(()=>{let r=(L,z)=>fe.current(L,z);return h>0?pt(r,h):s>0?ye(r,s):r},[s,h]),Fe=(0,n.useRef)();(0,n.useEffect)(()=>{j&&re&&(Fe.current=ye(()=>{a.current.active()},re))},[j,re]);let S=()=>{D.current!==null&&(I.clearTimeout(D.current),D.current=null)},G=(r,L=!0)=>{S(),D.current=I.setTimeout(Pe,r||A.current),L&&(x.current=T())},Ue=r=>{!E.current&&!v.current&&(de.current(r,w),se.current({type:"active",prompted:!0},w)),M.current=0,C.current=T(),E.current=!0,G(B.current,!1)},We=()=>{S(),v.current||(pe.current(null,w),se.current({type:"idle"},w)),v.current=!0,y.current=T(),Ne.current?q():E.current&&(C.current=0,E.current=!1)},Le=r=>{S(),(v.current||E.current)&&($.current(r,w),se.current({type:"active",prompted:!1},w)),E.current=!1,C.current=0,v.current=!1,N.current+=T()-y.current,ne.current+=T()-y.current,F(),G()},Pe=r=>{if(!v.current){V.cancel&&V.cancel();let z=T()-x.current;if(!(A.current+B.current<z)&&B.current>0&&!E.current){a.current?a.current.prompt():Ue(r);return}a.current?a.current.idle():We();return}a.current?a.current.active():Le(r)},Me=r=>{if(!g&&!x.current&&(x.current=T(),$.current(null,w)),V(r,w),E.current)return;if(S(),!v.current&&_e.current.includes(r.type)){Pe(r);return}let L=T()-x.current;if(v.current&&!ue||!v.current&&L>=A.current){Pe(r);return}R.current=!1,M.current=0,C.current=0,G(),j&&re&&Fe.current()},he=(0,n.useRef)(Me);(0,n.useEffect)(()=>{let r=ie.current;r&&q(),W>0?he.current=ye(Me,W):he.current=Me,r&&F()},[W,s,h,fe,j,re]);let F=()=>{!k||!oe.current||ie.current||(we.current.forEach(r=>{oe.current.addEventListener(r,he.current,{capture:!0,passive:!0})}),ie.current=!0)},q=(r=!1)=>{!k||!oe.current||(ie.current||r)&&(we.current.forEach(L=>{oe.current.removeEventListener(L,he.current,{capture:!0})}),ie.current=!1)},J=(0,n.useCallback)(r=>{S(),F(),v.current=!1,E.current=!1,R.current=!1,M.current=0,C.current=0,a.current&&!r&&a.current.start(),G()},[D,v,A,a]),ke=(0,n.useCallback)(r=>{S(),F(),me.current=T(),N.current+=T()-y.current,ne.current+=T()-y.current,N.current=0,v.current=!1,E.current=!1,R.current=!1,M.current=0,C.current=0,a.current&&!r&&a.current.reset(),H||G()},[D,v,A,H,a]),Be=(0,n.useCallback)(r=>{S(),F(),(v.current||E.current)&&Le(),v.current=!1,E.current=!1,R.current=!1,M.current=0,C.current=0,me.current=T(),a.current&&!r&&a.current.activate(),G()},[D,v,E,A,a]),xe=(0,n.useCallback)((r=!1)=>R.current?!1:(M.current=Ve(),R.current=!0,q(),S(),a.current&&!r&&a.current.pause(),!0),[D,a]),Ae=(0,n.useCallback)((r=!1)=>R.current?(R.current=!1,E.current||F(),v.current||G(M.current),C.current&&(C.current=T()),a.current&&!r&&a.current.resume(),!0):!1,[D,A,M,a]),Tt=(0,n.useCallback)((r,L)=>{a.current?(L&&Y.current(r,w),a.current.message(r)):L&&Y.current(r,w)},[d]),It=(0,n.useCallback)(()=>v.current,[v]),Et=(0,n.useCallback)(()=>E.current,[E]),bt=(0,n.useCallback)(()=>a.current?a.current.isLeader:null,[a]),gt=(0,n.useCallback)(()=>a.current?a.current.isLastActive:null,[a]),yt=(0,n.useCallback)(()=>a.current?a.current.token:null,[a]),Ve=(0,n.useCallback)(()=>{if(R.current)return M.current;let r=M.current?M.current:B.current+A.current,L=x.current?T()-x.current:0,z=Math.floor(r-L);return z<0?0:Math.abs(z)},[A,B,E,M,x]),Ge=(0,n.useCallback)(()=>Math.round(T()-me.current),[me]),qe=(0,n.useCallback)(()=>Math.round(T()-He.current),[He]),wt=(0,n.useCallback)(()=>y.current?new Date(y.current):null,[y]),Lt=(0,n.useCallback)(()=>x.current?new Date(x.current):null,[x]),je=(0,n.useCallback)(()=>v.current?Math.round(T()-y.current+N.current):Math.round(N.current),[y,N]),$e=(0,n.useCallback)(()=>v.current?Math.round(T()-y.current+ne.current):Math.round(ne.current),[y,ne]),Pt=(0,n.useCallback)(()=>{let r=Math.round(Ge()-je());return r>=0?r:0},[y,N]),Mt=(0,n.useCallback)(()=>{let r=Math.round(qe()-$e());return r>=0?r:0},[y,N]);(0,n.useEffect)(()=>{if(h>0&&s>0)throw new Error("\u274C onAction can either be throttled or debounced, not both.");m&&lt(m);let r=()=>{a.current&&a.current.close(),V.cancel&&V.cancel(),S(),q(!0)};return k&&window.addEventListener("beforeunload",r),()=>{k&&window.removeEventListener("beforeunload",r),a.current&&a.current.close(),V.cancel&&V.cancel(),S(),q(!0)}},[]),(0,n.useEffect)(()=>{a.current&&a.current.close(),j?a.current=new Ce({channelName:Re,leaderElection:De,onPrompt:()=>{Ue()},onIdle:()=>{We()},onActive:()=>{Le()},onMessage:r=>{Y.current(r,w)},start:J,reset:ke,activate:Be,pause:xe,resume:Ae}):a.current=null},[j,Re,De,de,pe,$,Y,J,ke,xe,Ae]),(0,n.useEffect)(()=>{_.current||(S(),q(!0)),!H&&(g?J():F())},[H,g,_]),(0,n.useEffect)(()=>{if(!_.current){let r=[...new Set([...c,...b]).values()];if(q(),we.current=r,oe.current=o,_e.current=b,H)return;g?J():F()}},[o,JSON.stringify(c),JSON.stringify(b),_,H,g]),(0,n.useEffect)(()=>{_.current&&(_.current=!1)},[_]);let w={message:Tt,start:J,reset:ke,activate:Be,pause:xe,resume:Ae,isIdle:It,isPrompted:Et,isLeader:bt,isLastActiveTab:gt,getTabId:yt,getRemainingTime:Ve,getElapsedTime:Ge,getTotalElapsedTime:qe,getLastIdleTime:wt,getLastActiveTime:Lt,getIdleTime:je,getTotalIdleTime:$e,getActiveTime:Pt,getTotalActiveTime:Mt,setOnPresenceChange:r=>{O=r,se.current=r},setOnPrompt:r=>{U=r,de.current=r},setOnIdle:r=>{p=r,pe.current=r},setOnActive:r=>{u=r,$.current=r},setOnAction:r=>{f=r,fe.current=r},setOnMessage:r=>{d=r,Y.current=r}};return w}var te=Te(require("react"));var ce=(0,te.createContext)(null);function ft(t){let e=K(t);return te.default.createElement(ce.Provider,{value:e},t.children)}var ht=ce.Consumer;function vt(){return(0,te.useContext)(ce)}

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

var bt=Object.create,ke=Object.defineProperty;var gt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var wt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Pt=t=>ke(t,"__esModule",{value:!0});var Mt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var kt=(t,e,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of yt(e))!Lt.call(t,i)&&i!=="default"&&ke(t,i,{get:()=>e[i],enumerable:!(n=gt(e,i))||n.enumerable});return t},xt=t=>kt(Pt(ke(t!=null?bt(wt(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var Je=Mt((fe,Ye)=>{(function(t,e){typeof fe=="object"&&typeof Ye!="undefined"?e(fe):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t.fastUniqueNumbers={}))})(fe,function(t){"use strict";var e=function(d){return function(h){var o=d(h);return h.add(o),o}},n=function(d){return function(h,o){return d.set(h,o),o}},i=Number.MAX_SAFE_INTEGER===void 0?9007199254740991:Number.MAX_SAFE_INTEGER,l=536870912,m=l*2,g=function(d,h){return function(o){var V=h.get(o),w=V===void 0?o.size:V<m?V+1:0;if(!o.has(w))return d(o,w);if(o.size<l){for(;o.has(w);)w=Math.floor(Math.random()*m);return d(o,w)}if(o.size>i)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;o.has(w);)w=Math.floor(Math.random()*i);return d(o,w)}},R=new WeakMap,B=n(R),p=g(B,R),c=e(p);t.addUniqueNumber=c,t.generateUniqueNumber=p,Object.defineProperty(t,"__esModule",{value:!0})})});import At,{Component as St,forwardRef as Ot}from"react";function Ct(t){return Ot(function(n,i){let l={...n},m=ie(l);return typeof i=="function"?i(m):i&&(i.current=m),At.createElement(t,{...n,...m})})}var je=class extends St{},$e=class extends je{constructor(e){super(e);this.onPresenceChange&&e.setOnPresenceChange(this.onPresenceChange.bind(this)),this.onPrompt&&e.setOnPrompt(this.onPrompt.bind(this)),this.onIdle&&e.setOnIdle(this.onIdle.bind(this)),this.onActive&&e.setOnActive(this.onActive.bind(this)),this.onAction&&e.setOnAction(this.onAction.bind(this)),this.onMessage&&e.setOnMessage(this.onMessage.bind(this))}};import{useEffect as y,useRef as u,useCallback as I,useMemo as Dt}from"react";var oe=xt(Je());var ze=t=>t.method!==void 0&&t.method==="call";var Xe=t=>t.error===null&&typeof t.id=="number";var Ke=t=>{let e=new Map([[0,()=>{}]]),n=new Map([[0,()=>{}]]),i=new Map,l=new Worker(t);return l.addEventListener("message",({data:p})=>{if(ze(p)){let{params:{timerId:c,timerType:f}}=p;if(f==="interval"){let d=e.get(c);if(typeof d=="number"){let h=i.get(d);if(h===void 0||h.timerId!==c||h.timerType!==f)throw new Error("The timer is in an undefined state.")}else if(typeof d!="undefined")d();else throw new Error("The timer is in an undefined state.")}else if(f==="timeout"){let d=n.get(c);if(typeof d=="number"){let h=i.get(d);if(h===void 0||h.timerId!==c||h.timerType!==f)throw new Error("The timer is in an undefined state.")}else if(typeof d!="undefined")d(),n.delete(c);else throw new Error("The timer is in an undefined state.")}}else if(Xe(p)){let{id:c}=p,f=i.get(c);if(f===void 0)throw new Error("The timer is in an undefined state.");let{timerId:d,timerType:h}=f;i.delete(c),h==="interval"?e.delete(d):n.delete(d)}else{let{error:{message:c}}=p;throw new Error(c)}}),{clearInterval:p=>{let c=(0,oe.generateUniqueNumber)(i);i.set(c,{timerId:p,timerType:"interval"}),e.set(p,c),l.postMessage({id:c,method:"clear",params:{timerId:p,timerType:"interval"}})},clearTimeout:p=>{let c=(0,oe.generateUniqueNumber)(i);i.set(c,{timerId:p,timerType:"timeout"}),n.set(p,c),l.postMessage({id:c,method:"clear",params:{timerId:p,timerType:"timeout"}})},setInterval:(p,c)=>{let f=(0,oe.generateUniqueNumber)(e);return e.set(f,()=>{p(),typeof e.get(f)=="function"&&l.postMessage({id:null,method:"set",params:{delay:c,now:performance.now(),timerId:f,timerType:"interval"}})}),l.postMessage({id:null,method:"set",params:{delay:c,now:performance.now(),timerId:f,timerType:"interval"}}),f},setTimeout:(p,c)=>{let f=(0,oe.generateUniqueNumber)(n);return n.set(f,p),l.postMessage({id:null,method:"set",params:{delay:c,now:performance.now(),timerId:f,timerType:"timeout"}}),f}}};var se=null,Qe=(t,e)=>()=>{if(se!==null)return se;let n=new Blob([e],{type:"application/javascript; charset=utf-8"}),i=URL.createObjectURL(n);return se=t(i),se.setTimeout(()=>URL.revokeObjectURL(i),0),se};var Ze=`(()=>{"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 he=Qe(Ke,Ze),et=t=>he().clearInterval(t),tt=t=>he().clearTimeout(t),rt=(t,e)=>he().setInterval(t,e),nt=(t,e)=>he().setTimeout(t,e);var A=(typeof window=="undefined"?"undefined":typeof window)=="object";var E={setTimeout:A?setTimeout.bind(window):setTimeout,clearTimeout:A?clearTimeout.bind(window):clearTimeout,setInterval:A?setInterval.bind(window):setInterval,clearInterval:A?clearInterval.bind(window):clearInterval},ae={setTimeout:nt,clearTimeout:tt,setInterval:rt,clearInterval:et};function Rt(){E.setTimeout=setTimeout,E.clearTimeout=clearTimeout,E.setInterval=setInterval,E.clearInterval=clearInterval,ae.setTimeout=setTimeout,ae.clearTimeout=clearTimeout,ae.setInterval=setInterval,ae.clearInterval=clearInterval}function it(t){E.setTimeout=t.setTimeout,E.clearTimeout=t.clearTimeout,E.setInterval=t.setInterval,E.clearInterval=t.clearInterval}var Q={},ot=class{constructor(e){this.closed=!1;this.mc=new MessageChannel;this.name=e,Q[e]=Q[e]||[],Q[e].push(this),this.mc.port1.start(),this.mc.port2.start(),this.onStorage=this.onStorage.bind(this),window.addEventListener("storage",this.onStorage)}onStorage(e){if(e.storageArea!==window.localStorage||e.key.substring(0,this.name.length)!==this.name||e.newValue===null)return;let n=JSON.parse(e.newValue);this.mc.port2.postMessage(n)}postMessage(e){if(this.closed)throw new Error("InvalidStateError");let n=JSON.stringify(e),i=`${this.name}:${String(Date.now())}${String(Math.random())}`;window.localStorage.setItem(i,n),E.setTimeout(()=>{window.localStorage.removeItem(i)},500),Q[this.name].forEach(l=>{l!==this&&l.mc.port2.postMessage(JSON.parse(n))})}close(){if(this.closed)return;this.closed=!0,this.mc.port1.close(),this.mc.port2.close(),window.removeEventListener("storage",this.onStorage);let e=Q[this.name].indexOf(this);Q[this.name].splice(e,1)}get onmessage(){return this.mc.port1.onmessage}set onmessage(e){this.mc.port1.onmessage=e}get onmessageerror(){return this.mc.port1.onmessageerror}set onmessageerror(e){this.mc.port1.onmessageerror=e}addEventListener(e,n){return this.mc.port1.addEventListener(e,n)}removeEventListener(e,n){return this.mc.port1.removeEventListener(e,n)}dispatchEvent(e){return this.mc.port1.dispatchEvent(e)}},st=typeof window=="undefined"?void 0:typeof window.BroadcastChannel=="function"?window.BroadcastChannel:ot;function at(t=0){return new Promise(e=>E.setTimeout(e,t))}function ve(){return Math.random().toString(36).substring(2)}var a;(function(o){o[o.APPLY=0]="APPLY",o[o.TELL=1]="TELL",o[o.CLOSE=2]="CLOSE",o[o.REGISTER=3]="REGISTER",o[o.DEREGISTER=4]="DEREGISTER",o[o.IDLE=5]="IDLE",o[o.ACTIVE=6]="ACTIVE",o[o.PROMPT=7]="PROMPT",o[o.START=8]="START",o[o.RESET=9]="RESET",o[o.ACTIVATE=10]="ACTIVATE",o[o.PAUSE=11]="PAUSE",o[o.RESUME=12]="RESUME",o[o.MESSAGE=13]="MESSAGE"})(a||(a={}));var xe=class{constructor(e,n){this.token=ve();this.isLeader=!1;this.isDead=!1;this.isApplying=!1;this.reApply=!1;this.intervals=[];this.listeners=[];this.channel=e,this.options=n,this.apply=this.apply.bind(this),this.awaitLeadership=this.awaitLeadership.bind(this),this.sendAction=this.sendAction.bind(this)}async apply(){if(this.isLeader||this.isDead)return!1;if(this.isApplying)return this.reApply=!0,!1;this.isApplying=!0;let e=!1,n=i=>{let{token:l,action:m}=i.data;l!==this.token&&(m===a.APPLY&&l>this.token&&(e=!0),m===a.TELL&&(e=!0))};this.channel.addEventListener("message",n);try{return this.sendAction(a.APPLY),await at(this.options.responseTime),this.channel.removeEventListener("message",n),this.isApplying=!1,e?this.reApply?this.apply():!1:(this.assumeLead(),!0)}catch{return!1}}awaitLeadership(){if(this.isLeader)return Promise.resolve();let e=!1,n=null;return new Promise(i=>{let l=()=>{if(e)return;e=!0;try{E.clearInterval(n)}catch{}let g=this.intervals.indexOf(n);g>=0&&this.intervals.splice(g,1),this.channel.removeEventListener("message",m),i()};n=E.setInterval(()=>{this.apply().then(()=>{this.isLeader&&l()})},this.options.fallbackInterval),this.intervals.push(n);let m=g=>{let{action:R}=g.data;R===a.CLOSE&&this.apply().then(()=>{this.isLeader&&l()})};this.channel.addEventListener("message",m)})}sendAction(e){this.channel.postMessage({action:e,token:this.token})}assumeLead(){this.isLeader=!0;let e=n=>{let{action:i}=n.data;i===a.APPLY&&this.sendAction(a.TELL)};return this.channel.addEventListener("message",e),this.listeners.push(e),this.sendAction(a.TELL)}waitForLeadership(){return this.deferred?this.deferred:(this.deferred=this.awaitLeadership(),this.deferred)}close(){if(!this.isDead){this.isDead=!0,this.isLeader=!1,this.sendAction(a.CLOSE);try{this.listeners.forEach(e=>this.channel.removeEventListener("message",e)),this.intervals.forEach(e=>E.clearInterval(e))}catch{}}}};var k;(function(i){i[i.PROMPTED=0]="PROMPTED",i[i.ACTIVE=1]="ACTIVE",i[i.IDLE=2]="IDLE"})(k||(k={}));var Ae=class{constructor(e){this.token=ve();this.registry=new Map;this.allIdle=!1;this.isLastActive=!1;let{channelName:n}=e;if(this.options=e,this.channel=new st(n),this.registry.set(this.token,1),e.leaderElection){let i={fallbackInterval:2e3,responseTime:100};this.elector=new xe(this.channel,i),this.elector.waitForLeadership()}this.channel.addEventListener("message",i=>{let{action:l,token:m,data:g}=i.data;switch(l){case a.REGISTER:this.registry.set(m,2);break;case a.DEREGISTER:this.registry.delete(m);break;case a.IDLE:this.idle(m);break;case a.ACTIVE:this.active(m);break;case a.PROMPT:this.prompt(m);break;case a.START:this.start(m);break;case a.RESET:this.reset(m);break;case a.ACTIVATE:this.activate(m);break;case a.PAUSE:this.pause(m);break;case a.RESUME:this.resume(m);break;case a.MESSAGE:this.options.onMessage(g);break}}),this.send(a.REGISTER)}get isLeader(){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}prompt(e=this.token){this.registry.set(e,0);let n=[...this.registry.values()].every(i=>i===0);e===this.token&&this.send(a.PROMPT),n&&this.options.onPrompt()}idle(e=this.token){this.registry.set(e,2);let n=[...this.registry.values()].every(i=>i===2);e===this.token&&this.send(a.IDLE),!this.allIdle&&n&&(this.allIdle=!0,this.options.onIdle())}active(e=this.token){this.allIdle=!1,this.registry.set(e,1);let n=[...this.registry.values()].some(i=>i===1);e===this.token&&this.send(a.ACTIVE),n&&this.options.onActive(),this.isLastActive=e===this.token}start(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(a.START):this.options.start(!0),this.isLastActive=e===this.token}reset(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(a.RESET):this.options.reset(!0),this.isLastActive=e===this.token}activate(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(a.ACTIVATE):this.options.activate(!0),this.isLastActive=e===this.token}pause(e=this.token){e===this.token?this.send(a.PAUSE):this.options.pause(!0)}resume(e=this.token){e===this.token?this.send(a.RESUME):this.options.resume(!0)}message(e){try{this.channel.postMessage({action:a.MESSAGE,token:this.token,data:e})}catch{}}send(e){try{this.channel.postMessage({action:e,token:this.token})}catch{}}close(){this.options.leaderElection&&this.elector.close(),this.send(a.DEREGISTER),this.channel.close()}};var lt=A?document:null,Se=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange","focus"];function ct(t,e){let n;function i(...l){n&&clearTimeout(n),n=setTimeout(()=>{t(...l),n=null},e)}return i.cancel=function(){clearTimeout(n)},i}function Te(t,e){let n=0;return function(...i){let l=new Date().getTime();if(!(l-n<e))return n=l,t(...i)}}var T=()=>Date.now();var Z=2147483647;function ie({timeout:t=1e3*60*20,promptTimeout:e=0,promptBeforeIdle:n=0,element:i=lt,events:l=Se,timers:m=void 0,immediateEvents:g=[],onPresenceChange:R=()=>{},onPrompt:B=()=>{},onIdle:p=()=>{},onActive:c=()=>{},onAction:f=()=>{},onMessage:d=()=>{},debounce:h=0,throttle:o=0,eventsThrottle:V=200,startOnMount:w=!0,startManually:_=!1,stopOnIdle:le=!1,crossTab:Y=!1,name:Oe="idle-timer",syncTimers:ee=0,leaderElection:Ce=!1}={}){let Re=u(T()),ce=u(T()),L=u(null),S=u(null),F=u(0),te=u(0),D=u(0),x=u(0),v=u(!1),b=u(!1),H=u(!1),U=u(!0),re=u(!1),N=u(null),s=u(null),O=u(t),G=u(0);y(()=>{if(e&&console.warn("\u26A0\uFE0F IdleTimer -- The `promptTimeout` property has been deprecated in favor of `promptBeforeIdle`. It will be removed in the next major release."),n&&e)throw new Error("\u274C Both promptTimeout and promptBeforeIdle can not be set. The promptTimeout property will be deprecated in a future version.");if(t>=Z)throw new Error(`\u274C The value for the timeout property must fit in a 32 bit signed integer, ${Z}.`);if(e>=Z)throw new Error(`\u274C The value for the promptTimeout property must fit in a 32 bit signed integer, ${Z}.`);if(n>=Z)throw new Error(`\u274C The value for the promptBeforeIdle property must fit in a 32 bit signed integer, ${Z}.`);if(n>=t)throw new Error(`\u274C The value for the promptBeforeIdle property must be less than the timeout property, ${t}.`);if(n?(O.current=t-n,G.current=n):(O.current=t,G.current=e),!U.current){if(_)return;v.current&&(J.current(null,P),s.current&&s.current.active()),X()}},[t,e,n,_]);let De=u(le);y(()=>{De.current=le},[le]);let He=u(g),Ee=u(i),be=u([...new Set([...l,...g]).values()]),ne=u(R);y(()=>{ne.current=R},[R]);let ue=u(B);y(()=>{ue.current=B},[B]);let me=u(p);y(()=>{me.current=p},[p]);let J=u(c);y(()=>{J.current=c},[c]);let de=u(f);y(()=>{de.current=f},[f]);let z=u(d);y(()=>{z.current=d},[d]);let q=Dt(()=>{let r=(M,K)=>de.current(M,K);return h>0?ct(r,h):o>0?Te(r,o):r},[o,h]),Ne=u();y(()=>{Y&&ee&&(Ne.current=Te(()=>{s.current.active()},ee))},[Y,ee]);let C=()=>{N.current!==null&&(E.clearTimeout(N.current),N.current=null)},j=(r,M=!0)=>{C(),N.current=E.setTimeout(ye,r||O.current),M&&(S.current=T())},_e=r=>{!b.current&&!v.current&&(ue.current(r,P),ne.current({type:"active",prompted:!0},P)),x.current=0,D.current=T(),b.current=!0,j(G.current,!1)},Fe=()=>{C(),v.current||(me.current(null,P),ne.current({type:"idle"},P)),v.current=!0,L.current=T(),De.current?$():b.current&&(D.current=0,b.current=!1)},ge=r=>{C(),(v.current||b.current)&&(J.current(r,P),ne.current({type:"active",prompted:!1},P)),b.current=!1,D.current=0,v.current=!1,F.current+=T()-L.current,te.current+=T()-L.current,W(),j()},ye=r=>{if(!v.current){q.cancel&&q.cancel();let K=T()-S.current;if(!(O.current+G.current<K)&&G.current>0&&!b.current){s.current?s.current.prompt():_e(r);return}s.current?s.current.idle():Fe();return}s.current?s.current.active():ge(r)},we=r=>{if(!w&&!S.current&&(S.current=T(),J.current(null,P)),q(r,P),b.current)return;if(C(),!v.current&&He.current.includes(r.type)){ye(r);return}let M=T()-S.current;if(v.current&&!le||!v.current&&M>=O.current){ye(r);return}H.current=!1,x.current=0,D.current=0,j(),Y&&ee&&Ne.current()},pe=u(we);y(()=>{let r=re.current;r&&$(),V>0?pe.current=Te(we,V):pe.current=we,r&&W()},[V,o,h,de,Y,ee]);let W=()=>{!A||re.current||(be.current.forEach(r=>{Ee.current.addEventListener(r,pe.current,{capture:!0,passive:!0})}),re.current=!0)},$=(r=!1)=>{!A||(re.current||r)&&(be.current.forEach(M=>{Ee.current.removeEventListener(M,pe.current,{capture:!0})}),re.current=!1)},X=I(r=>{C(),W(),v.current=!1,b.current=!1,H.current=!1,x.current=0,D.current=0,s.current&&!r&&s.current.start(),j()},[N,v,O,s]),Le=I(r=>{C(),W(),ce.current=T(),F.current+=T()-L.current,te.current+=T()-L.current,F.current=0,v.current=!1,b.current=!1,H.current=!1,x.current=0,D.current=0,s.current&&!r&&s.current.reset(),_||j()},[N,v,O,_,s]),Ue=I(r=>{C(),W(),(v.current||b.current)&&ge(),v.current=!1,b.current=!1,H.current=!1,x.current=0,D.current=0,ce.current=T(),s.current&&!r&&s.current.activate(),j()},[N,v,b,O,s]),Pe=I((r=!1)=>H.current?!1:(x.current=We(),H.current=!0,$(),C(),s.current&&!r&&s.current.pause(),!0),[N,s]),Me=I((r=!1)=>H.current?(H.current=!1,b.current||W(),v.current||j(x.current),D.current&&(D.current=T()),s.current&&!r&&s.current.resume(),!0):!1,[N,O,x,s]),ut=I((r,M)=>{s.current?(M&&z.current(r,P),s.current.message(r)):M&&z.current(r,P)},[d]),mt=I(()=>v.current,[v]),dt=I(()=>b.current,[b]),pt=I(()=>s.current?s.current.isLeader:null,[s]),ft=I(()=>s.current?s.current.isLastActive:null,[s]),ht=I(()=>s.current?s.current.token:null,[s]),We=I(()=>{if(H.current)return x.current;let r=x.current?x.current:G.current+O.current,M=S.current?T()-S.current:0,K=Math.floor(r-M);return K<0?0:Math.abs(K)},[O,G,b,x,S]),Be=I(()=>Math.round(T()-ce.current),[ce]),Ve=I(()=>Math.round(T()-Re.current),[Re]),vt=I(()=>L.current?new Date(L.current):null,[L]),Tt=I(()=>S.current?new Date(S.current):null,[S]),Ge=I(()=>v.current?Math.round(T()-L.current+F.current):Math.round(F.current),[L,F]),qe=I(()=>v.current?Math.round(T()-L.current+te.current):Math.round(te.current),[L,te]),It=I(()=>{let r=Math.round(Be()-Ge());return r>=0?r:0},[L,F]),Et=I(()=>{let r=Math.round(Ve()-qe());return r>=0?r:0},[L,F]);y(()=>{if(h>0&&o>0)throw new Error("\u274C onAction can either be throttled or debounced, not both.");m&&it(m);let r=()=>{s.current&&s.current.close(),q.cancel&&q.cancel(),C(),$(!0)};return A&&window.addEventListener("beforeunload",r),()=>{A&&window.removeEventListener("beforeunload",r),s.current&&s.current.close(),q.cancel&&q.cancel(),C(),$(!0)}},[]),y(()=>{s.current&&s.current.close(),Y?s.current=new Ae({channelName:Oe,leaderElection:Ce,onPrompt:()=>{_e()},onIdle:()=>{Fe()},onActive:()=>{ge()},onMessage:r=>{z.current(r,P)},start:X,reset:Le,activate:Ue,pause:Pe,resume:Me}):s.current=null},[Y,Oe,Ce,ue,me,J,z,X,Le,Pe,Me]),y(()=>{U.current||(C(),$(!0)),!_&&(w?X():W())},[_,w,U]),y(()=>{if(!U.current){let r=[...new Set([...l,...g]).values()];if($(),be.current=r,Ee.current=i,He.current=g,_)return;w?X():W()}},[i,JSON.stringify(l),JSON.stringify(g),U,_,w]),y(()=>{U.current&&(U.current=!1)},[U]);let P={message:ut,start:X,reset:Le,activate:Ue,pause:Pe,resume:Me,isIdle:mt,isPrompted:dt,isLeader:pt,isLastActiveTab:ft,getTabId:ht,getRemainingTime:We,getElapsedTime:Be,getTotalElapsedTime:Ve,getLastIdleTime:vt,getLastActiveTime:Tt,getIdleTime:Ge,getTotalIdleTime:qe,getActiveTime:It,getTotalActiveTime:Et,setOnPresenceChange:r=>{R=r,ne.current=r},setOnPrompt:r=>{B=r,ue.current=r},setOnIdle:r=>{p=r,me.current=r},setOnActive:r=>{c=r,J.current=r},setOnAction:r=>{f=r,de.current=r},setOnMessage:r=>{d=r,z.current=r}};return P}import Ht,{createContext as Nt,useContext as _t}from"react";var Ie=Nt(null);function Ft(t){let e=ie(t);return Ht.createElement(Ie.Provider,{value:e},t.children)}var Ut=Ie.Consumer;function Wt(){return _t(Ie)}export{Se as DEFAULT_EVENTS,$e as IdleTimerComponent,Ut as IdleTimerConsumer,Ie as IdleTimerContext,Ft as IdleTimerProvider,Rt as createMocks,ie as useIdleTimer,Wt as useIdleTimerContext,Ct as withIdleTimer,ae as workerTimers};
var bt=Object.create,ke=Object.defineProperty;var gt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var wt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Pt=t=>ke(t,"__esModule",{value:!0});var Mt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var kt=(t,e,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of yt(e))!Lt.call(t,i)&&i!=="default"&&ke(t,i,{get:()=>e[i],enumerable:!(n=gt(e,i))||n.enumerable});return t},xt=t=>kt(Pt(ke(t!=null?bt(wt(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var Je=Mt((he,Ye)=>{(function(t,e){typeof he=="object"&&typeof Ye!="undefined"?e(he):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t.fastUniqueNumbers={}))})(he,function(t){"use strict";var e=function(d){return function(h){var o=d(h);return h.add(o),o}},n=function(d){return function(h,o){return d.set(h,o),o}},i=Number.MAX_SAFE_INTEGER===void 0?9007199254740991:Number.MAX_SAFE_INTEGER,l=536870912,m=l*2,g=function(d,h){return function(o){var V=h.get(o),w=V===void 0?o.size:V<m?V+1:0;if(!o.has(w))return d(o,w);if(o.size<l){for(;o.has(w);)w=Math.floor(Math.random()*m);return d(o,w)}if(o.size>i)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;o.has(w);)w=Math.floor(Math.random()*i);return d(o,w)}},R=new WeakMap,B=n(R),p=g(B,R),c=e(p);t.addUniqueNumber=c,t.generateUniqueNumber=p,Object.defineProperty(t,"__esModule",{value:!0})})});import At,{Component as St,forwardRef as Ot}from"react";function Ct(t){return Ot(function(n,i){let l={...n},m=oe(l);return typeof i=="function"?i(m):i&&(i.current=m),At.createElement(t,{...n,...m})})}var je=class extends St{},$e=class extends je{constructor(e){super(e);this.onPresenceChange&&e.setOnPresenceChange(this.onPresenceChange.bind(this)),this.onPrompt&&e.setOnPrompt(this.onPrompt.bind(this)),this.onIdle&&e.setOnIdle(this.onIdle.bind(this)),this.onActive&&e.setOnActive(this.onActive.bind(this)),this.onAction&&e.setOnAction(this.onAction.bind(this)),this.onMessage&&e.setOnMessage(this.onMessage.bind(this))}};import{useEffect as y,useRef as u,useCallback as I,useMemo as Dt}from"react";var se=xt(Je());var ze=t=>t.method!==void 0&&t.method==="call";var Xe=t=>t.error===null&&typeof t.id=="number";var Ke=t=>{let e=new Map([[0,()=>{}]]),n=new Map([[0,()=>{}]]),i=new Map,l=new Worker(t);return l.addEventListener("message",({data:p})=>{if(ze(p)){let{params:{timerId:c,timerType:f}}=p;if(f==="interval"){let d=e.get(c);if(typeof d=="number"){let h=i.get(d);if(h===void 0||h.timerId!==c||h.timerType!==f)throw new Error("The timer is in an undefined state.")}else if(typeof d!="undefined")d();else throw new Error("The timer is in an undefined state.")}else if(f==="timeout"){let d=n.get(c);if(typeof d=="number"){let h=i.get(d);if(h===void 0||h.timerId!==c||h.timerType!==f)throw new Error("The timer is in an undefined state.")}else if(typeof d!="undefined")d(),n.delete(c);else throw new Error("The timer is in an undefined state.")}}else if(Xe(p)){let{id:c}=p,f=i.get(c);if(f===void 0)throw new Error("The timer is in an undefined state.");let{timerId:d,timerType:h}=f;i.delete(c),h==="interval"?e.delete(d):n.delete(d)}else{let{error:{message:c}}=p;throw new Error(c)}}),{clearInterval:p=>{let c=(0,se.generateUniqueNumber)(i);i.set(c,{timerId:p,timerType:"interval"}),e.set(p,c),l.postMessage({id:c,method:"clear",params:{timerId:p,timerType:"interval"}})},clearTimeout:p=>{let c=(0,se.generateUniqueNumber)(i);i.set(c,{timerId:p,timerType:"timeout"}),n.set(p,c),l.postMessage({id:c,method:"clear",params:{timerId:p,timerType:"timeout"}})},setInterval:(p,c)=>{let f=(0,se.generateUniqueNumber)(e);return e.set(f,()=>{p(),typeof e.get(f)=="function"&&l.postMessage({id:null,method:"set",params:{delay:c,now:performance.now(),timerId:f,timerType:"interval"}})}),l.postMessage({id:null,method:"set",params:{delay:c,now:performance.now(),timerId:f,timerType:"interval"}}),f},setTimeout:(p,c)=>{let f=(0,se.generateUniqueNumber)(n);return n.set(f,p),l.postMessage({id:null,method:"set",params:{delay:c,now:performance.now(),timerId:f,timerType:"timeout"}}),f}}};var ae=null,Qe=(t,e)=>()=>{if(ae!==null)return ae;let n=new Blob([e],{type:"application/javascript; charset=utf-8"}),i=URL.createObjectURL(n);return ae=t(i),ae.setTimeout(()=>URL.revokeObjectURL(i),0),ae};var Ze=`(()=>{"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 ve=Qe(Ke,Ze),et=t=>ve().clearInterval(t),tt=t=>ve().clearTimeout(t),rt=(t,e)=>ve().setInterval(t,e),nt=(t,e)=>ve().setTimeout(t,e);var A=(typeof window=="undefined"?"undefined":typeof window)=="object";var E={setTimeout:A?setTimeout.bind(window):setTimeout,clearTimeout:A?clearTimeout.bind(window):clearTimeout,setInterval:A?setInterval.bind(window):setInterval,clearInterval:A?clearInterval.bind(window):clearInterval},le={setTimeout:nt,clearTimeout:tt,setInterval:rt,clearInterval:et};function Rt(){E.setTimeout=setTimeout,E.clearTimeout=clearTimeout,E.setInterval=setInterval,E.clearInterval=clearInterval,le.setTimeout=setTimeout,le.clearTimeout=clearTimeout,le.setInterval=setInterval,le.clearInterval=clearInterval}function it(t){E.setTimeout=t.setTimeout,E.clearTimeout=t.clearTimeout,E.setInterval=t.setInterval,E.clearInterval=t.clearInterval}var Q={},ot=class{constructor(e){this.closed=!1;this.mc=new MessageChannel;this.name=e,Q[e]=Q[e]||[],Q[e].push(this),this.mc.port1.start(),this.mc.port2.start(),this.onStorage=this.onStorage.bind(this),window.addEventListener("storage",this.onStorage)}onStorage(e){if(e.storageArea!==window.localStorage||e.key.substring(0,this.name.length)!==this.name||e.newValue===null)return;let n=JSON.parse(e.newValue);this.mc.port2.postMessage(n)}postMessage(e){if(this.closed)throw new Error("InvalidStateError");let n=JSON.stringify(e),i=`${this.name}:${String(Date.now())}${String(Math.random())}`;window.localStorage.setItem(i,n),E.setTimeout(()=>{window.localStorage.removeItem(i)},500),Q[this.name].forEach(l=>{l!==this&&l.mc.port2.postMessage(JSON.parse(n))})}close(){if(this.closed)return;this.closed=!0,this.mc.port1.close(),this.mc.port2.close(),window.removeEventListener("storage",this.onStorage);let e=Q[this.name].indexOf(this);Q[this.name].splice(e,1)}get onmessage(){return this.mc.port1.onmessage}set onmessage(e){this.mc.port1.onmessage=e}get onmessageerror(){return this.mc.port1.onmessageerror}set onmessageerror(e){this.mc.port1.onmessageerror=e}addEventListener(e,n){return this.mc.port1.addEventListener(e,n)}removeEventListener(e,n){return this.mc.port1.removeEventListener(e,n)}dispatchEvent(e){return this.mc.port1.dispatchEvent(e)}},st=typeof window=="undefined"?void 0:typeof window.BroadcastChannel=="function"?window.BroadcastChannel:ot;function at(t=0){return new Promise(e=>E.setTimeout(e,t))}function Te(){return Math.random().toString(36).substring(2)}var a;(function(o){o[o.APPLY=0]="APPLY",o[o.TELL=1]="TELL",o[o.CLOSE=2]="CLOSE",o[o.REGISTER=3]="REGISTER",o[o.DEREGISTER=4]="DEREGISTER",o[o.IDLE=5]="IDLE",o[o.ACTIVE=6]="ACTIVE",o[o.PROMPT=7]="PROMPT",o[o.START=8]="START",o[o.RESET=9]="RESET",o[o.ACTIVATE=10]="ACTIVATE",o[o.PAUSE=11]="PAUSE",o[o.RESUME=12]="RESUME",o[o.MESSAGE=13]="MESSAGE"})(a||(a={}));var xe=class{constructor(e,n){this.token=Te();this.isLeader=!1;this.isDead=!1;this.isApplying=!1;this.reApply=!1;this.intervals=[];this.listeners=[];this.channel=e,this.options=n,this.apply=this.apply.bind(this),this.awaitLeadership=this.awaitLeadership.bind(this),this.sendAction=this.sendAction.bind(this)}async apply(){if(this.isLeader||this.isDead)return!1;if(this.isApplying)return this.reApply=!0,!1;this.isApplying=!0;let e=!1,n=i=>{let{token:l,action:m}=i.data;l!==this.token&&(m===a.APPLY&&l>this.token&&(e=!0),m===a.TELL&&(e=!0))};this.channel.addEventListener("message",n);try{return this.sendAction(a.APPLY),await at(this.options.responseTime),this.channel.removeEventListener("message",n),this.isApplying=!1,e?this.reApply?this.apply():!1:(this.assumeLead(),!0)}catch{return!1}}awaitLeadership(){if(this.isLeader)return Promise.resolve();let e=!1,n=null;return new Promise(i=>{let l=()=>{if(e)return;e=!0;try{E.clearInterval(n)}catch{}let g=this.intervals.indexOf(n);g>=0&&this.intervals.splice(g,1),this.channel.removeEventListener("message",m),i()};n=E.setInterval(()=>{this.apply().then(()=>{this.isLeader&&l()})},this.options.fallbackInterval),this.intervals.push(n);let m=g=>{let{action:R}=g.data;R===a.CLOSE&&this.apply().then(()=>{this.isLeader&&l()})};this.channel.addEventListener("message",m)})}sendAction(e){this.channel.postMessage({action:e,token:this.token})}assumeLead(){this.isLeader=!0;let e=n=>{let{action:i}=n.data;i===a.APPLY&&this.sendAction(a.TELL)};return this.channel.addEventListener("message",e),this.listeners.push(e),this.sendAction(a.TELL)}waitForLeadership(){return this.deferred?this.deferred:(this.deferred=this.awaitLeadership(),this.deferred)}close(){if(!this.isDead){this.isDead=!0,this.isLeader=!1,this.sendAction(a.CLOSE);try{this.listeners.forEach(e=>this.channel.removeEventListener("message",e)),this.intervals.forEach(e=>E.clearInterval(e))}catch{}}}};var k;(function(i){i[i.PROMPTED=0]="PROMPTED",i[i.ACTIVE=1]="ACTIVE",i[i.IDLE=2]="IDLE"})(k||(k={}));var Ae=class{constructor(e){this.token=Te();this.registry=new Map;this.allIdle=!1;this.isLastActive=!1;let{channelName:n}=e;if(this.options=e,this.channel=new st(n),this.registry.set(this.token,1),e.leaderElection){let i={fallbackInterval:2e3,responseTime:100};this.elector=new xe(this.channel,i),this.elector.waitForLeadership()}this.channel.addEventListener("message",i=>{let{action:l,token:m,data:g}=i.data;switch(l){case a.REGISTER:this.registry.set(m,2);break;case a.DEREGISTER:this.registry.delete(m);break;case a.IDLE:this.idle(m);break;case a.ACTIVE:this.active(m);break;case a.PROMPT:this.prompt(m);break;case a.START:this.start(m);break;case a.RESET:this.reset(m);break;case a.ACTIVATE:this.activate(m);break;case a.PAUSE:this.pause(m);break;case a.RESUME:this.resume(m);break;case a.MESSAGE:this.options.onMessage(g);break}}),this.send(a.REGISTER)}get isLeader(){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}prompt(e=this.token){this.registry.set(e,0);let n=[...this.registry.values()].every(i=>i===0);e===this.token&&this.send(a.PROMPT),n&&this.options.onPrompt()}idle(e=this.token){this.registry.set(e,2);let n=[...this.registry.values()].every(i=>i===2);e===this.token&&this.send(a.IDLE),!this.allIdle&&n&&(this.allIdle=!0,this.options.onIdle())}active(e=this.token){this.allIdle=!1,this.registry.set(e,1);let n=[...this.registry.values()].some(i=>i===1);e===this.token&&this.send(a.ACTIVE),n&&this.options.onActive(),this.isLastActive=e===this.token}start(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(a.START):this.options.start(!0),this.isLastActive=e===this.token}reset(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(a.RESET):this.options.reset(!0),this.isLastActive=e===this.token}activate(e=this.token){this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(a.ACTIVATE):this.options.activate(!0),this.isLastActive=e===this.token}pause(e=this.token){e===this.token?this.send(a.PAUSE):this.options.pause(!0)}resume(e=this.token){e===this.token?this.send(a.RESUME):this.options.resume(!0)}message(e){try{this.channel.postMessage({action:a.MESSAGE,token:this.token,data:e})}catch{}}send(e){try{this.channel.postMessage({action:e,token:this.token})}catch{}}close(){this.options.leaderElection&&this.elector.close(),this.send(a.DEREGISTER),this.channel.close()}};var lt=A?document:null,Se=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange","focus"];function ct(t,e){let n;function i(...l){n&&clearTimeout(n),n=setTimeout(()=>{t(...l),n=null},e)}return i.cancel=function(){clearTimeout(n)},i}function Ie(t,e){let n=0;return function(...i){let l=new Date().getTime();if(!(l-n<e))return n=l,t(...i)}}var T=()=>Date.now();var Z=2147483647;function oe({timeout:t=1e3*60*20,promptTimeout:e=0,promptBeforeIdle:n=0,element:i=lt,events:l=Se,timers:m=void 0,immediateEvents:g=[],onPresenceChange:R=()=>{},onPrompt:B=()=>{},onIdle:p=()=>{},onActive:c=()=>{},onAction:f=()=>{},onMessage:d=()=>{},debounce:h=0,throttle:o=0,eventsThrottle:V=200,startOnMount:w=!0,startManually:_=!1,stopOnIdle:ce=!1,crossTab:Y=!1,name:Oe="idle-timer",syncTimers:ee=0,leaderElection:Ce=!1}={}){let Re=u(T()),ue=u(T()),L=u(null),S=u(null),F=u(0),te=u(0),D=u(0),x=u(0),v=u(!1),b=u(!1),H=u(!1),U=u(!0),re=u(!1),N=u(null),s=u(null),O=u(t),G=u(0);y(()=>{if(e&&console.warn("\u26A0\uFE0F IdleTimer -- The `promptTimeout` property has been deprecated in favor of `promptBeforeIdle`. It will be removed in the next major release."),n&&e)throw new Error("\u274C Both promptTimeout and promptBeforeIdle can not be set. The promptTimeout property will be deprecated in a future version.");if(t>=Z)throw new Error(`\u274C The value for the timeout property must fit in a 32 bit signed integer, ${Z}.`);if(e>=Z)throw new Error(`\u274C The value for the promptTimeout property must fit in a 32 bit signed integer, ${Z}.`);if(n>=Z)throw new Error(`\u274C The value for the promptBeforeIdle property must fit in a 32 bit signed integer, ${Z}.`);if(n>=t)throw new Error(`\u274C The value for the promptBeforeIdle property must be less than the timeout property, ${t}.`);if(n?(O.current=t-n,G.current=n):(O.current=t,G.current=e),!U.current){if(_)return;v.current&&(J.current(null,P),s.current&&s.current.active()),X()}},[t,e,n,_]);let De=u(ce);y(()=>{De.current=ce},[ce]);let He=u(g),ne=u(i),be=u([...new Set([...l,...g]).values()]),ie=u(R);y(()=>{ie.current=R},[R]);let me=u(B);y(()=>{me.current=B},[B]);let de=u(p);y(()=>{de.current=p},[p]);let J=u(c);y(()=>{J.current=c},[c]);let pe=u(f);y(()=>{pe.current=f},[f]);let z=u(d);y(()=>{z.current=d},[d]);let q=Dt(()=>{let r=(M,K)=>pe.current(M,K);return h>0?ct(r,h):o>0?Ie(r,o):r},[o,h]),Ne=u();y(()=>{Y&&ee&&(Ne.current=Ie(()=>{s.current.active()},ee))},[Y,ee]);let C=()=>{N.current!==null&&(E.clearTimeout(N.current),N.current=null)},j=(r,M=!0)=>{C(),N.current=E.setTimeout(ye,r||O.current),M&&(S.current=T())},_e=r=>{!b.current&&!v.current&&(me.current(r,P),ie.current({type:"active",prompted:!0},P)),x.current=0,D.current=T(),b.current=!0,j(G.current,!1)},Fe=()=>{C(),v.current||(de.current(null,P),ie.current({type:"idle"},P)),v.current=!0,L.current=T(),De.current?$():b.current&&(D.current=0,b.current=!1)},ge=r=>{C(),(v.current||b.current)&&(J.current(r,P),ie.current({type:"active",prompted:!1},P)),b.current=!1,D.current=0,v.current=!1,F.current+=T()-L.current,te.current+=T()-L.current,W(),j()},ye=r=>{if(!v.current){q.cancel&&q.cancel();let K=T()-S.current;if(!(O.current+G.current<K)&&G.current>0&&!b.current){s.current?s.current.prompt():_e(r);return}s.current?s.current.idle():Fe();return}s.current?s.current.active():ge(r)},we=r=>{if(!w&&!S.current&&(S.current=T(),J.current(null,P)),q(r,P),b.current)return;if(C(),!v.current&&He.current.includes(r.type)){ye(r);return}let M=T()-S.current;if(v.current&&!ce||!v.current&&M>=O.current){ye(r);return}H.current=!1,x.current=0,D.current=0,j(),Y&&ee&&Ne.current()},fe=u(we);y(()=>{let r=re.current;r&&$(),V>0?fe.current=Ie(we,V):fe.current=we,r&&W()},[V,o,h,pe,Y,ee]);let W=()=>{!A||!ne.current||re.current||(be.current.forEach(r=>{ne.current.addEventListener(r,fe.current,{capture:!0,passive:!0})}),re.current=!0)},$=(r=!1)=>{!A||!ne.current||(re.current||r)&&(be.current.forEach(M=>{ne.current.removeEventListener(M,fe.current,{capture:!0})}),re.current=!1)},X=I(r=>{C(),W(),v.current=!1,b.current=!1,H.current=!1,x.current=0,D.current=0,s.current&&!r&&s.current.start(),j()},[N,v,O,s]),Le=I(r=>{C(),W(),ue.current=T(),F.current+=T()-L.current,te.current+=T()-L.current,F.current=0,v.current=!1,b.current=!1,H.current=!1,x.current=0,D.current=0,s.current&&!r&&s.current.reset(),_||j()},[N,v,O,_,s]),Ue=I(r=>{C(),W(),(v.current||b.current)&&ge(),v.current=!1,b.current=!1,H.current=!1,x.current=0,D.current=0,ue.current=T(),s.current&&!r&&s.current.activate(),j()},[N,v,b,O,s]),Pe=I((r=!1)=>H.current?!1:(x.current=We(),H.current=!0,$(),C(),s.current&&!r&&s.current.pause(),!0),[N,s]),Me=I((r=!1)=>H.current?(H.current=!1,b.current||W(),v.current||j(x.current),D.current&&(D.current=T()),s.current&&!r&&s.current.resume(),!0):!1,[N,O,x,s]),ut=I((r,M)=>{s.current?(M&&z.current(r,P),s.current.message(r)):M&&z.current(r,P)},[d]),mt=I(()=>v.current,[v]),dt=I(()=>b.current,[b]),pt=I(()=>s.current?s.current.isLeader:null,[s]),ft=I(()=>s.current?s.current.isLastActive:null,[s]),ht=I(()=>s.current?s.current.token:null,[s]),We=I(()=>{if(H.current)return x.current;let r=x.current?x.current:G.current+O.current,M=S.current?T()-S.current:0,K=Math.floor(r-M);return K<0?0:Math.abs(K)},[O,G,b,x,S]),Be=I(()=>Math.round(T()-ue.current),[ue]),Ve=I(()=>Math.round(T()-Re.current),[Re]),vt=I(()=>L.current?new Date(L.current):null,[L]),Tt=I(()=>S.current?new Date(S.current):null,[S]),Ge=I(()=>v.current?Math.round(T()-L.current+F.current):Math.round(F.current),[L,F]),qe=I(()=>v.current?Math.round(T()-L.current+te.current):Math.round(te.current),[L,te]),It=I(()=>{let r=Math.round(Be()-Ge());return r>=0?r:0},[L,F]),Et=I(()=>{let r=Math.round(Ve()-qe());return r>=0?r:0},[L,F]);y(()=>{if(h>0&&o>0)throw new Error("\u274C onAction can either be throttled or debounced, not both.");m&&it(m);let r=()=>{s.current&&s.current.close(),q.cancel&&q.cancel(),C(),$(!0)};return A&&window.addEventListener("beforeunload",r),()=>{A&&window.removeEventListener("beforeunload",r),s.current&&s.current.close(),q.cancel&&q.cancel(),C(),$(!0)}},[]),y(()=>{s.current&&s.current.close(),Y?s.current=new Ae({channelName:Oe,leaderElection:Ce,onPrompt:()=>{_e()},onIdle:()=>{Fe()},onActive:()=>{ge()},onMessage:r=>{z.current(r,P)},start:X,reset:Le,activate:Ue,pause:Pe,resume:Me}):s.current=null},[Y,Oe,Ce,me,de,J,z,X,Le,Pe,Me]),y(()=>{U.current||(C(),$(!0)),!_&&(w?X():W())},[_,w,U]),y(()=>{if(!U.current){let r=[...new Set([...l,...g]).values()];if($(),be.current=r,ne.current=i,He.current=g,_)return;w?X():W()}},[i,JSON.stringify(l),JSON.stringify(g),U,_,w]),y(()=>{U.current&&(U.current=!1)},[U]);let P={message:ut,start:X,reset:Le,activate:Ue,pause:Pe,resume:Me,isIdle:mt,isPrompted:dt,isLeader:pt,isLastActiveTab:ft,getTabId:ht,getRemainingTime:We,getElapsedTime:Be,getTotalElapsedTime:Ve,getLastIdleTime:vt,getLastActiveTime:Tt,getIdleTime:Ge,getTotalIdleTime:qe,getActiveTime:It,getTotalActiveTime:Et,setOnPresenceChange:r=>{R=r,ie.current=r},setOnPrompt:r=>{B=r,me.current=r},setOnIdle:r=>{p=r,de.current=r},setOnActive:r=>{c=r,J.current=r},setOnAction:r=>{f=r,pe.current=r},setOnMessage:r=>{d=r,z.current=r}};return P}import Ht,{createContext as Nt,useContext as _t}from"react";var Ee=Nt(null);function Ft(t){let e=oe(t);return Ht.createElement(Ee.Provider,{value:e},t.children)}var Ut=Ee.Consumer;function Wt(){return _t(Ee)}export{Se as DEFAULT_EVENTS,$e as IdleTimerComponent,Ut as IdleTimerConsumer,Ee as IdleTimerContext,Ft as IdleTimerProvider,Rt as createMocks,oe as useIdleTimer,Wt as useIdleTimerContext,Ct as withIdleTimer,le as workerTimers};
{
"name": "react-idle-timer",
"version": "5.6.1",
"version": "5.6.2",
"description": "Activity detection for React.js",

@@ -5,0 +5,0 @@ "main": "./dist/index.cjs.js",