vue-countup-v3
Advanced tools
Comparing version
@@ -1,100 +0,84 @@ | ||
export type { CountUp as ICountUp, CountUpOptions } from 'countup.js'; | ||
import { CountUp } from 'countup.js'; | ||
import type { CountUpOptions } from 'countup.js'; | ||
declare const _default: import("vue").DefineComponent<{ | ||
endVal: { | ||
type: import("vue").PropType<string | number>; | ||
required: true; | ||
}; | ||
startVal: { | ||
type: import("vue").PropType<string | number>; | ||
} & { | ||
default: number; | ||
}; | ||
duration: { | ||
type: import("vue").PropType<string | number>; | ||
} & { | ||
default: number; | ||
}; | ||
decimalPlaces: { | ||
type: import("vue").PropType<number>; | ||
} & { | ||
default: number; | ||
}; | ||
autoplay: { | ||
type: import("vue").PropType<boolean>; | ||
} & { | ||
default: boolean; | ||
}; | ||
loop: { | ||
type: import("vue").PropType<number | boolean>; | ||
} & { | ||
default: boolean; | ||
}; | ||
delay: { | ||
type: import("vue").PropType<number>; | ||
} & { | ||
default: number; | ||
}; | ||
options: { | ||
type: import("vue").PropType<CountUpOptions>; | ||
} & { | ||
default: undefined; | ||
}; | ||
}, () => void, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, { | ||
export type { CountUp as ICountUp, CountUpOptions } from 'countup.js'; | ||
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<{ | ||
endVal: number | string; | ||
startVal?: string | number | undefined; | ||
duration?: string | number | undefined; | ||
decimalPlaces?: number | undefined; | ||
autoplay?: boolean | undefined; | ||
loop?: number | boolean | undefined; | ||
delay?: number | undefined; | ||
options?: CountUpOptions | undefined; | ||
}>, { | ||
startVal: number; | ||
duration: number; | ||
decimalPlaces: number; | ||
autoplay: boolean; | ||
loop: boolean; | ||
delay: number; | ||
ignorePart: undefined; | ||
options: undefined; | ||
}>, { | ||
init: () => void; | ||
restart: () => void; | ||
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, { | ||
init: (countup: CountUp) => void; | ||
} & { | ||
finished: () => void; | ||
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{ | ||
endVal: { | ||
type: import("vue").PropType<string | number>; | ||
required: true; | ||
}; | ||
startVal: { | ||
type: import("vue").PropType<string | number>; | ||
} & { | ||
default: number; | ||
}; | ||
duration: { | ||
type: import("vue").PropType<string | number>; | ||
} & { | ||
default: number; | ||
}; | ||
decimalPlaces: { | ||
type: import("vue").PropType<number>; | ||
} & { | ||
default: number; | ||
}; | ||
autoplay: { | ||
type: import("vue").PropType<boolean>; | ||
} & { | ||
default: boolean; | ||
}; | ||
loop: { | ||
type: import("vue").PropType<number | boolean>; | ||
} & { | ||
default: boolean; | ||
}; | ||
delay: { | ||
type: import("vue").PropType<number>; | ||
} & { | ||
default: number; | ||
}; | ||
options: { | ||
type: import("vue").PropType<CountUpOptions>; | ||
} & { | ||
default: undefined; | ||
}; | ||
}>> & { | ||
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<{ | ||
endVal: number | string; | ||
startVal?: string | number | undefined; | ||
duration?: string | number | undefined; | ||
decimalPlaces?: number | undefined; | ||
autoplay?: boolean | undefined; | ||
loop?: number | boolean | undefined; | ||
delay?: number | undefined; | ||
options?: CountUpOptions | undefined; | ||
}>, { | ||
startVal: number; | ||
duration: number; | ||
decimalPlaces: number; | ||
autoplay: boolean; | ||
loop: boolean; | ||
delay: number; | ||
ignorePart: undefined; | ||
options: undefined; | ||
}>>> & { | ||
onInit?: ((countup: CountUp) => any) | undefined; | ||
onFinished?: (() => any) | undefined; | ||
onInit?: ((countup: CountUp) => any) | undefined; | ||
}, { | ||
options: CountUpOptions; | ||
duration: string | number; | ||
startVal: number | string; | ||
duration: number | string; | ||
decimalPlaces: number; | ||
autoplay: boolean; | ||
loop: number | boolean; | ||
startVal: string | number; | ||
decimalPlaces: number; | ||
loop: boolean | number; | ||
delay: number; | ||
options: CountUpOptions; | ||
}, {}>, { | ||
prefix?(_: {}): any; | ||
suffix?(_: {}): any; | ||
}>; | ||
export default _default; | ||
type __VLS_WithDefaults<P, D> = { | ||
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & { | ||
default: D[K]; | ||
}> : P[K]; | ||
}; | ||
type __VLS_Prettify<T> = { | ||
[K in keyof T]: T[K]; | ||
} & {}; | ||
type __VLS_WithTemplateSlots<T, S> = T & { | ||
new (): { | ||
$slots: S; | ||
}; | ||
}; | ||
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T; | ||
type __VLS_TypePropsToOption<T> = { | ||
[K in keyof T]-?: {} extends Pick<T, K> ? { | ||
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>; | ||
} : { | ||
type: import('vue').PropType<T[K]>; | ||
required: true; | ||
}; | ||
}; |
@@ -1,172 +0,1 @@ | ||
import { ref as V, defineComponent as E, watch as w, onMounted as F, onUnmounted as b, openBlock as A, createElementBlock as S, renderSlot as y, createElementVNode as N } from "vue"; | ||
var g = function() { | ||
return g = Object.assign || function(s) { | ||
for (var e, i = 1, n = arguments.length; i < n; i++) | ||
for (var t in e = arguments[i]) | ||
Object.prototype.hasOwnProperty.call(e, t) && (s[t] = e[t]); | ||
return s; | ||
}, g.apply(this, arguments); | ||
}, C = function() { | ||
function s(e, i, n) { | ||
var t = this; | ||
this.endVal = i, this.options = n, this.version = "2.6.2", this.defaults = { startVal: 0, decimalPlaces: 0, duration: 2, useEasing: !0, useGrouping: !0, useIndianSeparators: !1, 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(a) { | ||
t.startTime || (t.startTime = a); | ||
var o = a - t.startTime; | ||
t.remaining = t.duration - o, t.useEasing ? t.countDown ? t.frameVal = t.startVal - t.easingFn(o, 0, t.startVal - t.endVal, t.duration) : t.frameVal = t.easingFn(o, t.startVal, t.endVal - t.startVal, t.duration) : t.frameVal = t.startVal + (t.endVal - t.startVal) * (o / t.duration); | ||
var r = t.countDown ? t.frameVal < t.endVal : t.frameVal > t.endVal; | ||
t.frameVal = r ? t.endVal : t.frameVal, t.frameVal = Number(t.frameVal.toFixed(t.options.decimalPlaces)), t.printValue(t.frameVal), o < t.duration ? t.rAF = requestAnimationFrame(t.count) : t.finalEndVal !== null ? t.update(t.finalEndVal) : t.options.onCompleteCallback && t.options.onCompleteCallback(); | ||
}, this.formatNumber = function(a) { | ||
var o, r, l, p, f = a < 0 ? "-" : ""; | ||
o = Math.abs(a).toFixed(t.options.decimalPlaces); | ||
var c = (o += "").split("."); | ||
if (r = c[0], l = c.length > 1 ? t.options.decimal + c[1] : "", t.options.useGrouping) { | ||
p = ""; | ||
for (var u = 3, h = 0, d = 0, m = r.length; d < m; ++d) | ||
t.options.useIndianSeparators && d === 4 && (u = 2, h = 1), d !== 0 && h % u == 0 && (p = t.options.separator + p), h++, p = r[m - d - 1] + p; | ||
r = p; | ||
} | ||
return t.options.numerals && t.options.numerals.length && (r = r.replace(/[0-9]/g, function(v) { | ||
return t.options.numerals[+v]; | ||
}), l = l.replace(/[0-9]/g, function(v) { | ||
return t.options.numerals[+v]; | ||
})), f + t.options.prefix + r + l + t.options.suffix; | ||
}, this.easeOutExpo = function(a, o, r, l) { | ||
return r * (1 - Math.pow(2, -10 * a / l)) * 1024 / 1023 + o; | ||
}, this.options = g(g({}, this.defaults), n), 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(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 = typeof e == "string" ? document.getElementById(e) : e, this.el ? this.printValue(this.startVal) : this.error = "[CountUp] target is null or undefined", typeof window < "u" && this.options.enableScrollSpy && (this.error ? console.error(this.error, e) : (window.onScrollFns = window.onScrollFns || [], window.onScrollFns.push(function() { | ||
return t.handleScroll(t); | ||
}), window.onscroll = function() { | ||
window.onScrollFns.forEach(function(a) { | ||
return a(); | ||
}); | ||
}, this.handleScroll(this))); | ||
} | ||
return s.prototype.handleScroll = function(e) { | ||
if (e && window && !e.once) { | ||
var i = window.innerHeight + window.scrollY, n = e.el.getBoundingClientRect(), t = n.top + window.pageYOffset, a = n.top + n.height + window.pageYOffset; | ||
a < i && a > window.scrollY && e.paused ? (e.paused = !1, setTimeout(function() { | ||
return e.start(); | ||
}, e.options.scrollSpyDelay), e.options.scrollSpyOnce && (e.once = !0)) : (window.scrollY > a || t > i) && !e.paused && e.reset(); | ||
} | ||
}, s.prototype.determineDirectionAndSmartEasing = function() { | ||
var e = this.finalEndVal ? this.finalEndVal : this.endVal; | ||
this.countDown = this.startVal > e; | ||
var i = e - this.startVal; | ||
if (Math.abs(i) > this.options.smartEasingThreshold && this.options.useEasing) { | ||
this.finalEndVal = e; | ||
var n = this.countDown ? 1 : -1; | ||
this.endVal = e + n * this.options.smartEasingAmount, this.duration = this.duration / 2; | ||
} else | ||
this.endVal = e, this.finalEndVal = null; | ||
this.finalEndVal !== null ? this.useEasing = !1 : this.useEasing = this.options.useEasing; | ||
}, s.prototype.start = function(e) { | ||
this.error || (e && (this.options.onCompleteCallback = e), 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(e) { | ||
cancelAnimationFrame(this.rAF), this.startTime = null, this.endVal = this.validateValue(e), 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(e) { | ||
var i; | ||
if (this.el) { | ||
var n = this.formattingFn(e); | ||
!((i = this.options.plugin) === null || i === void 0) && i.render ? this.options.plugin.render(this.el, n) : 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(e) { | ||
return typeof e == "number" && !isNaN(e); | ||
}, s.prototype.validateValue = function(e) { | ||
var i = Number(e); | ||
return this.ensureNumber(i) ? i : (this.error = "[CountUp] invalid start or end value: ".concat(e), null); | ||
}, s.prototype.resetDuration = function() { | ||
this.startTime = null, this.duration = 1e3 * Number(this.options.duration), this.remaining = this.duration; | ||
}, s; | ||
}(); | ||
function D(s, e = 1) { | ||
const i = V(-1); | ||
let n; | ||
function t(o) { | ||
n || (n = o), o - n < e * 1e3 ? i.value = requestAnimationFrame(t) : s(); | ||
} | ||
i.value = requestAnimationFrame(t); | ||
function a() { | ||
window.cancelAnimationFrame(i.value); | ||
} | ||
return { cancel: a }; | ||
} | ||
const T = { class: "countup-wrap" }, x = { | ||
name: "CountUp" | ||
}, _ = /* @__PURE__ */ E({ | ||
...x, | ||
props: { | ||
endVal: null, | ||
startVal: { default: 0 }, | ||
duration: { default: 2.5 }, | ||
decimalPlaces: { default: 0 }, | ||
autoplay: { type: Boolean, default: !0 }, | ||
loop: { type: [Boolean, Number], default: !1 }, | ||
delay: { default: 0 }, | ||
options: { default: void 0 } | ||
}, | ||
emits: ["init", "finished"], | ||
setup(s, { expose: e, emit: i }) { | ||
const n = s; | ||
let t = V(), a = V(), o = 0; | ||
const r = V(!1); | ||
let l; | ||
function p() { | ||
if (!t.value) { | ||
console.warn("[vue-countup-v3]", "elRef can't found"); | ||
return; | ||
} | ||
o = 0, r.value = !1; | ||
const u = Number(n.startVal), h = Number(n.endVal), d = Number(n.duration); | ||
if (a.value = new C(t.value, h, { | ||
startVal: u, | ||
duration: d, | ||
decimalPlaces: n.decimalPlaces, | ||
...n.options | ||
}), a.value.error) { | ||
console.error("[vue-countup-v3]", a.value.error); | ||
return; | ||
} | ||
i("init", a.value); | ||
} | ||
function f() { | ||
var h; | ||
a.value || p(), (h = a.value) == null || h.start(u), o++; | ||
function u() { | ||
typeof n.loop == "boolean" && n.loop || n.loop > o ? l = D(() => { | ||
var m; | ||
(m = a.value) == null || m.reset(), f(); | ||
}, n.delay) : r.value = !0; | ||
} | ||
} | ||
function c() { | ||
l == null || l.cancel(), p(), f(); | ||
} | ||
return w([() => n.startVal, () => n.endVal], () => { | ||
n.autoplay && c(); | ||
}), w(r, (u) => { | ||
var h; | ||
u && ((h = n.options) != null && h.onCompleteCallback && n.options.onCompleteCallback(), i("finished")); | ||
}), F(() => { | ||
p(), n.autoplay && f(); | ||
}), b(() => { | ||
var u; | ||
l == null || l.cancel(), (u = a.value) == null || u.reset(); | ||
}), e({ | ||
init: p, | ||
restart: c | ||
}), (u, h) => (A(), S("div", T, [ | ||
y(u.$slots, "prefix"), | ||
N("span", { | ||
ref_key: "elRef", | ||
ref: t | ||
}, null, 512), | ||
y(u.$slots, "suffix") | ||
])); | ||
} | ||
}); | ||
export { | ||
_ as default | ||
}; | ||
import{defineComponent as t,ref as n,watch as i,onMounted as a,onUnmounted as e,openBlock as s,createElementBlock as o,renderSlot as r,createElementVNode as l}from"vue";var u=function(){return u=Object.assign||function(t){for(var n,i=1,a=arguments.length;i<a;i++)for(var e in n=arguments[i])Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e]);return t},u.apply(this,arguments)},h=function(){function t(t,n,i){var a=this;this.endVal=n,this.options=i,this.version="2.8.0",this.defaults={startVal:0,decimalPlaces:0,duration:2,useEasing:!0,useGrouping:!0,useIndianSeparators:!1,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(t){a.startTime||(a.startTime=t);var n=t-a.startTime;a.remaining=a.duration-n,a.useEasing?a.countDown?a.frameVal=a.startVal-a.easingFn(n,0,a.startVal-a.endVal,a.duration):a.frameVal=a.easingFn(n,a.startVal,a.endVal-a.startVal,a.duration):a.frameVal=a.startVal+(a.endVal-a.startVal)*(n/a.duration);var i=a.countDown?a.frameVal<a.endVal:a.frameVal>a.endVal;a.frameVal=i?a.endVal:a.frameVal,a.frameVal=Number(a.frameVal.toFixed(a.options.decimalPlaces)),a.printValue(a.frameVal),n<a.duration?a.rAF=requestAnimationFrame(a.count):null!==a.finalEndVal?a.update(a.finalEndVal):a.options.onCompleteCallback&&a.options.onCompleteCallback()},this.formatNumber=function(t){var n,i,e,s,o=t<0?"-":"";n=Math.abs(t).toFixed(a.options.decimalPlaces);var r=(n+="").split(".");if(i=r[0],e=r.length>1?a.options.decimal+r[1]:"",a.options.useGrouping){s="";for(var l=3,u=0,h=0,p=i.length;h<p;++h)a.options.useIndianSeparators&&4===h&&(l=2,u=1),0!==h&&u%l==0&&(s=a.options.separator+s),u++,s=i[p-h-1]+s;i=s}return a.options.numerals&&a.options.numerals.length&&(i=i.replace(/[0-9]/g,(function(t){return a.options.numerals[+t]})),e=e.replace(/[0-9]/g,(function(t){return a.options.numerals[+t]}))),o+a.options.prefix+i+e+a.options.suffix},this.easeOutExpo=function(t,n,i,a){return i*(1-Math.pow(2,-10*t/a))*1024/1023+n},this.options=u(u({},this.defaults),i),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="string"==typeof t?document.getElementById(t):t,this.el?this.printValue(this.startVal):this.error="[CountUp] target is null or undefined",typeof window<"u"&&this.options.enableScrollSpy&&(this.error?console.error(this.error,t):(window.onScrollFns=window.onScrollFns||[],window.onScrollFns.push((function(){return a.handleScroll(a)})),window.onscroll=function(){window.onScrollFns.forEach((function(t){return t()}))},this.handleScroll(this)))}return t.prototype.handleScroll=function(t){if(t&&window&&!t.once){var n=window.innerHeight+window.scrollY,i=t.el.getBoundingClientRect(),a=i.top+window.pageYOffset,e=i.top+i.height+window.pageYOffset;e<n&&e>window.scrollY&&t.paused?(t.paused=!1,setTimeout((function(){return t.start()}),t.options.scrollSpyDelay),t.options.scrollSpyOnce&&(t.once=!0)):(window.scrollY>e||a>n)&&!t.paused&&t.reset()}},t.prototype.determineDirectionAndSmartEasing=function(){var t=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>t;var n=t-this.startVal;if(Math.abs(n)>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(){cancelAnimationFrame(this.rAF),this.paused=!0,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 n;if(this.el){var i=this.formattingFn(t);null!==(n=this.options.plugin)&&void 0!==n&&n.render?this.options.plugin.render(this.el,i):"INPUT"===this.el.tagName?this.el.value=i:"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 n=Number(t);return this.ensureNumber(n)?n:(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}();const p={class:"countup-wrap"},c=t({name:"CountUp",props:{endVal:{},startVal:{default:0},duration:{default:2.5},decimalPlaces:{default:0},autoplay:{type:Boolean,default:!0},loop:{type:[Boolean,Number],default:!1},delay:{default:0},options:{default:void 0}},emits:["init","finished"],setup(t,{expose:u,emit:c}){const d=t,m=c;let f=n(),V=n(),g=0;const v=n(!1);let w;function y(){if(!f.value)return void console.warn("[vue-countup-v3]","elRef can't found");g=0,v.value=!1;const t=Number(d.startVal),n=Number(d.endVal),i=Number(d.duration);V.value=new h(f.value,n,{startVal:t,duration:i,decimalPlaces:d.decimalPlaces,...d.options}),V.value.error?console.error("[vue-countup-v3]",V.value.error):m("init",V.value)}function F(){var t;V.value||y(),null==(t=V.value)||t.start((function(){"boolean"==typeof d.loop&&d.loop||d.loop>g?w=function(t,i=1){const a=n(-1);let e;return a.value=requestAnimationFrame((function n(s){e||(e=s),s-e<1e3*i?a.value=requestAnimationFrame(n):t()})),{cancel:function(){window.cancelAnimationFrame(a.value)}}}((()=>{var t;null==(t=V.value)||t.reset(),F()}),d.delay):v.value=!0})),g++}function E(){null==w||w.cancel(),y(),F()}return i([()=>d.startVal,()=>d.endVal],(()=>{d.autoplay&&E()})),i(v,(t=>{var n;t&&(null!=(n=d.options)&&n.onCompleteCallback&&d.options.onCompleteCallback(),m("finished"))})),a((()=>{y(),d.autoplay&&F()})),e((()=>{var t;null==w||w.cancel(),null==(t=V.value)||t.reset()})),u({init:y,restart:E}),(t,n)=>(s(),o("div",p,[r(t.$slots,"prefix"),l("span",{ref_key:"elRef",ref:f},null,512),r(t.$slots,"suffix")]))}});export{c as default}; |
@@ -1,1 +0,1 @@ | ||
(function(s,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("vue")):typeof define=="function"&&define.amd?define(["vue"],c):(s=typeof globalThis<"u"?globalThis:s||self,s.VueCountUp=c(s.Vue))})(this,function(s){"use strict";var c=function(){return c=Object.assign||function(o){for(var e,i=1,n=arguments.length;i<n;i++)for(var t in e=arguments[i])Object.prototype.hasOwnProperty.call(e,t)&&(o[t]=e[t]);return o},c.apply(this,arguments)},y=function(){function o(e,i,n){var t=this;this.endVal=i,this.options=n,this.version="2.6.2",this.defaults={startVal:0,decimalPlaces:0,duration:2,useEasing:!0,useGrouping:!0,useIndianSeparators:!1,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(a){t.startTime||(t.startTime=a);var r=a-t.startTime;t.remaining=t.duration-r,t.useEasing?t.countDown?t.frameVal=t.startVal-t.easingFn(r,0,t.startVal-t.endVal,t.duration):t.frameVal=t.easingFn(r,t.startVal,t.endVal-t.startVal,t.duration):t.frameVal=t.startVal+(t.endVal-t.startVal)*(r/t.duration);var l=t.countDown?t.frameVal<t.endVal:t.frameVal>t.endVal;t.frameVal=l?t.endVal:t.frameVal,t.frameVal=Number(t.frameVal.toFixed(t.options.decimalPlaces)),t.printValue(t.frameVal),r<t.duration?t.rAF=requestAnimationFrame(t.count):t.finalEndVal!==null?t.update(t.finalEndVal):t.options.onCompleteCallback&&t.options.onCompleteCallback()},this.formatNumber=function(a){var r,l,u,d,V=a<0?"-":"";r=Math.abs(a).toFixed(t.options.decimalPlaces);var m=(r+="").split(".");if(l=m[0],u=m.length>1?t.options.decimal+m[1]:"",t.options.useGrouping){d="";for(var h=3,p=0,f=0,g=l.length;f<g;++f)t.options.useIndianSeparators&&f===4&&(h=2,p=1),f!==0&&p%h==0&&(d=t.options.separator+d),p++,d=l[g-f-1]+d;l=d}return t.options.numerals&&t.options.numerals.length&&(l=l.replace(/[0-9]/g,function(w){return t.options.numerals[+w]}),u=u.replace(/[0-9]/g,function(w){return t.options.numerals[+w]})),V+t.options.prefix+l+u+t.options.suffix},this.easeOutExpo=function(a,r,l,u){return l*(1-Math.pow(2,-10*a/u))*1024/1023+r},this.options=c(c({},this.defaults),n),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(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=typeof e=="string"?document.getElementById(e):e,this.el?this.printValue(this.startVal):this.error="[CountUp] target is null or undefined",typeof window<"u"&&this.options.enableScrollSpy&&(this.error?console.error(this.error,e):(window.onScrollFns=window.onScrollFns||[],window.onScrollFns.push(function(){return t.handleScroll(t)}),window.onscroll=function(){window.onScrollFns.forEach(function(a){return a()})},this.handleScroll(this)))}return o.prototype.handleScroll=function(e){if(e&&window&&!e.once){var i=window.innerHeight+window.scrollY,n=e.el.getBoundingClientRect(),t=n.top+window.pageYOffset,a=n.top+n.height+window.pageYOffset;a<i&&a>window.scrollY&&e.paused?(e.paused=!1,setTimeout(function(){return e.start()},e.options.scrollSpyDelay),e.options.scrollSpyOnce&&(e.once=!0)):(window.scrollY>a||t>i)&&!e.paused&&e.reset()}},o.prototype.determineDirectionAndSmartEasing=function(){var e=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>e;var i=e-this.startVal;if(Math.abs(i)>this.options.smartEasingThreshold&&this.options.useEasing){this.finalEndVal=e;var n=this.countDown?1:-1;this.endVal=e+n*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=e,this.finalEndVal=null;this.finalEndVal!==null?this.useEasing=!1:this.useEasing=this.options.useEasing},o.prototype.start=function(e){this.error||(e&&(this.options.onCompleteCallback=e),this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},o.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},o.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)},o.prototype.update=function(e){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(e),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,this.finalEndVal==null&&this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},o.prototype.printValue=function(e){var i;if(this.el){var n=this.formattingFn(e);!((i=this.options.plugin)===null||i===void 0)&&i.render?this.options.plugin.render(this.el,n):this.el.tagName==="INPUT"?this.el.value=n:this.el.tagName==="text"||this.el.tagName==="tspan"?this.el.textContent=n:this.el.innerHTML=n}},o.prototype.ensureNumber=function(e){return typeof e=="number"&&!isNaN(e)},o.prototype.validateValue=function(e){var i=Number(e);return this.ensureNumber(i)?i:(this.error="[CountUp] invalid start or end value: ".concat(e),null)},o.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},o}();function v(o,e=1){const i=s.ref(-1);let n;function t(r){n||(n=r),r-n<e*1e3?i.value=requestAnimationFrame(t):o()}i.value=requestAnimationFrame(t);function a(){window.cancelAnimationFrame(i.value)}return{cancel:a}}const E={class:"countup-wrap"},F={name:"CountUp"};return s.defineComponent({...F,props:{endVal:null,startVal:{default:0},duration:{default:2.5},decimalPlaces:{default:0},autoplay:{type:Boolean,default:!0},loop:{type:[Boolean,Number],default:!1},delay:{default:0},options:{default:void 0}},emits:["init","finished"],setup(o,{expose:e,emit:i}){const n=o;let t=s.ref(),a=s.ref(),r=0;const l=s.ref(!1);let u;function d(){if(!t.value){console.warn("[vue-countup-v3]","elRef can't found");return}r=0,l.value=!1;const h=Number(n.startVal),p=Number(n.endVal),f=Number(n.duration);if(a.value=new y(t.value,p,{startVal:h,duration:f,decimalPlaces:n.decimalPlaces,...n.options}),a.value.error){console.error("[vue-countup-v3]",a.value.error);return}i("init",a.value)}function V(){var p;a.value||d(),(p=a.value)==null||p.start(h),r++;function h(){typeof n.loop=="boolean"&&n.loop||n.loop>r?u=v(()=>{var g;(g=a.value)==null||g.reset(),V()},n.delay):l.value=!0}}function m(){u==null||u.cancel(),d(),V()}return s.watch([()=>n.startVal,()=>n.endVal],()=>{n.autoplay&&m()}),s.watch(l,h=>{var p;h&&((p=n.options)!=null&&p.onCompleteCallback&&n.options.onCompleteCallback(),i("finished"))}),s.onMounted(()=>{d(),n.autoplay&&V()}),s.onUnmounted(()=>{var h;u==null||u.cancel(),(h=a.value)==null||h.reset()}),e({init:d,restart:m}),(h,p)=>(s.openBlock(),s.createElementBlock("div",E,[s.renderSlot(h.$slots,"prefix"),s.createElementVNode("span",{ref_key:"elRef",ref:t},null,512),s.renderSlot(h.$slots,"suffix")]))}})}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("vue")):"function"==typeof define&&define.amd?define(["vue"],n):(t="undefined"!=typeof globalThis?globalThis:t||self).VueCountUp=n(t.Vue)}(this,(function(t){"use strict";var n=function(){return n=Object.assign||function(t){for(var n,e=1,i=arguments.length;e<i;e++)for(var a in n=arguments[e])Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a]);return t},n.apply(this,arguments)},e=function(){function t(t,e,i){var a=this;this.endVal=e,this.options=i,this.version="2.8.0",this.defaults={startVal:0,decimalPlaces:0,duration:2,useEasing:!0,useGrouping:!0,useIndianSeparators:!1,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(t){a.startTime||(a.startTime=t);var n=t-a.startTime;a.remaining=a.duration-n,a.useEasing?a.countDown?a.frameVal=a.startVal-a.easingFn(n,0,a.startVal-a.endVal,a.duration):a.frameVal=a.easingFn(n,a.startVal,a.endVal-a.startVal,a.duration):a.frameVal=a.startVal+(a.endVal-a.startVal)*(n/a.duration);var e=a.countDown?a.frameVal<a.endVal:a.frameVal>a.endVal;a.frameVal=e?a.endVal:a.frameVal,a.frameVal=Number(a.frameVal.toFixed(a.options.decimalPlaces)),a.printValue(a.frameVal),n<a.duration?a.rAF=requestAnimationFrame(a.count):null!==a.finalEndVal?a.update(a.finalEndVal):a.options.onCompleteCallback&&a.options.onCompleteCallback()},this.formatNumber=function(t){var n,e,i,s,o=t<0?"-":"";n=Math.abs(t).toFixed(a.options.decimalPlaces);var r=(n+="").split(".");if(e=r[0],i=r.length>1?a.options.decimal+r[1]:"",a.options.useGrouping){s="";for(var l=3,u=0,h=0,p=e.length;h<p;++h)a.options.useIndianSeparators&&4===h&&(l=2,u=1),0!==h&&u%l==0&&(s=a.options.separator+s),u++,s=e[p-h-1]+s;e=s}return a.options.numerals&&a.options.numerals.length&&(e=e.replace(/[0-9]/g,(function(t){return a.options.numerals[+t]})),i=i.replace(/[0-9]/g,(function(t){return a.options.numerals[+t]}))),o+a.options.prefix+e+i+a.options.suffix},this.easeOutExpo=function(t,n,e,i){return e*(1-Math.pow(2,-10*t/i))*1024/1023+n},this.options=n(n({},this.defaults),i),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(e),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="string"==typeof t?document.getElementById(t):t,this.el?this.printValue(this.startVal):this.error="[CountUp] target is null or undefined",typeof window<"u"&&this.options.enableScrollSpy&&(this.error?console.error(this.error,t):(window.onScrollFns=window.onScrollFns||[],window.onScrollFns.push((function(){return a.handleScroll(a)})),window.onscroll=function(){window.onScrollFns.forEach((function(t){return t()}))},this.handleScroll(this)))}return t.prototype.handleScroll=function(t){if(t&&window&&!t.once){var n=window.innerHeight+window.scrollY,e=t.el.getBoundingClientRect(),i=e.top+window.pageYOffset,a=e.top+e.height+window.pageYOffset;a<n&&a>window.scrollY&&t.paused?(t.paused=!1,setTimeout((function(){return t.start()}),t.options.scrollSpyDelay),t.options.scrollSpyOnce&&(t.once=!0)):(window.scrollY>a||i>n)&&!t.paused&&t.reset()}},t.prototype.determineDirectionAndSmartEasing=function(){var t=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>t;var n=t-this.startVal;if(Math.abs(n)>this.options.smartEasingThreshold&&this.options.useEasing){this.finalEndVal=t;var e=this.countDown?1:-1;this.endVal=t+e*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(){cancelAnimationFrame(this.rAF),this.paused=!0,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 n;if(this.el){var e=this.formattingFn(t);null!==(n=this.options.plugin)&&void 0!==n&&n.render?this.options.plugin.render(this.el,e):"INPUT"===this.el.tagName?this.el.value=e:"text"===this.el.tagName||"tspan"===this.el.tagName?this.el.textContent=e:this.el.innerHTML=e}},t.prototype.ensureNumber=function(t){return"number"==typeof t&&!isNaN(t)},t.prototype.validateValue=function(t){var n=Number(t);return this.ensureNumber(n)?n:(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}();const i={class:"countup-wrap"};return t.defineComponent({name:"CountUp",props:{endVal:{},startVal:{default:0},duration:{default:2.5},decimalPlaces:{default:0},autoplay:{type:Boolean,default:!0},loop:{type:[Boolean,Number],default:!1},delay:{default:0},options:{default:void 0}},emits:["init","finished"],setup(n,{expose:a,emit:s}){const o=n,r=s;let l=t.ref(),u=t.ref(),h=0;const p=t.ref(!1);let d;function c(){if(!l.value)return void console.warn("[vue-countup-v3]","elRef can't found");h=0,p.value=!1;const t=Number(o.startVal),n=Number(o.endVal),i=Number(o.duration);u.value=new e(l.value,n,{startVal:t,duration:i,decimalPlaces:o.decimalPlaces,...o.options}),u.value.error?console.error("[vue-countup-v3]",u.value.error):r("init",u.value)}function f(){var n;u.value||c(),null==(n=u.value)||n.start((function(){"boolean"==typeof o.loop&&o.loop||o.loop>h?d=function(n,e=1){const i=t.ref(-1);let a;return i.value=requestAnimationFrame((function t(s){a||(a=s),s-a<1e3*e?i.value=requestAnimationFrame(t):n()})),{cancel:function(){window.cancelAnimationFrame(i.value)}}}((()=>{var t;null==(t=u.value)||t.reset(),f()}),o.delay):p.value=!0})),h++}function m(){null==d||d.cancel(),c(),f()}return t.watch([()=>o.startVal,()=>o.endVal],(()=>{o.autoplay&&m()})),t.watch(p,(t=>{var n;t&&(null!=(n=o.options)&&n.onCompleteCallback&&o.options.onCompleteCallback(),r("finished"))})),t.onMounted((()=>{c(),o.autoplay&&f()})),t.onUnmounted((()=>{var t;null==d||d.cancel(),null==(t=u.value)||t.reset()})),a({init:c,restart:m}),(n,e)=>(t.openBlock(),t.createElementBlock("div",i,[t.renderSlot(n.$slots,"prefix"),t.createElementVNode("span",{ref_key:"elRef",ref:l},null,512),t.renderSlot(n.$slots,"suffix")]))}})})); |
{ | ||
"name": "vue-countup-v3", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "Vue 3 component wrap for countUp.js,and expand some features.", | ||
@@ -28,7 +28,8 @@ "keywords": [ | ||
"license": "MIT", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"release": "node scripts/release.js", | ||
"build": "vite build && npm run build:dts", | ||
"build:dts": "vue-tsc --declaration --emitDeclarationOnly --declarationDir dist", | ||
"release": "node scripts/release.cjs", | ||
"build": "vite build && npm run build:dts && rollup -c", | ||
"build:dts": "vue-tsc --declaration --emitDeclarationOnly", | ||
"check:type": "vue-tsc --noEmit", | ||
@@ -46,4 +47,7 @@ "lint": "eslint src --fix --ext .ts,.tsx,.vue,.js,.jsx", | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.24.5", | ||
"@commitlint/cli": "^16.2.3", | ||
"@commitlint/config-conventional": "^16.2.1", | ||
"@rollup/plugin-babel": "^6.0.4", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@types/node": "^20.11.0", | ||
@@ -66,6 +70,6 @@ "@typescript-eslint/eslint-plugin": "^5.13.0", | ||
"semver": "^7.3.5", | ||
"typescript": "^4.5.4", | ||
"typescript": "^5.2.2", | ||
"vite": "^5.0.11", | ||
"vue": "^3.2.31", | ||
"vue-tsc": "^0.29.8" | ||
"vue-tsc": "^2.0.6" | ||
}, | ||
@@ -72,0 +76,0 @@ "lint-staged": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40027
11.72%8
14.29%Yes
NaN26
13.04%325
-4.69%