diff --git a/dist/widget-qrcode.min.js b/dist/widget-qrcode.min.js index 75a826e..305ac2a 100644 --- a/dist/widget-qrcode.min.js +++ b/dist/widget-qrcode.min.js @@ -1,5 +1,5 @@ /*! - * qrcode-tool v1.0.0 + * widget-qrcode v1.0.3 * qrcode component * https://passer-by.com/widget-qrcode/ * @@ -8,6 +8,6 @@ * Released under the MIT License * https://github.com/mumuy/widget-qrcode * - * Created on: 2024-05-29 + * Created on: 2024-07-13 */ -!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^=E.G15<=0;)t^=E.G18<>>=1;return t},getPatternPosition:function(e){return E.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 g=0;gc.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=[],u=!0,g=!1;try{if(a=(o=o.call(e)).next,0===t){if(Object(o)!==o)return;u=!1}else for(;!(u=(r=a.call(o)).done)&&(l.push(r.value),l.length!==t);u=!0);}catch(e){g=!0,n=e}finally{try{if(!u&&null!=o.return&&(i=o.return(),Object(i)!==i))return}finally{if(g)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.")}()}x.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=x.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=E.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=E.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 u=!1;a>>n&1)),E.getMask(t,r,i-l)&&(u=!u),this.modules[r][i-l]=u,-1==--n&&(a++,n=7)}if((r+=o)<0||this.moduleCount<=r){r-=o,o=-o;break}}}},x.PAD0=236,x.PAD1=17,x.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(x.PAD0,8),n.getLengthInBits()>=8*l));)n.put(x.PAD1,8);return x.createBytes(n,r)},x.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,u=j(e,t,o),g={};o.foregroundImage&&(g.foregroundImage=o.foregroundImage),o.backgroundImage&&(g.backgroundImage=o.backgroundImage),o.logo&&(g.logo=o.logo),u.imageReady(g).then((function(t){var n=o.backgroundColor||"#ffffff",g=(o.foregroundColor||"#000000").split(","),s=g[0];if(!o.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=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=g.length-1;g.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=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=o.innerColor||s,d=o.outerColor||s,v=n;!o.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=o.innerColor||g,v=o.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 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 x(V(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}),u}(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^=E.G15<=0;)t^=E.G18<>>=1;return t},getPatternPosition:function(e){return E.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 g=0;gc.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=[],u=!0,g=!1;try{if(a=(o=o.call(e)).next,0===t){if(Object(o)!==o)return;u=!1}else for(;!(u=(r=a.call(o)).done)&&(l.push(r.value),l.length!==t);u=!0);}catch(e){g=!0,n=e}finally{try{if(!u&&null!=o.return&&(i=o.return(),Object(i)!==i))return}finally{if(g)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.")}()}x.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=x.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=E.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=E.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 u=!1;a>>n&1)),E.getMask(t,r,i-l)&&(u=!u),this.modules[r][i-l]=u,-1==--n&&(a++,n=7)}if((r+=o)<0||this.moduleCount<=r){r-=o,o=-o;break}}}},x.PAD0=236,x.PAD1=17,x.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(x.PAD0,8),n.getLengthInBits()>=8*l));)n.put(x.PAD1,8);return x.createBytes(n,r)},x.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,u=j(e,t,o),g={};o.foregroundImage&&(g.foregroundImage=o.foregroundImage),o.backgroundImage&&(g.backgroundImage=o.backgroundImage),o.logo&&(g.logo=o.logo),u.imageReady(g).then((function(t){var n=o.backgroundColor||"#ffffff",g=(o.foregroundColor||"#000000").split(","),s=g[0];if(!o.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=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=g.length-1;g.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=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=o.innerColor||s,d=o.outerColor||s,v=n;!o.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=o.innerColor||g,v=o.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 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 x(V(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}),u}(s(HTMLElement));customElements.get("widget-qrcode")||customElements.define("widget-qrcode",z)})); diff --git a/package.json b/package.json index 2033283..3b90671 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "qrcode-tool", - "version": "1.0.0", + "name": "widget-qrcode", + "version": "1.0.4", "description": "qrcode component", "author": "HaoLe Zheng", "license": "MIT", @@ -22,6 +22,9 @@ "yarn": "please-use-npm", "npm": ">=8" }, + "files":[ + "dist" + ], "devDependencies": { "@babel/core": "^7.23.2", "@babel/plugin-syntax-import-attributes": "^7.22.5", diff --git a/rollup.config.mjs b/rollup.config.mjs index ee3cb3c..90941ad 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -36,7 +36,7 @@ const commonPlugins = [ input: './src/widget-qrcode.js', output:[{ file: './dist/widget-qrcode.min.js', - format: 'iife', + format: 'umd', banner }], acornInjectPlugins: [ importAssertions ],