moderator-toolbox-nxg-for-reddit / util/data/color

util/data/color

Functions

autoContrastColor()

autoContrastColor(color, bg): string

Defined in: extension/data/util/data/color.ts:196

Adjusts a color’s lightness just far enough to meet WCAG AA small-text contrast against bg, keeping its hue and saturation. Colors that already pass are returned unchanged (normalized to hex). The lightness walks toward white on dark backgrounds and toward black on light ones, so the loop always terminates at a readable color.

Parameters

color

string

bg

string

Returns

string


colorNameToHex()

colorNameToHex(color): string

Defined in: extension/data/util/data/color.ts:19

Converts an HTML color name to its hex value, returning the input unchanged if not a known name.

Parameters

color

string

Returns

string


getBestTextColor()

getBestTextColor(bgColor): string

Defined in: extension/data/util/data/color.ts:11

Returns the most readable text color (black or white) for a given background color. Results are memoized.

Parameters

bgColor

string

Returns

string


invertedDarkVariant()

invertedDarkVariant(color): string

Defined in: extension/data/util/data/color.ts:216

Computes the dark-mode variant of a color the way classic toolbox’s dark-mode container filter (filter: invert(90%) hue-rotate(180deg)) did: a 90% channel inversion followed by the CSS filter spec’s hue-rotate matrix at 180°. Accepts any tinycolor-parseable color and returns hex.

Parameters

color

string

Returns

string


isReadableOn()

isReadableOn(color, bg): boolean

Defined in: extension/data/util/data/color.ts:185

Returns true when color meets WCAG AA small-text contrast against bg.

Parameters

color

string

bg

string

Returns

boolean

Variables

DARK_THEME_BG

const DARK_THEME_BG: "rgb(17 27 38)" = 'rgb(17 27 38)'

Defined in: extension/data/util/data/color.ts:182


LIGHT_THEME_BG

const LIGHT_THEME_BG: "rgb(247 250 253)" = 'rgb(247 250 253)'

Defined in: extension/data/util/data/color.ts:181

Representative theme background colors that usernote tags and chips sit on

  • the --toolbox-action-bg values from base.css. Used for readability checks; keep in sync with the variable definitions there.