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