Files

2 lines
6.8 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
!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).countUp={})}(this,(function(t){"use strict";var e=function(){return e=Object.assign||function(t){for(var e,i=1,s=arguments.length;i<s;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},e.apply(this,arguments)},i=function(){function t(t,i,s){var n=this;this.endVal=i,this.options=s,this.version="2.10.0",this.defaults={startVal:0,decimalPlaces:0,duration:2,useEasing:!0,useGrouping:!0,useIndianSeparators:!1,smartEasingThreshold:999,smartEasingAmount:333,separator:",",decimal:".",prefix:"",suffix:"",autoAnimate:!1,autoAnimateDelay:200,autoAnimateOnce:!1},this.finalEndVal=null,this.useEasing=!0,this.countDown=!1,this.error="",this.startVal=0,this.paused=!0,this.once=!1,this.count=function(t){n.startTime||(n.startTime=t);var e=t-n.startTime;n.remaining=n.duration-e,n.useEasing?n.countDown?n.frameVal=n.startVal-n.easingFn(e,0,n.startVal-n.endVal,n.duration):n.frameVal=n.easingFn(e,n.startVal,n.endVal-n.startVal,n.duration):n.frameVal=n.startVal+(n.endVal-n.startVal)*(e/n.duration);var i=n.countDown?n.frameVal<n.endVal:n.frameVal>n.endVal;n.frameVal=i?n.endVal:n.frameVal,n.frameVal=Number(n.frameVal.toFixed(n.options.decimalPlaces)),n.printValue(n.frameVal),e<n.duration?n.rAF=requestAnimationFrame(n.count):null!==n.finalEndVal?n.update(n.finalEndVal):n.options.onCompleteCallback&&n.options.onCompleteCallback()},this.formatNumber=function(t){var e,i,s,a,o=t<0?"-":"";e=Math.abs(t).toFixed(n.options.decimalPlaces);var r=(e+="").split(".");if(i=r[0],s=r.length>1?n.options.decimal+r[1]:"",n.options.useGrouping){a="";for(var l=3,u=0,h=0,p=i.length;h<p;++h)n.options.useIndianSeparators&&4===h&&(l=2,u=1),0!==h&&u%l==0&&(a=n.options.separator+a),u++,a=i[p-h-1]+a;i=a}return n.options.numerals&&n.options.numerals.length&&(i=i.replace(/[0-9]/g,(function(t){return n.options.numerals[+t]})),s=s.replace(/[0-9]/g,(function(t){return n.options.numerals[+t]}))),o+n.options.prefix+i+s+n.options.suffix},this.easeOutExpo=function(t,e,i,s){return i*(1-Math.pow(2,-10*t/s))*1024/1023+e},this.options=e(e({},this.defaults),s),this.options.enableScrollSpy&&(this.options.autoAnimate=!0),void 0!==this.options.scrollSpyDelay&&(this.options.autoAnimateDelay=this.options.scrollSpyDelay),this.options.scrollSpyOnce&&(this.options.autoAnimateOnce=!0),this.formattingFn=this.options.formattingFn?this.options.formattingFn:this.formatNumber,this.easingFn=this.options.easingFn?this.options.easingFn:this.easeOutExpo,this.el="string"==typeof t?document.getElementById(t):t,i=null==i?this.parse(this.el.innerHTML):i,this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.endVal=this.validateValue(i),this.options.decimalPlaces=Math.max(this.options.decimalPlaces),this.resetDuration(),this.options.separator=String(this.options.separator),this.useEasing=this.options.useEasing,""===this.options.separator&&(this.options.useGrouping=!1),this.el?this.printValue(this.startVal):this.error="[CountUp] target is null or undefined","undefined"!=typeof window&&this.options.autoAnimate&&(this.error||"undefined"==typeof IntersectionObserver?this.error?console.error(this.error,t):console.error("IntersectionObserver is not supported by this browser"):this.setupObserver())}return t.prototype.setupObserver=function(){var e=this,i=t.observedElements.get(this.el);i&&i.unobserve(),t.observedElements.set(this.el,this),this.observer=new IntersectionObserver((function(t){for(var i=0,s=t;i<s.length;i++){var n=s[i];n.isIntersecting&&e.paused&&!e.once?(e.paused=!1,e.autoAnimateTimeout=setTimeout((function(){return e.start()}),e.options.autoAnimateDelay),e.options.autoAnimateOnce&&(e.once=!0,e.observer.disconnect())):n.isIntersecting||e.paused||(clearTimeout(e.autoAnimateTimeout),e.reset())}}),{threshold:0}),this.observer.observe(this.el)},t.prototype.unobserve=function(){var e;clearTimeout(this.autoAnimateTimeout),null===(e=this.observer)||void 0===e||e.disconnect(),t.observedElements.delete(this.el)},t.prototype.onDestroy=function(){clearTimeout(this.autoAnimateTimeout),cancelAnimationFrame(this.rAF),this.paused=!0,this.unobserve(),this.options.onCompleteCallback=null,this.options.onStartCallback=null},t.prototype.determineDirectionAndSmartEasing=function(){var t=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>t;var e=t-this.startVal;if(Math.abs(e)>this.options.smartEasingThreshold&&this.options.useEasing){this.finalEndVal=t;var i=this.countDown?1:-1;this.endVal=t+i*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=t,this.finalEndVal=null;null!==this.finalEndVal?this.useEasing=!1:this.useEasing=this.options.useEasing},t.prototype.start=function(t){this.error||(this.options.onStartCallback&&this.options.onStartCallback(),t&&(this.options.onCompleteCallback=t),this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},t.prototype.pauseResume=function(){this.paused?(this.startTime=null,this.duration=this.remaining,this.startVal=this.frameVal,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count)):cancelAnimationFrame(this.rAF),this.paused=!this.paused},t.prototype.reset=function(){clearTimeout(this.autoAnimateTimeout),cancelAnimationFrame(this.rAF),this.paused=!0,this.once=!1,this.resetDuration(),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.printValue(this.startVal)},t.prototype.update=function(t){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(t),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,null==this.finalEndVal&&this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},t.prototype.printValue=function(t){var e;if(this.el){var i=this.formattingFn(t);if(null===(e=this.options.plugin)||void 0===e?void 0:e.render)this.options.plugin.render(this.el,i);else if("INPUT"===this.el.tagName)this.el.value=i;else"text"===this.el.tagName||"tspan"===this.el.tagName?this.el.textContent=i:this.el.innerHTML=i}},t.prototype.ensureNumber=function(t){return"number"==typeof t&&!isNaN(t)},t.prototype.validateValue=function(t){var e=Number(t);return this.ensureNumber(e)?e:(this.error="[CountUp] invalid start or end value: ".concat(t),null)},t.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},t.prototype.parse=function(t){var e=function(t){return t.replace(/([.,'  ])/g,"\\$1")},i=e(this.options.separator),s=e(this.options.decimal),n=t.replace(new RegExp(i,"g"),"").replace(new RegExp(s,"g"),".");return parseFloat(n)},t.observedElements=new WeakMap,t}();t.CountUp=i}));