veryfi-lens-wasm 3.4.1 → 3.5.0
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 +9 -3
- package/components/captureButton.js +5 -5
- package/components/exitButton.js +4 -10
- package/components/liquid-glass.js +30 -0
- package/components/prescriptionLabelGuide.js +114 -31
- package/components/prescriptionLabelOverlay.js +77 -0
- package/components/radialSpinner.js +50 -0
- package/components/reviewGallery.js +414 -134
- package/components/shared-styles.js +4 -0
- package/components/spinner.js +9 -21
- package/core/api.js +25 -17
- package/core/camera.js +2 -0
- package/core/capture/checks.js +32 -187
- package/core/capture/prescription_label.js +49 -6
- package/core/constants.js +8 -2
- package/core/crop-field-detection.js +15 -9
- package/core/drawing.js +52 -34
- package/core/lifecycle.js +1 -0
- package/core/review-flow.js +106 -15
- package/core/state.js +7 -3
- package/core/ui-renderer.js +19 -16
- package/core/utils.js +44 -0
- 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
|
|
|
@@ -221,7 +223,9 @@ After each accepted capture, the `document`, `anydocs`, and `prescription_label`
|
|
|
221
223
|
| `anydocAddPageText` | `string` | `"Add Page"` | _Deprecated:_ alias for `reviewAddPageText` |
|
|
222
224
|
| `anydocSubmitText` | `string` | `"Submit"` | _Deprecated:_ alias for `reviewSubmitText` |
|
|
223
225
|
| `anydocShowGuide` | `boolean` | `false` | Show a dismissible on-screen text guide explaining how to capture. Auto-hides after each page capture and reappears when the camera restarts for the next page |
|
|
224
|
-
| `anydocGuideText` | `string` | `"Position the document within the frame..."` | Guide text shown for anydocs capture.
|
|
226
|
+
| `anydocGuideText` | `string` | `"Position the document within the frame..."` | Guide text shown for anydocs capture. Separate steps with a blank line (`\n\n`) — each becomes a numbered step |
|
|
227
|
+
| `anydocGuideTitle` | `string` | `"Steps to Capture"` | Heading of the anydocs capture guide panel |
|
|
228
|
+
| `guideShowOnce` | `boolean` | `false` | Show the capture guide only for the first capture of a session instead of re-showing it every time the camera returns for the next capture (multi-capture / QR sessions) |
|
|
225
229
|
|
|
226
230
|
### Bottle Cap Settings (`caps` flavor)
|
|
227
231
|
|
|
@@ -250,8 +254,9 @@ After each accepted capture, the `document`, `anydocs`, and `prescription_label`
|
|
|
250
254
|
| `prescriptionLabelSquareWidthRatio` | `number` | `0.8` | Square overlay width (0-1 relative to viewport) |
|
|
251
255
|
| `prescriptionLabelSquareHeightRatio` | `number` | `0.5` | Square overlay height (0-1 relative to viewport) |
|
|
252
256
|
| `prescriptionLabelShowGuide` | `boolean` | `false` | Show a semi-transparent guide explaining how to record the label. Auto-hides when recording starts and reappears on retake |
|
|
253
|
-
| `prescriptionLabelGuideText` | `string` | `"Position the bottle within the outline.\n\nPress the capture button to start recording
|
|
254
|
-
| `prescriptionLabelSquareGuideText` | `string` | `"Position the prescription label within the square.\n\nPress the capture button to take a photo of the label."` | Guide text shown when the box overlay is active.
|
|
257
|
+
| `prescriptionLabelGuideText` | `string` | `"Position the bottle within the outline.\n\nPress the capture button to start recording.\n\nSlowly rotate the bottle to capture the entire label and press the capture button again to stop recording."` | Guide text shown when the bottle outline overlay is active. Separate steps with a blank line (`\n\n`) — each becomes a numbered step |
|
|
258
|
+
| `prescriptionLabelSquareGuideText` | `string` | `"Position the prescription label within the square.\n\nPress the capture button to take a photo of the label."` | Guide text shown when the box overlay is active. Separate steps with a blank line (`\n\n`) — each becomes a numbered step |
|
|
259
|
+
| `prescriptionLabelGuideTitle` | `string` | `"Steps to Capture"` | Heading of the prescription label capture guide panel |
|
|
255
260
|
| `prescriptionLabelShowOverlayToggle` | `boolean` | `true` | Show a toggle that lets the user switch between the bottle and box overlays during capture. The **bottle** overlay records a video; the **box** overlay captures a still image |
|
|
256
261
|
| `prescriptionLabelBottleLabel` | `string` | `"Bottle"` | Label for the bottle (video) segment of the overlay toggle |
|
|
257
262
|
| `prescriptionLabelBoxLabel` | `string` | `"Box"` | Label for the box (image) segment of the overlay toggle |
|
|
@@ -261,6 +266,7 @@ After each accepted capture, the `document`, `anydocs`, and `prescription_label`
|
|
|
261
266
|
| `prescriptionLabelBoxSideAddText` | `string` | `"Capture another side"` | _Deprecated:_ use `reviewAddPageText` |
|
|
262
267
|
| `prescriptionLabelBoxSideSubmitText` | `string` | `"Submit"` | _Deprecated:_ use `reviewSubmitText` |
|
|
263
268
|
| `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 |
|
|
269
|
+
| `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
270
|
|
|
265
271
|
### Upload Settings (`upload` flavor)
|
|
266
272
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { LIQUID_GLASS, liquidGlassStyles } from './liquid-glass.js';
|
|
2
|
-
|
|
3
1
|
export const createCaptureButton = (container, onCapture, onStopStitching) => {
|
|
4
2
|
const button = document.createElement('button');
|
|
5
3
|
button.id = 'veryfi-capture-button';
|
|
@@ -19,7 +17,9 @@ export const createCaptureButton = (container, onCapture, onStopStitching) => {
|
|
|
19
17
|
outline: 'none',
|
|
20
18
|
pointerEvents: 'auto',
|
|
21
19
|
boxSizing: 'border-box',
|
|
22
|
-
|
|
20
|
+
backgroundColor: '#FFFFFF',
|
|
21
|
+
border: 'none',
|
|
22
|
+
boxShadow: '0 2px 12px rgba(0, 0, 0, 0.25)',
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
@@ -46,11 +46,11 @@ export const createCaptureButton = (container, onCapture, onStopStitching) => {
|
|
|
46
46
|
|
|
47
47
|
// Add hover effect
|
|
48
48
|
button.addEventListener('mouseenter', () => {
|
|
49
|
-
button.style.backgroundColor =
|
|
49
|
+
button.style.backgroundColor = 'var(--capture-button-hover-background-color, rgba(255, 255, 255, 0.85))';
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
button.addEventListener('mouseleave', () => {
|
|
53
|
-
button.style.backgroundColor =
|
|
53
|
+
button.style.backgroundColor = 'var(--capture-button-background-color, #FFFFFF)';
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
let isStitching = false;
|
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
|
|
|
@@ -36,3 +36,33 @@ export const liquidGlassStyles = (overrides = {}) => ({
|
|
|
36
36
|
boxShadow: LIQUID_GLASS.boxShadow,
|
|
37
37
|
...overrides,
|
|
38
38
|
});
|
|
39
|
+
|
|
40
|
+
// Light review-gallery surface (wireframe: pale sage background, white cards,
|
|
41
|
+
// dark icons). Use reviewGalleryStyles() to spread into gallery components.
|
|
42
|
+
export const REVIEW_LIGHT = {
|
|
43
|
+
background: '#E8EBE6',
|
|
44
|
+
cardBackground: '#FFFFFF',
|
|
45
|
+
textColor: '#1A1A1A',
|
|
46
|
+
iconColor: '#1A1A1A',
|
|
47
|
+
mutedText: 'rgba(26, 26, 26, 0.55)',
|
|
48
|
+
border: '1px solid rgba(0, 0, 0, 0.08)',
|
|
49
|
+
tileBorder: '2px solid #FFFFFF',
|
|
50
|
+
addTileBorder: '2px dashed rgba(0, 0, 0, 0.25)',
|
|
51
|
+
addTileBackground: 'rgba(255, 255, 255, 0.6)',
|
|
52
|
+
stripBorder: '1px solid rgba(0, 0, 0, 0.08)',
|
|
53
|
+
toolbarButtonBackground: 'transparent',
|
|
54
|
+
toolbarButtonColor: '#1A1A1A',
|
|
55
|
+
cropBackground: '#E8EBE6',
|
|
56
|
+
cropCancelColor: '#8B2942',
|
|
57
|
+
cropCancelBorder: '1px solid #8B2942',
|
|
58
|
+
cropApplyBackground: '#1A2332',
|
|
59
|
+
cropApplyColor: '#FFFFFF',
|
|
60
|
+
loadingOverlay: 'rgba(232, 235, 230, 0.72)',
|
|
61
|
+
loadingText: '#1A1A1A',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const reviewGalleryStyles = (overrides = {}) => ({
|
|
65
|
+
background: REVIEW_LIGHT.background,
|
|
66
|
+
color: REVIEW_LIGHT.textColor,
|
|
67
|
+
...overrides,
|
|
68
|
+
});
|
|
@@ -1,75 +1,158 @@
|
|
|
1
|
+
import { LIQUID_GLASS } from './liquid-glass.js';
|
|
2
|
+
|
|
3
|
+
const NS = 'http://www.w3.org/2000/svg';
|
|
4
|
+
|
|
5
|
+
const closeIcon = () => {
|
|
6
|
+
const svg = document.createElementNS(NS, 'svg');
|
|
7
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
8
|
+
svg.setAttribute('width', '20');
|
|
9
|
+
svg.setAttribute('height', '20');
|
|
10
|
+
svg.setAttribute('fill', 'none');
|
|
11
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
12
|
+
svg.setAttribute('stroke-width', '2');
|
|
13
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
14
|
+
['M18 6 6 18', 'm6 6 12 12'].forEach((d) => {
|
|
15
|
+
const path = document.createElementNS(NS, 'path');
|
|
16
|
+
path.setAttribute('d', d);
|
|
17
|
+
svg.appendChild(path);
|
|
18
|
+
});
|
|
19
|
+
return svg;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Blank-line-separated paragraphs become the numbered steps.
|
|
23
|
+
const splitSteps = (text) =>
|
|
24
|
+
String(text || '')
|
|
25
|
+
.split(/\n\s*\n/)
|
|
26
|
+
.map((step) => step.trim())
|
|
27
|
+
.filter(Boolean);
|
|
28
|
+
|
|
1
29
|
export const createPrescriptionLabelGuide = (container, options = {}) => {
|
|
2
|
-
const text = options.text || '';
|
|
3
30
|
const id = options.id || 'veryfi-prescription-label-guide';
|
|
31
|
+
const stepNumberColor = options.stepNumberColor || '#22C55E';
|
|
32
|
+
// When set, the guide is shown once per session: subsequent show() calls (the
|
|
33
|
+
// camera re-entry between captures) leave it hidden.
|
|
34
|
+
const showOnce = options.showOnce === true;
|
|
4
35
|
|
|
5
36
|
const guide = document.createElement('div');
|
|
6
37
|
guide.id = id;
|
|
7
38
|
|
|
8
39
|
Object.assign(guide.style, {
|
|
9
40
|
position: 'absolute',
|
|
10
|
-
top: '
|
|
41
|
+
top: '50%',
|
|
11
42
|
left: '50%',
|
|
12
|
-
transform: '
|
|
13
|
-
width
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
43
|
+
transform: 'translate(-50%, -50%)',
|
|
44
|
+
// The parent overlay has a shrink-to-fit width, so a percentage width here
|
|
45
|
+
// would collapse. Size against the viewport instead.
|
|
46
|
+
width: '300px',
|
|
47
|
+
maxWidth: 'calc(100vw - 48px)',
|
|
48
|
+
maxHeight: 'calc(100vh - 120px)',
|
|
49
|
+
overflowY: 'auto',
|
|
50
|
+
padding: '22px 24px 24px',
|
|
51
|
+
backgroundColor: LIQUID_GLASS.darkPanelBackground,
|
|
52
|
+
backdropFilter: LIQUID_GLASS.blur,
|
|
53
|
+
WebkitBackdropFilter: LIQUID_GLASS.blur,
|
|
54
|
+
border: LIQUID_GLASS.darkBorder,
|
|
55
|
+
boxShadow: LIQUID_GLASS.darkPanelBoxShadow,
|
|
17
56
|
color: 'white',
|
|
18
|
-
borderRadius: '
|
|
57
|
+
borderRadius: '20px',
|
|
19
58
|
fontFamily: "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
|
|
20
59
|
fontSize: '14px',
|
|
21
|
-
lineHeight: '1.
|
|
60
|
+
lineHeight: '1.45',
|
|
22
61
|
textAlign: 'left',
|
|
23
|
-
whiteSpace: 'pre-line',
|
|
24
62
|
zIndex: '1003',
|
|
25
63
|
pointerEvents: 'auto',
|
|
26
|
-
backdropFilter: 'blur(8px)',
|
|
27
|
-
WebkitBackdropFilter: 'blur(8px)',
|
|
28
|
-
border: '1px solid rgba(255, 255, 255, 0.2)',
|
|
29
64
|
boxSizing: 'border-box',
|
|
30
65
|
});
|
|
31
66
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
67
|
+
const header = document.createElement('div');
|
|
68
|
+
Object.assign(header.style, {
|
|
69
|
+
display: 'flex',
|
|
70
|
+
alignItems: 'center',
|
|
71
|
+
justifyContent: 'space-between',
|
|
72
|
+
gap: '12px',
|
|
73
|
+
marginBottom: '18px',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const titleEl = document.createElement('div');
|
|
77
|
+
titleEl.textContent = options.title || '';
|
|
78
|
+
Object.assign(titleEl.style, {
|
|
79
|
+
fontSize: '17px',
|
|
80
|
+
fontWeight: '700',
|
|
81
|
+
letterSpacing: '0.2px',
|
|
82
|
+
});
|
|
35
83
|
|
|
36
84
|
const closeButton = document.createElement('button');
|
|
37
85
|
closeButton.id = `${id}-close`;
|
|
38
86
|
closeButton.setAttribute('aria-label', 'Close guide');
|
|
39
|
-
closeButton.textContent = '\u00D7';
|
|
40
87
|
Object.assign(closeButton.style, {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
width: '24px',
|
|
45
|
-
height: '24px',
|
|
88
|
+
flex: '0 0 auto',
|
|
89
|
+
width: '28px',
|
|
90
|
+
height: '28px',
|
|
46
91
|
padding: '0',
|
|
92
|
+
display: 'flex',
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
justifyContent: 'center',
|
|
47
95
|
border: 'none',
|
|
48
96
|
background: 'transparent',
|
|
49
97
|
color: 'white',
|
|
50
|
-
fontSize: '20px',
|
|
51
|
-
lineHeight: '24px',
|
|
52
|
-
fontFamily: 'sans-serif',
|
|
53
98
|
cursor: 'pointer',
|
|
54
|
-
opacity: '0.
|
|
99
|
+
opacity: '0.85',
|
|
55
100
|
pointerEvents: 'auto',
|
|
56
101
|
outline: 'none',
|
|
57
102
|
});
|
|
58
|
-
|
|
103
|
+
closeButton.appendChild(closeIcon());
|
|
59
104
|
closeButton.addEventListener('mouseenter', () => { closeButton.style.opacity = '1'; });
|
|
60
|
-
closeButton.addEventListener('mouseleave', () => { closeButton.style.opacity = '0.
|
|
105
|
+
closeButton.addEventListener('mouseleave', () => { closeButton.style.opacity = '0.85'; });
|
|
61
106
|
closeButton.addEventListener('click', (e) => {
|
|
62
107
|
e.stopPropagation();
|
|
63
108
|
guide.style.display = 'none';
|
|
64
109
|
});
|
|
65
110
|
|
|
66
|
-
|
|
111
|
+
header.appendChild(titleEl);
|
|
112
|
+
header.appendChild(closeButton);
|
|
113
|
+
guide.appendChild(header);
|
|
114
|
+
|
|
115
|
+
const stepsEl = document.createElement('div');
|
|
116
|
+
Object.assign(stepsEl.style, {
|
|
117
|
+
display: 'flex',
|
|
118
|
+
flexDirection: 'column',
|
|
119
|
+
gap: '14px',
|
|
120
|
+
});
|
|
121
|
+
guide.appendChild(stepsEl);
|
|
122
|
+
|
|
123
|
+
const renderSteps = (text) => {
|
|
124
|
+
stepsEl.innerHTML = '';
|
|
125
|
+
splitSteps(text).forEach((step, index) => {
|
|
126
|
+
const row = document.createElement('div');
|
|
127
|
+
const num = document.createElement('span');
|
|
128
|
+
num.textContent = String(index + 1).padStart(2, '0');
|
|
129
|
+
Object.assign(num.style, {
|
|
130
|
+
color: stepNumberColor,
|
|
131
|
+
fontWeight: '700',
|
|
132
|
+
marginRight: '8px',
|
|
133
|
+
});
|
|
134
|
+
row.appendChild(num);
|
|
135
|
+
row.appendChild(document.createTextNode(step));
|
|
136
|
+
stepsEl.appendChild(row);
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
renderSteps(options.text);
|
|
140
|
+
|
|
141
|
+
// The panel is visible on creation, so that already counts as the one showing
|
|
142
|
+
// allowed by showOnce.
|
|
143
|
+
let hasBeenShown = true;
|
|
144
|
+
|
|
67
145
|
container.appendChild(guide);
|
|
68
146
|
|
|
69
147
|
return {
|
|
70
148
|
element: guide,
|
|
71
|
-
|
|
72
|
-
|
|
149
|
+
setTitle: (newTitle) => { titleEl.textContent = newTitle || ''; },
|
|
150
|
+
setText: (newText) => { renderSteps(newText); },
|
|
151
|
+
show: () => {
|
|
152
|
+
if (showOnce && hasBeenShown) return;
|
|
153
|
+
hasBeenShown = true;
|
|
154
|
+
guide.style.display = 'block';
|
|
155
|
+
},
|
|
73
156
|
hide: () => { guide.style.display = 'none'; },
|
|
74
157
|
remove: () => {
|
|
75
158
|
if (guide.parentNode) guide.parentNode.removeChild(guide);
|
|
@@ -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) {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ensureSpinKeyframes } from './shared-styles.js';
|
|
2
|
+
|
|
3
|
+
const SEGMENT_COUNT = 12;
|
|
4
|
+
|
|
5
|
+
/** Radial tick / "leaf" activity indicator (wireframe loading style). */
|
|
6
|
+
export const createRadialSpinner = (options = {}) => {
|
|
7
|
+
const size = options.size ?? 44;
|
|
8
|
+
const color = options.color ?? '#00AA00';
|
|
9
|
+
const duration = options.duration ?? '1s';
|
|
10
|
+
|
|
11
|
+
ensureSpinKeyframes();
|
|
12
|
+
|
|
13
|
+
const root = document.createElement('div');
|
|
14
|
+
if (options.id) root.id = options.id;
|
|
15
|
+
root.setAttribute('role', 'status');
|
|
16
|
+
root.setAttribute('aria-label', options.label ?? 'Loading');
|
|
17
|
+
Object.assign(root.style, {
|
|
18
|
+
position: 'relative',
|
|
19
|
+
width: `${size}px`,
|
|
20
|
+
height: `${size}px`,
|
|
21
|
+
flexShrink: '0',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const barW = Math.max(3, Math.round(size * 0.1));
|
|
25
|
+
const barH = Math.round(size * 0.28);
|
|
26
|
+
const offset = Math.round(size * 0.34);
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < SEGMENT_COUNT; i += 1) {
|
|
29
|
+
const bar = document.createElement('div');
|
|
30
|
+
const angle = (360 / SEGMENT_COUNT) * i;
|
|
31
|
+
Object.assign(bar.style, {
|
|
32
|
+
position: 'absolute',
|
|
33
|
+
left: '50%',
|
|
34
|
+
top: '50%',
|
|
35
|
+
width: `${barW}px`,
|
|
36
|
+
height: `${barH}px`,
|
|
37
|
+
marginLeft: `${-barW / 2}px`,
|
|
38
|
+
marginTop: `${-barH / 2}px`,
|
|
39
|
+
backgroundColor: color,
|
|
40
|
+
borderRadius: `${barW}px`,
|
|
41
|
+
transform: `rotate(${angle}deg) translateY(${-offset}px)`,
|
|
42
|
+
opacity: '0.2',
|
|
43
|
+
animation: `veryfi-radial-fade ${duration} linear infinite`,
|
|
44
|
+
animationDelay: `${-(SEGMENT_COUNT - i) * (parseFloat(duration) / SEGMENT_COUNT)}s`,
|
|
45
|
+
});
|
|
46
|
+
root.appendChild(bar);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return root;
|
|
50
|
+
};
|