@smileid/web-components 1.0.0-beta

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 (73) hide show
  1. package/.eslintrc.cjs +72 -0
  2. package/components/README.md +14 -0
  3. package/components/attribution/PoweredBySmileId.js +42 -0
  4. package/components/camera-permission/CameraPermission.js +136 -0
  5. package/components/camera-permission/CameraPermission.stories.js +21 -0
  6. package/components/combobox/src/Combobox.js +586 -0
  7. package/components/combobox/src/index.js +1 -0
  8. package/components/document/src/DocumentCaptureScreens.js +317 -0
  9. package/components/document/src/DocumentCaptureScreens.stories.js +51 -0
  10. package/components/document/src/README.md +108 -0
  11. package/components/document/src/document-capture/DocumentCapture.js +677 -0
  12. package/components/document/src/document-capture/DocumentCapture.stories.js +71 -0
  13. package/components/document/src/document-capture/README.md +89 -0
  14. package/components/document/src/document-capture/index.js +3 -0
  15. package/components/document/src/document-capture-instructions/DocumentCaptureInstructions.js +499 -0
  16. package/components/document/src/document-capture-instructions/DocumentCaptureInstructions.stories.js +17 -0
  17. package/components/document/src/document-capture-instructions/README.md +56 -0
  18. package/components/document/src/document-capture-instructions/index.js +3 -0
  19. package/components/document/src/document-capture-review/DocumentCaptureReview.js +378 -0
  20. package/components/document/src/document-capture-review/DocumentCaptureReview.stories.js +14 -0
  21. package/components/document/src/document-capture-review/README.md +79 -0
  22. package/components/document/src/document-capture-review/index.js +3 -0
  23. package/components/document/src/index.js +3 -0
  24. package/components/end-user-consent/src/EndUserConsent.js +809 -0
  25. package/components/end-user-consent/src/EndUserConsent.stories.js +23 -0
  26. package/components/end-user-consent/src/index.js +4 -0
  27. package/components/navigation/src/Navigation.js +160 -0
  28. package/components/navigation/src/Navigation.stories.js +24 -0
  29. package/components/navigation/src/index.js +3 -0
  30. package/components/selfie/README.md +201 -0
  31. package/components/selfie/src/SelfieCaptureScreens.js +224 -0
  32. package/components/selfie/src/SelfieCaptureScreens.stories.js +21 -0
  33. package/components/selfie/src/index.js +5 -0
  34. package/components/selfie/src/selfie-capture/SelfieCapture.js +878 -0
  35. package/components/selfie/src/selfie-capture/SelfieCapture.stories.js +23 -0
  36. package/components/selfie/src/selfie-capture/index.js +3 -0
  37. package/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.js +638 -0
  38. package/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.stories.js +17 -0
  39. package/components/selfie/src/selfie-capture-instructions/index.js +3 -0
  40. package/components/selfie/src/selfie-capture-review/SelfieCaptureReview.js +348 -0
  41. package/components/selfie/src/selfie-capture-review/SelfieCaptureReview.stories.js +17 -0
  42. package/components/selfie/src/selfie-capture-review/index.js +3 -0
  43. package/components/signature-pad/package.json +30 -0
  44. package/components/signature-pad/src/SignaturePad.js +477 -0
  45. package/components/signature-pad/src/SignaturePad.stories.js +24 -0
  46. package/components/signature-pad/src/index.js +3 -0
  47. package/components/smart-camera-web/src/SmartCameraWeb.js +246 -0
  48. package/components/smart-camera-web/src/SmartCameraWeb.stories.js +35 -0
  49. package/components/totp-consent/src/TotpConsent.js +935 -0
  50. package/components/totp-consent/src/index.js +4 -0
  51. package/cypress/e2e/smart-camera-web-attribution.cy.js +21 -0
  52. package/cypress/e2e/smart-camera-web-back-press.cy.js +481 -0
  53. package/cypress/e2e/smart-camera-web-hide-instructions.cy.js +334 -0
  54. package/cypress/e2e/smart-camera-web.cy.js +309 -0
  55. package/cypress/fixtures/example.json +5 -0
  56. package/cypress/pages/capture-back-of-id-hide-attribution.html +44 -0
  57. package/cypress/pages/capture-back-of-id-navigation.html +72 -0
  58. package/cypress/pages/smart-camera-web-hide-instructions.html +38 -0
  59. package/cypress/pages/smart-camera-web.html +38 -0
  60. package/cypress/support/commands.js +144 -0
  61. package/cypress/support/e2e.js +20 -0
  62. package/cypress.config.js +11 -0
  63. package/domain/camera/src/README.md +38 -0
  64. package/domain/camera/src/SmartCamera.js +81 -0
  65. package/domain/constants/src/Constants.js +27 -0
  66. package/domain/file-upload/README.md +35 -0
  67. package/domain/file-upload/src/SmartFileUpload.js +65 -0
  68. package/esbuild.js +119 -0
  69. package/index.js +5 -0
  70. package/package.json +46 -0
  71. package/styles/README.md +3 -0
  72. package/styles/src/styles.js +348 -0
  73. package/styles/src/typography.js +52 -0
@@ -0,0 +1,246 @@
1
+ import styles from '../../../styles/src/styles';
2
+ import SmartCamera from '../../../domain/camera/src/SmartCamera';
3
+
4
+ import '../../document/src';
5
+ import '../../selfie/src';
6
+ import '../../camera-permission/CameraPermission';
7
+
8
+ import { version as COMPONENTS_VERSION } from '../../../package.json';
9
+
10
+ function scwTemplateString() {
11
+ return `
12
+ ${styles}
13
+ <div>
14
+ <camera-permission ${this.title} ${this.showNavigation} ${this.hideInstructions ? '' : 'hidden'}></camera-permission>
15
+ <selfie-capture-screens ${this.title} ${this.showNavigation} ${this.disableImageTests} ${this.hideAttribution} ${this.hideInstructions} hidden
16
+ ${this.hideBackToHost}
17
+ ></selfie-capture-screens>
18
+ <document-capture-screens document-type=${this.documentType} ${this.title} ${this.documentCaptureModes} ${this.showNavigation} ${this.hideAttribution} hidden></document-capture-screens>
19
+ </div>
20
+ `;
21
+ }
22
+ class SmartCameraWeb extends HTMLElement {
23
+ constructor() {
24
+ super();
25
+ this.scwTemplateString = scwTemplateString.bind(this);
26
+ this.render = () => this.scwTemplateString();
27
+ this.attachShadow({ mode: 'open' });
28
+ this.activeScreen = null;
29
+ }
30
+
31
+ connectedCallback() {
32
+ this.shadowRoot.innerHTML = this.render();
33
+
34
+ this._data = {
35
+ images: [],
36
+ meta: {
37
+ libraryVersion: COMPONENTS_VERSION,
38
+ },
39
+ };
40
+
41
+ if (
42
+ 'mediaDevices' in navigator &&
43
+ 'getUserMedia' in navigator.mediaDevices
44
+ ) {
45
+ this.setUpEventListeners();
46
+ } else {
47
+ this.shadowRoot.innerHTML =
48
+ '<h1 class="error-message">Your browser does not support this integration</h1>';
49
+ }
50
+ }
51
+
52
+ disconnectedCallback() {
53
+ SmartCamera.stopMedia();
54
+ if (this.activeScreen) {
55
+ this.activeScreen.removeAttribute('hidden');
56
+ }
57
+ this.activeScreen = null;
58
+ this.shadowRoot.innerHTML = '';
59
+ }
60
+
61
+ static get observedAttributes() {
62
+ return [
63
+ 'document-capture-modes',
64
+ 'document-type',
65
+ 'hide-back-to-host',
66
+ 'show-navigation',
67
+ ];
68
+ }
69
+
70
+ attributeChangedCallback(name) {
71
+ switch (name) {
72
+ case 'document-capture-modes':
73
+ case 'document-type':
74
+ case 'hide-back-to-host':
75
+ case 'show-navigation':
76
+ this.shadowRoot.innerHTML = this.render();
77
+ this.setUpEventListeners();
78
+ break;
79
+ default:
80
+ break;
81
+ }
82
+ }
83
+
84
+ setUpEventListeners() {
85
+ this.cameraPermission = this.shadowRoot.querySelector('camera-permission');
86
+ this.SelfieCaptureScreens = this.shadowRoot.querySelector(
87
+ 'selfie-capture-screens',
88
+ );
89
+ this.documentCapture = this.shadowRoot.querySelector(
90
+ 'document-capture-screens',
91
+ );
92
+
93
+ if (this.hideInstructions) {
94
+ this.setActiveScreen(this.cameraPermission);
95
+ } else {
96
+ this.setActiveScreen(this.SelfieCaptureScreens);
97
+ }
98
+ this.cameraPermission.addEventListener('camera-permission.granted', () => {
99
+ this.setActiveScreen(this.SelfieCaptureScreens);
100
+ this.SelfieCaptureScreens.removeAttribute('data-camera-error');
101
+ this.SelfieCaptureScreens.setAttribute('data-camera-ready', true);
102
+ });
103
+
104
+ this.SelfieCaptureScreens.addEventListener(
105
+ 'selfie-capture-screens.publish',
106
+ (event) => {
107
+ this._data.images = event.detail.images;
108
+ this.setActiveScreen(this.documentCapture);
109
+ },
110
+ );
111
+
112
+ this.SelfieCaptureScreens.addEventListener(
113
+ 'selfie-capture-screens.cancelled',
114
+ () => {
115
+ if (this.hideInstructions) {
116
+ this.setActiveScreen(this.cameraPermission);
117
+ } else {
118
+ this.handleBackEvents();
119
+ }
120
+ },
121
+ );
122
+ this.SelfieCaptureScreens.addEventListener(
123
+ 'selfie-capture-screens.back',
124
+ () => {
125
+ if (!this.hideInstructions) {
126
+ this.setActiveScreen(this.cameraPermission);
127
+ }
128
+ },
129
+ );
130
+
131
+ this.documentCapture.addEventListener(
132
+ 'document-capture-screens.publish',
133
+ (event) => {
134
+ this._data.images = [...this._data.images, ...event.detail.images];
135
+ this._publishSelectedImages();
136
+ },
137
+ );
138
+
139
+ this.documentCapture.addEventListener(
140
+ 'document-capture-screens.cancelled',
141
+ () => {
142
+ this.SelfieCaptureScreens.setAttribute(
143
+ 'initial-screen',
144
+ 'selfie-capture',
145
+ );
146
+ this.setActiveScreen(this.SelfieCaptureScreens);
147
+ this.SelfieCaptureScreens.removeAttribute('data-camera-error');
148
+ this.SelfieCaptureScreens.setAttribute('data-camera-ready', true);
149
+ },
150
+ );
151
+
152
+ [
153
+ this.cameraPermission,
154
+ this.SelfieCaptureScreens,
155
+ this.documentCapture,
156
+ ].forEach((screen) => {
157
+ screen.addEventListener(`${screen.nodeName.toLowerCase()}.close`, () =>
158
+ this.handleCloseEvent(),
159
+ );
160
+ });
161
+ this.documentCapture.addEventListener(
162
+ 'document-capture-screens.back',
163
+ () => {
164
+ this.setActiveScreen(this.SelfieCaptureScreens);
165
+ this.reset();
166
+ },
167
+ );
168
+ }
169
+
170
+ reset() {
171
+ this.disconnectedCallback();
172
+ this.connectedCallback();
173
+ }
174
+
175
+ handleBackEvents() {
176
+ this.dispatchEvent(new CustomEvent('smart-camera-web.cancelled'));
177
+ }
178
+
179
+ _publishSelectedImages() {
180
+ this.dispatchEvent(
181
+ new CustomEvent('smart-camera-web.publish', { detail: this._data }),
182
+ );
183
+ }
184
+
185
+ get documentType() {
186
+ return this.getAttribute('document-type');
187
+ }
188
+
189
+ get isPortraitCaptureView() {
190
+ return this.getAttribute('document-type') === 'GREEN_BOOK';
191
+ }
192
+
193
+ get hideInstructions() {
194
+ return this.hasAttribute('hide-instructions') ? 'hide-instructions' : '';
195
+ }
196
+
197
+ get hideBackOfId() {
198
+ return this.hasAttribute('hide-back-of-id');
199
+ }
200
+
201
+ get showNavigation() {
202
+ return this.hasAttribute('show-navigation') ? 'show-navigation' : '';
203
+ }
204
+
205
+ get hideBackToHost() {
206
+ return this.hasAttribute('hide-back-to-host') ? 'hide-back-to-host' : '';
207
+ }
208
+
209
+ get title() {
210
+ return this.hasAttribute('title')
211
+ ? `title=${this.getAttribute('title')}`
212
+ : '';
213
+ }
214
+
215
+ get documentCaptureModes() {
216
+ return this.hasAttribute('document-capture-modes')
217
+ ? `document-capture-modes='${this.getAttribute('document-capture-modes')}'`
218
+ : '';
219
+ }
220
+
221
+ get disableImageTests() {
222
+ return this.hasAttribute('disable-image-tests')
223
+ ? 'disable-image-tests'
224
+ : '';
225
+ }
226
+
227
+ get hideAttribution() {
228
+ return this.hasAttribute('hide-attribution') ? 'hide-attribution' : '';
229
+ }
230
+
231
+ setActiveScreen(screen) {
232
+ this.activeScreen?.setAttribute('hidden', '');
233
+ screen.removeAttribute('hidden');
234
+ this.activeScreen = screen;
235
+ }
236
+
237
+ handleCloseEvent() {
238
+ this.dispatchEvent(new CustomEvent('smart-camera-web.close'));
239
+ }
240
+ }
241
+
242
+ if ('customElements' in window && !customElements.get('smart-camera-web')) {
243
+ customElements.define('smart-camera-web', SmartCameraWeb);
244
+ }
245
+
246
+ export default SmartCameraWeb;
@@ -0,0 +1,35 @@
1
+ import './SmartCameraWeb';
2
+
3
+ const meta = {
4
+ component: 'smart-camera-web',
5
+ };
6
+
7
+ export default meta;
8
+
9
+ export const SmartCameraWeb = {
10
+ render: () => `
11
+ <smart-camera-web show-navigation>
12
+ </smart-camera-web>
13
+ `,
14
+ };
15
+
16
+ export const SmartCameraWebWithOutInstructions = {
17
+ render: () => `
18
+ <smart-camera-web hide-instructions>
19
+ </smart-camera-web>
20
+ `,
21
+ };
22
+
23
+ export const SmartCameraWebWithOutNavigation = {
24
+ render: () => `
25
+ <smart-camera-web>
26
+ </smart-camera-web>
27
+ `,
28
+ };
29
+
30
+ export const SmartCameraWebWithOutBackToHost = {
31
+ render: () => `
32
+ <smart-camera-web show-navigation hide-back-to-host>
33
+ </smart-camera-web>
34
+ `,
35
+ };