AnyBot/src/theme.rs

230 lines
10 KiB
Rust
Raw Normal View History

// Colours. Light values come from the original's stylesheet
// (index CSS, ":root,.sand-1vbcnu7" block). Dark values come from the renderer's appearance primitives.
use eframe::egui::Color32;
#[derive(Clone, Copy)]
pub struct Palette {
pub pane: Color32,
pub sidebar: Color32,
pub elevated: Color32,
pub hover: Color32,
pub active: Color32,
pub primary: Color32,
pub text: Color32,
pub text2: Color32,
pub text3: Color32,
pub on_primary: Color32,
pub bubble_user: Color32,
pub border: Color32,
pub focus: Color32,
pub accent: Color32,
pub danger: Color32,
/// 需要你: the one colour for what waits for the person (a request, a newer build).
pub attention: Color32,
/// Behind a request's card.
pub attention_bg: Color32,
/// The quiet fill behind secondary blocks: filled inputs, list trays, segmented tracks
/// (the shadcn 'muted' layer — it is what makes groups read as groups).
pub muted: Color32,
圖表與數字卡改成閱讀向排版(Notion 風):色板、直接標數、排序、手機原生圖 研究依據(2026-10 Supernova 11 設計系統調查、IBM Carbon 資料視覺化規範、 Atlassian chart tokens、shadcn/ui chart、Tufte data-ink、EEA/Sheffield 準則): 預設單色、分類色≤6固定序、只留淡水平參考線、直接標數取代圖例與座標軸、 長條按大小排序(自有順序的標籤不排)、顏色只給意義(漲綠跌紅附箭頭)。 - theme.rs:新增 chart_cat 六色(明暗各一組,低飽和藍紫青橙粉灰)、grid、up - 桌面圖表卡:網格只剩淡水平線;單系列長條把數字標在條上、不畫 y 軸; 長條自動由大到小排序(月/季/年/W1/Q1/數字等自然序標籤不排); 多條線在線尾標系列名(取代圖例);stats 數字卡大字、↑/+綠 ↓/−紅 - Mermaid:白底卡節點、細灰連線、同套六色圓餅(house_theme) - 手機:```chart 原本掉成純文字——現在畫原生 SVG,規則與色板和桌面同款; stats 卡改白卡描邊、大字、漲綠跌紅;代幣進 :root/dark - write_page 說明:排版由渲染器接手,Bot 專心把圖標題寫成結論 - 功能地圖 pages.md/FEATURES.md 同步;layout_audit 新增「頁面(圖表)」場景 已驗證: cargo test 501 全綠;layout_audit 全綠(新場景含長條排序/多線/圓餅/stats, 664/1000/1440 三寬度無出界無疊字);手機 chartMd 用 node 跑 8 個案例(排序、 自然序不排、線尾標名、圓餅佔比、tooltip、千分位、壞輸入回空)全過; ANYBOT_SHOT=page 截圖肉眼確認 未驗證: 手機端只在 node 驗證圖表產生器,未實機開網頁看 SVG 渲染; Mermaid 新主題未逐圖型(gantt/gitGraph)目視;深色模式截圖未拍
2026-11-16 08:43:55 +00:00
/// Chart series colours, in fixed order (Atlassian/Carbon practice: a protocol, not a
/// preference — the same hue always means the same rank of series; max six categories).
/// Chosen low-saturation so many series never fight, with light/dark variants.
pub chart_cat: [Color32; 6],
/// The one faint gridline (value axis only; the category axis never gets one).
pub grid: Color32,
/// Up / good (charts, stat tiles). Down and bad is `danger`.
pub up: Color32,
}
const fn hexa(r: u8, g: u8, b: u8, a: u8) -> Color32 {
Color32::from_rgba_unmultiplied_const(r, g, b, a)
}
pub const LIGHT: Palette = Palette {
pane: hexa(0xff, 0xff, 0xff, 0xff),
sidebar: hexa(0xf5, 0xf5, 0xf3, 0xff),
elevated: hexa(0xff, 0xff, 0xff, 0xff),
hover: hexa(0x1c, 0x1c, 0x1c, 0x0f),
active: hexa(0x1c, 0x1c, 0x1c, 0x14),
primary: hexa(0x1c, 0x1c, 0x1c, 0xff),
text: hexa(0x1c, 0x1c, 0x1c, 0xff),
text2: hexa(0x1c, 0x1c, 0x1c, 0xad),
text3: hexa(0x1c, 0x1c, 0x1c, 0x8f),
on_primary: hexa(0xff, 0xff, 0xff, 0xff),
bubble_user: hexa(0x1c, 0x1c, 0x1c, 0xff),
border: hexa(0x1c, 0x1c, 0x1c, 0x1f),
focus: hexa(0x1e, 0x86, 0xfc, 0xff),
accent: hexa(0x16, 0x80, 0xf3, 0xff),
danger: hexa(0xcd, 0x28, 0x34, 0xff),
attention: hexa(0xff, 0xc8, 0x3d, 0xff),
attention_bg: hexa(0xff, 0xf6, 0xd6, 0xff),
muted: hexa(0xf1, 0xf1, 0xee, 0xff),
圖表與數字卡改成閱讀向排版(Notion 風):色板、直接標數、排序、手機原生圖 研究依據(2026-10 Supernova 11 設計系統調查、IBM Carbon 資料視覺化規範、 Atlassian chart tokens、shadcn/ui chart、Tufte data-ink、EEA/Sheffield 準則): 預設單色、分類色≤6固定序、只留淡水平參考線、直接標數取代圖例與座標軸、 長條按大小排序(自有順序的標籤不排)、顏色只給意義(漲綠跌紅附箭頭)。 - theme.rs:新增 chart_cat 六色(明暗各一組,低飽和藍紫青橙粉灰)、grid、up - 桌面圖表卡:網格只剩淡水平線;單系列長條把數字標在條上、不畫 y 軸; 長條自動由大到小排序(月/季/年/W1/Q1/數字等自然序標籤不排); 多條線在線尾標系列名(取代圖例);stats 數字卡大字、↑/+綠 ↓/−紅 - Mermaid:白底卡節點、細灰連線、同套六色圓餅(house_theme) - 手機:```chart 原本掉成純文字——現在畫原生 SVG,規則與色板和桌面同款; stats 卡改白卡描邊、大字、漲綠跌紅;代幣進 :root/dark - write_page 說明:排版由渲染器接手,Bot 專心把圖標題寫成結論 - 功能地圖 pages.md/FEATURES.md 同步;layout_audit 新增「頁面(圖表)」場景 已驗證: cargo test 501 全綠;layout_audit 全綠(新場景含長條排序/多線/圓餅/stats, 664/1000/1440 三寬度無出界無疊字);手機 chartMd 用 node 跑 8 個案例(排序、 自然序不排、線尾標名、圓餅佔比、tooltip、千分位、壞輸入回空)全過; ANYBOT_SHOT=page 截圖肉眼確認 未驗證: 手機端只在 node 驗證圖表產生器,未實機開網頁看 SVG 渲染; Mermaid 新主題未逐圖型(gantt/gitGraph)目視;深色模式截圖未拍
2026-11-16 08:43:55 +00:00
// Notion-ish: blue, purple, teal, orange, pink, slate — all muted, all readable on white.
chart_cat: [
hexa(0x23, 0x83, 0xe2, 0xff),
hexa(0x90, 0x65, 0xb0, 0xff),
hexa(0x0f, 0x7b, 0x6c, 0xff),
hexa(0xd9, 0x73, 0x0d, 0xff),
hexa(0xe0, 0x6b, 0x9e, 0xff),
hexa(0x6e, 0x6c, 0x68, 0xff),
],
grid: hexa(0x1c, 0x1c, 0x1c, 0x12),
up: hexa(0x0f, 0x7b, 0x6c, 0xff),
};
// From the original's renderer (index.eager-common: appearance primitives dark neutral/0..6 and the
// g_ alpha table): pane #1f1f1f, elevated #161616, chrome #121212, sidebar #0e0e0e, ink #f5f5f5,
// primary hover #dbdbdb; translucent tokens are the ink at hover 6%, active 8%, agent bubble 4%,
// user bubble 18%, text 66/54%, border 10%. Accent blue/0 #1884fc, danger red/0 #fc2c3e.
// Measured from the original's dark window: chat rgb 19, sidebar 16, bubbles/cards 31–33.
pub const DARK: Palette = Palette {
pane: hexa(0x13, 0x13, 0x13, 0xff),
sidebar: hexa(0x10, 0x10, 0x10, 0xff),
elevated: hexa(0x1f, 0x1f, 0x1f, 0xff),
hover: hexa(0xf5, 0xf5, 0xf5, 0x0f),
active: hexa(0xf5, 0xf5, 0xf5, 0x14),
primary: hexa(0xf5, 0xf5, 0xf5, 0xff),
text: hexa(0xf5, 0xf5, 0xf5, 0xff),
text2: hexa(0xf5, 0xf5, 0xf5, 0xa8),
text3: hexa(0xf5, 0xf5, 0xf5, 0x8a),
on_primary: hexa(0x1f, 0x1f, 0x1f, 0xff),
bubble_user: hexa(0xf5, 0xf5, 0xf5, 0x2e),
border: hexa(0xf5, 0xf5, 0xf5, 0x1a),
focus: hexa(0x18, 0x84, 0xfc, 0xff),
accent: hexa(0x18, 0x84, 0xfc, 0xff),
danger: hexa(0xfc, 0x2c, 0x3e, 0xff),
attention: hexa(0xff, 0xc8, 0x3d, 0xff),
attention_bg: hexa(0x3a, 0x32, 0x12, 0xff),
muted: hexa(0x1d, 0x1d, 0x1d, 0xff),
圖表與數字卡改成閱讀向排版(Notion 風):色板、直接標數、排序、手機原生圖 研究依據(2026-10 Supernova 11 設計系統調查、IBM Carbon 資料視覺化規範、 Atlassian chart tokens、shadcn/ui chart、Tufte data-ink、EEA/Sheffield 準則): 預設單色、分類色≤6固定序、只留淡水平參考線、直接標數取代圖例與座標軸、 長條按大小排序(自有順序的標籤不排)、顏色只給意義(漲綠跌紅附箭頭)。 - theme.rs:新增 chart_cat 六色(明暗各一組,低飽和藍紫青橙粉灰)、grid、up - 桌面圖表卡:網格只剩淡水平線;單系列長條把數字標在條上、不畫 y 軸; 長條自動由大到小排序(月/季/年/W1/Q1/數字等自然序標籤不排); 多條線在線尾標系列名(取代圖例);stats 數字卡大字、↑/+綠 ↓/−紅 - Mermaid:白底卡節點、細灰連線、同套六色圓餅(house_theme) - 手機:```chart 原本掉成純文字——現在畫原生 SVG,規則與色板和桌面同款; stats 卡改白卡描邊、大字、漲綠跌紅;代幣進 :root/dark - write_page 說明:排版由渲染器接手,Bot 專心把圖標題寫成結論 - 功能地圖 pages.md/FEATURES.md 同步;layout_audit 新增「頁面(圖表)」場景 已驗證: cargo test 501 全綠;layout_audit 全綠(新場景含長條排序/多線/圓餅/stats, 664/1000/1440 三寬度無出界無疊字);手機 chartMd 用 node 跑 8 個案例(排序、 自然序不排、線尾標名、圓餅佔比、tooltip、千分位、壞輸入回空)全過; ANYBOT_SHOT=page 截圖肉眼確認 未驗證: 手機端只在 node 驗證圖表產生器,未實機開網頁看 SVG 渲染; Mermaid 新主題未逐圖型(gantt/gitGraph)目視;深色模式截圖未拍
2026-11-16 08:43:55 +00:00
// The same six families, lightened for a dark page (dark-theme palettes must be raised
// in lightness to keep contrast, Carbon's dark set does the same).
chart_cat: [
hexa(0x52, 0x9c, 0xca, 0xff),
hexa(0xb4, 0x93, 0xe5, 0xff),
hexa(0x4d, 0xab, 0x9a, 0xff),
hexa(0xe3, 0xa0, 0x62, 0xff),
hexa(0xf2, 0x91, 0xc0, 0xff),
hexa(0xa0, 0x9e, 0x9a, 0xff),
],
grid: hexa(0xf5, 0xf5, 0xf5, 0x14),
up: hexa(0x4d, 0xab, 0x9a, 0xff),
};
/// A bot's colour as a quiet background (its selected tile, its cards): a little of it over the
/// page — more on a dark page, where a tenth would not show.
pub fn mist(col: Color32, p: Palette) -> Color32 {
let k = if p.pane.r() < 128 { 0.24 } else { 0.10 };
let mix = |a: u8, b: u8| (a as f32 + (b as f32 - a as f32) * k).round() as u8;
Color32::from_rgb(mix(p.pane.r(), col.r()), mix(p.pane.g(), col.g()), mix(p.pane.b(), col.b()))
}
/// Concept themes for screenshots only (`ANYBOT_SHOT_PAL=paper|night|ink|moss`, with
/// `ANYBOT_SHOT_THEME=dark` for the dark one): the shell is generated from three inputs —
/// one ink, one paper, one accent — the Linear way (98 hand-set colours became 3 inputs).
/// Surfaces are the paper stepped toward the ink in equal little steps; text is the ink
/// faded back from full; colour appears only as the accent and as meaning (danger, up).
/// When a direction is chosen it becomes LIGHT/DARK proper; this stays as the generator seed.
pub fn shot_palette(name: &str, dark: bool) -> Option<Palette> {
// (ink, paper, accent, danger, up) — the three inputs, plus the two meanings.
let (ink, paper, accent, danger, up) = match (name, dark) {
// 紙: warm ivory page, near-black warm ink, one clay accent (Claude's register).
("paper", false) => (rgb(0x25, 0x22, 0x1f), rgb(0xfa, 0xf9, 0xf6), rgb(0xc0, 0x62, 0x44), rgb(0xb4, 0x2a, 0x2a), rgb(0x2e, 0x7d, 0x3f)),
("paper", true) => (rgb(0xf2, 0xf0, 0xeb), rgb(0x1e, 0x1d, 0x1b), rgb(0xd8, 0x83, 0x66), rgb(0xe2, 0x6e, 0x6e), rgb(0x6f, 0xb9, 0x7d)),
// 夜: Linear's warm near-black, one desaturated indigo, everything else grey.
("night", false) => (rgb(0x20, 0x21, 0x24), rgb(0xf6, 0xf6, 0xf8), rgb(0x5e, 0x6a, 0xd2), rgb(0xc2, 0x37, 0x37), rgb(0x2c, 0x7a, 0x55)),
("night", true) => (rgb(0xf0, 0xf0, 0xf2), rgb(0x10, 0x11, 0x12), rgb(0x7c, 0x87, 0xe0), rgb(0xe5, 0x73, 0x73), rgb(0x67, 0xb3, 0x8b)),
// 墨: pure monochrome, high contrast — the accent is the ink itself (ChatGPT's rule).
("ink", false) => (rgb(0x0d, 0x0d, 0x0d), rgb(0xf9, 0xf9, 0xf9), rgb(0x0d, 0x0d, 0x0d), rgb(0x9c, 0x22, 0x22), rgb(0x1d, 0x6b, 0x3a)),
("ink", true) => (rgb(0xf7, 0xf7, 0xf7), rgb(0x0a, 0x0a, 0x0a), rgb(0xf7, 0xf7, 0xf7), rgb(0xe0, 0x60, 0x60), rgb(0x6c, 0xb7, 0x84)),
// 苔: a green-grey paper, moss accent — the quiet one with a colour temperature.
("moss", false) => (rgb(0x1f, 0x24, 0x20), rgb(0xf4, 0xf6, 0xf2), rgb(0x4a, 0x7c, 0x59), rgb(0xa9, 0x35, 0x2e), rgb(0x2e, 0x7d, 0x4f)),
("moss", true) => (rgb(0xec, 0xf0, 0xea), rgb(0x15, 0x18, 0x15), rgb(0x7f, 0xaa, 0x8a), rgb(0xdd, 0x6f, 0x66), rgb(0x76, 0xc0, 0x90)),
_ => return None,
};
let (accent, focus) = (accent, accent);
// The ladder: every surface is the paper stepped toward the ink; every text is the ink
// stepped back toward the paper. Equal steps are what makes it read as one system.
let step = |k: f32| mix(paper, ink, k);
let six = |l: f32| [hsl_shift(accent, 0.0, 0.52, l), hsl_shift(accent, 52.0, 0.42, l), hsl_shift(accent, 110.0, 0.40, l), hsl_shift(accent, 190.0, 0.45, l), hsl_shift(accent, 265.0, 0.40, l), hsl_shift(accent, 325.0, 0.12, l)];
let cat = if dark { six(0.62) } else { six(0.48) };
Some(Palette {
pane: paper,
sidebar: step(0.045),
elevated: if dark { step(0.10) } else { rgb(0xff, 0xff, 0xff) },
hover: with(ink, 15),
active: with(ink, 26),
primary: ink,
text: ink,
text2: mix(ink, paper, 0.34),
text3: mix(ink, paper, 0.50),
on_primary: paper,
bubble_user: if dark { with(ink, 46) } else { ink },
border: with(ink, if dark { 26 } else { 20 }),
focus,
accent,
danger,
attention: rgb(0xd9, 0xa4, 0x41),
attention_bg: with(rgb(0xd9, 0xa4, 0x41), if dark { 38 } else { 26 }),
muted: if dark { step(0.10) } else { step(0.035) },
chart_cat: cat,
grid: with(ink, 14),
up,
})
}
const fn rgb(r: u8, g: u8, b: u8) -> Color32 {
Color32::from_rgb(r, g, b)
}
fn with(c: Color32, a: u8) -> Color32 {
Color32::from_rgba_unmultiplied(c.r(), c.g(), c.b(), a)
}
fn mix(a: Color32, b: Color32, t: f32) -> Color32 {
let m = |x: u8, y: u8| (x as f32 + (y as f32 - x as f32) * t).round().clamp(0.0, 255.0) as u8;
Color32::from_rgb(m(a.r(), b.r()), m(a.g(), b.g()), m(a.b(), b.b()))
}
/// The accent turned into the six series colours: hue moved by `dh`, chroma and lightness set
/// to the quiet chart register (low saturation, one lightness step for the whole set).
fn hsl_shift(c: Color32, dh: f32, s: f32, l: f32) -> Color32 {
let (mut h, _, _) = rgb_to_hsl(c);
h = (h + dh).rem_euclid(360.0);
hsl_to_rgb(h, s, l)
}
fn rgb_to_hsl(c: Color32) -> (f32, f32, f32) {
let (r, g, b) = (c.r() as f32 / 255.0, c.g() as f32 / 255.0, c.b() as f32 / 255.0);
let (mx, mn) = (r.max(g).max(b), r.min(g).min(b));
let l = (mx + mn) / 2.0;
let d = mx - mn;
if d < 1e-6 {
return (0.0, 0.0, l);
}
let s = d / (1.0 - (2.0 * l - 1.0).abs());
let h = if mx == r {
60.0 * (((g - b) / d) % 6.0)
} else if mx == g {
60.0 * ((b - r) / d + 2.0)
} else {
60.0 * ((r - g) / d + 4.0)
};
(h.rem_euclid(360.0), s, l)
}
fn hsl_to_rgb(h: f32, s: f32, l: f32) -> Color32 {
let c = (1.0 - (2.0 * l - 1.0).abs()) * s;
let x = c * (1.0 - ((h / 60.0) % 2.0 - 1.0).abs());
let m = l - c / 2.0;
let (r, g, b) = match (h / 60.0).floor() as i32 {
0 => (c, x, 0.0),
1 => (x, c, 0.0),
2 => (0.0, c, x),
3 => (0.0, x, c),
4 => (x, 0.0, c),
_ => (c, 0.0, x),
};
rgb(((r + m) * 255.0).round() as u8, ((g + m) * 255.0).round() as u8, ((b + m) * 255.0).round() as u8)
}