API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classColor

@codexo/exojs / core / stable

32-bit RGBA color value with channel-wise accessors. Red, green, and blue are integers in 0..255; alpha is a float in 0..1. Out-of-range values are saturated on assignment (RGB clamped to 0..255 and truncated to an integer, alpha clamped to 0..1) - values outside the range no longer wrap around. The class predefines the eight corners of the RGB cube plus the two transparent ends as shared static instances (`Color.black`, `Color.magenta`, `Color.transparent`, ...). These instances are shared on purpose - do not mutate them; Color.clone first if you need a mutable starting point. Development builds freeze them, so writing to one throws there and passes unnoticed in production. Any other color is written as a value: `new Color(0x6495ed)`, `Color.fromHex('#6495ed')`, or channel by channel. Internally caches the packed RGBA32 representation and a normalized `Float32Array` for upload to GPU buffers; both are invalidated on channel writes and rebuilt lazily.

15
props
14
methods
0
events
Import
import { Color } from '@codexo/exojs'

32-bit RGBA color value with channel-wise accessors. Red, green, and blue are integers in 0..255; alpha is a float in 0..1. Out-of-range values are saturated on assignment (RGB clamped to 0..255 and truncated to an integer, alpha clamped to 0..1) - values outside the range no longer wrap around.

The class predefines the eight corners of the RGB cube plus the two transparent ends as shared static instances (`Color.black`, `Color.magenta`, `Color.transparent`, ...). These instances are shared on purpose - do not mutate them; Color.clone first if you need a mutable starting point. Development builds freeze them, so writing to one throws there and passes unnoticed in production. Any other color is written as a value: `new Color(0x6495ed)`, `Color.fromHex('#6495ed')`, or channel by channel.

Internally caches the packed RGBA32 representation and a normalized `Float32Array` for upload to GPU buffers; both are invalidated on channel writes and rebuilt lazily.

Constructors2
new(rgb?: number, alpha?: number): Color
Build from a packed 0xRRGGBB value, with alpha as a separate argument. The packed form deliberately stops at six digits: JavaScript numbers carry no leading zeros, so 0x00FF00FF (opaque green as RGBA) and 0xFF00FF (magenta as RGB) are the *same* value at runtime and cannot be told apart. Use a string ('#00ff00ff') when alpha belongs in the literal.
new(r: number, g: number, b: number, a?: number): Color
Build channel by channel. RGB are 0..255 integers, alpha is a 0..1 float.
Methods14
clone(): this
copy(color: Color): this
destroy(): void
equals(__namedParameters: Partial<Color>): boolean
set(r: number, g: number, b: number, a: number): this
Set any subset of channels. Omitted parameters default to the current channel value (use this for "set red, leave the rest"). RGB are clamped to 0..255; alpha is clamped to 0..1.
setHex(value: number | string, alpha?: number): this
Overwrite this color from a hex value, in place. Same input forms as Color.fromHex; use this instead of the factory in a loop, where the factory's allocation would land in the frame budget.
toArray(normalized: boolean): Float32Array
Return an RGBA Float32Array view backed by an internal cache. Pass normalized = true to map RGB into 0..1 (typical for shader uploads); default returns 0..255 RGB and 0..1 alpha. The returned array is the same instance across calls - copy it if you need a stable snapshot.
toHex(alpha: boolean, prefixed: boolean): string
Return the color as a hex string. alpha = true appends the alpha pair (#RRGGBBAA, CSS order); prefixed = false omits the leading #. Unlike Color.toRgb, the alpha form is unambiguous here: a string still carries its own length, so it can be read back by Color.fromHex exactly as written.
toRgb(): number
Return the RGB channels packed as 0xRRGGBB - the exact form the constructor and Color.fromHex accept, so the two round-trip. Alpha is not included; it cannot be, for the reason the constructor gives.
toRgba8(): number
Return one RGBA8 texel as a little-endian Uint32 - the value written into a Uint32Array row for GPU upload (R in the low byte, A in the high byte), matching TextureFormat.Rgba8. This is a pixel format, **not** a color literal: written out it reads 0xAABBGGRR, the reverse of the 0xRRGGBB the constructor takes. Do not feed it back into Color.from; use Color.toRgb for that. Cached after first call until any channel is written. RGB is preserved at every alpha - a fully transparent red and a fully transparent black pack to different values.
toString(): string
The six-digit hex form, so a color can be handed straight to a CSS or canvas property.
Build from a packed 0xRRGGBB number, a hex string, another color, or a plain { r, g, b, a } object. alpha overrides whatever the value carried. A number never carries alpha here - see the constructor for why six digits is the limit. Hex strings have no such problem, because their length is still there to read: '#f0f', '#f0fc', '#ff00ff' and '#ff00ffcc' are all accepted, alpha last, as CSS Color 4 spells them.
fromCss(value: string, alpha?: number): Color
Build from any CSS color the runtime's own parser understands: the four hex forms, rgb()/rgba(), hsl()/hsla(), hwb(), the CSS named colors, and anything else the engine resolves into sRGB. alpha overrides an alpha the value carried. The parsing is the platform's, not this package's, so the set of accepted syntaxes is the host engine's and the call needs a document - it throws in a worker and in any non-DOM host. It also throws on a value the engine rejects, and on one it accepts but keeps in a wider color space than sRGB (lab(), oklch(), color-mix() on some engines). Reach for Color.fromHex when the value is already hex: that path is self-contained, needs no document, and cannot be affected by the host.
fromHex(value: number | string, alpha?: number): Color
Build from a hex value in either spelling: a 0xRRGGBB number, or a string in any of the four CSS forms (#RGB, #RGBA, #RRGGBB, #RRGGBBAA, with or without the leading #). alpha overrides an alpha the string carried. Throws on a string that is not one of those forms. The check stays on in production because this is an input parser: a hex value often comes from a document or a theme rather than from source, and quietly returning black would hide the broken input rather than report it.
Properties15
black: Color
blue: Color
cyan: Color
green: Color
magenta: Color
red: Color
transparent: Color
CSS transparent, which is defined as rgba(0, 0, 0, 0) - the same instance as Color.transparentBlack.
transparentBlack: Color
transparentWhite: Color
white: Color
yellow: Color
a: number
b: number
g: number
r: number
Source