@regulaforensics/vp-frontend-document-components 1.1.0 → 2.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 (91) hide show
  1. package/README.md +694 -81
  2. package/dist/main.js +1 -1
  3. package/dist/main.js.LICENSE.txt +41 -0
  4. package/esm/main.js +2 -0
  5. package/esm/main.js.LICENSE.txt +41 -0
  6. package/lib/common/BackCameraIcon.d.ts +6 -0
  7. package/lib/common/Button.d.ts +7 -0
  8. package/lib/common/CameraChangeIcon.d.ts +6 -0
  9. package/lib/common/CameraIcon.d.ts +6 -0
  10. package/lib/common/CheckIcon.d.ts +6 -0
  11. package/lib/common/CrossIcon.d.ts +6 -0
  12. package/lib/common/DocReaderCameraDisabled.d.ts +5 -0
  13. package/lib/common/DocReaderCameraPreparing.d.ts +5 -0
  14. package/lib/common/DocReaderFlip.d.ts +5 -0
  15. package/lib/common/DocReaderProcessing.d.ts +5 -0
  16. package/lib/common/DocReaderProcessingError.d.ts +5 -0
  17. package/lib/common/DocReaderProcessingFinished.d.ts +6 -0
  18. package/lib/common/DocReaderSearch.d.ts +5 -0
  19. package/lib/common/ErrorIcon.d.ts +6 -0
  20. package/lib/common/FromCameraIcon.d.ts +5 -0
  21. package/lib/common/FromGalleryIcon.d.ts +5 -0
  22. package/lib/common/FrontCameraIcon.d.ts +6 -0
  23. package/lib/common/FullscreenExitIcon.d.ts +6 -0
  24. package/lib/common/FullscreenIcon.d.ts +6 -0
  25. package/lib/common/Icon.d.ts +7 -0
  26. package/lib/common/InstructionIconFaceDetection.d.ts +5 -0
  27. package/lib/common/InstructionIconFaceLiveness.d.ts +5 -0
  28. package/lib/common/Message.d.ts +7 -0
  29. package/lib/common/NoGlareIcon.d.ts +5 -0
  30. package/lib/common/NoSmilingIcon.d.ts +5 -0
  31. package/lib/common/RegulaLogo.d.ts +6 -0
  32. package/lib/common/SnapshotIcon.d.ts +6 -0
  33. package/lib/common/Spinner.d.ts +3 -0
  34. package/lib/common/SquareIcon.d.ts +6 -0
  35. package/lib/common/StopIcon.d.ts +6 -0
  36. package/lib/common/VerifiedIcon.d.ts +6 -0
  37. package/lib/components/CameraCapture.d.ts +9 -0
  38. package/lib/components/CameraSnapshot.d.ts +2 -0
  39. package/lib/components/CameraSnapshotFileCapture.d.ts +10 -0
  40. package/lib/components/DocumentCapture.d.ts +10 -0
  41. package/lib/components/DocumentFullScreenOverlay.d.ts +11 -0
  42. package/lib/components/DocumentReader.d.ts +2 -0
  43. package/lib/components/DocumentReaderFileCapture.d.ts +12 -0
  44. package/lib/components/DocumentReaderLayout.d.ts +22 -0
  45. package/lib/components/DocumentReaderStartScreen.d.ts +10 -0
  46. package/lib/components/ErrorBoundary.d.ts +18 -0
  47. package/lib/components/FaceCapture.d.ts +15 -0
  48. package/lib/components/FaceDetection.d.ts +2 -0
  49. package/lib/components/FaceFullScreenOverlay.d.ts +11 -0
  50. package/lib/components/FaceLayout.d.ts +18 -0
  51. package/lib/components/FaceLiveness.d.ts +2 -0
  52. package/lib/components/InfoScreen.d.ts +10 -0
  53. package/lib/components/InstructionScreen.d.ts +9 -0
  54. package/lib/components/ProcessScreen.d.ts +6 -0
  55. package/lib/components/RetryScreen.d.ts +7 -0
  56. package/lib/components/WebCamera.d.ts +19 -0
  57. package/lib/constants.d.ts +568 -0
  58. package/lib/contexts/DocumentAttributesContext.d.ts +24 -0
  59. package/lib/contexts/DocumentSDKContext.d.ts +6 -0
  60. package/lib/contexts/FaceAttributesContext.d.ts +21 -0
  61. package/lib/hoc/withDocumentAttributesContext.d.ts +4 -0
  62. package/lib/hoc/withDocumentSDKContext.d.ts +3 -0
  63. package/lib/hoc/withFaceAttributesContext.d.ts +4 -0
  64. package/lib/hoc/withLocalize.d.ts +7 -0
  65. package/lib/hooks/useDocumentReaderSeries.d.ts +25 -0
  66. package/lib/hooks/useDocumentReaderSingle.d.ts +15 -0
  67. package/lib/hooks/useFaceLiveness.d.ts +30 -0
  68. package/lib/hooks/useImageInputParam.d.ts +9 -0
  69. package/lib/hooks/useOrientationChange.d.ts +10 -0
  70. package/lib/hooks/useStream.d.ts +10 -0
  71. package/lib/hooks/useUserAgent.d.ts +3 -0
  72. package/lib/hooks/useWindowBlur.d.ts +2 -0
  73. package/lib/i18n/dictionaries/_dictionaries.d.ts +2115 -0
  74. package/lib/index-document.d.ts +5 -0
  75. package/lib/models/CameraModel.d.ts +9 -0
  76. package/lib/models/CustomError.d.ts +7 -0
  77. package/lib/models/ImageModel.d.ts +7 -0
  78. package/lib/services/DebugService.d.ts +13 -0
  79. package/lib/services/DocumentReaderProcessor.d.ts +53 -0
  80. package/lib/services/DocumentReaderService.d.ts +44 -0
  81. package/lib/services/EventEmitter.d.ts +9 -0
  82. package/lib/services/FaceLivenessService.d.ts +43 -0
  83. package/lib/services/FaceService.d.ts +12 -0
  84. package/lib/types.d.ts +323 -0
  85. package/lib/utils.d.ts +27 -0
  86. package/lib/web-components/CameraSnapshot.d.ts +11 -0
  87. package/lib/web-components/DocumentReader.d.ts +11 -0
  88. package/lib/web-components/FaceDetection.d.ts +11 -0
  89. package/lib/web-components/FaceLiveness.d.ts +14 -0
  90. package/lib/web-components/FullScreenContainer.d.ts +4 -0
  91. package/package.json +63 -67
package/README.md CHANGED
@@ -1,144 +1,757 @@
1
- # Table of сontents
1
+ # Table of contents
2
2
  1. [About](#about)
3
- 1. [Install via NPM](#npm)
4
- 1. [Install via CDN](#cdn)
5
- 1. [Component events](#events)
6
- 1. [Component response](#response)
7
- 1. [Component attributes](#attributes)
8
- 1. [Examples](#examples)
3
+ 2. [Compatibility](#compatibility)
4
+ 3. [UI components](#ui-components)
5
+ * [Integration via NPM](#integration-via-npm)
6
+ * [Integration via CDN](#integration-via-cdn)
7
+ * [Events](#events)
8
+ * [Response](#response)
9
+ * [Attributes](#attributes)
10
+ * [Customization](#customization)
11
+ 4. [Document reader SDK](#document-reader-sdk)
12
+ * [SDK integration via NPM](#sdk-integration-via-npm)
13
+ * [SDK integration via CDN](#sdk-integration-via-cdn)
14
+ * [Available DocumentReaderProcessor methods](#available-documentreaderprocessor-methods)
15
+ * [DocumentReaderProcessor settings](#documentreaderprocessor-settings)
16
+ 5. [Problems](#problems)
17
+ 6. [Examples](#examples)
9
18
 
10
19
  ---
11
20
 
12
- <a name="about"></a>
13
21
  ## About
14
22
 
15
- This package contains web components for documents recognition.
23
+ This package contains UI web components and SDK for documents recognition.
16
24
 
17
- <a name="npm"></a>
18
- ## Install via NPM
25
+ ## Compatibility
19
26
 
20
- On the command line, navigate to the root directory of your project:
27
+ | Devices | ![Chrome](https://raw.githubusercontent.com/alrra/browser-logos/main/src/chrome/chrome_48x48.png) | ![FireFox](https://raw.githubusercontent.com/alrra/browser-logos/main/src/firefox/firefox_48x48.png) | ![Safari](https://raw.githubusercontent.com/alrra/browser-logos/main/src/safari/safari_48x48.png) |
28
+ |:---------------------|:-------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------:|
29
+ | **Mobile (iOS)** | 99 | 99 | 11 |
30
+ | **Mobile (Android)** | 66 | 61 | - |
31
+ | **Desktop** | 61 | 60 | 11 |
32
+
33
+ ## UI components
34
+
35
+ ### Integration via NPM
36
+
37
+ Install ```@regulaforensics/vp-frontend-document-components```:
21
38
 
22
39
  ```
23
- cd /path/to/project
40
+ npm i @regulaforensics/vp-frontend-document-components
24
41
  ```
25
42
 
26
- Run the following command:
43
+ Import ```defineComponents``` and ```DocumentReaderService``` from ```@regulaforensics/vp-frontend-document-components``` into your ```.js``` file:
44
+
45
+ ```javascript
46
+ // If you use module bundler
47
+ import { defineComponents, DocumentReaderService } from '@regulaforensics/vp-frontend-document-components';
27
48
 
49
+ // If you don't use module bundler
50
+ import { defineComponents, DocumentReaderService } from './node_modules/@regulaforensics/vp-frontend-document-components/esm/main.js';
28
51
  ```
29
- npm init
52
+
53
+ Add ```DocumentReaderService``` to the global variable ```RegulaDocumentSDK```, define the components and prepare the service:
54
+
55
+ ```javascript
56
+ window.RegulaDocumentSDK = new DocumentReaderService();
57
+
58
+ defineComponents().then(async () => {
59
+ await window.RegulaDocumentSDK.prepare();
60
+ });
61
+
62
+ // Notice: If you use only the camera-snapshot component, then it is not necessary to create a global variable and prepare the service, use only defineComponents();
30
63
  ```
31
- Answer the questions in the command line questionnaire.
32
64
 
33
- Install ```@regulaforensics/vp-frontend-document-components```:
65
+ Add the component name to the ```.html``` file. The available components are:
34
66
 
67
+ ```html
68
+ <document-reader></document-reader> <!-- for documents recognition -->
69
+ <camera-snapshot></camera-snapshot> <!-- to capture images from the camera and gallery -->
35
70
  ```
36
- npm i @regulaforensics/vp-frontend-document-components
71
+
72
+ Notice: To use ```<document-reader></document-reader>``` component on test environments, set the base64 license value to the ```license``` attribute. Example: ```<document-reader license="BASE64_LICENSE_KEY"></document-reader>```.
73
+
74
+ ### Integration via CDN
75
+
76
+ Connect the script in your ```.html``` file. CDN link: ```unpkg.com/:package@:version/:file```
77
+
78
+ For example:
79
+
80
+ ```html
81
+ <!-- Replace <VERSION> with the package version. The list of versions is available on NPM in the versions section -->
82
+ <script src="https://unpkg.com/@regulaforensics/vp-frontend-document-components@<VERSION>/dist/main.js"></script>
37
83
  ```
38
84
 
39
- Create ```index.html``` and ```index.js``` files in the root directory of the project.
85
+ In your ```.js``` file define the components and prepare the service. ```DocumentReaderService``` and ```defineComponents``` are available in the global variable ```window.Regula```:
86
+
87
+ ```javascript
88
+ const { defineComponents, DocumentReaderService } = window.Regula;
40
89
 
41
- Import ```@regulaforensics/vp-frontend-document-components``` into your ```index.js```:
90
+ window.RegulaDocumentSDK = new DocumentReaderService();
91
+
92
+ defineComponents().then(async () => {
93
+ await window.RegulaDocumentSDK.prepare();
94
+ });
95
+
96
+ // Notice: If you use only the camera-snapshot component, then it is not necessary to create a global variable and prepare the service, use only defineComponents();
97
+ ```
98
+
99
+ Add the component name to the ```.html``` file. The available components are:
100
+
101
+ ```html
102
+ <document-reader></document-reader> <!-- for documents recognition -->
103
+ <camera-snapshot></camera-snapshot> <!-- to capture images from the camera and gallery -->
104
+ ```
105
+
106
+ Notice: To use ```<document-reader></document-reader>``` component on test environments, set the base64 license value to the ```license``` attribute. Example: ```<document-reader license="BASE64_LICENSE_KEY"></document-reader>```.
107
+
108
+ ### Events
109
+
110
+ You can subscribe to the component events.
111
+
112
+ For example:
42
113
 
43
114
  ```javascript
44
- import './node_modules/@regulaforensics/vp-frontend-document-components/dist/main.js';
115
+ const documentReaderComponent = document.querySelector('document-reader');
116
+ const cameraSnapshotComponent = document.querySelector('camera-snapshot');
117
+
118
+ documentReaderComponent.addEventListener('document-reader', (event) => console.log(event.detail)); // Event listener for document-reader component.
119
+ cameraSnapshotComponent.addEventListener('camera-snapshot', (event) => console.log(event.detail)); // Event listener for camera-snapshot component.
45
120
  ```
46
121
 
47
- In ```index.html``` connect ```index.js``` and add the name of the component you want to use. Available components:
122
+ The ```document-reader``` type of event is generated for the document-reader component, and ```camera-snapshot``` type of event is generated for the camera-snapshot component.
48
123
 
49
- <!-- 1. ```<document-reader></document-reader>``` - for documents recognition; -->
50
- 1. ```<camera-snapshot></camera-snapshot>``` - to capture images from the camera and gallery.
124
+ The generated event object (```event.detail```) contains three fields that describe the event:
51
125
 
52
- Example:
126
+ ```javascript
127
+ {
128
+ action: "PRESS_CAMERA_BUTTON", // the type of action that generated the event (all actions are described in the table below)
129
+ data: null, // component data
130
+ manual: true // event generated by user action or component by itself
131
+ }
132
+ ```
53
133
 
54
- ```html
55
- <!DOCTYPE html>
56
- <html>
57
- <head>
58
- <meta charset="utf-8" />
59
- <title>My app</title>
60
- </head>
61
- <body>
62
- <camera-snapshot></camera-snapshot>
63
- <script type="module" src="index.js"></script>
64
- </body>
65
- </html>
66
- ```
67
-
68
- <a name="cdn"></a>
69
- ## Install via CDN
134
+ Type of actions:
70
135
 
71
- Connect the script in your ```.html``` file. CDN link: ```unpkg.com/:package@:version/:file```
136
+ | Type of action | Description of the action | In which component is present |
137
+ |:--------------------------|:-------------------------------------:|:--------------------------------------------:|
138
+ | ```ELEMENT_VISIBLE``` | Component is appended in the DOM. | ```document-reader```, ```camera-snapshot``` |
139
+ | ```PRESS_CAMERA_BUTTON``` | The "From camera" button is pressed. | ```document-reader```, ```camera-snapshot``` |
140
+ | ```PRESS_FILE_BUTTON``` | The "From gallery" button is pressed. | ```document-reader```, ```camera-snapshot``` |
141
+ | ```PRESS_RETRY_BUTTON``` | The "Retry" button is pressed. | ```document-reader```, ```camera-snapshot``` |
142
+ | ```PRESS_SKIP_BUTTON``` | The "Skip" button is pressed. | ```document-reader``` |
143
+ | ```CLOSE``` | The "Close" button is pressed. | ```document-reader```, ```camera-snapshot``` |
144
+ | ```PROCESS_FINISHED``` | The component has finished its work. | ```document-reader```, ```camera-snapshot``` |
145
+ | ```SERVICE_INITIALIZED``` | The component has started its work. | ```document-reader``` |
72
146
 
73
- Example:
147
+ In cases of successful operation of the components, the ```data``` field will contain the following fields:
74
148
 
75
- ```html
76
- <script src="https://unpkg.com/@regulaforensics/vp-frontend-document-components@1.0.0/dist/main.js"></script>
149
+ ```javascript
150
+ {
151
+ response: { ... }, // component result
152
+ status: 1 // 1 for successful work and 0 for unsuccessful
153
+ }
77
154
  ```
78
155
 
79
- Add the name of the component to the html, as in the example above.
156
+ In cases of unsuccessful work, the ```data``` field will contain the following fields:
80
157
 
81
- <a name="events"></a>
82
- ## Component events
158
+ ```javascript
159
+ {
160
+ reason: "CAMERA_PERMISSION_DENIED", // error reason (possible causes of errors are described in the table below)
161
+ status: 0
162
+ }
163
+ ```
164
+
165
+ Table of error causes:
166
+
167
+ | Reason | Description of the reason |
168
+ |:-------------------------------|:-----------------------------------:|
169
+ | ```WASM_ERROR``` | Error in WASM. |
170
+ | ```WASM_LICENSE``` | Missing or incorrect license. |
171
+ | ```FILE_SIZE``` | The file size is too large. |
172
+ | ```INCORRECT_FILE``` | Problems with reading the file. |
173
+ | ```UNKNOWN_ERROR``` | Unknown error. |
174
+ | ```NOT_SUPPORTED``` | The browser is not supported. |
175
+ | ```CAMERA_UNKNOWN_ERROR``` | Unknown camera error. |
176
+ | ```CAMERA_PERMISSION_DENIED``` | Access to the camera is prohibited. |
177
+ | ```NO_CAMERA``` | There is no camera. |
178
+ | ```CONNECTION_ERROR``` | Connection errors. |
179
+
180
+ The table below describes the cases of event generation:
181
+
182
+ <table>
183
+ <thead>
184
+ <tr>
185
+ <th>Event condition </th>
186
+ <th>Event type</th>
187
+ <th>
188
+
189
+ Event object ```event.detail```
190
+ </th>
191
+ <th>Description</th>
192
+ </tr>
193
+ </thead>
194
+ <tbody>
195
+ <tr>
196
+ <td>The component is mounted in the DOM.</td>
197
+ <td>
198
+
199
+ For document-reader:
200
+ ```document-reader```
201
+
202
+ For camera-snapshot:
203
+ ```camera-snapshot```
204
+
205
+ </td>
206
+ <td>
207
+
208
+ ```javascript
209
+ {
210
+ action: "ELEMENT_VISIBLE",
211
+ data: null,
212
+ manual: true
213
+ }
214
+ ```
83
215
 
84
- You can subscribe to component events. In cases of successful and unsuccessful work, the following events will be triggered:
216
+ </td>
217
+ <td>
85
218
 
86
- <!-- For the ```document-reader``` component - ```document-reader``` -->
87
- For the ```camera-snapshot``` component - ```camera-snapshot```
219
+ To receive this event, you must wrap the component in another element (for example, a div) and add an addEventListener to it. When the component appears in the DOM, the event will pop up.
88
220
 
89
221
  Example:
222
+ ```html
223
+ <div id="add-event-listener-to-this-element">
224
+ <document-reader></document-reader>
225
+ </div>
226
+ ```
227
+
228
+ </td>
229
+ </tr>
230
+ <tr>
231
+ <td>The "From camera" button is pressed.</td>
232
+ <td>
233
+
234
+ For document-reader:
235
+ ```document-reader```
236
+
237
+ For camera-snapshot:
238
+ ```camera-snapshot```
239
+
240
+ </td>
241
+ <td>
242
+
243
+ ```javascript
244
+ {
245
+ action: "PRESS_CAMERA_BUTTON",
246
+ data: null,
247
+ manual: true
248
+ }
249
+ ```
250
+
251
+ </td>
252
+ <td></td>
253
+ </tr>
254
+ <tr>
255
+ <td>The "From gallery" button is pressed.</td>
256
+ <td>
257
+
258
+ For document-reader:
259
+ ```document-reader```
260
+
261
+ For camera-snapshot:
262
+ ```camera-snapshot```
263
+
264
+ </td>
265
+ <td>
90
266
 
91
267
  ```javascript
92
- const component = document.getElementsByTagName('camera-snapshot')[0];
268
+ {
269
+ action: "PRESS_FILE_BUTTON",
270
+ data: null,
271
+ manual: true
272
+ }
273
+ ```
274
+
275
+ </td>
276
+ <td></td>
277
+ </tr>
278
+ <tr>
279
+ <td>The "Retry" button is pressed.</td>
280
+ <td>
281
+
282
+ For document-reader:
283
+ ```document-reader```
284
+
285
+ For camera-snapshot:
286
+ ```camera-snapshot```
93
287
 
94
- component.addEventListener('camera-snapshot', () => alert('Event!'));
288
+ </td>
289
+ <td>
290
+
291
+ ```javascript
292
+ {
293
+ action: "PRESS_RETRY_BUTTON",
294
+ data: null,
295
+ manual: true
296
+ }
95
297
  ```
96
298
 
97
- <a name="response"></a>
98
- ## Component response
299
+ </td>
300
+ <td></td>
301
+ </tr>
302
+ <tr>
303
+ <td>The "Skip page" button is pressed.</td>
304
+ <td>
305
+
306
+ ```document-reader```
99
307
 
100
- You can get the response of the component in the ```detail``` field of the event object.
308
+ </td>
309
+ <td>
101
310
 
102
- Example:
311
+ ```javascript
312
+ {
313
+ action: "PRESS_SKIP_BUTTON",
314
+ data: null,
315
+ manual: true
316
+ }
317
+ ```
318
+
319
+ </td>
320
+ <td>
321
+
322
+ This event available only in ```document-reader```.
323
+
324
+ </td>
325
+ </tr>
326
+ <tr>
327
+ <td>The "Close" button is pressed.</td>
328
+ <td>
329
+
330
+ For document-reader:
331
+ ```document-reader```
332
+
333
+ For camera-snapshot:
334
+ ```camera-snapshot```
335
+
336
+ </td>
337
+ <td>
103
338
 
104
339
  ```javascript
105
- const component = document.getElementsByTagName('camera-snapshot')[0];
340
+ {
341
+ action: "CLOSE",
342
+ data: null,
343
+ manual: true
344
+ }
345
+ ```
346
+
347
+ </td>
348
+ <td></td>
349
+ </tr>
350
+ <tr>
351
+ <td>The work of the component is completed successfully.</td>
352
+ <td>
353
+
354
+ For document-reader:
355
+ ```document-reader```
356
+
357
+ For camera-snapshot:
358
+ ```camera-snapshot```
359
+
360
+ </td>
361
+ <td>
362
+
363
+ ```javascript
364
+ {
365
+ action: "PROCESS_FINISHED",
366
+ data: {
367
+ response: { ... },
368
+ status: 1
369
+ },
370
+ manual: false
371
+ }
372
+ ```
373
+
374
+ </td>
375
+ <td></td>
376
+ </tr>
377
+ <tr>
378
+ <td>The work of the component failed.</td>
379
+ <td>
380
+
381
+ For document-reader:
382
+ ```document-reader```
383
+
384
+ For camera-snapshot:
385
+ ```camera-snapshot```
386
+
387
+ </td>
388
+ <td>
389
+
390
+ ```javascript
391
+ {
392
+ action: "PROCESS_FINISHED",
393
+ data: {
394
+ reason: "An error has occurred",
395
+ status: 0
396
+ },
397
+ manual: false
398
+ }
399
+ ```
400
+
401
+ </td>
402
+ <td></td>
403
+ </tr>
404
+ <tr>
405
+ <td>Component is initialized and ready to work.</td>
406
+ <td>
407
+
408
+ ```document-reader```
409
+
410
+ </td>
411
+ <td>
412
+
413
+ ```javascript
414
+ {
415
+ action: "SERVICE_INITIALIZED",
416
+ data: null,
417
+ manual: false
418
+ }
419
+ ```
420
+
421
+ </td>
422
+ <td>
423
+
424
+ This event available only in ```document-reader```.
425
+
426
+ </td>
427
+ </tr>
428
+ </tbody>
429
+ </table>
430
+
431
+ ### Response
432
+
433
+ You can get the response of the component in the ```detail.data.response``` field of the event object.
434
+
435
+ For example:
436
+
437
+ ```javascript
438
+ const component = document.querySelector('document-reader');
106
439
 
107
440
  function listener(event) {
108
- if (event.detail) {
109
- const response = event.detail;
441
+ if (event.detail.action === 'PROCESS_FINISHED' && event.detail.data.status === 1) {
442
+ const response = event.detail.data.response;
110
443
  console.log(response);
111
444
  }
112
445
  }
113
446
 
114
- component.addEventListener('camera-snapshot', listener);
447
+ component.addEventListener('document-reader', listener);
115
448
  ```
116
449
 
117
- <a name="attributes"></a>
118
- ## Component attributes
450
+ ### Attributes
451
+
452
+ #### document-reader
453
+
454
+ | Attribute | Info | Data type | Default value | Values |
455
+ |:-------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------:|:------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
456
+ | **locale** | The language of the component interface. If empty, the language is selected from the browser settings, if it is not found, the system language is taken. | string | ```en``` | ```ru```, ```en```, ```de```, ```pl```, ```it```, ```hu```, ```ch```, ```sk```, ```uk```, ```fr```, ```es```, ```pt```, ```ar```, ```nl```, ```id```, ```vi```, ```ko```, ```ms```, ```ro```, ```gr```, ```tr```, ```jp```, ```cz```, ```th```, ```hi```, ```bn```, ```he```, ```fi```, ```sv```, ```da```, ```hr```, ```no``` |
457
+ | **internal-scenario** | The component document verification scenario. For more details, see the [Web components documentation](https://docs.regulaforensics.com/develop/doc-reader-sdk/web-components/getting-started#processing-scenarios). | string | ```MrzAndLocate``` | ```MrzAndLocate```, ```MrzOrLocate```, ```Mrz```, ```Locate``` |
458
+ | **multipage-processing** | Whether to allow processing of two pages in cases when the component detects an ID1-sized document. Multipage processing is not triggered for documents of other formats. If ```true```, the component asks for the second page and processes it. If ```false```, only one page/side of the document is processed regardless the document format. | boolean | ```false``` | ```true```, ```false``` |
459
+ | **start-screen** | Whether to show the start screen with two options for the document image uploading: From camera and From gallery. If ```true```, the start screen is shown. If ```false```, no start screen is shown and instead the camera of the device is turned on automatically to capture the image of the document. | boolean | ```false``` | ```true```, ```false``` |
460
+ | **multiple** | Whether to allow uploading more than one file via the file system. Can be set to ```true``` only if ```startScreen``` is ```true```. | boolean | ```true``` | ```true```, ```false``` |
461
+ | **camera-id** | Ability to select a camera. You can get the device ID using [navigator.mediaDevices.enumerateDevices()](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices). | string | ```undefined``` | ```camera id string value``` |
462
+ | **license** | To use the component on test environments, set the base64 license value to the ```license``` attribute. | string | ```undefined``` | ```base64 license value``` |
463
+ | **copyright** | Show Regula copyright footer. | boolean | ```true``` | ```true```, ```false``` |
464
+ | **object-fit** | Object-fit of the video element. | string | ```contain``` | ```cover```, ```contain``` |
465
+ | **change-camera** | Show the camera switch button. | boolean | ```false``` | ```true```, ```false``` |
466
+
467
+ #### camera-snapshot
468
+
469
+ | Attribute | Info | Data type | Default value | Values |
470
+ |:------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------:|:---------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
471
+ | **locale** | The language of the component interface. If empty, the language is selected from the browser settings, if it is not found, the system language is taken. | string | ```en``` | ```ru```, ```en```, ```de```, ```pl```, ```it```, ```hu```, ```ch```, ```sk```, ```uk```, ```fr```, ```es```, ```pt```, ```ar```, ```nl```, ```id```, ```vi```, ```ko```, ```ms```, ```ro```, ```gr```, ```tr```, ```jp```, ```cz```, ```th```, ```hi```, ```bn```, ```he```, ```fi```, ```sv```, ```da```, ```hr```, ```no``` |
472
+ | **start-screen** | Whether to show the start screen with two options for the document image uploading: From camera and From gallery. If ```true```, the start screen is shown. If ```false```, no start screen is shown and instead the camera of the device is turned on automatically to capture the image of the document. | boolean | ```false``` | ```true```, ```false``` |
473
+ | **multiple** | Whether to allow uploading more than one file via the file system. Can be set to ```true``` only if ```startScreen``` is ```true```. | boolean | ```true``` | ```true```, ```false``` |
474
+ | **camera-id** | Ability to select a camera. You can get the device ID using [navigator.mediaDevices.enumerateDevices()](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices). | string | ```undefined``` | ```camera id string value``` |
475
+ | **copyright** | Show Regula copyright footer. | boolean | ```true``` | ```true```, ```false``` |
476
+ | **object-fit** | Object-fit of the video element. | string | ```contain``` | ```cover```, ```contain``` |
477
+ | **change-camera** | Show the camera switch button. | boolean | ```false``` | ```true```, ```false``` |
478
+
479
+ ### Customization
480
+
481
+ Using CSS variables, you can change the font and the main colors of the components.
482
+
483
+ | Variable | Info | Default value |
484
+ |:-------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------------------:|
485
+ | **--font-family** | The font family of all text elements. If you change the font family, make sure to adjust the fond size so the message on the start screen would fit the frame. | ```Noto Sans, sans-serif``` |
486
+ | **--font-size** | The font size for the text elements. | ```16px``` |
487
+ | **--main-color** | Color for the graphic elements of the component. By default, the brand Regula violet is set. | ```#663399``` |
488
+ | **--hover-color** | Buttons hover color. | ```#7c45b4``` |
489
+ | **--active-color** | Buttons active color. | ```#663399``` |
490
+
491
+ For example:
492
+
493
+ CSS:
494
+
495
+ ```css
496
+ .my-custom-style {
497
+ --font-family: Arial, sans-serif;
498
+ --main-color: green;
499
+ }
500
+ ```
119
501
 
120
- <!-- ### document-reader
502
+ HTML:
121
503
 
122
- The component can work in two modes: with further processing of the result on the API and without such processing. For further processing on the API, you need to set the ```url``` attribute and set the API address to it.
504
+ ```html
505
+ <document-reader class="my-custom-style"></document-reader>
506
+ ```
507
+
508
+ ## Document reader SDK
509
+
510
+ You can use the document-reader SDK to create your own UI interface.
511
+
512
+ ### SDK integration via NPM
513
+
514
+ Install ```@regulaforensics/vp-frontend-document-components```:
515
+
516
+ ```
517
+ npm i @regulaforensics/vp-frontend-document-components
518
+ ```
519
+
520
+ Import ```DocumentReaderProcessor``` from ```@regulaforensics/vp-frontend-document-components``` into your ```.js``` file:
521
+
522
+ ```javascript
523
+ import { DocumentReaderProcessor } from '@regulaforensics/vp-frontend-document-components'; // If you use module bundler. In other cases use full path '/node_modules/@regulaforensics/vp-frontend-document-components/esm/main.js'.
524
+ ```
525
+
526
+ Add video tag to ```.html``` file then prepare and initialize ```DocumentReaderProcessor```:
527
+
528
+ ```javascript
529
+ const videoElement = document.getElementById('yourVideoElement');
530
+ const processor = new DocumentReaderProcessor(videoElement);
531
+
532
+ try {
533
+ await processor.prepare();
534
+ await processor.initialize({license: 'BASE64_LICENSE_KEY'}); // Set license object ONLY on test environments. In the production build call initialize(); without a license object.
535
+
536
+ const result = await processor.startRecognition(); // Result of the document recognition will be located here.
537
+
538
+ processor.stopRecognition();
539
+
540
+ console.log(result);
541
+ } catch (e) {
542
+ console.log(e);
543
+ }
544
+ ```
545
+
546
+ ### SDK integration via CDN
547
+
548
+ Connect the script in your ```.html``` file. CDN link: ```unpkg.com/:package@:version/:file```
549
+
550
+ For example:
551
+
552
+ ```html
553
+ <!-- Replace <VERSION> with the package version. The list of versions is available on NPM in the versions section -->
554
+ <script src="https://unpkg.com/@regulaforensics/vp-frontend-document-components@<VERSION>/dist/main.js"></script>
555
+ ```
556
+
557
+ Add video tag to ```.html``` file then prepare and initialize ```DocumentReaderProcessor```. ```DocumentReaderProcessor``` is available in the global variable ```window.Regula```:
123
558
 
124
- | Attribute | Info | Default value | Values |
125
- |:----------|:-----|:-------------:|:------:|
126
- | **locale** | the language of the component | ```en``` | ```ru```, ```en```, ```de```, ```pl```, ```it```, ```ch```, ```fr```, ```es```, ```pt```, ```ar```, ```nl```, ```vi```, ```ko```, ```ms```, ```gr```, ```tr```, ```jp```, ```cz```, ```th```, ```hi```, ```bn```, ```he```, ```fi```, ```sv``` |
127
- | **url** | API url (set this attribute if you want to process the result on the API) | ```undefined``` | ```any url``` |
128
- | **internal-scenario** | component document verification scenario | ```MrzAndLocate``` | ```MrzAndLocate```, ```MrzOrLocate```, ```Mrz```, ```Locate``` |
129
- | **external-scenario** | API document verification scenario (works if the ```url``` attribute is specified) | ```FullProcess``` | ```FullProcess```, ```MrzAndLocate```, ```MrzOrLocate```, ```Mrz```, ```Locate``` |
130
- | **multipage-processing** | checking multiple pages of a document | ```false``` | ```true```, ```false``` |
131
- | **start-screen** | displaying the start page | ```false``` | ```true```, ```false``` | -->
559
+ ```javascript
560
+ const { DocumentReaderProcessor } = window.Regula;
561
+
562
+ const videoElement = document.getElementById('yourVideoElement');
563
+ const processor = new DocumentReaderProcessor(videoElement);
564
+
565
+ try {
566
+ await processor.prepare();
567
+ await processor.initialize({license: 'BASE64_LICENSE_KEY'}); // Set license object ONLY on test environments. In the production build call initialize(); without a license object.
568
+
569
+ const result = await processor.startRecognition(); // Result of the document recognition will be located here.
570
+
571
+ processor.stopRecognition();
572
+
573
+ console.log(result);
574
+ } catch (e) {
575
+ console.log(e);
576
+ }
577
+ ```
578
+
579
+ ### Available DocumentReaderProcessor methods
580
+
581
+ #### prepare
582
+
583
+ Prepares SDK files. The method must be run before initialization:
584
+
585
+ ```javascript
586
+ await processor.prepare();
587
+ ```
588
+
589
+ #### initialize
590
+
591
+ Initializes the processor. The method must be run after preparing. Accepts an object with a base64 license. An object with a license must be installed only to work on test environments. Do not install an object with a license in production mode:
592
+
593
+ ```javascript
594
+ await processor.initialize({license: 'BASE64_LICENSE_KEY'});
595
+ ```
596
+
597
+ #### startRecognition
598
+
599
+ The method starts the video stream and starts the process of recognizing the document. Returns the result of document processing:
600
+
601
+ ```javascript
602
+ const result = await processor.startRecognition();
603
+ ```
604
+
605
+ To process multi-page documents, add the callback function to the method. The callback function takes in an object with an intermediate result of processing, a method for starting the next page and a method for completing the process:
606
+
607
+ ```javascript
608
+ /**
609
+ * @param {object} currentPage - Page data.
610
+ * @param {object} currentPage.data - Page processing result.
611
+ * @param {function} currentPage.startNextPage - The method of starting the recognition of the next page.
612
+ * @param {function} currentPage.finishRecognition - Finish the process and return the result.
613
+ */
614
+
615
+ async function pageListener(currentPage) {
616
+
617
+ setTimeout(async () => {
618
+ await currentPage.startNextPage(); // Will start recognition of the next page in 3 seconds.
619
+ }, 3000); // During this time, you can tell the user to turn the document over.
620
+ }
621
+
622
+ const result = await processor.startRecognition(pageListener);
623
+ ```
624
+
625
+ #### processImage
626
+
627
+ Processes document files. Can process ```FileList``` or ```Blob``` array:
628
+
629
+ ```javascript
630
+ const file = 'FileList or Blob array';
631
+
632
+ const result = await processor.processImage(file);
633
+ ```
634
+
635
+ #### stopRecognition
636
+
637
+ Stops the document recognition process and ends the video stream.
638
+
639
+ ```javascript
640
+ processor.stopRecognition();
641
+ ```
642
+
643
+ ### DocumentReaderProcessor settings
644
+
645
+ You can change the default settings for video streaming and document recognition. The settings must be set before the document recognition process.
646
+
647
+ #### streamParam
648
+
649
+ Sets the video stream settings:
650
+
651
+ ```javascript
652
+ processor.streamParam = {
653
+ cameraMode: 'user', // Camera facing mode. Can be 'environment' or 'user'. By default 'user'.
654
+ preferredCameraId: '', // Selecting a camera by ID. The camera ID can be obtained using navigator.mediaDevices.enumerateDevices();. Not set by default.
655
+ resolution: { // Video resolution. By default 1280x720.
656
+ width: 1280,
657
+ height: 720,
658
+ },
659
+ }
660
+ ```
661
+
662
+ #### recognizerProcessParam
663
+
664
+ Sets the settings for recognizing a document from the camera (```startRecognition``` method):
665
+
666
+ ```javascript
667
+ processor.recognizerProcessParam = {
668
+ processParam: {
669
+ returnUncroppedImage: true, // When enabled, returns input images in output. Disabled by default.
670
+ scenario: 'MrzAndLocate', // Recognition scenario. Can be 'MrzAndLocate', 'MrzOrLocate', 'Mrz', 'Locate'. By default 'MrzAndLocate'.
671
+ multipageProcessing: true, // Enables multi-page document processing mode. By default false.
672
+ timeout: 20000, // Recognition timeout in milliseconds. After this time process will be finished. By default 20000.
673
+ resultTypeOutput: [], // Types of results to return in response. By default [] - all available types.
674
+ imageQa: { // Quality checks.
675
+ expectedPass: ['dpiThreshold', 'glaresCheck'],
676
+ dpiThreshold: 130,
677
+ glaresCheck: true,
678
+ glaresCheckParams: {
679
+ imgMarginPart: 0.05,
680
+ maxGlaringPart: 0.01,
681
+ },
682
+ },
683
+ },
684
+ }
685
+ ```
686
+
687
+ #### imageProcessParam
688
+
689
+ Sets the settings for recognizing a document as a file (```processImage``` method):
690
+
691
+ ```javascript
692
+ processor.imageProcessParam = {
693
+ processParam: {
694
+ returnUncroppedImage: true, // When enabled, returns input images in output. Disabled by default.
695
+ scenario: 'MrzAndLocate', // Recognition scenario. Can be 'MrzAndLocate', 'MrzOrLocate', 'Mrz', 'Locate'. By default 'MrzAndLocate'.
696
+ resultTypeOutput: [], // Types of results to return in response. By default [] - all available types.
697
+ },
698
+ }
699
+ ```
700
+
701
+ #### recognizeListener
702
+
703
+ Sets the callback function that takes in the processing result for each frame:
704
+
705
+ ```javascript
706
+ /**
707
+ * @param {object} response - The result of processing each frame.
708
+ */
709
+
710
+ function listener(response) {
711
+ console.log(response);
712
+ }
713
+
714
+ processor.recognizeListener = listener; // Not set by default.
715
+ ```
716
+
717
+ #### videoElement
718
+
719
+ Sets the video element to display the video stream from the camera. This setting will change the video element that you set when creating the instance ```new DocumentReaderProcessor(videoElement)```:
720
+
721
+ ```javascript
722
+ const videoElement = document.getElementById('HTMLVideoElement');
723
+
724
+ processor.videoElement = videoElement; // By default null.
725
+ ```
726
+
727
+ #### isPrepared
728
+
729
+ Read-only property. Returns true if the processor has been prepared.
730
+
731
+ ```javascript
732
+ processor.isPrepared; // True or false.
733
+ ```
734
+
735
+ #### isInitialized
736
+
737
+ Read-only property. Returns true if the processor has been initialized.
738
+
739
+ ```javascript
740
+ processor.isInitialized; // True or false.
741
+ ```
742
+
743
+ #### isProcessing
744
+
745
+ Read-only property. Returns true if document recognition is not completed.
746
+
747
+ ```javascript
748
+ processor.isProcessing; // True or false.
749
+ ```
132
750
 
133
- ### camera-snapshot
751
+ ## Problems
134
752
 
135
- | Attribute | Info | Default value | Values |
136
- |:----------|:-----|:-------------:|:------:|
137
- | **locale** | the language of the component | ```en``` | ```ru```, ```en```, ```de```, ```pl```, ```it```, ```ch```, ```fr```, ```es```, ```pt```, ```ar```, ```nl```, ```vi```, ```ko```, ```ms```, ```gr```, ```tr```, ```jp```, ```cz```, ```th```, ```hi```, ```bn```, ```he```, ```fi```, ```sv``` |
138
- | **start-screen** | displaying the start page | ```false``` | ```true```, ```false``` |
139
- | **multiple** | specify whether more then 1 image can be uploaded through the file system | ```true``` | ```true```, ```false``` |
753
+ UI components and SDK use the ```getUserMedia``` method to display the video stream from the camera. This feature is available only in secure contexts (HTTPS).
140
754
 
141
- <a name="examples"></a>
142
755
  ## Examples
143
756
 
144
- You can see examples of using the components [here](https://github.com/regulaforensics/document-web-components-samples).
757
+ You can see the examples of using the components on the [Samples page](https://github.com/regulaforensics/document-web-components-samples).