# blip-tokens

Blip Design Tokens — the single source of truth for UI attributes (colors, spacing, typeface, icons, illustrations, etc.) consumed by the Blip Design System.

---

## Table of Contents

- [Getting Started](#getting-started)
- [Project Structure](#project-structure)
- [Design Tokens](#design-tokens)
- [Figma Tokens and Themes](#figma-tokens-and-themes)
- [Icons](#icons)
  - [Adding New Icons](#adding-new-icons)
  - [Icon Script (generate_icons)](#icon-script-generate_icons)
  - [Icon TypeScript Types (generate_icon_types)](#icon-typescript-types-generate_icon_types)
  - [Importing Icons in Your Project](#importing-icons-in-your-project)
- [Illustrations](#illustrations)
- [Emojis](#emojis)
- [Logos](#logos)
- [Components](#components)
- [CDN Assets](#cdn-assets)
- [Build](#build)
- [Build Outputs](#build-outputs)
- [CI/CD](#cicd)
- [Contributing](#contributing)

## Getting Started

Use Node.js 24, matching CI. From the repository root:

```bash
npm install
npm run build
```

To install the published package in a consuming project:

```bash
npm install blip-tokens
```

## Project Structure

```
blip-tokens/
├── assets/                        # Raw SVG source files
│   ├── components/
│   ├── emojis/
│   ├── icons/
│   │   ├── outline/               # Outline-style icons (.svg)
│   │   └── solid/                 # Solid-style icons (.svg)
│   │       └── flags/             # Flag icons (sub-folder)
│   ├── illustrations/             # Illustration categories (blip-outline, brand, default, …)
│   └── logos/
├── properties/                    # Asset registries and legacy token sources (published)
│   └── assets/
│       ├── icons.json             # Icon registry (name → SVG path)
│       ├── emojis.json            # Emoji registry
│       ├── illustrations.json     # Illustration registry
│       ├── logos.json             # Logo registry
│       ├── components.json        # Component artwork registry
│       ├── variables.json         # Legacy color palette tokens
│       ├── theme-light.json       # Legacy light theme semantic tokens
│       ├── theme-dark.json        # Legacy dark theme semantic tokens
│       ├── theme-high-contrast.json
│       └── extended-color.json    # Extended color palette
├── figma-source/                  # Reviewed live Figma snapshot and sync audit
├── scripts/
│   ├── build_tokens.js            # Figma-derived --uai-* outputs (Style Dictionary 5)
│   ├── figma-tokens.js            # Variable snapshot validation and compilation
│   ├── figma-styles.js            # Effect and text style compilation
│   ├── collect_tokens.js          # Assemble exported Figma chunks
│   ├── sync_tokens.js             # Preview/apply variable syncs
│   ├── sync_styles.js             # Preview/apply style syncs
│   ├── generate_icons.cjs         # Sync SVGs → icons.json registry
│   ├── generate_icon_types.js     # Generate TS types from filesystem
│   ├── generate_assets.cjs        # Validate/copy CDN SVGs and write manifest
│   ├── release_assets.cjs         # Build/upload exact Semantic Release version
│   └── test/                      # Asset build and release regression tests
├── tests/                         # Figma token pipeline, theme cascade and package tests
├── config.cjs                     # Build entry: legacy tokens (Style Dictionary 2), icons, Figma tokens, CDN assets
├── build/                         # Generated output (git-ignored)
├── docs/                          # Architecture Decision Records
└── package.json
```

---

## Design Tokens

The package publishes two token sets side by side while components migrate:

| Set | Source | Names | Status |
|---|---|---|---|
| **Figma tokens** | Figma variable library, `figma-source/` | `--uai-*` | Canonical; use for new work |
| **Legacy tokens** | `properties/assets/*.json` | `.color-*` / `.bg-*` classes, `$` SCSS variables, flat JSON | Unchanged; kept until blip-ds has migrated |

Legacy sources:

| Source File | Description |
|---|---|
| `variables.json` | Legacy base color palette |
| `theme-light.json` | Legacy light theme |
| `theme-dark.json` | Legacy dark theme |
| `theme-high-contrast.json` | Legacy high-contrast theme |
| `extended-color.json` | Legacy extended color set |

Legacy outputs (`build/json/*`, `build/scss/*`, `build/css/classes.css`) are
generated by the unchanged Style Dictionary 2 build, into the same folders as the
new `uai-*` files. The Figma pipeline only adds `uai-*` files, so migrating
components can rely on the legacy files until the legacy set is retired.

## Figma Tokens and Themes

The architecture and publication policy are recorded in
[AD-004](docs/ad/004-figma-token-pipeline-and-publication.md) and
[AD-005](docs/ad/005-legacy-and-figma-token-coexistence.md).

The package name remains **`blip-tokens`**, published to the public npm registry.
The reviewed source is the
[Figma variable library](https://www.figma.com/design/xNgjSCmKfbgd3ed5mIPdHo/UAI-Design-Tokens).
Builds run offline from `figma-source/variables.json` and
`figma-source/styles.json`; they never fetch Figma or require Figma credentials.

The internal snapshot preserves collection and variable IDs, descriptions,
scopes, modes and raw values/aliases. Foundation is internal build input and is
**not included in the Figma token outputs**. Its values are resolved into the
semantic tokens that use them. Only three semantic collections are published.
Public names are `--uai-` followed by the token path **without** the collection
name:

| Figma collection | Figma name | Example CSS custom property |
|---|---|---|
| Typography | `body/base/font-size` | `--uai-body-base-font-size` |
| Colors | `surface/background` | `--uai-surface-background` |
| Dimensions | `spacing/md` | `--uai-spacing-md` |
| Effect styles | `elevation/1` | `--uai-elevation-1` |

Names must be unique across the three published collections; the build fails on
a collision instead of overwriting a token. Text styles are not published as
CSS classes; see [Typography](#typography).

The raw Figma snapshot, including Foundation, is excluded from the published
package. Generated DTCG JSON contains only semantic tokens, with primitive
references resolved to values so it has no dangling aliases. Descriptions,
Figma scopes and variable IDs stay attached to each published semantic token.
CSS custom properties include each token's Figma usage description as a
comment. The legacy outputs remain available alongside them.
The 306-variable count covers variable collections only: 206 Foundation
primitives are internal, and 100 semantic variables are published. Separately,
the Figma file has eight elevation effect styles, published as variables, and
28 text styles, published as metadata, without exposing Foundation primitives.
There are no per-component color or typography tokens: components use the
semantic tokens directly, so their names stay stable across light and dark modes.

### Focus indicators

`border/ring` (`--uai-border-ring`) is a solid neutral focus color: dark in Light
mode and light in Dark mode, using the same Foundation aliases as `content/primary`.
It replaces the previous purple value without renaming the public token.
Consumers such as UaiButton keep a full-opacity focus outline.

For UaiInput, the focused control has two independent layers: a solid 1 px border
and a 2 px outer halo. Only the halo uses semantic `opacity/focus-ring`
(`--uai-opacity-focus-ring`, unitless `0.3`);
never reduce the opacity of the whole input or of every focus indicator.
The token lives in Dimensions: Figma opacity bindings require percentages, so
its source value is `30`, explicitly normalized to unitless `0.3` in DTCG,
CSS, SCSS and JavaScript outputs. Foundation's pre-existing fractional opacity
primitives remain private and unchanged. Do not invent a local opacity
value or reuse a pressed overlay for this role.
The halo is supplementary, not the only focus cue. Keep geometry tokenized,
avoid layout shifts, and verify focus contrast and forced-colors behavior in
the consuming component.

The halo maps directly to a zero-blur CSS shadow; it does not change the
control's box size:

```css
.control[data-focused] {
  border-color: var(--uai-border-ring);
  box-shadow: 0 0 0 var(--uai-border-width-thick)
    color-mix(in srgb, var(--uai-border-ring) calc(var(--uai-opacity-focus-ring) * 100%), transparent);
}

@media (forced-colors: active) {
  .control[data-focused] {
    box-shadow: none;
    outline: var(--uai-border-width-thick) solid CanvasText;
    outline-offset: var(--uai-border-width-default);
  }
}
```

The consumer tracks focus, not whether `value` is empty or typing is in progress.
Keep the normal border width and radius unchanged, and ensure that parent
containers do not clip the halo.

### Using the tokens in a component

#### Dark-mode contrast and action colors

The [dark-theme contrast and migration report](docs/dark-theme-contrast.md)
records the audited foreground/background pairs, changed values and consumer
impact. Dark text and feedback accents target **4.5:1** on the supported standard
surfaces; essential control borders and solid focus cues target **3:1**.
This is color-contrast coverage, not a claim of complete WCAG conformance.

- Use `feedback/*` for text/icons on standard or matching subtle surfaces, not
  as a universal filled-button background.
- Filled positive actions pair `action/positive` with
  `action/positive-foreground`. Filled destructive actions pair
  `action/destructive` with `action/destructive-foreground`. Never assume
  white text: both foregrounds are dark neutrals in Dark mode.
- `border/default` is decorative. Use `border/input` for an essential control
  boundary and `border/ring` for focus.
- `fixed/brand` keeps its brand value; pair it with `fixed/dim`, not white.
  Keep `fixed/bright` for supported dark backgrounds such as `fixed/dim` and
  `fixed/blue`.
- Keep non-color cues for errors, links and selection. Disabled content is
  exempt from contrast requirements; placeholders are not.
- Light placeholder, success and warning text have existing contrast gaps and
  are outside this Dark correction. Do not infer Light compliance from this audit.

The tokens are an internal contract of the blip-ds design system. Only blip-ds
components read them. Micro frontends (MFEs) consume blip-ds components and do
not import `blip-tokens` or use `var(--uai-*)`: spacing and layout come from the
design system's grids and templates, which use the tokens internally. If an MFE
needs something the design system does not cover, the design system changes.

blip-ds loads the tokens once, in its own entry:

```js
import 'blip-tokens/css/colors';
import 'blip-tokens/css/typography';
import 'blip-tokens/css/dimensions';
import 'blip-tokens/css/layout';
import 'blip-tokens/css/motion';
import 'blip-tokens/css/shadows';
// or, for all: import 'blip-tokens/css';
```

Components then read the variables in their own styles. There is nothing to
import per component. For example, a button:

```scss
.button {
  height: var(--uai-sizing-2xl);
  padding: 0 var(--uai-spacing-md);
  border-radius: var(--uai-radius-md);
  border: var(--uai-border-width-default) solid transparent;
  font-family: var(--uai-font-family-sans);
  font-size: var(--uai-body-base-font-size);
  line-height: var(--uai-body-base-line-height);
  font-weight: var(--uai-font-weight-semibold);

  &--primary {
    background: var(--uai-action-primary-default);
    color: var(--uai-action-primary-foreground);
    &:hover { background: var(--uai-action-primary-hover); }
    &:active { background: var(--uai-action-primary-pressed); }
  }

  &:focus-visible {
    outline: var(--uai-border-width-thick) solid var(--uai-border-ring);
  }
}
```

The Figma code syntax of every semantic variable shows its CSS name, for example
`var(--uai-action-primary-default)`, so names can be copied from the design.
Foundation primitives have no code syntax because they are not published.
Use the CSS variables for styling. The SCSS variables (`$uai-*`) and the
JavaScript maps hold static values and do not follow the theme.

The output is split by what the tokens are. Only colors depend on the theme:

| Entry | File | Tokens | Declared on |
|---|---|---|---|
| `blip-tokens/css` | `build/css/uai.css` | Imports the grouped files below | — |
| `blip-tokens/css/colors` | `build/css/uai-colors.css` | Surface, content, action, border, feedback, overlay, fixed and AI accent colors | Every theme root (light and dark) |
| `blip-tokens/css/typography` | `build/css/uai-typography.css` | Font families, sizes and line heights per role, weights, letter spacing | The outermost theme root |
| `blip-tokens/css/dimensions` | `build/css/uai-dimensions.css` | Spacing, sizing, control heights, radius, border width, opacity | The outermost theme root |
| `blip-tokens/css/layout` | `build/css/uai-layout.css` | Layout widths, z-index layers | The outermost theme root |
| `blip-tokens/css/motion` | `build/css/uai-motion.css` | Durations and easing curves | The outermost theme root |
| `blip-tokens/css/shadows` | `build/css/uai-shadows.css` | Eight elevation shadows | The outermost theme root |

SCSS follows the same split: `blip-tokens/scss/colors-light`,
`scss/colors-dark`, `scss/typography`, `scss/dimensions`, `scss/layout`,
`scss/motion` and `scss/shadows`.

Breakpoints (`$uai-breakpoint-xs|sm|md|lg`) are published only to SCSS
(`scss/layout`), JavaScript and JSON, never as CSS custom properties, because
media queries cannot read `var()`:

```scss
@use 'blip-tokens/scss/layout' as layout;

@media (max-width: layout.$uai-breakpoint-lg) { … }
```

The tokens are never declared at `:root`, `html` or `body`, so loading the CSS
does not change anything outside the theme roots. The `--uai-` prefix also keeps
every name apart from the v1 tokens, so v1 and v2 components can share a page.
Components never redeclare the variables; they only read them. Only elements
inside a theme root have tokens, so a component outside one renders without them.

A container can override a token for everything inside it, including nested
theme regions:

```css
.compact-panel { --uai-spacing-md: 0.75rem; }
```

### Themes

A theme root is an element with `data-uai-theme="light"` or `"dark"`. The
blip-ds theme provider renders that attribute on its host, and everything
inside the provider inherits the tokens. The nearest root wins for colors, so
regions can be nested:

```html
<bds-theme-provider theme="dark" data-uai-theme="dark">
  …
  <aside data-uai-theme="light">…</aside>    <!-- light region inside it -->
</bds-theme-provider>
```

The provider is the same `bds-theme-provider` used today, extended for v2: it
keeps the v1 `theme--*` classes and `--color-*` variables for the v1 components,
and also renders `data-uai-theme` for the new ones. The v1 classes and variables
do not feed the new tokens.

Each theme root also sets the CSS `color-scheme`. Typography, dimensions, layout,
motion and shadows do not depend on the theme, so they are declared only on the
outermost root and inherited by nested regions; that is why an override on a container
reaches components inside a nested region. The selectors use `:where()`, so a
rule that overrides a token on the theme root itself always wins.

The provider must:

- render `data-uai-theme` on its host, at the mount point of each MFE, in the
  light DOM: a stylesheet loaded in the document does not reach elements inside
  another component's shadow root;
- emit only `light` or `dark`. Any other value, including an empty one, makes the
  element a theme root without colors. The v1 `high-contrast` theme has no Figma
  equivalent, so the provider maps it to `light` or `dark`;
- copy the nearest `data-uai-theme` to the containers of portals (modals,
  tooltips, dropdowns), which attach to `<body>` and sit outside the provider;
- warn in development when a v2 component has no theme root above it.

The package does not read OS preferences or persist the selection. Both themes
expose the same custom-property names.

### Versioning of the tokens

Several versions of blip-ds v2 can end up on one page, each with its own copy of
the token CSS, and the same selectors then compete. To keep that safe, within a
major version tokens are only added or have their values adjusted, and are never
renamed or removed. Renames and removals ship in a major release.

### Trying the tokens before a release

`build/` is generated and not committed, so a pull request shows the pipeline
and the Figma snapshots, not the CSS. To see the files:

- run `npm ci && npm run build` on the branch and open `build/css/`; or
- download the `build-artifacts` artifact from the pull request's CI run; or
- run `npm run build && npm pack` on the branch and install the `.tgz` in blip-ds with
  `npm install ../blip-tokens/blip-tokens-0.0.0-development.tgz`.

### Shadows

The default CSS entry also includes the eight Figma elevation styles as custom
properties declared on the outermost theme root, for example
`box-shadow: var(--uai-elevation-1)`. They do not depend on the theme. Standalone entries are
`blip-tokens/css/shadows` and `blip-tokens/scss/shadows`.

Shadow layers retain their Figma order, RGB colors, opacity and pixel geometry.
For example, `--uai-elevation-3` contains two comma-separated shadows;
CSS, SCSS, JSON and JavaScript all expose the complete composition.

### Typography

The design system does not generate utility classes. A text style in Figma is a
role (`body/base`, `heading/lg`, …) plus a weight, so components compose text
from the semantic variables:

```css
.card-title {
  font-family: var(--uai-font-family-sans);
  font-size: var(--uai-title-md-font-size);
  line-height: var(--uai-title-md-line-height);
  font-weight: var(--uai-font-weight-semibold);
  letter-spacing: var(--uai-letter-spacing-normal);
}
```

Typography size roles are `title/lg` (18/24), `title/md` (16/24),
`title/sm` (14/20), `body/lg` (16/24), and `body/sm` (12/20), in pixels.
The existing `title/font-size` and `title/line-height` tokens remain
compatibility aliases to `title/md`.

The 28 Figma text styles are published as metadata only. Each entry in
`textStyles` names the variables that make it up, so a component can match its
Figma text style exactly:

```ts
textStyles['uai-typography-title-semibold'].tokens;
// { fontFamily: '--uai-font-family-sans', fontSize: '--uai-title-font-size',
//   lineHeight: '--uai-title-line-height', fontWeight: '--uai-font-weight-semibold',
//   letterSpacing: '--uai-letter-spacing-normal' }
```

The build fails if a text style stops matching its role and weight variables, so
Figma cannot drift from the published values. Display text uses
`--uai-font-family-display`; the spaced body style uses
`--uai-letter-spacing-expanded`.

### JavaScript, TypeScript and token JSON

```ts
import { light, dark, type TokenName } from 'blip-tokens/tokens';

const name: TokenName = 'uai-body-base-font-size';
console.log(light[name]); // "0.875rem"
console.log(dark['uai-surface-background']);
```

The ESM entry `blip-tokens/tokens` exports `light`, `dark`, `shadows`, `textStyles`
and `metadata`. The package root still resolves to the icon entry. Theme maps
contain resolved web values (strings or numbers); they do not switch themes
automatically.

`blip-tokens/tokens/light` and `blip-tokens/tokens/dark` export normalized DTCG
JSON with semantic descriptions, dimension objects in px and sRGB color objects.
They contain no Foundation tokens; references to Foundation are resolved. The
web-oriented metadata object is also available as
`blip-tokens/tokens/metadata`:

```ts
import { metadata, shadows, textStyles } from 'blip-tokens/tokens';

metadata['uai-surface-background'];
// { description, type, collection, scopes, figmaVariableId }

textStyles['uai-typography-body-base-regular'];
// { name, fontFamily, fontSize, lineHeight, fontWeight, letterSpacing, description, figmaStyleId, tokens }

shadows['uai-elevation-1'];
// { value, description, figmaStyleId }
```

Descriptions explain intended use and should be specific enough to guide design
and implementation decisions. The build rejects missing descriptions so that
the token API remains useful to people and AI tools. The original snapshot and
audit trail remain maintainer-only and are not packed into npm. DTCG files are
design-token data, not the transformed web maps. SCSS variables are available via the
`blip-tokens/scss/colors-light`, `scss/colors-dark`, `scss/typography`,
`scss/dimensions` and `scss/shadows` package entries using a package-aware Sass
resolver. They hold static values, so prefer the CSS variables for themed styles.

### Unit policy

| Usage | Source/normalized DTCG | Web output |
|---|---|---|
| Font size and line height | px | rem, at 16 px per rem |
| Spacing, sizing, control height, radius, breakpoint and layout width | px | rem, at 16 px per rem |
| Border width | px | px |
| Shadow geometry | px | px |
| Letter spacing / font tracking | px | px |
| Opacity and font weight | number | unitless number |
| Layer / z-index | integer | unitless integer |
| Duration | seconds | milliseconds (`ms`) |
| Easing curve | Figma cubic Bezier | CSS `cubic-bezier(...)` |

The current Figma tracking primitives explicitly document pixels; do not infer
`em` or percent from their numeric values. A future change requires an explicit
policy and tests. Conversion is applied by semantic usage after resolving raw
aliases: a shared Foundation dimension can become `rem` when used as spacing,
sizing, control height, radius, breakpoint, width or typography, while remaining
`px` for border width. Figma opacity percentages are normalized to 0–1, while
layers remain non-negative integers. Figma durations in seconds are emitted as milliseconds. The build does not
change the application's root font size.

Raw Figma floats are preserved in the snapshot. Normalized numeric/color values
are rounded to six decimal places to remove serialization noise (for example,
`-0.4000000059604645` becomes `-0.4`).

### Synchronization

Maintainers use the repository-internal
[tokens-sync skill](.github/skills/tokens-sync/SKILL.md) for **Figma to repository**
sync. There is no background sync or automatic write-back to Figma.

```sh
# Assemble every exported chunk into a new candidate file outside the repository.
npm run tokens:collect -- /tmp/blip-candidate.json /tmp/blip-chunk-0.json /tmp/blip-chunk-40.json
# Preview only.
npm run tokens:sync -- /tmp/blip-candidate.json
# Apply reviewed changes and append the audit record.
npm run tokens:sync -- /tmp/blip-candidate.json --apply
```

The collector example abbreviates the chunk list; pass all chunks until the
declared total is covered. The sync validates the complete snapshot, reports
before/after changes, and requires `--approve-breaking` in addition to `--apply`
for explicitly approved removals or renames. No-op exports leave the source and
audit untouched. Commit the snapshot and audit together; never edit the audit
by hand. Unknown types, missing modes, broken aliases, cycles and naming
collisions fail the build instead of being silently skipped.

Composite Figma styles are exported and synced independently because they are
not variable collections. The styles workflow maintains its own snapshot and
hash-linked audit:

```sh
npm run tokens:styles:sync -- /tmp/blip-styles-candidate.json
npm run tokens:styles:sync -- /tmp/blip-styles-candidate.json --apply
```

Style removals and renames also require explicit approval and
`--approve-breaking`. Inventory changes require updating the compiler and tests
before applying the snapshot.

Style snapshot schema 2 stores each effect row as
`[id, name, description, layers]`, where each layer is
`[x, y, blur, spread, red, green, blue, alpha]`. Layers are ordered and nonempty;
the exporter rejects hidden effects and effects other than `DROP_SHADOW`.
Text rows retain their existing format. Schema 1 remains readable so historical
snapshot hashes and the audit chain are preserved.

The initial source is a fresh live export, not the UAI repository's snapshot.
Tokens that exist only in that other repository are not implicitly added here.

### Figma library revision, 2026-10-16

This revision of the Figma library removes and renames variables and styles
relative to the earlier Figma snapshot. That snapshot was never published to
npm, and the `--uai-*` names are new, so no published consumer is affected:
existing consumers keep using the unchanged legacy outputs. Use this section
when migrating work-in-progress code that adopted earlier Figma names. There
are no compatibility aliases. Audit entries retain the exact before/after data
and original Figma IDs.

| Previous name | New name preserving the original variable/style ID |
|---|---|
| `spacing/6xl` (80 px) | `spacing/7xl` (80 px) |
| `spacing/7xl` (96 px) | `spacing/9xl` (96 px) |
| `letter-spacing/body` | `letter-spacing/normal` |
| `elevation/xs` | `elevation/floating-control` |
| `elevation/sm` | `elevation/tab-active` |
| `elevation/md` | `elevation/1` |
| `elevation/lg` | `elevation/2` |
| `elevation/xl` | `elevation/dialog` |
| `elevation/2xl` | `elevation/sidebar-right` |

The new `spacing/6xl` is 72 px (4.5 rem), not the previous 80 px; the existing
`spacing/7xl` name now resolves to 80 px (5 rem), not 96 px. Update consumers
explicitly to preserve their intended geometry. New spacing tokens include
`spacing/8xl` at 88 px (5.5 rem). Renamed shadows also have revised geometry;
renaming alone does not preserve their previous appearance.

Removed public variables:

- Dimensions: `sizing/5xl`, `sizing/6xl`, `border-width/thin`,
  `border-width/medium`, `border-width/heavy`.
- Typography: `display/font-family`, `heading/xl/font-family`,
  `heading/lg/font-family`, `heading/md/font-family`, `title/font-family`,
  `body/lg/font-family`, `body/base/font-family`, `body/sm/font-family`,
  `caption/font-family`, `overline/font-family`, `body/lg/font-size`,
  `body/lg/line-height`, `body/sm/font-size`, `body/sm/line-height`,
  `font-weight/light`, `letter-spacing/heading`.
- Colors: `surface/foreground`, `surface/paper-foreground`, `surface/brand`,
  `surface/brand-foreground`, `surface/muted-foreground`, `surface/elevated`,
  `surface/elevated-foreground`, `surface/accent`, `surface/accent-foreground`,
  `content/heading`, `action/secondary/default`, `action/secondary/hover`,
  `action/secondary/pressed`, `action/secondary/foreground`, `border/subtle`,
  `feedback/destructive`.

Replacements, where the values are equivalent. The eight `body/lg/*` and
`body/sm/*` text styles have the same values as `title/*` and `caption/*`:

| Removed | Use instead |
|---|---|
| `uai-typography-body-lg-{regular,medium,semibold,bold}` (16/24) | `uai-typography-title-*` with the same weight |
| `uai-typography-body-sm-{regular,medium,semibold,bold}` (12/20) | `uai-typography-caption-*` with the same weight |
| `--uai-*-font-family` | `--uai-font-family-sans`, or `--uai-font-family-display` for display text |
| `--uai-letter-spacing-heading` | `--uai-letter-spacing-normal` |
| `--uai-surface-brand` / `--uai-surface-brand-foreground` | `--uai-fixed-brand` / `--uai-fixed-bright` |
| `--uai-border-subtle` | `--uai-border-default`; in dark mode this is `slate.850` instead of `slate.800` |
| `--uai-border-width-heavy` (4 px) | `--uai-border-width-thick` (2 px); the stroke is thinner |

The remaining removals have no one-to-one replacement. Choose a semantic variable
from its usage description. New styles include `elevation/3` and
`elevation/sidebar-left`; `content/inverse` is the new semantic foreground for
inverted surfaces. Retained color paths keep their Light and Dark values.

---

## Icons

Icons are SVG files stored in `assets/icons/`. The build copies validated SVGs directly from source into the CDN upload directory and records their paths and hashes in the asset manifest. It does not generate base64 JSON catalogs or include SVG artwork in the npm package.

There are two icon variants:

| Variant | Directory | Naming convention in `icons.json` |
|---|---|---|
| **Outline** | `assets/icons/outline/` | `<name>-outline` |
| **Solid** | `assets/icons/solid/` | `<name>-solid` |

### UAI Icon font

The separate UAI icon set lives in `assets/uai-icons/outline/` and `assets/uai-icons/solid/`. Its SVGs are uploaded to the versioned CDN. The generated monochrome WOFF2 font and glyph data are published under `uai-icon/font/` and `uai-icon/glyphs.json` in the CDN. The npm package bundles only the CSS under `build/uai-icons/`, exported as `blip-tokens/uai-icons/css`; the CSS references the versioned CDN font. The legacy `assets/icons/` registry, names, and build remain independent.

The generated font uses `currentColor`, so icon color follows the CSS `color` property of the element (or an inherited color). Import the bundled stylesheet, then use the base class, glyph class, and a size class. The WOFF2 font and glyph manifest are available from the versioned CDN; only the stylesheet is included in the package.

```html
<link rel="stylesheet" href="node_modules/blip-tokens/build/uai-icons/uai-icon.css">
<i class="uai-icon uai-icon-outline-favorite uai-icon-32" aria-hidden="true"></i>
<span class="uai-icon uai-icon-solid-favorite uai-icon-24" style="color: #e2483d" aria-hidden="true"></span>
```

Supported size classes are `uai-icon-16`, `uai-icon-24`, and `uai-icon-32`. The glyph class is `uai-icon-<variant>-<name>`; when two icons share a leaf name, the category is included to disambiguate, for example `uai-icon-outline-file-video` and `uai-icon-outline-media-video`.

The build generates the font source from the UAI SVGs, replacing their monochrome fill/stroke colors with `currentColor`; transparent fills such as `fill="none"` are preserved. This transformation is isolated to the font source and does not modify the shipped UAI SVG assets.

### Adding New Icons

1. **Place the SVG file** in the correct folder:
   - Outline icons → `assets/icons/outline/`
   - Solid icons → `assets/icons/solid/`
   - (Sub-folders like `solid/flags/` are supported)

2. **Register the icon** in `properties/assets/icons.json`:

   ```json
   "icon-name-outline": {
     "value": "assets/icons/outline/icon-name.svg"
   }
   ```

   Or for solid:

   ```json
   "icon-name-solid": {
     "value": "assets/icons/solid/icon-name.svg"
   }
   ```

   > The list is organized alphabetically, with all outline icons first, then all solid icons.

3. **Or use the automated script** (recommended):

   ```bash
  (cd scripts && node generate_icons.cjs)
   ```

   The script scans `assets/icons/`, detects unregistered SVGs, and interactively prompts you to add them to `icons.json`. It also sorts the file automatically.

4. **Build** to generate the CDN SVGs, asset manifest, and icon names/types:

   ```bash
   npm run build
   ```

  The manual and automated registration methods are alternatives. Registry entries belong under `asset.icon` in `properties/assets/icons.json`.

### Icon Script (`generate_icons`)

**File:** `scripts/generate_icons.cjs`

This CommonJS script:
- Recursively scans `assets/icons/` for `.svg` files
- Compares found files against `properties/assets/icons.json`
- Reports files that are missing from the registry or that reference missing SVGs
- Interactively asks whether to add unregistered files
- Auto-generates the key using the convention `<filename>-<variant>` (e.g. `add-outline`, `heart-solid`)
- Sorts the resulting JSON (outline first, then solid, both alphabetically)

### Icon TypeScript Types (`generate_icon_types`)

**File:** `scripts/generate_icon_types.js`

This ESM script runs automatically at the end of `npm run build`. It:
- Scans the filesystem (`assets/icons/outline/` and `assets/icons/solid/`) directly
- Generates `build/icons.js` with runtime arrays (`OutlineIcons`, `SolidIcons`, `AllIcons`) and helper functions (`isOutlineIcon`, `isSolidIcon`, `isValidIcon`)
- Generates `build/icons.d.ts` with TypeScript type definitions (`OutlineIcon`, `SolidIcon`, `IconName`)

### Importing Icons in Your Project

#### Runtime arrays

```typescript
import { OutlineIcons, SolidIcons, AllIcons } from 'blip-tokens/icons';

console.log(OutlineIcons); // ["123", "ab", "add", ...]
console.log(SolidIcons);   // ["add", "attention", ...]
console.log(AllIcons);     // Union of both, deduplicated
```

#### TypeScript types

```typescript
import type { OutlineIcon, SolidIcon, IconName } from 'blip-tokens/icons';

function renderIcon(name: OutlineIcon) {
  // TypeScript validates and auto-completes icon names
}
```

#### Helper functions

```typescript
import { isOutlineIcon, isSolidIcon, isValidIcon } from 'blip-tokens/icons';

if (isValidIcon(userInput)) {
  // Safe to use
}
```

> See [AD-003](docs/ad/003-icon-type-exports.md) for full usage examples (React components, dynamic pickers, form validation).

---

## Illustrations

Illustration SVGs live in `assets/illustrations/` organized by category (`default`, `brand`, `blip-outline`, `blip-solid`, `empty-states`, `screens`, `segmented`, `smartphone`, `spots`, `logo-integration`).

Registry: `properties/assets/illustrations.json` (under `asset`).

The build copies registered SVGs to `build/assets/v1/illustrations/<category>/` for CDN upload and adds `illustration/<category>/<name>` entries to the manifest. It does not generate per-category illustration JSON catalogs.

---

## Emojis

Emoji SVGs live in `assets/emojis/`.

Registry: `properties/assets/emojis.json` (under `asset.emoji`). Registered SVGs are copied to `build/assets/v1/emojis/` for CDN upload and listed in the manifest.

---

## Logos

Logo SVGs live in `assets/logos/`.

Registry: `properties/assets/logos.json` (under `asset.logo`). Registered SVGs are copied to `build/assets/v1/logos/` for CDN upload and listed in the manifest.

---

## Components

Component artwork SVGs live in `assets/components/` and are registered under `asset.component` in `properties/assets/components.json`. The build copies them to `build/assets/v1/components/` for CDN upload and lists them in the manifest.

---

## CDN Assets

Artwork families and UAI icons are delivered as standalone SVGs through the CDN, not embedded in the npm package. Import the packaged manifest to resolve an asset URL:

```javascript
import manifest from 'blip-tokens/assets/manifest' with { type: 'json' };

const asset = manifest.assets['asset-icon-add-outline'];
const url = new URL(`${manifest.version}/${asset.path}`, manifest.baseUrl).href;
```

JSON import syntax depends on the consuming runtime or bundler. Each manifest entry provides `path`, `bytes`, `sha256`, and `contentType`; the manifest also provides `schemaVersion`, `version`, and `baseUrl`. Keys use `asset-icon-<name>`, `asset-emoji-<name>`, `asset-logo-<name>`, `asset-component-<name>`, or `illustration/<category>/<name>`. Icon manifest keys include the variant suffix; the icon name arrays and TypeScript types do not.

The default URL pattern is `https://cdn.blip.ai/blip-tokens/<version>/<asset.path>`. Use the manifest shipped with the installed package so its version and asset paths stay aligned. A local build's `unreleased` directory is not published automatically.

### Figtree

The CDN manifest includes the variable Figtree WOFF2 subsets `font/figtree/latin`
and `font/figtree/latin-ext`, both covering weights 300–900. Resolve each URL from
the installed package's manifest; use both subsets with the matching
`unicode-range` declarations from the
[Google Fonts stylesheet](https://fonts.googleapis.com/css2?family=Figtree:wght@300..900&display=swap).
The same CDN manifest also includes `font/figtree/license` (`fonts/figtree/OFL.txt`).
The font and license are CDN-only and are not included in the npm package.

Figtree is redistributed under the SIL Open Font License 1.1. Keep the license
available alongside the font when using these assets. Source files are from
[Google Fonts' Figtree family](https://github.com/google/fonts/tree/main/ofl/figtree).

The generator validates SVG documents, active content, external references,
WOFF2 signatures, the Figtree license, source paths outside `assets/`, and
duplicate output paths. Add artwork to its registry as well as the filesystem;
CDN generation reads registries, while icon names/types are generated from the
filesystem.

---

## Build

```bash
npm run build
```

No asset environment variables are required locally. Ordinary local builds use the fixed `unreleased` path because branch-specific CDN directories are not published. In CI, the build requires `CDN_ASSETS_VERSION` from shared workflow conventions unless an explicit release version is supplied; pull requests receive a unique preview version, and release builds use the conventions project version. The build fails if CI provides neither version. Semantic Release passes its exact next version explicitly to the build so the published npm package and CDN directory always agree. The default CDN root is `https://cdn.blip.ai/blip-tokens/`.

| Setting | Behavior |
|---|---|
| `CDN_ASSETS_VERSION` | Required in CI; must be an exact version such as `2.0.3` or `2.0.3-pr.42`. Ignored by ordinary local builds. |
| `CDN_ASSETS_CDN_URL` | Optional CDN root override; must be HTTPS, end in `/`, and contain no credentials, query, or fragment. |
| `npm run build -- --version <version>` | Explicit exact release version override; takes precedence over the CI version. Used by release automation. |

During `npm publish`, `prepublishOnly` also passes npm's `npm_package_version`
explicitly to the asset generator. This preserves the exact release version even
when the publish lifecycle does not receive `CDN_ASSETS_VERSION`.

The build clears previous outputs and runs four steps:

1. **Style Dictionary 2** (`config.cjs`) — transforms only color and theme tokens into the legacy JSON, CSS, and SCSS; artwork registries are not inputs
2. **Icon types generator** (`scripts/generate_icon_types.js`) — produces `build/icons.js` and `build/icons.d.ts`
3. **Figma token pipeline** (`scripts/build_tokens.js`) — validates the Figma snapshot, normalizes DTCG, resolves aliases and generates the `--uai-*` outputs with Style Dictionary 5. It runs after step 1 and writes only `uai-*` files, `tokens.js` and `tokens.d.ts`, so the legacy files are not touched
4. **CDN asset generator** (`scripts/generate_assets.cjs`) — reads the SVG source registries directly, validates and copies artwork and Figtree font files, and generates the asset manifest without intermediate embedded JSON catalogs

Style Dictionary 5 is installed as the `style-dictionary-v5` alias next to
Style Dictionary 2, which the legacy and asset builds still use. Run `npm test`
for the Figma pipeline tests together with the asset and release tests.

### Build Outputs

Outputs are grouped by format. Figma-derived files carry the `uai-` prefix and sit
next to the legacy files, which keep their original names and paths:

```
build/
├── css/
│   ├── uai.css                # Entry: imports all grouped uai-* files below
│   ├── uai-colors.css         # Color variables: one block per theme root
│   ├── uai-typography.css     # Typography variables, outermost theme root
│   ├── uai-dimensions.css     # Spacing, sizing, control heights, radius, border width and opacity
│   ├── uai-layout.css         # Widths and z-index layers (breakpoints are SCSS/JS only)
│   ├── uai-motion.css         # Durations and easing curves
│   ├── uai-shadows.css        # Elevation variables, outermost theme root
│   └── classes.css            # Legacy color and background classes
├── scss/
│   ├── uai-colors-light.scss  # $uai-* color variables, light values
│   ├── uai-colors-dark.scss   # $uai-* color variables, dark values
│   ├── uai-typography.scss
│   ├── uai-dimensions.scss
│   ├── uai-layout.scss
│   ├── uai-motion.scss
│   ├── uai-shadows.scss
│   └── theme-*.scss, variables.scss, extended-color.scss  # Legacy palette and themes
├── json/
│   ├── uai-light.tokens.json  # Semantic DTCG with resolved aliases
│   ├── uai-dark.tokens.json
│   ├── uai-metadata.json      # Figma descriptions, scopes and IDs
│   ├── uai-shadows.json       # Eight composed elevation styles
│   ├── uai-text-styles.json   # 28 text styles and the variables that compose each
│   ├── variables.json         # Legacy flat JSON of non-artwork tokens
│   ├── colors.json            # Legacy palette
│   ├── theme-*.json           # Legacy themes (light, dark, high-contrast)
│   └── extended-color.json    # Legacy extended palette
├── assets/v1/
│   ├── manifest.json          # Packaged inventory; used for validation, not uploaded
│   ├── .../*.svg              # CDN upload only; excluded from npm
│   └── fonts/figtree/         # Variable WOFF2 subsets and OFL license; CDN only
├── tokens.js                  # ESM theme maps, styles and metadata
├── tokens.d.ts                # Token, style and metadata types
├── icons.js                   # Runtime icon arrays + helpers
└── icons.d.ts                 # TypeScript type definitions
```

The npm package contains design tokens, icon names and types, path-only source registries, and the CDN manifest exported as `blip-tokens/assets/manifest`. The build does not generate the old embedded-SVG `assets_*.json` or illustration JSON catalogs. Consumers of those catalogs must resolve artwork through the CDN manifest instead.

Packaging uses `.npmignore` exclusions instead of a per-file `package.json` allowlist, so new token outputs are included automatically. Raw SVGs, raw source artwork, legacy embedded-artwork catalogs, and development files (including `figma-source/`, `tests/` and `docs/`) are excluded from npm. The standalone SVGs remain in `build/assets/v1` for CDN upload; packaging does not delete them. Tests inspect a real npm archive to check that tokens and exports remain available without raw or embedded SVG artwork.

Consumers of the Figma tokens import through the package `exports` (for example
`blip-tokens/css` or `blip-tokens/css/colors`), which map to the `uai-*`
files, so file names can change without affecting them. The legacy outputs are
exposed by path through `blip-tokens/build/css/*`, `blip-tokens/build/scss/*`
and `blip-tokens/build/json/*`. The package root (`blip-tokens`) still resolves
to the icon entry; the token maps are at `blip-tokens/tokens`.

---

## CI/CD

- **Workflow:** `.github/workflows/nodejs.yml`
- **Triggers:** Pushes to `main`, pushes of `v*` tags, pull requests targeting `main`, and manual dispatch. Fork pull requests do not run the reusable CI job.
- **Pipeline:** Delegates to the shared Node workflow with Node.js 24, `npm run test:ci`, `npm run lint`, and `npm run build`. `test:ci` and `lint` cover the Figma token pipeline as well as the asset scripts.
- **Test reports:** `test:ci` writes JUnit to `TestResults/junit.xml` and LCOV to `TestResults/coverage/lcov.info`.
- **CDN:** Publishes `build/assets/v1` using release versioning. Shared conventions supply the build version; release preparation builds and uploads the exact upcoming release before npm publication.
- **npm:** [Semantic Release](https://github.com/semantic-release/semantic-release) publishes to `https://registry.npmjs.org/` using the `PUBLIC_NPM_TOKEN` secret. The `prepublishOnly` lifecycle rebuilds with npm's exact package version.

Release automation requires the shared `cdn-assets` bootstrap to supply `CDN_ASSETS_ACTION_PATH` and validated `CDN_ASSETS_DEPLOYMENT_JSON`. These are not required for a local build. An npm publish rebuild does not itself upload artwork; publish through the configured release pipeline to keep CDN assets available for the package version.

---

## Contributing

1. Follow [Conventional Commits](https://www.conventionalcommits.org/) — the release process depends on it
2. PR titles must use the correct type prefix (`feat:`, `fix:`, `chore:`, `docs:`, etc.)
3. When adding icons, prefer using the `generate_icons.cjs` script to keep `icons.json` consistent
4. Run `npm test`, `npm run lint`, and `npm run build` locally to verify your changes
5. The `build/` directory is git-ignored — never commit it
