diff --git a/apps/client/src/types-pdfjs.d.ts b/apps/client/src/types-pdfjs.d.ts index 54a440f16..13cb91f6e 100644 --- a/apps/client/src/types-pdfjs.d.ts +++ b/apps/client/src/types-pdfjs.d.ts @@ -1,3 +1,15 @@ interface Window { + /** + * By default, pdf.js will try to store information about the opened PDFs such as zoom and scroll position in local storage. + * The Trilium alternative is to use attachments stored at note level. + * This variable represents the direct content used by the pdf.js viewer in its local storage key, but in plain JS object format. + * The variable must be set early at startup, before pdf.js fully initializes. + */ TRILIUM_VIEW_HISTORY_STORE?: object; + + /** + * If set to true, hides the pdf.js viewer default sidebar containing the outline, page navigation, etc. + * This needs to be set early in the main method. + */ + TRILIUM_HIDE_SIDEBAR?: boolean; } diff --git a/apps/client/src/widgets/note_types.tsx b/apps/client/src/widgets/note_types.tsx index a6b3feb27..76142b7af 100644 --- a/apps/client/src/widgets/note_types.tsx +++ b/apps/client/src/widgets/note_types.tsx @@ -4,7 +4,8 @@ */ import { NoteType } from "@triliumnext/commons"; -import { VNode, type JSX } from "preact"; +import { type JSX,VNode } from "preact"; + import { TypeWidgetProps } from "./type_widgets/type_widget"; /** @@ -13,7 +14,7 @@ import { TypeWidgetProps } from "./type_widgets/type_widget"; */ export type ExtendedNoteType = Exclude | "empty" | "readOnlyCode" | "readOnlyText" | "editableText" | "editableCode" | "attachmentDetail" | "attachmentList" | "protectedSession" | "aiChat"; -export type TypeWidget = ((props: TypeWidgetProps) => VNode | JSX.Element); +export type TypeWidget = ((props: TypeWidgetProps) => VNode | JSX.Element | undefined); type NoteTypeView = () => (Promise<{ default: TypeWidget } | TypeWidget> | TypeWidget); interface NoteTypeMapping { diff --git a/packages/pdfjs-viewer/src/pages.ts b/packages/pdfjs-viewer/src/pages.ts index e63c234b9..67896e256 100644 --- a/packages/pdfjs-viewer/src/pages.ts +++ b/packages/pdfjs-viewer/src/pages.ts @@ -64,7 +64,7 @@ async function generateThumbnail(pageNumber: number) { // Render page to canvas await page.render({ - canvasContext: context, + canvas: canvas, viewport: viewport }).promise; diff --git a/packages/pdfjs-viewer/src/toc.ts b/packages/pdfjs-viewer/src/toc.ts index eca3d7da8..ddc2db707 100644 --- a/packages/pdfjs-viewer/src/toc.ts +++ b/packages/pdfjs-viewer/src/toc.ts @@ -126,7 +126,6 @@ export function setupActiveHeadingTracking() { function updateActiveHeading() { if (!headingPositions || headingPositions.length === 0) return; - const currentPage = app.page - 1; // PDF.js uses 1-based, we need 0-based const viewer = app.pdfViewer; const container = viewer.container; const scrollTop = container.scrollTop; diff --git a/packages/pdfjs-viewer/src/typings.d.ts b/packages/pdfjs-viewer/src/typings.d.ts index 9370df20a..50ac44fc0 100644 --- a/packages/pdfjs-viewer/src/typings.d.ts +++ b/packages/pdfjs-viewer/src/typings.d.ts @@ -14,10 +14,32 @@ declare global { _readFromStorage: () => Promise; } + interface PdfJsDestination { + + } + interface Window { PDFViewerApplication?: { initializedPromise: Promise; pdfDocument: PDFDocumentProxy; + pdfViewer: { + currentPageNumber: number; + optionalContentConfigPromise: { + setVisibility(groupId: string, visible: boolean); + getGroup(groupId: string): { + name: string; + usage: {}; + }; + getOrder(): {}[] + }; + getPageView(pageIndex: number): { + div: HTMLDivElement; + }; + container: HTMLElement; + }; + pdfLinkService: { + goToDestination(dest: PdfJsDestination); + }; eventBus: { on(event: string, listener: (...args: any[]) => void): void; dispatch(event: string, data?: any): void;