Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(web): 搜索玻璃从图标位置弹性伸展

longmeidao19384facc89e
diff --git a/docs/BOARD_UI.md b/docs/BOARD_UI.md
index f713c76fd..bf28d05f7 100644
--- a/docs/BOARD_UI.md
+++ b/docs/BOARD_UI.md
@@ -4,7 +4,9 @@
2026-09-11 核对 [liquid-gooey spring.ts](https://github.com/Jakubantalik/Libraries/blob/422180dd7a5ac646c85deedc65500c4a74339127/packages/liquid-gooey/src/spring.ts),MIT,源码 SHA-256 `9dc0d5e9dd269000d95743572320039404982803d1b2da9977e717b5956d5481`。
-Peach 复用已采样的短程弹簧(208ms,stiffness 3600、damping 68、mass 1),以 CSS 裁切和透明度衔接开合;搜索建议在展开完成后解除裁切。控件固定 36px 高度,按顶栏实际高度居中,右侧按钮依次为搜索、沉浸、多选。
+形变证据来自同一 revision 的 `LiquidItem.tsx`:`morph.shape` 将尺寸变化描述为弹性形变、过冲和软胶回落;`observer.ts`(SHA-256 `5e44c076e50ceb707572cd7b4e083f835a5d454cc21fb405f5c7dd3ff3ef4865`)分别驱动位置、尺寸和圆角。此前记录的裁切与透明度方案未满足用户要求的图标形变,不能作为形变验收证据。 <!-- copy-lint-disable-line -->
+
+Peach 使用现有 313ms 玻璃弹簧(stiffness 1700、damping 46、mass 1),从图标真实矩形变为搜索框,轮廓中途鼓起、回落,反向操作从当前可见矩形接续。关键帧限制在视口内,玻璃全程可见,文字不横向缩放。尺寸动画只作用于绝对定位的搜索层,建议面板在动画结束后显示;起止同高 36px、共用顶栏中心线。右侧按钮依次为搜索、沉浸、多选。
未新增依赖;上游未作为完整搜索组件复刻。上游搜索交互与本轮浏览器实测未取得,本轮按用户要求不调用浏览器工具。
diff --git a/docs/REUSE.md b/docs/REUSE.md
index 42b75f252..fa5604ac8 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -2,6 +2,8 @@
## Board 界面与数值设置
+- 搜索玻璃复用 `glideEase()` 的采样弹簧;`web/js/search-morph.js` 只负责视口边界与轮廓关键帧,证据与差异见 `BOARD_UI.md`,无新增依赖。
+
- 浮层筛选由 `web/js/ui-components.js` 的 `mountFilterFrame()` 承载:首页与实体资料页共用视图、标签、读数、控件四个槽位。外框负责玻璃与吸顶,页面负责查询状态和事件;视频、照片与名册更新只替换底行。复用现有 Board 控件及原生 DOM,不新增依赖;身份与观看状态的组合沿用 `/api/items`。
- 组件映射、官方公开注册表证据与许可证见 [Board 界面](BOARD_UI.md)。`web/board.css` 共用正式页面结构,设置可关闭该视觉层;登录和首启页共用 `board_entry_style()`。
diff --git a/tests/test_web_js.py b/tests/test_web_js.py
index 2268029f8..c1e97817c 100644
--- a/tests/test_web_js.py
+++ b/tests/test_web_js.py
@@ -53,6 +53,31 @@ process.stdout.write(JSON.stringify(results));
@unittest.skipUnless(NODE, "没装 Node,纯模块的行为验收跳过")
class WebJsBehaviourTests(unittest.TestCase):
+ 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]
+ for viewport in (320, 390, 760):
+ expanded = dict(left=48, top=14, width=viewport-56, height=36)
+ compact = dict(left=viewport-124, top=14, width=36, height=36)
+ interrupted = dict(left=80, top=12, width=180, height=40)
+ for start, end in ((compact, expanded), (expanded, compact), (interrupted, compact)):
+ with self.subTest(viewport=viewport, start=start):
+ frames = self.run_js([("search-morph.js", "searchMorphFrames",
+ [start, end, expanded, 7, 16, easing, viewport])])[0]
+ self.assertGreater(len(frames), 2)
+ self.assertAlmostEqual(float(frames[0]["width"][:-2]), start["width"])
+ self.assertAlmostEqual(float(frames[-1]["width"][:-2]), end["width"])
+ self.assertGreater(max(float(frame["height"][:-2]) for frame in frames), 36)
+ for frame in frames:
+ x, y = (float(value[:-2]) for value in frame["translate"].split())
+ left = expanded["left"] + x
+ width = float(frame["width"][:-2])
+ height = float(frame["height"][:-2])
+ self.assertGreaterEqual(left, 8)
+ self.assertLessEqual(left + width, viewport - 8 + .001)
+ self.assertAlmostEqual(expanded["top"] + y + height/2, 32)
+ self.assertNotIn("opacity", frame)
+
@classmethod
def setUpClass(cls):
cls._tmp = tempfile.TemporaryDirectory()
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index 4ae328ae6..e28cb47df 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -2510,11 +2510,13 @@ class WebUiSourceTests(unittest.TestCase):
board = (root / "web/board.css").read_text(encoding="utf-8")
self.assertLess(html.index('id="searchBtn"'), html.index('id="immerseBtn"'))
self.assertLess(html.index('id="immerseBtn"'), html.index('id="selectMode"'))
- self.assertIn("transition:clip-path calc(var(--spring-press-ms) * 1ms) var(--spring-press)", board)
- self.assertIn(".top .search.search-ready{clip-path:none}", board)
+ self.assertIn(".top .search.search-morphing{contain:layout;overflow:hidden}", board)
+ self.assertPageContains("const anchor=button.getBoundingClientRect();")
+ self.assertPageContains("const from=interrupted?current:open?anchor:expanded,to=open?expanded:anchor;")
+ self.assertPageContains("motion.onfinish=()=>{if(searchMorph===motion)finishSearchMorph()};")
self.assertPageContains("if(document.activeElement===$('#q'))return;")
self.assertPageContains("$('#searchBtn').setAttribute('aria-expanded',String(open));")
- self.assertPageContains("if(open&&matchMedia('(prefers-reduced-motion:reduce)').matches)")
+ self.assertPageContains("if(innerWidth>760||matchMedia('(prefers-reduced-motion:reduce)').matches)return;")
def test_unlinked_identity_does_not_look_clickable(self):
"""渲染成 `<span>` 的归属不能长得像链接。
diff --git a/web/app.js b/web/app.js
index 9b77be658..1f0335700 100644
--- a/web/app.js
+++ b/web/app.js
@@ -1,6 +1,7 @@
import { resourceScanHtml, boundedPreference, mountNumberSetting, syncNumberSetting, statCardBody, rankedChart, radarChart, distributionChart, jobActivityHtml, sidebarSectionHtml, wireSidebarGroups, transitionTheme } from './dist/peach-ui.js';
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 { 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';
@@ -16,7 +17,7 @@ import { javImageKind, normalizeJavImage, normalizeJavLayout, normalizeJavPrefer
import {
attachOverlayScrollbar, breadcrumbHtml, checkboxHtml, collectionSummaryHtml, closeAnchoredMenu, confirmModal, dismissMenu, emptyStateHtml, fieldsetTitle,
fillSkeletonTier, fitSkeleton, formModal, iconSwitchHtml, indexSkeletonHtml, loadingDotsHtml,
- mediaViewButtonsHtml, mountFilterFrame, filterChipHtml, moveGlidePane, sortControlsHtml, collectionHeaderHtml, wireHorizontalScroller, noteHtml, presentMenu, progressHtml, gaugeHtml, scrollerHtml, searchInputHtml, selectFieldHtml,
+ mediaViewButtonsHtml, mountFilterFrame, filterChipHtml, moveGlidePane, glideEase, sortControlsHtml, collectionHeaderHtml, wireHorizontalScroller, noteHtml, presentMenu, progressHtml, gaugeHtml, scrollerHtml, searchInputHtml, selectFieldHtml,
setActionBusy, skeletonHtml, spinnerHtml, wireAnchoredMenu, wireBusyActions, wireCollapse, wireDragReorder,
wireIconSwitch, wireOverlayScrollbars, wireScrollers, wireSelectField, wireContextCard, configurationSkeletonHtml, wireLoadMore,
} from './js/ui-components.js';
@@ -9501,20 +9502,44 @@ async function tokNext(d){
}
$('#immerseBtn').onclick=()=>openTok();
+let searchMorph=null;
+/* 玻璃轮廓与内容使用同一时间轴,位置和宽度从当前可见矩形接续。
+ 绝对定位层只在自身内部排版,字形不随玻璃宽度被压扁。 */
+function finishSearchMorph(){
+ searchMorph?.cancel();searchMorph=null;
+ $('.search').classList.remove('search-morphing');
+}
function setNarrowSearchOpen(open){
- const search=$('.search');
- if(search.classList.contains('search-ready')){
- search.classList.remove('search-ready');
- void search.offsetWidth;
- }
+ const search=$('.search'),button=$('#searchBtn');
+ if(search.classList.contains('open')===open)return;
+ const interrupted=!!searchMorph;
+ const current=search.getBoundingClientRect();
+ const currentPadding=parseFloat(getComputedStyle(search).paddingLeft);
+ finishSearchMorph();
+ search.classList.remove('open');
+ const anchor=button.getBoundingClientRect();
search.classList.toggle('open',open);
$('#searchBtn').setAttribute('aria-expanded',String(open));
- if(open&&matchMedia('(prefers-reduced-motion:reduce)').matches)search.classList.add('search-ready');
-}
-$('.search').addEventListener('transitionend',event=>{
- if(event.target===$('.search')&&event.propertyName==='clip-path'&&$('.search').classList.contains('open'))
- $('.search').classList.add('search-ready');
-});
+ if(innerWidth>760||matchMedia('(prefers-reduced-motion:reduce)').matches)return;
+ const expanded=search.getBoundingClientRect(),css=getComputedStyle(search);
+ const padding=parseFloat(css.paddingLeft);
+ const iconWidth=search.querySelector('svg').getBoundingClientRect().width;
+ const compactPadding=Math.max(0,(anchor.width-iconWidth)/2-parseFloat(css.borderLeftWidth));
+ const from=interrupted?current:open?anchor:expanded,to=open?expanded:anchor;
+ const ease=glideEase();
+ search.classList.add('search-morphing');
+ const motion=search.animate(searchMorphFrames(from,to,expanded,
+ interrupted?currentPadding:open?compactPadding:padding,open?padding:compactPadding,
+ ease.easing,innerWidth),{duration:ease.duration,easing:'linear',fill:'both'});
+ searchMorph=motion;
+ motion.onfinish=()=>{if(searchMorph===motion)finishSearchMorph()};
+}
+let searchMorphViewport=innerWidth;
+addEventListener('resize',()=>{
+ if(innerWidth===searchMorphViewport)return;
+ searchMorphViewport=innerWidth;finishSearchMorph();
+},{passive:true});
+matchMedia('(prefers-reduced-motion:reduce)').addEventListener('change',finishSearchMorph);
$('#searchBtn').onclick=()=>{setNarrowSearchOpen(true);$('#q').focus()};
/* 窄屏退出搜索。失焦那条 140ms 的兜底只在输入框为空时才收起搜索栏,
输入过内容就没有出口了;返回按钮无条件收起,并清掉下拉栏。 */
diff --git a/web/board.css b/web/board.css
index ab214a0a2..b7dc9c539 100644
--- a/web/board.css
+++ b/web/board.css
@@ -532,16 +532,14 @@ body>.board-filter-frame{margin-inline:16px}
.drawer #brandHome .mark{width:28px;height:28px}.drawer #brandHome h1{font-size:20px;letter-spacing:.02em}.drawer #brandHome .sub{display:none}
.edge::before{content:'';width:28px;height:28px;background:url('/peach-logo.png') center/contain no-repeat;padding:0;margin:4px 0 16px}
.top .search{max-width:none;flex:1 1 0;min-width:0;margin-left:0;margin-right:0}
-/* 搜索沿横向展开,复用短程玻璃弹簧;文字与控件高度保持固定。 */
+/* 搜索玻璃从图标的实际矩形形变,建议面板在轮廓收稳后显示。 */
@media(max-width:760px){
- .top .search{display:flex;visibility:hidden;pointer-events:none;opacity:0;
- clip-path:inset(0 80px 0 max(0px,calc(100% - 116px)) round 18px);
- transition:clip-path calc(var(--spring-press-ms) * 1ms) var(--spring-press),
- opacity calc(var(--spring-press-ms) * 1ms),visibility 0s calc(var(--spring-press-ms) * 1ms)}
- .top .search.open{visibility:visible;pointer-events:auto;opacity:1;
- clip-path:inset(0 0 0 0 round 18px);transition-delay:0s}
- .top .search.search-ready{clip-path:none}
- .top .search:not(.search-ready) .searchmenu{visibility:hidden}
+ .top .search{display:flex;visibility:hidden;pointer-events:none}
+ .top .search.open,.top .search.search-morphing{visibility:visible;pointer-events:auto}
+ .top .search.search-morphing{contain:layout;overflow:hidden}
+ .top .search.search-morphing .searchmenu{visibility:hidden}
+ .top:has(.search.search-morphing){overflow:visible}
+ .top:has(.search.search-morphing) #searchBtn{opacity:0}
}
.board-filter-frame #tagbar{height:48px;gap:6px;padding:8px 12px}
.board-filter-frame #tagbar .pill{height:30px;padding:0 10px;font-size:13px;line-height:20px;border-radius:8px;border:1px solid transparent}
diff --git a/web/js/search-morph.js b/web/js/search-morph.js
new file mode 100644
index 000000000..b2c275b30
--- /dev/null
+++ b/web/js/search-morph.js
@@ -0,0 +1,14 @@
+/* 使用项目采样弹簧构造玻璃轮廓,限制在视口内;内容不做横向缩放。 */
+export function searchMorphFrames(from,to,base,paddingFrom,paddingTo,easing,viewportWidth){
+ const values=easing.startsWith('linear(')?easing.slice(7,-1).split(',').map(Number):[0,1];
+ return values.map((progress,index)=>{
+ const t=index/(values.length-1),mix=(a,b)=>a+(b-a)*progress;
+ const left=Math.max(8,Math.min(viewportWidth-44,mix(from.left,to.left)));
+ const width=Math.max(36,Math.min(viewportWidth-8-left,mix(from.width,to.width)));
+ const height=mix(from.height,to.height)+Math.sin(Math.PI*t)*to.height*.12;
+ const center=mix(from.top+from.height/2,to.top+to.height/2);
+ return {offset:t,width:`${width}px`,height:`${height}px`,
+ translate:`${left-base.left}px ${center-height/2-base.top}px`,
+ paddingLeft:`${mix(paddingFrom,paddingTo)}px`,paddingRight:`${mix(paddingFrom,paddingTo)}px`};
+ });
+}