Interface ColorDefinition

Each supported color model requires a definition object for detection and normalization.

See

ColorDetectors

Hierarchy

  • ColorDefinition

Properties

Methods

Properties

converters: {
    hex: Converter;
    hexa: Converter;
    hsb: Converter;
    hsl: Converter;
    hsla: Converter;
    hsv: Converter;
    hwb: Converter;
    rgb: Converter;
    rgba: Converter;
}

A list of methods that convert the current color model into another one. Every entry in the ColorName enum must be present for each definition.

Type declaration

re: RegExp

This should be able to detect a CSS string for a specific color model.

Remarks

Many color strings support multiple formats. For example, RGBA can be written as rgba(191, 205, 45, 0.7), rgba(75%, 40%, 100%, 50%), rgba(191 205 45 / 0.7), and rgba(75% 40% 100% / 50%) (and a few others). Non-CSS color strings like hsb and hsv simply use commas and have no alternative formats. The regex should also not care about extra spaces, so hsv(75deg, 75% 65%) and hsv( 75deg ,75%, 65% ) have identical results.

See

Methods

  • Convert the bits from a converter method into the format used in the color string.

    Remarks

    Fractions are converted to whole numbers (ex. 0.75 becomes 191 for RGB or 75 for percentage) or hexadecimal (ex. 0.75 becomes 'bf') and rounded off. Angles will already be in degrees before this method is called.

    Example

    // convert RGBA to HEX
    finalize({ r: 0.5, g: 1, b: 0.5, a: 1 }) // return { r: '80', g: 'ff', b: '80', a: 1 }

    Parameters

    • color: ColorModel

      This is the color model (from normalize) that should be converted to the final format.

    Returns ColorModel

  • Convert the bits from the regex to percentages for percentage and RGB values, and degrees for angles.

    Remarks

    Bits from the regex will begin at index 1 because index 0 is the original string. Each bit can be in any format supported by the color model, such as an angle (toDegrees), a float percentage, an actual percentage string, or a number. The normalize method is responsible for converting all of those to degrees in the case of an angle, or a float percentage for everything else. If an opacity isn't included (index AlphaIndex of bits is empty), then it is defaulted to 1.

    Example

    // input to {@link ColorDefinition.re} is 'rgb(128, 255, 191)'
    normalize(['rgb(128, 255, 191)', '128', '255', '191']) // return [0.5, 1, 0.75, 1]

    Parameters

    • bits: string[]

      Index 0 is the original string, so it should be ignored by the normalize method.

    Returns ConverterTuple

Generated using TypeDoc