(theme: Theme)
| 347 | } |
| 348 | |
| 349 | export 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 | // ^^^^^^ ^ ^^^ ^ ^^^^^^^ |
no test coverage detected