modules/colour/contrast.zzm

colour-palette-0.0.1 documentation

Package

Name
colour-palette
Version
0.0.1
Uploaded
2026-05-13 17:33:17
Dependencies
Metadata
zuzu-distribution.json
Archive
Download .tar.gz

NAME

colour/contrast - Colour contrast helpers.

SYNOPSIS

  from colour/contrast import
      contrast_ratio,
      contrast_passes,
      readable_text_colour;

  say( contrast_ratio( "black", "white" ) );
  say( readable_text_colour( "gold" ) );

DESCRIPTION

This pure-Zuzu module provides WCAG-style relative luminance and contrast ratio helpers. All colour arguments are parsed through std/colour via colour/palette.

EXPORTED FUNCTIONS

  • relative_luminance(String colour)

    Return the sRGB relative luminance for colour.

  • contrast_ratio(String foreground, String background)

    Return the contrast ratio between two colours.

  • contrast_passes(String foreground, String background, String level := "AA", Boolean large_text := false)

    Return whether the pair passes AA or AAA. Large text uses the corresponding reduced thresholds.

  • contrast_grade(String foreground, String background)

    Return AAA, AA, AA Large, or Fail.

  • best_contrast(String background, Array colours)

    Return the candidate colour with the best contrast against background.

  • readable_text_colour(String background, String dark := "#000000", String light := "#ffffff")

    Return whichever of dark or light has better contrast against background.

COPYRIGHT AND LICENCE

colour/contrast is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.