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:
parent
86f943ca03
commit
9b62f2e7d1
2 changed files with 8 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue