From 8d730d4c6f17c77ba7aa5b4880d40792ebc874a6 Mon Sep 17 00:00:00 2001 From: Lloyd Kupchanko Date: Tue, 28 Feb 2023 21:42:30 -0700 Subject: [PATCH] Ensure toGamut always returns a color object 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. --- src/toGamut.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/toGamut.js b/src/toGamut.js index c95c4b157..d68ee3549 100644 --- a/src/toGamut.js +++ b/src/toGamut.js @@ -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. @@ -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: