Skip to content

Commit

Permalink
Ensure toGamut always returns a color object
Browse files Browse the repository at this point in the history
Calling toGamut with a color that is already in gamut
for the specified color space would return the original
color parameter which may or may not be a color object.

For example calling toGamut("red", "oklch") would return "red"
instead of a color object.

This change ensures that a color object will always be returned.
  • Loading branch information
lloydk committed Mar 1, 2023
1 parent e939c7c commit 8d730d4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/toGamut.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import to from "./to.js";
import get from "./get.js";
import set from "./set.js";
import clone from "./clone.js";
import getColor from "./getColor.js";

/**
* Force coordinates to be in gamut of a certain color space.
Expand All @@ -27,7 +28,7 @@ export default function toGamut (color, {method = defaults.gamut_mapping, space
space = ColorSpace.get(space);

if (inGamut(color, space, {epsilon: 0})) {
return color;
return getColor(color);
}

// 3 spaces:
Expand Down

0 comments on commit 8d730d4

Please sign in to comment.