veryfi-lens-wasm 2.0.5 → 2.0.6-beta.1

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.
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Creates a circular overlay for capturing bottle caps
3
+ * @param {HTMLElement} container - The container element
4
+ * @param {Object} options - Configuration options
5
+ * @param {number} [options.circleRadius=0.7] - The circle radius as a proportion of the smaller video dimension (0-1)
6
+ * @param {string} [options.instructionText="Position bottle cap in circle"] - The instruction text to display
7
+ * @returns {Object} The bottle cap overlay object with element and methods
8
+ */
9
+ export const createBottleCapOverlay = (container, options = {}) => {
10
+ // Get configuration options with defaults
11
+ const circleRadius = options.circleRadius !== undefined ? options.circleRadius : 0.7;
12
+ const instructionText = options.instructionText || "Position bottle cap in circle";
13
+
14
+ // Create overlay container that will match video dimensions
15
+ const overlay = document.createElement("div");
16
+ overlay.id = "veryfi-bottle-cap-overlay";
17
+ overlay.style.position = "absolute";
18
+ overlay.style.zIndex = "100";
19
+ overlay.style.pointerEvents = "none";
20
+
21
+ // Create a full-screen dark mask
22
+ const darkMask = document.createElement("div");
23
+ darkMask.id = "veryfi-bottle-cap-mask";
24
+ darkMask.style.position = "absolute";
25
+ darkMask.style.top = "0";
26
+ darkMask.style.left = "0";
27
+ darkMask.style.width = "100%";
28
+ darkMask.style.height = "100%";
29
+ darkMask.style.zIndex = "1001";
30
+
31
+ // Create a circular "hole" in the mask
32
+ const circleHole = document.createElement("div");
33
+ circleHole.id = "veryfi-bottle-cap-hole";
34
+ circleHole.style.position = "absolute";
35
+ circleHole.style.top = "50%";
36
+ circleHole.style.left = "50%";
37
+ circleHole.style.transform = "translate(-50%, -50%)";
38
+ circleHole.style.borderRadius = "50%";
39
+ circleHole.style.backgroundColor = "transparent";
40
+ circleHole.style.zIndex = "1002";
41
+ // We'll use a radial-gradient as a mask for the hole
42
+ circleHole.style.boxShadow = "0 0 0 9999px rgba(0, 0, 0, 0.6)";
43
+
44
+ // Create a guide circle to mark the target area
45
+ const circleGuide = document.createElement("div");
46
+ circleGuide.id = "veryfi-bottle-cap-guide";
47
+ circleGuide.style.position = "absolute";
48
+ circleGuide.style.top = "50%";
49
+ circleGuide.style.left = "50%";
50
+ circleGuide.style.transform = "translate(-50%, -50%)";
51
+ circleGuide.style.borderRadius = "50%";
52
+ circleGuide.style.border = "2px solid #54C08B";
53
+ circleGuide.style.zIndex = "1003";
54
+ circleGuide.style.pointerEvents = "none";
55
+ circleGuide.style.boxSizing = "border-box";
56
+
57
+ // Create a text label
58
+ const textLabel = document.createElement("div");
59
+ textLabel.id = "veryfi-bottle-cap-label";
60
+ textLabel.textContent = instructionText;
61
+ textLabel.style.position = "absolute";
62
+ textLabel.style.bottom = "25%";
63
+ textLabel.style.left = "0";
64
+ textLabel.style.width = "100%";
65
+ textLabel.style.textAlign = "center";
66
+ textLabel.style.color = "white";
67
+ textLabel.style.fontFamily = "Arial, sans-serif";
68
+ textLabel.style.fontSize = "16px";
69
+ textLabel.style.fontWeight = "bold";
70
+ textLabel.style.zIndex = "1004";
71
+ textLabel.style.textShadow = "0 1px 2px rgba(0,0,0,0.8)";
72
+
73
+ // Create a loading indicator that shows while waiting for camera
74
+ const loadingIndicator = document.createElement("div");
75
+ loadingIndicator.id = "veryfi-bottle-cap-loading";
76
+ loadingIndicator.style.position = "absolute";
77
+ loadingIndicator.style.top = "50%";
78
+ loadingIndicator.style.left = "50%";
79
+ loadingIndicator.style.transform = "translate(-50%, -50%)";
80
+ loadingIndicator.style.width = "40px";
81
+ loadingIndicator.style.height = "40px";
82
+ loadingIndicator.style.borderRadius = "50%";
83
+ loadingIndicator.style.border = "3px solid rgba(255, 255, 255, 0.3)";
84
+ loadingIndicator.style.borderTopColor = "#54C08B";
85
+ loadingIndicator.style.animation = "veryfi-spin 1s linear infinite";
86
+ loadingIndicator.style.zIndex = "1005";
87
+
88
+ // Add keyframes for spinner animation
89
+ const style = document.createElement("style");
90
+ style.textContent = `
91
+ @keyframes veryfi-spin {
92
+ 0% { transform: translate(-50%, -50%) rotate(0deg); }
93
+ 100% { transform: translate(-50%, -50%) rotate(360deg); }
94
+ }
95
+ `;
96
+ document.head.appendChild(style);
97
+
98
+ // Add elements to the DOM
99
+ overlay.appendChild(darkMask);
100
+ overlay.appendChild(circleHole);
101
+ overlay.appendChild(circleGuide);
102
+ // overlay.appendChild(textLabel);
103
+ overlay.appendChild(loadingIndicator);
104
+ container.appendChild(overlay);
105
+
106
+ // Function to update the overlay position and size to match the video element
107
+ const updateOverlayPosition = () => {
108
+ const videoElement = document.getElementById("veryfi-video-ref");
109
+ if (!videoElement) return;
110
+
111
+ const videoRect = videoElement.getBoundingClientRect();
112
+ const containerRect = container.getBoundingClientRect();
113
+
114
+ // Position the overlay to exactly match the video element
115
+ overlay.style.top = `${videoRect.top - containerRect.top}px`;
116
+ overlay.style.left = `${videoRect.left - containerRect.left}px`;
117
+ overlay.style.width = `${videoRect.width}px`;
118
+ overlay.style.height = `${videoRect.height}px`;
119
+
120
+ // Size the circle based on the smaller dimension of the video and the configured radius
121
+ const circleDiameter = Math.min(videoRect.width, videoRect.height) * circleRadius;
122
+
123
+ // Update circle hole and guide size
124
+ circleHole.style.width = `${circleDiameter}px`;
125
+ circleHole.style.height = `${circleDiameter}px`;
126
+
127
+ // Update guide circle size
128
+ circleGuide.style.width = `${circleDiameter}px`;
129
+ circleGuide.style.height = `${circleDiameter}px`;
130
+
131
+ // Hide loading indicator if video is properly sized and loaded
132
+ if (videoRect.width > 0 && videoElement.readyState >= 2) {
133
+ const loadingIndicator = document.getElementById("veryfi-bottle-cap-loading");
134
+ if (loadingIndicator) {
135
+ loadingIndicator.style.display = "none";
136
+ }
137
+ }
138
+ };
139
+
140
+ // Update positioning immediately
141
+ updateOverlayPosition();
142
+
143
+ // Setup continuous monitoring of size and position
144
+ let resizeObserver;
145
+ let mutationObserver;
146
+
147
+ // Setup resize observer to detect any size changes to the video
148
+ try {
149
+ resizeObserver = new ResizeObserver(() => {
150
+ updateOverlayPosition();
151
+ });
152
+
153
+ // Observe container immediately
154
+ resizeObserver.observe(container);
155
+
156
+ // Observe video element if available
157
+ const videoElement = document.getElementById("veryfi-video-ref");
158
+ if (videoElement) {
159
+ resizeObserver.observe(videoElement);
160
+ }
161
+ } catch (e) {
162
+ console.log("ResizeObserver not supported, falling back to window resize event");
163
+ window.addEventListener("resize", updateOverlayPosition);
164
+ }
165
+
166
+ // Set up mutation observer to watch for video element being added/changed
167
+ mutationObserver = new MutationObserver((mutations) => {
168
+ const videoElement = document.getElementById("veryfi-video-ref");
169
+ if (videoElement) {
170
+ updateOverlayPosition();
171
+ if (resizeObserver) {
172
+ resizeObserver.observe(videoElement);
173
+ }
174
+ }
175
+ });
176
+
177
+ mutationObserver.observe(container, { childList: true, subtree: true });
178
+
179
+ // Add event listeners for any potential layout changes
180
+ window.addEventListener("resize", updateOverlayPosition);
181
+ window.addEventListener("orientationchange", updateOverlayPosition);
182
+ document.addEventListener("DOMContentLoaded", updateOverlayPosition);
183
+
184
+ // For devtools opening (which can change layout)
185
+ let lastWidth = window.innerWidth;
186
+ window.addEventListener("resize", () => {
187
+ if (window.innerWidth !== lastWidth) {
188
+ lastWidth = window.innerWidth;
189
+ setTimeout(updateOverlayPosition, 300);
190
+ }
191
+ });
192
+
193
+ return {
194
+ element: overlay,
195
+
196
+ updatePosition: () => {
197
+ updateOverlayPosition();
198
+ },
199
+
200
+ // Method to crop the bottle cap image
201
+ cropBottleCap: (videoElement) => {
202
+ if (!videoElement) return null;
203
+
204
+ // Get the cropImgRef element
205
+ const cropImgRef = document.getElementById("veryfi-crop-img-ref");
206
+ if (!cropImgRef) {
207
+ console.error("Crop image reference not found");
208
+ return null;
209
+ }
210
+
211
+ const videoRect = videoElement.getBoundingClientRect();
212
+ const circleDiameter = Math.min(videoRect.width, videoRect.height) * circleRadius;
213
+ const squareSize = circleDiameter * 0.7; // Square inside the circle
214
+
215
+ // Calculate scaling factors between screen and video dimensions
216
+ const scaleX = videoElement.videoWidth / videoRect.width;
217
+ const scaleY = videoElement.videoHeight / videoRect.height;
218
+
219
+ // Calculate center point in video coordinates
220
+ const centerX = (videoRect.width / 2) * scaleX;
221
+ const centerY = (videoRect.height / 2) * scaleY;
222
+
223
+ // Calculate the square's dimensions in video coordinates
224
+ const squareVideoSize = squareSize * Math.max(scaleX, scaleY);
225
+
226
+ // Calculate the top-left corner of the square in video coordinates
227
+ const cropX = centerX - (squareVideoSize / 2);
228
+ const cropY = centerY - (squareVideoSize / 2);
229
+
230
+ // Set cropImgRef dimensions to match the crop size - make sure width and height are equal
231
+ cropImgRef.width = squareVideoSize;
232
+ cropImgRef.height = squareVideoSize;
233
+
234
+ // Draw the cropped portion to the cropImgRef canvas
235
+ const ctx = cropImgRef.getContext('2d');
236
+ ctx.clearRect(0, 0, cropImgRef.width, cropImgRef.height);
237
+ ctx.drawImage(
238
+ videoElement,
239
+ cropX, cropY, squareVideoSize, squareVideoSize,
240
+ 0, 0, squareVideoSize, squareVideoSize
241
+ );
242
+
243
+ // Apply square display styling if the method exists
244
+ if (typeof cropImgRef.setSquareDisplay === 'function') {
245
+ cropImgRef.setSquareDisplay();
246
+ }
247
+
248
+ // Convert to base64
249
+ return cropImgRef.toDataURL('image/jpeg').split(',')[1];
250
+ },
251
+
252
+ hide: () => {
253
+ overlay.style.display = 'none';
254
+ },
255
+
256
+ show: () => {
257
+ overlay.style.display = 'block';
258
+ updateOverlayPosition();
259
+ },
260
+
261
+ cleanup: () => {
262
+ window.removeEventListener("resize", updateOverlayPosition);
263
+ window.removeEventListener("orientationchange", updateOverlayPosition);
264
+ document.removeEventListener("DOMContentLoaded", updateOverlayPosition);
265
+
266
+ if (resizeObserver) {
267
+ resizeObserver.disconnect();
268
+ }
269
+
270
+ if (mutationObserver) {
271
+ mutationObserver.disconnect();
272
+ }
273
+ }
274
+ };
275
+ };
@@ -1,4 +1,4 @@
1
- export function createFileUpload(container, captureUploaded, onSubmit) {
1
+ export function createFileUpload(container, captureUploaded, onSubmit, options = {}) {
2
2
  const fileUploadComponent = document.createElement('div');
3
3
  fileUploadComponent.id = 'veryfi-file-upload';
4
4
 
@@ -54,6 +54,14 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
54
54
  fileUploadComponent.style.imageContainerTop = '0%';
55
55
  }
56
56
 
57
+ // Define default options for button text
58
+ const defaultOptions = {
59
+ cropButtonText: 'Crop',
60
+ resetButtonText: 'Reset',
61
+ submitButtonText: 'Submit',
62
+ dropZoneText: 'Click or drag and drop to upload an image'
63
+ };
64
+
57
65
  fileUploadComponent.innerHTML = `
58
66
  <div id="image-container" style="
59
67
  width: 100%;
@@ -96,7 +104,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
96
104
  color: var(--file-upload-upload-zone-color, ${defaultStyles.uploadZoneColor});
97
105
  font-family: var(--file-upload-upload-zone-font-family, ${defaultStyles.uploadZoneFontFamily});
98
106
  ">
99
- Click or drag and drop to upload an image
107
+ ${options.dropZoneText}
100
108
  </div>
101
109
  <div id="button-container" style="
102
110
  display: none;
@@ -114,7 +122,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
114
122
  font-family: var(--file-upload-button-font-family, ${defaultStyles.buttonFontFamily});
115
123
  font-size: var(--file-upload-button-font-size, ${defaultStyles.buttonFontSize});
116
124
  width: var(--file-upload-button-width, ${defaultStyles.buttonWidth});
117
- ">Crop</button>
125
+ ">${options.cropButtonText}</button>
118
126
  <button id="reset-button" style="
119
127
  padding: var(--file-upload-button-padding, ${defaultStyles.buttonPadding});
120
128
  background-color: var(--file-upload-button-background-color, ${defaultStyles.buttonBackgroundColor});
@@ -125,7 +133,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
125
133
  font-family: var(--file-upload-button-font-family, ${defaultStyles.buttonFontFamily});
126
134
  font-size: var(--file-upload-button-font-size, ${defaultStyles.buttonFontSize});
127
135
  width: var(--file-upload-button-width, ${defaultStyles.buttonWidth});
128
- ">Reset</button>
136
+ ">${options.resetButtonText}</button>
129
137
  <button id="submit-button" style="
130
138
  padding: var(--file-upload-button-padding, ${defaultStyles.buttonPadding});
131
139
  background-color: var(--file-upload-button-background-color, ${defaultStyles.buttonBackgroundColor});
@@ -137,7 +145,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
137
145
  font-size: var(--file-upload-button-font-size, ${defaultStyles.buttonFontSize});
138
146
  display: none;
139
147
  width: var(--file-upload-button-width, ${defaultStyles.buttonWidth});
140
- ">Submit</button>
148
+ ">${options.submitButtonText}</button>
141
149
  </div>
142
150
  </div>
143
151
  `;
@@ -169,6 +177,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
169
177
  submitButton.style.display = 'none';
170
178
  cropButton.style.display = 'inline-block';
171
179
  resetButton.style.display = 'inline-block';
180
+ fileInput.value = '';
172
181
  };
173
182
 
174
183
  const handleFileSelect = (file) => {
@@ -221,7 +230,20 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
221
230
  imagePreview.style.display = 'block';
222
231
 
223
232
  cropButton.style.display = 'none';
224
- submitButton.style.display = 'inline-block';
233
+
234
+ // Check if submit button should be shown based on enableSubmit setting
235
+ if (container.dataset.enableSubmit !== 'false') {
236
+ submitButton.style.display = 'inline-block';
237
+ } else {
238
+ // If submit is disabled, call the callback directly with the processed image
239
+ // Format the result to match the document flavor format
240
+ console.log("Submit disabled, returning processed image directly");
241
+ onSubmit({
242
+ image: processedImage,
243
+ // Add any other properties that might be expected
244
+ doc_type: 'receipt'
245
+ });
246
+ }
225
247
  } catch (error) {
226
248
  console.error('Error during image processing:', error);
227
249
  alert(`An error occurred: ${error.message}. Please try again or check your connection. If the problem persists, contact support.`);
@@ -8,7 +8,7 @@ export const createCroppedImage = (container) => {
8
8
  height: 'auto',
9
9
  maxWidth: '350px',
10
10
  maxHeight: '100%',
11
- zIndex: '30'
11
+ zIndex: '130'
12
12
  };
13
13
 
14
14
  Object.entries(defaultStyles).forEach(([key, value]) => {
@@ -47,14 +47,31 @@ export const createCroppedImage = (container) => {
47
47
  const handleResize = () => {
48
48
  const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
49
49
  const isLandscape = window.innerWidth > window.innerHeight;
50
+ // Check if we're in bottle caps mode
51
+ const isBottleCapsMode = container.querySelector('#veryfi-bottle-cap-overlay') !== null;
50
52
 
51
- if (isMobile) {
53
+ if (isBottleCapsMode) {
54
+ // For bottle caps, maintain square aspect ratio
55
+ const squareSize = Math.min(350, Math.min(window.innerWidth * 0.8, window.innerHeight * 0.6));
56
+ cropImgCanvas.style.width = `${squareSize}px`;
57
+ cropImgCanvas.style.height = `${squareSize}px`;
58
+ cropImgCanvas.style.maxWidth = `${squareSize}px`;
59
+ cropImgCanvas.style.maxHeight = `${squareSize}px`;
60
+ cropImgCanvas.style.position = 'fixed';
61
+ cropImgCanvas.style.top = '50%';
62
+ cropImgCanvas.style.left = '50%';
63
+ cropImgCanvas.style.transform = 'translate(-50%, -50%)';
64
+ cropImgCanvas.style.objectFit = 'contain';
65
+ cropImgCanvas.style.display = 'block';
66
+ cropImgCanvas.style.margin = 'auto';
67
+ } else if (isMobile) {
52
68
  cropImgCanvas.style.width = '370px';
53
69
  cropImgCanvas.style.height = '95vh';
54
70
  cropImgCanvas.style.maxWidth = '350px';
55
71
  cropImgCanvas.style.position = 'fixed';
56
72
  cropImgCanvas.style.top = '';
57
73
  cropImgCanvas.style.left = '';
74
+ cropImgCanvas.style.transform = '';
58
75
  if (isLandscape) {
59
76
  cropImgCanvas.style.width = '170px';
60
77
  cropImgCanvas.style.height = '85vh';
@@ -70,6 +87,7 @@ export const createCroppedImage = (container) => {
70
87
  cropImgCanvas.style.position = 'absolute';
71
88
  cropImgCanvas.style.top = '';
72
89
  cropImgCanvas.style.left = '';
90
+ cropImgCanvas.style.transform = '';
73
91
  }
74
92
  };
75
93
 
@@ -82,6 +100,22 @@ export const createCroppedImage = (container) => {
82
100
  window.removeEventListener('resize', handleResize);
83
101
  };
84
102
 
103
+ // Add a specific method for bottle caps to ensure square display
104
+ const setSquareDisplay = () => {
105
+ const squareSize = Math.min(350, Math.min(window.innerWidth * 0.8, window.innerHeight * 0.6));
106
+ cropImgCanvas.style.width = `${squareSize}px`;
107
+ cropImgCanvas.style.height = `${squareSize}px`;
108
+ cropImgCanvas.style.maxWidth = `${squareSize}px`;
109
+ cropImgCanvas.style.maxHeight = `${squareSize}px`;
110
+ cropImgCanvas.style.position = 'fixed';
111
+ cropImgCanvas.style.top = '50%';
112
+ cropImgCanvas.style.left = '50%';
113
+ cropImgCanvas.style.transform = 'translate(-50%, -50%)';
114
+ cropImgCanvas.style.objectFit = 'contain';
115
+ cropImgCanvas.style.display = 'block';
116
+ cropImgCanvas.style.margin = 'auto';
117
+ };
118
+
85
119
  return Object.assign(cropImgCanvas, {
86
120
  cleanup,
87
121
  showBorder: () => {
@@ -95,6 +129,7 @@ export const createCroppedImage = (container) => {
95
129
  showSuccessBorder: () => {
96
130
  cropImgCanvas.style.border = '3px solid #00FA6C';
97
131
  cropImgCanvas.style.borderRadius = '10px';
98
- }
132
+ },
133
+ setSquareDisplay
99
134
  });
100
135
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "2.0.5",
3
+ "version": "2.0.6-beta.1",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
@@ -1,2 +1,119 @@
1
1
  import './ua-parser.js';
2
- export default (typeof window !== 'undefined' ? window.UAParser : null);
2
+
3
+ // Create a wrapper that ensures we always have something to export
4
+ const UAParserWrapper = function(ua, extensions) {
5
+ // First try to use the global UAParser
6
+ if (typeof window !== 'undefined' && typeof window.UAParser === 'function') {
7
+ try {
8
+ return new window.UAParser(ua, extensions);
9
+ } catch (e) {
10
+ console.warn('Error initializing UAParser:', e);
11
+ // Fall through to fallback
12
+ }
13
+ }
14
+
15
+ // If we can't use the global UAParser, create a basic parser that extracts some info
16
+ // This is a simplified version that handles common patterns
17
+ const userAgent = ua || (typeof navigator !== 'undefined' ? navigator.userAgent : '');
18
+
19
+ // Extract basic browser info
20
+ let browserName = 'unknown';
21
+ let browserVersion = 'unknown';
22
+ let osName = 'unknown';
23
+ let osVersion = 'unknown';
24
+ let deviceType = 'desktop';
25
+ let deviceVendor = 'unknown';
26
+ let deviceModel = 'unknown';
27
+
28
+ try {
29
+ // Basic browser detection
30
+ if (userAgent.indexOf('Chrome') > -1) {
31
+ browserName = 'Chrome';
32
+ const match = userAgent.match(/Chrome\/([\d\.]+)/);
33
+ if (match) browserVersion = match[1];
34
+ } else if (userAgent.indexOf('Firefox') > -1) {
35
+ browserName = 'Firefox';
36
+ const match = userAgent.match(/Firefox\/([\d\.]+)/);
37
+ if (match) browserVersion = match[1];
38
+ } else if (userAgent.indexOf('Safari') > -1) {
39
+ browserName = 'Safari';
40
+ const match = userAgent.match(/Version\/([\d\.]+)/);
41
+ if (match) browserVersion = match[1];
42
+ } else if (userAgent.indexOf('Edge') > -1 || userAgent.indexOf('Edg/') > -1) {
43
+ browserName = 'Edge';
44
+ const match = userAgent.match(/Edge?\/([\d\.]+)/);
45
+ if (match) browserVersion = match[1];
46
+ }
47
+
48
+ // Basic OS detection
49
+ if (userAgent.indexOf('Windows') > -1) {
50
+ osName = 'Windows';
51
+ if (userAgent.indexOf('Windows NT 10.0') > -1) osVersion = '10';
52
+ else if (userAgent.indexOf('Windows NT 6.3') > -1) osVersion = '8.1';
53
+ else if (userAgent.indexOf('Windows NT 6.2') > -1) osVersion = '8';
54
+ else if (userAgent.indexOf('Windows NT 6.1') > -1) osVersion = '7';
55
+ } else if (userAgent.indexOf('Mac OS X') > -1) {
56
+ osName = 'Mac OS';
57
+ const match = userAgent.match(/Mac OS X (\d+[._]\d+[._\d]*)/);
58
+ if (match) osVersion = match[1].replace(/_/g, '.');
59
+ } else if (userAgent.indexOf('Android') > -1) {
60
+ osName = 'Android';
61
+ deviceType = 'mobile';
62
+ const match = userAgent.match(/Android (\d+\.\d+)/);
63
+ if (match) osVersion = match[1];
64
+ } else if (userAgent.indexOf('iOS') > -1 || userAgent.indexOf('iPhone') > -1 || userAgent.indexOf('iPad') > -1) {
65
+ osName = 'iOS';
66
+ deviceType = userAgent.indexOf('iPad') > -1 ? 'tablet' : 'mobile';
67
+ deviceVendor = 'Apple';
68
+ deviceModel = userAgent.indexOf('iPad') > -1 ? 'iPad' : 'iPhone';
69
+ const match = userAgent.match(/OS (\d+_\d+)/);
70
+ if (match) osVersion = match[1].replace(/_/g, '.');
71
+ } else if (userAgent.indexOf('Linux') > -1) {
72
+ osName = 'Linux';
73
+ }
74
+
75
+ // Mobile detection
76
+ if (userAgent.indexOf('Mobile') > -1) {
77
+ deviceType = 'mobile';
78
+ }
79
+
80
+ // Device vendor detection
81
+ if (userAgent.indexOf('iPhone') > -1 || userAgent.indexOf('iPad') > -1 || userAgent.indexOf('iPod') > -1) {
82
+ deviceVendor = 'Apple';
83
+ } else if (userAgent.indexOf('Samsung') > -1) {
84
+ deviceVendor = 'Samsung';
85
+ } else if (userAgent.indexOf('Pixel') > -1) {
86
+ deviceVendor = 'Google';
87
+ } else if (userAgent.indexOf('Huawei') > -1) {
88
+ deviceVendor = 'Huawei';
89
+ }
90
+ } catch (e) {
91
+ console.warn('Error in fallback UA parsing:', e);
92
+ }
93
+
94
+ // Fallback implementation
95
+ return {
96
+ getResult: function() {
97
+ return {
98
+ ua: userAgent,
99
+ browser: { name: browserName, version: browserVersion },
100
+ engine: { name: 'unknown', version: 'unknown' },
101
+ os: { name: osName, version: osVersion },
102
+ device: { model: deviceModel, type: deviceType, vendor: deviceVendor },
103
+ cpu: { architecture: 'unknown' }
104
+ };
105
+ },
106
+ getBrowser: function() { return { name: browserName, version: browserVersion }; },
107
+ getEngine: function() { return { name: 'unknown', version: 'unknown' }; },
108
+ getOS: function() { return { name: osName, version: osVersion }; },
109
+ getDevice: function() { return { model: deviceModel, type: deviceType, vendor: deviceVendor }; },
110
+ getCPU: function() { return { architecture: 'unknown' }; },
111
+ getUA: function() { return userAgent; },
112
+ setUA: function(newUA) {
113
+ // This doesn't actually update the parsed values in this fallback
114
+ return this;
115
+ }
116
+ };
117
+ };
118
+
119
+ export default UAParserWrapper;
package/veryfi-lens.js CHANGED
@@ -24,6 +24,7 @@ import { createStitchingButton } from './components/stitchingButton.js';
24
24
  import { createCheckImages } from './components/checkImages.js';
25
25
  import { createSpinner } from './components/spinner.js';
26
26
  import { createCardDataButton } from './components/cardDataButton.js';
27
+ import { createBottleCapOverlay } from "./components/bottleCapOverlay.js";
27
28
 
28
29
 
29
30
 
@@ -37,7 +38,7 @@ const VeryfiLens = (function () {
37
38
  isCapturingFront: false,
38
39
  started: false,
39
40
  hasInit: false,
40
- torch_enabled: true,
41
+ torchEnabled: true,
41
42
  shouldProcessCC: true,
42
43
 
43
44
  // Document state
@@ -103,6 +104,8 @@ const VeryfiLens = (function () {
103
104
  frontImageSetter: null,
104
105
  backImageSetter: null,
105
106
  cardDataButton: null,
107
+ capCircleRadius: 0.7, // Default circle radius for bottle cap overlay (70% of smaller dimension)
108
+ bottleCapText: "Position bottle cap in circle", // Default instruction text for bottle cap overlay
106
109
 
107
110
  // Handlers
108
111
  successHandler: null,
@@ -142,6 +145,17 @@ const VeryfiLens = (function () {
142
145
  blurModalMessage: 'Oops, The image is too blurry to process',
143
146
  submitButtonText: 'Submit Anyway',
144
147
  retakeButtonText: 'Retake a picture',
148
+
149
+ // File upload UI text configuration
150
+ cropButtonText: 'Crop',
151
+ resetButtonText: 'Reset',
152
+ dropZoneText: 'Click or drag and drop to upload an image',
153
+
154
+ // Add new property for custom submit handler
155
+ customSubmitHandler: null,
156
+
157
+ // Add new properties for bottle cap functionality
158
+ bottleCapOverlay: null,
145
159
  };
146
160
 
147
161
 
@@ -197,7 +211,7 @@ const VeryfiLens = (function () {
197
211
  height: { ideal: 2160 }
198
212
  }),
199
213
  facingMode: "environment",
200
- advanced: [{ torch: true }]
214
+ ...(state.torchEnabled ? { advanced: [{ torch: true }] } : {})
201
215
  };
202
216
  state.debug_mode && console.log("video config", videoConfig);
203
217
 
@@ -236,7 +250,7 @@ const VeryfiLens = (function () {
236
250
  state.torchTrack = track;
237
251
  const capabilities = track.getCapabilities();
238
252
  if (capabilities.torch) {
239
- state.torch_enabled = true;
253
+ state.torchEnabled = true;
240
254
  }
241
255
  }
242
256
 
@@ -247,6 +261,8 @@ const VeryfiLens = (function () {
247
261
  case 'long_document':
248
262
  wasmWrapper.setStitcherCallback(logLongDocument);
249
263
  break;
264
+ case 'caps':
265
+ break;
250
266
  default:
251
267
  wasmWrapper.setDocumentCallback(logDocument);
252
268
  }
@@ -862,11 +878,22 @@ const VeryfiLens = (function () {
862
878
  };
863
879
 
864
880
  const parseUA = () => {
865
- const userAgentString = navigator.userAgent;
866
- const parser = new UAParser(userAgentString);
867
- let parserResults = parser.getResult && parser.getResult();
868
- if (parserResults) {
869
- return parserResults;
881
+ try {
882
+ const userAgentString = navigator.userAgent;
883
+ const parser = UAParser(userAgentString); // Note: no 'new' keyword needed now
884
+ let parserResults = parser.getResult();
885
+ if (parserResults) {
886
+ return parserResults;
887
+ }
888
+ // ...
889
+ } catch (error) {
890
+ console.error('Error parsing user agent:', error);
891
+ // Return fallback object
892
+ return {
893
+ browser: { name: 'unknown', version: 'unknown' },
894
+ os: { name: 'unknown', version: 'unknown' },
895
+ device: { model: 'unknown', type: 'unknown', vendor: 'unknown' }
896
+ };
870
897
  }
871
898
  };
872
899
 
@@ -936,7 +963,12 @@ const VeryfiLens = (function () {
936
963
  () => {
937
964
  state.debug_mode && console.log("Submitting anyway");
938
965
  hideVideoOverlay();
939
- state.submitHandler && state.submitHandler(state.finalImage);
966
+ // Use custom handler if provided, otherwise use default
967
+ if (state.customSubmitHandler && typeof state.customSubmitHandler === 'function') {
968
+ state.customSubmitHandler(state.finalImage);
969
+ } else {
970
+ state.submitHandler && state.submitHandler(state.finalImage);
971
+ }
940
972
  },
941
973
  {
942
974
  blurModalMessage: state.blurModalMessage,
@@ -958,7 +990,12 @@ const VeryfiLens = (function () {
958
990
  () => {
959
991
  state.debug_mode && console.log("Submitting anyway");
960
992
  hideVideoOverlay();
961
- state.submitHandler && state.submitHandler(state.finalImage);
993
+ // Use custom handler if provided, otherwise use default
994
+ if (state.customSubmitHandler && typeof state.customSubmitHandler === 'function') {
995
+ state.customSubmitHandler(state.finalImage);
996
+ } else {
997
+ state.submitHandler && state.submitHandler(state.finalImage);
998
+ }
962
999
  },
963
1000
  {
964
1001
  noDocumentMessage: state.documentModalMessage,
@@ -1130,36 +1167,52 @@ const VeryfiLens = (function () {
1130
1167
 
1131
1168
  const removeOverlay = () => {
1132
1169
  try {
1133
- // Clear any existing intervals first
1134
- if (state.intervalRef) {
1135
- clearInterval(state.intervalRef);
1136
- state.intervalRef = null;
1137
- }
1170
+ // Clear any existing intervals first
1171
+ if (state.intervalRef) {
1172
+ clearInterval(state.intervalRef);
1173
+ state.intervalRef = null;
1174
+ }
1138
1175
 
1139
- // Then proceed with other cleanup
1140
- if (state.videoRef && state.videoRef.srcObject) {
1141
- const tracks = state.videoRef.srcObject.getTracks();
1142
- tracks.forEach(track => track.stop());
1143
- }
1176
+ // Then proceed with other cleanup
1177
+ if (state.videoRef && state.videoRef.srcObject) {
1178
+ const tracks = state.videoRef.srcObject.getTracks();
1179
+ tracks.forEach(track => track.stop());
1180
+ }
1144
1181
 
1145
- // Reset WASM wrapper
1146
- if (wasmWrapper) {
1147
- wasmWrapper.release();
1148
- wasmWrapper = null;
1149
- }
1150
- if (state.usingOverlayContainer) {
1151
- stopLens();
1152
- document.body.removeChild(state.container);
1153
- state.usingOverlayContainer = false;
1154
- } else {
1155
- stopLens();
1156
- }
1182
+ // Reset WASM wrapper
1183
+ if (wasmWrapper) {
1184
+ try {
1185
+ wasmWrapper.release();
1186
+ } catch (error) {
1187
+ // Handle the case where WASM functions aren't accessible
1188
+ console.warn('WASM release failed - this is normal if cross-origin isolation is not enabled');
1189
+ } finally {
1190
+ wasmWrapper = null;
1191
+ }
1192
+ }
1157
1193
 
1158
- // Continue with other cleanup...
1159
- resetState();
1160
-
1194
+ // Clean up file upload component if it exists
1195
+ if (state.fileUpload) {
1196
+ state.fileUpload = null;
1197
+ }
1198
+
1199
+ if (state.usingOverlayContainer) {
1200
+ stopLens();
1201
+ document.body.removeChild(state.container);
1202
+ state.usingOverlayContainer = false;
1203
+ } else {
1204
+ stopLens();
1205
+ // Clear container contents if not using overlay
1206
+ if (state.container) {
1207
+ state.container.innerHTML = '';
1208
+ }
1209
+ }
1210
+
1211
+ // Continue with other cleanup...
1212
+ resetState();
1213
+
1161
1214
  } catch (error) {
1162
- console.error("Error in removeOverlay:", error);
1215
+ console.error("Error in removeOverlay:", error);
1163
1216
  }
1164
1217
  };
1165
1218
 
@@ -1183,6 +1236,8 @@ const VeryfiLens = (function () {
1183
1236
  state.frontImage = null;
1184
1237
  state.backImage = null;
1185
1238
  state.previewData = null;
1239
+ state.capCircleRadius = 0.7; // Reset to default circle radius
1240
+ state.bottleCapText = "Position bottle cap in circle"; // Reset to default text
1186
1241
 
1187
1242
  // Reset UI references
1188
1243
  state.videoOverlay = null;
@@ -1200,7 +1255,7 @@ const VeryfiLens = (function () {
1200
1255
  state.longPreview = null;
1201
1256
  state.stitchingButton = null;
1202
1257
  state.checkImagesComponent = null;
1203
-
1258
+ state.bottleCapOverlay = null;
1204
1259
  // Reset container if using overlay
1205
1260
  if (state.usingOverlayContainer) {
1206
1261
  state.container = null;
@@ -1213,8 +1268,14 @@ const VeryfiLens = (function () {
1213
1268
 
1214
1269
  // Reset WASM
1215
1270
  if (wasmWrapper) {
1216
- wasmWrapper.release();
1217
- wasmWrapper = null;
1271
+ try {
1272
+ wasmWrapper.release();
1273
+ } catch (error) {
1274
+ // Handle the case where WASM functions aren't accessible
1275
+ console.warn('WASM release failed - this is normal if cross-origin isolation is not enabled');
1276
+ } finally {
1277
+ wasmWrapper = null;
1278
+ }
1218
1279
  }
1219
1280
 
1220
1281
  state.debug_mode && console.log("State reset complete");
@@ -1365,7 +1426,12 @@ const VeryfiLens = (function () {
1365
1426
  hideVideoOverlay();
1366
1427
  if (state.isDocument && !state.blurStatus) {
1367
1428
  state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1368
- handleSubmit(state.finalImage);
1429
+ // Use custom handler if provided, otherwise use default
1430
+ if (state.customSubmitHandler && typeof state.customSubmitHandler === 'function') {
1431
+ state.customSubmitHandler(state.finalImage);
1432
+ } else {
1433
+ handleSubmit(state.finalImage);
1434
+ }
1369
1435
  }, removeOverlay);
1370
1436
  state.enableSubmit && state.submitButton.show();
1371
1437
  }
@@ -1441,7 +1507,12 @@ const VeryfiLens = (function () {
1441
1507
  hideVideoOverlay();
1442
1508
  if (state.isDocument && !state.blurStatus) {
1443
1509
  state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1444
- handleSubmit(state.frontImage);
1510
+ // Use custom handler if provided, otherwise use default
1511
+ if (state.customSubmitHandler && typeof state.customSubmitHandler === 'function') {
1512
+ state.customSubmitHandler(state.frontImage);
1513
+ } else {
1514
+ handleSubmit(state.frontImage);
1515
+ }
1445
1516
  }, removeOverlay);
1446
1517
  state.enableSubmit && state.submitButton.show();
1447
1518
  }
@@ -1497,8 +1568,11 @@ const VeryfiLens = (function () {
1497
1568
  zip.file("back.jpg", state.backImage, { base64: true });
1498
1569
  const zipContent = await zip.generateAsync({ type: "base64" });
1499
1570
  state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1500
- state.captureBackOfCheck ? handleSubmit(zipContent) : handleSubmit(state.frontImage);
1501
-
1571
+ if (state.customSubmitHandler && typeof state.customSubmitHandler === 'function') {
1572
+ state.customSubmitHandler(state.captureBackOfCheck ? zipContent : state.frontImage);
1573
+ } else {
1574
+ state.captureBackOfCheck ? handleSubmit(zipContent) : handleSubmit(state.frontImage);
1575
+ }
1502
1576
  }, removeOverlay);
1503
1577
  state.enableSubmit && state.submitButton.show();
1504
1578
  }
@@ -1584,7 +1658,10 @@ const VeryfiLens = (function () {
1584
1658
  }
1585
1659
  }
1586
1660
 
1587
- await initializeWasmWrapper();
1661
+ // Only initialize WASM for flavors that need it
1662
+ if (state.lensFlavor !== "caps") {
1663
+ await initializeWasmWrapper();
1664
+ }
1588
1665
 
1589
1666
  // Set up flavor-specific configurations
1590
1667
  switch (state.lensFlavor) {
@@ -1615,17 +1692,27 @@ const VeryfiLens = (function () {
1615
1692
  wasmWrapper.setDocumentCallback(logDocument);
1616
1693
  }
1617
1694
  break;
1695
+ case "caps":
1696
+ // Caps doesn't need WASM processing, just a simple camera feed
1697
+ break;
1618
1698
  default:
1619
1699
  throw new Error(`Unknown lens flavor: ${state.lensFlavor}`);
1620
1700
  }
1621
1701
 
1622
- state.lensFlavor != 'upload' && await getVideo(state.lensFlavor);
1702
+ // Get video for all camera-based flavors
1703
+ if (state.lensFlavor !== 'upload') {
1704
+ await getVideo(state.lensFlavor);
1705
+ }
1623
1706
 
1624
- // Start processing frames
1707
+ // Start processing frames for all except caps and upload
1625
1708
  requestAnimationFrame(displayVideo);
1626
- state.intervalRef = setInterval(() => {
1627
- state.lensFlavor === "credit_card" ? sendCardWasm() : sendWasm(state.lensFlavor);
1628
- }, state.INTERVAL);
1709
+
1710
+ // Only set up interval for flavors that need continuous processing
1711
+ if (state.lensFlavor !== "caps" && state.lensFlavor !== "upload") {
1712
+ state.intervalRef = setInterval(() => {
1713
+ state.lensFlavor === "credit_card" ? sendCardWasm() : sendWasm(state.lensFlavor);
1714
+ }, state.INTERVAL);
1715
+ }
1629
1716
  };
1630
1717
 
1631
1718
  const stopLens = () => {
@@ -1873,6 +1960,131 @@ const VeryfiLens = (function () {
1873
1960
  }
1874
1961
  }
1875
1962
 
1963
+ // Add a new function to handle bottle cap capture
1964
+ const captureBottleCap = async () => {
1965
+ try {
1966
+ state.debug_mode && console.log("[EVENT] capture bottle cap");
1967
+ state.updateHandler && state.updateHandler({ status: 'capture_started' });
1968
+
1969
+ if (!state.bottleCapOverlay || !state.videoRef) {
1970
+ throw new Error("Bottle cap overlay or video reference not initialized");
1971
+ }
1972
+
1973
+ // Crop the bottle cap from the video stream
1974
+ state.finalImage = state.bottleCapOverlay.cropBottleCap(state.videoRef);
1975
+
1976
+ if (!state.finalImage) {
1977
+ throw new Error("Failed to capture bottle cap image");
1978
+ }
1979
+
1980
+ // Set document state to true for processing
1981
+ state.isDocument = true;
1982
+
1983
+ // Hide video components
1984
+ hideVideoOverlay();
1985
+
1986
+ // Set square display for the cropped image
1987
+ if (state.cropImgRef && typeof state.cropImgRef.setSquareDisplay === 'function') {
1988
+ state.cropImgRef.setSquareDisplay();
1989
+ }
1990
+
1991
+ // Show success border on the cropped image
1992
+ if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
1993
+ state.cropImgRef.showSuccessBorder();
1994
+ }
1995
+
1996
+ // Send the image to the result setter if available
1997
+ if (state.resultSetter && typeof state.resultSetter === 'function') {
1998
+ state.resultSetter(state.finalImage);
1999
+ }
2000
+
2001
+ // Process the document with the API if needed
2002
+ try {
2003
+ state.updateHandler && state.updateHandler({ status: 'processing_started' });
2004
+ // state.docReadyResult = await docReady();
2005
+ state.updateHandler && state.updateHandler({ status: 'processing_completed' });
2006
+
2007
+ if (state.resultSetter && typeof state.resultSetter === 'function') {
2008
+ state.resultSetter({ image: state.finalImage });
2009
+ }
2010
+ } catch (error) {
2011
+ console.error("Error processing document:", error);
2012
+ // Continue even if docReady fails
2013
+ }
2014
+
2015
+ // Create submit button for sending image to backend
2016
+ state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
2017
+ // Use custom handler if provided, otherwise use default
2018
+ if (state.customSubmitHandler && typeof state.customSubmitHandler === 'function') {
2019
+ state.customSubmitHandler(state.finalImage);
2020
+ } else {
2021
+ handleSubmit(state.finalImage);
2022
+ }
2023
+ }, removeOverlay);
2024
+
2025
+ state.enableSubmit && state.submitButton.show();
2026
+ state.updateHandler && state.updateHandler({ status: 'capture_completed' });
2027
+
2028
+ return state.finalImage;
2029
+ } catch (error) {
2030
+ console.error("Bottle cap capture failed:", error.message);
2031
+ if (state.failureHandler && typeof state.failureHandler === 'function') {
2032
+ state.failureHandler(error);
2033
+ }
2034
+ state.updateHandler && state.updateHandler({ status: 'capture_failed' });
2035
+ return null;
2036
+ }
2037
+ };
2038
+
2039
+ // Add function to render bottle cap overlay
2040
+ const renderBottleCapOverlayIfNeeded = () => {
2041
+ state.debug_mode && console.log("Rendering bottle cap overlay");
2042
+ !state.videoOverlay && (state.videoOverlay = createVideoOverlay(state.container));
2043
+
2044
+ // Add exit button first
2045
+ if (state.exitButton) {
2046
+ state.exitButton = createExitButton(state.videoOverlay.overlay, {
2047
+ setter: state.onClose,
2048
+ redirectUrl: state.onCloseRedirectUrl,
2049
+ lensFlavor: state.lensFlavor,
2050
+ }, removeOverlay);
2051
+ }
2052
+
2053
+ // Add capture button
2054
+ state.captureButton = createCaptureButton(state.videoOverlay.overlay, captureBottleCap);
2055
+
2056
+ // Add torch button if enabled
2057
+ if (state.torchButton) {
2058
+ state.torchButton = createTorchButton(state.videoOverlay.overlay, () => {
2059
+ toggleTorchLight();
2060
+ }, state.lensFlavor);
2061
+ }
2062
+
2063
+ // Only create bottle cap overlay after video is loaded
2064
+ const videoElement = document.getElementById("veryfi-video-ref");
2065
+
2066
+ if (videoElement) {
2067
+ // If video is already loaded, create overlay immediately
2068
+ if (videoElement.readyState >= 2) {
2069
+ !state.bottleCapOverlay && (state.bottleCapOverlay = createBottleCapOverlay(state.container, {
2070
+ circleRadius: state.capCircleRadius,
2071
+ instructionText: state.bottleCapText
2072
+ }));
2073
+ } else {
2074
+ // Otherwise wait for video to load enough data
2075
+ const handleVideoLoad = () => {
2076
+ !state.bottleCapOverlay && (state.bottleCapOverlay = createBottleCapOverlay(state.container, {
2077
+ circleRadius: state.capCircleRadius,
2078
+ instructionText: state.bottleCapText
2079
+ }));
2080
+ videoElement.removeEventListener('loadeddata', handleVideoLoad);
2081
+ };
2082
+
2083
+ videoElement.addEventListener('loadeddata', handleVideoLoad);
2084
+ }
2085
+ }
2086
+ };
2087
+
1876
2088
  return {
1877
2089
 
1878
2090
  init: async (clientId, config) => {
@@ -1884,8 +2096,8 @@ const VeryfiLens = (function () {
1884
2096
  state.clientId = clientId
1885
2097
  state.clientData = await validatePartner(state.clientId);
1886
2098
  config.debug_mode && console.log(state.clientData);
1887
-
1888
- await initializeWasmWrapper();
2099
+
2100
+ config.lensFlavor === "caps" ? null : await initializeWasmWrapper();
1889
2101
 
1890
2102
  switch (config.lensFlavor) {
1891
2103
  case "checks":
@@ -1922,6 +2134,7 @@ const VeryfiLens = (function () {
1922
2134
  showCamera: async (setter) => {
1923
2135
  try {
1924
2136
  state.debug_mode && console.log("Starting camera initialization");
2137
+ console.log(setter);
1925
2138
  setter && (state.resultSetter = setter);
1926
2139
 
1927
2140
  // Ensure container exists
@@ -1933,6 +2146,9 @@ const VeryfiLens = (function () {
1933
2146
  }
1934
2147
  }
1935
2148
 
2149
+ // Pass enableSubmit setting to container for use by components
2150
+ state.container.dataset.enableSubmit = state.enableSubmit.toString();
2151
+
1936
2152
  // Create core elements and verify success
1937
2153
  const elementsCreated = await createCoreElements();
1938
2154
 
@@ -1941,12 +2157,41 @@ const VeryfiLens = (function () {
1941
2157
  }
1942
2158
 
1943
2159
  // Initialize WASM if needed
1944
- await initializeWasmWrapper();
2160
+ state.lensFlavor === "caps" ? null : await initializeWasmWrapper();
2161
+
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("Starting lens for bottle cap");
2165
+ await newStartLens();
2166
+ }
1945
2167
 
1946
2168
  // Render appropriate UI elements based on lens flavor
1947
2169
  switch (state.lensFlavor) {
1948
2170
  case 'upload':
1949
- !state.fileUpload && (state.fileUpload = createFileUpload(state.container, captureUploaded, handleSubmit));
2171
+ !state.fileUpload && (state.fileUpload = createFileUpload(state.container, captureUploaded, (result) => {
2172
+ const formattedResult = typeof result === 'string'
2173
+ ? { image: result, doc_type: 'receipt' }
2174
+ : result;
2175
+
2176
+ if (!state.enableSubmit) {
2177
+ state.debug_mode && console.log("Submit disabled, handling image directly");
2178
+ if (state.resultSetter && typeof state.resultSetter === 'function') {
2179
+ state.resultSetter(formattedResult);
2180
+ }
2181
+ } else {
2182
+ // Use custom handler if provided, otherwise use default
2183
+ if (state.customSubmitHandler && typeof state.customSubmitHandler === 'function') {
2184
+ state.customSubmitHandler(formattedResult.image);
2185
+ } else {
2186
+ handleSubmit(formattedResult.image);
2187
+ }
2188
+ }
2189
+ }, {
2190
+ cropButtonText: state.cropButtonText,
2191
+ resetButtonText: state.resetButtonText,
2192
+ submitButtonText: state.submitButtonText,
2193
+ dropZoneText: state.dropZoneText
2194
+ }));
1950
2195
  // Add exit button for upload flavor
1951
2196
  if (state.exitButton) {
1952
2197
  createExitButton(state.container, {
@@ -1959,6 +2204,10 @@ const VeryfiLens = (function () {
1959
2204
  case 'credit_card':
1960
2205
  renderCreditCardIfNeeded();
1961
2206
  break;
2207
+ case 'caps':
2208
+ // Create UI elements after video has initialized
2209
+ renderBottleCapOverlayIfNeeded();
2210
+ break;
1962
2211
  default:
1963
2212
  state.debug_mode && console.log('Rendering UI elements');
1964
2213
  renderModalsIfNeeded();
@@ -1966,8 +2215,8 @@ const VeryfiLens = (function () {
1966
2215
  break;
1967
2216
  }
1968
2217
 
1969
- // Start lens if not already started
1970
- if (!state.started) {
2218
+ // Start lens for non-caps flavors
2219
+ if (!state.started && state.lensFlavor !== 'caps') {
1971
2220
  state.debug_mode && console.log("Starting lens");
1972
2221
  await newStartLens();
1973
2222
  }
@@ -1990,6 +2239,7 @@ const VeryfiLens = (function () {
1990
2239
  !state.uuidv4 && await generateDeviceIDifNeeded();
1991
2240
  const browserData = await getBrowserData();
1992
2241
  const UAData = flattenObject(parseUA());
2242
+
1993
2243
  return {
1994
2244
  browser_fingerprint: { ...UAData, ...browserData },
1995
2245
  uuid: state.uuidv4,
@@ -2031,7 +2281,15 @@ const VeryfiLens = (function () {
2031
2281
  state.failureHandler(error);
2032
2282
  }
2033
2283
  }
2034
- }
2284
+ },
2285
+
2286
+ setCustomSubmitHandler: (handler) => {
2287
+ if (typeof handler === 'function') {
2288
+ state.customSubmitHandler = handler;
2289
+ } else {
2290
+ console.warn('Custom submit handler must be a function');
2291
+ }
2292
+ },
2035
2293
  };
2036
2294
  })();
2037
2295