veryfi-lens-wasm 3.5.10 → 3.5.12

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/core/camera.js CHANGED
@@ -48,7 +48,7 @@ export const getVideo = async (lensFlavor) => {
48
48
  const isAndroid = /Android/i.test(navigator.userAgent);
49
49
 
50
50
  let videoConfig = {
51
- ...(lensFlavor === 'long_document' || lensFlavor === 'prescription_label' || state.fullScreenEnabled ? {
51
+ ...(lensFlavor === 'prescription_label' || state.fullScreenEnabled ? {
52
52
  width: { ideal: 1920 },
53
53
  height: { ideal: 1080 }
54
54
  } : {
package/core/constants.js CHANGED
@@ -8,6 +8,7 @@ const WASM_PATH = '/static/wasm/';
8
8
 
9
9
  export const WASM = {
10
10
  BASE_URL: `${API_BASES.PROD}${WASM_PATH}`,
11
+ LOCAL_BASE_URL: '/wasm/',
11
12
  };
12
13
 
13
14
  const buildApiUrls = (base) => ({
@@ -39,7 +40,7 @@ export const setApiBaseUrl = (base) => {
39
40
  };
40
41
 
41
42
  export const DEFAULTS = {
42
- SDK_VERSION: '3.5.10',
43
+ SDK_VERSION: '3.5.12',
43
44
  BLUR_THRESHOLD: 0.7,
44
45
  LCD_THRESHOLD: 0.5,
45
46
  BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
@@ -69,6 +70,7 @@ export const DEFAULTS = {
69
70
  GUIDE_MAX_HEIGHT_SCALE: 0.70,
70
71
  CROP_MARGIN: 0.0,
71
72
  CHECKS_CROP_MARGIN: 0.1,
73
+ LONG_DOCUMENT_FRAME_SHORT_SIDE: 1080,
72
74
  };
73
75
 
74
76
  export const MESSAGES = {
package/core/lifecycle.js CHANGED
@@ -2,14 +2,8 @@ import { state, refs, resetState, actions } from './state.js';
2
2
  import { getVideo, displayVideo, clearCameraPermissionDenied } from './camera.js';
3
3
  import { initializeWasmWrapper, sendWasm, sendCardWasm, getLongImage, logDocument, stopWasm, resetAutoCaptureCounters, resetFieldDetectorBootstrap } from './wasm-processing.js';
4
4
  import { hideVideoOverlay, showVideoOverlay } from './overlay-controls.js';
5
- import { docReady, handleSubmit, fireResultSetter } from './api.js';
6
- import { createSubmitButton } from '../components/submitButton.js';
7
5
  import { createVideo } from '../components/video.js';
8
- import {
9
- cancelCropFieldDetection,
10
- onCropPreviewReady,
11
- holdSubmitForFieldDetectionIfNeeded,
12
- } from './crop-field-detection.js';
6
+ import { cancelCropFieldDetection } from './crop-field-detection.js';
13
7
  import { bootstrapTesseract, resetTesseractBootstrap, terminateTesseract } from './tesseract-ocr.js';
14
8
  import { createLongPreview } from '../components/longPreview.js';
15
9
  import { createCheckOverlay } from '../components/checkOverlay.js';
@@ -119,6 +113,7 @@ export const newStartLens = async () => {
119
113
  state.isStitchingProcess = false;
120
114
  state.doc_type = "long_receipt";
121
115
  if (state.enableLongReceiptPreview) {
116
+ state.longPreview?.remove();
122
117
  state.longPreview = createLongPreview(state.container);
123
118
  }
124
119
  break;
@@ -238,24 +233,8 @@ export const stopStitching = async () => {
238
233
  }
239
234
  hideVideoOverlay();
240
235
  state.longPreview?.hide?.();
241
- state.resultSetter?.(state.finalImage);
242
- state.docReadyResult = await docReady();
243
- await fireResultSetter({ ...state.docReadyResult, image: state.finalImage });
244
- const partnerDriven =
245
- state.packageMode && !state.enableSubmit && typeof state.customSubmitHandler !== 'function';
246
- state.submitButton = createSubmitButton(
247
- state.videoOverlay.overlay,
248
- () => {
249
- if (!partnerDriven) {
250
- handleSubmit(state.finalImage);
251
- }
252
- },
253
- () => actions.removeOverlay(),
254
- { buttonText: partnerDriven ? 'Done' : 'Submit' }
255
- );
256
- (state.enableSubmit || partnerDriven) && state.submitButton.show();
257
- holdSubmitForFieldDetectionIfNeeded();
258
- void onCropPreviewReady();
236
+ const { commitCaptureToReview } = await import('./review-flow.js');
237
+ await commitCaptureToReview({ kind: 'image', data: state.finalImage });
259
238
  state.updateHandler?.({ status: 'stitching_completed' });
260
239
  };
261
240
 
@@ -39,7 +39,9 @@ export const showVideoOverlay = () => {
39
39
  if (state.boxRef) state.boxRef.style.display = 'block';
40
40
  if (state.frameRef) state.frameRef.style.display = 'block';
41
41
 
42
- if (state.captureButton?.button) {
42
+ if (state.stitchingButton) {
43
+ state.stitchingButton.show();
44
+ } else if (state.captureButton?.button) {
43
45
  state.captureButton.button.style.display = 'block';
44
46
  }
45
47
 
package/core/state.js CHANGED
@@ -64,6 +64,7 @@ export const state = {
64
64
  frontImage: null,
65
65
  backImage: null,
66
66
  previewData: null,
67
+ longDocumentFrameScale: 1,
67
68
 
68
69
  // Configuration
69
70
  clientId: "",
@@ -79,6 +80,7 @@ export const state = {
79
80
  enableFullScreen: false,
80
81
  testBlurDetection: true,
81
82
  useDevApi: false,
83
+ useLocalWasm: false,
82
84
 
83
85
  // UI Configuration
84
86
  theme: 'system',
@@ -377,6 +379,7 @@ export const resetState = () => {
377
379
  state.frontImage = null;
378
380
  state.backImage = null;
379
381
  state.previewData = null;
382
+ state.longDocumentFrameScale = 1;
380
383
  state.capCircleRadius = DEFAULTS.CAP_CIRCLE_RADIUS;
381
384
  state.bottleCapText = MESSAGES.BOTTLE_CAP;
382
385
  state.enforceAndSkipBothSides = false;
@@ -50,7 +50,8 @@ export const initializeWasmWrapper = async () => {
50
50
  }
51
51
  if (!refs.wasmWrapper.loaded) {
52
52
  await refs.wasmWrapper.initialize(state.clientId, {
53
- wasmBaseUrl: WASM.BASE_URL,
53
+ wasmBaseUrl: state.useLocalWasm ? WASM.LOCAL_BASE_URL : WASM.BASE_URL,
54
+ hostedLayout: !state.useLocalWasm,
54
55
  useDevApi: state.useDevApi,
55
56
  debug: state.debug_mode,
56
57
  });
@@ -121,7 +122,8 @@ export function logDocument(detectorResult, corners, nDocs) {
121
122
  }
122
123
 
123
124
  export function logLongDocument(stitcherResult, corners, nDocs, preview) {
124
- state.coordinates = corners.map((corner) => [corner.x, corner.y]);
125
+ const scale = state.longDocumentFrameScale;
126
+ state.coordinates = corners.map((corner) => [corner.x / scale, corner.y / scale]);
125
127
  state.previewData = preview;
126
128
  state.shouldUpdatePreview = stitcherResult === 0;
127
129
  state.isDocument = corners.length > 0 && stitcherResult === 0;
@@ -190,6 +192,23 @@ export const logCard = (status, name, number, date, cvv) => {
190
192
  }
191
193
  };
192
194
 
195
+ const createLongDocumentFrame = async (video) => {
196
+ const scale = Math.min(
197
+ 1,
198
+ DEFAULTS.LONG_DOCUMENT_FRAME_SHORT_SIDE / Math.min(video.videoWidth, video.videoHeight)
199
+ );
200
+ const bitmap = scale < 1
201
+ ? await createImageBitmap(video, {
202
+ resizeWidth: Math.round(video.videoWidth * scale),
203
+ resizeHeight: Math.round(video.videoHeight * scale),
204
+ resizeQuality: 'medium',
205
+ })
206
+ : await createImageBitmap(video);
207
+ // Measured from the bitmap because some browsers ignore the resize options.
208
+ state.longDocumentFrameScale = bitmap.width / video.videoWidth;
209
+ return bitmap;
210
+ };
211
+
193
212
  export const sendWasm = async (mode) => {
194
213
  if (!refs.wasmWrapper) {
195
214
  state.debug_mode && console.log("WASM wrapper not initialized");
@@ -267,7 +286,9 @@ export const sendWasm = async (mode) => {
267
286
  }
268
287
  } else {
269
288
  try {
270
- const bitmap = await createImageBitmap(video);
289
+ const bitmap = state.lensFlavor === 'long_document'
290
+ ? await createLongDocumentFrame(video)
291
+ : await createImageBitmap(video);
271
292
  if (state.fullSizeImage?.close) {
272
293
  state.fullSizeImage.close();
273
294
  }
@@ -12,6 +12,10 @@ export const setup = async (state, refs, actions) => {
12
12
  actions.checkIfDocumentOnCapture = checkIfDocumentOnCapture;
13
13
  actions.startStitching = startStitching;
14
14
  actions.stopStitching = stopStitching;
15
+ // A stitched long receipt is always a single page, but several of them can be
16
+ // captured in one session when the partner enables multiSubmission/maxDocuments.
17
+ state.maxPagesPerDocument = 1;
18
+ if (state.maxDocuments == null) state.maxDocuments = state.multiSubmission ? null : 1;
15
19
  };
16
20
 
17
21
  export const render = async (state, refs, actions) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "3.5.10",
3
+ "version": "3.5.12",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
package/wasm/wasm.js CHANGED
@@ -73,6 +73,9 @@ export class WasmWrapper {
73
73
  * @param {Object} [options]
74
74
  * @param {string} [options.wasmBaseUrl] - Base URL for hosted WASM files.
75
75
  * Defaults to "/wasm/".
76
+ * @param {boolean} [options.hostedLayout] - When false, variants are read
77
+ * from `<wasmBaseUrl><variant>/` instead of `<wasmBaseUrl>hosted/<variant>/`.
78
+ * Defaults to true.
76
79
  * @param {boolean} [options.useDevApi] - When true, WASM model fetches use
77
80
  * lens-dev.veryfi.com instead of production.
78
81
  */
@@ -89,7 +92,7 @@ export class WasmWrapper {
89
92
  console.log(`[PERF][WASM] feature detection: ${(performance.now() - tFeat0).toFixed(1)}ms (simd=${useSimd})`);
90
93
 
91
94
  const simdDir = this.selectDir(useSimd);
92
- const dir = "hosted/" + simdDir;
95
+ const dir = (options.hostedLayout === false ? "" : "hosted/") + simdDir;
93
96
  console.log("[PERF][WASM] Using hosted build, variant:", simdDir);
94
97
 
95
98
  const scriptUrl = wasmBaseUrl + dir + "/veryfi-wasm.js";