diff --git a/.devcontainer/devcontainer-lock.json b/.devcontainer/devcontainer-lock.json new file mode 100644 index 00000000..be560843 --- /dev/null +++ b/.devcontainer/devcontainer-lock.json @@ -0,0 +1,9 @@ +{ + "features": { + "ghcr.io/devcontainers-extra/features/bun:1": { + "version": "1.1.0", + "resolved": "ghcr.io/devcontainers-extra/features/bun@sha256:0624284ecaead9dd4c6654616a7f939cfa4ebcbc60593700a74e35b1767befa5", + "integrity": "sha256:0624284ecaead9dd4c6654616a7f939cfa4ebcbc60593700a74e35b1767befa5" + } + } +} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..2d7fd991 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,10 @@ +{ + "name": "Node.js & TypeScript", + "image": "mcr.microsoft.com/devcontainers/typescript-node:5-24-trixie", + + "features": { + "ghcr.io/devcontainers-extra/features/bun:1": { + "version": "latest" + } + } +} \ No newline at end of file diff --git a/packages/ui/src/theme/color.test.ts b/packages/ui/src/theme/color.test.ts new file mode 100644 index 00000000..1b85e5b5 --- /dev/null +++ b/packages/ui/src/theme/color.test.ts @@ -0,0 +1,22 @@ +import { describe, expect, test } from "bun:test" +import { fitOklch } from "./color" + +describe("fitOklch", () => { + test("keeps an in-gamut color unchanged", () => { + const input = { l: 0.5, c: 0.1, h: 120 } + + const result = fitOklch(input) + + expect(result).toEqual(input) + }) + + test("reduces chroma for an out-of-gamut color", () => { + const input = { l: 0.5, c: 1, h: 120 } + + const result = fitOklch(input) + + expect(result.c).toBeLessThanOrEqual(input.c) + expect(result.l).toBeGreaterThanOrEqual(0) + expect(result.l).toBeLessThanOrEqual(1) + }) +}) \ No newline at end of file diff --git a/packages/ui/src/theme/color.ts b/packages/ui/src/theme/color.ts index 730642b1..21794ae7 100644 --- a/packages/ui/src/theme/color.ts +++ b/packages/ui/src/theme/color.ts @@ -117,7 +117,11 @@ export function fitOklch(oklch: OklchColor): OklchColor { c *= 0.9 const next = { ...base, c } const out = oklchToRgb(next) - if (out.r >= 0 && out.r <= 1 && out.g >= 0 && out.g <= 1 && out.b >= 0 && out.b <= 1) { + const redInRange = out.r >= 0 && out.r <= 1 + const greenInRange = out.g >= 0 && out.g <= 1 + const blueInRange = out.b >= 0 && out.b <= 1 + + if (redInRange && greenInRange && blueInRange) { return next } }