veryfi-lens-wasm 3.0.3 → 3.0.4
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 +9 -2
- package/components/checkOverlay.js +95 -23
- package/components/exitButton.js +1 -1
- package/components/mirrorButton.js +68 -0
- package/components/prescriptionSquareOverlay.js +126 -0
- package/components/switchCameraButton.js +68 -0
- package/components/torchButton.js +1 -1
- package/core/camera.js +70 -0
- package/core/constants.js +4 -2
- package/core/overlay-controls.js +16 -0
- package/core/state.js +17 -0
- package/core/ui-renderer.js +42 -6
- package/package.json +1 -1
- package/veryfi-lens.js +3 -1
package/README.md
CHANGED
|
@@ -120,6 +120,9 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
|
|
|
120
120
|
|---|---|---|---|
|
|
121
121
|
| `torchButton` | `boolean` | `true` | Show torch/flashlight toggle |
|
|
122
122
|
| `torchOnStart` | `boolean` | `true` | Turn torch on when camera starts |
|
|
123
|
+
| `switchCameraButton` | `boolean` | `true` | Show switch camera (front/back) button |
|
|
124
|
+
| `mirrorButton` | `boolean` | `true` | Show mirror/flip video button |
|
|
125
|
+
| `mirrorOnDesktop` | `boolean` | `true` | Auto-mirror video on desktop (front-facing webcam) |
|
|
123
126
|
| `exitButton` | `boolean` | `false` | Show exit/close button |
|
|
124
127
|
| `onClose` | `function` | — | Callback when lens is closed |
|
|
125
128
|
| `onCloseRedirectUrl` | `string` | — | URL to redirect to on close |
|
|
@@ -223,9 +226,13 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
|
|
|
223
226
|
|
|
224
227
|
| Option | Type | Default | Description |
|
|
225
228
|
|---|---|---|---|
|
|
226
|
-
| `
|
|
227
|
-
| `
|
|
229
|
+
| `prescriptionLabelShowOverlay` | `boolean` | `true` | Show the bottle cutout overlay guide |
|
|
230
|
+
| `prescriptionLabelWidthRatio` | `number` | `0.55` | Bottle overlay width (0-1 relative to viewport) |
|
|
231
|
+
| `prescriptionLabelHeightRatio` | `number` | `0.65` | Bottle overlay height (0-1 relative to viewport) |
|
|
228
232
|
| `prescriptionLabelText` | `string` | `"Position prescription label in outline"` | Instruction text |
|
|
233
|
+
| `prescriptionLabelShowSquareOverlay` | `boolean` | `false` | Show a square/rectangular overlay guide |
|
|
234
|
+
| `prescriptionLabelSquareWidthRatio` | `number` | `0.8` | Square overlay width (0-1 relative to viewport) |
|
|
235
|
+
| `prescriptionLabelSquareHeightRatio` | `number` | `0.5` | Square overlay height (0-1 relative to viewport) |
|
|
229
236
|
|
|
230
237
|
### Upload Settings (`upload` flavor)
|
|
231
238
|
|
|
@@ -3,9 +3,7 @@ import { createOverlayBase } from './overlayBase.js';
|
|
|
3
3
|
export const createCheckOverlay = (container, options = {}) => {
|
|
4
4
|
const cropLayoutAspectRatio = options.cropLayoutAspectRatio !== undefined ? options.cropLayoutAspectRatio : 0.0;
|
|
5
5
|
const cropMargin = options.cropMargin !== undefined ? options.cropMargin : 0.0;
|
|
6
|
-
const instructionText = options.instructionText || "
|
|
7
|
-
const borderColor = options.borderColor || "#54C08B";
|
|
8
|
-
const borderWidth = options.borderWidth !== undefined ? options.borderWidth : 2;
|
|
6
|
+
const instructionText = options.instructionText || "We could not detect a check, hope this will make it easier";
|
|
9
7
|
const overlayAlpha = options.overlayAlpha !== undefined ? options.overlayAlpha : 0.6;
|
|
10
8
|
const cornerRadius = options.cornerRadius !== undefined ? options.cornerRadius : 0;
|
|
11
9
|
const guideTopPosition = options.guideTopPosition || "40%";
|
|
@@ -33,38 +31,109 @@ export const createCheckOverlay = (container, options = {}) => {
|
|
|
33
31
|
|
|
34
32
|
const rectGuide = document.createElement("div");
|
|
35
33
|
rectGuide.id = "veryfi-check-guide";
|
|
36
|
-
rectGuide.style
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
Object.assign(rectGuide.style, {
|
|
35
|
+
position: "absolute",
|
|
36
|
+
top: guideTopPosition,
|
|
37
|
+
left: guideLeftPosition,
|
|
38
|
+
transform: "translate(-50%, -50%)",
|
|
39
|
+
border: "none",
|
|
40
|
+
borderRadius: `${cornerRadius}px`,
|
|
41
|
+
zIndex: "1003",
|
|
42
|
+
pointerEvents: "none",
|
|
43
|
+
boxSizing: "border-box",
|
|
44
|
+
overflow: "hidden",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const micrLine = document.createElement("div");
|
|
48
|
+
micrLine.id = "veryfi-check-micr";
|
|
49
|
+
Object.assign(micrLine.style, {
|
|
50
|
+
position: "absolute",
|
|
51
|
+
left: "5%",
|
|
52
|
+
top: "3%",
|
|
53
|
+
transform: "rotate(90deg)",
|
|
54
|
+
transformOrigin: "left bottom",
|
|
55
|
+
display: "flex",
|
|
56
|
+
alignItems: "center",
|
|
57
|
+
gap: "8px",
|
|
58
|
+
pointerEvents: "none",
|
|
59
|
+
whiteSpace: "nowrap",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const createMicrSegment = (text) => {
|
|
63
|
+
const span = document.createElement("span");
|
|
64
|
+
span.textContent = text;
|
|
65
|
+
Object.assign(span.style, {
|
|
66
|
+
color: "rgba(255, 255, 255, 0.5)",
|
|
67
|
+
fontFamily: "'Courier New', Courier, monospace",
|
|
68
|
+
fontSize: "14px",
|
|
69
|
+
fontWeight: "bold",
|
|
70
|
+
letterSpacing: "2px",
|
|
71
|
+
whiteSpace: "nowrap",
|
|
72
|
+
});
|
|
73
|
+
return span;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
micrLine.appendChild(createMicrSegment("####"));
|
|
77
|
+
micrLine.appendChild(createMicrSegment("####"));
|
|
78
|
+
micrLine.appendChild(createMicrSegment("####"));
|
|
79
|
+
|
|
80
|
+
const micrLineBottom = document.createElement("div");
|
|
81
|
+
micrLineBottom.id = "veryfi-check-micr-bottom";
|
|
82
|
+
Object.assign(micrLineBottom.style, {
|
|
83
|
+
position: "absolute",
|
|
84
|
+
right: "15%",
|
|
85
|
+
bottom: "8%",
|
|
86
|
+
transform: "rotate(90deg)",
|
|
87
|
+
transformOrigin: "right bottom",
|
|
88
|
+
display: "flex",
|
|
89
|
+
alignItems: "center",
|
|
90
|
+
gap: "8px",
|
|
91
|
+
pointerEvents: "none",
|
|
92
|
+
whiteSpace: "nowrap",
|
|
93
|
+
});
|
|
94
|
+
micrLineBottom.appendChild(createMicrSegment("###"));
|
|
95
|
+
|
|
96
|
+
const separatorLine = document.createElement("div");
|
|
97
|
+
Object.assign(separatorLine.style, {
|
|
98
|
+
position: "absolute",
|
|
99
|
+
left: "15%",
|
|
100
|
+
top: "5%",
|
|
101
|
+
bottom: "5%",
|
|
102
|
+
width: "1px",
|
|
103
|
+
backgroundColor: "rgba(255, 255, 255, 0.35)",
|
|
104
|
+
pointerEvents: "none",
|
|
105
|
+
});
|
|
45
106
|
|
|
46
107
|
const textLabel = document.createElement("div");
|
|
47
108
|
textLabel.id = "veryfi-check-label";
|
|
48
109
|
textLabel.textContent = instructionText;
|
|
49
|
-
textLabel.style
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
110
|
+
Object.assign(textLabel.style, {
|
|
111
|
+
position: "absolute",
|
|
112
|
+
color: tipColor,
|
|
113
|
+
fontFamily: tipFontFamily,
|
|
114
|
+
fontSize: tipFontSize,
|
|
115
|
+
fontWeight: tipFontWeight,
|
|
116
|
+
zIndex: "1004",
|
|
117
|
+
textShadow: tipTextShadow,
|
|
118
|
+
whiteSpace: "nowrap",
|
|
119
|
+
backgroundColor: "rgba(255, 255, 255, 0.85)",
|
|
120
|
+
color: "#333",
|
|
121
|
+
padding: "6px 14px",
|
|
122
|
+
borderRadius: "20px",
|
|
123
|
+
textShadow: "none",
|
|
124
|
+
});
|
|
58
125
|
|
|
59
126
|
switch (tipPosition) {
|
|
60
127
|
case "top":
|
|
61
128
|
textLabel.style.bottom = "100%";
|
|
62
|
-
textLabel.style.left = "
|
|
129
|
+
textLabel.style.left = "50%";
|
|
130
|
+
textLabel.style.transform = "translateX(-50%)";
|
|
63
131
|
textLabel.style.marginBottom = tipOffset;
|
|
64
132
|
break;
|
|
65
133
|
case "bottom":
|
|
66
134
|
textLabel.style.top = "100%";
|
|
67
|
-
textLabel.style.left = "
|
|
135
|
+
textLabel.style.left = "50%";
|
|
136
|
+
textLabel.style.transform = "translateX(-50%)";
|
|
68
137
|
textLabel.style.marginTop = tipOffset;
|
|
69
138
|
break;
|
|
70
139
|
case "left":
|
|
@@ -99,6 +168,9 @@ export const createCheckOverlay = (container, options = {}) => {
|
|
|
99
168
|
buildContent: (overlay) => {
|
|
100
169
|
overlay.appendChild(rectHole);
|
|
101
170
|
overlay.appendChild(rectGuide);
|
|
171
|
+
rectGuide.appendChild(micrLine);
|
|
172
|
+
rectGuide.appendChild(micrLineBottom);
|
|
173
|
+
rectGuide.appendChild(separatorLine);
|
|
102
174
|
rectGuide.appendChild(textLabel);
|
|
103
175
|
|
|
104
176
|
return (videoRect) => {
|
package/components/exitButton.js
CHANGED
|
@@ -8,7 +8,7 @@ export const createExitButton = (container, options, removeOverlay) => {
|
|
|
8
8
|
const defaultStyles = {
|
|
9
9
|
position: 'absolute',
|
|
10
10
|
bottom: '50px',
|
|
11
|
-
left: '
|
|
11
|
+
left: '115px',
|
|
12
12
|
backgroundColor: 'rgba(255, 255, 255, 0.15)',
|
|
13
13
|
color: 'white',
|
|
14
14
|
fontWeight: 'bold',
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export const createMirrorButton = (container, toggleCallback) => {
|
|
2
|
+
const button = document.createElement('button');
|
|
3
|
+
button.id = 'veryfi-mirror-button';
|
|
4
|
+
|
|
5
|
+
const defaultStyles = {
|
|
6
|
+
width: '40px',
|
|
7
|
+
height: '40px',
|
|
8
|
+
backgroundColor: 'rgba(255, 255, 255, 0.15)',
|
|
9
|
+
color: '#FFFFFF',
|
|
10
|
+
borderRadius: '50%',
|
|
11
|
+
position: 'absolute',
|
|
12
|
+
bottom: '50px',
|
|
13
|
+
left: '50px',
|
|
14
|
+
zIndex: '1000',
|
|
15
|
+
display: 'flex',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
justifyContent: 'center',
|
|
18
|
+
padding: '0',
|
|
19
|
+
cursor: 'pointer',
|
|
20
|
+
pointerEvents: 'auto',
|
|
21
|
+
border: '1px solid rgba(255, 255, 255, 0.4)',
|
|
22
|
+
outline: 'none',
|
|
23
|
+
boxSizing: 'border-box',
|
|
24
|
+
margin: '0',
|
|
25
|
+
minWidth: '40px',
|
|
26
|
+
minHeight: '40px',
|
|
27
|
+
maxWidth: '40px',
|
|
28
|
+
maxHeight: '40px',
|
|
29
|
+
backdropFilter: 'blur(8px)',
|
|
30
|
+
WebkitBackdropFilter: 'blur(8px)',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
34
|
+
button.style[key] = value;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
button.addEventListener('mouseover', () => {
|
|
38
|
+
button.style.backgroundColor = 'rgba(255, 255, 255, 0.25)';
|
|
39
|
+
});
|
|
40
|
+
button.addEventListener('mouseout', () => {
|
|
41
|
+
button.style.backgroundColor = 'rgba(255, 255, 255, 0.15)';
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
button.addEventListener('click', toggleCallback);
|
|
45
|
+
|
|
46
|
+
button.innerHTML = `
|
|
47
|
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width: 20px; height: 20px;">
|
|
48
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M7.5 21L3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5"/>
|
|
49
|
+
</svg>
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
container.appendChild(button);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
show: () => {
|
|
56
|
+
button.style.display = 'flex';
|
|
57
|
+
},
|
|
58
|
+
hide: () => {
|
|
59
|
+
button.style.display = 'none';
|
|
60
|
+
},
|
|
61
|
+
remove: () => {
|
|
62
|
+
if (button.parentNode) {
|
|
63
|
+
button.parentNode.removeChild(button);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
button: button,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createOverlayBase, createLoadingSpinner } from './overlayBase.js';
|
|
2
|
+
|
|
3
|
+
const buildSquarePath = (vw, vh, widthRatio, heightRatio) => {
|
|
4
|
+
const w = vw * widthRatio;
|
|
5
|
+
const h = vh * heightRatio;
|
|
6
|
+
const r = Math.min(w, h) * 0.02;
|
|
7
|
+
|
|
8
|
+
const cx = vw / 2;
|
|
9
|
+
const cy = vh * 0.46;
|
|
10
|
+
|
|
11
|
+
const x1 = cx - w / 2;
|
|
12
|
+
const x2 = cx + w / 2;
|
|
13
|
+
const y1 = cy - h / 2;
|
|
14
|
+
const y2 = cy + h / 2;
|
|
15
|
+
|
|
16
|
+
return [
|
|
17
|
+
`M ${x1 + r} ${y1}`,
|
|
18
|
+
`H ${x2 - r}`,
|
|
19
|
+
`A ${r} ${r} 0 0 1 ${x2} ${y1 + r}`,
|
|
20
|
+
`V ${y2 - r}`,
|
|
21
|
+
`A ${r} ${r} 0 0 1 ${x2 - r} ${y2}`,
|
|
22
|
+
`H ${x1 + r}`,
|
|
23
|
+
`A ${r} ${r} 0 0 1 ${x1} ${y2 - r}`,
|
|
24
|
+
`V ${y1 + r}`,
|
|
25
|
+
`A ${r} ${r} 0 0 1 ${x1 + r} ${y1}`,
|
|
26
|
+
`Z`
|
|
27
|
+
].join(' ');
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const NS = 'http://www.w3.org/2000/svg';
|
|
31
|
+
|
|
32
|
+
let traceStyleEl = null;
|
|
33
|
+
|
|
34
|
+
const setTraceAnimation = (totalLen) => {
|
|
35
|
+
if (traceStyleEl) traceStyleEl.remove();
|
|
36
|
+
traceStyleEl = document.createElement('style');
|
|
37
|
+
traceStyleEl.id = 'veryfi-square-trace-keyframes';
|
|
38
|
+
traceStyleEl.textContent = `
|
|
39
|
+
@keyframes veryfi-square-trace {
|
|
40
|
+
0% { stroke-dashoffset: 0; }
|
|
41
|
+
100% { stroke-dashoffset: ${-totalLen}; }
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
document.head.appendChild(traceStyleEl);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const createPrescriptionSquareOverlay = (container, options = {}) => {
|
|
48
|
+
const widthRatio = options.squareWidthRatio !== undefined ? options.squareWidthRatio : 0.8;
|
|
49
|
+
const heightRatio = options.squareHeightRatio !== undefined ? options.squareHeightRatio : 0.5;
|
|
50
|
+
|
|
51
|
+
const svg = document.createElementNS(NS, 'svg');
|
|
52
|
+
svg.style.position = 'absolute';
|
|
53
|
+
svg.style.top = '0';
|
|
54
|
+
svg.style.left = '0';
|
|
55
|
+
svg.style.width = '100%';
|
|
56
|
+
svg.style.height = '100%';
|
|
57
|
+
svg.style.zIndex = '1002';
|
|
58
|
+
svg.style.pointerEvents = 'none';
|
|
59
|
+
|
|
60
|
+
const maskPath = document.createElementNS(NS, 'path');
|
|
61
|
+
maskPath.setAttribute('fill', 'rgba(0, 0, 0, 0.6)');
|
|
62
|
+
maskPath.setAttribute('fill-rule', 'evenodd');
|
|
63
|
+
svg.appendChild(maskPath);
|
|
64
|
+
|
|
65
|
+
const guidePath = document.createElementNS(NS, 'path');
|
|
66
|
+
guidePath.setAttribute('fill', 'none');
|
|
67
|
+
guidePath.setAttribute('stroke', '#00AA00');
|
|
68
|
+
guidePath.setAttribute('stroke-width', '3');
|
|
69
|
+
guidePath.setAttribute('stroke-linecap', 'round');
|
|
70
|
+
svg.appendChild(guidePath);
|
|
71
|
+
|
|
72
|
+
const loadingIndicator = createLoadingSpinner('veryfi-prescription-square-loading');
|
|
73
|
+
|
|
74
|
+
let dashInitialized = false;
|
|
75
|
+
|
|
76
|
+
const base = createOverlayBase(container, {
|
|
77
|
+
id: 'veryfi-prescription-square-overlay',
|
|
78
|
+
hasSpinner: true,
|
|
79
|
+
buildContent: (overlay) => {
|
|
80
|
+
overlay.appendChild(svg);
|
|
81
|
+
overlay.appendChild(loadingIndicator);
|
|
82
|
+
|
|
83
|
+
return (videoRect, videoElement) => {
|
|
84
|
+
const vw = videoRect.width;
|
|
85
|
+
const vh = videoRect.height;
|
|
86
|
+
|
|
87
|
+
if (vw <= 0 || vh <= 0) return;
|
|
88
|
+
|
|
89
|
+
svg.setAttribute('viewBox', `0 0 ${vw} ${vh}`);
|
|
90
|
+
|
|
91
|
+
const outerRect = `M 0 0 H ${vw} V ${vh} H 0 Z`;
|
|
92
|
+
const square = buildSquarePath(vw, vh, widthRatio, heightRatio);
|
|
93
|
+
|
|
94
|
+
maskPath.setAttribute('d', `${outerRect} ${square}`);
|
|
95
|
+
guidePath.setAttribute('d', square);
|
|
96
|
+
|
|
97
|
+
if (!dashInitialized) {
|
|
98
|
+
const totalLen = guidePath.getTotalLength();
|
|
99
|
+
const dashLen = totalLen * 0.15;
|
|
100
|
+
const gapLen = totalLen - dashLen;
|
|
101
|
+
|
|
102
|
+
guidePath.setAttribute('stroke-dasharray', `${dashLen} ${gapLen}`);
|
|
103
|
+
setTraceAnimation(totalLen);
|
|
104
|
+
guidePath.style.animation = 'veryfi-square-trace 3s linear infinite';
|
|
105
|
+
dashInitialized = true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (videoElement.readyState >= 2) {
|
|
109
|
+
loadingIndicator.style.display = 'none';
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
cropFn: null,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
...base,
|
|
118
|
+
cleanup: () => {
|
|
119
|
+
base.cleanup();
|
|
120
|
+
if (traceStyleEl) {
|
|
121
|
+
traceStyleEl.remove();
|
|
122
|
+
traceStyleEl = null;
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export const createSwitchCameraButton = (container, toggleCallback) => {
|
|
2
|
+
const button = document.createElement('button');
|
|
3
|
+
button.id = 'veryfi-switch-camera-button';
|
|
4
|
+
|
|
5
|
+
const defaultStyles = {
|
|
6
|
+
width: '40px',
|
|
7
|
+
height: '40px',
|
|
8
|
+
backgroundColor: 'rgba(255, 255, 255, 0.15)',
|
|
9
|
+
color: '#FFFFFF',
|
|
10
|
+
borderRadius: '50%',
|
|
11
|
+
position: 'absolute',
|
|
12
|
+
bottom: '50px',
|
|
13
|
+
right: '50px',
|
|
14
|
+
zIndex: '1000',
|
|
15
|
+
display: 'flex',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
justifyContent: 'center',
|
|
18
|
+
padding: '0',
|
|
19
|
+
cursor: 'pointer',
|
|
20
|
+
pointerEvents: 'auto',
|
|
21
|
+
border: '1px solid rgba(255, 255, 255, 0.4)',
|
|
22
|
+
outline: 'none',
|
|
23
|
+
boxSizing: 'border-box',
|
|
24
|
+
margin: '0',
|
|
25
|
+
minWidth: '40px',
|
|
26
|
+
minHeight: '40px',
|
|
27
|
+
maxWidth: '40px',
|
|
28
|
+
maxHeight: '40px',
|
|
29
|
+
backdropFilter: 'blur(8px)',
|
|
30
|
+
WebkitBackdropFilter: 'blur(8px)',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
34
|
+
button.style[key] = value;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
button.addEventListener('mouseover', () => {
|
|
38
|
+
button.style.backgroundColor = 'rgba(255, 255, 255, 0.25)';
|
|
39
|
+
});
|
|
40
|
+
button.addEventListener('mouseout', () => {
|
|
41
|
+
button.style.backgroundColor = 'rgba(255, 255, 255, 0.15)';
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
button.addEventListener('click', toggleCallback);
|
|
45
|
+
|
|
46
|
+
button.innerHTML = `
|
|
47
|
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width: 20px; height: 20px;">
|
|
48
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.992 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182M20.015 4.356v4.992"/>
|
|
49
|
+
</svg>
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
container.appendChild(button);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
show: () => {
|
|
56
|
+
button.style.display = 'flex';
|
|
57
|
+
},
|
|
58
|
+
hide: () => {
|
|
59
|
+
button.style.display = 'none';
|
|
60
|
+
},
|
|
61
|
+
remove: () => {
|
|
62
|
+
if (button.parentNode) {
|
|
63
|
+
button.parentNode.removeChild(button);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
button: button,
|
|
67
|
+
};
|
|
68
|
+
};
|
package/core/camera.js
CHANGED
|
@@ -69,6 +69,16 @@ export const getVideo = async (lensFlavor) => {
|
|
|
69
69
|
|
|
70
70
|
state.videoRef.addEventListener('loadedmetadata', () => {
|
|
71
71
|
state.videoRef.style.opacity = '1';
|
|
72
|
+
|
|
73
|
+
if (state.mirrorOnDesktop) {
|
|
74
|
+
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
|
|
75
|
+
if (!isMobile && !state.isMirrored) {
|
|
76
|
+
state.isMirrored = true;
|
|
77
|
+
state.videoRef.style.transform = 'scaleX(-1)';
|
|
78
|
+
if (state.boxRef) state.boxRef.style.transform = 'scaleX(-1)';
|
|
79
|
+
state.debug_mode && console.log('Auto-mirrored video on desktop');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
72
82
|
}, { once: true });
|
|
73
83
|
|
|
74
84
|
state.videoRef.style.width = '100vw';
|
|
@@ -179,6 +189,66 @@ export const getChecksVideo = async () => {
|
|
|
179
189
|
}
|
|
180
190
|
};
|
|
181
191
|
|
|
192
|
+
export const mirrorVideo = () => {
|
|
193
|
+
if (!state.videoRef) return;
|
|
194
|
+
state.isMirrored = !state.isMirrored;
|
|
195
|
+
const mirrorTransform = state.isMirrored ? 'scaleX(-1)' : '';
|
|
196
|
+
state.videoRef.style.transform = mirrorTransform;
|
|
197
|
+
if (state.boxRef) state.boxRef.style.transform = mirrorTransform;
|
|
198
|
+
state.debug_mode && console.log('Video mirrored:', state.isMirrored);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export const switchCamera = async () => {
|
|
202
|
+
if (!state.videoRef) return;
|
|
203
|
+
|
|
204
|
+
const currentFacing = state.cameraFacingMode || 'environment';
|
|
205
|
+
const newFacing = currentFacing === 'environment' ? 'user' : 'environment';
|
|
206
|
+
|
|
207
|
+
if (state.videoRef.srcObject) {
|
|
208
|
+
state.videoRef.srcObject.getTracks().forEach((track) => track.stop());
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const videoConfig = {
|
|
212
|
+
width: { ideal: 3840 },
|
|
213
|
+
height: { ideal: 2160 },
|
|
214
|
+
facingMode: newFacing,
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
state.updateHandler?.({ status: 'camera_switching' });
|
|
219
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
220
|
+
audio: false,
|
|
221
|
+
video: videoConfig,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
state.videoRef.srcObject = stream;
|
|
225
|
+
state.cameraFacingMode = newFacing;
|
|
226
|
+
|
|
227
|
+
const videoTracks = stream.getVideoTracks();
|
|
228
|
+
if (videoTracks.length > 0) {
|
|
229
|
+
const track = videoTracks[0];
|
|
230
|
+
state.torchTrack = track;
|
|
231
|
+
const capabilities = track.getCapabilities();
|
|
232
|
+
state.torchEnabled = !!capabilities.torch;
|
|
233
|
+
|
|
234
|
+
if (state.torchButtonRef) {
|
|
235
|
+
if (state.torchEnabled) {
|
|
236
|
+
state.torchButtonRef.show();
|
|
237
|
+
} else {
|
|
238
|
+
state.torchButtonRef.hide();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
state.updateHandler?.({ status: 'camera_ready' });
|
|
244
|
+
state.debug_mode && console.log('Switched camera to:', newFacing);
|
|
245
|
+
} catch (err) {
|
|
246
|
+
console.error('Error switching camera:', err);
|
|
247
|
+
state.updateHandler?.({ status: 'camera_switch_failed', error: err.message });
|
|
248
|
+
state.failureHandler?.(err);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
182
252
|
export const toggleTorchLight = async () => {
|
|
183
253
|
if (!state.torchTrack) {
|
|
184
254
|
state.debug_mode && console.log("Camera not initialized");
|
package/core/constants.js
CHANGED
|
@@ -12,7 +12,7 @@ export const API_URLS = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export const DEFAULTS = {
|
|
15
|
-
SDK_VERSION: '3.0.
|
|
15
|
+
SDK_VERSION: '3.0.4',
|
|
16
16
|
BLUR_THRESHOLD: 0.7,
|
|
17
17
|
LCD_THRESHOLD: 0.5,
|
|
18
18
|
BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
|
|
@@ -29,6 +29,8 @@ export const DEFAULTS = {
|
|
|
29
29
|
RECT_HEIGHT: 0.08,
|
|
30
30
|
PRESCRIPTION_LABEL_WIDTH: 0.55,
|
|
31
31
|
PRESCRIPTION_LABEL_HEIGHT: 0.65,
|
|
32
|
+
PRESCRIPTION_SQUARE_WIDTH: 0.8,
|
|
33
|
+
PRESCRIPTION_SQUARE_HEIGHT: 0.5,
|
|
32
34
|
EXPAND_FACTOR: 1.02,
|
|
33
35
|
CROP_LAYOUT_OVERLAY_ALPHA: 0.6,
|
|
34
36
|
CROP_LAYOUT_STROKE: 2,
|
|
@@ -57,7 +59,7 @@ export const MESSAGES = {
|
|
|
57
59
|
BOTTLE_CAP: 'Position bottle cap in circle',
|
|
58
60
|
PRESCRIPTION_LABEL: 'Position prescription label in outline',
|
|
59
61
|
CODE_STRIPS: 'Position code strip in rectangle',
|
|
60
|
-
CHECK_POSITION: '
|
|
62
|
+
CHECK_POSITION: 'We could not detect a check, hope this will make it easier',
|
|
61
63
|
ANYDOC_ADD_PAGE: 'Add Page',
|
|
62
64
|
ANYDOC_SUBMIT: 'Submit',
|
|
63
65
|
ANYDOC_FLIP: 'Please flip the document and capture the other side',
|
package/core/overlay-controls.js
CHANGED
|
@@ -17,6 +17,14 @@ export const hideVideoOverlay = () => {
|
|
|
17
17
|
state.torchButtonRef.button.style.display = 'none';
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
if (typeof state.mirrorButtonRef?.hide === 'function') {
|
|
21
|
+
state.mirrorButtonRef.hide();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (typeof state.switchCameraButtonRef?.hide === 'function') {
|
|
25
|
+
state.switchCameraButtonRef.hide();
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
if (state.submitButton) {
|
|
21
29
|
state.submitButton.hide();
|
|
22
30
|
}
|
|
@@ -49,6 +57,14 @@ export const showVideoOverlay = () => {
|
|
|
49
57
|
state.exitButtonRef.show();
|
|
50
58
|
}
|
|
51
59
|
|
|
60
|
+
if (typeof state.mirrorButtonRef?.show === 'function') {
|
|
61
|
+
state.mirrorButtonRef.show();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (typeof state.switchCameraButtonRef?.show === 'function') {
|
|
65
|
+
state.switchCameraButtonRef.show();
|
|
66
|
+
}
|
|
67
|
+
|
|
52
68
|
if (state.isManualCheckCapture && state.checkOverlay) {
|
|
53
69
|
state.checkOverlay.show();
|
|
54
70
|
}
|
package/core/state.js
CHANGED
|
@@ -19,6 +19,9 @@ export const state = {
|
|
|
19
19
|
hasInit: false,
|
|
20
20
|
torchEnabled: true,
|
|
21
21
|
torchOnStart: true,
|
|
22
|
+
isMirrored: false,
|
|
23
|
+
mirrorOnDesktop: true,
|
|
24
|
+
cameraFacingMode: 'environment',
|
|
22
25
|
shouldProcessCC: true,
|
|
23
26
|
|
|
24
27
|
// Document state
|
|
@@ -74,6 +77,8 @@ export const state = {
|
|
|
74
77
|
|
|
75
78
|
// UI Configuration
|
|
76
79
|
torchButton: true,
|
|
80
|
+
switchCameraButton: true,
|
|
81
|
+
mirrorButton: true,
|
|
77
82
|
detectBlur: true,
|
|
78
83
|
isBlurModal: true,
|
|
79
84
|
isDocumentModal: true,
|
|
@@ -146,6 +151,8 @@ export const state = {
|
|
|
146
151
|
documentModal: null,
|
|
147
152
|
lcdModal: null,
|
|
148
153
|
torchButtonRef: null,
|
|
154
|
+
mirrorButtonRef: null,
|
|
155
|
+
switchCameraButtonRef: null,
|
|
149
156
|
uploadContainer: null,
|
|
150
157
|
fileUpload: null,
|
|
151
158
|
croppedImage: null,
|
|
@@ -182,9 +189,14 @@ export const state = {
|
|
|
182
189
|
bottleCapOverlay: null,
|
|
183
190
|
|
|
184
191
|
prescriptionLabelOverlay: null,
|
|
192
|
+
prescriptionLabelShowOverlay: true,
|
|
185
193
|
prescriptionLabelWidthRatio: DEFAULTS.PRESCRIPTION_LABEL_WIDTH,
|
|
186
194
|
prescriptionLabelHeightRatio: DEFAULTS.PRESCRIPTION_LABEL_HEIGHT,
|
|
187
195
|
prescriptionLabelText: MESSAGES.PRESCRIPTION_LABEL,
|
|
196
|
+
prescriptionSquareOverlay: null,
|
|
197
|
+
prescriptionLabelShowSquareOverlay: false,
|
|
198
|
+
prescriptionLabelSquareWidthRatio: DEFAULTS.PRESCRIPTION_SQUARE_WIDTH,
|
|
199
|
+
prescriptionLabelSquareHeightRatio: DEFAULTS.PRESCRIPTION_SQUARE_HEIGHT,
|
|
188
200
|
preferredVideoFormat: null,
|
|
189
201
|
|
|
190
202
|
codeStripsOverlay: null,
|
|
@@ -286,6 +298,10 @@ export const resetState = () => {
|
|
|
286
298
|
state.videoRef = null;
|
|
287
299
|
state.boxRef = null;
|
|
288
300
|
state.torchButtonRef = null;
|
|
301
|
+
state.mirrorButtonRef = null;
|
|
302
|
+
state.switchCameraButtonRef = null;
|
|
303
|
+
state.isMirrored = false;
|
|
304
|
+
state.cameraFacingMode = 'environment';
|
|
289
305
|
state.captureButton = null;
|
|
290
306
|
state.submitButton = null;
|
|
291
307
|
state.exitButtonRef = null;
|
|
@@ -294,6 +310,7 @@ export const resetState = () => {
|
|
|
294
310
|
state.checkImagesComponent = null;
|
|
295
311
|
state.bottleCapOverlay = null;
|
|
296
312
|
state.prescriptionLabelOverlay = null;
|
|
313
|
+
state.prescriptionSquareOverlay = null;
|
|
297
314
|
state.codeStripsOverlay = null;
|
|
298
315
|
state.checkOverlay = null;
|
|
299
316
|
state.isManualCheckCapture = false;
|
package/core/ui-renderer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { state, refs, actions } from './state.js';
|
|
2
2
|
import { hideVideoOverlay, showVideoOverlay } from './overlay-controls.js';
|
|
3
|
-
import { toggleTorchLight } from './camera.js';
|
|
3
|
+
import { toggleTorchLight, mirrorVideo, switchCamera } from './camera.js';
|
|
4
4
|
import { createVideo } from '../components/video.js';
|
|
5
5
|
import { createBlurModal } from '../components/blurModal.js';
|
|
6
6
|
import { createDocumentModal } from '../components/documentModal.js';
|
|
@@ -17,6 +17,9 @@ import { createCardDataButton } from '../components/cardDataButton.js';
|
|
|
17
17
|
import { createBottleCapOverlay } from '../components/bottleCapOverlay.js';
|
|
18
18
|
import { createCodeStripsOverlay } from '../components/codeStripsOverlay.js';
|
|
19
19
|
import { createPrescriptionLabelOverlay } from '../components/prescriptionLabelOverlay.js';
|
|
20
|
+
import { createPrescriptionSquareOverlay } from '../components/prescriptionSquareOverlay.js';
|
|
21
|
+
import { createMirrorButton } from '../components/mirrorButton.js';
|
|
22
|
+
import { createSwitchCameraButton } from '../components/switchCameraButton.js';
|
|
20
23
|
|
|
21
24
|
export const renderWatermarkIfNeeded = () => {
|
|
22
25
|
if (state.clientData?.show_watermark) {
|
|
@@ -49,6 +52,18 @@ const setupVideoOverlayControls = (captureAction) => {
|
|
|
49
52
|
}, state.lensFlavor);
|
|
50
53
|
}
|
|
51
54
|
|
|
55
|
+
if (state.switchCameraButton) {
|
|
56
|
+
state.switchCameraButtonRef = createSwitchCameraButton(state.videoOverlay.overlay, () => {
|
|
57
|
+
switchCamera();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (state.mirrorButton) {
|
|
62
|
+
state.mirrorButtonRef = createMirrorButton(state.videoOverlay.overlay, () => {
|
|
63
|
+
mirrorVideo();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
52
67
|
renderWatermarkIfNeeded();
|
|
53
68
|
};
|
|
54
69
|
|
|
@@ -127,6 +142,18 @@ export const renderVideoOverlayIfNeeded = () => {
|
|
|
127
142
|
}, state.lensFlavor);
|
|
128
143
|
}
|
|
129
144
|
|
|
145
|
+
if (state.switchCameraButton) {
|
|
146
|
+
state.switchCameraButtonRef = createSwitchCameraButton(state.videoOverlay.overlay, () => {
|
|
147
|
+
switchCamera();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (state.mirrorButton) {
|
|
152
|
+
state.mirrorButtonRef = createMirrorButton(state.videoOverlay.overlay, () => {
|
|
153
|
+
mirrorVideo();
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
130
157
|
renderWatermarkIfNeeded();
|
|
131
158
|
};
|
|
132
159
|
|
|
@@ -261,11 +288,20 @@ export const renderPrescriptionLabelOverlayIfNeeded = () => {
|
|
|
261
288
|
state.debug_mode && console.log("Rendering prescription label overlay");
|
|
262
289
|
setupVideoOverlayControls(() => actions.capturePrescriptionLabel());
|
|
263
290
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
291
|
+
if (state.prescriptionLabelShowOverlay) {
|
|
292
|
+
createSpecialtyOverlayOnReady('prescriptionLabelOverlay', createPrescriptionLabelOverlay, {
|
|
293
|
+
bottleWidthRatio: state.prescriptionLabelWidthRatio,
|
|
294
|
+
bottleHeightRatio: state.prescriptionLabelHeightRatio,
|
|
295
|
+
instructionText: state.prescriptionLabelText
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (state.prescriptionLabelShowSquareOverlay) {
|
|
300
|
+
createSpecialtyOverlayOnReady('prescriptionSquareOverlay', createPrescriptionSquareOverlay, {
|
|
301
|
+
squareWidthRatio: state.prescriptionLabelSquareWidthRatio,
|
|
302
|
+
squareHeightRatio: state.prescriptionLabelSquareHeightRatio,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
269
305
|
};
|
|
270
306
|
|
|
271
307
|
export const renderCodeStripsOverlayIfNeeded = () => {
|
package/package.json
CHANGED
package/veryfi-lens.js
CHANGED
|
@@ -2,7 +2,7 @@ import { state, refs, actions } from './core/state.js';
|
|
|
2
2
|
import { DEFAULTS } 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
|
-
import { toggleTorchLight } from './core/camera.js';
|
|
5
|
+
import { toggleTorchLight, mirrorVideo, switchCamera } from './core/camera.js';
|
|
6
6
|
import { checkIfDocumentOnCapture } from './core/validation.js';
|
|
7
7
|
import { validatePartner } from './core/api.js';
|
|
8
8
|
import { initializeWasmWrapper } from './core/wasm-processing.js';
|
|
@@ -15,6 +15,8 @@ import { createSpinner } from './components/spinner.js';
|
|
|
15
15
|
actions.newStartLens = newStartLens;
|
|
16
16
|
actions.removeOverlay = removeOverlay;
|
|
17
17
|
actions.toggleTorchLight = toggleTorchLight;
|
|
18
|
+
actions.mirrorVideo = mirrorVideo;
|
|
19
|
+
actions.switchCamera = switchCamera;
|
|
18
20
|
actions.checkIfDocumentOnCapture = checkIfDocumentOnCapture;
|
|
19
21
|
|
|
20
22
|
const VeryfiLens = {
|