UNPKG

capacitor-plugin-scanbot-barcode-scanner-sdk

Version:

Scanbot Barcode Scanner SDK for Capacitor

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