* Gets the RGB values for a color token. * * @param tokenName - The token name to look up. * @param mode - 'light' or 'dark' mode. * @returns [r, g, b] or null if not found.
( tokenName: string, mode: 'light' | 'dark' = 'light' )
| 43 | * @returns [r, g, b] or null if not found. |
| 44 | */ |
| 45 | function getColorRgb( |
| 46 | tokenName: string, |
| 47 | mode: 'light' | 'dark' = 'light' |
| 48 | ): [number, number, number] | null { |
| 49 | const token = (tokens as any)[tokenName]; |
| 50 | if (!token) { |
| 51 | return null; |
| 52 | } |
| 53 | |
| 54 | let value: string | undefined; |
| 55 | if (token.sets?.[mode]?.value) { |
| 56 | value = token.sets[mode].value; |
| 57 | } else if (token.sets?.light?.value) { |
| 58 | // Fallback to light |
| 59 | value = token.sets.light.value; |
| 60 | } else if (token.value) { |
| 61 | value = token.value; |
| 62 | } |
| 63 | |
| 64 | if (!value) { |
| 65 | return null; |
| 66 | } |
| 67 | |
| 68 | // Parse rgb(r, g, b) or rgba(r, g, b, a) |
| 69 | const match = value.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/); |
| 70 | if (match) { |
| 71 | return [parseInt(match[1], 10), parseInt(match[2], 10), parseInt(match[3], 10)]; |
| 72 | } |
| 73 | return null; |
| 74 | } |
| 75 | |
| 76 | // Background color token mappings (semantic and base layer colors) |
| 77 | const backgroundColorTokens: Record<string, string> = { |
no outgoing calls
no test coverage detected