HatangContrast

WCAG colour maths on packed ARGB ints (no Android or Compose types, so it is unit-testable on the JVM). Ported from the Flutter SDK's HatangChatTheme helpers.

Functions

Link copied to clipboard
fun alphaBlend(top: Int, base: Int): Int

top (possibly translucent) composited over the opaque base.

Link copied to clipboard

WCAG 2 contrast ratio between two opaque colours (1 to 21).

Link copied to clipboard
fun lerp(a: Int, b: Int, t: Double): Int

Linear interpolation between two ARGB colours.

Link copied to clipboard
fun luminance(argb: Int): Double

Relative luminance (0 black … 1 white) of an opaque argb colour.

Link copied to clipboard

Near-black or white, whichever reads better on c (a mid blue such as #0ea5e9 gets dark text).

Link copied to clipboard
fun parseHex(hex: String?): Int?

Parses #rgb, #rrggbb or #rrggbbaa into ARGB; null when malformed.

Link copied to clipboard
fun readableOn(c: Int, backgrounds: List<Int>, ratio: Double = 4.5): Int

c moved towards black or white in 5 % steps until it reaches ratio against every colour in backgrounds (opaque; blend translucent tints with alphaBlend first).