import * as colors from "https://deno.land/x/colors@v2.0.2/mod.ts";
A collection of functions to extract information from colors, generate shades and tints, convert to other color spaces, etc.
Note: All methods either accept RGB/RGBA colors as parameters or give RGB/RGBA colors as results. In order to work with other color spaces (eg. XYZ), convert them to RGB first.
Examples
Example 1
Example 1
// Deno /x
import { rgbaFromHex, xyz, lab } from "https://deno.land/x/colors/mod.ts";
// Deno JSR
import { rgbaFromHex, xyz, lab } from "jsr:@retraigo/colors";
// Node JSR (after installation)
import { rgbaFromHex, xyz, lab } from "jsr:@retraigo/colors";
const color = rgbaFromHex("#fceff1");
// CIE XYZ color space
console.log(xyz(color));
// CIE LAB color space
console.log(lab(color));
// Conversion of color into all supported spaces
console.log(json(color));
Variables
6 / 29 | |
4 / 29 | |
(6 / 29)^3 | |
(6 / 29)^2 | |
Standard illuminant D65 |
Functions
Get average of colors. Can be used for grayscale. | |
Calculate chroma | |
f cmyk | Convert RGB(A) to CMYK |
Get contrast ratio | |
Find the nearest neighbour of a color in a palette It would be more accurate to use consider luminance along with Euclidean distance but I chose to stay with distance for performance. | |
Convert RGBA to grayscale using luminance | |
f hcg | Convert RGB(A) to HCG |
f hex | Convert RGB(A) to Hex |
f hsl | Convert RGB(A) to Hue, Saturation, Lightness |
f hsv | Convert RGB(A) to Hue, Saturation, Value |
f hue | Calculate hue using chroma |
Inverse lab function | |
Invert HSV | |
Invert a color linearly | |
Bright colors darken, dark colors brighten. | |
f json | |
f lab | CIE Lab color space |
f labF | t = C / Cn ratio |
Get lightness of color. | |
Get linear rgb values | |
Calculate luminance from RGB or RGBA color | |
f max | Get maximum of r, g, b, a, scaled to [0, 1]. |
Calculate mean distance between two colors | |
f min | Get minimum of r, g, b, a, scaled to [0, 1]. |
f mix | Mix with a different color. Copyright (c) 2006-2009 Hampton Catlin, Natalie Weizenbaum, and Chris Eppstein http://sass-lang.com |
Get perceived lightness | |
Convert Hexadecimal string to RGBA | |
Convert CMYK to RGB | |
Convert HSL color to RGB | |
Convert HSV color to RGB | |
Convert CIE Lab to Linear RGB color space | |
Convert CIE XYZ to Linear RGB color space | |
Get saturation | |
Get a shade of the color | |
Stringify the RGBA color | |
f tint | Get a tint of the color |
f xyz | CIE 1931 XYZ |
Convert CIE Lab* to CIE XYZ |
Type Aliases
1-Channel Color (Grayscale) | |
3-Channel Color | |
4-Channel Color | |
A record of color spaces and values for the color in those spaces. |