Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(web): 开着又被禁的 Toggle 读成灰的

longmeidaoc5a38d147222
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index b0669aa03..6b7dce6b4 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -352,7 +352,7 @@ class WebUiSourceTests(unittest.TestCase):
":focus", # 焦点环::focus / :focus-visible / :focus-within
".geist-progress", ".watchprogress", ".vjs-play-progress", ".vjs-progress-holder",
".trace .bar", ".tokbar", # 进度与数据
- ":is(#censorSetting,#detailAutoplaySetting,.ptoggle):checked", # Toggle 开态:Geist Toggle 实测轨道 rgb(0,112,243)
+ ".ptoggle:checked", # Toggle 开态:Geist Toggle 实测轨道 rgb(0,112,243)
".entitylink", ".flink", ".fsourcelink", ".fcred a", ".tokauthor>a", ".confighelp a", ".taste-history-guide-content a", ".geist-text-link", # 真正的链接
)
@@ -1125,6 +1125,29 @@ class WebUiSourceTests(unittest.TestCase):
self.assertIn("cursor:not-allowed", css[start:css.index("}", start)],
f"{selector} 要给出禁止光标")
+ def test_a_disabled_toggle_reads_grey_even_when_it_is_on(self):
+ """开着又被禁的开关必须是灰的,不能还留着那抹蓝。
+
+ 「静默启动」只在「开机后启动 Peach」打开时才有意义,所以后者关着时它拿到
+ `disabled`。可轨道此前照旧是蓝的,只有标签变灰:Toggle 的选择器写成
+ `:is(#censorSetting,#detailAutoplaySetting,.ptoggle)`,而 `:is()` 取的是里面
+ 最强那一项的权重——混一个 id 进去,整组就是 (1,1,0),同文件末尾追加的
+ `.ptoggle:disabled` (0,2,0) 再也压不过 `:checked`。选择器里不许再有 id。
+ """
+ css = stylesheet_source()
+ self.assertNotIn("#censorSetting", css, "Toggle 的样式不靠 id 选中")
+ self.assertNotIn("#detailAutoplaySetting", css, "Toggle 的样式不靠 id 选中")
+ self.assertPageContains(".ptoggle:disabled{background:var(--surface);cursor:not-allowed}")
+ self.assertPageContains(".ptoggle:disabled::after{background:var(--muted)}")
+ self.assertPageContains(".ptoggle:disabled:checked{background:var(--surface)}")
+ # 禁用要写在开态之后,同权重下后写的赢。
+ self.assertLess(css.index(".ptoggle:checked{"), css.index(".ptoggle:disabled{"),
+ "禁用规则排在开态之后才压得住它")
+ # 两颗用 id 接线的开关也得带上这个类,否则它们一条样式都拿不到。
+ for line in ('class="ptoggle" type="checkbox" id="censorSetting"',
+ 'class="ptoggle" type="checkbox" id="detailAutoplaySetting"'):
+ self.assertPageContains(line)
+
def test_font_weights_stay_on_the_three_geist_steps(self):
"""字重只有 400/500/600 三档。
@@ -1725,7 +1748,7 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains('appSettings.detailAutoplay=appSettings.detailAutoplay!==false;')
self.assertPageContains('mountDetailPlayer(it,vv,appSettings.detailAutoplay)')
self.assertPageContains('mountDetailPlayer(item,followVideo,appSettings.detailAutoplay,{')
- self.assertPageContains('id="detailAutoplaySetting"')
+ self.assertPageContains('class="ptoggle" type="checkbox" id="detailAutoplaySetting"')
def test_entity_links_have_no_external_arrow(self):
# `target="_blank"` 已经是外链,箭头只是重复;一排链接里它还会挤掉本就不多的
@@ -6086,7 +6109,7 @@ class WebUiSourceTests(unittest.TestCase):
"""
# 顶栏不出现独立开关,开关在设置面板「安全」组。
self.assertPageLacks('id="censorBtn"')
- self.assertPageContains('id="censorSetting" role="switch" aria-describedby="sfwDescription"')
+ self.assertPageContains('class="ptoggle" type="checkbox" id="censorSetting" role="switch" aria-describedby="sfwDescription"')
self.assertPageContains('<b>SFW 模式</b><small id="sfwDescription">')
self.assertPageContains('模糊、降低饱和度并压暗全站图片和视频,包括封面、头像与详情预览;停止悬停预览。文字、品牌标识和来源图标保持可见。')
self.assertPageLacks('共享屏幕或截图前开启,遮住全站封面与预览图。')
@@ -6156,8 +6179,8 @@ class WebUiSourceTests(unittest.TestCase):
self.assertNotIn("box-shadow:0 8px 32px -12px", self.css, "浮层靠发丝线不靠投影")
# 布尔开关是 Geist 中号 Toggle(36×20 轨道 + 17px 圆点),不是原生复选框;
# Geist 的 Switch 是分段选择器,别用错控件。
- self.assertPageContains(":is(#censorSetting,#detailAutoplaySetting,.ptoggle){appearance:none;-webkit-appearance:none;width:36px;height:20px;flex:none;")
- self.assertPageContains(":is(#censorSetting,#detailAutoplaySetting,.ptoggle):checked{background:var(--tungsten)}")
+ self.assertPageContains(".ptoggle{appearance:none;-webkit-appearance:none;width:36px;height:20px;flex:none;")
+ self.assertPageContains(".ptoggle:checked{background:var(--tungsten)}")
# 没有直接证据的 command-menu 入场动画与无有效高度约束的复核卡
# Scroller 不应继续作为「Vercel 对齐」进入产品。
self.assertPageLacks("animation:panel-in")
diff --git a/web/css/16-settings.css b/web/css/16-settings.css
index be10a1c59..3ad96af10 100644
--- a/web/css/16-settings.css
+++ b/web/css/16-settings.css
@@ -43,15 +43,24 @@ body.settings-open{overflow:hidden}
.settinggroup .settingrow{margin:0;padding-left:0;padding-right:0}
/* 布尔开关用 Geist Toggle 而不是原生复选框(取证 vercel-geist-semantics-measured.md):
中号 36×20 轨道 + 17px 圆点,关 = 灰轨道圆点靠左,开 = 主题蓝圆点靠右;
- Geist 的「Switch」是分段选择器(radio 语义),布尔开关的正确控件叫 Toggle。 */
-:is(#censorSetting,#detailAutoplaySetting,.ptoggle){appearance:none;-webkit-appearance:none;width:36px;height:20px;flex:none;
+ Geist 的「Switch」是分段选择器(radio 语义),布尔开关的正确控件叫 Toggle。
+ 选择器只认 `.ptoggle` 这一个类,不许再把 id 混进 `:is()`:`:is()` 取的是里面最强的
+ 那一项的权重,混一个 id 进去整组就变成 (1,x,0),同文件后面任何 `.ptoggle` 规则都再也
+ 压不过它。开态和禁用态于是同时成立——「静默启动」在「开机后启动」关着时明明拿到了
+ `disabled`,轨道却仍是那抹蓝,只有标签变灰。 */
+.ptoggle{appearance:none;-webkit-appearance:none;width:36px;height:20px;flex:none;
border:0;box-sizing:border-box;padding:0;border-radius:var(--pill-radius);background:var(--line);position:relative;cursor:pointer;margin:0;
transition:background-color .15s ease}
-:is(#censorSetting,#detailAutoplaySetting,.ptoggle)::after{content:'';position:absolute;top:1.5px;left:2px;width:17px;height:17px;
+.ptoggle::after{content:'';position:absolute;top:1.5px;left:2px;width:17px;height:17px;
border-radius:50%;background:#fff;transition:left .15s ease}
-:is(#censorSetting,#detailAutoplaySetting,.ptoggle):checked{background:var(--tungsten)}
-:is(#censorSetting,#detailAutoplaySetting,.ptoggle):checked::after{left:17px}
-:is(#censorSetting,#detailAutoplaySetting,.ptoggle):focus-visible{outline:2px solid var(--tungsten);outline-offset:2px}
+.ptoggle:checked{background:var(--tungsten)}
+.ptoggle:checked::after{left:17px}
+.ptoggle:focus-visible{outline:2px solid var(--tungsten);outline-offset:2px}
+/* 禁用要压过开态,所以写在 `:checked` 之后:一颗开着又被禁的开关(「静默启动」在
+ 「开机后启动」关着时就是这样)得读成灰的,不是蓝的。 */
+.ptoggle:disabled{background:var(--surface);cursor:not-allowed}
+.ptoggle:disabled::after{background:var(--muted)}
+.ptoggle:disabled:checked{background:var(--surface)}
/* 主题选择器是 Geist 里唯一给选中项加环的控件:三档的底色和它坐着的面板同色,
光靠填充分不出当前是哪一档。几何按 2026-09-04 实测 vercel.com 的 system/light/dark
三枚圆形按钮:外框是 32px 高、无填充的胶囊加一圈 1px 环,每档 32×32 正圆、图标 16px,
@@ -82,5 +91,3 @@ body.settings-open{overflow:hidden}
.settingrow .gselect{width:100%;min-width:0}.settingrow .pcheck{justify-self:start}}
.sidebaradd .sidebaraddmenu button{justify-items:start}
-.ptoggle:disabled{background:var(--surface);cursor:not-allowed}
-.ptoggle:disabled::after{background:var(--muted)}
diff --git a/web/index.html b/web/index.html
index e4bd150de..7f928138b 100644
--- a/web/index.html
+++ b/web/index.html
@@ -240,7 +240,7 @@
</section>
<section class="settinggroup"><h3>播放</h3>
<div class="settingrow"><span><b>悬停放大</b><small>转圈完成后进入放大预览。</small></span><div id="hoverDelaySetting"></div></div>
- <label class="settingrow"><span><b>打开详情自动播放</b><small id="detailAutoplayDescription">打开本地作品或关注视频详情时开始播放;关闭后点击播放按钮开始。</small></span><input type="checkbox" id="detailAutoplaySetting" role="switch" aria-describedby="detailAutoplayDescription"></label>
+ <label class="settingrow"><span><b>打开详情自动播放</b><small id="detailAutoplayDescription">打开本地作品或关注视频详情时开始播放;关闭后点击播放按钮开始。</small></span><input class="ptoggle" type="checkbox" id="detailAutoplaySetting" role="switch" aria-describedby="detailAutoplayDescription"></label>
<label class="settingrow"><span><b>小窗播放</b><small id="miniplayerDescription">离开详情时正在播放的视频缩到角落继续播放;小窗开着时点击其他视频直接在小窗里换片。</small></span><input type="checkbox" id="miniplayerSetting" class="ptoggle" role="switch" aria-describedby="miniplayerDescription"></label>
<div class="settingrow"><span><b>快进 / 快退</b><small>卡片预览和详情播放器共用。</small></span><div id="seekSecondsSetting"></div></div>
<div class="settingrow"><span><b>相关推荐</b><small>详情下方一次显示的相似作品数量。</small></span><div id="relatedLimitSetting"></div></div>
@@ -252,7 +252,7 @@
<div class="settingrow"><span><b>关注自动更新</b><small id="followScheduleState" aria-live="polite">读取运行状态…</small></span><div id="followScheduleSetting"></div></div>
</section>
<section class="settinggroup"><h3>安全</h3>
- <label class="settingrow"><span><b>SFW 模式</b><small id="sfwDescription">模糊、降低饱和度并压暗全站图片和视频,包括封面、头像与详情预览;停止悬停预览。文字、品牌标识和来源图标保持可见。</small></span><input type="checkbox" id="censorSetting" role="switch" aria-describedby="sfwDescription"></label>
+ <label class="settingrow"><span><b>SFW 模式</b><small id="sfwDescription">模糊、降低饱和度并压暗全站图片和视频,包括封面、头像与详情预览;停止悬停预览。文字、品牌标识和来源图标保持可见。</small></span><input class="ptoggle" type="checkbox" id="censorSetting" role="switch" aria-describedby="sfwDescription"></label>
</section>
</div>
</div>