@sythos/js_barcode_universal 1.5.8 → 1.5.10

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 (179) hide show
  1. package/LICENSE +5 -4
  2. package/NOTICE.md +2 -2
  3. package/README.md +61 -13
  4. package/bundle/sythos-barcode.esm.js +11658 -11244
  5. package/bundle/sythos-barcode.js +11658 -11244
  6. package/package.json +10 -3
  7. package/src/index.d.ts +1 -1
  8. package/src/index.js +508 -516
  9. package/src/js/aztec/decoder.js +208 -199
  10. package/src/js/aztec/detector.js +153 -126
  11. package/src/js/aztec/encoder.js +172 -153
  12. package/src/js/aztec/high-level.js +106 -101
  13. package/src/js/aztec/index.js +1 -12
  14. package/src/js/aztec/tables.js +106 -120
  15. package/src/js/aztecrune/decoder.js +76 -85
  16. package/src/js/aztecrune/detector.js +107 -93
  17. package/src/js/aztecrune/encoder.js +50 -68
  18. package/src/js/aztecrune/index.js +1 -16
  19. package/src/js/aztecrune/tables.js +59 -54
  20. package/src/js/compactpdf417/decoder.js +69 -74
  21. package/src/js/compactpdf417/detector.js +74 -75
  22. package/src/js/compactpdf417/encoder.js +68 -81
  23. package/src/js/compactpdf417/index.js +1 -13
  24. package/src/js/compactpdf417/tables.js +71 -80
  25. package/src/js/core/bit-buffer.js +106 -122
  26. package/src/js/core/bit-matrix.js +196 -194
  27. package/src/js/core/errors.js +13 -15
  28. package/src/js/core/galois-field.js +119 -133
  29. package/src/js/core/index.js +2 -19
  30. package/src/js/core/reed-solomon.js +195 -204
  31. package/src/js/databar/codec.js +93 -108
  32. package/src/js/databar/decoder.js +149 -140
  33. package/src/js/databar/encoder.js +47 -55
  34. package/src/js/databar/gs1.js +122 -123
  35. package/src/js/databar/index.js +4 -36
  36. package/src/js/databar/patterns.js +81 -85
  37. package/src/js/databar/tables.js +51 -52
  38. package/src/js/datamatrix/decoder.js +216 -182
  39. package/src/js/datamatrix/detector.js +161 -132
  40. package/src/js/datamatrix/encoder.js +192 -133
  41. package/src/js/datamatrix/index.js +1 -9
  42. package/src/js/datamatrix/tables.js +68 -69
  43. package/src/js/frameqr/decoder.js +102 -125
  44. package/src/js/frameqr/detector.js +101 -94
  45. package/src/js/frameqr/encoder.js +67 -80
  46. package/src/js/frameqr/index.js +1 -10
  47. package/src/js/frameqr/tables.js +145 -163
  48. package/src/js/image/binarizer.js +146 -162
  49. package/src/js/image/grid-sampler.js +63 -79
  50. package/src/js/image/index.js +0 -2
  51. package/src/js/image/luminance.js +129 -140
  52. package/src/js/image/perspective.js +112 -149
  53. package/src/js/micropdf417/compaction.js +64 -65
  54. package/src/js/micropdf417/decoder.js +106 -109
  55. package/src/js/micropdf417/detector.js +73 -70
  56. package/src/js/micropdf417/encoder.js +129 -154
  57. package/src/js/micropdf417/error-correction.js +6 -11
  58. package/src/js/micropdf417/index.js +2 -16
  59. package/src/js/micropdf417/tables.js +112 -99
  60. package/src/js/microqr/decoder.js +177 -182
  61. package/src/js/microqr/detector.js +240 -256
  62. package/src/js/microqr/encoder.js +239 -194
  63. package/src/js/microqr/index.js +0 -2
  64. package/src/js/microqr/tables.js +208 -200
  65. package/src/js/oned/addons.js +167 -191
  66. package/src/js/oned/index.js +27 -58
  67. package/src/js/oned/patterns.js +194 -213
  68. package/src/js/oned/reader.js +1003 -984
  69. package/src/js/oned/writers.js +411 -466
  70. package/src/js/pdf417/compaction.js +315 -222
  71. package/src/js/pdf417/decoder.js +71 -36
  72. package/src/js/pdf417/detector.js +377 -361
  73. package/src/js/pdf417/encoder.js +57 -46
  74. package/src/js/pdf417/error-correction.js +5 -8
  75. package/src/js/pdf417/tables.js +248 -250
  76. package/src/js/qr/decoder.js +311 -347
  77. package/src/js/qr/detector.js +378 -395
  78. package/src/js/qr/encoder.js +514 -599
  79. package/src/js/qr/index.js +0 -2
  80. package/src/js/qr/tables.js +375 -422
  81. package/src/js/render/image-data.js +57 -62
  82. package/src/js/render/index.js +21 -23
  83. package/src/js/render/options.js +82 -90
  84. package/src/js/render/png.js +144 -169
  85. package/src/js/render/svg.js +41 -44
  86. package/src/js/render/webgl.js +103 -109
  87. package/src/js/render/webgpu.js +205 -217
  88. package/src/js/rmqr/decoder.js +161 -53
  89. package/src/js/rmqr/detector.js +73 -41
  90. package/src/js/rmqr/encoder.js +253 -104
  91. package/src/js/rmqr/index.js +1 -5
  92. package/src/js/rmqr/tables.js +108 -85
  93. package/src/ts/aztec/decoder.ts +317 -0
  94. package/src/ts/aztec/detector.ts +224 -0
  95. package/src/ts/aztec/encoder.ts +257 -0
  96. package/src/ts/aztec/high-level.ts +211 -0
  97. package/src/ts/aztec/index.ts +45 -0
  98. package/src/ts/aztec/tables.ts +210 -0
  99. package/src/ts/aztecrune/decoder.ts +155 -0
  100. package/src/ts/aztecrune/detector.ts +166 -0
  101. package/src/ts/aztecrune/encoder.ts +121 -0
  102. package/src/ts/aztecrune/index.ts +49 -0
  103. package/src/ts/aztecrune/tables.ts +137 -0
  104. package/src/ts/compactpdf417/decoder.ts +128 -0
  105. package/src/ts/compactpdf417/detector.ts +139 -0
  106. package/src/ts/compactpdf417/encoder.ts +140 -0
  107. package/src/ts/compactpdf417/index.ts +17 -0
  108. package/src/ts/compactpdf417/tables.ts +173 -0
  109. package/src/ts/core/bit-buffer.ts +174 -0
  110. package/src/ts/core/bit-matrix.ts +241 -0
  111. package/src/ts/core/errors.ts +61 -0
  112. package/src/ts/core/galois-field.ts +207 -0
  113. package/src/ts/core/index.ts +56 -0
  114. package/src/ts/core/reed-solomon.ts +327 -0
  115. package/src/ts/databar/codec.ts +181 -0
  116. package/src/ts/databar/decoder.ts +215 -0
  117. package/src/ts/databar/encoder.ts +96 -0
  118. package/src/ts/databar/gs1.ts +177 -0
  119. package/src/ts/databar/index.ts +68 -0
  120. package/src/ts/databar/patterns.ts +143 -0
  121. package/src/ts/databar/tables.ts +124 -0
  122. package/src/ts/datamatrix/decoder.ts +262 -0
  123. package/src/ts/datamatrix/detector.ts +225 -0
  124. package/src/ts/datamatrix/encoder.ts +191 -0
  125. package/src/ts/datamatrix/index.ts +42 -0
  126. package/src/ts/datamatrix/tables.ts +123 -0
  127. package/src/ts/frameqr/decoder.ts +239 -0
  128. package/src/ts/frameqr/detector.ts +192 -0
  129. package/src/ts/frameqr/encoder.ts +156 -0
  130. package/src/ts/frameqr/index.ts +42 -0
  131. package/src/ts/frameqr/tables.ts +270 -0
  132. package/src/ts/image/binarizer.ts +270 -0
  133. package/src/ts/image/grid-sampler.ts +164 -0
  134. package/src/ts/image/index.ts +40 -0
  135. package/src/ts/image/luminance.ts +196 -0
  136. package/src/ts/image/perspective.ts +195 -0
  137. package/src/ts/index.d.ts +1 -1
  138. package/src/ts/index.ts +790 -0
  139. package/src/ts/micropdf417/compaction.ts +116 -0
  140. package/src/ts/micropdf417/decoder.ts +183 -0
  141. package/src/ts/micropdf417/detector.ts +149 -0
  142. package/src/ts/micropdf417/encoder.ts +209 -0
  143. package/src/ts/micropdf417/error-correction.ts +55 -0
  144. package/src/ts/micropdf417/index.ts +49 -0
  145. package/src/ts/micropdf417/tables.ts +184 -0
  146. package/src/ts/microqr/decoder.ts +245 -0
  147. package/src/ts/microqr/detector.ts +355 -0
  148. package/src/ts/microqr/encoder.ts +269 -0
  149. package/src/ts/microqr/index.ts +36 -0
  150. package/src/ts/microqr/tables.ts +316 -0
  151. package/src/ts/oned/addons.ts +420 -0
  152. package/src/ts/oned/index.ts +106 -0
  153. package/src/ts/oned/patterns.ts +384 -0
  154. package/src/ts/oned/reader.ts +1364 -0
  155. package/src/ts/oned/writers.ts +746 -0
  156. package/src/ts/pdf417/compaction.ts +298 -0
  157. package/src/ts/pdf417/decoder.ts +75 -0
  158. package/src/ts/pdf417/detector.ts +468 -0
  159. package/src/ts/pdf417/encoder.ts +91 -0
  160. package/src/ts/pdf417/error-correction.ts +47 -0
  161. package/src/ts/pdf417/index.ts +6 -0
  162. package/src/ts/pdf417/tables.ts +317 -0
  163. package/src/ts/qr/decoder.ts +575 -0
  164. package/src/ts/qr/detector.ts +630 -0
  165. package/src/ts/qr/encoder.ts +958 -0
  166. package/src/ts/qr/index.ts +44 -0
  167. package/src/ts/qr/tables.ts +737 -0
  168. package/src/ts/render/image-data.ts +125 -0
  169. package/src/ts/render/index.ts +130 -0
  170. package/src/ts/render/options.ts +160 -0
  171. package/src/ts/render/png.ts +295 -0
  172. package/src/ts/render/svg.ts +120 -0
  173. package/src/ts/render/webgl.ts +206 -0
  174. package/src/ts/render/webgpu.ts +369 -0
  175. package/src/ts/rmqr/decoder.ts +101 -0
  176. package/src/ts/rmqr/detector.ts +90 -0
  177. package/src/ts/rmqr/encoder.ts +172 -0
  178. package/src/ts/rmqr/index.ts +37 -0
  179. package/src/ts/rmqr/tables.ts +154 -0
@@ -27,7 +27,6 @@
27
27
  *
28
28
  * Original work. No code from any other barcode implementation.
29
29
  */
30
-
31
30
  /**
32
31
  * Aztec image detection.
33
32
  *
@@ -47,109 +46,118 @@
47
46
  *
48
47
  * @module aztec/detector
49
48
  */
50
-
51
49
  import { NotFoundError } from '../core/errors.js';
52
50
  import { sampleQuad } from '../image/grid-sampler.js';
53
51
  import { decodeAztec } from './decoder.js';
54
-
55
52
  /** @typedef {{x:number, y:number}} Point */
56
53
  /** @typedef {{corners: Point[], dimension: number, compact: boolean, moduleSize: number, matrix: import('../core/bit-matrix.js').BitMatrix}} Detection */
57
-
58
54
  // Compact: 11 + 4 layers. Full symbols add reference-grid rows/columns every
59
55
  // 15 modules measured from their central 14-module base, not every 15 layers.
60
56
  const DIMENSIONS = [
61
- ...[1, 2, 3, 4].map((layers) => ({ compact: true, dimension: 11 + 4 * layers })),
62
- ...Array.from({ length: 32 }, (_, index) => {
63
- const layers = index + 1;
64
- return { compact: false, dimension: 15 + 4 * layers + 2 * Math.floor((2 * layers + 6) / 15) };
65
- }),
57
+ ...[1, 2, 3, 4].map((layers) => ({ compact: true, dimension: 11 + 4 * layers })),
58
+ ...Array.from({ length: 32 }, (_, index) => {
59
+ const layers = index + 1;
60
+ return { compact: false, dimension: 15 + 4 * layers + 2 * Math.floor((2 * layers + 6) / 15) };
61
+ }),
66
62
  ];
67
-
68
63
  function pixel(image, x, y) {
69
- const ix = Math.round(x);
70
- const iy = Math.round(y);
71
- return ix >= 0 && iy >= 0 && ix < image.width && iy < image.height && image.get(ix, iy);
64
+ const ix = Math.round(x);
65
+ const iy = Math.round(y);
66
+ return ix >= 0 && iy >= 0 && ix < image.width && iy < image.height && image.get(ix, iy);
72
67
  }
73
-
74
68
  /** Connected components of either polarity, retaining only plausible modules. */
75
69
  function components(image, value) {
76
- const seen = new Uint8Array(image.width * image.height);
77
- const out = [];
78
- const maximumArea = Math.max(4, Math.floor(image.width * image.height * 0.08));
79
- for (let y = 0; y < image.height; y++) for (let x = 0; x < image.width; x++) {
80
- const start = y * image.width + x;
81
- if (seen[start] || image.get(x, y) !== value) continue;
82
- const xs = [x];
83
- const ys = [y];
84
- seen[start] = 1;
85
- let head = 0;
86
- let minX = x; let maxX = x; let minY = y; let maxY = y;
87
- while (head < xs.length) {
88
- const px = xs[head]; const py = ys[head++];
89
- if (px < minX) minX = px; if (px > maxX) maxX = px;
90
- if (py < minY) minY = py; if (py > maxY) maxY = py;
91
- for (const [nx, ny] of [[px - 1, py], [px + 1, py], [px, py - 1], [px, py + 1]]) {
92
- if (nx < 0 || ny < 0 || nx >= image.width || ny >= image.height) continue;
93
- const at = ny * image.width + nx;
94
- if (!seen[at] && image.get(nx, ny) === value) {
95
- seen[at] = 1; xs.push(nx); ys.push(ny);
70
+ const seen = new Uint8Array(image.width * image.height);
71
+ const out = [];
72
+ const maximumArea = Math.max(4, Math.floor(image.width * image.height * 0.08));
73
+ for (let y = 0; y < image.height; y++)
74
+ for (let x = 0; x < image.width; x++) {
75
+ const start = y * image.width + x;
76
+ if (seen[start] || image.get(x, y) !== value)
77
+ continue;
78
+ const xs = [x];
79
+ const ys = [y];
80
+ seen[start] = 1;
81
+ let head = 0;
82
+ let minX = x;
83
+ let maxX = x;
84
+ let minY = y;
85
+ let maxY = y;
86
+ while (head < xs.length) {
87
+ const px = xs[head];
88
+ const py = ys[head++];
89
+ if (px < minX)
90
+ minX = px;
91
+ if (px > maxX)
92
+ maxX = px;
93
+ if (py < minY)
94
+ minY = py;
95
+ if (py > maxY)
96
+ maxY = py;
97
+ for (const [nx, ny] of [[px - 1, py], [px + 1, py], [px, py - 1], [px, py + 1]]) {
98
+ if (nx < 0 || ny < 0 || nx >= image.width || ny >= image.height)
99
+ continue;
100
+ const at = ny * image.width + nx;
101
+ if (!seen[at] && image.get(nx, ny) === value) {
102
+ seen[at] = 1;
103
+ xs.push(nx);
104
+ ys.push(ny);
105
+ }
106
+ }
107
+ }
108
+ const width = maxX - minX + 1;
109
+ const height = maxY - minY + 1;
110
+ const area = width * height;
111
+ // The central module is solid and approximately square. This filter is
112
+ // intentionally permissive because a rotated raster module is diamond-ish.
113
+ if (xs.length <= maximumArea && Math.abs(width - height) <= Math.max(1, Math.ceil(Math.max(width, height) * 0.35)) &&
114
+ xs.length >= area * 0.45) {
115
+ out.push({ x: (minX + maxX) / 2, y: (minY + maxY) / 2, width, height, pixels: xs.length });
116
+ }
96
117
  }
97
- }
98
- }
99
- const width = maxX - minX + 1;
100
- const height = maxY - minY + 1;
101
- const area = width * height;
102
- // The central module is solid and approximately square. This filter is
103
- // intentionally permissive because a rotated raster module is diamond-ish.
104
- if (xs.length <= maximumArea && Math.abs(width - height) <= Math.max(1, Math.ceil(Math.max(width, height) * 0.35)) &&
105
- xs.length >= area * 0.45) {
106
- out.push({ x: (minX + maxX) / 2, y: (minY + maxY) / 2, width, height, pixels: xs.length });
107
- }
108
- }
109
- return out.sort((a, b) => b.pixels - a.pixels).slice(0, 2000);
118
+ return out.sort((a, b) => b.pixels - a.pixels).slice(0, 2000);
110
119
  }
111
-
112
120
  function expectedDark(ring, inverted) {
113
- return inverted ? (ring & 1) === 1 : (ring & 1) === 0;
121
+ return inverted ? (ring & 1) === 1 : (ring & 1) === 0;
114
122
  }
115
-
116
123
  /** Score one square bull's-eye at an angle and a candidate module pitch. */
117
124
  function ringScore(image, centre, pitch, angle, inverted, rings) {
118
- const cos = Math.cos(angle);
119
- const sin = Math.sin(angle);
120
- let correct = 0;
121
- let total = 0;
122
- for (let ring = 0; ring < rings; ring++) {
123
- const wanted = expectedDark(ring, inverted);
124
- for (let j = -ring; j <= ring; j++) for (let i = -ring; i <= ring; i++) {
125
- if (ring && Math.abs(i) !== ring && Math.abs(j) !== ring) continue;
126
- const x = centre.x + (i * cos - j * sin) * pitch;
127
- const y = centre.y + (i * sin + j * cos) * pitch;
128
- if (pixel(image, x, y) === wanted) correct++;
129
- total++;
125
+ const cos = Math.cos(angle);
126
+ const sin = Math.sin(angle);
127
+ let correct = 0;
128
+ let total = 0;
129
+ for (let ring = 0; ring < rings; ring++) {
130
+ const wanted = expectedDark(ring, inverted);
131
+ for (let j = -ring; j <= ring; j++)
132
+ for (let i = -ring; i <= ring; i++) {
133
+ if (ring && Math.abs(i) !== ring && Math.abs(j) !== ring)
134
+ continue;
135
+ const x = centre.x + (i * cos - j * sin) * pitch;
136
+ const y = centre.y + (i * sin + j * cos) * pitch;
137
+ if (pixel(image, x, y) === wanted)
138
+ correct++;
139
+ total++;
140
+ }
130
141
  }
131
- }
132
- return correct / total;
142
+ return correct / total;
133
143
  }
134
-
135
144
  function rotateCorners(corners, turn) {
136
- return corners.slice(turn).concat(corners.slice(0, turn));
145
+ return corners.slice(turn).concat(corners.slice(0, turn));
137
146
  }
138
-
139
147
  function invert(matrix) {
140
- const out = matrix.clone();
141
- for (let y = 0; y < out.height; y++) for (let x = 0; x < out.width; x++) out.flip(x, y);
142
- return out;
148
+ const out = matrix.clone();
149
+ for (let y = 0; y < out.height; y++)
150
+ for (let x = 0; x < out.width; x++)
151
+ out.flip(x, y);
152
+ return out;
143
153
  }
144
-
145
154
  function cornersFor(centre, pitch, angle, dimension) {
146
- const half = dimension * pitch / 2;
147
- const cos = Math.cos(angle);
148
- const sin = Math.sin(angle);
149
- const point = (x, y) => ({ x: centre.x + x * cos - y * sin, y: centre.y + x * sin + y * cos });
150
- return [point(-half, -half), point(half, -half), point(half, half), point(-half, half)];
155
+ const half = dimension * pitch / 2;
156
+ const cos = Math.cos(angle);
157
+ const sin = Math.sin(angle);
158
+ const point = (x, y) => ({ x: centre.x + x * cos - y * sin, y: centre.y + x * sin + y * cos });
159
+ return [point(-half, -half), point(half, -half), point(half, half), point(-half, half)];
151
160
  }
152
-
153
161
  /**
154
162
  * Find an Aztec symbol in a binarized image.
155
163
  *
@@ -161,53 +169,62 @@ function cornersFor(centre, pitch, angle, dimension) {
161
169
  * @returns {Detection | null}
162
170
  */
163
171
  export function detectAztec(binaryImage) {
164
- if (!binaryImage || !binaryImage.width || !binaryImage.height) {
165
- throw new NotFoundError('detectAztec: no image supplied');
166
- }
167
- const candidates = [];
168
- for (const inverted of [false, true]) {
169
- for (const core of components(binaryImage, !inverted)) {
170
- // A non-rotated one-module component directly gives its pitch. For
171
- // rotated modules its bounding box grows by |sin| + |cos|, compensated
172
- // below for every tested angle.
173
- for (let degrees = 0; degrees < 180; degrees += 4) {
174
- const angle = degrees * Math.PI / 180;
175
- const scale = Math.abs(Math.cos(angle)) + Math.abs(Math.sin(angle));
176
- const pitch = ((core.width + core.height) / 2) / scale;
177
- if (pitch < 0.8) continue;
178
- // Test Full first: its seven rings also exclude Compact candidates.
179
- const fullScore = ringScore(binaryImage, core, pitch, angle, inverted, 7);
180
- const rings = fullScore >= 0.88 ? 7 : 5;
181
- const score = rings === 7 ? fullScore : ringScore(binaryImage, core, pitch, angle, inverted, 5);
182
- if (score < 0.91) continue;
183
- const symbolKinds = rings === 7 ? DIMENSIONS.filter((item) => !item.compact) : DIMENSIONS.filter((item) => item.compact);
184
- for (const kind of symbolKinds) {
185
- const baseCorners = cornersFor(core, pitch, angle, kind.dimension);
186
- for (let turn = 0; turn < 4; turn++) {
187
- const corners = rotateCorners(baseCorners, turn);
188
- let matrix;
189
- try { matrix = sampleQuad(binaryImage, kind.dimension, corners); } catch (e) { continue; }
190
- if (inverted) matrix = invert(matrix);
191
- try {
192
- // The decoder verifies the mode-message ECC and exact geometry.
193
- // We do not expose its result here so callers can use pure
194
- // detection without treating payload decoding as an API contract.
195
- decodeAztec(matrix);
196
- candidates.push({ corners, dimension: kind.dimension, compact: kind.compact,
197
- moduleSize: pitch, matrix, score });
198
- } catch (e) { /* Not an Aztec mode message at this dimension. */ }
199
- }
172
+ if (!binaryImage || !binaryImage.width || !binaryImage.height) {
173
+ throw new NotFoundError('detectAztec: no image supplied');
174
+ }
175
+ const candidates = [];
176
+ for (const inverted of [false, true]) {
177
+ for (const core of components(binaryImage, !inverted)) {
178
+ // A non-rotated one-module component directly gives its pitch. For
179
+ // rotated modules its bounding box grows by |sin| + |cos|, compensated
180
+ // below for every tested angle.
181
+ for (let degrees = 0; degrees < 180; degrees += 4) {
182
+ const angle = degrees * Math.PI / 180;
183
+ const scale = Math.abs(Math.cos(angle)) + Math.abs(Math.sin(angle));
184
+ const pitch = ((core.width + core.height) / 2) / scale;
185
+ if (pitch < 0.8)
186
+ continue;
187
+ // Test Full first: its seven rings also exclude Compact candidates.
188
+ const fullScore = ringScore(binaryImage, core, pitch, angle, inverted, 7);
189
+ const rings = fullScore >= 0.88 ? 7 : 5;
190
+ const score = rings === 7 ? fullScore : ringScore(binaryImage, core, pitch, angle, inverted, 5);
191
+ if (score < 0.91)
192
+ continue;
193
+ const symbolKinds = rings === 7 ? DIMENSIONS.filter((item) => !item.compact) : DIMENSIONS.filter((item) => item.compact);
194
+ for (const kind of symbolKinds) {
195
+ const baseCorners = cornersFor(core, pitch, angle, kind.dimension);
196
+ for (let turn = 0; turn < 4; turn++) {
197
+ const corners = rotateCorners(baseCorners, turn);
198
+ let matrix;
199
+ try {
200
+ matrix = sampleQuad(binaryImage, kind.dimension, corners);
201
+ }
202
+ catch (e) {
203
+ continue;
204
+ }
205
+ if (inverted)
206
+ matrix = invert(matrix);
207
+ try {
208
+ // The decoder verifies the mode-message ECC and exact geometry.
209
+ // We do not expose its result here so callers can use pure
210
+ // detection without treating payload decoding as an API contract.
211
+ decodeAztec(matrix);
212
+ candidates.push({ corners, dimension: kind.dimension, compact: kind.compact,
213
+ moduleSize: pitch, matrix, score });
214
+ }
215
+ catch (e) { /* Not an Aztec mode message at this dimension. */ }
216
+ }
217
+ }
218
+ }
200
219
  }
201
- }
202
220
  }
203
- }
204
- candidates.sort((a, b) => b.score - a.score || b.moduleSize - a.moduleSize);
205
- const best = candidates[0];
206
- if (!best) return null;
207
- delete best.score;
208
- return best;
221
+ candidates.sort((a, b) => b.score - a.score || b.moduleSize - a.moduleSize);
222
+ const best = candidates[0];
223
+ if (!best)
224
+ return null;
225
+ delete best.score;
226
+ return best;
209
227
  }
210
-
211
228
  /**
212
229
  * Detect then decode an Aztec symbol. Detection failure is a normal result for
213
230
  * images without an Aztec code, therefore invalid candidates return null.
@@ -216,9 +233,19 @@ export function detectAztec(binaryImage) {
216
233
  * @returns {(import('./decoder.js').DecodeResult & {corners: Point[]}) | null}
217
234
  */
218
235
  export function detectAndDecodeAztec(binaryImage) {
219
- let detection;
220
- try { detection = detectAztec(binaryImage); } catch (e) { return null; }
221
- if (!detection) return null;
222
- try { return Object.assign({ corners: detection.corners }, decodeAztec(detection.matrix)); }
223
- catch (e) { return null; }
236
+ let detection;
237
+ try {
238
+ detection = detectAztec(binaryImage);
239
+ }
240
+ catch (e) {
241
+ return null;
242
+ }
243
+ if (!detection)
244
+ return null;
245
+ try {
246
+ return Object.assign({ corners: detection.corners }, decodeAztec(detection.matrix));
247
+ }
248
+ catch (e) {
249
+ return null;
250
+ }
224
251
  }