Socket
Socket
Sign inDemoInstall

react-idle-timer

Package Overview
Dependencies
5
Maintainers
1
Versions
142
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.5.3 to 5.6.0

dist/types/IMessageHandler.d.ts

2

dist/index.cjs.js

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

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

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

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

@@ -1,5 +0,6 @@

import { EventType } from './EventType';
import type { EventType } from './EventType';
import type { IIdleTimer } from './IIdleTimer';
export interface IEventHandler {
(event?: EventType): void;
(event?: EventType, idleTimer?: IIdleTimer): void;
cancel?: () => void;
}

@@ -59,3 +59,3 @@ import { RefObject } from 'react';

*/
onPresenceChange?: (presence: PresenceType) => void;
onPresenceChange?: (presence: PresenceType, idleTimer?: IIdleTimer) => void;
/**

@@ -68,3 +68,3 @@ * When promptTimeout is set, this function is called after the user becomes

*/
onPrompt?: () => void;
onPrompt?: (event?: Event, idleTimer?: IIdleTimer) => void;
/**

@@ -75,3 +75,3 @@ * Function to call when user is idle.

*/
onIdle?: () => void;
onIdle?: (event?: Event, idleTimer?: IIdleTimer) => void;
/**

@@ -82,3 +82,3 @@ * Function to call when user becomes active.

*/
onActive?: (event?: Event) => void;
onActive?: (event?: Event, idleTimer?: IIdleTimer) => void;
/**

@@ -90,3 +90,3 @@ * Function to call on user activity. Can be throttled or debounced using the

*/
onAction?: (event?: Event) => void;
onAction?: (event?: Event, idleTimer?: IIdleTimer) => void;
/**

@@ -97,3 +97,3 @@ * Function to call when message is has been emitted.

*/
onMessage?: (data: any) => void;
onMessage?: (data: any, idleTimer?: IIdleTimer) => void;
/**

@@ -100,0 +100,0 @@ * Debounce the onAction function by setting delay in milliseconds.

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

import { IIdleTimer } from './types/IIdleTimer';
import { IIdleTimerProps } from './types/IIdleTimerProps';
import type { IIdleTimer } from './types/IIdleTimer';
import type { IIdleTimerProps } from './types/IIdleTimerProps';
/**

@@ -4,0 +4,0 @@ * Creates an IdleTimer instance.

{
"name": "react-idle-timer",
"version": "5.5.3",
"version": "5.6.0",
"description": "Activity detection for React.js",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc