@OPEN-KAPPA/COLORS
    Preparing search index...

    Class WcagAbstract

    Utilities for Web Content Accessibility Guidelines (WCAG) and APCA. Provides methods to check contrast ratios and readability.

    Index

    Constructors

    Methods

    • Calculates the APCA (Advanced Perceptual Contrast Algorithm) value. Returns a value Lc between ~ -108 and +106.

      • Positive: Dark text on light background.
      • Negative: Light text on dark background.
      • APCA is perceptually more accurate than standard WCAG 2.1, accounting for polarity (light-on-dark vs dark-on-light).

      Parameters

      • background: Xyz

        The background.

      • text: Xyz

        The text.

      Returns number

      The score.

    • Returns font size requirements based on the APCA score. APCA couples contrast with font weight and size (unlike WCAG 2.1).

      Parameters

      • apcaScore: number

        The score.

      Returns FontRequirements

      The reequirements.

    • Get a human friendly string representing the score.

      Parameters

      • score: number

        The score.

      Returns string

      The string.

    • Computes the standard WCAG 2.1 contrast ratio. Formula: (L1 + 0.05) / (L2 + 0.05) Returns a value between 1.0 and 21.0.

      Parameters

      • c1: Xyz

        THe first color.

      • c2: Xyz

        The second color.

      Returns number

      The contrast.

    • Returns the color (c1 or c2) that provides the highest contrast against the background. Uses APCA by default for perceptual accuracy, but falls back to WCAG 2.1 if specified.

      Parameters

      • bg: Xyz

        The background color.

      • dark: Xyz

        The dark text option (usually Black).

      • light: Xyz

        The light text option (usually White).

      • algorithm: "APCA" | "WCAG" = "APCA"

        The algorithm to use ("APCA" or "WCAG").

      Returns Xyz

      The color with the best contrast.

    • Returns the minimum font size for a specific font weight.

      Parameters

      • apcaScore: number

        The calculated APCA score.

      • weight: ApcaWeight

        The font weight (200, 300, 400, 500, 600, 700, 900).

      Returns number

      The minimum size in pixels, or 999 if prohibited.

    • Check if the text is readable.

      Parameters

      • bg: Xyz

        The background.

      • text: Xyz

        The text.

      • fontSize: number

        The font size.

      • fontWeight: "normal" | "bold" = "normal"

        The font weight.

      Returns boolean

      True if readable.

    • Check if the text is dark.

      Parameters

      • color: Xyz

        The color.

      Returns boolean

      True if the color is dark.

    • Check if the text is light.

      Parameters

      • color: Xyz

        The color.

      Returns boolean

      True if the color is light.

    • Get the relative luminance.

      Parameters

      • color: Xyz

        The color.

      Returns number

      The luminance.