UNPKG

@ctsy/layui-vue

Version:

a component library for Vue 3 base on layui-vue

96 lines (95 loc) 3.44 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import { defineComponent, ref, computed, watch, onMounted, openBlock, createElementBlock, Fragment, renderSlot, createElementVNode, toDisplayString, unref } from "vue"; import { T as TransitionPresets, u as useTransition } from "../index4.js"; const __default__ = { name: "LayCountUp" }; const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__), { props: { startVal: { default: 0 }, endVal: { default: 0 }, decimal: { default: "." }, decimalPlaces: { default: 0 }, useGrouping: { type: Boolean, default: true }, separator: { default: "," }, autoplay: { type: Boolean, default: true }, useEasing: { type: Boolean, default: true }, easingFn: { default: TransitionPresets.easeInOutCubic }, duration: { default: 2e3 }, prefix: { default: "" }, suffix: { default: "" } }, setup(__props, { expose }) { const props = __props; let localStartVal = ref(props.startVal); const isNumber = (val) => !isNaN(parseFloat(val)); const formatNumber = (num) => { if (typeof num != "number") return "0"; num = num.toFixed(props.decimalPlaces); num += ""; const x = num.split("."); let x1 = x[0]; const x2 = x.length > 1 ? props.decimal + x[1] : ""; const rgx = /(\d+)(\d{3})/; if (props.separator && !isNumber(props.separator)) { while (rgx.test(x1)) { x1 = x1.replace(rgx, "$1" + props.separator + "$2"); } } return props.prefix + x1 + x2 + props.suffix; }; const printVal = useTransition(localStartVal, { delay: 0, duration: props.duration, disabled: !props.useEasing, transition: typeof props.easingFn === "string" ? TransitionPresets[props.easingFn] : props.easingFn }); const displayValue = computed(() => formatNumber(printVal.value)); const start = function() { localStartVal.value = props.endVal; }; watch(() => props.endVal, () => { if (props.autoplay) { localStartVal.value = props.endVal; } }); onMounted(() => { if (props.autoplay) { start(); } }); expose({ start }); return (_ctx, _cache) => { return openBlock(), createElementBlock(Fragment, null, [ renderSlot(_ctx.$slots, "prefix"), createElementVNode("span", null, toDisplayString(unref(displayValue)), 1), renderSlot(_ctx.$slots, "suffix") ], 64); }; } })); _sfc_main.install = (app) => { app.component(_sfc_main.name, _sfc_main); }; export { _sfc_main as default };