Files
kefu/deploy/knowledge-v2-20260916/payload/admin-web/apps/web-antd/dist/js/index.esm-DUQ5US9x.js
T
2026-09-21 10:34:06 +08:00

20 lines
28 KiB
JavaScript

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;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},r.apply(this,arguments)};function i(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||(n=Promise))(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})}function a(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o=Object.create((typeof Iterator==`function`?Iterator:Object).prototype);return o.next=s(0),o.throw=s(1),o.return=s(2),typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if(a=n.trys,!(a=a.length>0&&a[a.length-1])&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}var o=function(e){return e.toDataURL(`image/png`,1)},s=function(e){return typeof e==`function`},c=function(e){return e===void 0},l=function(e){return typeof e==`string`},u=function(e,t,n){t===void 0&&(t={}),n===void 0&&(n=`http://www.w3.org/2000/svg`);var r=document.createElementNS(n,e);for(var i in t)r.setAttribute(i,t[i]);return r},d=function(e,t,n){for(var r=[],i=``,a=``,o=0,s=t.length;o<s;o++){if(a=t.charAt(o),a===`
`){r.push(i),i=``;continue}i+=a,e.measureText(i).width>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=`<div class='rich-text-content'>${t.content}</div>`,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<i.length?(o=i[r],[5,n(o)]):[3,4];case 2:s.sent(),s.label=3;case 3:return r++,[3,1];case 4:return[2]}})})}var m=function(e){return`data:image/svg+xml;charset=utf-8,${e.outerHTML.replace(/<(img|br|input|hr|embed)(.*?)>/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;u<this.rows;u++)for(var d=0;d<this.cols;d++)(s=(o=this.matrix)==null?void 0:o[u])!=null&&s[d]&&(l==null||l.drawImage(this.partialCanvas,this.partialWidth*d+this.gap[0]*d,this.partialHeight*u+this.gap[1]*u,this.partialWidth,this.partialHeight));return c},e}(),w=function(e,t){switch(e.layout){case`grid`:return new C(e,t).draw();default:return t}},T=function(e){var t,n,r;switch(e.layout){case`grid`:var i=((t=e.gridLayoutOptions)==null?void 0:t.cols)||1,a=((n=e.gridLayoutOptions)==null?void 0:n.rows)||1,o=((r=e.gridLayoutOptions)==null?void 0:r.gap)||[0,0];return[e.width*i+o[0]*i,e.height*a+o[1]*a];default:return[e.width,e.height]}},E=function(){function e(e){e===void 0&&(e={}),this.parentElement=document.body,this.isCreating=!1,this.props=e,this.options=r(r({},y),e),this.changeParentElement(this.options.parent),this.watermarkCanvas=new S(this.props,this.options),x(this.options.monitorProtection)}return e.prototype.changeOptions=function(){return i(this,arguments,void 0,function(e,t,n){return e===void 0&&(e={}),t===void 0&&(t=`overwrite`),n===void 0&&(n=!0),a(this,function(r){switch(r.label){case 0:return this.initConfigData(e,t),x(this.options.monitorProtection),n?(this.remove(),[4,this.create()]):[3,2];case 1:r.sent(),r.label=2;case 2:return[2]}})})},e.prototype.create=function(){return i(this,void 0,void 0,function(){var e,t,n,r,i,s,l,u,d,f,p,m;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()?[2]:(e=c(this.watermarkDom),[4,(s=this.watermarkCanvas)==null?void 0:s.draw()]);case 2:if(a.sent(),this.layoutCanvas=w(this.options,(l=this.watermarkCanvas)==null?void 0:l.getCanvas()),t=o(this.layoutCanvas),(u=this.watermarkCanvas)==null||u.clear(),this.watermarkDom=document.createElement(`div`),n=document.createElement(`div`),this.watermarkDom.__WATERMARK__=`watermark`,this.watermarkDom.__WATERMARK__INSTANCE__=this,r=this.checkParentElementType(),this.watermarkDom.style.cssText=`
z-index:${this.options.zIndex}!important;display:block!important;visibility:visible!important;transform:none!important;scale:none!important;
${r===`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;`}
`,i=T(this.options),n.style.cssText=`
display:block!important;visibility:visible!important;pointer-events:none;top:0;bottom:0;left:0;right:0;transform:none!important;scale:none!important;
position:${r===`root`?`fixed`:`absolute`}!important;-webkit-print-color-adjust:exact!important;width:100%!important;height:100%!important;
z-index:${this.options.zIndex}!important;background-image:url(${t})!important;background-repeat:${this.options.backgroundRepeat}!important;
background-size:${i[0]}px ${i[1]}px!important;background-position:${this.options.backgroundPosition};
${v(this.options.movable,this.options.backgroundRepeat)}
`,this.watermarkDom.appendChild(n),this.parentElement.appendChild(this.watermarkDom),this.options.mutationObserve)try{this.bindMutationObserver()}catch(e){(f=(d=this.options).onObserveError)==null||f.call(d)}return e&&((m=(p=this.options).onSuccess)==null||m.call(p)),[3,4];case 3:return this.isCreating=!1,[7];case 4:return[2]}})})},e.prototype.destroy=function(){this.remove(),this.watermarkDom=void 0},e.prototype.check=function(){return i(this,void 0,void 0,function(){return a(this,function(e){return[2,this.parentElement.contains(this.watermarkDom)]})})},e.prototype.remove=function(){var e,t,n,r,i,a,o,s;(t=(e=this.options).onBeforeDestroy)==null||t.call(e),(n=this.observer)==null||n.disconnect(),(r=this.parentObserver)==null||r.disconnect(),(a=(i=this.watermarkDom)==null?void 0:i.parentNode)==null||a.removeChild(this.watermarkDom),(s=(o=this.options).onDestroyed)==null||s.call(o)},e.prototype.initConfigData=function(e,t){var n=this;t===void 0&&(t=`overwrite`),t===`append`?Object.keys(e).forEach(function(t){n.props&&(n.props[t]=e[t])}):this.props=e,this.options=r(r({},y),this.props),this.changeParentElement(this.options.parent),this.watermarkCanvas=new S(this.props,this.options)},e.prototype.changeParentElement=function(e){if(typeof e==`string`){var t=document.querySelector(e);t&&(this.parentElement=t)}else this.parentElement=e;this.parentElement||console.error(`[WatermarkJsPlus]: please pass a valid parent element.`)},e.prototype.validateUnique=function(){var e=!0;return Array.from(this.parentElement.childNodes).forEach(function(t){e&&Object.hasOwnProperty.call(t,`__WATERMARK__`)&&(e=!1)}),e},e.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}},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<o;s++)t.fillRect(0,0,n,r)}},O=function(e){n(t,e);function t(t){return t===void 0&&(t={}),e.call(this,r(r({},t),{globalAlpha:.005,mode:`blind`}))||this}return t.prototype.changeOptions=function(){return i(this,arguments,void 0,function(e,t,n){return e===void 0&&(e={}),t===void 0&&(t=`overwrite`),n===void 0&&(n=!0),a(this,function(r){switch(r.label){case 0:return e.globalAlpha=.005,e.mode=`blind`,this.initConfigData(e,t),x(this.options.monitorProtection),n?(this.remove(),[4,this.create()]):[3,2];case 1:r.sent(),r.label=2;case 2:return[2]}})})},t.decode=function(e){var t=e.url,n=t===void 0?``:t,r=e.fillColor,i=r===void 0?`#000`:r,a=e.compositeOperation,c=a===void 0?`color-burn`:a,l=e.mode,u=l===void 0?`canvas`:l,d=e.compositeTimes,f=d===void 0?3:d,p=e.onSuccess;if(n&&u===`canvas`){var m=new Image;m.src=n,m.addEventListener(`load`,function(){var e=m.width,t=m.height,n=S.createCanvas(e,t),r=n.getContext(`2d`);if(!r)throw Error(`get context error`);r.drawImage(m,0,0,e,t),D({ctx:r,width:e,height:t,fillColor:i,compositeOperation:c,compositeTimes:f});var a=o(n);s(p)&&(p==null||p(a))})}},t}(E),k=function(){function e(e){e===void 0&&(e={});var t,n;this.drew=!1,this.props=e,this.options=r(r({},y),e),this.props.crossOrigin&&((t=this.props.dom)==null||t.setAttribute(`crossOrigin`,`anonymous`)),this.watermarkCanvas=new S(this.props,this.options),this.originalSrc=(n=this.props.dom)==null?void 0:n.src,this.backgroundImage=this.getBackgroundImage()}return e.prototype.create=function(){return i(this,void 0,void 0,function(){var e,t,n,i,s;return a(this,function(a){switch(a.label){case 0:return this.drew?[2]:[4,(e=this.watermarkCanvas)==null?void 0:e.draw()];case 1:return a.sent(),this.options.layout=`grid`,this.options.gridLayoutOptions=r(r({},this.options.gridLayoutOptions),{width:(t=this.backgroundImage)==null?void 0:t.width,height:(n=this.backgroundImage)==null?void 0:n.height,backgroundImage:this.backgroundImage}),this.layoutCanvas=w(this.options,(i=this.watermarkCanvas)==null?void 0:i.getCanvas()),this.options.dom.src=o(this.layoutCanvas),(s=this.watermarkCanvas)==null||s.clear(),this.drew=!0,[2]}})})},e.prototype.destroy=function(){this.options.dom.src=this.originalSrc,this.drew=!1},e.prototype.getBackgroundImage=function(){if(this.options.dom)return this.options.dom},e}();export{O as BlindWatermark,k as ImageWatermark,E as Watermark};