@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
  * WebGL2 drawing.
33
32
  *
@@ -42,9 +41,7 @@
42
41
  *
43
42
  * @module render/webgl
44
43
  */
45
-
46
44
  import { normalizeOptions, parseColor } from './options.js';
47
-
48
45
  const VERTEX_SHADER = `#version 300 es
49
46
  // A single oversized triangle covers the viewport with no vertex buffer:
50
47
  // three gl_VertexID lookups, no attribute state to set up or leak.
@@ -54,7 +51,6 @@ void main() {
54
51
  vUV = pos;
55
52
  gl_Position = vec4(pos * 2.0 - 1.0, 0.0, 1.0);
56
53
  }`;
57
-
58
54
  const FRAGMENT_SHADER = `#version 300 es
59
55
  precision highp float;
60
56
  in vec2 vUV;
@@ -72,27 +68,30 @@ void main() {
72
68
  float v = texture(uMatrix, texel).r;
73
69
  fragColor = v > 0.5 ? uDark : uLight;
74
70
  }`;
75
-
76
71
  /**
77
72
  * Is WebGL2 usable here?
78
73
  *
79
74
  * @returns {boolean}
80
75
  */
81
76
  export function isWebGL2Available() {
82
- try {
83
- if (typeof document === 'undefined') return false;
84
- if (typeof WebGL2RenderingContext === 'undefined') return false;
85
- const probe = document.createElement('canvas');
86
- const gl = probe.getContext('webgl2');
87
- if (!gl) return false;
88
- const lose = gl.getExtension('WEBGL_lose_context');
89
- if (lose) lose.loseContext();
90
- return true;
91
- } catch {
92
- return false;
93
- }
77
+ try {
78
+ if (typeof document === 'undefined')
79
+ return false;
80
+ if (typeof WebGL2RenderingContext === 'undefined')
81
+ return false;
82
+ const probe = document.createElement('canvas');
83
+ const gl = probe.getContext('webgl2');
84
+ if (!gl)
85
+ return false;
86
+ const lose = gl.getExtension('WEBGL_lose_context');
87
+ if (lose)
88
+ lose.loseContext();
89
+ return true;
90
+ }
91
+ catch {
92
+ return false;
93
+ }
94
94
  }
95
-
96
95
  /**
97
96
  * @param {WebGL2RenderingContext} gl
98
97
  * @param {number} type
@@ -100,17 +99,17 @@ export function isWebGL2Available() {
100
99
  * @returns {WebGLShader | null}
101
100
  */
102
101
  function compile(gl, type, source) {
103
- const shader = gl.createShader(type);
104
- if (!shader) return null;
105
- gl.shaderSource(shader, source);
106
- gl.compileShader(shader);
107
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
108
- gl.deleteShader(shader);
109
- return null;
110
- }
111
- return shader;
102
+ const shader = gl.createShader(type);
103
+ if (!shader)
104
+ return null;
105
+ gl.shaderSource(shader, source);
106
+ gl.compileShader(shader);
107
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
108
+ gl.deleteShader(shader);
109
+ return null;
110
+ }
111
+ return shader;
112
112
  }
113
-
114
113
  /**
115
114
  * Draw a matrix into a canvas with WebGL2.
116
115
  *
@@ -120,87 +119,82 @@ function compile(gl, type, source) {
120
119
  * @returns {boolean} True if it drew; false means the caller should fall back.
121
120
  */
122
121
  export function renderToCanvasWebGL(matrix, canvas, options = {}) {
123
- let gl = null;
124
- let program = null;
125
- let vs = null;
126
- let fs = null;
127
- let texture = null;
128
- let vao = null;
129
-
130
- try {
131
- const opts = normalizeOptions(matrix, options);
132
- const { source, pixelWidth, pixelHeight } = opts;
133
-
134
- gl = canvas.getContext('webgl2', { antialias: false, premultipliedAlpha: false });
135
- if (!gl) return false;
136
-
137
- canvas.width = pixelWidth;
138
- canvas.height = pixelHeight;
139
-
140
- vs = compile(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
141
- fs = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
142
- if (!vs || !fs) return false;
143
-
144
- program = gl.createProgram();
145
- gl.attachShader(program, vs);
146
- gl.attachShader(program, fs);
147
- gl.linkProgram(program);
148
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) return false;
149
- gl.useProgram(program);
150
-
151
- // One byte per module. R8 is the narrowest single-channel format WebGL2
152
- // guarantees as colour-renderable and filterable.
153
- const pixels = new Uint8Array(source.width * source.height);
154
- for (let y = 0; y < source.height; y++) {
155
- for (let x = 0; x < source.width; x++) {
156
- pixels[y * source.width + x] = source.get(x, y) ? 255 : 0;
157
- }
122
+ let gl = null;
123
+ let program = null;
124
+ let vs = null;
125
+ let fs = null;
126
+ let texture = null;
127
+ let vao = null;
128
+ try {
129
+ const opts = normalizeOptions(matrix, options);
130
+ const { source, pixelWidth, pixelHeight } = opts;
131
+ gl = canvas.getContext('webgl2', { antialias: false, premultipliedAlpha: false });
132
+ if (!gl)
133
+ return false;
134
+ canvas.width = pixelWidth;
135
+ canvas.height = pixelHeight;
136
+ vs = compile(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
137
+ fs = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
138
+ if (!vs || !fs)
139
+ return false;
140
+ program = gl.createProgram();
141
+ gl.attachShader(program, vs);
142
+ gl.attachShader(program, fs);
143
+ gl.linkProgram(program);
144
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS))
145
+ return false;
146
+ gl.useProgram(program);
147
+ // One byte per module. R8 is the narrowest single-channel format WebGL2
148
+ // guarantees as colour-renderable and filterable.
149
+ const pixels = new Uint8Array(source.width * source.height);
150
+ for (let y = 0; y < source.height; y++) {
151
+ for (let x = 0; x < source.width; x++) {
152
+ pixels[y * source.width + x] = source.get(x, y) ? 255 : 0;
153
+ }
154
+ }
155
+ texture = gl.createTexture();
156
+ gl.bindTexture(gl.TEXTURE_2D, texture);
157
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
158
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.R8, source.width, source.height, 0, gl.RED, gl.UNSIGNED_BYTE, pixels);
159
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
160
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
161
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
162
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
163
+ const dark = parseColor(opts.dark).map((c) => c / 255);
164
+ const light = parseColor(opts.light).map((c) => c / 255);
165
+ gl.uniform1i(gl.getUniformLocation(program, 'uMatrix'), 0);
166
+ gl.uniform4f(gl.getUniformLocation(program, 'uDark'), dark[0], dark[1], dark[2], dark[3]);
167
+ gl.uniform4f(gl.getUniformLocation(program, 'uLight'), light[0], light[1], light[2], light[3]);
168
+ gl.uniform2f(gl.getUniformLocation(program, 'uSize'), source.width, source.height);
169
+ // WebGL2 still requires a bound VAO even when drawing without attributes.
170
+ vao = gl.createVertexArray();
171
+ gl.bindVertexArray(vao);
172
+ gl.viewport(0, 0, pixelWidth, pixelHeight);
173
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
174
+ return true;
175
+ }
176
+ catch {
177
+ return false;
158
178
  }
159
-
160
- texture = gl.createTexture();
161
- gl.bindTexture(gl.TEXTURE_2D, texture);
162
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
163
- gl.texImage2D(
164
- gl.TEXTURE_2D, 0, gl.R8,
165
- source.width, source.height, 0,
166
- gl.RED, gl.UNSIGNED_BYTE, pixels
167
- );
168
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
169
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
170
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
171
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
172
-
173
- const dark = parseColor(opts.dark).map((c) => c / 255);
174
- const light = parseColor(opts.light).map((c) => c / 255);
175
-
176
- gl.uniform1i(gl.getUniformLocation(program, 'uMatrix'), 0);
177
- gl.uniform4f(gl.getUniformLocation(program, 'uDark'), dark[0], dark[1], dark[2], dark[3]);
178
- gl.uniform4f(gl.getUniformLocation(program, 'uLight'), light[0], light[1], light[2], light[3]);
179
- gl.uniform2f(gl.getUniformLocation(program, 'uSize'), source.width, source.height);
180
-
181
- // WebGL2 still requires a bound VAO even when drawing without attributes.
182
- vao = gl.createVertexArray();
183
- gl.bindVertexArray(vao);
184
-
185
- gl.viewport(0, 0, pixelWidth, pixelHeight);
186
- gl.drawArrays(gl.TRIANGLES, 0, 3);
187
-
188
- return true;
189
- } catch {
190
- return false;
191
- } finally {
192
- // Release eagerly: a page generating many barcodes would otherwise hold
193
- // every texture until GC caught up, and GL memory is not GC's priority.
194
- if (gl) {
195
- try {
196
- if (vao) gl.deleteVertexArray(vao);
197
- if (texture) gl.deleteTexture(texture);
198
- if (program) gl.deleteProgram(program);
199
- if (vs) gl.deleteShader(vs);
200
- if (fs) gl.deleteShader(fs);
201
- } catch {
202
- /* context already gone */
203
- }
179
+ finally {
180
+ // Release eagerly: a page generating many barcodes would otherwise hold
181
+ // every texture until GC caught up, and GL memory is not GC's priority.
182
+ if (gl) {
183
+ try {
184
+ if (vao)
185
+ gl.deleteVertexArray(vao);
186
+ if (texture)
187
+ gl.deleteTexture(texture);
188
+ if (program)
189
+ gl.deleteProgram(program);
190
+ if (vs)
191
+ gl.deleteShader(vs);
192
+ if (fs)
193
+ gl.deleteShader(fs);
194
+ }
195
+ catch {
196
+ /* context already gone */
197
+ }
198
+ }
204
199
  }
205
- }
206
200
  }