refactor(ui): 全站 svg 图标收进 index.html 的 symbol sprite

前端 99 处 svg、56 个唯一图形(× 号 11 次、+ 号 6 次、复制与文档各 5 次),
43 处是纯冗余路径:改一个图标得在两三个文件里同步,加个新图标又要复制一份 path。
现在几何图形统一定义在 index.html 里的一份 sprite,引用写成
<svg 原属性><use href="#i-xxx"/></svg>——外层 class、尺寸、fill/stroke 原样保留,
所以大小和描边仍归各处 CSS 管(.ic / .tree-act svg / .files-fab svg),形状逐像素照搬。

脚本按几何指纹建映射,99 处全部命中,零未匹配;校验结果 symbol 56 个、
引用 99 处、无缺失、无未被引用、sprite 外无残留几何标签,JS 全部 node --check 通过。
同形但历史写法不同的(folder/folder-b/folder-c、x-line/x-line-b/x-path、eye/eye-sm 等)
各留一份 symbol,保证替换前后完全一致,后续要收敛只改引用指向即可。

sprite 容器用 position:absolute + 零尺寸,不用 display:none:后者在部分旧浏览器上
会让被引用的 symbol 也一并不渲染。

体积:index.html +6KB(sprite 定义),js 合计 -5.3KB,总量基本持平。
This commit is contained in:
2026-11-13 15:20:10 +08:00
parent 0433e61941
commit 2e2e47171f
9 changed files with 163 additions and 100 deletions
+2 -3
View File
@@ -145,8 +145,7 @@ function pvInfoNode(name, sizeText, hint) {
const box = document.createElement('div');
box.className = 'pv-none';
box.innerHTML =
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">' +
'<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline></svg>' +
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><use href="#i-file-doc"/></svg>' +
'<div class="nm"></div><div class="meta"></div><div class="hint"></div>';
box.querySelector('.nm').textContent = String(name || '');
box.querySelector('.meta').textContent = sizeText ? sizeText : '';
@@ -728,7 +727,7 @@ window.matchMedia('(min-width: 960px)').addEventListener('change', () => { if (!
// —— 通用 UI 卡片(stream.js 转发 SSE ui_card;任何 MCP 服务/工具回包附 type:"ui_card" 块即可产出)——
// 产生方契约 {action, arg, title?, note?};新交互在动作注册表加一条即可,未知 action 忽略(向前兼容)。
// 图标由前端统一持有(与 pv-none 同一枚文档 SVG),产生方不提供图形,只给数据。
const UI_CARD_ICON_DOC = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline></svg>';
const UI_CARD_ICON_DOC = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><use href="#i-file-doc"/></svg>';
const UI_CARD_ACTIONS = {
// arg = 相对会话目录的文件路径,点击 = openFilePreview(office 走预览网关,其余类型走文本/图片渲染)
open_preview: { go: '预览 ›', hint: '点击打开预览', icon: UI_CARD_ICON_DOC, run: (d) => openFilePreview(d.arg) },