UNPKG

gen-qrcode-logo

Version:

qrCode with logo,完全支持node端和前端

2 lines (1 loc) 32.2 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.QrCodeWithLogo=e()}(this,function(){"use strict";function t(t){return"string"==typeof t}var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function r(t,e){return t(e={exports:{}},e.exports),e.exports}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o="object"===("undefined"==typeof self?"undefined":n(self))&&self.self===self&&self||"object"===n(e)&&e.global===e&&e||e,i=function(){return"function"==typeof o.Promise&&"function"==typeof o.Promise.prototype.then},a={}.toString,u=Array.isArray||function(t){return"[object Array]"==a.call(t)};f.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()}catch(t){return!1}}();var s=f.TYPED_ARRAY_SUPPORT?2147483647:1073741823;function f(t,e,r){return f.TYPED_ARRAY_SUPPORT||this instanceof f?"number"==typeof t?h(this,t):function(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');if("undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer)return function(t,e,r,n){if(r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");var o;o=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);f.TYPED_ARRAY_SUPPORT?o.__proto__=f.prototype:o=g(t,o);return o}(t,e,r,n);if("string"==typeof e)return function(t,e){var r=0|p(e),n=l(t,r),o=n.write(e);o!==r&&(n=n.slice(0,o));return n}(t,e);return function(t,e){if(f.isBuffer(e)){var r=0|c(e.length),n=l(t,r);return 0===n.length?n:(e.copy(n,0,0,r),n)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(o=e.length)!=o?l(t,0):g(t,e);if("Buffer"===e.type&&Array.isArray(e.data))return g(t,e.data)}var o;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}(this,t,e,r):new f(t,e,r)}function c(t){if(t>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return 0|t}function l(t,e){var r;return f.TYPED_ARRAY_SUPPORT?(r=new Uint8Array(e)).__proto__=f.prototype:(null===(r=t)&&(r=new f(e)),r.length=e),r}function h(t,e){var r=l(t,e<0?0:0|c(e));if(!f.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)r[n]=0;return r}function g(t,e){for(var r=e.length<0?0:0|c(e.length),n=l(t,r),o=0;o<r;o+=1)n[o]=255&e[o];return n}function d(t,e){var r;e=e||1/0;for(var n=t.length,o=null,i=[],a=0;a<n;++a){if((r=t.charCodeAt(a))>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function p(t){return f.isBuffer(t)?t.length:"undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer)?t.byteLength:("string"!=typeof t&&(t=""+t),0===t.length?0:d(t).length)}f.TYPED_ARRAY_SUPPORT&&(f.prototype.__proto__=Uint8Array.prototype,f.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&f[Symbol.species]===f&&Object.defineProperty(f,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1})),f.prototype.write=function(t,e,r){void 0===e?(r=this.length,e=0):void 0===r&&"string"==typeof e?(r=this.length,e=0):isFinite(e)&&(e|=0,isFinite(r)?r|=0:r=void 0);var n=this.length-e;if((void 0===r||r>n)&&(r=n),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");return function(t,e,r,n){return function(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}(d(e,t.length-r),t,r,n)}(this,t,e,r)},f.prototype.slice=function(t,e){var r,n=this.length;if(t=~~t,e=void 0===e?n:~~e,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),e<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),f.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=f.prototype;else{var o=e-t;r=new f(o,void 0);for(var i=0;i<o;++i)r[i]=this[i+t]}return r},f.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var o,i=n-r;if(this===t&&r<e&&e<n)for(o=i-1;o>=0;--o)t[o+e]=this[o+r];else if(i<1e3||!f.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+i),e);return i},f.prototype.fill=function(t,e,r){if("string"==typeof t){if("string"==typeof e?(e=0,r=this.length):"string"==typeof r&&(r=this.length),1===t.length){var n=t.charCodeAt(0);n<256&&(t=n)}}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{var i=f.isBuffer(t)?t:new f(t),a=i.length;for(o=0;o<r-e;++o)this[o+e]=i[o%a]}return this},f.concat=function(t,e){if(!u(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return l(null,0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=h(null,e),o=0;for(r=0;r<t.length;++r){var i=t[r];if(!f.isBuffer(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,o),o+=i.length}return n},f.byteLength=p,f.prototype._isBuffer=!0,f.isBuffer=function(t){return!(null==t||!t._isBuffer)};var v,y=f,w=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706],m={getSymbolSize:function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return 4*t+17},getSymbolTotalCodewords:function(t){return w[t]},getBCHDigit:function(t){for(var e=0;0!==t;)e++,t>>>=1;return e},setToSJISFunction:function(t){if("function"!=typeof t)throw new Error('"toSJISFunc" is not a valid function.');v=t},isKanjiModeEnabled:function(){return void 0!==v},toSJIS:function(t){return v(t)}},E=r(function(t,e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2},e.isValid=function(t){return t&&void 0!==t.bit&&t.bit>=0&&t.bit<4},e.from=function(t,r){if(e.isValid(t))return t;try{return function(t){if("string"!=typeof t)throw new Error("Param is not a string");switch(t.toLowerCase()){case"l":case"low":return e.L;case"m":case"medium":return e.M;case"q":case"quartile":return e.Q;case"h":case"high":return e.H;default:throw new Error("Unknown EC Level: "+t)}}(t)}catch(t){return r}}});E.L,E.M,E.Q,E.H,E.isValid,E.from;function A(){this.buffer=[],this.length=0}A.prototype={get:function(t){var e=Math.floor(t/8);return 1==(this.buffer[e]>>>7-t%8&1)},put:function(t,e){for(var r=0;r<e;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++}};var b=A;function B(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new y(t*t),this.data.fill(0),this.reservedBit=new y(t*t),this.reservedBit.fill(0)}B.prototype.set=function(t,e,r,n){var o=t*this.size+e;this.data[o]=r,n&&(this.reservedBit[o]=!0)},B.prototype.get=function(t,e){return this.data[t*this.size+e]},B.prototype.xor=function(t,e,r){this.data[t*this.size+e]^=r},B.prototype.isReserved=function(t,e){return this.reservedBit[t*this.size+e]};var P=B,C=r(function(t,e){var r=m.getSymbolSize;e.getRowColCoords=function(t){if(1===t)return[];for(var e=Math.floor(t/7)+2,n=r(t),o=145===n?26:2*Math.ceil((n-13)/(2*e-2)),i=[n-7],a=1;a<e-1;a++)i[a]=i[a-1]-o;return i.push(6),i.reverse()},e.getPositions=function(t){for(var r=[],n=e.getRowColCoords(t),o=n.length,i=0;i<o;i++)for(var a=0;a<o;a++)0===i&&0===a||0===i&&a===o-1||i===o-1&&0===a||r.push([n[i],n[a]]);return r}}),R=(C.getRowColCoords,C.getPositions,m.getSymbolSize),T={getPositions:function(t){var e=R(t);return[[0,0],[e-7,0],[0,e-7]]}},I=r(function(t,e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var r=3,n=3,o=40,i=10;function a(t,r,n){switch(t){case e.Patterns.PATTERN000:return(r+n)%2==0;case e.Patterns.PATTERN001:return r%2==0;case e.Patterns.PATTERN010:return n%3==0;case e.Patterns.PATTERN011:return(r+n)%3==0;case e.Patterns.PATTERN100:return(Math.floor(r/2)+Math.floor(n/3))%2==0;case e.Patterns.PATTERN101:return r*n%2+r*n%3==0;case e.Patterns.PATTERN110:return(r*n%2+r*n%3)%2==0;case e.Patterns.PATTERN111:return(r*n%3+(r+n)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}}e.isValid=function(t){return null!=t&&""!==t&&!isNaN(t)&&t>=0&&t<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(t){for(var e=t.size,n=0,o=0,i=0,a=null,u=null,s=0;s<e;s++){o=i=0,a=u=null;for(var f=0;f<e;f++){var c=t.get(s,f);c===a?o++:(o>=5&&(n+=r+(o-5)),a=c,o=1),(c=t.get(f,s))===u?i++:(i>=5&&(n+=r+(i-5)),u=c,i=1)}o>=5&&(n+=r+(o-5)),i>=5&&(n+=r+(i-5))}return n},e.getPenaltyN2=function(t){for(var e=t.size,r=0,o=0;o<e-1;o++)for(var i=0;i<e-1;i++){var a=t.get(o,i)+t.get(o,i+1)+t.get(o+1,i)+t.get(o+1,i+1);4!==a&&0!==a||r++}return r*n},e.getPenaltyN3=function(t){for(var e=t.size,r=0,n=0,i=0,a=0;a<e;a++){n=i=0;for(var u=0;u<e;u++)n=n<<1&2047|t.get(a,u),u>=10&&(1488===n||93===n)&&r++,i=i<<1&2047|t.get(u,a),u>=10&&(1488===i||93===i)&&r++}return r*o},e.getPenaltyN4=function(t){for(var e=0,r=t.data.length,n=0;n<r;n++)e+=t.data[n];return Math.abs(Math.ceil(100*e/r/5)-10)*i},e.applyMask=function(t,e){for(var r=e.size,n=0;n<r;n++)for(var o=0;o<r;o++)e.isReserved(o,n)||e.xor(o,n,a(t,o,n))},e.getBestMask=function(t,r){for(var n=Object.keys(e.Patterns).length,o=0,i=1/0,a=0;a<n;a++){r(a),e.applyMask(a,t);var u=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(a,t),u<i&&(i=u,o=a)}return o}}),M=(I.Patterns,I.isValid,I.from,I.getPenaltyN1,I.getPenaltyN2,I.getPenaltyN3,I.getPenaltyN4,I.applyMask,I.getBestMask,[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81]),N=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430],S={getBlocksCount:function(t,e){switch(e){case E.L:return M[4*(t-1)+0];case E.M:return M[4*(t-1)+1];case E.Q:return M[4*(t-1)+2];case E.H:return M[4*(t-1)+3];default:return}},getTotalCodewordsCount:function(t,e){switch(e){case E.L:return N[4*(t-1)+0];case E.M:return N[4*(t-1)+1];case E.Q:return N[4*(t-1)+2];case E.H:return N[4*(t-1)+3];default:return}}},_=new y(512),L=new y(256);!function(){for(var t=1,e=0;e<255;e++)_[e]=t,L[t]=e,256&(t<<=1)&&(t^=285);for(e=255;e<512;e++)_[e]=_[e-255]}();var U=function(t){return _[t]},x=function(t,e){return 0===t||0===e?0:_[L[t]+L[e]]},D=r(function(t,e){e.mul=function(t,e){var r=new y(t.length+e.length-1);r.fill(0);for(var n=0;n<t.length;n++)for(var o=0;o<e.length;o++)r[n+o]^=x(t[n],e[o]);return r},e.mod=function(t,e){for(var r=new y(t);r.length-e.length>=0;){for(var n=r[0],o=0;o<e.length;o++)r[o]^=x(e[o],n);for(var i=0;i<r.length&&0===r[i];)i++;r=r.slice(i)}return r},e.generateECPolynomial=function(t){for(var r=new y([1]),n=0;n<t;n++)r=e.mul(r,[1,U(n)]);return r}});D.mul,D.mod,D.generateECPolynomial;function Y(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}Y.prototype.initialize=function(t){this.degree=t,this.genPoly=D.generateECPolynomial(this.degree)},Y.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");var e=new y(this.degree);e.fill(0);var r=y.concat([t,e],t.length+this.degree),n=D.mod(r,this.genPoly),o=this.degree-n.length;if(o>0){var i=new y(this.degree);return i.fill(0),n.copy(i,o),i}return n};var k=Y,F=function(t){return!isNaN(t)&&t>=1&&t<=40},H="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+",O="(?:(?![A-Z0-9 $%*+\\-./:]|"+(H=H.replace(/u/g,"\\u"))+")(?:.|[\r\n]))+",z=new RegExp(H,"g"),J=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),K=new RegExp(O,"g"),j=new RegExp("[0-9]+","g"),Q=new RegExp("[A-Z $%*+\\-./:]+","g"),V=new RegExp("^"+H+"$"),q=new RegExp("^[0-9]+$"),$=new RegExp("^[A-Z0-9 $%*+\\-./:]+$"),W={KANJI:z,BYTE_KANJI:J,BYTE:K,NUMERIC:j,ALPHANUMERIC:Q,testKanji:function(t){return V.test(t)},testNumeric:function(t){return q.test(t)},testAlphanumeric:function(t){return $.test(t)}},X=r(function(t,e){e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(t,e){if(!t.ccBits)throw new Error("Invalid mode: "+t);if(!F(e))throw new Error("Invalid version: "+e);return e>=1&&e<10?t.ccBits[0]:e<27?t.ccBits[1]:t.ccBits[2]},e.getBestModeForData=function(t){return W.testNumeric(t)?e.NUMERIC:W.testAlphanumeric(t)?e.ALPHANUMERIC:W.testKanji(t)?e.KANJI:e.BYTE},e.toString=function(t){if(t&&t.id)return t.id;throw new Error("Invalid mode")},e.isValid=function(t){return t&&t.bit&&t.ccBits},e.from=function(t,r){if(e.isValid(t))return t;try{return function(t){if("string"!=typeof t)throw new Error("Param is not a string");switch(t.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+t)}}(t)}catch(t){return r}}}),Z=(X.NUMERIC,X.ALPHANUMERIC,X.BYTE,X.KANJI,X.MIXED,X.getCharCountIndicator,X.getBestModeForData,X.isValid,X.from,r(function(t,e){var r=m.getBCHDigit(7973);function n(t,e){return X.getCharCountIndicator(t,e)+4}function o(t,e){var r=0;return t.forEach(function(t){var o=n(t.mode,e);r+=o+t.getBitsLength()}),r}e.from=function(t,e){return F(t)?parseInt(t,10):e},e.getCapacity=function(t,e,r){if(!F(t))throw new Error("Invalid QR Code version");void 0===r&&(r=X.BYTE);var o=8*(m.getSymbolTotalCodewords(t)-S.getTotalCodewordsCount(t,e));if(r===X.MIXED)return o;var i=o-n(r,t);switch(r){case X.NUMERIC:return Math.floor(i/10*3);case X.ALPHANUMERIC:return Math.floor(i/11*2);case X.KANJI:return Math.floor(i/13);case X.BYTE:default:return Math.floor(i/8)}},e.getBestVersionForData=function(t,r){var n,i=E.from(r,E.M);if(u(t)){if(t.length>1)return function(t,r){for(var n=1;n<=40;n++)if(o(t,n)<=e.getCapacity(n,r,X.MIXED))return n}(t,i);if(0===t.length)return 1;n=t[0]}else n=t;return function(t,r,n){for(var o=1;o<=40;o++)if(r<=e.getCapacity(o,n,t))return o}(n.mode,n.getLength(),i)},e.getEncodedBits=function(t){if(!F(t)||t<7)throw new Error("Invalid QR Code version");for(var e=t<<12;m.getBCHDigit(e)-r>=0;)e^=7973<<m.getBCHDigit(e)-r;return t<<12|e}})),G=(Z.from,Z.getCapacity,Z.getBestVersionForData,Z.getEncodedBits,m.getBCHDigit(1335)),tt={getEncodedBits:function(t,e){for(var r=t.bit<<3|e,n=r<<10;m.getBCHDigit(n)-G>=0;)n^=1335<<m.getBCHDigit(n)-G;return 21522^(r<<10|n)}};function et(t){this.mode=X.NUMERIC,this.data=t.toString()}et.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)},et.prototype.getLength=function(){return this.data.length},et.prototype.getBitsLength=function(){return et.getBitsLength(this.data.length)},et.prototype.write=function(t){var e,r,n;for(e=0;e+3<=this.data.length;e+=3)r=this.data.substr(e,3),n=parseInt(r,10),t.put(n,10);var o=this.data.length-e;o>0&&(r=this.data.substr(e),n=parseInt(r,10),t.put(n,3*o+1))};var rt=et,nt=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function ot(t){this.mode=X.ALPHANUMERIC,this.data=t}ot.getBitsLength=function(t){return 11*Math.floor(t/2)+t%2*6},ot.prototype.getLength=function(){return this.data.length},ot.prototype.getBitsLength=function(){return ot.getBitsLength(this.data.length)},ot.prototype.write=function(t){var e;for(e=0;e+2<=this.data.length;e+=2){var r=45*nt.indexOf(this.data[e]);r+=nt.indexOf(this.data[e+1]),t.put(r,11)}this.data.length%2&&t.put(nt.indexOf(this.data[e]),6)};var it=ot;function at(t){this.mode=X.BYTE,this.data=new y(t)}at.getBitsLength=function(t){return 8*t},at.prototype.getLength=function(){return this.data.length},at.prototype.getBitsLength=function(){return at.getBitsLength(this.data.length)},at.prototype.write=function(t){for(var e=0,r=this.data.length;e<r;e++)t.put(this.data[e],8)};var ut=at;function st(t){this.mode=X.KANJI,this.data=t}st.getBitsLength=function(t){return 13*t},st.prototype.getLength=function(){return this.data.length},st.prototype.getBitsLength=function(){return st.getBitsLength(this.data.length)},st.prototype.write=function(t){var e;for(e=0;e<this.data.length;e++){var r=m.toSJIS(this.data[e]);if(r>=33088&&r<=40956)r-=33088;else{if(!(r>=57408&&r<=60351))throw new Error("Invalid SJIS character: "+this.data[e]+"\nMake sure your charset is UTF-8");r-=49472}r=192*(r>>>8&255)+(255&r),t.put(r,13)}};var ft=st,ct=r(function(t){var e={single_source_shortest_paths:function(t,r,n){var o={},i={};i[r]=0;var a,u,s,f,c,l,h,g=e.PriorityQueue.make();for(g.push(r,0);!g.empty();)for(s in u=(a=g.pop()).value,f=a.cost,c=t[u]||{})c.hasOwnProperty(s)&&(l=f+c[s],h=i[s],(void 0===i[s]||h>l)&&(i[s]=l,g.push(s,l),o[s]=u));if(void 0!==n&&void 0===i[n]){var d=["Could not find a path from ",r," to ",n,"."].join("");throw new Error(d)}return o},extract_shortest_path_from_predecessor_list:function(t,e){for(var r=[],n=e;n;)r.push(n),t[n],n=t[n];return r.reverse(),r},find_path:function(t,r,n){var o=e.single_source_shortest_paths(t,r,n);return e.extract_shortest_path_from_predecessor_list(o,n)},PriorityQueue:{make:function(t){var r,n=e.PriorityQueue,o={};for(r in t=t||{},n)n.hasOwnProperty(r)&&(o[r]=n[r]);return o.queue=[],o.sorter=t.sorter||n.default_sorter,o},default_sorter:function(t,e){return t.cost-e.cost},push:function(t,e){var r={value:t,cost:e};this.queue.push(r),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return 0===this.queue.length}}};t.exports=e}),lt=r(function(t,e){function r(t){return unescape(encodeURIComponent(t)).length}function n(t,e,r){for(var n,o=[];null!==(n=t.exec(r));)o.push({data:n[0],index:n.index,mode:e,length:n[0].length});return o}function o(t){var e,r,o=n(W.NUMERIC,X.NUMERIC,t),i=n(W.ALPHANUMERIC,X.ALPHANUMERIC,t);return m.isKanjiModeEnabled()?(e=n(W.BYTE,X.BYTE,t),r=n(W.KANJI,X.KANJI,t)):(e=n(W.BYTE_KANJI,X.BYTE,t),r=[]),o.concat(i,e,r).sort(function(t,e){return t.index-e.index}).map(function(t){return{data:t.data,mode:t.mode,length:t.length}})}function i(t,e){switch(e){case X.NUMERIC:return rt.getBitsLength(t);case X.ALPHANUMERIC:return it.getBitsLength(t);case X.KANJI:return ft.getBitsLength(t);case X.BYTE:return ut.getBitsLength(t)}}function a(t,e){var r,n=X.getBestModeForData(t);if((r=X.from(e,n))!==X.BYTE&&r.bit<n.bit)throw new Error('"'+t+'" cannot be encoded with mode '+X.toString(r)+".\n Suggested mode is: "+X.toString(n));switch(r!==X.KANJI||m.isKanjiModeEnabled()||(r=X.BYTE),r){case X.NUMERIC:return new rt(t);case X.ALPHANUMERIC:return new it(t);case X.KANJI:return new ft(t);case X.BYTE:return new ut(t)}}e.fromArray=function(t){return t.reduce(function(t,e){return"string"==typeof e?t.push(a(e,null)):e.data&&t.push(a(e.data,e.mode)),t},[])},e.fromString=function(t,n){for(var a=function(t,e){for(var r={},n={start:{}},o=["start"],a=0;a<t.length;a++){for(var u=t[a],s=[],f=0;f<u.length;f++){var c=u[f],l=""+a+f;s.push(l),r[l]={node:c,lastCount:0},n[l]={};for(var h=0;h<o.length;h++){var g=o[h];r[g]&&r[g].node.mode===c.mode?(n[g][l]=i(r[g].lastCount+c.length,c.mode)-i(r[g].lastCount,c.mode),r[g].lastCount+=c.length):(r[g]&&(r[g].lastCount=c.length),n[g][l]=i(c.length,c.mode)+4+X.getCharCountIndicator(c.mode,e))}}o=s}for(h=0;h<o.length;h++)n[o[h]].end=0;return{map:n,table:r}}(function(t){for(var e=[],n=0;n<t.length;n++){var o=t[n];switch(o.mode){case X.NUMERIC:e.push([o,{data:o.data,mode:X.ALPHANUMERIC,length:o.length},{data:o.data,mode:X.BYTE,length:o.length}]);break;case X.ALPHANUMERIC:e.push([o,{data:o.data,mode:X.BYTE,length:o.length}]);break;case X.KANJI:e.push([o,{data:o.data,mode:X.BYTE,length:r(o.data)}]);break;case X.BYTE:e.push([{data:o.data,mode:X.BYTE,length:r(o.data)}])}}return e}(o(t,m.isKanjiModeEnabled())),n),u=ct.find_path(a.map,"start","end"),s=[],f=1;f<u.length-1;f++)s.push(a.table[u[f]].node);return e.fromArray(function(t){return t.reduce(function(t,e){var r=t.length-1>=0?t[t.length-1]:null;return r&&r.mode===e.mode?(t[t.length-1].data+=e.data,t):(t.push(e),t)},[])}(s))},e.rawSplit=function(t){return e.fromArray(o(t,m.isKanjiModeEnabled()))}});lt.fromArray,lt.fromString,lt.rawSplit;function ht(t,e,r){var n,o,i=t.size,a=tt.getEncodedBits(e,r);for(n=0;n<15;n++)o=1==(a>>n&1),n<6?t.set(n,8,o,!0):n<8?t.set(n+1,8,o,!0):t.set(i-15+n,8,o,!0),n<8?t.set(8,i-n-1,o,!0):n<9?t.set(8,15-n-1+1,o,!0):t.set(8,15-n-1,o,!0);t.set(i-8,8,1,!0)}function gt(t,e,r){var n=new b;r.forEach(function(e){n.put(e.mode.bit,4),n.put(e.getLength(),X.getCharCountIndicator(e.mode,t)),e.write(n)});var o=8*(m.getSymbolTotalCodewords(t)-S.getTotalCodewordsCount(t,e));for(n.getLengthInBits()+4<=o&&n.put(0,4);n.getLengthInBits()%8!=0;)n.putBit(0);for(var i=(o-n.getLengthInBits())/8,a=0;a<i;a++)n.put(a%2?17:236,8);return function(t,e,r){for(var n=m.getSymbolTotalCodewords(e),o=S.getTotalCodewordsCount(e,r),i=n-o,a=S.getBlocksCount(e,r),u=a-n%a,s=Math.floor(n/a),f=Math.floor(i/a),c=f+1,l=s-f,h=new k(l),g=0,d=new Array(a),p=new Array(a),v=0,w=new y(t.buffer),E=0;E<a;E++){var A=E<u?f:c;d[E]=w.slice(g,g+A),p[E]=h.encode(d[E]),g+=A,v=Math.max(v,A)}var b,B,P=new y(n),C=0;for(b=0;b<v;b++)for(B=0;B<a;B++)b<d[B].length&&(P[C++]=d[B][b]);for(b=0;b<l;b++)for(B=0;B<a;B++)P[C++]=p[B][b];return P}(n,t,e)}function dt(t,e,r,n){var o;if(u(t))o=lt.fromArray(t);else{if("string"!=typeof t)throw new Error("Invalid data");var i=e;if(!i){var a=lt.rawSplit(t);i=Z.getBestVersionForData(a,r)}o=lt.fromString(t,i||40)}var s=Z.getBestVersionForData(o,r);if(!s)throw new Error("The amount of data is too big to be stored in a QR Code");if(e){if(e<s)throw new Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: "+s+".\n")}else e=s;var f=gt(e,r,o),c=m.getSymbolSize(e),l=new P(c);return function(t,e){for(var r=t.size,n=T.getPositions(e),o=0;o<n.length;o++)for(var i=n[o][0],a=n[o][1],u=-1;u<=7;u++)if(!(i+u<=-1||r<=i+u))for(var s=-1;s<=7;s++)a+s<=-1||r<=a+s||(u>=0&&u<=6&&(0===s||6===s)||s>=0&&s<=6&&(0===u||6===u)||u>=2&&u<=4&&s>=2&&s<=4?t.set(i+u,a+s,!0,!0):t.set(i+u,a+s,!1,!0))}(l,e),function(t){for(var e=t.size,r=8;r<e-8;r++){var n=r%2==0;t.set(r,6,n,!0),t.set(6,r,n,!0)}}(l),function(t,e){for(var r=C.getPositions(e),n=0;n<r.length;n++)for(var o=r[n][0],i=r[n][1],a=-2;a<=2;a++)for(var u=-2;u<=2;u++)-2===a||2===a||-2===u||2===u||0===a&&0===u?t.set(o+a,i+u,!0,!0):t.set(o+a,i+u,!1,!0)}(l,e),ht(l,r,0),e>=7&&function(t,e){for(var r,n,o,i=t.size,a=Z.getEncodedBits(e),u=0;u<18;u++)r=Math.floor(u/3),n=u%3+i-8-3,o=1==(a>>u&1),t.set(r,n,o,!0),t.set(n,r,o,!0)}(l,e),function(t,e){for(var r=t.size,n=-1,o=r-1,i=7,a=0,u=r-1;u>0;u-=2)for(6===u&&u--;;){for(var s=0;s<2;s++)if(!t.isReserved(o,u-s)){var f=!1;a<e.length&&(f=1==(e[a]>>>i&1)),t.set(o,u-s,f),-1==--i&&(a++,i=7)}if((o+=n)<0||r<=o){o-=n,n=-n;break}}}(l,f),isNaN(n)&&(n=I.getBestMask(l,ht.bind(null,l,r))),I.applyMask(n,l),ht(l,r,n),{modules:l,version:e,errorCorrectionLevel:r,maskPattern:n,segments:o}}var pt={create:function(t,e){if(void 0===t||""===t)throw new Error("No input text");var r,n,o=E.M;return void 0!==e&&(o=E.from(e.errorCorrectionLevel,E.M),r=Z.from(e.version),n=I.from(e.maskPattern),e.toSJISFunc&&m.setToSJISFunction(e.toSJISFunc)),dt(t,r,o,n)}},vt=r(function(t,e){function r(t){if("string"!=typeof t)throw new Error("Color should be defined as hex string");var e=t.slice().replace("#","").split("");if(e.length<3||5===e.length||e.length>8)throw new Error("Invalid hex color: "+t);3!==e.length&&4!==e.length||(e=Array.prototype.concat.apply([],e.map(function(t){return[t,t]}))),6===e.length&&e.push("F","F");var r=parseInt(e.join(""),16);return{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:255&r,hex:"#"+e.slice(0,6).join("")}}e.getOptions=function(t){t||(t={}),t.color||(t.color={});var e=void 0===t.margin||null===t.margin||t.margin<0?4:t.margin,n=t.width&&t.width>=21?t.width:void 0,o=t.scale||4;return{width:n,scale:n?4:o,margin:e,color:{dark:r(t.color.dark||"#000000ff"),light:r(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}},e.getScale=function(t,e){return e.width&&e.width>=t+2*e.margin?e.width/(t+2*e.margin):e.scale},e.getImageWidth=function(t,r){var n=e.getScale(t,r);return Math.floor((t+2*r.margin)*n)},e.qrToImageData=function(t,r,n){for(var o=r.modules.size,i=r.modules.data,a=e.getScale(o,n),u=Math.floor((o+2*n.margin)*a),s=n.margin*a,f=[n.color.light,n.color.dark],c=0;c<u;c++)for(var l=0;l<u;l++){var h=4*(c*u+l),g=n.color.light;if(c>=s&&l>=s&&c<u-s&&l<u-s)g=f[i[Math.floor((c-s)/a)*o+Math.floor((l-s)/a)]?1:0];t[h++]=g.r,t[h++]=g.g,t[h++]=g.b,t[h]=g.a}}}),yt=(vt.getOptions,vt.getScale,vt.getImageWidth,vt.qrToImageData,r(function(t,e){e.render=function(t,e,r){var n=r,o=e;void 0!==n||e&&e.getContext||(n=e,e=void 0),e||(o=function(){try{return document.createElement("canvas")}catch(t){throw new Error("You need to specify a canvas element")}}()),n=vt.getOptions(n);var i=vt.getImageWidth(t.modules.size,n),a=o.getContext("2d"),u=a.createImageData(i,i);return vt.qrToImageData(u.data,t,n),function(t,e,r){t.clearRect(0,0,e.width,e.height),e.style||(e.style={}),e.height=r,e.width=r,e.style.height=r+"px",e.style.width=r+"px"}(a,o,i),a.putImageData(u,0,0),o},e.renderToDataURL=function(t,r,n){var o=n;void 0!==o||r&&r.getContext||(o=r,r=void 0),o||(o={});var i=e.render(t,r,o),a=o.type||"image/png",u=o.rendererOpts||{};return i.toDataURL(a,u.quality)}}));yt.render,yt.renderToDataURL;function wt(t,e){var r=t.a/255,n=e+'="'+t.hex+'"';return r<1?n+" "+e+'-opacity="'+r.toFixed(2).slice(1)+'"':n}function mt(t,e,r){var n=t+e;return void 0!==r&&(n+=" "+r),n}var Et=function(t,e,r){var n=vt.getOptions(e),o=t.modules.size,i=t.modules.data,a=o+2*n.margin,u=n.color.light.a?"<path "+wt(n.color.light,"fill")+' d="M0 0h'+a+"v"+a+'H0z"/>':"",s="<path "+wt(n.color.dark,"stroke")+' d="'+function(t,e,r){for(var n="",o=0,i=!1,a=0,u=0;u<t.length;u++){var s=Math.floor(u%e),f=Math.floor(u/e);s||i||(i=!0),t[u]?(a++,u>0&&s>0&&t[u-1]||(n+=i?mt("M",s+r,.5+f+r):mt("m",o,0),o=0,i=!1),s+1<e&&t[u+1]||(n+=mt("h",a),a=0)):o++}return n}(i,o,n.margin)+'"/>',f='viewBox="0 0 '+a+" "+a+'"',c='<svg xmlns="http://www.w3.org/2000/svg" '+(n.width?'width="'+n.width+'" height="'+n.width+'" ':"")+f+' shape-rendering="crispEdges">'+u+s+"</svg>\n";return"function"==typeof r&&r(null,c),c};function At(t,e,r,n,o){var a=[].slice.call(arguments,1),u=a.length,s="function"==typeof a[u-1];if(!s&&!i())throw new Error("Callback required as last argument");if(!s){if(u<1)throw new Error("Too few arguments provided");return 1===u?(r=e,e=n=void 0):2!==u||e.getContext||(n=r,r=e,e=void 0),new Promise(function(o,i){try{var a=pt.create(r,n);o(t(a,e,n))}catch(t){i(t)}})}if(u<2)throw new Error("Too few arguments provided");2===u?(o=r,r=e,e=n=void 0):3===u&&(e.getContext&&void 0===o?(o=n,n=void 0):(o=n,n=r,r=e,e=void 0));try{var f=pt.create(r,n);o(null,t(f,e,n))}catch(t){o(t)}}var bt,Bt=pt.create,Pt=At.bind(null,yt.render),Ct=At.bind(null,yt.renderToDataURL),Rt=At.bind(null,function(t,e,r){return Et(t,r)}),Tt=(bt={create:Bt,toCanvas:Pt,toDataURL:Ct,toString:Rt}.toCanvas,function(){var t=Array.prototype.slice.call(arguments);return new Promise(function(e,r){t.push(function(t,n){t?r(t):e(n)}),bt.apply(null,t)})}),It=function(t,e){var r;return r=document.createElement("canvas"),Tt(r,t,e).then(function(){return r.width})},Mt=function(t){return t.length>36?"M":t.length>16?"Q":"H"},Nt=function(t){var e=t.canvas,r=(t.content,t.logo);if(r&&(!r||r.src)){var n=e.width,o=e.height,i=e.getContext("2d"),a=r.logoSize,u=void 0===a?.15:a,s=r.borderColor,f=r.bgColor,c=void 0===f?s||"#ffffff":f,l=r.crossOrigin,h=r.borderRadius,g=void 0===h?0:h,d=r.logoRadius,p=void 0===d?0:d,v=r.logoWidth,y=r.logoHeight,w=r.borderWidth,m=void 0===w?2:w,E=r.borderHeight,A="string"==typeof r?r:r.src,b=(n-(v=v||n*u))/2,B=(o-(y=y||v))/2;if(void 0===E&&(E=m),0!==m||0!==E){var P=2*m+v,C=2*E+y,R=(n-P)/2,T=(o-C)/2;St(i)(R,T,P,C,g),i.fillStyle=c,i.fill()}return new Promise(function(t,e){var r=new Image;(l||p)&&r.setAttribute("crossOrigin",l||"anonymous"),r.src=A,r.onload=function(){p?function(t){var e=void 0;(e=document.createElement("canvas")).width=b+v,e.height=B+y,e.getContext("2d").drawImage(t,b,B,v,y),St(i)(b,B,v,y,p),i.fillStyle=i.createPattern(e,"no-repeat"),i.fill()}(r):function(t){i.drawImage(t,b,B,v,y)}(r),t()}})}},St=function(t){return function(e,r,n,o,i){var a=Math.min(n,o);return i>a/2&&(i=a/2),t.beginPath(),t.moveTo(e+i,r),t.arcTo(e+n,r,e+n,r+o,i),t.arcTo(e+n,r+o,e,r+o,i),t.arcTo(e,r+o,e,r,i),t.arcTo(e,r,e+n,r,i),t.closePath(),t}},_t=function(t){return(e=t,r=e.canvas,n=e.content,o=e.width,i=void 0===o?0:o,a=e.nodeQrCodeOptions,u=void 0===a?{}:a,u.errorCorrectionLevel=Mt(n),It(n,u).then(function(t){return u.scale=0===i?void 0:i/t*4,Tt(r,n,u)})).then(function(){return t}).then(Nt);var e,r,n,o,i,a,u},Lt=function(t,e){var r=t.src,n=document.createElement("a");n.download=e,n.href=r,document.body.appendChild(n),n.click(),document.body.removeChild(n)};return{toCanvas:_t,toImage:function(e){var r=document.createElement("canvas");return e.canvas=r,e.logo&&(t(e.logo)&&(e.logo={src:e.logo}),e.logo.crossOrigin="Anonymous"),_t(e).then(function(){var t=e.image,n=void 0===t?new Image:t,o=e.downloadName,i=void 0===o?"qr-code":o,a=e.download,u=r.toDataURL();null!==n.getAttribute("href")||null!==n.getAttribute("xlink:href")?(n.setAttribute("href",u),n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",u)):n.src=u,(!0===a||"function"==typeof a)&&(a=!0===a?function(t){return t()}:a)(function(){Lt(n,i)})})},toDataURL:function(e){var r=void 0;return r=document.createElement("canvas"),e.canvas=r,e.logo&&(t(e.logo)&&(e.logo={src:e.logo}),e.logo.crossOrigin="Anonymous"),_t(e).then(function(){return r.toDataURL()})}}});