Merge pull request #17830 from Snuffleupagus/path2d-new-polyfill

Update the `Path2D` polyfill for Node.js environments
This commit is contained in:
Jonas Jenwald 2024-03-25 14:58:08 +01:00 committed by GitHub
commit 90dfe52a76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 24 deletions

View File

@ -2155,7 +2155,7 @@ function packageJson() {
license: DIST_LICENSE, license: DIST_LICENSE,
optionalDependencies: { optionalDependencies: {
canvas: "^2.11.2", canvas: "^2.11.2",
"path2d-polyfill": "^2.0.1", path2d: "^0.1.2",
}, },
browser: { browser: {
canvas: false, canvas: false,

26
package-lock.json generated
View File

@ -45,7 +45,7 @@
"merge-stream": "^2.0.0", "merge-stream": "^2.0.0",
"mkdirp": "^3.0.1", "mkdirp": "^3.0.1",
"needle": "^3.3.1", "needle": "^3.3.1",
"path2d-polyfill": "^2.1.1", "path2d": "^0.1.2",
"pngjs": "^7.0.0", "pngjs": "^7.0.0",
"postcss": "^8.4.35", "postcss": "^8.4.35",
"postcss-dark-theme-class": "^1.2.1", "postcss-dark-theme-class": "^1.2.1",
@ -13358,6 +13358,7 @@
}, },
"node_modules/npm/node_modules/lodash._baseindexof": { "node_modules/npm/node_modules/lodash._baseindexof": {
"version": "3.1.0", "version": "3.1.0",
"dev": true,
"inBundle": true, "inBundle": true,
"license": "MIT" "license": "MIT"
}, },
@ -13373,16 +13374,19 @@
}, },
"node_modules/npm/node_modules/lodash._bindcallback": { "node_modules/npm/node_modules/lodash._bindcallback": {
"version": "3.0.1", "version": "3.0.1",
"dev": true,
"inBundle": true, "inBundle": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/npm/node_modules/lodash._cacheindexof": { "node_modules/npm/node_modules/lodash._cacheindexof": {
"version": "3.0.2", "version": "3.0.2",
"dev": true,
"inBundle": true, "inBundle": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/npm/node_modules/lodash._createcache": { "node_modules/npm/node_modules/lodash._createcache": {
"version": "3.1.2", "version": "3.1.2",
"dev": true,
"inBundle": true, "inBundle": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -13397,6 +13401,7 @@
}, },
"node_modules/npm/node_modules/lodash._getnative": { "node_modules/npm/node_modules/lodash._getnative": {
"version": "3.9.1", "version": "3.9.1",
"dev": true,
"inBundle": true, "inBundle": true,
"license": "MIT" "license": "MIT"
}, },
@ -13414,6 +13419,7 @@
}, },
"node_modules/npm/node_modules/lodash.restparam": { "node_modules/npm/node_modules/lodash.restparam": {
"version": "3.6.1", "version": "3.6.1",
"dev": true,
"inBundle": true, "inBundle": true,
"license": "MIT" "license": "MIT"
}, },
@ -16192,26 +16198,14 @@
} }
}, },
"node_modules/path2d": { "node_modules/path2d": {
"version": "0.1.1", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/path2d/-/path2d-0.1.1.tgz", "resolved": "https://registry.npmjs.org/path2d/-/path2d-0.1.2.tgz",
"integrity": "sha512-/+S03c8AGsDYKKBtRDqieTJv2GlkMb0bWjnqOgtF6MkjdUQ9a8ARAtxWf9NgKLGm2+WQr6+/tqJdU8HNGsIDoA==", "integrity": "sha512-LW++2uxgHNL/FANhgGTPo/yDDQcgsVbKotwIVbpTgTBgRlKUpjOpjp3s3+KjG4OWCQ/r6z+WLDljH1/fC03PWw==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/path2d-polyfill": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/path2d-polyfill/-/path2d-polyfill-2.1.1.tgz",
"integrity": "sha512-4Rka5lN+rY/p0CdD8+E+BFv51lFaFvJOrlOhyQ+zjzyQrzyh3ozmxd1vVGGDdIbUFSBtIZLSnspxTgPT0iJhvA==",
"dev": true,
"dependencies": {
"path2d": "0.1.1"
},
"engines": {
"node": ">=18"
}
},
"node_modules/pend": { "node_modules/pend": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",

View File

@ -39,7 +39,7 @@
"merge-stream": "^2.0.0", "merge-stream": "^2.0.0",
"mkdirp": "^3.0.1", "mkdirp": "^3.0.1",
"needle": "^3.3.1", "needle": "^3.3.1",
"path2d-polyfill": "^2.1.1", "path2d": "^0.1.2",
"pngjs": "^7.0.0", "pngjs": "^7.0.0",
"postcss": "^8.4.35", "postcss": "^8.4.35",
"postcss-dark-theme-class": "^1.2.1", "postcss-dark-theme-class": "^1.2.1",

View File

@ -27,7 +27,7 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
); );
} }
let fs, canvas, path2d_polyfill; let fs, canvas, path2d;
if (isNodeJS) { if (isNodeJS) {
// Native packages. // Native packages.
fs = await __non_webpack_import__("fs"); fs = await __non_webpack_import__("fs");
@ -36,7 +36,7 @@ if (isNodeJS) {
canvas = await __non_webpack_import__("canvas"); canvas = await __non_webpack_import__("canvas");
} catch {} } catch {}
try { try {
path2d_polyfill = await __non_webpack_import__("path2d-polyfill"); path2d = await __non_webpack_import__("path2d");
} catch {} } catch {}
} }
@ -59,11 +59,17 @@ if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("SKIP_BABEL")) {
return; return;
} }
const CanvasRenderingContext2D = canvas?.CanvasRenderingContext2D; const CanvasRenderingContext2D = canvas?.CanvasRenderingContext2D;
const polyfillPath2D = path2d_polyfill?.polyfillPath2D; const applyPath2DToCanvasRenderingContext =
path2d?.applyPath2DToCanvasRenderingContext;
const Path2D = path2d?.Path2D;
if (CanvasRenderingContext2D && polyfillPath2D) { if (
globalThis.CanvasRenderingContext2D = CanvasRenderingContext2D; CanvasRenderingContext2D &&
polyfillPath2D(globalThis); applyPath2DToCanvasRenderingContext &&
Path2D
) {
applyPath2DToCanvasRenderingContext(CanvasRenderingContext2D);
globalThis.Path2D = Path2D;
} else { } else {
warn("Cannot polyfill `Path2D`, rendering may be broken."); warn("Cannot polyfill `Path2D`, rendering may be broken.");
} }