diff --git a/package-lock.json b/package-lock.json index ad6e48ec01a28..5d501da2e9d50 100644 --- a/package-lock.json +++ b/package-lock.json @@ -64,7 +64,7 @@ "yargs": "^17.7.2" }, "engines": { - "node": ">=20" + "node": ">=22" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index 1478dbc10ffc0..3c86d2b6cd920 100644 --- a/package.json +++ b/package.json @@ -60,10 +60,13 @@ }, "repository": { "type": "git", - "url": "git://github.com/mozilla/pdf.js.git" + "url": "git://github.com/edrlab/pdf.js.git" }, "engines": { - "node": ">=20" + "node": ">=22" + }, + "scripts": { + "build": "npx gulp web && npx gulp types" }, "license": "Apache-2.0" } diff --git a/web/app.js b/web/app.js index 82fa056801e7c..5e50eb9a42a47 100644 --- a/web/app.js +++ b/web/app.js @@ -259,6 +259,8 @@ const PDFViewerApplication = { this._initializedCapability.settled = true; this._initializedCapability.resolve(); + // THORIUM_BUILD + this.eventBus.dispatch("__ready"); }, /** @@ -376,15 +378,18 @@ const PDFViewerApplication = { async _initializeViewerComponents() { const { appConfig, externalServices, l10n } = this; - const eventBus = - typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL") - ? new FirefoxEventBus( - AppOptions.get("allowedGlobalEvents"), - externalServices, - AppOptions.get("isInAutomation") - ) - : new EventBus(); - this.eventBus = AppOptions.eventBus = eventBus; + // THORIUM_BUILD + // const eventBus = + // typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL") + // ? new FirefoxEventBus( + // AppOptions.get("allowedGlobalEvents"), + // externalServices, + // AppOptions.get("isInAutomation") + // ) + // : new EventBus(); + console.log("PDFJS EVENT BUS FOUND:",!!window.pdfjsEventBus); + const eventBus = window.pdfjsEventBus || new EventBus(); + this.eventBus = AppOptions.eventBus = eventBus this.mlManager?.setEventBus(eventBus, this._globalAbortController.signal); this.overlayManager = new OverlayManager(); @@ -1422,14 +1427,15 @@ const PDFViewerApplication = { this.pdfOutlineViewer.render({ outline, pdfDocument }); }); } - if (this.pdfAttachmentViewer) { - pdfDocument.getAttachments().then(attachments => { - if (pdfDocument !== this.pdfDocument) { - return; // The document was closed while the attachments resolved. - } - this.pdfAttachmentViewer.render({ attachments }); - }); - } + // THORIUM_BUILD + // if (this.pdfAttachmentViewer) { + // pdfDocument.getAttachments().then(attachments => { + // if (pdfDocument !== this.pdfDocument) { + // return; // The document was closed while the attachments resolved. + // } + // this.pdfAttachmentViewer.render({ attachments }); + // }); + // } if (this.pdfLayerViewer) { // Ensure that the layers accurately reflects the current state in the // viewer itself, rather than the default state provided by the API. @@ -1444,6 +1450,7 @@ const PDFViewerApplication = { this._initializePageLabels(pdfDocument); this._initializeMetadata(pdfDocument); + this.eventBus.dispatch("__pdfdocument", pdfDocument); }, /** @@ -1883,8 +1890,8 @@ const PDFViewerApplication = { eventBus._on("resize", onResize.bind(this), opts); eventBus._on("hashchange", onHashchange.bind(this), opts); - eventBus._on("beforeprint", this.beforePrint.bind(this), opts); - eventBus._on("afterprint", this.afterPrint.bind(this), opts); + // eventBus._on("beforeprint", this.beforePrint.bind(this), opts); + // eventBus._on("afterprint", this.afterPrint.bind(this), opts); eventBus._on("pagerender", onPageRender.bind(this), opts); eventBus._on("pagerendered", onPageRendered.bind(this), opts); eventBus._on("updateviewarea", onUpdateViewarea.bind(this), opts); @@ -1909,8 +1916,8 @@ const PDFViewerApplication = { evt => (pdfViewer.annotationEditorMode = evt), opts ); - eventBus._on("print", this.triggerPrinting.bind(this), opts); - eventBus._on("download", this.downloadOrSave.bind(this), opts); + // eventBus._on("print", this.triggerPrinting.bind(this), opts); + // eventBus._on("download", this.downloadOrSave.bind(this), opts); eventBus._on("firstpage", () => (this.page = 1), opts); eventBus._on("lastpage", () => (this.page = this.pagesCount), opts); eventBus._on("nextpage", () => pdfViewer.nextPage(), opts); @@ -1974,8 +1981,8 @@ const PDFViewerApplication = { ); if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { - eventBus._on("fileinputchange", onFileInputChange.bind(this), opts); - eventBus._on("openfile", onOpenFile.bind(this), opts); + // eventBus._on("fileinputchange", onFileInputChange.bind(this), opts); + // eventBus._on("openfile", onOpenFile.bind(this), opts); } if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { eventBus._on( @@ -1999,6 +2006,56 @@ const PDFViewerApplication = { opts ); } + + + // THORIUM_BUILD + const pageRenderedExtract = async (ev) => { + try { + if (ev.pageNumber === 1) { + const page = ev.source; + if (!page || !page.canvas) { + throw Error("PDF PAGE CANVAS??!"); + } + + // const img = page?.canvas?.toDataURL("image/png"); + const blob = await new Promise((res, _rej) => { + page.canvas.toBlob( + (blob) => { + res(blob); + }, + "image/png", + 0.95 + ); + }); + const img = await blob.arrayBuffer(); + + const doc = this.pdfDocument; + const metadata = await doc.getMetadata(); + const numberofpages = doc.numPages; + const numberOfPagesChecked = typeof numberofpages === "number" ? numberofpages : 0; + + // https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm + const data = { + ...metadata, + img, + numberofpages: numberOfPagesChecked, + }; + + // https://www.electronjs.org/docs/api/ipc-renderer#ipcrenderersendchannel-args + // const ipc = require('electron').ipcRenderer; + const ipc = window.electronIpcRenderer; + if (ipc) { + ipc.send("pdfjs-extract-data", data); + } + + eventBus._off("pagerendered", pageRenderedExtract); + } + } catch (e) { + console.log("ERROR TO EXTRACT COVER AND METADATA FROM PDF"); + console.log("ERROR", e); + } + }; + eventBus._on("pagerendered", pageRenderedExtract); }, bindWindowEvents() { @@ -2235,9 +2292,11 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { // Removing of the following line will not guarantee that the viewer will // start accepting URLs from foreign origin -- CORS headers on the remote // server must be properly configured. - if (fileOrigin !== viewerOrigin) { - throw new Error("file origin does not match viewer's"); - } + + // THORIUM_BUILD + // if (fileOrigin !== viewerOrigin) { + // throw new Error("file origin does not match viewer's"); + // } } catch (ex) { PDFViewerApplication._documentError("pdfjs-loading-error", { message: ex.message, diff --git a/web/pdf_print_service.js b/web/pdf_print_service.js index 45106ca30788b..08862e69fe250 100644 --- a/web/pdf_print_service.js +++ b/web/pdf_print_service.js @@ -382,7 +382,9 @@ class PDFPrintServiceFactory { } static get supportsPrinting() { - return shadow(this, "supportsPrinting", true); + // THORIUM_BUILD + // return shadow(this, "supportsPrinting", true); + return false; } static createPrintService(params) { diff --git a/web/viewer.css b/web/viewer.css index 3629d5eb2a514..90bcbcb1d5896 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -336,12 +336,13 @@ body { #viewerContainer { overflow: auto; position: absolute; - inset: var(--toolbar-height) 0 0; + inset: 0 0 0 0; outline: none; z-index: 0; } -#viewerContainer:not(.pdfPresentationMode) { +/* THORIUM_BUILD */ +/* #viewerContainer:not(.pdfPresentationMode) { transition-duration: var(--sidebar-transition-duration); transition-timing-function: var(--sidebar-transition-timing-function); } @@ -349,7 +350,7 @@ body { #outerContainer.sidebarOpen #viewerContainer:not(.pdfPresentationMode) { inset-inline-start: var(--sidebar-width); transition-property: inset-inline-start; -} +} */ #sidebarContainer :is(input, button, select) { font: message-box; diff --git a/web/viewer.html b/web/viewer.html index 1a8eb7f10dc13..f9ba395d0f460 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -1,4 +1,4 @@ - + PDF.js viewer + + + + @@ -98,7 +104,7 @@
-
+