/** * Worker Proxy - Main thread interface for the Docxodus Web Worker * * This module provides a Promise-based API that mirrors the main API but * executes all WASM operations in a Web Worker, keeping the main thread free. * * @example * ```typescript * import { createWorkerDocxodus } from 'docxodus/worker'; * * // Create worker instance * const docxodus = await createWorkerDocxodus(); * * // Use the same API as the main module, but non-blocking! * const html = await docxodus.convertDocxToHtml(docxFile); * * // Clean up when done * docxodus.terminate(); * ``` */ import type { WorkerDocxodusOptions, ConversionOptions, CompareOptions, GetRevisionsOptions, Revision, VersionInfo, DocumentMetadata, DocxSessionSettings, DocumentAnnotation, AnnotationUpdate, CharSpan, EditResult } from "./types.js"; /** * A worker-proxied DocxSession. Mirrors the main-thread {@link DocxSession} * annotation write surface but each call returns a Promise, since the actual * work happens inside the Web Worker. * * Acquire via {@link WorkerDocxodus.openDocxSession}; always call * {@link close} when finished to free the in-worker handle. */ export interface WorkerDocxSession { /** * Add an annotation to the document at the given anchor. * @param anchorId - Markdown-projection anchor id of the target block * @param span - Character span within the block, or null for the whole block * @param annotation - Annotation data (id auto-generated if omitted) * @returns EditResult indicating success and any created/modified anchors */ addAnnotation(anchorId: string, span: CharSpan | null, annotation: DocumentAnnotation): Promise; /** * Remove an existing annotation by its id. * @param annotationId - The annotation id to remove * @returns EditResult indicating success */ removeAnnotation(annotationId: string): Promise; /** * Partially update an annotation's metadata without moving it. * @param annotationId - The annotation id to update * @param update - Fields to change (omitted fields are left unchanged) * @returns EditResult indicating success */ updateAnnotation(annotationId: string, update: AnnotationUpdate): Promise; /** * Move an annotation to a new anchor/span position. * @param annotationId - The annotation id to move * @param newAnchorId - Target anchor id * @param newSpan - New character span, or null for the whole block * @returns EditResult indicating success */ moveAnnotation(annotationId: string, newAnchorId: string, newSpan: CharSpan | null): Promise; /** * Close the session and release its in-worker handle. * After calling this, the instance cannot be used anymore. */ close(): Promise; } /** * A worker-based Docxodus instance. * * Provides the same API as the main module but executes all operations * in a Web Worker for non-blocking UI. */ export interface WorkerDocxodus { /** * Convert a DOCX document to HTML. * @param document - DOCX file as File object or Uint8Array * @param options - Conversion options * @returns HTML string */ convertDocxToHtml(document: File | Uint8Array, options?: ConversionOptions): Promise; /** * Compare two DOCX documents and return the redlined result. * @param original - Original DOCX document * @param modified - Modified DOCX document * @param options - Comparison options * @returns Redlined DOCX as Uint8Array */ compareDocuments(original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions): Promise; /** * Compare two DOCX documents and return the result as HTML. * @param original - Original DOCX document * @param modified - Modified DOCX document * @param options - Comparison options * @returns HTML string with redlined content */ compareDocumentsToHtml(original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions): Promise; /** * Get revisions from a compared document. * @param document - A document that has tracked changes * @param options - Revision extraction options * @returns Array of revisions */ getRevisions(document: File | Uint8Array, options?: GetRevisionsOptions): Promise; /** * Get document metadata for lazy loading pagination. * This is a fast operation that extracts structure without full HTML rendering. * @param document - DOCX file as File object or Uint8Array * @returns Document metadata including sections, dimensions, and content counts */ getDocumentMetadata(document: File | Uint8Array): Promise; /** * Get version information about the library. * @returns Version information */ getVersion(): Promise; /** * Pre-warm the comparison code path. * * The 10s runtime warmup paid by {@link createWorkerDocxodus} does not load * the comparison assemblies — the .NET WASM runtime defers * `Docxodus.*.wasm` and its `System.*.wasm` dependents until the first * {@link compareDocuments} call, which then costs ~3s of pure assembly-load * latency. Call `prepare()` after creating the worker to pay that cost ahead * of any user action; once it resolves, the next {@link compareDocuments} * (or {@link compareDocumentsToHtml}) triggers no further `.wasm` fetches. * * Semantics: * - **Idempotent.** Repeated calls share one in-flight warmup and resolve * immediately once it has completed. * - **No caller IO.** No seed files to fetch, no inputs to construct — the * seed documents are built inside the worker. * - **Concurrent-safe.** `prepare()` and `compareDocuments()` may be called * in any order; a `compareDocuments()` issued while a `prepare()` is in * flight does not double-load assemblies. * * @returns A Promise that resolves when the comparison path is fully hot. */ prepare(): Promise; /** * Open a {@link WorkerDocxSession} for surgical annotation editing inside * the worker. The document bytes are transferred to the worker (zero-copy). * * Always call {@link WorkerDocxSession.close} when you are done to release * the in-worker session handle. * * @param document - DOCX file as File or Uint8Array * @param settings - Optional session settings * @returns A proxied session whose methods are off-main-thread */ openDocxSession(document: File | Uint8Array, settings?: DocxSessionSettings): Promise; /** * Terminate the worker. * After calling this, the instance cannot be used anymore. */ terminate(): void; /** * Check if the worker is still active. */ isActive(): boolean; } /** * Create a worker-based Docxodus instance. * * This function spawns a Web Worker that loads the WASM runtime independently. * All operations are executed in the worker, keeping the main thread responsive. * * @param options - Configuration options * @returns A Promise that resolves to a WorkerDocxodus instance * * @example * ```typescript * // Basic usage * const docxodus = await createWorkerDocxodus(); * const html = await docxodus.convertDocxToHtml(docxFile); * * // With custom WASM path * const docxodus = await createWorkerDocxodus({ * wasmBasePath: '/assets/wasm/' * }); * ``` */ export declare function createWorkerDocxodus(options?: WorkerDocxodusOptions): Promise; /** * Check if Web Workers are supported in the current environment. */ export declare function isWorkerSupported(): boolean; //# sourceMappingURL=worker-proxy.d.ts.map