You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
21 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, computed, shallowRef, ref, onMounted, watch, onBeforeUnmount, openBlock, createElementBlock, normalizeStyle, renderSlot } from 'vue';\nimport { useMutationObserver } from '@vueuse/core';\nimport { watermarkProps } from './watermark.mjs';\nimport { reRendering, getStyleStr, getPixelRatio } from './utils.mjs';\nimport useClips, { FontGap } from './useClips.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { isArray } from '@vue/shared';\nconst __default__ = defineComponent({\n name: \"ElWatermark\"\n});\nconst _sfc_main = /* @__PURE__ */defineComponent({\n ...__default__,\n props: watermarkProps,\n setup(__props) {\n const props = __props;\n const style = {\n position: \"relative\"\n };\n const color = computed(() => {\n var _a, _b;\n return (_b = (_a = props.font) == null ? void 0 : _a.color) != null ? _b : \"rgba(0,0,0,.15)\";\n });\n const fontSize = computed(() => {\n var _a, _b;\n return (_b = (_a = props.font) == null ? void 0 : _a.fontSize) != null ? _b : 16;\n });\n const fontWeight = computed(() => {\n var _a, _b;\n return (_b = (_a = props.font) == null ? void 0 : _a.fontWeight) != null ? _b : \"normal\";\n });\n const fontStyle = computed(() => {\n var _a, _b;\n return (_b = (_a = props.font) == null ? void 0 : _a.fontStyle) != null ? _b : \"normal\";\n });\n const fontFamily = computed(() => {\n var _a, _b;\n return (_b = (_a = props.font) == null ? void 0 : _a.fontFamily) != null ? _b : \"sans-serif\";\n });\n const textAlign = computed(() => {\n var _a, _b;\n return (_b = (_a = props.font) == null ? void 0 : _a.textAlign) != null ? _b : \"center\";\n });\n const textBaseline = computed(() => {\n var _a, _b;\n return (_b = (_a = props.font) == null ? void 0 : _a.textBaseline) != null ? _b : \"hanging\";\n });\n const gapX = computed(() => props.gap[0]);\n const gapY = computed(() => props.gap[1]);\n const gapXCenter = computed(() => gapX.value / 2);\n const gapYCenter = computed(() => gapY.value / 2);\n const offsetLeft = computed(() => {\n var _a, _b;\n return (_b = (_a = props.offset) == null ? void 0 : _a[0]) != null ? _b : gapXCenter.value;\n });\n const offsetTop = computed(() => {\n var _a, _b;\n return (_b = (_a = props.offset) == null ? void 0 : _a[1]) != null ? _b : gapYCenter.value;\n });\n const getMarkStyle = () => {\n const markStyle = {\n zIndex: props.zIndex,\n position: \"absolute\",\n left: 0,\n top: 0,\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n backgroundRepeat: \"repeat\"\n };\n let positionLeft = offsetLeft.value - gapXCenter.value;\n let positionTop = offsetTop.value - gapYCenter.value;\n if (positionLeft > 0) {\n markStyle.left = `${positionLeft}px`;\n markStyle.width = `calc(100% - ${positionLeft}px)`;\n positionLeft = 0;\n }\n if (positionTop > 0) {\n markStyle.top = `${positionTop}px`;\n markStyle.height = `calc(100% - ${positionTop}px)`;\n positionTop = 0;\n }\n markStyle.backgroundPosition = `${positionLeft}px ${positionTop}px`;\n return markStyle;\n };\n const containerRef = shallowRef(null);\n const watermarkRef = shallowRef();\n const stopObservation = ref(false);\n const destroyWatermark = () => {\n if (watermarkRef.value) {\n watermarkRef.value.remove();\n watermarkRef.value = void 0;\n }\n };\n const appendWatermark = (base64Url, markWidth) => {\n var _a;\n if (containerRef.value && watermarkRef.value) {\n stopObservation.value = true;\n watermarkRef.value.setAttribute(\"style\", getStyleStr({\n ...getMarkStyle(),\n backgroundImage: `url('${base64Url}')`,\n backgroundSize: `${Math.floor(markWidth)}px`\n }));\n (_a = containerRef.value) == nul