veryfi-lens-wasm 3.5.13 → 3.6.0-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/README.md CHANGED
@@ -117,6 +117,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
117
117
  | `debug_mode` | `boolean` | `false` | Enable console logging |
118
118
  | `useDevApi` | `boolean` | `false` | Route API requests to `lens-dev.veryfi.com` instead of production |
119
119
  | `originalImageMaxSizeInMB` | `number` | — | Maximum size in MB for produced images (valid range `0.2`–`2.5`). Quality, then dimensions, are reduced until the JPEG fits. Unset or `0` means no size limit. Does not apply to recorded video |
120
+ | `softBinarizationIsOn` | `boolean` | `false` | Post-crop contrast filter for document crops (not checks), including cropped uploads: whitens the paper and stretches contrast so faint text reads better. Skipped for crops under 250 px or images that don't look like ink on paper |
120
121
  | `autoTagSource` | `boolean` | `false` | Tag the submitted document with its source (`LFB`) |
121
122
  | `autoTagDeviceId` | `boolean` | `false` | Tag the submitted document with the device ID (UUID) |
122
123
  | `autoTagLensVersion` | `boolean` | `false` | Tag the submitted document with the Lens version |
@@ -130,6 +131,9 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
130
131
  | `torchOnStart` | `boolean` | `true` | Turn torch on when camera starts |
131
132
  | `switchCameraButton` | `boolean` | `true` | Show switch camera (front/back) button |
132
133
  | `mirrorButton` | `boolean` | `true` | Show mirror/flip video button |
134
+ | `checksOrientationButton` | `boolean` | `true` | Checks on desktop (non-fullscreen): show the landscape/portrait camera view toggle |
135
+ | `checksRotateHint` | `boolean` | `true` | Checks on mobile: show an animated "rotate your device" hint while the phone is held upright in portrait. Hidden once the phone is turned sideways (also detected with auto-rotate off, via the motion sensor; on iOS only after the user grants motion access by tapping the hint) and when tapped. Font via `--checks-rotate-hint-font-family` (default: Roboto) |
136
+ | `cameraLoadingSpinner` | `boolean` | `true` | Show a spinner over the camera view while it has no video (camera starting, or switching between portrait and landscape). Color via `--video-loading-spinner-color` |
133
137
  | `mirrorOnDesktop` | `boolean` | `true` | Auto-mirror video on desktop (front-facing webcam) |
134
138
  | `exitButton` | `boolean` | `false` | Show exit/close button |
135
139
  | `watermarkPosition` | `string` | `"top-right"` | Corner for the "Powered by Veryfi" watermark (when enabled for the client): `"top-right"`, `"top-left"`, `"bottom-right"`, `"bottom-left"` |
@@ -152,6 +156,8 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
152
156
  | `enforceDocumentDetection` | `boolean` | `false` | Block submission if no document detected |
153
157
  | `enforceBlurDetection` | `boolean` | `false` | Block submission if image is blurry |
154
158
  | `enforceLcdDetection` | `boolean` | `false` | Block submission if screen capture detected |
159
+ | `validateDocumentCorners` | `boolean` | `false` | `document` / `anydocs` camera captures: re-detect the document on the captured frame and show `documentCornersModalMessage` with Try again when four corners are not found. Can be aggressive. Uploads skip it. Sends `document_corners_not_detected` to `onUpdate` |
160
+ | `allowSubmitDocumentCornersNotDetected` | `boolean` | `true` | Add an "I'm happy with it" button to the document corners modal that keeps the image |
155
161
  | `blurThreshold` | `number` | `0.7` | Blur detection threshold (0-1, higher = stricter) |
156
162
  | `lcdThreshold` | `number` | `0.4` | LCD detection threshold (0-1) |
157
163
 
@@ -167,7 +173,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
167
173
 
168
174
  | Option | Type | Default | Description |
169
175
  |---|---|---|---|
170
- | `autoDocumentCapture` | `boolean` | `false` | Enable hands-free automatic capture |
176
+ | `autoDocumentCapture` | `boolean` | `false` | Enable hands-free automatic capture (`document`, `anydocs`) |
171
177
 
172
178
  ### Check Capture Settings
173
179
 
@@ -178,12 +184,17 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
178
184
  | `enforceAndSkipBothSides` | `boolean` | `false` | Auto-proceed to back capture without prompt |
179
185
  | `delayBetweenCaptures` | `number` | `0` | Delay (ms) between front and back capture |
180
186
  | `frontBackDetectionForChecks` | `boolean` | `false` | Enable front/back side detection |
187
+ | `validateCheckCorners` | `boolean` | `false` | After a camera capture, re-detect the check on the captured frame and show `checkCornersModalMessage` with Try again when four corners are not found. Can be aggressive. Sends `check_corners_not_detected` to `onUpdate` |
188
+ | `allowSubmitCheckCornersNotDetected` | `boolean` | `true` | Add an "I'm happy with it" button to the check corners modal that keeps the image |
189
+ | `validateCheckSize` | `boolean` | `false` | Reject a cropped check smaller than the X9 minimum of 820×351 pixels with `checkSizeModalMessage`. The only action is Try again. Sends `check_too_far` (with `width`, `height`) to `onUpdate` |
181
190
  | `checksEnableManualMode` | `boolean` | `true` | Enable manual capture mode with guide overlay |
182
191
  | `checksManualModeTimeout` | `number` | `3000` | Timeout (ms) before switching to manual mode |
183
192
  | `checksCropMargin` | `number` | `0.1` | Margin around check crop (0.0-1.0) |
184
193
  | `cropMargin` | `number` | `0.0` | Margin around crop for all document types |
185
194
  | `persistManualModeOnRetake` | `boolean` | `true` | Keep manual mode when retaking front side |
186
195
  | `forceLandscapeCheckPreview` | `boolean` | `true` | Force horizontal display of check previews |
196
+ | `checksDesktopLandscape` | `boolean` | `true` | Checks on desktop (non-fullscreen): start with a landscape camera view; `false` starts in portrait |
197
+ | `checksSegmentationDetection` | `boolean` | `false` | Detect the check's corners in the live camera view with the checks segmentation model (the one used for the final crop) instead of the general document model. Applies only without auto-capture; until the model has downloaded, the general model is used |
187
198
 
188
199
  ### Check Crop Layout Appearance
189
200
 
@@ -196,7 +207,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
196
207
  | `cropLayoutCornerRadius` | `number` | `0` | Guide corner radius (px) |
197
208
  | `cropLayoutTipMessage` | `string` | `"Position check inside rectangle"` | Instruction text |
198
209
  | `cropLayoutTipPosition` | `string` | `"right"` | Tip text position: `"top"`, `"bottom"`, `"left"`, `"right"` |
199
- | `cropLayoutGuideTopPosition` | `string` | `"40%"` | Vertical position of guide |
210
+ | `cropLayoutGuideTopPosition` | `string` | `"40%"` portrait, `"50%"` landscape | Vertical position of the guide's centre |
200
211
  | `cropLayoutGuideLeftPosition` | `string` | `"50%"` | Horizontal position of guide |
201
212
  | `cropLayoutGuideWidthScale` | `number` | `0.90` | Guide width relative to video (0-1) |
202
213
  | `cropLayoutGuideMaxHeightScale` | `number` | `0.70` | Guide max height relative to video (0-1) |
@@ -318,6 +329,12 @@ When `multiSubmission` is set or `maxDocuments` is not `1`, `init()` asks the ba
318
329
  | `checkOptionalModalMessage` | `string` | `"Do you want to capture the back side of the check?"` |
319
330
  | `wrongSideFrontMessage` | `string` | `"This looks like the back of the check..."` |
320
331
  | `wrongSideBackMessage` | `string` | `"This looks like the front of the check..."` |
332
+ | `checkCornersModalMessage` | `string` | `"Check corners not detected. Please ensure all four corners of the check are visible"` |
333
+ | `documentCornersModalMessage` | `string` | `"Document corners not detected. Please ensure all four corners of the document are visible"` |
334
+ | `checkSizeModalMessage` | `string` | `"Check too far away. Please move the camera closer to the check while keeping the entire document in the frame"` |
335
+ | `tryAgainButtonText` | `string` | `"Try again"` |
336
+ | `keepImageButtonText` | `string` | `"I'm happy with it"` |
337
+ | `checksRotateHintText` | `string` | `"Rotate your device"` |
321
338
 
322
339
  ### Fingerprint Settings
323
340
 
@@ -27,18 +27,6 @@ export const createCaptureButton = (container, onCapture, onStopStitching) => {
27
27
  button.style[key] = value;
28
28
  });
29
29
 
30
- const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
31
- const isLandscape = window.innerWidth > window.innerHeight;
32
-
33
- if (isMobile && isLandscape) {
34
- button.style.right = '10px';
35
- button.style.top = 'calc(50vh - 2rem)';
36
- button.style.left = 'unset';
37
- button.style.bottom = 'unset';
38
- } else {
39
- // Apply default styles directly
40
- }
41
-
42
30
  // Set up CSS variables for customization
43
31
  Object.entries(defaultStyles).forEach(([key, value]) => {
44
32
  const cssVar = `--capture-button-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
@@ -7,7 +7,7 @@ export const createCheckOverlay = (container, options = {}) => {
7
7
  const instructionText = options.instructionText || "We could not detect a check, hope this will make it easier";
8
8
  const overlayAlpha = options.overlayAlpha !== undefined ? options.overlayAlpha : 0.6;
9
9
  const cornerRadius = options.cornerRadius !== undefined ? options.cornerRadius : 0;
10
- const guideTopPosition = options.guideTopPosition || "40%";
10
+ const guideTopFor = (isLandscape) => options.guideTopPosition || (isLandscape ? "50%" : "40%");
11
11
  const guideLeftPosition = options.guideLeftPosition || "50%";
12
12
  const guideWidthScale = options.guideWidthScale !== undefined ? options.guideWidthScale : 0.90;
13
13
  const guideMaxHeightScale = options.guideMaxHeightScale !== undefined ? options.guideMaxHeightScale : 0.70;
@@ -18,11 +18,11 @@ export const createCheckOverlay = (container, options = {}) => {
18
18
  const tipColor = options.tipColor || "var(--veryfi-panel-text, #1e293b)";
19
19
  const tipTextShadow = options.tipTextShadow || "none";
20
20
  const tipOffset = options.tipOffset || "35%";
21
+ const LANDSCAPE_TIP_INSET = "12px";
21
22
 
22
23
  const rectHole = document.createElement("div");
23
24
  rectHole.id = "veryfi-check-hole";
24
25
  rectHole.style.position = "absolute";
25
- rectHole.style.top = guideTopPosition;
26
26
  rectHole.style.left = guideLeftPosition;
27
27
  rectHole.style.transform = "translate(-50%, -50%)";
28
28
  rectHole.style.backgroundColor = "transparent";
@@ -34,7 +34,6 @@ export const createCheckOverlay = (container, options = {}) => {
34
34
  rectGuide.id = "veryfi-check-guide";
35
35
  Object.assign(rectGuide.style, {
36
36
  position: "absolute",
37
- top: guideTopPosition,
38
37
  left: guideLeftPosition,
39
38
  transform: "translate(-50%, -50%)",
40
39
  border: "none",
@@ -49,10 +48,6 @@ export const createCheckOverlay = (container, options = {}) => {
49
48
  micrLine.id = "veryfi-check-micr";
50
49
  Object.assign(micrLine.style, {
51
50
  position: "absolute",
52
- left: "5%",
53
- top: "3%",
54
- transform: "rotate(90deg)",
55
- transformOrigin: "left bottom",
56
51
  display: "flex",
57
52
  alignItems: "center",
58
53
  gap: "8px",
@@ -82,10 +77,6 @@ export const createCheckOverlay = (container, options = {}) => {
82
77
  micrLineBottom.id = "veryfi-check-micr-bottom";
83
78
  Object.assign(micrLineBottom.style, {
84
79
  position: "absolute",
85
- right: "15%",
86
- bottom: "8%",
87
- transform: "rotate(90deg)",
88
- transformOrigin: "right bottom",
89
80
  display: "flex",
90
81
  alignItems: "center",
91
82
  gap: "8px",
@@ -97,10 +88,6 @@ export const createCheckOverlay = (container, options = {}) => {
97
88
  const separatorLine = document.createElement("div");
98
89
  Object.assign(separatorLine.style, {
99
90
  position: "absolute",
100
- left: "15%",
101
- top: "5%",
102
- bottom: "5%",
103
- width: "1px",
104
91
  backgroundColor: "rgba(255, 255, 255, 0.35)",
105
92
  pointerEvents: "none",
106
93
  });
@@ -122,42 +109,70 @@ export const createCheckOverlay = (container, options = {}) => {
122
109
  borderRadius: "20px",
123
110
  });
124
111
 
125
- switch (tipPosition) {
126
- case "top":
127
- textLabel.style.bottom = "100%";
128
- textLabel.style.left = "50%";
129
- textLabel.style.transform = "translateX(-50%)";
130
- textLabel.style.marginBottom = tipOffset;
131
- break;
132
- case "bottom":
133
- textLabel.style.top = "100%";
134
- textLabel.style.left = "50%";
135
- textLabel.style.transform = "translateX(-50%)";
136
- textLabel.style.marginTop = tipOffset;
137
- break;
138
- case "left":
139
- textLabel.style.top = "50%";
140
- textLabel.style.left = "0";
141
- textLabel.style.transform = "translateY(-50%) translateX(-50%) rotate(90deg)";
142
- textLabel.style.marginLeft = tipOffset;
143
- break;
144
- case "right":
145
- default:
146
- textLabel.style.top = "50%";
147
- textLabel.style.right = "0";
148
- textLabel.style.transform = "translateY(-50%) translateX(50%) rotate(90deg)";
149
- textLabel.style.marginRight = tipOffset;
150
- break;
151
- }
112
+ const CLEAR_POSITION = {
113
+ top: "", bottom: "", left: "", right: "", transform: "", transformOrigin: "",
114
+ width: "", height: "", marginTop: "", marginBottom: "", marginLeft: "", marginRight: "",
115
+ };
116
+
117
+ // The portrait guide shows the check turned 90° clockwise (MICR line down the
118
+ // left edge); landscape shows it upright (MICR line along the bottom).
119
+ const DECORATION_LAYOUTS = {
120
+ portrait: {
121
+ micr: { left: "5%", top: "3%", transform: "rotate(90deg)", transformOrigin: "left bottom" },
122
+ micrBottom: { right: "15%", bottom: "8%", transform: "rotate(90deg)", transformOrigin: "right bottom" },
123
+ separator: { left: "15%", top: "5%", bottom: "5%", width: "1px" },
124
+ },
125
+ landscape: {
126
+ micr: { left: "3%", bottom: "5%" },
127
+ micrBottom: { right: "8%", top: "15%" },
128
+ separator: { left: "5%", right: "5%", bottom: "15%", height: "1px" },
129
+ },
130
+ };
131
+
132
+ const tipLayout = (isLandscape) => {
133
+ if (isLandscape) {
134
+ // The guide clips its content, so the tip stays inside it: the portrait
135
+ // right/left sides are the upright check's top/bottom.
136
+ return tipPosition === "bottom" || tipPosition === "left"
137
+ ? { bottom: `calc(15% + ${LANDSCAPE_TIP_INSET})`, left: "50%", transform: "translateX(-50%)" }
138
+ : { top: LANDSCAPE_TIP_INSET, left: "50%", transform: "translateX(-50%)" };
139
+ }
140
+ switch (tipPosition) {
141
+ case "top":
142
+ return { bottom: "100%", left: "50%", transform: "translateX(-50%)", marginBottom: tipOffset };
143
+ case "bottom":
144
+ return { top: "100%", left: "50%", transform: "translateX(-50%)", marginTop: tipOffset };
145
+ case "left":
146
+ return { top: "50%", left: "0", transform: "translateY(-50%) translateX(-50%) rotate(90deg)", marginLeft: tipOffset };
147
+ case "right":
148
+ default:
149
+ return { top: "50%", right: "0", transform: "translateY(-50%) translateX(50%) rotate(90deg)", marginRight: tipOffset };
150
+ }
151
+ };
152
+
153
+ let appliedLayout = null;
154
+ const applyOrientation = (isLandscape) => {
155
+ const layoutKey = isLandscape ? "landscape" : "portrait";
156
+ if (appliedLayout === layoutKey) return;
157
+ appliedLayout = layoutKey;
158
+ const layout = DECORATION_LAYOUTS[layoutKey];
159
+ Object.assign(micrLine.style, CLEAR_POSITION, layout.micr);
160
+ Object.assign(micrLineBottom.style, CLEAR_POSITION, layout.micrBottom);
161
+ Object.assign(separatorLine.style, CLEAR_POSITION, layout.separator);
162
+ Object.assign(textLabel.style, CLEAR_POSITION, tipLayout(isLandscape));
163
+ rectHole.style.top = guideTopFor(isLandscape);
164
+ rectGuide.style.top = guideTopFor(isLandscape);
165
+ };
152
166
 
153
167
  const calcRectDimensions = (videoRect) => {
154
168
  const aspectRatio = cropLayoutAspectRatio > 0 ? cropLayoutAspectRatio : 2.61;
169
+ const isLandscape = videoRect.width > videoRect.height;
155
170
  let rw = videoRect.width * guideWidthScale;
156
- let rh = rw * aspectRatio;
171
+ let rh = isLandscape ? rw / aspectRatio : rw * aspectRatio;
157
172
  const maxHeight = videoRect.height * guideMaxHeightScale;
158
173
  if (rh > maxHeight) {
159
174
  rh = maxHeight;
160
- rw = rh / aspectRatio;
175
+ rw = isLandscape ? rh * aspectRatio : rh / aspectRatio;
161
176
  }
162
177
  return { rw, rh };
163
178
  };
@@ -173,6 +188,7 @@ export const createCheckOverlay = (container, options = {}) => {
173
188
  rectGuide.appendChild(textLabel);
174
189
 
175
190
  return (videoRect) => {
191
+ applyOrientation(videoRect.width > videoRect.height);
176
192
  const { rw, rh } = calcRectDimensions(videoRect);
177
193
  rectHole.style.width = `${rw}px`;
178
194
  rectHole.style.height = `${rh}px`;
@@ -188,9 +204,16 @@ export const createCheckOverlay = (container, options = {}) => {
188
204
  const videoRect = videoElement.getBoundingClientRect();
189
205
  const { rw, rh } = calcRectDimensions(videoRect);
190
206
 
191
- const scaleX = videoElement.videoWidth / videoRect.width;
192
- const scaleY = videoElement.videoHeight / videoRect.height;
207
+ const vw = videoElement.videoWidth;
208
+ const vh = videoElement.videoHeight;
209
+ const fit = getComputedStyle(videoElement).objectFit;
210
+ const displayScale = fit === 'contain'
211
+ ? Math.min(videoRect.width / vw, videoRect.height / vh)
212
+ : Math.max(videoRect.width / vw, videoRect.height / vh);
213
+ const offsetX = (vw * displayScale - videoRect.width) / 2;
214
+ const offsetY = (vh * displayScale - videoRect.height) / 2;
193
215
 
216
+ const guideTopPosition = guideTopFor(videoRect.width > videoRect.height);
194
217
  let guideTopPercent = 0.40;
195
218
  if (guideTopPosition.endsWith('%')) {
196
219
  guideTopPercent = parseFloat(guideTopPosition) / 100;
@@ -198,10 +221,10 @@ export const createCheckOverlay = (container, options = {}) => {
198
221
  guideTopPercent = parseFloat(guideTopPosition) / videoRect.height;
199
222
  }
200
223
 
201
- const centerX = (videoRect.width / 2) * scaleX;
202
- const centerY = (videoRect.height * guideTopPercent) * scaleY;
203
- const rectWidthInVideo = rw * scaleX;
204
- const rectHeightInVideo = rh * scaleY;
224
+ const centerX = (videoRect.width / 2 + offsetX) / displayScale;
225
+ const centerY = (videoRect.height * guideTopPercent + offsetY) / displayScale;
226
+ const rectWidthInVideo = rw / displayScale;
227
+ const rectHeightInVideo = rh / displayScale;
205
228
 
206
229
  let baseCropX = centerX - (rectWidthInVideo / 2);
207
230
  let baseCropY = centerY - (rectHeightInVideo / 2);
@@ -0,0 +1,19 @@
1
+ import { createModal } from './modalBase.js';
2
+
3
+ export const createCheckSizeModal = (container, croppedImage, onRetake, options = {}) => {
4
+ const defaults = {
5
+ message: 'Check too far away. Please move the camera closer to the check while keeping the entire document in the frame',
6
+ tryAgainButtonText: 'Try again'
7
+ };
8
+ const o = { ...defaults, ...options };
9
+
10
+ return createModal(container, {
11
+ id: 'veryfi-check-size-modal',
12
+ cssPrefix: 'check-size-modal',
13
+ message: o.message,
14
+ primaryButtonText: o.tryAgainButtonText,
15
+ primaryButtonId: 'veryfi-retake-check-size',
16
+ onPrimaryClick: onRetake,
17
+ croppedImage,
18
+ });
19
+ };
@@ -0,0 +1,86 @@
1
+ import { LIQUID_GLASS, liquidGlassStyles } from './liquid-glass.js';
2
+
3
+ const LANDSCAPE_ICON = `
4
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width: 20px; height: 20px;">
5
+ <rect x="3" y="7" width="18" height="10" rx="2"/>
6
+ </svg>
7
+ `;
8
+
9
+ const PORTRAIT_ICON = `
10
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width: 20px; height: 20px;">
11
+ <rect x="7" y="3" width="10" height="18" rx="2"/>
12
+ </svg>
13
+ `;
14
+
15
+ export const createChecksOrientationButton = (container, { initialLandscape = true, onToggle } = {}) => {
16
+ const button = document.createElement('button');
17
+ button.id = 'veryfi-checks-orientation-button';
18
+
19
+ const defaultStyles = {
20
+ width: '40px',
21
+ height: '40px',
22
+ color: '#FFFFFF',
23
+ borderRadius: '50%',
24
+ position: 'absolute',
25
+ bottom: '50px',
26
+ right: '115px',
27
+ zIndex: '1000',
28
+ display: 'flex',
29
+ alignItems: 'center',
30
+ justifyContent: 'center',
31
+ padding: '0',
32
+ cursor: 'pointer',
33
+ pointerEvents: 'auto',
34
+ outline: 'none',
35
+ boxSizing: 'border-box',
36
+ margin: '0',
37
+ minWidth: '40px',
38
+ minHeight: '40px',
39
+ maxWidth: '40px',
40
+ maxHeight: '40px',
41
+ transition: 'background-color 0.3s ease, box-shadow 0.3s ease',
42
+ ...liquidGlassStyles(),
43
+ };
44
+
45
+ Object.entries(defaultStyles).forEach(([key, value]) => {
46
+ button.style[key] = value;
47
+ });
48
+
49
+ const setLandscape = (isLandscape) => {
50
+ button.innerHTML = isLandscape ? LANDSCAPE_ICON : PORTRAIT_ICON;
51
+ const label = isLandscape ? 'Switch to portrait view' : 'Switch to landscape view';
52
+ button.title = label;
53
+ button.setAttribute('aria-label', label);
54
+ };
55
+
56
+ button.addEventListener('mouseover', () => {
57
+ button.style.backgroundColor = LIQUID_GLASS.hoverBackgroundColor;
58
+ });
59
+ button.addEventListener('mouseout', () => {
60
+ button.style.backgroundColor = LIQUID_GLASS.backgroundColor;
61
+ });
62
+
63
+ button.addEventListener('click', () => {
64
+ const isLandscape = onToggle?.();
65
+ if (typeof isLandscape === 'boolean') setLandscape(isLandscape);
66
+ });
67
+
68
+ setLandscape(initialLandscape);
69
+ container.appendChild(button);
70
+
71
+ return {
72
+ show: () => {
73
+ button.style.display = 'flex';
74
+ },
75
+ hide: () => {
76
+ button.style.display = 'none';
77
+ },
78
+ remove: () => {
79
+ if (button.parentNode) {
80
+ button.parentNode.removeChild(button);
81
+ }
82
+ },
83
+ setLandscape,
84
+ button: button,
85
+ };
86
+ };
@@ -0,0 +1,203 @@
1
+ import { liquidGlassStyles } from './liquid-glass.js';
2
+ import { visibleVideoCenter } from './shared-styles.js';
3
+
4
+ const STYLE_ID = 'veryfi-checks-rotate-hint-styles';
5
+
6
+ // Gravity (m/s²) needed in the screen plane before the phone's orientation is
7
+ // trusted; held flatter than this (e.g. over a check on a table) the last
8
+ // reading is kept.
9
+ const MIN_TILT = 3;
10
+ // One axis must exceed the other by this factor to switch orientation, so the
11
+ // hint doesn't flicker when the phone is held near 45°.
12
+ const SWITCH_RATIO = 1.3;
13
+
14
+ const ROTATE_ICON = `
15
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" style="width: 96px; height: 96px;">
16
+ <path d="M12.4 36.3 A40 40 0 0 1 56.9 10.6" />
17
+ <polyline points="19.8,31.1 12.4,36.3 10.1,27.6" />
18
+ <path d="M87.6 63.7 A40 40 0 0 1 43.1 89.4" />
19
+ <polyline points="80.2,68.9 87.6,63.7 89.9,72.4" />
20
+ <g class="veryfi-checks-rotate-hint-phone">
21
+ <rect x="38" y="28" width="24" height="44" rx="5" />
22
+ <line x1="46" y1="33" x2="54" y2="33" />
23
+ </g>
24
+ </svg>
25
+ `;
26
+
27
+ const CLOSE_ICON = `
28
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" style="width: 14px; height: 14px;">
29
+ <path d="M18 6 6 18" />
30
+ <path d="m6 6 12 12" />
31
+ </svg>
32
+ `;
33
+
34
+ const ensureStyles = () => {
35
+ if (document.getElementById(STYLE_ID)) return;
36
+ const style = document.createElement('style');
37
+ style.id = STYLE_ID;
38
+ style.textContent = `
39
+ @keyframes veryfi-checks-rotate-hint {
40
+ 0%, 15% { transform: rotate(0deg); }
41
+ 45%, 70% { transform: rotate(-90deg); }
42
+ 100% { transform: rotate(0deg); }
43
+ }
44
+ .veryfi-checks-rotate-hint-phone {
45
+ transform-origin: 50px 50px;
46
+ animation: veryfi-checks-rotate-hint 2.4s ease-in-out infinite;
47
+ }
48
+ `;
49
+ document.head.appendChild(style);
50
+ };
51
+
52
+ // Asks the user to turn the phone sideways while the camera view is portrait
53
+ // (the portrait check guide is upright). Hidden once the view turns landscape,
54
+ // or, with auto-rotate off, once the motion sensor reports the phone is held
55
+ // sideways. Tapping it dismisses it.
56
+ export const createChecksRotateHint = (container, videoElement, { text } = {}) => {
57
+ ensureStyles();
58
+
59
+ const hint = document.createElement('div');
60
+ hint.id = 'veryfi-checks-rotate-hint';
61
+ hint.setAttribute('role', 'status');
62
+ hint.innerHTML = ROTATE_ICON;
63
+
64
+ const label = document.createElement('div');
65
+ label.textContent = text;
66
+ Object.assign(label.style, {
67
+ fontFamily: 'var(--checks-rotate-hint-font-family, Roboto, sans-serif)',
68
+ fontSize: '15px',
69
+ fontWeight: '600',
70
+ textAlign: 'center',
71
+ });
72
+ hint.appendChild(label);
73
+
74
+ // Dismissal is handled by the click listener on the whole hint.
75
+ const close = document.createElement('button');
76
+ close.type = 'button';
77
+ close.setAttribute('aria-label', 'Dismiss');
78
+ close.innerHTML = CLOSE_ICON;
79
+ Object.assign(close.style, {
80
+ position: 'absolute',
81
+ top: '6px',
82
+ right: '6px',
83
+ width: '24px',
84
+ height: '24px',
85
+ padding: '0',
86
+ display: 'flex',
87
+ alignItems: 'center',
88
+ justifyContent: 'center',
89
+ border: 'none',
90
+ borderRadius: '50%',
91
+ background: 'transparent',
92
+ color: 'rgba(255, 255, 255, 0.8)',
93
+ cursor: 'pointer',
94
+ });
95
+ hint.appendChild(close);
96
+
97
+ Object.assign(hint.style, {
98
+ position: 'fixed',
99
+ transform: 'translate(-50%, -50%)',
100
+ zIndex: '1100',
101
+ display: 'none',
102
+ flexDirection: 'column',
103
+ alignItems: 'center',
104
+ gap: '8px',
105
+ padding: '16px 24px',
106
+ maxWidth: '70vw',
107
+ boxSizing: 'border-box',
108
+ borderRadius: '16px',
109
+ color: 'white',
110
+ cursor: 'pointer',
111
+ pointerEvents: 'auto',
112
+ ...liquidGlassStyles(),
113
+ });
114
+ container.appendChild(hint);
115
+
116
+ let active = true;
117
+ let dismissed = false;
118
+ let heldSideways = false;
119
+
120
+ const update = () => {
121
+ // The container is emptied on teardown without calling remove()
122
+ if (!hint.isConnected) {
123
+ cleanup();
124
+ return;
125
+ }
126
+ const visible = active && !dismissed && !heldSideways &&
127
+ container.dataset.checksDesktop !== 'true' &&
128
+ window.matchMedia('(pointer: coarse)').matches &&
129
+ window.innerHeight > window.innerWidth &&
130
+ videoElement.style.display !== 'none';
131
+ if (visible) {
132
+ const { x, y } = visibleVideoCenter(videoElement);
133
+ hint.style.left = `${x}px`;
134
+ hint.style.top = `${y}px`;
135
+ }
136
+ hint.style.display = visible ? 'flex' : 'none';
137
+ };
138
+
139
+ // accelerationIncludingGravity is in device coordinates, so it reports the
140
+ // phone held sideways even when auto-rotate keeps the page in portrait.
141
+ const onMotion = (e) => {
142
+ const g = e.accelerationIncludingGravity;
143
+ if (!g || g.x == null || g.y == null) return;
144
+ const x = Math.abs(g.x);
145
+ const y = Math.abs(g.y);
146
+ if (Math.max(x, y) < MIN_TILT) return;
147
+ const sideways = heldSideways ? y <= x * SWITCH_RATIO : x > y * SWITCH_RATIO;
148
+ if (sideways !== heldSideways) {
149
+ heldSideways = sideways;
150
+ update();
151
+ }
152
+ };
153
+
154
+ const listenForMotion = () => window.addEventListener('devicemotion', onMotion);
155
+
156
+ // iOS only delivers motion events after DeviceMotionEvent.requestPermission(),
157
+ // which must run in a user gesture (it resolves without a prompt once granted).
158
+ const needsMotionPermission = typeof window.DeviceMotionEvent?.requestPermission === 'function';
159
+ const requestMotionPermission = () => {
160
+ window.DeviceMotionEvent.requestPermission()
161
+ .then((result) => {
162
+ if (result === 'granted') listenForMotion();
163
+ })
164
+ .catch(() => {});
165
+ };
166
+
167
+ if (needsMotionPermission) {
168
+ requestMotionPermission();
169
+ } else if (window.DeviceMotionEvent) {
170
+ listenForMotion();
171
+ }
172
+
173
+ hint.addEventListener('click', () => {
174
+ if (needsMotionPermission) requestMotionPermission();
175
+ dismissed = true;
176
+ update();
177
+ });
178
+
179
+ const cleanup = () => {
180
+ window.removeEventListener('devicemotion', onMotion);
181
+ window.removeEventListener('resize', update);
182
+ container.removeEventListener('veryfi-layout-change', update);
183
+ };
184
+
185
+ window.addEventListener('resize', update);
186
+ container.addEventListener('veryfi-layout-change', update);
187
+ update();
188
+
189
+ return {
190
+ show: () => {
191
+ active = true;
192
+ update();
193
+ },
194
+ hide: () => {
195
+ active = false;
196
+ update();
197
+ },
198
+ remove: () => {
199
+ cleanup();
200
+ hint.remove();
201
+ },
202
+ };
203
+ };
@@ -0,0 +1,24 @@
1
+ import { createModal } from './modalBase.js';
2
+
3
+ export const createCornersModal = (container, croppedImage, onRetake, onKeep, options = {}) => {
4
+ const defaults = {
5
+ message: 'Document corners not detected. Please ensure all four corners of the document are visible',
6
+ tryAgainButtonText: 'Try again',
7
+ keepImageButtonText: "I'm happy with it",
8
+ allowKeep: true
9
+ };
10
+ const o = { ...defaults, ...options };
11
+
12
+ return createModal(container, {
13
+ id: 'veryfi-corners-modal',
14
+ cssPrefix: 'corners-modal',
15
+ message: o.message,
16
+ primaryButtonText: o.tryAgainButtonText,
17
+ primaryButtonId: 'veryfi-retake-corners',
18
+ secondaryButtonText: o.allowKeep ? o.keepImageButtonText : null,
19
+ secondaryButtonId: 'veryfi-keep-corners',
20
+ onPrimaryClick: onRetake,
21
+ onSecondaryClick: onKeep,
22
+ croppedImage,
23
+ });
24
+ };
@@ -260,6 +260,11 @@ const evaluate = () => {
260
260
  }
261
261
  };
262
262
 
263
+ // Touch input can come and go without a resize (e.g. DevTools device mode
264
+ // turning touch emulation off after the viewport has already widened).
265
+ const INPUT_MEDIA_QUERIES = ['(pointer: coarse)', '(hover: none)', '(any-pointer: coarse)', '(any-hover: none)'];
266
+ let inputMediaLists = [];
267
+
263
268
  export const installDesktopModeWatchdog = () => {
264
269
  if (typeof window === 'undefined' || typeof document === 'undefined') return;
265
270
  isDismissed = false;
@@ -267,6 +272,10 @@ export const installDesktopModeWatchdog = () => {
267
272
  installed = true;
268
273
  window.addEventListener('resize', evaluate);
269
274
  window.addEventListener('orientationchange', evaluate);
275
+ if (typeof window.matchMedia === 'function') {
276
+ inputMediaLists = INPUT_MEDIA_QUERIES.map((query) => window.matchMedia(query));
277
+ inputMediaLists.forEach((list) => list.addEventListener?.('change', evaluate));
278
+ }
270
279
  }
271
280
  evaluate();
272
281
  if (isActive) attachModal();
@@ -277,6 +286,8 @@ export const uninstallDesktopModeWatchdog = () => {
277
286
  if (installed) {
278
287
  window.removeEventListener('resize', evaluate);
279
288
  window.removeEventListener('orientationchange', evaluate);
289
+ inputMediaLists.forEach((list) => list.removeEventListener?.('change', evaluate));
290
+ inputMediaLists = [];
280
291
  installed = false;
281
292
  }
282
293
  if (isActive) {