@smileid/web-components 11.0.0 → 11.0.1
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 +15 -15
- package/dist/README.md +15 -0
- package/dist/components/README.md +14 -0
- package/dist/components/document/src/README.md +111 -0
- package/dist/components/document/src/document-capture/README.md +90 -0
- package/dist/components/document/src/document-capture-instructions/README.md +56 -0
- package/dist/components/document/src/document-capture-review/README.md +79 -0
- package/dist/components/selfie/README.md +225 -0
- package/dist/components/smart-camera-web/src/README.md +207 -0
- package/dist/domain/camera/src/README.md +38 -0
- package/dist/domain/file-upload/README.md +35 -0
- package/dist/esm/{DocumentCaptureScreens-RECPb0wH.js → DocumentCaptureScreens-DmH2JZDA.js} +2 -2
- package/dist/esm/DocumentCaptureScreens-DmH2JZDA.js.map +1 -0
- package/dist/esm/EndUserConsent-D4fd1ovG.js.map +1 -1
- package/dist/esm/Navigation-CTjK6tLU.js.map +1 -1
- package/dist/esm/PoweredBySmileId-CxbaihMu.js.map +1 -1
- package/dist/esm/{SelfieCaptureScreens-CqBVGEJk.js → SelfieCaptureScreens-DbdN2zNk.js} +2 -2
- package/dist/esm/SelfieCaptureScreens-DbdN2zNk.js.map +1 -0
- package/dist/esm/SignaturePad-C7MtmT8m.js.map +1 -1
- package/dist/esm/TotpConsent-CQU5jQi4.js.map +1 -1
- package/dist/esm/combobox.js.map +1 -1
- package/dist/esm/document.js +1 -1
- package/dist/esm/main.js +2 -2
- package/dist/esm/{package-BDJnoIAU.js → package-bgeQiff6.js} +2 -2
- package/dist/esm/package-bgeQiff6.js.map +1 -0
- package/dist/esm/selfie.js +1 -1
- package/dist/esm/smart-camera-web.js +3 -3
- package/dist/esm/smart-camera-web.js.map +1 -1
- package/dist/esm/styles-BOEZtbuc.js.map +1 -1
- package/dist/package-lock.json +4948 -0
- package/dist/package.json +59 -0
- package/dist/smart-camera-web.js +1 -1
- package/dist/smart-camera-web.js.gz +0 -0
- package/dist/smart-camera-web.js.map +1 -1
- package/dist/src/components/combobox/src/index.js +2 -0
- package/dist/src/components/combobox/src/index.js.map +7 -0
- package/dist/src/components/document/src/index.js +2 -0
- package/dist/src/components/document/src/index.js.map +7 -0
- package/dist/src/components/end-user-consent/src/index.js +14 -0
- package/dist/src/components/end-user-consent/src/index.js.map +7 -0
- package/dist/src/components/selfie/src/index.js +2 -0
- package/dist/src/components/selfie/src/index.js.map +7 -0
- package/dist/src/components/signature-pad/src/index.js +10 -0
- package/dist/src/components/signature-pad/src/index.js.map +7 -0
- package/dist/src/components/smart-camera-web/src/SmartCameraWeb.js +2 -0
- package/dist/src/components/smart-camera-web/src/SmartCameraWeb.js.map +7 -0
- package/dist/src/components/totp-consent/src/index.js +14 -0
- package/dist/src/components/totp-consent/src/index.js.map +7 -0
- package/dist/src/index.js.map +7 -0
- package/dist/styles/README.md +3 -0
- package/dist/types/combobox.d.ts +19 -19
- package/dist/types/document.d.ts +19 -19
- package/dist/types/end-user-consent.d.ts +19 -19
- package/dist/types/main.d.ts +24 -20
- package/dist/types/navigation.d.ts +19 -19
- package/dist/types/selfie.d.ts +19 -19
- package/dist/types/signature-pad.d.ts +19 -19
- package/dist/types/smart-camera-web.d.ts +19 -19
- package/dist/types/totp-consent.d.ts +19 -19
- package/lib/components/README.md +14 -14
- package/lib/components/attribution/PoweredBySmileId.js +42 -42
- package/lib/components/camera-permission/CameraPermission.js +139 -139
- package/lib/components/camera-permission/CameraPermission.stories.js +27 -27
- package/lib/components/combobox/src/Combobox.js +589 -589
- package/lib/components/combobox/src/index.js +1 -1
- package/lib/components/document/src/DocumentCaptureScreens.js +410 -410
- package/lib/components/document/src/DocumentCaptureScreens.stories.js +57 -57
- package/lib/components/document/src/README.md +111 -111
- package/lib/components/document/src/document-capture/DocumentCapture.js +760 -760
- package/lib/components/document/src/document-capture/DocumentCapture.stories.js +78 -78
- package/lib/components/document/src/document-capture/README.md +90 -90
- package/lib/components/document/src/document-capture/index.js +3 -3
- package/lib/components/document/src/document-capture-instructions/DocumentCaptureInstructions.js +545 -545
- package/lib/components/document/src/document-capture-instructions/DocumentCaptureInstructions.stories.js +24 -24
- package/lib/components/document/src/document-capture-instructions/README.md +56 -56
- package/lib/components/document/src/document-capture-instructions/index.js +3 -3
- package/lib/components/document/src/document-capture-review/DocumentCaptureReview.js +360 -360
- package/lib/components/document/src/document-capture-review/DocumentCaptureReview.stories.js +24 -24
- package/lib/components/document/src/document-capture-review/README.md +79 -79
- package/lib/components/document/src/document-capture-review/index.js +3 -3
- package/lib/components/document/src/index.js +3 -3
- package/lib/components/end-user-consent/src/EndUserConsent.js +795 -795
- package/lib/components/end-user-consent/src/EndUserConsent.stories.js +29 -29
- package/lib/components/end-user-consent/src/index.js +4 -4
- package/lib/components/navigation/src/Navigation.js +171 -171
- package/lib/components/navigation/src/Navigation.stories.js +24 -24
- package/lib/components/navigation/src/index.js +3 -3
- package/lib/components/selfie/README.md +225 -225
- package/lib/components/selfie/src/SelfieCaptureScreens.js +420 -420
- package/lib/components/selfie/src/SelfieCaptureScreens.stories.js +29 -29
- package/lib/components/selfie/src/index.js +3 -3
- package/lib/components/selfie/src/selfie-capture/SelfieCapture.js +1099 -1099
- package/lib/components/selfie/src/selfie-capture/SelfieCapture.stories.js +36 -36
- package/lib/components/selfie/src/selfie-capture/index.js +3 -3
- package/lib/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.js +689 -689
- package/lib/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.stories.js +23 -23
- package/lib/components/selfie/src/selfie-capture-instructions/index.js +3 -3
- package/lib/components/selfie/src/selfie-capture-review/SelfieCaptureReview.js +209 -209
- package/lib/components/selfie/src/selfie-capture-review/SelfieCaptureReview.stories.js +24 -24
- package/lib/components/selfie/src/selfie-capture-review/index.js +3 -3
- package/lib/components/selfie/src/selfie-capture-wrapper/SelfieCaptureWrapper.tsx +256 -256
- package/lib/components/selfie/src/selfie-capture-wrapper/index.ts +1 -1
- package/lib/components/selfie/src/smartselfie-capture/OvalProgress.tsx +81 -81
- package/lib/components/selfie/src/smartselfie-capture/SmartSelfieCapture.tsx +265 -265
- package/lib/components/selfie/src/smartselfie-capture/components/AlertDisplay.tsx +34 -34
- package/lib/components/selfie/src/smartselfie-capture/components/CameraPreview.tsx +97 -97
- package/lib/components/selfie/src/smartselfie-capture/components/CaptureControls.tsx +78 -78
- package/lib/components/selfie/src/smartselfie-capture/components/index.ts +3 -3
- package/lib/components/selfie/src/smartselfie-capture/constants.ts +23 -23
- package/lib/components/selfie/src/smartselfie-capture/hooks/index.ts +2 -2
- package/lib/components/selfie/src/smartselfie-capture/hooks/useCamera.ts +238 -238
- package/lib/components/selfie/src/smartselfie-capture/hooks/useFaceCapture.ts +618 -618
- package/lib/components/selfie/src/smartselfie-capture/index.ts +1 -1
- package/lib/components/selfie/src/smartselfie-capture/utils/alertMessages.ts +13 -13
- package/lib/components/selfie/src/smartselfie-capture/utils/canvas.ts +105 -105
- package/lib/components/selfie/src/smartselfie-capture/utils/faceDetection.ts +129 -129
- package/lib/components/selfie/src/smartselfie-capture/utils/imageCapture.ts +64 -64
- package/lib/components/selfie/src/smartselfie-capture/utils/index.ts +4 -4
- package/lib/components/selfie/src/smartselfie-capture/utils/mediapipeManager.ts +77 -77
- package/lib/components/signature-pad/package-lock.json +3009 -3009
- package/lib/components/signature-pad/package.json +30 -30
- package/lib/components/signature-pad/src/SignaturePad.js +484 -484
- package/lib/components/signature-pad/src/SignaturePad.stories.js +32 -32
- package/lib/components/signature-pad/src/index.js +3 -3
- package/lib/components/smart-camera-web/src/README.md +206 -206
- package/lib/components/smart-camera-web/src/SmartCameraWeb.js +305 -305
- package/lib/components/smart-camera-web/src/SmartCameraWeb.stories.js +57 -57
- package/lib/components/totp-consent/src/TotpConsent.js +949 -949
- package/lib/components/totp-consent/src/index.js +4 -4
- package/lib/domain/camera/src/README.md +38 -38
- package/lib/domain/camera/src/SmartCamera.js +109 -109
- package/lib/domain/constants/src/Constants.js +27 -27
- package/lib/domain/file-upload/README.md +35 -35
- package/lib/domain/file-upload/src/SmartFileUpload.js +65 -65
- package/lib/styles/README.md +3 -3
- package/lib/styles/src/styles.js +372 -372
- package/lib/styles/src/typography.js +52 -52
- package/package.json +111 -112
- package/dist/esm/DocumentCaptureScreens-RECPb0wH.js.map +0 -1
- package/dist/esm/SelfieCaptureScreens-CqBVGEJk.js.map +0 -1
- package/dist/esm/package-BDJnoIAU.js.map +0 -1
|
@@ -1,256 +1,256 @@
|
|
|
1
|
-
import { useState, useEffect } from 'preact/hooks';
|
|
2
|
-
import { IconLoader2 } from '@tabler/icons-preact';
|
|
3
|
-
import register from 'preact-custom-element';
|
|
4
|
-
import type { FunctionComponent } from 'preact';
|
|
5
|
-
|
|
6
|
-
import { getBoolProp } from '@/utils/props';
|
|
7
|
-
import SmartSelfieCapture from '../smartselfie-capture/SmartSelfieCapture';
|
|
8
|
-
import '../selfie-capture/SelfieCapture';
|
|
9
|
-
import { getMediapipeInstance } from '../smartselfie-capture/utils/mediapipeManager';
|
|
10
|
-
|
|
11
|
-
interface Props {
|
|
12
|
-
timeout?: number;
|
|
13
|
-
interval?: number;
|
|
14
|
-
duration?: number;
|
|
15
|
-
'theme-color'?: string;
|
|
16
|
-
'show-navigation'?: string | boolean;
|
|
17
|
-
'allow-agent-mode'?: string | boolean;
|
|
18
|
-
'show-agent-mode-for-tests'?: string | boolean;
|
|
19
|
-
'hide-attribution'?: string | boolean;
|
|
20
|
-
'disable-image-tests'?: string | boolean;
|
|
21
|
-
key?: string;
|
|
22
|
-
'start-countdown'?: string | boolean;
|
|
23
|
-
hidden?: string | boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const SelfieCaptureWrapper: FunctionComponent<Props> = ({
|
|
27
|
-
timeout = 20000,
|
|
28
|
-
'start-countdown': startCountdownProp = false,
|
|
29
|
-
hidden: hiddenProp = false,
|
|
30
|
-
...props
|
|
31
|
-
}) => {
|
|
32
|
-
const isParentCypress = (() => {
|
|
33
|
-
try {
|
|
34
|
-
return (
|
|
35
|
-
!!(window.parent as any).Cypress ||
|
|
36
|
-
(window.parent.navigator.userAgent.includes('Electron') &&
|
|
37
|
-
(window.parent as any).__Cypress)
|
|
38
|
-
);
|
|
39
|
-
} catch {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
})();
|
|
43
|
-
const isCypress =
|
|
44
|
-
isParentCypress ||
|
|
45
|
-
!!(window as any).Cypress ||
|
|
46
|
-
(window.navigator.userAgent.includes('Electron') &&
|
|
47
|
-
(window as any).__Cypress);
|
|
48
|
-
|
|
49
|
-
const hidden = getBoolProp(hiddenProp);
|
|
50
|
-
const startCountdown = getBoolProp(startCountdownProp);
|
|
51
|
-
const [mediapipeReady, setMediapipeReady] = useState(false);
|
|
52
|
-
const [loadingProgress, setLoadingProgress] = useState(isCypress ? 100 : 0);
|
|
53
|
-
const [initialSessionCompleted, setInitialSessionCompleted] = useState(false);
|
|
54
|
-
const [mediapipeLoading, setMediapipeLoading] = useState(false);
|
|
55
|
-
const [usingSelfieCapture, setUsingSelfieCapture] = useState(false);
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (mediapipeReady || mediapipeLoading || isCypress) return;
|
|
59
|
-
|
|
60
|
-
const loadMediapipe = async () => {
|
|
61
|
-
setMediapipeLoading(true);
|
|
62
|
-
try {
|
|
63
|
-
await getMediapipeInstance();
|
|
64
|
-
setMediapipeReady(true);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error('Failed to load Mediapipe:', error);
|
|
67
|
-
}
|
|
68
|
-
setMediapipeLoading(false);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
loadMediapipe();
|
|
72
|
-
}, [mediapipeReady, mediapipeLoading]);
|
|
73
|
-
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
if (hidden || !startCountdown || mediapipeReady) return undefined;
|
|
76
|
-
|
|
77
|
-
const timer = setInterval(() => {
|
|
78
|
-
setLoadingProgress((prev: number) => Math.min(prev + 1, 100));
|
|
79
|
-
}, timeout / 100);
|
|
80
|
-
|
|
81
|
-
return () => {
|
|
82
|
-
clearInterval(timer);
|
|
83
|
-
};
|
|
84
|
-
}, [hidden, startCountdown, timeout, mediapipeReady]);
|
|
85
|
-
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
if (hidden || mediapipeReady || loadingProgress < 100) return undefined;
|
|
88
|
-
|
|
89
|
-
const setupEventForwarding = () => {
|
|
90
|
-
const selfieCapture = document.querySelector('selfie-capture');
|
|
91
|
-
if (
|
|
92
|
-
selfieCapture &&
|
|
93
|
-
!selfieCapture.hasAttribute('data-backup-events-setup')
|
|
94
|
-
) {
|
|
95
|
-
selfieCapture.setAttribute('data-backup-events-setup', 'true');
|
|
96
|
-
|
|
97
|
-
const forwardEvent = (event: Event) => {
|
|
98
|
-
const customEvent = event as CustomEvent;
|
|
99
|
-
window.dispatchEvent(
|
|
100
|
-
new CustomEvent(customEvent.type, {
|
|
101
|
-
detail: customEvent.detail,
|
|
102
|
-
bubbles: true,
|
|
103
|
-
}),
|
|
104
|
-
);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
selfieCapture.addEventListener('selfie-capture.publish', forwardEvent);
|
|
108
|
-
selfieCapture.addEventListener(
|
|
109
|
-
'selfie-capture.cancelled',
|
|
110
|
-
forwardEvent,
|
|
111
|
-
);
|
|
112
|
-
selfieCapture.addEventListener('selfie-capture.close', forwardEvent);
|
|
113
|
-
|
|
114
|
-
return () => {
|
|
115
|
-
selfieCapture.removeEventListener(
|
|
116
|
-
'selfie-capture.publish',
|
|
117
|
-
forwardEvent,
|
|
118
|
-
);
|
|
119
|
-
selfieCapture.removeEventListener(
|
|
120
|
-
'selfie-capture.cancelled',
|
|
121
|
-
forwardEvent,
|
|
122
|
-
);
|
|
123
|
-
selfieCapture.removeEventListener(
|
|
124
|
-
'selfie-capture.close',
|
|
125
|
-
forwardEvent,
|
|
126
|
-
);
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
return undefined;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const timeoutId = setTimeout(setupEventForwarding, 200);
|
|
133
|
-
return () => {
|
|
134
|
-
clearTimeout(timeoutId);
|
|
135
|
-
};
|
|
136
|
-
}, [hidden, mediapipeReady, loadingProgress]);
|
|
137
|
-
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
if (hidden || mediapipeLoading) return;
|
|
140
|
-
|
|
141
|
-
const smartCameraWeb = document.querySelector('smart-camera-web');
|
|
142
|
-
smartCameraWeb?.dispatchEvent(
|
|
143
|
-
new CustomEvent('metadata.active-liveness-version', {
|
|
144
|
-
detail: {
|
|
145
|
-
version: usingSelfieCapture ? '0.0.1' : '1.0.0',
|
|
146
|
-
},
|
|
147
|
-
}),
|
|
148
|
-
);
|
|
149
|
-
}, [usingSelfieCapture, hidden, mediapipeLoading]);
|
|
150
|
-
|
|
151
|
-
if (hidden) {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// on retakes, prefer SmartSelfieCapture if Mediapipe is ready
|
|
156
|
-
if (initialSessionCompleted && mediapipeReady && !usingSelfieCapture) {
|
|
157
|
-
return <SmartSelfieCapture {...props} />;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// use SmartSelfieCapture if mediapipe loads
|
|
161
|
-
if (!initialSessionCompleted && mediapipeReady && !usingSelfieCapture) {
|
|
162
|
-
return <SmartSelfieCapture {...props} />;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (loadingProgress >= 100) {
|
|
166
|
-
if (!usingSelfieCapture) {
|
|
167
|
-
setUsingSelfieCapture(true);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const propsWithoutHidden = { ...props };
|
|
171
|
-
delete (propsWithoutHidden as any).hidden;
|
|
172
|
-
|
|
173
|
-
return (
|
|
174
|
-
// @ts-ignore
|
|
175
|
-
<selfie-capture
|
|
176
|
-
{...propsWithoutHidden}
|
|
177
|
-
ref={(el: HTMLElement) => {
|
|
178
|
-
if (el && !el.hasAttribute('data-events-setup')) {
|
|
179
|
-
el.setAttribute('data-events-setup', 'true');
|
|
180
|
-
|
|
181
|
-
const forwardEvent = (event: Event) => {
|
|
182
|
-
const customEvent = event as CustomEvent;
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
customEvent.type === 'selfie-capture.publish' ||
|
|
186
|
-
customEvent.type === 'selfie-capture.cancelled' ||
|
|
187
|
-
customEvent.type === 'selfie-capture.close'
|
|
188
|
-
) {
|
|
189
|
-
setInitialSessionCompleted(true);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
window.dispatchEvent(
|
|
193
|
-
new CustomEvent(customEvent.type, {
|
|
194
|
-
detail: customEvent.detail,
|
|
195
|
-
bubbles: true,
|
|
196
|
-
}),
|
|
197
|
-
);
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
el.addEventListener('selfie-capture.publish', forwardEvent);
|
|
201
|
-
el.addEventListener('selfie-capture.cancelled', forwardEvent);
|
|
202
|
-
el.addEventListener('selfie-capture.close', forwardEvent);
|
|
203
|
-
}
|
|
204
|
-
}}
|
|
205
|
-
/>
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return (
|
|
210
|
-
<div style={{ textAlign: 'center', marginTop: '20%' }}>
|
|
211
|
-
<div
|
|
212
|
-
style={{
|
|
213
|
-
marginBottom: '16px',
|
|
214
|
-
display: 'flex',
|
|
215
|
-
justifyContent: 'center',
|
|
216
|
-
}}
|
|
217
|
-
>
|
|
218
|
-
<IconLoader2
|
|
219
|
-
size={48}
|
|
220
|
-
style={{ animation: 'spin 1s linear infinite' }}
|
|
221
|
-
/>
|
|
222
|
-
</div>
|
|
223
|
-
<p>Loading... {loadingProgress}%</p>
|
|
224
|
-
<style>{`
|
|
225
|
-
@keyframes spin {
|
|
226
|
-
from { transform: rotate(0deg); }
|
|
227
|
-
to { transform: rotate(360deg); }
|
|
228
|
-
}
|
|
229
|
-
`}</style>
|
|
230
|
-
</div>
|
|
231
|
-
);
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
if (!customElements.get('selfie-capture-wrapper')) {
|
|
235
|
-
register(
|
|
236
|
-
SelfieCaptureWrapper,
|
|
237
|
-
'selfie-capture-wrapper',
|
|
238
|
-
[
|
|
239
|
-
'timeout',
|
|
240
|
-
'interval',
|
|
241
|
-
'duration',
|
|
242
|
-
'theme-color',
|
|
243
|
-
'show-navigation',
|
|
244
|
-
'allow-agent-mode',
|
|
245
|
-
'show-agent-mode-for-tests',
|
|
246
|
-
'hide-attribution',
|
|
247
|
-
'disable-image-tests',
|
|
248
|
-
'key',
|
|
249
|
-
'start-countdown',
|
|
250
|
-
'hidden',
|
|
251
|
-
],
|
|
252
|
-
{ shadow: true },
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export default SelfieCaptureWrapper;
|
|
1
|
+
import { useState, useEffect } from 'preact/hooks';
|
|
2
|
+
import { IconLoader2 } from '@tabler/icons-preact';
|
|
3
|
+
import register from 'preact-custom-element';
|
|
4
|
+
import type { FunctionComponent } from 'preact';
|
|
5
|
+
|
|
6
|
+
import { getBoolProp } from '@/utils/props';
|
|
7
|
+
import SmartSelfieCapture from '../smartselfie-capture/SmartSelfieCapture';
|
|
8
|
+
import '../selfie-capture/SelfieCapture';
|
|
9
|
+
import { getMediapipeInstance } from '../smartselfie-capture/utils/mediapipeManager';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
timeout?: number;
|
|
13
|
+
interval?: number;
|
|
14
|
+
duration?: number;
|
|
15
|
+
'theme-color'?: string;
|
|
16
|
+
'show-navigation'?: string | boolean;
|
|
17
|
+
'allow-agent-mode'?: string | boolean;
|
|
18
|
+
'show-agent-mode-for-tests'?: string | boolean;
|
|
19
|
+
'hide-attribution'?: string | boolean;
|
|
20
|
+
'disable-image-tests'?: string | boolean;
|
|
21
|
+
key?: string;
|
|
22
|
+
'start-countdown'?: string | boolean;
|
|
23
|
+
hidden?: string | boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const SelfieCaptureWrapper: FunctionComponent<Props> = ({
|
|
27
|
+
timeout = 20000,
|
|
28
|
+
'start-countdown': startCountdownProp = false,
|
|
29
|
+
hidden: hiddenProp = false,
|
|
30
|
+
...props
|
|
31
|
+
}) => {
|
|
32
|
+
const isParentCypress = (() => {
|
|
33
|
+
try {
|
|
34
|
+
return (
|
|
35
|
+
!!(window.parent as any).Cypress ||
|
|
36
|
+
(window.parent.navigator.userAgent.includes('Electron') &&
|
|
37
|
+
(window.parent as any).__Cypress)
|
|
38
|
+
);
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
})();
|
|
43
|
+
const isCypress =
|
|
44
|
+
isParentCypress ||
|
|
45
|
+
!!(window as any).Cypress ||
|
|
46
|
+
(window.navigator.userAgent.includes('Electron') &&
|
|
47
|
+
(window as any).__Cypress);
|
|
48
|
+
|
|
49
|
+
const hidden = getBoolProp(hiddenProp);
|
|
50
|
+
const startCountdown = getBoolProp(startCountdownProp);
|
|
51
|
+
const [mediapipeReady, setMediapipeReady] = useState(false);
|
|
52
|
+
const [loadingProgress, setLoadingProgress] = useState(isCypress ? 100 : 0);
|
|
53
|
+
const [initialSessionCompleted, setInitialSessionCompleted] = useState(false);
|
|
54
|
+
const [mediapipeLoading, setMediapipeLoading] = useState(false);
|
|
55
|
+
const [usingSelfieCapture, setUsingSelfieCapture] = useState(false);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (mediapipeReady || mediapipeLoading || isCypress) return;
|
|
59
|
+
|
|
60
|
+
const loadMediapipe = async () => {
|
|
61
|
+
setMediapipeLoading(true);
|
|
62
|
+
try {
|
|
63
|
+
await getMediapipeInstance();
|
|
64
|
+
setMediapipeReady(true);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('Failed to load Mediapipe:', error);
|
|
67
|
+
}
|
|
68
|
+
setMediapipeLoading(false);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
loadMediapipe();
|
|
72
|
+
}, [mediapipeReady, mediapipeLoading]);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (hidden || !startCountdown || mediapipeReady) return undefined;
|
|
76
|
+
|
|
77
|
+
const timer = setInterval(() => {
|
|
78
|
+
setLoadingProgress((prev: number) => Math.min(prev + 1, 100));
|
|
79
|
+
}, timeout / 100);
|
|
80
|
+
|
|
81
|
+
return () => {
|
|
82
|
+
clearInterval(timer);
|
|
83
|
+
};
|
|
84
|
+
}, [hidden, startCountdown, timeout, mediapipeReady]);
|
|
85
|
+
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (hidden || mediapipeReady || loadingProgress < 100) return undefined;
|
|
88
|
+
|
|
89
|
+
const setupEventForwarding = () => {
|
|
90
|
+
const selfieCapture = document.querySelector('selfie-capture');
|
|
91
|
+
if (
|
|
92
|
+
selfieCapture &&
|
|
93
|
+
!selfieCapture.hasAttribute('data-backup-events-setup')
|
|
94
|
+
) {
|
|
95
|
+
selfieCapture.setAttribute('data-backup-events-setup', 'true');
|
|
96
|
+
|
|
97
|
+
const forwardEvent = (event: Event) => {
|
|
98
|
+
const customEvent = event as CustomEvent;
|
|
99
|
+
window.dispatchEvent(
|
|
100
|
+
new CustomEvent(customEvent.type, {
|
|
101
|
+
detail: customEvent.detail,
|
|
102
|
+
bubbles: true,
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
selfieCapture.addEventListener('selfie-capture.publish', forwardEvent);
|
|
108
|
+
selfieCapture.addEventListener(
|
|
109
|
+
'selfie-capture.cancelled',
|
|
110
|
+
forwardEvent,
|
|
111
|
+
);
|
|
112
|
+
selfieCapture.addEventListener('selfie-capture.close', forwardEvent);
|
|
113
|
+
|
|
114
|
+
return () => {
|
|
115
|
+
selfieCapture.removeEventListener(
|
|
116
|
+
'selfie-capture.publish',
|
|
117
|
+
forwardEvent,
|
|
118
|
+
);
|
|
119
|
+
selfieCapture.removeEventListener(
|
|
120
|
+
'selfie-capture.cancelled',
|
|
121
|
+
forwardEvent,
|
|
122
|
+
);
|
|
123
|
+
selfieCapture.removeEventListener(
|
|
124
|
+
'selfie-capture.close',
|
|
125
|
+
forwardEvent,
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const timeoutId = setTimeout(setupEventForwarding, 200);
|
|
133
|
+
return () => {
|
|
134
|
+
clearTimeout(timeoutId);
|
|
135
|
+
};
|
|
136
|
+
}, [hidden, mediapipeReady, loadingProgress]);
|
|
137
|
+
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if (hidden || mediapipeLoading) return;
|
|
140
|
+
|
|
141
|
+
const smartCameraWeb = document.querySelector('smart-camera-web');
|
|
142
|
+
smartCameraWeb?.dispatchEvent(
|
|
143
|
+
new CustomEvent('metadata.active-liveness-version', {
|
|
144
|
+
detail: {
|
|
145
|
+
version: usingSelfieCapture ? '0.0.1' : '1.0.0',
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
}, [usingSelfieCapture, hidden, mediapipeLoading]);
|
|
150
|
+
|
|
151
|
+
if (hidden) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// on retakes, prefer SmartSelfieCapture if Mediapipe is ready
|
|
156
|
+
if (initialSessionCompleted && mediapipeReady && !usingSelfieCapture) {
|
|
157
|
+
return <SmartSelfieCapture {...props} />;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// use SmartSelfieCapture if mediapipe loads
|
|
161
|
+
if (!initialSessionCompleted && mediapipeReady && !usingSelfieCapture) {
|
|
162
|
+
return <SmartSelfieCapture {...props} />;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (loadingProgress >= 100) {
|
|
166
|
+
if (!usingSelfieCapture) {
|
|
167
|
+
setUsingSelfieCapture(true);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const propsWithoutHidden = { ...props };
|
|
171
|
+
delete (propsWithoutHidden as any).hidden;
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
<selfie-capture
|
|
176
|
+
{...propsWithoutHidden}
|
|
177
|
+
ref={(el: HTMLElement) => {
|
|
178
|
+
if (el && !el.hasAttribute('data-events-setup')) {
|
|
179
|
+
el.setAttribute('data-events-setup', 'true');
|
|
180
|
+
|
|
181
|
+
const forwardEvent = (event: Event) => {
|
|
182
|
+
const customEvent = event as CustomEvent;
|
|
183
|
+
|
|
184
|
+
if (
|
|
185
|
+
customEvent.type === 'selfie-capture.publish' ||
|
|
186
|
+
customEvent.type === 'selfie-capture.cancelled' ||
|
|
187
|
+
customEvent.type === 'selfie-capture.close'
|
|
188
|
+
) {
|
|
189
|
+
setInitialSessionCompleted(true);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
window.dispatchEvent(
|
|
193
|
+
new CustomEvent(customEvent.type, {
|
|
194
|
+
detail: customEvent.detail,
|
|
195
|
+
bubbles: true,
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
el.addEventListener('selfie-capture.publish', forwardEvent);
|
|
201
|
+
el.addEventListener('selfie-capture.cancelled', forwardEvent);
|
|
202
|
+
el.addEventListener('selfie-capture.close', forwardEvent);
|
|
203
|
+
}
|
|
204
|
+
}}
|
|
205
|
+
/>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<div style={{ textAlign: 'center', marginTop: '20%' }}>
|
|
211
|
+
<div
|
|
212
|
+
style={{
|
|
213
|
+
marginBottom: '16px',
|
|
214
|
+
display: 'flex',
|
|
215
|
+
justifyContent: 'center',
|
|
216
|
+
}}
|
|
217
|
+
>
|
|
218
|
+
<IconLoader2
|
|
219
|
+
size={48}
|
|
220
|
+
style={{ animation: 'spin 1s linear infinite' }}
|
|
221
|
+
/>
|
|
222
|
+
</div>
|
|
223
|
+
<p>Loading... {loadingProgress}%</p>
|
|
224
|
+
<style>{`
|
|
225
|
+
@keyframes spin {
|
|
226
|
+
from { transform: rotate(0deg); }
|
|
227
|
+
to { transform: rotate(360deg); }
|
|
228
|
+
}
|
|
229
|
+
`}</style>
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
if (!customElements.get('selfie-capture-wrapper')) {
|
|
235
|
+
register(
|
|
236
|
+
SelfieCaptureWrapper,
|
|
237
|
+
'selfie-capture-wrapper',
|
|
238
|
+
[
|
|
239
|
+
'timeout',
|
|
240
|
+
'interval',
|
|
241
|
+
'duration',
|
|
242
|
+
'theme-color',
|
|
243
|
+
'show-navigation',
|
|
244
|
+
'allow-agent-mode',
|
|
245
|
+
'show-agent-mode-for-tests',
|
|
246
|
+
'hide-attribution',
|
|
247
|
+
'disable-image-tests',
|
|
248
|
+
'key',
|
|
249
|
+
'start-countdown',
|
|
250
|
+
'hidden',
|
|
251
|
+
],
|
|
252
|
+
{ shadow: true },
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export default SelfieCaptureWrapper;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as SelfieCaptureWrapper } from './SelfieCaptureWrapper';
|
|
1
|
+
export { default as SelfieCaptureWrapper } from './SelfieCaptureWrapper';
|