Merge pull request #18061 from Snuffleupagus/api-report-Stats
Slightly re-factor how the viewer initializes debug-only functionality
This commit is contained in:
commit
0347e59b99
@ -1510,8 +1510,14 @@ class PDFPageProxy {
|
|||||||
internalRenderTask.capability.resolve();
|
internalRenderTask.capability.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._stats?.timeEnd("Rendering");
|
if (this._stats) {
|
||||||
this._stats?.timeEnd("Overall");
|
this._stats.timeEnd("Rendering");
|
||||||
|
this._stats.timeEnd("Overall");
|
||||||
|
|
||||||
|
if (globalThis.Stats?.enabled) {
|
||||||
|
globalThis.Stats.add(this.pageNumber, this._stats);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const internalRenderTask = new InternalRenderTask({
|
const internalRenderTask = new InternalRenderTask({
|
||||||
|
|||||||
60
web/app.js
60
web/app.js
@ -265,9 +265,27 @@ 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 {
|
||||||
await loadFakeWorker();
|
GlobalWorkerOptions.workerSrc ||= AppOptions.get("workerSrc");
|
||||||
|
|
||||||
|
if (typeof PDFJSDev === "undefined") {
|
||||||
|
globalThis.pdfjsWorker = await import("pdfjs/pdf.worker.js");
|
||||||
|
} else {
|
||||||
|
await __non_webpack_import__(PDFWorker.workerSrc);
|
||||||
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`_parseHashParams: "${ex.message}".`);
|
console.error(`_parseHashParams: "${ex.message}".`);
|
||||||
}
|
}
|
||||||
@ -306,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}".`);
|
||||||
@ -315,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}".`);
|
||||||
@ -1898,10 +1915,6 @@ const PDFViewerApplication = {
|
|||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (AppOptions.get("pdfBug")) {
|
|
||||||
eventBus._on("pagerendered", reportPageStatsPDFBug, { signal });
|
|
||||||
eventBus._on("pagechanging", reportPageStatsPDFBug, { signal });
|
|
||||||
}
|
|
||||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||||
eventBus._on("fileinputchange", webViewerFileInputChange, { signal });
|
eventBus._on("fileinputchange", webViewerFileInputChange, { signal });
|
||||||
eventBus._on("openfile", webViewerOpenFile, { signal });
|
eventBus._on("openfile", webViewerOpenFile, { signal });
|
||||||
@ -2168,35 +2181,6 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadFakeWorker() {
|
|
||||||
GlobalWorkerOptions.workerSrc ||= AppOptions.get("workerSrc");
|
|
||||||
|
|
||||||
if (typeof PDFJSDev === "undefined") {
|
|
||||||
globalThis.pdfjsWorker = await import("pdfjs/pdf.worker.js");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await __non_webpack_import__(PDFWorker.workerSrc);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 reportPageStatsPDFBug({ pageNumber }) {
|
|
||||||
if (!globalThis.Stats?.enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const pageView = PDFViewerApplication.pdfViewer.getPageView(
|
|
||||||
/* index = */ pageNumber - 1
|
|
||||||
);
|
|
||||||
globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user