Toolkit for analyzing color palettes.
Given an object literal of palettes → color names → tints → colors, easily calculate any stats you need about about the color components. Pretty print the results or import them in other scripts for further processing. The palettes need to all use the same tints and color names ("hues") otherwise results will be meaningless.
You can use this as a JS library or as a CLI tool.
import { getStats } from "palette-lab";
// Your palette data
import palettes from "./palettes.js";
getStats(palettes);
This will print out sample stats to the console (oklch coordinate ranges). However, to really harness the power of this library, you should provide your own queries.
import { getStats } from "palette-lab";
// Your palette data
import palettes from "./palettes.js";
// Your queries
import queries from "./queries.js";
getStats(palettes, queries);
pstats 'palettes/*.css' 'queries/*.js'
Each query consists of the following params to analyze:
component
: The color component to analyze (h, c, l). IfgetValue()
is provided, this is ignored.getValue
: A function to extract the value to analyze from a color, for more complex analysis than just getting a componentby
: The grouping to analyze by (1-2 of 'tint', 'hue', 'palette'). IfgetKey()
is provided, this is ignoredgetKey
: A function to generate a key for each group. If not provided, it is generated based on the 'by' paramcaption
: The caption to display in the console. If not provided, a default label is generated from test params.filter
: Restrict to specific hues/tints/palettes or exclude themstats
: The stats to calculate for each group (min
,max
,mid
,extent
,avg
,median
,count
)
When using as a CLI tool, all params can be specified as --param=value
, except filters which are just included raw in the command.