Color

data class Color(val value: String) : CssValue(source)

See CSS Color Module Level 3

This class represents a CSS color value. String parameters to the constructor argument can take one of the following forms:

  • HTML color name, e.g. `Red`, `DarkSalmon` (case-insensitive), though in this case the use of the pre-defined constants is recommended.

  • `#rgb` or `#rrggbb`

  • `rgb(0..255, 0..255, 0..255)`, `rgb(0..100%, 0..100%, 0..100%)`, `rgb(0..100%, 0..100%, 0..100%, 0..1)`, `rgba(0..255, 0..255, 0..255, 0..1)`

  • `hsl(0..360, 0-100%, 0..100%)` or `hsla(0..360, 0-100%, 0..100%, 0..1)`

Technically, the Hue parameter to `hsl` or `hsla` can exceed `360`, because it represents a degree (angle) on the color wheel. But as per the algorithm proposed by the W3C, the value will ultimately be capped to `360` through a series of modulus operations; see section 4.2.4. HSL color values of the above specification.

Constructors

Link copied to clipboard
constructor(value: String)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val value: String

Functions

Link copied to clipboard
fun blend(backgroundColor: Color): Color
Link copied to clipboard
fun changeAlpha(alpha: Double): Color

changeAlpha rewrites existing alpha value: rgba(0, 0, 0, 0.5).withAlpha(0.1) = rgba(0, 0, 0, 0.1)

Link copied to clipboard
fun darken(percent: Int): Color

Darken the color by the specified percent (between 0-100), returning a new instance of Color.

Link copied to clipboard
fun desaturate(percent: Int): Color

Desaturate the color by the specified percent (between 0-100), returning a new instance of Color.

Link copied to clipboard
fun lighten(percent: Int): Color

Lighten the color by the specified percent (between 0-100), returning a new instance of Color.

Link copied to clipboard
fun saturate(percent: Int): Color

Saturate the color by the specified percent (between 0-100), returning a new instance of Color.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun withAlpha(alpha: Double): Color

withAlpha preserves existing alpha value: rgba(0, 0, 0, 0.5).withAlpha(0.1) = rgba(0, 0, 0, 0.05)