UNPKG

awesome-qr

Version:

An awesome QR code generator written in JavaScript.

1 lines 31.3 kB
var AwesomeQRCode,GIFE;require(["./gif"],function(e){GIFE=e}),function e(t,r,a){function i(o,s){if(!r[o]){if(!t[o]){var l="function"==typeof require&&require;if(!s&&l)return l(o,!0);if(n)return n(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=r[o]={exports:{}};t[o][0].call(h.exports,function(e){var r=t[o][1][e];return i(r||e)},h,h.exports,e,t,r,a)}return r[o].exports}for(var n="function"==typeof require&&require,o=0;o<a.length;o++)i(a[o]);return i}({1:[function(e,t,r){function a(e){this.data=e,this.pos=0}a.prototype.readByte=function(){return this.data[this.pos++]},a.prototype.peekByte=function(){return this.data[this.pos]},a.prototype.readBytes=function(e){for(var t=new Array(e),r=0;r<e;r++)t[r]=this.readByte();return t},a.prototype.peekBytes=function(e){for(var t=new Array(e),r=0;r<e;r++)t[r]=this.data[this.pos+r];return t},a.prototype.readString=function(e){for(var t="",r=0;r<e;r++)t+=String.fromCharCode(this.readByte());return t},a.prototype.readBitArray=function(){for(var e=[],t=this.readByte(),r=7;r>=0;r--)e.push(!!(t&1<<r));return e},a.prototype.readUnsigned=function(e){var t=this.readBytes(2);return e?(t[1]<<8)+t[0]:(t[0]<<8)+t[1]},t.exports=a},{}],2:[function(e,t,r){function a(e){this.stream=new n(e),this.output={}}function i(e){return e.reduce(function(e,t){return 2*e+t},0)}var n=e("./bytestream");a.prototype.parse=function(e){return this.parseParts(this.output,e),this.output},a.prototype.parseParts=function(e,t){for(var r=0;r<t.length;r++){var a=t[r];this.parsePart(e,a)}},a.prototype.parsePart=function(e,t){var r,a=t.label;if(!t.requires||t.requires(this.stream,this.output,e))if(t.loop){for(var i=[];t.loop(this.stream);){var n={};this.parseParts(n,t.parts),i.push(n)}e[a]=i}else t.parts?(r={},this.parseParts(r,t.parts),e[a]=r):t.parser?(r=t.parser(this.stream,this.output,e),t.skip||(e[a]=r)):t.bits&&(e[a]=this.parseBits(t.bits))},a.prototype.parseBits=function(e){var t={},r=this.stream.readBitArray();for(var a in e){var n=e[a];n.length?t[a]=i(r.slice(n.index,n.index+n.length)):t[a]=r[n.index]}return t},t.exports=a},{"./bytestream":1}],3:[function(e,t,r){var a={readByte:function(){return function(e){return e.readByte()}},readBytes:function(e){return function(t){return t.readBytes(e)}},readString:function(e){return function(t){return t.readString(e)}},readUnsigned:function(e){return function(t){return t.readUnsigned(e)}},readArray:function(e,t){return function(r,a,i){for(var n=t(r,a,i),o=new Array(n),s=0;s<n;s++)o[s]=r.readBytes(e);return o}}};t.exports=a},{}],4:[function(e,t,r){var a=window.GIF||{};a=e("./gif"),window.GIF=a},{"./gif":5}],5:[function(e,t,r){function a(e){var t=new Uint8Array(e),r=new i(t);this.raw=r.parse(n),this.raw.hasImages=!1;for(var a=0;a<this.raw.frames.length;a++)if(this.raw.frames[a].image){this.raw.hasImages=!0;break}}var i=e("../bower_components/js-binary-schema-parser/src/dataparser"),n=e("./schema");a.prototype.decompressFrame=function(e,t){if(e>=this.raw.frames.length)return null;var r=this.raw.frames[e];if(r.image){var a=r.image.descriptor.width*r.image.descriptor.height,i=function(e,t,r){var a,i,n,o,s,l,u,h,c,d,f,g,p,m,v,b,y=r,w=new Array(r),_=new Array(4096),C=new Array(4096),A=new Array(4097);for(s=1+(i=1<<(g=e)),a=i+2,u=-1,n=(1<<(o=g+1))-1,c=0;c<i;c++)_[c]=0,C[c]=c;for(f=h=count=p=m=b=v=0,d=0;d<y;){if(0===m){if(h<o){f+=t[v]<<h,h+=8,v++;continue}if(c=f&n,f>>=o,h-=o,c>a||c==s)break;if(c==i){n=(1<<(o=g+1))-1,a=i+2,u=-1;continue}if(-1==u){A[m++]=C[c],u=c,p=c;continue}for(l=c,c==a&&(A[m++]=p,c=u);c>i;)A[m++]=C[c],c=_[c];p=255&C[c],A[m++]=p,a<4096&&(_[a]=u,C[a]=p,0==(++a&n)&&a<4096&&(o++,n+=a)),u=l}m--,w[b++]=A[m],d++}for(d=b;d<y;d++)w[d]=0;return w}(r.image.data.minCodeSize,r.image.data.blocks,a);r.image.descriptor.lct.interlaced&&(i=function(e,t){for(var r=new Array(e.length),a=e.length/t,i=[0,4,2,1],n=[8,8,4,2],o=0,s=0;s<4;s++)for(var l=i[s];l<a;l+=n[s])!function(a,i){var n=e.slice(i*t,(i+1)*t);r.splice.apply(r,[a*t,t].concat(n))}(l,o),o++;return r}(i,r.image.descriptor.width));var n={pixels:i,dims:{top:r.image.descriptor.top,left:r.image.descriptor.left,width:r.image.descriptor.width,height:r.image.descriptor.height}};return r.image.descriptor.lct&&r.image.descriptor.lct.exists?n.colorTable=r.image.lct:n.colorTable=this.raw.gct,r.gce&&(n.delay=10*(r.gce.delay||10),n.disposalType=r.gce.extras.disposal,r.gce.extras.transparentColorGiven&&(n.transparentIndex=r.gce.transparentColorIndex)),t&&(n.patch=function(e){for(var t=e.pixels.length,r=new Uint8ClampedArray(4*t),a=0;a<t;a++){var i=4*a,n=e.pixels[a],o=e.colorTable[n];r[i]=o[0],r[i+1]=o[1],r[i+2]=o[2],r[i+3]=n!==e.transparentIndex?255:0}return r}(n)),n}return null},a.prototype.decompressFrames=function(e){for(var t=[],r=0;r<this.raw.frames.length;r++)this.raw.frames[r].image&&t.push(this.decompressFrame(r,e));return t},t.exports=a},{"../bower_components/js-binary-schema-parser/src/dataparser":2,"./schema":6}],6:[function(e,t,r){var a=e("../bower_components/js-binary-schema-parser/src/parsers"),i={label:"blocks",parser:function(e){for(var t=[],r=e.readByte();0!==r;r=e.readByte())t=t.concat(e.readBytes(r));return t}},n={label:"gce",requires:function(e){var t=e.peekBytes(2);return 33===t[0]&&249===t[1]},parts:[{label:"codes",parser:a.readBytes(2),skip:!0},{label:"byteSize",parser:a.readByte()},{label:"extras",bits:{future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}}},{label:"delay",parser:a.readUnsigned(!0)},{label:"transparentColorIndex",parser:a.readByte()},{label:"terminator",parser:a.readByte(),skip:!0}]},o={label:"image",requires:function(e){return 44===e.peekByte()},parts:[{label:"code",parser:a.readByte(),skip:!0},{label:"descriptor",parts:[{label:"left",parser:a.readUnsigned(!0)},{label:"top",parser:a.readUnsigned(!0)},{label:"width",parser:a.readUnsigned(!0)},{label:"height",parser:a.readUnsigned(!0)},{label:"lct",bits:{exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}}}]},{label:"lct",requires:function(e,t,r){return r.descriptor.lct.exists},parser:a.readArray(3,function(e,t,r){return Math.pow(2,r.descriptor.lct.size+1)})},{label:"data",parts:[{label:"minCodeSize",parser:a.readByte()},i]}]},s={label:"text",requires:function(e){var t=e.peekBytes(2);return 33===t[0]&&1===t[1]},parts:[{label:"codes",parser:a.readBytes(2),skip:!0},{label:"blockSize",parser:a.readByte()},{label:"preData",parser:function(e,t,r){return e.readBytes(r.text.blockSize)}},i]},l={label:"frames",parts:[n,{label:"application",requires:function(e,t,r){var a=e.peekBytes(2);return 33===a[0]&&255===a[1]},parts:[{label:"codes",parser:a.readBytes(2),skip:!0},{label:"blockSize",parser:a.readByte()},{label:"id",parser:function(e,t,r){return e.readString(r.blockSize)}},i]},{label:"comment",requires:function(e,t,r){var a=e.peekBytes(2);return 33===a[0]&&254===a[1]},parts:[{label:"codes",parser:a.readBytes(2),skip:!0},i]},o,s],loop:function(e){var t=e.peekByte();return 33===t||44===t}},u=[{label:"header",parts:[{label:"signature",parser:a.readString(3)},{label:"version",parser:a.readString(3)}]},{label:"lsd",parts:[{label:"width",parser:a.readUnsigned(!0)},{label:"height",parser:a.readUnsigned(!0)},{label:"gct",bits:{exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}}},{label:"backgroundColorIndex",parser:a.readByte()},{label:"pixelAspectRatio",parser:a.readByte()}]},{label:"gct",requires:function(e,t){return t.lsd.gct.exists},parser:a.readArray(3,function(e,t){return Math.pow(2,t.lsd.gct.size+1)})},l];t.exports=u},{"../bower_components/js-binary-schema-parser/src/parsers":3}]},{},[4]),function(){function e(e){this.mode=c.MODE_8BIT_BYTE,this.data=e,this.parsedData=[];for(var t=0,r=this.data.length;t<r;t++){var a=[],i=this.data.charCodeAt(t);i>65536?(a[0]=240|(1835008&i)>>>18,a[1]=128|(258048&i)>>>12,a[2]=128|(4032&i)>>>6,a[3]=128|63&i):i>2048?(a[0]=224|(61440&i)>>>12,a[1]=128|(4032&i)>>>6,a[2]=128|63&i):i>128?(a[0]=192|(1984&i)>>>6,a[1]=128|63&i):a[0]=i,this.parsedData.push(a)}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 t(e,t){this.typeNumber=e,this.errorCorrectLevel=t,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}function r(e,t){if(void 0==e.length)throw new Error(e.length+"/"+t);for(var r=0;r<e.length&&0==e[r];)r++;this.num=new Array(e.length-r+t);for(var a=0;a<e.length-r;a++)this.num[a]=e[a+r]}function a(e,t){this.totalCount=e,this.dataCount=t}function i(){this.buffer=[],this.length=0}function n(e,t,r,a,i,n){e.beginPath(),e.moveTo(t,r),e.arcTo(t+a,r,t+a,r+i,n),e.arcTo(t+a,r+i,t,r+i,n),e.arcTo(t,r+i,t,r,n),e.arcTo(t,r,t+a,r,n),e.closePath()}function o(e,t,r){return.3*e+.59*r+.11*r}function s(e,t,r,a,i,n,o){if(void 0===n)e.fillRect(t,r,a,i);else{e.drawImage(n,t,r,a,i,t,r,a,i);var s=e.fillStyle;e.fillStyle=o?"rgba(0, 0, 0, .5)":"rgba(255, 255, 255, .7)",e.fillRect(t,r,a,i),e.fillStyle=s}}function l(e,t,r,a,i){e.clearRect((t-2)*a,(r-2)*i,5*a,5*i),e.fillRect((t-2)*a,(r-2)*i,5*a,5*i)}function u(e,t,r,a,i){e.fillRect((t-2)*a,(r-2)*i,a,4*i),e.fillRect((t+2)*a,(r-2+1)*i,a,4*i),e.fillRect((t-2+1)*a,(r-2)*i,4*a,i),e.fillRect((t-2)*a,(r+2)*i,4*a,i),e.fillRect(t*a,r*i,a,i)}function h(e){var t,r,a,i,n={r:0,g:0,b:0},o=document.createElement("canvas"),s=o.getContext&&o.getContext("2d"),l=-4,u={r:0,g:0,b:0},h=0;if(!s)return n;a=o.height=e.naturalHeight||e.offsetHeight||e.height,r=o.width=e.naturalWidth||e.offsetWidth||e.width,s.drawImage(e,0,0);try{t=s.getImageData(0,0,r,a)}catch(e){return n}for(i=t.data.length;(l+=20)<i;)t.data[l]>200||t.data[l+1]>200||t.data[l+2]>200||(++h,u.r+=t.data[l],u.g+=t.data[l+1],u.b+=t.data[l+2]);return u.r=~~(u.r/h),u.g=~~(u.g/h),u.b=~~(u.b/h),u}e.prototype={getLength:function(e){return this.parsedData.length},write:function(e){for(var t=0,r=this.parsedData.length;t<r;t++)e.put(this.parsedData[t],8)}},t.prototype={addData:function(t){var r=new e(t);this.dataList.push(r),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(){if(this.typeNumber<1){var e=1;for(e=1;e<40;e++){for(var t=a.getRSBlocks(e,this.errorCorrectLevel),r=new i,n=0,o=0;o<t.length;o++)n+=t[o].dataCount;for(o=0;o<this.dataList.length;o++){var s=this.dataList[o];r.put(s.mode,4),r.put(s.getLength(),g.getLengthInBits(s.mode,e)),s.write(r)}if(r.getLengthInBits()<=8*n)break}this.typeNumber=e}this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(e,r){this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var a=0;a<this.moduleCount;a++){this.modules[a]=new Array(this.moduleCount);for(var i=0;i<this.moduleCount;i++)this.modules[a][i]=null}this.setupPositionProbePattern(0,0),this.setupPositionProbePattern(this.moduleCount-7,0),this.setupPositionProbePattern(0,this.moduleCount-7),this.setupPositionAdjustPattern(),this.setupTimingPattern(),this.setupTypeInfo(e,r),this.typeNumber>=7&&this.setupTypeNumber(e),null==this.dataCache&&(this.dataCache=t.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,r)},setupPositionProbePattern:function(e,t){for(var r=-1;r<=7;r++)if(!(e+r<=-1||this.moduleCount<=e+r))for(var a=-1;a<=7;a++)t+a<=-1||this.moduleCount<=t+a||(this.modules[e+r][t+a]=0<=r&&r<=6&&(0==a||6==a)||0<=a&&a<=6&&(0==r||6==r)||2<=r&&r<=4&&2<=a&&a<=4)},getBestMaskPattern:function(){for(var e=0,t=0,r=0;r<8;r++){this.makeImpl(!0,r);var a=g.getLostPoint(this);(0==r||e>a)&&(e=a,t=r)}return t},createMovieClip:function(e,t,r){var a=e.createEmptyMovieClip(t,r);this.make();for(var i=0;i<this.modules.length;i++)for(var n=1*i,o=0;o<this.modules[i].length;o++){var s=1*o;this.modules[i][o]&&(a.beginFill(0,100),a.moveTo(s,n),a.lineTo(s+1,n),a.lineTo(s+1,n+1),a.lineTo(s,n+1),a.endFill())}return a},setupTimingPattern:function(){for(var e=8;e<this.moduleCount-8;e++)null==this.modules[e][6]&&(this.modules[e][6]=e%2==0);for(var t=8;t<this.moduleCount-8;t++)null==this.modules[6][t]&&(this.modules[6][t]=t%2==0)},setupPositionAdjustPattern:function(){for(var e=g.getPatternPosition(this.typeNumber),t=0;t<e.length;t++)for(var r=0;r<e.length;r++){var a=e[t],i=e[r];if(null==this.modules[a][i])for(var n=-2;n<=2;n++)for(var o=-2;o<=2;o++)this.modules[a+n][i+o]=-2==n||2==n||-2==o||2==o||0==n&&0==o}},setupTypeNumber:function(e){for(var t=g.getBCHTypeNumber(this.typeNumber),r=0;r<18;r++){a=!e&&1==(t>>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=a}for(r=0;r<18;r++){var a=!e&&1==(t>>r&1);this.modules[r%3+this.moduleCount-8-3][Math.floor(r/3)]=a}},setupTypeInfo:function(e,t){for(var r=this.errorCorrectLevel<<3|t,a=g.getBCHTypeInfo(r),i=0;i<15;i++){n=!e&&1==(a>>i&1);i<6?this.modules[i][8]=n:i<8?this.modules[i+1][8]=n:this.modules[this.moduleCount-15+i][8]=n}for(i=0;i<15;i++){var n=!e&&1==(a>>i&1);i<8?this.modules[8][this.moduleCount-i-1]=n:i<9?this.modules[8][15-i-1+1]=n:this.modules[8][15-i-1]=n}this.modules[this.moduleCount-8][8]=!e},mapData:function(e,t){for(var r=-1,a=this.moduleCount-1,i=7,n=0,o=this.moduleCount-1;o>0;o-=2)for(6==o&&o--;;){for(var s=0;s<2;s++)if(null==this.modules[a][o-s]){var l=!1;n<e.length&&(l=1==(e[n]>>>i&1)),g.getMask(t,a,o-s)&&(l=!l),this.modules[a][o-s]=l,-1==--i&&(n++,i=7)}if((a+=r)<0||this.moduleCount<=a){a-=r,r=-r;break}}}},t.PAD0=236,t.PAD1=17,t.createData=function(e,r,n){for(var o=a.getRSBlocks(e,r),s=new i,l=0;l<n.length;l++){var u=n[l];s.put(u.mode,4),s.put(u.getLength(),g.getLengthInBits(u.mode,e)),u.write(s)}for(var h=0,l=0;l<o.length;l++)h+=o[l].dataCount;if(s.getLengthInBits()>8*h)throw new Error("code length overflow. ("+s.getLengthInBits()+">"+8*h+")");for(s.getLengthInBits()+4<=8*h&&s.put(0,4);s.getLengthInBits()%8!=0;)s.putBit(!1);for(;;){if(s.getLengthInBits()>=8*h)break;if(s.put(t.PAD0,8),s.getLengthInBits()>=8*h)break;s.put(t.PAD1,8)}return t.createBytes(s,o)},t.createBytes=function(e,t){for(var a=0,i=0,n=0,o=new Array(t.length),s=new Array(t.length),l=0;l<t.length;l++){var u=t[l].dataCount,h=t[l].totalCount-u;i=Math.max(i,u),n=Math.max(n,h),o[l]=new Array(u);for(m=0;m<o[l].length;m++)o[l][m]=255&e.buffer[m+a];a+=u;var c=g.getErrorCorrectPolynomial(h),d=new r(o[l],c.getLength()-1).mod(c);s[l]=new Array(c.getLength()-1);for(m=0;m<s[l].length;m++){var f=m+d.getLength()-s[l].length;s[l][m]=f>=0?d.get(f):0}}for(var p=0,m=0;m<t.length;m++)p+=t[m].totalCount;for(var v=new Array(p),b=0,m=0;m<i;m++)for(l=0;l<t.length;l++)m<o[l].length&&(v[b++]=o[l][m]);for(m=0;m<n;m++)for(l=0;l<t.length;l++)m<s[l].length&&(v[b++]=s[l][m]);return v};for(var c={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},d={L:1,M:0,Q:3,H:2},f={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},g={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(e){for(var t=e<<10;g.getBCHDigit(t)-g.getBCHDigit(g.G15)>=0;)t^=g.G15<<g.getBCHDigit(t)-g.getBCHDigit(g.G15);return(e<<10|t)^g.G15_MASK},getBCHTypeNumber:function(e){for(var t=e<<12;g.getBCHDigit(t)-g.getBCHDigit(g.G18)>=0;)t^=g.G18<<g.getBCHDigit(t)-g.getBCHDigit(g.G18);return e<<12|t},getBCHDigit:function(e){for(var t=0;0!=e;)t++,e>>>=1;return t},getPatternPosition:function(e){return g.PATTERN_POSITION_TABLE[e-1]},getMask:function(e,t,r){switch(e){case f.PATTERN000:return(t+r)%2==0;case f.PATTERN001:return t%2==0;case f.PATTERN010:return r%3==0;case f.PATTERN011:return(t+r)%3==0;case f.PATTERN100:return(Math.floor(t/2)+Math.floor(r/3))%2==0;case f.PATTERN101:return t*r%2+t*r%3==0;case f.PATTERN110:return(t*r%2+t*r%3)%2==0;case f.PATTERN111:return(t*r%3+(t+r)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}},getErrorCorrectPolynomial:function(e){for(var t=new r([1],0),a=0;a<e;a++)t=t.multiply(new r([1,p.gexp(a)],0));return t},getLengthInBits:function(e,t){if(1<=t&&t<10)switch(e){case c.MODE_NUMBER:return 10;case c.MODE_ALPHA_NUM:return 9;case c.MODE_8BIT_BYTE:case c.MODE_KANJI:return 8;default:throw new Error("mode:"+e)}else if(t<27)switch(e){case c.MODE_NUMBER:return 12;case c.MODE_ALPHA_NUM:return 11;case c.MODE_8BIT_BYTE:return 16;case c.MODE_KANJI:return 10;default:throw new Error("mode:"+e)}else{if(!(t<41))throw new Error("type:"+t);switch(e){case c.MODE_NUMBER:return 14;case c.MODE_ALPHA_NUM:return 13;case c.MODE_8BIT_BYTE:return 16;case c.MODE_KANJI:return 12;default:throw new Error("mode:"+e)}}},getLostPoint:function(e){for(var t=e.getModuleCount(),r=0,a=0;a<t;a++)for(h=0;h<t;h++){for(var i=0,n=e.isDark(a,h),o=-1;o<=1;o++)if(!(a+o<0||t<=a+o))for(var s=-1;s<=1;s++)h+s<0||t<=h+s||0==o&&0==s||n==e.isDark(a+o,h+s)&&i++;i>5&&(r+=3+i-5)}for(a=0;a<t-1;a++)for(h=0;h<t-1;h++){var l=0;e.isDark(a,h)&&l++,e.isDark(a+1,h)&&l++,e.isDark(a,h+1)&&l++,e.isDark(a+1,h+1)&&l++,0!=l&&4!=l||(r+=3)}for(a=0;a<t;a++)for(h=0;h<t-6;h++)e.isDark(a,h)&&!e.isDark(a,h+1)&&e.isDark(a,h+2)&&e.isDark(a,h+3)&&e.isDark(a,h+4)&&!e.isDark(a,h+5)&&e.isDark(a,h+6)&&(r+=40);for(h=0;h<t;h++)for(a=0;a<t-6;a++)e.isDark(a,h)&&!e.isDark(a+1,h)&&e.isDark(a+2,h)&&e.isDark(a+3,h)&&e.isDark(a+4,h)&&!e.isDark(a+5,h)&&e.isDark(a+6,h)&&(r+=40);for(var u=0,h=0;h<t;h++)for(a=0;a<t;a++)e.isDark(a,h)&&u++;return r+=10*(Math.abs(100*u/t/t-50)/5)}},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)},m=0;m<8;m++)p.EXP_TABLE[m]=1<<m;for(m=8;m<256;m++)p.EXP_TABLE[m]=p.EXP_TABLE[m-4]^p.EXP_TABLE[m-5]^p.EXP_TABLE[m-6]^p.EXP_TABLE[m-8];for(m=0;m<255;m++)p.LOG_TABLE[p.EXP_TABLE[m]]=m;r.prototype={get:function(e){return this.num[e]},getLength:function(){return this.num.length},multiply:function(e){for(var t=new Array(this.getLength()+e.getLength()-1),a=0;a<this.getLength();a++)for(var i=0;i<e.getLength();i++)t[a+i]^=p.gexp(p.glog(this.get(a))+p.glog(e.get(i)));return new r(t,0)},mod:function(e){if(this.getLength()-e.getLength()<0)return this;for(var t=p.glog(this.get(0))-p.glog(e.get(0)),a=new Array(this.getLength()),i=0;i<this.getLength();i++)a[i]=this.get(i);for(i=0;i<e.getLength();i++)a[i]^=p.gexp(p.glog(e.get(i))+t);return new r(a,0).mod(e)}},a.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]],a.getRSBlocks=function(e,t){var r=a.getRsBlockTable(e,t);if(void 0==r)throw new Error("bad rs block @ typeNumber:"+e+"/errorCorrectLevel:"+t);for(var i=r.length/3,n=[],o=0;o<i;o++)for(var s=r[3*o+0],l=r[3*o+1],u=r[3*o+2],h=0;h<s;h++)n.push(new a(l,u));return n},a.getRsBlockTable=function(e,t){switch(t){case d.L:return a.RS_BLOCK_TABLE[4*(e-1)+0];case d.M:return a.RS_BLOCK_TABLE[4*(e-1)+1];case d.Q:return a.RS_BLOCK_TABLE[4*(e-1)+2];case d.H:return a.RS_BLOCK_TABLE[4*(e-1)+3];default:return}},i.prototype={get:function(e){var t=Math.floor(e/8);return 1==(this.buffer[t]>>>7-e%8&1)},put:function(e,t){for(var r=0;r<t;r++)this.putBit(1==(e>>>t-r-1&1))},getLengthInBits:function(){return this.length},putBit:function(e){var t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}};var v=function(){function e(){this._elImage.src=this._elCanvas.toDataURL("image/png"),this._elImage.style.display="block",this._elCanvas.style.display="none"}function t(e,t){var r=this;if(r._fFail=t,r._fSuccess=e,null===r._bSupportDataURI){var a=document.createElement("img"),i=function(){r._bSupportDataURI=!1,r._fFail&&r._fFail.call(r)};return a.onabort=i,a.onerror=i,a.onload=function(){r._bSupportDataURI=!0,r._fSuccess&&r._fSuccess.call(r)},void(a.src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==")}!0===r._bSupportDataURI&&r._fSuccess?r._fSuccess.call(r):!1===r._bSupportDataURI&&r._fFail&&r._fFail.call(r)}var r=function(e){this._bIsPainted=!1,this._htOption=e,this._elCanvas=document.createElement("canvas"),this._elCanvas.width=e.size,this._elCanvas.height=e.size,this._oContext=this._elCanvas.getContext("2d"),this._bIsPainted=!1,this._elImage=document.createElement("img"),this._elImage.alt="Scan me!",this._elImage.style.display="none",this._bSupportDataURI=null,this._callback=e.callback,this._bindElement=e.bindElement};return r.prototype.draw=function(e){var t=this._elImage,r=document.createElement("canvas"),a=r.getContext("2d"),i=this._htOption,c=e.getModuleCount(),d=i.size,f=i.margin;(f<0||2*f>=d)&&(f=0);var p=Math.ceil(f),m=d-2*f,v=i.whiteMargin,b=i.backgroundDimming,y=Math.ceil(m/c),w=y*c,_=w+2*p,C=void 0,A=void 0;r.width=_,r.height=_;var B=i.dotScale;if(t.style.display="none",this.clear(),B<=0||B>1)throw new Error("Scale should be in range (0, 1).");a.save(),a.translate(p,p);var E=document.createElement("canvas");E.width=_,E.height=_;var k=E.getContext("2d"),I=void 0;if(void 0!==i.gifBackground){var D=new GIF(i.gifBackground);if(!D.raw.hasImages)throw new Error("An invalid gif has been selected as the background.");if(C=D,A=D.decompressFrames(!0),i.autoColor){for(var T=0,R=0,L=0,P=0,x=0;x<A[0].colorTable.length;x++){var M=A[0].colorTable[x];M[0]>200||M[1]>200||M[2]>200||(0===M[0]&&0===M[1]&&0===M[2]||(P++,T+=M[0],R+=M[1],L+=M[2]))}T=~~(T/P),R=~~(R/P),L=~~(L/P),i.colorDark="rgb("+T+", "+R+", "+L+")"}}else if(void 0!==i.backgroundImage){if(i.autoColor){var S=h(i.backgroundImage);i.colorDark="rgb("+S.r+", "+S.g+", "+S.b+")"}i.maskedDots?((I=document.createElement("canvas")).width=_,I.height=_,I.getContext("2d").drawImage(i.backgroundImage,0,0,i.backgroundImage.width,i.backgroundImage.height,0,0,_,_),k.rect(0,0,_,_),k.fillStyle="#ffffff",k.fill()):(k.drawImage(i.backgroundImage,0,0,i.backgroundImage.width,i.backgroundImage.height,0,0,_,_),k.rect(0,0,_,_),k.fillStyle=b,k.fill())}else k.rect(0,0,_,_),k.fillStyle="#ffffff",k.fill();i.binarize&&(i.colorDark="#000000",i.colorLight="#FFFFFF");for(var N=g.getPatternPosition(e.typeNumber),O=.5*(1-B),F=0;F<c;F++)for(var U=0;U<c;U++){for(var G=e.isDark(F,U),z=U<8&&(F<8||F>=c-8)||U>=c-8&&F<8,H=6===F||6===U||z,x=0;x<N.length-1;x++)H=H||F>=N[x]-2&&F<=N[x]+2&&U>=N[x]-2&&U<=N[x]+2;var Q=U*y+(H?0:O*y),q=F*y+(H?0:O*y);if(a.strokeStyle=G?i.colorDark:i.colorLight,a.lineWidth=.5,a.fillStyle=G?i.colorDark:"rgba(255, 255, 255, 0.6)",0===N.length)H||s(a,Q,q,(H?1:B)*y,(H?1:B)*y,I,G);else{var K=U<c-4&&U>=c-4-5&&F<c-4&&F>=c-4-5;H||K||s(a,Q,q,(H?1:B)*y,(H?1:B)*y,I,G)}}a.fillStyle="rgba(255, 255, 255, 0.6)",a.fillRect(0,0,8*y,8*y),a.fillRect(0,(c-8)*y,8*y,8*y),a.fillRect((c-8)*y,0,8*y,8*y),a.fillRect(8*y,6*y,(c-8-8)*y,y),a.fillRect(6*y,8*y,y,(c-8-8)*y);for(var X=N[N.length-1],x=0;x<N.length;x++)for(J=0;J<N.length;J++){var j=N[J],Y=N[x];(6!==j||6!==Y&&Y!==X)&&((6!==Y||6!==j&&j!==X)&&l(a,j,Y,y,y))}a.fillStyle=i.colorDark,a.fillRect(0,0,7*y,y),a.fillRect((c-7)*y,0,7*y,y),a.fillRect(0,6*y,7*y,y),a.fillRect((c-7)*y,6*y,7*y,y),a.fillRect(0,(c-7)*y,7*y,y),a.fillRect(0,(c-7+6)*y,7*y,y),a.fillRect(0,0,y,7*y),a.fillRect(6*y,0,y,7*y),a.fillRect((c-7)*y,0,y,7*y),a.fillRect((c-7+6)*y,0,y,7*y),a.fillRect(0,(c-7)*y,y,7*y),a.fillRect(6*y,(c-7)*y,y,7*y),a.fillRect(2*y,2*y,3*y,3*y),a.fillRect((c-7+2)*y,2*y,3*y,3*y),a.fillRect(2*y,(c-7+2)*y,3*y,3*y);for(x=0;x<c-8;x+=2)a.fillRect((8+x)*y,6*y,y,y),a.fillRect(6*y,(8+x)*y,y,y);for(x=0;x<N.length;x++)for(var J=0;J<N.length;J++){var j=N[J],Y=N[x];(6!==j||6!==Y&&Y!==X)&&((6!==Y||6!==j&&j!==X)&&(6!==j&&j!==X&&6!==Y&&Y!==X?(a.fillStyle="rgba(0, 0, 0, .2)",u(a,j,Y,y,y)):(a.fillStyle=i.colorDark,u(a,j,Y,y,y))))}if(v&&(a.fillStyle="#FFFFFF",a.fillRect(-p,-p,_,p),a.fillRect(-p,w,_,p),a.fillRect(w,-p,p,_),a.fillRect(-p,-p,p,_)),void 0!==i.logoImage){var W=i.logoScale,V=i.logoMargin,Z=i.logoCornerRadius;(W<=0||W>=1)&&(W=.2),V<0&&(V=0),Z<0&&(Z=0),a.restore();var $=w*W,ee=.5*(_-$),te=ee;a.fillStyle="#FFFFFF",a.save(),n(a,ee-V,te-V,$+2*V,$+2*V,Z),a.clip(),a.fill(),a.restore(),a.save(),n(a,ee,te,$,$,Z),a.clip(),a.drawImage(i.logoImage,ee,te,$,$),a.restore()}if(void 0===C){if(k.drawImage(r,0,0,_,_),a.drawImage(E,-p,-p,_,_),i.binarize){var re=a.getImageData(0,0,_,_),ae=128;parseInt(i.binarizeThreshold)>0&&parseInt(i.binarizeThreshold)<255&&(ae=parseInt(i.binarizeThreshold));for(x=0;x<re.data.length;x+=4)o(re.data[x],re.data[x+1],re.data[x+2])>ae?(re.data[x]=255,re.data[x+1]=255,re.data[x+2]=255):(re.data[x]=0,re.data[x+1]=0,re.data[x+2]=0);a.putImageData(re,0,0)}var ie=document.createElement("canvas"),ne=ie.getContext("2d");if(ie.width=d,ie.height=d,ne.drawImage(r,0,0,d,d),this._elCanvas=ie,this._bIsPainted=!0,void 0!==this._callback&&this._callback(this._elCanvas.toDataURL()),void 0!==this._bindElement)try{var oe=document.getElementById(this._bindElement);if("IMG"===oe.nodeName)oe.src=this._elCanvas.toDataURL();else{var se=oe.style;se["background-image"]="url("+this._elCanvas.toDataURL()+")",se["background-size"]="contain",se["background-repeat"]="no-repeat"}}catch(e){console.error(e)}}else{var le,ue,he,ce,de=document.createElement("canvas"),fe=de.getContext("2d");if(A.forEach(function(e){void 0===le&&(le=new GIFE({workers:4,quality:10,width:d,height:d})),void 0===ue&&(ue=document.createElement("canvas"),he=ue.getContext("2d"),ue.width=e.dims.width,ue.height=e.dims.height,he.rect(0,0,ue.width,ue.height),he.fillStyle="#ffffff",he.fill()),ce&&e.dims.width===de.width&&e.dims.height===de.height||(de.width=e.dims.width,de.height=e.dims.height,ce=fe.createImageData(e.dims.width,e.dims.height)),ce.data.set(e.patch),fe.putImageData(ce,0,0),he.drawImage(de,e.dims.left,e.dims.top);var t=document.createElement("canvas");t.width=_,t.height=_;var a=t.getContext("2d");a.drawImage(ue,0,0,_,_),a.drawImage(r,0,0,_,_);var i=document.createElement("canvas"),n=i.getContext("2d");i.width=d,i.height=d,n.drawImage(t,0,0,d,d),le.addFrame(n,{copy:!0,delay:e.delay})}),void 0===le)throw new Error("No frames.");var ge=this;le.on("finished",function(e){var t=new FileReader;t.onload=function(e){var t=e.target.result;if(ge._bIsPainted=!0,void 0!==ge._callback&&ge._callback(t),void 0!==ge._bindElement)try{var r=document.getElementById(ge._bindElement);if("IMG"===r.nodeName)r.src=t;else{var a=r.style;a["background-image"]="url("+t+")",a["background-size"]="contain",a["background-repeat"]="no-repeat"}}catch(e){console.error(e)}},t.readAsDataURL(e)}),le.render()}},r.prototype.makeImage=function(){this._bIsPainted&&t.call(this,e)},r.prototype.isPainted=function(){return this._bIsPainted},r.prototype.clear=function(){this._oContext.clearRect(0,0,this._elCanvas.width,this._elCanvas.height),this._bIsPainted=!1},r.prototype.round=function(e){return e?Math.floor(1e3*e)/1e3:e},r}();(AwesomeQRCode=function(){}).prototype.create=function(e){if(this._htOption={size:800,margin:20,typeNumber:4,colorDark:"#000000",colorLight:"#ffffff",correctLevel:d.M,backgroundImage:void 0,backgroundDimming:"rgba(0,0,0,0)",logoImage:void 0,logoScale:.2,logoMargin:6,logoCornerRadius:8,whiteMargin:!0,dotScale:.35,maskedDots:!1,autoColor:!0,binarize:!1,binarizeThreshold:128,gifBackground:void 0,callback:void 0,bindElement:void 0},"string"==typeof e&&(e={text:e}),e)for(var t in e)this._htOption[t]=e[t];this._oQRCode=null,this._oDrawing=new v(this._htOption),this._htOption.text&&this.makeCode(this._htOption.text)},AwesomeQRCode.prototype.makeCode=function(e){this._oQRCode=new t(-1,this._htOption.correctLevel),this._oQRCode.addData(e),this._oQRCode.make(),this._oDrawing.draw(this._oQRCode),this.makeImage()},AwesomeQRCode.prototype.makeImage=function(){"function"==typeof this._oDrawing.makeImage&&this._oDrawing.makeImage()},AwesomeQRCode.prototype.clear=function(){this._oDrawing.clear()},AwesomeQRCode.CorrectLevel=d}(),function(e,t){"object"==typeof exports?module.exports=t:"function"==typeof define&&define.amd?define(t):e.eventUtil=t()}(this,function(){return new AwesomeQRCode});