Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(web): 窄屏筛选框按滚动方向切换吸顶

longmeidaod9c1cafb0f18
diff --git a/docs/BOARD_UI.md b/docs/BOARD_UI.md
index bf28d05f7..6dbc69168 100644
--- a/docs/BOARD_UI.md
+++ b/docs/BOARD_UI.md
@@ -1,5 +1,9 @@
# BoardUI 适配
+## 窄屏筛选框滚动
+
+760px 及以下,首页与实体资料页的共享筛选框向下滚时随页面离开顶部,向上滚时恢复吸顶。方向累计 8px 才切换,使用现有 `--board-motion` 过渡顶部约束,文档占位保持不变;减少动态效果时即时切换。页面顶端、键盘焦点、输入与展开菜单保持筛选可见,桌面维持吸顶。原生 sticky 与滚动事件足够覆盖此交互,不新增依赖;浏览器视觉验收未取得。
+
## 窄屏搜索玻璃动效
2026-09-11 核对 [liquid-gooey spring.ts](https://github.com/Jakubantalik/Libraries/blob/422180dd7a5ac646c85deedc65500c4a74339127/packages/liquid-gooey/src/spring.ts),MIT,源码 SHA-256 `9dc0d5e9dd269000d95743572320039404982803d1b2da9977e717b5956d5481`。
diff --git a/docs/REUSE.md b/docs/REUSE.md
index fa5604ac8..cfff0d9c5 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -2,6 +2,8 @@
## Board 界面与数值设置
+- 窄屏筛选框共用 `filterScrollState()`、现有滚动帧调度和原生 sticky;同一方向累计 8px 再切换吸顶,保留文档占位与键盘可达性,无新增依赖。
+
- 搜索玻璃复用 `glideEase()` 的采样弹簧;`web/js/search-morph.js` 只负责视口边界与轮廓关键帧,证据与差异见 `BOARD_UI.md`,无新增依赖。
- 浮层筛选由 `web/js/ui-components.js` 的 `mountFilterFrame()` 承载:首页与实体资料页共用视图、标签、读数、控件四个槽位。外框负责玻璃与吸顶,页面负责查询状态和事件;视频、照片与名册更新只替换底行。复用现有 Board 控件及原生 DOM,不新增依赖;身份与观看状态的组合沿用 `/api/items`。
diff --git a/tests/test_web_js.py b/tests/test_web_js.py
index c1e97817c..1c8a5a2bd 100644
--- a/tests/test_web_js.py
+++ b/tests/test_web_js.py
@@ -53,6 +53,25 @@ process.stdout.write(JSON.stringify(results));
@unittest.skipUnless(NODE, "没装 Node,纯模块的行为验收跳过")
class WebJsBehaviourTests(unittest.TestCase):
+ def test_mobile_filter_scroll_has_direction_hysteresis_and_visible_resets(self):
+ down = dict(y=120, origin=100, direction=1, free=True)
+ jitter = dict(y=117, origin=120, direction=-1, free=True)
+ cases = [
+ [None, 100, True],
+ [dict(y=100, origin=100, direction=0, free=False), 108, True],
+ [down, 117, True],
+ [jitter, 112, True],
+ [down, 120, True],
+ [down, -4, True],
+ [down, 130, False],
+ [down, 130, True, True],
+ ]
+ results = self.run_js([("filter-scroll.js", "filterScrollState", args) for args in cases])
+ self.assertEqual([result["free"] for result in results],
+ [False, True, True, False, True, False, False, False])
+ self.assertEqual(results[2]["origin"], 120)
+ self.assertEqual(results[5]["y"], 0)
+
def test_search_glass_morph_has_geometry_and_stays_in_the_viewport(self):
css = (ROOT / "web/board.css").read_text(encoding="utf-8")
easing = css.split("--spring-pane:", 1)[1].split(";", 1)[0]
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index e28cb47df..9256a4fae 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -2518,6 +2518,15 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("$('#searchBtn').setAttribute('aria-expanded',String(open));")
self.assertPageContains("if(innerWidth>760||matchMedia('(prefers-reduced-motion:reduce)').matches)return;")
+ def test_mobile_filter_frame_scroll_keeps_its_document_space(self):
+ board = (Path(__file__).resolve().parents[1] / "web/board.css").read_text(encoding="utf-8")
+ self.assertPageContains("document.querySelectorAll('[data-filter-frame]')")
+ self.assertPageContains("const active=frames.find(frame=>frame.offsetParent!==null);")
+ self.assertPageContains("mobileFilterScroll=filterScrollState(mobileFilterScroll,y,innerWidth<=760,hold);")
+ self.assertIn(".board-filter-frame.board-filter-frame{transition:top var(--board-motion)}", board)
+ self.assertIn(".board-filter-frame.board-filter-frame.mobile-filter-free{top:var(--filter-free-top)}", board)
+ self.assertPageContains("document.documentElement.scrollHeight-innerHeight")
+
def test_unlinked_identity_does_not_look_clickable(self):
"""渲染成 `<span>` 的归属不能长得像链接。
diff --git a/web/app.js b/web/app.js
index 1f0335700..648e35edb 100644
--- a/web/app.js
+++ b/web/app.js
@@ -2,6 +2,7 @@ import { resourceScanHtml, boundedPreference, mountNumberSetting, syncNumberSett
import {$, ENTITY_ROUTES, LOC, ROUTE_ENTITIES, ROUTE_STATES, SITE_FAVICONS, STATE_LABELS, STATE_ROUTES, api, isAbort, mapLimit, brandIcon, entityPath, esc, faviconFallbackUrl, faviconUrl, linkHost, linkMarkUrl, fmtClock, fmtDur, fmtSize, foldName, icon, isCatalogPath, realDuration} from './js/core.js';
import { faceFrame } from './js/face-frame.js';
import { searchMorphFrames } from './js/search-morph.js';
+import { filterScrollState } from './js/filter-scroll.js';
import { selectRange, selectionSummary, selectGroup, syncSelectionToolbar } from './dist/peach-ui.js';
import { MEDIA_SOURCE_ICONS } from './js/media-source-icons.js';
import { boardPageSkeleton, initBoardControls, syncBoardRange, wireExpandableRanks, creatorSankeyHtml, wireCreatorSankey } from './dist/peach-ui.js';
@@ -8370,7 +8371,23 @@ function buildEdge(){
每次都新建 video 并发起 /stream 请求,直接把页面拖垮。 */
window.__scrolling=false; let scrollT=null;
let stickyFrame=0;
+let mobileFilterScroll=null,mobileFilterHost=null,mobileFilterPath='';
+function updateMobileFilterScroll(){
+ const frames=[...document.querySelectorAll('[data-filter-frame]')];
+ const active=frames.find(frame=>frame.offsetParent!==null);
+ if(active!==mobileFilterHost||location.pathname!==mobileFilterPath)mobileFilterScroll=null;
+ mobileFilterHost=active;mobileFilterPath=location.pathname;
+ const y=Math.max(0,Math.min(scrollY,document.documentElement.scrollHeight-innerHeight));
+ const hold=!!active?.querySelector(':focus-visible,input:focus,select:focus,textarea:focus,[aria-expanded="true"]');
+ mobileFilterScroll=filterScrollState(mobileFilterScroll,y,innerWidth<=760,hold);
+ for(const frame of frames){
+ const free=frame===active&&mobileFilterScroll.free;
+ if(free)frame.style.setProperty('--filter-free-top',`${-frame.offsetHeight-12}px`);
+ frame.classList.toggle('mobile-filter-free',free);
+ }
+}
function updateStickySurfaces(){
+ updateMobileFilterScroll();
updateReviewSticky($('.review'));
['.board-filter-frame','#tagbar','#count','.entitytagbar','.entitycollectionhead'].forEach(selector=>{
const el=$(selector),css=el&&getComputedStyle(el),top=css?parseFloat(css.top):NaN;
@@ -8384,6 +8401,8 @@ function scheduleStickySurfaces(){
if(stickyFrame)return;
stickyFrame=requestAnimationFrame(()=>{stickyFrame=0;updateStickySurfaces()});
}
+document.addEventListener('focusin',scheduleStickySurfaces);
+document.addEventListener('focusout',scheduleStickySurfaces);
window.addEventListener('scroll',()=>{
scheduleStickySurfaces();
window.__scrolling=true;
diff --git a/web/board.css b/web/board.css
index b7dc9c539..2a1adc909 100644
--- a/web/board.css
+++ b/web/board.css
@@ -483,6 +483,10 @@ body::before{display:none}
8px 还被 `.combo` 的下边距吃掉,加起来 32px,下面却只有 20px,同一块浮层上下差出 12px。
上面这 22px 改不动(两处都是别的页面共用的),所以自己不再加,下面照同一个数写。 */
.board-filter-frame{position:sticky;top:calc(var(--topH) + 8px);z-index:60;border:0;border-radius:16px;background:var(--ground);margin:0 0 22px;box-shadow:0 2px 14px #00000014}
+@media(max-width:760px){
+ .board-filter-frame.board-filter-frame{transition:top var(--board-motion)}
+ .board-filter-frame.board-filter-frame.mobile-filter-free{top:var(--filter-free-top)}
+}
/* 首页那块住在 `body` 底下,两侧没有任何东西给它留白,22px 的圆角直接切在屏幕边沿上;
资料页那块在 `#index` 里,`main` 的 16px 已经把它让开了。这里补的就是那 16px,取的
也是 `main` 自己的那个数,所以两页的浮层和底下的网格对在同一条竖线上。 */
diff --git a/web/js/filter-scroll.js b/web/js/filter-scroll.js
new file mode 100644
index 000000000..fc229150c
--- /dev/null
+++ b/web/js/filter-scroll.js
@@ -0,0 +1,10 @@
+/** 窄屏滚动方向累计到 8px 才切换吸顶,顶端与控件交互保持显示。 */
+export function filterScrollState(previous,y,narrow,hold=false){
+ y=Math.max(0,y);
+ if(!previous||!narrow||hold||y<=8)return {y,origin:y,direction:0,free:false};
+ const delta=y-previous.y;
+ if(!delta)return previous;
+ const direction=Math.sign(delta),origin=direction===previous.direction?previous.origin:previous.y;
+ const free=Math.abs(y-origin)>=8?direction>0:previous.free;
+ return {y,origin,direction,free};
+}