1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Remove most build-time require statements from the viewer (PR 16009 follow-up)

This further extends the web-specific import maps introduced in PR 16009, to allow removing *most* of the build-time `require` statements from the viewer. The few remaining ones are fallbacks used for the COMPONENTS respectively the `legacy` GENERIC builds.
This commit is contained in:
Jonas Jenwald 2023-02-05 16:13:18 +01:00
parent 8f37301d1f
commit 90ffbc1d39
7 changed files with 48 additions and 57 deletions

View file

@ -46,6 +46,7 @@ import { AnnotationEditorLayerBuilder } from "./annotation_editor_layer_builder.
import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
import { compatibilityParams } from "./app_options.js";
import { NullL10n } from "./l10n_utils.js";
import { SimpleLinkService } from "./pdf_link_service.js";
import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js";
import { TextAccessibilityManager } from "./text_accessibility.js";
import { TextHighlighter } from "./text_highlighter.js";
@ -103,7 +104,6 @@ const DEFAULT_LAYER_PROPERTIES = () => {
findController: null,
hasJSActionsPromise: null,
get linkService() {
const { SimpleLinkService } = require("./pdf_link_service.js");
return new SimpleLinkService();
},
};

View file

@ -51,6 +51,7 @@ See https://github.com/adobe-type-tools/cmap-resources
"pdfjs-fitCurve": "../build/dev-fitCurve/fit_curve.js",
"web-annotation_editor_params": "./stubs-geckoview.js",
"web-com": "./genericcom.js",
"web-pdf_attachment_viewer": "./stubs-geckoview.js",
"web-pdf_cursor_tools": "./stubs-geckoview.js",
"web-pdf_document_properties": "./stubs-geckoview.js",
@ -61,6 +62,7 @@ See https://github.com/adobe-type-tools/cmap-resources
"web-pdf_sidebar": "./stubs-geckoview.js",
"web-pdf_sidebar_resizer": "./stubs-geckoview.js",
"web-pdf_thumbnail_viewer": "./stubs-geckoview.js",
"web-print_service": "./stubs-geckoview.js",
"web-secondary_toolbar": "./stubs-geckoview.js",
"web-toolbar": "./stubs-geckoview.js"
}

View file

@ -13,6 +13,7 @@
* limitations under the License.
*/
import "web-com";
import { RenderingStates, ScrollMode, SpreadMode } from "./ui_utils.js";
import { AppOptions } from "./app_options.js";
import { LinkTarget } from "./pdf_link_service.js";
@ -34,10 +35,6 @@ window.PDFViewerApplication = PDFViewerApplication;
window.PDFViewerApplicationConstants = AppConstants;
window.PDFViewerApplicationOptions = AppOptions;
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
require("./firefoxcom.js");
}
function getViewerConfiguration() {
return {
appContainer: document.body,
@ -60,15 +57,11 @@ function getViewerConfiguration() {
function webViewerLoad() {
const config = getViewerConfiguration();
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
window.isGECKOVIEW = true;
import("pdfjs-web/genericcom.js").then(function (genericCom) {
PDFViewerApplication.run(config);
});
} else {
PDFViewerApplication.run(config);
}
PDFViewerApplication.run(config);
}
// Block the "load" event until all pages are loaded, to ensure that printing

View file

@ -52,6 +52,7 @@ See https://github.com/adobe-type-tools/cmap-resources
"pdfjs-fitCurve": "../build/dev-fitCurve/fit_curve.js",
"web-annotation_editor_params": "./annotation_editor_params.js",
"web-com": "./genericcom.js",
"web-pdf_attachment_viewer": "./pdf_attachment_viewer.js",
"web-pdf_cursor_tools": "./pdf_cursor_tools.js",
"web-pdf_document_properties": "./pdf_document_properties.js",
@ -62,6 +63,7 @@ See https://github.com/adobe-type-tools/cmap-resources
"web-pdf_sidebar": "./pdf_sidebar.js",
"web-pdf_sidebar_resizer": "./pdf_sidebar_resizer.js",
"web-pdf_thumbnail_viewer": "./pdf_thumbnail_viewer.js",
"web-print_service": "./pdf_print_service.js",
"web-secondary_toolbar": "./secondary_toolbar.js",
"web-toolbar": "./toolbar.js"
}

View file

@ -13,6 +13,8 @@
* limitations under the License.
*/
import "web-com";
import "web-print_service";
import { RenderingStates, ScrollMode, SpreadMode } from "./ui_utils.js";
import { AppOptions } from "./app_options.js";
import { LinkTarget } from "./pdf_link_service.js";
@ -54,20 +56,6 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
})();
}
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
require("./firefoxcom.js");
require("./firefox_print_service.js");
}
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")) {
require("./genericcom.js");
}
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
require("./chromecom.js");
}
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME || GENERIC")) {
require("./pdf_print_service.js");
}
function getViewerConfiguration() {
return {
appContainer: document.body,
@ -206,37 +194,28 @@ function getViewerConfiguration() {
function webViewerLoad() {
const config = getViewerConfiguration();
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
Promise.all([
import("pdfjs-web/genericcom.js"),
import("pdfjs-web/pdf_print_service.js"),
]).then(function ([genericCom, pdfPrintService]) {
PDFViewerApplication.run(config);
});
} else {
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
// files are loaded but *before* the viewer initialization has run.
const event = document.createEvent("CustomEvent");
event.initCustomEvent("webviewerloaded", true, true, {
source: window,
});
try {
// Attempt to dispatch the event at the embedding `document`,
// in order to support cases where the viewer is embedded in
// a *dynamically* created <iframe> element.
parent.document.dispatchEvent(event);
} catch (ex) {
// The viewer could be in e.g. a cross-origin <iframe> element,
// fallback to dispatching the event at the current `document`.
console.error(`webviewerloaded: ${ex}`);
document.dispatchEvent(event);
}
}
PDFViewerApplication.run(config);
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
// files are loaded but *before* the viewer initialization has run.
const event = document.createEvent("CustomEvent");
event.initCustomEvent("webviewerloaded", true, true, {
source: window,
});
try {
// Attempt to dispatch the event at the embedding `document`,
// in order to support cases where the viewer is embedded in
// a *dynamically* created <iframe> element.
parent.document.dispatchEvent(event);
} catch (ex) {
// The viewer could be in e.g. a cross-origin <iframe> element,
// fallback to dispatching the event at the current `document`.
console.error(`webviewerloaded: ${ex}`);
document.dispatchEvent(event);
}
}
PDFViewerApplication.run(config);
}
// Block the "load" event until all pages are loaded, to ensure that printing