veryfi-lens-wasm 3.2.2 → 3.3.3
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/README.md +5 -2
- package/components/anydocPageControls.js +5 -1
- package/components/greenBox.js +11 -0
- package/components/multiCaptureModal.js +23 -0
- package/components/prescriptionLabelGuide.js +1 -0
- package/components/prescriptionOverlayToggleButton.js +75 -0
- package/components/submitButton.js +7 -0
- package/components/video.js +12 -0
- package/core/api.js +46 -1
- package/core/capture/anydoc.js +15 -26
- package/core/capture/document.js +8 -3
- package/core/capture/prescription_label.js +158 -16
- package/core/constants.js +20 -4
- package/core/lifecycle.js +31 -1
- package/core/multi-submission.js +90 -0
- package/core/state.js +52 -0
- package/core/ui-core.js +8 -0
- package/core/ui-renderer.js +57 -10
- package/package.json +1 -1
- package/veryfi-lens.js +6 -2
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Veryfi Lens for Web is a browser SDK that gives your web app document capture su
|
|
|
17
17
|
| `credit_card` | Credit card scanning (name, number, date, CVV) |
|
|
18
18
|
| `caps` | Bottle cap capture with circular guide overlay |
|
|
19
19
|
| `code_strips` | Code strip capture with rectangular guide overlay |
|
|
20
|
-
| `prescription_label` | Prescription label
|
|
20
|
+
| `prescription_label` | Prescription label capture, submits to anydocs. Switch overlays during capture: bottle overlay records video, box overlay captures a still image |
|
|
21
21
|
| `upload` | File upload with crop and submit (no camera) |
|
|
22
22
|
|
|
23
23
|
## Installation
|
|
@@ -236,7 +236,10 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
|
|
|
236
236
|
| `prescriptionLabelSquareHeightRatio` | `number` | `0.5` | Square overlay height (0-1 relative to viewport) |
|
|
237
237
|
| `prescriptionLabelShowGuide` | `boolean` | `false` | Show a semi-transparent guide explaining how to record the label. Auto-hides when recording starts and reappears on retake |
|
|
238
238
|
| `prescriptionLabelGuideText` | `string` | `"Position the bottle within the outline.\n\nPress the capture button to start recording, slowly rotate the bottle to capture the entire label and press the capture button again to stop recording."` | Guide text shown when the bottle outline overlay is active. Use `\n` for line breaks |
|
|
239
|
-
| `prescriptionLabelSquareGuideText` | `string` | `"Position the prescription label within the square.\n\nPress the capture button to
|
|
239
|
+
| `prescriptionLabelSquareGuideText` | `string` | `"Position the prescription label within the square.\n\nPress the capture button to take a photo of the label."` | Guide text shown when the box overlay is active. Use `\n` for line breaks |
|
|
240
|
+
| `prescriptionLabelShowOverlayToggle` | `boolean` | `true` | Show a toggle that lets the user switch between the bottle and box overlays during capture. The **bottle** overlay records a video; the **box** overlay captures a still image |
|
|
241
|
+
| `prescriptionLabelBottleLabel` | `string` | `"Bottle"` | Label for the bottle (video) segment of the overlay toggle |
|
|
242
|
+
| `prescriptionLabelBoxLabel` | `string` | `"Box"` | Label for the box (image) segment of the overlay toggle |
|
|
240
243
|
|
|
241
244
|
### Upload Settings (`upload` flavor)
|
|
242
245
|
|
|
@@ -127,7 +127,11 @@ export const createAnydocPageControls = (container, onAddPage, onSubmit, removeO
|
|
|
127
127
|
} catch (error) {
|
|
128
128
|
console.error('Error during anydoc submission:', error);
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
// When autoCloseOnSubmit is false the onSubmit handler owns teardown
|
|
131
|
+
// (multi-submission loop prompts for another capture instead of closing).
|
|
132
|
+
if (options.autoCloseOnSubmit !== false) {
|
|
133
|
+
removeOverlay();
|
|
134
|
+
}
|
|
131
135
|
};
|
|
132
136
|
submitButton.addEventListener('click', submitClickHandler);
|
|
133
137
|
|
package/components/greenBox.js
CHANGED
|
@@ -20,6 +20,17 @@ export const createGreenBox = (container) => {
|
|
|
20
20
|
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768 || isDesktopModeOnMobile();
|
|
21
21
|
const isFullscreen = container.dataset.fullscreen === 'true';
|
|
22
22
|
|
|
23
|
+
if (container.dataset.longDocDesktop === 'true') {
|
|
24
|
+
boxCanvas.style.position = 'fixed';
|
|
25
|
+
boxCanvas.style.top = '0';
|
|
26
|
+
boxCanvas.style.left = '0';
|
|
27
|
+
boxCanvas.style.width = '100vw';
|
|
28
|
+
boxCanvas.style.height = '100vh';
|
|
29
|
+
boxCanvas.style.maxWidth = 'none';
|
|
30
|
+
boxCanvas.style.objectFit = 'contain';
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
if (!isMobile) {
|
|
24
35
|
if (isFullscreen) {
|
|
25
36
|
boxCanvas.style.position = 'fixed';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createModal } from './modalBase.js';
|
|
2
|
+
|
|
3
|
+
export const createMultiCaptureModal = (container, onCaptureAnother, onFinish, options = {}) => {
|
|
4
|
+
const defaults = {
|
|
5
|
+
message: 'Do you need to capture another document?',
|
|
6
|
+
yesButtonText: 'Capture another',
|
|
7
|
+
noButtonText: "No, I'm done",
|
|
8
|
+
};
|
|
9
|
+
const o = { ...defaults, ...options };
|
|
10
|
+
|
|
11
|
+
return createModal(container, {
|
|
12
|
+
id: 'veryfi-multi-capture-modal',
|
|
13
|
+
cssPrefix: 'multi-capture-modal',
|
|
14
|
+
message: o.message,
|
|
15
|
+
primaryButtonText: o.yesButtonText,
|
|
16
|
+
primaryButtonId: 'veryfi-multi-capture-another',
|
|
17
|
+
secondaryButtonText: o.noButtonText,
|
|
18
|
+
secondaryButtonId: 'veryfi-multi-capture-finish',
|
|
19
|
+
onPrimaryClick: onCaptureAnother,
|
|
20
|
+
onSecondaryClick: onFinish,
|
|
21
|
+
useBackdrop: true,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -67,6 +67,7 @@ export const createPrescriptionLabelGuide = (container, options = {}) => {
|
|
|
67
67
|
|
|
68
68
|
return {
|
|
69
69
|
element: guide,
|
|
70
|
+
setText: (newText) => { textEl.textContent = newText || ''; },
|
|
70
71
|
show: () => { guide.style.display = 'block'; },
|
|
71
72
|
hide: () => { guide.style.display = 'none'; },
|
|
72
73
|
remove: () => {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export const createPrescriptionOverlayToggleButton = (container, options = {}) => {
|
|
2
|
+
const bottleLabel = options.bottleLabel || 'Bottle';
|
|
3
|
+
const boxLabel = options.boxLabel || 'Box';
|
|
4
|
+
let active = options.initial === 'box' ? 'box' : 'bottle';
|
|
5
|
+
const onToggle = typeof options.onToggle === 'function' ? options.onToggle : () => {};
|
|
6
|
+
|
|
7
|
+
const wrapper = document.createElement('div');
|
|
8
|
+
wrapper.id = 'veryfi-prescription-overlay-toggle';
|
|
9
|
+
Object.assign(wrapper.style, {
|
|
10
|
+
position: 'absolute',
|
|
11
|
+
top: '20px',
|
|
12
|
+
left: '50%',
|
|
13
|
+
transform: 'translateX(-50%)',
|
|
14
|
+
display: 'flex',
|
|
15
|
+
gap: '4px',
|
|
16
|
+
padding: '4px',
|
|
17
|
+
backgroundColor: 'rgba(255, 255, 255, 0.15)',
|
|
18
|
+
border: '1px solid rgba(255, 255, 255, 0.4)',
|
|
19
|
+
borderRadius: '25px',
|
|
20
|
+
backdropFilter: 'blur(8px)',
|
|
21
|
+
WebkitBackdropFilter: 'blur(8px)',
|
|
22
|
+
zIndex: '1004',
|
|
23
|
+
pointerEvents: 'auto',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const makeSegment = (label, type) => {
|
|
27
|
+
const btn = document.createElement('button');
|
|
28
|
+
btn.type = 'button';
|
|
29
|
+
btn.textContent = label;
|
|
30
|
+
btn.dataset.type = type;
|
|
31
|
+
Object.assign(btn.style, {
|
|
32
|
+
border: 'none',
|
|
33
|
+
outline: 'none',
|
|
34
|
+
cursor: 'pointer',
|
|
35
|
+
borderRadius: '20px',
|
|
36
|
+
padding: '8px 18px',
|
|
37
|
+
fontSize: '14px',
|
|
38
|
+
fontWeight: '600',
|
|
39
|
+
fontFamily: "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
|
|
40
|
+
color: 'white',
|
|
41
|
+
backgroundColor: 'transparent',
|
|
42
|
+
transition: 'background-color 0.2s ease',
|
|
43
|
+
});
|
|
44
|
+
btn.addEventListener('click', () => {
|
|
45
|
+
if (active === type) return;
|
|
46
|
+
active = type;
|
|
47
|
+
updateSegments();
|
|
48
|
+
onToggle(active);
|
|
49
|
+
});
|
|
50
|
+
return btn;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const bottleBtn = makeSegment(bottleLabel, 'bottle');
|
|
54
|
+
const boxBtn = makeSegment(boxLabel, 'box');
|
|
55
|
+
|
|
56
|
+
const updateSegments = () => {
|
|
57
|
+
[[bottleBtn, 'bottle'], [boxBtn, 'box']].forEach(([btn, type]) => {
|
|
58
|
+
btn.style.backgroundColor = active === type ? 'rgba(255, 255, 255, 0.35)' : 'transparent';
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
wrapper.appendChild(bottleBtn);
|
|
63
|
+
wrapper.appendChild(boxBtn);
|
|
64
|
+
updateSegments();
|
|
65
|
+
container.appendChild(wrapper);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
element: wrapper,
|
|
69
|
+
getActive: () => active,
|
|
70
|
+
setActive: (type) => { active = type === 'box' ? 'box' : 'bottle'; updateSegments(); },
|
|
71
|
+
show: () => { wrapper.style.display = 'flex'; },
|
|
72
|
+
hide: () => { wrapper.style.display = 'none'; },
|
|
73
|
+
remove: () => { if (wrapper.parentNode) wrapper.parentNode.removeChild(wrapper); },
|
|
74
|
+
};
|
|
75
|
+
};
|
|
@@ -57,6 +57,13 @@ export const createSubmitButton = (container, onSubmit, removeOverlay, options =
|
|
|
57
57
|
if (button.disabled) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
+
// When autoClose is false the onSubmit handler owns teardown/continuation
|
|
61
|
+
// (used by the multi-submission loop, which prompts for another capture
|
|
62
|
+
// instead of removing the overlay after a successful submit).
|
|
63
|
+
if (options.autoClose === false) {
|
|
64
|
+
await onSubmit();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
60
67
|
try {
|
|
61
68
|
await onSubmit();
|
|
62
69
|
} finally {
|
package/components/video.js
CHANGED
|
@@ -23,6 +23,18 @@ export const createVideo = (container) => {
|
|
|
23
23
|
const isFullscreen = container.dataset.fullscreen === 'true';
|
|
24
24
|
const isLandscape = window.innerWidth > window.innerHeight;
|
|
25
25
|
|
|
26
|
+
if (container.dataset.longDocDesktop === 'true') {
|
|
27
|
+
video.style.position = 'fixed';
|
|
28
|
+
video.style.top = '0';
|
|
29
|
+
video.style.left = '0';
|
|
30
|
+
video.style.width = '100vw';
|
|
31
|
+
video.style.height = '100vh';
|
|
32
|
+
video.style.maxWidth = 'none';
|
|
33
|
+
video.style.transform = 'none';
|
|
34
|
+
video.style.objectFit = 'contain';
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
if (!isMobile) {
|
|
27
39
|
if (isFullscreen) {
|
|
28
40
|
video.style.position = 'fixed';
|
package/core/api.js
CHANGED
|
@@ -5,6 +5,10 @@ import { createSpinner } from '../components/spinner.js';
|
|
|
5
5
|
import { API_URLS } from './constants.js';
|
|
6
6
|
import { shouldRunFieldDetection } from './field-detection-policy.js';
|
|
7
7
|
|
|
8
|
+
export const getQrSessionId = () => {
|
|
9
|
+
return new URLSearchParams(window.location.search).get('session');
|
|
10
|
+
};
|
|
11
|
+
|
|
8
12
|
export const validatePartner = async (client_id) => {
|
|
9
13
|
try {
|
|
10
14
|
state.updateHandler?.({ status: 'validation_started' });
|
|
@@ -314,7 +318,7 @@ export const handleSubmit = async (image) => {
|
|
|
314
318
|
...customData,
|
|
315
319
|
};
|
|
316
320
|
|
|
317
|
-
const qrSessionId =
|
|
321
|
+
const qrSessionId = getQrSessionId();
|
|
318
322
|
|
|
319
323
|
const requestOptions = {
|
|
320
324
|
method: 'POST',
|
|
@@ -351,6 +355,7 @@ export const handleSubmit = async (image) => {
|
|
|
351
355
|
state.debug_mode && console.log("Success handler called");
|
|
352
356
|
successHandler(result);
|
|
353
357
|
}
|
|
358
|
+
return result;
|
|
354
359
|
} finally {
|
|
355
360
|
spinner.remove();
|
|
356
361
|
}
|
|
@@ -372,6 +377,46 @@ export const handleSubmit = async (image) => {
|
|
|
372
377
|
}
|
|
373
378
|
};
|
|
374
379
|
|
|
380
|
+
export const finishBatch = async () => {
|
|
381
|
+
const clientId = state.clientId;
|
|
382
|
+
const qrSessionId = getQrSessionId();
|
|
383
|
+
|
|
384
|
+
if (!clientId || !qrSessionId) {
|
|
385
|
+
throw new Error('CLIENT-ID and QR session are required to finish the batch');
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
state.updateHandler?.({ status: 'batch_finish_started' });
|
|
389
|
+
|
|
390
|
+
const response = await fetch(API_URLS.FINISH_BATCH, {
|
|
391
|
+
method: 'POST',
|
|
392
|
+
headers: {
|
|
393
|
+
'CLIENT-ID': clientId,
|
|
394
|
+
'QR-SESSION-ID': qrSessionId,
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
if (!response.ok) {
|
|
399
|
+
const errorData = await response.json().catch(() => null);
|
|
400
|
+
const message = errorData?.detail || `HTTP error! status: ${response.status}`;
|
|
401
|
+
const error = new Error(message);
|
|
402
|
+
error.status = response.status;
|
|
403
|
+
error.detail = errorData;
|
|
404
|
+
state.updateHandler?.({
|
|
405
|
+
status: 'batch_finish_failed',
|
|
406
|
+
error: errorData,
|
|
407
|
+
statusCode: response.status,
|
|
408
|
+
});
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const result = await response.json();
|
|
413
|
+
state.updateHandler?.({
|
|
414
|
+
status: 'batch_finish_completed',
|
|
415
|
+
document_count: result.document_count,
|
|
416
|
+
});
|
|
417
|
+
return result;
|
|
418
|
+
};
|
|
419
|
+
|
|
375
420
|
export const fetchBlueprints = async () => {
|
|
376
421
|
const requestOptions = {
|
|
377
422
|
method: 'POST',
|
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
|
|
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();
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { state } from '../state.js';
|
|
2
|
-
import { handleSubmit, addPackageScan, ensurePackageUploaded } from '../api.js';
|
|
2
|
+
import { handleSubmit, addPackageScan, ensurePackageUploaded, docReady } 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';
|
|
7
|
+
import { DEFAULTS } from '../constants.js';
|
|
6
8
|
|
|
7
9
|
let previewRecorder = null;
|
|
8
10
|
let previewChunks = [];
|
|
@@ -133,7 +135,7 @@ const getRecorderMimeType = () => {
|
|
|
133
135
|
};
|
|
134
136
|
|
|
135
137
|
const computeOverlayCropRect = (vw, vh) => {
|
|
136
|
-
if (state.
|
|
138
|
+
if (state.prescriptionLabelActiveOverlay === 'box') {
|
|
137
139
|
const w = vw * state.prescriptionLabelSquareWidthRatio;
|
|
138
140
|
const h = vh * state.prescriptionLabelSquareHeightRatio;
|
|
139
141
|
const cx = vw / 2;
|
|
@@ -141,15 +143,11 @@ const computeOverlayCropRect = (vw, vh) => {
|
|
|
141
143
|
return { x: cx - w / 2, y: cy - h / 2, width: w, height: h };
|
|
142
144
|
}
|
|
143
145
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return { x: cx - bodyW / 2, y: cy - totalH / 2, width: bodyW, height: totalH };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return null;
|
|
146
|
+
const bodyW = vw * state.prescriptionLabelWidthRatio;
|
|
147
|
+
const totalH = vh * state.prescriptionLabelHeightRatio;
|
|
148
|
+
const cx = vw / 2;
|
|
149
|
+
const cy = vh * 0.46;
|
|
150
|
+
return { x: cx - bodyW / 2, y: cy - totalH / 2, width: bodyW, height: totalH };
|
|
153
151
|
};
|
|
154
152
|
|
|
155
153
|
const computeSourceCropRegion = (videoElement) => {
|
|
@@ -272,6 +270,7 @@ const startRecording = () => {
|
|
|
272
270
|
isRecording = true;
|
|
273
271
|
updateRecordingUI(true);
|
|
274
272
|
state.prescriptionLabelGuide?.hide?.();
|
|
273
|
+
state.prescriptionOverlayToggleButton?.hide?.();
|
|
275
274
|
state.updateHandler?.({ status: 'recording_started' });
|
|
276
275
|
state.debug_mode && console.log('[EVENT] prescription label recording started');
|
|
277
276
|
};
|
|
@@ -456,6 +455,7 @@ const showVideoPreview = (videoBlob) => {
|
|
|
456
455
|
}
|
|
457
456
|
showVideoOverlay();
|
|
458
457
|
state.prescriptionLabelGuide?.show?.();
|
|
458
|
+
state.prescriptionOverlayToggleButton?.show?.();
|
|
459
459
|
await newStartLens();
|
|
460
460
|
});
|
|
461
461
|
containerEl.appendChild(retakeButtonEl);
|
|
@@ -480,21 +480,149 @@ const submitVideoBlob = async (videoBlob) => {
|
|
|
480
480
|
state.updateHandler?.({ status: 'processing_completed' });
|
|
481
481
|
|
|
482
482
|
const uploadStartTime = performance.now();
|
|
483
|
+
let submitResult;
|
|
483
484
|
if (typeof state.customSubmitHandler === 'function') {
|
|
484
485
|
const packageInfo = await ensurePackageUploaded();
|
|
485
486
|
state.customSubmitHandler(videoBlob, packageInfo);
|
|
487
|
+
submitResult = videoBlob;
|
|
486
488
|
} else {
|
|
487
|
-
await handleSubmit(submitData);
|
|
489
|
+
submitResult = await handleSubmit(submitData);
|
|
488
490
|
}
|
|
489
491
|
const uploadDurationSec = (performance.now() - uploadStartTime) / 1000;
|
|
490
492
|
const totalDurationSec = (performance.now() - submissionStartTime) / 1000;
|
|
491
493
|
console.log(`[prescription_label] submission complete — total: ${totalDurationSec.toFixed(2)}s, upload: ${uploadDurationSec.toFixed(2)}s, video: ${(videoBlob.size / 1024).toFixed(1)} KB`);
|
|
492
494
|
|
|
493
495
|
state.updateHandler?.({ status: 'capture_completed' });
|
|
494
|
-
return
|
|
496
|
+
return submitResult;
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
const submitPrescriptionImage = async (imageBase64) => {
|
|
500
|
+
state.updateHandler?.({ status: 'processing_started' });
|
|
501
|
+
state.updateHandler?.({ status: 'processing_completed' });
|
|
502
|
+
|
|
503
|
+
let submitResult;
|
|
504
|
+
if (typeof state.customSubmitHandler === 'function') {
|
|
505
|
+
const packageInfo = await ensurePackageUploaded();
|
|
506
|
+
state.customSubmitHandler(imageBase64, packageInfo);
|
|
507
|
+
submitResult = imageBase64;
|
|
508
|
+
} else {
|
|
509
|
+
submitResult = await handleSubmit(imageBase64);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
state.updateHandler?.({ status: 'capture_completed' });
|
|
513
|
+
return submitResult;
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const capturePrescriptionImage = async () => {
|
|
517
|
+
try {
|
|
518
|
+
state.debug_mode && console.log('[EVENT] capture prescription label image');
|
|
519
|
+
state.updateHandler?.({ status: 'capture_started' });
|
|
520
|
+
|
|
521
|
+
const videoElement = state.videoRef;
|
|
522
|
+
if (!videoElement) {
|
|
523
|
+
throw new Error('Video reference not initialized');
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const region = computeSourceCropRegion(videoElement);
|
|
527
|
+
if (!region) {
|
|
528
|
+
throw new Error('Failed to compute prescription label crop region');
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const cropImgRef = state.cropImgRef;
|
|
532
|
+
if (!cropImgRef) {
|
|
533
|
+
throw new Error('Crop image reference not initialized');
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
cropImgRef.width = Math.max(2, Math.round(region.srcW));
|
|
537
|
+
cropImgRef.height = Math.max(2, Math.round(region.srcH));
|
|
538
|
+
const ctx = cropImgRef.getContext('2d');
|
|
539
|
+
ctx.clearRect(0, 0, cropImgRef.width, cropImgRef.height);
|
|
540
|
+
ctx.drawImage(
|
|
541
|
+
videoElement,
|
|
542
|
+
region.srcX, region.srcY, region.srcW, region.srcH,
|
|
543
|
+
0, 0, cropImgRef.width, cropImgRef.height
|
|
544
|
+
);
|
|
545
|
+
|
|
546
|
+
state.finalImage = cropImgRef.toDataURL('image/jpeg', DEFAULTS.IMAGE_QUALITY).split(',')[1];
|
|
547
|
+
if (!state.finalImage) {
|
|
548
|
+
throw new Error('Failed to capture prescription label image');
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
state.isDocument = true;
|
|
552
|
+
hideVideoOverlay();
|
|
553
|
+
state.prescriptionSquareOverlay?.hide?.();
|
|
554
|
+
state.prescriptionLabelOverlay?.hide?.();
|
|
555
|
+
state.prescriptionOverlayToggleButton?.hide?.();
|
|
556
|
+
state.prescriptionLabelGuide?.hide?.();
|
|
557
|
+
state.exitButtonRef?.hide?.();
|
|
558
|
+
state.videoRef?.srcObject?.getTracks?.().forEach((track) => track.stop());
|
|
559
|
+
|
|
560
|
+
state.cropImgRef?.setRectangleDisplay?.();
|
|
561
|
+
state.cropImgRef?.showSuccessBorder?.();
|
|
562
|
+
|
|
563
|
+
// Per-capture upload, parity with image flavors' docReady() on crop accept:
|
|
564
|
+
// - packageMode: true => accumulate scan into state.packageScans
|
|
565
|
+
// - packageMode: false => POST base64 to /rest/send-cropped now
|
|
566
|
+
state.updateHandler?.({ status: 'processing_started' });
|
|
567
|
+
state.docReadyResult = await docReady();
|
|
568
|
+
state.updateHandler?.({ status: 'processing_completed' });
|
|
569
|
+
|
|
570
|
+
const restartPrescription = async () => {
|
|
571
|
+
if (state.cropImgRef) {
|
|
572
|
+
const previewImg = state.cropImgRef.previewImg;
|
|
573
|
+
if (previewImg) {
|
|
574
|
+
previewImg.style.display = 'none';
|
|
575
|
+
previewImg.src = '';
|
|
576
|
+
}
|
|
577
|
+
state.cropImgRef.hideBorder?.();
|
|
578
|
+
const cctx = state.cropImgRef.getContext('2d');
|
|
579
|
+
cctx?.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
|
|
580
|
+
}
|
|
581
|
+
showVideoOverlay();
|
|
582
|
+
state.prescriptionSquareOverlay?.show?.();
|
|
583
|
+
state.prescriptionLabelGuide?.show?.();
|
|
584
|
+
state.prescriptionOverlayToggleButton?.show?.();
|
|
585
|
+
await newStartLens();
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
state.submitButton = createSubmitButton(
|
|
589
|
+
state.container,
|
|
590
|
+
async () => {
|
|
591
|
+
const result = await submitPrescriptionImage(state.finalImage);
|
|
592
|
+
if (state.multiSubmission && result) {
|
|
593
|
+
state.submitButton?.hide?.();
|
|
594
|
+
promptForAnotherCapture(restartPrescription);
|
|
595
|
+
} else {
|
|
596
|
+
removeOverlay();
|
|
597
|
+
}
|
|
598
|
+
},
|
|
599
|
+
() => {},
|
|
600
|
+
{ autoClose: false }
|
|
601
|
+
);
|
|
602
|
+
state.submitButton.show();
|
|
603
|
+
|
|
604
|
+
if (state.packageMode && !state.enableSubmit) {
|
|
605
|
+
const packageInfo = await ensurePackageUploaded();
|
|
606
|
+
state.resultSetter?.({ ...(packageInfo || {}), image: state.finalImage });
|
|
607
|
+
} else {
|
|
608
|
+
state.resultSetter?.(state.finalImage);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
state.updateHandler?.({ status: 'capture_completed' });
|
|
612
|
+
return state.finalImage;
|
|
613
|
+
} catch (error) {
|
|
614
|
+
console.error('Prescription label image capture failed:', error.message);
|
|
615
|
+
state.failureHandler?.(error);
|
|
616
|
+
state.updateHandler?.({ status: 'capture_failed' });
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
495
619
|
};
|
|
496
620
|
|
|
497
621
|
export const capturePrescriptionLabel = async () => {
|
|
622
|
+
if (state.prescriptionLabelActiveOverlay === 'box') {
|
|
623
|
+
return capturePrescriptionImage();
|
|
624
|
+
}
|
|
625
|
+
|
|
498
626
|
try {
|
|
499
627
|
if (!isRecording) {
|
|
500
628
|
state.debug_mode && console.log('[EVENT] starting prescription label recording');
|
|
@@ -532,13 +660,27 @@ export const capturePrescriptionLabel = async () => {
|
|
|
532
660
|
isBase64: false,
|
|
533
661
|
});
|
|
534
662
|
|
|
663
|
+
const restartPrescription = async () => {
|
|
664
|
+
cleanupPreview();
|
|
665
|
+
showVideoOverlay();
|
|
666
|
+
state.prescriptionLabelGuide?.show?.();
|
|
667
|
+
state.prescriptionOverlayToggleButton?.show?.();
|
|
668
|
+
await newStartLens();
|
|
669
|
+
};
|
|
670
|
+
|
|
535
671
|
state.submitButton = createSubmitButton(
|
|
536
672
|
state.container,
|
|
537
673
|
async () => {
|
|
538
|
-
await submitVideoBlob(submissionBlob);
|
|
539
|
-
|
|
674
|
+
const result = await submitVideoBlob(submissionBlob);
|
|
675
|
+
if (state.multiSubmission && result) {
|
|
676
|
+
state.submitButton?.hide?.();
|
|
677
|
+
promptForAnotherCapture(restartPrescription);
|
|
678
|
+
} else {
|
|
679
|
+
removeOverlay();
|
|
680
|
+
}
|
|
540
681
|
},
|
|
541
|
-
() => {}
|
|
682
|
+
() => {},
|
|
683
|
+
{ autoClose: false }
|
|
542
684
|
);
|
|
543
685
|
const submitBtnEl = document.getElementById('veryfi-submit-button');
|
|
544
686
|
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.
|
|
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)',
|
|
@@ -79,13 +86,22 @@ export const MESSAGES = {
|
|
|
79
86
|
BOTTLE_CAP: 'Position bottle cap in circle',
|
|
80
87
|
PRESCRIPTION_LABEL: 'Position prescription label in outline',
|
|
81
88
|
PRESCRIPTION_LABEL_GUIDE: 'Position the bottle within the outline.\n\nPress the capture button to start recording, slowly rotate the bottle to capture the entire label and press the capture button again to stop recording.',
|
|
82
|
-
PRESCRIPTION_SQUARE_GUIDE: 'Position the prescription label within the square.\n\nPress the capture button to
|
|
89
|
+
PRESCRIPTION_SQUARE_GUIDE: 'Position the prescription label within the square.\n\nPress the capture button to take a photo of the label.',
|
|
90
|
+
PRESCRIPTION_TOGGLE_BOTTLE: 'Bottle',
|
|
91
|
+
PRESCRIPTION_TOGGLE_BOX: 'Box',
|
|
83
92
|
CODE_STRIPS: 'Position code strip in rectangle',
|
|
84
93
|
CHECK_POSITION: 'We could not detect a check, hope this will make it easier',
|
|
85
94
|
ANYDOC_ADD_PAGE: 'Add Page',
|
|
86
95
|
ANYDOC_SUBMIT: 'Submit',
|
|
87
96
|
ANYDOC_FLIP: 'Please flip the document and capture the other side',
|
|
88
97
|
ANYDOC_FLIP_CONTINUE: 'Continue',
|
|
98
|
+
MULTI_CAPTURE_PROMPT: 'Do you need to capture another document?',
|
|
99
|
+
MULTI_CAPTURE_YES: 'Capture another',
|
|
100
|
+
MULTI_CAPTURE_NO: "No, I'm done",
|
|
101
|
+
BATCH_FINISHING: 'Completing batch...',
|
|
102
|
+
BATCH_FINISH_FAILED: 'Failed to notify your system. Would you like to try again?',
|
|
103
|
+
BATCH_FINISH_RETRY: 'Retry',
|
|
104
|
+
BATCH_FINISH_CANCEL: 'Close without notifying',
|
|
89
105
|
AUTH_FAILED: 'Authorization failed, please provide correct client-id or contact customer support at support@veryfi.com',
|
|
90
106
|
AUTH_FAILED_CONTACT: 'Authorization failed, please contact customer support at support@veryfi.com',
|
|
91
107
|
};
|
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,
|
|
@@ -158,6 +159,35 @@ export const newStartLens = async () => {
|
|
|
158
159
|
}
|
|
159
160
|
};
|
|
160
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
|
+
|
|
161
191
|
export const stopLens = () => {
|
|
162
192
|
state.started = false;
|
|
163
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,
|
|
@@ -209,6 +214,11 @@ export const state = {
|
|
|
209
214
|
prescriptionLabelGuideText: MESSAGES.PRESCRIPTION_LABEL_GUIDE,
|
|
210
215
|
prescriptionLabelSquareGuideText: MESSAGES.PRESCRIPTION_SQUARE_GUIDE,
|
|
211
216
|
prescriptionLabelGuide: null,
|
|
217
|
+
prescriptionLabelActiveOverlay: null,
|
|
218
|
+
prescriptionLabelShowOverlayToggle: true,
|
|
219
|
+
prescriptionLabelBottleLabel: MESSAGES.PRESCRIPTION_TOGGLE_BOTTLE,
|
|
220
|
+
prescriptionLabelBoxLabel: MESSAGES.PRESCRIPTION_TOGGLE_BOX,
|
|
221
|
+
prescriptionOverlayToggleButton: null,
|
|
212
222
|
preferredVideoFormat: null,
|
|
213
223
|
|
|
214
224
|
codeStripsOverlay: null,
|
|
@@ -328,6 +338,8 @@ export const resetState = () => {
|
|
|
328
338
|
state.prescriptionLabelOverlay = null;
|
|
329
339
|
state.prescriptionSquareOverlay = null;
|
|
330
340
|
state.prescriptionLabelGuide = null;
|
|
341
|
+
state.prescriptionLabelActiveOverlay = null;
|
|
342
|
+
state.prescriptionOverlayToggleButton = null;
|
|
331
343
|
state.codeStripsOverlay = null;
|
|
332
344
|
state.checkOverlay = null;
|
|
333
345
|
state.isManualCheckCapture = false;
|
|
@@ -380,3 +392,43 @@ export const resetState = () => {
|
|
|
380
392
|
|
|
381
393
|
state.debug_mode && console.log("State reset complete");
|
|
382
394
|
};
|
|
395
|
+
|
|
396
|
+
// Soft reset between submissions of a multi-submission QR session. Clears only
|
|
397
|
+
// the per-document accumulators and per-submission UI so the next capture
|
|
398
|
+
// produces a fresh, independent document — while keeping the session alive
|
|
399
|
+
// (hasInit, clientData/session, camera) so we don't re-init the whole SDK.
|
|
400
|
+
export const resetForNextSubmission = () => {
|
|
401
|
+
state.debug_mode && console.log("Resetting state for next submission");
|
|
402
|
+
|
|
403
|
+
if (state.submitButton) {
|
|
404
|
+
state.submitButton.remove();
|
|
405
|
+
state.submitButton = null;
|
|
406
|
+
}
|
|
407
|
+
if (state.anydocPageControls) {
|
|
408
|
+
state.anydocPageControls.remove();
|
|
409
|
+
state.anydocPageControls = null;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
state.docReadyResult = null;
|
|
413
|
+
state.fullSizeImage = null;
|
|
414
|
+
state.finalImage = null;
|
|
415
|
+
state.frontImage = null;
|
|
416
|
+
state.backImage = null;
|
|
417
|
+
state.previewData = null;
|
|
418
|
+
state.fieldDetectionResult = null;
|
|
419
|
+
state.blurStatus = "";
|
|
420
|
+
state.lcdStatus = false;
|
|
421
|
+
state.isDocument = false;
|
|
422
|
+
state.hasCoordinates = false;
|
|
423
|
+
state.coordinates = [];
|
|
424
|
+
state.anydocPages = [];
|
|
425
|
+
state.packageScans = [];
|
|
426
|
+
state.packageFilename = null;
|
|
427
|
+
state.packageUploadId = null;
|
|
428
|
+
|
|
429
|
+
if (state.lensFlavor === 'checks') {
|
|
430
|
+
state.isCapturingFront = true;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
state.exitButtonRef?.show?.();
|
|
434
|
+
};
|
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/ui-renderer.js
CHANGED
|
@@ -20,6 +20,7 @@ import { createCodeStripsOverlay } from '../components/codeStripsOverlay.js';
|
|
|
20
20
|
import { createPrescriptionLabelOverlay } from '../components/prescriptionLabelOverlay.js';
|
|
21
21
|
import { createPrescriptionSquareOverlay } from '../components/prescriptionSquareOverlay.js';
|
|
22
22
|
import { createPrescriptionLabelGuide } from '../components/prescriptionLabelGuide.js';
|
|
23
|
+
import { createPrescriptionOverlayToggleButton } from '../components/prescriptionOverlayToggleButton.js';
|
|
23
24
|
import { createMirrorButton } from '../components/mirrorButton.js';
|
|
24
25
|
import { createSwitchCameraButton } from '../components/switchCameraButton.js';
|
|
25
26
|
|
|
@@ -69,19 +70,22 @@ const setupVideoOverlayControls = (captureAction) => {
|
|
|
69
70
|
renderWatermarkIfNeeded();
|
|
70
71
|
};
|
|
71
72
|
|
|
72
|
-
const createSpecialtyOverlayOnReady = (overlayKey, createFn, options) => {
|
|
73
|
+
const createSpecialtyOverlayOnReady = (overlayKey, createFn, options, onReady) => {
|
|
73
74
|
const videoElement = document.getElementById("veryfi-video-ref");
|
|
74
75
|
if (!videoElement) return;
|
|
75
76
|
|
|
76
|
-
|
|
77
|
+
const create = () => {
|
|
77
78
|
if (!state[overlayKey]) {
|
|
78
79
|
state[overlayKey] = createFn(state.container, options);
|
|
79
80
|
}
|
|
81
|
+
onReady?.();
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
if (videoElement.readyState >= 2) {
|
|
85
|
+
create();
|
|
80
86
|
} else {
|
|
81
87
|
const handleVideoLoad = () => {
|
|
82
|
-
|
|
83
|
-
state[overlayKey] = createFn(state.container, options);
|
|
84
|
-
}
|
|
88
|
+
create();
|
|
85
89
|
videoElement.removeEventListener('loadeddata', handleVideoLoad);
|
|
86
90
|
};
|
|
87
91
|
videoElement.addEventListener('loadeddata', handleVideoLoad);
|
|
@@ -293,23 +297,47 @@ export const renderPrescriptionLabelOverlayIfNeeded = () => {
|
|
|
293
297
|
state.debug_mode && console.log("Rendering prescription label overlay");
|
|
294
298
|
setupVideoOverlayControls(() => actions.capturePrescriptionLabel());
|
|
295
299
|
|
|
296
|
-
|
|
300
|
+
const toggleEnabled = state.prescriptionLabelShowOverlayToggle;
|
|
301
|
+
// When the toggle is enabled both overlays must be switchable regardless of
|
|
302
|
+
// the individual show flags; otherwise fall back to the legacy per-flag show.
|
|
303
|
+
const bottleEnabled = toggleEnabled || state.prescriptionLabelShowOverlay;
|
|
304
|
+
const boxEnabled = toggleEnabled || state.prescriptionLabelShowSquareOverlay;
|
|
305
|
+
|
|
306
|
+
if (!state.prescriptionLabelActiveOverlay) {
|
|
307
|
+
state.prescriptionLabelActiveOverlay =
|
|
308
|
+
(state.prescriptionLabelShowSquareOverlay && !state.prescriptionLabelShowOverlay) ? 'box' : 'bottle';
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const applyOverlayVisibility = () => {
|
|
312
|
+
if (state.prescriptionLabelOverlay) {
|
|
313
|
+
state.prescriptionLabelActiveOverlay === 'bottle'
|
|
314
|
+
? state.prescriptionLabelOverlay.show()
|
|
315
|
+
: state.prescriptionLabelOverlay.hide();
|
|
316
|
+
}
|
|
317
|
+
if (state.prescriptionSquareOverlay) {
|
|
318
|
+
state.prescriptionLabelActiveOverlay === 'box'
|
|
319
|
+
? state.prescriptionSquareOverlay.show()
|
|
320
|
+
: state.prescriptionSquareOverlay.hide();
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
if (bottleEnabled) {
|
|
297
325
|
createSpecialtyOverlayOnReady('prescriptionLabelOverlay', createPrescriptionLabelOverlay, {
|
|
298
326
|
bottleWidthRatio: state.prescriptionLabelWidthRatio,
|
|
299
327
|
bottleHeightRatio: state.prescriptionLabelHeightRatio,
|
|
300
328
|
instructionText: state.prescriptionLabelText
|
|
301
|
-
});
|
|
329
|
+
}, applyOverlayVisibility);
|
|
302
330
|
}
|
|
303
331
|
|
|
304
|
-
if (
|
|
332
|
+
if (boxEnabled) {
|
|
305
333
|
createSpecialtyOverlayOnReady('prescriptionSquareOverlay', createPrescriptionSquareOverlay, {
|
|
306
334
|
squareWidthRatio: state.prescriptionLabelSquareWidthRatio,
|
|
307
335
|
squareHeightRatio: state.prescriptionLabelSquareHeightRatio,
|
|
308
|
-
});
|
|
336
|
+
}, applyOverlayVisibility);
|
|
309
337
|
}
|
|
310
338
|
|
|
311
339
|
if (state.prescriptionLabelShowGuide && !state.prescriptionLabelGuide) {
|
|
312
|
-
const guideText = state.
|
|
340
|
+
const guideText = state.prescriptionLabelActiveOverlay === 'box'
|
|
313
341
|
? state.prescriptionLabelSquareGuideText
|
|
314
342
|
: state.prescriptionLabelGuideText;
|
|
315
343
|
state.prescriptionLabelGuide = createPrescriptionLabelGuide(
|
|
@@ -317,6 +345,25 @@ export const renderPrescriptionLabelOverlayIfNeeded = () => {
|
|
|
317
345
|
{ text: guideText }
|
|
318
346
|
);
|
|
319
347
|
}
|
|
348
|
+
|
|
349
|
+
if (toggleEnabled && bottleEnabled && boxEnabled && !state.prescriptionOverlayToggleButton) {
|
|
350
|
+
state.prescriptionOverlayToggleButton = createPrescriptionOverlayToggleButton(
|
|
351
|
+
state.videoOverlay?.overlay || state.container,
|
|
352
|
+
{
|
|
353
|
+
initial: state.prescriptionLabelActiveOverlay,
|
|
354
|
+
bottleLabel: state.prescriptionLabelBottleLabel,
|
|
355
|
+
boxLabel: state.prescriptionLabelBoxLabel,
|
|
356
|
+
onToggle: (type) => {
|
|
357
|
+
state.prescriptionLabelActiveOverlay = type;
|
|
358
|
+
applyOverlayVisibility();
|
|
359
|
+
const text = type === 'box'
|
|
360
|
+
? state.prescriptionLabelSquareGuideText
|
|
361
|
+
: state.prescriptionLabelGuideText;
|
|
362
|
+
state.prescriptionLabelGuide?.setText?.(text);
|
|
363
|
+
},
|
|
364
|
+
}
|
|
365
|
+
);
|
|
366
|
+
}
|
|
320
367
|
};
|
|
321
368
|
|
|
322
369
|
export const renderCodeStripsOverlayIfNeeded = () => {
|
package/package.json
CHANGED
package/veryfi-lens.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { state, refs, actions } from './core/state.js';
|
|
2
|
-
import { DEFAULTS, setApiEnvironment } from './core/constants.js';
|
|
2
|
+
import { DEFAULTS, setApiEnvironment, setApiBaseUrl } from './core/constants.js';
|
|
3
3
|
import { flattenObject, parseUA, getBrowserData } from './core/utils.js';
|
|
4
4
|
import { generateDeviceIDifNeeded, setLCDDetectionSettings, setFrontBackDetectionSettings, getDocumentLcdStatus } from './core/device.js';
|
|
5
5
|
import {
|
|
@@ -42,7 +42,11 @@ const VeryfiLens = {
|
|
|
42
42
|
config.debug_mode && console.log("init", config);
|
|
43
43
|
state.clientId = clientId;
|
|
44
44
|
state.useDevApi = config.useDevApi ?? false;
|
|
45
|
-
|
|
45
|
+
if (config.lfbApiBaseUrl) {
|
|
46
|
+
setApiBaseUrl(config.lfbApiBaseUrl);
|
|
47
|
+
} else {
|
|
48
|
+
setApiEnvironment(state.useDevApi);
|
|
49
|
+
}
|
|
46
50
|
state.clientData = await validatePartner(state.clientId);
|
|
47
51
|
config.debug_mode && console.log(state.clientData);
|
|
48
52
|
|