import { TextRun, TabRun, RunMark, TrackedChangeMeta, TrackedChangeKind } from '../../../../../../../layout-engine/contracts/src/index.js';
import { UnderlineStyle, PMMark, HyperlinkConfig, ThemeColorPalette } from '../types.js';
/**
 * Track change mark type constants from ProseMirror schema.
 */
export declare const TRACK_INSERT_MARK = "trackInsert";
export declare const TRACK_DELETE_MARK = "trackDelete";
export declare const TRACK_FORMAT_MARK = "trackFormat";
/**
 * Calculates relative luminance of a hex color per WCAG 2.1 guidelines.
 *
 * Implements the WCAG 2.1 relative luminance formula to determine perceived brightness
 * of a color. This is critical for ensuring sufficient contrast between text and background
 * colors to meet accessibility standards (WCAG AA requires 4.5:1 contrast for normal text).
 *
 * The calculation converts RGB values to linear RGB space using the sRGB gamma correction,
 * then applies weighted coefficients based on human perception (green contributes most to
 * perceived brightness, blue the least).
 *
 * @param hexColor - Hex color string (e.g., "#FF0000" or "F00" for red). May optionally
 *   include the "#" prefix. Supports both 3-digit (#RGB) and 6-digit (#RRGGBB) formats.
 * @returns Relative luminance value from 0 (black) to 1 (white). Returns 1.0 (light) for
 *   invalid color strings to default to black text for safety.
 *
 * @example
 * ```typescript
 * getLuminance('#FFFFFF'); // 1.0 (pure white)
 * getLuminance('#000000'); // 0.0 (pure black)
 * getLuminance('#808080'); // ~0.2159 (mid gray)
 * getLuminance('#342D8C'); // ~0.0557 (dark purple, < 0.18 threshold)
 * getLuminance('#F00');    // 0.2126 (red in short form)
 * getLuminance('invalid'); // 1.0 (defaults to light/black text)
 * ```
 *
 * @see https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
 * @see https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio
 */
export declare const getLuminance: (hexColor: string) => number;
/**
 * Resolves auto text color (black or white) based on background luminance for optimal contrast.
 *
 * Automatically determines whether to use white (#FFFFFF) or black (#000000) text based on
 * the background color's relative luminance to ensure WCAG AA compliance (4.5:1 contrast ratio
 * for normal text). This is essential for table cells and other elements where text color is
 * not explicitly set.
 *
 * The function uses a luminance threshold of 0.18 - backgrounds darker than this receive white
 * text, while lighter backgrounds receive black text. This threshold is calibrated to ensure
 * maximum readability across all background colors.
 *
 * @param backgroundColor - Background color as hex string (e.g., "#FF0000", "F00", or "#808080").
 *   May optionally include the "#" prefix. Supports both 3-digit and 6-digit hex formats.
 * @returns "#FFFFFF" (white) for dark backgrounds (luminance < 0.18), or "#000000" (black)
 *   for light backgrounds (luminance >= 0.18).
 *
 * @example
 * ```typescript
 * resolveAutoColor('#000000'); // "#FFFFFF" (white text on black)
 * resolveAutoColor('#FFFFFF'); // "#000000" (black text on white)
 * resolveAutoColor('#342D8C'); // "#FFFFFF" (white text on dark purple)
 * resolveAutoColor('#CCCCCC'); // "#000000" (black text on light gray)
 * resolveAutoColor('#808080'); // "#000000" (black text on mid gray, at threshold boundary)
 * ```
 *
 * @see https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio
 * @see {@link getLuminance} for luminance calculation details
 */
export declare const resolveAutoColor: (backgroundColor: string) => string;
/**
 * Extracts data-* attributes from a mark's attrs and normalizes values to strings.
 * Only forwards primitive/stringifiable values to avoid bloating run payloads.
 * Applies security limits to prevent DoS attacks from malicious payloads.
 *
 * @param attrs - Mark attributes object that may contain data-* attributes
 * @returns Record of data-* attributes with string values, or undefined if no valid attributes found
 *
 * @example
 * ```typescript
 * extractDataAttributes({ 'data-id': '123', 'data-name': 'test' });
 * // Returns: { 'data-id': '123', 'data-name': 'test' }
 *
 * extractDataAttributes({ 'data-id': 123, 'data-active': true });
 * // Returns: { 'data-id': '123', 'data-active': 'true' }
 *
 * extractDataAttributes({ color: 'red', 'data-id': '123' });
 * // Returns: { 'data-id': '123' } (non-data attributes filtered out)
 * ```
 */
export declare const extractDataAttributes: (attrs: Record<string, unknown> | undefined) => Record<string, string> | undefined;
/**
 * Normalizes and validates run mark lists from trackFormat metadata.
 * Applies security limits to prevent DoS attacks from malicious payloads.
 *
 * @param value - Raw mark list (string JSON or array)
 * @returns Normalized RunMark array, or undefined if validation fails
 */
export declare const normalizeRunMarkList: (value: unknown) => RunMark[] | undefined;
/**
 * Maps a ProseMirror mark type to a tracked change kind.
 *
 * @param markType - The PM mark type string (e.g., 'trackInsert', 'trackDelete', 'trackFormat')
 * @returns The corresponding TrackedChangeKind ('insert', 'delete', or 'format'), or undefined if not a tracked change mark
 */
export declare const pickTrackedChangeKind: (markType: string) => TrackedChangeKind | undefined;
/**
 * Builds tracked change metadata from a ProseMirror mark.
 * Extracts author info, timestamps, and before/after formatting for trackFormat marks.
 *
 * @param mark - ProseMirror mark containing tracked change attributes
 * @returns TrackedChangeMeta object, or undefined if not a tracked change mark
 */
export declare const buildTrackedChangeMetaFromMark: (mark: PMMark, storyKey?: string) => TrackedChangeMeta | undefined;
/**
 * Selects the higher-priority tracked change metadata when multiple marks overlap.
 * Insert/delete marks (priority 3) take precedence over format marks (priority 1).
 *
 * @param existing - Current tracked change metadata, if any
 * @param next - New tracked change metadata to consider
 * @returns The higher-priority metadata
 */
export declare const selectTrackedChangeMeta: (existing: TrackedChangeMeta | undefined, next: TrackedChangeMeta) => TrackedChangeMeta;
/**
 * Checks if two text runs have compatible tracked change metadata for merging.
 * Runs are compatible if their normalized tracked-change layer identities match,
 * or both have no metadata.
 *
 * @param a - First text run
 * @param b - Second text run
 * @returns true if runs can be merged, false otherwise
 */
export declare const trackedChangesCompatible: (a: TextRun, b: TextRun) => boolean;
export declare const collectTrackedChangesFromMarks: (marks?: PMMark[], storyKey?: string) => TrackedChangeMeta[];
/**
 * Collects and prioritizes tracked change metadata from an array of ProseMirror marks.
 * When multiple tracked change marks are present, returns the first normalized layer.
 *
 * @param marks - Array of ProseMirror marks to process
 * @returns The primary TrackedChangeMeta, or undefined if none found
 */
export declare const collectTrackedChangeFromMarks: (marks?: PMMark[], storyKey?: string) => TrackedChangeMeta | undefined;
/**
 * Normalizes underline style value from PM mark attributes.
 * Returns a valid UnderlineStyle, or undefined for explicit off values.
 * Missing/undefined values default to 'single' (presence of underline mark implies underline).
 *
 * @param value - Unknown value from mark attributes that should be an underline style
 * @returns A valid UnderlineStyle ('single', 'double', 'dotted', 'dashed', 'wavy'), or undefined if explicitly disabled
 *
 * @remarks
 * Handles multiple value types:
 * - Strings: Recognizes specific underline styles ('double', 'dotted', etc.) and off values ('none', '0', 'false', 'off')
 * - Numbers: 0 returns undefined (off), any other number returns 'single'
 * - Booleans: false returns undefined (off), true returns 'single'
 * - undefined/null: Returns 'single' (default)
 * - Empty/whitespace strings: Returns 'single' (default)
 *
 * @example
 * ```typescript
 * normalizeUnderlineStyle('double');    // 'double'
 * normalizeUnderlineStyle('none');      // undefined
 * normalizeUnderlineStyle(false);       // undefined
 * normalizeUnderlineStyle(0);           // undefined
 * normalizeUnderlineStyle(undefined);   // 'single'
 * normalizeUnderlineStyle(123);         // 'single'
 * normalizeUnderlineStyle('custom');    // 'single'
 * ```
 */
export declare const normalizeUnderlineStyle: (value: unknown) => UnderlineStyle | undefined;
/**
 * Applies text style mark attributes to a text run.
 * Handles color, fontFamily, fontSize, and letterSpacing with validation and normalization.
 * Properties are applied with bounds checking and sanitization to prevent invalid values.
 *
 * @param run - The text run to apply styles to (mutated in place)
 * @param attrs - Mark attributes containing style properties:
 *   - color: Hex color string (e.g., "FF0000" or "#FF0000")
 *   - fontFamily: Font name string (sanitized for CSS injection)
 *   - fontSize: Numeric pixel value or string with units (e.g., 12, "12pt", "24px").
 *     Point values are converted to pixels (96 DPI); unitless/px values are treated as pixels.
 *     Valid range after conversion: 1-1000px. Values outside this range are ignored.
 *   - letterSpacing: Numeric pixel value or string with units (e.g., 2, "0.75pt", "-1px").
 *     Point values are converted to pixels (96 DPI); unitless/px values are treated as pixels.
 *     Valid range after conversion: -100 to 100px. Values outside this range are ignored.
 * @param themeColors - Optional theme color palette for color resolution
 */
export declare const applyTextStyleMark: (run: TextRun, attrs: Record<string, unknown>, themeColors?: ThemeColorPalette) => void;
/**
 * Applies all ProseMirror marks to a text run.
 * Processes formatting marks (bold, italic, underline, etc.),
 * text style marks, hyperlinks, and tracked changes in a single pass.
 * If an individual mark application fails, that mark is skipped and processing continues.
 *
 * @param run - The text run to apply marks to (mutated in place)
 * @param marks - Array of ProseMirror marks to apply
 * @param hyperlinkConfig - Configuration for hyperlink processing (defaults to basic mode)
 * @param themeColors - Optional theme color palette for resolving theme colors
 * @param backgroundColor - Optional cell background color for auto text color resolution
 * @param enableComments - Whether to process comment marks (defaults to true)
 * @throws Does not throw; errors in mark processing are logged but do not interrupt processing
 */
export declare const applyMarksToRun: (run: TextRun | TabRun, marks: PMMark[], hyperlinkConfig?: HyperlinkConfig, themeColors?: ThemeColorPalette, backgroundColor?: string, enableComments?: boolean, storyKey?: string) => void;
//# sourceMappingURL=application.d.ts.map