@fisher-zh/watermark
Version:
a js plugin for watermark
1 lines • 3.37 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.WaterMark=e():t.WaterMark=e()}(this,function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){const o=n(1),r=n(2);t.exports=function t({type:e="canvas",container:n=document.body,content:i="WaterMark",width:a="300px",height:l="200px",rotate:c="30",fontSize:u="20px",color:s="rgba(184, 184, 184, 0.8)",zIndex:f=1e3}={}){const d=arguments[0];let p;p="canvas"===e?o({content:i,width:a,height:l,rotate:c,fontSize:u,fillStyle:s}):r({content:i,width:a,height:l,rotate:c,fontSize:u,fill:s});const x=document.querySelector(".__wm"),b=x||document.createElement("div"),h=`\n position:absolute;\n top:0;\n left:0;\n width:100%;\n height:100%;\n z-index:${f};\n pointer-events:none;\n background-repeat:repeat;\n background-image:url('${p}')`;b.setAttribute("style",h),b.classList.add("__wm"),x||(n.style.position="relative",n.insertBefore(b,n.firstChild));const g=window.MutationObserver||window.WebKitMutationObserver;if(g){let e=new g(function(){const n=document.querySelector(".__wm");(n&&n.getAttribute("style")!==h||!n)&&(e.disconnect(),e=null,t(d))});e.observe(n,{attributes:!0,subtree:!0,childList:!0})}}},function(t,e){t.exports=function({width:t="300px",height:e="200px",textAlign:n="center",textBaseline:o="middle",fontSize:r="20px",fillStyle:i="rgba(184, 184, 184, 0.8)",content:a="WaterMark",rotate:l="30"}={}){const c=document.createElement("canvas");c.setAttribute("width",t),c.setAttribute("height",e);const u=c.getContext("2d");return u.textAlign=n,u.textBaseline=o,u.fontSize=r,u.fillStyle=i,u.rotate(Math.PI/180*l),u.fillText(a,parseFloat(t)/2,parseFloat(e)/2),c.toDataURL()}},function(t,e){t.exports=function({content:t="WaterMark",width:e="300px",height:n="200px",fontSize:o="20px",fill:r="rgba(184, 184, 184, 0.8)",rotate:i="30"}={}){const a=`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${n}">\n <text x="50%" y="50%" dy="12px"\n text-anchor="middle"\n fill="${r}"\n transform="rotate(${i})"\n style="font-size: ${o};">\n ${t}\n </text>\n </svg>`;return`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(a)))}`}}])});