/** * Shared justify alignment utilities. * * CRITICAL: This module provides the single source of truth for justify decisions. * Both the painter (visual rendering) and text measurement (caret positioning) MUST use * these functions to ensure consistent behavior and prevent caret drift. */ /** * Set of characters considered as spaces for justify distribution. * Includes both regular space and non-breaking space. */ export declare const SPACE_CHARS: Set; /** * Parameters for determining whether to apply justify to a line. */ export type ShouldApplyJustifyParams = { /** Paragraph alignment value (must be 'justify' for justify to apply). */ alignment: string | undefined; /** Whether the line has explicit segment positioning. Used as a legacy fallback. */ hasExplicitPositioning?: boolean; /** Whether the line used author-defined OOXML tab stops. */ hasExplicitTabStops?: boolean; /** Whether this is the last line of the paragraph. */ isLastLineOfParagraph: boolean; /** Whether the paragraph ends with a soft break (Shift+Enter / LineBreak run). */ paragraphEndsWithLineBreak: boolean; /** Explicit override to skip justify (e.g., from rendering context). */ skipJustifyOverride?: boolean; }; /** * Determines whether justify spacing should be applied to a line. * * Justify is applied when ALL of the following are true: * - Alignment is 'justify' * - No explicit skip override * - Line doesn't have author-defined tab stops * - Line is NOT the last line, OR paragraph ends with a soft break * * This matches Microsoft Word's behavior: * - All lines are justified except the true last line * - Soft breaks (Shift+Enter) do NOT count as "last line" * - Explicit tab-aligned text is never justified * - Default/manual tab-aligned text can still be justified * * @param params - Parameters for justify decision * @returns true if justify should be applied, false otherwise */ export declare function shouldApplyJustify(params: ShouldApplyJustifyParams): boolean; /** * Parameters for calculating justify spacing. */ export type CalculateJustifySpacingParams = { /** Line width (use naturalWidth ?? width to support compression). */ lineWidth: number; /** Available width for the line. */ availableWidth: number; /** Number of space characters in the line. */ spaceCount: number; /** Whether justify should be applied (from shouldApplyJustify). */ shouldJustify: boolean; }; /** * Calculates the extra spacing to apply per space character for justify. * * Returns the number of pixels to add after each space (via CSS word-spacing). * Can be negative for compression (when line is slightly too wide). * * Returns 0 if: * - Justify should not be applied * - There are no spaces in the line (division by zero prevention) * * Formula: (availableWidth - lineWidth) / spaceCount * * @param params - Parameters for spacing calculation * @returns Extra spacing per space in pixels (can be negative) */ /** * Computes the first-line indent offset from paragraph indent attributes. * * Returns 0 when first-line indent is suppressed. * The result is positive for firstLine indent, negative for hanging indent. */ export declare function getFirstLineIndentOffset(indent: { firstLine?: number; hanging?: number; } | undefined, suppressFirstLineIndent: boolean): number; /** * Adjusts availableWidth for first-line text indent. * * Negative textIndent (hanging indent): the measurer sets line.maxWidth to the * correct wider value, but Math.min with fallbackAvailableWidth clamps it back down. * Always adjust to restore actual available space. * * Positive textIndent (firstLine indent): the measurer already bakes it into * line.maxWidth, so only adjust on the fallback path (maxWidth not set). */ export declare function adjustAvailableWidthForTextIndent(availableWidth: number, textIndentOffset: number, lineMaxWidth: number | null | undefined): number; export declare function calculateJustifySpacing(params: CalculateJustifySpacingParams): number; //# sourceMappingURL=justify-utils.d.ts.map