Skip to content

Commit 335b00b

Browse files
committed
fix(web): bound OKLCH gamut mapping
1 parent 9e20194 commit 335b00b

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎apps/web/src/themePalette.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ describe("theme files", () => {
246246
}
247247
});
248248

249+
it("gamut maps extreme finite OKLCH chroma from theme files", () => {
250+
const theme = parseThemeFile({
251+
version: THEME_FILE_VERSION,
252+
name: "Extreme chroma",
253+
appearance: "light",
254+
colors: { accent: "oklch(0.5 1e303 0)" },
255+
});
256+
257+
expect(theme.colors.accent).toBe("oklch(0.5 1e+303 0)");
258+
expect(themeColorToHex(theme.colors.accent)).toBe("#b5005e");
259+
});
260+
249261
it("rejects unknown roles and invalid color values", () => {
250262
expect(() =>
251263
parseThemeFile({

‎apps/web/src/themePalette.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,11 @@ function mapThemeOklchToSrgbGamut(color: ThemeOklch): ThemeOklch {
902902

903903
let low = 0;
904904
let high = color.C;
905-
const steps = Math.max(1, Math.ceil(Math.log2(Math.max(color.C, 0.000001) / 0.000001)));
905+
const chromaResolution = 0.000001;
906+
const steps = Math.max(
907+
1,
908+
Math.ceil(Math.log2(Math.max(color.C, chromaResolution)) - Math.log2(chromaResolution)),
909+
);
906910
for (let step = 0; step < steps; step += 1) {
907911
const mid = (low + high) / 2;
908912
if (isInGamut(mid)) low = mid;

0 commit comments

Comments
 (0)