veryfi-lens-wasm 3.4.1 → 3.4.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
@@ -210,6 +210,8 @@ After each accepted capture, the `document`, `anydocs`, and `prescription_label`
210
210
  | `reviewDoneText` | `string` | `"Done"` | Done action text |
211
211
  | `reviewRetakeText` | `string` | `"Retake"` | Retake action text |
212
212
  | `reviewDeleteText` | `string` | `"Delete"` | Delete action text |
213
+ | `reviewSubmitButtonColor` | `string` | `"#00AA00"` | Submit button color (also used as the crop editor accent) |
214
+ | `reviewSubmitButtonTextColor` | `string` | `"#FFFFFF"` | Submit button text color (also the crop editor Apply button) |
213
215
 
214
216
  ### Anydocs Multi-Page Settings
215
217
 
@@ -261,6 +263,7 @@ After each accepted capture, the `document`, `anydocs`, and `prescription_label`
261
263
  | `prescriptionLabelBoxSideAddText` | `string` | `"Capture another side"` | _Deprecated:_ use `reviewAddPageText` |
262
264
  | `prescriptionLabelBoxSideSubmitText` | `string` | `"Submit"` | _Deprecated:_ use `reviewSubmitText` |
263
265
  | `prescriptionLabelMaxVideoDuration` | `number` | `12` | Maximum length, in seconds, of a bottle (video) capture. When reached, recording stops automatically. An on-screen countdown is shown while recording. Set to `0` to disable the limit |
266
+ | `prescriptionLabelProgressFill` | `boolean` | `false` | When `true`, the remaining bottle capture time is shown by the bottle outline draining (with a centered countdown) instead of the "REC" box. Requires `prescriptionLabelMaxVideoDuration > 0` |
264
267
 
265
268
  ### Upload Settings (`upload` flavor)
266
269
 
@@ -1,7 +1,7 @@
1
1
  import { LIQUID_GLASS, liquidGlassStyles } from './liquid-glass.js';
2
2
 
3
- export const createExitButton = (container, options, removeOverlay) => {
4
- const { setter, redirectUrl, lensFlavor } = options;
3
+ export const createExitButton = (container, options, onExit) => {
4
+ const { lensFlavor } = options;
5
5
 
6
6
  const button = document.createElement('a');
7
7
  button.id = 'veryfi-exit-button';
@@ -78,14 +78,8 @@ export const createExitButton = (container, options, removeOverlay) => {
78
78
 
79
79
  button.addEventListener('click', (e) => {
80
80
  e.preventDefault();
81
- if (setter && typeof setter === 'function') {
82
- setter(false);
83
- }
84
- if (redirectUrl) {
85
- window.location.href = redirectUrl;
86
- }
87
- if (typeof removeOverlay === 'function') {
88
- removeOverlay();
81
+ if (typeof onExit === 'function') {
82
+ onExit();
89
83
  }
90
84
  });
91
85
 
@@ -98,6 +98,23 @@ export const createPrescriptionLabelOverlay = (container, options = {}) => {
98
98
  maskPath.setAttribute('fill-rule', 'evenodd');
99
99
  svg.appendChild(maskPath);
100
100
 
101
+ // Liquid-fill progress: a rect clipped to the bottle shape that rises/drains
102
+ // to visualize the remaining capture time (used instead of the REC box when
103
+ // prescriptionLabelProgressFill is enabled).
104
+ const defs = document.createElementNS(NS, 'defs');
105
+ const clipPath = document.createElementNS(NS, 'clipPath');
106
+ clipPath.setAttribute('id', 'veryfi-bottle-fill-clip');
107
+ const clipPathShape = document.createElementNS(NS, 'path');
108
+ clipPath.appendChild(clipPathShape);
109
+ defs.appendChild(clipPath);
110
+ svg.appendChild(defs);
111
+
112
+ const fillRect = document.createElementNS(NS, 'rect');
113
+ fillRect.setAttribute('fill', 'rgba(0, 170, 0, 0.35)');
114
+ fillRect.setAttribute('clip-path', 'url(#veryfi-bottle-fill-clip)');
115
+ fillRect.style.display = 'none';
116
+ svg.appendChild(fillRect);
117
+
101
118
  const guidePath = document.createElementNS(NS, 'path');
102
119
  guidePath.setAttribute('fill', 'none');
103
120
  guidePath.setAttribute('stroke', '#00AA00');
@@ -105,10 +122,47 @@ export const createPrescriptionLabelOverlay = (container, options = {}) => {
105
122
  guidePath.setAttribute('stroke-linecap', 'round');
106
123
  svg.appendChild(guidePath);
107
124
 
125
+ const timeText = document.createElementNS(NS, 'text');
126
+ timeText.setAttribute('text-anchor', 'middle');
127
+ timeText.setAttribute('dominant-baseline', 'middle');
128
+ timeText.setAttribute('fill', 'white');
129
+ timeText.setAttribute('font-size', '34');
130
+ timeText.setAttribute('font-weight', 'bold');
131
+ timeText.setAttribute('font-family', 'Arial, sans-serif');
132
+ timeText.style.pointerEvents = 'none';
133
+ timeText.style.display = 'none';
134
+ svg.appendChild(timeText);
135
+
108
136
  const loadingIndicator = createLoadingSpinner('veryfi-prescription-label-loading');
109
137
 
110
138
  let dashInitialized = false;
111
139
 
140
+ // Current bottle geometry + fill state, so the fill can be updated
141
+ // independently of the resize-driven redraw loop.
142
+ let lastVW = 0;
143
+ let bottleTopY = 0;
144
+ let bottleBottomY = 0;
145
+ let currentFraction = 0;
146
+ let currentLabel = null;
147
+
148
+ const applyFill = () => {
149
+ const totalH = Math.max(0, bottleBottomY - bottleTopY);
150
+ const h = Math.max(0, Math.min(totalH, totalH * currentFraction));
151
+ fillRect.setAttribute('x', '0');
152
+ fillRect.setAttribute('width', String(lastVW));
153
+ fillRect.setAttribute('y', String(bottleBottomY - h));
154
+ fillRect.setAttribute('height', String(h));
155
+ fillRect.style.display = h > 0 ? 'block' : 'none';
156
+ if (currentLabel != null) {
157
+ timeText.textContent = currentLabel;
158
+ timeText.setAttribute('x', String(lastVW / 2));
159
+ timeText.setAttribute('y', String(bottleTopY + totalH / 2));
160
+ timeText.style.display = 'block';
161
+ } else {
162
+ timeText.style.display = 'none';
163
+ }
164
+ };
165
+
112
166
  const base = createOverlayBase(container, {
113
167
  id: 'veryfi-prescription-label-overlay',
114
168
  hasSpinner: true,
@@ -129,6 +183,16 @@ export const createPrescriptionLabelOverlay = (container, options = {}) => {
129
183
 
130
184
  maskPath.setAttribute('d', `${outerRect} ${bottle}`);
131
185
  guidePath.setAttribute('d', bottle);
186
+ clipPathShape.setAttribute('d', bottle);
187
+
188
+ // Track bottle bounds for the liquid fill and re-apply the current level
189
+ // after any geometry change (resize / orientation).
190
+ const cy = vh * 0.46;
191
+ const totalH = vh * bottleHeightRatio;
192
+ lastVW = vw;
193
+ bottleTopY = cy - totalH / 2;
194
+ bottleBottomY = cy + totalH / 2;
195
+ applyFill();
132
196
 
133
197
  if (!dashInitialized) {
134
198
  const totalLen = guidePath.getTotalLength();
@@ -151,6 +215,19 @@ export const createPrescriptionLabelOverlay = (container, options = {}) => {
151
215
 
152
216
  return {
153
217
  ...base,
218
+ // Set the liquid-fill level (0..1) and an optional centered label (e.g. the
219
+ // remaining time). Called each frame while recording when the progress-fill
220
+ // indicator is enabled.
221
+ setFillProgress: (fraction, label = null) => {
222
+ currentFraction = fraction;
223
+ currentLabel = label;
224
+ applyFill();
225
+ },
226
+ resetFill: () => {
227
+ currentFraction = 0;
228
+ currentLabel = null;
229
+ applyFill();
230
+ },
154
231
  cleanup: () => {
155
232
  base.cleanup();
156
233
  if (traceStyleEl) {
@@ -18,7 +18,50 @@ import { liquidGlassStyles, LIQUID_GLASS } from './liquid-glass.js';
18
18
  // onDeletePage(docIndex, pageIndex),
19
19
  // onSelectDoc(docIndex),
20
20
  // }
21
+ // Inject the gallery's keyframes/animation rules once per document. Keyframes
22
+ // can't live in inline styles, and everything is gated behind
23
+ // prefers-reduced-motion so it degrades to no motion when the user opts out.
24
+ const ANIM_STYLE_ID = 'veryfi-review-gallery-anim';
25
+ const ensureAnimStyles = () => {
26
+ if (document.getElementById(ANIM_STYLE_ID)) return;
27
+ const style = document.createElement('style');
28
+ style.id = ANIM_STYLE_ID;
29
+ style.textContent = `
30
+ @media (prefers-reduced-motion: no-preference) {
31
+ #veryfi-review-gallery.veryfi-rg-opening {
32
+ animation: veryfi-rg-gallery-in 280ms cubic-bezier(0.22, 1, 0.36, 1);
33
+ }
34
+ #veryfi-review-gallery .veryfi-rg-tile {
35
+ animation: veryfi-rg-tile-in 320ms cubic-bezier(0.22, 1, 0.36, 1) both;
36
+ }
37
+ #veryfi-review-gallery .veryfi-rg-detail {
38
+ animation: veryfi-rg-detail-in 300ms cubic-bezier(0.22, 1, 0.36, 1);
39
+ }
40
+ }
41
+ @keyframes veryfi-rg-gallery-in {
42
+ from { opacity: 0; transform: scale(1.03); }
43
+ to { opacity: 1; transform: none; }
44
+ }
45
+ @keyframes veryfi-rg-tile-in {
46
+ from { opacity: 0; transform: translateY(12px) scale(0.94); }
47
+ to { opacity: 1; transform: none; }
48
+ }
49
+ @keyframes veryfi-rg-detail-in {
50
+ from { opacity: 0; transform: scale(0.97); }
51
+ to { opacity: 1; transform: none; }
52
+ }
53
+ #veryfi-review-gallery button {
54
+ transition: transform 0.12s ease, background-color 0.2s ease, box-shadow 0.2s ease;
55
+ }
56
+ #veryfi-review-gallery button:active {
57
+ transform: scale(0.93);
58
+ }
59
+ `;
60
+ document.head.appendChild(style);
61
+ };
62
+
21
63
  export const createReviewGallery = (container, callbacks = {}, options = {}) => {
64
+ ensureAnimStyles();
22
65
  const o = {
23
66
  title: options.title || 'Review',
24
67
  addPageText: options.addPageText || 'Add Page',
@@ -31,6 +74,8 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
31
74
  cropText: options.cropText || 'Crop',
32
75
  downloadText: options.downloadText || 'Download',
33
76
  backText: options.backText || 'Back',
77
+ submitButtonColor: options.submitButtonColor || '#00AA00',
78
+ submitButtonTextColor: options.submitButtonTextColor || '#FFFFFF',
34
79
  imageQuality: options.imageQuality || 0.97,
35
80
  allowAddPage: options.allowAddPage !== false,
36
81
  allowAddDocument: options.allowAddDocument !== false,
@@ -166,12 +211,13 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
166
211
  const submitButton = document.createElement('button');
167
212
  submitButton.id = 'veryfi-review-submit';
168
213
  submitButton.textContent = o.submitText;
169
- Object.assign(submitButton.style, pillStyle('#00AA00'), {
214
+ Object.assign(submitButton.style, pillStyle(o.submitButtonColor), {
170
215
  flex: '1 1 auto',
171
216
  maxWidth: '420px',
172
217
  textAlign: 'center',
173
218
  fontSize: '16px',
174
219
  padding: '10px 24px',
220
+ color: o.submitButtonTextColor,
175
221
  });
176
222
  submitButton.addEventListener('click', async () => {
177
223
  if (submitButton.disabled) return;
@@ -359,7 +405,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
359
405
  const box = document.createElement('div');
360
406
  Object.assign(box.style, {
361
407
  position: 'absolute',
362
- border: '2px solid #00AA00',
408
+ border: `2px solid ${o.submitButtonColor}`,
363
409
  boxShadow: '0 0 0 9999px rgba(0, 0, 0, 0.5)',
364
410
  boxSizing: 'border-box',
365
411
  cursor: 'move',
@@ -372,7 +418,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
372
418
  position: 'absolute',
373
419
  width: '22px',
374
420
  height: '22px',
375
- background: '#00AA00',
421
+ background: o.submitButtonColor,
376
422
  borderRadius: '50%',
377
423
  [corner.includes('n') ? 'top' : 'bottom']: '-11px',
378
424
  [corner.includes('w') ? 'left' : 'right']: '-11px',
@@ -399,7 +445,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
399
445
  Object.assign(cancelBtn.style, pillStyle());
400
446
  const applyBtn = document.createElement('button');
401
447
  applyBtn.textContent = o.cropText;
402
- Object.assign(applyBtn.style, pillStyle('#00AA00'));
448
+ Object.assign(applyBtn.style, pillStyle(o.submitButtonColor), { color: o.submitButtonTextColor });
403
449
  bar.appendChild(cancelBtn);
404
450
  bar.appendChild(applyBtn);
405
451
 
@@ -537,6 +583,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
537
583
  // Dashed "+" tile used to add a document (strip) or a page (grid).
538
584
  const buildAddTile = (label, onClick, sizeStyle = {}) => {
539
585
  const tile = document.createElement('button');
586
+ tile.classList.add('veryfi-rg-tile');
540
587
  Object.assign(tile.style, {
541
588
  flex: '0 0 auto',
542
589
  display: 'flex',
@@ -580,6 +627,8 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
580
627
 
581
628
  docs.forEach((doc, index) => {
582
629
  const tile = document.createElement('button');
630
+ tile.classList.add('veryfi-rg-tile');
631
+ tile.style.animationDelay = `${index * 45}ms`;
583
632
  const isActive = index === activeIndex;
584
633
  Object.assign(tile.style, {
585
634
  position: 'relative',
@@ -624,12 +673,12 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
624
673
  });
625
674
 
626
675
  if (o.allowAddDocument && canAddDocument) {
627
- stripEl.appendChild(
628
- buildAddTile(o.addDocumentText, () => callbacks.onAddDocument?.(), {
629
- width: '65px',
630
- height: '60px',
631
- })
632
- );
676
+ const addDoc = buildAddTile(o.addDocumentText, () => callbacks.onAddDocument?.(), {
677
+ width: '65px',
678
+ height: '60px',
679
+ });
680
+ addDoc.style.animationDelay = `${docs.length * 45}ms`;
681
+ stripEl.appendChild(addDoc);
633
682
  }
634
683
  };
635
684
 
@@ -637,6 +686,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
637
686
  // one-page session and when a grid tile is tapped (focused page).
638
687
  const buildDetailCell = (page, docIndex, pageIndex, { showBack }) => {
639
688
  const cell = document.createElement('div');
689
+ cell.classList.add('veryfi-rg-detail');
640
690
  Object.assign(cell.style, {
641
691
  position: 'relative',
642
692
  display: 'flex',
@@ -722,6 +772,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
722
772
  // Grid tile for the multi-page overview: tapping it opens the page detail.
723
773
  const buildGridTile = (page, pageIndex) => {
724
774
  const cell = document.createElement('div');
775
+ cell.classList.add('veryfi-rg-tile');
725
776
  Object.assign(cell.style, {
726
777
  position: 'relative',
727
778
  borderRadius: '10px',
@@ -822,12 +873,14 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
822
873
 
823
874
  gridEl.style.gridTemplateColumns = 'repeat(auto-fill, minmax(150px, 1fr))';
824
875
  pages.forEach((page, pageIndex) => {
825
- gridEl.appendChild(buildGridTile(page, pageIndex));
876
+ const tile = buildGridTile(page, pageIndex);
877
+ tile.style.animationDelay = `${pageIndex * 45}ms`;
878
+ gridEl.appendChild(tile);
826
879
  });
827
880
  if (allowAddPageNow) {
828
- gridEl.appendChild(
829
- buildAddTile(o.addPageText, () => callbacks.onAddPage?.(), { aspectRatio: '3 / 4' })
830
- );
881
+ const addTile = buildAddTile(o.addPageText, () => callbacks.onAddPage?.(), { aspectRatio: '3 / 4' });
882
+ addTile.style.animationDelay = `${pages.length * 45}ms`;
883
+ gridEl.appendChild(addTile);
831
884
  }
832
885
  };
833
886
 
@@ -859,6 +912,12 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
859
912
  show: (payload) => {
860
913
  render(payload);
861
914
  root.style.display = 'flex';
915
+ // Replay the open animation on every show (the gallery is hidden while the
916
+ // camera is active between captures). Force a reflow so re-adding the class
917
+ // restarts the animation.
918
+ root.classList.remove('veryfi-rg-opening');
919
+ void root.offsetWidth;
920
+ root.classList.add('veryfi-rg-opening');
862
921
  },
863
922
  hide: () => {
864
923
  root.style.display = 'none';
@@ -1,195 +1,43 @@
1
1
  import { state, refs } from '../state.js';
2
2
  import { cropWasm } from '../wasm-processing.js';
3
3
  import { checkIfDocumentOnCapture, checkIfBlurOnCapture, checkIfLcdOnCapture } from '../validation.js';
4
- import { docReady, handleSubmit, ensurePackageUploaded, fireResultSetter } from '../api.js';
5
- import { hideVideoOverlay, showVideoOverlay } from '../overlay-controls.js';
6
- import { newStartLens, removeOverlay } from '../lifecycle.js';
7
- import { createSubmitButton } from '../../components/submitButton.js';
8
- import { createCheckCaptureModal } from '../../components/checkCaptureModal.js';
9
- import { createCheckImages } from '../../components/checkImages.js';
10
- import { revealCropPreview } from '../../components/croppedImage.js';
11
-
12
- export const handleChecksFrontAccepted = async () => {
13
- state.blurStatus = false;
14
- state.lcdStatus = false;
15
-
16
- state.cropImgRef?.showSuccessBorder?.();
17
-
18
- state.updateHandler?.({ status: 'processing_started' });
19
- state.docReadyResult = await docReady();
20
- state.updateHandler?.({ status: 'processing_completed' });
21
- state.debug_mode && console.log("Front check image processed successfully");
22
-
23
- const isBackExpected = state.captureBackOfCheck || state.enforceBothSides || state.enforceAndSkipBothSides;
24
-
25
- const finalized = await fireResultSetter(
26
- {
27
- ...state.docReadyResult,
28
- frontImage: state.frontImage,
29
- frontLcdResult: state.frontLcdResult,
30
- frontFrontBackResult: state.frontFrontBackResult
31
- },
32
- { autoUpload: !isBackExpected }
33
- );
34
- if (finalized) {
35
- removeOverlay();
4
+ import { showVideoOverlay } from '../overlay-controls.js';
5
+ import { restartCameraForNextCapture } from '../lifecycle.js';
6
+ import * as store from '../capture-store.js';
7
+ const syncCapturingSide = () => {
8
+ if (state.recaptureTarget) {
9
+ state.isCapturingFront = state.recaptureTarget.pageIndex === 0;
36
10
  return;
37
11
  }
38
-
39
- if (isBackExpected) {
40
- if (state.enforceAndSkipBothSides) {
41
- const proceedToBackCapture = () => {
42
- if (state.videoRef) state.videoRef.style.display = 'block';
43
- if (state.boxRef) state.boxRef.style.display = 'block';
44
- if (state.frameRef) state.frameRef.style.display = 'block';
45
-
46
- if (state.cropImgRef) {
47
- state.cropImgRef.hideBorder();
48
- if (state.cropImgRef.previewImg) state.cropImgRef.previewImg.style.display = 'none';
49
- const ctx = state.cropImgRef.getContext("2d");
50
- ctx?.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
51
- }
52
-
53
- state.isCapturingFront = false;
54
- state.updateHandler?.({ status: 'capture_back_side_auto' });
55
- newStartLens(state.lensFlavor);
56
- };
57
-
58
- if (state.delayBetweenCaptures > 0) {
59
- state.debug_mode && console.log(`Delaying back capture by ${state.delayBetweenCaptures}ms`);
60
- setTimeout(proceedToBackCapture, state.delayBetweenCaptures);
61
- } else {
62
- proceedToBackCapture();
63
- }
64
- } else {
65
- const checkCaptureModal = createCheckCaptureModal(
66
- state.container,
67
- state.finalImage,
68
- () => {
69
- showVideoOverlay();
70
- if (state.isManualCheckCapture && state.checkOverlay) {
71
- state.checkOverlay.show();
72
- }
73
- if (state.cropImgRef) {
74
- state.cropImgRef.hideBorder();
75
- if (state.cropImgRef.previewImg) state.cropImgRef.previewImg.style.display = 'none';
76
- const ctx = state.cropImgRef.getContext("2d");
77
- ctx?.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
78
- }
79
- state.isCapturingFront = false;
80
- state.updateHandler?.({ status: 'capture_back_side_required' });
81
- newStartLens(state.lensFlavor);
82
- },
83
- state.enforceBothSides ? null : () => {
84
- hideVideoOverlay();
85
- state.cropImgRef?.setCheckDisplay?.();
86
- revealCropPreview(state.cropImgRef?.previewImg);
87
- if (state.isDocument) {
88
- state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
89
- if (typeof state.customSubmitHandler === 'function') {
90
- const packageInfo = await ensurePackageUploaded();
91
- state.customSubmitHandler(state.frontImage, packageInfo);
92
- } else {
93
- handleSubmit(state.frontImage);
94
- }
95
- }, removeOverlay);
96
- state.enableSubmit && state.submitButton.show();
97
- }
98
- },
99
- {
100
- enforcedModalMessage: state.checkEnforcedModalMessage,
101
- optionalModalMessage: state.checkOptionalModalMessage,
102
- continueButtonText: state.checkContinueButtonText,
103
- yesButtonText: state.checkYesButtonText,
104
- noButtonText: state.checkNoButtonText
105
- }
106
- );
107
-
108
- hideVideoOverlay();
109
- state.cropImgRef?.setCheckDisplay?.();
110
- checkCaptureModal.show();
111
- state.isCapturingFront = false;
112
- state.updateHandler?.({ status: 'capture_back_side' });
113
- }
114
- } else {
115
- hideVideoOverlay();
116
- if (state.isDocument) {
117
- const finalized = await fireResultSetter({
118
- ...state.docReadyResult,
119
- frontImage: state.frontImage,
120
- frontLcdResult: state.frontLcdResult,
121
- frontFrontBackResult: state.frontFrontBackResult
122
- });
123
- if (finalized) {
124
- removeOverlay();
125
- return;
126
- }
127
-
128
- state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
129
- if (typeof state.customSubmitHandler === 'function') {
130
- const packageInfo = await ensurePackageUploaded();
131
- state.customSubmitHandler(state.frontImage, packageInfo);
132
- } else {
133
- handleSubmit(state.frontImage);
134
- }
135
- }, removeOverlay);
136
- state.enableSubmit && state.submitButton.show();
137
- }
138
- }
12
+ const doc = store.getActiveDoc();
13
+ state.isCapturingFront = (doc?.pages?.length || 0) === 0;
139
14
  };
140
15
 
141
- export const handleChecksBackAccepted = async () => {
142
- state.blurStatus = false;
143
- state.lcdStatus = false;
16
+ // Camera re-entry for the review gallery (registered as actions.reviewRestart).
17
+ // Set the expected side before restarting so the manual-mode restore logic in
18
+ // newStartLens sees the correct front/back state.
19
+ export const checksReviewRestart = async () => {
20
+ syncCapturingSide();
21
+ await restartCameraForNextCapture();
22
+ };
144
23
 
145
- state.updateHandler?.({ status: 'processing_started' });
146
- state.docReadyResult = await docReady();
147
- state.updateHandler?.({ status: 'processing_completed' });
148
- state.debug_mode && console.log("Back check image processed successfully");
24
+ const buildCheckMeta = () => (state.isCapturingFront
25
+ ? { side: 'front', lcdResult: state.frontLcdResult, frontBackResult: state.frontFrontBackResult }
26
+ : { side: 'back', lcdResult: state.backLcdResult, frontBackResult: state.backFrontBackResult });
149
27
 
28
+ // Commit the validated current side into the review gallery. Also registered as
29
+ // actions.commitCheckSide so the blur / document / LCD modals' "submit anyway"
30
+ // path can accept the current side.
31
+ export const commitCheckSide = async () => {
150
32
  state.cropImgRef?.showSuccessBorder?.();
151
-
152
- hideVideoOverlay();
153
-
154
- refs.checkImagesComponent = createCheckImages(state.container, {
155
- forceLandscape: state.forceLandscapeCheckPreview
156
- });
157
-
158
- try {
159
- const elements = await refs.checkImagesComponent.renderCheckImages(state.frontImage, state.backImage, state.cropImgRef);
160
- if (state.isDocument) {
161
- state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
162
- if (typeof state.customSubmitHandler === 'function') {
163
- const packageInfo = await ensurePackageUploaded();
164
- state.customSubmitHandler(state.frontImage, packageInfo);
165
- } else {
166
- handleSubmit(state.frontImage);
167
- }
168
- }, removeOverlay);
169
- state.enableSubmit && state.submitButton.show();
170
- }
171
-
172
- state.debug_mode && console.log("Setting result setter");
173
- const finalized = await fireResultSetter({
174
- ...state.docReadyResult,
175
- frontImage: state.frontImage,
176
- backImage: state.backImage,
177
- frontLcdResult: state.frontLcdResult,
178
- backLcdResult: state.backLcdResult,
179
- frontFrontBackResult: state.frontFrontBackResult,
180
- backFrontBackResult: state.backFrontBackResult
181
- });
182
- if (finalized) {
183
- removeOverlay();
184
- }
185
- } catch (error) {
186
- console.error('Error rendering check images:', error);
187
- showVideoOverlay();
188
- }
33
+ const { commitCaptureToReview } = await import('../review-flow.js');
34
+ await commitCaptureToReview({ kind: 'image', data: state.finalImage, meta: buildCheckMeta() });
189
35
  };
190
36
 
191
37
  export const captureChecks = async () => {
192
38
  try {
39
+ syncCapturingSide();
40
+
193
41
  if (state.isCapturingFront) {
194
42
  if (state.isManualCheckCapture && state.checkOverlay && state.videoRef) {
195
43
  state.debug_mode && console.log("Using manual check capture mode");
@@ -279,7 +127,7 @@ export const captureChecks = async () => {
279
127
  return;
280
128
  }
281
129
 
282
- await handleChecksFrontAccepted();
130
+ await commitCheckSide();
283
131
  } else {
284
132
  // Back side capture
285
133
  if (state.isManualCheckCapture && state.checkOverlay && state.videoRef) {
@@ -296,6 +144,7 @@ export const captureChecks = async () => {
296
144
  } else {
297
145
  state.backImage = await cropWasm(state.testBlurDetection);
298
146
  }
147
+ state.finalImage = state.backImage;
299
148
 
300
149
  state.debug_mode && console.log("Back capture - Document detected:", state.isDocument);
301
150
  const isDocumentDetected = checkIfDocumentOnCapture();
@@ -329,18 +178,14 @@ export const captureChecks = async () => {
329
178
  }
330
179
 
331
180
  state.backFrontBackResult = null;
332
- console.log("[FrontBack] Back check - enabled:", state.frontBackDetectionForChecks,
333
- "wasmWrapper:", !!refs.wasmWrapper,
334
- "detectorReady:", refs.wasmWrapper?.isFrontBackDetectorReady?.(),
335
- "cropImgRef:", !!state.cropImgRef);
336
181
  if (state.frontBackDetectionForChecks && refs.wasmWrapper?.isFrontBackDetectorReady?.() && state.cropImgRef) {
337
- console.log("[FrontBack] Running front/back detection on back check...");
182
+ state.debug_mode && console.log("[FrontBack] Running front/back detection on back check...");
338
183
  try {
339
184
  const croppedBitmap = await createImageBitmap(state.cropImgRef);
340
185
  state.backFrontBackResult = refs.wasmWrapper.detectFrontBack(croppedBitmap);
341
186
  croppedBitmap.close();
342
187
  state.frontBackStatus = state.backFrontBackResult;
343
- console.log("[FrontBack] Back check result:", state.backFrontBackResult);
188
+ state.debug_mode && console.log("[FrontBack] Back check result:", state.backFrontBackResult);
344
189
  } catch (error) {
345
190
  console.error("[FrontBack] Error running front/back detection on back check:", error);
346
191
  }
@@ -349,7 +194,7 @@ export const captureChecks = async () => {
349
194
  if (state.backFrontBackResult) {
350
195
  const { frontProb, backProb, otherProb } = state.backFrontBackResult;
351
196
  if (frontProb > backProb && frontProb > otherProb) {
352
- console.log("[FrontBack] Wrong side detected on back capture - frontProb is highest:", state.backFrontBackResult);
197
+ state.debug_mode && console.log("[FrontBack] Wrong side detected on back capture - frontProb is highest:", state.backFrontBackResult);
353
198
  if (state.wrongSideModal) {
354
199
  state.wrongSideModal.show('back');
355
200
  state.updateHandler?.({ status: 'wrong_side_detected', expectedSide: 'back', result: state.backFrontBackResult });
@@ -365,7 +210,7 @@ export const captureChecks = async () => {
365
210
  return;
366
211
  }
367
212
 
368
- await handleChecksBackAccepted();
213
+ await commitCheckSide();
369
214
  }
370
215
  } catch (error) {
371
216
  console.error('Error in captureChecks:', error);