UNPKG

1.85 kBJavaScriptView Raw
1/*! @uiw/watermark.js v0.0.5 | MIT © 2022 kenny wang <wowohoo@qq.com> https://uiwjs.github.io/react-watermark */
2!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Watermark=e()}(this,(function(){"use strict";return class{constructor(t){this.option={gapX:212,gapY:222,width:120,height:64,rotate:-22,fontStyle:"normal",fontWeight:"normal",fontColor:"rgba(0,0,0,.15)",fontSize:16,fontFamily:"sans-serif"},this.option=Object.assign(Object.assign({},this.option),t)}async create(){const{image:t="",content:e="",gapX:o=212,gapY:n=222,width:i=120,height:r=64,rotate:a=-22,fontStyle:s="normal",fontWeight:f="normal",fontColor:l="rgba(0,0,0,.15)",fontSize:c=16,fontFamily:g="sans-serif",offsetLeft:u,offsetTop:m}=this.option,h=document.createElement("canvas"),p=h.getContext("2d"),d=(t=>{if(!t)return 1;const e=t.backingStorePixelRatio||t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/e})(p),x=(o+i)*d+"px",y=(n+r)*d+"px",b=u||o/2,S=m||n/2;return h.setAttribute("width",x),h.setAttribute("height",y),new Promise((async(o,n)=>{if(!p)return n("Error: Canvas is not supported in the current environment");{p.translate(b*d,S*d),p.rotate(Math.PI/180*Number(a));const u=i*d,m=r*d;if(t){const e=new Image;e.crossOrigin="anonymous",e.referrerPolicy="no-referrer",e.src=t,e.onload=async()=>(p.drawImage(e,0,0,u,m),o(h.toDataURL())),e.onerror=t=>n(t)}else if(e){const t=Number(c)*d;return p.font=`${s} normal ${f} ${t}px/${m}px ${g}`,p.fillStyle=l,Array.isArray(e)?null==e||e.forEach(((t,e)=>p.fillText(t,0,50*e))):p.fillText(e,0,0),o(h.toDataURL())}}}))}}}));
3//# sourceMappingURL=watermark.min.js.map