UNPKG

2.58 kBTypeScriptView Raw
1export declare class Color {
2 readonly r: number;
3 readonly g: number;
4 readonly b: number;
5 readonly a: number;
6 /**
7 * Every color component should be in the [0, 1] range.
8 * Some easing functions (such as elastic easing) can overshoot the target value by some amount.
9 * So, when animating colors, if the source or target color components are already near
10 * or at the edge of the allowed [0, 1] range, it is possible for the intermediate color
11 * component value to end up outside of that range mid-animation. For this reason the constructor
12 * performs range checking/constraining.
13 * @param r Red component.
14 * @param g Green component.
15 * @param b Blue component.
16 * @param a Alpha (opacity) component.
17 */
18 constructor(r: number, g: number, b: number, a?: number);
19 /**
20 * The given string can be in one of the following formats:
21 * - #rgb
22 * - #rrggbb
23 * - rgb(r, g, b)
24 * - rgba(r, g, b, a)
25 * - CSS color name such as 'white', 'orange', 'cyan', etc.
26 * @param str
27 */
28 static fromString(str: string): Color;
29 private static hexRe;
30 private static shortHexRe;
31 static fromHexString(str: string): Color;
32 private static rgbRe;
33 private static rgbaRe;
34 static fromRgbaString(str: string): Color;
35 static fromArray(arr: [number, number, number] | [number, number, number, number]): Color;
36 /**
37 * Creates an instance of the Color class from the given HSB(A) components.
38 * @param h Hue in the [0, 360) range.
39 * @param s Saturation in the [0, 1] range.
40 * @param b Brightness in the [0, 1] range.
41 * @param alpha Opacity in the [0, 1] range. Defaults to 1 (completely opaque).
42 */
43 static fromHSB(h: number, s: number, b: number, alpha?: number): Color;
44 private static padHex;
45 toHexString(): string;
46 toRgbaString(fractionDigits?: number): string;
47 toString(): string;
48 toHSB(): [number, number, number];
49 /**
50 * Converts the given RGB triple to an array of HSB (HSV) components.
51 * The hue component will be `NaN` for achromatic colors.
52 */
53 static RGBtoHSB(r: number, g: number, b: number): [number, number, number];
54 /**
55 * Converts the given HSB (HSV) triple to an array of RGB components.
56 */
57 static HSBtoRGB(H: number, S: number, B: number): [number, number, number];
58 private derive;
59 brighter(): Color;
60 darker(): Color;
61 /**
62 * CSS Color Module Level 4:
63 * https://drafts.csswg.org/css-color/#named-colors
64 */
65 private static nameToHex;
66}