From b516783244e9aa847c89cd3ca3b8114bc6157934 Mon Sep 17 00:00:00 2001 From: bubkoo Date: Sat, 3 Dec 2022 12:13:41 +0800 Subject: [PATCH] fix: type errors --- src/embed-images.ts | 8 +++++++- src/util.ts | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/embed-images.ts b/src/embed-images.ts index e8a075c2..6da82d42 100644 --- a/src/embed-images.ts +++ b/src/embed-images.ts @@ -40,8 +40,14 @@ async function embedImageNode( const dataURL = await resourceToDataURL(url, getMimeType(url), options) await new Promise((resolve, reject) => { - clonedNode.decode = resolve + clonedNode.onload = resolve clonedNode.onerror = reject + + const image = clonedNode as HTMLImageElement + if (image.decode) { + image.decode = resolve as any + } + if (clonedNode instanceof HTMLImageElement) { clonedNode.srcset = '' clonedNode.src = dataURL diff --git a/src/util.ts b/src/util.ts index abff7bf5..2e375735 100644 --- a/src/util.ts +++ b/src/util.ts @@ -183,10 +183,11 @@ export function canvasToBlob( export function createImage(url: string): Promise { return new Promise((resolve, reject) => { const img = new Image() - img.decode = () => resolve(img) + img.decode = () => resolve(img) as any + img.onload = () => resolve(img) img.onerror = reject img.crossOrigin = 'anonymous' - img.decoding = 'sync' + img.decoding = 'async' img.src = url }) }