/**
 * Low-level client for communicating with the UDoc worker.
 *
 * Provides a Promise-based API for document operations.
 * Also handles render queue, cache, and priority management.
 * This is an internal API - use UDocClient for the public SDK.
 */
import type { Annotation, AnnotationsByPage, Composition, ComposePick, ExtractedFont, ExtractedImage, FontEntry, FontUsageEntry, LayoutPage, LicenseResult, OutlineItem, PageGroup, PageGroupLayout, PageTransition, OutlineSection, SplitByOutlineResult, VisibilityGroup } from "./worker.js";
import type { JsOrientation as Orientation, JsSideDirection as SideDirection, JsCornerDirection as CornerDirection, JsEightDirection as EightDirection, JsInOutDirection as InOutDirection, JsTransitionEffect as TransitionEffect, JsFontSource as FontSource, JsResolvedFontInfo as ResolvedFontInfo, JsLayoutFrame as LayoutFrame, JsLayoutParcel as LayoutParcel, JsLayoutLine as LayoutLine, JsLayoutRun as LayoutRun, JsLayoutRunList as LayoutRunList, JsLayoutRunContent as LayoutRunContent, JsLayoutLineContent as LayoutLineContent, JsLayoutTable as LayoutTable, JsLayoutTableRow as LayoutTableRow, JsLayoutTableCell as LayoutTableCell, JsLayoutTableColumn as LayoutTableColumn, JsLayoutGrid as LayoutGrid, JsLayoutGridRow as LayoutGridRow, JsLayoutGridCell as LayoutGridCell, JsLayoutGridColumn as LayoutGridColumn, JsLayoutGlyph as LayoutGlyph, JsTransform as Transform } from "../wasm/udoc.js";
export type { Annotation, AnnotationsByPage, Composition, ComposePick, ExtractedFont, ExtractedImage, FontEntry, OutlineItem, OutlineSection, PageGroup, PageGroupLayout, SplitByOutlineResult, VisibilityGroup, };
export type { LicenseResult };
export type { Orientation, SideDirection, CornerDirection, EightDirection, InOutDirection, TransitionEffect, PageTransition, };
export type { FontSource, ResolvedFontInfo, FontUsageEntry };
export type { LayoutPage, LayoutFrame, LayoutParcel, LayoutLine, LayoutRun, LayoutRunList, LayoutRunContent, LayoutLineContent, LayoutTable, LayoutTableRow, LayoutTableCell, LayoutTableColumn, LayoutGrid, LayoutGridRow, LayoutGridCell, LayoutGridColumn, LayoutGlyph, Transform, };
/**
 * Font information extracted from raw font binary data.
 */
export interface FontInfo {
    /** Font typeface/family name (e.g., "Roboto", "Arial") */
    typeface: string;
    /** Whether the font is bold */
    bold: boolean;
    /** Whether the font is italic */
    italic: boolean;
}
export interface PageInfo {
    width: number;
    height: number;
    /** Document rotation in degrees (0, 90, 180, or 270) */
    rotation: 0 | 90 | 180 | 270;
    /** Slide transition (PPTX only) */
    transition?: PageTransition;
    /** Content area for continuous mode cropping (DOCX body bounds, XLSX grid area).
     * Absent for PDF/PPTX where the full page is the content. */
    contentRect?: {
        x: number;
        y: number;
        width: number;
        height: number;
    };
    /** Tile position in a 2D page grid (XLSX only).
     * Absent for linear formats (PDF, PPTX, DOCX). */
    tilePos?: {
        row: number;
        col: number;
    };
}
export type RenderType = "page" | "thumbnail" | "preview";
export interface RenderRequest {
    docId: string;
    page: number;
    type: RenderType;
    scale: number;
}
export interface RenderCacheBucket {
    count: number;
    bytes: number;
}
export interface RenderCacheStats {
    page: RenderCacheBucket;
    thumbnail: RenderCacheBucket;
    preview: RenderCacheBucket;
    total: RenderCacheBucket;
}
export interface RenderResult {
    bitmap: ImageBitmap;
    width: number;
    height: number;
}
import type { IPerformanceCounter } from "../performance/index.js";
/**
 * Generate a cache key for render requests.
 * Uses toFixed(4) for scale to normalize floating-point variations.
 * Exported so Spread component can use the same key format.
 */
export declare function makeRenderKey(docId: string, page: number, type: RenderType, scale: number): string;
export declare class WorkerClient {
    private worker;
    private requestId;
    private pending;
    private pageRenderCache;
    private thumbnailRenderCache;
    private previewRenderCache;
    private workQueue;
    private currentWork;
    private maxPageCacheBytes;
    private maxThumbnailCacheSize;
    private maxPreviewCacheSize;
    private pageFocus;
    private thumbnailFocus;
    private renderInvalidatedCallbacks;
    private oomCallbacks;
    private lastOOMClearAt;
    private fontUsageChangedCallbacks;
    private lastFontUsageLength;
    private performanceCounters;
    private pageInfoCache;
    private pageGroupsCache;
    private constructor();
    /**
     * Create a WorkerClient using the inline bundled worker.
     * Creates a blob worker from the build-time inlined source code,
     * avoiding import.meta.url for universal bundler compatibility.
     *
     * Falls back to module worker via import.meta.url when WORKER_INLINE
     * is empty (e.g. running from TypeScript source in Vite dev mode).
     */
    static create(): WorkerClient;
    /**
     * Create a WorkerClient with a custom worker URL.
     * Use this when hosting worker files at a custom location.
     */
    static createWithUrl(workerUrl: string | URL): WorkerClient;
    /**
     * Initialize the WASM module.
     */
    init(wasmUrl: string | undefined, gpu: boolean | undefined, domain: string, viewerVersion: string): Promise<void>;
    /**
     * Set the anonymous distinct ID for telemetry tracking.
     */
    setupTelemetry(distinctId: string): Promise<void>;
    /**
     * Disable telemetry reporting. Requires a license with the "no_telemetry" feature.
     * @returns true if telemetry was disabled, false if the license does not permit it.
     */
    disableTelemetry(): Promise<boolean>;
    /**
     * Set the license key.
     * @param license - The license key string
     * @param domain - The current domain (from window.location.hostname)
     * @returns License validation result
     */
    setLicense(license: string, domain: string): Promise<LicenseResult>;
    /**
     * Get current license status.
     */
    getLicenseStatus(): Promise<LicenseResult>;
    /**
     * Load a PDF document.
     * @returns The document ID.
     */
    /**
     * Load a document with auto-format detection.
     * The WASM engine inspects the file contents to determine the format.
     * @returns The document ID.
     */
    loadDocument(bytes: Uint8Array): Promise<string>;
    /**
     * Get the detected format of a loaded document.
     * @returns The format string: "pdf", "docx", "pptx", "xlsx", or "image".
     */
    getDocumentFormat(documentId: string): Promise<string>;
    loadPdf(bytes: Uint8Array): Promise<string>;
    /**
     * Load an image file.
     * Supports various formats: JPEG, PNG, GIF, BMP, TIFF, WebP, etc.
     * Multi-page TIFF files will create a document with multiple pages.
     * @returns The document ID.
     */
    loadImage(bytes: Uint8Array): Promise<string>;
    /**
     * Load a PPTX (PowerPoint) document.
     * @returns The document ID.
     */
    loadPptx(bytes: Uint8Array): Promise<string>;
    /**
     * Load a DOCX (Word) document.
     * @returns The document ID.
     */
    loadDocx(bytes: Uint8Array): Promise<string>;
    /**
     * Unload a PDF document.
     * @returns True if the document was removed.
     */
    unloadPdf(documentId: string): Promise<boolean>;
    /**
     * Check if a document requires a password to open.
     * @returns True if the document needs authentication.
     */
    needsPassword(documentId: string): Promise<boolean>;
    /**
     * Authenticate with a password to unlock an encrypted document.
     * @param documentId - The document ID
     * @param password - The password to try
     * @returns True if authentication succeeded, false if the password was incorrect.
     */
    authenticate(documentId: string, password: string): Promise<boolean>;
    /**
     * Get the page count of a document.
     * Returns from cache if available.
     */
    getPageCount(documentId: string): Promise<number>;
    /**
     * Get info for a single page.
     * Returns from cache if available (populated by getAllPageInfo).
     */
    getPageInfo(documentId: string, pageIndex: number): Promise<PageInfo>;
    /**
     * Get info for all pages in one call.
     * Results are cached for subsequent calls.
     */
    getAllPageInfo(documentId: string): Promise<PageInfo[]>;
    /**
     * Get stitching groups for a document (one `linear` group for PDF/DOCX/PPTX,
     * one `tiled` group per sheet for XLSX). Results are cached.
     */
    getPageGroups(documentId: string): Promise<PageGroup[]>;
    /**
     * Get the document outline.
     */
    getOutline(documentId: string): Promise<OutlineItem[]>;
    /**
     * Get font usage information for a document.
     */
    getFontUsage(documentId: string): Promise<FontUsageEntry[]>;
    /**
     * Get annotations for a specific page.
     * Routed through the unified work queue so renders take priority.
     */
    getPageAnnotations(documentId: string, pageIndex: number): Promise<Annotation[]>;
    /**
     * Get the layout model for a specific page (for text selection/search).
     * Routed through the unified work queue so renders take priority.
     */
    getLayoutPage(documentId: string, pageIndex: number): Promise<LayoutPage>;
    /**
     * Request annotations via the unified work queue.
     * Lower priority than renders — waits for pending renders to complete first.
     */
    requestAnnotations(docId: string, pageIndex: number): Promise<Annotation[]>;
    /**
     * Request text content via the unified work queue.
     * Lowest priority — waits for pending renders and annotations to complete first.
     */
    requestText(docId: string, pageIndex: number): Promise<LayoutPage>;
    /**
     * Get all annotations grouped by page.
     */
    getAllAnnotations(documentId: string): Promise<AnnotationsByPage>;
    /**
     * Save annotations to a PDF document.
     * Returns the modified PDF bytes with annotations applied.
     */
    pdfSaveAnnotations(documentId: string, annotationsByPage: AnnotationsByPage): Promise<Uint8Array>;
    /**
     * Compose new PDF documents by cherry-picking pages from source documents.
     *
     * @param compositions - Array of compositions. Each composition is an array of picks
     *   that will form one output document.
     * @param docIds - Array of document IDs to use as sources (order matters for doc indices)
     * @returns Array of new document IDs (one per composition)
     */
    pdfCompose(compositions: Composition[], docIds: string[]): Promise<string[]>;
    /**
     * Split a PDF document by its outline (bookmarks) structure.
     *
     * @param documentId - Document ID to split
     * @param maxLevel - Maximum outline level to consider (1 = top level only)
     * @param splitMidPage - When true, filters page content when sections share a page
     * @returns Object with documentIds and sections
     */
    pdfSplitByOutline(documentId: string, maxLevel: number, splitMidPage?: boolean): Promise<SplitByOutlineResult>;
    /**
     * Extract all embedded images from a PDF document.
     *
     * @param documentId - Document ID to extract images from
     * @param convertRawToPng - When true, converts raw pixel data to PNG format
     * @returns Array of extracted images with metadata and data
     */
    pdfExtractImages(documentId: string, convertRawToPng?: boolean): Promise<ExtractedImage[]>;
    /**
     * Extract all embedded fonts from a PDF document.
     *
     * @param documentId - Document ID to extract fonts from
     * @returns Array of extracted fonts with metadata and data
     */
    /**
     * Parse font information from raw font binary data.
     *
     * @param data - Raw font binary data (e.g., .ttf, .otf, .woff2)
     * @returns Font information including typeface, bold, and italic
     */
    parseFontInfo(data: Uint8Array): Promise<FontInfo>;
    pdfExtractFonts(documentId: string): Promise<ExtractedFont[]>;
    /**
     * Compress a PDF document.
     *
     * Saves the document with full compression options enabled.
     *
     * @param documentId - Document ID to compress
     * @returns Compressed PDF data
     */
    pdfCompress(documentId: string): Promise<Uint8Array>;
    /**
     * Decompress a PDF document.
     *
     * Removes all filter encodings from streams, resulting in raw,
     * uncompressed stream data.
     *
     * @param documentId - Document ID to decompress
     * @returns Decompressed PDF data
     */
    pdfDecompress(documentId: string): Promise<Uint8Array>;
    /**
     * Get the raw PDF bytes of a document.
     */
    getBytes(documentId: string): Promise<Uint8Array>;
    /**
     * Register font URLs.
     *
     * The engine fetches fonts on-demand during layout from the provided URLs.
     * Call this before loading documents. Registered fonts take priority over
     * Google Fonts.
     *
     * @param fonts - Array of font entries with typeface, style, and URL
     */
    registerFonts(fonts: FontEntry[]): Promise<void>;
    /**
     * Enable Google Fonts.
     *
     * When enabled, fonts not embedded in the document are fetched from
     * Google Fonts on-demand during rendering. Google Fonts are resolved
     * after any URL fonts registered via `registerFonts`.
     *
     * Call this before loading documents.
     */
    enableGoogleFonts(): Promise<void>;
    /**
     * Get visibility groups for a document.
     */
    getVisibilityGroups(documentId: string): Promise<VisibilityGroup[]>;
    /**
     * Set visibility of a specific group.
     *
     * @returns true if the group was found and updated
     */
    setVisibilityGroupVisible(documentId: string, groupId: string, visible: boolean): Promise<boolean>;
    /**
     * Set the performance counter for a document.
     * All operations for this document will be tracked.
     */
    setPerformanceCounter(docId: string, counter: IPerformanceCounter): void;
    /**
     * Remove the performance counter for a document.
     */
    removePerformanceCounter(docId: string): void;
    private getCounter;
    private getCache;
    private getMaxCacheSize;
    private cacheTotalBytes;
    /**
     * Request a render. Returns cached result if available,
     * otherwise queues the request.
     *
     * When a new request is queued, it cancels any existing queued requests
     * for the same page index and render type (but not in-flight requests).
     */
    requestRender(req: RenderRequest): Promise<RenderResult>;
    /**
     * Cancel queued requests for a specific page (within the same render type).
     * Does not cancel in-flight requests.
     */
    private cancelQueuedRequestsForPage;
    /**
     * Get a cached result without queuing a render.
     */
    getCachedRender(docId: string, page: number, type: RenderType, scale: number): RenderResult | null;
    /**
     * Cancel pending render requests matching criteria.
     * Does not cancel in-flight requests.
     */
    cancelRenders(docId?: string, page?: number, type?: RenderType): void;
    /**
     * Invalidate cache entries. Call when document or zoom changes.
     */
    /**
     * Clear cached bitmaps without notifying UI callbacks.
     * Use during document close to avoid triggering re-renders.
     */
    clearRenderCache(docId?: string): void;
    invalidateRenderCache(docId?: string, type?: RenderType): void;
    /**
     * Subscribe to render cache invalidation events.
     * Returns an unsubscribe function.
     */
    onRenderInvalidated(callback: () => void): () => void;
    /**
     * Subscribe to render OOM events. Fired after caches are cleared so UIs
     * can surface a warning or trigger quality degradation.
     */
    onOOM(callback: (error: Error) => void): () => void;
    /**
     * Current WASM linear-memory size in bytes (reflects every `memory.grow`).
     * Returns 0 if the worker has not finished initializing yet.
     */
    getWasmMemoryBytes(): Promise<number>;
    /**
     * Return a snapshot of cached bitmap counts and estimated memory (bytes).
     * Estimated as width * height * 4 (RGBA) per ImageBitmap.
     */
    getRenderCacheStats(): RenderCacheStats;
    /**
     * Drop every cached ImageBitmap to free memory, then notify OOM subscribers.
     * Throttled so a burst of failures doesn't produce a cache-clear storm.
     */
    private handleOOM;
    /**
     * Subscribe to font usage change events.
     * Called when font usage changes after a page render.
     * Returns an unsubscribe function.
     */
    onFontUsageChanged(callback: (docId: string) => void): () => void;
    /**
     * Enqueue a font usage check at the end of the work queue.
     * Deduplicates: only one check per docId is queued at a time.
     */
    private scheduleFontUsageCheck;
    private doFontUsageCheck;
    /**
     * Sort page render requests in the queue by distance to the focused page.
     * Updates the page focus and re-sorts the queue.
     */
    boostPageRenderPriority(docId: string, focusPage: number): void;
    /**
     * Sort thumbnail render requests in the queue by distance to the focused thumbnail.
     * Updates the thumbnail focus and re-sorts the queue.
     */
    boostThumbnailRenderPriority(docId: string, focusPage: number): void;
    private static readonly PRERENDER_RANGE;
    /**
     * Prerender adjacent pages for smooth page flipping in single spread mode.
     * Queues renders for pages before and after the current page (fire and forget).
     * Boosts current page priority so it renders first during rapid flipping.
     */
    prerenderAdjacentPages(docId: string, currentPage: number, scale: number, totalPages: number): void;
    /**
     * Render a page directly, bypassing the cache and queue.
     * Useful for one-off renders that shouldn't affect the normal render flow.
     */
    forceRender(req: RenderRequest): Promise<RenderResult>;
    private static readonly BOOST_RANGE;
    /**
     * Sort work queue by priority: page-proximity first, then type within each page.
     *
     * For page-focused items (pages, previews, annotations, text):
     *   Grouped by distance to pageFocus, closest first. Within each page,
     *   ordered: preview → page render → annotation → text.
     *   Boosted pages (within BOOST_RANGE) come before all non-boosted pages.
     *
     * Thumbnails use thumbnailFocus independently and come after all page items.
     */
    private sortQueue;
    /**
     * Clean up render resources.
     */
    destroyRenderResources(): void;
    private processWorkQueue;
    private doRender;
    private doAnnotation;
    private doText;
    private addToRenderCache;
    private evictLRU;
    /**
     * Terminate the worker.
     */
    terminate(): void;
    private send;
    private handleMessage;
    private handleError;
}
//# sourceMappingURL=WorkerClient.d.ts.map