import { type ChartInfoDesign, type PlaceholderKind, type PreparedDocument, type QualityFact, type TableColumnInfoDesign, type TableInfoDesign } from '@json-to-office/quality'; import type { ExpandedBlocks, FontRuntimeOpts, GenerationWarning } from '@json-to-office/shared'; import { type BlockSlotRole } from '@json-to-office/shared'; import type { ReportComponentDefinition } from '../types'; import type { ThemeConfig } from '../styles'; import { type GenerationThemeContext } from '../core/generationContext'; import { type ResolvedDocumentTree } from '../core/structure'; import { type BlockSourceMap } from '../blocks'; import { type DocxTextFact } from './text-inventory'; export interface DocxTableWidthFact extends QualityFact { kind: 'docx/table-width'; totalWidthTwips: number; availableWidthTwips: number; hasExplicitWidth: boolean; allColumnsExplicit: boolean; pointSum: number; percentSum: number; /** * Authored explicit widths by column index (points as numbers, `"NN%"` * strings kept verbatim) — what a fix has to rescale. Columns without an * explicit width are absent. */ explicitWidths: ReadonlyArray<{ index: number; width: number | string; }>; } /** * A chart in a document — native or Highcharts — read into the vocabulary the * information-design rules speak. */ export interface DocxChartFact extends QualityFact, ChartInfoDesign { kind: 'docx/chart'; /** `chart` or `highcharts`; the two answer the same questions differently. */ componentName: string; /** Theme tokens a palette fix can name, in series order. */ paletteTokens: readonly string[]; /** * Drawn by a block definition rather than written by the author: `path` * names the invocation, which has no chart props a patch could set. */ generated: boolean; } export interface DocxTableColumnFact extends TableColumnInfoDesign { /** The authored column already carries a `cellDefaults` object. */ hasCellDefaults: boolean; /** The authored column declares a header cell an alignment can be set on. */ hasHeader: boolean; /** * Body cells that state an alignment of their own. A column default never * reaches those, so a repair has to name them one by one. */ cellsWithOwnAlignment: readonly number[]; /** * Compiled from a block rather than written by the author. `path` then * names the slot that produced the column, which has no `cellDefaults` or * `header` to patch: the definition decides how it aligns. */ generated: boolean; } /** A table, resolved through the same cascade the renderer draws it with. */ export interface DocxTableFact extends QualityFact, TableInfoDesign { kind: 'docx/table'; columns: readonly DocxTableColumnFact[]; } export interface DocxHeadingFact extends QualityFact { kind: 'docx/heading'; level: number; previousLevel?: number; /** * A block compiled the heading. Its level is then the definition's or a * slot's, and `path` names that source — an invocation, a slot — not a * level prop a patch could set. */ generated: boolean; /** * Whether the heading is bound to what follows it, from its own prop or * from the style the theme gives its level. Word breaks a page between an * unbound heading and its first paragraph without a second thought. */ keepNext: boolean; } /** * A paragraph pinned into a floating frame — the one place in DOCX where the * author, not the layout engine, decides how much room the text gets. Flowed * body copy repaginates; a frame keeps its declared box and lets the text spill * or break inside it. */ export interface DocxFrameTextFact extends QualityFact { kind: 'docx/frame-text'; text: string; fontSizePt: number; /** Height of one line, including the resolved line-spacing rule. */ lineHeightPt: number; /** Signed tracking in points: negative when the run is condensed. */ characterSpacingPt: number; frameWidthTwips: number; frameHeightTwips?: number; /** Frame top, when pinned with an absolute vertical offset. */ offsetYTwips?: number; /** The paper edge — the last twip anything can render on. */ pageBottomTwips: number; /** The longest whitespace-delimited token — the one with nowhere to wrap. */ longestWord: string; /** * Resolved anchor when the frame is pinned by numeric offsets; an unstated * axis pins at 0, exactly as the compiler resolves it. Absent for * alignment-positioned frames and for percentage offsets, which this static * pass does not resolve. */ absoluteOffsetTwips?: { x: number; y: number; }; /** * What each axis's offset is measured from — `page` unless authored. * Offsets are only comparable between frames sharing both references. */ anchorHorizontal: string; anchorVertical: string; /** * Shared by consecutive paragraphs whose frame properties are identical. * OOXML merges those into one flowing frame (§17.3.1.11 — the stock stat * cards stack number, caption and body this way), so their texts stack * inside the box rather than painting over each other. Any rule comparing * frame rects must treat a chain as a single frame. */ frameChainId: string; /** * Top-level flow this frame renders in. Every top-level `section` starts a * new page, so frames in different flows never share one; top-level content * outside any section shares the flow it lands in. */ flowIndex: number; } /** * A `` element inside an inline SVG, with the canvas it has to sit in. * SVG has no overflow rule to fall back on: a baseline past the viewBox is * simply not painted, and the words leave the document's text layer with it. */ export interface DocxSvgTextFact extends QualityFact { kind: 'docx/svg-text'; content: string; /** Baseline position and nominal size, in viewBox units. */ baselineY: number; fontSizeUnits: number; viewBoxMinY: number; viewBoxHeight: number; } /** * A paragraph or heading whose line box is pinned with `exactly` — the one * line-spacing form that is an absolute height rather than a floor the line may * grow past. `atLeast` and the multiples can only ever be as tall as the text * needs; an exact box keeps its stated height and the glyphs are clipped to it. */ export interface DocxLineBoxFact extends QualityFact { kind: 'docx/line-box'; /** The pinned box, in points. */ lineBoxPt: number; /** Size of the text inside it: authored, defaulted, or from the style. */ fontSizePt: number; /** Whether the size came from the component rather than the paragraph style. */ fontSizeAuthored: boolean; /** * Whether `path` addresses a member of the authored document. A line box * arriving through `componentDefaults` has no such member, and an RFC 6902 * `add` under a parent that does not exist fails instead of repairing. */ patchable: boolean; } /** The resolved theme, as the brand rules see it. */ export interface DocxThemeFact extends QualityFact { kind: 'docx/theme'; themeName: string; /** Token name to `#RRGGBB`, for every palette entry that resolves. */ paletteHexes: Readonly>; fontFamilies: readonly string[]; /** * Every size the theme paints, ascending: each named style, each font role * and, where the theme declares a type scale, every step of it. A size an * author writes by hand is on the theme's scale when it is in this list. */ typeScalePt: readonly number[]; /** Style key (`heading2`, `normal`, a `themeStyle`) to the size it paints. */ roleSizesPt: Readonly>; } /** * One painted size, wherever the document paints it: a paragraph, a heading, a * table cell, a line of a running head. `role` is the style the size belongs * to; `authored` says the size was written rather than inherited, and then * `sizePath` is the pointer that wrote it — the only thing a fix can replace. * `generated` says a block compiled the node, so its pointer is not the * author's to patch. */ export interface DocxTextSizeFact extends QualityFact { kind: 'docx/text-size'; role: string; fontSizePt: number; authored: boolean; generated: boolean; /** Pointer to the authored size value; absent when the size is inherited. */ sizePath?: string; } /** A colour written as a literal rather than as a theme token. */ export interface DocxColorFact extends QualityFact { kind: 'docx/color'; raw: string; hex: string; } /** A font family the document asks for by name. */ export interface DocxFontFact extends QualityFact { kind: 'docx/font-family'; family: string; } /** * One text slot of a block, counted against the budget the block declares. * The path is the authored slot, so a finding lands where the author writes. */ export interface DocxBlockSlotFact extends QualityFact { kind: 'docx/block-slot'; block: string; slot: string; words: number; maxWords: number; } /** One authored string that reads as a placeholder rather than as content. */ export interface DocxPlaceholderFact extends QualityFact { kind: 'docx/placeholder'; text: string; placeholderKind: PlaceholderKind; pattern: string; excerpt: string; } /** * A role-bearing slot of a block invocation, present or not. A profile reads * these to require a takeaway under every chart or a source under every * table; the theme that styles them never adds a requirement. */ export interface DocxChromeSlotFact extends QualityFact { kind: 'docx/chrome-slot'; block: string; slot: string; role: BlockSlotRole; present: boolean; /** The invocation the slot belongs to. */ invocation: string; } /** * What a top-level section carries once blocks have expanded: a header, a * footer, and a page-number field in either. A profile decides whether a * body section owes a running head; the first section is where a cover lives. */ export interface DocxSectionChromeFact extends QualityFact { kind: 'docx/section-chrome'; index: number; header: boolean; footer: boolean; pageNumber: boolean; } /** * What a top-level section holds once blocks have expanded: whether anything * reaches the page at all, and whether a heading opens it. A profile decides * whether either is required; the theme never does. */ export interface DocxSectionFact extends QualityFact { kind: 'docx/section'; index: number; /** Paragraphs, list items, table cells, captions — text a reader sees. */ words: number; /** Figures a section carries without words: a chart, a table, an image. */ exhibits: number; headings: number; /** Any text of its own reaches the page: a heading, a contents field, copy. */ rendersText: boolean; } /** * The document's outline as a whole: how many headings it carries and whether * it offers a table of contents to reach them by. */ export interface DocxOutlineFact extends QualityFact { kind: 'docx/outline'; headings: number; contents: boolean; } /** * A drawn image and what is known about the asset behind it. `naturalRatio` * is present only when the asset could be read where it stands — a data URI * or inline SVG markup. A path is resolved at generation, not here, so a * distorted file-backed image is the rendered pass's to catch. */ export interface DocxImageFact extends QualityFact { kind: 'docx/image'; alt?: string; /** Whether a caption paragraph follows the image in reading order. */ captioned: boolean; drawnRatio?: number; naturalRatio?: number; /** `width` and `height` as the author wrote them, when both are pixels. */ authoredSizePx?: { width: number; height: number; }; } /** * How wide a line of body copy runs, in characters. The measure is the * section's usable width; the characters are what the body face fits in it. */ export interface DocxMeasureFact extends QualityFact { kind: 'docx/measure'; index: number; charactersPerLine: number; widthTwips: number; fontSizePt: number; } export type DocxQualityFact = DocxTextFact | DocxSectionFact | DocxOutlineFact | DocxImageFact | DocxMeasureFact | DocxChromeSlotFact | DocxSectionChromeFact | DocxTableWidthFact | DocxHeadingFact | DocxFrameTextFact | DocxSvgTextFact | DocxLineBoxFact | DocxPlaceholderFact | DocxBlockSlotFact | DocxThemeFact | DocxTextSizeFact | DocxColorFact | DocxFontFact | DocxChartFact | DocxTableFact; export interface DocxQualityModel { authored: ReportComponentDefinition; /** Theme context over the expanded tree: every block lowered in place. */ context: GenerationThemeContext; document: ResolvedDocumentTree; themeName: string; } /** What `PreparedDocument.metadata.blocks` carries once a block expanded. */ export interface DocxBlocksMetadata { /** Expanded pointer → authored pointer, for every compiled region. */ sourceMap: BlockSourceMap; /** Authored pointers of the expanded blocks. */ blocks: readonly string[]; /** The compiled form: the document with every block lowered in place. */ document: ReportComponentDefinition; } export interface PrepareDocxQualityOptions { customThemes?: Record; fonts?: FontRuntimeOpts; warnings?: GenerationWarning[]; context?: GenerationThemeContext; renderer?: string; /** * The expansion a plugin host already ran over `context.document`: blocks * and registered code components lowered together, with the source map * back to what the author wrote. Given, preparation reads it instead of * expanding blocks alone, so a fact about a plugin's output reports at the * invocation that emitted it. */ expanded?: ExpandedBlocks; } export declare function prepareDocxQualityDocument(document: ReportComponentDefinition, options?: PrepareDocxQualityOptions): PreparedDocument; //# sourceMappingURL=facts.d.ts.map