/** * DOCX Reader Context * * Encapsulates per-parse session state so that concurrent readDocx() calls * are safe. Previously this state lived in a module-level `_session` object. */ import { type WordSecurityPolicy } from "../security/policy.js"; import type { FormField, RunProperties } from "../types.js"; /** * A parsed OPC relationship entry (from a .rels part). */ export interface ParsedRelationship { id: string; type: string; target: string; targetMode?: string; } /** * State for the OOXML field state machine (``). * * OOXML allows complex fields (TOC, INDEX, SEQ, REF, …) to span multiple * paragraphs: `` may be in paragraph A while * the matching `end` is in paragraph C. This state therefore lives on the * shared reader context rather than as locals in `parseParagraph`. * * It is intentionally swappable: when entering a self-contained part such as * a header, footer, footnote, endnote or comment we save and reset the field * state so an unterminated field in the body never bleeds into those parts. */ export interface FieldParseState { state: "none" | "instrText" | "cached"; instr: string; cached: string; runProps: RunProperties | undefined; formField: FormField | undefined; } /** * Per-parse session context. Holds relationship maps and any other state * that needs to be shared across parse functions during a single readDocx() * invocation without relying on module-level mutable state. */ export interface ReaderContext { /** Relationship map for the current part being parsed (document, header, footer, etc.) */ relMap: Map; /** Field state machine; shared across paragraphs to support cross-paragraph fields. */ field: FieldParseState; /** * Resolved security policy for this read. Parsers consult specific * fields (e.g. `allowExternalTargets`) to decide whether to keep certain * pieces of information that may be dangerous in untrusted documents. * Defaults to `DEFAULT_SECURITY_POLICY` when not set. */ securityPolicy: Required; } /** * Create a fresh field state in the "none" state. */ export declare function createFieldState(): FieldParseState; /** * Create a fresh reader context for a new parse session. */ export declare function createReaderContext(securityPolicy?: Required): ReaderContext; /** * Parse a `.rels` XML string into an array of `ParsedRelationship` entries. * * Normalizes ISO 29500 Strict relationship types to Transitional equivalents * via `STRICT_TO_TRANSITIONAL_REL`. */ export declare function parseRelationships(xmlStr: string): ParsedRelationship[];