Peach: Local-first video metadata scraper and media manager.
fix(web): 稳定搜索与主题切换中的玻璃合成
longmeidaoc0c098a6e783
diff --git a/docs/BOARD_UI.md b/docs/BOARD_UI.mdindex 0d1e1dd7a..e6938e939 100644--- a/docs/BOARD_UI.md+++ b/docs/BOARD_UI.md@@ -324,6 +324,8 @@ DatePicker 的内面板、候选草稿及取消/应用结构,候选不包含内部正文导航复用 `LinkButton`,右箭头沿用本地共享图标;无底色、无描边、4px 图文间距、20px 图标、hover 下划线。来源为 https://www.boardui.com/components/link-button 的公开注册表 https://www.boardui.com/r/link-button.json ,2026-09-11 取得,SHA-256 `05eb37b3cf1334c153e0702de05fe4989e4359c9c74d5ba55cc552a58e4629bd`。保留 Peach 的 Preact 与蓝色令牌,不新增依赖。外链保持外链图标和蓝色文字;Note 统一带淡背景、图文垂直居中。封面采集反馈列出本机与候选尺寸或实际失败原因,不以网络推测代替来源结果。+搜索玻璃使用原生 `blur(22px)`,保留底色、光晕与描边。主题扩散快照期间,各玻璃表面以当前主题实底承接光晕,结束或跳过动画后恢复实时背景采样;媒体库顶层弹窗使用同一规则。离开页面后清理已移除面板的 SVG 滤镜和尺寸监听。浏览器视觉验收未取得。+只读预览的 `/state-preview` 提供加载、准备、执行、等待重试、连接中断、恢复连接、失败、完成、状态失效及暂停等演示状态,复用 LibraryProcessing、Note、Project Banner 和进度组件。演示入口不调用任务接口,不写真实账本。390px 断线演示已验证页面宽度为 390px,卡片宽 358px。diff --git a/frontend/src/sidebar-groups.ts b/frontend/src/sidebar-groups.tsindex bb8e29617..fb381636e 100644--- a/frontend/src/sidebar-groups.ts+++ b/frontend/src/sidebar-groups.ts@@ -38,5 +38,10 @@ export async function transitionTheme(button:HTMLElement,apply:()=>void):Promiseconst mask='radial-gradient(circle closest-side,#000 78%,#0006 88%,transparent)';const style=document.createElement('style');style.textContent=`::view-transition-old(root){animation:none}::view-transition-new(root){mix-blend-mode:normal;mask-image:${mask};mask-repeat:no-repeat;will-change:mask-position,mask-size;animation:peach-theme-reveal 560ms cubic-bezier(.16,1,.3,1) both}@keyframes peach-theme-reveal{from{mask-position:${x}px ${y}px;mask-size:0px 0px}to{mask-position:${x-size/2}px ${y-size/2}px;mask-size:${size}px ${size}px}}`;themeChanging=true;document.head.append(style);- try{await document.startViewTransition(apply).finished}catch{apply()}finally{style.remove();themeChanging=false}+ const root=document.documentElement;+ root.dataset.themeSnapshot='true';+ let applied=false;+ const applyOnce=()=>{if(!applied){applied=true;apply()}};+ try{await document.startViewTransition(applyOnce).finished}catch{applyOnce()}+ finally{delete root.dataset.themeSnapshot;style.remove();themeChanging=false}}diff --git a/frontend/test/sidebar-groups.test.ts b/frontend/test/sidebar-groups.test.tsindex 1a2bcc619..485c62126 100644--- a/frontend/test/sidebar-groups.test.ts+++ b/frontend/test/sidebar-groups.test.ts@@ -1,7 +1,28 @@import { beforeEach, expect, it, vi } from 'vitest';vi.mock('@peach/legacy/ui',()=>vi.importActual('../../web/js/ui-components.js'));-import { sidebarSectionHtml, wireSidebarGroups } from '../src/sidebar-groups';+import { sidebarSectionHtml, wireSidebarGroups, transitionTheme } from '../src/sidebar-groups';beforeEach(()=>{document.body.replaceChildren();sessionStorage.clear()});+it('theme snapshots restore live glass after completion or rejection and apply once',async()=>{+ vi.stubGlobal('matchMedia',()=>({matches:false}));+ const button=document.createElement('button');document.body.append(button);+ for(const rejects of [false,true]){+ const apply=vi.fn();+ let finish!:()=>void;+ const finished=new Promise<void>((resolve,reject)=>{finish=()=>rejects?reject(new Error('skip')):resolve()});+ const start=vi.fn((update:()=>void)=>{+ expect(document.documentElement.dataset.themeSnapshot).toBe('true');+ update();return{finished};+ });+ Object.defineProperty(document,'startViewTransition',{configurable:true,value:start});+ const pending=transitionTheme(button,apply);+ expect(apply).toHaveBeenCalledTimes(1);+ finish();await pending;+ expect(apply).toHaveBeenCalledTimes(1);+ expect(document.documentElement.hasAttribute('data-theme-snapshot')).toBe(false);+ expect([...document.head.querySelectorAll('style')].some(style=>style.textContent?.includes('peach-theme-reveal'))).toBe(false);+ }+ Reflect.deleteProperty(document,'startViewTransition');vi.unstubAllGlobals();+});it('opens selected filters and preserves the user disclosure choice after rendering',()=>{const render=()=>{document.body.innerHTML=sidebarSectionHtml('标签','<button aria-pressed="true">已选标签</button>');wireSidebarGroups(document.body)};render();expect(document.querySelector<HTMLDetailsElement>('[data-sidebar-group]')!.open).toBe(true);diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex bb8196398..5ceb7e76a 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -4066,6 +4066,16 @@ class WebUiSourceTests(unittest.TestCase):self.assertIn('backdrop-filter:blur(22px) saturate(160%) var(--glass-lume)', menu)self.assertIn('var(--glass-shadow)', menu)+ def test_glass_compositing_covers_search_snapshots_and_disposed_panels(self):+ board = (Path(__file__).resolve().parents[1] / 'web/board.css').read_text(encoding='utf-8')+ self.assertIn('.top .search.search.search{--glass-optic:blur(22px)}', board)+ snapshot = board.split('html[data-theme-snapshot] :is(', 1)[1].split('}', 1)[0]+ for surface in ('.board-library-menu', '.board-filter-frame', '.search', '.drawer'):+ self.assertIn(surface, snapshot)+ self.assertIn('background-color:var(--ground)!important', snapshot)+ self.assertIn('backdrop-filter:none!important', snapshot)+ self.assertPageContains('observer.disconnect();filter.remove();attached.delete(node)')+def test_notes_and_navigation_links_keep_their_own_presentation(self):board = (Path(__file__).resolve().parents[1] / "web/board.css").read_text(encoding="utf-8")note = self.css.split('.geist-note{', 1)[1].split('}', 1)[0]diff --git a/web/app.js b/web/app.jsindex 43f257da9..f8db2f4ae 100644--- a/web/app.js+++ b/web/app.js@@ -10087,9 +10087,9 @@ if(/Chrome|Chromium|Edg\//.test(navigator.userAgent)){const ns='http://www.w3.org/2000/svg';const svg=document.createElementNS(ns,'svg');svg.setAttribute('width','0');svg.setAttribute('height','0');svg.setAttribute('aria-hidden','true');svg.style.position='fixed';svg.style.pointerEvents='none';const defs=document.createElementNS(ns,'defs');svg.append(defs);document.body.append(svg);- const attached=new WeakSet();let sequence=0;+ const attached=new Map();let sequence=0;function attach(node){- if(attached.has(node))return;attached.add(node);+ if(attached.has(node))return;const id=`peach-optic-${++sequence}`;const filter=document.createElementNS(ns,'filter');filter.id=id;filter.setAttribute('filterUnits','userSpaceOnUse');filter.setAttribute('color-interpolation-filters','sRGB');const map=document.createElementNS(ns,'feImage');map.setAttribute('result','edge-map');map.setAttribute('preserveAspectRatio','none');const displacement=document.createElementNS(ns,'feDisplacementMap');displacement.setAttribute('in','SourceGraphic');displacement.setAttribute('in2','edge-map');displacement.setAttribute('xChannelSelector','R');displacement.setAttribute('yChannelSelector','G');displacement.setAttribute('scale','24');filter.append(map,displacement);defs.append(filter);@@ -10112,9 +10112,15 @@ if(/Chrome|Chromium|Edg\//.test(navigator.userAgent)){反过来先位移再糊,折射出来的亮边会被第二步抹平,只剩一块均匀磨砂。 */node.style.setProperty('--glass-optic',`blur(14px) url("#${id}")`);node.dataset.opticGlass='true';};- new ResizeObserver(draw).observe(node);draw();+ const observer=new ResizeObserver(draw);observer.observe(node);+ attached.set(node,{observer,filter});draw();}- const sync=()=>document.querySelectorAll('.board-filter-frame,.top .search,.top>.ib,.edge,.drawer,.selectiondock,.reviewcontrols,.reviewgroupbar').forEach(attach);+ const sync=()=>{+ for(const [node,{observer,filter}] of attached){+ if(!node.isConnected){observer.disconnect();filter.remove();attached.delete(node)}+ }+ document.querySelectorAll('.board-filter-frame,.top>.ib,.edge,.drawer,.selectiondock,.reviewcontrols,.reviewgroupbar').forEach(attach);+ };new MutationObserver(sync).observe(document.querySelector('#main'),{childList:true,subtree:true});sync();}diff --git a/web/board.css b/web/board.cssindex 4dd54c675..42ea66cbc 100644--- a/web/board.css+++ b/web/board.css@@ -125,6 +125,11 @@backdrop-filter:var(--glass-optic,blur(22px)) saturate(160%) var(--glass-lume);-webkit-backdrop-filter:var(--glass-optic,blur(22px)) saturate(160%) var(--glass-lume);border:0;box-shadow:inset 0 1px 0 var(--glass-rim),inset 1px 0 0 var(--glass-low),inset -1px 0 0 var(--glass-low),inset 0 -1px 0 var(--glass-low),var(--glass-shadow);}+/* 搜索框使用浏览器原生模糊,尺寸变化不依赖异步 SVG 位移贴图。 */+.top .search.search.search{--glass-optic:blur(22px)}+/* 快照里的玻璃使用实底承接光晕;实时页面恢复后再采样背景。 */+html[data-theme-snapshot] :is(.board-filter-frame,.entitytagbar,.entitycollectionhead,.drawer,.edge,.search,.top>.ib,.board-library-menu,.viewglide,.navglide,.selectiondock,.reviewcontrols,.reviewgroupbar,.reviewbulktoolbar,.batchbar,.tagselection),+html[data-theme-snapshot] .review.review-is-stuck::before{backdrop-filter:none!important;-webkit-backdrop-filter:none!important;background-color:var(--ground)!important}.board-filter-frame.board-filter-frame{border-radius:22px;isolation:isolate;color:var(--glass-text);overflow:visible}.entitytagbar.entitytagbar.entitytagbar,.entitycollectionhead.entitycollectionhead.entitycollectionhead{border-radius:22px;color:var(--glass-text)}diff --git a/web/dist/peach-ui.js b/web/dist/peach-ui.jsindex 5010707f7..47bc19f38 100644--- a/web/dist/peach-ui.js+++ b/web/dist/peach-ui.js@@ -1721,12 +1721,17 @@ async function On(e, t) {}let n = e.getBoundingClientRect(), r = n.left + n.width / 2, i = n.top + n.height / 2, a = Math.hypot(Math.max(r, innerWidth - r), Math.max(i, innerHeight - i)) * 2.5, o = document.createElement("style");o.textContent = `::view-transition-old(root){animation:none}::view-transition-new(root){mix-blend-mode:normal;mask-image:radial-gradient(circle closest-side,#000 78%,#0006 88%,transparent);mask-repeat:no-repeat;will-change:mask-position,mask-size;animation:peach-theme-reveal 560ms cubic-bezier(.16,1,.3,1) both}@keyframes peach-theme-reveal{from{mask-position:${r}px ${i}px;mask-size:0px 0px}to{mask-position:${r - a / 2}px ${i - a / 2}px;mask-size:${a}px ${a}px}}`, Dn = !0, document.head.append(o);+ let s = document.documentElement;+ s.dataset.themeSnapshot = "true";+ let c = !1, l = () => {+ c || (c = !0, t());+ };try {- await document.startViewTransition(t).finished;+ await document.startViewTransition(l).finished;} catch {- t();+ l();} finally {- o.remove(), Dn = !1;+ delete s.dataset.themeSnapshot, o.remove(), Dn = !1;}}//#endregion