veryfi-lens-wasm 3.2.1 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/anydocPageControls.js +5 -1
- package/components/croppedImage.js +32 -11
- package/components/croppedImageLayouts.js +47 -33
- package/components/fieldDetectionMessages.js +6 -8
- package/components/fieldDetectionOverlay.js +9 -4
- package/components/fieldDetectionScanOverlay.js +40 -14
- package/components/greenBox.js +11 -0
- package/components/multiCaptureModal.js +23 -0
- package/components/previewLayout.js +98 -0
- package/components/submitButton.js +7 -0
- package/components/video.js +12 -0
- package/core/api.js +48 -2
- package/core/capture/anydoc.js +17 -26
- package/core/capture/checks.js +3 -0
- package/core/capture/document.js +8 -3
- package/core/capture/prescription_label.js +21 -5
- package/core/constants.js +17 -3
- package/core/crop-field-detection.js +35 -6
- package/core/field-detection-policy.js +10 -0
- package/core/field-detection.js +11 -2
- package/core/lifecycle.js +36 -2
- package/core/multi-submission.js +90 -0
- package/core/state.js +45 -0
- package/core/tesseract-ocr.js +2 -1
- package/core/ui-core.js +8 -0
- package/core/validation.js +4 -0
- package/core/wasm-processing.js +2 -1
- package/package.json +1 -1
- package/veryfi-lens.js +11 -4
package/core/capture/anydoc.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { state } from '../state.js';
|
|
2
2
|
import { handleSubmit, ensurePackageUploaded, fireResultSetter } from '../api.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { createVideo } from '../../components/video.js';
|
|
3
|
+
import { removeOverlay, restartCameraForNextCapture } from '../lifecycle.js';
|
|
4
|
+
import { promptForAnotherCapture } from '../multi-submission.js';
|
|
6
5
|
import { createAnydocPageControls } from '../../components/anydocPageControls.js';
|
|
7
6
|
|
|
8
7
|
export const handleAnydocPageCapture = () => {
|
|
@@ -31,28 +30,7 @@ export const handleAnydocPageCapture = () => {
|
|
|
31
30
|
async () => {
|
|
32
31
|
state.debug_mode && console.log('Add page clicked, restarting camera');
|
|
33
32
|
state.anydocPageControls?.hide();
|
|
34
|
-
|
|
35
|
-
if (state.cropImgRef.previewImg) {
|
|
36
|
-
state.cropImgRef.previewImg.style.display = 'none';
|
|
37
|
-
state.cropImgRef.previewImg.style.top = '';
|
|
38
|
-
state.cropImgRef.previewImg.style.left = '';
|
|
39
|
-
state.cropImgRef.previewImg.style.transform = '';
|
|
40
|
-
state.cropImgRef.previewImg.src = '';
|
|
41
|
-
}
|
|
42
|
-
const ctx = state.cropImgRef.getContext("2d");
|
|
43
|
-
ctx.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
|
|
44
|
-
state.cropImgRef.hideBorder?.();
|
|
45
|
-
}
|
|
46
|
-
if (!state.videoRef) {
|
|
47
|
-
state.videoRef = document.getElementById("veryfi-video-ref");
|
|
48
|
-
if (!state.videoRef && state.container) {
|
|
49
|
-
createVideo(state.container);
|
|
50
|
-
await new Promise(resolve => setTimeout(resolve, 10));
|
|
51
|
-
state.videoRef = document.getElementById("veryfi-video-ref");
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
showVideoOverlay();
|
|
55
|
-
await newStartLens();
|
|
33
|
+
await restartCameraForNextCapture();
|
|
56
34
|
},
|
|
57
35
|
async () => {
|
|
58
36
|
state.debug_mode && console.log(`Submitting ${state.anydocPages.length} anydoc pages`);
|
|
@@ -70,6 +48,16 @@ export const handleAnydocPageCapture = () => {
|
|
|
70
48
|
// upload the cumulative zip now and surface bucket/package_path
|
|
71
49
|
// through the showCamera setter.
|
|
72
50
|
await fireResultSetter({ image: state.finalImage });
|
|
51
|
+
} else if (state.multiSubmission) {
|
|
52
|
+
// Multi-submission QR: submit this document, then ask whether another
|
|
53
|
+
// capture is needed instead of tearing the overlay down. autoCloseOnSubmit
|
|
54
|
+
// is false below so teardown is owned here.
|
|
55
|
+
const result = await handleSubmit(state.finalImage);
|
|
56
|
+
if (result) {
|
|
57
|
+
promptForAnotherCapture(restartCameraForNextCapture);
|
|
58
|
+
} else {
|
|
59
|
+
removeOverlay();
|
|
60
|
+
}
|
|
73
61
|
} else {
|
|
74
62
|
handleSubmit(state.finalImage);
|
|
75
63
|
}
|
|
@@ -79,7 +67,8 @@ export const handleAnydocPageCapture = () => {
|
|
|
79
67
|
addPageText: state.anydocAddPageText,
|
|
80
68
|
submitText: partnerDriven ? 'Done' : state.anydocSubmitText,
|
|
81
69
|
onClose: state.onClose,
|
|
82
|
-
onCloseRedirectUrl: state.onCloseRedirectUrl
|
|
70
|
+
onCloseRedirectUrl: state.onCloseRedirectUrl,
|
|
71
|
+
autoCloseOnSubmit: !state.multiSubmission,
|
|
83
72
|
}
|
|
84
73
|
);
|
|
85
74
|
|
|
@@ -104,4 +93,6 @@ export const handleAnydocPageCapture = () => {
|
|
|
104
93
|
const showControls = state.enableSubmit || state.packageMode;
|
|
105
94
|
showControls && state.anydocPageControls.show(pageNum, canAddMore, state.anydocPages, state.cropImgRef);
|
|
106
95
|
}
|
|
96
|
+
|
|
97
|
+
state.cropImgRef?.setRectangleDisplay?.();
|
|
107
98
|
};
|
package/core/capture/checks.js
CHANGED
|
@@ -7,6 +7,7 @@ import { newStartLens, removeOverlay } from '../lifecycle.js';
|
|
|
7
7
|
import { createSubmitButton } from '../../components/submitButton.js';
|
|
8
8
|
import { createCheckCaptureModal } from '../../components/checkCaptureModal.js';
|
|
9
9
|
import { createCheckImages } from '../../components/checkImages.js';
|
|
10
|
+
import { revealCropPreview } from '../../components/croppedImage.js';
|
|
10
11
|
|
|
11
12
|
export const handleChecksFrontAccepted = async () => {
|
|
12
13
|
state.blurStatus = false;
|
|
@@ -81,6 +82,8 @@ export const handleChecksFrontAccepted = async () => {
|
|
|
81
82
|
},
|
|
82
83
|
state.enforceBothSides ? null : () => {
|
|
83
84
|
hideVideoOverlay();
|
|
85
|
+
state.cropImgRef?.setCheckDisplay?.();
|
|
86
|
+
revealCropPreview(state.cropImgRef?.previewImg);
|
|
84
87
|
if (state.isDocument) {
|
|
85
88
|
state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
|
|
86
89
|
if (typeof state.customSubmitHandler === 'function') {
|
package/core/capture/document.js
CHANGED
|
@@ -3,7 +3,8 @@ import { cropWasm } from '../wasm-processing.js';
|
|
|
3
3
|
import { checkIfDocumentOnCapture, checkIfBlurOnCapture, checkIfLcdOnCapture } from '../validation.js';
|
|
4
4
|
import { docReady, handleSubmit, ensurePackageUploaded, fireResultSetter } from '../api.js';
|
|
5
5
|
import { hideVideoOverlay } from '../overlay-controls.js';
|
|
6
|
-
import { stopLens, startStitching, stopStitching, removeOverlay } from '../lifecycle.js';
|
|
6
|
+
import { stopLens, startStitching, stopStitching, removeOverlay, restartCameraForNextCapture } from '../lifecycle.js';
|
|
7
|
+
import { promptForAnotherCapture } from '../multi-submission.js';
|
|
7
8
|
import { onCropPreviewReady, holdSubmitForFieldDetectionIfNeeded } from '../crop-field-detection.js';
|
|
8
9
|
import { generateDeviceIDifNeeded } from '../device.js';
|
|
9
10
|
import { createSubmitButton } from '../../components/submitButton.js';
|
|
@@ -273,11 +274,15 @@ export const newCapture = async () => {
|
|
|
273
274
|
const packageInfo = await ensurePackageUploaded();
|
|
274
275
|
state.customSubmitHandler(state.finalImage, packageInfo);
|
|
275
276
|
} else {
|
|
276
|
-
await handleSubmit(state.finalImage);
|
|
277
|
+
const result = await handleSubmit(state.finalImage);
|
|
278
|
+
if (state.multiSubmission && result) {
|
|
279
|
+
state.submitButton?.hide?.();
|
|
280
|
+
promptForAnotherCapture(restartCameraForNextCapture);
|
|
281
|
+
}
|
|
277
282
|
}
|
|
278
283
|
},
|
|
279
284
|
removeOverlay,
|
|
280
|
-
{ buttonText: partnerDriven ? 'Done' : 'Submit' }
|
|
285
|
+
{ buttonText: partnerDriven ? 'Done' : 'Submit', autoClose: !state.multiSubmission }
|
|
281
286
|
);
|
|
282
287
|
(state.enableSubmit || partnerDriven) && state.submitButton.show();
|
|
283
288
|
holdSubmitForFieldDetectionIfNeeded();
|
|
@@ -2,6 +2,7 @@ import { state } from '../state.js';
|
|
|
2
2
|
import { handleSubmit, addPackageScan, ensurePackageUploaded } from '../api.js';
|
|
3
3
|
import { hideVideoOverlay, showVideoOverlay } from '../overlay-controls.js';
|
|
4
4
|
import { removeOverlay, newStartLens } from '../lifecycle.js';
|
|
5
|
+
import { promptForAnotherCapture } from '../multi-submission.js';
|
|
5
6
|
import { createSubmitButton } from '../../components/submitButton.js';
|
|
6
7
|
|
|
7
8
|
let previewRecorder = null;
|
|
@@ -480,18 +481,20 @@ const submitVideoBlob = async (videoBlob) => {
|
|
|
480
481
|
state.updateHandler?.({ status: 'processing_completed' });
|
|
481
482
|
|
|
482
483
|
const uploadStartTime = performance.now();
|
|
484
|
+
let submitResult;
|
|
483
485
|
if (typeof state.customSubmitHandler === 'function') {
|
|
484
486
|
const packageInfo = await ensurePackageUploaded();
|
|
485
487
|
state.customSubmitHandler(videoBlob, packageInfo);
|
|
488
|
+
submitResult = videoBlob;
|
|
486
489
|
} else {
|
|
487
|
-
await handleSubmit(submitData);
|
|
490
|
+
submitResult = await handleSubmit(submitData);
|
|
488
491
|
}
|
|
489
492
|
const uploadDurationSec = (performance.now() - uploadStartTime) / 1000;
|
|
490
493
|
const totalDurationSec = (performance.now() - submissionStartTime) / 1000;
|
|
491
494
|
console.log(`[prescription_label] submission complete — total: ${totalDurationSec.toFixed(2)}s, upload: ${uploadDurationSec.toFixed(2)}s, video: ${(videoBlob.size / 1024).toFixed(1)} KB`);
|
|
492
495
|
|
|
493
496
|
state.updateHandler?.({ status: 'capture_completed' });
|
|
494
|
-
return
|
|
497
|
+
return submitResult;
|
|
495
498
|
};
|
|
496
499
|
|
|
497
500
|
export const capturePrescriptionLabel = async () => {
|
|
@@ -532,13 +535,26 @@ export const capturePrescriptionLabel = async () => {
|
|
|
532
535
|
isBase64: false,
|
|
533
536
|
});
|
|
534
537
|
|
|
538
|
+
const restartPrescription = async () => {
|
|
539
|
+
cleanupPreview();
|
|
540
|
+
showVideoOverlay();
|
|
541
|
+
state.prescriptionLabelGuide?.show?.();
|
|
542
|
+
await newStartLens();
|
|
543
|
+
};
|
|
544
|
+
|
|
535
545
|
state.submitButton = createSubmitButton(
|
|
536
546
|
state.container,
|
|
537
547
|
async () => {
|
|
538
|
-
await submitVideoBlob(submissionBlob);
|
|
539
|
-
|
|
548
|
+
const result = await submitVideoBlob(submissionBlob);
|
|
549
|
+
if (state.multiSubmission && result) {
|
|
550
|
+
state.submitButton?.hide?.();
|
|
551
|
+
promptForAnotherCapture(restartPrescription);
|
|
552
|
+
} else {
|
|
553
|
+
removeOverlay();
|
|
554
|
+
}
|
|
540
555
|
},
|
|
541
|
-
() => {}
|
|
556
|
+
() => {},
|
|
557
|
+
{ autoClose: false }
|
|
542
558
|
);
|
|
543
559
|
const submitBtnEl = document.getElementById('veryfi-submit-button');
|
|
544
560
|
if (submitBtnEl) {
|
package/core/constants.js
CHANGED
|
@@ -15,6 +15,7 @@ const buildApiUrls = (base) => ({
|
|
|
15
15
|
SEND_CROPPED: `${base}/rest/send-cropped`,
|
|
16
16
|
SEND_PACKAGE: `${base}/rest/send-package`,
|
|
17
17
|
PROCESS_DOCUMENT: `${base}/api/document`,
|
|
18
|
+
FINISH_BATCH: `${base}/api/finish`,
|
|
18
19
|
BLUEPRINTS: `${base}/api/blueprints`,
|
|
19
20
|
FINGERPRINT: 'https://fp.veryfi.com',
|
|
20
21
|
FINGERPRINT_SCRIPT: 'https://fp.veryfi.com/web/v<version>/<apiKey>/loader_v<loaderVersion>.js',
|
|
@@ -27,12 +28,18 @@ export const API_URLS = buildApiUrls(API_BASES.PROD);
|
|
|
27
28
|
|
|
28
29
|
export const setApiEnvironment = (useDevApi) => {
|
|
29
30
|
const base = useDevApi ? API_BASES.DEV : API_BASES.PROD;
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
setApiBaseUrl(base);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Point all SDK API and WASM requests at a specific LFB origin (e.g. local Docker). */
|
|
35
|
+
export const setApiBaseUrl = (base) => {
|
|
36
|
+
const normalized = String(base || '').replace(/\/$/, '');
|
|
37
|
+
Object.assign(API_URLS, buildApiUrls(normalized));
|
|
38
|
+
WASM.BASE_URL = `${normalized}${WASM_PATH}`;
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
export const DEFAULTS = {
|
|
35
|
-
SDK_VERSION: '3.2
|
|
42
|
+
SDK_VERSION: '3.3.2',
|
|
36
43
|
BLUR_THRESHOLD: 0.7,
|
|
37
44
|
LCD_THRESHOLD: 0.5,
|
|
38
45
|
BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
|
|
@@ -86,6 +93,13 @@ export const MESSAGES = {
|
|
|
86
93
|
ANYDOC_SUBMIT: 'Submit',
|
|
87
94
|
ANYDOC_FLIP: 'Please flip the document and capture the other side',
|
|
88
95
|
ANYDOC_FLIP_CONTINUE: 'Continue',
|
|
96
|
+
MULTI_CAPTURE_PROMPT: 'Do you need to capture another document?',
|
|
97
|
+
MULTI_CAPTURE_YES: 'Capture another',
|
|
98
|
+
MULTI_CAPTURE_NO: "No, I'm done",
|
|
99
|
+
BATCH_FINISHING: 'Completing batch...',
|
|
100
|
+
BATCH_FINISH_FAILED: 'Failed to notify your system. Would you like to try again?',
|
|
101
|
+
BATCH_FINISH_RETRY: 'Retry',
|
|
102
|
+
BATCH_FINISH_CANCEL: 'Close without notifying',
|
|
89
103
|
AUTH_FAILED: 'Authorization failed, please provide correct client-id or contact customer support at support@veryfi.com',
|
|
90
104
|
AUTH_FAILED_CONTACT: 'Authorization failed, please contact customer support at support@veryfi.com',
|
|
91
105
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { state, refs } from './state.js';
|
|
2
2
|
import { detectDocumentFieldsFromCropCanvas } from './field-detection.js';
|
|
3
|
-
import {
|
|
3
|
+
import { shouldRunFieldDetection } from './field-detection-policy.js';
|
|
4
|
+
import { hideCropPreview, revealCropPreview } from '../components/croppedImage.js';
|
|
4
5
|
import {
|
|
5
6
|
hideFieldDetectionOverlay,
|
|
6
7
|
showFieldDetectionOverlay,
|
|
@@ -10,11 +11,16 @@ import {
|
|
|
10
11
|
hideFieldDetectionScanOverlay,
|
|
11
12
|
showFieldDetectionScanOverlay,
|
|
12
13
|
} from '../components/fieldDetectionScanOverlay.js';
|
|
14
|
+
import {
|
|
15
|
+
applyCropPreviewLayoutRect,
|
|
16
|
+
getCropPreviewLayoutRectFromCanvas,
|
|
17
|
+
rememberCropPreviewLayout,
|
|
18
|
+
} from '../components/previewLayout.js';
|
|
13
19
|
|
|
14
20
|
let cropDetectionGeneration = 0;
|
|
15
21
|
|
|
16
22
|
const shouldHoldSubmitForFieldDetection = () =>
|
|
17
|
-
state.disableSubmitUntilFieldDetectionDone &&
|
|
23
|
+
state.disableSubmitUntilFieldDetectionDone && shouldRunFieldDetection();
|
|
18
24
|
|
|
19
25
|
export const holdSubmitForFieldDetectionIfNeeded = () => {
|
|
20
26
|
if (shouldHoldSubmitForFieldDetection()) {
|
|
@@ -33,10 +39,10 @@ const releaseSubmitAfterFieldDetection = () => {
|
|
|
33
39
|
* on the crop preview before the user submits.
|
|
34
40
|
*/
|
|
35
41
|
export const onCropPreviewReady = async () => {
|
|
36
|
-
|
|
37
|
-
if (!documentFieldsToDetect?.length) {
|
|
42
|
+
if (!shouldRunFieldDetection()) {
|
|
38
43
|
return;
|
|
39
44
|
}
|
|
45
|
+
const documentFieldsToDetect = state.documentFieldsToDetect;
|
|
40
46
|
|
|
41
47
|
const canvas = state.cropImgRef;
|
|
42
48
|
const previewImg =
|
|
@@ -46,13 +52,18 @@ export const onCropPreviewReady = async () => {
|
|
|
46
52
|
return;
|
|
47
53
|
}
|
|
48
54
|
|
|
55
|
+
const scanLayout = getCropPreviewLayoutRectFromCanvas(canvas, previewImg?.parentElement);
|
|
56
|
+
rememberCropPreviewLayout(canvas, scanLayout);
|
|
57
|
+
if (previewImg && scanLayout) {
|
|
58
|
+
applyCropPreviewLayoutRect(previewImg, scanLayout);
|
|
59
|
+
}
|
|
49
60
|
const generation = ++cropDetectionGeneration;
|
|
50
61
|
const scanImageSrc =
|
|
51
62
|
previewImg?.src ||
|
|
52
63
|
(canvas.width && canvas.height ? canvas.toDataURL('image/jpeg', 0.92) : null);
|
|
53
64
|
if (previewImg && scanImageSrc) {
|
|
54
|
-
previewImg
|
|
55
|
-
showFieldDetectionScanOverlay(previewImg, scanImageSrc);
|
|
65
|
+
hideCropPreview(previewImg);
|
|
66
|
+
showFieldDetectionScanOverlay(previewImg, scanImageSrc, scanLayout);
|
|
56
67
|
}
|
|
57
68
|
|
|
58
69
|
try {
|
|
@@ -122,6 +133,24 @@ const revealCropPreviewAndOverlay = (previewImg, fieldDetection) => {
|
|
|
122
133
|
}
|
|
123
134
|
};
|
|
124
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Show the crop preview behind blur / document / LCD modals without running field-detection OCR.
|
|
138
|
+
*/
|
|
139
|
+
export const showCropPreviewForValidationModal = () => {
|
|
140
|
+
const canvas = state.cropImgRef;
|
|
141
|
+
const previewImg =
|
|
142
|
+
canvas?.previewImg ?? document.getElementById('veryfi-crop-img-preview');
|
|
143
|
+
if (!previewImg || !canvas?.width) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
cropDetectionGeneration += 1;
|
|
147
|
+
hideFieldDetectionScanOverlay();
|
|
148
|
+
hideFieldDetectionMessages();
|
|
149
|
+
hideFieldDetectionOverlay();
|
|
150
|
+
canvas.setRectangleDisplay?.();
|
|
151
|
+
revealCropPreview(previewImg);
|
|
152
|
+
};
|
|
153
|
+
|
|
125
154
|
export const cancelCropFieldDetection = () => {
|
|
126
155
|
cropDetectionGeneration += 1;
|
|
127
156
|
hideFieldDetectionScanOverlay();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { state } from './state.js';
|
|
2
|
+
|
|
3
|
+
/** Receipt and long-receipt flavors only (not checks, anydocs, etc.). */
|
|
4
|
+
const FIELD_DETECTION_FLAVORS = new Set(['document', 'long_document']);
|
|
5
|
+
|
|
6
|
+
export const isFieldDetectionFlavor = (flavor = state.lensFlavor) =>
|
|
7
|
+
FIELD_DETECTION_FLAVORS.has(flavor);
|
|
8
|
+
|
|
9
|
+
export const shouldRunFieldDetection = (flavor = state.lensFlavor) =>
|
|
10
|
+
isFieldDetectionFlavor(flavor) && !!state.documentFieldsToDetect?.length;
|
package/core/field-detection.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { state, refs } from './state.js';
|
|
2
2
|
import { recognizeCanvas, tesseractDataToOcrPayload } from './tesseract-ocr.js';
|
|
3
3
|
|
|
4
|
+
import { shouldRunFieldDetection } from './field-detection-policy.js';
|
|
5
|
+
|
|
6
|
+
export { isFieldDetectionFlavor, shouldRunFieldDetection } from './field-detection-policy.js';
|
|
7
|
+
|
|
4
8
|
const VALID_FIELDS = new Set(['vendor', 'date', 'total']);
|
|
5
9
|
|
|
6
10
|
export const filterFieldsForRequest = (result, requestedFields) => {
|
|
@@ -24,7 +28,12 @@ export const detectDocumentFieldsFromCropCanvas = async (canvas, context = {}) =
|
|
|
24
28
|
const documentFieldsToDetect =
|
|
25
29
|
context.documentFieldsToDetect ?? state.documentFieldsToDetect;
|
|
26
30
|
|
|
27
|
-
if (
|
|
31
|
+
if (
|
|
32
|
+
!shouldRunFieldDetection() ||
|
|
33
|
+
!documentFieldsToDetect?.length ||
|
|
34
|
+
!canvas?.width ||
|
|
35
|
+
!canvas?.height
|
|
36
|
+
) {
|
|
28
37
|
return null;
|
|
29
38
|
}
|
|
30
39
|
if (!wasmWrapper) {
|
|
@@ -68,7 +77,7 @@ export const detectDocumentFieldsFromCropCanvas = async (canvas, context = {}) =
|
|
|
68
77
|
};
|
|
69
78
|
|
|
70
79
|
export const initFieldDetectorIfNeeded = () => {
|
|
71
|
-
if (!
|
|
80
|
+
if (!shouldRunFieldDetection()) {
|
|
72
81
|
return false;
|
|
73
82
|
}
|
|
74
83
|
if (!refs.wasmWrapper?.loaded) {
|
package/core/lifecycle.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { state, refs, resetState, actions } from './state.js';
|
|
2
2
|
import { getVideo, displayVideo } from './camera.js';
|
|
3
3
|
import { initializeWasmWrapper, sendWasm, sendCardWasm, getLongImage, logDocument, stopWasm, resetAutoCaptureCounters, resetFieldDetectorBootstrap } from './wasm-processing.js';
|
|
4
|
-
import { hideVideoOverlay } from './overlay-controls.js';
|
|
4
|
+
import { hideVideoOverlay, showVideoOverlay } from './overlay-controls.js';
|
|
5
5
|
import { docReady, handleSubmit, fireResultSetter } from './api.js';
|
|
6
6
|
import { createSubmitButton } from '../components/submitButton.js';
|
|
7
|
+
import { createVideo } from '../components/video.js';
|
|
7
8
|
import {
|
|
8
9
|
cancelCropFieldDetection,
|
|
9
10
|
onCropPreviewReady,
|
|
@@ -15,6 +16,8 @@ import { createCheckOverlay } from '../components/checkOverlay.js';
|
|
|
15
16
|
import { DEFAULTS } from './constants.js';
|
|
16
17
|
import { cleanupPrescriptionLabelRecording } from './capture/prescription_label.js';
|
|
17
18
|
import { installDesktopModeWatchdog, uninstallDesktopModeWatchdog } from '../components/desktopModeModal.js';
|
|
19
|
+
import { shouldRunFieldDetection } from './field-detection-policy.js';
|
|
20
|
+
import { hideCropPreview } from '../components/croppedImage.js';
|
|
18
21
|
|
|
19
22
|
export const newStartLens = async () => {
|
|
20
23
|
state.started = true;
|
|
@@ -75,13 +78,15 @@ export const newStartLens = async () => {
|
|
|
75
78
|
if (state.cropImgRef) {
|
|
76
79
|
const ctx = state.cropImgRef.getContext('2d');
|
|
77
80
|
ctx?.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
|
|
81
|
+
delete state.cropImgRef._previewLayoutRect;
|
|
82
|
+
hideCropPreview(state.cropImgRef.previewImg);
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
if (state.lensFlavor !== "caps" && state.lensFlavor !== "code_strips" && state.lensFlavor !== "prescription_label") {
|
|
81
86
|
await initializeWasmWrapper();
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
if (
|
|
89
|
+
if (shouldRunFieldDetection()) {
|
|
85
90
|
bootstrapTesseract();
|
|
86
91
|
}
|
|
87
92
|
|
|
@@ -154,6 +159,35 @@ export const newStartLens = async () => {
|
|
|
154
159
|
}
|
|
155
160
|
};
|
|
156
161
|
|
|
162
|
+
// Re-enter capture without tearing down the overlay/container. Clears the crop
|
|
163
|
+
// preview, makes sure the video element exists, re-shows the overlay and
|
|
164
|
+
// restarts the lens. Shared by the anydoc "Add Page" loop and the
|
|
165
|
+
// multi-submission "Capture another" loop.
|
|
166
|
+
export const restartCameraForNextCapture = async () => {
|
|
167
|
+
if (state.cropImgRef) {
|
|
168
|
+
if (state.cropImgRef.previewImg) {
|
|
169
|
+
state.cropImgRef.previewImg.style.display = 'none';
|
|
170
|
+
state.cropImgRef.previewImg.style.top = '';
|
|
171
|
+
state.cropImgRef.previewImg.style.left = '';
|
|
172
|
+
state.cropImgRef.previewImg.style.transform = '';
|
|
173
|
+
state.cropImgRef.previewImg.src = '';
|
|
174
|
+
}
|
|
175
|
+
const ctx = state.cropImgRef.getContext('2d');
|
|
176
|
+
ctx?.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
|
|
177
|
+
state.cropImgRef.hideBorder?.();
|
|
178
|
+
}
|
|
179
|
+
if (!state.videoRef) {
|
|
180
|
+
state.videoRef = document.getElementById('veryfi-video-ref');
|
|
181
|
+
if (!state.videoRef && state.container) {
|
|
182
|
+
createVideo(state.container);
|
|
183
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
184
|
+
state.videoRef = document.getElementById('veryfi-video-ref');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
showVideoOverlay();
|
|
188
|
+
await newStartLens();
|
|
189
|
+
};
|
|
190
|
+
|
|
157
191
|
export const stopLens = () => {
|
|
158
192
|
state.started = false;
|
|
159
193
|
if (state.intervalRef) {
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { state, resetForNextSubmission } from './state.js';
|
|
2
|
+
import { removeOverlay, restartCameraForNextCapture } from './lifecycle.js';
|
|
3
|
+
import { createMultiCaptureModal } from '../components/multiCaptureModal.js';
|
|
4
|
+
import { finishBatch } from './api.js';
|
|
5
|
+
import { createSpinner } from '../components/spinner.js';
|
|
6
|
+
import { MESSAGES } from './constants.js';
|
|
7
|
+
|
|
8
|
+
const showBatchFinishRetryDialog = (onRetry) => {
|
|
9
|
+
const retryModal = createMultiCaptureModal(
|
|
10
|
+
state.container,
|
|
11
|
+
async () => {
|
|
12
|
+
retryModal.remove();
|
|
13
|
+
await onRetry();
|
|
14
|
+
},
|
|
15
|
+
() => {
|
|
16
|
+
retryModal.remove();
|
|
17
|
+
removeOverlay();
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
message: MESSAGES.BATCH_FINISH_FAILED,
|
|
21
|
+
yesButtonText: MESSAGES.BATCH_FINISH_RETRY,
|
|
22
|
+
noButtonText: MESSAGES.BATCH_FINISH_CANCEL,
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
retryModal.show();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const finishBatchSession = async () => {
|
|
30
|
+
const spinner = createSpinner(state.container, MESSAGES.BATCH_FINISHING);
|
|
31
|
+
spinner.show();
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
await finishBatch();
|
|
35
|
+
removeOverlay();
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error.status === 502) {
|
|
38
|
+
showBatchFinishRetryDialog(finishBatchSession);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
state.failureHandler?.(error);
|
|
42
|
+
removeOverlay();
|
|
43
|
+
} finally {
|
|
44
|
+
spinner.remove();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleMultiSubmissionDone = async () => {
|
|
49
|
+
if (state.batchReady) {
|
|
50
|
+
await finishBatchSession();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
state.updateHandler?.({ status: 'multi_submission_completed' });
|
|
55
|
+
removeOverlay();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const promptForAnotherCapture = (restart) => {
|
|
59
|
+
const doRestart = typeof restart === 'function' ? restart : restartCameraForNextCapture;
|
|
60
|
+
|
|
61
|
+
const modal = createMultiCaptureModal(
|
|
62
|
+
state.container,
|
|
63
|
+
async () => {
|
|
64
|
+
modal.remove();
|
|
65
|
+
resetForNextSubmission();
|
|
66
|
+
try {
|
|
67
|
+
await doRestart();
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('Failed to restart capture for next submission:', error);
|
|
70
|
+
state.failureHandler?.(error);
|
|
71
|
+
removeOverlay();
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
() => {
|
|
75
|
+
modal.remove();
|
|
76
|
+
handleMultiSubmissionDone().catch((error) => {
|
|
77
|
+
console.error('Failed to complete multi-submission session:', error);
|
|
78
|
+
state.failureHandler?.(error);
|
|
79
|
+
removeOverlay();
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
message: state.multiCaptureModalMessage,
|
|
84
|
+
yesButtonText: state.multiCaptureYesButtonText,
|
|
85
|
+
noButtonText: state.multiCaptureNoButtonText,
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
modal.show();
|
|
90
|
+
};
|
package/core/state.js
CHANGED
|
@@ -135,6 +135,11 @@ export const state = {
|
|
|
135
135
|
packageUploadId: null,
|
|
136
136
|
anydocAddPageText: MESSAGES.ANYDOC_ADD_PAGE,
|
|
137
137
|
anydocSubmitText: MESSAGES.ANYDOC_SUBMIT,
|
|
138
|
+
multiSubmission: false,
|
|
139
|
+
batchReady: false,
|
|
140
|
+
multiCaptureModalMessage: MESSAGES.MULTI_CAPTURE_PROMPT,
|
|
141
|
+
multiCaptureYesButtonText: MESSAGES.MULTI_CAPTURE_YES,
|
|
142
|
+
multiCaptureNoButtonText: MESSAGES.MULTI_CAPTURE_NO,
|
|
138
143
|
anydocShowFlipMessage: false,
|
|
139
144
|
anydocFlipMessageText: MESSAGES.ANYDOC_FLIP,
|
|
140
145
|
anydocFlipContinueText: MESSAGES.ANYDOC_FLIP_CONTINUE,
|
|
@@ -380,3 +385,43 @@ export const resetState = () => {
|
|
|
380
385
|
|
|
381
386
|
state.debug_mode && console.log("State reset complete");
|
|
382
387
|
};
|
|
388
|
+
|
|
389
|
+
// Soft reset between submissions of a multi-submission QR session. Clears only
|
|
390
|
+
// the per-document accumulators and per-submission UI so the next capture
|
|
391
|
+
// produces a fresh, independent document — while keeping the session alive
|
|
392
|
+
// (hasInit, clientData/session, camera) so we don't re-init the whole SDK.
|
|
393
|
+
export const resetForNextSubmission = () => {
|
|
394
|
+
state.debug_mode && console.log("Resetting state for next submission");
|
|
395
|
+
|
|
396
|
+
if (state.submitButton) {
|
|
397
|
+
state.submitButton.remove();
|
|
398
|
+
state.submitButton = null;
|
|
399
|
+
}
|
|
400
|
+
if (state.anydocPageControls) {
|
|
401
|
+
state.anydocPageControls.remove();
|
|
402
|
+
state.anydocPageControls = null;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
state.docReadyResult = null;
|
|
406
|
+
state.fullSizeImage = null;
|
|
407
|
+
state.finalImage = null;
|
|
408
|
+
state.frontImage = null;
|
|
409
|
+
state.backImage = null;
|
|
410
|
+
state.previewData = null;
|
|
411
|
+
state.fieldDetectionResult = null;
|
|
412
|
+
state.blurStatus = "";
|
|
413
|
+
state.lcdStatus = false;
|
|
414
|
+
state.isDocument = false;
|
|
415
|
+
state.hasCoordinates = false;
|
|
416
|
+
state.coordinates = [];
|
|
417
|
+
state.anydocPages = [];
|
|
418
|
+
state.packageScans = [];
|
|
419
|
+
state.packageFilename = null;
|
|
420
|
+
state.packageUploadId = null;
|
|
421
|
+
|
|
422
|
+
if (state.lensFlavor === 'checks') {
|
|
423
|
+
state.isCapturingFront = true;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
state.exitButtonRef?.show?.();
|
|
427
|
+
};
|
package/core/tesseract-ocr.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createWorker } from 'tesseract.js';
|
|
2
2
|
import { state } from './state.js';
|
|
3
|
+
import { shouldRunFieldDetection } from './field-detection-policy.js';
|
|
3
4
|
|
|
4
5
|
let workerPromise = null;
|
|
5
6
|
let workerLang = null;
|
|
@@ -16,7 +17,7 @@ export const bootstrapTesseract = (lang = 'eng+spa') => {
|
|
|
16
17
|
if (tesseractBootstrapStarted) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
if (!
|
|
20
|
+
if (!shouldRunFieldDetection()) {
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
22
23
|
|
package/core/ui-core.js
CHANGED
|
@@ -12,6 +12,14 @@ export const createCoreElements = async () => {
|
|
|
12
12
|
|
|
13
13
|
if (state.container) {
|
|
14
14
|
state.container.dataset.fullscreen = state.enableFullScreen.toString();
|
|
15
|
+
|
|
16
|
+
// Long-receipt on desktop: render the camera view and green box full-screen at the
|
|
17
|
+
// camera's native aspect ratio (object-fit: contain) so the detector contour lines
|
|
18
|
+
// up with the displayed frame instead of being mismatched by cover-vs-fill scaling.
|
|
19
|
+
const isDesktop = !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
20
|
+
navigator.userAgent
|
|
21
|
+
);
|
|
22
|
+
state.container.dataset.longDocDesktop = (isDesktop && state.lensFlavor === 'long_document').toString();
|
|
15
23
|
}
|
|
16
24
|
|
|
17
25
|
if (state.lensFlavor !== "credit_card" && state.lensFlavor !== "upload") {
|
package/core/validation.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { state } from './state.js';
|
|
2
|
+
import { showCropPreviewForValidationModal } from './crop-field-detection.js';
|
|
2
3
|
|
|
3
4
|
export const checkIfDocumentOnCapture = () => {
|
|
4
5
|
if (!state.isDocument) {
|
|
@@ -7,6 +8,7 @@ export const checkIfDocumentOnCapture = () => {
|
|
|
7
8
|
|
|
8
9
|
if (state.isDocumentModal && state.documentModal) {
|
|
9
10
|
state.documentModal.show();
|
|
11
|
+
showCropPreviewForValidationModal();
|
|
10
12
|
state.updateHandler?.({ status: 'not_a_document' });
|
|
11
13
|
state.cropImgRef?.showBorder?.();
|
|
12
14
|
} else {
|
|
@@ -23,6 +25,7 @@ export const checkIfBlurOnCapture = () => {
|
|
|
23
25
|
if (state.isBlurModal && state.blurModal) {
|
|
24
26
|
state.isBlurrySetter?.(true);
|
|
25
27
|
state.blurModal.show();
|
|
28
|
+
showCropPreviewForValidationModal();
|
|
26
29
|
state.updateHandler?.({ status: 'blur_detected' });
|
|
27
30
|
state.cropImgRef?.showBorder?.();
|
|
28
31
|
return true;
|
|
@@ -42,6 +45,7 @@ export const checkIfLcdOnCapture = () => {
|
|
|
42
45
|
state.isLcdSetter?.(true);
|
|
43
46
|
state.debug_mode && console.log("Showing LCD modal");
|
|
44
47
|
state.lcdModal.show();
|
|
48
|
+
showCropPreviewForValidationModal();
|
|
45
49
|
state.updateHandler?.({ status: 'lcd_detected' });
|
|
46
50
|
state.cropImgRef?.showBorder?.();
|
|
47
51
|
return true;
|
package/core/wasm-processing.js
CHANGED
|
@@ -3,6 +3,7 @@ import { drawContours, expandCoordinatesWithMargin } from './drawing.js';
|
|
|
3
3
|
import { releaseCanvas, setCoordinates, setHasCoordinates, setBlurStatus } from './utils.js';
|
|
4
4
|
import { DEFAULTS, WASM } from './constants.js';
|
|
5
5
|
import { bootstrapTesseract } from './tesseract-ocr.js';
|
|
6
|
+
import { shouldRunFieldDetection } from './field-detection-policy.js';
|
|
6
7
|
|
|
7
8
|
let _autoCaptureFrameCount = 0;
|
|
8
9
|
let _lastAutoCaptureStatus = null;
|
|
@@ -21,7 +22,7 @@ export const bootstrapFieldDetector = () => {
|
|
|
21
22
|
if (_fieldDetectorBootstrapStarted) {
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
|
-
if (!
|
|
25
|
+
if (!shouldRunFieldDetection() || !refs.wasmWrapper?.loaded) {
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
28
|
_fieldDetectorBootstrapStarted = true;
|