export var EnableEnum;!function(t){t[t.DISABLE=0]="DISABLE",t[t.ENABLE=1]="ENABLE"}(EnableEnum||(EnableEnum={}));export var 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||(PageInfoEnum={}));var ShowDensityEnum,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={}));export var HorizontalTypeEnum;!function(t){t[t.RIGHT=0]="RIGHT",t[t.LEFT=1]="LEFT"}(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,i,o,a,l,r,u,E=null;return u=(E=this.createCanvas()).getContext("2d"),E.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===(i=e.documentElement)||void 0===i?void 0:i.clientWidth)||DEFAULT_CANVAS_WIDTH,E.height=(null===(o=window)||void 0===o||null===(a=o.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(u),this.drawText(u),E.toDataURL("image/png")},n.calcTextSize=function(){var t,n,e=this.options,i="exclusiveDingTalkWaterMarkCustomClass"+100*Math.random(),o=(t='<span id="'+i+'" 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(o);var a=document.getElementById(i),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(o)},n.setCanvasStyle=function(t){var n=this.options,e=n.deg,i=n.fontStyle,o=n.fontSize,a=n.textFont,l=n.fontColor,r=n.transparency;t.rotate(e),t.font=i+" "+o+"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,i=e.width,o=e.height,a=e.texts,l=e.tWidth,r=e.tHeight,u=0;u<40;u++)for(var E=u*o+r,d=0;d<40;d++){var s=void 0;s=u%2==0?t===HorizontalTypeEnum.RIGHT?(l+i)*d:(l+i)*d+l+i:t===HorizontalTypeEnum.RIGHT?(l+i)*d+i:(l+i)*d+l,n.fillText(a,t===HorizontalTypeEnum.RIGHT?s:-s,E)}},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,i,o,a,l,r,u,E;void 0===n&&(n=PageInfoEnum.H5PAGEOTHER);var d=null;try{d=JSON.parse(t)}catch(t){d={}}var s=null===(e=d)||void 0===e||null===(i=e.watermark)||void 0===i?void 0:i.ruleContent,m=null===(o=d)||void 0===o?void 0:o.userInfo;if((null==s?void 0:s.enable)===EnableEnum.DISABLE||(null==s?void 0:s.enable)===EnableEnum.ENABLE&&(null==s||null===(a=s.effectPage)||void 0===a?void 0:a[n])!==EnableEnum.ENABLE)return emptyWatermark;var T,c="";((null==s||null===(l=s.watermarkContent)||void 0===l?void 0:l.enableUsername)===EnableEnum.ENABLE&&(c+=null==m?void 0:m.userName),(null==s||null===(r=s.watermarkContent)||void 0===r?void 0:r.enablePhoneNumber)===EnableEnum.ENABLE&&(c+=" "+(null==m?void 0:m.lastFourPhoneNo)),null!=s&&null!==(u=s.watermarkContent)&&void 0!==u&&u.customCopy)&&(c+=" "+(null==s||null===(T=s.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==s?void 0:s.watermarkStyle,{fontStyle:fontStyleMap[null==s||null===(E=s.watermarkStyle)||void 0===E?void 0:E.fontStyle]})).init():emptyWatermark}export default function generateWaterMarkV2(t,n){void 0===n&&(n=PageInfoEnum.H5PAGEOTHER);try{return drawWatermark.call(null,JSON.stringify(t),n)}catch(t){return""}}