Skip to content

armgit / peach

Public Imported from GitHub
0

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

Enforce middle truncation semantics

longmeidaobf4f02172da7
diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md
index da7bb3f2a..122969938 100644
--- a/docs/HANDOFF.md
+++ b/docs/HANDOFF.md
@@ -75,7 +75,7 @@ Claude 的 `.claude/settings.json` 已配置 Stop、StopFailure、SessionEnd hoo
`grid-module__AMTIxG__grid`;网格引导线由父级统一拥有,单元透明、0 圆角,示例按阅读顺序逐行排列,
并明确要求各断点可预测重排、可点击单元独立显示 focus。Peach 复用共享边线与 3/2/1 列重排,
但 Tag 仍保留 6px 小圆角,普通排行不复制演示页的大留白或装饰性引导线。
-**Vercel Geist 控件(2026-08-28)**:官方 introduction 页实测普通操作使用 4/6px 圆角、图标操作为 32×32px,圆形留给 emoji 反馈等特殊语义。Peach 的普通操作和关闭按钮因此统一用 `--control-radius:6px`,菜单与 Modal 使用 `--floating-radius:12px`,状态标记使用 `--badge-radius:4px`;Tag 保持胶囊,媒体左右切换与头像保留圆形。全站字号、顶栏、搜索、播放列表、设置、管理、详情、关注与移动端共用这套语义 token;弹层自己的滚动容器必须使用 `overscroll-behavior:contain`,粘性标题栏要设置 `scroll-padding-top`,不能遮住键盘焦点。锁定版本、完整测量和有意差异见 `vercel-geist-controls-measured.md`。**Vercel Geist MiddleTruncate(2026-08-30)**:官方页 <https://vercel.com/geist/middle-truncate> 规定只对文件路径、URL、ID、SHA 等首尾都有信息的值做中间省略;单个 `…` 随容器宽度重算,复制和无障碍名称保留完整原文,外层不得再套 `text-overflow:ellipsis`。Peach 用原生 ES module 适配这套行为,不引入 React;标题、说明和创作者名继续末尾省略。实时浏览器 DOM/CSS/JS 本轮未取得,通道错误与候选判断见 `vercel-geist-middle-truncate.md`。
+**Vercel Geist 控件(2026-08-28)**:官方 introduction 页实测普通操作使用 4/6px 圆角、图标操作为 32×32px,圆形留给 emoji 反馈等特殊语义。Peach 的普通操作和关闭按钮因此统一用 `--control-radius:6px`,菜单与 Modal 使用 `--floating-radius:12px`,状态标记使用 `--badge-radius:4px`;Tag 保持胶囊,媒体左右切换与头像保留圆形。全站字号、顶栏、搜索、播放列表、设置、管理、详情、关注与移动端共用这套语义 token;弹层自己的滚动容器必须使用 `overscroll-behavior:contain`,粘性标题栏要设置 `scroll-padding-top`,不能遮住键盘焦点。锁定版本、完整测量和有意差异见 `vercel-geist-controls-measured.md`。**Vercel Geist MiddleTruncate(2026-08-30)**:官方页 <https://vercel.com/geist/middle-truncate> 规定只对文件路径、URL、ID、SHA 等首尾都有信息的值做中间省略;单个 `…` 随容器宽度重算,复制和无障碍名称保留完整原文,外层不得再套 `text-overflow:ellipsis`。Peach 用原生 ES module 适配这套行为,不引入 React;资源标识必须显式使用 `data-middle-truncate`,标题、说明、人名和标签保留末尾省略;页面源门槛登记全部末尾省略选择器,任何新增截断都必须先分类。实时浏览器 DOM/CSS/JS 本轮未取得,通道错误与候选判断见 `vercel-geist-middle-truncate.md`。
**Vercel Tooltip/Collapse/Projects 工具栏(2026-08-30)**:登录态项目页确认搜索占剩余宽度、筛选为方形图标钮、主操作在右,筛选菜单无展开动画并在自身内部滚动;Tooltip 官方 bundle 确认 250px 最大宽度、focus/Escape/`aria-describedby` 与视口边缘自动对齐;Collapse 官方 bundle 确认测量高度、200ms `ease-in-out`、chevron 旋转及关闭时 `inert`。Peach 的来源菜单不得套用 Collapse motion,作者别名才使用 Collapse;凭据 Tooltip 必须固定在视口内,不能制造页面滚动条。资源路径、SHA、截图摘要和 Peach 差异见 `vercel-geist-semantics-measured.md`。
**Beeg 资料页(2026-08-29)**:Reislin 页面实测顺序是头像与名称、简介、外部链接、关联艺人、标签、内容。Peach 的女优/厂牌资料页和关注页复用这个阅读顺序,但媒体切换只按 Peach 的真实视频/图片数量出现;合集详情继续使用普通详情的左媒体、右信息,下方另设 Mix/分卷/播放列表/多视频的横向切换带。锁定样式摘要、截图摘要和主动差异见 `beeg-profile-layout.md`。
YouTube Shorts 沉浸页使用用户截图记录 `docs/reference-snapshots/youtube-shorts-immersive-user-screenshot.md`:竖屏复用中央 9:16 舞台和外置动作列,横屏使用在整个视口视觉居中的 16:9 舞台并把动作列收进视频右侧;Peach 保留自己的反馈语义,不复制订阅或社交动作。沉浸视频每次加载都要带独立 `session`,切片、关闭、失败和页面离开时取消旧会话;只清浏览器的 `src` 不足以停止 CloudDrive 预读或 FFmpeg。
diff --git a/docs/REUSE.md b/docs/REUSE.md
index 939de1fce..69ac7196f 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -45,7 +45,7 @@
| 照片灯箱轮播 | Swiper 14.1.0(MIT,本地固定版本,按需 `<script>` 注入)的 Thumbs / Keyboard / Zoom 模块 | 图集来源与顺序、缩略图缓存与计费口径、瀑布流本身(CSS `column-count`,不经过 Swiper) |
| 导航排序 | 浏览器原生 HTML Drag and Drop | 桌面鼠标直接拖动、落点提示、上下移动按钮作为键盘与触屏回退、`localStorage` 持久化;不为单列排序引入额外运行时依赖 |
| 图标 | 固定版本的本地 Lucide 子集;Health Icons 24 px outline(CC0)用于领域图标 | 标签、状态和交互设计 |
-| 资源文本中间省略 | Vercel Geist `MiddleTruncate` 行为契约 + 浏览器原生 `ResizeObserver`、`Intl.Segmenter`、Canvas 测量 | 只处理文件名、路径、URL、ID 等首尾都重要的值;保留完整复制、无障碍名称与标题/说明的末尾省略 |
+| 资源文本中间省略 | Vercel Geist `MiddleTruncate` 行为契约 + 浏览器原生 `ResizeObserver`、`Intl.Segmenter`、Canvas 测量 | 文件名、路径、URL、ID 等资源标识用 `data-middle-truncate`;标题、说明、人名、标签等语义文本保留末尾省略;页面源测试登记全部末尾省略选择器,新增截断未先分类会失败 |
| 定时轮询 | APScheduler 3.11.3(MIT,固定稳定版;3.x `BackgroundScheduler` / interval trigger) | 只在 ledger writer 启动、持久频率、首次延迟、单实例、手动/自动互斥、运行状态与来源错误汇总 |
| 本地文件事件 | watchdog + 定期对账 | 媒体身份和漏报修复 |
| 过渡期元数据/媒体 | Stash GraphQL、CommunityScrapers、Stash 任务系统 | 适配、对账、退出门槛 |
diff --git a/docs/reference-snapshots/vercel-geist-middle-truncate.md b/docs/reference-snapshots/vercel-geist-middle-truncate.md
index e1368a90b..b85b19051 100644
--- a/docs/reference-snapshots/vercel-geist-middle-truncate.md
+++ b/docs/reference-snapshots/vercel-geist-middle-truncate.md
@@ -35,3 +35,10 @@ Peach 使用原生 `ResizeObserver`、`Intl.Segmenter` 与 Canvas 文本测量
完整值保存在模块状态中;可见文本只显示首尾与单个 `…`,`aria-label`、原生 `title` 和复制事件
仍提供完整值。容器宽度、字体加载或动态文本变化后重新计算。
+
+## 项目门槛
+
+- 资源标识一律显式加 `data-middle-truncate`;当前页面源测试锁定全部调用点。
+- CSS `text-overflow:ellipsis` 与多行 line clamp 只留给标题、说明、人名、标签和状态值。
+- `test_every_end_truncation_selector_is_explicitly_reviewed` 登记当前全部末尾省略选择器;新增、删除或改名都会失败,修改者必须先判断其语义,再同步门槛。
+- `*[data-middle-truncate]` 在样式表末尾强制 `text-overflow:clip`,即使资源标识落入旧的末尾省略容器,也不会叠加两种省略算法。
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index aa4275358..3600c2756 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -13,6 +13,8 @@ class WebUiSourceTests(unittest.TestCase):
web = Path(__file__).resolve().parents[1] / "web"
sources = [web / "index.html", web / "app.css", web / "app.js"]
sources.extend(sorted((web / "js").glob("*.js")))
+ cls.css = (web / "app.css").read_text(encoding="utf-8")
+ cls.app_js = (web / "app.js").read_text(encoding="utf-8")
cls.page = chr(10).join(
path.read_text(encoding="utf-8") for path in sources
)
@@ -1509,8 +1511,15 @@ class WebUiSourceTests(unittest.TestCase):
'class="dupname" data-middle-truncate',
'class="mono duppath" data-middle-truncate',
'<button data-middle-truncate data-quality-open=',
- '<b data-middle-truncate></b>'):
+ '<b data-middle-truncate></b>',
+ '<div><b data-middle-truncate title="${esc(asset.name||\'\')}"',
+ '<div><b data-middle-truncate title="${esc(row.asset_name||\'\')}"',
+ '<b data-middle-truncate>${esc(media.name)}</b>',
+ '<b data-middle-truncate>${esc(x.name)}</b>'):
self.assertPageContains(consumer)
+ self.assertEqual(self.app_js.count("data-middle-truncate"), 8)
+ self.assertEqual(self.app_js.count('class="mixitemtext"'), 3)
+ self.assertEqual(self.app_js.count("data-truncate-end"), 4)
self.assertPageContains("new Intl.Segmenter(undefined,{granularity:'grapheme'})")
self.assertPageContains("resizeObserver=new ResizeObserver")
self.assertPageContains("context.font=style.font||`${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`")
@@ -1518,9 +1527,37 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("element.setAttribute('aria-label',state.full)")
self.assertPageContains("event.clipboardData.setData('text/plain',state.full)")
self.assertPageContains("export { initMiddleTruncate, middleTruncateText }")
+ self.assertPageContains("*[data-middle-truncate]{min-width:0;overflow:hidden;white-space:nowrap;text-overflow:clip}")
self.assertPageContains(".qualityitem h3 button{display:block;width:100%")
self.assertPageLacks(".qualityitem h3 button{max-width:100%;border:0;background:transparent;padding:0;color:inherit;text-align:left;cursor:pointer;overflow-wrap:anywhere;display:-webkit-box")
+ def test_every_end_truncation_selector_is_explicitly_reviewed(self):
+ """新增 CSS 省略必须先决定它是语义文本,还是应改用 MiddleTruncate。"""
+ reviewed_end_selectors = {
+ ".alphatag span:first-of-type", ".av .nm", ".entitylinklabel",
+ ".entitytags button", ".fauthor .fsource.frow>b", ".fauthorhead b",
+ ".fchip", ".frow>b", ".fvkind", ".idname", ".kv>span:first-child",
+ ".meta .t", ".meta .who", ".mixcopy b,.mixcopy span",
+ ".mixitemtext [data-truncate-end]", ".mixqueuehead h2",
+ ".playerstats dd", ".relatedperson .nm", ".reviewentity b",
+ ".reviewitem h4", ".searchoption span",
+ ".sgrid.mixgrid>.mixqueue .mixqueuehead span", ".sidebarorderlabel>b",
+ ".tagpickitem .pickname", ".tasterank b,.tasterank small",
+ ".tastesource b,.tastesource small", ".tastesummary>small", ".tg",
+ ".tokui .toktitle", "body[data-density=\"dense\"] .card .ctags .tg",
+ "body[data-density=\"dense\"] .card .meta .t",
+ }
+ css_without_comments = re.sub(r"/\*.*?\*/", "", self.css, flags=re.S)
+ actual = set()
+ for selector, body in re.findall(r"([^{}]+)\{([^{}]*)\}", css_without_comments):
+ truncates = re.search(
+ r"text-overflow\s*:\s*ellipsis|-webkit-line-clamp\s*:(?!\s*unset)",
+ body,
+ )
+ if truncates:
+ actual.add(" ".join(selector.split()))
+ self.assertEqual(reviewed_end_selectors, actual)
+
def test_duplicate_removal_is_reversible(self):
# 只能进回收站;永久删除仍得从回收站单独执行。
self.assertPageContains("operation:'dispose'")
diff --git a/web/app.css b/web/app.css
index 50de13bc4..0b1919781 100644
--- a/web/app.css
+++ b/web/app.css
@@ -572,7 +572,7 @@ button.serieslink.entitylink:hover{color:var(--tungsten);text-decoration:none}
.reviewentity small{display:block;margin-top:7px;color:var(--muted);font-size:var(--fs-xs)}
.revieworigincover{width:132px;aspect-ratio:16/10;border:0;border-radius:7px;overflow:hidden;background:#000;padding:0;cursor:pointer}
.revieworigincover img{width:100%;height:100%;object-fit:contain;display:block}.revieworigincover span{display:grid;place-items:center;width:100%;height:100%;color:var(--muted)}
-.revieworigin>div{min-width:0}.revieworigin b{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-bottom:8px}
+.revieworigin>div{min-width:0}.revieworigin b{display:block;overflow:hidden;white-space:nowrap;margin-bottom:8px}
.revieworigin>div button{display:inline-flex;align-items:center;gap:6px;border:0;border-radius:7px;background:var(--hover);padding:6px 9px;color:var(--ink-2);cursor:pointer}
.revieworigin>div button:hover{color:var(--tungsten)}.revieworigin>div button svg{width:15px;height:15px;stroke:currentColor;fill:none;stroke-width:2}
@media(max-width:640px){.qualitylist{grid-template-columns:1fr}.qualityitem{grid-template-columns:110px minmax(0,1fr)}.qualitycover{width:110px}.reviewcompare{grid-template-columns:1fr}.revieworigin{grid-template-columns:110px minmax(0,1fr)}.revieworigincover{width:110px}}
@@ -853,7 +853,7 @@ body.index-open #tiers,body.index-open #tagbar{display:none}
.mixitem:hover{background:var(--overlay-5)}.mixitem.current{background:color-mix(in srgb,var(--tungsten) 15%,var(--overlay-5))}
.mixitempic{position:relative;aspect-ratio:16/9;border-radius:4px;overflow:hidden;background:#000}
.mixitempic img{position:absolute;inset:0;width:100%;height:100%;object-fit:contain}.mixitempic .dur{right:4px;bottom:3px}
-.mixitemtext{min-width:0}.mixitemtext b,.mixitemtext span{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
+.mixitemtext{min-width:0}.mixitemtext b,.mixitemtext span{display:block;overflow:hidden;white-space:nowrap}.mixitemtext [data-truncate-end]{text-overflow:ellipsis}
.mixitemtext b{font-size:var(--fs-xs);line-height:1.4}.mixitemtext span{font-size:var(--fs-xs);color:var(--muted);margin-top:3px}
.queueedit{display:grid;grid-template-columns:repeat(3,24px);gap:2px;padding-right:5px}.queueedit button{width:24px;height:24px;border:0;border-radius:5px;background:transparent;color:var(--muted);padding:0;display:grid;place-items:center;cursor:pointer}.queueedit button:hover:not(:disabled){background:var(--hover);color:var(--ink)}.queueedit button:disabled{opacity:.25;cursor:default}.queueedit svg{width:14px;height:14px;stroke:currentColor;fill:none}
/* 详情下方的集合不是侧栏列表,而是与「接着看」同语义的横向切换带。
@@ -1830,3 +1830,7 @@ details.fcred{display:block}
.followmore{display:flex;align-items:center;gap:12px;margin:18px 0 0;
padding-top:14px;border-top:1px solid var(--line-soft)}
.folderfoot .fmeta{margin-left:0}
+
+/* 资源标识统一由 MiddleTruncate 计算可见文本。星号让本规则与「类 + 元素」的末尾省略
+ 选择器同权重,并凭源码顺序覆盖,避免两套省略同时生效。 */
+*[data-middle-truncate]{min-width:0;overflow:hidden;white-space:nowrap;text-overflow:clip}
diff --git a/web/app.js b/web/app.js
index 16cdcd4fc..19f58d245 100644
--- a/web/app.js
+++ b/web/app.js
@@ -1472,7 +1472,7 @@ async function openReview(push=true){
const comparisonOrigin=comparison.length>1?`<div class="reviewcompare">${comparison.map(asset=>`<div class="revieworigin">
<button class="revieworigincover" data-review-open-item="${asset.id}" aria-label="打开原视频 ${esc(asset.name||'')}">
${asset.preview_url?`<img src="${esc(asset.preview_url)}" alt="" loading="lazy" onerror="this.remove()">`:'<span>无封面</span>'}</button>
- <div><b title="${esc(asset.name||'')}">${esc(asset.code||asset.name||'原视频')}</b>
+ <div><b data-middle-truncate title="${esc(asset.name||'')}">${esc(asset.code||asset.name||'原视频')}</b>
<button type="button" data-review-open-item="${asset.id}">${icon('play')}打开原视频</button></div></div>`).join('')}</div>`:'';
const origin=comparisonOrigin||subjectKind&&subjectName?comparisonOrigin||`<div class="reviewentity">
<button class="reviewentityface" data-entity-kind="${subjectKind}" data-entity-name="${esc(subjectName)}"
@@ -1483,7 +1483,7 @@ async function openReview(push=true){
:row.asset_id?`<div class="revieworigin">
<button class="revieworigincover" data-review-open-item="${row.asset_id}" aria-label="打开原视频 ${esc(row.asset_name||'')}">
${row.asset_preview_url?`<img src="${esc(row.asset_preview_url)}" alt="" loading="lazy" onerror="this.remove()">`:'<span>无封面</span>'}</button>
- <div><b title="${esc(row.asset_name||'')}">${esc(row.asset_name||'原视频')}</b>
+ <div><b data-middle-truncate title="${esc(row.asset_name||'')}">${esc(row.asset_name||'原视频')}</b>
<button type="button" data-review-open-item="${row.asset_id}">${icon('play')}打开原视频</button></div></div>`:'';
/* 只有一个候选时没什么可选的,单选圈只是让人以为还有别的选项。
改成纯展示,几何对齐上面的「打开原视频」块。
@@ -1747,7 +1747,7 @@ function followQueueHtml(group,itemId){
:`<span class="fnothumb">${sourceIcon(item.provider)}</span>`;
return `<div class="mixrow"><button class="mixitem ${item.id===itemId?'current':''}" data-follow-queue-item="${item.id}" aria-current="${item.id===itemId?'true':'false'}">
<span class="mixitempic">${thumb}${item.duration?`<i class="dur mono">${fmtDur(item.duration)}</i>`:''}</span>
- <span class="mixitemtext"><b>${esc(copy.title)}</b><span><i class="fvkind ${esc(item.variant_kind||'')}">${esc(copy.label)}</i>${followWhen(item)}</span></span></button></div>`;
+ <span class="mixitemtext"><b data-truncate-end>${esc(copy.title)}</b><span data-truncate-end><i class="fvkind ${esc(item.variant_kind||'')}">${esc(copy.label)}</i>${followWhen(item)}</span></span></button></div>`;
}).join('')}</div></aside>`;
}
@@ -1759,7 +1759,7 @@ function followEmbeddedQueueHtml(item,mediaIndex){
?`<img src="${esc(media.thumb_url)}" alt="" loading="lazy" referrerpolicy="no-referrer" onerror="this.remove()">`
:`<span class="fnothumb">${sourceIcon(media.resource_provider||item.provider)}</span>`;
return `<div class="mixrow"><button class="mixitem ${media.index===mediaIndex?'current':''}" data-follow-media-item="${media.index}" data-media-kind="${media.media_kind}" aria-current="${media.index===mediaIndex?'true':'false'}">
- <span class="mixitempic">${thumb}</span><span class="mixitemtext"><b>${esc(media.name)}</b><span>${media.media_kind==='image'?'图片':'视频'}</span></span></button></div>`;
+ <span class="mixitempic">${thumb}</span><span class="mixitemtext"><b data-middle-truncate>${esc(media.name)}</b><span data-truncate-end>${media.media_kind==='image'?'图片':'视频'}</span></span></button></div>`;
}).join('')}</div></aside>`;
}
@@ -4028,7 +4028,7 @@ function queueHtml(queue,itemId){
const thumb=x.has_thumb?`<img src="/poster?id=${x.id}&c=4" alt="" loading="lazy">`:'';
const edit=queue.kind==='playlist'?`<span class="queueedit"><button data-queue-up="${index}" aria-label="上移" ${index===0?'disabled':''}>↑</button><button data-queue-down="${index}" aria-label="下移" ${index===queue.items.length-1?'disabled':''}>↓</button><button data-queue-remove="${x.id}" aria-label="移出播放列表">${icon('x')}</button></span>`:'';
return `<div class="mixrow"><button class="mixitem ${x.id===itemId?'current':''}" data-queue-item="${x.id}" aria-current="${x.id===itemId?'true':'false'}">
- <span class="mixitempic">${thumb}<i class="dur mono">${fmtDur(x.duration)}</i></span><span class="mixitemtext"><b>${esc(x.name)}</b><span>${queue.kind==='parts'?`第 ${esc(x.part_label)} 卷`:esc(mixLabel(x))}</span></span></button>${edit}</div>`;
+ <span class="mixitempic">${thumb}<i class="dur mono">${fmtDur(x.duration)}</i></span><span class="mixitemtext"><b data-middle-truncate>${esc(x.name)}</b><span data-truncate-end>${queue.kind==='parts'?`第 ${esc(x.part_label)} 卷`:esc(mixLabel(x))}</span></span></button>${edit}</div>`;
}).join('')}</div></aside>`;
}
async function buildMix(seedId){