diff --git a/docs/design/system/decisions.md b/docs/design/system/decisions.md index 2c138f79..c358bfda 100644 --- a/docs/design/system/decisions.md +++ b/docs/design/system/decisions.md @@ -123,6 +123,7 @@ ledger: append-only | 信息窗复制图标弱化档 | 新增 `--app-text-4`(spec §6 文本弱化档):信息窗复制路径 / 复制文件两图标默认色由 `--app-text-3` 降为该档,hover 提亮到 `--app-text`;该档仅用于低干扰辅助图标静息态,不用于任何文本;标题与路径保持左对齐 | editor-surface-batch24 / #1856 | 2026-11-30 | | 画面按钮图标定案 | 取代台账「画面图标(#486):图片框构图(山与太阳)」行:控制条「画面」按钮改用「显示器 + 播放三角」(外框 + 底座 + 三角,单 `s` path,§2.1 安全区 / ≤6 笔画);新增 `visual` 概念键,与 `video` 文件类型图标(外框 + 三角)不同构图、不复用 path;两套图标源 + e2e mock 三处同步 | editor-surface-batch24 / #1857 | 2026-11-30 | | 页签同比例收缩 | #1843 在固定上限模型上补「变窄时同比例收缩」:页签 `flex: 0 1 auto` + `min-width: 0` + `flex-shrink: 1`,移除 `calc-size(max-content, min(...))` 保底(WebKit 不支持),`--tab-min-width` 不再作收缩下限;短名按内容实际宽度、长名以 `--tab-max-width` 为上限并省略号收尾,全部页签在窗格变窄时按同一比例连续收缩 | #1843 | 2026-12-02 | +| 媒体表面默认固定暗色 | 音视频播放器的媒体表面(画面底色、底栏、控制条、菜单与 body 浮层)默认放入暗色 token 作用域(`data-media-theme="dark"`,复用 `.dark` 同一份暗色词表,不新增色值),另给「跟随应用主题」档恢复原行为;`tokens.css` 暗色块选择器由 `.dark` 扩为 `.dark, [data-media-theme="dark"]` | media-player-theme-switch / #1973 | 2026-12-02 | **图标纪检 18px 高频裁决明细(11 行,spec §2.1 / §2.2 / §2.4)** diff --git a/e2e/player-theme.spec.ts b/e2e/player-theme.spec.ts index cf85f47c..3039c182 100644 --- a/e2e/player-theme.spec.ts +++ b/e2e/player-theme.spec.ts @@ -20,8 +20,38 @@ const TINY_MP4 = readFileSync( path.resolve(process.cwd(), "e2e/fixtures/tiny.mp4"), ).toString("base64"); -async function openPlayer(page: Page): Promise { +const EVIDENCE_DIR = process.env.EVIDENCE_DIR; +async function shot(page: Page, name: string): Promise { + if (EVIDENCE_DIR) { + await page.screenshot({ path: path.join(EVIDENCE_DIR, `${name}.png`) }); + } +} + +async function openPlayer( + page: Page, + opts: { mediaTheme?: "follow" } = {}, +): Promise { await page.addInitScript({ path: "./e2e/mocks/tauri-mock.js" }); + if (opts.mediaTheme) { + // 真实配置加载路径:load_config 返回 follow,应用按配置归一化后进媒体表面。 + await page.addInitScript((theme) => { + const w = window as unknown as { + __TAURI_INTERNALS__?: { + invoke?: (cmd: string, args?: unknown) => Promise; + }; + }; + const internals = w.__TAURI_INTERNALS__; + if (!internals || typeof internals.invoke !== "function") return; + const orig = internals.invoke; + internals.invoke = async (cmd, args) => { + const res = await orig(cmd, args); + if (cmd === "load_config" && res && typeof res === "object") { + return { ...(res as Record), mediaTheme: theme }; + } + return res; + }; + }, opts.mediaTheme); + } await page.addInitScript(() => { const w = window as unknown as Record; w.__biaoyue_media__ = [ @@ -145,10 +175,33 @@ const luminance = (rgb: string): number => { return 0.299 * c[0] + 0.587 * c[1] + 0.114 * c[2]; }; +test("浅色主题 + 默认配置:播放器固定暗色(#1973)", async ({ page }) => { + await openPlayer(page, {}); + const c = await readChrome(page); + console.log("[player-theme dark-default]", JSON.stringify(c)); + + // 播放器底色 = 暗色 --app-bg(#131316),不是浅色底 + expect(sameColor(c.playerBg, "#131316")).toBe(true); + // 控制条文字 = 暗色 --app-text(#d8dade) + expect(sameColor(c.controlColor, "#d8dade")).toBe(true); + await shot(page, "default-dark"); + + // body 浮层同源:倍速菜单底色 = 暗色 --app-surface(#1a1b1e) + await page.locator(".art-control[data-name='rate']").click(); + await expect(page.locator(".rate-menu")).toBeVisible(); + const rateMenuBg = await page.evaluate( + () => + getComputedStyle(document.querySelector(".rate-menu")!).backgroundColor, + ); + console.log("[player-theme dark-default rate]", rateMenuBg); + expect(sameColor(rateMenuBg, "#1a1b1e")).toBe(true); + await shot(page, "default-dark-menu"); +}); + test("浅色主题:播放器底/控制条非黑,文字随 app-text,强调色随 app-accent", async ({ page, }) => { - await openPlayer(page); + await openPlayer(page, { mediaTheme: "follow" }); const c = await readChrome(page); console.log("[player-theme light]", JSON.stringify(c)); @@ -171,11 +224,13 @@ test("浅色主题:播放器底/控制条非黑,文字随 app-text,强调 }); test("暗色主题:切换 .dark 后底色变暗且随暗色 token", async ({ page }) => { - await openPlayer(page); + await openPlayer(page, { mediaTheme: "follow" }); const light = await readChrome(page); + await shot(page, "follow-light"); await page.evaluate(() => document.documentElement.classList.add("dark")); await page.waitForTimeout(200); const dark = await readChrome(page); + await shot(page, "follow-dark-app"); console.log("[player-theme dark]", JSON.stringify(dark)); expect(isBlack(dark.playerBg)).toBe(false); @@ -293,7 +348,7 @@ function readPopovers(page: Page): Promise { test("浅色主题:自研浮层与 Artplayer 浮层底色随 app-surface,文字随 app-text", async ({ page, }) => { - await openPlayer(page); + await openPlayer(page, { mediaTheme: "follow" }); // 倍速菜单(单独打开读取,避免浮层互相关闭) await page.locator(".art-control[data-name='rate']").click(); @@ -382,7 +437,7 @@ test("浅色主题:自研浮层与 Artplayer 浮层底色随 app-surface,文 }); test("暗色主题:浮层随 .dark 变深且文字随暗色 token", async ({ page }) => { - await openPlayer(page); + await openPlayer(page, { mediaTheme: "follow" }); await page.locator(".art-control[data-name='rate']").click(); await expect(page.locator(".rate-menu")).toBeVisible(); const light = await readPopovers(page); @@ -437,7 +492,7 @@ test("暗色主题:浮层随 .dark 变深且文字随暗色 token", async ({ p test("浅色主题:按钮悬停提示(hint 伪元素)非黑,随 app-surface/app-text(#1957)", async ({ page, }) => { - await openPlayer(page); + await openPlayer(page, { mediaTheme: "follow" }); const r = await page.evaluate(() => { const root = getComputedStyle(document.documentElement); const token = (k: string) => root.getPropertyValue(k).trim(); diff --git a/openspec/changes/media-player-theme-switch/design.md b/openspec/changes/media-player-theme-switch/design.md index a7f565b2..babb182b 100644 --- a/openspec/changes/media-player-theme-switch/design.md +++ b/openspec/changes/media-player-theme-switch/design.md @@ -38,7 +38,7 @@ | 落点 | 位置 | 载体/符号 | 判据 | |---|---|---|---| -| 规格 | docs/design/system/spec.md | — | 只消费既有 `--app-*` 语义色,不新增色值;暗色词表复用同一份定义 | +| 规格 | design-system:§6 | — | 只消费既有 `--app-*` 语义色,不新增色值;暗色词表复用同一份定义 | | 存储 | src-tauri/src/config.rs | media_theme | `Option`,camelCase 序列化为 `mediaTheme`,缺省 None 语义为 dark | | 校验 | src-tauri/src/config.rs | validate_config | `check_enum` 仅接受 `dark|follow`,非法值拒绝且不落盘 | | 桥接 | src/hooks/useConfig.ts | saveAppConfig | 读 store 的 `mediaTheme` 写盘;加载时未知值回落 `dark` | diff --git a/openspec/changes/media-player-theme-switch/tasks.md b/openspec/changes/media-player-theme-switch/tasks.md index 1b81e98e..cd59cc8d 100644 --- a/openspec/changes/media-player-theme-switch/tasks.md +++ b/openspec/changes/media-player-theme-switch/tasks.md @@ -2,7 +2,7 @@ ## 1. 媒体主题开关 -- [ ] 1.1 配置项 `mediaTheme` + 播放器默认暗色作用域(容器与 `body` 浮层同源),并改写既有的播放器主题默认态用例 +- [x] 1.1 配置项 `mediaTheme` + 播放器默认暗色作用域(容器与 `body` 浮层同源),并改写既有的播放器主题默认态用例 - **数据面**: 规格,存储,校验,桥接,消费,回滚(六栏见 design.md「## 数据面」) - [ ] 1.2 设置 → 外观 新增「音视频固定暗色背景」开关,接跟随档热应用与持久化,补开关与重启保持用例(Blocked by 1.1) - **数据面**: 消费 diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index bf1ec0c6..d31e2918 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -134,6 +134,12 @@ pub struct AppConfig { /// Default 给 Some(理由同 pane_mode);反序列化缺键仍回落 medium。 #[serde(default, skip_serializing_if = "Option::is_none")] pub pane_scale: Option, + /// 媒体表面主题(media-player-theme-switch / #1973):dark(固定暗色,缺省)/ + /// follow(跟随应用主题)。缺省 None 的语义 = dark(前端归一化)。 + /// `default` + `skip_serializing_if` 让老配置仍能读、新配置不多出空字段; + /// 补丁白名单由 `nested_defaults()` 显式登记(与 bodyFont 同一处理)。 + #[serde(default, skip_serializing_if = "Option::is_none")] + pub media_theme: Option, } /// 扩展包启用态(extension-package-v2 D5):settings 优先于旧 `.disabled` 标记。 @@ -326,6 +332,7 @@ impl Default for AppConfig { // skip_serializing_if 跳出白名单,故预设键的 default 给 Some。 pane_mode: Some("standard".into()), pane_scale: Some("medium".into()), + media_theme: None, sidebar_left_visible: Some(true), sidebar_right_visible: Some(false), sidebar_left_width: Some(220.0), @@ -724,6 +731,11 @@ pub fn validate_config(config: &AppConfig) -> Result<(), AppError> { config.pane_scale.as_deref(), &["small", "medium", "large"], )?; + check_enum( + "mediaTheme", + config.media_theme.as_deref(), + &["dark", "follow"], + )?; if let Some(spec) = &config.rail_view_spec { check_enum( "railViewSpec.layout", @@ -1112,7 +1124,8 @@ fn nested_defaults() -> Value { "searchHoverPreview": null, "iconLabel": null, "paneLayout": null, - "bodyFont": null + "bodyFont": null, + "mediaTheme": null }) } @@ -1296,6 +1309,7 @@ pub(crate) const SKILL_MAP: &str = r#"# Biaoyue 配置地图 | `readerSkin` | `paper` / `indigo` / `moss` / `clay`(兼容 `plain`) | | `paneMode` | `simple` / `standard` / `hardcore` | | `paneScale` | `small` / `medium` / `large` | +| `mediaTheme` | `dark` / `follow` | | `propertyBar.displayStyle` | `list` / `dual` | | `propertyBar.displayDefault.preview` / `.edit` | `show` / `collapse` / `hide` | | `propertyBar.newDocVisible` | `true` / `false` | @@ -2953,6 +2967,35 @@ mod tests { } } + #[test] + fn media_theme_patch_accepts_follow_and_rejects_light() { + let dir = temp_base("media_theme"); + let base = dir.path(); + write_user(base, r#"{"theme":"light"}"#); + + // 缺省 = None(语义 dark),补丁边界必须接受合法键。 + assert_eq!(load_config_at(base).unwrap().media_theme, None); + let patched = apply_patch_at(base, &serde_json::json!({"mediaTheme": "follow"})) + .expect("follow 应被接受"); + assert_eq!(patched.media_theme.as_deref(), Some("follow")); + assert_eq!( + load_config_at(base).unwrap().media_theme.as_deref(), + Some("follow") + ); + + // 非法值:校验拒绝且不落盘(user 层字节不变)。 + let after_follow = read_user(base); + let err = apply_patch_at(base, &serde_json::json!({"mediaTheme": "light"})).unwrap_err(); + assert!(matches!(err, AppError::Validation { .. }), "got {err:?}"); + assert_eq!(read_user(base), after_follow); + assert_eq!( + load_config_at(base).unwrap().media_theme.as_deref(), + Some("follow") + ); + let user: Value = serde_json::from_str(&read_user(base)).unwrap(); + assert_eq!(user["mediaTheme"], serde_json::json!("follow")); + } + #[test] fn keyring_uses_platform_store_not_mock() { // keyring v3 不默认开启任何平台凭据库 feature;缺失时静默退回内存 mock, diff --git a/src/__tests__/mediaPlayerHost.test.tsx b/src/__tests__/mediaPlayerHost.test.tsx index 9d5cecc1..02fc5512 100644 --- a/src/__tests__/mediaPlayerHost.test.tsx +++ b/src/__tests__/mediaPlayerHost.test.tsx @@ -2,9 +2,11 @@ import { describe, it, expect, afterEach, vi } from "vitest"; import { render, act } from "@testing-library/react"; import MediaPlayerHost from "../components/Content/MediaPlayerHost"; import { mediaPlayer } from "../components/Content/mediaPlayerState"; +import { useEditorStore } from "../stores/editorStore"; afterEach(() => { mediaPlayer.stop(); + useEditorStore.getState().reset(); }); describe("MediaPlayerHost 媒体播放器宿主(无迷你条)", () => { @@ -113,4 +115,31 @@ describe("MediaPlayerHost 媒体播放器宿主(无迷你条)", () => { }); expect(fn).toHaveBeenCalledTimes(2); }); + + it("默认(缺省)媒体主题 = dark:宿主挂 data-media-theme=dark", () => { + act(() => { + mediaPlayer.show({ + filePath: "/tmp/clip.mp4", + url: "media://localhost/tmp/clip.mp4", + fileKind: "video", + }); + }); + const { container } = render(); + const host = container.firstElementChild as HTMLElement; + expect(host.getAttribute("data-media-theme")).toBe("dark"); + }); + + it("mediaTheme=follow:宿主不挂 data-media-theme", () => { + act(() => { + useEditorStore.getState().setConfig({ mediaTheme: "follow" }); + mediaPlayer.show({ + filePath: "/tmp/clip.mp4", + url: "media://localhost/tmp/clip.mp4", + fileKind: "video", + }); + }); + const { container } = render(); + const host = container.firstElementChild as HTMLElement; + expect(host.getAttribute("data-media-theme")).toBeNull(); + }); }); diff --git a/src/__tests__/mediaTheme.test.ts b/src/__tests__/mediaTheme.test.ts new file mode 100644 index 00000000..d20a1899 --- /dev/null +++ b/src/__tests__/mediaTheme.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, it } from "vitest"; +import { normalizeMediaTheme } from "../hooks/useConfig"; + +describe("normalizeMediaTheme(media-player-theme-switch / #1973)", () => { + it("缺省 / null / 未知值一律回落 dark", () => { + expect(normalizeMediaTheme(undefined)).toBe("dark"); + expect(normalizeMediaTheme(null)).toBe("dark"); + expect(normalizeMediaTheme("light")).toBe("dark"); + expect(normalizeMediaTheme("DARK")).toBe("dark"); + expect(normalizeMediaTheme("")).toBe("dark"); + }); + + it("仅精确 follow 保留", () => { + expect(normalizeMediaTheme("follow")).toBe("follow"); + expect(normalizeMediaTheme("follow ")).toBe("dark"); + expect(normalizeMediaTheme("Follow")).toBe("dark"); + }); +}); diff --git a/src/__tests__/styles/themeShadowTokens.test.ts b/src/__tests__/styles/themeShadowTokens.test.ts index 86fbb3cf..06ec5eb4 100644 --- a/src/__tests__/styles/themeShadowTokens.test.ts +++ b/src/__tests__/styles/themeShadowTokens.test.ts @@ -6,7 +6,7 @@ import { fileURLToPath } from "node:url"; const tokensCss = readFileSync( fileURLToPath(new URL("../../styles/tokens.css", import.meta.url)), "utf8", -); +).replace(/\/\*[\s\S]*?\*\//g, ""); const SHADOW_KEYS = [ "--shadow-menu", @@ -17,12 +17,16 @@ const SHADOW_KEYS = [ ] as const; function block(selector: string): string { - const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); - const match = tokensCss.match( - new RegExp(`(?:^|\\n)\\s*${escaped}\\s*\\{([\\s\\S]*?)\\}`), - ); - if (!match) throw new Error(`未找到 ${selector} 块`); - return match[1]; + for (const m of tokensCss.matchAll( + /(?:^|\n)\s*([^{}]+?)\s*\{([\s\S]*?)\}/g, + )) { + const selectors = m[1] + .split(",") + .map((s) => s.trim()) + .filter(Boolean); + if (selectors.includes(selector)) return m[2]; + } + throw new Error(`未找到 ${selector} 块`); } function shadowTokens(selector: string): Map { diff --git a/src/components/Content/MediaPlayerHost.tsx b/src/components/Content/MediaPlayerHost.tsx index 218448e0..64cc1e98 100644 --- a/src/components/Content/MediaPlayerHost.tsx +++ b/src/components/Content/MediaPlayerHost.tsx @@ -5,6 +5,7 @@ import { type MediaPlayerState, type MediaSource, } from "./mediaPlayerState"; +import { useEditorStore } from "../../stores/editorStore"; import VideoPlayer from "./VideoPlayer"; interface Rect { @@ -93,6 +94,9 @@ function PaneMediaPlayer({ visible: boolean; }) { const hostRef = useRef(null); + const mediaDark = useEditorStore( + (s) => (s.config.mediaTheme ?? "dark") !== "follow", + ); const paneId = source.paneId ?? null; const embedded = source.embedded === true; const [paneRect, setPaneRect] = useState<{ @@ -150,7 +154,12 @@ function PaneMediaPlayer({ }; return ( -
+
(null); + const mediaDark = useEditorStore( + (s) => (s.config.mediaTheme ?? "dark") !== "follow", + ); const containerRef = useRef(null); const canvasRef = useRef(null); const artRef = useRef(null); @@ -2755,6 +2759,7 @@ export default function VideoPlayer({ return (
+ {popoverPanel} +
, + document.body, + ) : popoverPanel)} {/* 时间戳笔记窗口:可拖动 + 可调整大小 */} diff --git a/src/hooks/useConfig.ts b/src/hooks/useConfig.ts index 108f725b..80badb90 100644 --- a/src/hooks/useConfig.ts +++ b/src/hooks/useConfig.ts @@ -75,6 +75,7 @@ interface RustAppConfig { sourceLang: string | null; targetLang: string | null; theme: string | null; + mediaTheme?: string | null; aiConfirmDensity: string | null; iconLabel: string | null; sidebarLeftVisible: boolean | null; @@ -413,6 +414,7 @@ export async function saveAppConfig(): Promise { sourceLang: es.config.langPair?.source ?? null, targetLang: es.config.langPair?.target ?? null, theme: es.config.theme ?? null, + mediaTheme: es.config.mediaTheme ?? null, aiConfirmDensity: es.config.aiConfirmDensity ?? null, iconLabel: es.config.iconLabel ?? null, sidebarLeftVisible: es.config.sidebarLeftVisible ?? null, @@ -606,6 +608,16 @@ export function normalizeHtmlToolbarItems( return out.length > 0 ? out : null; } +/** + * 媒体表面主题档位归一化(media-player-theme-switch / #1973): + * 只有精确 "follow" 保留,其余(含缺失 / null / 未知值)一律回落 "dark"。 + */ +export function normalizeMediaTheme( + raw: string | null | undefined, +): "dark" | "follow" { + return raw === "follow" ? "follow" : "dark"; +} + /** * 提示时长(ui-polish-batch15 4.1):有限数、0.1–10、1 位小数才有效, * 其余(含缺失)一律回落 null,消费端按默认 3 秒处理。 @@ -691,6 +703,7 @@ export function applyRustConfig(raw: RustAppConfig): void { target: raw.targetLang ?? "zh-CN", }, theme: (raw.theme as Theme) ?? "system", + mediaTheme: normalizeMediaTheme(raw.mediaTheme), aiConfirmDensity: (raw.aiConfirmDensity as AppConfig["aiConfirmDensity"]) ?? "session-silent", @@ -883,6 +896,7 @@ export function useConfig() { translationProvider: "ollama", langPair: { source: "en", target: "zh-CN" }, theme: "system", + mediaTheme: "dark", aiConfirmDensity: "session-silent", sidebarLeftVisible: true, sidebarRightVisible: false, diff --git a/src/styles/tokens.css b/src/styles/tokens.css index b7420825..a653de59 100644 --- a/src/styles/tokens.css +++ b/src/styles/tokens.css @@ -112,7 +112,8 @@ --shadow-button: 0 1px 1.5px rgba(0, 0, 0, 0.05); } -.dark { +.dark, +[data-media-theme="dark"] { --app-accent: #818cf8; --app-accent-soft: rgba(129, 140, 248, 0.14); --app-accent-fill: #818cf8; diff --git a/src/types/index.ts b/src/types/index.ts index c3a38626..d767fd13 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -111,6 +111,8 @@ export interface AppConfig { translationProvider: TranslationProvider; langPair: LangPair; theme: Theme; + /** 媒体表面主题(media-player-theme-switch / #1973):dark 固定暗色(缺省)/ follow 跟随应用主题 */ + mediaTheme?: "dark" | "follow" | null; /** AI 改动前的确认密度:always 每次确认 / session-silent 本会话静默 / never 只靠撤销 */ aiConfirmDensity?: "always" | "session-silent" | "never"; sidebarLeftVisible: boolean;