UNPKG

vuux

Version:

Vue3 Nuxt3 Nuxt4 组件库

2 lines (1 loc) 1.21 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue"),y=(a,n)=>{const i=l.ref(""),e=l.ref(null),d=({width:s=a.width,height:o=a.height,content:r=a.content,font:m="12px uucn",color:f=a.color,degree:g=-22,x1:h=40,y1:b=80,x2:x=350,y2:k=550})=>{const u=document.createElement("canvas");u.width=s,u.height=o;const t=u.getContext("2d");return t&&(t.font=m,t.fillStyle=f,t.rotate(g*Math.PI/180),t.fillText(r,h,b),t.fillText(r,x,k)),i.value=u.toDataURL("image/png"),i.value},c=()=>{n.value&&(e.value&&e.value.parentNode&&e.value.parentNode.removeChild(e.value),d({content:a.content}),e.value=document.createElement("div"),e.value.className="water-mark",Object.assign(e.value.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",backgroundImage:`url(${i.value})`,backgroundRepeat:"repeat"}),n.value.appendChild(e.value))},v=new MutationObserver(s=>{for(const o of s){for(const r of Array.from(o.removedNodes))if(r===e.value){c();return}if(o.target===e.value){c();return}}});l.onMounted(()=>{c(),n.value&&v.observe(n.value,{childList:!0,subtree:!0,attributes:!0})}),l.onUnmounted(()=>{v.disconnect()})};exports.useWater=y;