@smileid/web-components 11.0.0 → 11.0.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 +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-CRx5ymqY.js} +2 -2
- package/dist/esm/DocumentCaptureScreens-CRx5ymqY.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-DuQjKt_K.js} +274 -257
- package/dist/esm/SelfieCaptureScreens-DuQjKt_K.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-C_cKNrUu.js} +2 -2
- package/dist/esm/package-C_cKNrUu.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 +23 -23
- 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 +281 -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 +118 -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,281 @@
|
|
|
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
|
-
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
'
|
|
18
|
-
'show-
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
|
|
22
|
-
'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
selfieCapture
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
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
|
+
// Legacy web component fallback (used when Mediapipe isn't available)
|
|
9
|
+
import '../selfie-capture/SelfieCapture';
|
|
10
|
+
// Mediapipe loader/manager used by SmartSelfieCapture
|
|
11
|
+
import { getMediapipeInstance } from '../smartselfie-capture/utils/mediapipeManager';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
timeout?: number;
|
|
15
|
+
interval?: number;
|
|
16
|
+
duration?: number;
|
|
17
|
+
'theme-color'?: string;
|
|
18
|
+
'show-navigation'?: string | boolean;
|
|
19
|
+
'allow-agent-mode'?: string | boolean;
|
|
20
|
+
'show-agent-mode-for-tests'?: string | boolean;
|
|
21
|
+
'hide-attribution'?: string | boolean;
|
|
22
|
+
'disable-image-tests'?: string | boolean;
|
|
23
|
+
key?: string;
|
|
24
|
+
'start-countdown'?: string | boolean;
|
|
25
|
+
hidden?: string | boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Wrapper component that decides whether to use the modern
|
|
29
|
+
// SmartSelfieCapture (Mediapipe-based) or fallback to the legacy `selfie-capture`
|
|
30
|
+
// web component after a timeout of 20 seconds.
|
|
31
|
+
const SelfieCaptureWrapper: FunctionComponent<Props> = ({
|
|
32
|
+
timeout = 20000,
|
|
33
|
+
'start-countdown': startCountdownProp = false,
|
|
34
|
+
hidden: hiddenProp = false,
|
|
35
|
+
...props
|
|
36
|
+
}) => {
|
|
37
|
+
// Detect if tests are running under Cypress/Electron (affects loading behavior)
|
|
38
|
+
const isParentCypress = (() => {
|
|
39
|
+
try {
|
|
40
|
+
return (
|
|
41
|
+
!!(window.parent as any).Cypress ||
|
|
42
|
+
(window.parent.navigator.userAgent.includes('Electron') &&
|
|
43
|
+
(window.parent as any).__Cypress)
|
|
44
|
+
);
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
49
|
+
const isCypress =
|
|
50
|
+
isParentCypress ||
|
|
51
|
+
!!(window as any).Cypress ||
|
|
52
|
+
(window.navigator.userAgent.includes('Electron') &&
|
|
53
|
+
(window as any).__Cypress);
|
|
54
|
+
|
|
55
|
+
const hidden = getBoolProp(hiddenProp);
|
|
56
|
+
const startCountdown = getBoolProp(startCountdownProp);
|
|
57
|
+
// Component state:
|
|
58
|
+
// - mediapipeReady: whether the mediapipe instance has successfully loaded
|
|
59
|
+
// - loadingProgress: percentage used for the visible loading UI
|
|
60
|
+
// - initialSessionCompleted: set when the legacy component emits publish/cancel/close
|
|
61
|
+
// - mediapipeLoading: true while attempting to load mediapipe
|
|
62
|
+
// - usingSelfieCapture: whether we've mounted the legacy `selfie-capture` element
|
|
63
|
+
const [mediapipeReady, setMediapipeReady] = useState(false);
|
|
64
|
+
const [loadingProgress, setLoadingProgress] = useState(isCypress ? 100 : 0);
|
|
65
|
+
const [initialSessionCompleted, setInitialSessionCompleted] = useState(false);
|
|
66
|
+
const [mediapipeLoading, setMediapipeLoading] = useState(false);
|
|
67
|
+
const [usingSelfieCapture, setUsingSelfieCapture] = useState(false);
|
|
68
|
+
|
|
69
|
+
// Attempt to load Mediapipe (once). If Mediapipe is already ready, loading,
|
|
70
|
+
// or running under Cypress, skip the attempt. This side-effect flips
|
|
71
|
+
// mediapipeReady/mediapipeLoading flags which control which component is used.
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (mediapipeReady || mediapipeLoading || isCypress) return;
|
|
74
|
+
|
|
75
|
+
const loadMediapipe = async () => {
|
|
76
|
+
setMediapipeLoading(true);
|
|
77
|
+
try {
|
|
78
|
+
await getMediapipeInstance();
|
|
79
|
+
setMediapipeReady(true);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
// Loading failed; we'll fall back to the legacy selfie-capture component
|
|
82
|
+
// after the loadingProgress reaches 100%.
|
|
83
|
+
console.error('Failed to load Mediapipe:', error);
|
|
84
|
+
}
|
|
85
|
+
setMediapipeLoading(false);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
loadMediapipe();
|
|
89
|
+
}, [mediapipeReady, mediapipeLoading]);
|
|
90
|
+
|
|
91
|
+
// When using the loading countdown (startCountdown), increment the
|
|
92
|
+
// visible loading progress. This is only used while mediapipe hasn't
|
|
93
|
+
// reported ready; once mediapipeReady becomes true we stop the timer.
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (hidden || !startCountdown || mediapipeReady) return undefined;
|
|
96
|
+
|
|
97
|
+
const timer = setInterval(() => {
|
|
98
|
+
setLoadingProgress((prev: number) => Math.min(prev + 1, 100));
|
|
99
|
+
}, timeout / 100);
|
|
100
|
+
|
|
101
|
+
return () => {
|
|
102
|
+
clearInterval(timer);
|
|
103
|
+
};
|
|
104
|
+
}, [hidden, startCountdown, timeout, mediapipeReady]);
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (hidden || mediapipeReady || loadingProgress < 100) return undefined;
|
|
108
|
+
|
|
109
|
+
const setupEventForwarding = () => {
|
|
110
|
+
const selfieCapture = document.querySelector('selfie-capture');
|
|
111
|
+
if (
|
|
112
|
+
selfieCapture &&
|
|
113
|
+
!selfieCapture.hasAttribute('data-backup-events-setup')
|
|
114
|
+
) {
|
|
115
|
+
selfieCapture.setAttribute('data-backup-events-setup', 'true');
|
|
116
|
+
|
|
117
|
+
const forwardEvent = (event: Event) => {
|
|
118
|
+
const customEvent = event as CustomEvent;
|
|
119
|
+
window.dispatchEvent(
|
|
120
|
+
new CustomEvent(customEvent.type, {
|
|
121
|
+
detail: customEvent.detail,
|
|
122
|
+
bubbles: true,
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
selfieCapture.addEventListener('selfie-capture.publish', forwardEvent);
|
|
128
|
+
selfieCapture.addEventListener(
|
|
129
|
+
'selfie-capture.cancelled',
|
|
130
|
+
forwardEvent,
|
|
131
|
+
);
|
|
132
|
+
selfieCapture.addEventListener('selfie-capture.close', forwardEvent);
|
|
133
|
+
|
|
134
|
+
return () => {
|
|
135
|
+
selfieCapture.removeEventListener(
|
|
136
|
+
'selfie-capture.publish',
|
|
137
|
+
forwardEvent,
|
|
138
|
+
);
|
|
139
|
+
selfieCapture.removeEventListener(
|
|
140
|
+
'selfie-capture.cancelled',
|
|
141
|
+
forwardEvent,
|
|
142
|
+
);
|
|
143
|
+
selfieCapture.removeEventListener(
|
|
144
|
+
'selfie-capture.close',
|
|
145
|
+
forwardEvent,
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const timeoutId = setTimeout(setupEventForwarding, 200);
|
|
153
|
+
return () => {
|
|
154
|
+
clearTimeout(timeoutId);
|
|
155
|
+
};
|
|
156
|
+
}, [hidden, mediapipeReady, loadingProgress]);
|
|
157
|
+
|
|
158
|
+
// Announce to any `smart-camera-web` element which liveness version is active.
|
|
159
|
+
// The old capture users 0.0.1, the new one 1.0.0.
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (hidden || mediapipeLoading) return;
|
|
162
|
+
|
|
163
|
+
const smartCameraWeb = document.querySelector('smart-camera-web');
|
|
164
|
+
smartCameraWeb?.dispatchEvent(
|
|
165
|
+
new CustomEvent('metadata.active-liveness-version', {
|
|
166
|
+
detail: {
|
|
167
|
+
version: usingSelfieCapture ? '0.0.1' : '1.0.0',
|
|
168
|
+
},
|
|
169
|
+
}),
|
|
170
|
+
);
|
|
171
|
+
}, [usingSelfieCapture, hidden, mediapipeLoading]);
|
|
172
|
+
|
|
173
|
+
if (hidden) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// on retakes, prefer SmartSelfieCapture if Mediapipe is ready
|
|
178
|
+
if (initialSessionCompleted && mediapipeReady && !usingSelfieCapture) {
|
|
179
|
+
return <SmartSelfieCapture {...props} />;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// use SmartSelfieCapture if mediapipe loads
|
|
183
|
+
if (!initialSessionCompleted && mediapipeReady && !usingSelfieCapture) {
|
|
184
|
+
return <SmartSelfieCapture {...props} />;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (loadingProgress >= 100) {
|
|
188
|
+
// When loading completes without Mediapipe becoming ready, mount the legacy
|
|
189
|
+
// `selfie-capture` web component. We also set `usingSelfieCapture` so other
|
|
190
|
+
// effects can react (e.g. metadata dispatch).
|
|
191
|
+
if (!usingSelfieCapture) {
|
|
192
|
+
setUsingSelfieCapture(true);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const propsWithoutHidden = { ...props };
|
|
196
|
+
delete (propsWithoutHidden as any).hidden;
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
// @ts-ignore
|
|
200
|
+
<selfie-capture
|
|
201
|
+
{...propsWithoutHidden}
|
|
202
|
+
ref={(el: HTMLElement) => {
|
|
203
|
+
if (el && !el.hasAttribute('data-events-setup')) {
|
|
204
|
+
el.setAttribute('data-events-setup', 'true');
|
|
205
|
+
|
|
206
|
+
const forwardEvent = (event: Event) => {
|
|
207
|
+
const customEvent = event as CustomEvent;
|
|
208
|
+
|
|
209
|
+
if (
|
|
210
|
+
customEvent.type === 'selfie-capture.publish' ||
|
|
211
|
+
customEvent.type === 'selfie-capture.cancelled' ||
|
|
212
|
+
customEvent.type === 'selfie-capture.close'
|
|
213
|
+
) {
|
|
214
|
+
setInitialSessionCompleted(true);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
window.dispatchEvent(
|
|
218
|
+
new CustomEvent(customEvent.type, {
|
|
219
|
+
detail: customEvent.detail,
|
|
220
|
+
bubbles: true,
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
el.addEventListener('selfie-capture.publish', forwardEvent);
|
|
226
|
+
el.addEventListener('selfie-capture.cancelled', forwardEvent);
|
|
227
|
+
el.addEventListener('selfie-capture.close', forwardEvent);
|
|
228
|
+
}
|
|
229
|
+
}}
|
|
230
|
+
/>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<div style={{ textAlign: 'center', marginTop: '20%' }}>
|
|
236
|
+
<div
|
|
237
|
+
style={{
|
|
238
|
+
marginBottom: '16px',
|
|
239
|
+
display: 'flex',
|
|
240
|
+
justifyContent: 'center',
|
|
241
|
+
}}
|
|
242
|
+
>
|
|
243
|
+
<IconLoader2
|
|
244
|
+
size={48}
|
|
245
|
+
style={{ animation: 'spin 1s linear infinite' }}
|
|
246
|
+
/>
|
|
247
|
+
</div>
|
|
248
|
+
<p>Loading... {loadingProgress}%</p>
|
|
249
|
+
<style>{`
|
|
250
|
+
@keyframes spin {
|
|
251
|
+
from { transform: rotate(0deg); }
|
|
252
|
+
to { transform: rotate(360deg); }
|
|
253
|
+
}
|
|
254
|
+
`}</style>
|
|
255
|
+
</div>
|
|
256
|
+
);
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
if (!customElements.get('selfie-capture-wrapper')) {
|
|
260
|
+
register(
|
|
261
|
+
SelfieCaptureWrapper,
|
|
262
|
+
'selfie-capture-wrapper',
|
|
263
|
+
[
|
|
264
|
+
'timeout',
|
|
265
|
+
'interval',
|
|
266
|
+
'duration',
|
|
267
|
+
'theme-color',
|
|
268
|
+
'show-navigation',
|
|
269
|
+
'allow-agent-mode',
|
|
270
|
+
'show-agent-mode-for-tests',
|
|
271
|
+
'hide-attribution',
|
|
272
|
+
'disable-image-tests',
|
|
273
|
+
'key',
|
|
274
|
+
'start-countdown',
|
|
275
|
+
'hidden',
|
|
276
|
+
],
|
|
277
|
+
{ shadow: true },
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export default SelfieCaptureWrapper;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as SelfieCaptureWrapper } from './SelfieCaptureWrapper';
|
|
1
|
+
export { default as SelfieCaptureWrapper } from './SelfieCaptureWrapper';
|