API Docs

Bridge type for working with colors in JavaScript

Properties

This type has no properties.

Methods

staticHSColor.rgb(r, g, b, a) -> HSColor

Create a color from RGB values

HSColor.rgb(r, g, b, a) -> HSColor
Name Type Description
r number Red component (0.0-1.0)
g number Green component (0.0-1.0)
b number Blue component (0.0-1.0)
a number Alpha component (0.0-1.0)
An HSColor object

staticHSColor.hex(hex) -> HSColor

Create a color from a hex string

HSColor.hex(hex) -> HSColor
Name Type Description
hex string Hex string (e.g. "#FF0000", "FF0000", "#F00", or "#FF000080" with alpha)
An HSColor object

staticHSColor.named(name) -> HSColor

Create a color from a named system color

HSColor.named(name) -> HSColor
Name Type Description
name string Name of the system color (e.g. "red", "blue", "systemBlue")
An HSColor object

set(value) -> None

Update this color's value.

If this color is bound to a UI element, the canvas re-renders automatically.

set(value) -> None
Name Type Description
value string | HSColor A hex color string (e.g. "#FF0000") or another HSColor object
None
const reactive = HSColor.hex("#4A90E2")
reactive.set("#E24A4A")
reactive.set(HSColor.named("red"))

toJSON() -> object

Returns a plain object containing this color's sRGB components, for JSON serialisation

JSON.stringify() calls this automatically, so you rarely need to call it yourself.

toJSON() -> {red: number, green: number, blue: number, alpha: number}
object
An object with red, green, blue and alpha properties, each between 0.0 and 1.0, matching the arguments of HSColor.rgb()
Field Type Description
red number
green number
blue number
alpha number
JSON.stringify(HSColor.rgb(1, 0, 0, 0.5)) // '{"red":1,"green":0,"blue":0,"alpha":0.5}'