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,175 @@
|
|
|
1
|
+
// 三视图共用内容 ID、聚焦范围与标题手势。
|
|
2
|
+
var canvasRecords = {}, canvasDocPaths = {}, canvasMindPaths = {}, canvasFocusId = null;
|
|
3
|
+
var canvasDocClosed = {}, canvasContentClosed = {}, canvasCardClosed = {}, canvasClickTimer = 0;
|
|
4
|
+
(function () {
|
|
5
|
+
function add(n, docPath, parent, card) {
|
|
6
|
+
var r = { id: n.id, title: n.title, parent: parent, card: card, docPath: docPath, mindPath: '0.' + docPath, kids: [] };
|
|
7
|
+
r.fullPath = parent ? canvasRecords[parent].fullPath + '.' + n.title : n.title;
|
|
8
|
+
canvasRecords[r.id] = r; canvasDocPaths[docPath] = r; canvasMindPaths[r.mindPath] = r;
|
|
9
|
+
(n.nodes || n.kids || []).forEach(function (child, i) { r.kids.push(child.id); add(child, docPath + '.' + i, r.id, card); });
|
|
10
|
+
}
|
|
11
|
+
DOC.cards.forEach(function (card, i) { add(card, String(i), null, card.id); });
|
|
12
|
+
})();
|
|
13
|
+
function canvasPrepareMindNode() { /* 正文始终保留;只折叠后代。 */ }
|
|
14
|
+
var canvasOut = {}, canvasIn = {};
|
|
15
|
+
$$('#article .slice[data-path]').forEach(function (section) {
|
|
16
|
+
var source = canvasDocPaths[section.dataset.path]; if (!source) return;
|
|
17
|
+
$$('a.edge', section).forEach(function (link) {
|
|
18
|
+
var target = canvasRecords[link.dataset.edge]; if (!target) return;
|
|
19
|
+
if (link.dataset.anchorId) target = canvasRecords[link.dataset.anchorId] || target;
|
|
20
|
+
else if (link.dataset.anchor) target = Object.values(canvasRecords).find(function (r) { return r.card === target.card && r.title === link.dataset.anchor; }) || target;
|
|
21
|
+
if (source.id === target.id) return;
|
|
22
|
+
(canvasOut[source.id] || (canvasOut[source.id] = new Set())).add(target.id);
|
|
23
|
+
(canvasIn[target.id] || (canvasIn[target.id] = new Set())).add(source.id);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
function canvasFocusSet() {
|
|
27
|
+
if (!canvasFocusId) return null;
|
|
28
|
+
if (canvasFocusId === '__document') return new Set(Object.keys(canvasRecords));
|
|
29
|
+
var lit = new Set();
|
|
30
|
+
function walk(direction) {
|
|
31
|
+
var queue = [canvasFocusId], seen = new Set();
|
|
32
|
+
while (queue.length) {
|
|
33
|
+
var id = queue.shift(); if (seen.has(id)) continue; seen.add(id); lit.add(id);
|
|
34
|
+
var r = canvasRecords[id]; if (!r) continue;
|
|
35
|
+
if (direction === 'down') queue.push.apply(queue, r.kids);
|
|
36
|
+
else if (r.parent) queue.push(r.parent);
|
|
37
|
+
var links = (direction === 'down' ? canvasOut : canvasIn)[id];
|
|
38
|
+
if (links) links.forEach(function (next) { queue.push(next); });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// 上游与下游分别遍历,避免经上游再扩散到无关的兄弟分支。
|
|
42
|
+
walk('up'); walk('down'); return lit;
|
|
43
|
+
}
|
|
44
|
+
function canvasApplyFocus() {
|
|
45
|
+
var lit = canvasFocusSet();
|
|
46
|
+
$$('.focus-muted,.focus-selected,.focus-line,.focus-line-muted').forEach(function (el) { el.classList.remove('focus-muted', 'focus-selected', 'focus-line', 'focus-line-muted'); });
|
|
47
|
+
if (!lit) return;
|
|
48
|
+
$$('#mind .mnode').forEach(function (el) {
|
|
49
|
+
var r = canvasMindPaths[el.dataset.path];
|
|
50
|
+
if (el.dataset.path === '0') { el.classList.toggle('focus-selected', canvasFocusId === '__document'); return; }
|
|
51
|
+
if (!r) return;
|
|
52
|
+
el.classList.toggle('focus-muted', !lit.has(r.id)); el.classList.toggle('focus-selected', r.id === canvasFocusId);
|
|
53
|
+
});
|
|
54
|
+
$$('#world > .card').forEach(function (el) {
|
|
55
|
+
var relevant = Object.values(canvasRecords).some(function (r) { return r.card === el.dataset.id && lit.has(r.id); });
|
|
56
|
+
el.classList.toggle('focus-muted', !relevant);
|
|
57
|
+
var selected = canvasRecords[canvasFocusId]; el.classList.toggle('focus-selected', !!selected && selected.card === el.dataset.id);
|
|
58
|
+
$$('.slice[data-id]', el).forEach(function (slice) { slice.classList.toggle('focus-muted', !lit.has(slice.dataset.id)); });
|
|
59
|
+
});
|
|
60
|
+
$$('#article .slice[data-path]').forEach(function (el) { var r = canvasDocPaths[el.dataset.path]; if (r) { el.classList.toggle('focus-muted', !lit.has(r.id)); el.classList.toggle('focus-selected', r.id === canvasFocusId); } });
|
|
61
|
+
$$('#toc a[data-path]').forEach(function (el) { var r = canvasDocPaths[el.dataset.path]; if (r) { el.classList.toggle('focus-muted', !lit.has(r.id)); el.classList.toggle('on', r.id === canvasFocusId); } });
|
|
62
|
+
$$('#wires path,#mwires path').forEach(function (path) {
|
|
63
|
+
var from = path.dataset.sourceId, to = path.dataset.targetId;
|
|
64
|
+
var related = (from === '__document' || lit.has(from)) && lit.has(to);
|
|
65
|
+
path.classList.toggle('focus-line', related); path.classList.toggle('focus-line-muted', !related);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
var canvasClearLit = clearLit;
|
|
69
|
+
clearLit = function () { canvasFocusId = null; canvasClearLit(); canvasApplyFocus(); };
|
|
70
|
+
function canvasFocusContent(id) {
|
|
71
|
+
var next = canvasFocusId === id ? null : id;
|
|
72
|
+
canvasClearLit(); canvasFocusId = next; canvasApplyFocus();
|
|
73
|
+
}
|
|
74
|
+
focusPath = function (path) {
|
|
75
|
+
if (path == null) { clearLit(); return; }
|
|
76
|
+
var r = (document.body.dataset.mode === 'mindmap' ? canvasMindPaths : canvasDocPaths)[path];
|
|
77
|
+
canvasFocusContent(path === '0' && document.body.dataset.mode === 'mindmap' ? '__document' : r && r.id);
|
|
78
|
+
};
|
|
79
|
+
var canvasSetMode = setMode;
|
|
80
|
+
setMode = function (mode) {
|
|
81
|
+
var selected = canvasFocusId; canvasSetMode(mode); canvasFocusId = selected;
|
|
82
|
+
requestAnimationFrame(canvasApplyFocus);
|
|
83
|
+
};
|
|
84
|
+
var canvasDrawWires = drawWires;
|
|
85
|
+
drawWires = function () { canvasDrawWires(); canvasApplyFocus(); };
|
|
86
|
+
var canvasRenderMindFocus = renderMind;
|
|
87
|
+
renderMind = function () { canvasRenderMindFocus(); canvasApplyFocus(); };
|
|
88
|
+
var canvasApplyVisibility = applyVisibility;
|
|
89
|
+
applyVisibility = function () { canvasApplyVisibility(); canvasApplyFocus(); };
|
|
90
|
+
|
|
91
|
+
function canvasDocumentFolds() {
|
|
92
|
+
$$('#article .slice[data-path]').forEach(function (section) {
|
|
93
|
+
var r = canvasDocPaths[section.dataset.path]; if (!r) return;
|
|
94
|
+
var parent = r.parent, hidden = false;
|
|
95
|
+
while (parent) { if (canvasDocClosed[parent]) hidden = true; parent = canvasRecords[parent].parent; }
|
|
96
|
+
section.hidden = hidden;
|
|
97
|
+
var closed = !!r.kids.length && !!canvasDocClosed[r.id]; section.classList.toggle('document-folded', closed);
|
|
98
|
+
$('.slice-head', section).setAttribute('aria-expanded', String(!closed));
|
|
99
|
+
$$('.markdown-body', section).forEach(function (body) { body.hidden = false; });
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function canvasRecordForTarget(target) {
|
|
103
|
+
var toc = target.closest('#toc a[data-path]'); if (toc) return canvasDocPaths[toc.dataset.path];
|
|
104
|
+
var mind = target.closest('#mind .mnode'); if (mind) return mind.dataset.path === '0' ? { id: '__document', mindPath: '0', kids: DOC.cards.map(function (c) { return c.id; }) } : canvasMindPaths[mind.dataset.path];
|
|
105
|
+
var doc = target.closest('#article .slice[data-path]'); if (doc) return canvasDocPaths[doc.dataset.path];
|
|
106
|
+
var slice = target.closest('#world .card .slice[data-id]'); if (slice) return canvasRecords[slice.dataset.id];
|
|
107
|
+
var card = target.closest('#world > .card'); return card ? canvasRecords[card.dataset.id] : null;
|
|
108
|
+
}
|
|
109
|
+
function canvasCardFolds() {
|
|
110
|
+
$$('#world > .card .slice[data-id]').forEach(function (section) {
|
|
111
|
+
var r = canvasRecords[section.dataset.id]; if (!r) return;
|
|
112
|
+
var parent = r.parent, hidden = false;
|
|
113
|
+
while (parent) { if (canvasCardClosed[parent]) hidden = true; parent = canvasRecords[parent].parent; }
|
|
114
|
+
section.hidden = hidden;
|
|
115
|
+
section.classList.toggle('document-folded', !!r.kids.length && !!canvasCardClosed[r.id]);
|
|
116
|
+
$$('.markdown-body', section).forEach(function (body) { body.hidden = false; });
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function canvasToggleContent(r, target) {
|
|
120
|
+
var mode = document.body.dataset.mode;
|
|
121
|
+
if (mode === 'doc') {
|
|
122
|
+
if (!r.kids.length) return;
|
|
123
|
+
canvasDocClosed[r.id] = !canvasDocClosed[r.id]; canvasDocumentFolds(); canvasApplyFocus(); return;
|
|
124
|
+
}
|
|
125
|
+
if (mode === 'mindmap') {
|
|
126
|
+
if (!r.kids.length) return;
|
|
127
|
+
canvasAnimateMindChange(function () { MIND_CLOSED[r.mindPath] = !MIND_CLOSED[r.mindPath]; renderMind(); }); return;
|
|
128
|
+
}
|
|
129
|
+
var card = target.closest('.card'), head = target.closest('.slice-head');
|
|
130
|
+
if (!card) return;
|
|
131
|
+
var targets = head ? sliceTargets(card, head.parentNode) : cardTargets(card);
|
|
132
|
+
if (r.kids.length) { canvasCardClosed[r.id] = !canvasCardClosed[r.id]; canvasCardFolds(); }
|
|
133
|
+
if (targets.length) toggleEdges(card.dataset.id, targets);
|
|
134
|
+
repinPorts(); drawWires();
|
|
135
|
+
}
|
|
136
|
+
document.addEventListener('click', function (event) {
|
|
137
|
+
if (typeof canvasChainIsOpen === 'function' && (canvasChainIsOpen() || Date.now() < canvasChainSuppressUntil)) return;
|
|
138
|
+
if (!event.target.closest('.card-title h1,.slice-head,#toc a')) return;
|
|
139
|
+
if (event.target.closest('.zoomable,.port,.rz,a:not(#toc a),button')) return;
|
|
140
|
+
var r = canvasRecordForTarget(event.target);
|
|
141
|
+
if (!r) return;
|
|
142
|
+
event.stopImmediatePropagation();
|
|
143
|
+
if (event.target.closest('#toc a')) event.preventDefault();
|
|
144
|
+
clearTimeout(canvasClickTimer);
|
|
145
|
+
if (event.detail > 1) return;
|
|
146
|
+
canvasClickTimer = setTimeout(function () { canvasFocusContent(r.id); }, 240);
|
|
147
|
+
}, true);
|
|
148
|
+
document.addEventListener('dblclick', function (event) {
|
|
149
|
+
if (typeof canvasChainIsOpen === 'function' && (canvasChainIsOpen() || Date.now() < canvasChainSuppressUntil)) return;
|
|
150
|
+
if (!event.target.closest('.card-title h1,.slice-head,#toc a')) return;
|
|
151
|
+
if (event.target.closest('.zoomable,.port,.rz')) return;
|
|
152
|
+
var r = canvasRecordForTarget(event.target); if (!r) return;
|
|
153
|
+
event.preventDefault(); event.stopImmediatePropagation(); clearTimeout(canvasClickTimer);
|
|
154
|
+
canvasToggleContent(r, event.target);
|
|
155
|
+
}, true);
|
|
156
|
+
document.addEventListener('keydown', function (event) {
|
|
157
|
+
if (event.key !== 'Escape') return;
|
|
158
|
+
if (typeof canvasChainIsOpen === 'function' && canvasChainIsOpen()) { event.preventDefault(); event.stopImmediatePropagation(); return; }
|
|
159
|
+
if (event.target.closest('input,textarea,.document-editor')) return;
|
|
160
|
+
clearTimeout(canvasClickTimer);
|
|
161
|
+
if ($('#lens').classList.contains('open')) { closeLens(); event.stopImmediatePropagation(); }
|
|
162
|
+
else clearLit();
|
|
163
|
+
}, true);
|
|
164
|
+
|
|
165
|
+
document.addEventListener('click', function (event) {
|
|
166
|
+
var link=event.target.closest('a.edge');if (!link) return;
|
|
167
|
+
var id=link.dataset.anchorId || link.dataset.edge;
|
|
168
|
+
if (!link.dataset.anchorId && link.dataset.anchor) {
|
|
169
|
+
var found=Object.values(canvasRecords).find(function(r){return r.card===id && r.title===link.dataset.anchor;});if(found)id=found.id;
|
|
170
|
+
}
|
|
171
|
+
if (canvasRecords[id]) {
|
|
172
|
+
if (document.body.dataset.mode === 'doc') $('#article .slice[data-path="' + canvasRecords[id].docPath + '"]').scrollIntoView({ block: 'center' });
|
|
173
|
+
else if (typeof canvasChainCenter === 'function') canvasChainCenter(id);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
:root{--proto-font:14px;--proto-radius:11px;--proto-reading-width:1000px}
|
|
2
|
+
/* 脑图与卡片共用的画布组件。 */
|
|
3
|
+
.top{gap:12px;padding:0 18px;height:52px}.top .canvas-brand{display:flex;align-items:center;gap:9px;min-width:0;flex:1;letter-spacing:0}.top .canvas-brand strong{font-size:17px;font-weight:600;letter-spacing:-.5px;flex-shrink:0}.top .canvas-brand .canvas-brand-mark{display:grid;place-items:center;width:27px;height:27px;flex-shrink:0;background:var(--fg);color:var(--panel);border-radius:8px;margin:0;font-size:15px;font-weight:750}.top .canvas-brand .canvas-brand-divider{display:block;margin:0 4px;width:1px;height:18px;background:var(--line);flex-shrink:0}.top .canvas-brand .canvas-doc-name{display:block;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;font-weight:450;letter-spacing:0;margin:0;color:var(--fg-2)}.top .diag{margin:0;flex-shrink:0}.top .diag[hidden]{display:none}.top .seg{flex-shrink:0}.top .icon{flex-shrink:0}.issues-badge{display:inline-flex;align-items:center;border:1px solid #d4a72c66;background:#fff8c5;color:#896214;border-radius:20px;padding:4px 10px;font:inherit;font-size:11px;line-height:1.6;cursor:pointer;white-space:nowrap}.issues-badge.has-errors{background:#ffebe9;border-color:#cf222e55;color:#cf222e}[data-theme="dark"] .issues-badge{background:#2d2612;border-color:#9e6a0366;color:#d29922}[data-theme="dark"] .issues-badge.has-errors{background:#3a1518;border-color:#cf222e66;color:#f85149}#stage,#doc{top:52px}.hint{display:none!important}
|
|
4
|
+
.canvas-card{background:var(--panel);border:1px solid var(--line);border-radius:var(--proto-radius);box-shadow:var(--shadow)}.mnode{max-width:500px}.canvas-card .markdown-body{background:transparent;font-size:calc(var(--proto-font) - 1.5px);line-height:1.55}.canvas-card .card-title h1{font-size:17.5px;font-weight:700;line-height:1.3;letter-spacing:-.2px;margin:0 0 6px!important}.mnode.root{border-width:1px;border-color:var(--accent)}.canvas-card .markdown-body p{margin:0 0 6px}.canvas-card .markdown-body p:last-child{margin-bottom:0}.canvas-card .markdown-body pre{margin:6px 0 0;padding:7px 9px;border-radius:7px;border:1px solid var(--line-2);white-space:pre-wrap;overflow-wrap:anywhere;font-size:11.5px;line-height:1.55}.canvas-card .markdown-body pre code{background:transparent;padding:0;font-size:inherit;white-space:inherit}.canvas-card .markdown-body code{font-family:ui-monospace,SFMono-Regular,"SF Mono",Menlo,monospace;font-size:11.5px;background:var(--bg);padding:.12em .35em;border-radius:4px}.canvas-card .markdown-body .ztable table th,.canvas-card .markdown-body .ztable table td{white-space:normal!important;word-break:break-word}.canvas-card .markdown-body ul,.canvas-card .markdown-body ol{padding-left:18px;margin:0 0 6px}
|
|
5
|
+
.canvas-card .markdown-body a{color:var(--accent);text-decoration:none;border-bottom:1px solid color-mix(in srgb,var(--accent) 35%,transparent)}.canvas-card .markdown-body a:hover{background:var(--accent-soft)}.canvas-card .markdown-body a.edge{color:inherit;border-bottom:0;text-decoration:underline;text-decoration-style:dotted;text-decoration-thickness:1px;text-decoration-color:var(--line-2);text-underline-offset:2.5px}.canvas-card .markdown-body a.edge:hover{color:var(--accent);background:transparent;text-decoration-color:var(--accent)}
|
|
6
|
+
.canvas-card>.hbar{top:37px;left:-2px;width:4px;height:20px;border:0;border-radius:3px;background:var(--accent);opacity:.8}.canvas-card>.port{right:-2px;width:4px;height:20px;border:0;border-radius:3px;background:var(--accent);opacity:.8;box-shadow:0 0 0 2px var(--panel)}.canvas-card>.port.soft{width:4px;border:0;background:var(--accent);opacity:.8}.canvas-card>.port.folded{background:var(--fg-2);opacity:.45}.mnode>.port{pointer-events:none;cursor:default}.card>.incoming-anchor{left:-2px}.card>.incoming-anchor,.mnode>.hbar{pointer-events:none}#mwires path,#wires path{stroke:var(--accent);stroke-width:2;stroke-opacity:.7}#mwires path.edge,#wires path.w-soft{stroke-width:1.6;stroke-opacity:.45;stroke-dasharray:5 4}.mnode.closed:after{bottom:7px}
|
|
7
|
+
@media(max-width:650px){.top{gap:7px;padding-inline:12px}.top .canvas-brand{gap:6px}.top .canvas-brand .canvas-brand-divider{margin-inline:2px}.top .seg button{padding:4px 7px;font-size:11px}.issues-badge{padding:4px 7px;font-size:10px}}@media(max-width:520px){.top{gap:6px;padding-inline:10px}.top .canvas-brand strong{display:none}.top .canvas-brand .canvas-brand-mark{width:24px;height:24px;font-size:14px}.top .canvas-brand .canvas-doc-name{font-size:10px}.top .canvas-brand .canvas-brand-divider{height:15px}.top .icon{width:27px;height:27px}.top .seg button{padding-inline:5px}}
|
|
8
|
+
.focus-muted{opacity:.18!important}.canvas-card.focus-selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent-soft),var(--shadow)}#article .slice.focus-selected>.slice-head .h{color:var(--accent)}#wires path.focus-line,#mwires path.focus-line{stroke:var(--accent);stroke-width:2.6;stroke-opacity:1}#wires path.focus-line-muted,#mwires path.focus-line-muted{stroke-opacity:.09}#article .slice[hidden],.markdown-body[hidden],.body>.slice[hidden]{display:none!important}.document-folded>.slice-head:after,.content-folded>.card-title:after{content:'+';color:var(--accent);font-size:12px;margin-left:8px}.slice-head[aria-expanded]{cursor:pointer}.mnode.content-folded .body{padding-bottom:10px}
|
|
9
|
+
.mind-exiting{pointer-events:none!important}#mwires path{stroke-linecap:round;stroke-linejoin:round}#mwires path[data-kind="hierarchy"]{stroke-dasharray:none}#mwires path[data-kind="relation"]{stroke-dasharray:5 4}
|
|
10
|
+
|
|
11
|
+
.canvas-card .slice[data-level="2"]>.slice-head .h{font-size:13.5px}.canvas-card .slice[data-level="3"]>.slice-head .h{font-size:12.5px}.canvas-card .slice[data-level="4"]>.slice-head .h{font-size:12px}.canvas-card .slice[data-level="5"]>.slice-head .h,.canvas-card .slice[data-level="6"]>.slice-head .h{font-size:12px;font-weight:500}
|
|
12
|
+
|
|
13
|
+
/* 长按标题提取关联链路,主画布和子画布分别保存各自的取景。 */
|
|
14
|
+
.card-title h1,.slice-head,#toc a{touch-action:none;user-select:none;-webkit-user-select:none}
|
|
15
|
+
.card-title h1:focus-visible,.slice-head:focus-visible,#toc a:focus-visible{outline:2px solid var(--accent);outline-offset:3px;border-radius:3px}
|
|
16
|
+
.canvas-chain-dialog{position:fixed;inset:0;width:min(1440px,calc(100vw - 48px));height:calc(100dvh - 64px);max-width:none;max-height:none;margin:auto;padding:0;border:1px solid var(--line);border-radius:14px;background:var(--bg);color:var(--fg);box-shadow:0 24px 90px #0005;overflow:hidden}
|
|
17
|
+
.canvas-chain-dialog::backdrop{background:#10182766;backdrop-filter:blur(3px)}
|
|
18
|
+
.canvas-chain-bar{height:61px;display:flex;align-items:center;gap:14px;padding:0 17px;border-bottom:1px solid var(--line);background:var(--panel)}
|
|
19
|
+
.canvas-chain-heading{flex:1;min-width:0;display:flex;flex-direction:column;gap:4px}.canvas-chain-heading strong{font-size:14px;font-weight:600;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.canvas-chain-meta{font-size:11px;color:var(--fg-2)}
|
|
20
|
+
.canvas-chain-controls{display:flex;align-items:center;gap:6px}.canvas-chain-controls button{width:30px;height:30px;display:grid;place-items:center;border:1px solid var(--line);border-radius:7px;background:var(--panel);color:var(--fg);font:inherit;font-size:17px;cursor:pointer}.canvas-chain-controls button:hover{background:var(--accent-soft);color:var(--accent)}.canvas-chain-controls button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.canvas-chain-dialog iframe{display:block;width:100%;height:calc(100% - 62px);border:0;background:var(--bg)}
|
|
21
|
+
@media(max-width:650px){.canvas-chain-dialog{width:calc(100vw - 16px);height:calc(100dvh - 24px);border-radius:10px}.canvas-chain-bar{padding-inline:10px;gap:8px}.canvas-chain-meta{font-size:10px}}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const top = document.querySelector('.top');
|
|
3
|
+
const brand = top.querySelector('.brand');
|
|
4
|
+
const file = new URLSearchParams(location.search).get('file');
|
|
5
|
+
brand.classList.add('canvas-brand');
|
|
6
|
+
brand.replaceChildren();
|
|
7
|
+
const mark = document.createElement('span'); mark.className = 'canvas-brand-mark'; mark.textContent = 'C';
|
|
8
|
+
const name = document.createElement('strong'); name.textContent = 'clado';
|
|
9
|
+
const divider = document.createElement('span'); divider.className = 'canvas-brand-divider'; divider.setAttribute('aria-hidden', 'true');
|
|
10
|
+
const title = document.createElement('span'); title.className = 'canvas-doc-name'; title.textContent = file?.split('/').pop() || window.__CLADO_FILE__ || window.__CLADO__.title || '文档'; title.title = title.textContent;
|
|
11
|
+
brand.append(mark, name, divider, title);
|
|
12
|
+
const diag = top.querySelector('.diag'), modes = document.querySelector('#modes'), theme = document.querySelector('#theme');
|
|
13
|
+
top.append(diag, modes, theme);
|
|
14
|
+
const diagnostics = window.__CLADO_DIAGNOSTICS__ || [];
|
|
15
|
+
const errors = diagnostics.filter(d => d.severity === 'error').length;
|
|
16
|
+
const warnings = diagnostics.filter(d => d.severity === 'warn' || d.severity === 'warning').length;
|
|
17
|
+
diag.replaceChildren(); diag.hidden = errors + warnings === 0;
|
|
18
|
+
if (errors + warnings) {
|
|
19
|
+
const issue = document.createElement('button'); issue.id = 'issuesChip'; issue.className = 'issues-badge' + (errors ? ' has-errors' : '');
|
|
20
|
+
issue.textContent = errors + warnings + ' 项问题'; issue.title = errors + ' 个 Error · ' + warnings + ' 个 Warning';
|
|
21
|
+
issue.setAttribute('aria-label', issue.title + ',查看诊断');
|
|
22
|
+
issue.onclick = () => window.__CLADO_LENS__(window.__CLADO_DIAG__);
|
|
23
|
+
diag.append(issue);
|
|
24
|
+
}
|
|
25
|
+
theme.setAttribute('aria-label', '切换日间或夜间模式');
|
|
26
|
+
['mindmap','cards','doc'].forEach(mode => {
|
|
27
|
+
const button = modes.querySelector('[data-mode="' + mode + '"]');
|
|
28
|
+
button.textContent = { mindmap: '脑图', cards: '卡片', doc: '文档' }[mode]; modes.append(button);
|
|
29
|
+
});
|
|
30
|
+
document.querySelector('#hint').hidden = true;
|
|
31
|
+
if (!window.__CLADO_LIVE__) {
|
|
32
|
+
const rewrite = () => document.querySelectorAll('a[href]:not(.edge)').forEach(a => {
|
|
33
|
+
const href = a.getAttribute('href');
|
|
34
|
+
if (href && !/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(href)) a.setAttribute('href',href.replace(/\.md(?=#|$)/i,'.html'));
|
|
35
|
+
});
|
|
36
|
+
rewrite(); new MutationObserver(rewrite).observe(document.querySelector('#world'),{childList:true,subtree:true});
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// 两种画布共用:右侧出、左侧入;直接以短曲线连接端口,不避让卡片。
|
|
2
|
+
function canvasLocalPoint(svg, x, y) {
|
|
3
|
+
var p = svg.createSVGPoint(); p.x = x; p.y = y;
|
|
4
|
+
return p.matrixTransform(svg.getScreenCTM().inverse());
|
|
5
|
+
}
|
|
6
|
+
function canvasBounds(svg, el) {
|
|
7
|
+
var r = el.getBoundingClientRect(), a = canvasLocalPoint(svg, r.left, r.top), b = canvasLocalPoint(svg, r.right, r.bottom);
|
|
8
|
+
return { left: a.x, top: a.y, right: b.x, bottom: b.y };
|
|
9
|
+
}
|
|
10
|
+
function canvasPort(svg, el) {
|
|
11
|
+
var r = el.getBoundingClientRect();
|
|
12
|
+
return canvasLocalPoint(svg, r.left + r.width / 2, r.top + r.height / 2);
|
|
13
|
+
}
|
|
14
|
+
function canvasWirePath(from, to) {
|
|
15
|
+
var distance = to.x - from.x;
|
|
16
|
+
var lead = distance > 0 ? Math.min(8, distance / 4) : 8;
|
|
17
|
+
var start = from.x + lead, end = to.x - lead, gap = end - start;
|
|
18
|
+
// 前向线的控制点始终按 x 排序;近乎齐平时自然形成浅 S 弯,不强造鼓包。
|
|
19
|
+
var handle = gap > 0 ? Math.min(96, gap * .4) : 32;
|
|
20
|
+
return 'M' + from.x + ' ' + from.y + ' L' + start + ' ' + from.y +
|
|
21
|
+
' C' + (start + handle) + ' ' + from.y + ' ' + (end - handle) + ' ' + to.y +
|
|
22
|
+
' ' + end + ' ' + to.y + ' L' + to.x + ' ' + to.y;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
drawWires = function () {
|
|
26
|
+
if (document.body.dataset.mode !== 'cards') return;
|
|
27
|
+
var svg = $('#wires');
|
|
28
|
+
if (!svg.getScreenCTM()) return;
|
|
29
|
+
$$('.incoming-anchor').forEach(function (p) { p.remove(); });
|
|
30
|
+
svg.setAttribute('width', box.w); svg.setAttribute('height', box.h);
|
|
31
|
+
svg.setAttribute('viewBox', '0 0 ' + box.w + ' ' + box.h);
|
|
32
|
+
svg.style.width = box.w + 'px'; svg.style.height = box.h + 'px';
|
|
33
|
+
var boxes = $$('#world > .card').filter(function (c) { return VIS[c.dataset.id]; }).map(function (c) { return canvasBounds(svg, c); });
|
|
34
|
+
var paths = [], index = 0;
|
|
35
|
+
$$('#world > .card .port[data-edge]').forEach(function (port) {
|
|
36
|
+
var source = port.closest('.card'), target = render.card[port.dataset.edge];
|
|
37
|
+
if (!target || !VIS[source.dataset.id] || !VIS[target.dataset.id] || !openEdge[edgeKey(source.dataset.id, target.dataset.id)]) return;
|
|
38
|
+
var input = $('.hbar', target), targetId = target.dataset.id;
|
|
39
|
+
if (port.dataset.anchor) {
|
|
40
|
+
var heading = $$('.slice-head', target).find(function (h) { return port.dataset.anchorId ? h.closest('.slice').dataset.id === port.dataset.anchorId : h.textContent.trim() === port.dataset.anchor; });
|
|
41
|
+
if (heading) {
|
|
42
|
+
var rect = target.getBoundingClientRect(), hr = heading.getBoundingClientRect(), k = rect.width / target.offsetWidth;
|
|
43
|
+
input = document.createElement('span'); input.className = 'hbar incoming-anchor';
|
|
44
|
+
input.style.top = ((hr.top + hr.height / 2 - rect.top) / k - 10) + 'px'; target.append(input);
|
|
45
|
+
targetId = heading.closest('.slice').dataset.id;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
var from = canvasPort(svg, port), to = canvasPort(svg, input);
|
|
49
|
+
var d = canvasWirePath(from, to, canvasBounds(svg, source), canvasBounds(svg, target), boxes, index++);
|
|
50
|
+
var sourceId = source.dataset.id;
|
|
51
|
+
var link = $$('a.edge', source).find(function (a) { return a.dataset.edge === port.dataset.edge && (a.dataset.anchor || '') === (port.dataset.anchor || ''); });
|
|
52
|
+
if (link && link.closest('.slice')) sourceId = link.closest('.slice').dataset.id;
|
|
53
|
+
paths.push('<path class="' + (port.dataset.soft ? 'w-soft' : '') + '" data-source-id="' + esc(sourceId) + '" data-target-id="' + esc(targetId) + '" d="' + d + '"/>');
|
|
54
|
+
});
|
|
55
|
+
svg.innerHTML = paths.join('');
|
|
56
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var canvasRenderMind = renderMind;
|
|
2
|
+
renderMind = function () {
|
|
3
|
+
canvasRenderMind();
|
|
4
|
+
canvasDrawMindWires();
|
|
5
|
+
};
|
|
6
|
+
function canvasDrawMindWires() {
|
|
7
|
+
var mind = $('#mind'), svg = $('#mwires');
|
|
8
|
+
if (!svg.getScreenCTM()) return;
|
|
9
|
+
$$('.mnode > .port', mind).forEach(function (port) { port.remove(); });
|
|
10
|
+
var nodes = {}, cards = {}, paths = [], index = 0;
|
|
11
|
+
function record(path) {
|
|
12
|
+
var parts = path.split('.').map(Number); if (parts.length === 1) return { id: '__document', title: DOC.title };
|
|
13
|
+
var current = DOC.cards[parts[1]];
|
|
14
|
+
for (var i = 2; i < parts.length; i++) current = (current.nodes || current.kids)[parts[i]];
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
$$('.mnode', mind).forEach(function (el) {
|
|
18
|
+
var fade = getComputedStyle(el).filter.match(/opacity\(([\d.]+)\)/);
|
|
19
|
+
var node = { path: el.dataset.path, el: el, record: record(el.dataset.path), bounds: canvasBounds(svg, el), input: canvasPort(svg, $('.hbar', el)), alpha: fade ? Number(fade[1]) : 1 };
|
|
20
|
+
nodes[node.path] = node; if (el.dataset.card) cards[el.dataset.card] = node;
|
|
21
|
+
});
|
|
22
|
+
var boxes = Object.keys(nodes).map(function (path) { return nodes[path].bounds; });
|
|
23
|
+
function output(node, y, soft) {
|
|
24
|
+
var port = document.createElement('span'); port.className = 'port' + (soft ? ' soft' : '');
|
|
25
|
+
port.style.top = (y - node.bounds.top - 10) + 'px'; port.setAttribute('aria-hidden', 'true'); node.el.append(port);
|
|
26
|
+
return canvasPort(svg, port);
|
|
27
|
+
}
|
|
28
|
+
function connect(source, target, from, soft, kind) {
|
|
29
|
+
paths.push('<path' + (soft ? ' class="edge"' : '') + ' style="opacity:' + Math.min(source.alpha, target.alpha) + '" data-kind="' + kind + '" data-source-path="' + source.path + '" data-target-path="' + target.path + '" data-source-id="' + esc(source.record.id) + '" data-target-id="' + esc(target.record.id) + '" d="' + canvasWirePath(from, target.input, source.bounds, target.bounds, boxes, index++) + '"/>');
|
|
30
|
+
}
|
|
31
|
+
Object.keys(nodes).forEach(function (path) {
|
|
32
|
+
var source = nodes[path], seen = {};
|
|
33
|
+
$$('.body a.edge', source.el).forEach(function (link) {
|
|
34
|
+
var target = cards[link.dataset.edge]; if (!target) return;
|
|
35
|
+
if (link.dataset.anchorId) target = Object.values(nodes).find(function(n){return n.record.id===link.dataset.anchorId;}) || target;
|
|
36
|
+
else if (link.dataset.anchor) {
|
|
37
|
+
var parentPath = target.path;
|
|
38
|
+
var anchored = Object.keys(nodes).find(function (key) { return key.indexOf(parentPath + '.') === 0 && nodes[key].record.title === link.dataset.anchor; });
|
|
39
|
+
if (anchored) target = nodes[anchored];
|
|
40
|
+
}
|
|
41
|
+
if (target === source || seen[target.path]) return; seen[target.path] = true;
|
|
42
|
+
var r = link.getBoundingClientRect(), p = canvasLocalPoint(svg, r.left, r.top + r.height / 2);
|
|
43
|
+
if (!r.width || !r.height) return;
|
|
44
|
+
connect(source, target, output(source, p.y, true), true, 'relation');
|
|
45
|
+
});
|
|
46
|
+
var children = Object.keys(nodes).filter(function (key) { return key.slice(0, key.lastIndexOf('.')) === path; });
|
|
47
|
+
if (!children.length) return;
|
|
48
|
+
var from = output(source, source.input.y, false);
|
|
49
|
+
children.forEach(function (key) { connect(source, nodes[key], from, false, 'hierarchy'); });
|
|
50
|
+
});
|
|
51
|
+
svg.innerHTML = paths.join('');
|
|
52
|
+
}
|
|
53
|
+
// 拖动/调整尺寸由共享组件触发,仍使用同一个端口和线型渲染入口。
|
|
54
|
+
drawMindWires = function () {
|
|
55
|
+
canvasDrawMindWires();
|
|
56
|
+
if (typeof canvasApplyFocus === 'function') canvasApplyFocus();
|
|
57
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// 脑图重建节点时保留已渲染的 Mermaid,避免退回源码。
|
|
2
|
+
var canvasMindMedia = Object.create(null);
|
|
3
|
+
var canvasMdToBody = mdToBody;
|
|
4
|
+
mdToBody = function (md) {
|
|
5
|
+
var body = canvasMdToBody(md);
|
|
6
|
+
var theme = document.documentElement.dataset.theme;
|
|
7
|
+
$$('.mermaid', body).forEach(function (diagram) {
|
|
8
|
+
var cached = canvasMindMedia[theme + '\n' + diagram.dataset.src];
|
|
9
|
+
if (!cached) return;
|
|
10
|
+
diagram.innerHTML = cached;
|
|
11
|
+
diagram.dataset.mmd = theme;
|
|
12
|
+
diagram.setAttribute('data-processed', 'true');
|
|
13
|
+
});
|
|
14
|
+
return body;
|
|
15
|
+
};
|
|
16
|
+
var canvasMindWithConnectors = renderMind;
|
|
17
|
+
var canvasMindMediaPending = false;
|
|
18
|
+
renderMind = function () {
|
|
19
|
+
var theme = document.documentElement.dataset.theme;
|
|
20
|
+
$$('.mermaid').forEach(function (diagram) {
|
|
21
|
+
if (diagram.dataset.mmd === theme && $('svg', diagram)) {
|
|
22
|
+
canvasMindMedia[theme + '\n' + diagram.dataset.src] = diagram.innerHTML;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
canvasMindWithConnectors();
|
|
26
|
+
if (canvasMindMediaPending || document.body.dataset.mode !== 'mindmap') return;
|
|
27
|
+
if (!$$('#mind .mermaid').some(function (d) { return !$('svg', d); })) return;
|
|
28
|
+
canvasMindMediaPending = true;
|
|
29
|
+
requestAnimationFrame(function () {
|
|
30
|
+
renderMermaid().then(function () {
|
|
31
|
+
canvasMindMediaPending = false;
|
|
32
|
+
if (document.body.dataset.mode !== 'mindmap') return;
|
|
33
|
+
// 成功渲染后才重建,失败保留内容供排查,避免重试循环。
|
|
34
|
+
if ($$('#mind .mermaid').every(function (d) { return !!$('svg', d); })) {
|
|
35
|
+
renderMind(); fit();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// 收放时保留旧位置,节点平移与淡入淡出;每帧按实际端口位置重画曲线。
|
|
2
|
+
var canvasMindMotion = null;
|
|
3
|
+
document.addEventListener('canvas-card:gesture-start', function () {
|
|
4
|
+
if (canvasMindMotion) canvasMindMotion.stop();
|
|
5
|
+
});
|
|
6
|
+
function canvasAnimateMindChange(change) {
|
|
7
|
+
var svg = $('#mwires'), mind = $('#mind'), before = {};
|
|
8
|
+
$$('.mnode', mind).forEach(function (el) {
|
|
9
|
+
before[el.dataset.path] = { el: el, bounds: canvasBounds(svg, el) };
|
|
10
|
+
});
|
|
11
|
+
if (canvasMindMotion) canvasMindMotion.stop();
|
|
12
|
+
change();
|
|
13
|
+
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
14
|
+
var after = {}, animations = [], ghosts = [], cleanups = [], frame = 0;
|
|
15
|
+
$$('.mnode', mind).forEach(function (el) {
|
|
16
|
+
after[el.dataset.path] = { el: el, bounds: canvasBounds(svg, el) };
|
|
17
|
+
});
|
|
18
|
+
function ancestor(path, records) {
|
|
19
|
+
while (path.includes('.')) {
|
|
20
|
+
path = path.slice(0, path.lastIndexOf('.'));
|
|
21
|
+
if (records[path]) return records[path].bounds;
|
|
22
|
+
}
|
|
23
|
+
return records['0'] && records['0'].bounds;
|
|
24
|
+
}
|
|
25
|
+
function animate(el, from, to) {
|
|
26
|
+
animations.push(el.animate([from, to], { duration: 340, easing: 'cubic-bezier(.22,.61,.36,1)' }));
|
|
27
|
+
}
|
|
28
|
+
Object.keys(after).forEach(function (path) {
|
|
29
|
+
var node = after[path], old = before[path], start = old ? old.bounds : ancestor(path, before) || node.bounds;
|
|
30
|
+
var dx = (old ? start.left : start.right) - node.bounds.left, dy = start.top - node.bounds.top;
|
|
31
|
+
var from = { transform: 'translate(' + dx + 'px,' + dy + 'px)', filter: old ? 'opacity(1)' : 'opacity(0)' };
|
|
32
|
+
var to = { transform: 'translate(0px,0px)', filter: 'opacity(1)' };
|
|
33
|
+
if (old && Math.abs(start.bottom - start.top - node.el.offsetHeight) > 1) {
|
|
34
|
+
from.height = (start.bottom - start.top) + 'px'; to.height = node.el.offsetHeight + 'px';
|
|
35
|
+
var overflow = node.el.style.overflow; node.el.style.overflow = 'hidden';
|
|
36
|
+
cleanups.push(function () { node.el.style.overflow = overflow; });
|
|
37
|
+
}
|
|
38
|
+
animate(node.el, from, to);
|
|
39
|
+
});
|
|
40
|
+
Object.keys(before).forEach(function (path) {
|
|
41
|
+
if (after[path]) return;
|
|
42
|
+
var old = before[path], el = old.el, end = ancestor(path, after) || old.bounds;
|
|
43
|
+
el.classList.add('mind-exiting'); el.setAttribute('aria-hidden', 'true'); el.inert = true;
|
|
44
|
+
el.style.left = old.bounds.left + 'px'; el.style.top = old.bounds.top + 'px';
|
|
45
|
+
el.style.width = (old.bounds.right - old.bounds.left) + 'px';
|
|
46
|
+
el.style.height = (old.bounds.bottom - old.bounds.top) + 'px';
|
|
47
|
+
mind.append(el); ghosts.push(el);
|
|
48
|
+
animate(el, { transform: 'translate(0px,0px)', filter: 'opacity(1)' },
|
|
49
|
+
{ transform: 'translate(' + (end.right - old.bounds.left) + 'px,' + (end.top - old.bounds.top) + 'px)', filter: 'opacity(0)' });
|
|
50
|
+
});
|
|
51
|
+
function stop() {
|
|
52
|
+
cancelAnimationFrame(frame); animations.forEach(function (a) { a.cancel(); });
|
|
53
|
+
ghosts.forEach(function (el) { el.remove(); }); cleanups.forEach(function (cleanup) { cleanup(); });
|
|
54
|
+
if (canvasMindMotion === motion) canvasMindMotion = null;
|
|
55
|
+
}
|
|
56
|
+
var motion = { stop: stop }; canvasMindMotion = motion;
|
|
57
|
+
function tick() {
|
|
58
|
+
if (canvasMindMotion !== motion) return;
|
|
59
|
+
if (document.body.dataset.mode !== 'mindmap') { stop(); return; }
|
|
60
|
+
canvasDrawMindWires(); canvasApplyFocus();
|
|
61
|
+
frame = requestAnimationFrame(tick);
|
|
62
|
+
}
|
|
63
|
+
tick();
|
|
64
|
+
Promise.all(animations.map(function (a) { return a.finished.catch(function () {}); })).then(function () {
|
|
65
|
+
if (canvasMindMotion !== motion) return;
|
|
66
|
+
stop();
|
|
67
|
+
if (document.body.dataset.mode === 'mindmap') { canvasDrawMindWires(); canvasApplyFocus(); }
|
|
68
|
+
});
|
|
69
|
+
}
|
package/src/html/page.js
CHANGED
|
@@ -20,10 +20,12 @@ import { readFileSync } from 'node:fs';
|
|
|
20
20
|
import { fileURLToPath } from 'node:url';
|
|
21
21
|
import { dirname, join } from 'node:path';
|
|
22
22
|
|
|
23
|
+
import { fixCanvasRuntime } from './runtime-fixes.js';
|
|
23
24
|
import { escapeHtml } from './escape.js';
|
|
24
25
|
import { APP_CSS } from './app-css.js';
|
|
25
26
|
import { scopeCss } from './scope-css.js';
|
|
26
27
|
|
|
28
|
+
const basenameForDisplay = file => String(file || '').split(/[\\/]/).pop();
|
|
27
29
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
28
30
|
const VENDOR = join(HERE, '..', 'vendor');
|
|
29
31
|
const read = (f) => readFileSync(join(VENDOR, f), 'utf8');
|
|
@@ -86,7 +88,7 @@ export function renderHtml(doc, diagnostics = [], options = {}) {
|
|
|
86
88
|
// (`--theme=dark` 想让页面一进来就是深色,靠的就是它)。写成常量的话这个旗标就是死的。
|
|
87
89
|
const theme = options.theme === 'dark' ? 'dark' : 'light';
|
|
88
90
|
const title = options.title || doc.title || 'Clado';
|
|
89
|
-
const version = options.version || '0.
|
|
91
|
+
const version = options.version || '0.4.0';
|
|
90
92
|
const command = options.command || '';
|
|
91
93
|
const file = options.file || '';
|
|
92
94
|
|
|
@@ -96,11 +98,20 @@ export function renderHtml(doc, diagnostics = [], options = {}) {
|
|
|
96
98
|
|
|
97
99
|
// ★ 替换值一律用函数:这些片段里有大把 `$&` / `$1`,直接给字符串的话
|
|
98
100
|
// String.replace 会把它们当成替换模式解释掉(marked 里就有)。
|
|
99
|
-
|
|
101
|
+
let runtime = readFileSync(join(HERE, 'runtime.js'), 'utf8')
|
|
102
|
+
.replace('/*__CANVAS_CARD__*/', () => readFileSync(join(HERE, 'canvas-card.js'), 'utf8'))
|
|
100
103
|
.replace('/*__MARKED__*/', () => cjs('marked', read('marked.umd.js')))
|
|
101
104
|
.replace('/*__HLJS__*/', () => (hasCodeBlock(doc) ? cjs('hljs', read('highlight.min.js')) : 'var hljs = null;'))
|
|
102
105
|
.replace('/*__MERMAID__*/', () => (doc.hasMermaid ? read('mermaid.min.js') : ''));
|
|
103
106
|
|
|
107
|
+
runtime = fixCanvasRuntime(runtime);
|
|
108
|
+
const helpers = ['canvas-wires.js','mindmap-connectors.js','mindmap-media.js','canvas-focus.js','canvas-chain.js','mindmap-motion.js','runtime-api.js']
|
|
109
|
+
.map(name => readFileSync(join(HERE, name), 'utf8')).join('\n');
|
|
110
|
+
const end = runtime.lastIndexOf('})();');
|
|
111
|
+
runtime = runtime.slice(0, end) + helpers + runtime.slice(end);
|
|
112
|
+
runtime = runtime.replace(/<(?:!--|\/?script\b)/gi, match => '\\x3c' + match.slice(1));
|
|
113
|
+
const canvasCss = readFileSync(join(HERE, 'canvas-ui.css'), 'utf8');
|
|
114
|
+
const canvasUi = readFileSync(join(HERE, 'canvas-ui.js'), 'utf8');
|
|
104
115
|
const diag = renderDiagnosticsText(diagnostics, file);
|
|
105
116
|
|
|
106
117
|
return `<!DOCTYPE html>
|
|
@@ -113,6 +124,7 @@ export function renderHtml(doc, diagnostics = [], options = {}) {
|
|
|
113
124
|
<style>
|
|
114
125
|
${vendorCss()}
|
|
115
126
|
${APP_CSS}
|
|
127
|
+
${canvasCss}
|
|
116
128
|
</style>
|
|
117
129
|
</head>
|
|
118
130
|
<body data-mode="${mode}">
|
|
@@ -120,11 +132,10 @@ ${APP_CSS}
|
|
|
120
132
|
<header class="top">
|
|
121
133
|
<div class="brand">clado<span>${escapeHtml(version)}</span></div>
|
|
122
134
|
<div class="seg" id="modes">
|
|
123
|
-
<button data-mode="doc"
|
|
124
|
-
<button data-mode="cards"
|
|
125
|
-
<button data-mode="mindmap"
|
|
135
|
+
<button data-mode="doc" title="文档 doc">doc</button>
|
|
136
|
+
<button data-mode="cards" title="卡片 cards">cards</button>
|
|
137
|
+
<button data-mode="mindmap" title="脑图 mindmap">mindmap</button>
|
|
126
138
|
</div>
|
|
127
|
-
<div class="cmd" id="cmd">${escapeHtml(command)}</div>
|
|
128
139
|
<div class="diag">${diagChips(diagnostics)}</div>
|
|
129
140
|
<button class="icon" id="theme" title="切浅色 / 深色">☾︎</button>
|
|
130
141
|
</header>
|
|
@@ -152,11 +163,15 @@ ${APP_CSS}
|
|
|
152
163
|
<script>
|
|
153
164
|
window.__CLADO__ = ${json(doc)};
|
|
154
165
|
window.__CLADO_CMD__ = ${json(command)};
|
|
166
|
+
window.__CLADO_LIVE__ = ${json(!!options.library)};
|
|
155
167
|
window.__CLADO_DIAG__ = ${json(diag)};
|
|
168
|
+
window.__CLADO_DIAGNOSTICS__ = ${json(diagnostics)};
|
|
169
|
+
window.__CLADO_FILE__ = ${json(basenameForDisplay(file))};
|
|
156
170
|
</script>
|
|
157
171
|
<script>
|
|
158
172
|
${runtime}
|
|
159
173
|
</script>
|
|
174
|
+
<script>${canvasUi}</script>
|
|
160
175
|
</body>
|
|
161
176
|
</html>
|
|
162
177
|
`;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
window.CladoRuntime = {
|
|
3
|
+
setMode: setMode, setTheme: setTheme, clearFocus: clearLit,
|
|
4
|
+
focusPath: focusPath,
|
|
5
|
+
contentPath: function (id) { var r = canvasRecords[id]; return r ? r.fullPath : null; },
|
|
6
|
+
focusTitle: function (title) {
|
|
7
|
+
var r = Object.values(canvasRecords).find(function (r) { return r.title === title || r.fullPath === title; });
|
|
8
|
+
if (!r) return;
|
|
9
|
+
canvasClearLit(); canvasFocusId = r.id; canvasApplyFocus();
|
|
10
|
+
if (document.body.dataset.mode === 'doc') $('#article .slice[data-path="' + r.docPath + '"]').scrollIntoView({block:'center'});
|
|
11
|
+
},
|
|
12
|
+
captureView: function () {
|
|
13
|
+
return { mode: document.body.dataset.mode, scale: scale, tx: tx, ty: ty,
|
|
14
|
+
edges: Object.assign({}, openEdge), closed: Object.assign({}, MIND_CLOSED),
|
|
15
|
+
focusId: canvasFocusId, docClosed: Object.assign({}, canvasDocClosed),
|
|
16
|
+
contentClosed: Object.assign({}, canvasContentClosed),
|
|
17
|
+
mindCards: Object.assign({}, MIND_CARD_STATE),
|
|
18
|
+
mindClosedIds: Object.keys(MIND_CLOSED).filter(function(p){return MIND_CLOSED[p];}).map(function(p){return p==='0'?'__document':canvasMindPaths[p] && canvasMindPaths[p].id;}),
|
|
19
|
+
cardClosed: Object.assign({},canvasCardClosed),
|
|
20
|
+
cardPlacements: Object.assign({},CARD_PLACEMENTS),
|
|
21
|
+
cards: Object.fromEntries(Object.keys(render.card).map(function(id){var el=render.card[id];return [id,{x:pos[id] && pos[id].x,y:pos[id] && pos[id].y,width:el.style.width,height:el.style.height}];})),
|
|
22
|
+
scrollTop: $('#doc').scrollTop };
|
|
23
|
+
},
|
|
24
|
+
restoreView: function (view) {
|
|
25
|
+
if (!view || view.mode !== document.body.dataset.mode) return;
|
|
26
|
+
openEdge = Object.assign({}, view.edges); MIND_CLOSED = Object.assign({}, view.closed);
|
|
27
|
+
canvasFocusId = canvasRecords[view.focusId] || view.focusId === '__document' ? view.focusId : null;
|
|
28
|
+
canvasDocClosed = Object.assign({}, view.docClosed); canvasContentClosed = Object.assign({}, view.contentClosed);
|
|
29
|
+
MIND_CARD_STATE = Object.assign({}, view.mindCards);
|
|
30
|
+
canvasCardClosed = Object.assign({},view.cardClosed);
|
|
31
|
+
CARD_PLACEMENTS = Object.assign({},view.cardPlacements);
|
|
32
|
+
if (view.mindClosedIds) { MIND_CLOSED={};view.mindClosedIds.forEach(function(id){if(id==='__document')MIND_CLOSED['0']=1;else if(canvasRecords[id])MIND_CLOSED[canvasRecords[id].mindPath]=1;}); }
|
|
33
|
+
Object.keys(view.cards || {}).forEach(function(id){
|
|
34
|
+
var el=render.card[id], saved=view.cards[id];if(!el)return;
|
|
35
|
+
if(saved.width)el.style.width=saved.width;if(saved.height)el.style.height=saved.height;
|
|
36
|
+
});
|
|
37
|
+
canvasCardFolds();
|
|
38
|
+
if (view.mode === 'mindmap') renderMind();
|
|
39
|
+
else if (view.mode === 'cards') { applyVisibility(); layout(); }
|
|
40
|
+
scale = view.scale; tx = view.tx; ty = view.ty; apply(); repinPorts(); drawWires();
|
|
41
|
+
$('#doc').scrollTop = view.scrollTop || 0;
|
|
42
|
+
canvasDocumentFolds(); canvasApplyFocus();
|
|
43
|
+
},
|
|
44
|
+
refresh: function () {
|
|
45
|
+
if (document.body.dataset.mode === 'mindmap') renderMind();
|
|
46
|
+
else if (document.body.dataset.mode === 'cards') layout();
|
|
47
|
+
if (document.body.dataset.mode !== 'doc') { fit(); repinPorts(); }
|
|
48
|
+
},
|
|
49
|
+
allEdges: function (open) {
|
|
50
|
+
openEdge = {};
|
|
51
|
+
if (open) DOC.edges.forEach(function (e) { openEdge[edgeKey(e[0], e[1])] = 1; });
|
|
52
|
+
lastAnchor = null; lastPrev = null;
|
|
53
|
+
applyVisibility(); layout(); fit(); repinPorts();
|
|
54
|
+
return renderMermaid().then(afterMedia);
|
|
55
|
+
},
|
|
56
|
+
collapseMind: function () {
|
|
57
|
+
MIND_CLOSED = { '0.1': 1, '0.3': 1 };
|
|
58
|
+
renderMind(); fit();
|
|
59
|
+
},
|
|
60
|
+
whenMedia: function () { return renderMermaid().then(afterMedia); },
|
|
61
|
+
closeLens: closeLens
|
|
62
|
+
};
|