Color spaces and ranges
An RGB triplet from a canvas can use 0–255, while a picker may give you 0–1. Choose the channel space and units before you move values between tools.
Look up the channel ranges
Alpha runs from 0 to 1 in each space. These are typical values. Numeric conversions can give you channels outside those ranges for wide-gamut colors.
Read channels for a picker
Use toArray('srgb') for encoded unit-range RGB followed by alpha.
import { colore } from 'colore-js';
const blue = colore('#2563eb');
console.log(blue.toArray('srgb').map(value => Number(value.toFixed(3))));
// [0.145, 0.388, 0.922, 1]
Use toObject('srgb') if you need to pass that color back to Colore with its space attached. Use toRgb() when your consumer expects 0–255 integer channels.
Mix colors in the space you want
import { colore } from 'colore-js';
console.log(colore('#ff0000').mix('#0000ff', 0.5, 'oklab').css()); // '#8c53a2'
OKLab is a good starting point for a visual transition. Use sRGB when you need to match an existing sRGB blend.
Related
- Gamut and CSS output for mapping and clipping
- Color object output
- Use OKLCH in JavaScript