Polyfill Path2D
in Node.js environments
Until just recently the only existing `Path2D` polyfill didn't have support for Node.js and/or the `node-canvas` package. Given that this was just fixed, in the latest version, we can now finally remove our inline-checks at the relevant call-sites; please also see https://github.com/nilzona/path2d-polyfill#usage-with-node-canvas
This commit is contained in:
parent
cb5a28ceca
commit
cf0369d622
@ -2206,6 +2206,7 @@ function packageJson() {
|
||||
canvas: "^2.11.0",
|
||||
},
|
||||
dependencies: {
|
||||
"path2d-polyfill": "^2.0.1",
|
||||
"web-streams-polyfill": "^3.2.1",
|
||||
},
|
||||
browser: {
|
||||
|
2673
package-lock.json
generated
2673
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -39,6 +39,7 @@
|
||||
"merge-stream": "^2.0.0",
|
||||
"mkdirp": "^2.1.3",
|
||||
"needle": "^3.2.0",
|
||||
"path2d-polyfill": "^2.0.1",
|
||||
"postcss": "^8.4.21",
|
||||
"postcss-dir-pseudo-class": "^7.0.0",
|
||||
"postcss-logical": "^5.0.4",
|
||||
|
@ -38,7 +38,6 @@ import {
|
||||
TilingPattern,
|
||||
} from "./pattern_helper.js";
|
||||
import { applyMaskImageData } from "../shared/image_utils.js";
|
||||
import { isNodeJS } from "../shared/is_node.js";
|
||||
|
||||
// <canvas> contexts store most of the state we need natively.
|
||||
// However, PDF needs a bit more state, which we store here.
|
||||
@ -55,13 +54,7 @@ const EXECUTION_TIME = 15; // ms
|
||||
const EXECUTION_STEPS = 10;
|
||||
|
||||
// To disable Type3 compilation, set the value to `-1`.
|
||||
const MAX_SIZE_TO_COMPILE =
|
||||
typeof PDFJSDev !== "undefined" &&
|
||||
PDFJSDev.test("GENERIC") &&
|
||||
isNodeJS &&
|
||||
typeof Path2D === "undefined"
|
||||
? -1
|
||||
: 1000;
|
||||
const MAX_SIZE_TO_COMPILE = 1000;
|
||||
|
||||
const FULL_CHUNK_HEIGHT = 16;
|
||||
|
||||
|
@ -21,7 +21,6 @@ import {
|
||||
Util,
|
||||
} from "../shared/util.js";
|
||||
import { getCurrentTransform } from "./display_utils.js";
|
||||
import { isNodeJS } from "../shared/is_node.js";
|
||||
|
||||
const PathType = {
|
||||
FILL: "Fill",
|
||||
@ -30,7 +29,7 @@ const PathType = {
|
||||
};
|
||||
|
||||
function applyBoundingBox(ctx, bbox) {
|
||||
if (!bbox || isNodeJS) {
|
||||
if (!bbox) {
|
||||
return;
|
||||
}
|
||||
const width = bbox[2] - bbox[0];
|
||||
|
@ -46,6 +46,18 @@ import { isNodeJS } from "./is_node.js";
|
||||
globalThis.DOMMatrix = __non_webpack_require__("canvas").DOMMatrix;
|
||||
})();
|
||||
|
||||
// Support: Node.js
|
||||
(function checkPath2D() {
|
||||
if (globalThis.Path2D || !isNodeJS) {
|
||||
return;
|
||||
}
|
||||
const { CanvasRenderingContext2D } = __non_webpack_require__("canvas");
|
||||
const { polyfillPath2D } = __non_webpack_require__("path2d-polyfill");
|
||||
|
||||
globalThis.CanvasRenderingContext2D = CanvasRenderingContext2D;
|
||||
polyfillPath2D(globalThis);
|
||||
})();
|
||||
|
||||
// Support: Node.js
|
||||
(function checkReadableStream() {
|
||||
if (globalThis.ReadableStream || !isNodeJS) {
|
||||
|
Loading…
Reference in New Issue
Block a user