veryfi-lens-wasm 2.0.6-beta.1 → 2.0.7-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/codeStripsOverlay.js +278 -0
- package/package.json +1 -1
- package/veryfi-lens.js +159 -13
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
export const createCodeStripsOverlay = (container, options = {}) => {
|
|
2
|
+
// Get configuration options with defaults
|
|
3
|
+
const rectWidth = options.rectWidth !== undefined ? options.rectWidth : 0.8;
|
|
4
|
+
const rectHeight = options.rectHeight !== undefined ? options.rectHeight : 0.2;
|
|
5
|
+
const instructionText = options.instructionText || "Position code strip in rectangle";
|
|
6
|
+
const cornerRadius = options.cornerRadius !== undefined ? options.cornerRadius : 10; // Default corner radius in pixels
|
|
7
|
+
|
|
8
|
+
// Create overlay container that will match video dimensions
|
|
9
|
+
const overlay = document.createElement("div");
|
|
10
|
+
overlay.id = "veryfi-code-strip-overlay";
|
|
11
|
+
overlay.style.position = "absolute";
|
|
12
|
+
overlay.style.zIndex = "100";
|
|
13
|
+
overlay.style.pointerEvents = "none";
|
|
14
|
+
|
|
15
|
+
// Create a full-screen dark mask
|
|
16
|
+
const darkMask = document.createElement("div");
|
|
17
|
+
darkMask.id = "veryfi-code-strip-mask";
|
|
18
|
+
darkMask.style.position = "absolute";
|
|
19
|
+
darkMask.style.top = "0";
|
|
20
|
+
darkMask.style.left = "0";
|
|
21
|
+
darkMask.style.width = "100%";
|
|
22
|
+
darkMask.style.height = "100%";
|
|
23
|
+
darkMask.style.zIndex = "1001";
|
|
24
|
+
|
|
25
|
+
// Create a rectangular "hole" in the mask
|
|
26
|
+
const rectHole = document.createElement("div");
|
|
27
|
+
rectHole.id = "veryfi-code-strip-hole";
|
|
28
|
+
rectHole.style.position = "absolute";
|
|
29
|
+
rectHole.style.top = "50%";
|
|
30
|
+
rectHole.style.left = "50%";
|
|
31
|
+
rectHole.style.transform = "translate(-50%, -50%)";
|
|
32
|
+
rectHole.style.backgroundColor = "transparent";
|
|
33
|
+
rectHole.style.zIndex = "1002";
|
|
34
|
+
rectHole.style.borderRadius = cornerRadius + "px"; // Add rounded corners
|
|
35
|
+
// We'll use a box-shadow as a mask for the hole
|
|
36
|
+
rectHole.style.boxShadow = "0 0 0 9999px rgba(0, 0, 0, 0.6)";
|
|
37
|
+
|
|
38
|
+
// Create a guide rectangle to mark the target area
|
|
39
|
+
const rectGuide = document.createElement("div");
|
|
40
|
+
rectGuide.id = "veryfi-code-strip-guide";
|
|
41
|
+
rectGuide.style.position = "absolute";
|
|
42
|
+
rectGuide.style.top = "50%";
|
|
43
|
+
rectGuide.style.left = "50%";
|
|
44
|
+
rectGuide.style.transform = "translate(-50%, -50%)";
|
|
45
|
+
rectGuide.style.border = "2px solid #54C08B";
|
|
46
|
+
rectGuide.style.borderRadius = cornerRadius + "px"; // Add rounded corners
|
|
47
|
+
rectGuide.style.zIndex = "1003";
|
|
48
|
+
rectGuide.style.pointerEvents = "none";
|
|
49
|
+
rectGuide.style.boxSizing = "border-box";
|
|
50
|
+
|
|
51
|
+
// Create a text label
|
|
52
|
+
const textLabel = document.createElement("div");
|
|
53
|
+
textLabel.id = "veryfi-code-strip-label";
|
|
54
|
+
textLabel.textContent = instructionText;
|
|
55
|
+
textLabel.style.position = "absolute";
|
|
56
|
+
textLabel.style.bottom = "25%";
|
|
57
|
+
textLabel.style.left = "0";
|
|
58
|
+
textLabel.style.width = "100%";
|
|
59
|
+
textLabel.style.textAlign = "center";
|
|
60
|
+
textLabel.style.color = "white";
|
|
61
|
+
textLabel.style.fontFamily = "Arial, sans-serif";
|
|
62
|
+
textLabel.style.fontSize = "16px";
|
|
63
|
+
textLabel.style.fontWeight = "bold";
|
|
64
|
+
textLabel.style.zIndex = "1004";
|
|
65
|
+
textLabel.style.textShadow = "0 1px 2px rgba(0,0,0,0.8)";
|
|
66
|
+
|
|
67
|
+
// Create a loading indicator that shows while waiting for camera
|
|
68
|
+
const loadingIndicator = document.createElement("div");
|
|
69
|
+
loadingIndicator.id = "veryfi-code-strip-loading";
|
|
70
|
+
loadingIndicator.style.position = "absolute";
|
|
71
|
+
loadingIndicator.style.top = "50%";
|
|
72
|
+
loadingIndicator.style.left = "50%";
|
|
73
|
+
loadingIndicator.style.transform = "translate(-50%, -50%)";
|
|
74
|
+
loadingIndicator.style.width = "40px";
|
|
75
|
+
loadingIndicator.style.height = "40px";
|
|
76
|
+
loadingIndicator.style.borderRadius = "50%";
|
|
77
|
+
loadingIndicator.style.border = "3px solid rgba(255, 255, 255, 0.3)";
|
|
78
|
+
loadingIndicator.style.borderTopColor = "#54C08B";
|
|
79
|
+
loadingIndicator.style.animation = "veryfi-spin 1s linear infinite";
|
|
80
|
+
loadingIndicator.style.zIndex = "1005";
|
|
81
|
+
|
|
82
|
+
// Add keyframes for spinner animation
|
|
83
|
+
const style = document.createElement("style");
|
|
84
|
+
style.textContent = `
|
|
85
|
+
@keyframes veryfi-spin {
|
|
86
|
+
0% { transform: translate(-50%, -50%) rotate(0deg); }
|
|
87
|
+
100% { transform: translate(-50%, -50%) rotate(360deg); }
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
document.head.appendChild(style);
|
|
91
|
+
|
|
92
|
+
// Add elements to the DOM
|
|
93
|
+
overlay.appendChild(darkMask);
|
|
94
|
+
overlay.appendChild(rectHole);
|
|
95
|
+
overlay.appendChild(rectGuide);
|
|
96
|
+
overlay.appendChild(loadingIndicator);
|
|
97
|
+
container.appendChild(overlay);
|
|
98
|
+
|
|
99
|
+
// Function to update the overlay position and size to match the video element
|
|
100
|
+
const updateOverlayPosition = () => {
|
|
101
|
+
const videoElement = document.getElementById("veryfi-video-ref");
|
|
102
|
+
if (!videoElement) return;
|
|
103
|
+
|
|
104
|
+
const videoRect = videoElement.getBoundingClientRect();
|
|
105
|
+
const containerRect = container.getBoundingClientRect();
|
|
106
|
+
|
|
107
|
+
// Position the overlay to exactly match the video element
|
|
108
|
+
overlay.style.top = `${videoRect.top - containerRect.top}px`;
|
|
109
|
+
overlay.style.left = `${videoRect.left - containerRect.left}px`;
|
|
110
|
+
overlay.style.width = `${videoRect.width}px`;
|
|
111
|
+
overlay.style.height = `${videoRect.height}px`;
|
|
112
|
+
|
|
113
|
+
// Size the rectangle based on video dimensions and the configured size
|
|
114
|
+
const rectWidth_px = videoRect.width * rectWidth;
|
|
115
|
+
const rectHeight_px = videoRect.height * rectHeight;
|
|
116
|
+
|
|
117
|
+
// Update rectangle hole and guide size
|
|
118
|
+
rectHole.style.width = `${rectWidth_px}px`;
|
|
119
|
+
rectHole.style.height = `${rectHeight_px}px`;
|
|
120
|
+
|
|
121
|
+
// Update guide rectangle size
|
|
122
|
+
rectGuide.style.width = `${rectWidth_px}px`;
|
|
123
|
+
rectGuide.style.height = `${rectHeight_px}px`;
|
|
124
|
+
|
|
125
|
+
// Adjust corner radius if needed based on rectangle size
|
|
126
|
+
const dynamicRadius = Math.min(rectWidth_px, rectHeight_px) * 0.15; // 15% of smaller dimension
|
|
127
|
+
const finalRadius = Math.min(cornerRadius, dynamicRadius); // Use the smaller of fixed or dynamic radius
|
|
128
|
+
|
|
129
|
+
rectHole.style.borderRadius = `${finalRadius}px`;
|
|
130
|
+
rectGuide.style.borderRadius = `${finalRadius}px`;
|
|
131
|
+
|
|
132
|
+
// Hide loading indicator if video is properly sized and loaded
|
|
133
|
+
if (videoRect.width > 0 && videoElement.readyState >= 2) {
|
|
134
|
+
const loadingIndicator = document.getElementById("veryfi-code-strip-loading");
|
|
135
|
+
if (loadingIndicator) {
|
|
136
|
+
loadingIndicator.style.display = "none";
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// Update positioning immediately
|
|
142
|
+
updateOverlayPosition();
|
|
143
|
+
|
|
144
|
+
// Setup continuous monitoring of size and position
|
|
145
|
+
let resizeObserver;
|
|
146
|
+
let mutationObserver;
|
|
147
|
+
|
|
148
|
+
// Setup resize observer to detect any size changes to the video
|
|
149
|
+
try {
|
|
150
|
+
resizeObserver = new ResizeObserver(() => {
|
|
151
|
+
updateOverlayPosition();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Observe container immediately
|
|
155
|
+
resizeObserver.observe(container);
|
|
156
|
+
|
|
157
|
+
// Observe video element if available
|
|
158
|
+
const videoElement = document.getElementById("veryfi-video-ref");
|
|
159
|
+
if (videoElement) {
|
|
160
|
+
resizeObserver.observe(videoElement);
|
|
161
|
+
}
|
|
162
|
+
} catch (e) {
|
|
163
|
+
console.log("ResizeObserver not supported, falling back to window resize event");
|
|
164
|
+
window.addEventListener("resize", updateOverlayPosition);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Set up mutation observer to watch for video element being added/changed
|
|
168
|
+
mutationObserver = new MutationObserver((mutations) => {
|
|
169
|
+
const videoElement = document.getElementById("veryfi-video-ref");
|
|
170
|
+
if (videoElement) {
|
|
171
|
+
updateOverlayPosition();
|
|
172
|
+
if (resizeObserver) {
|
|
173
|
+
resizeObserver.observe(videoElement);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
mutationObserver.observe(container, { childList: true, subtree: true });
|
|
179
|
+
|
|
180
|
+
// Add event listeners for any potential layout changes
|
|
181
|
+
window.addEventListener("resize", updateOverlayPosition);
|
|
182
|
+
window.addEventListener("orientationchange", updateOverlayPosition);
|
|
183
|
+
document.addEventListener("DOMContentLoaded", updateOverlayPosition);
|
|
184
|
+
|
|
185
|
+
// For devtools opening (which can change layout)
|
|
186
|
+
let lastWidth = window.innerWidth;
|
|
187
|
+
window.addEventListener("resize", () => {
|
|
188
|
+
if (window.innerWidth !== lastWidth) {
|
|
189
|
+
lastWidth = window.innerWidth;
|
|
190
|
+
setTimeout(updateOverlayPosition, 300);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
element: overlay,
|
|
196
|
+
|
|
197
|
+
updatePosition: () => {
|
|
198
|
+
updateOverlayPosition();
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
// Method to crop the code strip image
|
|
202
|
+
cropCodeStrip: (videoElement) => {
|
|
203
|
+
if (!videoElement) return null;
|
|
204
|
+
|
|
205
|
+
// Get the cropImgRef element
|
|
206
|
+
const cropImgRef = document.getElementById("veryfi-crop-img-ref");
|
|
207
|
+
if (!cropImgRef) {
|
|
208
|
+
console.error("Crop image reference not found");
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const videoRect = videoElement.getBoundingClientRect();
|
|
213
|
+
|
|
214
|
+
// Calculate rectangle dimensions based on video size
|
|
215
|
+
const rectWidth_px = videoRect.width * rectWidth;
|
|
216
|
+
const rectHeight_px = videoRect.height * rectHeight;
|
|
217
|
+
|
|
218
|
+
// Calculate scaling factors between screen and video dimensions
|
|
219
|
+
const scaleX = videoElement.videoWidth / videoRect.width;
|
|
220
|
+
const scaleY = videoElement.videoHeight / videoRect.height;
|
|
221
|
+
|
|
222
|
+
// Calculate center point in video coordinates
|
|
223
|
+
const centerX = (videoRect.width / 2) * scaleX;
|
|
224
|
+
const centerY = (videoRect.height / 2) * scaleY;
|
|
225
|
+
|
|
226
|
+
// Instead of using the rectangle dimensions, use a square with side length equal to the rectangle width
|
|
227
|
+
const squareSize = rectWidth_px * scaleX; // Use the width of the rectangle for the square size
|
|
228
|
+
|
|
229
|
+
// Calculate the top-left corner of the square in video coordinates
|
|
230
|
+
const cropX = centerX - (squareSize / 2);
|
|
231
|
+
const cropY = centerY - (squareSize / 2); // Center the square vertically
|
|
232
|
+
|
|
233
|
+
// Set cropImgRef dimensions to match the square size (equal width and height)
|
|
234
|
+
cropImgRef.width = squareSize;
|
|
235
|
+
cropImgRef.height = squareSize;
|
|
236
|
+
|
|
237
|
+
// Draw the cropped portion to the cropImgRef canvas
|
|
238
|
+
const ctx = cropImgRef.getContext('2d');
|
|
239
|
+
ctx.clearRect(0, 0, cropImgRef.width, cropImgRef.height);
|
|
240
|
+
ctx.drawImage(
|
|
241
|
+
videoElement,
|
|
242
|
+
cropX, cropY, squareSize, squareSize,
|
|
243
|
+
0, 0, squareSize, squareSize
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
// Set square display if the method exists
|
|
247
|
+
if (typeof cropImgRef.setSquareDisplay === 'function') {
|
|
248
|
+
cropImgRef.setSquareDisplay();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Convert to base64
|
|
252
|
+
return cropImgRef.toDataURL('image/jpeg').split(',')[1];
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
hide: () => {
|
|
256
|
+
overlay.style.display = 'none';
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
show: () => {
|
|
260
|
+
overlay.style.display = 'block';
|
|
261
|
+
updateOverlayPosition();
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
cleanup: () => {
|
|
265
|
+
window.removeEventListener("resize", updateOverlayPosition);
|
|
266
|
+
window.removeEventListener("orientationchange", updateOverlayPosition);
|
|
267
|
+
document.removeEventListener("DOMContentLoaded", updateOverlayPosition);
|
|
268
|
+
|
|
269
|
+
if (resizeObserver) {
|
|
270
|
+
resizeObserver.disconnect();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (mutationObserver) {
|
|
274
|
+
mutationObserver.disconnect();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
};
|
package/package.json
CHANGED
package/veryfi-lens.js
CHANGED
|
@@ -25,6 +25,7 @@ import { createCheckImages } from './components/checkImages.js';
|
|
|
25
25
|
import { createSpinner } from './components/spinner.js';
|
|
26
26
|
import { createCardDataButton } from './components/cardDataButton.js';
|
|
27
27
|
import { createBottleCapOverlay } from "./components/bottleCapOverlay.js";
|
|
28
|
+
import { createCodeStripsOverlay } from "./components/codeStripsOverlay.js";
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
|
|
@@ -156,6 +157,12 @@ const VeryfiLens = (function () {
|
|
|
156
157
|
|
|
157
158
|
// Add new properties for bottle cap functionality
|
|
158
159
|
bottleCapOverlay: null,
|
|
160
|
+
|
|
161
|
+
// Add new properties for code strips functionality
|
|
162
|
+
codeStripsOverlay: null,
|
|
163
|
+
rectWidth: 0.7,
|
|
164
|
+
rectHeight: 0.08,
|
|
165
|
+
codeStripsText: "Position code strip in rectangle",
|
|
159
166
|
};
|
|
160
167
|
|
|
161
168
|
|
|
@@ -263,6 +270,8 @@ const VeryfiLens = (function () {
|
|
|
263
270
|
break;
|
|
264
271
|
case 'caps':
|
|
265
272
|
break;
|
|
273
|
+
case 'code_strips':
|
|
274
|
+
break;
|
|
266
275
|
default:
|
|
267
276
|
wasmWrapper.setDocumentCallback(logDocument);
|
|
268
277
|
}
|
|
@@ -1278,6 +1287,12 @@ const VeryfiLens = (function () {
|
|
|
1278
1287
|
}
|
|
1279
1288
|
}
|
|
1280
1289
|
|
|
1290
|
+
// Add reset for code strips properties
|
|
1291
|
+
state.rectWidth = 0.7; // Reset to default rectangle width
|
|
1292
|
+
state.rectHeight = 0.08; // Reset to default rectangle height
|
|
1293
|
+
state.codeStripsText = "Position code strip in rectangle"; // Reset to default text
|
|
1294
|
+
state.codeStripsOverlay = null;
|
|
1295
|
+
|
|
1281
1296
|
state.debug_mode && console.log("State reset complete");
|
|
1282
1297
|
};
|
|
1283
1298
|
|
|
@@ -1659,7 +1674,7 @@ const VeryfiLens = (function () {
|
|
|
1659
1674
|
}
|
|
1660
1675
|
|
|
1661
1676
|
// Only initialize WASM for flavors that need it
|
|
1662
|
-
if (state.lensFlavor !== "caps") {
|
|
1677
|
+
if (state.lensFlavor !== "caps" && state.lensFlavor !== "code_strips") {
|
|
1663
1678
|
await initializeWasmWrapper();
|
|
1664
1679
|
}
|
|
1665
1680
|
|
|
@@ -1693,7 +1708,7 @@ const VeryfiLens = (function () {
|
|
|
1693
1708
|
}
|
|
1694
1709
|
break;
|
|
1695
1710
|
case "caps":
|
|
1696
|
-
|
|
1711
|
+
case "code_strips":
|
|
1697
1712
|
break;
|
|
1698
1713
|
default:
|
|
1699
1714
|
throw new Error(`Unknown lens flavor: ${state.lensFlavor}`);
|
|
@@ -1704,11 +1719,11 @@ const VeryfiLens = (function () {
|
|
|
1704
1719
|
await getVideo(state.lensFlavor);
|
|
1705
1720
|
}
|
|
1706
1721
|
|
|
1707
|
-
// Start processing frames for all except caps and upload
|
|
1722
|
+
// Start processing frames for all except caps, code_strips and upload
|
|
1708
1723
|
requestAnimationFrame(displayVideo);
|
|
1709
1724
|
|
|
1710
1725
|
// Only set up interval for flavors that need continuous processing
|
|
1711
|
-
if (state.lensFlavor !== "caps" && state.lensFlavor !== "upload") {
|
|
1726
|
+
if (state.lensFlavor !== "caps" && state.lensFlavor !== "code_strips" && state.lensFlavor !== "upload") {
|
|
1712
1727
|
state.intervalRef = setInterval(() => {
|
|
1713
1728
|
state.lensFlavor === "credit_card" ? sendCardWasm() : sendWasm(state.lensFlavor);
|
|
1714
1729
|
}, state.INTERVAL);
|
|
@@ -2001,11 +2016,11 @@ const VeryfiLens = (function () {
|
|
|
2001
2016
|
// Process the document with the API if needed
|
|
2002
2017
|
try {
|
|
2003
2018
|
state.updateHandler && state.updateHandler({ status: 'processing_started' });
|
|
2004
|
-
|
|
2019
|
+
state.docReadyResult = await docReady();
|
|
2005
2020
|
state.updateHandler && state.updateHandler({ status: 'processing_completed' });
|
|
2006
2021
|
|
|
2007
2022
|
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
2008
|
-
state.resultSetter({ image: state.finalImage });
|
|
2023
|
+
state.resultSetter({ ...state.docReadyResult, image: state.finalImage });
|
|
2009
2024
|
}
|
|
2010
2025
|
} catch (error) {
|
|
2011
2026
|
console.error("Error processing document:", error);
|
|
@@ -2085,6 +2100,133 @@ const VeryfiLens = (function () {
|
|
|
2085
2100
|
}
|
|
2086
2101
|
};
|
|
2087
2102
|
|
|
2103
|
+
// Add function to capture code strips
|
|
2104
|
+
const captureCodeStrip = async () => {
|
|
2105
|
+
try {
|
|
2106
|
+
state.debug_mode && console.log("[EVENT] capture code strip");
|
|
2107
|
+
state.updateHandler && state.updateHandler({ status: 'capture_started' });
|
|
2108
|
+
|
|
2109
|
+
if (!state.codeStripsOverlay || !state.videoRef) {
|
|
2110
|
+
throw new Error("Code strips overlay or video reference not initialized");
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
// Crop the code strip from the video stream
|
|
2114
|
+
state.finalImage = state.codeStripsOverlay.cropCodeStrip(state.videoRef);
|
|
2115
|
+
|
|
2116
|
+
if (!state.finalImage) {
|
|
2117
|
+
throw new Error("Failed to capture code strip image");
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
// Set document state to true for processing
|
|
2121
|
+
state.isDocument = true;
|
|
2122
|
+
|
|
2123
|
+
// Hide video components
|
|
2124
|
+
hideVideoOverlay();
|
|
2125
|
+
|
|
2126
|
+
// Set rectangle display for the cropped image
|
|
2127
|
+
if (state.cropImgRef && typeof state.cropImgRef.setRectangleDisplay === 'function') {
|
|
2128
|
+
state.cropImgRef.setRectangleDisplay();
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
// Show success border on the cropped image
|
|
2132
|
+
if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
|
|
2133
|
+
state.cropImgRef.showSuccessBorder();
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
// Send the image to the result setter if available
|
|
2137
|
+
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
2138
|
+
state.resultSetter(state.finalImage);
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
// Process the document with the API if needed
|
|
2142
|
+
try {
|
|
2143
|
+
state.updateHandler && state.updateHandler({ status: 'processing_started' });
|
|
2144
|
+
state.docReadyResult = await docReady();
|
|
2145
|
+
state.updateHandler && state.updateHandler({ status: 'processing_completed' });
|
|
2146
|
+
|
|
2147
|
+
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
2148
|
+
state.resultSetter({ ...state.docReadyResult, image: state.finalImage });
|
|
2149
|
+
}
|
|
2150
|
+
} catch (error) {
|
|
2151
|
+
console.error("Error processing document:", error);
|
|
2152
|
+
// Continue even if docReady fails
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
// Create submit button for sending image to backend
|
|
2156
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
2157
|
+
// Use custom handler if provided, otherwise use default
|
|
2158
|
+
if (state.customSubmitHandler && typeof state.customSubmitHandler === 'function') {
|
|
2159
|
+
state.customSubmitHandler(state.finalImage);
|
|
2160
|
+
} else {
|
|
2161
|
+
handleSubmit(state.finalImage);
|
|
2162
|
+
}
|
|
2163
|
+
}, removeOverlay);
|
|
2164
|
+
|
|
2165
|
+
state.enableSubmit && state.submitButton.show();
|
|
2166
|
+
state.updateHandler && state.updateHandler({ status: 'capture_completed' });
|
|
2167
|
+
|
|
2168
|
+
return state.finalImage;
|
|
2169
|
+
} catch (error) {
|
|
2170
|
+
console.error("Code strip capture failed:", error.message);
|
|
2171
|
+
if (state.failureHandler && typeof state.failureHandler === 'function') {
|
|
2172
|
+
state.failureHandler(error);
|
|
2173
|
+
}
|
|
2174
|
+
state.updateHandler && state.updateHandler({ status: 'capture_failed' });
|
|
2175
|
+
return null;
|
|
2176
|
+
}
|
|
2177
|
+
};
|
|
2178
|
+
|
|
2179
|
+
// Add function to render code strips overlay
|
|
2180
|
+
const renderCodeStripsOverlayIfNeeded = () => {
|
|
2181
|
+
state.debug_mode && console.log("Rendering code strips overlay");
|
|
2182
|
+
!state.videoOverlay && (state.videoOverlay = createVideoOverlay(state.container));
|
|
2183
|
+
|
|
2184
|
+
// Add exit button first
|
|
2185
|
+
if (state.exitButton) {
|
|
2186
|
+
state.exitButton = createExitButton(state.videoOverlay.overlay, {
|
|
2187
|
+
setter: state.onClose,
|
|
2188
|
+
redirectUrl: state.onCloseRedirectUrl,
|
|
2189
|
+
lensFlavor: state.lensFlavor,
|
|
2190
|
+
}, removeOverlay);
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
// Add capture button
|
|
2194
|
+
state.captureButton = createCaptureButton(state.videoOverlay.overlay, captureCodeStrip);
|
|
2195
|
+
|
|
2196
|
+
// Add torch button if enabled
|
|
2197
|
+
if (state.torchButton) {
|
|
2198
|
+
state.torchButton = createTorchButton(state.videoOverlay.overlay, () => {
|
|
2199
|
+
toggleTorchLight();
|
|
2200
|
+
}, state.lensFlavor);
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
// Only create code strips overlay after video is loaded
|
|
2204
|
+
const videoElement = document.getElementById("veryfi-video-ref");
|
|
2205
|
+
|
|
2206
|
+
if (videoElement) {
|
|
2207
|
+
// If video is already loaded, create overlay immediately
|
|
2208
|
+
if (videoElement.readyState >= 2) {
|
|
2209
|
+
!state.codeStripsOverlay && (state.codeStripsOverlay = createCodeStripsOverlay(state.container, {
|
|
2210
|
+
rectWidth: state.rectWidth,
|
|
2211
|
+
rectHeight: state.rectHeight,
|
|
2212
|
+
instructionText: state.codeStripsText
|
|
2213
|
+
}));
|
|
2214
|
+
} else {
|
|
2215
|
+
// Otherwise wait for video to load enough data
|
|
2216
|
+
const handleVideoLoad = () => {
|
|
2217
|
+
!state.codeStripsOverlay && (state.codeStripsOverlay = createCodeStripsOverlay(state.container, {
|
|
2218
|
+
rectWidth: state.rectWidth,
|
|
2219
|
+
rectHeight: state.rectHeight,
|
|
2220
|
+
instructionText: state.codeStripsText
|
|
2221
|
+
}));
|
|
2222
|
+
videoElement.removeEventListener('loadeddata', handleVideoLoad);
|
|
2223
|
+
};
|
|
2224
|
+
|
|
2225
|
+
videoElement.addEventListener('loadeddata', handleVideoLoad);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
};
|
|
2229
|
+
|
|
2088
2230
|
return {
|
|
2089
2231
|
|
|
2090
2232
|
init: async (clientId, config) => {
|
|
@@ -2097,7 +2239,7 @@ const VeryfiLens = (function () {
|
|
|
2097
2239
|
state.clientData = await validatePartner(state.clientId);
|
|
2098
2240
|
config.debug_mode && console.log(state.clientData);
|
|
2099
2241
|
|
|
2100
|
-
config.lensFlavor === "caps" ? null : await initializeWasmWrapper();
|
|
2242
|
+
config.lensFlavor === "caps" || config.lensFlavor === "code_strips" ? null : await initializeWasmWrapper();
|
|
2101
2243
|
|
|
2102
2244
|
switch (config.lensFlavor) {
|
|
2103
2245
|
case "checks":
|
|
@@ -2157,11 +2299,11 @@ const VeryfiLens = (function () {
|
|
|
2157
2299
|
}
|
|
2158
2300
|
|
|
2159
2301
|
// Initialize WASM if needed
|
|
2160
|
-
state.lensFlavor === "caps" ? null : await initializeWasmWrapper();
|
|
2302
|
+
state.lensFlavor === "caps" || state.lensFlavor === "code_strips" ? null : await initializeWasmWrapper();
|
|
2161
2303
|
|
|
2162
|
-
// Start lens if not already started - do this first for bottle cap to ensure video is loaded
|
|
2163
|
-
if (state.lensFlavor === 'caps' && !state.started) {
|
|
2164
|
-
state.debug_mode && console.log(
|
|
2304
|
+
// Start lens if not already started - do this first for bottle cap and code strips to ensure video is loaded
|
|
2305
|
+
if ((state.lensFlavor === 'caps' || state.lensFlavor === 'code_strips') && !state.started) {
|
|
2306
|
+
state.debug_mode && console.log(`Starting lens for ${state.lensFlavor}`);
|
|
2165
2307
|
await newStartLens();
|
|
2166
2308
|
}
|
|
2167
2309
|
|
|
@@ -2208,6 +2350,10 @@ const VeryfiLens = (function () {
|
|
|
2208
2350
|
// Create UI elements after video has initialized
|
|
2209
2351
|
renderBottleCapOverlayIfNeeded();
|
|
2210
2352
|
break;
|
|
2353
|
+
case 'code_strips':
|
|
2354
|
+
// Create UI elements for code strips
|
|
2355
|
+
renderCodeStripsOverlayIfNeeded();
|
|
2356
|
+
break;
|
|
2211
2357
|
default:
|
|
2212
2358
|
state.debug_mode && console.log('Rendering UI elements');
|
|
2213
2359
|
renderModalsIfNeeded();
|
|
@@ -2215,8 +2361,8 @@ const VeryfiLens = (function () {
|
|
|
2215
2361
|
break;
|
|
2216
2362
|
}
|
|
2217
2363
|
|
|
2218
|
-
// Start lens for non-caps flavors
|
|
2219
|
-
if (!state.started && state.lensFlavor !== 'caps') {
|
|
2364
|
+
// Start lens for non-caps and non-code_strips flavors
|
|
2365
|
+
if (!state.started && state.lensFlavor !== 'caps' && state.lensFlavor !== 'code_strips') {
|
|
2220
2366
|
state.debug_mode && console.log("Starting lens");
|
|
2221
2367
|
await newStartLens();
|
|
2222
2368
|
}
|