import { BorderSpec, CellBorders, TableBorderValue, TableBorders, TableFragment } from '../../../../contracts/src/index.js'; import { TableCellGridPosition } from './grid-geometry.js'; /** * Applies a border specification to one side of an HTML element. * * Converts BorderSpec format to CSS border properties and applies them to the specified * side of the element. Handles style conversion (e.g., 'single' → 'solid'), color validation, * and special cases like 'thick' borders which use doubled width. * * @param element - The HTML element to apply the border to * @param side - Which side of the element to apply the border ('Top', 'Right', 'Bottom', or 'Left') * @param border - The border specification to apply, or undefined to skip * * @example * ```typescript * const cell = document.createElement('td'); * applyBorder(cell, 'Top', { style: 'single', width: 2, color: '#FF0000' }); * // Sets cell.style.borderTop = '2px solid #FF0000' * ``` */ export declare const applyBorder: (element: HTMLElement, side: "Top" | "Right" | "Bottom" | "Left", border?: BorderSpec, widthOverridePx?: number) => void; /** * Applies border specifications to all four sides of a table cell element. * * Convenience function that applies borders to top, right, bottom, and left sides * of an element using applyBorder(). Only applies borders for sides that are defined * in the CellBorders object. * * @param element - The HTML element (typically a table cell) to apply borders to * @param borders - Cell border specifications for each side, or undefined to skip * * @example * ```typescript * const cell = document.createElement('td'); * applyCellBorders(cell, { * top: { style: 'single', width: 1, color: '#000000' }, * left: { style: 'double', width: 2, color: '#FF0000' } * }); * ``` */ export declare const applyCellBorders: (element: HTMLElement, borders?: CellBorders, widthOverridesPx?: { left?: number; right?: number; }) => void; /** * Word's separate-borders bevel model for `outset`/`inset` (measured from 300dpi * probes, SD-3028): the legacy HTML table look. With `outset` the TABLE frame is * raised (visual top/left light, bottom/right dark) and each CELL is sunken (the * inverse); `inset` mirrors both. Tones derive from the authored color: auto/black * uses #F0F0F0 / #A0A0A0, an explicit color uses the color itself (light) and the * color at half intensity (dark). All other styles pass through unchanged. Only * separate-borders mode calls this; in the collapsed model Word paints these * styles as plain solid lines. */ export declare const bevelToneSpec: (spec: BorderSpec | undefined, visualSide: "top" | "right" | "bottom" | "left", owner: "table" | "cell") => BorderSpec | undefined; /** * Converts a TableBorderValue to a BorderSpec for rendering. * * Handles conversion of table-level border values (which may include {none: true} markers) * to BorderSpec format used by the DOM renderer. Supports both 'width' and legacy 'size' * properties. * * @param value - Table border value to convert, or null/undefined * @returns BorderSpec for rendering, or undefined if value is null/undefined * * @example * ```typescript * const spec = borderValueToSpec({ style: 'single', width: 2, color: '#FF0000' }); * // Returns: { style: 'single', width: 2, color: '#FF0000' } * * const none = borderValueToSpec({ none: true }); * // Returns: { style: 'none', width: 0 } * ``` */ export declare const borderValueToSpec: (value?: TableBorderValue | null) => BorderSpec | undefined; /** * Resolves a table border value with fallback support. * * Attempts to use the explicit border value first, falling back to the fallback value * if the explicit value is undefined or null. This is used when cell borders can come * from either cell-specific definitions or table-level definitions. * * @param explicit - Primary border value to use (e.g., from cell attributes) * @param fallback - Fallback border value (e.g., from table borders) * @returns Resolved BorderSpec, or undefined if both values are undefined/null * * @example * ```typescript * const cellBorder = { style: 'double', width: 3, color: '#FF0000' }; * const tableBorder = { style: 'single', width: 1, color: '#000000' }; * const result = resolveTableBorderValue(cellBorder, tableBorder); * // Returns BorderSpec from cellBorder (explicit wins) * ``` */ export declare const resolveTableBorderValue: (explicit: TableBorderValue | undefined | null, fallback?: TableBorderValue | undefined | null) => BorderSpec | undefined; export declare const isPresentBorder: (b?: BorderSpec) => b is BorderSpec; /** * True when a border is EXPLICITLY set to none/nil (`w:val="nil"`/`"none"`), as opposed to * simply unset/absent. The distinction matters for shared interior edges (§17.4.66): an * explicit none on BOTH adjacent cells suppresses the divider, while an unset side inherits * the table's insideH/insideV. Accepts either a CellBorders BorderSpec (`{style:'none'}`) or * a TableBorderValue (`{none:true}`). */ export declare const isExplicitNoneBorder: (b?: unknown) => boolean; /** * OOXML cell-border conflict resolution (ECMA-376 §17.4.66). * * With zero cell spacing, two cells sharing an edge each specify a border; the spec * collapses them to a SINGLE displayed border: * 1. If either side is nil/none/absent, the opposing (present) border is displayed. * 2. Otherwise the border with greater weight wins, where * weight = (#lines in the style) × (style number). * 3. Equal weight → the style higher on the precedence list (single first) wins. * 4. Identical style → the color with the smaller brightness (R+B+2G, then B+2G, then * G) wins; finally the first border (reading order) wins. * * @param a - One side's border (the owning cell's, e.g. the lower/right cell) * @param b - The opposing side's border (e.g. the upper/left neighbor) * @returns The single BorderSpec to display, or undefined if neither is present. */ export declare const resolveBorderConflict: (a?: BorderSpec, b?: BorderSpec) => BorderSpec | undefined; /** * Creates a border overlay element for a table fragment. * * Generates an absolutely-positioned div that renders table-level borders (top, right, * bottom, left) on top of the table content. This is used to apply outer table borders * without affecting the table's internal layout. * * @param doc - Document object for creating the overlay element * @param fragment - Table fragment containing dimensions for the overlay * @param tableBorders - Table border specifications * @returns HTMLElement overlay with borders applied, or null if no borders are defined * * @example * ```typescript * const overlay = createTableBorderOverlay(document, fragment, { * top: { style: 'single', width: 2, color: '#000000' }, * bottom: { style: 'single', width: 2, color: '#000000' } * }); * if (overlay) container.appendChild(overlay); * ``` */ export declare const createTableBorderOverlay: (doc: Document, fragment: TableFragment, tableBorders: TableBorders) => HTMLElement | null; /** * Resolves cell-specific borders based on cell position within a table. * * Implements a **single-owner border model** to prevent double borders when * rendering tables with absolutely-positioned divs (which don't support CSS * border-collapse). Each shared border is owned by exactly one cell: * * - TOP border: Cell owns its own top (first row uses table.top, others use insideH) * - LEFT border: Cell owns its own left (first col uses table.left, others use insideV) * - BOTTOM border: Only last row renders it (using table.bottom) * - RIGHT border: Only last column renders it (using table.right) * * This ensures each border line is rendered exactly once, eliminating the * double-border issue that occurs when adjacent cells both render their * shared edge. * * @param tableBorders - Table-level border definitions * @param cellPosition - Cell position and span within the table grid * @returns CellBorders object with resolved borders for all four sides * * @example * ```typescript * // For a 3x3 table: * // Cell (0,0): top=table.top, left=table.left, bottom=undefined, right=undefined * // Cell (1,1): top=insideH, left=insideV, bottom=undefined, right=undefined * // Cell (2,2): top=insideH, left=insideV, bottom=table.bottom, right=table.right * ``` */ /** * Checks whether a CellBorders object has at least one explicitly defined side. * * Returns false when borders is undefined/null or when all four sides are undefined. * Used to distinguish "no borders attribute" from "borders attribute present but empty" * (intentionally borderless). * * @param cellBorders - Cell border definitions to check * @returns True if at least one side (top, right, bottom, left) is defined */ export declare const hasExplicitCellBorders: (cellBorders?: CellBorders) => cellBorders is CellBorders; export declare const resolveTableCellBorders: (tableBorders: { top?: TableBorderValue; bottom?: TableBorderValue; left?: TableBorderValue; right?: TableBorderValue; insideH?: TableBorderValue; insideV?: TableBorderValue; }, cellPosition: TableCellGridPosition) => CellBorders; /** * Swap left↔right on table borders for RTL tables (ECMA-376 Part 4 §14.3.2, §14.3.6). * insideH/insideV and top/bottom are not affected by direction. */ export declare const swapTableBordersLR: (borders: TableBorders | undefined) => TableBorders | undefined; /** * Swap left↔right on cell borders for RTL tables (ECMA-376 Part 4 §14.3.1, §14.3.5). */ export declare const swapCellBordersLR: (borders: CellBorders | undefined) => CellBorders | undefined; //# sourceMappingURL=border-utils.d.ts.map