TinyColor
Class in @sascom/commonjs.
API catalogue · @sascom/commonjs · Class
Members#
| Member | Kind | Description |
|---|---|---|
| constructor | Method | Create a tinycolor instance of the color named. |
| analogous | Method | Gets an analogous color scheme based off of the current color. |
| brighten | Method | Brighten the color a given amount. |
| clone | Method | Gets a new instance with the current color |
| complement | Method | Gets the complement of the current color |
| darken | Method | Darken the color a given amount. Providing 100 will always return black. |
| desaturate | Method | Desaturate the color a given amount. Providing 100 will is the same as calling greyscale. |
| getAlpha | Method | Returns the alpha value of the color |
| getBrightness | Method | Returns the perceived brightness of the color, from 0-255. |
| getFormat | Method | Returns the format used to create the tinycolor instance. |
| getLuminance | Method | Returns the perceived luminance of a color, from 0-1. |
| getOriginalInput | Method | Returns the input passed into the constructer used to create the tinycolor instance. |
| greyscale | Method | Completely desaturates a color into greyscale. Same as calling desaturate(100). |
| isDark | Method | Return an indication whether the color's perceived brightness is dark. |
| isLight | Method | Return an indication whether the color's perceived brightness is light. |
| isValid | Method | Return an indication whether the color was successfully parsed. |
| lighten | Method | Lighten the color a given amount. Providing 100 will always return white. |
| monochromatic | Method | Gets a monochromatic color scheme based off of the current color. |
| saturate | Method | Saturate the color a given amount. |
| setAlpha | Method | Sets the alpha value on the current color. |
| spin | Method | Spin the hue a given amount. Calling with 0, 360, or -360 will do nothing. |
| splitcomplement | Method | Gets a split complement color scheme based off of the current color. |
| tetrad | Method | Gets a tetrad based off of the current color. |
| toFilter | Method | Returns the color represented as a Microsoft filter for use in old versions of IE. |
| toHex | Method | Returns the hex value of the color. |
| toHex8 | Method | Returns the hex 8 value of the color. |
| toHex8String | Method | Returns the hex 8 value of the color -with a # appened. |
| toHexString | Method | Returns the hex value of the color -with a # appened. |
| toHsl | Method | Returns the object as a HSLA object. |
| toHslString | Method | Returns the hsla values interpolated into a string with the following format: "hsla(xxx, xxx, xxx, xx)". |
| toHsv | Method | Returns the object as a HSVA object. |
| toHsvString | Method | Returns the hsva values interpolated into a string with the following format: "hsva(xxx, xxx, xxx, xx)". |
| toName | Method | The 'real' name of the color -if there is one. |
| toPercentageRgb | Method | Returns the object as a RGBA object. |
| toPercentageRgbString | Method | Returns the RGBA relative values interpolated into a string with the following format: "RGBA(xxx, xxx, xxx, xx)". |
| toRgb | Method | Returns the object as a RGBA object. |
| toRgba | Method | Returns the color as [r, g, b, a], every component in 0..1. |
| toRgbString | Method | Returns the RGBA values interpolated into a string with the following format: "RGBA(xxx, xxx, xxx, xx)". |
| toString | Method | String representation of the color. |
| triad | Method | Gets a triad based off of the current color. |
| equals | Method | Compares two colors. Each colors can be any color inputs. |
| fromFloatObject | Method | Create a tinycolor from components in 0..1. |
| fromRatio | Method | Create a tinycolor instance based off the relative values. Works with any color formats |
| isReadable | Method | Ensure that foreground and background color combinations meet WCAG2 guidelines. |
| mostReadable | Method | Given a base color and a list of possible foreground or background colors for that base, returns the most readable color. Optionally returns Black or White i… |
| random | Method | Returns a random color |
| readability | Method | Compares the two colors and returns the constrast between two colors as a number. |
constructor#
constructor(color?: ColorInput, opts?: ConstructorOptions)Create a tinycolor instance of the color named.
Parameters#
| Name | Type | Description |
|---|---|---|
color |
tinycolor.ColorInput | the color as one of the valid color input format. |
opts |
tinycolor.ConstructorOptions |
analogous#
Gets an analogous color scheme based off of the current color.
Parameters#
| Name | Type | Description |
|---|---|---|
results |
number |
The amount of results to return. Default value: 6. |
slices |
number |
The amount to slice the input color by. Default value: 30. |
brighten#
Brighten the color a given amount.
Parameters#
| Name | Type | Description |
|---|---|---|
amount |
number |
The amount to brighten by. The valid range is 0 to 100. Default value: 10. |
clone#
Gets a new instance with the current color
complement#
Gets the complement of the current color
darken#
Darken the color a given amount. Providing 100 will always return black.
Parameters#
| Name | Type | Description |
|---|---|---|
amount |
number |
The amount to darken by. The valid range is 0 to 100. Default value: 10. |
desaturate#
Desaturate the color a given amount. Providing 100 will is the same as calling greyscale.
Parameters#
| Name | Type | Description |
|---|---|---|
amount |
number |
The amount to desaturate by. The valid range is 0 to 100. Default value: 10. |
getAlpha#
getAlpha(): numberReturns the alpha value of the color
getBrightness#
getBrightness(): numberReturns the perceived brightness of the color, from 0-255.
getFormat#
getFormat(): stringReturns the format used to create the tinycolor instance.
getLuminance#
getLuminance(): numberReturns the perceived luminance of a color, from 0-1.
getOriginalInput#
getOriginalInput(): ColorInputReturns the input passed into the constructer used to create the tinycolor instance.
greyscale#
Completely desaturates a color into greyscale. Same as calling desaturate(100).
isDark#
isDark(): booleanReturn an indication whether the color's perceived brightness is dark.
isLight#
isLight(): booleanReturn an indication whether the color's perceived brightness is light.
isValid#
isValid(): booleanReturn an indication whether the color was successfully parsed.
lighten#
Lighten the color a given amount. Providing 100 will always return white.
Parameters#
| Name | Type | Description |
|---|---|---|
amount |
number |
The amount to lighten by. The valid range is 0 to 100. Default value: 10. |
monochromatic#
Gets a monochromatic color scheme based off of the current color.
Parameters#
| Name | Type | Description |
|---|---|---|
results |
number |
The amount of results to return. Default value: 6. |
saturate#
Saturate the color a given amount.
Parameters#
| Name | Type | Description |
|---|---|---|
amount |
number |
The amount to saturate by. The valid range is 0 to 100. Default value: 10. |
setAlpha#
Sets the alpha value on the current color.
Parameters#
| Name | Type | Description |
|---|---|---|
alpha |
number |
The new alpha value. The accepted range is 0-1. |
spin#
Spin the hue a given amount. Calling with 0, 360, or -360 will do nothing.
Parameters#
| Name | Type | Description |
|---|---|---|
amount |
number |
The amount to spin by. The valid range is -360 to 360. |
splitcomplement#
Gets a split complement color scheme based off of the current color.
tetrad#
Gets a tetrad based off of the current color.
toFilter#
toFilter(): stringReturns the color represented as a Microsoft filter for use in old versions of IE.
toHex#
toHex(): stringReturns the hex value of the color.
toHex8#
toHex8(): stringReturns the hex 8 value of the color.
toHex8String#
toHex8String(): stringReturns the hex 8 value of the color -with a # appened.
toHexString#
toHexString(): stringReturns the hex value of the color -with a # appened.
toHsl#
Returns the object as a HSLA object.
toHslString#
toHslString(): stringReturns the hsla values interpolated into a string with the following format: "hsla(xxx, xxx, xxx, xx)".
toHsv#
Returns the object as a HSVA object.
toHsvString#
toHsvString(): stringReturns the hsva values interpolated into a string with the following format: "hsva(xxx, xxx, xxx, xx)".
toName#
toName(): string | falseThe 'real' name of the color -if there is one.
toPercentageRgb#
Returns the object as a RGBA object.
toPercentageRgbString#
toPercentageRgbString(): stringReturns the RGBA relative values interpolated into a string with the following format: "RGBA(xxx, xxx, xxx, xx)".
toRgb#
Returns the object as a RGBA object.
toRgba#
toRgba(): [number, number, number, number]Returns the color as [r, g, b, a], every component in 0..1.
toRgbString#
toRgbString(): stringReturns the RGBA values interpolated into a string with the following format: "RGBA(xxx, xxx, xxx, xx)".
toString#
toString(format?: "name" | "rgb" | "prgb" | "hex" | "hex6" | "hex3" | "hex4" | "hex8" | "hsl" | "hsv"): stringString representation of the color.
Parameters#
| Name | Type | Description |
|---|---|---|
format |
"name" | "rgb" | "prgb" | "hex" | "hex6" | "hex3" | "hex4" | "hex8" | "hsl" | "hsv" |
The format to be used when displaying the string representation. The accepted values are: "rgb", "prgb", "hex6", "hex3", "hex8", "name", "hsl", "hsv". |
triad#
Gets a triad based off of the current color.
equals#
static equals(color1?: ColorInput, color2?: ColorInput): booleanCompares two colors. Each colors can be any color inputs.
Parameters#
| Name | Type | Description |
|---|---|---|
color1 |
tinycolor.ColorInput | |
color2 |
tinycolor.ColorInput |
fromFloatObject#
static fromFloatObject(object: { a: number; b: number; g: number; r: number }): TinyColorCreate a tinycolor from components in 0..1.
Parameters#
| Name | Type | Description |
|---|---|---|
object |
{ a: number; b: number; g: number; r: number } |
fromRatio#
static fromRatio(ratio?: ColorInputWithoutInstance): TinyColorCreate a tinycolor instance based off the relative values. Works with any color formats
Parameters#
| Name | Type | Description |
|---|---|---|
ratio |
tinycolor.ColorInputWithoutInstance | the relative color/hue values to apply to the new instance. |
isReadable#
static isReadable(color1: ColorInput, color2: ColorInput, wcag2?: WCAG2Options): booleanEnsure that foreground and background color combinations meet WCAG2 guidelines.
Parameters#
| Name | Type | Description |
|---|---|---|
color1 |
tinycolor.ColorInput | the fore color wanted. |
color2 |
tinycolor.ColorInput | the back color wanted. |
wcag2 |
tinycolor.WCAG2Options | WCAG option. If the entire object is absent, function use the default of {level:"AA",size:"small"}. |
mostReadable#
static mostReadable(baseColor: ColorInput, colorList: (ColorInput)[], args?: MostReadableArgs): TinyColorGiven a base color and a list of possible foreground or background colors for that base, returns the most readable color. Optionally returns Black or White if the most readable color is unreadable.
Parameters#
| Name | Type | Description |
|---|---|---|
baseColor |
tinycolor.ColorInput | the base color. |
colorList |
(ColorInput)[] |
array of colors to pick the most readable one from. |
args |
tinycolor.MostReadableArgs | and object with extra arguments |
random#
Returns a random color
readability#
static readability(color1: ColorInput, color2: ColorInput): numberCompares the two colors and returns the constrast between two colors as a number.
Parameters#
| Name | Type | Description |
|---|---|---|
color1 |
tinycolor.ColorInput | the first color to be used in the comparison. |
color2 |
tinycolor.ColorInput | the second color to be used in the comparison. |