dsh-mindmap 0.12.0 → 0.13.1

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/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}` : ""}`;
@@ -958,6 +974,29 @@ window.__ModuleLoader__.load({
958
974
  }
959
975
  //#endregion
960
976
 
977
+ //#region 036 脑图收件箱:默认目录的显示文案与新建入口(纯函数)
978
+ const DEFAULT_MINDMAP_DIR = ".mindmaps";
979
+ const DEFAULT_MINDMAP_DIR_LABEL = "脑图收件箱(.mindmaps)";
980
+
981
+ /** 目录树显示名:点号目录看着像工具残留,收件箱给一句人话(真实路径仍在 title 上)。 */
982
+ function treeDirLabel(name) {
983
+ const raw = String(name ?? "");
984
+ return raw === DEFAULT_MINDMAP_DIR ? DEFAULT_MINDMAP_DIR_LABEL : raw;
985
+ }
986
+
987
+ /** 新建入口文案:有目录上下文就写进那个目录,没有才交给默认收件箱。 */
988
+ function treeCreateDraft(relDirectory) {
989
+ const dir = String(relDirectory ?? "").trim();
990
+ return dir
991
+ ? `我想在 ${dir} 目录里创建一个 Markdown 脑图`
992
+ : `我想新建一个脑图,按默认命名放进 ${DEFAULT_MINDMAP_DIR} 脑图收件箱`;
993
+ }
994
+
995
+ function treeCreateLabel(relDirectory) {
996
+ return String(relDirectory ?? "").trim() ? "在此目录新建 Markdown 脑图" : "在脑图收件箱新建脑图";
997
+ }
998
+ //#endregion
999
+
961
1000
  //#region 025 草稿保护:能力探测(宿主是否让插件读到聊天草稿)
962
1001
  /**
963
1002
  * 读取当前聊天草稿。宿主契约只保证 setDraft/submit,读取面属可选能力:
@@ -1027,6 +1066,79 @@ window.__ModuleLoader__.load({
1027
1066
  }
1028
1067
  //#endregion
1029
1068
 
1069
+ //#region 035 节点搜索:命中计算 / 下标步进 / 命中保持 / 祖先展开(纯函数,经 internals 供测试)
1070
+ /**
1071
+ * 在当前树里搜节点可见文字(topic):大小写不敏感子串匹配,先序遍历
1072
+ * 返回命中节点 id 列表(含根)。空/纯空白查询返回空数组。不搜整个
1073
+ * workspace、不做正则/模糊——第一版只要简单可靠。
1074
+ */
1075
+ function searchTreeMatches(tree, query) {
1076
+ const q = String(query ?? "").trim().toLowerCase();
1077
+ if (!q) return [];
1078
+ const out = [];
1079
+ const walk = (node) => {
1080
+ if (!node) return;
1081
+ if (String(node.topic ?? "").toLowerCase().includes(q)) out.push(node.id);
1082
+ for (const child of node.children ?? []) walk(child);
1083
+ };
1084
+ walk(tree);
1085
+ return out;
1086
+ }
1087
+
1088
+ /**
1089
+ * 下标步进(delta = +1 下一个 / −1 上一个),双向环绕(末尾→开头、
1090
+ * 开头→末尾)。当前下标越界(AI 改写后命中列表已变)先归零再步进;
1091
+ * 无命中返回 −1。
1092
+ */
1093
+ function stepMatchIndex(index, count, delta) {
1094
+ if (!(count > 0)) return -1;
1095
+ const base = Number.isInteger(index) && index >= 0 && index < count ? index : 0;
1096
+ const step = delta >= 0 ? 1 : -1;
1097
+ return (base + step + count) % count;
1098
+ }
1099
+
1100
+ /**
1101
+ * 命中列表重算后的当前项保持(AI 更改 mindmap 后):优先按稳定结构 id
1102
+ * 找回原命中节点;找不到则钳制到最近的有效下标;再不行回落第一个。
1103
+ * 无命中返回 −1。返回值是 matches 里的下标。
1104
+ */
1105
+ function reconcileActiveMatch(prevId, prevIndex, matches) {
1106
+ if (!Array.isArray(matches) || matches.length === 0) return -1;
1107
+ if (prevId != null) {
1108
+ const idx = matches.indexOf(prevId);
1109
+ if (idx >= 0) return idx;
1110
+ }
1111
+ if (Number.isInteger(prevIndex) && prevIndex >= 0 && prevIndex < matches.length) return prevIndex;
1112
+ return 0;
1113
+ }
1114
+
1115
+ /**
1116
+ * 定位命中前展开其祖先路径:把「根 → 目标」链上的折叠 id 全部移出
1117
+ *(不含目标自身——自身折叠只藏子树,盒子仍可见),无关折叠保留。
1118
+ * 无需变化 / 目标不存在时原样返回入参集合(引用不变,React 免重渲染)。
1119
+ */
1120
+ function expandAncestorsFor(collapsed, tree, nodeId) {
1121
+ if (!collapsed || collapsed.size === 0 || !tree || nodeId == null) return collapsed;
1122
+ const ancestors = [];
1123
+ const walk = (node, chain) => {
1124
+ if (!node) return false;
1125
+ if (node.id === nodeId) {
1126
+ for (const id of chain) ancestors.push(id);
1127
+ return true;
1128
+ }
1129
+ for (const child of node.children ?? []) {
1130
+ if (walk(child, chain.concat(node.id))) return true;
1131
+ }
1132
+ return false;
1133
+ };
1134
+ walk(tree, []);
1135
+ if (!ancestors.some((id) => collapsed.has(id))) return collapsed;
1136
+ const next = new Set(collapsed);
1137
+ for (const id of ancestors) next.delete(id);
1138
+ return next;
1139
+ }
1140
+ //#endregion
1141
+
1030
1142
  //#region PNG 导出(SVG 序列化 → canvas → 下载 / 剪贴板)
1031
1143
  // 019 可变盒高布局:盒高按内容估行数(全量换行的导出形态),表格节点加宽;
1032
1144
  // 布局契约不变——叶子自上而下占行、父节点垂直居中于其子块。
@@ -1426,7 +1538,10 @@ window.__ModuleLoader__.load({
1426
1538
  canvasWrap: { flex: "1 1 auto", minHeight: 0, minWidth: 0, position: "relative", display: "flex", flexDirection: "column" },
1427
1539
  // 021 平移:空白处抓手光标(节点盒自带 pointer 覆盖);overscroll
1428
1540
  // contain 让画布滚到边时不把滚动链传给宿主页面(聊天区不跟着动)。
1429
- canvasScroll: { flex: "1 1 auto", minHeight: 0, minWidth: 0, overflow: "auto", cursor: "grab", overscrollBehavior: "contain" },
1541
+ // 033 scrollbar-gutter 常驻滚动条槽位:滚动条出现/消失不再改变
1542
+ // clientWidth——从源头掐掉「适配→滚动条出现→视口变窄→再适配」的
1543
+ // 抖动循环(老保险丝降级为兜底;不支持该属性的宿主优雅退化)。
1544
+ canvasScroll: { flex: "1 1 auto", minHeight: 0, minWidth: 0, overflow: "auto", cursor: "grab", overscrollBehavior: "contain", scrollbarGutter: "stable" },
1430
1545
  // 居中层:内容小则铺满视口(100%),大则撑到内容尺寸(max-content);
1431
1546
  // 子项用 margin:auto——空间充足双向居中,溢出时 margin 归零、从滚动
1432
1547
  // 原点排布(flexbox 溢出居中裁剪的标准解法,无左/上侧裁剪)。
@@ -1439,6 +1554,11 @@ window.__ModuleLoader__.load({
1439
1554
  // 百分比标签:tabular-nums 防数字抖动。
1440
1555
  zoomLabel: { flex: "none", minWidth: "38px", textAlign: "center", fontSize: "11px", lineHeight: "20px", color: "var(--dsw-alias-label-secondary)", fontVariantNumeric: "tabular-nums", userSelect: "none" },
1441
1556
  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" },
1557
+ // 035 节点搜索:缩放条同款浮层容器,挂在缩放条正下方(顶 44px),
1558
+ // 全部复用宿主主题变量,亮暗/换肤自动跟随。
1559
+ 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)" },
1560
+ 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" },
1561
+ 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
1562
  // 027 内嵌头部(sidebar 模式):BS 外层已有 Tab 头部,内嵌只保留一行
1443
1563
  // 紧凑工具栏——脑图列表标签 + 当前脑图标签 + 导出按钮(行尾)。
1444
1564
  // 上下内距比 standalone 的 header(12px 14px 0)更紧凑,行间距更小。
@@ -1785,8 +1905,8 @@ window.__ModuleLoader__.load({
1785
1905
  //#endregion
1786
1906
 
1787
1907
  function NodeBox(props) {
1788
- const { node, theme, revealDelay, selectedId, onCodePanel } = props;
1789
- const [hovered, setHovered] = react.useState(false);
1908
+ const { node, theme, revealDelay, selectedId, onCodePanel, matchIds, activeMatchId } = props;
1909
+ const [hovered, setHovered] = react.useState(false);
1790
1910
  const boxRef = react.useRef(null);
1791
1911
  // 020 长度治理:散文类块(text/md/list/quote)套 6 行截断;clamped = 实测
1792
1912
  // 真的溢出了(scrollHeight>clientHeight),悬停浮层看全文(复用代码浮层)。
@@ -1808,7 +1928,13 @@ window.__ModuleLoader__.load({
1808
1928
  ...resolveNodeStyle(node, {
1809
1929
  colorTheme: theme && theme.colorTheme,
1810
1930
  cardStyle: theme && theme.cardStyle,
1811
- states: { hovered, selected: selectedId === node.id },
1931
+ states: {
1932
+ hovered,
1933
+ selected: selectedId === node.id,
1934
+ // 035 搜索命中:普通命中轻描边,活动命中的命中节点双层强调环。
1935
+ matched: Boolean(matchIds && matchIds.has(node.id)),
1936
+ matchActive: activeMatchId === node.id,
1937
+ },
1812
1938
  }),
1813
1939
  };
1814
1940
  // 020 表格块不参与散文 320px 宽上限:完整网格需要更宽书写面,
@@ -1849,7 +1975,7 @@ window.__ModuleLoader__.load({
1849
1975
 
1850
1976
  /** 左→右递归树:节点盒 + 右侧子节点列 + 连线层(015 支持折线/曲线两种线型)。 */
1851
1977
  function TreeRow(props) {
1852
- const { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse } = props;
1978
+ const { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse, matchIds, activeMatchId } = props;
1853
1979
  // 025 折叠:纯视图态——markdown 资产不变,导出仍取完整子树。
1854
1980
  const hasChildren = Boolean(node.children && node.children.length > 0);
1855
1981
  const isCollapsed = hasChildren && Boolean(collapsed && collapsed.has(node.id));
@@ -1966,7 +2092,7 @@ window.__ModuleLoader__.load({
1966
2092
  e.stopPropagation();
1967
2093
  onNodeContextMenu(e, node);
1968
2094
  } : undefined,
1969
- children: (0, react_jsx_runtime.jsx)(NodeBox, { node, theme, revealDelay, selectedId, onCodePanel }),
2095
+ children: (0, react_jsx_runtime.jsx)(NodeBox, { node, theme, revealDelay, selectedId, onCodePanel, matchIds, activeMatchId }),
1970
2096
  }),
1971
2097
  // 025 折叠开关:坐在盒与子列之间的连线起点上(有子节点才出现)。
1972
2098
  // stopPropagation 保证点它不触发画布的「点节点聚焦 / 点空白取消选中」。
@@ -1991,7 +2117,7 @@ window.__ModuleLoader__.load({
1991
2117
  ref: (el) => {
1992
2118
  childRefs.current[idx] = el;
1993
2119
  },
1994
- children: (0, react_jsx_runtime.jsx)(TreeRow, { node: child, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse }),
2120
+ children: (0, react_jsx_runtime.jsx)(TreeRow, { node: child, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse, matchIds, activeMatchId }),
1995
2121
  }, child.id)) })
1996
2122
  : null,
1997
2123
  ] });
@@ -2001,7 +2127,15 @@ window.__ModuleLoader__.load({
2001
2127
  // 缩放契约:范围 [0.25, 3],每级 ×1.2;适配计算四周留 48px 余量
2002
2128
  //(16px 视觉内距 + 经典滚动条占位,避免「适配→滚动条出现→视口变
2003
2129
  // 窄→再适配」的抖动循环)。
2004
- const ZOOM = { min: 0.25, max: 3, step: 1.2, padding: 48, focusMax: 1 };
2130
+ // 033 focusJump:点击聚焦单次跳变上限(相对当前比例最多 ×2 / ÷2),
2131
+ // 巨图点叶子不再一步怼到 100%,连点渐进 drill。narrowView:视口宽
2132
+ // 低于该值(sidebar 最窄 280px)时改按高度适配——横向适配在窄面板
2133
+ // 永远占主导会把子树压得过小,宽度溢出交给平移(横向本就一等公民)。
2134
+ // animMs:033 平滑过渡时长上限(限长、可中断、熔断后退化瞬时)。
2135
+ const ZOOM = { min: 0.25, max: 3, step: 1.2, padding: 48, focusMax: 1, focusJump: 2, narrowView: 400, animMs: 250 };
2136
+ // 034 聚焦锚位(视口比例):树向右生长,节点压在左侧 1/4 处、
2137
+ // 垂直居中,右侧 3/4 视野铺开子级。动画从点击位置插值到此锚位。
2138
+ const FOCUS_ANCHOR = { x: 0.25, y: 0.5 };
2005
2139
 
2006
2140
  /** 缩放夹取:非有限值/≤0 回退 1,否则夹到 [min, max]。 */
2007
2141
  function clampZoom(value) {
@@ -2018,18 +2152,59 @@ window.__ModuleLoader__.load({
2018
2152
  /** 适配比例:min((view-padding)/tree, 1) 再夹取——小图不放大、巨图夹下限;零/非法尺寸返回 1。 */
2019
2153
  function fitZoom(treeW, treeH, viewW, viewH) {
2020
2154
  if (!(treeW > 0) || !(treeH > 0) || !(viewW > 0) || !(viewH > 0)) return 1;
2155
+ // 033 窄视口(sidebar):按高度适配,宽度溢出靠平移。
2156
+ if (viewW < ZOOM.narrowView) return clampZoom(Math.min((viewH - ZOOM.padding) / treeH, 1));
2021
2157
  return clampZoom(Math.min((viewW - ZOOM.padding) / treeW, (viewH - ZOOM.padding) / treeH, 1));
2022
2158
  }
2023
2159
 
2024
2160
  /**
2025
2161
  * 子树聚焦比例:适配整棵子树(区别于全局适配,允许放大到 focusMax),
2026
2162
  * 叶子/小子树不会怼脸、巨子树夹下限;零/非法尺寸返回 1。
2163
+ * 033 窄视口同 fitZoom:按高度适配(子树行通常宽而扁,窄面板里
2164
+ * 横向适配会把整行压到不可读)。
2027
2165
  */
2028
2166
  function focusZoom(treeW, treeH, viewW, viewH) {
2029
2167
  if (!(treeW > 0) || !(treeH > 0) || !(viewW > 0) || !(viewH > 0)) return 1;
2168
+ if (viewW < ZOOM.narrowView) return clampZoom(Math.min((viewH - ZOOM.padding) / treeH, ZOOM.focusMax));
2030
2169
  return clampZoom(Math.min((viewW - ZOOM.padding) / treeW, (viewH - ZOOM.padding) / treeH, ZOOM.focusMax));
2031
2170
  }
2032
2171
 
2172
+ /**
2173
+ * 033 点击聚焦跳变钳制:目标比例相对当前值单次最多变化 focusJump 倍
2174
+ *(放大 ×2 / 缩小 ÷2),超出则截到边界。放置在调用点而非 focusZoom
2175
+ * 内——focusZoom 保持「无状态适配计算」语义(测试直测),跳变限制
2176
+ * 需要知道当前值,属交互层策略。连续点击逐步逼近,方向不变。
2177
+ */
2178
+ function clampFocusJump(target, current) {
2179
+ const value = clampZoom(target);
2180
+ const base = clampZoom(current);
2181
+ return Math.min(base * ZOOM.focusJump, Math.max(base / ZOOM.focusJump, value));
2182
+ }
2183
+
2184
+ /** 033 项3:按结构 id 找当前树里的节点盒(遍历比对属性值,不做选择器
2185
+ * 拼接——结构 id 虽是数字路径,这里不依赖该假设)。找不到返回 null。 */
2186
+ function findBoxByNodeId(scroller, id) {
2187
+ if (!scroller || typeof scroller.querySelectorAll !== "function") return null;
2188
+ const boxes = scroller.querySelectorAll("[data-mindmap-node-id]");
2189
+ for (const el of boxes) {
2190
+ if (el.getAttribute("data-mindmap-node-id") === id) return el;
2191
+ }
2192
+ return null;
2193
+ }
2194
+
2195
+ /** 033 项3:把完全离开视口的盒子拉回最近边的最小滚动位移(视口坐标
2196
+ * 系,正 = 向右/下滚)。部分可见或在内返回 0——不打扰用户视角。
2197
+ * margin = 拉回后与视口边保留的呼吸余量。 */
2198
+ function edgePullOffsets(box, view, margin) {
2199
+ let dx = 0;
2200
+ let dy = 0;
2201
+ if (box.right < view.left) dx = box.left - (view.left + margin);
2202
+ else if (box.left > view.right) dx = box.right - (view.right - margin);
2203
+ if (box.bottom < view.top) dy = box.top - (view.top + margin);
2204
+ else if (box.top > view.bottom) dy = box.bottom - (view.bottom - margin);
2205
+ return { x: dx, y: dy };
2206
+ }
2207
+
2033
2208
  //#region 021 画布平移:拖拽手势(中键 / 空白处左键 / 空格+左键)
2034
2209
  // 平移契约(三条手指路径,覆盖鼠标与 Mac 触摸板):
2035
2210
  // 中键拖动 —— 画布惯例,任何位置都拖(压节点上也拖)
@@ -2127,7 +2302,7 @@ window.__ModuleLoader__.load({
2127
2302
  // 016 熔断器:观察器触发的适配时间戳。1.5s 内第 5 次 → 判定
2128
2303
  // 反馈循环,自动停手(保险丝,任何未知循环都最多闪几下)。
2129
2304
  const fitStampRef = react.useRef([]);
2130
- const [zoom, setZoomState] = react.useState(1);
2305
+ const [zoom, setZoomState] = react.useState(1);
2131
2306
  const [hover, setHover] = react.useState(null);
2132
2307
  // 017 节点右键菜单:{x, y, node};null = 关闭。busy = "copy" |
2133
2308
  // "export" 表示对应动作进行中(两项都禁用),error 展示失败原因。
@@ -2140,6 +2315,24 @@ window.__ModuleLoader__.load({
2140
2315
  // 025 折叠子树:纯视图态(不写回 markdown,导出仍取完整子树)。
2141
2316
  // 切换文档时全部展开;AI 改写后清掉已消失节点的折叠标记。
2142
2317
  const [collapsed, setCollapsed] = react.useState(() => new Set());
2318
+ // 035 节点搜索:开箱态 / 查询词 / 当前命中下标 / 待定位 id。
2319
+ // 命中列表由 useMemo 按 [node, searchQuery] 现算——O(n) 子串
2320
+ // 匹配(上千节点也是微秒级),不重 parse、不重建 DOM。
2321
+ const [searchOpen, setSearchOpen] = react.useState(false);
2322
+ const [searchQuery, setSearchQuery] = react.useState("");
2323
+ const [searchIndex, setSearchIndex] = react.useState(-1);
2324
+ const [searchReveal, setSearchReveal] = react.useState(null);
2325
+ const searchInputRef = react.useRef(null);
2326
+ // 当前命中的稳定结构 id:AI 改写树后按它找回原命中节点。
2327
+ const searchActiveIdRef = react.useRef(null);
2328
+ const searchMatches = react.useMemo(() => searchTreeMatches(node, searchQuery), [node, searchQuery]);
2329
+ const searchMatchIds = searchMatches.length > 0 ? new Set(searchMatches) : null;
2330
+ // 渲染期先钳一次:AI 改写后命中列表变短,[node] 协调 effect
2331
+ // 生效前的那一帧若沿用旧下标会显示「4 / 3」这类越界计数。
2332
+ const searchIndexSafe = searchMatches.length > 0
2333
+ ? (searchIndex >= 0 && searchIndex < searchMatches.length ? searchIndex : 0)
2334
+ : -1;
2335
+ const searchActiveId = searchIndexSafe >= 0 ? searchMatches[searchIndexSafe] : null;
2143
2336
  // 019 代码块悬停浮层:{node, anchor};null = 关闭。延迟关闭(150ms
2144
2337
  // 宽限)让鼠标能从节点盒移到面板上滚动全文,不闪灭。
2145
2338
  const [codePanel, setCodePanel] = react.useState(null);
@@ -2171,6 +2364,94 @@ window.__ModuleLoader__.load({
2171
2364
  // 021 指针是否悬在画布上(空格键要不要拦默认行为的门控;纯
2172
2365
  // 读取,不参与渲染)。
2173
2366
  const hoverRef = react.useRef(false);
2367
+ // 033 平滑过渡:在飞的 zoom 动画句柄 { id, from, to, start };
2368
+ // animDisabled = 熔断器触发过(本轮 fitKey 内动画退化为瞬时,
2369
+ // 切文档/点适配时复位)。
2370
+ // 034 动画期间绕过 React(根因二:每帧 setZoomState 整树重渲染,
2371
+ // 大图掉帧):每帧直写内容层 style.zoom + 滚动校正,不进 state;
2372
+ // 结束帧一次性 setZoomState(target) 同步 UI(百分比/边界按钮/
2373
+ // committedZoomRef)。测量基准不受影响——动画只在点击后飞,
2374
+ // 此时 userZoomedRef 已置位,ResizeObserver 不会再调 applyFit。
2375
+ const zoomAnimRef = react.useRef(null);
2376
+ const animDisabledRef = react.useRef(false);
2377
+
2378
+ // 034 仅停帧:取消 rAF + 同步 committed/state,保留 focusRef
2379
+ //(animateZoomTo 替换旧动画时用——调用方随后会覆盖 focusRef,
2380
+ // 不能让它把新聚焦也清掉)。中断时 DOM 已被直写到中间值——
2381
+ // 立即把 committedZoomRef 对齐该值(applyFit 的自然尺寸测量基准
2382
+ // 必须等于 DOM 实际 zoom),并用 setZoomState 把 React state
2383
+ // 兜底同步(防后续 re-render 把 style.zoom 打回动画前的旧值)。
2384
+ function stopZoomAnimFrames() {
2385
+ const anim = zoomAnimRef.current;
2386
+ if (!anim) return;
2387
+ zoomAnimRef.current = null;
2388
+ if (typeof cancelAnimationFrame === "function") cancelAnimationFrame(anim.id);
2389
+ committedZoomRef.current = zoomRef.current;
2390
+ setZoomState(zoomRef.current);
2391
+ }
2392
+
2393
+ // 033 截停在飞动画(任何新交互都先调):停帧 + 顺手清掉
2394
+ // focusRef(否则下一次 zoom 提交会被过期聚焦劫持定位)。
2395
+ function cancelZoomAnim() {
2396
+ if (!zoomAnimRef.current) return;
2397
+ stopZoomAnimFrames();
2398
+ focusRef.current = null;
2399
+ }
2400
+
2401
+ // 034 期望锚位插值:点击位置 → FOCUS_ANCHOR,与 zoom 同一
2402
+ // eased 进度——第一帧期望位置 = 点击时位置(零瞬移,根因一),
2403
+ // 节点被「牵着」滑向锚位。
2404
+ function lerpFocusAnchor(start, k) {
2405
+ return {
2406
+ x: start.x + (FOCUS_ANCHOR.x - start.x) * k,
2407
+ y: start.y + (FOCUS_ANCHOR.y - start.y) * k,
2408
+ };
2409
+ }
2410
+
2411
+ // 033/034 平滑 zoom:from → to,限长 animMs、easeOutQuad,并行
2412
+ // 上限 1(新动画先截停旧动画)。每帧:直写 style.zoom、同步
2413
+ // zoomRef、按插值锚位滚动校正(applyFocusAnchor);结束帧精确落
2414
+ // 在 to 并 setZoomState 触发最后一次 [zoom] effect(positionFocus
2415
+ // 消费 focusRef、全量锚位终校——此刻 ≈ no-op)。禁用/无 rAF 环
2416
+ // 境瞬时应用,行为与 033 之前完全一致。
2417
+ function animateZoomTo(to) {
2418
+ stopZoomAnimFrames();
2419
+ const target = clampZoom(to);
2420
+ const from = zoomRef.current;
2421
+ if (from === target) return;
2422
+ const scroller = scrollRef.current;
2423
+ const content = contentRef.current;
2424
+ const canAnimate = animDisabledRef.current !== true
2425
+ && scroller
2426
+ && content
2427
+ && typeof requestAnimationFrame === "function";
2428
+ if (!canAnimate) {
2429
+ zoomRef.current = target;
2430
+ setZoomState(target);
2431
+ return;
2432
+ }
2433
+ const anim = { id: 0, from, to: target, start: Date.now() };
2434
+ zoomAnimRef.current = anim;
2435
+ const frame = () => {
2436
+ if (zoomAnimRef.current !== anim) return; // 已被截停/替换
2437
+ const t = Math.min(1, (Date.now() - anim.start) / ZOOM.animMs);
2438
+ const eased = 1 - (1 - t) * (1 - t);
2439
+ const value = t >= 1 ? target : from + (target - from) * eased;
2440
+ zoomRef.current = value;
2441
+ content.style.zoom = value; // 034:直写 DOM,绕过 React
2442
+ const focus = focusRef.current;
2443
+ if (focus && focus.boxEl && focus.boxEl.isConnected) {
2444
+ applyFocusAnchor(focus.boxEl, lerpFocusAnchor(focus.startAnchor, eased));
2445
+ }
2446
+ if (t >= 1) {
2447
+ zoomAnimRef.current = null;
2448
+ setZoomState(target);
2449
+ return;
2450
+ }
2451
+ anim.id = requestAnimationFrame(frame);
2452
+ };
2453
+ anim.id = requestAnimationFrame(frame);
2454
+ }
2174
2455
 
2175
2456
  // 测量并适配:自然尺寸 = getBoundingClientRect ÷ 已提交 zoom(与
2176
2457
  // DOM 实际状态严格同步,无竞态)。值不变不动 state(bail-out),
@@ -2179,6 +2460,9 @@ window.__ModuleLoader__.load({
2179
2460
  const scroller = scrollRef.current;
2180
2461
  const content = contentRef.current;
2181
2462
  if (!scroller || !content) return;
2463
+ // 033:适配前截停在飞动画(观察器/适配按钮不能被旧动画
2464
+ // 的后续帧反向覆盖)。
2465
+ cancelZoomAnim();
2182
2466
  resetPanOffset();
2183
2467
  const rect = content.getBoundingClientRect();
2184
2468
  if (!(rect.width > 0) || !(rect.height > 0)) return;
@@ -2198,14 +2482,27 @@ window.__ModuleLoader__.load({
2198
2482
  }
2199
2483
 
2200
2484
  // 挂载 / 文档切换:清除「用户已手动缩放」标记与熔断计数,
2201
- // 布局稳定后(rAF)适配一次。
2485
+ // 布局稳定后(rAF)适配一次。033:同时复位动画禁用位与
2486
+ // 选中态(新文档不该继承旧文档的选中环——结构 id 跨文档
2487
+ // 可能撞名,会让保视野逻辑锚错节点);清理时截停在飞动画。
2202
2488
  react.useLayoutEffect(() => {
2203
2489
  userZoomedRef.current = false;
2204
2490
  lastNaturalRef.current = null;
2205
2491
  fitStampRef.current = [];
2492
+ animDisabledRef.current = false;
2493
+ setSelectedId(null);
2206
2494
  setCollapsed((prev) => (prev.size > 0 ? new Set() : prev));
2495
+ // 035:切文档重置搜索——上一张图的 query/命中不污染新图。
2496
+ setSearchOpen(false);
2497
+ setSearchQuery("");
2498
+ setSearchIndex(-1);
2499
+ setSearchReveal(null);
2500
+ searchActiveIdRef.current = null;
2207
2501
  const id = requestAnimationFrame(applyFit);
2208
- return () => cancelAnimationFrame(id);
2502
+ return () => {
2503
+ cancelAnimationFrame(id);
2504
+ cancelZoomAnim();
2505
+ };
2209
2506
  }, [fitKey]);
2210
2507
 
2211
2508
  // 内容 / 画布尺寸变化(AI 编辑、面板拖宽)→ 未手动缩放则再适配。
@@ -2234,6 +2531,9 @@ window.__ModuleLoader__.load({
2234
2531
  const stamps = fitStampRef.current = fitStampRef.current.filter((t) => now - t < 1500);
2235
2532
  if (stamps.length >= 5) {
2236
2533
  userZoomedRef.current = true;
2534
+ // 033:熔断判定成立 → 本轮 fitKey 内动画也停用(反馈
2535
+ // 循环环境里再引入中间态提交只会火上浇油)。
2536
+ animDisabledRef.current = true;
2237
2537
  return;
2238
2538
  }
2239
2539
  stamps.push(now);
@@ -2297,6 +2597,9 @@ window.__ModuleLoader__.load({
2297
2597
  // 否则上轮手势留下的 true 会粘到下一次点击上——例:拖完画布后再
2298
2598
  // 触摸点按(touch 路径不启动平移就早退了),那次点击会被白吞一次。
2299
2599
  suppressClickRef.current = false;
2600
+ // 033:平移起手即截停缩放动画——聚焦动画每帧把节点钉回锚位,
2601
+ // 会和用户拖拽的方向对着干。
2602
+ cancelZoomAnim();
2300
2603
  const scroller = scrollRef.current;
2301
2604
  if (!scroller || panRef.current) return;
2302
2605
  const target = e.target;
@@ -2385,7 +2688,11 @@ window.__ModuleLoader__.load({
2385
2688
  // DOM 已提交到该 zoom,测量换算基准同步(applyFit 依赖)。
2386
2689
  committedZoomRef.current = zoom;
2387
2690
  if (focusRef.current) {
2388
- positionFocus();
2691
+ // 034:动画在飞时既不定位也不消费——帧回调自己管锚位插值;
2692
+ // 动画中再点击时,cancel 的 setZoomState 也会路过这里,
2693
+ // 提前消费/全量锚位都会造成闪跳。瞬时聚焦与动画结束帧
2694
+ //(anim 先清再 setState)才做全量终校(结束时 ≈ no-op)。
2695
+ if (!zoomAnimRef.current) positionFocus();
2389
2696
  return;
2390
2697
  }
2391
2698
  const scroller = scrollRef.current;
@@ -2400,11 +2707,13 @@ window.__ModuleLoader__.load({
2400
2707
 
2401
2708
  function zoomIn() {
2402
2709
  userZoomedRef.current = true;
2710
+ cancelZoomAnim();
2403
2711
  setZoom(stepZoom(zoomRef.current, 1), true);
2404
2712
  }
2405
2713
 
2406
2714
  function zoomOut() {
2407
2715
  userZoomedRef.current = true;
2716
+ cancelZoomAnim();
2408
2717
  setZoom(stepZoom(zoomRef.current, -1), true);
2409
2718
  }
2410
2719
 
@@ -2418,6 +2727,8 @@ window.__ModuleLoader__.load({
2418
2727
  // 左侧锚点让子级铺满右侧视野),缩放比例取 focusZoom(整棵子树适配、
2419
2728
  // 上限 focusMax)。事件委托:closest 找节点盒与所在子树 row,无需给
2420
2729
  // 递归 TreeRow 传回调。聚焦视为用户手动缩放(停自动再适配)。
2730
+ // 033:目标比例经 clampFocusJump 单次最多 ×2/÷2(巨图点叶子不再一步
2731
+ // 怼到 100%,连点渐进 drill);zoom 变化经 animateZoomTo 平滑过渡。
2421
2732
  function onCanvasClick(e) {
2422
2733
  // 021:刚拖过画布(平移)的这次 click 不是点击,直接吞掉——
2423
2734
  // 否则每次平移松手都会顺手把选中环清掉。
@@ -2441,34 +2752,173 @@ window.__ModuleLoader__.load({
2441
2752
  if (!scroller) return;
2442
2753
  const current = zoomRef.current;
2443
2754
  const rowRect = rowEl.getBoundingClientRect();
2444
- const focus = focusZoom(rowRect.width / current, rowRect.height / current, scroller.clientWidth, scroller.clientHeight);
2755
+ // 033 跳变钳制:相对当前比例单次最多 ×2 / ÷2。
2756
+ const focus = clampFocusJump(
2757
+ focusZoom(rowRect.width / current, rowRect.height / current, scroller.clientWidth, scroller.clientHeight),
2758
+ current,
2759
+ );
2760
+ // 034:记录点击时节点中心的视口比例位置——动画锚位插值起点
2761
+ //(第一帧期望位置 = 点击时位置,消除首帧滚动瞬移)。
2762
+ const boxRect = boxEl.getBoundingClientRect();
2763
+ const scrollerRect = scroller.getBoundingClientRect();
2764
+ const startAnchor = {
2765
+ x: (boxRect.left + boxRect.width / 2 - scrollerRect.left) / scroller.clientWidth,
2766
+ y: (boxRect.top + boxRect.height / 2 - scrollerRect.top) / scroller.clientHeight,
2767
+ };
2445
2768
  userZoomedRef.current = true;
2446
- focusRef.current = { boxEl };
2447
2769
  if (focus !== current) {
2448
2770
  anchorRef.current = null;
2449
- zoomRef.current = focus;
2450
- setZoomState(focus);
2771
+ // 034:先完整截停旧动画(清过期 focusRef + 同步中间值),
2772
+ // 再登记本次聚焦——顺序不能反(cancel 会清 focusRef)。
2773
+ cancelZoomAnim();
2774
+ focusRef.current = { boxEl, startAnchor };
2775
+ animateZoomTo(focus);
2451
2776
  } else {
2777
+ cancelZoomAnim();
2778
+ focusRef.current = { boxEl, startAnchor };
2452
2779
  positionFocus();
2453
2780
  }
2454
2781
  }
2455
2782
 
2456
- // 聚焦定位:DOM 更新后量节点盒当前位置,滚动增量 = 当前位置 − 期望位置
2457
- //(scroll 增量与视口位移 1:1,浏览器自动钳制滚动范围;比例不变时同步调用)。
2458
- function positionFocus() {
2459
- const focus = focusRef.current;
2460
- focusRef.current = null;
2783
+ // 034 锚位应用:把节点盒中心滚到指定视口比例锚位(滚动增量与视口
2784
+ // 位移 1:1,浏览器自动钳制滚动范围)。positionFocus(固定锚位)与
2785
+ // 聚焦动画帧(插值锚位)共用。
2786
+ function applyFocusAnchor(boxEl, anchor) {
2461
2787
  const scroller = scrollRef.current;
2462
- if (!scroller || !focus || !focus.boxEl || !focus.boxEl.isConnected) return;
2788
+ if (!scroller || !boxEl || !boxEl.isConnected) return;
2463
2789
  resetPanOffset();
2464
- const boxRect = focus.boxEl.getBoundingClientRect();
2790
+ const boxRect = boxEl.getBoundingClientRect();
2465
2791
  const scrollerRect = scroller.getBoundingClientRect();
2466
2792
  const curX = boxRect.left + boxRect.width / 2 - scrollerRect.left;
2467
2793
  const curY = boxRect.top + boxRect.height / 2 - scrollerRect.top;
2468
- scroller.scrollLeft += curX - scroller.clientWidth * 0.25;
2469
- scroller.scrollTop += curY - scroller.clientHeight / 2;
2794
+ scroller.scrollLeft += curX - scroller.clientWidth * anchor.x;
2795
+ scroller.scrollTop += curY - scroller.clientHeight * anchor.y;
2470
2796
  }
2471
2797
 
2798
+ // 聚焦定位:DOM 更新后把节点盒滚到 FOCUS_ANCHOR(全量校正)。
2799
+ // 034:consume = false 时保留 focusRef——瞬时聚焦路径不再逐帧,仅
2800
+ // 动画结束帧(zoomAnimRef 已清空)与同步调用消费。
2801
+ function positionFocus(consume = true) {
2802
+ const focus = focusRef.current;
2803
+ if (!focus || !focus.boxEl || !focus.boxEl.isConnected) {
2804
+ focusRef.current = null;
2805
+ return;
2806
+ }
2807
+ if (consume) focusRef.current = null;
2808
+ applyFocusAnchor(focus.boxEl, FOCUS_ANCHOR);
2809
+ }
2810
+
2811
+ //#region 035 节点搜索:输入即搜 + 匹配间跳转 + 自动展开祖先 + 滚动定位
2812
+ // 打开搜索(Cmd/Ctrl+F 或缩放条 🔍)。关闭 = 清 query/命中/高亮;
2813
+ // 为定位展开的祖先保持展开——用户下一步多半还要看上下文。
2814
+ function openSearch() {
2815
+ setSearchOpen(true);
2816
+ }
2817
+ function closeSearch() {
2818
+ setSearchOpen(false);
2819
+ setSearchQuery("");
2820
+ setSearchIndex(-1);
2821
+ searchActiveIdRef.current = null;
2822
+ }
2823
+
2824
+ // 输入即搜:每次按键 O(n) 现算命中并跳到第一个(VS Code find 同款手感)。
2825
+ // 直接调纯函数拿新查询的结果(本渲染的 memo 还是旧 query 的)。
2826
+ function onQueryChange(e) {
2827
+ const query = e && e.target ? e.target.value : "";
2828
+ const matches = searchTreeMatches(node, query);
2829
+ setSearchQuery(query);
2830
+ if (matches.length > 0) {
2831
+ setSearchIndex(0);
2832
+ searchActiveIdRef.current = matches[0];
2833
+ revealSearchMatch(matches[0]);
2834
+ } else {
2835
+ setSearchIndex(-1);
2836
+ searchActiveIdRef.current = null;
2837
+ }
2838
+ }
2839
+
2840
+ // 上一个/下一个:双向环绕(末尾→开头、开头→末尾)。
2841
+ function stepSearch(delta) {
2842
+ if (searchMatches.length === 0) return;
2843
+ const next = stepMatchIndex(searchIndex, searchMatches.length, delta);
2844
+ setSearchIndex(next);
2845
+ searchActiveIdRef.current = searchMatches[next];
2846
+ revealSearchMatch(searchMatches[next]);
2847
+ }
2848
+
2849
+ // 定位一个命中:先展开它的祖先路径(折叠分支里的结果也真正可见),
2850
+ // 再登记待定位 id——[searchReveal] layout effect 在 DOM 提交后按结构
2851
+ // id 找盒、滚到聚焦锚位。不动 zoom(保留用户当前缩放,只改必要滚动)。
2852
+ function revealSearchMatch(id) {
2853
+ setCollapsed((prev) => expandAncestorsFor(prev, node, id));
2854
+ setSearchReveal(id);
2855
+ }
2856
+
2857
+ // 搜索定位提交后的滚动:与展开祖先同批 setState,此 effect 运行时
2858
+ // 展开的子树已挂载。搜索定位 = 显式视角意图:与点击聚焦一样停自动
2859
+ // 再适配,并截停在飞聚焦动画(其帧回调会把节点钉回旧锚位对着干)。
2860
+ react.useLayoutEffect(() => {
2861
+ if (!searchReveal) return;
2862
+ const scroller = scrollRef.current;
2863
+ const boxEl = scroller ? findBoxByNodeId(scroller, searchReveal) : null;
2864
+ if (boxEl) {
2865
+ userZoomedRef.current = true;
2866
+ cancelZoomAnim();
2867
+ applyFocusAnchor(boxEl, FOCUS_ANCHOR);
2868
+ }
2869
+ setSearchReveal(null);
2870
+ }, [searchReveal]);
2871
+
2872
+ // 开箱聚焦输入框(全选既有词——当前实现关闭即清空,习惯上仍全选)。
2873
+ react.useLayoutEffect(() => {
2874
+ if (!searchOpen) return;
2875
+ const input = searchInputRef.current;
2876
+ if (!input || typeof input.focus !== "function") return;
2877
+ input.focus();
2878
+ if (typeof input.select === "function") input.select();
2879
+ }, [searchOpen]);
2880
+
2881
+ // AI 更新后重算命中:保留 query;优先按稳定 id 找回原命中节点,
2882
+ // 找不到回落最近有效下标/第一个;无命中显示 0。只调下标不滚动——
2883
+ // AI 每次编辑都拽走视口会与「视角归用户」冲突,滚动只由导航触发。
2884
+ react.useEffect(() => {
2885
+ if (searchQuery === "") return;
2886
+ const next = reconcileActiveMatch(searchActiveIdRef.current, searchIndex, searchMatches);
2887
+ if (next !== searchIndex) setSearchIndex(next);
2888
+ if (next >= 0) searchActiveIdRef.current = searchMatches[next];
2889
+ }, [node]);
2890
+
2891
+ // Cmd/Ctrl+F 打开搜索。拦截范围 = 画布挂载(脑图 tab 可见且激活;
2892
+ // 面板收起/切目录树即卸载,无僵尸监听)且目标不是别人的文本输入
2893
+ //(聊天框里的 Cmd+F 留给宿主);已有人处理过(defaultPrevented)不抢。
2894
+ react.useEffect(() => {
2895
+ const onKeyDown = (e) => {
2896
+ if (e.defaultPrevented || e.altKey) return;
2897
+ if (!(e.metaKey || e.ctrlKey)) return;
2898
+ if (!e.key || e.key.toLowerCase() !== "f") return;
2899
+ if (isTextEntry(e.target) && e.target !== searchInputRef.current) return;
2900
+ e.preventDefault();
2901
+ setSearchOpen(true);
2902
+ };
2903
+ window.addEventListener("keydown", onKeyDown);
2904
+ return () => window.removeEventListener("keydown", onKeyDown);
2905
+ }, []);
2906
+
2907
+ // Escape 关闭搜索:仅搜索打开期间注册(closeSearch 只调常参 setter,
2908
+ // 闭包过期无害);目标在他人输入框时不抢 Escape。
2909
+ react.useEffect(() => {
2910
+ if (!searchOpen) return;
2911
+ const onKeyDown = (e) => {
2912
+ if (e.key !== "Escape" || e.defaultPrevented) return;
2913
+ if (isTextEntry(e.target) && e.target !== searchInputRef.current) return;
2914
+ e.preventDefault();
2915
+ closeSearch();
2916
+ };
2917
+ window.addEventListener("keydown", onKeyDown);
2918
+ return () => window.removeEventListener("keydown", onKeyDown);
2919
+ }, [searchOpen]);
2920
+ //#endregion
2921
+
2472
2922
  // 017 右键菜单开合:点其它地方/失焦/改窗口即关闭(目录树菜单同款);
2473
2923
  // 点菜单内部(复制/导出按钮)不关——菜单里要展示「复制中…」与失败
2474
2924
  // 原因。节点右键经 stopPropagation 不会触发这里的 contextmenu 关闭,
@@ -2497,6 +2947,29 @@ window.__ModuleLoader__.load({
2497
2947
  setCodePanel(null);
2498
2948
  // 025:树重解析后丢弃已消失节点的折叠标记(无变化时保持原引用)。
2499
2949
  setCollapsed((prev) => pruneCollapsed(prev, node));
2950
+ // 033 项3:AI 编辑后保住选中节点在视野内。仅在用户已定视角
2951
+ //(userZoomedRef,自动再适配已停)且选中节点**完全**离开视口时,
2952
+ // 以最小滚动量把它带回最近的边(部分可见不打扰)。只动 scroll:
2953
+ // 不改缩放、不碰 userZoomedRef/熔断器(滚动不触发 ResizeObserver
2954
+ // 的内容尺寸变化),「面板跟随 AI 实时变化」与「视角归用户」两个
2955
+ // 承诺同时成立。id 失效(节点被删/重写)→ 查不到盒,自然跳过。
2956
+ if (userZoomedRef.current && selectedId) {
2957
+ const scroller = scrollRef.current;
2958
+ const boxEl = scroller && typeof scroller.querySelectorAll === "function"
2959
+ ? findBoxByNodeId(scroller, selectedId)
2960
+ : null;
2961
+ if (boxEl && typeof boxEl.getBoundingClientRect === "function") {
2962
+ const box = boxEl.getBoundingClientRect();
2963
+ const view = scroller.getBoundingClientRect();
2964
+ const MARGIN = 24;
2965
+ const pull = edgePullOffsets(box, view, MARGIN);
2966
+ if (pull.x !== 0 || pull.y !== 0) {
2967
+ resetPanOffset();
2968
+ scroller.scrollLeft += pull.x;
2969
+ scroller.scrollTop += pull.y;
2970
+ }
2971
+ }
2972
+ }
2500
2973
  }, [node]);
2501
2974
 
2502
2975
  function toggleCollapse(id) {
@@ -2566,12 +3039,44 @@ window.__ModuleLoader__.load({
2566
3039
  },
2567
3040
  children:
2568
3041
  (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 })
3042
+ // 034:动画期间 zoom 走 DOM 直写(style.zoom),React state
3043
+ // 停在动画前的旧值——动画中任何 re-render(AI 改树、hover)
3044
+ // 若按 state 渲染会把 DOM 打回旧值造成跳变。渲染值在动画
3045
+ // 在飞时改读 zoomRef(恒等于 DOM 当前值),style diff 后
3046
+ // 不覆盖;动画结束 state 已同步,两种取值一致。
3047
+ (0, react_jsx_runtime.jsx)("div", { ref: contentRef, style: { margin: "auto", zoom: zoomAnimRef.current ? zoomRef.current : zoom }, children:
3048
+ (0, react_jsx_runtime.jsx)(TreeRow, { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel: handleCodePanel, collapsed, onToggleCollapse: toggleCollapse, matchIds: searchMatchIds, activeMatchId: searchActiveId })
2571
3049
  })
2572
3050
  })
2573
3051
  }),
2574
3052
  (0, react_jsx_runtime.jsxs)("div", { style: S.zoomBar, children: [
3053
+ // 035 搜索入口:缩放条内一个轻量 🔍(线框图标与 M 按钮同风格),
3054
+ // 两模式(BS Tab / 独立面板)共用画布,一处实现双模式生效。
3055
+ (0, react_jsx_runtime.jsx)("button", {
3056
+ type: "button",
3057
+ title: "搜索节点(⌘/Ctrl+F)",
3058
+ "aria-label": "搜索节点",
3059
+ "aria-expanded": searchOpen ? "true" : "false",
3060
+ style: zoomBtnStyle("search", false),
3061
+ onClick: () => (searchOpen ? closeSearch() : openSearch()),
3062
+ onMouseEnter: () => setHover("search"),
3063
+ onMouseLeave: () => setHover((h) => (h === "search" ? null : h)),
3064
+ children: (0, react_jsx_runtime.jsx)("svg", {
3065
+ width: 13,
3066
+ height: 13,
3067
+ viewBox: "0 0 14 14",
3068
+ fill: "none",
3069
+ stroke: "currentColor",
3070
+ strokeWidth: 1.4,
3071
+ strokeLinecap: "round",
3072
+ "aria-hidden": "true",
3073
+ style: { display: "block" },
3074
+ children: [
3075
+ (0, react_jsx_runtime.jsx)("circle", { cx: 6, cy: 6, r: 4 }),
3076
+ (0, react_jsx_runtime.jsx)("path", { d: "M9.2 9.2 L12.5 12.5" }),
3077
+ ],
3078
+ }),
3079
+ }),
2575
3080
  (0, react_jsx_runtime.jsx)("button", {
2576
3081
  type: "button",
2577
3082
  title: "缩小",
@@ -2603,6 +3108,68 @@ window.__ModuleLoader__.load({
2603
3108
  children: "适配",
2604
3109
  }),
2605
3110
  ] }),
3111
+ // 035 节点搜索条:缩放条正下方的紧凑浮层(同款容器/主题变量)。
3112
+ // 输入即搜;Enter/↓ 下一个、Shift+Enter/↑ 上一个(双向环绕);
3113
+ // 无命中显示「未找到」。纯视图态——不碰 markdown/revision。
3114
+ searchOpen ? (0, react_jsx_runtime.jsxs)("div", { style: S.searchBar, children: [
3115
+ (0, react_jsx_runtime.jsx)("input", {
3116
+ ref: searchInputRef,
3117
+ type: "text",
3118
+ value: searchQuery,
3119
+ placeholder: "搜索节点…",
3120
+ "aria-label": "搜索当前脑图的节点文字",
3121
+ title: "搜索当前脑图的节点文字(Enter 下一个,Shift+Enter 上一个,Esc 关闭)",
3122
+ style: S.searchInput,
3123
+ onChange: onQueryChange,
3124
+ onKeyDown: (e) => {
3125
+ if (e.key === "Enter") {
3126
+ e.preventDefault();
3127
+ stepSearch(e.shiftKey ? -1 : 1);
3128
+ } else if (e.key === "ArrowDown") {
3129
+ e.preventDefault();
3130
+ stepSearch(1);
3131
+ } else if (e.key === "ArrowUp") {
3132
+ e.preventDefault();
3133
+ stepSearch(-1);
3134
+ }
3135
+ },
3136
+ }),
3137
+ (0, react_jsx_runtime.jsx)("span", { style: S.searchCount, "aria-live": "polite", children: searchMatches.length === 0
3138
+ ? (searchQuery.trim() ? "未找到" : "0 / 0")
3139
+ : `${searchIndexSafe >= 0 ? searchIndexSafe + 1 : 0} / ${searchMatches.length}` }),
3140
+ (0, react_jsx_runtime.jsx)("button", {
3141
+ type: "button",
3142
+ title: "上一个匹配(Shift+Enter)",
3143
+ "aria-label": "上一个匹配",
3144
+ style: zoomBtnStyle("sprev", searchMatches.length === 0),
3145
+ disabled: searchMatches.length === 0,
3146
+ onClick: () => stepSearch(-1),
3147
+ onMouseEnter: () => setHover("sprev"),
3148
+ onMouseLeave: () => setHover((h) => (h === "sprev" ? null : h)),
3149
+ children: "↑",
3150
+ }),
3151
+ (0, react_jsx_runtime.jsx)("button", {
3152
+ type: "button",
3153
+ title: "下一个匹配(Enter)",
3154
+ "aria-label": "下一个匹配",
3155
+ style: zoomBtnStyle("snext", searchMatches.length === 0),
3156
+ disabled: searchMatches.length === 0,
3157
+ onClick: () => stepSearch(1),
3158
+ onMouseEnter: () => setHover("snext"),
3159
+ onMouseLeave: () => setHover((h) => (h === "snext" ? null : h)),
3160
+ children: "↓",
3161
+ }),
3162
+ (0, react_jsx_runtime.jsx)("button", {
3163
+ type: "button",
3164
+ title: "关闭搜索(Esc)",
3165
+ "aria-label": "关闭搜索",
3166
+ style: zoomBtnStyle("sclose", false),
3167
+ onClick: closeSearch,
3168
+ onMouseEnter: () => setHover("sclose"),
3169
+ onMouseLeave: () => setHover((h) => (h === "sclose" ? null : h)),
3170
+ children: "✕",
3171
+ }),
3172
+ ] }) : null,
2606
3173
  // 017 节点右键菜单:标题行(节点主题)+ 复制全文/复制为图片/导出为
2607
3174
  // 图片三动作 + 错误行。复用目录树菜单容器样式(fixed 定位,left/top = 视口坐标)。
2608
3175
  nodeMenu ? (0, react_jsx_runtime.jsxs)("div", {
@@ -2760,6 +3327,10 @@ window.__ModuleLoader__.load({
2760
3327
  const [exporting, setExporting] = react.useState(false);
2761
3328
  const [exportError, setExportError] = react.useState("");
2762
3329
  const [filledHint, setFilledHint] = react.useState("");
3330
+ // 032 复制全文:copying = 写剪贴板进行中;copiedOk = 成功短反馈
3331
+ //(按钮文案短暂变「已复制 ✓」约 2s;失败复用 exportError 展示位)。
3332
+ const [copying, setCopying] = react.useState(false);
3333
+ const [copiedOk, setCopiedOk] = react.useState(false);
2763
3334
  // fsTree:nodes = {path → 节点}, expanded = {path → true}, loading = {path → true}。
2764
3335
  const [fsTree, setFsTree] = react.useState({ nodes: {}, expanded: {}, loading: {}, cwd: null, error: null });
2765
3336
  // 会话切换时递增,使旧请求的异步回包不能写入新会话的目录树。
@@ -2888,6 +3459,24 @@ window.__ModuleLoader__.load({
2888
3459
  setExporting(false);
2889
3460
  }
2890
3461
  }
3462
+
3463
+ // 032 复制全文:当前脑图的 Markdown 原文写入系统剪贴板。内容直接取
3464
+ // doc.content(tree 即由它解析而来),不从树结构反向序列化——零信息
3465
+ // 损失(标题/列表/表格/原文空白原样保留),与参考实现实测路径一致。
3466
+ async function onCopyText() {
3467
+ if (!doc || doc.op === "local" || copying) return;
3468
+ setCopying(true);
3469
+ setExportError("");
3470
+ try {
3471
+ await copyPlainText(doc.content);
3472
+ setCopiedOk(true);
3473
+ setTimeout(() => setCopiedOk(false), 2000);
3474
+ } catch (error) {
3475
+ setExportError(String(error?.message ?? error));
3476
+ } finally {
3477
+ setCopying(false);
3478
+ }
3479
+ }
2891
3480
  //#region 013 目录树 tab:懒加载树 + 把指令填进聊天输入框
2892
3481
  // 草稿保护:确实读到非空草稿才让路(改走剪贴板),读不到就按既有
2893
3482
  // 行为直填直发——宿主不暴露草稿时不能把功能整个卡死。
@@ -3095,9 +3684,10 @@ window.__ModuleLoader__.load({
3095
3684
  });
3096
3685
  }
3097
3686
  function directoryLabel(name, expanded) {
3687
+ const label = treeDirLabel(name);
3098
3688
  return (0, react_jsx_runtime.jsx)("span", {
3099
3689
  style: { flex: "0 1 auto", overflow: "hidden", textOverflow: "ellipsis", minWidth: 0 },
3100
- children: variant === "sidebar" ? name : `${expanded ? "📂" : "📁"} ${name}`,
3690
+ children: variant === "sidebar" ? label : `${expanded ? "📂" : "📁"} ${label}`,
3101
3691
  });
3102
3692
  }
3103
3693
  function blockFileInteraction(event) {
@@ -3328,11 +3918,9 @@ window.__ModuleLoader__.load({
3328
3918
  style: S.treeMenuItem,
3329
3919
  onClick: () => {
3330
3920
  setTreeMenu(null);
3331
- fillDraft(treeMenu.kind === "dir"
3332
- ? `我想在 ${treeMenu.rel} 目录里创建一个 Markdown 脑图`
3333
- : "我想创建一个脑图");
3921
+ fillDraft(treeCreateDraft(treeMenu.rel));
3334
3922
  },
3335
- children: treeMenu.kind === "dir" ? "在此目录新建 Markdown 脑图" : "新建 Markdown 脑图",
3923
+ children: treeCreateLabel(treeMenu.rel),
3336
3924
  }),
3337
3925
  ],
3338
3926
  }) : null,
@@ -3359,6 +3947,16 @@ window.__ModuleLoader__.load({
3359
3947
  onClick: onExport,
3360
3948
  children: exporting ? "导出中…" : "导出图片",
3361
3949
  });
3950
+ // 032 复制全文按钮(两种模式共用):整篇 Markdown 原文写系统剪贴板,插在
3951
+ // 导出按钮左侧;disabled 语义与导出一致(无树/复制中/本地占位不可复制)。
3952
+ const copyBtn = (0, react_jsx_runtime.jsx)("button", {
3953
+ type: "button",
3954
+ style: S.action,
3955
+ disabled: !tree || copying || (doc && doc.op === "local"),
3956
+ onClick: onCopyText,
3957
+ title: "把当前脑图的 Markdown 原文复制到剪贴板",
3958
+ children: copying ? "复制中…" : copiedOk ? "已复制 ✓" : "复制全文",
3959
+ });
3362
3960
  const exportErrorSpan = exportError
3363
3961
  ? (0, react_jsx_runtime.jsx)("span", { style: { color: "var(--dsw-alias-label-error)", fontSize: "12px" }, children: exportError })
3364
3962
  : null;
@@ -3418,10 +4016,11 @@ window.__ModuleLoader__.load({
3418
4016
  }),
3419
4017
  ],
3420
4018
  }, shown) : null,
3421
- // 导出按钮 + 错误推到行尾。
4019
+ // 复制/导出按钮 + 错误推到行尾。
3422
4020
  (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
3423
4021
  approvalControls,
3424
4022
  exportErrorSpan,
4023
+ copyBtn,
3425
4024
  exportBtn,
3426
4025
  ] }),
3427
4026
  // 016:脑图视图走 MindmapCanvas(自带滚动 + 居中 + 右上角缩放控制条),
@@ -3457,6 +4056,7 @@ window.__ModuleLoader__.load({
3457
4056
  (0, react_jsx_runtime.jsxs)("div", { style: S.headerTop, children: [
3458
4057
  (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
3459
4058
  approvalControls,
4059
+ copyBtn,
3460
4060
  exportBtn,
3461
4061
  exportErrorSpan,
3462
4062
  // 关闭按钮:仅独立 fixed 壳提供 onClose(BS Tab 自带关闭)。
@@ -4308,6 +4908,11 @@ window.__ModuleLoader__.load({
4308
4908
  planGrowthReveal,
4309
4909
  relPathWithin,
4310
4910
  visibleTreeRows,
4911
+ // 036 脑图收件箱:默认目录的显示文案与新建入口(供测试)。
4912
+ DEFAULT_MINDMAP_DIR,
4913
+ treeDirLabel,
4914
+ treeCreateDraft,
4915
+ treeCreateLabel,
4311
4916
  // 025 草稿保护:宿主草稿读取面的能力探测(供测试)。
4312
4917
  readDraftText,
4313
4918
  draftBlocksAutoSend,
@@ -4316,6 +4921,11 @@ window.__ModuleLoader__.load({
4316
4921
  countDescendants,
4317
4922
  pruneCollapsed,
4318
4923
  TreeRow,
4924
+ // 035 节点搜索:命中计算 / 下标步进(环绕)/ 命中保持 / 祖先展开(供测试)。
4925
+ searchTreeMatches,
4926
+ stepMatchIndex,
4927
+ reconcileActiveMatch,
4928
+ expandAncestorsFor,
4319
4929
  // 019 皮肤层与血肉层纯函数(供测试)。
4320
4930
  resolveToken,
4321
4931
  resolveNodeStyle,
@@ -4335,6 +4945,9 @@ window.__ModuleLoader__.load({
4335
4945
  stepZoom,
4336
4946
  fitZoom,
4337
4947
  focusZoom,
4948
+ // 033 点击聚焦跳变钳制 + 保视野拉回位移(供测试)。
4949
+ clampFocusJump,
4950
+ edgePullOffsets,
4338
4951
  // 021 画布平移手势判定(供测试)。
4339
4952
  PAN,
4340
4953
  shouldStartPan,