@nuintun/qrcode
Advanced tools
Comparing version 0.6.2 to 0.7.0
@@ -8,2 +8,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Mode_1 = require("./qrcode/common/Mode"); | ||
exports.Mode = Mode_1.default; | ||
var QRByte_1 = require("./qrcode/encoder/QRByte"); | ||
@@ -21,3 +23,3 @@ exports.QRByte = QRByte_1.default; | ||
exports.QRAlphanumeric = QRAlphanumeric_1.default; | ||
var ErrorCorrectLevel_1 = require("./qrcode/encoder/ErrorCorrectLevel"); | ||
exports.ErrorCorrectLevel = ErrorCorrectLevel_1.default; | ||
var ErrorCorrectionLevel_1 = require("./qrcode/common/ErrorCorrectionLevel"); | ||
exports.ErrorCorrectionLevel = ErrorCorrectionLevel_1.default; |
@@ -10,24 +10,4 @@ "use strict"; | ||
var BitStream_1 = require("./BitStream"); | ||
var Mode_1 = require("../../../common/Mode"); | ||
var SJIS_1 = require("../../../../encoding/SJIS"); | ||
var Mode; | ||
(function (Mode) { | ||
Mode["Numeric"] = "numeric"; | ||
Mode["Alphanumeric"] = "alphanumeric"; | ||
Mode["StructuredAppend"] = "structuredappend"; | ||
Mode["Byte"] = "byte"; | ||
Mode["Kanji"] = "kanji"; | ||
Mode["ECI"] = "eci"; | ||
})(Mode || (Mode = {})); | ||
var ModeByte; | ||
(function (ModeByte) { | ||
ModeByte[ModeByte["Terminator"] = 0] = "Terminator"; | ||
ModeByte[ModeByte["Numeric"] = 1] = "Numeric"; | ||
ModeByte[ModeByte["Alphanumeric"] = 2] = "Alphanumeric"; | ||
ModeByte[ModeByte["StructuredAppend"] = 3] = "StructuredAppend"; | ||
ModeByte[ModeByte["Byte"] = 4] = "Byte"; | ||
ModeByte[ModeByte["Kanji"] = 8] = "Kanji"; | ||
ModeByte[ModeByte["ECI"] = 7] = "ECI"; | ||
// FNC1FirstPosition = 0x5, | ||
// FNC1SecondPosition = 0x9 | ||
})(ModeByte || (ModeByte = {})); | ||
function decodeNumeric(stream, size) { | ||
@@ -102,3 +82,3 @@ var text = ''; | ||
* @function bytesToUTF8 | ||
* @param bytes | ||
* @param {number[]} bytes | ||
* @returns {string} | ||
@@ -165,3 +145,3 @@ * @see https://github.com/google/closure-library/blob/master/closure/goog/crypt/crypt.js | ||
} | ||
function decode(data, version) { | ||
function decode(data, version, errorCorrectionLevel) { | ||
var _a, _b, _c, _d; | ||
@@ -171,12 +151,12 @@ var stream = new BitStream_1.default(data); | ||
var size = version <= 9 ? 0 : version <= 26 ? 1 : 2; | ||
var result = { text: '', bytes: [], chunks: [] }; | ||
var result = { text: '', bytes: [], chunks: [], version: version, errorCorrectionLevel: errorCorrectionLevel }; | ||
while (stream.available() >= 4) { | ||
var mode = stream.readBits(4); | ||
if (mode === ModeByte.Terminator) { | ||
if (mode === Mode_1.default.Terminator) { | ||
return result; | ||
} | ||
else if (mode === ModeByte.ECI) { | ||
else if (mode === Mode_1.default.ECI) { | ||
if (stream.readBits(1) === 0) { | ||
result.chunks.push({ | ||
type: Mode.ECI, | ||
type: Mode_1.default.ECI, | ||
assignmentNumber: stream.readBits(7) | ||
@@ -187,3 +167,3 @@ }); | ||
result.chunks.push({ | ||
type: Mode.ECI, | ||
type: Mode_1.default.ECI, | ||
assignmentNumber: stream.readBits(14) | ||
@@ -194,3 +174,3 @@ }); | ||
result.chunks.push({ | ||
type: Mode.ECI, | ||
type: Mode_1.default.ECI, | ||
assignmentNumber: stream.readBits(21) | ||
@@ -202,3 +182,3 @@ }); | ||
result.chunks.push({ | ||
type: Mode.ECI, | ||
type: Mode_1.default.ECI, | ||
assignmentNumber: -1 | ||
@@ -208,3 +188,3 @@ }); | ||
} | ||
else if (mode === ModeByte.Numeric) { | ||
else if (mode === Mode_1.default.Numeric) { | ||
var numericResult = decodeNumeric(stream, size); | ||
@@ -214,7 +194,7 @@ result.text += numericResult.text; | ||
result.chunks.push({ | ||
type: Mode.Numeric, | ||
type: Mode_1.default.Numeric, | ||
text: numericResult.text | ||
}); | ||
} | ||
else if (mode === ModeByte.Alphanumeric) { | ||
else if (mode === Mode_1.default.Alphanumeric) { | ||
var alphanumericResult = decodeAlphanumeric(stream, size); | ||
@@ -224,7 +204,7 @@ result.text += alphanumericResult.text; | ||
result.chunks.push({ | ||
type: Mode.Alphanumeric, | ||
type: Mode_1.default.Alphanumeric, | ||
text: alphanumericResult.text | ||
}); | ||
} | ||
else if (mode === ModeByte.StructuredAppend) { | ||
else if (mode === Mode_1.default.StructuredAppend) { | ||
// QR Standard section 9.2: | ||
@@ -237,5 +217,5 @@ // > The 4-bit patterns shall be the binary equivalents of (m - 1) and (n - 1) respectively. | ||
}; | ||
result.chunks.push(tslib_1.__assign({ type: Mode.StructuredAppend }, structuredAppend)); | ||
result.chunks.push(tslib_1.__assign({ type: Mode_1.default.StructuredAppend }, structuredAppend)); | ||
} | ||
else if (mode === ModeByte.Byte) { | ||
else if (mode === Mode_1.default.Byte) { | ||
var byteResult = decodeByte(stream, size); | ||
@@ -245,3 +225,3 @@ result.text += byteResult.text; | ||
result.chunks.push({ | ||
type: Mode.Byte, | ||
type: Mode_1.default.Byte, | ||
bytes: byteResult.bytes, | ||
@@ -251,3 +231,3 @@ text: byteResult.text | ||
} | ||
else if (mode === ModeByte.Kanji) { | ||
else if (mode === Mode_1.default.Kanji) { | ||
var kanjiResult = decodeKanji(stream, size); | ||
@@ -257,3 +237,3 @@ result.text += kanjiResult.text; | ||
result.chunks.push({ | ||
type: Mode.Kanji, | ||
type: Mode_1.default.Kanji, | ||
bytes: kanjiResult.bytes, | ||
@@ -260,0 +240,0 @@ text: kanjiResult.text |
@@ -295,3 +295,3 @@ "use strict"; | ||
try { | ||
return decode_1.decode(resultBytes, version.versionNumber); | ||
return decode_1.decode(resultBytes, version.versionNumber, formatInfo.errorCorrectionLevel); | ||
} | ||
@@ -298,0 +298,0 @@ catch (_a) { |
@@ -22,5 +22,5 @@ "use strict"; | ||
var oneThreeDistance = distance(pattern1, pattern3); | ||
var bottomLeft; | ||
var topLeft; | ||
var topRight; | ||
var bottomLeft; | ||
// Assume one closest to other two is B; A and C will just be guesses at first | ||
@@ -358,9 +358,9 @@ if (twoThreeDistance >= oneTwoDistance && twoThreeDistance >= oneThreeDistance) { | ||
return { | ||
alignmentPattern: { x: alignmentPattern.x, y: alignmentPattern.y }, | ||
bottomLeft: { x: bottomLeft.x, y: bottomLeft.y }, | ||
dimension: dimension, | ||
topLeft: { x: topLeft.x, y: topLeft.y }, | ||
topRight: { x: topRight.x, y: topRight.y } | ||
topRight: { x: topRight.x, y: topRight.y }, | ||
bottomLeft: { x: bottomLeft.x, y: bottomLeft.y }, | ||
alignmentPattern: { x: alignmentPattern.x, y: alignmentPattern.y } | ||
}; | ||
} | ||
exports.default = locate; |
@@ -8,2 +8,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var decoder_1 = require("./decoder"); | ||
@@ -23,17 +24,12 @@ var locator_1 = require("./locator"); | ||
} | ||
return { | ||
data: decoded.text, | ||
binary: decoded.bytes, | ||
chunks: decoded.chunks, | ||
location: { | ||
return tslib_1.__assign({}, decoded, { location: { | ||
topLeftCorner: extracted.mappingFunction(0, 0), | ||
topRightCorner: extracted.mappingFunction(location.dimension, 0), | ||
bottomLeftCorner: extracted.mappingFunction(0, location.dimension), | ||
bottomRightCorner: extracted.mappingFunction(location.dimension, location.dimension), | ||
topLeftFinderPattern: location.topLeft, | ||
topRightFinderPattern: location.topRight, | ||
bottomLeftFinderPattern: location.bottomLeft, | ||
bottomRightAlignmentPattern: location.alignmentPattern, | ||
topLeftCorner: extracted.mappingFunction(0, 0), | ||
topRightCorner: extracted.mappingFunction(location.dimension, 0), | ||
bottomLeftCorner: extracted.mappingFunction(0, location.dimension), | ||
bottomRightCorner: extracted.mappingFunction(location.dimension, location.dimension) | ||
} | ||
}; | ||
bottomRightAlignmentPattern: decoded.version > 7 ? location.alignmentPattern : null | ||
} }); | ||
} | ||
@@ -59,7 +55,3 @@ var defaultOptions = { | ||
options = options || {}; | ||
Object.keys(defaultOptions).forEach(function (key) { | ||
// Sad implementation of Object.assign since we target es5 not es6 | ||
options[key] = key in options ? options[key] : defaultOptions[key]; | ||
}); | ||
this.options = options; | ||
this.options = tslib_1.__assign({}, defaultOptions, options); | ||
}; | ||
@@ -66,0 +58,0 @@ /** |
@@ -9,4 +9,4 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
var Mode_1 = require("./Mode"); | ||
var QRData_1 = require("./QRData"); | ||
var Mode_1 = require("../common/Mode"); | ||
var QRAlphanumeric = /** @class */ (function (_super) { | ||
@@ -13,0 +13,0 @@ tslib_1.__extends(QRAlphanumeric, _super); |
@@ -9,4 +9,4 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
var Mode_1 = require("./Mode"); | ||
var QRData_1 = require("./QRData"); | ||
var Mode_1 = require("../common/Mode"); | ||
var UTF8_1 = require("../../encoding/UTF8"); | ||
@@ -13,0 +13,0 @@ var QRByte = /** @class */ (function (_super) { |
@@ -15,3 +15,3 @@ "use strict"; | ||
var GIFImage_1 = require("../../image/GIFImage"); | ||
var ErrorCorrectLevel_1 = require("./ErrorCorrectLevel"); | ||
var ErrorCorrectionLevel_1 = require("../common/ErrorCorrectionLevel"); | ||
var toString = Object.prototype.toString; | ||
@@ -32,3 +32,3 @@ function createNumArray(length) { | ||
this.autoVersion = this.version === 0; | ||
this.errorCorrectLevel = ErrorCorrectLevel_1.default.L; | ||
this.errorCorrectionLevel = ErrorCorrectionLevel_1.default.L; | ||
} | ||
@@ -69,20 +69,20 @@ /** | ||
* @public | ||
* @method getErrorCorrectLevel | ||
* @returns {ErrorCorrectLevel} | ||
* @method getErrorCorrectionLevel | ||
* @returns {ErrorCorrectionLevel} | ||
*/ | ||
QRCode.prototype.getErrorCorrectLevel = function () { | ||
return this.errorCorrectLevel; | ||
QRCode.prototype.getErrorCorrectionLevel = function () { | ||
return this.errorCorrectionLevel; | ||
}; | ||
/** | ||
* @public | ||
* @method setErrorCorrectLevel | ||
* @param {ErrorCorrectLevel} errorCorrectLevel | ||
* @method setErrorCorrectionLevel | ||
* @param {ErrorCorrectionLevel} errorCorrectionLevel | ||
*/ | ||
QRCode.prototype.setErrorCorrectLevel = function (errorCorrectLevel) { | ||
switch (errorCorrectLevel) { | ||
case ErrorCorrectLevel_1.default.L: | ||
case ErrorCorrectLevel_1.default.M: | ||
case ErrorCorrectLevel_1.default.Q: | ||
case ErrorCorrectLevel_1.default.H: | ||
this.errorCorrectLevel = errorCorrectLevel; | ||
QRCode.prototype.setErrorCorrectionLevel = function (errorCorrectionLevel) { | ||
switch (errorCorrectionLevel) { | ||
case ErrorCorrectionLevel_1.default.L: | ||
case ErrorCorrectionLevel_1.default.M: | ||
case ErrorCorrectionLevel_1.default.Q: | ||
case ErrorCorrectionLevel_1.default.H: | ||
this.errorCorrectionLevel = errorCorrectionLevel; | ||
} | ||
@@ -190,3 +190,3 @@ }; | ||
QRCode.prototype.setupFormatInfo = function (test, maskPattern) { | ||
var data = (this.errorCorrectLevel << 3) | maskPattern; | ||
var data = (this.errorCorrectionLevel << 3) | maskPattern; | ||
var bits = QRUtil.getBCHVersionInfo(data); | ||
@@ -227,6 +227,6 @@ for (var i = 0; i < 15; i++) { | ||
}; | ||
QRCode.prepareData = function (version, errorCorrectLevel, dataList) { | ||
QRCode.prepareData = function (version, errorCorrectionLevel, dataList) { | ||
var dLength = dataList.length; | ||
var buffer = new BitBuffer_1.default(); | ||
var rsBlocks = RSBlock_1.default.getRSBlocks(version, errorCorrectLevel); | ||
var rsBlocks = RSBlock_1.default.getRSBlocks(version, errorCorrectionLevel); | ||
for (var i = 0; i < dLength; i++) { | ||
@@ -267,3 +267,3 @@ var data = dataList[i]; | ||
offset += dcCount; | ||
var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount); | ||
var rsPoly = QRUtil.getErrorCorrectionPolynomial(ecCount); | ||
var rawPoly = new Polynomial_1.default(dcData[r], rsPoly.getLength() - 1); | ||
@@ -407,6 +407,6 @@ var modPoly = rawPoly.mod(rsPoly); | ||
var dataList = this.dataList; | ||
var errorCorrectLevel = this.errorCorrectLevel; | ||
var errorCorrectionLevel = this.errorCorrectionLevel; | ||
if (this.autoVersion) { | ||
for (this.version = 1; this.version <= 40; this.version++) { | ||
_a = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2]; | ||
_a = QRCode.prepareData(this.version, errorCorrectionLevel, dataList), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2]; | ||
if (buffer.getLengthInBits() <= maxDataCount) | ||
@@ -417,3 +417,3 @@ break; | ||
else { | ||
_b = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2]; | ||
_b = QRCode.prepareData(this.version, errorCorrectionLevel, dataList), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2]; | ||
} | ||
@@ -420,0 +420,0 @@ // calc module count |
@@ -8,3 +8,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Mode_1 = require("./Mode"); | ||
var Mode_1 = require("../common/Mode"); | ||
var QRData = /** @class */ (function () { | ||
@@ -11,0 +11,0 @@ function QRData(mode, data) { |
@@ -10,4 +10,4 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
var Mode_1 = require("./Mode"); | ||
var QRData_1 = require("./QRData"); | ||
var Mode_1 = require("../common/Mode"); | ||
var SJIS_1 = require("../../encoding/SJIS"); | ||
@@ -14,0 +14,0 @@ function createCharError(index, data) { |
@@ -9,4 +9,4 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
var Mode_1 = require("./Mode"); | ||
var QRData_1 = require("./QRData"); | ||
var Mode_1 = require("../common/Mode"); | ||
var QRNumeric = /** @class */ (function (_super) { | ||
@@ -13,0 +13,0 @@ tslib_1.__extends(QRNumeric, _super); |
@@ -60,5 +60,5 @@ "use strict"; | ||
exports.getAlignmentPattern = getAlignmentPattern; | ||
function getErrorCorrectPolynomial(errorCorrectLength) { | ||
function getErrorCorrectionPolynomial(errorCorrectionLength) { | ||
var e = new Polynomial_1.default([1]); | ||
for (var i = 0; i < errorCorrectLength; i++) { | ||
for (var i = 0; i < errorCorrectionLength; i++) { | ||
e = e.multiply(new Polynomial_1.default([1, QRMath.gexp(i)])); | ||
@@ -68,3 +68,3 @@ } | ||
} | ||
exports.getErrorCorrectPolynomial = getErrorCorrectPolynomial; | ||
exports.getErrorCorrectionPolynomial = getErrorCorrectionPolynomial; | ||
function getMaskFunc(maskPattern) { | ||
@@ -71,0 +71,0 @@ switch (maskPattern) { |
@@ -8,3 +8,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ErrorCorrectLevel_1 = require("./ErrorCorrectLevel"); | ||
var ErrorCorrectionLevel_1 = require("../common/ErrorCorrectionLevel"); | ||
var RSBlock = /** @class */ (function () { | ||
@@ -21,5 +21,5 @@ function RSBlock(totalCount, dataCount) { | ||
}; | ||
RSBlock.getRSBlocks = function (version, errorCorrectLevel) { | ||
RSBlock.getRSBlocks = function (version, errorCorrectionLevel) { | ||
var rsBlocks = []; | ||
var rsBlock = RSBlock.getRSBlockTable(version, errorCorrectLevel); | ||
var rsBlock = RSBlock.getRSBlockTable(version, errorCorrectionLevel); | ||
var length = rsBlock.length / 3; | ||
@@ -36,14 +36,14 @@ for (var i = 0; i < length; i++) { | ||
}; | ||
RSBlock.getRSBlockTable = function (version, errorCorrectLevel) { | ||
switch (errorCorrectLevel) { | ||
case ErrorCorrectLevel_1.default.L: | ||
RSBlock.getRSBlockTable = function (version, errorCorrectionLevel) { | ||
switch (errorCorrectionLevel) { | ||
case ErrorCorrectionLevel_1.default.L: | ||
return RSBlock.RS_BLOCK_TABLE[(version - 1) * 4 + 0]; | ||
case ErrorCorrectLevel_1.default.M: | ||
case ErrorCorrectionLevel_1.default.M: | ||
return RSBlock.RS_BLOCK_TABLE[(version - 1) * 4 + 1]; | ||
case ErrorCorrectLevel_1.default.Q: | ||
case ErrorCorrectionLevel_1.default.Q: | ||
return RSBlock.RS_BLOCK_TABLE[(version - 1) * 4 + 2]; | ||
case ErrorCorrectLevel_1.default.H: | ||
case ErrorCorrectionLevel_1.default.H: | ||
return RSBlock.RS_BLOCK_TABLE[(version - 1) * 4 + 3]; | ||
default: | ||
throw "illegal error correct level: " + errorCorrectLevel; | ||
throw "illegal error correction level: " + errorCorrectionLevel; | ||
} | ||
@@ -50,0 +50,0 @@ }; |
@@ -6,2 +6,3 @@ /** | ||
*/ | ||
export { default as Mode } from './qrcode/common/Mode'; | ||
export { default as QRByte } from './qrcode/encoder/QRByte'; | ||
@@ -13,2 +14,2 @@ export { default as Encoder } from './qrcode/encoder/QRCode'; | ||
export { default as QRAlphanumeric } from './qrcode/encoder/QRAlphanumeric'; | ||
export { default as ErrorCorrectLevel } from './qrcode/encoder/ErrorCorrectLevel'; | ||
export { default as ErrorCorrectionLevel } from './qrcode/common/ErrorCorrectionLevel'; |
@@ -8,24 +8,4 @@ /** | ||
import BitStream from './BitStream'; | ||
import Mode from '../../../common/Mode'; | ||
import { UTF2SJISTable } from '../../../../encoding/SJIS'; | ||
var Mode; | ||
(function (Mode) { | ||
Mode["Numeric"] = "numeric"; | ||
Mode["Alphanumeric"] = "alphanumeric"; | ||
Mode["StructuredAppend"] = "structuredappend"; | ||
Mode["Byte"] = "byte"; | ||
Mode["Kanji"] = "kanji"; | ||
Mode["ECI"] = "eci"; | ||
})(Mode || (Mode = {})); | ||
var ModeByte; | ||
(function (ModeByte) { | ||
ModeByte[ModeByte["Terminator"] = 0] = "Terminator"; | ||
ModeByte[ModeByte["Numeric"] = 1] = "Numeric"; | ||
ModeByte[ModeByte["Alphanumeric"] = 2] = "Alphanumeric"; | ||
ModeByte[ModeByte["StructuredAppend"] = 3] = "StructuredAppend"; | ||
ModeByte[ModeByte["Byte"] = 4] = "Byte"; | ||
ModeByte[ModeByte["Kanji"] = 8] = "Kanji"; | ||
ModeByte[ModeByte["ECI"] = 7] = "ECI"; | ||
// FNC1FirstPosition = 0x5, | ||
// FNC1SecondPosition = 0x9 | ||
})(ModeByte || (ModeByte = {})); | ||
function decodeNumeric(stream, size) { | ||
@@ -100,3 +80,3 @@ var text = ''; | ||
* @function bytesToUTF8 | ||
* @param bytes | ||
* @param {number[]} bytes | ||
* @returns {string} | ||
@@ -163,3 +143,3 @@ * @see https://github.com/google/closure-library/blob/master/closure/goog/crypt/crypt.js | ||
} | ||
export function decode(data, version) { | ||
export function decode(data, version, errorCorrectionLevel) { | ||
var _a, _b, _c, _d; | ||
@@ -169,9 +149,9 @@ var stream = new BitStream(data); | ||
var size = version <= 9 ? 0 : version <= 26 ? 1 : 2; | ||
var result = { text: '', bytes: [], chunks: [] }; | ||
var result = { text: '', bytes: [], chunks: [], version: version, errorCorrectionLevel: errorCorrectionLevel }; | ||
while (stream.available() >= 4) { | ||
var mode = stream.readBits(4); | ||
if (mode === ModeByte.Terminator) { | ||
if (mode === Mode.Terminator) { | ||
return result; | ||
} | ||
else if (mode === ModeByte.ECI) { | ||
else if (mode === Mode.ECI) { | ||
if (stream.readBits(1) === 0) { | ||
@@ -203,3 +183,3 @@ result.chunks.push({ | ||
} | ||
else if (mode === ModeByte.Numeric) { | ||
else if (mode === Mode.Numeric) { | ||
var numericResult = decodeNumeric(stream, size); | ||
@@ -213,3 +193,3 @@ result.text += numericResult.text; | ||
} | ||
else if (mode === ModeByte.Alphanumeric) { | ||
else if (mode === Mode.Alphanumeric) { | ||
var alphanumericResult = decodeAlphanumeric(stream, size); | ||
@@ -223,3 +203,3 @@ result.text += alphanumericResult.text; | ||
} | ||
else if (mode === ModeByte.StructuredAppend) { | ||
else if (mode === Mode.StructuredAppend) { | ||
// QR Standard section 9.2: | ||
@@ -234,3 +214,3 @@ // > The 4-bit patterns shall be the binary equivalents of (m - 1) and (n - 1) respectively. | ||
} | ||
else if (mode === ModeByte.Byte) { | ||
else if (mode === Mode.Byte) { | ||
var byteResult = decodeByte(stream, size); | ||
@@ -245,3 +225,3 @@ result.text += byteResult.text; | ||
} | ||
else if (mode === ModeByte.Kanji) { | ||
else if (mode === Mode.Kanji) { | ||
var kanjiResult = decodeKanji(stream, size); | ||
@@ -248,0 +228,0 @@ result.text += kanjiResult.text; |
@@ -293,3 +293,3 @@ /** | ||
try { | ||
return decodeBytes(resultBytes, version.versionNumber); | ||
return decodeBytes(resultBytes, version.versionNumber, formatInfo.errorCorrectionLevel); | ||
} | ||
@@ -296,0 +296,0 @@ catch (_a) { |
@@ -20,5 +20,5 @@ /** | ||
var oneThreeDistance = distance(pattern1, pattern3); | ||
var bottomLeft; | ||
var topLeft; | ||
var topRight; | ||
var bottomLeft; | ||
// Assume one closest to other two is B; A and C will just be guesses at first | ||
@@ -356,8 +356,8 @@ if (twoThreeDistance >= oneTwoDistance && twoThreeDistance >= oneThreeDistance) { | ||
return { | ||
alignmentPattern: { x: alignmentPattern.x, y: alignmentPattern.y }, | ||
bottomLeft: { x: bottomLeft.x, y: bottomLeft.y }, | ||
dimension: dimension, | ||
topLeft: { x: topLeft.x, y: topLeft.y }, | ||
topRight: { x: topRight.x, y: topRight.y } | ||
topRight: { x: topRight.x, y: topRight.y }, | ||
bottomLeft: { x: bottomLeft.x, y: bottomLeft.y }, | ||
alignmentPattern: { x: alignmentPattern.x, y: alignmentPattern.y } | ||
}; | ||
} |
@@ -6,2 +6,3 @@ /** | ||
*/ | ||
import * as tslib_1 from "tslib"; | ||
import decodeQRCode from './decoder'; | ||
@@ -21,17 +22,12 @@ import locate from './locator'; | ||
} | ||
return { | ||
data: decoded.text, | ||
binary: decoded.bytes, | ||
chunks: decoded.chunks, | ||
location: { | ||
return tslib_1.__assign({}, decoded, { location: { | ||
topLeftCorner: extracted.mappingFunction(0, 0), | ||
topRightCorner: extracted.mappingFunction(location.dimension, 0), | ||
bottomLeftCorner: extracted.mappingFunction(0, location.dimension), | ||
bottomRightCorner: extracted.mappingFunction(location.dimension, location.dimension), | ||
topLeftFinderPattern: location.topLeft, | ||
topRightFinderPattern: location.topRight, | ||
bottomLeftFinderPattern: location.bottomLeft, | ||
bottomRightAlignmentPattern: location.alignmentPattern, | ||
topLeftCorner: extracted.mappingFunction(0, 0), | ||
topRightCorner: extracted.mappingFunction(location.dimension, 0), | ||
bottomLeftCorner: extracted.mappingFunction(0, location.dimension), | ||
bottomRightCorner: extracted.mappingFunction(location.dimension, location.dimension) | ||
} | ||
}; | ||
bottomRightAlignmentPattern: decoded.version > 7 ? location.alignmentPattern : null | ||
} }); | ||
} | ||
@@ -57,7 +53,3 @@ var defaultOptions = { | ||
options = options || {}; | ||
Object.keys(defaultOptions).forEach(function (key) { | ||
// Sad implementation of Object.assign since we target es5 not es6 | ||
options[key] = key in options ? options[key] : defaultOptions[key]; | ||
}); | ||
this.options = options; | ||
this.options = tslib_1.__assign({}, defaultOptions, options); | ||
}; | ||
@@ -64,0 +56,0 @@ /** |
@@ -7,4 +7,4 @@ /** | ||
import * as tslib_1 from "tslib"; | ||
import Mode from './Mode'; | ||
import QRData from './QRData'; | ||
import Mode from '../common/Mode'; | ||
var QRAlphanumeric = /** @class */ (function (_super) { | ||
@@ -11,0 +11,0 @@ tslib_1.__extends(QRAlphanumeric, _super); |
@@ -7,4 +7,4 @@ /** | ||
import * as tslib_1 from "tslib"; | ||
import Mode from './Mode'; | ||
import QRData from './QRData'; | ||
import Mode from '../common/Mode'; | ||
import stringToBytes from '../../encoding/UTF8'; | ||
@@ -11,0 +11,0 @@ var QRByte = /** @class */ (function (_super) { |
@@ -13,3 +13,3 @@ /** | ||
import GIFImage from '../../image/GIFImage'; | ||
import ErrorCorrectLevel from './ErrorCorrectLevel'; | ||
import ErrorCorrectionLevel from '../common/ErrorCorrectionLevel'; | ||
var toString = Object.prototype.toString; | ||
@@ -30,3 +30,3 @@ function createNumArray(length) { | ||
this.autoVersion = this.version === 0; | ||
this.errorCorrectLevel = ErrorCorrectLevel.L; | ||
this.errorCorrectionLevel = ErrorCorrectionLevel.L; | ||
} | ||
@@ -67,20 +67,20 @@ /** | ||
* @public | ||
* @method getErrorCorrectLevel | ||
* @returns {ErrorCorrectLevel} | ||
* @method getErrorCorrectionLevel | ||
* @returns {ErrorCorrectionLevel} | ||
*/ | ||
QRCode.prototype.getErrorCorrectLevel = function () { | ||
return this.errorCorrectLevel; | ||
QRCode.prototype.getErrorCorrectionLevel = function () { | ||
return this.errorCorrectionLevel; | ||
}; | ||
/** | ||
* @public | ||
* @method setErrorCorrectLevel | ||
* @param {ErrorCorrectLevel} errorCorrectLevel | ||
* @method setErrorCorrectionLevel | ||
* @param {ErrorCorrectionLevel} errorCorrectionLevel | ||
*/ | ||
QRCode.prototype.setErrorCorrectLevel = function (errorCorrectLevel) { | ||
switch (errorCorrectLevel) { | ||
case ErrorCorrectLevel.L: | ||
case ErrorCorrectLevel.M: | ||
case ErrorCorrectLevel.Q: | ||
case ErrorCorrectLevel.H: | ||
this.errorCorrectLevel = errorCorrectLevel; | ||
QRCode.prototype.setErrorCorrectionLevel = function (errorCorrectionLevel) { | ||
switch (errorCorrectionLevel) { | ||
case ErrorCorrectionLevel.L: | ||
case ErrorCorrectionLevel.M: | ||
case ErrorCorrectionLevel.Q: | ||
case ErrorCorrectionLevel.H: | ||
this.errorCorrectionLevel = errorCorrectionLevel; | ||
} | ||
@@ -188,3 +188,3 @@ }; | ||
QRCode.prototype.setupFormatInfo = function (test, maskPattern) { | ||
var data = (this.errorCorrectLevel << 3) | maskPattern; | ||
var data = (this.errorCorrectionLevel << 3) | maskPattern; | ||
var bits = QRUtil.getBCHVersionInfo(data); | ||
@@ -225,6 +225,6 @@ for (var i = 0; i < 15; i++) { | ||
}; | ||
QRCode.prepareData = function (version, errorCorrectLevel, dataList) { | ||
QRCode.prepareData = function (version, errorCorrectionLevel, dataList) { | ||
var dLength = dataList.length; | ||
var buffer = new BitBuffer(); | ||
var rsBlocks = RSBlock.getRSBlocks(version, errorCorrectLevel); | ||
var rsBlocks = RSBlock.getRSBlocks(version, errorCorrectionLevel); | ||
for (var i = 0; i < dLength; i++) { | ||
@@ -265,3 +265,3 @@ var data = dataList[i]; | ||
offset += dcCount; | ||
var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount); | ||
var rsPoly = QRUtil.getErrorCorrectionPolynomial(ecCount); | ||
var rawPoly = new Polynomial(dcData[r], rsPoly.getLength() - 1); | ||
@@ -405,6 +405,6 @@ var modPoly = rawPoly.mod(rsPoly); | ||
var dataList = this.dataList; | ||
var errorCorrectLevel = this.errorCorrectLevel; | ||
var errorCorrectionLevel = this.errorCorrectionLevel; | ||
if (this.autoVersion) { | ||
for (this.version = 1; this.version <= 40; this.version++) { | ||
_a = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2]; | ||
_a = QRCode.prepareData(this.version, errorCorrectionLevel, dataList), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2]; | ||
if (buffer.getLengthInBits() <= maxDataCount) | ||
@@ -415,3 +415,3 @@ break; | ||
else { | ||
_b = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2]; | ||
_b = QRCode.prepareData(this.version, errorCorrectionLevel, dataList), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2]; | ||
} | ||
@@ -418,0 +418,0 @@ // calc module count |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
import Mode from './Mode'; | ||
import Mode from '../common/Mode'; | ||
var QRData = /** @class */ (function () { | ||
@@ -9,0 +9,0 @@ function QRData(mode, data) { |
@@ -8,4 +8,4 @@ /** | ||
import * as tslib_1 from "tslib"; | ||
import Mode from './Mode'; | ||
import QRData from './QRData'; | ||
import Mode from '../common/Mode'; | ||
import stringToBytes from '../../encoding/SJIS'; | ||
@@ -12,0 +12,0 @@ function createCharError(index, data) { |
@@ -7,4 +7,4 @@ /** | ||
import * as tslib_1 from "tslib"; | ||
import Mode from './Mode'; | ||
import QRData from './QRData'; | ||
import Mode from '../common/Mode'; | ||
var QRNumeric = /** @class */ (function (_super) { | ||
@@ -11,0 +11,0 @@ tslib_1.__extends(QRNumeric, _super); |
@@ -57,5 +57,5 @@ /** | ||
} | ||
export function getErrorCorrectPolynomial(errorCorrectLength) { | ||
export function getErrorCorrectionPolynomial(errorCorrectionLength) { | ||
var e = new Polynomial([1]); | ||
for (var i = 0; i < errorCorrectLength; i++) { | ||
for (var i = 0; i < errorCorrectionLength; i++) { | ||
e = e.multiply(new Polynomial([1, QRMath.gexp(i)])); | ||
@@ -62,0 +62,0 @@ } |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
import ErrorCorrectLevel from './ErrorCorrectLevel'; | ||
import ErrorCorrectionLevel from '../common/ErrorCorrectionLevel'; | ||
var RSBlock = /** @class */ (function () { | ||
@@ -19,5 +19,5 @@ function RSBlock(totalCount, dataCount) { | ||
}; | ||
RSBlock.getRSBlocks = function (version, errorCorrectLevel) { | ||
RSBlock.getRSBlocks = function (version, errorCorrectionLevel) { | ||
var rsBlocks = []; | ||
var rsBlock = RSBlock.getRSBlockTable(version, errorCorrectLevel); | ||
var rsBlock = RSBlock.getRSBlockTable(version, errorCorrectionLevel); | ||
var length = rsBlock.length / 3; | ||
@@ -34,14 +34,14 @@ for (var i = 0; i < length; i++) { | ||
}; | ||
RSBlock.getRSBlockTable = function (version, errorCorrectLevel) { | ||
switch (errorCorrectLevel) { | ||
case ErrorCorrectLevel.L: | ||
RSBlock.getRSBlockTable = function (version, errorCorrectionLevel) { | ||
switch (errorCorrectionLevel) { | ||
case ErrorCorrectionLevel.L: | ||
return RSBlock.RS_BLOCK_TABLE[(version - 1) * 4 + 0]; | ||
case ErrorCorrectLevel.M: | ||
case ErrorCorrectionLevel.M: | ||
return RSBlock.RS_BLOCK_TABLE[(version - 1) * 4 + 1]; | ||
case ErrorCorrectLevel.Q: | ||
case ErrorCorrectionLevel.Q: | ||
return RSBlock.RS_BLOCK_TABLE[(version - 1) * 4 + 2]; | ||
case ErrorCorrectLevel.H: | ||
case ErrorCorrectionLevel.H: | ||
return RSBlock.RS_BLOCK_TABLE[(version - 1) * 4 + 3]; | ||
default: | ||
throw "illegal error correct level: " + errorCorrectLevel; | ||
throw "illegal error correction level: " + errorCorrectionLevel; | ||
} | ||
@@ -48,0 +48,0 @@ }; |
{ | ||
"name": "@nuintun/qrcode", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"description": "QRCode encode and decode library.", | ||
@@ -5,0 +5,0 @@ "main": "es5/index.js", |
@@ -6,2 +6,3 @@ /** | ||
*/ | ||
export { default as Mode } from './qrcode/common/Mode'; | ||
export { default as QRByte } from './qrcode/encoder/QRByte'; | ||
@@ -13,2 +14,2 @@ export { default as Encoder } from './qrcode/encoder/QRCode'; | ||
export { default as QRAlphanumeric } from './qrcode/encoder/QRAlphanumeric'; | ||
export { default as ErrorCorrectLevel } from './qrcode/encoder/ErrorCorrectLevel'; | ||
export { default as ErrorCorrectionLevel } from './qrcode/common/ErrorCorrectionLevel'; |
@@ -6,2 +6,4 @@ /** | ||
*/ | ||
import Mode from '../../../common/Mode'; | ||
import ErrorCorrectionLevel from '../../../common/ErrorCorrectionLevel'; | ||
interface Chunk { | ||
@@ -27,3 +29,2 @@ type: Mode; | ||
} | ||
export declare type Chunks = Array<Chunk | ByteChunk | ECIChunk | StructuredAppendChunk>; | ||
interface DecodeData { | ||
@@ -33,14 +34,9 @@ text: string; | ||
} | ||
declare type Chunks = Array<Chunk | ByteChunk | ECIChunk | StructuredAppendChunk>; | ||
export interface DecodeResult extends DecodeData { | ||
chunks: Chunks; | ||
version: number; | ||
errorCorrectionLevel: ErrorCorrectionLevel; | ||
} | ||
declare enum Mode { | ||
Numeric = "numeric", | ||
Alphanumeric = "alphanumeric", | ||
StructuredAppend = "structuredappend", | ||
Byte = "byte", | ||
Kanji = "kanji", | ||
ECI = "eci" | ||
} | ||
export declare function decode(data: Uint8ClampedArray, version: number): DecodeResult; | ||
export declare function decode(data: Uint8ClampedArray, version: number, errorCorrectionLevel: ErrorCorrectionLevel): DecodeResult; | ||
export {}; |
@@ -9,8 +9,8 @@ /** | ||
export interface QRLocation { | ||
topLeft: Point; | ||
topRight: Point; | ||
bottomLeft: Point; | ||
topLeft: Point; | ||
dimension: number; | ||
alignmentPattern: Point; | ||
dimension: number; | ||
} | ||
export default function locate(matrix: BitMatrix): QRLocation; |
@@ -7,7 +7,4 @@ /** | ||
import Point from './Point'; | ||
import { Chunks } from './decoder/decode'; | ||
export interface DecoderResult { | ||
data: string; | ||
chunks: Chunks; | ||
binary: number[]; | ||
import { DecodeResult } from './decoder/decode'; | ||
export interface DecoderResult extends DecodeResult { | ||
location: { | ||
@@ -21,3 +18,3 @@ topLeftCorner: Point; | ||
bottomLeftFinderPattern: Point; | ||
bottomRightAlignmentPattern?: Point; | ||
bottomRightAlignmentPattern: Point | null; | ||
}; | ||
@@ -24,0 +21,0 @@ } |
@@ -7,3 +7,3 @@ /** | ||
import QRData from './QRData'; | ||
import ErrorCorrectLevel from './ErrorCorrectLevel'; | ||
import ErrorCorrectionLevel from '../common/ErrorCorrectionLevel'; | ||
export default class QRCode { | ||
@@ -17,3 +17,3 @@ private static PAD0; | ||
private autoVersion; | ||
private errorCorrectLevel; | ||
private errorCorrectionLevel; | ||
/** | ||
@@ -44,12 +44,12 @@ * @public | ||
* @public | ||
* @method getErrorCorrectLevel | ||
* @returns {ErrorCorrectLevel} | ||
* @method getErrorCorrectionLevel | ||
* @returns {ErrorCorrectionLevel} | ||
*/ | ||
getErrorCorrectLevel(): ErrorCorrectLevel; | ||
getErrorCorrectionLevel(): ErrorCorrectionLevel; | ||
/** | ||
* @public | ||
* @method setErrorCorrectLevel | ||
* @param {ErrorCorrectLevel} errorCorrectLevel | ||
* @method setErrorCorrectionLevel | ||
* @param {ErrorCorrectionLevel} errorCorrectionLevel | ||
*/ | ||
setErrorCorrectLevel(errorCorrectLevel: ErrorCorrectLevel): void; | ||
setErrorCorrectionLevel(errorCorrectionLevel: ErrorCorrectionLevel): void; | ||
/** | ||
@@ -56,0 +56,0 @@ * @public |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
import Mode from './Mode'; | ||
import Mode from '../common/Mode'; | ||
import BitBuffer from './BitBuffer'; | ||
@@ -9,0 +9,0 @@ export default abstract class QRData { |
@@ -13,3 +13,3 @@ /** | ||
export declare function getAlignmentPattern(version: number): number[]; | ||
export declare function getErrorCorrectPolynomial(errorCorrectLength: number): Polynomial; | ||
export declare function getErrorCorrectionPolynomial(errorCorrectionLength: number): Polynomial; | ||
export declare function getMaskFunc(maskPattern: number): maskFunc; | ||
@@ -16,0 +16,0 @@ /** |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
import ErrorCorrectLevel from './ErrorCorrectLevel'; | ||
import ErrorCorrectionLevel from '../common/ErrorCorrectionLevel'; | ||
export default class RSBlock { | ||
@@ -15,4 +15,4 @@ private static RS_BLOCK_TABLE; | ||
getTotalCount(): number; | ||
static getRSBlocks(version: number, errorCorrectLevel: ErrorCorrectLevel): RSBlock[]; | ||
static getRSBlocks(version: number, errorCorrectionLevel: ErrorCorrectionLevel): RSBlock[]; | ||
private static getRSBlockTable; | ||
} |
437991
10404