tav-ui
Version:
78 lines (73 loc) • 2.51 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var core = require('@vueuse/core');
var is = require('../../../utils/is2.js');
var types = require('./types2.js');
var pluginVue_exportHelper = require('../../../../_virtual/plugin-vue_export-helper.js');
const _sfc_main = vue.defineComponent({
name: "TaCountTo",
props: types.countToProps,
emits: ["onStarted", "onFinished"],
setup(props, { emit }) {
const source = vue.ref(props.startVal);
const disabled = vue.ref(false);
let outputValue = core.useTransition(source);
const value = vue.computed(() => formatNumber(vue.unref(outputValue)));
vue.watchEffect(() => {
source.value = props.startVal;
});
vue.watch([() => props.startVal, () => props.endVal], () => {
if (props.autoplay) {
start();
}
});
vue.onMounted(() => {
props.autoplay && start();
});
function start() {
run();
source.value = props.endVal;
}
function reset() {
source.value = props.startVal;
run();
}
function run() {
outputValue = core.useTransition(source, {
disabled,
duration: props.duration,
onFinished: () => emit("onFinished"),
onStarted: () => emit("onStarted"),
...props.useEasing ? { transition: core.TransitionPresets[props.transition] } : {}
});
}
function formatNumber(num) {
if (!num && num !== 0) {
return "";
}
const { decimals, decimal, separator, suffix, prefix } = props;
num = Number(num).toFixed(decimals);
num += "";
const x = num.split(".");
let x1 = x[0];
const x2 = x.length > 1 ? decimal + x[1] : "";
const rgx = /(\d+)(\d{3})/;
if (separator && !is.isNumber(separator)) {
while (rgx.test(x1)) {
x1 = x1.replace(rgx, `$1${separator}$2`);
}
}
return prefix + x1 + x2 + suffix;
}
return { value, start, reset };
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return vue.openBlock(), vue.createElementBlock("span", {
style: vue.normalizeStyle({ color: _ctx.color })
}, vue.toDisplayString(_ctx.value), 5);
}
var CountTo = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/tav-ui/tav-ui/packages/components/count-to/src/count-to.vue"]]);
exports["default"] = CountTo;
//# sourceMappingURL=count-to2.js.map