🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

react-idle-timer

Package Overview
Dependencies
Maintainers
1
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-idle-timer - npm Package Compare versions

Comparing version

to
5.0.0-rc.16

2

dist/index.cjs.js

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

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

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

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

Sorry, the diff of this file is not supported yet