Peach: Local-first video metadata scraper and media manager.
fix(web): 收起排名时展开键钉在原位,页面不再先上移再回滚
longmeidao9186d064297b
diff --git a/docs/BOARD_UI.md b/docs/BOARD_UI.mdindex 44de50023..e6f601306 100644--- a/docs/BOARD_UI.md+++ b/docs/BOARD_UI.md@@ -255,7 +255,7 @@ Radial Chart Card、Bar List Card、Heatmap 与 Sankey 的 Pro 源码**未取得| 位置 | 上游 | Peach || --- | --- | --- || 排名行 | 行 36px、圆角 8、无悬停类;填充条 `absolute inset-y-0 left-0` 圆角 8,`chart-6` 14% 透明,只对宽度和颜色做 500ms 过渡 | 行与填充条圆角 8,填充 14%,去掉行悬停底(两层叠一起就是回执里的「违和」);行高保留 44 容两行字 |-| 「Show N more」 | 40×20 药丸,居中贴底 4px,`border-button-default` 描边、primary 底、xs 阴影,14px 箭头,悬停 primary-hover 150ms;被折起的行直接不渲染,没有渐隐 | 同尺寸同色;保留 48px 渐隐是主动差异;点按展开键时列表高度走共用 Collapse 的 `.2s ease-in-out`(用户要求,上游没有高度动画;先快后慢的曲线在头一帧就把视口里那截长完,展开看不出动画),过渡只在点按那一下挂上,切维度标签引起的高度变化直接到位,不跟着抖 |+| 「Show N more」 | 40×20 药丸,居中贴底 4px,`border-button-default` 描边、primary 底、xs 阴影,14px 箭头,悬停 primary-hover 150ms;被折起的行直接不渲染,没有渐隐 | 同尺寸同色;保留 48px 渐隐是主动差异;点按展开键时列表高度走共用 Collapse 的 `.2s ease-in-out`(用户要求,上游没有高度动画;先快后慢的曲线在头一帧就把视口里那截长完,展开看不出动画),过渡只在点按那一下挂上,切维度标签引起的高度变化直接到位,不跟着抖;收起时展开键逐帧钉在指针下(用户选定),卡片多在页底,变短引起的视口回退朝一个方向完成,不先上移再回滚 || 数据源卡的删除键 | 站上图标键 `size-9 rounded-2lg text-foreground-icon-secondary`,只过渡颜色 | 36px、圆角 10、透明底,悬停主文字色 6% 薄底加 `--drop` 文字,`transform:none` || 指标卡悬停 | 无对应 | `--surface` 与 `--ground` 在亮色里同为白,改主文字色 6% 混底 || 管理页标题 | 无对应 | `body body.cleanup-layout` 写错让标题一直留在 812px 窄列;标题、面包屑、导语不看布局类一律对齐 1120(复核、高清版、重复文件这些子页没有布局类),复核页容器同宽 |diff --git a/frontend/src/board-controls.ts b/frontend/src/board-controls.tsindex b8f198f50..ede2b5742 100644--- a/frontend/src/board-controls.ts+++ b/frontend/src/board-controls.ts@@ -138,7 +138,11 @@ export function wireExpandableRanks(root:ParentNode) {/* 高度过渡只挂在点按那一下。切维度标签时内容换了、量出的高度跟着变,常驻过渡会让列表抖一下。 */const settle=(event:Event)=>{if(event.target===list)outer.classList.remove('toggling')};list.addEventListener('transitionend',settle);list.addEventListener('transitioncancel',settle);- button.onclick=()=>{const expanded=button.getAttribute('aria-expanded')!=='true';button.setAttribute('aria-expanded',String(expanded));button.setAttribute('aria-label',expanded?'收起排名':'展开更多排名');outer.classList.add('toggling');update()};+ /* 收起时展开键钉在指针下。排名卡多在页底,列表变短后视口必须回退;不钉的话键先被带着上移、+ 到底后才换成页面回滚,方向中途一折就是「滚了一下」。过渡期间逐帧按它的位移回滚。 */+ const pin=()=>{const top=button.getBoundingClientRect().top,until=performance.now()+300;+ const hold=()=>{const shift=button.getBoundingClientRect().top-top;if(shift)window.scrollBy(0,shift);if(performance.now()<until)requestAnimationFrame(hold)};hold()};+ button.onclick=()=>{const expanded=button.getAttribute('aria-expanded')!=='true';button.setAttribute('aria-expanded',String(expanded));button.setAttribute('aria-label',expanded?'收起排名':'展开更多排名');outer.classList.add('toggling');update();if(!expanded)pin()};new ResizeObserver(size).observe(list);update();});}diff --git a/frontend/test/board-controls.test.ts b/frontend/test/board-controls.test.tsindex 165ae74f3..705db118b 100644--- a/frontend/test/board-controls.test.ts+++ b/frontend/test/board-controls.test.ts@@ -58,6 +58,18 @@ describe('范围控件',()=>{list.dispatchEvent(new Event('transitionend'));expect(outer.classList.contains('toggling')).toBe(false);});+ it('收起时展开键钉在原位:它被带着上移多少,页面就回滚多少;展开不动页面',()=>{+ document.body.innerHTML='<div class="tasteranks">'+Array.from({length:7},()=>'<button>排名</button>').join('')+'</div>';+ wireExpandableRanks(document);+ const toggle=document.querySelector<HTMLButtonElement>('.board-rank-expand')!;+ const scroll=vi.spyOn(window,'scrollBy').mockImplementation(()=>{});+ vi.stubGlobal('requestAnimationFrame',()=>0);+ try{+ toggle.click();expect(scroll).not.toHaveBeenCalled();+ vi.spyOn(toggle,'getBoundingClientRect').mockReturnValueOnce({top:400} as DOMRect).mockReturnValueOnce({top:300} as DOMRect);+ toggle.click();expect(scroll).toHaveBeenCalledWith(0,-100);+ }finally{vi.unstubAllGlobals();scroll.mockRestore()}+ });it('两个端点分别保留数值与不限状态,重复接线不增加气泡',()=>{document.body.innerHTML='<div class="dual-range"><input id="durMin" type="range" min="0" max="180" value="20"><input id="durMax" type="range" min="0" max="180" value="180"></div>';const inputs=[...document.querySelectorAll('input')];inputs.forEach(syncBoardRange);inputs.forEach(syncBoardRange);diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex 3279cba19..4ad1964c7 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -10405,6 +10405,9 @@ class WebUiSourceTests(unittest.TestCase):self.assertIn(".board-rank-list,.board-expand-ranks.toggling>.board-rank-list,"".board-rank-expand svg{transition:none}", board)self.assertIn("outer.classList.add('toggling')", controls)+ # 收起时展开键钉在指针下,页面回退朝一个方向完成,不先上移再回滚。+ self.assertIn("outer.classList.add('toggling');update();if(!expanded)pin()", controls)+ self.assertIn("if(shift)window.scrollBy(0,shift)", controls)# 箭头是描边字形。只给宽高的话 use 里那条折线会被默认 fill 填成一枚实心三角。self.assertIn(".board-rank-expand svg{width:14px;height:14px;fill:none;stroke:currentColor;""stroke-width:2;stroke-linecap:round;stroke-linejoin:round;"diff --git a/web/dist/peach-ui.js b/web/dist/peach-ui.jsindex 1b0198b94..196747674 100644--- a/web/dist/peach-ui.js+++ b/web/dist/peach-ui.js@@ -1293,9 +1293,17 @@ function Wt(e) {}, o = (t) => {t.target === e && n.classList.remove("toggling");};- e.addEventListener("transitionend", o), e.addEventListener("transitioncancel", o), r.onclick = () => {+ e.addEventListener("transitionend", o), e.addEventListener("transitioncancel", o);+ let s = () => {+ let e = r.getBoundingClientRect().top, t = performance.now() + 300, n = () => {+ let i = r.getBoundingClientRect().top - e;+ i && window.scrollBy(0, i), performance.now() < t && requestAnimationFrame(n);+ };+ n();+ };+ r.onclick = () => {let e = r.getAttribute("aria-expanded") !== "true";- r.setAttribute("aria-expanded", String(e)), r.setAttribute("aria-label", e ? "收起排名" : "展开更多排名"), n.classList.add("toggling"), a();+ r.setAttribute("aria-expanded", String(e)), r.setAttribute("aria-label", e ? "收起排名" : "展开更多排名"), n.classList.add("toggling"), a(), e || s();}, new ResizeObserver(i).observe(e), a();});}