Polyfill ImageData in Node.js environments
Given that `ImageData` has been supported for many years in all browsers, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/ImageData#browser_compatibility), we have a `typeof` check that's only necessary in Node.js environments. Since the `@napi-rs/canvas` package provides that functionality, we can thus add an `ImageData` polyfill which allows us to ever so slightly simplify the code.
This commit is contained in:
parent
86f943ca03
commit
9b62f2e7d1
@ -586,7 +586,7 @@ class CanvasExtraState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function putBinaryImageData(ctx, imgData) {
|
function putBinaryImageData(ctx, imgData) {
|
||||||
if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
|
if (imgData instanceof ImageData) {
|
||||||
ctx.putImageData(imgData, 0, 0);
|
ctx.putImageData(imgData, 0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,6 +51,13 @@ if (
|
|||||||
warn("Cannot polyfill `DOMMatrix`, rendering may be broken.");
|
warn("Cannot polyfill `DOMMatrix`, rendering may be broken.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!globalThis.ImageData) {
|
||||||
|
if (canvas?.ImageData) {
|
||||||
|
globalThis.ImageData = canvas.ImageData;
|
||||||
|
} else {
|
||||||
|
warn("Cannot polyfill `ImageData`, rendering may be broken.");
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!globalThis.Path2D) {
|
if (!globalThis.Path2D) {
|
||||||
if (canvas?.Path2D) {
|
if (canvas?.Path2D) {
|
||||||
globalThis.Path2D = canvas.Path2D;
|
globalThis.Path2D = canvas.Path2D;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user