@smileid/web-components 10.0.6 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +15 -15
  2. package/dist/README.md +15 -0
  3. package/dist/components/README.md +14 -0
  4. package/dist/components/document/src/README.md +111 -0
  5. package/dist/components/document/src/document-capture/README.md +90 -0
  6. package/dist/components/document/src/document-capture-instructions/README.md +56 -0
  7. package/dist/components/document/src/document-capture-review/README.md +79 -0
  8. package/dist/components/selfie/README.md +225 -0
  9. package/dist/components/smart-camera-web/src/README.md +207 -0
  10. package/dist/domain/camera/src/README.md +38 -0
  11. package/dist/domain/file-upload/README.md +35 -0
  12. package/dist/esm/{DocumentCaptureScreens-BjATTDqu.js → DocumentCaptureScreens-DmH2JZDA.js} +3 -3
  13. package/dist/esm/DocumentCaptureScreens-DmH2JZDA.js.map +1 -0
  14. package/dist/esm/EndUserConsent-D4fd1ovG.js.map +1 -1
  15. package/dist/esm/Navigation-CTjK6tLU.js.map +1 -1
  16. package/dist/esm/PoweredBySmileId-CxbaihMu.js.map +1 -1
  17. package/dist/esm/SelfieCaptureScreens-DbdN2zNk.js +7901 -0
  18. package/dist/esm/SelfieCaptureScreens-DbdN2zNk.js.map +1 -0
  19. package/dist/esm/SignaturePad-C7MtmT8m.js.map +1 -1
  20. package/dist/esm/TotpConsent-CQU5jQi4.js.map +1 -1
  21. package/dist/esm/combobox.js.map +1 -1
  22. package/dist/esm/document.js +1 -1
  23. package/dist/esm/main.js +2 -2
  24. package/dist/esm/{package-CZlW6BZn.js → package-bgeQiff6.js} +2 -2
  25. package/dist/esm/package-bgeQiff6.js.map +1 -0
  26. package/dist/esm/selfie.js +1 -1
  27. package/dist/esm/smart-camera-web.js +3 -3
  28. package/dist/esm/smart-camera-web.js.map +1 -1
  29. package/dist/esm/styles-BOEZtbuc.js.map +1 -1
  30. package/dist/package-lock.json +4948 -0
  31. package/dist/package.json +59 -0
  32. package/dist/smart-camera-web.js +72 -98
  33. package/dist/smart-camera-web.js.gz +0 -0
  34. package/dist/smart-camera-web.js.map +1 -1
  35. package/dist/src/components/combobox/src/index.js +2 -0
  36. package/dist/src/components/combobox/src/index.js.map +7 -0
  37. package/dist/src/components/document/src/index.js +2 -0
  38. package/dist/src/components/document/src/index.js.map +7 -0
  39. package/dist/src/components/end-user-consent/src/index.js +14 -0
  40. package/dist/src/components/end-user-consent/src/index.js.map +7 -0
  41. package/dist/src/components/selfie/src/index.js +2 -0
  42. package/dist/src/components/selfie/src/index.js.map +7 -0
  43. package/dist/src/components/signature-pad/src/index.js +10 -0
  44. package/dist/src/components/signature-pad/src/index.js.map +7 -0
  45. package/dist/src/components/smart-camera-web/src/SmartCameraWeb.js +2 -0
  46. package/dist/src/components/smart-camera-web/src/SmartCameraWeb.js.map +7 -0
  47. package/dist/src/components/totp-consent/src/index.js +14 -0
  48. package/dist/src/components/totp-consent/src/index.js.map +7 -0
  49. package/dist/src/index.js.map +7 -0
  50. package/dist/styles/README.md +3 -0
  51. package/dist/types/combobox.d.ts +19 -19
  52. package/dist/types/document.d.ts +19 -19
  53. package/dist/types/end-user-consent.d.ts +19 -19
  54. package/dist/types/main.d.ts +24 -20
  55. package/dist/types/navigation.d.ts +19 -19
  56. package/dist/types/selfie.d.ts +19 -19
  57. package/dist/types/signature-pad.d.ts +19 -19
  58. package/dist/types/smart-camera-web.d.ts +19 -19
  59. package/dist/types/totp-consent.d.ts +19 -19
  60. package/lib/components/README.md +14 -14
  61. package/lib/components/attribution/PoweredBySmileId.js +42 -42
  62. package/lib/components/camera-permission/CameraPermission.js +139 -139
  63. package/lib/components/camera-permission/CameraPermission.stories.js +27 -27
  64. package/lib/components/combobox/src/Combobox.js +589 -589
  65. package/lib/components/combobox/src/index.js +1 -1
  66. package/lib/components/document/src/DocumentCaptureScreens.js +410 -409
  67. package/lib/components/document/src/DocumentCaptureScreens.stories.js +57 -57
  68. package/lib/components/document/src/README.md +111 -111
  69. package/lib/components/document/src/document-capture/DocumentCapture.js +760 -760
  70. package/lib/components/document/src/document-capture/DocumentCapture.stories.js +78 -78
  71. package/lib/components/document/src/document-capture/README.md +90 -90
  72. package/lib/components/document/src/document-capture/index.js +3 -3
  73. package/lib/components/document/src/document-capture-instructions/DocumentCaptureInstructions.js +545 -545
  74. package/lib/components/document/src/document-capture-instructions/DocumentCaptureInstructions.stories.js +24 -24
  75. package/lib/components/document/src/document-capture-instructions/README.md +56 -56
  76. package/lib/components/document/src/document-capture-instructions/index.js +3 -3
  77. package/lib/components/document/src/document-capture-review/DocumentCaptureReview.js +360 -360
  78. package/lib/components/document/src/document-capture-review/DocumentCaptureReview.stories.js +24 -24
  79. package/lib/components/document/src/document-capture-review/README.md +79 -79
  80. package/lib/components/document/src/document-capture-review/index.js +3 -3
  81. package/lib/components/document/src/index.js +3 -3
  82. package/lib/components/end-user-consent/src/EndUserConsent.js +795 -795
  83. package/lib/components/end-user-consent/src/EndUserConsent.stories.js +29 -29
  84. package/lib/components/end-user-consent/src/index.js +4 -4
  85. package/lib/components/navigation/src/Navigation.js +171 -171
  86. package/lib/components/navigation/src/Navigation.stories.js +24 -24
  87. package/lib/components/navigation/src/index.js +3 -3
  88. package/lib/components/selfie/README.md +225 -225
  89. package/lib/components/selfie/src/SelfieCaptureScreens.js +420 -431
  90. package/lib/components/selfie/src/SelfieCaptureScreens.stories.js +29 -29
  91. package/lib/components/selfie/src/index.js +3 -3
  92. package/lib/components/selfie/src/selfie-capture/SelfieCapture.js +1099 -1084
  93. package/lib/components/selfie/src/selfie-capture/SelfieCapture.stories.js +36 -36
  94. package/lib/components/selfie/src/selfie-capture/index.js +3 -3
  95. package/lib/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.js +689 -689
  96. package/lib/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.stories.js +23 -23
  97. package/lib/components/selfie/src/selfie-capture-instructions/index.js +3 -3
  98. package/lib/components/selfie/src/selfie-capture-review/SelfieCaptureReview.js +209 -209
  99. package/lib/components/selfie/src/selfie-capture-review/SelfieCaptureReview.stories.js +24 -24
  100. package/lib/components/selfie/src/selfie-capture-review/index.js +3 -3
  101. package/lib/components/selfie/src/selfie-capture-wrapper/SelfieCaptureWrapper.tsx +256 -239
  102. package/lib/components/selfie/src/selfie-capture-wrapper/index.ts +1 -1
  103. package/lib/components/selfie/src/smartselfie-capture/OvalProgress.tsx +81 -81
  104. package/lib/components/selfie/src/smartselfie-capture/SmartSelfieCapture.tsx +265 -283
  105. package/lib/components/selfie/src/smartselfie-capture/components/AlertDisplay.tsx +34 -34
  106. package/lib/components/selfie/src/smartselfie-capture/components/CameraPreview.tsx +97 -97
  107. package/lib/components/selfie/src/smartselfie-capture/components/CaptureControls.tsx +78 -76
  108. package/lib/components/selfie/src/smartselfie-capture/components/index.ts +3 -3
  109. package/lib/components/selfie/src/smartselfie-capture/constants.ts +23 -23
  110. package/lib/components/selfie/src/smartselfie-capture/hooks/index.ts +2 -2
  111. package/lib/components/selfie/src/smartselfie-capture/hooks/useCamera.ts +238 -238
  112. package/lib/components/selfie/src/smartselfie-capture/hooks/useFaceCapture.ts +618 -617
  113. package/lib/components/selfie/src/smartselfie-capture/index.ts +1 -1
  114. package/lib/components/selfie/src/smartselfie-capture/utils/alertMessages.ts +13 -13
  115. package/lib/components/selfie/src/smartselfie-capture/utils/canvas.ts +105 -105
  116. package/lib/components/selfie/src/smartselfie-capture/utils/faceDetection.ts +129 -129
  117. package/lib/components/selfie/src/smartselfie-capture/utils/imageCapture.ts +64 -64
  118. package/lib/components/selfie/src/smartselfie-capture/utils/index.ts +4 -4
  119. package/lib/components/selfie/src/smartselfie-capture/utils/mediapipeManager.ts +77 -77
  120. package/lib/components/signature-pad/package-lock.json +3009 -3009
  121. package/lib/components/signature-pad/package.json +30 -30
  122. package/lib/components/signature-pad/src/SignaturePad.js +484 -484
  123. package/lib/components/signature-pad/src/SignaturePad.stories.js +32 -32
  124. package/lib/components/signature-pad/src/index.js +3 -3
  125. package/lib/components/smart-camera-web/src/README.md +206 -206
  126. package/lib/components/smart-camera-web/src/SmartCameraWeb.js +305 -305
  127. package/lib/components/smart-camera-web/src/SmartCameraWeb.stories.js +57 -57
  128. package/lib/components/totp-consent/src/TotpConsent.js +949 -949
  129. package/lib/components/totp-consent/src/index.js +4 -4
  130. package/lib/domain/camera/src/README.md +38 -38
  131. package/lib/domain/camera/src/SmartCamera.js +109 -109
  132. package/lib/domain/constants/src/Constants.js +27 -27
  133. package/lib/domain/file-upload/README.md +35 -35
  134. package/lib/domain/file-upload/src/SmartFileUpload.js +65 -65
  135. package/lib/styles/README.md +3 -3
  136. package/lib/styles/src/styles.js +372 -372
  137. package/lib/styles/src/typography.js +52 -52
  138. package/package.json +111 -112
  139. package/dist/esm/DocumentCaptureScreens-BjATTDqu.js.map +0 -1
  140. package/dist/esm/SelfieCaptureScreens-UUzZzl1A.js +0 -11361
  141. package/dist/esm/SelfieCaptureScreens-UUzZzl1A.js.map +0 -1
  142. package/dist/esm/package-CZlW6BZn.js.map +0 -1
@@ -1,409 +1,410 @@
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 style="height: 100%;">
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 style="height: 100%;">
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
+ smartCameraWeb?.dispatchEvent(new CustomEvent('metadata.cleanup'));
108
+ if (this.activeScreen) {
109
+ this.activeScreen.removeAttribute('hidden');
110
+ }
111
+ this.activeScreen = null;
112
+ this.innerHTML = '';
113
+ }
114
+
115
+ setUpEventListeners() {
116
+ this.documentInstruction.addEventListener(
117
+ 'document-capture-instructions.cancelled',
118
+ () => {
119
+ this.handleBackEvents();
120
+ },
121
+ );
122
+
123
+ this.documentInstruction.addEventListener(
124
+ 'document-capture-instructions.capture',
125
+ async () => {
126
+ smartCameraWeb?.dispatchEvent(
127
+ new CustomEvent('metadata.document-front-capture-start'),
128
+ );
129
+ smartCameraWeb?.dispatchEvent(
130
+ new CustomEvent('metadata.document-front-origin', {
131
+ detail: { imageOrigin: 'camera_manual_capture' },
132
+ }),
133
+ );
134
+ this.setActiveScreen(this.idCapture);
135
+ await getPermissions(this.idCapture);
136
+ },
137
+ );
138
+ this.documentInstruction.addEventListener(
139
+ 'document-capture-instructions.upload',
140
+ async (event) => {
141
+ smartCameraWeb?.dispatchEvent(
142
+ new CustomEvent('metadata.document-front-origin', {
143
+ detail: { imageOrigin: 'gallery' },
144
+ }),
145
+ );
146
+ this.idReview.setAttribute('data-image', event.detail.previewImage);
147
+ this._data.images.push({
148
+ image: event.detail.image.split(',')[1],
149
+ image_type_id: IMAGE_TYPE.ID_CARD_IMAGE_BASE64,
150
+ });
151
+ this.setActiveScreen(this.idReview);
152
+ },
153
+ );
154
+
155
+ this.idCapture.addEventListener('document-capture.publish', (event) => {
156
+ smartCameraWeb?.dispatchEvent(
157
+ new CustomEvent('metadata.document-front-capture-end'),
158
+ );
159
+ this.idReview.setAttribute('data-image', event.detail.previewImage);
160
+ this._data.images.push({
161
+ image: event.detail.image.split(',')[1],
162
+ image_type_id: IMAGE_TYPE.ID_CARD_IMAGE_BASE64,
163
+ });
164
+ SmartCamera.stopMedia();
165
+ this.setActiveScreen(this.idReview);
166
+ });
167
+
168
+ this.idCapture.addEventListener('document-capture.cancelled', () => {
169
+ if (this.hideInstructions) {
170
+ this.handleBackEvents();
171
+ } else {
172
+ this.setActiveScreen(this.documentInstruction);
173
+ }
174
+ });
175
+
176
+ this.idReview.addEventListener(
177
+ 'document-capture-review.rejected',
178
+ async () => {
179
+ smartCameraWeb?.dispatchEvent(
180
+ new CustomEvent('metadata.document-front-capture-retry'),
181
+ );
182
+ this.idReview.removeAttribute('data-image');
183
+ this._data.images.pop();
184
+ if (this.hideInstructions) {
185
+ this.setActiveScreen(this.idCapture);
186
+ await getPermissions(this.idCapture);
187
+ } else {
188
+ this.setActiveScreen(this.documentInstruction);
189
+ }
190
+ },
191
+ );
192
+
193
+ this.idReview.addEventListener(
194
+ 'document-capture-review.accepted',
195
+ async () => {
196
+ if (this.hideBackOfId) {
197
+ this._publishSelectedImages();
198
+ } else if (this.hideInstructions) {
199
+ this.setActiveScreen(this.idCaptureBack);
200
+ await getPermissions(this.idCaptureBack);
201
+ } else {
202
+ this.setActiveScreen(this.documentInstructionBack);
203
+ }
204
+ },
205
+ );
206
+
207
+ this.documentInstructionBack.addEventListener(
208
+ 'document-capture-instructions.capture',
209
+ async () => {
210
+ smartCameraWeb?.dispatchEvent(
211
+ new CustomEvent('metadata.document-back-capture-start'),
212
+ );
213
+ smartCameraWeb?.dispatchEvent(
214
+ new CustomEvent('metadata.document-back-origin', {
215
+ detail: { imageOrigin: 'camera_manual_capture' },
216
+ }),
217
+ );
218
+ this.setActiveScreen(this.idCaptureBack);
219
+ await getPermissions(this.idCaptureBack);
220
+ },
221
+ );
222
+
223
+ this.documentInstructionBack.addEventListener(
224
+ 'document-capture-instructions.cancelled',
225
+ async () => {
226
+ this.idReview.removeAttribute('data-image');
227
+ this._data.images.pop();
228
+ if (this.hideInstructions) {
229
+ this.setActiveScreen(this.idCapture);
230
+ await getPermissions(this.idCapture);
231
+ } else {
232
+ this.setActiveScreen(this.documentInstruction);
233
+ }
234
+ },
235
+ );
236
+
237
+ this.documentInstructionBack.addEventListener(
238
+ 'document-capture-instructions.upload',
239
+ async (event) => {
240
+ smartCameraWeb?.dispatchEvent(
241
+ new CustomEvent('metadata.document-back-origin', {
242
+ detail: { imageOrigin: 'gallery' },
243
+ }),
244
+ );
245
+ this.backOfIdReview.setAttribute('data-image', event.detail.image);
246
+ this._data.images.push({
247
+ image: event.detail.image.split(',')[1],
248
+ image_type_id: IMAGE_TYPE.ID_CARD_BACK_IMAGE_BASE64,
249
+ });
250
+ this.setActiveScreen(this.backOfIdReview);
251
+ },
252
+ );
253
+ this.idCaptureBack.addEventListener('document-capture.publish', (event) => {
254
+ smartCameraWeb?.dispatchEvent(
255
+ new CustomEvent('metadata.document-back-capture-end'),
256
+ );
257
+ this.backOfIdReview.setAttribute('data-image', event.detail.previewImage);
258
+ this._data.images.push({
259
+ image: event.detail.image.split(',')[1],
260
+ image_type_id: IMAGE_TYPE.ID_CARD_BACK_IMAGE_BASE64,
261
+ });
262
+ this.setActiveScreen(this.backOfIdReview);
263
+ SmartCamera.stopMedia();
264
+ });
265
+
266
+ this.idCaptureBack.addEventListener(
267
+ 'document-capture.cancelled',
268
+ async () => {
269
+ if (this.hideInstructions) {
270
+ this.setActiveScreen(this.idCapture);
271
+ await getPermissions(this.idCapture);
272
+ } else {
273
+ this.setActiveScreen(this.documentInstructionBack);
274
+ }
275
+ },
276
+ );
277
+
278
+ this.backOfIdReview.addEventListener(
279
+ 'document-capture-review.rejected',
280
+ async () => {
281
+ smartCameraWeb?.dispatchEvent(
282
+ new CustomEvent('metadata.document-back-capture-retry'),
283
+ );
284
+ this.backOfIdReview.removeAttribute('data-image');
285
+ this._data.images.pop();
286
+ if (this.hideInstructions) {
287
+ this.setActiveScreen(this.idCaptureBack);
288
+ await getPermissions(this.idCaptureBack);
289
+ } else {
290
+ this.setActiveScreen(this.documentInstructionBack);
291
+ }
292
+ },
293
+ );
294
+
295
+ this.backOfIdReview.addEventListener(
296
+ 'document-capture-review.accepted',
297
+ () => {
298
+ this._publishSelectedImages();
299
+ },
300
+ );
301
+
302
+ const screens = [
303
+ this.documentInstruction,
304
+ this.idCapture,
305
+ this.documentInstructionBack,
306
+ this.idCaptureBack,
307
+ this.idReview,
308
+ this.backOfIdReview,
309
+ ];
310
+
311
+ screens.forEach((screen) => {
312
+ screen.addEventListener(`${screen.nodeName.toLowerCase()}.close`, () =>
313
+ this.handleCloseEvents(),
314
+ );
315
+ });
316
+ }
317
+
318
+ _publishSelectedImages() {
319
+ this.dispatchEvent(
320
+ new CustomEvent('document-capture-screens.publish', {
321
+ detail: this._data,
322
+ }),
323
+ );
324
+ }
325
+
326
+ get hideInstructions() {
327
+ return this.hasAttribute('hide-instructions');
328
+ }
329
+
330
+ get hideBackOfId() {
331
+ return this.hasAttribute('hide-back-of-id');
332
+ }
333
+
334
+ get showNavigation() {
335
+ return this.hasAttribute('show-navigation') ? 'show-navigation' : '';
336
+ }
337
+
338
+ get title() {
339
+ return this.hasAttribute('title')
340
+ ? `title=${this.getAttribute('title')}`
341
+ : '';
342
+ }
343
+
344
+ get documentCaptureModes() {
345
+ return this.hasAttribute('document-capture-modes')
346
+ ? `document-capture-modes='${this.getAttribute('document-capture-modes')}'`
347
+ : '';
348
+ }
349
+
350
+ get documentType() {
351
+ return this.hasAttribute('document-type')
352
+ ? `document-type='${this.getAttribute('document-type')}'`
353
+ : '';
354
+ }
355
+
356
+ get hideAttribution() {
357
+ return this.hasAttribute('hide-attribution') ? 'hide-attribution' : '';
358
+ }
359
+
360
+ get themeColor() {
361
+ return this.getAttribute('theme-color') || '#001096';
362
+ }
363
+
364
+ handleBackEvents() {
365
+ this.dispatchEvent(new CustomEvent('document-capture-screens.cancelled'));
366
+ }
367
+
368
+ handleCloseEvents() {
369
+ this.dispatchEvent(new CustomEvent('document-capture-screens.close'));
370
+ }
371
+
372
+ setActiveScreen(screen) {
373
+ this.activeScreen?.setAttribute('hidden', '');
374
+ screen.removeAttribute('hidden');
375
+ this.activeScreen = screen;
376
+ }
377
+
378
+ static get observedAttributes() {
379
+ return [
380
+ 'document-capture-modes',
381
+ 'document-type',
382
+ 'hide-back-to-host',
383
+ 'show-navigation',
384
+ 'hide-back-of-id',
385
+ ];
386
+ }
387
+
388
+ attributeChangedCallback(name) {
389
+ switch (name) {
390
+ case 'document-capture-modes':
391
+ case 'document-type':
392
+ case 'hide-back-of-id':
393
+ case 'hide-back-to-host':
394
+ case 'show-navigation':
395
+ this.connectedCallback();
396
+ break;
397
+ default:
398
+ break;
399
+ }
400
+ }
401
+ }
402
+
403
+ if (
404
+ 'customElements' in window &&
405
+ !customElements.get('document-capture-screens')
406
+ ) {
407
+ customElements.define('document-capture-screens', DocumentCaptureScreens);
408
+ }
409
+
410
+ export default DocumentCaptureScreens;