feat(ui): 加暗色主题,浅/深两态手动切换
style.css 里 204 处硬编码颜色(92 种)先收敛成 88 个语义变量,亮色值原样 保留——亮色主题视觉一点没变。暗色只写一块 :root[data-theme="dark"] 覆盖 这些变量,渲染规则一行没动,不会出现「调一处崩另一处」。 切换入口放文件树头部最右组(Finder 前面),太阳/月亮两态循环,存 localStorage,默认浅色;head 里一段内联脚本先落 data-theme,避免刷新时 先白一下。 配套:Prism token 一套 GitHub dark 配色、Git diff 的加减底色与行号分隔线、 color-scheme: dark(原生滚动条/输入框跟着转暗)、meta theme-color 同步。 .input-shell 原来写的是 rgba(0,0,0,0.1) 边框,黑底上等于没画,暗色下换成 #3d444d;工具卡的卡片底、命令区、文字原来是同一个黄褐色,分层为 #332713 / #241c0a / #e3b341,结果文字改浅灰 #d7cfc0,一眼能分出层次。
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
const SVG_EYE = '<svg class="ic sm" viewBox="0 0 24 24"><use href="#i-eye-sm"/></svg>';
|
||||
const SVG_DL = '<svg viewBox="0 0 24 24"><use href="#i-download"/></svg>';
|
||||
const SVG_DEL = '<svg viewBox="0 0 24 24"><use href="#i-trash"/></svg>';
|
||||
const SVG_THEME = '<svg class="ic sm" viewBox="0 0 24 24"><use href="#i-theme-light"/></svg>' +
|
||||
'<svg class="ic sm hidden" viewBox="0 0 24 24"><use href="#i-theme-dark"/></svg>';
|
||||
const SVG_REVEAL_SM = '<svg viewBox="0 0 24 24"><use href="#i-external-b"/></svg>';
|
||||
|
||||
let localCapable = false; // local 启动器:才显示「在 Finder/终端中打开」
|
||||
@@ -394,6 +396,35 @@
|
||||
}
|
||||
|
||||
// local 能力探测结果回来后才把「在 Finder/终端中打开」露出来(服务器形态永远隐藏)
|
||||
// ---------- 主题(auto / light / dark 三态循环)----------
|
||||
// 色板全在 style.css 的变量里,这里只负责落 data-theme 与两态图标。
|
||||
const THEME_ORDER = ['light', 'dark'];
|
||||
const THEME_LABEL = ['主题:浅色', '主题:深色'];
|
||||
function themeMode() { return document.documentElement.getAttribute('data-theme-mode') === 'dark' ? 'dark' : 'light'; }
|
||||
function applyTheme(mode) {
|
||||
const m = mode === 'dark' ? 'dark' : 'light';
|
||||
document.documentElement.setAttribute('data-theme', m);
|
||||
document.documentElement.setAttribute('data-theme-mode', m);
|
||||
try { localStorage.setItem('agent-theme', m); } catch (_) {}
|
||||
const meta = document.querySelector('meta[name="theme-color"]');
|
||||
if (meta) meta.setAttribute('content', m === 'dark' ? '#0d1117' : '#3964FE');
|
||||
syncThemeBtn();
|
||||
}
|
||||
function cycleTheme() {
|
||||
applyTheme(themeMode() === 'dark' ? 'light' : 'dark');
|
||||
}
|
||||
function syncThemeBtn() {
|
||||
const btn = $('tree-theme');
|
||||
if (!btn) return;
|
||||
const i = themeMode() === 'dark' ? 1 : 0;
|
||||
btn.title = THEME_LABEL[i];
|
||||
btn.setAttribute('aria-label', THEME_LABEL[i]);
|
||||
btn.querySelectorAll('svg').forEach(function (s, k) { s.classList.toggle('hidden', k !== i); });
|
||||
}
|
||||
window.applyTheme = applyTheme;
|
||||
window.cycleTheme = cycleTheme;
|
||||
window.syncThemeBtn = syncThemeBtn;
|
||||
|
||||
function syncLocalButtons() {
|
||||
const rv = $('tree-reveal'), tm = $('tree-terminal');
|
||||
if (rv) rv.classList.toggle('hidden', !localCapable);
|
||||
@@ -424,6 +455,7 @@
|
||||
'<button class="icon-btn" type="button" id="tree-vcs" title="Git 改动与历史" aria-label="Git 改动与历史">' + SVG_VCS + '</button>' +
|
||||
'</span>' +
|
||||
'<span class="pv-actions tree-actions-ext">' +
|
||||
'<button class="icon-btn" type="button" id="tree-theme" title="主题:浅色" aria-label="切换主题">' + SVG_THEME + '</button>' +
|
||||
'<button class="icon-btn hidden" type="button" id="tree-reveal" title="在 Finder 中打开" aria-label="在 Finder 中打开">' + SVG_REVEAL + '</button>' +
|
||||
'<button class="icon-btn hidden" type="button" id="tree-terminal" title="在终端中打开" aria-label="在终端中打开">' + SVG_TERM + '</button>' +
|
||||
'</span>';
|
||||
@@ -445,6 +477,9 @@
|
||||
box.appendChild(body);
|
||||
box.appendChild(foot);
|
||||
|
||||
head.querySelector('#tree-theme').addEventListener('click', function () {
|
||||
if (typeof cycleTheme === 'function') cycleTheme();
|
||||
});
|
||||
head.querySelector('#tree-hidden').addEventListener('click', function () {
|
||||
showHidden = !showHidden;
|
||||
invalidate(false);
|
||||
@@ -466,6 +501,7 @@
|
||||
body.addEventListener('click', onTreeClick);
|
||||
|
||||
syncLocalButtons();
|
||||
syncThemeBtn();
|
||||
}
|
||||
|
||||
// 侧栏底部「文件树」图标 → 切到这个面板(由 files.js 的 setDrawerPane 调用)。
|
||||
|
||||
Reference in New Issue
Block a user