针对 AI 流式输出长内容时应用卡死问题,实施 12 项性能优化: 渲染层优化(F1/F3/F7): - F1: React.memo 包裹 MessageItem/AssistantMessage,跳过历史消息重渲染 - F3: 流式时用纯文本渲染,避免 ReactMarkdown 全量重解析 O(n²) - F7: useMemo 缓存 ReactMarkdown 元素,非流式时复用实例 滚动与布局(F2/F4/F10/F12): - F2: 滚动节流 rAF + 100ms throttle + trailing 兜底,避免高频布局 - F4: CSS content-visibility 准虚拟滚动,跳过不可见区域布局 - F10: CSS contain 隔离 markdown 布局计算 - F12: 滚动容器 transform: translateZ(0) GPU 加速 状态与 IPC 批处理(F5/F8/F9): - F5: 渲染进程 text_delta rAF 批处理,合并多次 store 写入 - F8: 主进程 text_delta 32ms 节流合并,降低 IPC 频率 - F9: reasoning_delta traceSteps thought 走 rAF 批处理 代码清理(F11): - F11: 移除 rehypeRaw,节省 raw HTML 解析开销 + 防 AI 输出注入 验证:tsc --noEmit 通过,flush 逻辑在 done/error/cleanup 三处正确执行。
282 lines
7.8 KiB
CSS
282 lines
7.8 KiB
CSS
@import "tailwindcss";
|
|
@import "highlight.js/styles/github-dark.css";
|
|
|
|
/* ===== MetonaAI Desktop — 全局样式 ===== */
|
|
|
|
/* CSS 变量 — 暗色主题(默认) */
|
|
:root,
|
|
:root[data-theme="dark"] {
|
|
color-scheme: dark;
|
|
--bg-primary: #0f1117;
|
|
--bg-secondary: #1a1d27;
|
|
--bg-tertiary: #252836;
|
|
--bg-hover: rgba(99, 102, 241, 0.06);
|
|
--bg-card: #1a1d27;
|
|
--text-primary: #e1e4ed;
|
|
--text-secondary: #64748b;
|
|
--text-dim: #8b8fa7;
|
|
--border-color: #2a2d3a;
|
|
--accent: #818cf8;
|
|
--accent-soft: rgba(99, 102, 241, 0.15);
|
|
--green: #34d399;
|
|
--orange: #fb923c;
|
|
--red: #f87171;
|
|
--amber: #fbbf24;
|
|
--cyan: #22d3ee;
|
|
--purple: #a855f7;
|
|
--pink: #f472b6;
|
|
--background: #0f1117;
|
|
--foreground: #e1e4ed;
|
|
--primary: #818cf8;
|
|
--primary-foreground: #0f1117;
|
|
--secondary: #252836;
|
|
--secondary-foreground: #e1e4ed;
|
|
--muted: #252836;
|
|
--muted-foreground: #8b8fa7;
|
|
--destructive: #f87171;
|
|
--destructive-foreground: #e1e4ed;
|
|
--border: #2a2d3a;
|
|
--input: #2a2d3a;
|
|
--ring: #818cf8;
|
|
--radius: 0.625rem;
|
|
}
|
|
|
|
/* 亮色主题 */
|
|
:root[data-theme="light"] {
|
|
color-scheme: light;
|
|
--bg-primary: #ffffff;
|
|
--bg-secondary: #f8fafc;
|
|
--bg-tertiary: #f1f5f9;
|
|
--bg-hover: rgba(99, 102, 241, 0.04);
|
|
--bg-card: #f8fafc;
|
|
--text-primary: #0f172a;
|
|
--text-secondary: #334155;
|
|
--text-dim: #64748b;
|
|
--border-color: #e2e8f0;
|
|
--accent: #6366f1;
|
|
--accent-soft: rgba(99, 102, 241, 0.1);
|
|
--green: #059669;
|
|
--orange: #ea580c;
|
|
--red: #dc2626;
|
|
--amber: #d97706;
|
|
--cyan: #0891b2;
|
|
--purple: #9333ea;
|
|
--pink: #db2777;
|
|
--background: #ffffff;
|
|
--foreground: #0f172a;
|
|
--primary: #6366f1;
|
|
--primary-foreground: #ffffff;
|
|
--secondary: #f1f5f9;
|
|
--secondary-foreground: #0f172a;
|
|
--muted: #f1f5f9;
|
|
--muted-foreground: #64748b;
|
|
--destructive: #dc2626;
|
|
--destructive-foreground: #ffffff;
|
|
--border: #e2e8f0;
|
|
--input: #e2e8f0;
|
|
--ring: #6366f1;
|
|
--radius: 0.625rem;
|
|
}
|
|
|
|
/* Tailwind v4 主题注册 */
|
|
@theme {
|
|
--color-bg-primary: var(--bg-primary);
|
|
--color-bg-secondary: var(--bg-secondary);
|
|
--color-bg-tertiary: var(--bg-tertiary);
|
|
--color-bg-hover: var(--bg-hover);
|
|
--color-text-primary: var(--text-primary);
|
|
--color-text-secondary: var(--text-secondary);
|
|
--color-text-dim: var(--text-dim);
|
|
--color-border-color: var(--border-color);
|
|
--color-green: var(--green);
|
|
--color-orange: var(--orange);
|
|
--color-red: var(--red);
|
|
--color-amber: var(--amber);
|
|
--color-cyan: var(--cyan);
|
|
--color-purple: var(--purple);
|
|
--color-pink: var(--pink);
|
|
--color-background: var(--background);
|
|
--color-foreground: var(--foreground);
|
|
--color-primary: var(--primary);
|
|
--color-primary-foreground: var(--primary-foreground);
|
|
--color-secondary: var(--secondary);
|
|
--color-secondary-foreground: var(--secondary-foreground);
|
|
--color-muted: var(--muted);
|
|
--color-muted-foreground: var(--muted-foreground);
|
|
--color-destructive: var(--destructive);
|
|
--color-destructive-foreground: var(--destructive-foreground);
|
|
--color-border: var(--border);
|
|
--color-input: var(--input);
|
|
--color-ring: var(--ring);
|
|
--radius: var(--radius);
|
|
}
|
|
|
|
/* ===== 全局基础样式 ===== */
|
|
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
html, body, #root { width: 100%; height: 100%; overflow: hidden; }
|
|
body {
|
|
background: var(--bg-primary);
|
|
color: var(--text-primary);
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
|
-webkit-font-smoothing: antialiased;
|
|
}
|
|
|
|
/* ===== 滚动条样式 ===== */
|
|
|
|
::-webkit-scrollbar { width: 6px; height: 6px; }
|
|
::-webkit-scrollbar-track { background: transparent; }
|
|
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
|
|
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
|
|
|
|
/* ===== 代码字体 ===== */
|
|
|
|
code, pre, .font-mono { font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace; }
|
|
|
|
/* ===== 选择文本颜色 ===== */
|
|
::selection { background: rgba(99, 102, 241, 0.15); }
|
|
|
|
/* ===== 焦点样式 ===== */
|
|
:focus-visible { outline: 2px solid #818cf8; outline-offset: 2px; }
|
|
|
|
/* ===== 动画 Keyframes ===== */
|
|
|
|
@keyframes fadeInUp {
|
|
from { opacity: 0; transform: translateY(10px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
|
|
@keyframes pulse {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0.5; }
|
|
}
|
|
|
|
@keyframes spin {
|
|
from { transform: rotate(0deg); }
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
|
|
@keyframes shimmer {
|
|
0% { background-position: -200% 0; }
|
|
100% { background-position: 200% 0; }
|
|
}
|
|
|
|
@keyframes blink {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0; }
|
|
}
|
|
|
|
@keyframes slideUp {
|
|
from { opacity: 0; transform: translateY(20px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; }
|
|
to { opacity: 1; }
|
|
}
|
|
|
|
@keyframes scaleIn {
|
|
from { opacity: 0; transform: scale(0.95); }
|
|
to { opacity: 1; transform: scale(1); }
|
|
}
|
|
|
|
/* ===== Markdown Prose 样式 ===== */
|
|
|
|
.prose-metona {
|
|
color: inherit;
|
|
line-height: 1.7;
|
|
font-size: 14px;
|
|
/* F10: CSS containment 隔离布局计算
|
|
contain: layout style 隔离 markdown 渲染区域的布局和样式计算,
|
|
避免 reflow 扩散到外部容器。不含 paint 以避免裁剪代码块横向滚动溢出。 */
|
|
contain: layout style;
|
|
}
|
|
|
|
.prose-metona h1,
|
|
.prose-metona h2,
|
|
.prose-metona h3,
|
|
.prose-metona h4 {
|
|
font-weight: 600;
|
|
margin-top: 1.5em;
|
|
margin-bottom: 0.5em;
|
|
}
|
|
|
|
.prose-metona h1 { font-size: 1.5em; }
|
|
.prose-metona h2 { font-size: 1.25em; }
|
|
.prose-metona h3 { font-size: 1.125em; }
|
|
|
|
.prose-metona p { margin-bottom: 0.75em; }
|
|
|
|
.prose-metona a { color: #818cf8; text-decoration: none; }
|
|
.prose-metona a:hover { text-decoration: underline; }
|
|
|
|
.prose-metona code {
|
|
color: #22d3ee;
|
|
background: rgba(34, 211, 238, 0.1);
|
|
padding: 1px 5px;
|
|
border-radius: 3px;
|
|
font-size: 0.875em;
|
|
}
|
|
|
|
.prose-metona pre {
|
|
background: var(--bg-tertiary);
|
|
border: 1px solid var(--border-color);
|
|
border-radius: 8px;
|
|
padding: 16px;
|
|
overflow-x: auto;
|
|
margin-bottom: 1em;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.prose-metona pre code {
|
|
color: var(--text-primary);
|
|
background: transparent;
|
|
padding: 0;
|
|
font-size: 13px;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
/* highlight.js 语法高亮覆盖 — 浅色关键字/字符串/数字 */
|
|
.prose-metona .hljs-keyword { color: #cba6f7; }
|
|
.prose-metona .hljs-string { color: #a6e3a1; }
|
|
.prose-metona .hljs-number { color: #fab387; }
|
|
.prose-metona .hljs-comment { color: #6c7086; font-style: italic; }
|
|
.prose-metona .hljs-function { color: #89b4fa; }
|
|
.prose-metona .hljs-title { color: #89b4fa; }
|
|
.prose-metona .hljs-params { color: #f9e2af; }
|
|
.prose-metona .hljs-built_in { color: #f38ba8; }
|
|
.prose-metona .hljs-type { color: #f9e2af; }
|
|
.prose-metona .hljs-literal { color: #fab387; }
|
|
.prose-metona .hljs-attr { color: #89b4fa; }
|
|
.prose-metona .hljs-selector-class { color: #a6e3a1; }
|
|
.prose-metona .hljs-selector-tag { color: #cba6f7; }
|
|
.prose-metona .hljs-variable { color: #cdd6f4; }
|
|
|
|
.prose-metona blockquote {
|
|
border-left: 3px solid #818cf8;
|
|
padding-left: 16px;
|
|
color: #64748b;
|
|
margin-bottom: 0.75em;
|
|
}
|
|
|
|
.prose-metona ul, .prose-metona ol { padding-left: 1.5em; margin-bottom: 0.75em; }
|
|
.prose-metona li { margin-bottom: 0.25em; }
|
|
|
|
.prose-metona table { width: 100%; border-collapse: collapse; margin-bottom: 1em; font-size: 13px; }
|
|
.prose-metona th { text-align: left; padding: 8px 12px; background: var(--bg-tertiary); border-bottom: 1px solid var(--border-color); color: var(--text-primary); font-weight: 600; }
|
|
.prose-metona td { padding: 8px 12px; border-bottom: 1px solid var(--border-color); color: var(--text-primary); }
|
|
|
|
.prose-metona hr { border: none; height: 1px; background: #2a2d3a; margin: 1.5em 0; }
|
|
.prose-metona img { max-width: 100%; border-radius: 8px; }
|
|
|
|
/* ===== 动效降级 ===== */
|
|
|
|
@media (prefers-reduced-motion: reduce) {
|
|
*, *::before, *::after {
|
|
animation-duration: 0.01ms !important;
|
|
animation-iteration-count: 1 !important;
|
|
transition-duration: 0.01ms !important;
|
|
}
|
|
}
|