/** sRGB colour: `r`/`g`/`b` in `0–255`, `a` in `0–1`. */ export interface RgbColor { r: number; g: number; b: number; a: number; } /** HSL colour: `h` in `0–360` degrees, `s`/`l` in `0–100` percent, `a` in `0–1`. */ export interface HslColor { h: number; s: number; l: number; a: number; } /** HSB (a.k.a. HSV) colour: `h` in `0–360` degrees, `s`/`b` in `0–100` percent, `a` in `0–1`; `b` is brightness, not blue. */ export interface HsbColor { h: number; s: number; b: number; a: number; } /** Serialisation targets for {@link formatColor}; `'hsb'` is this library's own notation, not CSS, so it round-trips through {@link parseColor} but must not go in a stylesheet. */ export type ColorFormat = 'hex' | 'rgb' | 'hsl' | 'hsb'; /** * Serialises an sRGB colour as `#rrggbb`, or `#rrggbbaa` when `includeAlpha` is set, clamping and rounding channels so a computed colour with `r: 255.4` still produces valid hex. * * @example * ```ts * rgbToHex({ r: 217, g: 76, b: 76, a: 0.5 }); // '#d94c4c' * rgbToHex({ r: 217, g: 76, b: 76, a: 0.5 }, true); // '#d94c4c80' * ``` */ export declare function rgbToHex(rgb: RgbColor, includeAlpha?: boolean): string; /** * Parses `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa` into sRGB, returning `null` for anything else, including 5- and 7-digit strings that look like hex but aren't a colour. * * @example * ```ts * hexToRgb('#f00'); // { r: 255, g: 0, b: 0, a: 1 } * hexToRgb('#ff000080'); // { r: 255, g: 0, b: 0, a: 0.502 } * hexToRgb('nope'); // null * ``` */ export declare function hexToRgb(hex: string): RgbColor | null; /** sRGB → HSB. A greyscale colour reports hue `0`, because it genuinely has none. */ export declare function rgbToHsb(rgb: RgbColor): HsbColor; /** HSB → sRGB. */ export declare function hsbToRgb(hsb: HsbColor): RgbColor; /** sRGB → HSL. */ export declare function rgbToHsl(rgb: RgbColor): HslColor; /** HSL → sRGB. */ export declare function hslToRgb(hsl: HslColor): RgbColor; /** HSB → HSL, computed directly rather than via RGB, since the detour would quantise to 8 bits and flatten near-black hues. */ export declare function hsbToHsl(hsb: HsbColor): HslColor; /** HSL → HSB, the exact inverse of {@link hsbToHsl}, also without an RGB detour. */ export declare function hslToHsb(hsl: HslColor): HsbColor; /** * Parses a colour string (hex, `rgb()`, `hsl()`, or this library's own `hsb()`) into the canonical {@link HsbColor}, returning `null` rather than throwing for anything unrecognized, including named colours. * * @example * ```ts * parseColor('#d94c4c'); // { h: 0, s: 64.98, b: 85.1, a: 1 } * parseColor('rgb(255 0 0 / 50%)'); // { h: 0, s: 100, b: 100, a: 0.5 } * parseColor('hsl(210, 60%, 85%)'); // { h: 210, s: 19.15, b: 94, a: 1 } * parseColor('rebeccapurple'); // null * ``` */ export declare function parseColor(input: string): HsbColor | null; /** * Serialises the canonical {@link HsbColor} back to a string in `format`, omitting alpha only when it equals 1 unless `alpha: false` forces it off; round-trips through {@link parseColor} to the precision `format` can carry. * * @example * ```ts * formatColor({ h: 0, s: 100, b: 100, a: 1 }, 'hex'); // '#ff0000' * formatColor({ h: 0, s: 100, b: 100, a: 0.5 }, 'hex'); // '#ff000080' * formatColor({ h: 0, s: 100, b: 100, a: 0.5 }, 'rgb'); // 'rgba(255, 0, 0, 0.5)' * formatColor({ h: 0, s: 100, b: 100, a: 0.5 }, 'hex', false); // '#ff0000' * ``` */ export declare function formatColor(color: HsbColor, format: ColorFormat, alpha?: boolean): string;