1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +02:00

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:
Jonas Jenwald 2024-11-09 12:58:18 +01:00
parent 86f943ca03
commit 9b62f2e7d1
2 changed files with 8 additions and 1 deletions

View file

@ -586,7 +586,7 @@ class CanvasExtraState {
}
function putBinaryImageData(ctx, imgData) {
if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
if (imgData instanceof ImageData) {
ctx.putImageData(imgData, 0, 0);
return;
}

View file

@ -51,6 +51,13 @@ if (
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 (canvas?.Path2D) {
globalThis.Path2D = canvas.Path2D;