Skip to content

armgit / peach

Public Imported from GitHub
0

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

feat(web): 播放器两块浮层互斥、播放速度不再被切,详情标题行改浮动

longmeidaod400cdc0b29e
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index 81e1880e3..3fad6abf8 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -1813,23 +1813,67 @@ class WebUiSourceTests(unittest.TestCase):
def test_narrow_player_keeps_both_overlays_inside_the_frame(self):
"""390 宽的视口上 16:9 的播放器只有 200 出头的高,设置面板要 212、统计面板要 256。
- 所以先给播放器一个 280px 的最低高度,窄屏改成上下留黑边;再让两个浮层各自
+ 所以先给播放器一个 320px 的最低高度,窄屏改成上下留黑边;再让两个浮层各自
按播放器高度收顶,谁都不可能超过播放器本身。窄屏的设置面板还要撤掉
`right:-100px`——那个偏移是给设置键右边还有影院键和全屏键时留的位。
"""
self.assertPageContains(
- ".vwrap>.video-js{width:100%;height:auto;min-height:280px;max-height:76vh;"
+ ".vwrap>.video-js{width:100%;height:auto;min-height:320px;max-height:76vh;"
"aspect-ratio:16/9;background:#000}")
- self.assertPageContains(".gate{aspect-ratio:16/9;width:100%;min-height:280px")
+ self.assertPageContains(".gate{aspect-ratio:16/9;width:100%;min-height:320px")
self.assertPageContains(
"max-height:calc(100% - 114px);overflow-y:auto;overscroll-behavior:contain;")
self.assertPageContains(
".video-js.vjs-peach-xsmall .vjs-peach-settings-menu{right:0;"
"width:min(274px,calc(100vw - 48px));")
- self.assertPageContains("max-height:calc(var(--peach-player-h,420px) - 64px)}")
+ self.assertPageContains("max-height:calc(var(--peach-player-h,420px) - 74px)}")
# 面板的定位祖先只有 36px 高,百分比高度到不了播放器,得由布局脚本把高度写上来。
self.assertPageContains("box.style.setProperty('--peach-player-h',`${box.clientHeight}px`)")
+ def test_narrow_settings_panel_fits_eight_speed_options_without_scrolling(self):
+ """八档播放速度单列要 57+16+8×48=457px,320px 高的播放器只给得出 246px。
+
+ 行高压到 44px、排成两列是 57+8+4×44=241px;只让选项多于四条的列表分两列,
+ 主面板那三行仍是单列。
+ """
+ self.assertPageContains(".video-js.vjs-peach-xsmall .vjs-peach-panel-menu{padding:4px 8px}")
+ self.assertPageContains(".video-js.vjs-peach-xsmall .vjs-peach-menu-option{min-height:44px}")
+ self.assertPageContains(
+ ".video-js.vjs-peach-xsmall .vjs-peach-panel-menu"
+ ":has(>.vjs-peach-menu-option:nth-child(5)){display:grid;grid-template-columns:1fr 1fr}")
+
+ def test_opening_one_player_overlay_closes_the_other(self):
+ """设置面板和播放统计都盖在画面上,同时开就互相遮挡,开哪个另一个自己收起。
+
+ 两块面板挂在不同作用域里,共享一个 document 事件名比互相持有引用干净。
+ """
+ self.assertPageContains("const PLAYER_PANEL_EVENT='peach-player-panel';")
+ self.assertPageContains(
+ "if(open)document.dispatchEvent(new CustomEvent(PLAYER_PANEL_EVENT,{detail:'settings'}))};")
+ self.assertPageContains(
+ "const closeSettingsForOtherPanel=event=>{if(event.detail!=='settings')close()};")
+ self.assertPageContains(
+ "document.dispatchEvent(new CustomEvent(PLAYER_PANEL_EVENT,{detail:'stats'}));")
+ self.assertPageContains(
+ "const closeStatsForOtherPanel=event=>{if(event.detail!=='stats')closeStats()};")
+ # 两个监听都挂在 document 上,播放器销毁时必须摘掉,否则换条目后旧闭包继续收事件。
+ self.assertPageContains(
+ "document.removeEventListener(PLAYER_PANEL_EVENT,closeSettingsForOtherPanel);")
+ self.assertPageContains(
+ "detailPlayer.on('dispose',()=>document.removeEventListener(PLAYER_PANEL_EVENT,closeStatsForOtherPanel));")
+
+ def test_control_tooltip_is_dark_enough_to_read_as_a_label(self):
+ """按钮提示的底色和播放器其它悬浮件同一档黑。
+
+ rgba(0,0,0,.3) 配 blur(16px) 落在亮画面上只剩一块低对比灰板,悬停时看着像
+ 凭空多出来一块阴影而不是一条说明。
+ """
+ for selector in (".vjs-peach-tooltip{", ".vjs-volume-tooltip{"):
+ # 声明外观的那条规则在前,后面同名选择器只切 display,取第一处。
+ start = self.css.index(selector)
+ rule = self.css[start:self.css.index("}", start)]
+ self.assertIn("background:rgba(0,0,0,.6)", rule, f"{selector} 和同屏的悬浮件不是一档黑")
+
def test_narrow_settings_keep_the_toggle_on_the_title_row(self):
"""窄屏那条单列是给 select 留的:148px 的下拉配上标题和说明挤不下。
@@ -3692,16 +3736,20 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("openItem(+button.dataset.reviewOpenItem)")
def test_detail_title_keeps_source_and_file_actions_inline(self):
- """定位文件与刷新跟在标题文字后面,不单占一列。
+ """来源徽标浮左、定位文件与刷新浮右,两者都浮出标题的文字流。
- 标题会折行,工具键单占一个网格列时那一列的宽度按最宽的一行留着,标题短的条目
- 右边就空出一大块,而标题长的条目仍被挤成三四行。
+ 三者并排参与弹性布局时,徽标那一列会把标题的每一行都缩进,右端 66px 的动作
+ 又在标题占满一行时被整块挤到下一行;浮动只缩短第一行的行盒,动作也留在行末。
"""
- self.assertPageContains('<div class="detailtitle">${srcBadge(it.location,it.cost,\'srcbig\')}')
- self.assertPageContains('<div class="stitle">${javTitleHtml(it)}')
- self.assertPageContains('<span class="srctools detailtitletools">${sourceToolButtons(it.id)}</span>')
- self.assertPageContains(".detailtitle{display:flex;align-items:flex-start;gap:8px")
- self.assertPageContains(".detailtitletools{display:inline-flex;vertical-align:middle;margin:0 0 0 8px")
+ self.assertPageContains(
+ '<div class="detailtitle">${srcBadge(it.location,it.cost,\'srcbig\')}'
+ '${it.location===\'online\'?\'\':`<span class="srctools detailtitletools">'
+ '${sourceToolButtons(it.id)}</span>`}')
+ self.assertPageContains('<div class="stitle">${javTitleHtml(it)}</div></div>')
+ self.assertPageContains(".detailtitle{display:flow-root;margin-bottom:10px}")
+ self.assertPageContains(".detailtitletools{float:right;height:26px;margin:0 0 2px 8px;flex-wrap:nowrap}")
+ # 浮动块整好一行高(28px),行高 1.75 既让 26px 的按钮上下留出空隙,也让第二行起整行宽。
+ self.assertPageContains(".detailtitle .stitle{min-width:0;margin:0;line-height:1.75}")
def test_detail_metadata_uses_icons_instead_of_release_copy(self):
self.assertPageContains('<span class="detailmetaitem">${icon(\'monitor\')}')
@@ -4101,7 +4149,8 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("width:var(--id-face,46px);height:var(--id-face,46px)")
def test_detail_source_icon_starts_at_the_content_edge(self):
- self.assertPageContains(".detailtitle>.srcbig{place-items:start;flex:none;width:17px;margin-top:2px}")
+ self.assertPageContains(
+ ".detailtitle>.srcbig{float:left;width:17px;height:28px;margin:0 8px 0 0;place-items:center}")
def test_official_tags_do_not_have_a_visible_marker(self):
self.assertPageLacks(".detailtag .tagfilter small{")
diff --git a/web/app.css b/web/app.css
index ef372710f..d43767a03 100644
--- a/web/app.css
+++ b/web/app.css
@@ -1226,7 +1226,7 @@ body.index-open #tiers,body.index-open #tagbar{display:none}
/* 窄屏下 16:9 只剩 200px 出头,设置面板和统计面板都比这高,必然被裁。给播放器一个
最低高度,画面按 object-fit:contain 上下补黑边,浮层就有地方站。占位门同用一个值,
否则点开的一瞬间整页会往下跳一截。 */
-.vwrap>.video-js{width:100%;height:auto;min-height:280px;max-height:76vh;aspect-ratio:16/9;background:#000}
+.vwrap>.video-js{width:100%;height:auto;min-height:320px;max-height:76vh;aspect-ratio:16/9;background:#000}
.vwrap .video-js .vjs-tech{object-fit:contain}
.vwrap .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%;
@@ -1329,7 +1329,7 @@ body.index-open #tiers,body.index-open #tagbar{display:none}
.vwrap .video-js .vjs-volume-panel .vjs-volume-level{height:2px;background:#fff}
.vwrap .video-js .vjs-volume-panel .vjs-volume-level:before{top:50%;right:-6px;width:12px;height:12px;margin:0;font-size:0;border-radius:50%;background:#fff;transform:translateY(-50%)}
.vwrap .video-js .vjs-volume-panel .vjs-volume-tooltip{z-index:5!important;left:50%;right:auto;top:auto;bottom:calc(100% + 32px);
- float:none;transform:translateX(-50%);padding:5px 9px;border-radius:var(--surface-radius);background:rgba(0,0,0,.3);
+ float:none;transform:translateX(-50%);padding:5px 9px;border-radius:var(--surface-radius);background:rgba(0,0,0,.6);
backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);color:#fff;font-family:inherit;font-size:var(--fs-sm);font-weight:500;
line-height:15px;text-shadow:0 0 2px #000;overflow:visible;white-space:nowrap}
.vjs-peach-right-controls{box-sizing:border-box;position:relative;align-self:flex-end;flex:0 0 auto;height:40px;margin:0 0 8px;
@@ -1418,11 +1418,13 @@ body.index-open #tiers,body.index-open #tagbar{display:none}
.vjs-peach-option-check{width:35px;height:24px;display:grid;place-items:center}.vjs-peach-option-check svg{width:24px;height:24px;display:block;fill:currentColor;stroke:none}
.vjs-peach-option-label{min-width:0}
/* 悬停提示取自 YouTube delhi-modern(player 9470c977 的 www-player.css):毛玻璃 blur(16px)、
- rgba(0,0,0,.3) 底、8px 圆角(--surface-radius)、5px 9px 内距、13px/15px 500 字重(--fs-sm)、
+ 8px 圆角(--surface-radius)、5px 9px 内距、13px/15px 500 字重(--fs-sm)、
text-shadow 0 0 2px #000;快捷键徽标 1px rgba(255,255,255,.3) 边、4px 圆角(--badge-radius)、
- 最小宽 11px、左外边距 4px,空了就收起。控制条上每个按钮共用这一套。 */
+ 最小宽 11px、左外边距 4px,空了就收起。控制条上每个按钮共用这一套。
+ 底色是 Peach 主动偏离上游的一处:上游 rgba(0,0,0,.3) 加 blur 落在亮画面上只剩一块低对比
+ 灰板,悬停时看着像凭空多出来一块阴影。提示和播放器其它悬浮件同档,一律 rgba(0,0,0,.6)。 */
.vjs-peach-tooltip{position:absolute;z-index:5;right:50%;bottom:calc(100% + 12px);transform:translateX(50%);
- display:none;align-items:center;padding:5px 9px;border-radius:var(--surface-radius);background:rgba(0,0,0,.3);
+ display:none;align-items:center;padding:5px 9px;border-radius:var(--surface-radius);background:rgba(0,0,0,.6);
backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);color:#fff;white-space:nowrap;
font-size:var(--fs-sm);font-weight:500;line-height:15px;text-shadow:0 0 2px #000;pointer-events:none}
.vjs-peach-tooltip kbd{display:flex;justify-content:center;align-items:center;min-width:11px;margin-left:4px;padding:0 2px;
@@ -1459,7 +1461,13 @@ body.index-open #tiers,body.index-open #tagbar{display:none}
窄屏照原样偏移会把整个面板推到播放器外面。贴住设置键右缘往左铺,高度按播放器
自己的高度收顶(`--peach-player-h` 由布局脚本写在播放器元素上)。 */
.video-js.vjs-peach-xsmall .vjs-peach-settings-menu{right:0;width:min(274px,calc(100vw - 48px));
- max-height:calc(var(--peach-player-h,420px) - 64px)}
+ max-height:calc(var(--peach-player-h,420px) - 74px)}
+/* 面板底边离播放器底边 66px(离设置键 52px 加控制条那 14px),顶上再留 8px,所以收顶取
+ 播放器高度减 74px:320px 高的播放器给出 246px。八档播放速度单列要 57+16+8×48=457px,
+ 排两列、行高 44px 是 57+8+4×44=241px,最挤的那个面板也不用滚。 */
+.video-js.vjs-peach-xsmall .vjs-peach-panel-menu{padding:4px 8px}
+.video-js.vjs-peach-xsmall .vjs-peach-menu-option{min-height:44px}
+.video-js.vjs-peach-xsmall .vjs-peach-panel-menu:has(>.vjs-peach-menu-option:nth-child(5)){display:grid;grid-template-columns:1fr 1fr}
.video-js.vjs-peach-xsmall .vjs-peach-right-controls>.vjs-control:not(.vjs-peach-settings):not(.vjs-peach-expand){display:none}
.video-js.vjs-peach-xsmall .vjs-peach-expand{display:block}
.video-js.vjs-peach-xsmall.vjs-peach-right-expanded .vjs-peach-right-controls>.vjs-control:not(.vjs-peach-settings):not(.vjs-peach-expand){display:block}
@@ -1510,7 +1518,7 @@ body.index-open #tiers,body.index-open #tagbar{display:none}
否则「640 KB/s」会在这条 flex 行里断成两行,把 40px 的胶囊顶破。 */
.playernet svg{width:18px;height:18px;flex:none;stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round}
.playernet[hidden]{display:none}
-.gate{aspect-ratio:16/9;width:100%;min-height:280px;background:var(--sunk);border:1px dashed var(--meter);
+.gate{aspect-ratio:16/9;width:100%;min-height:320px;background:var(--sunk);border:1px dashed var(--meter);
display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;cursor:pointer}
/* 占位说明的字号原先写在 openItem 的模板里当内联 style,三处各写一遍、
连 `color:var(--muted)` 也抄了三份。 */
@@ -1532,8 +1540,12 @@ body.index-open #tiers,body.index-open #tagbar{display:none}
.sidecontent{box-sizing:border-box;width:100%;height:100%;max-height:76vh;padding:18px;display:flex;gap:0;
flex-direction:column;overflow-y:auto;overflow-x:hidden}
.stitle{font-size:var(--fs-lg);line-height:1.4;word-break:break-all;margin-bottom:8px}
-.detailtitle{display:flex;align-items:flex-start;gap:8px;margin-bottom:10px}
-.detailtitle>.srcbig{place-items:start;flex:none;width:17px;margin-top:2px}.detailtitle .stitle{min-width:0;margin:0}
+/* 来源徽标和两个文件动作都浮出标题的文字流:徽标浮左只缩进第一行,折行后的第二行顶到
+ 内容左边缘;动作浮右占住行末那 66px,右边有空间时不会被挤到下一行。两个浮动块都刚好
+ 一行高(28px),所以第二行起是整行宽。行高 1.75 让 26px 的按钮上下各留出空隙。 */
+.detailtitle{display:flow-root;margin-bottom:10px}
+.detailtitle>.srcbig{float:left;width:17px;height:28px;margin:0 8px 0 0;place-items:center}
+.detailtitle .stitle{min-width:0;margin:0;line-height:1.75}
/* 源文件管理:定位 + 目录对账。图标必须显式写 stroke/fill,Lucide 是描边路径,
缺了就被按默认 fill:black 画成黑块(详见 .photonav 那一段的同类修复)。 */
.srctools{display:flex;align-items:center;gap:6px;margin:0 0 10px;flex-wrap:wrap}
@@ -1544,7 +1556,7 @@ body.index-open #tiers,body.index-open #tagbar{display:none}
.srctools button:hover{background:var(--hover);color:var(--ink)}
.srctools button:disabled{background:var(--surface);border-color:var(--border-15);color:var(--muted);cursor:default}
.srcstate{font-size:var(--fs-xs);color:var(--muted);min-width:0;flex:1 1 100%}
-.detailtitletools{display:inline-flex;vertical-align:middle;margin:0 0 0 8px;translate:0 -2px;flex-wrap:nowrap}.detailtitlestate{display:block;margin:-4px 0 10px}
+.detailtitletools{float:right;height:26px;margin:0 0 2px 8px;flex-wrap:nowrap}.detailtitlestate{display:block;margin:-4px 0 10px}
.detailtitlestate:empty{display:none}
.photohead .srctools{margin:0 0 0 auto}
.photohead .srcstate{flex:none}
diff --git a/web/app.js b/web/app.js
index 839eca52c..660bbbf1b 100644
--- a/web/app.js
+++ b/web/app.js
@@ -718,6 +718,9 @@ function pushPlayerStat(samples,value){
samples.push(Number.isFinite(value)&&value>0?value:0);
if(samples.length>PLAYER_STATS_HISTORY)samples.splice(0,samples.length-PLAYER_STATS_HISTORY);
}
+/* 设置面板和播放统计都盖在画面上,同时开就互相遮挡。开哪个都往 document 广播一次,
+ 另一个自己收起:两块面板挂在不同的作用域里,共享一个事件名比互相持有引用干净。 */
+const PLAYER_PANEL_EVENT='peach-player-panel';
function playerStatsPlot(samples,kind,ceiling,label){
const values=Array(Math.max(0,PLAYER_STATS_HISTORY-samples.length)).fill(null).concat(samples);
const top=Math.max(1,ceiling||0);
@@ -870,8 +873,11 @@ function mountPlayerQualityControl(player,video,fallbackHeight=0,initialSourceQu
return {options,active};
};
const isOpen=()=>menu.getAttribute('aria-hidden')!=='true';
- const setOpen=open=>{menu.setAttribute('aria-hidden',String(!open));toggle.setAttribute('aria-expanded',String(open))};
+ const setOpen=open=>{menu.setAttribute('aria-hidden',String(!open));toggle.setAttribute('aria-expanded',String(open));
+ if(open)document.dispatchEvent(new CustomEvent(PLAYER_PANEL_EVENT,{detail:'settings'}))};
const close=()=>setOpen(false);
+ const closeSettingsForOtherPanel=event=>{if(event.detail!=='settings')close()};
+ document.addEventListener(PLAYER_PANEL_EVENT,closeSettingsForOtherPanel);
/* 面板之间的切换照 YouTube 播放器 9470c977 的 www-player.css:popup 自己 .25s
cubic-bezier(.4,0,.2,1) 改高度,旧面板往来的方向滑出、新面板从去的方向滑入。
旧面板必须先脱离布局再滑,否则两块内容会在动画期间把菜单撑成两倍高;高度也得
@@ -945,7 +951,9 @@ function mountPlayerQualityControl(player,video,fallbackHeight=0,initialSourceQu
root.addEventListener('keydown',event=>{if(event.key==='Escape'){close();toggle.focus()}});
video.addEventListener('loadedmetadata',()=>{if(isOpen())showMain();else qualityRows()});
levels?.on?.(['addqualitylevel','removequalitylevel'],()=>{if(isOpen())showMain();else qualityRows()});
- player.on('dispose',()=>{document.removeEventListener('pointerdown',outside);if(panelTimer)clearTimeout(panelTimer)});qualityRows();
+ player.on('dispose',()=>{document.removeEventListener('pointerdown',outside);
+ document.removeEventListener(PLAYER_PANEL_EVENT,closeSettingsForOtherPanel);
+ if(panelTimer)clearTimeout(panelTimer)});qualityRows();
mountPlayerTheaterControl(player,root);
mountPlayerChromeLayout(player);
return next=>{sourceQualities=next?.length?next:null;if(isOpen())showMain();else qualityRows()};
@@ -1241,11 +1249,22 @@ async function mountDetailPlayer(it,video,autoplay,options={}){
mountPlayerCenterControls(detailPlayer);
if(statsButton)statsButton.hidden=false
});
- if(statsButton&&statsPanel)statsButton.onclick=()=>{
- const open=statsPanel.hidden;statsPanel.hidden=!open;statsButton.setAttribute('aria-pressed',String(open));
- if(open){updateStats();if(detailStatsTimer)clearInterval(detailStatsTimer);detailStatsTimer=setInterval(updateStats,1000)}
- else if(detailStatsTimer){clearInterval(detailStatsTimer);detailStatsTimer=null}
- };
+ if(statsButton&&statsPanel){
+ const closeStats=()=>{
+ if(statsPanel.hidden)return;
+ statsPanel.hidden=true;statsButton.setAttribute('aria-pressed','false');
+ if(detailStatsTimer){clearInterval(detailStatsTimer);detailStatsTimer=null}
+ };
+ statsButton.onclick=()=>{
+ if(!statsPanel.hidden){closeStats();return}
+ document.dispatchEvent(new CustomEvent(PLAYER_PANEL_EVENT,{detail:'stats'}));
+ statsPanel.hidden=false;statsButton.setAttribute('aria-pressed','true');
+ updateStats();if(detailStatsTimer)clearInterval(detailStatsTimer);detailStatsTimer=setInterval(updateStats,1000);
+ };
+ const closeStatsForOtherPanel=event=>{if(event.detail!=='stats')closeStats()};
+ document.addEventListener(PLAYER_PANEL_EVENT,closeStatsForOtherPanel);
+ detailPlayer.on('dispose',()=>document.removeEventListener(PLAYER_PANEL_EVENT,closeStatsForOtherPanel));
+ }
source().then(source=>{
if(!detailPlayer||detailPlayer!==player||player.isDisposed())return;
segmentedSource=String(source.type||'').includes('mpegurl');
@@ -6278,8 +6297,8 @@ async function openItem(id,push=true,queueContext=null,anchor=null){
:`<video id="vid" class="video-js vjs-big-play-centered" controls playsinline preload="metadata"></video>`}
</div>${queueContext?queueHtml(queueContext,it.id):''}
<div class="side"><div class="sidecontent">
- <div class="detailtitle">${srcBadge(it.location,it.cost,'srcbig')}
- <div class="stitle">${javTitleHtml(it)}${it.location==='online'?'':`<span class="srctools detailtitletools">${sourceToolButtons(it.id)}</span>`}</div></div>
+ <div class="detailtitle">${srcBadge(it.location,it.cost,'srcbig')}${it.location==='online'?'':`<span class="srctools detailtitletools">${sourceToolButtons(it.id)}</span>`}
+ <div class="stitle">${javTitleHtml(it)}</div></div>
${it.location==='online'?'':`<span class="srcstate detailtitlestate" aria-live="polite"></span>`}
<div class="smeta mono">
<span class="detailmetaitem">${icon('monitor')}<span>${it.width||'?'}×${it.height||'?'}</span></span>