jon/color-tools
is a comprehensive color manipulation library for Clojure and ClojureScript that provides everything you need to work with colors in your applications.
Color manipulation is a common need in many applications - from web development to data visualization, design tools, and accessibility compliance. jon/color-tools
provides a unified, functional API for all your color needs.
The library follows these core principles:
All functions are pure with no side effects. Colors in, colors out.
Works identically in Clojure (JVM) and ClojureScript (browser/Node.js) environments.
Functions accept colors in multiple formats (hex strings, RGB vectors) and return results in the same format, making it easy to integrate into existing codebases.
From basic format conversions to advanced color theory and accessibility compliance - all in one library.
The library supports several color formats:
"#ff5733"
or "#f53"
[255, 87, 51]
with values 0-255[255, 87, 51, 0.8]
with alpha 0-1[9, 100, 60]
(Hue 0-360, Saturation/Lightness 0-100)[9, 80, 100]
(Hue 0-360, Saturation/Value 0-100)Most manipulation functions preserve the input format:
(lighten "#ff5733" 0.2) ; Returns hex string
;=> "#ff8566"
(lighten [255 87 51] 0.2) ; Returns RGB vector
;=> [255 133 102]
The library implements color theory concepts like:
Built-in support for WCAG (Web Content Accessibility Guidelines) compliance:
The quickest way to get started is to require the namespace and try some basic operations:
(require '[jon.color-tools :as color])
;; Convert formats
(color/hex->rgb "#3498db")
;=> [52 152 219]
;; Manipulate colors
(color/lighten "#3498db" 0.2)
;=> "#5dade2"
;; Generate palettes
(color/analogous "#3498db" 3)
;=> ["#34c6db" "#34dbae" "#3adb34"]
;; Check accessibility
(color/accessible? "#3498db" "#ffffff")
;=> false ; Doesn't meet AA standards
(color/contrast-ratio "#3498db" "#ffffff")
;=> 3.14 ; Needs 4.5 for AA
The library is organized into several functional areas:
Functions to validate color formats and normalize values (e.g., expanding 3-digit hex codes).
Bidirectional conversion functions between all supported color formats.
Functions to modify colors: lighten, darken, saturate, adjust hue, invert, etc.
Functions to analyze color properties: brightness, warmth, vibrancy, etc.
Functions implementing color theory for generating harmonious color combinations.
Functions for WCAG compliance checking and accessible color generation.
Functions for combining colors mathematically.
The library is designed for performance:
For comprehensive examples and tutorials, see the main README.md file.
For advanced usage patterns and best practices, explore the examples in the test suite.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |