Options
All
  • Public
  • Public/Protected
  • All
Menu
classdesc

Generates color space instances that ColorMaster can interpret. This allows the user to manipulate colors via helpful functions/wrappers.

note

If a color's values are not valid, ColorMaster uses "black" or a mixture with provided values that are valid (in the corresponding colorspace) by default. Additionally, ColorMaster works in RGBA space internally by default and only converts to other color spaces as necessary. For example, printing a string requires conversion to the correct color space. On that end, it is also easier to work with HSLA space when performing rotation and other hue related adjustments. This approach ensures the highest possible accuracy when converting to other color spaces.

Hierarchy

  • ColorMaster

Implements

Index

Constructors

constructor

Properties

Private #color

#color: Irgba = ...

Private #format

#format: TFormat = "rgb"

Static Parsers

Parsers: TParser[] = ...

Accessors

alpha

  • get alpha(): number

blue

  • get blue(): number

format

green

  • get green(): number

hue

  • get hue(): number
  • The hue channel value from the corresponding HSLA color space

    Returns number

lightness

  • get lightness(): number

red

  • get red(): number

saturation

  • get saturation(): number

Methods

alphaBy

  • Changes the "alpha" channel value BY a given delta

    Parameters

    • delta: number

    Returns ColorMaster

    The instance that was acted upon → for function chaining

alphaTo

  • Changes the "alpha" channel value TO a given input value

    Parameters

    • value: number

    Returns ColorMaster

    The instance that was acted upon → for function chaining

brightness

  • brightness(opts?: Omit<IA11yOpts, "bgColor" | "ratio">): number

closestCool

closestPureHue

closestWarm

closestWebSafe

cmyka

contrast

  • contrast(opts?: Omit<IA11yOpts, "percentage">): string | number
  • Given a background color as input, determines the contrast ratio if the current color is used as the foreground color

    note

    This ratio will range from 1:1 → white fg : white bg to 21:1 → black fg : white bg

    see

    readableOn for readable contrast ratios

    default

    opts = { bgColor: "#fff", precision: 4, ratio: false }

    Parameters

    • Optional opts: Omit<IA11yOpts, "percentage">

    Returns string | number

    The contrast between current color instance and bgColor as a number (value → ratio = false) or string ("value:1" → ratio = true)

darkerBy

  • Removes lightness (tone) of the color in HSLA space

    Parameters

    • delta: number

    Returns ColorMaster

    The instance that was acted upon → for function chaining

desaturateBy

equalTo

  • Given an input color to compare with, determine if that color is identical to the current color instance

    default

    cmpColor = "#fff"

    note

    Alpha values are included in the equality checks

    Parameters

    Returns boolean

    True if the two color instances are identical (same RGBA channel values). False otherwise.

grayscale

harmony

  • Generates an RGBA color instance array based on the corresponding harmony

    see

    https://www.tigercolor.com/color-lab/color-theory/color-harmonies.htm

    note

    For "monochromatic", the amount must be in range [2, 10]

    default

    opts = { type: "analogous", effect: "tones", amount: 5 }

    Parameters

    Returns ColorMaster[]

    • All harmony types return an array with the original color as the first element.
         - The only exception to this are 'analogous' and 'double-split-complementary',
           which return the original color as the second element.
         - For 'monochromatic' the original color is always first and the array size is `amount + 1` evenly spaced colors.
      

hexa

  • hexa(__namedParameters?: { round: any }): Ihexa
  • Converts a RGBA color instance to HEXA color object

    Parameters

    • __namedParameters: { round: any } = {}

    Returns Ihexa

    A HSLA object containing the respective channel values

hsla

  • Converts a RGBA color instance to HSLA color object

    Returns Ihsla

    A HSLA object containing the respective channel values

hsva

hueBy

  • Changes the "hue" channel value BY a given delta (done in HSLA space and converted back to RGBA space)

    Parameters

    • delta: number

    Returns ColorMaster

    The instance that was acted upon → for function chaining

hueTo

  • Changes the "hue" channel value TO a given input value (done in HSLA space and converted back to RGBA space)

    Parameters

    • value: number | THue

    Returns ColorMaster

    The instance that was acted upon → for function chaining

hwba

invert

  • invert(__namedParameters?: { alpha: any }): ColorMaster
  • Given an input color, get its inverse value by subtracting current value from the upper bound for each channel

    Parameters

    • __namedParameters: { alpha: any } = {}

    Returns ColorMaster

    The corresponding inverse color

isCool

  • isCool(): boolean

isDark

  • isDark(): boolean
  • Determines if a given color is dark based on its brightness (brightness < 0.50)

    Returns boolean

isLight

  • isLight(): boolean
  • Determines if a given color is light based on its brightness (brightness ≥ 0.50)

    Returns boolean

isPureHue

  • isPureHue(opts?: IPureHue): boolean | { pure: boolean; reason: "tinted" | "shaded" | "toned" | "N/A" }
  • Helper for determining if a given color instance is pure (not tinted, shaded, or toned)

    note

    reason only provides extra information when the color instance is not pure hue

    default

    opts = { reason: true }

    Parameters

    Returns boolean | { pure: boolean; reason: "tinted" | "shaded" | "toned" | "N/A" }

    boolean (if reason is truthy) OR an object containing the reason for purity determination (if reason is falsy)

isShaded

  • isShaded(): boolean
  • Helper for determining if a given color instance is shaded (lightness deviated downwards from a pure hue whose lightness is 50%)

    Returns boolean

isTinted

  • isTinted(): boolean
  • Helper for determining if a given color instance is tinted (lightness deviated upwards from a pure hue whose lightness is 50%)

    Returns boolean

isToned

  • isToned(): boolean
  • Helper for determining if a given color instance is toned (saturation deviated from a pure hue whose saturation is 100%)

    Returns boolean

isValid

  • isValid(): boolean
  • Determines if the current color instance is valid (based on the format returned by the parsers)

    Returns boolean

isWarm

  • isWarm(): boolean

laba

lcha

lighterBy

lightnessTo

  • Sets the lightness (tone) of a color in HSLA space to a specific value

    Parameters

    • value: number

    Returns ColorMaster

    The instance that was acted upon → for function chaining

luminance

  • luminance(opts?: Omit<IA11yOpts, "bgColor" | "ratio">): number

luva

mix

  • Mix current color instance with another based on a given ratio (done in LUVA space by default for best results)

    note

    Not specifying a ratio will cause equal proportions of colors to be mixed

    example

    CM("#000").mix({ color: "#fff", ratio: 0.2, colorspace: "rgb" }) → "mix 20% of white INTO 80% of the current color (black) using the RGB colorspace"

    default

    opts = { color: "#fff", ratio: 0.5, colorspace: "luv" }

    Parameters

    • Optional opts: IMix

    Returns ColorMaster

    A new color instance corresponding to the new mixture

name

  • Gets the color table HTML/CSS name for a given color

    note

    Colors with an alpha value of '0' return 'transparent'. Also, colors with alpha < 1, return CSS_NAME (with opacity)

    example

    CM("rgb(128, 0, 0)").name() → "maroon"

    default

    opts = { exact: true }

    Parameters

    Returns string

    The color's HTML/CSS name

readableOn

rgba

  • Converts a RGBA color instance to RGBA color object

    Returns Irgba

    A HSLA object containing the respective channel values

rotate

  • Rotation changes the hue of a color by value degrees in HSLA space

    Parameters

    • value: number

    Returns ColorMaster

    The instance that was acted upon → for function chaining

ryba

saturateBy

saturationTo

  • Sets the saturation (intensity) of color in HSLA space to a specific value

    Parameters

    • value: number

    Returns ColorMaster

    The instance that was acted upon → for function chaining

stringCMYK

  • Gives the string representation of an input CMYKA color object

    example

    CM({ r: 200, g: 150, b: 100, a: 0.7 }).stringCMYK() → "cmyka(0, 25, 50, 22)"

    default

    opts = { alpha: true, precision: [0, 0, 0, 0, 1] }

    Parameters

    Returns string

    device-cmyk(C, M, Y, K[, A])

stringHEX

  • stringHEX(__namedParameters?: { alpha: any }): string
  • Gives the string representation of an input HEXA color object

    Parameters

    • __namedParameters: { alpha: any } = {}

    Returns string

    #RRGGBB[AA]

stringHSL

  • stringHSL(__namedParameters?: { alpha: any; precision: any }): string
  • Gives the string representation of an input HSLA color object

    Parameters

    • __namedParameters: { alpha: any; precision: any } = {}

    Returns string

    hsl[a](H, S, L[, A])

stringHSV

  • Gives the string representation of an input HSVA color object

    example

    CM({ r: 200, g: 150, b: 100, a: 0.7 }).stringHSV() → "hsva(30, 50%, 78%, 0.7)"

    default

    opts = { alpha: true, precision: [0, 0, 0, 1] }

    Parameters

    Returns string

    hsv[a](H, S, V[, A])

stringHWB

  • Gives the string representation of an input HWBA color object

    example

    CM({ r: 200, g: 150, b: 100, a: 0.7 }).stringHWB() → "hwba(30, 39%, 22%, 0.7)"

    default

    opts = { alpha: true, precision: [0, 0, 0, 1] }

    Parameters

    Returns string

    hwb[a](H, W, B[, A])

stringLAB

  • Gives the string representation of an input LABA color object

    example

    CM({ r: 200, g: 150, b: 100, a: 0.7 }).stringLAB() → "laba(66%, 15, 34, 0.7)"

    default

    opts = { alpha: true, precision: [0, 0, 0, 1] }

    Parameters

    Returns string

    lab[a](L, A, B[, A])

stringLCH

  • Gives the string representation of an input LCHA color object

    example

    CM({ r: 200, g: 150, b: 100, a: 0.7 }).stringLCH() → "lcha(66%, 36, 69, 0.7)"

    default

    { alpha: true, precision: [0, 0, 0, 1] }

    Parameters

    Returns string

    lch[a](L, C, H[, A])

stringLUV

  • Gives the string representation of an input LUVA color object

    example

    CM({ r: 200, g: 150, b: 100, a: 0.7 }).stringLUV() → "color(luva 66%, 39%, 31%, 0.7)"

    default

    opts = { alpha: true, precision: [0, 0, 0, 1] }

    Parameters

    Returns string

    color(luv[a] L, A, B[, A])

stringRGB

  • stringRGB(__namedParameters?: { alpha: any; precision: any }): string
  • Gives the string representation of an input RGBA color object

    Parameters

    • __namedParameters: { alpha: any; precision: any } = {}

    Returns string

    rgb[a](R, G, B[, A])

stringRYB

  • Gives the string representation of an input RYBA color object

    example

    CM({ r: 200, g: 150, b: 100, a: 0.7 }).stringRYB() → "color(ryba 200, 200, 100, 0.7)"

    default

    opts = { alpha: true, precision: [0, 0, 0, 1] }

    Parameters

    Returns string

    color(ryb[a] R, Y, B[, A])

stringUVW

  • Gives the string representation of an input UVWA color object

    example

    CM({ r: 200, g: 150, b: 100, a: 0.7 }).stringUVW() → "color(uvwa 26, 35, 40, 0.7)"

    default

    opts = { alpha: true, precision: [0, 0, 0, 1] }

    Parameters

    Returns string

    color(uvw[a] U, V, W[, A])

stringXYZ

  • Gives the string representation of an input XYZA color object

    example

    CM({ r: 200, g: 150, b: 100, a: 0.7 }).stringXYZ() → "color(xyza 37, 35, 17, 0.7)"

    default

    opts = { alpha: true, precision: [0, 0, 0, 1] }

    see

    https://www.w3.org/TR/css-color-4/#predefined

    Parameters

    Returns string

    color(xyz[a] X, Y, Z[, A])

uvwa

xyza