Skip to content

Commit 7b6fe23

Browse files
committed
Document how to bundle zbar-wasm, remove LGPL warnings
Bump the version number so that the updated README shows up in npm.
1 parent a610379 commit 7b6fe23

29 files changed

+1291
-45
lines changed

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ It offers the following features:
2020
+ Scans `<img>`, `<canvas>` and live `<video>` elements, image and video `Blob`s and `File`s and more
2121
+ Detects multiple barcodes per frame, also with different types
2222
+ Barcodes may be oriented horizontally or vertically
23-
+ Avoids the LGPL license obligation of the [`@undecaf/zbar-wasm`](https://www.npmjs.com/package/@undecaf/zbar-wasm) dependency
24-
by loading it at runtime as a library
2523
+ Outperforms pure JavaScript polyfills
2624

2725
An online example is available [on GitHub](https://undecaf.github.io/barcode-detector-polyfill/example/)
@@ -60,7 +58,7 @@ try {
6058
Expose the `BarcodeDetectorPolyfill` API in variable `barcodeDetectorPolyfill`:
6159

6260
```html
63-
<script src="https://cdn.jsdelivr.net/npm/@undecaf/[email protected].11/dist/index.js"></script>
61+
<script src="https://cdn.jsdelivr.net/npm/@undecaf/[email protected].12/dist/index.js"></script>
6462
<script src="https://cdn.jsdelivr.net/npm/@undecaf/[email protected]/dist/index.js"></script>
6563
<script>
6664
try {
@@ -161,21 +159,33 @@ Type definitions for `BarcodeDetectorPolyfill`, for constructor and method param
161159
are provided in `@undecaf/barcode-detector-polyfill/dist/main.d.ts`.
162160

163161

164-
## Bundling
162+
## Build configurations
165163

166-
This package, [`@undecaf/barcode-detector-polyfill`](https://www.npmjs.com/package/@undecaf/barcode-detector-polyfill),
164+
### Bundling dependency `@undecaf/zbar-wasm`
165+
166+
[This package](https://www.npmjs.com/package/@undecaf/barcode-detector-polyfill)
167167
is under the MIT license although it depends on [`@undecaf/zbar-wasm`](https://www.npmjs.com/package/@undecaf/zbar-wasm)
168168
which is under LGPL.
169+
Nevertheless, `@undecaf/zbar-wasm` may be bundled in your project as this does not violate the [LGPL requirements](https://fossa.com/blog/open-source-software-licenses-101-lgpl-license/).
170+
171+
Module `@undecaf/zbar-wasm`, however, expects the WASM file `zbar.wasm` to be located at the same path as itself;
172+
details can be found in the [documentation of `@undecaf/zbar-wasm`](https://github.com/undecaf/zbar-wasm#bundlingdeploying-zbar-wasm).
173+
Therefore, bundlers must be configured accordingly. Configuration examples for [Rollup](https://rollupjs.org/) and [esbuild](https://esbuild.github.io/)
174+
can be found in directory [`example-bundled`](https://github.com/undecaf/barcode-detector-polyfill/tree/master/example-bundled).
175+
They were used to bundle the JavaScript code for this [online example](https://undecaf.github.io/barcode-detector-polyfill/example-bundled/)
176+
in [`docs/example-bundled`](https://github.com/undecaf/barcode-detector-polyfill/tree/master/docs/example-bundled).
177+
178+
### Loading dependency `@undecaf/zbar-wasm` at runtime
169179

170-
In order to comply with the LGPL, `@undecaf/zbar-wasm` must not be bundled but may only be loaded as a library at runtime.
171-
It will be loaded from `https://cdn.jsdelivr.net` by default, but it can also be fetched from
180+
~~In order to comply with the LGPL, `@undecaf/zbar-wasm` must not be bundled but may only be loaded as a library at runtime.~~
181+
`@undecaf/zbar-wasm` can also be loaded at runtime, by default from `https://cdn.jsdelivr.net`. It can also be fetched from
172182
a different endpoint if desired.
173183

174184
Bundlers must be configured so that they treat `@undecaf/zbar-wasm` as an external dependency instead of trying to resolve it.
175-
Sample build configurations for [Rollup](https://rollupjs.org/) and [esbuild](https://esbuild.github.io/)
176-
can be found in the [`example`](https://github.com/undecaf/barcode-detector-polyfill/tree/master/example) directory.
177-
They were used to bundle the JavaScript code for the [online example](https://undecaf.github.io/barcode-detector-polyfill/example/)
178-
in [`docs/example`](https://github.com/undecaf/barcode-detector-polyfill/tree/master/docs/example).
185+
Configuration examples for [Rollup](https://rollupjs.org/) and [esbuild](https://esbuild.github.io/)
186+
can be found in directory [`example-loaded`](https://github.com/undecaf/barcode-detector-polyfill/tree/master/example-loaded).
187+
They were used to bundle the JavaScript code for this [online example](https://undecaf.github.io/barcode-detector-polyfill/example-loaded/)
188+
in [`docs/example-loaded`](https://github.com/undecaf/barcode-detector-polyfill/tree/master/docs/example-loaded).
179189
They also illustrate how to load `@undecaf/zbar-wasm` from a non-default endpoint.
180190

181191

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

docs/example/index.html renamed to docs/example-bundled/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
<body>
2020
<div class="container">
21-
<h4><code>BarcodeDetector</code> polyfill example</h4>
21+
<h4>
22+
<code>BarcodeDetector</code> polyfill example,
23+
<a href="https://www.npmjs.com/package/@undecaf/zbar-wasm"><code>zbar-wasm</code></a> bundled
24+
</h4>
2225

2326
<div>Supported formats: <pre id="formats"></pre></p>
2427

@@ -55,4 +58,4 @@ <h5>Result</h5>
5558
<pre id="result"></pre>
5659
</div>
5760
</body>
58-
</html>
61+
</html>

docs/example-bundled/js/main.js

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/example-bundled/js/zbar.wasm

233 KB
Binary file not shown.

docs/example-loaded/css/main.css

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
.container {
2+
margin-top: 1em;
3+
}
4+
5+
h5, p {
6+
margin-top: 0.5em;
7+
}
8+
9+
label {
10+
display: inline-block;
11+
}
12+
13+
.viewport {
14+
display: inline-block;
15+
position: relative;
16+
}
17+
18+
img, video, #note {
19+
display: none;
20+
max-width: 100%;
21+
}
22+
23+
#imgUrl {
24+
width: 25em;
25+
max-width: 100%;
26+
}
27+
28+
#imgUrl.active {
29+
color: #ffffff;
30+
background-color: #33C3F0;
31+
}
32+
33+
#imgUrl.active ~ .viewport > #img,
34+
#imgUrl.active ~ #note,
35+
#imgBtn.button-primary ~ .viewport > #img,
36+
#videoBtn.button-primary ~ .viewport > #video {
37+
display: block;
38+
}
39+
40+
#canvas {
41+
position: absolute;
42+
left: 0;
43+
top: 0;
44+
width: 100%;
45+
height: 100%;
46+
}
47+
48+
#encoding {
49+
margin-right: 1em;
50+
}
51+
52+
pre {
53+
font-size: 1.35rem;
54+
white-space: pre-wrap;
55+
word-wrap: break-word;
56+
}

0 commit comments

Comments
 (0)