|
| 1 | +import { DSImageData, OriginalImageResultItem, Quadrilateral } from 'dynamsoft-core'; |
| 2 | +export * from 'dynamsoft-core'; |
| 3 | +export * from 'dynamsoft-license'; |
| 4 | +import { CapturedResult, CaptureVisionRouter } from 'dynamsoft-capture-vision-router'; |
| 5 | +export * from 'dynamsoft-capture-vision-router'; |
| 6 | +import { CameraEnhancer, CameraView } from 'dynamsoft-camera-enhancer'; |
| 7 | +export * from 'dynamsoft-camera-enhancer'; |
| 8 | +import { NormalizedImageResultItem } from 'dynamsoft-document-normalizer'; |
| 9 | +export * from 'dynamsoft-document-normalizer'; |
| 10 | +export * from 'dynamsoft-utility'; |
| 11 | +export { NormalizedImageResultItem, PlayCallbackInfo, Point, Rect, VideoDeviceInfo } from 'dynamsoft-capture-vision-bundle'; |
| 12 | + |
| 13 | +interface UtilizedTemplateNames { |
| 14 | + detect: string; |
| 15 | + normalize: string; |
| 16 | +} |
| 17 | +declare enum EnumResultStatus { |
| 18 | + RS_SUCCESS = 0, |
| 19 | + RS_CANCELLED = 1, |
| 20 | + RS_FAILED = 2 |
| 21 | +} |
| 22 | +declare enum EnumFlowType { |
| 23 | + MANUAL = "manual", |
| 24 | + SMART_CAPTURE = "smartCapture", |
| 25 | + AUTO_CROP = "autoCrop", |
| 26 | + UPLOADED_IMAGE = "uploadedImage" |
| 27 | +} |
| 28 | +type ResultStatus = { |
| 29 | + code: EnumResultStatus; |
| 30 | + message?: string; |
| 31 | +}; |
| 32 | +interface DocumentScanResult { |
| 33 | + status: ResultStatus; |
| 34 | + correctedImageResult?: NormalizedImageResultItem | DSImageData; |
| 35 | + originalImageResult?: OriginalImageResultItem["imageData"]; |
| 36 | + detectedQuadrilateral?: Quadrilateral; |
| 37 | + _flowType?: EnumFlowType; |
| 38 | +} |
| 39 | +interface ControlButton { |
| 40 | + icon: string; |
| 41 | + text: string; |
| 42 | + onClick?: () => void | Promise<void>; |
| 43 | + disabled?: boolean; |
| 44 | +} |
| 45 | + |
| 46 | +interface DocumentCorrectionViewControlIcons { |
| 47 | + fullImageBtn?: Pick<ControlButton, "icon" | "text">; |
| 48 | + detectBordersBtn?: Pick<ControlButton, "icon" | "text">; |
| 49 | + applyBtn?: Pick<ControlButton, "icon" | "text">; |
| 50 | + containerStyle?: Partial<CSSStyleDeclaration>; |
| 51 | +} |
| 52 | +interface DocumentCorrectionViewConfig { |
| 53 | + container?: HTMLElement; |
| 54 | + controlIcons?: DocumentCorrectionViewControlIcons; |
| 55 | + templateFilePath?: string; |
| 56 | + utilizedTemplateNames?: UtilizedTemplateNames; |
| 57 | + onFinish?: (result: DocumentScanResult) => void; |
| 58 | +} |
| 59 | +declare class DocumentCorrectionView { |
| 60 | + private resources; |
| 61 | + private config; |
| 62 | + private imageEditorView; |
| 63 | + private layer; |
| 64 | + private currentCorrectionResolver?; |
| 65 | + constructor(resources: SharedResources, config: DocumentCorrectionViewConfig); |
| 66 | + initialize(): Promise<void>; |
| 67 | + private setupDrawingLayerStyle; |
| 68 | + private setupQuadConstraints; |
| 69 | + private getCanvasBounds; |
| 70 | + private addQuadToLayer; |
| 71 | + private setupInitialDetectedQuad; |
| 72 | + private createControls; |
| 73 | + private setupCorrectionControls; |
| 74 | + setFullImageBoundary(): void; |
| 75 | + setBoundaryAutomatically(): Promise<void>; |
| 76 | + confirmCorrection(): Promise<void>; |
| 77 | + launch(): Promise<DocumentScanResult>; |
| 78 | + hideView(): void; |
| 79 | + /** |
| 80 | + * Normalize an image with DDN given a set of points |
| 81 | + * @param points - points provided by either users or DDN's detect quad |
| 82 | + * @returns normalized image by DDN |
| 83 | + */ |
| 84 | + correctImage(points: Quadrilateral["points"]): Promise<NormalizedImageResultItem>; |
| 85 | + dispose(): void; |
| 86 | +} |
| 87 | + |
| 88 | +declare enum _DEMO_CAMERA_LIST { |
| 89 | + DEMO_IDEAL_DOC = "demo1", |
| 90 | + DEMO_SIMILAR_BG = "demo2", |
| 91 | + PHYSICAL_CAMERA = "camera" |
| 92 | +} |
| 93 | +type _DEMO_CameraType = _DEMO_CAMERA_LIST; |
| 94 | +interface DocumentScannerViewConfig { |
| 95 | + templateFilePath?: string; |
| 96 | + cameraEnhancerUIPath?: string; |
| 97 | + container?: HTMLElement; |
| 98 | + utilizedTemplateNames?: UtilizedTemplateNames; |
| 99 | +} |
| 100 | +declare class DocumentScannerView { |
| 101 | + private resources; |
| 102 | + private config; |
| 103 | + private demoScanningMode; |
| 104 | + private demoScanningResolution; |
| 105 | + private boundsDetectionEnabled; |
| 106 | + private smartCaptureEnabled; |
| 107 | + private autoCropEnabled; |
| 108 | + private crossVerificationCount; |
| 109 | + private capturedResultItems; |
| 110 | + private originalImageData; |
| 111 | + private initialized; |
| 112 | + private initializedDCE; |
| 113 | + private DCE_ELEMENTS; |
| 114 | + private currentScanResolver?; |
| 115 | + private loadingScreen; |
| 116 | + private showScannerLoadingOverlay; |
| 117 | + private hideScannerLoadingOverlay; |
| 118 | + constructor(resources: SharedResources, config: DocumentScannerViewConfig); |
| 119 | + initialize(): Promise<void>; |
| 120 | + private initializeElements; |
| 121 | + private assignDCEClickEvents; |
| 122 | + handleCloseBtn(): Promise<void>; |
| 123 | + private attachOptionClickListeners; |
| 124 | + private highlightCameraAndResolutionOption; |
| 125 | + private toggleSelectCameraBox; |
| 126 | + private _demo_CheckForFakeCamera; |
| 127 | + private _demo_AddFakeCameras; |
| 128 | + private _demo_AttachFakeEventsToCameras; |
| 129 | + private _demo_playVideoWithRes; |
| 130 | + private uploadImage; |
| 131 | + private fileToBlob; |
| 132 | + toggleAutoCaptureAnimation(enabled?: boolean): Promise<void>; |
| 133 | + toggleBoundsDetection(enabled?: boolean): Promise<void>; |
| 134 | + toggleSmartCapture(mode?: boolean): Promise<void>; |
| 135 | + toggleAutoCrop(mode?: boolean): Promise<void>; |
| 136 | + private get _demo_IsFirefoxAndroid(); |
| 137 | + openCamera(_demo_cameraType?: _DEMO_CameraType): Promise<void>; |
| 138 | + closeCamera(hideContainer?: boolean): void; |
| 139 | + pauseCamera(): void; |
| 140 | + stopCapturing(): void; |
| 141 | + private getFlowType; |
| 142 | + takePhoto(): Promise<void>; |
| 143 | + handleBoundsDetection(result: CapturedResult): Promise<void>; |
| 144 | + /** |
| 145 | + * Normalize an image with DDN given a set of points |
| 146 | + * @param points - points provided by either users or DDN's detect quad |
| 147 | + * @returns normalized image by DDN |
| 148 | + */ |
| 149 | + private handleAutoCaptureMode; |
| 150 | + launch(_demo_cameraType?: _DEMO_CameraType): Promise<DocumentScanResult>; |
| 151 | + normalizeImage(points: Quadrilateral["points"], originalImageData: OriginalImageResultItem["imageData"]): Promise<NormalizedImageResultItem>; |
| 152 | +} |
| 153 | + |
| 154 | +interface ScanResultViewControlIcons { |
| 155 | + uploadBtn?: Pick<ControlButton, "icon" | "text">; |
| 156 | + correctImageBtn?: Pick<ControlButton, "icon" | "text">; |
| 157 | + retakeBtn?: Pick<ControlButton, "icon" | "text">; |
| 158 | + doneBtn?: Pick<ControlButton, "icon" | "text">; |
| 159 | + containerStyle?: Partial<CSSStyleDeclaration>; |
| 160 | +} |
| 161 | +interface ScanResultViewConfig { |
| 162 | + container?: HTMLElement; |
| 163 | + controlIcons?: ScanResultViewControlIcons; |
| 164 | + onDone?: (result: DocumentScanResult) => Promise<void>; |
| 165 | + onUpload?: (result: DocumentScanResult) => Promise<void>; |
| 166 | +} |
| 167 | +declare class ScanResultView { |
| 168 | + private resources; |
| 169 | + private config; |
| 170 | + private scannerView; |
| 171 | + private correctionView; |
| 172 | + private container; |
| 173 | + private currentScanResultViewResolver?; |
| 174 | + constructor(resources: SharedResources, config: ScanResultViewConfig, scannerView: DocumentScannerView, correctionView: DocumentCorrectionView); |
| 175 | + launch(): Promise<DocumentScanResult>; |
| 176 | + private handleUploadAndShareBtn; |
| 177 | + private handleShare; |
| 178 | + private handleCorrectImage; |
| 179 | + private handleRetake; |
| 180 | + private handleDone; |
| 181 | + private createControls; |
| 182 | + initialize(): Promise<void>; |
| 183 | + hideView(): void; |
| 184 | + dispose(preserveResolver?: boolean): void; |
| 185 | +} |
| 186 | + |
| 187 | +interface DocumentScannerConfig { |
| 188 | + license?: string; |
| 189 | + container?: HTMLElement | string; |
| 190 | + scannerViewConfig?: DocumentScannerViewConfig; |
| 191 | + scanResultViewConfig?: ScanResultViewConfig; |
| 192 | + correctionViewConfig?: DocumentCorrectionViewConfig; |
| 193 | + utilizedTemplateNames?: UtilizedTemplateNames; |
| 194 | +} |
| 195 | +interface SharedResources { |
| 196 | + cvRouter?: CaptureVisionRouter; |
| 197 | + cameraEnhancer?: CameraEnhancer; |
| 198 | + cameraView?: CameraView; |
| 199 | + result?: DocumentScanResult; |
| 200 | + onResultUpdated?: (result: DocumentScanResult) => void; |
| 201 | +} |
| 202 | +declare class DocumentScanner { |
| 203 | + private config; |
| 204 | + private scannerView?; |
| 205 | + private scanResultView?; |
| 206 | + private correctionView?; |
| 207 | + private resources; |
| 208 | + private isCapturing; |
| 209 | + private shouldCreateDefaultContainer; |
| 210 | + private createDefaultDDSContainer; |
| 211 | + private createViewContainers; |
| 212 | + constructor(config: DocumentScannerConfig); |
| 213 | + initializeConfig(): Promise<void>; |
| 214 | + initialize(): Promise<{ |
| 215 | + resources: SharedResources; |
| 216 | + components: { |
| 217 | + scannerView?: DocumentScannerView; |
| 218 | + correctionView?: DocumentCorrectionView; |
| 219 | + scanResultView?: ScanResultView; |
| 220 | + }; |
| 221 | + }>; |
| 222 | + private initializeResources; |
| 223 | + dispose(): void; |
| 224 | + /** |
| 225 | + * Launches the document scanning process. |
| 226 | + * |
| 227 | + * Flow paths based on which view containers are configured and the capture method: |
| 228 | + * |
| 229 | + * View Container Configurations |
| 230 | + * 1. All views present (Scanner, Correction, ScanResult) |
| 231 | + * Flow: |
| 232 | + * A. Auto-capture paths: |
| 233 | + * - Smart Capture: Scanner -> Correction -> ScanResult |
| 234 | + * - Auto Crop: Scanner -> ScanResult |
| 235 | + * |
| 236 | + * B. Manual paths: |
| 237 | + * - Upload Image: Scanner -> Correction -> ScanResult |
| 238 | + * - Manual Capture: Scanner -> ScanResult |
| 239 | + * 2. Scanner + ScanResult |
| 240 | + * Flow: Scanner -> ScanResult |
| 241 | + * |
| 242 | + * 3. Scanner + Correction |
| 243 | + * Flow: Scanner -> Correction |
| 244 | + * |
| 245 | + * 4. Special cases: |
| 246 | + * - Only Scanner available: Returns scan result directly |
| 247 | + * - Only Correction available + existing result: Goes to Correction |
| 248 | + * - Only ScanResult available + existing result: Goes to ScanResult |
| 249 | + * |
| 250 | + * @returns Promise<DocumentScanResult> containing: |
| 251 | + * - status: Success/Failed/Cancelled with message |
| 252 | + * - originalImageResult: Raw captured image |
| 253 | + * - correctedImageResult: Normalized image (if correction applied) |
| 254 | + * - detectedQuadrilateral: Document boundaries |
| 255 | + * - _flowType: Internal routing flag for different capture methods |
| 256 | + * |
| 257 | + * @throws Error if capture session already running |
| 258 | + */ |
| 259 | + launch(_demo_cameraType?: _DEMO_CameraType): Promise<DocumentScanResult>; |
| 260 | + /** |
| 261 | + * Checks if a capture session is currently in progress |
| 262 | + */ |
| 263 | + isCapturingImage(): boolean; |
| 264 | +} |
| 265 | + |
| 266 | +declare const DDS: { |
| 267 | + DocumentScanner: typeof DocumentScanner; |
| 268 | + DocumentNormalizerView: typeof DocumentCorrectionView; |
| 269 | + DocumentScannerView: typeof DocumentScannerView; |
| 270 | + ScanResultView: typeof ScanResultView; |
| 271 | + EnumResultStatus: typeof EnumResultStatus; |
| 272 | +}; |
| 273 | + |
| 274 | +export { ControlButton, DDS, DocumentCorrectionViewConfig, DocumentCorrectionViewControlIcons, DocumentCorrectionView as DocumentNormalizerView, DocumentScanResult, DocumentScanner, DocumentScannerConfig, DocumentScannerView, DocumentScannerViewConfig, EnumFlowType, EnumResultStatus, ResultStatus, ScanResultView, ScanResultViewConfig, ScanResultViewControlIcons, SharedResources, UtilizedTemplateNames }; |
0 commit comments