@microblink/capture 1.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.
- package/README.md +175 -0
- package/dist/capture.js +16647 -0
- package/dist/capture.umd.cjs +238 -0
- package/dist/resources/advanced/capture-wasm.data +0 -0
- package/dist/resources/advanced/capture-wasm.js +159 -0
- package/dist/resources/advanced/capture-wasm.wasm +0 -0
- package/dist/resources/advanced-threads/capture-wasm.data +0 -0
- package/dist/resources/advanced-threads/capture-wasm.js +178 -0
- package/dist/resources/advanced-threads/capture-wasm.wasm +0 -0
- package/dist/resources/advanced-threads/capture-wasm.worker.js +1 -0
- package/dist/resources/basic/capture-wasm.data +0 -0
- package/dist/resources/basic/capture-wasm.js +159 -0
- package/dist/resources/basic/capture-wasm.wasm +0 -0
- package/dist/resources/capture-worker.js +5 -0
- package/dist/style.css +1 -0
- package/package.json +62 -0
- package/types/index.d.cts +12 -0
- package/types/index.d.ts +913 -0
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# _Capture_ SDK for browsers
|
|
2
|
+
|
|
3
|
+
The Capture Browser SDK gives you the ability to auto-capture high-quality images of identity documents in a user-friendly way. The SDK provides you with a rectified image of the document, ensuring a high success rate in extracting document text or verifying the document's validity.
|
|
4
|
+
|
|
5
|
+
Users are guided to avoid glare, blurred images, bad lighting conditions, fingers over the document, or too much tilt. The SDK is able to recognize if a document is single-sided (i.e., passport) or double-sided (i.e., driving license) and prompt the user to scan the back side of the document when needed.
|
|
6
|
+
|
|
7
|
+
In the results, you can obtain a cropped, perspective-corrected image of the document, along with the original frame. These can be processed by your webapp in any way required. The SDK is lightweight and can be easily integrated into your webapp, blending seamlessly with your design.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
The Capture SDK is available as a package on NPM for use with a module bundler.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# npm
|
|
15
|
+
npm install @microblink/capture
|
|
16
|
+
|
|
17
|
+
# yarn
|
|
18
|
+
yarn add @microblink/capture
|
|
19
|
+
|
|
20
|
+
# pnpm
|
|
21
|
+
pnpm add @microblink/capture
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Obtaining a licence
|
|
25
|
+
|
|
26
|
+
A valid license key is required to initialize scanning. You can request a free trial license key after registering on [Microblink Developer Hub](https://account.microblink.com/signin). The license is bound to the application ID of your app.
|
|
27
|
+
|
|
28
|
+
## Hosting environment
|
|
29
|
+
|
|
30
|
+
In order for the SDK to work it needs to run inside a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts).
|
|
31
|
+
Additionally, to run the threaded version of the SDK, the following headers need to be set on your server:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Cross-Origin-Embedder-Policy: require-corp
|
|
35
|
+
Cross-Origin-Opener-Policy: same-origin
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Otherwise, you will only be able to run the single-threaded version of the SDK.
|
|
39
|
+
|
|
40
|
+
In order to load the accompanying Wasm files and Web Workers, you also need to host them locally on your dev server. These files can be found inside the `node_modules/@microblink/capture/dist/resources` directory after installation.
|
|
41
|
+
|
|
42
|
+
The dev environments for the example apps have these set and you can use them as a reference.
|
|
43
|
+
|
|
44
|
+
## Examples Quick Start
|
|
45
|
+
|
|
46
|
+
### Requirements
|
|
47
|
+
|
|
48
|
+
In order to run the examples provided in the [GitHub repository](), you'll need the following tools:
|
|
49
|
+
|
|
50
|
+
1. NodeJS LTS (18.x)
|
|
51
|
+
|
|
52
|
+
- Prefer using [`nvm`](https://github.com/nvm-sh/nvm) on dev machines:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
nvm install --lts
|
|
56
|
+
nvm use --lts
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- [alternative installation methods](https://nodejs.org/en/download)
|
|
60
|
+
|
|
61
|
+
2. `pnpm`
|
|
62
|
+
|
|
63
|
+
- alternative package manager to `npm`
|
|
64
|
+
- easiest to install using `npm install -g pnpm`
|
|
65
|
+
- [alternative installation methods](https://pnpm.io/installation)
|
|
66
|
+
|
|
67
|
+
### Device requirements
|
|
68
|
+
|
|
69
|
+
Additionally, your device will need a camera capable of providing a video stream with a minimum resolution of 1920x1080.
|
|
70
|
+
|
|
71
|
+
The minimum supported browser versions are Chrome 96, Firefox 79 and Safari 15.2. Web views are not supported as they are not providing a secure context.
|
|
72
|
+
|
|
73
|
+
### Running the provided examples
|
|
74
|
+
|
|
75
|
+
The examples provided in the [GitHub repository]() can be run by first building the SDK by running `pnpm build`, and then navigating to the examples found in `/apps/*` and running `pnpm dev` for the dev server or `pnpm serve` for the production build.
|
|
76
|
+
|
|
77
|
+
These examples will move the `node_modules/@microblink/capture/dist/resources` as part of the build step to [Vite's public folder](https://vitejs.dev/guide/assets.html#the-public-directory), generate a local HTTPS certificate and apply the appropriate headers to Vite's dev server.
|
|
78
|
+
|
|
79
|
+
## Using the SDK
|
|
80
|
+
|
|
81
|
+
It is strongly recommended to use TypeScript and an IDE that has a TypeScript language server during development as the SDK is strongly typed and provides JSdoc comments, links, usage examples, autocomplete, and other Intellisense features.
|
|
82
|
+
|
|
83
|
+
### Using the provided UI component with `createCaptureUi`
|
|
84
|
+
|
|
85
|
+
The simplest way to initialize the SDK and start capturing is to call `createCaptureUi` and provide it with a licence key. This will mount a full-screen capturing UI in your web app. Make sure to also load the CSS styles for the component.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { createCaptureUi } from "@microblink/capture";
|
|
89
|
+
import "@microblink/capture/style.css";
|
|
90
|
+
|
|
91
|
+
createCaptureUi({
|
|
92
|
+
sdkSettings: {
|
|
93
|
+
licenseKey: "YOUR_LICENCE",
|
|
94
|
+
callbacks: {
|
|
95
|
+
onCaptureResult: (result) => {
|
|
96
|
+
/* do something with the result */
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Headless usage with `createCaptureSdk`
|
|
104
|
+
|
|
105
|
+
You can also use the Capture SDK without the provided UI and build your own experience by using `createCaptureSdk`. All the mechanisms that the Capture UI uses are provided by the object returned by this method.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { createCaptureSdk } from "@microblink/capture";
|
|
109
|
+
|
|
110
|
+
const sdk = await createCaptureSdk({
|
|
111
|
+
licenseKey: "YOUR_LICENCE",
|
|
112
|
+
callbacks: {
|
|
113
|
+
onCaptureResult: (result) => {
|
|
114
|
+
/* do something with the result */
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
await sdk.startCameraStream(document.getElementById("videoElementId"));
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The SDK will terminate automatically if the video element is dismounted and requires no handling on the developer's end.
|
|
123
|
+
|
|
124
|
+
## Configuration
|
|
125
|
+
|
|
126
|
+
### Configuring the Capture SDK
|
|
127
|
+
|
|
128
|
+
The SDK can be configured on initialization using `createCaptureSdk(settings)` . The configuration documentation can be found on [`CaptureSdkSettings`](/packages/capture-main/src/createCaptureSdk.ts#30).
|
|
129
|
+
|
|
130
|
+
The capturing process is handled using the [`Analyzer`](/packages/capture-wasm/src/Analyzer.ts). The configuration settings for the `Analyzer` can be found on [`AnalyzerSettings`](/packages/capture-wasm/src/AnalyzerSettings.ts).
|
|
131
|
+
|
|
132
|
+
### Configuring the Capture UI
|
|
133
|
+
|
|
134
|
+
`createCaptureUi` takes a [`CreateCaptureUiSettings`](/packages/capture-ui/src/createCaptureUi.tsx#52) configuration object as a parameter with both [`CaptureSdkSettings`](/packages/capture-main/src/createCaptureSdk.ts#30) that configures the SDK behaviour, and [`UiSettings`](/packages/capture-ui/src/StoreContext.tsx#36) which configures the UI itself.
|
|
135
|
+
|
|
136
|
+
You can configure the mount point of the UI, toggle the display of the onboarding screen and help screens, the error screen and provide your own localization strings.
|
|
137
|
+
|
|
138
|
+
You can find a list of all the localization strings in [`packages/capture-ui/src/locales/en.ts`](/packages/capture-ui/src/locales/en.ts)
|
|
139
|
+
|
|
140
|
+
## Advanced usage
|
|
141
|
+
|
|
142
|
+
### State management and subscriptions
|
|
143
|
+
|
|
144
|
+
The Capture SDK tracks its internal state on the [`ReactiveStore`](/packages/capture-main/src/zustandStore.ts#8) object, which is implemented using [Zustand](https://github.com/pmndrs/zustand).
|
|
145
|
+
|
|
146
|
+
The user can get the internal state of the SDK at any time by calling `getState()` on the `CaptureSdk` object returned by `createCaptureSdk`. `CaptureSdk` is also available on the `CaptureComponent` instance returned by `createCaptureUi`.
|
|
147
|
+
|
|
148
|
+
You can also subscribe to state changes by calling `CaptureSdk.subscribe()`. Detailed documentation for using this feature is available [here](https://github.com/pmndrs/zustand#using-subscribe-with-selector).
|
|
149
|
+
|
|
150
|
+
### UI customization
|
|
151
|
+
|
|
152
|
+
The UI can be customized by either overriding the CSS variables found at `packages/capture-ui/src/root-styles.scss`, or by manually targetting the CSS classes applied to the UI component.
|
|
153
|
+
|
|
154
|
+
All components rendered by the UI are nested under `.mb-style-scope` which provides some base styles.
|
|
155
|
+
|
|
156
|
+
### Detailed capturing process information
|
|
157
|
+
|
|
158
|
+
You can find details on the internal state of the capture process using the [`onFrameAnalysis`](/packages/capture-main/src/createCaptureSdk.ts#57) callback. This callback will provide you with an `ImageData` instance of the previously processed frame and the [`FrameAnalysisResult`](/packages/capture-wasm/src/FrameAnalysisResult.ts).
|
|
159
|
+
|
|
160
|
+
## Troubleshooting
|
|
161
|
+
|
|
162
|
+
### Integration problems
|
|
163
|
+
|
|
164
|
+
If you are experiencing issues with the SDK integration, first make sure that you have followed the integration instructions and used our [provided examples as reference](#examples-quick-start).
|
|
165
|
+
Also make sure that your device meets the [requirements](#requirements). If you're still having problems, please contact us at [help.microblink.com](help.microblink.com).
|
|
166
|
+
|
|
167
|
+
### Licencing problems
|
|
168
|
+
|
|
169
|
+
If you are getting "invalid licence key" error or having other licence-related problems, first check the console. All licence-related problems are logged to error log so it is easy to determine what went wrong.
|
|
170
|
+
|
|
171
|
+
When you have determined what is the licence-related problem or you simply do not understand the log, you should contact us [help.microblink.com](help.microblink.com). When contacting us, please make sure you provide following information:
|
|
172
|
+
|
|
173
|
+
## Contact
|
|
174
|
+
|
|
175
|
+
For any other questions, feel free to contact us at [help.microblink.com](help.microblink.com).
|