(rules: CssInJs | CssInJs[])
| 556 | export type CssInJs = { [key: string]: string | string[] | CssInJs | CssInJs[] } |
| 557 | |
| 558 | export function objectToAst(rules: CssInJs | CssInJs[]): AstNode[] { |
| 559 | let ast: AstNode[] = [] |
| 560 | |
| 561 | rules = Array.isArray(rules) ? rules : [rules] |
| 562 | |
| 563 | let entries = rules.flatMap((rule) => Object.entries(rule)) |
| 564 | |
| 565 | for (let [name, value] of entries) { |
| 566 | if (value === null || value === undefined) continue |
| 567 | |
| 568 | // @ts-expect-error |
| 569 | // We do not want `false` present in the types but still need to discard these nodes for |
| 570 | // compatibility purposes |
| 571 | if (value === false) continue |
| 572 | |
| 573 | if (typeof value !== 'object') { |
| 574 | if (!name.startsWith('--')) { |
| 575 | if (value === '@slot') { |
| 576 | ast.push(rule(name, [atRule('@slot')])) |
| 577 | continue |
| 578 | } |
| 579 | |
| 580 | // Convert camelCase to kebab-case: |
| 581 | // https://github.com/postcss/postcss-js/blob/b3db658b932b42f6ac14ca0b1d50f50c4569805b/parser.js#L30-L35 |
| 582 | name = name.replace(/([A-Z])/g, '-$1').toLowerCase() |
| 583 | } |
| 584 | |
| 585 | ast.push(decl(name, String(value))) |
| 586 | } else if (Array.isArray(value)) { |
| 587 | for (let item of value) { |
| 588 | if (typeof item === 'string') { |
| 589 | ast.push(decl(name, item)) |
| 590 | } else { |
| 591 | ast.push(rule(name, objectToAst(item))) |
| 592 | } |
| 593 | } |
| 594 | } else { |
| 595 | ast.push(rule(name, objectToAst(value))) |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | return ast |
| 600 | } |
| 601 | |
| 602 | function parseVariantValue(resolved: string | string[], nodes: AstNode[]): AstNode[] { |
| 603 | let resolvedArray = typeof resolved === 'string' ? [resolved] : resolved |
no test coverage detected