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 Field Type Description .luminancenumber How 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.
Parameter Takes other required color
Example
.kscript XML Copy
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->contrast_ratio('white') }</echo>.kscript XML Copy
$x: color = '#ff8800'
echo $x->contrast_ratio('white')# color ->css () → string Its CSS form: #rrggbb, or rgb(r g b / a) with transparency.
Example
.kscript XML Copy
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->css() }</echo>.kscript XML Copy
$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.
Parameter Takes amount optional number
Example
.kscript XML Copy
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->darken() }</echo>.kscript XML Copy
$x: color = '#ff8800'
echo $x->darken()# color ->hex () → string Its #rrggbb form, without the alpha.
Example
.kscript XML Copy
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->hex() }</echo>.kscript XML Copy
$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.
Parameter Takes amount optional number
Example
.kscript XML Copy
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->lighten(0.5) }</echo>.kscript XML Copy
$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.
Arguments can be named: ->mix(…, amount: …).
Example
.kscript XML Copy
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->mix('blue') }</echo>.kscript XML Copy
$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
.kscript XML Copy
<let name="x" type="color" value="'#ff8800'" />
<echo>{ $x->rgb() }</echo>.kscript XML Copy
$x: color = '#ff8800'
echo $x->rgb()Methods from any Methods from string