Skip to content

Commit 0539f2a

Browse files
authored
fix/web code snippets, update samples urls, better parser cdn doc (#259)
* better docs for parser web * fix web samples links, add stackblitz link * fix code snippets * Fix code snippet and "alternative" repetition
1 parent 3be880f commit 0539f2a

File tree

5 files changed

+369
-358
lines changed

5 files changed

+369
-358
lines changed

docs/sdks/web/add-sdk.md

Lines changed: 110 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ You can consume the Scandit Data Capture SDK Web packages in two ways:
1717
- as an external resource from a CDN in HTML
1818
- as package dependency via npm.
1919

20+
## Prerequisites
21+
22+
Before you begin, make sure you have the following prerequisites in place:
23+
24+
- The latest stable version of Node.js and npm (required only if including and building the SDK as part of an app, instead of just including it as an external resource from a CDN in HTML).
25+
- Valid Scandit Data Capture SDK license, sign up for a [free trial](https://www.scandit.com/trial/) if you don't already have a license key
26+
27+
For detailed information about system requirements, see [System Requirements](/system-requirements/#web-sdk).
28+
29+
:::warning
30+
Devices running the Scandit Data Capture SDK need to have a GPU and run a browser capable of making it available (requires [WebGL - current support?](https://caniuse.com/#feat=webgl) and [OffscreenCanvas - current support?](https://caniuse.com/#feat=offscreencanvas)) or the performance will drastically decrease.
31+
:::
32+
33+
## Package Information
34+
2035
Scandit Data Capture SDKs [npm packages](https://www.npmjs.com/search?q=@scandit) are distributed under `@scandit/` scope.
2136

2237
You need to add the `@scandit/web-datacapture-core` package, which contains the shared functionality used by the other data capture packages.
@@ -25,25 +40,86 @@ If you're using `barcodecapture`-related functionalities,
2540
make sure to also add the:
2641

2742
- `@scandit/web-datacapture-barcode` package, and/or
28-
- `@scandit/web-datacapture-parser`
43+
- `@scandit/web-datacapture-parser` package
44+
45+
`@scandit/web-datacapture-parser` package needs `@scandit/web-datacapture-barcode` as dependency.
46+
See the [Parser documentation](/sdks/web/parser/get-started.md) to learn more.
2947

30-
In addition, you need to add `@scandit/web-datacapture-id` if you want to scan personal identification documents, such as identity cards, passports or visas. See the [ID Capture documentation](/sdks/web/id-capture/get-started.md) to learn more.
48+
If you want to scan personal identification documents, such as identity cards, passports or visas you need to add `@scandit/web-datacapture-id`.
49+
See the [ID Capture documentation](/sdks/web/id-capture/get-started.md) to learn more.
3150

3251
:::tip
3352
You can safely remove _barcode_ or _id_ dependencies if you are not going to use their features.
3453
:::
3554

36-
## Prerequisites
55+
## Install via package manager
3756

38-
Before you begin, make sure you have the following prerequisites in place:
57+
To add the packages via your preferred package manager, run the following command from your project's root folder:
3958

40-
- The latest stable version of Node.js and npm (required only if including and building the SDK as part of an app, instead of just including it as an external resource from a CDN in HTML).
41-
- Valid Scandit Data Capture SDK license, sign up for a [free trial](https://www.scandit.com/trial/) if you don't already have a license key
59+
<Tabs groupId="packageManager">
4260

43-
:::warning
44-
Devices running the Scandit Data Capture SDK need to have a GPU and run a browser capable of making it available (requires [WebGL - current support?](https://caniuse.com/#feat=webgl) and [OffscreenCanvas - current support?](https://caniuse.com/#feat=offscreencanvas)) or the performance will drastically decrease.
61+
<TabItem value="npm" label="npm">
62+
63+
```sh
64+
npm install --save @scandit/web-datacapture-core @scandit/web-datacapture-barcode
65+
```
66+
67+
</TabItem>
68+
69+
<TabItem value="yarn" label="yarn">
70+
71+
```sh
72+
yarn add @scandit/web-datacapture-core @scandit/web-datacapture-barcode
73+
```
74+
75+
</TabItem>
76+
77+
<TabItem value="pnpm" label="pnpm">
78+
79+
```sh
80+
pnpm add @scandit/web-datacapture-core @scandit/web-datacapture-barcode
81+
```
82+
83+
</TabItem>
84+
85+
<TabItem value="bun" label="bun">
86+
87+
```sh
88+
bun add @scandit/web-datacapture-core @scandit/web-datacapture-barcode
89+
```
90+
91+
</TabItem>
92+
93+
<TabItem value="deno" label="deno">
94+
95+
```sh
96+
deno add npm:@scandit/web-datacapture-core npm:@scandit/web-datacapture-barcode
97+
```
98+
99+
</TabItem>
100+
101+
</Tabs>
102+
103+
:::note
104+
You can also specify a version @`<version>`.
45105
:::
46106

107+
Then import the package in your JavaScript/TypeScript code by using:
108+
109+
```js
110+
// Importing only the necessary items is recommended to allow bundler to optimize the code through tree-shaking
111+
import {
112+
DataCaptureContext,
113+
Camera,
114+
} from "@scandit/web-datacapture-core";
115+
import {
116+
BarcodeCapture,
117+
barcodeCaptureLoader,
118+
} from "@scandit/web-datacapture-barcode";
119+
120+
// Insert your code here
121+
```
122+
47123
## Install via CDN
48124

49125
:::warning Important considerations when using CDNs
@@ -64,75 +140,17 @@ For production environments, we recommend:
64140
- Enterprise-grade support
65141
:::
66142

67-
You can use the [jsDelivr](https://jsdelivr.com/) or [UNPKG](https://unpkg.com/) CDN to specify a certain version (or range) and include and import from our library as follows. This example imports the core and barcode capture packages:
68-
69-
```html
70-
<!--
71-
You can optionally preload the modules.
72-
More info about this feature here https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/modulepreload
73-
-->
74-
<link
75-
rel="modulepreload"
76-
href="https://cdn.jsdelivr.net/npm/@scandit/[email protected]/build/js/index.js"
77-
/>
78-
<link
79-
rel="modulepreload"
80-
href="https://cdn.jsdelivr.net/npm/@scandit/[email protected]/build/js/index.js"
81-
/>
82-
<!-- polyfill browsers not supporting import maps. use the latest version from here https://github.com/guybedford/es-module-shims/releases -->
83-
<script
84-
async
85-
src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js"
86-
></script>
87-
<script type="importmap">
88-
{
89-
"imports": {
90-
"@scandit/web-datacapture-core": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/build/js/index.js",
91-
"@scandit/web-datacapture-barcode": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/build/js/index.js",
92-
"@scandit/web-datacapture-barcode/": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/",
93-
"@scandit/web-datacapture-core/": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/"
94-
}
95-
}
96-
</script>
97-
98-
<script type="module">
99-
// Importing only the necessary items is recommended
100-
import {
101-
DataCaptureContext,
102-
Camera,
103-
} from "@scandit/web-datacapture-core";
104-
import {
105-
BarcodeCapture,
106-
barcodeCaptureLoader,
107-
} from "@scandit/web-datacapture-barcode";
108-
109-
// Insert your code here
110-
</script>
111-
OR
112-
<script type="module">
113-
// OR import everything. Not recommended.
114-
import * as SDCCore from "@scandit/web-datacapture-core";
115-
import * as SDCBarcode from "@scandit/web-datacapture-barcode";
116-
117-
// Insert your code here
118-
</script>
119-
```
143+
You can use the [jsDelivr](https://jsdelivr.com/) or [UNPKG](https://unpkg.com/) CDN to specify a certain version (or range) and include and import from our library as follows.
120144

121145
:::note
122-
In alternative to jsdeliver unpkg can be used as alternative:
146+
In alternative to jsdeliver, unpkg can be used:
123147

124148
- [UNPKG Core](https://unpkg.com/@scandit/[email protected])
125149
- [UNPKG Barcode](https://unpkg.com/@scandit/[email protected])
126150

127151
:::
128152

129-
Alternatively, you can also put the same JavaScript/TypeScript code in a separate file via:
130-
131-
```html
132-
<script type="module" src="script.js"></script>
133-
```
134-
135-
### Complete Example
153+
### Complete CDN Example
136154

137155
```html
138156
<!DOCTYPE html>
@@ -146,12 +164,18 @@ Alternatively, you can also put the same JavaScript/TypeScript code in a separat
146164
"imports": {
147165
"@scandit/web-datacapture-core": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/build/js/index.js",
148166
"@scandit/web-datacapture-barcode": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/build/js/index.js",
167+
"@scandit/web-datacapture-parser": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/build/js/index.js",
149168
150169
"@scandit/web-datacapture-barcode/": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/",
151-
"@scandit/web-datacapture-core/": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/"
170+
"@scandit/web-datacapture-core/": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/",
171+
"@scandit/web-datacapture-parser/": "https://cdn.jsdelivr.net/npm/@scandit/[email protected]/"
152172
}
153173
}
154174
</script>
175+
<!--
176+
You can optionally preload the modules.
177+
More info about this feature here https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/modulepreload
178+
-->
155179
<link
156180
rel="modulepreload"
157181
href="https://cdn.jsdelivr.net/npm/@scandit/[email protected]/build/js/index.js"
@@ -160,6 +184,10 @@ Alternatively, you can also put the same JavaScript/TypeScript code in a separat
160184
rel="modulepreload"
161185
href="https://cdn.jsdelivr.net/npm/@scandit/[email protected]/build/js/index.js"
162186
/>
187+
<link
188+
rel="modulepreload"
189+
href="https://cdn.jsdelivr.net/npm/@scandit/[email protected]/build/js/index.js"
190+
/>
163191
<style>
164192
html,
165193
body {
@@ -238,84 +266,6 @@ Alternatively, you can also put the same JavaScript/TypeScript code in a separat
238266
</html>
239267
```
240268
241-
## Install via package manager
242-
243-
To add the packages via your preferred package manager, run the following command from your project's root folder:
244-
245-
<Tabs groupId="packageManager">
246-
247-
<TabItem value="npm" label="npm">
248-
249-
```sh
250-
npm install --save @scandit/web-datacapture-core @scandit/web-datacapture-barcode
251-
```
252-
253-
</TabItem>
254-
255-
<TabItem value="yarn" label="yarn">
256-
257-
```sh
258-
yarn add @scandit/web-datacapture-core @scandit/web-datacapture-barcode
259-
```
260-
261-
</TabItem>
262-
263-
<TabItem value="pnpm" label="pnpm">
264-
265-
```sh
266-
pnpm add @scandit/web-datacapture-core @scandit/web-datacapture-barcode
267-
```
268-
269-
</TabItem>
270-
271-
<TabItem value="bun" label="bun">
272-
273-
```sh
274-
bun add @scandit/web-datacapture-core @scandit/web-datacapture-barcode
275-
```
276-
277-
</TabItem>
278-
279-
<TabItem value="deno" label="deno">
280-
281-
```sh
282-
deno add npm:@scandit/web-datacapture-core npm:@scandit/web-datacapture-barcode
283-
```
284-
285-
</TabItem>
286-
287-
</Tabs>
288-
289-
:::note
290-
You can also specify a version @`<version>`.
291-
:::
292-
293-
Then import the package in your JavaScript/TypeScript code by using:
294-
295-
```js
296-
// Importing only the necessary items is recommended
297-
import {
298-
DataCaptureContext,
299-
Camera,
300-
} from "@scandit/web-datacapture-core";
301-
import {
302-
BarcodeCapture,
303-
barcodeCaptureLoader,
304-
} from "@scandit/web-datacapture-barcode";
305-
306-
// Insert your code here
307-
```
308-
309-
OR
310-
311-
```js
312-
// Import everything
313-
import * as SDCCore from "@scandit/web-datacapture-core";
314-
import * as SDCBarcode from "@scandit/web-datacapture-barcode";
315-
316-
// Insert your code here
317-
```
318-
319269
## Configure the Library
320270
321271
The library needs to be configured and initialized before it can be used, this is done via the DataCaptureContext [`forLicenseKey`](https://docs.scandit.com/data-capture-sdk/web/core/api/data-capture-context.html#class-scandit.datacapture.core.DataCaptureContext) function.
@@ -334,7 +284,7 @@ If you installed the library through npm, **these files should be copied and ser
334284
The configuration option that you provide should then point to the folder containing these files, either as a path of your website or an absolute URL (like the CDN one). **By default the library will look at the root of your website**.
335285
336286
:::caution Version Matching Required
337-
The npm package version and the `sdc-lib` files must be from the exact same SDK version. For example, if you have `@scandit/[email protected]` in your `package.json`, you must serve the `sdc-lib` folder from `node_modules/@scandit/[email protected]/sdc-lib/`. Mismatched versions will cause runtime errors and unexpected behavior.
287+
The npm package version and the `sdc-lib` files must be from the exact same SDK version. For example, if you have `@scandit/[email protected]` in your `package.json`, you must serve the `sdc-lib` folder from `node_modules/@scandit/[email protected]/sdc-lib/`. **Mismatched versions will cause runtime errors and unexpected behavior.**
338288
:::
339289
340290
In case a common CDN is used (jsDelivr or UNPKG) the library will automatically, internally set up the correct URLs pointing to the files needed for the matching library version.
@@ -348,7 +298,7 @@ We recommend serving the `sdc-lib` folder yourself.
348298
:::caution Important: Full Folder Copy and Version Matching
349299
You must copy the **entire `sdc-lib` folder recursively** from the installed Scandit package to your server. This includes all subdirectories and files. The `sdc-lib` folder must come from a package version that exactly matches your npm package version. For example, if you have `@scandit/[email protected]`, you must copy the `sdc-lib` from `node_modules/@scandit/[email protected]/sdc-lib/`.
350300
351-
Additionally, you should copy `sdc-lib` from all installed Scandit packages (`@scandit/web-datacapture-core`, `@scandit/web-datacapture-barcode`, `@scandit/web-datacapture-id`, etc.) to the same location.
301+
Additionally, you should copy `sdc-lib` from all installed Scandit packages (`@scandit/web-datacapture-core`, `@scandit/web-datacapture-barcode`, `@scandit/web-datacapture-id`, `@scandit/web-datacapture-parser`, etc.) to the same location.
352302
:::
353303
354304
Once copied, be sure to serve the files correctly by setting up the correct MIME type for the `.wasm`, `.model`, and `.js` files. Some common examples are provided below:
@@ -449,7 +399,7 @@ def serve_file(filename):
449399
## Show loading status with default UI
450400
451401
It could take a while the very first time to download the .wasm files.
452-
To show some feedback to the user about the loading status you have two options:
402+
To show some visual feedback to the user about the loading status you have two options:
453403
454404
- use the default UI provided with the SDK
455405
- subscribe to the loading status and update your own custom UI.
@@ -461,6 +411,7 @@ import {
461411
DataCaptureView,
462412
DataCaptureContext,
463413
} from "@scandit/web-datacapture-core";
414+
import { idCaptureLoader } from "@scandit/web-datacapture-id";
464415
465416
const view = new DataCaptureView();
466417
@@ -484,8 +435,11 @@ You can also subscribe for the [loading status](https://docs.scandit.com/data-ca
484435
by simply attaching a listener like this:
485436
486437
```ts
438+
import type { ProgressInfo } from "@scandit/web-datacapture-core";
487439
import { loadingStatus, DataCaptureContext } from "@scandit/web-datacapture-core";
488-
loadingStatus.subscribe((info) => {
440+
import { barcodeCaptureLoader } from "@scandit/web-datacapture-barcode";
441+
442+
loadingStatus.subscribe((info: ProgressInfo) => {
489443
// updateUI(info.percentage, info.loadedBytes)
490444
});
491445
@@ -511,6 +465,10 @@ For more information:
511465
- [GatsbyJS - Using client side only packages](https://www.gatsbyjs.com/docs/using-client-side-only-packages/).
512466
- [NextJS - Lazy Loading with no ssr](https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#with-no-ssr).
513467
468+
### Performance Optimization
469+
470+
For information on how to improve runtime performance, see [Improve Runtime Performance by Enabling Browser Multithreading](/sdks/web/matrixscan/get-started/#improve-runtime-performance-by-enabling-browser-multithreading).
471+
514472
### Camera Permissions
515473
516474
When using the Scandit Data Capture SDK you will likely want to set the camera as the frame source for various capture modes.

0 commit comments

Comments
 (0)