zedbar 0.2.4 → 0.3.0

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.
package/README.md CHANGED
@@ -101,6 +101,12 @@ Scans grayscale image data for barcodes and QR codes.
101
101
  ### `ScanOptions`
102
102
 
103
103
  - `retryUndecodedRegions` (`boolean`, default: `true`) - Automatically retry undecoded QR finder regions by cropping and upscaling. Disable to skip the retry and reduce processing time for images that are known to have sufficient resolution.
104
+ - `symbologies` (`string[]`, optional) - Restrict scanning to the listed symbologies. When omitted, every supported symbology is enabled. Names match the `symbolType` field on results — see [Supported Formats](#supported-formats).
105
+
106
+ ```javascript
107
+ // Scan QR codes only
108
+ const results = scanImageBytes(imageBytes, { symbologies: ['QR-Code'] });
109
+ ```
104
110
 
105
111
  ### `DecodeResult`
106
112
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zedbar",
3
3
  "description": "Fast QR code and barcode scanner for Node.js, powered by WebAssembly",
4
- "version": "0.2.4",
4
+ "version": "0.3.0",
5
5
  "license": "LGPL-3.0-or-later",
6
6
  "repository": {
7
7
  "type": "git",
package/zedbar.d.ts CHANGED
@@ -1,14 +1,5 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- /**
4
- * Scan grayscale image data for barcodes and QR codes.
5
- *
6
- * `data` must be an array of 8-bit grayscale pixel values,
7
- * row-major, with dimensions `width` x `height`.
8
- *
9
- * Returns an array of `DecodeResult` objects.
10
- */
11
- export function scanGrayscale(data: Uint8Array, width: number, height: number, options?: ScanOptions | null): DecodeResult[];
12
3
  /**
13
4
  * Scan an encoded image (PNG, JPEG, BMP, WebP) for barcodes and QR codes.
14
5
  *
@@ -21,6 +12,15 @@ export function scanGrayscale(data: Uint8Array, width: number, height: number, o
21
12
  * Returns an array of `DecodeResult` objects.
22
13
  */
23
14
  export function scanImageBytes(bytes: Uint8Array, options?: ScanOptions | null): DecodeResult[];
15
+ /**
16
+ * Scan grayscale image data for barcodes and QR codes.
17
+ *
18
+ * `data` must be an array of 8-bit grayscale pixel values,
19
+ * row-major, with dimensions `width` x `height`.
20
+ *
21
+ * Returns an array of `DecodeResult` objects.
22
+ */
23
+ export function scanGrayscale(data: Uint8Array, width: number, height: number, options?: ScanOptions | null): DecodeResult[];
24
24
  /**
25
25
  * A decoded barcode/QR code result.
26
26
  */
@@ -54,11 +54,14 @@ export class DecodeResult {
54
54
  * All fields are optional and default to sensible values when omitted.
55
55
  *
56
56
  * ```js
57
- * // Use defaults (retry enabled):
57
+ * // Use defaults (every supported symbology, retry enabled):
58
58
  * const results = scanGrayscale(data, width, height);
59
59
  *
60
60
  * // Disable automatic retry of small QR codes:
61
61
  * const results = scanGrayscale(data, width, height, { retryUndecodedRegions: false });
62
+ *
63
+ * // Restrict to QR codes only:
64
+ * const results = scanGrayscale(data, width, height, { symbologies: ["QR-Code"] });
62
65
  * ```
63
66
  */
64
67
  export class ScanOptions {
@@ -68,6 +71,17 @@ export class ScanOptions {
68
71
  * Create a new options object with defaults.
69
72
  */
70
73
  constructor();
74
+ /**
75
+ * Restrict scanning to the listed symbologies. When omitted, every
76
+ * supported symbology is enabled.
77
+ *
78
+ * Names match the `symbolType` field on decode results: `"QR-Code"`,
79
+ * `"SQ-Code"`, `"EAN-13"`, `"EAN-8"`, `"EAN-2"`, `"EAN-5"`,
80
+ * `"UPC-A"`, `"UPC-E"`, `"ISBN-10"`, `"ISBN-13"`, `"I2/5"`,
81
+ * `"DataBar"`, `"DataBar-Exp"`, `"Codabar"`, `"CODE-39"`,
82
+ * `"CODE-93"`, `"CODE-128"`.
83
+ */
84
+ set symbologies(value: string[]);
71
85
  /**
72
86
  * Whether to automatically retry undecoded QR finder regions by
73
87
  * cropping and upscaling them. Default: `true`.
package/zedbar.js CHANGED
@@ -2,6 +2,8 @@
2
2
  let imports = {};
3
3
  imports['__wbindgen_placeholder__'] = module.exports;
4
4
 
5
+ let WASM_VECTOR_LEN = 0;
6
+
5
7
  let cachedUint8ArrayMemory0 = null;
6
8
 
7
9
  function getUint8ArrayMemory0() {
@@ -11,6 +13,71 @@ function getUint8ArrayMemory0() {
11
13
  return cachedUint8ArrayMemory0;
12
14
  }
13
15
 
16
+ const cachedTextEncoder = new TextEncoder();
17
+
18
+ if (!('encodeInto' in cachedTextEncoder)) {
19
+ cachedTextEncoder.encodeInto = function (arg, view) {
20
+ const buf = cachedTextEncoder.encode(arg);
21
+ view.set(buf);
22
+ return {
23
+ read: arg.length,
24
+ written: buf.length
25
+ };
26
+ }
27
+ }
28
+
29
+ function passStringToWasm0(arg, malloc, realloc) {
30
+
31
+ if (realloc === undefined) {
32
+ const buf = cachedTextEncoder.encode(arg);
33
+ const ptr = malloc(buf.length, 1) >>> 0;
34
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
35
+ WASM_VECTOR_LEN = buf.length;
36
+ return ptr;
37
+ }
38
+
39
+ let len = arg.length;
40
+ let ptr = malloc(len, 1) >>> 0;
41
+
42
+ const mem = getUint8ArrayMemory0();
43
+
44
+ let offset = 0;
45
+
46
+ for (; offset < len; offset++) {
47
+ const code = arg.charCodeAt(offset);
48
+ if (code > 0x7F) break;
49
+ mem[ptr + offset] = code;
50
+ }
51
+
52
+ if (offset !== len) {
53
+ if (offset !== 0) {
54
+ arg = arg.slice(offset);
55
+ }
56
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
57
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
58
+ const ret = cachedTextEncoder.encodeInto(arg, view);
59
+
60
+ offset += ret.written;
61
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
62
+ }
63
+
64
+ WASM_VECTOR_LEN = offset;
65
+ return ptr;
66
+ }
67
+
68
+ function isLikeNone(x) {
69
+ return x === undefined || x === null;
70
+ }
71
+
72
+ let cachedDataViewMemory0 = null;
73
+
74
+ function getDataViewMemory0() {
75
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
76
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
77
+ }
78
+ return cachedDataViewMemory0;
79
+ }
80
+
14
81
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
15
82
 
16
83
  cachedTextDecoder.decode();
@@ -24,13 +91,27 @@ function getStringFromWasm0(ptr, len) {
24
91
  return decodeText(ptr, len);
25
92
  }
26
93
 
94
+ function addToExternrefTable0(obj) {
95
+ const idx = wasm.__externref_table_alloc();
96
+ wasm.__wbindgen_export_2.set(idx, obj);
97
+ return idx;
98
+ }
99
+
100
+ function passArrayJsValueToWasm0(array, malloc) {
101
+ const ptr = malloc(array.length * 4, 4) >>> 0;
102
+ for (let i = 0; i < array.length; i++) {
103
+ const add = addToExternrefTable0(array[i]);
104
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
105
+ }
106
+ WASM_VECTOR_LEN = array.length;
107
+ return ptr;
108
+ }
109
+
27
110
  function getArrayU8FromWasm0(ptr, len) {
28
111
  ptr = ptr >>> 0;
29
112
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
30
113
  }
31
114
 
32
- let WASM_VECTOR_LEN = 0;
33
-
34
115
  function passArray8ToWasm0(arg, malloc) {
35
116
  const ptr = malloc(arg.length * 1, 1) >>> 0;
36
117
  getUint8ArrayMemory0().set(arg, ptr / 1);
@@ -38,10 +119,6 @@ function passArray8ToWasm0(arg, malloc) {
38
119
  return ptr;
39
120
  }
40
121
 
41
- function isLikeNone(x) {
42
- return x === undefined || x === null;
43
- }
44
-
45
122
  function _assertClass(instance, klass) {
46
123
  if (!(instance instanceof klass)) {
47
124
  throw new Error(`expected instance of ${klass.name}`);
@@ -49,52 +126,44 @@ function _assertClass(instance, klass) {
49
126
  }
50
127
 
51
128
  function takeFromExternrefTable0(idx) {
52
- const value = wasm.__wbindgen_export_0.get(idx);
129
+ const value = wasm.__wbindgen_export_2.get(idx);
53
130
  wasm.__externref_table_dealloc(idx);
54
131
  return value;
55
132
  }
56
133
 
57
- let cachedDataViewMemory0 = null;
58
-
59
- function getDataViewMemory0() {
60
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
61
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
62
- }
63
- return cachedDataViewMemory0;
64
- }
65
-
66
134
  function getArrayJsValueFromWasm0(ptr, len) {
67
135
  ptr = ptr >>> 0;
68
136
  const mem = getDataViewMemory0();
69
137
  const result = [];
70
138
  for (let i = ptr; i < ptr + 4 * len; i += 4) {
71
- result.push(wasm.__wbindgen_export_0.get(mem.getUint32(i, true)));
139
+ result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true)));
72
140
  }
73
141
  wasm.__externref_drop_slice(ptr, len);
74
142
  return result;
75
143
  }
76
144
  /**
77
- * Scan grayscale image data for barcodes and QR codes.
145
+ * Scan an encoded image (PNG, JPEG, BMP, WebP) for barcodes and QR codes.
78
146
  *
79
- * `data` must be an array of 8-bit grayscale pixel values,
80
- * row-major, with dimensions `width` x `height`.
147
+ * `bytes` should contain the raw bytes of an image file in one of the
148
+ * supported formats: PNG, JPEG, BMP, or WebP.
149
+ *
150
+ * The image will be automatically decoded and converted to grayscale
151
+ * before scanning.
81
152
  *
82
153
  * Returns an array of `DecodeResult` objects.
83
- * @param {Uint8Array} data
84
- * @param {number} width
85
- * @param {number} height
154
+ * @param {Uint8Array} bytes
86
155
  * @param {ScanOptions | null} [options]
87
156
  * @returns {DecodeResult[]}
88
157
  */
89
- exports.scanGrayscale = function(data, width, height, options) {
90
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
158
+ exports.scanImageBytes = function(bytes, options) {
159
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
91
160
  const len0 = WASM_VECTOR_LEN;
92
161
  let ptr1 = 0;
93
162
  if (!isLikeNone(options)) {
94
163
  _assertClass(options, ScanOptions);
95
164
  ptr1 = options.__destroy_into_raw();
96
165
  }
97
- const ret = wasm.scanGrayscale(ptr0, len0, width, height, ptr1);
166
+ const ret = wasm.scanImageBytes(ptr0, len0, ptr1);
98
167
  if (ret[3]) {
99
168
  throw takeFromExternrefTable0(ret[2]);
100
169
  }
@@ -104,28 +173,27 @@ exports.scanGrayscale = function(data, width, height, options) {
104
173
  };
105
174
 
106
175
  /**
107
- * Scan an encoded image (PNG, JPEG, BMP, WebP) for barcodes and QR codes.
108
- *
109
- * `bytes` should contain the raw bytes of an image file in one of the
110
- * supported formats: PNG, JPEG, BMP, or WebP.
176
+ * Scan grayscale image data for barcodes and QR codes.
111
177
  *
112
- * The image will be automatically decoded and converted to grayscale
113
- * before scanning.
178
+ * `data` must be an array of 8-bit grayscale pixel values,
179
+ * row-major, with dimensions `width` x `height`.
114
180
  *
115
181
  * Returns an array of `DecodeResult` objects.
116
- * @param {Uint8Array} bytes
182
+ * @param {Uint8Array} data
183
+ * @param {number} width
184
+ * @param {number} height
117
185
  * @param {ScanOptions | null} [options]
118
186
  * @returns {DecodeResult[]}
119
187
  */
120
- exports.scanImageBytes = function(bytes, options) {
121
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
188
+ exports.scanGrayscale = function(data, width, height, options) {
189
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
122
190
  const len0 = WASM_VECTOR_LEN;
123
191
  let ptr1 = 0;
124
192
  if (!isLikeNone(options)) {
125
193
  _assertClass(options, ScanOptions);
126
194
  ptr1 = options.__destroy_into_raw();
127
195
  }
128
- const ret = wasm.scanImageBytes(ptr0, len0, ptr1);
196
+ const ret = wasm.scanGrayscale(ptr0, len0, width, height, ptr1);
129
197
  if (ret[3]) {
130
198
  throw takeFromExternrefTable0(ret[2]);
131
199
  }
@@ -221,11 +289,14 @@ const ScanOptionsFinalization = (typeof FinalizationRegistry === 'undefined')
221
289
  * All fields are optional and default to sensible values when omitted.
222
290
  *
223
291
  * ```js
224
- * // Use defaults (retry enabled):
292
+ * // Use defaults (every supported symbology, retry enabled):
225
293
  * const results = scanGrayscale(data, width, height);
226
294
  *
227
295
  * // Disable automatic retry of small QR codes:
228
296
  * const results = scanGrayscale(data, width, height, { retryUndecodedRegions: false });
297
+ *
298
+ * // Restrict to QR codes only:
299
+ * const results = scanGrayscale(data, width, height, { symbologies: ["QR-Code"] });
229
300
  * ```
230
301
  */
231
302
  class ScanOptions {
@@ -241,6 +312,22 @@ class ScanOptions {
241
312
  const ptr = this.__destroy_into_raw();
242
313
  wasm.__wbg_scanoptions_free(ptr, 0);
243
314
  }
315
+ /**
316
+ * Restrict scanning to the listed symbologies. When omitted, every
317
+ * supported symbology is enabled.
318
+ *
319
+ * Names match the `symbolType` field on decode results: `"QR-Code"`,
320
+ * `"SQ-Code"`, `"EAN-13"`, `"EAN-8"`, `"EAN-2"`, `"EAN-5"`,
321
+ * `"UPC-A"`, `"UPC-E"`, `"ISBN-10"`, `"ISBN-13"`, `"I2/5"`,
322
+ * `"DataBar"`, `"DataBar-Exp"`, `"Codabar"`, `"CODE-39"`,
323
+ * `"CODE-93"`, `"CODE-128"`.
324
+ * @param {string[]} value
325
+ */
326
+ set symbologies(value) {
327
+ const ptr0 = passArrayJsValueToWasm0(value, wasm.__wbindgen_malloc);
328
+ const len0 = WASM_VECTOR_LEN;
329
+ wasm.scanoptions_set_symbologies(this.__wbg_ptr, ptr0, len0);
330
+ }
244
331
  /**
245
332
  * Whether to automatically retry undecoded QR finder regions by
246
333
  * cropping and upscaling them. Default: `true`.
@@ -268,6 +355,15 @@ exports.__wbg_decoderesult_new = function(arg0) {
268
355
  return ret;
269
356
  };
270
357
 
358
+ exports.__wbg_wbindgenstringget_0f16a6ddddef376f = function(arg0, arg1) {
359
+ const obj = arg1;
360
+ const ret = typeof(obj) === 'string' ? obj : undefined;
361
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
362
+ var len1 = WASM_VECTOR_LEN;
363
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
364
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
365
+ };
366
+
271
367
  exports.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
272
368
  throw new Error(getStringFromWasm0(arg0, arg1));
273
369
  };
@@ -279,7 +375,7 @@ exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
279
375
  };
280
376
 
281
377
  exports.__wbindgen_init_externref_table = function() {
282
- const table = wasm.__wbindgen_export_0;
378
+ const table = wasm.__wbindgen_export_2;
283
379
  const offset = table.grow(4);
284
380
  table.set(0, undefined);
285
381
  table.set(offset + 0, undefined);
package/zedbar_bg.wasm CHANGED
Binary file