@sythos/js_barcode_universal 1.5.8 → 1.5.9

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 +17 -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
  * A 2D bit grid — the common currency of this library.
33
32
  *
@@ -43,199 +42,202 @@
43
42
  *
44
43
  * @module core/bit-matrix
45
44
  */
46
-
47
45
  export class BitMatrix {
48
- /**
49
- * @param {number} width
50
- * @param {number} height
51
- */
52
- constructor(width, height = width) {
53
- if (width < 1 || height < 1) {
54
- throw new Error(`BitMatrix: dimensions must be positive, got ${width}x${height}`);
55
- }
56
- this.width = width;
57
- this.height = height;
58
- this.rowWords = Math.ceil(width / 32);
59
- this.bits = new Uint32Array(this.rowWords * height);
60
- }
61
-
62
- /**
63
- * @param {number} x @param {number} y
64
- * @returns {boolean} True if the module is dark.
65
- */
66
- get(x, y) {
67
- if (x < 0 || y < 0 || x >= this.width || y >= this.height) return false;
68
- return ((this.bits[y * this.rowWords + (x >>> 5)] >>> (x & 31)) & 1) === 1;
69
- }
70
-
71
- /** @param {number} x @param {number} y */
72
- set(x, y) {
73
- if (x < 0 || y < 0 || x >= this.width || y >= this.height) return;
74
- this.bits[y * this.rowWords + (x >>> 5)] |= 1 << (x & 31);
75
- }
76
-
77
- /** @param {number} x @param {number} y */
78
- unset(x, y) {
79
- if (x < 0 || y < 0 || x >= this.width || y >= this.height) return;
80
- this.bits[y * this.rowWords + (x >>> 5)] &= ~(1 << (x & 31));
81
- }
82
-
83
- /** @param {number} x @param {number} y */
84
- flip(x, y) {
85
- if (x < 0 || y < 0 || x >= this.width || y >= this.height) return;
86
- this.bits[y * this.rowWords + (x >>> 5)] ^= 1 << (x & 31);
87
- }
88
-
89
- /**
90
- * @param {number} x @param {number} y @param {boolean} value
91
- */
92
- setValue(x, y, value) {
93
- if (value) this.set(x, y);
94
- else this.unset(x, y);
95
- }
96
-
97
- /** Fill a rectangle. @param {number} x @param {number} y @param {number} w @param {number} h */
98
- setRegion(x, y, w, h) {
99
- for (let j = y; j < y + h; j++) {
100
- for (let i = x; i < x + w; i++) this.set(i, j);
101
- }
102
- }
103
-
104
- clear() {
105
- this.bits.fill(0);
106
- }
107
-
108
- /** @returns {BitMatrix} */
109
- clone() {
110
- const m = new BitMatrix(this.width, this.height);
111
- m.bits.set(this.bits);
112
- return m;
113
- }
114
-
115
- /**
116
- * Copy row `y` into a reusable array, avoiding an allocation per row in the
117
- * 1D scanning loops which run this thousands of times per image.
118
- *
119
- * @param {number} y
120
- * @param {Uint8Array} [out]
121
- * @returns {Uint8Array}
122
- */
123
- getRow(y, out) {
124
- const row = out && out.length >= this.width ? out : new Uint8Array(this.width);
125
- const base = y * this.rowWords;
126
- for (let x = 0; x < this.width; x++) {
127
- row[x] = (this.bits[base + (x >>> 5)] >>> (x & 31)) & 1;
128
- }
129
- return row;
130
- }
131
-
132
- /**
133
- * Add a uniform light border. Symbols need a quiet zone to be scannable at
134
- * all, so this is applied by default when rendering.
135
- *
136
- * @param {number} size Modules of margin on every side.
137
- * @returns {BitMatrix}
138
- */
139
- withMargin(size) {
140
- if (size <= 0) return this.clone();
141
- const m = new BitMatrix(this.width + size * 2, this.height + size * 2);
142
- for (let y = 0; y < this.height; y++) {
143
- for (let x = 0; x < this.width; x++) {
144
- if (this.get(x, y)) m.set(x + size, y + size);
145
- }
146
- }
147
- return m;
148
- }
149
-
150
- /**
151
- * Nearest-neighbour upscale. Integer factors only — a barcode resampled with
152
- * interpolation stops being readable.
153
- *
154
- * @param {number} factor
155
- * @returns {BitMatrix}
156
- */
157
- scale(factor) {
158
- const f = Math.max(1, Math.floor(factor));
159
- if (f === 1) return this.clone();
160
- const m = new BitMatrix(this.width * f, this.height * f);
161
- for (let y = 0; y < this.height; y++) {
162
- for (let x = 0; x < this.width; x++) {
163
- if (this.get(x, y)) m.setRegion(x * f, y * f, f, f);
164
- }
165
- }
166
- return m;
167
- }
168
-
169
- /**
170
- * Bounding box of the dark modules, or null if the matrix is empty.
171
- * @returns {{x: number, y: number, width: number, height: number} | null}
172
- */
173
- getBounds() {
174
- let minX = this.width, minY = this.height, maxX = -1, maxY = -1;
175
- for (let y = 0; y < this.height; y++) {
176
- for (let x = 0; x < this.width; x++) {
177
- if (this.get(x, y)) {
178
- if (x < minX) minX = x;
179
- if (x > maxX) maxX = x;
180
- if (y < minY) minY = y;
181
- if (y > maxY) maxY = y;
46
+ /**
47
+ * @param {number} width
48
+ * @param {number} height
49
+ */
50
+ constructor(width, height = width) {
51
+ if (width < 1 || height < 1) {
52
+ throw new Error(`BitMatrix: dimensions must be positive, got ${width}x${height}`);
182
53
  }
183
- }
184
- }
185
- if (maxX < 0) return null;
186
- return { x: minX, y: minY, width: maxX - minX + 1, height: maxY - minY + 1 };
187
- }
188
-
189
- /**
190
- * Rotate 180 degrees, in place. Cheaper than re-detecting when a reader
191
- * discovers a symbol is upside down.
192
- */
193
- rotate180() {
194
- const w = this.width, h = this.height;
195
- for (let y = 0; y < Math.ceil(h / 2); y++) {
196
- for (let x = 0; x < w; x++) {
197
- const oy = h - 1 - y, ox = w - 1 - x;
198
- if (y === oy && x >= ox) break;
199
- const a = this.get(x, y);
200
- const b = this.get(ox, oy);
201
- this.setValue(x, y, b);
202
- this.setValue(ox, oy, a);
203
- }
204
- }
205
- }
206
-
207
- /**
208
- * Build from a string of '1'/'X'/'#' (dark) and anything else (light),
209
- * newline-separated. Test fixtures are far more legible this way.
210
- *
211
- * @param {string} text
212
- * @returns {BitMatrix}
213
- */
214
- static parse(text) {
215
- const lines = text.trim().split('\n').map((l) => l.trim()).filter((l) => l.length);
216
- const height = lines.length;
217
- const width = Math.max(...lines.map((l) => l.length));
218
- const m = new BitMatrix(width, height);
219
- for (let y = 0; y < height; y++) {
220
- for (let x = 0; x < lines[y].length; x++) {
221
- const c = lines[y][x];
222
- if (c === '1' || c === 'X' || c === 'x' || c === '#') m.set(x, y);
223
- }
224
- }
225
- return m;
226
- }
227
-
228
- /**
229
- * @param {string} [dark] @param {string} [light]
230
- * @returns {string}
231
- */
232
- toString(dark = '##', light = ' ') {
233
- const rows = [];
234
- for (let y = 0; y < this.height; y++) {
235
- let s = '';
236
- for (let x = 0; x < this.width; x++) s += this.get(x, y) ? dark : light;
237
- rows.push(s);
238
- }
239
- return rows.join('\n');
240
- }
54
+ this.width = width;
55
+ this.height = height;
56
+ this.rowWords = Math.ceil(width / 32);
57
+ this.bits = new Uint32Array(this.rowWords * height);
58
+ }
59
+ /**
60
+ * @param {number} x @param {number} y
61
+ * @returns {boolean} True if the module is dark.
62
+ */
63
+ get(x, y) {
64
+ if (x < 0 || y < 0 || x >= this.width || y >= this.height)
65
+ return false;
66
+ return ((this.bits[y * this.rowWords + (x >>> 5)] >>> (x & 31)) & 1) === 1;
67
+ }
68
+ /** @param {number} x @param {number} y */
69
+ set(x, y) {
70
+ if (x < 0 || y < 0 || x >= this.width || y >= this.height)
71
+ return;
72
+ this.bits[y * this.rowWords + (x >>> 5)] |= 1 << (x & 31);
73
+ }
74
+ /** @param {number} x @param {number} y */
75
+ unset(x, y) {
76
+ if (x < 0 || y < 0 || x >= this.width || y >= this.height)
77
+ return;
78
+ this.bits[y * this.rowWords + (x >>> 5)] &= ~(1 << (x & 31));
79
+ }
80
+ /** @param {number} x @param {number} y */
81
+ flip(x, y) {
82
+ if (x < 0 || y < 0 || x >= this.width || y >= this.height)
83
+ return;
84
+ this.bits[y * this.rowWords + (x >>> 5)] ^= 1 << (x & 31);
85
+ }
86
+ /**
87
+ * @param {number} x @param {number} y @param {boolean} value
88
+ */
89
+ setValue(x, y, value) {
90
+ if (value)
91
+ this.set(x, y);
92
+ else
93
+ this.unset(x, y);
94
+ }
95
+ /** Fill a rectangle. @param {number} x @param {number} y @param {number} w @param {number} h */
96
+ setRegion(x, y, w, h) {
97
+ for (let j = y; j < y + h; j++) {
98
+ for (let i = x; i < x + w; i++)
99
+ this.set(i, j);
100
+ }
101
+ }
102
+ clear() {
103
+ this.bits.fill(0);
104
+ }
105
+ /** @returns {BitMatrix} */
106
+ clone() {
107
+ const m = new BitMatrix(this.width, this.height);
108
+ m.bits.set(this.bits);
109
+ return m;
110
+ }
111
+ /**
112
+ * Copy row `y` into a reusable array, avoiding an allocation per row in the
113
+ * 1D scanning loops which run this thousands of times per image.
114
+ *
115
+ * @param {number} y
116
+ * @param {Uint8Array} [out]
117
+ * @returns {Uint8Array}
118
+ */
119
+ getRow(y, out) {
120
+ const row = out && out.length >= this.width ? out : new Uint8Array(this.width);
121
+ const base = y * this.rowWords;
122
+ for (let x = 0; x < this.width; x++) {
123
+ row[x] = (this.bits[base + (x >>> 5)] >>> (x & 31)) & 1;
124
+ }
125
+ return row;
126
+ }
127
+ /**
128
+ * Add a uniform light border. Symbols need a quiet zone to be scannable at
129
+ * all, so this is applied by default when rendering.
130
+ *
131
+ * @param {number} size Modules of margin on every side.
132
+ * @returns {BitMatrix}
133
+ */
134
+ withMargin(size) {
135
+ if (size <= 0)
136
+ return this.clone();
137
+ const m = new BitMatrix(this.width + size * 2, this.height + size * 2);
138
+ for (let y = 0; y < this.height; y++) {
139
+ for (let x = 0; x < this.width; x++) {
140
+ if (this.get(x, y))
141
+ m.set(x + size, y + size);
142
+ }
143
+ }
144
+ return m;
145
+ }
146
+ /**
147
+ * Nearest-neighbour upscale. Integer factors only — a barcode resampled with
148
+ * interpolation stops being readable.
149
+ *
150
+ * @param {number} factor
151
+ * @returns {BitMatrix}
152
+ */
153
+ scale(factor) {
154
+ const f = Math.max(1, Math.floor(factor));
155
+ if (f === 1)
156
+ return this.clone();
157
+ const m = new BitMatrix(this.width * f, this.height * f);
158
+ for (let y = 0; y < this.height; y++) {
159
+ for (let x = 0; x < this.width; x++) {
160
+ if (this.get(x, y))
161
+ m.setRegion(x * f, y * f, f, f);
162
+ }
163
+ }
164
+ return m;
165
+ }
166
+ /**
167
+ * Bounding box of the dark modules, or null if the matrix is empty.
168
+ * @returns {{x: number, y: number, width: number, height: number} | null}
169
+ */
170
+ getBounds() {
171
+ let minX = this.width, minY = this.height, maxX = -1, maxY = -1;
172
+ for (let y = 0; y < this.height; y++) {
173
+ for (let x = 0; x < this.width; x++) {
174
+ if (this.get(x, y)) {
175
+ if (x < minX)
176
+ minX = x;
177
+ if (x > maxX)
178
+ maxX = x;
179
+ if (y < minY)
180
+ minY = y;
181
+ if (y > maxY)
182
+ maxY = y;
183
+ }
184
+ }
185
+ }
186
+ if (maxX < 0)
187
+ return null;
188
+ return { x: minX, y: minY, width: maxX - minX + 1, height: maxY - minY + 1 };
189
+ }
190
+ /**
191
+ * Rotate 180 degrees, in place. Cheaper than re-detecting when a reader
192
+ * discovers a symbol is upside down.
193
+ */
194
+ rotate180() {
195
+ const w = this.width, h = this.height;
196
+ for (let y = 0; y < Math.ceil(h / 2); y++) {
197
+ for (let x = 0; x < w; x++) {
198
+ const oy = h - 1 - y, ox = w - 1 - x;
199
+ if (y === oy && x >= ox)
200
+ break;
201
+ const a = this.get(x, y);
202
+ const b = this.get(ox, oy);
203
+ this.setValue(x, y, b);
204
+ this.setValue(ox, oy, a);
205
+ }
206
+ }
207
+ }
208
+ /**
209
+ * Build from a string of '1'/'X'/'#' (dark) and anything else (light),
210
+ * newline-separated. Test fixtures are far more legible this way.
211
+ *
212
+ * @param {string} text
213
+ * @returns {BitMatrix}
214
+ */
215
+ static parse(text) {
216
+ const lines = text.trim().split('\n').map((l) => l.trim()).filter((l) => l.length);
217
+ const height = lines.length;
218
+ const width = Math.max(...lines.map((l) => l.length));
219
+ const m = new BitMatrix(width, height);
220
+ for (let y = 0; y < height; y++) {
221
+ for (let x = 0; x < lines[y].length; x++) {
222
+ const c = lines[y][x];
223
+ if (c === '1' || c === 'X' || c === 'x' || c === '#')
224
+ m.set(x, y);
225
+ }
226
+ }
227
+ return m;
228
+ }
229
+ /**
230
+ * @param {string} [dark] @param {string} [light]
231
+ * @returns {string}
232
+ */
233
+ toString(dark = '##', light = ' ') {
234
+ const rows = [];
235
+ for (let y = 0; y < this.height; y++) {
236
+ let s = '';
237
+ for (let x = 0; x < this.width; x++)
238
+ s += this.get(x, y) ? dark : light;
239
+ rows.push(s);
240
+ }
241
+ return rows.join('\n');
242
+ }
241
243
  }
@@ -27,7 +27,6 @@
27
27
  *
28
28
  * Original work. No code from any other barcode implementation.
29
29
  */
30
-
31
30
  /**
32
31
  * Error types.
33
32
  *
@@ -38,24 +37,23 @@
38
37
  *
39
38
  * @module core/errors
40
39
  */
41
-
42
40
  /** Base class so consumers can `catch (e) { if (e instanceof BarcodeError) ... }`. */
43
41
  export class BarcodeError extends Error {
44
- /** @param {string} message */
45
- constructor(message) {
46
- super(message);
47
- this.name = new.target.name;
48
- }
42
+ /** @param {string} message */
43
+ constructor(message) {
44
+ super(message);
45
+ this.name = new.target.name;
46
+ }
49
47
  }
50
-
51
48
  /** Input could not be encoded — bad payload, or it does not fit the symbology. */
52
- export class EncodeError extends BarcodeError {}
53
-
49
+ export class EncodeError extends BarcodeError {
50
+ }
54
51
  /** No symbol was found in the image. Not an error condition for `decode()`. */
55
- export class NotFoundError extends BarcodeError {}
56
-
52
+ export class NotFoundError extends BarcodeError {
53
+ }
57
54
  /** A symbol was found, but its geometry or content is malformed. */
58
- export class FormatError extends BarcodeError {}
59
-
55
+ export class FormatError extends BarcodeError {
56
+ }
60
57
  /** A symbol was found and read, but error correction could not repair it. */
61
- export class ChecksumError extends BarcodeError {}
58
+ export class ChecksumError extends BarcodeError {
59
+ }