Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(web): 排名与侧栏名单展开改走 Collapse 的高度过渡,展开时看得见动画

longmeidaoc8519779e006
diff --git a/docs/BOARD_UI.md b/docs/BOARD_UI.md
index bcdab2f3e..44de50023 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 渐隐是主动差异;点按展开键时列表高度与箭头同走 200ms 过渡(用户要求,上游没有高度动画),过渡只在点按那一下挂上,切维度标签引起的高度变化直接到位,不跟着抖 |
+| 「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/test/grow-collapse.test.ts b/frontend/test/grow-collapse.test.ts
new file mode 100644
index 000000000..623bfd18b
--- /dev/null
+++ b/frontend/test/grow-collapse.test.ts
@@ -0,0 +1,30 @@
+import { afterEach, expect, it, vi } from 'vitest';
+// @ts-expect-error 遗留模块由浏览器直接加载,此测试调用实际实现。
+import { growCollapse } from '../../web/js/ui-components.js';
+
+afterEach(() => { vi.useRealTimers(); document.body.replaceChildren(); });
+
+it('从起始高度长到内容高度,跑完交回 auto 并装回展开态', () => {
+ vi.useFakeTimers();
+ const body = document.createElement('div'); body.className = 'fcollapse fcollapse-settled'; document.body.append(body);
+ Object.defineProperty(body, 'scrollHeight', { configurable: true, value: 480 });
+ growCollapse(body, 120);
+ expect(body.classList.contains('fcollapse-settled')).toBe(false);
+ expect(body.style.height).toBe('480px');
+ body.dispatchEvent(Object.assign(new Event('transitionend'), { propertyName: 'opacity' }));
+ expect(body.style.height).toBe('480px');
+ vi.advanceTimersByTime(260);
+ expect(body.style.height).toBe('auto');
+ expect(body.classList.contains('fcollapse-settled')).toBe(true);
+});
+
+it('过渡途中又被收起时不收尾', () => {
+ vi.useFakeTimers();
+ const body = document.createElement('div'); body.className = 'fcollapse'; document.body.append(body);
+ let open = true;
+ growCollapse(body, 0, () => open);
+ open = false; body.style.height = '0px';
+ vi.advanceTimersByTime(260);
+ expect(body.style.height).toBe('0px');
+ expect(body.classList.contains('fcollapse-settled')).toBe(false);
+});
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index 231db82c4..3279cba19 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -6962,6 +6962,9 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("group.querySelector('.chips').outerHTML=chips(src,k,false,expanded?lim:999);")
self.assertPageContains("b.setAttribute('aria-expanded',String(!expanded));")
self.assertPageContains("if(expanded)group.querySelector('.board-section-toggle').click();")
+ # 摊开那一下和分组 Collapse 走同一份高度过渡,不是整段名单瞬间铺出来。
+ self.assertPageContains("if(!expanded&&body)growCollapse(body,before,()=>toggle.getAttribute('aria-expanded')==='true');")
+ self.assertPageContains("export function growCollapse(body,start,isCurrent=()=>true){")
# 摊开的内容全在按下的这个点以下,这一列停在哪儿归人自己管。
self.assertPageContains("const scroller=$('#drawerScroll'),keep=scroller.scrollTop;")
self.assertPageContains("bind();hold();requestAnimationFrame(hold);});")
@@ -10386,7 +10389,8 @@ class WebUiSourceTests(unittest.TestCase):
盖的那种要先猜卡片是什么底色,猜错就在图上留一道横带;淡的这种在任何底色上都
成立。boardui 实测:列表自己带 `linear-gradient(#000 calc(100% - 44px),transparent)`,
展开就取消,正好露五行、淡掉最后 44px。两头高度由 JS 量好写进变量,展开收起的
- 高度过渡与箭头旋转共用同一组 200ms 曲线。
+ 高度过渡与共用 Collapse 同为 `.2s ease-in-out`:展开要长上千像素,先快后慢的曲线
+ 在头一帧就把视口里那一截长完,看着像没有动画。
"""
board = (Path(__file__).resolve().parents[1] / "web/board.css").read_text(encoding="utf-8")
controls = (Path(__file__).resolve().parents[1] / "frontend/src/board-controls.ts").read_text(encoding="utf-8")
@@ -10394,7 +10398,9 @@ class WebUiSourceTests(unittest.TestCase):
"{mask-image:linear-gradient(#000 calc(100% - 44px),transparent)}", board)
self.assertNotIn(".board-expand-ranks:not(.expanded)::after", board)
# 过渡只挂在点展开键的那一下:切维度标签时内容换了、量出的高度跟着变,常驻过渡会让列表抖一下。
- self.assertIn(".board-expand-ranks.toggling>.board-rank-list{transition:max-height .2s cubic-bezier(0,0,.2,1)}", board)
+ self.assertIn(".board-expand-ranks.toggling>.board-rank-list{transition:max-height .2s ease-in-out}", board)
+ self.assertIn(".fcollapse{overflow:hidden;transition:height .2s ease-in-out}", (
+ Path(__file__).resolve().parents[1] / "web/css/08-photos.css").read_text(encoding="utf-8"))
self.assertNotIn("overflow:hidden;transition:max-height", board)
self.assertIn(".board-rank-list,.board-expand-ranks.toggling>.board-rank-list,"
".board-rank-expand svg{transition:none}", board)
diff --git a/web/app.js b/web/app.js
index 68a88cdee..49cf44dea 100644
--- a/web/app.js
+++ b/web/app.js
@@ -19,7 +19,7 @@ import {
attachOverlayScrollbar, breadcrumbHtml, checkboxHtml, collectionSummaryHtml, closeAnchoredMenu, confirmModal, dismissMenu, emptyStateHtml, fieldsetTitle, selectOptionIconHtml,
fillSkeletonTier, fitSkeleton, formModal, iconSwitchHtml, indexSkeletonHtml, loadingDotsHtml,
mediaViewButtonsHtml, boardTabsHtml, mountFilterFrame, filterChipHtml, moveGlidePane, glideEase, sortControlsHtml, collectionHeaderHtml, wireHorizontalScroller, noteHtml, presentMenu, progressHtml, gaugeHtml, scrollerHtml, searchInputHtml, selectFieldHtml,
- setActionBusy, skeletonHtml, spinnerHtml, wireAnchoredMenu, wireBusyActions, wireCollapse, wireDragReorder,
+ setActionBusy, skeletonHtml, spinnerHtml, growCollapse, wireAnchoredMenu, wireBusyActions, wireCollapse, wireDragReorder,
wireIconSwitch, wireOverlayScrollbars, wireScrollers, wireSelectField, wireContextCard, configurationSkeletonHtml, wireLoadMore,
} from './js/ui-components.js';
@@ -3992,7 +3992,11 @@ async function buildBars(){
现在要看第几条。名单一变长,浏览器会顺着焦点和锚定把这一列推走,所以记下再放回。 */
const scroller=$('#drawerScroll'),keep=scroller.scrollTop;
const hold=()=>{scroller.scrollTop=keep};
+ const body=group.querySelector(':scope > .fcollapse'),before=body?.getBoundingClientRect().height;
group.querySelector('.chips').outerHTML=chips(src,k,false,expanded?lim:999);
+ /* 摊开时名单从二十几条长到全部,和分组的 Collapse 走同一份高度过渡;中途收起整组就不收尾。 */
+ const toggle=group.querySelector('.board-section-toggle');
+ if(!expanded&&body)growCollapse(body,before,()=>toggle.getAttribute('aria-expanded')==='true');
b.setAttribute('aria-expanded',String(!expanded));
b.setAttribute('aria-label',(expanded?'展开全部':'收起')+name);
/* 收起收的是整组。名单已经摊到最长,把它退回二十几条只是换一个断点,人还站在同一
diff --git a/web/board.css b/web/board.css
index 3ff059ef7..957024f49 100644
--- a/web/board.css
+++ b/web/board.css
@@ -1340,7 +1340,7 @@ html.board-high-contrast :is(.selectiondock,.reviewcontrols.is-stuck,.reviewgrou
/* 收起时最后一行是被 mask 淡掉的,不是被一块渐变色盖住(boardui 实测:列表自己带
`linear-gradient(#000 calc(100% - 44px),transparent)`,展开就取消)。盖的那种要先猜卡片
是什么底色,猜错就在图上留一道横带;淡的这种在任何底色上都成立。 */
-.board-expand-ranks{position:relative;padding-bottom:28px}.board-rank-list{position:relative;display:grid;grid-template-columns:1fr;max-height:var(--rank-collapsed-height,300px);overflow:hidden}.board-expand-ranks.toggling>.board-rank-list{transition:max-height .2s cubic-bezier(0,0,.2,1)}.board-expand-ranks:not(.expanded)>.board-rank-list{mask-image:linear-gradient(#000 calc(100% - 44px),transparent)}.board-expand-ranks.expanded>.board-rank-list{max-height:var(--rank-expanded-height)}.board-rank-expand{position:absolute;z-index:1;bottom:4px;left:50%;transform:translateX(-50%);display:grid;place-items:center;width:40px;height:20px;padding:0;border:1px solid var(--line);border-radius:999px;background:var(--surface);box-shadow:0 1px 3px #0000001a;color:var(--muted)}.board-rank-expand svg{width:14px;height:14px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;transition:transform .2s cubic-bezier(0,0,.2,1)}.board-rank-expand[aria-expanded=true] svg{transform:rotate(180deg)}
+.board-expand-ranks{position:relative;padding-bottom:28px}.board-rank-list{position:relative;display:grid;grid-template-columns:1fr;max-height:var(--rank-collapsed-height,300px);overflow:hidden}.board-expand-ranks.toggling>.board-rank-list{transition:max-height .2s ease-in-out}.board-expand-ranks:not(.expanded)>.board-rank-list{mask-image:linear-gradient(#000 calc(100% - 44px),transparent)}.board-expand-ranks.expanded>.board-rank-list{max-height:var(--rank-expanded-height)}.board-rank-expand{position:absolute;z-index:1;bottom:4px;left:50%;transform:translateX(-50%);display:grid;place-items:center;width:40px;height:20px;padding:0;border:1px solid var(--line);border-radius:999px;background:var(--surface);box-shadow:0 1px 3px #0000001a;color:var(--muted)}.board-rank-expand svg{width:14px;height:14px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;transition:transform .2s cubic-bezier(0,0,.2,1)}.board-rank-expand[aria-expanded=true] svg{transform:rotate(180deg)}
.board-rank-list .tasterank{position:relative;isolation:isolate;border:0;border-radius:8px;background:transparent;overflow:hidden;min-height:44px}.board-rank-list .taste-rank-track{position:absolute;inset:0;height:100%;margin:0;z-index:-1;background:none;opacity:.14}.board-rank-list .taste-rank-track i{height:100%;border-radius:8px}
.board-sankey-card{padding:20px;border-radius:20px;margin-bottom:20px;background:var(--color-background-secondary-default);min-width:0}.board-sankey-card header{display:grid;grid-template-columns:1fr auto;gap:8px;margin-bottom:20px}.board-sankey-card h3{margin:0;font:var(--board-heading)}.board-sankey-card header b{grid-row:2;font:var(--board-title);font-variant-numeric:tabular-nums}.board-sankey-card header span{grid-column:2;grid-row:2;color:var(--muted);align-self:end;font:var(--board-caption)}.board-sankey-scroll{overflow-x:auto}.board-sankey-scroll svg{display:block;width:100%;min-width:640px;max-height:520px}.board-sankey-links path{fill:none;stroke:var(--flow-color);opacity:.3;transition:opacity .2s;animation:board-heat-enter .6s ease-out}.board-sankey-nodes g{transition:opacity .2s}.board-sankey-nodes text{fill:var(--color-text-primary);font:var(--board-caption)}.board-sankey-nodes tspan{fill:var(--muted);font-size:11px}.board-sankey-card footer{display:flex;justify-content:space-between;color:var(--muted);font:var(--board-caption);margin-top:12px}
.tasteactions [data-taste-window] .gselectfield::before{content:'';width:16px;height:16px;flex:none;background:currentColor;mask:url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2"%3E%3Crect x="3" y="5" width="18" height="16" rx="2"/%3E%3Cpath d="M16 3v4M8 3v4M3 11h18"/%3E%3C/svg%3E') center/contain no-repeat}
diff --git a/web/js/ui-components.js b/web/js/ui-components.js
index a77953543..506263110 100644
--- a/web/js/ui-components.js
+++ b/web/js/ui-components.js
@@ -716,17 +716,6 @@ export function wireCollapse(root,selector,idPrefix,triggerSelector='summary'){
if(expanded)body.classList.add('fcollapse-settled');
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;
@@ -735,19 +724,41 @@ export function wireCollapse(root,selector,idPrefix,triggerSelector='summary'){
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';body.classList.add('fcollapse-settled')});
+ growCollapse(body,start,()=>run===transitionRun);
}else{
body.inert=true;body.classList.remove('fcollapse-settled');
body.style.height=body.getBoundingClientRect().height+'px';body.getBoundingClientRect();
body.style.height='0px';
- settle(run,()=>{details.open=false;body.style.height=''});
+ settleHeight(body,()=>{if(run===transitionRun){details.open=false;body.style.height=''}});
}
});
});
}
+/* 高度过渡跑完再收尾;减少动效时没有 transitionend,260ms 兜底。 */
+function settleHeight(body,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);
+ fn();
+ };
+ body.addEventListener('transitionend',finish);
+ timer=setTimeout(finish,260);
+}
+
+/**
+ * `.fcollapse` 从 `start` 长到内容此刻的高度,跑完交回 `auto` 并摘掉裁边。Collapse 展开与
+ * 侧栏名单摊开共用这一份。`isCurrent` 返回 false 说明中途又被收起,收尾就不做。
+ */
+export function growCollapse(body,start,isCurrent=()=>true){
+ body.classList.remove('fcollapse-settled');
+ body.style.height=start+'px';body.getBoundingClientRect();
+ body.style.height=body.scrollHeight+'px';
+ settleHeight(body,()=>{if(isCurrent()){body.style.height='auto';body.classList.add('fcollapse-settled')}});
+}
+
/* 锚定在触发钮上的菜单:无展开动画,固定在视口内,内容在菜单内滚动。
优先从触发钮右缘向左展开,下方放不下时改到上方。全站的锚定菜单共用这一份定位与