From e7437a0b67b0cc7fbe251607b5990179182ea486 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 11 Oct 2020 13:56:27 +0200 Subject: [PATCH] Use standard `import` statements when loading `PDFViewerApplication`/`AppOptions` in `web/viewer` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Given that we're no longer using SystemJS to load the `web/` files, see PR 11919, there's nothing that prevents us from using standard `ìmport` statements in this file. Obviously it's still necessary to load part of the code conditionally on the build type, however this still allows us to clean-up and simplify at least some of this file. --- web/viewer.js | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index 15ef9ca0e..d447c962a 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -13,7 +13,8 @@ * limitations under the License. */ -"use strict"; +import { AppOptions } from "./app_options.js"; +import { PDFViewerApplication } from "./app.js"; /* eslint-disable-next-line no-unused-vars */ const pdfjsVersion = @@ -22,6 +23,9 @@ const pdfjsVersion = const pdfjsBuild = typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0; +window.PDFViewerApplication = PDFViewerApplication; +window.PDFViewerApplicationOptions = AppOptions; + if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { var defaultUrl; // eslint-disable-line no-var @@ -42,12 +46,6 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { })(); } -let pdfjsWebApp, pdfjsWebAppOptions; -if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("PRODUCTION")) { - pdfjsWebApp = require("./app.js"); - pdfjsWebAppOptions = require("./app_options.js"); -} - if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { require("./firefoxcom.js"); require("./firefox_print_service.js"); @@ -198,23 +196,16 @@ function webViewerLoad() { const config = getViewerConfiguration(); if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) { Promise.all([ - import("pdfjs-web/app.js"), - import("pdfjs-web/app_options.js"), import("pdfjs-web/genericcom.js"), import("pdfjs-web/pdf_print_service.js"), - ]).then(function ([app, appOptions, genericCom, pdfPrintService]) { - window.PDFViewerApplication = app.PDFViewerApplication; - window.PDFViewerApplicationOptions = appOptions.AppOptions; - app.PDFViewerApplication.run(config); + ]).then(function ([genericCom, pdfPrintService]) { + PDFViewerApplication.run(config); }); } else { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { - pdfjsWebAppOptions.AppOptions.set("defaultUrl", defaultUrl); + AppOptions.set("defaultUrl", defaultUrl); } - window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication; - window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions; - if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")) { // Give custom implementations of the default viewer a simpler way to // set various `AppOptions`, by dispatching an event once all viewer @@ -236,7 +227,7 @@ function webViewerLoad() { } } - pdfjsWebApp.PDFViewerApplication.run(config); + PDFViewerApplication.run(config); } } @@ -248,3 +239,5 @@ if ( } else { document.addEventListener("DOMContentLoaded", webViewerLoad, true); } + +export { PDFViewerApplication, AppOptions as PDFViewerApplicationOptions };