@itwin/itwinui-react
Version:
A react component library for iTwinUI
181 lines (180 loc) • 5.74 kB
TypeScript
/**
* A color defined by Red, Green, and Blue
*/
export type RgbColor = {
/** 0-255 */
r: number;
/** 0-255 */
g: number;
/** 0-255 */
b: number;
/** 0-1 */
a?: number;
};
/**
* A color defined by Hue, Saturation, and Lightness.
*/
export type HslColor = {
/** 0-360 */
h: number;
/** 0-100 */
s: number;
/** 0-100 */
l: number;
/** 0-1 */
a?: number;
};
/**
* A color defined by Hue, Saturation, and Value
*/
export type HsvColor = {
/** 0-360 */
h: number;
/** 0-100 */
s: number;
/** 0-100 */
v: number;
/** 0-1 */
a?: number;
};
/**
* All supported color specifications.
*/
export type ColorType = string | RgbColor | HslColor | HsvColor;
/**
* isRgbValue type guard.
*/
export declare const isRgbColor: (value: ColorType) => value is RgbColor;
/**
* isHslValue type guard.
*/
export declare const isHslColor: (value: ColorType) => value is HslColor;
/**
* isHsvValue type guard.
*/
export declare const isHsvColor: (value: ColorType) => value is HsvColor;
/**
* An immutable integer representation of a color.
*
* Colors are stored as 4 components: Red, Blue, Green, and Transparency (0=fully opaque). Each is an 8-bit integer between 0-255.
* ColorValue uses `0xTTBBGGRR` (red in the low byte. 0==fully opaque in high byte) internally, but it also provides methods
* to return colors in popular web formats.
*
* The `create` method accepts any ColorType format.
*
* @public
*/
export declare class ColorValue {
private readonly _tbgr;
/** hue value provided by user */
private readonly _hue?;
private constructor();
/**
* Create a new ColorValue.
* @param val value to use.
*
* If a string, must be in one of the following forms:
* *"rgb(255,0,0)"*
* *"rgba(255,0,0,.2)"*
* *"rgb(100%,0%,0%)"*
* *"hsl(120,50%,50%)"*
* *"#rrggbb"*
*/
static create(val?: ColorType): ColorValue;
/**
* Convert this ColorValue to an unsigned 32 bit integer representing the 0xTTBBGGRR value
*/
toTbgr(): number;
/**
* Create a ColorValue from its 0xTTBBGGRR representation.
*/
static fromTbgr(tbgr: number): ColorValue;
/**
* Create a ColorValue from Red, Green, Blue, Transparency values. All inputs should be integers between 0-255.
*/
private static fromRgbt;
/**
* Compute the 0xTTBBGGRR value corresponding to the specified Red, Green, Blue, Transparency components.
* All inputs should be integers between 0-255.
*/
private static computeTbgrFromComponents;
/**
* Create a ColorValue from a string representation. The following representations are supported:
* *"rgb(255,0,0)"*
* *"rgba(255,0,0,.2)"*
* *"rgb(100%,0%,0%)"*
* *"hsl(120,50%,50%)"*
* *"#rrggbb"*
* NOTE: If defaultColorIfNotParsed is not defined and string is invalid then error is thrown.
* This allows component builders to know if they received bad input from user.
*/
static fromString(val: string, defaultColorIfNotParsed?: ColorValue): ColorValue;
/** Create a ColorValue from hue, saturation, lightness values. */
private static fromHSL;
/** Create a ColorValue from an RgbColor */
private static fromRGB;
/**
* Create a ColorValue from an HsvColor
*/
private static fromHSV;
/**
* Compute the 0xTTBBGGRR value corresponding to a string representation of a color. The following representations are supported:
* *"rgb(255,0,0)"*
* *"rgba(255,0,0,.2)"*
* *"rgb(100%,0%,0%)"*
* *"hsl(120,50%,50%)"*
* *"#rrggbb"*
*/
private static computeTbgrFromString;
/**
* Get the r,g,b,t values encoded in an 0xTTBBGGRR value. Values will be integers between 0-255.
*/
private static getColors;
/**
* Get the RGB value of the 0xTTBBGGRR color as a number in 0xRRGGBB or 0xRRGGBBAA format
*/
private getRgb;
/**
* Get the alpha value for this ColorDef. Will be between 0-255
*/
getAlpha(): number;
/**
* Extract the alpha value from a 0xTTBBGGRR color.
*/
private static getAlpha;
/**
* Convert this ColorValue to a string in the form "#rrggbb" or "#rrggbbaa" where values are hex digits of the respective colors
*/
toHexString(includeAlpha?: boolean): string;
/**
* Compute the 0xTTBBGGRR color corresponding to the specified hue, saturation, lightness values.
*/
private static computeTbgrFromHSL;
/**
* Return HslColor from this ColorValue
*/
toHslColor(): HslColor;
/** Create an HslColor from this ColorValue */
private static toHsl;
/**
* Create an RgbColor from this ColorValue
*/
toRgbColor(): RgbColor;
/**
* Return HsvColor from this ColorValue
*/
toHsvColor(): HsvColor;
/**
* Create an HsvColor from this ColorValue
*/
private static toHsv;
/** True if the value of this ColorValue is the same as another ColorValue. */
equals(other: ColorValue): boolean;
static getFormattedColorNumber(value: number, precision?: number): string;
/** Convert the 0xTTBBGGRR color to a string of the form "rgba(r,g,b,a)" where the color components are specified in decimal and the alpha component is a fraction. */
toRgbString(includeAlpha?: boolean): string;
/** Convert this ColorValue to a string in the form "hsl(h,s,l) or hsla(h,s,l,a)" - i.e hsl(120,50%,50%). */
toHslString(includeAlpha?: boolean): string;
/** Convert this ColorValue to a string in the form "hsv(h,s,v) or hsva(h,s,v,a)" - i.e hsv(120,50%,50%). */
toHsvString(includeAlpha?: boolean): string;
}