port bezel theme system into the theme crate

This commit is contained in:
2026-10-09 08:42:54 +07:00
parent 22f57def7d
commit 90377c8c76
14 changed files with 2121 additions and 566 deletions
+181
View File
@@ -0,0 +1,181 @@
//! The two concrete palettes: dark and light. Ported from bezel
//! (`crates/theme/src/theme/palettes.rs`, MIT License, Copyright (c) 2026
//! bezel contributors).
//!
//! Light is designed, not inverted — mirroring lightness reverses surface
//! order, elevation and accent contrast. Each light text token lands within
//! ~0.5 of its dark counterpart's ratio; `tests/contrast.rs` asserts it.
use gpui::{hsla, rgb};
use crate::paint::{band_for, hairline_for};
use crate::syntax::SyntaxPalette;
use crate::{Ink, TextInk, ThemeColors, ThemeMode, color};
/// Build the dark palette. The surface tones are sampled from bezel's
/// reference screenshots: main panel `#060606`, shell/sidebar `#0d0d0d`.
pub(crate) fn dark() -> ThemeColors {
let mut colors = ThemeColors {
// ---- neutral surfaces ----
bg: color::grey(6), // main panel — #060606
surface: color::grey(13), // shell / sidebar — #0d0d0d
surface_raised: color::neutral(0.235),
surface_card: color::grey(0x0e),
surface_dialog: color::grey(0x10),
surface_overlay: color::grey(0x16),
// The reference app's `--color-hover`, pure ink: white at 8%.
element_hover: hsla(0.0, 0.0, 1.0, 0.08),
// `--color-active`, a rung above the hover: white at 12%.
element_active: hsla(0.0, 0.0, 1.0, 0.12),
// ---- hairlines ----
border_faint: hairline_for(ThemeMode::Dark, 0.06),
border: hairline_for(ThemeMode::Dark, 0.08),
border_strong: hairline_for(ThemeMode::Dark, 0.14),
// ---- text ----
text: TextInk::color(ThemeMode::Dark, Ink::APPKIT.dark.text),
text_muted: TextInk::color(ThemeMode::Dark, Ink::APPKIT.dark.muted),
text_faint: TextInk::color(ThemeMode::Dark, Ink::APPKIT.dark.faint),
text_dim: color::grey(0x98),
// ---- high-contrast solid ----
solid: color::neutral(0.922),
on_solid: color::grey(0x0e),
// ---- accents, neutral by default ----
accent: color::neutral(0.673),
accent_strong: color::neutral(0.922),
on_accent: color::grey(0x0e),
// ---- semantic ----
danger: color::oklch(0.704, 0.191, 22.216), // red-400
danger_muted: color::oklch(0.808, 0.114, 19.571), // red-300
danger_strong: color::oklch(0.58, 0.16, 25.0),
warning: color::oklch(0.828, 0.189, 84.429), // amber-400
warning_muted: color::oklch(0.924, 0.12, 95.746), // amber-200
success: color::oklch(0.765, 0.177, 163.223), // emerald-400
success_muted: color::oklch(0.845, 0.143, 164.978), // emerald-300
busy: color::oklch(0.718, 0.202, 349.761), // pink-400
// ---- components ----
surface_raised_hover: color::neutral(0.29),
band: band_for(ThemeMode::Dark),
input_bg: hsla(0.0, 0.0, 1.0, 0.03),
selection: rgb(0x3f638b).into(),
cursor: color::neutral(0.94),
caret: color::neutral(0.673),
ring: hairline_for(ThemeMode::Dark, 0.35),
drop_line: hairline_for(ThemeMode::Dark, 0.35),
drop_target: hsla(0.0, 0.0, 1.0, 0.10),
// ---- code & diff ----
code_text: color::neutral(0.94),
code_wash: hsla(0.0, 0.0, 1.0, 0.08),
syntax: SyntaxPalette::dark(
color::neutral(0.922),
color::neutral(0.60),
color::oklch(0.704, 0.191, 22.216),
),
diff_add: color::oklch(0.765, 0.177, 163.223), // emerald-400
diff_del: color::oklch(0.704, 0.191, 22.216), // red-400
diff_hunk_bg: hsla(0.6, 0.35, 0.6, 0.05),
..ThemeColors::legacy_default()
};
colors.sync_legacy(ThemeMode::Dark);
colors
}
/// Build the light palette. Neutrals are the same oklch scale read from the
/// other end, but the *roles* are reassigned rather than mirrored: content
/// plane white, chrome grey, raised surfaces white-plus-shadow. Text tones
/// reproduce the dark theme's contrast ratios, and accents drop from the 400
/// to the 600 step at identical hue so they clear WCAG AA on white.
pub(crate) fn light() -> ThemeColors {
let mut colors = ThemeColors {
// ---- neutral surfaces ----
bg: color::grey(0xff), // main panel — clean white
// Deeper than ~neutral-100 looks on paper: the content card is pure
// white and sits *inside* this surface, so too small a step leaves the
// whole window one flat sheet with a hairline drawn on it.
surface: color::neutral(0.968),
// A real grey, NOT white: this is the opaque-plate tone, and those sit
// directly on the white content plane with no border or shadow to save
// them.
surface_raised: color::neutral(0.940),
surface_card: color::grey(0xff),
surface_dialog: color::grey(0xff),
surface_overlay: color::grey(0xff),
// The same token in light: black at 4%.
element_hover: hsla(0.0, 0.0, 0.0, 0.04),
// The same rung in light: black at 6%.
element_active: hsla(0.0, 0.0, 0.0, 0.06),
// ---- hairlines ----
border_faint: hairline_for(ThemeMode::Light, 0.06),
border: hairline_for(ThemeMode::Light, 0.08),
border_strong: hairline_for(ThemeMode::Light, 0.14),
// ---- text ----
text: TextInk::color(ThemeMode::Light, Ink::APPKIT.light.text),
text_muted: TextInk::color(ThemeMode::Light, Ink::APPKIT.light.muted),
text_faint: TextInk::color(ThemeMode::Light, Ink::APPKIT.light.faint),
text_dim: color::neutral(0.50),
// ---- high-contrast solid ----
solid: color::neutral(0.205),
on_solid: color::neutral(0.985),
// ---- accents, neutral by default ----
accent: color::neutral(0.511),
accent_strong: color::neutral(0.205),
on_accent: color::neutral(0.985),
// ---- semantic ----
danger: color::oklch(0.577, 0.245, 27.325), // red-600
danger_muted: color::oklch(0.505, 0.213, 27.518), // red-700
danger_strong: color::oklch(0.51, 0.20, 25.0),
warning: color::oklch(0.555, 0.163, 48.998), // amber-700 — carries 12px text
warning_muted: color::oklch(0.473, 0.137, 46.201), // amber-800
success: color::oklch(0.596, 0.145, 163.225), // emerald-600
success_muted: color::oklch(0.508, 0.118, 165.612), // emerald-700
busy: color::oklch(0.592, 0.249, 0.584), // pink-600
// ---- components ----
// Opaque pills darken on hover here rather than brighten — same
// "brighten the plate, don't wash it out" rule, read the other way.
surface_raised_hover: color::neutral(0.900),
band: band_for(ThemeMode::Light),
input_bg: color::grey(0xff),
selection: rgb(0xb3d7ff).into(),
cursor: color::neutral(0.205),
caret: color::neutral(0.511),
ring: hairline_for(ThemeMode::Light, 0.35),
drop_line: hairline_for(ThemeMode::Light, 0.35),
drop_target: hsla(0.0, 0.0, 0.0, 0.06),
// ---- code & diff ----
code_text: color::neutral(0.18),
code_wash: hsla(0.0, 0.0, 0.0, 0.06),
syntax: SyntaxPalette::light(
color::neutral(0.25),
color::neutral(0.48),
color::oklch(0.505, 0.213, 27.518),
),
diff_add: color::oklch(0.596, 0.145, 163.225), // emerald-600
diff_del: color::oklch(0.577, 0.245, 27.325), // red-600
diff_hunk_bg: hsla(0.6, 0.35, 0.35, 0.07),
..ThemeColors::legacy_default()
};
colors.sync_legacy(ThemeMode::Light);
colors
}
pub(crate) fn for_appearance(appearance: ThemeMode) -> ThemeColors {
match appearance {
ThemeMode::Dark => dark(),
ThemeMode::Light => light(),
}
}