Skip to content

Commit

Permalink
Move the loadPDFBug function into `PDFViewerApplication._parseHashP…
Browse files Browse the repository at this point in the history
…arams`

Given that this is a debug-only function we don't need to define it "globally" in the `web/app.js` file.
  • Loading branch information
Snuffleupagus committed May 11, 2024
1 parent ba8c620 commit 5fbc5ba
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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}".`);
Expand All @@ -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}".`);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5fbc5ba

Please sign in to comment.