(text: string, styles: TextStyles)
| 174 | * Theme resolution happens at component layer, not here. |
| 175 | */ |
| 176 | export function applyTextStyles(text: string, styles: TextStyles): string { |
| 177 | let result = text |
| 178 | |
| 179 | // Apply styles in reverse order of desired nesting. |
| 180 | // chalk wraps text so later calls become outer wrappers. |
| 181 | // Desired order (outermost to innermost): |
| 182 | // background > foreground > text modifiers |
| 183 | // So we apply: text modifiers first, then foreground, then background last. |
| 184 | |
| 185 | if (styles.inverse) { |
| 186 | result = chalk.inverse(result) |
| 187 | } |
| 188 | |
| 189 | if (styles.strikethrough) { |
| 190 | result = chalk.strikethrough(result) |
| 191 | } |
| 192 | |
| 193 | if (styles.underline) { |
| 194 | result = chalk.underline(result) |
| 195 | } |
| 196 | |
| 197 | if (styles.italic) { |
| 198 | result = chalk.italic(result) |
| 199 | } |
| 200 | |
| 201 | if (styles.bold) { |
| 202 | result = chalk.bold(result) |
| 203 | } |
| 204 | |
| 205 | if (styles.dim) { |
| 206 | result = chalk.dim(result) |
| 207 | } |
| 208 | |
| 209 | if (styles.color) { |
| 210 | // Color is now always a raw color value (theme resolution happens at component layer) |
| 211 | result = colorize(result, styles.color, 'foreground') |
| 212 | } |
| 213 | |
| 214 | if (styles.backgroundColor) { |
| 215 | // backgroundColor is now always a raw color value |
| 216 | result = colorize(result, styles.backgroundColor, 'background') |
| 217 | } |
| 218 | |
| 219 | return result |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Apply a raw color value to text. |
no test coverage detected