@ericblade/quagga2 1.7.7 → 1.8.1

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/lib/quagga.js CHANGED
@@ -546,6 +546,7 @@ var ImageWrapper = /*#__PURE__*/function () {
546
546
  key: "show",
547
547
  value: function show(canvas) {
548
548
  var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1.0;
549
+ console.warn('* imagewrapper show getcontext 2d');
549
550
  var ctx = canvas.getContext('2d');
550
551
  if (!ctx) {
551
552
  throw new Error('Unable to get canvas context');
@@ -574,6 +575,7 @@ var ImageWrapper = /*#__PURE__*/function () {
574
575
  var whiteRgb = [255, 255, 255];
575
576
  var blackRgb = [0, 0, 0];
576
577
  var result = [];
578
+ console.warn('* imagewrapper overlay getcontext 2d');
577
579
  var ctx = canvas.getContext('2d');
578
580
  if (!ctx) {
579
581
  throw new Error('Unable to get canvas context');
@@ -1264,6 +1266,7 @@ function loadImageArray(src, callback) {
1264
1266
  canvas.width = this.width;
1265
1267
  // eslint-disable-next-line no-param-reassign
1266
1268
  canvas.height = this.height;
1269
+ console.warn('* loadImageArray getContext 2d');
1267
1270
  var ctx = canvas.getContext('2d');
1268
1271
  ctx.drawImage(this, 0, 0);
1269
1272
  var array = new Uint8Array(this.width * this.height);
@@ -1922,7 +1925,11 @@ function initCanvas() {
1922
1925
  _canvasContainer.dom.binary = document.createElement('canvas');
1923
1926
  _canvasContainer.dom.binary.className = 'binaryBuffer';
1924
1927
  if (false) {}
1925
- _canvasContainer.ctx.binary = _canvasContainer.dom.binary.getContext('2d');
1928
+ var willReadFrequently = !!_config.willReadFrequently;
1929
+ console.warn('* initCanvas willReadFrequently', willReadFrequently, _config);
1930
+ _canvasContainer.ctx.binary = _canvasContainer.dom.binary.getContext('2d', {
1931
+ willReadFrequently: willReadFrequently
1932
+ });
1926
1933
  _canvasContainer.dom.binary.width = _binaryImageWrapper.size.x;
1927
1934
  _canvasContainer.dom.binary.height = _binaryImageWrapper.size.y;
1928
1935
  }
@@ -10426,21 +10433,32 @@ var QuaggaJSCameraAccess = {
10426
10433
  track = getActiveTrack(); // TODO: should we acquire camera access even if there's no current camera open?
10427
10434
  // TODO: what happens on iOS or another device where torch isn't supported at all? Should we throw an error?
10428
10435
  if (!track) {
10429
- _context2.next = 4;
10436
+ _context2.next = 11;
10430
10437
  break;
10431
10438
  }
10432
- _context2.next = 4;
10439
+ _context2.prev = 2;
10440
+ _context2.next = 5;
10433
10441
  return track.applyConstraints({
10434
10442
  advanced: [{
10435
10443
  torch: false
10436
10444
  }]
10437
10445
  });
10438
- case 4:
10446
+ case 5:
10447
+ _context2.next = 11;
10448
+ break;
10449
+ case 7:
10450
+ _context2.prev = 7;
10451
+ _context2.t0 = _context2["catch"](2);
10452
+ if (_context2.t0 instanceof OverconstrainedError) {
10453
+ console.warn('quagga2/CameraAccess: Torch not supported on this device');
10454
+ }
10455
+ throw _context2.t0;
10456
+ case 11:
10439
10457
  case "end":
10440
10458
  return _context2.stop();
10441
10459
  }
10442
10460
  }
10443
- }, _callee2);
10461
+ }, _callee2, null, [[2, 7]]);
10444
10462
  }))();
10445
10463
  },
10446
10464
  enableTorch: function enableTorch() {
@@ -10453,21 +10471,32 @@ var QuaggaJSCameraAccess = {
10453
10471
  track = getActiveTrack(); // TODO: should we acquire camera access even if there's no current camera open?
10454
10472
  // TODO: what happens on iOS or another device where torch isn't supported at all? Should we throw an error?
10455
10473
  if (!track) {
10456
- _context3.next = 4;
10474
+ _context3.next = 11;
10457
10475
  break;
10458
10476
  }
10459
- _context3.next = 4;
10477
+ _context3.prev = 2;
10478
+ _context3.next = 5;
10460
10479
  return track.applyConstraints({
10461
10480
  advanced: [{
10462
10481
  torch: true
10463
10482
  }]
10464
10483
  });
10465
- case 4:
10484
+ case 5:
10485
+ _context3.next = 11;
10486
+ break;
10487
+ case 7:
10488
+ _context3.prev = 7;
10489
+ _context3.t0 = _context3["catch"](2);
10490
+ if (_context3.t0 instanceof OverconstrainedError) {
10491
+ console.warn('quagga2/CameraAccess: Torch not supported on this device');
10492
+ }
10493
+ throw _context3.t0;
10494
+ case 11:
10466
10495
  case "end":
10467
10496
  return _context3.stop();
10468
10497
  }
10469
10498
  }
10470
- }, _callee3);
10499
+ }, _callee3, null, [[2, 7]]);
10471
10500
  }))();
10472
10501
  }
10473
10502
  };
@@ -10489,7 +10518,9 @@ function passesFilter(codeResult, filter) {
10489
10518
  create: function create(config) {
10490
10519
  var _config$capacity;
10491
10520
  var canvas = document.createElement('canvas');
10492
- var ctx = canvas.getContext('2d');
10521
+ var ctx = canvas.getContext('2d', {
10522
+ willReadFrequently: !!config.willReadFrequently
10523
+ });
10493
10524
  var results = [];
10494
10525
  var capacity = (_config$capacity = config.capacity) !== null && _config$capacity !== void 0 ? _config$capacity : 20;
10495
10526
  var capture = config.capture === true;
@@ -10910,18 +10941,26 @@ function findOrCreateCanvas(selector, className) {
10910
10941
  }
10911
10942
  return canvas;
10912
10943
  }
10913
- function getCanvasAndContext(selector, className) {
10944
+ function getCanvasAndContext(selector, className, options) {
10914
10945
  var canvas = findOrCreateCanvas(selector, className);
10915
- var context = canvas.getContext('2d');
10946
+ console.warn('* initCanvas getCanvasAndContext');
10947
+ var context = canvas.getContext('2d', {
10948
+ willReadFrequently: options.willReadFrequently
10949
+ });
10916
10950
  return {
10917
10951
  canvas: canvas,
10918
10952
  context: context
10919
10953
  };
10920
10954
  }
10921
- function initCanvases(canvasSize) {
10955
+ function initCanvases(canvasSize, _ref) {
10956
+ var willReadFrequently = _ref.willReadFrequently;
10922
10957
  if (typeof document !== 'undefined') {
10923
- var image = getCanvasAndContext('canvas.imgBuffer', 'imgBuffer');
10924
- var overlay = getCanvasAndContext('canvas.drawingBuffer', 'drawingBuffer');
10958
+ var image = getCanvasAndContext('canvas.imgBuffer', 'imgBuffer', {
10959
+ willReadFrequently: willReadFrequently
10960
+ });
10961
+ var overlay = getCanvasAndContext('canvas.drawingBuffer', 'drawingBuffer', {
10962
+ willReadFrequently: willReadFrequently
10963
+ });
10925
10964
 
10926
10965
  // eslint-disable-next-line no-multi-assign
10927
10966
  image.canvas.width = overlay.canvas.width = canvasSize.x;
@@ -10941,11 +10980,13 @@ function initCanvases(canvasSize) {
10941
10980
  return null;
10942
10981
  }
10943
10982
  function initCanvas_initCanvas(context) {
10944
- var _context$config, _context$config$input, _context$config2, _context$config2$inpu;
10983
+ var _context$config, _context$config$input, _context$config2, _context$config2$inpu, _context$config3, _context$config3$inpu;
10945
10984
  var viewport = getViewPort_getViewPort(context === null || context === void 0 ? void 0 : (_context$config = context.config) === null || _context$config === void 0 ? void 0 : (_context$config$input = _context$config.inputStream) === null || _context$config$input === void 0 ? void 0 : _context$config$input.target);
10946
10985
  var type = context === null || context === void 0 ? void 0 : (_context$config2 = context.config) === null || _context$config2 === void 0 ? void 0 : (_context$config2$inpu = _context$config2.inputStream) === null || _context$config2$inpu === void 0 ? void 0 : _context$config2$inpu.type;
10947
10986
  if (!type) return null;
10948
- var container = initCanvases(context.inputStream.getCanvasSize());
10987
+ var container = initCanvases(context.inputStream.getCanvasSize(), {
10988
+ willReadFrequently: !!(context !== null && context !== void 0 && (_context$config3 = context.config) !== null && _context$config3 !== void 0 && (_context$config3$inpu = _context$config3.inputStream) !== null && _context$config3$inpu !== void 0 && _context$config3$inpu.willReadFrequently)
10989
+ });
10949
10990
  if (!container) return {
10950
10991
  dom: {
10951
10992
  image: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ericblade/quagga2",
3
- "version": "1.7.7",
3
+ "version": "1.8.1",
4
4
  "description": "An advanced barcode-scanner written in JavaScript",
5
5
  "main": "lib/quagga.js",
6
6
  "types": "type-definitions/quagga.d.ts",
@@ -76,6 +76,7 @@
76
76
  "build:dev": "npx cross-env NODE_ENV=development BUILD_ENV=development webpack --config configs/webpack.config.js",
77
77
  "build:prod": "npx cross-env NODE_ENV=production BUILD_ENV=production webpack --config configs/webpack.config.min.js",
78
78
  "build:node": "npx cross-env NODE_ENV=production BABEL_ENV=commonjs BUILD_ENV=node webpack --config configs/webpack.node.config.js",
79
+ "build-new": "npx cross-env NODE_OPTIONS=--openssl-legacy-provider npm run build",
79
80
  "build": "npm run check-types && npm run build:dev && npm run build:prod && npm run build:node",
80
81
  "watch": "npx cross-env BUILD_ENV=development webpack --watch",
81
82
  "lint": "eslint src",
@@ -119,7 +119,7 @@ export interface BarcodeReaderConfig {
119
119
 
120
120
  export enum BarcodeDirection {
121
121
  Forward = 1,
122
- Reverse = -1
122
+ Reverse = -1,
123
123
  }
124
124
  type BarcodeFormat = string;
125
125
 
@@ -129,11 +129,11 @@ export interface BarcodeCorrection {
129
129
  }
130
130
 
131
131
  export interface BarcodePosition {
132
- start: number;
133
- startCounter?: number;
134
132
  end: number;
135
133
  endCounter?: number;
136
134
  error?: number;
135
+ start: number;
136
+ startCounter?: number;
137
137
  }
138
138
 
139
139
  export interface BarcodeInfo extends BarcodePosition {
@@ -156,18 +156,18 @@ export interface Barcode {
156
156
  }
157
157
 
158
158
  export interface ThresholdSize {
159
- size: number;
160
159
  counts: number;
161
- min: number;
162
160
  max: number;
161
+ min: number;
162
+ size: number;
163
163
  }
164
164
 
165
165
  export interface Threshold {
166
- space: {
166
+ bar: {
167
167
  narrow: ThresholdSize;
168
168
  wide: ThresholdSize;
169
169
  };
170
- bar: {
170
+ space: {
171
171
  narrow: ThresholdSize;
172
172
  wide: ThresholdSize;
173
173
  };
@@ -176,14 +176,17 @@ export interface Threshold {
176
176
  export declare module Readers {
177
177
  export abstract class BarcodeReader {
178
178
  _row: Array<number>;
179
+
179
180
  SINGLE_CODE_ERROR: number;
181
+
180
182
  FORMAT: BarcodeFormat;
183
+
181
184
  CONFIG_KEYS: BarcodeReaderConfig;
182
185
 
183
186
  static get Exception(): {
184
- StartNotFoundException: string;
185
187
  CodeNotFoundException: string;
186
188
  PatternNotFoundException: string;
189
+ StartNotFoundException: string;
187
190
  };
188
191
 
189
192
  constructor(config: BarcodeReaderConfig, supplements?: Array<BarcodeReader>);
@@ -209,7 +212,9 @@ export declare module Readers {
209
212
 
210
213
  export class TwoOfFiveReader extends BarcodeReader {
211
214
  FORMAT: string;
215
+
212
216
  SINGLE_CODE_ERROR: number;
217
+
213
218
  AVG_CODE_ERROR: number;
214
219
 
215
220
  decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
@@ -259,17 +264,29 @@ export declare module Readers {
259
264
 
260
265
  export class Code128Reader extends BarcodeReader {
261
266
  CODE_SHIFT: number;
267
+
262
268
  CODE_C: number;
269
+
263
270
  CODE_B: number;
271
+
264
272
  CODE_A: number;
273
+
265
274
  START_CODE_A: number;
275
+
266
276
  START_CODE_B: number;
277
+
267
278
  START_CODE_C: number;
279
+
268
280
  STOP_CODE: number;
281
+
269
282
  CODE_PATTERN: number[][];
283
+
270
284
  SINGLE_CODE_ERROR: number;
285
+
271
286
  AVG_CODE_ERROR: number;
287
+
272
288
  FORMAT: string;
289
+
273
290
  MODULE_INDICES: {
274
291
  bar: number[];
275
292
  space: number[];
@@ -288,16 +305,6 @@ export declare module Readers {
288
305
  protected _verifyTrailingWhitespace(endInfo: BarcodeInfo): BarcodeInfo | null;
289
306
  }
290
307
 
291
- export class Code32Reader extends Code39Reader {
292
- FORMAT: string;
293
-
294
- decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
295
-
296
- protected _decodeCode32(code: string): string | null;
297
-
298
- protected _checkChecksum(code: string): boolean;
299
- }
300
-
301
308
  export class Code39Reader extends BarcodeReader {
302
309
  FORMAT: string;
303
310
 
@@ -314,6 +321,16 @@ export declare module Readers {
314
321
  protected _verifyTrailingWhitespace(lastStart: number, nextStart: number, counters: Uint16Array): boolean;
315
322
  }
316
323
 
324
+ export class Code32Reader extends Code39Reader {
325
+ FORMAT: string;
326
+
327
+ decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
328
+
329
+ protected _decodeCode32(code: string): string | null;
330
+
331
+ protected _checkChecksum(code: string): boolean;
332
+ }
333
+
317
334
  export class Code39VINReader extends Code39Reader {
318
335
  FORMAT: string;
319
336
 
@@ -342,24 +359,6 @@ export declare module Readers {
342
359
  protected _verifyChecksums(charArray: Array<string>): boolean;
343
360
  }
344
361
 
345
- export class EAN2Reader extends EANReader {
346
- FORMAT: string;
347
-
348
- decode(row?: Array<number>, start?: number): Barcode | null;
349
- }
350
-
351
- export class EAN5Reader extends EANReader {
352
- FORMAT: string;
353
-
354
- decode(row?: Array<number>, start?: number): Barcode | null;
355
- }
356
-
357
- export class EAN8Reader extends EANReader {
358
- FORMAT: string;
359
-
360
- protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
361
- }
362
-
363
362
  export class EANReader extends BarcodeReader {
364
363
  FORMAT: string;
365
364
  SINGLE_CODE_ERROR: number;
@@ -384,13 +383,37 @@ export declare module Readers {
384
383
  protected _checksum(result: Array<number>): boolean;
385
384
  }
386
385
 
386
+ export class EAN2Reader extends EANReader {
387
+ FORMAT: string;
388
+
389
+ decode(row?: Array<number>, start?: number): Barcode | null;
390
+ }
391
+
392
+ export class EAN5Reader extends EANReader {
393
+ FORMAT: string;
394
+
395
+ decode(row?: Array<number>, start?: number): Barcode | null;
396
+ }
397
+
398
+ export class EAN8Reader extends EANReader {
399
+ FORMAT: string;
400
+
401
+ protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
402
+ }
403
+
387
404
  export class I2of5Reader extends BarcodeReader {
388
405
  SINGLE_CODE_ERROR: number;
406
+
389
407
  AVG_CODE_ERROR: number;
408
+
390
409
  START_PATTERN: number[];
410
+
391
411
  STOP_PATTERN: number[];
412
+
392
413
  CODE_PATTERN: number[][];
414
+
393
415
  MAX_CORRECTION_FACTOR: number;
416
+
394
417
  FORMAT: string;
395
418
 
396
419
  constructor(opts: BarcodeReaderConfig);
@@ -418,7 +441,9 @@ export declare module Readers {
418
441
 
419
442
  export class UPCEReader extends EANReader {
420
443
  CODE_FREQUENCY: number[][];
444
+
421
445
  STOP_PATTERN: number[];
446
+
422
447
  FORMAT: string;
423
448
 
424
449
  protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
@@ -678,6 +703,7 @@ export interface QuaggaJSResultCollector {
678
703
  create?(param: QuaggaJSResultCollector): QuaggaJSResultCollector;
679
704
 
680
705
  getResults?(): QuaggaJSCodeResult[];
706
+ willReadFrequently?: boolean;
681
707
  }
682
708
 
683
709
  /**
@@ -768,6 +794,13 @@ export interface QuaggaJSConfigObject {
768
794
  */
769
795
  type?: InputStreamType;
770
796
 
797
+ /**
798
+ * Use canvas.getContext('2d', { willReadFrequently: true }) for browser frame grabber operations
799
+ * @default false
800
+ * ... defaulting false because historically this wasn't an option, so i don't want to change behavior
801
+ */
802
+ willReadFrequently?: boolean;
803
+
771
804
  target?: Element | string;
772
805
 
773
806
  constraints?: MediaTrackConstraints;
@@ -881,7 +914,7 @@ export interface QuaggaJSConfigObject {
881
914
  * Available values: x-small, small, medium, large, x-large
882
915
  */
883
916
  patchSize?: string;
884
-
917
+ willReadFrequently?: boolean;
885
918
  debug?: {
886
919
  /**
887
920
  * @default false
@@ -939,16 +972,16 @@ export interface QuaggaJSConfigObject {
939
972
  }
940
973
 
941
974
  export interface QuaggaJSReaderConfig {
942
- format: string;
943
975
  config: {
944
976
  supplements: string[];
945
977
  };
978
+ format: string;
946
979
  }
947
980
 
948
981
  export interface MediaTrackConstraintsWithDeprecated extends MediaTrackConstraints {
982
+ facing?: string;
949
983
  maxAspectRatio?: number; // i don't see this in the documentation anywhere, but it's in the original test suite...
950
984
  minAspectRatio?: number;
951
- facing?: string;
952
985
  }
953
986
 
954
987
  export type TypedArrayConstructor =