qr-decoder-js 1.0.7 → 1.0.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.
Files changed (54) hide show
  1. package/LICENSE.jsQR +201 -0
  2. package/LICENSE.qcore +21 -0
  3. package/README.md +19 -127
  4. package/README_ZH.md +19 -122
  5. package/dist/cjs/core/decoder.js +246 -0
  6. package/dist/cjs/core/encoding.js +217 -0
  7. package/dist/cjs/core/preprocess.js +687 -0
  8. package/dist/cjs/index.js +12 -0
  9. package/dist/cjs/native/binarize.js +76 -0
  10. package/dist/cjs/native/bitstream.js +138 -0
  11. package/dist/cjs/native/format.js +33 -0
  12. package/dist/cjs/native/gf256.js +50 -0
  13. package/dist/cjs/native/locator.js +159 -0
  14. package/dist/cjs/native/matrix-decoder.js +166 -0
  15. package/dist/cjs/native/matrix.js +31 -0
  16. package/dist/cjs/native/reed-solomon.js +106 -0
  17. package/dist/cjs/native/sampling.js +71 -0
  18. package/dist/cjs/native/scanner.js +60 -0
  19. package/dist/cjs/native/versions.js +45 -0
  20. package/dist/cjs/package.json +1 -0
  21. package/dist/esm/core/decoder.d.ts +59 -0
  22. package/dist/esm/core/decoder.js +242 -0
  23. package/dist/esm/core/encoding.d.ts +33 -0
  24. package/dist/esm/core/encoding.js +211 -0
  25. package/dist/esm/core/preprocess.d.ts +191 -0
  26. package/dist/esm/core/preprocess.js +670 -0
  27. package/dist/esm/index.d.ts +7 -0
  28. package/dist/esm/index.js +7 -0
  29. package/dist/esm/native/binarize.d.ts +6 -0
  30. package/dist/esm/native/binarize.js +73 -0
  31. package/dist/esm/native/bitstream.d.ts +14 -0
  32. package/dist/esm/native/bitstream.js +135 -0
  33. package/dist/esm/native/format.d.ts +9 -0
  34. package/dist/esm/native/format.js +30 -0
  35. package/dist/esm/native/gf256.d.ts +5 -0
  36. package/dist/esm/native/gf256.js +44 -0
  37. package/dist/esm/native/locator.d.ts +14 -0
  38. package/dist/esm/native/locator.js +156 -0
  39. package/dist/esm/native/matrix-decoder.d.ts +5 -0
  40. package/dist/esm/native/matrix-decoder.js +162 -0
  41. package/dist/esm/native/matrix.d.ts +12 -0
  42. package/dist/esm/native/matrix.js +27 -0
  43. package/dist/esm/native/reed-solomon.d.ts +2 -0
  44. package/dist/esm/native/reed-solomon.js +103 -0
  45. package/dist/esm/native/sampling.d.ts +7 -0
  46. package/dist/esm/native/sampling.js +68 -0
  47. package/dist/esm/native/scanner.d.ts +2 -0
  48. package/dist/esm/native/scanner.js +57 -0
  49. package/dist/esm/native/versions.d.ts +9 -0
  50. package/dist/esm/native/versions.js +42 -0
  51. package/dist/{index.d.ts → esm/types.d.ts} +15 -0
  52. package/package.json +17 -19
  53. package/dist/qr-decoder.js +0 -2670
  54. package/dist/qr-decoder.umd.cjs +0 -1
@@ -0,0 +1,27 @@
1
+ /** Boolean image or QR module grid in row-major order. */
2
+ export class BitMatrix {
3
+ constructor(width, height) {
4
+ this.width = width;
5
+ this.height = height;
6
+ this.cells = new Uint8Array(width * height);
7
+ }
8
+ static createEmpty(width, height) {
9
+ return new BitMatrix(width, height);
10
+ }
11
+ row(y) {
12
+ const start = y * this.width;
13
+ return this.cells.subarray(start, start + this.width);
14
+ }
15
+ get(x, y) {
16
+ return x >= 0 && x < this.width && y >= 0 && y < this.height && this.cells[y * this.width + x] !== 0;
17
+ }
18
+ set(x, y, value) {
19
+ if (x >= 0 && x < this.width && y >= 0 && y < this.height)
20
+ this.cells[y * this.width + x] = value ? 1 : 0;
21
+ }
22
+ setRegion(left, top, width, height, value) {
23
+ for (let y = top; y < top + height; y++)
24
+ for (let x = left; x < left + width; x++)
25
+ this.set(x, y, value);
26
+ }
27
+ }
@@ -0,0 +1,2 @@
1
+ /** Correct QR codewords using their Reed–Solomon parity, or return null. */
2
+ export declare function correctCodewords(input: Uint8Array, parityCount: number, erasures?: number[]): Uint8Array | null;
@@ -0,0 +1,103 @@
1
+ import { divide, multiply, power, syndromes } from './gf256.js';
2
+ /** Correct QR codewords using their Reed–Solomon parity, or return null. */
3
+ export function correctCodewords(input, parityCount, erasures = []) {
4
+ if (input.length === 0 || input.length > 255 || parityCount <= 0 || parityCount >= input.length) {
5
+ throw new RangeError('Invalid Reed–Solomon block dimensions');
6
+ }
7
+ if (erasures.length > parityCount || new Set(erasures).size !== erasures.length ||
8
+ erasures.some(index => !Number.isInteger(index) || index < 0 || index >= input.length)) {
9
+ throw new RangeError('Invalid Reed–Solomon erasures');
10
+ }
11
+ const syndrome = syndromes(input, parityCount);
12
+ if (syndrome.every(value => value === 0))
13
+ return input.slice();
14
+ // Remove known error locations from the syndrome sequence before finding
15
+ // the remaining unknown locations with Berlekamp–Massey.
16
+ let modified = Array.from(syndrome);
17
+ for (const index of erasures) {
18
+ const root = power(2, input.length - 1 - index);
19
+ modified = modified.slice(1).map((value, i) => value ^ multiply(root, modified[i]));
20
+ }
21
+ // Berlekamp–Massey: coefficients are ordered from constant term upward.
22
+ let locator = new Uint8Array(parityCount + 1);
23
+ let previous = new Uint8Array(parityCount + 1);
24
+ locator[0] = previous[0] = 1;
25
+ let degree = 0;
26
+ let shift = 1;
27
+ let lastDiscrepancy = 1;
28
+ for (let n = 0; n < modified.length; n++) {
29
+ let discrepancy = modified[n];
30
+ for (let i = 1; i <= degree; i++)
31
+ discrepancy ^= multiply(locator[i], modified[n - i]);
32
+ if (discrepancy === 0) {
33
+ shift++;
34
+ continue;
35
+ }
36
+ const saved = locator.slice();
37
+ const factor = divide(discrepancy, lastDiscrepancy);
38
+ for (let i = 0; i + shift <= parityCount; i++) {
39
+ locator[i + shift] ^= multiply(factor, previous[i]);
40
+ }
41
+ if (2 * degree <= n) {
42
+ degree = n + 1 - degree;
43
+ previous = saved;
44
+ lastDiscrepancy = discrepancy;
45
+ shift = 1;
46
+ }
47
+ else {
48
+ shift++;
49
+ }
50
+ }
51
+ if (2 * degree + erasures.length > parityCount)
52
+ return null;
53
+ // Chien search maps roots to codeword indices.
54
+ const locations = [];
55
+ for (let index = 0; index < input.length; index++) {
56
+ const exponent = input.length - 1 - index;
57
+ const root = power(2, -exponent);
58
+ let evaluation = 0;
59
+ for (let i = degree; i >= 0; i--)
60
+ evaluation = multiply(evaluation, root) ^ locator[i];
61
+ if (evaluation === 0)
62
+ locations.push(index);
63
+ }
64
+ if (locations.length !== degree)
65
+ return null;
66
+ if (locations.some(index => erasures.includes(index)))
67
+ return null;
68
+ locations.push(...erasures);
69
+ if (!locations.length)
70
+ return null;
71
+ // Solve the syndrome equations for error magnitudes in the finite field.
72
+ const errorCount = locations.length;
73
+ const equations = Array.from({ length: errorCount }, (_, row) => {
74
+ const equation = new Uint8Array(errorCount + 1);
75
+ for (let column = 0; column < errorCount; column++) {
76
+ equation[column] = power(2, (input.length - 1 - locations[column]) * row);
77
+ }
78
+ equation[errorCount] = syndrome[row];
79
+ return equation;
80
+ });
81
+ for (let column = 0; column < errorCount; column++) {
82
+ let pivot = column;
83
+ while (pivot < errorCount && equations[pivot][column] === 0)
84
+ pivot++;
85
+ if (pivot === errorCount)
86
+ return null;
87
+ [equations[column], equations[pivot]] = [equations[pivot], equations[column]];
88
+ const divisor = equations[column][column];
89
+ for (let i = column; i <= errorCount; i++)
90
+ equations[column][i] = divide(equations[column][i], divisor);
91
+ for (let row = 0; row < errorCount; row++) {
92
+ if (row === column)
93
+ continue;
94
+ const factor = equations[row][column];
95
+ for (let i = column; i <= errorCount; i++)
96
+ equations[row][i] ^= multiply(factor, equations[column][i]);
97
+ }
98
+ }
99
+ const corrected = input.slice();
100
+ for (let i = 0; i < errorCount; i++)
101
+ corrected[locations[i]] ^= equations[i][errorCount];
102
+ return syndromes(corrected, parityCount).every(value => value === 0) ? corrected : null;
103
+ }
@@ -0,0 +1,7 @@
1
+ import { BitMatrix } from './matrix.js';
2
+ import type { Point, QRLocation } from './locator.js';
3
+ export declare function extract(image: BitMatrix, location: QRLocation, soft?: boolean, checkVersion?: boolean): {
4
+ matrix: BitMatrix;
5
+ mappingFunction: (x: number, y: number) => Point;
6
+ confidence: Uint8Array<ArrayBuffer>;
7
+ };
@@ -0,0 +1,68 @@
1
+ import { BitMatrix } from './matrix.js';
2
+ import { isVersionValid } from './matrix-decoder.js';
3
+ // Solve a projective mapping from four module coordinates to four image coordinates.
4
+ function projection(from, to) {
5
+ const rows = [];
6
+ for (let i = 0; i < 4; i++) {
7
+ const { x, y } = from[i];
8
+ const { x: u, y: v } = to[i];
9
+ rows.push([x, y, 1, 0, 0, 0, -u * x, -u * y, u]);
10
+ rows.push([0, 0, 0, x, y, 1, -v * x, -v * y, v]);
11
+ }
12
+ for (let col = 0; col < 8; col++) {
13
+ let pivot = col;
14
+ for (let row = col + 1; row < 8; row++) {
15
+ if (Math.abs(rows[row][col]) > Math.abs(rows[pivot][col]))
16
+ pivot = row;
17
+ }
18
+ if (Math.abs(rows[pivot][col]) < 1e-10)
19
+ throw new Error('Degenerate QR geometry');
20
+ [rows[col], rows[pivot]] = [rows[pivot], rows[col]];
21
+ const divisor = rows[col][col];
22
+ for (let j = col; j <= 8; j++)
23
+ rows[col][j] /= divisor;
24
+ for (let row = 0; row < 8; row++) {
25
+ if (row === col)
26
+ continue;
27
+ const factor = rows[row][col];
28
+ for (let j = col; j <= 8; j++)
29
+ rows[row][j] -= factor * rows[col][j];
30
+ }
31
+ }
32
+ const h = rows.map(row => row[8]);
33
+ return (x, y) => {
34
+ const scale = h[6] * x + h[7] * y + 1;
35
+ return { x: (h[0] * x + h[1] * y + h[2]) / scale, y: (h[3] * x + h[4] * y + h[5]) / scale };
36
+ };
37
+ }
38
+ export function extract(image, location, soft = false, checkVersion = false) {
39
+ const n = location.dimension;
40
+ const mappingFunction = projection([{ x: 3.5, y: 3.5 }, { x: n - 3.5, y: 3.5 }, { x: n - 6.5, y: n - 6.5 }, { x: 3.5, y: n - 3.5 }], [location.topLeft, location.topRight, location.alignmentPattern, location.bottomLeft]);
41
+ // The two version fields swap when mirrored, so one check covers both orientations.
42
+ if (checkVersion && !soft && !isVersionValid(n, (x, y) => {
43
+ const point = mappingFunction(x + 0.5, y + 0.5);
44
+ return image.get(Math.floor(point.x), Math.floor(point.y));
45
+ }))
46
+ return null;
47
+ const matrix = BitMatrix.createEmpty(n, n);
48
+ const confidence = soft ? new Uint8Array(n * n) : undefined;
49
+ for (let y = 0; y < n; y++)
50
+ for (let x = 0; x < n; x++) {
51
+ const point = mappingFunction(x + 0.5, y + 0.5);
52
+ if (point.x < 0 || point.x >= image.width || point.y < 0 || point.y >= image.height) {
53
+ if (confidence)
54
+ confidence[y * n + x] = 0;
55
+ continue;
56
+ }
57
+ const sample = (dx, dy) => image.get(Math.floor(point.x + dx), Math.floor(point.y + dy));
58
+ const center = sample(0, 0);
59
+ if (!confidence) {
60
+ matrix.set(x, y, center);
61
+ continue;
62
+ }
63
+ const votes = Number(center) * 2 + Number(sample(-0.25, 0)) + Number(sample(0.25, 0)) + Number(sample(0, -0.25)) + Number(sample(0, 0.25));
64
+ matrix.set(x, y, votes >= 3);
65
+ confidence[y * n + x] = votes === 0 || votes === 6 ? 210 : 40 + Math.abs(2 * votes - 6) * 20;
66
+ }
67
+ return { matrix, mappingFunction, confidence };
68
+ }
@@ -0,0 +1,2 @@
1
+ import type { Payload } from './bitstream.js';
2
+ export declare function scanQR(data: Uint8ClampedArray, width: number, height: number, tryInvert?: boolean, soft?: boolean): Payload | null;
@@ -0,0 +1,57 @@
1
+ import { binarize } from './binarize.js';
2
+ import { locate } from './locator.js';
3
+ import { extract } from './sampling.js';
4
+ import { decode } from './matrix-decoder.js';
5
+ function scanMatrix(image, soft) {
6
+ const retryLocations = [];
7
+ for (const location of locate(image)) {
8
+ if (soft && retryLocations.length < 6)
9
+ retryLocations.push(location);
10
+ try {
11
+ const sampled = extract(image, location, false, true);
12
+ if (!sampled)
13
+ continue;
14
+ const result = decode(sampled.matrix);
15
+ if (result)
16
+ return result;
17
+ }
18
+ catch {
19
+ // A degenerate candidate does not prevent trying other finder triples.
20
+ }
21
+ }
22
+ if (soft) {
23
+ // Small, blurred symbols can shift a finder center by a fraction of a module.
24
+ // Only accept a soft-corrected payload when two nearby samples agree.
25
+ for (const location of retryLocations) {
26
+ const moduleSize = (Math.hypot(location.topRight.x - location.topLeft.x, location.topRight.y - location.topLeft.y) +
27
+ Math.hypot(location.bottomLeft.x - location.topLeft.x, location.bottomLeft.y - location.topLeft.y)) / (2 * (location.dimension - 7));
28
+ for (const point of ['bottomLeft', 'topRight', 'topLeft', 'alignmentPattern']) {
29
+ for (const axis of ['x', 'y'])
30
+ for (const direction of [-1, 1]) {
31
+ let previous = null;
32
+ for (const offset of [0.08, 0.14]) {
33
+ const adjusted = { ...location, [point]: { ...location[point], [axis]: location[point][axis] + direction * offset * moduleSize } };
34
+ try {
35
+ const sampled = extract(image, adjusted, true);
36
+ const result = decode(sampled.matrix, sampled.confidence);
37
+ if (result && previous && result.version === previous.version && result.bytes.length === previous.bytes.length &&
38
+ result.bytes.every((byte, i) => byte === previous.bytes[i]) && JSON.stringify(result.chunks) === JSON.stringify(previous.chunks))
39
+ return result;
40
+ previous = result;
41
+ }
42
+ catch {
43
+ previous = null;
44
+ }
45
+ if (!previous)
46
+ break;
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ return null;
53
+ }
54
+ export function scanQR(data, width, height, tryInvert = true, soft = false) {
55
+ const { binarized, inverted } = binarize(data, width, height, tryInvert);
56
+ return scanMatrix(binarized, soft) || (inverted ? scanMatrix(inverted, soft) : null);
57
+ }
@@ -0,0 +1,9 @@
1
+ export interface BlockSpec {
2
+ parity: number;
3
+ groups: Array<[number, number]>;
4
+ }
5
+ export interface VersionSpec {
6
+ alignment: number[];
7
+ blocks: Record<string, BlockSpec>;
8
+ }
9
+ export declare const VERSIONS: VersionSpec[];
@@ -0,0 +1,42 @@
1
+ export const VERSIONS = [
2
+ { alignment: [], blocks: { L: { parity: 7, groups: [[1, 19]] }, M: { parity: 10, groups: [[1, 16]] }, Q: { parity: 13, groups: [[1, 13]] }, H: { parity: 17, groups: [[1, 9]] } } },
3
+ { alignment: [6, 18], blocks: { L: { parity: 10, groups: [[1, 34]] }, M: { parity: 16, groups: [[1, 28]] }, Q: { parity: 22, groups: [[1, 22]] }, H: { parity: 28, groups: [[1, 16]] } } },
4
+ { alignment: [6, 22], blocks: { L: { parity: 15, groups: [[1, 55]] }, M: { parity: 26, groups: [[1, 44]] }, Q: { parity: 18, groups: [[2, 17]] }, H: { parity: 22, groups: [[2, 13]] } } },
5
+ { alignment: [6, 26], blocks: { L: { parity: 20, groups: [[1, 80]] }, M: { parity: 18, groups: [[2, 32]] }, Q: { parity: 26, groups: [[2, 24]] }, H: { parity: 16, groups: [[4, 9]] } } },
6
+ { alignment: [6, 30], blocks: { L: { parity: 26, groups: [[1, 108]] }, M: { parity: 24, groups: [[2, 43]] }, Q: { parity: 18, groups: [[2, 15], [2, 16]] }, H: { parity: 22, groups: [[2, 11], [2, 12]] } } },
7
+ { alignment: [6, 34], blocks: { L: { parity: 18, groups: [[2, 68]] }, M: { parity: 16, groups: [[4, 27]] }, Q: { parity: 24, groups: [[4, 19]] }, H: { parity: 28, groups: [[4, 15]] } } },
8
+ { alignment: [6, 22, 38], blocks: { L: { parity: 20, groups: [[2, 78]] }, M: { parity: 18, groups: [[4, 31]] }, Q: { parity: 18, groups: [[2, 14], [4, 15]] }, H: { parity: 26, groups: [[4, 13], [1, 14]] } } },
9
+ { alignment: [6, 24, 42], blocks: { L: { parity: 24, groups: [[2, 97]] }, M: { parity: 22, groups: [[2, 38], [2, 39]] }, Q: { parity: 22, groups: [[4, 18], [2, 19]] }, H: { parity: 26, groups: [[4, 14], [2, 15]] } } },
10
+ { alignment: [6, 26, 46], blocks: { L: { parity: 30, groups: [[2, 116]] }, M: { parity: 22, groups: [[3, 36], [2, 37]] }, Q: { parity: 20, groups: [[4, 16], [4, 17]] }, H: { parity: 24, groups: [[4, 12], [4, 13]] } } },
11
+ { alignment: [6, 28, 50], blocks: { L: { parity: 18, groups: [[2, 68], [2, 69]] }, M: { parity: 26, groups: [[4, 43], [1, 44]] }, Q: { parity: 24, groups: [[6, 19], [2, 20]] }, H: { parity: 28, groups: [[6, 15], [2, 16]] } } },
12
+ { alignment: [6, 30, 54], blocks: { L: { parity: 20, groups: [[4, 81]] }, M: { parity: 30, groups: [[1, 50], [4, 51]] }, Q: { parity: 28, groups: [[4, 22], [4, 23]] }, H: { parity: 24, groups: [[3, 12], [8, 13]] } } },
13
+ { alignment: [6, 32, 58], blocks: { L: { parity: 24, groups: [[2, 92], [2, 93]] }, M: { parity: 22, groups: [[6, 36], [2, 37]] }, Q: { parity: 26, groups: [[4, 20], [6, 21]] }, H: { parity: 28, groups: [[7, 14], [4, 15]] } } },
14
+ { alignment: [6, 34, 62], blocks: { L: { parity: 26, groups: [[4, 107]] }, M: { parity: 22, groups: [[8, 37], [1, 38]] }, Q: { parity: 24, groups: [[8, 20], [4, 21]] }, H: { parity: 22, groups: [[12, 11], [4, 12]] } } },
15
+ { alignment: [6, 26, 46, 66], blocks: { L: { parity: 30, groups: [[3, 115], [1, 116]] }, M: { parity: 24, groups: [[4, 40], [5, 41]] }, Q: { parity: 20, groups: [[11, 16], [5, 17]] }, H: { parity: 24, groups: [[11, 12], [5, 13]] } } },
16
+ { alignment: [6, 26, 48, 70], blocks: { L: { parity: 22, groups: [[5, 87], [1, 88]] }, M: { parity: 24, groups: [[5, 41], [5, 42]] }, Q: { parity: 30, groups: [[5, 24], [7, 25]] }, H: { parity: 24, groups: [[11, 12], [7, 13]] } } },
17
+ { alignment: [6, 26, 50, 74], blocks: { L: { parity: 24, groups: [[5, 98], [1, 99]] }, M: { parity: 28, groups: [[7, 45], [3, 46]] }, Q: { parity: 24, groups: [[15, 19], [2, 20]] }, H: { parity: 30, groups: [[3, 15], [13, 16]] } } },
18
+ { alignment: [6, 30, 54, 78], blocks: { L: { parity: 28, groups: [[1, 107], [5, 108]] }, M: { parity: 28, groups: [[10, 46], [1, 47]] }, Q: { parity: 28, groups: [[1, 22], [15, 23]] }, H: { parity: 28, groups: [[2, 14], [17, 15]] } } },
19
+ { alignment: [6, 30, 56, 82], blocks: { L: { parity: 30, groups: [[5, 120], [1, 121]] }, M: { parity: 26, groups: [[9, 43], [4, 44]] }, Q: { parity: 28, groups: [[17, 22], [1, 23]] }, H: { parity: 28, groups: [[2, 14], [19, 15]] } } },
20
+ { alignment: [6, 30, 58, 86], blocks: { L: { parity: 28, groups: [[3, 113], [4, 114]] }, M: { parity: 26, groups: [[3, 44], [11, 45]] }, Q: { parity: 26, groups: [[17, 21], [4, 22]] }, H: { parity: 26, groups: [[9, 13], [16, 14]] } } },
21
+ { alignment: [6, 34, 62, 90], blocks: { L: { parity: 28, groups: [[3, 107], [5, 108]] }, M: { parity: 26, groups: [[3, 41], [13, 42]] }, Q: { parity: 30, groups: [[15, 24], [5, 25]] }, H: { parity: 28, groups: [[15, 15], [10, 16]] } } },
22
+ { alignment: [6, 28, 50, 72, 94], blocks: { L: { parity: 28, groups: [[4, 116], [4, 117]] }, M: { parity: 26, groups: [[17, 42]] }, Q: { parity: 28, groups: [[17, 22], [6, 23]] }, H: { parity: 30, groups: [[19, 16], [6, 17]] } } },
23
+ { alignment: [6, 26, 50, 74, 98], blocks: { L: { parity: 28, groups: [[2, 111], [7, 112]] }, M: { parity: 28, groups: [[17, 46]] }, Q: { parity: 30, groups: [[7, 24], [16, 25]] }, H: { parity: 24, groups: [[34, 13]] } } },
24
+ { alignment: [6, 30, 54, 78, 102], blocks: { L: { parity: 30, groups: [[4, 121], [5, 122]] }, M: { parity: 28, groups: [[4, 47], [14, 48]] }, Q: { parity: 30, groups: [[11, 24], [14, 25]] }, H: { parity: 30, groups: [[16, 15], [14, 16]] } } },
25
+ { alignment: [6, 28, 54, 80, 106], blocks: { L: { parity: 30, groups: [[6, 117], [4, 118]] }, M: { parity: 28, groups: [[6, 45], [14, 46]] }, Q: { parity: 30, groups: [[11, 24], [16, 25]] }, H: { parity: 30, groups: [[30, 16], [2, 17]] } } },
26
+ { alignment: [6, 32, 58, 84, 110], blocks: { L: { parity: 26, groups: [[8, 106], [4, 107]] }, M: { parity: 28, groups: [[8, 47], [13, 48]] }, Q: { parity: 30, groups: [[7, 24], [22, 25]] }, H: { parity: 30, groups: [[22, 15], [13, 16]] } } },
27
+ { alignment: [6, 30, 58, 86, 114], blocks: { L: { parity: 28, groups: [[10, 114], [2, 115]] }, M: { parity: 28, groups: [[19, 46], [4, 47]] }, Q: { parity: 28, groups: [[28, 22], [6, 23]] }, H: { parity: 30, groups: [[33, 16], [4, 17]] } } },
28
+ { alignment: [6, 34, 62, 90, 118], blocks: { L: { parity: 30, groups: [[8, 122], [4, 123]] }, M: { parity: 28, groups: [[22, 45], [3, 46]] }, Q: { parity: 30, groups: [[8, 23], [26, 24]] }, H: { parity: 30, groups: [[12, 15], [28, 16]] } } },
29
+ { alignment: [6, 26, 50, 74, 98, 122], blocks: { L: { parity: 30, groups: [[3, 117], [10, 118]] }, M: { parity: 28, groups: [[3, 45], [23, 46]] }, Q: { parity: 30, groups: [[4, 24], [31, 25]] }, H: { parity: 30, groups: [[11, 15], [31, 16]] } } },
30
+ { alignment: [6, 30, 54, 78, 102, 126], blocks: { L: { parity: 30, groups: [[7, 116], [7, 117]] }, M: { parity: 28, groups: [[21, 45], [7, 46]] }, Q: { parity: 30, groups: [[1, 23], [37, 24]] }, H: { parity: 30, groups: [[19, 15], [26, 16]] } } },
31
+ { alignment: [6, 26, 52, 78, 104, 130], blocks: { L: { parity: 30, groups: [[5, 115], [10, 116]] }, M: { parity: 28, groups: [[19, 47], [10, 48]] }, Q: { parity: 30, groups: [[15, 24], [25, 25]] }, H: { parity: 30, groups: [[23, 15], [25, 16]] } } },
32
+ { alignment: [6, 30, 56, 82, 108, 134], blocks: { L: { parity: 30, groups: [[13, 115], [3, 116]] }, M: { parity: 28, groups: [[2, 46], [29, 47]] }, Q: { parity: 30, groups: [[42, 24], [1, 25]] }, H: { parity: 30, groups: [[23, 15], [28, 16]] } } },
33
+ { alignment: [6, 34, 60, 86, 112, 138], blocks: { L: { parity: 30, groups: [[17, 115]] }, M: { parity: 28, groups: [[10, 46], [23, 47]] }, Q: { parity: 30, groups: [[10, 24], [35, 25]] }, H: { parity: 30, groups: [[19, 15], [35, 16]] } } },
34
+ { alignment: [6, 30, 58, 86, 114, 142], blocks: { L: { parity: 30, groups: [[17, 115], [1, 116]] }, M: { parity: 28, groups: [[14, 46], [21, 47]] }, Q: { parity: 30, groups: [[29, 24], [19, 25]] }, H: { parity: 30, groups: [[11, 15], [46, 16]] } } },
35
+ { alignment: [6, 34, 62, 90, 118, 146], blocks: { L: { parity: 30, groups: [[13, 115], [6, 116]] }, M: { parity: 28, groups: [[14, 46], [23, 47]] }, Q: { parity: 30, groups: [[44, 24], [7, 25]] }, H: { parity: 30, groups: [[59, 16], [1, 17]] } } },
36
+ { alignment: [6, 30, 54, 78, 102, 126, 150], blocks: { L: { parity: 30, groups: [[12, 121], [7, 122]] }, M: { parity: 28, groups: [[12, 47], [26, 48]] }, Q: { parity: 30, groups: [[39, 24], [14, 25]] }, H: { parity: 30, groups: [[22, 15], [41, 16]] } } },
37
+ { alignment: [6, 24, 50, 76, 102, 128, 154], blocks: { L: { parity: 30, groups: [[6, 121], [14, 122]] }, M: { parity: 28, groups: [[6, 47], [34, 48]] }, Q: { parity: 30, groups: [[46, 24], [10, 25]] }, H: { parity: 30, groups: [[2, 15], [64, 16]] } } },
38
+ { alignment: [6, 28, 54, 80, 106, 132, 158], blocks: { L: { parity: 30, groups: [[17, 122], [4, 123]] }, M: { parity: 28, groups: [[29, 46], [14, 47]] }, Q: { parity: 30, groups: [[49, 24], [10, 25]] }, H: { parity: 30, groups: [[24, 15], [46, 16]] } } },
39
+ { alignment: [6, 32, 58, 84, 110, 136, 162], blocks: { L: { parity: 30, groups: [[4, 122], [18, 123]] }, M: { parity: 28, groups: [[13, 46], [32, 47]] }, Q: { parity: 30, groups: [[48, 24], [14, 25]] }, H: { parity: 30, groups: [[42, 15], [32, 16]] } } },
40
+ { alignment: [6, 26, 54, 82, 110, 138, 166], blocks: { L: { parity: 30, groups: [[20, 117], [4, 118]] }, M: { parity: 28, groups: [[40, 47], [7, 48]] }, Q: { parity: 30, groups: [[43, 24], [22, 25]] }, H: { parity: 30, groups: [[10, 15], [67, 16]] } } },
41
+ { alignment: [6, 30, 58, 86, 114, 142, 170], blocks: { L: { parity: 30, groups: [[19, 118], [6, 119]] }, M: { parity: 28, groups: [[18, 47], [31, 48]] }, Q: { parity: 30, groups: [[34, 24], [34, 25]] }, H: { parity: 30, groups: [[20, 15], [61, 16]] } } },
42
+ ];
@@ -6,6 +6,10 @@ export interface DecodeResult {
6
6
  encoding?: string;
7
7
  /** Detected encoding identifier. */
8
8
  detectedEncoding?: string | null;
9
+ /** QR payload bytes before text decoding. */
10
+ rawBytes?: Uint8Array;
11
+ /** QR symbol version (1–40). */
12
+ qrVersion?: number;
9
13
  /** Preprocess version that matched, such as original, color rescue, adaptive binary, or inverted. */
10
14
  version?: string;
11
15
  error?: string;
@@ -18,16 +22,27 @@ export interface ReaderOptions {
18
22
  * - aggressive: balanced + quiet-zone, dot-matrix, Otsu, adaptive binary, and inverted variants
19
23
  */
20
24
  mode?: 'fast' | 'balanced' | 'aggressive';
25
+ /** @deprecated Accepted for compatibility; the TypeScript engine decodes QR codes only. */
21
26
  formats?: string[];
27
+ /** @deprecated Accepted for compatibility; finder detection handles rotation automatically. */
22
28
  tryRotate?: boolean;
29
+ /** Whether to scan the inverse image; defaults to true. */
23
30
  tryInvert?: boolean;
31
+ /** @deprecated ZXing-specific option; not used by the TypeScript engine. */
24
32
  tryHarder?: boolean;
33
+ /** @deprecated ZXing-specific option; not used by the TypeScript engine. */
25
34
  tryDownscale?: boolean;
35
+ /** @deprecated ZXing-specific option; not used by the TypeScript engine. */
26
36
  tryDenoise?: boolean;
37
+ /** @deprecated The TypeScript engine currently returns at most one symbol. */
27
38
  maxNumberOfSymbols?: number;
39
+ /** @deprecated ZXing-specific option; not used by the TypeScript engine. */
28
40
  binarizer?: string;
41
+ /** @deprecated ZXing-specific option; not used by the TypeScript engine. */
29
42
  isPure?: boolean;
43
+ /** @deprecated ZXing-specific option; not used by the TypeScript engine. */
30
44
  returnErrors?: boolean;
45
+ /** @deprecated ZXing-specific option; not used by the TypeScript engine. */
31
46
  textMode?: string;
32
47
  characterSet?: string;
33
48
  [key: string]: unknown;
package/package.json CHANGED
@@ -1,22 +1,24 @@
1
1
  {
2
2
  "name": "qr-decoder-js",
3
- "version": "1.0.7",
4
- "description": "Browser QR code decoder with character encoding detection and fallback decoding to reduce garbled Chinese and non-UTF-8 text.",
3
+ "version": "1.0.8",
4
+ "description": "Dependency-free TypeScript QR code decoder for browsers",
5
5
  "type": "module",
6
- "main": "./dist/qr-decoder.umd.cjs",
7
- "module": "./dist/qr-decoder.js",
8
- "types": "./dist/index.d.ts",
6
+ "main": "./dist/cjs/index.js",
7
+ "module": "./dist/esm/index.js",
8
+ "types": "./dist/esm/types.d.ts",
9
9
  "files": [
10
10
  "dist",
11
11
  "README.md",
12
- "README_ZH.md"
12
+ "README_ZH.md",
13
+ "LICENSE.jsQR",
14
+ "LICENSE.qcore"
13
15
  ],
14
16
  "exports": {
15
17
  ".": {
16
- "types": "./dist/index.d.ts",
17
- "import": "./dist/qr-decoder.js",
18
- "require": "./dist/qr-decoder.umd.cjs",
19
- "default": "./dist/qr-decoder.js"
18
+ "types": "./dist/esm/types.d.ts",
19
+ "import": "./dist/esm/index.js",
20
+ "require": "./dist/cjs/index.js",
21
+ "default": "./dist/esm/index.js"
20
22
  },
21
23
  "./package.json": "./package.json"
22
24
  },
@@ -25,8 +27,6 @@
25
27
  "qrcode",
26
28
  "decode",
27
29
  "qr",
28
- "wasm",
29
- "zxing",
30
30
  "encoding",
31
31
  "character-encoding",
32
32
  "text-decoding"
@@ -49,14 +49,12 @@
49
49
  }
50
50
  },
51
51
  "devDependencies": {
52
- "vite": "^8.2.2",
53
- "zxing-wasm": "^3.1.3"
52
+ "typescript": "^5.9.3"
54
53
  },
55
54
  "scripts": {
56
- "dev": "vite",
57
- "build": "vite build",
58
- "build:demo": "vite build --config vite.demo.config.js",
59
- "postbuild": "node -e \"require('fs').copyFileSync('src/types.d.ts', 'dist/index.d.ts')\"",
60
- "preview": "vite preview --outDir dist-demo"
55
+ "build": "node scripts/build.mjs",
56
+ "build:demo": "pnpm run build && node scripts/build-demo.mjs",
57
+ "test": "node scripts/build.mjs && node --experimental-strip-types --test tests/*.test.mjs",
58
+ "typecheck": "tsc --noEmit"
61
59
  }
62
60
  }