tavern-harness 0.1.32 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/package.json +4 -1
- package/src/App.tsx +1 -1
- package/src/components/CharactersView.tsx +1 -1
- package/src/components/ChatView.tsx +1 -1
- package/src/components/SettingsView.tsx +82 -21
- package/src/components/Sidebar.tsx +26 -27
- package/src/core/autoHideScrollbars.ts +191 -0
- package/src/core/browserPreferences.ts +6 -1
- package/src/core/i18n.ts +27 -3
- package/src/db/database.ts +17 -8
- package/src/generated/changelog.json +110 -1
- package/src/main.tsx +3 -0
- package/src/store/store.ts +13 -12
- package/src/theme/chat.css +70 -53
- package/src/theme/global.css +122 -57
- package/src/theme/theme.ts +96 -43
- package/src/theme/views.css +84 -24
- package/src/types/models.ts +2 -0
- package/vite.config.ts +46 -11
- package/voice-server.mjs +21 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,81 @@
|
|
|
3
3
|
> 本文件由 `scripts/changelog.mjs` 从 `changelog/v*.md` 生成,请勿手动编辑。
|
|
4
4
|
> 版本对比链接见文末;源文件位于仓库 `changelog/` 目录。
|
|
5
5
|
|
|
6
|
+
## [0.2.0] - 2026-11-20
|
|
7
|
+
|
|
8
|
+
### 中文
|
|
9
|
+
|
|
10
|
+
#### 新增
|
|
11
|
+
|
|
12
|
+
- 设置页拆分为「API 配置 / 模型参数 / 通用设置」三个标签页,服务商、超参数和主题不再挤在同一个长页面里
|
|
13
|
+
- 新增「烛光琥珀 / 森野翡翠 / 暮色蔷薇 / 星夜靛蓝」四套配色方案,可在设置中随时切换,浅色与深色模式分别适配
|
|
14
|
+
- 对话标题栏和输入框改为悬浮玻璃卡片:内容从卡片背后滚动,输入框固定在底部;群聊时两者都会避开右侧成员栏
|
|
15
|
+
|
|
16
|
+
#### 改进
|
|
17
|
+
|
|
18
|
+
- 侧边栏与主区域改为各自独立的悬浮卡片,去掉渐变光晕、虚线纹理和多余投影,层级更干净
|
|
19
|
+
- 工具调用与思考卡片改用无边框色块表达状态,减少卡片套卡片的感觉
|
|
20
|
+
- 原生滚动条替换为滚动时出现、静止后淡出的悬浮细条,不再占用内容宽度
|
|
21
|
+
- Markdown 的标题、列表标记、代码块和表格跟随所选配色,并随浅色/深色模式自动调整
|
|
22
|
+
- 侧边栏宽度拖拽手柄更易识别,并支持触屏拖动
|
|
23
|
+
|
|
24
|
+
#### 修复
|
|
25
|
+
|
|
26
|
+
- 修复电脑休眠唤醒后持久化服务尚未就绪时,启动快照只重试一次就放弃、页面可能读不到数据的问题;启动阶段现在最多重试四次
|
|
27
|
+
- 修复设置页服务商名称过长时溢出卡片、挤压「文本服务 / 语音服务」标签的问题,名称过长时改为自动滚动显示
|
|
28
|
+
|
|
29
|
+
### English
|
|
30
|
+
|
|
31
|
+
#### Added
|
|
32
|
+
|
|
33
|
+
- Settings is split into API Configuration, Model Parameters, and General tabs, so providers, hyperparameters, and theme no longer share one long page
|
|
34
|
+
- Four color palettes — Candle Amber, Forest Jade, Twilight Rose, and Starlight Indigo — switchable at any time, each tuned for light and dark modes
|
|
35
|
+
- The conversation header and composer are now floating glass cards: content scrolls behind them, the composer stays pinned to the bottom, and both make room for the member panel in group chats
|
|
36
|
+
|
|
37
|
+
#### Changed
|
|
38
|
+
|
|
39
|
+
- The sidebar and main area are now separate floating cards; gradient glows, dashed textures, and excess shadows are gone for a cleaner hierarchy
|
|
40
|
+
- Tool call and reasoning cards use borderless color blocks to show state instead of nested outlines
|
|
41
|
+
- Native scrollbars are replaced by floating thin thumbs that appear while scrolling and fade when idle, without taking content width
|
|
42
|
+
- Markdown headings, list markers, code blocks, and tables follow the selected palette and adapt to light and dark modes
|
|
43
|
+
- The sidebar resize handle is easier to spot and now supports touch dragging
|
|
44
|
+
|
|
45
|
+
#### Fixed
|
|
46
|
+
|
|
47
|
+
- Fixed the startup snapshot giving up after one retry when the persistence service was still starting after sleep; startup now retries up to four times
|
|
48
|
+
- Fixed long provider names overflowing their cards and squeezing the text/voice service label; overflowing names now scroll automatically
|
|
49
|
+
|
|
50
|
+
#### Internal
|
|
51
|
+
|
|
52
|
+
- Added a global auto-hiding scrollbar module shared by all scroll containers
|
|
53
|
+
- Added test coverage for persistence startup retries
|
|
54
|
+
|
|
55
|
+
## [0.1.33] - 2026-11-18
|
|
56
|
+
|
|
57
|
+
### 中文
|
|
58
|
+
|
|
59
|
+
#### 修复
|
|
60
|
+
|
|
61
|
+
- 修复 0.1.32 的 npm 包遗漏 `voice-server.mjs`、导致本地持久化服务无法启动、对话数据无法加载与保存的问题
|
|
62
|
+
- 持久化与沙箱子进程反复拉起时不再重复注册进程退出监听,消除启动时的 `MaxListenersExceededWarning`
|
|
63
|
+
- 子进程的错误输出会显示在终端,本地服务启动失败时不再静默
|
|
64
|
+
|
|
65
|
+
#### 内部
|
|
66
|
+
|
|
67
|
+
- 新增发布内容校验:`npm pack` / `npm publish` 前会检查 `files` 白名单是否覆盖所有运行时相对导入
|
|
68
|
+
|
|
69
|
+
### English
|
|
70
|
+
|
|
71
|
+
#### Fixed
|
|
72
|
+
|
|
73
|
+
- Fixed the 0.1.32 npm package missing `voice-server.mjs`, which prevented the local persistence service from starting and blocked loading or saving conversations
|
|
74
|
+
- Stopped re-registering process exit listeners whenever the persistence or sandbox child process is relaunched, removing the startup `MaxListenersExceededWarning`
|
|
75
|
+
- Child-process errors now appear in the terminal instead of failing silently
|
|
76
|
+
|
|
77
|
+
#### Internal
|
|
78
|
+
|
|
79
|
+
- Added a publish-content check that verifies the `files` allowlist covers every runtime relative import before `npm pack` / `npm publish`
|
|
80
|
+
|
|
6
81
|
## [0.1.32] - 2026-11-18
|
|
7
82
|
|
|
8
83
|
### 中文
|
|
@@ -956,6 +1031,8 @@
|
|
|
956
1031
|
- Vite + React + Zustand + Dexie stack with browser-side local persistence
|
|
957
1032
|
|
|
958
1033
|
<!-- 链接定义 -->
|
|
1034
|
+
[0.2.0]: https://github.com/Rannichan/Tavern-Harness/compare/v0.1.33...v0.2.0
|
|
1035
|
+
[0.1.33]: https://github.com/Rannichan/Tavern-Harness/compare/v0.1.32...v0.1.33
|
|
959
1036
|
[0.1.32]: https://github.com/Rannichan/Tavern-Harness/compare/v0.1.31...v0.1.32
|
|
960
1037
|
[0.1.31]: https://github.com/Rannichan/Tavern-Harness/compare/v0.1.30...v0.1.31
|
|
961
1038
|
[0.1.30]: https://github.com/Rannichan/Tavern-Harness/compare/v0.1.29...v0.1.30
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tavern-harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Tavern Harness — 酒馆模式下的本地 AI Agent 助手(MyAgent-Android 的 Web 复刻)",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"vite.config.ts",
|
|
16
16
|
"sandbox-server.mjs",
|
|
17
17
|
"persistence-server.mjs",
|
|
18
|
+
"voice-server.mjs",
|
|
18
19
|
"tsconfig.json",
|
|
19
20
|
"README.md",
|
|
20
21
|
"CHANGELOG.md"
|
|
@@ -41,6 +42,8 @@
|
|
|
41
42
|
"changelog:build": "node scripts/changelog.mjs build",
|
|
42
43
|
"changelog:check": "node scripts/changelog.mjs check",
|
|
43
44
|
"changelog:check:release": "node scripts/changelog.mjs check --release",
|
|
45
|
+
"check:package": "node scripts/check-package-files.mjs",
|
|
46
|
+
"prepack": "npm run check:package",
|
|
44
47
|
"prepublishOnly": "npm run build && npm run changelog:check:release"
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
package/src/App.tsx
CHANGED
|
@@ -367,7 +367,7 @@ function SessionHeader({
|
|
|
367
367
|
}, [showMobileActions]);
|
|
368
368
|
|
|
369
369
|
return (
|
|
370
|
-
<div className=
|
|
370
|
+
<div className={`chat-header${session.mode === 'GROUP' ? ' chat-header-group' : ''}`}>
|
|
371
371
|
<SessionVisual mode={session.mode} npcName={npcRef?.name ?? undefined} hue={npcRef?.avatarColorOrdinal ?? 0} imageUrl={npcRef?.avatarDataUrl} members={session.mode === 'GROUP' ? groupMemberAvatars : undefined} size="lg" />
|
|
372
372
|
<div className="tinfo">
|
|
373
373
|
<div className="ttitle">{session.title}</div>
|
|
@@ -108,7 +108,7 @@ export const CharactersView = memo(function CharactersView({ active = true }: {
|
|
|
108
108
|
<h2 className="view-title">{t('workshop.title')}</h2>
|
|
109
109
|
<p className="view-sub">{t('workshop.sub')}</p>
|
|
110
110
|
</div>
|
|
111
|
-
<div className="side-nav" data-hscroll>
|
|
111
|
+
<div className="side-nav view-tabs" data-hscroll>
|
|
112
112
|
<button className={`nav-chip ${tab === 'characters' ? 'active' : ''}`} onClick={() => selectTab('characters')}>
|
|
113
113
|
{t('workshop.tabCharacters')}
|
|
114
114
|
</button>
|
|
@@ -988,7 +988,7 @@ export function ChatInput({ sessionId }: { sessionId: number }) {
|
|
|
988
988
|
};
|
|
989
989
|
|
|
990
990
|
return (
|
|
991
|
-
<div className=
|
|
991
|
+
<div className={`composer${session?.mode === 'GROUP' ? ' composer-group' : ''}`}>
|
|
992
992
|
{attachments.length > 0 && (
|
|
993
993
|
<div className="attach-preview">
|
|
994
994
|
{attachments.map((a, i) => (
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { memo, useRef, useState, type PointerEvent as ReactPointerEvent } from 'react';
|
|
1
|
+
import { memo, useEffect, useRef, useState, type PointerEvent as ReactPointerEvent } from 'react';
|
|
2
2
|
import { useStore } from '../store/store';
|
|
3
3
|
import { db, DEFAULT_GENERATION_SETTINGS } from '../db/database';
|
|
4
|
-
import { type ThemeMode } from '../theme/theme';
|
|
4
|
+
import { type ThemeMode, type ThemePaletteId } from '../theme/theme';
|
|
5
5
|
import { type ApiProvider, type AppLanguage, type ReasoningEffort, type VoiceProvider, type VoiceProviderKind, type VoiceId, enabledModelIds, modelAliases } from '../types/models';
|
|
6
6
|
import { VOICE_PROVIDER_OPTIONS, previewVoice } from '../core/voice';
|
|
7
7
|
import { Icon, Modal } from './shared';
|
|
@@ -15,6 +15,8 @@ import { VersionHistoryModal } from './VersionHistoryModal';
|
|
|
15
15
|
// 设置视图(模型服务 / 超参数 / 主题)
|
|
16
16
|
// ============================================================
|
|
17
17
|
|
|
18
|
+
type SettingsTab = 'api' | 'model' | 'general';
|
|
19
|
+
|
|
18
20
|
export const SettingsView = memo(function SettingsView() {
|
|
19
21
|
const settings = useStore((s) => s.settings);
|
|
20
22
|
const setSettings = useStore((s) => s.setSettings);
|
|
@@ -24,6 +26,7 @@ export const SettingsView = memo(function SettingsView() {
|
|
|
24
26
|
const refreshProviders = useStore((s) => s.refreshProviders);
|
|
25
27
|
const voiceProviders = useStore((s) => s.voiceProviders);
|
|
26
28
|
const refreshVoiceProviders = useStore((s) => s.refreshVoiceProviders);
|
|
29
|
+
const [tab, setTab] = useState<SettingsTab>('api');
|
|
27
30
|
const [showResetConfirm, setShowResetConfirm] = useState(false);
|
|
28
31
|
const [resetting, setResetting] = useState(false);
|
|
29
32
|
const [showVersionHistory, setShowVersionHistory] = useState(false);
|
|
@@ -107,18 +110,32 @@ export const SettingsView = memo(function SettingsView() {
|
|
|
107
110
|
addToast(t('toast.genParamsReset'));
|
|
108
111
|
};
|
|
109
112
|
return (
|
|
110
|
-
<div className="view-page">
|
|
113
|
+
<div className="view-page settings-page">
|
|
111
114
|
<div className="view-col">
|
|
112
115
|
<div>
|
|
113
116
|
<h2 className="view-title">{t('settings.title')}</h2>
|
|
114
117
|
<p className="view-sub">{t('settings.sub')}</p>
|
|
115
118
|
</div>
|
|
116
119
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
<div className="side-nav view-tabs" data-hscroll role="tablist" aria-label={t('settings.title')}>
|
|
121
|
+
<button type="button" role="tab" aria-selected={tab === 'api'} className={`nav-chip ${tab === 'api' ? 'active' : ''}`} onClick={() => setTab('api')}>
|
|
122
|
+
{t('settings.tabApi')}
|
|
123
|
+
</button>
|
|
124
|
+
<button type="button" role="tab" aria-selected={tab === 'model'} className={`nav-chip ${tab === 'model' ? 'active' : ''}`} onClick={() => setTab('model')}>
|
|
125
|
+
{t('settings.tabModel')}
|
|
126
|
+
</button>
|
|
127
|
+
<button type="button" role="tab" aria-selected={tab === 'general'} className={`nav-chip ${tab === 'general' ? 'active' : ''}`} onClick={() => setTab('general')}>
|
|
128
|
+
{t('settings.tabGeneral')}
|
|
129
|
+
</button>
|
|
130
|
+
</div>
|
|
120
131
|
|
|
121
|
-
<div className="
|
|
132
|
+
<div className="settings-tab-panel" data-active={tab === 'api' ? 'true' : 'false'} role="tabpanel">
|
|
133
|
+
<ProviderManager providers={providers} onChanged={refreshProviders} />
|
|
134
|
+
<VoiceProviderManager providers={voiceProviders} onChanged={refreshVoiceProviders} />
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<div className="settings-tab-panel" data-active={tab === 'model' ? 'true' : 'false'} role="tabpanel">
|
|
138
|
+
<div className="set-section">
|
|
122
139
|
<h3>{t('settings.toolExecution')}</h3>
|
|
123
140
|
<div className="set-row settings-tool-row">
|
|
124
141
|
<div>
|
|
@@ -278,9 +295,10 @@ export const SettingsView = memo(function SettingsView() {
|
|
|
278
295
|
</tr>
|
|
279
296
|
</tbody>
|
|
280
297
|
</table>
|
|
298
|
+
</div>
|
|
281
299
|
</div>
|
|
282
300
|
|
|
283
|
-
<div className="
|
|
301
|
+
<div className="settings-tab-panel" data-active={tab === 'general' ? 'true' : 'false'} role="tabpanel">
|
|
284
302
|
{/* 界面语言 */}
|
|
285
303
|
<div className="set-section">
|
|
286
304
|
<h3>{t('settings.language')}</h3>
|
|
@@ -300,18 +318,37 @@ export const SettingsView = memo(function SettingsView() {
|
|
|
300
318
|
{/* 主题 */}
|
|
301
319
|
<div className="set-section">
|
|
302
320
|
<h3>{t('settings.theme')}</h3>
|
|
303
|
-
<
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
321
|
+
<div className="theme-palette-grid" role="radiogroup" aria-label={t('settings.colorPalette')}>
|
|
322
|
+
{(['amber', 'jade', 'rose', 'indigo'] as ThemePaletteId[]).map((palette) => (
|
|
323
|
+
<button
|
|
324
|
+
type="button"
|
|
325
|
+
role="radio"
|
|
326
|
+
aria-checked={settings.themePalette === palette}
|
|
327
|
+
className={`theme-palette-option theme-palette-${palette}${settings.themePalette === palette ? ' active' : ''}`}
|
|
328
|
+
onClick={() => setSettings({ themePalette: palette })}
|
|
329
|
+
key={palette}
|
|
330
|
+
>
|
|
331
|
+
<span className="theme-palette-preview" aria-hidden="true">
|
|
332
|
+
<i /><i /><i />
|
|
333
|
+
</span>
|
|
334
|
+
<span>{t(`settings.palette.${palette}`)}</span>
|
|
335
|
+
</button>
|
|
336
|
+
))}
|
|
337
|
+
</div>
|
|
338
|
+
<label className="theme-mode-row">
|
|
339
|
+
<span>{t('settings.appearance')}</span>
|
|
340
|
+
<select
|
|
341
|
+
className="select"
|
|
342
|
+
aria-label={t('settings.appearance')}
|
|
343
|
+
value={settings.themeMode}
|
|
344
|
+
onChange={(e) => setSettings({ themeMode: e.target.value as ThemeMode })}
|
|
345
|
+
>
|
|
346
|
+
<option value="system">{t('settings.system')}</option>
|
|
347
|
+
<option value="light">{t('settings.light')}</option>
|
|
348
|
+
<option value="dark">{t('settings.dark')}</option>
|
|
349
|
+
</select>
|
|
350
|
+
</label>
|
|
313
351
|
</div>
|
|
314
|
-
</div>
|
|
315
352
|
|
|
316
353
|
<div className="set-section settings-about-section">
|
|
317
354
|
<div>
|
|
@@ -336,6 +373,7 @@ export const SettingsView = memo(function SettingsView() {
|
|
|
336
373
|
<Icon name="refresh" size={14} /> {t('settings.resetBtn')}
|
|
337
374
|
</button>
|
|
338
375
|
</div>
|
|
376
|
+
</div>
|
|
339
377
|
</div>
|
|
340
378
|
|
|
341
379
|
{showVersionHistory && <VersionHistoryModal onClose={() => setShowVersionHistory(false)} />}
|
|
@@ -463,6 +501,29 @@ function ApiKeyField({ value, onChange, required = false }: { value: string; onC
|
|
|
463
501
|
);
|
|
464
502
|
}
|
|
465
503
|
|
|
504
|
+
function ScrollingProviderName({ name }: { name: string }) {
|
|
505
|
+
const containerRef = useRef<HTMLSpanElement>(null);
|
|
506
|
+
const textRef = useRef<HTMLSpanElement>(null);
|
|
507
|
+
const [overflowing, setOverflowing] = useState(false);
|
|
508
|
+
|
|
509
|
+
useEffect(() => {
|
|
510
|
+
const updateOverflow = () => {
|
|
511
|
+
setOverflowing((textRef.current?.scrollWidth ?? 0) > (containerRef.current?.clientWidth ?? 0));
|
|
512
|
+
};
|
|
513
|
+
updateOverflow();
|
|
514
|
+
const observer = new ResizeObserver(updateOverflow);
|
|
515
|
+
if (containerRef.current) observer.observe(containerRef.current);
|
|
516
|
+
return () => observer.disconnect();
|
|
517
|
+
}, [name]);
|
|
518
|
+
|
|
519
|
+
return (
|
|
520
|
+
<span ref={containerRef} className={`p-name card-name-scroll${overflowing ? ' is-overflowing' : ''}`}>
|
|
521
|
+
<span ref={textRef} className="card-name-scroll-text">{name}</span>
|
|
522
|
+
{overflowing && <span className="card-name-scroll-text card-name-scroll-copy" aria-hidden="true">{name}</span>}
|
|
523
|
+
</span>
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
|
|
466
527
|
function VoiceProviderManager({ providers, onChanged }: { providers: VoiceProvider[]; onChanged: () => void }) {
|
|
467
528
|
const settings = useStore((s) => s.settings)!;
|
|
468
529
|
const setSettings = useStore((s) => s.setSettings);
|
|
@@ -501,7 +562,7 @@ function VoiceProviderManager({ providers, onChanged }: { providers: VoiceProvid
|
|
|
501
562
|
<input type="checkbox" checked={provider.isEnabled} onChange={async () => { await db.voiceProviders.update(provider.id!, { isEnabled: !provider.isEnabled }); await onChanged(); }} />
|
|
502
563
|
<span className="switch-slider" />
|
|
503
564
|
</label>
|
|
504
|
-
<
|
|
565
|
+
<ScrollingProviderName name={providerName(provider.kind)} />
|
|
505
566
|
<span className="p-status voice">{t('settings.voiceServiceTag')}</span>
|
|
506
567
|
<div style={{ marginLeft: 'auto', display: 'flex', gap: 6 }}>
|
|
507
568
|
<button className="btn btn-sm" onClick={() => setEditing(provider)}>{t('common.edit')}</button>
|
|
@@ -630,7 +691,7 @@ function ProviderManager({ providers, onChanged }: { providers: ApiProvider[]; o
|
|
|
630
691
|
<input type="checkbox" checked={p.isEnabled} onChange={() => toggleEnabled(p)} />
|
|
631
692
|
<span className="switch-slider" />
|
|
632
693
|
</label>
|
|
633
|
-
<
|
|
694
|
+
<ScrollingProviderName name={p.name} />
|
|
634
695
|
<span className="p-status text">{t('settings.textServiceTag')}</span>
|
|
635
696
|
<div style={{ marginLeft: 'auto', display: 'flex', gap: 6 }}>
|
|
636
697
|
<button className="btn btn-sm" onClick={() => setEditing(p)}>{t('common.edit')}</button>
|
|
@@ -93,7 +93,7 @@ export function Sidebar() {
|
|
|
93
93
|
const saved = parseFloat(localStorage.getItem('tav-sidebar-w') || '0');
|
|
94
94
|
return saved >= SIDEBAR_MIN && saved <= SIDEBAR_MAX ? saved : 356;
|
|
95
95
|
});
|
|
96
|
-
const dragRef = useRef<{ startX: number; startW: number } | null>(null);
|
|
96
|
+
const dragRef = useRef<{ pointerId: number; startX: number; startW: number } | null>(null);
|
|
97
97
|
|
|
98
98
|
useEffect(() => {
|
|
99
99
|
const root = document.documentElement;
|
|
@@ -122,24 +122,13 @@ export function Sidebar() {
|
|
|
122
122
|
};
|
|
123
123
|
}, []);
|
|
124
124
|
|
|
125
|
-
useEffect(() =>
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const onUp = () => {
|
|
133
|
-
dragRef.current = null;
|
|
134
|
-
document.body.classList.remove('resizing');
|
|
135
|
-
};
|
|
136
|
-
window.addEventListener('mousemove', onMove);
|
|
137
|
-
window.addEventListener('mouseup', onUp);
|
|
138
|
-
return () => {
|
|
139
|
-
window.removeEventListener('mousemove', onMove);
|
|
140
|
-
window.removeEventListener('mouseup', onUp);
|
|
141
|
-
};
|
|
142
|
-
}, []);
|
|
125
|
+
useEffect(() => () => document.body.classList.remove('resizing'), []);
|
|
126
|
+
|
|
127
|
+
const finishResize = (pointerId: number) => {
|
|
128
|
+
if (dragRef.current?.pointerId !== pointerId) return;
|
|
129
|
+
dragRef.current = null;
|
|
130
|
+
document.body.classList.remove('resizing');
|
|
131
|
+
};
|
|
143
132
|
|
|
144
133
|
useEffect(() => {
|
|
145
134
|
const isMobile = () => window.matchMedia('(max-width: 680px)').matches;
|
|
@@ -325,13 +314,13 @@ export function Sidebar() {
|
|
|
325
314
|
<button className={`nav-chip ${activeView === 'characters' ? 'active' : ''}`} onClick={() => { setActiveView('characters'); setMobileOpen(false); }}>
|
|
326
315
|
<Icon name="users" size={15} /> <span>{t('nav.characters')}</span>
|
|
327
316
|
</button>
|
|
328
|
-
<button className={`nav-chip ${activeView === 'stats' ? 'active' : ''}`} onClick={() => { setActiveView('stats'); setMobileOpen(false); }}>
|
|
329
|
-
<Icon name="trophy" size={15} /> <span>{t('nav.achievements')}</span>
|
|
330
|
-
</button>
|
|
331
317
|
<button className={`nav-chip ${activeView === 'settings' ? 'active' : ''}`} onClick={() => { setActiveView('settings'); setMobileOpen(false); }}>
|
|
332
318
|
<Icon name="settings" size={15} /> <span>{t('nav.settings')}</span>
|
|
333
319
|
{hasUnseenVersion && <span className="unseen-dot" title={t('changelog.unseen')} />}
|
|
334
320
|
</button>
|
|
321
|
+
<button className={`nav-chip ${activeView === 'stats' ? 'active' : ''}`} onClick={() => { setActiveView('stats'); setMobileOpen(false); }}>
|
|
322
|
+
<Icon name="trophy" size={15} /> <span>{t('nav.achievements')}</span>
|
|
323
|
+
</button>
|
|
335
324
|
</nav>
|
|
336
325
|
</div>
|
|
337
326
|
{mobileOpen && <button className="mobile-sidebar-backdrop" type="button" aria-label={t('common.close')} onClick={() => setMobileOpen(false)} />}
|
|
@@ -369,13 +358,13 @@ export function Sidebar() {
|
|
|
369
358
|
<button className={`nav-chip ${activeView === 'characters' ? 'active' : ''}`} onClick={() => setActiveView('characters')}>
|
|
370
359
|
<Icon name="users" size={13} /> {t('nav.characters')}
|
|
371
360
|
</button>
|
|
372
|
-
<button className={`nav-chip ${activeView === 'stats' ? 'active' : ''}`} onClick={() => setActiveView('stats')}>
|
|
373
|
-
<Icon name="trophy" size={13} /> {t('nav.achievements')}
|
|
374
|
-
</button>
|
|
375
361
|
<button className={`nav-chip ${activeView === 'settings' ? 'active' : ''}`} onClick={() => setActiveView('settings')}>
|
|
376
362
|
<Icon name="settings" size={13} /> {t('nav.settings')}
|
|
377
363
|
{hasUnseenVersion && <span className="unseen-dot" title={t('changelog.unseen')} />}
|
|
378
364
|
</button>
|
|
365
|
+
<button className={`nav-chip ${activeView === 'stats' ? 'active' : ''}`} onClick={() => setActiveView('stats')}>
|
|
366
|
+
<Icon name="trophy" size={13} /> {t('nav.achievements')}
|
|
367
|
+
</button>
|
|
379
368
|
</div>
|
|
380
369
|
</div>
|
|
381
370
|
|
|
@@ -546,10 +535,20 @@ export function Sidebar() {
|
|
|
546
535
|
<div
|
|
547
536
|
className="sidebar-resizer"
|
|
548
537
|
title={t('nav.resize')}
|
|
549
|
-
|
|
550
|
-
|
|
538
|
+
onPointerDown={(event) => {
|
|
539
|
+
if (!event.isPrimary || event.button !== 0) return;
|
|
540
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
541
|
+
dragRef.current = { pointerId: event.pointerId, startX: event.clientX, startW: sidebarW };
|
|
551
542
|
document.body.classList.add('resizing');
|
|
552
543
|
}}
|
|
544
|
+
onPointerMove={(event) => {
|
|
545
|
+
const drag = dragRef.current;
|
|
546
|
+
if (!drag || drag.pointerId !== event.pointerId) return;
|
|
547
|
+
const width = Math.min(SIDEBAR_MAX, Math.max(SIDEBAR_MIN, drag.startW + event.clientX - drag.startX));
|
|
548
|
+
setSidebarW(width);
|
|
549
|
+
}}
|
|
550
|
+
onPointerUp={(event) => finishResize(event.pointerId)}
|
|
551
|
+
onPointerCancel={(event) => finishResize(event.pointerId)}
|
|
553
552
|
/>
|
|
554
553
|
</aside>
|
|
555
554
|
</>
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 全局悬浮滚动条
|
|
3
|
+
//
|
|
4
|
+
// 原生滚动条会占据布局宽度、外观也随平台变化。这里把原生滚动条完全
|
|
5
|
+
// 隐藏(见 global.css),再以 position: fixed 的细条覆盖在滚动容器上:
|
|
6
|
+
// * 只在容器滚动时出现,静止一段时间后淡出;
|
|
7
|
+
// * 悬浮绘制,不参与 layout,出现/消失都不会让内容尺寸跳动。
|
|
8
|
+
//
|
|
9
|
+
// 滚动事件不冒泡,但可以在 document 上以 capture 捕获到所有容器。
|
|
10
|
+
// 启动时调用一次 installAutoHideScrollbars() 即可。
|
|
11
|
+
// ============================================================
|
|
12
|
+
|
|
13
|
+
const IDLE_HIDE_MS = 1400;
|
|
14
|
+
const THICKNESS = 6;
|
|
15
|
+
const EDGE_INSET = 3;
|
|
16
|
+
const MIN_THUMB = 28;
|
|
17
|
+
|
|
18
|
+
interface ThumbPair {
|
|
19
|
+
vertical: HTMLDivElement | null;
|
|
20
|
+
horizontal: HTMLDivElement | null;
|
|
21
|
+
timer: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ScrollMetrics {
|
|
25
|
+
innerTop: number;
|
|
26
|
+
innerLeft: number;
|
|
27
|
+
innerWidth: number;
|
|
28
|
+
innerHeight: number;
|
|
29
|
+
scrollTop: number;
|
|
30
|
+
scrollLeft: number;
|
|
31
|
+
scrollWidth: number;
|
|
32
|
+
scrollHeight: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const pairs = new WeakMap<Element, ThumbPair>();
|
|
36
|
+
const dirty = new Set<Element>();
|
|
37
|
+
const active = new Set<Element>();
|
|
38
|
+
let layer: HTMLDivElement | null = null;
|
|
39
|
+
let frame = 0;
|
|
40
|
+
|
|
41
|
+
function getLayer(): HTMLDivElement {
|
|
42
|
+
if (layer?.isConnected) return layer;
|
|
43
|
+
layer = document.createElement('div');
|
|
44
|
+
layer.className = 'th-scrollbar-layer';
|
|
45
|
+
layer.setAttribute('aria-hidden', 'true');
|
|
46
|
+
document.body.appendChild(layer);
|
|
47
|
+
return layer;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getPair(el: Element): ThumbPair {
|
|
51
|
+
let pair = pairs.get(el);
|
|
52
|
+
if (!pair) {
|
|
53
|
+
pair = { vertical: null, horizontal: null, timer: 0 };
|
|
54
|
+
pairs.set(el, pair);
|
|
55
|
+
}
|
|
56
|
+
return pair;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getThumb(pair: ThumbPair, axis: 'vertical' | 'horizontal'): HTMLDivElement {
|
|
60
|
+
if (axis === 'vertical') {
|
|
61
|
+
if (!pair.vertical) {
|
|
62
|
+
pair.vertical = document.createElement('div');
|
|
63
|
+
pair.vertical.className = 'th-scrollbar-thumb th-scrollbar-thumb--v';
|
|
64
|
+
getLayer().appendChild(pair.vertical);
|
|
65
|
+
}
|
|
66
|
+
return pair.vertical;
|
|
67
|
+
}
|
|
68
|
+
if (!pair.horizontal) {
|
|
69
|
+
pair.horizontal = document.createElement('div');
|
|
70
|
+
pair.horizontal.className = 'th-scrollbar-thumb th-scrollbar-thumb--h';
|
|
71
|
+
getLayer().appendChild(pair.horizontal);
|
|
72
|
+
}
|
|
73
|
+
return pair.horizontal;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function measure(el: Element): ScrollMetrics | null {
|
|
77
|
+
if (el === document.documentElement) {
|
|
78
|
+
const se = document.scrollingElement ?? document.documentElement;
|
|
79
|
+
return {
|
|
80
|
+
innerTop: 0,
|
|
81
|
+
innerLeft: 0,
|
|
82
|
+
innerWidth: window.innerWidth,
|
|
83
|
+
innerHeight: window.innerHeight,
|
|
84
|
+
scrollTop: window.scrollY,
|
|
85
|
+
scrollLeft: window.scrollX,
|
|
86
|
+
scrollWidth: se.scrollWidth,
|
|
87
|
+
scrollHeight: se.scrollHeight,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (!(el instanceof HTMLElement) || !el.isConnected) return null;
|
|
91
|
+
const rect = el.getBoundingClientRect();
|
|
92
|
+
if (rect.width <= 0 || rect.height <= 0) return null;
|
|
93
|
+
return {
|
|
94
|
+
innerTop: rect.top + el.clientTop,
|
|
95
|
+
innerLeft: rect.left + el.clientLeft,
|
|
96
|
+
innerWidth: el.clientWidth,
|
|
97
|
+
innerHeight: el.clientHeight,
|
|
98
|
+
scrollTop: el.scrollTop,
|
|
99
|
+
scrollLeft: el.scrollLeft,
|
|
100
|
+
scrollWidth: el.scrollWidth,
|
|
101
|
+
scrollHeight: el.scrollHeight,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function positionVertical(node: HTMLDivElement, m: ScrollMetrics): boolean {
|
|
106
|
+
if (m.scrollHeight - m.innerHeight <= 1) return false;
|
|
107
|
+
const trackTop = m.innerTop + EDGE_INSET;
|
|
108
|
+
const trackHeight = m.innerHeight - EDGE_INSET * 2;
|
|
109
|
+
const thumbHeight = Math.max(MIN_THUMB, (trackHeight * m.innerHeight) / m.scrollHeight);
|
|
110
|
+
if (thumbHeight >= trackHeight) return false;
|
|
111
|
+
const maxScroll = m.scrollHeight - m.innerHeight;
|
|
112
|
+
const progress = maxScroll > 0 ? Math.min(1, Math.max(0, m.scrollTop / maxScroll)) : 0;
|
|
113
|
+
node.style.left = `${m.innerLeft + m.innerWidth - THICKNESS - EDGE_INSET}px`;
|
|
114
|
+
node.style.top = `${trackTop + (trackHeight - thumbHeight) * progress}px`;
|
|
115
|
+
node.style.height = `${thumbHeight}px`;
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function positionHorizontal(node: HTMLDivElement, m: ScrollMetrics): boolean {
|
|
120
|
+
if (m.scrollWidth - m.innerWidth <= 1) return false;
|
|
121
|
+
const trackLeft = m.innerLeft + EDGE_INSET;
|
|
122
|
+
const trackWidth = m.innerWidth - EDGE_INSET * 2;
|
|
123
|
+
const thumbWidth = Math.max(MIN_THUMB, (trackWidth * m.innerWidth) / m.scrollWidth);
|
|
124
|
+
if (thumbWidth >= trackWidth) return false;
|
|
125
|
+
const maxScroll = m.scrollWidth - m.innerWidth;
|
|
126
|
+
const progress = maxScroll > 0 ? Math.min(1, Math.max(0, m.scrollLeft / maxScroll)) : 0;
|
|
127
|
+
node.style.top = `${m.innerTop + m.innerHeight - THICKNESS - EDGE_INSET}px`;
|
|
128
|
+
node.style.left = `${trackLeft + (trackWidth - thumbWidth) * progress}px`;
|
|
129
|
+
node.style.width = `${thumbWidth}px`;
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function hidePair(pair: ThumbPair): void {
|
|
134
|
+
pair.vertical?.classList.remove('is-visible');
|
|
135
|
+
pair.horizontal?.classList.remove('is-visible');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function update(el: Element): void {
|
|
139
|
+
const metrics = measure(el);
|
|
140
|
+
if (!metrics) return;
|
|
141
|
+
const pair = getPair(el);
|
|
142
|
+
const vertical = getThumb(pair, 'vertical');
|
|
143
|
+
const horizontal = getThumb(pair, 'horizontal');
|
|
144
|
+
const hasVertical = positionVertical(vertical, metrics);
|
|
145
|
+
const hasHorizontal = positionHorizontal(horizontal, metrics);
|
|
146
|
+
|
|
147
|
+
vertical.classList.toggle('is-visible', hasVertical);
|
|
148
|
+
horizontal.classList.toggle('is-visible', hasHorizontal);
|
|
149
|
+
active.add(el);
|
|
150
|
+
|
|
151
|
+
window.clearTimeout(pair.timer);
|
|
152
|
+
pair.timer = window.setTimeout(() => {
|
|
153
|
+
hidePair(pair);
|
|
154
|
+
active.delete(el);
|
|
155
|
+
// 容器已被移除时顺手回收浮层节点(WeakMap 无法清理 DOM 引用)。
|
|
156
|
+
if (!el.isConnected) {
|
|
157
|
+
pair.vertical?.remove();
|
|
158
|
+
pair.horizontal?.remove();
|
|
159
|
+
pairs.delete(el);
|
|
160
|
+
}
|
|
161
|
+
}, IDLE_HIDE_MS);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function flush(): void {
|
|
165
|
+
frame = 0;
|
|
166
|
+
for (const el of dirty) update(el);
|
|
167
|
+
dirty.clear();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function onScroll(event: Event): void {
|
|
171
|
+
const target = event.target;
|
|
172
|
+
let el: Element;
|
|
173
|
+
if (target === document) el = document.documentElement;
|
|
174
|
+
else if (target instanceof Element) el = target;
|
|
175
|
+
else return;
|
|
176
|
+
dirty.add(el);
|
|
177
|
+
if (frame === 0) frame = window.requestAnimationFrame(flush);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function installAutoHideScrollbars(): void {
|
|
181
|
+
if (typeof document === 'undefined') return;
|
|
182
|
+
document.addEventListener('scroll', onScroll, { capture: true, passive: true });
|
|
183
|
+
// 视口尺寸变化后旧坐标会失效,先收起,等下一次滚动重新定位。
|
|
184
|
+
window.addEventListener('resize', () => {
|
|
185
|
+
for (const el of active) {
|
|
186
|
+
const pair = pairs.get(el);
|
|
187
|
+
if (pair) hidePair(pair);
|
|
188
|
+
}
|
|
189
|
+
active.clear();
|
|
190
|
+
});
|
|
191
|
+
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import type { AppLanguage, ThemeModeId } from '../types/models';
|
|
1
|
+
import type { AppLanguage, ThemeModeId, ThemePaletteId } from '../types/models';
|
|
2
2
|
|
|
3
3
|
const BROWSER_UI_PREFERENCES_KEY = 'th-browser-ui-preferences';
|
|
4
4
|
|
|
5
5
|
export interface BrowserUiPreferences {
|
|
6
6
|
language: AppLanguage;
|
|
7
7
|
themeMode: ThemeModeId;
|
|
8
|
+
themePalette: ThemePaletteId;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
const DEFAULT_BROWSER_UI_PREFERENCES: BrowserUiPreferences = {
|
|
11
12
|
language: null,
|
|
12
13
|
themeMode: 'system',
|
|
14
|
+
themePalette: 'amber',
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
export function hasBrowserUiPreferences(): boolean {
|
|
@@ -28,6 +30,9 @@ export function readBrowserUiPreferences(): BrowserUiPreferences {
|
|
|
28
30
|
return {
|
|
29
31
|
language: value.language === 'zh-CN' || value.language === 'zh-TW' || value.language === 'en' ? value.language : null,
|
|
30
32
|
themeMode: value.themeMode === 'light' || value.themeMode === 'dark' || value.themeMode === 'system' ? value.themeMode : 'system',
|
|
33
|
+
themePalette: value.themePalette === 'jade' || value.themePalette === 'rose' || value.themePalette === 'indigo'
|
|
34
|
+
? value.themePalette
|
|
35
|
+
: 'amber',
|
|
31
36
|
};
|
|
32
37
|
} catch {
|
|
33
38
|
return DEFAULT_BROWSER_UI_PREFERENCES;
|