The color to bind.
Optionaloptions: ColorOptionsOptional overrides and properties for the bound color.
Returns true if the bound color has hue or is grayscale elsColorspaces} [colorspace='lch'] The colorspace to use when checking if the color is grayscale or not.
import { color } from "@skchr/color";
import { formatHex8, interpolate, samples } from "culori"
var test = c => color(c).isAchromatic()
test('pink')
// false
let sample = [
"#164100",
"#ffff00",
"#310000",
'pink'
];
console.log(sample.map(test));
// [false, false, false,false]
test('gray')
// true
// we create an interpolation using black and white
let f = interpolate(["black", "white"]);
//We then create 12 evenly spaced samples and pass them to f as the `t` param required by an interpolating function.
// Lastly we convert the color to hex for brevity for this example (otherwise color objects work fine too.)
let grays = samples(12).map((c) => formatHex8(f(c)));
console.log(grays.map(test));
//
[ false, true, true,
true, true, true,
true, true, true,
true, true, false
]
Sets/Gets the opacity or alpha channel of a color. If the value parameter is omitted it gets the bound color's alpha value.
*
Optionalamount: string | numberThe value to apply to the opacity channel. The value is normalized to the range [0,1]. *
amount is omitted, or the color token with the new alpha.Gets the contrast value between the bound and comparison ( or against) color.
*
Optionalagainst: ColorTokenThe color to use for comparison. The default is 'black'.
*
Simulates how a color may be perceived by people with color vision deficiency.
To avoid writing the long types, the expected parameters for the kind of blindness are simply the colors that are hard to perceive for the type of color blindness:
'tritanopia' - An inability to distinguish the color 'blue'. The kind is 'blue'.
'deuteranopia' - An inability to distinguish the color 'green'.. The kind is 'green'.
'protanopia' - An inability to distinguish the color 'red'. The kind is 'red'.
Optionaloptions: DeficiencyOptionsOptions to customize the color vision deficiency simulation. *
* import { color } from '@skchr/color'
// Here we are simulating color blindness of tritanomaly or we can't see 'blue'.
// We are passing in our color as an array of channel values in the mode "rgb". The severity is set to 0.1
let tritanomaly = color(['rgb', 230, 100, 50, 0.5]).colorDeficiency('blue', 0.1)
console.log(tritanomaly)
// #dd663680
// Here we are simulating color blindness of tritanomaly or we can't see 'red'. The severity is not explicitly set so it defaults to 1
let protanopia = color({ h: 20, w: 50, b: 30, mode: 'hwb' }).colorDeficiency('red')
console.log(protanopia)
// #9f9f9f
Creates a color scale between an earth tone and any color token using spline interpolation.
Optionaloptions: EarthtoneOptionsOptional overrides for customising interpolation and easing functions.
import { color } from '@skchr/color'
let base = 'purple'
console.log(color(base).earthtone({num:8}))
ColorArray {
colors: [
'#352a21', '#3e2825',
'#4c2624', '#5f2028',
'#741033', '#860040',
'#940049', '#99004b'
]
}
console.log(color(base).earthtone({ iterations:8 }).output())
// call output() to only get results array
// [
'#352a21', '#3e2825',
'#4c2624', '#5f2028',
'#741033', '#860040',
'#940049', '#99004b'
]
Gets the hue family which a color belongs to with the overtone included (if it has one.).
For example 'red' or 'blue-green'. If the color is achromatic it returns the string 'gray'.
Hue shifting means that:
The minLightness and maxLightness values determine how dark or light our color will be at either extreme respectively.
The length of the resultant array is the number of samples (num) mult lied by 2 plus the base color passed in or (num * 2) + 1.
Optionaloptions: HueshiftOptionsThe optional overrides object to customize the hue shift options like easing function. *
Darkens the bound color by reducing the lightness channel by amount of the channel. For example 0.3 means reduce the lightness by 0.3 of the channel's current value.
Optionalamount: numberThe amount to darken with. The value is expected to be in the range [0,1]. Default is 0.1.
Gets the luminance of the passed in color token.
If the amount parameter is not passed in else it will adjust the luminance by interpolating the color with black (to decrease luminance) or white (to increase the luminance) by the specified amount.
*
Optionalamount: numberThe luminance value to set on the bound color. *
amount is omitted, or the color token with the new luminance.Sets the value of the specified channel on the passed in color.
If the amount parameter is undefined it gets the value of the specified channel.
*
The mode and channel to be retrieved. For example rgb.b will return the value of the blue channel's value in the RGB color space of that color.
*
Optionalvalue: string | numberThe value to set on the queried channel. Also supports expressions as strings e.g "#fc23a1" "*0.5". The supported symbols: * + - /.
*
value is omitted, or the color token with the new channel value.
*Returns the final value from the chain.
Creates a palette that consists of a baseColor that is incremented by a hueStep to get the final color to pair with.
The colors are then spline interpolated via white or black.
A negative hueStep will pick a color that is hueStep degrees behind the base color.
Optionaloptions: PairedSchemeOptionsThe optional overrides object to customize per channel options like interpolation methods and channel fixups.
Returns a randomized pastel variant of the bound color token. Preserves the bound ColorToken type.
Sets/Gets the saturation value of the bound color. *
Optionalamount: numberThe amount of saturation to set on the bound color token. Also supports string expressions. *
amount is omitted, or the color token with the new saturation.Returns a randomised classic color scheme from the bound color.
Optionaloptions: SchemeOptionsParses any recognizable color to the specified kind of ColorToken type.
The kind option supports the following types as options:
'array' - Parses the color token to an array of channel values with the colorspace as the first element if the omitMode parameter is set to false in the options object.
'number' - Parses the color token to its numerical equivalent to a number between 0 and 16,777,215.
The numberType can be used to specify which type of number to return if the kind option is set to 'number':
'hexadecimal''binary''octal''decimal' exponential notation'hex' - Parses the color token to its hexadecimal string equivalent.If the color token has an explicit alpha (specified by the alpha key in color objects and as the fourth and last number in a color array) the string will be 8 characters long instead of 6.
'object' - Parses the color token to a plain color object in the mode specified by the targetMode parameter in the options object.Optionaloptions: TokenOptionsInterpolates the bound color via the origin with the point t at 0.5.
The color to interpolate via.
Creates a lazy chain wrapper over a single color token that has all the functions that take a
ColorTokenas their first argument.Example