/** * collectDocumentOutline — per-document pre-pass over the layout (#174, #177, * #182). One walk, three outputs: TOC entries, heading numbers, and the * cross-reference targets `[@id]` resolves against. * * `updateFields: true` asks Word to repopulate every TOC field on open, and * Word obliges. Headless LibreOffice does not, so a TOC field with no cached * content exports to PDF as the bare word "Contents" — and the rasterizer path * goes through soffice. Collecting the entries up front lets the renderer pass * them to docx as `cachedEntries`, which writes real paragraphs between the * field's `separate` and `end` characters. * * Modelled on `prerasterizeVisuals`: a pure collection pass over the layout, * seeded into the render context, consulted by the component that needs it. * Over-collection shows a stale entry until the reader refreshes the field; * under-collection degrades to today's empty TOC. Neither breaks a render. * * What the walk must and must not reach: * - **Headers and footers are excluded by construction.** They are fields on * `SectionLayout`, not components in `components[]`, and `renderSection` * handles only paragraph/image/table there — a heading in a header renders as * nothing and must never appear in the TOC. * - **`text-box` is reachable and does hold headings.** Its children render * through `renderComponent` as real `Heading1..6` paragraphs, which Word's * `\o` switch collects. * - **`columns` cannot appear here** — `applyLayout` hoists its children before * this runs. The descent is kept anyway for the text-box-nested case and so a * future layout change cannot silently drop entries. * - **Table cells cannot carry headings** (`processCellContent` handles only * paragraph and image), so tables are leaves. * * Two kinds of entry are collected, because Word populates a TOC from two * sources: heading components (the `\o` outline range) and paragraphs whose * `themeStyle` a TOC maps via `props.styles` (the `\t` switch). Collecting only * the first would make the cached entries disagree with Word's own refresh — * exactly the failure `cachedEntries` exists to prevent. * * The walk also owns the two counters render cannot keep itself: the heading * numbering sequence (a cross-reference needs the number of a heading that may * come later in the document) and each list's item counters. */ import type { SectionLayout } from './layout'; /** * A cross-reference target: a numbered heading or list item. * * Resolved by the outline pre-pass and read back while text is compiled, which * is why a `[@id]` can point at something further down the document. */ export interface NumberedItemInfo { kind: 'heading' | 'list-item'; /** Rendered text of the target, for a `:none` (text) reference. */ text: string; /** Full multilevel number ("2.1.3"), absent when the target is unnumbered. */ full?: string; /** The target's own level counter ("3"), absent when unnumbered. */ own?: string; } export interface TocHeadingEntry { /** Rendered text, with markdown decorators stripped as `createHeading` does. */ title: string; /** Outline level (heading) or the level its style maps to. */ level: number; /** * `themeStyle` key for a style-mapped paragraph; undefined for a heading. * A TOC includes these only when its own `props.styles` maps the key. */ styleId?: string; /** Bookmark of the layout section this entry sits in, when inside one. */ sectionBookmarkId?: string; /** Multilevel number ("2.1") when heading numbering applies to this entry. */ number?: string; } export interface DocumentOutline { entries: TocHeadingEntry[]; /** Cross-reference targets, keyed by the bookmark id render will emit. */ numberedItems: Map; } /** * Strip the inline decorators `createHeading` consumes, so a cached entry shows * "Results" rather than "**Results**". */ export declare function normalizeEntryTitle(text: string): string; /** * Walk the document once and derive everything render needs to know about it up * front: the TOC entries, the heading numbers, and the cross-reference targets * keyed by the bookmark ids render will produce. * * The id prediction is the delicate part. `renderHeadingComponent` slugs a * heading's text and disambiguates it against bookmarks registered *so far*, so * this walk must see the same ids in the same order — including the explicit * `props.id` a paragraph registers — or a cross-reference resolves against an * id that never gets written. */ export declare function collectDocumentOutline(sections: readonly SectionLayout[]): DocumentOutline; /** * Collect every TOC-eligible entry in document order, tagged with the layout * section it belongs to so a section-scoped TOC can filter to its own. */ export declare function collectTocHeadings(sections: readonly SectionLayout[]): TocHeadingEntry[]; //# sourceMappingURL=collectTocHeadings.d.ts.map