Files
qhmes/web-dist/js/index-DBkAHGH_.js
2026-06-16 18:19:57 +08:00

2 lines
3.2 KiB
Java

var B=Object.defineProperty;var b=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var R=(e,n,t)=>n in e?B(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,E=(e,n)=>{for(var t in n||(n={}))D.call(n,t)&&R(e,t,n[t]);if(b)for(var t of b(n))W.call(n,t)&&R(e,t,n[t]);return e};var y=(e,n,t)=>new Promise((a,o)=>{var r=i=>{try{c(t.next(i))}catch(f){o(f)}},s=i=>{try{c(t.throw(i))}catch(f){o(f)}},c=i=>i.done?a(i.value):Promise.resolve(i.value).then(r,s);c((t=t.apply(e,n)).next())});import{aQ as M,ag as O,au as P,y as U}from"./index-X7Y8jykP.js";import{b as C}from"./browser-D2DxMZOB.js";import{downloadByUrl as z}from"./download-CygB1orH.js";import{e as H,o as $,h as k,r as Y,u as h,C as j,z as _,y as A,Y as X}from"./vue-vendor-DNhG1Cve.js";const q=({canvas:e,content:n,width:t=0,options:a={}})=>{const o=M(a);return o.errorCorrectionLevel=o.errorCorrectionLevel||V(n),N(n,o).then(r=>(o.scale=t===0?void 0:t/r*4,C.toCanvas(e,n,o)))};function N(e,n){const t=document.createElement("canvas");return C.toCanvas(t,e,n).then(()=>t.width)}function V(e){return e.length>36?"M":e.length>16?"Q":"H"}const F=({canvas:e,logo:n})=>{if(!n)return new Promise(m=>{m(e.toDataURL())});const t=e.width,{logoSize:a=.15,bgColor:o="#ffffff",borderSize:r=.05,crossOrigin:s,borderRadius:c=8,logoRadius:i=0}=n,f=O(n)?n:n.src,l=t*a,u=t*(1-a)/2,g=t*(a+r),w=t*(1-a-r)/2,d=e.getContext("2d");if(!d)return;I(d)(w,w,g,g,c),d.fillStyle=o,d.fill();const p=new Image;(s||i)&&p.setAttribute("crossOrigin",s||"anonymous"),p.src=f;const Q=m=>{d.drawImage(m,u,u,l,l)},T=m=>{const v=document.createElement("canvas");v.width=u+l,v.height=u+l;const L=v.getContext("2d");if(!L||!d||(L.drawImage(m,u,u,l,l),I(d)(u,u,l,l,i),!d))return;const S=d.createPattern(v,"no-repeat");S&&(d.fillStyle=S,d.fill())};return new Promise(m=>{p.onload=()=>{i?T(p):Q(p),m(e.toDataURL())}})};function I(e){return(n,t,a,o,r)=>{const s=Math.min(a,o);return r>s/2&&(r=s/2),e.beginPath(),e.moveTo(n+r,t),e.arcTo(n+a,t,n+a,t+o,r),e.arcTo(n+a,t+o,n,t+o,r),e.arcTo(n,t+o,n,t,r),e.arcTo(n,t,n+a,t,r),e.closePath(),e}}const G=e=>q(e).then(()=>e).then(F),J=H({name:"QrCode",props:{value:{type:[String,Array],default:null},options:{type:Object,default:null},width:{type:Number,default:200},logo:{type:[String,Object],default:""},tag:{type:String,default:"canvas",validator:e=>["canvas","img"].includes(e)}},emits:{done:e=>!!e,error:e=>!!e},setup(e,{emit:n}){const t=Y(null);function a(){return y(this,null,function*(){try{const{tag:r,value:s,options:c={},width:i,logo:f}=e,l=String(s),u=h(t);if(l==null||l===""||!u)return;if(r==="canvas"){const g=yield G({canvas:u,width:i,logo:f,content:l,options:c||{}});n("done",{url:g,ctx:u.getContext("2d")});return}if(r==="img"){const g=yield C.toDataURL(l,E({errorCorrectionLevel:"H",width:i},c));h(t).src=g,n("done",{url:g})}}catch(r){n("error",r)}})}function o(r){let s="";const c=h(t);c instanceof HTMLCanvasElement?s=c.toDataURL():c instanceof HTMLImageElement&&(s=c.src),s&&z({url:s,fileName:r})}return $(a),k(e,()=>{a()},{deep:!0}),{wrapRef:t,download:o}}});function K(e,n,t,a,o,r){return _(),j("div",null,[(_(),A(X(e.tag),{ref:"wrapRef"},null,512))])}const Z=P(J,[["render",K]]),oe=U(Z);export{oe as Q};