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

Function negateConditions

packages/tailwindcss/src/variants.ts:377–457  ·  view source on GitHub ↗
(ruleName: string, conditions: string[])

Source from the content-addressed store, hash-verified

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 // ^^^^^^ ^ ^^^ ^ ^^^^^^^
407 // ast 0 1 2 3 4
408 else if (
409 ast.length >= 5 &&
410 ast[0].kind === 'word' &&
411 ast[2].kind === 'word' &&
412 ast[2].value === 'not' &&
413 ast[4].kind === 'function'
414 ) {
415 // Drop the `not` (ast[2]) and separator (ast[3])
416 ast.splice(2, 2)
417
418 return ValueParser.toCss(ast)
419 }
420
421 // @container {name} {query}
422 // ^^^^^^ ^ ^^^^^^^
423 // ast 0 1 2
424 else if (
425 ast.length >= 3 &&
426 ast[0].kind === 'word' &&
427 ast[0].value !== 'not' &&
428 ast[2].kind === 'function'
429 ) {
430 // Inject a separator and a `not`, after the `name` (ast[0])
431 ast.splice(1, 0, { kind: 'separator', value: ' ' }, { kind: 'word', value: 'not' })
432
433 return ValueParser.toCss(ast)
434 }

Callers 1

negateAtRuleFunction · 0.85

Calls 1

segmentFunction · 0.90

Tested by

no test coverage detected