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