buildDesignSystem() — tailwindcss Function Reference
Architecture documentation for the buildDesignSystem() function in design-system.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed["buildDesignSystem()"] 7fd72d4c_e95c_d849_1002_1e1c9d8aca1a["design-system.ts"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|defined in| 7fd72d4c_e95c_d849_1002_1e1c9d8aca1a fb628c58_7fe8_bbd2_d098_fbfc88e55630["run()"] fb628c58_7fe8_bbd2_d098_fbfc88e55630 -->|calls| 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed 3970218d_3d6c_e455_87cc_45b4a094f0e9["parseCss()"] 3970218d_3d6c_e455_87cc_45b4a094f0e9 -->|calls| 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed 355fe08b_f60b_3860_26b3_b4da300a811c["loadDesignSystem()"] 355fe08b_f60b_3860_26b3_b4da300a811c -->|calls| 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed 5325bb92_82db_cf31_b2b3_1541819bb8e3["simpleDesign()"] 5325bb92_82db_cf31_b2b3_1541819bb8e3 -->|calls| 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed 0ce247c0_4edf_7255_2fe4_6eb777680bdf["createUtilities()"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|calls| 0ce247c0_4edf_7255_2fe4_6eb777680bdf c1a769fc_95ca_ceea_62f9_aedeeedf7c66["createVariants()"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|calls| c1a769fc_95ca_ceea_62f9_aedeeedf7c66 7ba77268_84c7_7083_8f22_251a4a791d25["parseVariant()"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|calls| 7ba77268_84c7_7083_8f22_251a4a791d25 d4b90da0_01b5_b21d_ff05_b37798744576["parseCandidate()"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|calls| d4b90da0_01b5_b21d_ff05_b37798744576 e57db502_ed4e_4f14_1b2a_b25af3c0477d["compileAstNodes()"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|calls| e57db502_ed4e_4f14_1b2a_b25af3c0477d a14450c0_b6d2_d918_cff3_c3396641b12d["theme()"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|calls| a14450c0_b6d2_d918_cff3_c3396641b12d cbcebe85_5027_3db6_180a_0ceaa8acbbfb["substituteFunctions()"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|calls| cbcebe85_5027_3db6_180a_0ceaa8acbbfb 0ec6110b_085e_e69b_cc4a_37d966dc5ace["substituteAtVariant()"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|calls| 0ec6110b_085e_e69b_cc4a_37d966dc5ace c74af9b2_8c4e_9508_1d10_dd910b7bf65e["extractUsedVariables()"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|calls| c74af9b2_8c4e_9508_1d10_dd910b7bf65e style 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/design-system.ts lines 70–255
export function buildDesignSystem(
theme: Theme,
utilitiesSrc?: SourceLocation | undefined,
): DesignSystem {
let utilities = createUtilities(theme)
let variants = createVariants(theme)
let parsedVariants = new DefaultMap((variant) => parseVariant(variant, designSystem))
let parsedCandidates = new DefaultMap((candidate) =>
Array.from(parseCandidate(candidate, designSystem)),
)
let compiledAstNodes = new DefaultMap<number>((flags) => {
return new DefaultMap<Candidate>((candidate) => {
let ast = compileAstNodes(candidate, designSystem, flags)
try {
// Arbitrary values (`text-[theme(--color-red-500)]`) and arbitrary
// properties (`[--my-var:theme(--color-red-500)]`) can contain function
// calls so we need evaluate any functions we find there that weren't in
// the source CSS.
substituteFunctions(
ast.map(({ node }) => node),
designSystem,
)
// JS plugins might contain an `@variant` inside a generated utility
substituteAtVariant(
ast.map(({ node }) => node),
designSystem,
)
} catch (err) {
// If substitution fails then the candidate likely contains a call to
// `theme()` that is invalid which may be because of incorrect usage,
// invalid arguments, or a theme key that does not exist.
return []
}
return ast
})
})
let trackUsedVariables = new DefaultMap((raw) => {
for (let variable of extractUsedVariables(raw)) {
theme.markUsedVariable(variable)
}
})
function candidatesToAst(classes: string[]): AstNode[][] {
let result: AstNode[][] = []
for (let className of classes) {
let wasValid = true
let { astNodes } = compileCandidates([className], designSystem, {
onInvalidCandidate() {
wasValid = false
},
})
if (utilitiesSrc) {
walk(astNodes, (node) => {
// We do this conditionally to preserve source locations from both
// `@utility` and `@custom-variant`. Even though generated nodes are
// cached this should be fine because `utilitiesNode.src` should not
// change without a full rebuild which destroys the cache.
node.src ??= utilitiesSrc
return WalkAction.Continue
})
}
// Disable all polyfills to not unnecessarily pollute IntelliSense output
astNodes = optimizeAst(astNodes, designSystem, Polyfills.None)
result.push(wasValid ? astNodes : [])
}
return result
}
function candidatesToCss(classes: string[]): (string | null)[] {
Domain
Subdomains
Defined In
Calls
- compare()
- compileAstNodes()
- compileCandidates()
- createUtilities()
- createVariants()
- extractUsedVariables()
- get()
- getClassList()
- getClassOrder()
- getVariants()
- markUsedVariable()
- optimizeAst()
- parseCandidate()
- parseVariant()
- printCandidate()
- printVariant()
- resolve()
- set()
- substituteAtVariant()
- substituteFunctions()
- theme()
- toCss()
- walk()
- withAlpha()
Source
Frequently Asked Questions
What does buildDesignSystem() do?
buildDesignSystem() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/design-system.ts.
Where is buildDesignSystem() defined?
buildDesignSystem() is defined in packages/tailwindcss/src/design-system.ts at line 70.
What does buildDesignSystem() call?
buildDesignSystem() calls 24 function(s): compare, compileAstNodes, compileCandidates, createUtilities, createVariants, extractUsedVariables, get, getClassList, and 16 more.
What calls buildDesignSystem()?
buildDesignSystem() is called by 4 function(s): loadDesignSystem, parseCss, run, simpleDesign.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free