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