@regulaforensics/document-reader 8.2.204-beta → 8.3.246-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 (65) hide show
  1. package/README.md +2 -3
  2. package/RNDocumentReader.podspec +2 -2
  3. package/android/build.gradle +2 -2
  4. package/android/cordova.gradle +2 -2
  5. package/android/src/main/java/com/regula/plugin/documentreader/Config.kt +3 -1
  6. package/examples/capacitor/README.md +10 -0
  7. package/examples/capacitor/index.html +2 -7
  8. package/examples/capacitor/index.tsx +39 -0
  9. package/examples/capacitor/package.json +3 -3
  10. package/examples/capacitor/scripts/setup.sh +4 -0
  11. package/examples/capacitor/src/extra/bt_device.tsx +8 -7
  12. package/examples/capacitor/src/extra/custom_rfid.tsx +8 -8
  13. package/examples/capacitor/src/main.css +4 -1
  14. package/examples/capacitor/src/main.html +1 -4
  15. package/examples/capacitor/src/main.tsx +58 -94
  16. package/examples/ionic/README.md +10 -0
  17. package/examples/ionic/config.xml +2 -0
  18. package/examples/ionic/index.tsx +54 -0
  19. package/examples/ionic/package.json +3 -3
  20. package/examples/ionic/src/extra/{bt_device.ts → bt_device.tsx} +8 -7
  21. package/examples/ionic/src/extra/{custom_rfid.ts → custom_rfid.tsx} +8 -8
  22. package/examples/ionic/src/main.css +4 -1
  23. package/examples/ionic/src/main.html +1 -4
  24. package/examples/ionic/src/main.tsx +171 -0
  25. package/examples/ionic/tsconfig.json +3 -2
  26. package/examples/react_native/README.md +10 -0
  27. package/examples/react_native/index.tsx +28 -5
  28. package/examples/react_native/package-lock.json +476 -421
  29. package/examples/react_native/package.json +10 -10
  30. package/examples/react_native/src/extra/bt_device.tsx +8 -8
  31. package/examples/react_native/src/extra/custom_rfid.tsx +8 -9
  32. package/examples/react_native/src/main.css +4 -1
  33. package/examples/react_native/src/main.html +1 -4
  34. package/examples/react_native/src/main.tsx +59 -84
  35. package/ios/RGLWConfig.m +2 -0
  36. package/package.json +1 -1
  37. package/plugin.xml +2 -2
  38. package/www/capacitor/index.js +16 -16
  39. package/www/capacitor/params/process_params/ProcessParams.js +7 -0
  40. package/www/cordova.js +23 -16
  41. package/www/react-native/index.js +16 -16
  42. package/www/react-native/params/process_params/ProcessParams.js +7 -0
  43. package/www/types/index.d.ts +8 -8
  44. package/www/types/params/process_params/ProcessParams.d.ts +4 -0
  45. package/examples/cordova/.vscode/launch.json +0 -28
  46. package/examples/cordova/.vscode/typings/cordova/cordova.d.ts +0 -80
  47. package/examples/cordova/README.md +0 -12
  48. package/examples/cordova/config.xml +0 -30
  49. package/examples/cordova/package-lock.json +0 -1314
  50. package/examples/cordova/package.json +0 -32
  51. package/examples/cordova/scripts/android.sh +0 -8
  52. package/examples/cordova/scripts/ios.sh +0 -8
  53. package/examples/cordova/scripts/setup.sh +0 -8
  54. package/examples/cordova/www/images/document.png +0 -0
  55. package/examples/cordova/www/images/logo.png +0 -0
  56. package/examples/cordova/www/images/portrait.png +0 -0
  57. package/examples/cordova/www/index.html +0 -6
  58. package/examples/cordova/www/index.js +0 -40
  59. package/examples/cordova/www/src/extra/bt_device.js +0 -31
  60. package/examples/cordova/www/src/extra/custom_rfid.js +0 -60
  61. package/examples/cordova/www/src/main.css +0 -131
  62. package/examples/cordova/www/src/main.html +0 -41
  63. package/examples/cordova/www/src/main.js +0 -202
  64. package/examples/ionic/index.ts +0 -16
  65. package/examples/ionic/src/main.ts +0 -213
@@ -1,26 +1,27 @@
1
1
  import { DocumentReader, InitConfig } from "@regulaforensics/document-reader"
2
- import { handleException, setStatus } from "../main"
2
+ import { handleException, init, setStatus } from "../main"
3
3
 
4
4
  export const useBtDevice = false
5
- const btDeviceName = "Regula 0000"
5
+ export const btDeviceName = "Regula 0000"
6
6
 
7
7
  export function setupBTDevice() {
8
- document.getElementById("bt-device").style.display = "flex"
9
- document.getElementById("connect").onclick = () => connect()
8
+ var connectButton = document.getElementById("connect")!
9
+ connectButton.style.display = "flex"
10
+ connectButton.onclick = () => connect()
10
11
  setStatus("Connect to a bluetooth device")
11
12
  }
12
13
 
13
14
  async function connect() {
14
15
  setStatus("Searching for devices...")
15
16
  if (await DocumentReader.instance.connectBluetoothDevice(btDeviceName)) {
16
- await initialize()
17
+ await init()
17
18
  DocumentReader.instance.functionality.useAuthenticator = true
18
- document.getElementById("bt-device").style.display = "none"
19
+ document.getElementById("bt-device")!.style.display = "none"
19
20
  } else
20
21
  setStatus("Failed to connect")
21
22
  }
22
23
 
23
- async function initialize() {
24
+ export async function initializeWithBTDevice() {
24
25
  setStatus("Initializing...")
25
26
 
26
27
  var initConfig = InitConfig.withBleDevice()
@@ -28,7 +28,7 @@ function setup() {
28
28
  setProgress(-1)
29
29
  currentProgress = -1
30
30
  setShowing(true)
31
- document.getElementById("cancel-rfid").onclick = () => stop()
31
+ document.getElementById("cancel-rfid")!.onclick = () => stop()
32
32
  }
33
33
 
34
34
  function stop() {
@@ -37,13 +37,13 @@ function stop() {
37
37
  setShowing(false)
38
38
  }
39
39
 
40
- function setDescription(data) {
41
- document.getElementById("rfid-description").innerHTML = data
40
+ function setDescription(data: string) {
41
+ document.getElementById("rfid-description")!.innerHTML = data
42
42
  }
43
43
 
44
44
  var currentProgress = -1
45
- function setProgress(next) {
46
- var progress = document.getElementById("progress")
45
+ function setProgress(next: number) {
46
+ var progress = document.getElementById("progress")!
47
47
  // make progress bar look better
48
48
  if (next == 0) return // ignore idle 0s, leave progress at 100 while its not moving
49
49
  if (next < currentProgress) next = 0 // move to 0 if progress finaly started moving
@@ -55,7 +55,7 @@ function setProgress(next) {
55
55
  currentProgress = next
56
56
  }
57
57
 
58
- function setShowing(data) {
59
- document.getElementById("main").style.display = data ? "none" : "flex"
60
- document.getElementById("custom-rfid").style.display = data ? "flex" : "none"
58
+ function setShowing(data: boolean) {
59
+ document.getElementById("main")!.style.display = data ? "none" : "flex"
60
+ document.getElementById("custom-rfid")!.style.display = data ? "flex" : "none"
61
61
  }
@@ -1,8 +1,10 @@
1
1
  html,
2
2
  body {
3
- width: 99%;
3
+ margin: 0;
4
+ width: 100%;
4
5
  height: 99vh;
5
6
  display: flex;
7
+ overflow: hidden;
6
8
  flex-direction: column;
7
9
  }
8
10
 
@@ -59,6 +61,7 @@ body {
59
61
  color: white;
60
62
  border: none;
61
63
  padding: 10px 20px;
64
+ justify-content: center;
62
65
  font-size: 16px;
63
66
  border-radius: 100px;
64
67
  cursor: pointer;
@@ -14,10 +14,6 @@
14
14
  <img id="document-image" src="images/document.png" height="160px" width="200px">
15
15
  </div>
16
16
  </div>
17
- <div id="bt-device" class="row" style="display: none;">
18
- <input type="text" placeholder="Regula 0000" />
19
- <button id="connect" class="button">Connect</button>
20
- </div>
21
17
  <div id="scenario-container" class="column no-scroll" style="margin-top: 15px; background-color: rgba(0, 0, 0, 0.03);">
22
18
  <div id="scenarios" class="scroll"></div>
23
19
  </div>
@@ -29,6 +25,7 @@
29
25
  <button id="scan" class="button">Scan document</button>
30
26
  <button id="recognize" class="button">Scan image</button>
31
27
  </div>
28
+ <button id="connect" class="button" style="width: 360px; display: none;">Connect</button>
32
29
  <div style="padding-top: 20px;"></div>
33
30
  </div>
34
31
  <div id="custom-rfid" class="column no-scroll" style="display: none;">
@@ -0,0 +1,171 @@
1
+ import { DocumentReader, DocReaderAction, FieldType, GraphicFieldType, InitConfig, RecognizeConfig, ResultType, RFIDConfig, ScannerConfig, Scenario, Results, DocReaderException, DocReaderScenario } from '@regulaforensics/document-reader'
2
+ import { loadAsset, pickImage } from '../index'
3
+ import { initializeWithBTDevice, setupBTDevice, useBtDevice } from './extra/bt_device'
4
+ import { useRfidSelfHostedUI, rfidSelfHostedUI } from './extra/custom_rfid'
5
+
6
+ var documentReader = DocumentReader.instance
7
+ var selectedScenario = Scenario.MRZ
8
+ var doRfid = false
9
+ var isReadingRfid = false
10
+
11
+ export async function init() {
12
+ if (!await initialize()) return
13
+ setScenarios(documentReader.availableScenarios)
14
+ setCanRfid(await documentReader.isRFIDAvailableForUse())
15
+ setStatus("Ready")
16
+ }
17
+
18
+ async function scan() {
19
+ if (!await documentReader.isReady()) return
20
+ clearResults()
21
+ documentReader.startScanner(
22
+ ScannerConfig.withScenario(selectedScenario),
23
+ handleCompletion,
24
+ )
25
+ }
26
+
27
+ async function recognize() {
28
+ if (!await documentReader.isReady()) return
29
+ var image = await pickImage()
30
+ if (image == null) return
31
+
32
+ clearResults()
33
+ documentReader.recognize(
34
+ RecognizeConfig.withScenario(selectedScenario, { image: image }),
35
+ handleCompletion,
36
+ )
37
+ }
38
+
39
+ export function handleCompletion(action: DocReaderAction, results: Results | null, error: DocReaderException | null) {
40
+ handleException(error)
41
+ if (DocReaderAction.stopped(action) && !shouldRfid(results)) {
42
+ displayResults(results)
43
+ } else if (DocReaderAction.finished(action) && shouldRfid(results)) {
44
+ isReadingRfid = true
45
+ readRfid()
46
+ }
47
+ }
48
+
49
+ export async function displayResults(results: Results | null) {
50
+ isReadingRfid = false
51
+ clearResults()
52
+ if (results == null) return
53
+
54
+ var name = await results.textFieldValueByType(FieldType.SURNAME_AND_GIVEN_NAMES)
55
+ var docImage = await results.graphicFieldImageByType(GraphicFieldType.DOCUMENT_IMAGE)
56
+ var portrait = await results.graphicFieldImageByType(GraphicFieldType.PORTRAIT)
57
+ portrait = await results.graphicFieldImageByTypeSource(GraphicFieldType.PORTRAIT, ResultType.RFID_IMAGE_DATA) ?? portrait
58
+
59
+ setStatus(name)
60
+ setPortrait(portrait)
61
+ setDocImage(docImage)
62
+ }
63
+
64
+ var readRfid = () => {
65
+ documentReader.rfid(new RFIDConfig(handleCompletion))
66
+ }
67
+
68
+ function shouldRfid(results: Results | null) {
69
+ return doRfid &&
70
+ !isReadingRfid &&
71
+ results != null && results.chipPage != 0
72
+ }
73
+
74
+ var initialize = async () => {
75
+ setStatus("Initializing...")
76
+
77
+ var license = await loadAsset("regula.license")
78
+ var initConfig = new InitConfig(license)
79
+ var [success, error] = await documentReader.initialize(initConfig)
80
+
81
+ handleException(error)
82
+ return success
83
+ }
84
+
85
+ export function handleException(error: DocReaderException | null) {
86
+ if (error != null) {
87
+ setStatus(error.message)
88
+ console.log(error.code + ": " + error.message)
89
+ }
90
+ }
91
+
92
+ // --------------------------------------------------------------------------------------------------------------------
93
+
94
+ var documentUIImage: HTMLImageElement
95
+ var portraitUIImage: HTMLImageElement
96
+ export function main() {
97
+ documentUIImage = document.getElementById("document-image") as HTMLImageElement
98
+ portraitUIImage = document.getElementById("portrait-image") as HTMLImageElement
99
+ document.getElementById("scan")!.onclick = () => scan()
100
+ document.getElementById("recognize")!.onclick = () => recognize()
101
+
102
+ // custom rfid
103
+ if (useRfidSelfHostedUI) readRfid = () => rfidSelfHostedUI()
104
+
105
+ // bt device
106
+ if (!useBtDevice) init()
107
+ else {
108
+ setupBTDevice()
109
+ initialize = initializeWithBTDevice
110
+ }
111
+ }
112
+
113
+ export function setStatus(data: string | null) {
114
+ if (data != null)
115
+ document.getElementById("status")!.innerHTML = data
116
+ }
117
+
118
+ function setPortrait(data: string | null) {
119
+ if (data != null)
120
+ portraitUIImage.src = "data:image/png;base64," + data
121
+ }
122
+
123
+ function setDocImage(data: string | null) {
124
+ if (data != null)
125
+ documentUIImage.src = "data:image/png;base64," + data
126
+ }
127
+
128
+ function clearResults() {
129
+ setStatus("Ready")
130
+ portraitUIImage.src = "images/portrait.png"
131
+ documentUIImage.src = "images/document.png"
132
+ }
133
+
134
+ function setCanRfid(data: boolean) {
135
+ var checkbox = document.getElementById('rfid-checkbox') as HTMLInputElement
136
+ var checkboxDescription = document.getElementById("rfid-checkbox-description")!
137
+ if (data) {
138
+ checkbox.disabled = false
139
+ checkboxDescription.innerHTML = "Process rfid reading"
140
+ var onclick = () => {
141
+ doRfid = !doRfid
142
+ checkbox.checked = doRfid
143
+ }
144
+ checkbox.onclick = onclick
145
+ checkboxDescription.onclick = onclick
146
+ }
147
+ }
148
+
149
+ function setScenarios(data: DocReaderScenario[]) {
150
+ var scenariosContainer = document.getElementById("scenarios")!
151
+
152
+ data.forEach(scenario => {
153
+ var checked = selectedScenario == scenario.name ? "checked" : ""
154
+ var scenarioElement = `<div class="row radio">
155
+ <input type="radio" name="scenario" id="${scenario.name}" value="${scenario.name}" ${checked}>
156
+ <span id="${scenario.name}-caption" style="width: 200px; padding-left: 5px;">${scenario.caption}</span>
157
+ </div>`
158
+ scenariosContainer.insertAdjacentHTML("beforeend", scenarioElement)
159
+ })
160
+
161
+ data.forEach(scenario => {
162
+ var element = document.getElementById(scenario.name) as HTMLInputElement
163
+ var elementCaption = document.getElementById(scenario.name + "-caption")!
164
+ var onclick = () => {
165
+ selectedScenario = scenario.name as Scenario
166
+ element.checked = true
167
+ }
168
+ element.onclick = onclick
169
+ elementCaption.onclick = onclick
170
+ })
171
+ }
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "include": [
3
- "*.ts"
3
+ "*.tsx"
4
4
  ],
5
5
  "compilerOptions": {
6
6
  "types": [],
7
7
  "module": "esnext",
8
8
  "moduleResolution": "node",
9
9
  "experimentalDecorators": true,
10
- "target": "es2022"
10
+ "target": "es2022",
11
+ "jsx": "react-jsx"
11
12
  }
12
13
  }
@@ -10,3 +10,13 @@
10
10
  * Android: `npm run android`.
11
11
 
12
12
  **Note**: this is just one way of running the app. You can also pass `-o` or `--open` argument to the command, and this will open Xcode/Android Studio, then run the app directly from the IDE. Overall, this is a more consistent way, so if you're having troubles running the app from terminal, try running it from the IDE. Just don't forget to make sure that Metro Bundler is running(`npm start`).
13
+
14
+ ## Additional examples
15
+
16
+ ### Bluetooth device
17
+
18
+ In order to connect to an external scanning device, change the `useBtDevice` constant to true in `src/extra/bt_device`, and set `btDeviceName` to the name of you device. After running the app, click `Connect`.
19
+
20
+ ### RFID self hosted UI
21
+
22
+ This app also demonstraits how you can implement you own UI for the RFID reading process. To enable it, change the `useRfidSelfHostedUI` constant to true in `src/extra/custom_rfid`. Run the app and initiate RFID reading.
@@ -1,19 +1,22 @@
1
1
  import { registerRootComponent } from 'expo'
2
2
  import WebView from 'react-native-webview'
3
3
  import React from 'react'
4
- import { onload } from './src/main'
4
+ import * as RNFS from 'react-native-fs'
5
+ import { Platform } from 'react-native'
6
+ import { launchImageLibrary } from 'react-native-image-picker'
7
+ import { main } from './src/main'
5
8
 
6
9
  var webViewRef: any
7
10
  const onclicks: any = {}
8
11
  const onMessage = (json: any) => {
9
12
  const event = JSON.parse(json.nativeEvent.data)
10
- if (event.id === "ready") onload()
13
+ if (event.id === "ready") main()
11
14
  if (event.id === "onclick") {
12
15
  onclicks[event.value]()
13
16
  }
14
17
  }
15
18
 
16
- export const document = {
19
+ const document = {
17
20
  getElementById(id: string): any {
18
21
  return new Proxy({}, {
19
22
  set(_, prop: string, value) {
@@ -35,8 +38,12 @@ export const document = {
35
38
  return true
36
39
  }
37
40
  })
41
+ if (prop === "insertAdjacentHTML") return (position: string, html: string) => {
42
+ webViewRef.injectJavaScript(`document.getElementById("${id}").insertAdjacentHTML('${position}', \`${html}\`); true`)
43
+ return true
44
+ }
38
45
  return undefined
39
- },
46
+ }
40
47
  }
41
48
  )
42
49
  }
@@ -47,12 +54,28 @@ function parseValue(value: any) {
47
54
  return value
48
55
  }
49
56
 
57
+ (globalThis as any).document = document;
50
58
  registerRootComponent(() =>
51
59
  <WebView
52
60
  ref={ref => { webViewRef = ref }}
53
61
  onMessage={onMessage}
54
62
  source={require("./index.html")}
55
63
  scrollEnabled={false}
56
- injectedJavaScript="document.body.addEventListener('touchmove', function(e) { e.preventDefault() }, { passive: false })"
64
+ overScrollMode={'content'}
57
65
  />
58
66
  )
67
+
68
+ export async function loadAsset(path: string): Promise<string> {
69
+ if (Platform.OS === 'ios') path = RNFS.MainBundlePath + "/" + path
70
+ var readFile = Platform.OS === 'ios' ? RNFS.readFile : RNFS.readFileRes
71
+ return await readFile(path, 'base64')
72
+ }
73
+
74
+ export async function pickImage(): Promise<string | null> {
75
+ var response = await launchImageLibrary({
76
+ mediaType: 'photo',
77
+ selectionLimit: 1,
78
+ includeBase64: true
79
+ })
80
+ return response?.assets?.[0].base64!
81
+ }