Merge pull request #11905 from Snuffleupagus/less-require
Reduce the usage of `require` statements in code-paths not protected by pre-processor and/or run-time checks
This commit is contained in:
commit
15087c35d1
@ -678,7 +678,7 @@ function isMessagePort(maybePort) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Worker thread (and not node.js)?
|
// Worker thread (and not Node.js)?
|
||||||
if (
|
if (
|
||||||
typeof window === "undefined" &&
|
typeof window === "undefined" &&
|
||||||
!isNodeJS &&
|
!isNodeJS &&
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { isNodeJS } from "../shared/is_node.js";
|
||||||
|
|
||||||
const compatibilityParams = Object.create(null);
|
const compatibilityParams = Object.create(null);
|
||||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||||
const { isNodeJS } = require("../shared/is_node.js");
|
|
||||||
|
|
||||||
const userAgent =
|
const userAgent =
|
||||||
(typeof navigator !== "undefined" && navigator.userAgent) || "";
|
(typeof navigator !== "undefined" && navigator.userAgent) || "";
|
||||||
const isIE = /Trident/.test(userAgent);
|
const isIE = /Trident/.test(userAgent);
|
||||||
@ -41,5 +41,6 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
const apiCompatibilityParams = Object.freeze(compatibilityParams);
|
||||||
|
|
||||||
exports.apiCompatibilityParams = Object.freeze(compatibilityParams);
|
export { apiCompatibilityParams };
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint no-var: error */
|
/* eslint no-var: error */
|
||||||
|
|
||||||
|
import { isNodeJS } from "./is_node.js";
|
||||||
|
|
||||||
// Skip compatibility checks for modern builds and if we already ran the module.
|
// Skip compatibility checks for modern builds and if we already ran the module.
|
||||||
if (
|
if (
|
||||||
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("SKIP_BABEL")) &&
|
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("SKIP_BABEL")) &&
|
||||||
@ -27,8 +29,6 @@ if (
|
|||||||
}
|
}
|
||||||
globalThis._pdfjsCompatibilityChecked = true;
|
globalThis._pdfjsCompatibilityChecked = true;
|
||||||
|
|
||||||
const { isNodeJS } = require("./is_node.js");
|
|
||||||
|
|
||||||
const hasDOM = typeof window === "object" && typeof document === "object";
|
const hasDOM = typeof window === "object" && typeof document === "object";
|
||||||
const userAgent =
|
const userAgent =
|
||||||
(typeof navigator !== "undefined" && navigator.userAgent) || "";
|
(typeof navigator !== "undefined" && navigator.userAgent) || "";
|
||||||
@ -248,15 +248,18 @@ if (
|
|||||||
|
|
||||||
// Support: IE
|
// Support: IE
|
||||||
(function checkURL() {
|
(function checkURL() {
|
||||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) {
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
||||||
// The current image decoders don't use the `URL` constructor, so it
|
// Prevent "require is not a function" errors in development mode,
|
||||||
// doesn't need to be polyfilled for the IMAGE_DECODERS build target.
|
// since the `URL` constructor should be available in modern browers.
|
||||||
return;
|
return;
|
||||||
}
|
} else if (!PDFJSDev.test("GENERIC")) {
|
||||||
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
|
|
||||||
// The `URL` constructor is assumed to be available in the extension
|
// The `URL` constructor is assumed to be available in the extension
|
||||||
// builds.
|
// builds.
|
||||||
return;
|
return;
|
||||||
|
} else if (PDFJSDev.test("IMAGE_DECODERS")) {
|
||||||
|
// The current image decoders don't use the `URL` constructor, so it
|
||||||
|
// doesn't need to be polyfilled for the IMAGE_DECODERS build target.
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
globalThis.URL = require("core-js/web/url.js");
|
globalThis.URL = require("core-js/web/url.js");
|
||||||
})();
|
})();
|
||||||
|
@ -35,5 +35,6 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
const viewerCompatibilityParams = Object.freeze(compatibilityParams);
|
||||||
|
|
||||||
exports.viewerCompatibilityParams = Object.freeze(compatibilityParams);
|
export { viewerCompatibilityParams };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user