import { defineComponent as N, ref as m, computed as $, unref as T, watchEffect as B, watch as C, onMounted as E, openBlock as F, createElementBlock as k, normalizeStyle as w, toDisplayString as P } from "vue";
import { useTransition as y, TransitionPresets as z } from "@vueuse/core";
const D = {
  startVal: { type: Number, default: 0 },
  endVal: { type: Number, default: 0 },
  duration: { type: Number, default: 1500 },
  autoplay: { type: Boolean, default: !0 },
  decimals: {
    type: Number,
    default: 0,
    validator(t) {
      return t >= 0;
    }
  },
  prefix: { type: String, default: "" },
  suffix: { type: String, default: "" },
  separator: { type: String, default: "," },
  decimal: { type: String, default: "." },
  color: { type: String },
  useEasing: { type: Boolean, default: !0 },
  transition: { type: String, default: "linear" }
}, G = "G", M = N({
  name: `${G}CountTo`,
  props: D,
  emits: ["onStarted", "onFinished"],
  setup(t, { emit: a }) {
    const e = m(t.startVal), i = m(!1);
    let o = y(e);
    const f = $(() => S(T(o)));
    B(() => {
      e.value = t.startVal;
    }), C([() => t.startVal, () => t.endVal], () => {
      t.autoplay && l();
    }), E(() => {
      t.autoplay && l();
    });
    function l() {
      d(), e.value = t.endVal;
    }
    function g() {
      e.value = t.startVal, d();
    }
    function d() {
      o = y(e, {
        disabled: i,
        duration: t.duration,
        onFinished: () => a("onFinished"),
        onStarted: () => a("onStarted"),
        ...t.useEasing ? { transition: z[t.transition] } : {}
      });
    }
    function x(n) {
      return typeof n == "number";
    }
    function S(n) {
      if (!n && n !== 0)
        return "";
      const { decimals: b, decimal: V, separator: s, suffix: h, prefix: v } = t;
      n = Number(n).toFixed(b), n += "";
      const c = n.split(".");
      let u = c[0];
      const _ = c.length > 1 ? V + c[1] : "", p = /(\d+)(\d{3})/;
      if (s && !x(s))
        for (; p.test(u); )
          u = u.replace(p, "$1" + s + "$2");
      return v + u + _ + h;
    }
    return { value: f, start: l, reset: g };
  }
}), O = (t, a) => {
  const e = t.__vccOpts || t;
  for (const [i, o] of a)
    e[i] = o;
  return e;
};
function j(t, a, e, i, o, f) {
  return F(), k("span", {
    style: w({ color: t.color })
  }, P(t.value), 5);
}
const r = /* @__PURE__ */ O(M, [["render", j]]);
r.install = function(t, a) {
  t.component(a || r.name, r);
};
const H = {
  title: "CountTo 数字动画",
  category: "数据描述",
  status: "100%",
  install(t) {
    t.component(r.name, r);
  }
};
export {
  r as CountTo,
  H as default
};
