/** A color space a `Color` can be expressed in. */ export type ColorSpace = 'rgb' | 'hsl' | 'hsb' | 'oklch'; /** A single adjustable component of a color. */ export type ColorChannel = 'red' | 'green' | 'blue' | 'hue' | 'saturation' | 'lightness' | 'brightness' | 'chroma' | 'alpha'; /** A string form `formatColor` can produce and `parseColor` can read back. */ export type ColorFormat = 'hex' | 'hexa' | 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'hsb' | 'hsba' | 'oklch' | 'oklcha'; /** sRGB color. Channels are 0-255, alpha is 0-1. */ export interface RgbColor { space: 'rgb'; red: number; green: number; blue: number; alpha: number; } /** HSL color. Hue is 0-360, saturation and lightness are 0-100, alpha is 0-1. */ export interface HslColor { space: 'hsl'; hue: number; saturation: number; lightness: number; alpha: number; } /** HSB (a.k.a. HSV) color. Hue is 0-360, saturation and brightness are 0-100, alpha is 0-1. */ export interface HsbColor { space: 'hsb'; hue: number; saturation: number; brightness: number; alpha: number; } /** OKLCh color. Lightness is 0-100, chroma is 0-0.4, hue is 0-360, alpha is 0-1. */ export interface OklchColor { space: 'oklch'; lightness: number; chroma: number; hue: number; alpha: number; } /** A color value in one of the supported color spaces. */ export type Color = RgbColor | HslColor | HsbColor | OklchColor; /** The bounds and increments of a channel within a given color space. */ export interface ColorChannelRange { /** Lowest value the channel accepts. */ minValue: number; /** Highest value the channel accepts. */ maxValue: number; /** Increment applied by an arrow key. */ step: number; /** Increment applied by Page Up, Page Down, or a shifted arrow key. */ pageSize: number; } /** The three channels of a color space, mapped onto the axes of a color area. */ export interface ColorAxes { /** Channel driven by the horizontal axis. */ xChannel: ColorChannel; /** Channel driven by the vertical axis. */ yChannel: ColorChannel; /** Channel held constant, and so not represented by either axis. */ zChannel: ColorChannel; } /** Returns the three channels that define `space`, in canonical order. */ export declare function getColorChannels(space: ColorSpace): [ColorChannel, ColorChannel, ColorChannel]; /** Returns the bounds and increments of `channel` within `space`. */ export declare function getChannelRange(space: ColorSpace, channel: ColorChannel): ColorChannelRange; /** Reads a single channel off a color. Throws if the channel is not in the color's space. */ export declare function getChannelValue(color: Color, channel: ColorChannel): number; /** Returns a copy of `color` with `channel` clamped into range and set to `value`. */ export declare function withChannelValue(color: Color, channel: ColorChannel, value: number): Color; /** * Resolves the x, y and z channels of a color area. Unspecified axes fall back to * the first channels of `space` that are still free. */ export declare function getColorSpaceAxes(space: ColorSpace, axes?: Partial>): ColorAxes; /** Converts `color` into `space`. Returns the same object when it is already there. */ export declare function convertColor(color: Color, space: S): Extract; /** Returns the English display name of `channel`, for labels and value text. */ export declare function getChannelName(channel: ColorChannel): string; /** Formats a channel value for display, with the unit the channel is measured in. */ export declare function formatChannelValue(color: Color, channel: ColorChannel): string; /** * Parses a CSS color string into a `Color`. Accepts hex (3, 4, 6 or 8 digits), * `rgb()`, `hsl()`, `oklch()` in both comma and space separated forms, plus the * non-CSS `hsb()` used by design tools. Throws on anything else. */ export declare function parseColor(value: string): Color; /** Parses `value` into a `Color`, returning `undefined` instead of throwing on bad input. */ export declare function safeParseColor(value: string): Color | undefined; /** * Serializes `color` to a CSS string. `'css'` picks the shortest form the browser * understands for the color's own space, which is what you want for a `background`. */ export declare function formatColor(color: Color, format?: ColorFormat | 'css'): string; //# sourceMappingURL=color.d.ts.map