diff --git a/dist/widget-qrcode.min.js b/dist/widget-qrcode.min.js index 8a7c6ee..7a5ef73 100644 --- a/dist/widget-qrcode.min.js +++ b/dist/widget-qrcode.min.js @@ -8,6 +8,6 @@ * Released under the MIT License * https://github.com/mumuy/widget-qrcode * - * Created on: 2024-08-15 + * Created on: 2024-09-02 */ -!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=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 y(){this.buffer=[],this.length=0}b.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 I={glog:function(e){if(e<1)throw new Error("glog("+e+")");return I.LOG_TABLE[e]},gexp:function(e){for(;e<0;)e+=255;for(;e>=256;)e-=255;return I.EXP_TABLE[e]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},P=0;P<8;P++)I.EXP_TABLE[P]=1<=0;)t^=V.G15<=0;)t^=V.G18<>>=1;return t},getPatternPosition:function(e){return V.PATTERN_POSITION_TABLE[e-1]},getMask:function(e,t,o){switch(e){case T:return(t+o)%2==0;case S:return t%2==0;case R:return o%3==0;case M:return(t+o)%3==0;case B: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 D: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;uh.length)throw new Error("Too long data");return o}function O(e,o){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var r,a,n,i,l=[],g=!0,u=!1;try{if(n=(o=o.call(e)).next,0===t){if(Object(o)!==o)return;g=!1}else for(;!(g=(r=n.call(o)).done)&&(l.push(r.value),l.length!==t);g=!0);}catch(e){u=!0,a=e}finally{try{if(!g&&null!=o.return&&(i=o.return(),Object(i)!==i))return}finally{if(u)throw a}}return l}}(e,o)||t(e,o)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}E.prototype={addData:function(e){var t=new b(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=V.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=V.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)),V.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=C.getRSBlocks(e,t),a=new y,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;m=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)}}}var H={default:function(e,t,o){var r=t.length,a=.05*e.canvas.width,n=(e.canvas.width-2*a)/r,i=a,l=a,g=j(e,t,o),u={};o.foregroundImage&&(u.foregroundImage=o.foregroundImage),o.backgroundImage&&(u.backgroundImage=o.backgroundImage),o.logo&&(u.logo=o.logo),g.imageReady(u).then((function(t){var a=o.backgroundColor||"#ffffff",u=(o.foregroundColor||"#000000").split(","),s=u[0];if(!o.foregroundColor&&t.foregroundImage&&(s=g.getImageBrush(t.foregroundImage)),u.length>1){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=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=a;!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+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,y=t.backgroundImage?g.getImageBrush(t.backgroundImage):a;e.save(),e.fillStyle=y,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i,l);for(var I=0;I\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,f[t]),f[t]);return o.addData(e),o.make(),o.modules}(e.value,t);e.context.clearRect(0,0,e.$canvas.width,e.$canvas.height),(H[e.template]||H.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"]}}],a&&n(r.prototype,a),i&&n(r,i),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,a,i}(s(HTMLElement));customElements.get("widget-qrcode")||customElements.define("widget-qrcode",$)})); +!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=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 y(){this.buffer=[],this.length=0}b.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 I={glog:function(e){if(e<1)throw new Error("glog("+e+")");return I.LOG_TABLE[e]},gexp:function(e){for(;e<0;)e+=255;for(;e>=256;)e-=255;return I.EXP_TABLE[e]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},P=0;P<8;P++)I.EXP_TABLE[P]=1<=0;)t^=V.G15<=0;)t^=V.G18<>>=1;return t},getPatternPosition:function(e){return V.PATTERN_POSITION_TABLE[e-1]},getMask:function(e,t,r){switch(e){case T:return(t+r)%2==0;case S:return t%2==0;case R:return r%3==0;case M:return(t+r)%3==0;case A:return(Math.floor(t/2)+Math.floor(r/3))%2==0;case B:return t*r%2+t*r%3==0;case L:return(t*r%2+t*r%3)%2==0;case D:return(t*r%3+(t+r)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}},getErrorCorrectPolynomial:function(e){for(var t=new w([1],0),r=0;r5&&(r+=3+a-5)}for(var g=0;gc.length)throw new Error("Too long data");return r}function O(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var o,n,a,i,l=[],u=!0,g=!1;try{if(a=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(o=a.call(r)).done)&&(l.push(o.value),l.length!==t);u=!0);}catch(e){g=!0,n=e}finally{try{if(!u&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(g)throw n}}return l}}(e,r)||t(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}E.prototype={addData:function(e){var t=new b(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=V.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=V.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)),V.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=C.getRSBlocks(e,t),n=new y,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;m=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)},getImageBrush: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&&t.height>e.canvas.height?t.width/t.heighte.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()},setText:function(){if(r.text){var t=Math.ceil(e.canvas.height/12.5),o=Math.ceil(e.canvas.height/50);e.textAlign="center",e.textBaseline="middle",e.font="bold ".concat(t,"px 微软雅黑"),e.lineWidth=o,e.strokeStyle=r.textStroke||"#ffffff",e.strokeText(r.text,e.canvas.width/2,e.canvas.height/2),e.fillStyle=r.textColor||"#000000",e.fillText(r.text,e.canvas.width/2,e.canvas.height/2)}},setLogo:function(t){var r=Math.ceil(e.canvas.width/4),o=(e.canvas.width-r)/2,n=(e.canvas.height-r)/2;e.drawImage(t,o,n,r,r)}}}var H={default:function(e,t,r){var o=t.length,n=.05*e.canvas.width,a=(e.canvas.width-2*n)/o,i=n,l=n,u=j(e,t,r),g={};r.foregroundImage&&(g.foregroundImage=r.foregroundImage),r.backgroundImage&&(g.backgroundImage=r.backgroundImage),r.logo&&(g.logo=r.logo),u.imageReady(g).then((function(t){var n=r.backgroundColor||"#ffffff",g=(r.foregroundColor||"#000000").split(","),s=g[0];if(!r.foregroundColor&&t.foregroundImage&&(s=u.getImageBrush(t.foregroundImage)),g.length>1){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,v=n;!r.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),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,v=n;!r.backgroundColor&&t.backgroundImage&&(v=u.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),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,v=n;!r.backgroundColor&&t.backgroundImage&&(v=u.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 c=e.createLinearGradient(0,0,e.canvas.width,e.canvas.height),h=s.length-1;s.forEach((function(e,t){c.addColorStop(t/h,e)})),f=c}var d=r.innerColor||g,v=r.outerColor||g;t.backgroundImage&&(g=g.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,y=t.backgroundImage?u.getImageBrush(t.backgroundImage):n;e.save(),e.fillStyle=y,e.fillRect(0,0,e.canvas.width,e.canvas.height),e.restore(),e.save(),e.translate(i,l);for(var I=0;I\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.logo?"H":e.level,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(x(e,f[t]),f[t]);return r.addData(e),r.make(),r.modules}(e.value,t);e.context.clearRect(0,0,e.$canvas.width,e.$canvas.height),(H[e.template]||H.default)(e.context,r,{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"]}}],n&&a(o.prototype,n),i&&a(o,i),Object.defineProperty(o,"prototype",{writable:!1}),o;var o,n,i}(s(HTMLElement));customElements.get("widget-qrcode")||customElements.define("widget-qrcode",$)})); diff --git a/src/widget-qrcode.js b/src/widget-qrcode.js index de13b28..9699c60 100644 --- a/src/widget-qrcode.js +++ b/src/widget-qrcode.js @@ -13,48 +13,93 @@ class WidgetQRCode extends HTMLElement { get value(){ return this.getAttribute('value')||'https://passer-by.com/'; } + set value(value){ + return this.setAttribute('value',value); + } get template(){ return this.getAttribute('template')||'default'; } + set template(value){ + return this.setAttribute('template',value); + } get level(){ return this.getAttribute('level')||'H'; } + set level(value){ + return this.setAttribute('level',value); + } get width(){ return +this.getAttribute('width')||0; } + set width(value){ + return this.setAttribute('width',value); + } get height(){ return +this.getAttribute('height')||0; } + set height(value){ + return this.setAttribute('height',value); + } get logo(){ return this.getAttribute('logo')||''; } + set logo(value){ + return this.setAttribute('logo',value); + } get text(){ return this.getAttribute('text')||''; } + set text(value){ + return this.setAttribute('text',value); + } get textColor(){ return this.getAttribute('text-color')||''; } + set textColor(value){ + return this.setAttribute('text-color',value); + } get textStroke(){ return this.getAttribute('text-stroke')||''; } + set textStroke(value){ + return this.setAttribute('text-stroke',value); + } get foregroundImage(){ return this.getAttribute('foreground-image')||''; } + set foregroundImage(value){ + return this.setAttribute('foreground-image',value); + } get backgroundImage(){ return this.getAttribute('background-image')||''; } + set backgroundImage(value){ + return this.setAttribute('background-image',value); + } get foregroundColor(){ return this.getAttribute('foreground-color')||''; } + set foregroundColor(value){ + return this.setAttribute('foreground-color',value); + } get backgroundColor(){ return this.getAttribute('background-color')||''; } + set backgroundColor(value){ + return this.setAttribute('background-color',value); + } get innerColor(){ return this.getAttribute('inner-color')||''; } + set innerColor(value){ + return this.setAttribute('inner-color',value); + } get outerColor(){ return this.getAttribute('outer-color')||''; } + set outerColor(value){ + return this.setAttribute('outer-color',value); + } attributeChangedCallback(name, oldValue, newValue){ if(oldValue!=newValue){ this.context&&this.drawQRCode();