Skip to content

0.1.0 — resolve late

Latest

Choose a tag to compare

@soren-creates soren-creates released this 27 Jul 18:21

First public release.

OKLCH colours for SwiftUI that resolve late — against the real display gamut, colour scheme, and contrast setting, at the moment SwiftUI asks for a colour rather than when you wrote it down. Built on ShapeStyle.resolve(in:) (iOS 17+), which nothing else in the ecosystem uses to make colour decisions.

Why late resolution

Every surveyed OKLCH package converts to RGB eagerly, at construction time — and the destination gamut, the colour scheme, the contrast setting, and the backdrop are all runtime facts. Converting back is possible — the maths is invertible — but one baked value cannot say what its author would have chosen for dark mode, Increase Contrast, or a display that could have shown more chroma.

OklchStyle keeps the declaration in OKLCH: light/dark/increased-contrast variants selected at resolve time, or contrasting(_:hue:chroma:preferring:against:) — declare a WCAG or APCA target and the lightness is solved against whatever backdrop is actually behind it, including ones you never saw. No single hard-coded value can pass every backdrop; the solve has to run where the backdrop is known. Out-of-gamut chroma is gamut-mapped per display via CSS Color 4 (the algorithm browsers use) — chroma traded away at the declared hue — rather than hard-clipped with the hue drift that causes.

What's in the box

  • OklchUIOklchStyle (a ShapeStyle that stays in OKLCH), contrast-solved foregrounds with observable shortfall via oklchDiagnostics, backdrop publication via oklchBackground, and a colorGamut override. iOS 17 · macOS 14 · tvOS 17 · visionOS 1.
  • OklchCore — the pure maths: conversions, CSS Color 4 gamut mapping, interpolation with shortest-arc and powerless-hue rules, APCA/WCAG measurement and solving. No platform dependencies; builds and tests on Linux and watchOS 10.

Verification

Nothing here validates itself. Every conversion and gamut-map is asserted against a generated Color.js oracle within measured, pinned tolerances (docs/pins.md); five defects found in existing OKLCH packages are regression tests; on-device measurements show Display P3 surviving the full resolution pipeline bit-for-bit (docs/evidence/).

Install

.package(url: "https://github.com/soren-creates/oklch-swiftui.git", from: "0.1.0")

Pre-1.0: the public API is small and settled, but minor versions may still rearrange it.