# Design tokens — one standard, every brand (1.15.0) Every site built on IAPL uses the same token **names** (`--ipal-*`), the same scale, the same dark-mode mechanism and the same Tailwind utilities. Only the **values** differ per brand. Components (the shared blocks, the plugin's own UI, the project's sections) read only tokens, so a new brand is a new `DESIGN.md` plus one tokens file. Nobody edits a component. Everything here is opt-in. A site that imports none of it looks exactly as before. Every value can be overridden. ## What the plugin ships | Export | What it is | |---|---| | `@intecion/ipal-kit/tokens.css` | neutral defaults for every token: light on `:root` / `[data-theme="light"]`, dark on `[data-theme="dark"]` (any element), the inverse scope, reduced motion | | `@intecion/ipal-kit/tailwind.css` | Tailwind 4 preset: `@theme inline` map (utilities below), `dark:` on `data-theme`, `duration-*` / `z-*` utilities, a small base layer, the theme-switch transition | | `@intecion/ipal-kit/fluid-wide.css` / `fluid.css` | the type and space scale (`--ipal-fs-*`, `--ipal-space-*`, containers, height helpers): grows to 1920 px / 1280 px | | `@intecion/ipal-kit/a11y.css` | optional CSS for the accessibility widget's attributes, working through the tokens (accessibility.md) | | `@intecion/ipal-kit/tokens` | TS entry with no Payload/React import: `defineTokens`, `IAPL_TOKENS`, `iaplVar`, `IAPL_BREAKPOINTS`, `tokensToCss`, `contrastReport`, `fluidClamp` … | | `iapl-tokens` (bin) | `src/design/tokens.ts` → `src/design/tokens.css` + WCAG contrast check | `defineTokens`, `IAPL_TOKENS`, `iaplVar`, `IAPL_BREAKPOINTS` and the types `IaplTokenName`, `TokensInput` are also exported from the root entry (`@intecion/ipal-kit`). ## Wiring (a new site) ```css /* src/app/(frontend)/styles.css — the same on every site */ @import "tailwindcss"; @import "@intecion/ipal-kit/fluid-wide.css"; /* default for new sites; or fluid.css */ @import "@intecion/ipal-kit/tokens.css"; /* neutral defaults */ @import "@intecion/ipal-kit/tailwind.css"; /* utilities, dark variant, base layer */ @import "../../design/tokens.css"; /* the brand — generated, always last */ @source "../../../node_modules/@intecion/ipal-kit/dist/**/*.js"; ``` ```ts // src/design/tokens.ts — the ONLY file you edit to rebrand (template: iapl-setup/resources/tokens.ts) import { defineTokens } from '@intecion/ipal-kit/tokens' export const tokens = defineTokens({ theme: 'both', // 'light' | 'dark' | 'both' — match Site settings → Theme fluid: 'wide', // the fluid file styles.css imports color: { light: { primary: 'oklch(0.5 0.17 250)', accent: 'oklch(0.78 0.15 85)' }, dark: { bg: 'oklch(0.16 0.01 250)' }, // brand roles left out carry over from light }, font: { fwHeading: 700 }, radius: { control: '999px', card: '1.25rem' }, fs: { h1: ['2.25rem', '4rem'] }, // min → max; the clamp() is computed for the fluid range }) ``` ```bash pnpm exec iapl-tokens ``` ```tsx // src/app/(frontend)/[locale]/layout.tsx — fonts in the two fixed slots const body = Inter({ subsets: ['latin', 'latin-ext'], variable: '--font-family-body', display: 'swap' }) const heading = Fraunces({ subsets: ['latin', 'latin-ext'], variable: '--font-family-heading', display: 'swap' }) ``` The slots are `--font-family-body` / `--font-family-heading` (and `--font-family-mono`), never `--font-body`. `--font-body` is the Tailwind key behind `font-body`, and that key maps back to the token, so the two would form a `var()` cycle. Dark mode: `` (theme.md). Nothing else is needed: the roles switch on `data-theme`. **Check.** - `pnpm exec iapl-tokens --check` → `✓ … up to date`. `pnpm exec iapl-tokens` exits 0, with no ✗ rows. - In the browser, `getComputedStyle(document.documentElement).getPropertyValue('--ipal-primary')` returns the brand value. - Switch the theme: `--ipal-bg` changes. - The cookie banner uses the brand colour in both themes. ## The tokens ### Colour roles (switch with the theme) | Token `--ipal-…` | Role | Utility | |---|---|---| | `bg` | page background (`settings.background = default`) | `bg-bg` | | `surface` | card, panel, banner | `bg-surface` | | `surface-muted` | alternate section (`muted`) | `bg-surface-muted` | | `surface-raised` | header, popover, dropdown | `bg-surface-raised` | | `surface-inverse` / `text-inverse` | inverted section (`inverted`) | `bg-inverse` / `text-on-inverse` | | `text` · `text-strong` · `text-muted` | body · headings · captions | `text-fg` · `text-fg-strong` · `text-fg-muted` | | `border` · `border-strong` | dividers, inputs, cards | `border-border` · `border-border-strong` | | `primary` · `primary-hover` · `primary-text` | main buttons, key accents | `bg-primary` · `hover:bg-primary-hover` · `text-on-primary` | | `secondary` · `secondary-hover` · `secondary-text` | second button (default: neutral strong) | `bg-secondary` · `text-on-secondary` | | `accent` · `accent-text` | highlight, badge, rating stars (default: primary) | `bg-accent` · `text-accent` · `text-on-accent` | | `link` · `link-hover` | links in running text | `text-link` · `hover:text-link-hover` | | `link-inverse` · `focus-inverse` · `primary-inverse` · `primary-inverse-text` | link, focus ring and primary button inside an inverted section | (read through the inverse scope) | | `hover` | neutral hover (ghost button, row) | `bg-hover` | | `focus` | focus ring | `outline-focus` · `ring-focus` | | `overlay` | scrim, hero image overlay | `bg-overlay` · `from-overlay` | | `success` · `warning` · `danger` · `info` (+ `-surface`) | form and status states | `text-danger` · `bg-danger-surface` … | Unset hovers, links and focus derive from `primary` with `color-mix(in oklch, …)`. Write values in oklch (the standard). Any CSS colour works. ### Type, space, shape, motion | Group | Tokens | Utilities | |---|---|---| | Fonts | `font-body`, `font-heading`, `font-mono`; `fw-body`, `fw-heading`, `lh-body`, `lh-heading`, `tracking-heading` | `font-body` (= `font-sans`), `font-heading`, `font-mono`, `leading-body`, `leading-heading`, `tracking-heading` | | Sizes (fluid) | `fs-xs`, `fs-sm`, `fs-base`, `fs-lg`, `fs-h4`, `fs-h3`, `fs-h2`, `fs-h1`, `fs-display` | `text-xs` … `text-display`, `text-lead` (= `fs-lg`) | | Space (fluid) | `space-stack`, `space-gap`, `space-gutter`, `space-section-sm`, `space-section` | `space-y-stack`/`mt-stack`, `gap-gap`, `px-gutter`, `py-section-sm`, `py-section` | | Radius | `radius` (controls), `radius-sm`, `radius-card`, `radius-media`, `radius-full` | `rounded-control`, `rounded-sm`, `rounded-card`, `rounded-media`, `rounded-full` | | Shadow | `shadow-sm`, `shadow-md`, `shadow-lg` (dark theme: deeper + hairline ring) | `shadow-sm/md/lg` | | Layout | `container` (80rem), `container-wide` (96rem), `container-narrow` (48rem), `measure` (68ch), `hero-min-h`, `*-fit` | `max-w-container`, `max-w-container-wide`, `max-w-narrow`, `max-w-measure` | | Motion | `duration-fast` 150ms, `duration` 250ms, `duration-slow` 400ms, `ease-out`, `ease-in-out` (all durations 0 with reduced motion or `data-a11y-motion="reduce"`) | `duration-fast`, `duration-base`, `duration-slow`, `ease-out`, `ease-in-out` | | Layers, focus | `z-header` 40, `z-overlay` 50, `z-toast` 60; `focus-width`, `focus-offset` | `z-header`, `z-overlay`, `z-toast` | | Breakpoints | fixed: `sm 40 · md 48 · lg 64 · xl 80 · 2xl 96` rem (Tailwind defaults); `IAPL_BREAKPOINTS` for `sizes=` / `matchMedia` | `sm:` … `2xl:` | A project may *add* a breakpoint (`--breakpoint-xs`) as a deviation recorded in `DESIGN.md`. It never moves an existing one. ### Themes on any element `data-theme="dark"` / `"light"` switches the colour roles on any element, not only ``: a dark panel on a light page, or a styleguide showing both themes side by side (`
…
`). The preset's base layer gives such a panel its text colour; give it a background yourself (`bg-bg` or `bg-surface`). The Tailwind `dark:` variant follows the nearest `data-theme`. ### Inverted sections `
` with `settings.background = inverted` renders `bg-inverse` and `data-surface="inverse"`. Inside that scope, `text`, `text-strong`, `text-muted`, `border(-strong)`, `surface`, `hover`, `link`, `focus` and `primary` (+ `primary-hover`, `primary-text`) are re-mapped for the inverse surface, and `color-scheme` flips. Cards, rich text, links, focus rings and primary buttons need no inverse variants: they keep `text-fg`, `text-link`, `border-border`, `bg-primary text-on-primary`. `primary` inside reads **`primary-inverse`** / **`primary-inverse-text`** (default: the brand primary). A dark brand colour vanishes on a dark inverse surface: the contrast report warns (`primary on surface-inverse` below 3:1, inverse scope), so set a lighter one, per theme: `color: { light: { 'primary-inverse': 'oklch(0.85 0.1 150)', 'primary-inverse-text': 'oklch(0.2 0.05 150)' } }`. `accent` is not re-mapped. Put `data-surface` and `data-theme` on different elements. ### Legacy `-dark` names `--ipal-surface-dark`, `--ipal-text-dark` … (the cookie banner's old twins) stay as aliases: in the dark theme `tokens.css` sets each to its role. The banner and button now read the single names. Without `tokens.css`, their fallback follows the page's `color-scheme` (`light-dark()`) and still honours a `-dark` variable a site sets. New code never reads `-dark`. ## `iapl-tokens` | Command | Does | |---|---| | `pnpm exec iapl-tokens` | writes `src/design/tokens.css` (only what differs from the defaults), prints the failing contrast pairs, exits 1 on a WCAG AA failure | | `--check` | writes nothing; exits 1 when the CSS is out of date (CI, `iapl-doctor`) | | `--report` | prints every checked pair: paste into `DESIGN.md` → Colour | | `--warn-only` | contrast failures do not fail the command | | `--in --out ` | other paths; `--in` also takes `.mjs` / `.js` / `.json` | The input must export `tokens` (or a default export). `.ts` needs Node 22.18+ (type stripping). The contrast check covers text on every surface (4.5:1) in both themes, text on primary/secondary/accent, the inverse scope, the states, and focus rings (3:1). ## Building blocks (`@intecion/ipal-kit/tokens`) | Export | Use | |---|---| | `defineTokens(input)` | checks every role and size name, returns the input (type `TokensInput`, colours `ColorInput`) | | `tokensToCss(input, { source })` | the brand CSS the CLI writes | | `defaultTokensCss()` | the content of `tokens.css` | | `contrastReport(input)` → `ContrastRow[]` | the WCAG check; `contrastRatio(fg, bg)`, `parseColor(css, lookup)` for your own pairs | | `resolveColors(input)` | each theme's final colour values (defaults + brand) | | `fluidClamp(min, max, range)` | the fluid.css `clamp()` for your own sizes; `FLUID_SCALE`, `FLUID_RANGES`, type `FluidRange`, `RemValue` | | `IAPL_TOKENS`, `iaplVar(name, fallback?)` | `var(--ipal-…)` strings for inline styles, charts, a styleguide page (type `IaplTokenName`) | | `IAPL_BREAKPOINTS` | breakpoints in rem | | `COLOR_DEFAULTS`, `STATIC_DEFAULTS`, `FLUID_TOKENS`, `INVERSE_SCOPE`, `LEGACY_DARK_ROLES`, `LIGHT_SELECTOR`, `DARK_SELECTOR`, `INVERSE_SELECTOR`, type `ColorRole` | the catalogue itself | Values that CSS variables can't reach (`next/og` images, e-mail templates, ``): import `tokens` from `@/design/tokens` and read `resolveColors(tokens).light.primary`. ## DESIGN.md The template (`iapl-setup/resources/DESIGN.md`) has nine fixed sections: brand, colour (with the contrast report), type, shape, layout, motion, imagery, theme, deviations. `DESIGN.md` is the human source and `tokens.ts` its machine form. They must agree. The vendored `ext-frontend-design` skill may propose a direction, but its palette is mapped onto these roles in `DESIGN.md` / `tokens.ts` after the owner approves. It never adds token names, colours or fonts in components. ## Turn off, override, extend - **Turn off:** don't import a file. `tokens.css` without `tailwind.css` works for plain CSS (`var(--ipal-…)`). No `tokens.ts` means the neutral defaults. A plain-CSS site (no Tailwind) imports `tokens.css` alone. - **Override:** every value in `tokens.ts` (`raw: { 'hero-min-h': '…' }` for anything without a field), or plain CSS after the imports. The cookie banner and button also keep `classNames` / `className`. - **Extend:** project-only tokens (decorative brand colours) go in `styles.css` below the imports and in `DESIGN.md` → Deviations. A missing *role* every site would need → plugin gap (`iapl-plugin-gap`). ## Migrating an existing site 1. `iapl-upgrade` to 1.15.0, add the imports above and `src/design/tokens.ts`. 2. Map the site's current `@theme` colours to the roles, its fonts to the slots, and its radius, container and fluid pairs into `tokens.ts`. Keep the old names as aliases (`--color-brand: var(--ipal-primary)`) in a `/* legacy, remove after migration */` block, so no component breaks on day one. 3. Delete the `--ipal-*-dark` block the site kept only to stop the cookie banner going dark. 4. Replace old utilities and hard-coded values file by file (`iapl-audit` lists them). Remove `dark:` colour classes. 5. Remove the legacy block. Write `DESIGN.md` from the template.