var b=(d,p,r)=>new Promise((x,g)=>{var T=s=>{try{t(r.next(s))}catch(a){g(a)}},w=s=>{try{t(r.throw(s))}catch(a){g(a)}},t=s=>s.done?x(s.value):Promise.resolve(s.value).then(T,w);t((r=r.apply(d,p)).next())});import{_ as $,o as v,l as m,d as B,a4 as S,r as k,f as D,n as R,y as U,a as I,t as X,u as y,b3 as Y,e as E,w as W,c as P,H as z,N,__tla as H}from"./index-b5895273.js";let _,q=Promise.all([(()=>{try{return H}catch(d){}})()]).then(()=>b(void 0,null,function*(){const d={props:{width:{type:Number,default:800},height:{type:Number,default:300},lineWidth:{type:Number,default:4},lineColor:{type:String,default:"#000000"},bgColor:{type:String,default:""},isCrop:{type:Boolean,default:!1},isClearBgColor:{type:Boolean,default:!0},format:{type:String,default:"image/png"},quality:{type:Number,default:1}},data(){return{hasDrew:!1,resultImg:"",points:[],canvasTxt:null,startX:0,startY:0,isDrawing:!1,sratio:1}},computed:{ratio(){return this.height/this.width},stageInfo(){return this.$refs.canvas.getBoundingClientRect()},myBg(){return this.bgColor?this.bgColor:"rgba(255, 255, 255, 0)"}},watch:{myBg:function(t){this.$refs.canvas.style.background=t}},beforeMount(){window.addEventListener("resize",this.$_resizeHandler)},beforeDestroy(){window.removeEventListener("resize",this.$_resizeHandler)},mounted(){const t=this.$refs.canvas;t.height=this.height,t.width=this.width,t.style.background=this.myBg,this.$_resizeHandler(),document.onmouseup=()=>{this.isDrawing=!1}},methods:{$_resizeHandler(){const t=this.$refs.canvas;t.style.width=this.width+"px";const s=parseFloat(window.getComputedStyle(t).width);t.style.height=this.ratio*s+"px",this.canvasTxt=t.getContext("2d"),this.canvasTxt.scale(1*this.sratio,1*this.sratio),this.sratio=s/this.width,this.canvasTxt.scale(1/this.sratio,1/this.sratio)},mouseDown(t){t=t||event,t.preventDefault(),this.isDrawing=!0,this.hasDrew=!0;let s={x:t.offsetX,y:t.offsetY};this.drawStart(s)},mouseMove(t){if(t=t||event,t.preventDefault(),this.isDrawing){let s={x:t.offsetX,y:t.offsetY};this.drawMove(s)}},mouseUp(t){t=t||event,t.preventDefault();let s={x:t.offsetX,y:t.offsetY};this.drawEnd(s),this.isDrawing=!1},touchStart(t){if(t=t||event,t.preventDefault(),this.hasDrew=!0,t.touches.length===1){let s={x:t.targetTouches[0].clientX-this.$refs.canvas.getBoundingClientRect().left,y:t.targetTouches[0].clientY-this.$refs.canvas.getBoundingClientRect().top};this.drawStart(s)}},touchMove(t){if(t=t||event,t.preventDefault(),t.touches.length===1){let s={x:t.targetTouches[0].clientX-this.$refs.canvas.getBoundingClientRect().left,y:t.targetTouches[0].clientY-this.$refs.canvas.getBoundingClientRect().top};this.drawMove(s)}},touchEnd(t){if(t=t||event,t.preventDefault(),t.touches.length===1){let s={x:t.targetTouches[0].clientX-this.$refs.canvas.getBoundingClientRect().left,y:t.targetTouches[0].clientY-this.$refs.canvas.getBoundingClientRect().top};this.drawEnd(s)}},drawStart(t){this.startX=t.x,this.startY=t.y,this.canvasTxt.beginPath(),this.canvasTxt.moveTo(this.startX,this.startY),this.canvasTxt.lineTo(t.x,t.y),this.canvasTxt.lineCap="round",this.canvasTxt.lineJoin="round",this.canvasTxt.lineWidth=this.lineWidth*this.sratio,this.canvasTxt.stroke(),this.canvasTxt.closePath(),this.points.push(t)},drawMove(t){this.canvasTxt.beginPath(),this.canvasTxt.moveTo(this.startX,this.startY),this.canvasTxt.lineTo(t.x,t.y),this.canvasTxt.strokeStyle=this.lineColor,this.canvasTxt.lineWidth=this.lineWidth*this.sratio,this.canvasTxt.lineCap="round",this.canvasTxt.lineJoin="round",this.canvasTxt.stroke(),this.canvasTxt.closePath(),this.startY=t.y,this.startX=t.x,this.points.push(t)},drawEnd(t){this.canvasTxt.beginPath(),this.canvasTxt.moveTo(this.startX,this.startY),this.canvasTxt.lineTo(t.x,t.y),this.canvasTxt.lineCap="round",this.canvasTxt.lineJoin="round",this.canvasTxt.stroke(),this.canvasTxt.closePath(),this.points.push(t),this.points.push({x:-1,y:-1})},generate(t){let s=t&&t.format?t.format:this.format,a=t&&t.quality?t.quality:this.quality;return new Promise((h,o)=>{if(!this.hasDrew){o("Warning: Not Signned!");return}var e=this.canvasTxt.getImageData(0,0,this.$refs.canvas.width,this.$refs.canvas.height);this.canvasTxt.globalCompositeOperation="destination-over",this.canvasTxt.fillStyle=this.myBg,this.canvasTxt.fillRect(0,0,this.$refs.canvas.width,this.$refs.canvas.height),this.resultImg=this.$refs.canvas.toDataURL(s,a);var i=this.resultImg;if(this.canvasTxt.clearRect(0,0,this.$refs.canvas.width,this.$refs.canvas.height),this.canvasTxt.putImageData(e,0,0),this.canvasTxt.globalCompositeOperation="source-over",this.isCrop){const l=this.getCropArea(e.data);var n=document.createElement("canvas");const u=n.getContext("2d");n.width=l[2]-l[0],n.height=l[3]-l[1];const c=this.canvasTxt.getImageData(...l);u.globalCompositeOperation="destination-over",u.putImageData(c,0,0),u.fillStyle=this.myBg,u.fillRect(0,0,n.width,n.height),i=n.toDataURL(s,a),n=null}h(i)})},reset(){this.canvasTxt.clearRect(0,0,this.$refs.canvas.width,this.$refs.canvas.height),this.isClearBgColor&&(this.$emit("update:bgColor",""),this.$refs.canvas.style.background="rgba(255, 255, 255, 0)"),this.points=[],this.hasDrew=!1,this.resultImg=""},getCropArea(t){for(var s=this.$refs.canvas.width,a=0,h=this.$refs.canvas.height,o=0,e=0;e0||t[n+1]>0||t[n+2]||t[n+3]>0)&&(o=Math.max(i,o),a=Math.max(e,a),h=Math.min(i,h),s=Math.min(e,s))}return s++,a++,h++,o++,[s,h,a,o]}}};function p(t,s,a,h,o,e){return v(),m("canvas",{ref:"canvas",onMousedown:s[0]||(s[0]=(...i)=>e.mouseDown&&e.mouseDown(...i)),onMousemove:s[1]||(s[1]=(...i)=>e.mouseMove&&e.mouseMove(...i)),onMouseup:s[2]||(s[2]=(...i)=>e.mouseUp&&e.mouseUp(...i)),onTouchstart:s[3]||(s[3]=(...i)=>e.touchStart&&e.touchStart(...i)),onTouchmove:s[4]||(s[4]=(...i)=>e.touchMove&&e.touchMove(...i)),onTouchend:s[5]||(s[5]=(...i)=>e.touchEnd&&e.touchEnd(...i))},null,544)}const r=$(d,[["render",p],["__scopeId","data-v-5c7dd0c2"]]);r.install=function(t){this.installed||(this.installed=!0,t.component("vueEsign",r))};const x=["onClick"],g=["src"],T={key:1},w=B({__name:"Sign",props:["src"],emits:["submit"],setup(t,{emit:s}){const a=t,{t:h}=S(),o=k(),e=D({visible:!1,imgUrl:""}),i=D({lineWidth:6,lineColor:"#000000",bgColor:"",resultImg:"",isCrop:!1});R(()=>{a.src&&(e.imgUrl=a.src)});function n(){e.visible=!0,a.src&&(e.imgUrl=a.src)}function l(){o.value.reset()}function u(){o.value.generate().then(c=>{c&&(s("submit",c),e.imgUrl=c,e.visible=!1)}).catch(c=>{})}return(c,f)=>{const M=U("a-modal");return v(),m(N,null,[I("div",{onClick:Y(n,["stop"]),class:"sign-box"},[e.imgUrl?(v(),m("img",{key:0,class:"imgCanvas",src:e.imgUrl},null,8,g)):(v(),m("span",T,X(y(h)("\u70B9\u51FB\u624B\u5199\u7B7E\u540D")),1))],8,x),E(M,{visible:e.visible,"onUpdate:visible":f[1]||(f[1]=C=>e.visible=C),width:600,title:y(h)("\u7B7E\u540D"),onOk:u,onCancel:l},{default:W(()=>[e.visible?(v(),P(y(r),{key:0,ref_key:"canvas",ref:o,width:800,height:300,isCrop:i.isCrop,lineWidth:i.lineWidth,lineColor:i.lineColor,bgColor:i.bgColor,"onUpdate:bgColor":f[0]||(f[0]=C=>i.bgColor=C)},null,8,["isCrop","lineWidth","lineColor","bgColor"])):z("",!0)]),_:1},8,["visible","title"])],64)}}});_=$(w,[["__scopeId","data-v-3ccf46d3"]])}));export{q as __tla,_ as default};