{"version":3,"file":"qr-tables.cjs","names":[],"sources":["../../../src/components/QRCode/qr-tables.ts"],"sourcesContent":["/**\n * The fixed tables of ISO/IEC 18004, transcribed.\n *\n * They are data, not logic: the standard specifies them and there is nothing to\n * derive. They live apart from {@link ./qr-encode} so the algorithm reads as\n * algorithm and a typo in a table stays findable.\n */\n\n/** Error correction level, by how much of the symbol it can lose and survive. */\nexport type QRErrorCorrection = \"L\" | \"M\" | \"Q\" | \"H\";\n\nexport const ECC_LEVELS: readonly QRErrorCorrection[] = [\"L\", \"M\", \"Q\", \"H\"];\n\n/** The 2-bit code each level carries in the format information. */\nexport const ECC_FORMAT_BITS: Record<QRErrorCorrection, number> = { L: 1, M: 0, Q: 3, H: 2 };\n\n/**\n * Error-correction codewords per block, indexed `[level][version - 1]`.\n *\n * Together with {@link ECC_BLOCK_COUNT} this fixes how much of each version is\n * data and how much is redundancy.\n */\nexport const ECC_CODEWORDS_PER_BLOCK: Record<QRErrorCorrection, readonly number[]> = {\n    L: [\n        7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30,\n        30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n    ],\n    M: [\n        10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28,\n        28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,\n    ],\n    Q: [\n        13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30,\n        30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n    ],\n    H: [\n        17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30,\n        30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n    ],\n};\n\n/** Number of error-correction blocks, indexed `[level][version - 1]`. */\nexport const ECC_BLOCK_COUNT: Record<QRErrorCorrection, readonly number[]> = {\n    L: [\n        1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14,\n        15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25,\n    ],\n    M: [\n        1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23,\n        25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49,\n    ],\n    Q: [\n        1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34,\n        34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68,\n    ],\n    H: [\n        1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35,\n        37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81,\n    ],\n};\n\n/** The alphanumeric mode's 45-character alphabet, in code order. */\nexport const ALPHANUMERIC_CHARS = \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:\";\n\n/** Lowest and highest symbol version. */\nexport const MIN_VERSION = 1;\nexport const MAX_VERSION = 40;\n\n/**\n * Total data modules in a symbol, before subtracting error correction.\n *\n * Closed form rather than a 40-row table: the function patterns a version\n * carries are themselves a function of the version, so counting them beats\n * transcribing the totals and hoping.\n *\n * @param version - Symbol version, 1 to 40.\n * @returns The module count available to data and error correction.\n */\nexport function rawDataModules(version: number): number {\n    let result = (16 * version + 128) * version + 64;\n    if (version >= 2) {\n        const alignCount = Math.floor(version / 7) + 2;\n        result -= (25 * alignCount - 10) * alignCount - 55;\n        if (version >= 7) result -= 36;\n    }\n    return result;\n}\n\n/**\n * How many data codewords a version holds at a given level.\n *\n * @param version - Symbol version, 1 to 40.\n * @param level - Error correction level.\n * @returns Codewords left for the message itself.\n */\nexport function dataCodewords(version: number, level: QRErrorCorrection): number {\n    return (\n        Math.floor(rawDataModules(version) / 8) -\n        ECC_CODEWORDS_PER_BLOCK[level][version - 1] * ECC_BLOCK_COUNT[level][version - 1]\n    );\n}\n\n/**\n * Row/column centres of the alignment patterns for a version.\n *\n * @param version - Symbol version, 1 to 40.\n * @returns Coordinates, ascending. Empty for version 1, which has none.\n */\nexport function alignmentPatternPositions(version: number): number[] {\n    if (version === 1) return [];\n    const count = Math.floor(version / 7) + 2;\n    // Version 32 is the one case the general spacing rule gets wrong.\n    const step = version === 32 ? 26 : Math.ceil((version * 4 + 4) / (count * 2 - 2)) * 2;\n    const positions = [6];\n    for (let pos = version * 4 + 10; positions.length < count; pos -= step) {\n        positions.splice(1, 0, pos);\n    }\n    return positions;\n}\n"],"mappings":"AAcA,IAAa,EAAqD,CAAE,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,CAAE,EAQ9E,EAAwE,CACjF,EAAG,CACC,EAAG,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GACvF,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,EACpE,EACA,EAAG,CACC,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GACxF,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GA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