Interface CSSColor

All Known Subinterfaces:
HSLColor, HWBColor, LABColor, LCHColor, RGBAColor, XYZColor

public interface CSSColor
A color.
  • Method Details

    • getColorModel

      CSSColorValue.ColorModel getColorModel()
      Get the color model that this color uses.

      If this methods returns the PROFILE value, this color belongs to a custom profile.

      Returns:
      the color model.
    • getColorSpace

      String getColorSpace()
      Get the color space to which this color belongs.

      See ColorSpace.

      Returns:
      the color space.
    • getAlpha

      CSSPrimitiveValue getAlpha()
      Get the alpha channel of this color.
      Returns:
      the alpha channel.
    • item

      CSSPrimitiveValue item(int index)
      Get the component of this color located at index.

      The alpha channel is considered the component 0, so the actual color component index starts at 1.

      Parameters:
      index - the index. 0 is always the alpha channel.
      Returns:
      the component, or null if the index is out of range.
    • getLength

      int getLength()
      The number of component values plus the alpha channel.
      Returns:
      the number of component values plus the alpha channel.
    • toNumberArray

      double[] toNumberArray() throws DOMException
      Convert the color components to a normalized form and put them in an array.

      The array does not include the alpha channel (that is, the array length is getLength() - 1).

      For RGB colors, the components are in the [0,1] interval.

      Returns:
      the array with the non-alpha normalized color components.
      Throws:
      DOMException - INVALID_STATE_ERR if the components cannot be converted to numbers.
    • toColorSpace

      CSSColor toColorSpace(String colorSpace) throws DOMException
      Convert this color to the given CSS color space.
      Parameters:
      colorSpace - the destination color space. The color spaces in ColorSpace are supported, as well as the other valid CSS space names (hsl and hwb).
      Returns:
      a color converted to the given color space.
      Throws:
      DOMException - if the color space is not supported.
      IllegalStateException - if the color components have to be converted to typed values.
    • toMinifiedString

      String toMinifiedString()
      Gives a minified string representation of this color.
      Returns:
      a minified serialization.
    • packInValue

      CSSColorValue packInValue()
      Pack this color into a new CSS value.

      Colors that come from a conversion sometimes aren't packed into a CSSColorValue, and this method provides a way to create one.

      Returns:
      the new CSS value packing this color.
    • clone

      CSSColor clone()
      Clone this color.
      Returns:
      a clone of this color.