|
| 1 | +var __defProp = Object.defineProperty; |
| 2 | +var __defProps = Object.defineProperties; |
| 3 | +var __getOwnPropDescs = Object.getOwnPropertyDescriptors; |
| 4 | +var __getOwnPropSymbols = Object.getOwnPropertySymbols; |
| 5 | +var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 6 | +var __propIsEnum = Object.prototype.propertyIsEnumerable; |
| 7 | +var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; |
| 8 | +var __spreadValues = (a, b) => { |
| 9 | + for (var prop in b || (b = {})) |
| 10 | + if (__hasOwnProp.call(b, prop)) |
| 11 | + __defNormalProp(a, prop, b[prop]); |
| 12 | + if (__getOwnPropSymbols) |
| 13 | + for (var prop of __getOwnPropSymbols(b)) { |
| 14 | + if (__propIsEnum.call(b, prop)) |
| 15 | + __defNormalProp(a, prop, b[prop]); |
| 16 | + } |
| 17 | + return a; |
| 18 | +}; |
| 19 | +var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); |
| 20 | +import { defineComponent, ref, watch, onMounted, openBlock, createElementBlock } from "vue"; |
| 21 | +import { CountUp } from "countup.js"; |
| 22 | +const __default__ = { |
| 23 | + name: "CountUp" |
| 24 | +}; |
| 25 | +const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__), { |
| 26 | + props: { |
| 27 | + endVal: null, |
| 28 | + startVal: { default: 0 }, |
| 29 | + duration: { default: 2.5 }, |
| 30 | + autoplay: { type: Boolean, default: true }, |
| 31 | + options: { default: void 0 } |
| 32 | + }, |
| 33 | + emits: ["init"], |
| 34 | + setup(__props, { emit: emits }) { |
| 35 | + const props = __props; |
| 36 | + let ElRef = ref(); |
| 37 | + let countUp = ref(); |
| 38 | + const startAnim = () => { |
| 39 | + var _a; |
| 40 | + (_a = countUp.value) == null ? void 0 : _a.start(); |
| 41 | + }; |
| 42 | + const initCountUp = () => { |
| 43 | + if (!ElRef.value) |
| 44 | + return; |
| 45 | + const startVal = Number(props.startVal); |
| 46 | + const endVal = Number(props.endVal); |
| 47 | + const duration = Number(props.duration); |
| 48 | + countUp.value = new CountUp(ElRef.value, endVal, __spreadValues({ |
| 49 | + startVal, |
| 50 | + duration |
| 51 | + }, props.options)); |
| 52 | + if (countUp.value.error) { |
| 53 | + console.error(countUp.value.error); |
| 54 | + return; |
| 55 | + } |
| 56 | + emits("init", countUp.value); |
| 57 | + }; |
| 58 | + watch(() => props.endVal, (value) => { |
| 59 | + var _a; |
| 60 | + if (props.autoplay) { |
| 61 | + (_a = countUp.value) == null ? void 0 : _a.update(value); |
| 62 | + } |
| 63 | + }); |
| 64 | + onMounted(() => { |
| 65 | + initCountUp(); |
| 66 | + if (props.autoplay) { |
| 67 | + startAnim(); |
| 68 | + } |
| 69 | + }); |
| 70 | + return (_ctx, _cache) => { |
| 71 | + return openBlock(), createElementBlock("div", { |
| 72 | + ref_key: "ElRef", |
| 73 | + ref: ElRef |
| 74 | + }, null, 512); |
| 75 | + }; |
| 76 | + } |
| 77 | +})); |
| 78 | +export { _sfc_main as default }; |
0 commit comments