qrcode.vue 3.3.4 → 3.4.1
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.
- package/CHANGELOG.md +12 -0
- package/README-zh_cn.md +16 -0
- package/README.md +16 -0
- package/dist/index.d.ts +81 -80
- package/dist/qrcode.vue.browser.js +1047 -1420
- package/dist/qrcode.vue.browser.min.js +2 -2
- package/dist/qrcode.vue.cjs.js +1047 -1420
- package/dist/qrcode.vue.esm.js +1047 -1420
- package/dist/qrcodegen.d.ts +95 -0
- package/package.json +15 -19
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* qrcode.vue v3.
|
|
2
|
+
* qrcode.vue v3.4.1
|
|
3
3
|
* A Vue.js component to generate QRCode.
|
|
4
4
|
* © 2017-2023 @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=function(){return e=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},e.apply(this,arguments)},r={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},n=r;function o(t){this.mode=n.MODE_8BIT_BYTE,this.data=t}o.prototype={getLength:function(t){return this.data.length},write:function(t){for(var e=0;this.data.length>e;e++)t.put(this.data.charCodeAt(e),8)}};var i=o,a={L:1,M:0,Q:3,H:2},u=a;function s(t,e){this.totalCount=t,this.dataCount=e}s.RS_BLOCK_TABLE=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],s.getRSBlocks=function(t,e){var r=s.getRsBlockTable(t,e);if(null==r)throw Error("bad rs block @ typeNumber:"+t+"/errorCorrectLevel:"+e);for(var n=r.length/3,o=[],i=0;n>i;i++)for(var a=r[3*i+0],u=r[3*i+1],h=r[3*i+2],l=0;a>l;l++)o.push(new s(u,h));return o},s.getRsBlockTable=function(t,e){switch(e){case u.L:return s.RS_BLOCK_TABLE[4*(t-1)+0];case u.M:return s.RS_BLOCK_TABLE[4*(t-1)+1];case u.Q:return s.RS_BLOCK_TABLE[4*(t-1)+2];case u.H:return s.RS_BLOCK_TABLE[4*(t-1)+3];default:return}};var h=s;function l(){this.buffer=[],this.length=0}l.prototype={get:function(t){return 1==(this.buffer[Math.floor(t/8)]>>>7-t%8&1)},put:function(t,e){for(var r=0;e>r;r++)this.putBit(1==(t>>>e-r-1&1))},getLengthInBits:function(){return this.length},putBit:function(t){var e=Math.floor(this.length/8);this.buffer.length>e||this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}};for(var f=l,g={glog:function(t){if(1>t)throw Error("glog("+t+")");return g.LOG_TABLE[t]},gexp:function(t){for(;0>t;)t+=255;for(;t>=256;)t-=255;return g.EXP_TABLE[t]},EXP_TABLE:Array(256),LOG_TABLE:Array(256)},c=0;8>c;c++)g.EXP_TABLE[c]=1<<c;for(c=8;256>c;c++)g.EXP_TABLE[c]=g.EXP_TABLE[c-4]^g.EXP_TABLE[c-5]^g.EXP_TABLE[c-6]^g.EXP_TABLE[c-8];for(c=0;255>c;c++)g.LOG_TABLE[g.EXP_TABLE[c]]=c;var d=g,v=d;function m(t,e){if(null==t.length)throw Error(t.length+"/"+e);for(var r=0;t.length>r&&0==t[r];)r++;this.num=Array(t.length-r+e);for(var n=0;t.length-r>n;n++)this.num[n]=t[n+r]}m.prototype={get:function(t){return this.num[t]},getLength:function(){return this.num.length},multiply:function(t){for(var e=Array(this.getLength()+t.getLength()-1),r=0;r<this.getLength();r++)for(var n=0;n<t.getLength();n++)e[r+n]^=v.gexp(v.glog(this.get(r))+v.glog(t.get(n)));return new m(e,0)},mod:function(t){if(0>this.getLength()-t.getLength())return this;for(var e=v.glog(this.get(0))-v.glog(t.get(0)),r=Array(this.getLength()),n=0;n<this.getLength();n++)r[n]=this.get(n);for(n=0;n<t.getLength();n++)r[n]^=v.gexp(v.glog(t.get(n))+e);return new m(r,0).mod(t)}};var p=r,C=m,B=d,E=0,L=1,D=2,y=3,A=4,P=5,_=6,T=7,M={PATTERN_POSITION_TABLE:[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],G15:1335,G18:7973,G15_MASK:21522,getBCHTypeInfo:function(t){for(var e=t<<10;M.getBCHDigit(e)-M.getBCHDigit(M.G15)>=0;)e^=M.G15<<M.getBCHDigit(e)-M.getBCHDigit(M.G15);return(t<<10|e)^M.G15_MASK},getBCHTypeNumber:function(t){for(var e=t<<12;M.getBCHDigit(e)-M.getBCHDigit(M.G18)>=0;)e^=M.G18<<M.getBCHDigit(e)-M.getBCHDigit(M.G18);return t<<12|e},getBCHDigit:function(t){for(var e=0;0!=t;)e++,t>>>=1;return e},getPatternPosition:function(t){return M.PATTERN_POSITION_TABLE[t-1]},getMask:function(t,e,r){switch(t){case E:return(e+r)%2==0;case L:return e%2==0;case D:return r%3==0;case y:return(e+r)%3==0;case A:return(Math.floor(e/2)+Math.floor(r/3))%2==0;case P:return e*r%2+e*r%3==0;case _:return(e*r%2+e*r%3)%2==0;case T:return(e*r%3+(e+r)%2)%2==0;default:throw Error("bad maskPattern:"+t)}},getErrorCorrectPolynomial:function(t){for(var e=new C([1],0),r=0;t>r;r++)e=e.multiply(new C([1,B.gexp(r)],0));return e},getLengthInBits:function(t,e){if(e>=1&&10>e)switch(t){case p.MODE_NUMBER:return 10;case p.MODE_ALPHA_NUM:return 9;case p.MODE_8BIT_BYTE:case p.MODE_KANJI:return 8;default:throw Error("mode:"+t)}else if(27>e)switch(t){case p.MODE_NUMBER:return 12;case p.MODE_ALPHA_NUM:return 11;case p.MODE_8BIT_BYTE:return 16;case p.MODE_KANJI:return 10;default:throw Error("mode:"+t)}else{if(e>=41)throw Error("type:"+e);switch(t){case p.MODE_NUMBER:return 14;case p.MODE_ALPHA_NUM:return 13;case p.MODE_8BIT_BYTE:return 16;case p.MODE_KANJI:return 12;default:throw Error("mode:"+t)}}},getLostPoint:function(t){for(var e=t.getModuleCount(),r=0,n=0;e>n;n++)for(var o=0;e>o;o++){for(var i=0,a=t.isDark(n,o),u=-1;1>=u;u++)if(n+u>=0&&e>n+u)for(var s=-1;1>=s;s++)o+s>=0&&e>o+s&&(0==u&&0==s||a==t.isDark(n+u,o+s)&&i++);i>5&&(r+=3+i-5)}for(n=0;e-1>n;n++)for(o=0;e-1>o;o++){var h=0;t.isDark(n,o)&&h++,t.isDark(n+1,o)&&h++,t.isDark(n,o+1)&&h++,t.isDark(n+1,o+1)&&h++,0!=h&&4!=h||(r+=3)}for(n=0;e>n;n++)for(o=0;e-6>o;o++)t.isDark(n,o)&&!t.isDark(n,o+1)&&t.isDark(n,o+2)&&t.isDark(n,o+3)&&t.isDark(n,o+4)&&!t.isDark(n,o+5)&&t.isDark(n,o+6)&&(r+=40);for(o=0;e>o;o++)for(n=0;e-6>n;n++)t.isDark(n,o)&&!t.isDark(n+1,o)&&t.isDark(n+2,o)&&t.isDark(n+3,o)&&t.isDark(n+4,o)&&!t.isDark(n+5,o)&&t.isDark(n+6,o)&&(r+=40);var l=0;for(o=0;e>o;o++)for(n=0;e>n;n++)t.isDark(n,o)&&l++;return r+=10*(Math.abs(100*l/e/e-50)/5)}},k=i,b=h,w=f,O=M,I=m;function N(t,e){this.typeNumber=t,this.errorCorrectLevel=e,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}var S=N.prototype;S.addData=function(t){var e=new k(t);this.dataList.push(e),this.dataCache=null},S.isDark=function(t,e){if(0>t||t>=this.moduleCount||0>e||e>=this.moduleCount)throw Error(t+","+e);return this.modules[t][e]},S.getModuleCount=function(){return this.moduleCount},S.make=function(){if(1>this.typeNumber){var t=1;for(t=1;40>t;t++){for(var e=b.getRSBlocks(t,this.errorCorrectLevel),r=new w,n=0,o=0;e.length>o;o++)n+=e[o].dataCount;for(o=0;this.dataList.length>o;o++){var i=this.dataList[o];r.put(i.mode,4),r.put(i.getLength(),O.getLengthInBits(i.mode,t)),i.write(r)}if(r.getLengthInBits()<=8*n)break}this.typeNumber=t}this.makeImpl(!1,this.getBestMaskPattern())},S.makeImpl=function(t,e){this.moduleCount=4*this.typeNumber+17,this.modules=Array(this.moduleCount);for(var r=0;this.moduleCount>r;r++){this.modules[r]=Array(this.moduleCount);for(var n=0;this.moduleCount>n;n++)this.modules[r][n]=null}this.setupPositionProbePattern(0,0),this.setupPositionProbePattern(this.moduleCount-7,0),this.setupPositionProbePattern(0,this.moduleCount-7),this.setupPositionAdjustPattern(),this.setupTimingPattern(),this.setupTypeInfo(t,e),7>this.typeNumber||this.setupTypeNumber(t),null==this.dataCache&&(this.dataCache=N.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,e)},S.setupPositionProbePattern=function(t,e){for(var r=-1;7>=r;r++)if(t+r>-1&&this.moduleCount>t+r)for(var n=-1;7>=n;n++)e+n>-1&&this.moduleCount>e+n&&(this.modules[t+r][e+n]=!((0>r||r>6||0!=n&&6!=n)&&(0>n||n>6||0!=r&&6!=r)&&(2>r||r>4||2>n||n>4)))},S.getBestMaskPattern=function(){for(var t=0,e=0,r=0;8>r;r++){this.makeImpl(!0,r);var n=O.getLostPoint(this);(0==r||t>n)&&(t=n,e=r)}return e},S.createMovieClip=function(t,e,r){var n=t.createEmptyMovieClip(e,r);this.make();for(var o=0;this.modules.length>o;o++)for(var i=1*o,a=0;this.modules[o].length>a;a++){var u=1*a;this.modules[o][a]&&(n.beginFill(0,100),n.moveTo(u,i),n.lineTo(u+1,i),n.lineTo(u+1,i+1),n.lineTo(u,i+1),n.endFill())}return n},S.setupTimingPattern=function(){for(var t=8;this.moduleCount-8>t;t++)null==this.modules[t][6]&&(this.modules[t][6]=t%2==0);for(var e=8;this.moduleCount-8>e;e++)null==this.modules[6][e]&&(this.modules[6][e]=e%2==0)},S.setupPositionAdjustPattern=function(){for(var t=O.getPatternPosition(this.typeNumber),e=0;t.length>e;e++)for(var r=0;t.length>r;r++){var n=t[e],o=t[r];if(null==this.modules[n][o])for(var i=-2;2>=i;i++)for(var a=-2;2>=a;a++)this.modules[n+i][o+a]=-2==i||2==i||-2==a||2==a||0==i&&0==a}},S.setupTypeNumber=function(t){for(var e=O.getBCHTypeNumber(this.typeNumber),r=0;18>r;r++){var n=!t&&1==(e>>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=n}for(r=0;18>r;r++){n=!t&&1==(e>>r&1);this.modules[r%3+this.moduleCount-8-3][Math.floor(r/3)]=n}},S.setupTypeInfo=function(t,e){for(var r=O.getBCHTypeInfo(this.errorCorrectLevel<<3|e),n=0;15>n;n++){var o=!t&&1==(r>>n&1);6>n?this.modules[n][8]=o:8>n?this.modules[n+1][8]=o:this.modules[this.moduleCount-15+n][8]=o}for(n=0;15>n;n++){o=!t&&1==(r>>n&1);8>n?this.modules[8][this.moduleCount-n-1]=o:9>n?this.modules[8][15-n-1+1]=o:this.modules[8][15-n-1]=o}this.modules[this.moduleCount-8][8]=!t},S.mapData=function(t,e){for(var r=-1,n=this.moduleCount-1,o=7,i=0,a=this.moduleCount-1;a>0;a-=2)for(6==a&&a--;;){for(var u=0;2>u;u++)if(null==this.modules[n][a-u]){var s=!1;t.length>i&&(s=1==(t[i]>>>o&1)),O.getMask(e,n,a-u)&&(s=!s),this.modules[n][a-u]=s,-1==--o&&(i++,o=7)}if(0>(n+=r)||n>=this.moduleCount){n-=r,r=-r;break}}},N.PAD0=236,N.PAD1=17,N.createData=function(t,e,r){for(var n=b.getRSBlocks(t,e),o=new w,i=0;r.length>i;i++){var a=r[i];o.put(a.mode,4),o.put(a.getLength(),O.getLengthInBits(a.mode,t)),a.write(o)}var u=0;for(i=0;n.length>i;i++)u+=n[i].dataCount;if(o.getLengthInBits()>8*u)throw Error("code length overflow. ("+o.getLengthInBits()+">"+8*u+")");for(o.getLengthInBits()+4>8*u||o.put(0,4);o.getLengthInBits()%8!=0;)o.putBit(!1);for(;o.getLengthInBits()<8*u&&(o.put(N.PAD0,8),o.getLengthInBits()<8*u);)o.put(N.PAD1,8);return N.createBytes(o,n)},N.createBytes=function(t,e){for(var r=0,n=0,o=0,i=Array(e.length),a=Array(e.length),u=0;e.length>u;u++){var s=e[u].dataCount,h=e[u].totalCount-s;n=Math.max(n,s),o=Math.max(o,h),i[u]=Array(s);for(var l=0;i[u].length>l;l++)i[u][l]=255&t.buffer[l+r];r+=s;var f=O.getErrorCorrectPolynomial(h),g=new I(i[u],f.getLength()-1).mod(f);a[u]=Array(f.getLength()-1);for(l=0;a[u].length>l;l++){var c=l+g.getLength()-a[u].length;a[u][l]=0>c?0:g.get(c)}}var d=0;for(l=0;e.length>l;l++)d+=e[l].totalCount;var v=Array(d),m=0;for(l=0;n>l;l++)for(u=0;e.length>u;u++)i[u].length>l&&(v[m++]=i[u][l]);for(l=0;o>l;l++)for(u=0;e.length>u;u++)a[u].length>l&&(v[m++]=a[u][l]);return v};var H=N,R=function(){try{(new Path2D).addPath(new Path2D)}catch(t){return!1}return!0}();function x(t,e){var r=new H(-1,a[e]);return r.addData(function(t){for(var e="",r=0;t.length>r;r++){var n=t.charCodeAt(r);128>n?e+=String.fromCharCode(n):2048>n?(e+=String.fromCharCode(192|n>>6),e+=String.fromCharCode(128|63&n)):55296>n||n>=57344?(e+=String.fromCharCode(224|n>>12),e+=String.fromCharCode(128|n>>6&63),e+=String.fromCharCode(128|63&n)):(r++,n=65536+((1023&n)<<10|1023&t.charCodeAt(r)),e+=String.fromCharCode(240|n>>18),e+=String.fromCharCode(128|n>>12&63),e+=String.fromCharCode(128|n>>6&63),e+=String.fromCharCode(128|63&n))}return e}(t)),r.make(),r}function G(t){return t in a}function z(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 K={value:{type:String,required:!0,default:""},size:{type:Number,default:100},level:{type:String,default:"H",validator:function(t){return G(t)}},background:{type:String,default:"#fff"},foreground:{type:String,default:"#000"},margin:{type:Number,required:!1,default:0}},U=e(e({},K),{renderAs:{type:String,required:!1,default:"canvas",validator:function(t){return["canvas","svg"].indexOf(t)>-1}}}),X=t.defineComponent({name:"QRCodeSvg",props:K,setup:function(e){var r=t.ref(0),n=t.ref(""),o=function(){var t=e.margin,o=x(e.value,e.level).modules;r.value=o.length+2*t,n.value=z(o,t)};return o(),t.onUpdated(o),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:n.value})])}}}),j=t.defineComponent({name:"QRCodeCanvas",props:K,setup:function(e){var r=t.ref(null),n=function(){var t=e.size,n=e.margin,o=e.background,i=e.foreground,a=x(e.value,e.level).modules,u=a.length+2*n,s=r.value;if(s){var h=s.getContext("2d");if(h){var l=window.devicePixelRatio||1,f=t/u*l;s.height=s.width=t*l,h.scale(f,f),h.fillStyle=o,h.fillRect(0,0,u,u),h.fillStyle=i,R?h.fill(new Path2D(z(a,n))):a.forEach((function(t,e){t.forEach((function(t,r){t&&h.fillRect(r+n,e+n,1,1)}))}))}}};return t.onMounted(n),t.onUpdated(n),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,a=e.foreground,u=e.size>>>0,s=e.margin>>>0,h=G(o)?o:"H";return t.h("svg"===r?X:j,{value:n,size:u,margin:s,level:h,background:i,foreground:a})},props:U})}));
|
|
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})}));
|