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.0.0-rc.22 to 5.0.0-rc.23

2

dist/index.cjs.js

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

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

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

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

@@ -33,6 +33,6 @@ /// <reference types="react" />

private options;
isLeader: boolean;
allIdle: boolean;
private registry;
constructor(options: ITabManagerOptions);
get isLeader(): boolean;
idle(token?: string): void;

@@ -39,0 +39,0 @@ active(token?: string): void;

@@ -20,4 +20,5 @@ interface ILeaderElectorOptions {

isLeader: boolean;
isDead: boolean;
isApplying: boolean;
private isDead;
private isApplying;
private reApply;
private intervals;

@@ -24,0 +25,0 @@ private listeners;

{
"name": "react-idle-timer",
"version": "5.0.0-rc.22",
"version": "5.0.0-rc.23",
"description": "Activity detection for React.js",

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

Sorry, the diff of this file is not supported yet

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