@sythos/js_barcode_universal 1.5.5 → 1.5.7

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 (94) hide show
  1. package/README.md +15 -3
  2. package/bundle/sythos-barcode.esm.js +2 -2
  3. package/bundle/sythos-barcode.js +2 -2
  4. package/examples/read.html +5 -3
  5. package/package.json +91 -25
  6. package/src/index.js +1 -1
  7. package/typings/aztec/decoder.d.ts +57 -0
  8. package/typings/aztec/detector.d.ts +62 -0
  9. package/typings/aztec/encoder.d.ts +94 -0
  10. package/typings/aztec/high-level.d.ts +89 -0
  11. package/typings/aztec/index.d.ts +35 -0
  12. package/typings/aztec/tables.d.ts +144 -0
  13. package/typings/aztecrune/decoder.d.ts +56 -0
  14. package/typings/aztecrune/detector.d.ts +53 -0
  15. package/typings/aztecrune/encoder.d.ts +51 -0
  16. package/typings/aztecrune/index.d.ts +35 -0
  17. package/typings/aztecrune/tables.d.ts +75 -0
  18. package/typings/bundle/sythos-barcode.d.ts +31 -0
  19. package/typings/bundle/sythos-barcode.esm.d.ts +31 -0
  20. package/typings/compactpdf417/decoder.d.ts +64 -0
  21. package/typings/compactpdf417/detector.d.ts +48 -0
  22. package/typings/compactpdf417/encoder.d.ts +49 -0
  23. package/typings/compactpdf417/index.d.ts +8 -0
  24. package/typings/compactpdf417/tables.d.ts +84 -0
  25. package/typings/core/bit-buffer.d.ts +78 -0
  26. package/typings/core/bit-matrix.d.ts +129 -0
  27. package/typings/core/errors.d.ts +57 -0
  28. package/typings/core/galois-field.d.ts +141 -0
  29. package/typings/core/index.d.ts +40 -0
  30. package/typings/core/reed-solomon.d.ts +65 -0
  31. package/typings/databar/codec.d.ts +78 -0
  32. package/typings/databar/decoder.d.ts +55 -0
  33. package/typings/databar/encoder.d.ts +34 -0
  34. package/typings/databar/gs1.d.ts +48 -0
  35. package/typings/databar/index.d.ts +37 -0
  36. package/typings/databar/patterns.d.ts +46 -0
  37. package/typings/databar/tables.d.ts +119 -0
  38. package/typings/datamatrix/decoder.d.ts +57 -0
  39. package/typings/datamatrix/detector.d.ts +59 -0
  40. package/typings/datamatrix/encoder.d.ts +36 -0
  41. package/typings/datamatrix/index.d.ts +35 -0
  42. package/typings/datamatrix/tables.d.ts +88 -0
  43. package/typings/frameqr/decoder.d.ts +64 -0
  44. package/typings/frameqr/detector.d.ts +96 -0
  45. package/typings/frameqr/encoder.d.ts +73 -0
  46. package/typings/frameqr/index.d.ts +34 -0
  47. package/typings/frameqr/tables.d.ts +123 -0
  48. package/typings/image/binarizer.d.ts +85 -0
  49. package/typings/image/grid-sampler.d.ts +82 -0
  50. package/typings/image/index.d.ts +39 -0
  51. package/typings/image/luminance.d.ts +112 -0
  52. package/typings/image/perspective.d.ts +111 -0
  53. package/typings/index.d.ts +363 -0
  54. package/typings/micropdf417/compaction.d.ts +38 -0
  55. package/typings/micropdf417/decoder.d.ts +57 -0
  56. package/typings/micropdf417/detector.d.ts +95 -0
  57. package/typings/micropdf417/encoder.d.ts +34 -0
  58. package/typings/micropdf417/error-correction.d.ts +38 -0
  59. package/typings/micropdf417/index.d.ts +36 -0
  60. package/typings/micropdf417/tables.d.ts +73 -0
  61. package/typings/microqr/decoder.d.ts +49 -0
  62. package/typings/microqr/detector.d.ts +96 -0
  63. package/typings/microqr/encoder.d.ts +33 -0
  64. package/typings/microqr/index.d.ts +35 -0
  65. package/typings/microqr/tables.d.ts +107 -0
  66. package/typings/oned/addons.d.ts +181 -0
  67. package/typings/oned/index.d.ts +55 -0
  68. package/typings/oned/patterns.d.ts +259 -0
  69. package/typings/oned/reader.d.ts +129 -0
  70. package/typings/oned/writers.d.ts +218 -0
  71. package/typings/pdf417/compaction.d.ts +59 -0
  72. package/typings/pdf417/decoder.d.ts +48 -0
  73. package/typings/pdf417/detector.d.ts +73 -0
  74. package/typings/pdf417/encoder.d.ts +32 -0
  75. package/typings/pdf417/error-correction.d.ts +34 -0
  76. package/typings/pdf417/index.d.ts +10 -0
  77. package/typings/pdf417/tables.d.ts +53 -0
  78. package/typings/qr/decoder.d.ts +79 -0
  79. package/typings/qr/detector.d.ts +93 -0
  80. package/typings/qr/encoder.d.ts +166 -0
  81. package/typings/qr/index.d.ts +43 -0
  82. package/typings/qr/tables.d.ts +291 -0
  83. package/typings/render/image-data.d.ts +58 -0
  84. package/typings/render/index.d.ts +110 -0
  85. package/typings/render/options.d.ts +98 -0
  86. package/typings/render/png.d.ts +58 -0
  87. package/typings/render/svg.d.ts +46 -0
  88. package/typings/render/webgl.d.ts +45 -0
  89. package/typings/render/webgpu.d.ts +51 -0
  90. package/typings/rmqr/decoder.d.ts +42 -0
  91. package/typings/rmqr/detector.d.ts +81 -0
  92. package/typings/rmqr/encoder.d.ts +45 -0
  93. package/typings/rmqr/index.d.ts +34 -0
  94. package/typings/rmqr/tables.d.ts +89 -0
@@ -0,0 +1,93 @@
1
+ /*!
2
+ * Sythos Barcode Suite
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2026 Sythos
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *
26
+ * SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
27
+ * SPDX-License-Identifier: MIT
28
+ *
29
+ * Original work. No code from any other barcode implementation.
30
+ */
31
+ export type Candidate = {
32
+ x: number;
33
+ y: number;
34
+ moduleSize: number;
35
+ hits: number;
36
+ };
37
+ export type Detection = {
38
+ /**
39
+ * Outer corners of the
40
+ * symbol, ordered top-left, top-right, bottom-right, bottom-left.
41
+ */
42
+ corners: Array<{
43
+ x: number;
44
+ y: number;
45
+ }>;
46
+ /**
47
+ * Modules per side.
48
+ */
49
+ dimension: number;
50
+ version: number;
51
+ /**
52
+ * Estimated pixels per module.
53
+ */
54
+ moduleSize: number;
55
+ alignmentFound: boolean;
56
+ };
57
+ /**
58
+ * @typedef {object} Detection
59
+ * @property {Array<{x: number, y: number}>} corners Outer corners of the
60
+ * symbol, ordered top-left, top-right, bottom-right, bottom-left.
61
+ * @property {number} dimension Modules per side.
62
+ * @property {number} version
63
+ * @property {number} moduleSize Estimated pixels per module.
64
+ * @property {boolean} alignmentFound
65
+ */
66
+ /**
67
+ * Find QR Code symbols in a binarized image.
68
+ *
69
+ * @param {import('../core/bit-matrix.js').BitMatrix} binaryImage Set bit = dark.
70
+ * @returns {Detection[]} Possibly empty; ordered by descending module size, so
71
+ * the most prominent symbol comes first.
72
+ */
73
+ export declare function detectQR(binaryImage: import('../core/bit-matrix.js').BitMatrix): Detection[];
74
+ /**
75
+ * Find and decode every QR Code in a binarized image.
76
+ *
77
+ * Each candidate gets up to four attempts: a plain centre sample, a 3x3
78
+ * majority vote for noisy input, and both of those rotated 180 degrees. The
79
+ * rotation retry matters because three finders in a right isoceles triangle
80
+ * look identical to the same three rotated half a turn — the orientation is
81
+ * only settled once the format information reads cleanly, which is to say once
82
+ * the decode succeeds.
83
+ *
84
+ * @param {import('../core/bit-matrix.js').BitMatrix} binaryImage
85
+ * @returns {Array<import('./decoder.js').DecodeResult & {corners: Array<{x: number, y: number}>}>}
86
+ * Empty when nothing decodes; never throws for "no symbol here".
87
+ */
88
+ export declare function detectAndDecodeQR(binaryImage: import('../core/bit-matrix.js').BitMatrix): Array<import('./decoder.js').DecodeResult & {
89
+ corners: Array<{
90
+ x: number;
91
+ y: number;
92
+ }>;
93
+ }>;
@@ -0,0 +1,166 @@
1
+ /*!
2
+ * Sythos Barcode Suite
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2026 Sythos
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *
26
+ * SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
27
+ * SPDX-License-Identifier: MIT
28
+ *
29
+ * Original work. No code from any other barcode implementation.
30
+ */
31
+ /**
32
+ * QR Code encoder.
33
+ *
34
+ * Pipeline: analyse the text into mode segments, pick the smallest version that
35
+ * holds them, serialise the bitstream, split it into Reed-Solomon blocks,
36
+ * interleave data and parity, lay the result into the module grid along the
37
+ * zig-zag path, then choose the mask that scores best under the four penalty
38
+ * rules.
39
+ *
40
+ * Segment selection is a shortest-path problem, not a greedy scan. "1234ABCD"
41
+ * is cheaper as one alphanumeric segment than as numeric plus alphanumeric,
42
+ * because a mode switch costs a mode indicator plus a character count field;
43
+ * whether that trade pays depends on run lengths that a left-to-right scan
44
+ * cannot see yet. The dynamic program below weighs it properly.
45
+ *
46
+ * It also has to run *per version band*, because the character count field
47
+ * widens at versions 10 and 27 — so the cheapest segmentation depends on the
48
+ * version, and the smallest sufficient version depends on the segmentation.
49
+ * {@link encodeQR} resolves the circularity by solving each band independently
50
+ * and taking the first version that fits.
51
+ *
52
+ * @module qr/encoder
53
+ */
54
+ import { BitMatrix } from '../core/bit-matrix.js';
55
+ /** Alphanumeric mode character set; a character's index is its encoded value. */
56
+ export declare const ALPHANUMERIC_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
57
+ /** ECI designator for UTF-8. */
58
+ export declare const ECI_UTF8 = 26;
59
+ export type EncodeOptions = {
60
+ /**
61
+ * Error correction level. Default 'M'.
62
+ */
63
+ ecc?: 'L' | 'M' | 'Q' | 'H';
64
+ /**
65
+ * Force a version 1-40 instead of the smallest fit.
66
+ */
67
+ version?: number;
68
+ /**
69
+ * Force a mask 0-7 instead of the best-scoring one.
70
+ */
71
+ mask?: number;
72
+ /**
73
+ * Byte mode interpretation.
74
+ * 'auto' uses ISO-8859-1 when the text allows it and UTF-8 with an ECI
75
+ * header otherwise.
76
+ */
77
+ charset?: 'auto' | 'utf-8' | 'iso-8859-1';
78
+ /**
79
+ * Allow kanji mode. Default true; ignored when the
80
+ * platform cannot supply a Shift_JIS codec.
81
+ */
82
+ kanji?: boolean;
83
+ };
84
+ /**
85
+ * Pack a Shift_JIS double byte into the 13-bit kanji mode value.
86
+ *
87
+ * The two covered ranges are folded onto a single contiguous space by
88
+ * subtracting a different offset from each, then re-basing the low byte to 0xC0
89
+ * values per high byte.
90
+ *
91
+ * @param {number} sjis 16-bit Shift_JIS value.
92
+ * @returns {number} 13-bit value, or -1 if outside the kanji mode ranges.
93
+ */
94
+ export declare function sjisToThirteenBits(sjis: number): number;
95
+ export type CharInfo = {
96
+ /**
97
+ * Code points.
98
+ */
99
+ points: string[];
100
+ numeric: Uint8Array;
101
+ /**
102
+ * Alphanumeric value, or -1.
103
+ */
104
+ alnum: Int32Array;
105
+ /**
106
+ * Bytes this code point costs in byte mode.
107
+ */
108
+ byteLen: Int32Array;
109
+ /**
110
+ * 13-bit kanji value, or -1.
111
+ */
112
+ kanji: Int32Array;
113
+ utf8: boolean;
114
+ };
115
+ export type Segment = {
116
+ mode: number;
117
+ /**
118
+ * Inclusive index into the code point array.
119
+ */
120
+ start: number;
121
+ /**
122
+ * Exclusive.
123
+ */
124
+ end: number;
125
+ };
126
+ /**
127
+ * The 15-bit masked format information.
128
+ *
129
+ * @param {string} ecc @param {number} mask
130
+ * @returns {number}
131
+ */
132
+ export declare function formatInfoBits(ecc: string, mask: number): number;
133
+ /**
134
+ * The 18-bit version information, for versions 7 and up.
135
+ *
136
+ * @param {number} version
137
+ * @returns {number}
138
+ */
139
+ export declare function versionInfoBits(version: number): number;
140
+ /**
141
+ * The four penalty rules. Lower is better.
142
+ *
143
+ * These exist to keep a symbol readable: long uniform runs and large blocks
144
+ * confuse the binarizer, finder lookalikes confuse the detector, and a symbol
145
+ * far from half dark loses contrast headroom. Scoring is a heuristic, not a
146
+ * correctness surface — any of the eight masks decodes, because the format
147
+ * information says which one was used.
148
+ *
149
+ * @param {BitMatrix} m
150
+ * @returns {number}
151
+ */
152
+ export declare function maskPenalty(m: BitMatrix): number;
153
+ /**
154
+ * Encode text as a QR Code.
155
+ *
156
+ * The result carries no quiet zone; callers add one with
157
+ * `matrix.withMargin(4)`. Keeping the margin out of the encoder means the
158
+ * renderer decides it, which is where the decision belongs — a symbol embedded
159
+ * in a design and a symbol printed on a label want different borders.
160
+ *
161
+ * @param {string} text
162
+ * @param {EncodeOptions} [options]
163
+ * @returns {BitMatrix} Set bit = dark module.
164
+ * @throws {EncodeError} If the text does not fit, or the options are invalid.
165
+ */
166
+ export declare function encodeQR(text: string, options?: EncodeOptions): BitMatrix;
@@ -0,0 +1,43 @@
1
+ /*!
2
+ * Sythos Barcode Suite
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2026 Sythos
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *
26
+ * SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
27
+ * SPDX-License-Identifier: MIT
28
+ *
29
+ * Original work. No code from any other barcode implementation.
30
+ */
31
+ /**
32
+ * QR Code, re-exported.
33
+ *
34
+ * `QR_PLACEHOLDER` is deliberately absent: `src/index.js` probes for it to
35
+ * decide whether this build can read and write QR, and its absence is what
36
+ * reports the format as available.
37
+ *
38
+ * @module qr
39
+ */
40
+ export { encodeQR } from './encoder.js';
41
+ export { decodeQR } from './decoder.js';
42
+ export { detectQR, detectAndDecodeQR } from './detector.js';
43
+ export { validateTables } from './tables.js';
@@ -0,0 +1,291 @@
1
+ /*!
2
+ * Sythos Barcode Suite
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2026 Sythos
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *
26
+ * SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
27
+ * SPDX-License-Identifier: MIT
28
+ *
29
+ * Original work. No code from any other barcode implementation.
30
+ */
31
+ /**
32
+ * QR Code structural tables.
33
+ *
34
+ * The design principle here is that as little as possible is *recalled* and as
35
+ * much as possible is *derived*, because a barcode table is the one place where
36
+ * a single mistyped digit produces a symbol that looks perfect and scans as
37
+ * garbage — or, worse, scans correctly for the payload you tested and fails for
38
+ * the payload your user sends.
39
+ *
40
+ * So:
41
+ *
42
+ * - Symbol size, function-pattern layout and total codeword capacity are
43
+ * computed from geometry. Nothing is tabulated that the module grid already
44
+ * knows.
45
+ * - Alignment centres come from the spec's spacing rule, not a 40-row table.
46
+ * - The group-1 / group-2 block split is arithmetic, not data.
47
+ *
48
+ * That leaves exactly three recalled numbers per (version, level): the error
49
+ * correction codewords per block, the block count, and the total data codeword
50
+ * count. Those three are deliberately redundant — they must satisfy
51
+ *
52
+ * blocks * eccPerBlock + totalDataCodewords === geometricTotalCodewords(v)
53
+ *
54
+ * for all 160 combinations, where the right-hand side is counted off the module
55
+ * grid. Any single typo on either side breaks the identity. {@link validateTables}
56
+ * enforces it, and the test suite asserts it returns no problems.
57
+ *
58
+ * @module qr/tables
59
+ */
60
+ import { BitMatrix } from '../core/bit-matrix.js';
61
+ /** Error correction levels, weakest to strongest. */
62
+ export declare const ECC_LEVELS: string[];
63
+ /**
64
+ * Two-bit level indicator used in the format information.
65
+ * Note this is *not* the L/M/Q/H ordering — the spec assigns them out of order.
66
+ */
67
+ export declare const ECC_LEVEL_BITS: {
68
+ L: number;
69
+ M: number;
70
+ Q: number;
71
+ H: number;
72
+ };
73
+ /** Inverse of {@link ECC_LEVEL_BITS}, indexed by the 2-bit value. */
74
+ export declare const ECC_LEVEL_BY_BITS: string[];
75
+ export declare const MIN_VERSION = 1;
76
+ export declare const MAX_VERSION = 40;
77
+ /** Version at and above which an 18-bit version information block is carried. */
78
+ export declare const VERSION_INFO_MIN = 7;
79
+ /** Mode indicator nibbles. */
80
+ export declare const MODE: {
81
+ TERMINATOR: number;
82
+ NUMERIC: number;
83
+ ALPHANUMERIC: number;
84
+ STRUCTURED_APPEND: number;
85
+ BYTE: number;
86
+ FNC1_FIRST: number;
87
+ ECI: number;
88
+ KANJI: number;
89
+ FNC1_SECOND: number;
90
+ };
91
+ /**
92
+ * @param {number} version 1-40
93
+ * @returns {number} Modules per side.
94
+ */
95
+ export declare function versionSize(version: number): number;
96
+ /**
97
+ * Bits in the character count indicator.
98
+ *
99
+ * @param {number} mode One of {@link MODE}.
100
+ * @param {number} version
101
+ * @returns {number}
102
+ */
103
+ export declare function countBits(mode: number, version: number): number;
104
+ /**
105
+ * Centre coordinates of the alignment patterns for a version.
106
+ *
107
+ * The spec's rule: the first centre is always 6 and the last is always
108
+ * `size - 7`; the count grows by one every seven versions; and the centres are
109
+ * evenly spaced with the *first* gap absorbing the rounding slack. Expressing
110
+ * that as arithmetic rather than a 40-row table means there is no table to
111
+ * mistype, and {@link validateTables} can then assert the shape of the result.
112
+ *
113
+ * @param {number} version
114
+ * @returns {number[]} Ascending centres. Empty for version 1.
115
+ */
116
+ export declare function alignmentCoordinates(version: number): number[];
117
+ /**
118
+ * Centres of the alignment patterns actually drawn, as [x, y] pairs.
119
+ *
120
+ * The three combinations that would sit on top of a finder pattern are omitted.
121
+ *
122
+ * @param {number} version
123
+ * @returns {Array<[number, number]>}
124
+ */
125
+ export declare function alignmentCentres(version: number): Array<[number, number]>;
126
+ /**
127
+ * Map of modules that carry function patterns rather than payload.
128
+ *
129
+ * A set bit means "reserved": finder, separator, timing, alignment, format
130
+ * information, the dark module, and the version information blocks. This is the
131
+ * single source of truth used by the encoder to skip modules while laying out
132
+ * the bitstream, by the decoder to read them back in the same order, and by
133
+ * {@link geometricTotalCodewords} to count what is left.
134
+ *
135
+ * Deriving capacity this way rather than by hand arithmetic is what makes the
136
+ * awkward cases free: an alignment pattern that overlaps the timing pattern is
137
+ * counted once because it is the same set of modules, not because anyone
138
+ * remembered to subtract five.
139
+ *
140
+ * @param {number} version
141
+ * @returns {BitMatrix} Shared, cached — treat as immutable.
142
+ */
143
+ export declare function reservedModules(version: number): BitMatrix;
144
+ /**
145
+ * Module positions of the two format information copies.
146
+ *
147
+ * Index `i` in each array is bit `i` of the 15-bit format value, bit 0 being
148
+ * the least significant.
149
+ *
150
+ * CAVEAT WORTH READING: the *direction* of this numbering is the one thing in
151
+ * this file that a round-trip test cannot falsify. Encoder and decoder share
152
+ * these tables, so a mirrored layout would pass every test in the suite and
153
+ * fail only against a real scanner. The layout below is the standard one; both
154
+ * sides deliberately consume this single definition so there is no second place
155
+ * for the convention to drift.
156
+ *
157
+ * @param {number} size Modules per side.
158
+ * @returns {[Array<[number, number]>, Array<[number, number]>]} [copyA, copyB]
159
+ */
160
+ export declare function formatInfoPositions(size: number): [Array<[number, number]>, Array<[number, number]>];
161
+ /**
162
+ * Modules available to data and error correction, counted off the grid.
163
+ *
164
+ * @param {number} version
165
+ * @returns {number}
166
+ */
167
+ export declare function freeModuleCount(version: number): number;
168
+ /**
169
+ * Total codewords (data + error correction) a version holds.
170
+ *
171
+ * Geometric, not tabulated — this is the reference the ECC table is checked
172
+ * against.
173
+ *
174
+ * @param {number} version
175
+ * @returns {number}
176
+ */
177
+ export declare function geometricTotalCodewords(version: number): number;
178
+ /**
179
+ * Bits left over after the last whole codeword, written as zeroes.
180
+ *
181
+ * @param {number} version
182
+ * @returns {number} 0, 3, 4 or 7.
183
+ */
184
+ export declare function remainderBits(version: number): number;
185
+ /**
186
+ * Module positions in bitstream order, as interleaved x, y pairs.
187
+ *
188
+ * The layout walks two-module-wide columns from the bottom-right corner
189
+ * leftward, alternating upward and downward, right module of the pair before
190
+ * the left, skipping the vertical timing column and every reserved module.
191
+ *
192
+ * Encoder and decoder both consume this one function. That is not tidiness: a
193
+ * placement order that disagrees between the two would still round-trip
194
+ * perfectly within this library while producing symbols no scanner can read.
195
+ * There is only one order because there is only one implementation of it.
196
+ *
197
+ * @param {number} version
198
+ * @returns {Int32Array} Shared, cached — treat as immutable. Length is
199
+ * `2 * freeModuleCount(version)`.
200
+ */
201
+ export declare function dataModuleOrder(version: number): Int32Array;
202
+ /**
203
+ * The eight data mask predicates.
204
+ *
205
+ * A true result means the module at (x, y) is inverted. Masks apply to payload
206
+ * modules only; function patterns are laid down after masking and are never
207
+ * touched.
208
+ *
209
+ * @param {number} mask 0-7
210
+ * @param {number} x Column.
211
+ * @param {number} y Row.
212
+ * @returns {boolean}
213
+ */
214
+ export declare function maskBit(mask: number, x: number, y: number): boolean;
215
+ export type BlockLayout = {
216
+ version: number;
217
+ ecc: string;
218
+ /**
219
+ * Data + error correction.
220
+ */
221
+ totalCodewords: number;
222
+ totalDataCodewords: number;
223
+ eccPerBlock: number;
224
+ blockCount: number;
225
+ /**
226
+ * Blocks holding the smaller data count.
227
+ */
228
+ group1Blocks: number;
229
+ group1DataCount: number;
230
+ /**
231
+ * Blocks holding one extra data codeword.
232
+ */
233
+ group2Blocks: number;
234
+ group2DataCount: number;
235
+ remainderBits: number;
236
+ };
237
+ /**
238
+ * @typedef {object} BlockLayout
239
+ * @property {number} version
240
+ * @property {string} ecc
241
+ * @property {number} totalCodewords Data + error correction.
242
+ * @property {number} totalDataCodewords
243
+ * @property {number} eccPerBlock
244
+ * @property {number} blockCount
245
+ * @property {number} group1Blocks Blocks holding the smaller data count.
246
+ * @property {number} group1DataCount
247
+ * @property {number} group2Blocks Blocks holding one extra data codeword.
248
+ * @property {number} group2DataCount
249
+ * @property {number} remainderBits
250
+ */
251
+ /**
252
+ * Block structure for a (version, level).
253
+ *
254
+ * The group split is derived: the spec distributes the remainder of
255
+ * `data / blocks` one codeword at a time into the *trailing* blocks, so the
256
+ * short blocks come first. That is arithmetic, and tabulating it would only
257
+ * create somewhere else for a typo to hide.
258
+ *
259
+ * @param {number} version
260
+ * @param {string} ecc 'L' | 'M' | 'Q' | 'H'
261
+ * @returns {BlockLayout}
262
+ */
263
+ export declare function blockLayout(version: number, ecc: string): BlockLayout;
264
+ /**
265
+ * Data capacity in codewords.
266
+ *
267
+ * @param {number} version
268
+ * @param {string} ecc
269
+ * @returns {number}
270
+ */
271
+ export declare function dataCodewords(version: number, ecc: string): number;
272
+ /**
273
+ * Data capacity in bits.
274
+ *
275
+ * @param {number} version
276
+ * @param {string} ecc
277
+ * @returns {number}
278
+ */
279
+ export declare function dataBitCapacity(version: number, ecc: string): number;
280
+ /**
281
+ * Self-check every table in this file.
282
+ *
283
+ * The load-bearing assertion is the capacity identity across all 160
284
+ * (version, level) combinations, but a pair of compensating typos could in
285
+ * principle slip past it, so the surrounding checks each constrain a different
286
+ * axis: monotonicity, the closed set of ECC block sizes, the field size limit,
287
+ * and the shape of the alignment coordinate sequence.
288
+ *
289
+ * @returns {string[]} Human-readable problems; empty means everything holds.
290
+ */
291
+ export declare function validateTables(): string[];
@@ -0,0 +1,58 @@
1
+ /*!
2
+ * Sythos Barcode Suite
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2026 Sythos
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *
26
+ * SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
27
+ * SPDX-License-Identifier: MIT
28
+ *
29
+ * Original work. No code from any other barcode implementation.
30
+ */
31
+ /**
32
+ * Render to an `ImageData`-shaped object.
33
+ *
34
+ * A plain object rather than a real `ImageData`, so this works in Node and in
35
+ * workers without a DOM. It is accepted directly by `ctx.putImageData` in the
36
+ * browser, and by this library's own reader.
37
+ *
38
+ * @param {import('../core/bit-matrix.js').BitMatrix} matrix
39
+ * @param {import('./options.js').RenderOptions} [options]
40
+ * @returns {{data: Uint8ClampedArray, width: number, height: number}}
41
+ */
42
+ export declare function toImageData(matrix: import('../core/bit-matrix.js').BitMatrix, options?: import('./options.js').RenderOptions): {
43
+ data: Uint8ClampedArray;
44
+ width: number;
45
+ height: number;
46
+ };
47
+ /**
48
+ * Draw into a canvas using its 2D context.
49
+ *
50
+ * This is the universal fallback: every browser that runs JavaScript at all
51
+ * has a 2D context, including every iOS Safari version.
52
+ *
53
+ * @param {import('../core/bit-matrix.js').BitMatrix} matrix
54
+ * @param {HTMLCanvasElement | OffscreenCanvas} canvas
55
+ * @param {import('./options.js').RenderOptions} [options]
56
+ * @returns {boolean} True when it drew.
57
+ */
58
+ export declare function toCanvas(matrix: import('../core/bit-matrix.js').BitMatrix, canvas: HTMLCanvasElement | OffscreenCanvas, options?: import('./options.js').RenderOptions): boolean;