From 51b0eb74a5b0255261c4f59b4583178dd87bb643 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 30 Dec 2025 01:37:44 +0200 Subject: [PATCH] chore(pdfjs): address requested changes --- apps/client/src/widgets/type_widgets/file/Pdf.tsx | 4 ++-- packages/pdfjs-viewer/src/custom.ts | 14 -------------- packages/pdfjs-viewer/src/persistence.ts | 2 ++ 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/file/Pdf.tsx b/apps/client/src/widgets/type_widgets/file/Pdf.tsx index fcce704cf..f254e13c4 100644 --- a/apps/client/src/widgets/type_widgets/file/Pdf.tsx +++ b/apps/client/src/widgets/type_widgets/file/Pdf.tsx @@ -99,7 +99,7 @@ function useStyleInjection(iframeRef: RefObject) { function getRootCssVariables() { const styles = getComputedStyle(document.documentElement); - const vars = {}; + const vars: Record = {}; for (let i = 0; i < styles.length; i++) { const prop = styles[i]; @@ -111,7 +111,7 @@ function getRootCssVariables() { return vars; } -function cssVarsToString(vars) { +function cssVarsToString(vars: Record) { return `:root {\n${Object.entries(vars) .map(([k, v]) => ` ${k}: ${v};`) .join('\n')}\n}`; diff --git a/packages/pdfjs-viewer/src/custom.ts b/packages/pdfjs-viewer/src/custom.ts index 99f66c26b..39f588119 100644 --- a/packages/pdfjs-viewer/src/custom.ts +++ b/packages/pdfjs-viewer/src/custom.ts @@ -1,9 +1,6 @@ import interceptPersistence from "./persistence"; -const LOG_EVENT_BUS = false; - async function main() { - console.log("Hi"); interceptPersistence(getCustomAppOptions()); // Wait for the PDF viewer application to be available. @@ -66,15 +63,4 @@ function manageSave() { }); } -function patchEventBus() { - const eventBus = window.PDFViewerApplication.eventBus; - const originalDispatch = eventBus.dispatch.bind(eventBus); - - eventBus.dispatch = (type: string, data?: any) => { - console.log("PDF.js event:", type, data); - return originalDispatch(type, data); - }; -} - main(); -console.log("Custom script loaded"); diff --git a/packages/pdfjs-viewer/src/persistence.ts b/packages/pdfjs-viewer/src/persistence.ts index a70671262..7f0110799 100644 --- a/packages/pdfjs-viewer/src/persistence.ts +++ b/packages/pdfjs-viewer/src/persistence.ts @@ -1,4 +1,6 @@ export default function interceptViewHistory(customOptions?: object) { + // We need to monkey-patch the localStorage used by PDF.js to store view history. + // Other attempts to intercept the history saving/loading (like overriding methods on PDFViewerApplication) have failed. const originalSetItem = Storage.prototype.setItem; Storage.prototype.setItem = function (key: string, value: string) { if (key === "pdfjs.history") {