Skip to content

Commit f4236de

Browse files
committed
feat: update demo to v1.1.0
1 parent ff43ef0 commit f4236de

24 files changed

+2767
-82
lines changed
Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
import { DSImageData, OriginalImageResultItem, Quadrilateral, EngineResourcePaths } 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+
declare enum EnumDDSViews {
14+
Scanner = "scanner",
15+
Result = "scan-result",
16+
Correction = "correction"
17+
}
18+
interface UtilizedTemplateNames {
19+
detect: string;
20+
normalize: string;
21+
}
22+
declare enum EnumResultStatus {
23+
RS_SUCCESS = 0,
24+
RS_CANCELLED = 1,
25+
RS_FAILED = 2
26+
}
27+
declare enum EnumFlowType {
28+
MANUAL = "manual",
29+
SMART_CAPTURE = "smartCapture",
30+
AUTO_CROP = "autoCrop",
31+
UPLOADED_IMAGE = "uploadedImage"
32+
}
33+
type ResultStatus = {
34+
code: EnumResultStatus;
35+
message?: string;
36+
};
37+
interface DocumentResult {
38+
status: ResultStatus;
39+
correctedImageResult?: NormalizedImageResultItem | DSImageData;
40+
originalImageResult?: OriginalImageResultItem["imageData"];
41+
detectedQuadrilateral?: Quadrilateral;
42+
_flowType?: EnumFlowType;
43+
}
44+
type ToolbarButtonConfig = Pick<ToolbarButton, "icon" | "label" | "className" | "isHidden">;
45+
interface ToolbarButton {
46+
id: string;
47+
icon: string;
48+
label: string;
49+
onClick?: () => void | Promise<void>;
50+
className?: string;
51+
isDisabled?: boolean;
52+
isHidden?: boolean;
53+
}
54+
55+
interface DocumentCorrectionViewToolbarButtonsConfig {
56+
fullImage?: ToolbarButtonConfig;
57+
detectBorders?: ToolbarButtonConfig;
58+
apply?: ToolbarButtonConfig;
59+
}
60+
interface DocumentCorrectionViewConfig {
61+
container?: HTMLElement | string;
62+
toolbarButtonsConfig?: DocumentCorrectionViewToolbarButtonsConfig;
63+
templateFilePath?: string;
64+
utilizedTemplateNames?: UtilizedTemplateNames;
65+
onFinish?: (result: DocumentResult) => void;
66+
_showResultView?: boolean;
67+
}
68+
declare class DocumentCorrectionView {
69+
private resources;
70+
private config;
71+
private imageEditorView;
72+
private layer;
73+
private currentCorrectionResolver?;
74+
constructor(resources: SharedResources, config: DocumentCorrectionViewConfig);
75+
initialize(): Promise<void>;
76+
private setupDrawingLayerStyle;
77+
private setupQuadConstraints;
78+
private getCanvasBounds;
79+
private addQuadToLayer;
80+
private setupInitialDetectedQuad;
81+
private createControls;
82+
private setupCorrectionControls;
83+
setFullImageBoundary(): void;
84+
setBoundaryAutomatically(): Promise<void>;
85+
confirmCorrection(): Promise<void>;
86+
launch(): Promise<DocumentResult>;
87+
hideView(): void;
88+
/**
89+
* Normalize an image with DDN given a set of points
90+
* @param points - points provided by either users or DDN's detect quad
91+
* @returns normalized image by DDN
92+
*/
93+
correctImage(points: Quadrilateral["points"]): Promise<NormalizedImageResultItem>;
94+
dispose(): void;
95+
}
96+
97+
declare enum _DEMO_CAMERA_LIST {
98+
DEMO_IDEAL_DOC = "demo1",
99+
DEMO_SIMILAR_BG = "demo2",
100+
PHYSICAL_CAMERA = "camera"
101+
}
102+
type _DEMO_CameraType = _DEMO_CAMERA_LIST;
103+
interface DocumentScannerViewConfig {
104+
_showCorrectionView?: boolean;
105+
templateFilePath?: string;
106+
cameraEnhancerUIPath?: string;
107+
container?: HTMLElement | string;
108+
utilizedTemplateNames?: UtilizedTemplateNames;
109+
}
110+
declare class DocumentScannerView {
111+
private resources;
112+
private config;
113+
private demoScanningMode;
114+
private demoScanningResolution;
115+
private boundsDetectionEnabled;
116+
private smartCaptureEnabled;
117+
private autoCropEnabled;
118+
private crossVerificationCount;
119+
private capturedResultItems;
120+
private originalImageData;
121+
private initialized;
122+
private initializedDCE;
123+
private DCE_ELEMENTS;
124+
private currentScanResolver?;
125+
private loadingScreen;
126+
private showScannerLoadingOverlay;
127+
private hideScannerLoadingOverlay;
128+
constructor(resources: SharedResources, config: DocumentScannerViewConfig);
129+
initialize(): Promise<void>;
130+
private initializeElements;
131+
private assignDCEClickEvents;
132+
handleCloseBtn(): Promise<void>;
133+
private attachOptionClickListeners;
134+
private highlightCameraAndResolutionOption;
135+
private toggleSelectCameraBox;
136+
private _demo_CheckForFakeCamera;
137+
private _demo_AddFakeCameras;
138+
private _demo_AttachFakeEventsToCameras;
139+
private _demo_playVideoWithRes;
140+
private uploadImage;
141+
private fileToBlob;
142+
toggleAutoCaptureAnimation(enabled?: boolean): Promise<void>;
143+
toggleBoundsDetection(enabled?: boolean): Promise<void>;
144+
toggleSmartCapture(mode?: boolean): Promise<void>;
145+
toggleAutoCrop(mode?: boolean): Promise<void>;
146+
private get _demo_IsFirefoxAndroid();
147+
openCamera(_demo_cameraType?: _DEMO_CameraType): Promise<void>;
148+
closeCamera(hideContainer?: boolean): void;
149+
pauseCamera(): void;
150+
stopCapturing(): void;
151+
private getFlowType;
152+
takePhoto(): Promise<void>;
153+
handleBoundsDetection(result: CapturedResult): Promise<void>;
154+
/**
155+
* Normalize an image with DDN given a set of points
156+
* @param points - points provided by either users or DDN's detect quad
157+
* @returns normalized image by DDN
158+
*/
159+
private handleAutoCaptureMode;
160+
launch(_demo_cameraType?: _DEMO_CameraType): Promise<DocumentResult>;
161+
normalizeImage(points: Quadrilateral["points"], originalImageData: OriginalImageResultItem["imageData"]): Promise<NormalizedImageResultItem>;
162+
}
163+
164+
interface DocumentResultViewToolbarButtonsConfig {
165+
retake?: ToolbarButtonConfig;
166+
correct?: ToolbarButtonConfig;
167+
share?: ToolbarButtonConfig;
168+
upload?: ToolbarButtonConfig;
169+
done?: ToolbarButtonConfig;
170+
}
171+
interface DocumentResultViewConfig {
172+
container?: HTMLElement | string;
173+
toolbarButtonsConfig?: DocumentResultViewToolbarButtonsConfig;
174+
onDone?: (result: DocumentResult) => Promise<void>;
175+
onUpload?: (result: DocumentResult) => Promise<void>;
176+
}
177+
declare class DocumentResultView {
178+
private resources;
179+
private config;
180+
private scannerView;
181+
private correctionView;
182+
private currentScanResultViewResolver?;
183+
constructor(resources: SharedResources, config: DocumentResultViewConfig, scannerView: DocumentScannerView, correctionView: DocumentCorrectionView);
184+
launch(): Promise<DocumentResult>;
185+
private handleUploadAndShareBtn;
186+
private handleShare;
187+
private handleCorrectImage;
188+
private handleRetake;
189+
private handleDone;
190+
private createControls;
191+
initialize(): Promise<void>;
192+
hideView(): void;
193+
dispose(preserveResolver?: boolean): void;
194+
}
195+
196+
interface DocumentScannerConfig {
197+
license?: string;
198+
container?: HTMLElement | string;
199+
templateFilePath?: string;
200+
utilizedTemplateNames?: UtilizedTemplateNames;
201+
engineResourcePaths?: EngineResourcePaths;
202+
scannerViewConfig?: Omit<DocumentScannerViewConfig, "templateFilePath" | "utilizedTemplateNames" | "_showCorrectionView">;
203+
resultViewConfig?: DocumentResultViewConfig;
204+
correctionViewConfig?: Omit<DocumentCorrectionViewConfig, "templateFilePath" | "utilizedTemplateNames" | "_showCorrectionView">;
205+
showResultView?: boolean;
206+
showCorrectionView?: boolean;
207+
}
208+
interface SharedResources {
209+
cvRouter?: CaptureVisionRouter;
210+
cameraEnhancer?: CameraEnhancer;
211+
cameraView?: CameraView;
212+
result?: DocumentResult;
213+
onResultUpdated?: (result: DocumentResult) => void;
214+
}
215+
declare class DocumentScanner {
216+
private config;
217+
private scannerView?;
218+
private scanResultView?;
219+
private correctionView?;
220+
private resources;
221+
private isInitialized;
222+
private isCapturing;
223+
constructor(config: DocumentScannerConfig);
224+
initialize(): Promise<{
225+
resources: SharedResources;
226+
components: {
227+
scannerView?: DocumentScannerView;
228+
correctionView?: DocumentCorrectionView;
229+
scanResultView?: DocumentResultView;
230+
};
231+
}>;
232+
private initializeDCVResources;
233+
private shouldCreateDefaultContainer;
234+
private createDefaultDDSContainer;
235+
private checkForTemporaryLicense;
236+
private validateViewConfigs;
237+
private showCorrectionView;
238+
private showResultView;
239+
private initializeDDSConfig;
240+
private createViewContainers;
241+
dispose(): void;
242+
/**
243+
* Launches the document scanning process.
244+
*
245+
* Configuration Requirements:
246+
* 1. A container must be provided either through:
247+
* - A main container in config.container, OR
248+
* - Individual view containers in viewConfig.container when corresponding show flags are true
249+
* 2. If no main container is provided:
250+
* - showCorrectionView: true requires correctionViewConfig.container
251+
* - showResultView: true requires resultViewConfig.container
252+
*
253+
* Flow paths based on view configurations and capture method:
254+
*
255+
* 1. All views enabled (Scanner, Correction, Result):
256+
* A. Auto-capture paths:
257+
* - Smart Capture: Scanner -> Correction -> Result
258+
* - Auto Crop: Scanner -> Result
259+
* B. Manual paths:
260+
* - Upload Image: Scanner -> Correction -> Result
261+
* - Manual Capture: Scanner -> Result
262+
*
263+
* 2. Scanner + Result only:
264+
* - Flow: Scanner -> Result
265+
* - Requires: showCorrectionView: false or undefined
266+
*
267+
* 3. Scanner + Correction only:
268+
* - Flow: Scanner -> Correction
269+
* - Requires: showResultView: false or undefined
270+
*
271+
* 4. Special cases:
272+
* - Scanner only: Returns scan result directly
273+
* - Correction only + existing result: Goes to Correction
274+
* - Result only + existing result: Goes to Result
275+
*
276+
* @returns Promise<DocumentResult> containing:
277+
* - status: Success/Failed/Cancelled with message
278+
* - originalImageResult: Raw captured image
279+
* - correctedImageResult: Normalized image (if correction applied)
280+
* - detectedQuadrilateral: Document boundaries
281+
* - _flowType: Internal routing flag for different capture methods
282+
*
283+
* @throws Error if:
284+
* - Capture session is already running
285+
* - Scanner view is required but not configured
286+
* - No container is provided when showCorrectionView or showResultView is true
287+
*/
288+
launch(_demo_cameraType?: _DEMO_CameraType): Promise<DocumentResult>;
289+
}
290+
291+
declare const DDS: {
292+
DocumentScanner: typeof DocumentScanner;
293+
DocumentNormalizerView: typeof DocumentCorrectionView;
294+
DocumentScannerView: typeof DocumentScannerView;
295+
DocumentResultView: typeof DocumentResultView;
296+
EnumResultStatus: typeof EnumResultStatus;
297+
EnumFlowType: typeof EnumFlowType;
298+
EnumDDSViews: typeof EnumDDSViews;
299+
};
300+
301+
export { DDS, DocumentCorrectionViewConfig, DocumentCorrectionViewToolbarButtonsConfig, DocumentCorrectionView as DocumentNormalizerView, DocumentResult, DocumentResultView, DocumentResultViewConfig, DocumentResultViewToolbarButtonsConfig, DocumentScanner, DocumentScannerConfig, DocumentScannerView, DocumentScannerViewConfig, EnumResultStatus, ResultStatus, SharedResources, ToolbarButtonConfig, UtilizedTemplateNames };

.github/workflows/dist/dds.bundle.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/dist/dds.bundle.mjs

Lines changed: 11 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)