UNPKG

react-native-scanbot-sdk

Version:

Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS

341 lines (316 loc) 11.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BarcodeScannerResult = exports.BarcodeScannerEngineModeValues = exports.BarcodeScannerConfiguration = exports.BarcodeItem = void 0; var _BarcodeConfigurationTypes = require("../barcode/BarcodeConfigurationTypes"); var _GenericDocument = require("../documents/GenericDocument"); var _image = require("../imageRef/image"); var _JsonSerializationTypes = require("../utils/json/JsonSerializationTypes"); var _utils = require("../utils/utils"); /// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten. /// Generated from core/schemas/BarcodeScannerTypes.yaml /** A single barcode found in the input image. Barcodes with the same content but different locations in the image are considered separate barcodes. */ class BarcodeItem extends _utils.PartiallyConstructible { /** Text contained in the barcode. Binary data is returned in the rawBytes field only. */ /** Barcode format. Default is NONE */ format = 'NONE'; /** The four corners of the barcode in the input image, in clockwise order starting from the top left, in image coordinates. */ /** The four corners of the barcode in the input image, in clockwise order starting from the top left, normalized to the range [0, 1]. */ /** True if this is a 1D barcode that is printed upside-down, that is, the barcode was scanned right-to-left. Default is false */ isUpsideDown = false; /** A crop from the input image containing the barcode. */ sourceImage = null; /** Raw bytes of barcode contents. Some formats can contain binary data, which is returned in this field. */ /** If this is a UPC/EAN barcode that has an EAN-2 or EAN-5 extension, this field contains the extension value. Requires the UPC_EAN_EXTENSION format to be enabled in the decoding options. */ /** True if the barcode contains a GS1 message. Requires GS1 handling to be enabled in the decoding option. Default is false */ isGS1Message = false; /** True if this result is the 2D part of a GS1 Composite barcode. Can only happen if GS1_COMPOSITE scanning is disabled and a part of the composite (1D) or (2D) is scanned separately. When GS1_COMPOSITE scanning is enabled, parts of the composite barcode are never returned separately, even if their respective format is enabled in the decoding options. Default is false */ isGS1CompositePart = false; /** The number of 1D stacks in the barcode. Applies only to DATABAR and DATABAR_EXPANDED barcodes. Default is 1 */ dataBarStackSize = 1; /** The size score is a floating point value between 0 and 1 that represents the relative size of the barcode in the input image. Barcodes taking up a small portion of the input image will have a score close to 0, while barcodes that take a large portion will have a score close to 1. Default is 0 */ sizeScore = 0.0; /** The parsed known document format (if parsed successfully). */ /** @param source {@displayType `DeepPartial<BarcodeItem>`} */ constructor(source = {}) { super(); if (source.text !== undefined) { this.text = source.text; } else { throw new Error('text must be present in constructor argument'); } if (source.format !== undefined) { this.format = source.format; } if (source.quad !== undefined) { this.quad = source.quad.map(it => { return { x: it.x, y: it.y }; }); } else { throw new Error('quad must be present in constructor argument'); } if (source.quadNormalized !== undefined) { this.quadNormalized = source.quadNormalized.map(it => { return { x: it.x, y: it.y }; }); } else { throw new Error('quadNormalized must be present in constructor argument'); } if (source.isUpsideDown !== undefined) { this.isUpsideDown = source.isUpsideDown; } if (source.sourceImage !== undefined) { this.sourceImage = source.sourceImage != null ? _image.ImageRef.From(source.sourceImage) : null; } if (source.rawBytes !== undefined) { this.rawBytes = source.rawBytes; } else { throw new Error('rawBytes must be present in constructor argument'); } if (source.upcEanExtension !== undefined) { this.upcEanExtension = source.upcEanExtension; } else { throw new Error('upcEanExtension must be present in constructor argument'); } if (source.isGS1Message !== undefined) { this.isGS1Message = source.isGS1Message; } if (source.isGS1CompositePart !== undefined) { this.isGS1CompositePart = source.isGS1CompositePart; } if (source.dataBarStackSize !== undefined) { this.dataBarStackSize = source.dataBarStackSize; } if (source.sizeScore !== undefined) { this.sizeScore = source.sizeScore; } if (source.extractedDocument !== undefined) { this.extractedDocument = source.extractedDocument != null ? new _GenericDocument.GenericDocument(source.extractedDocument) : null; } else { throw new Error('extractedDocument must be present in constructor argument'); } } async serialize(config = new _JsonSerializationTypes.ToJsonConfiguration()) { return { text: this.text, format: this.format, quad: this.quad.map(it => { return it; }), quadNormalized: this.quadNormalized.map(it => { return it; }), isUpsideDown: this.isUpsideDown, sourceImage: config.serializeImages ? this.sourceImage != null ? await this.sourceImage.serialize(config.imageSerializationMode) : null : undefined, rawBytes: this.rawBytes, upcEanExtension: this.upcEanExtension, isGS1Message: this.isGS1Message, isGS1CompositePart: this.isGS1CompositePart, dataBarStackSize: this.dataBarStackSize, sizeScore: this.sizeScore, extractedDocument: this.extractedDocument != null ? await this.extractedDocument.serialize(config) : null }; } _released = false; release() { if (this._released) { return; } { if (this.sourceImage != null) { this.sourceImage.release(); } } { if (this.extractedDocument != null) { this.extractedDocument.release(); } } this._released = true; } async encodeImages() { if (this.sourceImage != null) { await this.sourceImage.encodeInPlace(); } if (this.extractedDocument != null) { await this.extractedDocument.encodeImages(); } } } /** The engine mode for barcode scanning. - `LEGACY`: Legacy mode. Very fast, significantly less accurate. Doesn't support all barcode types. - `NEXT_GEN_LOW_POWER`: A faster version of the main engine mode, for use with low-power devices. - `NEXT_GEN`: Main engine mode for high-power devices. Supports all barcodes types. - `NEXT_GEN_LOW_POWER_FAR_DISTANCE`: Similar to NEXT_GEN_LOW_POWER, but optimized for scanning from far distances. - `NEXT_GEN_FAR_DISTANCE`: Similar to NEXT_GEN, optimized for scanning from far distances. */ exports.BarcodeItem = BarcodeItem; const BarcodeScannerEngineModeValues = exports.BarcodeScannerEngineModeValues = ['LEGACY', 'NEXT_GEN_LOW_POWER', 'NEXT_GEN', 'NEXT_GEN_LOW_POWER_FAR_DISTANCE', 'NEXT_GEN_FAR_DISTANCE']; /** Configuration for the barcode scanner. */ class BarcodeScannerConfiguration extends _utils.PartiallyConstructible { /** Options for barcode decoding. */ barcodeFormatConfigurations = [new _BarcodeConfigurationTypes.BarcodeFormatCommonConfiguration({})]; /** List of document formats to be extracted. Barcodes that decode to one of the extracted document formats will have extractedDocument field in BarcodeItem populated with the parsed document. By default all supported barcode document formats are accepted. If empty, no barcodes will be parsed into documents. To only accept the document formats listed in extractedDocumentFormats, the property onlyAcceptDocuments must be true. */ extractedDocumentFormats = ['AAMVA', 'BOARDING_PASS', 'DE_MEDICAL_PLAN', 'MEDICAL_CERTIFICATE', 'ID_CARD_PDF_417', 'SEPA', 'SWISS_QR', 'VCARD', 'GS1', 'HIBC']; /** If true and extractedDocumentFormats is not empty, then barcodes that don't decode to one of the extracted document formats will be ignored. Default is false */ onlyAcceptDocuments = false; /** If true, the barcode image will be returned in the BarcodeItem. Default is false */ returnBarcodeImage = false; /** The engine mode for barcode scanning. Default is NEXT_GEN */ engineMode = 'NEXT_GEN'; /** If true, the quads of linear (1D) barcodes will be further refined to more closely match the barcode's outline in the input image. This will also produce stabler barcode outlines across frames for use cases such as AR. Default is false */ optimizedForOverlays = false; /** @param source {@displayType `DeepPartial<BarcodeScannerConfiguration>`} */ constructor(source = {}) { super(); if (source.barcodeFormatConfigurations !== undefined) { this.barcodeFormatConfigurations = source.barcodeFormatConfigurations.map(it => { return _BarcodeConfigurationTypes.BarcodeFormatConfigurationBase.From(it); }); } if (source.extractedDocumentFormats !== undefined) { this.extractedDocumentFormats = source.extractedDocumentFormats.map(it => { return it; }); } if (source.onlyAcceptDocuments !== undefined) { this.onlyAcceptDocuments = source.onlyAcceptDocuments; } if (source.returnBarcodeImage !== undefined) { this.returnBarcodeImage = source.returnBarcodeImage; } if (source.engineMode !== undefined) { this.engineMode = source.engineMode; } if (source.optimizedForOverlays !== undefined) { this.optimizedForOverlays = source.optimizedForOverlays; } } } /** The result of barcode scanning. */ exports.BarcodeScannerConfiguration = BarcodeScannerConfiguration; class BarcodeScannerResult extends _utils.PartiallyConstructible { /** List of found barcodes. */ /** True if any barcodes were found. */ /** @param source {@displayType `DeepPartial<BarcodeScannerResult>`} */ constructor(source = {}) { super(); if (source.barcodes !== undefined) { this.barcodes = source.barcodes.map(it => { return new BarcodeItem(it); }); } else { throw new Error('barcodes must be present in constructor argument'); } if (source.success !== undefined) { this.success = source.success; } else { throw new Error('success must be present in constructor argument'); } } async serialize(config = new _JsonSerializationTypes.ToJsonConfiguration()) { return { barcodes: await Promise.all(this.barcodes.map(async it => { return await it.serialize(config); })), success: this.success }; } _released = false; release() { if (this._released) { return; } this.barcodes.forEach(it => { it.release(); }); this._released = true; } async encodeImages() { await Promise.all(this.barcodes.map(async it => { await it.encodeImages(); })); } } exports.BarcodeScannerResult = BarcodeScannerResult; //# sourceMappingURL=BarcodeScannerTypes.js.map