/** * Pure XML-tree helpers for `templates.apply` source-authoritative adoption. * * These operate on xml-js JSON element trees (the converter's `parseXmlToJson` * shape) and never touch the editor/converter runtime — so they can be run on * clones for dry-run planning and on live parts for application. */ export interface XmlElement { type?: string; name?: string; attributes?: Record; elements?: XmlElement[]; text?: string; declaration?: unknown; } /** Local (namespace-stripped) name of an element, e.g. `w:style` -> `style`. */ export declare function localName(el: XmlElement): string | undefined; /** Find the first descendant-or-self root element whose local name matches. */ export declare function rootElement(parsed: XmlElement, name: string): XmlElement | undefined; /** Direct children of `el` with the given local name. */ export declare function childrenByLocalName(el: XmlElement, name: string): XmlElement[]; export declare function firstChildByLocalName(el: XmlElement, name: string): XmlElement | undefined; export declare function clone(value: T): T; export declare function xmlDeepEqual(a: unknown, b: unknown): boolean; export interface StylesMergeResult { /** Shared styleIds whose target definition was replaced in place by the source. */ replacedIds: string[]; /** Source-only styleIds appended to the target. */ addedIds: string[]; /** docDefaults adopted from the source. */ docDefaultsAdopted: boolean; /** latentStyles adopted from the source. */ latentStylesAdopted: boolean; /** Element references (in the merged tree) for every source-origin style. */ importedStyleEls: XmlElement[]; } /** * Source-authoritative style-system merge (`DA-TEMPLATE-011/012/013`). * * - Replaces the target `w:docDefaults` / `w:latentStyles` with the source. * - For a shared `styleId`, replaces the target style in place with the source * definition (no `*-tmpl` rename). * - Appends source-only styles. * - Leaves target-only styles untouched (retained for preserved content). * * The full source style set is imported. That is a superset of the strict * `basedOn`/`next`/`link`/numbering closure, so every imported dependency is * present; importing the superset is safe because the source is authoritative. */ export declare function mergeStylesAuthoritative(currentRoot: XmlElement, sourceRoot: XmlElement): StylesMergeResult; /** * Rewrite numbering references that live inside imported source style nodes so * they resolve through the reconciled numbering graph (`DA-TEMPLATE-014`). Only * imported (source-origin) styles are rewritten; target styles keep their own * numbering references. */ export declare function rewriteImportedStyleNumbering(importedStyleEls: XmlElement[], numRemap: Map): void; export interface NumberingMergeResult { /** old numId -> new numId for remapped source list instances. */ numRemap: Map; /** old abstractNumId -> new abstractNumId for remapped source abstracts. */ abstractRemap: Map; /** Receipt id-mappings (numbering kind), only for entries actually remapped. */ mappings: Array<{ kind: 'numbering'; from: string; to: string; }>; } /** * Reconcile source numbering into the current numbering as a dependency graph. * * Imports the source `w:abstractNum` / `w:num` graph, remapping ids that collide * with the target's existing ids, and rewires each imported `w:num`'s * `w:abstractNumId` to the (possibly remapped) abstract. IDs are preserved when * free, remapped only on collision. Existing target definitions are retained, * and the merged child list is normalized so non-definition children stay ahead * of `w:abstractNum` / `w:num` entries. */ export declare function mergeNumberingGraph(currentRoot: XmlElement, sourceRoot: XmlElement): NumberingMergeResult; export interface SettingsReconcileResult { adopted: string[]; changed: boolean; } /** * Bounded settings reconciliation. Adopts the source's layout/style-affecting * settings into the current settings part, preserving everything identity- or * workflow-oriented. Mutates `currentRoot` in place. */ export declare function reconcileSettings(currentRoot: XmlElement, sourceRoot: XmlElement): SettingsReconcileResult; /** Find the body-level (final) `w:sectPr` in a parsed `word/document.xml`. */ export declare function findFinalBodySectPr(documentRoot: XmlElement): XmlElement | undefined; /** * Find the `w:sectPr` whose settings govern page 1 of the source document. * * For a multi-section DOCX, this is the first paragraph-attached section break * in story order. For a single-section DOCX, it falls back to the body-level * final `w:sectPr`. Copying that whole section preserves the source page-1 * header/footer visibility semantics via `w:titlePg`. */ export declare function findPageOneSectPr(documentRoot: XmlElement): XmlElement | undefined; /** Rewrite header/footer reference relationship ids in a sectPr clone. */ export declare function rewriteSectPrRefs(sectPr: XmlElement, relIdRemap: Map): void; //# sourceMappingURL=template-xml.d.ts.map