Class that represents a single color. All of Color.js’s tree-shakeable methods are also available as instance methods on this class, as well as static methods that take the color as the first argument.

Hierarchy

  • SpaceAccessors
    • Color

Implements

Constructors

Properties

__rec2020_oetf: SpaceAccessor
a: number
a98rgb_linear: SpaceAccessor
alpha: number
az: number
b: number
bz: number
c: number
cam16_jmh: SpaceAccessor
contrast: ((...args: [foreground: ColorTypes, o:
    | "WCAG21"
    | "APCA"
    | "Michelson"
    | "Weber"
    | "Lstar"
    | "DeltaPhi"
    | {
        algorithm:
            | "WCAG21"
            | "APCA"
            | "Michelson"
            | "Weber"
            | "Lstar"
            | "DeltaPhi";
    } & Record<string, any>]) => number)
contrastAPCA: ((...args: [foreground: ColorTypes]) => number)
contrastDeltaPhi: ((...args: [color2: ColorTypes]) => number)
contrastLstar: ((...args: [color2: ColorTypes]) => number)
contrastMichelson: ((...args: [color2: ColorTypes]) => number)
contrastWCAG21: ((...args: [color2: ColorTypes]) => number)
contrastWeber: ((...args: [color2: ColorTypes]) => number)
coords: Coords
cp: number
ct: number
cz: number
darken: ((...args: [amount: number]) => Color)
deltaE: ((...args: [c2: ColorTypes, o:
    | "76"
    | "Jz"
    | "HCT"
    | "CMC"
    | "2000"
    | "ITP"
    | "OK"
    | "OK2"
    | {
        method?:
            | "76"
            | "Jz"
            | "HCT"
            | "CMC"
            | "2000"
            | "ITP"
            | "OK"
            | "OK2";
    } & Record<string, any>]) => number)
deltaE2000: ((...args: [sample: ColorTypes, {
    kC?: number;
    kH?: number;
    kL?: number;
}?]) => number)
deltaE76: ((...args: [sample: ColorTypes]) => number)
deltaECMC: ((...args: [sample: ColorTypes, {
    c?: number;
    l?: number;
}?]) => number)
deltaEITP: ((...args: [sample: ColorTypes]) => number)
deltaEJz: ((...args: [sample: ColorTypes]) => number)
deltaEOK: ((...args: [sample: ColorTypes]) => number)
distance: ((...args: [color2: ColorTypes, space: string | Space]) => number)
equals: ((...args: [color2: ColorTypes]) => boolean)
g: number
get: ((...args: [prop: Ref]) => number)
getAll: ((...args: [GetAllOptions?]) => Coords)
h: number
hz: number
i: number
inGamut: ((...args: [space: string | Space, {
    epsilon?: number;
}?]) => boolean)
j: number
jz: number
l: number
lab_d65: SpaceAccessor
lighten: ((...args: [amount: number]) => Color)
m: number
p3_linear: SpaceAccessor
prophoto: SpaceAccessor
prophoto_linear: SpaceAccessor
r: number
range: ((...args: [ColorTypes, (RangeOptions & Record<string, any>)?]) => Range)

Creates a function that accepts a number and returns a color. For numbers in the range 0 to 1, the function interpolates; for numbers outside that range, the function extrapolates (and thus may not return the results you expect)

rec2020: SpaceAccessor
rec2020_linear: SpaceAccessor
rec2100_linear: SpaceAccessor
rec2100hlg: SpaceAccessor
rec2100pq: SpaceAccessor
s: number
srgb_linear: SpaceAccessor
t: number
to: ((...args: [space: string | Space, {
    inGamut?: boolean | ToGamutOptions;
}?]) => Color)
toString: ((...args: [options: SerializeOptions & Record<string, any>]) => string)

Returns a string representation of an object.

u: number
uv: ((...args: []) => [number, number])
v: number
w: number
x: number
xy: ((...args: []) => [number, number])
xyz_abs_d65: SpaceAccessor
xyz_d50: SpaceAccessor
xyz_d65: SpaceAccessor
y: number
z: number
contrast: ((background: ColorTypes, foreground: ColorTypes, o:
    | "WCAG21"
    | "APCA"
    | "Michelson"
    | "Weber"
    | "Lstar"
    | "DeltaPhi"
    | {
        algorithm:
            | "WCAG21"
            | "APCA"
            | "Michelson"
            | "Weber"
            | "Lstar"
            | "DeltaPhi";
    } & Record<string, any>) => number)

Type declaration

    • (background, foreground, o): number
    • Parameters

      • background: ColorTypes
      • foreground: ColorTypes
      • o:
            | "WCAG21"
            | "APCA"
            | "Michelson"
            | "Weber"
            | "Lstar"
            | "DeltaPhi"
            | {
                algorithm:
                    | "WCAG21"
                    | "APCA"
                    | "Michelson"
                    | "Weber"
                    | "Lstar"
                    | "DeltaPhi";
            } & Record<string, any>

        Algorithm to use as well as any other options to pass to the contrast function

      Returns number

      Unknown or unspecified algorithm

contrastAPCA: ((background: ColorTypes, foreground: ColorTypes) => number)

Type declaration

    • (background, foreground): number
    • Not symmetric, requires a foreground (text) color, and a background color

      Parameters

      Returns number

contrastDeltaPhi: ((color1: ColorTypes, color2: ColorTypes) => number)

Type declaration

contrastLstar: ((color1: ColorTypes, color2: ColorTypes) => number)

Type declaration

contrastMichelson: ((color1: ColorTypes, color2: ColorTypes) => number)

Type declaration

contrastWCAG21: ((color1: ColorTypes, color2: ColorTypes) => number)

Type declaration

contrastWeber: ((color1: ColorTypes, color2: ColorTypes) => number)

Type declaration

darken: ((...args: [color: ColorTypes, amount: number]) => Color)
deltaE: ((c1: ColorTypes, c2: ColorTypes, o??:
    | "76"
    | "Jz"
    | "HCT"
    | "CMC"
    | "2000"
    | "ITP"
    | "OK"
    | "OK2"
    | {
        method?:
            | "76"
            | "Jz"
            | "HCT"
            | "CMC"
            | "2000"
            | "ITP"
            | "OK"
            | "OK2";
    } & Record<string, any>) => number)

Type declaration

    • (c1, c2, o?): number
    • Parameters

      • c1: ColorTypes
      • c2: ColorTypes
      • Optionalo:
            | "76"
            | "Jz"
            | "HCT"
            | "CMC"
            | "2000"
            | "ITP"
            | "OK"
            | "OK2"
            | {
                method?:
                    | "76"
                    | "Jz"
                    | "HCT"
                    | "CMC"
                    | "2000"
                    | "ITP"
                    | "OK"
                    | "OK2";
            } & Record<string, any> = {}

        deltaE method to use as well as any other options to pass to the deltaE function

      Returns number

      Unknown or unspecified method

deltaE2000: ((color: ColorTypes, sample: ColorTypes, options?: {
    kC?: number;
    kH?: number;
    kL?: number;
}) => number)

Type declaration

    • (color, sample, options?): number
    • Parameters

      • color: ColorTypes
      • sample: ColorTypes
      • options: {
            kC?: number;
            kH?: number;
            kL?: number;
        } = {}
        • OptionalkC?: number
        • OptionalkH?: number
        • OptionalkL?: number

      Returns number

deltaE76: ((color: ColorTypes, sample: ColorTypes) => number)

Type declaration

deltaECMC: ((color: ColorTypes, sample: ColorTypes, options?: {
    c?: number;
    l?: number;
}) => number)

Type declaration

    • (color, sample, options?): number
    • Parameters

      • color: ColorTypes
      • sample: ColorTypes
      • options: {
            c?: number;
            l?: number;
        } = {}
        • Optionalc?: number
        • Optionall?: number

      Returns number

deltaEITP: ((color: ColorTypes, sample: ColorTypes) => number)

Type declaration

    • (color, sample): number
    • Delta E in ICtCp space, which the ITU calls Delta E ITP, which is shorter. Formulae from ITU Rec. ITU-R BT.2124-0

      Parameters

      Returns number

deltaEJz: ((color: ColorTypes, sample: ColorTypes) => number)

Type declaration

    • (color, sample): number
    • More accurate color-difference formulae than the simple 1976 Euclidean distance in Lab

      Uses JzCzHz, which has improved perceptual uniformity and thus a simple Euclidean root-sum of ΔL² ΔC² ΔH² gives good results.

      Parameters

      Returns number

deltaEMethods: {
    deltaE2000: ((color: ColorTypes, sample: ColorTypes, options?: {
        kC?: number;
        kH?: number;
        kL?: number;
    }) => number);
    deltaE76: ((color: ColorTypes, sample: ColorTypes) => number);
    deltaECMC: ((color: ColorTypes, sample: ColorTypes, options?: {
        c?: number;
        l?: number;
    }) => number);
    deltaEHCT: ((color: ColorTypes, sample: ColorTypes) => number);
    deltaEITP: ((color: ColorTypes, sample: ColorTypes) => number);
    deltaEJz: ((color: ColorTypes, sample: ColorTypes) => number);
    deltaEOK: ((color: ColorTypes, sample: ColorTypes) => number);
    deltaEOK2: ((color: ColorTypes, sample: ColorTypes) => number);
}

Type declaration

  • deltaE2000: ((color: ColorTypes, sample: ColorTypes, options?: {
        kC?: number;
        kH?: number;
        kL?: number;
    }) => number)
      • (color, sample, options?): number
      • Parameters

        • color: ColorTypes
        • sample: ColorTypes
        • options: {
              kC?: number;
              kH?: number;
              kL?: number;
          } = {}
          • OptionalkC?: number
          • OptionalkH?: number
          • OptionalkL?: number

        Returns number

  • deltaE76: ((color: ColorTypes, sample: ColorTypes) => number)
  • deltaECMC: ((color: ColorTypes, sample: ColorTypes, options?: {
        c?: number;
        l?: number;
    }) => number)
      • (color, sample, options?): number
      • Parameters

        • color: ColorTypes
        • sample: ColorTypes
        • options: {
              c?: number;
              l?: number;
          } = {}
          • Optionalc?: number
          • Optionall?: number

        Returns number

  • deltaEHCT: ((color: ColorTypes, sample: ColorTypes) => number)
      • (color, sample): number
      • Color distance using HCT.

        Parameters

        Returns number

  • deltaEITP: ((color: ColorTypes, sample: ColorTypes) => number)
      • (color, sample): number
      • Delta E in ICtCp space, which the ITU calls Delta E ITP, which is shorter. Formulae from ITU Rec. ITU-R BT.2124-0

        Parameters

        Returns number

  • deltaEJz: ((color: ColorTypes, sample: ColorTypes) => number)
      • (color, sample): number
      • More accurate color-difference formulae than the simple 1976 Euclidean distance in Lab

        Uses JzCzHz, which has improved perceptual uniformity and thus a simple Euclidean root-sum of ΔL² ΔC² ΔH² gives good results.

        Parameters

        Returns number

  • deltaEOK: ((color: ColorTypes, sample: ColorTypes) => number)
      • (color, sample): number
      • More accurate color-difference formulae than the simple 1976 Euclidean distance in CIE Lab

        Parameters

        Returns number

  • deltaEOK2: ((color: ColorTypes, sample: ColorTypes) => number)
      • (color, sample): number
      • More accurate color-difference formulae than the simple 1976 Euclidean distance in CIE Lab The Oklab a and b axes are scaled relative to the L axis, for better uniformity Björn Ottosson said: "I've recently done some tests with color distance datasets as implemented in Colorio and on both the Combvd dataset and the OSA-UCS dataset a scale factor of slightly more than 2 for a and b would give the best results (2.016 works best for Combvd and 2.045 for the OSA-UCS dataset)."

        Parameters

        Returns number

deltaEOK: ((color: ColorTypes, sample: ColorTypes) => number)

Type declaration

    • (color, sample): number
    • More accurate color-difference formulae than the simple 1976 Euclidean distance in CIE Lab

      Parameters

      Returns number

lighten: ((...args: [color: ColorTypes, amount: number]) => Color)
range: {
    (range: Range, options?: RangeOptions): Range;
    (color1: ColorTypes, color2: ColorTypes, options?: RangeOptions & Record<string, any>): Range;
}

Creates a function that accepts a number and returns a color. For numbers in the range 0 to 1, the function interpolates; for numbers outside that range, the function extrapolates (and thus may not return the results you expect)

Type declaration

    • (range, options?): Range
    • Creates a function that accepts a number and returns a color. For numbers in the range 0 to 1, the function interpolates; for numbers outside that range, the function extrapolates (and thus may not return the results you expect)

      Parameters

      Returns Range

    • (color1, color2, options?): Range
    • Parameters

      Returns Range

Accessors

  • get luminance(): number
  • Returns number

  • set luminance(_): void
  • Parameters

    • _: number

    Returns void

Methods

  • Parameters

    • Rest...args: [({
          space?: string | Space;
      } & Record<string, any>)?]

    Returns string & {
        color: Color;
    }