@dragonspark/chroma-kit
    Preparing search index...

    Function contrastAPCA

    • Calculates the contrast between two colors using the APCA (Accessible Perceptual Contrast Algorithm).

      APCA is a modern contrast algorithm designed to replace WCAG 2.x contrast metrics. It was developed by Andrew Somers to better predict perceived contrast for modern displays and to address limitations in the WCAG 2.x contrast formula.

      The algorithm uses different calculations based on the polarity (whether text is darker or lighter than the background), applies non-linear transformations to account for human perception, and includes special handling for very dark colors.

      Key characteristics:

      • Produces values from approximately -108% to 106% (negative values indicate light text on dark background)
      • Accounts for the non-linear perception of contrast in human vision
      • Uses different calculations based on polarity (dark-on-light vs. light-on-dark)
      • Applies soft clamping to very dark colors to prevent excessive contrast
      • Designed specifically for predicting readability of text
      • Recommended minimum values vary by font size and weight:
        • Large, bold text: 45%
        • Normal body text: 60%
        • Small or thin text: 75%

      Limitations:

      • More complex than simpler contrast metrics
      • Still evolving and may change in future versions
      • Not yet officially adopted in accessibility standards
      • Requires conversion to specific color spaces for accurate results

      Parameters

      • foreground: RGBColor

        The foreground (typically text) color in RGB color space

      • background: RGBColor

        The background color in RGB color space

      Returns number

      The APCA contrast value, with positive values for dark-on-light and negative values for light-on-dark