lean-qr
Version:
minimal QR code generation
2 lines (1 loc) • 1.06 kB
JavaScript
const e=e=>{const t=new Error(`lean-qr error ${e}`);throw t.code=e,t},t=["minCorrectionLevel","maxCorrectionLevel","minVersion","maxVersion","mask","trailer","modes"],r=["on","off","pad","padX","padY","width","height","scale"],n=e=>{try{return e()}catch(e){console.warn(e.message)}},s=(e,t)=>Object.fromEntries(t.map(t=>[t,e[t]]).filter(([e,t])=>void 0!==t)),i="image-rendering:pixelated",o={props:["content",...t,...r],expose:[]},h=({h}=e(6),a=e(7),d={})=>({name:"LeanQRCanvas",...o,computed:{qr(){return n(()=>a(this.content,{...d,...s(this,t)}))},d(){return[this.qr,{...d,...s(this,r)}]}},mounted(){this.$watch("d",([e,t])=>{this.$refs.o.hidden=!e,e?.toCanvas(this.$refs.o,t)},{immediate:!0,flush:"post"})},render:()=>h("canvas",{ref:"o",style:i})}),a=({h}=e(6),a=e(7),d=e(8),m={})=>({name:"LeanQRSvg",...o,computed:{qr(){return n(()=>a(this.content,{...m,...s(this,t)}))},u(){return this.qr&&n(()=>d(this.qr,{...m,...s(this,r)}))}},render(){return this.u?h("img",{src:this.u,style:i}):null}});export{h as makeVueCanvasComponent,a as makeVueSvgComponent};