@@ -23,7 +23,7 @@ of the [ZBar Bar Code Reader](https://github.com/mchehab/zbar) written in C/C++.
2323 RGB/grayscale [ ` ArrayBuffer ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer ) objects
2424+ Outperforms pure JavaScript barcode scanners
2525
26- :warning : v0 .10.0 contains breaking changes regarding bundling , please refer to section [ Bundling/deploying zbar-wasm] ( #bundlingdeploying-zbar-wasm ) .
26+ :warning : zbar-wasm version 0 .10 contains breaking changes with respect to version 0.9 , please refer to section [ Bundling/deploying zbar-wasm] ( #bundlingdeploying-zbar-wasm ) .
2727
2828
2929## Examples based on zbar-wasm
@@ -54,7 +54,7 @@ An example that scans a static image file:
5454 <pre id =" result" ></pre >
5555
5656 <script type =" module" >
57- import * as zbarWasm from ' https://cdn.jsdelivr.net/npm/@undecaf/[email protected] .0 /dist/main .js' 57+ import * as zbarWasm from ' https://cdn.jsdelivr.net/npm/@undecaf/[email protected] .1 /dist/index .js' 5858
5959 (async () => {
6060 const
@@ -88,15 +88,15 @@ Almost identical to the snippet above, just replace the lines
8888``` html
8989 ⁝
9090 <script type =" module" >
91- import * as zbarWasm from ' https://cdn.jsdelivr.net/npm/@undecaf/[email protected] .0 /dist/main .js' 91+ import * as zbarWasm from ' https://cdn.jsdelivr.net/npm/@undecaf/[email protected] .1 /dist/index .js' 9292 ⁝
9393` ` `
9494
9595with
9696
9797` ` ` html
9898 ⁝
99- < script src= " https://cdn.jsdelivr.net/npm/@undecaf/[email protected] .0 /dist/index.js" > </
script >
99+ < script src= " https://cdn.jsdelivr.net/npm/@undecaf/[email protected] .1 /dist/index.js" > </
script >
100100 <script >
101101 ⁝
102102` ` `
107107Installing:
108108
109109` ` ` shell script
110- $ npm install @undecaf/ zbar- wasm@0.10 .0
110+ $ npm install @undecaf/ zbar- wasm@0.10 .1
111111 or
112- $ yarn add @undecaf/ zbar- wasm@0.10 .0
112+ $ yarn add @undecaf/ zbar- wasm@0.10 .1
113113` ` `
114114
115115Using:
@@ -135,10 +135,9 @@ import { scanImageData } from '@undecaf/zbar-wasm';
135135
136136 const
137137 imageData = ctx .getImageData (0 , 0 , img .width , img .height ),
138- // @ts-ignore
139138 symbols = await scanImageData (imageData);
140139
141- console .log (symbols [0 ]? .typeName , symbols[0 ]? .decode ())
140+ console .log (ssymbols [0 ]? .typeName , symbols[0 ]? .decode ())
142141})(' https://raw.githubusercontent.com/undecaf/zbar-wasm/master/tests/img/qr_code.png' )
143142` ` `
144143
@@ -152,33 +151,46 @@ const { scanImageData } = require('@undecaf/zbar-wasm');
152151
153152### Bundling/deploying zbar-wasm
154153
155- zbar-wasm delegates barcode scanning to the WebAssembly code in file ` zbar .wasm ` .
156- This file is part of the package and can be provided at runtime in different ways:
154+ zbar-wasm provides ESM and CommonJS modules for Node.js and browsers. One of them needs to be
155+ bundled in your application. In any case, barcode scanning is delegated to the WebAssembly code
156+ in file ` zbar .wasm ` . At runtime, this file can be provided in different ways depending on the
157+ bundling configuration and on which zbar-wasm module was emitted by the bundler:
157158
158159+ It can be loaded from a CDN by browsers.
159160+ It can be bundled as an asset. That asset should be served to browsers as ` application/ wasm`
160161 so that it can be compiled in parallel with being received.
161- + zbar-wasm also provides modules that contain ` zbar .wasm ` as inline data.
162-
163- The [package entry points](https://nodejs.org/docs/latest-v16.x/api/packages.html#package-entry-points)
164- of zbar-wasm have been chosen so that bundlers will select the
165- appropriate module by default in most cases. ` zbar .wasm ` as inline data requires an
166- [export condition](https://nodejs.org/docs/latest-v16.x/api/packages.html#conditional-exports)
167- in the bundler configuration.
168-
169- The build process of zbar-wasm tests bundling with
170- [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/) and
171- [esbuild](https://esbuild.github.io/) and also tests the resulting bundles.
172- The bundler configuration files
162+ + Several zbar-wasm modules contain ` zbar .wasm ` as inline data.
163+
164+ This overview shows which modules are available in zbar-wasm:
165+
166+ | Path in package | Module type | Node core modules polyfilled<br>(suitable for browsers) | ` zbar .wasm ` inlined |
167+ |:--------------------------|:-----------:|:-------------------------------------------------------:|:-------------------:|
168+ | ` / dist/ index .mjs ` | ESM | :heavy_check_mark: | |
169+ | ` / dist/ index .js ` | CommonJS | :heavy_check_mark: | |
170+ | ` / dist/ main .mjs ` | ESM | | |
171+ | ` / dist/ main .cjs ` | CommonJS | | |
172+ | ` / dist/ inlined/ index .mjs ` | ESM | :heavy_check_mark: | :heavy_check_mark: |
173+ | ` / dist/ inlined/ index .js ` | CommonJS | :heavy_check_mark: | :heavy_check_mark: |
174+ | ` / dist/ inlined/ main .mjs ` | ESM | | :heavy_check_mark: |
175+ | ` / dist/ inlined/ main .cjs ` | CommonJS | | :heavy_check_mark: |
176+
177+ The [package entry points](https://nodejs.org/docs/latest-v16.x/api/packages.html#package-entry-points) of zbar-wasm have been chosen so that bundlers will emit the
178+ appropriate module by default in most cases. However, ` zbar .wasm ` as inline data requires a suitable
179+ [export condition](https://nodejs.org/docs/latest-v16.x/api/packages.html#conditional-exports) in the bundler configuration, typically ` ' zbar-inlined' ` .
180+ Please refer to the ` exports ` section of ` package .json ` for details.
181+
182+ [Building zbar-wasm](#building-zbar-wasm-from-source) runs bundling tests with [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/) and
183+ [esbuild](https://esbuild.github.io/) and also tests the resulting bundles. The bundler configuration files
173184[` tests/ {webpack,rollup,esbuild}.config .js ` ](https://github.com/undecaf/zbar-wasm/tree/master/tests)
174- may be used as a reference of how to achieve a particular bundling result. They cover the following
175- combinations of platforms, module types and ` zbar .wasm ` provisioning:
185+ may be used as a reference of how to achieve a particular bundling result. Each of them covers
186+ the following combinations of platforms, module types and ` zbar .wasm ` provisioning for the
187+ respective bundler:
176188
177- | ` zbar .wasm ` | Node.js module types | Browser module types |
178- |:------------------|:-------------------- :|:---------------------:|
179- | loaded from CDN | | ESM, plain script |
180- | bundled as asset | ESM, CommonJS | ESM |
181- | inlined in module | ESM, CommonJS | ESM, plain script |
189+ | ` zbar .wasm ` | Node module types | Browser module types |
190+ |:------------------|:-----------------:|:---------------------:|
191+ | loaded from CDN | | ESM, plain ` < script> ` |
192+ | bundled as asset | ESM, CommonJS | ESM |
193+ | inlined in module | ESM, CommonJS | ESM, plain ` < script> ` |
182194
183195
184196## API documentation
@@ -211,32 +223,34 @@ Prerequisites:
211223+ GNU ` make` , ` tar` and ` curl`
212224+ [Docker](https://www.docker.com/) or [Podman](https://podman.io/)
213225+ [Node.js](https://nodejs.org/) v16+
226+ + At least one of the [browsers supported by TestCafé](https://testcafe.io/documentation/402828/guides/intermediate-guides/browsers)
214227
215228To build:
216229
217- ` ` ` bash
218- $ git clone https: // github.com/undecaf/zbar-wasm
219- $ cd zbar- wasm
220- $ make
221- ` ` `
222-
223- The ` make` command runs [emscripten](https://emscripten.org/) in a container, compiling the C/C++
224- sources of the [ZBar Bar Code Reader](https://github.com/mchehab/zbar)
225- to [WebAssembly](https://webassembly.org/). It also compiles and bundles the TypeScript glue code
226- and runs the tests in Node.js on the host machine.
227-
228- If you prefer [Podman](https://podman.io/) as container engine then the provided ` Makefile` needs
229- to be edited before running ` make` : replace the line
230-
231- ` ` `
232- EM_ENGINE = $ (EM_DOCKER )
233- ` ` `
234-
235- with
236-
237- ` ` `
238- EM_ENGINE = $ (EM_PODMAN )
239- ` ` `
230+ - Clone this repository:
231+ ` ` ` bash
232+ $ git clone https: // github.com/undecaf/zbar-wasm
233+ $ cd zbar- wasm
234+ ` ` `
235+ - Enter your browser(s) in ` .testcaferc .json ` ([supported browsers](https://testcafe.io/documentation/402828/guides/intermediate-guides/browsers)).
236+ - Enter two available port numbers in ` tests/ src/ ports .js ` .
237+ - If you prefer [Podman](https://podman.io/) as container engine then replace
238+ ` ` `
239+ EM_ENGINE = $ (EM_DOCKER )
240+ ` ` `
241+ with
242+ ` ` `
243+ EM_ENGINE = $ (EM_PODMAN )
244+ ` ` `
245+ in the provided ` Makefile` .
246+ - Run the build process:
247+ ` ` ` bash
248+ $ make
249+ ` ` `
250+ The ` make` command runs [emscripten](https://emscripten.org/) in a container, compiling the C/C++
251+ sources of the [ZBar Bar Code Reader](https://github.com/mchehab/zbar)
252+ to [WebAssembly](https://webassembly.org/). It also compiles and bundles the TypeScript glue code
253+ and runs the tests in Node.js and in the selected browser(s) on the host machine.
240254
241255
242256## Credits to ...
0 commit comments