function e(e,t){t===void 0&&(t={});var n=t.insertAt;if(!(typeof document>`u`)){var r=document.head||document.getElementsByTagName(`head`)[0],i=document.createElement(`style`);i.type=`text/css`,n===`top`&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}e(`@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 t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)};function n(e,n){if(typeof n!=`function`&&n!==null)throw TypeError(`Class extends value `+String(n)+` is not a constructor or null`);t(e,n);function r(){this.constructor=e}e.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&a[a.length-1])&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]n&&(r.push(i.substring(0,i.length-1)),i=``,o--)}return r.push(i),r},f=function(e,t){return i(void 0,void 0,void 0,function(){var n,r,i,o,s,c,l,d,f;return a(this,function(a){switch(a.label){case 0:return n=u(`svg`,{xmlns:`http://www.w3.org/2000/svg`}),r=document.createElement(`div`),r.setAttribute(`xmlns`,`http://www.w3.org/1999/xhtml`),r.style.cssText=` text-align: center; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font: ${e.font}; color: ${t.fontColor}; `,r.innerHTML=`
${t.content}
`,document.body.appendChild(r),[4,p(r)];case 1:return a.sent(),i=(f=r.querySelector(`.rich-text-content`))==null?void 0:f.getBoundingClientRect(),o=i==null?void 0:i.width,s=i==null?void 0:i.height,document.body.removeChild(r),c=t.richTextWidth||o||t.width,l=t.richTextHeight||s||t.height,n.setAttribute(`width`,c.toString()),n.setAttribute(`height`,l.toString()),d=u(`foreignObject`,{width:c.toString(),height:l.toString()}),d.appendChild(r),n.appendChild(d),[2,{element:n,width:c,height:l}]}})})};function p(e){return i(this,void 0,void 0,function(){var t,n,r,i,o;return a(this,function(s){switch(s.label){case 0:t=e.querySelectorAll(`img`),n=function(e){var t,n,r,i,o;return a(this,function(a){switch(a.label){case 0:if(t=e.getAttribute(`src`),!t)return[3,6];a.label=1;case 1:return a.trys.push([1,5,,6]),[4,fetch(t)];case 2:return n=a.sent(),[4,n.blob()];case 3:return r=a.sent(),[4,new Promise(function(e,t){var n=new FileReader;n.onloadend=function(){return e(n.result)},n.onerror=t,n.readAsDataURL(r)})];case 4:return i=a.sent(),l(i)&&e.setAttribute(`src`,i),[3,6];case 5:return o=a.sent(),console.error(`Error converting ${t} to base64:`,o),[3,6];case 6:return[2]}})},r=0,i=Array.from(t),s.label=1;case 1:return r/g,`<$1$2/>`).replace(/\n/g,``).replace(/\t/g,``).replace(/#/g,`%23`)}`},h=function(e,t){return c(e)?t:e},g=function(e,t,n){t===void 0&&(t=void 0),n===void 0&&(n=void 0);var r=new Image;return r.setAttribute(`crossOrigin`,`anonymous`),!c(t)&&(r.width=t),!c(n)&&(r.height=n),r.src=e,new Promise(function(e){r.onload=function(){e(r)}})},_=function(e,t,n){return Array.from({length:e},function(){return Array(t).fill(n)})},v=function(e,t){if(!e)return``;var n=Math.random()*6+2,r=Math.random()*2+2;switch(t){case`repeat`:return`animation: 200s linear 0s infinite alternate watermark !important;`;case`repeat-x`:return`animation: ${n}s linear 0s infinite alternate watermark-vertical !important;'`;case`repeat-y`:return`animation: ${r}s linear 0s infinite alternate watermark-horizontal !important;'`;case`no-repeat`:return`animation: ${n}s linear 0s infinite alternate watermark-horizontal, ${r}s linear 0s infinite alternate watermark-vertical !important;`;default:return``}},y={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(){}},b=function(e,t,n){var r=e.getContext(`2d`);if(r===null)throw Error(`get context error`);r.font=`${t.fontStyle} ${t.fontVariant} ${t.fontWeight} ${t.fontSize} ${t.fontFamily}`,r.filter=t.filter,r.letterSpacing=t.letterSpacing,r.wordSpacing=t.wordSpacing,t!=null&&t.rotate&&(t.rotate=(360-t.rotate%360)*(Math.PI/180)),c(n.textRowMaxWidth)&&(t.textRowMaxWidth=t.width);var i={image:{rect:{width:t.imageWidth,height:t.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(t.contentType){case`text`:i.textLine.data=[t.content];break;case`multi-line-text`:i.textLine.data=d(r,t.content,t.textRowMaxWidth)}var a=t.width/2,o=t.height/2,s=`middle`,l=`center`;switch(!c(n==null?void 0:n.translateX)&&!c(n==null?void 0:n.translateY)?(a=n==null?void 0:n.translateX,o=n==null?void 0:n.translateY,s=`top`,l=`left`):(i.advancedStyleParams.linear.x0=-t.width/2,i.advancedStyleParams.linear.x1=t.width/2,i.advancedStyleParams.radial.r0=0,i.advancedStyleParams.radial.r1=t.width/2),n.translatePlacement){case`top`:a=t.width/2,o=0,s=`top`,i.advancedStyleParams.linear.x0=-t.width/2,i.advancedStyleParams.linear.x1=t.width/2,i.advancedStyleParams.radial.y0=i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.radial.y1=i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.conic.y=i.textLine.data.length*t.lineHeight/2;break;case`top-start`:a=0,o=0,s=`top`,l=`start`,i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=t.width,i.advancedStyleParams.radial.x0=t.width/2,i.advancedStyleParams.radial.y0=i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.radial.x1=t.width/2,i.advancedStyleParams.radial.y1=i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.conic.x=t.width/2,i.advancedStyleParams.conic.y=i.textLine.data.length*t.lineHeight/2;break;case`top-end`:a=t.width,o=0,s=`top`,l=`end`,i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=-t.width,i.advancedStyleParams.radial.x0=-t.width/2,i.advancedStyleParams.radial.y0=i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.radial.x1=-t.width/2,i.advancedStyleParams.radial.y1=i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.conic.x=-t.width/2,i.advancedStyleParams.conic.y=i.textLine.data.length*t.lineHeight/2;break;case`bottom`:a=t.width/2,o=t.height,s=`bottom`,i.advancedStyleParams.linear.x0=-t.width/2,i.advancedStyleParams.linear.x1=t.width/2,i.advancedStyleParams.radial.y0=-i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.radial.y1=-i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.conic.x=0,i.advancedStyleParams.conic.y=-i.textLine.data.length*t.lineHeight/2;break;case`bottom-start`:a=0,o=t.height,s=`bottom`,l=`start`,i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=t.width,i.advancedStyleParams.radial.x0=t.width/2,i.advancedStyleParams.radial.y0=-i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.radial.x1=t.width/2,i.advancedStyleParams.radial.y1=-i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.conic.x=t.width/2,i.advancedStyleParams.conic.y=-i.textLine.data.length*t.lineHeight/2;break;case`bottom-end`:a=t.width,o=t.height,s=`bottom`,l=`end`,i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=-t.width,i.advancedStyleParams.radial.x0=-t.width/2,i.advancedStyleParams.radial.y0=-i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.radial.x1=-t.width/2,i.advancedStyleParams.radial.y1=-i.textLine.data.length*t.lineHeight/2,i.advancedStyleParams.conic.x=-t.width/2,i.advancedStyleParams.conic.y=-i.textLine.data.length*t.lineHeight/2;break;case`left`:a=0,o=t.height/2,l=`start`,i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=t.width,i.advancedStyleParams.radial.x0=t.width/2,i.advancedStyleParams.radial.x1=t.width/2,i.advancedStyleParams.conic.x=t.width/2,i.advancedStyleParams.conic.y=0;break;case`right`:a=t.width,o=t.height/2,l=`end`,i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=-t.width,i.advancedStyleParams.radial.x0=-t.width/2,i.advancedStyleParams.radial.x1=-t.width/2,i.advancedStyleParams.conic.x=-t.width/2,i.advancedStyleParams.conic.y=0}if(t.translateX=a,t.translateY=o,c(n==null?void 0:n.textBaseline)&&(t.textBaseline=s),c(n==null?void 0:n.textAlign)&&(t.textAlign=l),[`text`,`multi-line-text`].includes(t.contentType))switch(t.textBaseline){case`middle`:i.textLine.yOffsetValue=(i.textLine.data.length-1)*t.lineHeight/2;break;case`bottom`:case`alphabetic`:case`ideographic`:i.textLine.yOffsetValue=(i.textLine.data.length-1)*t.lineHeight+(t.lineHeight-parseInt(t.fontSize))/2;break;case`top`:case`hanging`:i.textLine.yOffsetValue=-t.lineHeight/2+parseInt(t.fontSize)/2}return i},x=(function(e){typeof window>`u`||e&&Object.defineProperty(window,"MutationObserver",{writable:!1,configurable:!1})}),S=function(){function e(t,n){this.props=t,this.options=n,this.canvas=e.createCanvas(this.options.width,this.options.height),this.recommendOptions=b(this.canvas,this.options,this.props)}return e.createCanvas=function(e,t){var n,r=window.devicePixelRatio||1,i=document.createElement(`canvas`);return i.width=e*r,i.height=t*r,i.style.width=`${e}px`,i.style.height=`${t}px`,(n=i.getContext(`2d`))==null||n.setTransform(r,0,0,r,0,0),i},e.clearCanvas=function(e){var t=e.getContext(`2d`);if(t===null)throw Error(`get context error`);t.restore(),t.resetTransform(),t.clearRect(0,0,e.width,e.height);var n=window.devicePixelRatio||1;t.setTransform(n,0,0,n,0,0)},e.prototype.getCanvas=function(){return this.canvas},e.prototype.clear=function(){e.clearCanvas(this.canvas)},e.prototype.draw=function(){var e=this,t=this.canvas.getContext(`2d`);if(t===null)throw Error(`get context error`);return this.options.auxiliaryLine&&(t.beginPath(),t.rect(0,0,this.options.width,this.options.height),t.lineWidth=1,t.strokeStyle=`#000`,t.stroke(),t.closePath(),t.beginPath(),t.rect(this.options.translateX,this.options.translateY,1,1),t.lineWidth=1,t.strokeStyle=`#f00`,t.stroke(),t.closePath()),this.setStyle(t),t.save(),t.translate(this.options.translateX,this.options.translateY),t.rotate(this.options.rotate),new Promise(function(n){switch(e.options.contentType){case`text`:e.drawText(t,n);break;case`image`:e.drawImage(t,n);break;case`multi-line-text`:e.drawMultiLineText(t,n);break;case`rich-text`:e.drawRichText(t,n)}})},e.prototype.setStyle=function(e){var t,n=`fillStyle`;this.options.textType===`stroke`&&(n=`strokeStyle`);var r=this.options.fontColor;if((t=this.options)!=null&&t.advancedStyle)switch(this.options.advancedStyle.type){case`linear`:r=this.createLinearGradient(e);break;case`radial`:r=this.createRadialGradient(e);break;case`conic`:r=this.createConicGradient(e);break;case`pattern`:r=this.createPattern(e)}e[n]&&r&&(e[n]=r),this.options.textAlign&&(e.textAlign=this.options.textAlign),this.options.textBaseline&&(e.textBaseline=this.options.textBaseline),e.globalAlpha=this.options.globalAlpha,this.options.shadowStyle&&(e.shadowBlur=h(this.options.shadowStyle.shadowBlur,0),e.shadowColor=h(this.options.shadowStyle.shadowColor,`#00000000`),e.shadowOffsetX=h(this.options.shadowStyle.shadowOffsetX,0),e.shadowOffsetY=h(this.options.shadowStyle.shadowOffsetY,0)),s(this.options.extraDrawFunc)&&this.options.extraDrawFunc(e)},e.prototype.createLinearGradient=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p,m,g,_=e.createLinearGradient(h((r=(n=(t=this.options.advancedStyle)==null?void 0:t.params)==null?void 0:n.linear)==null?void 0:r.x0,this.recommendOptions.advancedStyleParams.linear.x0),h((o=(a=(i=this.options.advancedStyle)==null?void 0:i.params)==null?void 0:a.linear)==null?void 0:o.y0,0),h((l=(c=(s=this.options.advancedStyle)==null?void 0:s.params)==null?void 0:c.linear)==null?void 0:l.x1,this.recommendOptions.advancedStyleParams.linear.x1),h((f=(d=(u=this.options.advancedStyle)==null?void 0:u.params)==null?void 0:d.linear)==null?void 0:f.y1,0));return(g=(m=(p=this.options)==null?void 0:p.advancedStyle)==null?void 0:m.colorStops)==null||g.forEach(function(e){_.addColorStop(e.offset,e.color)}),_},e.prototype.createConicGradient=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p,m,g,_=e.createConicGradient(h((i=(r=(n=(t=this.options)==null?void 0:t.advancedStyle)==null?void 0:n.params)==null?void 0:r.conic)==null?void 0:i.startAngle,0),h((c=(s=(o=(a=this.options)==null?void 0:a.advancedStyle)==null?void 0:o.params)==null?void 0:s.conic)==null?void 0:c.x,this.recommendOptions.advancedStyleParams.conic.x),h((f=(d=(u=(l=this.options)==null?void 0:l.advancedStyle)==null?void 0:u.params)==null?void 0:d.conic)==null?void 0:f.y,this.recommendOptions.advancedStyleParams.conic.y));return(g=(m=(p=this.options)==null?void 0:p.advancedStyle)==null?void 0:m.colorStops)==null||g.forEach(function(e){_.addColorStop(e.offset,e.color)}),_},e.prototype.createRadialGradient=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p,m,g,_,v,y,b,x,S,C,w,T,E,D,O,k=e.createRadialGradient(h((i=(r=(n=(t=this.options)==null?void 0:t.advancedStyle)==null?void 0:n.params)==null?void 0:r.radial)==null?void 0:i.x0,this.recommendOptions.advancedStyleParams.radial.x0),h((c=(s=(o=(a=this.options)==null?void 0:a.advancedStyle)==null?void 0:o.params)==null?void 0:s.radial)==null?void 0:c.y0,this.recommendOptions.advancedStyleParams.radial.y0),h((f=(d=(u=(l=this.options)==null?void 0:l.advancedStyle)==null?void 0:u.params)==null?void 0:d.radial)==null?void 0:f.r0,this.recommendOptions.advancedStyleParams.radial.r0),h((_=(g=(m=(p=this.options)==null?void 0:p.advancedStyle)==null?void 0:m.params)==null?void 0:g.radial)==null?void 0:_.x1,this.recommendOptions.advancedStyleParams.radial.x1),h((x=(b=(y=(v=this.options)==null?void 0:v.advancedStyle)==null?void 0:y.params)==null?void 0:b.radial)==null?void 0:x.y1,this.recommendOptions.advancedStyleParams.radial.y1),h((T=(w=(C=(S=this.options)==null?void 0:S.advancedStyle)==null?void 0:C.params)==null?void 0:w.radial)==null?void 0:T.r1,this.recommendOptions.advancedStyleParams.radial.r1));return(O=(D=(E=this.options)==null?void 0:E.advancedStyle)==null?void 0:D.colorStops)==null||O.forEach(function(e){k.addColorStop(e.offset,e.color)}),k},e.prototype.createPattern=function(e){var t,n,r,i,a,o,s,c;return e.createPattern((i=(r=(n=(t=this.options)==null?void 0:t.advancedStyle)==null?void 0:n.params)==null?void 0:r.pattern)==null?void 0:i.image,((c=(s=(o=(a=this.options)==null?void 0:a.advancedStyle)==null?void 0:o.params)==null?void 0:s.pattern)==null?void 0:c.repetition)||``)},e.prototype.setText=function(e,t){var n=`fillText`;this.options.textType===`stroke`&&(n=`strokeText`),e[n]&&e[n](t.text,t.x,t.y,t.maxWidth)},e.prototype.drawText=function(e,t){this.setText(e,{text:this.options.content,x:0,y:0-this.recommendOptions.textLine.yOffsetValue,maxWidth:this.options.textRowMaxWidth||this.options.width}),t(e.canvas)},e.prototype.drawImage=function(e,t){var n=this;g(this.options.image).then(function(r){var i=n.getImageRect(r),a=i.width,o=i.height,s=n.getDrawImagePosition(a,o);e.drawImage(r,s.x,s.y,a,o),t(e.canvas)})},e.prototype.drawMultiLineText=function(e,t){var n=this,r=this.recommendOptions.textLine.data,i=this.recommendOptions.textLine.yOffsetValue;r.forEach(function(t,r){n.setText(e,{text:t,x:0,y:n.options.lineHeight*r-i,maxWidth:n.options.textRowMaxWidth||n.options.width})}),t(e.canvas)},e.prototype.drawRichText=function(e,t){return i(this,void 0,void 0,function(){var n,r=this;return a(this,function(i){switch(i.label){case 0:return[4,f(e,this.options)];case 1:return n=i.sent(),g(m(n.element),n.width,n.height).then(function(n){var i=r.getDrawImagePosition(n.width,n.height);e.drawImage(n,i.x,i.y,n.width,n.height),t(e.canvas)}),[2]}})})},e.prototype.getImageRect=function(e){var t={width:this.options.imageWidth||0,height:this.options.imageHeight||0};switch(!0){case t.width!==0&&t.height===0:t.height=t.width*e.height/e.width;break;case t.width===0&&t.height!==0:t.width=t.height*e.width/e.height;break;case t.width===0&&t.height===0:t.width=e.width,t.height=e.height}return t},e.prototype.getDrawImagePosition=function(e,t){var n,r,i={x:-e/2,y:-t/2};switch(this.options.translatePlacement){case`top`:i.x=-e/2,i.y=0;break;case`top-start`:i.x=0,i.y=0;break;case`top-end`:i.x=-e,i.y=0;break;case`bottom`:i.x=-e/2,i.y=-t;break;case`bottom-start`:i.x=0,i.y=-t;break;case`bottom-end`:i.x=-e,i.y=-t;break;case`left`:i.x=0,i.y=-t/2;break;case`right`:i.x=-e,i.y=-t/2}return!c((n=this.props)==null?void 0:n.translateX)&&(i.x=0),!c((r=this.props)==null?void 0:r.translateY)&&(i.y=0),i},e}(),C=function(){function e(e,t){var n,r,i,a;this.options=e,this.partialWidth=this.options.width,this.partialHeight=this.options.height,this.rows=((n=this.options.gridLayoutOptions)==null?void 0:n.rows)||1,this.cols=((r=this.options.gridLayoutOptions)==null?void 0:r.cols)||1,this.matrix=((i=this.options.gridLayoutOptions)==null?void 0:i.matrix)||_(this.rows,this.cols,1),this.gap=((a=this.options.gridLayoutOptions)==null?void 0:a.gap)||[0,0],this.partialCanvas=t}return e.prototype.draw=function(){var e,t,n,r,i,a,o,s,c=S.createCanvas(((e=this.options.gridLayoutOptions)==null?void 0:e.width)||this.partialWidth*this.cols+this.gap[0]*this.cols,((t=this.options.gridLayoutOptions)==null?void 0:t.height)||this.partialHeight*this.rows+this.gap[1]*this.rows),l=c.getContext(`2d`);(n=this.options.gridLayoutOptions)!=null&&n.backgroundImage&&(l==null||l.drawImage((r=this.options.gridLayoutOptions)==null?void 0:r.backgroundImage,0,0,(i=this.options.gridLayoutOptions)==null?void 0:i.width,(a=this.options.gridLayoutOptions)==null?void 0:a.height));for(var u=0;u0}},e.prototype.checkParentElementType=function(){return[`html`,`body`].includes(this.parentElement.tagName.toLocaleLowerCase())?`root`:`custom`},e.prototype.recreateOnMutation=function(){return i(this,void 0,void 0,function(){var e,t;return a(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.remove(),[4,this.create()];case 1:return n.sent(),[3,3];case 2:return n.sent(),(t=(e=this.options).onObserveError)==null||t.call(e),[3,3];case 3:return[2]}})})},e.prototype.bindMutationObserver=function(){var e=this;this.watermarkDom&&(this.observer=new MutationObserver(function(t){t.length>0&&e.recreateOnMutation()}),this.observer.observe(this.watermarkDom,{attributes:!0,attributeFilter:[`style`,`class`,`hidden`,`id`],childList:!0,subtree:!0,characterData:!0}),this.parentObserver=new MutationObserver(function(t){var n=e.watermarkDom;n&&t.some(function(e){return Array.from(e.removedNodes).includes(n)})&&e.recreateOnMutation()}),this.parentObserver.observe(this.parentElement,{childList:!0}))},e}(),D=function(e){var t=e.ctx,n=e.width,r=e.height,i=e.fillColor,a=e.compositeOperation,o=e.compositeTimes;if(o>0){t.globalCompositeOperation,t.globalCompositeOperation=a,t.globalCompositeOperation,t.fillStyle=i;for(var s=0;s