(name, variant)
| 118 | }, |
| 119 | |
| 120 | addVariant(name, variant) { |
| 121 | if (!IS_VALID_VARIANT_NAME.test(name)) { |
| 122 | throw new Error( |
| 123 | `\`addVariant('${name}')\` defines an invalid variant name. Variants should only contain alphanumeric, dashes, or underscore characters and start with a lowercase letter or number.`, |
| 124 | ) |
| 125 | } |
| 126 | |
| 127 | // Ignore variants emitting v3 `:merge(…)` rules. In v4, the `group-*` and `peer-*` variants |
| 128 | // compound automatically. |
| 129 | if (typeof variant === 'string') { |
| 130 | if (variant.includes(':merge(')) return |
| 131 | } else if (Array.isArray(variant)) { |
| 132 | if (variant.some((v) => v.includes(':merge('))) return |
| 133 | } else if (typeof variant === 'object') { |
| 134 | function keyIncludes(object: Record<string, any>, search: string): boolean { |
| 135 | return Object.entries(object).some( |
| 136 | ([key, value]) => |
| 137 | key.includes(search) || (typeof value === 'object' && keyIncludes(value, search)), |
| 138 | ) |
| 139 | } |
| 140 | if (keyIncludes(variant, ':merge(')) return |
| 141 | } |
| 142 | |
| 143 | // Single selector or multiple parallel selectors |
| 144 | if (typeof variant === 'string' || Array.isArray(variant)) { |
| 145 | designSystem.variants.static( |
| 146 | name, |
| 147 | (r) => { |
| 148 | r.nodes = parseVariantValue(variant, r.nodes) |
| 149 | }, |
| 150 | { |
| 151 | compounds: compoundsForSelectors(typeof variant === 'string' ? [variant] : variant), |
| 152 | }, |
| 153 | ) |
| 154 | } |
| 155 | |
| 156 | // CSS-in-JS object |
| 157 | else if (typeof variant === 'object') { |
| 158 | designSystem.variants.fromAst(name, objectToAst(variant), designSystem) |
| 159 | } |
| 160 | }, |
| 161 | matchVariant(name, fn, options) { |
| 162 | function resolveVariantValue<T extends Parameters<typeof fn>[0]>( |
| 163 | value: T, |
no test coverage detected