/** * 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 { DeliverableVerificationRequest, ExternalAnnotationSet, ExternalAnnotationValidationResult, ExternalAnnotationProjectionSettings, OpenContractDocExport, WorkerDocxodusOptions, ConversionOptions, CompareOptions, DocxDiffSettings, RevisionListEntry, CommentListEntry, VersionInfo, DocumentMetadata, DocxSessionSettings, DocumentAnnotation, AnnotationUpdate, CharSpan, EditResult, PackageManifest, DeliverableVerificationResult, RedlineReversibilityProof, SemanticChangeSet, PackageManifestInspectionLimits, WorkerErrorCode } from "./types.js"; /** * Rejection carrying the worker's machine-readable cause. Callers classify failures with * {@link workerErrorCode}; `message` is diagnostic text whose wording is not a contract. */ export declare class WorkerOperationError extends Error { readonly code?: WorkerErrorCode; constructor(message: string, code?: WorkerErrorCode); } /** Reads a worker failure's machine-readable cause, or undefined for any other error. */ export declare function workerErrorCode(error: unknown): WorkerErrorCode | undefined; /** * 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 { /** Generate a deterministic manifest of the session's current logical checkpoint. */ getPackageManifest(): Promise; /** Run the default deliverable gate over the session's clean-save checkpoint. */ verifyDeliverable(request?: DeliverableVerificationRequest): Promise; /** Compare the current logical checkpoint with the exact opening package. */ getSemanticChanges(): Promise; /** * 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 { /** Generate a deterministic, non-mutating verification manifest. */ generatePackageManifest(document: File | Uint8Array, limits?: PackageManifestInspectionLimits): Promise; /** Generate the exact canonical manifest JSON for strict boundary validation. */ generatePackageManifestJson(document: File | Uint8Array, limits?: PackageManifestInspectionLimits): Promise; /** Derive an isolated final/original package; the source bytes remain caller-owned. */ projectReviewProfile(document: File | Uint8Array, profile: "final" | "original", maximumOutputBytes?: number): Promise; /** Run the default bounded deliverable gate, optionally against an exact baseline. */ verifyDeliverable(document: File | Uint8Array, baseline?: File | Uint8Array, request?: DeliverableVerificationRequest): Promise; /** * Prove that a redline's generated revisions accept to the intended final and reject to the * baseline. Three packages are inspected and two rebuilt, so this always runs off the main * thread; the returned proof carries digests and divergences rather than the rebuilt bytes. */ proveRedlineReversibility(baseline: File | Uint8Array, intendedFinal: File | Uint8Array, redline: File | Uint8Array): Promise; /** Compare two DOCX packages into the stable, versioned semantic-change schema. */ getSemanticChanges(left: File | Uint8Array, right: File | Uint8Array, settings?: DocxDiffSettings): Promise; /** * Create an empty external annotation set bound to the document's content hash — the input * to every other call in the annotation family. Runs in the worker, so a read-only viewer * that renders through this proxy needs no main-thread runtime to annotate (issue #775). */ createExternalAnnotationSet(document: File | Uint8Array, documentId: string): Promise; /** Validate an annotation set against a document: hash match and per-annotation text. */ validateExternalAnnotations(document: File | Uint8Array, annotationSet: ExternalAnnotationSet): Promise; /** * Project an annotation set onto HTML the engine rendered. The input is parsed as XML, so * hand it the converter's output (or another well-formed serialization), not a live DOM's * `innerHTML`. */ projectAnnotationsOntoHtml(html: string, annotationSet: ExternalAnnotationSet, projectionOptions?: ExternalAnnotationProjectionSettings): Promise; /** Convert a document and project an annotation set onto it in one round trip. */ convertDocxToHtmlWithExternalAnnotations(document: File | Uint8Array, annotationSet: ExternalAnnotationSet, conversionOptions?: ConversionOptions, projectionOptions?: ExternalAnnotationProjectionSettings): Promise; /** Export a document to the OpenContracts format (text, layout tokens, labels). */ exportToOpenContract(document: File | Uint8Array): Promise; /** * 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, maximumOutputBytes?: number): 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): Promise; /** * Read a document's native Word comments — the comment twin of {@link getRevisions}. * Same entries as `session.listComments()` without a session, so a read-only viewer * needs no main-thread runtime to show comment threads. * @param document - DOCX file as File object or Uint8Array * @returns Array of comments in comments-part order (empty when there are none) */ getComments(document: File | Uint8Array): 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. Uint8Array inputs are copied once so the caller's buffer remains attached and * subarray boundaries are preserved; the private copy is then transferred. * * 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