2 lines
3.2 KiB
Java
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,r,t)=>r in e?B(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,E=(e,r)=>{for(var t in r||(r={}))D.call(r,t)&&R(e,t,r[t]);if(b)for(var t of b(r))W.call(r,t)&&R(e,t,r[t]);return e};var _=(e,r,t)=>new Promise((a,o)=>{var n=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(n,s);c((t=t.apply(e,r)).next())});import{i as M,d as O,x as P}from"./index-BI6CMai0.js";import{d as U,f as H,u as h,o as $,w as k,ar as z,as as I,aC as j,aQ as A}from"./vue-vendor-C7Zq48Yl.js";import{b as C}from"./browser-INOPQ3v-.js";import{h as X}from"./antd-vue-vendor-BPnV8VqP.js";import{downloadByUrl as Y}from"./download-UE0L9Rfp.js";const q=({canvas:e,content:r,width:t=0,options:a={}})=>{const o=X(a);return o.errorCorrectionLevel=o.errorCorrectionLevel||V(r),N(r,o).then(n=>(o.scale=t===0?void 0:t/n*4,C.toCanvas(e,r,o)))};function N(e,r){const t=document.createElement("canvas");return C.toCanvas(t,e,r).then(()=>t.width)}function V(e){return e.length>36?"M":e.length>16?"Q":"H"}const F=({canvas:e,logo:r})=>{if(!r)return new Promise(m=>{m(e.toDataURL())});const t=e.width,{logoSize:a=.15,bgColor:o="#ffffff",borderSize:n=.05,crossOrigin:s,borderRadius:c=8,logoRadius:i=0}=r,f=M(r)?r:r.src,l=t*a,u=t*(1-a)/2,g=t*(a+n),w=t*(1-a-n)/2,d=e.getContext("2d");if(!d)return;Q(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 T=m=>{d.drawImage(m,u,u,l,l)},y=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),Q(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?y(p):T(p),m(e.toDataURL())}})};function Q(e){return(r,t,a,o,n)=>{const s=Math.min(a,o);return n>s/2&&(n=s/2),e.beginPath(),e.moveTo(r+n,t),e.arcTo(r+a,t,r+a,t+o,n),e.arcTo(r+a,t+o,r,t+o,n),e.arcTo(r,t+o,r,t,n),e.arcTo(r,t,r+a,t,n),e.closePath(),e}}const G=e=>q(e).then(()=>e).then(F),J=U({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:r}){const t=H(null);function a(){return _(this,null,function*(){try{const{tag:n,value:s,options:c={},width:i,logo:f}=e,l=String(s),u=h(t);if(l==null||l===""||!u)return;if(n==="canvas"){const g=yield G({canvas:u,width:i,logo:f,content:l,options:c||{}});r("done",{url:g,ctx:u.getContext("2d")});return}if(n==="img"){const g=yield C.toDataURL(l,E({errorCorrectionLevel:"H",width:i},c));h(t).src=g,r("done",{url:g})}}catch(n){r("error",n)}})}function o(n){let s="";const c=h(t);c instanceof HTMLCanvasElement?s=c.toDataURL():c instanceof HTMLImageElement&&(s=c.src),s&&Y({url:s,fileName:n})}return $(a),k(e,()=>{a()},{deep:!0}),{wrapRef:t,download:o}}});function K(e,r,t,a,o,n){return I(),z("div",null,[(I(),j(A(e.tag),{ref:"wrapRef"},null,512))])}const Z=O(J,[["render",K]]),ae=P(Z);export{ae as Q};
|