1.0.12 • Published 11 months ago

@dynamize/color-utilities v1.0.12

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Color Utilities

Tools for all your color needs

Color utilities is a collection of tools used to work with colors.

Features

  • Color conversions (ansi16, ansi256, cmy, cmyk, tsl, hsl, hsv, lab, luv, lch xyz ...)
  • Color blending
  • Color harmony pallet creation
  • Color mixers ( such as getting shades, tints and tones)
  • Performing Chromatic adaptation

Table of Contents

About Color Utilities

Color Utilities aims to be a one-stop shop for any work related to colors, mostly built with pure functions One can use as little or as much of it as needed or wanted, avoiding unneeded project bloating. In the future, this library will most probably grow further.

Limits

Due to the nature of color spaces, certain conversions are more computationally taxing than others. Further, certain conversions lead to data loss like RGB to Ansi16 and then back to RGB will most probably result in a significant difference in color.

Documentation

npm install --save @dynamize/color-utilities

Dependencies

This library has no dependencies and is completely self-contained.

Importing

Importing is done using the ES static import declaration. Example:

import { Color } from "@dynamize/color-utilities";

In order to use the import declaration in a source file, the file must be interpreted by the runtime as a module.

Color

A Color class is a representation of a color in Color Utilities. Use case for this is when you know you will need values for more then one color space.

Usage examples:

import { Color } from "@dynamize/color-utilities";

const color = new Color("rgb", { red: 238, green: 200, blue: 27 });

console.log(color.data);
Param placeDescriptionFormats
1stSpace in which color values are passedadobe_98_rgb", "apple_rgb", "ansi16", "ansi256", "best_rgb", "beta_rgb", "bruce_rgb", "cie_rgb", "color_match_rgb", "cmy", "cmyk", "don_rgb_4", "eci_rgb_v2" "etka_space_ps5", "hcy", "hex", "hsi", "hsl", "hsv", "hunter_lab", "hwb", "lab", "lch_ab", "lch_uv", "luv", "lms", "ntsc_rgb", "pal_secam_rgb", "pro_photo_rgb", "rgb", "ryb", "tsl", "smpte_c_rgb", "wide_gamut_rgb", "uvw","xvycc", "xyy", "xyz", "ycbcr_BT601", "yccbccrc", "ycocg", "ydbdr", "yiq", "ypbpr"
2ndColor valuesnumber, string, or color data object
3rdoptional - colors spaces to computestring [] of "all"
  • The first argument we pass is a string value and it represents the space in which color values will be passed.
  • The second argument is the actual color values and it's passed in form of an object.
  • The third argument is optional and has a form of string array or a string "all", if not passed, automatically values for hex, hvs, lab, and cmyk, will be computed, alternatively color spaces listed in the array will be computed.

The result of the above example is:

 Color {
  rgb: { red: 238, green: 200, blue: 27, inGamut: true },
  xyz: { x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 },
  hex: 'EEC81B',
  hsv: { hue: 49, saturation: 89, value: 93 },
  lab: {
    luminance: 81.60296053275202,
    a: -1.2482727232548951,
    b: 79.33052440955292
 },
 cmyk: {
   cyan: 0,
   magenta: 15.96638655462185,
   yellow: 88.65546218487395,
   key: 6.666666666666665
  }
 }

Lets see an alternative use:

import { Color } from "@dynamize/color-utilities";

const color = new Color("rgb", { red: 238, green: 200, blue: 27 }, [
  "hsl",
  "luv",
  "ryb",
  "tsl",
]);

console.log(color.data);

Result from the above example would be:

Color {
  rgb: { red: 238, green: 200, blue: 27, inGamut: true },
  xyz: { x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 },
  hsl: { hue: 49, saturation: 86, lightness: 52 },
  luv: { L: 81.60296053275202, u: 33.50413039331645, v: 84.4716716630059 },
  ryb: { red: 63.346820809248555, yellow: 228, blue: 17 },
  tsl: {
    tint: 0.4209301051592921,
    saturation: 0.27240784750042124,
    lightness: 0.7515294117647058
  }
}

Note: If you noticed RGB and XYZ values are returned regardless, they are needed for two main family of spaces and there for are computed by default.

If "all" is passed as a third argument, all 45 spaces will be computed (the return example is to big to show here), this option is computationally tasking and it's not a good option for color pickers or other use cases where there is a high frequency of re computation. Accidentally the default (no third argument) will return values utilized in a Photoshop color picker (rgb, hsv, lab, cmyk and hex).

Conversions

Here is a list of all color conversion methods, they are standalone, and can be utilized on their own. Some of them might have multiple conversions and that will be stated in the table.

NameDescriptionConversionsNotesParameter
ansi16ToRgbConverts an Ansi16 numeric value to sRGB valuesAnsi16 to sRGBPossible data lossnumber
ansi256ToRGBConverts an Ansi256 numeric value ro sRGB valuesAnsi256 to sRGBPossible data lossnumber
cmyToSRgbConverts colors CMY values in to sRGB valuesCYM to sRGBNo major data loss{ cyan: number, magenta: number, yellow: number}
cmykToRgbConverts colors CMYK values in to sRGB valuesCMYK to sRGBNo major data loss{ cyan: number, magenta: number, yellow: number, key: number }
hclToLabConverts colors HCL values in to CIE-L*ab valuesHCL to LABNo major data loss{ luminance: number, hue: number, chroma: number }
hcyToSrgbConverts colors HCY values in to sRGB valuesHCY to sRGBNo major data loss{ hue: number, chroma: number, Yluminance: number }
hexToRgbConverts a HEX string value in to sRGB valuesHEX to sRGBNo major data lossstring
hextToIntConverts a Hex string value in to a integer valueHEX to Integerstring
hexToDecimalConverts a Hex string value in to a decimal valueHEX to Decimalstring
hsiToSrgbConverts a colors HSI values in to sRGB valuesHSI to sRGBNo major data loss{ hue: number, saturation: number, intensity: number }
hslToToHexConverts a colors HSL values in to a HEX stringHSL to HEXNo major data loss{ hue: number, saturation: number, lightness: number }
hslToHsvConverts a colors HSL values in to HSV valuesHSL to HSVNo major data loss{ hue: number, saturation: number, lightness: number }
hslToRgbConverts a colors HSL values in to sRGB valuesHSL to sRGBNo major data loss{ hue: number, saturation: number, lightness: number }
hsvToAnsi16Converts a colors HSV values in to Ansi16 numericHSV to Ansi16Possible data loss{ hue: number, saturation: number, value: number }
hsvToHslConverts a colors HSV values in to HSL valuesHSV to HSLNo major data loss{ hue: number, saturation: number, value: number }
hsvToRgbConverts a colors HSV values in to sRGB valuesHSV to sRGBNo major data loss{ hue: number, saturation: number, value: number }
hwbToRgbConverts a colors HWB values in to sRGB valuesHWB to sRGBNo major data loss{ hue: number, whiteness: number, blackness: number }
labToLch_abConverts a colors CIE-L*ab values in to LCH(ab)LAB to LCHNo major data loss{ luminance: number, a: number, b: number }
labToSrgbConverts a colors CIE-L*ab values in to sRgbLAB to XYZ to sRGBNo major data loss{ luminance: number, a: number, b: number }
labToXyzConverts a colors CIE-L*ab values in to XYZLAB to XYZNo major data loss{ luminance: number, a: number, b: number }
hunterLabToXyzConverts a colors Hunter's Lab values in to XYZLAB to XYZNo major data loss{ luminance: number, a: number, b: number }
lch_abToLabConverts a colors LCH(ab) values in to CIE-L*abLCH to LABNo major data loss{ lightness: number, chroma: number, hue: number }
lch_abToXyzConverts a colors LCH(ab) values in to XYZLCH to XYZNo major data loss{ lightness: number, chroma: number, hue: number }
lch_uvToLuvConverts a colors LCH(uv) values in to LUVLCH to LUVNo major data loss{ lightness: number, chroma: number, hue: number }
lch_uvToXyzConverts a colors LCH(uv) values in to XYZLCH to XYZNo major data loss{ lightness: number, chroma: number, hue: number }
lmsToXyzConverts a colors LMS values in to XYZ valuesLMS to XYZNo major data loss{ long: number, medium: number, short: number }
luvToLch_uvConverts a colors LUV values to LCH(uv) valuesLUV to LCHNo major data loss{ L: number, u: number, v: number }
luvToXyzConverts a colors LUV values to XYZ valuesLUV to XYZNo major data loss{ L: number, u: number, v: number }
sRgbToAdobeRgbConverts a colors sRGB values in to Adobe 98 RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToAppleRgbConverts a colors sRGB values in to Apple RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToBestRgbConverts a colors sRGB values in to Best RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToBetaRgbConverts a colors sRGB values in to Beta RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToBruceRgbConverts a colors sRGB values in to Bruce RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToCieRgbConverts a colors sRGB values in to CIE RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToColorMatchRgbConverts a colors sRGB values in to Color Match RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToDonRgb4Converts a colors sRGB values in to DON RGB 4RGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToEtkaSpacePs5Converts a colors sRGB values in to Etka Space ps5RGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToNtscRgbConverts a colors sRGB values in to NTSC RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToPalSecamRgbConverts a colors sRGB values in to PAL/SECAM RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToProPhotoRgbConverts a colors sRGB values in to PRO PHOTO RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToSmpteCRgbConverts a colors sRGB values in to SMPTE-C RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToWideGamutRgbConverts a colors sRGB values in to Wide Gamut RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToEciRgbV2Converts a colors sRGB values in to ECI RGB V2RGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToAnsi16Converts a colors sRGB values in to Ansi16 numericRGB to Ansi16Possible data loss{ red: number, green: number, blue: number }
sRgbToAnsi256Converts a colors sRGB values in to Ansi256 numericRGB to Ansi256Possible data loss{ red: number, green: number, blue: number }
sRgbToCmyConverts a colors sRGB values in to CMY valuesRGB to CMYNo major data loss{ red: number, green: number, blue: number }
sRgbToCmykConverts a colors sRGB values in to CMYK valuesRGB to CMYKNo major data loss{ red: number, green: number, blue: number }
sRgbToHcyConverts a colors sRGB values in to HCY valuesRGB to HCYNo major data loss{ red: number, green: number, blue: number }
sRgbToHexConverts a colors sRGB values in to a HEX stringRGB to HEXNo major data loss{ red: number, green: number, blue: number }
sRgbaToHexConverts a colors sRGBA values in to a HEX stringRGBA to HEXNo major data loss{ red: number, green: number, blue: number }
sRgbToHsiConverts a colors sRGB values in to HSI valuesRGB to HSINo major data loss{ red: number, green: number, blue: number }
sRgbToHslConverts a colors sRGB values in to HSL valuesRGB to HSLNo major data loss{ red: number, green: number, blue: number }
sRgbToHsvConverts a colors sRGB values in to HSV valuesRGB to HSVNo major data loss{ red: number, green: number, blue: number }
sRgbToHwgConverts a colors sRGB values in to HSV valuesRGB to HWGNo major data loss{ red: number, green: number, blue: number }
sRgbToLabConverts a colors sRGB values in to CIE-L*ab valuesRGB to XYZ to LABNo major data loss{ red: number, green: number, blue: number }
sRgbToLch_abConverts a colors sRGB values in to LCH(ab) valuesRGB to XYZ to LAB to LCHNo major data loss{ red: number, green: number, blue: number }
sRgbToLch_uvConverts a colors sRGB values in to LCH(uv) valuesRGB to XYZ to LUV to LCHNo major data loss{ red: number, green: number, blue: number }
sRgbToLuvConverts a colors sRGB values in to LUV valuesRGB to XYZ to LUVNo major data loss{ red: number, green: number, blue: number }
sRgbToRybConverts a colors sRGB values in to RYB valuesRGB to RYBNo major data loss{ red: number, green: number, blue: number }
sRgbToTslConverts a colors sRGB values in to TSL valuesRGB to TSLNo major data loss{ red: number, green: number, blue: number }
sRgbToUvqConverts a colors sRGB values in to UVW valuesRGB to XYZ to UVWNo major data loss{ red: number, green: number, blue: number }
sRgbToYCbCrBT601Converts a colors sRGB values in to Y′CbCr (YUV)RGB to YCbCrNo major data loss{ red: number, green: number, blue: number }
sRgbToYCbCrBT709Converts a colors sRGB values in to Y′CbCr BT.709RGB to YCbCrNo major data loss{ red: number, green: number, blue: number }
sRgbToYDbDrConverts a colors sRGB values in to YDbDr valuesRGB to YDbDrNo major data loss{ red: number, green: number, blue: number }
sRgbToYPbPrConverts a colors sRGB values in to YPbPr valuesRGB to YPbPrNo major data loss{ red: number, green: number, blue: number }
sRgbToYcCbcCrcConverts a colors sRGB values in to YcCbcCrc valuesRGB to YcCbcCrcNo major data loss{ red: number, green: number, blue: number }
sRgbToYCgCoConverts a colors sRGB values in to YCoCg valuesRGB to YCoCgNo major data loss{ red: number, green: number, blue: number }
sRgbToYiqConverts a colors sRGB values in to YIQ valuesRGB to YIQNo major data loss{ red: number, green: number, blue: number }
sRgbToXvYccConverts a colors sRGB values in to xvYCC valuesRGB to xvYCCNo major data loss{ red: number, green: number, blue: number }
sRgbToXyzConverts a colors sRGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
adobeRgbToXyzConverts a colors Adobe 98 values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
appleRgbToXyzConverts a colors Apple RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
bestRgbToXyzConverts a colors Best RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
betaRgbToXyzConverts a colors Beta RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
bruceRgbToXyzConverts a colors Bruce RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
cieRgbToXyzConverts a colors CIE RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
colorMatchRgbToXyzConverts a colors COLOR MATCH RGB values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
donRgb4ToXyzConverts a colors DON RGB 4 values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
etkaSpacePs5ToXyzConverts a colors ETKA SPACE PS5 values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
ntscRgbToXyzConverts a colors NTSC RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
palSecamRgbToXyzConverts a colors PAL/SECAM RGB values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
proPhotoRgbToXyzConverts a colors PRO PHOTO RGB values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
smpteCRgbToXyzConverts a colors SMPTE-C RGB values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
wideGamutRgbToXyzConverts a colors WIDE GAMUT RGB values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
eciRgbV2ToXyzConverts a colors ECI RGB V2 values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
rybToSrgbConverts a colors RYB values to a sRGB valuesRYB to RGBNo major data loss{ red: number, green: number, blue: number }
tslToSrgbConverts a colors TSL values to a sRGB valuesTSL to RGBNo major data loss{ red: number, green: number, blue: number }
uvwToXyzConverts a colors UVW values to a XYZ valuesUVW to XYZNo major data loss{ u: number, v: number, w: number }
xvYccToYcbcrBT601Converts a colors xvYCC values to Y′CbCr (YUV)xvYCC to YCbCrNo major data loss{ Y: number, Cb: number, Cr: number }
xvYccToSrgbConverts a colors xvYCC values to a SRGB valuesxvYCC to YCbCr to sRGBNo major data loss{ Y: number, Cb: number, Cr: number }
xyYToXyzConverts colors xyY values to XYZ valuesXYY to XYZNo major data loss{ x: number, y: number, Y: number }
xyzToAdobeRgbConverts colors XYZ values to Adobe 98 valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToAppleRgbConverts colors XYZ values to Apple RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToBestRgbConverts colors XYZ values to Best RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToBetaRgbConverts colors XYZ values to Beta RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToBruceRgbConverts colors XYZ values to Bruce RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToCieRgbConverts colors XYZ values to CIE RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToColorMatchRgbConverts colors XYZ values to COLOR MATCH RGBXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToDonRgb4Converts colors XYZ values to DON RGB 4 valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToEtkaSpacePs5Converts colors XYZ values to ETKA SPACE PS5 valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToNtscRgbConverts colors XYZ values to NTSC RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToPalSecamRgbConverts colors XYZ values to PAL/SECAM RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToProPhotoRgbConverts colors XYZ values to PRO PHOTO RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToSmpteCRgbConverts colors XYZ values to SMPTE-C RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToWideGamutRgbConverts colors XYZ values to WIDE GAMUT RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToEciRgbV2Converts colors XYZ values to ECI RGB V2 valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToLabConverts colors XYZ values to CIE-L*ab valuesXYZ to LABNo major data loss{ x: number, y: number, z: number }
xyzToLuvConverts colors XYZ values to LUV valuesXYZ to LUVNo major data loss{ x: number, y: number, z: number }
xyzToLch_uvConverts colors XYZ values to LCH(uv) valuesXYZ to LCHNo major data loss{ x: number, y: number, z: number }
xyzToUvwConverts colors XYZ values to UVW valuesXYZ to UVWNo major data loss{ x: number, y: number, z: number }
xyzToSrgbConverts colors XYZ values to sRGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToLmsConverts colors XYZ values to LMS valuesXYZ to LMSNo major data loss{ x: number, y: number, z: number }
xyzToHunterLabConverts colors XYZ values to Hunter's Lab valuesXYZ to LABNo major data loss{ x: number, y: number, z: number }
xyzToXyYConverts colors XYZ values to XYY valuesXYZ to XYYNo major data loss{ x: number, y: number, z: number }
yCbCrBT601ToSrgbConverts colors Y′CbCr (YUV) values to sRGB valuesYCbCr to RGBNo major data loss{ Y: number, Cb: number, Cr: number }
yCbCrBT601ToXvYccConverts colors Y′CbCr (YUV) values to xvYCC valuesYCbCr to xvYCCNo major data loss{ Y: number, Cb: number, Cr: number }
yCbCrBT601ToYPbPrConverts colors Y′CbCr (YUV) values to YPbPr valuesYCbCr to YPbPrNo major data loss{ Y: number, Cb: number, Cr: number }
yCbCrBT709ToSrgbConverts colors Y′CbCr BT.709 values to sRGB valuesYCbCr to RGBNo major data loss{ Y: number, Cb: number, Cr: number }
ycCbcCrcToSrgbConverts colors YcCbcCrc values to sRGB valuesYcCbcCrc to RGBNo major data loss{ Yc: number, Cbc: number, Crc: number }
yCgCoToSrgbConverts colors YCoCg values to sRGB valuesYCoCg to RGBNo major data loss{ Y: number, Co: number, Cg: number }
yDbDrToSrgbConverts colors YDbDr values to sRGB valuesYDbDr to RGBNo major data loss{ Y: number, Co: number, Cg: number }
yiqToSrgbConverts colors YIQ values to sRGB valuesYIQ to RGBNo major data loss{ Y: number, Co: number, Cg: number }
yPbPrToSrgbConverts colors YPbPr values to sRGB valuesYPbPr to RGBNo major data loss{ Y: number, Co: number, Cg: number }
yPbPrToYCbCrConverts colors YPbPr values to YCbCr valuesYPbPr to YCbCrNo major data loss{ Y: number, Co: number, Cg: number }

Color Converter

In situations where you might need to covert from one space into multiple spaces, you can use a color converter. Color Converter is faster and less task-intensive than using Color. There are two prebuilt Color Converters, RGB Converter and the XYZ Converter.

RGB Converter

RGB Converter is a prebuilt Color Converter that takes a single attribute of a type: { red: number, green: number, blue: number } or { r: number, g: number, b: number }.

It has a single method, "get" and it takes an attribute of type string which represents a color space you would like back. Supported conversion are: adobe_98_rgb, apple_rgb, ansi16, ansi256, best_rgb, beta_rgb, bruce_rgb, cie_rgb, color_match_rgb, cmy, cmyk, don_rgb_4, etka_space_ps5, eci_rgb_v2, hcy, hex, hsi, hsl, hsv, hwb, lab, lch_ab, lch_uv, luv, ntsc_rgb, pal_secam_rgb, pro_photo_rgb, ryb, smpte_c_rgb, tsl, uvw, wide_gamut_rgb, ycbcr_BT601, ycbcr_BT709, ycbcr_BT2020, ydbdr, ypbpr, yccbccrc, ycocg, yiq, xvycc, xyz.

Usage example:

import { RgbConverter } from "@dynamize/color-utilities";

const rgbCon = new RgbConverter({ red: 238, green: 200, blue: 27 });

console.log(rgbCon.get("hsv"));

This will return HSV values for the above-given color.

XYZ Converter

XYZ Converter is a prebuilt Color Converter that takes a single attribute of a type: { x: number, y: number, z: number }.

It has a single method, "get" and it takes an attribute of type string which represents a color space you would like back. Supported conversion are: lab, lch_ab, lch_uv, luv, uvw, rgb, adobe_98_rgb, apple_rgb, best_rgb, beta_rgb, bruce_rgb, cie_rgb, color_match_rgb, don_rgb_4, etka_space_ps5, eci_rgb_v2, ntsc_rgb, pal_secam_rgb, pro_photo_rgb, smpte_c_rgb, wide_gamut_rgb, xyy, lms, hunters_lab.

Usage example:

import { XyzConverter } from "@dynamize/color-utilities";

const xyzCon = new XyzConverter({ red: 238, green: 200, blue: 27 });

console.log(xyzCon.get("luv"));

This will return LUV values for the above-given color.

Color Blending

In Color Utilities, there are two ways you can blend colors: either by using the standalone method "blend" or by using a Color Blender.

Blender

Color Blender is quite powerful, it allows you to blend two colors in rgb ,cmyk, hex, hsl ,hsv, hwb, hex, ryb and xyz formats. The two colors do not have to be in the same format to blend them, and the returned color can have any of the following formats: rgb ,cmyk, hex, hsl ,hsv, hwb, hex, ryb, xyz.

Usage example:

import { Blender } from "@dynamize/color-utilities";

const color = new Blender(
  { c: 0, m: 7, y: 100, k: 0 },
  { h: 0, s: 100, v: 100 },
  { weight: 0.67, returnType: "hex" }
);

console.log(color.color);

Color Blender can return two things: color or blend data. Color will just be a color value in the format that was requested, blend data will give you more information. Below, you can see the blend data for the above example:

{
    color1: {
      data: { cyan: 0, magenta: 7, yellow: 100, key: 0 },
      rgb: { red: 255, green: 237.14999999999998, blue: 0, inGamut: true },
      amount: 0.67,
    },
    color2: {
      data: { hue: 0, saturation: 100, value: 100 },
      rgb: { red: 255, green: 0, blue: 0, inGamut: true },
      amount: 0.32999999999999996,
    },
    resultColor: "FF9F00",
  }

blend

Using the blend method is pretty straight-forward. It takes three parameters, the first two being the RGB values of colors to blend, and the last one is a percentage of the first color, the remaining percentage will be allocated to the second one.

Usage example:

import { blend } from "@dynamize/color-utilities";

const blended = blend(
  { red: 255, green: 237, blue: 0 },
  { red: 255, green: 0, blue: 0 },
  0.67
);

console.log(blended);

Color Harmonies

With Color utilities, you can also generate a number of Harmony pallets. For more information about Harmonies, visit: https://simplified.com/blog/colors/color-harmony All Harmonies are a standalone functions and they all the a color in a HSL format ({ hue: number, saturation: number, lightness: number }) and return an array of hex values. In addition, in addition the second optional parameter is a boolean, which represents if returned hex values should start with a #.

Analogous

Usage example:

import { analogousHarmony } from "@dynamize/color-utilities";

const pallet = analogousHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Clash

Usage example:

import { clashHarmony } from "@dynamize/color-utilities";

const pallet = clashHarmony({ hue: 49, saturation: 86, lightness: 52 }, true);

console.log(pallet);

Complementary

Usage example:

import { complementaryHarmony } from "@dynamize/color-utilities";

const pallet = complementaryHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Split Complementary

Usage example:

import { splitComplementaryHarmony } from "@dynamize/color-utilities";

const pallet = splitComplementaryHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { splitComplementaryCWHarmony } from "@dynamize/color-utilities";

const pallet = splitComplementaryCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { splitComplementaryCCWHarmony } from "@dynamize/color-utilities";

const pallet = splitComplementaryCCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Four Tone

Usage example:

import { fourToneCWHarmony } from "@dynamize/color-utilities";

const pallet = fourToneCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { fourToneCCWHarmony } from "@dynamize/color-utilities";

const pallet = fourToneCCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Five Tone

Usage example:

import { fiveToneAHarmony } from "@dynamize/color-utilities";

const pallet = fiveToneAHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { fiveToneBHarmony } from "@dynamize/color-utilities";

const pallet = fiveToneBHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { fiveToneCHarmony } from "@dynamize/color-utilities";

const pallet = fiveToneCHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { fiveToneDHarmony } from "@dynamize/color-utilities";

const pallet = fiveToneDHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { fiveToneEHarmony } from "@dynamize/color-utilities";

const pallet = fiveToneEHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Six Tone

Usage example:

import { sixToneCWHarmony } from "@dynamize/color-utilities";

const pallet = sixToneCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { sixToneCCWHarmony } from "@dynamize/color-utilities";

const pallet = sixToneCCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Neutral

Usage example:

import { neutralHarmony } from "@dynamize/color-utilities";

const pallet = neutralHarmony({ hue: 49, saturation: 86, lightness: 52 }, true);

console.log(pallet);

Square

import { squareHarmony } from "@dynamize/color-utilities";

const pallet = squareHarmony({ hue: 49, saturation: 86, lightness: 52 }, true);

console.log(pallet);

Tetradic

import { tetradicHarmony } from "@dynamize/color-utilities";

const pallet = tetradicHarmony({ hue: 49, saturation: 86, lightness: 52 }, true);

console.log(pallet);

Triadic

import { triadicHarmony } from "@dynamize/color-utilities";

const pallet = triadicHarmony({ hue: 49, saturation: 86, lightness: 52 }, true);

console.log(pallet);

Color Mixes

Color Utilities also provides three types of color mixes you can get: Shades, Tints and Tones. All of these are generated by a standalone function that receives two arguments, the first being a base color in RGB format, and the second one is an optional options object that can have two values: size (number of colors generated in the pallet) and prefixed (boolean stating if the colors should start with a #). The return value is an array of strings representing hex values.

Tones

import { getTones } from "@dynamize/color-utilities";

const tones = getTones(
  { red: 238, green: 200, blue: 27 },
  { size: 10, prefixed: true }
);

console.log(pallet);

Tints

import { getTints } from "@dynamize/color-utilities";

const tones = getTints(
  { red: 238, green: 200, blue: 27 },
  { size: 10, prefixed: true }
);

console.log(pallet);

Shades

import { getShades } from "@dynamize/color-utilities";

const tones = getShades(
  { red: 238, green: 200, blue: 27 },
  { size: 10, prefixed: true }
);

console.log(pallet);

Chromatic adaptation

Chromatic adaptation can be preformed in two ways, either by using a standalone "adapt" function or by using an Adapter class.

adapt

"adapt" function which takes two arguments, first being XYZ values 0f the color to be adapted, and a string value representing reference illuminant and a destination illuminant.

import { adapt } from "@dynamize/color-utilities";

const adapted = adapt({ x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 }, 'A_B');

console.log(adapted);

The above example will adapt from a from reference illuminant A to destination illuminant B.

Adapter

The Adapter class is a little bit more powerful but slower, it takes two optional arguments, first being color values, second is the color space of those values, if not passed default values will be for color white in XYZ format.

Here is a table of all available formats and values:

Param placeDescriptionFormats
# 1Color data{ r: number, g: number, b: number }, { red: number, green: number, blue: number }, { l: number, a: number, b: number }, { luminance: number, a: number, b: number }, { L: number, u: number, v: number }, { l: number, c: number, h: number }, { lightness: number, chroma: number hue: number }, { long: number, medium: number, short: number }, { u: number, v: number, w: number }, { x: number, y: number, Y: number }, { x: number, y: number, z: number }
# 2Color Space of the given coloradobe_98_rgb, apple_rgb, best_rgb, beta_rgb, bruce_rgb, cie_rgb, color_match_rgb, don_rgb_4, eci_rgb_v2, etka_space_ps5, ntsc_rgb, pal_secam_rgb, pro_photo_rgb, rgb, smpte_c_rgb, wide_gamut_rgb

Example 1:

import { Adapter } from "@dynamize/color-utilities";

const adapted = new Adapter(
  { x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 }
).adapt('A_B');

console.log(adapted);

Example 2:

import { Adapter } from "@dynamize/color-utilities";

const adapter = new Adapter();
const adapted = adapter.set(
  { x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 }
).adapt('A_B');

console.log(adapted);

The above example is using the "adapt" method with in the Adapter. The difference being that it takes an optional second argument, which is the desired color space of returned color values.

Example 3:

import { Adapter } from "@dynamize/color-utilities";

const adapter = new Adapter();
const adapted = adapter.set(
  { x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 }
).adapt(
  'A_B', 
  'adobe_98_rgb'
);

console.log(adapted);

Delta E / Color Difference

There are multiple ways to calculate the color difference or color distance. More information about color difference: https://en.wikipedia.org/wiki/Color_difference

NameDescriptionFormats
comparativeDistanceEuclidean distance{ red; number, green: number, blue: number }
deltaECIE76LabDelta E using the CIE76 algorithm{ luminance: number, a: number, b: number }
deltaECIE76LchDelta E using the CIE76 algorithm{ lightness: number, chroma: number, hue: number }
deltaECIE76RgbDelta E using the CIE76 algorithm{ red; number, green: number, blue: number }
deltaECIE94LabDelta E using the CIE94 algorithm{ luminance: number, a: number, b: number }
deltaECIE00LabDelta E using the CIE2000 algorithm{ luminance: number, a: number, b: number }
deltaECIE00RgbDelta E using the CIE2000 algorithm{ red; number, green: number, blue: number }

Usage examples:

import { comparativeDistance } from "@dynamize/color-utilities";

const diff = comparativeDistance(
  { red: 238, green: 200, blue: 27 },
  { red: 217, green: 122, blue: 37 }
  );

console.log(diff);

CIE 76

import { deltaECIE76Lab } from "@dynamize/color-utilities";

const diff = deltaECIE76Lab(
  { luminance: 81.60296053275202, a: -1.2482727232548951, b: 79.33052440955292 } ,
  { luminance: 60.61218950864361, a: 31.243719367882505, b: 58.52164206596838 }
  );

console.log(diff);
import { deltaECIE76Rgb } from "@dynamize/color-utilities";

const diff =  deltaECIE76Rgb(
  { red: 238, green: 200, blue: 27 },
  { red: 217, green: 122, blue: 37 }
  );

console.log(diff);

CIE 94

import { deltaECIE94Lab } from "@dynamize/color-utilities";

const diff = deltaECIE94Lab(
  { luminance: 81.60296053275202, a: -1.2482727232548951, b: 79.33052440955292 } ,
  { luminance: 60.61218950864361, a: 31.243719367882505, b: 58.52164206596838 }
  );

console.log(diff);

CIE 00

import { deltaECIE00Lab } from "@dynamize/color-utilities";

const diff = deltaECIE00Lab(
  { luminance: 81.60296053275202, a: -1.2482727232548951, b: 79.33052440955292 } ,
  { luminance: 60.61218950864361, a: 31.243719367882505, b: 58.52164206596838 }
  );

console.log(diff);
import { deltaECIE00Rgb } from "@dynamize/color-utilities";

const diff = deltaECIE00Rgb(
  { red: 238, green: 200, blue: 27 },
  { red: 217, green: 122, blue: 37 }
  );

console.log(diff);