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

    Function contrast

    • Calculates the contrast between two colors using the specified algorithm.

      This function provides a unified interface to access multiple contrast calculation algorithms. It automatically converts the input colors to the appropriate color space required by each algorithm.

      Usage examples:

      // Calculate contrast using the default APCA algorithm
      const apcaContrast = contrast('#000000', '#FFFFFF');

      // Calculate contrast using WCAG 2.1
      const wcagContrast = contrast('#000000', '#FFFFFF', 'WCAG21');

      // Calculate contrast using Delta L*
      const deltaLContrast = contrast('#000000', '#FFFFFF', 'DeltaL*');

      Note that each algorithm produces values in different ranges and with different interpretations:

      • APCA: Values from -108% to 106%, with negative values for light-on-dark
      • DeltaL*: Values from 0 to 100, with higher values indicating more contrast
      • DeltaPhi*: Values from 0 to 100+, with higher values indicating more contrast
      • Michelson: Values from 0 to 1, with higher values indicating more contrast
      • WCAG21: Values from 1:1 to 21:1, with higher values indicating more contrast
      • Weber: Values from 0 to ∞, with higher values indicating more contrast

      Parameters

      • foreground: string | Color

        The foreground color (typically text)

      • background: string | Color

        The background color

      • Optionalalgorithm: ContrastAlgorithm = 'APCA'

        The contrast algorithm to use

      Returns number

      The calculated contrast value

      If an unknown algorithm is specified