Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
10 changes: 10 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
22 changes: 22 additions & 0 deletions packages/ui/src/theme/color.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
6 changes: 5 additions & 1 deletion packages/ui/src/theme/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Loading