veryfi-lens-wasm 3.4.0 → 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 +3 -0
- package/components/exitButton.js +4 -10
- package/components/prescriptionLabelOverlay.js +77 -0
- package/components/reviewGallery.js +162 -42
- package/core/capture/checks.js +32 -187
- package/core/capture/prescription_label.js +49 -6
- package/core/constants.js +3 -1
- package/core/drawing.js +52 -34
- package/core/review-flow.js +83 -10
- package/core/state.js +4 -3
- package/core/ui-renderer.js +8 -14
- package/core/wasm-processing.js +70 -11
- package/flavors/checks.js +8 -3
- package/flavors/upload.js +1 -3
- package/package.json +1 -1
- package/wasm/wasm.js +190 -0
- package/components/checkCaptureModal.js +0 -27
- package/components/checkImages.js +0 -175
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
|
|
package/components/exitButton.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LIQUID_GLASS, liquidGlassStyles } from './liquid-glass.js';
|
|
2
2
|
|
|
3
|
-
export const createExitButton = (container, options,
|
|
4
|
-
const {
|
|
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 (
|
|
82
|
-
|
|
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,
|
|
@@ -108,17 +153,18 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
108
153
|
|
|
109
154
|
topBar.appendChild(titleEl);
|
|
110
155
|
|
|
111
|
-
// Document strip (horizontal): one tile per document.
|
|
156
|
+
// Document strip (horizontal): one tile per document, plus an "add" tile.
|
|
112
157
|
const stripEl = document.createElement('div');
|
|
113
158
|
stripEl.id = 'veryfi-review-doc-strip';
|
|
114
159
|
Object.assign(stripEl.style, {
|
|
115
160
|
display: 'none',
|
|
116
161
|
gap: '8px',
|
|
117
|
-
padding: '
|
|
162
|
+
padding: '10px 16px',
|
|
118
163
|
overflowX: 'auto',
|
|
119
164
|
WebkitOverflowScrolling: 'touch',
|
|
120
165
|
overscrollBehavior: 'contain',
|
|
121
166
|
flex: '0 0 auto',
|
|
167
|
+
borderTop: '1px solid rgba(255, 255, 255, 0.12)',
|
|
122
168
|
});
|
|
123
169
|
|
|
124
170
|
// Main scrollable page grid for the active document.
|
|
@@ -160,34 +206,27 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
160
206
|
...liquidGlassStyles(bg ? { backgroundColor: bg } : {}),
|
|
161
207
|
});
|
|
162
208
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
addPageButton.textContent = o.addPageText;
|
|
166
|
-
Object.assign(addPageButton.style, pillStyle());
|
|
167
|
-
addPageButton.addEventListener('click', () => callbacks.onAddPage?.());
|
|
168
|
-
|
|
169
|
-
const addDocButton = document.createElement('button');
|
|
170
|
-
addDocButton.id = 'veryfi-review-add-doc';
|
|
171
|
-
addDocButton.textContent = o.addDocumentText;
|
|
172
|
-
Object.assign(addDocButton.style, pillStyle());
|
|
173
|
-
addDocButton.addEventListener('click', () => callbacks.onAddDocument?.());
|
|
174
|
-
|
|
209
|
+
// Single, prominent primary action. Add Page / Add Document are inline "+"
|
|
210
|
+
// tiles in the grid / document strip, so the action bar stays uncluttered.
|
|
175
211
|
const submitButton = document.createElement('button');
|
|
176
212
|
submitButton.id = 'veryfi-review-submit';
|
|
177
213
|
submitButton.textContent = o.submitText;
|
|
178
|
-
Object.assign(submitButton.style, pillStyle(
|
|
214
|
+
Object.assign(submitButton.style, pillStyle(o.submitButtonColor), {
|
|
215
|
+
flex: '1 1 auto',
|
|
216
|
+
maxWidth: '420px',
|
|
217
|
+
textAlign: 'center',
|
|
218
|
+
fontSize: '16px',
|
|
219
|
+
padding: '10px 24px',
|
|
220
|
+
color: o.submitButtonTextColor,
|
|
221
|
+
});
|
|
179
222
|
submitButton.addEventListener('click', async () => {
|
|
180
223
|
if (submitButton.disabled) return;
|
|
181
224
|
submitButton.disabled = true;
|
|
182
|
-
addPageButton.disabled = true;
|
|
183
|
-
addDocButton.disabled = true;
|
|
184
225
|
try {
|
|
185
226
|
await callbacks.onSubmit?.();
|
|
186
227
|
} catch (error) {
|
|
187
228
|
console.error('Review gallery submit failed:', error);
|
|
188
229
|
submitButton.disabled = false;
|
|
189
|
-
addPageButton.disabled = false;
|
|
190
|
-
addDocButton.disabled = false;
|
|
191
230
|
}
|
|
192
231
|
});
|
|
193
232
|
|
|
@@ -202,11 +241,10 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
202
241
|
display: o.showClose ? 'flex' : 'none',
|
|
203
242
|
alignItems: 'center',
|
|
204
243
|
justifyContent: 'center',
|
|
244
|
+
flex: '0 0 auto',
|
|
205
245
|
});
|
|
206
246
|
exitButton.addEventListener('click', () => callbacks.onClose?.());
|
|
207
247
|
|
|
208
|
-
actionsEl.appendChild(addPageButton);
|
|
209
|
-
actionsEl.appendChild(addDocButton);
|
|
210
248
|
actionsEl.appendChild(submitButton);
|
|
211
249
|
actionsEl.appendChild(exitButton);
|
|
212
250
|
|
|
@@ -220,8 +258,9 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
220
258
|
document.addEventListener('keydown', onKeyDown);
|
|
221
259
|
|
|
222
260
|
root.appendChild(topBar);
|
|
223
|
-
root.appendChild(stripEl);
|
|
224
261
|
root.appendChild(gridEl);
|
|
262
|
+
// Document thumbnails row lives at the bottom, just above the primary action.
|
|
263
|
+
root.appendChild(stripEl);
|
|
225
264
|
root.appendChild(actionsEl);
|
|
226
265
|
container.appendChild(root);
|
|
227
266
|
|
|
@@ -366,7 +405,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
366
405
|
const box = document.createElement('div');
|
|
367
406
|
Object.assign(box.style, {
|
|
368
407
|
position: 'absolute',
|
|
369
|
-
border:
|
|
408
|
+
border: `2px solid ${o.submitButtonColor}`,
|
|
370
409
|
boxShadow: '0 0 0 9999px rgba(0, 0, 0, 0.5)',
|
|
371
410
|
boxSizing: 'border-box',
|
|
372
411
|
cursor: 'move',
|
|
@@ -379,7 +418,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
379
418
|
position: 'absolute',
|
|
380
419
|
width: '22px',
|
|
381
420
|
height: '22px',
|
|
382
|
-
background:
|
|
421
|
+
background: o.submitButtonColor,
|
|
383
422
|
borderRadius: '50%',
|
|
384
423
|
[corner.includes('n') ? 'top' : 'bottom']: '-11px',
|
|
385
424
|
[corner.includes('w') ? 'left' : 'right']: '-11px',
|
|
@@ -406,7 +445,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
406
445
|
Object.assign(cancelBtn.style, pillStyle());
|
|
407
446
|
const applyBtn = document.createElement('button');
|
|
408
447
|
applyBtn.textContent = o.cropText;
|
|
409
|
-
Object.assign(applyBtn.style, pillStyle(
|
|
448
|
+
Object.assign(applyBtn.style, pillStyle(o.submitButtonColor), { color: o.submitButtonTextColor });
|
|
410
449
|
bar.appendChild(cancelBtn);
|
|
411
450
|
bar.appendChild(applyBtn);
|
|
412
451
|
|
|
@@ -541,6 +580,45 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
541
580
|
return img;
|
|
542
581
|
};
|
|
543
582
|
|
|
583
|
+
// Dashed "+" tile used to add a document (strip) or a page (grid).
|
|
584
|
+
const buildAddTile = (label, onClick, sizeStyle = {}) => {
|
|
585
|
+
const tile = document.createElement('button');
|
|
586
|
+
tile.classList.add('veryfi-rg-tile');
|
|
587
|
+
Object.assign(tile.style, {
|
|
588
|
+
flex: '0 0 auto',
|
|
589
|
+
display: 'flex',
|
|
590
|
+
flexDirection: 'column',
|
|
591
|
+
alignItems: 'center',
|
|
592
|
+
justifyContent: 'center',
|
|
593
|
+
gap: '4px',
|
|
594
|
+
borderRadius: '10px',
|
|
595
|
+
cursor: 'pointer',
|
|
596
|
+
color: 'white',
|
|
597
|
+
background: 'rgba(255, 255, 255, 0.06)',
|
|
598
|
+
border: '2px dashed rgba(255, 255, 255, 0.45)',
|
|
599
|
+
padding: '4px',
|
|
600
|
+
...sizeStyle,
|
|
601
|
+
});
|
|
602
|
+
const plus = document.createElement('span');
|
|
603
|
+
plus.textContent = '+';
|
|
604
|
+
Object.assign(plus.style, { fontSize: '26px', lineHeight: '1', fontWeight: '400' });
|
|
605
|
+
const lbl = document.createElement('span');
|
|
606
|
+
lbl.textContent = label;
|
|
607
|
+
Object.assign(lbl.style, {
|
|
608
|
+
fontSize: '11px',
|
|
609
|
+
fontWeight: '600',
|
|
610
|
+
textAlign: 'center',
|
|
611
|
+
lineHeight: '1.1',
|
|
612
|
+
});
|
|
613
|
+
tile.appendChild(plus);
|
|
614
|
+
tile.appendChild(lbl);
|
|
615
|
+
tile.addEventListener('click', (e) => {
|
|
616
|
+
e.stopPropagation();
|
|
617
|
+
onClick();
|
|
618
|
+
});
|
|
619
|
+
return tile;
|
|
620
|
+
};
|
|
621
|
+
|
|
544
622
|
const renderStrip = () => {
|
|
545
623
|
const multiDoc = o.showDocumentStrip && (docs.length > 1 || o.allowAddDocument);
|
|
546
624
|
stripEl.style.display = multiDoc ? 'flex' : 'none';
|
|
@@ -549,12 +627,14 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
549
627
|
|
|
550
628
|
docs.forEach((doc, index) => {
|
|
551
629
|
const tile = document.createElement('button');
|
|
630
|
+
tile.classList.add('veryfi-rg-tile');
|
|
631
|
+
tile.style.animationDelay = `${index * 45}ms`;
|
|
552
632
|
const isActive = index === activeIndex;
|
|
553
633
|
Object.assign(tile.style, {
|
|
554
634
|
position: 'relative',
|
|
555
635
|
flex: '0 0 auto',
|
|
556
|
-
width: '
|
|
557
|
-
height: '
|
|
636
|
+
width: '65px',
|
|
637
|
+
height: '60px',
|
|
558
638
|
borderRadius: '10px',
|
|
559
639
|
overflow: 'hidden',
|
|
560
640
|
cursor: 'pointer',
|
|
@@ -591,18 +671,30 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
591
671
|
});
|
|
592
672
|
stripEl.appendChild(tile);
|
|
593
673
|
});
|
|
674
|
+
|
|
675
|
+
if (o.allowAddDocument && canAddDocument) {
|
|
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);
|
|
682
|
+
}
|
|
594
683
|
};
|
|
595
684
|
|
|
596
685
|
// Single detail view (with the action toolbar) for one page. Used both for a
|
|
597
686
|
// one-page session and when a grid tile is tapped (focused page).
|
|
598
687
|
const buildDetailCell = (page, docIndex, pageIndex, { showBack }) => {
|
|
599
688
|
const cell = document.createElement('div');
|
|
689
|
+
cell.classList.add('veryfi-rg-detail');
|
|
600
690
|
Object.assign(cell.style, {
|
|
601
691
|
position: 'relative',
|
|
602
692
|
display: 'flex',
|
|
603
693
|
flexDirection: 'column',
|
|
604
694
|
alignItems: 'center',
|
|
695
|
+
justifyContent: 'center',
|
|
605
696
|
gap: '12px',
|
|
697
|
+
minHeight: '100%',
|
|
606
698
|
});
|
|
607
699
|
|
|
608
700
|
// Toolbar sits above the image (not overlapping it): optional back, then
|
|
@@ -617,6 +709,8 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
617
709
|
flexWrap: 'wrap',
|
|
618
710
|
flex: '0 0 auto',
|
|
619
711
|
});
|
|
712
|
+
// Don't dismiss when interacting with the toolbar area.
|
|
713
|
+
toolbar.addEventListener('click', (e) => e.stopPropagation());
|
|
620
714
|
if (showBack) {
|
|
621
715
|
toolbar.appendChild(
|
|
622
716
|
toolButton('arrow-left', o.backText, () => {
|
|
@@ -668,6 +762,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
668
762
|
thumb.style.maxHeight = '62vh';
|
|
669
763
|
thumb.style.maxHeight = '62dvh';
|
|
670
764
|
if (thumb.tagName === 'VIDEO') thumb.controls = true;
|
|
765
|
+
thumb.addEventListener('click', (e) => e.stopPropagation());
|
|
671
766
|
media.appendChild(thumb);
|
|
672
767
|
cell.appendChild(media);
|
|
673
768
|
|
|
@@ -677,9 +772,11 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
677
772
|
// Grid tile for the multi-page overview: tapping it opens the page detail.
|
|
678
773
|
const buildGridTile = (page, pageIndex) => {
|
|
679
774
|
const cell = document.createElement('div');
|
|
775
|
+
cell.classList.add('veryfi-rg-tile');
|
|
680
776
|
Object.assign(cell.style, {
|
|
681
777
|
position: 'relative',
|
|
682
778
|
borderRadius: '10px',
|
|
779
|
+
border: '2px solid white',
|
|
683
780
|
overflow: 'hidden',
|
|
684
781
|
background: '#000',
|
|
685
782
|
aspectRatio: '3 / 4',
|
|
@@ -692,7 +789,8 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
692
789
|
thumb.style.pointerEvents = 'none';
|
|
693
790
|
if (thumb.tagName === 'VIDEO') thumb.controls = false;
|
|
694
791
|
cell.appendChild(thumb);
|
|
695
|
-
cell.addEventListener('click', () => {
|
|
792
|
+
cell.addEventListener('click', (e) => {
|
|
793
|
+
e.stopPropagation();
|
|
696
794
|
focusedIndex = pageIndex;
|
|
697
795
|
renderGrid();
|
|
698
796
|
});
|
|
@@ -743,33 +841,51 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
743
841
|
if (focusedIndex !== null && (focusedIndex < 0 || focusedIndex >= pages.length)) {
|
|
744
842
|
focusedIndex = null;
|
|
745
843
|
}
|
|
746
|
-
const
|
|
747
|
-
//
|
|
748
|
-
//
|
|
749
|
-
const
|
|
844
|
+
const allowAddPageNow = o.allowAddPage && canAddPage;
|
|
845
|
+
// Show the overview grid when there are multiple pages or the user can add
|
|
846
|
+
// pages (so the "+" tile is reachable); otherwise show the lone page detail.
|
|
847
|
+
const showGrid = pages.length > 1 || allowAddPageNow;
|
|
848
|
+
|
|
849
|
+
// Detail view: an explicitly focused page, or the single page when there's
|
|
850
|
+
// no grid to show.
|
|
851
|
+
let detailIndex = focusedIndex;
|
|
852
|
+
if (detailIndex === null && !showGrid && pages.length === 1) {
|
|
853
|
+
detailIndex = 0;
|
|
854
|
+
}
|
|
750
855
|
|
|
751
856
|
if (detailIndex !== null) {
|
|
752
857
|
gridEl.style.gridTemplateColumns = '1fr';
|
|
858
|
+
// Clicking the backdrop (anywhere in the grid area that isn't the toolbar
|
|
859
|
+
// or the image — including below the image) returns to the gallery grid.
|
|
860
|
+
// Only when there is a grid to go back to.
|
|
861
|
+
gridEl.onclick = showGrid
|
|
862
|
+
? () => {
|
|
863
|
+
focusedIndex = null;
|
|
864
|
+
renderGrid();
|
|
865
|
+
}
|
|
866
|
+
: null;
|
|
753
867
|
gridEl.appendChild(
|
|
754
|
-
buildDetailCell(pages[detailIndex], activeIndex, detailIndex, { showBack:
|
|
868
|
+
buildDetailCell(pages[detailIndex], activeIndex, detailIndex, { showBack: showGrid })
|
|
755
869
|
);
|
|
756
870
|
return;
|
|
757
871
|
}
|
|
872
|
+
gridEl.onclick = null;
|
|
758
873
|
|
|
759
|
-
// Larger previews: ~2 columns on phones (roughly 6 tiles visible per view)
|
|
760
|
-
// instead of the previous denser 120px grid.
|
|
761
874
|
gridEl.style.gridTemplateColumns = 'repeat(auto-fill, minmax(150px, 1fr))';
|
|
762
875
|
pages.forEach((page, pageIndex) => {
|
|
763
|
-
|
|
876
|
+
const tile = buildGridTile(page, pageIndex);
|
|
877
|
+
tile.style.animationDelay = `${pageIndex * 45}ms`;
|
|
878
|
+
gridEl.appendChild(tile);
|
|
764
879
|
});
|
|
880
|
+
if (allowAddPageNow) {
|
|
881
|
+
const addTile = buildAddTile(o.addPageText, () => callbacks.onAddPage?.(), { aspectRatio: '3 / 4' });
|
|
882
|
+
addTile.style.animationDelay = `${pages.length * 45}ms`;
|
|
883
|
+
gridEl.appendChild(addTile);
|
|
884
|
+
}
|
|
765
885
|
};
|
|
766
886
|
|
|
767
887
|
const renderActions = () => {
|
|
768
|
-
addPageButton.disabled = false;
|
|
769
|
-
addDocButton.disabled = false;
|
|
770
888
|
submitButton.disabled = false;
|
|
771
|
-
addPageButton.style.display = o.allowAddPage && canAddPage ? 'inline-block' : 'none';
|
|
772
|
-
addDocButton.style.display = o.allowAddDocument && canAddDocument ? 'inline-block' : 'none';
|
|
773
889
|
submitButton.textContent = o.submitText;
|
|
774
890
|
};
|
|
775
891
|
|
|
@@ -796,14 +912,18 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
|
|
|
796
912
|
show: (payload) => {
|
|
797
913
|
render(payload);
|
|
798
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');
|
|
799
921
|
},
|
|
800
922
|
hide: () => {
|
|
801
923
|
root.style.display = 'none';
|
|
802
924
|
},
|
|
803
925
|
setSubmitting: (submitting) => {
|
|
804
926
|
submitButton.disabled = submitting;
|
|
805
|
-
addPageButton.disabled = submitting;
|
|
806
|
-
addDocButton.disabled = submitting;
|
|
807
927
|
},
|
|
808
928
|
remove: () => {
|
|
809
929
|
document.removeEventListener('keydown', onKeyDown);
|