!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("ng-idle-core",["exports","@angular/core","rxjs","rxjs/operators"],e):e((t=t||self)["ng-idle-core"]={},t.ng.core,t.rxjs,t.rxjs.operators)}(this,function(t,e,n,r){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function s(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function u(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(u){i={error:u}}finally{try{r&&!r.done&&(n=o["return"])&&n.call(o)}finally{if(i)throw i.error}}return s}var a=function(){function t(){this.idValue=new Date,this.idlingValue=!1}return t.prototype.id=function(t){if(void 0!==t){if(!t)throw new Error("A value must be specified for the ID.");this.idValue=t}return this.idValue},t.prototype.idling=function(t){return void 0!==t&&(this.idlingValue=t),this.idlingValue},t.prototype.now=function(){return new Date},t.prototype.isExpired=function(){var t=this.last();return null!=t&&t<=this.now()},t}(),l=function(){function t(t){this.source=t}return t.prototype.subscribe=function(t){this.sub=this.source.onInterrupt.subscribe(t)},t.prototype.unsubscribe=function(){this.sub.unsubscribe(),this.sub=null},t.prototype.resume=function(){this.source.attach()},t.prototype.pause=function(){this.source.detach()},t}(),p=function(){return function(){}}(),c=function(){function t(){this.storageMap={}}return Object.defineProperty(t.prototype,"length",{get:function(){return Object.keys(this.storageMap).length},enumerable:!0,configurable:!0}),t.prototype.clear=function(){this.storageMap={}},t.prototype.getItem=function(t){return"undefined"!=typeof this.storageMap[t]?this.storageMap[t]:null},t.prototype.key=function(t){return Object.keys(this.storageMap)[t]||null},t.prototype.removeItem=function(t){this.storageMap[t]=undefined},t.prototype.setItem=function(t,e){this.storageMap[t]=e},t}(),h=function(){function t(){this.storage=this.getStorage()}return t.prototype.getStorage=function(){try{var t=localStorage;return t.setItem("ng2IdleStorage",""),t.removeItem("ng2IdleStorage"),t}catch(e){return new c}},t.prototype.getItem=function(t){return this.storage.getItem("ng2Idle."+t)},t.prototype.removeItem=function(t){this.storage.removeItem("ng2Idle."+t)},t.prototype.setItem=function(t,e){this.storage.setItem("ng2Idle."+t,e)},t.prototype._wrapped=function(){return this.storage},t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[]},t}(),f=function(t){function n(e){var n=t.call(this)||this;return n.localStorage=e,n.idleName="main",n}return o(n,t),n.prototype.last=function(t){return void 0!==t&&this.setExpiry(t),this.getExpiry()},n.prototype.idling=function(t){return void 0!==t&&this.setIdling(t),this.getIdling()},n.prototype.getIdleName=function(){return this.idleName},n.prototype.setIdleName=function(t){t&&(this.idleName=t)},n.prototype.getExpiry=function(){var t=this.localStorage.getItem(this.idleName+".expiry");return t?new Date(parseInt(t,10)):null},n.prototype.setExpiry=function(t){t?this.localStorage.setItem(this.idleName+".expiry",t.getTime().toString()):this.localStorage.removeItem(this.idleName+".expiry")},n.prototype.getIdling=function(){var t=this.localStorage.getItem(this.idleName+".idling");return!!t&&"true"===t},n.prototype.setIdling=function(t){t?this.localStorage.setItem(this.idleName+".idling",t.toString()):this.localStorage.setItem(this.idleName+".idling","false")},n.decorators=[{type:e.Injectable}],n.ctorParameters=function(){return[{type:h}]},n}(a),d={disabled:0,idle:1,notIdle:2};d[d.disabled]="disabled",d[d.idle]="idle",d[d.notIdle]="notIdle";var v=function(){function t(t,n,r){this.expiry=t,this.zone=n,this.idle=1200,this.timeoutVal=30,this.autoResume=d.idle,this.interrupts=new Array,this.running=!1,this.keepaliveEnabled=!1,this.onIdleStart=new e.EventEmitter,this.onIdleEnd=new e.EventEmitter,this.onTimeoutWarning=new e.EventEmitter,this.onTimeout=new e.EventEmitter,this.onInterrupt=new e.EventEmitter,r&&(this.keepaliveSvc=r,this.keepaliveEnabled=!0),this.setIdling(!1)}return t.prototype.setIdleName=function(t){if(!(this.expiry instanceof f))throw new Error("Cannot set expiry key name because no LocalStorageExpiry has been provided.");this.expiry.setIdleName(t)},t.prototype.getKeepaliveEnabled=function(){return this.keepaliveEnabled},t.prototype.setKeepaliveEnabled=function(t){if(!this.keepaliveSvc)throw new Error("Cannot enable keepalive integration because no KeepaliveSvc has been provided.");return this.keepaliveEnabled=t},t.prototype.getTimeout=function(){return this.timeoutVal},t.prototype.setTimeout=function(t){if(!1===t)this.timeoutVal=0;else{if(!("number"==typeof t&&t>=0))throw new Error("'seconds' can only be 'false' or a positive number.");this.timeoutVal=t}return this.timeoutVal},t.prototype.getIdle=function(){return this.idle},t.prototype.setIdle=function(t){if(t<=0)throw new Error("'seconds' must be greater zero");return this.idle=t},t.prototype.getAutoResume=function(){return this.autoResume},t.prototype.setAutoResume=function(t){return this.autoResume=t},t.prototype.setInterrupts=function(t){var e,n;this.clearInterrupts();var r=this;try{for(var i=s(t),o=i.next();!o.done;o=i.next()){var u=o.value,a=new l(u);a.subscribe(function(t){r.interrupt(t.force,t.innerArgs)}),this.interrupts.push(a)}}catch(p){e={error:p}}finally{try{o&&!o.done&&(n=i["return"])&&n.call(i)}finally{if(e)throw e.error}}return this.interrupts},t.prototype.getInterrupts=function(){return this.interrupts},t.prototype.clearInterrupts=function(){var t,e;try{for(var n=s(this.interrupts),r=n.next();!r.done;r=n.next()){var i=r.value;i.pause(),i.unsubscribe()}}catch(o){t={error:o}}finally{try{r&&!r.done&&(e=n["return"])&&e.call(n)}finally{if(t)throw t.error}}this.interrupts.length=0},t.prototype.isRunning=function(){return this.running},t.prototype.isIdling=function(){return this.idling},t.prototype.watch=function(t){var e=this;this.safeClearInterval("idleHandle"),this.safeClearInterval("timeoutHandle");var n=this.timeoutVal?this.timeoutVal:0;if(!t){var r=new Date(this.expiry.now().getTime()+1e3*(this.idle+n));this.expiry.last(r)}this.idling&&this.toggleState(),this.running||(this.startKeepalive(),this.toggleInterrupts(!0)),this.running=!0;var i=function(){e.zone.run(function(){e.getExpiryDiff(n)>0?(e.safeClearInterval("idleHandle"),e.setIdleIntervalOutsideOfZone(i,1e3)):e.toggleState()})};this.setIdleIntervalOutsideOfZone(i,1e3)},t.prototype.setIdleIntervalOutsideOfZone=function(t,e){var n=this;this.zone.runOutsideAngular(function(){n.idleHandle=setInterval(t,e)})},t.prototype.stop=function(){this.stopKeepalive(),this.toggleInterrupts(!1),this.safeClearInterval("idleHandle"),this.safeClearInterval("timeoutHandle"),this.setIdling(!1),this.running=!1,this.expiry.last(null)},t.prototype.timeout=function(){this.stopKeepalive(),this.toggleInterrupts(!1),this.safeClearInterval("idleHandle"),this.safeClearInterval("timeoutHandle"),this.setIdling(!0),this.running=!1,this.countdown=0,this.onTimeout.emit(null)},t.prototype.interrupt=function(t,e){this.running&&(this.timeoutVal&&this.expiry.isExpired()?this.timeout():(this.onInterrupt.emit(e),(!0===t||this.autoResume===d.idle||this.autoResume===d.notIdle&&!this.expiry.idling())&&this.watch(t)))},t.prototype.setIdling=function(t){this.idling=t,this.expiry.idling(t)},t.prototype.toggleState=function(){var t=this;this.setIdling(!this.idling),this.idling?(this.onIdleStart.emit(null),this.stopKeepalive(),this.timeoutVal>0&&(this.countdown=this.timeoutVal,this.doCountdown(),this.setTimeoutIntervalOutsideZone(function(){t.doCountdownInZone()},1e3))):(this.toggleInterrupts(!0),this.onIdleEnd.emit(null),this.startKeepalive()),this.safeClearInterval("idleHandle")},t.prototype.setTimeoutIntervalOutsideZone=function(t,e){var n=this;this.zone.runOutsideAngular(function(){n.timeoutHandle=setInterval(function(){t()},e)})},t.prototype.toggleInterrupts=function(t){var e,n;try{for(var r=s(this.interrupts),i=r.next();!i.done;i=r.next()){var o=i.value;t?o.resume():o.pause()}}catch(u){e={error:u}}finally{try{i&&!i.done&&(n=r["return"])&&n.call(r)}finally{if(e)throw e.error}}},t.prototype.getExpiryDiff=function(t){var e=this.expiry.now();return(this.expiry.last()||e).getTime()-e.getTime()-1e3*t},t.prototype.doCountdownInZone=function(){var t=this;this.zone.run(function(){t.doCountdown()})},t.prototype.doCountdown=function(){var t=this.getExpiryDiff(this.timeoutVal);if(t>0)return this.safeClearInterval("timeoutHandle"),void this.interrupt(!0);if(this.idling)if(this.countdown<=0)this.timeout();else{this.onTimeoutWarning.emit(this.countdown);var e=1e3*(this.timeoutVal-1)+t;this.countdown=Math.round(e/1e3)}},t.prototype.safeClearInterval=function(t){var e=this[t];null!=e&&(clearInterval(this[t]),this[t]=null)},t.prototype.startKeepalive=function(){this.keepaliveSvc&&this.keepaliveEnabled&&(this.running&&this.keepaliveSvc.ping(),this.keepaliveSvc.start())},t.prototype.stopKeepalive=function(){this.keepaliveSvc&&this.keepaliveEnabled&&this.keepaliveSvc.stop()},t.prototype.ngOnDestroy=function(){this.stop(),this.clearInterrupts()},t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[{type:a},{type:e.NgZone},{type:p,decorators:[{type:e.Optional}]}]},t}(),y=function(){return function(t,e,n){void 0===n&&(n=!1),this.source=t,this.innerArgs=e,this.force=n}}(),g=function(){function t(t,n){this.attachFn=t,this.detachFn=n,this.isAttached=!1,this.onInterrupt=new e.EventEmitter}return t.prototype.attach=function(){var t=this;!0!==Zone.current.get("isAngularZone")?(!this.isAttached&&this.attachFn&&this.attachFn(this),this.isAttached=!0):Zone.current.parent.run(function(){return t.attach()})},t.prototype.detach=function(){this.isAttached&&this.detachFn&&this.detachFn(this),this.isAttached=!1},t}(),m=500,I=function(t){function e(e,i,o){var s=t.call(this,null,null)||this;s.target=e,s.events=i,s.eventSubscription=new n.Subscription,"number"==typeof o&&(o={throttleDelay:o,passive:!1}),(o=o||{throttleDelay:m,passive:!1}).throttleDelay!==undefined&&null!==o.throttleDelay||(o.throttleDelay=m),s.throttleDelay=o.throttleDelay,s.passive=!!o.passive;var a=s.passive?{passive:!0}:null,l=i.split(" ").map(function(t){return n.fromEvent(e,t,a)});s.eventSrc=n.merge.apply(void 0,function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(u(arguments[e]));return t}(l)),s.eventSrc=s.eventSrc.pipe(r.filter(function(t){return!s.filterEvent(t)})),s.throttleDelay>0&&(s.eventSrc=s.eventSrc.pipe(r.throttleTime(s.throttleDelay)));var p=function(t){return s.onInterrupt.emit(new y(s,t))};return s.attachFn=function(){return s.eventSubscription=s.eventSrc.subscribe(p)},s.detachFn=function(){return s.eventSubscription.unsubscribe()},s}return o(e,t),e.prototype.filterEvent=function(t){return!1},Object.defineProperty(e.prototype,"options",{get:function(){return{throttleDelay:this.throttleDelay,passive:this.passive}},enumerable:!0,configurable:!0}),e}(g),b=function(t){function e(e,n){return t.call(this,document.documentElement,e,n)||this}return o(e,t),e.prototype.filterEvent=function(t){return!("mousemove"!==t.type||!(t.originalEvent&&0===t.originalEvent.movementX&&0===t.originalEvent.movementY||void 0!==t.movementX&&!t.movementX)&&t.movementY)},e}(I),w=function(t){function e(e,n){return t.call(this,window,e,n)||this}return o(e,t),e}(I),S=function(t){function e(e){return void 0===e&&(e=500),t.call(this,"storage",e)||this}return o(e,t),e.prototype.filterEvent=function(t){return!(t.key&&t.key.indexOf("ng2Idle.")>=0&&t.key.indexOf(".expiry")>=0)},e}(w),E=function(t){function e(){var e=t.call(this)||this;return e.lastValue=null,e}return o(e,t),e.prototype.last=function(t){return void 0!==t&&(this.lastValue=t),this.lastValue},e}(a),x=function(){function t(){}return t.forRoot=function(){return{ngModule:t,providers:[f,{provide:a,useExisting:f},v]}},t.decorators=[{type:e.NgModule,args:[{providers:[h]}]}],t}();function O(t){return[new b("mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",t),new S]}var D=O();t.AutoResume=d,t.DEFAULT_INTERRUPTSOURCES=D,t.DocumentInterruptSource=b,t.EventTargetInterruptSource=I,t.Idle=v,t.IdleExpiry=a,t.InterruptArgs=y,t.InterruptSource=g,t.KeepaliveSvc=p,t.LocalStorage=h,t.LocalStorageExpiry=f,t.NgIdleModule=x,t.SimpleExpiry=E,t.StorageInterruptSource=S,t.WindowInterruptSource=w,t.createDefaultInterruptSources=O,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ng-idle-core.umd.min.js.map