apcach-rs
Rust port of apcach, a color calculator for composing colors with consistent APCA or WCAG contrast.
The crate works in OKLCH and can target both sRGB and Display-P3 output.
Install
Add the crate to Cargo.toml:
[]
= "0.1"
In Rust code, import it as apcach_rs.
Example
use ;
Compose Colors
White background shorthand:
use ;
let color = apcach?;
Foreground on a custom background:
use ;
let color = apcach?;
Maximum chroma search:
use ;
let color = apcach?;
Convert To CSS
use ;
let color = apcach?;
let oklch = to_css?;
let hex = to_css?;
let rgb = to_css?;
let p3 = to_css?;
Supported CSS output formats:
CssFormat::OklchCssFormat::RgbCssFormat::HexCssFormat::P3CssFormat::FigmaP3
API Overview
Core composition and conversion:
apcachcalc_contrastto_css
Contrast configuration helpers:
cr_to_bgcr_to_bg_whitecr_to_bg_blackcr_to_fgcr_to_fg_whitecr_to_fg_black
Color adjustment helpers:
set_contrastmap_contrastset_chromamap_chromaset_huemap_hue
Chroma helpers:
max_chromamax_chroma_capped
Key public types:
ApcachColorChromaColorColorSpaceContrastConfigContrastInputContrastModelCssFormatErrorSearchDirection
License
MIT