diff --git a/dist/widget-qrcode.min.js b/dist/widget-qrcode.min.js index 9f31064..27e8e0a 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 r=0,o=new Array(t);r65536?(o[0]=240|(1835008&a)>>>18,o[1]=128|(258048&a)>>>12,o[2]=128|(4032&a)>>>6,o[3]=128|63&a):a>2048?(o[0]=224|(61440&a)>>>12,o[1]=128|(4032&a)>>>6,o[2]=128|63&a):a>128?(o[0]=192|(1984&a)>>>6,o[1]=128|63&a):o[0]=a,this.parsedData.push(o)}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,r=this.parsedData.length;t>>7-e%8&1)},put:function(e,t){for(var r=0;r>>t-r-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)},I=0;I<8;I++)P.EXP_TABLE[I]=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,r){switch(e){case C:return(t+r)%2==0;case T:return t%2==0;case S:return r%3==0;case R:return(t+r)%3==0;case M:return(Math.floor(t/2)+Math.floor(r/3))%2==0;case B:return t*r%2+t*r%3==0;case A:return(t*r%2+t*r%3)%2==0;case L:return(t*r%3+(t+r)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}},getErrorCorrectPolynomial:function(e){for(var t=new k([1],0),r=0;r5&&(r+=3+n-5)}for(var g=0;gf.length)throw new Error("Too long data");return r}function _(e,t,r){return{imageReady:function(e){var t={},r=Object.entries(e).map((function(e){return new Promise((function(r){var o=new Image;o.src=e[1],o.onload=function(){t[e[0]]=o,r()}}))}));return r.length?Promise.all(r).then((function(){return t})):Promise.resolve({})},getValue:function(e,r){var o;return null==t||null===(o=t[e])||void 0===o?void 0:o[r]},isPositionPoint:function(e,r){if(!t)return!1;var o=t.length,a=0;return e>=2&&e<5&&r>=2&&r<5?a=1:e<7&&r<7?a=2:e>=o-5&&e=2&r<5?a=1:e>=o-7&&e=0&r<7?a=2:e>=2&&e<5&&r>=o-5&r=0&&e<7&&r>=o-7&r=n||l>=n||(t[i][l]=2)},getForegroundImageBrush:function(t){var r;if(t.width>e.canvas.width||t.height>e.canvas.height){var o=document.createElement("canvas"),a=o.getContext("2d");t.width>e.canvas.width?(o.width=e.canvas.width,o.height=t.height/t.width*e.canvas.width):(o.width=t.width/t.height*e.canvas.height,o.height=e.canvas.height),a.drawImage(t,0,0,o.width,o.height),r=e.createPattern(o,"repeat")}else r=e.createPattern(t,"repeat");return r},drawRightAngle:function(t,r,o,a){var n,i;switch(o){case 0:n=t*a,i=r*a,e.lineTo(n,i);break;case 1:n=t*a+a,i=r*a,e.lineTo(n,i);break;case 2:n=t*a+a,i=r*a+a,e.lineTo(n,i);break;case 3:n=t*a,i=r*a+a,e.lineTo(n,i)}},drawRoundBrick:function(t,r,o,a){var n,i,l=a/2;switch(o){case 0:n=t*a+l,i=r*a+l,e.arc(n,i,l,Math.PI,1.5*Math.PI,!1);break;case 1:n=t*a+a-l,i=r*a+l,e.arc(n,i,l,1.5*Math.PI,2*Math.PI,!1);break;case 2:n=t*a+a-l,i=r*a+a-l,e.arc(n,i,l,0,Math.PI/2,!1);break;case 3:n=t*a+l,i=r*a+a-l,e.arc(n,i,l,Math.PI/2,Math.PI,!1)}},fillRound:function(t,r,o,a){var n,i,l=a/2;switch(e.beginPath(),o){case 0:n=t*a+l,i=r*a+l,e.arc(n,i,l,Math.PI,1.5*Math.PI,!1),n=t*a,i=r*a;break;case 1:n=t*a+a-l,i=r*a+l,e.arc(n,i,l,1.5*Math.PI,2*Math.PI,!1),n=t*a+a,i=r*a;break;case 2:n=t*a+a-l,i=r*a+a-l,e.arc(n,i,l,0,Math.PI/2,!1),n=t*a+a,i=r*a+a;break;case 3:n=t*a+l,i=r*a+a-l,e.arc(n,i,l,Math.PI/2,Math.PI,!1),n=t*a,i=r*a+a}e.lineTo(n,i),e.closePath(),e.fill(),e.stroke()}}}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 r=0;r=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 r=-1;r<=7;r++)if(!(e+r<=-1||this.moduleCount<=e+r))for(var o=-1;o<=7;o++)t+o<=-1||this.moduleCount<=t+o||(this.modules[e+r][t+o]=0<=r&&r<=6&&(0==o||6==o)||0<=o&&o<=6&&(0==r||6==r)||2<=r&&r<=4&&2<=o&&o<=4)},getBestMaskPattern:function(){for(var e=0,t=0,r=0;r<8;r++){this.makeImpl(!0,r);var o=D.getLostPoint(this);(0==r||e>o)&&(e=o,t=r)}return t},createMovieClip:function(e,t,r){var o=e.createEmptyMovieClip(t,r);this.make();for(var a=0;a>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=o}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 r=this.errorCorrectLevel<<3|t,o=D.getBCHTypeInfo(r),a=0;a<15;a++){var n=!e&&1==(o>>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==(o>>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 r=-1,o=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[o][i-l]){var u=!1;n>>a&1)),D.getMask(t,o,i-l)&&(u=!u),this.modules[o][i-l]=u,-1==--a&&(n++,a=7)}if((o+=r)<0||this.moduleCount<=o){o-=r,r=-r;break}}}},E.PAD0=236,E.PAD1=17,E.createData=function(e,t,r){for(var o=w.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,o)},E.createBytes=function(e,t){for(var r=0,o=0,a=0,n=new Array(t.length),i=new Array(t.length),l=0;l=0?c.get(d):0}}for(var v=0,m=0;m1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),c=g.length-1;g.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=r.innerColor||s,d=r.outerColor||s;e.save(),!r.backgroundColor&&t.backgroundImage?e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height):(e.fillStyle=a,e.fillRect(0,0,e.canvas.width,e.canvas.height)),e.restore(),e.save(),e.translate(i,l);for(var v=0;v1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),c=g.length-1;g.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=r.innerColor||s,d=r.outerColor||s;e.save(),!r.backgroundColor&&t.backgroundImage?e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height):(e.fillStyle=a,e.fillRect(0,0,e.canvas.width,e.canvas.height)),e.restore(),e.save(),e.translate(i,l);for(var v=0;v1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),c=g.length-1;g.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=r.innerColor||s,d=r.outerColor||s;e.save(),!r.backgroundColor&&t.backgroundImage?e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height):(e.fillStyle=a,e.fillRect(0,0,e.canvas.width,e.canvas.height)),e.restore(),e.save(),e.translate(i+n/2,l+n/2);for(var v=0;v1){var s=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),f=g.length-1;g.forEach((function(e,t){s.addColorStop(t/f,e)})),s}r.innerColor,r.outerColor,e.save(),t.backgroundImage?e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height):(e.fillStyle=a,e.fillRect(0,0,e.canvas.width,e.canvas.height)),e.restore(),e.save(),e.translate(i,l);for(var c=0;c\n \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 r=Math.max(parseInt(t.width),parseInt(t.height));e.$canvas.width=2*r,e.$canvas.height=2*r,e.drawQRCode()}}},{key:"drawQRCode",value:function(){var e=this,t=e.level;e.logo?(t="H",e.$module.querySelector(".logo").style="background: url(".concat(e.logo,") center center/ 25% 25% no-repeat;")):e.$module.querySelector(".logo").style="";var r=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",r=new E(V(e,s[t]),s[t]);return r.addData(e),r.make(),r.modules}(e.value,t);e.context.clearRect(0,0,e.$canvas.width,e.$canvas.height),(O[e.template]||O.default)(e.context,r,{foregroundImage:e.foregroundImage,backgroundImage:e.backgroundImage,foregroundColor:e.foregroundColor,backgroundColor:e.backgroundColor,innerColor:e.innerColor,outerColor:e.outerColor})}}],i=[{key:"observedAttributes",get:function(){return["value","template","level","width","height","logo","foreground-image","background-image","foreground-color","background-color","inner-color","outer-color"]}}],o&&a(r.prototype,o),i&&a(r,i),Object.defineProperty(r,"prototype",{writable:!1}),u}(g(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 r=0,o=new Array(t);r65536?(o[0]=240|(1835008&n)>>>18,o[1]=128|(258048&n)>>>12,o[2]=128|(4032&n)>>>6,o[3]=128|63&n):n>2048?(o[0]=224|(61440&n)>>>12,o[1]=128|(4032&n)>>>6,o[2]=128|63&n):n>128?(o[0]=192|(1984&n)>>>6,o[1]=128|63&n):o[0]=n,this.parsedData.push(o)}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,r=this.parsedData.length;t>>7-e%8&1)},put:function(e,t){for(var r=0;r>>t-r-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)},I=0;I<8;I++)P.EXP_TABLE[I]=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,r){switch(e){case C:return(t+r)%2==0;case T:return t%2==0;case R:return r%3==0;case S:return(t+r)%3==0;case M:return(Math.floor(t/2)+Math.floor(r/3))%2==0;case B:return t*r%2+t*r%3==0;case A:return(t*r%2+t*r%3)%2==0;case L:return(t*r%3+(t+r)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}},getErrorCorrectPolynomial:function(e){for(var t=new k([1],0),r=0;r5&&(r+=3+a-5)}for(var g=0;gf.length)throw new Error("Too long data");return r}function _(e,t,r){return{imageReady:function(e){var t={},r=Object.entries(e).map((function(e){return new Promise((function(r){var o=new Image;o.src=e[1],o.onload=function(){t[e[0]]=o,r()}}))}));return r.length?Promise.all(r).then((function(){return t})):Promise.resolve({})},getValue:function(e,r){var o;return null==t||null===(o=t[e])||void 0===o?void 0:o[r]},isPositionPoint:function(e,r){if(!t)return!1;var o=t.length,n=0;return e>=2&&e<5&&r>=2&&r<5?n=1:e<7&&r<7?n=2:e>=o-5&&e=2&r<5?n=1:e>=o-7&&e=0&r<7?n=2:e>=2&&e<5&&r>=o-5&r=0&&e<7&&r>=o-7&r=a||l>=a||(t[i][l]=2)},getForegroundImageBrush:function(t){var r;if(t.width>e.canvas.width||t.height>e.canvas.height){var o=document.createElement("canvas"),n=o.getContext("2d");t.width>e.canvas.width?(o.width=e.canvas.width,o.height=t.height/t.width*e.canvas.width):(o.width=t.width/t.height*e.canvas.height,o.height=e.canvas.height),n.drawImage(t,0,0,o.width,o.height),r=e.createPattern(o,"repeat")}else r=e.createPattern(t,"repeat");return r},drawRightAngle:function(t,r,o,n){var a,i;switch(o){case 0:a=t*n,i=r*n,e.lineTo(a,i);break;case 1:a=t*n+n,i=r*n,e.lineTo(a,i);break;case 2:a=t*n+n,i=r*n+n,e.lineTo(a,i);break;case 3:a=t*n,i=r*n+n,e.lineTo(a,i)}},drawRoundBrick:function(t,r,o,n){var a,i,l=n/2;switch(o){case 0:a=t*n+l,i=r*n+l,e.arc(a,i,l,Math.PI,1.5*Math.PI,!1);break;case 1:a=t*n+n-l,i=r*n+l,e.arc(a,i,l,1.5*Math.PI,2*Math.PI,!1);break;case 2:a=t*n+n-l,i=r*n+n-l,e.arc(a,i,l,0,Math.PI/2,!1);break;case 3:a=t*n+l,i=r*n+n-l,e.arc(a,i,l,Math.PI/2,Math.PI,!1)}},fillRound:function(t,r,o,n){var a,i,l=n/2;switch(e.beginPath(),o){case 0:a=t*n+l,i=r*n+l,e.arc(a,i,l,Math.PI,1.5*Math.PI,!1),a=t*n,i=r*n;break;case 1:a=t*n+n-l,i=r*n+l,e.arc(a,i,l,1.5*Math.PI,2*Math.PI,!1),a=t*n+n,i=r*n;break;case 2:a=t*n+n-l,i=r*n+n-l,e.arc(a,i,l,0,Math.PI/2,!1),a=t*n+n,i=r*n+n;break;case 3:a=t*n+l,i=r*n+n-l,e.arc(a,i,l,Math.PI/2,Math.PI,!1),a=t*n,i=r*n+n}e.lineTo(a,i),e.closePath(),e.fill(),e.stroke()}}}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 r=0;r=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 r=-1;r<=7;r++)if(!(e+r<=-1||this.moduleCount<=e+r))for(var o=-1;o<=7;o++)t+o<=-1||this.moduleCount<=t+o||(this.modules[e+r][t+o]=0<=r&&r<=6&&(0==o||6==o)||0<=o&&o<=6&&(0==r||6==r)||2<=r&&r<=4&&2<=o&&o<=4)},getBestMaskPattern:function(){for(var e=0,t=0,r=0;r<8;r++){this.makeImpl(!0,r);var o=D.getLostPoint(this);(0==r||e>o)&&(e=o,t=r)}return t},createMovieClip:function(e,t,r){var o=e.createEmptyMovieClip(t,r);this.make();for(var n=0;n>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=o}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 r=this.errorCorrectLevel<<3|t,o=D.getBCHTypeInfo(r),n=0;n<15;n++){var a=!e&&1==(o>>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==(o>>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 r=-1,o=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[o][i-l]){var u=!1;a>>n&1)),D.getMask(t,o,i-l)&&(u=!u),this.modules[o][i-l]=u,-1==--n&&(a++,n=7)}if((o+=r)<0||this.moduleCount<=o){o-=r,r=-r;break}}}},E.PAD0=236,E.PAD1=17,E.createData=function(e,t,r){for(var o=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,o)},E.createBytes=function(e,t){for(var r=0,o=0,n=0,a=new Array(t.length),i=new Array(t.length),l=0;l=0?c.get(d):0}}for(var v=0,m=0;m1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),c=g.length-1;g.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=r.innerColor||s,d=r.outerColor||s;e.save(),!r.backgroundColor&&t.backgroundImage?e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height):(e.fillStyle=n,e.fillRect(0,0,e.canvas.width,e.canvas.height)),e.restore(),e.save(),e.translate(i,l);for(var v=0;v1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),c=g.length-1;g.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=r.innerColor||s,d=r.outerColor||s;e.save(),!r.backgroundColor&&t.backgroundImage?e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height):(e.fillStyle=n,e.fillRect(0,0,e.canvas.width,e.canvas.height)),e.restore(),e.save(),e.translate(i,l);for(var v=0;v1){var f=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),c=g.length-1;g.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=r.innerColor||s,d=r.outerColor||s;e.save(),!r.backgroundColor&&t.backgroundImage?e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height):(e.fillStyle=n,e.fillRect(0,0,e.canvas.width,e.canvas.height)),e.restore(),e.save(),e.translate(i+a/2,l+a/2);for(var v=0;v1){var s=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),f=g.length-1;g.forEach((function(e,t){s.addColorStop(t/f,e)})),s}r.innerColor,r.outerColor,e.save(),t.backgroundImage?e.drawImage(t.backgroundImage,0,0,e.canvas.width,e.canvas.height):(e.fillStyle=n,e.fillRect(0,0,e.canvas.width,e.canvas.height)),e.restore(),e.save(),e.translate(i,l);for(var c=0;c\n \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 r=Math.max(parseInt(t.width),parseInt(t.height));e.$canvas.width=2*r,e.$canvas.height=2*r,e.drawQRCode()}}},{key:"drawQRCode",value:function(){var e=this,t=e.level;e.logo?(t="H",e.$module.querySelector(".logo").style="background: url(".concat(e.logo,") center center/ 25% 25% no-repeat;")):e.$module.querySelector(".logo").style="";var r=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",r=new E(V(e,s[t]),s[t]);return r.addData(e),r.make(),r.modules}(e.value,t);e.context.clearRect(0,0,e.$canvas.width,e.$canvas.height),(O[e.template]||O.default)(e.context,r,{foregroundImage:e.foregroundImage,backgroundImage:e.backgroundImage,foregroundColor:e.foregroundColor,backgroundColor:e.backgroundColor,innerColor:e.innerColor,outerColor:e.outerColor})}}],i=[{key:"observedAttributes",get:function(){return["value","template","level","width","height","logo","foreground-image","background-image","foreground-color","background-color","inner-color","outer-color"]}}],o&&n(r.prototype,o),i&&n(r,i),Object.defineProperty(r,"prototype",{writable:!1}),u}(g(HTMLElement));customElements.get("widget-qrcode")||customElements.define("widget-qrcode",j)}(); diff --git a/index.html b/index.html index 066aa86..6edd161 100644 --- a/index.html +++ b/index.html @@ -183,13 +183,13 @@

二维码组件开源算法

- + + - - +
diff --git a/src/module/template/bar.js b/src/module/template/bar.js index 6f53ffc..aea1c5a 100644 --- a/src/module/template/bar.js +++ b/src/module/template/bar.js @@ -34,6 +34,16 @@ export default function(context,data,options){ context.restore(); context.save(); context.translate(x+0.5*pxWidth,y+0.5*pxWidth); + let drawItem = function(x,y,width,height){ + context.beginPath(); + context.arc(x*pxWidth,y*pxWidth,0.4*pxWidth,1*Math.PI,1.5*Math.PI); + context.arc((x+width-1)*pxWidth,y*pxWidth,0.4*pxWidth,1.5*Math.PI,0*Math.PI); + context.arc((x+width-1)*pxWidth,(y+height-1)*pxWidth,0.4*pxWidth,0*Math.PI,0.5*Math.PI); + context.arc(x*pxWidth,(y+height-1)*pxWidth,0.4*pxWidth,0.5*Math.PI,1*Math.PI); + context.closePath(); + context.fill(); + api.setRangeDisabled(x,y,width,height); + }; for(let i=0;i