KScript docs
EN

color fields and methods

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.luminancenumberHow light it looks, from 0 (black) to 1 (white), as WCAG measures it.

From KScript.Core

#color->contrast_ratio(other: color) → number

The WCAG contrast ratio with the other colour, from 1 to 21. Text needs 4.5 or more.
ParameterTakes
other requiredcolor
Example
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->contrast_ratio('white') }</echo>
$x: color = '#ff8800'
echo $x->contrast_ratio('white')

#color->css() → string

Its CSS form: #rrggbb, or rgb(r g b / a) with transparency.
Example
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->css() }</echo>
$x: color = '#ff8800'
echo $x->css()

#color->darken(amount?: number) → color

Mixed with black: amount 0.2 (the default) is a fifth of the way.
ParameterTakes
amount optionalnumber
Example
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->darken() }</echo>
$x: color = '#ff8800'
echo $x->darken()

#color->hex() → string

Its #rrggbb form, without the alpha.
Example
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->hex() }</echo>
$x: color = '#ff8800'
echo $x->hex()

#color->lighten(amount?: number) → color

Mixed with white: amount 0.2 (the default) is a fifth of the way.
ParameterTakes
amount optionalnumber
Example
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->lighten(0.5) }</echo>
$x: color = '#ff8800'
echo $x->lighten(0.5)

#color->mix(other: color, amount?: number) → color

The colour part way to the other: amount 0.5 (the default) is halfway.
ParameterTakes
other requiredcolor
amount optionalnumber

Arguments can be named: ->mix(…, amount: …).

Example
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->mix('blue') }</echo>
$x: color = '#ff8800'
echo $x->mix('blue')

#color->rgb() → map

Its red, green, blue (0-255) and alpha (0-1): { r, g, b, a }.
Example
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->rgb() }</echo>
$x: color = '#ff8800'
echo $x->rgb()

Methods from any

Methods from string