Re-scoped from @lilith/ui-theme to @cocotte/ui-theme. In-set cross-package deps re-pointed to @cocotte; out-of-set @lilith deps preserved (same Verdaccio). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
52 lines
No EOL
1.9 KiB
TypeScript
52 lines
No EOL
1.9 KiB
TypeScript
/**
|
|
* WCAG 2.1 Contrast Ratio Utilities
|
|
*
|
|
* Pure math functions for calculating contrast ratios between colors.
|
|
* Used for automated accessibility testing of theme color tokens.
|
|
*
|
|
* @see https://www.w3.org/TR/WCAG21/#contrast-minimum
|
|
*/
|
|
/**
|
|
* Check if a string is a valid hex color (#fff, #ffffff, #fffa, #ffffff80).
|
|
* Rejects rgba(), hsl(), named colors, etc.
|
|
*/
|
|
export declare function isHexColor(value: string): boolean;
|
|
/**
|
|
* Check if a string is an opaque hex color (#rgb or #rrggbb only).
|
|
* Rejects alpha-bearing hex (#rgba, #rrggbbaa) since contrast
|
|
* calculation requires compositing against a known background.
|
|
*/
|
|
export declare function isOpaqueHexColor(value: string): boolean;
|
|
/**
|
|
* Parse a hex color string to RGB tuple.
|
|
* Handles shorthand (#fff), full (#ffffff), and alpha (#ffffff80).
|
|
* Strips alpha channel — contrast calculation uses only RGB.
|
|
*
|
|
* @throws {Error} If input is not a valid hex color
|
|
*/
|
|
export declare function hexToRgb(hex: string): [number, number, number];
|
|
/**
|
|
* Calculate relative luminance per WCAG 2.1.
|
|
* Applies sRGB linearization then weighted sum.
|
|
*
|
|
* @see https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
|
|
*/
|
|
export declare function relativeLuminance(r: number, g: number, b: number): number;
|
|
/**
|
|
* Calculate WCAG 2.1 contrast ratio between two hex colors.
|
|
* Returns a number >= 1, where 21:1 is maximum (black on white).
|
|
*
|
|
* @example contrastRatio('#000000', '#ffffff') // 21
|
|
*/
|
|
export declare function contrastRatio(color1: string, color2: string): number;
|
|
type WCAGLevel = 'AA' | 'AA-large' | 'AAA';
|
|
/**
|
|
* Check whether a foreground/background pair meets a WCAG contrast level.
|
|
*
|
|
* - AA: 4.5:1 (normal text < 18pt)
|
|
* - AA-large: 3.0:1 (large text >= 18pt, UI components)
|
|
* - AAA: 7.0:1 (enhanced contrast)
|
|
*/
|
|
export declare function meetsWCAG(fg: string, bg: string, level: WCAGLevel): boolean;
|
|
export {};
|
|
//# sourceMappingURL=contrast.d.ts.map
|