tamaki.mes.utils.getReadableTextColor
Description
Determines whether black or white text is more readable against a given hex background colour, using
the perceived-brightness (YIQ) formula. Accepts a 3- or 6-digit hex string, with or without a leading
#. Returns "#000000" (black) for bright backgrounds and "#FFFFFF" (white) for dark backgrounds.
Raises a ValueError if the hex string is not 3 or 6 characters long or contains invalid hex
characters.
Syntax
tamaki.mes.utils.getReadableTextColor(hex_color)
Parameters
| Parameter | Type | Nullable | Description |
|---|---|---|---|
hex_color | String | False | A hex colour string (for example "#FFFFFF", "000", "ff0000"). |
Returns
A String: "#000000" (black) or "#FFFFFF" (white).
Code Examples
# In a binding script transform: pick a readable text colour for a background hex
return tamaki.mes.utils.getReadableTextColor(value)
# e.g. "#1d4ed8" -> "#FFFFFF"