/** * docx shared internals — the contract Phase-4 feature modules code against. * * OWNERSHIP (DESIGN-P4.md): this file is owned by the architect/Integrate * agent and is FROZEN during parallel implementation. Feature implementers * (resolver.ts, tables.ts, images.ts, sections.ts) import from it but never * edit it. `index.ts` implements the {@link DocumentInternal} interface * (via the `@internal` `Document._internal()`, stable per instance) and * re-exports the public helpers below. * * Everything in this file is either: * - a pure helper extracted verbatim from index.ts (behavior unchanged), or * - a capability interface implemented by the `Document` lens in index.ts. * * Nothing here mutates DOMs except through the interface; dirty-marking * discipline (CONTRACTS.md §0.1) is the caller's responsibility via * `markDirty`. */ import type { OfficeDocument } from '../document/index.js'; import type { OpcPart } from '../opc/index.js'; import { XmlElement, type XmlDocument } from '../xml/index.js'; /** WordprocessingML main namespace (the `w:` prefix). */ export declare const WML_NAMESPACE = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"; /** DrawingML main namespace (the `a:` prefix; understood for MCE selection). */ export declare const DRAWINGML_NAMESPACE = "http://schemas.openxmlformats.org/drawingml/2006/main"; /** WordprocessingDrawing namespace (the `wp:` prefix; understood for MCE). */ export declare const WP_DRAWING_NAMESPACE = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"; /** DrawingML picture namespace (the `pic:` prefix; images.ts). */ export declare const PIC_NAMESPACE = "http://schemas.openxmlformats.org/drawingml/2006/picture"; /** Relationship-attribute namespace (the `r:` prefix — r:id, r:embed). */ export declare const R_ATTR_NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"; /** * The namespaces the Word lens claims to understand when resolving MCE * markup (CONTRACTS.md §10.1). Extending this set is a contract change. */ export declare const UNDERSTOOD: ReadonlySet; export declare const REL_TYPE_STYLES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"; export declare const REL_TYPE_NUMBERING = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"; export declare const REL_TYPE_SETTINGS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"; export declare const REL_TYPE_HEADER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"; export declare const REL_TYPE_FOOTER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"; export declare const REL_TYPE_IMAGE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"; export declare const CT_MAIN_DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"; export declare const CT_STYLES = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"; export declare const CT_NUMBERING = "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"; export declare const CT_SETTINGS = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"; export declare const CT_HEADER = "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml"; export declare const CT_FOOTER = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"; export declare const CT_PNG = "image/png"; export declare const CT_JPEG = "image/jpeg"; export declare const XML_DECL = ""; /** The styles.xml skeleton written by create() and ensureStyles(). */ export declare const STYLES_XML: string; /** Empty numbering part skeleton (abstractNum/num are added by sections.ts). */ export declare const NUMBERING_XML = ""; /** Empty settings part skeleton (flags are added by feature modules). */ export declare const SETTINGS_XML = ""; /** Create a module-prefixed error (CONTRACTS.md §0.3). */ export declare function docxError(message: string): Error; /** True when `node` is a WML element with the given local name. */ export declare function isWml(node: XmlElement, localName: string): boolean; /** XML whitespace at either end ⇒ the w:t needs xml:space="preserve". */ export declare function needsSpacePreserve(text: string): boolean; /** * Interpret an ST_OnOff toggle element (w:b, w:i, …): absent element ⇒ * false; present without w:val ⇒ true; w:val of 0/false/off ⇒ false; * anything else ⇒ true. */ export declare function onOff(el: XmlElement | undefined): boolean; /** * Tri-state ST_OnOff read for cascade resolution: `undefined` when the * element is absent (property not specified at this level — inherit), * otherwise the explicit boolean. The resolver needs the "not specified" * case to implement toggle-property XOR (ECMA-376 §17.7.3) correctly. */ export declare function onOffExplicit(el: XmlElement | undefined): boolean | undefined; /** * Plain text of one run: `w:t` content in order, `w:tab` → '\t', * `w:br`/`w:cr` → '\n'. MCE-resolved (a run inside an AlternateContent * branch is read through the selected branch only). */ export declare function runText(run: XmlElement): string; /** * Concatenated text of all runs at or below `el` (which is a w:p or an * inline container such as w:hyperlink / w:ins / w:sdt), MCE-resolved. * Property containers, nested paragraphs, and nested tables contribute * nothing (nested w:p elements are separate paragraphs). */ export declare function textOfContainer(el: XmlElement): string; /** * Collect w:r elements at or below `el` in document order, MCE-resolved, * without descending into nested paragraphs/tables or property elements. */ export declare function collectRuns(el: XmlElement, out: XmlElement[]): void; /** * Build a `w:r > (w:rPr > w:b?/w:i?)? + w:t` subtree (detached). Child * order inside w:rPr follows the schema order: b before i. */ export declare function buildRun(prefix: string | null, text: string, bold: boolean, italic: boolean): XmlElement; /** * Walk up the parent chain from `el` to the nearest enclosing WML element * with `localName` (e.g. the w:p containing a w:r), or undefined. */ export declare function nearestAncestor(el: XmlElement, localName: string): XmlElement | undefined; /** * One modeled part with its LIVE cached DOM. `doc` is the document * layer's cached instance — dirty flagging and save-time serialization * are its job. */ export interface PartDom { readonly part: OpcPart; readonly doc: XmlDocument; } /** Which side of the page a header/footer part serves. */ export type HeaderFooterKind = 'header' | 'footer'; /** A loaded header or footer part (from a main-part header/footer rel). */ export interface HeaderFooterPartRef { readonly kind: HeaderFooterKind; readonly pd: PartDom; } /** * Capabilities of a `Document` exposed to feature modules. Obtained via * the `@internal` `Document._internal()` (stable per instance); * implemented in index.ts. * * `Document.open` eagerly loads — in addition to the main part — the * styles, numbering, and settings parts (when present) and every * header/footer part referenced from the main part's relationships, so * all Phase-4 READ APIs are synchronous. Loading never dirties anything: * untouched loaded parts still raw-copy at save (CONTRACTS.md §6.4). */ export interface DocumentInternal { /** The underlying office document (package, parts, DOM cache). */ readonly office: OfficeDocument; /** document.xml part + live DOM. */ readonly main: PartDom; /** The live `w:body` element (throws when the main part has none). */ body(): XmlElement; /** * The prefix bound to the WML namespace at the body element (usually * 'w'; null for a default-namespace document). Use it for every element * created into the main part. */ wmlPrefix(): string | null; /** styles.xml, or null when the document has none. */ styles(): PartDom | null; /** * styles.xml, creating the minimal docDefaults+Normal part, * content-type override, and main-part relationship on first use * (marks the new part dirty). */ ensureStyles(): PartDom; /** numbering.xml, or null when the document has none. */ numbering(): PartDom | null; /** * numbering.xml, creating an EMPTY `w:numbering` part + override + * relationship on first use (sections.ts adds abstractNum/num content). */ ensureNumbering(): PartDom; /** settings.xml, or null when the document has none. */ settings(): PartDom | null; /** * settings.xml, creating an empty `w:settings` part + override + * relationship on first use (e.g. for `w:evenAndOddHeaders`). */ ensureSettings(): PartDom; /** * Every loaded header/footer part (rel types header/footer on the main * part), in relationship document order. Parts added through * {@link addXmlPart} with a header/footer rel type appear here too. */ headerFooterParts(): readonly HeaderFooterPartRef[]; /** Flag a modeled part dirty (delegates to the document-layer cache). */ markDirty(pd: PartDom): void; /** * Smallest-N free part name `${prefix}${N}.${ext}` (N ≥ 1, name lookup * case-insensitive), e.g. `freePartName('/word/header', 'xml')` → * '/word/header1.xml', `freePartName('/word/media/image', 'png')` → * '/word/media/image1.png'. */ freePartName(prefix: string, ext: string): string; /** * Create an XML part: adds the part (content-type override per opc * rules), primes its DOM as the live cached instance (born dirty), and * adds a main-part relationship of `relType` targeting it. Returns the * PartDom and the allocated relationship id. */ addXmlPart(partName: string, contentType: string, relType: string, doc: XmlDocument): { pd: PartDom; relId: string; }; /** * Create a binary (non-XML) part, e.g. /word/media/image1.png, plus a * main-part relationship of `relType`. Returns the part and rel id. */ addBinaryPart(partName: string, contentType: string, relType: string, bytes: Uint8Array): { part: OpcPart; relId: string; }; /** * Remove a part created/referenced from the main part: deletes every * main-part relationship resolving to it, the part itself (with its * .rels and content-type override), and any internal caching (e.g. its * headerFooterParts entry). Used when replacing a header/footer leaves * the old part unreferenced. */ removeRelatedPart(partName: string): void; /** * The smallest positive integer strictly greater than every * `wp:docPr/@id` in the main part and all loaded header/footer parts — * DrawingML object ids must be unique document-wide or Word repairs. */ nextDrawingId(): number; } //# sourceMappingURL=internal.d.ts.map