{"version":3,"file":"vendors-798bcfdb.f584a1446b2fc034d810.bundle.js","mappings":"AA0BA","sources":["webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/detector/Detector.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/ASCIIEncoder.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/Base256Encoder.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/C40Encoder.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/DefaultPlacement.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/EdifactEncoder.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/EncoderContext.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/ErrorCorrection.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/HighLevelEncoder.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/SymbolInfo.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/TextEncoder.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/X12Encoder.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/constants.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/datamatrix/encoder/MinimalEncoder.js","webpack://lernplattform-admin-frontend/../common/node_modules/@zxing/library/esm/core/oned/AbstractUPCEANReader.js"],"sourcesContent":["import WhiteRectangleDetector from '../../common/detector/WhiteRectangleDetector';\nimport DetectorResult from '../../common/DetectorResult';\nimport GridSamplerInstance from '../../common/GridSamplerInstance';\nimport NotFoundException from '../../NotFoundException';\nimport ResultPoint from '../../ResultPoint';\n/*\n * Copyright 2008 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/**\n * <p>Encapsulates logic that can detect a Data Matrix Code in an image, even if the Data Matrix Code\n * is rotated or skewed, or partially obscured.</p>\n *\n * @author Sean Owen\n */\nvar Detector = /** @class */ (function () {\n    function Detector(image) {\n        this.image = image;\n        this.rectangleDetector = new WhiteRectangleDetector(this.image);\n    }\n    /**\n     * <p>Detects a Data Matrix Code in an image.</p>\n     *\n     * @return {@link DetectorResult} encapsulating results of detecting a Data Matrix Code\n     * @throws NotFoundException if no Data Matrix Code can be found\n     */\n    Detector.prototype.detect = function () {\n        var cornerPoints = this.rectangleDetector.detect();\n        var points = this.detectSolid1(cornerPoints);\n        points = this.detectSolid2(points);\n        points[3] = this.correctTopRight(points);\n        if (!points[3]) {\n            throw new NotFoundException();\n        }\n        points = this.shiftToModuleCenter(points);\n        var topLeft = points[0];\n        var bottomLeft = points[1];\n        var bottomRight = points[2];\n        var topRight = points[3];\n        var dimensionTop = this.transitionsBetween(topLeft, topRight) + 1;\n        var dimensionRight = this.transitionsBetween(bottomRight, topRight) + 1;\n        if ((dimensionTop & 0x01) === 1) {\n            dimensionTop += 1;\n        }\n        if ((dimensionRight & 0x01) === 1) {\n            dimensionRight += 1;\n        }\n        if (4 * dimensionTop < 7 * dimensionRight && 4 * dimensionRight < 7 * dimensionTop) {\n            // The matrix is square\n            dimensionTop = dimensionRight = Math.max(dimensionTop, dimensionRight);\n        }\n        var bits = Detector.sampleGrid(this.image, topLeft, bottomLeft, bottomRight, topRight, dimensionTop, dimensionRight);\n        return new DetectorResult(bits, [topLeft, bottomLeft, bottomRight, topRight]);\n    };\n    Detector.shiftPoint = function (point, to, div) {\n        var x = (to.getX() - point.getX()) / (div + 1);\n        var y = (to.getY() - point.getY()) / (div + 1);\n        return new ResultPoint(point.getX() + x, point.getY() + y);\n    };\n    Detector.moveAway = function (point, fromX, fromY) {\n        var x = point.getX();\n        var y = point.getY();\n        if (x < fromX) {\n            x -= 1;\n        }\n        else {\n            x += 1;\n        }\n        if (y < fromY) {\n            y -= 1;\n        }\n        else {\n            y += 1;\n        }\n        return new ResultPoint(x, y);\n    };\n    /**\n     * Detect a solid side which has minimum transition.\n     */\n    Detector.prototype.detectSolid1 = function (cornerPoints) {\n        // 0  2\n        // 1  3\n        var pointA = cornerPoints[0];\n        var pointB = cornerPoints[1];\n        var pointC = cornerPoints[3];\n        var pointD = cornerPoints[2];\n        var trAB = this.transitionsBetween(pointA, pointB);\n        var trBC = this.transitionsBetween(pointB, pointC);\n        var trCD = this.transitionsBetween(pointC, pointD);\n        var trDA = this.transitionsBetween(pointD, pointA);\n        // 0..3\n        // :  :\n        // 1--2\n        var min = trAB;\n        var points = [pointD, pointA, pointB, pointC];\n        if (min > trBC) {\n            min = trBC;\n            points[0] = pointA;\n            points[1] = pointB;\n            points[2] = pointC;\n            points[3] = pointD;\n        }\n        if (min > trCD) {\n            min = trCD;\n            points[0] = pointB;\n            points[1] = pointC;\n            points[2] = pointD;\n            points[3] = pointA;\n        }\n        if (min > trDA) {\n            points[0] = pointC;\n            points[1] = pointD;\n            points[2] = pointA;\n            points[3] = pointB;\n        }\n        return points;\n    };\n    /**\n     * Detect a second solid side next to first solid side.\n     */\n    Detector.prototype.detectSolid2 = function (points) {\n        // A..D\n        // :  :\n        // B--C\n        var pointA = points[0];\n        var pointB = points[1];\n        var pointC = points[2];\n        var pointD = points[3];\n        // Transition detection on the edge is not stable.\n        // To safely detect, shift the points to the module center.\n        var tr = this.transitionsBetween(pointA, pointD);\n        var pointBs = Detector.shiftPoint(pointB, pointC, (tr + 1) * 4);\n        var pointCs = Detector.shiftPoint(pointC, pointB, (tr + 1) * 4);\n        var trBA = this.transitionsBetween(pointBs, pointA);\n        var trCD = this.transitionsBetween(pointCs, pointD);\n        // 0..3\n        // |  :\n        // 1--2\n        if (trBA < trCD) {\n            // solid sides: A-B-C\n            points[0] = pointA;\n            points[1] = pointB;\n            points[2] = pointC;\n            points[3] = pointD;\n        }\n        else {\n            // solid sides: B-C-D\n            points[0] = pointB;\n            points[1] = pointC;\n            points[2] = pointD;\n            points[3] = pointA;\n        }\n        return points;\n    };\n    /**\n     * Calculates the corner position of the white top right module.\n     */\n    Detector.prototype.correctTopRight = function (points) {\n        // A..D\n        // |  :\n        // B--C\n        var pointA = points[0];\n        var pointB = points[1];\n        var pointC = points[2];\n        var pointD = points[3];\n        // shift points for safe transition detection.\n        var trTop = this.transitionsBetween(pointA, pointD);\n        var trRight = this.transitionsBetween(pointB, pointD);\n        var pointAs = Detector.shiftPoint(pointA, pointB, (trRight + 1) * 4);\n        var pointCs = Detector.shiftPoint(pointC, pointB, (trTop + 1) * 4);\n        trTop = this.transitionsBetween(pointAs, pointD);\n        trRight = this.transitionsBetween(pointCs, pointD);\n        var candidate1 = new ResultPoint(pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop + 1), pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop + 1));\n        var candidate2 = new ResultPoint(pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight + 1), pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight + 1));\n        if (!this.isValid(candidate1)) {\n            if (this.isValid(candidate2)) {\n                return candidate2;\n            }\n            return null;\n        }\n        if (!this.isValid(candidate2)) {\n            return candidate1;\n        }\n        var sumc1 = this.transitionsBetween(pointAs, candidate1) + this.transitionsBetween(pointCs, candidate1);\n        var sumc2 = this.transitionsBetween(pointAs, candidate2) + this.transitionsBetween(pointCs, candidate2);\n        if (sumc1 > sumc2) {\n            return candidate1;\n        }\n        else {\n            return candidate2;\n        }\n    };\n    /**\n     * Shift the edge points to the module center.\n     */\n    Detector.prototype.shiftToModuleCenter = function (points) {\n        // A..D\n        // |  :\n        // B--C\n        var pointA = points[0];\n        var pointB = points[1];\n        var pointC = points[2];\n        var pointD = points[3];\n        // calculate pseudo dimensions\n        var dimH = this.transitionsBetween(pointA, pointD) + 1;\n        var dimV = this.transitionsBetween(pointC, pointD) + 1;\n        // shift points for safe dimension detection\n        var pointAs = Detector.shiftPoint(pointA, pointB, dimV * 4);\n        var pointCs = Detector.shiftPoint(pointC, pointB, dimH * 4);\n        //  calculate more precise dimensions\n        dimH = this.transitionsBetween(pointAs, pointD) + 1;\n        dimV = this.transitionsBetween(pointCs, pointD) + 1;\n        if ((dimH & 0x01) === 1) {\n            dimH += 1;\n        }\n        if ((dimV & 0x01) === 1) {\n            dimV += 1;\n        }\n        // WhiteRectangleDetector returns points inside of the rectangle.\n        // I want points on the edges.\n        var centerX = (pointA.getX() + pointB.getX() + pointC.getX() + pointD.getX()) / 4;\n        var centerY = (pointA.getY() + pointB.getY() + pointC.getY() + pointD.getY()) / 4;\n        pointA = Detector.moveAway(pointA, centerX, centerY);\n        pointB = Detector.moveAway(pointB, centerX, centerY);\n        pointC = Detector.moveAway(pointC, centerX, centerY);\n        pointD = Detector.moveAway(pointD, centerX, centerY);\n        var pointBs;\n        var pointDs;\n        // shift points to the center of each modules\n        pointAs = Detector.shiftPoint(pointA, pointB, dimV * 4);\n        pointAs = Detector.shiftPoint(pointAs, pointD, dimH * 4);\n        pointBs = Detector.shiftPoint(pointB, pointA, dimV * 4);\n        pointBs = Detector.shiftPoint(pointBs, pointC, dimH * 4);\n        pointCs = Detector.shiftPoint(pointC, pointD, dimV * 4);\n        pointCs = Detector.shiftPoint(pointCs, pointB, dimH * 4);\n        pointDs = Detector.shiftPoint(pointD, pointC, dimV * 4);\n        pointDs = Detector.shiftPoint(pointDs, pointA, dimH * 4);\n        return [pointAs, pointBs, pointCs, pointDs];\n    };\n    Detector.prototype.isValid = function (p) {\n        return p.getX() >= 0 && p.getX() < this.image.getWidth() && p.getY() > 0 && p.getY() < this.image.getHeight();\n    };\n    Detector.sampleGrid = function (image, topLeft, bottomLeft, bottomRight, topRight, dimensionX, dimensionY) {\n        var sampler = GridSamplerInstance.getInstance();\n        return sampler.sampleGrid(image, dimensionX, dimensionY, 0.5, 0.5, dimensionX - 0.5, 0.5, dimensionX - 0.5, dimensionY - 0.5, 0.5, dimensionY - 0.5, topLeft.getX(), topLeft.getY(), topRight.getX(), topRight.getY(), bottomRight.getX(), bottomRight.getY(), bottomLeft.getX(), bottomLeft.getY());\n    };\n    /**\n     * Counts the number of black/white transitions between two points, using something like Bresenham's algorithm.\n     */\n    Detector.prototype.transitionsBetween = function (from, to) {\n        // See QR Code Detector, sizeOfBlackWhiteBlackRun()\n        var fromX = Math.trunc(from.getX());\n        var fromY = Math.trunc(from.getY());\n        var toX = Math.trunc(to.getX());\n        var toY = Math.trunc(to.getY());\n        var steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);\n        if (steep) {\n            var temp = fromX;\n            fromX = fromY;\n            fromY = temp;\n            temp = toX;\n            toX = toY;\n            toY = temp;\n        }\n        var dx = Math.abs(toX - fromX);\n        var dy = Math.abs(toY - fromY);\n        var error = -dx / 2;\n        var ystep = fromY < toY ? 1 : -1;\n        var xstep = fromX < toX ? 1 : -1;\n        var transitions = 0;\n        var inBlack = this.image.get(steep ? fromY : fromX, steep ? fromX : fromY);\n        for (var x = fromX, y = fromY; x !== toX; x += xstep) {\n            var isBlack = this.image.get(steep ? y : x, steep ? x : y);\n            if (isBlack !== inBlack) {\n                transitions++;\n                inBlack = isBlack;\n            }\n            error += dy;\n            if (error > 0) {\n                if (y === toY) {\n                    break;\n                }\n                y += ystep;\n                error -= dx;\n            }\n        }\n        return transitions;\n    };\n    return Detector;\n}());\nexport default Detector;\n","import { ASCII_ENCODATION, BASE256_ENCODATION, C40_ENCODATION, EDIFACT_ENCODATION, LATCH_TO_ANSIX12, LATCH_TO_BASE256, LATCH_TO_C40, LATCH_TO_EDIFACT, LATCH_TO_TEXT, TEXT_ENCODATION, UPPER_SHIFT, X12_ENCODATION, } from './constants';\n// tslint:disable-next-line:no-circular-imports\nimport HighLevelEncoder from './HighLevelEncoder';\nvar ASCIIEncoder = /** @class */ (function () {\n    function ASCIIEncoder() {\n    }\n    ASCIIEncoder.prototype.getEncodingMode = function () {\n        return ASCII_ENCODATION;\n    };\n    ASCIIEncoder.prototype.encode = function (context) {\n        // step B\n        var n = HighLevelEncoder.determineConsecutiveDigitCount(context.getMessage(), context.pos);\n        if (n >= 2) {\n            context.writeCodeword(this.encodeASCIIDigits(context.getMessage().charCodeAt(context.pos), context.getMessage().charCodeAt(context.pos + 1)));\n            context.pos += 2;\n        }\n        else {\n            var c = context.getCurrentChar();\n            var newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, this.getEncodingMode());\n            if (newMode !== this.getEncodingMode()) {\n                switch (newMode) {\n                    case BASE256_ENCODATION:\n                        context.writeCodeword(LATCH_TO_BASE256);\n                        context.signalEncoderChange(BASE256_ENCODATION);\n                        return;\n                    case C40_ENCODATION:\n                        context.writeCodeword(LATCH_TO_C40);\n                        context.signalEncoderChange(C40_ENCODATION);\n                        return;\n                    case X12_ENCODATION:\n                        context.writeCodeword(LATCH_TO_ANSIX12);\n                        context.signalEncoderChange(X12_ENCODATION);\n                        break;\n                    case TEXT_ENCODATION:\n                        context.writeCodeword(LATCH_TO_TEXT);\n                        context.signalEncoderChange(TEXT_ENCODATION);\n                        break;\n                    case EDIFACT_ENCODATION:\n                        context.writeCodeword(LATCH_TO_EDIFACT);\n                        context.signalEncoderChange(EDIFACT_ENCODATION);\n                        break;\n                    default:\n                        throw new Error('Illegal mode: ' + newMode);\n                }\n            }\n            else if (HighLevelEncoder.isExtendedASCII(c)) {\n                context.writeCodeword(UPPER_SHIFT);\n                context.writeCodeword(c - 128 + 1);\n                context.pos++;\n            }\n            else {\n                context.writeCodeword(c + 1);\n                context.pos++;\n            }\n        }\n    };\n    ASCIIEncoder.prototype.encodeASCIIDigits = function (digit1, digit2) {\n        if (HighLevelEncoder.isDigit(digit1) && HighLevelEncoder.isDigit(digit2)) {\n            var num = (digit1 - 48) * 10 + (digit2 - 48);\n            return num + 130;\n        }\n        throw new Error('not digits: ' + digit1 + digit2);\n    };\n    return ASCIIEncoder;\n}());\nexport { ASCIIEncoder };\n","import StringUtils from '../../common/StringUtils';\nimport StringBuilder from '../../util/StringBuilder';\nimport HighLevelEncoder from './HighLevelEncoder';\nimport { BASE256_ENCODATION, ASCII_ENCODATION } from './constants';\nvar Base256Encoder = /** @class */ (function () {\n    function Base256Encoder() {\n    }\n    Base256Encoder.prototype.getEncodingMode = function () {\n        return BASE256_ENCODATION;\n    };\n    Base256Encoder.prototype.encode = function (context) {\n        var buffer = new StringBuilder();\n        buffer.append(0); // Initialize length field\n        while (context.hasMoreCharacters()) {\n            var c = context.getCurrentChar();\n            buffer.append(c);\n            context.pos++;\n            var newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, this.getEncodingMode());\n            if (newMode !== this.getEncodingMode()) {\n                // Return to ASCII encodation, which will actually handle latch to new mode\n                context.signalEncoderChange(ASCII_ENCODATION);\n                break;\n            }\n        }\n        var dataCount = buffer.length() - 1;\n        var lengthFieldSize = 1;\n        var currentSize = context.getCodewordCount() + dataCount + lengthFieldSize;\n        context.updateSymbolInfo(currentSize);\n        var mustPad = context.getSymbolInfo().getDataCapacity() - currentSize > 0;\n        if (context.hasMoreCharacters() || mustPad) {\n            if (dataCount <= 249) {\n                buffer.setCharAt(0, StringUtils.getCharAt(dataCount));\n            }\n            else if (dataCount <= 1555) {\n                buffer.setCharAt(0, StringUtils.getCharAt(Math.floor(dataCount / 250) + 249));\n                buffer.insert(1, StringUtils.getCharAt(dataCount % 250));\n            }\n            else {\n                throw new Error('Message length not in valid ranges: ' + dataCount);\n            }\n        }\n        for (var i = 0, c = buffer.length(); i < c; i++) {\n            context.writeCodeword(this.randomize255State(buffer.charAt(i).charCodeAt(0), context.getCodewordCount() + 1));\n        }\n    };\n    Base256Encoder.prototype.randomize255State = function (ch, codewordPosition) {\n        var pseudoRandom = ((149 * codewordPosition) % 255) + 1;\n        var tempVariable = ch + pseudoRandom;\n        if (tempVariable <= 255) {\n            return tempVariable;\n        }\n        else {\n            return tempVariable - 256;\n        }\n    };\n    return Base256Encoder;\n}());\nexport { Base256Encoder };\n","import StringBuilder from '../../util/StringBuilder';\nimport HighLevelEncoder from './HighLevelEncoder';\nimport { C40_ENCODATION, LATCH_TO_C40, ASCII_ENCODATION, C40_UNLATCH, } from './constants';\nvar C40Encoder = /** @class */ (function () {\n    function C40Encoder() {\n    }\n    C40Encoder.prototype.getEncodingMode = function () {\n        return C40_ENCODATION;\n    };\n    C40Encoder.prototype.encodeMaximal = function (context) {\n        var buffer = new StringBuilder();\n        var lastCharSize = 0;\n        var backtrackStartPosition = context.pos;\n        var backtrackBufferLength = 0;\n        while (context.hasMoreCharacters()) {\n            var c = context.getCurrentChar();\n            context.pos++;\n            lastCharSize = this.encodeChar(c, buffer);\n            if (buffer.length() % 3 === 0) {\n                backtrackStartPosition = context.pos;\n                backtrackBufferLength = buffer.length();\n            }\n        }\n        if (backtrackBufferLength !== buffer.length()) {\n            var unwritten = Math.floor((buffer.length() / 3) * 2);\n            var curCodewordCount = Math.floor(context.getCodewordCount() + unwritten + 1); // +1 for the latch to C40\n            context.updateSymbolInfo(curCodewordCount);\n            var available = context.getSymbolInfo().getDataCapacity() - curCodewordCount;\n            var rest = Math.floor(buffer.length() % 3);\n            if ((rest === 2 && available !== 2) ||\n                (rest === 1 && (lastCharSize > 3 || available !== 1))) {\n                // buffer.setLength(backtrackBufferLength);\n                context.pos = backtrackStartPosition;\n            }\n        }\n        if (buffer.length() > 0) {\n            context.writeCodeword(LATCH_TO_C40);\n        }\n        this.handleEOD(context, buffer);\n    };\n    C40Encoder.prototype.encode = function (context) {\n        // step C\n        var buffer = new StringBuilder();\n        while (context.hasMoreCharacters()) {\n            var c = context.getCurrentChar();\n            context.pos++;\n            var lastCharSize = this.encodeChar(c, buffer);\n            var unwritten = Math.floor(buffer.length() / 3) * 2;\n            var curCodewordCount = context.getCodewordCount() + unwritten;\n            context.updateSymbolInfo(curCodewordCount);\n            var available = context.getSymbolInfo().getDataCapacity() - curCodewordCount;\n            if (!context.hasMoreCharacters()) {\n                // Avoid having a single C40 value in the last triplet\n                var removed = new StringBuilder();\n                if (buffer.length() % 3 === 2 && available !== 2) {\n                    lastCharSize = this.backtrackOneCharacter(context, buffer, removed, lastCharSize);\n                }\n                while (buffer.length() % 3 === 1 &&\n                    (lastCharSize > 3 || available !== 1)) {\n                    lastCharSize = this.backtrackOneCharacter(context, buffer, removed, lastCharSize);\n                }\n                break;\n            }\n            var count = buffer.length();\n            if (count % 3 === 0) {\n                var newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, this.getEncodingMode());\n                if (newMode !== this.getEncodingMode()) {\n                    // Return to ASCII encodation, which will actually handle latch to new mode\n                    context.signalEncoderChange(ASCII_ENCODATION);\n                    break;\n                }\n            }\n        }\n        this.handleEOD(context, buffer);\n    };\n    C40Encoder.prototype.backtrackOneCharacter = function (context, buffer, removed, lastCharSize) {\n        var count = buffer.length();\n        var test = buffer.toString().substring(0, count - lastCharSize);\n        buffer.setLengthToZero();\n        buffer.append(test);\n        // buffer.delete(count - lastCharSize, count);\n        /*for (let i = count - lastCharSize; i < count; i++) {\n          buffer.deleteCharAt(i);\n        }*/\n        context.pos--;\n        var c = context.getCurrentChar();\n        lastCharSize = this.encodeChar(c, removed);\n        context.resetSymbolInfo(); // Deal with possible reduction in symbol size\n        return lastCharSize;\n    };\n    C40Encoder.prototype.writeNextTriplet = function (context, buffer) {\n        context.writeCodewords(this.encodeToCodewords(buffer.toString()));\n        var test = buffer.toString().substring(3);\n        buffer.setLengthToZero();\n        buffer.append(test);\n        // buffer.delete(0, 3);\n        /*for (let i = 0; i < 3; i++) {\n          buffer.deleteCharAt(i);\n        }*/\n    };\n    /**\n     * Handle \"end of data\" situations\n     *\n     * @param context the encoder context\n     * @param buffer  the buffer with the remaining encoded characters\n     */\n    C40Encoder.prototype.handleEOD = function (context, buffer) {\n        var unwritten = Math.floor((buffer.length() / 3) * 2);\n        var rest = buffer.length() % 3;\n        var curCodewordCount = context.getCodewordCount() + unwritten;\n        context.updateSymbolInfo(curCodewordCount);\n        var available = context.getSymbolInfo().getDataCapacity() - curCodewordCount;\n        if (rest === 2) {\n            buffer.append('\\0'); // Shift 1\n            while (buffer.length() >= 3) {\n                this.writeNextTriplet(context, buffer);\n            }\n            if (context.hasMoreCharacters()) {\n                context.writeCodeword(C40_UNLATCH);\n            }\n        }\n        else if (available === 1 && rest === 1) {\n            while (buffer.length() >= 3) {\n                this.writeNextTriplet(context, buffer);\n            }\n            if (context.hasMoreCharacters()) {\n                context.writeCodeword(C40_UNLATCH);\n            }\n            // else no unlatch\n            context.pos--;\n        }\n        else if (rest === 0) {\n            while (buffer.length() >= 3) {\n                this.writeNextTriplet(context, buffer);\n            }\n            if (available > 0 || context.hasMoreCharacters()) {\n                context.writeCodeword(C40_UNLATCH);\n            }\n        }\n        else {\n            throw new Error('Unexpected case. Please report!');\n        }\n        context.signalEncoderChange(ASCII_ENCODATION);\n    };\n    C40Encoder.prototype.encodeChar = function (c, sb) {\n        if (c === ' '.charCodeAt(0)) {\n            sb.append(3);\n            return 1;\n        }\n        if (c >= '0'.charCodeAt(0) && c <= '9'.charCodeAt(0)) {\n            sb.append(c - 48 + 4);\n            return 1;\n        }\n        if (c >= 'A'.charCodeAt(0) && c <= 'Z'.charCodeAt(0)) {\n            sb.append(c - 65 + 14);\n            return 1;\n        }\n        if (c < ' '.charCodeAt(0)) {\n            sb.append(0); // Shift 1 Set\n            sb.append(c);\n            return 2;\n        }\n        if (c <= '/'.charCodeAt(0)) {\n            sb.append(1); // Shift 2 Set\n            sb.append(c - 33);\n            return 2;\n        }\n        if (c <= '@'.charCodeAt(0)) {\n            sb.append(1); // Shift 2 Set\n            sb.append(c - 58 + 15);\n            return 2;\n        }\n        if (c <= '_'.charCodeAt(0)) {\n            sb.append(1); // Shift 2 Set\n            sb.append(c - 91 + 22);\n            return 2;\n        }\n        if (c <= 127) {\n            sb.append(2); // Shift 3 Set\n            sb.append(c - 96);\n            return 2;\n        }\n        sb.append(1 + \"\\u001E\"); // Shift 2, Upper Shift\n        var len = 2;\n        len += this.encodeChar(c - 128, sb);\n        return len;\n    };\n    C40Encoder.prototype.encodeToCodewords = function (sb) {\n        var v = 1600 * sb.charCodeAt(0) + 40 * sb.charCodeAt(1) + sb.charCodeAt(2) + 1;\n        var cw1 = v / 256;\n        var cw2 = v % 256;\n        var result = new StringBuilder();\n        result.append(cw1);\n        result.append(cw2);\n        return result.toString();\n    };\n    return C40Encoder;\n}());\nexport { C40Encoder };\n","import Arrays from '../../util/Arrays';\n/**\n * Symbol Character Placement Program. Adapted from Annex M.1 in ISO/IEC 16022:2000(E).\n */\nvar DefaultPlacement = /** @class */ (function () {\n    /**\n     * Main constructor\n     *\n     * @param codewords the codewords to place\n     * @param numcols   the number of columns\n     * @param numrows   the number of rows\n     */\n    function DefaultPlacement(codewords, numcols, numrows) {\n        this.codewords = codewords;\n        this.numcols = numcols;\n        this.numrows = numrows;\n        this.bits = new Uint8Array(numcols * numrows);\n        Arrays.fill(this.bits, 2); // Initialize with \"not set\" value\n    }\n    DefaultPlacement.prototype.getNumrows = function () {\n        return this.numrows;\n    };\n    DefaultPlacement.prototype.getNumcols = function () {\n        return this.numcols;\n    };\n    DefaultPlacement.prototype.getBits = function () {\n        return this.bits;\n    };\n    DefaultPlacement.prototype.getBit = function (col, row) {\n        return this.bits[row * this.numcols + col] === 1;\n    };\n    DefaultPlacement.prototype.setBit = function (col, row, bit) {\n        this.bits[row * this.numcols + col] = bit ? 1 : 0;\n    };\n    DefaultPlacement.prototype.noBit = function (col, row) {\n        return this.bits[row * this.numcols + col] === 2;\n    };\n    DefaultPlacement.prototype.place = function () {\n        var pos = 0;\n        var row = 4;\n        var col = 0;\n        do {\n            // repeatedly first check for one of the special corner cases, then...\n            if (row === this.numrows && col === 0) {\n                this.corner1(pos++);\n            }\n            if (row === this.numrows - 2 && col === 0 && this.numcols % 4 !== 0) {\n                this.corner2(pos++);\n            }\n            if (row === this.numrows - 2 && col === 0 && this.numcols % 8 === 4) {\n                this.corner3(pos++);\n            }\n            if (row === this.numrows + 4 && col === 2 && this.numcols % 8 === 0) {\n                this.corner4(pos++);\n            }\n            // sweep upward diagonally, inserting successive characters...\n            do {\n                if (row < this.numrows && col >= 0 && this.noBit(col, row)) {\n                    this.utah(row, col, pos++);\n                }\n                row -= 2;\n                col += 2;\n            } while (row >= 0 && col < this.numcols);\n            row++;\n            col += 3;\n            // and then sweep downward diagonally, inserting successive characters, ...\n            do {\n                if (row >= 0 && col < this.numcols && this.noBit(col, row)) {\n                    this.utah(row, col, pos++);\n                }\n                row += 2;\n                col -= 2;\n            } while (row < this.numrows && col >= 0);\n            row += 3;\n            col++;\n            // ...until the entire array is scanned\n        } while (row < this.numrows || col < this.numcols);\n        // Lastly, if the lower right-hand corner is untouched, fill in fixed pattern\n        if (this.noBit(this.numcols - 1, this.numrows - 1)) {\n            this.setBit(this.numcols - 1, this.numrows - 1, true);\n            this.setBit(this.numcols - 2, this.numrows - 2, true);\n        }\n    };\n    DefaultPlacement.prototype.module = function (row, col, pos, bit) {\n        if (row < 0) {\n            row += this.numrows;\n            col += 4 - ((this.numrows + 4) % 8);\n        }\n        if (col < 0) {\n            col += this.numcols;\n            row += 4 - ((this.numcols + 4) % 8);\n        }\n        // Note the conversion:\n        var v = this.codewords.charCodeAt(pos);\n        v &= 1 << (8 - bit);\n        this.setBit(col, row, v !== 0);\n    };\n    /**\n     * Places the 8 bits of a utah-shaped symbol character in ECC200.\n     *\n     * @param row the row\n     * @param col the column\n     * @param pos character position\n     */\n    DefaultPlacement.prototype.utah = function (row, col, pos) {\n        this.module(row - 2, col - 2, pos, 1);\n        this.module(row - 2, col - 1, pos, 2);\n        this.module(row - 1, col - 2, pos, 3);\n        this.module(row - 1, col - 1, pos, 4);\n        this.module(row - 1, col, pos, 5);\n        this.module(row, col - 2, pos, 6);\n        this.module(row, col - 1, pos, 7);\n        this.module(row, col, pos, 8);\n    };\n    DefaultPlacement.prototype.corner1 = function (pos) {\n        this.module(this.numrows - 1, 0, pos, 1);\n        this.module(this.numrows - 1, 1, pos, 2);\n        this.module(this.numrows - 1, 2, pos, 3);\n        this.module(0, this.numcols - 2, pos, 4);\n        this.module(0, this.numcols - 1, pos, 5);\n        this.module(1, this.numcols - 1, pos, 6);\n        this.module(2, this.numcols - 1, pos, 7);\n        this.module(3, this.numcols - 1, pos, 8);\n    };\n    DefaultPlacement.prototype.corner2 = function (pos) {\n        this.module(this.numrows - 3, 0, pos, 1);\n        this.module(this.numrows - 2, 0, pos, 2);\n        this.module(this.numrows - 1, 0, pos, 3);\n        this.module(0, this.numcols - 4, pos, 4);\n        this.module(0, this.numcols - 3, pos, 5);\n        this.module(0, this.numcols - 2, pos, 6);\n        this.module(0, this.numcols - 1, pos, 7);\n        this.module(1, this.numcols - 1, pos, 8);\n    };\n    DefaultPlacement.prototype.corner3 = function (pos) {\n        this.module(this.numrows - 3, 0, pos, 1);\n        this.module(this.numrows - 2, 0, pos, 2);\n        this.module(this.numrows - 1, 0, pos, 3);\n        this.module(0, this.numcols - 2, pos, 4);\n        this.module(0, this.numcols - 1, pos, 5);\n        this.module(1, this.numcols - 1, pos, 6);\n        this.module(2, this.numcols - 1, pos, 7);\n        this.module(3, this.numcols - 1, pos, 8);\n    };\n    DefaultPlacement.prototype.corner4 = function (pos) {\n        this.module(this.numrows - 1, 0, pos, 1);\n        this.module(this.numrows - 1, this.numcols - 1, pos, 2);\n        this.module(0, this.numcols - 3, pos, 3);\n        this.module(0, this.numcols - 2, pos, 4);\n        this.module(0, this.numcols - 1, pos, 5);\n        this.module(1, this.numcols - 3, pos, 6);\n        this.module(1, this.numcols - 2, pos, 7);\n        this.module(1, this.numcols - 1, pos, 8);\n    };\n    return DefaultPlacement;\n}());\nexport default DefaultPlacement;\n","import StringUtils from '../../common/StringUtils';\nimport StringBuilder from '../../util/StringBuilder';\nimport { EDIFACT_ENCODATION, ASCII_ENCODATION } from './constants';\nimport HighLevelEncoder from './HighLevelEncoder';\nvar EdifactEncoder = /** @class */ (function () {\n    function EdifactEncoder() {\n    }\n    EdifactEncoder.prototype.getEncodingMode = function () {\n        return EDIFACT_ENCODATION;\n    };\n    EdifactEncoder.prototype.encode = function (context) {\n        // step F\n        var buffer = new StringBuilder();\n        while (context.hasMoreCharacters()) {\n            var c = context.getCurrentChar();\n            this.encodeChar(c, buffer);\n            context.pos++;\n            var count = buffer.length();\n            if (count >= 4) {\n                context.writeCodewords(this.encodeToCodewords(buffer.toString()));\n                var test_1 = buffer.toString().substring(4);\n                buffer.setLengthToZero();\n                buffer.append(test_1);\n                // buffer.delete(0, 4);\n                // for (let i = 0; i < 4; i++) {\n                //  buffer.deleteCharAt(i);\n                // }\n                var newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, this.getEncodingMode());\n                if (newMode !== this.getEncodingMode()) {\n                    // Return to ASCII encodation, which will actually handle latch to new mode\n                    context.signalEncoderChange(ASCII_ENCODATION);\n                    break;\n                }\n            }\n        }\n        buffer.append(StringUtils.getCharAt(31)); // Unlatch\n        this.handleEOD(context, buffer);\n    };\n    /**\n     * Handle \"end of data\" situations\n     *\n     * @param context the encoder context\n     * @param buffer  the buffer with the remaining encoded characters\n     */\n    EdifactEncoder.prototype.handleEOD = function (context, buffer) {\n        try {\n            var count = buffer.length();\n            if (count === 0) {\n                return; // Already finished\n            }\n            if (count === 1) {\n                // Only an unlatch at the end\n                context.updateSymbolInfo();\n                var available = context.getSymbolInfo().getDataCapacity() -\n                    context.getCodewordCount();\n                var remaining = context.getRemainingCharacters();\n                // The following two lines are a hack inspired by the 'fix' from https://sourceforge.net/p/barcode4j/svn/221/\n                if (remaining > available) {\n                    context.updateSymbolInfo(context.getCodewordCount() + 1);\n                    available =\n                        context.getSymbolInfo().getDataCapacity() -\n                            context.getCodewordCount();\n                }\n                if (remaining <= available && available <= 2) {\n                    return; // No unlatch\n                }\n            }\n            if (count > 4) {\n                throw new Error('Count must not exceed 4');\n            }\n            var restChars = count - 1;\n            var encoded = this.encodeToCodewords(buffer.toString());\n            var endOfSymbolReached = !context.hasMoreCharacters();\n            var restInAscii = endOfSymbolReached && restChars <= 2;\n            if (restChars <= 2) {\n                context.updateSymbolInfo(context.getCodewordCount() + restChars);\n                var available = context.getSymbolInfo().getDataCapacity() -\n                    context.getCodewordCount();\n                if (available >= 3) {\n                    restInAscii = false;\n                    context.updateSymbolInfo(context.getCodewordCount() + encoded.length);\n                    // available = context.symbolInfo.dataCapacity - context.getCodewordCount();\n                }\n            }\n            if (restInAscii) {\n                context.resetSymbolInfo();\n                context.pos -= restChars;\n            }\n            else {\n                context.writeCodewords(encoded);\n            }\n        }\n        finally {\n            context.signalEncoderChange(ASCII_ENCODATION);\n        }\n    };\n    EdifactEncoder.prototype.encodeChar = function (c, sb) {\n        if (c >= ' '.charCodeAt(0) && c <= '?'.charCodeAt(0)) {\n            sb.append(c);\n        }\n        else if (c >= '@'.charCodeAt(0) && c <= '^'.charCodeAt(0)) {\n            sb.append(StringUtils.getCharAt(c - 64));\n        }\n        else {\n            HighLevelEncoder.illegalCharacter(StringUtils.getCharAt(c));\n        }\n    };\n    EdifactEncoder.prototype.encodeToCodewords = function (sb) {\n        var len = sb.length;\n        if (len === 0) {\n            throw new Error('StringBuilder must not be empty');\n        }\n        var c1 = sb.charAt(0).charCodeAt(0);\n        var c2 = len >= 2 ? sb.charAt(1).charCodeAt(0) : 0;\n        var c3 = len >= 3 ? sb.charAt(2).charCodeAt(0) : 0;\n        var c4 = len >= 4 ? sb.charAt(3).charCodeAt(0) : 0;\n        var v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4;\n        var cw1 = (v >> 16) & 255;\n        var cw2 = (v >> 8) & 255;\n        var cw3 = v & 255;\n        var res = new StringBuilder();\n        res.append(cw1);\n        if (len >= 2) {\n            res.append(cw2);\n        }\n        if (len >= 3) {\n            res.append(cw3);\n        }\n        return res.toString();\n    };\n    return EdifactEncoder;\n}());\nexport { EdifactEncoder };\n","import StringBuilder from '../../util/StringBuilder';\nimport SymbolInfo from './SymbolInfo';\nvar EncoderContext = /** @class */ (function () {\n    function EncoderContext(msg) {\n        this.msg = msg;\n        this.pos = 0;\n        this.skipAtEnd = 0;\n        // From this point on Strings are not Unicode anymore!\n        var msgBinary = msg.split('').map(function (c) { return c.charCodeAt(0); });\n        var sb = new StringBuilder();\n        for (var i = 0, c = msgBinary.length; i < c; i++) {\n            var ch = String.fromCharCode(msgBinary[i] & 0xff);\n            if (ch === '?' && msg.charAt(i) !== '?') {\n                throw new Error('Message contains characters outside ISO-8859-1 encoding.');\n            }\n            sb.append(ch);\n        }\n        this.msg = sb.toString(); // Not Unicode here!\n        this.shape = 0 /* FORCE_NONE */;\n        this.codewords = new StringBuilder();\n        this.newEncoding = -1;\n    }\n    EncoderContext.prototype.setSymbolShape = function (shape) {\n        this.shape = shape;\n    };\n    EncoderContext.prototype.setSizeConstraints = function (minSize, maxSize) {\n        this.minSize = minSize;\n        this.maxSize = maxSize;\n    };\n    EncoderContext.prototype.getMessage = function () {\n        return this.msg;\n    };\n    EncoderContext.prototype.setSkipAtEnd = function (count) {\n        this.skipAtEnd = count;\n    };\n    EncoderContext.prototype.getCurrentChar = function () {\n        return this.msg.charCodeAt(this.pos);\n    };\n    EncoderContext.prototype.getCurrent = function () {\n        return this.msg.charCodeAt(this.pos);\n    };\n    EncoderContext.prototype.getCodewords = function () {\n        return this.codewords;\n    };\n    EncoderContext.prototype.writeCodewords = function (codewords) {\n        this.codewords.append(codewords);\n    };\n    EncoderContext.prototype.writeCodeword = function (codeword) {\n        this.codewords.append(codeword);\n    };\n    EncoderContext.prototype.getCodewordCount = function () {\n        return this.codewords.length();\n    };\n    EncoderContext.prototype.getNewEncoding = function () {\n        return this.newEncoding;\n    };\n    EncoderContext.prototype.signalEncoderChange = function (encoding) {\n        this.newEncoding = encoding;\n    };\n    EncoderContext.prototype.resetEncoderSignal = function () {\n        this.newEncoding = -1;\n    };\n    EncoderContext.prototype.hasMoreCharacters = function () {\n        return this.pos < this.getTotalMessageCharCount();\n    };\n    EncoderContext.prototype.getTotalMessageCharCount = function () {\n        return this.msg.length - this.skipAtEnd;\n    };\n    EncoderContext.prototype.getRemainingCharacters = function () {\n        return this.getTotalMessageCharCount() - this.pos;\n    };\n    EncoderContext.prototype.getSymbolInfo = function () {\n        return this.symbolInfo;\n    };\n    EncoderContext.prototype.updateSymbolInfo = function (len) {\n        if (len === void 0) { len = this.getCodewordCount(); }\n        if (this.symbolInfo == null || len > this.symbolInfo.getDataCapacity()) {\n            this.symbolInfo = SymbolInfo.lookup(len, this.shape, this.minSize, this.maxSize, true);\n        }\n    };\n    EncoderContext.prototype.resetSymbolInfo = function () {\n        this.symbolInfo = null;\n    };\n    return EncoderContext;\n}());\nexport { EncoderContext };\n","import StringBuilder from '../../util/StringBuilder';\nimport { ALOG, FACTORS, FACTOR_SETS, LOG } from './constants';\n/**\n * Error Correction Code for ECC200.\n */\nvar ErrorCorrection = /** @class */ (function () {\n    function ErrorCorrection() {\n    }\n    /**\n     * Creates the ECC200 error correction for an encoded message.\n     *\n     * @param codewords  the codewords\n     * @param symbolInfo information about the symbol to be encoded\n     * @return the codewords with interleaved error correction.\n     */\n    ErrorCorrection.encodeECC200 = function (codewords, symbolInfo) {\n        if (codewords.length !== symbolInfo.getDataCapacity()) {\n            throw new Error('The number of codewords does not match the selected symbol');\n        }\n        var sb = new StringBuilder();\n        sb.append(codewords);\n        var blockCount = symbolInfo.getInterleavedBlockCount();\n        if (blockCount === 1) {\n            var ecc = this.createECCBlock(codewords, symbolInfo.getErrorCodewords());\n            sb.append(ecc);\n        }\n        else {\n            // sb.setLength(sb.capacity());\n            var dataSizes = [];\n            var errorSizes = [];\n            for (var i = 0; i < blockCount; i++) {\n                dataSizes[i] = symbolInfo.getDataLengthForInterleavedBlock(i + 1);\n                errorSizes[i] = symbolInfo.getErrorLengthForInterleavedBlock(i + 1);\n            }\n            for (var block = 0; block < blockCount; block++) {\n                var temp = new StringBuilder();\n                for (var d = block; d < symbolInfo.getDataCapacity(); d += blockCount) {\n                    temp.append(codewords.charAt(d));\n                }\n                var ecc = this.createECCBlock(temp.toString(), errorSizes[block]);\n                var pos = 0;\n                for (var e = block; e < errorSizes[block] * blockCount; e += blockCount) {\n                    sb.setCharAt(symbolInfo.getDataCapacity() + e, ecc.charAt(pos++));\n                }\n            }\n        }\n        return sb.toString();\n    };\n    ErrorCorrection.createECCBlock = function (codewords, numECWords) {\n        var table = -1;\n        for (var i = 0; i < FACTOR_SETS.length; i++) {\n            if (FACTOR_SETS[i] === numECWords) {\n                table = i;\n                break;\n            }\n        }\n        if (table < 0) {\n            throw new Error('Illegal number of error correction codewords specified: ' + numECWords);\n        }\n        var poly = FACTORS[table];\n        var ecc = [];\n        for (var i = 0; i < numECWords; i++) {\n            ecc[i] = 0;\n        }\n        for (var i = 0; i < codewords.length; i++) {\n            var m = ecc[numECWords - 1] ^ codewords.charAt(i).charCodeAt(0);\n            for (var k = numECWords - 1; k > 0; k--) {\n                if (m !== 0 && poly[k] !== 0) {\n                    ecc[k] = ecc[k - 1] ^ ALOG[(LOG[m] + LOG[poly[k]]) % 255];\n                }\n                else {\n                    ecc[k] = ecc[k - 1];\n                }\n            }\n            if (m !== 0 && poly[0] !== 0) {\n                ecc[0] = ALOG[(LOG[m] + LOG[poly[0]]) % 255];\n            }\n            else {\n                ecc[0] = 0;\n            }\n        }\n        var eccReversed = [];\n        for (var i = 0; i < numECWords; i++) {\n            eccReversed[i] = ecc[numECWords - i - 1];\n        }\n        return eccReversed.map(function (c) { return String.fromCharCode(c); }).join('');\n    };\n    return ErrorCorrection;\n}());\nexport default ErrorCorrection;\n","// tslint:disable-next-line:no-circular-imports\nimport { ASCIIEncoder } from './ASCIIEncoder';\n// tslint:disable-next-line:no-circular-imports\nimport { Base256Encoder } from './Base256Encoder';\n// tslint:disable-next-line:no-circular-imports\nimport { C40Encoder } from './C40Encoder';\nimport { ASCII_ENCODATION, BASE256_ENCODATION, C40_ENCODATION, EDIFACT_ENCODATION, MACRO_05, MACRO_05_HEADER, MACRO_06, MACRO_06_HEADER, MACRO_TRAILER, PAD, TEXT_ENCODATION, X12_ENCODATION, } from './constants';\n// tslint:disable-next-line:no-circular-imports\nimport { EdifactEncoder } from './EdifactEncoder';\nimport { EncoderContext } from './EncoderContext';\n// tslint:disable-next-line:no-circular-imports\nimport { X12Encoder } from './X12Encoder';\n// tslint:disable-next-line:no-circular-imports\nimport { TextEncoder } from './TextEncoder';\nimport Arrays from '../../util/Arrays';\nimport Integer from '../../util/Integer';\n/**\n * DataMatrix ECC 200 data encoder following the algorithm described in ISO/IEC 16022:200(E) in\n * annex S.\n */\nvar HighLevelEncoder = /** @class */ (function () {\n    function HighLevelEncoder() {\n    }\n    HighLevelEncoder.randomize253State = function (codewordPosition) {\n        var pseudoRandom = ((149 * codewordPosition) % 253) + 1;\n        var tempVariable = PAD + pseudoRandom;\n        return tempVariable <= 254 ? tempVariable : tempVariable - 254;\n    };\n    /**\n     * Performs message encoding of a DataMatrix message using the algorithm described in annex P\n     * of ISO/IEC 16022:2000(E).\n     *\n     * @param msg     the message\n     * @param shape   requested shape. May be {@code SymbolShapeHint.FORCE_NONE},\n     *                {@code SymbolShapeHint.FORCE_SQUARE} or {@code SymbolShapeHint.FORCE_RECTANGLE}.\n     * @param minSize the minimum symbol size constraint or null for no constraint\n     * @param maxSize the maximum symbol size constraint or null for no constraint\n     * @param forceC40 enforce C40 encoding\n     * @return the encoded message (the char values range from 0 to 255)\n     */\n    HighLevelEncoder.encodeHighLevel = function (msg, shape, minSize, maxSize, forceC40) {\n        if (shape === void 0) { shape = 0 /* FORCE_NONE */; }\n        if (minSize === void 0) { minSize = null; }\n        if (maxSize === void 0) { maxSize = null; }\n        if (forceC40 === void 0) { forceC40 = false; }\n        // the codewords 0..255 are encoded as Unicode characters\n        var c40Encoder = new C40Encoder();\n        var encoders = [\n            new ASCIIEncoder(),\n            c40Encoder,\n            new TextEncoder(),\n            new X12Encoder(),\n            new EdifactEncoder(),\n            new Base256Encoder(),\n        ];\n        var context = new EncoderContext(msg);\n        context.setSymbolShape(shape);\n        context.setSizeConstraints(minSize, maxSize);\n        if (msg.startsWith(MACRO_05_HEADER) && msg.endsWith(MACRO_TRAILER)) {\n            context.writeCodeword(MACRO_05);\n            context.setSkipAtEnd(2);\n            context.pos += MACRO_05_HEADER.length;\n        }\n        else if (msg.startsWith(MACRO_06_HEADER) && msg.endsWith(MACRO_TRAILER)) {\n            context.writeCodeword(MACRO_06);\n            context.setSkipAtEnd(2);\n            context.pos += MACRO_06_HEADER.length;\n        }\n        var encodingMode = ASCII_ENCODATION; // Default mode\n        if (forceC40) {\n            c40Encoder.encodeMaximal(context);\n            encodingMode = context.getNewEncoding();\n            context.resetEncoderSignal();\n        }\n        while (context.hasMoreCharacters()) {\n            encoders[encodingMode].encode(context);\n            if (context.getNewEncoding() >= 0) {\n                encodingMode = context.getNewEncoding();\n                context.resetEncoderSignal();\n            }\n        }\n        var len = context.getCodewordCount();\n        context.updateSymbolInfo();\n        var capacity = context.getSymbolInfo().getDataCapacity();\n        if (len < capacity &&\n            encodingMode !== ASCII_ENCODATION &&\n            encodingMode !== BASE256_ENCODATION &&\n            encodingMode !== EDIFACT_ENCODATION) {\n            context.writeCodeword('\\u00fe'); // Unlatch (254)\n        }\n        // Padding\n        var codewords = context.getCodewords();\n        if (codewords.length() < capacity) {\n            codewords.append(PAD);\n        }\n        while (codewords.length() < capacity) {\n            codewords.append(this.randomize253State(codewords.length() + 1));\n        }\n        return context.getCodewords().toString();\n    };\n    HighLevelEncoder.lookAheadTest = function (msg, startpos, currentMode) {\n        var newMode = this.lookAheadTestIntern(msg, startpos, currentMode);\n        if (currentMode === X12_ENCODATION && newMode === X12_ENCODATION) {\n            var endpos = Math.min(startpos + 3, msg.length);\n            for (var i = startpos; i < endpos; i++) {\n                if (!this.isNativeX12(msg.charCodeAt(i))) {\n                    return ASCII_ENCODATION;\n                }\n            }\n        }\n        else if (currentMode === EDIFACT_ENCODATION &&\n            newMode === EDIFACT_ENCODATION) {\n            var endpos = Math.min(startpos + 4, msg.length);\n            for (var i = startpos; i < endpos; i++) {\n                if (!this.isNativeEDIFACT(msg.charCodeAt(i))) {\n                    return ASCII_ENCODATION;\n                }\n            }\n        }\n        return newMode;\n    };\n    HighLevelEncoder.lookAheadTestIntern = function (msg, startpos, currentMode) {\n        if (startpos >= msg.length) {\n            return currentMode;\n        }\n        var charCounts;\n        // step J\n        if (currentMode === ASCII_ENCODATION) {\n            charCounts = [0, 1, 1, 1, 1, 1.25];\n        }\n        else {\n            charCounts = [1, 2, 2, 2, 2, 2.25];\n            charCounts[currentMode] = 0;\n        }\n        var charsProcessed = 0;\n        var mins = new Uint8Array(6);\n        var intCharCounts = [];\n        while (true) {\n            // step K\n            if (startpos + charsProcessed === msg.length) {\n                Arrays.fill(mins, 0);\n                Arrays.fill(intCharCounts, 0);\n                var min = this.findMinimums(charCounts, intCharCounts, Integer.MAX_VALUE, mins);\n                var minCount = this.getMinimumCount(mins);\n                if (intCharCounts[ASCII_ENCODATION] === min) {\n                    return ASCII_ENCODATION;\n                }\n                if (minCount === 1) {\n                    if (mins[BASE256_ENCODATION] > 0) {\n                        return BASE256_ENCODATION;\n                    }\n                    if (mins[EDIFACT_ENCODATION] > 0) {\n                        return EDIFACT_ENCODATION;\n                    }\n                    if (mins[TEXT_ENCODATION] > 0) {\n                        return TEXT_ENCODATION;\n                    }\n                    if (mins[X12_ENCODATION] > 0) {\n                        return X12_ENCODATION;\n                    }\n                }\n                return C40_ENCODATION;\n            }\n            var c = msg.charCodeAt(startpos + charsProcessed);\n            charsProcessed++;\n            // step L\n            if (this.isDigit(c)) {\n                charCounts[ASCII_ENCODATION] += 0.5;\n            }\n            else if (this.isExtendedASCII(c)) {\n                charCounts[ASCII_ENCODATION] = Math.ceil(charCounts[ASCII_ENCODATION]);\n                charCounts[ASCII_ENCODATION] += 2.0;\n            }\n            else {\n                charCounts[ASCII_ENCODATION] = Math.ceil(charCounts[ASCII_ENCODATION]);\n                charCounts[ASCII_ENCODATION]++;\n            }\n            // step M\n            if (this.isNativeC40(c)) {\n                charCounts[C40_ENCODATION] += 2.0 / 3.0;\n            }\n            else if (this.isExtendedASCII(c)) {\n                charCounts[C40_ENCODATION] += 8.0 / 3.0;\n            }\n            else {\n                charCounts[C40_ENCODATION] += 4.0 / 3.0;\n            }\n            // step N\n            if (this.isNativeText(c)) {\n                charCounts[TEXT_ENCODATION] += 2.0 / 3.0;\n            }\n            else if (this.isExtendedASCII(c)) {\n                charCounts[TEXT_ENCODATION] += 8.0 / 3.0;\n            }\n            else {\n                charCounts[TEXT_ENCODATION] += 4.0 / 3.0;\n            }\n            // step O\n            if (this.isNativeX12(c)) {\n                charCounts[X12_ENCODATION] += 2.0 / 3.0;\n            }\n            else if (this.isExtendedASCII(c)) {\n                charCounts[X12_ENCODATION] += 13.0 / 3.0;\n            }\n            else {\n                charCounts[X12_ENCODATION] += 10.0 / 3.0;\n            }\n            // step P\n            if (this.isNativeEDIFACT(c)) {\n                charCounts[EDIFACT_ENCODATION] += 3.0 / 4.0;\n            }\n            else if (this.isExtendedASCII(c)) {\n                charCounts[EDIFACT_ENCODATION] += 17.0 / 4.0;\n            }\n            else {\n                charCounts[EDIFACT_ENCODATION] += 13.0 / 4.0;\n            }\n            // step Q\n            if (this.isSpecialB256(c)) {\n                charCounts[BASE256_ENCODATION] += 4.0;\n            }\n            else {\n                charCounts[BASE256_ENCODATION]++;\n            }\n            // step R\n            if (charsProcessed >= 4) {\n                Arrays.fill(mins, 0);\n                Arrays.fill(intCharCounts, 0);\n                this.findMinimums(charCounts, intCharCounts, Integer.MAX_VALUE, mins);\n                if (intCharCounts[ASCII_ENCODATION] <\n                    this.min(intCharCounts[BASE256_ENCODATION], intCharCounts[C40_ENCODATION], intCharCounts[TEXT_ENCODATION], intCharCounts[X12_ENCODATION], intCharCounts[EDIFACT_ENCODATION])) {\n                    return ASCII_ENCODATION;\n                }\n                if (intCharCounts[BASE256_ENCODATION] < intCharCounts[ASCII_ENCODATION] ||\n                    intCharCounts[BASE256_ENCODATION] + 1 <\n                        this.min(intCharCounts[C40_ENCODATION], intCharCounts[TEXT_ENCODATION], intCharCounts[X12_ENCODATION], intCharCounts[EDIFACT_ENCODATION])) {\n                    return BASE256_ENCODATION;\n                }\n                if (intCharCounts[EDIFACT_ENCODATION] + 1 <\n                    this.min(intCharCounts[BASE256_ENCODATION], intCharCounts[C40_ENCODATION], intCharCounts[TEXT_ENCODATION], intCharCounts[X12_ENCODATION], intCharCounts[ASCII_ENCODATION])) {\n                    return EDIFACT_ENCODATION;\n                }\n                if (intCharCounts[TEXT_ENCODATION] + 1 <\n                    this.min(intCharCounts[BASE256_ENCODATION], intCharCounts[C40_ENCODATION], intCharCounts[EDIFACT_ENCODATION], intCharCounts[X12_ENCODATION], intCharCounts[ASCII_ENCODATION])) {\n                    return TEXT_ENCODATION;\n                }\n                if (intCharCounts[X12_ENCODATION] + 1 <\n                    this.min(intCharCounts[BASE256_ENCODATION], intCharCounts[C40_ENCODATION], intCharCounts[EDIFACT_ENCODATION], intCharCounts[TEXT_ENCODATION], intCharCounts[ASCII_ENCODATION])) {\n                    return X12_ENCODATION;\n                }\n                if (intCharCounts[C40_ENCODATION] + 1 <\n                    this.min(intCharCounts[ASCII_ENCODATION], intCharCounts[BASE256_ENCODATION], intCharCounts[EDIFACT_ENCODATION], intCharCounts[TEXT_ENCODATION])) {\n                    if (intCharCounts[C40_ENCODATION] < intCharCounts[X12_ENCODATION]) {\n                        return C40_ENCODATION;\n                    }\n                    if (intCharCounts[C40_ENCODATION] === intCharCounts[X12_ENCODATION]) {\n                        var p = startpos + charsProcessed + 1;\n                        while (p < msg.length) {\n                            var tc = msg.charCodeAt(p);\n                            if (this.isX12TermSep(tc)) {\n                                return X12_ENCODATION;\n                            }\n                            if (!this.isNativeX12(tc)) {\n                                break;\n                            }\n                            p++;\n                        }\n                        return C40_ENCODATION;\n                    }\n                }\n            }\n        }\n    };\n    HighLevelEncoder.min = function (f1, f2, f3, f4, f5) {\n        var val = Math.min(f1, Math.min(f2, Math.min(f3, f4)));\n        if (f5 === undefined) {\n            return val;\n        }\n        else {\n            return Math.min(val, f5);\n        }\n    };\n    HighLevelEncoder.findMinimums = function (charCounts, intCharCounts, min, mins) {\n        for (var i = 0; i < 6; i++) {\n            var current = (intCharCounts[i] = Math.ceil(charCounts[i]));\n            if (min > current) {\n                min = current;\n                Arrays.fill(mins, 0);\n            }\n            if (min === current) {\n                mins[i] = mins[i] + 1;\n            }\n        }\n        return min;\n    };\n    HighLevelEncoder.getMinimumCount = function (mins) {\n        var minCount = 0;\n        for (var i = 0; i < 6; i++) {\n            minCount += mins[i];\n        }\n        return minCount || 0;\n    };\n    HighLevelEncoder.isDigit = function (ch) {\n        return ch >= '0'.charCodeAt(0) && ch <= '9'.charCodeAt(0);\n    };\n    HighLevelEncoder.isExtendedASCII = function (ch) {\n        return ch >= 128 && ch <= 255;\n    };\n    HighLevelEncoder.isNativeC40 = function (ch) {\n        return (ch === ' '.charCodeAt(0) ||\n            (ch >= '0'.charCodeAt(0) && ch <= '9'.charCodeAt(0)) ||\n            (ch >= 'A'.charCodeAt(0) && ch <= 'Z'.charCodeAt(0)));\n    };\n    HighLevelEncoder.isNativeText = function (ch) {\n        return (ch === ' '.charCodeAt(0) ||\n            (ch >= '0'.charCodeAt(0) && ch <= '9'.charCodeAt(0)) ||\n            (ch >= 'a'.charCodeAt(0) && ch <= 'z'.charCodeAt(0)));\n    };\n    HighLevelEncoder.isNativeX12 = function (ch) {\n        return (this.isX12TermSep(ch) ||\n            ch === ' '.charCodeAt(0) ||\n            (ch >= '0'.charCodeAt(0) && ch <= '9'.charCodeAt(0)) ||\n            (ch >= 'A'.charCodeAt(0) && ch <= 'Z'.charCodeAt(0)));\n    };\n    HighLevelEncoder.isX12TermSep = function (ch) {\n        return (ch === 13 || // CR\n            ch === '*'.charCodeAt(0) ||\n            ch === '>'.charCodeAt(0));\n    };\n    HighLevelEncoder.isNativeEDIFACT = function (ch) {\n        return ch >= ' '.charCodeAt(0) && ch <= '^'.charCodeAt(0);\n    };\n    HighLevelEncoder.isSpecialB256 = function (ch) {\n        return false; // TODO NOT IMPLEMENTED YET!!!\n    };\n    /**\n     * Determines the number of consecutive characters that are encodable using numeric compaction.\n     *\n     * @param msg      the message\n     * @param startpos the start position within the message\n     * @return the requested character count\n     */\n    HighLevelEncoder.determineConsecutiveDigitCount = function (msg, startpos) {\n        if (startpos === void 0) { startpos = 0; }\n        var len = msg.length;\n        var idx = startpos;\n        while (idx < len && this.isDigit(msg.charCodeAt(idx))) {\n            idx++;\n        }\n        return idx - startpos;\n    };\n    HighLevelEncoder.illegalCharacter = function (singleCharacter) {\n        var hex = Integer.toHexString(singleCharacter.charCodeAt(0));\n        hex = '0000'.substring(0, 4 - hex.length) + hex;\n        throw new Error('Illegal character: ' + singleCharacter + ' (0x' + hex + ')');\n    };\n    return HighLevelEncoder;\n}());\nexport default HighLevelEncoder;\n","var __extends = (this && this.__extends) || (function () {\n    var extendStatics = function (d, b) {\n        extendStatics = Object.setPrototypeOf ||\n            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n        return extendStatics(d, b);\n    };\n    return function (d, b) {\n        extendStatics(d, b);\n        function __() { this.constructor = d; }\n        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n    };\n})();\nvar __values = (this && this.__values) || function(o) {\n    var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n    if (m) return m.call(o);\n    if (o && typeof o.length === \"number\") return {\n        next: function () {\n            if (o && i >= o.length) o = void 0;\n            return { value: o && o[i++], done: !o };\n        }\n    };\n    throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n};\n/**\n * Symbol info table for DataMatrix.\n */\nvar SymbolInfo = /** @class */ (function () {\n    function SymbolInfo(rectangular, dataCapacity, errorCodewords, matrixWidth, matrixHeight, dataRegions, rsBlockData, rsBlockError) {\n        if (rsBlockData === void 0) { rsBlockData = 0; }\n        if (rsBlockError === void 0) { rsBlockError = 0; }\n        this.rectangular = rectangular;\n        this.dataCapacity = dataCapacity;\n        this.errorCodewords = errorCodewords;\n        this.matrixWidth = matrixWidth;\n        this.matrixHeight = matrixHeight;\n        this.dataRegions = dataRegions;\n        this.rsBlockData = rsBlockData;\n        this.rsBlockError = rsBlockError;\n    }\n    SymbolInfo.lookup = function (dataCodewords, shape, minSize, maxSize, fail) {\n        var e_1, _a;\n        if (shape === void 0) { shape = 0 /* FORCE_NONE */; }\n        if (minSize === void 0) { minSize = null; }\n        if (maxSize === void 0) { maxSize = null; }\n        if (fail === void 0) { fail = true; }\n        try {\n            for (var PROD_SYMBOLS_1 = __values(PROD_SYMBOLS), PROD_SYMBOLS_1_1 = PROD_SYMBOLS_1.next(); !PROD_SYMBOLS_1_1.done; PROD_SYMBOLS_1_1 = PROD_SYMBOLS_1.next()) {\n                var symbol = PROD_SYMBOLS_1_1.value;\n                if (shape === 1 /* FORCE_SQUARE */ && symbol.rectangular) {\n                    continue;\n                }\n                if (shape === 2 /* FORCE_RECTANGLE */ && !symbol.rectangular) {\n                    continue;\n                }\n                if (minSize != null &&\n                    (symbol.getSymbolWidth() < minSize.getWidth() ||\n                        symbol.getSymbolHeight() < minSize.getHeight())) {\n                    continue;\n                }\n                if (maxSize != null &&\n                    (symbol.getSymbolWidth() > maxSize.getWidth() ||\n                        symbol.getSymbolHeight() > maxSize.getHeight())) {\n                    continue;\n                }\n                if (dataCodewords <= symbol.dataCapacity) {\n                    return symbol;\n                }\n            }\n        }\n        catch (e_1_1) { e_1 = { error: e_1_1 }; }\n        finally {\n            try {\n                if (PROD_SYMBOLS_1_1 && !PROD_SYMBOLS_1_1.done && (_a = PROD_SYMBOLS_1.return)) _a.call(PROD_SYMBOLS_1);\n            }\n            finally { if (e_1) throw e_1.error; }\n        }\n        if (fail) {\n            throw new Error(\"Can't find a symbol arrangement that matches the message. Data codewords: \" +\n                dataCodewords);\n        }\n        return null;\n    };\n    SymbolInfo.prototype.getHorizontalDataRegions = function () {\n        switch (this.dataRegions) {\n            case 1:\n                return 1;\n            case 2:\n            case 4:\n                return 2;\n            case 16:\n                return 4;\n            case 36:\n                return 6;\n            default:\n                throw new Error('Cannot handle this number of data regions');\n        }\n    };\n    SymbolInfo.prototype.getVerticalDataRegions = function () {\n        switch (this.dataRegions) {\n            case 1:\n            case 2:\n                return 1;\n            case 4:\n                return 2;\n            case 16:\n                return 4;\n            case 36:\n                return 6;\n            default:\n                throw new Error('Cannot handle this number of data regions');\n        }\n    };\n    SymbolInfo.prototype.getSymbolDataWidth = function () {\n        return this.getHorizontalDataRegions() * this.matrixWidth;\n    };\n    SymbolInfo.prototype.getSymbolDataHeight = function () {\n        return this.getVerticalDataRegions() * this.matrixHeight;\n    };\n    SymbolInfo.prototype.getSymbolWidth = function () {\n        return this.getSymbolDataWidth() + this.getHorizontalDataRegions() * 2;\n    };\n    SymbolInfo.prototype.getSymbolHeight = function () {\n        return this.getSymbolDataHeight() + this.getVerticalDataRegions() * 2;\n    };\n    SymbolInfo.prototype.getCodewordCount = function () {\n        return this.dataCapacity + this.errorCodewords;\n    };\n    SymbolInfo.prototype.getInterleavedBlockCount = function () {\n        if (!this.rsBlockData)\n            return 1;\n        return this.dataCapacity / this.rsBlockData;\n    };\n    SymbolInfo.prototype.getDataCapacity = function () {\n        return this.dataCapacity;\n    };\n    SymbolInfo.prototype.getErrorCodewords = function () {\n        return this.errorCodewords;\n    };\n    SymbolInfo.prototype.getDataLengthForInterleavedBlock = function (index) {\n        return this.rsBlockData;\n    };\n    SymbolInfo.prototype.getErrorLengthForInterleavedBlock = function (index) {\n        return this.rsBlockError;\n    };\n    return SymbolInfo;\n}());\nexport default SymbolInfo;\nvar DataMatrixSymbolInfo144 = /** @class */ (function (_super) {\n    __extends(DataMatrixSymbolInfo144, _super);\n    function DataMatrixSymbolInfo144() {\n        return _super.call(this, false, 1558, 620, 22, 22, 36, -1, 62) || this;\n    }\n    DataMatrixSymbolInfo144.prototype.getInterleavedBlockCount = function () {\n        return 10;\n    };\n    DataMatrixSymbolInfo144.prototype.getDataLengthForInterleavedBlock = function (index) {\n        return index <= 8 ? 156 : 155;\n    };\n    return DataMatrixSymbolInfo144;\n}(SymbolInfo));\nexport var PROD_SYMBOLS = [\n    new SymbolInfo(false, 3, 5, 8, 8, 1),\n    new SymbolInfo(false, 5, 7, 10, 10, 1),\n    /*rect*/ new SymbolInfo(true, 5, 7, 16, 6, 1),\n    new SymbolInfo(false, 8, 10, 12, 12, 1),\n    /*rect*/ new SymbolInfo(true, 10, 11, 14, 6, 2),\n    new SymbolInfo(false, 12, 12, 14, 14, 1),\n    /*rect*/ new SymbolInfo(true, 16, 14, 24, 10, 1),\n    new SymbolInfo(false, 18, 14, 16, 16, 1),\n    new SymbolInfo(false, 22, 18, 18, 18, 1),\n    /*rect*/ new SymbolInfo(true, 22, 18, 16, 10, 2),\n    new SymbolInfo(false, 30, 20, 20, 20, 1),\n    /*rect*/ new SymbolInfo(true, 32, 24, 16, 14, 2),\n    new SymbolInfo(false, 36, 24, 22, 22, 1),\n    new SymbolInfo(false, 44, 28, 24, 24, 1),\n    /*rect*/ new SymbolInfo(true, 49, 28, 22, 14, 2),\n    new SymbolInfo(false, 62, 36, 14, 14, 4),\n    new SymbolInfo(false, 86, 42, 16, 16, 4),\n    new SymbolInfo(false, 114, 48, 18, 18, 4),\n    new SymbolInfo(false, 144, 56, 20, 20, 4),\n    new SymbolInfo(false, 174, 68, 22, 22, 4),\n    new SymbolInfo(false, 204, 84, 24, 24, 4, 102, 42),\n    new SymbolInfo(false, 280, 112, 14, 14, 16, 140, 56),\n    new SymbolInfo(false, 368, 144, 16, 16, 16, 92, 36),\n    new SymbolInfo(false, 456, 192, 18, 18, 16, 114, 48),\n    new SymbolInfo(false, 576, 224, 20, 20, 16, 144, 56),\n    new SymbolInfo(false, 696, 272, 22, 22, 16, 174, 68),\n    new SymbolInfo(false, 816, 336, 24, 24, 16, 136, 56),\n    new SymbolInfo(false, 1050, 408, 18, 18, 36, 175, 68),\n    new SymbolInfo(false, 1304, 496, 20, 20, 36, 163, 62),\n    new DataMatrixSymbolInfo144(),\n];\n","var __extends = (this && this.__extends) || (function () {\n    var extendStatics = function (d, b) {\n        extendStatics = Object.setPrototypeOf ||\n            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n        return extendStatics(d, b);\n    };\n    return function (d, b) {\n        extendStatics(d, b);\n        function __() { this.constructor = d; }\n        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n    };\n})();\nimport { C40Encoder } from './C40Encoder';\nimport { TEXT_ENCODATION } from './constants';\nvar TextEncoder = /** @class */ (function (_super) {\n    __extends(TextEncoder, _super);\n    function TextEncoder() {\n        return _super !== null && _super.apply(this, arguments) || this;\n    }\n    TextEncoder.prototype.getEncodingMode = function () {\n        return TEXT_ENCODATION;\n    };\n    TextEncoder.prototype.encodeChar = function (c, sb) {\n        if (c === ' '.charCodeAt(0)) {\n            sb.append(3);\n            return 1;\n        }\n        if (c >= '0'.charCodeAt(0) && c <= '9'.charCodeAt(0)) {\n            sb.append(c - 48 + 4);\n            return 1;\n        }\n        if (c >= 'a'.charCodeAt(0) && c <= 'z'.charCodeAt(0)) {\n            sb.append(c - 97 + 14);\n            return 1;\n        }\n        if (c < ' '.charCodeAt(0)) {\n            sb.append(0); // Shift 1 Set\n            sb.append(c);\n            return 2;\n        }\n        if (c <= '/'.charCodeAt(0)) {\n            sb.append(1); // Shift 2 Set\n            sb.append(c - 33);\n            return 2;\n        }\n        if (c <= '@'.charCodeAt(0)) {\n            sb.append(1); // Shift 2 Set\n            sb.append(c - 58 + 15);\n            return 2;\n        }\n        if (c >= '['.charCodeAt(0) && c <= '_'.charCodeAt(0)) {\n            sb.append(1); // Shift 2 Set\n            sb.append(c - 91 + 22);\n            return 2;\n        }\n        if (c === '`'.charCodeAt(0)) {\n            sb.append(2); // Shift 3 Set\n            sb.append(0); // '`' - 96 == 0\n            return 2;\n        }\n        if (c <= 'Z'.charCodeAt(0)) {\n            sb.append(2); // Shift 3 Set\n            sb.append(c - 65 + 1);\n            return 2;\n        }\n        if (c <= 127) {\n            sb.append(2); // Shift 3 Set\n            sb.append(c - 123 + 27);\n            return 2;\n        }\n        sb.append(1 + \"\\u001E\"); // Shift 2, Upper Shift\n        var len = 2;\n        len += this.encodeChar(c - 128, sb);\n        return len;\n    };\n    return TextEncoder;\n}(C40Encoder));\nexport { TextEncoder };\n","var __extends = (this && this.__extends) || (function () {\n    var extendStatics = function (d, b) {\n        extendStatics = Object.setPrototypeOf ||\n            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n        return extendStatics(d, b);\n    };\n    return function (d, b) {\n        extendStatics(d, b);\n        function __() { this.constructor = d; }\n        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n    };\n})();\nimport StringUtils from '../../common/StringUtils';\nimport StringBuilder from '../../util/StringBuilder';\nimport { C40Encoder } from './C40Encoder';\nimport HighLevelEncoder from './HighLevelEncoder';\nimport { X12_ENCODATION, ASCII_ENCODATION, X12_UNLATCH } from './constants';\nvar X12Encoder = /** @class */ (function (_super) {\n    __extends(X12Encoder, _super);\n    function X12Encoder() {\n        return _super !== null && _super.apply(this, arguments) || this;\n    }\n    X12Encoder.prototype.getEncodingMode = function () {\n        return X12_ENCODATION;\n    };\n    X12Encoder.prototype.encode = function (context) {\n        // step C\n        var buffer = new StringBuilder();\n        while (context.hasMoreCharacters()) {\n            var c = context.getCurrentChar();\n            context.pos++;\n            this.encodeChar(c, buffer);\n            var count = buffer.length();\n            if (count % 3 === 0) {\n                this.writeNextTriplet(context, buffer);\n                var newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, this.getEncodingMode());\n                if (newMode !== this.getEncodingMode()) {\n                    // Return to ASCII encodation, which will actually handle latch to new mode\n                    context.signalEncoderChange(ASCII_ENCODATION);\n                    break;\n                }\n            }\n        }\n        this.handleEOD(context, buffer);\n    };\n    X12Encoder.prototype.encodeChar = function (c, sb) {\n        switch (c) {\n            case 13: // CR (Carriage return)\n                sb.append(0);\n                break;\n            case '*'.charCodeAt(0):\n                sb.append(1);\n                break;\n            case '>'.charCodeAt(0):\n                sb.append(2);\n                break;\n            case ' '.charCodeAt(0):\n                sb.append(3);\n                break;\n            default:\n                if (c >= '0'.charCodeAt(0) && c <= '9'.charCodeAt(0)) {\n                    sb.append(c - 48 + 4);\n                }\n                else if (c >= 'A'.charCodeAt(0) && c <= 'Z'.charCodeAt(0)) {\n                    sb.append(c - 65 + 14);\n                }\n                else {\n                    HighLevelEncoder.illegalCharacter(StringUtils.getCharAt(c));\n                }\n                break;\n        }\n        return 1;\n    };\n    X12Encoder.prototype.handleEOD = function (context, buffer) {\n        context.updateSymbolInfo();\n        var available = context.getSymbolInfo().getDataCapacity() - context.getCodewordCount();\n        var count = buffer.length();\n        context.pos -= count;\n        if (context.getRemainingCharacters() > 1 ||\n            available > 1 ||\n            context.getRemainingCharacters() !== available) {\n            context.writeCodeword(X12_UNLATCH);\n        }\n        if (context.getNewEncoding() < 0) {\n            context.signalEncoderChange(ASCII_ENCODATION);\n        }\n    };\n    return X12Encoder;\n}(C40Encoder));\nexport { X12Encoder };\n","var _a;\n/**\n * Lookup table which factors to use for which number of error correction codewords.\n * See FACTORS.\n */\nexport var FACTOR_SETS = [\n    5, 7, 10, 11, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 62, 68,\n];\n/**\n * Precomputed polynomial factors for ECC 200.\n */\nexport var FACTORS = [\n    [228, 48, 15, 111, 62],\n    [23, 68, 144, 134, 240, 92, 254],\n    [28, 24, 185, 166, 223, 248, 116, 255, 110, 61],\n    [175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120],\n    [41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242],\n    [156, 97, 192, 252, 95, 9, 157, 119, 138, 45, 18, 186, 83, 185],\n    [\n        83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48, 90,\n        188,\n    ],\n    [\n        15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27,\n        174, 186, 172,\n    ],\n    [\n        52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172,\n        254, 124, 12, 181, 184, 96, 50, 193,\n    ],\n    [\n        211, 231, 43, 97, 71, 96, 103, 174, 37, 151, 170, 53, 75, 34, 249, 121, 17,\n        138, 110, 213, 141, 136, 120, 151, 233, 168, 93, 255,\n    ],\n    [\n        245, 127, 242, 218, 130, 250, 162, 181, 102, 120, 84, 179, 220, 251, 80,\n        182, 229, 18, 2, 4, 68, 33, 101, 137, 95, 119, 115, 44, 175, 184, 59, 25,\n        225, 98, 81, 112,\n    ],\n    [\n        77, 193, 137, 31, 19, 38, 22, 153, 247, 105, 122, 2, 245, 133, 242, 8, 175,\n        95, 100, 9, 167, 105, 214, 111, 57, 121, 21, 1, 253, 57, 54, 101, 248, 202,\n        69, 50, 150, 177, 226, 5, 9, 5,\n    ],\n    [\n        245, 132, 172, 223, 96, 32, 117, 22, 238, 133, 238, 231, 205, 188, 237, 87,\n        191, 106, 16, 147, 118, 23, 37, 90, 170, 205, 131, 88, 120, 100, 66, 138,\n        186, 240, 82, 44, 176, 87, 187, 147, 160, 175, 69, 213, 92, 253, 225, 19,\n    ],\n    [\n        175, 9, 223, 238, 12, 17, 220, 208, 100, 29, 175, 170, 230, 192, 215, 235,\n        150, 159, 36, 223, 38, 200, 132, 54, 228, 146, 218, 234, 117, 203, 29, 232,\n        144, 238, 22, 150, 201, 117, 62, 207, 164, 13, 137, 245, 127, 67, 247, 28,\n        155, 43, 203, 107, 233, 53, 143, 46,\n    ],\n    [\n        242, 93, 169, 50, 144, 210, 39, 118, 202, 188, 201, 189, 143, 108, 196, 37,\n        185, 112, 134, 230, 245, 63, 197, 190, 250, 106, 185, 221, 175, 64, 114, 71,\n        161, 44, 147, 6, 27, 218, 51, 63, 87, 10, 40, 130, 188, 17, 163, 31, 176,\n        170, 4, 107, 232, 7, 94, 166, 224, 124, 86, 47, 11, 204,\n    ],\n    [\n        220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127,\n        213, 136, 248, 180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227, 236,\n        66, 139, 153, 185, 202, 167, 179, 25, 220, 232, 96, 210, 231, 136, 223, 239,\n        181, 241, 59, 52, 172, 25, 49, 232, 211, 189, 64, 54, 108, 153, 132, 63, 96,\n        103, 82, 186,\n    ],\n];\nexport var /*final*/ MODULO_VALUE = 0x12d;\nvar static_LOG = function (LOG, ALOG) {\n    var p = 1;\n    for (var i = 0; i < 255; i++) {\n        ALOG[i] = p;\n        LOG[p] = i;\n        p *= 2;\n        if (p >= 256) {\n            p ^= MODULO_VALUE;\n        }\n    }\n    return {\n        LOG: LOG,\n        ALOG: ALOG,\n    };\n};\nexport var LOG = (_a = static_LOG([], []), _a.LOG), ALOG = _a.ALOG;\nexport var SymbolShapeHint;\n(function (SymbolShapeHint) {\n    SymbolShapeHint[SymbolShapeHint[\"FORCE_NONE\"] = 0] = \"FORCE_NONE\";\n    SymbolShapeHint[SymbolShapeHint[\"FORCE_SQUARE\"] = 1] = \"FORCE_SQUARE\";\n    SymbolShapeHint[SymbolShapeHint[\"FORCE_RECTANGLE\"] = 2] = \"FORCE_RECTANGLE\";\n})(SymbolShapeHint || (SymbolShapeHint = {}));\n/**\n * Padding character\n */\nexport var PAD = 129;\n/**\n * mode latch to C40 encodation mode\n */\nexport var LATCH_TO_C40 = 230;\n/**\n * mode latch to Base 256 encodation mode\n */\nexport var LATCH_TO_BASE256 = 231;\n/**\n * FNC1 Codeword\n */\n// private static FNC1 = 232;\n/**\n * Structured Append Codeword\n */\n// private static STRUCTURED_APPEND = 233;\n/**\n * Reader Programming\n */\n// private static READER_PROGRAMMING = 234;\n/**\n * Upper Shift\n */\nexport var UPPER_SHIFT = 235;\n/**\n * 05 Macro\n */\nexport var MACRO_05 = 236;\n/**\n * 06 Macro\n */\nexport var MACRO_06 = 237;\n/**\n * mode latch to ANSI X.12 encodation mode\n */\nexport var LATCH_TO_ANSIX12 = 238;\n/**\n * mode latch to Text encodation mode\n */\nexport var LATCH_TO_TEXT = 239;\n/**\n * mode latch to EDIFACT encodation mode\n */\nexport var LATCH_TO_EDIFACT = 240;\n/**\n * ECI character (Extended Channel Interpretation)\n */\n// private export const ECI = 241;\n/**\n * Unlatch from C40 encodation\n */\nexport var C40_UNLATCH = 254;\n/**\n * Unlatch from X12 encodation\n */\nexport var X12_UNLATCH = 254;\n/**\n * 05 Macro header\n */\nexport var MACRO_05_HEADER = '[)>\\u001E05\\u001D';\n/**\n * 06 Macro header\n */\nexport var MACRO_06_HEADER = '[)>\\u001E06\\u001D';\n/**\n * Macro trailer\n */\nexport var MACRO_TRAILER = '\\u001E\\u0004';\nexport var ASCII_ENCODATION = 0;\nexport var C40_ENCODATION = 1;\nexport var TEXT_ENCODATION = 2;\nexport var X12_ENCODATION = 3;\nexport var EDIFACT_ENCODATION = 4;\nexport var BASE256_ENCODATION = 5;\n","var __extends = (this && this.__extends) || (function () {\n    var extendStatics = function (d, b) {\n        extendStatics = Object.setPrototypeOf ||\n            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n        return extendStatics(d, b);\n    };\n    return function (d, b) {\n        extendStatics(d, b);\n        function __() { this.constructor = d; }\n        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n    };\n})();\nvar __values = (this && this.__values) || function(o) {\n    var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n    if (m) return m.call(o);\n    if (o && typeof o.length === \"number\") return {\n        next: function () {\n            if (o && i >= o.length) o = void 0;\n            return { value: o && o[i++], done: !o };\n        }\n    };\n    throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n};\nvar __read = (this && this.__read) || function (o, n) {\n    var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n    if (!m) return o;\n    var i = m.call(o), r, ar = [], e;\n    try {\n        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n    }\n    catch (error) { e = { error: error }; }\n    finally {\n        try {\n            if (r && !r.done && (m = i[\"return\"])) m.call(i);\n        }\n        finally { if (e) throw e.error; }\n    }\n    return ar;\n};\nvar __spread = (this && this.__spread) || function () {\n    for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));\n    return ar;\n};\nimport { MACRO_05_HEADER, MACRO_06_HEADER, MACRO_TRAILER, } from './constants';\nimport HighLevelEncoder from './HighLevelEncoder';\nimport { MinimalECIInput } from '../../common/MinimalECIInput';\nimport Integer from '../../util/Integer';\nvar Mode;\n(function (Mode) {\n    Mode[Mode[\"ASCII\"] = 0] = \"ASCII\";\n    Mode[Mode[\"C40\"] = 1] = \"C40\";\n    Mode[Mode[\"TEXT\"] = 2] = \"TEXT\";\n    Mode[Mode[\"X12\"] = 3] = \"X12\";\n    Mode[Mode[\"EDF\"] = 4] = \"EDF\";\n    Mode[Mode[\"B256\"] = 5] = \"B256\";\n})(Mode || (Mode = {}));\nvar C40_SHIFT2_CHARS = [\n    '!',\n    '\"',\n    '#',\n    '$',\n    '%',\n    '&',\n    \"'\",\n    '(',\n    ')',\n    '*',\n    '+',\n    ',',\n    '-',\n    '.',\n    '/',\n    ':',\n    ';',\n    '<',\n    '=',\n    '>',\n    '?',\n    '@',\n    '[',\n    '\\\\',\n    ']',\n    '^',\n    '_',\n];\nvar MinimalEncoder = /** @class */ (function () {\n    function MinimalEncoder() {\n    }\n    MinimalEncoder.isExtendedASCII = function (ch, fnc1) {\n        return ch !== fnc1 && ch >= 128 && ch <= 255;\n    };\n    MinimalEncoder.isInC40Shift1Set = function (ch) {\n        return ch <= 31;\n    };\n    MinimalEncoder.isInC40Shift2Set = function (ch, fnc1) {\n        var e_1, _a;\n        try {\n            for (var C40_SHIFT2_CHARS_1 = __values(C40_SHIFT2_CHARS), C40_SHIFT2_CHARS_1_1 = C40_SHIFT2_CHARS_1.next(); !C40_SHIFT2_CHARS_1_1.done; C40_SHIFT2_CHARS_1_1 = C40_SHIFT2_CHARS_1.next()) {\n                var c40Shift2Char = C40_SHIFT2_CHARS_1_1.value;\n                if (c40Shift2Char.charCodeAt(0) === ch) {\n                    return true;\n                }\n            }\n        }\n        catch (e_1_1) { e_1 = { error: e_1_1 }; }\n        finally {\n            try {\n                if (C40_SHIFT2_CHARS_1_1 && !C40_SHIFT2_CHARS_1_1.done && (_a = C40_SHIFT2_CHARS_1.return)) _a.call(C40_SHIFT2_CHARS_1);\n            }\n            finally { if (e_1) throw e_1.error; }\n        }\n        return ch === fnc1;\n    };\n    MinimalEncoder.isInTextShift1Set = function (ch) {\n        return this.isInC40Shift1Set(ch);\n    };\n    MinimalEncoder.isInTextShift2Set = function (ch, fnc1) {\n        return this.isInC40Shift2Set(ch, fnc1);\n    };\n    /**\n     * Performs message encoding of a DataMatrix message\n     *\n     * @param msg the message\n     * @param priorityCharset The preferred {@link Charset}. When the value of the argument is null, the algorithm\n     *   chooses charsets that leads to a minimal representation. Otherwise the algorithm will use the priority\n     *   charset to encode any character in the input that can be encoded by it if the charset is among the\n     *   supported charsets.\n     * @param fnc1 denotes the character in the input that represents the FNC1 character or -1 if this is not a GS1\n     *   bar code. If the value is not -1 then a FNC1 is also prepended.\n     * @param shape requested shape.\n     * @return the encoded message (the char values range from 0 to 255)\n     */\n    MinimalEncoder.encodeHighLevel = function (msg, priorityCharset, fnc1, shape) {\n        if (priorityCharset === void 0) { priorityCharset = null; }\n        if (fnc1 === void 0) { fnc1 = -1; }\n        if (shape === void 0) { shape = 0 /* FORCE_NONE */; }\n        var macroId = 0;\n        if (msg.startsWith(MACRO_05_HEADER) && msg.endsWith(MACRO_TRAILER)) {\n            macroId = 5;\n            msg = msg.substring(MACRO_05_HEADER.length, msg.length - 2);\n        }\n        else if (msg.startsWith(MACRO_06_HEADER) && msg.endsWith(MACRO_TRAILER)) {\n            macroId = 6;\n            msg = msg.substring(MACRO_06_HEADER.length, msg.length - 2);\n        }\n        return decodeURIComponent(escape(String.fromCharCode.apply(String, __spread(this.encode(msg, priorityCharset, fnc1, shape, macroId)))));\n    };\n    /**\n     * Encodes input minimally and returns an array of the codewords\n     *\n     * @param input The string to encode\n     * @param priorityCharset The preferred {@link Charset}. When the value of the argument is null, the algorithm\n     *   chooses charsets that leads to a minimal representation. Otherwise the algorithm will use the priority\n     *   charset to encode any character in the input that can be encoded by it if the charset is among the\n     *   supported charsets.\n     * @param fnc1 denotes the character in the input that represents the FNC1 character or -1 if this is not a GS1\n     *   bar code. If the value is not -1 then a FNC1 is also prepended.\n     * @param shape requested shape.\n     * @param macroId Prepends the specified macro function in case that a value of 5 or 6 is specified.\n     * @return An array of bytes representing the codewords of a minimal encoding.\n     */\n    MinimalEncoder.encode = function (input, priorityCharset, fnc1, shape, macroId) {\n        return this.encodeMinimally(new Input(input, priorityCharset, fnc1, shape, macroId)).getBytes();\n    };\n    MinimalEncoder.addEdge = function (edges, edge) {\n        var vertexIndex = edge.fromPosition + edge.characterLength;\n        if (edges[vertexIndex][edge.getEndMode()] === null ||\n            edges[vertexIndex][edge.getEndMode()].cachedTotalSize >\n                edge.cachedTotalSize) {\n            edges[vertexIndex][edge.getEndMode()] = edge;\n        }\n    };\n    /** @return the number of words in which the string starting at from can be encoded in c40 or text mode.\n     *  The number of characters encoded is returned in characterLength.\n     *  The number of characters encoded is also minimal in the sense that the algorithm stops as soon\n     *  as a character encoding fills a C40 word competely (three C40 values). An exception is at the\n     *  end of the string where two C40 values are allowed (according to the spec the third c40 value\n     *  is filled  with 0 (Shift 1) in this case).\n     */\n    MinimalEncoder.getNumberOfC40Words = function (input, from, c40, characterLength) {\n        var thirdsCount = 0;\n        for (var i = from; i < input.length(); i++) {\n            if (input.isECI(i)) {\n                characterLength[0] = 0;\n                return 0;\n            }\n            var ci = input.charAt(i);\n            if ((c40 && HighLevelEncoder.isNativeC40(ci)) ||\n                (!c40 && HighLevelEncoder.isNativeText(ci))) {\n                thirdsCount++; // native\n            }\n            else if (!MinimalEncoder.isExtendedASCII(ci, input.getFNC1Character())) {\n                thirdsCount += 2; // shift\n            }\n            else {\n                var asciiValue = ci & 0xff;\n                if (asciiValue >= 128 &&\n                    ((c40 && HighLevelEncoder.isNativeC40(asciiValue - 128)) ||\n                        (!c40 && HighLevelEncoder.isNativeText(asciiValue - 128)))) {\n                    thirdsCount += 3; // shift, Upper shift\n                }\n                else {\n                    thirdsCount += 4; // shift, Upper shift, shift\n                }\n            }\n            if (thirdsCount % 3 === 0 ||\n                ((thirdsCount - 2) % 3 === 0 && i + 1 === input.length())) {\n                characterLength[0] = i - from + 1;\n                return Math.ceil(thirdsCount / 3.0);\n            }\n        }\n        characterLength[0] = 0;\n        return 0;\n    };\n    MinimalEncoder.addEdges = function (input, edges, from, previous) {\n        var e_2, _a;\n        if (input.isECI(from)) {\n            this.addEdge(edges, new Edge(input, Mode.ASCII, from, 1, previous));\n            return;\n        }\n        var ch = input.charAt(from);\n        if (previous === null || previous.getEndMode() !== Mode.EDF) {\n            // not possible to unlatch a full EDF edge to something\n            // else\n            if (HighLevelEncoder.isDigit(ch) &&\n                input.haveNCharacters(from, 2) &&\n                HighLevelEncoder.isDigit(input.charAt(from + 1))) {\n                // two digits ASCII encoded\n                this.addEdge(edges, new Edge(input, Mode.ASCII, from, 2, previous));\n            }\n            else {\n                // one ASCII encoded character or an extended character via Upper Shift\n                this.addEdge(edges, new Edge(input, Mode.ASCII, from, 1, previous));\n            }\n            var modes = [Mode.C40, Mode.TEXT];\n            try {\n                for (var modes_1 = __values(modes), modes_1_1 = modes_1.next(); !modes_1_1.done; modes_1_1 = modes_1.next()) {\n                    var mode = modes_1_1.value;\n                    var characterLength = [];\n                    if (MinimalEncoder.getNumberOfC40Words(input, from, mode === Mode.C40, characterLength) > 0) {\n                        this.addEdge(edges, new Edge(input, mode, from, characterLength[0], previous));\n                    }\n                }\n            }\n            catch (e_2_1) { e_2 = { error: e_2_1 }; }\n            finally {\n                try {\n                    if (modes_1_1 && !modes_1_1.done && (_a = modes_1.return)) _a.call(modes_1);\n                }\n                finally { if (e_2) throw e_2.error; }\n            }\n            if (input.haveNCharacters(from, 3) &&\n                HighLevelEncoder.isNativeX12(input.charAt(from)) &&\n                HighLevelEncoder.isNativeX12(input.charAt(from + 1)) &&\n                HighLevelEncoder.isNativeX12(input.charAt(from + 2))) {\n                this.addEdge(edges, new Edge(input, Mode.X12, from, 3, previous));\n            }\n            this.addEdge(edges, new Edge(input, Mode.B256, from, 1, previous));\n        }\n        // We create 4 EDF edges,  with 1, 2 3 or 4 characters length. The fourth normally doesn't have a latch to ASCII\n        // unless it is 2 characters away from the end of the input.\n        var i;\n        for (i = 0; i < 3; i++) {\n            var pos = from + i;\n            if (input.haveNCharacters(pos, 1) &&\n                HighLevelEncoder.isNativeEDIFACT(input.charAt(pos))) {\n                this.addEdge(edges, new Edge(input, Mode.EDF, from, i + 1, previous));\n            }\n            else {\n                break;\n            }\n        }\n        if (i === 3 &&\n            input.haveNCharacters(from, 4) &&\n            HighLevelEncoder.isNativeEDIFACT(input.charAt(from + 3))) {\n            this.addEdge(edges, new Edge(input, Mode.EDF, from, 4, previous));\n        }\n    };\n    MinimalEncoder.encodeMinimally = function (input) {\n        /* The minimal encoding is computed by Dijkstra. The acyclic graph is modeled as follows:\n         * A vertex represents a combination of a position in the input and an encoding mode where position 0\n         * denotes the position left of the first character, 1 the position left of the second character and so on.\n         * Likewise the end vertices are located after the last character at position input.length().\n         * For any position there might be up to six vertices, one for each of the encoding types ASCII, C40, TEXT, X12,\n         * EDF and B256.\n         *\n         * As an example consider the input string \"ABC123\" then at position 0 there is only one vertex with the default\n         * ASCII encodation. At position 3 there might be vertices for the types ASCII, C40, X12, EDF and B256.\n         *\n         * An edge leading to such a vertex encodes one or more of the characters left of the position that the vertex\n         * represents. It encodes the characters in the encoding mode of the vertex that it ends on. In other words,\n         * all edges leading to a particular vertex encode the same characters (the length of the suffix can vary) using the same\n         * encoding mode.\n         * As an example consider the input string \"ABC123\" and the vertex (4,EDF). Possible edges leading to this vertex\n         * are:\n         *   (0,ASCII)  --EDF(ABC1)--> (4,EDF)\n         *   (1,ASCII)  --EDF(BC1)-->  (4,EDF)\n         *   (1,B256)   --EDF(BC1)-->  (4,EDF)\n         *   (1,EDF)    --EDF(BC1)-->  (4,EDF)\n         *   (2,ASCII)  --EDF(C1)-->   (4,EDF)\n         *   (2,B256)   --EDF(C1)-->   (4,EDF)\n         *   (2,EDF)    --EDF(C1)-->   (4,EDF)\n         *   (3,ASCII)  --EDF(1)-->    (4,EDF)\n         *   (3,B256)   --EDF(1)-->    (4,EDF)\n         *   (3,EDF)    --EDF(1)-->    (4,EDF)\n         *   (3,C40)    --EDF(1)-->    (4,EDF)\n         *   (3,X12)    --EDF(1)-->    (4,EDF)\n         *\n         * The edges leading to a vertex are stored in such a way that there is a fast way to enumerate the edges ending\n         * on a particular vertex.\n         *\n         * The algorithm processes the vertices in order of their position thereby performing the following:\n         *\n         * For every vertex at position i the algorithm enumerates the edges ending on the vertex and removes all but the\n         * shortest from that list.\n         * Then it processes the vertices for the position i+1. If i+1 == input.length() then the algorithm ends\n         * and chooses the the edge with the smallest size from any of the edges leading to vertices at this position.\n         * Otherwise the algorithm computes all possible outgoing edges for the vertices at the position i+1\n         *\n         * Examples:\n         * The process is illustrated by showing the graph (edges) after each iteration from left to right over the input:\n         * An edge is drawn as follows \"(\" + fromVertex + \") -- \" + encodingMode + \"(\" + encodedInput + \") (\" +\n         * accumulatedSize + \") --> (\" + toVertex + \")\"\n         *\n         * Example 1 encoding the string \"ABCDEFG\":\n         *\n         *\n         * Situation after adding edges to the start vertex (0,ASCII)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII)\n         * (0,ASCII) B256(A) (3) --> (1,B256)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF)\n         * (0,ASCII) C40(ABC) (3) --> (3,C40)\n         * (0,ASCII) TEXT(ABC) (5) --> (3,TEXT)\n         * (0,ASCII) X12(ABC) (3) --> (3,X12)\n         * (0,ASCII) EDF(ABC) (4) --> (3,EDF)\n         * (0,ASCII) EDF(ABCD) (4) --> (4,EDF)\n         *\n         * Situation after adding edges to vertices at position 1\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII)\n         * (0,ASCII) B256(A) (3) --> (1,B256)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF)\n         * (0,ASCII) C40(ABC) (3) --> (3,C40)\n         * (0,ASCII) TEXT(ABC) (5) --> (3,TEXT)\n         * (0,ASCII) X12(ABC) (3) --> (3,X12)\n         * (0,ASCII) EDF(ABC) (4) --> (3,EDF)\n         * (0,ASCII) EDF(ABCD) (4) --> (4,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) B256(B) (4) --> (2,B256)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) EDF(BC) (5) --> (3,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) C40(BCD) (4) --> (4,C40)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) TEXT(BCD) (6) --> (4,TEXT)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) X12(BCD) (4) --> (4,X12)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) EDF(BCD) (5) --> (4,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) EDF(BCDE) (5) --> (5,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) ASCII(B) (4) --> (2,ASCII)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256)\n         * (0,ASCII) B256(A) (3) --> (1,B256) EDF(BC) (6) --> (3,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) C40(BCD) (5) --> (4,C40)\n         * (0,ASCII) B256(A) (3) --> (1,B256) TEXT(BCD) (7) --> (4,TEXT)\n         * (0,ASCII) B256(A) (3) --> (1,B256) X12(BCD) (5) --> (4,X12)\n         * (0,ASCII) B256(A) (3) --> (1,B256) EDF(BCD) (6) --> (4,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) EDF(BCDE) (6) --> (5,EDF)\n         *\n         * Edge \"(1,ASCII) ASCII(B) (2) --> (2,ASCII)\" is minimal for the vertex (2,ASCII) so that edge \"(1,B256) ASCII(B) (4) --> (2,ASCII)\" is removed.\n         * Edge \"(1,B256) B256(B) (3) --> (2,B256)\" is minimal for the vertext (2,B256) so that the edge \"(1,ASCII) B256(B) (4) --> (2,B256)\" is removed.\n         *\n         * Situation after adding edges to vertices at position 2\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII)\n         * (0,ASCII) B256(A) (3) --> (1,B256)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF)\n         * (0,ASCII) C40(ABC) (3) --> (3,C40)\n         * (0,ASCII) TEXT(ABC) (5) --> (3,TEXT)\n         * (0,ASCII) X12(ABC) (3) --> (3,X12)\n         * (0,ASCII) EDF(ABC) (4) --> (3,EDF)\n         * (0,ASCII) EDF(ABCD) (4) --> (4,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) EDF(BC) (5) --> (3,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) C40(BCD) (4) --> (4,C40)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) TEXT(BCD) (6) --> (4,TEXT)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) X12(BCD) (4) --> (4,X12)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) EDF(BCD) (5) --> (4,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) EDF(BCDE) (5) --> (5,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256)\n         * (0,ASCII) B256(A) (3) --> (1,B256) EDF(BC) (6) --> (3,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) C40(BCD) (5) --> (4,C40)\n         * (0,ASCII) B256(A) (3) --> (1,B256) TEXT(BCD) (7) --> (4,TEXT)\n         * (0,ASCII) B256(A) (3) --> (1,B256) X12(BCD) (5) --> (4,X12)\n         * (0,ASCII) B256(A) (3) --> (1,B256) EDF(BCD) (6) --> (4,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) EDF(BCDE) (6) --> (5,EDF)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF) ASCII(C) (5) --> (3,ASCII)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF) B256(C) (6) --> (3,B256)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF) EDF(CD) (7) --> (4,EDF)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF) C40(CDE) (6) --> (5,C40)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF) TEXT(CDE) (8) --> (5,TEXT)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF) X12(CDE) (6) --> (5,X12)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF) EDF(CDE) (7) --> (5,EDF)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF) EDF(CDEF) (7) --> (6,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) ASCII(C) (3) --> (3,ASCII)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) B256(C) (5) --> (3,B256)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) EDF(CD) (6) --> (4,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) C40(CDE) (5) --> (5,C40)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) TEXT(CDE) (7) --> (5,TEXT)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) X12(CDE) (5) --> (5,X12)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) EDF(CDE) (6) --> (5,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) EDF(CDEF) (6) --> (6,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) ASCII(C) (4) --> (3,ASCII)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) B256(C) (4) --> (3,B256)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) EDF(CD) (6) --> (4,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) C40(CDE) (5) --> (5,C40)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) TEXT(CDE) (7) --> (5,TEXT)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) X12(CDE) (5) --> (5,X12)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) EDF(CDE) (6) --> (5,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) EDF(CDEF) (6) --> (6,EDF)\n         *\n         * Edge \"(2,ASCII) ASCII(C) (3) --> (3,ASCII)\" is minimal for the vertex (3,ASCII) so that edges \"(2,EDF) ASCII(C) (5) --> (3,ASCII)\"\n         * and \"(2,B256) ASCII(C) (4) --> (3,ASCII)\" can be removed.\n         * Edge \"(0,ASCII) EDF(ABC) (4) --> (3,EDF)\" is minimal for the vertex (3,EDF) so that edges \"(1,ASCII) EDF(BC) (5) --> (3,EDF)\"\n         * and \"(1,B256) EDF(BC) (6) --> (3,EDF)\" can be removed.\n         * Edge \"(2,B256) B256(C) (4) --> (3,B256)\" is minimal for the vertex (3,B256) so that edges \"(2,ASCII) B256(C) (5) --> (3,B256)\"\n         * and \"(2,EDF) B256(C) (6) --> (3,B256)\" can be removed.\n         *\n         * This continues for vertices 3 thru 7\n         *\n         * Situation after adding edges to vertices at position 7\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII)\n         * (0,ASCII) B256(A) (3) --> (1,B256)\n         * (0,ASCII) EDF(AB) (4) --> (2,EDF)\n         * (0,ASCII) C40(ABC) (3) --> (3,C40)\n         * (0,ASCII) TEXT(ABC) (5) --> (3,TEXT)\n         * (0,ASCII) X12(ABC) (3) --> (3,X12)\n         * (0,ASCII) EDF(ABC) (4) --> (3,EDF)\n         * (0,ASCII) EDF(ABCD) (4) --> (4,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) C40(BCD) (4) --> (4,C40)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) TEXT(BCD) (6) --> (4,TEXT)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) X12(BCD) (4) --> (4,X12)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) EDF(BCDE) (5) --> (5,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256)\n         * (0,ASCII) C40(ABC) (3) --> (3,C40) C40(DEF) (5) --> (6,C40)\n         * (0,ASCII) X12(ABC) (3) --> (3,X12) X12(DEF) (5) --> (6,X12)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) ASCII(C) (3) --> (3,ASCII)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) C40(CDE) (5) --> (5,C40)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) TEXT(CDE) (7) --> (5,TEXT)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) X12(CDE) (5) --> (5,X12)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) EDF(CDEF) (6) --> (6,EDF)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) C40(BCD) (4) --> (4,C40) C40(EFG) (6) --> (7,C40)    //Solution 1\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) X12(BCD) (4) --> (4,X12) X12(EFG) (6) --> (7,X12)    //Solution 2\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) B256(C) (4) --> (3,B256)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) ASCII(C) (3) --> (3,ASCII) ASCII(D) (4) --> (4,ASCII)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) ASCII(C) (3) --> (3,ASCII) TEXT(DEF) (8) --> (6,TEXT)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) ASCII(C) (3) --> (3,ASCII) EDF(DEFG) (7) --> (7,EDF)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) B256(C) (4) --> (3,B256) B256(D) (5) --> (4,B256)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) ASCII(C) (3) --> (3,ASCII) ASCII(D) (4) --> (4,ASCII) ASCII(E) (5) --> (5,ASCII)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) ASCII(C) (3) --> (3,ASCII) ASCII(D) (4) --> (4,ASCII) TEXT(EFG) (9) --> (7,TEXT)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) B256(C) (4) --> (3,B256) B256(D) (5) --> (4,B256) B256(E) (6) --> (5,B256)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) ASCII(C) (3) --> (3,ASCII) ASCII(D) (4) --> (4,ASCII) ASCII(E) (5) --> (5,ASCII) ASCII(F) (6) --> (6,ASCII)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) B256(C) (4) --> (3,B256) B256(D) (5) --> (4,B256) B256(E) (6) --> (5,B256) B256(F) (7) --> (6,B256)\n         * (0,ASCII) ASCII(A) (1) --> (1,ASCII) ASCII(B) (2) --> (2,ASCII) ASCII(C) (3) --> (3,ASCII) ASCII(D) (4) --> (4,ASCII) ASCII(E) (5) --> (5,ASCII) ASCII(F) (6) --> (6,ASCII) ASCII(G) (7) --> (7,ASCII)\n         * (0,ASCII) B256(A) (3) --> (1,B256) B256(B) (3) --> (2,B256) B256(C) (4) --> (3,B256) B256(D) (5) --> (4,B256) B256(E) (6) --> (5,B256) B256(F) (7) --> (6,B256) B256(G) (8) --> (7,B256)\n         *\n         * Hence a minimal encoding of \"ABCDEFG\" is either ASCII(A),C40(BCDEFG) or ASCII(A), X12(BCDEFG) with a size of 5 bytes.\n         */\n        var inputLength = input.length();\n        // Array that represents vertices. There is a vertex for every character and mode.\n        // The last dimension in the array below encodes the 6 modes ASCII, C40, TEXT, X12, EDF and B256\n        var edges = Array(inputLength + 1)\n            .fill(null)\n            .map(function () { return Array(6).fill(0); });\n        this.addEdges(input, edges, 0, null);\n        for (var i = 1; i <= inputLength; i++) {\n            for (var j = 0; j < 6; j++) {\n                if (edges[i][j] !== null && i < inputLength) {\n                    this.addEdges(input, edges, i, edges[i][j]);\n                }\n            }\n            // optimize memory by removing edges that have been passed.\n            for (var j = 0; j < 6; j++) {\n                edges[i - 1][j] = null;\n            }\n        }\n        var minimalJ = -1;\n        var minimalSize = Integer.MAX_VALUE;\n        for (var j = 0; j < 6; j++) {\n            if (edges[inputLength][j] !== null) {\n                var edge = edges[inputLength][j];\n                var size = j >= 1 && j <= 3 ? edge.cachedTotalSize + 1 : edge.cachedTotalSize; // C40, TEXT and X12 need an\n                // extra unlatch at the end\n                if (size < minimalSize) {\n                    minimalSize = size;\n                    minimalJ = j;\n                }\n            }\n        }\n        if (minimalJ < 0) {\n            throw new Error('Failed to encode \"' + input + '\"');\n        }\n        return new Result(edges[inputLength][minimalJ]);\n    };\n    return MinimalEncoder;\n}());\nexport { MinimalEncoder };\nvar Result = /** @class */ (function () {\n    function Result(solution) {\n        var input = solution.input;\n        var size = 0;\n        var bytesAL = [];\n        var randomizePostfixLength = [];\n        var randomizeLengths = [];\n        if ((solution.mode === Mode.C40 ||\n            solution.mode === Mode.TEXT ||\n            solution.mode === Mode.X12) &&\n            solution.getEndMode() !== Mode.ASCII) {\n            size += this.prepend(Edge.getBytes(254), bytesAL);\n        }\n        var current = solution;\n        while (current !== null) {\n            size += this.prepend(current.getDataBytes(), bytesAL);\n            if (current.previous === null ||\n                current.getPreviousStartMode() !== current.getMode()) {\n                if (current.getMode() === Mode.B256) {\n                    if (size <= 249) {\n                        bytesAL.unshift(size);\n                        size++;\n                    }\n                    else {\n                        bytesAL.unshift(size % 250);\n                        bytesAL.unshift(size / 250 + 249);\n                        size += 2;\n                    }\n                    randomizePostfixLength.push(bytesAL.length);\n                    randomizeLengths.push(size);\n                }\n                this.prepend(current.getLatchBytes(), bytesAL);\n                size = 0;\n            }\n            current = current.previous;\n        }\n        if (input.getMacroId() === 5) {\n            size += this.prepend(Edge.getBytes(236), bytesAL);\n        }\n        else if (input.getMacroId() === 6) {\n            size += this.prepend(Edge.getBytes(237), bytesAL);\n        }\n        if (input.getFNC1Character() > 0) {\n            size += this.prepend(Edge.getBytes(232), bytesAL);\n        }\n        for (var i = 0; i < randomizePostfixLength.length; i++) {\n            this.applyRandomPattern(bytesAL, bytesAL.length - randomizePostfixLength[i], randomizeLengths[i]);\n        }\n        // add padding\n        var capacity = solution.getMinSymbolSize(bytesAL.length);\n        if (bytesAL.length < capacity) {\n            bytesAL.push(129);\n        }\n        while (bytesAL.length < capacity) {\n            bytesAL.push(this.randomize253State(bytesAL.length + 1));\n        }\n        this.bytes = new Uint8Array(bytesAL.length);\n        for (var i = 0; i < this.bytes.length; i++) {\n            this.bytes[i] = bytesAL[i];\n        }\n    }\n    Result.prototype.prepend = function (bytes, into) {\n        for (var i = bytes.length - 1; i >= 0; i--) {\n            into.unshift(bytes[i]);\n        }\n        return bytes.length;\n    };\n    Result.prototype.randomize253State = function (codewordPosition) {\n        var pseudoRandom = ((149 * codewordPosition) % 253) + 1;\n        var tempVariable = 129 + pseudoRandom;\n        return tempVariable <= 254 ? tempVariable : tempVariable - 254;\n    };\n    Result.prototype.applyRandomPattern = function (bytesAL, startPosition, length) {\n        for (var i = 0; i < length; i++) {\n            // See \"B.1 253-state algorithm\n            var Pad_codeword_position = startPosition + i;\n            var Pad_codeword_value = bytesAL[Pad_codeword_position] & 0xff;\n            var pseudo_random_number = ((149 * (Pad_codeword_position + 1)) % 255) + 1;\n            var temp_variable = Pad_codeword_value + pseudo_random_number;\n            bytesAL[Pad_codeword_position] =\n                temp_variable <= 255 ? temp_variable : temp_variable - 256;\n        }\n    };\n    Result.prototype.getBytes = function () {\n        return this.bytes;\n    };\n    return Result;\n}());\nvar Edge = /** @class */ (function () {\n    function Edge(input, mode, fromPosition, characterLength, previous) {\n        this.input = input;\n        this.mode = mode;\n        this.fromPosition = fromPosition;\n        this.characterLength = characterLength;\n        this.previous = previous;\n        this.allCodewordCapacities = [\n            3, 5, 8, 10, 12, 16, 18, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144, 174, 204,\n            280, 368, 456, 576, 696, 816, 1050, 1304, 1558,\n        ];\n        this.squareCodewordCapacities = [\n            3, 5, 8, 12, 18, 22, 30, 36, 44, 62, 86, 114, 144, 174, 204, 280, 368, 456,\n            576, 696, 816, 1050, 1304, 1558,\n        ];\n        this.rectangularCodewordCapacities = [5, 10, 16, 33, 32, 49];\n        if (!(fromPosition + characterLength <= input.length())) {\n            throw new Error('Invalid edge');\n        }\n        var size = previous !== null ? previous.cachedTotalSize : 0;\n        var previousMode = this.getPreviousMode();\n        /*\n         * Switching modes\n         * ASCII -> C40: latch 230\n         * ASCII -> TEXT: latch 239\n         * ASCII -> X12: latch 238\n         * ASCII -> EDF: latch 240\n         * ASCII -> B256: latch 231\n         * C40 -> ASCII: word(c1,c2,c3), 254\n         * TEXT -> ASCII: word(c1,c2,c3), 254\n         * X12 -> ASCII: word(c1,c2,c3), 254\n         * EDIFACT -> ASCII: Unlatch character,0,0,0 or c1,Unlatch character,0,0 or c1,c2,Unlatch character,0 or\n         * c1,c2,c3,Unlatch character\n         * B256 -> ASCII: without latch after n bytes\n         */\n        switch (mode) {\n            case Mode.ASCII:\n                size++;\n                if (input.isECI(fromPosition) ||\n                    MinimalEncoder.isExtendedASCII(input.charAt(fromPosition), input.getFNC1Character())) {\n                    size++;\n                }\n                if (previousMode === Mode.C40 ||\n                    previousMode === Mode.TEXT ||\n                    previousMode === Mode.X12) {\n                    size++; // unlatch 254 to ASCII\n                }\n                break;\n            case Mode.B256:\n                size++;\n                if (previousMode !== Mode.B256) {\n                    size++; // byte count\n                }\n                else if (this.getB256Size() === 250) {\n                    size++; // extra byte count\n                }\n                if (previousMode === Mode.ASCII) {\n                    size++; // latch to B256\n                }\n                else if (previousMode === Mode.C40 ||\n                    previousMode === Mode.TEXT ||\n                    previousMode === Mode.X12) {\n                    size += 2; // unlatch to ASCII, latch to B256\n                }\n                break;\n            case Mode.C40:\n            case Mode.TEXT:\n            case Mode.X12:\n                if (mode === Mode.X12) {\n                    size += 2;\n                }\n                else {\n                    var charLen = [];\n                    size +=\n                        MinimalEncoder.getNumberOfC40Words(input, fromPosition, mode === Mode.C40, charLen) * 2;\n                }\n                if (previousMode === Mode.ASCII || previousMode === Mode.B256) {\n                    size++; // additional byte for latch from ASCII to this mode\n                }\n                else if (previousMode !== mode &&\n                    (previousMode === Mode.C40 ||\n                        previousMode === Mode.TEXT ||\n                        previousMode === Mode.X12)) {\n                    size += 2; // unlatch 254 to ASCII followed by latch to this mode\n                }\n                break;\n            case Mode.EDF:\n                size += 3;\n                if (previousMode === Mode.ASCII || previousMode === Mode.B256) {\n                    size++; // additional byte for latch from ASCII to this mode\n                }\n                else if (previousMode === Mode.C40 ||\n                    previousMode === Mode.TEXT ||\n                    previousMode === Mode.X12) {\n                    size += 2; // unlatch 254 to ASCII followed by latch to this mode\n                }\n                break;\n        }\n        this.cachedTotalSize = size;\n    }\n    // does not count beyond 250\n    Edge.prototype.getB256Size = function () {\n        var cnt = 0;\n        var current = this;\n        while (current !== null && current.mode === Mode.B256 && cnt <= 250) {\n            cnt++;\n            current = current.previous;\n        }\n        return cnt;\n    };\n    Edge.prototype.getPreviousStartMode = function () {\n        return this.previous === null ? Mode.ASCII : this.previous.mode;\n    };\n    Edge.prototype.getPreviousMode = function () {\n        return this.previous === null ? Mode.ASCII : this.previous.getEndMode();\n    };\n    /** Returns Mode.ASCII in case that:\n     *  - Mode is EDIFACT and characterLength is less than 4 or the remaining characters can be encoded in at most 2\n     *    ASCII bytes.\n     *  - Mode is C40, TEXT or X12 and the remaining characters can be encoded in at most 1 ASCII byte.\n     *  Returns mode in all other cases.\n     * */\n    Edge.prototype.getEndMode = function () {\n        if (this.mode === Mode.EDF) {\n            if (this.characterLength < 4) {\n                return Mode.ASCII;\n            }\n            var lastASCII = this.getLastASCII(); // see 5.2.8.2 EDIFACT encodation Rules\n            if (lastASCII > 0 &&\n                this.getCodewordsRemaining(this.cachedTotalSize + lastASCII) <=\n                    2 - lastASCII) {\n                return Mode.ASCII;\n            }\n        }\n        if (this.mode === Mode.C40 ||\n            this.mode === Mode.TEXT ||\n            this.mode === Mode.X12) {\n            // see 5.2.5.2 C40 encodation rules and 5.2.7.2 ANSI X12 encodation rules\n            if (this.fromPosition + this.characterLength >= this.input.length() &&\n                this.getCodewordsRemaining(this.cachedTotalSize) === 0) {\n                return Mode.ASCII;\n            }\n            var lastASCII = this.getLastASCII();\n            if (lastASCII === 1 &&\n                this.getCodewordsRemaining(this.cachedTotalSize + 1) === 0) {\n                return Mode.ASCII;\n            }\n        }\n        return this.mode;\n    };\n    Edge.prototype.getMode = function () {\n        return this.mode;\n    };\n    /** Peeks ahead and returns 1 if the postfix consists of exactly two digits, 2 if the postfix consists of exactly\n     *  two consecutive digits and a non extended character or of 4 digits.\n     *  Returns 0 in any other case\n     **/\n    Edge.prototype.getLastASCII = function () {\n        var length = this.input.length();\n        var from = this.fromPosition + this.characterLength;\n        if (length - from > 4 || from >= length) {\n            return 0;\n        }\n        if (length - from === 1) {\n            if (MinimalEncoder.isExtendedASCII(this.input.charAt(from), this.input.getFNC1Character())) {\n                return 0;\n            }\n            return 1;\n        }\n        if (length - from === 2) {\n            if (MinimalEncoder.isExtendedASCII(this.input.charAt(from), this.input.getFNC1Character()) ||\n                MinimalEncoder.isExtendedASCII(this.input.charAt(from + 1), this.input.getFNC1Character())) {\n                return 0;\n            }\n            if (HighLevelEncoder.isDigit(this.input.charAt(from)) &&\n                HighLevelEncoder.isDigit(this.input.charAt(from + 1))) {\n                return 1;\n            }\n            return 2;\n        }\n        if (length - from === 3) {\n            if (HighLevelEncoder.isDigit(this.input.charAt(from)) &&\n                HighLevelEncoder.isDigit(this.input.charAt(from + 1)) &&\n                !MinimalEncoder.isExtendedASCII(this.input.charAt(from + 2), this.input.getFNC1Character())) {\n                return 2;\n            }\n            if (HighLevelEncoder.isDigit(this.input.charAt(from + 1)) &&\n                HighLevelEncoder.isDigit(this.input.charAt(from + 2)) &&\n                !MinimalEncoder.isExtendedASCII(this.input.charAt(from), this.input.getFNC1Character())) {\n                return 2;\n            }\n            return 0;\n        }\n        if (HighLevelEncoder.isDigit(this.input.charAt(from)) &&\n            HighLevelEncoder.isDigit(this.input.charAt(from + 1)) &&\n            HighLevelEncoder.isDigit(this.input.charAt(from + 2)) &&\n            HighLevelEncoder.isDigit(this.input.charAt(from + 3))) {\n            return 2;\n        }\n        return 0;\n    };\n    /** Returns the capacity in codewords of the smallest symbol that has enough capacity to fit the given minimal\n     * number of codewords.\n     **/\n    Edge.prototype.getMinSymbolSize = function (minimum) {\n        var e_3, _a, e_4, _b, e_5, _c;\n        switch (this.input.getShapeHint()) {\n            case 1 /* FORCE_SQUARE */:\n                try {\n                    for (var _d = __values(this.squareCodewordCapacities), _e = _d.next(); !_e.done; _e = _d.next()) {\n                        var capacity = _e.value;\n                        if (capacity >= minimum) {\n                            return capacity;\n                        }\n                    }\n                }\n                catch (e_3_1) { e_3 = { error: e_3_1 }; }\n                finally {\n                    try {\n                        if (_e && !_e.done && (_a = _d.return)) _a.call(_d);\n                    }\n                    finally { if (e_3) throw e_3.error; }\n                }\n                break;\n            case 2 /* FORCE_RECTANGLE */:\n                try {\n                    for (var _f = __values(this.rectangularCodewordCapacities), _g = _f.next(); !_g.done; _g = _f.next()) {\n                        var capacity = _g.value;\n                        if (capacity >= minimum) {\n                            return capacity;\n                        }\n                    }\n                }\n                catch (e_4_1) { e_4 = { error: e_4_1 }; }\n                finally {\n                    try {\n                        if (_g && !_g.done && (_b = _f.return)) _b.call(_f);\n                    }\n                    finally { if (e_4) throw e_4.error; }\n                }\n                break;\n        }\n        try {\n            for (var _h = __values(this.allCodewordCapacities), _j = _h.next(); !_j.done; _j = _h.next()) {\n                var capacity = _j.value;\n                if (capacity >= minimum) {\n                    return capacity;\n                }\n            }\n        }\n        catch (e_5_1) { e_5 = { error: e_5_1 }; }\n        finally {\n            try {\n                if (_j && !_j.done && (_c = _h.return)) _c.call(_h);\n            }\n            finally { if (e_5) throw e_5.error; }\n        }\n        return this.allCodewordCapacities[this.allCodewordCapacities.length - 1];\n    };\n    /** Returns the remaining capacity in codewords of the smallest symbol that has enough capacity to fit the given\n     * minimal number of codewords.\n     **/\n    Edge.prototype.getCodewordsRemaining = function (minimum) {\n        return this.getMinSymbolSize(minimum) - minimum;\n    };\n    Edge.getBytes = function (c1, c2) {\n        var result = new Uint8Array(c2 ? 2 : 1);\n        result[0] = c1;\n        if (c2) {\n            result[1] = c2;\n        }\n        return result;\n    };\n    Edge.prototype.setC40Word = function (bytes, offset, c1, c2, c3) {\n        var val16 = 1600 * (c1 & 0xff) + 40 * (c2 & 0xff) + (c3 & 0xff) + 1;\n        bytes[offset] = val16 / 256;\n        bytes[offset + 1] = val16 % 256;\n    };\n    Edge.prototype.getX12Value = function (c) {\n        return c === 13\n            ? 0\n            : c === 42\n                ? 1\n                : c === 62\n                    ? 2\n                    : c === 32\n                        ? 3\n                        : c >= 48 && c <= 57\n                            ? c - 44\n                            : c >= 65 && c <= 90\n                                ? c - 51\n                                : c;\n    };\n    Edge.prototype.getX12Words = function () {\n        if (!(this.characterLength % 3 === 0)) {\n            throw new Error('X12 words must be a multiple of 3');\n        }\n        var result = new Uint8Array((this.characterLength / 3) * 2);\n        for (var i = 0; i < result.length; i += 2) {\n            this.setC40Word(result, i, this.getX12Value(this.input.charAt(this.fromPosition + (i / 2) * 3)), this.getX12Value(this.input.charAt(this.fromPosition + (i / 2) * 3 + 1)), this.getX12Value(this.input.charAt(this.fromPosition + (i / 2) * 3 + 2)));\n        }\n        return result;\n    };\n    Edge.prototype.getShiftValue = function (c, c40, fnc1) {\n        return (c40 && MinimalEncoder.isInC40Shift1Set(c)) ||\n            (!c40 && MinimalEncoder.isInTextShift1Set(c))\n            ? 0\n            : (c40 && MinimalEncoder.isInC40Shift2Set(c, fnc1)) ||\n                (!c40 && MinimalEncoder.isInTextShift2Set(c, fnc1))\n                ? 1\n                : 2;\n    };\n    Edge.prototype.getC40Value = function (c40, setIndex, c, fnc1) {\n        if (c === fnc1) {\n            if (!(setIndex === 2)) {\n                throw new Error('FNC1 cannot be used in C40 shift 2');\n            }\n            return 27;\n        }\n        if (c40) {\n            return c <= 31\n                ? c\n                : c === 32\n                    ? 3\n                    : c <= 47\n                        ? c - 33\n                        : c <= 57\n                            ? c - 44\n                            : c <= 64\n                                ? c - 43\n                                : c <= 90\n                                    ? c - 51\n                                    : c <= 95\n                                        ? c - 69\n                                        : c <= 127\n                                            ? c - 96\n                                            : c;\n        }\n        else {\n            return c === 0\n                ? 0\n                : setIndex === 0 && c <= 3\n                    ? c - 1 // is this a bug in the spec?\n                    : setIndex === 1 && c <= 31\n                        ? c\n                        : c === 32\n                            ? 3\n                            : c >= 33 && c <= 47\n                                ? c - 33\n                                : c >= 48 && c <= 57\n                                    ? c - 44\n                                    : c >= 58 && c <= 64\n                                        ? c - 43\n                                        : c >= 65 && c <= 90\n                                            ? c - 64\n                                            : c >= 91 && c <= 95\n                                                ? c - 69\n                                                : c === 96\n                                                    ? 0\n                                                    : c >= 97 && c <= 122\n                                                        ? c - 83\n                                                        : c >= 123 && c <= 127\n                                                            ? c - 96\n                                                            : c;\n        }\n    };\n    Edge.prototype.getC40Words = function (c40, fnc1) {\n        var c40Values = [];\n        for (var i = 0; i < this.characterLength; i++) {\n            var ci = this.input.charAt(this.fromPosition + i);\n            if ((c40 && HighLevelEncoder.isNativeC40(ci)) ||\n                (!c40 && HighLevelEncoder.isNativeText(ci))) {\n                c40Values.push(this.getC40Value(c40, 0, ci, fnc1));\n            }\n            else if (!MinimalEncoder.isExtendedASCII(ci, fnc1)) {\n                var shiftValue = this.getShiftValue(ci, c40, fnc1);\n                c40Values.push(shiftValue); // Shift[123]\n                c40Values.push(this.getC40Value(c40, shiftValue, ci, fnc1));\n            }\n            else {\n                var asciiValue = (ci & 0xff) - 128;\n                if ((c40 && HighLevelEncoder.isNativeC40(asciiValue)) ||\n                    (!c40 && HighLevelEncoder.isNativeText(asciiValue))) {\n                    c40Values.push(1); // Shift 2\n                    c40Values.push(30); // Upper Shift\n                    c40Values.push(this.getC40Value(c40, 0, asciiValue, fnc1));\n                }\n                else {\n                    c40Values.push(1); // Shift 2\n                    c40Values.push(30); // Upper Shift\n                    var shiftValue = this.getShiftValue(asciiValue, c40, fnc1);\n                    c40Values.push(shiftValue); // Shift[123]\n                    c40Values.push(this.getC40Value(c40, shiftValue, asciiValue, fnc1));\n                }\n            }\n        }\n        if (c40Values.length % 3 !== 0) {\n            if (!((c40Values.length - 2) % 3 === 0 &&\n                this.fromPosition + this.characterLength === this.input.length())) {\n                throw new Error('C40 words must be a multiple of 3');\n            }\n            c40Values.push(0); // pad with 0 (Shift 1)\n        }\n        var result = new Uint8Array((c40Values.length / 3) * 2);\n        var byteIndex = 0;\n        for (var i = 0; i < c40Values.length; i += 3) {\n            this.setC40Word(result, byteIndex, c40Values[i] & 0xff, c40Values[i + 1] & 0xff, c40Values[i + 2] & 0xff);\n            byteIndex += 2;\n        }\n        return result;\n    };\n    Edge.prototype.getEDFBytes = function () {\n        var numberOfThirds = Math.ceil(this.characterLength / 4.0);\n        var result = new Uint8Array(numberOfThirds * 3);\n        var pos = this.fromPosition;\n        var endPos = Math.min(this.fromPosition + this.characterLength - 1, this.input.length() - 1);\n        for (var i = 0; i < numberOfThirds; i += 3) {\n            var edfValues = [];\n            for (var j = 0; j < 4; j++) {\n                if (pos <= endPos) {\n                    edfValues[j] = this.input.charAt(pos++) & 0x3f;\n                }\n                else {\n                    edfValues[j] = pos === endPos + 1 ? 0x1f : 0;\n                }\n            }\n            var val24 = edfValues[0] << 18;\n            val24 |= edfValues[1] << 12;\n            val24 |= edfValues[2] << 6;\n            val24 |= edfValues[3];\n            result[i] = (val24 >> 16) & 0xff;\n            result[i + 1] = (val24 >> 8) & 0xff;\n            result[i + 2] = val24 & 0xff;\n        }\n        return result;\n    };\n    Edge.prototype.getLatchBytes = function () {\n        switch (this.getPreviousMode()) {\n            case Mode.ASCII:\n            case Mode.B256: // after B256 ends (via length) we are back to ASCII\n                switch (this.mode) {\n                    case Mode.B256:\n                        return Edge.getBytes(231);\n                    case Mode.C40:\n                        return Edge.getBytes(230);\n                    case Mode.TEXT:\n                        return Edge.getBytes(239);\n                    case Mode.X12:\n                        return Edge.getBytes(238);\n                    case Mode.EDF:\n                        return Edge.getBytes(240);\n                }\n                break;\n            case Mode.C40:\n            case Mode.TEXT:\n            case Mode.X12:\n                if (this.mode !== this.getPreviousMode()) {\n                    switch (this.mode) {\n                        case Mode.ASCII:\n                            return Edge.getBytes(254);\n                        case Mode.B256:\n                            return Edge.getBytes(254, 231);\n                        case Mode.C40:\n                            return Edge.getBytes(254, 230);\n                        case Mode.TEXT:\n                            return Edge.getBytes(254, 239);\n                        case Mode.X12:\n                            return Edge.getBytes(254, 238);\n                        case Mode.EDF:\n                            return Edge.getBytes(254, 240);\n                    }\n                }\n                break;\n            case Mode.EDF:\n                // The rightmost EDIFACT edge always contains an unlatch character\n                if (this.mode !== Mode.EDF) {\n                    throw new Error('Cannot switch from EDF to ' + this.mode);\n                }\n                break;\n        }\n        return new Uint8Array(0);\n    };\n    // Important: The function does not return the length bytes (one or two) in case of B256 encoding\n    Edge.prototype.getDataBytes = function () {\n        switch (this.mode) {\n            case Mode.ASCII:\n                if (this.input.isECI(this.fromPosition)) {\n                    return Edge.getBytes(241, this.input.getECIValue(this.fromPosition) + 1);\n                }\n                else if (MinimalEncoder.isExtendedASCII(this.input.charAt(this.fromPosition), this.input.getFNC1Character())) {\n                    return Edge.getBytes(235, this.input.charAt(this.fromPosition) - 127);\n                }\n                else if (this.characterLength === 2) {\n                    return Edge.getBytes(this.input.charAt(this.fromPosition) * 10 +\n                        this.input.charAt(this.fromPosition + 1) +\n                        130);\n                }\n                else if (this.input.isFNC1(this.fromPosition)) {\n                    return Edge.getBytes(232);\n                }\n                else {\n                    return Edge.getBytes(this.input.charAt(this.fromPosition) + 1);\n                }\n            case Mode.B256:\n                return Edge.getBytes(this.input.charAt(this.fromPosition));\n            case Mode.C40:\n                return this.getC40Words(true, this.input.getFNC1Character());\n            case Mode.TEXT:\n                return this.getC40Words(false, this.input.getFNC1Character());\n            case Mode.X12:\n                return this.getX12Words();\n            case Mode.EDF:\n                return this.getEDFBytes();\n        }\n    };\n    return Edge;\n}());\nvar Input = /** @class */ (function (_super) {\n    __extends(Input, _super);\n    function Input(stringToEncode, priorityCharset, fnc1, shape, macroId) {\n        var _this = _super.call(this, stringToEncode, priorityCharset, fnc1) || this;\n        _this.shape = shape;\n        _this.macroId = macroId;\n        return _this;\n    }\n    Input.prototype.getMacroId = function () {\n        return this.macroId;\n    };\n    Input.prototype.getShapeHint = function () {\n        return this.shape;\n    };\n    return Input;\n}(MinimalECIInput));\n","/*\n * Copyright 2008 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nvar __extends = (this && this.__extends) || (function () {\n    var extendStatics = function (d, b) {\n        extendStatics = Object.setPrototypeOf ||\n            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n        return extendStatics(d, b);\n    };\n    return function (d, b) {\n        extendStatics(d, b);\n        function __() { this.constructor = d; }\n        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n    };\n})();\nimport OneDReader from './OneDReader';\nimport NotFoundException from '../NotFoundException';\nimport FormatException from '../FormatException';\n/**\n * <p>Encapsulates functionality and implementation that is common to UPC and EAN families\n * of one-dimensional barcodes.</p>\n *\n * @author dswitkin@google.com (Daniel Switkin)\n * @author Sean Owen\n * @author alasdair@google.com (Alasdair Mackintosh)\n */\nvar AbstractUPCEANReader = /** @class */ (function (_super) {\n    __extends(AbstractUPCEANReader, _super);\n    function AbstractUPCEANReader() {\n        var _this = _super !== null && _super.apply(this, arguments) || this;\n        _this.decodeRowStringBuffer = '';\n        return _this;\n    }\n    // private final UPCEANExtensionSupport extensionReader;\n    // private final EANManufacturerOrgSupport eanManSupport;\n    /*\n    protected UPCEANReader() {\n        decodeRowStringBuffer = new StringBuilder(20);\n        extensionReader = new UPCEANExtensionSupport();\n        eanManSupport = new EANManufacturerOrgSupport();\n    }\n    */\n    AbstractUPCEANReader.findStartGuardPattern = function (row) {\n        var foundStart = false;\n        var startRange;\n        var nextStart = 0;\n        var counters = Int32Array.from([0, 0, 0]);\n        while (!foundStart) {\n            counters = Int32Array.from([0, 0, 0]);\n            startRange = AbstractUPCEANReader.findGuardPattern(row, nextStart, false, this.START_END_PATTERN, counters);\n            var start = startRange[0];\n            nextStart = startRange[1];\n            var quietStart = start - (nextStart - start);\n            if (quietStart >= 0) {\n                foundStart = row.isRange(quietStart, start, false);\n            }\n        }\n        return startRange;\n    };\n    AbstractUPCEANReader.checkChecksum = function (s) {\n        return AbstractUPCEANReader.checkStandardUPCEANChecksum(s);\n    };\n    AbstractUPCEANReader.checkStandardUPCEANChecksum = function (s) {\n        var length = s.length;\n        if (length === 0)\n            return false;\n        var check = parseInt(s.charAt(length - 1), 10);\n        return AbstractUPCEANReader.getStandardUPCEANChecksum(s.substring(0, length - 1)) === check;\n    };\n    AbstractUPCEANReader.getStandardUPCEANChecksum = function (s) {\n        var length = s.length;\n        var sum = 0;\n        for (var i = length - 1; i >= 0; i -= 2) {\n            var digit = s.charAt(i).charCodeAt(0) - '0'.charCodeAt(0);\n            if (digit < 0 || digit > 9) {\n                throw new FormatException();\n            }\n            sum += digit;\n        }\n        sum *= 3;\n        for (var i = length - 2; i >= 0; i -= 2) {\n            var digit = s.charAt(i).charCodeAt(0) - '0'.charCodeAt(0);\n            if (digit < 0 || digit > 9) {\n                throw new FormatException();\n            }\n            sum += digit;\n        }\n        return (1000 - sum) % 10;\n    };\n    AbstractUPCEANReader.decodeEnd = function (row, endStart) {\n        return AbstractUPCEANReader.findGuardPattern(row, endStart, false, AbstractUPCEANReader.START_END_PATTERN, new Int32Array(AbstractUPCEANReader.START_END_PATTERN.length).fill(0));\n    };\n    /**\n     * @throws NotFoundException\n     */\n    AbstractUPCEANReader.findGuardPatternWithoutCounters = function (row, rowOffset, whiteFirst, pattern) {\n        return this.findGuardPattern(row, rowOffset, whiteFirst, pattern, new Int32Array(pattern.length));\n    };\n    /**\n     * @param row row of black/white values to search\n     * @param rowOffset position to start search\n     * @param whiteFirst if true, indicates that the pattern specifies white/black/white/...\n     * pixel counts, otherwise, it is interpreted as black/white/black/...\n     * @param pattern pattern of counts of number of black and white pixels that are being\n     * searched for as a pattern\n     * @param counters array of counters, as long as pattern, to re-use\n     * @return start/end horizontal offset of guard pattern, as an array of two ints\n     * @throws NotFoundException if pattern is not found\n     */\n    AbstractUPCEANReader.findGuardPattern = function (row, rowOffset, whiteFirst, pattern, counters) {\n        var width = row.getSize();\n        rowOffset = whiteFirst ? row.getNextUnset(rowOffset) : row.getNextSet(rowOffset);\n        var counterPosition = 0;\n        var patternStart = rowOffset;\n        var patternLength = pattern.length;\n        var isWhite = whiteFirst;\n        for (var x = rowOffset; x < width; x++) {\n            if (row.get(x) !== isWhite) {\n                counters[counterPosition]++;\n            }\n            else {\n                if (counterPosition === patternLength - 1) {\n                    if (OneDReader.patternMatchVariance(counters, pattern, AbstractUPCEANReader.MAX_INDIVIDUAL_VARIANCE) < AbstractUPCEANReader.MAX_AVG_VARIANCE) {\n                        return Int32Array.from([patternStart, x]);\n                    }\n                    patternStart += counters[0] + counters[1];\n                    var slice = counters.slice(2, counters.length);\n                    for (var i = 0; i < counterPosition - 1; i++) {\n                        counters[i] = slice[i];\n                    }\n                    counters[counterPosition - 1] = 0;\n                    counters[counterPosition] = 0;\n                    counterPosition--;\n                }\n                else {\n                    counterPosition++;\n                }\n                counters[counterPosition] = 1;\n                isWhite = !isWhite;\n            }\n        }\n        throw new NotFoundException();\n    };\n    AbstractUPCEANReader.decodeDigit = function (row, counters, rowOffset, patterns) {\n        this.recordPattern(row, rowOffset, counters);\n        var bestVariance = this.MAX_AVG_VARIANCE;\n        var bestMatch = -1;\n        var max = patterns.length;\n        for (var i = 0; i < max; i++) {\n            var pattern = patterns[i];\n            var variance = OneDReader.patternMatchVariance(counters, pattern, AbstractUPCEANReader.MAX_INDIVIDUAL_VARIANCE);\n            if (variance < bestVariance) {\n                bestVariance = variance;\n                bestMatch = i;\n            }\n        }\n        if (bestMatch >= 0) {\n            return bestMatch;\n        }\n        else {\n            throw new NotFoundException();\n        }\n    };\n    // These two values are critical for determining how permissive the decoding will be.\n    // We've arrived at these values through a lot of trial and error. Setting them any higher\n    // lets false positives creep in quickly.\n    AbstractUPCEANReader.MAX_AVG_VARIANCE = 0.48;\n    AbstractUPCEANReader.MAX_INDIVIDUAL_VARIANCE = 0.7;\n    /**\n     * Start/end guard pattern.\n     */\n    AbstractUPCEANReader.START_END_PATTERN = Int32Array.from([1, 1, 1]);\n    /**\n     * Pattern marking the middle of a UPC/EAN pattern, separating the two halves.\n     */\n    AbstractUPCEANReader.MIDDLE_PATTERN = Int32Array.from([1, 1, 1, 1, 1]);\n    /**\n     * end guard pattern.\n     */\n    AbstractUPCEANReader.END_PATTERN = Int32Array.from([1, 1, 1, 1, 1, 1]);\n    /**\n     * \"Odd\", or \"L\" patterns used to encode UPC/EAN digits.\n     */\n    AbstractUPCEANReader.L_PATTERNS = [\n        Int32Array.from([3, 2, 1, 1]),\n        Int32Array.from([2, 2, 2, 1]),\n        Int32Array.from([2, 1, 2, 2]),\n        Int32Array.from([1, 4, 1, 1]),\n        Int32Array.from([1, 1, 3, 2]),\n        Int32Array.from([1, 2, 3, 1]),\n        Int32Array.from([1, 1, 1, 4]),\n        Int32Array.from([1, 3, 1, 2]),\n        Int32Array.from([1, 2, 1, 3]),\n        Int32Array.from([3, 1, 1, 2]),\n    ];\n    return AbstractUPCEANReader;\n}(OneDReader));\nexport default AbstractUPCEANReader;\n"],"names":[],"sourceRoot":""}