Color
Class of which each instance represents a specific color. The instances provide methods to generate a new color with modified properties, such as lightness or saturation.
Static Member Summary
Static Public Members | ||
public static |
BLACK: * |
|
public static |
GRAY: * |
|
public static |
WHITE: * |
Static Method Summary
Static Public Methods | ||
public static |
getByHexCode(code: string): Color Returns an instance of Color for a hex code |
|
public static |
Returns an instance of Color for a predefined color name. |
|
public static |
Creates an instance of Color from an HSL value |
Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Public Members | ||
public |
hexCode: * |
|
public get |
hsl: * |
|
public |
name: * |
|
public |
|
|
public |
rgb: * |
Method Summary
Public Methods | ||
public |
contrastLevel(otherColor: Color): string |
|
public |
Calculate the contrast ratio against another color |
|
public |
findBrightnessThreshold(otherColor: Color, level: string): Color Tries to find a color whose contrast against the base color is close to a given level. |
|
public |
findLightnessThreshold(otherColor: Color, level: string): Color Tries to find a color whose contrast against the base color is close to a given level. |
|
public |
hasSameLuminance(otherColor: Color): boolean |
|
public |
hasSufficientContrast(otherColor: Color, level: string): boolean Checks if the contrast ratio between the base color and otherColor meets the requirement of WCAG 2.0 |
|
public |
isBrighterThan(otherColor: Color): boolean |
|
public |
|
|
public |
|
|
public |
|
|
public |
isSameColor(otherColor: Color): boolean Checks if the base color and otherColor have the same RGB value |
|
public |
Returns a string representation of the color. |
|
public |
withBrightness(ratio: number, name: string): Color Return a new instance of Color with adjusted brightness. |
|
public |
withContrast(ratio: number, name: string): Color Return a new instance of Color with adjusted contrast. |
|
public |
withGrayscale(ratio: number, name: string): Color Return a grayscale of the original color. |
|
public |
withHueRotate(degree: number, name: string): Color Return a hue rotation applied color as an instance of Color. |
|
public |
withInvert(ratio: number, name: string): Color Return an inverted color as an instance of Color. |
|
public |
withSaturate(ratio: number, name: string): Color Return a saturated color as an instance of Color. |
Static Public Members
public static BLACK: * source
Properties:
Name | Type | Attribute | Description |
BLACK | Color | an instance that represents #000000 |
Static Public Methods
public static getByHexCode(code: string): Color source
Returns an instance of Color for a hex code
Params:
Name | Type | Attribute | Description |
code | string | RGB value in hex code |
public static getByName(name: string): Color source
Returns an instance of Color for a predefined color name.
Params:
Name | Type | Attribute | Description |
name | string | names are defined at https://www.w3.org/TR/SVG/types.html#ColorKeywords |
Public Constructors
Public Members
public hexCode: * source
Properties:
Name | Type | Attribute | Description |
hexCode | string | RGB value in hex code notation |
public get hsl: * source
public name: * source
Properties:
Name | Type | Attribute | Description |
name | string | If no name is explicitely given, the property is set to the value of this.hexCode |
public relativeLuminance: * source
Properties:
Name | Type | Attribute | Description |
relativeLuminance | number | Relative luminance of the color defined at https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef |
Public Methods
public contrastLevel(otherColor: Color): string source
Params:
Name | Type | Attribute | Description |
otherColor | Color |
public contrastRatioAgainst(color: Color | string | Array<number, number, number>): number source
Calculate the contrast ratio against another color
public findBrightnessThreshold(otherColor: Color, level: string): Color source
Tries to find a color whose contrast against the base color is close to a given level.
The returned color is gained by modifying the brightness of otherColor. Even when a color that satisfies the level is not found, it returns a new color anyway.
public findLightnessThreshold(otherColor: Color, level: string): Color source
Tries to find a color whose contrast against the base color is close to a given level.
The returned color is gained by modifying the lightness of otherColor. Even when a color that satisfies the level is not found, it returns a new color anyway.
public hasSameLuminance(otherColor: Color): boolean source
Params:
Name | Type | Attribute | Description |
otherColor | Color |
public hasSufficientContrast(otherColor: Color, level: string): boolean source
Checks if the contrast ratio between the base color and otherColor meets the requirement of WCAG 2.0
public isBrighterThan(otherColor: Color): boolean source
Params:
Name | Type | Attribute | Description |
otherColor | Color |
public isLightColor(): boolean source
Return:
boolean | true if the contrast ratio against white is qual to or less than the ratio against black |
public isSameColor(otherColor: Color): boolean source
Checks if the base color and otherColor have the same RGB value
Params:
Name | Type | Attribute | Description |
otherColor | Color |
public toString(base: number | null): string source
Returns a string representation of the color. When 16 is passed, it return the hex code, and when 10 is passed, it returns the value in RGB notation Otherwise, it returns the color name or the hex code
public withBrightness(ratio: number, name: string): Color source
Return a new instance of Color with adjusted brightness.
public withContrast(ratio: number, name: string): Color source
Return a new instance of Color with adjusted contrast.
public withGrayscale(ratio: number, name: string): Color source
Return a grayscale of the original color.
public withHueRotate(degree: number, name: string): Color source
Return a hue rotation applied color as an instance of Color.