cladogram 0.3.1 → 0.5.2
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/README.md +57 -365
- package/bin/clado.js +126 -72
- package/package.json +11 -8
- package/skills/clado/SKILL.md +123 -747
- package/src/core/links.js +37 -0
- package/src/core/media-links.js +99 -0
- package/src/core/parse.js +81 -82
- package/src/html/app-css.js +51 -75
- package/src/html/canvas-card.js +65 -0
- package/src/html/canvas-chain.js +231 -0
- package/src/html/canvas-focus.js +175 -0
- package/src/html/canvas-ui.css +38 -0
- package/src/html/canvas-ui.js +40 -0
- package/src/html/canvas-wires.js +73 -0
- package/src/html/media-anchors.js +212 -0
- package/src/html/mindmap-connectors.js +78 -0
- package/src/html/mindmap-media.js +39 -0
- package/src/html/page.js +23 -4
- package/src/html/runtime-api.js +51 -0
- package/src/html/runtime-fixes.js +32 -0
- package/src/html/runtime.js +322 -272
- package/src/server/assets/library-canvas.js +96 -0
- package/src/server/assets/library.css +9 -0
- package/src/server/assets/library.html +20 -0
- package/src/server/assets/library.js +127 -0
- package/src/server/assets/tree.js +26 -0
- package/src/server/export.js +53 -0
- package/src/server/mcp.js +108 -0
- package/src/server/workspace.js +84 -0
- package/src/skill/install.js +16 -18
- package/src/skill/targets.js +28 -12
- package/src/skill/templates.js +60 -0
- package/src/util/version.js +3 -0
- package/src/workspace/content.js +72 -0
- package/src/workspace/documents.js +65 -0
- package/src/workspace/references.js +101 -0
- package/src/workspace/service.js +457 -0
- package/src/workspace/storage.js +169 -0
- package/src/workspace/tree.js +66 -0
- package/templates/business-flow.mdc +29 -0
- package/templates/call-chain.mdc +62 -0
- package/templates/data-design.mdc +35 -0
- package/templates/mind-expansion.mdc +52 -0
- package/templates/requirement-overview.mdc +29 -0
- package/templates/system-state.mdc +29 -0
- package/examples/showcase/README.md +0 -115
- package/examples/showcase/baseline.md +0 -365
- package/examples/showcase/build.sh +0 -48
- package/examples/showcase/calls.md +0 -136
- package/examples/showcase/fulfill-cn.md +0 -351
- package/examples/showcase/fulfill.md +0 -271
- package/examples/showcase/index.md +0 -187
- package/examples/showcase/order.md +0 -195
- package/examples/showcase/promo.md +0 -580
- package/examples/showcase/refund.md +0 -966
- package/examples/showcase/seckill.md +0 -787
- package/skills/clado/examples/01-/351/234/200/346/261/202/346/240/221.md +0 -32
- package/skills/clado/examples/02-/346/225/260/346/215/256/350/241/250.md +0 -44
- package/skills/clado/examples/03-/346/216/245/345/217/243/346/270/205/345/215/225.md +0 -51
- package/skills/clado/examples/04-/346/226/271/346/263/225/351/223/276.md +0 -70
- package/skills/clado/examples/05-/346/216/245/345/217/243/350/260/203/347/224/250.md +0 -58
- package/skills/clado/examples/06-/350/260/203/347/224/250/351/223/276.md +0 -49
- package/skills/clado/examples/07-/346/213/206/346/226/207/346/241/243/index.md +0 -38
- package/skills/clado/examples/07-/346/213/206/346/226/207/346/241/243/refund.md +0 -33
- package/skills/clado/examples/07-/346/213/206/346/226/207/346/241/243/seckill.md +0 -56
- package/skills/clado/examples/08-/347/234/237/345/256/236/350/247/204/346/250/241//346/216/245/345/217/243/345/245/221/347/272/246.md +0 -122
- package/skills/clado/examples/08-/347/234/237/345/256/236/350/247/204/346/250/241//346/225/205/351/232/234/345/244/215/347/233/230.md +0 -99
- package/skills/clado/examples/08-/347/234/237/345/256/236/350/247/204/346/250/241//350/260/203/347/224/250/351/223/276.md +0 -219
- package/skills/clado/examples/build.sh +0 -44
- package/skills/clado/references/diagnostics.md +0 -129
package/src/html/runtime.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* Clado 0.2.0 页面运行时。
|
|
2
2
|
*
|
|
3
|
-
* 输入只有一份数据:`window.__CLADO__`(形状见 docs/spec
|
|
3
|
+
* 输入只有一份数据:`window.__CLADO__`(形状见 docs/spec.md §四)。
|
|
4
4
|
* 它做的全部事情:
|
|
5
5
|
*
|
|
6
6
|
* ① 把每段原文 Markdown 交给 marked 渲染,再按固定顺序后处理
|
|
@@ -61,6 +61,10 @@
|
|
|
61
61
|
return ANCHORS[dec] || '';
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
function anchorIdOf(href) {
|
|
65
|
+
var table = DOC.targetNodes || {};
|
|
66
|
+
try { return table[href] || table[decodeURIComponent(href)] || ''; } catch (_) { return ''; }
|
|
67
|
+
}
|
|
64
68
|
var $ = function (s, r) { return (r || document).querySelector(s); };
|
|
65
69
|
var $$ = function (s, r) { return Array.prototype.slice.call((r || document).querySelectorAll(s)); };
|
|
66
70
|
function esc(s) {
|
|
@@ -68,6 +72,9 @@
|
|
|
68
72
|
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
69
73
|
}
|
|
70
74
|
|
|
75
|
+
/*__CANVAS_CARD__*/
|
|
76
|
+
/*__MEDIA_ANCHORS__*/
|
|
77
|
+
|
|
71
78
|
/* ══ ① Markdown → DOM ═══════════════════════════════════════════ */
|
|
72
79
|
|
|
73
80
|
var CODE_LINK = /\[([^\]]+)\]\(([^)\s]+)\)/g;
|
|
@@ -94,7 +101,7 @@
|
|
|
94
101
|
if (anchorOf(m[2])) a.dataset.anchor = anchorOf(m[2]);
|
|
95
102
|
a.title = '指向 ' + m[2] + ',图上有一条线';
|
|
96
103
|
} else {
|
|
97
|
-
a.href = m[2]; a.target = '_blank'; a.rel = 'noopener';
|
|
104
|
+
a.href = /^(?:javascript|data|vbscript):/i.test(m[2].replace(/[\x00-\x20]/g,'')) ? '#' : m[2]; a.target = '_blank'; a.rel = 'noopener';
|
|
98
105
|
}
|
|
99
106
|
a.textContent = m[1];
|
|
100
107
|
frag.appendChild(a);
|
|
@@ -115,7 +122,20 @@
|
|
|
115
122
|
var box = document.createElement('div');
|
|
116
123
|
box.className = 'markdown-body';
|
|
117
124
|
if (!md) return box;
|
|
118
|
-
|
|
125
|
+
var template = document.createElement('template'); template.innerHTML = marked.parse(md);
|
|
126
|
+
var tags = new Set('a p br hr em strong del code pre blockquote ul ol li table thead tbody tr th td img h1 h2 h3 h4 h5 h6 details summary sub sup kbd span div'.split(' '));
|
|
127
|
+
Array.from(template.content.querySelectorAll('*')).forEach(function (element) {
|
|
128
|
+
var tag = element.localName;
|
|
129
|
+
if (!tags.has(tag)) { element.remove(); return; }
|
|
130
|
+
Array.from(element.attributes).forEach(function (attribute) {
|
|
131
|
+
var name=attribute.name, value=attribute.value, allow=['title','alt','width','height','start','align'].includes(name);
|
|
132
|
+
if (name === 'class' && tag === 'code') allow = /^language-[\w+#.-]+$/.test(value);
|
|
133
|
+
if (name === 'href' && tag === 'a') allow = !/^[a-z][a-z0-9+.-]*:/i.test(value.replace(/[\x00-\x20]/g,'')) || /^(https?:|mailto:|tel:)/i.test(value);
|
|
134
|
+
if (name === 'src' && tag === 'img') allow = !/^[a-z][a-z0-9+.-]*:/i.test(value.replace(/[\x00-\x20]/g,'')) || /^(https?:|data:image\/(png|jpeg|gif|webp);base64,)/i.test(value);
|
|
135
|
+
if (!allow) element.removeAttribute(name);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
box.appendChild(template.content);
|
|
119
139
|
|
|
120
140
|
// 表格:左右到顶、列多了自己左右滑、点一下能放大
|
|
121
141
|
$$('table', box).forEach(function (t) {
|
|
@@ -167,12 +187,14 @@
|
|
|
167
187
|
a.setAttribute('href', '#');
|
|
168
188
|
a.dataset.edge = id;
|
|
169
189
|
if (anchorOf(t)) a.dataset.anchor = anchorOf(t);
|
|
170
|
-
a.
|
|
190
|
+
if (anchorIdOf(t)) a.dataset.anchorId = anchorIdOf(t);
|
|
191
|
+
if (!a.title.startsWith('clado:')) a.title = '指向 ' + t + ',图上有一条线';
|
|
171
192
|
} else {
|
|
172
193
|
a.target = '_blank';
|
|
173
194
|
a.rel = 'noopener';
|
|
174
195
|
}
|
|
175
196
|
});
|
|
197
|
+
canvasBindMediaLinks(box);
|
|
176
198
|
return box;
|
|
177
199
|
}
|
|
178
200
|
|
|
@@ -180,17 +202,17 @@
|
|
|
180
202
|
|
|
181
203
|
var render = { card: {} };
|
|
182
204
|
// COL 是列与列之间的横向留白。原来是 48,太挤了 —— 线和端口没地方站。
|
|
183
|
-
var W =
|
|
205
|
+
var W = 750, COL = 130, ROW = 34, PAD = 40;
|
|
184
206
|
// mermaid 量节点文字和画节点文字必须用同一个字体,否则框会差一圈、名字被切
|
|
185
207
|
var MFONT = '-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans","PingFang SC","Microsoft YaHei",Helvetica,Arial,sans-serif';
|
|
186
208
|
var MSIZE = 13;
|
|
187
|
-
var pos = {}, box = { w: 1200, h: 700 }, scale = 1, tx = 0, ty = 0;
|
|
209
|
+
var pos = {}, CARD_PLACEMENTS = {}, box = { w: 1200, h: 700 }, scale = 1, tx = 0, ty = 0;
|
|
188
210
|
|
|
189
211
|
function nodeEl(n) {
|
|
190
212
|
var sec = document.createElement('section');
|
|
191
213
|
sec.className = 'slice';
|
|
192
214
|
sec.style.setProperty('--d', n.d);
|
|
193
|
-
sec.dataset.id = n.id;
|
|
215
|
+
sec.dataset.id = n.id; sec.dataset.level = String(n.d);
|
|
194
216
|
sec.innerHTML = '<div class="slice-head"><div class="h">' + esc(n.title) + '</div></div>';
|
|
195
217
|
sec.appendChild(mdToBody(n.md));
|
|
196
218
|
return sec;
|
|
@@ -199,16 +221,9 @@
|
|
|
199
221
|
function buildCards() {
|
|
200
222
|
var world = $('#world');
|
|
201
223
|
DOC.cards.forEach(function (c) {
|
|
202
|
-
var el =
|
|
203
|
-
el.className = 'card';
|
|
224
|
+
var el = createCanvasCard(c.title, 'card');
|
|
204
225
|
el.dataset.id = c.id;
|
|
205
|
-
el.innerHTML = '<div class="bar"><span class="grip">⠿</span></div><span class="hbar"></span>' +
|
|
206
|
-
'<div class="body"></div><span class="rz" title="拖我改卡片大小"></span>';
|
|
207
226
|
var body = $('.body', el);
|
|
208
|
-
var title = document.createElement('div');
|
|
209
|
-
title.className = 'markdown-body card-title';
|
|
210
|
-
title.innerHTML = '<h1>' + esc(c.title) + '</h1>';
|
|
211
|
-
body.appendChild(title);
|
|
212
227
|
if (c.md) body.appendChild(mdToBody(c.md));
|
|
213
228
|
(function walk(nodes) {
|
|
214
229
|
(nodes || []).forEach(function (n) { body.appendChild(nodeEl(n)); walk(n.kids); });
|
|
@@ -259,23 +274,47 @@
|
|
|
259
274
|
kk = new DOMMatrixReadOnly(getComputedStyle($('#world')).transform).a || scale || 1;
|
|
260
275
|
} catch (_) { kk = scale || 1; }
|
|
261
276
|
if (!kk || !isFinite(kk)) kk = 1;
|
|
277
|
+
/*
|
|
278
|
+
* ★ 可见带:正文那一块(标题栏下面到内边距之间的区域)。
|
|
279
|
+
* 端口本来是钉在「写这条边的那一行」上的,可卡片被拖矮之后 .body 会滚,
|
|
280
|
+
* 那一行可能已经滚出可视区 —— 算出来的 top 就跑到卡片下边框外头去了,
|
|
281
|
+
* 而 .card 没有 overflow:hidden(端口故意探出右边一点,见上面的注释),
|
|
282
|
+
* 于是那根竖杠就挂在卡片外面飘着。用户的原话:
|
|
283
|
+
* 「我把卡片纵向收短之后,那个竖杠超出卡片范围了,还在」。
|
|
284
|
+
* 钉的时候夹到可见带里:那一行滚出去了,端口就停在最近的那条边上。
|
|
285
|
+
*/
|
|
286
|
+
var bd = $('.body', cardEl);
|
|
287
|
+
var bandR = (bd || cardEl).getBoundingClientRect();
|
|
288
|
+
var bandTop = bandR.top - cr.top;
|
|
289
|
+
var bandBot = bandR.bottom - cr.top;
|
|
290
|
+
if (!(bandBot > bandTop)) { bandTop = 0; bandBot = cr.height; }
|
|
262
291
|
var put = function (a, soft) {
|
|
292
|
+
var point = a.mediaBlock ? canvasMediaSource(a, cardEl) : null;
|
|
293
|
+
if (a.mediaBlock && !point) return;
|
|
263
294
|
var ar = a.getBoundingClientRect();
|
|
264
295
|
var p = document.createElement('span');
|
|
265
296
|
p.className = soft ? 'port soft' : 'port';
|
|
266
297
|
p.dataset.edge = a.dataset.edge;
|
|
298
|
+
if (point) { p.dataset.mediaPoint = a.dataset.mediaPoint; p.mediaLink = a; }
|
|
299
|
+
var section = a.closest('.slice');
|
|
300
|
+
p.dataset.sourceId = section ? section.dataset.id : cardEl.dataset.id;
|
|
267
301
|
if (a.dataset.anchor) p.dataset.anchor = a.dataset.anchor;
|
|
302
|
+
if (a.dataset.anchorId) p.dataset.anchorId = a.dataset.anchorId;
|
|
268
303
|
if (soft) p.dataset.soft = '1';
|
|
269
304
|
p.title = (soft ? '这一行表示关系,连到 ' : '这一行连到 ') + a.dataset.edge;
|
|
270
|
-
|
|
305
|
+
var mid = (point ? point.y : ar.top + ar.height / 2) - cr.top;
|
|
306
|
+
var lo = bandTop + 2, hi = bandBot - 22; // 22 = 端口高 20 + 底下留 2
|
|
307
|
+
if (hi < lo) hi = lo;
|
|
308
|
+
if (!point) mid = Math.max(lo, Math.min(hi, mid));
|
|
309
|
+
p.style.top = Math.max(2, mid / kk - 10).toFixed(1) + 'px';
|
|
271
310
|
cardEl.appendChild(p);
|
|
272
311
|
};
|
|
273
312
|
$$('.slice', cardEl).forEach(function (sl) {
|
|
274
313
|
var seen = {};
|
|
275
|
-
$$('a.edge', sl).forEach(function (a) {
|
|
314
|
+
$$('a.edge:not(.media-jump)', sl).forEach(function (a) {
|
|
276
315
|
var to = a.dataset.edge;
|
|
277
|
-
if (!to || seen[to]) return;
|
|
278
|
-
seen[to] = 1;
|
|
316
|
+
if (!to || (!a.mediaBlock && seen[to])) return;
|
|
317
|
+
if (!a.mediaBlock) seen[to] = 1;
|
|
279
318
|
put(a, !!a.dataset.anchor);
|
|
280
319
|
});
|
|
281
320
|
});
|
|
@@ -284,11 +323,11 @@
|
|
|
284
323
|
var body = $('.body', cardEl);
|
|
285
324
|
if (!body) return;
|
|
286
325
|
var seen2 = {};
|
|
287
|
-
$$('a.edge', body).forEach(function (a) {
|
|
326
|
+
$$('a.edge:not(.media-jump)', body).forEach(function (a) {
|
|
288
327
|
if (a.closest('.slice')) return;
|
|
289
328
|
var to = a.dataset.edge;
|
|
290
|
-
if (!to || seen2[to]) return;
|
|
291
|
-
seen2[to] = 1;
|
|
329
|
+
if (!to || (!a.mediaBlock && seen2[to])) return;
|
|
330
|
+
if (!a.mediaBlock) seen2[to] = 1;
|
|
292
331
|
put(a);
|
|
293
332
|
});
|
|
294
333
|
}
|
|
@@ -301,8 +340,7 @@
|
|
|
301
340
|
|
|
302
341
|
★ 默认全收:一进来只看得见**根**(没有入边的那几张卡)。
|
|
303
342
|
这是用户要的「第一个节点展示,后面的节点默认不展示」。
|
|
304
|
-
|
|
305
|
-
所以放出来的时候它还在原地,画布不会因为一收一放就整个重排。
|
|
343
|
+
收起的卡不占位置;展开时按可见分支重排,父卡和镜头保持原位。
|
|
306
344
|
★ 收起一条边时**不清掉它下游那些边开着没开着的记忆** ——
|
|
307
345
|
再点开放出来,里面还是你上次展开的样子。 */
|
|
308
346
|
|
|
@@ -313,6 +351,11 @@
|
|
|
313
351
|
|
|
314
352
|
/** 从根出发、只走「开着」的边,能走到的卡就是看得见的 */
|
|
315
353
|
function visibleSet() {
|
|
354
|
+
if (typeof canvasVisibleCards !== 'undefined' && canvasVisibleCards) {
|
|
355
|
+
var focused = {};
|
|
356
|
+
canvasVisibleCards.forEach(function (id) { focused[id] = 1; });
|
|
357
|
+
return focused;
|
|
358
|
+
}
|
|
316
359
|
var hasIn = {};
|
|
317
360
|
DOC.edges.forEach(function (e) { hasIn[e[1]] = 1; });
|
|
318
361
|
var start = DOC.cards.filter(function (c) { return !hasIn[c.id]; }).map(function (c) { return c.id; });
|
|
@@ -356,9 +399,9 @@
|
|
|
356
399
|
var cardEl = p.closest('.card');
|
|
357
400
|
var src = cardEl ? cardEl.dataset.id : '';
|
|
358
401
|
var dst = p.dataset.edge;
|
|
359
|
-
var open = !!(VIS[src] && openEdge[edgeKey(src, dst)]);
|
|
402
|
+
var open = !!(VIS[src] && (canvasVisibleCards ? VIS[dst] : openEdge[edgeKey(src, dst)]));
|
|
360
403
|
p.classList.toggle('folded', !open);
|
|
361
|
-
p.title = (open ? '收起 ' : '展开 ') + dst + '
|
|
404
|
+
p.title = canvasVisibleCards ? '关联链路' : (open ? '收起 ' : '展开 ') + dst + '(连同下游)';
|
|
362
405
|
p.dataset.open = open ? '1' : '';
|
|
363
406
|
});
|
|
364
407
|
if (document.body.dataset.mode === 'cards') drawWires();
|
|
@@ -370,56 +413,12 @@
|
|
|
370
413
|
* 不重摆的话画布上会留一块谁也没有的空当。
|
|
371
414
|
*/
|
|
372
415
|
function toggleEdge(src, dst) {
|
|
373
|
-
if (!src || !dst) return;
|
|
416
|
+
if (!src || !dst || canvasVisibleCards) return;
|
|
374
417
|
var k = edgeKey(src, dst);
|
|
375
418
|
if (openEdge[k]) delete openEdge[k]; else openEdge[k] = 1;
|
|
376
419
|
afterToggle(src);
|
|
377
420
|
}
|
|
378
421
|
|
|
379
|
-
/**
|
|
380
|
-
* 一批边一起开 / 关(点标题用):只要有一条还关着就全开,全开着就全关。
|
|
381
|
-
* 这样「点一下展开这一节、再点一下收回去」符合直觉。
|
|
382
|
-
*/
|
|
383
|
-
function toggleEdges(src, targets) {
|
|
384
|
-
if (!targets.length) return;
|
|
385
|
-
var allOpen = targets.every(function (t) { return openEdge[edgeKey(src, t)]; });
|
|
386
|
-
targets.forEach(function (t) {
|
|
387
|
-
var k = edgeKey(src, t);
|
|
388
|
-
if (allOpen) delete openEdge[k]; else openEdge[k] = 1;
|
|
389
|
-
});
|
|
390
|
-
afterToggle(src);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/** 一个 `.slice`(卡片里的 `##`…`######`)覆盖到的下游卡:自己和比自己深的那些片 */
|
|
394
|
-
function sliceTargets(cardEl, sl) {
|
|
395
|
-
var list = $$('.slice', cardEl);
|
|
396
|
-
var i = list.indexOf(sl);
|
|
397
|
-
if (i < 0) return [];
|
|
398
|
-
var d = parseInt(sl.style.getPropertyValue('--d'), 10) || 2;
|
|
399
|
-
var out = [], seen = {};
|
|
400
|
-
for (var j = i; j < list.length; j++) {
|
|
401
|
-
if (j > i) {
|
|
402
|
-
var dj = parseInt(list[j].style.getPropertyValue('--d'), 10) || 2;
|
|
403
|
-
if (dj <= d) break; // 回到同一层或更浅 —— 这一片到此为止
|
|
404
|
-
}
|
|
405
|
-
$$('a.edge', list[j]).forEach(function (a) {
|
|
406
|
-
var t = a.dataset.edge;
|
|
407
|
-
if (t && !seen[t]) { seen[t] = 1; out.push(t); }
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
return out;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/** 整张卡连出去的全部下游卡 */
|
|
414
|
-
function cardTargets(cardEl) {
|
|
415
|
-
var out = [], seen = {};
|
|
416
|
-
$$('a.edge', cardEl).forEach(function (a) {
|
|
417
|
-
var t = a.dataset.edge;
|
|
418
|
-
if (t && !seen[t]) { seen[t] = 1; out.push(t); }
|
|
419
|
-
});
|
|
420
|
-
return out;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
422
|
/*
|
|
424
423
|
* 最近一次收放是谁触发的 + 那之前所有卡片的位置。
|
|
425
424
|
* afterMedia(mermaid 渲完、卡片尺寸变了要重摆)靠它俩继续「只动那一支」。
|
|
@@ -530,9 +529,9 @@
|
|
|
530
529
|
DOC.cards.forEach(function (c) { if (!indeg[c.id]) sink(c.id); });
|
|
531
530
|
// 一个根都没有(整张图全是环)时,随便挑一张起头,剩下的照样能排开
|
|
532
531
|
DOC.cards.forEach(function (c) { if (!walked[c.id]) sink(c.id); });
|
|
533
|
-
var kids = {};
|
|
532
|
+
var kids = {}, focused = typeof canvasVisibleCards !== 'undefined' && canvasVisibleCards;
|
|
534
533
|
DOC.edges.forEach(function (e) {
|
|
535
|
-
if (!seen[e[0]] || !seen[e[1]]) return;
|
|
534
|
+
if (!seen[e[0]] || !seen[e[1]] || (!focused && !openEdge[edgeKey(e[0], e[1])])) return;
|
|
536
535
|
(kids[e[0]] = kids[e[0]] || []).push(e[1]);
|
|
537
536
|
});
|
|
538
537
|
/*
|
|
@@ -544,7 +543,7 @@
|
|
|
544
543
|
*/
|
|
545
544
|
var cols = {}, inCol = {};
|
|
546
545
|
DOC.edges.forEach(function (e) {
|
|
547
|
-
if (!seen[e[1]] || inCol[e[1]]) return;
|
|
546
|
+
if (!seen[e[0]] || !seen[e[1]] || (!focused && !openEdge[edgeKey(e[0], e[1])]) || inCol[e[1]]) return;
|
|
548
547
|
inCol[e[1]] = 1;
|
|
549
548
|
(cols[depth[e[1]]] = cols[depth[e[1]]] || []).push(e[1]);
|
|
550
549
|
});
|
|
@@ -560,7 +559,7 @@
|
|
|
560
559
|
* 一张被撑到 1200 的卡就直接压在右边那一列的卡身上了。这就是「缩放的时候
|
|
561
560
|
* 卡片会重叠」的来源(不是只算了一层,是压根没算宽度)。
|
|
562
561
|
*/
|
|
563
|
-
var colX = {}, cx = PAD;
|
|
562
|
+
var colX = {}, cx = PAD, naturalY = {};
|
|
564
563
|
keys.forEach(function (d) {
|
|
565
564
|
colX[d] = cx;
|
|
566
565
|
var wmax = W;
|
|
@@ -577,10 +576,10 @@
|
|
|
577
576
|
bot = Math.max(bot, pos[q].y + render.card[q].offsetHeight);
|
|
578
577
|
});
|
|
579
578
|
var want = isFinite(top) ? (top + bot) / 2 - h / 2 : PAD;
|
|
579
|
+
naturalY[id] = want;
|
|
580
580
|
return { id: id, h: h, want: want };
|
|
581
581
|
});
|
|
582
|
-
//
|
|
583
|
-
col.sort(function (a, b) { return a.want - b.want; });
|
|
582
|
+
// 后代的位置只影响纵向对齐。同一父卡的子卡始终按正文首次引用的顺序排列。
|
|
584
583
|
var prev = null;
|
|
585
584
|
col.forEach(function (it) {
|
|
586
585
|
// 先不夹到 PAD:父亲比儿子们高一大截时「居中」是要往负数走的,
|
|
@@ -592,6 +591,38 @@
|
|
|
592
591
|
prev = { y: y, h: it.h };
|
|
593
592
|
});
|
|
594
593
|
});
|
|
594
|
+
// 左列卡片互相让位后的位移要传给右列分支;共享子卡取所有父卡位移的平均值。
|
|
595
|
+
if (!anchor || !prevPos) {
|
|
596
|
+
var incoming = {};
|
|
597
|
+
Object.keys(kids).forEach(function (parent) {
|
|
598
|
+
kids[parent].forEach(function (child) {
|
|
599
|
+
if (depth[parent] < depth[child]) (incoming[child] || (incoming[child] = [])).push(parent);
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
keys.slice(1).forEach(function (d) {
|
|
603
|
+
var parentY = {}, desiredY = {};
|
|
604
|
+
cols[d].forEach(function (id) {
|
|
605
|
+
var parents = incoming[id] || [];
|
|
606
|
+
parentY[id] = parents.length ? parents.reduce(function (sum, parent) { return sum + pos[parent].y; }, 0) / parents.length : pos[id].y;
|
|
607
|
+
var shift = parents.length ? parents.reduce(function (sum, parent) { return sum + pos[parent].y - naturalY[parent]; }, 0) / parents.length : 0;
|
|
608
|
+
desiredY[id] = pos[id].y + shift;
|
|
609
|
+
});
|
|
610
|
+
// 同列先按父卡顺序分组。同组保留引用顺序,相撞时把间距分摊给两边。
|
|
611
|
+
var groups = [], offset = 0;
|
|
612
|
+
cols[d].slice().sort(function (a, b) { return parentY[a] - parentY[b]; }).forEach(function (id) {
|
|
613
|
+
groups.push({ cards: [{ id: id, offset: offset }], y: desiredY[id] - offset });
|
|
614
|
+
offset += render.card[id].offsetHeight + ROW;
|
|
615
|
+
while (groups.length > 1 && groups[groups.length - 2].y > groups[groups.length - 1].y) {
|
|
616
|
+
var next = groups.pop(), prev = groups[groups.length - 1];
|
|
617
|
+
prev.y = (prev.y * prev.cards.length + next.y * next.cards.length) / (prev.cards.length + next.cards.length);
|
|
618
|
+
prev.cards = prev.cards.concat(next.cards);
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
groups.forEach(function (group) {
|
|
622
|
+
group.cards.forEach(function (card) { pos[card.id].y = group.y + card.offset; });
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
}
|
|
595
626
|
/*
|
|
596
627
|
* ★ 收起 / 展开只动「被点的那张 + 它的**所有后代**」,别的卡一个像素都不挪。
|
|
597
628
|
* 做法:先照常全局摆一遍,然后把不在 moved 里的卡片 y 换回快照里的旧值,
|
|
@@ -608,8 +639,16 @@
|
|
|
608
639
|
moved[walkId] = 1;
|
|
609
640
|
(kids[walkId] || []).forEach(function (q) { stack.push(q); });
|
|
610
641
|
}
|
|
642
|
+
// 钉回父卡时整支一起平移,保留可见孩子围绕父卡的居中关系。
|
|
643
|
+
if (pos[anchor] && prevPos[anchor]) {
|
|
644
|
+
var dx = prevPos[anchor].x - pos[anchor].x, dy = prevPos[anchor].y - pos[anchor].y;
|
|
645
|
+
Object.keys(moved).forEach(function (id) {
|
|
646
|
+
if (pos[id]) { pos[id].x += dx; pos[id].y += dy; }
|
|
647
|
+
});
|
|
648
|
+
}
|
|
611
649
|
DOC.cards.forEach(function (c) {
|
|
612
650
|
if (pos[c.id] && !moved[c.id] && prevPos[c.id]) pos[c.id].y = prevPos[c.id].y;
|
|
651
|
+
if (pos[c.id] && !moved[c.id] && prevPos[c.id]) pos[c.id].x = prevPos[c.id].x;
|
|
613
652
|
});
|
|
614
653
|
/*
|
|
615
654
|
* ★ 被点的这张**自己也不许动**。用户原话:「我点的这个标题的这个卡片,它能不动吗?」
|
|
@@ -618,36 +657,31 @@
|
|
|
618
657
|
*/
|
|
619
658
|
if (pos[anchor] && prevPos[anchor]) pos[anchor].y = prevPos[anchor].y;
|
|
620
659
|
keys.forEach(function (d) {
|
|
621
|
-
var
|
|
622
|
-
|
|
660
|
+
var moving = [], pinned = [], blocked = [];
|
|
661
|
+
cols[d].forEach(function (id) {
|
|
662
|
+
if (CARD_PLACEMENTS[id]) pos[id] = Object.assign({}, CARD_PLACEMENTS[id]);
|
|
663
|
+
(moved[id] && id !== anchor && !CARD_PLACEMENTS[id] ? moving : pinned).push(id);
|
|
623
664
|
});
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
* 钉住的卡原则上不动,只有 moved 的让路。
|
|
631
|
-
* 但有一种例外必须让:mermaid 图是异步渲的,渲完之后卡片会变高,
|
|
632
|
-
* 这一列里原来不重叠的两张卡就顶上了 —— 这时候宁可把下面那张往下推,
|
|
633
|
-
* 也不能留着重叠(用户明确要求「不要重叠在一起」)。只往下推,不往上提。
|
|
634
|
-
*/
|
|
635
|
-
if (it.mv && it.id !== anchor) pos[it.id].y = y;
|
|
636
|
-
prev = { y: pos[it.id].y, h: it.h };
|
|
665
|
+
// 整组让开固定卡,保持孩子间距;选择离父卡最近的上下空位。
|
|
666
|
+
moving.forEach(function (id) {
|
|
667
|
+
pinned.forEach(function (fixed) {
|
|
668
|
+
blocked.push({ lo: pos[fixed].y - ROW - pos[id].y - render.card[id].offsetHeight,
|
|
669
|
+
hi: pos[fixed].y + render.card[fixed].offsetHeight + ROW - pos[id].y });
|
|
670
|
+
});
|
|
637
671
|
});
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
* 就是这么攒出来的(实测每点一下 style.top 涨 12.5px)。
|
|
645
|
-
* 改成只把越界的 moved 卡夹回 PAD,其他卡一个像素都不碰。
|
|
646
|
-
*/
|
|
647
|
-
keys.forEach(function (d) {
|
|
648
|
-
cols[d].forEach(function (id) {
|
|
649
|
-
if (pos[id] && moved[id] && pos[id].y < PAD) pos[id].y = PAD;
|
|
672
|
+
blocked.sort(function (a, b) { return a.lo - b.lo; });
|
|
673
|
+
var intervals = [];
|
|
674
|
+
blocked.forEach(function (range) {
|
|
675
|
+
var tail = intervals[intervals.length - 1];
|
|
676
|
+
if (tail && range.lo < tail.hi) tail.hi = Math.max(tail.hi, range.hi);
|
|
677
|
+
else intervals.push(range);
|
|
650
678
|
});
|
|
679
|
+
var shift = 0;
|
|
680
|
+
intervals.forEach(function (range) {
|
|
681
|
+
if (range.lo < 0 && range.hi > 0) shift = Math.abs(range.lo) < Math.abs(range.hi) ? range.lo : range.hi;
|
|
682
|
+
});
|
|
683
|
+
// 无限画布允许负坐标,不能把上半组逐张夹到PAD而破坏居中。
|
|
684
|
+
moving.forEach(function (id) { pos[id].y += shift; });
|
|
651
685
|
});
|
|
652
686
|
} else {
|
|
653
687
|
// 整体下移,保证最上面那张卡正好落在 PAD 上(相对关系一个没动)
|
|
@@ -681,6 +715,7 @@
|
|
|
681
715
|
DOC.cards.forEach(function (c) {
|
|
682
716
|
var el = render.card[c.id];
|
|
683
717
|
if (!pos[c.id]) return;
|
|
718
|
+
if (CARD_PLACEMENTS[c.id]) pos[c.id] = Object.assign({},CARD_PLACEMENTS[c.id]);
|
|
684
719
|
el.style.left = pos[c.id].x + 'px';
|
|
685
720
|
el.style.top = pos[c.id].y + 'px';
|
|
686
721
|
maxBottom = Math.max(maxBottom, pos[c.id].y + el.offsetHeight);
|
|
@@ -701,6 +736,36 @@
|
|
|
701
736
|
drawWires();
|
|
702
737
|
}
|
|
703
738
|
|
|
739
|
+
/*
|
|
740
|
+
* ★ 线是照着卡片的**当前渲染位置**画的(getBoundingClientRect),可卡片位置是带
|
|
741
|
+
* CSS 过渡滑过去的(.card 的 left/top 有 .26s),而 pointermove 只在那一瞬间画一次 ——
|
|
742
|
+
* 手指停下来之后卡片还要滑 260ms,线却停在原地,看着就是「线跟不上卡片」。
|
|
743
|
+
* 切模式也一样:layout() 重摆 + fit() 滑镜头都在过渡里,中间量到的位置是半路的,
|
|
744
|
+
* 过渡结束没人再画一次,线就永远停在半路上(用户给的那套复现步骤:
|
|
745
|
+
* 展开所有儿子 → 把父节点拖到别处 → 切文档再切回卡片)。
|
|
746
|
+
* 用户的原话:「卡片和卡片之间相连的线,在我把卡片快速拖动的时候,它可能会跟不上。
|
|
747
|
+
* 你要么加一个定时器,隔几百毫秒或者一秒就把它重新渲染一次,要么就修复这个问题,
|
|
748
|
+
* 让它永远能跟上」。
|
|
749
|
+
* 所以凡是可能让卡片动起来的地方都叫一次 keepWiresAlive():接下来这段时间里
|
|
750
|
+
* 每帧重画线,隔几帧再整套重钉一次端口,等卡片停稳了自己收手。
|
|
751
|
+
*/
|
|
752
|
+
var WIRE_UNTIL = 0, WIRE_BUSY = 0, WIRE_N = 0;
|
|
753
|
+
function keepWiresAlive(ms) {
|
|
754
|
+
var until = Date.now() + (ms || 700);
|
|
755
|
+
if (until > WIRE_UNTIL) WIRE_UNTIL = until;
|
|
756
|
+
if (WIRE_BUSY) return;
|
|
757
|
+
WIRE_BUSY = 1;
|
|
758
|
+
(function frame() {
|
|
759
|
+
if (document.body.dataset.mode === 'cards') {
|
|
760
|
+
// 端口本身:卡片一挪它就跟着挪(它是卡片的子节点),不用每帧重钉;
|
|
761
|
+
// 但卡片高度在过渡里变的时候得重钉,隔几帧来一次就够。
|
|
762
|
+
if ((WIRE_N++ % 6) === 0) repinPorts(); else drawWires();
|
|
763
|
+
}
|
|
764
|
+
if (Date.now() < WIRE_UNTIL) { requestAnimationFrame(frame); return; }
|
|
765
|
+
WIRE_BUSY = 0;
|
|
766
|
+
})();
|
|
767
|
+
}
|
|
768
|
+
|
|
704
769
|
function drawWires() {
|
|
705
770
|
var world = $('#world'), svg = $('#wires');
|
|
706
771
|
var wr = world.getBoundingClientRect();
|
|
@@ -778,7 +843,7 @@
|
|
|
778
843
|
function fit() {
|
|
779
844
|
var st = $('#stage').getBoundingClientRect();
|
|
780
845
|
// 别为了「全塞进屏幕」把卡片缩成蚂蚁 —— 画布是无限的,看不全就自己拖
|
|
781
|
-
var floor =
|
|
846
|
+
var floor = .85;
|
|
782
847
|
// ★ 卡片模式按「看得见的那些卡」算,不是按整张图:
|
|
783
848
|
// 默认只展开根的时候,按整张图去缩会把唯一那张卡缩成一个小点,还偏在角落。
|
|
784
849
|
var b = document.body.dataset.mode === 'cards' ? visibleBox() : box;
|
|
@@ -786,6 +851,25 @@
|
|
|
786
851
|
scale = Math.min(1, Math.max(floor, Math.min((st.width - 80) / cw, (st.height - 80) / ch)));
|
|
787
852
|
tx = Math.max(40, (st.width - cw * scale) / 2) - (b.x1 || 0) * scale;
|
|
788
853
|
ty = Math.max(20, (st.height - ch * scale) / 2) - (b.y1 || 0) * scale;
|
|
854
|
+
// 大图保留可读字号时,以调用入口为首屏;全图顶部可能是远处的子节点。
|
|
855
|
+
if (Math.min((st.width - 80) / cw, (st.height - 80) / ch) < floor) {
|
|
856
|
+
var entry = document.body.dataset.mode === 'mindmap' ? $('#mind .mnode[data-path="0"]') : null;
|
|
857
|
+
if (!entry && document.body.dataset.mode === 'cards') {
|
|
858
|
+
var first = DOC.cards.find(function (card) { return VIS[card.id]; });
|
|
859
|
+
entry = first && render.card[first.id];
|
|
860
|
+
}
|
|
861
|
+
if (entry) {
|
|
862
|
+
// layout 已写入最终坐标,但 left/top 的 CSS 过渡可能仍在途中;
|
|
863
|
+
// offsetLeft/Top 是动画当前值,按它取景会让入口在动画结束后漂出首屏。
|
|
864
|
+
var destination = document.body.dataset.mode === 'cards' && first ? pos[first.id] : null;
|
|
865
|
+
var entryX = destination ? destination.x : parseFloat(entry.style.left);
|
|
866
|
+
var entryY = destination ? destination.y : parseFloat(entry.style.top);
|
|
867
|
+
if (!isFinite(entryX)) entryX = entry.offsetLeft;
|
|
868
|
+
if (!isFinite(entryY)) entryY = entry.offsetTop;
|
|
869
|
+
tx = 40 - entryX * scale;
|
|
870
|
+
ty = Math.max(24, (st.height - entry.offsetHeight * scale) / 2) - entryY * scale;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
789
873
|
apply();
|
|
790
874
|
}
|
|
791
875
|
|
|
@@ -910,6 +994,8 @@
|
|
|
910
994
|
/** mermaid 出来之后尺寸会变,端口和线都得重量一遍 */
|
|
911
995
|
function afterMedia() {
|
|
912
996
|
fixMermaidLabels();
|
|
997
|
+
canvasPlaceMediaJumps($('#article'));
|
|
998
|
+
if (document.body.dataset.mode === 'mindmap') drawMindWires();
|
|
913
999
|
DOC.cards.forEach(function (c) { if (VIS[c.id]) placePorts(render.card[c.id]); });
|
|
914
1000
|
if (document.body.dataset.mode !== 'cards') return;
|
|
915
1001
|
sizeDiagrams(); // 图按自然尺寸摆,撑不下就让卡片为它让路
|
|
@@ -964,20 +1050,25 @@
|
|
|
964
1050
|
var stopDrag = function () { down = false; stage.classList.remove('drag'); endPan(); };
|
|
965
1051
|
stage.addEventListener('pointerup', stopDrag);
|
|
966
1052
|
stage.addEventListener('pointercancel', stopDrag);
|
|
967
|
-
stage.addEventListener('click', function (e) { if (!e.target.closest('.card')) clearLit(); });
|
|
1053
|
+
stage.addEventListener('click', function (e) { if (!e.target.closest('.card,.mnode')) clearLit(); });
|
|
968
1054
|
stage.addEventListener('wheel', function (e) {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1055
|
+
if (!e.ctrlKey && !e.metaKey) {
|
|
1056
|
+
for (var el = e.target.closest('.tscroll,pre,.body'); el && el !== stage; el = el.parentElement.closest('.tscroll,pre,.body')) {
|
|
1057
|
+
var style = getComputedStyle(el);
|
|
1058
|
+
var canScrollY = /^(auto|scroll)$/.test(style.overflowY) && (e.deltaY < 0 ? el.scrollTop > 0 : e.deltaY > 0 && el.scrollTop + el.clientHeight < el.scrollHeight - 1);
|
|
1059
|
+
var canScrollX = /^(auto|scroll)$/.test(style.overflowX) && (e.deltaX < 0 ? el.scrollLeft > 0 : e.deltaX > 0 && el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
|
|
1060
|
+
if (canScrollY || canScrollX) return;
|
|
1061
|
+
}
|
|
973
1062
|
}
|
|
1063
|
+
if (!e.deltaY) return;
|
|
974
1064
|
e.preventDefault();
|
|
975
1065
|
var r = stage.getBoundingClientRect(), mx = e.clientX - r.left, my = e.clientY - r.top;
|
|
976
1066
|
var ns = Math.min(2.5, Math.max(.2, scale * (e.deltaY < 0 ? 1.09 : 1 / 1.09)));
|
|
977
1067
|
tx = mx - (mx - tx) * (ns / scale);
|
|
978
1068
|
ty = my - (my - ty) * (ns / scale);
|
|
979
1069
|
scale = ns;
|
|
980
|
-
apply();
|
|
1070
|
+
apply();
|
|
1071
|
+
if (document.body.dataset.mode === 'mindmap') drawMindWires(); else drawWires();
|
|
981
1072
|
}, { passive: false });
|
|
982
1073
|
})();
|
|
983
1074
|
|
|
@@ -1001,60 +1092,10 @@
|
|
|
1001
1092
|
|
|
1002
1093
|
function bindCards() {
|
|
1003
1094
|
DOC.cards.forEach(function (c) {
|
|
1004
|
-
var el = render.card[c.id]
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
down = true; beginPan(); sx = e.clientX; sy = e.clientY; ox = pos[c.id].x; oy = pos[c.id].y;
|
|
1009
|
-
bar.setPointerCapture(e.pointerId);
|
|
1010
|
-
});
|
|
1011
|
-
bar.addEventListener('pointermove', function (e) {
|
|
1012
|
-
if (!down) return;
|
|
1013
|
-
pos[c.id].x = ox + (e.clientX - sx) / scale;
|
|
1014
|
-
pos[c.id].y = oy + (e.clientY - sy) / scale;
|
|
1015
|
-
el.style.left = pos[c.id].x + 'px'; el.style.top = pos[c.id].y + 'px';
|
|
1016
|
-
drawWires();
|
|
1017
|
-
});
|
|
1018
|
-
bar.addEventListener('pointerup', function () { down = false; endPan(); });
|
|
1019
|
-
bar.addEventListener('pointercancel', function () { down = false; endPan(); });
|
|
1020
|
-
|
|
1021
|
-
// 右下角拖着改大小(画布是缩放过的,位移要除回 scale)
|
|
1022
|
-
var rz = $('.rz', el);
|
|
1023
|
-
rz.addEventListener('pointerdown', function (e) {
|
|
1024
|
-
e.stopPropagation(); e.preventDefault();
|
|
1025
|
-
beginPan(); // 拖着改大小同样不许顺手选中文字
|
|
1026
|
-
var w0 = el.offsetWidth, px = e.clientX, py = e.clientY;
|
|
1027
|
-
/*
|
|
1028
|
-
* ★ 高度只能**往上缩小**,不能拉到比内容还高。
|
|
1029
|
-
* 所以先把写死的高度摘掉量一次「内容自然高度」nat —— 那才是上限。
|
|
1030
|
-
* 用户的原话:「卡片可以往下拉大,但是不能往上缩小。感觉你正好做反了,
|
|
1031
|
-
* 它应该是可以往上缩小,但是不能往下拉大」。
|
|
1032
|
-
*/
|
|
1033
|
-
var hWas = el.style.height, mWas = el.style.minHeight;
|
|
1034
|
-
el.style.height = ''; el.style.minHeight = '';
|
|
1035
|
-
var nat = el.offsetHeight;
|
|
1036
|
-
el.style.height = hWas; el.style.minHeight = mWas;
|
|
1037
|
-
var h0 = el.offsetHeight;
|
|
1038
|
-
try { rz.setPointerCapture(e.pointerId); } catch (_) {}
|
|
1039
|
-
var move = function (ev) {
|
|
1040
|
-
el.style.width = Math.max(240, w0 + (ev.clientX - px) / scale) + 'px';
|
|
1041
|
-
// 往上拖 = 变小;往下拖最多回到内容自然高度就停住
|
|
1042
|
-
var h = Math.max(110, h0 + (ev.clientY - py) / scale);
|
|
1043
|
-
if (nat > 0) h = Math.min(h, nat);
|
|
1044
|
-
el.style.minHeight = '';
|
|
1045
|
-
el.style.height = h + 'px';
|
|
1046
|
-
placePorts(el); // 宽度变了换行位置也变,端口要重新量
|
|
1047
|
-
drawWires();
|
|
1048
|
-
};
|
|
1049
|
-
var up = function () {
|
|
1050
|
-
rz.removeEventListener('pointermove', move);
|
|
1051
|
-
rz.removeEventListener('pointerup', up);
|
|
1052
|
-
rz.removeEventListener('pointercancel', up);
|
|
1053
|
-
endPan();
|
|
1054
|
-
};
|
|
1055
|
-
rz.addEventListener('pointermove', move);
|
|
1056
|
-
rz.addEventListener('pointerup', up);
|
|
1057
|
-
rz.addEventListener('pointercancel', up);
|
|
1095
|
+
var el = render.card[c.id];
|
|
1096
|
+
bindCanvasCard(el, {
|
|
1097
|
+
move: function (x, y) { pos[c.id] = { x: x, y: y }; CARD_PLACEMENTS[c.id] = {x:x,y:y}; },
|
|
1098
|
+
redraw: function () { placePorts(el); applyVisibility(); drawWires(); keepWiresAlive(600); }
|
|
1058
1099
|
});
|
|
1059
1100
|
|
|
1060
1101
|
// 点端口 = 展开 / 收起这条边下游的整棵子树。端口自己会从灰变蓝、蓝变灰。
|
|
@@ -1064,50 +1105,8 @@
|
|
|
1064
1105
|
toggleEdge(c.id, p.dataset.edge);
|
|
1065
1106
|
});
|
|
1066
1107
|
|
|
1067
|
-
|
|
1068
|
-
* 顶栏(那条 ⠿ 小横条):点亮这一支。
|
|
1069
|
-
* ★ 这个手势原来挂在卡片标题上。用户的标题现在要去「展开 / 收起下游」了,
|
|
1070
|
-
* 一个点击不能既换取景又收放卡片,所以点亮挪到顶栏。
|
|
1071
|
-
*/
|
|
1072
|
-
el.addEventListener('click', function (e) {
|
|
1073
|
-
if (!e.target.closest('.bar')) return;
|
|
1074
|
-
if (el.dataset.lit) { clearLit(); return; }
|
|
1075
|
-
clearLit();
|
|
1076
|
-
// 点亮这张卡 + **它的整条上游链** + 它的整条下游链,其余压暗。
|
|
1077
|
-
// ★ 上游也要亮(用户提的):原来只跟出边,点一张中间的卡时「它是被谁叫起来的」
|
|
1078
|
-
// 全被压暗了,看着像这张卡凭空冒出来。
|
|
1079
|
-
// ★ 必须是传递闭包,不是一跳:用户要的是「这张卡连着的那一整串」。
|
|
1080
|
-
var lit = {}; lit[c.id] = 1;
|
|
1081
|
-
var queue = [c.id];
|
|
1082
|
-
while (queue.length) {
|
|
1083
|
-
var cur = queue.shift();
|
|
1084
|
-
DOC.edges.forEach(function (e2) {
|
|
1085
|
-
if (e2[0] === cur && !lit[e2[1]]) { lit[e2[1]] = 1; queue.push(e2[1]); }
|
|
1086
|
-
if (e2[1] === cur && !lit[e2[0]]) { lit[e2[0]] = 1; queue.push(e2[0]); }
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1089
|
-
$$('.card').forEach(function (x) {
|
|
1090
|
-
x.classList.toggle('dim', !lit[x.dataset.id]);
|
|
1091
|
-
x.classList.toggle('lit', x.dataset.id === c.id);
|
|
1092
|
-
});
|
|
1093
|
-
el.dataset.lit = '1';
|
|
1094
|
-
});
|
|
1108
|
+
// 标题点击、双击与长按统一由 canvas-focus.js 处理;拖动柄只负责拖动。
|
|
1095
1109
|
|
|
1096
|
-
/*
|
|
1097
|
-
* 标题:点哪一级,就把那一级**连同它下面的各级**关联到的下游卡全部展开 / 收起。
|
|
1098
|
-
* · 点卡片最大的标题(h1)→ 这一整张卡连出去的全部下游
|
|
1099
|
-
* · 点卡片里的 `##` / `###` / … → 从这一片起,到下一个不比它深的片之前
|
|
1100
|
-
* (层级就是缩进,所以「下一片不比它深」就是这一节的边界)
|
|
1101
|
-
*/
|
|
1102
|
-
el.addEventListener('click', function (e) {
|
|
1103
|
-
if (e.target.closest('.port')) return;
|
|
1104
|
-
if (e.target.closest('.zoomable')) return;
|
|
1105
|
-
var head = e.target.closest('.slice-head');
|
|
1106
|
-
var h1 = e.target.closest('.card-title h1');
|
|
1107
|
-
if (!head && !h1) return;
|
|
1108
|
-
var targets = head ? sliceTargets(el, head.parentNode) : cardTargets(el);
|
|
1109
|
-
toggleEdges(c.id, targets);
|
|
1110
|
-
});
|
|
1111
1110
|
});
|
|
1112
1111
|
}
|
|
1113
1112
|
|
|
@@ -1129,7 +1128,7 @@
|
|
|
1129
1128
|
var sec = document.createElement('section');
|
|
1130
1129
|
sec.className = 'slice';
|
|
1131
1130
|
sec.style.setProperty('--d', 1);
|
|
1132
|
-
sec.dataset.path = String(ci);
|
|
1131
|
+
sec.dataset.path = String(ci); sec.dataset.level = "1";
|
|
1133
1132
|
sec.innerHTML = '<div class="slice-head"><div class="h">' + esc(c.title) + '</div></div>';
|
|
1134
1133
|
if (c.md) sec.appendChild(mdToBody(c.md));
|
|
1135
1134
|
art.appendChild(sec);
|
|
@@ -1140,7 +1139,7 @@
|
|
|
1140
1139
|
var s = document.createElement('section');
|
|
1141
1140
|
s.className = 'slice';
|
|
1142
1141
|
s.style.setProperty('--d', n.d);
|
|
1143
|
-
s.dataset.path = path;
|
|
1142
|
+
s.dataset.path = path; s.dataset.level = String(n.d);
|
|
1144
1143
|
s.innerHTML = '<div class="slice-head"><div class="h">' + esc(n.title) + '</div></div>';
|
|
1145
1144
|
if (n.md) s.appendChild(mdToBody(n.md));
|
|
1146
1145
|
art.appendChild(s);
|
|
@@ -1151,32 +1150,64 @@
|
|
|
1151
1150
|
});
|
|
1152
1151
|
}
|
|
1153
1152
|
|
|
1153
|
+
var MIND_CARD_STATE = {};
|
|
1154
|
+
function applyMindCardPlacement(el) {
|
|
1155
|
+
el.dataset.layoutX = el.style.left; el.dataset.layoutY = el.style.top;
|
|
1156
|
+
var state = MIND_CARD_STATE[el.dataset.contentId];
|
|
1157
|
+
if (state) {
|
|
1158
|
+
el.style.left = (parseFloat(el.style.left) + (state.dx || 0)) + 'px';
|
|
1159
|
+
el.style.top = (parseFloat(el.style.top) + (state.dy || 0)) + 'px';
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
function bindMindCard(el) {
|
|
1163
|
+
function state() { return MIND_CARD_STATE[el.dataset.contentId] || (MIND_CARD_STATE[el.dataset.contentId] = {}); }
|
|
1164
|
+
bindCanvasCard(el, {
|
|
1165
|
+
move: function (x, y) { var s = state(); s.dx = x - parseFloat(el.dataset.layoutX); s.dy = y - parseFloat(el.dataset.layoutY); },
|
|
1166
|
+
resize: function (width, height) { var s = state(); s.width = width; s.height = height; },
|
|
1167
|
+
redraw: function () { drawMindWires(); }
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1154
1170
|
function renderMind() {
|
|
1155
1171
|
var mind = $('#mind');
|
|
1156
1172
|
$$('.mnode', mind).forEach(function (n) { n.remove(); });
|
|
1157
|
-
var
|
|
1173
|
+
var GX = 64, GY = 12, X0 = 40, Y0 = 40;
|
|
1158
1174
|
var cursor = Y0;
|
|
1175
|
+
var ALL = []; // 所有节点,等宽度都量完了再统一算 left
|
|
1159
1176
|
// 先摆子、再回头把父摆在子的垂直中线上 —— 父先占位的话,父会挂在子树的头顶上,不是树
|
|
1160
1177
|
function place(nodes, depth, prefix) {
|
|
1161
1178
|
var out = [];
|
|
1162
1179
|
nodes.forEach(function (n, i) {
|
|
1163
1180
|
var path = prefix ? prefix + '.' + i : String(i);
|
|
1164
|
-
var
|
|
1165
|
-
el
|
|
1166
|
-
el.dataset.path = path;
|
|
1167
|
-
el.innerHTML = '<div class="mt">' + esc(n.title) + '</div>';
|
|
1181
|
+
var hasKids = !!(n.kids && n.kids.length);
|
|
1182
|
+
var el = createCanvasCard(n.title, 'mnode');
|
|
1183
|
+
el.dataset.path = path; el.dataset.contentId = n.card || n.id || '__document';
|
|
1168
1184
|
// 记下这张小卡片对应文档里的哪张卡 —— 画关系边的时候要靠它对上号
|
|
1169
1185
|
if (n.card) el.dataset.card = n.card;
|
|
1170
|
-
|
|
1171
|
-
el.
|
|
1172
|
-
|
|
1186
|
+
if (n.md && n.md.trim()) el.classList.add('has-body');
|
|
1187
|
+
$('.body', el).appendChild(mdToBody(n.md));
|
|
1188
|
+
var savedSize = MIND_CARD_STATE[el.dataset.contentId];
|
|
1189
|
+
if (savedSize && savedSize.width) el.style.width = savedSize.width + 'px';
|
|
1190
|
+
if (savedSize && savedSize.height) el.style.height = savedSize.height + 'px';
|
|
1191
|
+
mind.appendChild(el); bindMindCard(el);
|
|
1192
|
+
ALL.push({ el: el, depth: depth });
|
|
1173
1193
|
var b = { el: el, kids: [] };
|
|
1174
1194
|
var from = cursor;
|
|
1175
|
-
if (
|
|
1195
|
+
if (hasKids) {
|
|
1176
1196
|
b.kids = place(n.kids, depth + 1, path);
|
|
1177
1197
|
var f = b.kids[0].el, l = b.kids[b.kids.length - 1].el;
|
|
1178
1198
|
var mid = (f.offsetTop + l.offsetTop + l.offsetHeight) / 2;
|
|
1179
|
-
|
|
1199
|
+
var top = mid - el.offsetHeight / 2;
|
|
1200
|
+
if (top < from) {
|
|
1201
|
+
var shift = from - top;
|
|
1202
|
+
(function shiftChildren(branches) {
|
|
1203
|
+
branches.forEach(function (branch) {
|
|
1204
|
+
branch.el.style.top = (parseFloat(branch.el.style.top) + shift) + 'px';
|
|
1205
|
+
shiftChildren(branch.kids);
|
|
1206
|
+
});
|
|
1207
|
+
})(b.kids);
|
|
1208
|
+
cursor += shift; top = from;
|
|
1209
|
+
}
|
|
1210
|
+
el.style.top = top + 'px';
|
|
1180
1211
|
} else {
|
|
1181
1212
|
el.style.top = cursor + 'px';
|
|
1182
1213
|
cursor += el.offsetHeight + GY;
|
|
@@ -1193,12 +1224,31 @@
|
|
|
1193
1224
|
};
|
|
1194
1225
|
var all = place([root], 0, '');
|
|
1195
1226
|
all.forEach(function (r) { r.el.classList.add('root'); });
|
|
1227
|
+
/*
|
|
1228
|
+
* 每一列取这一列最宽的那个节点当列宽,再按列累加出 x —— 宽度是内容说了算,
|
|
1229
|
+
* 列里最宽的那张决定下一列从哪开始,列与列之间才不会叠在一起。
|
|
1230
|
+
*/
|
|
1231
|
+
var colW = [];
|
|
1232
|
+
ALL.forEach(function (x) {
|
|
1233
|
+
colW[x.depth] = Math.max(colW[x.depth] || 0, x.el.offsetWidth);
|
|
1234
|
+
});
|
|
1235
|
+
var colX = [], acc = X0;
|
|
1236
|
+
for (var ci = 0; ci < colW.length; ci++) {
|
|
1237
|
+
colX[ci] = acc;
|
|
1238
|
+
acc += (colW[ci] || 0) + GX;
|
|
1239
|
+
}
|
|
1240
|
+
ALL.forEach(function (x) { x.el.style.left = colX[x.depth] + 'px'; applyMindCardPlacement(x.el); });
|
|
1196
1241
|
var w = 0, h = 0;
|
|
1197
1242
|
$$('.mnode', mind).forEach(function (n) {
|
|
1198
1243
|
w = Math.max(w, n.offsetLeft + n.offsetWidth);
|
|
1199
1244
|
h = Math.max(h, n.offsetTop + n.offsetHeight);
|
|
1200
1245
|
});
|
|
1201
1246
|
box = { w: w + X0, h: h + Y0 };
|
|
1247
|
+
drawMindWires();
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
function drawMindWires() {
|
|
1251
|
+
var mind = $('#mind');
|
|
1202
1252
|
/*
|
|
1203
1253
|
* ★ 文档里的关系边(正文里 [文字](目标) 连出来的那些)也要画在脑图上。
|
|
1204
1254
|
* 原来脑图只有「树」的线 —— 那是标题嵌套长出来的父子线,文档里真正
|
|
@@ -1217,29 +1267,34 @@
|
|
|
1217
1267
|
var A = nodeOf[e[0]], B = nodeOf[e[1]];
|
|
1218
1268
|
if (!A || !B) return;
|
|
1219
1269
|
var ax = A.offsetLeft, aw = A.offsetWidth, bx = B.offsetLeft, bw = B.offsetWidth;
|
|
1220
|
-
var x1 = ax + aw, x2 = bx;
|
|
1221
|
-
if (bx < ax) { x1 = ax; x2 = bx + bw; } // 反向的边从左边出去
|
|
1222
|
-
if (x2 === x1) return;
|
|
1223
1270
|
var y1 = A.offsetTop + A.offsetHeight / 2, y2 = B.offsetTop + B.offsetHeight / 2;
|
|
1224
|
-
var
|
|
1225
|
-
|
|
1271
|
+
var x1, x2, c1, c2;
|
|
1272
|
+
if (Math.abs(ax - bx) < 1) {
|
|
1273
|
+
/*
|
|
1274
|
+
* ★ 同一列的边:卡片节点全在第一列,左右边完全重合。原来 x1 取源卡右边、
|
|
1275
|
+
* x2 取目标卡左边,等于横穿整列卡片画一道弧 —— 看着就像「所有线都是从
|
|
1276
|
+
* 一级那一列拉出来的」,而不是从某张卡出来。改成两头都钉在右边、向右
|
|
1277
|
+
* 鼓出去再绕回来:线从哪张卡出、进哪张卡,一眼能对上。
|
|
1278
|
+
*/
|
|
1279
|
+
x1 = ax + aw; x2 = bx + bw;
|
|
1280
|
+
var bulge = Math.max(x1, x2) + 44;
|
|
1281
|
+
c1 = bulge; c2 = bulge;
|
|
1282
|
+
} else if (bx < ax) { x1 = ax; x2 = bx + bw; c1 = (x1 + x2) / 2; c2 = c1; }
|
|
1283
|
+
else { x1 = ax + aw; x2 = bx; c1 = (x1 + x2) / 2; c2 = c1; }
|
|
1284
|
+
if (x2 === x1 && c1 === x1) return;
|
|
1285
|
+
d += '<path class="edge" d="M' + x1 + ' ' + y1 + ' C' + c1 + ' ' + y1 + ' ' + c2 + ' ' + y2 + ' ' + x2 + ' ' + y2 + '"/>';
|
|
1226
1286
|
});
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1287
|
+
var byPath = {};
|
|
1288
|
+
$$('.mnode', mind).forEach(function (el) { byPath[el.dataset.path] = el; });
|
|
1289
|
+
Object.keys(byPath).forEach(function (path) {
|
|
1290
|
+
var child = byPath[path], parent = byPath[path.slice(0, path.lastIndexOf('.'))];
|
|
1291
|
+
if (!parent || !path.includes('.')) return;
|
|
1292
|
+
var x1 = parent.offsetLeft + parent.offsetWidth, x2 = child.offsetLeft;
|
|
1293
|
+
var input1 = $('.hbar', parent), input2 = $('.hbar', child);
|
|
1294
|
+
var y1 = parent.offsetTop + input1.offsetTop + input1.offsetHeight / 2;
|
|
1295
|
+
var y2 = child.offsetTop + input2.offsetTop + input2.offsetHeight / 2, mx = (x1 + x2) / 2;
|
|
1296
|
+
d += '<path d="M' + x1 + ' ' + y1 + ' C' + mx + ' ' + y1 + ' ' + mx + ' ' + y2 + ' ' + x2 + ' ' + y2 + '"/>';
|
|
1234
1297
|
});
|
|
1235
|
-
all.forEach(function (r) { (function start(p) {
|
|
1236
|
-
var x1 = p.el.offsetLeft + p.el.offsetWidth, y1 = p.el.offsetTop + p.el.offsetHeight / 2;
|
|
1237
|
-
p.kids.forEach(function (k) {
|
|
1238
|
-
var x2 = k.el.offsetLeft, y2 = k.el.offsetTop + k.el.offsetHeight / 2, mx = (x1 + x2) / 2;
|
|
1239
|
-
d += '<path d="M' + x1 + ' ' + y1 + ' C' + mx + ' ' + y1 + ' ' + mx + ' ' + y2 + ' ' + x2 + ' ' + y2 + '"/>';
|
|
1240
|
-
start(k);
|
|
1241
|
-
});
|
|
1242
|
-
})(r); });
|
|
1243
1298
|
svg.innerHTML = d;
|
|
1244
1299
|
}
|
|
1245
1300
|
|
|
@@ -1286,9 +1341,11 @@
|
|
|
1286
1341
|
}
|
|
1287
1342
|
|
|
1288
1343
|
(function bindLens() {
|
|
1344
|
+
var st = $('#lensStage');
|
|
1345
|
+
var pointer = null, dragged = false, sx = 0, sy = 0, ox = 0, oy = 0;
|
|
1289
1346
|
document.addEventListener('click', function (e) {
|
|
1290
1347
|
var z = e.target.closest('.zoomable');
|
|
1291
|
-
if (z) {
|
|
1348
|
+
if (z && !e.target.closest('a.edge')) {
|
|
1292
1349
|
var media = $('svg,img', z), code = $('pre', z), tbl = $('table', z);
|
|
1293
1350
|
if (media) openLens(media.outerHTML, z.dataset.label, 'media');
|
|
1294
1351
|
else if (code) openLens(code.outerHTML, z.dataset.label, 'code');
|
|
@@ -1298,20 +1355,10 @@
|
|
|
1298
1355
|
var a = e.target.closest('a.edge');
|
|
1299
1356
|
if (a) { e.preventDefault(); flash(a.dataset.edge); }
|
|
1300
1357
|
});
|
|
1301
|
-
document.addEventListener('click', function (e) {
|
|
1302
|
-
if (e.target.closest('.zoomable') || e.target.closest('a.edge')) return;
|
|
1303
|
-
var m = document.body.dataset.mode;
|
|
1304
|
-
if (m === 'mindmap') {
|
|
1305
|
-
var n = e.target.closest('.mnode');
|
|
1306
|
-
focusPath(n ? n.dataset.path : null);
|
|
1307
|
-
} else if (m === 'doc') {
|
|
1308
|
-
var x = e.target.closest('#article .slice-head') || e.target.closest('.toc a');
|
|
1309
|
-
if (!x) { focusPath(null); return; }
|
|
1310
|
-
focusPath(x.closest('[data-path]').dataset.path);
|
|
1311
|
-
e.preventDefault();
|
|
1312
|
-
}
|
|
1313
|
-
});
|
|
1314
1358
|
$('#lens').addEventListener('click', function (e) {
|
|
1359
|
+
if (dragged) { dragged = false; return; }
|
|
1360
|
+
var selection = window.getSelection();
|
|
1361
|
+
if (selection && !selection.isCollapsed && selection.anchorNode && $('#lensInner').contains(selection.anchorNode)) return;
|
|
1315
1362
|
if (e.target.id === 'lensStage' || e.target.id === 'lens') closeLens();
|
|
1316
1363
|
});
|
|
1317
1364
|
$('#lensClose').addEventListener('click', closeLens);
|
|
@@ -1325,21 +1372,30 @@
|
|
|
1325
1372
|
esc(text) + '</pre>', '构建输出');
|
|
1326
1373
|
};
|
|
1327
1374
|
document.addEventListener('keydown', function (e) { if (e.key === 'Escape') closeLens(); });
|
|
1328
|
-
var st = $('#lensStage');
|
|
1329
|
-
var down = false, sx = 0, sy = 0, ox = 0, oy = 0;
|
|
1330
1375
|
st.addEventListener('pointerdown', function (e) {
|
|
1331
|
-
|
|
1376
|
+
if (pointer !== null) return;
|
|
1377
|
+
dragged = false;
|
|
1378
|
+
if (e.button !== 0 || e.target.closest('pre,table,svg text,svg foreignObject,a')) return;
|
|
1379
|
+
pointer = e.pointerId;
|
|
1332
1380
|
sx = e.clientX; sy = e.clientY; ox = lx; oy = ly;
|
|
1333
|
-
st.setPointerCapture(e.pointerId);
|
|
1334
1381
|
});
|
|
1335
1382
|
st.addEventListener('pointermove', function (e) {
|
|
1336
|
-
if (
|
|
1383
|
+
if (pointer !== e.pointerId) return;
|
|
1384
|
+
if (!dragged) {
|
|
1385
|
+
if (Math.hypot(e.clientX - sx, e.clientY - sy) < 4) return;
|
|
1386
|
+
dragged = true; st.classList.add('drag'); beginPan(); st.setPointerCapture(e.pointerId);
|
|
1387
|
+
}
|
|
1337
1388
|
lx = ox + e.clientX - sx; ly = oy + e.clientY - sy; lensApply();
|
|
1338
1389
|
});
|
|
1339
|
-
|
|
1340
|
-
|
|
1390
|
+
var stopDrag = function (e) {
|
|
1391
|
+
if (pointer !== e.pointerId) return;
|
|
1392
|
+
pointer = null;
|
|
1393
|
+
if (dragged) { st.classList.remove('drag'); endPan(); }
|
|
1394
|
+
};
|
|
1341
1395
|
st.addEventListener('pointerup', stopDrag);
|
|
1342
1396
|
st.addEventListener('pointercancel', stopDrag);
|
|
1397
|
+
st.addEventListener('lostpointercapture', stopDrag);
|
|
1398
|
+
st.addEventListener('pointerleave', function (e) { if (!dragged) stopDrag(e); });
|
|
1343
1399
|
st.addEventListener('wheel', function (e) {
|
|
1344
1400
|
e.preventDefault();
|
|
1345
1401
|
var r = st.getBoundingClientRect(), mx = e.clientX - r.left, my = e.clientY - r.top;
|
|
@@ -1380,7 +1436,7 @@
|
|
|
1380
1436
|
if (!todo.length) return Promise.resolve();
|
|
1381
1437
|
try {
|
|
1382
1438
|
mermaid.initialize({
|
|
1383
|
-
startOnLoad: false, securityLevel: '
|
|
1439
|
+
startOnLoad: false, securityLevel: 'strict',
|
|
1384
1440
|
theme: theme === 'dark' ? 'dark' : 'default',
|
|
1385
1441
|
// 量节点框用的字体必须和页面真正渲染的字体一致,否则 mermaid 按它自己的字体算宽度、
|
|
1386
1442
|
// 我们按页面字体画,节点名就会顶到框边甚至被切掉。
|
|
@@ -1395,7 +1451,7 @@
|
|
|
1395
1451
|
themeVariables: { fontSize: MSIZE + 'px', fontFamily: MFONT },
|
|
1396
1452
|
});
|
|
1397
1453
|
todo.forEach(function (d) {
|
|
1398
|
-
if (d.dataset.src != null) d.
|
|
1454
|
+
if (d.dataset.src != null) d.textContent = d.dataset.src;
|
|
1399
1455
|
d.removeAttribute('data-processed');
|
|
1400
1456
|
d.dataset.mmd = theme;
|
|
1401
1457
|
});
|
|
@@ -1413,24 +1469,18 @@
|
|
|
1413
1469
|
renderMermaid(true).then(afterMedia);
|
|
1414
1470
|
}
|
|
1415
1471
|
|
|
1416
|
-
var HINTS = {
|
|
1417
|
-
doc: '左大纲右正文 · <code>#</code> 到 <code>######</code> 就是层级 · Mermaid 和图片点一下放大',
|
|
1418
|
-
cards: '拖画布看全图 · 点标题展开 / 收起那一节的下游 · 点卡片顶栏点亮这一支 · 点 Mermaid / 代码 / 表格放大',
|
|
1419
|
-
mindmap: '一级标题 = 一棵树 · 二级是子节点 · 逐层展开 · 节点上的灰字就是那一层的「内容」',
|
|
1420
|
-
};
|
|
1421
|
-
|
|
1422
1472
|
function setMode(m) {
|
|
1423
1473
|
document.body.dataset.mode = m;
|
|
1424
1474
|
$$('#modes button').forEach(function (b) { b.classList.toggle('on', b.dataset.mode === m); });
|
|
1425
|
-
$('#hint').innerHTML = HINTS[m] || '';
|
|
1426
|
-
clearLit();
|
|
1427
1475
|
if (m === 'cards') {
|
|
1428
1476
|
requestAnimationFrame(function () {
|
|
1477
|
+
applyVisibility();
|
|
1429
1478
|
layout();
|
|
1430
1479
|
// ★ 从脑图切回来必须重新钉端口:脑图模式下卡片是 display:none,
|
|
1431
1480
|
// 端口的高度是量不出来的(见 placePorts 开头那段)。不重钉的话,
|
|
1432
1481
|
// 端口会一直赖在卡片右上角,直到你去点一次标题才归位。
|
|
1433
1482
|
fit(); repinPorts();
|
|
1483
|
+
keepWiresAlive(1200); // 卡片和镜头都在过渡里,等它们停稳再定稿
|
|
1434
1484
|
});
|
|
1435
1485
|
} else if (m === 'mindmap') {
|
|
1436
1486
|
// 脑图的节点位置是按「当前高度」摆的,所以图渲完必须重摆一次
|
|
@@ -1441,7 +1491,7 @@
|
|
|
1441
1491
|
renderMermaid().then(function () { renderMind(); fit(); });
|
|
1442
1492
|
});
|
|
1443
1493
|
} else {
|
|
1444
|
-
renderMermaid();
|
|
1494
|
+
renderMermaid().then(function () { canvasPlaceMediaJumps($('#article')); });
|
|
1445
1495
|
}
|
|
1446
1496
|
}
|
|
1447
1497
|
|