veryfi-lens-wasm 3.5.6 → 3.5.8

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
@@ -111,7 +111,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
111
111
  | `lensFlavor` | `string` | — | **Required.** Capture mode (see [Supported Flavors](#supported-flavors)) |
112
112
  | `container` | `string` | — | ID of an HTML element to render into. If omitted, creates a fullscreen overlay |
113
113
  | `theme` | `"light"\|"dark"\|"system"` | `"system"` | UI color theme. `"system"` follows OS changes while the lens is open |
114
- | `enableSubmit` | `boolean` | `true` | Show submit button after capture |
114
+ | `enableSubmit` | `boolean` | `true` | Show submit button after capture. With `false` (and `packageMode: false`) the review gallery's Submit uploads nothing: it fires the `showCamera` setter (checks: `{ frontImage, backImage, ...per-side LCD / front-back results }`; other flavors: `{ image }`), or calls `customSubmitHandler(image, null)` when set, then closes |
115
115
  | `enableFullScreen` | `boolean` | `false` | Enable fullscreen mode |
116
116
  | `debug_mode` | `boolean` | `false` | Enable console logging |
117
117
  | `useDevApi` | `boolean` | `false` | Route API requests to `lens-dev.veryfi.com` instead of production |
@@ -170,7 +170,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
170
170
  | Option | Type | Default | Description |
171
171
  |---|---|---|---|
172
172
  | `captureBackOfCheck` | `boolean` | `false` | Enable back side capture |
173
- | `enforceBothSides` | `boolean` | `false` | Require both sides |
173
+ | `enforceBothSides` | `boolean` | `false` | Require both sides. After the front, shows `checkEnforcedModalMessage` with a Continue button that opens the camera for the back |
174
174
  | `enforceAndSkipBothSides` | `boolean` | `false` | Auto-proceed to back capture without prompt |
175
175
  | `delayBetweenCaptures` | `number` | `0` | Delay (ms) between front and back capture |
176
176
  | `frontBackDetectionForChecks` | `boolean` | `false` | Enable front/back side detection |
@@ -221,6 +221,9 @@ When `multiSubmission` is set or `maxDocuments` is not `1`, `init()` asks the ba
221
221
  | `reviewRetakeText` | `string` | `"Retake"` | Retake action text |
222
222
  | `reviewDeleteText` | `string` | `"Delete"` | Delete action text |
223
223
  | `reviewShowQualityBadges` | `boolean` | `true` | Badge pages that failed a quality check. Applies to multi-document frames, which are committed with the failing pages flagged instead of blocked |
224
+ | `reviewDownloadButton` | `boolean` | `true` | Show the Download action on the page toolbar |
225
+ | `reviewRotateButton` | `boolean` | `true` | Show the Rotate action on the page toolbar (images only) |
226
+ | `reviewCropButton` | `boolean` | `true` | Show the Crop action on the page toolbar (images only) |
224
227
  | `reviewIssueBlurText` | `string` | `"Blurry"` | Badge text for a blurry page |
225
228
  | `reviewIssueLcdText` | `string` | `"Screen"` | Badge text for a screen/LCD page |
226
229
  | `reviewSubmitButtonColor` | `string` | `"#00AA00"` | Submit button color (also used as the crop editor accent) |
@@ -96,11 +96,15 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
96
96
  submitButtonTextColor: options.submitButtonTextColor || '#FFFFFF',
97
97
  imageQuality: options.imageQuality || 0.97,
98
98
  pageAspectRatio: options.pageAspectRatio || '3 / 4',
99
+ pageObjectFit: options.pageObjectFit || 'cover',
99
100
  stackedPages: options.stackedPages === true,
100
101
  pageLabels: Array.isArray(options.pageLabels) ? options.pageLabels : null,
101
102
  allowAddPage: options.allowAddPage !== false,
102
103
  allowAddDocument: options.allowAddDocument !== false,
103
104
  showQualityBadges: options.showQualityBadges !== false,
105
+ showDownload: options.showDownload !== false,
106
+ showRotate: options.showRotate !== false,
107
+ showCrop: options.showCrop !== false,
104
108
  issueLabels: options.issueLabels || { blur: 'Blurry', lcd: 'Screen' },
105
109
  showDocumentStrip: options.showDocumentStrip !== false,
106
110
  showClose: options.showClose !== false,
@@ -994,7 +998,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
994
998
  justifyContent: 'stretch',
995
999
  cursor: 'pointer',
996
1000
  });
997
- const thumb = buildPageThumb(page, { objectFit: 'cover', borderRadius: '0' });
1001
+ const thumb = buildPageThumb(page, { objectFit: o.pageObjectFit, borderRadius: '0' });
998
1002
  thumb.style.pointerEvents = 'none';
999
1003
  if (thumb.tagName === 'VIDEO') thumb.controls = false;
1000
1004
  cell.appendChild(thumb);
@@ -1070,19 +1074,25 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
1070
1074
  if (!page) return;
1071
1075
 
1072
1076
  if (page.kind !== 'video') {
1073
- topBarRight.appendChild(
1074
- toolButton('rotate-cw', o.rotateText, async () => {
1075
- const data = await rotateImageData(page.data);
1076
- callbacks.onEditPage?.(activeIndex, detailIndex, data);
1077
- })
1078
- );
1079
- topBarRight.appendChild(
1080
- toolButton('crop', o.cropText, () =>
1081
- openCropEditor(page, (data) => callbacks.onEditPage?.(activeIndex, detailIndex, data))
1082
- )
1083
- );
1077
+ if (o.showRotate) {
1078
+ topBarRight.appendChild(
1079
+ toolButton('rotate-cw', o.rotateText, async () => {
1080
+ const data = await rotateImageData(page.data);
1081
+ callbacks.onEditPage?.(activeIndex, detailIndex, data);
1082
+ })
1083
+ );
1084
+ }
1085
+ if (o.showCrop) {
1086
+ topBarRight.appendChild(
1087
+ toolButton('crop', o.cropText, () =>
1088
+ openCropEditor(page, (data) => callbacks.onEditPage?.(activeIndex, detailIndex, data))
1089
+ )
1090
+ );
1091
+ }
1092
+ }
1093
+ if (o.showDownload) {
1094
+ topBarRight.appendChild(toolButton('download', o.downloadText, () => downloadPage(page)));
1084
1095
  }
1085
- topBarRight.appendChild(toolButton('download', o.downloadText, () => downloadPage(page)));
1086
1096
  topBarRight.appendChild(
1087
1097
  toolButton('refresh-cw', o.retakeText, () => callbacks.onRetakePage?.(activeIndex, detailIndex))
1088
1098
  );
@@ -1225,6 +1235,10 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
1225
1235
  }
1226
1236
  },
1227
1237
  isSubmitting: () => submitting,
1238
+ setSubmitEnabled: (enabled) => {
1239
+ if (submitting) return;
1240
+ submitButton.disabled = !enabled;
1241
+ },
1228
1242
  updateSubmitMessage: (message) => {
1229
1243
  if (loadingMessageEl) loadingMessageEl.textContent = message;
1230
1244
  },
@@ -2,7 +2,7 @@ import { state, refs } from '../state.js';
2
2
  import { cropWasm } from '../wasm-processing.js';
3
3
  import { checkIfDocumentOnCapture, checkIfBlurOnCapture, checkIfLcdOnCapture } from '../validation.js';
4
4
  import { showVideoOverlay } from '../overlay-controls.js';
5
- import { restartCameraForNextCapture } from '../lifecycle.js';
5
+ import { restartCameraForNextCapture, stopLens } from '../lifecycle.js';
6
6
  import * as store from '../capture-store.js';
7
7
  const syncCapturingSide = () => {
8
8
  if (state.recaptureTarget) {
@@ -54,6 +54,7 @@ export const captureChecks = async () => {
54
54
  state.frontImage = await cropWasm(state.testBlurDetection);
55
55
  }
56
56
  state.finalImage = state.frontImage;
57
+ stopLens();
57
58
 
58
59
  if (state.videoRef) state.videoRef.style.display = 'none';
59
60
  if (state.boxRef) state.boxRef.style.display = 'none';
@@ -145,6 +146,7 @@ export const captureChecks = async () => {
145
146
  state.backImage = await cropWasm(state.testBlurDetection);
146
147
  }
147
148
  state.finalImage = state.backImage;
149
+ stopLens();
148
150
 
149
151
  state.debug_mode && console.log("Back capture - Document detected:", state.isDocument);
150
152
  const isDocumentDetected = checkIfDocumentOnCapture();
@@ -184,9 +184,12 @@ export const newCapture = async () => {
184
184
  }
185
185
  break;
186
186
  case "checks": {
187
+ // captureChecks owns the whole checks capture (stop, validation, commit).
188
+ // It can restart the camera for the back side before returning, so the
189
+ // shared post-capture steps below must not run for checks.
187
190
  const { captureChecks } = await import('./checks.js');
188
191
  await captureChecks();
189
- break;
192
+ return null;
190
193
  }
191
194
  default:
192
195
  if (state.fullSizeImage && state.fullSizeImage.close) {
package/core/constants.js CHANGED
@@ -39,7 +39,7 @@ export const setApiBaseUrl = (base) => {
39
39
  };
40
40
 
41
41
  export const DEFAULTS = {
42
- SDK_VERSION: '3.5.6',
42
+ SDK_VERSION: '3.5.8',
43
43
  BLUR_THRESHOLD: 0.7,
44
44
  LCD_THRESHOLD: 0.5,
45
45
  BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
package/core/drawing.js CHANGED
@@ -151,9 +151,10 @@ export const drawContours = (input) => {
151
151
  ctx.restore();
152
152
 
153
153
  // Capture uses the first quad's true corners; the overlay keeps all quads
154
- // for multi-doc redraw.
154
+ // for multi-doc redraw. Store them unexpanded so a redraw doesn't
155
+ // re-expand the previous frame's box.
155
156
  setCoordinates(first);
156
- state.allCoordinates = expanded;
157
+ state.allCoordinates = quads;
157
158
  setHasCoordinates(true);
158
159
  } else {
159
160
  ctx.clearRect(0, 0, BoxCanvas.width, BoxCanvas.height);
@@ -29,6 +29,10 @@ import * as store from './capture-store.js';
29
29
  const isPartnerDriven = () =>
30
30
  state.packageMode && !state.enableSubmit && typeof state.customSubmitHandler !== 'function';
31
31
 
32
+ // enableSubmit:false without packageMode: the partner uploads the captures
33
+ // itself, so Submit only hands them over and nothing is sent to Veryfi.
34
+ const isLocalOnlySubmit = () => !state.enableSubmit && !state.packageMode;
35
+
32
36
  // Flavors that need a custom camera re-entry (restore their overlay/guide) set
33
37
  // actions.reviewRestart / actions.nextDocKind. Defaults suit the document flavor.
34
38
  const restartCamera = async () => {
@@ -62,6 +66,9 @@ const galleryOptions = () => ({
62
66
  submitButtonTextColor: state.reviewSubmitButtonTextColor || DEFAULTS.SUBMIT_BUTTON_TEXT_COLOR,
63
67
  imageQuality: state.imageQuality || DEFAULTS.IMAGE_QUALITY,
64
68
  showQualityBadges: state.reviewShowQualityBadges,
69
+ showDownload: state.reviewDownloadButton,
70
+ showRotate: state.reviewRotateButton,
71
+ showCrop: state.reviewCropButton,
65
72
  issueLabels: {
66
73
  blur: state.reviewIssueBlurText,
67
74
  lcd: state.reviewIssueLcdText,
@@ -75,6 +82,7 @@ const galleryOptions = () => ({
75
82
  ...(state.lensFlavor === 'checks' ? {
76
83
  stackedPages: true,
77
84
  pageAspectRatio: `${DEFAULTS.CHECK_ASPECT_RATIO} / 1`,
85
+ pageObjectFit: 'contain',
78
86
  pageLabels: ['Front', 'Back'],
79
87
  } : {}),
80
88
  });
@@ -92,7 +100,7 @@ const applyChecksSubmitGate = () => {
92
100
  if (state.lensFlavor !== 'checks') return;
93
101
  const bothRequired = state.enforceBothSides || state.enforceAndSkipBothSides;
94
102
  if (bothRequired && store.totalPages() < 2) {
95
- state.reviewGalleryRef?.setSubmitting(true);
103
+ state.reviewGalleryRef?.setSubmitEnabled(false);
96
104
  }
97
105
  };
98
106
 
@@ -106,7 +114,7 @@ const isAnydocTwoPageFlip = () =>
106
114
  const applyAnydocFlipSubmitGate = () => {
107
115
  if (!isAnydocTwoPageFlip()) return;
108
116
  if ((store.getActiveDoc()?.pages?.length || 0) < 2) {
109
- state.reviewGalleryRef?.setSubmitting(true);
117
+ state.reviewGalleryRef?.setSubmitEnabled(false);
110
118
  }
111
119
  };
112
120
 
@@ -128,6 +136,16 @@ const shouldAutoAdvanceCheckBack = () => {
128
136
  return (doc?.pages?.length || 0) === 1;
129
137
  };
130
138
 
139
+ // enforceBothSides: once the front is accepted, prompt to flip the check
140
+ // (checkEnforcedModalMessage) and reopen the camera for the back.
141
+ const shouldPromptCheckFlip = () => {
142
+ if (state.lensFlavor !== 'checks') return false;
143
+ if (!state.enforceBothSides) return false;
144
+ if (state.recaptureTarget) return false;
145
+ const doc = store.getActiveDoc();
146
+ return (doc?.pages?.length || 0) === 1;
147
+ };
148
+
131
149
  // Anydocs with anydocShowFlipMessage and a 2-page cap: after the first page,
132
150
  // skip the gallery and prompt to flip, then reopen the camera for page 2.
133
151
  const shouldAutoAdvanceAnydocBack = () => {
@@ -137,21 +155,27 @@ const shouldAutoAdvanceAnydocBack = () => {
137
155
  return (doc?.pages?.length || 0) === 1;
138
156
  };
139
157
 
140
- const promptAnydocFlip = () => {
141
- state.updateHandler?.({ status: 'anydoc_flip_prompted' });
142
- if (state.anydocFlipModal) {
143
- state.anydocFlipModal.show();
158
+ const promptFlip = (modal, status) => {
159
+ state.updateHandler?.({ status });
160
+ if (modal) {
161
+ modal.show();
144
162
  return;
145
163
  }
146
164
  goToCamera();
147
165
  };
148
166
 
149
- export const continueAnydocFlip = async () => {
150
- state.anydocFlipModal?.hide();
151
- state.updateHandler?.({ status: 'anydoc_flip_continued' });
167
+ const continueFlip = async (modal, status) => {
168
+ modal?.hide();
169
+ state.updateHandler?.({ status });
152
170
  await goToCamera();
153
171
  };
154
172
 
173
+ export const continueAnydocFlip = () =>
174
+ continueFlip(state.anydocFlipModal, 'anydoc_flip_continued');
175
+
176
+ export const continueCheckFlip = () =>
177
+ continueFlip(state.checkFlipModal, 'capture_back_side_required');
178
+
155
179
  const closeReview = () => {
156
180
  if (typeof state.onClose === 'function') state.onClose(false);
157
181
  if (state.onCloseRedirectUrl) window.location.href = state.onCloseRedirectUrl;
@@ -225,6 +249,25 @@ const submitOneDocument = async (docIndex) => {
225
249
  });
226
250
  }
227
251
 
252
+ // Checks preserve their legacy setter contract: a single payload keyed by
253
+ // front/back (images + per-side LCD and front/back-detection results). The
254
+ // front image is what partner handlers receive (parity with the pre-gallery
255
+ // handleChecksBackAccepted path).
256
+ const isChecks = state.lensFlavor === 'checks';
257
+ const checksExtra = isChecks ? buildChecksExtra(doc) : null;
258
+ const setterImage = isChecks ? (doc.pages[0]?.data ?? null) : image;
259
+
260
+ if (isLocalOnlySubmit()) {
261
+ const hasHandler = typeof state.customSubmitHandler === 'function';
262
+ if (isChecks) {
263
+ state.resultSetter?.(checksExtra);
264
+ } else if (!hasHandler) {
265
+ state.resultSetter?.({ image: originalData });
266
+ }
267
+ if (hasHandler) state.customSubmitHandler(setterImage, null);
268
+ return null;
269
+ }
270
+
228
271
  // Rebuild the per-document package buffer from the store so deletes/retakes
229
272
  // are reflected, and give each document its own package identity.
230
273
  if (state.packageMode) {
@@ -243,14 +286,6 @@ const submitOneDocument = async (docIndex) => {
243
286
  }
244
287
  }
245
288
 
246
- // Checks preserve their legacy setter contract: a single payload keyed by
247
- // front/back (images + per-side LCD and front/back-detection results). The
248
- // front image is what partner handlers receive (parity with the pre-gallery
249
- // handleChecksBackAccepted path).
250
- const isChecks = state.lensFlavor === 'checks';
251
- const checksExtra = isChecks ? buildChecksExtra(doc) : null;
252
- const setterImage = isChecks ? (doc.pages[0]?.data ?? null) : image;
253
-
254
289
  if (isPartnerDriven()) {
255
290
  const packageInfo = await ensurePackageUploaded();
256
291
  state.resultSetter?.({ ...(packageInfo || {}), ...(checksExtra || { image: originalData }) });
@@ -412,9 +447,17 @@ export const commitCaptureToReview = async ({ kind = 'image', data, isBase64 = k
412
447
  return page;
413
448
  }
414
449
 
450
+ if (shouldPromptCheckFlip()) {
451
+ state.recaptureTarget = null;
452
+ hideVideoOverlay();
453
+ state.cropImgRef?.setCheckDisplay?.();
454
+ promptFlip(state.checkFlipModal, 'capture_back_side');
455
+ return page;
456
+ }
457
+
415
458
  if (shouldAutoAdvanceAnydocBack()) {
416
459
  state.recaptureTarget = null;
417
- promptAnydocFlip();
460
+ promptFlip(state.anydocFlipModal, 'anydoc_flip_prompted');
418
461
  return page;
419
462
  }
420
463
 
package/core/state.js CHANGED
@@ -165,6 +165,9 @@ export const state = {
165
165
  reviewRetakeText: MESSAGES.REVIEW_RETAKE,
166
166
  reviewDeleteText: MESSAGES.REVIEW_DELETE,
167
167
  reviewShowQualityBadges: true,
168
+ reviewDownloadButton: true,
169
+ reviewRotateButton: true,
170
+ reviewCropButton: true,
168
171
  reviewIssueBlurText: MESSAGES.REVIEW_ISSUE_BLUR,
169
172
  reviewIssueLcdText: MESSAGES.REVIEW_ISSUE_LCD,
170
173
  reviewSubmitButtonColor: DEFAULTS.SUBMIT_BUTTON_COLOR,
@@ -209,6 +212,7 @@ export const state = {
209
212
  documentModal: null,
210
213
  lcdModal: null,
211
214
  anydocFlipModal: null,
215
+ checkFlipModal: null,
212
216
  torchButtonRef: null,
213
217
  mirrorButtonRef: null,
214
218
  switchCameraButtonRef: null,
@@ -375,6 +379,7 @@ export const resetState = () => {
375
379
  state.documentModal = null;
376
380
  state.lcdModal = null;
377
381
  state.anydocFlipModal = null;
382
+ state.checkFlipModal = null;
378
383
  state.frameRef = null;
379
384
  state.cropImgRef = null;
380
385
  state.videoRef = null;
@@ -310,6 +310,21 @@ export const renderModalsIfNeeded = () => {
310
310
  }
311
311
  );
312
312
  }
313
+
314
+ if (state.enforceBothSides && !state.enforceAndSkipBothSides && state.lensFlavor === 'checks') {
315
+ state.checkFlipModal = createAnydocFlipModal(
316
+ state.container,
317
+ state.croppedImage,
318
+ async () => {
319
+ const { continueCheckFlip } = await import('./review-flow.js');
320
+ await continueCheckFlip();
321
+ },
322
+ {
323
+ message: state.checkEnforcedModalMessage,
324
+ continueText: state.checkContinueButtonText,
325
+ }
326
+ );
327
+ }
313
328
  };
314
329
 
315
330
  export const renderBottleCapOverlayIfNeeded = () => {
@@ -125,6 +125,7 @@ export function logLongDocument(stitcherResult, corners, nDocs, preview) {
125
125
  state.previewData = preview;
126
126
  state.shouldUpdatePreview = stitcherResult === 0;
127
127
  state.isDocument = corners.length > 0 && stitcherResult === 0;
128
+ drawContours(state.coordinates.length === 4 ? [state.coordinates] : []);
128
129
  }
129
130
 
130
131
  export const logCard = (status, name, number, date, cvv) => {
@@ -393,7 +394,16 @@ const applyOrientationCorrection = async (cropOut) => {
393
394
  const prediction = refs.wasmWrapper.classifyOrientation(bmp);
394
395
  bmp.close();
395
396
  if (!prediction) return cropOut;
396
- const correction = (360 - prediction.angle) % 360;
397
+ let { angle } = prediction;
398
+ // Checks are always landscape: a landscape crop may only flip 180°, a portrait
399
+ // crop must turn 90° — the classifier just picks the direction.
400
+ if (state.lensFlavor === 'checks') {
401
+ const { probs } = prediction;
402
+ angle = outputWidth >= outputHeight
403
+ ? (probs[2] > probs[0] ? 180 : 0)
404
+ : (probs[3] > probs[1] ? 270 : 90);
405
+ }
406
+ const correction = (360 - angle) % 360;
397
407
  state.debug_mode && console.log(`[Orient] detected=${prediction.angle}° correcting by ${correction}° probs=${prediction.probs.map(p => p.toFixed(3)).join(',')}`);
398
408
  if (correction === 0) return cropOut;
399
409
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "3.5.6",
3
+ "version": "3.5.8",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",