feat(frontend): unify font rendering and add font picker in settings

The UI used hardcoded "PingFang SC" in 50+ components, while the global
font stack in App.vue used a different fallback chain. Outside of mainland
China this caused visibly different fonts in the sidebar, breadcrumbs,
search and agent views compared to settings and document panes.

- Introduce --app-font-family / --app-font-family-mono CSS variables in
  theme.css and route TDesign's --td-font-family through them
- Add a useFont composable that persists the user's choice in localStorage
  and applies it via document.documentElement.style before mount
- Replace hardcoded font-family declarations across the app with the new
  variables (TencentSans logo and the SVG attribute list are preserved)
- Add UI font and monospace font selectors in General Settings with
  i18n strings for en-US, zh-CN, ko-KR and ru-RU

https://claude.ai/code/session_01S1FVPf4jRfWXkTSnpMmMp7
This commit is contained in:
Claude
2026-05-02 08:06:56 +00:00
committed by lyingbug
parent 6c1442aaf9
commit f140c12518
59 changed files with 542 additions and 251 deletions
+99
View File
@@ -0,0 +1,99 @@
import { ref } from 'vue'
export type FontKey =
| 'system'
| 'pingfang'
| 'inter'
| 'helvetica'
| 'segoe'
| 'roboto'
| 'sans-serif'
export type MonoFontKey =
| 'system'
| 'cascadia'
| 'jetbrains'
| 'fira'
| 'monaco'
| 'consolas'
| 'monospace'
const SANS_STORAGE_KEY = 'WeKnora_font_sans'
const MONO_STORAGE_KEY = 'WeKnora_font_mono'
export const SANS_STACKS: Record<FontKey, string> = {
system:
'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif',
pingfang:
'"PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", -apple-system, BlinkMacSystemFont, sans-serif',
inter:
'Inter, "Segoe UI", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif',
helvetica:
'"Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif',
segoe:
'"Segoe UI", Tahoma, Verdana, Arial, "PingFang SC", "Microsoft YaHei", sans-serif',
roboto:
'Roboto, "Segoe UI", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif',
'sans-serif': 'sans-serif',
}
export const MONO_STACKS: Record<MonoFontKey, string> = {
system:
'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
cascadia:
'"Cascadia Code", "Cascadia Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
jetbrains:
'"JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
fira: '"Fira Code", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
monaco: 'Monaco, Menlo, Consolas, "Courier New", monospace',
consolas: 'Consolas, "Courier New", Menlo, Monaco, monospace',
monospace: 'monospace',
}
const DEFAULT_SANS: FontKey = 'system'
const DEFAULT_MONO: MonoFontKey = 'system'
const isFontKey = (v: string | null): v is FontKey =>
!!v && Object.prototype.hasOwnProperty.call(SANS_STACKS, v)
const isMonoFontKey = (v: string | null): v is MonoFontKey =>
!!v && Object.prototype.hasOwnProperty.call(MONO_STACKS, v)
const currentSans = ref<FontKey>(
isFontKey(localStorage.getItem(SANS_STORAGE_KEY))
? (localStorage.getItem(SANS_STORAGE_KEY) as FontKey)
: DEFAULT_SANS,
)
const currentMono = ref<MonoFontKey>(
isMonoFontKey(localStorage.getItem(MONO_STORAGE_KEY))
? (localStorage.getItem(MONO_STORAGE_KEY) as MonoFontKey)
: DEFAULT_MONO,
)
function applyFont(sans: FontKey, mono: MonoFontKey) {
const root = document.documentElement
root.style.setProperty('--app-font-family', SANS_STACKS[sans])
root.style.setProperty('--app-font-family-mono', MONO_STACKS[mono])
}
export function useFont() {
function setSansFont(key: FontKey) {
currentSans.value = key
localStorage.setItem(SANS_STORAGE_KEY, key)
applyFont(currentSans.value, currentMono.value)
}
function setMonoFont(key: MonoFontKey) {
currentMono.value = key
localStorage.setItem(MONO_STORAGE_KEY, key)
applyFont(currentSans.value, currentMono.value)
}
return { currentSans, currentMono, setSansFont, setMonoFont }
}
/** Call once in main.ts to apply persisted font preferences before mount. */
export function initFont() {
applyFont(currentSans.value, currentMono.value)
}