@smileid/web-components 2.0.0 → 2.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/package.json +58 -58
- package/src/components/README.md +14 -14
- package/src/components/attribution/PoweredBySmileId.js +42 -42
- package/src/components/camera-permission/CameraPermission.js +140 -140
- package/src/components/camera-permission/CameraPermission.stories.js +27 -27
- package/src/components/combobox/src/Combobox.js +589 -589
- package/src/components/combobox/src/index.js +1 -1
- package/src/components/document/src/DocumentCaptureScreens.js +409 -409
- package/src/components/document/src/DocumentCaptureScreens.stories.js +57 -57
- package/src/components/document/src/README.md +111 -111
- package/src/components/document/src/document-capture/DocumentCapture.js +760 -760
- package/src/components/document/src/document-capture/DocumentCapture.stories.js +78 -78
- package/src/components/document/src/document-capture/README.md +90 -90
- package/src/components/document/src/document-capture/index.js +3 -3
- package/src/components/document/src/document-capture-instructions/DocumentCaptureInstructions.js +499 -499
- package/src/components/document/src/document-capture-instructions/DocumentCaptureInstructions.stories.js +24 -24
- package/src/components/document/src/document-capture-instructions/README.md +56 -56
- package/src/components/document/src/document-capture-instructions/index.js +3 -3
- package/src/components/document/src/document-capture-review/DocumentCaptureReview.js +362 -362
- package/src/components/document/src/document-capture-review/DocumentCaptureReview.stories.js +24 -24
- package/src/components/document/src/document-capture-review/README.md +79 -79
- package/src/components/document/src/document-capture-review/index.js +3 -3
- package/src/components/document/src/index.js +3 -3
- package/src/components/end-user-consent/src/EndUserConsent.js +795 -795
- package/src/components/end-user-consent/src/EndUserConsent.stories.js +29 -29
- package/src/components/end-user-consent/src/index.js +4 -4
- package/src/components/navigation/src/Navigation.js +171 -171
- package/src/components/navigation/src/Navigation.stories.js +24 -24
- package/src/components/navigation/src/index.js +3 -3
- package/src/components/selfie/README.md +225 -225
- package/src/components/selfie/src/SelfieCaptureScreens.js +282 -282
- package/src/components/selfie/src/SelfieCaptureScreens.stories.js +29 -29
- package/src/components/selfie/src/index.js +5 -5
- package/src/components/selfie/src/selfie-capture/SelfieCapture.js +1041 -1010
- package/src/components/selfie/src/selfie-capture/SelfieCapture.stories.js +36 -36
- package/src/components/selfie/src/selfie-capture/index.js +3 -3
- package/src/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.js +657 -648
- package/src/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.stories.js +23 -23
- package/src/components/selfie/src/selfie-capture-instructions/index.js +3 -3
- package/src/components/selfie/src/selfie-capture-review/SelfieCaptureReview.js +347 -347
- package/src/components/selfie/src/selfie-capture-review/SelfieCaptureReview.stories.js +24 -24
- package/src/components/selfie/src/selfie-capture-review/index.js +3 -3
- package/src/components/signature-pad/package-lock.json +3009 -3009
- package/src/components/signature-pad/package.json +30 -30
- package/src/components/signature-pad/src/SignaturePad.js +484 -484
- package/src/components/signature-pad/src/SignaturePad.stories.js +32 -32
- package/src/components/signature-pad/src/index.js +3 -3
- package/src/components/smart-camera-web/src/README.md +207 -207
- package/src/components/smart-camera-web/src/SmartCameraWeb.js +299 -299
- package/src/components/smart-camera-web/src/SmartCameraWeb.stories.js +57 -57
- package/src/components/totp-consent/src/TotpConsent.js +949 -949
- package/src/components/totp-consent/src/index.js +4 -4
- package/src/domain/camera/src/README.md +38 -38
- package/src/domain/camera/src/SmartCamera.js +109 -109
- package/src/domain/constants/src/Constants.js +27 -27
- package/src/domain/file-upload/README.md +35 -35
- package/src/domain/file-upload/src/SmartFileUpload.js +65 -65
- package/src/index.js +5 -5
- package/src/styles/README.md +3 -3
- package/src/styles/src/styles.js +359 -359
- package/src/styles/src/typography.js +52 -52
|
@@ -1,409 +1,409 @@
|
|
|
1
|
-
import { IMAGE_TYPE } from '../../../domain/constants/src/Constants';
|
|
2
|
-
import styles from '../../../styles/src/styles';
|
|
3
|
-
import SmartCamera from '../../../domain/camera/src/SmartCamera';
|
|
4
|
-
|
|
5
|
-
import './document-capture';
|
|
6
|
-
import './document-capture-review';
|
|
7
|
-
import './document-capture-instructions';
|
|
8
|
-
import packageJson from '../../../../package.json';
|
|
9
|
-
|
|
10
|
-
const COMPONENTS_VERSION = packageJson.version;
|
|
11
|
-
|
|
12
|
-
const smartCameraWeb = document.querySelector('smart-camera-web');
|
|
13
|
-
|
|
14
|
-
async function getPermissions(captureScreen) {
|
|
15
|
-
try {
|
|
16
|
-
const stream = await SmartCamera.getMedia({
|
|
17
|
-
audio: false,
|
|
18
|
-
video: SmartCamera.environmentOptions,
|
|
19
|
-
});
|
|
20
|
-
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
21
|
-
const videoDevice = devices.find(
|
|
22
|
-
(device) =>
|
|
23
|
-
device.kind === 'videoinput' &&
|
|
24
|
-
stream.getVideoTracks()[0].getSettings().deviceId === device.deviceId,
|
|
25
|
-
);
|
|
26
|
-
smartCameraWeb?.dispatchEvent(
|
|
27
|
-
new CustomEvent('metadata.camera-name', {
|
|
28
|
-
detail: { cameraName: videoDevice?.label },
|
|
29
|
-
}),
|
|
30
|
-
);
|
|
31
|
-
captureScreen.removeAttribute('data-camera-error');
|
|
32
|
-
captureScreen.setAttribute('data-camera-ready', true);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
captureScreen.removeAttribute('data-camera-ready');
|
|
35
|
-
captureScreen.setAttribute(
|
|
36
|
-
'data-camera-error',
|
|
37
|
-
SmartCamera.handleCameraError(error),
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
class DocumentCaptureScreens extends HTMLElement {
|
|
43
|
-
constructor() {
|
|
44
|
-
super();
|
|
45
|
-
this.activeScreen = null;
|
|
46
|
-
this.smartCameraWeb = this.closest('smart-camera-web');
|
|
47
|
-
smartCameraWeb?.dispatchEvent(new CustomEvent('metadata.initialize'));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
connectedCallback() {
|
|
51
|
-
this.innerHTML = `
|
|
52
|
-
${styles(this.themeColor)}
|
|
53
|
-
<div>
|
|
54
|
-
<document-capture-instructions theme-color='${this.themeColor}' id='document-capture-instructions-front' ${this.title}
|
|
55
|
-
${this.documentCaptureModes} ${this.showNavigation} ${this.hideInstructions ? 'hidden' : ''}
|
|
56
|
-
${this.hideAttribution}
|
|
57
|
-
></document-capture-instructions>
|
|
58
|
-
<document-capture id='document-capture-front' side-of-id='Front'
|
|
59
|
-
${this.title} ${this.showNavigation} ${this.hideInstructions ? '' : 'hidden'} ${this.hideAttribution}
|
|
60
|
-
${this.documentCaptureModes} ${this.documentType} theme-color='${this.themeColor}'
|
|
61
|
-
></document-capture>
|
|
62
|
-
<document-capture-instructions id='document-capture-instructions-back' side-of-id='Back' title='Submit Back of ID'
|
|
63
|
-
${this.documentCaptureModes} ${this.showNavigation} theme-color='${this.themeColor}' ${this.hideAttribution} hidden
|
|
64
|
-
></document-capture-instructions>
|
|
65
|
-
<document-capture id='document-capture-back' side-of-id='Back' ${this.title} ${this.showNavigation}
|
|
66
|
-
${this.documentCaptureModes} theme-color='${this.themeColor}' ${this.hideAttribution}
|
|
67
|
-
hidden
|
|
68
|
-
></document-capture>
|
|
69
|
-
<document-capture-review id='front-of-document-capture-review' theme-color='${this.themeColor}' ${this.hideAttribution} hidden></document-capture-review>
|
|
70
|
-
<document-capture-review id='back-of-document-capture-review' theme-color='${this.themeColor}' ${this.hideAttribution} hidden></document-capture-review>
|
|
71
|
-
</div>
|
|
72
|
-
`;
|
|
73
|
-
|
|
74
|
-
this._data = {
|
|
75
|
-
images: [],
|
|
76
|
-
meta: {
|
|
77
|
-
libraryVersion: COMPONENTS_VERSION,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
this.documentInstruction = this.querySelector(
|
|
82
|
-
'document-capture-instructions',
|
|
83
|
-
);
|
|
84
|
-
this.documentInstructionBack = this.querySelector(
|
|
85
|
-
'#document-capture-instructions-back',
|
|
86
|
-
);
|
|
87
|
-
this.idCapture = this.querySelector('#document-capture-front');
|
|
88
|
-
this.idReview = this.querySelector('#front-of-document-capture-review');
|
|
89
|
-
this.idCaptureBack = this.querySelector('#document-capture-back');
|
|
90
|
-
this.backOfIdReview = this.querySelector(
|
|
91
|
-
'#back-of-document-capture-review',
|
|
92
|
-
);
|
|
93
|
-
this.thankYouScreen = this.querySelector('thank-you');
|
|
94
|
-
|
|
95
|
-
if (this.hideInstructions) {
|
|
96
|
-
getPermissions(this.idCapture);
|
|
97
|
-
this.setActiveScreen(this.idCapture);
|
|
98
|
-
} else {
|
|
99
|
-
this.setActiveScreen(this.documentInstruction);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
this.setUpEventListeners();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
disconnectedCallback() {
|
|
106
|
-
SmartCamera.stopMedia();
|
|
107
|
-
if (this.activeScreen) {
|
|
108
|
-
this.activeScreen.removeAttribute('hidden');
|
|
109
|
-
}
|
|
110
|
-
this.activeScreen = null;
|
|
111
|
-
this.innerHTML = '';
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
setUpEventListeners() {
|
|
115
|
-
this.documentInstruction.addEventListener(
|
|
116
|
-
'document-capture-instructions.cancelled',
|
|
117
|
-
() => {
|
|
118
|
-
this.handleBackEvents();
|
|
119
|
-
},
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
this.documentInstruction.addEventListener(
|
|
123
|
-
'document-capture-instructions.capture',
|
|
124
|
-
async () => {
|
|
125
|
-
smartCameraWeb?.dispatchEvent(
|
|
126
|
-
new CustomEvent('metadata.document-front-capture-start'),
|
|
127
|
-
);
|
|
128
|
-
smartCameraWeb?.dispatchEvent(
|
|
129
|
-
new CustomEvent('metadata.document-front-origin', {
|
|
130
|
-
detail: { imageOrigin: 'camera_manual_capture' },
|
|
131
|
-
}),
|
|
132
|
-
);
|
|
133
|
-
this.setActiveScreen(this.idCapture);
|
|
134
|
-
await getPermissions(this.idCapture);
|
|
135
|
-
},
|
|
136
|
-
);
|
|
137
|
-
this.documentInstruction.addEventListener(
|
|
138
|
-
'document-capture-instructions.upload',
|
|
139
|
-
async (event) => {
|
|
140
|
-
smartCameraWeb?.dispatchEvent(
|
|
141
|
-
new CustomEvent('metadata.document-front-origin', {
|
|
142
|
-
detail: { imageOrigin: 'gallery' },
|
|
143
|
-
}),
|
|
144
|
-
);
|
|
145
|
-
this.idReview.setAttribute('data-image', event.detail.previewImage);
|
|
146
|
-
this._data.images.push({
|
|
147
|
-
image: event.detail.image.split(',')[1],
|
|
148
|
-
image_type_id: IMAGE_TYPE.ID_CARD_IMAGE_BASE64,
|
|
149
|
-
});
|
|
150
|
-
this.setActiveScreen(this.idReview);
|
|
151
|
-
},
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
this.idCapture.addEventListener('document-capture.publish', (event) => {
|
|
155
|
-
smartCameraWeb?.dispatchEvent(
|
|
156
|
-
new CustomEvent('metadata.document-front-capture-end'),
|
|
157
|
-
);
|
|
158
|
-
this.idReview.setAttribute('data-image', event.detail.previewImage);
|
|
159
|
-
this._data.images.push({
|
|
160
|
-
image: event.detail.image.split(',')[1],
|
|
161
|
-
image_type_id: IMAGE_TYPE.ID_CARD_IMAGE_BASE64,
|
|
162
|
-
});
|
|
163
|
-
SmartCamera.stopMedia();
|
|
164
|
-
this.setActiveScreen(this.idReview);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
this.idCapture.addEventListener('document-capture.cancelled', () => {
|
|
168
|
-
if (this.hideInstructions) {
|
|
169
|
-
this.handleBackEvents();
|
|
170
|
-
} else {
|
|
171
|
-
this.setActiveScreen(this.documentInstruction);
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
this.idReview.addEventListener(
|
|
176
|
-
'document-capture-review.rejected',
|
|
177
|
-
async () => {
|
|
178
|
-
smartCameraWeb?.dispatchEvent(
|
|
179
|
-
new CustomEvent('metadata.document-front-capture-retry'),
|
|
180
|
-
);
|
|
181
|
-
this.idReview.removeAttribute('data-image');
|
|
182
|
-
this._data.images.pop();
|
|
183
|
-
if (this.hideInstructions) {
|
|
184
|
-
this.setActiveScreen(this.idCapture);
|
|
185
|
-
await getPermissions(this.idCapture);
|
|
186
|
-
} else {
|
|
187
|
-
this.setActiveScreen(this.documentInstruction);
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
this.idReview.addEventListener(
|
|
193
|
-
'document-capture-review.accepted',
|
|
194
|
-
async () => {
|
|
195
|
-
if (this.hideBackOfId) {
|
|
196
|
-
this._publishSelectedImages();
|
|
197
|
-
} else if (this.hideInstructions) {
|
|
198
|
-
this.setActiveScreen(this.idCaptureBack);
|
|
199
|
-
await getPermissions(this.idCaptureBack);
|
|
200
|
-
} else {
|
|
201
|
-
this.setActiveScreen(this.documentInstructionBack);
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
this.documentInstructionBack.addEventListener(
|
|
207
|
-
'document-capture-instructions.capture',
|
|
208
|
-
async () => {
|
|
209
|
-
smartCameraWeb?.dispatchEvent(
|
|
210
|
-
new CustomEvent('metadata.document-back-capture-start'),
|
|
211
|
-
);
|
|
212
|
-
smartCameraWeb?.dispatchEvent(
|
|
213
|
-
new CustomEvent('metadata.document-back-origin', {
|
|
214
|
-
detail: { imageOrigin: 'camera_manual_capture' },
|
|
215
|
-
}),
|
|
216
|
-
);
|
|
217
|
-
this.setActiveScreen(this.idCaptureBack);
|
|
218
|
-
await getPermissions(this.idCaptureBack);
|
|
219
|
-
},
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
this.documentInstructionBack.addEventListener(
|
|
223
|
-
'document-capture-instructions.cancelled',
|
|
224
|
-
async () => {
|
|
225
|
-
this.idReview.removeAttribute('data-image');
|
|
226
|
-
this._data.images.pop();
|
|
227
|
-
if (this.hideInstructions) {
|
|
228
|
-
this.setActiveScreen(this.idCapture);
|
|
229
|
-
await getPermissions(this.idCapture);
|
|
230
|
-
} else {
|
|
231
|
-
this.setActiveScreen(this.documentInstruction);
|
|
232
|
-
}
|
|
233
|
-
},
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
this.documentInstructionBack.addEventListener(
|
|
237
|
-
'document-capture-instructions.upload',
|
|
238
|
-
async (event) => {
|
|
239
|
-
smartCameraWeb?.dispatchEvent(
|
|
240
|
-
new CustomEvent('metadata.document-back-origin', {
|
|
241
|
-
detail: { imageOrigin: 'gallery' },
|
|
242
|
-
}),
|
|
243
|
-
);
|
|
244
|
-
this.backOfIdReview.setAttribute('data-image', event.detail.image);
|
|
245
|
-
this._data.images.push({
|
|
246
|
-
image: event.detail.image.split(',')[1],
|
|
247
|
-
image_type_id: IMAGE_TYPE.ID_CARD_BACK_IMAGE_BASE64,
|
|
248
|
-
});
|
|
249
|
-
this.setActiveScreen(this.backOfIdReview);
|
|
250
|
-
},
|
|
251
|
-
);
|
|
252
|
-
this.idCaptureBack.addEventListener('document-capture.publish', (event) => {
|
|
253
|
-
smartCameraWeb?.dispatchEvent(
|
|
254
|
-
new CustomEvent('metadata.document-back-capture-end'),
|
|
255
|
-
);
|
|
256
|
-
this.backOfIdReview.setAttribute('data-image', event.detail.previewImage);
|
|
257
|
-
this._data.images.push({
|
|
258
|
-
image: event.detail.image.split(',')[1],
|
|
259
|
-
image_type_id: IMAGE_TYPE.ID_CARD_BACK_IMAGE_BASE64,
|
|
260
|
-
});
|
|
261
|
-
this.setActiveScreen(this.backOfIdReview);
|
|
262
|
-
SmartCamera.stopMedia();
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
this.idCaptureBack.addEventListener(
|
|
266
|
-
'document-capture.cancelled',
|
|
267
|
-
async () => {
|
|
268
|
-
if (this.hideInstructions) {
|
|
269
|
-
this.setActiveScreen(this.idCapture);
|
|
270
|
-
await getPermissions(this.idCapture);
|
|
271
|
-
} else {
|
|
272
|
-
this.setActiveScreen(this.documentInstructionBack);
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
this.backOfIdReview.addEventListener(
|
|
278
|
-
'document-capture-review.rejected',
|
|
279
|
-
async () => {
|
|
280
|
-
smartCameraWeb?.dispatchEvent(
|
|
281
|
-
new CustomEvent('metadata.document-back-capture-retry'),
|
|
282
|
-
);
|
|
283
|
-
this.backOfIdReview.removeAttribute('data-image');
|
|
284
|
-
this._data.images.pop();
|
|
285
|
-
if (this.hideInstructions) {
|
|
286
|
-
this.setActiveScreen(this.idCaptureBack);
|
|
287
|
-
await getPermissions(this.idCaptureBack);
|
|
288
|
-
} else {
|
|
289
|
-
this.setActiveScreen(this.documentInstructionBack);
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
this.backOfIdReview.addEventListener(
|
|
295
|
-
'document-capture-review.accepted',
|
|
296
|
-
() => {
|
|
297
|
-
this._publishSelectedImages();
|
|
298
|
-
},
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
const screens = [
|
|
302
|
-
this.documentInstruction,
|
|
303
|
-
this.idCapture,
|
|
304
|
-
this.documentInstructionBack,
|
|
305
|
-
this.idCaptureBack,
|
|
306
|
-
this.idReview,
|
|
307
|
-
this.backOfIdReview,
|
|
308
|
-
];
|
|
309
|
-
|
|
310
|
-
screens.forEach((screen) => {
|
|
311
|
-
screen.addEventListener(`${screen.nodeName.toLowerCase()}.close`, () =>
|
|
312
|
-
this.handleCloseEvents(),
|
|
313
|
-
);
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
_publishSelectedImages() {
|
|
318
|
-
this.dispatchEvent(
|
|
319
|
-
new CustomEvent('document-capture-screens.publish', {
|
|
320
|
-
detail: this._data,
|
|
321
|
-
}),
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
get hideInstructions() {
|
|
326
|
-
return this.hasAttribute('hide-instructions');
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
get hideBackOfId() {
|
|
330
|
-
return this.hasAttribute('hide-back-of-id');
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
get showNavigation() {
|
|
334
|
-
return this.hasAttribute('show-navigation') ? 'show-navigation' : '';
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
get title() {
|
|
338
|
-
return this.hasAttribute('title')
|
|
339
|
-
? `title=${this.getAttribute('title')}`
|
|
340
|
-
: '';
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
get documentCaptureModes() {
|
|
344
|
-
return this.hasAttribute('document-capture-modes')
|
|
345
|
-
? `document-capture-modes='${this.getAttribute('document-capture-modes')}'`
|
|
346
|
-
: '';
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
get documentType() {
|
|
350
|
-
return this.hasAttribute('document-type')
|
|
351
|
-
? `document-type='${this.getAttribute('document-type')}'`
|
|
352
|
-
: '';
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
get hideAttribution() {
|
|
356
|
-
return this.hasAttribute('hide-attribution') ? 'hide-attribution' : '';
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
get themeColor() {
|
|
360
|
-
return this.getAttribute('theme-color') || '#001096';
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
handleBackEvents() {
|
|
364
|
-
this.dispatchEvent(new CustomEvent('document-capture-screens.cancelled'));
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
handleCloseEvents() {
|
|
368
|
-
this.dispatchEvent(new CustomEvent('document-capture-screens.close'));
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
setActiveScreen(screen) {
|
|
372
|
-
this.activeScreen?.setAttribute('hidden', '');
|
|
373
|
-
screen.removeAttribute('hidden');
|
|
374
|
-
this.activeScreen = screen;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
static get observedAttributes() {
|
|
378
|
-
return [
|
|
379
|
-
'document-capture-modes',
|
|
380
|
-
'document-type',
|
|
381
|
-
'hide-back-to-host',
|
|
382
|
-
'show-navigation',
|
|
383
|
-
'hide-back-of-id',
|
|
384
|
-
];
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
attributeChangedCallback(name) {
|
|
388
|
-
switch (name) {
|
|
389
|
-
case 'document-capture-modes':
|
|
390
|
-
case 'document-type':
|
|
391
|
-
case 'hide-back-of-id':
|
|
392
|
-
case 'hide-back-to-host':
|
|
393
|
-
case 'show-navigation':
|
|
394
|
-
this.connectedCallback();
|
|
395
|
-
break;
|
|
396
|
-
default:
|
|
397
|
-
break;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
if (
|
|
403
|
-
'customElements' in window &&
|
|
404
|
-
!customElements.get('document-capture-screens')
|
|
405
|
-
) {
|
|
406
|
-
customElements.define('document-capture-screens', DocumentCaptureScreens);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export default DocumentCaptureScreens;
|
|
1
|
+
import { IMAGE_TYPE } from '../../../domain/constants/src/Constants';
|
|
2
|
+
import styles from '../../../styles/src/styles';
|
|
3
|
+
import SmartCamera from '../../../domain/camera/src/SmartCamera';
|
|
4
|
+
|
|
5
|
+
import './document-capture';
|
|
6
|
+
import './document-capture-review';
|
|
7
|
+
import './document-capture-instructions';
|
|
8
|
+
import packageJson from '../../../../package.json';
|
|
9
|
+
|
|
10
|
+
const COMPONENTS_VERSION = packageJson.version;
|
|
11
|
+
|
|
12
|
+
const smartCameraWeb = document.querySelector('smart-camera-web');
|
|
13
|
+
|
|
14
|
+
async function getPermissions(captureScreen) {
|
|
15
|
+
try {
|
|
16
|
+
const stream = await SmartCamera.getMedia({
|
|
17
|
+
audio: false,
|
|
18
|
+
video: SmartCamera.environmentOptions,
|
|
19
|
+
});
|
|
20
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
21
|
+
const videoDevice = devices.find(
|
|
22
|
+
(device) =>
|
|
23
|
+
device.kind === 'videoinput' &&
|
|
24
|
+
stream.getVideoTracks()[0].getSettings().deviceId === device.deviceId,
|
|
25
|
+
);
|
|
26
|
+
smartCameraWeb?.dispatchEvent(
|
|
27
|
+
new CustomEvent('metadata.camera-name', {
|
|
28
|
+
detail: { cameraName: videoDevice?.label },
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
captureScreen.removeAttribute('data-camera-error');
|
|
32
|
+
captureScreen.setAttribute('data-camera-ready', true);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
captureScreen.removeAttribute('data-camera-ready');
|
|
35
|
+
captureScreen.setAttribute(
|
|
36
|
+
'data-camera-error',
|
|
37
|
+
SmartCamera.handleCameraError(error),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class DocumentCaptureScreens extends HTMLElement {
|
|
43
|
+
constructor() {
|
|
44
|
+
super();
|
|
45
|
+
this.activeScreen = null;
|
|
46
|
+
this.smartCameraWeb = this.closest('smart-camera-web');
|
|
47
|
+
smartCameraWeb?.dispatchEvent(new CustomEvent('metadata.initialize'));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
connectedCallback() {
|
|
51
|
+
this.innerHTML = `
|
|
52
|
+
${styles(this.themeColor)}
|
|
53
|
+
<div>
|
|
54
|
+
<document-capture-instructions theme-color='${this.themeColor}' id='document-capture-instructions-front' ${this.title}
|
|
55
|
+
${this.documentCaptureModes} ${this.showNavigation} ${this.hideInstructions ? 'hidden' : ''}
|
|
56
|
+
${this.hideAttribution}
|
|
57
|
+
></document-capture-instructions>
|
|
58
|
+
<document-capture id='document-capture-front' side-of-id='Front'
|
|
59
|
+
${this.title} ${this.showNavigation} ${this.hideInstructions ? '' : 'hidden'} ${this.hideAttribution}
|
|
60
|
+
${this.documentCaptureModes} ${this.documentType} theme-color='${this.themeColor}'
|
|
61
|
+
></document-capture>
|
|
62
|
+
<document-capture-instructions id='document-capture-instructions-back' side-of-id='Back' title='Submit Back of ID'
|
|
63
|
+
${this.documentCaptureModes} ${this.showNavigation} theme-color='${this.themeColor}' ${this.hideAttribution} hidden
|
|
64
|
+
></document-capture-instructions>
|
|
65
|
+
<document-capture id='document-capture-back' side-of-id='Back' ${this.title} ${this.showNavigation}
|
|
66
|
+
${this.documentCaptureModes} theme-color='${this.themeColor}' ${this.hideAttribution}
|
|
67
|
+
hidden
|
|
68
|
+
></document-capture>
|
|
69
|
+
<document-capture-review id='front-of-document-capture-review' theme-color='${this.themeColor}' ${this.hideAttribution} hidden></document-capture-review>
|
|
70
|
+
<document-capture-review id='back-of-document-capture-review' theme-color='${this.themeColor}' ${this.hideAttribution} hidden></document-capture-review>
|
|
71
|
+
</div>
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
this._data = {
|
|
75
|
+
images: [],
|
|
76
|
+
meta: {
|
|
77
|
+
libraryVersion: COMPONENTS_VERSION,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
this.documentInstruction = this.querySelector(
|
|
82
|
+
'document-capture-instructions',
|
|
83
|
+
);
|
|
84
|
+
this.documentInstructionBack = this.querySelector(
|
|
85
|
+
'#document-capture-instructions-back',
|
|
86
|
+
);
|
|
87
|
+
this.idCapture = this.querySelector('#document-capture-front');
|
|
88
|
+
this.idReview = this.querySelector('#front-of-document-capture-review');
|
|
89
|
+
this.idCaptureBack = this.querySelector('#document-capture-back');
|
|
90
|
+
this.backOfIdReview = this.querySelector(
|
|
91
|
+
'#back-of-document-capture-review',
|
|
92
|
+
);
|
|
93
|
+
this.thankYouScreen = this.querySelector('thank-you');
|
|
94
|
+
|
|
95
|
+
if (this.hideInstructions) {
|
|
96
|
+
getPermissions(this.idCapture);
|
|
97
|
+
this.setActiveScreen(this.idCapture);
|
|
98
|
+
} else {
|
|
99
|
+
this.setActiveScreen(this.documentInstruction);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.setUpEventListeners();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
disconnectedCallback() {
|
|
106
|
+
SmartCamera.stopMedia();
|
|
107
|
+
if (this.activeScreen) {
|
|
108
|
+
this.activeScreen.removeAttribute('hidden');
|
|
109
|
+
}
|
|
110
|
+
this.activeScreen = null;
|
|
111
|
+
this.innerHTML = '';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setUpEventListeners() {
|
|
115
|
+
this.documentInstruction.addEventListener(
|
|
116
|
+
'document-capture-instructions.cancelled',
|
|
117
|
+
() => {
|
|
118
|
+
this.handleBackEvents();
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
this.documentInstruction.addEventListener(
|
|
123
|
+
'document-capture-instructions.capture',
|
|
124
|
+
async () => {
|
|
125
|
+
smartCameraWeb?.dispatchEvent(
|
|
126
|
+
new CustomEvent('metadata.document-front-capture-start'),
|
|
127
|
+
);
|
|
128
|
+
smartCameraWeb?.dispatchEvent(
|
|
129
|
+
new CustomEvent('metadata.document-front-origin', {
|
|
130
|
+
detail: { imageOrigin: 'camera_manual_capture' },
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
this.setActiveScreen(this.idCapture);
|
|
134
|
+
await getPermissions(this.idCapture);
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
this.documentInstruction.addEventListener(
|
|
138
|
+
'document-capture-instructions.upload',
|
|
139
|
+
async (event) => {
|
|
140
|
+
smartCameraWeb?.dispatchEvent(
|
|
141
|
+
new CustomEvent('metadata.document-front-origin', {
|
|
142
|
+
detail: { imageOrigin: 'gallery' },
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
this.idReview.setAttribute('data-image', event.detail.previewImage);
|
|
146
|
+
this._data.images.push({
|
|
147
|
+
image: event.detail.image.split(',')[1],
|
|
148
|
+
image_type_id: IMAGE_TYPE.ID_CARD_IMAGE_BASE64,
|
|
149
|
+
});
|
|
150
|
+
this.setActiveScreen(this.idReview);
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
this.idCapture.addEventListener('document-capture.publish', (event) => {
|
|
155
|
+
smartCameraWeb?.dispatchEvent(
|
|
156
|
+
new CustomEvent('metadata.document-front-capture-end'),
|
|
157
|
+
);
|
|
158
|
+
this.idReview.setAttribute('data-image', event.detail.previewImage);
|
|
159
|
+
this._data.images.push({
|
|
160
|
+
image: event.detail.image.split(',')[1],
|
|
161
|
+
image_type_id: IMAGE_TYPE.ID_CARD_IMAGE_BASE64,
|
|
162
|
+
});
|
|
163
|
+
SmartCamera.stopMedia();
|
|
164
|
+
this.setActiveScreen(this.idReview);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
this.idCapture.addEventListener('document-capture.cancelled', () => {
|
|
168
|
+
if (this.hideInstructions) {
|
|
169
|
+
this.handleBackEvents();
|
|
170
|
+
} else {
|
|
171
|
+
this.setActiveScreen(this.documentInstruction);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
this.idReview.addEventListener(
|
|
176
|
+
'document-capture-review.rejected',
|
|
177
|
+
async () => {
|
|
178
|
+
smartCameraWeb?.dispatchEvent(
|
|
179
|
+
new CustomEvent('metadata.document-front-capture-retry'),
|
|
180
|
+
);
|
|
181
|
+
this.idReview.removeAttribute('data-image');
|
|
182
|
+
this._data.images.pop();
|
|
183
|
+
if (this.hideInstructions) {
|
|
184
|
+
this.setActiveScreen(this.idCapture);
|
|
185
|
+
await getPermissions(this.idCapture);
|
|
186
|
+
} else {
|
|
187
|
+
this.setActiveScreen(this.documentInstruction);
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
this.idReview.addEventListener(
|
|
193
|
+
'document-capture-review.accepted',
|
|
194
|
+
async () => {
|
|
195
|
+
if (this.hideBackOfId) {
|
|
196
|
+
this._publishSelectedImages();
|
|
197
|
+
} else if (this.hideInstructions) {
|
|
198
|
+
this.setActiveScreen(this.idCaptureBack);
|
|
199
|
+
await getPermissions(this.idCaptureBack);
|
|
200
|
+
} else {
|
|
201
|
+
this.setActiveScreen(this.documentInstructionBack);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
this.documentInstructionBack.addEventListener(
|
|
207
|
+
'document-capture-instructions.capture',
|
|
208
|
+
async () => {
|
|
209
|
+
smartCameraWeb?.dispatchEvent(
|
|
210
|
+
new CustomEvent('metadata.document-back-capture-start'),
|
|
211
|
+
);
|
|
212
|
+
smartCameraWeb?.dispatchEvent(
|
|
213
|
+
new CustomEvent('metadata.document-back-origin', {
|
|
214
|
+
detail: { imageOrigin: 'camera_manual_capture' },
|
|
215
|
+
}),
|
|
216
|
+
);
|
|
217
|
+
this.setActiveScreen(this.idCaptureBack);
|
|
218
|
+
await getPermissions(this.idCaptureBack);
|
|
219
|
+
},
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
this.documentInstructionBack.addEventListener(
|
|
223
|
+
'document-capture-instructions.cancelled',
|
|
224
|
+
async () => {
|
|
225
|
+
this.idReview.removeAttribute('data-image');
|
|
226
|
+
this._data.images.pop();
|
|
227
|
+
if (this.hideInstructions) {
|
|
228
|
+
this.setActiveScreen(this.idCapture);
|
|
229
|
+
await getPermissions(this.idCapture);
|
|
230
|
+
} else {
|
|
231
|
+
this.setActiveScreen(this.documentInstruction);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
this.documentInstructionBack.addEventListener(
|
|
237
|
+
'document-capture-instructions.upload',
|
|
238
|
+
async (event) => {
|
|
239
|
+
smartCameraWeb?.dispatchEvent(
|
|
240
|
+
new CustomEvent('metadata.document-back-origin', {
|
|
241
|
+
detail: { imageOrigin: 'gallery' },
|
|
242
|
+
}),
|
|
243
|
+
);
|
|
244
|
+
this.backOfIdReview.setAttribute('data-image', event.detail.image);
|
|
245
|
+
this._data.images.push({
|
|
246
|
+
image: event.detail.image.split(',')[1],
|
|
247
|
+
image_type_id: IMAGE_TYPE.ID_CARD_BACK_IMAGE_BASE64,
|
|
248
|
+
});
|
|
249
|
+
this.setActiveScreen(this.backOfIdReview);
|
|
250
|
+
},
|
|
251
|
+
);
|
|
252
|
+
this.idCaptureBack.addEventListener('document-capture.publish', (event) => {
|
|
253
|
+
smartCameraWeb?.dispatchEvent(
|
|
254
|
+
new CustomEvent('metadata.document-back-capture-end'),
|
|
255
|
+
);
|
|
256
|
+
this.backOfIdReview.setAttribute('data-image', event.detail.previewImage);
|
|
257
|
+
this._data.images.push({
|
|
258
|
+
image: event.detail.image.split(',')[1],
|
|
259
|
+
image_type_id: IMAGE_TYPE.ID_CARD_BACK_IMAGE_BASE64,
|
|
260
|
+
});
|
|
261
|
+
this.setActiveScreen(this.backOfIdReview);
|
|
262
|
+
SmartCamera.stopMedia();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
this.idCaptureBack.addEventListener(
|
|
266
|
+
'document-capture.cancelled',
|
|
267
|
+
async () => {
|
|
268
|
+
if (this.hideInstructions) {
|
|
269
|
+
this.setActiveScreen(this.idCapture);
|
|
270
|
+
await getPermissions(this.idCapture);
|
|
271
|
+
} else {
|
|
272
|
+
this.setActiveScreen(this.documentInstructionBack);
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
this.backOfIdReview.addEventListener(
|
|
278
|
+
'document-capture-review.rejected',
|
|
279
|
+
async () => {
|
|
280
|
+
smartCameraWeb?.dispatchEvent(
|
|
281
|
+
new CustomEvent('metadata.document-back-capture-retry'),
|
|
282
|
+
);
|
|
283
|
+
this.backOfIdReview.removeAttribute('data-image');
|
|
284
|
+
this._data.images.pop();
|
|
285
|
+
if (this.hideInstructions) {
|
|
286
|
+
this.setActiveScreen(this.idCaptureBack);
|
|
287
|
+
await getPermissions(this.idCaptureBack);
|
|
288
|
+
} else {
|
|
289
|
+
this.setActiveScreen(this.documentInstructionBack);
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
this.backOfIdReview.addEventListener(
|
|
295
|
+
'document-capture-review.accepted',
|
|
296
|
+
() => {
|
|
297
|
+
this._publishSelectedImages();
|
|
298
|
+
},
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
const screens = [
|
|
302
|
+
this.documentInstruction,
|
|
303
|
+
this.idCapture,
|
|
304
|
+
this.documentInstructionBack,
|
|
305
|
+
this.idCaptureBack,
|
|
306
|
+
this.idReview,
|
|
307
|
+
this.backOfIdReview,
|
|
308
|
+
];
|
|
309
|
+
|
|
310
|
+
screens.forEach((screen) => {
|
|
311
|
+
screen.addEventListener(`${screen.nodeName.toLowerCase()}.close`, () =>
|
|
312
|
+
this.handleCloseEvents(),
|
|
313
|
+
);
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
_publishSelectedImages() {
|
|
318
|
+
this.dispatchEvent(
|
|
319
|
+
new CustomEvent('document-capture-screens.publish', {
|
|
320
|
+
detail: this._data,
|
|
321
|
+
}),
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
get hideInstructions() {
|
|
326
|
+
return this.hasAttribute('hide-instructions');
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
get hideBackOfId() {
|
|
330
|
+
return this.hasAttribute('hide-back-of-id');
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
get showNavigation() {
|
|
334
|
+
return this.hasAttribute('show-navigation') ? 'show-navigation' : '';
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
get title() {
|
|
338
|
+
return this.hasAttribute('title')
|
|
339
|
+
? `title=${this.getAttribute('title')}`
|
|
340
|
+
: '';
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
get documentCaptureModes() {
|
|
344
|
+
return this.hasAttribute('document-capture-modes')
|
|
345
|
+
? `document-capture-modes='${this.getAttribute('document-capture-modes')}'`
|
|
346
|
+
: '';
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
get documentType() {
|
|
350
|
+
return this.hasAttribute('document-type')
|
|
351
|
+
? `document-type='${this.getAttribute('document-type')}'`
|
|
352
|
+
: '';
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
get hideAttribution() {
|
|
356
|
+
return this.hasAttribute('hide-attribution') ? 'hide-attribution' : '';
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
get themeColor() {
|
|
360
|
+
return this.getAttribute('theme-color') || '#001096';
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
handleBackEvents() {
|
|
364
|
+
this.dispatchEvent(new CustomEvent('document-capture-screens.cancelled'));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
handleCloseEvents() {
|
|
368
|
+
this.dispatchEvent(new CustomEvent('document-capture-screens.close'));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
setActiveScreen(screen) {
|
|
372
|
+
this.activeScreen?.setAttribute('hidden', '');
|
|
373
|
+
screen.removeAttribute('hidden');
|
|
374
|
+
this.activeScreen = screen;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
static get observedAttributes() {
|
|
378
|
+
return [
|
|
379
|
+
'document-capture-modes',
|
|
380
|
+
'document-type',
|
|
381
|
+
'hide-back-to-host',
|
|
382
|
+
'show-navigation',
|
|
383
|
+
'hide-back-of-id',
|
|
384
|
+
];
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
attributeChangedCallback(name) {
|
|
388
|
+
switch (name) {
|
|
389
|
+
case 'document-capture-modes':
|
|
390
|
+
case 'document-type':
|
|
391
|
+
case 'hide-back-of-id':
|
|
392
|
+
case 'hide-back-to-host':
|
|
393
|
+
case 'show-navigation':
|
|
394
|
+
this.connectedCallback();
|
|
395
|
+
break;
|
|
396
|
+
default:
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (
|
|
403
|
+
'customElements' in window &&
|
|
404
|
+
!customElements.get('document-capture-screens')
|
|
405
|
+
) {
|
|
406
|
+
customElements.define('document-capture-screens', DocumentCaptureScreens);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export default DocumentCaptureScreens;
|