"use strict";var EnableEnum,PageInfoEnum;exports.__esModule=!0,exports.PageInfoEnum=exports.HorizontalTypeEnum=exports.EnableEnum=void 0,exports.default=generateWaterMarkV2,exports.EnableEnum=EnableEnum,function(t){t[t.DISABLE=0]="DISABLE",t[t.ENABLE=1]="ENABLE"}(EnableEnum||(exports.EnableEnum=EnableEnum={})),exports.PageInfoEnum=PageInfoEnum,function(t){t.IMSESSIONLIST="imSessionList",t.DOCPREVIEW="docPreview",t.H5PAGEOTHER="h5PageOther",t.MEETINGDETAIL="meetingDetail",t.H5PAGEBASIC="h5PageBasic",t.SELECTIONCOMPONENT="selectionComponent",t.CONTACTLIST="contactList",t.CONTACTDETAIL="contactDetail",t.CHAT="chat",t.SECRETCHAT="secretChat",t.CAMERA="camera"}(PageInfoEnum||(exports.PageInfoEnum=PageInfoEnum={}));var ShowDensityEnum,HorizontalTypeEnum,emptyWatermark="",fontStyleMap={1:"normal",2:"bold",3:"italic"};!function(t){t[t.LOOSE=0]="LOOSE",t[t.NORMAL=1]="NORMAL",t[t.DENSE=2]="DENSE"}(ShowDensityEnum||(ShowDensityEnum={})),exports.HorizontalTypeEnum=HorizontalTypeEnum,function(t){t[t.RIGHT=0]="RIGHT",t[t.LEFT=1]="LEFT"}(HorizontalTypeEnum||(exports.HorizontalTypeEnum=HorizontalTypeEnum={}));var DEFAULT_CANVAS_WIDTH=749,DEFAULT_CANVAS_HEIGHT=326,DEFAULT_TEXT_WIDTH=200,DEFAULT_TEXT_HEIGHT=16,DEFAULT_RATIO=1.3,WaterMark=function(){function t(t){this.options=Object.assign({texts:"",width:50,height:50,tiltAngle:-15,fontColor:"#171A1D",textFont:"PingFangSC-Regular,system-ui,sans-serif",transparency:90,canvas:[],fontSize:13,tWidth:0,tHeight:0,deg:-15},t,{width:t.leftAndRightSpacing,height:t.upAndDownSpacing}),this.options.deg=this.options.tiltAngle*Math.PI/180}var n=t.prototype;return n.init=function(){var t,n,e,o,i,a,l,r,E,u=null;return E=(u=this.createCanvas()).getContext("2d"),u.width=(null===(t=window)||void 0===t||null===(n=t.screen)||void 0===n?void 0:n.width)||(null===(e=document)||void 0===e||null===(o=e.documentElement)||void 0===o?void 0:o.clientWidth)||DEFAULT_CANVAS_WIDTH,u.height=(null===(i=window)||void 0===i||null===(a=i.screen)||void 0===a?void 0:a.height)||(null===(l=document)||void 0===l||null===(r=l.documentElement)||void 0===r?void 0:r.clientHeight)||DEFAULT_CANVAS_HEIGHT,this.calcTextSize(),this.setCanvasStyle(E),this.drawText(E),u.toDataURL("image/png")},n.calcTextSize=function(){var t,n,e=this.options,o="exclusiveDingTalkWaterMarkCustomClass"+100*Math.random(),i=(t='<span id="'+o+'" style="font:'+e.fontSize+"px "+e.textFont+';visibility:hidden;display:inline-block;">'+e.texts+"</span>",(n=document.createElement("div")).innerHTML=t.trim(),n.firstChild);document.body.appendChild(i);var a=document.getElementById(o),l=Math.max(a.clientWidth,e.texts.length*e.fontSize*DEFAULT_RATIO)||DEFAULT_TEXT_WIDTH,r=Math.min(a.clientHeight,e.fontSize*DEFAULT_RATIO)||DEFAULT_TEXT_HEIGHT;e.tWidth=l,e.tHeight=r,document.body.removeChild(i)},n.setCanvasStyle=function(t){var n=this.options,e=n.deg,o=n.fontStyle,i=n.fontSize,a=n.textFont,l=n.fontColor,r=n.transparency;t.rotate(e),t.font=o+" "+i+"px "+a,t.fillStyle=l,t.textAlign="left",t.textBaseline="bottom",t.globalAlpha=(100-r)/100},n.fillContent=function(t,n){for(var e=this.options,o=e.width,i=e.height,a=e.texts,l=e.tWidth,r=e.tHeight,E=0;E<40;E++)for(var u=E*i+r,s=0;s<40;s++){var d=void 0;d=E%2==0?t===HorizontalTypeEnum.RIGHT?(l+o)*s:(l+o)*s+l+o:t===HorizontalTypeEnum.RIGHT?(l+o)*s+o:(l+o)*s+l,n.fillText(a,t===HorizontalTypeEnum.RIGHT?d:-d,u)}},n.drawText=function(t){this.fillContent(HorizontalTypeEnum.RIGHT,t),this.fillContent(HorizontalTypeEnum.LEFT,t)},n.createCanvas=function(){var t=document.createElement("canvas");return this.options.canvas.push(t),t},t}();function drawWatermark(t,n){var e,o,i,a,l,r,E,u;void 0===n&&(n=PageInfoEnum.H5PAGEOTHER);var s=null;try{s=JSON.parse(t)}catch(t){s={}}var d=null===(e=s)||void 0===e||null===(o=e.watermark)||void 0===o?void 0:o.ruleContent,m=null===(i=s)||void 0===i?void 0:i.userInfo;if((null==d?void 0:d.enable)===EnableEnum.DISABLE||(null==d?void 0:d.enable)===EnableEnum.ENABLE&&(null==d||null===(a=d.effectPage)||void 0===a?void 0:a[n])!==EnableEnum.ENABLE)return emptyWatermark;var T,c="";((null==d||null===(l=d.watermarkContent)||void 0===l?void 0:l.enableUsername)===EnableEnum.ENABLE&&(c+=null==m?void 0:m.userName),(null==d||null===(r=d.watermarkContent)||void 0===r?void 0:r.enablePhoneNumber)===EnableEnum.ENABLE&&(c+=" "+(null==m?void 0:m.lastFourPhoneNo)),null!=d&&null!==(E=d.watermarkContent)&&void 0!==E&&E.customCopy)&&(c+=" "+(null==d||null===(T=d.watermarkContent)||void 0===T?void 0:T.customCopy));return c.length?new WaterMark(Object.assign({texts:c,textFont:"PingFangSC-Regular,system-ui,sans-serif"},null==d?void 0:d.watermarkStyle,{fontStyle:fontStyleMap[null==d||null===(u=d.watermarkStyle)||void 0===u?void 0:u.fontStyle]})).init():emptyWatermark}function generateWaterMarkV2(t,n){void 0===n&&(n=PageInfoEnum.H5PAGEOTHER);try{return drawWatermark.call(null,JSON.stringify(t),n)}catch(t){return""}}