@zhsz/cool-design-dv
Version:
177 lines (176 loc) • 6.3 kB
JavaScript
import { defineComponent, getCurrentInstance, useAttrs, inject, computed, onMounted, onBeforeUnmount, openBlock, createBlock, unref, mergeProps, withCtx, createElementBlock, normalizeStyle, createElementVNode, Fragment, renderList, renderSlot } from "vue";
import "./style.css";
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 { fade } from "../../utils/color.mjs";
import { baseConfig } from "../../hooks/useConfig.mjs";
import { uid } from "../../utils/util.mjs";
const _hoisted_1 = ["id"];
const _hoisted_2 = ["stroke"];
const _hoisted_3 = ["dur"];
const _hoisted_4 = ["stroke"];
const _hoisted_5 = ["dur"];
const _hoisted_6 = ["stroke"];
const _hoisted_7 = ["xlink:href", "stroke", "fill"];
const _hoisted_8 = ["dur", "begin"];
const _hoisted_9 = ["stroke"];
const __default__ = defineComponent({
name: "DvAdorn9"
});
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 _uid = uid();
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, 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 svgScale = computed(() => {
return width.value / 100;
});
const svgStyles = computed(() => {
return {
transform: `scale(${svgScale.value})`
};
});
function fade$1(color, percent = 100) {
const r = fade(color, percent);
if (r === false) {
return void 0;
} else {
return r;
}
}
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-9", unref(classes)],
style: unref(styles),
"default-width": "100px",
"default-height": "100px"
}, unref($attrs)), {
default: withCtx(() => [
(openBlock(), createElementBlock("svg", {
width: "100",
height: "100",
style: normalizeStyle(svgStyles.value)
}, [
createElementVNode("defs", null, [
createElementVNode("polygon", {
id: `polygon${unref(_uid)}`,
points: "15, 46.5, 21, 47.5, 21, 52.5, 15, 53.5"
}, null, 8, _hoisted_1)
]),
createElementVNode("circle", {
cx: "50",
cy: "50",
r: "45",
fill: "transparent",
stroke: unref(dark),
"stroke-width": "10",
"stroke-dasharray": "80, 100, 30, 100"
}, [
createElementVNode("animateTransform", {
attributeName: "transform",
type: "rotate",
values: "0 50 50;360 50 50",
dur: `${__props.duration}s`,
repeatCount: "indefinite"
}, null, 8, _hoisted_3)
], 8, _hoisted_2),
createElementVNode("circle", {
cx: "50",
cy: "50",
r: "45",
fill: "transparent",
stroke: unref(light),
"stroke-width": "6",
"stroke-dasharray": "50, 66, 100, 66"
}, [
createElementVNode("animateTransform", {
attributeName: "transform",
type: "rotate",
values: "0 50 50;-360 50 50",
dur: `${__props.duration}s`,
repeatCount: "indefinite"
}, null, 8, _hoisted_5)
], 8, _hoisted_4),
createElementVNode("circle", {
cx: "50",
cy: "50",
r: "38",
fill: "transparent",
stroke: fade$1(unref(dark), 30),
"stroke-width": "1",
"stroke-dasharray": "5, 1"
}, null, 8, _hoisted_6),
(openBlock(true), createElementBlock(Fragment, null, renderList(new Array(20).fill(0), (foo, i) => {
return openBlock(), createElementBlock("use", {
key: i,
"xlink:href": `#polygon${unref(_uid)}`,
stroke: unref(dark),
fill: Math.random() > 0.4 ? "transparent" : unref(light)
}, [
createElementVNode("animateTransform", {
attributeName: "transform",
type: "rotate",
values: "0 50 50;360 50 50",
dur: `${__props.duration}s`,
begin: `${i * __props.duration / 20}s`,
repeatCount: "indefinite"
}, null, 8, _hoisted_8)
], 8, _hoisted_7);
}), 128)),
createElementVNode("circle", {
cx: "50",
cy: "50",
r: "26",
fill: "transparent",
stroke: fade$1(unref(dark), 30),
"stroke-width": "1",
"stroke-dasharray": "5, 1"
}, null, 8, _hoisted_9)
], 4)),
createElementVNode("div", {
class: "my-dv-adorn-9__content",
style: normalizeStyle({ zoom: svgScale.value })
}, [
renderSlot(_ctx.$slots, "default")
], 4)
]),
_: 3
}, 16, ["class", "style"]);
};
}
});
export {
_sfc_main as default
};