# `math.color`

> Contract 2.0.0 · package sha256 `a857eca95b35921109faf997094bb4192f12527d9d0fcd4be7e97f06425bad6e` · generated from `math.d.ts` by `services/onsite-scripter/scripts/build-contract-docs.mjs`; edit the source, not this file.

Const · `import { color } from '@holostep-configurators/runtime-client/math';` · stable · since 2.0.0 · section 23. /math

sRGB hex colours and linear components.

## Members

| Member | Kind | Summary |
| --- | --- | --- |
| <a id="tolinear"></a>[`toLinear`](math.color.toLinear.md) | method | Linear Rec.709 components 0..1 of an sRGB hex colour. |
| <a id="tohex"></a>[`toHex`](math.color.toHex.md) | method | The sRGB hex colour of linear components 0..1. |
| <a id="parse"></a>[`parse`](math.color.parse.md) | method | Checks a string from your data: '#rgb' or '#rrggbb' (any case), returned as '#rrggbb'; null otherwise. |

## Declaration

```ts
export const color: {
  toLinear(hex: HexColor): {
    r: number;
    g: number;
    b: number;
  };
  toHex(linear: {
    r: number;
    g: number;
    b: number;
  }): HexColor;
  parse(text: string): HexColor | null;
};
```

## Example

Imports: values (`has`, `validate`, the `Holo*Error` classes, the pure helpers) from `@holostep-configurators/runtime-client`, types from `@holostep-configurators/runtime-client/contract`, `/math` and `/testing` names from those entries; `boot` from the runtime module the root's `loadRuntimeAtFloor` resolves to. A type your page defines is your app's: declare it there, never import it from the package.

Compiled under the contract's strict settings (`examples/declaration/23-color.ts`):

```ts
import { color } from '@holostep-configurators/runtime-client/math';
import type { Session } from '@holostep-configurators/runtime-client/contract';
declare const session: Session;
declare const signal: AbortSignal;
declare const row: { colour: string };                    // a string from your data, not a HexColor
const hex = color.parse(row.colour) ?? '#ffffff';
await session.find({ tag: 'frame' }).set({ material: { baseColor: hex } });
```

## Generic-API test (spec 3.1)

| Rule | Result |
| --- | --- |
| 1. Neutral name | pass: `color` names no product |
| 2. A precedent | not recorded: no ledger row (coverage.json) names this member or its owner |
| 3. Two apps, or labs | not recorded: no ledger row names this member or its owner |
| 4. The cheaper fix first | not recorded per member (Appendix B decides it per need) |
