chore(pdfjs): fix typecheck issues

This commit is contained in:
Elian Doran 2025-12-31 17:00:56 +02:00
parent 94204b4739
commit 0ff4756ef4
No known key found for this signature in database
5 changed files with 38 additions and 4 deletions

View File

@ -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;
}

View File

@ -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<NoteType, "launcher" | "text" | "code"> | "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 {

View File

@ -64,7 +64,7 @@ async function generateThumbnail(pageNumber: number) {
// Render page to canvas
await page.render({
canvasContext: context,
canvas: canvas,
viewport: viewport
}).promise;

View File

@ -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;

View File

@ -14,10 +14,32 @@ declare global {
_readFromStorage: () => Promise<string>;
}
interface PdfJsDestination {
}
interface Window {
PDFViewerApplication?: {
initializedPromise: Promise<void>;
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;