qrcode.vue 3.4.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * qrcode.vue v3.4.1
3
- * A Vue.js component to generate QRCode.
4
- * © 2017-2023 @scopewu(https://github.com/scopewu)
2
+ * qrcode.vue v3.5.0
3
+ * A Vue.js component to generate QRCode. Both support Vue 2 and Vue 3
4
+ * © 2017-PRESENT @scopewu(https://github.com/scopewu)
5
5
  * MIT License.
6
6
  */
7
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("vue")):"function"==typeof define&&define.amd?define(["vue"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).QrcodeVue=e(t.Vue)}(this,(function(t){"use strict";var e,r=function(){return r=Object.assign||function(t){for(var e,r=1,n=arguments.length;n>r;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError,function(t){var e=function(){function e(t,r,n,i){if(this.version=t,this.errorCorrectionLevel=r,this.modules=[],this.isFunction=[],e.MIN_VERSION>t||t>e.MAX_VERSION)throw new RangeError("Version value out of range");if(-1>i||i>7)throw new RangeError("Mask value out of range");this.size=4*t+17;for(var a=[],s=0;this.size>s;s++)a.push(!1);for(s=0;this.size>s;s++)this.modules.push(a.slice()),this.isFunction.push(a.slice());this.drawFunctionPatterns();var u=this.addEccAndInterleave(n);if(this.drawCodewords(u),-1==i){var h=1e9;for(s=0;8>s;s++){this.applyMask(s),this.drawFormatBits(s);var f=this.getPenaltyScore();h>f&&(i=s,h=f),this.applyMask(s)}}o(i>=0&&7>=i),this.mask=i,this.applyMask(i),this.drawFormatBits(i),this.isFunction=[]}return e.encodeText=function(r,n){var o=t.QrSegment.makeSegments(r);return e.encodeSegments(o,n)},e.encodeBinary=function(r,n){var o=t.QrSegment.makeBytes(r);return e.encodeSegments([o],n)},e.encodeSegments=function(t,n,a,s,u,h){if(void 0===a&&(a=1),void 0===s&&(s=40),void 0===u&&(u=-1),void 0===h&&(h=!0),e.MIN_VERSION>a||a>s||s>e.MAX_VERSION||-1>u||u>7)throw new RangeError("Invalid value");var f,l;for(f=a;;f++){var c=8*e.getNumDataCodewords(f,n),d=i.getTotalBits(t,f);if(c>=d){l=d;break}if(f>=s)throw new RangeError("Data too long")}for(var v=0,g=[e.Ecc.MEDIUM,e.Ecc.QUARTILE,e.Ecc.HIGH];g.length>v;v++){var m=g[v];h&&l<=8*e.getNumDataCodewords(f,m)&&(n=m)}for(var p=[],E=0,M=t;M.length>E;E++){var C=M[E];r(C.mode.modeBits,4,p),r(C.numChars,C.mode.numCharCountBits(f),p);for(var w=0,R=C.getData();R.length>w;w++){p.push(R[w])}}o(p.length==l);var y=8*e.getNumDataCodewords(f,n);o(y>=p.length),r(0,Math.min(4,y-p.length),p),r(0,(8-p.length%8)%8,p),o(p.length%8==0);for(var N=236;y>p.length;N^=253)r(N,8,p);for(var A=[];p.length>8*A.length;)A.push(0);return p.forEach((function(t,e){return A[e>>>3]|=t<<7-(7&e)})),new e(f,n,A,u)},e.prototype.getModule=function(t,e){return t>=0&&this.size>t&&e>=0&&this.size>e&&this.modules[e][t]},e.prototype.getModules=function(){return this.modules},e.prototype.drawFunctionPatterns=function(){for(var t=0;this.size>t;t++)this.setFunctionModule(6,t,t%2==0),this.setFunctionModule(t,6,t%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);var e=this.getAlignmentPatternPositions(),r=e.length;for(t=0;r>t;t++)for(var n=0;r>n;n++)0==t&&0==n||0==t&&n==r-1||t==r-1&&0==n||this.drawAlignmentPattern(e[t],e[n]);this.drawFormatBits(0),this.drawVersion()},e.prototype.drawFormatBits=function(t){for(var e=this.errorCorrectionLevel.formatBits<<3|t,r=e,i=0;10>i;i++)r=r<<1^1335*(r>>>9);var a=21522^(e<<10|r);o(a>>>15==0);for(i=0;5>=i;i++)this.setFunctionModule(8,i,n(a,i));this.setFunctionModule(8,7,n(a,6)),this.setFunctionModule(8,8,n(a,7)),this.setFunctionModule(7,8,n(a,8));for(i=9;15>i;i++)this.setFunctionModule(14-i,8,n(a,i));for(i=0;8>i;i++)this.setFunctionModule(this.size-1-i,8,n(a,i));for(i=8;15>i;i++)this.setFunctionModule(8,this.size-15+i,n(a,i));this.setFunctionModule(8,this.size-8,!0)},e.prototype.drawVersion=function(){if(this.version>=7){for(var t=this.version,e=0;12>e;e++)t=t<<1^7973*(t>>>11);var r=this.version<<12|t;o(r>>>18==0);for(e=0;18>e;e++){var i=n(r,e),a=this.size-11+e%3,s=Math.floor(e/3);this.setFunctionModule(a,s,i),this.setFunctionModule(s,a,i)}}},e.prototype.drawFinderPattern=function(t,e){for(var r=-4;4>=r;r++)for(var n=-4;4>=n;n++){var o=Math.max(Math.abs(n),Math.abs(r)),i=t+n,a=e+r;i>=0&&this.size>i&&a>=0&&this.size>a&&this.setFunctionModule(i,a,2!=o&&4!=o)}},e.prototype.drawAlignmentPattern=function(t,e){for(var r=-2;2>=r;r++)for(var n=-2;2>=n;n++)this.setFunctionModule(t+n,e+r,1!=Math.max(Math.abs(n),Math.abs(r)))},e.prototype.setFunctionModule=function(t,e,r){this.modules[e][t]=r,this.isFunction[e][t]=!0},e.prototype.addEccAndInterleave=function(t){var r=this.version,n=this.errorCorrectionLevel;if(t.length!=e.getNumDataCodewords(r,n))throw new RangeError("Invalid argument");for(var i=e.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][r],a=e.ECC_CODEWORDS_PER_BLOCK[n.ordinal][r],s=Math.floor(e.getNumRawDataModules(r)/8),u=i-s%i,h=Math.floor(s/i),f=[],l=e.reedSolomonComputeDivisor(a),c=0,d=0;i>c;c++){var v=t.slice(d,d+h-a+(u>c?0:1));d+=v.length;var g=e.reedSolomonComputeRemainder(v,l);u>c&&v.push(0),f.push(v.concat(g))}var m=[],p=function(t){f.forEach((function(e,r){t==h-a&&u>r||m.push(e[t])}))};for(c=0;f[0].length>c;c++)p(c);return o(m.length==s),m},e.prototype.drawCodewords=function(t){if(t.length!=Math.floor(e.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");for(var r=0,i=this.size-1;i>=1;i-=2){6==i&&(i=5);for(var a=0;this.size>a;a++)for(var s=0;2>s;s++){var u=i-s,h=0==(i+1&2)?this.size-1-a:a;!this.isFunction[h][u]&&8*t.length>r&&(this.modules[h][u]=n(t[r>>>3],7-(7&r)),r++)}}o(r==8*t.length)},e.prototype.applyMask=function(t){if(0>t||t>7)throw new RangeError("Mask value out of range");for(var e=0;this.size>e;e++)for(var r=0;this.size>r;r++){var n=void 0;switch(t){case 0:n=(r+e)%2==0;break;case 1:n=e%2==0;break;case 2:n=r%3==0;break;case 3:n=(r+e)%3==0;break;case 4:n=(Math.floor(r/3)+Math.floor(e/2))%2==0;break;case 5:n=r*e%2+r*e%3==0;break;case 6:n=(r*e%2+r*e%3)%2==0;break;case 7:n=((r+e)%2+r*e%3)%2==0;break;default:throw Error("Unreachable")}!this.isFunction[e][r]&&n&&(this.modules[e][r]=!this.modules[e][r])}},e.prototype.getPenaltyScore=function(){for(var t=0,r=0;this.size>r;r++){for(var n=!1,i=0,a=[0,0,0,0,0,0,0],s=0;this.size>s;s++)this.modules[r][s]==n?5==++i?t+=e.PENALTY_N1:i>5&&t++:(this.finderPenaltyAddHistory(i,a),n||(t+=this.finderPenaltyCountPatterns(a)*e.PENALTY_N3),n=this.modules[r][s],i=1);t+=this.finderPenaltyTerminateAndCount(n,i,a)*e.PENALTY_N3}for(s=0;this.size>s;s++){n=!1;var u=0;for(a=[0,0,0,0,0,0,0],r=0;this.size>r;r++)this.modules[r][s]==n?5==++u?t+=e.PENALTY_N1:u>5&&t++:(this.finderPenaltyAddHistory(u,a),n||(t+=this.finderPenaltyCountPatterns(a)*e.PENALTY_N3),n=this.modules[r][s],u=1);t+=this.finderPenaltyTerminateAndCount(n,u,a)*e.PENALTY_N3}for(r=0;this.size-1>r;r++)for(s=0;this.size-1>s;s++){var h=this.modules[r][s];h==this.modules[r][s+1]&&h==this.modules[r+1][s]&&h==this.modules[r+1][s+1]&&(t+=e.PENALTY_N2)}for(var f=0,l=0,c=this.modules;c.length>l;l++){f=c[l].reduce((function(t,e){return t+(e?1:0)}),f)}var d=this.size*this.size,v=Math.ceil(Math.abs(20*f-10*d)/d)-1;return o(v>=0&&9>=v),o((t+=v*e.PENALTY_N4)>=0&&2568888>=t),t},e.prototype.getAlignmentPatternPositions=function(){if(1==this.version)return[];for(var t=Math.floor(this.version/7)+2,e=32==this.version?26:2*Math.ceil((4*this.version+4)/(2*t-2)),r=[6],n=this.size-7;t>r.length;n-=e)r.splice(1,0,n);return r},e.getNumRawDataModules=function(t){if(e.MIN_VERSION>t||t>e.MAX_VERSION)throw new RangeError("Version number out of range");var r=(16*t+128)*t+64;if(t>=2){var n=Math.floor(t/7)+2;r-=(25*n-10)*n-55,7>t||(r-=36)}return o(r>=208&&29648>=r),r},e.getNumDataCodewords=function(t,r){return Math.floor(e.getNumRawDataModules(t)/8)-e.ECC_CODEWORDS_PER_BLOCK[r.ordinal][t]*e.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][t]},e.reedSolomonComputeDivisor=function(t){if(1>t||t>255)throw new RangeError("Degree out of range");for(var r=[],n=0;t-1>n;n++)r.push(0);r.push(1);var o=1;for(n=0;t>n;n++){for(var i=0;r.length>i;i++)r[i]=e.reedSolomonMultiply(r[i],o),r.length>i+1&&(r[i]^=r[i+1]);o=e.reedSolomonMultiply(o,2)}return r},e.reedSolomonComputeRemainder=function(t,r){for(var n=r.map((function(t){return 0})),o=function(t){var o=t^n.shift();n.push(0),r.forEach((function(t,r){return n[r]^=e.reedSolomonMultiply(t,o)}))},i=0,a=t;a.length>i;i++){o(a[i])}return n},e.reedSolomonMultiply=function(t,e){if(t>>>8!=0||e>>>8!=0)throw new RangeError("Byte out of range");for(var r=0,n=7;n>=0;n--)r=r<<1^285*(r>>>7),r^=(e>>>n&1)*t;return o(r>>>8==0),r},e.prototype.finderPenaltyCountPatterns=function(t){var e=t[1];o(3*this.size>=e);var r=e>0&&t[2]==e&&t[3]==3*e&&t[4]==e&&t[5]==e;return(!r||4*e>t[0]||e>t[6]?0:1)+(!r||4*e>t[6]||e>t[0]?0:1)},e.prototype.finderPenaltyTerminateAndCount=function(t,e,r){return t&&(this.finderPenaltyAddHistory(e,r),e=0),this.finderPenaltyAddHistory(e+=this.size,r),this.finderPenaltyCountPatterns(r)},e.prototype.finderPenaltyAddHistory=function(t,e){0==e[0]&&(t+=this.size),e.pop(),e.unshift(t)},e.MIN_VERSION=1,e.MAX_VERSION=40,e.PENALTY_N1=3,e.PENALTY_N2=3,e.PENALTY_N3=40,e.PENALTY_N4=10,e.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],e.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e}();function r(t,e,r){if(0>e||e>31||t>>>e!=0)throw new RangeError("Value out of range");for(var n=e-1;n>=0;n--)r.push(t>>>n&1)}function n(t,e){return 0!=(t>>>e&1)}function o(t){if(!t)throw Error("Assertion error")}t.QrCode=e;var i=function(){function t(t,e,r){if(this.mode=t,this.numChars=e,this.bitData=r,0>e)throw new RangeError("Invalid argument");this.bitData=r.slice()}return t.makeBytes=function(e){for(var n=[],o=0,i=e;i.length>o;o++){r(i[o],8,n)}return new t(t.Mode.BYTE,e.length,n)},t.makeNumeric=function(e){if(!t.isNumeric(e))throw new RangeError("String contains non-numeric characters");for(var n=[],o=0;e.length>o;){var i=Math.min(e.length-o,3);r(parseInt(e.substring(o,o+i),10),3*i+1,n),o+=i}return new t(t.Mode.NUMERIC,e.length,n)},t.makeAlphanumeric=function(e){if(!t.isAlphanumeric(e))throw new RangeError("String contains unencodable characters in alphanumeric mode");var n,o=[];for(n=0;e.length>=n+2;n+=2){var i=45*t.ALPHANUMERIC_CHARSET.indexOf(e.charAt(n));r(i+=t.ALPHANUMERIC_CHARSET.indexOf(e.charAt(n+1)),11,o)}return e.length>n&&r(t.ALPHANUMERIC_CHARSET.indexOf(e.charAt(n)),6,o),new t(t.Mode.ALPHANUMERIC,e.length,o)},t.makeSegments=function(e){return""==e?[]:t.isNumeric(e)?[t.makeNumeric(e)]:t.isAlphanumeric(e)?[t.makeAlphanumeric(e)]:[t.makeBytes(t.toUtf8ByteArray(e))]},t.makeEci=function(e){var n=[];if(0>e)throw new RangeError("ECI assignment value out of range");if(128>e)r(e,8,n);else if(16384>e)r(2,2,n),r(e,14,n);else{if(e>=1e6)throw new RangeError("ECI assignment value out of range");r(6,3,n),r(e,21,n)}return new t(t.Mode.ECI,0,n)},t.isNumeric=function(e){return t.NUMERIC_REGEX.test(e)},t.isAlphanumeric=function(e){return t.ALPHANUMERIC_REGEX.test(e)},t.prototype.getData=function(){return this.bitData.slice()},t.getTotalBits=function(t,e){for(var r=0,n=0,o=t;o.length>n;n++){var i=o[n],a=i.mode.numCharCountBits(e);if(i.numChars>=1<<a)return 1/0;r+=4+a+i.bitData.length}return r},t.toUtf8ByteArray=function(t){t=encodeURI(t);for(var e=[],r=0;t.length>r;r++)"%"!=t.charAt(r)?e.push(t.charCodeAt(r)):(e.push(parseInt(t.substring(r+1,r+3),16)),r+=2);return e},t.NUMERIC_REGEX=/^[0-9]*$/,t.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,t.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",t}();t.QrSegment=i}(e||(e={})),function(t){var e,r;e=t.QrCode||(t.QrCode={}),r=function(){function t(t,e){this.ordinal=t,this.formatBits=e}return t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),t}(),e.Ecc=r}(e||(e={})),function(t){var e,r;e=t.QrSegment||(t.QrSegment={}),r=function(){function t(t,e){this.modeBits=t,this.numBitsCharCount=e}return t.prototype.numCharCountBits=function(t){return this.numBitsCharCount[Math.floor((t+7)/17)]},t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),t}(),e.Mode=r}(e||(e={}));var n=e,o={L:n.QrCode.Ecc.LOW,M:n.QrCode.Ecc.MEDIUM,Q:n.QrCode.Ecc.QUARTILE,H:n.QrCode.Ecc.HIGH},i=function(){try{(new Path2D).addPath(new Path2D)}catch(t){return!1}return!0}();function a(t){return t in o}function s(t,e){void 0===e&&(e=0);var r=[];return t.forEach((function(t,n){var o=null;t.forEach((function(i,a){if(!i&&null!==o)return r.push("M".concat(o+e," ").concat(n+e,"h").concat(a-o,"v1H").concat(o+e,"z")),void(o=null);if(a!==t.length-1)i&&null===o&&(o=a);else{if(!i)return;r.push(null===o?"M".concat(a+e,",").concat(n+e," h1v1H").concat(a+e,"z"):"M".concat(o+e,",").concat(n+e," h").concat(a+1-o,"v1H").concat(o+e,"z"))}}))})),r.join("")}var u={value:{type:String,required:!0,default:""},size:{type:Number,default:100},level:{type:String,default:"H",validator:function(t){return a(t)}},background:{type:String,default:"#fff"},foreground:{type:String,default:"#000"},margin:{type:Number,required:!1,default:0}},h=r(r({},u),{renderAs:{type:String,required:!1,default:"canvas",validator:function(t){return["canvas","svg"].indexOf(t)>-1}}}),f=t.defineComponent({name:"QRCodeSvg",props:u,setup:function(e){var r=t.ref(0),i=t.ref(""),a=function(){var t=e.margin,a=n.QrCode.encodeText(e.value,o[e.level]).getModules();r.value=a.length+2*t,i.value=s(a,t)};return a(),t.onUpdated(a),function(){return t.h("svg",{width:e.size,height:e.size,"shape-rendering":"crispEdges",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 ".concat(r.value," ").concat(r.value)},[t.h("path",{fill:e.background,d:"M0,0 h".concat(r.value,"v").concat(r.value,"H0z")}),t.h("path",{fill:e.foreground,d:i.value})])}}}),l=t.defineComponent({name:"QRCodeCanvas",props:u,setup:function(e){var r=t.ref(null),a=function(){var t=e.value,a=e.level,u=e.size,h=e.margin,f=e.background,l=e.foreground,c=r.value;if(c){var d=c.getContext("2d");if(d){var v=n.QrCode.encodeText(t,o[a]).getModules(),g=v.length+2*h,m=window.devicePixelRatio||1,p=u/g*m;c.height=c.width=u*m,d.scale(p,p),d.fillStyle=f,d.fillRect(0,0,g,g),d.fillStyle=l,i?d.fill(new Path2D(s(v,h))):v.forEach((function(t,e){t.forEach((function(t,r){t&&d.fillRect(r+h,e+h,1,1)}))}))}}};return t.onMounted(a),t.onUpdated(a),function(){return t.h("canvas",{ref:r,style:{width:"".concat(e.size,"px"),height:"".concat(e.size,"px")}})}}});return t.defineComponent({name:"Qrcode",render:function(){var e=this.$props,r=e.renderAs,n=e.value,o=e.level,i=e.background,s=e.foreground,u=e.size>>>0,h=e.margin>>>0,c=a(o)?o:"H";return t.h("svg"===r?f:l,{value:n,size:u,margin:h,level:c,background:i,foreground:s})},props:h})}));
7
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).QrcodeVue={},t.Vue)}(this,(function(t,e){"use strict";var r,n=function(){return n=Object.assign||function(t){for(var e,r=1,n=arguments.length;n>r;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError,function(t){var e=function(){function e(t,r,n,i){if(this.version=t,this.errorCorrectionLevel=r,this.modules=[],this.isFunction=[],e.MIN_VERSION>t||t>e.MAX_VERSION)throw new RangeError("Version value out of range");if(-1>i||i>7)throw new RangeError("Mask value out of range");this.size=4*t+17;for(var a=[],s=0;this.size>s;s++)a.push(!1);for(s=0;this.size>s;s++)this.modules.push(a.slice()),this.isFunction.push(a.slice());this.drawFunctionPatterns();var u=this.addEccAndInterleave(n);if(this.drawCodewords(u),-1==i){var h=1e9;for(s=0;8>s;s++){this.applyMask(s),this.drawFormatBits(s);var l=this.getPenaltyScore();h>l&&(i=s,h=l),this.applyMask(s)}}o(i>=0&&7>=i),this.mask=i,this.applyMask(i),this.drawFormatBits(i),this.isFunction=[]}return e.encodeText=function(r,n){var o=t.QrSegment.makeSegments(r);return e.encodeSegments(o,n)},e.encodeBinary=function(r,n){var o=t.QrSegment.makeBytes(r);return e.encodeSegments([o],n)},e.encodeSegments=function(t,n,a,s,u,h){if(void 0===a&&(a=1),void 0===s&&(s=40),void 0===u&&(u=-1),void 0===h&&(h=!0),e.MIN_VERSION>a||a>s||s>e.MAX_VERSION||-1>u||u>7)throw new RangeError("Invalid value");var l,c;for(l=a;;l++){var f=8*e.getNumDataCodewords(l,n),d=i.getTotalBits(t,l);if(f>=d){c=d;break}if(l>=s)throw new RangeError("Data too long")}for(var g=0,v=[e.Ecc.MEDIUM,e.Ecc.QUARTILE,e.Ecc.HIGH];v.length>g;g++){var m=v[g];h&&c<=8*e.getNumDataCodewords(l,m)&&(n=m)}for(var p=[],E=0,w=t;w.length>E;E++){var M=w[E];r(M.mode.modeBits,4,p),r(M.numChars,M.mode.numCharCountBits(l),p);for(var C=0,y=M.getData();y.length>C;C++){p.push(y[C])}}o(p.length==c);var R=8*e.getNumDataCodewords(l,n);o(R>=p.length),r(0,Math.min(4,R-p.length),p),r(0,(8-p.length%8)%8,p),o(p.length%8==0);for(var N=236;R>p.length;N^=253)r(N,8,p);for(var A=[];p.length>8*A.length;)A.push(0);return p.forEach((function(t,e){return A[e>>>3]|=t<<7-(7&e)})),new e(l,n,A,u)},e.prototype.getModule=function(t,e){return t>=0&&this.size>t&&e>=0&&this.size>e&&this.modules[e][t]},e.prototype.getModules=function(){return this.modules},e.prototype.drawFunctionPatterns=function(){for(var t=0;this.size>t;t++)this.setFunctionModule(6,t,t%2==0),this.setFunctionModule(t,6,t%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);var e=this.getAlignmentPatternPositions(),r=e.length;for(t=0;r>t;t++)for(var n=0;r>n;n++)0==t&&0==n||0==t&&n==r-1||t==r-1&&0==n||this.drawAlignmentPattern(e[t],e[n]);this.drawFormatBits(0),this.drawVersion()},e.prototype.drawFormatBits=function(t){for(var e=this.errorCorrectionLevel.formatBits<<3|t,r=e,i=0;10>i;i++)r=r<<1^1335*(r>>>9);var a=21522^(e<<10|r);o(a>>>15==0);for(i=0;5>=i;i++)this.setFunctionModule(8,i,n(a,i));this.setFunctionModule(8,7,n(a,6)),this.setFunctionModule(8,8,n(a,7)),this.setFunctionModule(7,8,n(a,8));for(i=9;15>i;i++)this.setFunctionModule(14-i,8,n(a,i));for(i=0;8>i;i++)this.setFunctionModule(this.size-1-i,8,n(a,i));for(i=8;15>i;i++)this.setFunctionModule(8,this.size-15+i,n(a,i));this.setFunctionModule(8,this.size-8,!0)},e.prototype.drawVersion=function(){if(this.version>=7){for(var t=this.version,e=0;12>e;e++)t=t<<1^7973*(t>>>11);var r=this.version<<12|t;o(r>>>18==0);for(e=0;18>e;e++){var i=n(r,e),a=this.size-11+e%3,s=Math.floor(e/3);this.setFunctionModule(a,s,i),this.setFunctionModule(s,a,i)}}},e.prototype.drawFinderPattern=function(t,e){for(var r=-4;4>=r;r++)for(var n=-4;4>=n;n++){var o=Math.max(Math.abs(n),Math.abs(r)),i=t+n,a=e+r;i>=0&&this.size>i&&a>=0&&this.size>a&&this.setFunctionModule(i,a,2!=o&&4!=o)}},e.prototype.drawAlignmentPattern=function(t,e){for(var r=-2;2>=r;r++)for(var n=-2;2>=n;n++)this.setFunctionModule(t+n,e+r,1!=Math.max(Math.abs(n),Math.abs(r)))},e.prototype.setFunctionModule=function(t,e,r){this.modules[e][t]=r,this.isFunction[e][t]=!0},e.prototype.addEccAndInterleave=function(t){var r=this.version,n=this.errorCorrectionLevel;if(t.length!=e.getNumDataCodewords(r,n))throw new RangeError("Invalid argument");for(var i=e.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][r],a=e.ECC_CODEWORDS_PER_BLOCK[n.ordinal][r],s=Math.floor(e.getNumRawDataModules(r)/8),u=i-s%i,h=Math.floor(s/i),l=[],c=e.reedSolomonComputeDivisor(a),f=0,d=0;i>f;f++){var g=t.slice(d,d+h-a+(u>f?0:1));d+=g.length;var v=e.reedSolomonComputeRemainder(g,c);u>f&&g.push(0),l.push(g.concat(v))}var m=[],p=function(t){l.forEach((function(e,r){t==h-a&&u>r||m.push(e[t])}))};for(f=0;l[0].length>f;f++)p(f);return o(m.length==s),m},e.prototype.drawCodewords=function(t){if(t.length!=Math.floor(e.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");for(var r=0,i=this.size-1;i>=1;i-=2){6==i&&(i=5);for(var a=0;this.size>a;a++)for(var s=0;2>s;s++){var u=i-s,h=!(i+1&2)?this.size-1-a:a;!this.isFunction[h][u]&&8*t.length>r&&(this.modules[h][u]=n(t[r>>>3],7-(7&r)),r++)}}o(r==8*t.length)},e.prototype.applyMask=function(t){if(0>t||t>7)throw new RangeError("Mask value out of range");for(var e=0;this.size>e;e++)for(var r=0;this.size>r;r++){var n=void 0;switch(t){case 0:n=(r+e)%2==0;break;case 1:n=e%2==0;break;case 2:n=r%3==0;break;case 3:n=(r+e)%3==0;break;case 4:n=(Math.floor(r/3)+Math.floor(e/2))%2==0;break;case 5:n=r*e%2+r*e%3==0;break;case 6:n=(r*e%2+r*e%3)%2==0;break;case 7:n=((r+e)%2+r*e%3)%2==0;break;default:throw Error("Unreachable")}!this.isFunction[e][r]&&n&&(this.modules[e][r]=!this.modules[e][r])}},e.prototype.getPenaltyScore=function(){for(var t=0,r=0;this.size>r;r++){for(var n=!1,i=0,a=[0,0,0,0,0,0,0],s=0;this.size>s;s++)this.modules[r][s]==n?5==++i?t+=e.PENALTY_N1:i>5&&t++:(this.finderPenaltyAddHistory(i,a),n||(t+=this.finderPenaltyCountPatterns(a)*e.PENALTY_N3),n=this.modules[r][s],i=1);t+=this.finderPenaltyTerminateAndCount(n,i,a)*e.PENALTY_N3}for(s=0;this.size>s;s++){n=!1;var u=0;for(a=[0,0,0,0,0,0,0],r=0;this.size>r;r++)this.modules[r][s]==n?5==++u?t+=e.PENALTY_N1:u>5&&t++:(this.finderPenaltyAddHistory(u,a),n||(t+=this.finderPenaltyCountPatterns(a)*e.PENALTY_N3),n=this.modules[r][s],u=1);t+=this.finderPenaltyTerminateAndCount(n,u,a)*e.PENALTY_N3}for(r=0;this.size-1>r;r++)for(s=0;this.size-1>s;s++){var h=this.modules[r][s];h==this.modules[r][s+1]&&h==this.modules[r+1][s]&&h==this.modules[r+1][s+1]&&(t+=e.PENALTY_N2)}for(var l=0,c=0,f=this.modules;f.length>c;c++){l=f[c].reduce((function(t,e){return t+(e?1:0)}),l)}var d=this.size*this.size,g=Math.ceil(Math.abs(20*l-10*d)/d)-1;return o(g>=0&&9>=g),o((t+=g*e.PENALTY_N4)>=0&&2568888>=t),t},e.prototype.getAlignmentPatternPositions=function(){if(1==this.version)return[];for(var t=Math.floor(this.version/7)+2,e=2*Math.floor((8*this.version+3*t+5)/(4*t-4)),r=[6],n=this.size-7;t>r.length;n-=e)r.splice(1,0,n);return r},e.getNumRawDataModules=function(t){if(e.MIN_VERSION>t||t>e.MAX_VERSION)throw new RangeError("Version number out of range");var r=(16*t+128)*t+64;if(t>=2){var n=Math.floor(t/7)+2;r-=(25*n-10)*n-55,7>t||(r-=36)}return o(r>=208&&29648>=r),r},e.getNumDataCodewords=function(t,r){return Math.floor(e.getNumRawDataModules(t)/8)-e.ECC_CODEWORDS_PER_BLOCK[r.ordinal][t]*e.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][t]},e.reedSolomonComputeDivisor=function(t){if(1>t||t>255)throw new RangeError("Degree out of range");for(var r=[],n=0;t-1>n;n++)r.push(0);r.push(1);var o=1;for(n=0;t>n;n++){for(var i=0;r.length>i;i++)r[i]=e.reedSolomonMultiply(r[i],o),r.length>i+1&&(r[i]^=r[i+1]);o=e.reedSolomonMultiply(o,2)}return r},e.reedSolomonComputeRemainder=function(t,r){for(var n=r.map((function(t){return 0})),o=function(t){var o=t^n.shift();n.push(0),r.forEach((function(t,r){return n[r]^=e.reedSolomonMultiply(t,o)}))},i=0,a=t;a.length>i;i++){o(a[i])}return n},e.reedSolomonMultiply=function(t,e){if(t>>>8!=0||e>>>8!=0)throw new RangeError("Byte out of range");for(var r=0,n=7;n>=0;n--)r=r<<1^285*(r>>>7),r^=(e>>>n&1)*t;return o(r>>>8==0),r},e.prototype.finderPenaltyCountPatterns=function(t){var e=t[1];o(3*this.size>=e);var r=e>0&&t[2]==e&&t[3]==3*e&&t[4]==e&&t[5]==e;return(!r||4*e>t[0]||e>t[6]?0:1)+(!r||4*e>t[6]||e>t[0]?0:1)},e.prototype.finderPenaltyTerminateAndCount=function(t,e,r){return t&&(this.finderPenaltyAddHistory(e,r),e=0),this.finderPenaltyAddHistory(e+=this.size,r),this.finderPenaltyCountPatterns(r)},e.prototype.finderPenaltyAddHistory=function(t,e){0==e[0]&&(t+=this.size),e.pop(),e.unshift(t)},e.MIN_VERSION=1,e.MAX_VERSION=40,e.PENALTY_N1=3,e.PENALTY_N2=3,e.PENALTY_N3=40,e.PENALTY_N4=10,e.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],e.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e}();function r(t,e,r){if(0>e||e>31||t>>>e!=0)throw new RangeError("Value out of range");for(var n=e-1;n>=0;n--)r.push(t>>>n&1)}function n(t,e){return!!(t>>>e&1)}function o(t){if(!t)throw Error("Assertion error")}t.QrCode=e;var i=function(){function t(t,e,r){if(this.mode=t,this.numChars=e,this.bitData=r,0>e)throw new RangeError("Invalid argument");this.bitData=r.slice()}return t.makeBytes=function(e){for(var n=[],o=0,i=e;i.length>o;o++){r(i[o],8,n)}return new t(t.Mode.BYTE,e.length,n)},t.makeNumeric=function(e){if(!t.isNumeric(e))throw new RangeError("String contains non-numeric characters");for(var n=[],o=0;e.length>o;){var i=Math.min(e.length-o,3);r(parseInt(e.substring(o,o+i),10),3*i+1,n),o+=i}return new t(t.Mode.NUMERIC,e.length,n)},t.makeAlphanumeric=function(e){if(!t.isAlphanumeric(e))throw new RangeError("String contains unencodable characters in alphanumeric mode");var n,o=[];for(n=0;e.length>=n+2;n+=2){var i=45*t.ALPHANUMERIC_CHARSET.indexOf(e.charAt(n));r(i+=t.ALPHANUMERIC_CHARSET.indexOf(e.charAt(n+1)),11,o)}return e.length>n&&r(t.ALPHANUMERIC_CHARSET.indexOf(e.charAt(n)),6,o),new t(t.Mode.ALPHANUMERIC,e.length,o)},t.makeSegments=function(e){return""==e?[]:t.isNumeric(e)?[t.makeNumeric(e)]:t.isAlphanumeric(e)?[t.makeAlphanumeric(e)]:[t.makeBytes(t.toUtf8ByteArray(e))]},t.makeEci=function(e){var n=[];if(0>e)throw new RangeError("ECI assignment value out of range");if(128>e)r(e,8,n);else if(16384>e)r(2,2,n),r(e,14,n);else{if(e>=1e6)throw new RangeError("ECI assignment value out of range");r(6,3,n),r(e,21,n)}return new t(t.Mode.ECI,0,n)},t.isNumeric=function(e){return t.NUMERIC_REGEX.test(e)},t.isAlphanumeric=function(e){return t.ALPHANUMERIC_REGEX.test(e)},t.prototype.getData=function(){return this.bitData.slice()},t.getTotalBits=function(t,e){for(var r=0,n=0,o=t;o.length>n;n++){var i=o[n],a=i.mode.numCharCountBits(e);if(i.numChars>=1<<a)return 1/0;r+=4+a+i.bitData.length}return r},t.toUtf8ByteArray=function(t){t=encodeURI(t);for(var e=[],r=0;t.length>r;r++)"%"!=t.charAt(r)?e.push(t.charCodeAt(r)):(e.push(parseInt(t.substring(r+1,r+3),16)),r+=2);return e},t.NUMERIC_REGEX=/^[0-9]*$/,t.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,t.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",t}();t.QrSegment=i}(r||(r={})),function(t){var e,r;e=t.QrCode||(t.QrCode={}),r=function(){function t(t,e){this.ordinal=t,this.formatBits=e}return t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),t}(),e.Ecc=r}(r||(r={})),function(t){var e,r;e=t.QrSegment||(t.QrSegment={}),r=function(){function t(t,e){this.modeBits=t,this.numBitsCharCount=e}return t.prototype.numCharCountBits=function(t){return this.numBitsCharCount[Math.floor((t+7)/17)]},t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),t}(),e.Mode=r}(r||(r={}));var o=r,i={L:o.QrCode.Ecc.LOW,M:o.QrCode.Ecc.MEDIUM,Q:o.QrCode.Ecc.QUARTILE,H:o.QrCode.Ecc.HIGH},a=function(){try{(new Path2D).addPath(new Path2D)}catch(t){return!1}return!0}();function s(t){return t in i}function u(t,e){void 0===e&&(e=0);var r=[];return t.forEach((function(t,n){var o=null;t.forEach((function(i,a){if(!i&&null!==o)return r.push("M".concat(o+e," ").concat(n+e,"h").concat(a-o,"v1H").concat(o+e,"z")),void(o=null);if(a!==t.length-1)i&&null===o&&(o=a);else{if(!i)return;r.push(null===o?"M".concat(a+e,",").concat(n+e," h1v1H").concat(a+e,"z"):"M".concat(o+e,",").concat(n+e," h").concat(a+1-o,"v1H").concat(o+e,"z"))}}))})),r.join("")}function h(t,e,r,n){var o=n.width,i=n.height,a=n.x,s=n.y,u=t.length+2*r,h=Math.floor(.1*e),l=u/e,c=(o||h)*l,f=(i||h)*l,d=null==a?t.length/2-c/2:a*l,g=null==s?t.length/2-f/2:s*l,v=null;if(n.excavate){var m=Math.floor(d),p=Math.floor(g);v={x:m,y:p,w:Math.ceil(c+d-m),h:Math.ceil(f+g-p)}}return{x:d,y:g,h:f,w:c,excavation:v}}function l(t,e){return t.slice().map((function(t,r){return e.y>r||r>=e.y+e.h?t:t.map((function(t,r){return(e.x>r||r>=e.x+e.w)&&t}))}))}var c={value:{type:String,required:!0,default:""},size:{type:Number,default:100},level:{type:String,default:"L",validator:function(t){return s(t)}},background:{type:String,default:"#fff"},foreground:{type:String,default:"#000"},margin:{type:Number,required:!1,default:0},imageSettings:{type:Object,required:!1,default:function(){return{}}}},f=n(n({},c),{renderAs:{type:String,required:!1,default:"canvas",validator:function(t){return["canvas","svg"].indexOf(t)>-1}}}),d=e.defineComponent({name:"QRCodeSvg",props:c,setup:function(t){var r,a=e.ref(0),s=e.ref(""),c=function(){var e=t.margin,n=o.QrCode.encodeText(t.value,i[t.level]).getModules();if(a.value=n.length+2*e,t.imageSettings.src){var c=h(n,t.size,e,t.imageSettings);r={x:c.x+e,y:c.y+e,width:c.w,height:c.h},c.excavation&&(n=l(n,c.excavation))}s.value=u(n,e)};return c(),e.onUpdated(c),function(){return e.h("svg",{width:t.size,height:t.size,"shape-rendering":"crispEdges",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 ".concat(a.value," ").concat(a.value)},[e.h("path",{fill:t.background,d:"M0,0 h".concat(a.value,"v").concat(a.value,"H0z")}),e.h("path",{fill:t.foreground,d:s.value}),t.imageSettings.src&&e.h("image",n({href:t.imageSettings.src},r))])}}}),g=e.defineComponent({name:"QRCodeCanvas",props:c,setup:function(t,r){var s=e.ref(null),c=e.ref(null),f=function(){var e=t.value,r=t.level,n=t.size,f=t.margin,d=t.background,g=t.foreground,v=s.value;if(v){var m=v.getContext("2d");if(m){var p=o.QrCode.encodeText(e,i[r]).getModules(),E=p.length+2*f,w=c.value,M={x:0,y:0,width:0,height:0},C=t.imageSettings.src&&null!=w&&0!==w.naturalWidth&&0!==w.naturalHeight;if(C){var y=h(p,t.size,f,t.imageSettings);M={x:y.x+f,y:y.y+f,width:y.w,height:y.h},y.excavation&&(p=l(p,y.excavation))}var R=window.devicePixelRatio||1,N=n/E*R;v.height=v.width=n*R,m.scale(N,N),m.fillStyle=d,m.fillRect(0,0,E,E),m.fillStyle=g,a?m.fill(new Path2D(u(p,f))):p.forEach((function(t,e){t.forEach((function(t,r){t&&m.fillRect(r+f,e+f,1,1)}))})),C&&m.drawImage(w,M.x,M.y,M.width,M.height)}}};e.onMounted(f),e.onUpdated(f);var d=r.attrs.style;return function(){return e.h(e.Fragment,[e.h("canvas",n(n({},r.attrs),{ref:s,style:n(n({},d),{width:"".concat(t.size,"px"),height:"".concat(t.size,"px")})})),t.imageSettings.src&&e.h("img",{ref:c,src:t.imageSettings.src,style:{display:"none"},onLoad:f})])}}}),v=e.defineComponent({name:"Qrcode",render:function(){var t=this.$props,r=t.renderAs,n=t.value,o=t.level,i=t.background,a=t.foreground,u=t.imageSettings,h=t.size>>>0,l=t.margin>>>0,c=s(o)?o:"L";return e.h("svg"===r?d:g,{value:n,size:h,margin:l,level:c,background:i,foreground:a,imageSettings:u})},props:f});t.QrcodeCanvas=g,t.QrcodeSvg=d,t.default=v,Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -1,11 +1,13 @@
1
1
  /*!
2
- * qrcode.vue v3.4.1
3
- * A Vue.js component to generate QRCode.
4
- * © 2017-2023 @scopewu(https://github.com/scopewu)
2
+ * qrcode.vue v3.5.0
3
+ * A Vue.js component to generate QRCode. Both support Vue 2 and Vue 3
4
+ * © 2017-PRESENT @scopewu(https://github.com/scopewu)
5
5
  * MIT License.
6
6
  */
7
7
  'use strict';
8
8
 
9
+ Object.defineProperty(exports, '__esModule', { value: true });
10
+
9
11
  var vue = require('vue');
10
12
 
11
13
  /******************************************************************************
@@ -525,8 +527,7 @@ var qrcodegen;
525
527
  return [];
526
528
  else {
527
529
  var numAlign = Math.floor(this.version / 7) + 2;
528
- var step = (this.version == 32) ? 26 :
529
- Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
530
+ var step = Math.floor((this.version * 8 + numAlign * 3 + 5) / (numAlign * 4 - 4)) * 2;
530
531
  var result = [6];
531
532
  for (var pos = this.size - 7; result.length < numAlign; pos -= step)
532
533
  result.splice(1, 0, pos);
@@ -652,17 +653,17 @@ var qrcodegen;
652
653
  QrCode.ECC_CODEWORDS_PER_BLOCK = [
653
654
  // Version: (note that index 0 is for padding, and is set to an illegal value)
654
655
  //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
655
- [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
656
- [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
657
- [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
656
+ [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Low
657
+ [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28], // Medium
658
+ [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Quartile
658
659
  [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // High
659
660
  ];
660
661
  QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
661
662
  // Version: (note that index 0 is for padding, and is set to an illegal value)
662
663
  //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
663
- [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
664
- [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
665
- [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
664
+ [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25], // Low
665
+ [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49], // Medium
666
+ [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68], // Quartile
666
667
  [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81], // High
667
668
  ];
668
669
  return QrCode;
@@ -908,7 +909,7 @@ var qrcodegen;
908
909
  })(qrcodegen || (qrcodegen = {}));
909
910
  var QR = qrcodegen;
910
911
 
911
- var defaultErrorCorrectLevel = 'H';
912
+ var defaultErrorCorrectLevel = 'L';
912
913
  var ErrorCorrectLevelMap = {
913
914
  L: QR.QrCode.Ecc.LOW,
914
915
  M: QR.QrCode.Ecc.MEDIUM,
@@ -965,6 +966,38 @@ function generatePath(modules, margin) {
965
966
  });
966
967
  return ops.join('');
967
968
  }
969
+ function getImageSettings(cells, size, margin, imageSettings) {
970
+ var width = imageSettings.width, height = imageSettings.height, imageX = imageSettings.x, imageY = imageSettings.y;
971
+ var numCells = cells.length + margin * 2;
972
+ var defaultSize = Math.floor(size * 0.1);
973
+ var scale = numCells / size;
974
+ var w = (width || defaultSize) * scale;
975
+ var h = (height || defaultSize) * scale;
976
+ var x = imageX == null ? cells.length / 2 - w / 2 : imageX * scale;
977
+ var y = imageY == null ? cells.length / 2 - h / 2 : imageY * scale;
978
+ var excavation = null;
979
+ if (imageSettings.excavate) {
980
+ var floorX = Math.floor(x);
981
+ var floorY = Math.floor(y);
982
+ var ceilW = Math.ceil(w + x - floorX);
983
+ var ceilH = Math.ceil(h + y - floorY);
984
+ excavation = { x: floorX, y: floorY, w: ceilW, h: ceilH };
985
+ }
986
+ return { x: x, y: y, h: h, w: w, excavation: excavation };
987
+ }
988
+ function excavateModules(modules, excavation) {
989
+ return modules.slice().map(function (row, y) {
990
+ if (y < excavation.y || y >= excavation.y + excavation.h) {
991
+ return row;
992
+ }
993
+ return row.map(function (cell, x) {
994
+ if (x < excavation.x || x >= excavation.x + excavation.w) {
995
+ return cell;
996
+ }
997
+ return false;
998
+ });
999
+ });
1000
+ }
968
1001
  var QRCodeProps = {
969
1002
  value: {
970
1003
  type: String,
@@ -993,6 +1026,11 @@ var QRCodeProps = {
993
1026
  required: false,
994
1027
  default: 0,
995
1028
  },
1029
+ imageSettings: {
1030
+ type: Object,
1031
+ required: false,
1032
+ default: function () { return ({}); },
1033
+ },
996
1034
  };
997
1035
  var QRCodeVueProps = __assign(__assign({}, QRCodeProps), { renderAs: {
998
1036
  type: String,
@@ -1000,16 +1038,29 @@ var QRCodeVueProps = __assign(__assign({}, QRCodeProps), { renderAs: {
1000
1038
  default: 'canvas',
1001
1039
  validator: function (as) { return ['canvas', 'svg'].indexOf(as) > -1; },
1002
1040
  } });
1003
- var QRCodeSvg = vue.defineComponent({
1041
+ var QrcodeSvg = vue.defineComponent({
1004
1042
  name: 'QRCodeSvg',
1005
1043
  props: QRCodeProps,
1006
1044
  setup: function (props) {
1007
1045
  var numCells = vue.ref(0);
1008
1046
  var fgPath = vue.ref('');
1047
+ var imageProps;
1009
1048
  var generate = function () {
1010
1049
  var value = props.value, level = props.level, margin = props.margin;
1011
1050
  var cells = QR.QrCode.encodeText(value, ErrorCorrectLevelMap[level]).getModules();
1012
1051
  numCells.value = cells.length + margin * 2;
1052
+ if (props.imageSettings.src) {
1053
+ var imageSettings = getImageSettings(cells, props.size, margin, props.imageSettings);
1054
+ imageProps = {
1055
+ x: imageSettings.x + margin,
1056
+ y: imageSettings.y + margin,
1057
+ width: imageSettings.w,
1058
+ height: imageSettings.h,
1059
+ };
1060
+ if (imageSettings.excavation) {
1061
+ cells = excavateModules(cells, imageSettings.excavation);
1062
+ }
1063
+ }
1013
1064
  // Drawing strategy: instead of a rect per module, we're going to create a
1014
1065
  // single path for the dark modules and layer that on top of a light rect,
1015
1066
  // for a total of 2 DOM nodes. We pay a bit more in string concat but that's
@@ -1032,14 +1083,16 @@ var QRCodeSvg = vue.defineComponent({
1032
1083
  d: "M0,0 h".concat(numCells.value, "v").concat(numCells.value, "H0z"),
1033
1084
  }),
1034
1085
  vue.h('path', { fill: props.foreground, d: fgPath.value }),
1086
+ props.imageSettings.src && vue.h('image', __assign({ href: props.imageSettings.src }, imageProps)),
1035
1087
  ]); };
1036
1088
  },
1037
1089
  });
1038
- var QRCodeCanvas = vue.defineComponent({
1090
+ var QrcodeCanvas = vue.defineComponent({
1039
1091
  name: 'QRCodeCanvas',
1040
1092
  props: QRCodeProps,
1041
- setup: function (props) {
1093
+ setup: function (props, ctx) {
1042
1094
  var canvasEl = vue.ref(null);
1095
+ var imageRef = vue.ref(null);
1043
1096
  var generate = function () {
1044
1097
  var value = props.value, level = props.level, size = props.size, margin = props.margin, background = props.background, foreground = props.foreground;
1045
1098
  var canvas = canvasEl.value;
@@ -1052,6 +1105,21 @@ var QRCodeCanvas = vue.defineComponent({
1052
1105
  }
1053
1106
  var cells = QR.QrCode.encodeText(value, ErrorCorrectLevelMap[level]).getModules();
1054
1107
  var numCells = cells.length + margin * 2;
1108
+ var image = imageRef.value;
1109
+ var imageProps = { x: 0, y: 0, width: 0, height: 0 };
1110
+ var showImage = props.imageSettings.src && image != null && image.naturalWidth !== 0 && image.naturalHeight !== 0;
1111
+ if (showImage) {
1112
+ var imageSettings = getImageSettings(cells, props.size, margin, props.imageSettings);
1113
+ imageProps = {
1114
+ x: imageSettings.x + margin,
1115
+ y: imageSettings.y + margin,
1116
+ width: imageSettings.w,
1117
+ height: imageSettings.h,
1118
+ };
1119
+ if (imageSettings.excavation) {
1120
+ cells = excavateModules(cells, imageSettings.excavation);
1121
+ }
1122
+ }
1055
1123
  var devicePixelRatio = window.devicePixelRatio || 1;
1056
1124
  var scale = (size / numCells) * devicePixelRatio;
1057
1125
  canvas.height = canvas.width = size * devicePixelRatio;
@@ -1071,25 +1139,36 @@ var QRCodeCanvas = vue.defineComponent({
1071
1139
  });
1072
1140
  });
1073
1141
  }
1142
+ if (showImage) {
1143
+ ctx.drawImage(image, imageProps.x, imageProps.y, imageProps.width, imageProps.height);
1144
+ }
1074
1145
  };
1075
1146
  vue.onMounted(generate);
1076
1147
  vue.onUpdated(generate);
1077
- return function () { return vue.h('canvas', {
1078
- ref: canvasEl,
1079
- style: { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") },
1080
- }); };
1148
+ var style = ctx.attrs.style;
1149
+ return function () { return vue.h(vue.Fragment, [
1150
+ vue.h('canvas', __assign(__assign({}, ctx.attrs), { ref: canvasEl, style: __assign(__assign({}, style), { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }) })),
1151
+ props.imageSettings.src && vue.h('img', {
1152
+ ref: imageRef,
1153
+ src: props.imageSettings.src,
1154
+ style: { display: 'none' },
1155
+ onLoad: generate,
1156
+ })
1157
+ ]); };
1081
1158
  },
1082
1159
  });
1083
1160
  var QrcodeVue = vue.defineComponent({
1084
1161
  name: 'Qrcode',
1085
1162
  render: function () {
1086
- var _a = this.$props, renderAs = _a.renderAs, value = _a.value, _size = _a.size, _margin = _a.margin, _level = _a.level, background = _a.background, foreground = _a.foreground;
1163
+ var _a = this.$props, renderAs = _a.renderAs, value = _a.value, _size = _a.size, _margin = _a.margin, _level = _a.level, background = _a.background, foreground = _a.foreground, imageSettings = _a.imageSettings;
1087
1164
  var size = _size >>> 0;
1088
1165
  var margin = _margin >>> 0;
1089
1166
  var level = validErrorCorrectLevel(_level) ? _level : defaultErrorCorrectLevel;
1090
- return vue.h(renderAs === 'svg' ? QRCodeSvg : QRCodeCanvas, { value: value, size: size, margin: margin, level: level, background: background, foreground: foreground });
1167
+ return vue.h(renderAs === 'svg' ? QrcodeSvg : QrcodeCanvas, { value: value, size: size, margin: margin, level: level, background: background, foreground: foreground, imageSettings: imageSettings });
1091
1168
  },
1092
1169
  props: QRCodeVueProps,
1093
1170
  });
1094
1171
 
1095
- module.exports = QrcodeVue;
1172
+ exports.QrcodeCanvas = QrcodeCanvas;
1173
+ exports.QrcodeSvg = QrcodeSvg;
1174
+ exports.default = QrcodeVue;
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * qrcode.vue v3.4.1
3
- * A Vue.js component to generate QRCode.
4
- * © 2017-2023 @scopewu(https://github.com/scopewu)
2
+ * qrcode.vue v3.5.0
3
+ * A Vue.js component to generate QRCode. Both support Vue 2 and Vue 3
4
+ * © 2017-PRESENT @scopewu(https://github.com/scopewu)
5
5
  * MIT License.
6
6
  */
7
- import { defineComponent, ref, onUpdated, h, onMounted } from 'vue';
7
+ import { defineComponent, ref, onUpdated, h, onMounted, Fragment } from 'vue';
8
8
 
9
9
  /******************************************************************************
10
10
  Copyright (c) Microsoft Corporation.
@@ -523,8 +523,7 @@ var qrcodegen;
523
523
  return [];
524
524
  else {
525
525
  var numAlign = Math.floor(this.version / 7) + 2;
526
- var step = (this.version == 32) ? 26 :
527
- Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
526
+ var step = Math.floor((this.version * 8 + numAlign * 3 + 5) / (numAlign * 4 - 4)) * 2;
528
527
  var result = [6];
529
528
  for (var pos = this.size - 7; result.length < numAlign; pos -= step)
530
529
  result.splice(1, 0, pos);
@@ -650,17 +649,17 @@ var qrcodegen;
650
649
  QrCode.ECC_CODEWORDS_PER_BLOCK = [
651
650
  // Version: (note that index 0 is for padding, and is set to an illegal value)
652
651
  //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
653
- [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
654
- [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
655
- [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
652
+ [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Low
653
+ [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28], // Medium
654
+ [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Quartile
656
655
  [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // High
657
656
  ];
658
657
  QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
659
658
  // Version: (note that index 0 is for padding, and is set to an illegal value)
660
659
  //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
661
- [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
662
- [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
663
- [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
660
+ [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25], // Low
661
+ [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49], // Medium
662
+ [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68], // Quartile
664
663
  [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81], // High
665
664
  ];
666
665
  return QrCode;
@@ -906,7 +905,7 @@ var qrcodegen;
906
905
  })(qrcodegen || (qrcodegen = {}));
907
906
  var QR = qrcodegen;
908
907
 
909
- var defaultErrorCorrectLevel = 'H';
908
+ var defaultErrorCorrectLevel = 'L';
910
909
  var ErrorCorrectLevelMap = {
911
910
  L: QR.QrCode.Ecc.LOW,
912
911
  M: QR.QrCode.Ecc.MEDIUM,
@@ -963,6 +962,38 @@ function generatePath(modules, margin) {
963
962
  });
964
963
  return ops.join('');
965
964
  }
965
+ function getImageSettings(cells, size, margin, imageSettings) {
966
+ var width = imageSettings.width, height = imageSettings.height, imageX = imageSettings.x, imageY = imageSettings.y;
967
+ var numCells = cells.length + margin * 2;
968
+ var defaultSize = Math.floor(size * 0.1);
969
+ var scale = numCells / size;
970
+ var w = (width || defaultSize) * scale;
971
+ var h = (height || defaultSize) * scale;
972
+ var x = imageX == null ? cells.length / 2 - w / 2 : imageX * scale;
973
+ var y = imageY == null ? cells.length / 2 - h / 2 : imageY * scale;
974
+ var excavation = null;
975
+ if (imageSettings.excavate) {
976
+ var floorX = Math.floor(x);
977
+ var floorY = Math.floor(y);
978
+ var ceilW = Math.ceil(w + x - floorX);
979
+ var ceilH = Math.ceil(h + y - floorY);
980
+ excavation = { x: floorX, y: floorY, w: ceilW, h: ceilH };
981
+ }
982
+ return { x: x, y: y, h: h, w: w, excavation: excavation };
983
+ }
984
+ function excavateModules(modules, excavation) {
985
+ return modules.slice().map(function (row, y) {
986
+ if (y < excavation.y || y >= excavation.y + excavation.h) {
987
+ return row;
988
+ }
989
+ return row.map(function (cell, x) {
990
+ if (x < excavation.x || x >= excavation.x + excavation.w) {
991
+ return cell;
992
+ }
993
+ return false;
994
+ });
995
+ });
996
+ }
966
997
  var QRCodeProps = {
967
998
  value: {
968
999
  type: String,
@@ -991,6 +1022,11 @@ var QRCodeProps = {
991
1022
  required: false,
992
1023
  default: 0,
993
1024
  },
1025
+ imageSettings: {
1026
+ type: Object,
1027
+ required: false,
1028
+ default: function () { return ({}); },
1029
+ },
994
1030
  };
995
1031
  var QRCodeVueProps = __assign(__assign({}, QRCodeProps), { renderAs: {
996
1032
  type: String,
@@ -998,16 +1034,29 @@ var QRCodeVueProps = __assign(__assign({}, QRCodeProps), { renderAs: {
998
1034
  default: 'canvas',
999
1035
  validator: function (as) { return ['canvas', 'svg'].indexOf(as) > -1; },
1000
1036
  } });
1001
- var QRCodeSvg = defineComponent({
1037
+ var QrcodeSvg = defineComponent({
1002
1038
  name: 'QRCodeSvg',
1003
1039
  props: QRCodeProps,
1004
1040
  setup: function (props) {
1005
1041
  var numCells = ref(0);
1006
1042
  var fgPath = ref('');
1043
+ var imageProps;
1007
1044
  var generate = function () {
1008
1045
  var value = props.value, level = props.level, margin = props.margin;
1009
1046
  var cells = QR.QrCode.encodeText(value, ErrorCorrectLevelMap[level]).getModules();
1010
1047
  numCells.value = cells.length + margin * 2;
1048
+ if (props.imageSettings.src) {
1049
+ var imageSettings = getImageSettings(cells, props.size, margin, props.imageSettings);
1050
+ imageProps = {
1051
+ x: imageSettings.x + margin,
1052
+ y: imageSettings.y + margin,
1053
+ width: imageSettings.w,
1054
+ height: imageSettings.h,
1055
+ };
1056
+ if (imageSettings.excavation) {
1057
+ cells = excavateModules(cells, imageSettings.excavation);
1058
+ }
1059
+ }
1011
1060
  // Drawing strategy: instead of a rect per module, we're going to create a
1012
1061
  // single path for the dark modules and layer that on top of a light rect,
1013
1062
  // for a total of 2 DOM nodes. We pay a bit more in string concat but that's
@@ -1030,14 +1079,16 @@ var QRCodeSvg = defineComponent({
1030
1079
  d: "M0,0 h".concat(numCells.value, "v").concat(numCells.value, "H0z"),
1031
1080
  }),
1032
1081
  h('path', { fill: props.foreground, d: fgPath.value }),
1082
+ props.imageSettings.src && h('image', __assign({ href: props.imageSettings.src }, imageProps)),
1033
1083
  ]); };
1034
1084
  },
1035
1085
  });
1036
- var QRCodeCanvas = defineComponent({
1086
+ var QrcodeCanvas = defineComponent({
1037
1087
  name: 'QRCodeCanvas',
1038
1088
  props: QRCodeProps,
1039
- setup: function (props) {
1089
+ setup: function (props, ctx) {
1040
1090
  var canvasEl = ref(null);
1091
+ var imageRef = ref(null);
1041
1092
  var generate = function () {
1042
1093
  var value = props.value, level = props.level, size = props.size, margin = props.margin, background = props.background, foreground = props.foreground;
1043
1094
  var canvas = canvasEl.value;
@@ -1050,6 +1101,21 @@ var QRCodeCanvas = defineComponent({
1050
1101
  }
1051
1102
  var cells = QR.QrCode.encodeText(value, ErrorCorrectLevelMap[level]).getModules();
1052
1103
  var numCells = cells.length + margin * 2;
1104
+ var image = imageRef.value;
1105
+ var imageProps = { x: 0, y: 0, width: 0, height: 0 };
1106
+ var showImage = props.imageSettings.src && image != null && image.naturalWidth !== 0 && image.naturalHeight !== 0;
1107
+ if (showImage) {
1108
+ var imageSettings = getImageSettings(cells, props.size, margin, props.imageSettings);
1109
+ imageProps = {
1110
+ x: imageSettings.x + margin,
1111
+ y: imageSettings.y + margin,
1112
+ width: imageSettings.w,
1113
+ height: imageSettings.h,
1114
+ };
1115
+ if (imageSettings.excavation) {
1116
+ cells = excavateModules(cells, imageSettings.excavation);
1117
+ }
1118
+ }
1053
1119
  var devicePixelRatio = window.devicePixelRatio || 1;
1054
1120
  var scale = (size / numCells) * devicePixelRatio;
1055
1121
  canvas.height = canvas.width = size * devicePixelRatio;
@@ -1069,25 +1135,34 @@ var QRCodeCanvas = defineComponent({
1069
1135
  });
1070
1136
  });
1071
1137
  }
1138
+ if (showImage) {
1139
+ ctx.drawImage(image, imageProps.x, imageProps.y, imageProps.width, imageProps.height);
1140
+ }
1072
1141
  };
1073
1142
  onMounted(generate);
1074
1143
  onUpdated(generate);
1075
- return function () { return h('canvas', {
1076
- ref: canvasEl,
1077
- style: { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") },
1078
- }); };
1144
+ var style = ctx.attrs.style;
1145
+ return function () { return h(Fragment, [
1146
+ h('canvas', __assign(__assign({}, ctx.attrs), { ref: canvasEl, style: __assign(__assign({}, style), { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }) })),
1147
+ props.imageSettings.src && h('img', {
1148
+ ref: imageRef,
1149
+ src: props.imageSettings.src,
1150
+ style: { display: 'none' },
1151
+ onLoad: generate,
1152
+ })
1153
+ ]); };
1079
1154
  },
1080
1155
  });
1081
1156
  var QrcodeVue = defineComponent({
1082
1157
  name: 'Qrcode',
1083
1158
  render: function () {
1084
- var _a = this.$props, renderAs = _a.renderAs, value = _a.value, _size = _a.size, _margin = _a.margin, _level = _a.level, background = _a.background, foreground = _a.foreground;
1159
+ var _a = this.$props, renderAs = _a.renderAs, value = _a.value, _size = _a.size, _margin = _a.margin, _level = _a.level, background = _a.background, foreground = _a.foreground, imageSettings = _a.imageSettings;
1085
1160
  var size = _size >>> 0;
1086
1161
  var margin = _margin >>> 0;
1087
1162
  var level = validErrorCorrectLevel(_level) ? _level : defaultErrorCorrectLevel;
1088
- return h(renderAs === 'svg' ? QRCodeSvg : QRCodeCanvas, { value: value, size: size, margin: margin, level: level, background: background, foreground: foreground });
1163
+ return h(renderAs === 'svg' ? QrcodeSvg : QrcodeCanvas, { value: value, size: size, margin: margin, level: level, background: background, foreground: foreground, imageSettings: imageSettings });
1089
1164
  },
1090
1165
  props: QRCodeVueProps,
1091
1166
  });
1092
1167
 
1093
- export { QrcodeVue as default };
1168
+ export { QrcodeCanvas, QrcodeSvg, QrcodeVue as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qrcode.vue",
3
- "version": "3.4.1",
4
- "description": "A Vue.js component to generate QRCode.",
3
+ "version": "3.5.0",
4
+ "description": "A Vue.js component to generate QRCode. Both support Vue 2 and Vue 3",
5
5
  "type": "module",
6
6
  "main": "./dist/qrcode.vue.cjs.js",
7
7
  "module": "./dist/qrcode.vue.esm.js",
@@ -18,7 +18,7 @@
18
18
  "./package": "./package.json"
19
19
  },
20
20
  "scripts": {
21
- "start": "webpack serve --config webpack.config.js --mode=development",
21
+ "dev": "rsbuild dev",
22
22
  "build": "rollup -c"
23
23
  },
24
24
  "repository": {
@@ -50,18 +50,11 @@
50
50
  },
51
51
  "dependencies": {},
52
52
  "devDependencies": {
53
- "@rollup/plugin-terser": "^0.4.3",
54
- "@vue/compiler-sfc": "^3.3.4",
55
- "@vue/server-renderer": "^3.3.4",
56
- "html-webpack-plugin": "^5.5.3",
57
- "rollup": "^3.25.3",
58
- "rollup-plugin-typescript2": "^0.35.0",
59
- "ts-loader": "^9.4.3",
60
- "typescript": "^5.1.3",
61
- "vue": "^3.3.4",
62
- "vue-loader": "^17.2.2",
63
- "webpack": "^5.88.0",
64
- "webpack-cli": "^5.1.4",
65
- "webpack-dev-server": "^4.15.1"
53
+ "@rollup/plugin-terser": "^0.4.4",
54
+ "@rsbuild/core": "^1.0.7",
55
+ "rollup": "^4.22.4",
56
+ "rollup-plugin-typescript2": "^0.36.0",
57
+ "typescript": "^5.6.2",
58
+ "vue": "^3.5.8"
66
59
  }
67
60
  }