@ericblade/quagga2 1.5.0 → 1.7.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.
@@ -1,969 +1,972 @@
1
- /* eslint-disable max-classes-per-file */
2
- // Type definitions for QuaggaJS v0.12.1 (2017-10-19)
3
- // Project: http://serratus.github.io/quaggaJS/
4
- // Definitions by: Cam Birch, Peter Horwood aka Madman Pierre, Dan Manastireanu <https://github.com/danmana>
5
-
6
- // import SubImage from '../src/common/subImage';
7
- // import ImageWrapper from '../src/common/image_wrapper';
8
- // export { SubImage, ImageWrapper };
9
-
10
- declare const Quagga: QuaggaJSStatic;
11
- export default Quagga;
12
-
13
- // There are many different spots inside Quagga where we refer to an X/Y position of something, but it has entirely different
14
- // contextual meaning. This allows us to create a type that is branded by name, and therefore these variables cannot be directly
15
- // mixed up with each other, without explicitly forcing it to happen. Good.
16
- export interface XYObject<T extends string> {
17
- x: number;
18
- y: number;
19
- type: T;
20
- }
21
-
22
- // TODO: fill this in from cv_utils#imageRef
23
- export type ImageRef = XYObject<'ImageRef'>;
24
-
25
- export type XYSize = XYObject<'XYSize'>;
26
-
27
- export type Point = XYObject<'Point'>;
28
-
29
- export type SparseImageWrapper = {
30
- data: TypedArray | Array<number> | null;
31
- size: XYSize;
32
- };
33
-
34
- export type WrapperIndexMapping = {
35
- x: Array<number>;
36
- y: Array<number>;
37
- };
38
-
39
- // eslint-disable-next-line @typescript-eslint/class-name-casing
40
- export type Moment = {
41
- m00: number;
42
- m01: number;
43
- m10: number;
44
- m11: number;
45
- m02: number;
46
- m20: number;
47
- theta: number;
48
- rad: number;
49
- vec?: Array<number>;
50
- };
51
-
52
- export class ImageWrapper {
53
- data: TypedArray | Array<number>;
54
-
55
- size: XYSize;
56
-
57
- indexMapping?: WrapperIndexMapping;
58
-
59
- constructor(
60
- size: XYSize,
61
- data?: TypedArray | Array<number>,
62
- ArrayType?: TypedArrayConstructor | ArrayConstructor,
63
- initialize?: boolean
64
- );
65
-
66
- inImageWithBorder(imgRef: ImageRef, border: number): boolean;
67
-
68
- subImageAsCopy(imageWrapper: ImageWrapper, from: XYSize): ImageWrapper;
69
-
70
- get(x: number, y: number): number;
71
-
72
- getSafe(x: number, y: number): number;
73
-
74
- set(x: number, y: number, value: number): ImageWrapper;
75
-
76
- zeroBorder(): ImageWrapper;
77
-
78
- moments(labelCount: any): Array<Moment>;
79
-
80
- getAsRGBA(scale?: number): Uint8ClampedArray;
81
-
82
- show(canvas: HTMLCanvasElement, scale?: number): void;
83
-
84
- overlay(canvas: HTMLCanvasElement, scale: number, from: XYSize): void;
85
- }
86
-
87
- export class SubImage {
88
- I: ImageWrapper | SparseImageWrapper;
89
-
90
- data: ImageWrapper['data'];
91
-
92
- originalSize: ImageRef;
93
-
94
- from: ImageRef;
95
-
96
- size: ImageRef;
97
-
98
- constructor(from: ImageRef, size: ImageRef, I: SparseImageWrapper);
99
-
100
- get(x: number, y: number): number;
101
-
102
- show(canvas: HTMLCanvasElement, scale: number): void;
103
-
104
- updateData(image: ImageWrapper): void;
105
-
106
- updateFrom(from: ImageRef): void;
107
- }
108
-
109
- export type QuaggaImageData = Array<number>;
110
-
111
- export type BarcodeReaderType = string;
112
-
113
- export interface BarcodeReaderConfig {
114
- normalizeBarSpaceWidth?: boolean,
115
- supplements?: Array<BarcodeReaderType>,
116
- }
117
-
118
- export enum BarcodeDirection {
119
- Forward = 1,
120
- Reverse = -1
121
- }
122
- type BarcodeFormat = string;
123
-
124
- export interface BarcodeCorrection {
125
- bar: number;
126
- space: number;
127
- }
128
-
129
- export interface BarcodePosition {
130
- start: number;
131
- startCounter?: number;
132
- end: number;
133
- endCounter?: number;
134
- error?: number;
135
- }
136
-
137
- export interface BarcodeInfo extends BarcodePosition {
138
- code: number;
139
- correction?: BarcodeCorrection;
140
- }
141
-
142
- export interface Barcode {
143
- code: string;
144
- codeset?: number;
145
- correction?: BarcodeCorrection;
146
- decodedCodes?: Array<string | BarcodeInfo | BarcodePosition>;
147
- direction?: BarcodeDirection;
148
- end: number;
149
- endInfo?: BarcodePosition;
150
- format: BarcodeFormat;
151
- start: number;
152
- startInfo: BarcodePosition;
153
- supplement?: Barcode;
154
- }
155
-
156
- export interface ThresholdSize {
157
- size: number;
158
- counts: number;
159
- min: number;
160
- max: number;
161
- }
162
-
163
- export interface Threshold {
164
- space: {
165
- narrow: ThresholdSize;
166
- wide: ThresholdSize;
167
- };
168
- bar: {
169
- narrow: ThresholdSize;
170
- wide: ThresholdSize;
171
- };
172
- }
173
-
174
- export declare module Readers {
175
- export abstract class BarcodeReader {
176
- _row: Array<number>;
177
- SINGLE_CODE_ERROR: number;
178
- FORMAT: BarcodeFormat;
179
- CONFIG_KEYS: BarcodeReaderConfig;
180
-
181
- static get Exception(): {
182
- StartNotFoundException: string;
183
- CodeNotFoundException: string;
184
- PatternNotFoundException: string;
185
- };
186
-
187
- constructor(config: BarcodeReaderConfig, supplements?: Array<BarcodeReader>);
188
-
189
- abstract decode(row?: Array<number>, start?: BarcodePosition | number): Barcode | null;
190
-
191
- decodePattern(pattern: Array<number>): Barcode | null;
192
-
193
- protected _nextUnset(line: ReadonlyArray<number>, start?: number): number;
194
-
195
- protected _matchPattern(counter: ReadonlyArray<number>, code: ReadonlyArray<number>, maxSingleError?: number): number;
196
-
197
- protected _nextSet(line: ReadonlyArray<number>, offset?: number): number;
198
-
199
- protected _correctBars(counter: Array<number>, correction: number, indices: Array<number>): void;
200
-
201
- protected _matchRange(start: number, end: number, value: number): boolean;
202
-
203
- protected _fillCounters(offset?: number, end?: number, isWhite?: boolean): number[];
204
-
205
- protected _toCounters(start: number, counters: Uint16Array | Array<number>): number[] | Uint16Array;
206
- }
207
-
208
- export class TwoOfFiveReader extends BarcodeReader {
209
- FORMAT: string;
210
- SINGLE_CODE_ERROR: number;
211
- AVG_CODE_ERROR: number;
212
-
213
- decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
214
-
215
- protected _findPattern(pattern: ReadonlyArray<number>, offset: number, isWhite?: boolean, tryHarder?: boolean): BarcodeInfo | null;
216
-
217
- protected _findStart(): BarcodePosition | null;
218
-
219
- protected _verifyTrailingWhitespace(endInfo: BarcodeInfo): BarcodePosition | null;
220
-
221
- protected _findEnd(): BarcodePosition | null;
222
-
223
- protected _verifyCounterLength(counters: Array<number>): boolean;
224
-
225
- protected _decodeCode(counter: ReadonlyArray<number>): BarcodeInfo | null;
226
-
227
- protected _decodePayload(counters: ReadonlyArray<number>, result: Array<string>, decodedCodes: Array<BarcodeInfo | BarcodePosition>): BarcodeInfo | null;
228
- }
229
-
230
- export class NewCodabarReader extends BarcodeReader {
231
- FORMAT: string;
232
-
233
- decode(row?: Array<number>, start?: BarcodePosition | number | null): Barcode | null;
234
-
235
- protected _computeAlternatingThreshold(offset: number, end: number): number;
236
-
237
- protected _toPattern(offset: number): number;
238
-
239
- protected _isStartEnd(pattern: number): boolean;
240
-
241
- protected _sumCounters(start: number, end: number): number;
242
-
243
- protected _findStart(): BarcodePosition | null;
244
-
245
- protected _patternToChar(pattern: number): string | null;
246
-
247
- protected _calculatePatternLength(offset: number): number;
248
-
249
- protected _verifyWhitespace(startCounter: number, endCounter: number): boolean;
250
-
251
- protected _charToPattern(char: string): number;
252
-
253
- protected _thresholdResultPattern(result: ReadonlyArray<string>, startCounter: number): Threshold;
254
-
255
- protected _validateResult(result: ReadonlyArray<string>, startCounter: number): boolean;
256
- }
257
-
258
- export class Code128Reader extends BarcodeReader {
259
- CODE_SHIFT: number;
260
- CODE_C: number;
261
- CODE_B: number;
262
- CODE_A: number;
263
- START_CODE_A: number;
264
- START_CODE_B: number;
265
- START_CODE_C: number;
266
- STOP_CODE: number;
267
- CODE_PATTERN: number[][];
268
- SINGLE_CODE_ERROR: number;
269
- AVG_CODE_ERROR: number;
270
- FORMAT: string;
271
- MODULE_INDICES: {
272
- bar: number[];
273
- space: number[];
274
- };
275
-
276
- decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
277
-
278
- calculateCorrection(expected: ReadonlyArray<number>, normalized: ReadonlyArray<number>, indices: ReadonlyArray<number>): number;
279
-
280
- protected _decodeCode(start: number, correction?: BarcodeCorrection): BarcodeInfo | null;
281
-
282
- protected _correct(counter: Array<number>, correction: BarcodeCorrection): void;
283
-
284
- protected _findStart(): BarcodeInfo | null;
285
-
286
- protected _verifyTrailingWhitespace(endInfo: BarcodeInfo): BarcodeInfo | null;
287
- }
288
-
289
- export class Code32Reader extends Code39Reader {
290
- FORMAT: string;
291
-
292
- decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
293
-
294
- protected _decodeCode32(code: string): string | null;
295
-
296
- protected _checkChecksum(code: string): boolean;
297
- }
298
-
299
- export class Code39Reader extends BarcodeReader {
300
- FORMAT: string;
301
-
302
- decode(row?: Array<number>, start?: BarcodePosition | number | null): Barcode | null;
303
-
304
- protected _findStart(): BarcodePosition | null;
305
-
306
- protected _toPattern(counters: Uint16Array): number;
307
-
308
- protected _findNextWidth(counters: Uint16Array, current: number): number;
309
-
310
- protected _patternToChar(pattern: number): string | null;
311
-
312
- protected _verifyTrailingWhitespace(lastStart: number, nextStart: number, counters: Uint16Array): boolean;
313
- }
314
-
315
- export class Code39VINReader extends Code39Reader {
316
- FORMAT: string;
317
-
318
- decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
319
-
320
- protected _checkChecksum(code: string): boolean;
321
- }
322
-
323
- export class Code93Reader extends BarcodeReader {
324
- FORMAT: string;
325
-
326
- decode(row?: Array<number>, start?: BarcodePosition | number | null): Barcode | null;
327
-
328
- protected _patternToChar(pattern: number): string | null;
329
-
330
- protected _toPattern(counters: Uint16Array): number;
331
-
332
- protected _findStart(): BarcodePosition | null;
333
-
334
- protected _verifyEnd(lastStart: number, nextStart: number): boolean;
335
-
336
- protected _decodeExtended(charArray: Array<string>): string[] | null;
337
-
338
- protected _matchCheckChar(charArray: Array<string>, index: number, maxWeight: number): boolean;
339
-
340
- protected _verifyChecksums(charArray: Array<string>): boolean;
341
- }
342
-
343
- export class EAN2Reader extends EANReader {
344
- FORMAT: string;
345
-
346
- decode(row?: Array<number>, start?: number): Barcode | null;
347
- }
348
-
349
- export class EAN5Reader extends EANReader {
350
- FORMAT: string;
351
-
352
- decode(row?: Array<number>, start?: number): Barcode | null;
353
- }
354
-
355
- export class EAN8Reader extends EANReader {
356
- FORMAT: string;
357
-
358
- protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
359
- }
360
-
361
- export class EANReader extends BarcodeReader {
362
- FORMAT: string;
363
- SINGLE_CODE_ERROR: number;
364
- STOP_PATTERN: number[];
365
-
366
- constructor(config?: BarcodeReaderConfig, supplements?: Array<BarcodeReader>);
367
-
368
- decode(row?: Array<number>, start?: BarcodePosition | number): Barcode | null;
369
-
370
- protected _findPattern(pattern: ReadonlyArray<number>, offset: number, isWhite: boolean, tryHarder: boolean): BarcodePosition | null;
371
-
372
- protected _decodeCode(start: number, coderange?: number): BarcodeInfo | null;
373
-
374
- protected _findStart(): BarcodePosition | null;
375
-
376
- protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
377
-
378
- protected _verifyTrailingWhitespace(endInfo: BarcodePosition): BarcodePosition | null;
379
-
380
- protected _findEnd(offset: number, isWhite: boolean): BarcodePosition | null;
381
-
382
- protected _checksum(result: Array<number>): boolean;
383
- }
384
-
385
- export class I2of5Reader extends BarcodeReader {
386
- SINGLE_CODE_ERROR: number;
387
- AVG_CODE_ERROR: number;
388
- START_PATTERN: number[];
389
- STOP_PATTERN: number[];
390
- CODE_PATTERN: number[][];
391
- MAX_CORRECTION_FACTOR: number;
392
- FORMAT: string;
393
-
394
- constructor(opts: BarcodeReaderConfig);
395
-
396
- decode(row?: Array<number>, start?: BarcodePosition | number): Barcode | null;
397
-
398
- protected _matchPattern(counter: Array<number>, code: ReadonlyArray<number>): number;
399
-
400
- protected _findPattern(pattern: ReadonlyArray<number>, offset?: number, isWhite?: boolean, tryHarder?: boolean): BarcodePosition | null;
401
-
402
- protected _findStart(): BarcodePosition | null;
403
-
404
- protected _verifyTrailingWhitespace(endInfo: BarcodePosition): BarcodePosition | null;
405
-
406
- protected _findEnd(): BarcodePosition | null;
407
-
408
- protected _decodePair(counterPair: Array<Array<number>>): Array<BarcodeInfo> | null;
409
-
410
- protected _decodeCode(counter: Array<number>): BarcodeInfo | null;
411
-
412
- protected _decodePayload(counters: ReadonlyArray<number>, result: Array<string>, decodedCodes: Array<BarcodeInfo | BarcodePosition>): Array<BarcodeInfo> | null;
413
-
414
- protected _verifyCounterLength(counters: Array<number>): boolean;
415
- }
416
-
417
- export class UPCEReader extends EANReader {
418
- CODE_FREQUENCY: number[][];
419
- STOP_PATTERN: number[];
420
- FORMAT: string;
421
-
422
- protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
423
-
424
- protected _determineParity(codeFrequency: number, result: Array<number>): boolean;
425
-
426
- protected _convertToUPCA(result: Array<number>): number[];
427
-
428
- protected _checksum(result: Array<number>): boolean;
429
-
430
- protected _findEnd(offset: number, isWhite: boolean): BarcodePosition | null;
431
-
432
- protected _verifyTrailingWhitespace(endInfo: BarcodePosition): BarcodePosition | null;
433
- }
434
-
435
- export class UPCReader extends EANReader {
436
- FORMAT: string;
437
-
438
- decode(row?: Array<number>, start?: BarcodePosition | number): Barcode | null;
439
- }
440
-
441
- }
442
-
443
- export interface QuaggaJSStatic {
444
- /**
445
- * This method initializes the library for a given
446
- * configuration config (see below) and invokes the callback when Quagga is
447
- * ready to start. The initialization process also requests for camera
448
- * access if real-time detection is configured.
449
- */
450
- init(
451
- config: QuaggaJSConfigObject,
452
- callback?: (err: any) => void
453
- ): Promise<void>;
454
-
455
- init(
456
- config: QuaggaJSConfigObject,
457
- callback: (err: any) => void,
458
- imageWrapper: ImageWrapper,
459
- ): Promise<void>;
460
-
461
- /**
462
- * When the library is initialized, the start()
463
- * method starts the video-stream and begins locating and decoding the
464
- * images.
465
- */
466
- start(): void;
467
-
468
- /**
469
- * If the decoder is currently running, after calling
470
- * stop() the decoder does not process any more images.
471
- * Additionally, if a camera-stream was requested upon initialization,
472
- * this operation also disconnects the camera.
473
- */
474
- stop(): Promise<void>;
475
-
476
- /**
477
- * Pauses processing, but does not release any handlers
478
- */
479
- pause(): void;
480
-
481
- /**
482
- * This method registers a callback(data) function that is
483
- * called for each frame after the processing is done. The data object
484
- * contains detailed information about the success/failure of the operation.
485
- * The output varies, depending whether the detection and/or decoding were
486
- * successful or not.
487
- */
488
- onProcessed(callback: QuaggaJSResultCallbackFunction): void;
489
-
490
- /**
491
- * Removes a callback that was previously registered with @see onProcessed
492
- */
493
- offProcessed(callback?: QuaggaJSResultCallbackFunction): void;
494
-
495
- /**
496
- * Registers a callback(data) function which is triggered whenever a
497
- * barcode- pattern has been located and decoded successfully. The passed
498
- * data object contains information about the decoding process including the
499
- * detected code which can be obtained by calling data.codeResult.code.
500
- */
501
- onDetected(callback: QuaggaJSResultCallbackFunction): void;
502
-
503
- /**
504
- * Removes a callback that was previously registered with @see onDetected
505
- */
506
- offDetected(callback?: QuaggaJSResultCallbackFunction): void;
507
-
508
- ResultCollector: QuaggaJSResultCollector;
509
- registerResultCollector(resultCollector: QuaggaJSResultCollector): void;
510
- setReaders(readers: (QuaggaJSReaderConfig | string)[]): void;
511
- registerReader(name: string, reader: object): void;
512
-
513
- /**
514
- * In contrast to the calls described
515
- * above, this method does not rely on getUserMedia and operates on a single
516
- * image instead. The provided callback is the same as in onDetected and
517
- * contains the result data object.
518
- */
519
- decodeSingle(
520
- config: QuaggaJSConfigObject,
521
- resultCallback?: QuaggaJSResultCallbackFunction
522
- ): Promise<QuaggaJSResultObject>;
523
-
524
- /**
525
- * Constructs used for debugging purposes
526
- */
527
- ImageDebug: {
528
- drawPath: QuaggaJSDebugDrawPath;
529
- drawRect: QuaggaJSDebugDrawRect;
530
- };
531
- ImageWrapper: ImageWrapper;
532
-
533
- /**
534
- * an object Quagga uses for drawing and processing, useful for calling code
535
- * when debugging
536
- */
537
- canvas: {
538
- ctx: {
539
- image: CanvasRenderingContext2D;
540
- overlay: CanvasRenderingContext2D;
541
- };
542
- dom: {
543
- image: HTMLCanvasElement;
544
- overlay: HTMLCanvasElement;
545
- };
546
- };
547
-
548
- CameraAccess: QuaggaJSCameraAccess;
549
- }
550
-
551
- /**
552
- * Used for accessing information about the active stream track and available video devices.
553
- */
554
- export interface QuaggaJSCameraAccess {
555
- requestedVideoElement: HTMLVideoElement | null,
556
- request(video: HTMLVideoElement | null, videoConstraints?: MediaTrackConstraintsWithDeprecated): Promise<void> | never;
557
-
558
- release(): Promise<void>;
559
-
560
- enumerateVideoDevices(): Promise<MediaDeviceInfo[]> | never;
561
-
562
- getActiveStreamLabel(): string;
563
-
564
- getActiveTrack(): MediaStreamTrack | null;
565
- }
566
-
567
- /**
568
- * Called whenever an item is detected or a process step has been completed.
569
- */
570
- export interface QuaggaJSResultCallbackFunction {
571
- (
572
- data: QuaggaJSResultObject
573
- ): void;
574
- }
575
-
576
- /**
577
- * Called to draw debugging path. The path is an array of array of 2 numbers.
578
- * The def.x specifies element in the sub array is the x, and similarly the def.y
579
- * defines the y.
580
- * typical values 0, 1, 'x', 'y'
581
- */
582
- export interface QuaggaJSDebugDrawPath {
583
- (
584
- path: any[],
585
- def: QuaggaJSxyDef,
586
- ctx: CanvasRenderingContext2D,
587
- style: QuaggaJSStyle
588
- ): void;
589
- }
590
-
591
- /**
592
- * Called to draw debugging Rectangle
593
- */
594
- export interface QuaggaJSDebugDrawRect {
595
- (
596
- pos: any[],
597
- size: QuaggaJSRectSize,
598
- ctx: CanvasRenderingContext2D,
599
- style: QuaggaJSStyle
600
- ): void;
601
- }
602
-
603
- /**
604
- * an object with an x and a y value, the x and y specify which element in
605
- * another array is the x or y value.
606
- * typical values 0, 1, 'x', 'y'
607
- */
608
- // TODO: remove QuaggaJSxyDef from global type-defs (it's only used in image_debug, i think, which has a local definition)
609
- export interface QuaggaJSxyDef {
610
- x: any;
611
- y: any;
612
- }
613
-
614
- /**
615
- * an object with an x and a y value
616
- */
617
- export interface QuaggaJSxy {
618
- x: number;
619
- y: number;
620
- }
621
-
622
- /**
623
- * an object with a pair of x and a y values.
624
- * Used for giving a html canvas context.strokeRect function it's x, y, width
625
- * and height values.
626
- */
627
- export interface QuaggaJSRectSize {
628
- pos: QuaggaJSxy;
629
- size: QuaggaJSxy;
630
- }
631
-
632
- /**
633
- * an object with the styles, color can actually be a color, a gradient or a
634
- * pattern (see definitions for context.strokeStyle. But is most commonly a
635
- * colour.
636
- */
637
- export interface QuaggaJSStyle {
638
- color: string;
639
-
640
- /* http://www.w3schools.com/tags/canvas_linewidth.asp */
641
- lineWidth: number;
642
- }
643
-
644
- /**
645
- * Pass when creating a ResultCollector
646
- */
647
- export interface QuaggaJSResultCollector {
648
- /**
649
- * keep track of the image producing this result
650
- */
651
- capture?: boolean;
652
-
653
- /**
654
- * maximum number of results to store
655
- */
656
- capacity?: number;
657
-
658
- /**
659
- * a list of codes that should not be recorded. This is effectively a list
660
- * of filters that return false.
661
- */
662
- blacklist?: Array<QuaggaJSCodeResult>;
663
-
664
- /**
665
- * passed a QuaggaJSCodeResult, return true if you want this to be stored,
666
- * false if you don't. Note: The black list is effectively a list of filters
667
- * that return false. So if you only want to store results that are ean_13,
668
- * you would say return codeResult.format==="ean_13"
669
- */
670
- filter?: QuaggaJSResultCollectorFilterFunction;
671
-
672
- /*
673
- * a static function that returns you a ResultCollector
674
- */
675
- create?(param: QuaggaJSResultCollector): QuaggaJSResultCollector;
676
-
677
- getResults?(): QuaggaJSCodeResult[];
678
- }
679
-
680
- /**
681
- * used for ResultCollector blacklists and filters
682
- */
683
- export interface QuaggaJSCodeResult {
684
- code?: string;
685
- format?: string;
686
- }
687
-
688
- /**
689
- * Called to filter which Results to collect in ResultCollector
690
- */
691
- export interface QuaggaJSResultCollectorFilterFunction {
692
- (
693
- data: QuaggaJSCodeResult
694
- ): boolean;
695
- }
696
-
697
- /**
698
- * The callbacks passed into onProcessed, onDetected and decodeSingle receive a
699
- * data object upon execution. The data object contains the following
700
- * information. Depending on the success, some fields may be undefined or just
701
- * empty.
702
- */
703
- export interface QuaggaJSResultObject {
704
- // eslint-disable-next-line @typescript-eslint/camelcase
705
- codeResult: QuaggaJSResultObject_CodeResult;
706
- barcodes?: Array<QuaggaJSResultObject>;
707
- line: {
708
- x: number;
709
- y: number;
710
- }[];
711
- angle: number;
712
- pattern: number[];
713
- box: number[][];
714
- boxes: number[][][];
715
- frame?: string;
716
- }
717
-
718
- // eslint-disable-next-line @typescript-eslint/camelcase,@typescript-eslint/class-name-casing
719
- export interface QuaggaJSResultObject_CodeResult {
720
- code: string | null;
721
- start: number;
722
- end: number;
723
- codeset: number;
724
- startInfo: {
725
- error: number;
726
- code: number;
727
- start: number;
728
- end: number;
729
- };
730
- decodedCodes: {
731
- error?: number;
732
- code: number;
733
- start: number;
734
- end: number;
735
- }[];
736
-
737
- endInfo: {
738
- error: number;
739
- code: number;
740
- start: number;
741
- end: number;
742
- };
743
- direction: number;
744
- format: string;
745
- }
746
-
747
- export type InputStreamType = 'VideoStream' | 'ImageStream' | 'LiveStream';
748
-
749
- export interface QuaggaJSConfigObject {
750
- /**
751
- * The image path to load from, or a data url
752
- * Ex: '/test/fixtures/code_128/image-001.jpg'
753
- * or: 'data:image/jpg;base64,' + data
754
- */
755
- src?: string;
756
-
757
- inputStream?: {
758
- /**
759
- * @default "Live"
760
- */
761
- name?: string;
762
-
763
- /**
764
- * @default "LiveStream"
765
- */
766
- type?: InputStreamType;
767
-
768
- target?: Element | string;
769
-
770
- constraints?: MediaTrackConstraints;
771
-
772
- /**
773
- * defines rectangle of the detection/localization area. Useful when you
774
- * KNOW that certain parts of the image will not contain a barcode, also
775
- * useful when you have multiple barcodes in a row and you want to make
776
- * sure that only a code in, say the middle quarter is read not codes
777
- * above or below
778
- */
779
- area?: {
780
- /**
781
- * @default "0%", set this and bottom to 25% if you only want to
782
- * read a 'line' that is in the middle quarter
783
- */
784
- top?: string;
785
-
786
- /**
787
- * @default "0%"
788
- */
789
- right?: string;
790
-
791
- /**
792
- * @default "0%"
793
- */
794
- left?: string;
795
-
796
- /**
797
- * @default "0%", set this and top to 50% if you only want to read a
798
- * 'line' that is in the middle half
799
- */
800
- bottom?: string;
801
- };
802
-
803
- singleChannel?: boolean;
804
- size?: number;
805
- sequence?: boolean;
806
- };
807
-
808
- /**
809
- * @default false
810
- */
811
- debug?: boolean;
812
-
813
- /**
814
- * @default true
815
- */
816
- locate?: boolean;
817
-
818
- /**
819
- * @default 4
820
- */
821
- numOfWorkers?: number;
822
-
823
- /**
824
- * This top-level property controls the scan-frequency of the video-stream.
825
- * It’s optional and defines the maximum number of scans per second.
826
- * This renders useful for cases where the scan-session is long-running and
827
- * resources such as CPU power are of concern.
828
- */
829
- frequency?: number;
830
-
831
- decoder?: {
832
- /**
833
- * @default [ "code_128_reader" ]
834
- */
835
- readers?: (QuaggaJSReaderConfig | string)[];
836
-
837
- debug?: {
838
- /**
839
- * @default false
840
- */
841
- drawBoundingBox?: boolean;
842
-
843
- /**
844
- * @default false
845
- */
846
- showFrequency?: boolean;
847
-
848
- /**
849
- * @default false
850
- */
851
- drawScanline?: boolean;
852
-
853
- /**
854
- * @default false
855
- */
856
- showPattern?: boolean;
857
- };
858
-
859
- /**
860
- * The multiple property tells the decoder if it should continue decoding after finding a valid barcode.
861
- * If multiple is set to true, the results will be returned as an array of result objects.
862
- * Each object in the array will have a box, and may have a codeResult
863
- * depending on the success of decoding the individual box.
864
- */
865
- multiple?: boolean;
866
- };
867
-
868
- locator?: {
869
- /**
870
- * @default true
871
- */
872
- halfSample?: boolean;
873
-
874
- /**
875
- * @default "medium"
876
- * Available values: x-small, small, medium, large, x-large
877
- */
878
- patchSize?: string;
879
-
880
- debug?: {
881
- /**
882
- * @default false
883
- */
884
- showCanvas?: boolean;
885
-
886
- /**
887
- * @default false
888
- */
889
- showPatches?: boolean;
890
-
891
- /**
892
- * @default false
893
- */
894
- showFoundPatches?: boolean;
895
-
896
- /**
897
- * @default false
898
- */
899
- showSkeleton?: boolean;
900
-
901
- /**
902
- * @default false
903
- */
904
- showLabels?: boolean;
905
-
906
- /**
907
- * @default false
908
- */
909
- showPatchLabels?: boolean;
910
-
911
- /**
912
- * @default false
913
- */
914
- showRemainingPatchLabels?: boolean;
915
-
916
- boxFromPatches?: {
917
- /**
918
- * @default false
919
- */
920
- showTransformed?: boolean;
921
-
922
- /**
923
- * @default false
924
- */
925
- showTransformedBox?: boolean;
926
-
927
- /**
928
- * @default false
929
- */
930
- showBB?: boolean;
931
- };
932
- };
933
- };
934
- }
935
-
936
- export interface QuaggaJSReaderConfig {
937
- format: string;
938
- config: {
939
- supplements: string[];
940
- };
941
- }
942
-
943
- export interface MediaTrackConstraintsWithDeprecated extends MediaTrackConstraints {
944
- maxAspectRatio?: number; // i don't see this in the documentation anywhere, but it's in the original test suite...
945
- minAspectRatio?: number;
946
- facing?: string;
947
- }
948
-
949
- export type TypedArrayConstructor =
950
- Int8ArrayConstructor
951
- | Uint8ArrayConstructor
952
- | Uint8ClampedArrayConstructor
953
- | Int16ArrayConstructor
954
- | Uint16ArrayConstructor
955
- | Int32ArrayConstructor
956
- | Uint32ArrayConstructor
957
- | Float32ArrayConstructor
958
- | Float64ArrayConstructor;
959
-
960
- export type TypedArray =
961
- Int8Array
962
- | Uint8Array
963
- | Uint8ClampedArray
964
- | Int16Array
965
- | Uint16Array
966
- | Int32Array
967
- | Uint32Array
968
- | Float32Array
969
- | Float64Array;
1
+ /* eslint-disable max-classes-per-file */
2
+ // Type definitions for QuaggaJS v0.12.1 (2017-10-19)
3
+ // Project: http://serratus.github.io/quaggaJS/
4
+ // Definitions by: Cam Birch, Peter Horwood aka Madman Pierre, Dan Manastireanu <https://github.com/danmana>
5
+
6
+ // import SubImage from '../src/common/subImage';
7
+ // import ImageWrapper from '../src/common/image_wrapper';
8
+ // export { SubImage, ImageWrapper };
9
+
10
+ declare const Quagga: QuaggaJSStatic;
11
+ export default Quagga;
12
+
13
+ // There are many different spots inside Quagga where we refer to an X/Y position of something, but it has entirely different
14
+ // contextual meaning. This allows us to create a type that is branded by name, and therefore these variables cannot be directly
15
+ // mixed up with each other, without explicitly forcing it to happen. Good.
16
+ export interface XYObject<T extends string> {
17
+ x: number;
18
+ y: number;
19
+ type: T;
20
+ }
21
+
22
+ // TODO: fill this in from cv_utils#imageRef
23
+ export type ImageRef = XYObject<'ImageRef'>;
24
+
25
+ export type XYSize = XYObject<'XYSize'>;
26
+
27
+ export type Point = XYObject<'Point'>;
28
+
29
+ export type SparseImageWrapper = {
30
+ data: TypedArray | Array<number> | null;
31
+ size: XYSize;
32
+ };
33
+
34
+ export type WrapperIndexMapping = {
35
+ x: Array<number>;
36
+ y: Array<number>;
37
+ };
38
+
39
+ // eslint-disable-next-line @typescript-eslint/class-name-casing
40
+ export type Moment = {
41
+ m00: number;
42
+ m01: number;
43
+ m10: number;
44
+ m11: number;
45
+ m02: number;
46
+ m20: number;
47
+ theta: number;
48
+ rad: number;
49
+ vec?: Array<number>;
50
+ };
51
+
52
+ export class ImageWrapper {
53
+ data: TypedArray | Array<number>;
54
+
55
+ size: XYSize;
56
+
57
+ indexMapping?: WrapperIndexMapping;
58
+
59
+ constructor(
60
+ size: XYSize,
61
+ data?: TypedArray | Array<number>,
62
+ ArrayType?: TypedArrayConstructor | ArrayConstructor,
63
+ initialize?: boolean
64
+ );
65
+
66
+ inImageWithBorder(imgRef: ImageRef, border: number): boolean;
67
+
68
+ subImageAsCopy(imageWrapper: ImageWrapper, from: XYSize): ImageWrapper;
69
+
70
+ get(x: number, y: number): number;
71
+
72
+ getSafe(x: number, y: number): number;
73
+
74
+ set(x: number, y: number, value: number): ImageWrapper;
75
+
76
+ zeroBorder(): ImageWrapper;
77
+
78
+ moments(labelCount: any): Array<Moment>;
79
+
80
+ getAsRGBA(scale?: number): Uint8ClampedArray;
81
+
82
+ show(canvas: HTMLCanvasElement, scale?: number): void;
83
+
84
+ overlay(canvas: HTMLCanvasElement, scale: number, from: XYSize): void;
85
+ }
86
+
87
+ export class SubImage {
88
+ I: ImageWrapper | SparseImageWrapper;
89
+
90
+ data: ImageWrapper['data'];
91
+
92
+ originalSize: ImageRef;
93
+
94
+ from: ImageRef;
95
+
96
+ size: ImageRef;
97
+
98
+ constructor(from: ImageRef, size: ImageRef, I: SparseImageWrapper);
99
+
100
+ get(x: number, y: number): number;
101
+
102
+ show(canvas: HTMLCanvasElement, scale: number): void;
103
+
104
+ updateData(image: ImageWrapper): void;
105
+
106
+ updateFrom(from: ImageRef): void;
107
+ }
108
+
109
+ export type QuaggaImageData = Array<number>;
110
+
111
+ export type BarcodeReaderType = string;
112
+
113
+ export interface BarcodeReaderConfig {
114
+ normalizeBarSpaceWidth?: boolean,
115
+ supplements?: Array<BarcodeReaderType>,
116
+ }
117
+
118
+ export enum BarcodeDirection {
119
+ Forward = 1,
120
+ Reverse = -1
121
+ }
122
+ type BarcodeFormat = string;
123
+
124
+ export interface BarcodeCorrection {
125
+ bar: number;
126
+ space: number;
127
+ }
128
+
129
+ export interface BarcodePosition {
130
+ start: number;
131
+ startCounter?: number;
132
+ end: number;
133
+ endCounter?: number;
134
+ error?: number;
135
+ }
136
+
137
+ export interface BarcodeInfo extends BarcodePosition {
138
+ code: number;
139
+ correction?: BarcodeCorrection;
140
+ }
141
+
142
+ export interface Barcode {
143
+ code: string;
144
+ codeset?: number;
145
+ correction?: BarcodeCorrection;
146
+ decodedCodes?: Array<string | BarcodeInfo | BarcodePosition>;
147
+ direction?: BarcodeDirection;
148
+ end: number;
149
+ endInfo?: BarcodePosition;
150
+ format: BarcodeFormat;
151
+ start: number;
152
+ startInfo: BarcodePosition;
153
+ supplement?: Barcode;
154
+ }
155
+
156
+ export interface ThresholdSize {
157
+ size: number;
158
+ counts: number;
159
+ min: number;
160
+ max: number;
161
+ }
162
+
163
+ export interface Threshold {
164
+ space: {
165
+ narrow: ThresholdSize;
166
+ wide: ThresholdSize;
167
+ };
168
+ bar: {
169
+ narrow: ThresholdSize;
170
+ wide: ThresholdSize;
171
+ };
172
+ }
173
+
174
+ export declare module Readers {
175
+ export abstract class BarcodeReader {
176
+ _row: Array<number>;
177
+ SINGLE_CODE_ERROR: number;
178
+ FORMAT: BarcodeFormat;
179
+ CONFIG_KEYS: BarcodeReaderConfig;
180
+
181
+ static get Exception(): {
182
+ StartNotFoundException: string;
183
+ CodeNotFoundException: string;
184
+ PatternNotFoundException: string;
185
+ };
186
+
187
+ constructor(config: BarcodeReaderConfig, supplements?: Array<BarcodeReader>);
188
+
189
+ abstract decode(row?: Array<number>, start?: BarcodePosition | number): Barcode | null;
190
+
191
+ decodePattern(pattern: Array<number>): Barcode | null;
192
+
193
+ protected _nextUnset(line: ReadonlyArray<number>, start?: number): number;
194
+
195
+ protected _matchPattern(counter: ReadonlyArray<number>, code: ReadonlyArray<number>, maxSingleError?: number): number;
196
+
197
+ protected _nextSet(line: ReadonlyArray<number>, offset?: number): number;
198
+
199
+ protected _correctBars(counter: Array<number>, correction: number, indices: Array<number>): void;
200
+
201
+ protected _matchRange(start: number, end: number, value: number): boolean;
202
+
203
+ protected _fillCounters(offset?: number, end?: number, isWhite?: boolean): number[];
204
+
205
+ protected _toCounters(start: number, counters: Uint16Array | Array<number>): number[] | Uint16Array;
206
+ }
207
+
208
+ export class TwoOfFiveReader extends BarcodeReader {
209
+ FORMAT: string;
210
+ SINGLE_CODE_ERROR: number;
211
+ AVG_CODE_ERROR: number;
212
+
213
+ decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
214
+
215
+ protected _findPattern(pattern: ReadonlyArray<number>, offset: number, isWhite?: boolean, tryHarder?: boolean): BarcodeInfo | null;
216
+
217
+ protected _findStart(): BarcodePosition | null;
218
+
219
+ protected _verifyTrailingWhitespace(endInfo: BarcodeInfo): BarcodePosition | null;
220
+
221
+ protected _findEnd(): BarcodePosition | null;
222
+
223
+ protected _verifyCounterLength(counters: Array<number>): boolean;
224
+
225
+ protected _decodeCode(counter: ReadonlyArray<number>): BarcodeInfo | null;
226
+
227
+ protected _decodePayload(counters: ReadonlyArray<number>, result: Array<string>, decodedCodes: Array<BarcodeInfo | BarcodePosition>): BarcodeInfo | null;
228
+ }
229
+
230
+ export class NewCodabarReader extends BarcodeReader {
231
+ FORMAT: string;
232
+
233
+ decode(row?: Array<number>, start?: BarcodePosition | number | null): Barcode | null;
234
+
235
+ protected _computeAlternatingThreshold(offset: number, end: number): number;
236
+
237
+ protected _toPattern(offset: number): number;
238
+
239
+ protected _isStartEnd(pattern: number): boolean;
240
+
241
+ protected _sumCounters(start: number, end: number): number;
242
+
243
+ protected _findStart(): BarcodePosition | null;
244
+
245
+ protected _patternToChar(pattern: number): string | null;
246
+
247
+ protected _calculatePatternLength(offset: number): number;
248
+
249
+ protected _verifyWhitespace(startCounter: number, endCounter: number): boolean;
250
+
251
+ protected _charToPattern(char: string): number;
252
+
253
+ protected _thresholdResultPattern(result: ReadonlyArray<string>, startCounter: number): Threshold;
254
+
255
+ protected _validateResult(result: ReadonlyArray<string>, startCounter: number): boolean;
256
+ }
257
+
258
+ export class Code128Reader extends BarcodeReader {
259
+ CODE_SHIFT: number;
260
+ CODE_C: number;
261
+ CODE_B: number;
262
+ CODE_A: number;
263
+ START_CODE_A: number;
264
+ START_CODE_B: number;
265
+ START_CODE_C: number;
266
+ STOP_CODE: number;
267
+ CODE_PATTERN: number[][];
268
+ SINGLE_CODE_ERROR: number;
269
+ AVG_CODE_ERROR: number;
270
+ FORMAT: string;
271
+ MODULE_INDICES: {
272
+ bar: number[];
273
+ space: number[];
274
+ };
275
+
276
+ decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
277
+
278
+ calculateCorrection(expected: ReadonlyArray<number>, normalized: ReadonlyArray<number>, indices: ReadonlyArray<number>): number;
279
+
280
+ protected _decodeCode(start: number, correction?: BarcodeCorrection): BarcodeInfo | null;
281
+
282
+ protected _correct(counter: Array<number>, correction: BarcodeCorrection): void;
283
+
284
+ protected _findStart(): BarcodeInfo | null;
285
+
286
+ protected _verifyTrailingWhitespace(endInfo: BarcodeInfo): BarcodeInfo | null;
287
+ }
288
+
289
+ export class Code32Reader extends Code39Reader {
290
+ FORMAT: string;
291
+
292
+ decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
293
+
294
+ protected _decodeCode32(code: string): string | null;
295
+
296
+ protected _checkChecksum(code: string): boolean;
297
+ }
298
+
299
+ export class Code39Reader extends BarcodeReader {
300
+ FORMAT: string;
301
+
302
+ decode(row?: Array<number>, start?: BarcodePosition | number | null): Barcode | null;
303
+
304
+ protected _findStart(): BarcodePosition | null;
305
+
306
+ protected _toPattern(counters: Uint16Array): number;
307
+
308
+ protected _findNextWidth(counters: Uint16Array, current: number): number;
309
+
310
+ protected _patternToChar(pattern: number): string | null;
311
+
312
+ protected _verifyTrailingWhitespace(lastStart: number, nextStart: number, counters: Uint16Array): boolean;
313
+ }
314
+
315
+ export class Code39VINReader extends Code39Reader {
316
+ FORMAT: string;
317
+
318
+ decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
319
+
320
+ protected _checkChecksum(code: string): boolean;
321
+ }
322
+
323
+ export class Code93Reader extends BarcodeReader {
324
+ FORMAT: string;
325
+
326
+ decode(row?: Array<number>, start?: BarcodePosition | number | null): Barcode | null;
327
+
328
+ protected _patternToChar(pattern: number): string | null;
329
+
330
+ protected _toPattern(counters: Uint16Array): number;
331
+
332
+ protected _findStart(): BarcodePosition | null;
333
+
334
+ protected _verifyEnd(lastStart: number, nextStart: number): boolean;
335
+
336
+ protected _decodeExtended(charArray: Array<string>): string[] | null;
337
+
338
+ protected _matchCheckChar(charArray: Array<string>, index: number, maxWeight: number): boolean;
339
+
340
+ protected _verifyChecksums(charArray: Array<string>): boolean;
341
+ }
342
+
343
+ export class EAN2Reader extends EANReader {
344
+ FORMAT: string;
345
+
346
+ decode(row?: Array<number>, start?: number): Barcode | null;
347
+ }
348
+
349
+ export class EAN5Reader extends EANReader {
350
+ FORMAT: string;
351
+
352
+ decode(row?: Array<number>, start?: number): Barcode | null;
353
+ }
354
+
355
+ export class EAN8Reader extends EANReader {
356
+ FORMAT: string;
357
+
358
+ protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
359
+ }
360
+
361
+ export class EANReader extends BarcodeReader {
362
+ FORMAT: string;
363
+ SINGLE_CODE_ERROR: number;
364
+ STOP_PATTERN: number[];
365
+
366
+ constructor(config?: BarcodeReaderConfig, supplements?: Array<BarcodeReader>);
367
+
368
+ decode(row?: Array<number>, start?: BarcodePosition | number): Barcode | null;
369
+
370
+ protected _findPattern(pattern: ReadonlyArray<number>, offset: number, isWhite: boolean, tryHarder: boolean): BarcodePosition | null;
371
+
372
+ protected _decodeCode(start: number, coderange?: number): BarcodeInfo | null;
373
+
374
+ protected _findStart(): BarcodePosition | null;
375
+
376
+ protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
377
+
378
+ protected _verifyTrailingWhitespace(endInfo: BarcodePosition): BarcodePosition | null;
379
+
380
+ protected _findEnd(offset: number, isWhite: boolean): BarcodePosition | null;
381
+
382
+ protected _checksum(result: Array<number>): boolean;
383
+ }
384
+
385
+ export class I2of5Reader extends BarcodeReader {
386
+ SINGLE_CODE_ERROR: number;
387
+ AVG_CODE_ERROR: number;
388
+ START_PATTERN: number[];
389
+ STOP_PATTERN: number[];
390
+ CODE_PATTERN: number[][];
391
+ MAX_CORRECTION_FACTOR: number;
392
+ FORMAT: string;
393
+
394
+ constructor(opts: BarcodeReaderConfig);
395
+
396
+ decode(row?: Array<number>, start?: BarcodePosition | number): Barcode | null;
397
+
398
+ protected _matchPattern(counter: Array<number>, code: ReadonlyArray<number>): number;
399
+
400
+ protected _findPattern(pattern: ReadonlyArray<number>, offset?: number, isWhite?: boolean, tryHarder?: boolean): BarcodePosition | null;
401
+
402
+ protected _findStart(): BarcodePosition | null;
403
+
404
+ protected _verifyTrailingWhitespace(endInfo: BarcodePosition): BarcodePosition | null;
405
+
406
+ protected _findEnd(): BarcodePosition | null;
407
+
408
+ protected _decodePair(counterPair: Array<Array<number>>): Array<BarcodeInfo> | null;
409
+
410
+ protected _decodeCode(counter: Array<number>): BarcodeInfo | null;
411
+
412
+ protected _decodePayload(counters: ReadonlyArray<number>, result: Array<string>, decodedCodes: Array<BarcodeInfo | BarcodePosition>): Array<BarcodeInfo> | null;
413
+
414
+ protected _verifyCounterLength(counters: Array<number>): boolean;
415
+ }
416
+
417
+ export class UPCEReader extends EANReader {
418
+ CODE_FREQUENCY: number[][];
419
+ STOP_PATTERN: number[];
420
+ FORMAT: string;
421
+
422
+ protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
423
+
424
+ protected _determineParity(codeFrequency: number, result: Array<number>): boolean;
425
+
426
+ protected _convertToUPCA(result: Array<number>): number[];
427
+
428
+ protected _checksum(result: Array<number>): boolean;
429
+
430
+ protected _findEnd(offset: number, isWhite: boolean): BarcodePosition | null;
431
+
432
+ protected _verifyTrailingWhitespace(endInfo: BarcodePosition): BarcodePosition | null;
433
+ }
434
+
435
+ export class UPCReader extends EANReader {
436
+ FORMAT: string;
437
+
438
+ decode(row?: Array<number>, start?: BarcodePosition | number): Barcode | null;
439
+ }
440
+
441
+ }
442
+
443
+ export interface QuaggaJSStatic {
444
+ /**
445
+ * This method initializes the library for a given
446
+ * configuration config (see below) and invokes the callback when Quagga is
447
+ * ready to start. The initialization process also requests for camera
448
+ * access if real-time detection is configured.
449
+ */
450
+ init(
451
+ config: QuaggaJSConfigObject,
452
+ callback?: (err: any) => void
453
+ ): Promise<void>;
454
+
455
+ init(
456
+ config: QuaggaJSConfigObject,
457
+ callback: (err: any) => void,
458
+ imageWrapper: ImageWrapper,
459
+ ): Promise<void>;
460
+
461
+ /**
462
+ * When the library is initialized, the start()
463
+ * method starts the video-stream and begins locating and decoding the
464
+ * images.
465
+ */
466
+ start(): void;
467
+
468
+ /**
469
+ * If the decoder is currently running, after calling
470
+ * stop() the decoder does not process any more images.
471
+ * Additionally, if a camera-stream was requested upon initialization,
472
+ * this operation also disconnects the camera.
473
+ */
474
+ stop(): Promise<void>;
475
+
476
+ /**
477
+ * Pauses processing, but does not release any handlers
478
+ */
479
+ pause(): void;
480
+
481
+ /**
482
+ * This method registers a callback(data) function that is
483
+ * called for each frame after the processing is done. The data object
484
+ * contains detailed information about the success/failure of the operation.
485
+ * The output varies, depending whether the detection and/or decoding were
486
+ * successful or not.
487
+ */
488
+ onProcessed(callback: QuaggaJSResultCallbackFunction): void;
489
+
490
+ /**
491
+ * Removes a callback that was previously registered with @see onProcessed
492
+ */
493
+ offProcessed(callback?: QuaggaJSResultCallbackFunction): void;
494
+
495
+ /**
496
+ * Registers a callback(data) function which is triggered whenever a
497
+ * barcode- pattern has been located and decoded successfully. The passed
498
+ * data object contains information about the decoding process including the
499
+ * detected code which can be obtained by calling data.codeResult.code.
500
+ */
501
+ onDetected(callback: QuaggaJSResultCallbackFunction): void;
502
+
503
+ /**
504
+ * Removes a callback that was previously registered with @see onDetected
505
+ */
506
+ offDetected(callback?: QuaggaJSResultCallbackFunction): void;
507
+
508
+ ResultCollector: QuaggaJSResultCollector;
509
+ registerResultCollector(resultCollector: QuaggaJSResultCollector): void;
510
+ setReaders(readers: (QuaggaJSReaderConfig | string)[]): void;
511
+ registerReader(name: string, reader: object): void;
512
+
513
+ /**
514
+ * In contrast to the calls described
515
+ * above, this method does not rely on getUserMedia and operates on a single
516
+ * image instead. The provided callback is the same as in onDetected and
517
+ * contains the result data object.
518
+ */
519
+ decodeSingle(
520
+ config: QuaggaJSConfigObject,
521
+ resultCallback?: QuaggaJSResultCallbackFunction
522
+ ): Promise<QuaggaJSResultObject>;
523
+
524
+ /**
525
+ * Constructs used for debugging purposes
526
+ */
527
+ ImageDebug: {
528
+ drawPath: QuaggaJSDebugDrawPath;
529
+ drawRect: QuaggaJSDebugDrawRect;
530
+ };
531
+ ImageWrapper: ImageWrapper;
532
+
533
+ /**
534
+ * an object Quagga uses for drawing and processing, useful for calling code
535
+ * when debugging
536
+ */
537
+ canvas: {
538
+ ctx: {
539
+ image: CanvasRenderingContext2D;
540
+ overlay: CanvasRenderingContext2D;
541
+ };
542
+ dom: {
543
+ image: HTMLCanvasElement;
544
+ overlay: HTMLCanvasElement;
545
+ };
546
+ };
547
+
548
+ CameraAccess: QuaggaJSCameraAccess;
549
+ }
550
+
551
+ /**
552
+ * Used for accessing information about the active stream track and available video devices.
553
+ */
554
+ export interface QuaggaJSCameraAccess {
555
+ disableTorch(): Promise<void>;
556
+ enableTorch(): Promise<void>;
557
+ enumerateVideoDevices(): Promise<MediaDeviceInfo[]> | never;
558
+ getActiveStreamLabel(): string;
559
+ getActiveTrack(): MediaStreamTrack | null;
560
+ release(): Promise<void>;
561
+ request(
562
+ video: HTMLVideoElement | null,
563
+ videoConstraints?: MediaTrackConstraintsWithDeprecated
564
+ ): Promise<void> | never;
565
+ requestedVideoElement: HTMLVideoElement | null;
566
+ }
567
+
568
+ /**
569
+ * Called whenever an item is detected or a process step has been completed.
570
+ */
571
+ export interface QuaggaJSResultCallbackFunction {
572
+ (
573
+ data: QuaggaJSResultObject
574
+ ): void;
575
+ }
576
+
577
+ /**
578
+ * Called to draw debugging path. The path is an array of array of 2 numbers.
579
+ * The def.x specifies element in the sub array is the x, and similarly the def.y
580
+ * defines the y.
581
+ * typical values 0, 1, 'x', 'y'
582
+ */
583
+ export interface QuaggaJSDebugDrawPath {
584
+ (
585
+ path: any[],
586
+ def: QuaggaJSxyDef,
587
+ ctx: CanvasRenderingContext2D,
588
+ style: QuaggaJSStyle
589
+ ): void;
590
+ }
591
+
592
+ /**
593
+ * Called to draw debugging Rectangle
594
+ */
595
+ export interface QuaggaJSDebugDrawRect {
596
+ (
597
+ pos: any[],
598
+ size: QuaggaJSRectSize,
599
+ ctx: CanvasRenderingContext2D,
600
+ style: QuaggaJSStyle
601
+ ): void;
602
+ }
603
+
604
+ /**
605
+ * an object with an x and a y value, the x and y specify which element in
606
+ * another array is the x or y value.
607
+ * typical values 0, 1, 'x', 'y'
608
+ */
609
+ // TODO: remove QuaggaJSxyDef from global type-defs (it's only used in image_debug, i think, which has a local definition)
610
+ export interface QuaggaJSxyDef {
611
+ x: any;
612
+ y: any;
613
+ }
614
+
615
+ /**
616
+ * an object with an x and a y value
617
+ */
618
+ export interface QuaggaJSxy {
619
+ x: number;
620
+ y: number;
621
+ }
622
+
623
+ /**
624
+ * an object with a pair of x and a y values.
625
+ * Used for giving a html canvas context.strokeRect function it's x, y, width
626
+ * and height values.
627
+ */
628
+ export interface QuaggaJSRectSize {
629
+ pos: QuaggaJSxy;
630
+ size: QuaggaJSxy;
631
+ }
632
+
633
+ /**
634
+ * an object with the styles, color can actually be a color, a gradient or a
635
+ * pattern (see definitions for context.strokeStyle. But is most commonly a
636
+ * colour.
637
+ */
638
+ export interface QuaggaJSStyle {
639
+ color: string;
640
+
641
+ /* http://www.w3schools.com/tags/canvas_linewidth.asp */
642
+ lineWidth: number;
643
+ }
644
+
645
+ /**
646
+ * Pass when creating a ResultCollector
647
+ */
648
+ export interface QuaggaJSResultCollector {
649
+ /**
650
+ * keep track of the image producing this result
651
+ */
652
+ capture?: boolean;
653
+
654
+ /**
655
+ * maximum number of results to store
656
+ */
657
+ capacity?: number;
658
+
659
+ /**
660
+ * a list of codes that should not be recorded. This is effectively a list
661
+ * of filters that return false.
662
+ */
663
+ blacklist?: Array<QuaggaJSCodeResult>;
664
+
665
+ /**
666
+ * passed a QuaggaJSCodeResult, return true if you want this to be stored,
667
+ * false if you don't. Note: The black list is effectively a list of filters
668
+ * that return false. So if you only want to store results that are ean_13,
669
+ * you would say return codeResult.format==="ean_13"
670
+ */
671
+ filter?: QuaggaJSResultCollectorFilterFunction;
672
+
673
+ /*
674
+ * a static function that returns you a ResultCollector
675
+ */
676
+ create?(param: QuaggaJSResultCollector): QuaggaJSResultCollector;
677
+
678
+ getResults?(): QuaggaJSCodeResult[];
679
+ }
680
+
681
+ /**
682
+ * used for ResultCollector blacklists and filters
683
+ */
684
+ export interface QuaggaJSCodeResult {
685
+ code?: string;
686
+ format?: string;
687
+ }
688
+
689
+ /**
690
+ * Called to filter which Results to collect in ResultCollector
691
+ */
692
+ export interface QuaggaJSResultCollectorFilterFunction {
693
+ (
694
+ data: QuaggaJSCodeResult
695
+ ): boolean;
696
+ }
697
+
698
+ /**
699
+ * The callbacks passed into onProcessed, onDetected and decodeSingle receive a
700
+ * data object upon execution. The data object contains the following
701
+ * information. Depending on the success, some fields may be undefined or just
702
+ * empty.
703
+ */
704
+ export interface QuaggaJSResultObject {
705
+ // eslint-disable-next-line @typescript-eslint/camelcase
706
+ codeResult: QuaggaJSResultObject_CodeResult;
707
+ barcodes?: Array<QuaggaJSResultObject>;
708
+ line: {
709
+ x: number;
710
+ y: number;
711
+ }[];
712
+ angle: number;
713
+ pattern: number[];
714
+ box: number[][];
715
+ boxes: number[][][];
716
+ frame?: string;
717
+ }
718
+
719
+ // eslint-disable-next-line @typescript-eslint/camelcase,@typescript-eslint/class-name-casing
720
+ export interface QuaggaJSResultObject_CodeResult {
721
+ code: string | null;
722
+ start: number;
723
+ end: number;
724
+ codeset: number;
725
+ startInfo: {
726
+ error: number;
727
+ code: number;
728
+ start: number;
729
+ end: number;
730
+ };
731
+ decodedCodes: {
732
+ error?: number;
733
+ code: number;
734
+ start: number;
735
+ end: number;
736
+ }[];
737
+
738
+ endInfo: {
739
+ error: number;
740
+ code: number;
741
+ start: number;
742
+ end: number;
743
+ };
744
+ direction: number;
745
+ format: string;
746
+ }
747
+
748
+ export type InputStreamType = 'VideoStream' | 'ImageStream' | 'LiveStream';
749
+
750
+ export interface QuaggaJSConfigObject {
751
+ /**
752
+ * The image path to load from, or a data url
753
+ * Ex: '/test/fixtures/code_128/image-001.jpg'
754
+ * or: 'data:image/jpg;base64,' + data
755
+ */
756
+ src?: string | Uint8Array | Buffer;
757
+
758
+ inputStream?: {
759
+ /**
760
+ * @default "Live"
761
+ */
762
+ name?: string;
763
+
764
+ /**
765
+ * @default "LiveStream"
766
+ */
767
+ type?: InputStreamType;
768
+
769
+ target?: Element | string;
770
+
771
+ constraints?: MediaTrackConstraints;
772
+
773
+ /**
774
+ * defines rectangle of the detection/localization area. Useful when you
775
+ * KNOW that certain parts of the image will not contain a barcode, also
776
+ * useful when you have multiple barcodes in a row and you want to make
777
+ * sure that only a code in, say the middle quarter is read not codes
778
+ * above or below
779
+ */
780
+ area?: {
781
+ /**
782
+ * @default "0%", set this and bottom to 25% if you only want to
783
+ * read a 'line' that is in the middle quarter
784
+ */
785
+ top?: string;
786
+
787
+ /**
788
+ * @default "0%"
789
+ */
790
+ right?: string;
791
+
792
+ /**
793
+ * @default "0%"
794
+ */
795
+ left?: string;
796
+
797
+ /**
798
+ * @default "0%", set this and top to 50% if you only want to read a
799
+ * 'line' that is in the middle half
800
+ */
801
+ bottom?: string;
802
+ };
803
+
804
+ mime?: string;
805
+
806
+ singleChannel?: boolean;
807
+ size?: number;
808
+ sequence?: boolean;
809
+ };
810
+
811
+ /**
812
+ * @default false
813
+ */
814
+ debug?: boolean;
815
+
816
+ /**
817
+ * @default true
818
+ */
819
+ locate?: boolean;
820
+
821
+ /**
822
+ * @default 4
823
+ */
824
+ numOfWorkers?: number;
825
+
826
+ /**
827
+ * This top-level property controls the scan-frequency of the video-stream.
828
+ * It’s optional and defines the maximum number of scans per second.
829
+ * This renders useful for cases where the scan-session is long-running and
830
+ * resources such as CPU power are of concern.
831
+ */
832
+ frequency?: number;
833
+
834
+ decoder?: {
835
+ /**
836
+ * @default [ "code_128_reader" ]
837
+ */
838
+ readers?: (QuaggaJSReaderConfig | string)[];
839
+
840
+ debug?: {
841
+ /**
842
+ * @default false
843
+ */
844
+ drawBoundingBox?: boolean;
845
+
846
+ /**
847
+ * @default false
848
+ */
849
+ showFrequency?: boolean;
850
+
851
+ /**
852
+ * @default false
853
+ */
854
+ drawScanline?: boolean;
855
+
856
+ /**
857
+ * @default false
858
+ */
859
+ showPattern?: boolean;
860
+ };
861
+
862
+ /**
863
+ * The multiple property tells the decoder if it should continue decoding after finding a valid barcode.
864
+ * If multiple is set to true, the results will be returned as an array of result objects.
865
+ * Each object in the array will have a box, and may have a codeResult
866
+ * depending on the success of decoding the individual box.
867
+ */
868
+ multiple?: boolean;
869
+ };
870
+
871
+ locator?: {
872
+ /**
873
+ * @default true
874
+ */
875
+ halfSample?: boolean;
876
+
877
+ /**
878
+ * @default "medium"
879
+ * Available values: x-small, small, medium, large, x-large
880
+ */
881
+ patchSize?: string;
882
+
883
+ debug?: {
884
+ /**
885
+ * @default false
886
+ */
887
+ showCanvas?: boolean;
888
+
889
+ /**
890
+ * @default false
891
+ */
892
+ showPatches?: boolean;
893
+
894
+ /**
895
+ * @default false
896
+ */
897
+ showFoundPatches?: boolean;
898
+
899
+ /**
900
+ * @default false
901
+ */
902
+ showSkeleton?: boolean;
903
+
904
+ /**
905
+ * @default false
906
+ */
907
+ showLabels?: boolean;
908
+
909
+ /**
910
+ * @default false
911
+ */
912
+ showPatchLabels?: boolean;
913
+
914
+ /**
915
+ * @default false
916
+ */
917
+ showRemainingPatchLabels?: boolean;
918
+
919
+ boxFromPatches?: {
920
+ /**
921
+ * @default false
922
+ */
923
+ showTransformed?: boolean;
924
+
925
+ /**
926
+ * @default false
927
+ */
928
+ showTransformedBox?: boolean;
929
+
930
+ /**
931
+ * @default false
932
+ */
933
+ showBB?: boolean;
934
+ };
935
+ };
936
+ };
937
+ }
938
+
939
+ export interface QuaggaJSReaderConfig {
940
+ format: string;
941
+ config: {
942
+ supplements: string[];
943
+ };
944
+ }
945
+
946
+ export interface MediaTrackConstraintsWithDeprecated extends MediaTrackConstraints {
947
+ maxAspectRatio?: number; // i don't see this in the documentation anywhere, but it's in the original test suite...
948
+ minAspectRatio?: number;
949
+ facing?: string;
950
+ }
951
+
952
+ export type TypedArrayConstructor =
953
+ Int8ArrayConstructor
954
+ | Uint8ArrayConstructor
955
+ | Uint8ClampedArrayConstructor
956
+ | Int16ArrayConstructor
957
+ | Uint16ArrayConstructor
958
+ | Int32ArrayConstructor
959
+ | Uint32ArrayConstructor
960
+ | Float32ArrayConstructor
961
+ | Float64ArrayConstructor;
962
+
963
+ export type TypedArray =
964
+ Int8Array
965
+ | Uint8Array
966
+ | Uint8ClampedArray
967
+ | Int16Array
968
+ | Uint16Array
969
+ | Int32Array
970
+ | Uint32Array
971
+ | Float32Array
972
+ | Float64Array;