Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(follow): 合集换版本点下即换,控件装好前不露原装播放键

longmeidao07fb7e89297d
diff --git a/frontend/e2e/design-detail.test.ts b/frontend/e2e/design-detail.test.ts
index 5146f5050..132dd10cd 100644
--- a/frontend/e2e/design-detail.test.ts
+++ b/frontend/e2e/design-detail.test.ts
@@ -546,7 +546,6 @@ describe('设计决定:关注详情、作品详情、播放器与侧栏', () =
assert.equal((await styleOf(page, '#stage .vjs-progress-holder', ['height']))!.height, '6px', '彩条本身不变粗');
assert.equal((await styleOf(page, '#stage .vjs-play-progress', ['background-color']))!['background-color'],
await tokenColor(page, '#stage', '--tungsten'));
- assert.deepEqual(await styleOf(page, '#stage .vjs-big-play-button', ['width', 'height']), { width: '56px', height: '56px' });
assert.equal((await styleOf(page, '#stage .video-js', ['font-family']))!['font-family'],
(await styleOf(page, 'body', ['font-family']))!['font-family'], '播放器里的字用页面字体,不是 Video.js 的 Arial');
assert.deepEqual(await styleOf(page, '#stage [data-player-theater] > .vjs-peach-tooltip',
diff --git a/frontend/e2e/follow-detail.test.ts b/frontend/e2e/follow-detail.test.ts
index e469389f5..1ae25e86b 100644
--- a/frontend/e2e/follow-detail.test.ts
+++ b/frontend/e2e/follow-detail.test.ts
@@ -31,11 +31,17 @@ function watchFollowRequests(page: Page) {
return seen;
}
-/** 换条前记下舞台节点并盯住骨架:原地换条时浮窗还是同一个节点,中途不回骨架,焦点留在浮窗里。 */
+/** 换条前记下舞台节点并盯住骨架:原地换条时浮窗还是同一个节点,中途不回骨架,焦点留在浮窗里。
+ * 顺带盯新播放器:Peach 控件(提示圆是其中一枚)装上之前,Video.js 原装的控制条与大播放键不该露出来。 */
const watchStage = (page: Page) => page.evaluate(() => {
- const watch = { stage: document.getElementById('stage'), skeleton: false };
- new MutationObserver(() => { if (document.querySelector('#stage [data-skeleton="detail"]')) watch.skeleton = true })
- .observe(document.body, { childList: true, subtree: true });
+ const watch = { stage: document.getElementById('stage'), skeleton: false, rawControls: false };
+ const shown = (node: Element | null) => !!node && getComputedStyle(node).display !== 'none' && getComputedStyle(node).visibility !== 'hidden';
+ new MutationObserver(() => {
+ if (document.querySelector('#stage [data-skeleton="detail"]')) watch.skeleton = true;
+ for (const player of document.querySelectorAll('#stage div.video-js:not(:has(.vjs-peach-bezel))')) {
+ if (shown(player.querySelector('.vjs-control-bar')) || shown(player.querySelector('.vjs-big-play-button'))) watch.rawControls = true;
+ }
+ }).observe(document.body, { childList: true, subtree: true });
Object.assign(window, { stageWatch: watch });
});
const stageKept = (page: Page) => page.evaluate(() => {
@@ -138,6 +144,7 @@ describe('关注详情岛', () => {
assert.equal(await frame.locator('[data-ambient-canvas]').count(), 1);
assert.equal(await frame.locator('.video-js video').count(), 1, '媒体框里的 video 不止一个');
await watchStage(page);
+ const seen = watchFollowRequests(page);
await page.locator('[data-follow-queue-item="5102"]').click();
await pathIs(page, '/follow/item/5102');
await page.locator('#stage [data-follow-queue-item="5102"][aria-current="true"]').waitFor();
@@ -151,6 +158,9 @@ describe('关注详情岛', () => {
await page.locator('#stage .video-js .vjs-control-bar').waitFor({ state: 'attached' });
assert.equal(await page.locator('#stage .video-js').count(), 1, '后退之后旧播放器没拆');
assert.deepEqual(await stageKept(page), { same: true, skeleton: false, focused: true }, '后退到上一条重开了浮窗');
+ assert.deepEqual(seen.item, [], '组里的另一条和取过的那一条又单条取了一次,点下去要等一个来回才换');
+ assert.equal(await page.evaluate(() => (window as unknown as { stageWatch: { rawControls: boolean } }).stageWatch.rawControls),
+ false, 'Peach 控件装上之前露出了 Video.js 原装的控制条或大播放键');
await page.locator('#closeStage').click();
await pathIs(page, '/follow');
await page.locator('[data-follow-list] > [data-follow-item]').first().waitFor({ timeout: 15_000 });
diff --git a/frontend/src/player/player.css b/frontend/src/player/player.css
index e2b35681d..a89097160 100644
--- a/frontend/src/player/player.css
+++ b/frontend/src/player/player.css
@@ -35,15 +35,11 @@ video.video-js{vertical-align:top;font-size:10px;line-height:1;font-family:Arial
/* 画面层的高度只跟着外框走。上面那条 `[data-stage-media] video` 的 76vh 是给裸 `<video>` 的,它同样
命中 Video.js 里面这一枚:影院模式把外框放高之后,画面还停在 76vh,底下空出一条黑边。 */
[data-stage-media] .video-js .vjs-tech{object-fit:contain;max-height:none}
-[data-stage-media] .video-js .vjs-big-play-button{left:50%;top:50%;width:56px;height:56px;margin:0;
- transform:translate(-50%,-50%);border:0;border-radius:50%;
- background:rgba(0,0,0,.3);box-shadow:none;line-height:56px}
-[data-stage-media] .video-js .vjs-big-play-button:hover,[data-stage-media] .video-js .vjs-big-play-button:focus{background:rgba(255,255,255,.1)}
-[data-stage-media] .video-js .vjs-big-play-button .vjs-icon-placeholder:before{content:"";left:50%;top:50%;width:0;height:0;
- border-top:.72em solid transparent;border-bottom:.72em solid transparent;border-left:1.05em solid #fff;
- transform:translate(-38%,-50%)}
/* 中心提示圆自己就是画面中央的播放态入口,原生大播放键留着只会跟它抢同一块地方。 */
-[data-stage-media] .video-js:has(.vjs-peach-bezel) .vjs-big-play-button{display:none}
+[data-stage-media] .video-js .vjs-big-play-button{display:none}
+/* Peach 的控件在 `player.ready` 里才装上(提示圆是其中一枚)。在那之前控制条是 Video.js 原装那一排:
+ 没有时间、没有右侧胶囊,播放键也没换上 Peach 的字形,机器一忙这一段就看得见。装上之前先藏着。 */
+[data-stage-media] .video-js:not(:has(.vjs-peach-bezel)) .vjs-control-bar{visibility:hidden}
/* YouTube e937390a `FsY` spinner DOM 与当前四段动画;复用 Video.js 的 waiting/seeking 状态。 */
[data-stage-media] .video-js .vjs-loading-spinner{z-index:18;left:50%;top:50%;width:64px;height:64px;margin:0;padding:0;border:0;border-radius:0;background:transparent;opacity:1;transform:translate(-50%,-50%)}
[data-stage-media] .video-js .vjs-loading-spinner:before,[data-stage-media] .video-js .vjs-loading-spinner:after{content:none}
diff --git a/frontend/src/react/follow-detail/follow-detail.ts b/frontend/src/react/follow-detail/follow-detail.ts
index 6bf697ae6..76b14051a 100644
--- a/frontend/src/react/follow-detail/follow-detail.ts
+++ b/frontend/src/react/follow-detail/follow-detail.ts
@@ -1,7 +1,7 @@
/* 关注详情 `/follow/item/:id` 的数据与判定(ADR-0031)。
*
* 这一块是舞台岛(`../stage/`)树里的子组件;舞台本身、进出场、小窗与 Video.js 归舞台岛
- * (JAV 详情也在用)。条目归这里:先扫关注页岛已缓存的那几页(`findFollowItem`),
+ * (JAV 详情也在用)。条目归这里:先扫关注页岛已缓存的那几页(`findFollowItem`)与已取过的详情,
* 扫不到才单条取 `GET /api/follow?item=<id>`,响应形状同列表那一页,只含这一条所在的组。 */
import type { QueryKey } from '@tanstack/react-query';
import { apiGet } from '../../api';
@@ -74,14 +74,28 @@ export async function fetchFollowItem(id: number, signal?: AbortSignal): Promise
throw new FollowItemGone();
}
-/** 首屏:列表缓存里有就直接用(关掉详情回列表也不重取),没有才单条取;凭据没取过才取。 */
+/** 已经取过的详情里,组里有这一条的那一份:合集换版本、多媒体换到组里另一条,组就是舞台上
+ * 正摆着的那一份,单条取回来的也只是同一组。 */
+function findDetailGroupItem(id: number): FollowDetailData | null {
+ for (const [, data] of queryClient.getQueriesData<FollowDetailData>({ queryKey: ['follow-item'] })) {
+ if (!data?.group) continue;
+ const item = collectionItems(data.group).find((member) => member.id === id);
+ if (item) return { ...data, item: item as FollowDetailItem };
+ }
+ return null;
+}
+
+/** 首屏:列表缓存里有就直接用(关掉详情回列表也不重取);这一条取过、或者就在舞台上那一组里,
+ * 也不再问服务端——点下去到换过去之间没有等待。都没有才单条取;凭据没取过才取。 */
export async function prefetchFollowDetail(props: { id: number }, signal: AbortSignal): Promise<void> {
const key = followItemKey(props.id);
const hit = findFollowItem(props.id);
const credentials = queryClient.getQueryData(FOLLOW_CREDENTIALS_KEY)
? null
: queryClient.fetchQuery({ queryKey: FOLLOW_CREDENTIALS_KEY, queryFn: () => fetchFollowCredentials(signal) });
- if (hit) queryClient.setQueryData<FollowDetailData>(key, { ...hit, item: hit.item as FollowDetailItem });
+ const cached = hit ? { ...hit, item: hit.item as FollowDetailItem }
+ : queryClient.getQueryData<FollowDetailData>(key) ?? findDetailGroupItem(props.id);
+ if (cached) queryClient.setQueryData<FollowDetailData>(key, cached);
else await queryClient.fetchQuery({ queryKey: key, queryFn: () => fetchFollowItem(props.id, signal) });
await credentials;
}
diff --git a/frontend/src/react/stage/stage.css b/frontend/src/react/stage/stage.css
index d00e8b314..3af637d5c 100644
--- a/frontend/src/react/stage/stage.css
+++ b/frontend/src/react/stage/stage.css
@@ -93,8 +93,11 @@ body[data-detail-open] [class~=glowlayer]::before{animation-play-state:paused,pa
[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-row]{display:block;position:relative;min-width:0;background:transparent;scroll-snap-align:start}
[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item]{display:flex;flex-direction:column;align-items:stretch;gap:7px;padding:0}
[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item]:hover,[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item][aria-current="true"]{background:transparent}
-[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item-pic]{width:100%;border:1px solid transparent}
-[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item][aria-current="true"] [data-mix-item-pic]{border-color:var(--ink);box-shadow:0 0 0 1px var(--ink)}
+[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item-pic]{width:100%}
+/* 当前那张的框画在格子里面:格子按圆角整块裁(clip-path),画在外面的阴影一律被裁掉。外圈墨色、
+ 里圈垫一道底色,几个版本的封面都是同一张深色画面时也认得出是哪一张。 */
+[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item][aria-current="true"] [data-mix-item-pic]:after{content:"";position:absolute;
+ inset:0;z-index:1;border-radius:var(--badge-radius);box-shadow:inset 0 0 0 2px var(--ink),inset 0 0 0 4px var(--ground);pointer-events:none}
[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item-meta]{width:100%;padding:0 2px;align-items:flex-start}
[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item-meta] [class~="mav"],[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item-meta] [class~="mavstack"]{margin-top:2px}
[data-stage-grid][data-with-queue]>[data-mix-queue] [data-mix-item-text]{flex:1;min-width:0}