countUp.min.9e8207da.js 5.2 KB

1
  1. var c=globalThis&&globalThis.__assign||function(){return(c=Object.assign||function(s){for(var i,n=1,r=arguments.length;n<r;n++)for(var t in i=arguments[n])Object.prototype.hasOwnProperty.call(i,t)&&(s[t]=i[t]);return s}).apply(this,arguments)},V=function(){function s(i,n,r){var t=this;this.endVal=n,this.options=r,this.version="2.3.2",this.defaults={startVal:0,decimalPlaces:0,duration:2,useEasing:!0,useGrouping:!0,smartEasingThreshold:999,smartEasingAmount:333,separator:",",decimal:".",prefix:"",suffix:"",enableScrollSpy:!1,scrollSpyDelay:200,scrollSpyOnce:!1},this.finalEndVal=null,this.useEasing=!0,this.countDown=!1,this.error="",this.startVal=0,this.paused=!0,this.once=!1,this.count=function(o){t.startTime||(t.startTime=o);var e=o-t.startTime;t.remaining=t.duration-e,t.useEasing?t.countDown?t.frameVal=t.startVal-t.easingFn(e,0,t.startVal-t.endVal,t.duration):t.frameVal=t.easingFn(e,t.startVal,t.endVal-t.startVal,t.duration):t.frameVal=t.startVal+(t.endVal-t.startVal)*(e/t.duration);var a=t.countDown?t.frameVal<t.endVal:t.frameVal>t.endVal;t.frameVal=a?t.endVal:t.frameVal,t.frameVal=Number(t.frameVal.toFixed(t.options.decimalPlaces)),t.printValue(t.frameVal),e<t.duration?t.rAF=requestAnimationFrame(t.count):t.finalEndVal!==null?t.update(t.finalEndVal):t.callback&&t.callback()},this.formatNumber=function(o){var e,a,l,h,f=o<0?"-":"";e=Math.abs(o).toFixed(t.options.decimalPlaces);var p=(e+="").split(".");if(a=p[0],l=p.length>1?t.options.decimal+p[1]:"",t.options.useGrouping){h="";for(var u=0,m=a.length;u<m;++u)u!==0&&u%3==0&&(h=t.options.separator+h),h=a[m-u-1]+h;a=h}return t.options.numerals&&t.options.numerals.length&&(a=a.replace(/[0-9]/g,function(d){return t.options.numerals[+d]}),l=l.replace(/[0-9]/g,function(d){return t.options.numerals[+d]})),f+t.options.prefix+a+l+t.options.suffix},this.easeOutExpo=function(o,e,a,l){return a*(1-Math.pow(2,-10*o/l))*1024/1023+e},this.options=c(c({},this.defaults),r),this.formattingFn=this.options.formattingFn?this.options.formattingFn:this.formatNumber,this.easingFn=this.options.easingFn?this.options.easingFn:this.easeOutExpo,this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.endVal=this.validateValue(n),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=typeof i=="string"?document.getElementById(i):i,this.el?this.printValue(this.startVal):this.error="[CountUp] target is null or undefined",typeof window!="undefined"&&this.options.enableScrollSpy&&(this.error?console.error(this.error,i):(window.onScrollFns=window.onScrollFns||[],window.onScrollFns.push(function(){return t.handleScroll(t)}),window.onscroll=function(){window.onScrollFns.forEach(function(o){return o()})},this.handleScroll(this)))}return s.prototype.handleScroll=function(i){if(i&&window&&!i.once){var n=window.innerHeight+window.scrollY,r=i.el.getBoundingClientRect(),t=r.top+r.height+window.pageYOffset;t<n&&t>window.scrollY&&i.paused?(i.paused=!1,setTimeout(function(){return i.start()},i.options.scrollSpyDelay),i.options.scrollSpyOnce&&(i.once=!0)):window.scrollY>t&&!i.paused&&i.reset()}},s.prototype.determineDirectionAndSmartEasing=function(){var i=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>i;var n=i-this.startVal;if(Math.abs(n)>this.options.smartEasingThreshold&&this.options.useEasing){this.finalEndVal=i;var r=this.countDown?1:-1;this.endVal=i+r*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=i,this.finalEndVal=null;this.finalEndVal!==null?this.useEasing=!1:this.useEasing=this.options.useEasing},s.prototype.start=function(i){this.error||(this.callback=i,this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},s.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},s.prototype.reset=function(){cancelAnimationFrame(this.rAF),this.paused=!0,this.resetDuration(),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.printValue(this.startVal)},s.prototype.update=function(i){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(i),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,this.finalEndVal==null&&this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},s.prototype.printValue=function(i){var n=this.formattingFn(i);this.el.tagName==="INPUT"?this.el.value=n:this.el.tagName==="text"||this.el.tagName==="tspan"?this.el.textContent=n:this.el.innerHTML=n},s.prototype.ensureNumber=function(i){return typeof i=="number"&&!isNaN(i)},s.prototype.validateValue=function(i){var n=Number(i);return this.ensureNumber(n)?n:(this.error="[CountUp] invalid start or end value: ".concat(i),null)},s.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},s}();export{V as C};