@smileid/web-components 2.0.1 → 10.0.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.
Files changed (125) hide show
  1. package/dist/DocumentCaptureScreens-Dwl7UqVH.js +1534 -0
  2. package/dist/DocumentCaptureScreens-Dwl7UqVH.js.map +1 -0
  3. package/dist/EndUserConsent-C5hZdJzH.js +715 -0
  4. package/dist/EndUserConsent-C5hZdJzH.js.map +1 -0
  5. package/dist/Navigation-juBE4qOw.js +136 -0
  6. package/dist/Navigation-juBE4qOw.js.map +1 -0
  7. package/dist/PoweredBySmileId-CxbaihMu.js +33 -0
  8. package/dist/PoweredBySmileId-CxbaihMu.js.map +1 -0
  9. package/dist/SelfieCaptureScreens-CQc251hz.js +7618 -0
  10. package/dist/SelfieCaptureScreens-CQc251hz.js.map +1 -0
  11. package/dist/SignaturePad-C7MtmT8m.js +324 -0
  12. package/dist/SignaturePad-C7MtmT8m.js.map +1 -0
  13. package/dist/TotpConsent-CQU5jQi4.js +730 -0
  14. package/dist/TotpConsent-CQU5jQi4.js.map +1 -0
  15. package/dist/combobox.js +300 -0
  16. package/dist/combobox.js.map +1 -0
  17. package/dist/document.js +5 -0
  18. package/dist/document.js.map +1 -0
  19. package/dist/end-user-consent.js +5 -0
  20. package/dist/end-user-consent.js.map +1 -0
  21. package/dist/main.js +22 -0
  22. package/dist/main.js.map +1 -0
  23. package/dist/navigation.js +5 -0
  24. package/dist/navigation.js.map +1 -0
  25. package/dist/package-Oi2Yil3b.js +105 -0
  26. package/dist/package-Oi2Yil3b.js.map +1 -0
  27. package/dist/selfie.js +5 -0
  28. package/dist/selfie.js.map +1 -0
  29. package/dist/signature-pad.js +5 -0
  30. package/dist/signature-pad.js.map +1 -0
  31. package/dist/smart-camera-web.js +303 -0
  32. package/dist/smart-camera-web.js.map +1 -0
  33. package/dist/styles-BUWNxWeQ.js +406 -0
  34. package/dist/styles-BUWNxWeQ.js.map +1 -0
  35. package/dist/totp-consent.js +5 -0
  36. package/dist/totp-consent.js.map +1 -0
  37. package/dist/types/combobox.d.ts +21 -0
  38. package/dist/types/document.d.ts +21 -0
  39. package/dist/types/end-user-consent.d.ts +21 -0
  40. package/dist/types/main.d.ts +331 -0
  41. package/dist/types/navigation.d.ts +21 -0
  42. package/dist/types/selfie.d.ts +21 -0
  43. package/dist/types/signature-pad.d.ts +21 -0
  44. package/dist/types/smart-camera-web.d.ts +21 -0
  45. package/dist/types/totp-consent.d.ts +21 -0
  46. package/{src → lib}/components/README.md +14 -14
  47. package/{src → lib}/components/attribution/PoweredBySmileId.js +42 -42
  48. package/{src → lib}/components/camera-permission/CameraPermission.js +140 -140
  49. package/{src → lib}/components/camera-permission/CameraPermission.stories.js +27 -27
  50. package/{src → lib}/components/combobox/src/Combobox.js +589 -589
  51. package/{src → lib}/components/combobox/src/index.js +1 -1
  52. package/{src → lib}/components/document/src/DocumentCaptureScreens.js +409 -409
  53. package/{src → lib}/components/document/src/DocumentCaptureScreens.stories.js +57 -57
  54. package/{src → lib}/components/document/src/README.md +111 -111
  55. package/{src → lib}/components/document/src/document-capture/DocumentCapture.js +760 -760
  56. package/{src → lib}/components/document/src/document-capture/DocumentCapture.stories.js +78 -78
  57. package/{src → lib}/components/document/src/document-capture/README.md +90 -90
  58. package/{src → lib}/components/document/src/document-capture/index.js +3 -3
  59. package/{src → lib}/components/document/src/document-capture-instructions/DocumentCaptureInstructions.js +499 -499
  60. package/{src → lib}/components/document/src/document-capture-instructions/DocumentCaptureInstructions.stories.js +24 -24
  61. package/{src → lib}/components/document/src/document-capture-instructions/README.md +56 -56
  62. package/{src → lib}/components/document/src/document-capture-instructions/index.js +3 -3
  63. package/{src → lib}/components/document/src/document-capture-review/DocumentCaptureReview.js +362 -362
  64. package/{src → lib}/components/document/src/document-capture-review/DocumentCaptureReview.stories.js +24 -24
  65. package/{src → lib}/components/document/src/document-capture-review/README.md +79 -79
  66. package/{src → lib}/components/document/src/document-capture-review/index.js +3 -3
  67. package/{src → lib}/components/document/src/index.js +3 -3
  68. package/{src → lib}/components/end-user-consent/src/EndUserConsent.js +795 -795
  69. package/{src → lib}/components/end-user-consent/src/EndUserConsent.stories.js +29 -29
  70. package/{src → lib}/components/end-user-consent/src/index.js +4 -4
  71. package/{src → lib}/components/navigation/src/Navigation.js +171 -171
  72. package/{src → lib}/components/navigation/src/Navigation.stories.js +24 -24
  73. package/{src → lib}/components/navigation/src/index.js +3 -3
  74. package/{src → lib}/components/selfie/README.md +225 -225
  75. package/{src → lib}/components/selfie/src/SelfieCaptureScreens.js +433 -282
  76. package/{src → lib}/components/selfie/src/SelfieCaptureScreens.stories.js +29 -29
  77. package/{src → lib}/components/selfie/src/index.js +3 -5
  78. package/{src → lib}/components/selfie/src/selfie-capture/SelfieCapture.js +1041 -1010
  79. package/{src → lib}/components/selfie/src/selfie-capture/SelfieCapture.stories.js +36 -36
  80. package/{src → lib}/components/selfie/src/selfie-capture/index.js +3 -3
  81. package/{src → lib}/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.js +657 -648
  82. package/{src → lib}/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.stories.js +23 -23
  83. package/{src → lib}/components/selfie/src/selfie-capture-instructions/index.js +3 -3
  84. package/{src → lib}/components/selfie/src/selfie-capture-review/SelfieCaptureReview.js +340 -347
  85. package/{src → lib}/components/selfie/src/selfie-capture-review/SelfieCaptureReview.stories.js +24 -24
  86. package/{src → lib}/components/selfie/src/selfie-capture-review/index.js +3 -3
  87. package/lib/components/selfie/src/selfie-capture-wrapper/SelfieCaptureWrapper.tsx +227 -0
  88. package/lib/components/selfie/src/selfie-capture-wrapper/index.ts +1 -0
  89. package/lib/components/selfie/src/smartselfie-capture/OvalProgress.tsx +81 -0
  90. package/lib/components/selfie/src/smartselfie-capture/SmartSelfieCapture.tsx +224 -0
  91. package/lib/components/selfie/src/smartselfie-capture/components/AlertDisplay.tsx +34 -0
  92. package/lib/components/selfie/src/smartselfie-capture/components/CameraPreview.tsx +97 -0
  93. package/lib/components/selfie/src/smartselfie-capture/components/CaptureControls.tsx +74 -0
  94. package/lib/components/selfie/src/smartselfie-capture/components/index.ts +3 -0
  95. package/lib/components/selfie/src/smartselfie-capture/constants.ts +23 -0
  96. package/lib/components/selfie/src/smartselfie-capture/hooks/index.ts +2 -0
  97. package/lib/components/selfie/src/smartselfie-capture/hooks/useCamera.ts +94 -0
  98. package/lib/components/selfie/src/smartselfie-capture/hooks/useFaceCapture.ts +558 -0
  99. package/lib/components/selfie/src/smartselfie-capture/index.ts +1 -0
  100. package/lib/components/selfie/src/smartselfie-capture/utils/alertMessages.ts +12 -0
  101. package/lib/components/selfie/src/smartselfie-capture/utils/canvas.ts +105 -0
  102. package/lib/components/selfie/src/smartselfie-capture/utils/faceDetection.ts +129 -0
  103. package/lib/components/selfie/src/smartselfie-capture/utils/imageCapture.ts +64 -0
  104. package/lib/components/selfie/src/smartselfie-capture/utils/index.ts +4 -0
  105. package/lib/components/selfie/src/smartselfie-capture/utils/mediapipeManager.ts +60 -0
  106. package/{src → lib}/components/signature-pad/package-lock.json +3009 -3009
  107. package/{src → lib}/components/signature-pad/package.json +30 -30
  108. package/{src → lib}/components/signature-pad/src/SignaturePad.js +484 -484
  109. package/{src → lib}/components/signature-pad/src/SignaturePad.stories.js +32 -32
  110. package/{src → lib}/components/signature-pad/src/index.js +3 -3
  111. package/{src → lib}/components/smart-camera-web/src/README.md +206 -207
  112. package/{src → lib}/components/smart-camera-web/src/SmartCameraWeb.js +299 -299
  113. package/{src → lib}/components/smart-camera-web/src/SmartCameraWeb.stories.js +57 -57
  114. package/{src → lib}/components/totp-consent/src/TotpConsent.js +949 -949
  115. package/{src → lib}/components/totp-consent/src/index.js +4 -4
  116. package/{src → lib}/domain/camera/src/README.md +38 -38
  117. package/{src → lib}/domain/camera/src/SmartCamera.js +109 -109
  118. package/{src → lib}/domain/constants/src/Constants.js +27 -27
  119. package/{src → lib}/domain/file-upload/README.md +35 -35
  120. package/{src → lib}/domain/file-upload/src/SmartFileUpload.js +65 -65
  121. package/{src → lib}/styles/README.md +3 -3
  122. package/{src → lib}/styles/src/styles.js +359 -359
  123. package/{src → lib}/styles/src/typography.js +52 -52
  124. package/package.json +109 -58
  125. package/src/index.js +0 -5
@@ -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;