import {ColorContrastCalc} from 'color-contrast-calc/lib/color-contrast-calc.js'
ColorContrastCalc
Provides the top-level name space of this library.
Static Member Summary
Static Public Members | ||
public static |
NAMED_COLORS: * Array of named colors defined at https://www.w3.org/TR/SVG/types.html#ColorKeywords |
|
public static |
Array of web safe colors |
Static Method Summary
Static Public Methods | ||
public static |
Returns an instance of Color. |
|
public static |
colorsWithSufficientContrast(color: Color, level: string): Color[] Returns an array of named colors that satisfy a given level of contrast ratio |
|
public static |
compareFunction(colorOrder: string, keyType: string, keyMapper: function): function Returns a function to be used as a parameter of Array.prototype.sort() |
|
public static |
Returns an array of colors which share the same saturation and lightness. |
|
public static |
Sorts colors in an array and returns the result as a new array |
Static Public Members
public static NAMED_COLORS: * source
Array of named colors defined at https://www.w3.org/TR/SVG/types.html#ColorKeywords
Properties:
Name | Type | Attribute | Description |
NAMED_COLORS | Color[] |
Static Public Methods
public static colorFrom(colorValue: string | Array<number, number, number>, name: string): Color source
Returns an instance of Color.
As colorValue, you can pass a predefined color name, or an RGB value represented as an array of Integers or a hex code such as [255, 255, 255] or "#ffff00". name is assigned to the returned instance if it does not have a name already assigned.
public static colorsWithSufficientContrast(color: Color, level: string): Color[] source
Returns an array of named colors that satisfy a given level of contrast ratio
public static compareFunction(colorOrder: string, keyType: string, keyMapper: function): function source
Returns a function to be used as a parameter of Array.prototype.sort()
Params:
Name | Type | Attribute | Description |
colorOrder | string |
|
A left side primary color has a higher sorting precedence |
keyType | string |
|
Type of keys used for sorting: "color", "hex" or "rgb" |
keyMapper | function |
|
A function used to retrive key values from elements to be sorted |
public static hslColors(s: number, l: number, h_interval: number): Color[] source
Returns an array of colors which share the same saturation and lightness. By default, so-called pure colors are returned.
Params:
Name | Type | Attribute | Description |
s | number |
|
Ratio of saturation in percentage. |
l | number |
|
Ratio of lightness in percentage. |
h_interval | number |
|
Interval of hues given in degrees. By default, it returns 360 hues beginning from red. (Red is included twice, because it corresponds to 0 and 360 degrees.) |
public static sort(colors: Color[] | String[], colorOrder: string, keyMapper: function, mode: string): Color[] source
Sorts colors in an array and returns the result as a new array
Params:
Name | Type | Attribute | Description |
colors | Color[] | String[] | List of colors |
|
colorOrder | string |
|
A left side primary color has a higher sorting precedence, and an uppercase letter means descending order |
keyMapper | function |
|
A function used to retrive key values from elements to be sorted |
mode | string |
|
If set to "hex", key values are handled as hex code strings |