Skip to main content

Overview

The DesignSystem object is the core interface for working with Tailwind’s utilities, variants, and theme. It provides methods for parsing candidates, generating CSS, and managing the design system configuration.

Creating a Design System

Design systems are typically created internally during compilation, but you can create one manually:

Properties

theme

Theme
The theme instance containing all CSS custom properties and their values.

utilities

Utilities
The utilities registry for registering and managing utility classes.

variants

Variants
The variants registry for managing variant modifiers like hover:, md:, etc.

invalidCandidates

Set<string>
Set of candidate strings that have been determined to be invalid. Used for caching validation results.

important

boolean
Whether utility declarations should be marked as !important. Defaults to false.

storage

Record<symbol, unknown>
General purpose storage for plugins and extensions. Each key must be a unique symbol to avoid collisions.

Parsing Methods

parseCandidate()

Parse a candidate string into structured candidate objects.
string
required
The candidate string to parse (e.g., 'hover:bg-blue-500', 'md:flex').
Returns: Array of parsed candidate objects. A single string can produce multiple candidates (e.g., 'text-red-500/50' creates candidates for both color and opacity).

parseVariant()

Parse a variant string into a variant object.
string
required
The variant string to parse (e.g., 'hover', 'md', 'dark').
Returns: Parsed variant object or null if the variant is invalid.

compileAstNodes()

Compile a parsed candidate into AST nodes.
Candidate
required
The parsed candidate object to compile.
CompileAstFlags
Compilation flags:
  • CompileAstFlags.None - No special flags
  • CompileAstFlags.RespectImportant - Apply !important if designSystem.important is true (default)
Returns: Array of AST nodes with their property sort order.

String Conversion Methods

printCandidate()

Convert a parsed candidate back to its string representation.

printVariant()

Convert a parsed variant back to its string representation.

Ordering Methods

getClassOrder()

Get the sort order for an array of class names.
string[]
required
Array of class names to get sort order for.
Returns: Array of tuples containing the class name and its sort order (or null if invalid).

getVariantOrder()

Get a map of variants to their sort order.
Returns: Map where keys are variant objects and values are their numeric sort order.

IntelliSense Methods

getClassList()

Get a list of all available utility classes for IntelliSense.
Returns: Array of class entries containing metadata about each utility.

getVariants()

Get a list of all available variants for IntelliSense.
Returns: Array of variant entries.

candidatesToCss()

Convert an array of candidates to their CSS output.
string[]
required
Array of class names to convert to CSS.
Returns: Array of CSS strings (or null for invalid classes) corresponding to each input class.

candidatesToAst()

Convert an array of candidates to AST nodes.
string[]
required
Array of class names to convert to AST.
Returns: Array of AST node arrays (empty array for invalid classes).

Theme Methods

resolveThemeValue()

Resolve a theme path to its CSS value.
string
required
Theme path to resolve (e.g., '--color-blue-500', '--spacing-4').Can include an opacity modifier using / syntax: '--color-blue-500 / 50%'
boolean
If true, forces the value to be inlined rather than using a CSS variable reference. Defaults to true.
Returns: The resolved CSS value or undefined if the path doesn’t exist.

trackUsedVariables()

Track CSS variables used in arbitrary values to ensure they’re included in the output.
string
required
Raw string that may contain CSS variable references.

canonicalizeCandidates()

Canonicalize an array of candidates by parsing and re-printing them.
string[]
required
Array of candidate strings to canonicalize.
CanonicalizeOptions
Options for canonicalization.
Returns: Array of canonicalized candidate strings.

Example: Building a Custom Tool