UNPKG

@zhsz/cool-design-dv

Version:

136 lines (135 loc) 5.04 kB
import { defineComponent, getCurrentInstance, useAttrs, inject, computed, onMounted, onBeforeUnmount, openBlock, createBlock, unref, mergeProps, withCtx, createElementBlock, createElementVNode } from "vue"; import Box from "../dv-box/index.mjs"; import { dvPageSymbols } from "../../symbols/index.mjs"; import { addResizeListener, removeResizeListener } from "../../utils/resize-event.mjs"; import { useAdorn } from "../../hooks/useAdorn.mjs"; import { baseConfig } from "../../hooks/useConfig.mjs"; import { getPolylineLength } from "../../utils/util.mjs"; const _hoisted_1 = ["width", "height"]; const _hoisted_2 = ["stroke", "points"]; const _hoisted_3 = ["from", "to", "dur"]; const _hoisted_4 = ["stroke", "points"]; const _hoisted_5 = ["from", "to", "dur"]; const __default__ = defineComponent({ name: "DvAdorn5" }); const _sfc_main = /* @__PURE__ */ defineComponent({ ...__default__, props: { duration: { type: Number, default: 3 }, reverse: Boolean, opacity: { type: Number, default: 1 } }, emits: ["resize"], setup(__props, { emit: __emit }) { var _a, _b, _c; const props = __props; const instance = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy; const emits = __emit; const $attrs = useAttrs(); const page = inject(dvPageSymbols, null); const { resize, classes, styles, width, height, dark, light } = useAdorn( emits, ((_c = (_b = page == null ? void 0 : page.settings) == null ? void 0 : _b.value) == null ? void 0 : _c.color) ?? baseConfig.color, props, page ); const line1Points = computed(() => { return [ [0, height.value * 0.2], [width.value * 0.18, height.value * 0.2], [width.value * 0.2, height.value * 0.4], [width.value * 0.25, height.value * 0.4], [width.value * 0.27, height.value * 0.6], [width.value * 0.72, height.value * 0.6], [width.value * 0.75, height.value * 0.4], [width.value * 0.8, height.value * 0.4], [width.value * 0.82, height.value * 0.2], [width.value, height.value * 0.2] ]; }); const line2Points = computed(() => { return [ [width.value * 0.3, height.value * 0.8], [width.value * 0.7, height.value * 0.8] ]; }); const line1Length = computed(() => { return getPolylineLength(line1Points.value); }); const line2Length = computed(() => { return getPolylineLength(line2Points.value); }); onMounted(() => { resize(instance == null ? void 0 : instance.$el); addResizeListener(instance == null ? void 0 : instance.$el, () => resize(instance == null ? void 0 : instance.$el)); }); onBeforeUnmount(() => { removeResizeListener(instance == null ? void 0 : instance.$el, () => resize(instance == null ? void 0 : instance.$el)); }); return (_ctx, _cache) => { return openBlock(), createBlock(unref(Box), mergeProps({ class: ["my-dv-adorn-5", unref(classes)], style: unref(styles), "default-width": "400px", "default-height": "40px" }, unref($attrs)), { default: withCtx(() => [ (openBlock(), createElementBlock("svg", { width: `${unref(width)}px`, height: `${unref(height)}px` }, [ createElementVNode("polyline", { fill: "transparent", stroke: unref(dark), "stroke-width": "3", points: line1Points.value.toString() }, [ createElementVNode("animate", { attributeName: "stroke-dasharray", attributeType: "XML", from: `0, ${line1Length.value / 2}, 0, ${line1Length.value / 2}`, to: `0, 0, ${line1Length.value}, 0`, dur: `${__props.duration}s`, begin: "0s", calcMode: "spline", keyTimes: "0;1", keySplines: "0.4,1,0.49,0.98", repeatCount: "indefinite" }, null, 8, _hoisted_3) ], 8, _hoisted_2), createElementVNode("polyline", { fill: "transparent", stroke: unref(light), "stroke-width": "2", points: line2Points.value.toString() }, [ createElementVNode("animate", { attributeName: "stroke-dasharray", attributeType: "XML", from: `0, ${line2Length.value / 2}, 0, ${line2Length.value / 2}`, to: `0, 0, ${line2Length.value}, 0`, dur: `${__props.duration}s`, begin: "0s", calcMode: "spline", keyTimes: "0;1", keySplines: ".4,1,.49,.98", repeatCount: "indefinite" }, null, 8, _hoisted_5) ], 8, _hoisted_4) ], 8, _hoisted_1)) ]), _: 1 }, 16, ["class", "style"]); }; } }); export { _sfc_main as default };