UNPKG

@zhsz/cool-design-dv

Version:

121 lines (120 loc) 4.32 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 = ["fill", "x", "y", "width", "height"]; const _hoisted_3 = ["values", "dur", "begin"]; const __default__ = vue.defineComponent({ name: "DvAdorn3" }); const _sfc_main = /* @__PURE__ */ vue.defineComponent({ ...__default__, props: { duration: { type: Number, default: 3 }, reverse: Boolean, opacity: { type: Number, default: 1 }, size: { type: Number, default: 5 }, gap: { type: Number, default: 5 } }, emits: ["resize"], setup(__props, { emit: __emit }) { var _a, _b, _c; const props = __props; const points = vue.ref([]); 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 } = 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 ); const rows = vue.computed(() => { return Math.floor(height.value / (props.size + props.gap)); }); const columns = vue.computed(() => { return Math.floor(width.value / (props.size + props.gap)); }); function createPoints() { const grid = props.gap + props.size; const points2 = new Array(rows.value).fill(0).map( (foo, i) => new Array(columns.value).fill(0).map((foo2, j) => [grid * j, grid * i]) ); return points2.reduce((all, item) => [...all, ...item], []); } function setData() { points.value = createPoints(); } 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-3", 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.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(points.value, (point, i) => { return vue.openBlock(), vue.createElementBlock("rect", { key: i, fill: vue.unref(dark), x: point[0], y: point[1], width: __props.size, height: __props.size }, [ Math.random() > 0.6 ? (vue.openBlock(), vue.createElementBlock("animate", { key: 0, attributeName: "fill", values: `${[vue.unref(dark), "transparent"].join(";")}`, dur: Math.random() + 1 + "s", begin: Math.random() * 2, repeatCount: "indefinite" }, null, 8, _hoisted_3)) : vue.createCommentVNode("", true) ], 8, _hoisted_2); }), 128)) ], 8, _hoisted_1)) ]), _: 1 }, 16, ["class", "style"]); }; } }); exports.default = _sfc_main;