diff --git a/dist/widget-qrcode.min.js b/dist/widget-qrcode.min.js index d1529aa..5189cac 100644 --- a/dist/widget-qrcode.min.js +++ b/dist/widget-qrcode.min.js @@ -10,4 +10,4 @@ * * Created on: 2024-08-12 */ -!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=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 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 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^=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+a-5)}for(var u=0;uc.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,n,a,i,l=[],g=!0,u=!1;try{if(a=(o=o.call(e)).next,0===t){if(Object(o)!==o)return;g=!1}else for(;!(g=(r=a.call(o)).done)&&(l.push(r.value),l.length!==t);g=!0);}catch(e){u=!0,n=e}finally{try{if(!g&&null!=o.return&&(i=o.return(),Object(i)!==i))return}finally{if(u)throw n}}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 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=V.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)),V.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=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,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?c.get(d):0}}for(var v=0,m=0;m=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)}}}var H={default:function(e,t,o){var r=t.length,n=.05*e.canvas.width,a=(e.canvas.width-2*n)/r,i=n,l=n,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 n=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),c=u.length-1;u.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=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),c=u.length-1;u.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=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),c=u.length-1;u.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=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 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=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,y=t.backgroundImage?g.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 P=0;P\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})}}],n=[{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(t.prototype,r),n&&a(t,n),Object.defineProperty(t,"prototype",{writable:!1}),g}(s(HTMLElement));customElements.get("widget-qrcode")||customElements.define("widget-qrcode",z)})); +!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=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 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 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^=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+a-5)}for(var u=0;uc.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,n,a,i,l=[],g=!0,u=!1;try{if(a=(o=o.call(e)).next,0===t){if(Object(o)!==o)return;g=!1}else for(;!(g=(r=a.call(o)).done)&&(l.push(r.value),l.length!==t);g=!0);}catch(e){u=!0,n=e}finally{try{if(!g&&null!=o.return&&(i=o.return(),Object(i)!==i))return}finally{if(u)throw n}}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 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=V.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)),V.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=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,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?c.get(d):0}}for(var v=0,m=0;m=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)}}}var H={default:function(e,t,o){var r=t.length,n=.05*e.canvas.width,a=(e.canvas.width-2*n)/r,i=n,l=n,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 n=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),c=u.length-1;u.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=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),c=u.length-1;u.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=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),c=u.length-1;u.forEach((function(e,t){f.addColorStop(t/c,e)})),s=f}var h=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 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=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,y=t.backgroundImage?g.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 P=0;P\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})}}],n=[{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(t.prototype,r),n&&a(t,n),Object.defineProperty(t,"prototype",{writable:!1}),g}(s(HTMLElement));customElements.get("widget-qrcode")||customElements.define("widget-qrcode",z)})); diff --git a/index.html b/index.html index 2301aad..221f715 100644 --- a/index.html +++ b/index.html @@ -215,7 +215,7 @@ - +