UNPKG

@zhsz/cool-design-dv

Version:

137 lines (136 loc) 4.72 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const vue = require("vue"); const index$1 = require("../dv-box/index.js"); const index = require("../../symbols/index.js"); const resizeEvent = require("../../utils/resize-event.js"); const useAdorn = require("../../hooks/useAdorn.js"); const useConfig = require("../../hooks/useConfig.js"); const _hoisted_1 = ["width", "height"]; const _hoisted_2 = ["x", "y", "width", "height", "fill"]; const _hoisted_3 = ["attributeName", "to", "dur"]; const _hoisted_4 = ["x", "y", "width", "height", "fill"]; const _hoisted_5 = ["attributeName", "to", "dur"]; const __default__ = vue.defineComponent({ name: "DvAdorn2" }); const _sfc_main = /* @__PURE__ */ vue.defineComponent({ ...__default__, props: { duration: { type: Number, default: 3 }, reverse: Boolean, opacity: { type: Number, default: 1 }, // 线条的宽度 size: { type: Number, default: 1 } }, emits: ["resize"], setup(__props, { emit: __emit }) { var _a, _b, _c; const props = __props; const w = vue.ref(0); const h = vue.ref(0); const x = vue.ref(0); const y = vue.ref(0); const instance = (_a = vue.getCurrentInstance()) == null ? void 0 : _a.proxy; const emits = __emit; const $attrs = vue.useAttrs(); const page = vue.inject(index.dvPageSymbols, null); const mitt = vue.inject(index.mittSymbol, null); const { resize, classes, styles, width, height, dark, light } = useAdorn.useAdorn( emits, ((_c = (_b = page == null ? void 0 : page.settings) == null ? void 0 : _b.value) == null ? void 0 : _c.color) ?? useConfig.baseConfig.color, props, page ); function setData() { if (props.reverse) { w.value = props.size; h.value = height.value; x.value = (width.value - props.size) / 2; y.value = 0; } else { w.value = width.value; h.value = props.size; x.value = 0; y.value = (height.value - props.size) / 2; } } vue.onMounted(() => { resize(instance == null ? void 0 : instance.$el); setData(); resizeEvent.addResizeListener(instance == null ? void 0 : instance.$el, () => resize(instance == null ? void 0 : instance.$el)); if (mitt) { mitt.on("resize", setData); } }); vue.onBeforeUnmount(() => { resizeEvent.removeResizeListener(instance == null ? void 0 : instance.$el, () => resize(instance == null ? void 0 : instance.$el)); if (mitt) { mitt.off("resize", setData); } }); return (_ctx, _cache) => { return vue.openBlock(), vue.createBlock(vue.unref(index$1.default), vue.mergeProps({ class: ["my-dv-adorn-2", vue.unref(classes)], style: vue.unref(styles), "default-width": "300px", "default-height": "20px" }, vue.unref($attrs)), { default: vue.withCtx(() => [ (vue.openBlock(), vue.createElementBlock("svg", { width: `${vue.unref(width)}px`, height: `${vue.unref(height)}px` }, [ vue.createElementVNode("rect", { x: x.value, y: y.value, width: w.value, height: h.value, fill: vue.unref(dark) }, [ vue.createElementVNode("animate", { attributeName: __props.reverse ? "height" : "width", from: "0", to: __props.reverse ? vue.unref(height) : vue.unref(width), dur: `${__props.duration}s`, calcMode: "spline", keyTimes: "0;1", keySplines: ".42,0,.58,1", repeatCount: "indefinite" }, null, 8, _hoisted_3) ], 8, _hoisted_2), vue.createElementVNode("rect", { x: x.value, y: y.value, width: __props.size, height: __props.size, fill: vue.unref(light) }, [ vue.createElementVNode("animate", { attributeName: __props.reverse ? "y" : "x", from: "0", to: __props.reverse ? vue.unref(height) : vue.unref(width), dur: `${__props.duration}s`, calcMode: "spline", keyTimes: "0;1", keySplines: "0.42,0,0.58,1", repeatCount: "indefinite" }, null, 8, _hoisted_5) ], 8, _hoisted_4) ], 8, _hoisted_1)) ]), _: 1 }, 16, ["class", "style"]); }; } }); exports.default = _sfc_main;