(props: InkTextStyleProps)
| 270 | * Convert Ink Text style props to a React CSSProperties object. |
| 271 | */ |
| 272 | export function inkTextPropsToCSS(props: InkTextStyleProps): CSSProperties { |
| 273 | const css: CSSProperties = {} |
| 274 | |
| 275 | const fg = inkColorToCSS(props.color) |
| 276 | const bg = inkColorToCSS(props.backgroundColor) |
| 277 | |
| 278 | if (props.inverse) { |
| 279 | // Swap foreground and background |
| 280 | if (fg) css.backgroundColor = fg |
| 281 | if (bg) css.color = bg |
| 282 | if (!fg) css.filter = 'invert(1)' |
| 283 | } else { |
| 284 | if (fg) css.color = fg |
| 285 | if (bg) css.backgroundColor = bg |
| 286 | } |
| 287 | |
| 288 | if (props.bold) css.fontWeight = 'bold' |
| 289 | if (props.dim) css.opacity = 0.6 |
| 290 | if (props.italic) css.fontStyle = 'italic' |
| 291 | |
| 292 | const decorations: string[] = [] |
| 293 | if (props.underline) decorations.push('underline') |
| 294 | if (props.strikethrough) decorations.push('line-through') |
| 295 | if (decorations.length > 0) css.textDecoration = decorations.join(' ') |
| 296 | |
| 297 | if (props.wrap) { |
| 298 | switch (props.wrap) { |
| 299 | case 'wrap': |
| 300 | case 'wrap-trim': |
| 301 | css.whiteSpace = 'pre-wrap' |
| 302 | css.overflowWrap = 'anywhere' |
| 303 | break |
| 304 | case 'truncate': |
| 305 | case 'truncate-end': |
| 306 | case 'end': |
| 307 | css.overflow = 'hidden' |
| 308 | css.textOverflow = 'ellipsis' |
| 309 | css.whiteSpace = 'nowrap' |
| 310 | break |
| 311 | case 'truncate-middle': |
| 312 | case 'middle': |
| 313 | // CSS can't do mid-truncation; use ellipsis as fallback |
| 314 | css.overflow = 'hidden' |
| 315 | css.textOverflow = 'ellipsis' |
| 316 | css.whiteSpace = 'nowrap' |
| 317 | break |
| 318 | case 'truncate-start': |
| 319 | css.overflow = 'hidden' |
| 320 | css.direction = 'rtl' |
| 321 | css.textOverflow = 'ellipsis' |
| 322 | css.whiteSpace = 'nowrap' |
| 323 | break |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | return css |
| 328 | } |
nothing calls this directly
no test coverage detected