Skip to content

Commit 93ef376

Browse files
committed
Fix #17: isImageBitmapSource() fails in web workers
1 parent 463cfa6 commit 93ef376

File tree

8 files changed

+27
-27
lines changed

8 files changed

+27
-27
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Expose the `BarcodeDetectorPolyfill` API in variable `barcodeDetectorPolyfill`:
5959

6060
```html
6161
<script src="https://cdn.jsdelivr.net/npm/@undecaf/[email protected]/dist/index.js"></script>
62-
<script src="https://cdn.jsdelivr.net/npm/@undecaf/[email protected].20/dist/index.js"></script>
62+
<script src="https://cdn.jsdelivr.net/npm/@undecaf/[email protected].21/dist/index.js"></script>
6363
<script>
6464
try {
6565
window['BarcodeDetector'].getSupportedFormats()

docs/example-bundled/js/main.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/example-loaded/js/main.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example-bundled/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@undecaf/barcode-detector-polyfill-example",
3-
"version": "0.9.19",
3+
"version": "0.9.21",
44
"type": "module",
55
"scripts": {
66
"build:esbuild": "node esbuild.config.js",
@@ -9,7 +9,7 @@
99
"author": "F. Kasper <[email protected]>",
1010
"license": "MIT",
1111
"dependencies": {
12-
"@undecaf/barcode-detector-polyfill": "^0.9.20",
12+
"@undecaf/barcode-detector-polyfill": "^0.9.21",
1313
"@undecaf/zbar-wasm": "^0.9.15"
1414
},
1515
"devDependencies": {

example-loaded/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@undecaf/barcode-detector-polyfill-example",
3-
"version": "0.9.19",
3+
"version": "0.9.21",
44
"type": "module",
55
"scripts": {
66
"build:esbuild": "node esbuild.config.js",
@@ -9,7 +9,7 @@
99
"author": "F. Kasper <[email protected]>",
1010
"license": "MIT",
1111
"dependencies": {
12-
"@undecaf/barcode-detector-polyfill": "^0.9.20"
12+
"@undecaf/barcode-detector-polyfill": "^0.9.21"
1313
},
1414
"devDependencies": {
1515
"@rollup/plugin-node-resolve": "^13.1.1",

package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@undecaf/barcode-detector-polyfill",
3-
"version": "0.9.20",
3+
"version": "0.9.21",
44
"description": "A WebAssembly polyfill for the Barcode Detection API",
55
"keywords": [
66
"polyfill",

src/BarcodeDetectorPolyfill.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@ export class BarcodeDetectorPolyfill {
230230
* object having zero width or height.
231231
*/
232232
private static isImageBitmapSource(source: any): source is ImageBitmapSource {
233-
return (source instanceof HTMLImageElement)
234-
|| (source instanceof HTMLVideoElement)
235-
|| (source instanceof HTMLCanvasElement)
236-
|| (source instanceof Blob)
233+
return (typeof HTMLImageElement !== 'undefined' && source instanceof HTMLImageElement)
234+
|| (typeof HTMLVideoElement !== 'undefined' && source instanceof HTMLVideoElement)
235+
|| (typeof HTMLCanvasElement !== 'undefined' && source instanceof HTMLCanvasElement)
236+
|| (typeof CanvasRenderingContext2D !== 'undefined' && source instanceof CanvasRenderingContext2D)
237+
|| (typeof ImageBitmap !== 'undefined' && source instanceof ImageBitmap)
237238
|| (source instanceof ImageData)
238-
|| (source instanceof CanvasRenderingContext2D)
239-
|| (source instanceof ImageBitmap)
239+
|| (source instanceof Blob)
240240
// Note the (lenient) equality operator
241241
|| (source && source.width == 0)
242242
|| (source && source.height == 0)

0 commit comments

Comments
 (0)