/** * easytimer.js * Generated: 2023-08-28 * Version: 4.6.0 */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).easytimer={})}(this,(function(t){"use strict";function e(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function n(t){for(var n=1;ne)return t;for(r=0;r0&&void 0!==arguments[0]?arguments[0]:["hours","minutes","seconds"],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:":",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;t=t||["hours","minutes","seconds"],e=e||":",n=n||2;var r,o=[];for(r=0;r-1&&this.events[t].splice(n,1)}},u.prototype.removeAllListeners=function(t){t?Array.isArray(this.events[t])&&(this.events[t]=[]):this.events={}},u.prototype.emit=function(t){for(var e=this,n=arguments.length,r=new Array(n>1?n-1:0),o=1;o0&&void 0!==arguments[0]?arguments[0]:{},A=new s,P=new s,S=new u,E=!1,D=!1,L={},x={detail:{timer:this}};function V(t,e){var n=P[e];return function(t,e){var n=v[t];P[t]=e,A[t]=t===l?Math.abs(e):y(e>=0?e:n-y(e,n),n)}(e,B(t,p[e])),P[e]!==n}function M(){U(),A.reset(),P.reset()}function U(){clearInterval(t),t=void 0,E=!1,D=!1}function k(n){X()?(O=I(),b=F(m.target)):R(n),function(){var n=p[e];if(N(C(Date.now())))return;t=setInterval(_,n),E=!0,D=!1}()}function I(){return C(Date.now())-P.secondTenths*p[c]*o}function _(){var t=C(Date.now());!function(t){t[c]&&Q("secondTenthsUpdated",x);t[a]&&Q("secondsUpdated",x);t[f]&&Q("minutesUpdated",x);t[h]&&Q("hoursUpdated",x);t[l]&&Q("daysUpdated",x)}(z()),i(x.detail.timer),N(t)&&(H(),Q("targetAchieved",x))}function z(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:C(Date.now()),e=o>0?t-O:O-t,n={};return n[c]=V(e,c),n[a]=function(t){return V(t,a)}(e),n[f]=function(t){return V(t,f)}(e),n[h]=function(t){return V(t,h)}(e),n[l]=function(t){return V(t,l)}(e),n}function C(t){return Math.floor(t/p[e])*p[e]}function N(t){return b instanceof Array&&t>=j}function R(t){var n;e=function(t){if(t="string"==typeof t?t:a,!function(t){return d.indexOf(t)>=0}(t))throw new Error("Error in precision parameter: ".concat(t," is not a valid value"));return t}((t=t||{}).precision),i="function"==typeof t.callback?t.callback:function(){},w=!0===t.countdown,o=!0===w?-1:1,"object"===r(t.startValues)?(n=t.startValues,g=q(n),A.secondTenths=g[0],A.seconds=g[1],A.minutes=g[2],A.hours=g[3],A.days=g[4],P=G(g,P)):g=null,O=I(),z(),"object"===r(t.target)?b=F(t.target):w?(t.target={seconds:0},b=F(t.target)):b=null,L={precision:e,callback:i,countdown:"object"===r(t)&&!0===t.countdown,target:b,startValues:g},m=t}function q(t){var e;if("object"===r(t))if(t instanceof Array){if(5!==t.length)throw new Error("Array size not valid");e=t}else{for(var n in t)if(d.indexOf(n)<0)throw new Error("Error in startValues or target parameter: ".concat(n," is not a valid input value"));e=[t.secondTenths||0,t.seconds||0,t.minutes||0,t.hours||0,t.days||0]}e=e.map((function(t){return parseInt(t,10)}));var o=e[0],i=e[1]+B(o,10),s=e[2]+B(i,60),u=e[3]+B(s,60),c=e[4]+B(u,24);return e[0]=o%10,e[1]=i%60,e[2]=s%60,e[3]=u%24,e[4]=c,e}function B(t,e){var n=t/e;return n<0?Math.ceil(n):Math.floor(n)}function F(t){if(t){var e=G(b=q(t));return j=O+e.secondTenths*p[c]*o,b}}function G(t,e){var n=e||{};return n.days=t[4],n.hours=24*n.days+t[3],n.minutes=60*n.hours+t[2],n.seconds=60*n.minutes+t[1],n.secondTenths=10*n.seconds+t[[0]],n}function H(){M(),Q("stopped",x)}function J(t,e){S.on(t,e)}function K(t,e){S.removeListener(t,e)}function Q(t,e){S.emit(t,e)}function W(){return E}function X(){return D}R(T),void 0!==this&&(this.start=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t=n(n({},T),t),W()||(k(t),Q("started",x))},this.pause=function(){U(),D=!0,Q("paused",x)},this.stop=H,this.reset=function(){M(),k(m),Q("reset",x)},this.isRunning=W,this.isPaused=X,this.getTimeValues=function(){return A},this.getTotalTimeValues=function(){return P},this.getConfig=function(){return L},this.addEventListener=J,this.on=J,this.removeEventListener=K,this.removeAllEventListeners=function(t){S.removeAllListeners(t)},this.off=K)}t.Timer=m,t.default=m,Object.defineProperty(t,"__esModule",{value:!0})}));