forked from englishextra/qrjs2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqrjs2.min.js
1 lines (1 loc) · 9.48 KB
/
qrjs2.min.js
1
!function(r,t,e){r[t]=e()}("undefined" !== typeof window ? window : this,"QRCode",function(){for(var r=[null,[[10,7,17,13],[1,1,1,1],[]],[[16,10,28,22],[1,1,1,1],[4,16]],[[26,15,22,18],[1,1,2,2],[4,20]],[[18,20,16,26],[2,1,4,2],[4,24]],[[24,26,22,18],[2,1,4,4],[4,28]],[[16,18,28,24],[4,2,4,4],[4,32]],[[18,20,26,18],[4,2,5,6],[4,20,36]],[[22,24,26,22],[4,2,6,6],[4,22,40]],[[22,30,24,20],[5,2,8,8],[4,24,44]],[[26,18,28,24],[5,4,8,8],[4,26,48]],[[30,20,24,28],[5,4,11,8],[4,28,52]],[[22,24,28,26],[8,4,11,10],[4,30,56]],[[22,26,22,24],[9,4,16,12],[4,32,60]],[[24,30,24,20],[9,4,16,16],[4,24,44,64]],[[24,22,24,30],[10,6,18,12],[4,24,46,68]],[[28,24,30,24],[10,6,16,17],[4,24,48,72]],[[28,28,28,28],[11,6,19,16],[4,28,52,76]],[[26,30,28,28],[13,6,21,18],[4,28,54,80]],[[26,28,26,26],[14,7,25,21],[4,28,56,84]],[[26,28,28,30],[16,8,25,20],[4,32,60,88]],[[26,28,30,28],[17,8,25,23],[4,26,48,70,92]],[[28,28,24,30],[17,9,34,23],[4,24,48,72,96]],[[28,30,30,30],[18,9,30,25],[4,28,52,76,100]],[[28,30,30,30],[20,10,32,27],[4,26,52,78,104]],[[28,26,30,30],[21,12,35,29],[4,30,56,82,108]],[[28,28,30,28],[23,12,37,34],[4,28,56,84,112]],[[28,30,30,30],[25,12,40,34],[4,32,60,88,116]],[[28,30,30,30],[26,13,42,35],[4,24,48,72,96,120]],[[28,30,30,30],[28,14,45,38],[4,28,52,76,100,124]],[[28,30,30,30],[29,15,48,40],[4,24,50,76,102,128]],[[28,30,30,30],[31,16,51,43],[4,28,54,80,106,132]],[[28,30,30,30],[33,17,54,45],[4,32,58,84,110,136]],[[28,30,30,30],[35,18,57,48],[4,28,56,84,112,140]],[[28,30,30,30],[37,19,60,51],[4,32,60,88,116,144]],[[28,30,30,30],[38,19,63,53],[4,28,52,76,100,124,148]],[[28,30,30,30],[40,20,66,56],[4,22,48,74,100,126,152]],[[28,30,30,30],[43,21,70,59],[4,26,52,78,104,130,156]],[[28,30,30,30],[45,22,74,62],[4,30,56,82,108,134,160]],[[28,30,30,30],[47,24,77,65],[4,24,52,80,108,136,164]],[[28,30,30,30],[49,25,81,68],[4,28,56,84,112,140,168]]],t=0,e=1,n=2,a=4,o=8,u=/^\d*$/,i=/^[A-Za-z0-9 $%*+\-./:] * $ /,l=/^[A-Z0-9 $%*+\-./:] * $ /,f=1,c=0,s=3,h=2,v=[],g=[-1],p=0,d=1;255>p;++p)v.push(d),g[d]=p,d=2*d^(128>d?0:285);for(var m=[[]],p=0;30>p;++p){for(var w=m[p],b=[],x=0;p>=x;++x){var F=p>x?v[w[x]]:0,A=v[(p+(w[x-1]||0))%255];b.push(g[F^A])}m.push(b)}for(var C={},p=0;45>p;++p)C["0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:".charAt(p)]=p;var N=[function(r,t){return(r+t)%2===0},function(r){return r%2===0},function(r,t){return t%3===0},function(r,t){return(r+t)%3===0},function(r,t){return((r/2|0)+(t/3|0))%2===0},function(r,t){return r*t%2+r*t%3===0},function(r,t){return(r*t%2+r*t%3)%2===0},function(r,t){return((r+t)%2+r*t%3)%2===0}],S=function(r){return r>6},y=function(r){return 4*r+17},M=function(t){var e=r[t],n=16*t*t+128*t+64;return S(t)&&(n-=36),e[2].length&&(n-=25*e[2].length*e[2].length-10*e[2].length-55),n},E=function(t,e){var n=-8&M(t),a=r[t];return n-=8*a[0][e]*a[1][e]},k=function(r,t){switch(t){case e:return 10>r?10:27>r?12:14;case n:return 10>r?9:27>r?11:13;case a:return 10>r?8:16;case o:return 10>r?8:27>r?10:12}},L=function(r,t,u){var i=E(r,u)-4-k(r,t);switch(t){case e:return 3*(i/10|0)+(4>i%10?0:7>i%10?1:2);case n:return 2*(i/11|0)+(6>i%11?0:1);case a:return i/8|0;case o:return i/13|0}},R=function(r,t){switch(r){case e:return t.match(u)?t:null;case n:return t.match(i)?t.toUpperCase():null;case a:if("string"===typeof t){for(var o=[],l=0;l<t.length;++l){var f=t.charCodeAt(l);128>f?o.push(f):2048>f?o.push(192|f>>6,128|63&f):65536>f?o.push(224|f>>12,128|f>>6&63,128|63&f):o.push(240|f>>18,128|f>>12&63,128|f>>6&63,128|63&f)}return o}return t}},$=function(r,o,u,i){var l=[],f=0,c=8,s=u.length,h=function(r,t){if(t>=c){for(l.push(f|r>>(t-=c));t>=8;)l.push(r>>(t-=8)&255);f=0,c=8}t>0&&(f|=(r&(1<<t)-1)<<(c-=t))},v=k(r,o);switch(h(o,4),h(s,v),o){case e:for(var g=2;s>g;g+=3)h(parseInt(u.substring(g-2,g+1),10),10);h(parseInt(u.substring(g-2),10),[0,4,7][s%3]);break;case n:for(var g=1;s>g;g+=2)h(45*C[u.charAt(g-1)]+C[u.charAt(g)],11);s%2===1&&h(C[u.charAt(g-1)],6);break;case a:for(var g=0;s>g;++g)h(u[g],8)}for(h(t,4),8>c&&l.push(f);l.length+1<i;)l.push(236,17);return l.length<i&&l.push(236),l},z=function(r,t){for(var e=r.slice(0),n=r.length,a=t.length,o=0;a>o;++o)e.push(0);for(var u=0;n>u;){var i=g[e[u++]];if(i>=0)for(var l=0;a>l;++l)e[u+l]^=v[(i+t[l])%255]}return e.slice(n)},G=function(r,t,e){for(var n=[],a=r.length/t|0,o=0,u=t-r.length%t,i=0;u>i;++i)n.push(o),o+=a;for(var i=u;t>i;++i)n.push(o),o+=a+1;n.push(o);for(var l=[],i=0;t>i;++i)l.push(z(r.slice(n[i],n[i+1]),e));for(var f=[],c=r.length/t|0,i=0;c>i;++i)for(var s=0;t>s;++s)f.push(r[n[s]+i]);for(var s=u;t>s;++s)f.push(r[n[s+1]-1]);for(var i=0;i<e.length;++i)for(var s=0;t>s;++s)f.push(l[s][i]);return f},U=function(r,t,e,n){for(var a=r<<n,o=t-1;o>=0;--o)a>>n+o&1&&(a^=e<<o);return r<<n|a},D=function(t){for(var e=r[t],n=y(t),a=[],o=[],u=0;n>u;++u)a.push([]),o.push([]);var i=function(r,t,e,n,u){for(var i=0;e>i;++i)for(var l=0;n>l;++l)a[r+i][t+l]=u[i]>>l&1,o[r+i][t+l]=1};i(0,0,9,9,[127,65,93,93,93,65,383,0,64]),i(n-8,0,8,9,[256,127,65,93,93,93,65,127]),i(0,n-8,9,8,[254,130,186,186,186,130,254,0,0]);for(var u=9;n-8>u;++u)a[6][u]=a[u][6]=1&~u,o[6][u]=o[u][6]=1;for(var l=e[2],f=l.length,u=0;f>u;++u)for(var c=0===u||u===f-1?1:0,s=0===u?f-1:f,h=c;s>h;++h)i(l[u],l[h],5,5,[31,17,21,17,31]);if(S(t))for(var v=U(t,6,7973,12),g=0,u=0;6>u;++u)for(var h=0;3>h;++h)a[u][n-11+h]=a[n-11+h][u]=v>>g++&1,o[u][n-11+h]=o[n-11+h][u]=1;return{matrix:a,reserved:o}},H=function(r,t,e){for(var n=r.length,a=0,o=-1,u=n-1;u>=0;u-=2){6===u&&--u;for(var i=0>o?n-1:0,l=0;n>l;++l){for(var f=u;f>u-2;--f)t[i][f]||(r[i][f]=e[a>>3]>>(7&~a)&1,++a);i+=o}o=-o}return r},I=function(r,t,e){for(var n=N[e],a=r.length,o=0;a>o;++o)for(var u=0;a>u;++u)t[o][u]||(r[o][u]^=n(o,u));return r},P=function(r,t,e,n){for(var a=r.length,o=21522^U(e<<3|n,5,1335,10),u=0;15>u;++u){var i=[0,1,2,3,4,5,7,8,a-7,a-6,a-5,a-4,a-3,a-2,a-1][u],l=[a-1,a-2,a-3,a-4,a-5,a-6,a-7,a-8,7,5,4,3,2,1,0][u];r[i][8]=r[8][l]=o>>u&1}return r},Q=function(r){for(var t=3,e=3,n=40,a=10,o=function(r){for(var e=0,a=0;a<r.length;++a)r[a]<5||(e+=t+(r[a]-5));for(var a=5;a<r.length;a+=2){var o=r[a];r[a-1]!==o||r[a-2]!==3*o||r[a-3]!==o||r[a-4]!==o||r[a-5]<4*o&&r[a+1]<4*o||(e+=n)}return e},u=r.length,i=0,l=0,f=0;u>f;++f){var c,s=r[f];c=[0];for(var h=0;u>h;){var v;for(v=0;u>h&&s[h];++v)++h;for(c.push(v),v=0;u>h&&!s[h];++v)++h;c.push(v)}i+=o(c),c=[0];for(var h=0;u>h;){var v;for(v=0;u>h&&r[h][f];++v)++h;for(c.push(v),v=0;u>h&&!r[h][f];++v)++h;c.push(v)}i+=o(c);var g=r[f+1]||[];l+=s[0];for(var h=1;u>h;++h){var p=s[h];l+=p,s[h-1]===p&&g[h]===p&&g[h-1]===p&&(i+=e)}}return i+=a*(Math.abs(l/u/u-.5)/.05|0)},T=function(t,e,n,a,o){var u=r[e],i=$(e,n,t,E(e,a)>>3);i=G(i,u[1][a],m[u[0][a]]);var l=D(e),f=l.matrix,c=l.reserved;if(H(f,c,i),0>o){I(f,c,0),P(f,c,a,0);var s=0,h=Q(f);for(I(f,c,0),o=1;8>o;++o){I(f,c,o),P(f,c,a,o);var v=Q(f);h>v&&(h=v,s=o),I(f,c,o)}o=s}return I(f,c,o),P(f,c,a,o),f},Z={generate:function(r,t){var o={numeric:e,alphanumeric:n,octet:a},i={L:f,M:c,Q:s,H:h};t=t||{};var v=t.version||-1,g=i[(t.ecclevel||"L").toUpperCase()],p=t.mode?o[t.mode.toLowerCase()]:-1,d="mask"in t?t.mask:-1;if(0>p)p="string"===typeof r?r.match(u)?e:r.match(l)?n:a:a;else if(p!==e&&p!==n&&p!==a)throw"invalid or unsupported mode";if(r=R(p,r),null===r)throw"invalid data format";if(0>g||g>3)throw"invalid ECC level";if(0>v){for(v=1;40>=v&&r.length>L(v,p,g);++v);if(v>40)throw"too large data"}else if(1>v||v>40)throw"invalid version";if(-1!==d&&(0>d||d>8))throw"invalid mask";return T(r,v,p,g,d)},generateHTML:function(r,t){t=t||{};for(var e=t.fillcolor?t.fillcolor:"#FFFFFF",n=t.textcolor?t.textcolor:"#000000",a=Z.generate(r,t),o=Math.max(t.modulesize||5,.5),u=Math.max(null!==t.margin?t.margin:4,0),i=document.createElement("div"),l=a.length,f=['<table border="0" cellspacing="0" cellpadding="0" style="border:'+o*u+"px solid "+e+";background:"+e+'">'],c=0;l>c;++c){f.push("<tr>");for(var s=0;l>s;++s)f.push('<td style="width:'+o+"px;height:"+o+"px"+(a[c][s]?";background:"+n:"")+'"></td>');f.push("</tr>")}i.className="qrcode";var h=document.createRange();h.selectNodeContents(i);var v=h.createContextualFragment(f.join("")+"</table>");return i.appendChild(v),i},generateSVG:function(r,t){t=t||{};var e=t.fillcolor?t.fillcolor:"#FFFFFF",n=t.textcolor?t.textcolor:"#000000",a=Z.generate(r,t),o=a.length,u=Math.max(t.modulesize||5,.5),i=Math.max(t.margin?t.margin:4,0),l=u*(o+2*i),f=document.createElementNS("http://www.w3.org/2000/svg","svg");f.setAttribute("viewBox","0 0 "+l+" "+l),f.setAttribute("style","shape-rendering:crispEdges");var c=document.createDocumentFragment(),s=document.createElementNS("http://www.w3.org/2000/svg","style");s.appendChild(document.createTextNode(".bg{fill:"+e+"}.fg{fill:"+n+"}")),s.setAttribute("scoped","scoped"),c.appendChild(s);var h=function(r,t,e,n,a){var o=document.createElementNS("http://www.w3.org/2000/svg","rect")||"";return o.setAttributeNS(null,"class",r),o.setAttributeNS(null,"fill",t),o.setAttributeNS(null,"x",e),o.setAttributeNS(null,"y",n),o.setAttributeNS(null,"width",a),o.setAttributeNS(null,"height",a),o};c.appendChild(h("bg","none",0,0,l));for(var v=i*u,g=0;o>g;++g){for(var p=i*u,d=0;o>d;++d)a[g][d]&&c.appendChild(h("fg","none",p,v,u)),p+=u;v+=u}return f.appendChild(c),f},generatePNG:function(r,t){t=t||{};var e,n=t.fillcolor?t.fillcolor:"#FFFFFF",a=t.textcolor?t.textcolor:"#000000",o=Z.generate(r,t),u=Math.max(t.modulesize||5,.5),i=Math.max(null!==t.margin&&void 0!==t.margin?t.margin:4,0),l=o.length,f=u*(l+2*i),c=document.createElement("canvas");if(c.width=c.height=f,e=c.getContext("2d"),!e)throw"canvas support is needed for PNG output";e.fillStyle=n,e.fillRect(0,0,f,f),e.fillStyle=a;for(var s=0;l>s;++s)for(var h=0;l>h;++h)o[s][h]&&e.fillRect(u*(i+h),u*(i+s),u,u);return c.toDataURL()}};return Z});