@capsitech/idle-timer
Version:
Activity detection for React.js
2 lines (1 loc) • 32.1 kB
JavaScript
var Ar=Object.create;var Be=Object.defineProperty;var Cr=Object.getOwnPropertyDescriptor;var Mr=Object.getOwnPropertyNames;var jr=Object.getPrototypeOf,Dr=Object.prototype.hasOwnProperty;var Nr=function(t,r){return function(){return t&&(r=t(t=0)),r}};var Br=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}},Ur=function(t,r){for(var e in r)Be(t,e,{get:r[e],enumerable:!0})},jt=function(t,r,e,n){if(r&&typeof r=="object"||typeof r=="function")for(var i=Mr(r),s=0,c=i.length,v;s<c;s++)v=i[s],!Dr.call(t,v)&&v!==e&&Be(t,v,{get:function(l){return r[l]}.bind(null,v),enumerable:!(n=Cr(r,v))||n.enumerable});return t};var Dt=function(t,r,e){return e=t!=null?Ar(jr(t)):{},jt(r||!t||!t.__esModule?Be(e,"default",{value:t,enumerable:!0}):e,t)},Gr=function(t){return jt(Be({},"__esModule",{value:!0}),t)};function W(t){"@swc/helpers - typeof";return t&&typeof Symbol!="undefined"&&t.constructor===Symbol?"symbol":typeof t}var Ie=Nr(function(){});var zt=Br(function(Oe,Yt){Ie();(function(t,r){(typeof Oe=="undefined"?"undefined":W(Oe))==="object"&&typeof Yt!="undefined"?r(Oe):typeof define=="function"&&define.amd?define(["exports"],r):(t=typeof globalThis!="undefined"?globalThis:t||self,r(t.fastUniqueNumbers={}))})(Oe,function(t){"use strict";var r=function(w){return function(_){var m=w(_);return _.add(m),m}},e=function(w){return function(_,m){return w.set(_,m),m}},n=Number.MAX_SAFE_INTEGER===void 0?9007199254740991:Number.MAX_SAFE_INTEGER,i=536870912,s=i*2,c=function(w,_){return function(m){var j=_.get(m),E=j===void 0?m.size:j<s?j+1:0;if(!m.has(E))return w(m,E);if(m.size<i){for(;m.has(E);)E=Math.floor(Math.random()*s);return w(m,E)}if(m.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;m.has(E);)E=Math.floor(Math.random()*n);return w(m,E)}},v=new WeakMap,l=e(v),u=c(l,v),d=r(u);t.addUniqueNumber=d,t.generateUniqueNumber=u})});var qr={};Ur(qr,{BroadcastChannel:function(){return We},DEFAULT_EVENTS:function(){return qe},IdleTimerComponent:function(){return hr},IdleTimerConsumer:function(){return Bt},IdleTimerContext:function(){return Ee},IdleTimerProvider:function(){return Nt},createMocks:function(){return or},useIdleTimer:function(){return se},useIdleTimerContext:function(){return Ut},withIdleTimer:function(){return vr},workerTimers:function(){return ce}});module.exports=Gr(qr);var Ue=require("react");var Ee=(0,Ue.createContext)(null);function Nt(t){var r=se(t);return React.createElement(Ee.Provider,{value:r},t.children)}var Bt=Ee.Consumer;function Ut(){return(0,Ue.useContext)(Ee)}function Ge(t,r){return r!=null&&typeof Symbol!="undefined"&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](t):Ge(t,r)}function V(t,r){if(!Ge(t,r))throw new TypeError("Cannot call a class as a function")}function Gt(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function ue(t,r,e){return r&&Gt(t.prototype,r),e&&Gt(t,e),t}function h(t,r,e){return r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function Te(t,r){(r==null||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function Ft(t){if(Array.isArray(t))return Te(t)}function Vt(t){if(typeof Symbol!="undefined"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Wt(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function qt(t,r){if(t){if(typeof t=="string")return Te(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);if(e==="Object"&&t.constructor&&(e=t.constructor.name),e==="Map"||e==="Set")return Array.from(e);if(e==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return Te(t,r)}}function g(t){return Ft(t)||Vt(t)||qt(t)||Wt()}var p=function(t){return t[t.APPLY=0]="APPLY",t[t.TELL=1]="TELL",t[t.CLOSE=2]="CLOSE",t[t.REGISTER=3]="REGISTER",t[t.DEREGISTER=4]="DEREGISTER",t[t.IDLE=5]="IDLE",t[t.ACTIVE=6]="ACTIVE",t[t.PROMPT=7]="PROMPT",t[t.START=8]="START",t[t.RESET=9]="RESET",t[t.ACTIVATE=10]="ACTIVATE",t[t.PAUSE=11]="PAUSE",t[t.RESUME=12]="RESUME",t[t.MESSAGE=13]="MESSAGE",t}({});function Fe(){return Math.random().toString(36).substring(2)}Ie();var Se=Dt(zt());var Ht=function(t){return t.method!==void 0&&t.method==="call"};var Jt=function(t){return typeof t.id=="number"&&typeof t.result=="boolean"};var Xt=function(t){var r=new Map([[0,function(){}]]),e=new Map([[0,function(){}]]),n=new Map,i=new Worker(t);i.addEventListener("message",function(u){var d=u.data;if(Ht(d)){var S=d.params,w=S.timerId,_=S.timerType;if(_==="interval"){var m=r.get(w);if((typeof m=="undefined"?"undefined":W(m))===void 0)throw new Error("The timer is in an undefined state.");if(typeof m=="number"){var j=n.get(m);if(j===void 0||j.timerId!==w||j.timerType!==_)throw new Error("The timer is in an undefined state.")}else typeof m=="function"&&m()}else if(_==="timeout"){var E=e.get(w);if((typeof E=="undefined"?"undefined":W(E))===void 0)throw new Error("The timer is in an undefined state.");if(typeof E=="number"){var ee=n.get(E);if(ee===void 0||ee.timerId!==w||ee.timerType!==_)throw new Error("The timer is in an undefined state.")}else typeof E=="function"&&(E(),e.delete(w))}}else if(Jt(d)){var z=d.id,te=n.get(z);if(te===void 0)throw new Error("The timer is in an undefined state.");var H=te.timerId,Re=te.timerType;n.delete(z),Re==="interval"?r.delete(H):e.delete(H)}else{var re=d.error.message;throw new Error(re)}});var s=function(u){if(typeof r.get(u)=="function"){var d=(0,Se.generateUniqueNumber)(n);n.set(d,{timerId:u,timerType:"interval"}),r.set(u,d),i.postMessage({id:d,method:"clear",params:{timerId:u,timerType:"interval"}})}},c=function(u){if(typeof e.get(u)=="function"){var d=(0,Se.generateUniqueNumber)(n);n.set(d,{timerId:u,timerType:"timeout"}),e.set(u,d),i.postMessage({id:d,method:"clear",params:{timerId:u,timerType:"timeout"}})}},v=function(u){for(var d=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,S=arguments.length,w=new Array(S>2?S-2:0),_=2;_<S;_++)w[_-2]=arguments[_];var m=(0,Se.generateUniqueNumber)(r);return r.set(m,function(){u.apply(void 0,g(w)),typeof r.get(m)=="function"&&i.postMessage({id:null,method:"set",params:{delay:d,now:performance.timeOrigin+performance.now(),timerId:m,timerType:"interval"}})}),i.postMessage({id:null,method:"set",params:{delay:d,now:performance.timeOrigin+performance.now(),timerId:m,timerType:"interval"}}),m},l=function(u){for(var d=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,S=arguments.length,w=new Array(S>2?S-2:0),_=2;_<S;_++)w[_-2]=arguments[_];var m=(0,Se.generateUniqueNumber)(e);return e.set(m,function(){return u.apply(void 0,g(w))}),i.postMessage({id:null,method:"set",params:{delay:d,now:performance.timeOrigin+performance.now(),timerId:m,timerType:"timeout"}}),m};return{clearInterval:s,clearTimeout:c,setInterval:v,setTimeout:l}};var Kt=function(t,r){var e=null;return function(){if(e!==null)return e;var n=new Blob([r],{type:"application/javascript; charset=utf-8"}),i=URL.createObjectURL(n);return e=t(i),setTimeout(function(){return URL.revokeObjectURL(i)}),e}};var $t='(()=>{"use strict";const e=new Map,t=new Map,r=t=>{const r=e.get(t);return void 0!==r&&(clearTimeout(r),e.delete(t),!0)},s=e=>{const r=t.get(e);return void 0!==r&&(clearTimeout(r),t.delete(e),!0)},o=(e,t)=>{const r=performance.now(),s=e+t-r-performance.timeOrigin;return{expected:r+s,remainingDelay:s}},i=(e,t,r,s)=>{const o=r-performance.now();o>0?e.set(t,setTimeout(i,o,e,t,r,s)):(e.delete(t),postMessage({id:null,method:"call",params:{timerId:t,timerType:s}}))};addEventListener("message",(({data:n})=>{try{if("clear"===n.method){const{id:e,params:{timerId:t,timerType:o}}=n;if("interval"===o)postMessage({id:e,result:r(t)});else{if("timeout"!==o)throw new Error(\'The given type "\'.concat(o,\'" is not supported\'));postMessage({id:e,result:s(t)})}}else{if("set"!==n.method)throw new Error(\'The given method "\'.concat(n.method,\'" is not supported\'));{const{params:{delay:r,now:s,timerId:a,timerType:m}}=n;if("interval"===m)((t,r,s)=>{const{expected:n,remainingDelay:a}=o(t,s);e.set(r,setTimeout(i,a,e,r,n,"interval"))})(r,a,s);else{if("timeout"!==m)throw new Error(\'The given type "\'.concat(m,\'" is not supported\'));((e,r,s)=>{const{expected:n,remainingDelay:a}=o(e,s);t.set(r,setTimeout(i,a,t,r,n,"timeout"))})(r,a,s)}}}}catch(e){postMessage({error:{message:e.message},id:n.id,result:null})}}))})();';var Qt,Zt,Ve=Kt(Xt,$t),er=function(t){return Ve().clearInterval(t)},tr=function(t){return Ve().clearTimeout(t)},rr=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return(Qt=Ve()).setInterval.apply(Qt,g(r))},nr=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return(Zt=Ve()).setTimeout.apply(Zt,g(r))};Ie();var A=(typeof window=="undefined"||typeof window=="undefined"?"undefined":W(window))==="object";var T={setTimeout:A?setTimeout.bind(window):setTimeout,clearTimeout:A?clearTimeout.bind(window):clearTimeout,setInterval:A?setInterval.bind(window):setInterval,clearInterval:A?clearInterval.bind(window):clearInterval},ce={setTimeout:nr,clearTimeout:tr,setInterval:rr,clearInterval:er};function or(){T.setTimeout=setTimeout,T.clearTimeout=clearTimeout,T.setInterval=setInterval,T.clearInterval=clearInterval,ce.setTimeout=setTimeout,ce.clearTimeout=clearTimeout,ce.setInterval=setInterval,ce.clearInterval=clearInterval}function ir(t){T.setTimeout=t.setTimeout,T.clearTimeout=t.clearTimeout,T.setInterval=t.setInterval,T.clearInterval=t.clearInterval}var fe={},Vr=function(){"use strict";function t(r){V(this,t),h(this,"name",void 0),h(this,"closed",!1),h(this,"mc",new MessageChannel),this.name=r,fe[r]=fe[r]||[],fe[r].push(this),this.mc.port1.start(),this.mc.port2.start(),this.onStorage=this.onStorage.bind(this),window.addEventListener("storage",this.onStorage)}return ue(t,[{key:"onStorage",value:function(e){if(e.storageArea===window.localStorage&&e.key.substring(0,this.name.length)===this.name&&e.newValue!==null){var n=JSON.parse(e.newValue);this.mc.port2.postMessage(n)}}},{key:"postMessage",value:function(e){var n=this;if(this.closed)throw new Error("InvalidStateError");var i=JSON.stringify(e),s="".concat(this.name,":").concat(String(Date.now())).concat(String(Math.random()));window.localStorage.setItem(s,i),T.setTimeout(function(){window.localStorage.removeItem(s)},500),fe[this.name].forEach(function(c){c!==n&&c.mc.port2.postMessage(JSON.parse(i))})}},{key:"close",value:function(){if(!this.closed){this.closed=!0,this.mc.port1.close(),this.mc.port2.close(),window.removeEventListener("storage",this.onStorage);var e=fe[this.name].indexOf(this);fe[this.name].splice(e,1)}}},{key:"onmessage",get:function(){return this.mc.port1.onmessage},set:function(e){this.mc.port1.onmessage=e}},{key:"onmessageerror",get:function(){return this.mc.port1.onmessageerror},set:function(e){this.mc.port1.onmessageerror=e}},{key:"addEventListener",value:function(e,n){return this.mc.port1.addEventListener(e,n)}},{key:"removeEventListener",value:function(e,n){return this.mc.port1.removeEventListener(e,n)}},{key:"dispatchEvent",value:function(e){return this.mc.port1.dispatchEvent(e)}}]),t}(),We=typeof window=="undefined"?void 0:typeof window.BroadcastChannel=="function"?window.BroadcastChannel:Vr;function ar(t,r,e,n,i,s,c){try{var v=t[s](c),l=v.value}catch(u){e(u);return}v.done?r(l):Promise.resolve(l).then(n,i)}function sr(t){return function(){var r=this,e=arguments;return new Promise(function(n,i){var s=t.apply(r,e);function c(l){ar(s,n,i,c,v,"next",l)}function v(l){ar(s,n,i,c,v,"throw",l)}c(void 0)})}}function et(t,r){var e={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,c=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return c.next=v(0),c.throw=v(1),c.return=v(2),typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function v(u){return function(d){return l([u,d])}}function l(u){if(n)throw new TypeError("Generator is already executing.");for(;c&&(c=0,u[0]&&(e=0)),e;)try{if(n=1,i&&(s=u[0]&2?i.return:u[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,u[1])).done)return s;switch(i=0,s&&(u=[u[0]&2,s.value]),u[0]){case 0:case 1:s=u;break;case 4:return e.label++,{value:u[1],done:!1};case 5:e.label++,i=u[1],u=[0];continue;case 7:u=e.ops.pop(),e.trys.pop();continue;default:if(s=e.trys,!(s=s.length>0&&s[s.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!s||u[1]>s[0]&&u[1]<s[3])){e.label=u[1];break}if(u[0]===6&&e.label<s[1]){e.label=s[1],s=u;break}if(s&&e.label<s[2]){e.label=s[2],e.ops.push(u);break}s[2]&&e.ops.pop(),e.trys.pop();continue}u=r.call(t,e)}catch(d){u=[6,d],i=0}finally{n=s=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function ur(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return new Promise(function(r){return T.setTimeout(r,t)})}var cr=function(){"use strict";function t(r,e){V(this,t),h(this,"options",void 0),h(this,"channel",void 0),h(this,"token",Fe()),h(this,"isLeader",!1),h(this,"isDead",!1),h(this,"isApplying",!1),h(this,"reApply",!1),h(this,"intervals",[]),h(this,"listeners",[]),h(this,"deferred",void 0),this.channel=r,this.options=e,this.apply=this.apply.bind(this),this.awaitLeadership=this.awaitLeadership.bind(this),this.sendAction=this.sendAction.bind(this)}return ue(t,[{key:"apply",value:function(){var e=this;return sr(function(){var n,i,s;return et(this,function(c){switch(c.label){case 0:if(e.isLeader)return[2,!1];if(e.isDead)return[2,!1];if(e.isApplying)return e.reApply=!0,[2,!1];e.isApplying=!0,n=!1,i=function(v){var l=v.data,u=l.token,d=l.action;u!==e.token&&(d===p.APPLY&&u>e.token&&(n=!0),d===p.TELL&&(n=!0))},e.channel.addEventListener("message",i),c.label=1;case 1:return c.trys.push([1,3,,4]),e.sendAction(p.APPLY),[4,ur(e.options.responseTime)];case 2:return c.sent(),e.channel.removeEventListener("message",i),e.isApplying=!1,n?e.reApply?[2,e.apply()]:[2,!1]:(e.assumeLead(),[2,!0]);case 3:return s=c.sent(),[2,!1];case 4:return[2]}})})()}},{key:"awaitLeadership",value:function(){var e=this;if(this.isLeader)return Promise.resolve();var n=!1,i=null;return new Promise(function(s){var c=function(){if(!n){n=!0;try{T.clearInterval(i)}catch(u){}var l=e.intervals.indexOf(i);l>=0&&e.intervals.splice(l,1),e.channel.removeEventListener("message",v),s()}};i=T.setInterval(function(){e.apply().then(function(){e.isLeader&&c()})},e.options.fallbackInterval),e.intervals.push(i);var v=function(l){var u=l.data.action;u===p.CLOSE&&e.apply().then(function(){e.isLeader&&c()})};e.channel.addEventListener("message",v)})}},{key:"sendAction",value:function(e){this.channel.postMessage({action:e,token:this.token})}},{key:"assumeLead",value:function(){var e=this;this.isLeader=!0,this.options.onLeader();var n=function(i){var s=i.data.action;s===p.APPLY&&e.sendAction(p.TELL)};return this.channel.addEventListener("message",n),this.listeners.push(n),this.sendAction(p.TELL)}},{key:"waitForLeadership",value:function(){return this.deferred?this.deferred:(this.deferred=this.awaitLeadership(),this.deferred)}},{key:"close",value:function(){var e=this;if(!this.isDead){this.isDead=!0,this.isLeader=!1,this.sendAction(p.CLOSE);try{this.listeners.forEach(function(n){return e.channel.removeEventListener("message",n)}),this.intervals.forEach(function(n){return T.clearInterval(n)})}catch(n){}}}}]),t}();var fr=function(){"use strict";function t(r){var e=this;V(this,t),h(this,"channel",void 0),h(this,"options",void 0),h(this,"elector",void 0),h(this,"token",Fe()),h(this,"registry",new Map),h(this,"allIdle",!1),h(this,"isLastActive",!1);var n=r.channelName;if(this.options=r,this.channel=new We(n),this.registry.set(this.token,1),r.leaderElection){var i={fallbackInterval:2e3,responseTime:100,onLeader:this.options.onLeader};this.elector=new cr(this.channel,i),this.elector.waitForLeadership()}this.channel.addEventListener("message",function(s){var c=s.data,v=c.action,l=c.token,u=c.data,d=u===void 0?{}:u;switch(v){case p.REGISTER:e.registry.set(l,2);break;case p.DEREGISTER:e.registry.delete(l);break;case p.IDLE:e.idle(l,d.eventType);break;case p.ACTIVE:e.active(l);break;case p.PROMPT:e.prompt(l);break;case p.START:e.start(l);break;case p.RESET:e.reset(l);break;case p.ACTIVATE:e.activate(l);break;case p.PAUSE:e.pause(l);break;case p.RESUME:e.resume(l);break;case p.MESSAGE:e.options.onMessage(d);break}}),this.send(p.REGISTER)}return ue(t,[{key:"isLeader",get:function(){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}},{key:"prompt",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.registry.set(e,0);var n=g(this.registry.values()).every(function(i){return i===0});e===this.token&&this.send(p.PROMPT),n&&this.options.onPrompt()}},{key:"idle",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token,n=arguments.length>1?arguments[1]:void 0;this.registry.set(e,2);var i=g(this.registry.values()).every(function(s){return s===2});e===this.token&&this.send(p.IDLE,n),!this.allIdle&&i&&(this.allIdle=!0,this.options.onIdle({type:n},e))}},{key:"active",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.allIdle=!1,this.registry.set(e,1);var n=g(this.registry.values()).some(function(i){return i===1});e===this.token&&this.send(p.ACTIVE),n&&this.options.onActive(),this.isLastActive=e===this.token}},{key:"start",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(p.START):this.options.start(!0),this.isLastActive=e===this.token}},{key:"reset",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(p.RESET):this.options.reset(!0),this.isLastActive=e===this.token}},{key:"activate",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;this.allIdle=!1,this.registry.set(e,1),e===this.token?this.send(p.ACTIVATE):this.options.activate(!0),this.isLastActive=e===this.token}},{key:"pause",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;e===this.token?this.send(p.PAUSE):this.options.pause(!0)}},{key:"resume",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.token;e===this.token?this.send(p.RESUME):this.options.resume(!0)}},{key:"message",value:function(e){try{this.channel.postMessage({action:p.MESSAGE,token:this.token,data:e})}catch(n){}}},{key:"send",value:function(e,n){try{this.channel.postMessage({action:e,token:this.token,data:{eventType:n}})}catch(i){}}},{key:"close",value:function(){this.options.leaderElection&&this.elector.close(),this.send(p.DEREGISTER),this.channel.close()}}]),t}();var a=Dt(require("react"));function lr(t,r){var e;function n(){for(var i=arguments.length,s=new Array(i),c=0;c<i;c++)s[c]=arguments[c];e&&clearTimeout(e),e=setTimeout(function(){t.apply(void 0,g(s)),e=null},r)}return n.cancel=function(){clearTimeout(e)},n}var mr=A?document:null,qe=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange","focus"];var b=function(){return Date.now()};function Ye(t,r){var e=0;return function(){for(var n=arguments.length,i=new Array(n),s=0;s<n;s++)i[s]=arguments[s];var c=new Date().getTime();if(!(c-e<r))return e=c,t.apply(void 0,g(i))}}var le=2147483647;function se(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=t.timeout,e=r===void 0?1e3*60*20:r,n=t.promptTimeout,i=n===void 0?0:n,s=t.promptBeforeIdle,c=s===void 0?0:s,v=t.element,l=v===void 0?mr:v,u=t.events,d=u===void 0?qe:u,S=t.timers,w=S===void 0?void 0:S,_=t.immediateEvents,m=_===void 0?[]:_,j=t.immediateIdleEvents,E=j===void 0?[]:j,ee=t.onPresenceChange,z=ee===void 0?function(){}:ee,te=t.onPrompt,H=te===void 0?function(){}:te,Re=t.onIdle,re=Re===void 0?function(){}:Re,it=t.onActive,Le=it===void 0?function(){}:it,at=t.onAction,ke=at===void 0?function(){}:at,st=t.onMessage,me=st===void 0?function(){}:st,ut=t.onLeader,_r=ut===void 0?function(){}:ut,ct=t.debounce,de=ct===void 0?0:ct,ft=t.throttle,pe=ft===void 0?0:ft,lt=t.eventsThrottle,Je=lt===void 0?200:lt,mt=t.startOnMount,ne=mt===void 0?!0:mt,dt=t.startManually,N=dt===void 0?!1:dt,pt=t.stopOnIdle,Pe=pt===void 0?!1:pt,vt=t.crossTab,oe=vt===void 0?!1:vt,ht=t.name,_t=ht===void 0?"idle-timer":ht,yt=t.syncTimers,ve=yt===void 0?0:yt,gt=t.leaderElection,bt=gt===void 0?!1:gt,wt=t.disabled,D=wt===void 0?!1:wt,Et=a.default.useRef(b()),Ae=a.default.useRef(b()),x=a.default.useRef(null),Ce=a.default.useRef(null),R=a.default.useRef(null),J=a.default.useRef(0),he=a.default.useRef(0),B=a.default.useRef(0),k=a.default.useRef(0),y=a.default.useRef(!1),I=a.default.useRef(!1),U=a.default.useRef(!1),G=a.default.useRef(!0),_e=a.default.useRef(!1),F=a.default.useRef(null),f=a.default.useRef(null),C=a.default.useRef(e),X=a.default.useRef(0);a.default.useEffect(function(){if(i&&console.warn("\u26A0\uFE0F IdleTimer -- The `promptTimeout` property has been deprecated in favor of `promptBeforeIdle`. It will be removed in the next major release."),c&&i)throw new Error("\u274C Both promptTimeout and promptBeforeIdle can not be set. The promptTimeout property will be deprecated in a future version.");if(e>=le)throw new Error("\u274C The value for the timeout property must fit in a 32 bit signed integer, ".concat(le,"."));if(i>=le)throw new Error("\u274C The value for the promptTimeout property must fit in a 32 bit signed integer, ".concat(le,"."));if(c>=le)throw new Error("\u274C The value for the promptBeforeIdle property must fit in a 32 bit signed integer, ".concat(le,"."));if(c>=e)throw new Error("\u274C The value for the promptBeforeIdle property must be less than the timeout property, ".concat(e,"."));if(c?(C.current=e-c,X.current=c):(C.current=e,X.current=i),!G.current){if(N||D)return;y.current&&(K.current(null,L),f.current&&f.current.active()),Z()}},[e,i,c,N,D]);var Tt=a.default.useRef(Pe);a.default.useEffect(function(){Tt.current=Pe},[Pe]);var It=a.default.useRef(m),Ot=a.default.useRef(E),ye=a.default.useRef(l),Xe=a.default.useRef(g(new Set(g(d).concat(g(m),g(E))).values())),M=a.default.useRef(D);a.default.useEffect(function(){M.current=D,!G.current&&(D?Ne():N||Z())},[D]);var ge=a.default.useRef(z);a.default.useEffect(function(){ge.current=z},[z]);var Me=a.default.useRef(H);a.default.useEffect(function(){Me.current=H},[H]);var je=a.default.useRef(re);a.default.useEffect(function(){je.current=re},[re]);var K=a.default.useRef(Le);a.default.useEffect(function(){K.current=Le},[Le]);var De=a.default.useRef(ke);a.default.useEffect(function(){De.current=ke},[ke]);var ie=a.default.useRef(me);a.default.useEffect(function(){ie.current=me},[me]);var q=a.default.useMemo(function(){var o=function(O,ae){return De.current(O,ae)};return de>0?lr(o,de):pe>0?Ye(o,pe):o},[pe,de]),St=a.default.useRef();a.default.useEffect(function(){oe&&ve&&(St.current=Ye(function(){f.current.active()},ve))},[oe,ve]);var P=function(){F.current!==null&&(T.clearTimeout(F.current),F.current=null)},$=function(o){var O=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0;P(),F.current=T.setTimeout(be,o||C.current),O&&(R.current=b())},xt=function(o){!I.current&&!y.current&&(Me.current(o,L),ge.current({type:"active",prompted:!0},L)),k.current=0,B.current=b(),I.current=!0,$(X.current,!1)},Rt=function(o,O){P(),y.current||(je.current(null,L),ge.current({type:"idle"},L)),y.current=!0,x.current=b(),Ce.current="".concat(o,"::").concat(O),Tt.current?Q():I.current&&(B.current=0,I.current=!1)},Ke=function(o){P(),(y.current||I.current)&&(K.current(o,L),ge.current({type:"active",prompted:!1},L)),I.current=!1,B.current=0,y.current=!1,J.current+=b()-x.current,he.current+=b()-x.current,Y(),$()},be=function(o){var O=!y.current;if(O){q.cancel&&q.cancel();var ae=b()-R.current,Pr=C.current+X.current<ae;if(!Pr&&X.current>0&&!I.current){f.current?f.current.prompt():xt(o);return}f.current?f.current.idle():Rt(o.type),console.debug("Page idle - ".concat(o?o.type:""),b());return}f.current?f.current.active():Ke(o),console.debug("Page active - ".concat(o?o.type:""),b())},$e=function(o){if(!ne&&!R.current&&(R.current=b(),K.current(null,L)),q(o,L),!I.current){if(P(),Ot.current.includes(o.type)||o.type==="visibilitychange"&&l&&l.visibilityState==="hidden"){y.current||be(o);return}if(!y.current&&It.current.includes(o.type)){be(o);return}var O=b()-R.current;if(y.current&&!Pe||!y.current&&O>=C.current){be(o);return}U.current=!1,k.current=0,B.current=0,$(),oe&&ve&&St.current()}},we=a.default.useRef($e);a.default.useEffect(function(){var o=_e.current;o&&Q(),Je>0?we.current=Ye($e,Je):we.current=$e,o&&Y()},[Je,pe,de,De,oe,ve]);var yr=function(o){if(!ne&&!R.current&&(R.current=b(),K.current()),q(o),!I.current&&(P(),!y.current&&o.type==="blur")){be(o);return}},gr=a.default.useRef(yr),Y=function(){A&&ye.current&&(_e.current||(Xe.current.forEach(function(o){ye.current.addEventListener(o,we.current,{capture:!0,passive:!0})}),window.addEventListener("blur",gr.current,{capture:!0,passive:!0}),_e.current=!0))},Q=function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;A&&ye.current&&(_e.current||o)&&(Xe.current.forEach(function(O){ye.current.removeEventListener(O,we.current,{capture:!0})}),window.removeEventListener("blur",we.current,{capture:!0}),_e.current=!1)},Z=a.default.useCallback(function(o){return M.current?!1:(P(),Y(),y.current=!1,I.current=!1,U.current=!1,k.current=0,B.current=0,f.current&&!o&&f.current.start(),$(),!0)},[F,y,M,C,f]),Qe=a.default.useCallback(function(o){return M.current?!1:(P(),Y(),Ae.current=b(),he.current+=b()-x.current,J.current=0,y.current=!1,I.current=!1,U.current=!1,k.current=0,B.current=0,f.current&&!o&&f.current.reset(),N||$(),!0)},[F,y,C,N,M,f]),Lt=a.default.useCallback(function(o){return M.current?!1:(P(),Y(),(y.current||I.current)&&Ke(),y.current=!1,I.current=!1,U.current=!1,k.current=0,B.current=0,Ae.current=b(),f.current&&!o&&f.current.activate(),$(),!0)},[F,y,I,M,C,f]),Ne=a.default.useCallback(function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;return M.current||U.current?!1:(k.current=kt(),U.current=!0,Q(),P(),f.current&&!o&&f.current.pause(),!0)},[F,M,f]),Ze=a.default.useCallback(function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;return M.current||!U.current?!1:(U.current=!1,I.current||Y(),y.current||$(k.current),B.current&&(B.current=b()),f.current&&!o&&f.current.resume(),!0)},[F,C,M,k,f]),br=a.default.useCallback(function(o,O){return f.current?(O&&ie.current(o,L),f.current.message(o)):O&&ie.current(o,L),!0},[me]),wr=a.default.useCallback(function(){return y.current},[y]),Er=a.default.useCallback(function(){return I.current},[I]),Tr=a.default.useCallback(function(){return f.current?f.current.isLeader:null},[f]),Ir=a.default.useCallback(function(){return f.current?f.current.isLastActive:null},[f]),Or=a.default.useCallback(function(){return f.current?f.current.token:null},[f]),kt=a.default.useCallback(function(){if(U.current)return k.current;var o=k.current?k.current:X.current+C.current,O=R.current?b()-R.current:0,ae=Math.floor(o-O);return ae<0?0:Math.abs(ae)},[C,X,I,k,R]),Pt=a.default.useCallback(function(){return Math.round(b()-Ae.current)},[Ae]),At=a.default.useCallback(function(){return Math.round(b()-Et.current)},[Et]),Sr=a.default.useCallback(function(){return x.current?new Date(x.current):null},[x]),xr=a.default.useCallback(function(){return Ce.current?Ce.current:null},[Ce]),Rr=a.default.useCallback(function(){return R.current?new Date(R.current):null},[R]),Ct=a.default.useCallback(function(){return y.current?Math.round(b()-x.current+J.current):Math.round(J.current)},[x,J]),Mt=a.default.useCallback(function(){return y.current?Math.round(b()-x.current+he.current):Math.round(he.current)},[x,he]),Lr=a.default.useCallback(function(){var o=Math.round(Pt()-Ct());return o>=0?o:0},[x,J]),kr=a.default.useCallback(function(){var o=Math.round(At()-Mt());return o>=0?o:0},[x,J]);a.default.useEffect(function(){if(de>0&&pe>0)throw new Error("\u274C onAction can either be throttled or debounced, not both.");w&&ir(w);var o=function(){f.current&&f.current.close(),q.cancel&&q.cancel(),P(),Q(!0)};return A&&window.removeEventListener("beforeunload",o),function(){A&&window.removeEventListener("beforeunload",o),f.current&&f.current.close(),q.cancel&&q.cancel(),P(),Q(!0)}},[]),a.default.useEffect(function(){f.current&&f.current.close(),oe?f.current=new fr({channelName:_t,leaderElection:bt,onPrompt:function(){xt()},onIdle:function(o,O){Rt("cross-tab-".concat(o?o.type:""),O)},onActive:function(){Ke()},onMessage:function(o){ie.current(o,L)},onLeader:_r,start:Z,reset:Qe,activate:Lt,pause:Ne,resume:Ze}):f.current=null},[oe,_t,bt,Me,je,K,ie,Z,Qe,Ne,Ze]),a.default.useEffect(function(){G.current||(P(),Q(!0)),!(N||D)&&(ne?Z():Y())},[N,ne,D,G]),a.default.useEffect(function(){if(!G.current){var o=g(new Set(g(d).concat(g(m),g(E))).values());if(Q(),Xe.current=o,ye.current=l,It.current=m,Ot.current=E,N||D)return;ne?Z():Y()}},[l,JSON.stringify(d),JSON.stringify(m),G,N,ne,D]),a.default.useEffect(function(){G.current&&(G.current=!1)},[G]);var L={message:br,start:Z,reset:Qe,activate:Lt,pause:Ne,resume:Ze,isIdle:wr,isPrompted:Er,isLeader:Tr,isLastActiveTab:Ir,getTabId:Or,getRemainingTime:kt,getElapsedTime:Pt,getTotalElapsedTime:At,getLastIdleTime:Sr,getLastIdleEvent:xr,getLastActiveTime:Rr,getIdleTime:Ct,getTotalIdleTime:Mt,getActiveTime:Lr,getTotalActiveTime:kr,setOnPresenceChange:function(o){z=o,ge.current=o},setOnPrompt:function(o){H=o,Me.current=o},setOnIdle:function(o){re=o,je.current=o},setOnActive:function(o){Le=o,K.current=o},setOnAction:function(o){ke=o,De.current=o},setOnMessage:function(o){me=o,ie.current=o}};return L}function xe(t){return xe=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},xe(t)}function tt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(tt=function(){return!!t})()}function dr(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}Ie();function pr(t,r){return r&&(W(r)==="object"||typeof r=="function")?r:dr(t)}function rt(t,r,e){return r=xe(r),pr(t,tt()?Reflect.construct(r,e||[],xe(t).constructor):r.apply(t,e))}function ze(t,r){return ze=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},ze(t,r)}function nt(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),r&&ze(t,r)}function ot(t){for(var r=1;r<arguments.length;r++){var e=arguments[r]!=null?arguments[r]:{},n=Object.keys(e);typeof Object.getOwnPropertySymbols=="function"&&(n=n.concat(Object.getOwnPropertySymbols(e).filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable}))),n.forEach(function(i){h(t,i,e[i])})}return t}var He=require("react");function vr(t){return(0,He.forwardRef)(function(e,n){var i=ot({},e),s=se(i);return typeof n=="function"?n(s):n&&(n.current=s),React.createElement(t,ot({},e,s))})}var Wr=function(t){"use strict";nt(r,t);function r(){return V(this,r),rt(this,r,arguments)}return r}(He.Component),hr=function(t){"use strict";nt(r,t);function r(e){V(this,r);var n;return n=rt(this,r,[e]),n.onPresenceChange&&e.setOnPresenceChange(n.onPresenceChange.bind(n)),n.onPrompt&&e.setOnPrompt(n.onPrompt.bind(n)),n.onIdle&&e.setOnIdle(n.onIdle.bind(n)),n.onActive&&e.setOnActive(n.onActive.bind(n)),n.onAction&&e.setOnAction(n.onAction.bind(n)),n.onMessage&&e.setOnMessage(n.onMessage.bind(n)),n}return r}(Wr);