veryfi-lens-wasm 3.2.1 → 3.3.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.
@@ -127,7 +127,11 @@ export const createAnydocPageControls = (container, onAddPage, onSubmit, removeO
127
127
  } catch (error) {
128
128
  console.error('Error during anydoc submission:', error);
129
129
  }
130
- removeOverlay();
130
+ // When autoCloseOnSubmit is false the onSubmit handler owns teardown
131
+ // (multi-submission loop prompts for another capture instead of closing).
132
+ if (options.autoCloseOnSubmit !== false) {
133
+ removeOverlay();
134
+ }
131
135
  };
132
136
  submitButton.addEventListener('click', submitClickHandler);
133
137
 
@@ -1,5 +1,21 @@
1
1
  import { createLayoutManager } from './croppedImageLayouts.js';
2
2
  import { state } from '../core/state.js';
3
+ import { shouldRunFieldDetection } from '../core/field-detection-policy.js';
4
+ import {
5
+ applyCropPreviewLayoutRect,
6
+ resolveCropPreviewLayout,
7
+ rememberCropPreviewLayout,
8
+ } from './previewLayout.js';
9
+
10
+ export const hideCropPreview = (previewImg) => {
11
+ state.cropPreviewRevealed = false;
12
+ const img = previewImg ?? document.getElementById('veryfi-crop-img-preview');
13
+ if (!img) {
14
+ return;
15
+ }
16
+ img.style.display = 'none';
17
+ img.style.visibility = 'hidden';
18
+ };
3
19
 
4
20
  export const revealCropPreview = (previewImg) => {
5
21
  state.cropPreviewRevealed = true;
@@ -7,10 +23,17 @@ export const revealCropPreview = (previewImg) => {
7
23
  if (!img) {
8
24
  return;
9
25
  }
10
- img.style.visibility = '';
11
- if (img.style.display === 'none') {
12
- img.style.display = '';
26
+ const cropRef = document.getElementById('veryfi-crop-img-ref');
27
+ const parent = img.parentElement ?? cropRef?.parentElement;
28
+ const layout = resolveCropPreviewLayout(cropRef, parent);
29
+ if (layout) {
30
+ applyCropPreviewLayoutRect(img, layout);
31
+ rememberCropPreviewLayout(cropRef, layout);
32
+ } else if (cropRef?.width > 0 && cropRef?.height > 0) {
33
+ cropRef.setRectangleDisplay?.();
13
34
  }
35
+ img.style.visibility = '';
36
+ img.style.setProperty('display', 'var(--cropped-image-display, block)');
14
37
  };
15
38
 
16
39
  export const createCroppedImage = (container, options = {}) => {
@@ -20,6 +43,7 @@ export const createCroppedImage = (container, options = {}) => {
20
43
 
21
44
  const previewImg = document.createElement("img");
22
45
  previewImg.id = "veryfi-crop-img-preview";
46
+ previewImg.style.display = 'none';
23
47
 
24
48
  let forceLandscapeCheckPreview = options.forceLandscapeCheckPreview || false;
25
49
  const isChecksFlavor = typeof options.isChecksFlavor === 'function' ? options.isChecksFlavor : () => false;
@@ -47,15 +71,12 @@ export const createCroppedImage = (container, options = {}) => {
47
71
 
48
72
  const updatePreviewImg = () => {
49
73
  if (cropImgCanvas.width > 0 && cropImgCanvas.height > 0) {
50
- previewImg.src = cropImgCanvas.toDataURL("image/jpeg", 0.97);
51
- const holdForFieldDetection = state.documentFieldsToDetect?.length > 0;
74
+ const holdForFieldDetection = shouldRunFieldDetection();
52
75
  if (holdForFieldDetection) {
53
- state.cropPreviewRevealed = false;
54
- previewImg.style.visibility = 'hidden';
55
- if (previewImg.style.display === 'none') {
56
- previewImg.style.display = '';
57
- }
58
- } else {
76
+ hideCropPreview(previewImg);
77
+ }
78
+ previewImg.src = cropImgCanvas.toDataURL("image/jpeg", 0.97);
79
+ if (!holdForFieldDetection) {
59
80
  revealCropPreview(previewImg);
60
81
  }
61
82
  }
@@ -1,25 +1,61 @@
1
+ import {
2
+ applyCropPreviewLayoutRect,
3
+ getCropPreviewLayoutRectFromCanvas,
4
+ rememberCropPreviewLayout,
5
+ } from './previewLayout.js';
6
+
7
+ const MOBILE_BREAKPOINT = 768;
8
+ const MOBILE_PREVIEW_SCREEN_FRACTION = 0.8;
9
+
10
+ const isMobileViewport = () =>
11
+ window.innerWidth <= MOBILE_BREAKPOINT || window.innerHeight <= MOBILE_BREAKPOINT;
12
+
13
+ /** Fit crop aspect ratio inside a max box (fraction of viewport on mobile). */
14
+ export const computeRectangleDimensions = (aspectRatio) => {
15
+ const isMobile = isMobileViewport();
16
+ const baseMaxWidth = isMobile
17
+ ? window.innerWidth * MOBILE_PREVIEW_SCREEN_FRACTION
18
+ : Math.min(500, window.innerWidth * 0.9);
19
+ const baseMaxHeight = isMobile
20
+ ? window.innerHeight * MOBILE_PREVIEW_SCREEN_FRACTION
21
+ : window.innerHeight * 0.6;
22
+
23
+ if (aspectRatio > baseMaxWidth / baseMaxHeight) {
24
+ const width = baseMaxWidth;
25
+ return { width, height: width / aspectRatio };
26
+ }
27
+ const height = baseMaxHeight;
28
+ return { width: height * aspectRatio, height };
29
+ };
30
+
31
+ const applyRectangleLayoutFromCanvas = (previewImg, cropImgCanvas, container, defaultStyles) => {
32
+ const layout = getCropPreviewLayoutRectFromCanvas(cropImgCanvas, container);
33
+ if (!layout) {
34
+ return null;
35
+ }
36
+ rememberCropPreviewLayout(cropImgCanvas, layout);
37
+ applyCropPreviewLayoutRect(previewImg, layout, defaultStyles);
38
+ return layout;
39
+ };
40
+
1
41
  export const createLayoutManager = (previewImg, cropImgCanvas, container, defaultStyles) => {
2
42
  let isSpecialDisplayMode = false;
3
43
 
4
44
  const handleResize = () => {
5
45
  if (isSpecialDisplayMode) return;
6
46
 
7
- const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
47
+ const isMobile = isMobileViewport();
8
48
  const isLandscape = window.innerWidth > window.innerHeight;
9
49
  const isBottleCapsMode = container.querySelector('#veryfi-bottle-cap-overlay') !== null;
10
50
 
11
51
  if (isBottleCapsMode) {
12
52
  setSquareDisplay();
53
+ } else if (isMobile && cropImgCanvas.width > 0 && cropImgCanvas.height > 0) {
54
+ applyRectangleLayoutFromCanvas(previewImg, cropImgCanvas, container, defaultStyles);
13
55
  } else if (isMobile) {
14
- const mobileMaxWidth = isLandscape ? 'var(--cropped-image-mobile-landscape-max-width, 45vw)' : 'var(--cropped-image-mobile-max-width, 90vw)';
15
- previewImg.style.setProperty('width', 'auto');
16
- previewImg.style.setProperty('height', 'auto');
17
- previewImg.style.setProperty('max-width', mobileMaxWidth);
18
- previewImg.style.setProperty('max-height', '80vh');
19
- previewImg.style.setProperty('position', 'var(--cropped-image-mobile-position, fixed)');
20
- previewImg.style.top = '';
21
- previewImg.style.left = '';
22
- previewImg.style.transform = '';
56
+ previewImg.style.display = 'none';
57
+ } else if (!cropImgCanvas.width || !cropImgCanvas.height) {
58
+ previewImg.style.display = 'none';
23
59
  } else {
24
60
  previewImg.style.setProperty('width', 'auto');
25
61
  previewImg.style.setProperty('height', 'auto');
@@ -49,29 +85,7 @@ export const createLayoutManager = (previewImg, cropImgCanvas, container, defaul
49
85
  };
50
86
 
51
87
  const setRectangleDisplay = () => {
52
- const aspectRatio = cropImgCanvas.width / cropImgCanvas.height;
53
- const baseMaxWidth = Math.min(500, window.innerWidth * 0.9);
54
- const baseMaxHeight = window.innerHeight * 0.6;
55
- let width, height;
56
- if (aspectRatio > baseMaxWidth / baseMaxHeight) {
57
- width = baseMaxWidth;
58
- height = width / aspectRatio;
59
- } else {
60
- height = baseMaxHeight;
61
- width = height * aspectRatio;
62
- }
63
- previewImg.style.setProperty('width', `var(--cropped-image-rectangle-width, ${width}px)`);
64
- previewImg.style.setProperty('height', `var(--cropped-image-rectangle-height, ${height}px)`);
65
- previewImg.style.setProperty('max-width', `var(--cropped-image-rectangle-max-width, ${width}px)`);
66
- previewImg.style.setProperty('max-height', `var(--cropped-image-rectangle-max-height, ${height}px)`);
67
- previewImg.style.setProperty('position', 'var(--cropped-image-rectangle-position, fixed)');
68
- previewImg.style.setProperty('top', 'var(--cropped-image-rectangle-top, 50%)');
69
- previewImg.style.setProperty('left', 'var(--cropped-image-rectangle-left, 50%)');
70
- previewImg.style.setProperty('transform', 'var(--cropped-image-rectangle-transform, translate(-50%, -50%))');
71
- previewImg.style.setProperty('object-fit', 'var(--cropped-image-object-fit, contain)');
72
- previewImg.style.setProperty('display', 'var(--cropped-image-display, block)');
73
- previewImg.style.setProperty('margin', 'var(--cropped-image-margin, auto)');
74
- previewImg.style.setProperty('border-radius', `var(--cropped-image-border-radius-rectangle, ${defaultStyles.borderRadiusRectangle})`);
88
+ applyRectangleLayoutFromCanvas(previewImg, cropImgCanvas, container, defaultStyles);
75
89
  };
76
90
 
77
91
  const setCheckDisplay = () => {
@@ -1,6 +1,7 @@
1
1
  import { state } from '../core/state.js';
2
2
  import { createFieldLabelPill, createWarningPill } from './fieldDetectionPill.js';
3
3
  import { createSafeResizeObserver } from '../core/safe-resize-observer.js';
4
+ import { getPreviewLayoutRect } from './previewLayout.js';
4
5
 
5
6
  const FIELD_LABELS = { vendor: 'Vendor', date: 'Date', total: 'Total' };
6
7
  const ALL_FIELDS = ['vendor', 'date', 'total'];
@@ -22,23 +23,20 @@ const getMissingFields = (fieldDetection) => {
22
23
  };
23
24
 
24
25
  const positionMessages = (el, previewImg) => {
25
- const parent = el.parentElement;
26
- if (!parent || !previewImg) {
26
+ const layout = getPreviewLayoutRect(previewImg);
27
+ if (!layout) {
27
28
  return;
28
29
  }
29
30
 
30
31
  const gap = 12;
31
- const imageTop = previewImg.offsetTop;
32
- const imageBottom = imageTop + previewImg.clientHeight;
33
- const imageCenter = previewImg.offsetLeft + previewImg.clientWidth / 2;
34
32
  const messageHeight = el.offsetHeight || 32;
35
33
 
36
- el.style.left = `${imageCenter}px`;
34
+ el.style.left = `${layout.centerX}px`;
37
35
  el.style.transform = 'translateX(-50%)';
38
36
  el.style.right = 'auto';
39
37
  el.style.bottom = 'auto';
40
- el.style.maxWidth = `min(92%, ${Math.max(previewImg.clientWidth, 280)}px)`;
41
- el.style.top = `${Math.max(imageBottom - messageHeight - gap, imageTop + gap)}px`;
38
+ el.style.maxWidth = `min(92%, ${Math.max(layout.width, 280)}px)`;
39
+ el.style.top = `${Math.max(layout.bottom - messageHeight - gap, layout.top + gap)}px`;
42
40
  };
43
41
 
44
42
  /**
@@ -4,6 +4,7 @@ import {
4
4
  } from './fieldDetectionMessages.js';
5
5
  import { createFieldLabelPill, measureFieldLabelPill } from './fieldDetectionPill.js';
6
6
  import { createSafeResizeObserver } from '../core/safe-resize-observer.js';
7
+ import { getPreviewLayoutRect } from './previewLayout.js';
7
8
 
8
9
  const FIELD_LABELS = { vendor: 'Vendor', date: 'Date', total: 'Total' };
9
10
  const FIELD_GREEN = '#04581a';
@@ -57,10 +58,14 @@ const inflateRect = (rect, scale) => {
57
58
  const boxCornerRadius = (rect) => Math.min(rect.width, rect.height) / 2;
58
59
 
59
60
  const syncOverlayGeometry = (overlay, previewImg) => {
60
- overlay.style.left = `${previewImg.offsetLeft}px`;
61
- overlay.style.top = `${previewImg.offsetTop}px`;
62
- overlay.style.width = `${previewImg.clientWidth}px`;
63
- overlay.style.height = `${previewImg.clientHeight}px`;
61
+ const layout = getPreviewLayoutRect(previewImg);
62
+ if (!layout || layout.width <= 0 || layout.height <= 0) {
63
+ return;
64
+ }
65
+ overlay.style.left = `${layout.left}px`;
66
+ overlay.style.top = `${layout.top}px`;
67
+ overlay.style.width = `${layout.width}px`;
68
+ overlay.style.height = `${layout.height}px`;
64
69
  };
65
70
 
66
71
  const renderOverlay = (overlay, previewImg, fieldDetection) => {
@@ -1,4 +1,5 @@
1
1
  import { createSafeResizeObserver } from '../core/safe-resize-observer.js';
2
+ import { getCropPreviewLayoutRectFromCanvas, getPreviewLayoutRect } from './previewLayout.js';
2
3
 
3
4
  const SCAN_GREEN = '#00AA00';
4
5
  const SCAN_GREEN_GLOW = 'rgba(0, 170, 0, 0.85)';
@@ -159,29 +160,43 @@ const buildScanShell = (imageSrc, borderRadius) => {
159
160
  return shell;
160
161
  };
161
162
 
162
- const syncScanRootGeometry = (root, caption, shell, previewImg) => {
163
- const borderRadius = getComputedStyle(previewImg).borderRadius || '10px';
164
- const shellWidth = previewImg.clientWidth;
165
- const shellHeight = previewImg.clientHeight;
166
- if (shellWidth <= 0 || shellHeight <= 0) {
163
+ const syncScanRootGeometry = (root, caption, shell, previewImg, layoutRect) => {
164
+ const layout =
165
+ layoutRect ??
166
+ getPreviewLayoutRect(previewImg) ??
167
+ getCropPreviewLayoutRectFromCanvas(
168
+ document.getElementById('veryfi-crop-img-ref'),
169
+ previewImg?.parentElement
170
+ );
171
+ if (!layout || layout.width <= 0 || layout.height <= 0) {
167
172
  return;
168
173
  }
169
174
 
170
- shell.style.width = `${shellWidth}px`;
171
- shell.style.height = `${shellHeight}px`;
175
+ const borderRadius = previewImg
176
+ ? getComputedStyle(previewImg).borderRadius || '10px'
177
+ : '10px';
178
+ shell.style.width = `${layout.width}px`;
179
+ shell.style.height = `${layout.height}px`;
172
180
  shell.style.borderRadius = borderRadius;
173
- root.style.width = `${shellWidth}px`;
174
181
 
175
- const captionGap = 8;
176
- const captionHeight = caption.offsetHeight || 20;
177
- root.style.left = `${previewImg.offsetLeft}px`;
178
- root.style.top = `${Math.max(previewImg.offsetTop - captionHeight - captionGap, 4)}px`;
182
+ root.style.position = 'absolute';
183
+ root.style.left = `${layout.left}px`;
184
+ root.style.top = `${layout.top}px`;
185
+ root.style.width = `${layout.width}px`;
186
+ root.style.transform = 'none';
187
+ root.style.margin = '0';
188
+
189
+ caption.style.position = 'absolute';
190
+ caption.style.left = '0';
191
+ caption.style.right = '0';
192
+ caption.style.bottom = '100%';
193
+ caption.style.margin = '0 0 8px 0';
179
194
  };
180
195
 
181
196
  /**
182
197
  * Scanner-style top-to-bottom sweep on the crop preview while OCR runs.
183
198
  */
184
- export const showFieldDetectionScanOverlay = (previewImg, imageSrc) => {
199
+ export const showFieldDetectionScanOverlay = (previewImg, imageSrc, layoutRect = null) => {
185
200
  hideFieldDetectionScanOverlay();
186
201
  if (!previewImg?.parentElement) {
187
202
  return;
@@ -191,6 +206,13 @@ export const showFieldDetectionScanOverlay = (previewImg, imageSrc) => {
191
206
 
192
207
  const src = imageSrc || previewImg.src;
193
208
  const borderRadius = getComputedStyle(previewImg).borderRadius || '10px';
209
+ const resolveScanLayout = () =>
210
+ layoutRect ??
211
+ getCropPreviewLayoutRectFromCanvas(
212
+ document.getElementById('veryfi-crop-img-ref'),
213
+ previewImg.parentElement
214
+ ) ??
215
+ getPreviewLayoutRect(previewImg);
194
216
 
195
217
  const root = document.createElement('div');
196
218
  root.id = 'veryfi-field-detection-scan';
@@ -207,9 +229,13 @@ export const showFieldDetectionScanOverlay = (previewImg, imageSrc) => {
207
229
  previewImg.parentElement.appendChild(root);
208
230
  activeScanRoot = root;
209
231
 
210
- const render = () => syncScanRootGeometry(root, caption, shell, previewImg);
232
+ const render = () => syncScanRootGeometry(root, caption, shell, previewImg, resolveScanLayout());
211
233
  const resizeObserver = createSafeResizeObserver(render);
212
234
  resizeObserver?.observe(previewImg);
235
+ const cropCanvas = document.getElementById('veryfi-crop-img-ref');
236
+ if (cropCanvas) {
237
+ resizeObserver?.observe(cropCanvas);
238
+ }
213
239
  window.addEventListener('resize', render);
214
240
 
215
241
  root._cleanup = () => {
@@ -20,6 +20,17 @@ export const createGreenBox = (container) => {
20
20
  const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768 || isDesktopModeOnMobile();
21
21
  const isFullscreen = container.dataset.fullscreen === 'true';
22
22
 
23
+ if (container.dataset.longDocDesktop === 'true') {
24
+ boxCanvas.style.position = 'fixed';
25
+ boxCanvas.style.top = '0';
26
+ boxCanvas.style.left = '0';
27
+ boxCanvas.style.width = '100vw';
28
+ boxCanvas.style.height = '100vh';
29
+ boxCanvas.style.maxWidth = 'none';
30
+ boxCanvas.style.objectFit = 'contain';
31
+ return;
32
+ }
33
+
23
34
  if (!isMobile) {
24
35
  if (isFullscreen) {
25
36
  boxCanvas.style.position = 'fixed';
@@ -0,0 +1,23 @@
1
+ import { createModal } from './modalBase.js';
2
+
3
+ export const createMultiCaptureModal = (container, onCaptureAnother, onFinish, options = {}) => {
4
+ const defaults = {
5
+ message: 'Do you need to capture another document?',
6
+ yesButtonText: 'Capture another',
7
+ noButtonText: "No, I'm done",
8
+ };
9
+ const o = { ...defaults, ...options };
10
+
11
+ return createModal(container, {
12
+ id: 'veryfi-multi-capture-modal',
13
+ cssPrefix: 'multi-capture-modal',
14
+ message: o.message,
15
+ primaryButtonText: o.yesButtonText,
16
+ primaryButtonId: 'veryfi-multi-capture-another',
17
+ secondaryButtonText: o.noButtonText,
18
+ secondaryButtonId: 'veryfi-multi-capture-finish',
19
+ onPrimaryClick: onCaptureAnother,
20
+ onSecondaryClick: onFinish,
21
+ useBackdrop: true,
22
+ });
23
+ };
@@ -0,0 +1,98 @@
1
+ import { computeRectangleDimensions } from './croppedImageLayouts.js';
2
+
3
+ /**
4
+ * Visual layout of the crop preview relative to its offset parent.
5
+ * Use instead of offsetLeft/offsetTop when the preview is fixed + transform-centered.
6
+ */
7
+
8
+ /** Layout rect for a centered crop preview from canvas size (preview may stay display:none). */
9
+ export const getCropPreviewLayoutRectFromCanvas = (canvas, parentEl) => {
10
+ if (!canvas?.width || !canvas?.height || !parentEl) {
11
+ return null;
12
+ }
13
+
14
+ const { width, height } = computeRectangleDimensions(canvas.width / canvas.height);
15
+ const parentRect = parentEl.getBoundingClientRect();
16
+ const previewLeft = (window.innerWidth - width) / 2;
17
+ const previewTop = (window.innerHeight - height) / 2;
18
+ const left = previewLeft - parentRect.left;
19
+ const top = previewTop - parentRect.top;
20
+
21
+ return {
22
+ left,
23
+ top,
24
+ width,
25
+ height,
26
+ centerX: left + width / 2,
27
+ bottom: top + height,
28
+ };
29
+ };
30
+
31
+ export const rememberCropPreviewLayout = (canvas, layout) => {
32
+ if (canvas && layout) {
33
+ canvas._previewLayoutRect = layout;
34
+ }
35
+ };
36
+
37
+ export const resolveCropPreviewLayout = (canvas, parentEl) => {
38
+ if (canvas?._previewLayoutRect) {
39
+ return canvas._previewLayoutRect;
40
+ }
41
+ return getCropPreviewLayoutRectFromCanvas(canvas, parentEl);
42
+ };
43
+
44
+ /**
45
+ * Pin the preview to an exact rect (same coordinates as the field-detection scan shell).
46
+ */
47
+ export const applyCropPreviewLayoutRect = (previewImg, layout, defaultStyles = {}) => {
48
+ if (!previewImg || !layout) {
49
+ return null;
50
+ }
51
+
52
+ const borderRadius = defaultStyles.borderRadiusRectangle ?? '5px';
53
+ previewImg.style.setProperty('position', 'absolute');
54
+ previewImg.style.setProperty('left', `${layout.left}px`);
55
+ previewImg.style.setProperty('top', `${layout.top}px`);
56
+ previewImg.style.setProperty('width', `${layout.width}px`);
57
+ previewImg.style.setProperty('height', `${layout.height}px`);
58
+ previewImg.style.setProperty('max-width', `${layout.width}px`);
59
+ previewImg.style.setProperty('max-height', `${layout.height}px`);
60
+ previewImg.style.setProperty('transform', 'none');
61
+ previewImg.style.setProperty('margin', '0');
62
+ previewImg.style.setProperty('box-sizing', 'border-box');
63
+ previewImg.style.setProperty('object-fit', 'var(--cropped-image-object-fit, contain)');
64
+ previewImg.style.setProperty(
65
+ 'border-radius',
66
+ `var(--cropped-image-border-radius-rectangle, ${borderRadius})`
67
+ );
68
+ return layout;
69
+ };
70
+
71
+ export const getPreviewLayoutRect = (previewImg) => {
72
+ const parent = previewImg?.parentElement;
73
+ if (!parent) {
74
+ return null;
75
+ }
76
+
77
+ const previewRect = previewImg.getBoundingClientRect();
78
+ const parentRect = parent.getBoundingClientRect();
79
+ const left = previewRect.left - parentRect.left;
80
+ const top = previewRect.top - parentRect.top;
81
+ const width = previewRect.width;
82
+ const height = previewRect.height;
83
+
84
+ return {
85
+ left,
86
+ top,
87
+ width,
88
+ height,
89
+ centerX: left + width / 2,
90
+ bottom: top + height,
91
+ };
92
+ };
93
+
94
+ /** Wait for layout after setRectangleDisplay / similar style updates. */
95
+ export const afterPreviewLayout = () =>
96
+ new Promise((resolve) => {
97
+ requestAnimationFrame(() => requestAnimationFrame(resolve));
98
+ });
@@ -57,6 +57,13 @@ export const createSubmitButton = (container, onSubmit, removeOverlay, options =
57
57
  if (button.disabled) {
58
58
  return;
59
59
  }
60
+ // When autoClose is false the onSubmit handler owns teardown/continuation
61
+ // (used by the multi-submission loop, which prompts for another capture
62
+ // instead of removing the overlay after a successful submit).
63
+ if (options.autoClose === false) {
64
+ await onSubmit();
65
+ return;
66
+ }
60
67
  try {
61
68
  await onSubmit();
62
69
  } finally {
@@ -23,6 +23,18 @@ export const createVideo = (container) => {
23
23
  const isFullscreen = container.dataset.fullscreen === 'true';
24
24
  const isLandscape = window.innerWidth > window.innerHeight;
25
25
 
26
+ if (container.dataset.longDocDesktop === 'true') {
27
+ video.style.position = 'fixed';
28
+ video.style.top = '0';
29
+ video.style.left = '0';
30
+ video.style.width = '100vw';
31
+ video.style.height = '100vh';
32
+ video.style.maxWidth = 'none';
33
+ video.style.transform = 'none';
34
+ video.style.objectFit = 'contain';
35
+ return;
36
+ }
37
+
26
38
  if (!isMobile) {
27
39
  if (isFullscreen) {
28
40
  video.style.position = 'fixed';
package/core/api.js CHANGED
@@ -3,6 +3,11 @@ import { flattenObject, parseUA, getBrowserData } from './utils.js';
3
3
  import { getDeviceData } from './device.js';
4
4
  import { createSpinner } from '../components/spinner.js';
5
5
  import { API_URLS } from './constants.js';
6
+ import { shouldRunFieldDetection } from './field-detection-policy.js';
7
+
8
+ export const getQrSessionId = () => {
9
+ return new URLSearchParams(window.location.search).get('session');
10
+ };
6
11
 
7
12
  export const validatePartner = async (client_id) => {
8
13
  try {
@@ -313,7 +318,7 @@ export const handleSubmit = async (image) => {
313
318
  ...customData,
314
319
  };
315
320
 
316
- const qrSessionId = new URLSearchParams(window.location.search).get('session');
321
+ const qrSessionId = getQrSessionId();
317
322
 
318
323
  const requestOptions = {
319
324
  method: 'POST',
@@ -342,7 +347,7 @@ export const handleSubmit = async (image) => {
342
347
  state.updateHandler?.({ status: 'submission_completed' });
343
348
  const result = await response.json();
344
349
 
345
- if (documentFieldsToDetect.length && localFieldDetection) {
350
+ if (shouldRunFieldDetection(lensFlavor) && documentFieldsToDetect.length && localFieldDetection) {
346
351
  result.field_detection = localFieldDetection;
347
352
  }
348
353
 
@@ -350,6 +355,7 @@ export const handleSubmit = async (image) => {
350
355
  state.debug_mode && console.log("Success handler called");
351
356
  successHandler(result);
352
357
  }
358
+ return result;
353
359
  } finally {
354
360
  spinner.remove();
355
361
  }
@@ -371,6 +377,46 @@ export const handleSubmit = async (image) => {
371
377
  }
372
378
  };
373
379
 
380
+ export const finishBatch = async () => {
381
+ const clientId = state.clientId;
382
+ const qrSessionId = getQrSessionId();
383
+
384
+ if (!clientId || !qrSessionId) {
385
+ throw new Error('CLIENT-ID and QR session are required to finish the batch');
386
+ }
387
+
388
+ state.updateHandler?.({ status: 'batch_finish_started' });
389
+
390
+ const response = await fetch(API_URLS.FINISH_BATCH, {
391
+ method: 'POST',
392
+ headers: {
393
+ 'CLIENT-ID': clientId,
394
+ 'QR-SESSION-ID': qrSessionId,
395
+ },
396
+ });
397
+
398
+ if (!response.ok) {
399
+ const errorData = await response.json().catch(() => null);
400
+ const message = errorData?.detail || `HTTP error! status: ${response.status}`;
401
+ const error = new Error(message);
402
+ error.status = response.status;
403
+ error.detail = errorData;
404
+ state.updateHandler?.({
405
+ status: 'batch_finish_failed',
406
+ error: errorData,
407
+ statusCode: response.status,
408
+ });
409
+ throw error;
410
+ }
411
+
412
+ const result = await response.json();
413
+ state.updateHandler?.({
414
+ status: 'batch_finish_completed',
415
+ document_count: result.document_count,
416
+ });
417
+ return result;
418
+ };
419
+
374
420
  export const fetchBlueprints = async () => {
375
421
  const requestOptions = {
376
422
  method: 'POST',