From e96d34f741f79fb089253dd29e916f0c9411a0b8 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Fri, 8 Mar 2019 16:12:54 -0600 Subject: [PATCH] New QR Code component, fixes scanning of long lightning invoices --- .../Views/Invoice/Checkout-Body.cshtml | 2 +- BTCPayServer/Views/Invoice/Checkout.cshtml | 29 +- BTCPayServer/bundleconfig.json | 2 +- .../vendor/vue-qrcode/vue-qrcode.common.js | 3468 ++++++++++++++++ .../vendor/vue-qrcode/vue-qrcode.esm.js | 3466 ++++++++++++++++ .../wwwroot/vendor/vue-qrcode/vue-qrcode.js | 3474 +++++++++++++++++ .../vendor/vue-qrcode/vue-qrcode.min.js | 10 + .../wwwroot/vendor/vuejs/vue-qrcode.js | 1492 ------- .../wwwroot/vendor/vuejs/vue-qrcode.js.map | 9 - .../wwwroot/vendor/vuejs/vue-qrcode.min.js | 1 - 10 files changed, 10433 insertions(+), 1520 deletions(-) create mode 100644 BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.common.js create mode 100644 BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.esm.js create mode 100644 BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.js create mode 100644 BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.min.js delete mode 100644 BTCPayServer/wwwroot/vendor/vuejs/vue-qrcode.js delete mode 100644 BTCPayServer/wwwroot/vendor/vuejs/vue-qrcode.js.map delete mode 100644 BTCPayServer/wwwroot/vendor/vuejs/vue-qrcode.min.js diff --git a/BTCPayServer/Views/Invoice/Checkout-Body.cshtml b/BTCPayServer/Views/Invoice/Checkout-Body.cshtml index fc51704ae..1b2bfaf71 100644 --- a/BTCPayServer/Views/Invoice/Checkout-Body.cshtml +++ b/BTCPayServer/Views/Invoice/Checkout-Body.cshtml @@ -206,7 +206,7 @@
- +
diff --git a/BTCPayServer/Views/Invoice/Checkout.cshtml b/BTCPayServer/Views/Invoice/Checkout.cshtml index 587f877f9..a53573f36 100644 --- a/BTCPayServer/Views/Invoice/Checkout.cshtml +++ b/BTCPayServer/Views/Invoice/Checkout.cshtml @@ -82,15 +82,15 @@ @* Not working because of nsSeparator: false, keySeparator: false, {{$t("nested.lang")}} >> *@ - - - + onchange="changeLanguage($(this).val())" + asp-items="@langService.GetLanguages().Select((language) => new SelectListItem(language.DisplayName,language.Code, false))"> + + diff --git a/BTCPayServer/bundleconfig.json b/BTCPayServer/bundleconfig.json index f934ead9e..0a252ecd9 100644 --- a/BTCPayServer/bundleconfig.json +++ b/BTCPayServer/bundleconfig.json @@ -44,7 +44,7 @@ "wwwroot/vendor/clipboard.js/clipboard.js", "wwwroot/vendor/jquery/jquery.js", "wwwroot/vendor/vuejs/vue.min.js", - "wwwroot/vendor/vuejs/vue-qrcode.js", + "wwwroot/vendor/vue-qrcode/vue-qrcode.js", "wwwroot/vendor/i18next/i18next.js", "wwwroot/vendor/i18next/i18nextXHRBackend.js", "wwwroot/vendor/i18next/vue-i18next.js", diff --git a/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.common.js b/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.common.js new file mode 100644 index 000000000..013f5d70b --- /dev/null +++ b/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.common.js @@ -0,0 +1,3468 @@ +/*! + * vue-qrcode v1.0.0 + * https://fengyuanchen.github.io/vue-qrcode + * + * Copyright 2018-present Chen Fengyuan + * Released under the MIT license + * + * Date: 2018-10-21T13:04:02.951Z + */ + +'use strict'; + +var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + +function commonjsRequire () { + throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs'); +} + +function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; +} + +var qrcode = createCommonjsModule(function (module, exports) { +(function(f){{module.exports=f();}})(function(){return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof commonjsRequire&&commonjsRequire;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t);}return n[i].exports}for(var u="function"==typeof commonjsRequire&&commonjsRequire,i=0;i>> (7 - index % 8)) & 1) === 1 + }, + + put: function (num, length) { + for (var i = 0; i < length; i++) { + this.putBit(((num >>> (length - i - 1)) & 1) === 1); + } + }, + + getLengthInBits: function () { + return this.length + }, + + putBit: function (bit) { + var bufIndex = Math.floor(this.length / 8); + if (this.buffer.length <= bufIndex) { + this.buffer.push(0); + } + + if (bit) { + this.buffer[bufIndex] |= (0x80 >>> (this.length % 8)); + } + + this.length++; + } +}; + +module.exports = BitBuffer; + +},{}],4:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); + +/** + * Helper class to handle QR Code symbol modules + * + * @param {Number} size Symbol size + */ +function BitMatrix (size) { + if (!size || size < 1) { + throw new Error('BitMatrix size must be defined and greater than 0') + } + + this.size = size; + this.data = new Buffer(size * size); + this.data.fill(0); + this.reservedBit = new Buffer(size * size); + this.reservedBit.fill(0); +} + +/** + * Set bit value at specified location + * If reserved flag is set, this bit will be ignored during masking process + * + * @param {Number} row + * @param {Number} col + * @param {Boolean} value + * @param {Boolean} reserved + */ +BitMatrix.prototype.set = function (row, col, value, reserved) { + var index = row * this.size + col; + this.data[index] = value; + if (reserved) this.reservedBit[index] = true; +}; + +/** + * Returns bit value at specified location + * + * @param {Number} row + * @param {Number} col + * @return {Boolean} + */ +BitMatrix.prototype.get = function (row, col) { + return this.data[row * this.size + col] +}; + +/** + * Applies xor operator at specified location + * (used during masking process) + * + * @param {Number} row + * @param {Number} col + * @param {Boolean} value + */ +BitMatrix.prototype.xor = function (row, col, value) { + this.data[row * this.size + col] ^= value; +}; + +/** + * Check if bit at specified location is reserved + * + * @param {Number} row + * @param {Number} col + * @return {Boolean} + */ +BitMatrix.prototype.isReserved = function (row, col) { + return this.reservedBit[row * this.size + col] +}; + +module.exports = BitMatrix; + +},{"../utils/buffer":27}],5:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); +var Mode = require('./mode'); + +function ByteData (data) { + this.mode = Mode.BYTE; + this.data = new Buffer(data); +} + +ByteData.getBitsLength = function getBitsLength (length) { + return length * 8 +}; + +ByteData.prototype.getLength = function getLength () { + return this.data.length +}; + +ByteData.prototype.getBitsLength = function getBitsLength () { + return ByteData.getBitsLength(this.data.length) +}; + +ByteData.prototype.write = function (bitBuffer) { + for (var i = 0, l = this.data.length; i < l; i++) { + bitBuffer.put(this.data[i], 8); + } +}; + +module.exports = ByteData; + +},{"../utils/buffer":27,"./mode":13}],6:[function(require,module,exports){ +var ECLevel = require('./error-correction-level'); + +var EC_BLOCKS_TABLE = [ +// L M Q H + 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 +]; + +var EC_CODEWORDS_TABLE = [ +// L M Q H + 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 +]; + +/** + * Returns the number of error correction block that the QR Code should contain + * for the specified version and error correction level. + * + * @param {Number} version QR Code version + * @param {Number} errorCorrectionLevel Error correction level + * @return {Number} Number of error correction blocks + */ +exports.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) { + switch (errorCorrectionLevel) { + case ECLevel.L: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 0] + case ECLevel.M: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 1] + case ECLevel.Q: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 2] + case ECLevel.H: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 3] + default: + return undefined + } +}; + +/** + * Returns the number of error correction codewords to use for the specified + * version and error correction level. + * + * @param {Number} version QR Code version + * @param {Number} errorCorrectionLevel Error correction level + * @return {Number} Number of error correction codewords + */ +exports.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) { + switch (errorCorrectionLevel) { + case ECLevel.L: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0] + case ECLevel.M: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1] + case ECLevel.Q: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2] + case ECLevel.H: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3] + default: + return undefined + } +}; + +},{"./error-correction-level":7}],7:[function(require,module,exports){ +exports.L = { bit: 1 }; +exports.M = { bit: 0 }; +exports.Q = { bit: 3 }; +exports.H = { bit: 2 }; + +function fromString (string) { + if (typeof string !== 'string') { + throw new Error('Param is not a string') + } + + var lcStr = string.toLowerCase(); + + switch (lcStr) { + case 'l': + case 'low': + return exports.L + + case 'm': + case 'medium': + return exports.M + + case 'q': + case 'quartile': + return exports.Q + + case 'h': + case 'high': + return exports.H + + default: + throw new Error('Unknown EC Level: ' + string) + } +} + +exports.isValid = function isValid (level) { + return level && typeof level.bit !== 'undefined' && + level.bit >= 0 && level.bit < 4 +}; + +exports.from = function from (value, defaultValue) { + if (exports.isValid(value)) { + return value + } + + try { + return fromString(value) + } catch (e) { + return defaultValue + } +}; + +},{}],8:[function(require,module,exports){ +var getSymbolSize = require('./utils').getSymbolSize; +var FINDER_PATTERN_SIZE = 7; + +/** + * Returns an array containing the positions of each finder pattern. + * Each array's element represent the top-left point of the pattern as (x, y) coordinates + * + * @param {Number} version QR Code version + * @return {Array} Array of coordinates + */ +exports.getPositions = function getPositions (version) { + var size = getSymbolSize(version); + + return [ + // top-left + [0, 0], + // top-right + [size - FINDER_PATTERN_SIZE, 0], + // bottom-left + [0, size - FINDER_PATTERN_SIZE] + ] +}; + +},{"./utils":20}],9:[function(require,module,exports){ +var Utils = require('./utils'); + +var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0); +var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1); +var G15_BCH = Utils.getBCHDigit(G15); + +/** + * Returns format information with relative error correction bits + * + * The format information is a 15-bit sequence containing 5 data bits, + * with 10 error correction bits calculated using the (15, 5) BCH code. + * + * @param {Number} errorCorrectionLevel Error correction level + * @param {Number} mask Mask pattern + * @return {Number} Encoded format information bits + */ +exports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) { + var data = ((errorCorrectionLevel.bit << 3) | mask); + var d = data << 10; + + while (Utils.getBCHDigit(d) - G15_BCH >= 0) { + d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH)); + } + + // xor final data with mask pattern in order to ensure that + // no combination of Error Correction Level and data mask pattern + // will result in an all-zero data string + return ((data << 10) | d) ^ G15_MASK +}; + +},{"./utils":20}],10:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); + +var EXP_TABLE = new Buffer(512); +var LOG_TABLE = new Buffer(256) + +/** + * Precompute the log and anti-log tables for faster computation later + * + * For each possible value in the galois field 2^8, we will pre-compute + * the logarithm and anti-logarithm (exponential) of this value + * + * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields} + */ +;(function initTables () { + var x = 1; + for (var i = 0; i < 255; i++) { + EXP_TABLE[i] = x; + LOG_TABLE[x] = i; + + x <<= 1; // multiply by 2 + + // The QR code specification says to use byte-wise modulo 100011101 arithmetic. + // This means that when a number is 256 or larger, it should be XORed with 0x11D. + if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256) + x ^= 0x11D; + } + } + + // Optimization: double the size of the anti-log table so that we don't need to mod 255 to + // stay inside the bounds (because we will mainly use this table for the multiplication of + // two GF numbers, no more). + // @see {@link mul} + for (i = 255; i < 512; i++) { + EXP_TABLE[i] = EXP_TABLE[i - 255]; + } +}()); + +/** + * Returns log value of n inside Galois Field + * + * @param {Number} n + * @return {Number} + */ +exports.log = function log (n) { + if (n < 1) throw new Error('log(' + n + ')') + return LOG_TABLE[n] +}; + +/** + * Returns anti-log value of n inside Galois Field + * + * @param {Number} n + * @return {Number} + */ +exports.exp = function exp (n) { + return EXP_TABLE[n] +}; + +/** + * Multiplies two number inside Galois Field + * + * @param {Number} x + * @param {Number} y + * @return {Number} + */ +exports.mul = function mul (x, y) { + if (x === 0 || y === 0) return 0 + + // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized + // @see {@link initTables} + return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]] +}; + +},{"../utils/buffer":27}],11:[function(require,module,exports){ +var Mode = require('./mode'); +var Utils = require('./utils'); + +function KanjiData (data) { + this.mode = Mode.KANJI; + this.data = data; +} + +KanjiData.getBitsLength = function getBitsLength (length) { + return length * 13 +}; + +KanjiData.prototype.getLength = function getLength () { + return this.data.length +}; + +KanjiData.prototype.getBitsLength = function getBitsLength () { + return KanjiData.getBitsLength(this.data.length) +}; + +KanjiData.prototype.write = function (bitBuffer) { + var i; + + // In the Shift JIS system, Kanji characters are represented by a two byte combination. + // These byte values are shifted from the JIS X 0208 values. + // JIS X 0208 gives details of the shift coded representation. + for (i = 0; i < this.data.length; i++) { + var value = Utils.toSJIS(this.data[i]); + + // For characters with Shift JIS values from 0x8140 to 0x9FFC: + if (value >= 0x8140 && value <= 0x9FFC) { + // Subtract 0x8140 from Shift JIS value + value -= 0x8140; + + // For characters with Shift JIS values from 0xE040 to 0xEBBF + } else if (value >= 0xE040 && value <= 0xEBBF) { + // Subtract 0xC140 from Shift JIS value + value -= 0xC140; + } else { + throw new Error( + 'Invalid SJIS character: ' + this.data[i] + '\n' + + 'Make sure your charset is UTF-8') + } + + // Multiply most significant byte of result by 0xC0 + // and add least significant byte to product + value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff); + + // Convert result to a 13-bit binary string + bitBuffer.put(value, 13); + } +}; + +module.exports = KanjiData; + +},{"./mode":13,"./utils":20}],12:[function(require,module,exports){ +/** + * Data mask pattern reference + * @type {Object} + */ +exports.Patterns = { + PATTERN000: 0, + PATTERN001: 1, + PATTERN010: 2, + PATTERN011: 3, + PATTERN100: 4, + PATTERN101: 5, + PATTERN110: 6, + PATTERN111: 7 +}; + +/** + * Weighted penalty scores for the undesirable features + * @type {Object} + */ +var PenaltyScores = { + N1: 3, + N2: 3, + N3: 40, + N4: 10 +}; + +/** + * Check if mask pattern value is valid + * + * @param {Number} mask Mask pattern + * @return {Boolean} true if valid, false otherwise + */ +exports.isValid = function isValid (mask) { + return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7 +}; + +/** + * Returns mask pattern from a value. + * If value is not valid, returns undefined + * + * @param {Number|String} value Mask pattern value + * @return {Number} Valid mask pattern or undefined + */ +exports.from = function from (value) { + return exports.isValid(value) ? parseInt(value, 10) : undefined +}; + +/** +* Find adjacent modules in row/column with the same color +* and assign a penalty value. +* +* Points: N1 + i +* i is the amount by which the number of adjacent modules of the same color exceeds 5 +*/ +exports.getPenaltyN1 = function getPenaltyN1 (data) { + var size = data.size; + var points = 0; + var sameCountCol = 0; + var sameCountRow = 0; + var lastCol = null; + var lastRow = null; + + for (var row = 0; row < size; row++) { + sameCountCol = sameCountRow = 0; + lastCol = lastRow = null; + + for (var col = 0; col < size; col++) { + var module = data.get(row, col); + if (module === lastCol) { + sameCountCol++; + } else { + if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5); + lastCol = module; + sameCountCol = 1; + } + + module = data.get(col, row); + if (module === lastRow) { + sameCountRow++; + } else { + if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5); + lastRow = module; + sameCountRow = 1; + } + } + + if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5); + if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5); + } + + return points +}; + +/** + * Find 2x2 blocks with the same color and assign a penalty value + * + * Points: N2 * (m - 1) * (n - 1) + */ +exports.getPenaltyN2 = function getPenaltyN2 (data) { + var size = data.size; + var points = 0; + + for (var row = 0; row < size - 1; row++) { + for (var col = 0; col < size - 1; col++) { + var last = data.get(row, col) + + data.get(row, col + 1) + + data.get(row + 1, col) + + data.get(row + 1, col + 1); + + if (last === 4 || last === 0) points++; + } + } + + return points * PenaltyScores.N2 +}; + +/** + * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column, + * preceded or followed by light area 4 modules wide + * + * Points: N3 * number of pattern found + */ +exports.getPenaltyN3 = function getPenaltyN3 (data) { + var size = data.size; + var points = 0; + var bitsCol = 0; + var bitsRow = 0; + + for (var row = 0; row < size; row++) { + bitsCol = bitsRow = 0; + for (var col = 0; col < size; col++) { + bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col); + if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++; + + bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row); + if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++; + } + } + + return points * PenaltyScores.N3 +}; + +/** + * Calculate proportion of dark modules in entire symbol + * + * Points: N4 * k + * + * k is the rating of the deviation of the proportion of dark modules + * in the symbol from 50% in steps of 5% + */ +exports.getPenaltyN4 = function getPenaltyN4 (data) { + var darkCount = 0; + var modulesCount = data.data.length; + + for (var i = 0; i < modulesCount; i++) darkCount += data.data[i]; + + var k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10); + + return k * PenaltyScores.N4 +}; + +/** + * Return mask value at given position + * + * @param {Number} maskPattern Pattern reference value + * @param {Number} i Row + * @param {Number} j Column + * @return {Boolean} Mask value + */ +function getMaskAt (maskPattern, i, j) { + switch (maskPattern) { + case exports.Patterns.PATTERN000: return (i + j) % 2 === 0 + case exports.Patterns.PATTERN001: return i % 2 === 0 + case exports.Patterns.PATTERN010: return j % 3 === 0 + case exports.Patterns.PATTERN011: return (i + j) % 3 === 0 + case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0 + case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0 + case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0 + case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0 + + default: throw new Error('bad maskPattern:' + maskPattern) + } +} + +/** + * Apply a mask pattern to a BitMatrix + * + * @param {Number} pattern Pattern reference number + * @param {BitMatrix} data BitMatrix data + */ +exports.applyMask = function applyMask (pattern, data) { + var size = data.size; + + for (var col = 0; col < size; col++) { + for (var row = 0; row < size; row++) { + if (data.isReserved(row, col)) continue + data.xor(row, col, getMaskAt(pattern, row, col)); + } + } +}; + +/** + * Returns the best mask pattern for data + * + * @param {BitMatrix} data + * @return {Number} Mask pattern reference number + */ +exports.getBestMask = function getBestMask (data, setupFormatFunc) { + var numPatterns = Object.keys(exports.Patterns).length; + var bestPattern = 0; + var lowerPenalty = Infinity; + + for (var p = 0; p < numPatterns; p++) { + setupFormatFunc(p); + exports.applyMask(p, data); + + // Calculate penalty + var penalty = + exports.getPenaltyN1(data) + + exports.getPenaltyN2(data) + + exports.getPenaltyN3(data) + + exports.getPenaltyN4(data); + + // Undo previously applied mask + exports.applyMask(p, data); + + if (penalty < lowerPenalty) { + lowerPenalty = penalty; + bestPattern = p; + } + } + + return bestPattern +}; + +},{}],13:[function(require,module,exports){ +var VersionCheck = require('./version-check'); +var Regex = require('./regex'); + +/** + * Numeric mode encodes data from the decimal digit set (0 - 9) + * (byte values 30HEX to 39HEX). + * Normally, 3 data characters are represented by 10 bits. + * + * @type {Object} + */ +exports.NUMERIC = { + id: 'Numeric', + bit: 1 << 0, + ccBits: [10, 12, 14] +}; + +/** + * Alphanumeric mode encodes data from a set of 45 characters, + * i.e. 10 numeric digits (0 - 9), + * 26 alphabetic characters (A - Z), + * and 9 symbols (SP, $, %, *, +, -, ., /, :). + * Normally, two input characters are represented by 11 bits. + * + * @type {Object} + */ +exports.ALPHANUMERIC = { + id: 'Alphanumeric', + bit: 1 << 1, + ccBits: [9, 11, 13] +}; + +/** + * In byte mode, data is encoded at 8 bits per character. + * + * @type {Object} + */ +exports.BYTE = { + id: 'Byte', + bit: 1 << 2, + ccBits: [8, 16, 16] +}; + +/** + * The Kanji mode efficiently encodes Kanji characters in accordance with + * the Shift JIS system based on JIS X 0208. + * The Shift JIS values are shifted from the JIS X 0208 values. + * JIS X 0208 gives details of the shift coded representation. + * Each two-byte character value is compacted to a 13-bit binary codeword. + * + * @type {Object} + */ +exports.KANJI = { + id: 'Kanji', + bit: 1 << 3, + ccBits: [8, 10, 12] +}; + +/** + * Mixed mode will contain a sequences of data in a combination of any of + * the modes described above + * + * @type {Object} + */ +exports.MIXED = { + bit: -1 +}; + +/** + * Returns the number of bits needed to store the data length + * according to QR Code specifications. + * + * @param {Mode} mode Data mode + * @param {Number} version QR Code version + * @return {Number} Number of bits + */ +exports.getCharCountIndicator = function getCharCountIndicator (mode, version) { + if (!mode.ccBits) throw new Error('Invalid mode: ' + mode) + + if (!VersionCheck.isValid(version)) { + throw new Error('Invalid version: ' + version) + } + + if (version >= 1 && version < 10) return mode.ccBits[0] + else if (version < 27) return mode.ccBits[1] + return mode.ccBits[2] +}; + +/** + * Returns the most efficient mode to store the specified data + * + * @param {String} dataStr Input data string + * @return {Mode} Best mode + */ +exports.getBestModeForData = function getBestModeForData (dataStr) { + if (Regex.testNumeric(dataStr)) return exports.NUMERIC + else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC + else if (Regex.testKanji(dataStr)) return exports.KANJI + else return exports.BYTE +}; + +/** + * Return mode name as string + * + * @param {Mode} mode Mode object + * @returns {String} Mode name + */ +exports.toString = function toString (mode) { + if (mode && mode.id) return mode.id + throw new Error('Invalid mode') +}; + +/** + * Check if input param is a valid mode object + * + * @param {Mode} mode Mode object + * @returns {Boolean} True if valid mode, false otherwise + */ +exports.isValid = function isValid (mode) { + return mode && mode.bit && mode.ccBits +}; + +/** + * Get mode object from its name + * + * @param {String} string Mode name + * @returns {Mode} Mode object + */ +function fromString (string) { + if (typeof string !== 'string') { + throw new Error('Param is not a string') + } + + var lcStr = string.toLowerCase(); + + switch (lcStr) { + case 'numeric': + return exports.NUMERIC + case 'alphanumeric': + return exports.ALPHANUMERIC + case 'kanji': + return exports.KANJI + case 'byte': + return exports.BYTE + default: + throw new Error('Unknown mode: ' + string) + } +} + +/** + * Returns mode from a value. + * If value is not a valid mode, returns defaultValue + * + * @param {Mode|String} value Encoding mode + * @param {Mode} defaultValue Fallback value + * @return {Mode} Encoding mode + */ +exports.from = function from (value, defaultValue) { + if (exports.isValid(value)) { + return value + } + + try { + return fromString(value) + } catch (e) { + return defaultValue + } +}; + +},{"./regex":18,"./version-check":21}],14:[function(require,module,exports){ +var Mode = require('./mode'); + +function NumericData (data) { + this.mode = Mode.NUMERIC; + this.data = data.toString(); +} + +NumericData.getBitsLength = function getBitsLength (length) { + return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0) +}; + +NumericData.prototype.getLength = function getLength () { + return this.data.length +}; + +NumericData.prototype.getBitsLength = function getBitsLength () { + return NumericData.getBitsLength(this.data.length) +}; + +NumericData.prototype.write = function write (bitBuffer) { + var i, group, value; + + // The input data string is divided into groups of three digits, + // and each group is converted to its 10-bit binary equivalent. + for (i = 0; i + 3 <= this.data.length; i += 3) { + group = this.data.substr(i, 3); + value = parseInt(group, 10); + + bitBuffer.put(value, 10); + } + + // If the number of input digits is not an exact multiple of three, + // the final one or two digits are converted to 4 or 7 bits respectively. + var remainingNum = this.data.length - i; + if (remainingNum > 0) { + group = this.data.substr(i); + value = parseInt(group, 10); + + bitBuffer.put(value, remainingNum * 3 + 1); + } +}; + +module.exports = NumericData; + +},{"./mode":13}],15:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); +var GF = require('./galois-field'); + +/** + * Multiplies two polynomials inside Galois Field + * + * @param {Buffer} p1 Polynomial + * @param {Buffer} p2 Polynomial + * @return {Buffer} Product of p1 and p2 + */ +exports.mul = function mul (p1, p2) { + var coeff = new Buffer(p1.length + p2.length - 1); + coeff.fill(0); + + for (var i = 0; i < p1.length; i++) { + for (var j = 0; j < p2.length; j++) { + coeff[i + j] ^= GF.mul(p1[i], p2[j]); + } + } + + return coeff +}; + +/** + * Calculate the remainder of polynomials division + * + * @param {Buffer} divident Polynomial + * @param {Buffer} divisor Polynomial + * @return {Buffer} Remainder + */ +exports.mod = function mod (divident, divisor) { + var result = new Buffer(divident); + + while ((result.length - divisor.length) >= 0) { + var coeff = result[0]; + + for (var i = 0; i < divisor.length; i++) { + result[i] ^= GF.mul(divisor[i], coeff); + } + + // remove all zeros from buffer head + var offset = 0; + while (offset < result.length && result[offset] === 0) offset++; + result = result.slice(offset); + } + + return result +}; + +/** + * Generate an irreducible generator polynomial of specified degree + * (used by Reed-Solomon encoder) + * + * @param {Number} degree Degree of the generator polynomial + * @return {Buffer} Buffer containing polynomial coefficients + */ +exports.generateECPolynomial = function generateECPolynomial (degree) { + var poly = new Buffer([1]); + for (var i = 0; i < degree; i++) { + poly = exports.mul(poly, [1, GF.exp(i)]); + } + + return poly +}; + +},{"../utils/buffer":27,"./galois-field":10}],16:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); +var Utils = require('./utils'); +var ECLevel = require('./error-correction-level'); +var BitBuffer = require('./bit-buffer'); +var BitMatrix = require('./bit-matrix'); +var AlignmentPattern = require('./alignment-pattern'); +var FinderPattern = require('./finder-pattern'); +var MaskPattern = require('./mask-pattern'); +var ECCode = require('./error-correction-code'); +var ReedSolomonEncoder = require('./reed-solomon-encoder'); +var Version = require('./version'); +var FormatInfo = require('./format-info'); +var Mode = require('./mode'); +var Segments = require('./segments'); +var isArray = require('isarray'); + +/** + * QRCode for JavaScript + * + * modified by Ryan Day for nodejs support + * Copyright (c) 2011 Ryan Day + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/mit-license.php + * +//--------------------------------------------------------------------- +// QRCode for JavaScript +// +// Copyright (c) 2009 Kazuhiko Arase +// +// URL: http://www.d-project.com/ +// +// Licensed under the MIT license: +// http://www.opensource.org/licenses/mit-license.php +// +// The word "QR Code" is registered trademark of +// DENSO WAVE INCORPORATED +// http://www.denso-wave.com/qrcode/faqpatent-e.html +// +//--------------------------------------------------------------------- +*/ + +/** + * Add finder patterns bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {Number} version QR Code version + */ +function setupFinderPattern (matrix, version) { + var size = matrix.size; + var pos = FinderPattern.getPositions(version); + + for (var i = 0; i < pos.length; i++) { + var row = pos[i][0]; + var col = pos[i][1]; + + for (var r = -1; r <= 7; r++) { + if (row + r <= -1 || size <= row + r) continue + + for (var c = -1; c <= 7; c++) { + if (col + c <= -1 || size <= col + c) continue + + if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) || + (c >= 0 && c <= 6 && (r === 0 || r === 6)) || + (r >= 2 && r <= 4 && c >= 2 && c <= 4)) { + matrix.set(row + r, col + c, true, true); + } else { + matrix.set(row + r, col + c, false, true); + } + } + } + } +} + +/** + * Add timing pattern bits to matrix + * + * Note: this function must be called before {@link setupAlignmentPattern} + * + * @param {BitMatrix} matrix Modules matrix + */ +function setupTimingPattern (matrix) { + var size = matrix.size; + + for (var r = 8; r < size - 8; r++) { + var value = r % 2 === 0; + matrix.set(r, 6, value, true); + matrix.set(6, r, value, true); + } +} + +/** + * Add alignment patterns bits to matrix + * + * Note: this function must be called after {@link setupTimingPattern} + * + * @param {BitMatrix} matrix Modules matrix + * @param {Number} version QR Code version + */ +function setupAlignmentPattern (matrix, version) { + var pos = AlignmentPattern.getPositions(version); + + for (var i = 0; i < pos.length; i++) { + var row = pos[i][0]; + var col = pos[i][1]; + + for (var r = -2; r <= 2; r++) { + for (var c = -2; c <= 2; c++) { + if (r === -2 || r === 2 || c === -2 || c === 2 || + (r === 0 && c === 0)) { + matrix.set(row + r, col + c, true, true); + } else { + matrix.set(row + r, col + c, false, true); + } + } + } + } +} + +/** + * Add version info bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {Number} version QR Code version + */ +function setupVersionInfo (matrix, version) { + var size = matrix.size; + var bits = Version.getEncodedBits(version); + var row, col, mod; + + for (var i = 0; i < 18; i++) { + row = Math.floor(i / 3); + col = i % 3 + size - 8 - 3; + mod = ((bits >> i) & 1) === 1; + + matrix.set(row, col, mod, true); + matrix.set(col, row, mod, true); + } +} + +/** + * Add format info bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level + * @param {Number} maskPattern Mask pattern reference value + */ +function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) { + var size = matrix.size; + var bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern); + var i, mod; + + for (i = 0; i < 15; i++) { + mod = ((bits >> i) & 1) === 1; + + // vertical + if (i < 6) { + matrix.set(i, 8, mod, true); + } else if (i < 8) { + matrix.set(i + 1, 8, mod, true); + } else { + matrix.set(size - 15 + i, 8, mod, true); + } + + // horizontal + if (i < 8) { + matrix.set(8, size - i - 1, mod, true); + } else if (i < 9) { + matrix.set(8, 15 - i - 1 + 1, mod, true); + } else { + matrix.set(8, 15 - i - 1, mod, true); + } + } + + // fixed module + matrix.set(size - 8, 8, 1, true); +} + +/** + * Add encoded data bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {Buffer} data Data codewords + */ +function setupData (matrix, data) { + var size = matrix.size; + var inc = -1; + var row = size - 1; + var bitIndex = 7; + var byteIndex = 0; + + for (var col = size - 1; col > 0; col -= 2) { + if (col === 6) col--; + + while (true) { + for (var c = 0; c < 2; c++) { + if (!matrix.isReserved(row, col - c)) { + var dark = false; + + if (byteIndex < data.length) { + dark = (((data[byteIndex] >>> bitIndex) & 1) === 1); + } + + matrix.set(row, col - c, dark); + bitIndex--; + + if (bitIndex === -1) { + byteIndex++; + bitIndex = 7; + } + } + } + + row += inc; + + if (row < 0 || size <= row) { + row -= inc; + inc = -inc; + break + } + } + } +} + +/** + * Create encoded codewords from data input + * + * @param {Number} version QR Code version + * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level + * @param {ByteData} data Data input + * @return {Buffer} Buffer containing encoded codewords + */ +function createData (version, errorCorrectionLevel, segments) { + // Prepare data buffer + var buffer = new BitBuffer(); + + segments.forEach(function (data) { + // prefix data with mode indicator (4 bits) + buffer.put(data.mode.bit, 4); + + // Prefix data with character count indicator. + // The character count indicator is a string of bits that represents the + // number of characters that are being encoded. + // The character count indicator must be placed after the mode indicator + // and must be a certain number of bits long, depending on the QR version + // and data mode + // @see {@link Mode.getCharCountIndicator}. + buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version)); + + // add binary data sequence to buffer + data.write(buffer); + }); + + // Calculate required number of bits + var totalCodewords = Utils.getSymbolTotalCodewords(version); + var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel); + var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8; + + // Add a terminator. + // If the bit string is shorter than the total number of required bits, + // a terminator of up to four 0s must be added to the right side of the string. + // If the bit string is more than four bits shorter than the required number of bits, + // add four 0s to the end. + if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) { + buffer.put(0, 4); + } + + // If the bit string is fewer than four bits shorter, add only the number of 0s that + // are needed to reach the required number of bits. + + // After adding the terminator, if the number of bits in the string is not a multiple of 8, + // pad the string on the right with 0s to make the string's length a multiple of 8. + while (buffer.getLengthInBits() % 8 !== 0) { + buffer.putBit(0); + } + + // Add pad bytes if the string is still shorter than the total number of required bits. + // Extend the buffer to fill the data capacity of the symbol corresponding to + // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC) + // and 00010001 (0x11) alternately. + var remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8; + for (var i = 0; i < remainingByte; i++) { + buffer.put(i % 2 ? 0x11 : 0xEC, 8); + } + + return createCodewords(buffer, version, errorCorrectionLevel) +} + +/** + * Encode input data with Reed-Solomon and return codewords with + * relative error correction bits + * + * @param {BitBuffer} bitBuffer Data to encode + * @param {Number} version QR Code version + * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level + * @return {Buffer} Buffer containing encoded codewords + */ +function createCodewords (bitBuffer, version, errorCorrectionLevel) { + // Total codewords for this QR code version (Data + Error correction) + var totalCodewords = Utils.getSymbolTotalCodewords(version); + + // Total number of error correction codewords + var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel); + + // Total number of data codewords + var dataTotalCodewords = totalCodewords - ecTotalCodewords; + + // Total number of blocks + var ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel); + + // Calculate how many blocks each group should contain + var blocksInGroup2 = totalCodewords % ecTotalBlocks; + var blocksInGroup1 = ecTotalBlocks - blocksInGroup2; + + var totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks); + + var dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks); + var dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1; + + // Number of EC codewords is the same for both groups + var ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1; + + // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount + var rs = new ReedSolomonEncoder(ecCount); + + var offset = 0; + var dcData = new Array(ecTotalBlocks); + var ecData = new Array(ecTotalBlocks); + var maxDataSize = 0; + var buffer = new Buffer(bitBuffer.buffer); + + // Divide the buffer into the required number of blocks + for (var b = 0; b < ecTotalBlocks; b++) { + var dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2; + + // extract a block of data from buffer + dcData[b] = buffer.slice(offset, offset + dataSize); + + // Calculate EC codewords for this data block + ecData[b] = rs.encode(dcData[b]); + + offset += dataSize; + maxDataSize = Math.max(maxDataSize, dataSize); + } + + // Create final data + // Interleave the data and error correction codewords from each block + var data = new Buffer(totalCodewords); + var index = 0; + var i, r; + + // Add data codewords + for (i = 0; i < maxDataSize; i++) { + for (r = 0; r < ecTotalBlocks; r++) { + if (i < dcData[r].length) { + data[index++] = dcData[r][i]; + } + } + } + + // Apped EC codewords + for (i = 0; i < ecCount; i++) { + for (r = 0; r < ecTotalBlocks; r++) { + data[index++] = ecData[r][i]; + } + } + + return data +} + +/** + * Build QR Code symbol + * + * @param {String} data Input string + * @param {Number} version QR Code version + * @param {ErrorCorretionLevel} errorCorrectionLevel Error level + * @param {MaskPattern} maskPattern Mask pattern + * @return {Object} Object containing symbol data + */ +function createSymbol (data, version, errorCorrectionLevel, maskPattern) { + var segments; + + if (isArray(data)) { + segments = Segments.fromArray(data); + } else if (typeof data === 'string') { + var estimatedVersion = version; + + if (!estimatedVersion) { + var rawSegments = Segments.rawSplit(data); + + // Estimate best version that can contain raw splitted segments + estimatedVersion = Version.getBestVersionForData(rawSegments, + errorCorrectionLevel); + } + + // Build optimized segments + // If estimated version is undefined, try with the highest version + segments = Segments.fromString(data, estimatedVersion || 40); + } else { + throw new Error('Invalid data') + } + + // Get the min version that can contain data + var bestVersion = Version.getBestVersionForData(segments, + errorCorrectionLevel); + + // If no version is found, data cannot be stored + if (!bestVersion) { + throw new Error('The amount of data is too big to be stored in a QR Code') + } + + // If not specified, use min version as default + if (!version) { + version = bestVersion; + + // Check if the specified version can contain the data + } else if (version < bestVersion) { + throw new Error('\n' + + 'The chosen QR Code version cannot contain this amount of data.\n' + + 'Minimum version required to store current data is: ' + bestVersion + '.\n' + ) + } + + var dataBits = createData(version, errorCorrectionLevel, segments); + + // Allocate matrix buffer + var moduleCount = Utils.getSymbolSize(version); + var modules = new BitMatrix(moduleCount); + + // Add function modules + setupFinderPattern(modules, version); + setupTimingPattern(modules); + setupAlignmentPattern(modules, version); + + // Add temporary dummy bits for format info just to set them as reserved. + // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask} + // since the masking operation must be performed only on the encoding region. + // These blocks will be replaced with correct values later in code. + setupFormatInfo(modules, errorCorrectionLevel, 0); + + if (version >= 7) { + setupVersionInfo(modules, version); + } + + // Add data codewords + setupData(modules, dataBits); + + if (isNaN(maskPattern)) { + // Find best mask pattern + maskPattern = MaskPattern.getBestMask(modules, + setupFormatInfo.bind(null, modules, errorCorrectionLevel)); + } + + // Apply mask pattern + MaskPattern.applyMask(maskPattern, modules); + + // Replace format info bits with correct values + setupFormatInfo(modules, errorCorrectionLevel, maskPattern); + + return { + modules: modules, + version: version, + errorCorrectionLevel: errorCorrectionLevel, + maskPattern: maskPattern, + segments: segments + } +} + +/** + * QR Code + * + * @param {String | Array} data Input data + * @param {Object} options Optional configurations + * @param {Number} options.version QR Code version + * @param {String} options.errorCorrectionLevel Error correction level + * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis + */ +exports.create = function create (data, options) { + if (typeof data === 'undefined' || data === '') { + throw new Error('No input text') + } + + var errorCorrectionLevel = ECLevel.M; + var version; + var mask; + + if (typeof options !== 'undefined') { + // Use higher error correction level as default + errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M); + version = Version.from(options.version); + mask = MaskPattern.from(options.maskPattern); + + if (options.toSJISFunc) { + Utils.setToSJISFunction(options.toSJISFunc); + } + } + + return createSymbol(data, version, errorCorrectionLevel, mask) +}; + +},{"../utils/buffer":27,"./alignment-pattern":1,"./bit-buffer":3,"./bit-matrix":4,"./error-correction-code":6,"./error-correction-level":7,"./finder-pattern":8,"./format-info":9,"./mask-pattern":12,"./mode":13,"./reed-solomon-encoder":17,"./segments":19,"./utils":20,"./version":22,"isarray":30}],17:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); +var Polynomial = require('./polynomial'); + +function ReedSolomonEncoder (degree) { + this.genPoly = undefined; + this.degree = degree; + + if (this.degree) this.initialize(this.degree); +} + +/** + * Initialize the encoder. + * The input param should correspond to the number of error correction codewords. + * + * @param {Number} degree + */ +ReedSolomonEncoder.prototype.initialize = function initialize (degree) { + // create an irreducible generator polynomial + this.degree = degree; + this.genPoly = Polynomial.generateECPolynomial(this.degree); +}; + +/** + * Encodes a chunk of data + * + * @param {Buffer} data Buffer containing input data + * @return {Buffer} Buffer containing encoded data + */ +ReedSolomonEncoder.prototype.encode = function encode (data) { + if (!this.genPoly) { + throw new Error('Encoder not initialized') + } + + // Calculate EC for this data block + // extends data size to data+genPoly size + var pad = new Buffer(this.degree); + pad.fill(0); + var paddedData = Buffer.concat([data, pad], data.length + this.degree); + + // The error correction codewords are the remainder after dividing the data codewords + // by a generator polynomial + var remainder = Polynomial.mod(paddedData, this.genPoly); + + // return EC data blocks (last n byte, where n is the degree of genPoly) + // If coefficients number in remainder are less than genPoly degree, + // pad with 0s to the left to reach the needed number of coefficients + var start = this.degree - remainder.length; + if (start > 0) { + var buff = new Buffer(this.degree); + buff.fill(0); + remainder.copy(buff, start); + + return buff + } + + return remainder +}; + +module.exports = ReedSolomonEncoder; + +},{"../utils/buffer":27,"./polynomial":15}],18:[function(require,module,exports){ +var numeric = '[0-9]+'; +var alphanumeric = '[A-Z $%*+\\-./:]+'; +var kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' + + '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' + + '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' + + '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+'; +kanji = kanji.replace(/u/g, '\\u'); + +var byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+'; + +exports.KANJI = new RegExp(kanji, 'g'); +exports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g'); +exports.BYTE = new RegExp(byte, 'g'); +exports.NUMERIC = new RegExp(numeric, 'g'); +exports.ALPHANUMERIC = new RegExp(alphanumeric, 'g'); + +var TEST_KANJI = new RegExp('^' + kanji + '$'); +var TEST_NUMERIC = new RegExp('^' + numeric + '$'); +var TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$'); + +exports.testKanji = function testKanji (str) { + return TEST_KANJI.test(str) +}; + +exports.testNumeric = function testNumeric (str) { + return TEST_NUMERIC.test(str) +}; + +exports.testAlphanumeric = function testAlphanumeric (str) { + return TEST_ALPHANUMERIC.test(str) +}; + +},{}],19:[function(require,module,exports){ +var Mode = require('./mode'); +var NumericData = require('./numeric-data'); +var AlphanumericData = require('./alphanumeric-data'); +var ByteData = require('./byte-data'); +var KanjiData = require('./kanji-data'); +var Regex = require('./regex'); +var Utils = require('./utils'); +var dijkstra = require('dijkstrajs'); + +/** + * Returns UTF8 byte length + * + * @param {String} str Input string + * @return {Number} Number of byte + */ +function getStringByteLength (str) { + return unescape(encodeURIComponent(str)).length +} + +/** + * Get a list of segments of the specified mode + * from a string + * + * @param {Mode} mode Segment mode + * @param {String} str String to process + * @return {Array} Array of object with segments data + */ +function getSegments (regex, mode, str) { + var segments = []; + var result; + + while ((result = regex.exec(str)) !== null) { + segments.push({ + data: result[0], + index: result.index, + mode: mode, + length: result[0].length + }); + } + + return segments +} + +/** + * Extracts a series of segments with the appropriate + * modes from a string + * + * @param {String} dataStr Input string + * @return {Array} Array of object with segments data + */ +function getSegmentsFromString (dataStr) { + var numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr); + var alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr); + var byteSegs; + var kanjiSegs; + + if (Utils.isKanjiModeEnabled()) { + byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr); + kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr); + } else { + byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr); + kanjiSegs = []; + } + + var segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs); + + return segs + .sort(function (s1, s2) { + return s1.index - s2.index + }) + .map(function (obj) { + return { + data: obj.data, + mode: obj.mode, + length: obj.length + } + }) +} + +/** + * Returns how many bits are needed to encode a string of + * specified length with the specified mode + * + * @param {Number} length String length + * @param {Mode} mode Segment mode + * @return {Number} Bit length + */ +function getSegmentBitsLength (length, mode) { + switch (mode) { + case Mode.NUMERIC: + return NumericData.getBitsLength(length) + case Mode.ALPHANUMERIC: + return AlphanumericData.getBitsLength(length) + case Mode.KANJI: + return KanjiData.getBitsLength(length) + case Mode.BYTE: + return ByteData.getBitsLength(length) + } +} + +/** + * Merges adjacent segments which have the same mode + * + * @param {Array} segs Array of object with segments data + * @return {Array} Array of object with segments data + */ +function mergeSegments (segs) { + return segs.reduce(function (acc, curr) { + var prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null; + if (prevSeg && prevSeg.mode === curr.mode) { + acc[acc.length - 1].data += curr.data; + return acc + } + + acc.push(curr); + return acc + }, []) +} + +/** + * Generates a list of all possible nodes combination which + * will be used to build a segments graph. + * + * Nodes are divided by groups. Each group will contain a list of all the modes + * in which is possible to encode the given text. + * + * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte. + * The group for '12345' will contain then 3 objects, one for each + * possible encoding mode. + * + * Each node represents a possible segment. + * + * @param {Array} segs Array of object with segments data + * @return {Array} Array of object with segments data + */ +function buildNodes (segs) { + var nodes = []; + for (var i = 0; i < segs.length; i++) { + var seg = segs[i]; + + switch (seg.mode) { + case Mode.NUMERIC: + nodes.push([seg, + { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length }, + { data: seg.data, mode: Mode.BYTE, length: seg.length } + ]); + break + case Mode.ALPHANUMERIC: + nodes.push([seg, + { data: seg.data, mode: Mode.BYTE, length: seg.length } + ]); + break + case Mode.KANJI: + nodes.push([seg, + { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) } + ]); + break + case Mode.BYTE: + nodes.push([ + { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) } + ]); + } + } + + return nodes +} + +/** + * Builds a graph from a list of nodes. + * All segments in each node group will be connected with all the segments of + * the next group and so on. + * + * At each connection will be assigned a weight depending on the + * segment's byte length. + * + * @param {Array} nodes Array of object with segments data + * @param {Number} version QR Code version + * @return {Object} Graph of all possible segments + */ +function buildGraph (nodes, version) { + var table = {}; + var graph = {'start': {}}; + var prevNodeIds = ['start']; + + for (var i = 0; i < nodes.length; i++) { + var nodeGroup = nodes[i]; + var currentNodeIds = []; + + for (var j = 0; j < nodeGroup.length; j++) { + var node = nodeGroup[j]; + var key = '' + i + j; + + currentNodeIds.push(key); + table[key] = { node: node, lastCount: 0 }; + graph[key] = {}; + + for (var n = 0; n < prevNodeIds.length; n++) { + var prevNodeId = prevNodeIds[n]; + + if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) { + graph[prevNodeId][key] = + getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - + getSegmentBitsLength(table[prevNodeId].lastCount, node.mode); + + table[prevNodeId].lastCount += node.length; + } else { + if (table[prevNodeId]) table[prevNodeId].lastCount = node.length; + + graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + + 4 + Mode.getCharCountIndicator(node.mode, version); // switch cost + } + } + } + + prevNodeIds = currentNodeIds; + } + + for (n = 0; n < prevNodeIds.length; n++) { + graph[prevNodeIds[n]]['end'] = 0; + } + + return { map: graph, table: table } +} + +/** + * Builds a segment from a specified data and mode. + * If a mode is not specified, the more suitable will be used. + * + * @param {String} data Input data + * @param {Mode | String} modesHint Data mode + * @return {Segment} Segment + */ +function buildSingleSegment (data, modesHint) { + var mode; + var bestMode = Mode.getBestModeForData(data); + + mode = Mode.from(modesHint, bestMode); + + // Make sure data can be encoded + if (mode !== Mode.BYTE && mode.bit < bestMode.bit) { + throw new Error('"' + data + '"' + + ' cannot be encoded with mode ' + Mode.toString(mode) + + '.\n Suggested mode is: ' + Mode.toString(bestMode)) + } + + // Use Mode.BYTE if Kanji support is disabled + if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) { + mode = Mode.BYTE; + } + + switch (mode) { + case Mode.NUMERIC: + return new NumericData(data) + + case Mode.ALPHANUMERIC: + return new AlphanumericData(data) + + case Mode.KANJI: + return new KanjiData(data) + + case Mode.BYTE: + return new ByteData(data) + } +} + +/** + * Builds a list of segments from an array. + * Array can contain Strings or Objects with segment's info. + * + * For each item which is a string, will be generated a segment with the given + * string and the more appropriate encoding mode. + * + * For each item which is an object, will be generated a segment with the given + * data and mode. + * Objects must contain at least the property "data". + * If property "mode" is not present, the more suitable mode will be used. + * + * @param {Array} array Array of objects with segments data + * @return {Array} Array of Segments + */ +exports.fromArray = function fromArray (array) { + return array.reduce(function (acc, seg) { + if (typeof seg === 'string') { + acc.push(buildSingleSegment(seg, null)); + } else if (seg.data) { + acc.push(buildSingleSegment(seg.data, seg.mode)); + } + + return acc + }, []) +}; + +/** + * Builds an optimized sequence of segments from a string, + * which will produce the shortest possible bitstream. + * + * @param {String} data Input string + * @param {Number} version QR Code version + * @return {Array} Array of segments + */ +exports.fromString = function fromString (data, version) { + var segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled()); + + var nodes = buildNodes(segs); + var graph = buildGraph(nodes, version); + var path = dijkstra.find_path(graph.map, 'start', 'end'); + + var optimizedSegs = []; + for (var i = 1; i < path.length - 1; i++) { + optimizedSegs.push(graph.table[path[i]].node); + } + + return exports.fromArray(mergeSegments(optimizedSegs)) +}; + +/** + * Splits a string in various segments with the modes which + * best represent their content. + * The produced segments are far from being optimized. + * The output of this function is only used to estimate a QR Code version + * which may contain the data. + * + * @param {string} data Input string + * @return {Array} Array of segments + */ +exports.rawSplit = function rawSplit (data) { + return exports.fromArray( + getSegmentsFromString(data, Utils.isKanjiModeEnabled()) + ) +}; + +},{"./alphanumeric-data":2,"./byte-data":5,"./kanji-data":11,"./mode":13,"./numeric-data":14,"./regex":18,"./utils":20,"dijkstrajs":29}],20:[function(require,module,exports){ +var toSJISFunction; +var CODEWORDS_COUNT = [ + 0, // Not used + 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 +]; + +/** + * Returns the QR Code size for the specified version + * + * @param {Number} version QR Code version + * @return {Number} size of QR code + */ +exports.getSymbolSize = function getSymbolSize (version) { + if (!version) throw new Error('"version" cannot be null or undefined') + if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40') + return version * 4 + 17 +}; + +/** + * Returns the total number of codewords used to store data and EC information. + * + * @param {Number} version QR Code version + * @return {Number} Data length in bits + */ +exports.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) { + return CODEWORDS_COUNT[version] +}; + +/** + * Encode data with Bose-Chaudhuri-Hocquenghem + * + * @param {Number} data Value to encode + * @return {Number} Encoded value + */ +exports.getBCHDigit = function (data) { + var digit = 0; + + while (data !== 0) { + digit++; + data >>>= 1; + } + + return digit +}; + +exports.setToSJISFunction = function setToSJISFunction (f) { + if (typeof f !== 'function') { + throw new Error('"toSJISFunc" is not a valid function.') + } + + toSJISFunction = f; +}; + +exports.isKanjiModeEnabled = function () { + return typeof toSJISFunction !== 'undefined' +}; + +exports.toSJIS = function toSJIS (kanji) { + return toSJISFunction(kanji) +}; + +},{}],21:[function(require,module,exports){ +/** + * Check if QR Code version is valid + * + * @param {Number} version QR Code version + * @return {Boolean} true if valid version, false otherwise + */ +exports.isValid = function isValid (version) { + return !isNaN(version) && version >= 1 && version <= 40 +}; + +},{}],22:[function(require,module,exports){ +var Utils = require('./utils'); +var ECCode = require('./error-correction-code'); +var ECLevel = require('./error-correction-level'); +var Mode = require('./mode'); +var VersionCheck = require('./version-check'); +var isArray = require('isarray'); + +// Generator polynomial used to encode version information +var G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0); +var G18_BCH = Utils.getBCHDigit(G18); + +function getBestVersionForDataLength (mode, length, errorCorrectionLevel) { + for (var currentVersion = 1; currentVersion <= 40; currentVersion++) { + if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) { + return currentVersion + } + } + + return undefined +} + +function getReservedBitsCount (mode, version) { + // Character count indicator + mode indicator bits + return Mode.getCharCountIndicator(mode, version) + 4 +} + +function getTotalBitsFromDataArray (segments, version) { + var totalBits = 0; + + segments.forEach(function (data) { + var reservedBits = getReservedBitsCount(data.mode, version); + totalBits += reservedBits + data.getBitsLength(); + }); + + return totalBits +} + +function getBestVersionForMixedData (segments, errorCorrectionLevel) { + for (var currentVersion = 1; currentVersion <= 40; currentVersion++) { + var length = getTotalBitsFromDataArray(segments, currentVersion); + if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) { + return currentVersion + } + } + + return undefined +} + +/** + * Returns version number from a value. + * If value is not a valid version, returns defaultValue + * + * @param {Number|String} value QR Code version + * @param {Number} defaultValue Fallback value + * @return {Number} QR Code version number + */ +exports.from = function from (value, defaultValue) { + if (VersionCheck.isValid(value)) { + return parseInt(value, 10) + } + + return defaultValue +}; + +/** + * Returns how much data can be stored with the specified QR code version + * and error correction level + * + * @param {Number} version QR Code version (1-40) + * @param {Number} errorCorrectionLevel Error correction level + * @param {Mode} mode Data mode + * @return {Number} Quantity of storable data + */ +exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) { + if (!VersionCheck.isValid(version)) { + throw new Error('Invalid QR Code version') + } + + // Use Byte mode as default + if (typeof mode === 'undefined') mode = Mode.BYTE; + + // Total codewords for this QR code version (Data + Error correction) + var totalCodewords = Utils.getSymbolTotalCodewords(version); + + // Total number of error correction codewords + var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel); + + // Total number of data codewords + var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8; + + if (mode === Mode.MIXED) return dataTotalCodewordsBits + + var usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version); + + // Return max number of storable codewords + switch (mode) { + case Mode.NUMERIC: + return Math.floor((usableBits / 10) * 3) + + case Mode.ALPHANUMERIC: + return Math.floor((usableBits / 11) * 2) + + case Mode.KANJI: + return Math.floor(usableBits / 13) + + case Mode.BYTE: + default: + return Math.floor(usableBits / 8) + } +}; + +/** + * Returns the minimum version needed to contain the amount of data + * + * @param {Segment} data Segment of data + * @param {Number} [errorCorrectionLevel=H] Error correction level + * @param {Mode} mode Data mode + * @return {Number} QR Code version + */ +exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) { + var seg; + + var ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M); + + if (isArray(data)) { + if (data.length > 1) { + return getBestVersionForMixedData(data, ecl) + } + + if (data.length === 0) { + return 1 + } + + seg = data[0]; + } else { + seg = data; + } + + return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl) +}; + +/** + * Returns version information with relative error correction bits + * + * The version information is included in QR Code symbols of version 7 or larger. + * It consists of an 18-bit sequence containing 6 data bits, + * with 12 error correction bits calculated using the (18, 6) Golay code. + * + * @param {Number} version QR Code version + * @return {Number} Encoded version info bits + */ +exports.getEncodedBits = function getEncodedBits (version) { + if (!VersionCheck.isValid(version) || version < 7) { + throw new Error('Invalid QR Code version') + } + + var d = version << 12; + + while (Utils.getBCHDigit(d) - G18_BCH >= 0) { + d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH)); + } + + return (version << 12) | d +}; + +},{"./error-correction-code":6,"./error-correction-level":7,"./mode":13,"./utils":20,"./version-check":21,"isarray":30}],23:[function(require,module,exports){ +var canPromise = require('can-promise'); +var QRCode = require('./core/qrcode'); +var CanvasRenderer = require('./renderer/canvas'); +var SvgRenderer = require('./renderer/svg-tag.js'); + +function renderCanvas (renderFunc, canvas, text, opts, cb) { + var args = [].slice.call(arguments, 1); + var argsNum = args.length; + var isLastArgCb = typeof args[argsNum - 1] === 'function'; + + if (!isLastArgCb && !canPromise()) { + throw new Error('Callback required as last argument') + } + + if (isLastArgCb) { + if (argsNum < 2) { + throw new Error('Too few arguments provided') + } + + if (argsNum === 2) { + cb = text; + text = canvas; + canvas = opts = undefined; + } else if (argsNum === 3) { + if (canvas.getContext && typeof cb === 'undefined') { + cb = opts; + opts = undefined; + } else { + cb = opts; + opts = text; + text = canvas; + canvas = undefined; + } + } + } else { + if (argsNum < 1) { + throw new Error('Too few arguments provided') + } + + if (argsNum === 1) { + text = canvas; + canvas = opts = undefined; + } else if (argsNum === 2 && !canvas.getContext) { + opts = text; + text = canvas; + canvas = undefined; + } + + return new Promise(function (resolve, reject) { + try { + var data = QRCode.create(text, opts); + resolve(renderFunc(data, canvas, opts)); + } catch (e) { + reject(e); + } + }) + } + + try { + var data = QRCode.create(text, opts); + cb(null, renderFunc(data, canvas, opts)); + } catch (e) { + cb(e); + } +} + +exports.create = QRCode.create; +exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render); +exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL); + +// only svg for now. +exports.toString = renderCanvas.bind(null, function (data, _, opts) { + return SvgRenderer.render(data, opts) +}); + +},{"./core/qrcode":16,"./renderer/canvas":24,"./renderer/svg-tag.js":25,"can-promise":28}],24:[function(require,module,exports){ +var Utils = require('./utils'); + +function clearCanvas (ctx, canvas, size) { + ctx.clearRect(0, 0, canvas.width, canvas.height); + + if (!canvas.style) canvas.style = {}; + canvas.height = size; + canvas.width = size; + canvas.style.height = size + 'px'; + canvas.style.width = size + 'px'; +} + +function getCanvasElement () { + try { + return document.createElement('canvas') + } catch (e) { + throw new Error('You need to specify a canvas element') + } +} + +exports.render = function render (qrData, canvas, options) { + var opts = options; + var canvasEl = canvas; + + if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) { + opts = canvas; + canvas = undefined; + } + + if (!canvas) { + canvasEl = getCanvasElement(); + } + + opts = Utils.getOptions(opts); + var size = Utils.getImageWidth(qrData.modules.size, opts); + + var ctx = canvasEl.getContext('2d'); + var image = ctx.createImageData(size, size); + Utils.qrToImageData(image.data, qrData, opts); + + clearCanvas(ctx, canvasEl, size); + ctx.putImageData(image, 0, 0); + + return canvasEl +}; + +exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) { + var opts = options; + + if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) { + opts = canvas; + canvas = undefined; + } + + if (!opts) opts = {}; + + var canvasEl = exports.render(qrData, canvas, opts); + + var type = opts.type || 'image/png'; + var rendererOpts = opts.rendererOpts || {}; + + return canvasEl.toDataURL(type, rendererOpts.quality) +}; + +},{"./utils":26}],25:[function(require,module,exports){ +var Utils = require('./utils'); + +function getColorAttrib (color, attrib) { + var alpha = color.a / 255; + var str = attrib + '="' + color.hex + '"'; + + return alpha < 1 + ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' + : str +} + +function svgCmd (cmd, x, y) { + var str = cmd + x; + if (typeof y !== 'undefined') str += ' ' + y; + + return str +} + +function qrToPath (data, size, margin) { + var path = ''; + var moveBy = 0; + var newRow = false; + var lineLength = 0; + + for (var i = 0; i < data.length; i++) { + var col = Math.floor(i % size); + var row = Math.floor(i / size); + + if (!col && !newRow) newRow = true; + + if (data[i]) { + lineLength++; + + if (!(i > 0 && col > 0 && data[i - 1])) { + path += newRow + ? svgCmd('M', col + margin, 0.5 + row + margin) + : svgCmd('m', moveBy, 0); + + moveBy = 0; + newRow = false; + } + + if (!(col + 1 < size && data[i + 1])) { + path += svgCmd('h', lineLength); + lineLength = 0; + } + } else { + moveBy++; + } + } + + return path +} + +exports.render = function render (qrData, options, cb) { + var opts = Utils.getOptions(options); + var size = qrData.modules.size; + var data = qrData.modules.data; + var qrcodesize = size + opts.margin * 2; + + var bg = !opts.color.light.a + ? '' + : ''; + + var path = + ''; + + var viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"'; + + var width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" '; + + var svgTag = '' + bg + path + '\n'; + + if (typeof cb === 'function') { + cb(null, svgTag); + } + + return svgTag +}; + +},{"./utils":26}],26:[function(require,module,exports){ +function hex2rgba (hex) { + if (typeof hex !== 'string') { + throw new Error('Color should be defined as hex string') + } + + var hexCode = hex.slice().replace('#', '').split(''); + if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) { + throw new Error('Invalid hex color: ' + hex) + } + + // Convert from short to long form (fff -> ffffff) + if (hexCode.length === 3 || hexCode.length === 4) { + hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) { + return [c, c] + })); + } + + // Add default alpha value + if (hexCode.length === 6) hexCode.push('F', 'F'); + + var hexValue = parseInt(hexCode.join(''), 16); + + return { + r: (hexValue >> 24) & 255, + g: (hexValue >> 16) & 255, + b: (hexValue >> 8) & 255, + a: hexValue & 255, + hex: '#' + hexCode.slice(0, 6).join('') + } +} + +exports.getOptions = function getOptions (options) { + if (!options) options = {}; + if (!options.color) options.color = {}; + + var margin = typeof options.margin === 'undefined' || + options.margin === null || + options.margin < 0 ? 4 : options.margin; + + var width = options.width && options.width >= 21 ? options.width : undefined; + var scale = options.scale || 4; + + return { + width: width, + scale: width ? 4 : scale, + margin: margin, + color: { + dark: hex2rgba(options.color.dark || '#000000ff'), + light: hex2rgba(options.color.light || '#ffffffff') + }, + type: options.type, + rendererOpts: options.rendererOpts || {} + } +}; + +exports.getScale = function getScale (qrSize, opts) { + return opts.width && opts.width >= qrSize + opts.margin * 2 + ? opts.width / (qrSize + opts.margin * 2) + : opts.scale +}; + +exports.getImageWidth = function getImageWidth (qrSize, opts) { + var scale = exports.getScale(qrSize, opts); + return Math.floor((qrSize + opts.margin * 2) * scale) +}; + +exports.qrToImageData = function qrToImageData (imgData, qr, opts) { + var size = qr.modules.size; + var data = qr.modules.data; + var scale = exports.getScale(size, opts); + var symbolSize = Math.floor((size + opts.margin * 2) * scale); + var scaledMargin = opts.margin * scale; + var palette = [opts.color.light, opts.color.dark]; + + for (var i = 0; i < symbolSize; i++) { + for (var j = 0; j < symbolSize; j++) { + var posDst = (i * symbolSize + j) * 4; + var pxColor = opts.color.light; + + if (i >= scaledMargin && j >= scaledMargin && + i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) { + var iSrc = Math.floor((i - scaledMargin) / scale); + var jSrc = Math.floor((j - scaledMargin) / scale); + pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0]; + } + + imgData[posDst++] = pxColor.r; + imgData[posDst++] = pxColor.g; + imgData[posDst++] = pxColor.b; + imgData[posDst] = pxColor.a; + } + } +}; + +},{}],27:[function(require,module,exports){ + +var isArray = require('isarray'); + +function typedArraySupport () { + // Can typed array instances be augmented? + try { + var arr = new Uint8Array(1); + arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}; + return arr.foo() === 42 + } catch (e) { + return false + } +} + +Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); + +var K_MAX_LENGTH = Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff; + +function Buffer (arg, offset, length) { + if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { + return new Buffer(arg, offset, length) + } + + if (typeof arg === 'number') { + return allocUnsafe(this, arg) + } + + return from(this, arg, offset, length) +} + +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype; + Buffer.__proto__ = Uint8Array; + + // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 + if (typeof Symbol !== 'undefined' && Symbol.species && + Buffer[Symbol.species] === Buffer) { + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true, + enumerable: false, + writable: false + }); + } +} + +function checked (length) { + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= K_MAX_LENGTH) { + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') + } + return length | 0 +} + +function isnan (val) { + return val !== val // eslint-disable-line no-self-compare +} + +function createBuffer (that, length) { + var buf; + if (Buffer.TYPED_ARRAY_SUPPORT) { + buf = new Uint8Array(length); + buf.__proto__ = Buffer.prototype; + } else { + // Fallback: Return an object instance of the Buffer class + buf = that; + if (buf === null) { + buf = new Buffer(length); + } + buf.length = length; + } + + return buf +} + +function allocUnsafe (that, size) { + var buf = createBuffer(that, size < 0 ? 0 : checked(size) | 0); + + if (!Buffer.TYPED_ARRAY_SUPPORT) { + for (var i = 0; i < size; ++i) { + buf[i] = 0; + } + } + + return buf +} + +function fromString (that, string) { + var length = byteLength(string) | 0; + var buf = createBuffer(that, length); + + var actual = buf.write(string); + + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + buf = buf.slice(0, actual); + } + + return buf +} + +function fromArrayLike (that, array) { + var length = array.length < 0 ? 0 : checked(array.length) | 0; + var buf = createBuffer(that, length); + for (var i = 0; i < length; i += 1) { + buf[i] = array[i] & 255; + } + return buf +} + +function fromArrayBuffer (that, array, byteOffset, length) { + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('\'offset\' is out of bounds') + } + + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('\'length\' is out of bounds') + } + + var buf; + if (byteOffset === undefined && length === undefined) { + buf = new Uint8Array(array); + } else if (length === undefined) { + buf = new Uint8Array(array, byteOffset); + } else { + buf = new Uint8Array(array, byteOffset, length); + } + + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + buf.__proto__ = Buffer.prototype; + } else { + // Fallback: Return an object instance of the Buffer class + buf = fromArrayLike(that, buf); + } + + return buf +} + +function fromObject (that, obj) { + if (Buffer.isBuffer(obj)) { + var len = checked(obj.length) | 0; + var buf = createBuffer(that, len); + + if (buf.length === 0) { + return buf + } + + obj.copy(buf, 0, 0, len); + return buf + } + + if (obj) { + if ((typeof ArrayBuffer !== 'undefined' && + obj.buffer instanceof ArrayBuffer) || 'length' in obj) { + if (typeof obj.length !== 'number' || isnan(obj.length)) { + return createBuffer(that, 0) + } + return fromArrayLike(that, obj) + } + + if (obj.type === 'Buffer' && Array.isArray(obj.data)) { + return fromArrayLike(that, obj.data) + } + } + + throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') +} + +function utf8ToBytes (string, units) { + units = units || Infinity; + var codePoint; + var length = string.length; + var leadSurrogate = null; + var bytes = []; + + for (var i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i); + + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + continue + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + continue + } + + // valid lead + leadSurrogate = codePoint; + + continue + } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + leadSurrogate = codePoint; + continue + } + + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000; + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + } + + leadSurrogate = null; + + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break + bytes.push(codePoint); + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break + bytes.push( + codePoint >> 0x6 | 0xC0, + codePoint & 0x3F | 0x80 + ); + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break + bytes.push( + codePoint >> 0xC | 0xE0, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ); + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break + bytes.push( + codePoint >> 0x12 | 0xF0, + codePoint >> 0xC & 0x3F | 0x80, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ); + } else { + throw new Error('Invalid code point') + } + } + + return bytes +} + +function byteLength (string) { + if (Buffer.isBuffer(string)) { + return string.length + } + if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && + (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { + return string.byteLength + } + if (typeof string !== 'string') { + string = '' + string; + } + + var len = string.length; + if (len === 0) return 0 + + return utf8ToBytes(string).length +} + +function blitBuffer (src, dst, offset, length) { + for (var i = 0; i < length; ++i) { + if ((i + offset >= dst.length) || (i >= src.length)) break + dst[i + offset] = src[i]; + } + return i +} + +function utf8Write (buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) +} + +function from (that, value, offset, length) { + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number') + } + + if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { + return fromArrayBuffer(that, value, offset, length) + } + + if (typeof value === 'string') { + return fromString(that, value, offset) + } + + return fromObject(that, value) +} + +Buffer.prototype.write = function write (string, offset, length) { + // Buffer#write(string) + if (offset === undefined) { + length = this.length; + offset = 0; + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + length = this.length; + offset = 0; + // Buffer#write(string, offset[, length]) + } else if (isFinite(offset)) { + offset = offset | 0; + if (isFinite(length)) { + length = length | 0; + } else { + length = undefined; + } + } + + var remaining = this.length - offset; + if (length === undefined || length > remaining) length = remaining; + + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { + throw new RangeError('Attempt to write outside buffer bounds') + } + + return utf8Write(this, string, offset, length) +}; + +Buffer.prototype.slice = function slice (start, end) { + var len = this.length; + start = ~~start; + end = end === undefined ? len : ~~end; + + if (start < 0) { + start += len; + if (start < 0) start = 0; + } else if (start > len) { + start = len; + } + + if (end < 0) { + end += len; + if (end < 0) end = 0; + } else if (end > len) { + end = len; + } + + if (end < start) end = start; + + var newBuf; + if (Buffer.TYPED_ARRAY_SUPPORT) { + newBuf = this.subarray(start, end); + // Return an augmented `Uint8Array` instance + newBuf.__proto__ = Buffer.prototype; + } else { + var sliceLen = end - start; + newBuf = new Buffer(sliceLen, undefined); + for (var i = 0; i < sliceLen; ++i) { + newBuf[i] = this[i + start]; + } + } + + return newBuf +}; + +Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!start) start = 0; + if (!end && end !== 0) end = this.length; + if (targetStart >= target.length) targetStart = target.length; + if (!targetStart) targetStart = 0; + if (end > 0 && end < start) end = start; + + // Copy 0 bytes; we're done + if (end === start) return 0 + if (target.length === 0 || this.length === 0) return 0 + + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError('targetStart out of bounds') + } + if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') + if (end < 0) throw new RangeError('sourceEnd out of bounds') + + // Are we oob? + if (end > this.length) end = this.length; + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start; + } + + var len = end - start; + var i; + + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; --i) { + target[i + targetStart] = this[i + start]; + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; ++i) { + target[i + targetStart] = this[i + start]; + } + } else { + Uint8Array.prototype.set.call( + target, + this.subarray(start, start + len), + targetStart + ); + } + + return len +}; + +Buffer.prototype.fill = function fill (val, start, end) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + start = 0; + end = this.length; + } else if (typeof end === 'string') { + end = this.length; + } + if (val.length === 1) { + var code = val.charCodeAt(0); + if (code < 256) { + val = code; + } + } + } else if (typeof val === 'number') { + val = val & 255; + } + + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError('Out of range index') + } + + if (end <= start) { + return this + } + + start = start >>> 0; + end = end === undefined ? this.length : end >>> 0; + + if (!val) val = 0; + + var i; + if (typeof val === 'number') { + for (i = start; i < end; ++i) { + this[i] = val; + } + } else { + var bytes = Buffer.isBuffer(val) + ? val + : new Buffer(val); + var len = bytes.length; + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len]; + } + } + + return this +}; + +Buffer.concat = function concat (list, length) { + if (!isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + + if (list.length === 0) { + return createBuffer(null, 0) + } + + var i; + if (length === undefined) { + length = 0; + for (i = 0; i < list.length; ++i) { + length += list[i].length; + } + } + + var buffer = allocUnsafe(null, length); + var pos = 0; + for (i = 0; i < list.length; ++i) { + var buf = list[i]; + if (!Buffer.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + buf.copy(buffer, pos); + pos += buf.length; + } + return buffer +}; + +Buffer.byteLength = byteLength; + +Buffer.prototype._isBuffer = true; +Buffer.isBuffer = function isBuffer (b) { + return !!(b != null && b._isBuffer) +}; + +module.exports = Buffer; + +},{"isarray":30}],28:[function(require,module,exports){ + +var G = require('window-or-global'); + +module.exports = function() { + return ( + typeof G.Promise === 'function' && + typeof G.Promise.prototype.then === 'function' + ) +}; + +},{"window-or-global":31}],29:[function(require,module,exports){ + +/****************************************************************************** + * Created 2008-08-19. + * + * Dijkstra path-finding functions. Adapted from the Dijkstar Python project. + * + * Copyright (C) 2008 + * Wyatt Baldwin + * All rights reserved + * + * Licensed under the MIT license. + * + * http://www.opensource.org/licenses/mit-license.php + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + *****************************************************************************/ +var dijkstra = { + single_source_shortest_paths: function(graph, s, d) { + // Predecessor map for each node that has been encountered. + // node ID => predecessor node ID + var predecessors = {}; + + // Costs of shortest paths from s to all nodes encountered. + // node ID => cost + var costs = {}; + costs[s] = 0; + + // Costs of shortest paths from s to all nodes encountered; differs from + // `costs` in that it provides easy access to the node that currently has + // the known shortest path from s. + // XXX: Do we actually need both `costs` and `open`? + var open = dijkstra.PriorityQueue.make(); + open.push(s, 0); + + var closest, + u, v, + cost_of_s_to_u, + adjacent_nodes, + cost_of_e, + cost_of_s_to_u_plus_cost_of_e, + cost_of_s_to_v, + first_visit; + while (!open.empty()) { + // In the nodes remaining in graph that have a known cost from s, + // find the node, u, that currently has the shortest path from s. + closest = open.pop(); + u = closest.value; + cost_of_s_to_u = closest.cost; + + // Get nodes adjacent to u... + adjacent_nodes = graph[u] || {}; + + // ...and explore the edges that connect u to those nodes, updating + // the cost of the shortest paths to any or all of those nodes as + // necessary. v is the node across the current edge from u. + for (v in adjacent_nodes) { + if (adjacent_nodes.hasOwnProperty(v)) { + // Get the cost of the edge running from u to v. + cost_of_e = adjacent_nodes[v]; + + // Cost of s to u plus the cost of u to v across e--this is *a* + // cost from s to v that may or may not be less than the current + // known cost to v. + cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e; + + // If we haven't visited v yet OR if the current known cost from s to + // v is greater than the new cost we just found (cost of s to u plus + // cost of u to v across e), update v's cost in the cost list and + // update v's predecessor in the predecessor list (it's now u). + cost_of_s_to_v = costs[v]; + first_visit = (typeof costs[v] === 'undefined'); + if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) { + costs[v] = cost_of_s_to_u_plus_cost_of_e; + open.push(v, cost_of_s_to_u_plus_cost_of_e); + predecessors[v] = u; + } + } + } + } + + if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') { + var msg = ['Could not find a path from ', s, ' to ', d, '.'].join(''); + throw new Error(msg); + } + + return predecessors; + }, + + extract_shortest_path_from_predecessor_list: function(predecessors, d) { + var nodes = []; + var u = d; + var predecessor; + while (u) { + nodes.push(u); + predecessor = predecessors[u]; + u = predecessors[u]; + } + nodes.reverse(); + return nodes; + }, + + find_path: function(graph, s, d) { + var predecessors = dijkstra.single_source_shortest_paths(graph, s, d); + return dijkstra.extract_shortest_path_from_predecessor_list( + predecessors, d); + }, + + /** + * A very naive priority queue implementation. + */ + PriorityQueue: { + make: function (opts) { + var T = dijkstra.PriorityQueue, + t = {}, + key; + opts = opts || {}; + for (key in T) { + if (T.hasOwnProperty(key)) { + t[key] = T[key]; + } + } + t.queue = []; + t.sorter = opts.sorter || T.default_sorter; + return t; + }, + + default_sorter: function (a, b) { + return a.cost - b.cost; + }, + + /** + * Add a new item to the queue and ensure the highest priority element + * is at the front of the queue. + */ + push: function (value, cost) { + var item = {value: value, cost: cost}; + this.queue.push(item); + this.queue.sort(this.sorter); + }, + + /** + * Return the highest priority element in the queue. + */ + pop: function () { + return this.queue.shift(); + }, + + empty: function () { + return this.queue.length === 0; + } + } +}; + + +// node.js module exports +if (typeof module !== 'undefined') { + module.exports = dijkstra; +} + +},{}],30:[function(require,module,exports){ +var toString = {}.toString; + +module.exports = Array.isArray || function (arr) { + return toString.call(arr) == '[object Array]'; +}; + +},{}],31:[function(require,module,exports){ +(function (global){ +module.exports = (typeof self === 'object' && self.self === self && self) || + (typeof global === 'object' && global.global === global && global) || + this; + +}).call(this,typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}); + +},{}]},{},[23])(23) +}); + + +}); + +var index = { + name: 'qrcode', + props: { + /** + * The options for the QR code generator. + * {@link https://github.com/soldair/node-qrcode#qr-code-options} + */ + options: Object, + + /** + * The tag name of the component's root element. + */ + tag: { + type: String, + default: 'canvas' + }, + + /** + * The value of the QR code. + */ + value: null + }, + render: function render(createElement) { + return createElement(this.tag, this.$slots.default); + }, + watch: { + $props: { + deep: true, + immediate: true, + handler: function handler() { + if (this.$el) { + this.generate(); + } + } + } + }, + methods: { + /** + * Generate QR code. + */ + generate: function generate() { + var _this = this; + + var options = this.options, + tag = this.tag; + var value = String(this.value); + + if (tag === 'canvas') { + qrcode.toCanvas(this.$el, value, options, function (error) { + if (error) { + throw error; + } + }); + } else if (tag === 'img') { + qrcode.toDataURL(value, options, function (error, url) { + if (error) { + throw error; + } + + _this.$el.src = url; + }); + } else { + qrcode.toString(value, options, function (error, string) { + if (error) { + throw error; + } + + _this.$el.innerHTML = string; + }); + } + } + }, + mounted: function mounted() { + this.generate(); + } +}; + +module.exports = index; diff --git a/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.esm.js b/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.esm.js new file mode 100644 index 000000000..5bac0f9be --- /dev/null +++ b/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.esm.js @@ -0,0 +1,3466 @@ +/*! + * vue-qrcode v1.0.0 + * https://fengyuanchen.github.io/vue-qrcode + * + * Copyright 2018-present Chen Fengyuan + * Released under the MIT license + * + * Date: 2018-10-21T13:04:02.951Z + */ + +var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + +function commonjsRequire () { + throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs'); +} + +function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; +} + +var qrcode = createCommonjsModule(function (module, exports) { +(function(f){{module.exports=f();}})(function(){return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof commonjsRequire&&commonjsRequire;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t);}return n[i].exports}for(var u="function"==typeof commonjsRequire&&commonjsRequire,i=0;i>> (7 - index % 8)) & 1) === 1 + }, + + put: function (num, length) { + for (var i = 0; i < length; i++) { + this.putBit(((num >>> (length - i - 1)) & 1) === 1); + } + }, + + getLengthInBits: function () { + return this.length + }, + + putBit: function (bit) { + var bufIndex = Math.floor(this.length / 8); + if (this.buffer.length <= bufIndex) { + this.buffer.push(0); + } + + if (bit) { + this.buffer[bufIndex] |= (0x80 >>> (this.length % 8)); + } + + this.length++; + } +}; + +module.exports = BitBuffer; + +},{}],4:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); + +/** + * Helper class to handle QR Code symbol modules + * + * @param {Number} size Symbol size + */ +function BitMatrix (size) { + if (!size || size < 1) { + throw new Error('BitMatrix size must be defined and greater than 0') + } + + this.size = size; + this.data = new Buffer(size * size); + this.data.fill(0); + this.reservedBit = new Buffer(size * size); + this.reservedBit.fill(0); +} + +/** + * Set bit value at specified location + * If reserved flag is set, this bit will be ignored during masking process + * + * @param {Number} row + * @param {Number} col + * @param {Boolean} value + * @param {Boolean} reserved + */ +BitMatrix.prototype.set = function (row, col, value, reserved) { + var index = row * this.size + col; + this.data[index] = value; + if (reserved) this.reservedBit[index] = true; +}; + +/** + * Returns bit value at specified location + * + * @param {Number} row + * @param {Number} col + * @return {Boolean} + */ +BitMatrix.prototype.get = function (row, col) { + return this.data[row * this.size + col] +}; + +/** + * Applies xor operator at specified location + * (used during masking process) + * + * @param {Number} row + * @param {Number} col + * @param {Boolean} value + */ +BitMatrix.prototype.xor = function (row, col, value) { + this.data[row * this.size + col] ^= value; +}; + +/** + * Check if bit at specified location is reserved + * + * @param {Number} row + * @param {Number} col + * @return {Boolean} + */ +BitMatrix.prototype.isReserved = function (row, col) { + return this.reservedBit[row * this.size + col] +}; + +module.exports = BitMatrix; + +},{"../utils/buffer":27}],5:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); +var Mode = require('./mode'); + +function ByteData (data) { + this.mode = Mode.BYTE; + this.data = new Buffer(data); +} + +ByteData.getBitsLength = function getBitsLength (length) { + return length * 8 +}; + +ByteData.prototype.getLength = function getLength () { + return this.data.length +}; + +ByteData.prototype.getBitsLength = function getBitsLength () { + return ByteData.getBitsLength(this.data.length) +}; + +ByteData.prototype.write = function (bitBuffer) { + for (var i = 0, l = this.data.length; i < l; i++) { + bitBuffer.put(this.data[i], 8); + } +}; + +module.exports = ByteData; + +},{"../utils/buffer":27,"./mode":13}],6:[function(require,module,exports){ +var ECLevel = require('./error-correction-level'); + +var EC_BLOCKS_TABLE = [ +// L M Q H + 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 +]; + +var EC_CODEWORDS_TABLE = [ +// L M Q H + 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 +]; + +/** + * Returns the number of error correction block that the QR Code should contain + * for the specified version and error correction level. + * + * @param {Number} version QR Code version + * @param {Number} errorCorrectionLevel Error correction level + * @return {Number} Number of error correction blocks + */ +exports.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) { + switch (errorCorrectionLevel) { + case ECLevel.L: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 0] + case ECLevel.M: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 1] + case ECLevel.Q: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 2] + case ECLevel.H: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 3] + default: + return undefined + } +}; + +/** + * Returns the number of error correction codewords to use for the specified + * version and error correction level. + * + * @param {Number} version QR Code version + * @param {Number} errorCorrectionLevel Error correction level + * @return {Number} Number of error correction codewords + */ +exports.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) { + switch (errorCorrectionLevel) { + case ECLevel.L: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0] + case ECLevel.M: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1] + case ECLevel.Q: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2] + case ECLevel.H: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3] + default: + return undefined + } +}; + +},{"./error-correction-level":7}],7:[function(require,module,exports){ +exports.L = { bit: 1 }; +exports.M = { bit: 0 }; +exports.Q = { bit: 3 }; +exports.H = { bit: 2 }; + +function fromString (string) { + if (typeof string !== 'string') { + throw new Error('Param is not a string') + } + + var lcStr = string.toLowerCase(); + + switch (lcStr) { + case 'l': + case 'low': + return exports.L + + case 'm': + case 'medium': + return exports.M + + case 'q': + case 'quartile': + return exports.Q + + case 'h': + case 'high': + return exports.H + + default: + throw new Error('Unknown EC Level: ' + string) + } +} + +exports.isValid = function isValid (level) { + return level && typeof level.bit !== 'undefined' && + level.bit >= 0 && level.bit < 4 +}; + +exports.from = function from (value, defaultValue) { + if (exports.isValid(value)) { + return value + } + + try { + return fromString(value) + } catch (e) { + return defaultValue + } +}; + +},{}],8:[function(require,module,exports){ +var getSymbolSize = require('./utils').getSymbolSize; +var FINDER_PATTERN_SIZE = 7; + +/** + * Returns an array containing the positions of each finder pattern. + * Each array's element represent the top-left point of the pattern as (x, y) coordinates + * + * @param {Number} version QR Code version + * @return {Array} Array of coordinates + */ +exports.getPositions = function getPositions (version) { + var size = getSymbolSize(version); + + return [ + // top-left + [0, 0], + // top-right + [size - FINDER_PATTERN_SIZE, 0], + // bottom-left + [0, size - FINDER_PATTERN_SIZE] + ] +}; + +},{"./utils":20}],9:[function(require,module,exports){ +var Utils = require('./utils'); + +var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0); +var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1); +var G15_BCH = Utils.getBCHDigit(G15); + +/** + * Returns format information with relative error correction bits + * + * The format information is a 15-bit sequence containing 5 data bits, + * with 10 error correction bits calculated using the (15, 5) BCH code. + * + * @param {Number} errorCorrectionLevel Error correction level + * @param {Number} mask Mask pattern + * @return {Number} Encoded format information bits + */ +exports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) { + var data = ((errorCorrectionLevel.bit << 3) | mask); + var d = data << 10; + + while (Utils.getBCHDigit(d) - G15_BCH >= 0) { + d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH)); + } + + // xor final data with mask pattern in order to ensure that + // no combination of Error Correction Level and data mask pattern + // will result in an all-zero data string + return ((data << 10) | d) ^ G15_MASK +}; + +},{"./utils":20}],10:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); + +var EXP_TABLE = new Buffer(512); +var LOG_TABLE = new Buffer(256) + +/** + * Precompute the log and anti-log tables for faster computation later + * + * For each possible value in the galois field 2^8, we will pre-compute + * the logarithm and anti-logarithm (exponential) of this value + * + * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields} + */ +;(function initTables () { + var x = 1; + for (var i = 0; i < 255; i++) { + EXP_TABLE[i] = x; + LOG_TABLE[x] = i; + + x <<= 1; // multiply by 2 + + // The QR code specification says to use byte-wise modulo 100011101 arithmetic. + // This means that when a number is 256 or larger, it should be XORed with 0x11D. + if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256) + x ^= 0x11D; + } + } + + // Optimization: double the size of the anti-log table so that we don't need to mod 255 to + // stay inside the bounds (because we will mainly use this table for the multiplication of + // two GF numbers, no more). + // @see {@link mul} + for (i = 255; i < 512; i++) { + EXP_TABLE[i] = EXP_TABLE[i - 255]; + } +}()); + +/** + * Returns log value of n inside Galois Field + * + * @param {Number} n + * @return {Number} + */ +exports.log = function log (n) { + if (n < 1) throw new Error('log(' + n + ')') + return LOG_TABLE[n] +}; + +/** + * Returns anti-log value of n inside Galois Field + * + * @param {Number} n + * @return {Number} + */ +exports.exp = function exp (n) { + return EXP_TABLE[n] +}; + +/** + * Multiplies two number inside Galois Field + * + * @param {Number} x + * @param {Number} y + * @return {Number} + */ +exports.mul = function mul (x, y) { + if (x === 0 || y === 0) return 0 + + // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized + // @see {@link initTables} + return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]] +}; + +},{"../utils/buffer":27}],11:[function(require,module,exports){ +var Mode = require('./mode'); +var Utils = require('./utils'); + +function KanjiData (data) { + this.mode = Mode.KANJI; + this.data = data; +} + +KanjiData.getBitsLength = function getBitsLength (length) { + return length * 13 +}; + +KanjiData.prototype.getLength = function getLength () { + return this.data.length +}; + +KanjiData.prototype.getBitsLength = function getBitsLength () { + return KanjiData.getBitsLength(this.data.length) +}; + +KanjiData.prototype.write = function (bitBuffer) { + var i; + + // In the Shift JIS system, Kanji characters are represented by a two byte combination. + // These byte values are shifted from the JIS X 0208 values. + // JIS X 0208 gives details of the shift coded representation. + for (i = 0; i < this.data.length; i++) { + var value = Utils.toSJIS(this.data[i]); + + // For characters with Shift JIS values from 0x8140 to 0x9FFC: + if (value >= 0x8140 && value <= 0x9FFC) { + // Subtract 0x8140 from Shift JIS value + value -= 0x8140; + + // For characters with Shift JIS values from 0xE040 to 0xEBBF + } else if (value >= 0xE040 && value <= 0xEBBF) { + // Subtract 0xC140 from Shift JIS value + value -= 0xC140; + } else { + throw new Error( + 'Invalid SJIS character: ' + this.data[i] + '\n' + + 'Make sure your charset is UTF-8') + } + + // Multiply most significant byte of result by 0xC0 + // and add least significant byte to product + value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff); + + // Convert result to a 13-bit binary string + bitBuffer.put(value, 13); + } +}; + +module.exports = KanjiData; + +},{"./mode":13,"./utils":20}],12:[function(require,module,exports){ +/** + * Data mask pattern reference + * @type {Object} + */ +exports.Patterns = { + PATTERN000: 0, + PATTERN001: 1, + PATTERN010: 2, + PATTERN011: 3, + PATTERN100: 4, + PATTERN101: 5, + PATTERN110: 6, + PATTERN111: 7 +}; + +/** + * Weighted penalty scores for the undesirable features + * @type {Object} + */ +var PenaltyScores = { + N1: 3, + N2: 3, + N3: 40, + N4: 10 +}; + +/** + * Check if mask pattern value is valid + * + * @param {Number} mask Mask pattern + * @return {Boolean} true if valid, false otherwise + */ +exports.isValid = function isValid (mask) { + return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7 +}; + +/** + * Returns mask pattern from a value. + * If value is not valid, returns undefined + * + * @param {Number|String} value Mask pattern value + * @return {Number} Valid mask pattern or undefined + */ +exports.from = function from (value) { + return exports.isValid(value) ? parseInt(value, 10) : undefined +}; + +/** +* Find adjacent modules in row/column with the same color +* and assign a penalty value. +* +* Points: N1 + i +* i is the amount by which the number of adjacent modules of the same color exceeds 5 +*/ +exports.getPenaltyN1 = function getPenaltyN1 (data) { + var size = data.size; + var points = 0; + var sameCountCol = 0; + var sameCountRow = 0; + var lastCol = null; + var lastRow = null; + + for (var row = 0; row < size; row++) { + sameCountCol = sameCountRow = 0; + lastCol = lastRow = null; + + for (var col = 0; col < size; col++) { + var module = data.get(row, col); + if (module === lastCol) { + sameCountCol++; + } else { + if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5); + lastCol = module; + sameCountCol = 1; + } + + module = data.get(col, row); + if (module === lastRow) { + sameCountRow++; + } else { + if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5); + lastRow = module; + sameCountRow = 1; + } + } + + if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5); + if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5); + } + + return points +}; + +/** + * Find 2x2 blocks with the same color and assign a penalty value + * + * Points: N2 * (m - 1) * (n - 1) + */ +exports.getPenaltyN2 = function getPenaltyN2 (data) { + var size = data.size; + var points = 0; + + for (var row = 0; row < size - 1; row++) { + for (var col = 0; col < size - 1; col++) { + var last = data.get(row, col) + + data.get(row, col + 1) + + data.get(row + 1, col) + + data.get(row + 1, col + 1); + + if (last === 4 || last === 0) points++; + } + } + + return points * PenaltyScores.N2 +}; + +/** + * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column, + * preceded or followed by light area 4 modules wide + * + * Points: N3 * number of pattern found + */ +exports.getPenaltyN3 = function getPenaltyN3 (data) { + var size = data.size; + var points = 0; + var bitsCol = 0; + var bitsRow = 0; + + for (var row = 0; row < size; row++) { + bitsCol = bitsRow = 0; + for (var col = 0; col < size; col++) { + bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col); + if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++; + + bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row); + if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++; + } + } + + return points * PenaltyScores.N3 +}; + +/** + * Calculate proportion of dark modules in entire symbol + * + * Points: N4 * k + * + * k is the rating of the deviation of the proportion of dark modules + * in the symbol from 50% in steps of 5% + */ +exports.getPenaltyN4 = function getPenaltyN4 (data) { + var darkCount = 0; + var modulesCount = data.data.length; + + for (var i = 0; i < modulesCount; i++) darkCount += data.data[i]; + + var k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10); + + return k * PenaltyScores.N4 +}; + +/** + * Return mask value at given position + * + * @param {Number} maskPattern Pattern reference value + * @param {Number} i Row + * @param {Number} j Column + * @return {Boolean} Mask value + */ +function getMaskAt (maskPattern, i, j) { + switch (maskPattern) { + case exports.Patterns.PATTERN000: return (i + j) % 2 === 0 + case exports.Patterns.PATTERN001: return i % 2 === 0 + case exports.Patterns.PATTERN010: return j % 3 === 0 + case exports.Patterns.PATTERN011: return (i + j) % 3 === 0 + case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0 + case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0 + case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0 + case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0 + + default: throw new Error('bad maskPattern:' + maskPattern) + } +} + +/** + * Apply a mask pattern to a BitMatrix + * + * @param {Number} pattern Pattern reference number + * @param {BitMatrix} data BitMatrix data + */ +exports.applyMask = function applyMask (pattern, data) { + var size = data.size; + + for (var col = 0; col < size; col++) { + for (var row = 0; row < size; row++) { + if (data.isReserved(row, col)) continue + data.xor(row, col, getMaskAt(pattern, row, col)); + } + } +}; + +/** + * Returns the best mask pattern for data + * + * @param {BitMatrix} data + * @return {Number} Mask pattern reference number + */ +exports.getBestMask = function getBestMask (data, setupFormatFunc) { + var numPatterns = Object.keys(exports.Patterns).length; + var bestPattern = 0; + var lowerPenalty = Infinity; + + for (var p = 0; p < numPatterns; p++) { + setupFormatFunc(p); + exports.applyMask(p, data); + + // Calculate penalty + var penalty = + exports.getPenaltyN1(data) + + exports.getPenaltyN2(data) + + exports.getPenaltyN3(data) + + exports.getPenaltyN4(data); + + // Undo previously applied mask + exports.applyMask(p, data); + + if (penalty < lowerPenalty) { + lowerPenalty = penalty; + bestPattern = p; + } + } + + return bestPattern +}; + +},{}],13:[function(require,module,exports){ +var VersionCheck = require('./version-check'); +var Regex = require('./regex'); + +/** + * Numeric mode encodes data from the decimal digit set (0 - 9) + * (byte values 30HEX to 39HEX). + * Normally, 3 data characters are represented by 10 bits. + * + * @type {Object} + */ +exports.NUMERIC = { + id: 'Numeric', + bit: 1 << 0, + ccBits: [10, 12, 14] +}; + +/** + * Alphanumeric mode encodes data from a set of 45 characters, + * i.e. 10 numeric digits (0 - 9), + * 26 alphabetic characters (A - Z), + * and 9 symbols (SP, $, %, *, +, -, ., /, :). + * Normally, two input characters are represented by 11 bits. + * + * @type {Object} + */ +exports.ALPHANUMERIC = { + id: 'Alphanumeric', + bit: 1 << 1, + ccBits: [9, 11, 13] +}; + +/** + * In byte mode, data is encoded at 8 bits per character. + * + * @type {Object} + */ +exports.BYTE = { + id: 'Byte', + bit: 1 << 2, + ccBits: [8, 16, 16] +}; + +/** + * The Kanji mode efficiently encodes Kanji characters in accordance with + * the Shift JIS system based on JIS X 0208. + * The Shift JIS values are shifted from the JIS X 0208 values. + * JIS X 0208 gives details of the shift coded representation. + * Each two-byte character value is compacted to a 13-bit binary codeword. + * + * @type {Object} + */ +exports.KANJI = { + id: 'Kanji', + bit: 1 << 3, + ccBits: [8, 10, 12] +}; + +/** + * Mixed mode will contain a sequences of data in a combination of any of + * the modes described above + * + * @type {Object} + */ +exports.MIXED = { + bit: -1 +}; + +/** + * Returns the number of bits needed to store the data length + * according to QR Code specifications. + * + * @param {Mode} mode Data mode + * @param {Number} version QR Code version + * @return {Number} Number of bits + */ +exports.getCharCountIndicator = function getCharCountIndicator (mode, version) { + if (!mode.ccBits) throw new Error('Invalid mode: ' + mode) + + if (!VersionCheck.isValid(version)) { + throw new Error('Invalid version: ' + version) + } + + if (version >= 1 && version < 10) return mode.ccBits[0] + else if (version < 27) return mode.ccBits[1] + return mode.ccBits[2] +}; + +/** + * Returns the most efficient mode to store the specified data + * + * @param {String} dataStr Input data string + * @return {Mode} Best mode + */ +exports.getBestModeForData = function getBestModeForData (dataStr) { + if (Regex.testNumeric(dataStr)) return exports.NUMERIC + else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC + else if (Regex.testKanji(dataStr)) return exports.KANJI + else return exports.BYTE +}; + +/** + * Return mode name as string + * + * @param {Mode} mode Mode object + * @returns {String} Mode name + */ +exports.toString = function toString (mode) { + if (mode && mode.id) return mode.id + throw new Error('Invalid mode') +}; + +/** + * Check if input param is a valid mode object + * + * @param {Mode} mode Mode object + * @returns {Boolean} True if valid mode, false otherwise + */ +exports.isValid = function isValid (mode) { + return mode && mode.bit && mode.ccBits +}; + +/** + * Get mode object from its name + * + * @param {String} string Mode name + * @returns {Mode} Mode object + */ +function fromString (string) { + if (typeof string !== 'string') { + throw new Error('Param is not a string') + } + + var lcStr = string.toLowerCase(); + + switch (lcStr) { + case 'numeric': + return exports.NUMERIC + case 'alphanumeric': + return exports.ALPHANUMERIC + case 'kanji': + return exports.KANJI + case 'byte': + return exports.BYTE + default: + throw new Error('Unknown mode: ' + string) + } +} + +/** + * Returns mode from a value. + * If value is not a valid mode, returns defaultValue + * + * @param {Mode|String} value Encoding mode + * @param {Mode} defaultValue Fallback value + * @return {Mode} Encoding mode + */ +exports.from = function from (value, defaultValue) { + if (exports.isValid(value)) { + return value + } + + try { + return fromString(value) + } catch (e) { + return defaultValue + } +}; + +},{"./regex":18,"./version-check":21}],14:[function(require,module,exports){ +var Mode = require('./mode'); + +function NumericData (data) { + this.mode = Mode.NUMERIC; + this.data = data.toString(); +} + +NumericData.getBitsLength = function getBitsLength (length) { + return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0) +}; + +NumericData.prototype.getLength = function getLength () { + return this.data.length +}; + +NumericData.prototype.getBitsLength = function getBitsLength () { + return NumericData.getBitsLength(this.data.length) +}; + +NumericData.prototype.write = function write (bitBuffer) { + var i, group, value; + + // The input data string is divided into groups of three digits, + // and each group is converted to its 10-bit binary equivalent. + for (i = 0; i + 3 <= this.data.length; i += 3) { + group = this.data.substr(i, 3); + value = parseInt(group, 10); + + bitBuffer.put(value, 10); + } + + // If the number of input digits is not an exact multiple of three, + // the final one or two digits are converted to 4 or 7 bits respectively. + var remainingNum = this.data.length - i; + if (remainingNum > 0) { + group = this.data.substr(i); + value = parseInt(group, 10); + + bitBuffer.put(value, remainingNum * 3 + 1); + } +}; + +module.exports = NumericData; + +},{"./mode":13}],15:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); +var GF = require('./galois-field'); + +/** + * Multiplies two polynomials inside Galois Field + * + * @param {Buffer} p1 Polynomial + * @param {Buffer} p2 Polynomial + * @return {Buffer} Product of p1 and p2 + */ +exports.mul = function mul (p1, p2) { + var coeff = new Buffer(p1.length + p2.length - 1); + coeff.fill(0); + + for (var i = 0; i < p1.length; i++) { + for (var j = 0; j < p2.length; j++) { + coeff[i + j] ^= GF.mul(p1[i], p2[j]); + } + } + + return coeff +}; + +/** + * Calculate the remainder of polynomials division + * + * @param {Buffer} divident Polynomial + * @param {Buffer} divisor Polynomial + * @return {Buffer} Remainder + */ +exports.mod = function mod (divident, divisor) { + var result = new Buffer(divident); + + while ((result.length - divisor.length) >= 0) { + var coeff = result[0]; + + for (var i = 0; i < divisor.length; i++) { + result[i] ^= GF.mul(divisor[i], coeff); + } + + // remove all zeros from buffer head + var offset = 0; + while (offset < result.length && result[offset] === 0) offset++; + result = result.slice(offset); + } + + return result +}; + +/** + * Generate an irreducible generator polynomial of specified degree + * (used by Reed-Solomon encoder) + * + * @param {Number} degree Degree of the generator polynomial + * @return {Buffer} Buffer containing polynomial coefficients + */ +exports.generateECPolynomial = function generateECPolynomial (degree) { + var poly = new Buffer([1]); + for (var i = 0; i < degree; i++) { + poly = exports.mul(poly, [1, GF.exp(i)]); + } + + return poly +}; + +},{"../utils/buffer":27,"./galois-field":10}],16:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); +var Utils = require('./utils'); +var ECLevel = require('./error-correction-level'); +var BitBuffer = require('./bit-buffer'); +var BitMatrix = require('./bit-matrix'); +var AlignmentPattern = require('./alignment-pattern'); +var FinderPattern = require('./finder-pattern'); +var MaskPattern = require('./mask-pattern'); +var ECCode = require('./error-correction-code'); +var ReedSolomonEncoder = require('./reed-solomon-encoder'); +var Version = require('./version'); +var FormatInfo = require('./format-info'); +var Mode = require('./mode'); +var Segments = require('./segments'); +var isArray = require('isarray'); + +/** + * QRCode for JavaScript + * + * modified by Ryan Day for nodejs support + * Copyright (c) 2011 Ryan Day + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/mit-license.php + * +//--------------------------------------------------------------------- +// QRCode for JavaScript +// +// Copyright (c) 2009 Kazuhiko Arase +// +// URL: http://www.d-project.com/ +// +// Licensed under the MIT license: +// http://www.opensource.org/licenses/mit-license.php +// +// The word "QR Code" is registered trademark of +// DENSO WAVE INCORPORATED +// http://www.denso-wave.com/qrcode/faqpatent-e.html +// +//--------------------------------------------------------------------- +*/ + +/** + * Add finder patterns bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {Number} version QR Code version + */ +function setupFinderPattern (matrix, version) { + var size = matrix.size; + var pos = FinderPattern.getPositions(version); + + for (var i = 0; i < pos.length; i++) { + var row = pos[i][0]; + var col = pos[i][1]; + + for (var r = -1; r <= 7; r++) { + if (row + r <= -1 || size <= row + r) continue + + for (var c = -1; c <= 7; c++) { + if (col + c <= -1 || size <= col + c) continue + + if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) || + (c >= 0 && c <= 6 && (r === 0 || r === 6)) || + (r >= 2 && r <= 4 && c >= 2 && c <= 4)) { + matrix.set(row + r, col + c, true, true); + } else { + matrix.set(row + r, col + c, false, true); + } + } + } + } +} + +/** + * Add timing pattern bits to matrix + * + * Note: this function must be called before {@link setupAlignmentPattern} + * + * @param {BitMatrix} matrix Modules matrix + */ +function setupTimingPattern (matrix) { + var size = matrix.size; + + for (var r = 8; r < size - 8; r++) { + var value = r % 2 === 0; + matrix.set(r, 6, value, true); + matrix.set(6, r, value, true); + } +} + +/** + * Add alignment patterns bits to matrix + * + * Note: this function must be called after {@link setupTimingPattern} + * + * @param {BitMatrix} matrix Modules matrix + * @param {Number} version QR Code version + */ +function setupAlignmentPattern (matrix, version) { + var pos = AlignmentPattern.getPositions(version); + + for (var i = 0; i < pos.length; i++) { + var row = pos[i][0]; + var col = pos[i][1]; + + for (var r = -2; r <= 2; r++) { + for (var c = -2; c <= 2; c++) { + if (r === -2 || r === 2 || c === -2 || c === 2 || + (r === 0 && c === 0)) { + matrix.set(row + r, col + c, true, true); + } else { + matrix.set(row + r, col + c, false, true); + } + } + } + } +} + +/** + * Add version info bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {Number} version QR Code version + */ +function setupVersionInfo (matrix, version) { + var size = matrix.size; + var bits = Version.getEncodedBits(version); + var row, col, mod; + + for (var i = 0; i < 18; i++) { + row = Math.floor(i / 3); + col = i % 3 + size - 8 - 3; + mod = ((bits >> i) & 1) === 1; + + matrix.set(row, col, mod, true); + matrix.set(col, row, mod, true); + } +} + +/** + * Add format info bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level + * @param {Number} maskPattern Mask pattern reference value + */ +function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) { + var size = matrix.size; + var bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern); + var i, mod; + + for (i = 0; i < 15; i++) { + mod = ((bits >> i) & 1) === 1; + + // vertical + if (i < 6) { + matrix.set(i, 8, mod, true); + } else if (i < 8) { + matrix.set(i + 1, 8, mod, true); + } else { + matrix.set(size - 15 + i, 8, mod, true); + } + + // horizontal + if (i < 8) { + matrix.set(8, size - i - 1, mod, true); + } else if (i < 9) { + matrix.set(8, 15 - i - 1 + 1, mod, true); + } else { + matrix.set(8, 15 - i - 1, mod, true); + } + } + + // fixed module + matrix.set(size - 8, 8, 1, true); +} + +/** + * Add encoded data bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {Buffer} data Data codewords + */ +function setupData (matrix, data) { + var size = matrix.size; + var inc = -1; + var row = size - 1; + var bitIndex = 7; + var byteIndex = 0; + + for (var col = size - 1; col > 0; col -= 2) { + if (col === 6) col--; + + while (true) { + for (var c = 0; c < 2; c++) { + if (!matrix.isReserved(row, col - c)) { + var dark = false; + + if (byteIndex < data.length) { + dark = (((data[byteIndex] >>> bitIndex) & 1) === 1); + } + + matrix.set(row, col - c, dark); + bitIndex--; + + if (bitIndex === -1) { + byteIndex++; + bitIndex = 7; + } + } + } + + row += inc; + + if (row < 0 || size <= row) { + row -= inc; + inc = -inc; + break + } + } + } +} + +/** + * Create encoded codewords from data input + * + * @param {Number} version QR Code version + * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level + * @param {ByteData} data Data input + * @return {Buffer} Buffer containing encoded codewords + */ +function createData (version, errorCorrectionLevel, segments) { + // Prepare data buffer + var buffer = new BitBuffer(); + + segments.forEach(function (data) { + // prefix data with mode indicator (4 bits) + buffer.put(data.mode.bit, 4); + + // Prefix data with character count indicator. + // The character count indicator is a string of bits that represents the + // number of characters that are being encoded. + // The character count indicator must be placed after the mode indicator + // and must be a certain number of bits long, depending on the QR version + // and data mode + // @see {@link Mode.getCharCountIndicator}. + buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version)); + + // add binary data sequence to buffer + data.write(buffer); + }); + + // Calculate required number of bits + var totalCodewords = Utils.getSymbolTotalCodewords(version); + var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel); + var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8; + + // Add a terminator. + // If the bit string is shorter than the total number of required bits, + // a terminator of up to four 0s must be added to the right side of the string. + // If the bit string is more than four bits shorter than the required number of bits, + // add four 0s to the end. + if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) { + buffer.put(0, 4); + } + + // If the bit string is fewer than four bits shorter, add only the number of 0s that + // are needed to reach the required number of bits. + + // After adding the terminator, if the number of bits in the string is not a multiple of 8, + // pad the string on the right with 0s to make the string's length a multiple of 8. + while (buffer.getLengthInBits() % 8 !== 0) { + buffer.putBit(0); + } + + // Add pad bytes if the string is still shorter than the total number of required bits. + // Extend the buffer to fill the data capacity of the symbol corresponding to + // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC) + // and 00010001 (0x11) alternately. + var remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8; + for (var i = 0; i < remainingByte; i++) { + buffer.put(i % 2 ? 0x11 : 0xEC, 8); + } + + return createCodewords(buffer, version, errorCorrectionLevel) +} + +/** + * Encode input data with Reed-Solomon and return codewords with + * relative error correction bits + * + * @param {BitBuffer} bitBuffer Data to encode + * @param {Number} version QR Code version + * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level + * @return {Buffer} Buffer containing encoded codewords + */ +function createCodewords (bitBuffer, version, errorCorrectionLevel) { + // Total codewords for this QR code version (Data + Error correction) + var totalCodewords = Utils.getSymbolTotalCodewords(version); + + // Total number of error correction codewords + var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel); + + // Total number of data codewords + var dataTotalCodewords = totalCodewords - ecTotalCodewords; + + // Total number of blocks + var ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel); + + // Calculate how many blocks each group should contain + var blocksInGroup2 = totalCodewords % ecTotalBlocks; + var blocksInGroup1 = ecTotalBlocks - blocksInGroup2; + + var totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks); + + var dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks); + var dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1; + + // Number of EC codewords is the same for both groups + var ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1; + + // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount + var rs = new ReedSolomonEncoder(ecCount); + + var offset = 0; + var dcData = new Array(ecTotalBlocks); + var ecData = new Array(ecTotalBlocks); + var maxDataSize = 0; + var buffer = new Buffer(bitBuffer.buffer); + + // Divide the buffer into the required number of blocks + for (var b = 0; b < ecTotalBlocks; b++) { + var dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2; + + // extract a block of data from buffer + dcData[b] = buffer.slice(offset, offset + dataSize); + + // Calculate EC codewords for this data block + ecData[b] = rs.encode(dcData[b]); + + offset += dataSize; + maxDataSize = Math.max(maxDataSize, dataSize); + } + + // Create final data + // Interleave the data and error correction codewords from each block + var data = new Buffer(totalCodewords); + var index = 0; + var i, r; + + // Add data codewords + for (i = 0; i < maxDataSize; i++) { + for (r = 0; r < ecTotalBlocks; r++) { + if (i < dcData[r].length) { + data[index++] = dcData[r][i]; + } + } + } + + // Apped EC codewords + for (i = 0; i < ecCount; i++) { + for (r = 0; r < ecTotalBlocks; r++) { + data[index++] = ecData[r][i]; + } + } + + return data +} + +/** + * Build QR Code symbol + * + * @param {String} data Input string + * @param {Number} version QR Code version + * @param {ErrorCorretionLevel} errorCorrectionLevel Error level + * @param {MaskPattern} maskPattern Mask pattern + * @return {Object} Object containing symbol data + */ +function createSymbol (data, version, errorCorrectionLevel, maskPattern) { + var segments; + + if (isArray(data)) { + segments = Segments.fromArray(data); + } else if (typeof data === 'string') { + var estimatedVersion = version; + + if (!estimatedVersion) { + var rawSegments = Segments.rawSplit(data); + + // Estimate best version that can contain raw splitted segments + estimatedVersion = Version.getBestVersionForData(rawSegments, + errorCorrectionLevel); + } + + // Build optimized segments + // If estimated version is undefined, try with the highest version + segments = Segments.fromString(data, estimatedVersion || 40); + } else { + throw new Error('Invalid data') + } + + // Get the min version that can contain data + var bestVersion = Version.getBestVersionForData(segments, + errorCorrectionLevel); + + // If no version is found, data cannot be stored + if (!bestVersion) { + throw new Error('The amount of data is too big to be stored in a QR Code') + } + + // If not specified, use min version as default + if (!version) { + version = bestVersion; + + // Check if the specified version can contain the data + } else if (version < bestVersion) { + throw new Error('\n' + + 'The chosen QR Code version cannot contain this amount of data.\n' + + 'Minimum version required to store current data is: ' + bestVersion + '.\n' + ) + } + + var dataBits = createData(version, errorCorrectionLevel, segments); + + // Allocate matrix buffer + var moduleCount = Utils.getSymbolSize(version); + var modules = new BitMatrix(moduleCount); + + // Add function modules + setupFinderPattern(modules, version); + setupTimingPattern(modules); + setupAlignmentPattern(modules, version); + + // Add temporary dummy bits for format info just to set them as reserved. + // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask} + // since the masking operation must be performed only on the encoding region. + // These blocks will be replaced with correct values later in code. + setupFormatInfo(modules, errorCorrectionLevel, 0); + + if (version >= 7) { + setupVersionInfo(modules, version); + } + + // Add data codewords + setupData(modules, dataBits); + + if (isNaN(maskPattern)) { + // Find best mask pattern + maskPattern = MaskPattern.getBestMask(modules, + setupFormatInfo.bind(null, modules, errorCorrectionLevel)); + } + + // Apply mask pattern + MaskPattern.applyMask(maskPattern, modules); + + // Replace format info bits with correct values + setupFormatInfo(modules, errorCorrectionLevel, maskPattern); + + return { + modules: modules, + version: version, + errorCorrectionLevel: errorCorrectionLevel, + maskPattern: maskPattern, + segments: segments + } +} + +/** + * QR Code + * + * @param {String | Array} data Input data + * @param {Object} options Optional configurations + * @param {Number} options.version QR Code version + * @param {String} options.errorCorrectionLevel Error correction level + * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis + */ +exports.create = function create (data, options) { + if (typeof data === 'undefined' || data === '') { + throw new Error('No input text') + } + + var errorCorrectionLevel = ECLevel.M; + var version; + var mask; + + if (typeof options !== 'undefined') { + // Use higher error correction level as default + errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M); + version = Version.from(options.version); + mask = MaskPattern.from(options.maskPattern); + + if (options.toSJISFunc) { + Utils.setToSJISFunction(options.toSJISFunc); + } + } + + return createSymbol(data, version, errorCorrectionLevel, mask) +}; + +},{"../utils/buffer":27,"./alignment-pattern":1,"./bit-buffer":3,"./bit-matrix":4,"./error-correction-code":6,"./error-correction-level":7,"./finder-pattern":8,"./format-info":9,"./mask-pattern":12,"./mode":13,"./reed-solomon-encoder":17,"./segments":19,"./utils":20,"./version":22,"isarray":30}],17:[function(require,module,exports){ +var Buffer = require('../utils/buffer'); +var Polynomial = require('./polynomial'); + +function ReedSolomonEncoder (degree) { + this.genPoly = undefined; + this.degree = degree; + + if (this.degree) this.initialize(this.degree); +} + +/** + * Initialize the encoder. + * The input param should correspond to the number of error correction codewords. + * + * @param {Number} degree + */ +ReedSolomonEncoder.prototype.initialize = function initialize (degree) { + // create an irreducible generator polynomial + this.degree = degree; + this.genPoly = Polynomial.generateECPolynomial(this.degree); +}; + +/** + * Encodes a chunk of data + * + * @param {Buffer} data Buffer containing input data + * @return {Buffer} Buffer containing encoded data + */ +ReedSolomonEncoder.prototype.encode = function encode (data) { + if (!this.genPoly) { + throw new Error('Encoder not initialized') + } + + // Calculate EC for this data block + // extends data size to data+genPoly size + var pad = new Buffer(this.degree); + pad.fill(0); + var paddedData = Buffer.concat([data, pad], data.length + this.degree); + + // The error correction codewords are the remainder after dividing the data codewords + // by a generator polynomial + var remainder = Polynomial.mod(paddedData, this.genPoly); + + // return EC data blocks (last n byte, where n is the degree of genPoly) + // If coefficients number in remainder are less than genPoly degree, + // pad with 0s to the left to reach the needed number of coefficients + var start = this.degree - remainder.length; + if (start > 0) { + var buff = new Buffer(this.degree); + buff.fill(0); + remainder.copy(buff, start); + + return buff + } + + return remainder +}; + +module.exports = ReedSolomonEncoder; + +},{"../utils/buffer":27,"./polynomial":15}],18:[function(require,module,exports){ +var numeric = '[0-9]+'; +var alphanumeric = '[A-Z $%*+\\-./:]+'; +var kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' + + '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' + + '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' + + '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+'; +kanji = kanji.replace(/u/g, '\\u'); + +var byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+'; + +exports.KANJI = new RegExp(kanji, 'g'); +exports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g'); +exports.BYTE = new RegExp(byte, 'g'); +exports.NUMERIC = new RegExp(numeric, 'g'); +exports.ALPHANUMERIC = new RegExp(alphanumeric, 'g'); + +var TEST_KANJI = new RegExp('^' + kanji + '$'); +var TEST_NUMERIC = new RegExp('^' + numeric + '$'); +var TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$'); + +exports.testKanji = function testKanji (str) { + return TEST_KANJI.test(str) +}; + +exports.testNumeric = function testNumeric (str) { + return TEST_NUMERIC.test(str) +}; + +exports.testAlphanumeric = function testAlphanumeric (str) { + return TEST_ALPHANUMERIC.test(str) +}; + +},{}],19:[function(require,module,exports){ +var Mode = require('./mode'); +var NumericData = require('./numeric-data'); +var AlphanumericData = require('./alphanumeric-data'); +var ByteData = require('./byte-data'); +var KanjiData = require('./kanji-data'); +var Regex = require('./regex'); +var Utils = require('./utils'); +var dijkstra = require('dijkstrajs'); + +/** + * Returns UTF8 byte length + * + * @param {String} str Input string + * @return {Number} Number of byte + */ +function getStringByteLength (str) { + return unescape(encodeURIComponent(str)).length +} + +/** + * Get a list of segments of the specified mode + * from a string + * + * @param {Mode} mode Segment mode + * @param {String} str String to process + * @return {Array} Array of object with segments data + */ +function getSegments (regex, mode, str) { + var segments = []; + var result; + + while ((result = regex.exec(str)) !== null) { + segments.push({ + data: result[0], + index: result.index, + mode: mode, + length: result[0].length + }); + } + + return segments +} + +/** + * Extracts a series of segments with the appropriate + * modes from a string + * + * @param {String} dataStr Input string + * @return {Array} Array of object with segments data + */ +function getSegmentsFromString (dataStr) { + var numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr); + var alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr); + var byteSegs; + var kanjiSegs; + + if (Utils.isKanjiModeEnabled()) { + byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr); + kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr); + } else { + byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr); + kanjiSegs = []; + } + + var segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs); + + return segs + .sort(function (s1, s2) { + return s1.index - s2.index + }) + .map(function (obj) { + return { + data: obj.data, + mode: obj.mode, + length: obj.length + } + }) +} + +/** + * Returns how many bits are needed to encode a string of + * specified length with the specified mode + * + * @param {Number} length String length + * @param {Mode} mode Segment mode + * @return {Number} Bit length + */ +function getSegmentBitsLength (length, mode) { + switch (mode) { + case Mode.NUMERIC: + return NumericData.getBitsLength(length) + case Mode.ALPHANUMERIC: + return AlphanumericData.getBitsLength(length) + case Mode.KANJI: + return KanjiData.getBitsLength(length) + case Mode.BYTE: + return ByteData.getBitsLength(length) + } +} + +/** + * Merges adjacent segments which have the same mode + * + * @param {Array} segs Array of object with segments data + * @return {Array} Array of object with segments data + */ +function mergeSegments (segs) { + return segs.reduce(function (acc, curr) { + var prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null; + if (prevSeg && prevSeg.mode === curr.mode) { + acc[acc.length - 1].data += curr.data; + return acc + } + + acc.push(curr); + return acc + }, []) +} + +/** + * Generates a list of all possible nodes combination which + * will be used to build a segments graph. + * + * Nodes are divided by groups. Each group will contain a list of all the modes + * in which is possible to encode the given text. + * + * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte. + * The group for '12345' will contain then 3 objects, one for each + * possible encoding mode. + * + * Each node represents a possible segment. + * + * @param {Array} segs Array of object with segments data + * @return {Array} Array of object with segments data + */ +function buildNodes (segs) { + var nodes = []; + for (var i = 0; i < segs.length; i++) { + var seg = segs[i]; + + switch (seg.mode) { + case Mode.NUMERIC: + nodes.push([seg, + { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length }, + { data: seg.data, mode: Mode.BYTE, length: seg.length } + ]); + break + case Mode.ALPHANUMERIC: + nodes.push([seg, + { data: seg.data, mode: Mode.BYTE, length: seg.length } + ]); + break + case Mode.KANJI: + nodes.push([seg, + { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) } + ]); + break + case Mode.BYTE: + nodes.push([ + { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) } + ]); + } + } + + return nodes +} + +/** + * Builds a graph from a list of nodes. + * All segments in each node group will be connected with all the segments of + * the next group and so on. + * + * At each connection will be assigned a weight depending on the + * segment's byte length. + * + * @param {Array} nodes Array of object with segments data + * @param {Number} version QR Code version + * @return {Object} Graph of all possible segments + */ +function buildGraph (nodes, version) { + var table = {}; + var graph = {'start': {}}; + var prevNodeIds = ['start']; + + for (var i = 0; i < nodes.length; i++) { + var nodeGroup = nodes[i]; + var currentNodeIds = []; + + for (var j = 0; j < nodeGroup.length; j++) { + var node = nodeGroup[j]; + var key = '' + i + j; + + currentNodeIds.push(key); + table[key] = { node: node, lastCount: 0 }; + graph[key] = {}; + + for (var n = 0; n < prevNodeIds.length; n++) { + var prevNodeId = prevNodeIds[n]; + + if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) { + graph[prevNodeId][key] = + getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - + getSegmentBitsLength(table[prevNodeId].lastCount, node.mode); + + table[prevNodeId].lastCount += node.length; + } else { + if (table[prevNodeId]) table[prevNodeId].lastCount = node.length; + + graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + + 4 + Mode.getCharCountIndicator(node.mode, version); // switch cost + } + } + } + + prevNodeIds = currentNodeIds; + } + + for (n = 0; n < prevNodeIds.length; n++) { + graph[prevNodeIds[n]]['end'] = 0; + } + + return { map: graph, table: table } +} + +/** + * Builds a segment from a specified data and mode. + * If a mode is not specified, the more suitable will be used. + * + * @param {String} data Input data + * @param {Mode | String} modesHint Data mode + * @return {Segment} Segment + */ +function buildSingleSegment (data, modesHint) { + var mode; + var bestMode = Mode.getBestModeForData(data); + + mode = Mode.from(modesHint, bestMode); + + // Make sure data can be encoded + if (mode !== Mode.BYTE && mode.bit < bestMode.bit) { + throw new Error('"' + data + '"' + + ' cannot be encoded with mode ' + Mode.toString(mode) + + '.\n Suggested mode is: ' + Mode.toString(bestMode)) + } + + // Use Mode.BYTE if Kanji support is disabled + if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) { + mode = Mode.BYTE; + } + + switch (mode) { + case Mode.NUMERIC: + return new NumericData(data) + + case Mode.ALPHANUMERIC: + return new AlphanumericData(data) + + case Mode.KANJI: + return new KanjiData(data) + + case Mode.BYTE: + return new ByteData(data) + } +} + +/** + * Builds a list of segments from an array. + * Array can contain Strings or Objects with segment's info. + * + * For each item which is a string, will be generated a segment with the given + * string and the more appropriate encoding mode. + * + * For each item which is an object, will be generated a segment with the given + * data and mode. + * Objects must contain at least the property "data". + * If property "mode" is not present, the more suitable mode will be used. + * + * @param {Array} array Array of objects with segments data + * @return {Array} Array of Segments + */ +exports.fromArray = function fromArray (array) { + return array.reduce(function (acc, seg) { + if (typeof seg === 'string') { + acc.push(buildSingleSegment(seg, null)); + } else if (seg.data) { + acc.push(buildSingleSegment(seg.data, seg.mode)); + } + + return acc + }, []) +}; + +/** + * Builds an optimized sequence of segments from a string, + * which will produce the shortest possible bitstream. + * + * @param {String} data Input string + * @param {Number} version QR Code version + * @return {Array} Array of segments + */ +exports.fromString = function fromString (data, version) { + var segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled()); + + var nodes = buildNodes(segs); + var graph = buildGraph(nodes, version); + var path = dijkstra.find_path(graph.map, 'start', 'end'); + + var optimizedSegs = []; + for (var i = 1; i < path.length - 1; i++) { + optimizedSegs.push(graph.table[path[i]].node); + } + + return exports.fromArray(mergeSegments(optimizedSegs)) +}; + +/** + * Splits a string in various segments with the modes which + * best represent their content. + * The produced segments are far from being optimized. + * The output of this function is only used to estimate a QR Code version + * which may contain the data. + * + * @param {string} data Input string + * @return {Array} Array of segments + */ +exports.rawSplit = function rawSplit (data) { + return exports.fromArray( + getSegmentsFromString(data, Utils.isKanjiModeEnabled()) + ) +}; + +},{"./alphanumeric-data":2,"./byte-data":5,"./kanji-data":11,"./mode":13,"./numeric-data":14,"./regex":18,"./utils":20,"dijkstrajs":29}],20:[function(require,module,exports){ +var toSJISFunction; +var CODEWORDS_COUNT = [ + 0, // Not used + 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 +]; + +/** + * Returns the QR Code size for the specified version + * + * @param {Number} version QR Code version + * @return {Number} size of QR code + */ +exports.getSymbolSize = function getSymbolSize (version) { + if (!version) throw new Error('"version" cannot be null or undefined') + if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40') + return version * 4 + 17 +}; + +/** + * Returns the total number of codewords used to store data and EC information. + * + * @param {Number} version QR Code version + * @return {Number} Data length in bits + */ +exports.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) { + return CODEWORDS_COUNT[version] +}; + +/** + * Encode data with Bose-Chaudhuri-Hocquenghem + * + * @param {Number} data Value to encode + * @return {Number} Encoded value + */ +exports.getBCHDigit = function (data) { + var digit = 0; + + while (data !== 0) { + digit++; + data >>>= 1; + } + + return digit +}; + +exports.setToSJISFunction = function setToSJISFunction (f) { + if (typeof f !== 'function') { + throw new Error('"toSJISFunc" is not a valid function.') + } + + toSJISFunction = f; +}; + +exports.isKanjiModeEnabled = function () { + return typeof toSJISFunction !== 'undefined' +}; + +exports.toSJIS = function toSJIS (kanji) { + return toSJISFunction(kanji) +}; + +},{}],21:[function(require,module,exports){ +/** + * Check if QR Code version is valid + * + * @param {Number} version QR Code version + * @return {Boolean} true if valid version, false otherwise + */ +exports.isValid = function isValid (version) { + return !isNaN(version) && version >= 1 && version <= 40 +}; + +},{}],22:[function(require,module,exports){ +var Utils = require('./utils'); +var ECCode = require('./error-correction-code'); +var ECLevel = require('./error-correction-level'); +var Mode = require('./mode'); +var VersionCheck = require('./version-check'); +var isArray = require('isarray'); + +// Generator polynomial used to encode version information +var G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0); +var G18_BCH = Utils.getBCHDigit(G18); + +function getBestVersionForDataLength (mode, length, errorCorrectionLevel) { + for (var currentVersion = 1; currentVersion <= 40; currentVersion++) { + if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) { + return currentVersion + } + } + + return undefined +} + +function getReservedBitsCount (mode, version) { + // Character count indicator + mode indicator bits + return Mode.getCharCountIndicator(mode, version) + 4 +} + +function getTotalBitsFromDataArray (segments, version) { + var totalBits = 0; + + segments.forEach(function (data) { + var reservedBits = getReservedBitsCount(data.mode, version); + totalBits += reservedBits + data.getBitsLength(); + }); + + return totalBits +} + +function getBestVersionForMixedData (segments, errorCorrectionLevel) { + for (var currentVersion = 1; currentVersion <= 40; currentVersion++) { + var length = getTotalBitsFromDataArray(segments, currentVersion); + if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) { + return currentVersion + } + } + + return undefined +} + +/** + * Returns version number from a value. + * If value is not a valid version, returns defaultValue + * + * @param {Number|String} value QR Code version + * @param {Number} defaultValue Fallback value + * @return {Number} QR Code version number + */ +exports.from = function from (value, defaultValue) { + if (VersionCheck.isValid(value)) { + return parseInt(value, 10) + } + + return defaultValue +}; + +/** + * Returns how much data can be stored with the specified QR code version + * and error correction level + * + * @param {Number} version QR Code version (1-40) + * @param {Number} errorCorrectionLevel Error correction level + * @param {Mode} mode Data mode + * @return {Number} Quantity of storable data + */ +exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) { + if (!VersionCheck.isValid(version)) { + throw new Error('Invalid QR Code version') + } + + // Use Byte mode as default + if (typeof mode === 'undefined') mode = Mode.BYTE; + + // Total codewords for this QR code version (Data + Error correction) + var totalCodewords = Utils.getSymbolTotalCodewords(version); + + // Total number of error correction codewords + var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel); + + // Total number of data codewords + var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8; + + if (mode === Mode.MIXED) return dataTotalCodewordsBits + + var usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version); + + // Return max number of storable codewords + switch (mode) { + case Mode.NUMERIC: + return Math.floor((usableBits / 10) * 3) + + case Mode.ALPHANUMERIC: + return Math.floor((usableBits / 11) * 2) + + case Mode.KANJI: + return Math.floor(usableBits / 13) + + case Mode.BYTE: + default: + return Math.floor(usableBits / 8) + } +}; + +/** + * Returns the minimum version needed to contain the amount of data + * + * @param {Segment} data Segment of data + * @param {Number} [errorCorrectionLevel=H] Error correction level + * @param {Mode} mode Data mode + * @return {Number} QR Code version + */ +exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) { + var seg; + + var ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M); + + if (isArray(data)) { + if (data.length > 1) { + return getBestVersionForMixedData(data, ecl) + } + + if (data.length === 0) { + return 1 + } + + seg = data[0]; + } else { + seg = data; + } + + return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl) +}; + +/** + * Returns version information with relative error correction bits + * + * The version information is included in QR Code symbols of version 7 or larger. + * It consists of an 18-bit sequence containing 6 data bits, + * with 12 error correction bits calculated using the (18, 6) Golay code. + * + * @param {Number} version QR Code version + * @return {Number} Encoded version info bits + */ +exports.getEncodedBits = function getEncodedBits (version) { + if (!VersionCheck.isValid(version) || version < 7) { + throw new Error('Invalid QR Code version') + } + + var d = version << 12; + + while (Utils.getBCHDigit(d) - G18_BCH >= 0) { + d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH)); + } + + return (version << 12) | d +}; + +},{"./error-correction-code":6,"./error-correction-level":7,"./mode":13,"./utils":20,"./version-check":21,"isarray":30}],23:[function(require,module,exports){ +var canPromise = require('can-promise'); +var QRCode = require('./core/qrcode'); +var CanvasRenderer = require('./renderer/canvas'); +var SvgRenderer = require('./renderer/svg-tag.js'); + +function renderCanvas (renderFunc, canvas, text, opts, cb) { + var args = [].slice.call(arguments, 1); + var argsNum = args.length; + var isLastArgCb = typeof args[argsNum - 1] === 'function'; + + if (!isLastArgCb && !canPromise()) { + throw new Error('Callback required as last argument') + } + + if (isLastArgCb) { + if (argsNum < 2) { + throw new Error('Too few arguments provided') + } + + if (argsNum === 2) { + cb = text; + text = canvas; + canvas = opts = undefined; + } else if (argsNum === 3) { + if (canvas.getContext && typeof cb === 'undefined') { + cb = opts; + opts = undefined; + } else { + cb = opts; + opts = text; + text = canvas; + canvas = undefined; + } + } + } else { + if (argsNum < 1) { + throw new Error('Too few arguments provided') + } + + if (argsNum === 1) { + text = canvas; + canvas = opts = undefined; + } else if (argsNum === 2 && !canvas.getContext) { + opts = text; + text = canvas; + canvas = undefined; + } + + return new Promise(function (resolve, reject) { + try { + var data = QRCode.create(text, opts); + resolve(renderFunc(data, canvas, opts)); + } catch (e) { + reject(e); + } + }) + } + + try { + var data = QRCode.create(text, opts); + cb(null, renderFunc(data, canvas, opts)); + } catch (e) { + cb(e); + } +} + +exports.create = QRCode.create; +exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render); +exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL); + +// only svg for now. +exports.toString = renderCanvas.bind(null, function (data, _, opts) { + return SvgRenderer.render(data, opts) +}); + +},{"./core/qrcode":16,"./renderer/canvas":24,"./renderer/svg-tag.js":25,"can-promise":28}],24:[function(require,module,exports){ +var Utils = require('./utils'); + +function clearCanvas (ctx, canvas, size) { + ctx.clearRect(0, 0, canvas.width, canvas.height); + + if (!canvas.style) canvas.style = {}; + canvas.height = size; + canvas.width = size; + canvas.style.height = size + 'px'; + canvas.style.width = size + 'px'; +} + +function getCanvasElement () { + try { + return document.createElement('canvas') + } catch (e) { + throw new Error('You need to specify a canvas element') + } +} + +exports.render = function render (qrData, canvas, options) { + var opts = options; + var canvasEl = canvas; + + if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) { + opts = canvas; + canvas = undefined; + } + + if (!canvas) { + canvasEl = getCanvasElement(); + } + + opts = Utils.getOptions(opts); + var size = Utils.getImageWidth(qrData.modules.size, opts); + + var ctx = canvasEl.getContext('2d'); + var image = ctx.createImageData(size, size); + Utils.qrToImageData(image.data, qrData, opts); + + clearCanvas(ctx, canvasEl, size); + ctx.putImageData(image, 0, 0); + + return canvasEl +}; + +exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) { + var opts = options; + + if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) { + opts = canvas; + canvas = undefined; + } + + if (!opts) opts = {}; + + var canvasEl = exports.render(qrData, canvas, opts); + + var type = opts.type || 'image/png'; + var rendererOpts = opts.rendererOpts || {}; + + return canvasEl.toDataURL(type, rendererOpts.quality) +}; + +},{"./utils":26}],25:[function(require,module,exports){ +var Utils = require('./utils'); + +function getColorAttrib (color, attrib) { + var alpha = color.a / 255; + var str = attrib + '="' + color.hex + '"'; + + return alpha < 1 + ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' + : str +} + +function svgCmd (cmd, x, y) { + var str = cmd + x; + if (typeof y !== 'undefined') str += ' ' + y; + + return str +} + +function qrToPath (data, size, margin) { + var path = ''; + var moveBy = 0; + var newRow = false; + var lineLength = 0; + + for (var i = 0; i < data.length; i++) { + var col = Math.floor(i % size); + var row = Math.floor(i / size); + + if (!col && !newRow) newRow = true; + + if (data[i]) { + lineLength++; + + if (!(i > 0 && col > 0 && data[i - 1])) { + path += newRow + ? svgCmd('M', col + margin, 0.5 + row + margin) + : svgCmd('m', moveBy, 0); + + moveBy = 0; + newRow = false; + } + + if (!(col + 1 < size && data[i + 1])) { + path += svgCmd('h', lineLength); + lineLength = 0; + } + } else { + moveBy++; + } + } + + return path +} + +exports.render = function render (qrData, options, cb) { + var opts = Utils.getOptions(options); + var size = qrData.modules.size; + var data = qrData.modules.data; + var qrcodesize = size + opts.margin * 2; + + var bg = !opts.color.light.a + ? '' + : ''; + + var path = + ''; + + var viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"'; + + var width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" '; + + var svgTag = '' + bg + path + '\n'; + + if (typeof cb === 'function') { + cb(null, svgTag); + } + + return svgTag +}; + +},{"./utils":26}],26:[function(require,module,exports){ +function hex2rgba (hex) { + if (typeof hex !== 'string') { + throw new Error('Color should be defined as hex string') + } + + var hexCode = hex.slice().replace('#', '').split(''); + if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) { + throw new Error('Invalid hex color: ' + hex) + } + + // Convert from short to long form (fff -> ffffff) + if (hexCode.length === 3 || hexCode.length === 4) { + hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) { + return [c, c] + })); + } + + // Add default alpha value + if (hexCode.length === 6) hexCode.push('F', 'F'); + + var hexValue = parseInt(hexCode.join(''), 16); + + return { + r: (hexValue >> 24) & 255, + g: (hexValue >> 16) & 255, + b: (hexValue >> 8) & 255, + a: hexValue & 255, + hex: '#' + hexCode.slice(0, 6).join('') + } +} + +exports.getOptions = function getOptions (options) { + if (!options) options = {}; + if (!options.color) options.color = {}; + + var margin = typeof options.margin === 'undefined' || + options.margin === null || + options.margin < 0 ? 4 : options.margin; + + var width = options.width && options.width >= 21 ? options.width : undefined; + var scale = options.scale || 4; + + return { + width: width, + scale: width ? 4 : scale, + margin: margin, + color: { + dark: hex2rgba(options.color.dark || '#000000ff'), + light: hex2rgba(options.color.light || '#ffffffff') + }, + type: options.type, + rendererOpts: options.rendererOpts || {} + } +}; + +exports.getScale = function getScale (qrSize, opts) { + return opts.width && opts.width >= qrSize + opts.margin * 2 + ? opts.width / (qrSize + opts.margin * 2) + : opts.scale +}; + +exports.getImageWidth = function getImageWidth (qrSize, opts) { + var scale = exports.getScale(qrSize, opts); + return Math.floor((qrSize + opts.margin * 2) * scale) +}; + +exports.qrToImageData = function qrToImageData (imgData, qr, opts) { + var size = qr.modules.size; + var data = qr.modules.data; + var scale = exports.getScale(size, opts); + var symbolSize = Math.floor((size + opts.margin * 2) * scale); + var scaledMargin = opts.margin * scale; + var palette = [opts.color.light, opts.color.dark]; + + for (var i = 0; i < symbolSize; i++) { + for (var j = 0; j < symbolSize; j++) { + var posDst = (i * symbolSize + j) * 4; + var pxColor = opts.color.light; + + if (i >= scaledMargin && j >= scaledMargin && + i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) { + var iSrc = Math.floor((i - scaledMargin) / scale); + var jSrc = Math.floor((j - scaledMargin) / scale); + pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0]; + } + + imgData[posDst++] = pxColor.r; + imgData[posDst++] = pxColor.g; + imgData[posDst++] = pxColor.b; + imgData[posDst] = pxColor.a; + } + } +}; + +},{}],27:[function(require,module,exports){ + +var isArray = require('isarray'); + +function typedArraySupport () { + // Can typed array instances be augmented? + try { + var arr = new Uint8Array(1); + arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}; + return arr.foo() === 42 + } catch (e) { + return false + } +} + +Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); + +var K_MAX_LENGTH = Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff; + +function Buffer (arg, offset, length) { + if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { + return new Buffer(arg, offset, length) + } + + if (typeof arg === 'number') { + return allocUnsafe(this, arg) + } + + return from(this, arg, offset, length) +} + +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype; + Buffer.__proto__ = Uint8Array; + + // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 + if (typeof Symbol !== 'undefined' && Symbol.species && + Buffer[Symbol.species] === Buffer) { + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true, + enumerable: false, + writable: false + }); + } +} + +function checked (length) { + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= K_MAX_LENGTH) { + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') + } + return length | 0 +} + +function isnan (val) { + return val !== val // eslint-disable-line no-self-compare +} + +function createBuffer (that, length) { + var buf; + if (Buffer.TYPED_ARRAY_SUPPORT) { + buf = new Uint8Array(length); + buf.__proto__ = Buffer.prototype; + } else { + // Fallback: Return an object instance of the Buffer class + buf = that; + if (buf === null) { + buf = new Buffer(length); + } + buf.length = length; + } + + return buf +} + +function allocUnsafe (that, size) { + var buf = createBuffer(that, size < 0 ? 0 : checked(size) | 0); + + if (!Buffer.TYPED_ARRAY_SUPPORT) { + for (var i = 0; i < size; ++i) { + buf[i] = 0; + } + } + + return buf +} + +function fromString (that, string) { + var length = byteLength(string) | 0; + var buf = createBuffer(that, length); + + var actual = buf.write(string); + + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + buf = buf.slice(0, actual); + } + + return buf +} + +function fromArrayLike (that, array) { + var length = array.length < 0 ? 0 : checked(array.length) | 0; + var buf = createBuffer(that, length); + for (var i = 0; i < length; i += 1) { + buf[i] = array[i] & 255; + } + return buf +} + +function fromArrayBuffer (that, array, byteOffset, length) { + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('\'offset\' is out of bounds') + } + + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('\'length\' is out of bounds') + } + + var buf; + if (byteOffset === undefined && length === undefined) { + buf = new Uint8Array(array); + } else if (length === undefined) { + buf = new Uint8Array(array, byteOffset); + } else { + buf = new Uint8Array(array, byteOffset, length); + } + + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + buf.__proto__ = Buffer.prototype; + } else { + // Fallback: Return an object instance of the Buffer class + buf = fromArrayLike(that, buf); + } + + return buf +} + +function fromObject (that, obj) { + if (Buffer.isBuffer(obj)) { + var len = checked(obj.length) | 0; + var buf = createBuffer(that, len); + + if (buf.length === 0) { + return buf + } + + obj.copy(buf, 0, 0, len); + return buf + } + + if (obj) { + if ((typeof ArrayBuffer !== 'undefined' && + obj.buffer instanceof ArrayBuffer) || 'length' in obj) { + if (typeof obj.length !== 'number' || isnan(obj.length)) { + return createBuffer(that, 0) + } + return fromArrayLike(that, obj) + } + + if (obj.type === 'Buffer' && Array.isArray(obj.data)) { + return fromArrayLike(that, obj.data) + } + } + + throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') +} + +function utf8ToBytes (string, units) { + units = units || Infinity; + var codePoint; + var length = string.length; + var leadSurrogate = null; + var bytes = []; + + for (var i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i); + + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + continue + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + continue + } + + // valid lead + leadSurrogate = codePoint; + + continue + } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + leadSurrogate = codePoint; + continue + } + + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000; + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + } + + leadSurrogate = null; + + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break + bytes.push(codePoint); + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break + bytes.push( + codePoint >> 0x6 | 0xC0, + codePoint & 0x3F | 0x80 + ); + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break + bytes.push( + codePoint >> 0xC | 0xE0, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ); + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break + bytes.push( + codePoint >> 0x12 | 0xF0, + codePoint >> 0xC & 0x3F | 0x80, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ); + } else { + throw new Error('Invalid code point') + } + } + + return bytes +} + +function byteLength (string) { + if (Buffer.isBuffer(string)) { + return string.length + } + if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && + (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { + return string.byteLength + } + if (typeof string !== 'string') { + string = '' + string; + } + + var len = string.length; + if (len === 0) return 0 + + return utf8ToBytes(string).length +} + +function blitBuffer (src, dst, offset, length) { + for (var i = 0; i < length; ++i) { + if ((i + offset >= dst.length) || (i >= src.length)) break + dst[i + offset] = src[i]; + } + return i +} + +function utf8Write (buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) +} + +function from (that, value, offset, length) { + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number') + } + + if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { + return fromArrayBuffer(that, value, offset, length) + } + + if (typeof value === 'string') { + return fromString(that, value, offset) + } + + return fromObject(that, value) +} + +Buffer.prototype.write = function write (string, offset, length) { + // Buffer#write(string) + if (offset === undefined) { + length = this.length; + offset = 0; + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + length = this.length; + offset = 0; + // Buffer#write(string, offset[, length]) + } else if (isFinite(offset)) { + offset = offset | 0; + if (isFinite(length)) { + length = length | 0; + } else { + length = undefined; + } + } + + var remaining = this.length - offset; + if (length === undefined || length > remaining) length = remaining; + + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { + throw new RangeError('Attempt to write outside buffer bounds') + } + + return utf8Write(this, string, offset, length) +}; + +Buffer.prototype.slice = function slice (start, end) { + var len = this.length; + start = ~~start; + end = end === undefined ? len : ~~end; + + if (start < 0) { + start += len; + if (start < 0) start = 0; + } else if (start > len) { + start = len; + } + + if (end < 0) { + end += len; + if (end < 0) end = 0; + } else if (end > len) { + end = len; + } + + if (end < start) end = start; + + var newBuf; + if (Buffer.TYPED_ARRAY_SUPPORT) { + newBuf = this.subarray(start, end); + // Return an augmented `Uint8Array` instance + newBuf.__proto__ = Buffer.prototype; + } else { + var sliceLen = end - start; + newBuf = new Buffer(sliceLen, undefined); + for (var i = 0; i < sliceLen; ++i) { + newBuf[i] = this[i + start]; + } + } + + return newBuf +}; + +Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!start) start = 0; + if (!end && end !== 0) end = this.length; + if (targetStart >= target.length) targetStart = target.length; + if (!targetStart) targetStart = 0; + if (end > 0 && end < start) end = start; + + // Copy 0 bytes; we're done + if (end === start) return 0 + if (target.length === 0 || this.length === 0) return 0 + + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError('targetStart out of bounds') + } + if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') + if (end < 0) throw new RangeError('sourceEnd out of bounds') + + // Are we oob? + if (end > this.length) end = this.length; + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start; + } + + var len = end - start; + var i; + + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; --i) { + target[i + targetStart] = this[i + start]; + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; ++i) { + target[i + targetStart] = this[i + start]; + } + } else { + Uint8Array.prototype.set.call( + target, + this.subarray(start, start + len), + targetStart + ); + } + + return len +}; + +Buffer.prototype.fill = function fill (val, start, end) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + start = 0; + end = this.length; + } else if (typeof end === 'string') { + end = this.length; + } + if (val.length === 1) { + var code = val.charCodeAt(0); + if (code < 256) { + val = code; + } + } + } else if (typeof val === 'number') { + val = val & 255; + } + + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError('Out of range index') + } + + if (end <= start) { + return this + } + + start = start >>> 0; + end = end === undefined ? this.length : end >>> 0; + + if (!val) val = 0; + + var i; + if (typeof val === 'number') { + for (i = start; i < end; ++i) { + this[i] = val; + } + } else { + var bytes = Buffer.isBuffer(val) + ? val + : new Buffer(val); + var len = bytes.length; + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len]; + } + } + + return this +}; + +Buffer.concat = function concat (list, length) { + if (!isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + + if (list.length === 0) { + return createBuffer(null, 0) + } + + var i; + if (length === undefined) { + length = 0; + for (i = 0; i < list.length; ++i) { + length += list[i].length; + } + } + + var buffer = allocUnsafe(null, length); + var pos = 0; + for (i = 0; i < list.length; ++i) { + var buf = list[i]; + if (!Buffer.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + buf.copy(buffer, pos); + pos += buf.length; + } + return buffer +}; + +Buffer.byteLength = byteLength; + +Buffer.prototype._isBuffer = true; +Buffer.isBuffer = function isBuffer (b) { + return !!(b != null && b._isBuffer) +}; + +module.exports = Buffer; + +},{"isarray":30}],28:[function(require,module,exports){ + +var G = require('window-or-global'); + +module.exports = function() { + return ( + typeof G.Promise === 'function' && + typeof G.Promise.prototype.then === 'function' + ) +}; + +},{"window-or-global":31}],29:[function(require,module,exports){ + +/****************************************************************************** + * Created 2008-08-19. + * + * Dijkstra path-finding functions. Adapted from the Dijkstar Python project. + * + * Copyright (C) 2008 + * Wyatt Baldwin + * All rights reserved + * + * Licensed under the MIT license. + * + * http://www.opensource.org/licenses/mit-license.php + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + *****************************************************************************/ +var dijkstra = { + single_source_shortest_paths: function(graph, s, d) { + // Predecessor map for each node that has been encountered. + // node ID => predecessor node ID + var predecessors = {}; + + // Costs of shortest paths from s to all nodes encountered. + // node ID => cost + var costs = {}; + costs[s] = 0; + + // Costs of shortest paths from s to all nodes encountered; differs from + // `costs` in that it provides easy access to the node that currently has + // the known shortest path from s. + // XXX: Do we actually need both `costs` and `open`? + var open = dijkstra.PriorityQueue.make(); + open.push(s, 0); + + var closest, + u, v, + cost_of_s_to_u, + adjacent_nodes, + cost_of_e, + cost_of_s_to_u_plus_cost_of_e, + cost_of_s_to_v, + first_visit; + while (!open.empty()) { + // In the nodes remaining in graph that have a known cost from s, + // find the node, u, that currently has the shortest path from s. + closest = open.pop(); + u = closest.value; + cost_of_s_to_u = closest.cost; + + // Get nodes adjacent to u... + adjacent_nodes = graph[u] || {}; + + // ...and explore the edges that connect u to those nodes, updating + // the cost of the shortest paths to any or all of those nodes as + // necessary. v is the node across the current edge from u. + for (v in adjacent_nodes) { + if (adjacent_nodes.hasOwnProperty(v)) { + // Get the cost of the edge running from u to v. + cost_of_e = adjacent_nodes[v]; + + // Cost of s to u plus the cost of u to v across e--this is *a* + // cost from s to v that may or may not be less than the current + // known cost to v. + cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e; + + // If we haven't visited v yet OR if the current known cost from s to + // v is greater than the new cost we just found (cost of s to u plus + // cost of u to v across e), update v's cost in the cost list and + // update v's predecessor in the predecessor list (it's now u). + cost_of_s_to_v = costs[v]; + first_visit = (typeof costs[v] === 'undefined'); + if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) { + costs[v] = cost_of_s_to_u_plus_cost_of_e; + open.push(v, cost_of_s_to_u_plus_cost_of_e); + predecessors[v] = u; + } + } + } + } + + if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') { + var msg = ['Could not find a path from ', s, ' to ', d, '.'].join(''); + throw new Error(msg); + } + + return predecessors; + }, + + extract_shortest_path_from_predecessor_list: function(predecessors, d) { + var nodes = []; + var u = d; + var predecessor; + while (u) { + nodes.push(u); + predecessor = predecessors[u]; + u = predecessors[u]; + } + nodes.reverse(); + return nodes; + }, + + find_path: function(graph, s, d) { + var predecessors = dijkstra.single_source_shortest_paths(graph, s, d); + return dijkstra.extract_shortest_path_from_predecessor_list( + predecessors, d); + }, + + /** + * A very naive priority queue implementation. + */ + PriorityQueue: { + make: function (opts) { + var T = dijkstra.PriorityQueue, + t = {}, + key; + opts = opts || {}; + for (key in T) { + if (T.hasOwnProperty(key)) { + t[key] = T[key]; + } + } + t.queue = []; + t.sorter = opts.sorter || T.default_sorter; + return t; + }, + + default_sorter: function (a, b) { + return a.cost - b.cost; + }, + + /** + * Add a new item to the queue and ensure the highest priority element + * is at the front of the queue. + */ + push: function (value, cost) { + var item = {value: value, cost: cost}; + this.queue.push(item); + this.queue.sort(this.sorter); + }, + + /** + * Return the highest priority element in the queue. + */ + pop: function () { + return this.queue.shift(); + }, + + empty: function () { + return this.queue.length === 0; + } + } +}; + + +// node.js module exports +if (typeof module !== 'undefined') { + module.exports = dijkstra; +} + +},{}],30:[function(require,module,exports){ +var toString = {}.toString; + +module.exports = Array.isArray || function (arr) { + return toString.call(arr) == '[object Array]'; +}; + +},{}],31:[function(require,module,exports){ +(function (global){ +module.exports = (typeof self === 'object' && self.self === self && self) || + (typeof global === 'object' && global.global === global && global) || + this; + +}).call(this,typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}); + +},{}]},{},[23])(23) +}); + + +}); + +var index = { + name: 'qrcode', + props: { + /** + * The options for the QR code generator. + * {@link https://github.com/soldair/node-qrcode#qr-code-options} + */ + options: Object, + + /** + * The tag name of the component's root element. + */ + tag: { + type: String, + default: 'canvas' + }, + + /** + * The value of the QR code. + */ + value: null + }, + render: function render(createElement) { + return createElement(this.tag, this.$slots.default); + }, + watch: { + $props: { + deep: true, + immediate: true, + handler: function handler() { + if (this.$el) { + this.generate(); + } + } + } + }, + methods: { + /** + * Generate QR code. + */ + generate: function generate() { + var _this = this; + + var options = this.options, + tag = this.tag; + var value = String(this.value); + + if (tag === 'canvas') { + qrcode.toCanvas(this.$el, value, options, function (error) { + if (error) { + throw error; + } + }); + } else if (tag === 'img') { + qrcode.toDataURL(value, options, function (error, url) { + if (error) { + throw error; + } + + _this.$el.src = url; + }); + } else { + qrcode.toString(value, options, function (error, string) { + if (error) { + throw error; + } + + _this.$el.innerHTML = string; + }); + } + } + }, + mounted: function mounted() { + this.generate(); + } +}; + +export default index; diff --git a/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.js b/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.js new file mode 100644 index 000000000..1e5a28c54 --- /dev/null +++ b/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.js @@ -0,0 +1,3474 @@ +/*! + * vue-qrcode v1.0.0 + * https://fengyuanchen.github.io/vue-qrcode + * + * Copyright 2018-present Chen Fengyuan + * Released under the MIT license + * + * Date: 2018-10-21T13:04:02.951Z + */ + +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.VueQrcode = factory()); +}(this, (function () { 'use strict'; + + var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + + function commonjsRequire () { + throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs'); + } + + function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; + } + + var qrcode = createCommonjsModule(function (module, exports) { + (function(f){{module.exports=f();}})(function(){return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof commonjsRequire&&commonjsRequire;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t);}return n[i].exports}for(var u="function"==typeof commonjsRequire&&commonjsRequire,i=0;i>> (7 - index % 8)) & 1) === 1 + }, + + put: function (num, length) { + for (var i = 0; i < length; i++) { + this.putBit(((num >>> (length - i - 1)) & 1) === 1); + } + }, + + getLengthInBits: function () { + return this.length + }, + + putBit: function (bit) { + var bufIndex = Math.floor(this.length / 8); + if (this.buffer.length <= bufIndex) { + this.buffer.push(0); + } + + if (bit) { + this.buffer[bufIndex] |= (0x80 >>> (this.length % 8)); + } + + this.length++; + } + }; + + module.exports = BitBuffer; + + },{}],4:[function(require,module,exports){ + var Buffer = require('../utils/buffer'); + + /** + * Helper class to handle QR Code symbol modules + * + * @param {Number} size Symbol size + */ + function BitMatrix (size) { + if (!size || size < 1) { + throw new Error('BitMatrix size must be defined and greater than 0') + } + + this.size = size; + this.data = new Buffer(size * size); + this.data.fill(0); + this.reservedBit = new Buffer(size * size); + this.reservedBit.fill(0); + } + + /** + * Set bit value at specified location + * If reserved flag is set, this bit will be ignored during masking process + * + * @param {Number} row + * @param {Number} col + * @param {Boolean} value + * @param {Boolean} reserved + */ + BitMatrix.prototype.set = function (row, col, value, reserved) { + var index = row * this.size + col; + this.data[index] = value; + if (reserved) this.reservedBit[index] = true; + }; + + /** + * Returns bit value at specified location + * + * @param {Number} row + * @param {Number} col + * @return {Boolean} + */ + BitMatrix.prototype.get = function (row, col) { + return this.data[row * this.size + col] + }; + + /** + * Applies xor operator at specified location + * (used during masking process) + * + * @param {Number} row + * @param {Number} col + * @param {Boolean} value + */ + BitMatrix.prototype.xor = function (row, col, value) { + this.data[row * this.size + col] ^= value; + }; + + /** + * Check if bit at specified location is reserved + * + * @param {Number} row + * @param {Number} col + * @return {Boolean} + */ + BitMatrix.prototype.isReserved = function (row, col) { + return this.reservedBit[row * this.size + col] + }; + + module.exports = BitMatrix; + + },{"../utils/buffer":27}],5:[function(require,module,exports){ + var Buffer = require('../utils/buffer'); + var Mode = require('./mode'); + + function ByteData (data) { + this.mode = Mode.BYTE; + this.data = new Buffer(data); + } + + ByteData.getBitsLength = function getBitsLength (length) { + return length * 8 + }; + + ByteData.prototype.getLength = function getLength () { + return this.data.length + }; + + ByteData.prototype.getBitsLength = function getBitsLength () { + return ByteData.getBitsLength(this.data.length) + }; + + ByteData.prototype.write = function (bitBuffer) { + for (var i = 0, l = this.data.length; i < l; i++) { + bitBuffer.put(this.data[i], 8); + } + }; + + module.exports = ByteData; + + },{"../utils/buffer":27,"./mode":13}],6:[function(require,module,exports){ + var ECLevel = require('./error-correction-level'); + + var EC_BLOCKS_TABLE = [ + // L M Q H + 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 + ]; + + var EC_CODEWORDS_TABLE = [ + // L M Q H + 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 + ]; + + /** + * Returns the number of error correction block that the QR Code should contain + * for the specified version and error correction level. + * + * @param {Number} version QR Code version + * @param {Number} errorCorrectionLevel Error correction level + * @return {Number} Number of error correction blocks + */ + exports.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) { + switch (errorCorrectionLevel) { + case ECLevel.L: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 0] + case ECLevel.M: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 1] + case ECLevel.Q: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 2] + case ECLevel.H: + return EC_BLOCKS_TABLE[(version - 1) * 4 + 3] + default: + return undefined + } + }; + + /** + * Returns the number of error correction codewords to use for the specified + * version and error correction level. + * + * @param {Number} version QR Code version + * @param {Number} errorCorrectionLevel Error correction level + * @return {Number} Number of error correction codewords + */ + exports.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) { + switch (errorCorrectionLevel) { + case ECLevel.L: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0] + case ECLevel.M: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1] + case ECLevel.Q: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2] + case ECLevel.H: + return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3] + default: + return undefined + } + }; + + },{"./error-correction-level":7}],7:[function(require,module,exports){ + exports.L = { bit: 1 }; + exports.M = { bit: 0 }; + exports.Q = { bit: 3 }; + exports.H = { bit: 2 }; + + function fromString (string) { + if (typeof string !== 'string') { + throw new Error('Param is not a string') + } + + var lcStr = string.toLowerCase(); + + switch (lcStr) { + case 'l': + case 'low': + return exports.L + + case 'm': + case 'medium': + return exports.M + + case 'q': + case 'quartile': + return exports.Q + + case 'h': + case 'high': + return exports.H + + default: + throw new Error('Unknown EC Level: ' + string) + } + } + + exports.isValid = function isValid (level) { + return level && typeof level.bit !== 'undefined' && + level.bit >= 0 && level.bit < 4 + }; + + exports.from = function from (value, defaultValue) { + if (exports.isValid(value)) { + return value + } + + try { + return fromString(value) + } catch (e) { + return defaultValue + } + }; + + },{}],8:[function(require,module,exports){ + var getSymbolSize = require('./utils').getSymbolSize; + var FINDER_PATTERN_SIZE = 7; + + /** + * Returns an array containing the positions of each finder pattern. + * Each array's element represent the top-left point of the pattern as (x, y) coordinates + * + * @param {Number} version QR Code version + * @return {Array} Array of coordinates + */ + exports.getPositions = function getPositions (version) { + var size = getSymbolSize(version); + + return [ + // top-left + [0, 0], + // top-right + [size - FINDER_PATTERN_SIZE, 0], + // bottom-left + [0, size - FINDER_PATTERN_SIZE] + ] + }; + + },{"./utils":20}],9:[function(require,module,exports){ + var Utils = require('./utils'); + + var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0); + var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1); + var G15_BCH = Utils.getBCHDigit(G15); + + /** + * Returns format information with relative error correction bits + * + * The format information is a 15-bit sequence containing 5 data bits, + * with 10 error correction bits calculated using the (15, 5) BCH code. + * + * @param {Number} errorCorrectionLevel Error correction level + * @param {Number} mask Mask pattern + * @return {Number} Encoded format information bits + */ + exports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) { + var data = ((errorCorrectionLevel.bit << 3) | mask); + var d = data << 10; + + while (Utils.getBCHDigit(d) - G15_BCH >= 0) { + d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH)); + } + + // xor final data with mask pattern in order to ensure that + // no combination of Error Correction Level and data mask pattern + // will result in an all-zero data string + return ((data << 10) | d) ^ G15_MASK + }; + + },{"./utils":20}],10:[function(require,module,exports){ + var Buffer = require('../utils/buffer'); + + var EXP_TABLE = new Buffer(512); + var LOG_TABLE = new Buffer(256) + + /** + * Precompute the log and anti-log tables for faster computation later + * + * For each possible value in the galois field 2^8, we will pre-compute + * the logarithm and anti-logarithm (exponential) of this value + * + * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields} + */ + ;(function initTables () { + var x = 1; + for (var i = 0; i < 255; i++) { + EXP_TABLE[i] = x; + LOG_TABLE[x] = i; + + x <<= 1; // multiply by 2 + + // The QR code specification says to use byte-wise modulo 100011101 arithmetic. + // This means that when a number is 256 or larger, it should be XORed with 0x11D. + if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256) + x ^= 0x11D; + } + } + + // Optimization: double the size of the anti-log table so that we don't need to mod 255 to + // stay inside the bounds (because we will mainly use this table for the multiplication of + // two GF numbers, no more). + // @see {@link mul} + for (i = 255; i < 512; i++) { + EXP_TABLE[i] = EXP_TABLE[i - 255]; + } + }()); + + /** + * Returns log value of n inside Galois Field + * + * @param {Number} n + * @return {Number} + */ + exports.log = function log (n) { + if (n < 1) throw new Error('log(' + n + ')') + return LOG_TABLE[n] + }; + + /** + * Returns anti-log value of n inside Galois Field + * + * @param {Number} n + * @return {Number} + */ + exports.exp = function exp (n) { + return EXP_TABLE[n] + }; + + /** + * Multiplies two number inside Galois Field + * + * @param {Number} x + * @param {Number} y + * @return {Number} + */ + exports.mul = function mul (x, y) { + if (x === 0 || y === 0) return 0 + + // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized + // @see {@link initTables} + return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]] + }; + + },{"../utils/buffer":27}],11:[function(require,module,exports){ + var Mode = require('./mode'); + var Utils = require('./utils'); + + function KanjiData (data) { + this.mode = Mode.KANJI; + this.data = data; + } + + KanjiData.getBitsLength = function getBitsLength (length) { + return length * 13 + }; + + KanjiData.prototype.getLength = function getLength () { + return this.data.length + }; + + KanjiData.prototype.getBitsLength = function getBitsLength () { + return KanjiData.getBitsLength(this.data.length) + }; + + KanjiData.prototype.write = function (bitBuffer) { + var i; + + // In the Shift JIS system, Kanji characters are represented by a two byte combination. + // These byte values are shifted from the JIS X 0208 values. + // JIS X 0208 gives details of the shift coded representation. + for (i = 0; i < this.data.length; i++) { + var value = Utils.toSJIS(this.data[i]); + + // For characters with Shift JIS values from 0x8140 to 0x9FFC: + if (value >= 0x8140 && value <= 0x9FFC) { + // Subtract 0x8140 from Shift JIS value + value -= 0x8140; + + // For characters with Shift JIS values from 0xE040 to 0xEBBF + } else if (value >= 0xE040 && value <= 0xEBBF) { + // Subtract 0xC140 from Shift JIS value + value -= 0xC140; + } else { + throw new Error( + 'Invalid SJIS character: ' + this.data[i] + '\n' + + 'Make sure your charset is UTF-8') + } + + // Multiply most significant byte of result by 0xC0 + // and add least significant byte to product + value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff); + + // Convert result to a 13-bit binary string + bitBuffer.put(value, 13); + } + }; + + module.exports = KanjiData; + + },{"./mode":13,"./utils":20}],12:[function(require,module,exports){ + /** + * Data mask pattern reference + * @type {Object} + */ + exports.Patterns = { + PATTERN000: 0, + PATTERN001: 1, + PATTERN010: 2, + PATTERN011: 3, + PATTERN100: 4, + PATTERN101: 5, + PATTERN110: 6, + PATTERN111: 7 + }; + + /** + * Weighted penalty scores for the undesirable features + * @type {Object} + */ + var PenaltyScores = { + N1: 3, + N2: 3, + N3: 40, + N4: 10 + }; + + /** + * Check if mask pattern value is valid + * + * @param {Number} mask Mask pattern + * @return {Boolean} true if valid, false otherwise + */ + exports.isValid = function isValid (mask) { + return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7 + }; + + /** + * Returns mask pattern from a value. + * If value is not valid, returns undefined + * + * @param {Number|String} value Mask pattern value + * @return {Number} Valid mask pattern or undefined + */ + exports.from = function from (value) { + return exports.isValid(value) ? parseInt(value, 10) : undefined + }; + + /** + * Find adjacent modules in row/column with the same color + * and assign a penalty value. + * + * Points: N1 + i + * i is the amount by which the number of adjacent modules of the same color exceeds 5 + */ + exports.getPenaltyN1 = function getPenaltyN1 (data) { + var size = data.size; + var points = 0; + var sameCountCol = 0; + var sameCountRow = 0; + var lastCol = null; + var lastRow = null; + + for (var row = 0; row < size; row++) { + sameCountCol = sameCountRow = 0; + lastCol = lastRow = null; + + for (var col = 0; col < size; col++) { + var module = data.get(row, col); + if (module === lastCol) { + sameCountCol++; + } else { + if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5); + lastCol = module; + sameCountCol = 1; + } + + module = data.get(col, row); + if (module === lastRow) { + sameCountRow++; + } else { + if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5); + lastRow = module; + sameCountRow = 1; + } + } + + if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5); + if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5); + } + + return points + }; + + /** + * Find 2x2 blocks with the same color and assign a penalty value + * + * Points: N2 * (m - 1) * (n - 1) + */ + exports.getPenaltyN2 = function getPenaltyN2 (data) { + var size = data.size; + var points = 0; + + for (var row = 0; row < size - 1; row++) { + for (var col = 0; col < size - 1; col++) { + var last = data.get(row, col) + + data.get(row, col + 1) + + data.get(row + 1, col) + + data.get(row + 1, col + 1); + + if (last === 4 || last === 0) points++; + } + } + + return points * PenaltyScores.N2 + }; + + /** + * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column, + * preceded or followed by light area 4 modules wide + * + * Points: N3 * number of pattern found + */ + exports.getPenaltyN3 = function getPenaltyN3 (data) { + var size = data.size; + var points = 0; + var bitsCol = 0; + var bitsRow = 0; + + for (var row = 0; row < size; row++) { + bitsCol = bitsRow = 0; + for (var col = 0; col < size; col++) { + bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col); + if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++; + + bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row); + if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++; + } + } + + return points * PenaltyScores.N3 + }; + + /** + * Calculate proportion of dark modules in entire symbol + * + * Points: N4 * k + * + * k is the rating of the deviation of the proportion of dark modules + * in the symbol from 50% in steps of 5% + */ + exports.getPenaltyN4 = function getPenaltyN4 (data) { + var darkCount = 0; + var modulesCount = data.data.length; + + for (var i = 0; i < modulesCount; i++) darkCount += data.data[i]; + + var k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10); + + return k * PenaltyScores.N4 + }; + + /** + * Return mask value at given position + * + * @param {Number} maskPattern Pattern reference value + * @param {Number} i Row + * @param {Number} j Column + * @return {Boolean} Mask value + */ + function getMaskAt (maskPattern, i, j) { + switch (maskPattern) { + case exports.Patterns.PATTERN000: return (i + j) % 2 === 0 + case exports.Patterns.PATTERN001: return i % 2 === 0 + case exports.Patterns.PATTERN010: return j % 3 === 0 + case exports.Patterns.PATTERN011: return (i + j) % 3 === 0 + case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0 + case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0 + case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0 + case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0 + + default: throw new Error('bad maskPattern:' + maskPattern) + } + } + + /** + * Apply a mask pattern to a BitMatrix + * + * @param {Number} pattern Pattern reference number + * @param {BitMatrix} data BitMatrix data + */ + exports.applyMask = function applyMask (pattern, data) { + var size = data.size; + + for (var col = 0; col < size; col++) { + for (var row = 0; row < size; row++) { + if (data.isReserved(row, col)) continue + data.xor(row, col, getMaskAt(pattern, row, col)); + } + } + }; + + /** + * Returns the best mask pattern for data + * + * @param {BitMatrix} data + * @return {Number} Mask pattern reference number + */ + exports.getBestMask = function getBestMask (data, setupFormatFunc) { + var numPatterns = Object.keys(exports.Patterns).length; + var bestPattern = 0; + var lowerPenalty = Infinity; + + for (var p = 0; p < numPatterns; p++) { + setupFormatFunc(p); + exports.applyMask(p, data); + + // Calculate penalty + var penalty = + exports.getPenaltyN1(data) + + exports.getPenaltyN2(data) + + exports.getPenaltyN3(data) + + exports.getPenaltyN4(data); + + // Undo previously applied mask + exports.applyMask(p, data); + + if (penalty < lowerPenalty) { + lowerPenalty = penalty; + bestPattern = p; + } + } + + return bestPattern + }; + + },{}],13:[function(require,module,exports){ + var VersionCheck = require('./version-check'); + var Regex = require('./regex'); + + /** + * Numeric mode encodes data from the decimal digit set (0 - 9) + * (byte values 30HEX to 39HEX). + * Normally, 3 data characters are represented by 10 bits. + * + * @type {Object} + */ + exports.NUMERIC = { + id: 'Numeric', + bit: 1 << 0, + ccBits: [10, 12, 14] + }; + + /** + * Alphanumeric mode encodes data from a set of 45 characters, + * i.e. 10 numeric digits (0 - 9), + * 26 alphabetic characters (A - Z), + * and 9 symbols (SP, $, %, *, +, -, ., /, :). + * Normally, two input characters are represented by 11 bits. + * + * @type {Object} + */ + exports.ALPHANUMERIC = { + id: 'Alphanumeric', + bit: 1 << 1, + ccBits: [9, 11, 13] + }; + + /** + * In byte mode, data is encoded at 8 bits per character. + * + * @type {Object} + */ + exports.BYTE = { + id: 'Byte', + bit: 1 << 2, + ccBits: [8, 16, 16] + }; + + /** + * The Kanji mode efficiently encodes Kanji characters in accordance with + * the Shift JIS system based on JIS X 0208. + * The Shift JIS values are shifted from the JIS X 0208 values. + * JIS X 0208 gives details of the shift coded representation. + * Each two-byte character value is compacted to a 13-bit binary codeword. + * + * @type {Object} + */ + exports.KANJI = { + id: 'Kanji', + bit: 1 << 3, + ccBits: [8, 10, 12] + }; + + /** + * Mixed mode will contain a sequences of data in a combination of any of + * the modes described above + * + * @type {Object} + */ + exports.MIXED = { + bit: -1 + }; + + /** + * Returns the number of bits needed to store the data length + * according to QR Code specifications. + * + * @param {Mode} mode Data mode + * @param {Number} version QR Code version + * @return {Number} Number of bits + */ + exports.getCharCountIndicator = function getCharCountIndicator (mode, version) { + if (!mode.ccBits) throw new Error('Invalid mode: ' + mode) + + if (!VersionCheck.isValid(version)) { + throw new Error('Invalid version: ' + version) + } + + if (version >= 1 && version < 10) return mode.ccBits[0] + else if (version < 27) return mode.ccBits[1] + return mode.ccBits[2] + }; + + /** + * Returns the most efficient mode to store the specified data + * + * @param {String} dataStr Input data string + * @return {Mode} Best mode + */ + exports.getBestModeForData = function getBestModeForData (dataStr) { + if (Regex.testNumeric(dataStr)) return exports.NUMERIC + else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC + else if (Regex.testKanji(dataStr)) return exports.KANJI + else return exports.BYTE + }; + + /** + * Return mode name as string + * + * @param {Mode} mode Mode object + * @returns {String} Mode name + */ + exports.toString = function toString (mode) { + if (mode && mode.id) return mode.id + throw new Error('Invalid mode') + }; + + /** + * Check if input param is a valid mode object + * + * @param {Mode} mode Mode object + * @returns {Boolean} True if valid mode, false otherwise + */ + exports.isValid = function isValid (mode) { + return mode && mode.bit && mode.ccBits + }; + + /** + * Get mode object from its name + * + * @param {String} string Mode name + * @returns {Mode} Mode object + */ + function fromString (string) { + if (typeof string !== 'string') { + throw new Error('Param is not a string') + } + + var lcStr = string.toLowerCase(); + + switch (lcStr) { + case 'numeric': + return exports.NUMERIC + case 'alphanumeric': + return exports.ALPHANUMERIC + case 'kanji': + return exports.KANJI + case 'byte': + return exports.BYTE + default: + throw new Error('Unknown mode: ' + string) + } + } + + /** + * Returns mode from a value. + * If value is not a valid mode, returns defaultValue + * + * @param {Mode|String} value Encoding mode + * @param {Mode} defaultValue Fallback value + * @return {Mode} Encoding mode + */ + exports.from = function from (value, defaultValue) { + if (exports.isValid(value)) { + return value + } + + try { + return fromString(value) + } catch (e) { + return defaultValue + } + }; + + },{"./regex":18,"./version-check":21}],14:[function(require,module,exports){ + var Mode = require('./mode'); + + function NumericData (data) { + this.mode = Mode.NUMERIC; + this.data = data.toString(); + } + + NumericData.getBitsLength = function getBitsLength (length) { + return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0) + }; + + NumericData.prototype.getLength = function getLength () { + return this.data.length + }; + + NumericData.prototype.getBitsLength = function getBitsLength () { + return NumericData.getBitsLength(this.data.length) + }; + + NumericData.prototype.write = function write (bitBuffer) { + var i, group, value; + + // The input data string is divided into groups of three digits, + // and each group is converted to its 10-bit binary equivalent. + for (i = 0; i + 3 <= this.data.length; i += 3) { + group = this.data.substr(i, 3); + value = parseInt(group, 10); + + bitBuffer.put(value, 10); + } + + // If the number of input digits is not an exact multiple of three, + // the final one or two digits are converted to 4 or 7 bits respectively. + var remainingNum = this.data.length - i; + if (remainingNum > 0) { + group = this.data.substr(i); + value = parseInt(group, 10); + + bitBuffer.put(value, remainingNum * 3 + 1); + } + }; + + module.exports = NumericData; + + },{"./mode":13}],15:[function(require,module,exports){ + var Buffer = require('../utils/buffer'); + var GF = require('./galois-field'); + + /** + * Multiplies two polynomials inside Galois Field + * + * @param {Buffer} p1 Polynomial + * @param {Buffer} p2 Polynomial + * @return {Buffer} Product of p1 and p2 + */ + exports.mul = function mul (p1, p2) { + var coeff = new Buffer(p1.length + p2.length - 1); + coeff.fill(0); + + for (var i = 0; i < p1.length; i++) { + for (var j = 0; j < p2.length; j++) { + coeff[i + j] ^= GF.mul(p1[i], p2[j]); + } + } + + return coeff + }; + + /** + * Calculate the remainder of polynomials division + * + * @param {Buffer} divident Polynomial + * @param {Buffer} divisor Polynomial + * @return {Buffer} Remainder + */ + exports.mod = function mod (divident, divisor) { + var result = new Buffer(divident); + + while ((result.length - divisor.length) >= 0) { + var coeff = result[0]; + + for (var i = 0; i < divisor.length; i++) { + result[i] ^= GF.mul(divisor[i], coeff); + } + + // remove all zeros from buffer head + var offset = 0; + while (offset < result.length && result[offset] === 0) offset++; + result = result.slice(offset); + } + + return result + }; + + /** + * Generate an irreducible generator polynomial of specified degree + * (used by Reed-Solomon encoder) + * + * @param {Number} degree Degree of the generator polynomial + * @return {Buffer} Buffer containing polynomial coefficients + */ + exports.generateECPolynomial = function generateECPolynomial (degree) { + var poly = new Buffer([1]); + for (var i = 0; i < degree; i++) { + poly = exports.mul(poly, [1, GF.exp(i)]); + } + + return poly + }; + + },{"../utils/buffer":27,"./galois-field":10}],16:[function(require,module,exports){ + var Buffer = require('../utils/buffer'); + var Utils = require('./utils'); + var ECLevel = require('./error-correction-level'); + var BitBuffer = require('./bit-buffer'); + var BitMatrix = require('./bit-matrix'); + var AlignmentPattern = require('./alignment-pattern'); + var FinderPattern = require('./finder-pattern'); + var MaskPattern = require('./mask-pattern'); + var ECCode = require('./error-correction-code'); + var ReedSolomonEncoder = require('./reed-solomon-encoder'); + var Version = require('./version'); + var FormatInfo = require('./format-info'); + var Mode = require('./mode'); + var Segments = require('./segments'); + var isArray = require('isarray'); + + /** + * QRCode for JavaScript + * + * modified by Ryan Day for nodejs support + * Copyright (c) 2011 Ryan Day + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/mit-license.php + * + //--------------------------------------------------------------------- + // QRCode for JavaScript + // + // Copyright (c) 2009 Kazuhiko Arase + // + // URL: http://www.d-project.com/ + // + // Licensed under the MIT license: + // http://www.opensource.org/licenses/mit-license.php + // + // The word "QR Code" is registered trademark of + // DENSO WAVE INCORPORATED + // http://www.denso-wave.com/qrcode/faqpatent-e.html + // + //--------------------------------------------------------------------- + */ + + /** + * Add finder patterns bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {Number} version QR Code version + */ + function setupFinderPattern (matrix, version) { + var size = matrix.size; + var pos = FinderPattern.getPositions(version); + + for (var i = 0; i < pos.length; i++) { + var row = pos[i][0]; + var col = pos[i][1]; + + for (var r = -1; r <= 7; r++) { + if (row + r <= -1 || size <= row + r) continue + + for (var c = -1; c <= 7; c++) { + if (col + c <= -1 || size <= col + c) continue + + if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) || + (c >= 0 && c <= 6 && (r === 0 || r === 6)) || + (r >= 2 && r <= 4 && c >= 2 && c <= 4)) { + matrix.set(row + r, col + c, true, true); + } else { + matrix.set(row + r, col + c, false, true); + } + } + } + } + } + + /** + * Add timing pattern bits to matrix + * + * Note: this function must be called before {@link setupAlignmentPattern} + * + * @param {BitMatrix} matrix Modules matrix + */ + function setupTimingPattern (matrix) { + var size = matrix.size; + + for (var r = 8; r < size - 8; r++) { + var value = r % 2 === 0; + matrix.set(r, 6, value, true); + matrix.set(6, r, value, true); + } + } + + /** + * Add alignment patterns bits to matrix + * + * Note: this function must be called after {@link setupTimingPattern} + * + * @param {BitMatrix} matrix Modules matrix + * @param {Number} version QR Code version + */ + function setupAlignmentPattern (matrix, version) { + var pos = AlignmentPattern.getPositions(version); + + for (var i = 0; i < pos.length; i++) { + var row = pos[i][0]; + var col = pos[i][1]; + + for (var r = -2; r <= 2; r++) { + for (var c = -2; c <= 2; c++) { + if (r === -2 || r === 2 || c === -2 || c === 2 || + (r === 0 && c === 0)) { + matrix.set(row + r, col + c, true, true); + } else { + matrix.set(row + r, col + c, false, true); + } + } + } + } + } + + /** + * Add version info bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {Number} version QR Code version + */ + function setupVersionInfo (matrix, version) { + var size = matrix.size; + var bits = Version.getEncodedBits(version); + var row, col, mod; + + for (var i = 0; i < 18; i++) { + row = Math.floor(i / 3); + col = i % 3 + size - 8 - 3; + mod = ((bits >> i) & 1) === 1; + + matrix.set(row, col, mod, true); + matrix.set(col, row, mod, true); + } + } + + /** + * Add format info bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level + * @param {Number} maskPattern Mask pattern reference value + */ + function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) { + var size = matrix.size; + var bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern); + var i, mod; + + for (i = 0; i < 15; i++) { + mod = ((bits >> i) & 1) === 1; + + // vertical + if (i < 6) { + matrix.set(i, 8, mod, true); + } else if (i < 8) { + matrix.set(i + 1, 8, mod, true); + } else { + matrix.set(size - 15 + i, 8, mod, true); + } + + // horizontal + if (i < 8) { + matrix.set(8, size - i - 1, mod, true); + } else if (i < 9) { + matrix.set(8, 15 - i - 1 + 1, mod, true); + } else { + matrix.set(8, 15 - i - 1, mod, true); + } + } + + // fixed module + matrix.set(size - 8, 8, 1, true); + } + + /** + * Add encoded data bits to matrix + * + * @param {BitMatrix} matrix Modules matrix + * @param {Buffer} data Data codewords + */ + function setupData (matrix, data) { + var size = matrix.size; + var inc = -1; + var row = size - 1; + var bitIndex = 7; + var byteIndex = 0; + + for (var col = size - 1; col > 0; col -= 2) { + if (col === 6) col--; + + while (true) { + for (var c = 0; c < 2; c++) { + if (!matrix.isReserved(row, col - c)) { + var dark = false; + + if (byteIndex < data.length) { + dark = (((data[byteIndex] >>> bitIndex) & 1) === 1); + } + + matrix.set(row, col - c, dark); + bitIndex--; + + if (bitIndex === -1) { + byteIndex++; + bitIndex = 7; + } + } + } + + row += inc; + + if (row < 0 || size <= row) { + row -= inc; + inc = -inc; + break + } + } + } + } + + /** + * Create encoded codewords from data input + * + * @param {Number} version QR Code version + * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level + * @param {ByteData} data Data input + * @return {Buffer} Buffer containing encoded codewords + */ + function createData (version, errorCorrectionLevel, segments) { + // Prepare data buffer + var buffer = new BitBuffer(); + + segments.forEach(function (data) { + // prefix data with mode indicator (4 bits) + buffer.put(data.mode.bit, 4); + + // Prefix data with character count indicator. + // The character count indicator is a string of bits that represents the + // number of characters that are being encoded. + // The character count indicator must be placed after the mode indicator + // and must be a certain number of bits long, depending on the QR version + // and data mode + // @see {@link Mode.getCharCountIndicator}. + buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version)); + + // add binary data sequence to buffer + data.write(buffer); + }); + + // Calculate required number of bits + var totalCodewords = Utils.getSymbolTotalCodewords(version); + var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel); + var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8; + + // Add a terminator. + // If the bit string is shorter than the total number of required bits, + // a terminator of up to four 0s must be added to the right side of the string. + // If the bit string is more than four bits shorter than the required number of bits, + // add four 0s to the end. + if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) { + buffer.put(0, 4); + } + + // If the bit string is fewer than four bits shorter, add only the number of 0s that + // are needed to reach the required number of bits. + + // After adding the terminator, if the number of bits in the string is not a multiple of 8, + // pad the string on the right with 0s to make the string's length a multiple of 8. + while (buffer.getLengthInBits() % 8 !== 0) { + buffer.putBit(0); + } + + // Add pad bytes if the string is still shorter than the total number of required bits. + // Extend the buffer to fill the data capacity of the symbol corresponding to + // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC) + // and 00010001 (0x11) alternately. + var remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8; + for (var i = 0; i < remainingByte; i++) { + buffer.put(i % 2 ? 0x11 : 0xEC, 8); + } + + return createCodewords(buffer, version, errorCorrectionLevel) + } + + /** + * Encode input data with Reed-Solomon and return codewords with + * relative error correction bits + * + * @param {BitBuffer} bitBuffer Data to encode + * @param {Number} version QR Code version + * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level + * @return {Buffer} Buffer containing encoded codewords + */ + function createCodewords (bitBuffer, version, errorCorrectionLevel) { + // Total codewords for this QR code version (Data + Error correction) + var totalCodewords = Utils.getSymbolTotalCodewords(version); + + // Total number of error correction codewords + var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel); + + // Total number of data codewords + var dataTotalCodewords = totalCodewords - ecTotalCodewords; + + // Total number of blocks + var ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel); + + // Calculate how many blocks each group should contain + var blocksInGroup2 = totalCodewords % ecTotalBlocks; + var blocksInGroup1 = ecTotalBlocks - blocksInGroup2; + + var totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks); + + var dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks); + var dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1; + + // Number of EC codewords is the same for both groups + var ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1; + + // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount + var rs = new ReedSolomonEncoder(ecCount); + + var offset = 0; + var dcData = new Array(ecTotalBlocks); + var ecData = new Array(ecTotalBlocks); + var maxDataSize = 0; + var buffer = new Buffer(bitBuffer.buffer); + + // Divide the buffer into the required number of blocks + for (var b = 0; b < ecTotalBlocks; b++) { + var dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2; + + // extract a block of data from buffer + dcData[b] = buffer.slice(offset, offset + dataSize); + + // Calculate EC codewords for this data block + ecData[b] = rs.encode(dcData[b]); + + offset += dataSize; + maxDataSize = Math.max(maxDataSize, dataSize); + } + + // Create final data + // Interleave the data and error correction codewords from each block + var data = new Buffer(totalCodewords); + var index = 0; + var i, r; + + // Add data codewords + for (i = 0; i < maxDataSize; i++) { + for (r = 0; r < ecTotalBlocks; r++) { + if (i < dcData[r].length) { + data[index++] = dcData[r][i]; + } + } + } + + // Apped EC codewords + for (i = 0; i < ecCount; i++) { + for (r = 0; r < ecTotalBlocks; r++) { + data[index++] = ecData[r][i]; + } + } + + return data + } + + /** + * Build QR Code symbol + * + * @param {String} data Input string + * @param {Number} version QR Code version + * @param {ErrorCorretionLevel} errorCorrectionLevel Error level + * @param {MaskPattern} maskPattern Mask pattern + * @return {Object} Object containing symbol data + */ + function createSymbol (data, version, errorCorrectionLevel, maskPattern) { + var segments; + + if (isArray(data)) { + segments = Segments.fromArray(data); + } else if (typeof data === 'string') { + var estimatedVersion = version; + + if (!estimatedVersion) { + var rawSegments = Segments.rawSplit(data); + + // Estimate best version that can contain raw splitted segments + estimatedVersion = Version.getBestVersionForData(rawSegments, + errorCorrectionLevel); + } + + // Build optimized segments + // If estimated version is undefined, try with the highest version + segments = Segments.fromString(data, estimatedVersion || 40); + } else { + throw new Error('Invalid data') + } + + // Get the min version that can contain data + var bestVersion = Version.getBestVersionForData(segments, + errorCorrectionLevel); + + // If no version is found, data cannot be stored + if (!bestVersion) { + throw new Error('The amount of data is too big to be stored in a QR Code') + } + + // If not specified, use min version as default + if (!version) { + version = bestVersion; + + // Check if the specified version can contain the data + } else if (version < bestVersion) { + throw new Error('\n' + + 'The chosen QR Code version cannot contain this amount of data.\n' + + 'Minimum version required to store current data is: ' + bestVersion + '.\n' + ) + } + + var dataBits = createData(version, errorCorrectionLevel, segments); + + // Allocate matrix buffer + var moduleCount = Utils.getSymbolSize(version); + var modules = new BitMatrix(moduleCount); + + // Add function modules + setupFinderPattern(modules, version); + setupTimingPattern(modules); + setupAlignmentPattern(modules, version); + + // Add temporary dummy bits for format info just to set them as reserved. + // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask} + // since the masking operation must be performed only on the encoding region. + // These blocks will be replaced with correct values later in code. + setupFormatInfo(modules, errorCorrectionLevel, 0); + + if (version >= 7) { + setupVersionInfo(modules, version); + } + + // Add data codewords + setupData(modules, dataBits); + + if (isNaN(maskPattern)) { + // Find best mask pattern + maskPattern = MaskPattern.getBestMask(modules, + setupFormatInfo.bind(null, modules, errorCorrectionLevel)); + } + + // Apply mask pattern + MaskPattern.applyMask(maskPattern, modules); + + // Replace format info bits with correct values + setupFormatInfo(modules, errorCorrectionLevel, maskPattern); + + return { + modules: modules, + version: version, + errorCorrectionLevel: errorCorrectionLevel, + maskPattern: maskPattern, + segments: segments + } + } + + /** + * QR Code + * + * @param {String | Array} data Input data + * @param {Object} options Optional configurations + * @param {Number} options.version QR Code version + * @param {String} options.errorCorrectionLevel Error correction level + * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis + */ + exports.create = function create (data, options) { + if (typeof data === 'undefined' || data === '') { + throw new Error('No input text') + } + + var errorCorrectionLevel = ECLevel.M; + var version; + var mask; + + if (typeof options !== 'undefined') { + // Use higher error correction level as default + errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M); + version = Version.from(options.version); + mask = MaskPattern.from(options.maskPattern); + + if (options.toSJISFunc) { + Utils.setToSJISFunction(options.toSJISFunc); + } + } + + return createSymbol(data, version, errorCorrectionLevel, mask) + }; + + },{"../utils/buffer":27,"./alignment-pattern":1,"./bit-buffer":3,"./bit-matrix":4,"./error-correction-code":6,"./error-correction-level":7,"./finder-pattern":8,"./format-info":9,"./mask-pattern":12,"./mode":13,"./reed-solomon-encoder":17,"./segments":19,"./utils":20,"./version":22,"isarray":30}],17:[function(require,module,exports){ + var Buffer = require('../utils/buffer'); + var Polynomial = require('./polynomial'); + + function ReedSolomonEncoder (degree) { + this.genPoly = undefined; + this.degree = degree; + + if (this.degree) this.initialize(this.degree); + } + + /** + * Initialize the encoder. + * The input param should correspond to the number of error correction codewords. + * + * @param {Number} degree + */ + ReedSolomonEncoder.prototype.initialize = function initialize (degree) { + // create an irreducible generator polynomial + this.degree = degree; + this.genPoly = Polynomial.generateECPolynomial(this.degree); + }; + + /** + * Encodes a chunk of data + * + * @param {Buffer} data Buffer containing input data + * @return {Buffer} Buffer containing encoded data + */ + ReedSolomonEncoder.prototype.encode = function encode (data) { + if (!this.genPoly) { + throw new Error('Encoder not initialized') + } + + // Calculate EC for this data block + // extends data size to data+genPoly size + var pad = new Buffer(this.degree); + pad.fill(0); + var paddedData = Buffer.concat([data, pad], data.length + this.degree); + + // The error correction codewords are the remainder after dividing the data codewords + // by a generator polynomial + var remainder = Polynomial.mod(paddedData, this.genPoly); + + // return EC data blocks (last n byte, where n is the degree of genPoly) + // If coefficients number in remainder are less than genPoly degree, + // pad with 0s to the left to reach the needed number of coefficients + var start = this.degree - remainder.length; + if (start > 0) { + var buff = new Buffer(this.degree); + buff.fill(0); + remainder.copy(buff, start); + + return buff + } + + return remainder + }; + + module.exports = ReedSolomonEncoder; + + },{"../utils/buffer":27,"./polynomial":15}],18:[function(require,module,exports){ + var numeric = '[0-9]+'; + var alphanumeric = '[A-Z $%*+\\-./:]+'; + var kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' + + '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' + + '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' + + '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+'; + kanji = kanji.replace(/u/g, '\\u'); + + var byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+'; + + exports.KANJI = new RegExp(kanji, 'g'); + exports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g'); + exports.BYTE = new RegExp(byte, 'g'); + exports.NUMERIC = new RegExp(numeric, 'g'); + exports.ALPHANUMERIC = new RegExp(alphanumeric, 'g'); + + var TEST_KANJI = new RegExp('^' + kanji + '$'); + var TEST_NUMERIC = new RegExp('^' + numeric + '$'); + var TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$'); + + exports.testKanji = function testKanji (str) { + return TEST_KANJI.test(str) + }; + + exports.testNumeric = function testNumeric (str) { + return TEST_NUMERIC.test(str) + }; + + exports.testAlphanumeric = function testAlphanumeric (str) { + return TEST_ALPHANUMERIC.test(str) + }; + + },{}],19:[function(require,module,exports){ + var Mode = require('./mode'); + var NumericData = require('./numeric-data'); + var AlphanumericData = require('./alphanumeric-data'); + var ByteData = require('./byte-data'); + var KanjiData = require('./kanji-data'); + var Regex = require('./regex'); + var Utils = require('./utils'); + var dijkstra = require('dijkstrajs'); + + /** + * Returns UTF8 byte length + * + * @param {String} str Input string + * @return {Number} Number of byte + */ + function getStringByteLength (str) { + return unescape(encodeURIComponent(str)).length + } + + /** + * Get a list of segments of the specified mode + * from a string + * + * @param {Mode} mode Segment mode + * @param {String} str String to process + * @return {Array} Array of object with segments data + */ + function getSegments (regex, mode, str) { + var segments = []; + var result; + + while ((result = regex.exec(str)) !== null) { + segments.push({ + data: result[0], + index: result.index, + mode: mode, + length: result[0].length + }); + } + + return segments + } + + /** + * Extracts a series of segments with the appropriate + * modes from a string + * + * @param {String} dataStr Input string + * @return {Array} Array of object with segments data + */ + function getSegmentsFromString (dataStr) { + var numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr); + var alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr); + var byteSegs; + var kanjiSegs; + + if (Utils.isKanjiModeEnabled()) { + byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr); + kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr); + } else { + byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr); + kanjiSegs = []; + } + + var segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs); + + return segs + .sort(function (s1, s2) { + return s1.index - s2.index + }) + .map(function (obj) { + return { + data: obj.data, + mode: obj.mode, + length: obj.length + } + }) + } + + /** + * Returns how many bits are needed to encode a string of + * specified length with the specified mode + * + * @param {Number} length String length + * @param {Mode} mode Segment mode + * @return {Number} Bit length + */ + function getSegmentBitsLength (length, mode) { + switch (mode) { + case Mode.NUMERIC: + return NumericData.getBitsLength(length) + case Mode.ALPHANUMERIC: + return AlphanumericData.getBitsLength(length) + case Mode.KANJI: + return KanjiData.getBitsLength(length) + case Mode.BYTE: + return ByteData.getBitsLength(length) + } + } + + /** + * Merges adjacent segments which have the same mode + * + * @param {Array} segs Array of object with segments data + * @return {Array} Array of object with segments data + */ + function mergeSegments (segs) { + return segs.reduce(function (acc, curr) { + var prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null; + if (prevSeg && prevSeg.mode === curr.mode) { + acc[acc.length - 1].data += curr.data; + return acc + } + + acc.push(curr); + return acc + }, []) + } + + /** + * Generates a list of all possible nodes combination which + * will be used to build a segments graph. + * + * Nodes are divided by groups. Each group will contain a list of all the modes + * in which is possible to encode the given text. + * + * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte. + * The group for '12345' will contain then 3 objects, one for each + * possible encoding mode. + * + * Each node represents a possible segment. + * + * @param {Array} segs Array of object with segments data + * @return {Array} Array of object with segments data + */ + function buildNodes (segs) { + var nodes = []; + for (var i = 0; i < segs.length; i++) { + var seg = segs[i]; + + switch (seg.mode) { + case Mode.NUMERIC: + nodes.push([seg, + { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length }, + { data: seg.data, mode: Mode.BYTE, length: seg.length } + ]); + break + case Mode.ALPHANUMERIC: + nodes.push([seg, + { data: seg.data, mode: Mode.BYTE, length: seg.length } + ]); + break + case Mode.KANJI: + nodes.push([seg, + { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) } + ]); + break + case Mode.BYTE: + nodes.push([ + { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) } + ]); + } + } + + return nodes + } + + /** + * Builds a graph from a list of nodes. + * All segments in each node group will be connected with all the segments of + * the next group and so on. + * + * At each connection will be assigned a weight depending on the + * segment's byte length. + * + * @param {Array} nodes Array of object with segments data + * @param {Number} version QR Code version + * @return {Object} Graph of all possible segments + */ + function buildGraph (nodes, version) { + var table = {}; + var graph = {'start': {}}; + var prevNodeIds = ['start']; + + for (var i = 0; i < nodes.length; i++) { + var nodeGroup = nodes[i]; + var currentNodeIds = []; + + for (var j = 0; j < nodeGroup.length; j++) { + var node = nodeGroup[j]; + var key = '' + i + j; + + currentNodeIds.push(key); + table[key] = { node: node, lastCount: 0 }; + graph[key] = {}; + + for (var n = 0; n < prevNodeIds.length; n++) { + var prevNodeId = prevNodeIds[n]; + + if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) { + graph[prevNodeId][key] = + getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - + getSegmentBitsLength(table[prevNodeId].lastCount, node.mode); + + table[prevNodeId].lastCount += node.length; + } else { + if (table[prevNodeId]) table[prevNodeId].lastCount = node.length; + + graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + + 4 + Mode.getCharCountIndicator(node.mode, version); // switch cost + } + } + } + + prevNodeIds = currentNodeIds; + } + + for (n = 0; n < prevNodeIds.length; n++) { + graph[prevNodeIds[n]]['end'] = 0; + } + + return { map: graph, table: table } + } + + /** + * Builds a segment from a specified data and mode. + * If a mode is not specified, the more suitable will be used. + * + * @param {String} data Input data + * @param {Mode | String} modesHint Data mode + * @return {Segment} Segment + */ + function buildSingleSegment (data, modesHint) { + var mode; + var bestMode = Mode.getBestModeForData(data); + + mode = Mode.from(modesHint, bestMode); + + // Make sure data can be encoded + if (mode !== Mode.BYTE && mode.bit < bestMode.bit) { + throw new Error('"' + data + '"' + + ' cannot be encoded with mode ' + Mode.toString(mode) + + '.\n Suggested mode is: ' + Mode.toString(bestMode)) + } + + // Use Mode.BYTE if Kanji support is disabled + if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) { + mode = Mode.BYTE; + } + + switch (mode) { + case Mode.NUMERIC: + return new NumericData(data) + + case Mode.ALPHANUMERIC: + return new AlphanumericData(data) + + case Mode.KANJI: + return new KanjiData(data) + + case Mode.BYTE: + return new ByteData(data) + } + } + + /** + * Builds a list of segments from an array. + * Array can contain Strings or Objects with segment's info. + * + * For each item which is a string, will be generated a segment with the given + * string and the more appropriate encoding mode. + * + * For each item which is an object, will be generated a segment with the given + * data and mode. + * Objects must contain at least the property "data". + * If property "mode" is not present, the more suitable mode will be used. + * + * @param {Array} array Array of objects with segments data + * @return {Array} Array of Segments + */ + exports.fromArray = function fromArray (array) { + return array.reduce(function (acc, seg) { + if (typeof seg === 'string') { + acc.push(buildSingleSegment(seg, null)); + } else if (seg.data) { + acc.push(buildSingleSegment(seg.data, seg.mode)); + } + + return acc + }, []) + }; + + /** + * Builds an optimized sequence of segments from a string, + * which will produce the shortest possible bitstream. + * + * @param {String} data Input string + * @param {Number} version QR Code version + * @return {Array} Array of segments + */ + exports.fromString = function fromString (data, version) { + var segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled()); + + var nodes = buildNodes(segs); + var graph = buildGraph(nodes, version); + var path = dijkstra.find_path(graph.map, 'start', 'end'); + + var optimizedSegs = []; + for (var i = 1; i < path.length - 1; i++) { + optimizedSegs.push(graph.table[path[i]].node); + } + + return exports.fromArray(mergeSegments(optimizedSegs)) + }; + + /** + * Splits a string in various segments with the modes which + * best represent their content. + * The produced segments are far from being optimized. + * The output of this function is only used to estimate a QR Code version + * which may contain the data. + * + * @param {string} data Input string + * @return {Array} Array of segments + */ + exports.rawSplit = function rawSplit (data) { + return exports.fromArray( + getSegmentsFromString(data, Utils.isKanjiModeEnabled()) + ) + }; + + },{"./alphanumeric-data":2,"./byte-data":5,"./kanji-data":11,"./mode":13,"./numeric-data":14,"./regex":18,"./utils":20,"dijkstrajs":29}],20:[function(require,module,exports){ + var toSJISFunction; + var CODEWORDS_COUNT = [ + 0, // Not used + 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 + ]; + + /** + * Returns the QR Code size for the specified version + * + * @param {Number} version QR Code version + * @return {Number} size of QR code + */ + exports.getSymbolSize = function getSymbolSize (version) { + if (!version) throw new Error('"version" cannot be null or undefined') + if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40') + return version * 4 + 17 + }; + + /** + * Returns the total number of codewords used to store data and EC information. + * + * @param {Number} version QR Code version + * @return {Number} Data length in bits + */ + exports.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) { + return CODEWORDS_COUNT[version] + }; + + /** + * Encode data with Bose-Chaudhuri-Hocquenghem + * + * @param {Number} data Value to encode + * @return {Number} Encoded value + */ + exports.getBCHDigit = function (data) { + var digit = 0; + + while (data !== 0) { + digit++; + data >>>= 1; + } + + return digit + }; + + exports.setToSJISFunction = function setToSJISFunction (f) { + if (typeof f !== 'function') { + throw new Error('"toSJISFunc" is not a valid function.') + } + + toSJISFunction = f; + }; + + exports.isKanjiModeEnabled = function () { + return typeof toSJISFunction !== 'undefined' + }; + + exports.toSJIS = function toSJIS (kanji) { + return toSJISFunction(kanji) + }; + + },{}],21:[function(require,module,exports){ + /** + * Check if QR Code version is valid + * + * @param {Number} version QR Code version + * @return {Boolean} true if valid version, false otherwise + */ + exports.isValid = function isValid (version) { + return !isNaN(version) && version >= 1 && version <= 40 + }; + + },{}],22:[function(require,module,exports){ + var Utils = require('./utils'); + var ECCode = require('./error-correction-code'); + var ECLevel = require('./error-correction-level'); + var Mode = require('./mode'); + var VersionCheck = require('./version-check'); + var isArray = require('isarray'); + + // Generator polynomial used to encode version information + var G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0); + var G18_BCH = Utils.getBCHDigit(G18); + + function getBestVersionForDataLength (mode, length, errorCorrectionLevel) { + for (var currentVersion = 1; currentVersion <= 40; currentVersion++) { + if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) { + return currentVersion + } + } + + return undefined + } + + function getReservedBitsCount (mode, version) { + // Character count indicator + mode indicator bits + return Mode.getCharCountIndicator(mode, version) + 4 + } + + function getTotalBitsFromDataArray (segments, version) { + var totalBits = 0; + + segments.forEach(function (data) { + var reservedBits = getReservedBitsCount(data.mode, version); + totalBits += reservedBits + data.getBitsLength(); + }); + + return totalBits + } + + function getBestVersionForMixedData (segments, errorCorrectionLevel) { + for (var currentVersion = 1; currentVersion <= 40; currentVersion++) { + var length = getTotalBitsFromDataArray(segments, currentVersion); + if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) { + return currentVersion + } + } + + return undefined + } + + /** + * Returns version number from a value. + * If value is not a valid version, returns defaultValue + * + * @param {Number|String} value QR Code version + * @param {Number} defaultValue Fallback value + * @return {Number} QR Code version number + */ + exports.from = function from (value, defaultValue) { + if (VersionCheck.isValid(value)) { + return parseInt(value, 10) + } + + return defaultValue + }; + + /** + * Returns how much data can be stored with the specified QR code version + * and error correction level + * + * @param {Number} version QR Code version (1-40) + * @param {Number} errorCorrectionLevel Error correction level + * @param {Mode} mode Data mode + * @return {Number} Quantity of storable data + */ + exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) { + if (!VersionCheck.isValid(version)) { + throw new Error('Invalid QR Code version') + } + + // Use Byte mode as default + if (typeof mode === 'undefined') mode = Mode.BYTE; + + // Total codewords for this QR code version (Data + Error correction) + var totalCodewords = Utils.getSymbolTotalCodewords(version); + + // Total number of error correction codewords + var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel); + + // Total number of data codewords + var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8; + + if (mode === Mode.MIXED) return dataTotalCodewordsBits + + var usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version); + + // Return max number of storable codewords + switch (mode) { + case Mode.NUMERIC: + return Math.floor((usableBits / 10) * 3) + + case Mode.ALPHANUMERIC: + return Math.floor((usableBits / 11) * 2) + + case Mode.KANJI: + return Math.floor(usableBits / 13) + + case Mode.BYTE: + default: + return Math.floor(usableBits / 8) + } + }; + + /** + * Returns the minimum version needed to contain the amount of data + * + * @param {Segment} data Segment of data + * @param {Number} [errorCorrectionLevel=H] Error correction level + * @param {Mode} mode Data mode + * @return {Number} QR Code version + */ + exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) { + var seg; + + var ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M); + + if (isArray(data)) { + if (data.length > 1) { + return getBestVersionForMixedData(data, ecl) + } + + if (data.length === 0) { + return 1 + } + + seg = data[0]; + } else { + seg = data; + } + + return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl) + }; + + /** + * Returns version information with relative error correction bits + * + * The version information is included in QR Code symbols of version 7 or larger. + * It consists of an 18-bit sequence containing 6 data bits, + * with 12 error correction bits calculated using the (18, 6) Golay code. + * + * @param {Number} version QR Code version + * @return {Number} Encoded version info bits + */ + exports.getEncodedBits = function getEncodedBits (version) { + if (!VersionCheck.isValid(version) || version < 7) { + throw new Error('Invalid QR Code version') + } + + var d = version << 12; + + while (Utils.getBCHDigit(d) - G18_BCH >= 0) { + d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH)); + } + + return (version << 12) | d + }; + + },{"./error-correction-code":6,"./error-correction-level":7,"./mode":13,"./utils":20,"./version-check":21,"isarray":30}],23:[function(require,module,exports){ + var canPromise = require('can-promise'); + var QRCode = require('./core/qrcode'); + var CanvasRenderer = require('./renderer/canvas'); + var SvgRenderer = require('./renderer/svg-tag.js'); + + function renderCanvas (renderFunc, canvas, text, opts, cb) { + var args = [].slice.call(arguments, 1); + var argsNum = args.length; + var isLastArgCb = typeof args[argsNum - 1] === 'function'; + + if (!isLastArgCb && !canPromise()) { + throw new Error('Callback required as last argument') + } + + if (isLastArgCb) { + if (argsNum < 2) { + throw new Error('Too few arguments provided') + } + + if (argsNum === 2) { + cb = text; + text = canvas; + canvas = opts = undefined; + } else if (argsNum === 3) { + if (canvas.getContext && typeof cb === 'undefined') { + cb = opts; + opts = undefined; + } else { + cb = opts; + opts = text; + text = canvas; + canvas = undefined; + } + } + } else { + if (argsNum < 1) { + throw new Error('Too few arguments provided') + } + + if (argsNum === 1) { + text = canvas; + canvas = opts = undefined; + } else if (argsNum === 2 && !canvas.getContext) { + opts = text; + text = canvas; + canvas = undefined; + } + + return new Promise(function (resolve, reject) { + try { + var data = QRCode.create(text, opts); + resolve(renderFunc(data, canvas, opts)); + } catch (e) { + reject(e); + } + }) + } + + try { + var data = QRCode.create(text, opts); + cb(null, renderFunc(data, canvas, opts)); + } catch (e) { + cb(e); + } + } + + exports.create = QRCode.create; + exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render); + exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL); + + // only svg for now. + exports.toString = renderCanvas.bind(null, function (data, _, opts) { + return SvgRenderer.render(data, opts) + }); + + },{"./core/qrcode":16,"./renderer/canvas":24,"./renderer/svg-tag.js":25,"can-promise":28}],24:[function(require,module,exports){ + var Utils = require('./utils'); + + function clearCanvas (ctx, canvas, size) { + ctx.clearRect(0, 0, canvas.width, canvas.height); + + if (!canvas.style) canvas.style = {}; + canvas.height = size; + canvas.width = size; + canvas.style.height = size + 'px'; + canvas.style.width = size + 'px'; + } + + function getCanvasElement () { + try { + return document.createElement('canvas') + } catch (e) { + throw new Error('You need to specify a canvas element') + } + } + + exports.render = function render (qrData, canvas, options) { + var opts = options; + var canvasEl = canvas; + + if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) { + opts = canvas; + canvas = undefined; + } + + if (!canvas) { + canvasEl = getCanvasElement(); + } + + opts = Utils.getOptions(opts); + var size = Utils.getImageWidth(qrData.modules.size, opts); + + var ctx = canvasEl.getContext('2d'); + var image = ctx.createImageData(size, size); + Utils.qrToImageData(image.data, qrData, opts); + + clearCanvas(ctx, canvasEl, size); + ctx.putImageData(image, 0, 0); + + return canvasEl + }; + + exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) { + var opts = options; + + if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) { + opts = canvas; + canvas = undefined; + } + + if (!opts) opts = {}; + + var canvasEl = exports.render(qrData, canvas, opts); + + var type = opts.type || 'image/png'; + var rendererOpts = opts.rendererOpts || {}; + + return canvasEl.toDataURL(type, rendererOpts.quality) + }; + + },{"./utils":26}],25:[function(require,module,exports){ + var Utils = require('./utils'); + + function getColorAttrib (color, attrib) { + var alpha = color.a / 255; + var str = attrib + '="' + color.hex + '"'; + + return alpha < 1 + ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' + : str + } + + function svgCmd (cmd, x, y) { + var str = cmd + x; + if (typeof y !== 'undefined') str += ' ' + y; + + return str + } + + function qrToPath (data, size, margin) { + var path = ''; + var moveBy = 0; + var newRow = false; + var lineLength = 0; + + for (var i = 0; i < data.length; i++) { + var col = Math.floor(i % size); + var row = Math.floor(i / size); + + if (!col && !newRow) newRow = true; + + if (data[i]) { + lineLength++; + + if (!(i > 0 && col > 0 && data[i - 1])) { + path += newRow + ? svgCmd('M', col + margin, 0.5 + row + margin) + : svgCmd('m', moveBy, 0); + + moveBy = 0; + newRow = false; + } + + if (!(col + 1 < size && data[i + 1])) { + path += svgCmd('h', lineLength); + lineLength = 0; + } + } else { + moveBy++; + } + } + + return path + } + + exports.render = function render (qrData, options, cb) { + var opts = Utils.getOptions(options); + var size = qrData.modules.size; + var data = qrData.modules.data; + var qrcodesize = size + opts.margin * 2; + + var bg = !opts.color.light.a + ? '' + : ''; + + var path = + ''; + + var viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"'; + + var width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" '; + + var svgTag = '' + bg + path + '\n'; + + if (typeof cb === 'function') { + cb(null, svgTag); + } + + return svgTag + }; + + },{"./utils":26}],26:[function(require,module,exports){ + function hex2rgba (hex) { + if (typeof hex !== 'string') { + throw new Error('Color should be defined as hex string') + } + + var hexCode = hex.slice().replace('#', '').split(''); + if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) { + throw new Error('Invalid hex color: ' + hex) + } + + // Convert from short to long form (fff -> ffffff) + if (hexCode.length === 3 || hexCode.length === 4) { + hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) { + return [c, c] + })); + } + + // Add default alpha value + if (hexCode.length === 6) hexCode.push('F', 'F'); + + var hexValue = parseInt(hexCode.join(''), 16); + + return { + r: (hexValue >> 24) & 255, + g: (hexValue >> 16) & 255, + b: (hexValue >> 8) & 255, + a: hexValue & 255, + hex: '#' + hexCode.slice(0, 6).join('') + } + } + + exports.getOptions = function getOptions (options) { + if (!options) options = {}; + if (!options.color) options.color = {}; + + var margin = typeof options.margin === 'undefined' || + options.margin === null || + options.margin < 0 ? 4 : options.margin; + + var width = options.width && options.width >= 21 ? options.width : undefined; + var scale = options.scale || 4; + + return { + width: width, + scale: width ? 4 : scale, + margin: margin, + color: { + dark: hex2rgba(options.color.dark || '#000000ff'), + light: hex2rgba(options.color.light || '#ffffffff') + }, + type: options.type, + rendererOpts: options.rendererOpts || {} + } + }; + + exports.getScale = function getScale (qrSize, opts) { + return opts.width && opts.width >= qrSize + opts.margin * 2 + ? opts.width / (qrSize + opts.margin * 2) + : opts.scale + }; + + exports.getImageWidth = function getImageWidth (qrSize, opts) { + var scale = exports.getScale(qrSize, opts); + return Math.floor((qrSize + opts.margin * 2) * scale) + }; + + exports.qrToImageData = function qrToImageData (imgData, qr, opts) { + var size = qr.modules.size; + var data = qr.modules.data; + var scale = exports.getScale(size, opts); + var symbolSize = Math.floor((size + opts.margin * 2) * scale); + var scaledMargin = opts.margin * scale; + var palette = [opts.color.light, opts.color.dark]; + + for (var i = 0; i < symbolSize; i++) { + for (var j = 0; j < symbolSize; j++) { + var posDst = (i * symbolSize + j) * 4; + var pxColor = opts.color.light; + + if (i >= scaledMargin && j >= scaledMargin && + i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) { + var iSrc = Math.floor((i - scaledMargin) / scale); + var jSrc = Math.floor((j - scaledMargin) / scale); + pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0]; + } + + imgData[posDst++] = pxColor.r; + imgData[posDst++] = pxColor.g; + imgData[posDst++] = pxColor.b; + imgData[posDst] = pxColor.a; + } + } + }; + + },{}],27:[function(require,module,exports){ + + var isArray = require('isarray'); + + function typedArraySupport () { + // Can typed array instances be augmented? + try { + var arr = new Uint8Array(1); + arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}; + return arr.foo() === 42 + } catch (e) { + return false + } + } + + Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); + + var K_MAX_LENGTH = Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff; + + function Buffer (arg, offset, length) { + if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { + return new Buffer(arg, offset, length) + } + + if (typeof arg === 'number') { + return allocUnsafe(this, arg) + } + + return from(this, arg, offset, length) + } + + if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype; + Buffer.__proto__ = Uint8Array; + + // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 + if (typeof Symbol !== 'undefined' && Symbol.species && + Buffer[Symbol.species] === Buffer) { + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true, + enumerable: false, + writable: false + }); + } + } + + function checked (length) { + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= K_MAX_LENGTH) { + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') + } + return length | 0 + } + + function isnan (val) { + return val !== val // eslint-disable-line no-self-compare + } + + function createBuffer (that, length) { + var buf; + if (Buffer.TYPED_ARRAY_SUPPORT) { + buf = new Uint8Array(length); + buf.__proto__ = Buffer.prototype; + } else { + // Fallback: Return an object instance of the Buffer class + buf = that; + if (buf === null) { + buf = new Buffer(length); + } + buf.length = length; + } + + return buf + } + + function allocUnsafe (that, size) { + var buf = createBuffer(that, size < 0 ? 0 : checked(size) | 0); + + if (!Buffer.TYPED_ARRAY_SUPPORT) { + for (var i = 0; i < size; ++i) { + buf[i] = 0; + } + } + + return buf + } + + function fromString (that, string) { + var length = byteLength(string) | 0; + var buf = createBuffer(that, length); + + var actual = buf.write(string); + + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + buf = buf.slice(0, actual); + } + + return buf + } + + function fromArrayLike (that, array) { + var length = array.length < 0 ? 0 : checked(array.length) | 0; + var buf = createBuffer(that, length); + for (var i = 0; i < length; i += 1) { + buf[i] = array[i] & 255; + } + return buf + } + + function fromArrayBuffer (that, array, byteOffset, length) { + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('\'offset\' is out of bounds') + } + + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('\'length\' is out of bounds') + } + + var buf; + if (byteOffset === undefined && length === undefined) { + buf = new Uint8Array(array); + } else if (length === undefined) { + buf = new Uint8Array(array, byteOffset); + } else { + buf = new Uint8Array(array, byteOffset, length); + } + + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + buf.__proto__ = Buffer.prototype; + } else { + // Fallback: Return an object instance of the Buffer class + buf = fromArrayLike(that, buf); + } + + return buf + } + + function fromObject (that, obj) { + if (Buffer.isBuffer(obj)) { + var len = checked(obj.length) | 0; + var buf = createBuffer(that, len); + + if (buf.length === 0) { + return buf + } + + obj.copy(buf, 0, 0, len); + return buf + } + + if (obj) { + if ((typeof ArrayBuffer !== 'undefined' && + obj.buffer instanceof ArrayBuffer) || 'length' in obj) { + if (typeof obj.length !== 'number' || isnan(obj.length)) { + return createBuffer(that, 0) + } + return fromArrayLike(that, obj) + } + + if (obj.type === 'Buffer' && Array.isArray(obj.data)) { + return fromArrayLike(that, obj.data) + } + } + + throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') + } + + function utf8ToBytes (string, units) { + units = units || Infinity; + var codePoint; + var length = string.length; + var leadSurrogate = null; + var bytes = []; + + for (var i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i); + + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + continue + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + continue + } + + // valid lead + leadSurrogate = codePoint; + + continue + } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + leadSurrogate = codePoint; + continue + } + + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000; + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + } + + leadSurrogate = null; + + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break + bytes.push(codePoint); + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break + bytes.push( + codePoint >> 0x6 | 0xC0, + codePoint & 0x3F | 0x80 + ); + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break + bytes.push( + codePoint >> 0xC | 0xE0, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ); + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break + bytes.push( + codePoint >> 0x12 | 0xF0, + codePoint >> 0xC & 0x3F | 0x80, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ); + } else { + throw new Error('Invalid code point') + } + } + + return bytes + } + + function byteLength (string) { + if (Buffer.isBuffer(string)) { + return string.length + } + if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && + (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { + return string.byteLength + } + if (typeof string !== 'string') { + string = '' + string; + } + + var len = string.length; + if (len === 0) return 0 + + return utf8ToBytes(string).length + } + + function blitBuffer (src, dst, offset, length) { + for (var i = 0; i < length; ++i) { + if ((i + offset >= dst.length) || (i >= src.length)) break + dst[i + offset] = src[i]; + } + return i + } + + function utf8Write (buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) + } + + function from (that, value, offset, length) { + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number') + } + + if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { + return fromArrayBuffer(that, value, offset, length) + } + + if (typeof value === 'string') { + return fromString(that, value, offset) + } + + return fromObject(that, value) + } + + Buffer.prototype.write = function write (string, offset, length) { + // Buffer#write(string) + if (offset === undefined) { + length = this.length; + offset = 0; + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + length = this.length; + offset = 0; + // Buffer#write(string, offset[, length]) + } else if (isFinite(offset)) { + offset = offset | 0; + if (isFinite(length)) { + length = length | 0; + } else { + length = undefined; + } + } + + var remaining = this.length - offset; + if (length === undefined || length > remaining) length = remaining; + + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { + throw new RangeError('Attempt to write outside buffer bounds') + } + + return utf8Write(this, string, offset, length) + }; + + Buffer.prototype.slice = function slice (start, end) { + var len = this.length; + start = ~~start; + end = end === undefined ? len : ~~end; + + if (start < 0) { + start += len; + if (start < 0) start = 0; + } else if (start > len) { + start = len; + } + + if (end < 0) { + end += len; + if (end < 0) end = 0; + } else if (end > len) { + end = len; + } + + if (end < start) end = start; + + var newBuf; + if (Buffer.TYPED_ARRAY_SUPPORT) { + newBuf = this.subarray(start, end); + // Return an augmented `Uint8Array` instance + newBuf.__proto__ = Buffer.prototype; + } else { + var sliceLen = end - start; + newBuf = new Buffer(sliceLen, undefined); + for (var i = 0; i < sliceLen; ++i) { + newBuf[i] = this[i + start]; + } + } + + return newBuf + }; + + Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!start) start = 0; + if (!end && end !== 0) end = this.length; + if (targetStart >= target.length) targetStart = target.length; + if (!targetStart) targetStart = 0; + if (end > 0 && end < start) end = start; + + // Copy 0 bytes; we're done + if (end === start) return 0 + if (target.length === 0 || this.length === 0) return 0 + + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError('targetStart out of bounds') + } + if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') + if (end < 0) throw new RangeError('sourceEnd out of bounds') + + // Are we oob? + if (end > this.length) end = this.length; + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start; + } + + var len = end - start; + var i; + + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; --i) { + target[i + targetStart] = this[i + start]; + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; ++i) { + target[i + targetStart] = this[i + start]; + } + } else { + Uint8Array.prototype.set.call( + target, + this.subarray(start, start + len), + targetStart + ); + } + + return len + }; + + Buffer.prototype.fill = function fill (val, start, end) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + start = 0; + end = this.length; + } else if (typeof end === 'string') { + end = this.length; + } + if (val.length === 1) { + var code = val.charCodeAt(0); + if (code < 256) { + val = code; + } + } + } else if (typeof val === 'number') { + val = val & 255; + } + + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError('Out of range index') + } + + if (end <= start) { + return this + } + + start = start >>> 0; + end = end === undefined ? this.length : end >>> 0; + + if (!val) val = 0; + + var i; + if (typeof val === 'number') { + for (i = start; i < end; ++i) { + this[i] = val; + } + } else { + var bytes = Buffer.isBuffer(val) + ? val + : new Buffer(val); + var len = bytes.length; + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len]; + } + } + + return this + }; + + Buffer.concat = function concat (list, length) { + if (!isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + + if (list.length === 0) { + return createBuffer(null, 0) + } + + var i; + if (length === undefined) { + length = 0; + for (i = 0; i < list.length; ++i) { + length += list[i].length; + } + } + + var buffer = allocUnsafe(null, length); + var pos = 0; + for (i = 0; i < list.length; ++i) { + var buf = list[i]; + if (!Buffer.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + buf.copy(buffer, pos); + pos += buf.length; + } + return buffer + }; + + Buffer.byteLength = byteLength; + + Buffer.prototype._isBuffer = true; + Buffer.isBuffer = function isBuffer (b) { + return !!(b != null && b._isBuffer) + }; + + module.exports = Buffer; + + },{"isarray":30}],28:[function(require,module,exports){ + + var G = require('window-or-global'); + + module.exports = function() { + return ( + typeof G.Promise === 'function' && + typeof G.Promise.prototype.then === 'function' + ) + }; + + },{"window-or-global":31}],29:[function(require,module,exports){ + + /****************************************************************************** + * Created 2008-08-19. + * + * Dijkstra path-finding functions. Adapted from the Dijkstar Python project. + * + * Copyright (C) 2008 + * Wyatt Baldwin + * All rights reserved + * + * Licensed under the MIT license. + * + * http://www.opensource.org/licenses/mit-license.php + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + *****************************************************************************/ + var dijkstra = { + single_source_shortest_paths: function(graph, s, d) { + // Predecessor map for each node that has been encountered. + // node ID => predecessor node ID + var predecessors = {}; + + // Costs of shortest paths from s to all nodes encountered. + // node ID => cost + var costs = {}; + costs[s] = 0; + + // Costs of shortest paths from s to all nodes encountered; differs from + // `costs` in that it provides easy access to the node that currently has + // the known shortest path from s. + // XXX: Do we actually need both `costs` and `open`? + var open = dijkstra.PriorityQueue.make(); + open.push(s, 0); + + var closest, + u, v, + cost_of_s_to_u, + adjacent_nodes, + cost_of_e, + cost_of_s_to_u_plus_cost_of_e, + cost_of_s_to_v, + first_visit; + while (!open.empty()) { + // In the nodes remaining in graph that have a known cost from s, + // find the node, u, that currently has the shortest path from s. + closest = open.pop(); + u = closest.value; + cost_of_s_to_u = closest.cost; + + // Get nodes adjacent to u... + adjacent_nodes = graph[u] || {}; + + // ...and explore the edges that connect u to those nodes, updating + // the cost of the shortest paths to any or all of those nodes as + // necessary. v is the node across the current edge from u. + for (v in adjacent_nodes) { + if (adjacent_nodes.hasOwnProperty(v)) { + // Get the cost of the edge running from u to v. + cost_of_e = adjacent_nodes[v]; + + // Cost of s to u plus the cost of u to v across e--this is *a* + // cost from s to v that may or may not be less than the current + // known cost to v. + cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e; + + // If we haven't visited v yet OR if the current known cost from s to + // v is greater than the new cost we just found (cost of s to u plus + // cost of u to v across e), update v's cost in the cost list and + // update v's predecessor in the predecessor list (it's now u). + cost_of_s_to_v = costs[v]; + first_visit = (typeof costs[v] === 'undefined'); + if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) { + costs[v] = cost_of_s_to_u_plus_cost_of_e; + open.push(v, cost_of_s_to_u_plus_cost_of_e); + predecessors[v] = u; + } + } + } + } + + if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') { + var msg = ['Could not find a path from ', s, ' to ', d, '.'].join(''); + throw new Error(msg); + } + + return predecessors; + }, + + extract_shortest_path_from_predecessor_list: function(predecessors, d) { + var nodes = []; + var u = d; + var predecessor; + while (u) { + nodes.push(u); + predecessor = predecessors[u]; + u = predecessors[u]; + } + nodes.reverse(); + return nodes; + }, + + find_path: function(graph, s, d) { + var predecessors = dijkstra.single_source_shortest_paths(graph, s, d); + return dijkstra.extract_shortest_path_from_predecessor_list( + predecessors, d); + }, + + /** + * A very naive priority queue implementation. + */ + PriorityQueue: { + make: function (opts) { + var T = dijkstra.PriorityQueue, + t = {}, + key; + opts = opts || {}; + for (key in T) { + if (T.hasOwnProperty(key)) { + t[key] = T[key]; + } + } + t.queue = []; + t.sorter = opts.sorter || T.default_sorter; + return t; + }, + + default_sorter: function (a, b) { + return a.cost - b.cost; + }, + + /** + * Add a new item to the queue and ensure the highest priority element + * is at the front of the queue. + */ + push: function (value, cost) { + var item = {value: value, cost: cost}; + this.queue.push(item); + this.queue.sort(this.sorter); + }, + + /** + * Return the highest priority element in the queue. + */ + pop: function () { + return this.queue.shift(); + }, + + empty: function () { + return this.queue.length === 0; + } + } + }; + + + // node.js module exports + if (typeof module !== 'undefined') { + module.exports = dijkstra; + } + + },{}],30:[function(require,module,exports){ + var toString = {}.toString; + + module.exports = Array.isArray || function (arr) { + return toString.call(arr) == '[object Array]'; + }; + + },{}],31:[function(require,module,exports){ + (function (global){ + module.exports = (typeof self === 'object' && self.self === self && self) || + (typeof global === 'object' && global.global === global && global) || + this; + + }).call(this,typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}); + + },{}]},{},[23])(23) + }); + + + }); + + var index = { + name: 'qrcode', + props: { + /** + * The options for the QR code generator. + * {@link https://github.com/soldair/node-qrcode#qr-code-options} + */ + options: Object, + + /** + * The tag name of the component's root element. + */ + tag: { + type: String, + default: 'canvas' + }, + + /** + * The value of the QR code. + */ + value: null + }, + render: function render(createElement) { + return createElement(this.tag, this.$slots.default); + }, + watch: { + $props: { + deep: true, + immediate: true, + handler: function handler() { + if (this.$el) { + this.generate(); + } + } + } + }, + methods: { + /** + * Generate QR code. + */ + generate: function generate() { + var _this = this; + + var options = this.options, + tag = this.tag; + var value = String(this.value); + + if (tag === 'canvas') { + qrcode.toCanvas(this.$el, value, options, function (error) { + if (error) { + throw error; + } + }); + } else if (tag === 'img') { + qrcode.toDataURL(value, options, function (error, url) { + if (error) { + throw error; + } + + _this.$el.src = url; + }); + } else { + qrcode.toString(value, options, function (error, string) { + if (error) { + throw error; + } + + _this.$el.innerHTML = string; + }); + } + } + }, + mounted: function mounted() { + this.generate(); + } + }; + + return index; + +}))); diff --git a/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.min.js b/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.min.js new file mode 100644 index 000000000..f2958a784 --- /dev/null +++ b/BTCPayServer/wwwroot/vendor/vue-qrcode/vue-qrcode.min.js @@ -0,0 +1,10 @@ +/*! + * vue-qrcode v1.0.0 + * https://fengyuanchen.github.io/vue-qrcode + * + * Copyright 2018-present Chen Fengyuan + * Released under the MIT license + * + * Date: 2018-10-21T13:04:02.951Z + */ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueQrcode=e()}(this,function(){"use strict";var n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function c(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}var t,o=(function(t,e){t.exports=function i(a,u,s){function f(r,t){if(!u[r]){if(!a[r]){var e=c;if(!t&&e)return e(r,!0);if(l)return l(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var o=u[r]={exports:{}};a[r][0].call(o.exports,function(t){var e=a[r][1][t];return f(e||t)},o,o.exports,i,a,u,s)}return u[r].exports}for(var l=c,t=0;t>>7-t%8&1)},put:function(t,e){for(var r=0;r>>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++}},e.exports=n},{}],4:[function(t,e,r){var n=t("../utils/buffer");function o(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new n(t*t),this.data.fill(0),this.reservedBit=new n(t*t),this.reservedBit.fill(0)}o.prototype.set=function(t,e,r,n){var o=t*this.size+e;this.data[o]=r,n&&(this.reservedBit[o]=!0)},o.prototype.get=function(t,e){return this.data[t*this.size+e]},o.prototype.xor=function(t,e,r){this.data[t*this.size+e]^=r},o.prototype.isReserved=function(t,e){return this.reservedBit[t*this.size+e]},e.exports=o},{"../utils/buffer":27}],5:[function(t,e,r){var n=t("../utils/buffer"),o=t("./mode");function i(t){this.mode=o.BYTE,this.data=new n(t)}i.getBitsLength=function(t){return 8*t},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(t){for(var e=0,r=this.data.length;e>>8&255)+(255&r),t.put(r,13)}},e.exports=i},{"./mode":13,"./utils":20}],12:[function(t,e,u){u.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var l={N1:3,N2:3,N3:40,N4:10};function i(t,e,r){switch(t){case u.Patterns.PATTERN000:return(e+r)%2==0;case u.Patterns.PATTERN001:return e%2==0;case u.Patterns.PATTERN010:return r%3==0;case u.Patterns.PATTERN011:return(e+r)%3==0;case u.Patterns.PATTERN100:return(Math.floor(e/2)+Math.floor(r/3))%2==0;case u.Patterns.PATTERN101:return e*r%2+e*r%3==0;case u.Patterns.PATTERN110:return(e*r%2+e*r%3)%2==0;case u.Patterns.PATTERN111:return(e*r%3+(e+r)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}}u.isValid=function(t){return null!=t&&""!==t&&!isNaN(t)&&0<=t&&t<=7},u.from=function(t){return u.isValid(t)?parseInt(t,10):void 0},u.getPenaltyN1=function(t){for(var e=t.size,r=0,n=0,o=0,i=null,a=null,u=0;u>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 y(e,t,r){var n=new f;r.forEach(function(t){n.put(t.mode.bit,4),n.put(t.getLength(),l.getCharCountIndicator(t.mode,e)),t.write(n)});var o=P.getSymbolTotalCodewords(e),i=T.getTotalCodewordsCount(e,t),a=8*(o-i);for(n.getLengthInBits()+4<=a&&n.put(0,4);n.getLengthInBits()%8!=0;)n.putBit(0);for(var u=(a-n.getLengthInBits())/8,s=0;s>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;0>>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,s),isNaN(n)&&(n=g.getBestMask(l,w.bind(null,l,r))),g.applyMask(n,l),w(l,r,n),{modules:l,version:e,errorCorrectionLevel:r,maskPattern:n,segments:o}}r.create=function(t,e){if(void 0===t||""===t)throw new Error("No input text");var r,n,o=i.M;return void 0!==e&&(o=i.from(e.errorCorrectionLevel,i.M),r=p.from(e.version),n=g.from(e.maskPattern),e.toSJISFunc&&P.setToSJISFunction(e.toSJISFunc)),a(t,r,o,n)}},{"../utils/buffer":27,"./alignment-pattern":1,"./bit-buffer":3,"./bit-matrix":4,"./error-correction-code":6,"./error-correction-level":7,"./finder-pattern":8,"./format-info":9,"./mask-pattern":12,"./mode":13,"./reed-solomon-encoder":17,"./segments":19,"./utils":20,"./version":22,isarray:30}],17:[function(t,e,r){var a=t("../utils/buffer"),u=t("./polynomial");function n(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}n.prototype.initialize=function(t){this.degree=t,this.genPoly=u.generateECPolynomial(this.degree)},n.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");var e=new a(this.degree);e.fill(0);var r=a.concat([t,e],t.length+this.degree),n=u.mod(r,this.genPoly),o=this.degree-n.length;if(0>>=1;return e},r.setToSJISFunction=function(t){if("function"!=typeof t)throw new Error('"toSJISFunc" is not a valid function.');n=t},r.isKanjiModeEnabled=function(){return void 0!==n},r.toSJIS=function(t){return n(t)}},{}],21:[function(t,e,r){r.isValid=function(t){return!isNaN(t)&&1<=t&&t<=40}},{}],22:[function(t,e,o){var u=t("./utils"),s=t("./error-correction-code"),i=t("./error-correction-level"),f=t("./mode"),l=t("./version-check"),a=t("isarray"),r=u.getBCHDigit(7973);function c(t,e){return f.getCharCountIndicator(t,e)+4}function h(t,r){var n=0;return t.forEach(function(t){var e=c(t.mode,r);n+=e+t.getBitsLength()}),n}o.from=function(t,e){return l.isValid(t)?parseInt(t,10):e},o.getCapacity=function(t,e,r){if(!l.isValid(t))throw new Error("Invalid QR Code version");void 0===r&&(r=f.BYTE);var n=u.getSymbolTotalCodewords(t),o=s.getTotalCodewordsCount(t,e),i=8*(n-o);if(r===f.MIXED)return i;var a=i-c(r,t);switch(r){case f.NUMERIC:return Math.floor(a/10*3);case f.ALPHANUMERIC:return Math.floor(a/11*2);case f.KANJI:return Math.floor(a/13);case f.BYTE:default:return Math.floor(a/8)}},o.getBestVersionForData=function(t,e){var r,n=i.from(e,i.M);if(a(t)){if(1':"",s="',f='viewBox="0 0 '+a+" "+a+'"',l=n.width?'width="'+n.width+'" height="'+n.width+'" ':"",c=''+u+s+"\n";return"function"==typeof r&&r(null,c),c}},{"./utils":26}],26:[function(t,e,p){function o(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||8>24&255,g:r>>16&255,b:r>>8&255,a:255&r,hex:"#"+e.slice(0,6).join("")}}p.getOptions=function(t){t||(t={}),t.color||(t.color={});var e=void 0===t.margin||null===t.margin||t.margin<0?4:t.margin,r=t.width&&21<=t.width?t.width:void 0,n=t.scale||4;return{width:r,scale:r?4:n,margin:e,color:{dark:o(t.color.dark||"#000000ff"),light:o(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}},p.getScale=function(t,e){return e.width&&e.width>=t+2*e.margin?e.width/(t+2*e.margin):e.scale},p.getImageWidth=function(t,e){var r=p.getScale(t,e);return Math.floor((t+2*e.margin)*r)},p.qrToImageData=function(t,e,r){for(var n=e.modules.size,o=e.modules.data,i=p.getScale(n,r),a=Math.floor((n+2*r.margin)*i),u=r.margin*i,s=[r.color.light,r.color.dark],f=0;f>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 d(t){if(f.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;return 0===e?0:s(t).length}function g(t,e,r,n){for(var o=0;o=e.length||o>=t.length);++o)e[o+r]=t[o];return o}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,o,i,a=this.length-e;if((void 0===r||athis.length)throw new RangeError("Attempt to write outside buffer bounds");return o=e,i=r,g(s(t,(n=this).length-o),n,o,i)},f.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):n=t.length&&(e=t.length),e||(e=0),0=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>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o - //
- // - // - //
- // - // - // - // - // - /* generated by vue-loader */ - - /***/ -}, -/* 3 */ -/***/ function (module, exports, __webpack_require__) { - - var QRCode = __webpack_require__(4); - var ErrorCorrectLevel = __webpack_require__(8); - - var qrcode = function (data, opt) { - opt = opt || {}; - var qr = new QRCode(opt.typeNumber || -1, - opt.errorCorrectLevel || ErrorCorrectLevel.H); - qr.addData(data); - qr.make(); - - return qr; - }; - - qrcode.ErrorCorrectLevel = ErrorCorrectLevel; - - module.exports = qrcode; - - - - /***/ -}, -/* 4 */ -/***/ function (module, exports, __webpack_require__) { - - var BitByte = __webpack_require__(5); - var RSBlock = __webpack_require__(7); - var BitBuffer = __webpack_require__(9); - var util = __webpack_require__(10); - var Polynomial = __webpack_require__(11); - - function QRCode(typeNumber, errorCorrectLevel) { - this.typeNumber = typeNumber; - this.errorCorrectLevel = errorCorrectLevel; - this.modules = null; - this.moduleCount = 0; - this.dataCache = null; - this.dataList = []; - } - - // for client side minification - var proto = QRCode.prototype; - - proto.addData = function (data) { - var newData = new BitByte(data); - this.dataList.push(newData); - this.dataCache = null; - }; - - proto.isDark = function (row, col) { - if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) { - throw new Error(row + "," + col); - } - return this.modules[row][col]; - }; - - proto.getModuleCount = function () { - return this.moduleCount; - }; - - proto.make = function () { - // Calculate automatically typeNumber if provided is < 1 - if (this.typeNumber < 1) { - var typeNumber = 1; - for (typeNumber = 1; typeNumber < 40; typeNumber++) { - var rsBlocks = RSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel); - - var buffer = new BitBuffer(); - var totalDataCount = 0; - for (var i = 0; i < rsBlocks.length; i++) { - totalDataCount += rsBlocks[i].dataCount; - } - - for (var i = 0; i < this.dataList.length; i++) { - var data = this.dataList[i]; - buffer.put(data.mode, 4); - buffer.put(data.getLength(), util.getLengthInBits(data.mode, typeNumber)); - data.write(buffer); - } - if (buffer.getLengthInBits() <= totalDataCount * 8) - break; - } - this.typeNumber = typeNumber; - } - this.makeImpl(false, this.getBestMaskPattern()); - }; - - proto.makeImpl = function (test, maskPattern) { - - this.moduleCount = this.typeNumber * 4 + 17; - this.modules = new Array(this.moduleCount); - - for (var row = 0; row < this.moduleCount; row++) { - - this.modules[row] = new Array(this.moduleCount); - - for (var col = 0; col < this.moduleCount; col++) { - this.modules[row][col] = null;//(col + row) % 3; - } - } - - this.setupPositionProbePattern(0, 0); - this.setupPositionProbePattern(this.moduleCount - 7, 0); - this.setupPositionProbePattern(0, this.moduleCount - 7); - this.setupPositionAdjustPattern(); - this.setupTimingPattern(); - this.setupTypeInfo(test, maskPattern); - - if (this.typeNumber >= 7) { - this.setupTypeNumber(test); - } - - if (this.dataCache == null) { - this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList); - } - - this.mapData(this.dataCache, maskPattern); - }; - - proto.setupPositionProbePattern = function (row, col) { - - for (var r = -1; r <= 7; r++) { - - if (row + r <= -1 || this.moduleCount <= row + r) continue; - - for (var c = -1; c <= 7; c++) { - - if (col + c <= -1 || this.moduleCount <= col + c) continue; - - if ((0 <= r && r <= 6 && (c == 0 || c == 6)) - || (0 <= c && c <= 6 && (r == 0 || r == 6)) - || (2 <= r && r <= 4 && 2 <= c && c <= 4)) { - this.modules[row + r][col + c] = true; - } else { - this.modules[row + r][col + c] = false; - } - } - } - }; - - proto.getBestMaskPattern = function () { - - var minLostPoint = 0; - var pattern = 0; - - for (var i = 0; i < 8; i++) { - - this.makeImpl(true, i); - - var lostPoint = util.getLostPoint(this); - - if (i == 0 || minLostPoint > lostPoint) { - minLostPoint = lostPoint; - pattern = i; - } - } - - return pattern; - }; - - proto.createMovieClip = function (target_mc, instance_name, depth) { - - var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth); - var cs = 1; - - this.make(); - - for (var row = 0; row < this.modules.length; row++) { - - var y = row * cs; - - for (var col = 0; col < this.modules[row].length; col++) { - - var x = col * cs; - var dark = this.modules[row][col]; - - if (dark) { - qr_mc.beginFill(0, 100); - qr_mc.moveTo(x, y); - qr_mc.lineTo(x + cs, y); - qr_mc.lineTo(x + cs, y + cs); - qr_mc.lineTo(x, y + cs); - qr_mc.endFill(); - } - } - } - - return qr_mc; - }; - - proto.setupTimingPattern = function () { - - for (var r = 8; r < this.moduleCount - 8; r++) { - if (this.modules[r][6] != null) { - continue; - } - this.modules[r][6] = (r % 2 == 0); - } - - for (var c = 8; c < this.moduleCount - 8; c++) { - if (this.modules[6][c] != null) { - continue; - } - this.modules[6][c] = (c % 2 == 0); - } - }; - - proto.setupPositionAdjustPattern = function () { - - var pos = util.getPatternPosition(this.typeNumber); - - for (var i = 0; i < pos.length; i++) { - - for (var j = 0; j < pos.length; j++) { - - var row = pos[i]; - var col = pos[j]; - - if (this.modules[row][col] != null) { - continue; - } - - for (var r = -2; r <= 2; r++) { - - for (var c = -2; c <= 2; c++) { - - if (r == -2 || r == 2 || c == -2 || c == 2 - || (r == 0 && c == 0)) { - this.modules[row + r][col + c] = true; - } else { - this.modules[row + r][col + c] = false; - } - } - } - } - } - }; - - proto.setupTypeNumber = function (test) { - - var bits = util.getBCHTypeNumber(this.typeNumber); - - for (var i = 0; i < 18; i++) { - var mod = (!test && ((bits >> i) & 1) == 1); - this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod; - } - - for (var i = 0; i < 18; i++) { - var mod = (!test && ((bits >> i) & 1) == 1); - this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod; - } - }; - - proto.setupTypeInfo = function (test, maskPattern) { - - var data = (this.errorCorrectLevel << 3) | maskPattern; - var bits = util.getBCHTypeInfo(data); - - // vertical - for (var i = 0; i < 15; i++) { - - var mod = (!test && ((bits >> i) & 1) == 1); - - if (i < 6) { - this.modules[i][8] = mod; - } else if (i < 8) { - this.modules[i + 1][8] = mod; - } else { - this.modules[this.moduleCount - 15 + i][8] = mod; - } - } - - // horizontal - for (var i = 0; i < 15; i++) { - - var mod = (!test && ((bits >> i) & 1) == 1); - - if (i < 8) { - this.modules[8][this.moduleCount - i - 1] = mod; - } else if (i < 9) { - this.modules[8][15 - i - 1 + 1] = mod; - } else { - this.modules[8][15 - i - 1] = mod; - } - } - - // fixed module - this.modules[this.moduleCount - 8][8] = (!test); - }; - - proto.mapData = function (data, maskPattern) { - - var inc = -1; - var row = this.moduleCount - 1; - var bitIndex = 7; - var byteIndex = 0; - - for (var col = this.moduleCount - 1; col > 0; col -= 2) { - - if (col == 6) col--; - - while (true) { - - for (var c = 0; c < 2; c++) { - - if (this.modules[row][col - c] == null) { - - var dark = false; - - if (byteIndex < data.length) { - dark = (((data[byteIndex] >>> bitIndex) & 1) == 1); - } - - var mask = util.getMask(maskPattern, row, col - c); - - if (mask) { - dark = !dark; - } - - this.modules[row][col - c] = dark; - bitIndex--; - - if (bitIndex == -1) { - byteIndex++; - bitIndex = 7; - } - } - } - - row += inc; - - if (row < 0 || this.moduleCount <= row) { - row -= inc; - inc = -inc; - break; - } - } - } - }; - - QRCode.PAD0 = 0xEC; - QRCode.PAD1 = 0x11; - - QRCode.createData = function (typeNumber, errorCorrectLevel, dataList) { - - var rsBlocks = RSBlock.getRSBlocks(typeNumber, errorCorrectLevel); - - var buffer = new BitBuffer(); - - for (var i = 0; i < dataList.length; i++) { - var data = dataList[i]; - buffer.put(data.mode, 4); - buffer.put(data.getLength(), util.getLengthInBits(data.mode, typeNumber)); - data.write(buffer); - } - - // calc num max data. - var totalDataCount = 0; - for (var i = 0; i < rsBlocks.length; i++) { - totalDataCount += rsBlocks[i].dataCount; - } - - if (buffer.getLengthInBits() > totalDataCount * 8) { - throw new Error("code length overflow. (" - + buffer.getLengthInBits() - + ">" - + totalDataCount * 8 - + ")"); - } - - // end code - if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) { - buffer.put(0, 4); - } - - // padding - while (buffer.getLengthInBits() % 8 != 0) { - buffer.putBit(false); - } - - // padding - while (true) { - - if (buffer.getLengthInBits() >= totalDataCount * 8) { - break; - } - buffer.put(QRCode.PAD0, 8); - - if (buffer.getLengthInBits() >= totalDataCount * 8) { - break; - } - buffer.put(QRCode.PAD1, 8); - } - - return QRCode.createBytes(buffer, rsBlocks); - }; - - QRCode.createBytes = function (buffer, rsBlocks) { - - var offset = 0; - - var maxDcCount = 0; - var maxEcCount = 0; - - var dcdata = new Array(rsBlocks.length); - var ecdata = new Array(rsBlocks.length); - - for (var r = 0; r < rsBlocks.length; r++) { - - var dcCount = rsBlocks[r].dataCount; - var ecCount = rsBlocks[r].totalCount - dcCount; - - maxDcCount = Math.max(maxDcCount, dcCount); - maxEcCount = Math.max(maxEcCount, ecCount); - - dcdata[r] = new Array(dcCount); - - for (var i = 0; i < dcdata[r].length; i++) { - dcdata[r][i] = 0xff & buffer.buffer[i + offset]; - } - offset += dcCount; - - var rsPoly = util.getErrorCorrectPolynomial(ecCount); - var rawPoly = new Polynomial(dcdata[r], rsPoly.getLength() - 1); - - var modPoly = rawPoly.mod(rsPoly); - ecdata[r] = new Array(rsPoly.getLength() - 1); - for (var i = 0; i < ecdata[r].length; i++) { - var modIndex = i + modPoly.getLength() - ecdata[r].length; - ecdata[r][i] = (modIndex >= 0) ? modPoly.get(modIndex) : 0; - } - - } - - var totalCodeCount = 0; - for (var i = 0; i < rsBlocks.length; i++) { - totalCodeCount += rsBlocks[i].totalCount; - } - - var data = new Array(totalCodeCount); - var index = 0; - - for (var i = 0; i < maxDcCount; i++) { - for (var r = 0; r < rsBlocks.length; r++) { - if (i < dcdata[r].length) { - data[index++] = dcdata[r][i]; - } - } - } - - for (var i = 0; i < maxEcCount; i++) { - for (var r = 0; r < rsBlocks.length; r++) { - if (i < ecdata[r].length) { - data[index++] = ecdata[r][i]; - } - } - } - - return data; - }; - - module.exports = QRCode; - - - - /***/ -}, -/* 5 */ -/***/ function (module, exports, __webpack_require__) { - - var mode = __webpack_require__(6); - - function QR8bitByte(data) { - this.mode = mode.MODE_8BIT_BYTE; - this.data = data; - } - - QR8bitByte.prototype = { - - getLength: function (buffer) { - return this.data.length; - }, - - write: function (buffer) { - for (var i = 0; i < this.data.length; i++) { - // not JIS ... - buffer.put(this.data.charCodeAt(i), 8); - } - } - }; - - module.exports = QR8bitByte; - - - - /***/ -}, -/* 6 */ -/***/ function (module, exports) { - - module.exports = { - MODE_NUMBER: 1 << 0, - MODE_ALPHA_NUM: 1 << 1, - MODE_8BIT_BYTE: 1 << 2, - MODE_KANJI: 1 << 3 - }; - - - /***/ -}, -/* 7 */ -/***/ function (module, exports, __webpack_require__) { - - // ErrorCorrectLevel - var ECL = __webpack_require__(8); - - function QRRSBlock(totalCount, dataCount) { - this.totalCount = totalCount; - this.dataCount = dataCount; - } - - QRRSBlock.RS_BLOCK_TABLE = [ - - // L - // M - // Q - // H - - // 1 - [1, 26, 19], - [1, 26, 16], - [1, 26, 13], - [1, 26, 9], - - // 2 - [1, 44, 34], - [1, 44, 28], - [1, 44, 22], - [1, 44, 16], - - // 3 - [1, 70, 55], - [1, 70, 44], - [2, 35, 17], - [2, 35, 13], - - // 4 - [1, 100, 80], - [2, 50, 32], - [2, 50, 24], - [4, 25, 9], - - // 5 - [1, 134, 108], - [2, 67, 43], - [2, 33, 15, 2, 34, 16], - [2, 33, 11, 2, 34, 12], - - // 6 - [2, 86, 68], - [4, 43, 27], - [4, 43, 19], - [4, 43, 15], - - // 7 - [2, 98, 78], - [4, 49, 31], - [2, 32, 14, 4, 33, 15], - [4, 39, 13, 1, 40, 14], - - // 8 - [2, 121, 97], - [2, 60, 38, 2, 61, 39], - [4, 40, 18, 2, 41, 19], - [4, 40, 14, 2, 41, 15], - - // 9 - [2, 146, 116], - [3, 58, 36, 2, 59, 37], - [4, 36, 16, 4, 37, 17], - [4, 36, 12, 4, 37, 13], - - // 10 - [2, 86, 68, 2, 87, 69], - [4, 69, 43, 1, 70, 44], - [6, 43, 19, 2, 44, 20], - [6, 43, 15, 2, 44, 16], - - // 11 - [4, 101, 81], - [1, 80, 50, 4, 81, 51], - [4, 50, 22, 4, 51, 23], - [3, 36, 12, 8, 37, 13], - - // 12 - [2, 116, 92, 2, 117, 93], - [6, 58, 36, 2, 59, 37], - [4, 46, 20, 6, 47, 21], - [7, 42, 14, 4, 43, 15], - - // 13 - [4, 133, 107], - [8, 59, 37, 1, 60, 38], - [8, 44, 20, 4, 45, 21], - [12, 33, 11, 4, 34, 12], - - // 14 - [3, 145, 115, 1, 146, 116], - [4, 64, 40, 5, 65, 41], - [11, 36, 16, 5, 37, 17], - [11, 36, 12, 5, 37, 13], - - // 15 - [5, 109, 87, 1, 110, 88], - [5, 65, 41, 5, 66, 42], - [5, 54, 24, 7, 55, 25], - [11, 36, 12], - - // 16 - [5, 122, 98, 1, 123, 99], - [7, 73, 45, 3, 74, 46], - [15, 43, 19, 2, 44, 20], - [3, 45, 15, 13, 46, 16], - - // 17 - [1, 135, 107, 5, 136, 108], - [10, 74, 46, 1, 75, 47], - [1, 50, 22, 15, 51, 23], - [2, 42, 14, 17, 43, 15], - - // 18 - [5, 150, 120, 1, 151, 121], - [9, 69, 43, 4, 70, 44], - [17, 50, 22, 1, 51, 23], - [2, 42, 14, 19, 43, 15], - - // 19 - [3, 141, 113, 4, 142, 114], - [3, 70, 44, 11, 71, 45], - [17, 47, 21, 4, 48, 22], - [9, 39, 13, 16, 40, 14], - - // 20 - [3, 135, 107, 5, 136, 108], - [3, 67, 41, 13, 68, 42], - [15, 54, 24, 5, 55, 25], - [15, 43, 15, 10, 44, 16], - - // 21 - [4, 144, 116, 4, 145, 117], - [17, 68, 42], - [17, 50, 22, 6, 51, 23], - [19, 46, 16, 6, 47, 17], - - // 22 - [2, 139, 111, 7, 140, 112], - [17, 74, 46], - [7, 54, 24, 16, 55, 25], - [34, 37, 13], - - // 23 - [4, 151, 121, 5, 152, 122], - [4, 75, 47, 14, 76, 48], - [11, 54, 24, 14, 55, 25], - [16, 45, 15, 14, 46, 16], - - // 24 - [6, 147, 117, 4, 148, 118], - [6, 73, 45, 14, 74, 46], - [11, 54, 24, 16, 55, 25], - [30, 46, 16, 2, 47, 17], - - // 25 - [8, 132, 106, 4, 133, 107], - [8, 75, 47, 13, 76, 48], - [7, 54, 24, 22, 55, 25], - [22, 45, 15, 13, 46, 16], - - // 26 - [10, 142, 114, 2, 143, 115], - [19, 74, 46, 4, 75, 47], - [28, 50, 22, 6, 51, 23], - [33, 46, 16, 4, 47, 17], - - // 27 - [8, 152, 122, 4, 153, 123], - [22, 73, 45, 3, 74, 46], - [8, 53, 23, 26, 54, 24], - [12, 45, 15, 28, 46, 16], - - // 28 - [3, 147, 117, 10, 148, 118], - [3, 73, 45, 23, 74, 46], - [4, 54, 24, 31, 55, 25], - [11, 45, 15, 31, 46, 16], - - // 29 - [7, 146, 116, 7, 147, 117], - [21, 73, 45, 7, 74, 46], - [1, 53, 23, 37, 54, 24], - [19, 45, 15, 26, 46, 16], - - // 30 - [5, 145, 115, 10, 146, 116], - [19, 75, 47, 10, 76, 48], - [15, 54, 24, 25, 55, 25], - [23, 45, 15, 25, 46, 16], - - // 31 - [13, 145, 115, 3, 146, 116], - [2, 74, 46, 29, 75, 47], - [42, 54, 24, 1, 55, 25], - [23, 45, 15, 28, 46, 16], - - // 32 - [17, 145, 115], - [10, 74, 46, 23, 75, 47], - [10, 54, 24, 35, 55, 25], - [19, 45, 15, 35, 46, 16], - - // 33 - [17, 145, 115, 1, 146, 116], - [14, 74, 46, 21, 75, 47], - [29, 54, 24, 19, 55, 25], - [11, 45, 15, 46, 46, 16], - - // 34 - [13, 145, 115, 6, 146, 116], - [14, 74, 46, 23, 75, 47], - [44, 54, 24, 7, 55, 25], - [59, 46, 16, 1, 47, 17], - - // 35 - [12, 151, 121, 7, 152, 122], - [12, 75, 47, 26, 76, 48], - [39, 54, 24, 14, 55, 25], - [22, 45, 15, 41, 46, 16], - - // 36 - [6, 151, 121, 14, 152, 122], - [6, 75, 47, 34, 76, 48], - [46, 54, 24, 10, 55, 25], - [2, 45, 15, 64, 46, 16], - - // 37 - [17, 152, 122, 4, 153, 123], - [29, 74, 46, 14, 75, 47], - [49, 54, 24, 10, 55, 25], - [24, 45, 15, 46, 46, 16], - - // 38 - [4, 152, 122, 18, 153, 123], - [13, 74, 46, 32, 75, 47], - [48, 54, 24, 14, 55, 25], - [42, 45, 15, 32, 46, 16], - - // 39 - [20, 147, 117, 4, 148, 118], - [40, 75, 47, 7, 76, 48], - [43, 54, 24, 22, 55, 25], - [10, 45, 15, 67, 46, 16], - - // 40 - [19, 148, 118, 6, 149, 119], - [18, 75, 47, 31, 76, 48], - [34, 54, 24, 34, 55, 25], - [20, 45, 15, 61, 46, 16] - ]; - - QRRSBlock.getRSBlocks = function (typeNumber, errorCorrectLevel) { - - var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel); - - if (rsBlock == undefined) { - throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel); - } - - var length = rsBlock.length / 3; - - var list = new Array(); - - for (var i = 0; i < length; i++) { - - var count = rsBlock[i * 3 + 0]; - var totalCount = rsBlock[i * 3 + 1]; - var dataCount = rsBlock[i * 3 + 2]; - - for (var j = 0; j < count; j++) { - list.push(new QRRSBlock(totalCount, dataCount)); - } - } - - return list; - } - - QRRSBlock.getRsBlockTable = function (typeNumber, errorCorrectLevel) { - - switch (errorCorrectLevel) { - case ECL.L: - return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0]; - case ECL.M: - return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1]; - case ECL.Q: - return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2]; - case ECL.H: - return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3]; - default: - return undefined; - } - } - - module.exports = QRRSBlock; - - - /***/ -}, -/* 8 */ -/***/ function (module, exports) { - - module.exports = { - L: 1, - M: 0, - Q: 3, - H: 2 - }; - - - - /***/ -}, -/* 9 */ -/***/ function (module, exports) { - - function QRBitBuffer() { - this.buffer = new Array(); - this.length = 0; - } - - QRBitBuffer.prototype = { - - get: function (index) { - var bufIndex = Math.floor(index / 8); - return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) == 1; - }, - - put: function (num, length) { - for (var i = 0; i < length; i++) { - this.putBit(((num >>> (length - i - 1)) & 1) == 1); - } - }, - - getLengthInBits: function () { - return this.length; - }, - - putBit: function (bit) { - - var bufIndex = Math.floor(this.length / 8); - if (this.buffer.length <= bufIndex) { - this.buffer.push(0); - } - - if (bit) { - this.buffer[bufIndex] |= (0x80 >>> (this.length % 8)); - } - - this.length++; - } - }; - - module.exports = QRBitBuffer; - - - /***/ -}, -/* 10 */ -/***/ function (module, exports, __webpack_require__) { - - var Mode = __webpack_require__(6); - var Polynomial = __webpack_require__(11); - var math = __webpack_require__(12); - - var QRMaskPattern = { - PATTERN000: 0, - PATTERN001: 1, - PATTERN010: 2, - PATTERN011: 3, - PATTERN100: 4, - PATTERN101: 5, - PATTERN110: 6, - PATTERN111: 7 - }; - - var QRUtil = { - - 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: (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0), - G18: (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0), - G15_MASK: (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1), - - getBCHTypeInfo: function (data) { - var d = data << 10; - while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { - d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15))); - } - return ((data << 10) | d) ^ QRUtil.G15_MASK; - }, - - getBCHTypeNumber: function (data) { - var d = data << 12; - while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { - d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18))); - } - return (data << 12) | d; - }, - - getBCHDigit: function (data) { - - var digit = 0; - - while (data != 0) { - digit++; - data >>>= 1; - } - - return digit; - }, - - getPatternPosition: function (typeNumber) { - return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1]; - }, - - getMask: function (maskPattern, i, j) { - - switch (maskPattern) { - - case QRMaskPattern.PATTERN000: return (i + j) % 2 == 0; - case QRMaskPattern.PATTERN001: return i % 2 == 0; - case QRMaskPattern.PATTERN010: return j % 3 == 0; - case QRMaskPattern.PATTERN011: return (i + j) % 3 == 0; - case QRMaskPattern.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0; - case QRMaskPattern.PATTERN101: return (i * j) % 2 + (i * j) % 3 == 0; - case QRMaskPattern.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 == 0; - case QRMaskPattern.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 == 0; - - default: - throw new Error("bad maskPattern:" + maskPattern); - } - }, - - getErrorCorrectPolynomial: function (errorCorrectLength) { - - var a = new Polynomial([1], 0); - - for (var i = 0; i < errorCorrectLength; i++) { - a = a.multiply(new Polynomial([1, math.gexp(i)], 0)); - } - - return a; - }, - - getLengthInBits: function (mode, type) { - - if (1 <= type && type < 10) { - - // 1 - 9 - - switch (mode) { - case Mode.MODE_NUMBER: return 10; - case Mode.MODE_ALPHA_NUM: return 9; - case Mode.MODE_8BIT_BYTE: return 8; - case Mode.MODE_KANJI: return 8; - default: - throw new Error("mode:" + mode); - } - - } else if (type < 27) { - - // 10 - 26 - - switch (mode) { - case Mode.MODE_NUMBER: return 12; - case Mode.MODE_ALPHA_NUM: return 11; - case Mode.MODE_8BIT_BYTE: return 16; - case Mode.MODE_KANJI: return 10; - default: - throw new Error("mode:" + mode); - } - - } else if (type < 41) { - - // 27 - 40 - - switch (mode) { - case Mode.MODE_NUMBER: return 14; - case Mode.MODE_ALPHA_NUM: return 13; - case Mode.MODE_8BIT_BYTE: return 16; - case Mode.MODE_KANJI: return 12; - default: - throw new Error("mode:" + mode); - } - - } else { - throw new Error("type:" + type); - } - }, - - getLostPoint: function (qrCode) { - - var moduleCount = qrCode.getModuleCount(); - - var lostPoint = 0; - - // LEVEL1 - - for (var row = 0; row < moduleCount; row++) { - - for (var col = 0; col < moduleCount; col++) { - - var sameCount = 0; - var dark = qrCode.isDark(row, col); - - for (var r = -1; r <= 1; r++) { - - if (row + r < 0 || moduleCount <= row + r) { - continue; - } - - for (var c = -1; c <= 1; c++) { - - if (col + c < 0 || moduleCount <= col + c) { - continue; - } - - if (r == 0 && c == 0) { - continue; - } - - if (dark == qrCode.isDark(row + r, col + c)) { - sameCount++; - } - } - } - - if (sameCount > 5) { - lostPoint += (3 + sameCount - 5); - } - } - } - - // LEVEL2 - - for (var row = 0; row < moduleCount - 1; row++) { - for (var col = 0; col < moduleCount - 1; col++) { - var count = 0; - if (qrCode.isDark(row, col)) count++; - if (qrCode.isDark(row + 1, col)) count++; - if (qrCode.isDark(row, col + 1)) count++; - if (qrCode.isDark(row + 1, col + 1)) count++; - if (count == 0 || count == 4) { - lostPoint += 3; - } - } - } - - // LEVEL3 - - for (var row = 0; row < moduleCount; row++) { - for (var col = 0; col < moduleCount - 6; col++) { - if (qrCode.isDark(row, col) - && !qrCode.isDark(row, col + 1) - && qrCode.isDark(row, col + 2) - && qrCode.isDark(row, col + 3) - && qrCode.isDark(row, col + 4) - && !qrCode.isDark(row, col + 5) - && qrCode.isDark(row, col + 6)) { - lostPoint += 40; - } - } - } - - for (var col = 0; col < moduleCount; col++) { - for (var row = 0; row < moduleCount - 6; row++) { - if (qrCode.isDark(row, col) - && !qrCode.isDark(row + 1, col) - && qrCode.isDark(row + 2, col) - && qrCode.isDark(row + 3, col) - && qrCode.isDark(row + 4, col) - && !qrCode.isDark(row + 5, col) - && qrCode.isDark(row + 6, col)) { - lostPoint += 40; - } - } - } - - // LEVEL4 - - var darkCount = 0; - - for (var col = 0; col < moduleCount; col++) { - for (var row = 0; row < moduleCount; row++) { - if (qrCode.isDark(row, col)) { - darkCount++; - } - } - } - - var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; - lostPoint += ratio * 10; - - return lostPoint; - } - }; - - module.exports = QRUtil; - - - /***/ -}, -/* 11 */ -/***/ function (module, exports, __webpack_require__) { - - var math = __webpack_require__(12); - - function QRPolynomial(num, shift) { - - if (num.length == undefined) { - throw new Error(num.length + "/" + shift); - } - - var offset = 0; - - while (offset < num.length && num[offset] == 0) { - offset++; - } - - this.num = new Array(num.length - offset + shift); - for (var i = 0; i < num.length - offset; i++) { - this.num[i] = num[i + offset]; - } - } - - QRPolynomial.prototype = { - - get: function (index) { - return this.num[index]; - }, - - getLength: function () { - return this.num.length; - }, - - multiply: function (e) { - - var num = new Array(this.getLength() + e.getLength() - 1); - - for (var i = 0; i < this.getLength(); i++) { - for (var j = 0; j < e.getLength(); j++) { - num[i + j] ^= math.gexp(math.glog(this.get(i)) + math.glog(e.get(j))); - } - } - - return new QRPolynomial(num, 0); - }, - - mod: function (e) { - - if (this.getLength() - e.getLength() < 0) { - return this; - } - - var ratio = math.glog(this.get(0)) - math.glog(e.get(0)); - - var num = new Array(this.getLength()); - - for (var i = 0; i < this.getLength(); i++) { - num[i] = this.get(i); - } - - for (var i = 0; i < e.getLength(); i++) { - num[i] ^= math.gexp(math.glog(e.get(i)) + ratio); - } - - // recursive call - return new QRPolynomial(num, 0).mod(e); - } - }; - - module.exports = QRPolynomial; - - - /***/ -}, -/* 12 */ -/***/ function (module, exports) { - - var QRMath = { - - glog: function (n) { - - if (n < 1) { - throw new Error("glog(" + n + ")"); - } - - return QRMath.LOG_TABLE[n]; - }, - - gexp: function (n) { - - while (n < 0) { - n += 255; - } - - while (n >= 256) { - n -= 255; - } - - return QRMath.EXP_TABLE[n]; - }, - - EXP_TABLE: new Array(256), - - LOG_TABLE: new Array(256) - - }; - - for (var i = 0; i < 8; i++) { - QRMath.EXP_TABLE[i] = 1 << i; - } - for (var i = 8; i < 256; i++) { - QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] - ^ QRMath.EXP_TABLE[i - 5] - ^ QRMath.EXP_TABLE[i - 6] - ^ QRMath.EXP_TABLE[i - 8]; - } - for (var i = 0; i < 255; i++) { - QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i; - } - - module.exports = QRMath; - - - /***/ -}, -/* 13 */ -/***/ function (module, exports) { - - module.exports = "\n
\n \n \n
\n"; - - /***/ -} -/******/]) -}); -; -//# sourceMappingURL=vue-qrcode.js.map diff --git a/BTCPayServer/wwwroot/vendor/vuejs/vue-qrcode.js.map b/BTCPayServer/wwwroot/vendor/vuejs/vue-qrcode.js.map deleted file mode 100644 index f37f88c2f..000000000 --- a/BTCPayServer/wwwroot/vendor/vuejs/vue-qrcode.js.map +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": 3, - "sources": [ "webpack:///webpack/universalModuleDefinition", "webpack:///webpack/bootstrap 4d0ca69ab3f3eb801054", "webpack:///./src/index.js", "webpack:///./src/Qrcode.vue", "webpack:///Qrcode.vue", "webpack:///./~/qr.js/index.js", "webpack:///./~/qr.js/lib/QRCode.js", "webpack:///./~/qr.js/lib/8BitByte.js", "webpack:///./~/qr.js/lib/mode.js", "webpack:///./~/qr.js/lib/RSBlock.js", "webpack:///./~/qr.js/lib/ErrorCorrectLevel.js", "webpack:///./~/qr.js/lib/BitBuffer.js", "webpack:///./~/qr.js/lib/util.js", "webpack:///./~/qr.js/lib/Polynomial.js", "webpack:///./~/qr.js/lib/math.js", "webpack:///./src/Qrcode.vue?ba49" ], - "names": [ "module", "exports" ], - "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;ACtCA;;;;;;AAGAA,QAAOC,OAAP,oB;;;;;;ACHA;AACA;AACA;AACA;AACA;AACA,wBAAuB;AACvB,aAAiB,cAAc;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA,IAAG;AACH;AACA;AACA,EAAC,I;;;;;;;;;;;;ACDD;;;;;;AAEA,gCACA;QACA;AAEA;;;;;;;;;;;;;;;;;;aAIA;iBAEA;AAHA;;aAKA;gBAEA;AAHA;AAIA;YACA;;aAEA;gBAEA;AAHA;;aAKA;gBAGA;AAJA;AAfA;iBAoBA;YACA;;+BAEA;uBACA;0BACA;0BACA;4BAEA;;2CAEA;;gCACA;0BACA;gCACA;gCACA;8EAEA;;uCACA;wBAEA;;yCACA;0CACA;4CACA;mEACA;mEACA;6EACA;AACA;AACA;AAEA;AA3BA;AAvBA;;;AAoDA,yCACA;AACA,cACA,oCACA,iCACA,gCACA,+BACA,0BAEA;;;;;;;;;;;ACnFA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;;;;;;;ACfA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,uBAAsB,iBAAiB;AACvC;;AAEA;AACA;AACA,mBAAkB,qBAAqB;AACvC;AACA;;AAEA,mBAAkB,0BAA0B;AAC5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA,mBAAkB,wBAAwB;;AAE1C;;AAEA,oBAAmB,wBAAwB;AAC3C,kCAAiC;AACjC;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA,kBAAiB,QAAQ;;AAEzB;;AAEA,mBAAkB,QAAQ;;AAE1B;;AAEA;AACA;AACA;AACA;AACA,KAAI;AACJ;AACA;AACA,I;AACA,G;AACA;;AAEA;;AAEA;AACA;;AAEA,iBAAgB,OAAO;;AAEvB;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;;AAEA;;AAEA,mBAAkB,2BAA2B;;AAE7C;;AAEA,oBAAmB,gCAAgC;;AAEnD;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA,iBAAgB,0BAA0B;AAC1C;AACA;AACA;AACA;AACA;;AAEA,iBAAgB,0BAA0B;AAC1C;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA,iBAAgB,gBAAgB;;AAEhC,kBAAiB,gBAAgB;;AAEjC;AACA;;AAEA;AACA;AACA;;AAEA,oBAAmB,QAAQ;;AAE3B,qBAAoB,QAAQ;;AAE5B;AACA;AACA;AACA,OAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA,iBAAgB,QAAQ;AACxB;AACA;AACA;;AAEA,iBAAgB,QAAQ;AACxB;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA,iBAAgB,QAAQ;;AAExB;;AAEA;AACA;AACA,IAAG;AACH;AACA,IAAG;AACH;AACA;AACA;;AAEA;AACA,iBAAgB,QAAQ;;AAExB;;AAEA;AACA;AACA,IAAG;AACH;AACA,IAAG;AACH;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA,sCAAqC,SAAS;;AAE9C;;AAEA;;AAEA,mBAAkB,OAAO;;AAEzB;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA,iBAAgB,qBAAqB;AACrC;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,iBAAgB,qBAAqB;AACrC;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;AACA;;AAEA,iBAAgB,qBAAqB;;AAErC;AACA;;AAEA;AACA;;AAEA;;AAEA,kBAAiB,sBAAsB;AACvC;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA,kBAAiB,sBAAsB;AACvC;AACA;AACA;;AAEA;;AAEA;AACA,iBAAgB,qBAAqB;AACrC;AACA;;AAEA;AACA;;AAEA,iBAAgB,gBAAgB;AAChC,kBAAiB,qBAAqB;AACtC;AACA;AACA;AACA;AACA;;AAEA,iBAAgB,gBAAgB;AAChC,kBAAiB,qBAAqB;AACtC;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;;;;;;;ACpbA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,GAAE;;AAEF;AACA,kBAAiB,sBAAsB;AACvC;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;ACrBA;AACA;AACA;AACA;AACA;AACA;;;;;;;ACLA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA,iBAAgB,YAAY;;AAE5B;AACA;AACA;;AAEA,kBAAiB,WAAW;AAC5B,qD;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;AC1SA;AACA;AACA;AACA;AACA;AACA;;;;;;;;ACLA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA,GAAE;;AAEF;AACA,kBAAiB,YAAY;AAC7B;AACA;AACA,GAAE;;AAEF;AACA;AACA,GAAE;;AAEF;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;;;;;;ACrCA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,uF;AACA;AACA;AACA,MAAK;;AAEL;AACA;AACA;AACA,uF;AACA;AACA;AACA,MAAK;;AAEL;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,MAAK;;AAEL;AACA;AACA,MAAK;;AAEL;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,MAAK;;AAEL;;AAEA;;AAEA,qBAAoB,wBAAwB;AAC5C;AACA;;AAEA;AACA,MAAK;;AAEL;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAM;;AAEN;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAM;;AAEN;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAM;AACN;AACA;AACA,MAAK;;AAEL;;AAEA;;AAEA;;AAEA;;AAEA,uBAAsB,mBAAmB;;AAEzC,wBAAuB,mBAAmB;;AAE1C;AACA;;AAEA,qBAAoB,QAAQ;;AAE5B;AACA;AACA;;AAEA,yBAAwB,QAAQ;;AAEhC;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA,uBAAsB,uBAAuB;AAC7C,wBAAuB,uBAAuB;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA,uBAAsB,mBAAmB;AACzC,wBAAuB,uBAAuB;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,uBAAsB,mBAAmB;AACzC,wBAAuB,uBAAuB;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA,uBAAsB,mBAAmB;AACzC,wBAAuB,mBAAmB;AAC1C;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA,uB;AACA;AACA;;AAEA;;;;;;;ACtRA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA,iBAAgB,yBAAyB;AACzC;AACA;AACA;;AAEA;;AAEA;AACA;AACA,GAAE;;AAEF;AACA;AACA,GAAE;;AAEF;;AAEA;;AAEA,kBAAiB,sBAAsB;AACvC,mBAAkB,mBAAmB;AACrC;AACA;AACA;;AAEA;AACA,GAAE;;AAEF;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA,kBAAiB,sBAAsB;AACvC;AACA;;AAEA,kBAAiB,mBAAmB;AACpC;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;;;;;;AClEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA,GAAE;;AAEF;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,GAAE;;AAEF;;AAEA;;AAEA;;AAEA,gBAAe,OAAO;AACtB;AACA;AACA,gBAAe,SAAS;AACxB;AACA;AACA;AACA;AACA;AACA,gBAAe,SAAS;AACxB;AACA;;AAEA;;;;;;;AC3CA,wJAAuJ,wCAAwC,qH", - "file": "./dist/vue-qrcode.js", - "sourcesContent": [ "(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"VueQr\"] = factory();\n\telse\n\t\troot[\"VueQr\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition", " \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 4d0ca69ab3f3eb801054", "import Qrcode from './Qrcode.vue'\n\n\nmodule.exports = Qrcode\n\n\n\n\n// WEBPACK FOOTER //\n// ./src/index.js", "var __vue_script__, __vue_template__\n__vue_script__ = require(\"-!babel-loader!./../node_modules/vue-loader/lib/selector.js?type=script&index=0!./Qrcode.vue\")\n__vue_template__ = require(\"-!vue-html-loader!./../node_modules/vue-loader/lib/selector.js?type=template&index=0!./Qrcode.vue\")\nmodule.exports = __vue_script__ || {}\nif (module.exports.__esModule) module.exports = module.exports.default\nif (__vue_template__) { (typeof module.exports === \"function\" ? module.exports.options : module.exports).template = __vue_template__ }\nif (module.hot) {(function () { module.hot.accept()\n var hotAPI = require(\"vue-hot-reload-api\")\n hotAPI.install(require(\"vue\"), true)\n if (!hotAPI.compatible) return\n var id = \"/home/vixi_n/Documents/Github/vue-qrcode/src/Qrcode.vue\"\n if (!module.hot.data) {\n hotAPI.createRecord(id, module.exports)\n } else {\n hotAPI.update(id, module.exports, __vue_template__)\n }\n})()}\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/Qrcode.vue\n// module id = 1\n// module chunks = 0", "\n\n\n\n\n\n\n// WEBPACK FOOTER //\n// Qrcode.vue?34bfdd1a", "var QRCode = require('./lib/QRCode');\r\nvar ErrorCorrectLevel = require('./lib/ErrorCorrectLevel');\r\n\r\nvar qrcode = function(data, opt) {\r\n\topt = opt || {};\r\n\tvar qr = new QRCode(opt.typeNumber || -1,\r\n\t\t\t\t\t\topt.errorCorrectLevel || ErrorCorrectLevel.H);\r\n\tqr.addData(data);\r\n\tqr.make();\r\n\r\n\treturn qr;\r\n};\r\n\r\nqrcode.ErrorCorrectLevel = ErrorCorrectLevel;\r\n\r\nmodule.exports = qrcode;\r\n\r\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/qr.js/index.js\n// module id = 3\n// module chunks = 0", "var BitByte = require('./8BitByte');\nvar RSBlock = require('./RSBlock');\nvar BitBuffer = require('./BitBuffer');\nvar util = require('./util');\nvar Polynomial = require('./Polynomial');\n\nfunction QRCode(typeNumber, errorCorrectLevel) {\n\tthis.typeNumber = typeNumber;\n\tthis.errorCorrectLevel = errorCorrectLevel;\n\tthis.modules = null;\n\tthis.moduleCount = 0;\n\tthis.dataCache = null;\n\tthis.dataList = [];\n}\n\n// for client side minification\nvar proto = QRCode.prototype;\n\nproto.addData = function(data) {\n\tvar newData = new BitByte(data);\n\tthis.dataList.push(newData);\n\tthis.dataCache = null;\n};\n\nproto.isDark = function(row, col) {\n\tif (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {\n\t\tthrow new Error(row + \",\" + col);\n\t}\n\treturn this.modules[row][col];\n};\n\nproto.getModuleCount = function() {\n\treturn this.moduleCount;\n};\n\nproto.make = function() {\n\t// Calculate automatically typeNumber if provided is < 1\n\tif (this.typeNumber < 1 ){\n\t\tvar typeNumber = 1;\n\t\tfor (typeNumber = 1; typeNumber < 40; typeNumber++) {\n\t\t\tvar rsBlocks = RSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);\n\n\t\t\tvar buffer = new BitBuffer();\n\t\t\tvar totalDataCount = 0;\n\t\t\tfor (var i = 0; i < rsBlocks.length; i++) {\n\t\t\t\ttotalDataCount += rsBlocks[i].dataCount;\n\t\t\t}\n\n\t\t\tfor (var i = 0; i < this.dataList.length; i++) {\n\t\t\t\tvar data = this.dataList[i];\n\t\t\t\tbuffer.put(data.mode, 4);\n\t\t\t\tbuffer.put(data.getLength(), util.getLengthInBits(data.mode, typeNumber) );\n\t\t\t\tdata.write(buffer);\n\t\t\t}\n\t\t\tif (buffer.getLengthInBits() <= totalDataCount * 8)\n\t\t\t\tbreak;\n\t\t}\n\t\tthis.typeNumber = typeNumber;\n\t}\n\tthis.makeImpl(false, this.getBestMaskPattern() );\n};\n\nproto.makeImpl = function(test, maskPattern) {\n\t\n\tthis.moduleCount = this.typeNumber * 4 + 17;\n\tthis.modules = new Array(this.moduleCount);\n\t\n\tfor (var row = 0; row < this.moduleCount; row++) {\n\t\t\n\t\tthis.modules[row] = new Array(this.moduleCount);\n\t\t\n\t\tfor (var col = 0; col < this.moduleCount; col++) {\n\t\t\tthis.modules[row][col] = null;//(col + row) % 3;\n\t\t}\n\t}\n\n\tthis.setupPositionProbePattern(0, 0);\n\tthis.setupPositionProbePattern(this.moduleCount - 7, 0);\n\tthis.setupPositionProbePattern(0, this.moduleCount - 7);\n\tthis.setupPositionAdjustPattern();\n\tthis.setupTimingPattern();\n\tthis.setupTypeInfo(test, maskPattern);\n\t\n\tif (this.typeNumber >= 7) {\n\t\tthis.setupTypeNumber(test);\n\t}\n\n\tif (this.dataCache == null) {\n\t\tthis.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList);\n\t}\n\n\tthis.mapData(this.dataCache, maskPattern);\n};\n\nproto.setupPositionProbePattern = function(row, col) {\n\t\n\tfor (var r = -1; r <= 7; r++) {\n\t\t\n\t\tif (row + r <= -1 || this.moduleCount <= row + r) continue;\n\t\t\n\t\tfor (var c = -1; c <= 7; c++) {\n\t\t\t\n\t\t\tif (col + c <= -1 || this.moduleCount <= col + c) continue;\n\t\t\t\n\t\t\tif ( (0 <= r && r <= 6 && (c == 0 || c == 6) )\n\t\t\t\t\t|| (0 <= c && c <= 6 && (r == 0 || r == 6) )\n\t\t\t\t\t|| (2 <= r && r <= 4 && 2 <= c && c <= 4) ) {\n\t\t\t\tthis.modules[row + r][col + c] = true;\n\t\t\t} else {\n\t\t\t\tthis.modules[row + r][col + c] = false;\n\t\t\t}\n\t\t}\t\t\n\t}\t\t\n};\n\nproto.getBestMaskPattern = function() {\n\n\tvar minLostPoint = 0;\n\tvar pattern = 0;\n\n\tfor (var i = 0; i < 8; i++) {\n\t\t\n\t\tthis.makeImpl(true, i);\n\n\t\tvar lostPoint = util.getLostPoint(this);\n\n\t\tif (i == 0 || minLostPoint > lostPoint) {\n\t\t\tminLostPoint = lostPoint;\n\t\t\tpattern = i;\n\t\t}\n\t}\n\n\treturn pattern;\n};\n\nproto.createMovieClip = function(target_mc, instance_name, depth) {\n\n\tvar qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);\n\tvar cs = 1;\n\n\tthis.make();\n\n\tfor (var row = 0; row < this.modules.length; row++) {\n\t\t\n\t\tvar y = row * cs;\n\t\t\n\t\tfor (var col = 0; col < this.modules[row].length; col++) {\n\n\t\t\tvar x = col * cs;\n\t\t\tvar dark = this.modules[row][col];\n\t\t\n\t\t\tif (dark) {\n\t\t\t\tqr_mc.beginFill(0, 100);\n\t\t\t\tqr_mc.moveTo(x, y);\n\t\t\t\tqr_mc.lineTo(x + cs, y);\n\t\t\t\tqr_mc.lineTo(x + cs, y + cs);\n\t\t\t\tqr_mc.lineTo(x, y + cs);\n\t\t\t\tqr_mc.endFill();\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn qr_mc;\n};\n\nproto.setupTimingPattern = function() {\n\t\n\tfor (var r = 8; r < this.moduleCount - 8; r++) {\n\t\tif (this.modules[r][6] != null) {\n\t\t\tcontinue;\n\t\t}\n\t\tthis.modules[r][6] = (r % 2 == 0);\n\t}\n\n\tfor (var c = 8; c < this.moduleCount - 8; c++) {\n\t\tif (this.modules[6][c] != null) {\n\t\t\tcontinue;\n\t\t}\n\t\tthis.modules[6][c] = (c % 2 == 0);\n\t}\n};\n\nproto.setupPositionAdjustPattern = function() {\n\n\tvar pos = util.getPatternPosition(this.typeNumber);\n\t\n\tfor (var i = 0; i < pos.length; i++) {\n\t\n\t\tfor (var j = 0; j < pos.length; j++) {\n\t\t\n\t\t\tvar row = pos[i];\n\t\t\tvar col = pos[j];\n\t\t\t\n\t\t\tif (this.modules[row][col] != null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tfor (var r = -2; r <= 2; r++) {\n\t\t\t\n\t\t\t\tfor (var c = -2; c <= 2; c++) {\n\t\t\t\t\n\t\t\t\t\tif (r == -2 || r == 2 || c == -2 || c == 2\n\t\t\t\t\t\t\t|| (r == 0 && c == 0) ) {\n\t\t\t\t\t\tthis.modules[row + r][col + c] = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.modules[row + r][col + c] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n};\n\nproto.setupTypeNumber = function(test) {\n\n\tvar bits = util.getBCHTypeNumber(this.typeNumber);\n\n\tfor (var i = 0; i < 18; i++) {\n\t\tvar mod = (!test && ( (bits >> i) & 1) == 1);\n\t\tthis.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;\n\t}\n\n\tfor (var i = 0; i < 18; i++) {\n\t\tvar mod = (!test && ( (bits >> i) & 1) == 1);\n\t\tthis.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod;\n\t}\n};\n\nproto.setupTypeInfo = function(test, maskPattern) {\n\n\tvar data = (this.errorCorrectLevel << 3) | maskPattern;\n\tvar bits = util.getBCHTypeInfo(data);\n\n\t// vertical\t\t\n\tfor (var i = 0; i < 15; i++) {\n\n\t\tvar mod = (!test && ( (bits >> i) & 1) == 1);\n\n\t\tif (i < 6) {\n\t\t\tthis.modules[i][8] = mod;\n\t\t} else if (i < 8) {\n\t\t\tthis.modules[i + 1][8] = mod;\n\t\t} else {\n\t\t\tthis.modules[this.moduleCount - 15 + i][8] = mod;\n\t\t}\n\t}\n\n\t// horizontal\n\tfor (var i = 0; i < 15; i++) {\n\n\t\tvar mod = (!test && ( (bits >> i) & 1) == 1);\n\t\t\n\t\tif (i < 8) {\n\t\t\tthis.modules[8][this.moduleCount - i - 1] = mod;\n\t\t} else if (i < 9) {\n\t\t\tthis.modules[8][15 - i - 1 + 1] = mod;\n\t\t} else {\n\t\t\tthis.modules[8][15 - i - 1] = mod;\n\t\t}\n\t}\n\n\t// fixed module\n\tthis.modules[this.moduleCount - 8][8] = (!test);\n};\n\nproto.mapData = function(data, maskPattern) {\n\t\n\tvar inc = -1;\n\tvar row = this.moduleCount - 1;\n\tvar bitIndex = 7;\n\tvar byteIndex = 0;\n\t\n\tfor (var col = this.moduleCount - 1; col > 0; col -= 2) {\n\n\t\tif (col == 6) col--;\n\n\t\twhile (true) {\n\n\t\t\tfor (var c = 0; c < 2; c++) {\n\t\t\t\t\n\t\t\t\tif (this.modules[row][col - c] == null) {\n\t\t\t\t\t\n\t\t\t\t\tvar dark = false;\n\n\t\t\t\t\tif (byteIndex < data.length) {\n\t\t\t\t\t\tdark = ( ( (data[byteIndex] >>> bitIndex) & 1) == 1);\n\t\t\t\t\t}\n\n\t\t\t\t\tvar mask = util.getMask(maskPattern, row, col - c);\n\n\t\t\t\t\tif (mask) {\n\t\t\t\t\t\tdark = !dark;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tthis.modules[row][col - c] = dark;\n\t\t\t\t\tbitIndex--;\n\n\t\t\t\t\tif (bitIndex == -1) {\n\t\t\t\t\t\tbyteIndex++;\n\t\t\t\t\t\tbitIndex = 7;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\trow += inc;\n\n\t\t\tif (row < 0 || this.moduleCount <= row) {\n\t\t\t\trow -= inc;\n\t\t\t\tinc = -inc;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n};\n\nQRCode.PAD0 = 0xEC;\nQRCode.PAD1 = 0x11;\n\nQRCode.createData = function(typeNumber, errorCorrectLevel, dataList) {\n\t\n\tvar rsBlocks = RSBlock.getRSBlocks(typeNumber, errorCorrectLevel);\n\t\n\tvar buffer = new BitBuffer();\n\t\n\tfor (var i = 0; i < dataList.length; i++) {\n\t\tvar data = dataList[i];\n\t\tbuffer.put(data.mode, 4);\n\t\tbuffer.put(data.getLength(), util.getLengthInBits(data.mode, typeNumber) );\n\t\tdata.write(buffer);\n\t}\n\n\t// calc num max data.\n\tvar totalDataCount = 0;\n\tfor (var i = 0; i < rsBlocks.length; i++) {\n\t\ttotalDataCount += rsBlocks[i].dataCount;\n\t}\n\n\tif (buffer.getLengthInBits() > totalDataCount * 8) {\n\t\tthrow new Error(\"code length overflow. (\"\n\t\t\t+ buffer.getLengthInBits()\n\t\t\t+ \">\"\n\t\t\t+ totalDataCount * 8\n\t\t\t+ \")\");\n\t}\n\n\t// end code\n\tif (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {\n\t\tbuffer.put(0, 4);\n\t}\n\n\t// padding\n\twhile (buffer.getLengthInBits() % 8 != 0) {\n\t\tbuffer.putBit(false);\n\t}\n\n\t// padding\n\twhile (true) {\n\t\t\n\t\tif (buffer.getLengthInBits() >= totalDataCount * 8) {\n\t\t\tbreak;\n\t\t}\n\t\tbuffer.put(QRCode.PAD0, 8);\n\t\t\n\t\tif (buffer.getLengthInBits() >= totalDataCount * 8) {\n\t\t\tbreak;\n\t\t}\n\t\tbuffer.put(QRCode.PAD1, 8);\n\t}\n\n\treturn QRCode.createBytes(buffer, rsBlocks);\n};\n\nQRCode.createBytes = function(buffer, rsBlocks) {\n\n\tvar offset = 0;\n\t\n\tvar maxDcCount = 0;\n\tvar maxEcCount = 0;\n\t\n\tvar dcdata = new Array(rsBlocks.length);\n\tvar ecdata = new Array(rsBlocks.length);\n\t\n\tfor (var r = 0; r < rsBlocks.length; r++) {\n\n\t\tvar dcCount = rsBlocks[r].dataCount;\n\t\tvar ecCount = rsBlocks[r].totalCount - dcCount;\n\n\t\tmaxDcCount = Math.max(maxDcCount, dcCount);\n\t\tmaxEcCount = Math.max(maxEcCount, ecCount);\n\t\t\n\t\tdcdata[r] = new Array(dcCount);\n\t\t\n\t\tfor (var i = 0; i < dcdata[r].length; i++) {\n\t\t\tdcdata[r][i] = 0xff & buffer.buffer[i + offset];\n\t\t}\n\t\toffset += dcCount;\n\t\t\n\t\tvar rsPoly = util.getErrorCorrectPolynomial(ecCount);\n\t\tvar rawPoly = new Polynomial(dcdata[r], rsPoly.getLength() - 1);\n\n\t\tvar modPoly = rawPoly.mod(rsPoly);\n\t\tecdata[r] = new Array(rsPoly.getLength() - 1);\n\t\tfor (var i = 0; i < ecdata[r].length; i++) {\n var modIndex = i + modPoly.getLength() - ecdata[r].length;\n\t\t\tecdata[r][i] = (modIndex >= 0)? modPoly.get(modIndex) : 0;\n\t\t}\n\n\t}\n\t\n\tvar totalCodeCount = 0;\n\tfor (var i = 0; i < rsBlocks.length; i++) {\n\t\ttotalCodeCount += rsBlocks[i].totalCount;\n\t}\n\n\tvar data = new Array(totalCodeCount);\n\tvar index = 0;\n\n\tfor (var i = 0; i < maxDcCount; i++) {\n\t\tfor (var r = 0; r < rsBlocks.length; r++) {\n\t\t\tif (i < dcdata[r].length) {\n\t\t\t\tdata[index++] = dcdata[r][i];\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (var i = 0; i < maxEcCount; i++) {\n\t\tfor (var r = 0; r < rsBlocks.length; r++) {\n\t\t\tif (i < ecdata[r].length) {\n\t\t\t\tdata[index++] = ecdata[r][i];\n\t\t\t}\n\t\t}\n\t}\n\n\treturn data;\n};\n\nmodule.exports = QRCode;\n\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/qr.js/lib/QRCode.js\n// module id = 4\n// module chunks = 0", "var mode = require('./mode');\n\nfunction QR8bitByte(data) {\n\tthis.mode = mode.MODE_8BIT_BYTE;\n\tthis.data = data;\n}\n\nQR8bitByte.prototype = {\n\n\tgetLength : function(buffer) {\n\t\treturn this.data.length;\n\t},\n\t\n\twrite : function(buffer) {\n\t\tfor (var i = 0; i < this.data.length; i++) {\n\t\t\t// not JIS ...\n\t\t\tbuffer.put(this.data.charCodeAt(i), 8);\n\t\t}\n\t}\n};\n\nmodule.exports = QR8bitByte;\n\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/qr.js/lib/8BitByte.js\n// module id = 5\n// module chunks = 0", "module.exports = {\n\tMODE_NUMBER :\t\t1 << 0,\n\tMODE_ALPHA_NUM : \t1 << 1,\n\tMODE_8BIT_BYTE : \t1 << 2,\n\tMODE_KANJI :\t\t1 << 3\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/qr.js/lib/mode.js\n// module id = 6\n// module chunks = 0", "// ErrorCorrectLevel\nvar ECL = require('./ErrorCorrectLevel');\n\nfunction QRRSBlock(totalCount, dataCount) {\n\tthis.totalCount = totalCount;\n\tthis.dataCount = dataCount;\n}\n\nQRRSBlock.RS_BLOCK_TABLE = [\n\n\t// L\n\t// M\n\t// Q\n\t// H\n\n\t// 1\n\t[1, 26, 19],\n\t[1, 26, 16],\n\t[1, 26, 13],\n\t[1, 26, 9],\n\t\n\t// 2\n\t[1, 44, 34],\n\t[1, 44, 28],\n\t[1, 44, 22],\n\t[1, 44, 16],\n\n\t// 3\n\t[1, 70, 55],\n\t[1, 70, 44],\n\t[2, 35, 17],\n\t[2, 35, 13],\n\n\t// 4\t\t\n\t[1, 100, 80],\n\t[2, 50, 32],\n\t[2, 50, 24],\n\t[4, 25, 9],\n\t\n\t// 5\n\t[1, 134, 108],\n\t[2, 67, 43],\n\t[2, 33, 15, 2, 34, 16],\n\t[2, 33, 11, 2, 34, 12],\n\t\n\t// 6\n\t[2, 86, 68],\n\t[4, 43, 27],\n\t[4, 43, 19],\n\t[4, 43, 15],\n\t\n\t// 7\t\t\n\t[2, 98, 78],\n\t[4, 49, 31],\n\t[2, 32, 14, 4, 33, 15],\n\t[4, 39, 13, 1, 40, 14],\n\t\n\t// 8\n\t[2, 121, 97],\n\t[2, 60, 38, 2, 61, 39],\n\t[4, 40, 18, 2, 41, 19],\n\t[4, 40, 14, 2, 41, 15],\n\t\n\t// 9\n\t[2, 146, 116],\n\t[3, 58, 36, 2, 59, 37],\n\t[4, 36, 16, 4, 37, 17],\n\t[4, 36, 12, 4, 37, 13],\n\t\n\t// 10\t\t\n\t[2, 86, 68, 2, 87, 69],\n\t[4, 69, 43, 1, 70, 44],\n\t[6, 43, 19, 2, 44, 20],\n\t[6, 43, 15, 2, 44, 16],\n\n\t// 11\n\t[4, 101, 81],\n\t[1, 80, 50, 4, 81, 51],\n\t[4, 50, 22, 4, 51, 23],\n\t[3, 36, 12, 8, 37, 13],\n\n\t// 12\n\t[2, 116, 92, 2, 117, 93],\n\t[6, 58, 36, 2, 59, 37],\n\t[4, 46, 20, 6, 47, 21],\n\t[7, 42, 14, 4, 43, 15],\n\n\t// 13\n\t[4, 133, 107],\n\t[8, 59, 37, 1, 60, 38],\n\t[8, 44, 20, 4, 45, 21],\n\t[12, 33, 11, 4, 34, 12],\n\n\t// 14\n\t[3, 145, 115, 1, 146, 116],\n\t[4, 64, 40, 5, 65, 41],\n\t[11, 36, 16, 5, 37, 17],\n\t[11, 36, 12, 5, 37, 13],\n\n\t// 15\n\t[5, 109, 87, 1, 110, 88],\n\t[5, 65, 41, 5, 66, 42],\n\t[5, 54, 24, 7, 55, 25],\n\t[11, 36, 12],\n\n\t// 16\n\t[5, 122, 98, 1, 123, 99],\n\t[7, 73, 45, 3, 74, 46],\n\t[15, 43, 19, 2, 44, 20],\n\t[3, 45, 15, 13, 46, 16],\n\n\t// 17\n\t[1, 135, 107, 5, 136, 108],\n\t[10, 74, 46, 1, 75, 47],\n\t[1, 50, 22, 15, 51, 23],\n\t[2, 42, 14, 17, 43, 15],\n\n\t// 18\n\t[5, 150, 120, 1, 151, 121],\n\t[9, 69, 43, 4, 70, 44],\n\t[17, 50, 22, 1, 51, 23],\n\t[2, 42, 14, 19, 43, 15],\n\n\t// 19\n\t[3, 141, 113, 4, 142, 114],\n\t[3, 70, 44, 11, 71, 45],\n\t[17, 47, 21, 4, 48, 22],\n\t[9, 39, 13, 16, 40, 14],\n\n\t// 20\n\t[3, 135, 107, 5, 136, 108],\n\t[3, 67, 41, 13, 68, 42],\n\t[15, 54, 24, 5, 55, 25],\n\t[15, 43, 15, 10, 44, 16],\n\n\t// 21\n\t[4, 144, 116, 4, 145, 117],\n\t[17, 68, 42],\n\t[17, 50, 22, 6, 51, 23],\n\t[19, 46, 16, 6, 47, 17],\n\n\t// 22\n\t[2, 139, 111, 7, 140, 112],\n\t[17, 74, 46],\n\t[7, 54, 24, 16, 55, 25],\n\t[34, 37, 13],\n\n\t// 23\n\t[4, 151, 121, 5, 152, 122],\n\t[4, 75, 47, 14, 76, 48],\n\t[11, 54, 24, 14, 55, 25],\n\t[16, 45, 15, 14, 46, 16],\n\n\t// 24\n\t[6, 147, 117, 4, 148, 118],\n\t[6, 73, 45, 14, 74, 46],\n\t[11, 54, 24, 16, 55, 25],\n\t[30, 46, 16, 2, 47, 17],\n\n\t// 25\n\t[8, 132, 106, 4, 133, 107],\n\t[8, 75, 47, 13, 76, 48],\n\t[7, 54, 24, 22, 55, 25],\n\t[22, 45, 15, 13, 46, 16],\n\n\t// 26\n\t[10, 142, 114, 2, 143, 115],\n\t[19, 74, 46, 4, 75, 47],\n\t[28, 50, 22, 6, 51, 23],\n\t[33, 46, 16, 4, 47, 17],\n\n\t// 27\n\t[8, 152, 122, 4, 153, 123],\n\t[22, 73, 45, 3, 74, 46],\n\t[8, 53, 23, 26, 54, 24],\n\t[12, 45, 15, 28, 46, 16],\n\n\t// 28\n\t[3, 147, 117, 10, 148, 118],\n\t[3, 73, 45, 23, 74, 46],\n\t[4, 54, 24, 31, 55, 25],\n\t[11, 45, 15, 31, 46, 16],\n\n\t// 29\n\t[7, 146, 116, 7, 147, 117],\n\t[21, 73, 45, 7, 74, 46],\n\t[1, 53, 23, 37, 54, 24],\n\t[19, 45, 15, 26, 46, 16],\n\n\t// 30\n\t[5, 145, 115, 10, 146, 116],\n\t[19, 75, 47, 10, 76, 48],\n\t[15, 54, 24, 25, 55, 25],\n\t[23, 45, 15, 25, 46, 16],\n\n\t// 31\n\t[13, 145, 115, 3, 146, 116],\n\t[2, 74, 46, 29, 75, 47],\n\t[42, 54, 24, 1, 55, 25],\n\t[23, 45, 15, 28, 46, 16],\n\n\t// 32\n\t[17, 145, 115],\n\t[10, 74, 46, 23, 75, 47],\n\t[10, 54, 24, 35, 55, 25],\n\t[19, 45, 15, 35, 46, 16],\n\n\t// 33\n\t[17, 145, 115, 1, 146, 116],\n\t[14, 74, 46, 21, 75, 47],\n\t[29, 54, 24, 19, 55, 25],\n\t[11, 45, 15, 46, 46, 16],\n\n\t// 34\n\t[13, 145, 115, 6, 146, 116],\n\t[14, 74, 46, 23, 75, 47],\n\t[44, 54, 24, 7, 55, 25],\n\t[59, 46, 16, 1, 47, 17],\n\n\t// 35\n\t[12, 151, 121, 7, 152, 122],\n\t[12, 75, 47, 26, 76, 48],\n\t[39, 54, 24, 14, 55, 25],\n\t[22, 45, 15, 41, 46, 16],\n\n\t// 36\n\t[6, 151, 121, 14, 152, 122],\n\t[6, 75, 47, 34, 76, 48],\n\t[46, 54, 24, 10, 55, 25],\n\t[2, 45, 15, 64, 46, 16],\n\n\t// 37\n\t[17, 152, 122, 4, 153, 123],\n\t[29, 74, 46, 14, 75, 47],\n\t[49, 54, 24, 10, 55, 25],\n\t[24, 45, 15, 46, 46, 16],\n\n\t// 38\n\t[4, 152, 122, 18, 153, 123],\n\t[13, 74, 46, 32, 75, 47],\n\t[48, 54, 24, 14, 55, 25],\n\t[42, 45, 15, 32, 46, 16],\n\n\t// 39\n\t[20, 147, 117, 4, 148, 118],\n\t[40, 75, 47, 7, 76, 48],\n\t[43, 54, 24, 22, 55, 25],\n\t[10, 45, 15, 67, 46, 16],\n\n\t// 40\n\t[19, 148, 118, 6, 149, 119],\n\t[18, 75, 47, 31, 76, 48],\n\t[34, 54, 24, 34, 55, 25],\n\t[20, 45, 15, 61, 46, 16]\n];\n\nQRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) {\n\t\n\tvar rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);\n\t\n\tif (rsBlock == undefined) {\n\t\tthrow new Error(\"bad rs block @ typeNumber:\" + typeNumber + \"/errorCorrectLevel:\" + errorCorrectLevel);\n\t}\n\n\tvar length = rsBlock.length / 3;\n\t\n\tvar list = new Array();\n\t\n\tfor (var i = 0; i < length; i++) {\n\n\t\tvar count = rsBlock[i * 3 + 0];\n\t\tvar totalCount = rsBlock[i * 3 + 1];\n\t\tvar dataCount = rsBlock[i * 3 + 2];\n\n\t\tfor (var j = 0; j < count; j++) {\n\t\t\tlist.push(new QRRSBlock(totalCount, dataCount) );\t\n\t\t}\n\t}\n\t\n\treturn list;\n}\n\nQRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) {\n\n\tswitch(errorCorrectLevel) {\n\tcase ECL.L :\n\t\treturn QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];\n\tcase ECL.M :\n\t\treturn QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];\n\tcase ECL.Q :\n\t\treturn QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];\n\tcase ECL.H :\n\t\treturn QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];\n\tdefault :\n\t\treturn undefined;\n\t}\n}\n\nmodule.exports = QRRSBlock;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/qr.js/lib/RSBlock.js\n// module id = 7\n// module chunks = 0", "module.exports = {\n\tL : 1,\n\tM : 0,\n\tQ : 3,\n\tH : 2\n};\n\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/qr.js/lib/ErrorCorrectLevel.js\n// module id = 8\n// module chunks = 0", "function QRBitBuffer() {\n\tthis.buffer = new Array();\n\tthis.length = 0;\n}\n\nQRBitBuffer.prototype = {\n\n\tget : function(index) {\n\t\tvar bufIndex = Math.floor(index / 8);\n\t\treturn ( (this.buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1;\n\t},\n\t\n\tput : function(num, length) {\n\t\tfor (var i = 0; i < length; i++) {\n\t\t\tthis.putBit( ( (num >>> (length - i - 1) ) & 1) == 1);\n\t\t}\n\t},\n\t\n\tgetLengthInBits : function() {\n\t\treturn this.length;\n\t},\n\t\n\tputBit : function(bit) {\n\t\n\t\tvar bufIndex = Math.floor(this.length / 8);\n\t\tif (this.buffer.length <= bufIndex) {\n\t\t\tthis.buffer.push(0);\n\t\t}\n\t\n\t\tif (bit) {\n\t\t\tthis.buffer[bufIndex] |= (0x80 >>> (this.length % 8) );\n\t\t}\n\t\n\t\tthis.length++;\n\t}\n};\n\nmodule.exports = QRBitBuffer;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/qr.js/lib/BitBuffer.js\n// module id = 9\n// module chunks = 0", "var Mode = require('./mode');\nvar Polynomial = require('./Polynomial');\nvar math = require('./math');\n\nvar QRMaskPattern = {\n\tPATTERN000 : 0,\n\tPATTERN001 : 1,\n\tPATTERN010 : 2,\n\tPATTERN011 : 3,\n\tPATTERN100 : 4,\n\tPATTERN101 : 5,\n\tPATTERN110 : 6,\n\tPATTERN111 : 7\n};\n\nvar QRUtil = {\n\n PATTERN_POSITION_TABLE : [\n\t [],\n\t [6, 18],\n\t [6, 22],\n\t [6, 26],\n\t [6, 30],\n\t [6, 34],\n\t [6, 22, 38],\n\t [6, 24, 42],\n\t [6, 26, 46],\n\t [6, 28, 50],\n\t [6, 30, 54],\t\t\n\t [6, 32, 58],\n\t [6, 34, 62],\n\t [6, 26, 46, 66],\n\t [6, 26, 48, 70],\n\t [6, 26, 50, 74],\n\t [6, 30, 54, 78],\n\t [6, 30, 56, 82],\n\t [6, 30, 58, 86],\n\t [6, 34, 62, 90],\n\t [6, 28, 50, 72, 94],\n\t [6, 26, 50, 74, 98],\n\t [6, 30, 54, 78, 102],\n\t [6, 28, 54, 80, 106],\n\t [6, 32, 58, 84, 110],\n\t [6, 30, 58, 86, 114],\n\t [6, 34, 62, 90, 118],\n\t [6, 26, 50, 74, 98, 122],\n\t [6, 30, 54, 78, 102, 126],\n\t [6, 26, 52, 78, 104, 130],\n\t [6, 30, 56, 82, 108, 134],\n\t [6, 34, 60, 86, 112, 138],\n\t [6, 30, 58, 86, 114, 142],\n\t [6, 34, 62, 90, 118, 146],\n\t [6, 30, 54, 78, 102, 126, 150],\n\t [6, 24, 50, 76, 102, 128, 154],\n\t [6, 28, 54, 80, 106, 132, 158],\n\t [6, 32, 58, 84, 110, 136, 162],\n\t [6, 26, 54, 82, 110, 138, 166],\n\t [6, 30, 58, 86, 114, 142, 170]\n ],\n\n G15 : (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0),\n G18 : (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0),\n G15_MASK : (1 << 14) | (1 << 12) | (1 << 10)\t| (1 << 4) | (1 << 1),\n\n getBCHTypeInfo : function(data) {\n\t var d = data << 10;\n\t while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {\n\t\t d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) ) ); \t\n\t }\n\t return ( (data << 10) | d) ^ QRUtil.G15_MASK;\n },\n\n getBCHTypeNumber : function(data) {\n\t var d = data << 12;\n\t while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {\n\t\t d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) ) ); \t\n\t }\n\t return (data << 12) | d;\n },\n\n getBCHDigit : function(data) {\n\n\t var digit = 0;\n\n\t while (data != 0) {\n\t\t digit++;\n\t\t data >>>= 1;\n\t }\n\n\t return digit;\n },\n\n getPatternPosition : function(typeNumber) {\n\t return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];\n },\n\n getMask : function(maskPattern, i, j) {\n\t \n\t switch (maskPattern) {\n\t\t \n\t case QRMaskPattern.PATTERN000 : return (i + j) % 2 == 0;\n\t case QRMaskPattern.PATTERN001 : return i % 2 == 0;\n\t case QRMaskPattern.PATTERN010 : return j % 3 == 0;\n\t case QRMaskPattern.PATTERN011 : return (i + j) % 3 == 0;\n\t case QRMaskPattern.PATTERN100 : return (Math.floor(i / 2) + Math.floor(j / 3) ) % 2 == 0;\n\t case QRMaskPattern.PATTERN101 : return (i * j) % 2 + (i * j) % 3 == 0;\n\t case QRMaskPattern.PATTERN110 : return ( (i * j) % 2 + (i * j) % 3) % 2 == 0;\n\t case QRMaskPattern.PATTERN111 : return ( (i * j) % 3 + (i + j) % 2) % 2 == 0;\n\n\t default :\n\t\t throw new Error(\"bad maskPattern:\" + maskPattern);\n\t }\n },\n\n getErrorCorrectPolynomial : function(errorCorrectLength) {\n\n\t var a = new Polynomial([1], 0);\n\n\t for (var i = 0; i < errorCorrectLength; i++) {\n\t\t a = a.multiply(new Polynomial([1, math.gexp(i)], 0) );\n\t }\n\n\t return a;\n },\n\n getLengthInBits : function(mode, type) {\n\n\t if (1 <= type && type < 10) {\n\n\t\t // 1 - 9\n\n\t\t switch(mode) {\n\t\t case Mode.MODE_NUMBER \t: return 10;\n\t\t case Mode.MODE_ALPHA_NUM \t: return 9;\n\t\t case Mode.MODE_8BIT_BYTE\t: return 8;\n\t\t case Mode.MODE_KANJI \t: return 8;\n\t\t default :\n\t\t\t throw new Error(\"mode:\" + mode);\n\t\t }\n\n\t } else if (type < 27) {\n\n\t\t // 10 - 26\n\n\t\t switch(mode) {\n\t\t case Mode.MODE_NUMBER \t: return 12;\n\t\t case Mode.MODE_ALPHA_NUM \t: return 11;\n\t\t case Mode.MODE_8BIT_BYTE\t: return 16;\n\t\t case Mode.MODE_KANJI \t: return 10;\n\t\t default :\n\t\t\t throw new Error(\"mode:\" + mode);\n\t\t }\n\n\t } else if (type < 41) {\n\n\t\t // 27 - 40\n\n\t\t switch(mode) {\n\t\t case Mode.MODE_NUMBER \t: return 14;\n\t\t case Mode.MODE_ALPHA_NUM\t: return 13;\n\t\t case Mode.MODE_8BIT_BYTE\t: return 16;\n\t\t case Mode.MODE_KANJI \t: return 12;\n\t\t default :\n\t\t\t throw new Error(\"mode:\" + mode);\n\t\t }\n\n\t } else {\n\t\t throw new Error(\"type:\" + type);\n\t }\n },\n\n getLostPoint : function(qrCode) {\n\t \n\t var moduleCount = qrCode.getModuleCount();\n\t \n\t var lostPoint = 0;\n\t \n\t // LEVEL1\n\t \n\t for (var row = 0; row < moduleCount; row++) {\n\n\t\t for (var col = 0; col < moduleCount; col++) {\n\n\t\t\t var sameCount = 0;\n\t\t\t var dark = qrCode.isDark(row, col);\n\n\t\t\t\tfor (var r = -1; r <= 1; r++) {\n\n\t\t\t\t if (row + r < 0 || moduleCount <= row + r) {\n\t\t\t\t\t continue;\n\t\t\t\t }\n\n\t\t\t\t for (var c = -1; c <= 1; c++) {\n\n\t\t\t\t\t if (col + c < 0 || moduleCount <= col + c) {\n\t\t\t\t\t\t continue;\n\t\t\t\t\t }\n\n\t\t\t\t\t if (r == 0 && c == 0) {\n\t\t\t\t\t\t continue;\n\t\t\t\t\t }\n\n\t\t\t\t\t if (dark == qrCode.isDark(row + r, col + c) ) {\n\t\t\t\t\t\t sameCount++;\n\t\t\t\t\t }\n\t\t\t\t }\n\t\t\t }\n\n\t\t\t if (sameCount > 5) {\n\t\t\t\t lostPoint += (3 + sameCount - 5);\n\t\t\t }\n\t\t }\n\t }\n\n\t // LEVEL2\n\n\t for (var row = 0; row < moduleCount - 1; row++) {\n\t\t for (var col = 0; col < moduleCount - 1; col++) {\n\t\t\t var count = 0;\n\t\t\t if (qrCode.isDark(row, col ) ) count++;\n\t\t\t if (qrCode.isDark(row + 1, col ) ) count++;\n\t\t\t if (qrCode.isDark(row, col + 1) ) count++;\n\t\t\t if (qrCode.isDark(row + 1, col + 1) ) count++;\n\t\t\t if (count == 0 || count == 4) {\n\t\t\t\t lostPoint += 3;\n\t\t\t }\n\t\t }\n\t }\n\n\t // LEVEL3\n\n\t for (var row = 0; row < moduleCount; row++) {\n\t\t for (var col = 0; col < moduleCount - 6; col++) {\n\t\t\t if (qrCode.isDark(row, col)\n\t\t\t\t\t && !qrCode.isDark(row, col + 1)\n\t\t\t\t\t && qrCode.isDark(row, col + 2)\n\t\t\t\t\t && qrCode.isDark(row, col + 3)\n\t\t\t\t\t && qrCode.isDark(row, col + 4)\n\t\t\t\t\t && !qrCode.isDark(row, col + 5)\n\t\t\t\t\t && qrCode.isDark(row, col + 6) ) {\n\t\t\t\t lostPoint += 40;\n\t\t\t }\n\t\t }\n\t }\n\n\t for (var col = 0; col < moduleCount; col++) {\n\t\t for (var row = 0; row < moduleCount - 6; row++) {\n\t\t\t if (qrCode.isDark(row, col)\n\t\t\t\t\t && !qrCode.isDark(row + 1, col)\n\t\t\t\t\t && qrCode.isDark(row + 2, col)\n\t\t\t\t\t && qrCode.isDark(row + 3, col)\n\t\t\t\t\t && qrCode.isDark(row + 4, col)\n\t\t\t\t\t && !qrCode.isDark(row + 5, col)\n\t\t\t\t\t && qrCode.isDark(row + 6, col) ) {\n\t\t\t\t lostPoint += 40;\n\t\t\t }\n\t\t }\n\t }\n\n\t // LEVEL4\n\t \n\t var darkCount = 0;\n\n\t for (var col = 0; col < moduleCount; col++) {\n\t\t for (var row = 0; row < moduleCount; row++) {\n\t\t\t if (qrCode.isDark(row, col) ) {\n\t\t\t\t darkCount++;\n\t\t\t }\n\t\t }\n\t }\n\t \n\t var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;\n\t lostPoint += ratio * 10;\n\n\t return lostPoint;\t\t\n }\n};\n\nmodule.exports = QRUtil;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/qr.js/lib/util.js\n// module id = 10\n// module chunks = 0", "var math = require('./math');\n\nfunction QRPolynomial(num, shift) {\n\n\tif (num.length == undefined) {\n\t\tthrow new Error(num.length + \"/\" + shift);\n\t}\n\n\tvar offset = 0;\n\n\twhile (offset < num.length && num[offset] == 0) {\n\t\toffset++;\n\t}\n\n\tthis.num = new Array(num.length - offset + shift);\n\tfor (var i = 0; i < num.length - offset; i++) {\n\t\tthis.num[i] = num[i + offset];\n\t}\n}\n\nQRPolynomial.prototype = {\n\n\tget : function(index) {\n\t\treturn this.num[index];\n\t},\n\t\n\tgetLength : function() {\n\t\treturn this.num.length;\n\t},\n\t\n\tmultiply : function(e) {\n\t\n\t\tvar num = new Array(this.getLength() + e.getLength() - 1);\n\t\n\t\tfor (var i = 0; i < this.getLength(); i++) {\n\t\t\tfor (var j = 0; j < e.getLength(); j++) {\n\t\t\t\tnum[i + j] ^= math.gexp(math.glog(this.get(i) ) + math.glog(e.get(j) ) );\n\t\t\t}\n\t\t}\n\t\n\t\treturn new QRPolynomial(num, 0);\n\t},\n\t\n\tmod : function(e) {\n\t\n\t\tif (this.getLength() - e.getLength() < 0) {\n\t\t\treturn this;\n\t\t}\n\t\n\t\tvar ratio = math.glog(this.get(0) ) - math.glog(e.get(0) );\n\t\n\t\tvar num = new Array(this.getLength() );\n\t\t\n\t\tfor (var i = 0; i < this.getLength(); i++) {\n\t\t\tnum[i] = this.get(i);\n\t\t}\n\t\t\n\t\tfor (var i = 0; i < e.getLength(); i++) {\n\t\t\tnum[i] ^= math.gexp(math.glog(e.get(i) ) + ratio);\n\t\t}\n\t\n\t\t// recursive call\n\t\treturn new QRPolynomial(num, 0).mod(e);\n\t}\n};\n\nmodule.exports = QRPolynomial;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/qr.js/lib/Polynomial.js\n// module id = 11\n// module chunks = 0", "var QRMath = {\n\n\tglog : function(n) {\n\t\n\t\tif (n < 1) {\n\t\t\tthrow new Error(\"glog(\" + n + \")\");\n\t\t}\n\t\t\n\t\treturn QRMath.LOG_TABLE[n];\n\t},\n\t\n\tgexp : function(n) {\n\t\n\t\twhile (n < 0) {\n\t\t\tn += 255;\n\t\t}\n\t\n\t\twhile (n >= 256) {\n\t\t\tn -= 255;\n\t\t}\n\t\n\t\treturn QRMath.EXP_TABLE[n];\n\t},\n\t\n\tEXP_TABLE : new Array(256),\n\t\n\tLOG_TABLE : new Array(256)\n\n};\n\t\nfor (var i = 0; i < 8; i++) {\n\tQRMath.EXP_TABLE[i] = 1 << i;\n}\nfor (var i = 8; i < 256; i++) {\n\tQRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4]\n\t\t^ QRMath.EXP_TABLE[i - 5]\n\t\t^ QRMath.EXP_TABLE[i - 6]\n\t\t^ QRMath.EXP_TABLE[i - 8];\n}\nfor (var i = 0; i < 255; i++) {\n\tQRMath.LOG_TABLE[QRMath.EXP_TABLE[i] ] = i;\n}\n\nmodule.exports = QRMath;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/qr.js/lib/math.js\n// module id = 12\n// module chunks = 0", "module.exports = \"\\n
\\n \\n \\n
\\n\";\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/vue-html-loader!./~/vue-loader/lib/selector.js?type=template&index=0!./src/Qrcode.vue\n// module id = 13\n// module chunks = 0" ], - "sourceRoot": "" -} diff --git a/BTCPayServer/wwwroot/vendor/vuejs/vue-qrcode.min.js b/BTCPayServer/wwwroot/vendor/vuejs/vue-qrcode.min.js deleted file mode 100644 index 0ffa0ef76..000000000 --- a/BTCPayServer/wwwroot/vendor/vuejs/vue-qrcode.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.VueQr=e():t.VueQr=e()}(this,function(){return function(t){function e(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return t[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}var n=r(13),i=o(n);t.exports=i.default},function(t,e){t.exports={L:1,M:0,Q:3,H:2}},function(t,e,r){function o(t,e){if(void 0==t.length)throw new Error(t.length+"/"+e);for(var r=0;r=256;)t-=255;return r.EXP_TABLE[t]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},o=0;o<8;o++)r.EXP_TABLE[o]=1<>>7-t%8&1)},put:function(t,e){for(var r=0;r>>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++}},t.exports=r},function(t,e,r){function o(t,e){this.typeNumber=t,this.errorCorrectLevel=e,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}var n=r(7),i=r(10),a=r(8),s=r(11),u=r(2),h=o.prototype;h.addData=function(t){var e=new n(t);this.dataList.push(e),this.dataCache=null},h.isDark=function(t,e){if(t<0||this.moduleCount<=t||e<0||this.moduleCount<=e)throw new Error(t+","+e);return this.modules[t][e]},h.getModuleCount=function(){return this.moduleCount},h.make=function(){if(this.typeNumber<1){var t=1;for(t=1;t<40;t++){for(var e=i.getRSBlocks(t,this.errorCorrectLevel),r=new a,o=0,n=0;n=7&&this.setupTypeNumber(t),null==this.dataCache&&(this.dataCache=o.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,e)},h.setupPositionProbePattern=function(t,e){for(var r=-1;r<=7;r++)if(!(t+r<=-1||this.moduleCount<=t+r))for(var o=-1;o<=7;o++)e+o<=-1||this.moduleCount<=e+o||(0<=r&&r<=6&&(0==o||6==o)||0<=o&&o<=6&&(0==r||6==r)||2<=r&&r<=4&&2<=o&&o<=4?this.modules[t+r][e+o]=!0:this.modules[t+r][e+o]=!1)},h.getBestMaskPattern=function(){for(var t=0,e=0,r=0;r<8;r++){this.makeImpl(!0,r);var o=s.getLostPoint(this);(0==r||t>o)&&(t=o,e=r)}return e},h.createMovieClip=function(t,e,r){var o=t.createEmptyMovieClip(e,r),n=1;this.make();for(var i=0;i>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=o}for(var r=0;r<18;r++){var o=!t&&1==(e>>r&1);this.modules[r%3+this.moduleCount-8-3][Math.floor(r/3)]=o}},h.setupTypeInfo=function(t,e){for(var r=this.errorCorrectLevel<<3|e,o=s.getBCHTypeInfo(r),n=0;n<15;n++){var i=!t&&1==(o>>n&1);n<6?this.modules[n][8]=i:n<8?this.modules[n+1][8]=i:this.modules[this.moduleCount-15+n][8]=i}for(var n=0;n<15;n++){var i=!t&&1==(o>>n&1);n<8?this.modules[8][this.moduleCount-n-1]=i:n<9?this.modules[8][15-n-1+1]=i:this.modules[8][15-n-1]=i}this.modules[this.moduleCount-8][8]=!t},h.mapData=function(t,e){for(var r=-1,o=this.moduleCount-1,n=7,i=0,a=this.moduleCount-1;a>0;a-=2)for(6==a&&a--;;){for(var u=0;u<2;u++)if(null==this.modules[o][a-u]){var h=!1;i>>n&1));var l=s.getMask(e,o,a-u);l&&(h=!h),this.modules[o][a-u]=h,n--,n==-1&&(i++,n=7)}if(o+=r,o<0||this.moduleCount<=o){o-=r,r=-r;break}}},o.PAD0=236,o.PAD1=17,o.createData=function(t,e,r){for(var n=i.getRSBlocks(t,e),u=new a,h=0;h8*f)throw new Error("code length overflow. ("+u.getLengthInBits()+">"+8*f+")");for(u.getLengthInBits()+4<=8*f&&u.put(0,4);u.getLengthInBits()%8!=0;)u.putBit(!1);for(;;){if(u.getLengthInBits()>=8*f)break;if(u.put(o.PAD0,8),u.getLengthInBits()>=8*f)break;u.put(o.PAD1,8)}return o.createBytes(u,n)},o.createBytes=function(t,e){for(var r=0,o=0,n=0,i=new Array(e.length),a=new Array(e.length),h=0;h=0?v.get(p):0}}for(var m=0,g=0;g=0;)e^=s.G15<=0;)e^=s.G18<>>=1;return e},getPatternPosition:function(t){return s.PATTERN_POSITION_TABLE[t-1]},getMask:function(t,e,r){switch(t){case a.PATTERN000:return(e+r)%2==0;case a.PATTERN001:return e%2==0;case a.PATTERN010:return r%3==0;case a.PATTERN011:return(e+r)%3==0;case a.PATTERN100:return(Math.floor(e/2)+Math.floor(r/3))%2==0;case a.PATTERN101:return e*r%2+e*r%3==0;case a.PATTERN110:return(e*r%2+e*r%3)%2==0;case a.PATTERN111:return(e*r%3+(e+r)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}},getErrorCorrectPolynomial:function(t){for(var e=new n([1],0),r=0;r5&&(r+=3+i-5)}for(var o=0;o
"},function(t,e,r){var o,n;o=r(5),n=r(12),t.exports=o||{},t.exports.__esModule&&(t.exports=t.exports.default),n&&(("function"==typeof t.exports?t.exports.options:t.exports).template=n)}])}); \ No newline at end of file