UNPKG

comic-plus

Version:

<p align="center"> <img width="200px" src="./logo.png"/> </p>

152 lines (151 loc) 5.95 kB
import { defineComponent, ref, computed, onMounted, openBlock, createElementBlock, normalizeClass, normalizeStyle, createElementVNode, toDisplayString, createBlock, resolveDynamicComponent, createCommentVNode } from "vue"; import "../style/progress.css"; import "../../../utils/config.mjs"; import { isString, isFunction } from "../../../utils/typescript.mjs"; import "@vueuse/core"; import { progressProps } from "./main.props.mjs"; import "../../../icons/index.mjs"; import { Success, Warning, CloseOne } from "../../../icons/components/components.mjs"; const _hoisted_1 = { key: 0, class: "cu-progress__inner" }; const _hoisted_2 = { key: 0, class: "cu-progress__describe" }; const _hoisted_3 = { key: 0 }; const _hoisted_4 = { key: 2 }; const _hoisted_5 = ["width", "height"]; const _hoisted_6 = { key: 2, class: "cu-progress__inner" }; const _hoisted_7 = { key: 0 }; const _hoisted_8 = { key: 2 }; const _sfc_main = /* @__PURE__ */ defineComponent({ ...{ name: "CuProgress" }, __name: "main", props: progressProps, setup(__props) { const STATUS = { success: Success, warning: Warning, fail: CloseOne }; const formatSize = { trends: 17, circle: 17, line: 13, "line-trends": 13 }; const props = __props; const circleRef = ref(); const circleLength = ref(0); const style = computed(() => { return { "--cu-progress-color": computedColor.value ?? `var(--cu-color-${props.type || "primary"})` }; }); const computedColor = computed(() => { if (!props.colors) return void 0; if (isString(props.colors)) return props.colors; if (isFunction(props.colors)) return props.colors(schedule.value); for (const key in props.colors) { if (schedule.value <= Number(key)) { return props.colors[key]; } } return void 0; }); const schedule = computed(() => { return props.progress <= 0 ? 0 : props.progress >= 100 ? 100 : props.progress; }); const barsStyle = computed(() => { return { width: schedule.value + "%", height: props.barWidth ? props.barWidth + "px" : void 0, animationDuration: Math.floor(schedule.value / 3) + "s" }; }); onMounted(() => { if (props.barType === "circle") { circleLength.value = circleRef.value.getTotalLength() + 1; } }); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { class: normalizeClass(["cu-progress", _ctx.barType ? "is-" + _ctx.barType : void 0]), style: normalizeStyle(style.value) }, [ _ctx.barType === "line" || _ctx.barType === "line-trends" ? (openBlock(), createElementBlock("div", _hoisted_1, [ createElementVNode("div", { class: "cu-progress__bar", style: normalizeStyle(barsStyle.value) }, [ _ctx.insetFormat && _ctx.showText ? (openBlock(), createElementBlock("div", _hoisted_2, [ _ctx.format ? (openBlock(), createElementBlock("span", _hoisted_3, toDisplayString(_ctx.format), 1)) : STATUS[_ctx.status] ? (openBlock(), createBlock(resolveDynamicComponent(STATUS[_ctx.status]), { key: 1, size: formatSize[_ctx.barType], class: normalizeClass(_ctx.status) }, null, 8, ["size", "class"])) : (openBlock(), createElementBlock("span", _hoisted_4, toDisplayString(schedule.value + "%"), 1)) ])) : createCommentVNode("", true) ], 4) ])) : _ctx.barType === "circle" ? (openBlock(), createElementBlock("svg", { key: 1, width: _ctx.size, height: _ctx.size, style: normalizeStyle({ "--cu-progress-strokewidth": _ctx.barWidth, "--cu-progress-dasharray": circleLength.value, "--cu-progress-dashoffset": circleLength.value - schedule.value / 100 * circleLength.value + 1 }) }, [ _cache[0] || (_cache[0] = createElementVNode("circle", { class: "cu-progress__circle_bg", cx: "50%", cy: "50%", r: "47%", style: { "z-index": "1" } }, null, -1)), createElementVNode("circle", { ref_key: "circleRef", ref: circleRef, class: "cu-progress__circle", cx: "50%", cy: "50%", r: "47%", style: { "z-index": "2" } }, null, 512) ], 12, _hoisted_5)) : _ctx.barType === "trends" ? (openBlock(), createElementBlock("div", _hoisted_6, [ createElementVNode("div", { class: "cu-progress__bar", style: normalizeStyle({ width: _ctx.size + "px", height: _ctx.size + "px", "--cu-progress-dashoffset": (schedule.value === 0 ? -10 : schedule.value === 100 ? 110 : schedule.value) + "%" }) }, null, 4) ])) : createCommentVNode("", true), !_ctx.insetFormat && _ctx.showText || _ctx.barType === "circle" || _ctx.barType === "trends" ? (openBlock(), createElementBlock("div", { key: 3, class: "cu-progress__describe", style: normalizeStyle({ color: _ctx.barType === "trends" && schedule.value > 50 ? "#fff" : void 0 }) }, [ _ctx.format ? (openBlock(), createElementBlock("span", _hoisted_7, toDisplayString(_ctx.format), 1)) : STATUS[_ctx.status] ? (openBlock(), createBlock(resolveDynamicComponent(STATUS[_ctx.status]), { key: 1, size: formatSize[_ctx.barType], class: normalizeClass(_ctx.status) }, null, 8, ["size", "class"])) : (openBlock(), createElementBlock("span", _hoisted_8, toDisplayString(schedule.value + "%"), 1)) ], 4)) : createCommentVNode("", true) ], 6); }; } }); export { _sfc_main as default };