fix:type def of decodeFromImage() param (#23)

This commit is contained in:
dyoshikawa
2022-11-23 11:53:11 +08:00
committed by GitHub
parent 8afbcdad33
commit 0b7edb39df
+8 -7
View File
@@ -229,7 +229,7 @@ class QrcodeDecoder {
* refer to jsqr options: https://github.com/cozmo/jsQR * refer to jsqr options: https://github.com/cozmo/jsQR
*/ */
async decodeFromImage( async decodeFromImage(
img: HTMLImageElement, img: HTMLImageElement | string,
options: { crossOrigin?: string } = {}, options: { crossOrigin?: string } = {},
) { ) {
let imgDom: HTMLImageElement | null = null; let imgDom: HTMLImageElement | null = null;
@@ -237,12 +237,8 @@ class QrcodeDecoder {
...this.defaultOption, ...this.defaultOption,
...options, ...options,
}; };
if (+img.nodeType > 0) {
if (!img.src) { if (typeof img === 'string') {
throw new Error('The ImageElement must contain a src');
}
imgDom = img;
} else if (typeof img === 'string') {
imgDom = document.createElement('img'); imgDom = document.createElement('img');
if (options.crossOrigin) { if (options.crossOrigin) {
imgDom.crossOrigin = options.crossOrigin; imgDom.crossOrigin = options.crossOrigin;
@@ -253,6 +249,11 @@ class QrcodeDecoder {
imgDom!.onload = () => resolve(true); imgDom!.onload = () => resolve(true);
}); });
await proms(); await proms();
} else if (+img.nodeType > 0) {
if (!img.src) {
throw new Error('The ImageElement must contain a src');
}
imgDom = img;
} }
let code = null; let code = null;