import"./rolldown-runtime-BM3Ffeng.js";import{T as e}from"./element-plus-vendor-BF9PNysW.js";import{A as t,D as n,P as r,Pt as i,Tt as a,W as o,ct as s,et as c,k as l,qt as u,y as d}from"./vue-vendor-DMUmTARL.js";import{qr as f}from"./icons-vendor-Db5MGAkr.js";import{v as p}from"./index-BcZTP2Ia.js";var m=[`aria-busy`],h=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(h){let g=p(),_=h,v=s(),y=a(!1),b=a(!1),x=()=>{_.showDownload&&(b.value=!b.value)},S=async()=>{if(!(!_.src||y.value)){y.value=!0;try{let e=await C(_.src),t=document.createElement(`canvas`);t.width=e.naturalWidth||e.width,t.height=e.naturalHeight||e.height;let n=t.getContext(`2d`);if(!n)throw Error(`Canvas not supported`);n.drawImage(e,0,0);let r=await w(t),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=_.filename||`qrcode.png`,a.click(),URL.revokeObjectURL(i)}catch(e){console.error(`Failed to download QR code`,e),g.error(`二维码下载失败，请重试`)}finally{y.value=!1,b.value=!1,document.activeElement instanceof HTMLElement&&document.activeElement.blur()}}},C=e=>new Promise((t,n)=>{let r=new Image;r.crossOrigin=`anonymous`,r.onload=()=>t(r),r.onerror=n,r.src=e}),w=e=>new Promise((t,n)=>{e.toBlob(e=>{e?t(e):n(Error(`Failed to convert canvas to blob`))},`image/png`)});return(a,s)=>{let p=e,h=f;return c(),t(`div`,o({class:`group relative inline-block overflow-hidden`},i(v),{onClick:x,onMouseleave:s[0]||=e=>b.value=!1}),[r(p,{src:_.src,alt:_.alt,fit:_.imgFit,class:`block h-full w-full`},null,8,[`src`,`alt`,`fit`]),_.showDownload?(c(),t(`div`,{key:0,class:u([`pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-white/40 opacity-0 backdrop-blur-[2px] transition-all duration-300 group-focus-within:opacity-100 group-hover:opacity-100 dark:bg-black/50`,b.value?`!opacity-100`:``])},[n(`button`,{class:u([`pointer-events-auto inline-flex translate-y-1 scale-90 cursor-pointer items-center justify-center gap-1.5 rounded-full bg-white/80 px-3.5 py-1.5 text-sm font-medium text-gray-700 shadow-lg ring-1 ring-black/5 backdrop-blur-md transition-all duration-300 hover:bg-white/90 hover:text-gray-900 hover:shadow-xl focus:outline-none focus-visible:translate-y-0 focus-visible:scale-100 focus-visible:ring-2 focus-visible:ring-blue-500/50 group-focus-within:translate-y-0 group-focus-within:scale-100 group-hover:translate-y-0 group-hover:scale-100 dark:bg-zinc-800/80 dark:text-zinc-200 dark:ring-white/10 dark:hover:bg-zinc-700/90 dark:hover:text-white`,[y.value?`pointer-events-none opacity-70`:``,b.value?`!translate-y-0 !scale-100`:``]]),"aria-busy":y.value,"aria-label":`下载二维码`,onClick:d(S,[`stop`])},[r(h,{class:`text-base`}),s[1]||=n(`span`,null,`下载`,-1)],10,m)],2)):l(``,!0)],16)}}});export{h as t};