Tailwind and token pipeline
The token pipeline turns the design system's Figma token export into framework-neutral token data, Tailwind theme outputs, CSS variables, shared style behavior, and icon support used by Frappe UI. Its preset makes those outputs available to consuming apps, while migration and drift checks protect code from stale or changed token names. See the parent page, Styling and theming, for the wider visual system.
Pipeline overview
The pipeline has one source and several consumers. Engineers change the design-token export first, run the token sync, and then let the generated token modules drive the public token API, Tailwind plugin, preset, and CSS output.
flowchart LR
A[Figma design-token JSON] --> B[Token build]
B --> C[Generated token modules]
B --> D[Generated token types]
C --> E[Framework-neutral token API]
C --> F[Color and theme plugin]
C --> G[Tailwind preset]
G --> H[Consuming app CSS]
F --> H
I[Lucide SVG pack] --> J[Icon plugin]
J --> H
C --> K[Token-drift audit]
L[Existing app token usage] --> M[Token migration]
C --> M
Generation flow
The generation flow reads the W3C Design Tokens Community Group JSON files exported from Figma. The sync-tokens command runs tailwind/…/build.js, which writes generated color, radius, typography, and effect modules, records the input hashes, and regenerates the public token type contract. This keeps one command as the hand-off between design changes and Tailwind output.
The generator also applies the design system's value rules at this boundary. It converts literal hex colors to OKLCH, preserves token aliases until they can become references between generated layers, and derives typography and effect values in the forms that Tailwind and CSS can use. It builds all outputs before writing them so a bad export does not leave only part of the token set updated.
References: package.json• L25-49 tailwind/…/build.js• L1-29 tailwind/…/build.js• L571-609
Source token layers
The source export separates reusable values from meaning. Primitive files define color ramps and neutral values. Style files define semantic roles such as surfaces, ink, and outlines. Other token files define radius, text styles, and effects. This split lets a semantic role change its underlying primitive without changing the class name used by a component.
The generator intentionally emits only the supported vocabulary. Removed semantic names, unused type sizes, and unused custom effects do not become fallback output. This makes stale usage visible instead of allowing an old name to keep working with an unintended value.
References: tailwind/…/build.js• L51-78 tailwind/…/build.js• L207-267 tailwind/…/build.js• L398-408 tailwind/…/build.js• L491-528
Token provenance
Token provenance records the Figma file and a hash for each input file that produced the committed token modules. It helps reviewers tell whether a value moved because the design export changed or because a build rule changed.
References: tailwind/…/build.js• L159-172 tailwind/…/build.js• L552-569 tailwind/…/provenance.json• L1-10
Theme outputs
The generated data feeds two related layers. The public token surface provides resolved values to consumers that do not load Tailwind. The Tailwind layer adapts those same values into utilities and theme-aware CSS. The raw palette supports direct color utilities, while the semantic layer supports stable names and theme switching through CSS variables.
Framework-neutral token surface
The public token surface is exported from frappe-ui/tailwind/tokens. It exposes resolved colors, semantic colors, radius, shadows, focus rings, type data, spacing, breakpoints, and CSS variables without Tailwind-only sentinels. A Node script, design tool, or other consumer can read this entry without loading the Tailwind plugin or a component tree.
The surface is additive-only until the next major version. Token names therefore act as a public contract. The generated tailwind/tokens.d.ts describes the same keys and keeps value types stable when token values move.
References: tailwind/tokens.js• L1-28 tailwind/tokens.js• L35-89 tailwind/tokens.js• L91-115 tailwind/tokens.js• L159-208 tailwind/tokens.js• L210-335 tailwind/tokens.d.ts• L1-5 tailwind/…/build-types.js• L1-17
Color layers
The color output has four roles:
- Light and dark primitive ramps provide direct color families and shades.
- White and black overlay ramps provide alpha-aware overlay colors.
- Neutral values provide white, black, and transparent values.
- Semantic variables map product roles such as
surface,ink, andoutlineto the current mode.
The Tailwind color map adds an alpha placeholder to solid OKLCH values. This allows classes such as an opacity-modified background to keep working. The stored palette and CSS variables remain plain OKLCH values, while semantic utilities use color-mix so an opacity modifier can apply to the semantic color.
Light semantic variables live under :root. Dark semantic variables live under [data-theme="dark"], which matches the selector used by the preset. Components therefore keep the same semantic class while the active theme changes the resolved value.
References: tailwind/…/colors.js• L4-18 tailwind/…/colors.js• L349-381 tailwind/tokens.js• L42-89 tailwind/tokens.js• L252-279 tailwind/colorPalette.js• L16-23 tailwind/colorPalette.js• L54-95
Shape, type, and effect outputs
The non-color outputs give the rest of the visual system the same source-backed contract:
| Output | System role |
|---|---|
| Radius tokens | Numbered rounded-* values and matching --radius-* variables |
| Typography tokens | Font family, weight, size, line height, tracking, paragraph variants, and text transforms |
| Elevation tokens | Shadow values exposed through shadow-* utilities and CSS variables |
| Focus tokens | Theme-aware focus-ring utilities and the default keyboard focus outline |
The type output keeps weight-specific tracking with the size. The Tailwind plugin exposes combined classes such as text-<size>-<weight> so a weight change does not lose the tracking defined by the design source. The radius output uses numbered values, with only none and full retained as named exceptions.
Effects use CSS variables so the base focus indicator and named focus-ring utilities share the same source. Focus rings use outline values so they do not collide with shadow utilities. Elevation uses the light elevation set in both modes, while focus colors change with the active mode.
References: tailwind/…/radius.js• L4-17 tailwind/…/typography.js• L4-15 tailwind/…/effects.js• L4-42 tailwind/tokens.js• L115-157 tailwind/tokens.js• L173-230 tailwind/plugin.js• L23-137
Shared base and utility behavior
The Tailwind plugin adds shared behavior that sits beside the token-backed theme. It supplies form styling, the global keyboard focus indicator, theme-specific checkbox marks, list spacing hooks, and text-overflow behavior so common component states remain consistent across consuming apps.
The plugin keeps attribute-based dark checkbox selectors in the base layer. This preserves their order after the forms defaults and keeps the preset valid when Tailwind v4 loads it through @config. Its replacement for Tailwind's overflow utilities clips only the horizontal axis and resets the minimum sizes that are needed for flex and grid items. Later overflow and minimum-size utilities can still override those defaults.
References: tailwind/plugin.js• L140-248 tailwind/preset.test.js• L135-185 tailwind/preset.test.js• L242-275
Tailwind integration
The public Tailwind entry point exports a preset and a separate content-glob list. The preset is the reusable theme contract for an app. The content list tells Tailwind where library classes can occur because Tailwind v3 does not merge content globs from a preset.
Preset contract
The preset selects the data-theme dark-mode selector, fills the integer and half-step spacing scale, gates hover styles to devices that support hover, safelists editor typography classes, and combines the form, prose, theme, and icon plugins. The theme plugin adds semantic colors to text, backgrounds, borders, rings, divides, fills, strokes, and placeholders. It also adds the design-system type scale, radius scale, shadows, focus rings, and list styling hooks.
The spacing scale is the shared source for width, height, size, minimum-size, and maximum-size utilities. This keeps sizing classes aligned with the same scale used by list spacing hooks. The preset replaces Tailwind's color, font-size, screen, radius, and shadow sections with the design-system contract. An app normally imports the preset from frappe-ui/tailwind and adds the exported content values to its own Tailwind configuration. The older src/…/tailwind.config.js path remains only as a compatibility re-export; new integrations should use the package entry point.
References: tailwind/index.d.ts• L1-17 tailwind/preset.js• L14-36 tailwind/preset.test.js• L14-132 tailwind/plugin.js• L221-308 src/…/tailwind.config.js• L1-6
Responsive list columns
The list-column contract keeps a list's responsive track layout aligned with the consuming app's Tailwind screen utilities. A List can provide a base template and replacement templates for screen names such as md; the Tailwind plugin resolves those names from the app's final screen configuration.
The same contract covers plain widths, bounded ranges, maximum-width screens, raw media queries, and multiple ranges. The active template changes under the same condition and priority order as a matching visibility utility, so a hidden cell and the track that held it change together. Nested lists also resolve their own templates instead of inheriting an enclosing list's layout.
The plugin exposes list spacing hooks as Tailwind utilities. list-gap-* controls list gap and list-row-px-* controls row-side padding, including responsive variants and arbitrary values. The list-column tests build the preset against overridden and custom screen configurations to verify that layout tiers and screen utilities remain synchronized.
References: tailwind/listColumns.js• L1-32 tailwind/listColumns.js• L62-132 tailwind/plugin.js• L203-222 tailwind/listColumns.test.js• L196-358
Content scanning
Content scanning is part of the output contract because Tailwind emits CSS only for classes it finds in scanned source. The exported paths cover the library source, icon source, re-exported experimental modules, and the shared VitePress theme. They resolve from the installed package path and use forward slashes, so a consuming app does not need to copy or guess the library paths.
The main source glob also covers classes built outside component files, such as markup created by src/…/dialog.ts. The experimental paths follow the public frappe-ui/experimental barrel. A module that is not re-exported is not included because a consumer cannot reach it through that public surface. Story files are excluded from the scan. The consuming app must still provide its own source paths, and computed class names need a safelist or a statically visible alternative.
The path rules work when the package is installed in node_modules, linked in a monorepo, or used from a local workspace. Forward-slash conversion is required because Tailwind's glob reader treats backslashes as escape characters on Windows.
References: tailwind/content.js• L1-18 tailwind/content.js• L20-61 tailwind/content.test.js• L20-73 tailwind.config.js• L24-49
Icon support
The icon path turns the Lucide SVG collection into Tailwind classes without placing every icon in the application bundle. A reusable icon-pack plugin registers the available SVG names, and Tailwind's content scan emits CSS only for icon classes that appear in source.
Class-based icons
The Lucide plugin reads the installed lucide-static pack and registers names with the lucide- prefix. On non-SVG elements, each class masks its SVG as a data URI, uses currentColor for the tint, and defaults to a square that can be sized with normal utilities such as size-4. The plugin normalizes Lucide's stroke width to the value used by this design system.
This path is best for a known icon in a template. The full pack is a registration map, not a promise that all SVGs become CSS. Tailwind still needs the complete class name in scanned source to emit a rule.
The icon rule lives in Tailwind's components layer. Normal utilities such as size and text color run later, so they can set the icon's dimensions and tint without !important.
References: tailwind/lucideIconsPlugin.js• L1-31 tailwind/iconPackPlugin.js• L5-24 tailwind/iconPackPlugin.js• L34-67 tailwind/iconPackPlugin.js• L69-113 tailwind/iconPackPlugin.test.js• L1-43
Component-based icons
The Vite icon path remains available when an actual SVG component is needed or when the icon name is dynamic. It resolves an individual Lucide icon into a Vue component, while the class path keeps static icons in CSS and avoids component imports. The two paths serve the same icon set but have different build and runtime trade-offs.
References: package.json• L71-84 docs/…/icons.md• L22-53 docs/…/icons.md• L94-151
Token migration
The token migration tool updates existing app code from the old semantic and type vocabulary to the current token vocabulary. It works across Tailwind classes and CSS variables, reports removed names for manual review, and merges static size and weight classes when the combined style is needed to preserve tracking.
Migration modes
The tool chooses a safe mode from the codebase state or from an explicit flag:
| Mode | Purpose | Repeat-run rule |
|---|---|---|
| Full | Rename old color and type names, radius aliases, and static weight pairs | Color names can be reused, so a second full run can shift values again |
| Migrated typography | Correct type names and radius aliases in code that already shows v2 color names | Use when color migration already ran |
| Radius-only | Rename removed named radius aliases | Radius renames are safe to repeat |
| Ink shift | Move chromatic ink scales down one level | A marker blocks a second run on the same target |
Removed sizes, removed black text styles, and old ink step -1 are reported instead of rewritten when there is no safe destination. Dynamic class bindings and external symlink targets are not rewritten.
References: tailwind/migrate-tokens-v2.js• L1-68 tailwind/migrate-tokens-v2.js• L282-350 tailwind/migrate-tokens-v2.js• L352-385 tailwind/migrate-tokens-v2.js• L602-655 tailwind/migrate-tokens-v2.test.js• L25-181
Ink-shift protection
The ink-scale migration is a separate run-once operation. It accepts directory targets, creates an exclusive .tokens-v2-ink-shift marker before rewriting files, checks ancestor and nested targets, and rolls back markers if it cannot claim all targets. This protects a partial or concurrent run from silently shifting an already changed codebase again.
References: tailwind/migrate-tokens-v2.js• L387-457 tailwind/migrate-tokens-v2.js• L737-883 tailwind/migrate-tokens-v2.test.js• L256-438
Token-drift validation
The drift audit checks the color contract after token data has reached the generated token modules. It compares the current semantic mappings with a baseline Git ref and checks the current names against the Light and Dark Figma style exports. Run it with node scripts/audit-token-drift.cjs [baselineRef]; the default baseline is v0.1.278.
Drift categories
The audit reports three different risks because each needs a different response:
| Finding | Meaning | Risk |
|---|---|---|
| Build-breaking | A semantic reference points to a missing shade or value. | The generated theme cannot resolve the color. |
| Silent drift | A token still exists but its resolved value changed from the baseline. | The UI can change without a class-name change. |
| Legacy | Code uses a semantic name absent from the current Figma token set. | The name needs a replacement or planned removal. |
For silent drift, the audit separates a changed mapping from a changed primitive. For legacy names, it counts source usage and suggests current Figma tokens with the same resolved color when possible. This turns a palette change into a reviewable report rather than relying on visual checks alone.
References: scripts/audit-token-drift.cjs• L1-20 scripts/audit-token-drift.cjs• L41-76 scripts/audit-token-drift.cjs• L96-146 scripts/audit-token-drift.cjs• L148-173
Change checklist
When these files or sections are changed, remember to consider these:
- When a Figma token group or alias changes, regenerate all four token modules, the provenance file, and the generated type declaration. The plugin reads the public token module and its generated data modules.
- When a semantic color name changes, check every Tailwind color extension and every CSS variable selector. A name can work in light mode and fail only when its dark reference is missing.
- When a type size or weight changes, keep the generated tracking data, combined text-style utilities, and the migration vocabulary aligned.
- When a radius token changes, keep the generated radius module,
--radius-*variables, androunded-*utilities on the same numbered scale. Preserve thenoneandfullboundary names when they are part of the contract. - When the public token shape changes, regenerate tailwind/tokens.d.ts and keep the
frappe-ui/tailwind/tokenspackage export stable. - When the preset spacing scale changes, verify width, height, size, minimum-size, and maximum-size utilities as well as list spacing hooks. These utilities share the preset scale.
- When shared selector rules move between Tailwind layers, preserve both v3 output and Tailwind v4
@configcompatibility. Attribute selectors must keep their required order around the forms rules. - When text-overflow defaults change, preserve the ability of overflow and minimum-size utilities to override them without clipping tight text vertically.
- When a consuming app changes its
screensconfiguration, verify thatListcolumn names use those resolved screen names and that their visibility utilities switch at the intended conditions. - When an experimental module is added to or removed from the public barrel, update the matching exported content path. Keep the VitePress and story exclusion rules aligned with the source surfaces.
- When a supported source directory moves, update both the repository content globs and the exported
frappe-ui/tailwindcontent contract. - When an icon pack or icon name changes, preserve the complete class-name scan path. Dynamic names need component imports or an explicit safelist.
- When changing icon selector or mask rules, keep class-based icons limited to non-SVG elements so component-rendered SVGs keep their own size and stroke behavior. Verify that size and color utilities still override the icon defaults.
- When changing the color source or its baseline, run the drift audit and review mapping drift separately from primitive drift.
- When changing migration mappings or migration markers, check full, migrated-typography, radius-only, and ink-shift behavior. The modes have different repeat-run safety.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
sync-tokens is not run after a source export change | Tailwind continues to use stale generated theme data. | Run yarn sync-tokens and review the generated modules, provenance, and type declaration. |
| A generated token module is hand-edited | The next sync removes the edit and the provenance record no longer explains the change. | Change the source export or build rule, then regenerate the committed outputs. |
| A semantic alias points to a removed shade | A CSS variable or semantic utility resolves to no color. | Run the token-drift audit and fix build-breaking findings. |
| A public token key changes without regenerating types | TypeScript consumers see a stale contract or fail to compile against the runtime module. | Run the token type generator and its byte-for-byte contract check. |
| A shared attribute selector is registered as a component rule | Tailwind v4 can reject the preset when it loads the v3 config through @config. | Keep non-class selectors in the base layer and verify their order after the forms rules. |
A List column key does not match a screen in the consuming app | The column template is ignored while the list silently uses a lower tier. | Use the app's resolved screen names and inspect the development warning. |
| A consumer omits the library content globs | Component or icon utilities are purged from the app CSS. | Spread content from frappe-ui/tailwind into the app config. |
| An icon class is built only from a run-time name | Tailwind does not emit the matching mask rule. | Use complete literal class names or import icon components. |
| An icon mask rule matches an inline SVG | The class-based mask can override the component's size or stroke behavior. | Keep the selector restricted to non-SVG elements and run the icon plugin contract checks. |
| A full token migration runs twice | Reused token names can shift to the wrong color or type value. | Let migration-state detection choose the mode and use --force only after review. |
| Ink-shift runs twice on the same target | Chromatic ink values shift down a second level. | Run it once per codebase and keep the .tokens-v2-ink-shift marker. |
| A migration encounters a removed token with no safe destination | Code keeps a dead class or variable and the intended visual result is unknown. | Use the report for manual replacement instead of forcing a guess. |
| A primitive value changes while its semantic name stays the same | The UI changes without a source-class change. | Compare against the baseline with the drift audit. |
Key files
| File | Why to read it |
|---|---|
.figma-export/ | Source design-token export used to rebuild the committed token record. |
| tailwind/…/build.js | Main source-to-generated-data boundary, value rules, output writing, and provenance creation. |
| tailwind/…/build-types.js | Generation of the public token type declaration. |
tailwind/tokens/ | Generated color, radius, typography, effect, and provenance contract consumed by the token layer. |
| tailwind/tokens.js | Framework-neutral token API and CSS variable assembly. |
| tailwind/tokens.d.ts | Type-level contract for the public token API. |
| tailwind/colorPalette.js | Tailwind-only color shaping, semantic CSS variables, and alpha handling. |
| tailwind/plugin.js | Tailwind theme, shared base and utility behavior, and responsive list-layout surface built from token data. |
| tailwind/listColumns.js | Responsive list-column contract that follows the consuming app's screen configuration. |
| tailwind/listColumns.test.js | Contract checks for screen shapes, ordering, and alignment with Tailwind visibility utilities. |
| tailwind/preset.js | Public Tailwind preset composition, spacing scale, and dark-mode contract. |
| tailwind/preset.test.js | Resolved consumer-contract checks for spacing, sizing, radius, shadows, dark controls, hover behavior, arbitrary values, and text overflow. |
| tailwind/content.js | Content paths for the public library surfaces that consuming apps must add for class scanning. |
| tailwind/content.test.js | Checks that public experimental exports and package paths stay covered by content scanning. |
| tailwind/index.d.ts | Type-level contract for the preset and the separately exported content list. |
| tailwind/iconPackPlugin.js | Reusable SVG-to-class behavior for icon packs. |
| tailwind/lucideIconsPlugin.js | Lucide-specific icon registration and stroke normalization. |
| tailwind/migrate-tokens-v2.js | Existing-code token migration and run-once protection. |
| scripts/audit-token-drift.cjs | Baseline and Figma comparison for broken, changed, and legacy semantic colors. |
| docs/…/tailwind.md | Consumer-facing setup and the reason content paths are exported separately. |