import { AddPageOptions, CreateDocumentOptions, CroppingConfiguration, DocumentData, DocumentQualityAnalyzerConfiguration, DocumentQualityAnalyzerResult, DocumentScannerConfiguration, DocumentScanningFlow, DocumentScanningResult, handleImageInput, ImageInput, mapRTUUIResult, ModifyPageOptions, Page, ResultWrapper, withSBErrorHandling, } from '../types'; import { isIOS, ScanbotSDKNativeModule, ScanbotSDKUINativeModule } from './ScanbotSDKModule'; /** * @internal * @hidden */ export const ScanbotDocumentImpl = { async createDocumentFromImages(params: { images?: ImageInput[]; options?: CreateDocumentOptions; }): Promise { return withSBErrorHandling( async () => new DocumentData( await ScanbotSDKNativeModule.createDocumentFromImages({ ...params, images: Array.isArray(params.images) ? handleImageInput(params.images) : undefined, }) ) ); }, async createDocumentFromLegacyPages(params: { pages: Page[]; documentImageSizeLimit?: number; }): Promise { return withSBErrorHandling( async () => new DocumentData(await ScanbotSDKNativeModule.createDocumentFromLegacyPages(params)) ); }, async createDocumentFromPdf(params: { pdfFileUri: string; options?: CreateDocumentOptions; }): Promise { return withSBErrorHandling( async () => new DocumentData(await ScanbotSDKNativeModule.createDocumentFromPdf(params)) ); }, async documentExists(documentUuid: string): Promise { return withSBErrorHandling(async () => { return await ScanbotSDKNativeModule.documentExists({ documentUuid: documentUuid }); }); }, async loadDocument(documentUuid: string): Promise { return withSBErrorHandling( async () => new DocumentData(await ScanbotSDKNativeModule.loadDocument({ documentUuid: documentUuid })) ); }, async getStoredDocumentUuids(): Promise { return withSBErrorHandling(async () => { return await ScanbotSDKNativeModule.getStoredDocumentUuids(); }); }, async cloneDocument(documentUuid: string): Promise { return withSBErrorHandling( async () => new DocumentData(await ScanbotSDKNativeModule.cloneDocument({ documentUuid: documentUuid })) ); }, async deleteDocument(documentUuid: string): Promise { return withSBErrorHandling(() => ScanbotSDKNativeModule.deleteDocument({ documentUuid: documentUuid }) ); }, async deleteAllDocuments(): Promise { return withSBErrorHandling(() => ScanbotSDKNativeModule.deleteAllDocuments()); }, async addPages(params: { documentUuid: string; images: ImageInput[]; options?: AddPageOptions; }): Promise { return withSBErrorHandling( async () => new DocumentData( await ScanbotSDKNativeModule.addPages({ ...params, images: handleImageInput(params.images), }) ) ); }, async movePage(params: { documentUuid: string; fromIndex: number; toIndex: number; }): Promise { return withSBErrorHandling( async () => new DocumentData(await ScanbotSDKNativeModule.movePage(params)) ); }, async modifyPage(params: { documentUuid: string; pageUuid: string; options?: ModifyPageOptions; }): Promise { return withSBErrorHandling( async () => new DocumentData(await ScanbotSDKNativeModule.modifyPage(params)) ); }, async removePages(params: { documentUuid: string; pageUuids: string[] }): Promise { return withSBErrorHandling( async () => new DocumentData(await ScanbotSDKNativeModule.removePagesFromDocument(params)) ); }, async removeAllPages(documentUuid: string): Promise { return withSBErrorHandling( async () => new DocumentData( await ScanbotSDKNativeModule.removeAllPages({ documentUuid: documentUuid }) ) ); }, async scanFromImage(params: { image: ImageInput; configuration: DocumentScannerConfiguration; }): Promise { return withSBErrorHandling( async () => new DocumentScanningResult( await ScanbotSDKNativeModule.scanDocumentFromImage({ configuration: params.configuration, image: handleImageInput(params.image), }) ) ); }, async analyzeQualityOnImage(params: { image: ImageInput; configuration: DocumentQualityAnalyzerConfiguration; }): Promise { return withSBErrorHandling( async () => new DocumentQualityAnalyzerResult( await ScanbotSDKNativeModule.analyzeDocumentQualityOnImage({ configuration: params.configuration, image: handleImageInput(params.image), }) ) ); }, async startScanner(configuration: DocumentScanningFlow): Promise> { return withSBErrorHandling(async () => mapRTUUIResult( await ScanbotSDKUINativeModule.startDocumentScanner( isIOS ? JSON.stringify(configuration) : configuration ), DocumentData ) ); }, async startCroppingScreen( configuration: CroppingConfiguration ): Promise> { return withSBErrorHandling(async () => mapRTUUIResult( await ScanbotSDKUINativeModule.startCroppingScreen( isIOS ? JSON.stringify(configuration) : configuration ), DocumentData ) ); }, };