watermark-js-plus 0.6.0 → 0.8.0
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.
- package/dist/docs/components/config.d.ts +70 -0
- package/dist/{core → src/core}/watermark.d.ts +15 -7
- package/dist/{types → src/types}/index.d.ts +52 -15
- package/dist/{utils → src/utils}/index.d.ts +3 -0
- package/dist/src/utils/initialization.d.ts +49 -0
- package/dist/watermark.esm.js +402 -148
- package/dist/watermark.esm.min.js +1 -0
- package/dist/watermark.umd.js +402 -148
- package/dist/watermark.umd.min.js +1 -1
- package/package.json +21 -20
- /package/dist/{core → src/core}/blind.d.ts +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=function(e,a){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a])},t(e,a)};function e(t,e,a,n){return new(a||(a=Promise))((function(i,o){function r(t){try{l(n.next(t))}catch(t){o(t)}}function d(t){try{l(n.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof a?e:new a((function(t){t(e)}))).then(r,d)}l((n=n.apply(t,e||[])).next())}))}function a(t,e){var a,n,i,o,r={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:d(0),throw:d(1),return:d(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function d(d){return function(l){return function(d){if(a)throw new TypeError("Generator is already executing.");for(;o&&(o=0,d[0]&&(r=0)),r;)try{if(a=1,n&&(i=2&d[0]?n.return:d[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,d[1])).done)return i;switch(n=0,i&&(d=[2&d[0],i.value]),d[0]){case 0:case 1:i=d;break;case 4:return r.label++,{value:d[1],done:!1};case 5:r.label++,n=d[1],d=[0];continue;case 7:d=r.ops.pop(),r.trys.pop();continue;default:if(!(i=r.trys,(i=i.length>0&&i[i.length-1])||6!==d[0]&&2!==d[0])){r=0;continue}if(3===d[0]&&(!i||d[1]>i[0]&&d[1]<i[3])){r.label=d[1];break}if(6===d[0]&&r.label<i[1]){r.label=i[1],i=d;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(d);break}i[2]&&r.ops.pop(),r.trys.pop();continue}d=e.call(t,r)}catch(t){d=[6,t],n=0}finally{a=i=0}if(5&d[0])throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}([d,l])}}}var n=function(t){return t.toDataURL("image/png",1)},i=function(t){return"function"==typeof t},o=function(t){return void 0===t},r=function(t,e,a){void 0===e&&(e={}),void 0===a&&(a="http://www.w3.org/2000/svg");var n=document.createElementNS(a,t);for(var i in e)n.setAttribute(i,e[i]);return n},d=function(t,e){return o(t)?e:t},l=function(t,e,a){void 0===e&&(e=void 0),void 0===a&&(a=void 0);var n=new Image;return n.setAttribute("crossOrigin","Anonymous"),!o(e)&&(n.width=e),!o(a)&&(n.height=a),n.src=t,new Promise((function(t){n.onload=function(){t(n)}}))},s={width:300,height:300,rotate:45,auxiliaryLine:!1,translatePlacement:"middle",contentType:"text",content:"hello watermark-js-plus",textType:"fill",imageWidth:0,imageHeight:0,lineHeight:30,zIndex:1e4,backgroundPosition:"0 0, 0 0",backgroundRepeat:"repeat",fontSize:"20px",fontFamily:"sans-serif",fontStyle:"",fontVariant:"",fontColor:"#000",fontWeight:"normal",filter:"none",globalAlpha:.5,mode:"default",mutationObserve:!0,unique:!0,parent:"body",onSuccess:function(){},onBeforeDestroy:function(){},onDestroyed:function(){}},c=function(t,e,a){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,(null==e?void 0:e.rotate)&&(e.rotate=(360-e.rotate%360)*(Math.PI/180)),o(a.textRowMaxWidth)&&(e.textRowMaxWidth=e.width);var i={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":i.textLine.data=[e.content];break;case"multi-line-text":i.textLine.data=function(t,e,a){for(var n=[],i="",o=0,r=e.length;o<r;o++)i+=e.charAt(o),t.measureText(i).width>a&&(n.push(i.substring(0,i.length-1)),i="",o--);return n.push(i),n}(n,e.content,e.textRowMaxWidth)}var r=e.width/2,d=e.height/2,l="middle",s="center";switch(o(null==a?void 0:a.translateX)||o(null==a?void 0:a.translateY)?(i.advancedStyleParams.linear.x0=-e.width/2,i.advancedStyleParams.linear.x1=e.width/2,i.advancedStyleParams.radial.r0=0,i.advancedStyleParams.radial.r1=e.width/2):(r=null==a?void 0:a.translateX,d=null==a?void 0:a.translateY,l="top",s="left"),a.translatePlacement){case"top":r=e.width/2,d=0,l="top",i.advancedStyleParams.linear.x0=-e.width/2,i.advancedStyleParams.linear.x1=e.width/2,i.advancedStyleParams.radial.y0=i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.radial.y1=i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.conic.y=i.textLine.data.length*e.lineHeight/2;break;case"top-start":r=0,d=0,l="top",s="start",i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=e.width,i.advancedStyleParams.radial.x0=e.width/2,i.advancedStyleParams.radial.y0=i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.radial.x1=e.width/2,i.advancedStyleParams.radial.y1=i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.conic.x=e.width/2,i.advancedStyleParams.conic.y=i.textLine.data.length*e.lineHeight/2;break;case"top-end":r=e.width,d=0,l="top",s="end",i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=-e.width,i.advancedStyleParams.radial.x0=-e.width/2,i.advancedStyleParams.radial.y0=i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.radial.x1=-e.width/2,i.advancedStyleParams.radial.y1=i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.conic.x=-e.width/2,i.advancedStyleParams.conic.y=i.textLine.data.length*e.lineHeight/2;break;case"bottom":r=e.width/2,d=e.height,l="bottom",i.advancedStyleParams.linear.x0=-e.width/2,i.advancedStyleParams.linear.x1=e.width/2,i.advancedStyleParams.radial.y0=-i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.radial.y1=-i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.conic.x=0,i.advancedStyleParams.conic.y=-i.textLine.data.length*e.lineHeight/2;break;case"bottom-start":r=0,d=e.height,l="bottom",s="start",i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=e.width,i.advancedStyleParams.radial.x0=e.width/2,i.advancedStyleParams.radial.y0=-i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.radial.x1=e.width/2,i.advancedStyleParams.radial.y1=-i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.conic.x=e.width/2,i.advancedStyleParams.conic.y=-i.textLine.data.length*e.lineHeight/2;break;case"bottom-end":r=e.width,d=e.height,l="bottom",s="end",i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=-e.width,i.advancedStyleParams.radial.x0=-e.width/2,i.advancedStyleParams.radial.y0=-i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.radial.x1=-e.width/2,i.advancedStyleParams.radial.y1=-i.textLine.data.length*e.lineHeight/2,i.advancedStyleParams.conic.x=-e.width/2,i.advancedStyleParams.conic.y=-i.textLine.data.length*e.lineHeight/2;break;case"left":r=0,d=e.height/2,s="start",i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=e.width,i.advancedStyleParams.radial.x0=e.width/2,i.advancedStyleParams.radial.x1=e.width/2,i.advancedStyleParams.conic.x=e.width/2,i.advancedStyleParams.conic.y=0;break;case"right":r=e.width,d=e.height/2,s="end",i.advancedStyleParams.linear.x0=0,i.advancedStyleParams.linear.x1=-e.width,i.advancedStyleParams.radial.x0=-e.width/2,i.advancedStyleParams.radial.x1=-e.width/2,i.advancedStyleParams.conic.x=-e.width/2,i.advancedStyleParams.conic.y=0}if(e.translateX=r,e.translateY=d,o(null==a?void 0:a.textBaseline)&&(e.textBaseline=l),o(null==a?void 0:a.textAlign)&&(e.textAlign=s),"multi-line-text"===e.contentType)switch(e.textBaseline){case"middle":i.textLine.yOffsetValue=(i.textLine.data.length-1)*e.lineHeight/2;break;case"bottom":case"alphabetic":case"ideographic":i.textLine.yOffsetValue=(i.textLine.data.length-1)*e.lineHeight;break;case"top":case"hanging":i.textLine.yOffsetValue=0}return i},h=function(){function t(e){void 0===e&&(e={}),this.parentElement=document.body,this.props=e,this.options=Object.assign({},s,e),this.changeParentElement(this.options.parent),this.canvas=t.createCanvas(this.options.width,this.options.height),this.recommendOptions=c(this.canvas,this.options,this.props)}return t.createCanvas=function(t,e){var a,n=window.devicePixelRatio||1,i=document.createElement("canvas");return i.width=t*n,i.height=e*n,i.style.width="".concat(t,"px"),i.style.height="".concat(e,"px"),null===(a=i.getContext("2d"))||void 0===a||a.setTransform(n,0,0,n,0,0),i},t.prototype.changeOptions=function(t,e){void 0===t&&(t={}),void 0===e&&(e="overwrite"),this.initConfigData(t,e)},t.prototype.create=function(){var t,i;return e(this,void 0,void 0,(function(){var e,o,r,d;return a(this,(function(a){switch(a.label){case 0:return this.validateUnique()&&this.validateContent()?[4,this.draw()]:[2];case 1:return e=a.sent(),o=n(e),this.clearCanvas(),this.watermarkDom=document.createElement("div"),r=document.createElement("div"),this.watermarkDom.__WATERMARK__="watermark",this.watermarkDom.__WATERMARK__INSTANCE__=this,d=this.checkParentElementType(),this.watermarkDom.style.cssText="\n z-index: ".concat(this.options.zIndex,";\n ").concat("custom"===d?"top: 0;bottom: 0;left: 0;right: 0;height: 100%;pointer-events: none;position: absolute":"position: relative","\n "),r.style.cssText="\n position: ".concat("root"===d?"fixed;":"absolute;","\n z-index: ").concat(this.options.zIndex,";\n pointer-events: none;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n background-image: url(").concat(o,");\n background-repeat: ").concat(this.options.backgroundRepeat,";\n background-size: ").concat(this.options.width,"px ").concat(this.options.height,"px;\n background-position: ").concat(this.options.backgroundPosition,";\n -webkit-print-color-adjust: exact;\n "),this.watermarkDom.append(r),this.parentElement.appendChild(this.watermarkDom),this.options.mutationObserve&&this.bindMutationObserve(),null===(i=(t=this.options).onSuccess)||void 0===i||i.call(t),[2]}}))}))},t.prototype.destroy=function(){var t,e,a,n,i,o,r;null===(e=(t=this.options).onBeforeDestroy)||void 0===e||e.call(t),null===(a=this.observer)||void 0===a||a.disconnect(),null===(n=this.parentObserve)||void 0===n||n.disconnect(),null===(i=this.watermarkDom)||void 0===i||i.remove(),null===(r=(o=this.options).onDestroyed)||void 0===r||r.call(o)},t.prototype.initConfigData=function(e,a){var n=this;void 0===a&&(a="overwrite"),this.props=e,"overwrite"===a?this.options=Object.assign({},s,e):Object.keys(e).forEach((function(t){n.options[t]=e[t]})),this.changeParentElement(this.options.parent),this.canvas=t.createCanvas(this.options.width,this.options.height),this.recommendOptions=c(this.canvas,this.options,this.props)},t.prototype.changeParentElement=function(t){if("string"==typeof t){var e=document.querySelector(t);e&&(this.parentElement=e)}else this.parentElement=t},t.prototype.validateUnique=function(){var t=!0;return this.options.unique&&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}return!1},t.prototype.draw=function(){var t=this,e=this.canvas.getContext("2d");if(null===e)throw new Error("get context error");return this.setStyle(e),e.save(),e.translate(this.options.translateX,this.options.translateY),e.rotate(this.options.rotate),new Promise((function(a){switch(t.options.contentType){case"text":t.drawText(e,a);break;case"image":t.drawImage(e,a);break;case"multi-line-text":t.drawMultiLineText(e,a);break;case"rich-text":t.drawRichText(e,a)}}))},t.prototype.setStyle=function(t){var e,a="fillStyle";"stroke"===this.options.textType&&(a="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[a]&&n&&(t[a]=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=d(this.options.shadowStyle.shadowBlur,0),t.shadowColor=d(this.options.shadowStyle.shadowColor,"#00000000"),t.shadowOffsetX=d(this.options.shadowStyle.shadowOffsetX,0),t.shadowOffsetY=d(this.options.shadowStyle.shadowOffsetY,0)),i(this.options.extraDrawFunc)&&this.options.extraDrawFunc(t)},t.prototype.createLinearGradient=function(t){var e,a,n,i,o,r,l,s,c,h,v,u,p,m,y,g=t.createLinearGradient(d(null===(n=null===(a=null===(e=this.options.advancedStyle)||void 0===e?void 0:e.params)||void 0===a?void 0:a.linear)||void 0===n?void 0:n.x0,this.recommendOptions.advancedStyleParams.linear.x0),d(null===(r=null===(o=null===(i=this.options.advancedStyle)||void 0===i?void 0:i.params)||void 0===o?void 0:o.linear)||void 0===r?void 0:r.y0,0),d(null===(c=null===(s=null===(l=this.options.advancedStyle)||void 0===l?void 0:l.params)||void 0===s?void 0:s.linear)||void 0===c?void 0:c.x1,this.recommendOptions.advancedStyleParams.linear.x1),d(null===(u=null===(v=null===(h=this.options.advancedStyle)||void 0===h?void 0:h.params)||void 0===v?void 0:v.linear)||void 0===u?void 0:u.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,a,n,i,o,r,l,s,c,h,v,u,p,m,y,g=t.createConicGradient(d(null===(i=null===(n=null===(a=null===(e=this.options)||void 0===e?void 0:e.advancedStyle)||void 0===a?void 0:a.params)||void 0===n?void 0:n.conic)||void 0===i?void 0:i.startAngle,0),d(null===(s=null===(l=null===(r=null===(o=this.options)||void 0===o?void 0:o.advancedStyle)||void 0===r?void 0:r.params)||void 0===l?void 0:l.conic)||void 0===s?void 0:s.x,this.recommendOptions.advancedStyleParams.conic.x),d(null===(u=null===(v=null===(h=null===(c=this.options)||void 0===c?void 0:c.advancedStyle)||void 0===h?void 0:h.params)||void 0===v?void 0:v.conic)||void 0===u?void 0:u.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,a,n,i,o,r,l,s,c,h,v,u,p,m,y,g,x,f,w,S,b,P,k,O,L,C,T,E=t.createRadialGradient(d(null===(i=null===(n=null===(a=null===(e=this.options)||void 0===e?void 0:e.advancedStyle)||void 0===a?void 0:a.params)||void 0===n?void 0:n.radial)||void 0===i?void 0:i.x0,this.recommendOptions.advancedStyleParams.radial.x0),d(null===(s=null===(l=null===(r=null===(o=this.options)||void 0===o?void 0:o.advancedStyle)||void 0===r?void 0:r.params)||void 0===l?void 0:l.radial)||void 0===s?void 0:s.y0,this.recommendOptions.advancedStyleParams.radial.y0),d(null===(u=null===(v=null===(h=null===(c=this.options)||void 0===c?void 0:c.advancedStyle)||void 0===h?void 0:h.params)||void 0===v?void 0:v.radial)||void 0===u?void 0:u.r0,this.recommendOptions.advancedStyleParams.radial.r0),d(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),d(null===(S=null===(w=null===(f=null===(x=this.options)||void 0===x?void 0:x.advancedStyle)||void 0===f?void 0:f.params)||void 0===w?void 0:w.radial)||void 0===S?void 0:S.y1,this.recommendOptions.advancedStyleParams.radial.y1),d(null===(O=null===(k=null===(P=null===(b=this.options)||void 0===b?void 0:b.advancedStyle)||void 0===P?void 0:P.params)||void 0===k?void 0:k.radial)||void 0===O?void 0:O.r1,this.recommendOptions.advancedStyleParams.radial.r1));return null===(T=null===(C=null===(L=this.options)||void 0===L?void 0:L.advancedStyle)||void 0===C?void 0:C.colorStops)||void 0===T||T.forEach((function(t){E.addColorStop(t.offset,t.color)})),E},t.prototype.createPattern=function(t){var e,a,n,i,o,r,d,l;return t.createPattern(null===(i=null===(n=null===(a=null===(e=this.options)||void 0===e?void 0:e.advancedStyle)||void 0===a?void 0:a.params)||void 0===n?void 0:n.pattern)||void 0===i?void 0:i.image,(null===(l=null===(d=null===(r=null===(o=this.options)||void 0===o?void 0:o.advancedStyle)||void 0===r?void 0:r.params)||void 0===d?void 0:d.pattern)||void 0===l?void 0:l.repetition)||"")},t.prototype.setText=function(t,e){var a="fillText";"stroke"===this.options.textType&&(a="strokeText"),t[a]&&t[a](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,maxWidth:this.options.textRowMaxWidth||this.options.width}),e(t.canvas)},t.prototype.drawImage=function(t,e){var a=this;l(this.options.image).then((function(n){var i=a.getImageRect(n),o=i.width,r=i.height,d=a.getDrawImagePosition(o,r);t.drawImage(n,d.x,d.y,o,r),e(t.canvas)}))},t.prototype.drawMultiLineText=function(t,e){var a=this,n=this.recommendOptions.textLine.data,i=this.recommendOptions.textLine.yOffsetValue;n.forEach((function(e,n){a.setText(t,{text:e,x:0,y:a.options.lineHeight*n-i})})),e(t.canvas)},t.prototype.drawRichText=function(t,e){var a,n,i=this,o=function(t,e){var a=r("svg",{xmlns:"http://www.w3.org/2000/svg"}),n=document.createElement("div");n.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);var i=n.querySelector(".rich-text-content"),o=i.offsetHeight,d=i.offsetWidth;document.body.removeChild(n);var l=e.richTextWidth||d||e.width,s=e.richTextHeight||o||e.height,c=r("foreignObject",{width:l.toString(),height:s.toString()});return c.appendChild(n),a.appendChild(c),{element:a,width:l,height:s}}(t,this.options);l((a=o.element,n=a.outerHTML.replace(/\n/g,"").replace(/\t/g,"").replace(/#/g,"%23"),"data:image/svg+xml;charset=utf-8,".concat(n)),o.width,o.height).then((function(a){var n=i.getDrawImagePosition(a.width,a.height);t.drawImage(a,n.x,n.y,t.canvas.width,t.canvas.height),e(t.canvas)}))},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 a,n,i={x:-t/2,y:-e/2};switch(this.options.translatePlacement){case"top":i.x=-t/2,i.y=0;break;case"top-start":i.x=0,i.y=0;break;case"top-end":i.x=-t,i.y=0;break;case"bottom":i.x=-t/2,i.y=-e;break;case"bottom-start":i.x=0,i.y=-e;break;case"bottom-end":i.x=-t,i.y=-e;break;case"left":i.x=0,i.y=-e/2;break;case"right":i.x=-t,i.y=-e/2}return!o(null===(a=this.props)||void 0===a?void 0:a.translateX)&&(i.x=0),!o(null===(n=this.props)||void 0===n?void 0:n.translateY)&&(i.y=0),i},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){e.length>0&&(t.destroy(),t.create())})),this.observer.observe(this.watermarkDom,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),this.parentObserve=new MutationObserver((function(e){e.forEach((function(e){var a;(null==e?void 0:e.target)!==t.watermarkDom&&(null===(a=null==e?void 0:e.removedNodes)||void 0===a?void 0:a[0])!==t.watermarkDom||(t.destroy(),t.create())}))})),this.parentObserve.observe(this.parentElement,{attributes:!0,childList:!0,subtree:!0,characterData:!0}))},t.prototype.clearCanvas=function(){var t=this.canvas.getContext("2d");if(null===t)throw new Error("get context error");t.restore(),t.clearRect(0,0,this.canvas.width,this.canvas.height)},t}(),v=function(e){function a(t){return void 0===t&&(t={}),t.globalAlpha=.005,t.mode="blind",e.call(this,t)||this}return function(e,a){if("function"!=typeof a&&null!==a)throw new TypeError("Class extends value "+String(a)+" is not a constructor or null");function n(){this.constructor=e}t(e,a),e.prototype=null===a?Object.create(a):(n.prototype=a.prototype,new n)}(a,e),a.decode=function(t){var e=Object.assign({url:"",fillColor:"#000",compositeOperation:"color-burn",mode:"canvas"},t);if(e.url&&"canvas"===e.mode){var a=new Image;a.src=e.url,a.onload=function(){var t,o=a.width,r=a.height,d=h.createCanvas(o,r),l=d.getContext("2d");if(null===l)throw new Error("get context error");l.drawImage(a,0,0,o,r),l.globalCompositeOperation=e.compositeOperation,l.fillStyle=e.fillColor,l.fillRect(0,0,o,r);var s=n(d);e.onSuccess&&i(e.onSuccess)&&(null===(t=e.onSuccess)||void 0===t||t.call(e,s))}}},a}(h);export{v as BlindWatermark,h as Watermark};
|