modernizeArbitraryValuesVariant() — tailwindcss Function Reference
Architecture documentation for the modernizeArbitraryValuesVariant() function in canonicalize-candidates.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 8097972e_4628_663f_72e8_08883183690d["modernizeArbitraryValuesVariant()"] 7d350d81_5de1_f9f3_5b2c_19ec8fd3c37e["canonicalize-candidates.ts"] 8097972e_4628_663f_72e8_08883183690d -->|defined in| 7d350d81_5de1_f9f3_5b2c_19ec8fd3c37e bb11a053_5909_cc72_a9a1_0f42f67e2bf6["walkVariants()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| bb11a053_5909_cc72_a9a1_0f42f67e2bf6 7d8880a4_6eed_149c_588c_ca7202364452["isSingleSelector()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| 7d8880a4_6eed_149c_588c_ca7202364452 171d2039_b637_0b5d_5082_71ca42e05d86["replaceObject()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| 171d2039_b637_0b5d_5082_71ca42e05d86 7ba77268_84c7_7083_8f22_251a4a791d25["parseVariant()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| 7ba77268_84c7_7083_8f22_251a4a791d25 02a5a469_a54f_7532_8b33_d407c3c7f34a["printVariant()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| 02a5a469_a54f_7532_8b33_d407c3c7f34a 3dbf7d80_7687_0422_3f4a_486c5e4b6ba3["isAttributeSelector()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| 3dbf7d80_7687_0422_3f4a_486c5e4b6ba3 480ed885_b811_7ff5_c9fc_c17b9da8d505["selector()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| 480ed885_b811_7ff5_c9fc_c17b9da8d505 4e39f1e7_ebcb_7f62_4a59_b645e71d50fd["isPositiveInteger()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| 4e39f1e7_ebcb_7f62_4a59_b645e71d50fd 5bcf4886_1230_a8ff_7302_a26cc5a9a525["get()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| 5bcf4886_1230_a8ff_7302_a26cc5a9a525 ed78da58_8727_ad98_120c_61f35cea357a["walk()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| ed78da58_8727_ad98_120c_61f35cea357a b9517e77_a36f_4751_899c_27d813f3dbb3["parse()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| b9517e77_a36f_4751_899c_27d813f3dbb3 2da63033_d079_7b37_5cfb_3877674a70b9["toCss()"] 8097972e_4628_663f_72e8_08883183690d -->|calls| 2da63033_d079_7b37_5cfb_3877674a70b9 style 8097972e_4628_663f_72e8_08883183690d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/canonicalize-candidates.ts lines 1540–1911
function modernizeArbitraryValuesVariant(
variant: Variant,
options: InternalCanonicalizeOptions,
): Variant | Variant[] {
let result = [variant]
let designSystem = options.designSystem
let signatures = designSystem.storage[VARIANT_SIGNATURE_KEY]
let iterator = walkVariants(variant)
for (let [variant, parent] of iterator) {
// Forward modifier from the root to the compound variant
if (
variant.kind === 'compound' &&
(variant.root === 'has' || variant.root === 'not' || variant.root === 'in')
) {
if (variant.modifier !== null) {
if ('modifier' in variant.variant) {
variant.variant.modifier = variant.modifier
variant.modifier = null
}
}
}
// Expecting an arbitrary variant
if (variant.kind === 'arbitrary') {
// Expecting a non-relative arbitrary variant
if (variant.relative) continue
let ast = SelectorParser.parse(variant.selector.trim())
// Expecting a single selector node
if (!isSingleSelector(ast)) continue
// `[&>*]` can be replaced with `*`
if (
// Only top-level, so `has-[&>*]` is not supported
parent === null &&
// [&_>_*]:flex
// ^ ^ ^
ast.length === 3 &&
ast[0].kind === 'selector' &&
ast[0].value === '&' &&
ast[1].kind === 'combinator' &&
ast[1].value.trim() === '>' &&
ast[2].kind === 'selector' &&
ast[2].value === '*'
) {
replaceObject(variant, designSystem.parseVariant('*'))
continue
}
// `[&_*]` can be replaced with `**`
if (
// Only top-level, so `has-[&_*]` is not supported
parent === null &&
// [&_*]:flex
// ^ ^
ast.length === 3 &&
ast[0].kind === 'selector' &&
ast[0].value === '&' &&
ast[1].kind === 'combinator' &&
ast[1].value.trim() === '' && // space, but trimmed because there could be multiple spaces
ast[2].kind === 'selector' &&
ast[2].value === '*'
) {
replaceObject(variant, designSystem.parseVariant('**'))
continue
}
// `in-*` variant. If the selector ends with ` &`, we can convert it to an
// `in-*` variant.
//
// E.g.: `[[data-visible]_&]` => `in-data-visible`
if (
// Only top-level, so `in-[&_[data-visible]]` is not supported
parent === null &&
// [[data-visible]___&]:flex
// ^^^^^^^^^^^^^^ ^ ^
ast.length === 3 &&
ast[1].kind === 'combinator' &&
ast[1].value.trim() === '' && // Space, but trimmed because there could be multiple spaces
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does modernizeArbitraryValuesVariant() do?
modernizeArbitraryValuesVariant() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/canonicalize-candidates.ts.
Where is modernizeArbitraryValuesVariant() defined?
modernizeArbitraryValuesVariant() is defined in packages/tailwindcss/src/canonicalize-candidates.ts at line 1540.
What does modernizeArbitraryValuesVariant() call?
modernizeArbitraryValuesVariant() calls 12 function(s): get, isAttributeSelector, isPositiveInteger, isSingleSelector, parse, parseVariant, printVariant, replaceObject, and 4 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free