From 6a0e60bc6715eb3e0b7840d3ba24c604ae132a03 Mon Sep 17 00:00:00 2001 From: PASSER-BY Date: Fri, 31 May 2024 00:13:00 +0800 Subject: [PATCH] =?UTF-8?q?updated=20=E6=B7=BB=E5=8A=A0=E5=BD=A9=E8=9B=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/widget-qrcode.min.js | 2 +- index.html | 55 ++++++++++++++++++++++++++++++++++- src/module/method/DrawUtil.js | 9 ++++-- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/dist/widget-qrcode.min.js b/dist/widget-qrcode.min.js index 1f7c803..1ce65f0 100644 --- a/dist/widget-qrcode.min.js +++ b/dist/widget-qrcode.min.js @@ -10,4 +10,4 @@ * * Created on: 2024-05-26 */ -!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&n)>>>18,r[1]=128|(258048&n)>>>12,r[2]=128|(4032&n)>>>6,r[3]=128|63&n):n>2048?(r[0]=224|(61440&n)>>>12,r[1]=128|(4032&n)>>>6,r[2]=128|63&n):n>128?(r[0]=192|(1984&n)>>>6,r[1]=128|63&n):r[0]=n,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 B:return t*o%2+t*o%3==0;case L:return(t*o%2+t*o%3)%2==0;case A:return(t*o%3+(t+o)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}},getErrorCorrectPolynomial:function(e){for(var t=new k([1],0),o=0;o5&&(o+=3+a-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,n=0;return e>=2&&e<5&&o>=2&&o<5?n=1:e<7&&o<7?n=2:e>=r-5&&e=2&o<5?n=1:e>=r-7&&e=0&o<7?n=2:e>=2&&e<5&&o>=r-5&o=0&&e<7&&o>=r-7&o=a||l>=a||(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"),n=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),n.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,n){var a,i;switch(r){case 0:a=t*n,i=o*n,e.lineTo(a,i);break;case 1:a=t*n+n,i=o*n,e.lineTo(a,i);break;case 2:a=t*n+n,i=o*n+n,e.lineTo(a,i);break;case 3:a=t*n,i=o*n+n,e.lineTo(a,i)}},drawRoundBrick:function(t,o,r,n){var a,i,l=n/2;switch(r){case 0:a=t*n+l,i=o*n+l,e.arc(a,i,l,Math.PI,1.5*Math.PI,!1);break;case 1:a=t*n+n-l,i=o*n+l,e.arc(a,i,l,1.5*Math.PI,2*Math.PI,!1);break;case 2:a=t*n+n-l,i=o*n+n-l,e.arc(a,i,l,0,Math.PI/2,!1);break;case 3:a=t*n+l,i=o*n+n-l,e.arc(a,i,l,Math.PI/2,Math.PI,!1)}},fillRound:function(t,o,r,n){var a,i,l=n/2;switch(e.beginPath(),r){case 0:a=t*n+l,i=o*n+l,e.arc(a,i,l,Math.PI,1.5*Math.PI,!1),a=t*n,i=o*n;break;case 1:a=t*n+n-l,i=o*n+l,e.arc(a,i,l,1.5*Math.PI,2*Math.PI,!1),a=t*n+n,i=o*n;break;case 2:a=t*n+n-l,i=o*n+n-l,e.arc(a,i,l,0,Math.PI/2,!1),a=t*n+n,i=o*n+n;break;case 3:a=t*n+l,i=o*n+n-l,e.arc(a,i,l,Math.PI/2,Math.PI,!1),a=t*n,i=o*n+n}e.lineTo(a,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,n=(e.canvas.height-o)/2;e.drawImage(t,r,n,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 n=0;n>o&1);this.modules[Math.floor(o/3)][o%3+this.moduleCount-8-3]=r}for(var n=0;n<18;n++){var a=!e&&1==(t>>n&1);this.modules[n%3+this.moduleCount-8-3][Math.floor(n/3)]=a}},setupTypeInfo:function(e,t){for(var o=this.errorCorrectLevel<<3|t,r=D.getBCHTypeInfo(o),n=0;n<15;n++){var a=!e&&1==(r>>n&1);n<6?this.modules[n][8]=a:n<8?this.modules[n+1][8]=a:this.modules[this.moduleCount-15+n][8]=a}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,n=7,a=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;a>>n&1)),D.getMask(t,r,i-l)&&(g=!g),this.modules[r][i-l]=g,-1==--n&&(a++,n=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=w.getRSBlocks(e,t),n=new b,a=0;a8*l)throw new Error("code length overflow. ("+n.getLengthInBits()+">"+8*l+")");for(n.getLengthInBits()+4<=8*l&&n.put(0,4);n.getLengthInBits()%8!=0;)n.putBit(!1);for(;!(n.getLengthInBits()>=8*l||(n.put(E.PAD0,8),n.getLengthInBits()>=8*l));)n.put(E.PAD1,8);return E.createBytes(n,r)},E.createBytes=function(e,t){for(var o=0,r=0,n=0,a=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=n;!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=n;!o.backgroundColor&&t.backgroundImage&&(v=g.getImageBrush(t.backgroundImage)),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=n;!o.backgroundColor&&t.backgroundImage&&(v=g.getImageBrush(t.backgroundImage)),e.save(),e.fillStyle=v,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i+a/2,l+a/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"),n=n.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):n;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&&n(o.prototype,r),i&&n(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&n)>>>18,r[1]=128|(258048&n)>>>12,r[2]=128|(4032&n)>>>6,r[3]=128|63&n):n>2048?(r[0]=224|(61440&n)>>>12,r[1]=128|(4032&n)>>>6,r[2]=128|63&n):n>128?(r[0]=192|(1984&n)>>>6,r[1]=128|63&n):r[0]=n,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 B:return t*o%2+t*o%3==0;case L:return(t*o%2+t*o%3)%2==0;case A:return(t*o%3+(t+o)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}},getErrorCorrectPolynomial:function(e){for(var t=new k([1],0),o=0;o5&&(o+=3+a-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.width||r.height?(t[e[0]]=r,o()):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,n=0;return e>=2&&e<5&&o>=2&&o<5?n=1:e<7&&o<7?n=2:e>=r-5&&e=2&o<5?n=1:e>=r-7&&e=0&o<7?n=2:e>=2&&e<5&&o>=r-5&o=0&&e<7&&o>=r-7&o=a||l>=a||(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"),n=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),n.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,n){var a,i;switch(r){case 0:a=t*n,i=o*n,e.lineTo(a,i);break;case 1:a=t*n+n,i=o*n,e.lineTo(a,i);break;case 2:a=t*n+n,i=o*n+n,e.lineTo(a,i);break;case 3:a=t*n,i=o*n+n,e.lineTo(a,i)}},drawRoundBrick:function(t,o,r,n){var a,i,l=n/2;switch(r){case 0:a=t*n+l,i=o*n+l,e.arc(a,i,l,Math.PI,1.5*Math.PI,!1);break;case 1:a=t*n+n-l,i=o*n+l,e.arc(a,i,l,1.5*Math.PI,2*Math.PI,!1);break;case 2:a=t*n+n-l,i=o*n+n-l,e.arc(a,i,l,0,Math.PI/2,!1);break;case 3:a=t*n+l,i=o*n+n-l,e.arc(a,i,l,Math.PI/2,Math.PI,!1)}},fillRound:function(t,o,r,n){var a,i,l=n/2;switch(e.beginPath(),r){case 0:a=t*n+l,i=o*n+l,e.arc(a,i,l,Math.PI,1.5*Math.PI,!1),a=t*n,i=o*n;break;case 1:a=t*n+n-l,i=o*n+l,e.arc(a,i,l,1.5*Math.PI,2*Math.PI,!1),a=t*n+n,i=o*n;break;case 2:a=t*n+n-l,i=o*n+n-l,e.arc(a,i,l,0,Math.PI/2,!1),a=t*n+n,i=o*n+n;break;case 3:a=t*n+l,i=o*n+n-l,e.arc(a,i,l,Math.PI/2,Math.PI,!1),a=t*n,i=o*n+n}e.lineTo(a,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,n=(e.canvas.height-o)/2;e.drawImage(t,r,n,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 n=0;n>o&1);this.modules[Math.floor(o/3)][o%3+this.moduleCount-8-3]=r}for(var n=0;n<18;n++){var a=!e&&1==(t>>n&1);this.modules[n%3+this.moduleCount-8-3][Math.floor(n/3)]=a}},setupTypeInfo:function(e,t){for(var o=this.errorCorrectLevel<<3|t,r=D.getBCHTypeInfo(o),n=0;n<15;n++){var a=!e&&1==(r>>n&1);n<6?this.modules[n][8]=a:n<8?this.modules[n+1][8]=a:this.modules[this.moduleCount-15+n][8]=a}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,n=7,a=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;a>>n&1)),D.getMask(t,r,i-l)&&(g=!g),this.modules[r][i-l]=g,-1==--n&&(a++,n=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=w.getRSBlocks(e,t),n=new b,a=0;a8*l)throw new Error("code length overflow. ("+n.getLengthInBits()+">"+8*l+")");for(n.getLengthInBits()+4<=8*l&&n.put(0,4);n.getLengthInBits()%8!=0;)n.putBit(!1);for(;!(n.getLengthInBits()>=8*l||(n.put(E.PAD0,8),n.getLengthInBits()>=8*l));)n.put(E.PAD1,8);return E.createBytes(n,r)},E.createBytes=function(e,t){for(var o=0,r=0,n=0,a=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=n;!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=n;!o.backgroundColor&&t.backgroundImage&&(v=g.getImageBrush(t.backgroundImage)),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=n;!o.backgroundColor&&t.backgroundImage&&(v=g.getImageBrush(t.backgroundImage)),e.save(),e.fillStyle=v,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i+a/2,l+a/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"),n=n.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):n;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&&n(o.prototype,r),i&&n(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 2bef9e4..ac9e084 100644 --- a/index.html +++ b/index.html @@ -202,7 +202,7 @@
- + @@ -212,6 +212,59 @@
+
diff --git a/src/module/method/DrawUtil.js b/src/module/method/DrawUtil.js index c7b1135..cdd0583 100644 --- a/src/module/method/DrawUtil.js +++ b/src/module/method/DrawUtil.js @@ -8,10 +8,15 @@ export default function(context,data,options) { return new Promise(function(resolve){ var image = new Image(); image.src = item[1]; - image.onload = function(){ + if(image.width||image.height){ result[item[0]] = image; resolve(); - }; + }else{ + image.onload = function(){ + result[item[0]] = image; + resolve(); + }; + } }); }); return promoses.length?Promise.all(promoses).then(()=>result):Promise.resolve({});