@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,183 +27,158 @@
27
27
  *
28
28
  * Original work. No code from any other barcode implementation.
29
29
  */
30
-
31
30
  /** MicroPDF417 encoder. @module micropdf417/encoder */
32
-
33
31
  import { BitMatrix } from '../core/bit-matrix.js';
34
32
  import { EncodeError } from '../core/errors.js';
35
33
  import { pdf417PatternForCodeword } from '../pdf417/tables.js';
36
34
  import { compactMicroPDF417 } from './compaction.js';
37
35
  import { microPdf417ErrorCorrection } from './error-correction.js';
38
- import {
39
- MICROPDF417_VARIANTS,
40
- microPdf417RapSequence,
41
- microPdf417RowAddress,
42
- microPdf417VariantByNumber,
43
- microPdf417VariantForCapacity,
44
- } from './tables.js';
45
-
36
+ import { MICROPDF417_VARIANTS, microPdf417RapSequence, microPdf417RowAddress, microPdf417VariantByNumber, microPdf417VariantForCapacity, } from './tables.js';
46
37
  function appendWidths(matrix, y, x, sequence, height) {
47
- let dark = true;
48
- for (const digit of sequence) {
49
- const width = digit.charCodeAt(0) - 48;
50
- if (!Number.isInteger(width) || width < 1 || width > 6) {
51
- throw new EncodeError('MicroPDF417: invalid module-width sequence');
38
+ let dark = true;
39
+ for (const digit of sequence) {
40
+ const width = digit.charCodeAt(0) - 48;
41
+ if (!Number.isInteger(width) || width < 1 || width > 6) {
42
+ throw new EncodeError('MicroPDF417: invalid module-width sequence');
43
+ }
44
+ if (dark)
45
+ matrix.setRegion(x, y, width, height);
46
+ x += width;
47
+ dark = !dark;
52
48
  }
53
- if (dark) matrix.setRegion(x, y, width, height);
54
- x += width;
55
- dark = !dark;
56
- }
57
- return x;
49
+ return x;
58
50
  }
59
-
60
51
  function codewordSequence(codeword, cluster) {
61
- return pdf417PatternForCodeword(codeword, cluster)
62
- .toString(2)
63
- .padStart(17, '0')
64
- .replace(/0+|1+/g, (run) => String(run.length));
52
+ return pdf417PatternForCodeword(codeword, cluster)
53
+ .toString(2)
54
+ .padStart(17, '0')
55
+ .replace(/0+|1+/g, (run) => String(run.length));
65
56
  }
66
-
67
57
  function symbolWidth(columns) {
68
- return 21 + columns * 17 + (columns > 2 ? 10 : 0);
58
+ return 21 + columns * 17 + (columns > 2 ? 10 : 0);
69
59
  }
70
-
71
60
  function validateOptions(options) {
72
- const rowHeight = options.rowHeight ?? 2;
73
- if (!Number.isInteger(rowHeight) || rowHeight < 2) {
74
- throw new EncodeError('MicroPDF417: rowHeight must be an integer of at least 2');
75
- }
76
- if (options.columns !== undefined &&
77
- (!Number.isInteger(options.columns) || options.columns < 1 || options.columns > 4)) {
78
- throw new EncodeError('MicroPDF417: columns must be an integer in 1..4');
79
- }
80
- if (options.variant !== undefined &&
81
- (!Number.isInteger(options.variant) || options.variant < 1 || options.variant > 34)) {
82
- throw new EncodeError('MicroPDF417: variant must be an integer in 1..34');
83
- }
84
- if (options.aspectRatio !== undefined &&
85
- (!Number.isFinite(options.aspectRatio) || options.aspectRatio <= 0)) {
86
- throw new EncodeError('MicroPDF417: aspectRatio must be positive');
87
- }
88
- if (options.rows !== undefined) {
89
- throw new EncodeError('MicroPDF417: rows are fixed by the selected variant');
90
- }
91
- if (options.eccLevel !== undefined) {
92
- throw new EncodeError('MicroPDF417: error correction is fixed by the selected variant');
93
- }
94
- for (const feature of [
95
- 'structuredAppend', 'macro', 'macroPdf417', 'macroControlBlock',
96
- 'readerInit', 'gs1', 'hibc', 'linkage',
97
- ]) {
98
- if (options[feature] !== undefined) {
99
- throw new EncodeError(`MicroPDF417: ${feature} is not implemented`);
61
+ const rowHeight = options.rowHeight ?? 2;
62
+ if (!Number.isInteger(rowHeight) || rowHeight < 2) {
63
+ throw new EncodeError('MicroPDF417: rowHeight must be an integer of at least 2');
64
+ }
65
+ if (options.columns !== undefined &&
66
+ (!Number.isInteger(options.columns) || options.columns < 1 || options.columns > 4)) {
67
+ throw new EncodeError('MicroPDF417: columns must be an integer in 1..4');
68
+ }
69
+ if (options.variant !== undefined &&
70
+ (!Number.isInteger(options.variant) || options.variant < 1 || options.variant > 34)) {
71
+ throw new EncodeError('MicroPDF417: variant must be an integer in 1..34');
72
+ }
73
+ if (options.aspectRatio !== undefined &&
74
+ (!Number.isFinite(options.aspectRatio) || options.aspectRatio <= 0)) {
75
+ throw new EncodeError('MicroPDF417: aspectRatio must be positive');
76
+ }
77
+ if (options.rows !== undefined) {
78
+ throw new EncodeError('MicroPDF417: rows are fixed by the selected variant');
79
+ }
80
+ if (options.eccLevel !== undefined) {
81
+ throw new EncodeError('MicroPDF417: error correction is fixed by the selected variant');
82
+ }
83
+ for (const feature of [
84
+ 'structuredAppend', 'macro', 'macroPdf417', 'macroControlBlock',
85
+ 'readerInit', 'gs1', 'hibc', 'linkage',
86
+ ]) {
87
+ if (options[feature] !== undefined) {
88
+ throw new EncodeError(`MicroPDF417: ${feature} is not implemented`);
89
+ }
100
90
  }
101
- }
102
- return rowHeight;
91
+ return rowHeight;
103
92
  }
104
-
105
93
  function chooseVariant(codewordCount, rowHeight, options) {
106
- if (options.variant !== undefined) {
107
- const variant = microPdf417VariantByNumber(options.variant);
108
- if (!variant) throw new EncodeError(`MicroPDF417: unknown variant ${options.variant}`);
109
- if (options.columns !== undefined && variant.columns !== options.columns) {
110
- throw new EncodeError(`MicroPDF417: variant ${variant.id} has ${variant.columns} columns`);
94
+ if (options.variant !== undefined) {
95
+ const variant = microPdf417VariantByNumber(options.variant);
96
+ if (!variant)
97
+ throw new EncodeError(`MicroPDF417: unknown variant ${options.variant}`);
98
+ if (options.columns !== undefined && variant.columns !== options.columns) {
99
+ throw new EncodeError(`MicroPDF417: variant ${variant.id} has ${variant.columns} columns`);
100
+ }
101
+ if (codewordCount > variant.dataCodewords) {
102
+ throw new EncodeError(`MicroPDF417: payload requires ${codewordCount} data codewords, variant ${variant.id} holds ${variant.dataCodewords}`);
103
+ }
104
+ return variant;
111
105
  }
112
- if (codewordCount > variant.dataCodewords) {
113
- throw new EncodeError(
114
- `MicroPDF417: payload requires ${codewordCount} data codewords, variant ${variant.id} holds ${variant.dataCodewords}`
115
- );
106
+ if (options.columns === undefined && options.aspectRatio === undefined) {
107
+ try {
108
+ return microPdf417VariantForCapacity(codewordCount);
109
+ }
110
+ catch (error) {
111
+ if (!(error instanceof RangeError))
112
+ throw error;
113
+ throw new EncodeError(`MicroPDF417: payload requires ${codewordCount} data codewords and exceeds every variant`);
114
+ }
116
115
  }
117
- return variant;
118
- }
119
-
120
- if (options.columns === undefined && options.aspectRatio === undefined) {
121
- try {
122
- return microPdf417VariantForCapacity(codewordCount);
123
- } catch (error) {
124
- if (!(error instanceof RangeError)) throw error;
125
- throw new EncodeError(`MicroPDF417: payload requires ${codewordCount} data codewords and exceeds every variant`);
116
+ const candidates = MICROPDF417_VARIANTS.filter((variant) => variant.dataCodewords >= codewordCount &&
117
+ (options.columns === undefined || variant.columns === options.columns));
118
+ if (!candidates.length) {
119
+ const columnText = options.columns === undefined ? '' : ` with ${options.columns} columns`;
120
+ throw new EncodeError(`MicroPDF417: payload does not fit any supported variant${columnText}`);
126
121
  }
127
- }
128
-
129
- const candidates = MICROPDF417_VARIANTS.filter((variant) =>
130
- variant.dataCodewords >= codewordCount &&
131
- (options.columns === undefined || variant.columns === options.columns)
132
- );
133
- if (!candidates.length) {
134
- const columnText = options.columns === undefined ? '' : ` with ${options.columns} columns`;
135
- throw new EncodeError(`MicroPDF417: payload does not fit any supported variant${columnText}`);
136
- }
137
- if (options.aspectRatio === undefined) {
138
- return candidates.reduce((best, variant) =>
139
- variant.dataCodewords < best.dataCodewords ||
140
- (variant.dataCodewords === best.dataCodewords && variant.totalCodewords < best.totalCodewords)
141
- ? variant : best
142
- );
143
- }
144
-
145
- const target = options.aspectRatio;
146
- return candidates.reduce((best, variant) => {
147
- const ratio = symbolWidth(variant.columns) / (variant.rows * rowHeight);
148
- const score = Math.abs(Math.log(ratio / target)) +
149
- (variant.dataCodewords - codewordCount) / 10000;
150
- return !best || score < best.score ? { variant, score } : best;
151
- }, null).variant;
122
+ if (options.aspectRatio === undefined) {
123
+ return candidates.reduce((best, variant) => variant.dataCodewords < best.dataCodewords ||
124
+ (variant.dataCodewords === best.dataCodewords && variant.totalCodewords < best.totalCodewords)
125
+ ? variant : best);
126
+ }
127
+ const target = options.aspectRatio;
128
+ return candidates.reduce((best, variant) => {
129
+ const ratio = symbolWidth(variant.columns) / (variant.rows * rowHeight);
130
+ const score = Math.abs(Math.log(ratio / target)) +
131
+ (variant.dataCodewords - codewordCount) / 10000;
132
+ return !best || score < best.score ? { variant, score } : best;
133
+ }, null).variant;
152
134
  }
153
-
154
135
  /** Encode a value as one of the 34 fixed MicroPDF417 variants. */
155
136
  export function encodeMicroPDF417(value, options = {}) {
156
- const rowHeight = validateOptions(options);
157
- const payload = compactMicroPDF417(value, options);
158
- const variant = chooseVariant(payload.length, rowHeight, options);
159
- const data = payload.slice();
160
- while (data.length < variant.dataCodewords) data.push(900);
161
- const ecc = microPdf417ErrorCorrection(data, variant);
162
- if (ecc.length !== variant.eccCodewords) {
163
- throw new EncodeError('MicroPDF417: error-correction length does not match the selected variant');
164
- }
165
- const codewords = data.concat(ecc);
166
- if (codewords.length !== variant.totalCodewords || codewords.length !== variant.rows * variant.columns) {
167
- throw new EncodeError('MicroPDF417: selected variant has inconsistent codeword dimensions');
168
- }
169
-
170
- const matrix = new BitMatrix(symbolWidth(variant.columns), variant.rows * rowHeight);
171
- for (let row = 0; row < variant.rows; row++) {
172
- const y = row * rowHeight;
173
- const address = microPdf417RowAddress(variant, row);
174
- let x = appendWidths(matrix, y, 0, microPdf417RapSequence(address.left, 'side'), rowHeight);
175
- for (let column = 0; column < variant.columns; column++) {
176
- x = appendWidths(
177
- matrix,
178
- y,
179
- x,
180
- codewordSequence(codewords[row * variant.columns + column], address.cluster),
181
- rowHeight
182
- );
183
- const hasCentralRap = (variant.columns === 3 && column === 0) ||
184
- (variant.columns === 4 && column === 1);
185
- if (hasCentralRap) {
186
- if (address.center === null) {
187
- throw new EncodeError('MicroPDF417: selected variant is missing its centre row address');
137
+ const rowHeight = validateOptions(options);
138
+ const payload = compactMicroPDF417(value, options);
139
+ const variant = chooseVariant(payload.length, rowHeight, options);
140
+ const data = payload.slice();
141
+ while (data.length < variant.dataCodewords)
142
+ data.push(900);
143
+ const ecc = microPdf417ErrorCorrection(data, variant);
144
+ if (ecc.length !== variant.eccCodewords) {
145
+ throw new EncodeError('MicroPDF417: error-correction length does not match the selected variant');
146
+ }
147
+ const codewords = data.concat(ecc);
148
+ if (codewords.length !== variant.totalCodewords || codewords.length !== variant.rows * variant.columns) {
149
+ throw new EncodeError('MicroPDF417: selected variant has inconsistent codeword dimensions');
150
+ }
151
+ const matrix = new BitMatrix(symbolWidth(variant.columns), variant.rows * rowHeight);
152
+ for (let row = 0; row < variant.rows; row++) {
153
+ const y = row * rowHeight;
154
+ const address = microPdf417RowAddress(variant, row);
155
+ let x = appendWidths(matrix, y, 0, microPdf417RapSequence(address.left, 'side'), rowHeight);
156
+ for (let column = 0; column < variant.columns; column++) {
157
+ x = appendWidths(matrix, y, x, codewordSequence(codewords[row * variant.columns + column], address.cluster), rowHeight);
158
+ const hasCentralRap = (variant.columns === 3 && column === 0) ||
159
+ (variant.columns === 4 && column === 1);
160
+ if (hasCentralRap) {
161
+ if (address.center === null) {
162
+ throw new EncodeError('MicroPDF417: selected variant is missing its centre row address');
163
+ }
164
+ x = appendWidths(matrix, y, x, microPdf417RapSequence(address.center, 'center'), rowHeight);
165
+ }
188
166
  }
189
- x = appendWidths(matrix, y, x, microPdf417RapSequence(address.center, 'center'), rowHeight);
190
- }
167
+ x = appendWidths(matrix, y, x, microPdf417RapSequence(address.right, 'side'), rowHeight);
168
+ matrix.setRegion(x, y, 1, rowHeight);
169
+ x++;
170
+ if (x !== matrix.width)
171
+ throw new EncodeError('MicroPDF417: row width does not match the selected variant');
191
172
  }
192
- x = appendWidths(matrix, y, x, microPdf417RapSequence(address.right, 'side'), rowHeight);
193
- matrix.setRegion(x, y, 1, rowHeight);
194
- x++;
195
- if (x !== matrix.width) throw new EncodeError('MicroPDF417: row width does not match the selected variant');
196
- }
197
-
198
- matrix.micropdf417 = {
199
- variant: variant.id,
200
- rows: variant.rows,
201
- columns: variant.columns,
202
- eccCodewords: variant.eccCodewords,
203
- rowHeight,
204
- payloadCodewords: payload.length,
205
- dataCodewords: data,
206
- codewords,
207
- };
208
- return matrix;
173
+ matrix.micropdf417 = {
174
+ variant: variant.id,
175
+ rows: variant.rows,
176
+ columns: variant.columns,
177
+ eccCodewords: variant.eccCodewords,
178
+ rowHeight,
179
+ payloadCodewords: payload.length,
180
+ dataCodewords: data,
181
+ codewords,
182
+ };
183
+ return matrix;
209
184
  }
@@ -27,29 +27,24 @@
27
27
  *
28
28
  * Original work. No code from any other barcode implementation.
29
29
  */
30
-
31
30
  /** MicroPDF417 error correction over the existing GF(929) core. @module micropdf417/error-correction */
32
-
33
31
  import { EncodeError } from '../core/errors.js';
34
32
  import { GF929 } from '../core/galois-field.js';
35
33
  import { generatorPoly, rsDecode, rsEncode } from '../core/reed-solomon.js';
36
-
37
34
  function eccLength(entry) {
38
- if (!entry || !Number.isInteger(entry.eccCodewords)) throw new EncodeError('MicroPDF417: a variant with an ECC length is required');
39
- if (entry.eccCodewords < 1 || entry.eccCodewords >= GF929.size) throw new EncodeError('MicroPDF417: ECC length is outside GF(929) bounds');
40
- return entry.eccCodewords;
35
+ if (!entry || !Number.isInteger(entry.eccCodewords))
36
+ throw new EncodeError('MicroPDF417: a variant with an ECC length is required');
37
+ if (entry.eccCodewords < 1 || entry.eccCodewords >= GF929.size)
38
+ throw new EncodeError('MicroPDF417: ECC length is outside GF(929) bounds');
39
+ return entry.eccCodewords;
41
40
  }
42
-
43
41
  /** Return the fixed number of parity codewords for a MicroPDF417 variant. */
44
42
  export function microPdf417EccLength(entry) { return eccLength(entry); }
45
-
46
43
  /** Build the MicroPDF417 generator polynomial for a variant's fixed ECC length. */
47
44
  export function microPdf417Generator(entry) { return generatorPoly(eccLength(entry), GF929, 1); }
48
-
49
45
  /** Compute systematic MicroPDF417 parity codewords. `data` must already include padding. */
50
46
  export function microPdf417ErrorCorrection(data, entry) { return rsEncode(data, eccLength(entry), GF929, 1); }
51
-
52
47
  /** Correct a complete MicroPDF417 codeword stream, optionally marking erasures. */
53
48
  export function microPdf417CorrectErrors(codewords, entry, erasures = []) {
54
- return rsDecode(codewords, eccLength(entry), GF929, 1, erasures);
49
+ return rsDecode(codewords, eccLength(entry), GF929, 1, erasures);
55
50
  }
@@ -27,22 +27,8 @@
27
27
  *
28
28
  * Original work. No code from any other barcode implementation.
29
29
  */
30
-
31
- export {
32
- MICROPDF417_VARIANTS,
33
- microPdf417NextRap,
34
- microPdf417VariantByNumber,
35
- microPdf417VariantForCapacity,
36
- microPdf417RapSequence,
37
- microPdf417RowAddress,
38
- validateMicroPdf417Tables,
39
- } from './tables.js';
40
- export {
41
- microPdf417EccLength,
42
- microPdf417Generator,
43
- microPdf417ErrorCorrection,
44
- microPdf417CorrectErrors,
45
- } from './error-correction.js';
30
+ export { MICROPDF417_VARIANTS, microPdf417NextRap, microPdf417VariantByNumber, microPdf417VariantForCapacity, microPdf417RapSequence, microPdf417RowAddress, validateMicroPdf417Tables, } from './tables.js';
31
+ export { microPdf417EccLength, microPdf417Generator, microPdf417ErrorCorrection, microPdf417CorrectErrors, } from './error-correction.js';
46
32
  export { compactMicroPDF417 } from './compaction.js';
47
33
  export { encodeMicroPDF417 } from './encoder.js';
48
34
  export { decodeMicroPDF417 } from './decoder.js';