@sythos/js_barcode_universal 1.5.6 → 1.5.8
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.
- package/NOTICE.md +1 -1
- package/README.md +55 -35
- package/bundle/sythos-barcode.esm.js +618 -465
- package/bundle/sythos-barcode.js +618 -465
- package/package.json +90 -24
- package/src/index.d.ts +363 -0
- package/src/index.js +286 -133
- package/src/{aztec → js/aztec}/decoder.js +0 -1
- package/src/{aztec → js/aztec}/detector.js +0 -1
- package/src/{aztec → js/aztec}/encoder.js +0 -1
- package/src/{aztec → js/aztec}/high-level.js +0 -1
- package/src/{aztec → js/aztec}/index.js +0 -1
- package/src/{aztec → js/aztec}/tables.js +0 -1
- package/src/{aztecrune → js/aztecrune}/decoder.js +0 -1
- package/src/{aztecrune → js/aztecrune}/detector.js +0 -1
- package/src/{aztecrune → js/aztecrune}/encoder.js +0 -1
- package/src/{aztecrune → js/aztecrune}/index.js +0 -1
- package/src/{aztecrune → js/aztecrune}/tables.js +0 -1
- package/src/{compactpdf417 → js/compactpdf417}/decoder.js +0 -1
- package/src/{compactpdf417 → js/compactpdf417}/detector.js +0 -1
- package/src/{compactpdf417 → js/compactpdf417}/encoder.js +0 -1
- package/src/{compactpdf417 → js/compactpdf417}/index.js +0 -5
- package/src/{compactpdf417 → js/compactpdf417}/tables.js +0 -1
- package/src/{core → js/core}/bit-buffer.js +0 -1
- package/src/{core → js/core}/bit-matrix.js +0 -1
- package/src/{core → js/core}/errors.js +0 -1
- package/src/{core → js/core}/galois-field.js +0 -1
- package/src/{core → js/core}/index.js +0 -1
- package/src/{core → js/core}/reed-solomon.js +0 -1
- package/src/{databar → js/databar}/codec.js +0 -1
- package/src/{databar → js/databar}/decoder.js +0 -1
- package/src/{databar → js/databar}/encoder.js +0 -1
- package/src/{databar → js/databar}/gs1.js +0 -1
- package/src/{databar → js/databar}/index.js +0 -1
- package/src/{databar → js/databar}/patterns.js +0 -1
- package/src/{databar → js/databar}/tables.js +0 -1
- package/src/{datamatrix → js/datamatrix}/decoder.js +0 -1
- package/src/{datamatrix → js/datamatrix}/detector.js +0 -1
- package/src/{datamatrix → js/datamatrix}/encoder.js +0 -1
- package/src/{datamatrix → js/datamatrix}/index.js +0 -1
- package/src/{datamatrix → js/datamatrix}/tables.js +0 -1
- package/src/{frameqr → js/frameqr}/decoder.js +15 -16
- package/src/{frameqr → js/frameqr}/detector.js +2 -3
- package/src/{frameqr → js/frameqr}/encoder.js +7 -8
- package/src/{frameqr → js/frameqr}/index.js +0 -1
- package/src/{frameqr → js/frameqr}/tables.js +10 -11
- package/src/{image → js/image}/binarizer.js +0 -1
- package/src/{image → js/image}/grid-sampler.js +0 -1
- package/src/js/image/index.js +40 -0
- package/src/{image → js/image}/luminance.js +0 -1
- package/src/{image → js/image}/perspective.js +0 -1
- package/src/{micropdf417 → js/micropdf417}/compaction.js +0 -1
- package/src/{micropdf417 → js/micropdf417}/decoder.js +0 -1
- package/src/{micropdf417 → js/micropdf417}/detector.js +0 -1
- package/src/{micropdf417 → js/micropdf417}/encoder.js +0 -1
- package/src/{micropdf417 → js/micropdf417}/error-correction.js +0 -1
- package/src/{micropdf417 → js/micropdf417}/index.js +0 -1
- package/src/{micropdf417 → js/micropdf417}/tables.js +0 -1
- package/src/{microqr → js/microqr}/decoder.js +0 -1
- package/src/{microqr → js/microqr}/detector.js +0 -1
- package/src/{microqr → js/microqr}/encoder.js +0 -1
- package/src/js/microqr/index.js +36 -0
- package/src/{microqr → js/microqr}/tables.js +0 -1
- package/src/{oned → js/oned}/addons.js +0 -1
- package/src/{oned → js/oned}/index.js +0 -1
- package/src/{oned → js/oned}/patterns.js +0 -1
- package/src/{oned → js/oned}/reader.js +0 -1
- package/src/{oned → js/oned}/writers.js +0 -1
- package/src/{pdf417 → js/pdf417}/compaction.js +0 -1
- package/src/{pdf417 → js/pdf417}/decoder.js +0 -1
- package/src/{pdf417 → js/pdf417}/detector.js +0 -1
- package/src/{pdf417 → js/pdf417}/encoder.js +0 -1
- package/src/{pdf417 → js/pdf417}/error-correction.js +0 -1
- package/src/js/pdf417/index.js +6 -0
- package/src/{pdf417 → js/pdf417}/tables.js +0 -1
- package/src/{qr → js/qr}/decoder.js +0 -1
- package/src/{qr → js/qr}/detector.js +0 -1
- package/src/{qr → js/qr}/encoder.js +0 -1
- package/src/js/qr/index.js +44 -0
- package/src/{qr → js/qr}/tables.js +0 -1
- package/src/{render → js/render}/image-data.js +0 -1
- package/src/{render → js/render}/index.js +0 -1
- package/src/{render → js/render}/options.js +0 -1
- package/src/{render → js/render}/png.js +0 -1
- package/src/{render → js/render}/svg.js +0 -1
- package/src/{render → js/render}/webgl.js +0 -1
- package/src/{render → js/render}/webgpu.js +0 -1
- package/src/{rmqr → js/rmqr}/decoder.js +0 -1
- package/src/{rmqr → js/rmqr}/detector.js +0 -1
- package/src/{rmqr → js/rmqr}/encoder.js +0 -1
- package/src/{rmqr → js/rmqr}/index.js +0 -1
- package/src/{rmqr → js/rmqr}/tables.js +0 -1
- package/src/ts/aztec/decoder.d.ts +57 -0
- package/src/ts/aztec/detector.d.ts +62 -0
- package/src/ts/aztec/encoder.d.ts +94 -0
- package/src/ts/aztec/high-level.d.ts +89 -0
- package/src/ts/aztec/index.d.ts +35 -0
- package/src/ts/aztec/tables.d.ts +144 -0
- package/src/ts/aztecrune/decoder.d.ts +56 -0
- package/src/ts/aztecrune/detector.d.ts +53 -0
- package/src/ts/aztecrune/encoder.d.ts +51 -0
- package/src/ts/aztecrune/index.d.ts +35 -0
- package/src/ts/aztecrune/tables.d.ts +75 -0
- package/src/ts/bundle/sythos-barcode.d.ts +31 -0
- package/src/ts/bundle/sythos-barcode.esm.d.ts +31 -0
- package/src/ts/compactpdf417/decoder.d.ts +64 -0
- package/src/ts/compactpdf417/detector.d.ts +48 -0
- package/src/ts/compactpdf417/encoder.d.ts +49 -0
- package/src/ts/compactpdf417/index.d.ts +8 -0
- package/src/ts/compactpdf417/tables.d.ts +84 -0
- package/src/ts/core/bit-buffer.d.ts +78 -0
- package/src/ts/core/bit-matrix.d.ts +129 -0
- package/src/ts/core/errors.d.ts +57 -0
- package/src/ts/core/galois-field.d.ts +141 -0
- package/src/ts/core/index.d.ts +40 -0
- package/src/ts/core/reed-solomon.d.ts +65 -0
- package/src/ts/databar/codec.d.ts +78 -0
- package/src/ts/databar/decoder.d.ts +55 -0
- package/src/ts/databar/encoder.d.ts +34 -0
- package/src/ts/databar/gs1.d.ts +48 -0
- package/src/ts/databar/index.d.ts +37 -0
- package/src/ts/databar/patterns.d.ts +46 -0
- package/src/ts/databar/tables.d.ts +119 -0
- package/src/ts/datamatrix/decoder.d.ts +57 -0
- package/src/ts/datamatrix/detector.d.ts +59 -0
- package/src/ts/datamatrix/encoder.d.ts +36 -0
- package/src/ts/datamatrix/index.d.ts +35 -0
- package/src/ts/datamatrix/tables.d.ts +88 -0
- package/src/ts/frameqr/decoder.d.ts +64 -0
- package/src/ts/frameqr/detector.d.ts +96 -0
- package/src/ts/frameqr/encoder.d.ts +73 -0
- package/src/ts/frameqr/index.d.ts +34 -0
- package/src/ts/frameqr/tables.d.ts +123 -0
- package/src/ts/image/binarizer.d.ts +85 -0
- package/src/ts/image/grid-sampler.d.ts +82 -0
- package/src/{image/index.js → ts/image/index.d.ts} +0 -2
- package/src/ts/image/luminance.d.ts +112 -0
- package/src/ts/image/perspective.d.ts +111 -0
- package/src/ts/index.d.ts +363 -0
- package/src/ts/micropdf417/compaction.d.ts +38 -0
- package/src/ts/micropdf417/decoder.d.ts +57 -0
- package/src/ts/micropdf417/detector.d.ts +95 -0
- package/src/ts/micropdf417/encoder.d.ts +34 -0
- package/src/ts/micropdf417/error-correction.d.ts +38 -0
- package/src/ts/micropdf417/index.d.ts +36 -0
- package/src/ts/micropdf417/tables.d.ts +73 -0
- package/src/ts/microqr/decoder.d.ts +49 -0
- package/src/ts/microqr/detector.d.ts +96 -0
- package/src/ts/microqr/encoder.d.ts +33 -0
- package/src/{microqr/index.js → ts/microqr/index.d.ts} +0 -2
- package/src/ts/microqr/tables.d.ts +107 -0
- package/src/ts/oned/addons.d.ts +181 -0
- package/src/ts/oned/index.d.ts +55 -0
- package/src/ts/oned/patterns.d.ts +259 -0
- package/src/ts/oned/reader.d.ts +129 -0
- package/src/ts/oned/writers.d.ts +218 -0
- package/src/ts/pdf417/compaction.d.ts +59 -0
- package/src/ts/pdf417/decoder.d.ts +48 -0
- package/src/ts/pdf417/detector.d.ts +73 -0
- package/src/ts/pdf417/encoder.d.ts +32 -0
- package/src/ts/pdf417/error-correction.d.ts +34 -0
- package/src/{pdf417/index.js → ts/pdf417/index.d.ts} +0 -1
- package/src/ts/pdf417/tables.d.ts +53 -0
- package/src/ts/qr/decoder.d.ts +79 -0
- package/src/ts/qr/detector.d.ts +93 -0
- package/src/ts/qr/encoder.d.ts +166 -0
- package/src/{qr/index.js → ts/qr/index.d.ts} +0 -2
- package/src/ts/qr/tables.d.ts +291 -0
- package/src/ts/render/image-data.d.ts +58 -0
- package/src/ts/render/index.d.ts +110 -0
- package/src/ts/render/options.d.ts +98 -0
- package/src/ts/render/png.d.ts +58 -0
- package/src/ts/render/svg.d.ts +46 -0
- package/src/ts/render/webgl.d.ts +45 -0
- package/src/ts/render/webgpu.d.ts +51 -0
- package/src/ts/rmqr/decoder.d.ts +42 -0
- package/src/ts/rmqr/detector.d.ts +81 -0
- package/src/ts/rmqr/encoder.d.ts +45 -0
- package/src/ts/rmqr/index.d.ts +34 -0
- package/src/ts/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;
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
*
|
|
29
29
|
* Original work. No code from any other barcode implementation.
|
|
30
30
|
*/
|
|
31
|
-
|
|
32
31
|
/**
|
|
33
32
|
* QR Code, re-exported.
|
|
34
33
|
*
|
|
@@ -38,7 +37,6 @@
|
|
|
38
37
|
*
|
|
39
38
|
* @module qr
|
|
40
39
|
*/
|
|
41
|
-
|
|
42
40
|
export { encodeQR } from './encoder.js';
|
|
43
41
|
export { decodeQR } from './decoder.js';
|
|
44
42
|
export { detectQR, detectAndDecodeQR } from './detector.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;
|