Skip to content

Commit

Permalink
fix: type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Dec 3, 2022
1 parent db7d435 commit b516783
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/embed-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ async function embedImageNode<T extends HTMLElement | SVGImageElement>(

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
Expand Down
5 changes: 3 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ export function canvasToBlob(
export function createImage(url: string): Promise<HTMLImageElement> {
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
})
}
Expand Down

0 comments on commit b516783

Please sign in to comment.