MCPcopy
hub / github.com/tailwindlabs/tailwindcss / createVariants

Function createVariants

packages/tailwindcss/src/variants.ts:349–1212  ·  view source on GitHub ↗
(theme: Theme)

Source from the content-addressed store, hash-verified

347}
348
349export function createVariants(theme: Theme): Variants {
350 // In the future we may want to support returning a rule here if some complex
351 // variant requires it. For now pure mutation is sufficient and will be the
352 // most performant.
353 let variants = new Variants()
354
355 /**
356 * Register a static variant like `hover`.
357 */
358 function staticVariant(
359 name: string,
360 selectors: string[],
361 { compounds }: { compounds?: Compounds } = {},
362 ) {
363 compounds = compounds ?? compoundsForSelectors(selectors)
364
365 variants.static(
366 name,
367 (r) => {
368 r.nodes = selectors.map((selector) => rule(selector, r.nodes))
369 },
370 { compounds },
371 )
372 }
373
374 staticVariant('*', [':is(& > *)'], { compounds: Compounds.Never })
375 staticVariant('**', [':is(& *)'], { compounds: Compounds.Never })
376
377 function negateConditions(ruleName: string, conditions: string[]) {
378 return conditions.map((condition) => {
379 switch (ruleName) {
380 case '@container': {
381 let ast = ValueParser.parse(condition.trim())
382
383 // @container {query}
384 // ^^^^^^^
385 // ast 0
386 if (ast.length >= 1 && ast[0].kind === 'function') {
387 return `not ${condition}`
388 }
389
390 // @container not {query}
391 // ^^^ ^ ^^^^^^^
392 // ast 0 1 2
393 else if (
394 ast.length >= 3 &&
395 ast[0].kind === 'word' &&
396 ast[0].value === 'not' &&
397 ast[2].kind === 'function'
398 ) {
399 // Drop the leading `not` (ast[0]) and separator (ast[1])
400 ast.splice(0, 2)
401
402 return ValueParser.toCss(ast)
403 }
404
405 // @container {name} not {query}
406 // ^^^^^^ ^ ^^^ ^ ^^^^^^^

Callers 1

buildDesignSystemFunction · 0.90

Calls 15

compoundMethod · 0.95
suggestMethod · 0.95
keysMethod · 0.95
compoundsWithMethod · 0.95
staticMethod · 0.95
functionalMethod · 0.95
groupMethod · 0.95
getMethod · 0.95
walkFunction · 0.90
styleRuleFunction · 0.90
segmentFunction · 0.90
declFunction · 0.90

Tested by

no test coverage detected