formatCssString

fun Color.formatCssString(hueUnit: AngleUnit = AngleUnit.AUTO, renderAlpha: RenderCondition = RenderCondition.AUTO, unitsPercent: Boolean = false, alphaPercent: Boolean = false, legacyName: Boolean = false, legacyFormat: Boolean = false, customColorSpaces: Map<String, ColorSpace<*>> = emptyMap()): String

Render this color in CSS functional notation.

If CSS defines a color function syntax for this color's model (e.g. lab()), it will be used. Otherwise, the color() syntax will be used. For color spaces not predefined by CSS, you can pass them in customColorSpaces. Other color spaces will use a dashed identifier based on the space's name.

Note that for LAB, and LCHab, the CSS standard requires that the D50 white point be used. For XYZ, D50 and D65 are supported. Colors using other white points will be adapted to D50 before being serialized. Most color models default to D65, so you should use XYZ50, XYZ, LAB50, and LCHab50 if you're serializing a color in those models.

Examples

> RGB(255, 0, 128, .5f).formatCssString()
"rgb(255 0 128 / .5)"
> ROMM_RGB(0.1, 0.2, 0.3).formatCssString()
"color(prophoto-rgb 0.1 0.2 0.3)"
> JzAzBz(0.1, 0.2, 0.3).formatCssString()
"color(--jzazbz 0.1 0.2 0.3)"
> JzAzBz(0.1, 0.2, 0.3).formatCssString(customColorSpaces=listOf("jzazbz" to JzAzBz))
"color(jzazbz 0.1 0.2 0.3)"

Parameters

hueUnit

The unit to use to render hue values, if this color has any.

renderAlpha

Whether to render the alpha value.

unitsPercent

If true, render this color's components as percentages if the color syntax supports it.

alphaPercent

If true, render the alpha as a percentage. By default, it's rendered as a float.

legacyName

If true, use the legacy names hsla or rgba instead of hsl or `rgb for those functions.

legacyFormat

If true, use commas instead of spaces as separators for rgb and hsl functions. Other colors are unaffected.

customColorSpaces

A list of custom color spaces to use in the color() function. Each pair should be the identifier of the color and its ColorSpace.