Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions e2e/player-theme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,47 @@ test("浅色主题:按钮悬停提示(hint 伪元素)非黑,随 app-surf
r.arrowLeft === "rgba(0, 0, 0, 0)" || r.arrowLeft === "transparent",
).toBe(true);
});

test("全屏:播放器元素移到 body 后仍保持媒体暗色作用域(#1973 回归)", async ({
page,
}) => {
await openPlayer(page, {});
await shot(page, "windowed-default-dark");
await page.locator(".art-control[data-name='fullscreen']").click();
await expect(
page.locator(".art-video-player.art-fullscreen-web"),
).toHaveCount(1);
const r = await page.evaluate(() => {
const p = document.querySelector(".art-video-player.art-fullscreen-web");
return {
bg: p ? getComputedStyle(p).backgroundColor : null,
parent: p?.parentElement?.tagName ?? null,
attr: p?.getAttribute("data-media-theme") ?? null,
};
});
console.log("[fullscreen media theme]", JSON.stringify(r));
expect(r.parent).toBe("BODY");
expect(r.bg).toBe("rgb(19, 19, 22)");
await shot(page, "fullscreen-default-dark");
});

test("全屏:跟随档下背景随应用主题(浅色),且不设媒体作用域", async ({
page,
}) => {
await openPlayer(page, { mediaTheme: "follow" });
await shot(page, "windowed-follow-light");
await page.locator(".art-control[data-name='fullscreen']").click();
await expect(
page.locator(".art-video-player.art-fullscreen-web"),
).toHaveCount(1);
const r = await page.evaluate(() => {
const p = document.querySelector(".art-video-player.art-fullscreen-web");
return {
bg: p ? getComputedStyle(p).backgroundColor : null,
attr: p?.getAttribute("data-media-theme") ?? null,
};
});
expect(r.attr).toBeNull();
expect(r.bg).toBe("rgb(247, 247, 246)");
await shot(page, "fullscreen-follow-light");
});
9 changes: 9 additions & 0 deletions src/components/Content/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,15 @@ export default function VideoPlayer({
}, []);
/* eslint-enable react-hooks/exhaustive-deps */

// 网页全屏会把 $player 移到 body(ArtPlayer FULLSCREEN_WEB_IN_BODY=true),
// 媒体主题作用域必须跟着元素走,否则全屏底回落到 body 的应用主题 token(#1979)。
useEffect(() => {
const player = artRef.current?.template?.$player;
if (!player) return;
if (mediaDark) player.dataset.mediaTheme = "dark";
else delete player.dataset.mediaTheme;
}, [mediaDark]);

// 点击模型(#1862):单击画面切控制条显隐、右键切播放/暂停、双击进网页全屏,
// 均不弹右键菜单。ArtPlayer 内置 click 会 toggle 播放,故在 document 捕获阶段
// 先于其 target 监听拦截;网页全屏会把 $player 移入 body,捕获监听仍按
Expand Down
Loading