const e=require("./interface.js"),t=require("./qrcodegen.js");let n=require("vue");var r={L:t.default.QrCode.Ecc.LOW,M:t.default.QrCode.Ecc.MEDIUM,Q:t.default.QrCode.Ecc.QUARTILE,H:t.default.QrCode.Ecc.HIGH},i=128,a=`L`,o=`#FFFFFF`,s=`#000000`,c=!1,l=4,u=0,d=.1;function f(e,t=0){let n=[];return e.forEach((e,r)=>{let i=null;e.forEach((a,o)=>{if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function p(e,t){return e.slice().map((e,n)=>n<t.y||n>=t.y+t.h?e:e.map((e,n)=>n<t.x||n>=t.x+t.w?e:!1))}function m(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*d),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}return{x:l,y:u,h:c,w:s,excavation:f}}function h(e,t){return t==null?e?l:u:Math.floor(t)}var g=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),_=(0,n.defineComponent)({name:`QRCodeCanvas`,inheritAttrs:!1,props:{...e.qrProps(),level:String,bgColor:String,fgColor:String,marginSize:Number},setup(e,{attrs:l,expose:u}){let d=(0,n.computed)(()=>e.imageSettings?.src),_=(0,n.shallowRef)(null),v=(0,n.shallowRef)(null),y=(0,n.shallowRef)(!1);return u({toDataURL:(e,t)=>_.value?.toDataURL(e,t)}),(0,n.watchEffect)(()=>{let{value:n,size:l=i,level:u=a,bgColor:d=o,fgColor:b=s,includeMargin:x=c,marginSize:S,imageSettings:C}=e;if(_.value!=null){let e=_.value,i=e.getContext(`2d`);if(!i)return;let a=t.default.QrCode.encodeText(n,r[u]).getModules(),o=h(x,S),s=a.length+o*2,c=m(a,l,o,C),w=v.value,T=y.value&&c!=null&&w!==null&&w.complete&&w.naturalHeight!==0&&w.naturalWidth!==0;T&&c.excavation!=null&&(a=p(a,c.excavation));let E=window.devicePixelRatio||1;e.height=e.width=l*E;let D=l/s*E;i.scale(D,D),i.fillStyle=d,i.fillRect(0,0,s,s),i.fillStyle=b,g?i.fill(new Path2D(f(a,o))):a.forEach((e,t)=>{e.forEach((e,n)=>{e&&i.fillRect(n+o,t+o,1,1)})}),T&&i.drawImage(w,c.x+o,c.y+o,c.w,c.h)}},{flush:`post`}),(0,n.watch)(d,()=>{y.value=!1}),()=>{let t=e.size??i,r={height:`${t}px`,width:`${t}px`},a=null;return d.value!=null&&(a=(0,n.createVNode)(`img`,{src:d.value,key:d.value,style:{display:`none`},onLoad:()=>{y.value=!0},ref:v},null)),(0,n.createVNode)(n.Fragment,null,[(0,n.createVNode)(`canvas`,{...l,style:[r,l.style],ref:_},null),a])}}}),v=(0,n.defineComponent)({name:`QRCodeSVG`,inheritAttrs:!1,props:{...e.qrProps(),color:String,level:String,bgColor:String,fgColor:String,marginSize:Number,title:String},setup(e){let l=null,u=null,d=null,g=null,_=null,v=null;return(0,n.watchEffect)(()=>{let{value:o,size:s=i,level:y=a,includeMargin:b=c,marginSize:x,imageSettings:S}=e;l=t.default.QrCode.encodeText(o,r[y]).getModules(),u=h(b,x),d=l.length+u*2,g=m(l,s,u,S),S!=null&&g!=null&&(g.excavation!=null&&(l=p(l,g.excavation)),v=(0,n.createVNode)(`image`,{"xlink:href":S.src,height:g.h,width:g.w,x:g.x+u,y:g.y+u,preserveAspectRatio:`none`},null)),_=f(l,u)}),()=>{let t=e.bgColor&&o,r=e.fgColor&&s;return(0,n.createVNode)(`svg`,{height:e.size,width:e.size,viewBox:`0 0 ${d} ${d}`},[!!e.title&&(0,n.createVNode)(`title`,null,[e.title]),(0,n.createVNode)(`path`,{fill:t,d:`M0,0 h${d}v${d}H0z`,"shape-rendering":`crispEdges`},null),(0,n.createVNode)(`path`,{fill:r,d:_,"shape-rendering":`crispEdges`},null),v])}}});exports.QRCodeCanvas=_,exports.QRCodeSVG=v;