Skip to content

Commit

Permalink
Use clipped version if not in gamut
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnw committed Nov 20, 2023
1 parent eb453de commit 1375f3e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/toGamut.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -213,5 +214,8 @@ export function toGamutCSS (origin, { space = origin.space }) {
}
}
}
if (!inGamut(current, space)){
current = clipped;
}
return to(current, space);
}

0 comments on commit 1375f3e

Please sign in to comment.