feat(desktop): keep midnight, and retint themes that shade their accent
Midnight is monotone in a way none of the other skins are, and it turns out to be a good test of the retint: its ring is `#8b80e8` under a `#ddd6ff` primary — the same violet at a different lightness, not a repeat of one hex. Matching accent slots by exact equality with the primary left that ring behind, so re-seeding produced a half-retinted theme with a purple ring under a teal accent. Slots now join the family by HUE, within a tolerance, and each keeps its own lightness and chroma when it moves. A theme that deliberately runs a deeper ring keeps that relationship instead of being flattened onto one colour. Near-greys are excluded by chroma rather than hue, so mono's neutral ring still stays exactly where its author put it.
This commit is contained in:
committed by
brooklyn!
parent
b8c6547ca4
commit
50e2f970c8
@@ -297,6 +297,14 @@ export function maxChroma(l: number, h: number): number {
|
||||
return lo
|
||||
}
|
||||
|
||||
/**
|
||||
* Signed shortest angular distance from `from` to `to`, in degrees (-180..180).
|
||||
* Hue is a circle: 350° and 10° are 20° apart, not 340°.
|
||||
*/
|
||||
export function hueDelta(from: number, to: number): number {
|
||||
return ((to - from + 540) % 360) - 180
|
||||
}
|
||||
|
||||
/**
|
||||
* Bend a semantic color toward the accent along the shortest hue arc.
|
||||
*
|
||||
@@ -319,8 +327,7 @@ export function harmonize(hex: string, accent: string, strength: number): string
|
||||
}
|
||||
|
||||
// Signed shortest arc, so a green never takes the long way round the wheel.
|
||||
const delta = ((target.h - base.h + 540) % 360) - 180
|
||||
const h = (base.h + delta * Math.min(1, Math.max(0, strength)) + 360) % 360
|
||||
const h = (base.h + hueDelta(base.h, target.h) * Math.min(1, Math.max(0, strength)) + 360) % 360
|
||||
|
||||
return oklchToHex({ ...base, c: Math.min(Math.max(base.c, target.c * 0.85), maxChroma(base.l, h)), h })
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ const PROFILE_MODES_KEY = 'hermes-desktop-profile-modes-v1'
|
||||
const LAST_PROFILE_KEY = 'hermes-desktop-active-profile-v1'
|
||||
// Skins that no longer exist. A profile still pointing at one falls back to
|
||||
// DEFAULT_SKIN_NAME rather than painting a name nothing resolves.
|
||||
const RETIRED_SKINS = new Set(['nous-light', 'default', 'gold', 'midnight'])
|
||||
const RETIRED_SKINS = new Set(['nous-light', 'default', 'gold'])
|
||||
|
||||
export type ThemeMode = 'light' | 'dark' | 'system'
|
||||
|
||||
|
||||
@@ -587,6 +587,46 @@ export const solarizedTheme: DesktopTheme = {
|
||||
}
|
||||
|
||||
/** Warm crimson and bronze — forge vibes. Matches the CLI ares skin. */
|
||||
/**
|
||||
* Midnight — deep blue-violet, near-monotone. Dark only: it has no light
|
||||
* palette because the whole idea is the dark end of the spectrum.
|
||||
*/
|
||||
export const midnightTheme: DesktopTheme = {
|
||||
name: 'midnight',
|
||||
label: 'Midnight',
|
||||
description: 'Deep blue-violet with cool accents',
|
||||
colors: {
|
||||
background: '#08081c',
|
||||
foreground: '#ddd6ff',
|
||||
card: '#0d0d28',
|
||||
cardForeground: '#ddd6ff',
|
||||
muted: '#13133a',
|
||||
mutedForeground: '#7c7ab0',
|
||||
popover: '#0f0f2e',
|
||||
popoverForeground: '#ddd6ff',
|
||||
primary: '#ddd6ff',
|
||||
primaryForeground: '#08081c',
|
||||
secondary: '#1a1a4a',
|
||||
secondaryForeground: '#c4bff0',
|
||||
accent: '#1a1a44',
|
||||
accentForeground: '#d0c8ff',
|
||||
border: '#1e1e52',
|
||||
input: '#1e1e52',
|
||||
ring: '#8b80e8',
|
||||
midground: '#8b80e8',
|
||||
destructive: '#b03060',
|
||||
destructiveForeground: '#fef2f2',
|
||||
sidebarBackground: '#06061a',
|
||||
sidebarBorder: '#12123a',
|
||||
userBubble: '#14143a',
|
||||
userBubbleBorder: '#242466'
|
||||
},
|
||||
typography: {
|
||||
fontMono: `"JetBrains Mono", ${SYSTEM_MONO}`,
|
||||
fontUrl: 'https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap'
|
||||
}
|
||||
}
|
||||
|
||||
export const emberTheme: DesktopTheme = {
|
||||
name: 'ember',
|
||||
label: 'Ember',
|
||||
@@ -735,6 +775,7 @@ export const BUILTIN_THEMES: Record<string, DesktopTheme> = {
|
||||
catppuccin: catppuccinTheme,
|
||||
everforest: everforestTheme,
|
||||
solarized: solarizedTheme,
|
||||
midnight: midnightTheme,
|
||||
ember: emberTheme,
|
||||
mono: monoTheme,
|
||||
slate: slateTheme,
|
||||
|
||||
@@ -197,4 +197,31 @@ describe('retintTheme', () => {
|
||||
|
||||
expect(retintTheme(neutralRing, '#8250df').colors.ring).toBe('#9a9a9a')
|
||||
})
|
||||
|
||||
// A theme may shade its accent across slots rather than repeating one hex —
|
||||
// midnight runs a `#8b80e8` ring under a `#ddd6ff` primary. Both are the
|
||||
// same violet; matching on exact equality left the ring behind and produced
|
||||
// a half-retinted theme.
|
||||
describe('a theme whose accent slots are shades of each other', () => {
|
||||
const shaded = {
|
||||
...nousTheme,
|
||||
colors: { ...nousTheme.colors, primary: '#ddd6ff', ring: '#8b80e8', midground: '#8b80e8' },
|
||||
darkColors: undefined
|
||||
}
|
||||
|
||||
it('moves every slot in the family', () => {
|
||||
const teal = retintTheme(shaded, '#0f9b8e')
|
||||
|
||||
expect(teal.colors.ring).not.toBe('#8b80e8')
|
||||
expect(Math.abs(hexToOklch(teal.colors.ring)!.h - hexToOklch('#0f9b8e')!.h)).toBeLessThan(3)
|
||||
})
|
||||
|
||||
it('keeps each slot at its own lightness, rather than flattening them', () => {
|
||||
const teal = retintTheme(shaded, '#0f9b8e')
|
||||
const ring = hexToOklch(teal.colors.ring)!
|
||||
|
||||
expect(ring.l).toBeCloseTo(hexToOklch('#8b80e8')!.l, 1)
|
||||
expect(ring.l).not.toBeCloseTo(hexToOklch(teal.colors.primary)!.l, 1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
* Accent retinting — re-seed a theme's accent family from one color.
|
||||
*
|
||||
* A palette's accent is not one color, it's a family: the seed plus the soft
|
||||
* surfaces mixed from it. In `nous` that's 7 slots per mode from ONE seed —
|
||||
* `primary`/`ring`/`midground`/`composerRing` share the seed outright, and
|
||||
* `accent`/`secondary`/`userBubble` are mixes of it toward the background.
|
||||
* surfaces mixed from it. In `nous` that's 7 slots per mode —
|
||||
* `primary`/`ring`/`midground`/`composerRing` carry the accent itself, and
|
||||
* `accent`/`secondary`/`userBubble` are mixes of it toward the background. The
|
||||
* carrying slots need not be the same hex: a theme may shade them (see
|
||||
* `tracksAccent`), and a re-seed keeps that shading.
|
||||
*
|
||||
* So retinting is not "replace some hexes": it's move the seed, then re-derive
|
||||
* the family with the exact ratios the VS Code converter used. Those ratios
|
||||
@@ -24,13 +26,33 @@
|
||||
* the accent turns every theme into a monochrome wash.
|
||||
*/
|
||||
|
||||
import { ensureContrastOklch, hexToOklch, mixOklab, normalizeHex, oklchToHex, readableOn } from './color'
|
||||
import {
|
||||
ensureContrastOklch,
|
||||
hexToOklch,
|
||||
hueDelta,
|
||||
mixOklab,
|
||||
normalizeHex,
|
||||
type Oklch,
|
||||
oklchToHex,
|
||||
readableOn
|
||||
} from './color'
|
||||
import type { DesktopTheme, DesktopThemeColors } from './types'
|
||||
|
||||
/** Small uppercase sidebar labels paint in the accent, so it must clear AA. */
|
||||
const ACCENT_MIN_CONTRAST = 4.5
|
||||
|
||||
/** Slots that carry the accent seed verbatim. */
|
||||
/**
|
||||
* How far a slot's hue may sit from the primary and still count as the same
|
||||
* accent family. Wide enough for a theme that shades its ring (midnight runs
|
||||
* 286° against a 293° primary), narrow enough that a second, deliberately
|
||||
* different accent is left alone.
|
||||
*/
|
||||
const ACCENT_HUE_TOLERANCE = 25
|
||||
|
||||
/** Below this chroma a colour is a grey and its hue is noise. */
|
||||
const ACCENT_MIN_CHROMA = 0.03
|
||||
|
||||
/** Slots that carry the accent itself, rather than a surface mixed from it. */
|
||||
const ACCENT_SEED_KEYS = ['primary', 'ring', 'midground', 'composerRing'] as const
|
||||
|
||||
/**
|
||||
@@ -43,17 +65,47 @@ const ACCENT_MIX = {
|
||||
userBubble: { light: 0.12, dark: 0.18 }
|
||||
} as const
|
||||
|
||||
/**
|
||||
* Whether a slot belongs to the accent family, and so should follow a re-seed.
|
||||
*
|
||||
* Exact equality with `primary` is too strict: midnight's ring is `#8b80e8`
|
||||
* against a `#ddd6ff` primary — a deeper shade of the same violet, obviously
|
||||
* accent, and leaving it behind half-retints the theme. Hue is the honest
|
||||
* test. A slot within ACCENT_HUE_TOLERANCE of the primary is the same colour
|
||||
* family at another lightness; anything further is a deliberate choice (mono's
|
||||
* neutral grey ring) and stays put.
|
||||
*
|
||||
* Near-greys are decided by chroma, not hue: below ACCENT_MIN_CHROMA a hue
|
||||
* reading is noise, so a grey tracks the accent only when the accent is itself
|
||||
* a grey — which is how mono's own primary keeps working.
|
||||
*/
|
||||
function tracksAccent(slot: Oklch, primary: Oklch): boolean {
|
||||
if (slot.c < ACCENT_MIN_CHROMA) {
|
||||
return primary.c < ACCENT_MIN_CHROMA
|
||||
}
|
||||
|
||||
return Math.abs(hueDelta(primary.h, slot.h)) <= ACCENT_HUE_TOLERANCE
|
||||
}
|
||||
|
||||
/** Re-derive the accent family of one palette around `seed`. */
|
||||
function retintColors(colors: DesktopThemeColors, seed: string, isDark: boolean): DesktopThemeColors {
|
||||
const next: DesktopThemeColors = { ...colors }
|
||||
const pick = (spec: { dark: number; light: number }) => (isDark ? spec.dark : spec.light)
|
||||
const primary = hexToOklch(colors.primary)
|
||||
const seedLch = hexToOklch(seed)
|
||||
|
||||
for (const key of ACCENT_SEED_KEYS) {
|
||||
// Only move a slot that actually tracked the accent. A theme whose `ring`
|
||||
// is a neutral gray meant it; retinting must not brand it by surprise.
|
||||
if (colors[key] === colors.primary) {
|
||||
next[key] = seed
|
||||
const slot = colors[key]
|
||||
const lch = slot ? hexToOklch(slot) : null
|
||||
|
||||
if (!lch || !primary || !seedLch || !tracksAccent(lch, primary)) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Take the seed's hue but keep the slot's OWN lightness and chroma, so a
|
||||
// theme that deliberately runs a deeper ring than its primary keeps that
|
||||
// relationship instead of being flattened onto one colour.
|
||||
next[key] = slot === colors.primary ? seed : oklchToHex({ ...lch, h: seedLch.h })
|
||||
}
|
||||
|
||||
// OKLab, not sRGB: blending a saturated blue toward white in gamma space
|
||||
@@ -80,11 +132,10 @@ function seedFor(colors: DesktopThemeColors, seed: string): string {
|
||||
* Carry a light-mode seed across to dark by the theme's OWN lightness offset.
|
||||
*
|
||||
* A theme that ships both palettes has already answered "how much lighter does
|
||||
* this accent get in dark mode" — nous's greens are OKLCH L 0.471 → 0.632, the
|
||||
* same hue and chroma 0.16 apart. Reapplying that delta means a picked color
|
||||
* lands in dark exactly where the author would have put it, and it makes the
|
||||
* round trip exact: retinting with the theme's own accent reproduces both
|
||||
* palettes byte-for-byte.
|
||||
* this accent get in dark mode" — nous's blues are OKLCH L 0.528 → 0.638 at the
|
||||
* same hue. Reapplying that delta means a picked color lands in dark exactly
|
||||
* where the author would have put it, and it makes the round trip exact:
|
||||
* retinting with the theme's own accent reproduces both palettes byte-for-byte.
|
||||
*
|
||||
* Falling back to a bare AA clamp (what this did first) technically passed
|
||||
* contrast but ignored the author's intent — GitHub green came back as
|
||||
|
||||
Reference in New Issue
Block a user