Peach: Local-first video metadata scraper and media manager.
feat(web): 凭据行接上 Collapse 与 favicon,关注列表加紧凑版式开关
longmeidao84aefe918c36
diff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex 2e9600e09..31b6a3832 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -1840,6 +1840,71 @@ class FollowWebSourceTests(unittest.TestCase):self.assertPageContains('.faliasmanager>summary[aria-expanded="false"]{border-radius:0 0 calc(var(--surface-radius) - 1px) calc(var(--surface-radius) - 1px)}')self.assertPageContains(".faliasmanager .fcollapsebody{padding:4px 13px 14px}")+ def test_credential_rows_share_the_alias_collapse_motion(self):+ """凭据行早先是 flex 行布局接不上 Collapse。++ `details.fcred` 已经统一成 block,两处就该是同一份实现——展开一段正文这件事+ 不该有第二套开合逻辑。+ """+ self.assertPageContains("export function wireCollapse(root,selector,idPrefix)")+ self.assertPageContains("wireCollapse(root,'details.faliasmanager','follow-alias-collapse')")+ self.assertPageContains("wireCollapse(root,'details.fcred','follow-cred-collapse')")+ self.assertEqual(self.page.count("body.style.height=body.scrollHeight+'px'"), 1,+ "开合逻辑只该有一份")+ # 内边距归 .fcollapsebody:留在 .fcred[open] 上的话,收起那一帧高度已经归零、+ # 内边距还在,行尾会跳一下。+ self.assertPageContains(".fcred .fcollapsebody{padding:8px 0 12px}")+ self.assertPageLacks(".fcred[open]{padding-bottom")+ # 首段自己的上边距换成容器内边距,否则它跟容器外边距合并,scrollHeight 量矮一截。+ self.assertPageContains(".fcred .fcollapsebody>p:first-child{margin-top:0}")++ def test_credential_rows_carry_the_same_favicon_as_their_source(self):+ """凭据配的就是那个站,用来源行同一枚 favicon 指认它。"""+ self.assertPageContains(+ 'const mark=`<span class="ficonslot" aria-hidden="true">${sourceIcon(row.provider)}</span>`')+ self.assertPageContains('<div class="frow fcred none">${mark}<b>${esc(row.provider_label)}</b>')+ self.assertPageContains("<summary>${mark}<b>${esc(row.provider_label)}</b>")+ # 槽位占住 14px,不看里面有没有图:没登记 favicon 的站本来就没有,取不下来的+ # 那些还会被 data-drop="self" 整个丢掉,两种情况都会让名字的左边缘参差。+ self.assertPageContains(".fcred .ficonslot{flex:none;display:block;width:14px;height:14px}")+ self.assertPageContains(".fcred .ficon{margin-right:0}")+ self.assertIn('data-drop="self"', self.page)++ def test_the_follow_list_has_a_compact_switch_that_puts_two_per_row(self):+ """两个互斥视图用 Switch(共享 name 的 radio),不是 Toggle。"""+ self.assertPageContains(+ "const FOLLOW_LAYOUTS=[['cozy','舒适 · 一行一个','maximize'],"+ "['compact','紧凑 · 一行两个','layout-grid']]")+ self.assertPageContains(+ "iconSwitchHtml('follow-layout','关注列表版式',FOLLOW_LAYOUTS,followListLayout()")+ self.assertPageContains("{attr:'data-follow-layout'}")+ self.assertPageContains("${followLayoutButtons()}")+ self.assertPageContains("wireIconSwitch(root,'data-follow-layout',setFollowListLayout)")+ # 版式是纯展示层的事:改容器上的一个属性就够,不重画列表,也不重新请求。+ self.assertPageContains('<div class="frows fsources" data-layout="${followListLayout()}">')+ self.assertPageContains("node.dataset.layout=followListLayout()")+ # 紧凑就是一行两个;半幅宽度放不下六列,收掉最不影响判断的「上次检查」。+ self.assertPageContains(+ '.fsources[data-layout="compact"]{grid-template-columns:repeat(2,minmax(0,1fr))}')+ self.assertPageContains('.fsources[data-layout="compact"] .fsource .fchecked{display:none}')+ # 窄屏两栏塞不下,仍旧回到一栏——媒体查询要连紧凑一起覆盖,否则属性选择器更具体。+ self.assertPageContains('.fsources,.fsources[data-layout="compact"]{grid-template-columns:1fr}')+ # 窄屏两栏不成立,开关一起收起,不留一个按了没反应的控件。+ self.assertPageContains('.fsechead .iconswitch{display:none}')+ # 选择要留下来,和 JAV 版式一样存进设置。+ self.assertPageContains("javLayout:'big',followLayout:'cozy'")+ self.assertPageContains("appSettings.followLayout=value")+ self.assertPageContains(+ "allowedSetting(appSettings.followLayout,FOLLOW_LAYOUTS.map(([k])=>k),'cozy')")++ def test_the_layout_switch_lines_up_with_the_sort_box(self):+ """开关和排序框、按钮同处分区标题行,高度必须是同一档。"""+ rule = self.page[self.page.index(".fsechead .iconswitch{"):]+ rule = rule[:rule.index("}")]+ self.assertIn("flex:none", rule)+ self.assertIn("padding:2px", rule)+ self.assertPageContains(".fsechead .iconswitch label{width:32px;height:26px}")+def test_alias_count_badge_is_neutral_metadata(self):"""「3 组」只是计数,不是待处理提醒:徽章走 Geist gray badge 的中性灰。diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex 30aef70c2..b57f2b48c 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -3975,11 +3975,14 @@ class WebUiSourceTests(unittest.TestCase):self.assertPageContains("${javActive()?javLayoutButtons():''}")self.assertPageContains("wireJavLayoutButtons(section)")self.assertPageContains("renderEntityCollection(kind,name,{...entityCollectionPage,items:[...entityCollectionPage.items]}")- self.assertPageContains('<fieldset class="javlayout"><legend class="sr-only">JAV 卡片版式</legend>')- self.assertPageContains('type="radio" name="jav-layout" value="${k}" data-jav-layout')- self.assertPageContains("${k===javLayout()?'checked':''}")- self.assertPageContains("b.onchange=()=>{if(b.checked)setJavLayout(b.value)}")- self.assertPageContains(".javlayout label:has(input:checked){background:var(--surface);color:var(--ink)")+ # 版式开关和关注列表的紧凑开关是同一个控件:共用 iconSwitchHtml 与 .iconswitch+ # 样式,.javlayout 只留排序行里的位置微调。+ self.assertPageContains("iconSwitchHtml('jav-layout','JAV 卡片版式',JAV_LAYOUTS,javLayout(),")+ self.assertPageContains("{attr:'data-jav-layout',className:'javlayout'}")+ self.assertPageContains('type="radio" name="${esc(name)}" value="${esc(value)}" ${attr}')+ self.assertPageContains("${value===current?'checked':''}")+ self.assertPageContains("wireIconSwitch(root,'data-jav-layout',setJavLayout)")+ self.assertPageContains(".iconswitch label:has(input:checked){background:var(--surface);color:var(--ink)")self.assertPageContains("let entityRequestSeq=0,entityJavLayout=false")self.assertPageContains("(items.items||[]).some(item=>item.is_jav)")self.assertPageContains("return state.jav==='1'||entityJavLayout")diff --git a/web/app.css b/web/app.cssindex 1bdf0f49d..2cd3aaff3 100644--- a/web/app.css+++ b/web/app.css@@ -1950,7 +1950,7 @@ body.drawer-open .edge{opacity:0;pointer-events:none} /* 展开时窄栏让位.javbar{display:flex;align-items:center;gap:8px;padding:0 0 10px;flex-wrap:wrap}.javbar[hidden]{display:none}.javbar button{width:34px;height:30px;display:inline-grid;place-items:center;border-radius:var(--control-radius);border:1px solid var(--overlay-10);background:transparent;color:var(--ink-2);cursor:pointer;padding:0}.javbar button svg{width:17px;height:17px;stroke:currentColor;fill:none;stroke-width:1.8}.javbar button:hover{color:var(--ink)}.javbar button[aria-pressed="true"]{background:var(--hover);color:var(--ink)}-.javlayout{min-width:0;margin:0;padding:3px;border:1px solid var(--line-soft);border-radius:var(--surface-radius);background:var(--overlay-5)}.javlayout label{position:relative;display:inline-grid;width:34px;height:28px;place-items:center;border-radius:var(--control-radius);color:var(--muted);cursor:pointer}.javlayout input{position:absolute;inline-size:1px;block-size:1px;opacity:0}.javlayout label:hover{color:var(--ink)}.javlayout label:has(input:checked){background:var(--surface);color:var(--ink);box-shadow:0 1px 2px #0005}.javlayout label:has(input:focus-visible){outline:2px solid var(--tungsten);outline-offset:2px}.javlayout svg{width:17px;height:17px;stroke:currentColor;fill:none;stroke-width:1.8}+.iconswitch{min-width:0;margin:0;padding:3px;border:1px solid var(--line-soft);border-radius:var(--surface-radius);background:var(--overlay-5)}.iconswitch label{position:relative;display:inline-grid;width:34px;height:28px;place-items:center;border-radius:var(--control-radius);color:var(--muted);cursor:pointer}.iconswitch input{position:absolute;inline-size:1px;block-size:1px;opacity:0}.iconswitch label:hover{color:var(--ink)}.iconswitch label:has(input:checked){background:var(--surface);color:var(--ink);box-shadow:0 1px 2px #0005}.iconswitch label:has(input:focus-visible){outline:2px solid var(--tungsten);outline-offset:2px}.iconswitch svg{width:17px;height:17px;stroke:currentColor;fill:none;stroke-width:1.8}/* 取景:正封模式下,整张封套要把镜头推到右半边;本身就是竖版正封的则整张用。判据是图片自己的宽高比,由 onload 写进 data-frame。 */.poster.cover{width:100%;height:100%;object-fit:cover;display:block}@@ -2102,6 +2102,9 @@ body.drawer-open .edge{opacity:0;pointer-events:none} /* 展开时窄栏让位.fsechead h3{margin:0;font-size:var(--fs-md);font-weight:600;letter-spacing:.01em}.fsechead .fmeta{flex:1 1 auto}.fmanagesort{display:inline-flex;align-items:center;gap:7px;color:var(--muted);font-size:var(--fs-xs)}+/* 版式开关和排序框、按钮同处分区标题行,收到同一个 32px 高度上(fieldset 自带 1px 边框)。 */+.fsechead .iconswitch{display:inline-flex;gap:2px;flex:none;padding:2px}+.fsechead .iconswitch label{width:32px;height:26px}.fmanagesort select{height:32px;padding:0 10px;border:1px solid var(--border-15);border-radius:var(--control-radius);background:var(--surface);color:var(--ink-2);font:inherit;font-size:var(--fs-sm);color-scheme:dark;cursor:pointer}.fmanagesort select:focus-visible{outline:2px solid var(--tungsten);outline-offset:2px}@@ -2221,6 +2224,10 @@ body.drawer-open .edge{opacity:0;pointer-events:none} /* 展开时窄栏让位.frows{display:grid;min-width:0}.frows>*{min-width:0}.fsources{grid-template-columns:repeat(auto-fit,minmax(430px,1fr));gap:16px 22px;align-items:start}+/* 紧凑版式:一行两个。半幅宽度放不下来源行的六列,收掉「上次检查」——哪个站、+ 成没成功、能不能点都还在,时间是里面最不影响判断的一列。 */+.fsources[data-layout="compact"]{grid-template-columns:repeat(2,minmax(0,1fr))}+.fsources[data-layout="compact"] .fsource .fchecked{display:none}.frow{display:flex;align-items:center;gap:12px;padding:9px 0;flex-wrap:wrap;border-bottom:1px solid var(--border-10)}.frows>.frow:last-child{border-bottom:0}@@ -2323,15 +2330,21 @@ body.drawer-open .edge{opacity:0;pointer-events:none} /* 展开时窄栏让位/* summary 是 .frow 的 flex 子项,默认 flex:0 1 auto 不撑满整行——于是有折叠体的那几行状态贴在名字后面,没折叠体的却靠右,同一列两种对齐。让它占满,状态就统一在右边。 */-.fcred summary{flex:1 1 auto;min-width:0;display:flex;align-items:center;gap:12px;+.fcred summary{flex:1 1 auto;min-width:0;display:flex;align-items:center;gap:8px;cursor:pointer;list-style:none;margin:-9px 0;padding:9px 0}.fcred summary::-webkit-details-marker{display:none}.fcred summary b{flex:1 1 auto;min-width:0;font-weight:500}-.fcred.none{color:var(--muted)}+.fcred.none{color:var(--muted);gap:8px}/* 折叠时 .frow 让它是 flex、展开时又变 block,两种几何下 summary 的可用宽度差一个 gap,状态列就差 12px 对不齐。统一成 block:summary 自己是 flex 容器,宽度始终是整行。 */details.fcred{display:block}-.fcred[open]{padding-bottom:12px}+/* 展开体的内边距归 .fcollapsebody:留在 .fcred[open] 上的话,收起那一帧高度已经+ 归零、内边距还在,行尾会跳一下。首段自己的上边距换成容器内边距,免得它跟容器+ 外边距合并,量出来的 scrollHeight 比实际矮一截。 */+.fcred .fcollapsebody{padding:8px 0 12px}+.fcred .fcollapsebody>p:first-child{margin-top:0}+.fcred .ficonslot{flex:none;display:block;width:14px;height:14px}+.fcred .ficon{margin-right:0}.fcred p{margin:8px 0 0;font-size:var(--fs-sm);line-height:1.7;color:var(--muted);overflow-wrap:anywhere}.fcred a{color:var(--tungsten)}@@ -2366,7 +2379,9 @@ details.fcred{display:block}.faddform>.fsearchinput{grid-column:1/-1}.faddform>.fsrcfilter{justify-self:start}.frow{gap:8px}- .fsources{grid-template-columns:1fr}+ .fsources,.fsources[data-layout="compact"]{grid-template-columns:1fr}+ /* 窄屏放不下两栏,紧凑版式在这里不成立;开关跟着收起,不留一个按了没反应的控件。 */+ .fsechead .iconswitch{display:none}.frow .fmeta:nth-of-type(2){display:none}.faliasform{grid-template-columns:1fr}.faliasform .fbtn{width:100%}diff --git a/web/app.js b/web/app.jsindex 092c910f5..9491fe160 100644--- a/web/app.js+++ b/web/app.js@@ -5,9 +5,9 @@ import { matchRoute, routeLabel } from './js/routes.js';import { initMiddleTruncate } from './js/middle-truncate.js';import { tagLabel } from './js/tags.js';import {- breadcrumbHtml, emptyStateHtml, fieldsetTitle, loadingDotsHtml, mediaViewButtonsHtml, noteHtml,- progressHtml, scrollerHtml, setActionBusy, skeletonHtml, spinnerHtml, wireBusyActions,- wireScrollers,+ breadcrumbHtml, emptyStateHtml, fieldsetTitle, iconSwitchHtml, loadingDotsHtml,+ mediaViewButtonsHtml, noteHtml, progressHtml, scrollerHtml, setActionBusy, skeletonHtml,+ spinnerHtml, wireBusyActions, wireCollapse, wireIconSwitch, wireScrollers,} from './js/ui-components.js';initMiddleTruncate(document);@@ -262,7 +262,7 @@ const SORTS=[['seed','随机'],['rating','评分'],['o','高潮计数'],['plays'['big','体积'],['new','最近入库'],['played','最近看的']];const JAV_RELEASE_SORT=['release','发行时间'];const SORT_KEYS=[...SORTS,JAV_RELEASE_SORT].map(([key])=>key);-const DEFAULT_SETTINGS={batchSize:60,defaultSort:'seed',sortDefaultsVersion:2,hoverDelaySeconds:5,seekSeconds:10,searchHistoryLimit:10,relatedLimit:20,javLayout:'big',ambientMode:true,theaterMode:false,groupCollapse:true,sidebarOrder:DEFAULT_SIDEBAR_ORDER};+const DEFAULT_SETTINGS={batchSize:60,defaultSort:'seed',sortDefaultsVersion:2,hoverDelaySeconds:5,seekSeconds:10,searchHistoryLimit:10,relatedLimit:20,javLayout:'big',followLayout:'cozy',ambientMode:true,theaterMode:false,groupCollapse:true,sidebarOrder:DEFAULT_SIDEBAR_ORDER};let appSettings={...DEFAULT_SETTINGS};try{appSettings={...DEFAULT_SETTINGS,...JSON.parse(localStorage.getItem(SETTINGS_KEY)||'{}')}}catch(_e){}const allowedSetting=(value,allowed,fallback)=>allowed.includes(value)?value:fallback;@@ -3984,15 +3984,37 @@ function followCredentialRow(row){${row.world_readable?'<p class="fnote warn">文件权限过宽,请在运行 Peach 的 POSIX 主机上收紧为 0600。</p>':''}`;// 两个分支必须用同一个状态类,否则「不需要」那几行走 .fmeta、其余走 .fstate,// 同一列出现两套样式和两种对齐——用户一眼就看出来了。- if(!body)return `<div class="frow fcred none"><b>${esc(row.provider_label)}</b>+ /* 站点标记跟着来源走:凭据配的就是那个站,来源行已经用同一枚 favicon 指认它。+ 槽位固定 14px,不看里面有没有图:没登记 favicon 的站本来就没有,取不下来的那些+ 还会被 data-drop="self" 整个丢掉——两种情况都会让这一列的名字左边缘参差。 */+ const mark=`<span class="ficonslot" aria-hidden="true">${sourceIcon(row.provider)}</span>`;+ if(!body)return `<div class="frow fcred none">${mark}<b>${esc(row.provider_label)}</b><span class="fcstate none">${esc(label)}</span></div>`;return `<details class="frow fcred ${esc(kind)}${configured?' ok':''}"${needsAttention?' open':''}>- <summary><b>${esc(row.provider_label)}</b>+ <summary>${mark}<b>${esc(row.provider_label)}</b><span class="fcstate ${configured?'done':esc(kind)}">${esc(configured?'已配置':label)}</span>${row.missing.length?`<span class="fcstate missing">缺 ${esc(row.missing.join('、'))}</span>`:''}</summary>${body}</details>`;}+/* 关注列表版式。默认一行一个,来源行的六列都在;紧凑是一行两个,半幅宽度放不下+ 六列,收掉「上次检查」——哪个站、成没成功、能不能点都还留着,时间是里面最不+ 影响判断的一列。和 JAV 版式共用 iconSwitchHtml,只是 name 与选项不同。 */+const FOLLOW_LAYOUTS=[['cozy','舒适 · 一行一个','maximize'],['compact','紧凑 · 一行两个','layout-grid']];+function followListLayout(){+ return allowedSetting(appSettings.followLayout,FOLLOW_LAYOUTS.map(([k])=>k),'cozy');+}+function followLayoutButtons(){+ return iconSwitchHtml('follow-layout','关注列表版式',FOLLOW_LAYOUTS,followListLayout(),+ {attr:'data-follow-layout'});+}+function setFollowListLayout(value){+ appSettings.followLayout=value;+ saveSettings();+ // 版式是纯展示层的事:改容器上的一个属性就够,不重画列表,也不重新请求。+ document.querySelectorAll('.fsources').forEach(node=>{node.dataset.layout=followListLayout()});+}+/* 版式判据来自 docs/reference-sources.json 的 vercel-report-design:要避开卡片套卡片、用边框补救层级、成排通栏空条、细小灰字加随意字号。所以这里不再用嵌套卡片盒子——分组靠标题和一条发丝分隔线,@@ -4036,12 +4058,13 @@ function renderFollowManage(credentials){<option value="name"${followManageSort==='name'?' selected':''}>作者名称</option><option value="sources"${followManageSort==='sources'?' selected':''}>来源数量</option></select></label>+ ${followLayoutButtons()}<button class="fbtn" data-follow-check=""${sources.length?'':' disabled'}>${icon('refresh-cw')}检查全部</button><button class="fbtn" data-follow-view>${icon('rss')}去看更新</button></div>${followCheckReport?followCheckFailNote(followCheckReport):''}${broken.length?`<p class="fnote warn">${broken.length} 个来源上次检查失败,原因见对应那一行。</p>`:''}- ${sources.length?`<div class="frows fsources">${+ ${sources.length?`<div class="frows fsources" data-layout="${followListLayout()}">${followAuthorGroups(sources).map(followAuthorBlock).join('')}</div>${counts.new?`<div class="fsecfoot"><p class="fnote fbulkrow"><span class="fbulkcounts">未看 ${counts.new} · 已看 ${counts.seen||0}· 已保存 ${counts.saved||0} · 已忽略 ${counts.ignored||0}</span>@@ -4129,6 +4152,7 @@ function wireFollowManage(){route('/follow-manage'+(followManageSort==='checked'?'':'?sort='+encodeURIComponent(followManageSort)));openFollowManage(false);};+ wireIconSwitch(root,'data-follow-layout',setFollowListLayout);renderFollowSrcFilter(root.querySelector('#followSrcFilter'));const tooltipTrigger=root.querySelector('[data-fdesc-tooltip]');const tooltip=root.querySelector('#follow-credential-tooltip');@@ -4156,53 +4180,10 @@ function wireFollowManage(){tooltipTrigger.addEventListener('keydown',event=>{if(event.key==='Escape'){tooltipHovered=false;tooltipFocused=false;hideTooltip();tooltipTrigger.blur()}});}- /* 作者别名的折叠用 Geist Collapse 机制:内容包 .fcollapse,开合时 JS 量- scrollHeight 写 inline height 过渡(原生 details 无过渡;此前试过- ::details-content 方案会吞内容,已弃)。凭据行是 flex 行布局不接。 */- root.querySelectorAll('details.faliasmanager').forEach((details,index)=>{- if(details.querySelector(':scope > .fcollapse'))return;- const body=document.createElement('div');body.className='fcollapse';- /* 内边距放在内层 .fcollapsebody:.fcollapse 自身不带 padding,height 才能- 真正过渡到 0,否则 border-box 会在 20px 处卡住、收起末尾跳一下。 */- const inner=document.createElement('div');inner.className='fcollapsebody';- [...details.children].forEach(child=>{- if(child.tagName==='SUMMARY')return;- inner.appendChild(child)});- body.appendChild(inner);details.appendChild(body);- const summary=details.querySelector('summary');- let expanded=details.open,transitionRun=0;- body.id=`follow-alias-collapse-${index}`;- body.inert=!expanded;- summary.setAttribute('aria-controls',body.id);- summary.setAttribute('aria-expanded',String(expanded));- const settle=(run,fn)=>{- let done=false,timer;- const finish=e=>{- if(e&&e.propertyName!=='height')return;- if(done)return;done=true;- body.removeEventListener('transitionend',finish);clearTimeout(timer);- if(run===transitionRun)fn()};- body.addEventListener('transitionend',finish);- timer=setTimeout(finish,260)};- summary.addEventListener('click',e=>{- e.preventDefault();- expanded=!expanded;const run=++transitionRun;- summary.setAttribute('aria-expanded',String(expanded));- if(expanded){- body.inert=false;- const start=details.open?body.getBoundingClientRect().height:0;- details.open=true;- body.style.height=start+'px';body.getBoundingClientRect();- body.style.height=body.scrollHeight+'px';- settle(run,()=>{body.style.height='auto'});- }else{- body.inert=true;- body.style.height=body.getBoundingClientRect().height+'px';body.getBoundingClientRect();- body.style.height='0px';- settle(run,()=>{details.open=false;body.style.height=''});- }- });- });+ /* 作者别名和凭据行都走 Geist Collapse。凭据行早先是 flex 行布局接不上,+ `details.fcred` 统一成 block 之后两处用的就是同一份实现了。 */+ wireCollapse(root,'details.faliasmanager','follow-alias-collapse');+ wireCollapse(root,'details.fcred','follow-cred-collapse');const box=form&&form.querySelector('input[name="line"]');/* 回车自己接管,不靠隐式提交:没有提交按钮时浏览器只在「表单里仅有一个文本字段」才替你提交,而来源筛选的那串复选框就住在同一个 <form> 里。实测按下去什么也不发生。@@ -5534,11 +5515,11 @@ function javLayout(){const raw=JAV_LAYOUT_ALIASES[appSettings.javLayout]||appSettings.javLayout;return allowedSetting(raw,JAV_LAYOUTS.map(([k])=>k),'big');}-function javLayoutButtons(){return `<fieldset class="javlayout"><legend class="sr-only">JAV 卡片版式</legend>`+JAV_LAYOUTS.map(([k,label,ic])=>- `<label title="${esc(label)}"><input type="radio" name="jav-layout" value="${k}" data-jav-layout- ${k===javLayout()?'checked':''}><span aria-hidden="true">${icon(ic)}</span><span class="sr-only">${esc(label)}</span></label>`).join('')+`</fieldset>`}-function wireJavLayoutButtons(root){root?.querySelectorAll('[data-jav-layout]').forEach(b=>- b.onchange=()=>{if(b.checked)setJavLayout(b.value)})}+function javLayoutButtons(){+ return iconSwitchHtml('jav-layout','JAV 卡片版式',JAV_LAYOUTS,javLayout(),+ {attr:'data-jav-layout',className:'javlayout'});+}+function wireJavLayoutButtons(root){wireIconSwitch(root,'data-jav-layout',setJavLayout)}function setJavLayout(value){appSettings.javLayout=value;saveSettings();diff --git a/web/js/ui-components.js b/web/js/ui-components.jsindex ecf1ac975..3a8c61916 100644--- a/web/js/ui-components.js+++ b/web/js/ui-components.js@@ -174,3 +174,80 @@ export function wireScrollers(root=document){requestAnimationFrame(()=>updateScroller(wrapper));});}++/**+ * Geist Switch:2–3 个互斥视图用共享 name 的一组 radio,不用 Toggle。+ *+ * JAV 卡片版式和关注列表版式是同一个控件——只有 name、选项和当前值不同,所以模板+ * 与 `.iconswitch` 样式共用一份;调用方各自的摆放位置仍由自己的类负责。+ */+export function iconSwitchHtml(name,legend,options,current,{attr='',className=''}={}){+ const items=options.map(([value,label,symbol])=>+ `<label title="${esc(label)}"><input type="radio" name="${esc(name)}" value="${esc(value)}" ${attr}+ ${value===current?'checked':''}><span aria-hidden="true">${icon(symbol)}</span><span class="sr-only">${esc(label)}</span></label>`).join('');+ return `<fieldset class="iconswitch${className?` ${esc(className)}`:''}"><legend class="sr-only">${esc(legend)}</legend>${items}</fieldset>`;+}++/** 把一组 iconSwitchHtml 画出来的 radio 接到 apply(value) 上。 */+export function wireIconSwitch(root,attr,apply){+ root?.querySelectorAll(`[${attr}]`).forEach(input=>{+ input.onchange=()=>{if(input.checked)apply(input.value)};+ });+}++/**+ * Geist Collapse:原生 `<details>` 不过渡高度,所以把 summary 以外的内容包进+ * `.fcollapse`,开合时量 `scrollHeight` 写 inline `height` 让它过渡。+ * (试过 `::details-content`,那条路会吞掉内容,已弃。)+ *+ * 同一个 `details` 只接一次,重绘后原样再调用是安全的。+ */+export function wireCollapse(root,selector,idPrefix){+ root?.querySelectorAll(selector).forEach((details,index)=>{+ if(details.querySelector(':scope > .fcollapse'))return;+ const body=document.createElement('div');body.className='fcollapse';+ /* 内边距放在内层 .fcollapsebody:.fcollapse 自身不带 padding,height 才能真正+ 过渡到 0,否则 border-box 会卡在内边距上、收起末尾跳一下。 */+ const inner=document.createElement('div');inner.className='fcollapsebody';+ [...details.children].forEach(child=>{+ if(child.tagName==='SUMMARY')return;+ inner.appendChild(child);+ });+ body.appendChild(inner);details.appendChild(body);+ const summary=details.querySelector('summary');+ let expanded=details.open,transitionRun=0;+ body.id=`${idPrefix}-${index}`;+ body.inert=!expanded;+ summary.setAttribute('aria-controls',body.id);+ summary.setAttribute('aria-expanded',String(expanded));+ const settle=(run,fn)=>{+ let done=false,timer;+ const finish=e=>{+ if(e&&e.propertyName!=='height')return;+ if(done)return;done=true;+ body.removeEventListener('transitionend',finish);clearTimeout(timer);+ if(run===transitionRun)fn();+ };+ body.addEventListener('transitionend',finish);+ timer=setTimeout(finish,260);+ };+ summary.addEventListener('click',event=>{+ event.preventDefault();+ expanded=!expanded;const run=++transitionRun;+ summary.setAttribute('aria-expanded',String(expanded));+ if(expanded){+ body.inert=false;+ const start=details.open?body.getBoundingClientRect().height:0;+ details.open=true;+ body.style.height=start+'px';body.getBoundingClientRect();+ body.style.height=body.scrollHeight+'px';+ settle(run,()=>{body.style.height='auto'});+ }else{+ body.inert=true;+ body.style.height=body.getBoundingClientRect().height+'px';body.getBoundingClientRect();+ body.style.height='0px';+ settle(run,()=>{details.open=false;body.style.height=''});+ }+ });+ });+}