/** * Format-agnostic Office document layer. * * {@link OfficeDocument} detects which Office family a package belongs to * via the main part's content type (all 16 modern extensions mapped in * {@link OFFICE_FORMATS}), and provides the shared machinery every * high-level lens builds on: the OpcPackage, the main part, and a lazy * per-part XML DOM cache with dirty flagging. * * Dirty-tracking flow (the L3 pipeline): * 1. `xml(partName)` parses a part once and caches the live DOM. * 2. Lenses mutate that DOM in place and call `markDirty(partName)`. * 3. `save()` serializes every dirty DOM back into its part, then calls * `OpcPackage.save()`, which raw-copies all untouched parts. * A part whose DOM was loaded but never marked dirty is therefore still * copied byte-for-byte. */ import { OpcPackage, type OpcPart } from '../opc/index.js'; import { type XmlDocument } from '../xml/index.js'; /** Office relationship namespace (the `r:` prefix in OOXML markup). */ export declare const R_NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"; /** Relationship type of the package's main ("office document") part. */ export declare const REL_TYPE_OFFICE_DOCUMENT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"; /** Which application family a format belongs to. */ export type OfficeFamily = 'word' | 'excel' | 'powerpoint'; /** What kind of file within its family. */ export type OfficeFormatKind = 'document' | 'template' | 'slideshow' | 'addin'; /** Static description of one Office format (one file extension). */ export interface OfficeFormatInfo { /** Lowercase extension without dot, e.g. 'docx'. */ readonly extension: string; readonly family: OfficeFamily; readonly kind: OfficeFormatKind; readonly macroEnabled: boolean; /** Content type of the main part — the format discriminator. */ readonly mainPartContentType: string; } /** * All modern Office OOXML formats, keyed by main-part content type. * This table is normative — see CONTRACTS.md §document. */ export declare const OFFICE_FORMATS: readonly OfficeFormatInfo[]; /** * Look up the format whose main-part content type equals * `mainPartContentType` exactly (content types are compared * case-sensitively here; Office writes them in canonical case — a * deliberate exception to the opc layer's media-type equality, since the * 16-format table is a closed set of canonical-case discriminators). */ export declare function detectFormat(mainPartContentType: string): OfficeFormatInfo | undefined; /** * A detected Office document over an OPC package. * * Construction via {@link OfficeDocument.open} or * {@link OfficeDocument.fromPackage} only. */ export declare class OfficeDocument { #private; /** @internal Construct via {@link OfficeDocument.open} / {@link OfficeDocument.fromPackage}. */ constructor(pkg: OpcPackage, format: OfficeFormatInfo, mainPart: OpcPart); /** * Open file bytes as an Office document: opens the OPC package, finds * the main part via the officeDocument package relationship, and * detects the format from its content type. Throws `Error` when the * package has no officeDocument relationship, the target is * unresolvable, or the main part's content type is not in * {@link OFFICE_FORMATS}. (The file extension is never consulted — * bytes are the only truth.) */ static open(bytes: Uint8Array): Promise; /** * Wrap an already-constructed package (used by the docx/xlsx/pptx * `create()` paths). Same detection and validation as `open`. */ static fromPackage(pkg: OpcPackage): OfficeDocument; /** The underlying package (full low-level access remains available). */ get package(): OpcPackage; /** The detected format. */ get format(): OfficeFormatInfo; /** Convenience: `format.family`. */ get family(): OfficeFamily; /** The main part (e.g. /word/document.xml, /xl/workbook.xml). */ get mainPart(): OpcPart; /** * @internal Seed the DOM cache with an already-parsed document — the * bridge that lets the synchronous `create()`/`add…` factories of the * app lenses register the DOM they just built as THE live DOM of the * part (CONTRACTS.md §0.1: one DOM per part; `xml()` must return the * same instance the lenses mutate). The entry starts DIRTY: primed * parts are newly created, always serialized from their DOM at save, * so even direct DOM edits made without a `markDirty` call are never * silently dropped. Throws when the part does not exist or already has * a valid cached DOM. */ _primeXml(partName: string, doc: XmlDocument): void; /** * The lazily-parsed, cached, LIVE XML DOM of a part. Repeated calls * return the same XmlDocument instance. Mutating the returned tree * requires a matching `markDirty(partName)` (lens methods do this * automatically). Throws `Error` when the part does not exist. * * Note: writing raw bytes via `OpcPart.write()` to a part with a cached * DOM evicts that cached DOM (the next `xml()` reparses). */ xml(partName: string): Promise; /** True when `xml(partName)` has a (still valid) cached DOM for the part. */ isLoaded(partName: string): boolean; /** * Flag a part's cached DOM for reserialization at save. When the part * has no valid cached DOM (never parsed, or evicted by a raw write) the * part itself is flagged dirty instead, so its current bytes are * rewritten. Throws when the part does not exist. */ markDirty(partName: string): void; /** True when the part is flagged dirty (DOM-level or part-level). */ isDirty(partName: string): boolean; /** * Serialize every dirty cached DOM into its part, then save the package * (untouched parts copied byte-for-byte) and return the file bytes. * The DOM cache stays valid afterwards (each flushed entry re-syncs to * the bytes it just wrote). */ save(): Promise; } //# sourceMappingURL=index.d.ts.map