From 5fbc5ba16a6e595c45b0da1b9a15259558242247 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 10 May 2024 12:36:35 +0200 Subject: [PATCH] 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. --- web/app.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/web/app.js b/web/app.js index b97ed3d01..a980be77c 100644 --- a/web/app.js +++ b/web/app.js @@ -265,6 +265,18 @@ const PDFViewerApplication = { const { mainContainer, viewerContainer } = this.appConfig, 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") { try { GlobalWorkerOptions.workerSrc ||= AppOptions.get("workerSrc"); @@ -312,7 +324,7 @@ const PDFViewerApplication = { case "hover": viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`); try { - await loadPDFBug(this); + await loadPDFBug(); this._PDFBug.loadCSS(); } catch (ex) { console.error(`_parseHashParams: "${ex.message}".`); @@ -321,12 +333,11 @@ const PDFViewerApplication = { } } if (params.has("pdfbug")) { - AppOptions.set("pdfBug", true); - AppOptions.set("fontExtraProperties", true); + AppOptions.setAll({ pdfBug: true, fontExtraProperties: true }); const enabled = params.get("pdfbug").split(","); try { - await loadPDFBug(this); + await loadPDFBug(); this._PDFBug.init(mainContainer, enabled); } catch (ex) { 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 }) { // If the page is (the most) visible when it starts rendering, // ensure that the page number input loading indicator is displayed.