dsh-mindmap 0.18.8 → 0.18.12

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/client.js +362 -101
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -38,6 +38,10 @@ All notable changes to this project are documented here. Release-specific notes
38
38
 
39
39
  ### Fixed
40
40
 
41
+ - Standalone mindmap panel and dsh-zterm's standalone panel no longer fight over the `#root` layout (issue #6). Both plugins now inject the same layout-push rule, so `#root` width is viewport minus mindmap, zterm and sidebar widths and insertion order no longer decides which reserved width survives. The base rule no longer declares `transition`, so zterm open/close/drag stop re-laying out the whole window at 0.3s per frame; the mindmap keeps its 0.3s open/close animation through a temporary `dsh-layout-animating` class on `<html>` (about 320ms, only on open/close, never while dragging). Each open, close, or width change dispatches `dsh:panel-layout` on `window` with `{ id: 'dsh-mindmap', width }` (pixels, `0` when closed) after the CSS variable is written; unmounting announces width `0` and removes the mindmap's own class, timer and style. The matching dsh-zterm change ships separately, and issue #6 stays open until both sides are released. Better Sidebar mode, panel visuals, the width algorithm, and the issue #4 focus-sync and portal logic are unchanged.
42
+ - Standalone panels that mount already open (for example when the panel comes back from Better Sidebar mode with its open state kept) now play the same 0.3s open animation as a manual open, instead of appearing at their final position (issue #6 follow-up). The layout's previous state starts as closed, so the first layout pass treats an open mount as one open transition; closed mounts stay silent, and dragging or window resizing still never pulses the animation.
43
+ - PNG export now fits text to its card and stops breaking English words apart. The export lays out its own SVG instead of reusing one fixed box width: every node sizes itself to its content (clamped between 72px and 380px), so a short title such as 阶段三 no longer leaves a mostly empty card while a long work item is squeezed into three cramped lines. Text width is measured with the browser's real font metrics (`canvas.measureText`, using the same font stack as the drawing) rather than a per-character guess, so each line is laid out against the card's content width and keeps its inner padding instead of hugging the card edge; environments without a canvas keep the character estimate as a fallback. Line breaking is word-aware: `Apollo`, `RabbitMQ` and `CICD` stay in one piece, Chinese still breaks per character, explicit newlines are honoured, and overlong tokens (long URLs) are still hard-broken so no text is dropped or truncated. The break decision also counts the gap that precedes it, so a line never spills into the inner padding, and the original whitespace order is preserved — leading and trailing spaces stay where the author wrote them, even when a long token is hard-broken. Nodes on the same level keep a shared left edge, so the tree still reads as aligned columns, and the canvas size/pixel safety limits, full text, tables and multi-line content stay as they were. Both 导出图片 and the node context menu's 复制图片 share this export chain, so both are fixed together.
44
+
41
45
  - Standalone panels now portal their fixed host to `document.body` instead of rendering inside the conversation header actions slot, preventing host header overflow from clipping the entire panel on DSH 0.2.2 (issue #5). Closing still keeps the workspace mounted with `display:none`; Better Sidebar tabs, layout-push behavior, resizing, and panel visuals remain unchanged.
42
46
 
43
47
  - Focus synchronization no longer oscillates between two open mindmaps (issue #4). The AI-focus baseline is now event-driven — the document last created, opened, or updated by a tool result (read-only `mindmap_get` never moves it) — instead of the creation-order tail, which stayed pinned to the newer file so the comparison could never converge. Auto-sent `mindmap_open` messages are gated three ways: at most one per document per mount, a module-level per-session memory of sent display/focus pairs that survives tab remounts and dual windows, and a hard cap of 5 automatic opens per session that stops silently with a single notice (shown in both directory and mindmap views). Restored mount state (an out-of-sync display/focus pair established by the mount-time auto-open) is no longer a trigger, so a remounted tab or a reloaded page never sends a spontaneous message, and cwd arrival after a remount only changes the message's relative-path text instead of re-arming the effect. The sync effect now depends on values (displayed document, AI focus, visibility, session) rather than snapshot object identity, so remounts and unrelated tool results no longer re-fire it. Regression tests cover the two-document idle scenario (at most one message, then convergence), remount memory survival, and the hard-cap silent stop with a one-time notice.
package/client.js CHANGED
@@ -1343,9 +1343,23 @@ window.__ModuleLoader__.load({
1343
1343
  // 布局契约不变——叶子自上而下占行、父节点垂直居中于其子块。
1344
1344
  // 导出拥有独立的 SVG 度量:13px 正文、12px 表格、18px 行高;不随画布
1345
1345
  // 的 NODE_FONT_SIZE 或 CSS zoom 改动,否则预估盒高与导出绘制会失配。
1346
+ // 039 导出版式修复(断词 / 贴边 / 疏密失衡):
1347
+ // - 度量:改用真实字体宽度(canvas measureText,与绘制同一字体串);
1348
+ // 无 canvas 的环境退回字符估算兜底。测量与绘制共用同一套宽度,
1349
+ // 文字不再贴边或溢出卡片。
1350
+ // - 折行:按词优先——英文/数字词不从中间拆开;超长词(长 URL)才逐字
1351
+ // 硬断,全量文字不缩减、不截断(003 §5.5 / §7 契约不变)。
1352
+ // - 盒宽:按内容自适应(min/max 钳制);同层左缘对齐、按层成列——
1353
+ // 短标题不再空一大块,长正文不再被挤成多行。
1346
1354
  const EXPORT = {
1347
- nodeW: 220, padX: 12, padY: 8, hGap: 48, vGap: 12, pad: 20,
1355
+ // 039 节点宽度按内容自适应:短标题收窄、长正文放宽。
1356
+ minNodeW: 72,
1357
+ maxNodeW: 380,
1358
+ padX: 12, padY: 8, hGap: 48, vGap: 12, pad: 20,
1348
1359
  fontSize: 13, lineHeight: 18,
1360
+ // 测量与绘制共用同一字体串:估宽与实际字形一致。
1361
+ fontFamily: "-apple-system, 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', sans-serif",
1362
+ monoFamily: "Menlo, Consolas, 'Courier New', monospace",
1349
1363
  tableCellW: 110, tableCellPad: 8, tableMinW: 140, tableMaxW: 480,
1350
1364
  // 单元格折行宽下限 = 导出字号 12px 的全角宽:极宽表(如 60 列)
1351
1365
  // 列盒窄于内距时 cellInner 可能为负,钳到至少容纳一个全角字符;
@@ -1378,29 +1392,178 @@ window.__ModuleLoader__.load({
1378
1392
  .replace(/\*([^*\n]+)\*/g, "$1");
1379
1393
  }
1380
1394
 
1381
- /** 字符宽度估算:CJK 按一个字号宽,其余按 0.55 折算。 */
1395
+ /** 导出字体串:测量(canvas)与绘制(SVG)共用,字宽与字形一致。 */
1396
+ function exportFontSpec(fontSize, weight, mono) {
1397
+ return `${weight} ${fontSize}px ${mono ? EXPORT.monoFamily : EXPORT.fontFamily}`;
1398
+ }
1399
+
1400
+ let exportMeasureCtx;
1401
+ let exportMeasureReady = false;
1402
+
1403
+ /** 惰性取 canvas 2d 上下文:有则用真实字形度量,没有则走字符估算兜底。 */
1404
+ function exportMeasureContext() {
1405
+ if (!exportMeasureReady) {
1406
+ exportMeasureReady = true;
1407
+ try {
1408
+ if (typeof document !== "undefined" && document && typeof document.createElement === "function") {
1409
+ const canvas = document.createElement("canvas");
1410
+ const ctx = canvas && typeof canvas.getContext === "function" ? canvas.getContext("2d") : null;
1411
+ if (ctx && typeof ctx.measureText === "function") exportMeasureCtx = ctx;
1412
+ }
1413
+ } catch (error) {
1414
+ // 度量不可用不是致命错误:退回字符估算,导出照常出图。
1415
+ }
1416
+ }
1417
+ return exportMeasureCtx;
1418
+ }
1419
+
1420
+ /** 字符宽度估算(无 canvas 时的兜底):CJK 按一个字号宽,其余按 0.55 折算。 */
1382
1421
  function charW(ch, fontSize) {
1383
1422
  return ch.charCodeAt(0) > 0x2e7f ? fontSize : fontSize * 0.55;
1384
1423
  }
1385
1424
 
1386
- /** 按可用宽度贪心折行(尊重显式换行;长串硬折——长 URL 完整呈现不截断)。 */
1387
- function wrapExportText(text, maxWidth, fontSize) {
1425
+ function estimateExportText(text, fontSize, mono) {
1426
+ const s = String(text ?? "");
1427
+ if (mono) return [...s].length * fontSize * 0.6;
1428
+ let w = 0;
1429
+ for (const ch of s) w += charW(ch, fontSize);
1430
+ return w;
1431
+ }
1432
+
1433
+ /** 文字宽度:浏览器走真实字形,其余走估算兜底。 */
1434
+ function measureExportText(text, fontSize, weight = 400, mono = false) {
1435
+ const ctx = exportMeasureContext();
1436
+ if (ctx) {
1437
+ try {
1438
+ ctx.font = exportFontSpec(fontSize, weight, mono);
1439
+ return ctx.measureText(String(text ?? "")).width;
1440
+ } catch (error) {
1441
+ // 落回字符估算。
1442
+ }
1443
+ }
1444
+ return estimateExportText(text, fontSize, mono);
1445
+ }
1446
+
1447
+ const EXPORT_WORD_CHAR = /[0-9A-Za-z]/;
1448
+ const EXPORT_WORD_JOIN = /[-_.+/#@&']/;
1449
+
1450
+ /**
1451
+ * 039 折行原子:CJK 逐字可断;拉丁/数字词整体不可断(不从中间拆词);
1452
+ * 空白单独成块(行尾空白保留在行末,渲染时被折叠、字符不丢)。
1453
+ */
1454
+ function exportAtoms(segment) {
1455
+ const chars = [...String(segment ?? "")];
1456
+ const atoms = [];
1457
+ let i = 0;
1458
+ while (i < chars.length) {
1459
+ const ch = chars[i];
1460
+ if (ch === " " || ch === "\t") {
1461
+ atoms.push({ text: ch, space: true });
1462
+ i += 1;
1463
+ continue;
1464
+ }
1465
+ if (ch.charCodeAt(0) > 0x2e7f) {
1466
+ atoms.push({ text: ch, space: false });
1467
+ i += 1;
1468
+ continue;
1469
+ }
1470
+ if (EXPORT_WORD_CHAR.test(ch)) {
1471
+ let j = i + 1;
1472
+ while (j < chars.length) {
1473
+ const c = chars[j];
1474
+ if (EXPORT_WORD_CHAR.test(c)) { j += 1; continue; }
1475
+ // 词内连接符(- _ . / # + @ & ')跟随后面的词字符一起算一个词。
1476
+ if (EXPORT_WORD_JOIN.test(c) && j + 1 < chars.length && EXPORT_WORD_CHAR.test(chars[j + 1])) { j += 1; continue; }
1477
+ break;
1478
+ }
1479
+ atoms.push({ text: chars.slice(i, j).join(""), space: false });
1480
+ i = j;
1481
+ continue;
1482
+ }
1483
+ atoms.push({ text: ch, space: false });
1484
+ i += 1;
1485
+ }
1486
+ return atoms;
1487
+ }
1488
+
1489
+ /**
1490
+ * 按可用宽度折行(尊重显式换行;优先按词断行,英文词不从中间拆开;
1491
+ * 超长词/长 URL 才逐字硬断——长串完整呈现不截断)。
1492
+ *
1493
+ * 空白契约(039 复查修正):
1494
+ * - 原文顺序不变:行首空白留在行首、行尾空白留在行末,中间空白留在词间;
1495
+ * 逐行拼回恒等于原文(字符一个不丢、不搬家)。
1496
+ * - 断行决策必须把「即将插入的空白」算进去:词本身放得下、连同词间空白
1497
+ * 放不下时照样要断,否则这一行会顶破内容区、吃掉右内距。
1498
+ * - 宽度口径与渲染一致:行首空白渲染时被裁掉、不占宽度;词间空白在行内
1499
+ * 可见,按实宽计入(保守,宁可早断不越界)。
1500
+ */
1501
+ function wrapExportText(text, maxWidth, fontSize, options = {}) {
1502
+ const weight = options.weight || 400;
1503
+ const mono = options.mono === true;
1504
+ const measure = (value) => measureExportText(value, fontSize, weight, mono);
1388
1505
  const lines = [];
1389
1506
  for (const segment of String(text ?? "").split("\n")) {
1390
- let cur = "";
1391
- let w = 0;
1392
- for (const ch of segment) {
1393
- const cw = charW(ch, fontSize);
1394
- if (w + cw > maxWidth && cur) {
1395
- lines.push(cur);
1396
- cur = ch;
1397
- w = cw;
1398
- } else {
1399
- cur += ch;
1400
- w += cw;
1507
+ const atoms = exportAtoms(segment);
1508
+ let cur = ""; // 本行已定稿的文字(不含行首空白)
1509
+ let curW = 0; // 本行宽度(不含行首空白)
1510
+ let lead = ""; // 行首空白:渲染时被裁掉,不占宽度
1511
+ let pending = ""; // 词间空白:尚未插入下一个词
1512
+ let pendingW = 0;
1513
+ const flush = () => {
1514
+ lines.push(lead + cur + pending);
1515
+ cur = "";
1516
+ curW = 0;
1517
+ lead = "";
1518
+ pending = "";
1519
+ pendingW = 0;
1520
+ };
1521
+ for (const atom of atoms) {
1522
+ if (atom.space) {
1523
+ if (cur) {
1524
+ pending += atom.text;
1525
+ pendingW += measure(atom.text);
1526
+ } else {
1527
+ lead += atom.text;
1528
+ }
1529
+ continue;
1530
+ }
1531
+ const aw = measure(atom.text);
1532
+ // 断行决策要算上即将插入的词间空白。
1533
+ if (cur && curW + pendingW + aw > maxWidth) flush();
1534
+ if (!cur && aw > maxWidth) {
1535
+ // 超长词(长 URL 等):逐字硬断,字符一个不丢。
1536
+ // 先于该词的空白属于第一片(保持原文顺序)。
1537
+ const pieces = [];
1538
+ let piece = "";
1539
+ let pieceW = 0;
1540
+ for (const ch of atom.text) {
1541
+ const cw = measure(ch);
1542
+ if (pieceW > 0 && pieceW + cw > maxWidth) {
1543
+ pieces.push(piece);
1544
+ piece = "";
1545
+ pieceW = 0;
1546
+ }
1547
+ piece += ch;
1548
+ pieceW += cw;
1549
+ }
1550
+ if (piece) pieces.push(piece);
1551
+ for (let i = 0; i < pieces.length - 1; i += 1) {
1552
+ lines.push(i === 0 ? lead + pieces[0] : pieces[i]);
1553
+ }
1554
+ cur = pieces.length ? pieces[pieces.length - 1] : "";
1555
+ curW = measure(cur);
1556
+ lead = "";
1557
+ pending = "";
1558
+ pendingW = 0;
1559
+ continue;
1401
1560
  }
1561
+ cur += pending + atom.text;
1562
+ curW += pendingW + aw;
1563
+ pending = "";
1564
+ pendingW = 0;
1402
1565
  }
1403
- lines.push(cur);
1566
+ lines.push(lead + cur + pending);
1404
1567
  }
1405
1568
  return lines.length > 0 ? lines : [""];
1406
1569
  }
@@ -1417,120 +1580,167 @@ window.__ModuleLoader__.load({
1417
1580
  return { text: stripInlineForExport(node.topic), lines: null };
1418
1581
  }
1419
1582
 
1420
- /** 019 盒尺寸估算:文本按折行行数生长;表格按行列数算网格尺寸。
1583
+ /** 039 导出字形样式:字重/等宽与绘制一致,测量必须按同一套样式算宽度。 */
1584
+ function exportTextStyle(node, isRoot) {
1585
+ return {
1586
+ weight: isRoot ? 700 : node.kind === "heading" ? 600 : 400,
1587
+ mono: node.kind === "code",
1588
+ };
1589
+ }
1590
+
1591
+ /**
1592
+ * 019/039 盒尺寸:宽度按内容自适应(短标题收窄、长正文放宽),
1593
+ * 文本按该宽度折行后定高。
1421
1594
  * 022:测量与渲染必须共用钳制后的列宽——先算盒宽再按 w/cols 折行,
1422
- * 否则宽表(钳到 tableMaxW)按 110px 估行、渲染按更窄列宽折行,盒高不足。 */
1423
- function measureExportBox(node) {
1595
+ * 否则宽表(钳到 tableMaxW)按 110px 估行、渲染按更窄列宽折行,盒高不足。
1596
+ */
1597
+ function exportBoxSize(node, options = {}) {
1598
+ const style = exportTextStyle(node, options.root === true);
1424
1599
  if (node.kind === "table") {
1425
1600
  const rows = (node.data && node.data.rows) || [];
1426
1601
  const cols = rows.reduce((mx, row) => Math.max(mx, row.length), 0) || 1;
1427
1602
  const w = Math.min(EXPORT.tableMaxW, Math.max(EXPORT.tableMinW, cols * EXPORT.tableCellW));
1428
1603
  const cellInner = Math.max(w / cols - EXPORT.tableCellPad * 2, EXPORT.tableCellMinInner);
1429
- const rowLines = rows.map((row) => row.reduce((mx, cell) => Math.max(mx, wrapExportText(stripInlineForExport(cell), cellInner, EXPORT.fontSize - 1).length), 1));
1430
- const h = Math.max(EXPORT.lineHeight, rowLines.reduce((a, b) => a + b, 0) * EXPORT.lineHeight);
1431
- return { w, h };
1604
+ const cellLines = rows.map((row, ri) => row.map((cell) => wrapExportText(stripInlineForExport(cell), cellInner, EXPORT.fontSize - 1, { weight: ri === 0 ? 600 : 400 })));
1605
+ const rowH = cellLines.map((cells) => Math.max(1, ...cells.map((lines) => lines.length)) * EXPORT.lineHeight);
1606
+ const h = Math.max(EXPORT.lineHeight, rowH.reduce((a, b) => a + b, 0));
1607
+ return { w, h, style, table: { rows, cols, cellInner, cellLines, rowH } };
1432
1608
  }
1433
- const text = exportBlock(node).text;
1434
- const inner = EXPORT.nodeW - EXPORT.padX * 2;
1435
- const lines = node.kind === "code" ? [text] : wrapExportText(text, inner, EXPORT.fontSize);
1436
- return { w: EXPORT.nodeW, h: EXPORT.padY * 2 + lines.length * EXPORT.lineHeight };
1609
+ const label = node.kind === "placeholder" ? "待填写" : exportBlock(node).text;
1610
+ const widest = Math.max(0, ...String(label).split("\n").map((line) => measureExportText(line, EXPORT.fontSize, style.weight, style.mono)));
1611
+ // 左右内距 + 引用块的竖条;+2 是测量与光栅化的安全余量。
1612
+ const chrome = EXPORT.padX * 2 + (node.kind === "quote" ? 3 : 0);
1613
+ const w = Math.min(EXPORT.maxNodeW, Math.max(EXPORT.minNodeW, Math.ceil(widest) + chrome + 2));
1614
+ const inner = w - chrome;
1615
+ const lines = wrapExportText(label, inner, EXPORT.fontSize, { weight: style.weight, mono: style.mono });
1616
+ return { w, h: EXPORT.padY * 2 + lines.length * EXPORT.lineHeight, style, lines };
1617
+ }
1618
+
1619
+ /** 019 盒尺寸估算(对外只暴露尺寸,测量与渲染同源)。 */
1620
+ function measureExportBox(node, options = {}) {
1621
+ const size = exportBoxSize(node, options);
1622
+ return { w: size.w, h: size.h };
1623
+ }
1624
+
1625
+ /** 导出节点条目:一次算好样式、盒尺寸与子树,后续布局/绘制共用。 */
1626
+ function exportEntryOf(node, depth, parent) {
1627
+ const size = exportBoxSize(node, { root: depth === 0 });
1628
+ const entry = {
1629
+ node,
1630
+ depth,
1631
+ parent,
1632
+ style: size.style,
1633
+ table: size.table,
1634
+ lines: size.lines,
1635
+ text: node.kind === "placeholder" ? "待填写" : exportBlock(node).text,
1636
+ w: size.w,
1637
+ h: size.h,
1638
+ children: [],
1639
+ };
1640
+ entry.children = (node.children || []).map((child) => exportEntryOf(child, depth + 1, entry));
1641
+ return entry;
1437
1642
  }
1438
1643
 
1439
1644
  /**
1440
- * 布局 + 生成导出用 SVG 字符串。左→右分层:x = 父盒右缘 + 间距(可变盒宽),
1441
- * 叶子自上而下占行,父节点垂直居中于其子块;连线为水平贝塞尔。
1645
+ * 布局 + 生成导出用 SVG 字符串。左→右分层:同层节点左缘对齐成列
1646
+ * (列位由层号决定,盒宽仍按内容自适应),叶子自上而下占行,
1647
+ * 父节点垂直居中于其子块;连线为水平贝塞尔。
1442
1648
  * 019:盒高随内容生长(表格/引用画专属形态);色值取主题静态亮色快照
1443
1649
  *(导出 SVG 走 data-URL,宿主 CSS 变量不可用)。
1444
1650
  */
1445
1651
  function buildExportSvg(tree, themeName) {
1446
1652
  const palette = exportPalette(themeName);
1447
- const placed = [];
1448
- const edges = [];
1449
- let cursor = EXPORT.pad;
1450
- const place = (node, parentEntry) => {
1451
- const size = measureExportBox(node);
1452
- const entry = {
1453
- node,
1454
- size,
1455
- x: parentEntry ? parentEntry.x + parentEntry.size.w + EXPORT.hGap : EXPORT.pad,
1456
- y: 0,
1457
- };
1458
- placed.push(entry);
1459
- if (parentEntry) edges.push({ from: parentEntry, to: entry });
1460
- if (node.children && node.children.length > 0) {
1461
- let first = null;
1462
- let last = null;
1463
- for (const child of node.children) {
1464
- const childEntry = place(child, entry);
1465
- if (!first) first = childEntry;
1466
- last = childEntry;
1467
- }
1468
- entry.y = (first.y + last.y) / 2;
1469
- } else {
1470
- entry.y = cursor + size.h / 2;
1471
- cursor += size.h + EXPORT.vGap;
1653
+ const entries = [];
1654
+ const root = exportEntryOf(tree, 0, null);
1655
+ const collect = (entry) => {
1656
+ entries.push(entry);
1657
+ for (const child of entry.children) collect(child);
1658
+ };
1659
+ collect(root);
1660
+ // 列宽:同层取最宽者;列位由层号决定——各层左缘对齐,盒宽可各不相同。
1661
+ const colW = [];
1662
+ for (const entry of entries) colW[entry.depth] = Math.max(colW[entry.depth] || 0, entry.w);
1663
+ const colX = [];
1664
+ let cursorX = EXPORT.pad;
1665
+ for (let depth = 0; depth < colW.length; depth += 1) {
1666
+ colX[depth] = cursorX;
1667
+ cursorX += colW[depth] + EXPORT.hGap;
1668
+ }
1669
+ // 高度:自底向上算块高(子块叠放 + 间距);父盒比子块高时以父盒为准。
1670
+ const computeBlock = (entry) => {
1671
+ let stack = 0;
1672
+ for (const child of entry.children) stack += computeBlock(child);
1673
+ if (entry.children.length) stack += EXPORT.vGap * (entry.children.length - 1);
1674
+ entry.stackH = stack;
1675
+ entry.blockH = Math.max(stack, entry.h);
1676
+ return entry.blockH;
1677
+ };
1678
+ computeBlock(root);
1679
+ // 放置:自顶向下分块顶,节点竖直居中于自己的块。
1680
+ const place = (entry, blockTop) => {
1681
+ entry.x = colX[entry.depth];
1682
+ entry.y = blockTop + entry.blockH / 2;
1683
+ if (!entry.children.length) return;
1684
+ const offset = (entry.blockH - entry.stackH) / 2;
1685
+ let top = blockTop + offset;
1686
+ for (const child of entry.children) {
1687
+ place(child, top);
1688
+ top += child.blockH + EXPORT.vGap;
1472
1689
  }
1473
- return entry;
1474
1690
  };
1475
- place(tree, null);
1476
- const width = placed.reduce((mx, p) => Math.max(mx, p.x + p.size.w), 0) + EXPORT.pad;
1477
- const height = Math.max(EXPORT.pad * 2 + EXPORT.lineHeight, cursor - EXPORT.vGap + EXPORT.pad);
1691
+ place(root, EXPORT.pad);
1692
+ const width = colX[colX.length - 1] + colW[colW.length - 1] + EXPORT.pad;
1693
+ const height = root.blockH + EXPORT.pad * 2;
1478
1694
  const parts = [];
1479
- parts.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" font-family="-apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif">`);
1695
+ parts.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" font-family="${EXPORT.fontFamily}">`);
1480
1696
  parts.push(`<rect x="0" y="0" width="${width}" height="${height}" fill="${palette.canvasBg}"/>`);
1481
- for (const e of edges) {
1482
- const x1 = e.from.x + e.from.size.w;
1483
- const y1 = e.from.y;
1484
- const x2 = e.to.x;
1485
- const y2 = e.to.y;
1697
+ for (const entry of entries) {
1698
+ if (!entry.parent) continue;
1699
+ const x1 = entry.parent.x + entry.parent.w;
1700
+ const y1 = entry.parent.y;
1701
+ const x2 = entry.x;
1702
+ const y2 = entry.y;
1486
1703
  const mid = (x1 + x2) / 2;
1487
1704
  parts.push(`<path d="M ${x1} ${y1} C ${mid} ${y1}, ${mid} ${y2}, ${x2} ${y2}" fill="none" stroke="${palette.connector}" stroke-width="1.5"/>`);
1488
1705
  }
1489
- for (const p of placed) {
1490
- const node = p.node;
1706
+ for (const entry of entries) {
1707
+ const node = entry.node;
1491
1708
  const kind = node.kind;
1492
- const isRoot = !edges.some((e) => e.to === p);
1709
+ const isRoot = entry.depth === 0;
1493
1710
  const isPlaceholder = kind === "placeholder";
1494
1711
  const isCode = kind === "code";
1495
1712
  const isQuote = kind === "quote";
1496
1713
  const isTable = kind === "table";
1497
- const boxY = p.y - p.size.h / 2;
1714
+ const boxY = entry.y - entry.h / 2;
1498
1715
  const fill = isRoot ? palette.rootBg : isCode ? palette.surfaceCode : palette.surface;
1499
- parts.push(`<rect x="${p.x}" y="${boxY}" width="${p.size.w}" height="${p.size.h}" rx="7" fill="${isPlaceholder ? "none" : fill}" stroke="${isRoot ? palette.rootBorder : isPlaceholder ? palette.border : palette.border}" stroke-width="${isRoot ? 1.6 : 1}"${isPlaceholder ? ' stroke-dasharray="5,4"' : ""}/>`);
1716
+ parts.push(`<rect x="${entry.x}" y="${boxY}" width="${entry.w}" height="${entry.h}" rx="7" fill="${isPlaceholder ? "none" : fill}" stroke="${isRoot ? palette.rootBorder : palette.border}" stroke-width="${isRoot ? 1.6 : 1}"${isPlaceholder ? ' stroke-dasharray="5,4"' : ""}/>`);
1500
1717
  if (isQuote) {
1501
- parts.push(`<rect x="${p.x}" y="${boxY}" width="3" height="${p.size.h}" fill="${palette.quote}"/>`);
1718
+ parts.push(`<rect x="${entry.x}" y="${boxY}" width="3" height="${entry.h}" fill="${palette.quote}"/>`);
1502
1719
  }
1503
1720
  if (isTable) {
1504
1721
  // 表格块:完整网格(全量行列、单元格换行、不缩减,003 §5.5)。
1505
- const rows = (node.data && node.data.rows) || [];
1506
- const cols = rows.reduce((mx, row) => Math.max(mx, row.length), 0) || 1;
1507
- const colW = p.size.w / cols;
1508
- const innerW = Math.max(colW - EXPORT.tableCellPad * 2, EXPORT.tableCellMinInner);
1509
- const rowLines = rows.map((row) => row.reduce((mx, cell) => Math.max(mx, wrapExportText(stripInlineForExport(cell), innerW, EXPORT.fontSize - 1).length), 1));
1510
- const rowH = rowLines.map((n) => n * EXPORT.lineHeight);
1722
+ const table = entry.table;
1723
+ const cellBoxW = entry.w / table.cols;
1511
1724
  let ry = boxY;
1512
- rows.forEach((row, ri) => {
1725
+ table.rows.forEach((row, ri) => {
1513
1726
  row.forEach((cell, ci) => {
1514
- const cx = p.x + ci * colW;
1515
- parts.push(`<rect x="${cx}" y="${ry}" width="${colW}" height="${rowH[ri]}" fill="${ri === 0 ? palette.surfaceCode : "none"}" stroke="${palette.borderSubtle}" stroke-width="1"/>`);
1516
- const cellLines = wrapExportText(stripInlineForExport(cell), innerW, EXPORT.fontSize - 1);
1517
- cellLines.forEach((ln, li) => {
1727
+ const cx = entry.x + ci * cellBoxW;
1728
+ parts.push(`<rect x="${cx}" y="${ry}" width="${cellBoxW}" height="${table.rowH[ri]}" fill="${ri === 0 ? palette.surfaceCode : "none"}" stroke="${palette.borderSubtle}" stroke-width="1"/>`);
1729
+ table.cellLines[ri][ci].forEach((ln, li) => {
1518
1730
  const ty = ry + (li + 0.5) * EXPORT.lineHeight + (EXPORT.fontSize - 1) * 0.35;
1519
1731
  parts.push(`<text x="${cx + EXPORT.tableCellPad}" y="${ty.toFixed(1)}" font-size="${EXPORT.fontSize - 1}" font-weight="${ri === 0 ? 600 : 400}" fill="${palette.text}">${escapeXml(ln)}</text>`);
1520
1732
  });
1521
1733
  });
1522
- ry += rowH[ri];
1734
+ ry += table.rowH[ri];
1523
1735
  });
1524
1736
  continue;
1525
1737
  }
1526
- const label = isPlaceholder ? "待填写" : exportBlock(node).text;
1527
1738
  const color = isPlaceholder ? palette.muted : isRoot ? palette.rootText : kind === "heading" ? palette.heading : palette.text;
1528
- const weight = isRoot ? 700 : kind === "heading" ? 600 : 400;
1529
- const inner = p.size.w - EXPORT.padX * 2 - (isQuote ? 3 : 0);
1530
- const lines = isCode ? [label] : wrapExportText(label, inner, EXPORT.fontSize);
1531
- const startY = p.y - (lines.length - 1) * EXPORT.lineHeight / 2 + EXPORT.fontSize * 0.35;
1739
+ const lines = entry.lines;
1740
+ const textX = entry.x + EXPORT.padX + (isQuote ? 3 : 0);
1741
+ const startY = entry.y - (lines.length - 1) * EXPORT.lineHeight / 2 + EXPORT.fontSize * 0.35;
1532
1742
  lines.forEach((ln, li) => {
1533
- parts.push(`<text x="${p.x + EXPORT.padX + (isQuote ? 3 : 0)}" y="${(startY + li * EXPORT.lineHeight).toFixed(1)}" font-size="${EXPORT.fontSize}" font-weight="${weight}" font-family="${isCode ? "Menlo, monospace" : "inherit"}" fill="${color}">${escapeXml(ln)}</text>`);
1743
+ parts.push(`<text x="${textX}" y="${(startY + li * EXPORT.lineHeight).toFixed(1)}" font-size="${EXPORT.fontSize}" font-weight="${entry.style.weight}" font-family="${isCode ? EXPORT.monoFamily : EXPORT.fontFamily}" fill="${color}">${escapeXml(ln)}</text>`);
1534
1744
  });
1535
1745
  }
1536
1746
  parts.push("</svg>");
@@ -4748,17 +4958,31 @@ window.__ModuleLoader__.load({
4748
4958
  // 014 布局让位:面板打开/拖宽时把宽度写进 CSS 变量,挤窄 #root 推走
4749
4959
  // 聊天区(better-sidebar 同款);关闭/卸载时移除变量恢复全宽。
4750
4960
  // 仅独立壳模式启用——BS Tab 模式不渲染本组件,不写此变量。
4961
+ // issue #6(共享契约 L2/L3):写入/移除之后派发 dsh:panel-layout;只有 open
4962
+ // 切换才挂动画临时类——拖宽是逐帧跟随,动画会拖尾。
4963
+ // 上一次布局状态的初值取「关闭」:挂载前 #root 既无宽度变量也无动画类,所以
4964
+ // 首次挂载即打开也按一次开切换处理,播放一次开合动画(挂载即关不播放)。
4965
+ const layoutOpenRef = react.useRef(false);
4751
4966
  react.useLayoutEffect(() => {
4752
4967
  if (typeof document === "undefined") return;
4968
+ const toggled = layoutOpenRef.current !== open;
4969
+ layoutOpenRef.current = open;
4753
4970
  if (open) {
4754
4971
  document.documentElement.style.setProperty("--dsh-mindmap-width", `${panelWidth}px`);
4755
4972
  } else {
4756
4973
  document.documentElement.style.removeProperty("--dsh-mindmap-width");
4757
4974
  }
4975
+ if (toggled) pulseLayoutAnimating();
4976
+ dispatchPanelLayout(open ? panelWidth : 0);
4758
4977
  return () => {
4759
4978
  document.documentElement.style.removeProperty("--dsh-mindmap-width");
4760
4979
  };
4761
4980
  }, [open, panelWidth]);
4981
+ // issue #6 L5:卸载时清掉自己的动画类与计时器,并派发宽度 0(面板已不占位)。
4982
+ react.useLayoutEffect(() => () => {
4983
+ clearLayoutAnimating();
4984
+ dispatchPanelLayout(0);
4985
+ }, []);
4762
4986
 
4763
4987
  // 始终挂载 MindmapWorkspace:收起时用 display:none 隐藏外壳,
4764
4988
  // 但组件实例保留——hooks(auto-open / 焦点同步 / 目录树)照常跑。
@@ -5169,6 +5393,55 @@ window.__ModuleLoader__.load({
5169
5393
  return url.href;
5170
5394
  }
5171
5395
 
5396
+ /**
5397
+ * layout-push 规则(issue #6,共享契约 L1):与 zterm 逐字相同。两个插件都按
5398
+ * 视口 − 脑图 − zterm − sidebar 计算 #root,公式一致,插入顺序不再决定谁的预留
5399
+ * 宽度生效。基础块不得声明 transition;动画只属于「自己改宽度」的一方,由下方
5400
+ * html.dsh-layout-animating 临时类开启(L2)。
5401
+ */
5402
+ const LAYOUT_PUSH_CSS = [
5403
+ "#root{",
5404
+ " margin-right:calc(var(--dsh-mindmap-width,0px) + var(--dsh-zterm-width,0px) + var(--dsh-sidebar-width,0px))!important;",
5405
+ " width:calc(100% - var(--dsh-mindmap-width,0px) - var(--dsh-zterm-width,0px) - var(--dsh-sidebar-width,0px))!important;",
5406
+ "}",
5407
+ "html.dsh-layout-animating #root{transition:margin-right .3s ease-in-out,width .3s ease-in-out}",
5408
+ ].join("\n");
5409
+
5410
+ /**
5411
+ * 布局动画临时类(issue #6,L2):仅面板一键开/关时挂到 <html>,约 320ms 后
5412
+ * 移除,重复触发重置计时。拖宽与窗口 resize 不挂(逐帧跟随时动画会拖尾)。
5413
+ */
5414
+ const LAYOUT_ANIMATING_CLASS = "dsh-layout-animating";
5415
+ const LAYOUT_ANIMATING_MS = 320;
5416
+ let layoutAnimatingTimer = null;
5417
+ function pulseLayoutAnimating() {
5418
+ if (typeof document === "undefined") return;
5419
+ const root = document.documentElement;
5420
+ root.classList.add(LAYOUT_ANIMATING_CLASS);
5421
+ if (layoutAnimatingTimer !== null) clearTimeout(layoutAnimatingTimer);
5422
+ layoutAnimatingTimer = setTimeout(() => {
5423
+ layoutAnimatingTimer = null;
5424
+ root.classList.remove(LAYOUT_ANIMATING_CLASS);
5425
+ }, LAYOUT_ANIMATING_MS);
5426
+ }
5427
+ function clearLayoutAnimating() {
5428
+ if (layoutAnimatingTimer !== null) {
5429
+ clearTimeout(layoutAnimatingTimer);
5430
+ layoutAnimatingTimer = null;
5431
+ }
5432
+ if (typeof document !== "undefined") document.documentElement.classList.remove(LAYOUT_ANIMATING_CLASS);
5433
+ }
5434
+
5435
+ /**
5436
+ * 布局变更事件(issue #6,L3):面板 open/close/resize 后派发到 window,
5437
+ * detail = { id: "dsh-mindmap", width },width 为像素数,关闭为 0。zterm 据此
5438
+ * 收起自己的独立面板,替代其 MutationObserver 轮询。
5439
+ */
5440
+ function dispatchPanelLayout(width) {
5441
+ if (typeof window === "undefined") return;
5442
+ window.dispatchEvent(new CustomEvent("dsh:panel-layout", { detail: { id: "dsh-mindmap", width } }));
5443
+ }
5444
+
5172
5445
  function apply(ctx) {
5173
5446
  const face = {};
5174
5447
 
@@ -5266,13 +5539,7 @@ window.__ModuleLoader__.load({
5266
5539
  if (!layoutStyle) {
5267
5540
  layoutStyle = document.createElement("style");
5268
5541
  layoutStyle.setAttribute("data-dsh-mindmap", "layout-push");
5269
- layoutStyle.textContent = [
5270
- "#root{",
5271
- "margin-right:calc(var(--dsh-mindmap-width,0px) + var(--dsh-sidebar-width,0px))!important;",
5272
- "width:calc(100% - var(--dsh-mindmap-width,0px) - var(--dsh-sidebar-width,0px))!important;",
5273
- "transition:margin-right var(--ds-transition-duration-slow) var(--ds-ease-in-out),width var(--ds-transition-duration-slow) var(--ds-ease-in-out);",
5274
- "}",
5275
- ].join("");
5542
+ layoutStyle.textContent = LAYOUT_PUSH_CSS;
5276
5543
  document.head.appendChild(layoutStyle);
5277
5544
  }
5278
5545
  }
@@ -5288,13 +5555,7 @@ window.__ModuleLoader__.load({
5288
5555
  // ctx.effect 不可用:直接注入(015 原始行为),standalone 模式。
5289
5556
  const style = document.createElement("style");
5290
5557
  style.setAttribute("data-dsh-mindmap", "layout-push");
5291
- style.textContent = [
5292
- "#root{",
5293
- "margin-right:calc(var(--dsh-mindmap-width,0px) + var(--dsh-sidebar-width,0px))!important;",
5294
- "width:calc(100% - var(--dsh-mindmap-width,0px) - var(--dsh-sidebar-width,0px))!important;",
5295
- "transition:margin-right var(--ds-transition-duration-slow) var(--ds-ease-in-out),width var(--ds-transition-duration-slow) var(--ds-ease-in-out);",
5296
- "}",
5297
- ].join("");
5558
+ style.textContent = LAYOUT_PUSH_CSS;
5298
5559
  document.head.appendChild(style);
5299
5560
  }
5300
5561
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mindmap",
3
- "version": "0.18.8",
3
+ "version": "0.18.12",
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",