tempest-react-sdk 0.27.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +24 -0
  2. package/bin/lib/css/analyze.mjs +149 -0
  3. package/bin/lib/css/analyze.test.mjs +136 -0
  4. package/bin/lib/css/collect.mjs +152 -0
  5. package/bin/lib/css/findings.mjs +79 -0
  6. package/bin/lib/css/fix.e2e.test.mjs +99 -0
  7. package/bin/lib/css/fix.mjs +138 -0
  8. package/bin/lib/css/fix.test.mjs +108 -0
  9. package/bin/lib/css/index.mjs +16 -0
  10. package/bin/lib/css/parse.mjs +398 -0
  11. package/bin/lib/css/parse.test.mjs +146 -0
  12. package/bin/lib/css/properties.mjs +399 -0
  13. package/bin/lib/css/repetition.mjs +213 -0
  14. package/bin/lib/css/repetition.test.mjs +166 -0
  15. package/bin/lib/css/semantic.mjs +327 -0
  16. package/bin/lib/css/semantic.test.mjs +201 -0
  17. package/bin/lib/css/tokens.mjs +119 -0
  18. package/bin/lib/doctor/doctor.e2e.test.mjs +45 -0
  19. package/bin/tempest.mjs +169 -7
  20. package/dist/charts/scales.cjs +2 -0
  21. package/dist/charts/scales.cjs.map +1 -0
  22. package/dist/charts/scales.js +29 -0
  23. package/dist/charts/scales.js.map +1 -0
  24. package/dist/charts.cjs +1 -1
  25. package/dist/charts.d.ts +91 -0
  26. package/dist/charts.js +9 -8
  27. package/dist/components/BottomNavigation/BottomNavigation.module.cjs.map +1 -1
  28. package/dist/components/BottomNavigation/BottomNavigation.module.js.map +1 -1
  29. package/dist/components/Carousel/Carousel.module.cjs.map +1 -1
  30. package/dist/components/Carousel/Carousel.module.js.map +1 -1
  31. package/dist/components/CodeBlock/CodeBlock.cjs +3 -0
  32. package/dist/components/CodeBlock/CodeBlock.cjs.map +1 -0
  33. package/dist/components/CodeBlock/CodeBlock.js +53 -0
  34. package/dist/components/CodeBlock/CodeBlock.js.map +1 -0
  35. package/dist/components/CodeBlock/CodeBlock.module.cjs +2 -0
  36. package/dist/components/CodeBlock/CodeBlock.module.cjs.map +1 -0
  37. package/dist/components/CodeBlock/CodeBlock.module.js +29 -0
  38. package/dist/components/CodeBlock/CodeBlock.module.js.map +1 -0
  39. package/dist/components/CodeBlock/tokenize.cjs +3 -0
  40. package/dist/components/CodeBlock/tokenize.cjs.map +1 -0
  41. package/dist/components/CodeBlock/tokenize.js +267 -0
  42. package/dist/components/CodeBlock/tokenize.js.map +1 -0
  43. package/dist/components/Navbar/Navbar.module.cjs.map +1 -1
  44. package/dist/components/Navbar/Navbar.module.js.map +1 -1
  45. package/dist/components/QRCode/QRCode.cjs +2 -0
  46. package/dist/components/QRCode/QRCode.cjs.map +1 -0
  47. package/dist/components/QRCode/QRCode.js +49 -0
  48. package/dist/components/QRCode/QRCode.js.map +1 -0
  49. package/dist/components/QRCode/QRCode.module.cjs +2 -0
  50. package/dist/components/QRCode/QRCode.module.cjs.map +1 -0
  51. package/dist/components/QRCode/QRCode.module.js +9 -0
  52. package/dist/components/QRCode/QRCode.module.js.map +1 -0
  53. package/dist/components/QRCode/qr-encode.cjs +2 -0
  54. package/dist/components/QRCode/qr-encode.cjs.map +1 -0
  55. package/dist/components/QRCode/qr-encode.js +295 -0
  56. package/dist/components/QRCode/qr-encode.js.map +1 -0
  57. package/dist/components/QRCode/qr-tables.cjs +2 -0
  58. package/dist/components/QRCode/qr-tables.cjs.map +1 -0
  59. package/dist/components/QRCode/qr-tables.js +366 -0
  60. package/dist/components/QRCode/qr-tables.js.map +1 -0
  61. package/dist/components/ScrollArea/ScrollArea.cjs +1 -1
  62. package/dist/components/ScrollArea/ScrollArea.cjs.map +1 -1
  63. package/dist/components/ScrollArea/ScrollArea.js +22 -16
  64. package/dist/components/ScrollArea/ScrollArea.js.map +1 -1
  65. package/dist/components/ScrollArea/ScrollArea.module.cjs.map +1 -1
  66. package/dist/components/ScrollArea/ScrollArea.module.js.map +1 -1
  67. package/dist/components/Sparkline/Sparkline.cjs +2 -0
  68. package/dist/components/Sparkline/Sparkline.cjs.map +1 -0
  69. package/dist/components/Sparkline/Sparkline.js +64 -0
  70. package/dist/components/Sparkline/Sparkline.js.map +1 -0
  71. package/dist/components/Sparkline/Sparkline.module.cjs +2 -0
  72. package/dist/components/Sparkline/Sparkline.module.cjs.map +1 -0
  73. package/dist/components/Sparkline/Sparkline.module.js +10 -0
  74. package/dist/components/Sparkline/Sparkline.module.js.map +1 -0
  75. package/dist/components/Sparkline/sparkline-geometry.cjs +2 -0
  76. package/dist/components/Sparkline/sparkline-geometry.cjs.map +1 -0
  77. package/dist/components/Sparkline/sparkline-geometry.js +56 -0
  78. package/dist/components/Sparkline/sparkline-geometry.js.map +1 -0
  79. package/dist/components/Table/Table.cjs +1 -1
  80. package/dist/components/Table/Table.cjs.map +1 -1
  81. package/dist/components/Table/Table.js +37 -30
  82. package/dist/components/Table/Table.js.map +1 -1
  83. package/dist/components/Table/Table.module.cjs.map +1 -1
  84. package/dist/components/Table/Table.module.js.map +1 -1
  85. package/dist/components/VirtualList/VirtualList.cjs +1 -1
  86. package/dist/components/VirtualList/VirtualList.cjs.map +1 -1
  87. package/dist/components/VirtualList/VirtualList.js +13 -11
  88. package/dist/components/VirtualList/VirtualList.js.map +1 -1
  89. package/dist/components/VirtualList/VirtualList.module.cjs.map +1 -1
  90. package/dist/components/VirtualList/VirtualList.module.js.map +1 -1
  91. package/dist/hooks/use-scroll-overflow.cjs +2 -0
  92. package/dist/hooks/use-scroll-overflow.cjs.map +1 -0
  93. package/dist/hooks/use-scroll-overflow.js +22 -0
  94. package/dist/hooks/use-scroll-overflow.js.map +1 -0
  95. package/dist/styles.css +1 -1
  96. package/dist/tempest-react-sdk.cjs +1 -1
  97. package/dist/tempest-react-sdk.d.ts +445 -2
  98. package/dist/tempest-react-sdk.js +197 -190
  99. package/dist/theme/create-theme.cjs +3 -3
  100. package/dist/theme/create-theme.cjs.map +1 -1
  101. package/dist/theme/create-theme.js +52 -28
  102. package/dist/theme/create-theme.js.map +1 -1
  103. package/dist/theme/data-viz-ramps.cjs +2 -0
  104. package/dist/theme/data-viz-ramps.cjs.map +1 -0
  105. package/dist/theme/data-viz-ramps.js +58 -0
  106. package/dist/theme/data-viz-ramps.js.map +1 -0
  107. package/package.json +2 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qr-encode.cjs","names":[],"sources":["../../../src/components/QRCode/qr-encode.ts"],"sourcesContent":["import {\n ALPHANUMERIC_CHARS,\n alignmentPatternPositions,\n dataCodewords,\n ECC_BLOCK_COUNT,\n ECC_CODEWORDS_PER_BLOCK,\n ECC_FORMAT_BITS,\n MAX_VERSION,\n MIN_VERSION,\n rawDataModules,\n type QRErrorCorrection,\n} from \"./qr-tables\";\n\nexport type { QRErrorCorrection };\n\n/** How the payload is packed into bits. */\nexport type QRMode = \"numeric\" | \"alphanumeric\" | \"byte\";\n\nexport interface QRMatrix {\n /** Side length in modules, including no quiet zone. */\n size: number;\n /** Row-major modules; `true` is dark. */\n modules: boolean[][];\n /** Symbol version, 1 to 40. */\n version: number;\n /** Level the symbol was encoded at. */\n level: QRErrorCorrection;\n /** The mode chosen for the payload. */\n mode: QRMode;\n /** Which of the eight masks scored best. */\n mask: number;\n}\n\nexport interface QREncodeOptions {\n /** Error correction level. Default `\"M\"`. */\n level?: QRErrorCorrection;\n /**\n * Force a minimum version. The encoder still grows past it when the payload\n * does not fit — a version is a floor, never a cap that silently truncates.\n */\n minVersion?: number;\n}\n\n/** Raised when a payload cannot be encoded at the requested level. */\nexport class QRCapacityError extends Error {\n constructor(\n readonly length: number,\n readonly level: QRErrorCorrection,\n ) {\n super(\n `Payload of ${length} bytes does not fit in a version-${MAX_VERSION} QR symbol at level ${level}. ` +\n \"Shorten the data, or drop to a lower correction level.\",\n );\n this.name = \"QRCapacityError\";\n }\n}\n\nconst MODE_INDICATOR: Record<QRMode, number> = { numeric: 1, alphanumeric: 2, byte: 4 };\n\nconst NUMERIC_RE = /^[0-9]*$/;\nconst ALPHANUMERIC_RE = /^[0-9A-Z $%*+\\-./:]*$/;\n\n/**\n * Pick the densest mode the payload qualifies for.\n *\n * Numeric packs 3 digits into 10 bits and alphanumeric 2 characters into 11, so\n * a phone number or an upper-case code encodes far smaller than the same string\n * as bytes — often a whole version smaller, which is a visibly coarser symbol\n * and therefore easier to scan.\n *\n * @param text - The payload.\n * @returns The narrowest mode that can represent it.\n */\nexport function selectMode(text: string): QRMode {\n if (NUMERIC_RE.test(text)) return \"numeric\";\n if (ALPHANUMERIC_RE.test(text)) return \"alphanumeric\";\n return \"byte\";\n}\n\n/** Bits the character-count field takes, which widens with the version. */\nfunction charCountBits(mode: QRMode, version: number): number {\n const tier = version <= 9 ? 0 : version <= 26 ? 1 : 2;\n if (mode === \"numeric\") return [10, 12, 14][tier];\n if (mode === \"alphanumeric\") return [9, 11, 13][tier];\n return [8, 16, 16][tier];\n}\n\n/** A bit sink that appends most-significant-bit first. */\nclass BitBuffer {\n readonly bits: number[] = [];\n\n append(value: number, length: number) {\n for (let i = length - 1; i >= 0; i--) this.bits.push((value >>> i) & 1);\n }\n\n get length(): number {\n return this.bits.length;\n }\n}\n\n/** UTF-8 bytes for the byte mode, so accents and emoji survive the round trip. */\nfunction utf8Bytes(text: string): number[] {\n return Array.from(new TextEncoder().encode(text));\n}\n\n/** Bits the payload itself occupies in a given mode, excluding the headers. */\nfunction payloadBits(text: string, mode: QRMode): number {\n if (mode === \"numeric\") {\n const groups = Math.floor(text.length / 3);\n const rest = text.length % 3;\n return groups * 10 + (rest === 0 ? 0 : rest === 1 ? 4 : 7);\n }\n if (mode === \"alphanumeric\") {\n return Math.floor(text.length / 2) * 11 + (text.length % 2) * 6;\n }\n return utf8Bytes(text).length * 8;\n}\n\n/** Write the payload into the buffer in the chosen mode. */\nfunction writePayload(buffer: BitBuffer, text: string, mode: QRMode) {\n if (mode === \"numeric\") {\n for (let i = 0; i < text.length; i += 3) {\n const chunk = text.slice(i, i + 3);\n buffer.append(Number(chunk), chunk.length * 3 + 1);\n }\n return;\n }\n if (mode === \"alphanumeric\") {\n for (let i = 0; i < text.length; i += 2) {\n const first = ALPHANUMERIC_CHARS.indexOf(text[i]);\n if (i + 1 === text.length) {\n buffer.append(first, 6);\n } else {\n buffer.append(first * 45 + ALPHANUMERIC_CHARS.indexOf(text[i + 1]), 11);\n }\n }\n return;\n }\n for (const byte of utf8Bytes(text)) buffer.append(byte, 8);\n}\n\n/** Character count for the header, which is bytes — not characters — in byte mode. */\nfunction headerCount(text: string, mode: QRMode): number {\n return mode === \"byte\" ? utf8Bytes(text).length : text.length;\n}\n\n/**\n * The smallest version that fits the payload at this level.\n *\n * @throws {QRCapacityError} When even version 40 is too small.\n */\nfunction selectVersion(\n text: string,\n mode: QRMode,\n level: QRErrorCorrection,\n minVersion: number,\n): number {\n const bits = payloadBits(text, mode);\n for (let version = Math.max(MIN_VERSION, minVersion); version <= MAX_VERSION; version++) {\n const capacity = dataCodewords(version, level) * 8;\n if (4 + charCountBits(mode, version) + bits <= capacity) return version;\n }\n throw new QRCapacityError(headerCount(text, mode), level);\n}\n\n// ── Reed-Solomon over GF(256), primitive polynomial 0x11D ───────────────────\n\nconst GF_EXP = new Uint8Array(512);\nconst GF_LOG = new Uint8Array(256);\n\n{\n let x = 1;\n for (let i = 0; i < 255; i++) {\n GF_EXP[i] = x;\n GF_LOG[x] = i;\n x = (x << 1) ^ (x & 0x80 ? 0x11d : 0);\n }\n for (let i = 255; i < 512; i++) GF_EXP[i] = GF_EXP[i - 255];\n}\n\nfunction gfMul(a: number, b: number): number {\n if (a === 0 || b === 0) return 0;\n return GF_EXP[GF_LOG[a] + GF_LOG[b]];\n}\n\n/** The generator polynomial for `degree` error-correction codewords. */\nfunction rsGenerator(degree: number): number[] {\n let poly = [1];\n for (let i = 0; i < degree; i++) {\n const next = new Array<number>(poly.length + 1).fill(0);\n for (let j = 0; j < poly.length; j++) {\n next[j] ^= poly[j];\n next[j + 1] ^= gfMul(poly[j], GF_EXP[i]);\n }\n poly = next;\n }\n return poly;\n}\n\n/**\n * The error-correction codewords for one block.\n *\n * @param data - The block's data codewords.\n * @param degree - How many correction codewords to produce.\n * @returns The remainder of the polynomial division, which is the ECC block.\n */\nexport function reedSolomon(data: readonly number[], degree: number): number[] {\n const generator = rsGenerator(degree);\n const remainder = new Array<number>(degree).fill(0);\n for (const byte of data) {\n const factor = byte ^ remainder[0];\n remainder.shift();\n remainder.push(0);\n for (let i = 0; i < degree; i++) {\n remainder[i] ^= gfMul(generator[i + 1], factor);\n }\n }\n return remainder;\n}\n\n/**\n * Split into blocks, add correction, and interleave into the final codeword\n * stream.\n *\n * Interleaving is what makes the correction useful against a real-world smudge:\n * a contiguous scratch on the printed symbol then damages a few codewords of\n * every block instead of destroying one block completely.\n */\nfunction buildCodewords(\n data: readonly number[],\n version: number,\n level: QRErrorCorrection,\n): number[] {\n const blockCount = ECC_BLOCK_COUNT[level][version - 1];\n const eccPerBlock = ECC_CODEWORDS_PER_BLOCK[level][version - 1];\n const totalCodewords = Math.floor(rawDataModules(version) / 8);\n const shortBlockLength = Math.floor(totalCodewords / blockCount) - eccPerBlock;\n const longBlockCount = totalCodewords % blockCount;\n\n const dataBlocks: number[][] = [];\n const eccBlocks: number[][] = [];\n let offset = 0;\n for (let i = 0; i < blockCount; i++) {\n const length = shortBlockLength + (i >= blockCount - longBlockCount ? 1 : 0);\n const block = data.slice(offset, offset + length);\n offset += length;\n dataBlocks.push(block);\n eccBlocks.push(reedSolomon(block, eccPerBlock));\n }\n\n const result: number[] = [];\n for (let i = 0; i < shortBlockLength + 1; i++) {\n for (const block of dataBlocks) {\n if (i < block.length) result.push(block[i]);\n }\n }\n for (let i = 0; i < eccPerBlock; i++) {\n for (const block of eccBlocks) result.push(block[i]);\n }\n return result;\n}\n\n// ── Matrix construction ─────────────────────────────────────────────────────\n\n/** A grid under construction: modules plus which cells are function patterns. */\ninterface Canvas {\n size: number;\n modules: boolean[][];\n reserved: boolean[][];\n}\n\nfunction createCanvas(version: number): Canvas {\n const size = version * 4 + 17;\n return {\n size,\n modules: Array.from({ length: size }, () => new Array<boolean>(size).fill(false)),\n reserved: Array.from({ length: size }, () => new Array<boolean>(size).fill(false)),\n };\n}\n\nfunction setModule(canvas: Canvas, x: number, y: number, dark: boolean, reserve = true) {\n if (x < 0 || y < 0 || x >= canvas.size || y >= canvas.size) return;\n canvas.modules[y][x] = dark;\n if (reserve) canvas.reserved[y][x] = true;\n}\n\n/** A finder pattern with its separator, anchored at a corner. */\nfunction drawFinder(canvas: Canvas, left: number, top: number) {\n for (let dy = -1; dy <= 7; dy++) {\n for (let dx = -1; dx <= 7; dx++) {\n const distance = Math.max(Math.abs(dx - 3), Math.abs(dy - 3));\n setModule(canvas, left + dx, top + dy, distance !== 2 && distance <= 3);\n }\n }\n}\n\nfunction drawAlignment(canvas: Canvas, cx: number, cy: number) {\n for (let dy = -2; dy <= 2; dy++) {\n for (let dx = -2; dx <= 2; dx++) {\n setModule(canvas, cx + dx, cy + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);\n }\n }\n}\n\nfunction drawFunctionPatterns(canvas: Canvas, version: number) {\n drawFinder(canvas, 0, 0);\n drawFinder(canvas, canvas.size - 7, 0);\n drawFinder(canvas, 0, canvas.size - 7);\n\n for (let i = 8; i < canvas.size - 8; i++) {\n const dark = i % 2 === 0;\n setModule(canvas, i, 6, dark);\n setModule(canvas, 6, i, dark);\n }\n\n const positions = alignmentPatternPositions(version);\n for (const cy of positions) {\n for (const cx of positions) {\n // The three corners already hold finder patterns.\n const atFinder =\n (cx === 6 && cy === 6) ||\n (cx === 6 && cy === canvas.size - 7) ||\n (cx === canvas.size - 7 && cy === 6);\n if (!atFinder) drawAlignment(canvas, cx, cy);\n }\n }\n\n // Reserve the format information, and light the always-dark module.\n for (let i = 0; i < 9; i++) {\n setModule(canvas, i, 8, false);\n setModule(canvas, 8, i, false);\n }\n for (let i = 0; i < 8; i++) {\n setModule(canvas, canvas.size - 1 - i, 8, false);\n setModule(canvas, 8, canvas.size - 1 - i, false);\n }\n setModule(canvas, 8, canvas.size - 8, true);\n\n if (version >= 7) {\n const value = versionInformation(version);\n for (let i = 0; i < 18; i++) {\n const bit = ((value >>> i) & 1) === 1;\n const a = canvas.size - 11 + (i % 3);\n const b = Math.floor(i / 3);\n setModule(canvas, a, b, bit);\n setModule(canvas, b, a, bit);\n }\n }\n}\n\n/** The 18-bit version information block, BCH(18,6) with generator 0x1F25. */\nfunction versionInformation(version: number): number {\n let remainder = version;\n for (let i = 0; i < 12; i++) {\n remainder = (remainder << 1) ^ ((remainder >>> 11) * 0x1f25);\n }\n return (version << 12) | remainder;\n}\n\n/** The 15-bit format information, BCH(15,5) masked with 0x5412. */\nfunction formatInformation(level: QRErrorCorrection, mask: number): number {\n const data = (ECC_FORMAT_BITS[level] << 3) | mask;\n let remainder = data;\n for (let i = 0; i < 10; i++) {\n remainder = (remainder << 1) ^ ((remainder >>> 9) * 0x537);\n }\n return ((data << 10) | remainder) ^ 0x5412;\n}\n\nfunction drawFormatInformation(canvas: Canvas, level: QRErrorCorrection, mask: number) {\n const bits = formatInformation(level, mask);\n\n for (let i = 0; i <= 5; i++) setModule(canvas, 8, i, ((bits >>> i) & 1) === 1);\n setModule(canvas, 8, 7, ((bits >>> 6) & 1) === 1);\n setModule(canvas, 8, 8, ((bits >>> 7) & 1) === 1);\n setModule(canvas, 7, 8, ((bits >>> 8) & 1) === 1);\n for (let i = 9; i < 15; i++) setModule(canvas, 14 - i, 8, ((bits >>> i) & 1) === 1);\n\n for (let i = 0; i < 8; i++) {\n setModule(canvas, canvas.size - 1 - i, 8, ((bits >>> i) & 1) === 1);\n }\n for (let i = 8; i < 15; i++) {\n setModule(canvas, 8, canvas.size - 15 + i, ((bits >>> i) & 1) === 1);\n }\n setModule(canvas, 8, canvas.size - 8, true);\n}\n\n/**\n * Lay the codeword stream into the free modules.\n *\n * The path is a boustrophedon over two-module columns from the bottom-right\n * corner, skipping the vertical timing pattern in column 6 entirely — that\n * column would otherwise shift every subsequent column by one.\n */\nfunction drawCodewords(canvas: Canvas, codewords: readonly number[]) {\n let bitIndex = 0;\n let upward = true;\n\n for (let right = canvas.size - 1; right >= 1; right -= 2) {\n if (right === 6) right = 5;\n for (let step = 0; step < canvas.size; step++) {\n const y = upward ? canvas.size - 1 - step : step;\n for (let column = 0; column < 2; column++) {\n const x = right - column;\n if (canvas.reserved[y][x]) continue;\n const byte = codewords[bitIndex >>> 3];\n // Remainder bits past the stream are light, per the standard.\n canvas.modules[y][x] =\n byte !== undefined && ((byte >>> (7 - (bitIndex & 7))) & 1) === 1;\n bitIndex++;\n }\n }\n upward = !upward;\n }\n}\n\nconst MASK_FUNCTIONS: readonly ((x: number, y: number) => boolean)[] = [\n (x, y) => (x + y) % 2 === 0,\n (_x, y) => y % 2 === 0,\n (x) => x % 3 === 0,\n (x, y) => (x + y) % 3 === 0,\n (x, y) => (Math.floor(y / 2) + Math.floor(x / 3)) % 2 === 0,\n (x, y) => ((x * y) % 2) + ((x * y) % 3) === 0,\n (x, y) => (((x * y) % 2) + ((x * y) % 3)) % 2 === 0,\n (x, y) => (((x + y) % 2) + ((x * y) % 3)) % 2 === 0,\n];\n\nfunction applyMask(canvas: Canvas, mask: number) {\n const fn = MASK_FUNCTIONS[mask];\n for (let y = 0; y < canvas.size; y++) {\n for (let x = 0; x < canvas.size; x++) {\n if (!canvas.reserved[y][x] && fn(x, y)) canvas.modules[y][x] = !canvas.modules[y][x];\n }\n }\n}\n\n/**\n * Score a masked symbol; lower is better.\n *\n * The four penalties push away from patterns a scanner confuses with the finder\n * marks, and from large flat areas where it cannot lock on.\n */\nfunction penalty(canvas: Canvas): number {\n const { size, modules } = canvas;\n let score = 0;\n\n const runPenalty = (run: number) => (run >= 5 ? 3 + (run - 5) : 0);\n\n for (let y = 0; y < size; y++) {\n let run = 1;\n for (let x = 1; x < size; x++) {\n if (modules[y][x] === modules[y][x - 1]) run++;\n else {\n score += runPenalty(run);\n run = 1;\n }\n }\n score += runPenalty(run);\n }\n for (let x = 0; x < size; x++) {\n let run = 1;\n for (let y = 1; y < size; y++) {\n if (modules[y][x] === modules[y - 1][x]) run++;\n else {\n score += runPenalty(run);\n run = 1;\n }\n }\n score += runPenalty(run);\n }\n\n for (let y = 0; y < size - 1; y++) {\n for (let x = 0; x < size - 1; x++) {\n const cell = modules[y][x];\n if (\n cell === modules[y][x + 1] &&\n cell === modules[y + 1][x] &&\n cell === modules[y + 1][x + 1]\n ) {\n score += 3;\n }\n }\n }\n\n // 1:1:3:1:1 with four light modules on either side — the finder's signature.\n const FINDER = [true, false, true, true, true, false, true];\n const matchesAt = (line: readonly boolean[], at: number): boolean => {\n for (let i = 0; i < FINDER.length; i++) {\n if (line[at + i] !== FINDER[i]) return false;\n }\n const before = line.slice(Math.max(0, at - 4), at);\n const after = line.slice(at + 7, at + 11);\n const clear = (part: readonly boolean[]) => part.length === 4 && part.every((m) => !m);\n return clear(before) || clear(after);\n };\n\n for (let i = 0; i < size; i++) {\n const row = modules[i];\n const column = modules.map((line) => line[i]);\n for (let at = 0; at + 7 <= size; at++) {\n if (matchesAt(row, at)) score += 40;\n if (matchesAt(column, at)) score += 40;\n }\n }\n\n let dark = 0;\n for (const row of modules) for (const cell of row) if (cell) dark++;\n const percent = (dark * 100) / (size * size);\n score += Math.floor(Math.abs(percent - 50) / 5) * 10;\n\n return score;\n}\n\nfunction cloneCanvas(canvas: Canvas): Canvas {\n return {\n size: canvas.size,\n modules: canvas.modules.map((row) => [...row]),\n reserved: canvas.reserved.map((row) => [...row]),\n };\n}\n\n/**\n * Encode text into a QR matrix.\n *\n * The whole pipeline of ISO/IEC 18004: pick the densest mode the payload\n * qualifies for, pick the smallest version that fits, build the bit stream, add\n * Reed-Solomon correction, interleave the blocks, lay the modules out, then try\n * all eight masks and keep the one the standard's penalty function likes best.\n *\n * @param text - The payload. Byte mode encodes it as UTF-8.\n * @param options - Level and an optional version floor.\n * @returns The finished matrix, without a quiet zone.\n * @throws {QRCapacityError} When the payload does not fit at that level.\n *\n * @example\n * const qr = encodeQR(\"https://tempest.dev\", { level: \"Q\" });\n * qr.modules[0][0]; // true — top-left of the finder pattern\n */\nexport function encodeQR(text: string, options: QREncodeOptions = {}): QRMatrix {\n const { level = \"M\", minVersion = MIN_VERSION } = options;\n const mode = selectMode(text);\n const version = selectVersion(text, mode, level, minVersion);\n\n const buffer = new BitBuffer();\n buffer.append(MODE_INDICATOR[mode], 4);\n buffer.append(headerCount(text, mode), charCountBits(mode, version));\n writePayload(buffer, text, mode);\n\n const capacity = dataCodewords(version, level) * 8;\n buffer.append(0, Math.min(4, capacity - buffer.length));\n buffer.append(0, (8 - (buffer.length % 8)) % 8);\n\n const data: number[] = [];\n for (let i = 0; i < buffer.length; i += 8) {\n let byte = 0;\n for (let j = 0; j < 8; j++) byte = (byte << 1) | buffer.bits[i + j];\n data.push(byte);\n }\n // The two alternating pad bytes are prescribed, not arbitrary filler.\n for (let pad = 0xec; data.length < capacity / 8; pad ^= 0xec ^ 0x11) data.push(pad);\n\n const codewords = buildCodewords(data, version, level);\n\n const base = createCanvas(version);\n drawFunctionPatterns(base, version);\n drawCodewords(base, codewords);\n\n let best: Canvas | null = null;\n let bestMask = 0;\n let bestScore = Number.POSITIVE_INFINITY;\n for (let mask = 0; mask < 8; mask++) {\n const candidate = cloneCanvas(base);\n applyMask(candidate, mask);\n drawFormatInformation(candidate, level, mask);\n const score = penalty(candidate);\n if (score < bestScore) {\n bestScore = score;\n bestMask = mask;\n best = candidate;\n }\n }\n\n const chosen = best as Canvas;\n return {\n size: chosen.size,\n modules: chosen.modules,\n version,\n level,\n mode,\n mask: bestMask,\n };\n}\n\n/**\n * The matrix as an SVG path, one `M…h…v…h…z` rectangle per dark module.\n *\n * A path beats one `<rect>` per module: a version-10 symbol is 3 481 modules,\n * and that many elements is a real cost to parse and to paint. Coordinates are\n * whole numbers in module space, so the shape stays crisp at any size.\n *\n * @param matrix - An encoded matrix.\n * @param margin - Quiet zone in modules. The standard asks for 4.\n * @returns The `d` attribute, empty when there is nothing dark.\n */\nexport function matrixToPath(matrix: QRMatrix, margin = 4): string {\n const parts: string[] = [];\n for (let y = 0; y < matrix.size; y++) {\n let runStart = -1;\n for (let x = 0; x <= matrix.size; x++) {\n const dark = x < matrix.size && matrix.modules[y][x];\n if (dark && runStart === -1) runStart = x;\n if (!dark && runStart !== -1) {\n // Merge each horizontal run into one rectangle.\n parts.push(\n `M${runStart + margin} ${y + margin}h${x - runStart}v1h-${x - runStart}z`,\n );\n runStart = -1;\n }\n }\n }\n return parts.join(\"\");\n}\n"],"mappings":"mCA4CA,IAAa,EAAb,cAAqC,KAAM,CAE1B,OACA,MAFb,YACI,EACA,EACF,CACE,MACI,cAAc,EAAO,yDAAqE,EAAM,yDAEpG,EANS,KAAA,OAAA,EACA,KAAA,MAAA,EAMT,KAAK,KAAO,iBAChB,CACJ,EAEM,EAAyC,CAAE,QAAS,EAAG,aAAc,EAAG,KAAM,CAAE,EAEhF,EAAa,WACb,EAAkB,wBAaxB,SAAgB,EAAW,EAAsB,CAG7C,OAFI,EAAW,KAAK,CAAI,EAAU,UAC9B,EAAgB,KAAK,CAAI,EAAU,eAChC,MACX,CAGA,SAAS,EAAc,EAAc,EAAyB,CAC1D,IAAM,EAAO,GAAW,EAAI,EAAI,GAAW,GAAK,EAAI,EAGpD,OAFI,IAAS,UAAkB,CAAC,GAAI,GAAI,EAAE,CAAC,CAAC,GACxC,IAAS,eAAuB,CAAC,EAAG,GAAI,EAAE,CAAC,CAAC,GACzC,CAAC,EAAG,GAAI,EAAE,CAAC,CAAC,EACvB,CAGA,IAAM,EAAN,KAAgB,CACZ,KAA0B,CAAC,EAE3B,OAAO,EAAe,EAAgB,CAClC,IAAK,IAAI,EAAI,EAAS,EAAG,GAAK,EAAG,IAAK,KAAK,KAAK,KAAM,IAAU,EAAK,CAAC,CAC1E,CAEA,IAAI,QAAiB,CACjB,OAAO,KAAK,KAAK,MACrB,CACJ,EAGA,SAAS,EAAU,EAAwB,CACvC,OAAO,MAAM,KA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AAI,EAAG,EAAI,EAAO,KAAM,IAAK,CAClC,IAAI,EAAW,GACf,IAAK,IAAI,EAAI,EAAG,GAAK,EAAO,KAAM,IAAK,CACnC,IAAM,EAAO,EAAI,EAAO,MAAQ,EAAO,QAAQ,EAAE,CAAC,GAC9C,GAAQ,IAAa,KAAI,EAAW,GACpC,CAAC,GAAQ,IAAa,KAEtB,EAAM,KACF,IAAI,EAAW,EAAO,GAAG,EAAI,EAAO,GAAG,EAAI,EAAS,MAAM,EAAI,EAAS,EAC3E,EACA,EAAW,GAEnB,CACJ,CACA,OAAO,EAAM,KAAK,EAAE,CACxB"}
@@ -0,0 +1,295 @@
1
+ import { ALPHANUMERIC_CHARS as e, ECC_BLOCK_COUNT as t, ECC_CODEWORDS_PER_BLOCK as n, ECC_FORMAT_BITS as r, alignmentPatternPositions as i, dataCodewords as a, rawDataModules as o } from "./qr-tables.js";
2
+ //#region src/components/QRCode/qr-encode.ts
3
+ var s = class extends Error {
4
+ length;
5
+ level;
6
+ constructor(e, t) {
7
+ super(`Payload of ${e} bytes does not fit in a version-40 QR symbol at level ${t}. Shorten the data, or drop to a lower correction level.`), this.length = e, this.level = t, this.name = "QRCapacityError";
8
+ }
9
+ }, c = {
10
+ numeric: 1,
11
+ alphanumeric: 2,
12
+ byte: 4
13
+ }, l = /^[0-9]*$/, u = /^[0-9A-Z $%*+\-./:]*$/;
14
+ function d(e) {
15
+ return l.test(e) ? "numeric" : u.test(e) ? "alphanumeric" : "byte";
16
+ }
17
+ function f(e, t) {
18
+ let n = t <= 9 ? 0 : t <= 26 ? 1 : 2;
19
+ return e === "numeric" ? [
20
+ 10,
21
+ 12,
22
+ 14
23
+ ][n] : e === "alphanumeric" ? [
24
+ 9,
25
+ 11,
26
+ 13
27
+ ][n] : [
28
+ 8,
29
+ 16,
30
+ 16
31
+ ][n];
32
+ }
33
+ var p = class {
34
+ bits = [];
35
+ append(e, t) {
36
+ for (let n = t - 1; n >= 0; n--) this.bits.push(e >>> n & 1);
37
+ }
38
+ get length() {
39
+ return this.bits.length;
40
+ }
41
+ };
42
+ function m(e) {
43
+ return Array.from(new TextEncoder().encode(e));
44
+ }
45
+ function h(e, t) {
46
+ if (t === "numeric") {
47
+ let t = Math.floor(e.length / 3), n = e.length % 3;
48
+ return t * 10 + (n === 0 ? 0 : n === 1 ? 4 : 7);
49
+ }
50
+ return t === "alphanumeric" ? Math.floor(e.length / 2) * 11 + e.length % 2 * 6 : m(e).length * 8;
51
+ }
52
+ function g(t, n, r) {
53
+ if (r === "numeric") {
54
+ for (let e = 0; e < n.length; e += 3) {
55
+ let r = n.slice(e, e + 3);
56
+ t.append(Number(r), r.length * 3 + 1);
57
+ }
58
+ return;
59
+ }
60
+ if (r === "alphanumeric") {
61
+ for (let r = 0; r < n.length; r += 2) {
62
+ let i = e.indexOf(n[r]);
63
+ r + 1 === n.length ? t.append(i, 6) : t.append(i * 45 + e.indexOf(n[r + 1]), 11);
64
+ }
65
+ return;
66
+ }
67
+ for (let e of m(n)) t.append(e, 8);
68
+ }
69
+ function _(e, t) {
70
+ return t === "byte" ? m(e).length : e.length;
71
+ }
72
+ function v(e, t, n, r) {
73
+ let i = h(e, t);
74
+ for (let e = Math.max(1, r); e <= 40; e++) {
75
+ let r = a(e, n) * 8;
76
+ if (4 + f(t, e) + i <= r) return e;
77
+ }
78
+ throw new s(_(e, t), n);
79
+ }
80
+ var y = /* @__PURE__ */ new Uint8Array(512), b = /* @__PURE__ */ new Uint8Array(256);
81
+ {
82
+ let e = 1;
83
+ for (let t = 0; t < 255; t++) y[t] = e, b[e] = t, e = e << 1 ^ (e & 128 ? 285 : 0);
84
+ for (let e = 255; e < 512; e++) y[e] = y[e - 255];
85
+ }
86
+ function x(e, t) {
87
+ return e === 0 || t === 0 ? 0 : y[b[e] + b[t]];
88
+ }
89
+ function S(e) {
90
+ let t = [1];
91
+ for (let n = 0; n < e; n++) {
92
+ let e = Array(t.length + 1).fill(0);
93
+ for (let r = 0; r < t.length; r++) e[r] ^= t[r], e[r + 1] ^= x(t[r], y[n]);
94
+ t = e;
95
+ }
96
+ return t;
97
+ }
98
+ function C(e, t) {
99
+ let n = S(t), r = Array(t).fill(0);
100
+ for (let i of e) {
101
+ let e = i ^ r[0];
102
+ r.shift(), r.push(0);
103
+ for (let i = 0; i < t; i++) r[i] ^= x(n[i + 1], e);
104
+ }
105
+ return r;
106
+ }
107
+ function w(e, r, i) {
108
+ let a = t[i][r - 1], s = n[i][r - 1], c = Math.floor(o(r) / 8), l = Math.floor(c / a) - s, u = c % a, d = [], f = [], p = 0;
109
+ for (let t = 0; t < a; t++) {
110
+ let n = l + +(t >= a - u), r = e.slice(p, p + n);
111
+ p += n, d.push(r), f.push(C(r, s));
112
+ }
113
+ let m = [];
114
+ for (let e = 0; e < l + 1; e++) for (let t of d) e < t.length && m.push(t[e]);
115
+ for (let e = 0; e < s; e++) for (let t of f) m.push(t[e]);
116
+ return m;
117
+ }
118
+ function T(e) {
119
+ let t = e * 4 + 17;
120
+ return {
121
+ size: t,
122
+ modules: Array.from({ length: t }, () => Array(t).fill(!1)),
123
+ reserved: Array.from({ length: t }, () => Array(t).fill(!1))
124
+ };
125
+ }
126
+ function E(e, t, n, r, i = !0) {
127
+ t < 0 || n < 0 || t >= e.size || n >= e.size || (e.modules[n][t] = r, i && (e.reserved[n][t] = !0));
128
+ }
129
+ function D(e, t, n) {
130
+ for (let r = -1; r <= 7; r++) for (let i = -1; i <= 7; i++) {
131
+ let a = Math.max(Math.abs(i - 3), Math.abs(r - 3));
132
+ E(e, t + i, n + r, a !== 2 && a <= 3);
133
+ }
134
+ }
135
+ function O(e, t, n) {
136
+ for (let r = -2; r <= 2; r++) for (let i = -2; i <= 2; i++) E(e, t + i, n + r, Math.max(Math.abs(i), Math.abs(r)) !== 1);
137
+ }
138
+ function k(e, t) {
139
+ D(e, 0, 0), D(e, e.size - 7, 0), D(e, 0, e.size - 7);
140
+ for (let t = 8; t < e.size - 8; t++) {
141
+ let n = t % 2 == 0;
142
+ E(e, t, 6, n), E(e, 6, t, n);
143
+ }
144
+ let n = i(t);
145
+ for (let t of n) for (let r of n) r === 6 && t === 6 || r === 6 && t === e.size - 7 || r === e.size - 7 && t === 6 || O(e, r, t);
146
+ for (let t = 0; t < 9; t++) E(e, t, 8, !1), E(e, 8, t, !1);
147
+ for (let t = 0; t < 8; t++) E(e, e.size - 1 - t, 8, !1), E(e, 8, e.size - 1 - t, !1);
148
+ if (E(e, 8, e.size - 8, !0), t >= 7) {
149
+ let n = A(t);
150
+ for (let t = 0; t < 18; t++) {
151
+ let r = (n >>> t & 1) == 1, i = e.size - 11 + t % 3, a = Math.floor(t / 3);
152
+ E(e, i, a, r), E(e, a, i, r);
153
+ }
154
+ }
155
+ }
156
+ function A(e) {
157
+ let t = e;
158
+ for (let e = 0; e < 12; e++) t = t << 1 ^ (t >>> 11) * 7973;
159
+ return e << 12 | t;
160
+ }
161
+ function j(e, t) {
162
+ let n = r[e] << 3 | t, i = n;
163
+ for (let e = 0; e < 10; e++) i = i << 1 ^ (i >>> 9) * 1335;
164
+ return (n << 10 | i) ^ 21522;
165
+ }
166
+ function M(e, t, n) {
167
+ let r = j(t, n);
168
+ for (let t = 0; t <= 5; t++) E(e, 8, t, (r >>> t & 1) == 1);
169
+ E(e, 8, 7, (r >>> 6 & 1) == 1), E(e, 8, 8, (r >>> 7 & 1) == 1), E(e, 7, 8, (r >>> 8 & 1) == 1);
170
+ for (let t = 9; t < 15; t++) E(e, 14 - t, 8, (r >>> t & 1) == 1);
171
+ for (let t = 0; t < 8; t++) E(e, e.size - 1 - t, 8, (r >>> t & 1) == 1);
172
+ for (let t = 8; t < 15; t++) E(e, 8, e.size - 15 + t, (r >>> t & 1) == 1);
173
+ E(e, 8, e.size - 8, !0);
174
+ }
175
+ function N(e, t) {
176
+ let n = 0, r = !0;
177
+ for (let i = e.size - 1; i >= 1; i -= 2) {
178
+ i === 6 && (i = 5);
179
+ for (let a = 0; a < e.size; a++) {
180
+ let o = r ? e.size - 1 - a : a;
181
+ for (let r = 0; r < 2; r++) {
182
+ let a = i - r;
183
+ if (e.reserved[o][a]) continue;
184
+ let s = t[n >>> 3];
185
+ e.modules[o][a] = s !== void 0 && (s >>> 7 - (n & 7) & 1) == 1, n++;
186
+ }
187
+ }
188
+ r = !r;
189
+ }
190
+ }
191
+ var P = [
192
+ (e, t) => (e + t) % 2 == 0,
193
+ (e, t) => t % 2 == 0,
194
+ (e) => e % 3 == 0,
195
+ (e, t) => (e + t) % 3 == 0,
196
+ (e, t) => (Math.floor(t / 2) + Math.floor(e / 3)) % 2 == 0,
197
+ (e, t) => e * t % 2 + e * t % 3 == 0,
198
+ (e, t) => (e * t % 2 + e * t % 3) % 2 == 0,
199
+ (e, t) => ((e + t) % 2 + e * t % 3) % 2 == 0
200
+ ];
201
+ function F(e, t) {
202
+ let n = P[t];
203
+ for (let t = 0; t < e.size; t++) for (let r = 0; r < e.size; r++) !e.reserved[t][r] && n(r, t) && (e.modules[t][r] = !e.modules[t][r]);
204
+ }
205
+ function I(e) {
206
+ let { size: t, modules: n } = e, r = 0, i = (e) => e >= 5 ? 3 + (e - 5) : 0;
207
+ for (let e = 0; e < t; e++) {
208
+ let a = 1;
209
+ for (let o = 1; o < t; o++) n[e][o] === n[e][o - 1] ? a++ : (r += i(a), a = 1);
210
+ r += i(a);
211
+ }
212
+ for (let e = 0; e < t; e++) {
213
+ let a = 1;
214
+ for (let o = 1; o < t; o++) n[o][e] === n[o - 1][e] ? a++ : (r += i(a), a = 1);
215
+ r += i(a);
216
+ }
217
+ for (let e = 0; e < t - 1; e++) for (let i = 0; i < t - 1; i++) {
218
+ let t = n[e][i];
219
+ t === n[e][i + 1] && t === n[e + 1][i] && t === n[e + 1][i + 1] && (r += 3);
220
+ }
221
+ let a = [
222
+ !0,
223
+ !1,
224
+ !0,
225
+ !0,
226
+ !0,
227
+ !1,
228
+ !0
229
+ ], o = (e, t) => {
230
+ for (let n = 0; n < a.length; n++) if (e[t + n] !== a[n]) return !1;
231
+ let n = e.slice(Math.max(0, t - 4), t), r = e.slice(t + 7, t + 11), i = (e) => e.length === 4 && e.every((e) => !e);
232
+ return i(n) || i(r);
233
+ };
234
+ for (let e = 0; e < t; e++) {
235
+ let i = n[e], a = n.map((t) => t[e]);
236
+ for (let e = 0; e + 7 <= t; e++) o(i, e) && (r += 40), o(a, e) && (r += 40);
237
+ }
238
+ let s = 0;
239
+ for (let e of n) for (let t of e) t && s++;
240
+ let c = s * 100 / (t * t);
241
+ return r += Math.floor(Math.abs(c - 50) / 5) * 10, r;
242
+ }
243
+ function L(e) {
244
+ return {
245
+ size: e.size,
246
+ modules: e.modules.map((e) => [...e]),
247
+ reserved: e.reserved.map((e) => [...e])
248
+ };
249
+ }
250
+ function R(e, t = {}) {
251
+ let { level: n = "M", minVersion: r = 1 } = t, i = d(e), o = v(e, i, n, r), s = new p();
252
+ s.append(c[i], 4), s.append(_(e, i), f(i, o)), g(s, e, i);
253
+ let l = a(o, n) * 8;
254
+ s.append(0, Math.min(4, l - s.length)), s.append(0, (8 - s.length % 8) % 8);
255
+ let u = [];
256
+ for (let e = 0; e < s.length; e += 8) {
257
+ let t = 0;
258
+ for (let n = 0; n < 8; n++) t = t << 1 | s.bits[e + n];
259
+ u.push(t);
260
+ }
261
+ for (let e = 236; u.length < l / 8; e ^= 253) u.push(e);
262
+ let m = w(u, o, n), h = T(o);
263
+ k(h, o), N(h, m);
264
+ let y = null, b = 0, x = Infinity;
265
+ for (let e = 0; e < 8; e++) {
266
+ let t = L(h);
267
+ F(t, e), M(t, n, e);
268
+ let r = I(t);
269
+ r < x && (x = r, b = e, y = t);
270
+ }
271
+ let S = y;
272
+ return {
273
+ size: S.size,
274
+ modules: S.modules,
275
+ version: o,
276
+ level: n,
277
+ mode: i,
278
+ mask: b
279
+ };
280
+ }
281
+ function z(e, t = 4) {
282
+ let n = [];
283
+ for (let r = 0; r < e.size; r++) {
284
+ let i = -1;
285
+ for (let a = 0; a <= e.size; a++) {
286
+ let o = a < e.size && e.modules[r][a];
287
+ o && i === -1 && (i = a), !o && i !== -1 && (n.push(`M${i + t} ${r + t}h${a - i}v1h-${a - i}z`), i = -1);
288
+ }
289
+ }
290
+ return n.join("");
291
+ }
292
+ //#endregion
293
+ export { s as QRCapacityError, R as encodeQR, z as matrixToPath, C as reedSolomon, d as selectMode };
294
+
295
+ //# sourceMappingURL=qr-encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qr-encode.js","names":[],"sources":["../../../src/components/QRCode/qr-encode.ts"],"sourcesContent":["import {\n ALPHANUMERIC_CHARS,\n alignmentPatternPositions,\n dataCodewords,\n ECC_BLOCK_COUNT,\n ECC_CODEWORDS_PER_BLOCK,\n ECC_FORMAT_BITS,\n MAX_VERSION,\n MIN_VERSION,\n rawDataModules,\n type QRErrorCorrection,\n} from \"./qr-tables\";\n\nexport type { QRErrorCorrection };\n\n/** How the payload is packed into bits. */\nexport type QRMode = \"numeric\" | \"alphanumeric\" | \"byte\";\n\nexport interface QRMatrix {\n /** Side length in modules, including no quiet zone. */\n size: number;\n /** Row-major modules; `true` is dark. */\n modules: boolean[][];\n /** Symbol version, 1 to 40. */\n version: number;\n /** Level the symbol was encoded at. */\n level: QRErrorCorrection;\n /** The mode chosen for the payload. */\n mode: QRMode;\n /** Which of the eight masks scored best. */\n mask: number;\n}\n\nexport interface QREncodeOptions {\n /** Error correction level. Default `\"M\"`. */\n level?: QRErrorCorrection;\n /**\n * Force a minimum version. The encoder still grows past it when the payload\n * does not fit — a version is a floor, never a cap that silently truncates.\n */\n minVersion?: number;\n}\n\n/** Raised when a payload cannot be encoded at the requested level. */\nexport class QRCapacityError extends Error {\n constructor(\n readonly length: number,\n readonly level: QRErrorCorrection,\n ) {\n super(\n `Payload of ${length} bytes does not fit in a version-${MAX_VERSION} QR symbol at level ${level}. ` +\n \"Shorten the data, or drop to a lower correction level.\",\n );\n this.name = \"QRCapacityError\";\n }\n}\n\nconst MODE_INDICATOR: Record<QRMode, number> = { numeric: 1, alphanumeric: 2, byte: 4 };\n\nconst NUMERIC_RE = /^[0-9]*$/;\nconst ALPHANUMERIC_RE = /^[0-9A-Z $%*+\\-./:]*$/;\n\n/**\n * Pick the densest mode the payload qualifies for.\n *\n * Numeric packs 3 digits into 10 bits and alphanumeric 2 characters into 11, so\n * a phone number or an upper-case code encodes far smaller than the same string\n * as bytes — often a whole version smaller, which is a visibly coarser symbol\n * and therefore easier to scan.\n *\n * @param text - The payload.\n * @returns The narrowest mode that can represent it.\n */\nexport function selectMode(text: string): QRMode {\n if (NUMERIC_RE.test(text)) return \"numeric\";\n if (ALPHANUMERIC_RE.test(text)) return \"alphanumeric\";\n return \"byte\";\n}\n\n/** Bits the character-count field takes, which widens with the version. */\nfunction charCountBits(mode: QRMode, version: number): number {\n const tier = version <= 9 ? 0 : version <= 26 ? 1 : 2;\n if (mode === \"numeric\") return [10, 12, 14][tier];\n if (mode === \"alphanumeric\") return [9, 11, 13][tier];\n return [8, 16, 16][tier];\n}\n\n/** A bit sink that appends most-significant-bit first. */\nclass BitBuffer {\n readonly bits: number[] = [];\n\n append(value: number, length: number) {\n for (let i = length - 1; i >= 0; i--) this.bits.push((value >>> i) & 1);\n }\n\n get length(): number {\n return this.bits.length;\n }\n}\n\n/** UTF-8 bytes for the byte mode, so accents and emoji survive the round trip. */\nfunction utf8Bytes(text: string): number[] {\n return Array.from(new TextEncoder().encode(text));\n}\n\n/** Bits the payload itself occupies in a given mode, excluding the headers. */\nfunction payloadBits(text: string, mode: QRMode): number {\n if (mode === \"numeric\") {\n const groups = Math.floor(text.length / 3);\n const rest = text.length % 3;\n return groups * 10 + (rest === 0 ? 0 : rest === 1 ? 4 : 7);\n }\n if (mode === \"alphanumeric\") {\n return Math.floor(text.length / 2) * 11 + (text.length % 2) * 6;\n }\n return utf8Bytes(text).length * 8;\n}\n\n/** Write the payload into the buffer in the chosen mode. */\nfunction writePayload(buffer: BitBuffer, text: string, mode: QRMode) {\n if (mode === \"numeric\") {\n for (let i = 0; i < text.length; i += 3) {\n const chunk = text.slice(i, i + 3);\n buffer.append(Number(chunk), chunk.length * 3 + 1);\n }\n return;\n }\n if (mode === \"alphanumeric\") {\n for (let i = 0; i < text.length; i += 2) {\n const first = ALPHANUMERIC_CHARS.indexOf(text[i]);\n if (i + 1 === text.length) {\n buffer.append(first, 6);\n } else {\n buffer.append(first * 45 + ALPHANUMERIC_CHARS.indexOf(text[i + 1]), 11);\n }\n }\n return;\n }\n for (const byte of utf8Bytes(text)) buffer.append(byte, 8);\n}\n\n/** Character count for the header, which is bytes — not characters — in byte mode. */\nfunction headerCount(text: string, mode: QRMode): number {\n return mode === \"byte\" ? utf8Bytes(text).length : text.length;\n}\n\n/**\n * The smallest version that fits the payload at this level.\n *\n * @throws {QRCapacityError} When even version 40 is too small.\n */\nfunction selectVersion(\n text: string,\n mode: QRMode,\n level: QRErrorCorrection,\n minVersion: number,\n): number {\n const bits = payloadBits(text, mode);\n for (let version = Math.max(MIN_VERSION, minVersion); version <= MAX_VERSION; version++) {\n const capacity = dataCodewords(version, level) * 8;\n if (4 + charCountBits(mode, version) + bits <= capacity) return version;\n }\n throw new QRCapacityError(headerCount(text, mode), level);\n}\n\n// ── Reed-Solomon over GF(256), primitive polynomial 0x11D ───────────────────\n\nconst GF_EXP = new Uint8Array(512);\nconst GF_LOG = new Uint8Array(256);\n\n{\n let x = 1;\n for (let i = 0; i < 255; i++) {\n GF_EXP[i] = x;\n GF_LOG[x] = i;\n x = (x << 1) ^ (x & 0x80 ? 0x11d : 0);\n }\n for (let i = 255; i < 512; i++) GF_EXP[i] = GF_EXP[i - 255];\n}\n\nfunction gfMul(a: number, b: number): number {\n if (a === 0 || b === 0) return 0;\n return GF_EXP[GF_LOG[a] + GF_LOG[b]];\n}\n\n/** The generator polynomial for `degree` error-correction codewords. */\nfunction rsGenerator(degree: number): number[] {\n let poly = [1];\n for (let i = 0; i < degree; i++) {\n const next = new Array<number>(poly.length + 1).fill(0);\n for (let j = 0; j < poly.length; j++) {\n next[j] ^= poly[j];\n next[j + 1] ^= gfMul(poly[j], GF_EXP[i]);\n }\n poly = next;\n }\n return poly;\n}\n\n/**\n * The error-correction codewords for one block.\n *\n * @param data - The block's data codewords.\n * @param degree - How many correction codewords to produce.\n * @returns The remainder of the polynomial division, which is the ECC block.\n */\nexport function reedSolomon(data: readonly number[], degree: number): number[] {\n const generator = rsGenerator(degree);\n const remainder = new Array<number>(degree).fill(0);\n for (const byte of data) {\n const factor = byte ^ remainder[0];\n remainder.shift();\n remainder.push(0);\n for (let i = 0; i < degree; i++) {\n remainder[i] ^= gfMul(generator[i + 1], factor);\n }\n }\n return remainder;\n}\n\n/**\n * Split into blocks, add correction, and interleave into the final codeword\n * stream.\n *\n * Interleaving is what makes the correction useful against a real-world smudge:\n * a contiguous scratch on the printed symbol then damages a few codewords of\n * every block instead of destroying one block completely.\n */\nfunction buildCodewords(\n data: readonly number[],\n version: number,\n level: QRErrorCorrection,\n): number[] {\n const blockCount = ECC_BLOCK_COUNT[level][version - 1];\n const eccPerBlock = ECC_CODEWORDS_PER_BLOCK[level][version - 1];\n const totalCodewords = Math.floor(rawDataModules(version) / 8);\n const shortBlockLength = Math.floor(totalCodewords / blockCount) - eccPerBlock;\n const longBlockCount = totalCodewords % blockCount;\n\n const dataBlocks: number[][] = [];\n const eccBlocks: number[][] = [];\n let offset = 0;\n for (let i = 0; i < blockCount; i++) {\n const length = shortBlockLength + (i >= blockCount - longBlockCount ? 1 : 0);\n const block = data.slice(offset, offset + length);\n offset += length;\n dataBlocks.push(block);\n eccBlocks.push(reedSolomon(block, eccPerBlock));\n }\n\n const result: number[] = [];\n for (let i = 0; i < shortBlockLength + 1; i++) {\n for (const block of dataBlocks) {\n if (i < block.length) result.push(block[i]);\n }\n }\n for (let i = 0; i < eccPerBlock; i++) {\n for (const block of eccBlocks) result.push(block[i]);\n }\n return result;\n}\n\n// ── Matrix construction ─────────────────────────────────────────────────────\n\n/** A grid under construction: modules plus which cells are function patterns. */\ninterface Canvas {\n size: number;\n modules: boolean[][];\n reserved: boolean[][];\n}\n\nfunction createCanvas(version: number): Canvas {\n const size = version * 4 + 17;\n return {\n size,\n modules: Array.from({ length: size }, () => new Array<boolean>(size).fill(false)),\n reserved: Array.from({ length: size }, () => new Array<boolean>(size).fill(false)),\n };\n}\n\nfunction setModule(canvas: Canvas, x: number, y: number, dark: boolean, reserve = true) {\n if (x < 0 || y < 0 || x >= canvas.size || y >= canvas.size) return;\n canvas.modules[y][x] = dark;\n if (reserve) canvas.reserved[y][x] = true;\n}\n\n/** A finder pattern with its separator, anchored at a corner. */\nfunction drawFinder(canvas: Canvas, left: number, top: number) {\n for (let dy = -1; dy <= 7; dy++) {\n for (let dx = -1; dx <= 7; dx++) {\n const distance = Math.max(Math.abs(dx - 3), Math.abs(dy - 3));\n setModule(canvas, left + dx, top + dy, distance !== 2 && distance <= 3);\n }\n }\n}\n\nfunction drawAlignment(canvas: Canvas, cx: number, cy: number) {\n for (let dy = -2; dy <= 2; dy++) {\n for (let dx = -2; dx <= 2; dx++) {\n setModule(canvas, cx + dx, cy + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);\n }\n }\n}\n\nfunction drawFunctionPatterns(canvas: Canvas, version: number) {\n drawFinder(canvas, 0, 0);\n drawFinder(canvas, canvas.size - 7, 0);\n drawFinder(canvas, 0, canvas.size - 7);\n\n for (let i = 8; i < canvas.size - 8; i++) {\n const dark = i % 2 === 0;\n setModule(canvas, i, 6, dark);\n setModule(canvas, 6, i, dark);\n }\n\n const positions = alignmentPatternPositions(version);\n for (const cy of positions) {\n for (const cx of positions) {\n // The three corners already hold finder patterns.\n const atFinder =\n (cx === 6 && cy === 6) ||\n (cx === 6 && cy === canvas.size - 7) ||\n (cx === canvas.size - 7 && cy === 6);\n if (!atFinder) drawAlignment(canvas, cx, cy);\n }\n }\n\n // Reserve the format information, and light the always-dark module.\n for (let i = 0; i < 9; i++) {\n setModule(canvas, i, 8, false);\n setModule(canvas, 8, i, false);\n }\n for (let i = 0; i < 8; i++) {\n setModule(canvas, canvas.size - 1 - i, 8, false);\n setModule(canvas, 8, canvas.size - 1 - i, false);\n }\n setModule(canvas, 8, canvas.size - 8, true);\n\n if (version >= 7) {\n const value = versionInformation(version);\n for (let i = 0; i < 18; i++) {\n const bit = ((value >>> i) & 1) === 1;\n const a = canvas.size - 11 + (i % 3);\n const b = Math.floor(i / 3);\n setModule(canvas, a, b, bit);\n setModule(canvas, b, a, bit);\n }\n }\n}\n\n/** The 18-bit version information block, BCH(18,6) with generator 0x1F25. */\nfunction versionInformation(version: number): number {\n let remainder = version;\n for (let i = 0; i < 12; i++) {\n remainder = (remainder << 1) ^ ((remainder >>> 11) * 0x1f25);\n }\n return (version << 12) | remainder;\n}\n\n/** The 15-bit format information, BCH(15,5) masked with 0x5412. */\nfunction formatInformation(level: QRErrorCorrection, mask: number): number {\n const data = (ECC_FORMAT_BITS[level] << 3) | mask;\n let remainder = data;\n for (let i = 0; i < 10; i++) {\n remainder = (remainder << 1) ^ ((remainder >>> 9) * 0x537);\n }\n return ((data << 10) | remainder) ^ 0x5412;\n}\n\nfunction drawFormatInformation(canvas: Canvas, level: QRErrorCorrection, mask: number) {\n const bits = formatInformation(level, mask);\n\n for (let i = 0; i <= 5; i++) setModule(canvas, 8, i, ((bits >>> i) & 1) === 1);\n setModule(canvas, 8, 7, ((bits >>> 6) & 1) === 1);\n setModule(canvas, 8, 8, ((bits >>> 7) & 1) === 1);\n setModule(canvas, 7, 8, ((bits >>> 8) & 1) === 1);\n for (let i = 9; i < 15; i++) setModule(canvas, 14 - i, 8, ((bits >>> i) & 1) === 1);\n\n for (let i = 0; i < 8; i++) {\n setModule(canvas, canvas.size - 1 - i, 8, ((bits >>> i) & 1) === 1);\n }\n for (let i = 8; i < 15; i++) {\n setModule(canvas, 8, canvas.size - 15 + i, ((bits >>> i) & 1) === 1);\n }\n setModule(canvas, 8, canvas.size - 8, true);\n}\n\n/**\n * Lay the codeword stream into the free modules.\n *\n * The path is a boustrophedon over two-module columns from the bottom-right\n * corner, skipping the vertical timing pattern in column 6 entirely — that\n * column would otherwise shift every subsequent column by one.\n */\nfunction drawCodewords(canvas: Canvas, codewords: readonly number[]) {\n let bitIndex = 0;\n let upward = true;\n\n for (let right = canvas.size - 1; right >= 1; right -= 2) {\n if (right === 6) right = 5;\n for (let step = 0; step < canvas.size; step++) {\n const y = upward ? canvas.size - 1 - step : step;\n for (let column = 0; column < 2; column++) {\n const x = right - column;\n if (canvas.reserved[y][x]) continue;\n const byte = codewords[bitIndex >>> 3];\n // Remainder bits past the stream are light, per the standard.\n canvas.modules[y][x] =\n byte !== undefined && ((byte >>> (7 - (bitIndex & 7))) & 1) === 1;\n bitIndex++;\n }\n }\n upward = !upward;\n }\n}\n\nconst MASK_FUNCTIONS: readonly ((x: number, y: number) => boolean)[] = [\n (x, y) => (x + y) % 2 === 0,\n (_x, y) => y % 2 === 0,\n (x) => x % 3 === 0,\n (x, y) => (x + y) % 3 === 0,\n (x, y) => (Math.floor(y / 2) + Math.floor(x / 3)) % 2 === 0,\n (x, y) => ((x * y) % 2) + ((x * y) % 3) === 0,\n (x, y) => (((x * y) % 2) + ((x * y) % 3)) % 2 === 0,\n (x, y) => (((x + y) % 2) + ((x * y) % 3)) % 2 === 0,\n];\n\nfunction applyMask(canvas: Canvas, mask: number) {\n const fn = MASK_FUNCTIONS[mask];\n for (let y = 0; y < canvas.size; y++) {\n for (let x = 0; x < canvas.size; x++) {\n if (!canvas.reserved[y][x] && fn(x, y)) canvas.modules[y][x] = !canvas.modules[y][x];\n }\n }\n}\n\n/**\n * Score a masked symbol; lower is better.\n *\n * The four penalties push away from patterns a scanner confuses with the finder\n * marks, and from large flat areas where it cannot lock on.\n */\nfunction penalty(canvas: Canvas): number {\n const { size, modules } = canvas;\n let score = 0;\n\n const runPenalty = (run: number) => (run >= 5 ? 3 + (run - 5) : 0);\n\n for (let y = 0; y < size; y++) {\n let run = 1;\n for (let x = 1; x < size; x++) {\n if (modules[y][x] === modules[y][x - 1]) run++;\n else {\n score += runPenalty(run);\n run = 1;\n }\n }\n score += runPenalty(run);\n }\n for (let x = 0; x < size; x++) {\n let run = 1;\n for (let y = 1; y < size; y++) {\n if (modules[y][x] === modules[y - 1][x]) run++;\n else {\n score += runPenalty(run);\n run = 1;\n }\n }\n score += runPenalty(run);\n }\n\n for (let y = 0; y < size - 1; y++) {\n for (let x = 0; x < size - 1; x++) {\n const cell = modules[y][x];\n if (\n cell === modules[y][x + 1] &&\n cell === modules[y + 1][x] &&\n cell === modules[y + 1][x + 1]\n ) {\n score += 3;\n }\n }\n }\n\n // 1:1:3:1:1 with four light modules on either side — the finder's signature.\n const FINDER = [true, false, true, true, true, false, true];\n const matchesAt = (line: readonly boolean[], at: number): boolean => {\n for (let i = 0; i < FINDER.length; i++) {\n if (line[at + i] !== FINDER[i]) return false;\n }\n const before = line.slice(Math.max(0, at - 4), at);\n const after = line.slice(at + 7, at + 11);\n const clear = (part: readonly boolean[]) => part.length === 4 && part.every((m) => !m);\n return clear(before) || clear(after);\n };\n\n for (let i = 0; i < size; i++) {\n const row = modules[i];\n const column = modules.map((line) => line[i]);\n for (let at = 0; at + 7 <= size; at++) {\n if (matchesAt(row, at)) score += 40;\n if (matchesAt(column, at)) score += 40;\n }\n }\n\n let dark = 0;\n for (const row of modules) for (const cell of row) if (cell) dark++;\n const percent = (dark * 100) / (size * size);\n score += Math.floor(Math.abs(percent - 50) / 5) * 10;\n\n return score;\n}\n\nfunction cloneCanvas(canvas: Canvas): Canvas {\n return {\n size: canvas.size,\n modules: canvas.modules.map((row) => [...row]),\n reserved: canvas.reserved.map((row) => [...row]),\n };\n}\n\n/**\n * Encode text into a QR matrix.\n *\n * The whole pipeline of ISO/IEC 18004: pick the densest mode the payload\n * qualifies for, pick the smallest version that fits, build the bit stream, add\n * Reed-Solomon correction, interleave the blocks, lay the modules out, then try\n * all eight masks and keep the one the standard's penalty function likes best.\n *\n * @param text - The payload. Byte mode encodes it as UTF-8.\n * @param options - Level and an optional version floor.\n * @returns The finished matrix, without a quiet zone.\n * @throws {QRCapacityError} When the payload does not fit at that level.\n *\n * @example\n * const qr = encodeQR(\"https://tempest.dev\", { level: \"Q\" });\n * qr.modules[0][0]; // true — top-left of the finder pattern\n */\nexport function encodeQR(text: string, options: QREncodeOptions = {}): QRMatrix {\n const { level = \"M\", minVersion = MIN_VERSION } = options;\n const mode = selectMode(text);\n const version = selectVersion(text, mode, level, minVersion);\n\n const buffer = new BitBuffer();\n buffer.append(MODE_INDICATOR[mode], 4);\n buffer.append(headerCount(text, mode), charCountBits(mode, version));\n writePayload(buffer, text, mode);\n\n const capacity = dataCodewords(version, level) * 8;\n buffer.append(0, Math.min(4, capacity - buffer.length));\n buffer.append(0, (8 - (buffer.length % 8)) % 8);\n\n const data: number[] = [];\n for (let i = 0; i < buffer.length; i += 8) {\n let byte = 0;\n for (let j = 0; j < 8; j++) byte = (byte << 1) | buffer.bits[i + j];\n data.push(byte);\n }\n // The two alternating pad bytes are prescribed, not arbitrary filler.\n for (let pad = 0xec; data.length < capacity / 8; pad ^= 0xec ^ 0x11) data.push(pad);\n\n const codewords = buildCodewords(data, version, level);\n\n const base = createCanvas(version);\n drawFunctionPatterns(base, version);\n drawCodewords(base, codewords);\n\n let best: Canvas | null = null;\n let bestMask = 0;\n let bestScore = Number.POSITIVE_INFINITY;\n for (let mask = 0; mask < 8; mask++) {\n const candidate = cloneCanvas(base);\n applyMask(candidate, mask);\n drawFormatInformation(candidate, level, mask);\n const score = penalty(candidate);\n if (score < bestScore) {\n bestScore = score;\n bestMask = mask;\n best = candidate;\n }\n }\n\n const chosen = best as Canvas;\n return {\n size: chosen.size,\n modules: chosen.modules,\n version,\n level,\n mode,\n mask: bestMask,\n };\n}\n\n/**\n * The matrix as an SVG path, one `M…h…v…h…z` rectangle per dark module.\n *\n * A path beats one `<rect>` per module: a version-10 symbol is 3 481 modules,\n * and that many elements is a real cost to parse and to paint. Coordinates are\n * whole numbers in module space, so the shape stays crisp at any size.\n *\n * @param matrix - An encoded matrix.\n * @param margin - Quiet zone in modules. The standard asks for 4.\n * @returns The `d` attribute, empty when there is nothing dark.\n */\nexport function matrixToPath(matrix: QRMatrix, margin = 4): string {\n const parts: string[] = [];\n for (let y = 0; y < matrix.size; y++) {\n let runStart = -1;\n for (let x = 0; x <= matrix.size; x++) {\n const dark = x < matrix.size && matrix.modules[y][x];\n if (dark && runStart === -1) runStart = x;\n if (!dark && runStart !== -1) {\n // Merge each horizontal run into one rectangle.\n parts.push(\n `M${runStart + margin} ${y + margin}h${x - runStart}v1h-${x - runStart}z`,\n );\n runStart = -1;\n }\n }\n }\n return parts.join(\"\");\n}\n"],"mappings":";;AA4CA,IAAa,IAAb,cAAqC,MAAM;CAE1B;CACA;CAFb,YACI,GACA,GACF;EAKE,AAJA,MACI,cAAc,EAAO,yDAAqE,EAAM,yDAEpG,GANS,KAAA,SAAA,GACA,KAAA,QAAA,GAMT,KAAK,OAAO;CAChB;AACJ,GAEM,IAAyC;CAAE,SAAS;CAAG,cAAc;CAAG,MAAM;AAAE,GAEhF,IAAa,YACb,IAAkB;AAaxB,SAAgB,EAAW,GAAsB;CAG7C,OAFI,EAAW,KAAK,CAAI,IAAU,YAC9B,EAAgB,KAAK,CAAI,IAAU,iBAChC;AACX;AAGA,SAAS,EAAc,GAAc,GAAyB;CAC1D,IAAM,IAAO,KAAW,IAAI,IAAI,KAAW,KAAK,IAAI;CAGpD,OAFI,MAAS,YAAkB;EAAC;EAAI;EAAI;CAAE,CAAC,CAAC,KACxC,MAAS,iBAAuB;EAAC;EAAG;EAAI;CAAE,CAAC,CAAC,KACzC;EAAC;EAAG;EAAI;CAAE,CAAC,CAAC;AACvB;AAGA,IAAM,IAAN,MAAgB;CACZ,OAA0B,CAAC;CAE3B,OAAO,GAAe,GAAgB;EAClC,KAAK,IAAI,IAAI,IAAS,GAAG,KAAK,GAAG,KAAK,KAAK,KAAK,KAAM,MAAU,IAAK,CAAC;CAC1E;CAEA,IAAI,SAAiB;EACjB,OAAO,KAAK,KAAK;CACrB;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;EACH,MAAM,EAAO;EACb,SAAS,EAAO;EAChB;EACA;EACA;EACA,MAAM;CACV;AACJ;AAaA,SAAgB,EAAa,GAAkB,IAAS,GAAW;CAC/D,IAAM,IAAkB,CAAC;CACzB,KAAK,IAAI,IAAI,GAAG,IAAI,EAAO,MAAM,KAAK;EAClC,IAAI,IAAW;EACf,KAAK,IAAI,IAAI,GAAG,KAAK,EAAO,MAAM,KAAK;GACnC,IAAM,IAAO,IAAI,EAAO,QAAQ,EAAO,QAAQ,EAAE,CAAC;GAElD,AADI,KAAQ,MAAa,OAAI,IAAW,IACpC,CAAC,KAAQ,MAAa,OAEtB,EAAM,KACF,IAAI,IAAW,EAAO,GAAG,IAAI,EAAO,GAAG,IAAI,EAAS,MAAM,IAAI,EAAS,EAC3E,GACA,IAAW;EAEnB;CACJ;CACA,OAAO,EAAM,KAAK,EAAE;AACxB"}
@@ -0,0 +1,2 @@
1
+ var e={L:1,M:0,Q:3,H:2},t={L:[7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],M:[10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],Q:[13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],H:[17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]},n={L:[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,15,16,17,18,19,19,20,21,22,24,25],M:[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,25,26,28,29,31,33,35,37,38,40,43,45,47,49],Q:[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,34,35,38,40,43,45,48,51,53,56,59,62,65,68],H:[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,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]},r=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`;function i(e){let t=(16*e+128)*e+64;if(e>=2){let n=Math.floor(e/7)+2;t-=(25*n-10)*n-55,e>=7&&(t-=36)}return t}function a(e,r){return Math.floor(i(e)/8)-t[r][e-1]*n[r][e-1]}function o(e){if(e===1)return[];let t=Math.floor(e/7)+2,n=e===32?26:Math.ceil((e*4+4)/(t*2-2))*2,r=[6];for(let i=e*4+10;r.length<t;i-=n)r.splice(1,0,i);return r}exports.ALPHANUMERIC_CHARS=r,exports.ECC_BLOCK_COUNT=n,exports.ECC_CODEWORDS_PER_BLOCK=t,exports.ECC_FORMAT_BITS=e,exports.alignmentPatternPositions=o,exports.dataCodewords=a,exports.rawDataModules=i;
2
+ //# sourceMappingURL=qr-tables.cjs.map
@@ -0,0 +1 @@
1
+ {"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; p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