diff --git a/packages/palette/src/Color.test.ts b/packages/palette/src/Color.test.ts index 0a0c2e84..49518782 100644 --- a/packages/palette/src/Color.test.ts +++ b/packages/palette/src/Color.test.ts @@ -76,3 +76,26 @@ test("All color spaces do round trip to each other correctly", () => { ); }); }); + +test("In gamut tests", () => { + const colors = [ + "#f00", + "#ff0", + "#0f0", + "#0ff", + "#00f", + "#f0f", + "#fff", + "#888", + "#000", + ]; + const spaces = ["lab"]; + colors.forEach((color) => { + spaces.forEach((space) => { + const colorObj = Color.colorFromHex(color, space as any); + expect(colorObj.inGamut(), `${color} from ${space} to be in gamut`).toBe( + true + ); + }); + }); +}); diff --git a/packages/palette/src/Color.ts b/packages/palette/src/Color.ts index 510b176c..4b7c8944 100644 --- a/packages/palette/src/Color.ts +++ b/packages/palette/src/Color.ts @@ -81,7 +81,7 @@ export class Color { if (InGamutCache.has(key)) { return InGamutCache.get(key)!; } - const result = this.toColorIO().inGamut("srgb"); + const result = this.toColorIO().to("p3", { inGamut: false }).inGamut(); InGamutCache.set(key, result); return result; }