dsh-mindmap 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ All notable changes to this project are documented here. Release-specific notes
6
6
 
7
7
  ### Added
8
8
 
9
+ - Node search and quick navigation: ⌘/Ctrl+F (or the 🔍 in the canvas zoom bar) opens a compact search over the current mindmap — case-insensitive substring matching on node text, a `1 / 5` counter, and Enter / ↓ / ↑ (Shift+Enter) stepping through matches with wrap-around. Every match gets a light theme-token ring and the active match a stronger double ring; jumping keeps the user's zoom, scrolls the match to the focus anchor, and auto-expands collapsed ancestors so hits inside folded subtrees are actually revealed. Search is pure view state (no markdown writes, no revision changes), reconciles on stable node ids after an AI re-render, and resets on document switch; the ⌘/Ctrl+F interception only fires while the mindmap canvas is active and never while the caret sits in another text entry.
10
+
11
+ - Canvas focus experience: clicking a node now animates the zoom/scroll transition (≤250 ms, eased) and caps each click's zoom change at ×2/÷2, so focusing into a huge map drills down progressively instead of jumping 4× in one step. The transition interpolates the node's viewport anchor from its clicked position to the left-quarter focus point (no first-frame jump), and animation frames are written directly to the canvas DOM layer without re-rendering the tree per frame. Any new interaction (drag, zoom buttons, another click) interrupts the animation instantly, and the animation self-disables for the session once the resize-observer circuit breaker trips, falling back to the previous instant behavior. When an AI edit pushes the selected node fully out of view, the canvas performs a minimal scroll to bring it back to the edge without touching the user's chosen zoom.
12
+ - Copy as markdown: a 复制全文 button now sits left of 导出图片 in both the sidebar toolbar and the standalone panel header. One click copies the current mindmap's raw markdown source to the system clipboard via the existing `copyPlainText` helper (Clipboard API with a textarea fallback) — the document state's `doc.content` is used directly instead of re-serializing the tree, so headings, nested lists, tables, and the original whitespace round-trip losslessly. Success briefly switches the button label to 已复制 ✓; failures surface in the shared export error slot. The node context-menu 复制全文 (single-node text) is unchanged.
13
+ - Narrow panels (sidebar mode, viewport under 400px) now fit the mindmap by height instead of width; the overflowing part is reachable by panning, which keeps text readable in the 280px-minimum sidebar. The canvas scroller also reserves a stable scrollbar gutter (`scrollbar-gutter: stable`), so the fit ratio no longer oscillates as scrollbars appear and disappear; hosts without the property degrade to the previous behavior.
9
14
  - Read-only document opening now renders a clicked Markdown file before asking the AI to take over editing. `mindmap_create` accepts an optional relative directory, and read/write results carry a SHA-256 revision so stale `mindmap_update` calls can be rejected instead of overwriting newer edits.
10
15
  - Standalone panel width now remains usable on narrow viewports by clamping the initial, saved, resized, and settings-derived widths together.
11
16
  - Write approval now supports `per-operation`, `session` (default), and `off` for ordinary writes. Session mode reuses a successful approval per document, while renames, empty-content deletions, and broad rewrites stay gated; the settings page exposes the policy and the current mindmap workspace shows and revokes the current-session grant.
package/README.md CHANGED
@@ -23,9 +23,11 @@ A DeepSeek Harness plugin that turns a plain Markdown file into a live mindmap.
23
23
  - **Single-mindmap mode** — two tabs only: the tree/list tab and 脑图 (the current mindmap); opening another `.md` replaces the previous one.
24
24
  - **"What you see is what the AI edits"** — when the visible mindmap differs from the AI's working document, the panel automatically asks the AI to open it, keeping the chat focus in sync.
25
25
  - **MarkGrove-style mapping** — heading hierarchy, nested lists (empty items become placeholder nodes), code blocks as leaf nodes, paragraphs promoted to their own nodes (019 block concept), stable structural IDs, and orthogonal connector lines between nodes.
26
- - **Centered canvas with zoom and pan** — the mindmap opens centered in the canvas (scrollable without edge clipping when larger); a floating zoom bar at the canvas top-right (zoom out / percent / zoom in / fit) applies auto fit-to-view on open (small maps stay at 100%), steps through 25%–300% with a stable view center, and keeps re-fitting as the AI edits — until you zoom manually. Click any node to zoom in on it and its whole subtree, with the node pinned at the left-center of the canvas. The canvas also pans by drag: the **middle button** anywhere (even over a node), the **left button on blank canvas** (the Mac trackpad「click and drag」path), or **Space + left button** when the drag must start on a card. Panning works in both directions even when content does not overflow; content follows the pointer 1:1, blank space shows a grab hand, and a 4px threshold separates drag from click — so clicking blank space still clears the selection and clicking a node still focuses it, while a real drag never wipes the selection ring.
26
+ - **Centered canvas with zoom and pan** — the mindmap opens centered in the canvas (scrollable without edge clipping when larger); a floating zoom bar at the canvas top-right (zoom out / percent / zoom in / fit) applies auto fit-to-view on open (small maps stay at 100%), steps through 25%–300% with a stable view center, and keeps re-fitting as the AI edits — until you zoom manually. Click any node to zoom in on it and its whole subtree, with the node pinned at the left-center of the canvas. The focus transition glides the node from its clicked position to the left-quarter anchor with no first-frame jump, animates the zoom over ≤250 ms (capped at ×2/÷2 per click, so a huge map drills down progressively instead of jumping 4× in one step), and writes frames directly to the canvas DOM layer without re-rendering the tree per frame; any new interaction interrupts it instantly. When an AI edit pushes the selected node fully out of view, the canvas performs a minimal scroll to bring it back to the edge without touching your chosen zoom. Narrow panels (sidebar mode) fit by height instead of width — the overflowing part is reachable by panning — and the scrollbar gutter is reserved, so the fit ratio no longer oscillates as scrollbars appear. The canvas also pans by drag: the **middle button** anywhere (even over a node), the **left button on blank canvas** (the Mac trackpad「click and drag」path), or **Space + left button** when the drag must start on a card. Panning works in both directions even when content does not overflow; content follows the pointer 1:1, blank space shows a grab hand, and a 4px threshold separates drag from click — so clicking blank space still clears the selection and clicking a node still focuses it, while a real drag never wipes the selection ring.
27
27
  - **Collapsible subtrees** — every node with children carries a small toggle on its connector: collapsing hides the whole subtree and reports how many nodes are hidden, so large maps stay navigable. It is view state only — the markdown file is untouched, image export still covers the full subtree, and switching documents expands everything again.
28
28
  - **PNG export** — one click on 导出图片 exports the current mindmap.
29
+ - **Copy as markdown** — one click on 复制全文 (left of 导出图片) copies the current mindmap's raw markdown source to the system clipboard, so pasting into markdown-aware editors restores headings, nested lists, and tables, while plain-text targets keep the literal `#`/`-` source. The button shows 已复制 ✓ for about two seconds on success; failures reuse the export error slot.
30
+ - **Node search and quick navigation** — search the current mindmap by text (⌘/Ctrl+F, or the 🔍 in the zoom bar), jump through matches with Enter / ↑ ↓ (wrap-around), and automatically reveal matches inside collapsed subtrees. Jumping keeps your zoom and only scrolls; search is view-only, so the markdown never changes.
29
31
  - **Safety** — write approval defaults to “once per session/document”: after the first confirmation, ordinary `mindmap_update` calls for that document in the same session do not interrupt the flow. The settings page also offers “every write” and “disable ordinary confirmations”. Renames, deletes, and broad rewrites still require a separate confirmation; the current workspace shows and can revoke the current-session grant. Trusted automation can explicitly set `requireApproval: false` to skip ordinary confirmations; high-risk writes remain gated. The client has **no write path** to the filesystem — every edit goes through the AI tools.
30
32
 
31
33
  Inside Better Sidebar, the mindmap list uses the host's 14px body typography. Markdown files carry a compact M badge; folders and other files use 14px outline icons. Other file formats are display-only, without hover feedback, opening, dragging, or context menus; folders remain expandable. Tabs, actions, and hints use the host's 12px typography role. Standalone mode retains its original appearance, and mindmap node typography, zoom, and image export are unchanged.
package/README.zh-CN.md CHANGED
@@ -23,9 +23,11 @@
23
23
  - **单脑图模式**——面板只有树/列表和「脑图」两个 tab,打开新脑图替换旧的那颗。
24
24
  - **「所见即所编」焦点同步**——可见脑图与 AI 工作文档不一致时,面板自动让 AI 打开它,聊天焦点始终跟随你的眼睛。
25
25
  - **MarkGrove 同款映射与连线**——标题层级挂树、列表缩进(空项 = 占位节点)、代码块叶节点、段落升格为独立节点(019 块概念)、稳定结构 ID、节点间直角折线。
26
- - **画布居中、缩放与平移**——脑图打开后居中呈现(超出画布时可滚动、无边缘裁剪);画布右上角浮动缩放条(缩小 / 比例 / 放大 / 适配),打开时自动适配合适比例(小图保持 100%),25%–300% 逐级缩放且视图中心不跳变,AI 编辑后持续自动再适配,直到你手动缩放。点击任意节点即可聚焦:节点滚到画布左侧居中,视图放大到它和整棵子树完整可见(上限 100%)。画布还能拖着走:**中键**随处拖(含节点上)、**空白处左键拖**(Mac 触控板「点按并拖移」)、或 **Space + 左键拖**(必须从节点上起手时);无论内容是否溢出都可横纵双向拖动,内容跟手 1:1,空白处呈抓手光标,4px 阈值把拖与点分开——点空白仍取消选中、点节点仍聚焦,真拖不会误清选中圈。
26
+ - **画布居中、缩放与平移**——脑图打开后居中呈现(超出画布时可滚动、无边缘裁剪);画布右上角浮动缩放条(缩小 / 比例 / 放大 / 适配),打开时自动适配合适比例(小图保持 100%),25%–300% 逐级缩放且视图中心不跳变,AI 编辑后持续自动再适配,直到你手动缩放。点击任意节点即可聚焦:节点从被点位置平滑滑向画布左侧居中锚位(无首帧突跳),视图平滑放大到它和整棵子树完整可见(上限 100%,且单次点击缩放变化不超过 2 倍,巨图上连点渐进深入);动画期间直接操作画布层、不逐帧重绘整棵树,聚焦动画可随时被拖拽、缩放或新点击打断。AI 编辑后若聚焦的节点被顶出视野,画布只做最小滚动把它带回边缘,不打乱你选定的缩放。窄面板(侧栏模式)下自动改按高度适配,宽出的部分靠平移浏览;滚动条槽位常驻,适配比例不再因滚动条出现而反复跳变。画布还能拖着走:**中键**随处拖(含节点上)、**空白处左键拖**(Mac 触控板「点按并拖移」)、或 **Space + 左键拖**(必须从节点上起手时);无论内容是否溢出都可横纵双向拖动,内容跟手 1:1,空白处呈抓手光标,4px 阈值把拖与点分开——点空白仍取消选中、点节点仍聚焦,真拖不会误清选中圈。
27
27
  - **子树折叠**——有子节点的节点在连线起点上带一个小开关:折叠后隐藏整棵子树并提示隐藏了多少节点,超大脑图也能逐层看。折叠只是视图状态,不改 markdown 文件,导出图片仍是完整子树;切换文档自动全部展开。
28
28
  - **PNG 导出**——面板右上角「导出图片」一键导出当前脑图。
29
+ - **复制全文**——「导出图片」左侧一键把当前脑图的 Markdown 原文复制到系统剪贴板:粘到飞书文档 / Notion / Obsidian 等支持 Markdown 的目标会自动还原标题、嵌套列表和表格,粘到纯文本环境则是带 `#`、`-` 符号的源码,零信息损失。成功后按钮短暂显示「已复制 ✓」(约 2 秒),失败复用导出错误的红字提示位。
30
+ - **节点搜索与快速定位**——⌘/Ctrl+F(或缩放条上的 🔍)在当前脑图中搜索文字,Enter / ↑ ↓ 逐个跳转匹配节点(双向环绕),并自动展开被折叠分支中的搜索结果;跳转保留当前缩放、只滚动视图。搜索只改视图状态,绝不动 Markdown。
29
31
  - **安全**——写入确认默认采用“本会话一次”:同一会话内同一脑图首次写入确认后,后续普通 `mindmap_update` 不再重复弹窗;也可切换为“每次确认”或“关闭普通确认”。重命名、删除和大范围重写仍需单独确认;当前脑图工作区会显示并可撤销本会话授权。受信自动化可显式设置 `requireApproval: false` 关闭普通确认,但高风险写入仍需确认。客户端**没有任何写文件通道**,一切编辑都经 AI 工具。
30
32
 
31
33
  内嵌 Better Sidebar 时,脑图列表采用宿主的 14px 正文字体。Markdown 文件显示紧凑的 M 徽标,文件夹与其他文件使用 14px 线框图标;其他格式文件仅展示,没有悬停反馈、打开、拖拽或右键菜单,文件夹仍可展开。标签、操作按钮和提示采用宿主的 12px 字体角色。独立模式保留原有外观;脑图节点的字体层级、缩放和图片导出保持不变。
package/client.js CHANGED
@@ -62,6 +62,9 @@ window.__ModuleLoader__.load({
62
62
  "color.accent.code": { default: "#3b5bdb", fallback: "color.accent.root" },
63
63
  "color.accent.quote": { default: "#5c7cfa", fallback: "color.accent.heading.medium" },
64
64
  "color.state.selected": { default: "var(--dsw-alias-state-business-primary)" },
65
+ // 035 搜索命中:普通命中用品牌色浅色调(tertiary)描边,活动命中共用
66
+ // 选中环主色(primary)——同色系靠层数/宽度分强度,主题换肤自动跟随。
67
+ "color.state.match": { default: "var(--dsw-alias-state-business-tertiary)" },
65
68
  "color.state.hovered": { default: "var(--dsw-alias-interactive-bg-hover)" },
66
69
  "connector.color": { default: "var(--dsw-alias-border-l2)", fallback: "color.border.default" },
67
70
  "connector.width": { default: 1.5 },
@@ -184,6 +187,19 @@ window.__ModuleLoader__.load({
184
187
  if (states.hovered && kind !== "placeholder") {
185
188
  style.boxShadow = resolveToken("effect.shadow.hovered", overrides);
186
189
  }
190
+ // 035 搜索命中态:普通命中 = 浅色调 2px 描边环;活动命中 = 主色描边 +
191
+ // 3px 外扩阴影(双层强调)。outline 不占布局,相邻盒间隙(8px)内放得下。
192
+ // 置于 selected 之前——选中环仍是最高优先级,两者并存时各自可见。
193
+ if (states.matched && !states.matchActive) {
194
+ style.outline = `2px solid ${resolveToken("color.state.match", overrides)}`;
195
+ style.outlineOffset = 1;
196
+ }
197
+ if (states.matchActive) {
198
+ const ring = resolveToken("color.state.selected", overrides);
199
+ style.outline = `2px solid ${ring}`;
200
+ style.outlineOffset = 2;
201
+ style.boxShadow = `0 0 0 3px ${ring}${style.boxShadow && style.boxShadow !== "none" ? `, ${style.boxShadow}` : ""}`;
202
+ }
187
203
  if (states.selected) {
188
204
  const ring = resolveToken("color.state.selected", overrides);
189
205
  style.boxShadow = `0 0 0 2px ${ring}${style.boxShadow && style.boxShadow !== "none" ? `, ${style.boxShadow}` : ""}`;
@@ -1027,6 +1043,79 @@ window.__ModuleLoader__.load({
1027
1043
  }
1028
1044
  //#endregion
1029
1045
 
1046
+ //#region 035 节点搜索:命中计算 / 下标步进 / 命中保持 / 祖先展开(纯函数,经 internals 供测试)
1047
+ /**
1048
+ * 在当前树里搜节点可见文字(topic):大小写不敏感子串匹配,先序遍历
1049
+ * 返回命中节点 id 列表(含根)。空/纯空白查询返回空数组。不搜整个
1050
+ * workspace、不做正则/模糊——第一版只要简单可靠。
1051
+ */
1052
+ function searchTreeMatches(tree, query) {
1053
+ const q = String(query ?? "").trim().toLowerCase();
1054
+ if (!q) return [];
1055
+ const out = [];
1056
+ const walk = (node) => {
1057
+ if (!node) return;
1058
+ if (String(node.topic ?? "").toLowerCase().includes(q)) out.push(node.id);
1059
+ for (const child of node.children ?? []) walk(child);
1060
+ };
1061
+ walk(tree);
1062
+ return out;
1063
+ }
1064
+
1065
+ /**
1066
+ * 下标步进(delta = +1 下一个 / −1 上一个),双向环绕(末尾→开头、
1067
+ * 开头→末尾)。当前下标越界(AI 改写后命中列表已变)先归零再步进;
1068
+ * 无命中返回 −1。
1069
+ */
1070
+ function stepMatchIndex(index, count, delta) {
1071
+ if (!(count > 0)) return -1;
1072
+ const base = Number.isInteger(index) && index >= 0 && index < count ? index : 0;
1073
+ const step = delta >= 0 ? 1 : -1;
1074
+ return (base + step + count) % count;
1075
+ }
1076
+
1077
+ /**
1078
+ * 命中列表重算后的当前项保持(AI 更改 mindmap 后):优先按稳定结构 id
1079
+ * 找回原命中节点;找不到则钳制到最近的有效下标;再不行回落第一个。
1080
+ * 无命中返回 −1。返回值是 matches 里的下标。
1081
+ */
1082
+ function reconcileActiveMatch(prevId, prevIndex, matches) {
1083
+ if (!Array.isArray(matches) || matches.length === 0) return -1;
1084
+ if (prevId != null) {
1085
+ const idx = matches.indexOf(prevId);
1086
+ if (idx >= 0) return idx;
1087
+ }
1088
+ if (Number.isInteger(prevIndex) && prevIndex >= 0 && prevIndex < matches.length) return prevIndex;
1089
+ return 0;
1090
+ }
1091
+
1092
+ /**
1093
+ * 定位命中前展开其祖先路径:把「根 → 目标」链上的折叠 id 全部移出
1094
+ *(不含目标自身——自身折叠只藏子树,盒子仍可见),无关折叠保留。
1095
+ * 无需变化 / 目标不存在时原样返回入参集合(引用不变,React 免重渲染)。
1096
+ */
1097
+ function expandAncestorsFor(collapsed, tree, nodeId) {
1098
+ if (!collapsed || collapsed.size === 0 || !tree || nodeId == null) return collapsed;
1099
+ const ancestors = [];
1100
+ const walk = (node, chain) => {
1101
+ if (!node) return false;
1102
+ if (node.id === nodeId) {
1103
+ for (const id of chain) ancestors.push(id);
1104
+ return true;
1105
+ }
1106
+ for (const child of node.children ?? []) {
1107
+ if (walk(child, chain.concat(node.id))) return true;
1108
+ }
1109
+ return false;
1110
+ };
1111
+ walk(tree, []);
1112
+ if (!ancestors.some((id) => collapsed.has(id))) return collapsed;
1113
+ const next = new Set(collapsed);
1114
+ for (const id of ancestors) next.delete(id);
1115
+ return next;
1116
+ }
1117
+ //#endregion
1118
+
1030
1119
  //#region PNG 导出(SVG 序列化 → canvas → 下载 / 剪贴板)
1031
1120
  // 019 可变盒高布局:盒高按内容估行数(全量换行的导出形态),表格节点加宽;
1032
1121
  // 布局契约不变——叶子自上而下占行、父节点垂直居中于其子块。
@@ -1426,7 +1515,10 @@ window.__ModuleLoader__.load({
1426
1515
  canvasWrap: { flex: "1 1 auto", minHeight: 0, minWidth: 0, position: "relative", display: "flex", flexDirection: "column" },
1427
1516
  // 021 平移:空白处抓手光标(节点盒自带 pointer 覆盖);overscroll
1428
1517
  // contain 让画布滚到边时不把滚动链传给宿主页面(聊天区不跟着动)。
1429
- canvasScroll: { flex: "1 1 auto", minHeight: 0, minWidth: 0, overflow: "auto", cursor: "grab", overscrollBehavior: "contain" },
1518
+ // 033 scrollbar-gutter 常驻滚动条槽位:滚动条出现/消失不再改变
1519
+ // clientWidth——从源头掐掉「适配→滚动条出现→视口变窄→再适配」的
1520
+ // 抖动循环(老保险丝降级为兜底;不支持该属性的宿主优雅退化)。
1521
+ canvasScroll: { flex: "1 1 auto", minHeight: 0, minWidth: 0, overflow: "auto", cursor: "grab", overscrollBehavior: "contain", scrollbarGutter: "stable" },
1430
1522
  // 居中层:内容小则铺满视口(100%),大则撑到内容尺寸(max-content);
1431
1523
  // 子项用 margin:auto——空间充足双向居中,溢出时 margin 归零、从滚动
1432
1524
  // 原点排布(flexbox 溢出居中裁剪的标准解法,无左/上侧裁剪)。
@@ -1439,6 +1531,11 @@ window.__ModuleLoader__.load({
1439
1531
  // 百分比标签:tabular-nums 防数字抖动。
1440
1532
  zoomLabel: { flex: "none", minWidth: "38px", textAlign: "center", fontSize: "11px", lineHeight: "20px", color: "var(--dsw-alias-label-secondary)", fontVariantNumeric: "tabular-nums", userSelect: "none" },
1441
1533
  zoomFitBtn: { border: "none", background: "none", cursor: "pointer", font: "inherit", fontSize: "12px", lineHeight: "20px", height: "22px", padding: "0 8px", borderRadius: "6px", color: "var(--dsw-alias-label-secondary)", flex: "none" },
1534
+ // 035 节点搜索:缩放条同款浮层容器,挂在缩放条正下方(顶 44px),
1535
+ // 全部复用宿主主题变量,亮暗/换肤自动跟随。
1536
+ searchBar: { position: "absolute", top: "44px", right: "12px", zIndex: 5, display: "inline-flex", alignItems: "center", gap: "2px", padding: "3px", borderRadius: "8px", background: "var(--dsw-alias-bg-layer-3)", border: "1px solid var(--dsw-alias-border-l2)", boxShadow: "var(--dsw-shadow-l2)" },
1537
+ searchInput: { flex: "none", width: "108px", height: "22px", boxSizing: "border-box", padding: "0 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "var(--dsw-alias-bg-base)", color: "var(--dsw-alias-label-primary)", font: "inherit", fontSize: "12px", outline: "none" },
1538
+ searchCount: { flex: "none", minWidth: "38px", textAlign: "center", fontSize: "11px", lineHeight: "20px", color: "var(--dsw-alias-label-secondary)", fontVariantNumeric: "tabular-nums", userSelect: "none", whiteSpace: "nowrap" },
1442
1539
  // 027 内嵌头部(sidebar 模式):BS 外层已有 Tab 头部,内嵌只保留一行
1443
1540
  // 紧凑工具栏——脑图列表标签 + 当前脑图标签 + 导出按钮(行尾)。
1444
1541
  // 上下内距比 standalone 的 header(12px 14px 0)更紧凑,行间距更小。
@@ -1785,8 +1882,8 @@ window.__ModuleLoader__.load({
1785
1882
  //#endregion
1786
1883
 
1787
1884
  function NodeBox(props) {
1788
- const { node, theme, revealDelay, selectedId, onCodePanel } = props;
1789
- const [hovered, setHovered] = react.useState(false);
1885
+ const { node, theme, revealDelay, selectedId, onCodePanel, matchIds, activeMatchId } = props;
1886
+ const [hovered, setHovered] = react.useState(false);
1790
1887
  const boxRef = react.useRef(null);
1791
1888
  // 020 长度治理:散文类块(text/md/list/quote)套 6 行截断;clamped = 实测
1792
1889
  // 真的溢出了(scrollHeight>clientHeight),悬停浮层看全文(复用代码浮层)。
@@ -1808,7 +1905,13 @@ window.__ModuleLoader__.load({
1808
1905
  ...resolveNodeStyle(node, {
1809
1906
  colorTheme: theme && theme.colorTheme,
1810
1907
  cardStyle: theme && theme.cardStyle,
1811
- states: { hovered, selected: selectedId === node.id },
1908
+ states: {
1909
+ hovered,
1910
+ selected: selectedId === node.id,
1911
+ // 035 搜索命中:普通命中轻描边,活动命中的命中节点双层强调环。
1912
+ matched: Boolean(matchIds && matchIds.has(node.id)),
1913
+ matchActive: activeMatchId === node.id,
1914
+ },
1812
1915
  }),
1813
1916
  };
1814
1917
  // 020 表格块不参与散文 320px 宽上限:完整网格需要更宽书写面,
@@ -1849,7 +1952,7 @@ window.__ModuleLoader__.load({
1849
1952
 
1850
1953
  /** 左→右递归树:节点盒 + 右侧子节点列 + 连线层(015 支持折线/曲线两种线型)。 */
1851
1954
  function TreeRow(props) {
1852
- const { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse } = props;
1955
+ const { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse, matchIds, activeMatchId } = props;
1853
1956
  // 025 折叠:纯视图态——markdown 资产不变,导出仍取完整子树。
1854
1957
  const hasChildren = Boolean(node.children && node.children.length > 0);
1855
1958
  const isCollapsed = hasChildren && Boolean(collapsed && collapsed.has(node.id));
@@ -1966,7 +2069,7 @@ window.__ModuleLoader__.load({
1966
2069
  e.stopPropagation();
1967
2070
  onNodeContextMenu(e, node);
1968
2071
  } : undefined,
1969
- children: (0, react_jsx_runtime.jsx)(NodeBox, { node, theme, revealDelay, selectedId, onCodePanel }),
2072
+ children: (0, react_jsx_runtime.jsx)(NodeBox, { node, theme, revealDelay, selectedId, onCodePanel, matchIds, activeMatchId }),
1970
2073
  }),
1971
2074
  // 025 折叠开关:坐在盒与子列之间的连线起点上(有子节点才出现)。
1972
2075
  // stopPropagation 保证点它不触发画布的「点节点聚焦 / 点空白取消选中」。
@@ -1991,7 +2094,7 @@ window.__ModuleLoader__.load({
1991
2094
  ref: (el) => {
1992
2095
  childRefs.current[idx] = el;
1993
2096
  },
1994
- children: (0, react_jsx_runtime.jsx)(TreeRow, { node: child, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse }),
2097
+ children: (0, react_jsx_runtime.jsx)(TreeRow, { node: child, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse, matchIds, activeMatchId }),
1995
2098
  }, child.id)) })
1996
2099
  : null,
1997
2100
  ] });
@@ -2001,7 +2104,15 @@ window.__ModuleLoader__.load({
2001
2104
  // 缩放契约:范围 [0.25, 3],每级 ×1.2;适配计算四周留 48px 余量
2002
2105
  //(16px 视觉内距 + 经典滚动条占位,避免「适配→滚动条出现→视口变
2003
2106
  // 窄→再适配」的抖动循环)。
2004
- const ZOOM = { min: 0.25, max: 3, step: 1.2, padding: 48, focusMax: 1 };
2107
+ // 033 focusJump:点击聚焦单次跳变上限(相对当前比例最多 ×2 / ÷2),
2108
+ // 巨图点叶子不再一步怼到 100%,连点渐进 drill。narrowView:视口宽
2109
+ // 低于该值(sidebar 最窄 280px)时改按高度适配——横向适配在窄面板
2110
+ // 永远占主导会把子树压得过小,宽度溢出交给平移(横向本就一等公民)。
2111
+ // animMs:033 平滑过渡时长上限(限长、可中断、熔断后退化瞬时)。
2112
+ const ZOOM = { min: 0.25, max: 3, step: 1.2, padding: 48, focusMax: 1, focusJump: 2, narrowView: 400, animMs: 250 };
2113
+ // 034 聚焦锚位(视口比例):树向右生长,节点压在左侧 1/4 处、
2114
+ // 垂直居中,右侧 3/4 视野铺开子级。动画从点击位置插值到此锚位。
2115
+ const FOCUS_ANCHOR = { x: 0.25, y: 0.5 };
2005
2116
 
2006
2117
  /** 缩放夹取:非有限值/≤0 回退 1,否则夹到 [min, max]。 */
2007
2118
  function clampZoom(value) {
@@ -2018,18 +2129,59 @@ window.__ModuleLoader__.load({
2018
2129
  /** 适配比例:min((view-padding)/tree, 1) 再夹取——小图不放大、巨图夹下限;零/非法尺寸返回 1。 */
2019
2130
  function fitZoom(treeW, treeH, viewW, viewH) {
2020
2131
  if (!(treeW > 0) || !(treeH > 0) || !(viewW > 0) || !(viewH > 0)) return 1;
2132
+ // 033 窄视口(sidebar):按高度适配,宽度溢出靠平移。
2133
+ if (viewW < ZOOM.narrowView) return clampZoom(Math.min((viewH - ZOOM.padding) / treeH, 1));
2021
2134
  return clampZoom(Math.min((viewW - ZOOM.padding) / treeW, (viewH - ZOOM.padding) / treeH, 1));
2022
2135
  }
2023
2136
 
2024
2137
  /**
2025
2138
  * 子树聚焦比例:适配整棵子树(区别于全局适配,允许放大到 focusMax),
2026
2139
  * 叶子/小子树不会怼脸、巨子树夹下限;零/非法尺寸返回 1。
2140
+ * 033 窄视口同 fitZoom:按高度适配(子树行通常宽而扁,窄面板里
2141
+ * 横向适配会把整行压到不可读)。
2027
2142
  */
2028
2143
  function focusZoom(treeW, treeH, viewW, viewH) {
2029
2144
  if (!(treeW > 0) || !(treeH > 0) || !(viewW > 0) || !(viewH > 0)) return 1;
2145
+ if (viewW < ZOOM.narrowView) return clampZoom(Math.min((viewH - ZOOM.padding) / treeH, ZOOM.focusMax));
2030
2146
  return clampZoom(Math.min((viewW - ZOOM.padding) / treeW, (viewH - ZOOM.padding) / treeH, ZOOM.focusMax));
2031
2147
  }
2032
2148
 
2149
+ /**
2150
+ * 033 点击聚焦跳变钳制:目标比例相对当前值单次最多变化 focusJump 倍
2151
+ *(放大 ×2 / 缩小 ÷2),超出则截到边界。放置在调用点而非 focusZoom
2152
+ * 内——focusZoom 保持「无状态适配计算」语义(测试直测),跳变限制
2153
+ * 需要知道当前值,属交互层策略。连续点击逐步逼近,方向不变。
2154
+ */
2155
+ function clampFocusJump(target, current) {
2156
+ const value = clampZoom(target);
2157
+ const base = clampZoom(current);
2158
+ return Math.min(base * ZOOM.focusJump, Math.max(base / ZOOM.focusJump, value));
2159
+ }
2160
+
2161
+ /** 033 项3:按结构 id 找当前树里的节点盒(遍历比对属性值,不做选择器
2162
+ * 拼接——结构 id 虽是数字路径,这里不依赖该假设)。找不到返回 null。 */
2163
+ function findBoxByNodeId(scroller, id) {
2164
+ if (!scroller || typeof scroller.querySelectorAll !== "function") return null;
2165
+ const boxes = scroller.querySelectorAll("[data-mindmap-node-id]");
2166
+ for (const el of boxes) {
2167
+ if (el.getAttribute("data-mindmap-node-id") === id) return el;
2168
+ }
2169
+ return null;
2170
+ }
2171
+
2172
+ /** 033 项3:把完全离开视口的盒子拉回最近边的最小滚动位移(视口坐标
2173
+ * 系,正 = 向右/下滚)。部分可见或在内返回 0——不打扰用户视角。
2174
+ * margin = 拉回后与视口边保留的呼吸余量。 */
2175
+ function edgePullOffsets(box, view, margin) {
2176
+ let dx = 0;
2177
+ let dy = 0;
2178
+ if (box.right < view.left) dx = box.left - (view.left + margin);
2179
+ else if (box.left > view.right) dx = box.right - (view.right - margin);
2180
+ if (box.bottom < view.top) dy = box.top - (view.top + margin);
2181
+ else if (box.top > view.bottom) dy = box.bottom - (view.bottom - margin);
2182
+ return { x: dx, y: dy };
2183
+ }
2184
+
2033
2185
  //#region 021 画布平移:拖拽手势(中键 / 空白处左键 / 空格+左键)
2034
2186
  // 平移契约(三条手指路径,覆盖鼠标与 Mac 触摸板):
2035
2187
  // 中键拖动 —— 画布惯例,任何位置都拖(压节点上也拖)
@@ -2127,7 +2279,7 @@ window.__ModuleLoader__.load({
2127
2279
  // 016 熔断器:观察器触发的适配时间戳。1.5s 内第 5 次 → 判定
2128
2280
  // 反馈循环,自动停手(保险丝,任何未知循环都最多闪几下)。
2129
2281
  const fitStampRef = react.useRef([]);
2130
- const [zoom, setZoomState] = react.useState(1);
2282
+ const [zoom, setZoomState] = react.useState(1);
2131
2283
  const [hover, setHover] = react.useState(null);
2132
2284
  // 017 节点右键菜单:{x, y, node};null = 关闭。busy = "copy" |
2133
2285
  // "export" 表示对应动作进行中(两项都禁用),error 展示失败原因。
@@ -2140,6 +2292,24 @@ window.__ModuleLoader__.load({
2140
2292
  // 025 折叠子树:纯视图态(不写回 markdown,导出仍取完整子树)。
2141
2293
  // 切换文档时全部展开;AI 改写后清掉已消失节点的折叠标记。
2142
2294
  const [collapsed, setCollapsed] = react.useState(() => new Set());
2295
+ // 035 节点搜索:开箱态 / 查询词 / 当前命中下标 / 待定位 id。
2296
+ // 命中列表由 useMemo 按 [node, searchQuery] 现算——O(n) 子串
2297
+ // 匹配(上千节点也是微秒级),不重 parse、不重建 DOM。
2298
+ const [searchOpen, setSearchOpen] = react.useState(false);
2299
+ const [searchQuery, setSearchQuery] = react.useState("");
2300
+ const [searchIndex, setSearchIndex] = react.useState(-1);
2301
+ const [searchReveal, setSearchReveal] = react.useState(null);
2302
+ const searchInputRef = react.useRef(null);
2303
+ // 当前命中的稳定结构 id:AI 改写树后按它找回原命中节点。
2304
+ const searchActiveIdRef = react.useRef(null);
2305
+ const searchMatches = react.useMemo(() => searchTreeMatches(node, searchQuery), [node, searchQuery]);
2306
+ const searchMatchIds = searchMatches.length > 0 ? new Set(searchMatches) : null;
2307
+ // 渲染期先钳一次:AI 改写后命中列表变短,[node] 协调 effect
2308
+ // 生效前的那一帧若沿用旧下标会显示「4 / 3」这类越界计数。
2309
+ const searchIndexSafe = searchMatches.length > 0
2310
+ ? (searchIndex >= 0 && searchIndex < searchMatches.length ? searchIndex : 0)
2311
+ : -1;
2312
+ const searchActiveId = searchIndexSafe >= 0 ? searchMatches[searchIndexSafe] : null;
2143
2313
  // 019 代码块悬停浮层:{node, anchor};null = 关闭。延迟关闭(150ms
2144
2314
  // 宽限)让鼠标能从节点盒移到面板上滚动全文,不闪灭。
2145
2315
  const [codePanel, setCodePanel] = react.useState(null);
@@ -2171,6 +2341,94 @@ window.__ModuleLoader__.load({
2171
2341
  // 021 指针是否悬在画布上(空格键要不要拦默认行为的门控;纯
2172
2342
  // 读取,不参与渲染)。
2173
2343
  const hoverRef = react.useRef(false);
2344
+ // 033 平滑过渡:在飞的 zoom 动画句柄 { id, from, to, start };
2345
+ // animDisabled = 熔断器触发过(本轮 fitKey 内动画退化为瞬时,
2346
+ // 切文档/点适配时复位)。
2347
+ // 034 动画期间绕过 React(根因二:每帧 setZoomState 整树重渲染,
2348
+ // 大图掉帧):每帧直写内容层 style.zoom + 滚动校正,不进 state;
2349
+ // 结束帧一次性 setZoomState(target) 同步 UI(百分比/边界按钮/
2350
+ // committedZoomRef)。测量基准不受影响——动画只在点击后飞,
2351
+ // 此时 userZoomedRef 已置位,ResizeObserver 不会再调 applyFit。
2352
+ const zoomAnimRef = react.useRef(null);
2353
+ const animDisabledRef = react.useRef(false);
2354
+
2355
+ // 034 仅停帧:取消 rAF + 同步 committed/state,保留 focusRef
2356
+ //(animateZoomTo 替换旧动画时用——调用方随后会覆盖 focusRef,
2357
+ // 不能让它把新聚焦也清掉)。中断时 DOM 已被直写到中间值——
2358
+ // 立即把 committedZoomRef 对齐该值(applyFit 的自然尺寸测量基准
2359
+ // 必须等于 DOM 实际 zoom),并用 setZoomState 把 React state
2360
+ // 兜底同步(防后续 re-render 把 style.zoom 打回动画前的旧值)。
2361
+ function stopZoomAnimFrames() {
2362
+ const anim = zoomAnimRef.current;
2363
+ if (!anim) return;
2364
+ zoomAnimRef.current = null;
2365
+ if (typeof cancelAnimationFrame === "function") cancelAnimationFrame(anim.id);
2366
+ committedZoomRef.current = zoomRef.current;
2367
+ setZoomState(zoomRef.current);
2368
+ }
2369
+
2370
+ // 033 截停在飞动画(任何新交互都先调):停帧 + 顺手清掉
2371
+ // focusRef(否则下一次 zoom 提交会被过期聚焦劫持定位)。
2372
+ function cancelZoomAnim() {
2373
+ if (!zoomAnimRef.current) return;
2374
+ stopZoomAnimFrames();
2375
+ focusRef.current = null;
2376
+ }
2377
+
2378
+ // 034 期望锚位插值:点击位置 → FOCUS_ANCHOR,与 zoom 同一
2379
+ // eased 进度——第一帧期望位置 = 点击时位置(零瞬移,根因一),
2380
+ // 节点被「牵着」滑向锚位。
2381
+ function lerpFocusAnchor(start, k) {
2382
+ return {
2383
+ x: start.x + (FOCUS_ANCHOR.x - start.x) * k,
2384
+ y: start.y + (FOCUS_ANCHOR.y - start.y) * k,
2385
+ };
2386
+ }
2387
+
2388
+ // 033/034 平滑 zoom:from → to,限长 animMs、easeOutQuad,并行
2389
+ // 上限 1(新动画先截停旧动画)。每帧:直写 style.zoom、同步
2390
+ // zoomRef、按插值锚位滚动校正(applyFocusAnchor);结束帧精确落
2391
+ // 在 to 并 setZoomState 触发最后一次 [zoom] effect(positionFocus
2392
+ // 消费 focusRef、全量锚位终校——此刻 ≈ no-op)。禁用/无 rAF 环
2393
+ // 境瞬时应用,行为与 033 之前完全一致。
2394
+ function animateZoomTo(to) {
2395
+ stopZoomAnimFrames();
2396
+ const target = clampZoom(to);
2397
+ const from = zoomRef.current;
2398
+ if (from === target) return;
2399
+ const scroller = scrollRef.current;
2400
+ const content = contentRef.current;
2401
+ const canAnimate = animDisabledRef.current !== true
2402
+ && scroller
2403
+ && content
2404
+ && typeof requestAnimationFrame === "function";
2405
+ if (!canAnimate) {
2406
+ zoomRef.current = target;
2407
+ setZoomState(target);
2408
+ return;
2409
+ }
2410
+ const anim = { id: 0, from, to: target, start: Date.now() };
2411
+ zoomAnimRef.current = anim;
2412
+ const frame = () => {
2413
+ if (zoomAnimRef.current !== anim) return; // 已被截停/替换
2414
+ const t = Math.min(1, (Date.now() - anim.start) / ZOOM.animMs);
2415
+ const eased = 1 - (1 - t) * (1 - t);
2416
+ const value = t >= 1 ? target : from + (target - from) * eased;
2417
+ zoomRef.current = value;
2418
+ content.style.zoom = value; // 034:直写 DOM,绕过 React
2419
+ const focus = focusRef.current;
2420
+ if (focus && focus.boxEl && focus.boxEl.isConnected) {
2421
+ applyFocusAnchor(focus.boxEl, lerpFocusAnchor(focus.startAnchor, eased));
2422
+ }
2423
+ if (t >= 1) {
2424
+ zoomAnimRef.current = null;
2425
+ setZoomState(target);
2426
+ return;
2427
+ }
2428
+ anim.id = requestAnimationFrame(frame);
2429
+ };
2430
+ anim.id = requestAnimationFrame(frame);
2431
+ }
2174
2432
 
2175
2433
  // 测量并适配:自然尺寸 = getBoundingClientRect ÷ 已提交 zoom(与
2176
2434
  // DOM 实际状态严格同步,无竞态)。值不变不动 state(bail-out),
@@ -2179,6 +2437,9 @@ window.__ModuleLoader__.load({
2179
2437
  const scroller = scrollRef.current;
2180
2438
  const content = contentRef.current;
2181
2439
  if (!scroller || !content) return;
2440
+ // 033:适配前截停在飞动画(观察器/适配按钮不能被旧动画
2441
+ // 的后续帧反向覆盖)。
2442
+ cancelZoomAnim();
2182
2443
  resetPanOffset();
2183
2444
  const rect = content.getBoundingClientRect();
2184
2445
  if (!(rect.width > 0) || !(rect.height > 0)) return;
@@ -2198,14 +2459,27 @@ window.__ModuleLoader__.load({
2198
2459
  }
2199
2460
 
2200
2461
  // 挂载 / 文档切换:清除「用户已手动缩放」标记与熔断计数,
2201
- // 布局稳定后(rAF)适配一次。
2462
+ // 布局稳定后(rAF)适配一次。033:同时复位动画禁用位与
2463
+ // 选中态(新文档不该继承旧文档的选中环——结构 id 跨文档
2464
+ // 可能撞名,会让保视野逻辑锚错节点);清理时截停在飞动画。
2202
2465
  react.useLayoutEffect(() => {
2203
2466
  userZoomedRef.current = false;
2204
2467
  lastNaturalRef.current = null;
2205
2468
  fitStampRef.current = [];
2469
+ animDisabledRef.current = false;
2470
+ setSelectedId(null);
2206
2471
  setCollapsed((prev) => (prev.size > 0 ? new Set() : prev));
2472
+ // 035:切文档重置搜索——上一张图的 query/命中不污染新图。
2473
+ setSearchOpen(false);
2474
+ setSearchQuery("");
2475
+ setSearchIndex(-1);
2476
+ setSearchReveal(null);
2477
+ searchActiveIdRef.current = null;
2207
2478
  const id = requestAnimationFrame(applyFit);
2208
- return () => cancelAnimationFrame(id);
2479
+ return () => {
2480
+ cancelAnimationFrame(id);
2481
+ cancelZoomAnim();
2482
+ };
2209
2483
  }, [fitKey]);
2210
2484
 
2211
2485
  // 内容 / 画布尺寸变化(AI 编辑、面板拖宽)→ 未手动缩放则再适配。
@@ -2234,6 +2508,9 @@ window.__ModuleLoader__.load({
2234
2508
  const stamps = fitStampRef.current = fitStampRef.current.filter((t) => now - t < 1500);
2235
2509
  if (stamps.length >= 5) {
2236
2510
  userZoomedRef.current = true;
2511
+ // 033:熔断判定成立 → 本轮 fitKey 内动画也停用(反馈
2512
+ // 循环环境里再引入中间态提交只会火上浇油)。
2513
+ animDisabledRef.current = true;
2237
2514
  return;
2238
2515
  }
2239
2516
  stamps.push(now);
@@ -2297,6 +2574,9 @@ window.__ModuleLoader__.load({
2297
2574
  // 否则上轮手势留下的 true 会粘到下一次点击上——例:拖完画布后再
2298
2575
  // 触摸点按(touch 路径不启动平移就早退了),那次点击会被白吞一次。
2299
2576
  suppressClickRef.current = false;
2577
+ // 033:平移起手即截停缩放动画——聚焦动画每帧把节点钉回锚位,
2578
+ // 会和用户拖拽的方向对着干。
2579
+ cancelZoomAnim();
2300
2580
  const scroller = scrollRef.current;
2301
2581
  if (!scroller || panRef.current) return;
2302
2582
  const target = e.target;
@@ -2385,7 +2665,11 @@ window.__ModuleLoader__.load({
2385
2665
  // DOM 已提交到该 zoom,测量换算基准同步(applyFit 依赖)。
2386
2666
  committedZoomRef.current = zoom;
2387
2667
  if (focusRef.current) {
2388
- positionFocus();
2668
+ // 034:动画在飞时既不定位也不消费——帧回调自己管锚位插值;
2669
+ // 动画中再点击时,cancel 的 setZoomState 也会路过这里,
2670
+ // 提前消费/全量锚位都会造成闪跳。瞬时聚焦与动画结束帧
2671
+ //(anim 先清再 setState)才做全量终校(结束时 ≈ no-op)。
2672
+ if (!zoomAnimRef.current) positionFocus();
2389
2673
  return;
2390
2674
  }
2391
2675
  const scroller = scrollRef.current;
@@ -2400,11 +2684,13 @@ window.__ModuleLoader__.load({
2400
2684
 
2401
2685
  function zoomIn() {
2402
2686
  userZoomedRef.current = true;
2687
+ cancelZoomAnim();
2403
2688
  setZoom(stepZoom(zoomRef.current, 1), true);
2404
2689
  }
2405
2690
 
2406
2691
  function zoomOut() {
2407
2692
  userZoomedRef.current = true;
2693
+ cancelZoomAnim();
2408
2694
  setZoom(stepZoom(zoomRef.current, -1), true);
2409
2695
  }
2410
2696
 
@@ -2418,6 +2704,8 @@ window.__ModuleLoader__.load({
2418
2704
  // 左侧锚点让子级铺满右侧视野),缩放比例取 focusZoom(整棵子树适配、
2419
2705
  // 上限 focusMax)。事件委托:closest 找节点盒与所在子树 row,无需给
2420
2706
  // 递归 TreeRow 传回调。聚焦视为用户手动缩放(停自动再适配)。
2707
+ // 033:目标比例经 clampFocusJump 单次最多 ×2/÷2(巨图点叶子不再一步
2708
+ // 怼到 100%,连点渐进 drill);zoom 变化经 animateZoomTo 平滑过渡。
2421
2709
  function onCanvasClick(e) {
2422
2710
  // 021:刚拖过画布(平移)的这次 click 不是点击,直接吞掉——
2423
2711
  // 否则每次平移松手都会顺手把选中环清掉。
@@ -2441,34 +2729,173 @@ window.__ModuleLoader__.load({
2441
2729
  if (!scroller) return;
2442
2730
  const current = zoomRef.current;
2443
2731
  const rowRect = rowEl.getBoundingClientRect();
2444
- const focus = focusZoom(rowRect.width / current, rowRect.height / current, scroller.clientWidth, scroller.clientHeight);
2732
+ // 033 跳变钳制:相对当前比例单次最多 ×2 / ÷2。
2733
+ const focus = clampFocusJump(
2734
+ focusZoom(rowRect.width / current, rowRect.height / current, scroller.clientWidth, scroller.clientHeight),
2735
+ current,
2736
+ );
2737
+ // 034:记录点击时节点中心的视口比例位置——动画锚位插值起点
2738
+ //(第一帧期望位置 = 点击时位置,消除首帧滚动瞬移)。
2739
+ const boxRect = boxEl.getBoundingClientRect();
2740
+ const scrollerRect = scroller.getBoundingClientRect();
2741
+ const startAnchor = {
2742
+ x: (boxRect.left + boxRect.width / 2 - scrollerRect.left) / scroller.clientWidth,
2743
+ y: (boxRect.top + boxRect.height / 2 - scrollerRect.top) / scroller.clientHeight,
2744
+ };
2445
2745
  userZoomedRef.current = true;
2446
- focusRef.current = { boxEl };
2447
2746
  if (focus !== current) {
2448
2747
  anchorRef.current = null;
2449
- zoomRef.current = focus;
2450
- setZoomState(focus);
2748
+ // 034:先完整截停旧动画(清过期 focusRef + 同步中间值),
2749
+ // 再登记本次聚焦——顺序不能反(cancel 会清 focusRef)。
2750
+ cancelZoomAnim();
2751
+ focusRef.current = { boxEl, startAnchor };
2752
+ animateZoomTo(focus);
2451
2753
  } else {
2754
+ cancelZoomAnim();
2755
+ focusRef.current = { boxEl, startAnchor };
2452
2756
  positionFocus();
2453
2757
  }
2454
2758
  }
2455
2759
 
2456
- // 聚焦定位:DOM 更新后量节点盒当前位置,滚动增量 = 当前位置 − 期望位置
2457
- //(scroll 增量与视口位移 1:1,浏览器自动钳制滚动范围;比例不变时同步调用)。
2458
- function positionFocus() {
2459
- const focus = focusRef.current;
2460
- focusRef.current = null;
2760
+ // 034 锚位应用:把节点盒中心滚到指定视口比例锚位(滚动增量与视口
2761
+ // 位移 1:1,浏览器自动钳制滚动范围)。positionFocus(固定锚位)与
2762
+ // 聚焦动画帧(插值锚位)共用。
2763
+ function applyFocusAnchor(boxEl, anchor) {
2461
2764
  const scroller = scrollRef.current;
2462
- if (!scroller || !focus || !focus.boxEl || !focus.boxEl.isConnected) return;
2765
+ if (!scroller || !boxEl || !boxEl.isConnected) return;
2463
2766
  resetPanOffset();
2464
- const boxRect = focus.boxEl.getBoundingClientRect();
2767
+ const boxRect = boxEl.getBoundingClientRect();
2465
2768
  const scrollerRect = scroller.getBoundingClientRect();
2466
2769
  const curX = boxRect.left + boxRect.width / 2 - scrollerRect.left;
2467
2770
  const curY = boxRect.top + boxRect.height / 2 - scrollerRect.top;
2468
- scroller.scrollLeft += curX - scroller.clientWidth * 0.25;
2469
- scroller.scrollTop += curY - scroller.clientHeight / 2;
2771
+ scroller.scrollLeft += curX - scroller.clientWidth * anchor.x;
2772
+ scroller.scrollTop += curY - scroller.clientHeight * anchor.y;
2773
+ }
2774
+
2775
+ // 聚焦定位:DOM 更新后把节点盒滚到 FOCUS_ANCHOR(全量校正)。
2776
+ // 034:consume = false 时保留 focusRef——瞬时聚焦路径不再逐帧,仅
2777
+ // 动画结束帧(zoomAnimRef 已清空)与同步调用消费。
2778
+ function positionFocus(consume = true) {
2779
+ const focus = focusRef.current;
2780
+ if (!focus || !focus.boxEl || !focus.boxEl.isConnected) {
2781
+ focusRef.current = null;
2782
+ return;
2783
+ }
2784
+ if (consume) focusRef.current = null;
2785
+ applyFocusAnchor(focus.boxEl, FOCUS_ANCHOR);
2470
2786
  }
2471
2787
 
2788
+ //#region 035 节点搜索:输入即搜 + 匹配间跳转 + 自动展开祖先 + 滚动定位
2789
+ // 打开搜索(Cmd/Ctrl+F 或缩放条 🔍)。关闭 = 清 query/命中/高亮;
2790
+ // 为定位展开的祖先保持展开——用户下一步多半还要看上下文。
2791
+ function openSearch() {
2792
+ setSearchOpen(true);
2793
+ }
2794
+ function closeSearch() {
2795
+ setSearchOpen(false);
2796
+ setSearchQuery("");
2797
+ setSearchIndex(-1);
2798
+ searchActiveIdRef.current = null;
2799
+ }
2800
+
2801
+ // 输入即搜:每次按键 O(n) 现算命中并跳到第一个(VS Code find 同款手感)。
2802
+ // 直接调纯函数拿新查询的结果(本渲染的 memo 还是旧 query 的)。
2803
+ function onQueryChange(e) {
2804
+ const query = e && e.target ? e.target.value : "";
2805
+ const matches = searchTreeMatches(node, query);
2806
+ setSearchQuery(query);
2807
+ if (matches.length > 0) {
2808
+ setSearchIndex(0);
2809
+ searchActiveIdRef.current = matches[0];
2810
+ revealSearchMatch(matches[0]);
2811
+ } else {
2812
+ setSearchIndex(-1);
2813
+ searchActiveIdRef.current = null;
2814
+ }
2815
+ }
2816
+
2817
+ // 上一个/下一个:双向环绕(末尾→开头、开头→末尾)。
2818
+ function stepSearch(delta) {
2819
+ if (searchMatches.length === 0) return;
2820
+ const next = stepMatchIndex(searchIndex, searchMatches.length, delta);
2821
+ setSearchIndex(next);
2822
+ searchActiveIdRef.current = searchMatches[next];
2823
+ revealSearchMatch(searchMatches[next]);
2824
+ }
2825
+
2826
+ // 定位一个命中:先展开它的祖先路径(折叠分支里的结果也真正可见),
2827
+ // 再登记待定位 id——[searchReveal] layout effect 在 DOM 提交后按结构
2828
+ // id 找盒、滚到聚焦锚位。不动 zoom(保留用户当前缩放,只改必要滚动)。
2829
+ function revealSearchMatch(id) {
2830
+ setCollapsed((prev) => expandAncestorsFor(prev, node, id));
2831
+ setSearchReveal(id);
2832
+ }
2833
+
2834
+ // 搜索定位提交后的滚动:与展开祖先同批 setState,此 effect 运行时
2835
+ // 展开的子树已挂载。搜索定位 = 显式视角意图:与点击聚焦一样停自动
2836
+ // 再适配,并截停在飞聚焦动画(其帧回调会把节点钉回旧锚位对着干)。
2837
+ react.useLayoutEffect(() => {
2838
+ if (!searchReveal) return;
2839
+ const scroller = scrollRef.current;
2840
+ const boxEl = scroller ? findBoxByNodeId(scroller, searchReveal) : null;
2841
+ if (boxEl) {
2842
+ userZoomedRef.current = true;
2843
+ cancelZoomAnim();
2844
+ applyFocusAnchor(boxEl, FOCUS_ANCHOR);
2845
+ }
2846
+ setSearchReveal(null);
2847
+ }, [searchReveal]);
2848
+
2849
+ // 开箱聚焦输入框(全选既有词——当前实现关闭即清空,习惯上仍全选)。
2850
+ react.useLayoutEffect(() => {
2851
+ if (!searchOpen) return;
2852
+ const input = searchInputRef.current;
2853
+ if (!input || typeof input.focus !== "function") return;
2854
+ input.focus();
2855
+ if (typeof input.select === "function") input.select();
2856
+ }, [searchOpen]);
2857
+
2858
+ // AI 更新后重算命中:保留 query;优先按稳定 id 找回原命中节点,
2859
+ // 找不到回落最近有效下标/第一个;无命中显示 0。只调下标不滚动——
2860
+ // AI 每次编辑都拽走视口会与「视角归用户」冲突,滚动只由导航触发。
2861
+ react.useEffect(() => {
2862
+ if (searchQuery === "") return;
2863
+ const next = reconcileActiveMatch(searchActiveIdRef.current, searchIndex, searchMatches);
2864
+ if (next !== searchIndex) setSearchIndex(next);
2865
+ if (next >= 0) searchActiveIdRef.current = searchMatches[next];
2866
+ }, [node]);
2867
+
2868
+ // Cmd/Ctrl+F 打开搜索。拦截范围 = 画布挂载(脑图 tab 可见且激活;
2869
+ // 面板收起/切目录树即卸载,无僵尸监听)且目标不是别人的文本输入
2870
+ //(聊天框里的 Cmd+F 留给宿主);已有人处理过(defaultPrevented)不抢。
2871
+ react.useEffect(() => {
2872
+ const onKeyDown = (e) => {
2873
+ if (e.defaultPrevented || e.altKey) return;
2874
+ if (!(e.metaKey || e.ctrlKey)) return;
2875
+ if (!e.key || e.key.toLowerCase() !== "f") return;
2876
+ if (isTextEntry(e.target) && e.target !== searchInputRef.current) return;
2877
+ e.preventDefault();
2878
+ setSearchOpen(true);
2879
+ };
2880
+ window.addEventListener("keydown", onKeyDown);
2881
+ return () => window.removeEventListener("keydown", onKeyDown);
2882
+ }, []);
2883
+
2884
+ // Escape 关闭搜索:仅搜索打开期间注册(closeSearch 只调常参 setter,
2885
+ // 闭包过期无害);目标在他人输入框时不抢 Escape。
2886
+ react.useEffect(() => {
2887
+ if (!searchOpen) return;
2888
+ const onKeyDown = (e) => {
2889
+ if (e.key !== "Escape" || e.defaultPrevented) return;
2890
+ if (isTextEntry(e.target) && e.target !== searchInputRef.current) return;
2891
+ e.preventDefault();
2892
+ closeSearch();
2893
+ };
2894
+ window.addEventListener("keydown", onKeyDown);
2895
+ return () => window.removeEventListener("keydown", onKeyDown);
2896
+ }, [searchOpen]);
2897
+ //#endregion
2898
+
2472
2899
  // 017 右键菜单开合:点其它地方/失焦/改窗口即关闭(目录树菜单同款);
2473
2900
  // 点菜单内部(复制/导出按钮)不关——菜单里要展示「复制中…」与失败
2474
2901
  // 原因。节点右键经 stopPropagation 不会触发这里的 contextmenu 关闭,
@@ -2497,6 +2924,29 @@ window.__ModuleLoader__.load({
2497
2924
  setCodePanel(null);
2498
2925
  // 025:树重解析后丢弃已消失节点的折叠标记(无变化时保持原引用)。
2499
2926
  setCollapsed((prev) => pruneCollapsed(prev, node));
2927
+ // 033 项3:AI 编辑后保住选中节点在视野内。仅在用户已定视角
2928
+ //(userZoomedRef,自动再适配已停)且选中节点**完全**离开视口时,
2929
+ // 以最小滚动量把它带回最近的边(部分可见不打扰)。只动 scroll:
2930
+ // 不改缩放、不碰 userZoomedRef/熔断器(滚动不触发 ResizeObserver
2931
+ // 的内容尺寸变化),「面板跟随 AI 实时变化」与「视角归用户」两个
2932
+ // 承诺同时成立。id 失效(节点被删/重写)→ 查不到盒,自然跳过。
2933
+ if (userZoomedRef.current && selectedId) {
2934
+ const scroller = scrollRef.current;
2935
+ const boxEl = scroller && typeof scroller.querySelectorAll === "function"
2936
+ ? findBoxByNodeId(scroller, selectedId)
2937
+ : null;
2938
+ if (boxEl && typeof boxEl.getBoundingClientRect === "function") {
2939
+ const box = boxEl.getBoundingClientRect();
2940
+ const view = scroller.getBoundingClientRect();
2941
+ const MARGIN = 24;
2942
+ const pull = edgePullOffsets(box, view, MARGIN);
2943
+ if (pull.x !== 0 || pull.y !== 0) {
2944
+ resetPanOffset();
2945
+ scroller.scrollLeft += pull.x;
2946
+ scroller.scrollTop += pull.y;
2947
+ }
2948
+ }
2949
+ }
2500
2950
  }, [node]);
2501
2951
 
2502
2952
  function toggleCollapse(id) {
@@ -2566,12 +3016,44 @@ window.__ModuleLoader__.load({
2566
3016
  },
2567
3017
  children:
2568
3018
  (0, react_jsx_runtime.jsx)("div", { style: S.canvasCenter, children:
2569
- (0, react_jsx_runtime.jsx)("div", { ref: contentRef, style: { margin: "auto", zoom }, children:
2570
- (0, react_jsx_runtime.jsx)(TreeRow, { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel: handleCodePanel, collapsed, onToggleCollapse: toggleCollapse })
3019
+ // 034:动画期间 zoom 走 DOM 直写(style.zoom),React state
3020
+ // 停在动画前的旧值——动画中任何 re-render(AI 改树、hover)
3021
+ // 若按 state 渲染会把 DOM 打回旧值造成跳变。渲染值在动画
3022
+ // 在飞时改读 zoomRef(恒等于 DOM 当前值),style diff 后
3023
+ // 不覆盖;动画结束 state 已同步,两种取值一致。
3024
+ (0, react_jsx_runtime.jsx)("div", { ref: contentRef, style: { margin: "auto", zoom: zoomAnimRef.current ? zoomRef.current : zoom }, children:
3025
+ (0, react_jsx_runtime.jsx)(TreeRow, { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel: handleCodePanel, collapsed, onToggleCollapse: toggleCollapse, matchIds: searchMatchIds, activeMatchId: searchActiveId })
2571
3026
  })
2572
3027
  })
2573
3028
  }),
2574
3029
  (0, react_jsx_runtime.jsxs)("div", { style: S.zoomBar, children: [
3030
+ // 035 搜索入口:缩放条内一个轻量 🔍(线框图标与 M 按钮同风格),
3031
+ // 两模式(BS Tab / 独立面板)共用画布,一处实现双模式生效。
3032
+ (0, react_jsx_runtime.jsx)("button", {
3033
+ type: "button",
3034
+ title: "搜索节点(⌘/Ctrl+F)",
3035
+ "aria-label": "搜索节点",
3036
+ "aria-expanded": searchOpen ? "true" : "false",
3037
+ style: zoomBtnStyle("search", false),
3038
+ onClick: () => (searchOpen ? closeSearch() : openSearch()),
3039
+ onMouseEnter: () => setHover("search"),
3040
+ onMouseLeave: () => setHover((h) => (h === "search" ? null : h)),
3041
+ children: (0, react_jsx_runtime.jsx)("svg", {
3042
+ width: 13,
3043
+ height: 13,
3044
+ viewBox: "0 0 14 14",
3045
+ fill: "none",
3046
+ stroke: "currentColor",
3047
+ strokeWidth: 1.4,
3048
+ strokeLinecap: "round",
3049
+ "aria-hidden": "true",
3050
+ style: { display: "block" },
3051
+ children: [
3052
+ (0, react_jsx_runtime.jsx)("circle", { cx: 6, cy: 6, r: 4 }),
3053
+ (0, react_jsx_runtime.jsx)("path", { d: "M9.2 9.2 L12.5 12.5" }),
3054
+ ],
3055
+ }),
3056
+ }),
2575
3057
  (0, react_jsx_runtime.jsx)("button", {
2576
3058
  type: "button",
2577
3059
  title: "缩小",
@@ -2603,6 +3085,68 @@ window.__ModuleLoader__.load({
2603
3085
  children: "适配",
2604
3086
  }),
2605
3087
  ] }),
3088
+ // 035 节点搜索条:缩放条正下方的紧凑浮层(同款容器/主题变量)。
3089
+ // 输入即搜;Enter/↓ 下一个、Shift+Enter/↑ 上一个(双向环绕);
3090
+ // 无命中显示「未找到」。纯视图态——不碰 markdown/revision。
3091
+ searchOpen ? (0, react_jsx_runtime.jsxs)("div", { style: S.searchBar, children: [
3092
+ (0, react_jsx_runtime.jsx)("input", {
3093
+ ref: searchInputRef,
3094
+ type: "text",
3095
+ value: searchQuery,
3096
+ placeholder: "搜索节点…",
3097
+ "aria-label": "搜索当前脑图的节点文字",
3098
+ title: "搜索当前脑图的节点文字(Enter 下一个,Shift+Enter 上一个,Esc 关闭)",
3099
+ style: S.searchInput,
3100
+ onChange: onQueryChange,
3101
+ onKeyDown: (e) => {
3102
+ if (e.key === "Enter") {
3103
+ e.preventDefault();
3104
+ stepSearch(e.shiftKey ? -1 : 1);
3105
+ } else if (e.key === "ArrowDown") {
3106
+ e.preventDefault();
3107
+ stepSearch(1);
3108
+ } else if (e.key === "ArrowUp") {
3109
+ e.preventDefault();
3110
+ stepSearch(-1);
3111
+ }
3112
+ },
3113
+ }),
3114
+ (0, react_jsx_runtime.jsx)("span", { style: S.searchCount, "aria-live": "polite", children: searchMatches.length === 0
3115
+ ? (searchQuery.trim() ? "未找到" : "0 / 0")
3116
+ : `${searchIndexSafe >= 0 ? searchIndexSafe + 1 : 0} / ${searchMatches.length}` }),
3117
+ (0, react_jsx_runtime.jsx)("button", {
3118
+ type: "button",
3119
+ title: "上一个匹配(Shift+Enter)",
3120
+ "aria-label": "上一个匹配",
3121
+ style: zoomBtnStyle("sprev", searchMatches.length === 0),
3122
+ disabled: searchMatches.length === 0,
3123
+ onClick: () => stepSearch(-1),
3124
+ onMouseEnter: () => setHover("sprev"),
3125
+ onMouseLeave: () => setHover((h) => (h === "sprev" ? null : h)),
3126
+ children: "↑",
3127
+ }),
3128
+ (0, react_jsx_runtime.jsx)("button", {
3129
+ type: "button",
3130
+ title: "下一个匹配(Enter)",
3131
+ "aria-label": "下一个匹配",
3132
+ style: zoomBtnStyle("snext", searchMatches.length === 0),
3133
+ disabled: searchMatches.length === 0,
3134
+ onClick: () => stepSearch(1),
3135
+ onMouseEnter: () => setHover("snext"),
3136
+ onMouseLeave: () => setHover((h) => (h === "snext" ? null : h)),
3137
+ children: "↓",
3138
+ }),
3139
+ (0, react_jsx_runtime.jsx)("button", {
3140
+ type: "button",
3141
+ title: "关闭搜索(Esc)",
3142
+ "aria-label": "关闭搜索",
3143
+ style: zoomBtnStyle("sclose", false),
3144
+ onClick: closeSearch,
3145
+ onMouseEnter: () => setHover("sclose"),
3146
+ onMouseLeave: () => setHover((h) => (h === "sclose" ? null : h)),
3147
+ children: "✕",
3148
+ }),
3149
+ ] }) : null,
2606
3150
  // 017 节点右键菜单:标题行(节点主题)+ 复制全文/复制为图片/导出为
2607
3151
  // 图片三动作 + 错误行。复用目录树菜单容器样式(fixed 定位,left/top = 视口坐标)。
2608
3152
  nodeMenu ? (0, react_jsx_runtime.jsxs)("div", {
@@ -2760,6 +3304,10 @@ window.__ModuleLoader__.load({
2760
3304
  const [exporting, setExporting] = react.useState(false);
2761
3305
  const [exportError, setExportError] = react.useState("");
2762
3306
  const [filledHint, setFilledHint] = react.useState("");
3307
+ // 032 复制全文:copying = 写剪贴板进行中;copiedOk = 成功短反馈
3308
+ //(按钮文案短暂变「已复制 ✓」约 2s;失败复用 exportError 展示位)。
3309
+ const [copying, setCopying] = react.useState(false);
3310
+ const [copiedOk, setCopiedOk] = react.useState(false);
2763
3311
  // fsTree:nodes = {path → 节点}, expanded = {path → true}, loading = {path → true}。
2764
3312
  const [fsTree, setFsTree] = react.useState({ nodes: {}, expanded: {}, loading: {}, cwd: null, error: null });
2765
3313
  // 会话切换时递增,使旧请求的异步回包不能写入新会话的目录树。
@@ -2888,6 +3436,24 @@ window.__ModuleLoader__.load({
2888
3436
  setExporting(false);
2889
3437
  }
2890
3438
  }
3439
+
3440
+ // 032 复制全文:当前脑图的 Markdown 原文写入系统剪贴板。内容直接取
3441
+ // doc.content(tree 即由它解析而来),不从树结构反向序列化——零信息
3442
+ // 损失(标题/列表/表格/原文空白原样保留),与参考实现实测路径一致。
3443
+ async function onCopyText() {
3444
+ if (!doc || doc.op === "local" || copying) return;
3445
+ setCopying(true);
3446
+ setExportError("");
3447
+ try {
3448
+ await copyPlainText(doc.content);
3449
+ setCopiedOk(true);
3450
+ setTimeout(() => setCopiedOk(false), 2000);
3451
+ } catch (error) {
3452
+ setExportError(String(error?.message ?? error));
3453
+ } finally {
3454
+ setCopying(false);
3455
+ }
3456
+ }
2891
3457
  //#region 013 目录树 tab:懒加载树 + 把指令填进聊天输入框
2892
3458
  // 草稿保护:确实读到非空草稿才让路(改走剪贴板),读不到就按既有
2893
3459
  // 行为直填直发——宿主不暴露草稿时不能把功能整个卡死。
@@ -3359,6 +3925,16 @@ window.__ModuleLoader__.load({
3359
3925
  onClick: onExport,
3360
3926
  children: exporting ? "导出中…" : "导出图片",
3361
3927
  });
3928
+ // 032 复制全文按钮(两种模式共用):整篇 Markdown 原文写系统剪贴板,插在
3929
+ // 导出按钮左侧;disabled 语义与导出一致(无树/复制中/本地占位不可复制)。
3930
+ const copyBtn = (0, react_jsx_runtime.jsx)("button", {
3931
+ type: "button",
3932
+ style: S.action,
3933
+ disabled: !tree || copying || (doc && doc.op === "local"),
3934
+ onClick: onCopyText,
3935
+ title: "把当前脑图的 Markdown 原文复制到剪贴板",
3936
+ children: copying ? "复制中…" : copiedOk ? "已复制 ✓" : "复制全文",
3937
+ });
3362
3938
  const exportErrorSpan = exportError
3363
3939
  ? (0, react_jsx_runtime.jsx)("span", { style: { color: "var(--dsw-alias-label-error)", fontSize: "12px" }, children: exportError })
3364
3940
  : null;
@@ -3418,10 +3994,11 @@ window.__ModuleLoader__.load({
3418
3994
  }),
3419
3995
  ],
3420
3996
  }, shown) : null,
3421
- // 导出按钮 + 错误推到行尾。
3997
+ // 复制/导出按钮 + 错误推到行尾。
3422
3998
  (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
3423
3999
  approvalControls,
3424
4000
  exportErrorSpan,
4001
+ copyBtn,
3425
4002
  exportBtn,
3426
4003
  ] }),
3427
4004
  // 016:脑图视图走 MindmapCanvas(自带滚动 + 居中 + 右上角缩放控制条),
@@ -3457,6 +4034,7 @@ window.__ModuleLoader__.load({
3457
4034
  (0, react_jsx_runtime.jsxs)("div", { style: S.headerTop, children: [
3458
4035
  (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
3459
4036
  approvalControls,
4037
+ copyBtn,
3460
4038
  exportBtn,
3461
4039
  exportErrorSpan,
3462
4040
  // 关闭按钮:仅独立 fixed 壳提供 onClose(BS Tab 自带关闭)。
@@ -4316,6 +4894,11 @@ window.__ModuleLoader__.load({
4316
4894
  countDescendants,
4317
4895
  pruneCollapsed,
4318
4896
  TreeRow,
4897
+ // 035 节点搜索:命中计算 / 下标步进(环绕)/ 命中保持 / 祖先展开(供测试)。
4898
+ searchTreeMatches,
4899
+ stepMatchIndex,
4900
+ reconcileActiveMatch,
4901
+ expandAncestorsFor,
4319
4902
  // 019 皮肤层与血肉层纯函数(供测试)。
4320
4903
  resolveToken,
4321
4904
  resolveNodeStyle,
@@ -4335,6 +4918,9 @@ window.__ModuleLoader__.load({
4335
4918
  stepZoom,
4336
4919
  fitZoom,
4337
4920
  focusZoom,
4921
+ // 033 点击聚焦跳变钳制 + 保视野拉回位移(供测试)。
4922
+ clampFocusJump,
4923
+ edgePullOffsets,
4338
4924
  // 021 画布平移手势判定(供测试)。
4339
4925
  PAN,
4340
4926
  shouldStartPan,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mindmap",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Mindmap plugin for DeepSeek Harness: a plain markdown file in the working directory IS the mindmap; the chat edits it step by step and the right-side panel follows live.",
5
5
  "repository": {
6
6
  "type": "git",