Skip to content

Commit

Permalink
Fix #17: isImageBitmapSource() fails in web workers
Browse files Browse the repository at this point in the history
  • Loading branch information
undecaf committed Jul 30, 2024
1 parent 463cfa6 commit 93ef376
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Expose the `BarcodeDetectorPolyfill` API in variable `barcodeDetectorPolyfill`:

```html
<script src="https://cdn.jsdelivr.net/npm/@undecaf/zbar-wasm@0.9.15/dist/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@undecaf/barcode-detector-polyfill@0.9.20/dist/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@undecaf/barcode-detector-polyfill@0.9.21/dist/index.js"></script>
<script>
try {
window['BarcodeDetector'].getSupportedFormats()
Expand Down
8 changes: 4 additions & 4 deletions docs/example-bundled/js/main.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/example-loaded/js/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example-bundled/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@undecaf/barcode-detector-polyfill-example",
"version": "0.9.19",
"version": "0.9.21",
"type": "module",
"scripts": {
"build:esbuild": "node esbuild.config.js",
Expand All @@ -9,7 +9,7 @@
"author": "F. Kasper <fkasper@modus-operandi.at>",
"license": "MIT",
"dependencies": {
"@undecaf/barcode-detector-polyfill": "^0.9.20",
"@undecaf/barcode-detector-polyfill": "^0.9.21",
"@undecaf/zbar-wasm": "^0.9.15"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions example-loaded/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@undecaf/barcode-detector-polyfill-example",
"version": "0.9.19",
"version": "0.9.21",
"type": "module",
"scripts": {
"build:esbuild": "node esbuild.config.js",
Expand All @@ -9,7 +9,7 @@
"author": "F. Kasper <fkasper@modus-operandi.at>",
"license": "MIT",
"dependencies": {
"@undecaf/barcode-detector-polyfill": "^0.9.20"
"@undecaf/barcode-detector-polyfill": "^0.9.21"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.1.1",
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@undecaf/barcode-detector-polyfill",
"version": "0.9.20",
"version": "0.9.21",
"description": "A WebAssembly polyfill for the Barcode Detection API",
"keywords": [
"polyfill",
Expand Down
12 changes: 6 additions & 6 deletions src/BarcodeDetectorPolyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ export class BarcodeDetectorPolyfill {
* object having zero width or height.
*/
private static isImageBitmapSource(source: any): source is ImageBitmapSource {
return (source instanceof HTMLImageElement)
|| (source instanceof HTMLVideoElement)
|| (source instanceof HTMLCanvasElement)
|| (source instanceof Blob)
return (typeof HTMLImageElement !== 'undefined' && source instanceof HTMLImageElement)
|| (typeof HTMLVideoElement !== 'undefined' && source instanceof HTMLVideoElement)
|| (typeof HTMLCanvasElement !== 'undefined' && source instanceof HTMLCanvasElement)
|| (typeof CanvasRenderingContext2D !== 'undefined' && source instanceof CanvasRenderingContext2D)
|| (typeof ImageBitmap !== 'undefined' && source instanceof ImageBitmap)
|| (source instanceof ImageData)
|| (source instanceof CanvasRenderingContext2D)
|| (source instanceof ImageBitmap)
|| (source instanceof Blob)
// Note the (lenient) equality operator
|| (source && source.width == 0)
|| (source && source.height == 0)
Expand Down

0 comments on commit 93ef376

Please sign in to comment.