diff --git a/dist/widget-qrcode.min.js b/dist/widget-qrcode.min.js index 1575f77..ddf7452 100644 --- a/dist/widget-qrcode.min.js +++ b/dist/widget-qrcode.min.js @@ -10,4 +10,4 @@ * * Created on: 2024-05-28 */ -!function(){"use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=new Array(t);o65536?(r[0]=240|(1835008&a)>>>18,r[1]=128|(258048&a)>>>12,r[2]=128|(4032&a)>>>6,r[3]=128|63&a):a>2048?(r[0]=224|(61440&a)>>>12,r[1]=128|(4032&a)>>>6,r[2]=128|63&a):a>128?(r[0]=192|(1984&a)>>>6,r[1]=128|63&a):r[0]=a,this.parsedData.push(r)}this.parsedData=Array.prototype.concat.apply([],this.parsedData),this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}function b(){this.buffer=[],this.length=0}m.prototype={getLength:function(e){return this.parsedData.length},write:function(e){for(var t=0,o=this.parsedData.length;t>>7-e%8&1)},put:function(e,t){for(var o=0;o>>t-o-1&1))},getLengthInBits:function(){return this.length},putBit:function(e){var t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}};for(var P={glog:function(e){if(e<1)throw new Error("glog("+e+")");return P.LOG_TABLE[e]},gexp:function(e){for(;e<0;)e+=255;for(;e>=256;)e-=255;return P.EXP_TABLE[e]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},y=0;y<8;y++)P.EXP_TABLE[y]=1<=0;)t^=D.G15<=0;)t^=D.G18<>>=1;return t},getPatternPosition:function(e){return D.PATTERN_POSITION_TABLE[e-1]},getMask:function(e,t,o){switch(e){case C:return(t+o)%2==0;case T:return t%2==0;case R:return o%3==0;case S:return(t+o)%3==0;case M:return(Math.floor(t/2)+Math.floor(o/3))%2==0;case L:return t*o%2+t*o%3==0;case A:return(t*o%2+t*o%3)%2==0;case B:return(t*o%3+(t+o)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}},getErrorCorrectPolynomial:function(e){for(var t=new w([1],0),o=0;o5&&(o+=3+n-5)}for(var u=0;uf.length)throw new Error("Too long data");return o}function V(e,t,o){return{imageReady:function(e){var t={},o=Object.entries(e).map((function(e){return new Promise((function(o){var r=new Image;r.src=e[1],r.onload=function(){t[e[0]]=r,o()}}))}));return o.length?Promise.all(o).then((function(){return t})):Promise.resolve({})},getValue:function(e,o){var r;return null==t||null===(r=t[e])||void 0===r?void 0:r[o]},isPositionPoint:function(e,o){if(!t)return!1;var r=t.length,a=0;return e>=2&&e<5&&o>=2&&o<5?a=1:e<7&&o<7?a=2:e>=r-5&&e=2&o<5?a=1:e>=r-7&&e=0&o<7?a=2:e>=2&&e<5&&o>=r-5&o=0&&e<7&&o>=r-7&o=n||l>=n||(t[i][l]=2)},getImageBrush:function(t){var o;if(t.width>e.canvas.width||t.height>e.canvas.height){var r=document.createElement("canvas"),a=r.getContext("2d");t.width>e.canvas.width&&t.height>e.canvas.height?t.width/t.heighte.canvas.width?(r.width=e.canvas.width,r.height=t.height/t.width*e.canvas.width):(r.width=t.width/t.height*e.canvas.height,r.height=e.canvas.height),a.drawImage(t,0,0,r.width,r.height),o=e.createPattern(r,"repeat")}else o=e.createPattern(t,"repeat");return o},drawRightAngle:function(t,o,r,a){var n,i;switch(r){case 0:n=t*a,i=o*a,e.lineTo(n,i);break;case 1:n=t*a+a,i=o*a,e.lineTo(n,i);break;case 2:n=t*a+a,i=o*a+a,e.lineTo(n,i);break;case 3:n=t*a,i=o*a+a,e.lineTo(n,i)}},drawRoundBrick:function(t,o,r,a){var n,i,l=a/2;switch(r){case 0:n=t*a+l,i=o*a+l,e.arc(n,i,l,Math.PI,1.5*Math.PI,!1);break;case 1:n=t*a+a-l,i=o*a+l,e.arc(n,i,l,1.5*Math.PI,2*Math.PI,!1);break;case 2:n=t*a+a-l,i=o*a+a-l,e.arc(n,i,l,0,Math.PI/2,!1);break;case 3:n=t*a+l,i=o*a+a-l,e.arc(n,i,l,Math.PI/2,Math.PI,!1)}},fillRound:function(t,o,r,a){var n,i,l=a/2;switch(e.beginPath(),r){case 0:n=t*a+l,i=o*a+l,e.arc(n,i,l,Math.PI,1.5*Math.PI,!1),n=t*a,i=o*a;break;case 1:n=t*a+a-l,i=o*a+l,e.arc(n,i,l,1.5*Math.PI,2*Math.PI,!1),n=t*a+a,i=o*a;break;case 2:n=t*a+a-l,i=o*a+a-l,e.arc(n,i,l,0,Math.PI/2,!1),n=t*a+a,i=o*a+a;break;case 3:n=t*a+l,i=o*a+a-l,e.arc(n,i,l,Math.PI/2,Math.PI,!1),n=t*a,i=o*a+a}e.lineTo(n,i),e.closePath(),e.fill(),e.stroke()},setText:function(){if(o.text){var t=Math.ceil(e.canvas.height/12.5),r=Math.ceil(e.canvas.height/50);e.textAlign="center",e.textBaseline="middle",e.font="bold ".concat(t,"px 微软雅黑"),e.lineWidth=r,e.strokeStyle=o.textStroke||"#ffffff",e.strokeText(o.text,e.canvas.width/2,e.canvas.height/2),e.fillStyle=o.textColor||"#000000",e.fillText(o.text,e.canvas.width/2,e.canvas.height/2)}},setLogo:function(t){var o=Math.ceil(e.canvas.width/4),r=(e.canvas.width-o)/2,a=(e.canvas.height-o)/2;e.drawImage(t,r,a,o,o)}}}E.prototype={addData:function(e){var t=new m(e);this.dataList.push(t),this.dataCache=null},isDark:function(e,t){if(e<0||this.moduleCount<=e||t<0||this.moduleCount<=t)throw new Error(e+","+t);return this.modules[e][t]},getModuleCount:function(){return this.moduleCount},make:function(){this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(e,t){this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var o=0;o=7&&this.setupTypeNumber(e),null==this.dataCache&&(this.dataCache=E.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,t)},setupPositionProbePattern:function(e,t){for(var o=-1;o<=7;o++)if(!(e+o<=-1||this.moduleCount<=e+o))for(var r=-1;r<=7;r++)t+r<=-1||this.moduleCount<=t+r||(this.modules[e+o][t+r]=0<=o&&o<=6&&(0==r||6==r)||0<=r&&r<=6&&(0==o||6==o)||2<=o&&o<=4&&2<=r&&r<=4)},getBestMaskPattern:function(){for(var e=0,t=0,o=0;o<8;o++){this.makeImpl(!0,o);var r=D.getLostPoint(this);(0==o||e>r)&&(e=r,t=o)}return t},createMovieClip:function(e,t,o){var r=e.createEmptyMovieClip(t,o);this.make();for(var a=0;a>o&1);this.modules[Math.floor(o/3)][o%3+this.moduleCount-8-3]=r}for(var a=0;a<18;a++){var n=!e&&1==(t>>a&1);this.modules[a%3+this.moduleCount-8-3][Math.floor(a/3)]=n}},setupTypeInfo:function(e,t){for(var o=this.errorCorrectLevel<<3|t,r=D.getBCHTypeInfo(o),a=0;a<15;a++){var n=!e&&1==(r>>a&1);a<6?this.modules[a][8]=n:a<8?this.modules[a+1][8]=n:this.modules[this.moduleCount-15+a][8]=n}for(var i=0;i<15;i++){var l=!e&&1==(r>>i&1);i<8?this.modules[8][this.moduleCount-i-1]=l:i<9?this.modules[8][15-i-1+1]=l:this.modules[8][15-i-1]=l}this.modules[this.moduleCount-8][8]=!e},mapData:function(e,t){for(var o=-1,r=this.moduleCount-1,a=7,n=0,i=this.moduleCount-1;i>0;i-=2)for(6==i&&i--;;){for(var l=0;l<2;l++)if(null==this.modules[r][i-l]){var g=!1;n>>a&1)),D.getMask(t,r,i-l)&&(g=!g),this.modules[r][i-l]=g,-1==--a&&(n++,a=7)}if((r+=o)<0||this.moduleCount<=r){r-=o,o=-o;break}}}},E.PAD0=236,E.PAD1=17,E.createData=function(e,t,o){for(var r=k.getRSBlocks(e,t),a=new b,n=0;n8*l)throw new Error("code length overflow. ("+a.getLengthInBits()+">"+8*l+")");for(a.getLengthInBits()+4<=8*l&&a.put(0,4);a.getLengthInBits()%8!=0;)a.putBit(!1);for(;!(a.getLengthInBits()>=8*l||(a.put(E.PAD0,8),a.getLengthInBits()>=8*l));)a.put(E.PAD1,8);return E.createBytes(a,r)},E.createBytes=function(e,t){for(var o=0,r=0,a=0,n=new Array(t.length),i=new Array(t.length),l=0;l=0?h.get(d):0}}for(var v=0,m=0;m1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),h=u.length-1;u.forEach((function(e,t){f.addColorStop(t/h,e)})),s=f}var c=o.innerColor||s,d=o.outerColor||s,v=a;!o.backgroundColor&&t.backgroundImage&&(v=e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height)),e.save(),e.fillStyle=v,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i,l);for(var m=0;m1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),h=u.length-1;u.forEach((function(e,t){f.addColorStop(t/h,e)})),s=f}var c=o.innerColor||s,d=o.outerColor||s,v=a;!o.backgroundColor&&t.backgroundImage&&(v=e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height)),e.save(),e.fillStyle=v,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i,l);for(var m=0;m1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),h=u.length-1;u.forEach((function(e,t){f.addColorStop(t/h,e)})),s=f}var c=o.innerColor||s,d=o.outerColor||s,v=a;!o.backgroundColor&&t.backgroundImage&&(v=e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height)),e.save(),e.fillStyle=v,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i+n/2,l+n/2);for(var m=0;m1){var h=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),c=s.length-1;s.forEach((function(e,t){h.addColorStop(t/c,e)})),f=h}var d=o.innerColor||u,v=o.outerColor||u;t.backgroundImage&&(u=u.replace(/#([0-9a-fA-F]{6}).*/,"#$188"),a=a.replace(/#([0-9a-fA-F]{6}).*/,"#$188"),d=d.replace(/#([0-9a-fA-F]{6}).*/,"#$188"),v=v.replace(/#([0-9a-fA-F]{6}).*/,"#$188"));var m=d||f,b=v||f,P=t.backgroundImage?g.getImageBrush(t.backgroundImage):a;e.save(),e.fillStyle=P,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i,l);for(var y=0;y\n \n ',t.$module=t.shadowRoot.querySelector(".mod-qrcode"),t.$canvas=t.$module.querySelector("canvas"),t.context=t.$canvas.getContext("2d"),t.resize(),"undefined"!=typeof ResizeObserver&&new ResizeObserver((function(){t.resize()})).observe(t)}},{key:"resize",value:function(){var e=this,t=window.getComputedStyle(e);if(t.width&&t.height){var o=Math.max(parseInt(t.width),parseInt(t.height));e.$canvas.width=2*o,e.$canvas.height=2*o,e.drawQRCode()}}},{key:"drawQRCode",value:function(){var e=this,t=e.level;e.logo&&(t="H");var o=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://passer-by.com/",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"H",o=new E(x(e,s[t]),s[t]);return o.addData(e),o.make(),o.modules}(e.value,t);e.context.clearRect(0,0,e.$canvas.width,e.$canvas.height),(_[e.template]||_.default)(e.context,o,{foregroundImage:e.foregroundImage,backgroundImage:e.backgroundImage,foregroundColor:e.foregroundColor,backgroundColor:e.backgroundColor,innerColor:e.innerColor,outerColor:e.outerColor,logo:e.logo,text:e.text,textColor:e.textColor,textStroke:e.textStroke})}}],i=[{key:"observedAttributes",get:function(){return["value","template","level","width","height","logo","text","text-color","text-stroke","foreground-image","background-image","foreground-color","background-color","inner-color","outer-color"]}}],r&&a(o.prototype,r),i&&a(o,i),Object.defineProperty(o,"prototype",{writable:!1}),g}(u(HTMLElement));customElements.get("widget-qrcode")||customElements.define("widget-qrcode",j)}(); +!function(){"use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=new Array(t);o65536?(r[0]=240|(1835008&a)>>>18,r[1]=128|(258048&a)>>>12,r[2]=128|(4032&a)>>>6,r[3]=128|63&a):a>2048?(r[0]=224|(61440&a)>>>12,r[1]=128|(4032&a)>>>6,r[2]=128|63&a):a>128?(r[0]=192|(1984&a)>>>6,r[1]=128|63&a):r[0]=a,this.parsedData.push(r)}this.parsedData=Array.prototype.concat.apply([],this.parsedData),this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}function b(){this.buffer=[],this.length=0}m.prototype={getLength:function(e){return this.parsedData.length},write:function(e){for(var t=0,o=this.parsedData.length;t>>7-e%8&1)},put:function(e,t){for(var o=0;o>>t-o-1&1))},getLengthInBits:function(){return this.length},putBit:function(e){var t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}};for(var P={glog:function(e){if(e<1)throw new Error("glog("+e+")");return P.LOG_TABLE[e]},gexp:function(e){for(;e<0;)e+=255;for(;e>=256;)e-=255;return P.EXP_TABLE[e]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},y=0;y<8;y++)P.EXP_TABLE[y]=1<=0;)t^=D.G15<=0;)t^=D.G18<>>=1;return t},getPatternPosition:function(e){return D.PATTERN_POSITION_TABLE[e-1]},getMask:function(e,t,o){switch(e){case C:return(t+o)%2==0;case T:return t%2==0;case R:return o%3==0;case S:return(t+o)%3==0;case M:return(Math.floor(t/2)+Math.floor(o/3))%2==0;case L:return t*o%2+t*o%3==0;case A:return(t*o%2+t*o%3)%2==0;case B:return(t*o%3+(t+o)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}},getErrorCorrectPolynomial:function(e){for(var t=new w([1],0),o=0;o5&&(o+=3+n-5)}for(var u=0;uf.length)throw new Error("Too long data");return o}function V(e,t,o){return{imageReady:function(e){var t={},o=Object.entries(e).map((function(e){return new Promise((function(o){var r=new Image;r.src=e[1],r.onload=function(){t[e[0]]=r,o()}}))}));return o.length?Promise.all(o).then((function(){return t})):Promise.resolve({})},getValue:function(e,o){var r;return null==t||null===(r=t[e])||void 0===r?void 0:r[o]},isPositionPoint:function(e,o){if(!t)return!1;var r=t.length,a=0;return e>=2&&e<5&&o>=2&&o<5?a=1:e<7&&o<7?a=2:e>=r-5&&e=2&o<5?a=1:e>=r-7&&e=0&o<7?a=2:e>=2&&e<5&&o>=r-5&o=0&&e<7&&o>=r-7&o=n||l>=n||(t[i][l]=2)},getImageBrush:function(t){var o;if(t.width>e.canvas.width||t.height>e.canvas.height){var r=document.createElement("canvas"),a=r.getContext("2d");t.width>e.canvas.width&&t.height>e.canvas.height?t.width/t.heighte.canvas.width?(r.width=e.canvas.width,r.height=t.height/t.width*e.canvas.width):(r.width=t.width/t.height*e.canvas.height,r.height=e.canvas.height),a.drawImage(t,0,0,r.width,r.height),o=e.createPattern(r,"repeat")}else o=e.createPattern(t,"repeat");return o},drawRightAngle:function(t,o,r,a){var n,i;switch(r){case 0:n=t*a,i=o*a,e.lineTo(n,i);break;case 1:n=t*a+a,i=o*a,e.lineTo(n,i);break;case 2:n=t*a+a,i=o*a+a,e.lineTo(n,i);break;case 3:n=t*a,i=o*a+a,e.lineTo(n,i)}},drawRoundBrick:function(t,o,r,a){var n,i,l=a/2;switch(r){case 0:n=t*a+l,i=o*a+l,e.arc(n,i,l,Math.PI,1.5*Math.PI,!1);break;case 1:n=t*a+a-l,i=o*a+l,e.arc(n,i,l,1.5*Math.PI,2*Math.PI,!1);break;case 2:n=t*a+a-l,i=o*a+a-l,e.arc(n,i,l,0,Math.PI/2,!1);break;case 3:n=t*a+l,i=o*a+a-l,e.arc(n,i,l,Math.PI/2,Math.PI,!1)}},fillRound:function(t,o,r,a){var n,i,l=a/2;switch(e.beginPath(),r){case 0:n=t*a+l,i=o*a+l,e.arc(n,i,l,Math.PI,1.5*Math.PI,!1),n=t*a,i=o*a;break;case 1:n=t*a+a-l,i=o*a+l,e.arc(n,i,l,1.5*Math.PI,2*Math.PI,!1),n=t*a+a,i=o*a;break;case 2:n=t*a+a-l,i=o*a+a-l,e.arc(n,i,l,0,Math.PI/2,!1),n=t*a+a,i=o*a+a;break;case 3:n=t*a+l,i=o*a+a-l,e.arc(n,i,l,Math.PI/2,Math.PI,!1),n=t*a,i=o*a+a}e.lineTo(n,i),e.closePath(),e.fill(),e.stroke()},setText:function(){if(o.text){var t=Math.ceil(e.canvas.height/12.5),r=Math.ceil(e.canvas.height/50);e.textAlign="center",e.textBaseline="middle",e.font="bold ".concat(t,"px 微软雅黑"),e.lineWidth=r,e.strokeStyle=o.textStroke||"#ffffff",e.strokeText(o.text,e.canvas.width/2,e.canvas.height/2),e.fillStyle=o.textColor||"#000000",e.fillText(o.text,e.canvas.width/2,e.canvas.height/2)}},setLogo:function(t){var o=Math.ceil(e.canvas.width/4),r=(e.canvas.width-o)/2,a=(e.canvas.height-o)/2;e.drawImage(t,r,a,o,o)}}}E.prototype={addData:function(e){var t=new m(e);this.dataList.push(t),this.dataCache=null},isDark:function(e,t){if(e<0||this.moduleCount<=e||t<0||this.moduleCount<=t)throw new Error(e+","+t);return this.modules[e][t]},getModuleCount:function(){return this.moduleCount},make:function(){this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(e,t){this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var o=0;o=7&&this.setupTypeNumber(e),null==this.dataCache&&(this.dataCache=E.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,t)},setupPositionProbePattern:function(e,t){for(var o=-1;o<=7;o++)if(!(e+o<=-1||this.moduleCount<=e+o))for(var r=-1;r<=7;r++)t+r<=-1||this.moduleCount<=t+r||(this.modules[e+o][t+r]=0<=o&&o<=6&&(0==r||6==r)||0<=r&&r<=6&&(0==o||6==o)||2<=o&&o<=4&&2<=r&&r<=4)},getBestMaskPattern:function(){for(var e=0,t=0,o=0;o<8;o++){this.makeImpl(!0,o);var r=D.getLostPoint(this);(0==o||e>r)&&(e=r,t=o)}return t},createMovieClip:function(e,t,o){var r=e.createEmptyMovieClip(t,o);this.make();for(var a=0;a>o&1);this.modules[Math.floor(o/3)][o%3+this.moduleCount-8-3]=r}for(var a=0;a<18;a++){var n=!e&&1==(t>>a&1);this.modules[a%3+this.moduleCount-8-3][Math.floor(a/3)]=n}},setupTypeInfo:function(e,t){for(var o=this.errorCorrectLevel<<3|t,r=D.getBCHTypeInfo(o),a=0;a<15;a++){var n=!e&&1==(r>>a&1);a<6?this.modules[a][8]=n:a<8?this.modules[a+1][8]=n:this.modules[this.moduleCount-15+a][8]=n}for(var i=0;i<15;i++){var l=!e&&1==(r>>i&1);i<8?this.modules[8][this.moduleCount-i-1]=l:i<9?this.modules[8][15-i-1+1]=l:this.modules[8][15-i-1]=l}this.modules[this.moduleCount-8][8]=!e},mapData:function(e,t){for(var o=-1,r=this.moduleCount-1,a=7,n=0,i=this.moduleCount-1;i>0;i-=2)for(6==i&&i--;;){for(var l=0;l<2;l++)if(null==this.modules[r][i-l]){var g=!1;n>>a&1)),D.getMask(t,r,i-l)&&(g=!g),this.modules[r][i-l]=g,-1==--a&&(n++,a=7)}if((r+=o)<0||this.moduleCount<=r){r-=o,o=-o;break}}}},E.PAD0=236,E.PAD1=17,E.createData=function(e,t,o){for(var r=k.getRSBlocks(e,t),a=new b,n=0;n8*l)throw new Error("code length overflow. ("+a.getLengthInBits()+">"+8*l+")");for(a.getLengthInBits()+4<=8*l&&a.put(0,4);a.getLengthInBits()%8!=0;)a.putBit(!1);for(;!(a.getLengthInBits()>=8*l||(a.put(E.PAD0,8),a.getLengthInBits()>=8*l));)a.put(E.PAD1,8);return E.createBytes(a,r)},E.createBytes=function(e,t){for(var o=0,r=0,a=0,n=new Array(t.length),i=new Array(t.length),l=0;l=0?h.get(d):0}}for(var v=0,m=0;m1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),h=u.length-1;u.forEach((function(e,t){f.addColorStop(t/h,e)})),s=f}var c=o.innerColor||s,d=o.outerColor||s,v=a;!o.backgroundColor&&t.backgroundImage&&(v=e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height)),e.save(),e.fillStyle=v,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i,l);for(var m=0;m1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),h=u.length-1;u.forEach((function(e,t){f.addColorStop(t/h,e)})),s=f}var c=o.innerColor||s,d=o.outerColor||s,v=a;!o.backgroundColor&&t.backgroundImage&&(v=e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height)),e.save(),e.fillStyle=v,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i,l);for(var m=0;m1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),h=u.length-1;u.forEach((function(e,t){f.addColorStop(t/h,e)})),s=f}var c=o.innerColor||s,d=o.outerColor||s,v=a;!o.backgroundColor&&t.backgroundImage&&(v=e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height)),e.save(),e.fillStyle=v,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i+n/2,l+n/2);for(var m=0;m1){var h=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),c=s.length-1;s.forEach((function(e,t){h.addColorStop(t/c,e)})),f=h}var d=o.innerColor||u,v=o.outerColor||u;t.backgroundImage&&(u=u.replace(/#([0-9a-fA-F]{6}).*/,"#$188"),a=a.replace(/#([0-9a-fA-F]{6}).*/,"#$188"),d=d.replace(/#([0-9a-fA-F]{6}).*/,"#$188"),v=v.replace(/#([0-9a-fA-F]{6}).*/,"#$188"));var m=d||f,b=v||f,P=t.backgroundImage?g.getImageBrush(t.backgroundImage):a;e.save(),e.fillStyle=P,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i,l);for(var y=0;y\n \n ',t.$module=t.shadowRoot.querySelector(".mod-qrcode"),t.$canvas=t.$module.querySelector("canvas"),t.context=t.$canvas.getContext("2d"),t.resize(),"undefined"!=typeof ResizeObserver&&new ResizeObserver((function(){t.resize()})).observe(t)}},{key:"resize",value:function(){var e=this,t=window.getComputedStyle(e);if(t.width&&t.height){var o=Math.max(parseInt(t.width),parseInt(t.height));e.$canvas.width=2*o,e.$canvas.height=2*o,e.drawQRCode()}}},{key:"drawQRCode",value:function(){var e=this,t=e.logo?"H":e.level,o=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://passer-by.com/",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"H",o=new E(x(e,s[t]),s[t]);return o.addData(e),o.make(),o.modules}(e.value,t);e.context.clearRect(0,0,e.$canvas.width,e.$canvas.height),(_[e.template]||_.default)(e.context,o,{foregroundImage:e.foregroundImage,backgroundImage:e.backgroundImage,foregroundColor:e.foregroundColor,backgroundColor:e.backgroundColor,innerColor:e.innerColor,outerColor:e.outerColor,logo:e.logo,text:e.text,textColor:e.textColor,textStroke:e.textStroke})}}],i=[{key:"observedAttributes",get:function(){return["value","template","level","width","height","logo","text","text-color","text-stroke","foreground-image","background-image","foreground-color","background-color","inner-color","outer-color"]}}],r&&a(o.prototype,r),i&&a(o,i),Object.defineProperty(o,"prototype",{writable:!1}),g}(u(HTMLElement));customElements.get("widget-qrcode")||customElements.define("widget-qrcode",j)}(); diff --git a/index.html b/index.html index d9b9e3e..e857520 100644 --- a/index.html +++ b/index.html @@ -185,7 +185,7 @@

二维码组件开源算法

样例展示
- + diff --git a/src/widget-qrcode.js b/src/widget-qrcode.js index 2b3973c..f9dac13 100644 --- a/src/widget-qrcode.js +++ b/src/widget-qrcode.js @@ -119,7 +119,7 @@ class WidgetQRCode extends HTMLElement { } drawQRCode(){ let _ = this; - let level =_.logo:'H':_.level; + let level =_.logo?'H':_.level; let data = QRCode(_.value, level); _.context.clearRect(0,0,_.$canvas.width,_.$canvas.height); (Draw[_.template]||Draw['default'])(_.context, data, {