Skip to content
/ Garnish Public

Garnish helps you pick the ideal colors for text and UI elements in light and dark themes, ensuring ideal contrast and visual harmony based on luminance and brightness

License

Notifications You must be signed in to change notification settings

Aeastr/Garnish

Repository files navigation

Garnish Icon

Garnish

Intelligent color utilities for accessibility, contrast optimization, and visual harmony.

Swift 5.9+ iOS 14+ macOS 14+ tvOS 14+ watchOS 7+ visionOS 1+

Auto Contrast Color Math Color Analysis
Automatically generate readable text colors from any background Calculate luminance, brightness, and contrast ratios with WCAG standards Classify colors as light/dark and validate accessibility compliance

Overview

  • Contrast Optimization - Generate colors that meet WCAG accessibility standards
  • Dynamic Color Adaptation - Colors that work beautifully in light and dark themes
  • Mathematical Color Analysis - Precise luminance, brightness, and contrast calculations
  • Smart Color Generation - Create contrasting shades and optimized color combinations
  • Font Weight Optimization - Improved readability through accessibility-first recommendations

Installation

dependencies: [
    .package(url: "https://github.com/Aeastr/Garnish.git", from: "1.0.0")
]

See Getting Started for detailed setup instructions.

Usage

import Garnish

// Generate accessible text color for any background
let textColor = Garnish.contrastingColor(.primary, against: backgroundColor) ?? .primary

// Create a contrasting shade of the same color
let shade = Garnish.contrastingShade(of: .blue) ?? .blue

// Check accessibility compliance
let isAccessible = Garnish.hasGoodContrast(foreground, background)

See Documentation for the full API reference.

Playground

Garnish includes a demo app to explore its features. Open the Xcode workspace, select GarnishPlayground, and run.

Garnish Base Demo

How It Works

Garnish uses WCAG 2.1 luminance calculations to determine optimal contrast ratios. The core algorithm calculates relative luminance using the sRGB color space formula, then generates contrasting colors that meet accessibility thresholds (4.5:1 for AA, 7:1 for AAA compliance).

Contributing

Contributions welcome. See CONTRIBUTING.md for guidelines.

License

MIT. See LICENSE for details.

About

Garnish helps you pick the ideal colors for text and UI elements in light and dark themes, ensuring ideal contrast and visual harmony based on luminance and brightness

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •