Three named color palettes plus the helpers to move between hex, rgb, hsl and oklch. No runtime dependencies.
📖 Documentation — all palettes as swatches, usage & release notes
<dependency>
<groupId>io.rocketbase.commons</groupId>
<artifactId>colors</artifactId>
<version>1.0.0</version>
</dependency>| families | shades | total | |
|---|---|---|---|
ColorPalette |
— | — | 64 named colors |
TailwindPalette |
26 | 11 (50–950) | 286 — tracks Tailwind CSS 4.3.3 |
OpenColorPalette |
13 | 10 (0–9) | 130 — tracks Open Color 1.9.1 |
Each name below is printed in the text color the library picks for that background.
The two scale-based palettes keep the family in the enum and take the shade as a parameter:
String hex = TailwindPalette.EMERALD.shade(600).getHexCode();
String open = OpenColorPalette.BLUE.shade(5).getHexCodeWithLeadingHash();
// a random accent color, but never a washed out or nearly black one
TailwindShade accent = TailwindPalette.randomShade(Shade.mids());Tailwind defines its colors in oklch, so that is what the enum stores — the hex code is derived on demand and clipped to the sRGB gamut the way browsers do. All 286 values match what Tailwind publishes.
RgbColor whiteRgb = RgbColor.readRgb("rgb( 255, 255, 255)");
RgbColor whiteHex = RgbColor.hex2rgb("#fff");
boolean textOnTopBlack = whiteHex.isBlackContrastingColor();
// hex, rgb(), hsl() and oklch() all go through one entry point
RgbColor any = RgbColor.readColor("oklch(63.7% 0.237 25.331)");
ColorPalette nearest = ColorPalette.getNearest("#a54e3c");
TailwindShade nearestDark = TailwindPalette.getNearest(Shade.darks(), "#1a1a2e");hex2rgb reads both the short (#abc) and the long (#aabbcc) notation, with or without the leading hash, and returns null for anything it cannot parse.
Nearest-color lookups compare in oklab, where distance matches what the eye sees — an rgb comparison would happily call two colors similar that look nothing alike.
Every palette implements ColorCode, so getRgbColor(), getHslColor(), getOklchColor() and the two contrast helpers work the same everywhere, and ColorCode.getNearest(candidates, code) searches across palettes.
Tailwind CSS colors are MIT licensed, Copyright Tailwind Labs. Open Color is MIT licensed, Copyright (c) 2016 heeyeun.
-
1.0.x correctness, new palettes + new build
- two new palettes:
TailwindPalette(26 families × 11 shades) andOpenColorPalette(13 × 10), both addressed as family + shade instead of hundreds of flat constants - new
Shadeenum with ranges (lights(),mids(),darks(),range(from, to)) that also drive the random helpers - new
ColorCodeinterface shared by all palettes —ColorPaletteimplements it unchanged - new color spaces:
HslColorandOklchColor/OklabColorwithreadHsl,readOklchand a combinedRgbColor.readColor(...) getNearest()now measures distance in oklab instead of rgb, which matches perceived similarity — results differ from 0.6.x- fixed
hex2rgbfor 6-digit codes: the long notation read a single character per channel and multiplied it by 17, so only codes with repeating digit pairs such as#ffffffcame out right.#123456returned (17, 51, 85) instead of (18, 52, 86). Since everyColorPaletteentry is a 6-digit code, this affectedgetNearest()and both contrast algorithms as well — expect different results after upgrading. getHexCode()now zero-pads single-digit channels, sonew RgbColor(5, 10, 15)renders as050a0finstead of55aaff. Hex codes round-trip again.hex2rgbreturnsnullon invalid hex characters instead of throwingNumberFormatException, as the javadoc promised all along.ColorPalette.getRandomValue(Collection)had its loop condition inverted: it only ever returned colors already contained in the collection and looped forever on an empty one.- jdk-11 baseline — the artifact no longer loads on java 8
- moved from travis to github actions, switched release process to new sonatype central publishing
- upgraded dependencies (junit 5.14.4, hamcrest 3.0, lombok 1.18.46)
- two new palettes:
-
0.6.x jsonValue + openapi info
-
0.5.x initial release


