UNPKG

capacitor-plugin-scanbot-sdk

Version:

Scanbot Document and Barcode Scanner SDK for Capacitor

41 lines 2.42 kB
import { BarcodeDocumentParserResult, BarcodeScannerResult, BarcodeScannerUiResult, MultipleScanningMode, SingleScanningMode, handleImageInput, mapRTUUIResult, withSBErrorHandling, } from '../types'; import { ScanbotSDKPlugin } from './Definitions'; /** * @internal * @hidden */ export const ScanbotBarcodeImpl = { async scanFromImage(params) { return withSBErrorHandling(async () => new BarcodeScannerResult(await ScanbotSDKPlugin.scanBarcodesFromImage({ image: handleImageInput(params.image), configuration: params.configuration, }))); }, async scanFromPdf(params) { return withSBErrorHandling(async () => new BarcodeScannerResult(await ScanbotSDKPlugin.scanBarcodesFromPdf(params))); }, async startScanner(configuration) { if (configuration.useCase instanceof SingleScanningMode || configuration.useCase instanceof MultipleScanningMode) { const barcodeItemMapperCallback = configuration.useCase.barcodeInfoMapping.barcodeItemMapper; if (barcodeItemMapperCallback !== null) { ScanbotSDKPlugin.registerBarcodeItemMapperCallback({}, (barcodeItem) => { const barcodeItemUuid = `${barcodeItem.text}${barcodeItem.upcEanExtension}_${barcodeItem.format}`; barcodeItemMapperCallback(barcodeItem, (barcodeMappedData) => ScanbotSDKPlugin.onBarcodeItemMapper({ barcodeItemUuid, barcodeMappedData, }), () => ScanbotSDKPlugin.onBarcodeItemMapper({ barcodeItemUuid, })); }); // On iOS, the communication with the native part is throwing an error (startBarcodeScanner) because of the barcodeItemMapper // callback in the configuration class (not parsable), that's why we need to remove it before executing startBarcodeScanner method configuration.useCase.barcodeInfoMapping.barcodeItemMapper = null; } } return withSBErrorHandling(async () => mapRTUUIResult(await ScanbotSDKPlugin.startBarcodeScanner(configuration), BarcodeScannerUiResult)); }, async parseDocument(params) { return withSBErrorHandling(async () => new BarcodeDocumentParserResult(await ScanbotSDKPlugin.parseBarcodeDocument(params))); }, }; //# sourceMappingURL=BarcodeScannerImpl.js.map