watermark-js-plus 1.6.4 → 1.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var WatermarkPlus=function(t){"use strict";!function(t,e){void 0===e&&(e={});var i=e.insertAt;if("undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===i&&n.firstChild?n.insertBefore(a,n.firstChild):n.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t))}}("@keyframes watermark{0%{background-position:0 0}25%{background-position:100% 100%}50%{background-position:100% 0}75%{background-position:0 100%}to{background-position:0 0}}@keyframes watermark-horizontal{0%{background-position-x:0}to{background-position-x:100%}}@keyframes watermark-vertical{0%{background-position-y:0}to{background-position-y:100%}}");var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},e(t,i)};var i=function(){return i=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var a in e=arguments[i])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},i.apply(this,arguments)};function n(t,e,i,n){return new(i||(i=Promise))(function(a,o){function r(t){try{d(n.next(t))}catch(t){o(t)}}function s(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?a(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(r,s)}d((n=n.apply(t,e||[])).next())})}function a(t,e){var i,n,a,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},r=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return r.next=s(0),r.throw=s(1),r.return=s(2),"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(d){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(o=0)),o;)try{if(i=1,n&&(a=2&s[0]?n.return:s[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,s[1])).done)return a;switch(n=0,a&&(s=[2&s[0],a.value]),s[0]){case 0:case 1:a=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(a=o.trys,(a=a.length>0&&a[a.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!a||s[1]>a[0]&&s[1]<a[3])){o.label=s[1];break}if(6===s[0]&&o.label<a[1]){o.label=a[1],a=s;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(s);break}a[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],n=0}finally{i=a=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,d])}}}"function"==typeof SuppressedError&&SuppressedError;var o=function(t){return t.toDataURL("image/png",1)},r=function(t){return"function"==typeof t},s=function(t){return void 0===t},d=function(t,e,i){void 0===e&&(e={}),void 0===i&&(i="http://www.w3.org/2000/svg");var n=document.createElementNS(i,t);for(var a in e)n.setAttribute(a,e[a]);return n},l=function(t,e){return n(void 0,void 0,void 0,function(){var i,n,o,r,s,l,h,u,v;return a(this,function(a){switch(a.label){case 0:return i=d("svg",{xmlns:"http://www.w3.org/2000/svg"}),(n=document.createElement("div")).setAttribute("xmlns","http://www.w3.org/1999/xhtml"),n.style.cssText="\n text-align: center;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 100%;\n font: ".concat(t.font,";\n color: ").concat(e.fontColor,";\n"),n.innerHTML="<div class='rich-text-content'>".concat(e.content,"</div>"),document.body.appendChild(n),[4,c(n)];case 1:return a.sent(),o=null===(v=n.querySelector(".rich-text-content"))||void 0===v?void 0:v.getBoundingClientRect(),r=null==o?void 0:o.width,s=null==o?void 0:o.height,document.body.removeChild(n),l=e.richTextWidth||r||e.width,h=e.richTextHeight||s||e.height,i.setAttribute("width",l.toString()),i.setAttribute("height",h.toString()),(u=d("foreignObject",{width:l.toString(),height:h.toString()})).appendChild(n),i.appendChild(u),[2,{element:i,width:l,height:h}]}})})};function c(t){return n(this,void 0,void 0,function(){var e,i,n,o,r;return a(this,function(s){switch(s.label){case 0:e=t.querySelectorAll("img"),i=function(t){var e,i,n,o;return a(this,function(a){switch(a.label){case 0:if(!(e=t.getAttribute("src")))return[3,6];a.label=1;case 1:return a.trys.push([1,5,,6]),[4,fetch(e)];case 2:return[4,a.sent().blob()];case 3:return i=a.sent(),[4,new Promise(function(t,e){var n=new FileReader;n.onloadend=function(){return t(n.result)},n.onerror=e,n.readAsDataURL(i)})];case 4:return n=a.sent(),"string"==typeof n&&t.setAttribute("src",n),[3,6];case 5:return o=a.sent(),console.error("Error converting ".concat(e," to base64:"),o),[3,6];case 6:return[2]}})},n=0,o=Array.from(e),s.label=1;case 1:return n<o.length?(r=o[n],[5,i(r)]):[3,4];case 2:s.sent(),s.label=3;case 3:return n++,[3,1];case 4:return[2]}})})}var h=function(t,e){return s(t)?e:t},u=function(t,e,i){void 0===e&&(e=void 0),void 0===i&&(i=void 0);var n=new Image;return n.setAttribute("crossOrigin","anonymous"),!s(e)&&(n.width=e),!s(i)&&(n.height=i),n.src=t,new Promise(function(t){n.onload=function(){t(n)}})},v={width:300,height:300,rotate:45,layout:"default",auxiliaryLine:!1,translatePlacement:"middle",contentType:"text",content:"hello watermark-js-plus",textType:"fill",imageWidth:0,imageHeight:0,lineHeight:30,zIndex:2147483647,backgroundPosition:"0 0",backgroundRepeat:"repeat",fontSize:"20px",fontFamily:"sans-serif",fontStyle:"",fontVariant:"",fontColor:"#000",fontWeight:"normal",filter:"none",letterSpacing:"0px",wordSpacing:"0px",globalAlpha:.5,mode:"default",mutationObserve:!0,monitorProtection:!1,movable:!1,parent:"body",onSuccess:function(){},onBeforeDestroy:function(){},onDestroyed:function(){},onObserveError:function(){}},p=function(t){"undefined"!=typeof window&&t&&Object.defineProperty(window,"MutationObserver",{writable:!1,configurable:!1})},m=function(){function t(e,i){this.props=e,this.options=i,this.canvas=t.createCanvas(this.options.width,this.options.height),this.recommendOptions=function(t,e,i){var n=t.getContext("2d");if(null===n)throw new Error("get context error");n.font="".concat(e.fontStyle," ").concat(e.fontVariant," ").concat(e.fontWeight," ").concat(e.fontSize," ").concat(e.fontFamily),n.filter=e.filter,n.letterSpacing=e.letterSpacing,n.wordSpacing=e.wordSpacing,(null==e?void 0:e.rotate)&&(e.rotate=(360-e.rotate%360)*(Math.PI/180)),s(i.textRowMaxWidth)&&(e.textRowMaxWidth=e.width);var a={image:{rect:{width:e.imageWidth,height:e.imageHeight},position:{x:0,y:0}},textLine:{data:[],yOffsetValue:0},advancedStyleParams:{linear:{x0:0,x1:0},radial:{x0:0,y0:0,r0:0,x1:0,y1:0,r1:0},conic:{x:0,y:0,startAngle:0},pattern:{}}};switch(e.contentType){case"text":a.textLine.data=[e.content];break;case"multi-line-text":a.textLine.data=function(t,e,i){for(var n=[],a="",o="",r=0,s=e.length;r<s;r++)"\n"!==(o=e.charAt(r))?(a+=o,t.measureText(a).width>i&&(n.push(a.substring(0,a.length-1)),a="",r--)):(n.push(a),a="");return n.push(a),n}(n,e.content,e.textRowMaxWidth)}var o=e.width/2,r=e.height/2,d="middle",l="center";switch(s(null==i?void 0:i.translateX)||s(null==i?void 0:i.translateY)?(a.advancedStyleParams.linear.x0=-e.width/2,a.advancedStyleParams.linear.x1=e.width/2,a.advancedStyleParams.radial.r0=0,a.advancedStyleParams.radial.r1=e.width/2):(o=null==i?void 0:i.translateX,r=null==i?void 0:i.translateY,d="top",l="left"),i.translatePlacement){case"top":o=e.width/2,r=0,d="top",a.advancedStyleParams.linear.x0=-e.width/2,a.advancedStyleParams.linear.x1=e.width/2,a.advancedStyleParams.radial.y0=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.y1=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.y=a.textLine.data.length*e.lineHeight/2;break;case"top-start":o=0,r=0,d="top",l="start",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=e.width,a.advancedStyleParams.radial.x0=e.width/2,a.advancedStyleParams.radial.y0=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.x1=e.width/2,a.advancedStyleParams.radial.y1=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.x=e.width/2,a.advancedStyleParams.conic.y=a.textLine.data.length*e.lineHeight/2;break;case"top-end":o=e.width,r=0,d="top",l="end",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=-e.width,a.advancedStyleParams.radial.x0=-e.width/2,a.advancedStyleParams.radial.y0=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.x1=-e.width/2,a.advancedStyleParams.radial.y1=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.x=-e.width/2,a.advancedStyleParams.conic.y=a.textLine.data.length*e.lineHeight/2;break;case"bottom":o=e.width/2,r=e.height,d="bottom",a.advancedStyleParams.linear.x0=-e.width/2,a.advancedStyleParams.linear.x1=e.width/2,a.advancedStyleParams.radial.y0=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.y1=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.x=0,a.advancedStyleParams.conic.y=-a.textLine.data.length*e.lineHeight/2;break;case"bottom-start":o=0,r=e.height,d="bottom",l="start",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=e.width,a.advancedStyleParams.radial.x0=e.width/2,a.advancedStyleParams.radial.y0=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.x1=e.width/2,a.advancedStyleParams.radial.y1=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.x=e.width/2,a.advancedStyleParams.conic.y=-a.textLine.data.length*e.lineHeight/2;break;case"bottom-end":o=e.width,r=e.height,d="bottom",l="end",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=-e.width,a.advancedStyleParams.radial.x0=-e.width/2,a.advancedStyleParams.radial.y0=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.x1=-e.width/2,a.advancedStyleParams.radial.y1=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.x=-e.width/2,a.advancedStyleParams.conic.y=-a.textLine.data.length*e.lineHeight/2;break;case"left":o=0,r=e.height/2,l="start",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=e.width,a.advancedStyleParams.radial.x0=e.width/2,a.advancedStyleParams.radial.x1=e.width/2,a.advancedStyleParams.conic.x=e.width/2,a.advancedStyleParams.conic.y=0;break;case"right":o=e.width,r=e.height/2,l="end",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=-e.width,a.advancedStyleParams.radial.x0=-e.width/2,a.advancedStyleParams.radial.x1=-e.width/2,a.advancedStyleParams.conic.x=-e.width/2,a.advancedStyleParams.conic.y=0}if(e.translateX=o,e.translateY=r,s(null==i?void 0:i.textBaseline)&&(e.textBaseline=d),s(null==i?void 0:i.textAlign)&&(e.textAlign=l),["text","multi-line-text"].includes(e.contentType))switch(e.textBaseline){case"middle":a.textLine.yOffsetValue=(a.textLine.data.length-1)*e.lineHeight/2;break;case"bottom":case"alphabetic":case"ideographic":a.textLine.yOffsetValue=(a.textLine.data.length-1)*e.lineHeight+(e.lineHeight-parseInt(e.fontSize))/2;break;case"top":case"hanging":a.textLine.yOffsetValue=-e.lineHeight/2+parseInt(e.fontSize)/2}return a}(this.canvas,this.options,this.props)}return t.createCanvas=function(t,e){var i,n=window.devicePixelRatio||1,a=document.createElement("canvas");return a.width=t*n,a.height=e*n,a.style.width="".concat(t,"px"),a.style.height="".concat(e,"px"),null===(i=a.getContext("2d"))||void 0===i||i.setTransform(n,0,0,n,0,0),a},t.clearCanvas=function(t){var e=t.getContext("2d");if(null===e)throw new Error("get context error");e.restore(),e.resetTransform(),e.clearRect(0,0,t.width,t.height);var i=window.devicePixelRatio||1;e.setTransform(i,0,0,i,0,0)},t.prototype.getCanvas=function(){return this.canvas},t.prototype.clear=function(){t.clearCanvas(this.canvas)},t.prototype.draw=function(){var t=this,e=this.canvas.getContext("2d");if(null===e)throw new Error("get context error");return this.options.auxiliaryLine&&(e.beginPath(),e.rect(0,0,this.options.width,this.options.height),e.lineWidth=1,e.strokeStyle="#000",e.stroke(),e.closePath(),e.beginPath(),e.rect(this.options.translateX,this.options.translateY,1,1),e.lineWidth=1,e.strokeStyle="#f00",e.stroke(),e.closePath()),this.setStyle(e),e.save(),e.translate(this.options.translateX,this.options.translateY),e.rotate(this.options.rotate),new Promise(function(i){switch(t.options.contentType){case"text":t.drawText(e,i);break;case"image":t.drawImage(e,i);break;case"multi-line-text":t.drawMultiLineText(e,i);break;case"rich-text":t.drawRichText(e,i)}})},t.prototype.setStyle=function(t){var e,i="fillStyle";"stroke"===this.options.textType&&(i="strokeStyle");var n=this.options.fontColor;if(null===(e=this.options)||void 0===e?void 0:e.advancedStyle)switch(this.options.advancedStyle.type){case"linear":n=this.createLinearGradient(t);break;case"radial":n=this.createRadialGradient(t);break;case"conic":n=this.createConicGradient(t);break;case"pattern":n=this.createPattern(t)}t[i]&&n&&(t[i]=n),this.options.textAlign&&(t.textAlign=this.options.textAlign),this.options.textBaseline&&(t.textBaseline=this.options.textBaseline),t.globalAlpha=this.options.globalAlpha,this.options.shadowStyle&&(t.shadowBlur=h(this.options.shadowStyle.shadowBlur,0),t.shadowColor=h(this.options.shadowStyle.shadowColor,"#00000000"),t.shadowOffsetX=h(this.options.shadowStyle.shadowOffsetX,0),t.shadowOffsetY=h(this.options.shadowStyle.shadowOffsetY,0)),r(this.options.extraDrawFunc)&&this.options.extraDrawFunc(t)},t.prototype.createLinearGradient=function(t){var e,i,n,a,o,r,s,d,l,c,u,v,p,m,y,g=t.createLinearGradient(h(null===(n=null===(i=null===(e=this.options.advancedStyle)||void 0===e?void 0:e.params)||void 0===i?void 0:i.linear)||void 0===n?void 0:n.x0,this.recommendOptions.advancedStyleParams.linear.x0),h(null===(r=null===(o=null===(a=this.options.advancedStyle)||void 0===a?void 0:a.params)||void 0===o?void 0:o.linear)||void 0===r?void 0:r.y0,0),h(null===(l=null===(d=null===(s=this.options.advancedStyle)||void 0===s?void 0:s.params)||void 0===d?void 0:d.linear)||void 0===l?void 0:l.x1,this.recommendOptions.advancedStyleParams.linear.x1),h(null===(v=null===(u=null===(c=this.options.advancedStyle)||void 0===c?void 0:c.params)||void 0===u?void 0:u.linear)||void 0===v?void 0:v.y1,0));return null===(y=null===(m=null===(p=this.options)||void 0===p?void 0:p.advancedStyle)||void 0===m?void 0:m.colorStops)||void 0===y||y.forEach(function(t){g.addColorStop(t.offset,t.color)}),g},t.prototype.createConicGradient=function(t){var e,i,n,a,o,r,s,d,l,c,u,v,p,m,y,g=t.createConicGradient(h(null===(a=null===(n=null===(i=null===(e=this.options)||void 0===e?void 0:e.advancedStyle)||void 0===i?void 0:i.params)||void 0===n?void 0:n.conic)||void 0===a?void 0:a.startAngle,0),h(null===(d=null===(s=null===(r=null===(o=this.options)||void 0===o?void 0:o.advancedStyle)||void 0===r?void 0:r.params)||void 0===s?void 0:s.conic)||void 0===d?void 0:d.x,this.recommendOptions.advancedStyleParams.conic.x),h(null===(v=null===(u=null===(c=null===(l=this.options)||void 0===l?void 0:l.advancedStyle)||void 0===c?void 0:c.params)||void 0===u?void 0:u.conic)||void 0===v?void 0:v.y,this.recommendOptions.advancedStyleParams.conic.y));return null===(y=null===(m=null===(p=this.options)||void 0===p?void 0:p.advancedStyle)||void 0===m?void 0:m.colorStops)||void 0===y||y.forEach(function(t){g.addColorStop(t.offset,t.color)}),g},t.prototype.createRadialGradient=function(t){var e,i,n,a,o,r,s,d,l,c,u,v,p,m,y,g,f,w,x,b,S,k,P,O,C,L,E,T=t.createRadialGradient(h(null===(a=null===(n=null===(i=null===(e=this.options)||void 0===e?void 0:e.advancedStyle)||void 0===i?void 0:i.params)||void 0===n?void 0:n.radial)||void 0===a?void 0:a.x0,this.recommendOptions.advancedStyleParams.radial.x0),h(null===(d=null===(s=null===(r=null===(o=this.options)||void 0===o?void 0:o.advancedStyle)||void 0===r?void 0:r.params)||void 0===s?void 0:s.radial)||void 0===d?void 0:d.y0,this.recommendOptions.advancedStyleParams.radial.y0),h(null===(v=null===(u=null===(c=null===(l=this.options)||void 0===l?void 0:l.advancedStyle)||void 0===c?void 0:c.params)||void 0===u?void 0:u.radial)||void 0===v?void 0:v.r0,this.recommendOptions.advancedStyleParams.radial.r0),h(null===(g=null===(y=null===(m=null===(p=this.options)||void 0===p?void 0:p.advancedStyle)||void 0===m?void 0:m.params)||void 0===y?void 0:y.radial)||void 0===g?void 0:g.x1,this.recommendOptions.advancedStyleParams.radial.x1),h(null===(b=null===(x=null===(w=null===(f=this.options)||void 0===f?void 0:f.advancedStyle)||void 0===w?void 0:w.params)||void 0===x?void 0:x.radial)||void 0===b?void 0:b.y1,this.recommendOptions.advancedStyleParams.radial.y1),h(null===(O=null===(P=null===(k=null===(S=this.options)||void 0===S?void 0:S.advancedStyle)||void 0===k?void 0:k.params)||void 0===P?void 0:P.radial)||void 0===O?void 0:O.r1,this.recommendOptions.advancedStyleParams.radial.r1));return null===(E=null===(L=null===(C=this.options)||void 0===C?void 0:C.advancedStyle)||void 0===L?void 0:L.colorStops)||void 0===E||E.forEach(function(t){T.addColorStop(t.offset,t.color)}),T},t.prototype.createPattern=function(t){var e,i,n,a,o,r,s,d;return t.createPattern(null===(a=null===(n=null===(i=null===(e=this.options)||void 0===e?void 0:e.advancedStyle)||void 0===i?void 0:i.params)||void 0===n?void 0:n.pattern)||void 0===a?void 0:a.image,(null===(d=null===(s=null===(r=null===(o=this.options)||void 0===o?void 0:o.advancedStyle)||void 0===r?void 0:r.params)||void 0===s?void 0:s.pattern)||void 0===d?void 0:d.repetition)||"")},t.prototype.setText=function(t,e){var i="fillText";"stroke"===this.options.textType&&(i="strokeText"),t[i]&&t[i](e.text,e.x,e.y,e.maxWidth)},t.prototype.drawText=function(t,e){this.setText(t,{text:this.options.content,x:0,y:0-this.recommendOptions.textLine.yOffsetValue,maxWidth:this.options.textRowMaxWidth||this.options.width}),e(t.canvas)},t.prototype.drawImage=function(t,e){var i=this;u(this.options.image).then(function(n){var a=i.getImageRect(n),o=a.width,r=a.height,s=i.getDrawImagePosition(o,r);t.drawImage(n,s.x,s.y,o,r),e(t.canvas)})},t.prototype.drawMultiLineText=function(t,e){var i=this,n=this.recommendOptions.textLine.data,a=this.recommendOptions.textLine.yOffsetValue;n.forEach(function(e,n){i.setText(t,{text:e,x:0,y:i.options.lineHeight*n-a,maxWidth:i.options.textRowMaxWidth||i.options.width})}),e(t.canvas)},t.prototype.drawRichText=function(t,e){return n(this,void 0,void 0,function(){var i,n=this;return a(this,function(a){switch(a.label){case 0:return[4,l(t,this.options)];case 1:return i=a.sent(),u((o=i.element,r=o.outerHTML.replace(/<(img|br|input|hr|embed)(.*?)>/g,"<$1$2/>").replace(/\n/g,"").replace(/\t/g,"").replace(/#/g,"%23"),"data:image/svg+xml;charset=utf-8,".concat(r)),i.width,i.height).then(function(i){var a=n.getDrawImagePosition(i.width,i.height);t.drawImage(i,a.x,a.y,i.width,i.height),e(t.canvas)}),[2]}var o,r})})},t.prototype.getImageRect=function(t){var e={width:this.options.imageWidth||0,height:this.options.imageHeight||0};switch(!0){case 0!==e.width&&0===e.height:e.height=e.width*t.height/t.width;break;case 0===e.width&&0!==e.height:e.width=e.height*t.width/t.height;break;case 0===e.width&&0===e.height:e.width=t.width,e.height=t.height}return e},t.prototype.getDrawImagePosition=function(t,e){var i,n,a={x:-t/2,y:-e/2};switch(this.options.translatePlacement){case"top":a.x=-t/2,a.y=0;break;case"top-start":a.x=0,a.y=0;break;case"top-end":a.x=-t,a.y=0;break;case"bottom":a.x=-t/2,a.y=-e;break;case"bottom-start":a.x=0,a.y=-e;break;case"bottom-end":a.x=-t,a.y=-e;break;case"left":a.x=0,a.y=-e/2;break;case"right":a.x=-t,a.y=-e/2}return!s(null===(i=this.props)||void 0===i?void 0:i.translateX)&&(a.x=0),!s(null===(n=this.props)||void 0===n?void 0:n.translateY)&&(a.y=0),a},t}(),y=function(){function t(t,e){var i,n,a,o,r,s,d;this.options=t,this.partialWidth=this.options.width,this.partialHeight=this.options.height,this.rows=(null===(i=this.options.gridLayoutOptions)||void 0===i?void 0:i.rows)||1,this.cols=(null===(n=this.options.gridLayoutOptions)||void 0===n?void 0:n.cols)||1,this.matrix=(null===(a=this.options.gridLayoutOptions)||void 0===a?void 0:a.matrix)||(r=this.rows,s=this.cols,d=1,Array.from({length:r},function(){return new Array(s).fill(d)})),this.gap=(null===(o=this.options.gridLayoutOptions)||void 0===o?void 0:o.gap)||[0,0],this.partialCanvas=e}return t.prototype.draw=function(){var t,e,i,n,a,o,r,s,d=m.createCanvas((null===(t=this.options.gridLayoutOptions)||void 0===t?void 0:t.width)||this.partialWidth*this.cols+this.gap[0]*this.cols,(null===(e=this.options.gridLayoutOptions)||void 0===e?void 0:e.height)||this.partialHeight*this.rows+this.gap[1]*this.rows),l=d.getContext("2d");(null===(i=this.options.gridLayoutOptions)||void 0===i?void 0:i.backgroundImage)&&(null==l||l.drawImage(null===(n=this.options.gridLayoutOptions)||void 0===n?void 0:n.backgroundImage,0,0,null===(a=this.options.gridLayoutOptions)||void 0===a?void 0:a.width,null===(o=this.options.gridLayoutOptions)||void 0===o?void 0:o.height));for(var c=0;c<this.rows;c++)for(var h=0;h<this.cols;h++)(null===(s=null===(r=this.matrix)||void 0===r?void 0:r[c])||void 0===s?void 0:s[h])&&(null==l||l.drawImage(this.partialCanvas,this.partialWidth*h+this.gap[0]*h,this.partialHeight*c+this.gap[1]*c,this.partialWidth,this.partialHeight));return d},t}(),g=function(t,e){return"grid"===t.layout?new y(t,e).draw():e},f=function(){function t(t){void 0===t&&(t={}),this.parentElement=document.body,this.isCreating=!1,this.props=t,this.options=i(i({},v),t),this.changeParentElement(this.options.parent),this.watermarkCanvas=new m(this.props,this.options),p(this.options.monitorProtection)}return t.prototype.changeOptions=function(){return n(this,arguments,void 0,function(t,e,i){return void 0===t&&(t={}),void 0===e&&(e="overwrite"),void 0===i&&(i=!0),a(this,function(n){switch(n.label){case 0:return this.initConfigData(t,e),p(this.options.monitorProtection),i?(this.remove(),[4,this.create()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},t.prototype.create=function(){return n(this,void 0,void 0,function(){var t,e,i,n,r,d,l,c,h,u,v,p;return a(this,function(a){switch(a.label){case 0:return this.isCreating?[2]:(this.isCreating=!0,this.validateUnique()&&this.validateContent()?(t=s(this.watermarkDom),[4,null===(d=this.watermarkCanvas)||void 0===d?void 0:d.draw()]):(this.isCreating=!1,[2]));case 1:if(a.sent(),this.layoutCanvas=g(this.options,null===(l=this.watermarkCanvas)||void 0===l?void 0:l.getCanvas()),e=o(this.layoutCanvas),null===(c=this.watermarkCanvas)||void 0===c||c.clear(),this.watermarkDom=document.createElement("div"),i=document.createElement("div"),this.watermarkDom.__WATERMARK__="watermark",this.watermarkDom.__WATERMARK__INSTANCE__=this,n=this.checkParentElementType(),this.watermarkDom.style.cssText="\n z-index:".concat(this.options.zIndex,"!important;display:block!important;visibility:visible!important;transform:none!important;scale:none!important;\n ").concat("custom"===n?"top:0!important;bottom:0!important;left:0!important;right:0!important;height:100%!important;pointer-events:none!important;position:absolute!important;":"position:relative!important;","\n "),r=function(t){var e,i,n;if("grid"===t.layout){var a=(null===(e=t.gridLayoutOptions)||void 0===e?void 0:e.cols)||1,o=(null===(i=t.gridLayoutOptions)||void 0===i?void 0:i.rows)||1,r=(null===(n=t.gridLayoutOptions)||void 0===n?void 0:n.gap)||[0,0];return[t.width*a+r[0]*a,t.height*o+r[1]*o]}return[t.width,t.height]}(this.options),i.style.cssText="\n display:block!important;visibility:visible!important;pointer-events:none;top:0;bottom:0;left:0;right:0;transform:none!important;scale:none!important;\n position:".concat("root"===n?"fixed":"absolute","!important;-webkit-print-color-adjust:exact!important;width:100%!important;height:100%!important;\n z-index:").concat(this.options.zIndex,"!important;background-image:url(").concat(e,")!important;background-repeat:").concat(this.options.backgroundRepeat,"!important;\n background-size:").concat(r[0],"px ").concat(r[1],"px!important;background-position:").concat(this.options.backgroundPosition,";\n ").concat(function(t,e){if(!t)return"";var i=6*Math.random()+2,n=2*Math.random()+2;switch(e){case"repeat":return"animation: 200s linear 0s infinite alternate watermark !important;";case"repeat-x":return"animation: ".concat(i,"s linear 0s infinite alternate watermark-vertical !important;'");case"repeat-y":return"animation: ".concat(n,"s linear 0s infinite alternate watermark-horizontal !important;'");case"no-repeat":return"animation: ".concat(i,"s linear 0s infinite alternate watermark-horizontal, ").concat(n,"s linear 0s infinite alternate watermark-vertical !important;");default:return""}}(this.options.movable,this.options.backgroundRepeat),"\n "),this.watermarkDom.appendChild(i),this.parentElement.appendChild(this.watermarkDom),this.options.mutationObserve)try{this.bindMutationObserve()}catch(t){null===(u=(h=this.options).onObserveError)||void 0===u||u.call(h)}return t&&(null===(p=(v=this.options).onSuccess)||void 0===p||p.call(v)),this.isCreating=!1,[2]}})})},t.prototype.destroy=function(){this.remove(),this.watermarkDom=void 0},t.prototype.check=function(){return n(this,void 0,void 0,function(){return a(this,function(t){return[2,this.parentElement.contains(this.watermarkDom)]})})},t.prototype.remove=function(){var t,e,i,n,a,o,r,s;null===(e=(t=this.options).onBeforeDestroy)||void 0===e||e.call(t),null===(i=this.observer)||void 0===i||i.disconnect(),null===(n=this.parentObserve)||void 0===n||n.disconnect(),null===(o=null===(a=this.watermarkDom)||void 0===a?void 0:a.parentNode)||void 0===o||o.removeChild(this.watermarkDom),null===(s=(r=this.options).onDestroyed)||void 0===s||s.call(r)},t.prototype.initConfigData=function(t,e){var n=this;void 0===e&&(e="overwrite"),"append"===e?Object.keys(t).forEach(function(e){n.props&&(n.props[e]=t[e])}):this.props=t,this.options=i(i({},v),this.props),this.changeParentElement(this.options.parent),this.watermarkCanvas=new m(this.props,this.options)},t.prototype.changeParentElement=function(t){if("string"==typeof t){var e=document.querySelector(t);e&&(this.parentElement=e)}else this.parentElement=t;this.parentElement||console.error("[WatermarkJsPlus]: please pass a valid parent element.")},t.prototype.validateUnique=function(){var t=!0;return Array.from(this.parentElement.childNodes).forEach(function(e){t&&Object.hasOwnProperty.call(e,"__WATERMARK__")&&(t=!1)}),t},t.prototype.validateContent=function(){switch(this.options.contentType){case"image":return Object.hasOwnProperty.call(this.options,"image");case"multi-line-text":case"rich-text":case"text":return this.options.content.length>0}},t.prototype.checkParentElementType=function(){return["html","body"].includes(this.parentElement.tagName.toLocaleLowerCase())?"root":"custom"},t.prototype.bindMutationObserve=function(){var t=this;this.watermarkDom&&(this.observer=new MutationObserver(function(e){return n(t,void 0,void 0,function(){return a(this,function(t){switch(t.label){case 0:return e.length>0?(this.remove(),[4,this.create()]):[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})}),this.observer.observe(this.watermarkDom,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),this.parentObserve=new MutationObserver(function(e){return n(t,void 0,void 0,function(){var t,i,n;return a(this,function(a){switch(a.label){case 0:t=0,i=e,a.label=1;case 1:return t<i.length?(n=i[t],Array.from(n.removedNodes).includes(this.watermarkDom)?(this.remove(),[4,this.create()]):[3,3]):[3,4];case 2:a.sent(),a.label=3;case 3:return t++,[3,1];case 4:return[2]}})})}),this.parentObserve.observe(this.parentElement,{childList:!0}))},t}(),w=function(t){function s(e){void 0===e&&(e={});return t.call(this,i(i({},e),{globalAlpha:.005,mode:"blind"}))||this}return function(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}(s,t),s.prototype.changeOptions=function(){return n(this,arguments,void 0,function(t,e,i){return void 0===t&&(t={}),void 0===e&&(e="overwrite"),void 0===i&&(i=!0),a(this,function(n){switch(n.label){case 0:return t.globalAlpha=.005,t.mode="blind",this.initConfigData(t,e),p(this.options.monitorProtection),i?(this.remove(),[4,this.create()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},s.decode=function(t){var e=t.url,i=void 0===e?"":e,n=t.fillColor,a=void 0===n?"#000":n,s=t.compositeOperation,d=void 0===s?"color-burn":s,l=t.mode,c=void 0===l?"canvas":l,h=t.compositeTimes,u=void 0===h?3:h,v=t.onSuccess;if(i&&"canvas"===c){var p=new Image;p.src=i,p.addEventListener("load",function(){var t=p.width,e=p.height,i=m.createCanvas(t,e),n=i.getContext("2d");if(!n)throw new Error("get context error");n.drawImage(p,0,0,t,e),n.globalCompositeOperation=d,n.fillStyle=a;for(var s=0;s<u;s++)n.fillRect(0,0,t,e);var l=o(i);r(v)&&(null==v||v(l))})}},s}(f),x=function(){function t(t){var e,n;void 0===t&&(t={}),this.drew=!1,this.props=t,this.options=i(i({},v),t),this.props.crossOrigin&&(null===(e=this.props.dom)||void 0===e||e.setAttribute("crossOrigin","anonymous")),this.watermarkCanvas=new m(this.props,this.options),this.originalSrc=null===(n=this.props.dom)||void 0===n?void 0:n.src,this.backgroundImage=this.getBackgroundImage()}return t.prototype.create=function(){return n(this,void 0,void 0,function(){var t,e,n,r,s;return a(this,function(a){switch(a.label){case 0:return this.drew?[2]:[4,null===(t=this.watermarkCanvas)||void 0===t?void 0:t.draw()];case 1:return a.sent(),this.options.layout="grid",this.options.gridLayoutOptions=i(i({},this.options.gridLayoutOptions),{width:null===(e=this.backgroundImage)||void 0===e?void 0:e.width,height:null===(n=this.backgroundImage)||void 0===n?void 0:n.height,backgroundImage:this.backgroundImage}),this.layoutCanvas=g(this.options,null===(r=this.watermarkCanvas)||void 0===r?void 0:r.getCanvas()),this.options.dom.src=o(this.layoutCanvas),null===(s=this.watermarkCanvas)||void 0===s||s.clear(),this.drew=!0,[2]}})})},t.prototype.destroy=function(){this.options.dom.src=this.originalSrc,this.drew=!1},t.prototype.getBackgroundImage=function(){if(this.options.dom)return this.options.dom},t}();return t.BlindWatermark=w,t.ImageWatermark=x,t.Watermark=f,t}({});
1
+ var WatermarkPlus=function(t){"use strict";!function(t,e){void 0===e&&(e={});var i=e.insertAt;if("undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===i&&n.firstChild?n.insertBefore(a,n.firstChild):n.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t))}}("@keyframes watermark{0%{background-position:0 0}25%{background-position:100% 100%}50%{background-position:100% 0}75%{background-position:0 100%}to{background-position:0 0}}@keyframes watermark-horizontal{0%{background-position-x:0}to{background-position-x:100%}}@keyframes watermark-vertical{0%{background-position-y:0}to{background-position-y:100%}}");var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},e(t,i)};var i=function(){return i=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var a in e=arguments[i])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},i.apply(this,arguments)};function n(t,e,i,n){return new(i||(i=Promise))(function(a,o){function r(t){try{l(n.next(t))}catch(t){o(t)}}function s(t){try{l(n.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?a(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(r,s)}l((n=n.apply(t,e||[])).next())})}function a(t,e){var i,n,a,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},r=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return r.next=s(0),r.throw=s(1),r.return=s(2),"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(o=0)),o;)try{if(i=1,n&&(a=2&s[0]?n.return:s[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,s[1])).done)return a;switch(n=0,a&&(s=[2&s[0],a.value]),s[0]){case 0:case 1:a=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(a=o.trys,(a=a.length>0&&a[a.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!a||s[1]>a[0]&&s[1]<a[3])){o.label=s[1];break}if(6===s[0]&&o.label<a[1]){o.label=a[1],a=s;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(s);break}a[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],n=0}finally{i=a=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var o=function(t){return t.toDataURL("image/png",1)},r=function(t){return"function"==typeof t},s=function(t){return void 0===t},l=function(t,e,i){void 0===e&&(e={}),void 0===i&&(i="http://www.w3.org/2000/svg");var n=document.createElementNS(i,t);for(var a in e)n.setAttribute(a,e[a]);return n},d=function(t,e){return n(void 0,void 0,void 0,function(){var i,n,o,r,s,d,h,u,p;return a(this,function(a){switch(a.label){case 0:return i=l("svg",{xmlns:"http://www.w3.org/2000/svg"}),(n=document.createElement("div")).setAttribute("xmlns","http://www.w3.org/1999/xhtml"),n.style.cssText="\n text-align: center;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 100%;\n font: ".concat(t.font,";\n color: ").concat(e.fontColor,";\n"),n.innerHTML="<div class='rich-text-content'>".concat(e.content,"</div>"),document.body.appendChild(n),[4,c(n)];case 1:return a.sent(),o=null===(p=n.querySelector(".rich-text-content"))||void 0===p?void 0:p.getBoundingClientRect(),r=null==o?void 0:o.width,s=null==o?void 0:o.height,document.body.removeChild(n),d=e.richTextWidth||r||e.width,h=e.richTextHeight||s||e.height,i.setAttribute("width",d.toString()),i.setAttribute("height",h.toString()),(u=l("foreignObject",{width:d.toString(),height:h.toString()})).appendChild(n),i.appendChild(u),[2,{element:i,width:d,height:h}]}})})};function c(t){return n(this,void 0,void 0,function(){var e,i,n,o,r;return a(this,function(s){switch(s.label){case 0:e=t.querySelectorAll("img"),i=function(t){var e,i,n,o;return a(this,function(a){switch(a.label){case 0:if(!(e=t.getAttribute("src")))return[3,6];a.label=1;case 1:return a.trys.push([1,5,,6]),[4,fetch(e)];case 2:return[4,a.sent().blob()];case 3:return i=a.sent(),[4,new Promise(function(t,e){var n=new FileReader;n.onloadend=function(){return t(n.result)},n.onerror=e,n.readAsDataURL(i)})];case 4:return n=a.sent(),"string"==typeof n&&t.setAttribute("src",n),[3,6];case 5:return o=a.sent(),console.error("Error converting ".concat(e," to base64:"),o),[3,6];case 6:return[2]}})},n=0,o=Array.from(e),s.label=1;case 1:return n<o.length?(r=o[n],[5,i(r)]):[3,4];case 2:s.sent(),s.label=3;case 3:return n++,[3,1];case 4:return[2]}})})}var h=function(t,e){return s(t)?e:t},u=function(t,e,i){void 0===e&&(e=void 0),void 0===i&&(i=void 0);var n=new Image;return n.setAttribute("crossOrigin","anonymous"),!s(e)&&(n.width=e),!s(i)&&(n.height=i),n.src=t,new Promise(function(t){n.onload=function(){t(n)}})},p={width:300,height:300,rotate:45,layout:"default",auxiliaryLine:!1,translatePlacement:"middle",contentType:"text",content:"hello watermark-js-plus",textType:"fill",imageWidth:0,imageHeight:0,lineHeight:30,zIndex:2147483647,backgroundPosition:"0 0",backgroundRepeat:"repeat",fontSize:"20px",fontFamily:"sans-serif",fontStyle:"",fontVariant:"",fontColor:"#000",fontWeight:"normal",filter:"none",letterSpacing:"0px",wordSpacing:"0px",globalAlpha:.5,mode:"default",mutationObserve:!0,monitorProtection:!1,movable:!1,parent:"body",onSuccess:function(){},onBeforeDestroy:function(){},onDestroyed:function(){},onObserveError:function(){}},v=function(t){"undefined"!=typeof window&&t&&Object.defineProperty(window,"MutationObserver",{writable:!1,configurable:!1})},m=function(){function t(e,i){this.props=e,this.options=i,this.canvas=t.createCanvas(this.options.width,this.options.height),this.recommendOptions=function(t,e,i){var n=t.getContext("2d");if(null===n)throw new Error("get context error");n.font="".concat(e.fontStyle," ").concat(e.fontVariant," ").concat(e.fontWeight," ").concat(e.fontSize," ").concat(e.fontFamily),n.filter=e.filter,n.letterSpacing=e.letterSpacing,n.wordSpacing=e.wordSpacing,(null==e?void 0:e.rotate)&&(e.rotate=(360-e.rotate%360)*(Math.PI/180)),s(i.textRowMaxWidth)&&(e.textRowMaxWidth=e.width);var a={image:{rect:{width:e.imageWidth,height:e.imageHeight},position:{x:0,y:0}},textLine:{data:[],yOffsetValue:0},advancedStyleParams:{linear:{x0:0,x1:0},radial:{x0:0,y0:0,r0:0,x1:0,y1:0,r1:0},conic:{x:0,y:0,startAngle:0},pattern:{}}};switch(e.contentType){case"text":a.textLine.data=[e.content];break;case"multi-line-text":a.textLine.data=function(t,e,i){for(var n=[],a="",o="",r=0,s=e.length;r<s;r++)"\n"!==(o=e.charAt(r))?(a+=o,t.measureText(a).width>i&&(n.push(a.substring(0,a.length-1)),a="",r--)):(n.push(a),a="");return n.push(a),n}(n,e.content,e.textRowMaxWidth)}var o=e.width/2,r=e.height/2,l="middle",d="center";switch(s(null==i?void 0:i.translateX)||s(null==i?void 0:i.translateY)?(a.advancedStyleParams.linear.x0=-e.width/2,a.advancedStyleParams.linear.x1=e.width/2,a.advancedStyleParams.radial.r0=0,a.advancedStyleParams.radial.r1=e.width/2):(o=null==i?void 0:i.translateX,r=null==i?void 0:i.translateY,l="top",d="left"),i.translatePlacement){case"top":o=e.width/2,r=0,l="top",a.advancedStyleParams.linear.x0=-e.width/2,a.advancedStyleParams.linear.x1=e.width/2,a.advancedStyleParams.radial.y0=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.y1=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.y=a.textLine.data.length*e.lineHeight/2;break;case"top-start":o=0,r=0,l="top",d="start",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=e.width,a.advancedStyleParams.radial.x0=e.width/2,a.advancedStyleParams.radial.y0=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.x1=e.width/2,a.advancedStyleParams.radial.y1=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.x=e.width/2,a.advancedStyleParams.conic.y=a.textLine.data.length*e.lineHeight/2;break;case"top-end":o=e.width,r=0,l="top",d="end",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=-e.width,a.advancedStyleParams.radial.x0=-e.width/2,a.advancedStyleParams.radial.y0=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.x1=-e.width/2,a.advancedStyleParams.radial.y1=a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.x=-e.width/2,a.advancedStyleParams.conic.y=a.textLine.data.length*e.lineHeight/2;break;case"bottom":o=e.width/2,r=e.height,l="bottom",a.advancedStyleParams.linear.x0=-e.width/2,a.advancedStyleParams.linear.x1=e.width/2,a.advancedStyleParams.radial.y0=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.y1=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.x=0,a.advancedStyleParams.conic.y=-a.textLine.data.length*e.lineHeight/2;break;case"bottom-start":o=0,r=e.height,l="bottom",d="start",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=e.width,a.advancedStyleParams.radial.x0=e.width/2,a.advancedStyleParams.radial.y0=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.x1=e.width/2,a.advancedStyleParams.radial.y1=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.x=e.width/2,a.advancedStyleParams.conic.y=-a.textLine.data.length*e.lineHeight/2;break;case"bottom-end":o=e.width,r=e.height,l="bottom",d="end",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=-e.width,a.advancedStyleParams.radial.x0=-e.width/2,a.advancedStyleParams.radial.y0=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.radial.x1=-e.width/2,a.advancedStyleParams.radial.y1=-a.textLine.data.length*e.lineHeight/2,a.advancedStyleParams.conic.x=-e.width/2,a.advancedStyleParams.conic.y=-a.textLine.data.length*e.lineHeight/2;break;case"left":o=0,r=e.height/2,d="start",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=e.width,a.advancedStyleParams.radial.x0=e.width/2,a.advancedStyleParams.radial.x1=e.width/2,a.advancedStyleParams.conic.x=e.width/2,a.advancedStyleParams.conic.y=0;break;case"right":o=e.width,r=e.height/2,d="end",a.advancedStyleParams.linear.x0=0,a.advancedStyleParams.linear.x1=-e.width,a.advancedStyleParams.radial.x0=-e.width/2,a.advancedStyleParams.radial.x1=-e.width/2,a.advancedStyleParams.conic.x=-e.width/2,a.advancedStyleParams.conic.y=0}if(e.translateX=o,e.translateY=r,s(null==i?void 0:i.textBaseline)&&(e.textBaseline=l),s(null==i?void 0:i.textAlign)&&(e.textAlign=d),["text","multi-line-text"].includes(e.contentType))switch(e.textBaseline){case"middle":a.textLine.yOffsetValue=(a.textLine.data.length-1)*e.lineHeight/2;break;case"bottom":case"alphabetic":case"ideographic":a.textLine.yOffsetValue=(a.textLine.data.length-1)*e.lineHeight+(e.lineHeight-parseInt(e.fontSize))/2;break;case"top":case"hanging":a.textLine.yOffsetValue=-e.lineHeight/2+parseInt(e.fontSize)/2}return a}(this.canvas,this.options,this.props)}return t.createCanvas=function(t,e){var i,n=window.devicePixelRatio||1,a=document.createElement("canvas");return a.width=t*n,a.height=e*n,a.style.width="".concat(t,"px"),a.style.height="".concat(e,"px"),null===(i=a.getContext("2d"))||void 0===i||i.setTransform(n,0,0,n,0,0),a},t.clearCanvas=function(t){var e=t.getContext("2d");if(null===e)throw new Error("get context error");e.restore(),e.resetTransform(),e.clearRect(0,0,t.width,t.height);var i=window.devicePixelRatio||1;e.setTransform(i,0,0,i,0,0)},t.prototype.getCanvas=function(){return this.canvas},t.prototype.clear=function(){t.clearCanvas(this.canvas)},t.prototype.draw=function(){var t=this,e=this.canvas.getContext("2d");if(null===e)throw new Error("get context error");return this.options.auxiliaryLine&&(e.beginPath(),e.rect(0,0,this.options.width,this.options.height),e.lineWidth=1,e.strokeStyle="#000",e.stroke(),e.closePath(),e.beginPath(),e.rect(this.options.translateX,this.options.translateY,1,1),e.lineWidth=1,e.strokeStyle="#f00",e.stroke(),e.closePath()),this.setStyle(e),e.save(),e.translate(this.options.translateX,this.options.translateY),e.rotate(this.options.rotate),new Promise(function(i){switch(t.options.contentType){case"text":t.drawText(e,i);break;case"image":t.drawImage(e,i);break;case"multi-line-text":t.drawMultiLineText(e,i);break;case"rich-text":t.drawRichText(e,i)}})},t.prototype.setStyle=function(t){var e,i="fillStyle";"stroke"===this.options.textType&&(i="strokeStyle");var n=this.options.fontColor;if(null===(e=this.options)||void 0===e?void 0:e.advancedStyle)switch(this.options.advancedStyle.type){case"linear":n=this.createLinearGradient(t);break;case"radial":n=this.createRadialGradient(t);break;case"conic":n=this.createConicGradient(t);break;case"pattern":n=this.createPattern(t)}t[i]&&n&&(t[i]=n),this.options.textAlign&&(t.textAlign=this.options.textAlign),this.options.textBaseline&&(t.textBaseline=this.options.textBaseline),t.globalAlpha=this.options.globalAlpha,this.options.shadowStyle&&(t.shadowBlur=h(this.options.shadowStyle.shadowBlur,0),t.shadowColor=h(this.options.shadowStyle.shadowColor,"#00000000"),t.shadowOffsetX=h(this.options.shadowStyle.shadowOffsetX,0),t.shadowOffsetY=h(this.options.shadowStyle.shadowOffsetY,0)),r(this.options.extraDrawFunc)&&this.options.extraDrawFunc(t)},t.prototype.createLinearGradient=function(t){var e,i,n,a,o,r,s,l,d,c,u,p,v,m,y,g=t.createLinearGradient(h(null===(n=null===(i=null===(e=this.options.advancedStyle)||void 0===e?void 0:e.params)||void 0===i?void 0:i.linear)||void 0===n?void 0:n.x0,this.recommendOptions.advancedStyleParams.linear.x0),h(null===(r=null===(o=null===(a=this.options.advancedStyle)||void 0===a?void 0:a.params)||void 0===o?void 0:o.linear)||void 0===r?void 0:r.y0,0),h(null===(d=null===(l=null===(s=this.options.advancedStyle)||void 0===s?void 0:s.params)||void 0===l?void 0:l.linear)||void 0===d?void 0:d.x1,this.recommendOptions.advancedStyleParams.linear.x1),h(null===(p=null===(u=null===(c=this.options.advancedStyle)||void 0===c?void 0:c.params)||void 0===u?void 0:u.linear)||void 0===p?void 0:p.y1,0));return null===(y=null===(m=null===(v=this.options)||void 0===v?void 0:v.advancedStyle)||void 0===m?void 0:m.colorStops)||void 0===y||y.forEach(function(t){g.addColorStop(t.offset,t.color)}),g},t.prototype.createConicGradient=function(t){var e,i,n,a,o,r,s,l,d,c,u,p,v,m,y,g=t.createConicGradient(h(null===(a=null===(n=null===(i=null===(e=this.options)||void 0===e?void 0:e.advancedStyle)||void 0===i?void 0:i.params)||void 0===n?void 0:n.conic)||void 0===a?void 0:a.startAngle,0),h(null===(l=null===(s=null===(r=null===(o=this.options)||void 0===o?void 0:o.advancedStyle)||void 0===r?void 0:r.params)||void 0===s?void 0:s.conic)||void 0===l?void 0:l.x,this.recommendOptions.advancedStyleParams.conic.x),h(null===(p=null===(u=null===(c=null===(d=this.options)||void 0===d?void 0:d.advancedStyle)||void 0===c?void 0:c.params)||void 0===u?void 0:u.conic)||void 0===p?void 0:p.y,this.recommendOptions.advancedStyleParams.conic.y));return null===(y=null===(m=null===(v=this.options)||void 0===v?void 0:v.advancedStyle)||void 0===m?void 0:m.colorStops)||void 0===y||y.forEach(function(t){g.addColorStop(t.offset,t.color)}),g},t.prototype.createRadialGradient=function(t){var e,i,n,a,o,r,s,l,d,c,u,p,v,m,y,g,f,w,x,b,S,k,P,O,C,L,E,T=t.createRadialGradient(h(null===(a=null===(n=null===(i=null===(e=this.options)||void 0===e?void 0:e.advancedStyle)||void 0===i?void 0:i.params)||void 0===n?void 0:n.radial)||void 0===a?void 0:a.x0,this.recommendOptions.advancedStyleParams.radial.x0),h(null===(l=null===(s=null===(r=null===(o=this.options)||void 0===o?void 0:o.advancedStyle)||void 0===r?void 0:r.params)||void 0===s?void 0:s.radial)||void 0===l?void 0:l.y0,this.recommendOptions.advancedStyleParams.radial.y0),h(null===(p=null===(u=null===(c=null===(d=this.options)||void 0===d?void 0:d.advancedStyle)||void 0===c?void 0:c.params)||void 0===u?void 0:u.radial)||void 0===p?void 0:p.r0,this.recommendOptions.advancedStyleParams.radial.r0),h(null===(g=null===(y=null===(m=null===(v=this.options)||void 0===v?void 0:v.advancedStyle)||void 0===m?void 0:m.params)||void 0===y?void 0:y.radial)||void 0===g?void 0:g.x1,this.recommendOptions.advancedStyleParams.radial.x1),h(null===(b=null===(x=null===(w=null===(f=this.options)||void 0===f?void 0:f.advancedStyle)||void 0===w?void 0:w.params)||void 0===x?void 0:x.radial)||void 0===b?void 0:b.y1,this.recommendOptions.advancedStyleParams.radial.y1),h(null===(O=null===(P=null===(k=null===(S=this.options)||void 0===S?void 0:S.advancedStyle)||void 0===k?void 0:k.params)||void 0===P?void 0:P.radial)||void 0===O?void 0:O.r1,this.recommendOptions.advancedStyleParams.radial.r1));return null===(E=null===(L=null===(C=this.options)||void 0===C?void 0:C.advancedStyle)||void 0===L?void 0:L.colorStops)||void 0===E||E.forEach(function(t){T.addColorStop(t.offset,t.color)}),T},t.prototype.createPattern=function(t){var e,i,n,a,o,r,s,l;return t.createPattern(null===(a=null===(n=null===(i=null===(e=this.options)||void 0===e?void 0:e.advancedStyle)||void 0===i?void 0:i.params)||void 0===n?void 0:n.pattern)||void 0===a?void 0:a.image,(null===(l=null===(s=null===(r=null===(o=this.options)||void 0===o?void 0:o.advancedStyle)||void 0===r?void 0:r.params)||void 0===s?void 0:s.pattern)||void 0===l?void 0:l.repetition)||"")},t.prototype.setText=function(t,e){var i="fillText";"stroke"===this.options.textType&&(i="strokeText"),t[i]&&t[i](e.text,e.x,e.y,e.maxWidth)},t.prototype.drawText=function(t,e){this.setText(t,{text:this.options.content,x:0,y:0-this.recommendOptions.textLine.yOffsetValue,maxWidth:this.options.textRowMaxWidth||this.options.width}),e(t.canvas)},t.prototype.drawImage=function(t,e){var i=this;u(this.options.image).then(function(n){var a=i.getImageRect(n),o=a.width,r=a.height,s=i.getDrawImagePosition(o,r);t.drawImage(n,s.x,s.y,o,r),e(t.canvas)})},t.prototype.drawMultiLineText=function(t,e){var i=this,n=this.recommendOptions.textLine.data,a=this.recommendOptions.textLine.yOffsetValue;n.forEach(function(e,n){i.setText(t,{text:e,x:0,y:i.options.lineHeight*n-a,maxWidth:i.options.textRowMaxWidth||i.options.width})}),e(t.canvas)},t.prototype.drawRichText=function(t,e){return n(this,void 0,void 0,function(){var i,n=this;return a(this,function(a){switch(a.label){case 0:return[4,d(t,this.options)];case 1:return i=a.sent(),u((o=i.element,r=o.outerHTML.replace(/<(img|br|input|hr|embed)(.*?)>/g,"<$1$2/>").replace(/\n/g,"").replace(/\t/g,"").replace(/#/g,"%23"),"data:image/svg+xml;charset=utf-8,".concat(r)),i.width,i.height).then(function(i){var a=n.getDrawImagePosition(i.width,i.height);t.drawImage(i,a.x,a.y,i.width,i.height),e(t.canvas)}),[2]}var o,r})})},t.prototype.getImageRect=function(t){var e={width:this.options.imageWidth||0,height:this.options.imageHeight||0};switch(!0){case 0!==e.width&&0===e.height:e.height=e.width*t.height/t.width;break;case 0===e.width&&0!==e.height:e.width=e.height*t.width/t.height;break;case 0===e.width&&0===e.height:e.width=t.width,e.height=t.height}return e},t.prototype.getDrawImagePosition=function(t,e){var i,n,a={x:-t/2,y:-e/2};switch(this.options.translatePlacement){case"top":a.x=-t/2,a.y=0;break;case"top-start":a.x=0,a.y=0;break;case"top-end":a.x=-t,a.y=0;break;case"bottom":a.x=-t/2,a.y=-e;break;case"bottom-start":a.x=0,a.y=-e;break;case"bottom-end":a.x=-t,a.y=-e;break;case"left":a.x=0,a.y=-e/2;break;case"right":a.x=-t,a.y=-e/2}return!s(null===(i=this.props)||void 0===i?void 0:i.translateX)&&(a.x=0),!s(null===(n=this.props)||void 0===n?void 0:n.translateY)&&(a.y=0),a},t}(),y=function(){function t(t,e){var i,n,a,o,r,s,l;this.options=t,this.partialWidth=this.options.width,this.partialHeight=this.options.height,this.rows=(null===(i=this.options.gridLayoutOptions)||void 0===i?void 0:i.rows)||1,this.cols=(null===(n=this.options.gridLayoutOptions)||void 0===n?void 0:n.cols)||1,this.matrix=(null===(a=this.options.gridLayoutOptions)||void 0===a?void 0:a.matrix)||(r=this.rows,s=this.cols,l=1,Array.from({length:r},function(){return new Array(s).fill(l)})),this.gap=(null===(o=this.options.gridLayoutOptions)||void 0===o?void 0:o.gap)||[0,0],this.partialCanvas=e}return t.prototype.draw=function(){var t,e,i,n,a,o,r,s,l=m.createCanvas((null===(t=this.options.gridLayoutOptions)||void 0===t?void 0:t.width)||this.partialWidth*this.cols+this.gap[0]*this.cols,(null===(e=this.options.gridLayoutOptions)||void 0===e?void 0:e.height)||this.partialHeight*this.rows+this.gap[1]*this.rows),d=l.getContext("2d");(null===(i=this.options.gridLayoutOptions)||void 0===i?void 0:i.backgroundImage)&&(null==d||d.drawImage(null===(n=this.options.gridLayoutOptions)||void 0===n?void 0:n.backgroundImage,0,0,null===(a=this.options.gridLayoutOptions)||void 0===a?void 0:a.width,null===(o=this.options.gridLayoutOptions)||void 0===o?void 0:o.height));for(var c=0;c<this.rows;c++)for(var h=0;h<this.cols;h++)(null===(s=null===(r=this.matrix)||void 0===r?void 0:r[c])||void 0===s?void 0:s[h])&&(null==d||d.drawImage(this.partialCanvas,this.partialWidth*h+this.gap[0]*h,this.partialHeight*c+this.gap[1]*c,this.partialWidth,this.partialHeight));return l},t}(),g=function(t,e){return"grid"===t.layout?new y(t,e).draw():e},f=function(){function t(t){void 0===t&&(t={}),this.parentElement=document.body,this.isCreating=!1,this.props=t,this.options=i(i({},p),t),this.changeParentElement(this.options.parent),this.watermarkCanvas=new m(this.props,this.options),v(this.options.monitorProtection)}return t.prototype.changeOptions=function(){return n(this,arguments,void 0,function(t,e,i){return void 0===t&&(t={}),void 0===e&&(e="overwrite"),void 0===i&&(i=!0),a(this,function(n){switch(n.label){case 0:return this.initConfigData(t,e),v(this.options.monitorProtection),i?(this.remove(),[4,this.create()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},t.prototype.create=function(){return n(this,void 0,void 0,function(){var t,e,i,n,r,l,d,c,h,u,p,v;return a(this,function(a){switch(a.label){case 0:if(this.isCreating)return[2];this.isCreating=!0,a.label=1;case 1:return a.trys.push([1,,3,4]),this.validateUnique()?this.validateContent()?(t=s(this.watermarkDom),[4,null===(l=this.watermarkCanvas)||void 0===l?void 0:l.draw()]):[2]:[2];case 2:if(a.sent(),this.layoutCanvas=g(this.options,null===(d=this.watermarkCanvas)||void 0===d?void 0:d.getCanvas()),e=o(this.layoutCanvas),null===(c=this.watermarkCanvas)||void 0===c||c.clear(),this.watermarkDom=document.createElement("div"),i=document.createElement("div"),this.watermarkDom.__WATERMARK__="watermark",this.watermarkDom.__WATERMARK__INSTANCE__=this,n=this.checkParentElementType(),this.watermarkDom.style.cssText="\n z-index:".concat(this.options.zIndex,"!important;display:block!important;visibility:visible!important;transform:none!important;scale:none!important;\n ").concat("custom"===n?"top:0!important;bottom:0!important;left:0!important;right:0!important;height:100%!important;pointer-events:none!important;position:absolute!important;":"position:relative!important;","\n "),r=function(t){var e,i,n;if("grid"===t.layout){var a=(null===(e=t.gridLayoutOptions)||void 0===e?void 0:e.cols)||1,o=(null===(i=t.gridLayoutOptions)||void 0===i?void 0:i.rows)||1,r=(null===(n=t.gridLayoutOptions)||void 0===n?void 0:n.gap)||[0,0];return[t.width*a+r[0]*a,t.height*o+r[1]*o]}return[t.width,t.height]}(this.options),i.style.cssText="\n display:block!important;visibility:visible!important;pointer-events:none;top:0;bottom:0;left:0;right:0;transform:none!important;scale:none!important;\n position:".concat("root"===n?"fixed":"absolute","!important;-webkit-print-color-adjust:exact!important;width:100%!important;height:100%!important;\n z-index:").concat(this.options.zIndex,"!important;background-image:url(").concat(e,")!important;background-repeat:").concat(this.options.backgroundRepeat,"!important;\n background-size:").concat(r[0],"px ").concat(r[1],"px!important;background-position:").concat(this.options.backgroundPosition,";\n ").concat(function(t,e){if(!t)return"";var i=6*Math.random()+2,n=2*Math.random()+2;switch(e){case"repeat":return"animation: 200s linear 0s infinite alternate watermark !important;";case"repeat-x":return"animation: ".concat(i,"s linear 0s infinite alternate watermark-vertical !important;'");case"repeat-y":return"animation: ".concat(n,"s linear 0s infinite alternate watermark-horizontal !important;'");case"no-repeat":return"animation: ".concat(i,"s linear 0s infinite alternate watermark-horizontal, ").concat(n,"s linear 0s infinite alternate watermark-vertical !important;");default:return""}}(this.options.movable,this.options.backgroundRepeat),"\n "),this.watermarkDom.appendChild(i),this.parentElement.appendChild(this.watermarkDom),this.options.mutationObserve)try{this.bindMutationObserver()}catch(t){null===(u=(h=this.options).onObserveError)||void 0===u||u.call(h)}return t&&(null===(v=(p=this.options).onSuccess)||void 0===v||v.call(p)),[3,4];case 3:return this.isCreating=!1,[7];case 4:return[2]}})})},t.prototype.destroy=function(){this.remove(),this.watermarkDom=void 0},t.prototype.check=function(){return n(this,void 0,void 0,function(){return a(this,function(t){return[2,this.parentElement.contains(this.watermarkDom)]})})},t.prototype.remove=function(){var t,e,i,n,a,o,r,s;null===(e=(t=this.options).onBeforeDestroy)||void 0===e||e.call(t),null===(i=this.observer)||void 0===i||i.disconnect(),null===(n=this.parentObserver)||void 0===n||n.disconnect(),null===(o=null===(a=this.watermarkDom)||void 0===a?void 0:a.parentNode)||void 0===o||o.removeChild(this.watermarkDom),null===(s=(r=this.options).onDestroyed)||void 0===s||s.call(r)},t.prototype.initConfigData=function(t,e){var n=this;void 0===e&&(e="overwrite"),"append"===e?Object.keys(t).forEach(function(e){n.props&&(n.props[e]=t[e])}):this.props=t,this.options=i(i({},p),this.props),this.changeParentElement(this.options.parent),this.watermarkCanvas=new m(this.props,this.options)},t.prototype.changeParentElement=function(t){if("string"==typeof t){var e=document.querySelector(t);e&&(this.parentElement=e)}else this.parentElement=t;this.parentElement||console.error("[WatermarkJsPlus]: please pass a valid parent element.")},t.prototype.validateUnique=function(){var t=!0;return Array.from(this.parentElement.childNodes).forEach(function(e){t&&Object.hasOwnProperty.call(e,"__WATERMARK__")&&(t=!1)}),t},t.prototype.validateContent=function(){switch(this.options.contentType){case"image":return Object.hasOwnProperty.call(this.options,"image");case"multi-line-text":case"rich-text":case"text":return this.options.content.length>0}},t.prototype.checkParentElementType=function(){return["html","body"].includes(this.parentElement.tagName.toLocaleLowerCase())?"root":"custom"},t.prototype.recreateOnMutation=function(){return n(this,void 0,void 0,function(){var t,e;return a(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),this.remove(),[4,this.create()];case 1:return i.sent(),[3,3];case 2:return i.sent(),null===(e=(t=this.options).onObserveError)||void 0===e||e.call(t),[3,3];case 3:return[2]}})})},t.prototype.bindMutationObserver=function(){var t=this;this.watermarkDom&&(this.observer=new MutationObserver(function(e){e.length>0&&t.recreateOnMutation()}),this.observer.observe(this.watermarkDom,{attributes:!0,attributeFilter:["style","class","hidden","id"],childList:!0,subtree:!0,characterData:!0}),this.parentObserver=new MutationObserver(function(e){var i=t.watermarkDom;i&&(e.some(function(t){return Array.from(t.removedNodes).includes(i)})&&t.recreateOnMutation())}),this.parentObserver.observe(this.parentElement,{childList:!0}))},t}(),w=function(t){function s(e){void 0===e&&(e={});return t.call(this,i(i({},e),{globalAlpha:.005,mode:"blind"}))||this}return function(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}(s,t),s.prototype.changeOptions=function(){return n(this,arguments,void 0,function(t,e,i){return void 0===t&&(t={}),void 0===e&&(e="overwrite"),void 0===i&&(i=!0),a(this,function(n){switch(n.label){case 0:return t.globalAlpha=.005,t.mode="blind",this.initConfigData(t,e),v(this.options.monitorProtection),i?(this.remove(),[4,this.create()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},s.decode=function(t){var e=t.url,i=void 0===e?"":e,n=t.fillColor,a=void 0===n?"#000":n,s=t.compositeOperation,l=void 0===s?"color-burn":s,d=t.mode,c=void 0===d?"canvas":d,h=t.compositeTimes,u=void 0===h?3:h,p=t.onSuccess;if(i&&"canvas"===c){var v=new Image;v.src=i,v.addEventListener("load",function(){var t=v.width,e=v.height,i=m.createCanvas(t,e),n=i.getContext("2d");if(!n)throw new Error("get context error");n.drawImage(v,0,0,t,e),function(t){var e=t.ctx,i=t.width,n=t.height,a=t.fillColor,o=t.compositeOperation,r=t.compositeTimes;if(r>0){e.globalCompositeOperation,e.globalCompositeOperation=o,e.globalCompositeOperation,e.fillStyle=a;for(var s=0;s<r;s++)e.fillRect(0,0,i,n)}}({ctx:n,width:t,height:e,fillColor:a,compositeOperation:l,compositeTimes:u});var s=o(i);r(p)&&(null==p||p(s))})}},s}(f),x=function(){function t(t){var e,n;void 0===t&&(t={}),this.drew=!1,this.props=t,this.options=i(i({},p),t),this.props.crossOrigin&&(null===(e=this.props.dom)||void 0===e||e.setAttribute("crossOrigin","anonymous")),this.watermarkCanvas=new m(this.props,this.options),this.originalSrc=null===(n=this.props.dom)||void 0===n?void 0:n.src,this.backgroundImage=this.getBackgroundImage()}return t.prototype.create=function(){return n(this,void 0,void 0,function(){var t,e,n,r,s;return a(this,function(a){switch(a.label){case 0:return this.drew?[2]:[4,null===(t=this.watermarkCanvas)||void 0===t?void 0:t.draw()];case 1:return a.sent(),this.options.layout="grid",this.options.gridLayoutOptions=i(i({},this.options.gridLayoutOptions),{width:null===(e=this.backgroundImage)||void 0===e?void 0:e.width,height:null===(n=this.backgroundImage)||void 0===n?void 0:n.height,backgroundImage:this.backgroundImage}),this.layoutCanvas=g(this.options,null===(r=this.watermarkCanvas)||void 0===r?void 0:r.getCanvas()),this.options.dom.src=o(this.layoutCanvas),null===(s=this.watermarkCanvas)||void 0===s||s.clear(),this.drew=!0,[2]}})})},t.prototype.destroy=function(){this.options.dom.src=this.originalSrc,this.drew=!1},t.prototype.getBackgroundImage=function(){if(this.options.dom)return this.options.dom},t}();return t.BlindWatermark=w,t.ImageWatermark=x,t.Watermark=f,t}({});
package/dist/index.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * watermark-js-plus v1.6.4
2
+ * watermark-js-plus v1.6.6
3
3
  * (c) 2022-2024 Michael Sun
4
4
  * Released under the MIT License.
5
5
  */
@@ -1013,17 +1013,18 @@
1013
1013
  return [2 /*return*/];
1014
1014
  }
1015
1015
  this.isCreating = true;
1016
+ _h.label = 1;
1017
+ case 1:
1018
+ _h.trys.push([1, , 3, 4]);
1016
1019
  if (!this.validateUnique()) {
1017
- this.isCreating = false;
1018
1020
  return [2 /*return*/];
1019
1021
  }
1020
1022
  if (!this.validateContent()) {
1021
- this.isCreating = false;
1022
1023
  return [2 /*return*/];
1023
1024
  }
1024
1025
  firstDraw = isUndefined(this.watermarkDom);
1025
1026
  return [4 /*yield*/, ((_a = this.watermarkCanvas) === null || _a === void 0 ? void 0 : _a.draw())];
1026
- case 1:
1027
+ case 2:
1027
1028
  _h.sent();
1028
1029
  this.layoutCanvas = renderLayout(this.options, (_b = this.watermarkCanvas) === null || _b === void 0 ? void 0 : _b.getCanvas());
1029
1030
  image = convertImage(this.layoutCanvas);
@@ -1033,22 +1034,25 @@
1033
1034
  this.watermarkDom.__WATERMARK__ = 'watermark';
1034
1035
  this.watermarkDom.__WATERMARK__INSTANCE__ = this;
1035
1036
  parentElementType = this.checkParentElementType();
1036
- this.watermarkDom.style.cssText = "\n z-index:".concat(this.options.zIndex, "!important;display:block!important;visibility:visible!important;transform:none!important;scale:none!important;\n ").concat(parentElementType === 'custom' ? 'top:0!important;bottom:0!important;left:0!important;right:0!important;height:100%!important;pointer-events:none!important;position:absolute!important;' : 'position:relative!important;', "\n ");
1037
+ this.watermarkDom.style.cssText = "\n z-index:".concat(this.options.zIndex, "!important;display:block!important;visibility:visible!important;transform:none!important;scale:none!important;\n ").concat(parentElementType === 'custom' ? 'top:0!important;bottom:0!important;left:0!important;right:0!important;height:100%!important;pointer-events:none!important;position:absolute!important;' : 'position:relative!important;', "\n ");
1037
1038
  backgroundSize = generateBackgroundSize(this.options);
1038
- watermarkInnerDom.style.cssText = "\n display:block!important;visibility:visible!important;pointer-events:none;top:0;bottom:0;left:0;right:0;transform:none!important;scale:none!important;\n position:".concat(parentElementType === 'root' ? 'fixed' : 'absolute', "!important;-webkit-print-color-adjust:exact!important;width:100%!important;height:100%!important;\n z-index:").concat(this.options.zIndex, "!important;background-image:url(").concat(image, ")!important;background-repeat:").concat(this.options.backgroundRepeat, "!important;\n background-size:").concat(backgroundSize[0], "px ").concat(backgroundSize[1], "px!important;background-position:").concat(this.options.backgroundPosition, ";\n ").concat(generateAnimationStyle(this.options.movable, this.options.backgroundRepeat), "\n ");
1039
+ watermarkInnerDom.style.cssText = "\n display:block!important;visibility:visible!important;pointer-events:none;top:0;bottom:0;left:0;right:0;transform:none!important;scale:none!important;\n position:".concat(parentElementType === 'root' ? 'fixed' : 'absolute', "!important;-webkit-print-color-adjust:exact!important;width:100%!important;height:100%!important;\n z-index:").concat(this.options.zIndex, "!important;background-image:url(").concat(image, ")!important;background-repeat:").concat(this.options.backgroundRepeat, "!important;\n background-size:").concat(backgroundSize[0], "px ").concat(backgroundSize[1], "px!important;background-position:").concat(this.options.backgroundPosition, ";\n ").concat(generateAnimationStyle(this.options.movable, this.options.backgroundRepeat), "\n ");
1039
1040
  this.watermarkDom.appendChild(watermarkInnerDom);
1040
1041
  this.parentElement.appendChild(this.watermarkDom);
1041
1042
  if (this.options.mutationObserve) {
1042
1043
  try {
1043
- this.bindMutationObserve();
1044
+ this.bindMutationObserver();
1044
1045
  }
1045
1046
  catch (_j) {
1046
1047
  (_e = (_d = this.options).onObserveError) === null || _e === void 0 ? void 0 : _e.call(_d);
1047
1048
  }
1048
1049
  }
1049
1050
  firstDraw && ((_g = (_f = this.options).onSuccess) === null || _g === void 0 ? void 0 : _g.call(_f));
1051
+ return [3 /*break*/, 4];
1052
+ case 3:
1050
1053
  this.isCreating = false;
1051
- return [2 /*return*/];
1054
+ return [7 /*endfinally*/];
1055
+ case 4: return [2 /*return*/];
1052
1056
  }
1053
1057
  });
1054
1058
  });
@@ -1071,7 +1075,7 @@
1071
1075
  var _a, _b, _c, _d, _e, _f, _g, _h;
1072
1076
  (_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
1073
1077
  (_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
1074
- (_d = this.parentObserve) === null || _d === void 0 ? void 0 : _d.disconnect();
1078
+ (_d = this.parentObserver) === null || _d === void 0 ? void 0 : _d.disconnect();
1075
1079
  (_f = (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.parentNode) === null || _f === void 0 ? void 0 : _f.removeChild(this.watermarkDom);
1076
1080
  (_h = (_g = this.options).onDestroyed) === null || _h === void 0 ? void 0 : _h.call(_g);
1077
1081
  };
@@ -1131,62 +1135,76 @@
1131
1135
  }
1132
1136
  return 'custom';
1133
1137
  };
1134
- Watermark.prototype.bindMutationObserve = function () {
1135
- var _this = this;
1136
- if (!this.watermarkDom) {
1137
- return;
1138
- }
1139
- this.observer = new MutationObserver(function (mutationsList) { return __awaiter(_this, void 0, void 0, function () {
1140
- return __generator(this, function (_a) {
1141
- switch (_a.label) {
1138
+ Watermark.prototype.recreateOnMutation = function () {
1139
+ return __awaiter(this, void 0, void 0, function () {
1140
+ var _b, _c;
1141
+ return __generator(this, function (_d) {
1142
+ switch (_d.label) {
1142
1143
  case 0:
1143
- if (!(mutationsList.length > 0)) return [3 /*break*/, 2];
1144
+ _d.trys.push([0, 2, , 3]);
1144
1145
  this.remove();
1145
1146
  return [4 /*yield*/, this.create()];
1146
1147
  case 1:
1147
- _a.sent();
1148
- _a.label = 2;
1149
- case 2: return [2 /*return*/];
1148
+ _d.sent();
1149
+ return [3 /*break*/, 3];
1150
+ case 2:
1151
+ _d.sent();
1152
+ (_c = (_b = this.options).onObserveError) === null || _c === void 0 ? void 0 : _c.call(_b);
1153
+ return [3 /*break*/, 3];
1154
+ case 3: return [2 /*return*/];
1150
1155
  }
1151
1156
  });
1152
- }); });
1157
+ });
1158
+ };
1159
+ Watermark.prototype.bindMutationObserver = function () {
1160
+ var _this = this;
1161
+ if (!this.watermarkDom) {
1162
+ return;
1163
+ }
1164
+ this.observer = new MutationObserver(function (mutationsList) {
1165
+ if (mutationsList.length > 0) {
1166
+ void _this.recreateOnMutation();
1167
+ }
1168
+ });
1153
1169
  this.observer.observe(this.watermarkDom, {
1154
1170
  attributes: true, // 属性的变动
1171
+ attributeFilter: ['style', 'class', 'hidden', 'id'], // 仅监听会影响水印展示或标识的属性
1155
1172
  childList: true, // 子节点的变动(指新增,删除或者更改)
1156
1173
  subtree: true, // 布尔值,表示是否将该观察器应用于该节点的所有后代节点。
1157
1174
  characterData: true, // 节点内容或节点文本的变动。
1158
1175
  });
1159
- this.parentObserve = new MutationObserver(function (mutationsList) { return __awaiter(_this, void 0, void 0, function () {
1160
- var _i, mutationsList_1, item, watermarkRemoved;
1161
- return __generator(this, function (_a) {
1162
- switch (_a.label) {
1163
- case 0:
1164
- _i = 0, mutationsList_1 = mutationsList;
1165
- _a.label = 1;
1166
- case 1:
1167
- if (!(_i < mutationsList_1.length)) return [3 /*break*/, 4];
1168
- item = mutationsList_1[_i];
1169
- watermarkRemoved = Array.from(item.removedNodes).includes(this.watermarkDom);
1170
- if (!watermarkRemoved) return [3 /*break*/, 3];
1171
- this.remove();
1172
- return [4 /*yield*/, this.create()];
1173
- case 2:
1174
- _a.sent();
1175
- _a.label = 3;
1176
- case 3:
1177
- _i++;
1178
- return [3 /*break*/, 1];
1179
- case 4: return [2 /*return*/];
1180
- }
1181
- });
1182
- }); });
1183
- this.parentObserve.observe(this.parentElement, {
1176
+ this.parentObserver = new MutationObserver(function (mutationsList) {
1177
+ var watermarkDom = _this.watermarkDom;
1178
+ if (!watermarkDom) {
1179
+ return;
1180
+ }
1181
+ var watermarkRemoved = mutationsList.some(function (item) { return Array.from(item.removedNodes).includes(watermarkDom); });
1182
+ if (watermarkRemoved) {
1183
+ void _this.recreateOnMutation();
1184
+ }
1185
+ });
1186
+ this.parentObserver.observe(this.parentElement, {
1184
1187
  childList: true, // 子节点的变动(指新增,删除或者更改)
1185
1188
  });
1186
1189
  };
1187
1190
  return Watermark;
1188
1191
  }());
1189
1192
 
1193
+ var blindDecodeFallback;
1194
+ var applyBlindDecodeComposite = function (_a) {
1195
+ var ctx = _a.ctx, width = _a.width, height = _a.height, fillColor = _a.fillColor, compositeOperation = _a.compositeOperation, compositeTimes = _a.compositeTimes;
1196
+ if (!(compositeTimes > 0)) {
1197
+ return;
1198
+ }
1199
+ ctx.globalCompositeOperation;
1200
+ ctx.globalCompositeOperation = compositeOperation;
1201
+ if (ctx.globalCompositeOperation !== compositeOperation && blindDecodeFallback) ;
1202
+ ctx.fillStyle = fillColor;
1203
+ for (var i = 0; i < compositeTimes; i++) {
1204
+ ctx.fillRect(0, 0, width, height);
1205
+ }
1206
+ };
1207
+
1190
1208
  /**
1191
1209
  * BlindWatermark class
1192
1210
  */
@@ -1247,11 +1265,14 @@
1247
1265
  throw new Error('get context error');
1248
1266
  }
1249
1267
  ctx.drawImage(img_1, 0, 0, width, height);
1250
- ctx.globalCompositeOperation = compositeOperation;
1251
- ctx.fillStyle = fillColor;
1252
- for (var i = 0; i < compositeTimes; i++) {
1253
- ctx.fillRect(0, 0, width, height);
1254
- }
1268
+ applyBlindDecodeComposite({
1269
+ ctx: ctx,
1270
+ width: width,
1271
+ height: height,
1272
+ fillColor: fillColor,
1273
+ compositeOperation: compositeOperation,
1274
+ compositeTimes: compositeTimes,
1275
+ });
1255
1276
  var resultImage = convertImage(canvas);
1256
1277
  if (isFunction(onSuccess)) {
1257
1278
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(resultImage);