allc
Version:
A small typescript package for color conversion.
298 lines • 11.1 kB
TypeScript
import type { PerceptualColorSpace, RGBColorSpace } from "./index";
/**
* Represents a color. You can create colors from various color models and spaces.
*
* Instances of this class are immutable.
* On instantiation, the color is converted to CIE 1931 XYZ internally,
* and properties are calculated from that on access (lazily).
*
* ## Example
*
* ```ts
* const srgbRed = Color.fromRGB(1, 0, 0, "sRGB");
*
* // Logs the RGB values of the Display P3 representation.
* console.log(srgbRed.r("Display P3"), srgbRed.g("Display P3"), srgbRed.b("Display P3"));
* ```
*/
export declare class Color {
private readonly _X;
private readonly _Y;
private readonly _Z;
private constructor();
/**
* Creates a new color from the given CIE 1931 XYZ components.
*
* @param X The X component of CIE 1931 XYZ.
* @param Y The Y component of CIE 1931 XYZ.
* @param Z The Z component of CIE 1931 XYZ.
*
* @returns The new color.
*/
static fromCIE1931XYZ(X: number, Y: number, Z: number): Color;
/**
* Creates a new color from the given CIE 1931 xyY components.
*
* @param x The x component of CIE 1931 xyY, range [0, 1].
* @param y The y component of CIE 1931 xyY, range [0, 1].
* @param Y The Y component of CIE 1931 xyY, range [0, 1].
*
* @returns The new color.
*/
static fromCIE1931xyY(x: number, y: number, Y: number): Color;
/**
* Creates a new color from the given RGB components and color space.
*
* @param r The red component of RGB, typically in the range [0, 1].
* @param g The green component of RGB, typically in the range [0, 1].
* @param b The blue component of RGB, typically in the range [0, 1].
* @param colorSpace The RGB color space to use.
*
* @returns The new color.
*/
static fromRGB(r: number, g: number, b: number, colorSpace: RGBColorSpace): Color;
/**
* Creates a new color from the given hex string representation.
* The string can be in either of the formats listed below:
*
* * `"RGB"`
* * `"#RGB"`
* * `"RRGGBB"`
* * `"#RRGGBB"`
*
* Ignores any following characters. Defaults to 0 if the string/component is invalid.
*
* @param hex The hex string.
* @param colorSpace The RGB color space to use.
*
* @returns A new color.
*/
static fromHexString(hex: string, colorSpace: RGBColorSpace): Color;
/**
* Creates a new color from the given integer representation in the format `0xRRGGBB`.
* **All other bits will be ignored, including the alpha component.**
*
* @param integer The integer representation.
* @param colorSpace The RGB color space to use.
*
* @returns A new color.
*/
static fromInteger(integer: number, colorSpace: RGBColorSpace): Color;
/**
* Creates a new color from the given HSV components.
*
* @param h The hue component of HSV, unbounded, in radians.
* @param s The saturation component of HSV, range [0, 1].
* @param v The value component of HSV, range [0, 1].
* @param colorSpace The color space to use.
*
* @returns The new color.
*/
static fromHSV(h: number, s: number, v: number, colorSpace: RGBColorSpace): Color;
/**
* Creates a new color from the given HSL components.
*
* @param h The hue component of HSL, unbounded, in radians.
* @param s The saturation component of HSL, range [0, 1].
* @param l The value component of HSL, range [0, 1].
* @param colorSpace The color space to use.
*
* @returns The new color.
*/
static fromHSL(h: number, s: number, l: number, colorSpace: RGBColorSpace): Color;
/**
* Creates a new color from the given HSI components.
*
* @param h The hue component of HSI, unbounded, in radians.
* @param s The saturation component of HSI, range [0, 1].
* @param i The value component of HSI, range [0, 1].
* @param colorSpace The color space to use.
*
* @returns The new color.
*/
static fromHSI(h: number, s: number, i: number, colorSpace: RGBColorSpace): Color;
/**
* Creates a new color from the given linear RGB components.
*
* @param lr The red component of linear RGB, range [0, 1].
* @param lg The green component of linear RGB, range [0, 1].
* @param lb The blue component of linear RGB, range [0, 1].
* @param colorSpace The color space to use.
*
* @return The new color.
*/
static fromLinearRGB(lr: number, lg: number, lb: number, colorSpace: RGBColorSpace): Color;
/**
* Creates a new color from the given LAB components.
*
* @param l The luminance component of LAB, range [0, 1].
* @param a The a component of LAB, unbounded.
* @param b The b component of LAB, unbounded.
* @param colorSpace The color space to use.
*
* @return The new color.
*/
static fromLAB(l: number, a: number, b: number, colorSpace: PerceptualColorSpace): Color;
/**
* Creates a new color from the given LCH components.
*
* @param l The luminance component of LCH, range [0, 1].
* @param c The chromaticity component of LCH, unbounded.
* @param h The hue component of LCH, unbounded, in radians.
* @param colorSpace The color space to use.
*
* @returns The new color.
*/
static fromLCH(l: number, c: number, h: number, colorSpace: PerceptualColorSpace): Color;
/**
* Calculates the X component of the color in the CIE 1931 XYZ color space.
*/
X(): number;
/**
* Calculates the Y component of the color in the CIE 1931 XYZ color space.
*/
Y(): number;
/**
* Calculates the Z component of the color in the CIE 1931 XYZ color space.
*/
Z(): number;
/**
* Calculates the x component of the color in the CIE 1931 xyY color space.
*/
x(): number;
/**
* Calculates the y component of the color in the CIE 1931 xyY color space.
*/
y(): number;
/**
* Calculates the red component of the color in the RGB color model.
* @param colorSpace The color space to use.
*/
r(colorSpace: RGBColorSpace): number;
/**
* Calculates the green component of the color in the RGB color model.
* @param colorSpace The color space to use.
*/
g(colorSpace: RGBColorSpace): number;
/**
* Calculates the blue component of the color in the RGB color model.
* @param colorSpace The color space to use.
*/
b(colorSpace: RGBColorSpace): number;
/**
* Calculates the hex string representation in the format `"RRGGBB"` of the color in RGB.
* **Every component, including alpha, will be clamped to the range [0, 1] before processing.**
* If an alpha value is specified, the format will be `"RRGGBBAA"`.
*
* Uses {@link toHexStringFromRGB `toHexStringFromRGB(...)`} internally.
*
* @param colorSpace The color space to use.
* @param alpha - An optional alpha component, range [0, 1].
*
* @returns The hexadecimal representation of the color.
*/
hex(colorSpace: RGBColorSpace, alpha?: number): string;
/**
* Calculates the integer representation in the format `0xAARRGGBB` of the color in RGB.
* **Every component, including alpha, will be clamped to the range [0, 1] before processing.**
*
* Uses {@link toIntegerFromRGB `toIntegerFromRGB(...)`} internally.
*
* @param colorSpace The RGB color space to use.
* @param alpha The alpha value to use, range [0, 1], defaults to 0.
*
* @returns The integer representation of the color.
*/
int(colorSpace: RGBColorSpace, alpha?: number): number;
/**
* Calculates the shared hue component of the current color in the HSL/HSV color model.
* @param colorSpace The color space to use.
*/
h(colorSpace: RGBColorSpace): number;
/**
* Calculates the hue component of the color in the HSI color model.
* @param colorSpace The color space to use.
*/
h2(colorSpace: RGBColorSpace): number;
/**
* Calculates the saturation component of the color in the HSL color model.
* @param colorSpace The color model to use.
*/
sl(colorSpace: RGBColorSpace): number;
/**
* Calculates the saturation component of the color in the HSV color model.
* @param colorSpace The color space to use.
*/
sv(colorSpace: RGBColorSpace): number;
/**
* Calculates the saturation component of the color in the HSI color model.
* @param colorSpace The color space to use.
*/
si(colorSpace: RGBColorSpace): number;
/**
* Calculates the lightness component of the color in the HSL color model.
* @param colorSpace The color space to use.
*/
l(colorSpace: RGBColorSpace): number;
/**
* Calculates the value component of the color in the HSV color model.
* @param colorSpace The color space to use.
*/
v(colorSpace: RGBColorSpace): number;
/**
* Calculates the intensity component of the color in the HSI color model.
* @param colorSpace The color space to use.
*/
i(colorSpace: RGBColorSpace): number;
/**
* Calculates the red component of the color in linear RGB.
* @param colorSpace The color space to use.
*/
lr(colorSpace: RGBColorSpace): number;
/**
* Calculates the green component of the color in linear RGB.
* @param colorSpace The color space to use.
*/
lg(colorSpace: RGBColorSpace): number;
/**
* Calculates the blue component of the color in linear RGB.
* @param colorSpace The color space to use.
*/
lb(colorSpace: RGBColorSpace): number;
/**
* Calculates the shared luminance component of the color in the LAB/LCH color model.
* @param colorSpace The color space to use.
*/
pl(colorSpace: PerceptualColorSpace): number;
/**
* Calculates the a component of the color in the LAB color model.
* @param colorSpace The color space to use.
*/
pa(colorSpace: PerceptualColorSpace): number;
/**
* Calculates the b component of the color in the LAB color model.
* @param colorSpace The color space to use
*/
pb(colorSpace: PerceptualColorSpace): number;
/**
* Calculates the chromaticity component of the color in the LCH color model.
* @param colorSpace The color space to use.
*/
pc(colorSpace: PerceptualColorSpace): number;
/**
* Calculates the hue component of the color in the LCH color model.
* @param colorSpace The color space to use.
*/
ph(colorSpace: PerceptualColorSpace): number;
/**
* Calculates the CSS representation of the color.
*
* Uses {@link toCSSFromCIE1931XYZ `toCSSFromCIE1931XYZ(...)`} internally.
*
* @param alpha The alpha component, optional, range [0, 1].
*
* @returns The CSS representation of the color.
*/
css(alpha?: number): string;
}
//# sourceMappingURL=multi.d.ts.map