Files
qhmes/web-dist/js/useWatermark-DKRN2o8Y.js

2 lines
1.4 KiB
Java
Raw Normal View History

2026-06-16 18:19:57 +08:00
import{ap as x,aq as d}from"./index-X7Y8jykP.js";import{removeResizeListener as y,addResizeListener as p}from"./index-C4wWpZeQ.js";import{r as v,u as i,s as w,x as b,g as k}from"./vue-vendor-DNhG1Cve.js";import"./emoji-mart-vue-fast-R0uJEDq-.js";const W=Symbol("watermark-dom");function z(c=v(document.body)){const f=x(function(){const e=i(c);if(!e)return;const{clientHeight:t,clientWidth:r}=e;l({height:t,width:r})}),a=W.toString(),o=w(),m=()=>{const e=i(o);o.value=void 0;const t=i(c);t&&(e&&t.removeChild(e),y(t,f))};function u(e){const t=document.createElement("canvas"),r=300,s=240;Object.assign(t,{width:r,height:s});const n=t.getContext("2d");return n&&(n.rotate(-20*Math.PI/120),n.font="15px Vedana",n.fillStyle="rgba(0, 0, 0, 0.15)",n.textAlign="left",n.textBaseline="middle",n.fillText(e,r/20,s)),t.toDataURL("image/png")}function l(e={}){const t=i(o);t&&(d(e.width)&&(t.style.width=`${e.width}px`),d(e.height)&&(t.style.height=`${e.height}px`),d(e.str)&&(t.style.background=`url(${u(e.str)}) left top repeat`))}const h=e=>{if(i(o))return l({str:e}),a;const t=document.createElement("div");o.value=t,t.id=a,t.style.pointerEvents="none",t.style.top="0px",t.style.left="0px",t.style.position="absolute",t.style.zIndex="100000";const r=i(c);if(!r)return a;const{clientHeight:s,clientWidth:n}=r;return l({str:e,width:n,height:s}),r.appendChild(t),a};function g(e){h(e),p(document.documentElement,f),k()&&b(()=>{m()})}return{setWatermark:g,clear:m}}export{z as useWatermark};