fix(web): bound OKLCH gamut mapping (#6485)

Co-authored-by: Simone <[email protected]>
This commit is contained in:
SimoneandSimone authored and GitHub committed 2026-08-14 19:32:33 -04:00
1 parent e25021af76
commit 74f7b43486
2 files changed
+17 -1

No files matched your search

+12
View File
@@ -246,6 +246,18 @@ describe("theme files", () => {
}
});
it("gamut maps extreme finite OKLCH chroma from theme files", () => {
const theme = parseThemeFile({
version: THEME_FILE_VERSION,
name: "Extreme chroma",
appearance: "light",
colors: { accent: "oklch(0.5 1e303 0)" },
});
expect(theme.colors.accent).toBe("oklch(0.5 1e+303 0)");
expect(themeColorToHex(theme.colors.accent)).toBe("#b5005e");
});
it("rejects unknown roles and invalid color values", () => {
expect(() =>
parseThemeFile({
+5 -1
View File
@@ -902,7 +902,11 @@ function mapThemeOklchToSrgbGamut(color: ThemeOklch): ThemeOklch {
let low = 0;
let high = color.C;
const steps = Math.max(1, Math.ceil(Math.log2(Math.max(color.C, 0.000001) / 0.000001)));
const chromaResolution = 0.000001;
const steps = Math.max(
1,
Math.ceil(Math.log2(Math.max(color.C, chromaResolution)) - Math.log2(chromaResolution)),
);
for (let step = 0; step < steps; step += 1) {
const mid = (low + high) / 2;
if (isInGamut(mid)) low = mid;