cladogram 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -345
- package/bin/clado.js +99 -17
- package/examples/showcase/README.md +3 -1
- package/examples/showcase/build.sh +3 -3
- package/package.json +2 -2
- package/skills/clado/SKILL.md +50 -773
- package/skills/clado/examples/09-/345/215/217/344/275/234/347/224/273/345/270/203/backend.md +80 -0
- package/skills/clado/examples/09-/345/215/217/344/275/234/347/224/273/345/270/203/data.md +53 -0
- package/skills/clado/examples/09-/345/215/217/344/275/234/347/224/273/345/270/203/interaction.md +70 -0
- package/skills/clado/examples/09-/345/215/217/344/275/234/347/224/273/345/270/203/overview.md +30 -0
- package/skills/clado/examples/09-/345/215/217/344/275/234/347/224/273/345/270/203/verify.md +35 -0
- package/skills/clado/examples/10-/346/235/203/351/231/220/347/224/263/350/257/267/approval.md +69 -0
- package/skills/clado/examples/10-/346/235/203/351/231/220/347/224/263/350/257/267/data-verify.md +49 -0
- package/skills/clado/examples/10-/346/235/203/351/231/220/347/224/263/350/257/267/interaction.md +47 -0
- package/skills/clado/examples/10-/346/235/203/351/231/220/347/224/263/350/257/267/overview.md +39 -0
- package/skills/clado/examples/11-/344/272/213/346/225/205/345/223/215/345/272/224/evidence.md +42 -0
- package/skills/clado/examples/11-/344/272/213/346/225/205/345/223/215/345/272/224/overview.md +26 -0
- package/skills/clado/examples/11-/344/272/213/346/225/205/345/223/215/345/272/224/response.md +64 -0
- package/skills/clado/examples/12-/346/216/245/345/217/243/345/210/260/344/273/243/347/240/201/api.md +127 -0
- package/skills/clado/examples/12-/346/216/245/345/217/243/345/210/260/344/273/243/347/240/201/caller.md +50 -0
- package/skills/clado/examples/12-/346/216/245/345/217/243/345/210/260/344/273/243/347/240/201/calls.md +185 -0
- package/skills/clado/examples/12-/346/216/245/345/217/243/345/210/260/344/273/243/347/240/201/code.md +249 -0
- package/skills/clado/examples/12-/346/216/245/345/217/243/345/210/260/344/273/243/347/240/201/consumer.md +93 -0
- package/skills/clado/examples/12-/346/216/245/345/217/243/345/210/260/344/273/243/347/240/201/contracts.md +89 -0
- package/skills/clado/examples/12-/346/216/245/345/217/243/345/210/260/344/273/243/347/240/201/data.md +237 -0
- package/skills/clado/examples/12-/346/216/245/345/217/243/345/210/260/344/273/243/347/240/201/overview.md +75 -0
- package/skills/clado/examples/12-/346/216/245/345/217/243/345/210/260/344/273/243/347/240/201/publisher.md +175 -0
- package/skills/clado/examples/12-/346/216/245/345/217/243/345/210/260/344/273/243/347/240/201/verify.md +53 -0
- package/skills/clado/examples/13-/346/216/245/345/217/243/346/226/271/346/263/225/345/210/260SQL/01-/347/224/263/350/257/267/350/275/254/345/215/225.md +499 -0
- package/skills/clado/examples/13-/346/216/245/345/217/243/346/226/271/346/263/225/345/210/260SQL/02-/345/267/262/346/234/211/350/256/242/345/215/225/346/216/245/345/217/243.md +46 -0
- package/skills/clado/examples/13-/346/216/245/345/217/243/346/226/271/346/263/225/345/210/260SQL/03-/350/241/250/347/273/223/346/236/204.md +100 -0
- package/skills/clado/examples/13-/346/216/245/345/217/243/346/226/271/346/263/225/345/210/260SQL/overview.md +47 -0
- package/skills/clado/examples/build.sh +4 -1
- package/skills/clado/references/content-patterns.md +61 -0
- package/skills/clado/references/data.md +37 -0
- package/skills/clado/references/delivery.md +57 -0
- package/skills/clado/references/diagnostics.md +20 -104
- package/skills/clado/references/editing.md +49 -0
- package/skills/clado/references/engineering.md +167 -0
- package/skills/clado/references/flows.md +53 -0
- package/skills/clado/references/interactions.md +46 -0
- package/skills/clado/references/operations.md +39 -0
- package/skills/clado/references/requirements.md +37 -0
- package/skills/clado/references/verification.md +27 -0
- package/src/core/parse.js +59 -12
- package/src/html/app-css.js +52 -71
- package/src/html/canvas-card.js +66 -0
- package/src/html/canvas-chain.js +203 -0
- package/src/html/canvas-focus.js +175 -0
- package/src/html/canvas-ui.css +21 -0
- package/src/html/canvas-ui.js +38 -0
- package/src/html/canvas-wires.js +56 -0
- package/src/html/mindmap-connectors.js +57 -0
- package/src/html/mindmap-media.js +39 -0
- package/src/html/mindmap-motion.js +69 -0
- package/src/html/page.js +21 -6
- package/src/html/runtime-api.js +62 -0
- package/src/html/runtime-fixes.js +41 -0
- package/src/html/runtime.js +195 -159
- package/src/server/assets/editor.css +1 -0
- package/src/server/assets/editor.js +79 -0
- package/src/server/assets/library-canvas.js +90 -0
- package/src/server/assets/library.css +9 -0
- package/src/server/assets/library.html +20 -0
- package/src/server/assets/library.js +94 -0
- package/src/server/assets/tree.js +26 -0
- package/src/server/export.js +53 -0
- package/src/server/workspace.js +95 -0
- package/src/skill/targets.js +18 -9
- package/src/workspace/commands.js +42 -0
- package/src/workspace/documents.js +143 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// 页面运行时的媒体与事件修正。
|
|
2
|
+
export function fixCanvasRuntime(html) {
|
|
3
|
+
const replace = (before, after) => {
|
|
4
|
+
if (html.split(before).length !== 2) throw new Error('运行时修正位置不唯一:' + before);
|
|
5
|
+
html = html.replace(before, after);
|
|
6
|
+
};
|
|
7
|
+
replace("if (e.target.closest('.card')) return;", "if (e.target.closest('.card, .mnode, .zoomable')) return;");
|
|
8
|
+
replace("$('.body', el).appendChild(mdToBody(n.md));", "$('.body', el).appendChild(mdToBody(n.md));\n if (typeof canvasPrepareMindNode === 'function') canvasPrepareMindNode(el, path);");
|
|
9
|
+
// 只有真正拖动后才捕获指针,保留内容上的正常点击。
|
|
10
|
+
replace("if (e.target.id === 'lensStage' || e.target.id === 'lens') closeLens();",
|
|
11
|
+
"if (lensDragged) { lensDragged = false; return; }\n if (e.target.id === 'lensStage' || e.target.id === 'lens') closeLens();");
|
|
12
|
+
replace("var st = $('#lensStage');", "var st = $('#lensStage');\n var lensDragged = false;");
|
|
13
|
+
replace("down = true; st.classList.add('drag'); beginPan();", "down = true; lensDragged = false;");
|
|
14
|
+
replace("st.setPointerCapture(e.pointerId);", "// 指针移动超过阈值时再捕获。");
|
|
15
|
+
replace("lx = ox + e.clientX - sx; ly = oy + e.clientY - sy; lensApply();",
|
|
16
|
+
"if (!lensDragged && Math.hypot(e.clientX - sx, e.clientY - sy) < 4) return;\n if (!lensDragged) { lensDragged = true; st.classList.add('drag'); beginPan(); st.setPointerCapture(e.pointerId); }\n lx = ox + e.clientX - sx; ly = oy + e.clientY - sy; lensApply();");
|
|
17
|
+
// Mermaid 在缩放画布里测量文字会把标签高度一起缩小;在未缩放副本上渲染。
|
|
18
|
+
replace("var r = mermaid.run({ nodes: todo });\n return (r && r.then) ? r.catch(function () {}) : Promise.resolve();", `var host = document.createElement('div');
|
|
19
|
+
host.className = 'canvas-media-measure markdown-body';
|
|
20
|
+
host.setAttribute('aria-hidden', 'true');
|
|
21
|
+
host.style.cssText = 'position:fixed;left:-100000px;top:0;width:1500px;pointer-events:none';
|
|
22
|
+
document.body.appendChild(host);
|
|
23
|
+
var copies = todo.map(function (diagram) {
|
|
24
|
+
var copy = diagram.cloneNode(true);
|
|
25
|
+
host.appendChild(copy);
|
|
26
|
+
return copy;
|
|
27
|
+
});
|
|
28
|
+
var finish = function () {
|
|
29
|
+
copies.forEach(function (copy, i) {
|
|
30
|
+
if (todo[i].isConnected && todo[i].dataset.mmd === theme) todo[i].innerHTML = copy.innerHTML;
|
|
31
|
+
});
|
|
32
|
+
host.remove();
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
return Promise.resolve(mermaid.run({ nodes: copies })).then(finish, finish);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
host.remove();
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
}`);
|
|
40
|
+
return html;
|
|
41
|
+
}
|
package/src/html/runtime.js
CHANGED
|
@@ -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,8 @@
|
|
|
68
72
|
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
69
73
|
}
|
|
70
74
|
|
|
75
|
+
/*__CANVAS_CARD__*/
|
|
76
|
+
|
|
71
77
|
/* ══ ① Markdown → DOM ═══════════════════════════════════════════ */
|
|
72
78
|
|
|
73
79
|
var CODE_LINK = /\[([^\]]+)\]\(([^)\s]+)\)/g;
|
|
@@ -94,7 +100,7 @@
|
|
|
94
100
|
if (anchorOf(m[2])) a.dataset.anchor = anchorOf(m[2]);
|
|
95
101
|
a.title = '指向 ' + m[2] + ',图上有一条线';
|
|
96
102
|
} else {
|
|
97
|
-
a.href = m[2]; a.target = '_blank'; a.rel = 'noopener';
|
|
103
|
+
a.href = /^(?:javascript|data|vbscript):/i.test(m[2].replace(/[\x00-\x20]/g,'')) ? '#' : m[2]; a.target = '_blank'; a.rel = 'noopener';
|
|
98
104
|
}
|
|
99
105
|
a.textContent = m[1];
|
|
100
106
|
frag.appendChild(a);
|
|
@@ -115,7 +121,20 @@
|
|
|
115
121
|
var box = document.createElement('div');
|
|
116
122
|
box.className = 'markdown-body';
|
|
117
123
|
if (!md) return box;
|
|
118
|
-
|
|
124
|
+
var template = document.createElement('template'); template.innerHTML = marked.parse(md);
|
|
125
|
+
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(' '));
|
|
126
|
+
Array.from(template.content.querySelectorAll('*')).forEach(function (element) {
|
|
127
|
+
var tag = element.localName;
|
|
128
|
+
if (!tags.has(tag)) { element.remove(); return; }
|
|
129
|
+
Array.from(element.attributes).forEach(function (attribute) {
|
|
130
|
+
var name=attribute.name, value=attribute.value, allow=['title','alt','width','height','start','align'].includes(name);
|
|
131
|
+
if (name === 'class' && tag === 'code') allow = /^language-[\w+#.-]+$/.test(value);
|
|
132
|
+
if (name === 'href' && tag === 'a') allow = !/^[a-z][a-z0-9+.-]*:/i.test(value.replace(/[\x00-\x20]/g,'')) || /^(https?:|mailto:|tel:)/i.test(value);
|
|
133
|
+
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);
|
|
134
|
+
if (!allow) element.removeAttribute(name);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
box.appendChild(template.content);
|
|
119
138
|
|
|
120
139
|
// 表格:左右到顶、列多了自己左右滑、点一下能放大
|
|
121
140
|
$$('table', box).forEach(function (t) {
|
|
@@ -167,6 +186,7 @@
|
|
|
167
186
|
a.setAttribute('href', '#');
|
|
168
187
|
a.dataset.edge = id;
|
|
169
188
|
if (anchorOf(t)) a.dataset.anchor = anchorOf(t);
|
|
189
|
+
if (anchorIdOf(t)) a.dataset.anchorId = anchorIdOf(t);
|
|
170
190
|
a.title = '指向 ' + t + ',图上有一条线';
|
|
171
191
|
} else {
|
|
172
192
|
a.target = '_blank';
|
|
@@ -184,13 +204,13 @@
|
|
|
184
204
|
// mermaid 量节点文字和画节点文字必须用同一个字体,否则框会差一圈、名字被切
|
|
185
205
|
var MFONT = '-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans","PingFang SC","Microsoft YaHei",Helvetica,Arial,sans-serif';
|
|
186
206
|
var MSIZE = 13;
|
|
187
|
-
var pos = {}, box = { w: 1200, h: 700 }, scale = 1, tx = 0, ty = 0;
|
|
207
|
+
var pos = {}, CARD_PLACEMENTS = {}, box = { w: 1200, h: 700 }, scale = 1, tx = 0, ty = 0;
|
|
188
208
|
|
|
189
209
|
function nodeEl(n) {
|
|
190
210
|
var sec = document.createElement('section');
|
|
191
211
|
sec.className = 'slice';
|
|
192
212
|
sec.style.setProperty('--d', n.d);
|
|
193
|
-
sec.dataset.id = n.id;
|
|
213
|
+
sec.dataset.id = n.id; sec.dataset.level = String(n.d);
|
|
194
214
|
sec.innerHTML = '<div class="slice-head"><div class="h">' + esc(n.title) + '</div></div>';
|
|
195
215
|
sec.appendChild(mdToBody(n.md));
|
|
196
216
|
return sec;
|
|
@@ -199,16 +219,9 @@
|
|
|
199
219
|
function buildCards() {
|
|
200
220
|
var world = $('#world');
|
|
201
221
|
DOC.cards.forEach(function (c) {
|
|
202
|
-
var el =
|
|
203
|
-
el.className = 'card';
|
|
222
|
+
var el = createCanvasCard(c.title, 'card');
|
|
204
223
|
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
224
|
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
225
|
if (c.md) body.appendChild(mdToBody(c.md));
|
|
213
226
|
(function walk(nodes) {
|
|
214
227
|
(nodes || []).forEach(function (n) { body.appendChild(nodeEl(n)); walk(n.kids); });
|
|
@@ -247,15 +260,46 @@
|
|
|
247
260
|
* 用户的原话:「被连接的是一级标题,它一定是实线……如果连接的是 23456 级标题,
|
|
248
261
|
* 它就是虚线」。所以判据是 `a.dataset.anchor` 有没有值。
|
|
249
262
|
*/
|
|
263
|
+
/*
|
|
264
|
+
* ★ 量出来的是**屏幕坐标**,写进去的是卡片自己的坐标系 —— 中间差了画布的缩放倍数。
|
|
265
|
+
* 画布放大缩小时 #world 挂着 transform: scale(k),getBoundingClientRect() 给的是
|
|
266
|
+
* 缩完之后的屏幕像素,而 p.style.top 是卡片内部的 CSS 像素。k ≠ 1 时不除这一下,
|
|
267
|
+
* 端口就按 k 倍偏掉:实测 k=0.502 时 top 从 190.6px 变成 90.7px,
|
|
268
|
+
* 就是「缩放之后点一下卡片,右边那根竖线跑到别处去了」。
|
|
269
|
+
*/
|
|
270
|
+
var kk = 1;
|
|
271
|
+
try {
|
|
272
|
+
kk = new DOMMatrixReadOnly(getComputedStyle($('#world')).transform).a || scale || 1;
|
|
273
|
+
} catch (_) { kk = scale || 1; }
|
|
274
|
+
if (!kk || !isFinite(kk)) kk = 1;
|
|
275
|
+
/*
|
|
276
|
+
* ★ 可见带:正文那一块(标题栏下面到内边距之间的区域)。
|
|
277
|
+
* 端口本来是钉在「写这条边的那一行」上的,可卡片被拖矮之后 .body 会滚,
|
|
278
|
+
* 那一行可能已经滚出可视区 —— 算出来的 top 就跑到卡片下边框外头去了,
|
|
279
|
+
* 而 .card 没有 overflow:hidden(端口故意探出右边一点,见上面的注释),
|
|
280
|
+
* 于是那根竖杠就挂在卡片外面飘着。用户的原话:
|
|
281
|
+
* 「我把卡片纵向收短之后,那个竖杠超出卡片范围了,还在」。
|
|
282
|
+
* 钉的时候夹到可见带里:那一行滚出去了,端口就停在最近的那条边上。
|
|
283
|
+
*/
|
|
284
|
+
var bd = $('.body', cardEl);
|
|
285
|
+
var bandR = (bd || cardEl).getBoundingClientRect();
|
|
286
|
+
var bandTop = bandR.top - cr.top;
|
|
287
|
+
var bandBot = bandR.bottom - cr.top;
|
|
288
|
+
if (!(bandBot > bandTop)) { bandTop = 0; bandBot = cr.height; }
|
|
250
289
|
var put = function (a, soft) {
|
|
251
290
|
var ar = a.getBoundingClientRect();
|
|
252
291
|
var p = document.createElement('span');
|
|
253
292
|
p.className = soft ? 'port soft' : 'port';
|
|
254
293
|
p.dataset.edge = a.dataset.edge;
|
|
255
294
|
if (a.dataset.anchor) p.dataset.anchor = a.dataset.anchor;
|
|
295
|
+
if (a.dataset.anchorId) p.dataset.anchorId = a.dataset.anchorId;
|
|
256
296
|
if (soft) p.dataset.soft = '1';
|
|
257
297
|
p.title = (soft ? '这一行表示关系,连到 ' : '这一行连到 ') + a.dataset.edge;
|
|
258
|
-
|
|
298
|
+
var mid = ar.top - cr.top + ar.height / 2;
|
|
299
|
+
var lo = bandTop + 2, hi = bandBot - 22; // 22 = 端口高 20 + 底下留 2
|
|
300
|
+
if (hi < lo) hi = lo;
|
|
301
|
+
mid = Math.max(lo, Math.min(hi, mid));
|
|
302
|
+
p.style.top = Math.max(2, mid / kk - 10).toFixed(1) + 'px';
|
|
259
303
|
cardEl.appendChild(p);
|
|
260
304
|
};
|
|
261
305
|
$$('.slice', cardEl).forEach(function (sl) {
|
|
@@ -669,6 +713,7 @@
|
|
|
669
713
|
DOC.cards.forEach(function (c) {
|
|
670
714
|
var el = render.card[c.id];
|
|
671
715
|
if (!pos[c.id]) return;
|
|
716
|
+
if (CARD_PLACEMENTS[c.id]) pos[c.id] = Object.assign({},CARD_PLACEMENTS[c.id]);
|
|
672
717
|
el.style.left = pos[c.id].x + 'px';
|
|
673
718
|
el.style.top = pos[c.id].y + 'px';
|
|
674
719
|
maxBottom = Math.max(maxBottom, pos[c.id].y + el.offsetHeight);
|
|
@@ -689,6 +734,36 @@
|
|
|
689
734
|
drawWires();
|
|
690
735
|
}
|
|
691
736
|
|
|
737
|
+
/*
|
|
738
|
+
* ★ 线是照着卡片的**当前渲染位置**画的(getBoundingClientRect),可卡片位置是带
|
|
739
|
+
* CSS 过渡滑过去的(.card 的 left/top 有 .26s),而 pointermove 只在那一瞬间画一次 ——
|
|
740
|
+
* 手指停下来之后卡片还要滑 260ms,线却停在原地,看着就是「线跟不上卡片」。
|
|
741
|
+
* 切模式也一样:layout() 重摆 + fit() 滑镜头都在过渡里,中间量到的位置是半路的,
|
|
742
|
+
* 过渡结束没人再画一次,线就永远停在半路上(用户给的那套复现步骤:
|
|
743
|
+
* 展开所有儿子 → 把父节点拖到别处 → 切文档再切回卡片)。
|
|
744
|
+
* 用户的原话:「卡片和卡片之间相连的线,在我把卡片快速拖动的时候,它可能会跟不上。
|
|
745
|
+
* 你要么加一个定时器,隔几百毫秒或者一秒就把它重新渲染一次,要么就修复这个问题,
|
|
746
|
+
* 让它永远能跟上」。
|
|
747
|
+
* 所以凡是可能让卡片动起来的地方都叫一次 keepWiresAlive():接下来这段时间里
|
|
748
|
+
* 每帧重画线,隔几帧再整套重钉一次端口,等卡片停稳了自己收手。
|
|
749
|
+
*/
|
|
750
|
+
var WIRE_UNTIL = 0, WIRE_BUSY = 0, WIRE_N = 0;
|
|
751
|
+
function keepWiresAlive(ms) {
|
|
752
|
+
var until = Date.now() + (ms || 700);
|
|
753
|
+
if (until > WIRE_UNTIL) WIRE_UNTIL = until;
|
|
754
|
+
if (WIRE_BUSY) return;
|
|
755
|
+
WIRE_BUSY = 1;
|
|
756
|
+
(function frame() {
|
|
757
|
+
if (document.body.dataset.mode === 'cards') {
|
|
758
|
+
// 端口本身:卡片一挪它就跟着挪(它是卡片的子节点),不用每帧重钉;
|
|
759
|
+
// 但卡片高度在过渡里变的时候得重钉,隔几帧来一次就够。
|
|
760
|
+
if ((WIRE_N++ % 6) === 0) repinPorts(); else drawWires();
|
|
761
|
+
}
|
|
762
|
+
if (Date.now() < WIRE_UNTIL) { requestAnimationFrame(frame); return; }
|
|
763
|
+
WIRE_BUSY = 0;
|
|
764
|
+
})();
|
|
765
|
+
}
|
|
766
|
+
|
|
692
767
|
function drawWires() {
|
|
693
768
|
var world = $('#world'), svg = $('#wires');
|
|
694
769
|
var wr = world.getBoundingClientRect();
|
|
@@ -774,6 +849,18 @@
|
|
|
774
849
|
scale = Math.min(1, Math.max(floor, Math.min((st.width - 80) / cw, (st.height - 80) / ch)));
|
|
775
850
|
tx = Math.max(40, (st.width - cw * scale) / 2) - (b.x1 || 0) * scale;
|
|
776
851
|
ty = Math.max(20, (st.height - ch * scale) / 2) - (b.y1 || 0) * scale;
|
|
852
|
+
// 大图保留可读字号时,以调用入口为首屏;全图顶部可能是远处的子节点。
|
|
853
|
+
if (Math.min((st.width - 80) / cw, (st.height - 80) / ch) < floor) {
|
|
854
|
+
var entry = document.body.dataset.mode === 'mindmap' ? $('#mind .mnode[data-path="0"]') : null;
|
|
855
|
+
if (!entry && document.body.dataset.mode === 'cards') {
|
|
856
|
+
var first = DOC.cards.find(function (card) { return VIS[card.id]; });
|
|
857
|
+
entry = first && render.card[first.id];
|
|
858
|
+
}
|
|
859
|
+
if (entry) {
|
|
860
|
+
tx = 40 - entry.offsetLeft * scale;
|
|
861
|
+
ty = Math.max(24, (st.height - entry.offsetHeight * scale) / 2) - entry.offsetTop * scale;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
777
864
|
apply();
|
|
778
865
|
}
|
|
779
866
|
|
|
@@ -925,7 +1012,7 @@
|
|
|
925
1012
|
/*
|
|
926
1013
|
* 拖画布 / 拖大图的时候不许选中文字。
|
|
927
1014
|
* ★ 关在 body 上,不是关在 #stage 上:拖着往上一划就出了画布、划到顶栏那几个按钮上,
|
|
928
|
-
* 只关 #stage
|
|
1015
|
+
* 只关 #stage 的话顶栏那几个字照样被刷蓝。
|
|
929
1016
|
* CSS 一层(body.dragging *{user-select:none})+ selectstart 一层 ——
|
|
930
1017
|
* 有的浏览器在 pointerdown 那一刻就把选区锚点落下了,只靠 CSS 会留一小段被刷蓝的。
|
|
931
1018
|
*/
|
|
@@ -952,7 +1039,7 @@
|
|
|
952
1039
|
var stopDrag = function () { down = false; stage.classList.remove('drag'); endPan(); };
|
|
953
1040
|
stage.addEventListener('pointerup', stopDrag);
|
|
954
1041
|
stage.addEventListener('pointercancel', stopDrag);
|
|
955
|
-
stage.addEventListener('click', function (e) { if (!e.target.closest('.card')) clearLit(); });
|
|
1042
|
+
stage.addEventListener('click', function (e) { if (!e.target.closest('.card,.mnode')) clearLit(); });
|
|
956
1043
|
stage.addEventListener('wheel', function (e) {
|
|
957
1044
|
// 滚轮落在卡片正文上就整段交给卡片 —— 哪怕滚到底也不许拿去缩放画布
|
|
958
1045
|
if (e.target.closest('.body') || e.target.closest('.tscroll')) {
|
|
@@ -989,60 +1076,10 @@
|
|
|
989
1076
|
|
|
990
1077
|
function bindCards() {
|
|
991
1078
|
DOC.cards.forEach(function (c) {
|
|
992
|
-
var el = render.card[c.id]
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
down = true; beginPan(); sx = e.clientX; sy = e.clientY; ox = pos[c.id].x; oy = pos[c.id].y;
|
|
997
|
-
bar.setPointerCapture(e.pointerId);
|
|
998
|
-
});
|
|
999
|
-
bar.addEventListener('pointermove', function (e) {
|
|
1000
|
-
if (!down) return;
|
|
1001
|
-
pos[c.id].x = ox + (e.clientX - sx) / scale;
|
|
1002
|
-
pos[c.id].y = oy + (e.clientY - sy) / scale;
|
|
1003
|
-
el.style.left = pos[c.id].x + 'px'; el.style.top = pos[c.id].y + 'px';
|
|
1004
|
-
drawWires();
|
|
1005
|
-
});
|
|
1006
|
-
bar.addEventListener('pointerup', function () { down = false; endPan(); });
|
|
1007
|
-
bar.addEventListener('pointercancel', function () { down = false; endPan(); });
|
|
1008
|
-
|
|
1009
|
-
// 右下角拖着改大小(画布是缩放过的,位移要除回 scale)
|
|
1010
|
-
var rz = $('.rz', el);
|
|
1011
|
-
rz.addEventListener('pointerdown', function (e) {
|
|
1012
|
-
e.stopPropagation(); e.preventDefault();
|
|
1013
|
-
beginPan(); // 拖着改大小同样不许顺手选中文字
|
|
1014
|
-
var w0 = el.offsetWidth, px = e.clientX, py = e.clientY;
|
|
1015
|
-
/*
|
|
1016
|
-
* ★ 高度只能**往上缩小**,不能拉到比内容还高。
|
|
1017
|
-
* 所以先把写死的高度摘掉量一次「内容自然高度」nat —— 那才是上限。
|
|
1018
|
-
* 用户的原话:「卡片可以往下拉大,但是不能往上缩小。感觉你正好做反了,
|
|
1019
|
-
* 它应该是可以往上缩小,但是不能往下拉大」。
|
|
1020
|
-
*/
|
|
1021
|
-
var hWas = el.style.height, mWas = el.style.minHeight;
|
|
1022
|
-
el.style.height = ''; el.style.minHeight = '';
|
|
1023
|
-
var nat = el.offsetHeight;
|
|
1024
|
-
el.style.height = hWas; el.style.minHeight = mWas;
|
|
1025
|
-
var h0 = el.offsetHeight;
|
|
1026
|
-
try { rz.setPointerCapture(e.pointerId); } catch (_) {}
|
|
1027
|
-
var move = function (ev) {
|
|
1028
|
-
el.style.width = Math.max(240, w0 + (ev.clientX - px) / scale) + 'px';
|
|
1029
|
-
// 往上拖 = 变小;往下拖最多回到内容自然高度就停住
|
|
1030
|
-
var h = Math.max(110, h0 + (ev.clientY - py) / scale);
|
|
1031
|
-
if (nat > 0) h = Math.min(h, nat);
|
|
1032
|
-
el.style.minHeight = '';
|
|
1033
|
-
el.style.height = h + 'px';
|
|
1034
|
-
placePorts(el); // 宽度变了换行位置也变,端口要重新量
|
|
1035
|
-
drawWires();
|
|
1036
|
-
};
|
|
1037
|
-
var up = function () {
|
|
1038
|
-
rz.removeEventListener('pointermove', move);
|
|
1039
|
-
rz.removeEventListener('pointerup', up);
|
|
1040
|
-
rz.removeEventListener('pointercancel', up);
|
|
1041
|
-
endPan();
|
|
1042
|
-
};
|
|
1043
|
-
rz.addEventListener('pointermove', move);
|
|
1044
|
-
rz.addEventListener('pointerup', up);
|
|
1045
|
-
rz.addEventListener('pointercancel', up);
|
|
1079
|
+
var el = render.card[c.id];
|
|
1080
|
+
bindCanvasCard(el, {
|
|
1081
|
+
move: function (x, y) { pos[c.id] = { x: x, y: y }; CARD_PLACEMENTS[c.id] = {x:x,y:y}; },
|
|
1082
|
+
redraw: function () { placePorts(el); applyVisibility(); drawWires(); keepWiresAlive(600); }
|
|
1046
1083
|
});
|
|
1047
1084
|
|
|
1048
1085
|
// 点端口 = 展开 / 收起这条边下游的整棵子树。端口自己会从灰变蓝、蓝变灰。
|
|
@@ -1052,50 +1089,8 @@
|
|
|
1052
1089
|
toggleEdge(c.id, p.dataset.edge);
|
|
1053
1090
|
});
|
|
1054
1091
|
|
|
1055
|
-
|
|
1056
|
-
* 顶栏(那条 ⠿ 小横条):点亮这一支。
|
|
1057
|
-
* ★ 这个手势原来挂在卡片标题上。用户的标题现在要去「展开 / 收起下游」了,
|
|
1058
|
-
* 一个点击不能既换取景又收放卡片,所以点亮挪到顶栏。
|
|
1059
|
-
*/
|
|
1060
|
-
el.addEventListener('click', function (e) {
|
|
1061
|
-
if (!e.target.closest('.bar')) return;
|
|
1062
|
-
if (el.dataset.lit) { clearLit(); return; }
|
|
1063
|
-
clearLit();
|
|
1064
|
-
// 点亮这张卡 + **它的整条上游链** + 它的整条下游链,其余压暗。
|
|
1065
|
-
// ★ 上游也要亮(用户提的):原来只跟出边,点一张中间的卡时「它是被谁叫起来的」
|
|
1066
|
-
// 全被压暗了,看着像这张卡凭空冒出来。
|
|
1067
|
-
// ★ 必须是传递闭包,不是一跳:用户要的是「这张卡连着的那一整串」。
|
|
1068
|
-
var lit = {}; lit[c.id] = 1;
|
|
1069
|
-
var queue = [c.id];
|
|
1070
|
-
while (queue.length) {
|
|
1071
|
-
var cur = queue.shift();
|
|
1072
|
-
DOC.edges.forEach(function (e2) {
|
|
1073
|
-
if (e2[0] === cur && !lit[e2[1]]) { lit[e2[1]] = 1; queue.push(e2[1]); }
|
|
1074
|
-
if (e2[1] === cur && !lit[e2[0]]) { lit[e2[0]] = 1; queue.push(e2[0]); }
|
|
1075
|
-
});
|
|
1076
|
-
}
|
|
1077
|
-
$$('.card').forEach(function (x) {
|
|
1078
|
-
x.classList.toggle('dim', !lit[x.dataset.id]);
|
|
1079
|
-
x.classList.toggle('lit', x.dataset.id === c.id);
|
|
1080
|
-
});
|
|
1081
|
-
el.dataset.lit = '1';
|
|
1082
|
-
});
|
|
1092
|
+
// 标题点击、双击与长按统一由 canvas-focus.js 处理;拖动柄只负责拖动。
|
|
1083
1093
|
|
|
1084
|
-
/*
|
|
1085
|
-
* 标题:点哪一级,就把那一级**连同它下面的各级**关联到的下游卡全部展开 / 收起。
|
|
1086
|
-
* · 点卡片最大的标题(h1)→ 这一整张卡连出去的全部下游
|
|
1087
|
-
* · 点卡片里的 `##` / `###` / … → 从这一片起,到下一个不比它深的片之前
|
|
1088
|
-
* (层级就是缩进,所以「下一片不比它深」就是这一节的边界)
|
|
1089
|
-
*/
|
|
1090
|
-
el.addEventListener('click', function (e) {
|
|
1091
|
-
if (e.target.closest('.port')) return;
|
|
1092
|
-
if (e.target.closest('.zoomable')) return;
|
|
1093
|
-
var head = e.target.closest('.slice-head');
|
|
1094
|
-
var h1 = e.target.closest('.card-title h1');
|
|
1095
|
-
if (!head && !h1) return;
|
|
1096
|
-
var targets = head ? sliceTargets(el, head.parentNode) : cardTargets(el);
|
|
1097
|
-
toggleEdges(c.id, targets);
|
|
1098
|
-
});
|
|
1099
1094
|
});
|
|
1100
1095
|
}
|
|
1101
1096
|
|
|
@@ -1117,7 +1112,7 @@
|
|
|
1117
1112
|
var sec = document.createElement('section');
|
|
1118
1113
|
sec.className = 'slice';
|
|
1119
1114
|
sec.style.setProperty('--d', 1);
|
|
1120
|
-
sec.dataset.path = String(ci);
|
|
1115
|
+
sec.dataset.path = String(ci); sec.dataset.level = "1";
|
|
1121
1116
|
sec.innerHTML = '<div class="slice-head"><div class="h">' + esc(c.title) + '</div></div>';
|
|
1122
1117
|
if (c.md) sec.appendChild(mdToBody(c.md));
|
|
1123
1118
|
art.appendChild(sec);
|
|
@@ -1128,7 +1123,7 @@
|
|
|
1128
1123
|
var s = document.createElement('section');
|
|
1129
1124
|
s.className = 'slice';
|
|
1130
1125
|
s.style.setProperty('--d', n.d);
|
|
1131
|
-
s.dataset.path = path;
|
|
1126
|
+
s.dataset.path = path; s.dataset.level = String(n.d);
|
|
1132
1127
|
s.innerHTML = '<div class="slice-head"><div class="h">' + esc(n.title) + '</div></div>';
|
|
1133
1128
|
if (n.md) s.appendChild(mdToBody(n.md));
|
|
1134
1129
|
art.appendChild(s);
|
|
@@ -1139,28 +1134,58 @@
|
|
|
1139
1134
|
});
|
|
1140
1135
|
}
|
|
1141
1136
|
|
|
1137
|
+
// 脑图里被收起来的节点:path -> true。双击标题收放,和卡片视图一个手势。
|
|
1138
|
+
var MIND_CLOSED = {}, MIND_CARD_STATE = {};
|
|
1139
|
+
function applyMindCardPlacement(el) {
|
|
1140
|
+
el.dataset.layoutX = el.style.left; el.dataset.layoutY = el.style.top;
|
|
1141
|
+
var state = MIND_CARD_STATE[el.dataset.contentId];
|
|
1142
|
+
if (state) {
|
|
1143
|
+
el.style.left = (parseFloat(el.style.left) + (state.dx || 0)) + 'px';
|
|
1144
|
+
el.style.top = (parseFloat(el.style.top) + (state.dy || 0)) + 'px';
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
function bindMindCard(el) {
|
|
1148
|
+
function state() { return MIND_CARD_STATE[el.dataset.contentId] || (MIND_CARD_STATE[el.dataset.contentId] = {}); }
|
|
1149
|
+
bindCanvasCard(el, {
|
|
1150
|
+
move: function (x, y) { var s = state(); s.dx = x - parseFloat(el.dataset.layoutX); s.dy = y - parseFloat(el.dataset.layoutY); },
|
|
1151
|
+
resize: function (width, height) { var s = state(); s.width = width; s.height = height; },
|
|
1152
|
+
redraw: function () { drawMindWires(); }
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1142
1155
|
function renderMind() {
|
|
1143
1156
|
var mind = $('#mind');
|
|
1144
1157
|
$$('.mnode', mind).forEach(function (n) { n.remove(); });
|
|
1145
|
-
var
|
|
1158
|
+
var GX = 64, GY = 12, X0 = 40, Y0 = 40;
|
|
1146
1159
|
var cursor = Y0;
|
|
1160
|
+
var ALL = []; // 所有节点,等宽度都量完了再统一算 left
|
|
1147
1161
|
// 先摆子、再回头把父摆在子的垂直中线上 —— 父先占位的话,父会挂在子树的头顶上,不是树
|
|
1148
1162
|
function place(nodes, depth, prefix) {
|
|
1149
1163
|
var out = [];
|
|
1150
1164
|
nodes.forEach(function (n, i) {
|
|
1151
1165
|
var path = prefix ? prefix + '.' + i : String(i);
|
|
1152
|
-
var
|
|
1153
|
-
|
|
1154
|
-
el
|
|
1155
|
-
el.
|
|
1166
|
+
var hasKids = !!(n.kids && n.kids.length);
|
|
1167
|
+
var closed = hasKids && MIND_CLOSED[path];
|
|
1168
|
+
var el = createCanvasCard(n.title, 'mnode');
|
|
1169
|
+
el.dataset.path = path; el.dataset.contentId = n.card || n.id || '__document';
|
|
1156
1170
|
// 记下这张小卡片对应文档里的哪张卡 —— 画关系边的时候要靠它对上号
|
|
1157
1171
|
if (n.card) el.dataset.card = n.card;
|
|
1158
|
-
el.
|
|
1159
|
-
el.
|
|
1160
|
-
|
|
1172
|
+
if (hasKids) el.dataset.kids = String(n.kids.length);
|
|
1173
|
+
if (closed) el.classList.add('closed');
|
|
1174
|
+
$('.body', el).appendChild(mdToBody(n.md));
|
|
1175
|
+
/*
|
|
1176
|
+
* ★ 宽度的自适应:不再写死 300px,改成按内容量(CSS 里 min/max 兜住),
|
|
1177
|
+
* 并按层级补宽 —— 卡片视图里三四五六级标题是往里缩进的,正文可用宽度被
|
|
1178
|
+
* 缩进吃掉一截;脑图里没有缩进,所以更深一层就多给一档,看着才一样宽。
|
|
1179
|
+
*/
|
|
1180
|
+
el.style.minWidth = (240 + Math.min(depth, 5) * 26) + 'px';
|
|
1181
|
+
var savedSize = MIND_CARD_STATE[el.dataset.contentId];
|
|
1182
|
+
if (savedSize && savedSize.width) el.style.width = savedSize.width + 'px';
|
|
1183
|
+
if (savedSize && savedSize.height) el.style.height = savedSize.height + 'px';
|
|
1184
|
+
mind.appendChild(el); bindMindCard(el);
|
|
1185
|
+
ALL.push({ el: el, depth: depth });
|
|
1161
1186
|
var b = { el: el, kids: [] };
|
|
1162
1187
|
var from = cursor;
|
|
1163
|
-
if (
|
|
1188
|
+
if (hasKids && !closed) {
|
|
1164
1189
|
b.kids = place(n.kids, depth + 1, path);
|
|
1165
1190
|
var f = b.kids[0].el, l = b.kids[b.kids.length - 1].el;
|
|
1166
1191
|
var mid = (f.offsetTop + l.offsetTop + l.offsetHeight) / 2;
|
|
@@ -1181,12 +1206,31 @@
|
|
|
1181
1206
|
};
|
|
1182
1207
|
var all = place([root], 0, '');
|
|
1183
1208
|
all.forEach(function (r) { r.el.classList.add('root'); });
|
|
1209
|
+
/*
|
|
1210
|
+
* 每一列取这一列最宽的那个节点当列宽,再按列累加出 x —— 宽度是内容说了算,
|
|
1211
|
+
* 列里最宽的那张决定下一列从哪开始,列与列之间才不会叠在一起。
|
|
1212
|
+
*/
|
|
1213
|
+
var colW = [];
|
|
1214
|
+
ALL.forEach(function (x) {
|
|
1215
|
+
colW[x.depth] = Math.max(colW[x.depth] || 0, x.el.offsetWidth);
|
|
1216
|
+
});
|
|
1217
|
+
var colX = [], acc = X0;
|
|
1218
|
+
for (var ci = 0; ci < colW.length; ci++) {
|
|
1219
|
+
colX[ci] = acc;
|
|
1220
|
+
acc += (colW[ci] || 0) + GX;
|
|
1221
|
+
}
|
|
1222
|
+
ALL.forEach(function (x) { x.el.style.left = colX[x.depth] + 'px'; applyMindCardPlacement(x.el); });
|
|
1184
1223
|
var w = 0, h = 0;
|
|
1185
1224
|
$$('.mnode', mind).forEach(function (n) {
|
|
1186
1225
|
w = Math.max(w, n.offsetLeft + n.offsetWidth);
|
|
1187
1226
|
h = Math.max(h, n.offsetTop + n.offsetHeight);
|
|
1188
1227
|
});
|
|
1189
1228
|
box = { w: w + X0, h: h + Y0 };
|
|
1229
|
+
drawMindWires();
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
function drawMindWires() {
|
|
1233
|
+
var mind = $('#mind');
|
|
1190
1234
|
/*
|
|
1191
1235
|
* ★ 文档里的关系边(正文里 [文字](目标) 连出来的那些)也要画在脑图上。
|
|
1192
1236
|
* 原来脑图只有「树」的线 —— 那是标题嵌套长出来的父子线,文档里真正
|
|
@@ -1205,29 +1249,34 @@
|
|
|
1205
1249
|
var A = nodeOf[e[0]], B = nodeOf[e[1]];
|
|
1206
1250
|
if (!A || !B) return;
|
|
1207
1251
|
var ax = A.offsetLeft, aw = A.offsetWidth, bx = B.offsetLeft, bw = B.offsetWidth;
|
|
1208
|
-
var x1 = ax + aw, x2 = bx;
|
|
1209
|
-
if (bx < ax) { x1 = ax; x2 = bx + bw; } // 反向的边从左边出去
|
|
1210
|
-
if (x2 === x1) return;
|
|
1211
1252
|
var y1 = A.offsetTop + A.offsetHeight / 2, y2 = B.offsetTop + B.offsetHeight / 2;
|
|
1212
|
-
var
|
|
1213
|
-
|
|
1253
|
+
var x1, x2, c1, c2;
|
|
1254
|
+
if (Math.abs(ax - bx) < 1) {
|
|
1255
|
+
/*
|
|
1256
|
+
* ★ 同一列的边:卡片节点全在第一列,左右边完全重合。原来 x1 取源卡右边、
|
|
1257
|
+
* x2 取目标卡左边,等于横穿整列卡片画一道弧 —— 看着就像「所有线都是从
|
|
1258
|
+
* 一级那一列拉出来的」,而不是从某张卡出来。改成两头都钉在右边、向右
|
|
1259
|
+
* 鼓出去再绕回来:线从哪张卡出、进哪张卡,一眼能对上。
|
|
1260
|
+
*/
|
|
1261
|
+
x1 = ax + aw; x2 = bx + bw;
|
|
1262
|
+
var bulge = Math.max(x1, x2) + 44;
|
|
1263
|
+
c1 = bulge; c2 = bulge;
|
|
1264
|
+
} else if (bx < ax) { x1 = ax; x2 = bx + bw; c1 = (x1 + x2) / 2; c2 = c1; }
|
|
1265
|
+
else { x1 = ax + aw; x2 = bx; c1 = (x1 + x2) / 2; c2 = c1; }
|
|
1266
|
+
if (x2 === x1 && c1 === x1) return;
|
|
1267
|
+
d += '<path class="edge" d="M' + x1 + ' ' + y1 + ' C' + c1 + ' ' + y1 + ' ' + c2 + ' ' + y2 + ' ' + x2 + ' ' + y2 + '"/>';
|
|
1214
1268
|
});
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1269
|
+
var byPath = {};
|
|
1270
|
+
$$('.mnode', mind).forEach(function (el) { byPath[el.dataset.path] = el; });
|
|
1271
|
+
Object.keys(byPath).forEach(function (path) {
|
|
1272
|
+
var child = byPath[path], parent = byPath[path.slice(0, path.lastIndexOf('.'))];
|
|
1273
|
+
if (!parent || !path.includes('.')) return;
|
|
1274
|
+
var x1 = parent.offsetLeft + parent.offsetWidth, x2 = child.offsetLeft;
|
|
1275
|
+
var input1 = $('.hbar', parent), input2 = $('.hbar', child);
|
|
1276
|
+
var y1 = parent.offsetTop + input1.offsetTop + input1.offsetHeight / 2;
|
|
1277
|
+
var y2 = child.offsetTop + input2.offsetTop + input2.offsetHeight / 2, mx = (x1 + x2) / 2;
|
|
1278
|
+
d += '<path d="M' + x1 + ' ' + y1 + ' C' + mx + ' ' + y1 + ' ' + mx + ' ' + y2 + ' ' + x2 + ' ' + y2 + '"/>';
|
|
1222
1279
|
});
|
|
1223
|
-
all.forEach(function (r) { (function start(p) {
|
|
1224
|
-
var x1 = p.el.offsetLeft + p.el.offsetWidth, y1 = p.el.offsetTop + p.el.offsetHeight / 2;
|
|
1225
|
-
p.kids.forEach(function (k) {
|
|
1226
|
-
var x2 = k.el.offsetLeft, y2 = k.el.offsetTop + k.el.offsetHeight / 2, mx = (x1 + x2) / 2;
|
|
1227
|
-
d += '<path d="M' + x1 + ' ' + y1 + ' C' + mx + ' ' + y1 + ' ' + mx + ' ' + y2 + ' ' + x2 + ' ' + y2 + '"/>';
|
|
1228
|
-
start(k);
|
|
1229
|
-
});
|
|
1230
|
-
})(r); });
|
|
1231
1280
|
svg.innerHTML = d;
|
|
1232
1281
|
}
|
|
1233
1282
|
|
|
@@ -1286,19 +1335,6 @@
|
|
|
1286
1335
|
var a = e.target.closest('a.edge');
|
|
1287
1336
|
if (a) { e.preventDefault(); flash(a.dataset.edge); }
|
|
1288
1337
|
});
|
|
1289
|
-
document.addEventListener('click', function (e) {
|
|
1290
|
-
if (e.target.closest('.zoomable') || e.target.closest('a.edge')) return;
|
|
1291
|
-
var m = document.body.dataset.mode;
|
|
1292
|
-
if (m === 'mindmap') {
|
|
1293
|
-
var n = e.target.closest('.mnode');
|
|
1294
|
-
focusPath(n ? n.dataset.path : null);
|
|
1295
|
-
} else if (m === 'doc') {
|
|
1296
|
-
var x = e.target.closest('#article .slice-head') || e.target.closest('.toc a');
|
|
1297
|
-
if (!x) { focusPath(null); return; }
|
|
1298
|
-
focusPath(x.closest('[data-path]').dataset.path);
|
|
1299
|
-
e.preventDefault();
|
|
1300
|
-
}
|
|
1301
|
-
});
|
|
1302
1338
|
$('#lens').addEventListener('click', function (e) {
|
|
1303
1339
|
if (e.target.id === 'lensStage' || e.target.id === 'lens') closeLens();
|
|
1304
1340
|
});
|
|
@@ -1368,7 +1404,7 @@
|
|
|
1368
1404
|
if (!todo.length) return Promise.resolve();
|
|
1369
1405
|
try {
|
|
1370
1406
|
mermaid.initialize({
|
|
1371
|
-
startOnLoad: false, securityLevel: '
|
|
1407
|
+
startOnLoad: false, securityLevel: 'strict',
|
|
1372
1408
|
theme: theme === 'dark' ? 'dark' : 'default',
|
|
1373
1409
|
// 量节点框用的字体必须和页面真正渲染的字体一致,否则 mermaid 按它自己的字体算宽度、
|
|
1374
1410
|
// 我们按页面字体画,节点名就会顶到框边甚至被切掉。
|
|
@@ -1383,7 +1419,7 @@
|
|
|
1383
1419
|
themeVariables: { fontSize: MSIZE + 'px', fontFamily: MFONT },
|
|
1384
1420
|
});
|
|
1385
1421
|
todo.forEach(function (d) {
|
|
1386
|
-
if (d.dataset.src != null) d.
|
|
1422
|
+
if (d.dataset.src != null) d.textContent = d.dataset.src;
|
|
1387
1423
|
d.removeAttribute('data-processed');
|
|
1388
1424
|
d.dataset.mmd = theme;
|
|
1389
1425
|
});
|
|
@@ -1419,6 +1455,7 @@
|
|
|
1419
1455
|
// 端口的高度是量不出来的(见 placePorts 开头那段)。不重钉的话,
|
|
1420
1456
|
// 端口会一直赖在卡片右上角,直到你去点一次标题才归位。
|
|
1421
1457
|
fit(); repinPorts();
|
|
1458
|
+
keepWiresAlive(1200); // 卡片和镜头都在过渡里,等它们停稳再定稿
|
|
1422
1459
|
});
|
|
1423
1460
|
} else if (m === 'mindmap') {
|
|
1424
1461
|
// 脑图的节点位置是按「当前高度」摆的,所以图渲完必须重摆一次
|
|
@@ -1450,7 +1487,6 @@
|
|
|
1450
1487
|
// 默认只展开根,按整张图的尺寸缩的话,唯一那张卡会缩成角落里的一个小点。
|
|
1451
1488
|
VIS = visibleSet();
|
|
1452
1489
|
|
|
1453
|
-
if (CMD) $('#cmd').textContent = CMD;
|
|
1454
1490
|
// 主题三级兜底:本机上次切过的 > 编译时写进 <html data-theme> 的 > light。
|
|
1455
1491
|
// 中间那一级就是 `--theme=dark` 生效的地方 —— 少了它,那个旗标收下来也没人看。
|
|
1456
1492
|
var t = document.documentElement.dataset.theme || 'light';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.document-main{min-width:0}.document-controls{display:flex;align-items:center;width:100%;box-sizing:border-box;margin:0 0 20px;padding:0}.document-view-tabs{display:flex;width:100%;box-sizing:border-box;padding:2px;gap:2px;background:var(--bg);border:1px solid var(--line);border-radius:7px}.document-controls button,.document-editor button{font:inherit;font-size:12px;cursor:pointer;border:1px solid var(--line);border-radius:6px;background:var(--panel);color:var(--fg);padding:7px 13px}.document-view-tabs button{flex:1;min-width:0;height:26px;padding:3px 10px;line-height:18px;border-color:transparent;background:transparent}.document-view-tabs button[aria-pressed="true"]{background:var(--panel);border-color:var(--line);color:var(--accent)}.document-controls button:disabled,.document-editor button:disabled{cursor:default;opacity:.55}.document-edit-status{display:block;min-width:0;margin:0 0 16px;overflow-wrap:anywhere;font-size:12px;line-height:1.6;color:var(--fg-2)}.document-edit-status:empty{display:none}.document-editor{display:flex;flex-direction:column;gap:12px;min-height:calc(100vh - 195px)}.document-editor[hidden],.document-main>#article[hidden],.document-editor [hidden]{display:none!important}.document-editor label{font-size:12px;color:var(--fg-2)}.document-file{display:flex;flex-direction:column;gap:7px}.document-editor input,.document-editor textarea{box-sizing:border-box;width:100%;border:1px solid var(--line);border-radius:8px;background:var(--bg);color:var(--fg);outline-color:var(--accent)}.document-editor input{font:13px/1.6 ui-monospace,monospace;padding:9px 12px}.document-editor textarea{flex:1;min-height:420px;resize:vertical;font:13px/1.8 ui-monospace,SFMono-Regular,Consolas,monospace;padding:16px;tab-size:2}.document-editor-actions{display:flex;align-items:flex-start;gap:9px;padding:2px 0 12px}.document-editor-message{flex:1;font-size:12px;line-height:1.7;color:var(--fg-2);white-space:pre-wrap;overflow-wrap:anywhere}.document-editor button[type="submit"]{background:var(--accent);border-color:var(--accent);color:white}.document-editor-actions button{flex-shrink:0}@media(max-width:700px){.document-controls{gap:9px;flex-wrap:wrap}.document-editor textarea{min-height:55vh}.document-editor-actions{flex-wrap:wrap}.document-editor-message{flex-basis:100%}}
|