Migrating to v2
Replace v1 color tokens with the v2 names, and adopt the new nested-radius utilities.
v2 renames the color tokens. Every color value is the same, so a correct migration changes no pixels. Spacing and radius names are unchanged.
The naming rule:
on-Xis readable onX(bg-accent text-on-accent).foreground-*is readable on every neutral background and surface.X-containeris a tintedXbackground. Puton-X-containercontent on it.
1. Run the codemod
Save the script below as nerdfish-v2-tokens.mjs and run it from your project root. It has no dependencies, needs Node 18+, and is safe to run twice.
node nerdfish-v2-tokens.mjs --dry src # preview
node nerdfish-v2-tokens.mjs src app # rewrite files in one or more folders
It rewrites class names, --color-* variables and the v1 theme variables in .ts(x), .js(x), .mdx, .vue, .svelte, .astro, .html, .css and .scss files. It skips node_modules, build output and hidden folders. Anything it can’t decide on its own is listed under Needs a manual look; use the tables below for those.
nerdfish-v2-tokens.mjs
#!/usr/bin/env node
// Nerdfish v2 token codemod.
// Usage: node nerdfish-v2-tokens.mjs [--dry] [dir ...] (default dir: src)
import { readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
import path from 'node:path'
const args = process.argv.slice(2)
const isDry = args.includes('--dry')
const roots = args.filter((a) => a !== '--dry')
if (roots.length === 0) roots.push('src')
const CODE = /\.(?:[cm]?[jt]sx?|mdx|vue|svelte|astro|html)$/
const STYLE = /\.(?:css|scss)$/
// Hidden entries (.git, .next, .env, …) are skipped too.
const SKIP = new Set(['node_modules', 'dist', 'build', 'out', 'coverage'])
const S = '(destructive|success|info|warning)'
const END = '(?![a-z0-9-])'
const UTIL =
'\\b(bg|text|border|ring-offset|inset-ring|ring|fill|stroke|outline|divide|from|to|via|shadow|decoration|caret|placeholder|color)'
const rules = [
// `bg-destructive-background-muted` → `bg-destructive-container/50`.
// A var() form can't take an opacity suffix, so it is reported below.
[`(?<!--)(?<!--color-)(?<=-)${S}-background-muted${END}`, '$1-container/50'],
[`(?<=-)${S}-background${END}`, '$1-container'],
[`(?<=-)${S}-muted${END}`, 'on-$1-container'],
[`(?<=-)${S}-contrast${END}`, 'on-$1'],
[`(?<=-)accent-contrast${END}`, 'on-accent'],
[`(?<=-)background-inverted${END}`, 'inverse'],
[`(?<=-)foreground-inverted${END}`, 'on-inverse'],
[`(?<=-)background-surface-secondary${END}`, 'surface-strong'],
[`(?<=-)background-surface-muted${END}`, 'surface-muted'],
[`(?<=-)background-surface${END}`, 'surface'],
[`(?<=-)background-overlay-secondary${END}`, 'border-strong'],
[`(?<=-)background-overlay-muted${END}`, 'ring'],
[`(?<=-)background-overlay${END}`, 'border'],
[`(?<=-)foreground-(?:body|headline|link)${END}`, 'foreground'],
[`(?<=-)foreground-(?:subtitle|label)${END}`, 'foreground-muted'],
[`${UTIL}-popover-contrast${END}`, '$1-foreground'],
[`${UTIL}-popover${END}`, '$1-surface'],
[`${UTIL}-sidebar-(?:muted-contrast|foreground)${END}`, '$1-foreground'],
[`${UTIL}-sidebar-secondary-contrast${END}`, '$1-on-inverse'],
[`${UTIL}-sidebar-secondary${END}`, '$1-inverse'],
[`${UTIL}-sidebar-muted${END}`, '$1-background-muted'],
[`${UTIL}-sidebar-border${END}`, '$1-border'],
[`${UTIL}-sidebar-ring${END}`, '$1-ring'],
[`${UTIL}-sidebar${END}`, '$1-background'],
// Theme variables with a unique name.
...[
['mantle', 'background-muted'],
['crust', 'background-secondary'],
['surface-0', 'surface'],
['surface-1', 'surface-muted'],
['surface-2', 'surface-strong'],
['overlay-0', 'border'],
['overlay-2', 'border-strong'],
['subtext-0', 'foreground-muted'],
['brand-contrast', 'on-accent'],
['brand', 'accent'],
].map(([from, to]) => [`(?<![\\w-])--${from}(?![\\w-])`, `--${to}`]),
].map(([pattern, replacement]) => [new RegExp(pattern, 'g'), replacement])
// `--base` and `--text` are too generic to rename outside stylesheets.
const styleRules = [
['base', 'background'],
['text', 'foreground'],
].map(([from, to]) => [
new RegExp(`(?<![\\w-])--${from}(?![\\w-])`, 'g'),
`--${to}`,
])
const manual = [
[
/--(?:color-)?(?:destructive|success|info|warning)-background-muted\b/,
'removed: use the `-container` color at 50% opacity',
],
[
/--overlay-1\b/,
'split: use --ring for rings, --foreground-subtle for subtle text',
],
[/--subtext-1\b/, 'removed: use --foreground-subtle or --foreground-muted'],
[/--accent-muted\b/, 'removed: use bg-accent/10 or --accent with opacity'],
[
/rounded-\[calc\(/,
'nested radius: consider nest-radius-* / nest-inset-* + rounded-inner',
],
[
/\b(?:text|bg|border|fill|stroke)-(?:accent|destructive|success|info|warning)-foreground\b/,
'not a Nerdfish token (never was): use on-accent / on-destructive / …',
],
]
function* walk(target) {
let stat
try {
stat = statSync(target)
} catch {
console.warn(`skipped unreadable ${target}`)
return
}
if (stat.isFile()) {
yield target
return
}
for (const entry of readdirSync(target)) {
if (SKIP.has(entry) || entry.startsWith('.')) continue
yield* walk(path.join(target, entry))
}
}
let changedFiles = 0
const notes = []
for (const root of roots) {
for (const file of walk(root)) {
const isStyle = STYLE.test(file)
if (!isStyle && !CODE.test(file)) continue
const before = readFileSync(file, 'utf8')
let after = before
for (const [pattern, replacement] of isStyle
? [...rules, ...styleRules]
: rules) {
after = after.replace(pattern, replacement)
}
after.split('\n').forEach((line, index) => {
for (const [pattern, note] of manual) {
if (pattern.test(line)) notes.push(`${file}:${index + 1} ${note}`)
}
})
if (after === before) continue
changedFiles++
if (!isDry) writeFileSync(file, after)
console.log(`${isDry ? 'would update' : 'updated'} ${file}`)
}
}
console.log(`\n${changedFiles} file(s) ${isDry ? 'would change' : 'changed'}.`)
if (notes.length > 0) {
console.log(`\nNeeds a manual look (${notes.length}):`)
for (const note of notes) console.log(` ${note}`)
}To check for leftovers afterwards:
rg -n -e '-(contrast|background-inverted|foreground-inverted|background-surface|popover-contrast)\b' \
-e '\b(bg|text|border|ring)-sidebar' \
-e '--(base|mantle|crust|text|brand|subtext-[01]|overlay-[012]|surface-[012])\b' src
2. Classes
* is any color utility: bg-, text-, border-, ring-, fill-, stroke-, outline-, divide-, from-/via-/to-, shadow-, decoration-, caret-, placeholder-. {status} is destructive, success, info or warning.
Pairs and containers
| v1 | v2 |
|---|---|
*-accent-contrast |
*-on-accent |
*-{status}-contrast |
*-on-{status} |
*-{status}-background |
*-{status}-container |
*-{status}-background-muted |
*-{status}-container/50 |
*-{status}-muted |
*-on-{status}-container |
// v1
<div className="bg-destructive-background text-destructive-muted" />
<button className="bg-destructive text-destructive-contrast" />
// v2
<div className="bg-destructive-container text-on-destructive-container" />
<button className="bg-destructive text-on-destructive" />
Neutrals
| v1 | v2 |
|---|---|
*-background-inverted |
*-inverse |
*-foreground-inverted |
*-on-inverse |
*-background-surface |
*-surface |
*-background-surface-muted |
*-surface-muted |
*-background-surface-secondary |
*-surface-strong |
*-background-overlay |
*-border |
*-background-overlay-muted |
*-ring |
*-background-overlay-secondary |
*-border-strong |
*-foreground-body / -headline / -link |
*-foreground |
*-foreground-subtitle / -label |
*-foreground-muted |
Unchanged: background, background-muted, background-secondary, foreground, foreground-muted, foreground-subtle, border, ring, accent, destructive, success, info, warning, chart-1 … chart-5.
Popover and sidebar
These component-specific colors are gone; they always had the same values as the general tokens.
| v1 | v2 |
|---|---|
*-popover |
*-surface |
*-popover-contrast |
*-foreground |
*-sidebar |
*-background |
*-sidebar-foreground |
*-foreground |
*-sidebar-muted |
*-background-muted |
*-sidebar-muted-contrast |
*-foreground |
*-sidebar-secondary |
*-inverse |
*-sidebar-secondary-contrast |
*-on-inverse |
*-sidebar-border |
*-border |
*-sidebar-ring |
*-ring |
Spacing and radius classes named popover (p-popover, rounded-popover) still exist.
New
| Class | Use |
|---|---|
*-border-strong |
Borders that need more contrast than border |
*-gray-500 |
Was missing; fell back to Tailwind’s gray |
3. Theme variables
Only needed if you override the theme in your own CSS (:root { … } / .dark { … }). The codemod handles all of these except --overlay-1 and --subtext-1.
| v1 | v2 |
|---|---|
--base |
--background |
--mantle |
--background-muted |
--crust |
--background-secondary |
--surface-0 / -1 / -2 |
--surface / --surface-muted / --surface-strong |
--text |
--foreground |
--subtext-0 |
--foreground-muted |
--subtext-1 |
removed (only the code-block comment color used it) |
--overlay-0 |
--border |
--overlay-1 |
split: --ring and --foreground-subtle |
--overlay-2 |
--border-strong |
--brand / --brand-contrast |
--accent / --on-accent |
--accent-contrast, --accent-muted |
removed (unused) |
--{status}-contrast |
--on-{status} |
--{status}-background |
--{status}-container |
--{status}-background-muted |
removed: use {status}-container/50 |
--{status}-muted |
--on-{status}-container |
.dark and :root[data-theme='dark'] now share one rule, so override both at once:
.dark,
:root[data-theme='dark'] {
--accent: oklch(0.7 0.1 270);
--on-accent: oklch(0.2 0 0);
}
4. Nested corners
Replace hand-written rounded-[calc(…radius… - …padding…)] with rounded-inner. The parent declares its radius and padding; the child gets the radius minus the padding (never below 0).
// v1
<div className="rounded-container p-best-friends">
<img className="rounded-[calc(var(--radius-container)-theme(padding.best-friends))]" />
</div>
// v2
<div className="rounded-container p-best-friends nest-radius-container nest-inset-best-friends">
<img className="rounded-inner" />
</div>
Without a declaration, rounded-inner assumes a popover (rounded-popover + p-popover-compact), so items inside a menu or popover need only rounded-inner.
5. Behavior changes
cnmerges design-system classes (@nerdfish/utils).cn('p-bff', 'p-friends')now returnsp-friends. Before, both stayed and CSS order picked the winner, soclassNameoverrides of spacing or radius could silently lose. Check overrides that used to “not work”: they now apply.- Components where a dead override now applies: Attachment
size="xs"radius is 12px (was 16px). Tabsvariant="line"list gaps are 36 / 32 / 16 / 16px for lg / md / sm / xs (were 24 / 16 / 8 / 4px). - Sidebar
outlinemenu buttons now show their 1px ring. - Shadows and states: components use the new elevation tokens (
shadow-hairline,shadow-raised,shadow-floating,shadow-overlay); menus, popovers and dialogs get a softer, wider shadow. Pressed toggles usebg-state-selected. Use these tokens, andbg-state-hover/bg-state-selected/bg-state-active, for your own layers and interactive rows. See the Elevation page. - Menus: highlighted items in dropdown, context menu, select, combobox and command are a soft
bg-state-selectedfill instead of an inverted dark bar. If you styled menu items to match the old look, usebg-state-selected text-foreground. - Controls: checked checkboxes and radios are a solid accent fill. Dialogs and alert dialogs have larger corners (
rounded-page) and more padding (p-casual); check custom dialog content that relied on the old 16px padding. - Inset sidebar:
variant="inset"puts the sidebar and its wrapper on the newbg-canvas(off-white in light mode, darker in dark mode), so the main area reads as a sheet. Usebg-canvasfor your own app shells. --spacingis0.25rem(was4px). Same size at the default font size; spacing now scales when users change their browser font size.