diff --git a/src/toGamut.js b/src/toGamut.js index 2902cbe3d..691a4594a 100644 --- a/src/toGamut.js +++ b/src/toGamut.js @@ -136,12 +136,13 @@ export function toGamutCSS (origin, { space = origin.space }) { const JND = 0.02; const ε = 0.0001; space = ColorSpace.get(space); + const oklchSpace = ColorSpace.get("oklch"); if (space.isUnbounded) { return to(origin, space); } - const origin_OKLCH = to(origin, ColorSpace.get("oklch")); + const origin_OKLCH = to(origin, oklchSpace); let L = origin_OKLCH.coords[0]; // return media white or black, if lightness is out of range @@ -213,5 +214,8 @@ export function toGamutCSS (origin, { space = origin.space }) { } } } + if (!inGamut(current, space)){ + current = clipped; + } return to(current, space); }