veryfi-lens-wasm 3.5.11 → 3.5.13

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/constants.js CHANGED
@@ -11,6 +11,8 @@ export const WASM = {
11
11
  LOCAL_BASE_URL: '/wasm/',
12
12
  };
13
13
 
14
+ export const TESSERACT_URL = 'https://cdn.jsdelivr.net/npm/tesseract.js@7.0.0/dist/tesseract.esm.min.js';
15
+
14
16
  const buildApiUrls = (base) => ({
15
17
  VALIDATE_PARTNER: `${base}/rest/validate_partner`,
16
18
  SEND_CROPPED: `${base}/rest/send-cropped`,
@@ -40,7 +42,7 @@ export const setApiBaseUrl = (base) => {
40
42
  };
41
43
 
42
44
  export const DEFAULTS = {
43
- SDK_VERSION: '3.5.11',
45
+ SDK_VERSION: '3.5.13',
44
46
  BLUR_THRESHOLD: 0.7,
45
47
  LCD_THRESHOLD: 0.5,
46
48
  BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
@@ -12,6 +12,20 @@ const base64Bytes = (base64) => Math.floor((base64.length * 3) / 4);
12
12
  const encode = (canvas, quality) =>
13
13
  canvas.toDataURL('image/jpeg', quality).split(',')[1];
14
14
 
15
+ // JPEG has no alpha channel. Composite over white without changing the source
16
+ // canvas used by capture, review, or subsequent encodes.
17
+ const flattenForJpeg = (source) => {
18
+ if (source.width === 0 || source.height === 0) return source;
19
+ const opaque = document.createElement('canvas');
20
+ opaque.width = source.width;
21
+ opaque.height = source.height;
22
+ const ctx = opaque.getContext('2d');
23
+ ctx.fillStyle = '#fff';
24
+ ctx.fillRect(0, 0, opaque.width, opaque.height);
25
+ ctx.drawImage(source, 0, 0);
26
+ return opaque;
27
+ };
28
+
15
29
  const scaleCanvas = (source, scale) => {
16
30
  const width = Math.max(1, Math.round(source.width * scale));
17
31
  const height = Math.max(1, Math.round(source.height * scale));
@@ -30,7 +44,8 @@ const scaleCanvas = (source, scale) => {
30
44
  * Applies to still images only — recorded video is never re-encoded.
31
45
  */
32
46
  export const canvasToJpegBase64 = (canvas, quality = DEFAULTS.IMAGE_QUALITY) => {
33
- let base64 = encode(canvas, quality);
47
+ const opaque = flattenForJpeg(canvas);
48
+ let base64 = encode(opaque, quality);
34
49
 
35
50
  const maxSizeInMB = state.originalImageMaxSizeInMB;
36
51
  if (!maxSizeInMB) return base64;
@@ -40,11 +55,11 @@ export const canvasToJpegBase64 = (canvas, quality = DEFAULTS.IMAGE_QUALITY) =>
40
55
 
41
56
  for (const step of QUALITY_STEPS) {
42
57
  if (step >= quality) continue;
43
- base64 = encode(canvas, step);
58
+ base64 = encode(opaque, step);
44
59
  if (base64Bytes(base64) <= maxBytes) return base64;
45
60
  }
46
61
 
47
- let working = canvas;
62
+ let working = opaque;
48
63
  for (let attempt = 0; attempt < MAX_SCALE_ATTEMPTS; attempt += 1) {
49
64
  working = scaleCanvas(working, SCALE_STEP);
50
65
  base64 = encode(working, QUALITY_STEPS[QUALITY_STEPS.length - 1]);
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
@@ -136,6 +136,7 @@ export const state = {
136
136
  frontBackDetectionForChecks: false,
137
137
  documentFieldsToDetect: [],
138
138
  disableSubmitUntilFieldDetectionDone: false,
139
+ tesseractBaseUrl: null,
139
140
  fieldDetectionResult: null,
140
141
  cropPreviewRevealed: true,
141
142
  submitInProgress: false,
@@ -1,7 +1,9 @@
1
- import { createWorker } from 'tesseract.js';
2
1
  import { state } from './state.js';
3
2
  import { shouldRunFieldDetection } from './field-detection-policy.js';
3
+ import { TESSERACT_URL } from './constants.js';
4
4
 
5
+ let tesseractModulePromise = null;
6
+ let tesseractModuleUrl = null;
5
7
  let workerPromise = null;
6
8
  let workerLang = null;
7
9
  let tesseractBootstrapStarted = false;
@@ -53,6 +55,37 @@ const RECOGNIZE_OUTPUT = {
53
55
  blocks: true,
54
56
  };
55
57
 
58
+ /**
59
+ * Loader URL + worker paths. With `tesseractBaseUrl` set, every Tesseract file is read from it:
60
+ * `tesseract.esm.min.js`, `worker.min.js`, `core/tesseract-core-*.wasm.js`, `lang/<lang>.traineddata.gz`.
61
+ */
62
+ const getTesseractPaths = () => {
63
+ const base = state.tesseractBaseUrl ? String(state.tesseractBaseUrl).replace(/\/?$/, '/') : null;
64
+ if (!base) {
65
+ return { loaderUrl: TESSERACT_URL, workerPaths: {} };
66
+ }
67
+ return {
68
+ loaderUrl: `${base}tesseract.esm.min.js`,
69
+ workerPaths: {
70
+ workerPath: `${base}worker.min.js`,
71
+ corePath: `${base}core`,
72
+ langPath: `${base}lang`,
73
+ },
74
+ };
75
+ };
76
+
77
+ const loadCreateWorker = async (loaderUrl) => {
78
+ if (!tesseractModulePromise || tesseractModuleUrl !== loaderUrl) {
79
+ tesseractModuleUrl = loaderUrl;
80
+ tesseractModulePromise = import(/* webpackIgnore: true */ /* @vite-ignore */ loaderUrl).catch((error) => {
81
+ tesseractModulePromise = null;
82
+ throw error;
83
+ });
84
+ }
85
+ const { default: Tesseract } = await tesseractModulePromise;
86
+ return Tesseract.createWorker;
87
+ };
88
+
56
89
  /**
57
90
  * Shared Tesseract worker (lazy). Default eng+spa for receipt-style documents.
58
91
  */
@@ -67,19 +100,23 @@ export const getTesseractWorker = async (lang = 'eng+spa') => {
67
100
  }
68
101
 
69
102
  workerLang = lang;
70
- workerPromise = createWorker(lang, 1, {
71
- logger: (message) => {
72
- if (!state.debug_mode || !message?.status) return;
73
- if (message.status === 'recognizing text' && typeof message.progress === 'number') {
74
- const pct = Math.round(message.progress * 100);
75
- if (pct % 25 === 0) {
76
- console.log(`[Tesseract] ${message.status} ${pct}%`);
103
+ const { loaderUrl, workerPaths } = getTesseractPaths();
104
+ workerPromise = loadCreateWorker(loaderUrl).then((createWorker) =>
105
+ createWorker(lang, 1, {
106
+ ...workerPaths,
107
+ logger: (message) => {
108
+ if (!state.debug_mode || !message?.status) return;
109
+ if (message.status === 'recognizing text' && typeof message.progress === 'number') {
110
+ const pct = Math.round(message.progress * 100);
111
+ if (pct % 25 === 0) {
112
+ console.log(`[Tesseract] ${message.status} ${pct}%`);
113
+ }
114
+ } else {
115
+ console.log('[Tesseract]', message.status);
77
116
  }
78
- } else {
79
- console.log('[Tesseract]', message.status);
80
- }
81
- },
82
- });
117
+ },
118
+ })
119
+ );
83
120
  return workerPromise;
84
121
  };
85
122
 
@@ -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.11",
3
+ "version": "3.5.13",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
@@ -14,8 +14,7 @@
14
14
  "dependencies": {
15
15
  "@fingerprintjs/fingerprintjs": "4.6.2",
16
16
  "@fingerprintjs/fingerprintjs-pro": "3.12.8",
17
- "jszip": "3.10.1",
18
- "tesseract.js": "7.0.0"
17
+ "jszip": "3.10.1"
19
18
  },
20
19
  "files": [
21
20
  "dist",