import type { DownloadInfo, LoadProgress, OutlineItem, PageContent, PageRequest, Source } from '@zinejs/core'; /** Minimal shapes of the pdf.js API we rely on (avoids a hard type dependency). */ interface PdfPageLike { getViewport(opts: { scale: number; }): { width: number; height: number; }; /** `transform` is an affine matrix applied before painting, used to offset a cropped tile. */ render(opts: { canvasContext: unknown; viewport: unknown; transform?: number[]; }): { promise: Promise; }; /** Optional: absent on scanned PDFs with no text layer, and on hand-rolled document stubs. */ getTextContent?(): Promise<{ items: { str?: string; hasEOL?: boolean; }[]; }>; } /** A pdf.js outline entry. `dest` is either a named destination or an explicit array whose first * element references the target page. */ interface PdfOutlineNode { title?: string; dest?: string | unknown[] | null; items?: PdfOutlineNode[]; } interface PdfDocumentLike { numPages: number; getPage(pageNumber: number): Promise; destroy?(): void; /** Optional: absent on documents without a table of contents, and on hand-rolled stubs. */ getOutline?(): Promise; getDestination?(id: string): Promise; getPageIndex?(ref: unknown): Promise; } /** A URL, raw bytes, or a pre-created pdf.js document. */ export type PdfSrc = string | ArrayBuffer | Uint8Array | PdfDocumentLike; export interface PdfSourceOptions { /** URL to pdf.js's worker. Optional: auto-resolved from your bundler (`?url` / `new URL`) or * `pdfjs-dist` install, then a version-matched CDN when `cdnFallback` is true. Pass it for * CDN / UMD / CSP / offline, or if auto-resolve fails. */ workerSrc?: string; /** Allow falling back to a version-matched jsDelivr worker when no local worker can be * resolved (no bundler rewrite, no reachable install). Default true. Set false for * CSP-restricted or offline apps, where a network worker would fail opaquely — you must * then pass `workerSrc` (or set GlobalWorkerOptions.workerSrc). */ cdnFallback?: boolean; /** Base render scale; each page is rasterized at `renderScale × devicePixelRatio`. Default 1. */ renderScale?: number; /** How many adjacent pages to prefetch around a requested page. Default 1. */ preload?: number; /** Soft cap on cached page bytes; least-recently-used pages evict beyond it. Default ~256 MB. */ maxCacheBytes?: number; /** Paint a low-res page first, then swap to crisp (faster first paint). Default false. */ progressive?: boolean; /** Ask pdf.js to fetch only the byte ranges visible pages need (range-capable servers). Default false. */ disableAutoFetch?: boolean; /** * Load pdf.js's legacy build (transpiled with polyfills) instead of the modern one. The legacy * build runs on both old and modern browsers; the modern build is smaller and a touch faster but * needs a recent engine. Default true, favouring reach. Set false to serve the lean modern build * when your audience is on current browsers. Ignored when a pre-created pdf.js document or a * global `pdfjsLib` is supplied — those already picked their build. */ legacy?: boolean; } /** * Renders PDF pages to canvases for zinejs. pdf.js is a dependency of this * package, loaded lazily so it never lands in the core bundle. Async — pass it * to `new Zine`, which calls `open()` (learning the page count) before building * spreads. */ export declare class PdfSource implements Source { #private; pageCount: number; constructor(src: PdfSrc, options?: PdfSourceOptions); /** Register a handler called when a page upgrades from its progressive low-res pass to crisp. */ onPageUpdate(handler: (index: number) => void): void; /** Register a handler called as the document downloads, driving a loading indicator. */ onProgress(handler: (progress: LoadProgress) => void): void; open(): Promise; get(index: number, opts?: PageRequest): Promise; prefetch(indices: number[]): void; /** * The page's text, for search. Empty for a page with no text layer (a scan, or a pdf.js build * without text extraction) — callers treat that as "nothing to match" rather than an error. */ getText(index: number): Promise; /** * The document's table of contents, flattened into the shape the outline panel wants. * * Empty when the PDF has no outline, which is common. Destinations are resolved to page * indices here rather than in the UI: doing it once, up front, keeps clicking an entry * instant, and an entry whose destination cannot be resolved is kept with a null page so the * heading still shows. */ getOutline(): Promise; /** * The original PDF, for a download control. * * Null when the source was handed a pre-opened pdf.js document: the bytes belong to whoever * created it, and re-fetching them is not this class's call to make. */ getDownload(): Promise; destroy(): void; } export {};