import type { TableColumnPriority } from "./doc.js"; /** * Responsive column layout, independent of painting. * * Given the natural width of every column and the width available for the * grid, the layout yields either a grid (which columns to show and at what * width) or a stacked fallback. The policy, in order: * * 1. The natural widths fit: show everything as is. * 2. Otherwise, when the available width is below the stacked threshold, stack. * 3. Shrink the widest shrinkable columns toward their soft floors: the wider * of the declared minimum (default: header width), the widest unbreakable * word, and half the natural width (capped), so cells wrap between words * onto a couple of lines at most. * 4. Drop the droppable priorities in turn, each from the right, refitting at * soft floors after every drop. A table drops `optional` columns and then * `preferred` ones; a ledger drops only `optional` ones and stacks rather * than lose a column a reader cannot recover. * 5. Shrink the surviving columns to their word floors (wrapping onto more * lines but never splitting a word), then to their declared minimums, * splitting words as a last resort. * 6. Stack. */ export declare const STACKED_THRESHOLD = 40; export interface LayoutColumn { /** Display width of the header. */ readonly headerWidth: number; /** Widest cell or header. */ readonly naturalWidth: number; /** Widest unbreakable word across header and cells. */ readonly wordWidth: number; readonly width?: number; readonly minWidth?: number; readonly priority: TableColumnPriority; readonly align: "left" | "right"; } export interface GridColumn { /** Index into the source columns. */ readonly index: number; readonly width: number; readonly align: "left" | "right"; } export type TableLayout = { readonly _tag: "grid"; readonly columns: ReadonlyArray; readonly hidden: ReadonlyArray; } | { readonly _tag: "stacked"; }; export interface LayoutTableArgs { readonly columns: ReadonlyArray; readonly available: number | "unbounded"; readonly gap: number; /** Width below which the grid stacks outright; defaults to `STACKED_THRESHOLD`. */ readonly stackBelow?: number; /** Priorities dropped under pressure, in order; defaults to optional then preferred. */ readonly droppable?: ReadonlyArray; } export declare const layoutTable: (args: LayoutTableArgs) => TableLayout; export interface GridCell { /** Painted cell content for one line, formatting included. */ readonly text: string; readonly width: number; readonly align: "left" | "right"; } /** * Join one painted line of cells: every cell is padded to its column width * except a trailing left-aligned cell, so lines never carry trailing spaces. */ export declare const joinGridLine: (cells: ReadonlyArray, gap: number, pad: (text: string, width: number, align: "left" | "right") => string) => string; //# sourceMappingURL=table-layout.d.ts.map