diff --git a/gulpfile.mjs b/gulpfile.mjs index 160b1a953..5be216f8a 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -211,6 +211,14 @@ function createWebpackConfig( } const babelExcludeRegExp = new RegExp(`(${babelExcludes.join("|")})`); + const babelPresets = skipBabel + ? undefined + : [ + [ + "@babel/preset-env", + { corejs: "3.31.1", shippedProposals: true, useBuiltIns: "usage" }, + ], + ]; const babelPlugins = ["@babel/plugin-transform-modules-commonjs"]; const plugins = []; @@ -289,7 +297,7 @@ function createWebpackConfig( loader: "babel-loader", exclude: babelExcludeRegExp, options: { - presets: skipBabel ? undefined : ["@babel/preset-env"], + presets: babelPresets, plugins: babelPlugins, targets: BABEL_TARGETS, }, diff --git a/src/display/node_utils.js b/src/display/node_utils.js index e848ea543..e187c5aec 100644 --- a/src/display/node_utils.js +++ b/src/display/node_utils.js @@ -20,6 +20,7 @@ import { BaseFilterFactory, BaseStandardFontDataFactory, } from "./base_factory.js"; +import { isNodeJS } from "../shared/is_node.js"; if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { throw new Error( @@ -27,6 +28,26 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { ); } +if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("SKIP_BABEL")) { + (function checkDOMMatrix() { + if (globalThis.DOMMatrix || !isNodeJS) { + return; + } + globalThis.DOMMatrix = __non_webpack_require__("canvas").DOMMatrix; + })(); + + (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); + })(); +} + const fetchData = function (url) { return new Promise((resolve, reject) => { const fs = __non_webpack_require__("fs"); diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js deleted file mode 100644 index 346024f77..000000000 --- a/src/shared/compatibility.js +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright 2017 Mozilla Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* globals __non_webpack_require__ */ - -import { isNodeJS } from "./is_node.js"; - -// Support: Node.js -(function checkDOMMatrix() { - if (globalThis.DOMMatrix || !isNodeJS) { - return; - } - 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: Chrome<98 -(function checkStructuredClone() { - if (globalThis.structuredClone) { - return; - } - require("core-js/web/structured-clone.js"); -})(); diff --git a/src/shared/util.js b/src/shared/util.js index 70184dd8d..bbc692dd0 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -13,16 +13,6 @@ * limitations under the License. */ -// Skip compatibility checks for modern builds and if we already ran the module. -if ( - typeof PDFJSDev !== "undefined" && - !PDFJSDev.test("SKIP_BABEL") && - !globalThis._pdfjsCompatibilityChecked -) { - globalThis._pdfjsCompatibilityChecked = true; - require("./compatibility.js"); -} - const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];