# songstress/theme

> A theme's colours as the apps read them.

Page: https://songstress.app/docs/develop/reference/theme/

See [Themes](/docs/develop/themes/#colours).

What it exports is the SDK's own record of its public surface, which the SDK's tests hold to the code. Each type's
fields, and every description, are read from the SDK's source when the site is built.

It also exports, as the modules that declare them document them: [THEME_TOKENS](/docs/develop/reference/manifest/#type-THEME_TOKENS), [ThemeColors](/docs/develop/reference/manifest/#type-ThemeColors), [ThemeLook](/docs/develop/reference/manifest/#type-ThemeLook), [ThemeToken](/docs/develop/reference/manifest/#type-ThemeToken).

### MAX_COLOR_LENGTH

The longest colour a theme may write.

```ts
export declare const MAX_COLOR_LENGTH = 64;
```

### ParsedColor

A colour, read.

| Field | Type | Description |
|---|---|---|
| `hex` | `string` | Its one form: `#rrggbb`, or `#rrggbbaa` when it is translucent, in lower case. |
| `alpha` | `number` | From 0 to 1, as the form keeps it (in steps of 1/255): 1 for an opaque colour. |

### TRANSLUCENT_TOKENS

The tokens that may be translucent: every other colour of a theme is opaque.

```ts
export declare const TRANSLUCENT_TOKENS: readonly [
    "surface.hover",
    "border"
];
```

### normalizeColor

A colour in its one form, `#rrggbb` or `#rrggbbaa`; nothing for a value that is not a colour.

```ts
export declare function normalizeColor(value: string): string | undefined;
```

| Parameter | Type | Description |
|---|---|---|
| `value` | `string` | A colour as a theme writes it. |

Returns `string | undefined`: Its one form, or undefined.

### normalizeLook

A look with each colour in its one form, `#rrggbb` or `#rrggbbaa`, and nothing a look may not hold: a value
that is not one of a theme's colours, a translucent one where its place is opaque, a token this version does
not name, glow past the third. What is left out an app fills in, as it fills any token a look leaves out.
Nothing, for a value with no colour left in it. A look that passed `songstress/manifest`'s checks loses
nothing here: it only changes form.

```ts
export declare function normalizeLook(look: unknown): ThemeLook | undefined;
```

| Parameter | Type | Description |
|---|---|---|
| `look` | `unknown` | A look as a theme file holds it. |

Returns `ThemeLook | undefined`: The look in its one form, or undefined.

Refers to [ThemeLook](/docs/develop/reference/manifest/#type-ThemeLook).

### parseColor

Reads a colour as a theme writes it; nothing for a value that is not one of a theme's forms (SPEC.md,
section 12): a name, `currentColor`, `var()`, a gradient, a part out of its range, more than 64 characters.

```ts
export declare function parseColor(value: string): ParsedColor | undefined;
```

| Parameter | Type | Description |
|---|---|---|
| `value` | `string` | A colour as a theme writes it: hex, `rgb()`, `rgba()`, `hsl()` or `hsla()`. |

Returns `ParsedColor | undefined`: Its one form and its alpha, or undefined.

Example:

```ts
import { parseColor } from 'songstress/theme'

parseColor('#FF464A') // { hex: '#ff464a', alpha: 1 }
parseColor('red') // undefined: a name is not one of a theme's forms
```

Refers to [ParsedColor](/docs/develop/reference/theme/#type-ParsedColor).
