(
value:
| Extract<Candidate, { kind: 'functional' }>['value']
| Extract<Candidate, { kind: 'functional' }>['modifier'],
fn: ValueParser.ValueFunctionNode,
designSystem: DesignSystem,
)
| 6436 | } |
| 6437 | |
| 6438 | function resolveValueFunction( |
| 6439 | value: |
| 6440 | | Extract<Candidate, { kind: 'functional' }>['value'] |
| 6441 | | Extract<Candidate, { kind: 'functional' }>['modifier'], |
| 6442 | fn: ValueParser.ValueFunctionNode, |
| 6443 | designSystem: DesignSystem, |
| 6444 | ): { nodes: ValueParser.ValueAstNode[]; ratio?: boolean } | undefined { |
| 6445 | // No value provided, we can try `--default(…)` |
| 6446 | if (value === null) { |
| 6447 | for (let arg of fn.nodes) { |
| 6448 | // Resolve default value, e.g.: `--default(…)` |
| 6449 | if (arg.kind === 'function' && arg.value === '--default') { |
| 6450 | return { nodes: arg.nodes } |
| 6451 | } |
| 6452 | } |
| 6453 | return |
| 6454 | } |
| 6455 | |
| 6456 | for (let arg of fn.nodes) { |
| 6457 | // Resolve literal value, e.g.: `--modifier('closest-side')` |
| 6458 | if ( |
| 6459 | value.kind === 'named' && |
| 6460 | arg.kind === 'word' && |
| 6461 | // Should be wreapped in quotes |
| 6462 | (arg.value[0] === "'" || arg.value[0] === '"') && |
| 6463 | arg.value[arg.value.length - 1] === arg.value[0] && |
| 6464 | // Values should match |
| 6465 | arg.value.slice(1, -1) === value.value |
| 6466 | ) { |
| 6467 | return { nodes: ValueParser.parse(value.value) } |
| 6468 | } |
| 6469 | |
| 6470 | // Resolving theme value, e.g.: `--value(--color)` |
| 6471 | else if ( |
| 6472 | value.kind === 'named' && |
| 6473 | arg.kind === 'word' && |
| 6474 | arg.value[0] === '-' && |
| 6475 | arg.value[1] === '-' |
| 6476 | ) { |
| 6477 | let themeKey = arg.value as `--${string}` |
| 6478 | |
| 6479 | // Resolve the theme value, e.g.: `--value(--color)` |
| 6480 | if (themeKey.endsWith('-*')) { |
| 6481 | // Without `-*` postfix |
| 6482 | themeKey = themeKey.slice(0, -2) as `--${string}` |
| 6483 | |
| 6484 | let resolved = designSystem.theme.resolve(value.value, [themeKey]) |
| 6485 | if (resolved) return { nodes: ValueParser.parse(resolved) } |
| 6486 | } |
| 6487 | |
| 6488 | // Split `--text-*--line-height` into `--text` and `--line-height` |
| 6489 | else { |
| 6490 | let nestedKeys = themeKey.split('-*') as `--${string}`[] |
| 6491 | if (nestedKeys.length <= 1) continue |
| 6492 | |
| 6493 | // Resolve theme values with nested keys, e.g.: `--value(--text-*--line-height)` |
| 6494 | let themeKeys = [nestedKeys.shift()!] |
| 6495 | let resolved = designSystem.theme.resolveWith(value.value, themeKeys, nestedKeys) |
no test coverage detected