/// type Point = { x: number; y: number; }; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/BarcodeDetector/detect#return_value */ interface DetectedBarcode { boundingBox: DOMRectReadOnly; cornerPoints: [ Point, Point, Point, Point ]; format: string; rawValue: string; // @undecaf/zbar-wasm extensions orientation: Orientation; quality: number; } declare enum Orientation { UNKNOWN = -1, UPRIGHT = 0, ROTATED_RIGHT = 1, UPSIDE_DOWN = 2, ROTATED_LEFT = 3 } /** * Additional {@link BarcodeDetectorPolyfill} options supported by * the underlying ZBar implementation. */ declare class ZBarConfig { // Overrides automatic cache management if specified enableCache?: boolean; /** * Any of https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings; * defaults to UTF-8 */ encoding?: string; } /** * Parameter type of {@link BarcodeDetectorPolyfill.detect} */ type PolyfillImageBitmapSource = CanvasImageSourceWebCodecs | CanvasRenderingContext2D | { width: number; } | { height: number; }; /** * A polyfill for {@link external:BarcodeDetector}. * * @see https://wicg.github.io/shape-detection-api/#barcode-detection-api */ declare class BarcodeDetectorPolyfill { private readonly formats; private readonly zbarConfig; private canvas?; private scanner?; /** * See * BarcodeDetector() */ constructor(options?: { formats?: Array; zbar?: ZBarConfig; }); /** * See * BarcodeDetector.getSupportedFormats() */ static getSupportedFormats(): Promise>; /** * Scans an image for barcodes and returns a {@link Promise} for the result. * * @param {PolyfillImageBitmapSource} source the image to be scanned * @returns {Promise>} the scan result as described for {@link BarcodeDetector}, * or a rejected {@link Promise} containing the error * * @throws {TypeError} if the argument is not an {@link PolyfillImageBitmapSource} * @throws {DOMException} if the argument is in an invalid state for detection */ // TODO Enable cache for video source, disable for others unless overridden in zbarConfig detect(source: PolyfillImageBitmapSource): Promise>; /** * Returns an {@link ZBarScanner} configured for the requested barcode formats. */ private getScanner; /** * Converts any {@link PolyfillImageBitmapSource} to an {@link ImageData} instance. */ private toImageData; /** * Converts a ZBar {@link ZBarSymbol} to a {@link DetectedBarcode}. */ private toBarcodeDetectorResult; /** * Validates the argument of {@link BarcodeDetectorPolyfill.detect()} * against