buildDesignSystem() — tailwindcss Function Reference
Architecture documentation for the buildDesignSystem() function in design-system.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD e557c8a4_bb27_ee44_c462_9e238157ad04["buildDesignSystem()"] bdedd2f6_da4b_69dc_e990_0814b59fbe6e["design-system.ts"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|defined in| bdedd2f6_da4b_69dc_e990_0814b59fbe6e ea1f4863_da9d_0567_6eca_bc8e5ff73fea["run()"] ea1f4863_da9d_0567_6eca_bc8e5ff73fea -->|calls| e557c8a4_bb27_ee44_c462_9e238157ad04 f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f["parseCss()"] f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| e557c8a4_bb27_ee44_c462_9e238157ad04 56e002cc_409f_bdfa_c573_fa69116d8c75["loadDesignSystem()"] 56e002cc_409f_bdfa_c573_fa69116d8c75 -->|calls| e557c8a4_bb27_ee44_c462_9e238157ad04 e61c3072_d280_5d4e_55b5_4d25572f3d6d["simpleDesign()"] e61c3072_d280_5d4e_55b5_4d25572f3d6d -->|calls| e557c8a4_bb27_ee44_c462_9e238157ad04 0861496f_718c_184b_c62f_fca95bfa113c["createUtilities()"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|calls| 0861496f_718c_184b_c62f_fca95bfa113c 876035d0_94a8_cf2f_314a_d520aaae6e4b["createVariants()"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|calls| 876035d0_94a8_cf2f_314a_d520aaae6e4b 5719096b_0f51_ab16_7fbd_4455f835804c["parseVariant()"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|calls| 5719096b_0f51_ab16_7fbd_4455f835804c 7d328a86_10c6_b5c1_6390_36f4fffe9c14["parseCandidate()"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|calls| 7d328a86_10c6_b5c1_6390_36f4fffe9c14 8b088e47_7f37_81e9_fe8a_5da6d3f5e245["compileAstNodes()"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|calls| 8b088e47_7f37_81e9_fe8a_5da6d3f5e245 afa623bf_4f68_b25f_8bd7_1d00a4fcfe48["theme()"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|calls| afa623bf_4f68_b25f_8bd7_1d00a4fcfe48 6bed2e43_7855_2758_8396_9f9e9a11be52["substituteFunctions()"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|calls| 6bed2e43_7855_2758_8396_9f9e9a11be52 3a0ec0d5_1240_2a2d_bde3_145d361401fa["substituteAtVariant()"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|calls| 3a0ec0d5_1240_2a2d_bde3_145d361401fa 44fc256b_22c1_3ae2_924e_7d583f63c030["extractUsedVariables()"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|calls| 44fc256b_22c1_3ae2_924e_7d583f63c030 style e557c8a4_bb27_ee44_c462_9e238157ad04 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