dsh-mindmap 0.18.8 → 0.18.9
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 +2 -0
- package/client.js +297 -87
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -38,6 +38,8 @@ All notable changes to this project are documented here. Release-specific notes
|
|
|
38
38
|
|
|
39
39
|
### Fixed
|
|
40
40
|
|
|
41
|
+
- 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.
|
|
42
|
+
|
|
41
43
|
- 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
44
|
|
|
43
45
|
- 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
|
-
|
|
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
|
-
/**
|
|
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
|
-
|
|
1387
|
-
|
|
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
|
-
|
|
1391
|
-
let
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
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;
|
|
1401
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;
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
|
1430
|
-
const
|
|
1431
|
-
|
|
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
|
|
1434
|
-
const
|
|
1435
|
-
|
|
1436
|
-
|
|
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
|
|
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
|
|
1448
|
-
const
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
const
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
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(
|
|
1476
|
-
const width =
|
|
1477
|
-
const height =
|
|
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="
|
|
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
|
|
1482
|
-
|
|
1483
|
-
const
|
|
1484
|
-
const
|
|
1485
|
-
const
|
|
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
|
|
1490
|
-
const node =
|
|
1706
|
+
for (const entry of entries) {
|
|
1707
|
+
const node = entry.node;
|
|
1491
1708
|
const kind = node.kind;
|
|
1492
|
-
const isRoot =
|
|
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 =
|
|
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="${
|
|
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="${
|
|
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
|
|
1506
|
-
const
|
|
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 =
|
|
1515
|
-
parts.push(`<rect x="${cx}" y="${ry}" width="${
|
|
1516
|
-
|
|
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
|
|
1529
|
-
const
|
|
1530
|
-
const
|
|
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="${
|
|
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>");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mindmap",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.9",
|
|
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",
|