Skip to content

armgit / peach

Public Imported from GitHub
0

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

Merge branch 'master' into agent/claude/performer-index-layout

longmeidao0498a5512ec0
diff --cc web/app.js
index 9b04f77a4,0ac93fc21..4226acecc
--- a/web/app.js
+++ b/web/app.js
@@@ -1397,23 -1504,56 +1504,62 @@@ function avatarInner(name,ref,repId,kin
/* 人脸取景:资料页圆框按检出的人脸中心取景(/api/entity 的 avatar_focus)。
没检出或没算过返回空串维持几何居中;换回落图时必须撤掉——那是另一张照片,
脸不在同一位置,见 entityhero img 的 `data-drop-style`。 */
-function facePos(f){
- return f&&f.axis==='x'?` style="object-position:${f.pct}% 50%"`
- :f&&f.axis==='y'?` style="object-position:50% ${f.pct}%"`
+/* 换算只有这一份。资料页把它写进 img 的 style;索引页大图版式要把它交给圆框上的
+ CSS 变量——那里的 img 由共用的 avatarInner 拼,版式能改的容器只有圆框。 */
+function faceOrigin(f){
+ return f&&f.axis==='x'?`${f.pct}% 50%`
+ :f&&f.axis==='y'?`50% ${f.pct}%`
:'';
}
+function facePos(f){
+ const origin=faceOrigin(f);
+ return origin?` style="object-position:${origin}"`:'';
+}
- /* 官方封套有两种形态,实测过:整张封套约 1.48(左侧是剧照拼贴,右侧才是正封),
- 竖版正封约 0.70(本身就是正封,没有左半边可裁)。所以取景不能写死「取右边」,
- 得等图片加载后按它自己的宽高比分流——服务端没存这个比例,也不该为此再存一份。 */
- /* 常见双页 DVD 封套约 1.45:1;16:9 的横版官方剧照不是封套,不能把它也推到
- 最右半边。上限给扫描留余量,但明确排除 259LUXU-1573 这类 1.78:1 剧照。 */
- const COVER_FRAME=`onload="const r=this.naturalWidth/this.naturalHeight;this.dataset.frame=r>1.2&&r<1.65?'sleeve':'front'"`;
+ /* 官方封面有三种形态,实测过:整张封套约 1.48(左侧是剧照拼贴,右侧才是正封),
+ 竖版正封约 0.70(本身就是正封,没有左半边可裁),16:9 官方剧照约 1.78(整幅
+ 都是画面,没有「正封那一块」可推)。所以取景不能写死「取右边」,得等图片加载后
+ 按它自己的宽高比分流——服务端没存这个比例,也不该为此再存一份。
+ 剧照必须自成一档:把 1.78 归进 front 就会按写死的 50% 取横向中段,人偏在一侧
+ 就整个被切掉,而大图容器比所有封面都竖、纵向锚点在那里根本不生效。 */
+ function coverAnchor(img){
+ const r=img.naturalWidth/img.naturalHeight;
+ if(!r)return;
+ img.dataset.frame=r>=1.65?'still':r>1.2?'sleeve':'front';
+ /* `object-position` 的百分比说的是「图片上这个点对齐可见窗口的同一个百分比位置」,
+ 不是「这个点落到窗口正中」。所以人脸中心原样当锚点只能保证脸还在画面里:0.81
+ 那种偏右的脸会贴着窗口右缘,图片右边还剩一截永远露不出来。可见窗口占图片 w 时,
+ 让人脸落到正中的锚点是 (face - w/2) / (1 - w)。夹回 0–1 是因为脸离图片边缘不足
+ 半个窗口时窗口已经顶到边,再往外推只会把图片外面推进来。 */
+ const car=coverRatio(img);
+ const center=(name,face,visible)=>{
+ // 只给被裁的那个轴算。`object-fit:cover` 一次只裁一个轴,另一个轴整幅可见
+ // (visible>=1),那里的 object-position 是死值,算了也不生效。
+ if(face==null||!(visible>0&&visible<1))return;
+ const pct=Math.min(1,Math.max(0,(face-visible/2)/(1-visible)));
+ img.style.setProperty(name,`${Math.round(pct*100)}%`);
+ };
+ center('--cover-x',coverFace(img,'cx'),car/r);
+ center('--cover-y',coverFace(img,'cy'),r/car);
+ }
+ /* 容器比例只有 `.pic` 的 `--card-ratio` 知道:竖屏开关、JAV 大图和普通卡片各写一个
+ 值,在这里按 layout 重算迟早会和它分叉。自定义属性会继承,直接从图片上读;
+ `aspect-ratio` 允许 `16/9` 这种写法,所以两种形式都得认。 */
+ function coverRatio(img){
+ const parts=getComputedStyle(img).getPropertyValue('--card-ratio').trim().split('/').map(Number);
+ const r=parts.length===2?parts[0]/parts[1]:parts[0];
+ return Number.isFinite(r)&&r>0?r:16/9;
+ }
+ function coverFace(img,axis){
+ const face=parseFloat(img.dataset[axis]);
+ return Number.isFinite(face)?face:null;
+ }
+ /* 封面是模板字符串拼出来的,没法逐张挂监听;内联 `onload` 属性只能调全局函数,而
+ app.js 以 `type="module"` 加载,取景函数在那里取不到——页面会每张图报一次
+ ReferenceError,封面全部按回落取景。`load` 不冒泡,但捕获阶段照样收得到。 */
+ document.addEventListener('load',event=>{
+ const img=event.target;
+ if(img instanceof HTMLImageElement&&img.classList.contains('cover'))coverAnchor(img);
+ },true);
/* 整张封套里右侧正封占的宽高比。裁切靠的是容器比例而不是 CSS 裁剪:`object-fit:cover`
只在容器比图片更「竖」时才会横向裁;容器一旦宽过 1.48 就变成纵向裁、整张封套原样
铺满,「大图」于是只撑满画布而取不到右侧。 */
@@@ -4720,24 -4860,8 +4866,25 @@@ function paintTagIndexSelection()
const count=panel.querySelector('[data-tag-selected]');if(count)count.textContent=`已选 ${selectedIndexTags.size} 个标签`;
const apply=panel.querySelector('[data-tag-apply]');if(apply)apply.disabled=!selectedIndexTags.size;
}
+/* 艺人索引版式,思路同 JAV 大图:列宽不变、只把图从圆框拉成竖幅,一屏里的人数
+ 不变而每张脸更大;紧凑就是圆头像那一屏。控件与 JAV 版式、关注列表版式共用
+ iconSwitchHtml,切换只改容器上的 data-layout——版式是纯展示层的事,不重画列表,
+ 也不重新请求。 */
+const PEOPLE_LAYOUTS=[['big','大图 · 竖幅头像','maximize'],['compact','紧凑 · 圆形头像','layout-grid']];
+function peopleIndexLayout(){
+ return allowedSetting(appSettings.peopleLayout,PEOPLE_LAYOUTS.map(([k])=>k),'big');
+}
+function peopleLayoutButtons(){
+ return iconSwitchHtml('people-layout','艺人索引版式',PEOPLE_LAYOUTS,peopleIndexLayout(),
+ {attr:'data-people-layout'});
+}
+function setPeopleIndexLayout(value){
+ appSettings.peopleLayout=value;
+ saveSettings();
+ document.querySelectorAll('.igrid').forEach(grid=>{grid.dataset.layout=peopleIndexLayout()});
+}
- async function openIndex(kind,q,push=true){
+ /* refine=true 表示这一次是筛选框自己重跑,不是一次页面进入:既不铺骨架,也不重画表头。 */
+ async function openIndex(kind,q,push=true,refine=false){
releaseHoverPreviews();
const requestSeq=++indexRequestSeq;
document.body.classList.remove('entity-open');
@@@ -4806,16 -4928,32 +4955,34 @@@
<button type="button" data-tag-clear>清空</button>
<button type="button" class="primary" data-tag-apply disabled>显示结果</button>
</div>`:'');
- $('#index').innerHTML=`<div class="ihead">
+ const countText=`${tagItems.length}${d.has_more?'+':''} 项`;
+ /* 筛选重跑不重画表头:输入框是同一个节点,焦点、光标位置和中文输入法正在组的字
+ 才不会在 300 ms 后被换掉。表头里随查询变的只有计数一处,单独改它。 */
+ if(refine&&$('#iq')){
+ $('#indexCount').textContent=countText;
+ $('#indexFilters').innerHTML=filters;
+ $('#indexBody').innerHTML=body;
+ $('#indexMore').hidden=!d.has_more;
+ }else $('#index').innerHTML=`<div class="ihead">
<h2 class="disp indexheading">${kind==='tags'?icon('tags'):''}${title}</h2>
- <span class="mono" id="indexCount">${tagItems.length}${d.has_more?'+':''} 项</span>
+ <span class="mono" id="indexCount">${countText}</span>
${kind==='tags'?`<div class="tagmodes"><button data-tag-scope="local" aria-pressed="${!onlineTags}">${icon('database')}本地</button><button data-tag-scope="online" aria-pressed="${onlineTags}">${icon('globe')}在线</button></div>
<div class="tagmodes"><button data-tag-view="cloud" aria-pressed="${tagIndexMode==='cloud'}">${icon('tags')}标签云</button><button data-tag-view="alphabet" aria-pressed="${tagIndexMode==='alphabet'}">${icon('list-filter')}字母表</button></div>`:''}
+ ${people?peopleLayoutButtons():''}
- <div class="isearch"><input id="iq" placeholder="过滤…" value="${esc(q||'')}"></div>
- </div>${filters}<div id="indexBody">${body}</div><button class="indexmore" id="indexMore" type="button" ${d.has_more?'':'hidden'}>载入更多</button>`;
- let it2; $('#iq').oninput=e=>{clearTimeout(it2);it2=setTimeout(()=>openIndex(kind,e.target.value.trim(),true),300)};
+ ${searchInputHtml({id:'iq',label:'过滤'+title,value:q||''})}
+ </div><div id="indexFilters">${filters}</div><div id="indexBody">${body}</div><button class="indexmore" id="indexMore" type="button" ${d.has_more?'':'hidden'}>载入更多</button>`;
+ const iq=$('#iq');let it2;
+ const refineIndex=()=>{clearTimeout(it2);
+ it2=setTimeout(()=>openIndex(kind,iq.value.trim(),true,true),300)};
+ /* 中文输入法在选字过程中一样发 input,事件上的 isComposing 是唯一可靠的判据:
+ 拿还没定型的拼音去筛选,筛的是「zhon」这种半截输入。组完字由 compositionend 接手。 */
+ iq.oninput=e=>{if(e.isComposing)return;refineIndex()};
+ iq.oncompositionend=refineIndex;
+ /* 只读筛选不配提交按钮,回车就是「别等那 300 ms,现在就查」。组字过程中的回车
+ 是在定字,放过去会拿半截拼音发请求。 */
+ iq.onkeydown=e=>{if(e.isComposing||e.key!=='Enter')return;
+ e.preventDefault();clearTimeout(it2);openIndex(kind,iq.value.trim(),true,true)};
+ wireIconSwitch($('#index'),'data-people-layout',setPeopleIndexLayout);
$('#index').querySelectorAll('[data-tag-scope]').forEach(b=>b.onclick=()=>{
if(tagIndexScope===b.dataset.tagScope)return;
tagIndexScope=b.dataset.tagScope;