import{o as l,c as g,a as f,T as v,r as y,h as d,g as k,w as x,n as E,A as p,l as C,U as B,f as S}from"./index-25eb6331.js";import"./tooltip-4ed993c7.js";/* empty css               */import{E as P}from"./image-viewer-4f89162c.js";import{E as m}from"./request-14d7fed5.js";import{E as R}from"./index-51e1cffc.js";const U={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"},j=f("path",{fill:"currentColor",d:"M5 20h14v-2H5m14-9h-4V3H9v6H5l7 7l7-7Z"},null,-1),A=[j];function F(c,n){return l(),g("svg",U,A)}const H={name:"mdi-download",render:F},I=["aria-busy","onClick","onKeydown"],N=Object.assign({inheritAttrs:!1},{__name:"QrCodePreview",props:{src:{type:String,required:!0},showDownload:{type:Boolean,default:!0},filename:{type:String,default:"qrcode.png"},alt:{type:String,default:""},imgFit:{type:String,default:"contain"}},setup(c){const n=c,h=v(),a=y(!1),b=e=>{(e.key==="Enter"||e.key===" "||e.key==="Spacebar"||e.key==="Space")&&(e.preventDefault(),u())},u=async()=>{if(!(!n.src||a.value)){a.value=!0;try{const e=await w(n.src),t=document.createElement("canvas");t.width=e.naturalWidth||e.width,t.height=e.naturalHeight||e.height;const r=t.getContext("2d");if(!r)throw new Error("Canvas not supported");r.drawImage(e,0,0);const o=await _(t),i=URL.createObjectURL(o),s=document.createElement("a");s.href=i,s.download=n.filename||"qrcode.png",document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i)}catch(e){console.error("Failed to download QR code",e),typeof m<"u"&&m.error("二维码下载失败，请重试")}finally{a.value=!1}}},w=e=>new Promise((t,r)=>{const o=new Image;o.onload=()=>t(o),o.onerror=r,o.src=e}),_=e=>new Promise((t,r)=>{e.toBlob(o=>{o?t(o):r(new Error("Failed to convert canvas to blob"))},"image/png")});return(e,t)=>{const r=P,o=H,i=R;return l(),g("div",B({class:"relative inline-block group"},S(h)),[d(r,{src:n.src,alt:n.alt,fit:n.imgFit,class:"block w-full h-full"},null,8,["src","alt","fit"]),n.showDownload?(l(),k(i,{key:0,content:"下载二维码",placement:"top"},{default:x(()=>[f("span",{class:E(["absolute top-2 right-2 inline-flex items-center justify-center w-8 h-8 rounded-full bg-white/80 backdrop-blur-sm text-blue-400 shadow ring-1 ring-blue-200/60 transition duration-200 opacity-0 scale-90 cursor-pointer group-hover:opacity-100 group-hover:scale-100 group-hover:bg-blue-50 group-hover:text-blue-500 group-hover:ring-blue-200 focus-visible:opacity-100 focus-visible:scale-100 focus-visible:bg-blue-50 focus-visible:text-blue-500 focus-visible:ring-blue-200 group-focus-within:opacity-100 group-focus-within:scale-100",a.value?"pointer-events-none opacity-70":""]),role:"button",tabindex:"0","aria-label":"下载二维码","aria-busy":a.value,onClick:p(u,["stop"]),onKeydown:p(b,["stop"])},[d(o,{class:"text-base"})],42,I)]),_:1})):C("",!0)],16)}}});export{N as _};
