createVariantSignatureCache() — tailwindcss Function Reference
Architecture documentation for the createVariantSignatureCache() function in canonicalize-candidates.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 975d8b8a_4b03_4408_cd48_2cea8a20646c["createVariantSignatureCache()"] f6c14bbb_2e42_58cc_18f1_c89a243da9c0["canonicalize-candidates.ts"] 975d8b8a_4b03_4408_cd48_2cea8a20646c -->|defined in| f6c14bbb_2e42_58cc_18f1_c89a243da9c0 26169039_1fd2_e320_1f63_11ec10a6fc52["prepareDesignSystemStorage()"] 26169039_1fd2_e320_1f63_11ec10a6fc52 -->|calls| 975d8b8a_4b03_4408_cd48_2cea8a20646c 2a22052d_f868_4f88_0a03_2033be58172d["styleRule()"] 975d8b8a_4b03_4408_cd48_2cea8a20646c -->|calls| 2a22052d_f868_4f88_0a03_2033be58172d 2f6881be_62d9_4b96_7331_a962ced095f7["atRule()"] 975d8b8a_4b03_4408_cd48_2cea8a20646c -->|calls| 2f6881be_62d9_4b96_7331_a962ced095f7 7ad9d996_c0ff_47f5_d131_ab2ead06506e["substituteAtApply()"] 975d8b8a_4b03_4408_cd48_2cea8a20646c -->|calls| 7ad9d996_c0ff_47f5_d131_ab2ead06506e 4982d9ce_98d4_85d9_44af_7cc47b93c482["walk()"] 975d8b8a_4b03_4408_cd48_2cea8a20646c -->|calls| 4982d9ce_98d4_85d9_44af_7cc47b93c482 117bca28_0677_ab3f_6eec_6019671b392d["parse()"] 975d8b8a_4b03_4408_cd48_2cea8a20646c -->|calls| 117bca28_0677_ab3f_6eec_6019671b392d 9b49f3c6_0c8d_5c62_965c_30a1db6499f8["toCss()"] 975d8b8a_4b03_4408_cd48_2cea8a20646c -->|calls| 9b49f3c6_0c8d_5c62_965c_30a1db6499f8 style 975d8b8a_4b03_4408_cd48_2cea8a20646c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/canonicalize-candidates.ts lines 2395–2485
function createVariantSignatureCache(
designSystem: DesignSystem,
): DesignSystem['storage'][typeof VARIANT_SIGNATURE_KEY] {
return new DefaultMap<string, string | Symbol>((variant) => {
try {
// Ensure the prefix is added to the utility if it is not already present.
variant =
designSystem.theme.prefix && !variant.startsWith(designSystem.theme.prefix)
? `${designSystem.theme.prefix}:${variant}`
: variant
// Use `@apply` to normalize the selector to `.x`
let ast: AstNode[] = [styleRule('.x', [atRule('@apply', `${variant}:flex`)])]
substituteAtApply(ast, designSystem)
// Canonicalize selectors to their minimal form
walk(ast, (node) => {
// At-rules
if (node.kind === 'at-rule' && node.params.includes(' ')) {
node.params = node.params.replaceAll(' ', '')
}
// Style rules
else if (node.kind === 'rule') {
let selectorAst = SelectorParser.parse(node.selector)
let changed = false
walk(selectorAst, (node) => {
if (node.kind === 'separator' && node.value !== ' ') {
node.value = node.value.trim()
changed = true
}
// Remove unnecessary `:is(…)` selectors
else if (node.kind === 'function' && node.value === ':is') {
// A single selector inside of `:is(…)` can be replaced with the
// selector itself.
//
// E.g.: `:is(.foo)` → `.foo`
if (node.nodes.length === 1) {
changed = true
return WalkAction.Replace(node.nodes)
}
// A selector with the universal selector `*` followed by a pseudo
// class, can be replaced with the pseudo class itself.
else if (
node.nodes.length === 2 &&
node.nodes[0].kind === 'selector' &&
node.nodes[0].value === '*' &&
node.nodes[1].kind === 'selector' &&
node.nodes[1].value[0] === ':'
) {
changed = true
return WalkAction.Replace(node.nodes[1])
}
}
// Ensure `*` exists before pseudo selectors inside of `:not(…)`,
// `:where(…)`, …
//
// E.g.:
//
// `:not(:first-child)` → `:not(*:first-child)`
//
else if (
node.kind === 'function' &&
node.value[0] === ':' &&
node.nodes[0]?.kind === 'selector' &&
node.nodes[0]?.value[0] === ':'
) {
changed = true
node.nodes.unshift({ kind: 'selector', value: '*' })
}
})
if (changed) {
node.selector = SelectorParser.toCss(selectorAst)
}
}
})
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does createVariantSignatureCache() do?
createVariantSignatureCache() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/canonicalize-candidates.ts.
Where is createVariantSignatureCache() defined?
createVariantSignatureCache() is defined in packages/tailwindcss/src/canonicalize-candidates.ts at line 2395.
What does createVariantSignatureCache() call?
createVariantSignatureCache() calls 6 function(s): atRule, parse, styleRule, substituteAtApply, toCss, walk.
What calls createVariantSignatureCache()?
createVariantSignatureCache() is called by 1 function(s): prepareDesignSystemStorage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free