veryfi-lens-wasm 3.0.2 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md 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
@@ -218,6 +219,14 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
218
219
  | `rectHeight` | `number` | `0.08` | Capture rectangle height (0-1) |
219
220
  | `codeStripsText` | `string` | `"Position code strip in rectangle"` | Instruction text |
220
221
 
222
+ ### Prescription Label Settings (`prescription_label` flavor)
223
+
224
+ | Option | Type | Default | Description |
225
+ |---|---|---|---|
226
+ | `prescriptionLabelWidthRatio` | `number` | `0.55` | Label overlay width (0-1 relative to viewport) |
227
+ | `prescriptionLabelHeightRatio` | `number` | `0.65` | Label overlay height (0-1 relative to viewport) |
228
+ | `prescriptionLabelText` | `string` | `"Position prescription label in outline"` | Instruction text |
229
+
221
230
  ### Upload Settings (`upload` flavor)
222
231
 
223
232
  | 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: '4px solid white',
14
- backgroundColor: 'transparent',
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.5))';
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, transparent)';
54
+ button.style.backgroundColor = 'var(--capture-button-background-color, rgba(255, 255, 255, 0.15))';
52
55
  });
53
56
 
54
57
  let isStitching = false;
@@ -9,7 +9,7 @@ export const createExitButton = (container, options, removeOverlay) => {
9
9
  position: 'absolute',
10
10
  bottom: '50px',
11
11
  left: '100px',
12
- backgroundColor: 'rgba(107, 114, 128, 0.5)',
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: 'none',
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(55, 65, 81, 0.8)';
73
+ button.style.backgroundColor = 'rgba(255, 255, 255, 0.25)';
72
74
  });
73
75
 
74
76
  button.addEventListener('mouseleave', () => {
75
- button.style.backgroundColor = 'rgba(107, 114, 128, 0.5)';
77
+ button.style.backgroundColor = 'rgba(255, 255, 255, 0.15)';
76
78
  });
77
79
 
78
80
  button.addEventListener('click', (e) => {
@@ -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
+ };
@@ -5,7 +5,7 @@ export const createTorchButton = (container, toggleCallback, lensFlavor) => {
5
5
  const defaultStyles = {
6
6
  width: '40px',
7
7
  height: '40px',
8
- backgroundColor: 'rgba(107, 114, 128, 0.5)',
8
+ backgroundColor: 'rgba(255, 255, 255, 0.15)',
9
9
  color: '#FFFFFF',
10
10
  borderRadius: '50%',
11
11
  position: 'absolute',
@@ -18,7 +18,7 @@ export const createTorchButton = (container, toggleCallback, lensFlavor) => {
18
18
  padding: '0',
19
19
  cursor: 'pointer',
20
20
  pointerEvents: 'auto',
21
- border: 'none',
21
+ border: '1px solid rgba(255, 255, 255, 0.4)',
22
22
  outline: 'none',
23
23
  boxSizing: 'border-box',
24
24
  margin: '0',
@@ -26,6 +26,8 @@ export const createTorchButton = (container, toggleCallback, lensFlavor) => {
26
26
  minHeight: '40px',
27
27
  maxWidth: '40px',
28
28
  maxHeight: '40px',
29
+ backdropFilter: 'blur(8px)',
30
+ WebkitBackdropFilter: 'blur(8px)',
29
31
  };
30
32
 
31
33
 
@@ -57,10 +59,10 @@ export const createTorchButton = (container, toggleCallback, lensFlavor) => {
57
59
  }
58
60
 
59
61
  button.addEventListener('mouseover', () => {
60
- button.style.backgroundColor = 'rgba(75, 85, 99, 0.8)';
62
+ button.style.backgroundColor = 'rgba(255, 255, 255, 0.25)';
61
63
  });
62
64
  button.addEventListener('mouseout', () => {
63
- button.style.backgroundColor = 'rgba(107, 114, 128, 0.5)';
65
+ button.style.backgroundColor = 'rgba(255, 255, 255, 0.15)';
64
66
  });
65
67
 
66
68
  button.addEventListener('click', toggleCallback);
package/core/api.js CHANGED
@@ -110,7 +110,7 @@ export const handleSubmit = async (image) => {
110
110
 
111
111
  const getDocType = () => {
112
112
  if (lensFlavor === 'checks') return 'checks';
113
- if (lensFlavor === 'anydocs') return 'anydocs';
113
+ if (lensFlavor === 'anydocs' || lensFlavor === 'prescription_label') return 'anydocs';
114
114
  return 'documents';
115
115
  };
116
116
 
@@ -120,7 +120,7 @@ export const handleSubmit = async (image) => {
120
120
  resource: "api",
121
121
  client_name: clientData.client_name,
122
122
  device_data: deviceData,
123
- ...(lensFlavor === 'anydocs' && selectedBlueprint ? { blueprint_name: selectedBlueprint } : {}),
123
+ ...((lensFlavor === 'anydocs' || lensFlavor === 'prescription_label') && selectedBlueprint ? { blueprint_name: selectedBlueprint } : {}),
124
124
  ...customData
125
125
  };
126
126
 
package/core/camera.js CHANGED
@@ -93,6 +93,7 @@ export const getVideo = async (lensFlavor) => {
93
93
  break;
94
94
  case 'caps':
95
95
  case 'code_strips':
96
+ case 'prescription_label':
96
97
  break;
97
98
  default:
98
99
  refs.wasmWrapper.setDocumentCallback(actions.logDocument);
@@ -0,0 +1,417 @@
1
+ import { state } from '../state.js';
2
+ import { handleSubmit } from '../api.js';
3
+ import { hideVideoOverlay, showVideoOverlay } from '../overlay-controls.js';
4
+ import { removeOverlay, newStartLens } from '../lifecycle.js';
5
+ import { createSubmitButton } from '../../components/submitButton.js';
6
+
7
+ let mediaRecorder = null;
8
+ let recordedChunks = [];
9
+ let isRecording = false;
10
+ let recordingIndicator = null;
11
+ let pulseStyleEl = null;
12
+ let videoPreviewEl = null;
13
+ let retakeButtonEl = null;
14
+ let playPauseButtonEl = null;
15
+ let lastVideoBlob = null;
16
+
17
+ const ensurePulseKeyframes = () => {
18
+ if (pulseStyleEl) return;
19
+ pulseStyleEl = document.createElement('style');
20
+ pulseStyleEl.id = 'veryfi-pulse-keyframes';
21
+ pulseStyleEl.textContent = `
22
+ @keyframes veryfi-pulse {
23
+ 0%, 100% { opacity: 1; }
24
+ 50% { opacity: 0.3; }
25
+ }
26
+ `;
27
+ document.head.appendChild(pulseStyleEl);
28
+ };
29
+
30
+ const releasePulseKeyframes = () => {
31
+ if (pulseStyleEl) {
32
+ pulseStyleEl.remove();
33
+ pulseStyleEl = null;
34
+ }
35
+ };
36
+
37
+ const updateRecordingUI = (recording) => {
38
+ const captureBtn = document.getElementById('veryfi-capture-button');
39
+ if (captureBtn) {
40
+ if (recording) {
41
+ captureBtn.style.backgroundColor = 'rgba(255, 0, 0, 0.7)';
42
+ captureBtn.innerHTML = `
43
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white" style="width: 28px; height: 28px; display: block; margin: auto;">
44
+ <rect x="6" y="6" width="12" height="12" rx="2"/>
45
+ </svg>`;
46
+ } else {
47
+ captureBtn.style.backgroundColor = 'transparent';
48
+ captureBtn.innerHTML = '';
49
+ }
50
+ }
51
+
52
+ if (recording) {
53
+ ensurePulseKeyframes();
54
+ if (!recordingIndicator && state.videoOverlay?.overlay) {
55
+ recordingIndicator = document.createElement('div');
56
+ recordingIndicator.id = 'veryfi-recording-indicator';
57
+ Object.assign(recordingIndicator.style, {
58
+ position: 'absolute',
59
+ top: '20px',
60
+ left: '50%',
61
+ transform: 'translateX(-50%)',
62
+ display: 'flex',
63
+ alignItems: 'center',
64
+ gap: '8px',
65
+ padding: '6px 14px',
66
+ background: 'rgba(0,0,0,0.6)',
67
+ borderRadius: '20px',
68
+ zIndex: '1100',
69
+ pointerEvents: 'none',
70
+ });
71
+
72
+ const dot = document.createElement('div');
73
+ Object.assign(dot.style, {
74
+ width: '10px',
75
+ height: '10px',
76
+ borderRadius: '50%',
77
+ background: 'red',
78
+ animation: 'veryfi-pulse 1s infinite',
79
+ });
80
+
81
+ const text = document.createElement('span');
82
+ Object.assign(text.style, {
83
+ color: 'white',
84
+ fontSize: '14px',
85
+ fontFamily: 'Arial, sans-serif',
86
+ });
87
+ text.textContent = 'REC';
88
+
89
+ recordingIndicator.appendChild(dot);
90
+ recordingIndicator.appendChild(text);
91
+ state.videoOverlay.overlay.appendChild(recordingIndicator);
92
+ }
93
+ if (recordingIndicator) recordingIndicator.style.display = 'flex';
94
+ } else {
95
+ if (recordingIndicator) {
96
+ recordingIndicator.remove();
97
+ recordingIndicator = null;
98
+ }
99
+ releasePulseKeyframes();
100
+ }
101
+ };
102
+
103
+ const isIOS = () => /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
104
+
105
+ const getRecorderMimeType = () => {
106
+ if (state.preferredVideoFormat) {
107
+ const preferred = state.preferredVideoFormat;
108
+ if (MediaRecorder.isTypeSupported(preferred)) {
109
+ console.log(`[prescription_label] Using preferred video format: ${preferred}`);
110
+ return preferred;
111
+ }
112
+ console.warn(`[prescription_label] Preferred format "${preferred}" not supported, falling back`);
113
+ }
114
+
115
+ const types = isIOS()
116
+ ? ['video/mp4', 'video/quicktime']
117
+ : ['video/mp4', 'video/webm;codecs=vp9', 'video/webm;codecs=vp8', 'video/webm'];
118
+
119
+ for (const t of types) {
120
+ if (MediaRecorder.isTypeSupported(t)) {
121
+ console.log(`[prescription_label] Selected video format: ${t}`);
122
+ return t;
123
+ }
124
+ console.log(`[prescription_label] Format not supported: ${t}`);
125
+ }
126
+ console.warn('[prescription_label] No supported video format found, using browser default');
127
+ return '';
128
+ };
129
+
130
+ const startRecording = () => {
131
+ const stream = state.videoRef?.srcObject;
132
+ if (!stream) {
133
+ console.error('No video stream available for recording');
134
+ state.failureHandler?.(new Error('No video stream available'));
135
+ return;
136
+ }
137
+
138
+ recordedChunks = [];
139
+ const mimeType = getRecorderMimeType();
140
+ const recorderOptions = mimeType ? { mimeType } : {};
141
+ console.log(`[prescription_label] MediaRecorder options:`, recorderOptions);
142
+
143
+ try {
144
+ mediaRecorder = new MediaRecorder(stream, recorderOptions);
145
+ } catch (e) {
146
+ console.error('Failed to create MediaRecorder:', e);
147
+ state.failureHandler?.(e);
148
+ return;
149
+ }
150
+
151
+ mediaRecorder.ondataavailable = (event) => {
152
+ if (event.data.size > 0) {
153
+ recordedChunks.push(event.data);
154
+ }
155
+ };
156
+
157
+ mediaRecorder.start(200);
158
+ isRecording = true;
159
+ updateRecordingUI(true);
160
+ state.updateHandler?.({ status: 'recording_started' });
161
+ state.debug_mode && console.log('[EVENT] prescription label recording started');
162
+ };
163
+
164
+ const stopRecording = () => {
165
+ return new Promise((resolve) => {
166
+ if (!mediaRecorder || !isRecording) {
167
+ resolve(null);
168
+ return;
169
+ }
170
+
171
+ mediaRecorder.onstop = () => {
172
+ isRecording = false;
173
+ updateRecordingUI(false);
174
+ const blob = new Blob(recordedChunks, { type: mediaRecorder.mimeType });
175
+ recordedChunks = [];
176
+ mediaRecorder = null;
177
+ state.updateHandler?.({ status: 'recording_stopped' });
178
+ state.debug_mode && console.log('[EVENT] prescription label recording stopped, blob size:', blob.size);
179
+ resolve(blob);
180
+ };
181
+
182
+ mediaRecorder.stop();
183
+ });
184
+ };
185
+
186
+ const cleanupPreview = () => {
187
+ if (videoPreviewEl) {
188
+ videoPreviewEl.pause();
189
+ videoPreviewEl.src = '';
190
+ videoPreviewEl.remove();
191
+ videoPreviewEl = null;
192
+ }
193
+ if (retakeButtonEl) {
194
+ retakeButtonEl.remove();
195
+ retakeButtonEl = null;
196
+ }
197
+ if (playPauseButtonEl) {
198
+ playPauseButtonEl.remove();
199
+ playPauseButtonEl = null;
200
+ }
201
+ if (lastVideoBlob) {
202
+ URL.revokeObjectURL(lastVideoBlob._objectUrl);
203
+ lastVideoBlob = null;
204
+ }
205
+ };
206
+
207
+ const showVideoPreview = (videoBlob) => {
208
+ lastVideoBlob = videoBlob;
209
+ const objectUrl = URL.createObjectURL(videoBlob);
210
+ lastVideoBlob._objectUrl = objectUrl;
211
+
212
+ const containerEl = state.container;
213
+ if (!containerEl) return;
214
+
215
+ videoPreviewEl = document.createElement('video');
216
+ videoPreviewEl.id = 'veryfi-video-preview';
217
+ videoPreviewEl.src = objectUrl;
218
+ videoPreviewEl.loop = true;
219
+ videoPreviewEl.muted = true;
220
+ videoPreviewEl.playsInline = true;
221
+ const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
222
+ const isFullscreen = containerEl.dataset.fullscreen === 'true';
223
+
224
+ if (isMobile || isFullscreen) {
225
+ Object.assign(videoPreviewEl.style, {
226
+ position: 'fixed',
227
+ top: '0',
228
+ left: '0',
229
+ width: '100vw',
230
+ height: '100vh',
231
+ maxWidth: 'none',
232
+ transform: 'none',
233
+ objectFit: 'cover',
234
+ zIndex: '900',
235
+ background: '#000',
236
+ });
237
+ } else {
238
+ Object.assign(videoPreviewEl.style, {
239
+ position: 'absolute',
240
+ width: '100%',
241
+ height: 'auto',
242
+ maxWidth: '500px',
243
+ transform: 'none',
244
+ objectFit: 'cover',
245
+ zIndex: '900',
246
+ background: '#000',
247
+ });
248
+ }
249
+ containerEl.appendChild(videoPreviewEl);
250
+
251
+ const playSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white" style="width:24px;height:24px"><path d="M8 5v14l11-7z"/></svg>`;
252
+ const pauseSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white" style="width:24px;height:24px"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>`;
253
+
254
+ playPauseButtonEl = document.createElement('button');
255
+ playPauseButtonEl.id = 'veryfi-play-pause-button';
256
+ playPauseButtonEl.innerHTML = playSvg;
257
+ Object.assign(playPauseButtonEl.style, {
258
+ position: 'absolute',
259
+ top: '50%',
260
+ left: '50%',
261
+ transform: 'translate(-50%, -50%)',
262
+ width: '60px',
263
+ height: '60px',
264
+ borderRadius: '50%',
265
+ border: 'none',
266
+ backgroundColor: 'rgba(0,0,0,0.5)',
267
+ cursor: 'pointer',
268
+ zIndex: '950',
269
+ pointerEvents: 'auto',
270
+ display: 'flex',
271
+ alignItems: 'center',
272
+ justifyContent: 'center',
273
+ transition: 'opacity 0.2s',
274
+ });
275
+
276
+ playPauseButtonEl.addEventListener('click', () => {
277
+ if (videoPreviewEl.paused) {
278
+ videoPreviewEl.play().catch(() => {});
279
+ playPauseButtonEl.innerHTML = pauseSvg;
280
+ } else {
281
+ videoPreviewEl.pause();
282
+ playPauseButtonEl.innerHTML = playSvg;
283
+ }
284
+ });
285
+
286
+ videoPreviewEl.addEventListener('ended', () => {
287
+ playPauseButtonEl.innerHTML = playSvg;
288
+ });
289
+
290
+ containerEl.appendChild(playPauseButtonEl);
291
+
292
+ retakeButtonEl = document.createElement('button');
293
+ retakeButtonEl.id = 'veryfi-retake-button';
294
+ retakeButtonEl.textContent = 'Retake video';
295
+ Object.assign(retakeButtonEl.style, {
296
+ position: 'absolute',
297
+ bottom: '50px',
298
+ left: '50%',
299
+ transform: 'translateX(calc(-100% - 8px))',
300
+ width: '140px',
301
+ padding: '12px 0',
302
+ backgroundColor: 'rgba(255,255,255,0.15)',
303
+ color: 'white',
304
+ border: '1px solid rgba(255,255,255,0.4)',
305
+ borderRadius: '25px',
306
+ cursor: 'pointer',
307
+ fontSize: '14px',
308
+ fontFamily: "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
309
+ fontWeight: '600',
310
+ textAlign: 'center',
311
+ zIndex: '1000',
312
+ pointerEvents: 'auto',
313
+ });
314
+ retakeButtonEl.addEventListener('click', async () => {
315
+ cleanupPreview();
316
+ if (state.submitButton) {
317
+ state.submitButton.remove();
318
+ state.submitButton = null;
319
+ }
320
+ showVideoOverlay();
321
+ await newStartLens();
322
+ });
323
+ containerEl.appendChild(retakeButtonEl);
324
+ };
325
+
326
+ const submitVideoBlob = async (videoBlob) => {
327
+ state.updateHandler?.({ status: 'processing_started' });
328
+
329
+ const { default: JSZip } = await import('jszip');
330
+ const zip = new JSZip();
331
+
332
+ const ext = videoBlob.type.includes('mp4') ? 'mp4' : videoBlob.type.includes('quicktime') ? 'mov' : 'webm';
333
+ zip.file(`prescription_label.${ext}`, videoBlob);
334
+
335
+ const zipBase64 = await zip.generateAsync({ type: 'base64' });
336
+
337
+ state.finalImage = zipBase64;
338
+ state.updateHandler?.({ status: 'processing_completed' });
339
+
340
+ if (typeof state.customSubmitHandler === 'function') {
341
+ state.customSubmitHandler(zipBase64);
342
+ } else {
343
+ await handleSubmit(zipBase64);
344
+ }
345
+
346
+ state.updateHandler?.({ status: 'capture_completed' });
347
+ return zipBase64;
348
+ };
349
+
350
+ export const capturePrescriptionLabel = async () => {
351
+ try {
352
+ if (!isRecording) {
353
+ state.debug_mode && console.log('[EVENT] starting prescription label recording');
354
+ startRecording();
355
+ return null;
356
+ }
357
+
358
+ state.debug_mode && console.log('[EVENT] stopping prescription label recording');
359
+ state.updateHandler?.({ status: 'capture_started' });
360
+
361
+ const videoBlob = await stopRecording();
362
+ if (!videoBlob || videoBlob.size === 0) {
363
+ throw new Error('Failed to record video');
364
+ }
365
+
366
+ hideVideoOverlay();
367
+
368
+ if (state.videoRef?.srcObject) {
369
+ state.videoRef.srcObject.getTracks().forEach((track) => track.stop());
370
+ }
371
+
372
+ showVideoPreview(videoBlob);
373
+
374
+ state.submitButton = createSubmitButton(
375
+ state.container,
376
+ async () => {
377
+ await submitVideoBlob(videoBlob);
378
+ removeOverlay();
379
+ },
380
+ () => {}
381
+ );
382
+ const submitBtnEl = document.getElementById('veryfi-submit-button');
383
+ if (submitBtnEl) {
384
+ submitBtnEl.style.left = '50%';
385
+ submitBtnEl.style.transform = 'translateX(8px)';
386
+ submitBtnEl.style.width = '140px';
387
+ submitBtnEl.style.padding = '12px 0';
388
+ submitBtnEl.style.textAlign = 'center';
389
+ submitBtnEl.style.boxSizing = 'border-box';
390
+ }
391
+ state.submitButton.show();
392
+
393
+ state.resultSetter?.(videoBlob);
394
+
395
+ return null;
396
+ } catch (error) {
397
+ console.error('Prescription label capture failed:', error.message);
398
+ state.failureHandler?.(error);
399
+ state.updateHandler?.({ status: 'capture_failed' });
400
+ return null;
401
+ }
402
+ };
403
+
404
+ export const cleanupPrescriptionLabelRecording = () => {
405
+ if (mediaRecorder && isRecording) {
406
+ try {
407
+ mediaRecorder.stop();
408
+ } catch (e) {
409
+ // ignore
410
+ }
411
+ }
412
+ mediaRecorder = null;
413
+ recordedChunks = [];
414
+ isRecording = false;
415
+ updateRecordingUI(false);
416
+ cleanupPreview();
417
+ };
package/core/constants.js CHANGED
@@ -12,7 +12,7 @@ export const API_URLS = {
12
12
  };
13
13
 
14
14
  export const DEFAULTS = {
15
- SDK_VERSION: '3.0.2',
15
+ SDK_VERSION: '3.0.3',
16
16
  BLUR_THRESHOLD: 0.7,
17
17
  LCD_THRESHOLD: 0.5,
18
18
  BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
@@ -27,6 +27,8 @@ export const DEFAULTS = {
27
27
  CAP_CIRCLE_RADIUS: 0.7,
28
28
  RECT_WIDTH: 0.7,
29
29
  RECT_HEIGHT: 0.08,
30
+ PRESCRIPTION_LABEL_WIDTH: 0.55,
31
+ PRESCRIPTION_LABEL_HEIGHT: 0.65,
30
32
  EXPAND_FACTOR: 1.02,
31
33
  CROP_LAYOUT_OVERLAY_ALPHA: 0.6,
32
34
  CROP_LAYOUT_STROKE: 2,
@@ -53,6 +55,7 @@ export const MESSAGES = {
53
55
  WRONG_SIDE_FRONT: 'This looks like the back of the check. Please flip and capture the front side.',
54
56
  WRONG_SIDE_BACK: 'This looks like the front of the check. Please flip and capture the back side.',
55
57
  BOTTLE_CAP: 'Position bottle cap in circle',
58
+ PRESCRIPTION_LABEL: 'Position prescription label in outline',
56
59
  CODE_STRIPS: 'Position code strip in rectangle',
57
60
  CHECK_POSITION: 'Position check inside rectangle',
58
61
  ANYDOC_ADD_PAGE: 'Add Page',
package/core/lifecycle.js CHANGED
@@ -7,6 +7,7 @@ import { createSubmitButton } from '../components/submitButton.js';
7
7
  import { createLongPreview } from '../components/longPreview.js';
8
8
  import { createCheckOverlay } from '../components/checkOverlay.js';
9
9
  import { DEFAULTS } from './constants.js';
10
+ import { cleanupPrescriptionLabelRecording } from './capture/prescription_label.js';
10
11
 
11
12
  export const newStartLens = async () => {
12
13
  state.started = true;
@@ -68,7 +69,7 @@ export const newStartLens = async () => {
68
69
  ctx?.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
69
70
  }
70
71
 
71
- if (state.lensFlavor !== "caps" && state.lensFlavor !== "code_strips") {
72
+ if (state.lensFlavor !== "caps" && state.lensFlavor !== "code_strips" && state.lensFlavor !== "prescription_label") {
72
73
  await initializeWasmWrapper();
73
74
  }
74
75
 
@@ -119,6 +120,7 @@ export const newStartLens = async () => {
119
120
  break;
120
121
  case "caps":
121
122
  case "code_strips":
123
+ case "prescription_label":
122
124
  break;
123
125
  default:
124
126
  throw new Error(`Unknown lens flavor: ${state.lensFlavor}`);
@@ -130,7 +132,7 @@ export const newStartLens = async () => {
130
132
 
131
133
  requestAnimationFrame(displayVideo);
132
134
 
133
- if (state.lensFlavor !== "caps" && state.lensFlavor !== "code_strips" && state.lensFlavor !== "upload") {
135
+ if (state.lensFlavor !== "caps" && state.lensFlavor !== "code_strips" && state.lensFlavor !== "prescription_label" && state.lensFlavor !== "upload") {
134
136
  const processLoop = async () => {
135
137
  if (!state.started) return;
136
138
  state.lensFlavor === "credit_card" ? await sendCardWasm() : await sendWasm(state.lensFlavor);
@@ -219,6 +221,8 @@ export const removeOverlay = () => {
219
221
  state.anydocPageControls = null;
220
222
  }
221
223
 
224
+ cleanupPrescriptionLabelRecording();
225
+
222
226
  if (state.usingOverlayContainer) {
223
227
  stopLens();
224
228
  document.body.removeChild(state.container);
package/core/state.js CHANGED
@@ -181,6 +181,12 @@ export const state = {
181
181
 
182
182
  bottleCapOverlay: null,
183
183
 
184
+ prescriptionLabelOverlay: null,
185
+ prescriptionLabelWidthRatio: DEFAULTS.PRESCRIPTION_LABEL_WIDTH,
186
+ prescriptionLabelHeightRatio: DEFAULTS.PRESCRIPTION_LABEL_HEIGHT,
187
+ prescriptionLabelText: MESSAGES.PRESCRIPTION_LABEL,
188
+ preferredVideoFormat: null,
189
+
184
190
  codeStripsOverlay: null,
185
191
  rectWidth: DEFAULTS.RECT_WIDTH,
186
192
  rectHeight: DEFAULTS.RECT_HEIGHT,
@@ -287,6 +293,7 @@ export const resetState = () => {
287
293
  state.stitchingButton = null;
288
294
  state.checkImagesComponent = null;
289
295
  state.bottleCapOverlay = null;
296
+ state.prescriptionLabelOverlay = null;
290
297
  state.codeStripsOverlay = null;
291
298
  state.checkOverlay = null;
292
299
  state.isManualCheckCapture = false;
@@ -16,6 +16,7 @@ import { createWatermark } from '../components/watermark.js';
16
16
  import { createCardDataButton } from '../components/cardDataButton.js';
17
17
  import { createBottleCapOverlay } from '../components/bottleCapOverlay.js';
18
18
  import { createCodeStripsOverlay } from '../components/codeStripsOverlay.js';
19
+ import { createPrescriptionLabelOverlay } from '../components/prescriptionLabelOverlay.js';
19
20
 
20
21
  export const renderWatermarkIfNeeded = () => {
21
22
  if (state.clientData?.show_watermark) {
@@ -256,6 +257,17 @@ export const renderBottleCapOverlayIfNeeded = () => {
256
257
  });
257
258
  };
258
259
 
260
+ export const renderPrescriptionLabelOverlayIfNeeded = () => {
261
+ state.debug_mode && console.log("Rendering prescription label overlay");
262
+ setupVideoOverlayControls(() => actions.capturePrescriptionLabel());
263
+
264
+ createSpecialtyOverlayOnReady('prescriptionLabelOverlay', createPrescriptionLabelOverlay, {
265
+ bottleWidthRatio: state.prescriptionLabelWidthRatio,
266
+ bottleHeightRatio: state.prescriptionLabelHeightRatio,
267
+ instructionText: state.prescriptionLabelText
268
+ });
269
+ };
270
+
259
271
  export const renderCodeStripsOverlayIfNeeded = () => {
260
272
  state.debug_mode && console.log("Rendering code strips overlay");
261
273
  setupVideoOverlayControls(() => actions.captureCodeStrip());
@@ -0,0 +1,16 @@
1
+ import { renderPrescriptionLabelOverlayIfNeeded } from '../core/ui-renderer.js';
2
+ import { capturePrescriptionLabel } from '../core/capture/prescription_label.js';
3
+
4
+ export const setup = async (state, refs, actions) => {
5
+ actions.capturePrescriptionLabel = capturePrescriptionLabel;
6
+
7
+ if (!state.selectedBlueprint) {
8
+ state.selectedBlueprint = 'prescription_medication_label';
9
+ }
10
+ state.debug_mode && console.log('Using blueprint:', state.selectedBlueprint);
11
+ };
12
+
13
+ export const render = async (state, refs, actions) => {
14
+ state.debug_mode && console.log('Rendering UI elements for prescription_label');
15
+ renderPrescriptionLabelOverlayIfNeeded();
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
package/veryfi-lens.js CHANGED
@@ -35,7 +35,7 @@ const VeryfiLens = {
35
35
  }
36
36
  });
37
37
 
38
- if (config.lensFlavor !== "caps" && config.lensFlavor !== "code_strips") {
38
+ if (config.lensFlavor !== "caps" && config.lensFlavor !== "code_strips" && config.lensFlavor !== "prescription_label") {
39
39
  await initializeWasmWrapper();
40
40
  }
41
41
 
@@ -106,11 +106,11 @@ const VeryfiLens = {
106
106
  throw new Error('Failed to create core elements');
107
107
  }
108
108
 
109
- if (state.lensFlavor !== "caps" && state.lensFlavor !== "code_strips") {
109
+ if (state.lensFlavor !== "caps" && state.lensFlavor !== "code_strips" && state.lensFlavor !== "prescription_label") {
110
110
  await initializeWasmWrapper();
111
111
  }
112
112
 
113
- if ((state.lensFlavor === 'caps' || state.lensFlavor === 'code_strips') && !state.started) {
113
+ if ((state.lensFlavor === 'caps' || state.lensFlavor === 'code_strips' || state.lensFlavor === 'prescription_label') && !state.started) {
114
114
  state.debug_mode && console.log(`Starting lens for ${state.lensFlavor}`);
115
115
  await newStartLens();
116
116
  }
@@ -138,6 +138,9 @@ const VeryfiLens = {
138
138
  case 'code_strips':
139
139
  flavorModule = await import('./flavors/code_strips.js');
140
140
  break;
141
+ case 'prescription_label':
142
+ flavorModule = await import('./flavors/prescription_label.js');
143
+ break;
141
144
  case 'upload':
142
145
  flavorModule = await import('./flavors/upload.js');
143
146
  break;
@@ -151,7 +154,7 @@ const VeryfiLens = {
151
154
 
152
155
  await flavorModule.render(state, refs, actions);
153
156
 
154
- if (!state.started && state.lensFlavor !== 'caps' && state.lensFlavor !== 'code_strips') {
157
+ if (!state.started && state.lensFlavor !== 'caps' && state.lensFlavor !== 'code_strips' && state.lensFlavor !== 'prescription_label') {
155
158
  state.debug_mode && console.log("Starting lens");
156
159
  await newStartLens();
157
160
  }