Peach: Local-first video metadata scraper and media manager.
feat(web): 叠层卡片往上堆并让整行下沿平齐,关注页合集补上翻动
longmeidaoe6ca96ab98bb
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex b5aedba37..45cfdafa0 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -2344,12 +2344,12 @@ class WebUiSourceTests(unittest.TestCase):self.assertPageContains("wireMixFlip(el,seedId);")# 翻动的封面必须 eager:它们插进的是一个 hidden 容器,lazy 图没有布局盒# 就不发请求,实测除第一张外四张全部 naturalWidth=0,一翻就是黑屏。- self.assertPageContains("${mixFacePoster(x,layout,true)}")+ self.assertPageContains(".map(x=>mixFacePoster(x,layout,true));")self.assertPageContains("const load=eager?'eager':'lazy';")# 能不能画出图只有一个判据,seed 选择和翻动共用。分开写就会翻出# 或选中一张「无预览」:非 JAV 模式下 `has_cover` 并不代表卡片会画封套。self.assertPageContains("function mixHasPicture(it,layout){")- self.assertPageContains(".filter(x=>mixHasPicture(x,layout)).slice(0,MIX_FLIP_FACES);")+ self.assertPageContains(".filter(x=>mixHasPicture(x,layout)).slice(0,MIX_FLIP_FACES)")self.assertPageContains("const named=it=>mixHasPicture(it,layout)&&(it.creator")self.assertPageContains("||visible.slice(MIX_SLOT+1).find(it=>mixHasPicture(it,layout))")self.assertCode('''loading="${eager?'eager':'lazy'}"''')@@ -2367,6 +2367,47 @@ class WebUiSourceTests(unittest.TestCase):# 队列长度不能被悬浮预取剪短:两边用同一个 limit。self.assertPageContains("api('/api/related?id='+seedId+'&limit=28')")+ def test_stacked_cards_pile_upward_and_keep_the_row_bottom_aligned(self):+ """Mix、分卷、版次和关注合集的叠层往上溢出,卡片本体不为它留白。++ 留白(padding-top)会把整张卡压低并加高,同一行里这几种卡的封面和+ 下面的文字就比邻居矮一截。四种卡共用同一套叠层规则,不各调一份。+ """+ self.assertPageLacks(".mixcard,.partcard{padding-top:7px}")+ self.assertPageLacks(".followitem.collection{padding-top:7px}")+ self.assertPageContains(+ ".mixstack::before,.partstack::before{inset:0 12px 8px;transform:translateY(-7px)")+ self.assertPageContains(+ ".mixstack::after,.partstack::after{inset:0 6px 4px;transform:translateY(-4px)")+ # 密集模式给整个网格统一留 7px,那是所有卡片一起下移,不破坏平齐。+ self.assertPageContains('body[data-density="dense"] .grid>.card{padding-top:7px}')++ def test_follow_collections_flip_through_the_thumbs_they_already_have(self):+ """关注页的合集卡片和目录页的 Mix 用同一套翻动,不各写一份动效。++ 时序、启动门槛和 `_stopHover` 收尾都在 `wireStackFlip` 里;关注页的+ 几张缩略图卡片渲染时就在手上,悬浮不再为动画发一次请求。第一张是+ 静止封面本身,翻起来才不会露出取景差别。+ """+ self.assertPageContains("function wireStackFlip(el,loadFaces){")+ self.assertPageContains("try{pool=await loadFaces()}catch(_e){return}")+ self.assertPageContains("function wireFollowStackFlip(card){")+ self.assertPageContains("wireStackFlip(card,async()=>urls.map(url=>")+ self.assertPageContains(+ "if(!card.dataset.flipWired){card.dataset.flipWired='1';wireFollowStackFlip(card)}")+ # 翻的必须是角标数的那一组,否则卡上写「9 个视频」翻的却是别处的图。+ self.assertPageContains(+ "const faceSource=embedded.length>1?embedded:"+ "(groupedVideos.length>1?groupedVideos:videos);")+ self.assertPageContains("const faceUrls=isMix?[...new Set([thumbUrl,...faceSource")+ self.assertPageContains(".filter(entry=>!imageView||entry.media_kind==='image')")+ self.assertPageContains(".map(entry=>entry.thumb_url)].filter(Boolean))].slice(0,MIX_FLIP_FACES):[];")+ self.assertPageContains(+ '${faceUrls.length>1?`<div class="mixfaces" '+ 'data-mix-faces="${esc(JSON.stringify(faceUrls))}" hidden></div>`:\'\'}')+ # 遮住静止封面的底色跟着这张卡自己的底走:图片墙是浅底,视频卡是黑底。+ self.assertPageContains(".followitem.imagecard .mixfaces{background:var(--sunk)}")+def test_mix_and_persistent_playlists_share_the_routed_side_queue(self):self.assertPageContains('class="card mixcard" data-mix-seed=')self.assertPageContains("cards.splice(MIX_SLOT,0,mixCardHtml(seed))")diff --git a/web/app.css b/web/app.cssindex b5981c985..36cb309cd 100644--- a/web/app.css+++ b/web/app.css@@ -831,7 +831,9 @@ main{position:relative;z-index:1;padding:14px 16px 90px}.shorts-inline .scard .pic{aspect-ratio:var(--card-ratio,9/16)}.card{cursor:pointer;display:flex;flex-direction:column;gap:8px;min-width:0;position:relative;transition:transform .18s ease,filter .18s ease;transform-origin:center}-.mixcard,.partcard{padding-top:7px}+/* 叠层往上溢出到行间距里,卡片本体不为它留白。留白的写法(padding-top:7px)会把+ 整张卡压低 7px 并加高 7px,同一行里 Mix、分卷、版次卡的封面和下面的文字就比+ 邻居矮一截;往上堆之后卡片盒和普通卡完全同高,下沿自然平齐。 */.mixstack,.partstack{position:relative;isolation:isolate}.mixstack::before,.mixstack::after,.partstack::before,.partstack::after{content:"";position:absolute;border-radius:var(--badge-radius);border:1px solid var(--border-15);background:color-mix(in srgb,var(--surface) 84%,var(--video-glow,#15202a));z-index:0}@@ -1970,10 +1972,12 @@ body.drawer-open .edge{opacity:0;pointer-events:none} /* 展开时窄栏让位/* 固定媒体框在懒加载前就占好高度;多栏会随图片天然高度反复重新分栏,造成滚动位移。 */@media (max-width:1400px){.followlist.followphotowall{grid-template-columns:repeat(4,minmax(0,1fr))}}@media (max-width:1000px){.followlist.followphotowall{grid-template-columns:repeat(3,minmax(0,1fr))}}-.followitem{min-width:0}.followitem.collection{padding-top:7px}+.followitem{min-width:0}.followitem.imagecard{display:flex;width:100%;margin:0}.followitem.imagecard .pic{aspect-ratio:4/3;min-height:0;background:var(--sunk)}.followitem.imagecard .followvisual .pic>img{position:absolute;inset:0;width:100%;height:100%;object-fit:contain;background:var(--sunk)}+/* 翻动面板遮住静止封面,底色要跟着这张卡自己的底走:图片墙是浅底,视频卡是黑底。 */+.followitem.imagecard .mixfaces{background:var(--sunk)}.followitem a{text-decoration:none}.followitem a:hover{text-decoration:none}.followitem[data-status="ignored"],.followitem[data-status="seen"]{opacity:.62}.followvisual{position:relative;isolation:isolate}.followvisual .pic{z-index:1}diff --git a/web/app.js b/web/app.jsindex 382bf3f0b..0783f9856 100644--- a/web/app.js+++ b/web/app.js@@ -1627,10 +1627,12 @@ const MIX_FLIP_MS=1100; // 一张停多久再翻走const MIX_FLIP_LEAD_MS=420; // 面板建好到第一次翻动。直接用 1.1 秒间隔等第一张,鼠标停下到有反应要接近两秒const MIX_FLIP_FACES=9; // 最多预渲染几张,一次悬浮不拉一整批封面const reduceMotion=()=>matchMedia('(prefers-reduced-motion:reduce)').matches;-/* 悬浮 Mix 卡片时把它里面的前几部作品逐张翻走,说明它是一叠相似作品而不是- 某一个视频。门槛和悬停预览一致:多选、遮挡、滞后动画偏好和滚动中都不启动,- 离开即停并还原静止封面;`_stopHover` 让 releaseHoverPreviews 能连它一起收掉。 */-function wireMixFlip(el,seedId){+/* 悬浮一叠卡片时把它里面的前几张逐张翻走,说明它是一叠而不是某一个视频。+ 门槛和悬停预览一致:多选、遮挡、滞后动画偏好和滚动中都不启动,离开即停并+ 还原静止封面;`_stopHover` 让 releaseHoverPreviews 能连它一起收掉。+ 翻哪些由调用方给:目录页的 Mix 现拉相关作品,关注页的合集用卡片自己已有的+ 缩略图,两处共用同一套时序和门槛,不各写一份动效。 */+function wireStackFlip(el,loadFaces){const box=el.querySelector('[data-mix-faces]');if(!box)return;let armed=null,lead=null,cycle=null,faces=[],index=0,live=false;const stop=()=>{@@ -1649,14 +1651,11 @@ function wireMixFlip(el,seedId){const start=async()=>{if(selectMode||censorOn()||window.__scrolling||reduceMotion())return;live=true;- let related=[];- try{related=await mixRelated(seedId)}catch(_e){return}+ let pool=[];+ try{pool=await loadFaces()}catch(_e){return}if(!live||selectMode||censorOn())return;- const layout=javLayout();- const pool=[CACHE[seedId],...related]- .filter(x=>mixHasPicture(x,layout)).slice(0,MIX_FLIP_FACES);if(pool.length<2)return;- box.innerHTML=pool.map((x,i)=>`<div class="mixface${i?'':' on'}">${mixFacePoster(x,layout,true)}</div>`).join('');+ box.innerHTML=pool.map((face,i)=>`<div class="mixface${i?'':' on'}">${face}</div>`).join('');faces=[...box.children];index=0;box.hidden=false;lead=setTimeout(()=>{step();cycle=setInterval(step,MIX_FLIP_MS)},MIX_FLIP_LEAD_MS);};@@ -1664,6 +1663,24 @@ function wireMixFlip(el,seedId){el.addEventListener('mouseleave',stop);el._stopHover=stop;}+function wireMixFlip(el,seedId){+ wireStackFlip(el,async()=>{+ const related=await mixRelated(seedId),layout=javLayout();+ return [CACHE[seedId],...related]+ .filter(x=>mixHasPicture(x,layout)).slice(0,MIX_FLIP_FACES)+ .map(x=>mixFacePoster(x,layout,true));+ });+}+/* 关注页的合集翻的是卡片渲染时就写进 DOM 的那几张缩略图:同一组媒体已经在+ 手上,悬浮不该再为动画发一次请求。第一张必须是静止封面本身,否则一翻就+ 露出取景差别。 */+function wireFollowStackFlip(card){+ const box=card.querySelector('[data-mix-faces]');if(!box)return;+ let urls=[];+ try{urls=JSON.parse(box.dataset.mixFaces||'[]')}catch(_e){return}+ wireStackFlip(card,async()=>urls.map(url=>+ `<img class="poster" src="${esc(url)}" alt="" loading="eager" referrerpolicy="no-referrer">`));+}function wireMixCards(root){root.querySelectorAll('[data-mix-seed]').forEach(el=>{if(el.dataset.wired)return;el.dataset.wired='1';@@ -3438,13 +3455,19 @@ function followCard(group,authorSources=[]){const mixKind=embedded.length&&embedded.every(media=>media.media_kind==='image')?'图片':embedded.length&&embedded.some(media=>media.media_kind==='image')?'媒体':'视频';const mixTarget=embedded.length>1?item.id:(videos[0]?.id||item.id);+ /* 翻动用的几张必须来自角标数的那一组,否则卡上写「9 个视频」翻的却是别处的图。+ 图片视图里只翻图片:这一叠说的就是这几张图。 */+ const faceSource=embedded.length>1?embedded:(groupedVideos.length>1?groupedVideos:videos);+ const faceUrls=isMix?[...new Set([thumbUrl,...faceSource+ .filter(entry=>!imageView||entry.media_kind==='image')+ .map(entry=>entry.thumb_url)].filter(Boolean))].slice(0,MIX_FLIP_FACES):[];const badges=followBadges(group);const tags=followCardTags(item).slice(0,3).map(tag=>followTagChip(item,tag)).join('');const mediaIssue=followMediaIssue(item);const open=`<button class="cardopenhit" data-follow-detail="${item.id}" aria-label="打开 ${esc(item.title)} 详情"></button>`;return `<article class="card followitem${isMix?' collection':''}${imageView?' imagecard':''}" data-follow-item="${item.id}" data-status="${esc(item.status)}"><div class="${isMix?'mixstack ':''}followvisual"><div class="pic">- ${open}${thumb}+ ${open}${thumb}${faceUrls.length>1?`<div class="mixfaces" data-mix-faces="${esc(JSON.stringify(faceUrls))}" hidden></div>`:''}<span class="badge" title="${esc(item.provider_label)}" aria-label="来源:${esc(item.provider_label)}">${sourceIcon(item.provider)}</span><span class="selectionMark">${icon('check')}</span>${realDuration(item.duration)?`<span class="dur mono">${fmtDur(item.duration)}</span>`:''}${isMix?`<button class="mixbadge" data-follow-collection="${mixTarget}">${icon('play')}${mixCount} 个${mixKind}</button>`:''}@@ -4053,6 +4076,7 @@ function wireFollowItems(){event.stopPropagation();openFollowDetail(+button.dataset.followCollection)});root.querySelectorAll('.followitem[data-follow-item]').forEach(card=>{const id=+card.dataset.followItem;+ if(!card.dataset.flipWired){card.dataset.flipWired='1';wireFollowStackFlip(card)}card.onclick=event=>{if(event.target.closest('[data-follow-status],[data-follow-save],[data-follow-collection],[data-follow-detail],.tg'))return;if(selectMode||event.shiftKey||event.ctrlKey||event.metaKey){