feat(tailwind): map semantic tokens and add system type scale

Map the nine contract colour tokens to their CSS custom properties so no
utility hard-codes a palette value, replace the webfont stack with a system
font stack, and rebuild the type scale with a 16px/1.6 body step and three
heading steps above it.
This commit is contained in:
Locust agent
2026-11-02 21:23:13 +00:00
parent fbf62031fe
commit 683cdd56d2
+96 -6
View File
@@ -1,15 +1,98 @@
/**
* Semantic token bridge between the Tailwind theme and the stylesheet.
*
* The nine contract tokens live as CSS custom properties in the stylesheet
* (light values in `:root`, dark values in `.dark`):
*
* --color-background, --color-foreground, --color-muted,
* --color-muted-foreground, --color-border, --color-accent,
* --color-accent-foreground, --color-text-body, --color-text-large
*
* Every colour utility below reads its custom property, so no utility
* hard-codes a palette hex value and a theme swap only touches the stylesheet.
*/
/**
* Resolve a semantic token to its CSS custom property.
*
* The base utility gets the plain `var()` reference. Opacity modifiers
* (`bg-background/50`) need an alpha channel, which a bare `var()` cannot
* carry, so those get `color-mix()` instead of being dropped from the build.
*/
const token = (name) => ({ opacityValue }) => {
const value = `var(--color-${name})`;
if (opacityValue === undefined) return value;
const ratio = typeof opacityValue === 'number' ? opacityValue : Number.parseFloat(opacityValue);
// The base utility reports its opacity as the `var(--tw-*-opacity, 1)` fallback.
if (!Number.isFinite(ratio)) return value;
return `color-mix(in srgb, ${value} ${ratio * 100}%, transparent)`;
};
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{vue,js,ts,jsx,tsx}",
],
// Keep the semantic utilities in the bundle even before a component
// references them, so the token layer ships as a whole. Dark mode needs no
// extra entries: the custom properties swap values under `.dark`.
safelist: [
'bg-background', 'bg-foreground', 'bg-muted', 'bg-muted-foreground', 'bg-border', 'bg-accent', 'bg-accent-foreground', 'bg-body', 'bg-large',
'text-background', 'text-foreground', 'text-muted', 'text-muted-foreground', 'text-border', 'text-accent', 'text-accent-foreground', 'text-body', 'text-large',
'border-background', 'border-foreground', 'border-muted', 'border-muted-foreground', 'border-border', 'border-accent', 'border-accent-foreground', 'border-body', 'border-large',
'text-body-base', 'text-body-lg', 'text-title', 'text-heading', 'text-heading-lg', 'text-display-sm', 'text-display',
'font-sans', 'font-mono',
// Opacity modifiers resolve through `color-mix()`, so the common steps
// ship with the token layer instead of being dropped from the build.
'bg-background/50', 'bg-background/80', 'bg-muted/50', 'bg-accent/50',
'text-foreground/70', 'text-muted/80', 'text-accent/80', 'border-border/50',
],
darkMode: 'class',
theme: {
extend: {
// Semantic colour tokens. Every value is a CSS custom property read
// from the stylesheet, so a palette change happens in one place and no
// utility hard-codes a hex value.
colors: {
background: token('background'),
foreground: token('foreground'),
muted: token('muted'),
'muted-foreground': token('muted-foreground'),
border: token('border'),
accent: token('accent'),
'accent-foreground': token('accent-foreground'),
// The contract names the last two tokens "text-body" and "text-large".
// Their colour keys keep the token's own name, so the utility that
// reads `--color-text-body` is `text-body` and the one that reads
// `--color-text-large` is `text-large`. The type scale uses
// `body-base`, so no class name carries two rules.
body: token('text-body'),
large: token('text-large'),
},
// System font stacks: no webfont download, no font CDN request.
fontFamily: {
sans: ['Inter', 'system-ui', 'sans-serif'],
mono: ['JetBrains Mono', 'monospace'],
sans: [
'system-ui',
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'"Noto Sans"',
'sans-serif',
],
mono: [
'ui-monospace',
'SFMono-Regular',
'Menlo',
'Monaco',
'Consolas',
'"Liberation Mono"',
'"Courier New"',
'monospace',
],
},
// Extended screens for better responsive control
screens: {
@@ -22,13 +105,20 @@ export default {
'8xl': '88rem',
'9xl': '96rem',
},
// Responsive font sizes
// Type scale. The body step is 16px with a 1.6 line height, and three
// heading steps sit above it: title (20px), heading (24px), heading-lg
// (30px). The display steps keep their fluid clamps because their
// smallest size stays well above the heading steps. The body step is
// named `body-base` so it does not collide with the colour token
// `--color-text-body`, whose utility is `text-body`.
fontSize: {
'display': ['clamp(2.5rem, 8vw, 6rem)', { lineHeight: '1.1', letterSpacing: '-0.02em' }],
'display-sm': ['clamp(2rem, 5vw, 3.5rem)', { lineHeight: '1.15', letterSpacing: '-0.02em' }],
'title': ['clamp(1.5rem, 4vw, 2.5rem)', { lineHeight: '1.2', letterSpacing: '-0.01em' }],
'body-lg': ['clamp(1rem, 1.5vw, 1.25rem)', { lineHeight: '1.7' }],
'body': ['clamp(0.875rem, 1.2vw, 1rem)', { lineHeight: '1.6' }],
'heading-lg': ['1.875rem', { lineHeight: '1.3', letterSpacing: '-0.01em' }],
'heading': ['1.5rem', { lineHeight: '1.4', letterSpacing: '-0.01em' }],
'title': ['1.25rem', { lineHeight: '1.5', letterSpacing: '-0.005em' }],
'body-lg': ['1.125rem', { lineHeight: '1.6' }],
'body-base': ['1rem', { lineHeight: '1.6' }],
},
animation: {
'fade-in': 'fadeIn 0.6s ease-out forwards',