veryfi-lens-wasm 3.0.2 → 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 +16 -0
- package/components/captureButton.js +8 -5
- package/components/checkOverlay.js +95 -23
- package/components/exitButton.js +7 -5
- package/components/mirrorButton.js +68 -0
- package/components/prescriptionLabelOverlay.js +162 -0
- package/components/prescriptionSquareOverlay.js +126 -0
- package/components/switchCameraButton.js +68 -0
- package/components/torchButton.js +7 -5
- package/core/api.js +2 -2
- package/core/camera.js +71 -0
- package/core/capture/prescription_label.js +417 -0
- package/core/constants.js +7 -2
- package/core/lifecycle.js +6 -2
- package/core/overlay-controls.js +16 -0
- package/core/state.js +24 -0
- package/core/ui-renderer.js +49 -1
- package/flavors/prescription_label.js +16 -0
- package/package.json +1 -1
- package/veryfi-lens.js +10 -5
package/README.md
CHANGED
|
@@ -17,6 +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 video capture with pill bottle overlay, zips video and submits to anydocs |
|
|
20
21
|
| `upload` | File upload with crop and submit (no camera) |
|
|
21
22
|
|
|
22
23
|
## Installation
|
|
@@ -119,6 +120,9 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
|
|
|
119
120
|
|---|---|---|---|
|
|
120
121
|
| `torchButton` | `boolean` | `true` | Show torch/flashlight toggle |
|
|
121
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) |
|
|
122
126
|
| `exitButton` | `boolean` | `false` | Show exit/close button |
|
|
123
127
|
| `onClose` | `function` | — | Callback when lens is closed |
|
|
124
128
|
| `onCloseRedirectUrl` | `string` | — | URL to redirect to on close |
|
|
@@ -218,6 +222,18 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
|
|
|
218
222
|
| `rectHeight` | `number` | `0.08` | Capture rectangle height (0-1) |
|
|
219
223
|
| `codeStripsText` | `string` | `"Position code strip in rectangle"` | Instruction text |
|
|
220
224
|
|
|
225
|
+
### Prescription Label Settings (`prescription_label` flavor)
|
|
226
|
+
|
|
227
|
+
| Option | Type | Default | Description |
|
|
228
|
+
|---|---|---|---|
|
|
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) |
|
|
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) |
|
|
236
|
+
|
|
221
237
|
### Upload Settings (`upload` flavor)
|
|
222
238
|
|
|
223
239
|
| Option | Type | Default | Description |
|
|
@@ -10,14 +10,17 @@ export const createCaptureButton = (container, onCapture, onStopStitching) => {
|
|
|
10
10
|
width: '4rem',
|
|
11
11
|
height: '4rem',
|
|
12
12
|
borderRadius: '50%',
|
|
13
|
-
border: '
|
|
14
|
-
backgroundColor: '
|
|
13
|
+
border: '3px solid rgba(255, 255, 255, 0.4)',
|
|
14
|
+
backgroundColor: 'rgba(255, 255, 255, 0.15)',
|
|
15
15
|
cursor: 'pointer',
|
|
16
16
|
zIndex: '1000',
|
|
17
17
|
transition: 'background-color 0.3s ease',
|
|
18
18
|
padding: '0',
|
|
19
19
|
outline: 'none',
|
|
20
|
-
pointerEvents: 'auto'
|
|
20
|
+
pointerEvents: 'auto',
|
|
21
|
+
backdropFilter: 'blur(2px)',
|
|
22
|
+
WebkitBackdropFilter: 'blur(2px)',
|
|
23
|
+
boxSizing: 'border-box',
|
|
21
24
|
};
|
|
22
25
|
|
|
23
26
|
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
@@ -44,11 +47,11 @@ export const createCaptureButton = (container, onCapture, onStopStitching) => {
|
|
|
44
47
|
|
|
45
48
|
// Add hover effect
|
|
46
49
|
button.addEventListener('mouseenter', () => {
|
|
47
|
-
button.style.backgroundColor = 'var(--capture-button-hover-background-color, rgba(255, 255, 255, 0.
|
|
50
|
+
button.style.backgroundColor = 'var(--capture-button-hover-background-color, rgba(255, 255, 255, 0.25))';
|
|
48
51
|
});
|
|
49
52
|
|
|
50
53
|
button.addEventListener('mouseleave', () => {
|
|
51
|
-
button.style.backgroundColor = 'var(--capture-button-background-color,
|
|
54
|
+
button.style.backgroundColor = 'var(--capture-button-background-color, rgba(255, 255, 255, 0.15))';
|
|
52
55
|
});
|
|
53
56
|
|
|
54
57
|
let isStitching = false;
|
|
@@ -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,8 +8,8 @@ export const createExitButton = (container, options, removeOverlay) => {
|
|
|
8
8
|
const defaultStyles = {
|
|
9
9
|
position: 'absolute',
|
|
10
10
|
bottom: '50px',
|
|
11
|
-
left: '
|
|
12
|
-
backgroundColor: 'rgba(
|
|
11
|
+
left: '115px',
|
|
12
|
+
backgroundColor: 'rgba(255, 255, 255, 0.15)',
|
|
13
13
|
color: 'white',
|
|
14
14
|
fontWeight: 'bold',
|
|
15
15
|
borderRadius: '50%',
|
|
@@ -24,7 +24,7 @@ export const createExitButton = (container, options, removeOverlay) => {
|
|
|
24
24
|
alignItems: 'center',
|
|
25
25
|
justifyContent: 'center',
|
|
26
26
|
pointerEvents: 'auto',
|
|
27
|
-
border: '
|
|
27
|
+
border: '1px solid rgba(255, 255, 255, 0.4)',
|
|
28
28
|
outline: 'none',
|
|
29
29
|
boxSizing: 'border-box',
|
|
30
30
|
margin: '0',
|
|
@@ -33,6 +33,8 @@ export const createExitButton = (container, options, removeOverlay) => {
|
|
|
33
33
|
minHeight: '40px',
|
|
34
34
|
maxWidth: '40px',
|
|
35
35
|
maxHeight: '40px',
|
|
36
|
+
backdropFilter: 'blur(8px)',
|
|
37
|
+
WebkitBackdropFilter: 'blur(8px)',
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
@@ -68,11 +70,11 @@ export const createExitButton = (container, options, removeOverlay) => {
|
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
button.addEventListener('mouseenter', () => {
|
|
71
|
-
button.style.backgroundColor = 'rgba(
|
|
73
|
+
button.style.backgroundColor = 'rgba(255, 255, 255, 0.25)';
|
|
72
74
|
});
|
|
73
75
|
|
|
74
76
|
button.addEventListener('mouseleave', () => {
|
|
75
|
-
button.style.backgroundColor = 'rgba(
|
|
77
|
+
button.style.backgroundColor = 'rgba(255, 255, 255, 0.15)';
|
|
76
78
|
});
|
|
77
79
|
|
|
78
80
|
button.addEventListener('click', (e) => {
|
|
@@ -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,162 @@
|
|
|
1
|
+
import { createOverlayBase, createLoadingSpinner } from './overlayBase.js';
|
|
2
|
+
|
|
3
|
+
const buildBottlePath = (vw, vh, widthRatio, heightRatio) => {
|
|
4
|
+
const bodyW = vw * widthRatio;
|
|
5
|
+
const totalH = vh * heightRatio;
|
|
6
|
+
|
|
7
|
+
const capW = bodyW * 1.25;
|
|
8
|
+
const stepH = totalH * 0.04;
|
|
9
|
+
const capH = totalH * 0.14;
|
|
10
|
+
const bodyH = totalH - stepH - capH;
|
|
11
|
+
|
|
12
|
+
const r = bodyW * 0.035;
|
|
13
|
+
const stepR = stepH * 0.5;
|
|
14
|
+
const capR = capH * 0.25;
|
|
15
|
+
|
|
16
|
+
const cx = vw / 2;
|
|
17
|
+
const cy = vh * 0.46;
|
|
18
|
+
const topY = cy - totalH / 2;
|
|
19
|
+
|
|
20
|
+
const stepX1 = cx - bodyW / 2;
|
|
21
|
+
const stepX2 = cx + bodyW / 2;
|
|
22
|
+
const stepY1 = topY;
|
|
23
|
+
const stepY2 = topY + stepH;
|
|
24
|
+
|
|
25
|
+
const capX1 = cx - capW / 2;
|
|
26
|
+
const capX2 = cx + capW / 2;
|
|
27
|
+
const capY2 = stepY2 + capH;
|
|
28
|
+
|
|
29
|
+
const bodyX1 = cx - bodyW / 2;
|
|
30
|
+
const bodyX2 = cx + bodyW / 2;
|
|
31
|
+
const bodyY2 = capY2 + bodyH;
|
|
32
|
+
|
|
33
|
+
const bottlePath = [
|
|
34
|
+
`M ${stepX1 + stepR} ${stepY1}`,
|
|
35
|
+
`H ${stepX2 - stepR}`,
|
|
36
|
+
`A ${stepR} ${stepR} 0 0 1 ${stepX2} ${stepY1 + stepR}`,
|
|
37
|
+
`V ${stepY2}`,
|
|
38
|
+
|
|
39
|
+
`H ${capX2 - capR}`,
|
|
40
|
+
`A ${capR} ${capR} 0 0 1 ${capX2} ${stepY2 + capR}`,
|
|
41
|
+
`V ${capY2 - capR}`,
|
|
42
|
+
`A ${capR} ${capR} 0 0 1 ${capX2 - capR} ${capY2}`,
|
|
43
|
+
|
|
44
|
+
`H ${bodyX2}`,
|
|
45
|
+
`V ${bodyY2 - r}`,
|
|
46
|
+
`A ${r} ${r} 0 0 1 ${bodyX2 - r} ${bodyY2}`,
|
|
47
|
+
|
|
48
|
+
`H ${bodyX1 + r}`,
|
|
49
|
+
`A ${r} ${r} 0 0 1 ${bodyX1} ${bodyY2 - r}`,
|
|
50
|
+
`V ${capY2}`,
|
|
51
|
+
|
|
52
|
+
`H ${capX1 + capR}`,
|
|
53
|
+
`A ${capR} ${capR} 0 0 1 ${capX1} ${capY2 - capR}`,
|
|
54
|
+
`V ${stepY2 + capR}`,
|
|
55
|
+
`A ${capR} ${capR} 0 0 1 ${capX1 + capR} ${stepY2}`,
|
|
56
|
+
|
|
57
|
+
`H ${stepX1}`,
|
|
58
|
+
`V ${stepY1 + stepR}`,
|
|
59
|
+
`A ${stepR} ${stepR} 0 0 1 ${stepX1 + stepR} ${stepY1}`,
|
|
60
|
+
`Z`
|
|
61
|
+
].join(' ');
|
|
62
|
+
|
|
63
|
+
return bottlePath;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const NS = 'http://www.w3.org/2000/svg';
|
|
67
|
+
|
|
68
|
+
let traceStyleEl = null;
|
|
69
|
+
|
|
70
|
+
const setTraceAnimation = (totalLen) => {
|
|
71
|
+
if (traceStyleEl) traceStyleEl.remove();
|
|
72
|
+
traceStyleEl = document.createElement('style');
|
|
73
|
+
traceStyleEl.id = 'veryfi-label-trace-keyframes';
|
|
74
|
+
traceStyleEl.textContent = `
|
|
75
|
+
@keyframes veryfi-label-trace {
|
|
76
|
+
0% { stroke-dashoffset: 0; }
|
|
77
|
+
100% { stroke-dashoffset: ${-totalLen}; }
|
|
78
|
+
}
|
|
79
|
+
`;
|
|
80
|
+
document.head.appendChild(traceStyleEl);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const createPrescriptionLabelOverlay = (container, options = {}) => {
|
|
84
|
+
const bottleWidthRatio = options.bottleWidthRatio !== undefined ? options.bottleWidthRatio : 0.55;
|
|
85
|
+
const bottleHeightRatio = options.bottleHeightRatio !== undefined ? options.bottleHeightRatio : 0.65;
|
|
86
|
+
|
|
87
|
+
const svg = document.createElementNS(NS, 'svg');
|
|
88
|
+
svg.style.position = 'absolute';
|
|
89
|
+
svg.style.top = '0';
|
|
90
|
+
svg.style.left = '0';
|
|
91
|
+
svg.style.width = '100%';
|
|
92
|
+
svg.style.height = '100%';
|
|
93
|
+
svg.style.zIndex = '1002';
|
|
94
|
+
svg.style.pointerEvents = 'none';
|
|
95
|
+
|
|
96
|
+
const maskPath = document.createElementNS(NS, 'path');
|
|
97
|
+
maskPath.setAttribute('fill', 'rgba(0, 0, 0, 0.6)');
|
|
98
|
+
maskPath.setAttribute('fill-rule', 'evenodd');
|
|
99
|
+
svg.appendChild(maskPath);
|
|
100
|
+
|
|
101
|
+
const guidePath = document.createElementNS(NS, 'path');
|
|
102
|
+
guidePath.setAttribute('fill', 'none');
|
|
103
|
+
guidePath.setAttribute('stroke', '#00AA00');
|
|
104
|
+
guidePath.setAttribute('stroke-width', '3');
|
|
105
|
+
guidePath.setAttribute('stroke-linecap', 'round');
|
|
106
|
+
svg.appendChild(guidePath);
|
|
107
|
+
|
|
108
|
+
const loadingIndicator = createLoadingSpinner('veryfi-prescription-label-loading');
|
|
109
|
+
|
|
110
|
+
let dashInitialized = false;
|
|
111
|
+
|
|
112
|
+
const base = createOverlayBase(container, {
|
|
113
|
+
id: 'veryfi-prescription-label-overlay',
|
|
114
|
+
hasSpinner: true,
|
|
115
|
+
buildContent: (overlay) => {
|
|
116
|
+
overlay.appendChild(svg);
|
|
117
|
+
overlay.appendChild(loadingIndicator);
|
|
118
|
+
|
|
119
|
+
return (videoRect, videoElement) => {
|
|
120
|
+
const vw = videoRect.width;
|
|
121
|
+
const vh = videoRect.height;
|
|
122
|
+
|
|
123
|
+
if (vw <= 0 || vh <= 0) return;
|
|
124
|
+
|
|
125
|
+
svg.setAttribute('viewBox', `0 0 ${vw} ${vh}`);
|
|
126
|
+
|
|
127
|
+
const outerRect = `M 0 0 H ${vw} V ${vh} H 0 Z`;
|
|
128
|
+
const bottle = buildBottlePath(vw, vh, bottleWidthRatio, bottleHeightRatio);
|
|
129
|
+
|
|
130
|
+
maskPath.setAttribute('d', `${outerRect} ${bottle}`);
|
|
131
|
+
guidePath.setAttribute('d', bottle);
|
|
132
|
+
|
|
133
|
+
if (!dashInitialized) {
|
|
134
|
+
const totalLen = guidePath.getTotalLength();
|
|
135
|
+
const dashLen = totalLen * 0.15;
|
|
136
|
+
const gapLen = totalLen - dashLen;
|
|
137
|
+
|
|
138
|
+
guidePath.setAttribute('stroke-dasharray', `${dashLen} ${gapLen}`);
|
|
139
|
+
setTraceAnimation(totalLen);
|
|
140
|
+
guidePath.style.animation = 'veryfi-label-trace 3s linear infinite';
|
|
141
|
+
dashInitialized = true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (videoElement.readyState >= 2) {
|
|
145
|
+
loadingIndicator.style.display = 'none';
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
cropFn: null,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
...base,
|
|
154
|
+
cleanup: () => {
|
|
155
|
+
base.cleanup();
|
|
156
|
+
if (traceStyleEl) {
|
|
157
|
+
traceStyleEl.remove();
|
|
158
|
+
traceStyleEl = null;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
};
|
|
@@ -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
|
+
};
|