Move the loadPDFBug function into PDFViewerApplication._parseHashParams

Given that this is a debug-only function we don't need to define it "globally" in the `web/app.js` file.
This commit is contained in:
Jonas Jenwald 2024-05-10 12:36:35 +02:00
parent ba8c620e4b
commit 5fbc5ba16a

View File

@ -265,6 +265,18 @@ const PDFViewerApplication = {
const { mainContainer, viewerContainer } = this.appConfig, const { mainContainer, viewerContainer } = this.appConfig,
params = parseQueryString(hash); params = parseQueryString(hash);
const loadPDFBug = async () => {
if (this._PDFBug) {
return;
}
const { PDFBug } =
typeof PDFJSDev === "undefined"
? await import(AppOptions.get("debuggerSrc")) // eslint-disable-line no-unsanitized/method
: await __non_webpack_import__(AppOptions.get("debuggerSrc"));
this._PDFBug = PDFBug;
};
if (params.get("disableworker") === "true") { if (params.get("disableworker") === "true") {
try { try {
GlobalWorkerOptions.workerSrc ||= AppOptions.get("workerSrc"); GlobalWorkerOptions.workerSrc ||= AppOptions.get("workerSrc");
@ -312,7 +324,7 @@ const PDFViewerApplication = {
case "hover": case "hover":
viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`); viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
try { try {
await loadPDFBug(this); await loadPDFBug();
this._PDFBug.loadCSS(); this._PDFBug.loadCSS();
} catch (ex) { } catch (ex) {
console.error(`_parseHashParams: "${ex.message}".`); console.error(`_parseHashParams: "${ex.message}".`);
@ -321,12 +333,11 @@ const PDFViewerApplication = {
} }
} }
if (params.has("pdfbug")) { if (params.has("pdfbug")) {
AppOptions.set("pdfBug", true); AppOptions.setAll({ pdfBug: true, fontExtraProperties: true });
AppOptions.set("fontExtraProperties", true);
const enabled = params.get("pdfbug").split(","); const enabled = params.get("pdfbug").split(",");
try { try {
await loadPDFBug(this); await loadPDFBug();
this._PDFBug.init(mainContainer, enabled); this._PDFBug.init(mainContainer, enabled);
} catch (ex) { } catch (ex) {
console.error(`_parseHashParams: "${ex.message}".`); console.error(`_parseHashParams: "${ex.message}".`);
@ -2170,15 +2181,6 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
}; };
} }
async function loadPDFBug(self) {
const { PDFBug } =
typeof PDFJSDev === "undefined"
? await import(AppOptions.get("debuggerSrc")) // eslint-disable-line no-unsanitized/method
: await __non_webpack_import__(AppOptions.get("debuggerSrc"));
self._PDFBug = PDFBug;
}
function webViewerPageRender({ pageNumber }) { function webViewerPageRender({ pageNumber }) {
// If the page is (the most) visible when it starts rendering, // If the page is (the most) visible when it starts rendering,
// ensure that the page number input loading indicator is displayed. // ensure that the page number input loading indicator is displayed.