Skip to content

Releases: MineProDan/contrast-audit

ContrastAudit 0.1.0

Choose a tag to compare

@MineProDan MineProDan released this 26 Oct 06:37

First release of ContrastAudit: audit a whole color theme for WCAG 2.1 contrast from swift test, and get one failure that names every failing pair with its measured and required ratio.

Real output from the demo package (docs/example-output.txt):

✘ Test emberMeetsAA() recorded an issue at ThemeContrastTests.swift:19:35: Issue recorded
↳ Contrast audit failed for theme 'Ember' at AA: 2 of 12 checks failed (6 pairs x 2 variants).
    [light] 'toggle-track' on 'surface'  1.76:1  needs 3.00:1 (AA, UI component)
    [dark] 'subtitle' on 'surface'  3.89:1  needs 4.50:1 (AA, body text)
  Not counted as failures: 1 waived.

Added

  • ContrastCore, with no UI-framework or test-framework imports:
    • SRGBColor, created from components in 0...1 (throws instead of clamping),
      from 8-bit components, or from #RGB, #RGBA, #RRGGBB and #RRGGBBAA
      hex strings.
    • WCAG 2.1 relative luminance and ContrastRatio, which compares unrounded
      values and displays them truncated to two decimals, never rounded up.
    • PairRole (.bodyText, .largeText, .uiComponent) and
      ConformanceLevel (.aa, .aaa) with the WCAG 2.1 requirements.
    • Theme, ColorPair and Variant for declaring pairs once and auditing
      them in every variant.
    • Explicit backdrops for translucent backgrounds; source-over compositing on
      gamma-encoded sRGB; no assumed white background.
    • Waiver for reviewed exceptions with a reason and optional expiry note.
    • Baseline for recording known failures that may not get worse, with a
      versioned JSON format.
    • AuditReport with summary, the aggregated failureDescription,
      markdown() and json(), and CheckResult for inspecting checks in code.
    • Configuration mistakes (missing or malformed colors, duplicates, empty
      themes, backdrop problems, baseline level mismatch) reported as
      AuditProblems instead of crashes.
  • ContrastAuditTesting: ContrastAudit.assertPasses for XCTest and
    ContrastAudit.expectPasses for Swift Testing, each recording one failure
    with the aggregated message at the caller's source location.
  • ContrastPlatformColors: SRGBColor(resolving:appearance:) for NSColor,
    SRGBColor(resolving:with:) for UIColor and SRGBColor(resolving:in:) for
    SwiftUI Color, each with an explicit appearance, converting to sRGB without
    clamping.
  • scripts/verify_vectors.py, an independent standard-library Python
    implementation that generates the reference-vector fixture used by the tests.
  • Examples/ThemeAuditDemo, a separate package with one passing and one
    intentionally failing invented theme.
  • scripts/leak_scan.sh and a GitHub Actions workflow for macOS (Xcode 26.6 and
    Xcode 16.0 / Swift 6.0), the iOS
    simulator, Linux and the leak scan.

A passing audit means the declared pairs meet the declared ratios. It does not mean an app is accessible.