Skip to content

feat: OKLCH palette — perceptually-uniform preset colours#60

Closed
LeslieOA wants to merge 2 commits into
developfrom
feat/oklch-theme
Closed

feat: OKLCH palette — perceptually-uniform preset colours#60
LeslieOA wants to merge 2 commits into
developfrom
feat/oklch-theme

Conversation

@LeslieOA

@LeslieOA LeslieOA commented May 29, 2026

Copy link
Copy Markdown
Member

Summary

  • Replaces hand-rolled HSL palette in theme.ts with OKLCH presets via use-color (zero-dep, OKLCH-native, gamut-mapping built in)
  • All six preset codes share L=0.62, C≈0.175–0.19 — perceived brightness is now consistent across hues. Yellow (code 3) is intentionally L=0.78 (perceptually correct: yellow is inherently lighter at equal vividness)
  • Removes ~60 lines of bespoke hslToRgb / hexToHsl / rgbToHex helpers; card/border/background derivations use OKLCH-native .alpha() / fromOklch()
  • Public API unchangedgetNodeColors, getCanvasBackground, getMutedTextColor, resolveScheme have identical signatures; Skia consumers still receive plain #rrggbb / #rrggbbaa
  • Imports from the use-color main entry (not the /core subpath) so resolution works under Metro without requiring downstream consumers to enable package-exports

New preset colours (active hex)

Code Colour Old (HSL) New (OKLCH)
1 Red #d1453b #e24947
2 Orange #d86b2d #d85c00
3 Yellow #d4a017 #d2b71e
4 Green #2d7a3a #2aa03a
5 Blue #2980d4 #009ad0
6 Purple #8b5fd4 #9b67dc

Test plan

  • CI passes (typecheck + lint + 72 tests, 34 new in theme.test.ts)
  • On-device (macOS): open hesprs-demo / Gradients.canvas, confirm all 6 colour codes render visually balanced — no single hue dominating in brightness
  • Dark and light mode both look right
  • User-provided hex colours (#rrggbb in canvas JSON) still produce valid palettes

🤖 Generated with Claude Code

Closes #61

LeslieOA and others added 2 commits May 29, 2026 22:47
All six preset colours (codes 1–6) now live in OKLCH space at a common
L=0.62 / C≈0.175–0.19, with hue rotating around the wheel. Yellow (code 3)
carries L=0.78 because that is perceptually correct — equal perceived
vividness requires higher lightness on yellow. The old HSL presets at L=55%
read noticeably uneven: yellow was brighter, green darker.

Colour derivations (card, border, background, activeTransparent) now use
use-color's OKLCH-native operations instead of hand-rolled HSL math — which
removes ~60 lines of bespoke hslToRgb / hexToHsl helpers.

Public API unchanged: getNodeColors / getCanvasBackground / getMutedTextColor
/ resolveScheme all have the same signatures. Skia consumers keep receiving
plain #rrggbb / #rrggbbaa strings.

Adds src/renderer/__tests__/theme.test.ts: 34 tests covering output shape,
activeTransparent contract, no-colour defaults, preset distinctness, dark/light
card contrast, hex input, unknown code fallback, and utility functions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The /core subpath resolves only via the package `exports` field — it has no
file fallback. The main `use-color` entry has `main`/`module` fields, so it
resolves under Metro regardless of `unstable_enablePackageExports`. Since this
is a published library, depending on an exports-only subpath would silently
require every downstream consumer's Metro to enable package-exports. The main
entry avoids that at a ~negligible cost (full bundle is a superset of core).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LeslieOA

Copy link
Copy Markdown
Member Author

Closing without merging. OKLCH produced no user-visible win for this codebase (see #61 for the full post-mortem): native gradient interpolation is unavailable in the RN Skia binding and moot for single-hue fades; a uniform-OKLCH palette flattened the intended Obsidian/hesprs vibrancy; and OKLCH anchored on the real hexes is ≈identical to the existing HSL while adding a runtime dep. Keeping the canonical HSL palette. Branch deleted.

@LeslieOA LeslieOA closed this May 30, 2026
@LeslieOA LeslieOA deleted the feat/oklch-theme branch May 30, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

explore: colour rendering across all JSON Canvas elements (not just gradients)

1 participant