> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/BintzGavin/helios/llms.txt
> Use this file to discover all available pages before exploring further.

# Color

> Color parsing and interpolation utilities for Helios

## RgbaColor

Interface representing a color in RGBA format.

```typescript theme={null}
interface RgbaColor {
  r: number;
  g: number;
  b: number;
  a: number;
}
```

<ResponseField name="r" type="number">
  Red component (0-255)
</ResponseField>

<ResponseField name="g" type="number">
  Green component (0-255)
</ResponseField>

<ResponseField name="b" type="number">
  Blue component (0-255)
</ResponseField>

<ResponseField name="a" type="number">
  Alpha component (0-1)
</ResponseField>

## parseColor

Parses a color string into an RGBA object.

```typescript theme={null}
function parseColor(color: string): RgbaColor
```

<ParamField path="color" type="string" required>
  Color string in hex, RGB/RGBA, or HSL/HSLA format
</ParamField>

<ResponseField name="return" type="RgbaColor">
  Parsed color as an RGBA object
</ResponseField>

### Supported formats

* **Hex**: `#RGB`, `#RGBA`, `#RRGGBB`, `#RRGGBBAA`
* **RGB/RGBA**: `rgb(r, g, b)`, `rgba(r, g, b, a)`
* **HSL/HSLA**: `hsl(h, s%, l%)`, `hsla(h, s%, l%, a)`

### Example

```typescript theme={null}
import { parseColor } from '@helios-project/core';

// Hex formats
const red = parseColor('#f00');
const blue = parseColor('#0000ff');
const transparent = parseColor('#ff000080');

// RGB formats
const green = parseColor('rgb(0, 255, 0)');
const semiTransparent = parseColor('rgba(255, 0, 0, 0.5)');

// HSL formats
const yellow = parseColor('hsl(60, 100%, 50%)');
const purple = parseColor('hsla(270, 100%, 50%, 0.8)');

console.log(red); // { r: 255, g: 0, b: 0, a: 1 }
```

### Errors

Throws `HeliosError` with code `INVALID_COLOR_FORMAT` if the color string is not in a supported format.

## interpolateColors

Interpolates between colors based on an input value.

```typescript theme={null}
function interpolateColors(
  input: number,
  inputRange: number[],
  outputRange: string[],
  options?: InterpolateOptions
): string
```

<ParamField path="input" type="number" required>
  The value to interpolate
</ParamField>

<ParamField path="inputRange" type="number[]" required>
  Array of input values (must be strictly monotonically increasing). Minimum 2 elements.
</ParamField>

<ParamField path="outputRange" type="string[]" required>
  Array of output color strings (must match length of inputRange). Colors can be in any supported format.
</ParamField>

<ParamField path="options" type="InterpolateOptions">
  Configuration for extrapolation and easing
</ParamField>

<ResponseField name="return" type="string">
  Interpolated color as an RGBA string
</ResponseField>

### Options

<ParamField path="options.extrapolateLeft" type="'extend' | 'clamp' | 'identity'">
  Behavior when input is less than the first inputRange value. Default: `'extend'`
</ParamField>

<ParamField path="options.extrapolateRight" type="'extend' | 'clamp' | 'identity'">
  Behavior when input is greater than the last inputRange value. Default: `'extend'`
</ParamField>

<ParamField path="options.easing" type="(t: number) => number">
  Easing function to apply to the interpolation ratio
</ParamField>

### Example

```typescript theme={null}
import { interpolateColors } from '@helios-project/core';
import { easeInOut } from '@helios-project/core';

// Simple color transition
const color = interpolateColors(
  0.5,
  [0, 1],
  ['#ff0000', '#0000ff']
);
console.log(color); // 'rgba(127, 0, 127, 1)'

// Multi-stop gradient
const gradient = interpolateColors(
  50,
  [0, 50, 100],
  ['red', 'yellow', 'green']
);

// With easing
const smooth = interpolateColors(
  frame,
  [0, 60],
  ['#000', '#fff'],
  { easing: easeInOut }
);

// Clamp extrapolation
const clamped = interpolateColors(
  150,
  [0, 100],
  ['blue', 'red'],
  { extrapolateRight: 'clamp' }
); // Returns 'rgba(255, 0, 0, 1)' instead of extrapolating
```

### Errors

Throws `HeliosError` with:

* `INVALID_INPUT_RANGE` if inputRange and outputRange lengths don't match or have fewer than 2 elements
* `UNSORTED_INPUT_RANGE` if inputRange is not strictly monotonically increasing
* `INVALID_COLOR_FORMAT` if any color in outputRange cannot be parsed
