Skip to content

Commit dd60ee7

Browse files
committed
feat: demo for DDS
1 parent 61573af commit dd60ee7

25 files changed

+3226
-86
lines changed

.github/workflows/main.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: CI
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Allows you to run this workflow manually from the Actions tab
8+
workflow_dispatch:
9+
10+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
11+
jobs:
12+
# This workflow contains a single job called "build"
13+
Build-Demo:
14+
if: ${{ github.ref == 'refs/heads/demo' }}
15+
16+
# The type of runner that the job will run on
17+
runs-on: self-hosted
18+
env:
19+
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
20+
21+
# Steps represent a sequence of tasks that will be executed as part of the job
22+
steps:
23+
# Runs a set of commands using the runners shell
24+
- name: Get Source
25+
run: |
26+
cd /home/ubuntu
27+
[ -d document-scanner-javascript ] && rm -rf document-scanner-javascript
28+
git clone --depth 1 -b demo https://github.com/Dynamsoft/document-scanner-javascript.git
29+
30+
- name: Prepare Files
31+
run: |
32+
# Create a temporary directory for the files to be uploaded
33+
mkdir -p /home/ubuntu/document-scanner-javascript/demo
34+
35+
# Copy the dist folder
36+
cp -r /home/ubuntu/document-scanner-javascript/dist /home/ubuntu/document-scanner-javascript/demo
37+
38+
# Copy the samples folder and rename demo.html to index.html
39+
cp -r /home/ubuntu/document-scanner-javascript/samples/* /home/ubuntu/document-scanner-javascript/demo
40+
mv /home/ubuntu/deployment/samples/demo.html /home/ubuntu/deployment/samples/index.html
41+
42+
43+
- name: Sync files
44+
uses: SamKirkland/[email protected]
45+
with:
46+
server: ${{ secrets.FTP_DEMO_SERVER }}
47+
username: ${{ secrets.FTP_DEMO_USERNAME }}
48+
password: ${{ secrets.FTP_DEMO_PASSWORD }}
49+
port: 21
50+
local-dir: /home/ubuntu/document-scanner-javascript/demo
51+
server-dir: /Demo.dynamsoft.com/document-scanner/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
dist
1+
# dist <- only for demo-video
22
node_modules

dev-server/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@ app.use(
3232

3333
// Serve static files
3434
app.use("/dist", express.static(distPath));
35+
app.use("/assets", express.static(path.join(__dirname, "../samples/assets")));
36+
app.use("/css", express.static(path.join(__dirname, "../samples/css")));
37+
app.use("/font", express.static(path.join(__dirname, "../samples/font")));
3538

3639
// Routes
3740
app.get("/", (req, res) => {
38-
res.sendFile(path.join(__dirname, "../samples/hello-world.html"));
41+
res.sendFile(path.join(__dirname, "../samples/demo.html"));
42+
});
43+
44+
app.get("/demo", (req, res) => {
45+
res.sendFile(path.join(__dirname, "../samples/demo.html"));
3946
});
4047

4148
app.get("/hello-world", (req, res) => {
@@ -122,6 +129,7 @@ httpsServer.listen(httpsPort, "0.0.0.0", () => {
122129
});
123130
console.log("\x1b[36m Available Pages:\x1b[0m");
124131
console.log("\x1b[90m-------------------\x1b[0m");
132+
console.log("\x1b[33m Demo:\x1b[0m /demo");
125133
console.log("\x1b[33m Hello World:\x1b[0m /hello-world\n");
126134

127135
console.log("\x1b[90mPress Ctrl+C to stop the server\x1b[0m\n");

dist/dds.bundle.esm.d.ts

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
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 };

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.

dist/dds.bundle.mjs

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

0 commit comments

Comments
 (0)