/** * DOCX Reader - Shared XML/parsing utilities * * Low-level helpers used across the various reader sub-modules. * Extracted from docx-reader.ts to keep that file focused on * orchestration of the higher-level parsers. */ import type { XmlElement } from "../../xml/types.js"; import type { ParsedRelationship } from "./reader-context.js"; /** Get an attribute value, trying both `w:name` and bare `name`. */ export declare function attrVal(el: XmlElement, name: string): string | undefined; /** Get an attribute as an integer (returns undefined if missing or non-numeric). */ export declare function attrInt(el: XmlElement, name: string): number | undefined; /** * Like `parseInt(value ?? fallback, 10)` but never returns NaN: any * non-numeric value falls back to `fallback`. Use this when forwarding * raw attribute strings into numeric model fields — round-tripping a * `NaN` back into XML produces literal `"NaN"` and corrupts the * resulting DOCX. */ export declare function safeParseInt(value: string | undefined, fallback: number): number; /** Get the local name from a possibly-prefixed tag (`"w:p"` → `"p"`). */ export declare function localName(name: string): string; /** Find a child element by local name (matches both `w:name` and bare `name`). */ export declare function findChildNs(el: XmlElement, localName: string): XmlElement | undefined; /** Find all child elements with a given local name. */ export declare function findChildrenNs(el: XmlElement, localName: string): XmlElement[]; /** * Namespace-agnostic child finder: matches on the **local name** regardless * of the prefix. Useful for namespaces other than `w:` (e.g. `m:`, `c:`, * `cx:`) where the prefix may be inconsistent across producers. */ export declare function findChildLocal(el: XmlElement, name: string): XmlElement | undefined; /** Namespace-agnostic version of {@link findChildrenNs}. */ export declare function findChildrenLocal(el: XmlElement, name: string): XmlElement[]; /** * Get an attribute value by **local name**, regardless of prefix. * Useful when the same attribute may appear as `w:val`, `m:val`, etc. */ export declare function attrLocal(el: XmlElement, name: string): string | undefined; /** * Check for a boolean toggle element. * * In OOXML, many properties are represented as toggle elements where: * - Element present = true * - Element with `w:val="0"` or `"false"` = explicit false * - Element absent = undefined (use parent's default) */ export declare function boolToggle(parent: XmlElement, name: string): boolean | undefined; /** Serialize an XmlElement back to an XML string (used for opaque preservation). */ export declare function serializeElement(el: XmlElement): string; /** Extract all `r:xxx` attribute values (relationship IDs) from an element tree. */ export declare function collectRIds(el: XmlElement, out: Set): void; export { getPartRelsPath, getFileName, getFileExt } from "../core/opc-paths.js"; /** * Resolve an OPC relationship target against its source part. * * - Leading `/` → package root absolute * - `../` / `./` → resolved relative to the source part's directory * - Plain paths → resolved relative to the source part's directory * * Returns an empty string when the resolved path would escape the package * root (i.e. more `..` segments than there are directories above the * source). The previous behaviour silently treated extra `..` as a no-op, * which let a malicious or malformed `Target` value point at an entirely * different part than the directory traversal would suggest. */ export declare function resolvePartPath(sourcePart: string, target: string): string; /** * Find the first relationship of a given type and resolve its target path. * Returns undefined if no matching relationship exists. */ export declare function resolveRelTarget(rels: ParsedRelationship[], relType: string, sourcePart: string): string | undefined; /** Convert OOXML cryptAlgorithmSid to human-readable algorithm name. */ export declare function sidToHashAlgorithm(sid: string | undefined): string | undefined; /** * Common shape returned by {@link parseNoteProperties}. * * `numFmt` is widened to `string` (rather than `NoteNumberFormat`) so the * helper can populate either `FootnoteProperties` or `EndnoteProperties`, * which only differ in `position`'s narrow union. Callers cast at the * assignment site. */ export interface ParsedNoteProperties { numFmt?: string; numStart?: number; numRestart?: string; position?: string; } /** Parse footnote/endnote properties element. */ export declare function parseNoteProperties(el: XmlElement): ParsedNoteProperties | undefined;