cladogram 0.5.2 → 0.5.4
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 +30 -2
- package/bin/clado.js +55 -3
- package/docs/plugin-development.md +135 -0
- package/docs/plugin-ui.md +43 -0
- package/docs/release.md +26 -0
- package/package.json +8 -1
- package/plugins/agent/index.js +181 -0
- package/plugins/agent/style.css +105 -0
- package/plugins/brand/index.js +262 -0
- package/plugins/brand/style.css +162 -0
- package/plugins/directory/capabilities.json +27 -0
- package/plugins/directory/index.js +146 -0
- package/plugins/directory/style.css +48 -0
- package/plugins/view-controls/index.js +58 -0
- package/plugins/view-controls/style.css +46 -0
- package/skills/clado/SKILL.md +31 -17
- package/src/html/app-css.js +11 -42
- package/src/html/canvas-chain.js +5 -6
- package/src/html/canvas-focus.js +3 -4
- package/src/html/canvas-screenshot.js +199 -0
- package/src/html/canvas-ui.css +37 -9
- package/src/html/canvas-ui.js +35 -27
- package/src/html/page.js +11 -37
- package/src/html/plugin-assets.js +33 -0
- package/src/html/plugin-ui.css +176 -0
- package/src/html/plugin-ui.js +45 -0
- package/src/html/runtime-api.js +47 -0
- package/src/html/runtime.js +15 -12
- package/src/server/agent.js +222 -0
- package/src/server/assets/clado-plugin-sdk.js +111 -0
- package/src/server/assets/library-canvas.js +72 -11
- package/src/server/assets/library-plugin-bridge.js +84 -0
- package/src/server/assets/library-plugins.css +39 -0
- package/src/server/assets/library-plugins.js +200 -0
- package/src/server/assets/library.css +3 -6
- package/src/server/assets/library.html +2 -12
- package/src/server/assets/library.js +280 -44
- package/src/server/canvas-capture.js +47 -0
- package/src/server/export.js +5 -2
- package/src/server/mcp.js +44 -19
- package/src/server/plugin-capabilities.js +172 -0
- package/src/server/plugin-settings.js +117 -0
- package/src/server/plugins.js +236 -0
- package/src/server/workspace.js +157 -12
- package/src/skill/targets.js +1 -1
- package/src/util/update.js +58 -0
- package/src/vendor/html-to-image.min.js +24 -0
- package/src/workspace/content.js +3 -2
- package/src/workspace/service.js +81 -21
- package/src/workspace/tree.js +38 -0
- package/src/server/assets/tree.js +0 -26
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const maxPngBytes = 4 * 1024 * 1024;
|
|
3
|
+
const padding = 32;
|
|
4
|
+
const snapshotStyle = '<style>*{transition:none!important;animation:none!important;scroll-behavior:auto!important}</style>';
|
|
5
|
+
const error = (kind, message) => Object.assign(new Error(message), { kind });
|
|
6
|
+
const svgPaint = ['fill', 'fill-opacity', 'stroke', 'stroke-width', 'stroke-opacity',
|
|
7
|
+
'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'opacity'];
|
|
8
|
+
const layoutStyles = [
|
|
9
|
+
'display', 'position', 'top', 'right', 'bottom', 'left', 'z-index', 'box-sizing',
|
|
10
|
+
'width', 'height', 'min-width', 'min-height', 'max-width', 'max-height', 'aspect-ratio',
|
|
11
|
+
'margin', 'padding', 'border-radius', 'border-top', 'border-right', 'border-bottom', 'border-left',
|
|
12
|
+
'box-shadow', 'background', 'color', 'opacity', 'visibility', 'overflow-x', 'overflow-y',
|
|
13
|
+
'transform', 'transform-origin', 'object-fit', 'object-position',
|
|
14
|
+
'flex-direction', 'flex-wrap', 'flex-grow', 'flex-shrink', 'flex-basis',
|
|
15
|
+
'justify-content', 'align-items', 'align-content', 'align-self', 'row-gap', 'column-gap',
|
|
16
|
+
'grid-template-columns', 'grid-template-rows', 'grid-column', 'grid-row', 'justify-self', 'order',
|
|
17
|
+
'font-family', 'font-size', 'font-weight', 'font-style', 'font-variant', 'line-height',
|
|
18
|
+
'letter-spacing', 'word-spacing', 'text-align', 'text-indent', 'text-transform', 'text-decoration',
|
|
19
|
+
'text-overflow', 'white-space', 'overflow-wrap', 'word-break', 'tab-size', 'vertical-align',
|
|
20
|
+
'list-style', 'border-collapse', 'border-spacing', 'table-layout', 'caption-side',
|
|
21
|
+
...svgPaint,
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
function loadSnapshot(source) {
|
|
25
|
+
const snapshot = document.createElement('iframe');
|
|
26
|
+
snapshot.setAttribute('aria-hidden', 'true');
|
|
27
|
+
snapshot.tabIndex = -1;
|
|
28
|
+
Object.assign(snapshot.style, {
|
|
29
|
+
position: 'fixed', right: '100vw', top: '0', border: '0',
|
|
30
|
+
width: source.clientWidth + 'px', height: source.clientHeight + 'px', pointerEvents: 'none',
|
|
31
|
+
});
|
|
32
|
+
snapshot.srcdoc = source.srcdoc.replace('</head>', snapshotStyle + '</head>');
|
|
33
|
+
document.body.append(snapshot);
|
|
34
|
+
return snapshot;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function sizedSurface(doc, mode) {
|
|
38
|
+
if (mode === 'doc') {
|
|
39
|
+
const article = doc.querySelector('#article');
|
|
40
|
+
const width = Math.max(1, Math.ceil(article.getBoundingClientRect().width)) + 2 * padding;
|
|
41
|
+
const height = Math.max(1, article.scrollHeight) + 2 * padding;
|
|
42
|
+
const surface = doc.createElement('div');
|
|
43
|
+
Object.assign(surface.style, { boxSizing: 'border-box', padding: padding + 'px', width: width + 'px', height: height + 'px' });
|
|
44
|
+
article.replaceWith(surface);
|
|
45
|
+
surface.append(article);
|
|
46
|
+
return { surface, width, height };
|
|
47
|
+
}
|
|
48
|
+
const surface = doc.querySelector('#stage'), world = doc.querySelector('#world');
|
|
49
|
+
world.style.transform = 'none';
|
|
50
|
+
const boxes = [...world.querySelectorAll(mode === 'cards' ? '.card:not(.folded-away,.focus-hidden)' : '#mind .mnode:not(.focus-hidden)')]
|
|
51
|
+
.map(node => ({ x: node.offsetLeft, y: node.offsetTop, width: node.offsetWidth, height: node.offsetHeight }));
|
|
52
|
+
const wires = world.querySelector(mode === 'cards' ? '#wires' : '#mwires');
|
|
53
|
+
if (wires.querySelector('path')) {
|
|
54
|
+
// Freeze the SVG before the runtime's next redraw and give it explicit paint.
|
|
55
|
+
const paths = [...wires.querySelectorAll('path')];
|
|
56
|
+
const frozen = wires.cloneNode(true);
|
|
57
|
+
frozen.querySelectorAll('path').forEach((copy, index) => {
|
|
58
|
+
const path = paths[index];
|
|
59
|
+
if (path.classList.contains('focus-hidden')) { copy.remove(); return; }
|
|
60
|
+
boxes.push(path.getBBox());
|
|
61
|
+
const style = doc.defaultView.getComputedStyle(path);
|
|
62
|
+
for (const name of svgPaint) copy.style.setProperty(name, style.getPropertyValue(name));
|
|
63
|
+
});
|
|
64
|
+
wires.dataset.screenshotExclude = '';
|
|
65
|
+
wires.after(frozen);
|
|
66
|
+
}
|
|
67
|
+
if (!boxes.length) throw error('CAPTURE_NOT_READY', '当前画布没有可以截图的内容。');
|
|
68
|
+
const bounds = boxes.reduce(({ left, top, right, bottom }, box) => ({
|
|
69
|
+
left: Math.min(left, box.x),
|
|
70
|
+
top: Math.min(top, box.y),
|
|
71
|
+
right: Math.max(right, box.x + box.width),
|
|
72
|
+
bottom: Math.max(bottom, box.y + box.height),
|
|
73
|
+
}), { left: Infinity, top: Infinity, right: -Infinity, bottom: -Infinity });
|
|
74
|
+
const width = Math.ceil(bounds.right - bounds.left) + 2 * padding;
|
|
75
|
+
const height = Math.ceil(bounds.bottom - bounds.top) + 2 * padding;
|
|
76
|
+
Object.assign(surface.style, { inset: 'auto', left: '0', top: '0', width: width + 'px', height: height + 'px' });
|
|
77
|
+
world.style.transform = 'translate(' + (padding - bounds.left) + 'px,' + (padding - bounds.top) + 'px)';
|
|
78
|
+
return { surface, width, height };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function encodePng(canvas) {
|
|
82
|
+
let result = canvas;
|
|
83
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
84
|
+
const blob = await new Promise(resolve => result.toBlob(resolve, 'image/png'));
|
|
85
|
+
if (!blob) break;
|
|
86
|
+
if (blob.size <= maxPngBytes) {
|
|
87
|
+
const url = await new Promise((resolve, reject) => {
|
|
88
|
+
const reader = new FileReader();
|
|
89
|
+
reader.onload = () => resolve(reader.result);
|
|
90
|
+
reader.onerror = () => reject(reader.error);
|
|
91
|
+
reader.readAsDataURL(blob);
|
|
92
|
+
});
|
|
93
|
+
return { width: result.width, height: result.height, pngBase64: url.slice(url.indexOf(',') + 1) };
|
|
94
|
+
}
|
|
95
|
+
const smaller = document.createElement('canvas');
|
|
96
|
+
smaller.width = Math.max(1, Math.floor(result.width * .72));
|
|
97
|
+
smaller.height = Math.max(1, Math.floor(result.height * .72));
|
|
98
|
+
smaller.getContext('2d').drawImage(result, 0, 0, smaller.width, smaller.height);
|
|
99
|
+
result = smaller;
|
|
100
|
+
}
|
|
101
|
+
throw error('CAPTURE_FAILED', '无法生成大小合适的 PNG。');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function render(source, { mode, design, scope }) {
|
|
105
|
+
const live = source.contentWindow.CladoRuntime.captureView();
|
|
106
|
+
const snapshot = loadSnapshot(source);
|
|
107
|
+
let loadTimer, assetTimer, encodeTimer;
|
|
108
|
+
try {
|
|
109
|
+
await new Promise((resolve, reject) => {
|
|
110
|
+
snapshot.addEventListener('load', resolve, { once: true });
|
|
111
|
+
loadTimer = setTimeout(() => reject(error('CAPTURE_FAILED', '截图画布加载超时。')), 6500);
|
|
112
|
+
});
|
|
113
|
+
clearTimeout(loadTimer);
|
|
114
|
+
const win = snapshot.contentWindow, doc = snapshot.contentDocument, runtime = win.CladoRuntime;
|
|
115
|
+
if (!runtime) throw error('CAPTURE_FAILED', '截图画布无法加载。');
|
|
116
|
+
await win.CladoPrototype?.whenReady;
|
|
117
|
+
if (doc.body.dataset.mode !== mode) runtime.setMode(mode);
|
|
118
|
+
win.CladoPrototype?.setDesign(design);
|
|
119
|
+
await new Promise(resolve => win.requestAnimationFrame(resolve));
|
|
120
|
+
if (mode === 'cards' && scope === 'full') await runtime.allEdges(true);
|
|
121
|
+
else await runtime.whenMedia();
|
|
122
|
+
await Promise.race([
|
|
123
|
+
Promise.allSettled([...doc.querySelectorAll('img')].map(img => { img.loading = 'eager'; return img.decode(); })),
|
|
124
|
+
new Promise(resolve => { assetTimer = setTimeout(resolve, 2000); }),
|
|
125
|
+
]);
|
|
126
|
+
const view = runtime.captureView();
|
|
127
|
+
runtime.restoreView({ ...view, edges: scope === 'full' ? view.edges : live.edges,
|
|
128
|
+
focusId: scope === 'full' ? null : live.focusId, scale: 1, tx: 0, ty: 0, mindCards: live.mindCards,
|
|
129
|
+
cardPlacements: live.cardPlacements, cards: live.cards });
|
|
130
|
+
const { surface, width, height } = sizedSurface(doc, mode);
|
|
131
|
+
const rootStyle = win.getComputedStyle(doc.documentElement);
|
|
132
|
+
const backgroundColor = rootStyle.getPropertyValue(mode === 'doc' ? '--panel' : '--bg').trim();
|
|
133
|
+
const ratio = Math.min(1, 4096 / Math.max(width, height), Math.sqrt(8_000_000 / (width * height)));
|
|
134
|
+
const fetches = new AbortController();
|
|
135
|
+
const rasterize = window.htmlToImage.toSvg(surface, {
|
|
136
|
+
width, height, skipFonts: true, includeStyleProperties: layoutStyles, fetchRequestInit: { signal: fetches.signal },
|
|
137
|
+
filter: node => node.nodeType !== 1 ||
|
|
138
|
+
(!node.matches('[data-screenshot-exclude], .folded-away, .focus-hidden') && win.getComputedStyle(node).display !== 'none'),
|
|
139
|
+
}).then(async svg => {
|
|
140
|
+
const img = new Image();
|
|
141
|
+
img.src = svg;
|
|
142
|
+
await img.decode();
|
|
143
|
+
const canvas = document.createElement('canvas');
|
|
144
|
+
canvas.width = Math.max(1, Math.floor(width * ratio));
|
|
145
|
+
canvas.height = Math.max(1, Math.floor(height * ratio));
|
|
146
|
+
const context = canvas.getContext('2d');
|
|
147
|
+
context.fillStyle = backgroundColor;
|
|
148
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
149
|
+
context.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
150
|
+
return encodePng(canvas);
|
|
151
|
+
});
|
|
152
|
+
const png = await Promise.race([rasterize, new Promise((_, reject) => {
|
|
153
|
+
encodeTimer = setTimeout(() => {
|
|
154
|
+
fetches.abort();
|
|
155
|
+
reject(error('CAPTURE_FAILED', '截图渲染超时。'));
|
|
156
|
+
}, 26000);
|
|
157
|
+
})]);
|
|
158
|
+
return { ...png, layoutWidth: width, layoutHeight: height };
|
|
159
|
+
} finally {
|
|
160
|
+
clearTimeout(loadTimer);
|
|
161
|
+
clearTimeout(assetTimer);
|
|
162
|
+
clearTimeout(encodeTimer);
|
|
163
|
+
snapshot.remove();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
window.CladoScreenshot = () => {
|
|
168
|
+
let latest, pending;
|
|
169
|
+
return {
|
|
170
|
+
async capture(input, readCanvas) {
|
|
171
|
+
if (input.source === 'latest') {
|
|
172
|
+
if (!latest) throw error('NO_CAPTURE', '当前标签页还没有成功截过图。');
|
|
173
|
+
return latest;
|
|
174
|
+
}
|
|
175
|
+
const state = readCanvas();
|
|
176
|
+
if (!state) throw error('CAPTURE_NOT_READY', '请等当前画布加载后再截图。');
|
|
177
|
+
const mode = input.mode || state.mode, scope = input.scope || 'current';
|
|
178
|
+
if (pending) throw error('CAPTURE_NOT_READY', '当前标签页正在截图,请等这次完成。');
|
|
179
|
+
pending = render(state.frame, { ...state, mode, scope });
|
|
180
|
+
try {
|
|
181
|
+
const image = await pending;
|
|
182
|
+
latest = { file: state.file, revision: state.revision, mode, ...image };
|
|
183
|
+
return latest;
|
|
184
|
+
} finally { pending = null; }
|
|
185
|
+
},
|
|
186
|
+
async download(image) {
|
|
187
|
+
const data = await fetch('data:image/png;base64,' + image.pngBase64);
|
|
188
|
+
const url = URL.createObjectURL(await data.blob());
|
|
189
|
+
const link = document.createElement('a');
|
|
190
|
+
link.download = image.file.split('/').pop().replace(/\.mdc?$/i, '') + '-' + image.mode + '.png';
|
|
191
|
+
link.href = url;
|
|
192
|
+
document.body.append(link);
|
|
193
|
+
link.click();
|
|
194
|
+
link.remove();
|
|
195
|
+
setTimeout(() => URL.revokeObjectURL(url), 30000);
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
})();
|
package/src/html/canvas-ui.css
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
:root{--proto-font:14px;--proto-radius:11px;--proto-reading-width:1000px}
|
|
2
2
|
/* 脑图与卡片共用的画布组件。 */
|
|
3
|
-
.
|
|
3
|
+
.hint{display:none!important}
|
|
4
4
|
.canvas-card{background:var(--panel);border:1px solid var(--line);border-radius:var(--proto-radius);box-shadow:var(--shadow)}.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
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
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}
|
|
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
7
|
.focus-hidden{visibility:hidden;pointer-events:none}
|
|
9
8
|
.media-reference a{font-size:.9em}
|
|
10
9
|
.media-reference{display:none}
|
|
@@ -21,8 +20,6 @@
|
|
|
21
20
|
.canvas-card.focus-selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent-soft),var(--shadow)}
|
|
22
21
|
.slice.focus-selected>.slice-head .h{color:var(--accent)}
|
|
23
22
|
#wires path.focus-line,#mwires path.focus-line{stroke:var(--accent);stroke-width:2.6;stroke-opacity:1}
|
|
24
|
-
#exit-focus{flex-shrink:0;border:1px solid var(--line);border-radius:7px;background:var(--panel);color:var(--accent);font:inherit;font-size:12px;padding:4px 8px;cursor:pointer}
|
|
25
|
-
#exit-focus[hidden]{display:none}
|
|
26
23
|
#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}
|
|
27
24
|
|
|
28
25
|
.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}
|
|
@@ -30,9 +27,40 @@
|
|
|
30
27
|
/* 长按标题提取关联链路,主画布和子画布分别保存各自的取景。 */
|
|
31
28
|
.card-title h1,.slice-head,#toc a{touch-action:none;cursor:text;user-select:text;-webkit-user-select:text}
|
|
32
29
|
.card-title h1:focus-visible,.slice-head:focus-visible,#toc a:focus-visible{outline:2px solid var(--accent);outline-offset:3px;border-radius:3px}
|
|
33
|
-
.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;
|
|
34
|
-
.canvas-chain-
|
|
35
|
-
.canvas-chain-
|
|
36
|
-
.canvas-chain-
|
|
37
|
-
.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)}
|
|
30
|
+
.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;overflow:hidden}
|
|
31
|
+
.canvas-chain-bar{height:61px;display:flex;align-items:center;gap:14px;padding:0 17px;background:#fff;color:#192630;border-bottom:1px solid #dee5ec;--clado-ui-muted:#4b5a68;--clado-ui-accent:#075da9;--clado-ui-edge:#7890af54;--clado-ui-active:#e6eef8}
|
|
32
|
+
.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(--clado-ui-muted)}
|
|
33
|
+
.canvas-chain-controls{display:flex;align-items:center;gap:6px}.canvas-chain-controls button{width:30px;min-height:30px;padding:0;display:grid;place-items:center;border-radius:7px;font-size:17px}.canvas-chain-dialog iframe{display:block;width:100%;height:calc(100% - 62px);border:0;background:var(--bg)}
|
|
38
34
|
@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}}
|
|
35
|
+
@property --selection-angle{
|
|
36
|
+
syntax:'<angle>';inherits:false;initial-value:0deg;
|
|
37
|
+
}
|
|
38
|
+
@keyframes selection-light-around{
|
|
39
|
+
to{--selection-angle:1turn}
|
|
40
|
+
}
|
|
41
|
+
.clado-ai-selected{
|
|
42
|
+
--selection-colors:#62d9ff,#b59aff 21%,#ff90cb 43%,#ffce6f 65%,#69e3b6 85%,#62d9ff;
|
|
43
|
+
--selection-bloom:0 0 4px #fff,-2px -1px 11px #8be8ff85,2px -2px 12px #f0b2ff75,2px 2px 12px #ffdb8b80,-2px 2px 11px #93f5cd85;
|
|
44
|
+
}
|
|
45
|
+
[data-theme="dark"] .clado-ai-selected{
|
|
46
|
+
--selection-colors:#9feaff,#d1b6ff 21%,#ffa9d6 43%,#ffe095 65%,#9af2cf 85%,#9feaff;
|
|
47
|
+
--selection-bloom:0 0 5px #fff8,-2px -1px 11px #75dcff86,2px -2px 12px #e6a8ff82,2px 2px 12px #ffd38a83,-2px 2px 11px #82ecc386;
|
|
48
|
+
}
|
|
49
|
+
.clado-ai-selected::before,.clado-ai-selected::after{
|
|
50
|
+
content:'';position:absolute;inset:-1px;pointer-events:none;border-radius:var(--proto-radius);
|
|
51
|
+
}
|
|
52
|
+
.canvas-card>.hbar,.canvas-card>.port{z-index:3}
|
|
53
|
+
.canvas-card.clado-ai-selected,.canvas-card.clado-ai-selected.focus-selected{box-shadow:none}
|
|
54
|
+
[data-theme="dark"] .canvas-card.clado-ai-selected{background-color:#1b212a}
|
|
55
|
+
.clado-ai-selected::before,#article .clado-ai-selected::before{
|
|
56
|
+
display:block;box-shadow:var(--selection-bloom);
|
|
57
|
+
}
|
|
58
|
+
.clado-ai-selected::after{
|
|
59
|
+
padding:2px;background:conic-gradient(from var(--selection-angle,0deg),var(--selection-colors));
|
|
60
|
+
mask:linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0);
|
|
61
|
+
mask-composite:exclude;
|
|
62
|
+
}
|
|
63
|
+
@media(prefers-reduced-motion:no-preference){
|
|
64
|
+
.clado-ai-selected::after{animation:selection-light-around 8s linear infinite}
|
|
65
|
+
}
|
|
66
|
+
.slice.clado-ai-selected::before,.slice.clado-ai-selected::after{inset:-2px -4px;border-radius:6px}
|
package/src/html/canvas-ui.js
CHANGED
|
@@ -1,35 +1,43 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
const
|
|
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
|
-
const exitFocus = top.querySelector('#exit-focus');
|
|
14
|
-
if (exitFocus) top.append(exitFocus);
|
|
15
|
-
top.append(diag, modes, theme);
|
|
2
|
+
const runtime = window.CladoRuntime;
|
|
16
3
|
const diagnostics = window.__CLADO_DIAGNOSTICS__ || [];
|
|
17
4
|
const errors = diagnostics.filter(d => d.severity === 'error').length;
|
|
18
5
|
const warnings = diagnostics.filter(d => d.severity === 'warn' || d.severity === 'warning').length;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
const showDiagnostics = () => window.__CLADO_LENS__(window.__CLADO_DIAG__);
|
|
7
|
+
window.CladoCanvasControls = {
|
|
8
|
+
state: () => ({
|
|
9
|
+
mode: document.body.dataset.mode,
|
|
10
|
+
theme: document.documentElement.dataset.theme,
|
|
11
|
+
focused: runtime.isFocused(),
|
|
12
|
+
errors, warnings,
|
|
13
|
+
}),
|
|
14
|
+
showDiagnostics,
|
|
15
|
+
};
|
|
16
|
+
if (!window.__CLADO_WORKSPACE_CHROME__ && !window.__CLADO_CHAIN__) {
|
|
17
|
+
const ui = window.CladoPluginUI;
|
|
18
|
+
const host = ui.createHost();
|
|
19
|
+
const brand = ui.mountBrand(host, { setTheme: runtime.setTheme });
|
|
20
|
+
const update = ui.mountViewControls(host, {
|
|
21
|
+
setMode: runtime.setMode,
|
|
22
|
+
clearFocus: runtime.clearFocus, showDiagnostics,
|
|
23
|
+
});
|
|
24
|
+
const sync = () => {
|
|
25
|
+
const state = window.CladoCanvasControls.state();
|
|
26
|
+
brand.sync(state.theme);
|
|
27
|
+
update(state);
|
|
28
|
+
};
|
|
29
|
+
const syncLayers = () => {
|
|
30
|
+
const hidden = runtime.isChainOpen() || runtime.isLensOpen();
|
|
31
|
+
if (hidden) brand.close();
|
|
32
|
+
host.setHidden(hidden);
|
|
33
|
+
};
|
|
34
|
+
document.addEventListener('clado:view-state', sync);
|
|
35
|
+
for (const kind of ['chain', 'lens']) {
|
|
36
|
+
document.addEventListener('clado:' + kind + '-open', syncLayers);
|
|
37
|
+
document.addEventListener('clado:' + kind + '-close', syncLayers);
|
|
38
|
+
}
|
|
39
|
+
sync();
|
|
26
40
|
}
|
|
27
|
-
theme.setAttribute('aria-label', '切换日间或夜间模式');
|
|
28
|
-
['mindmap','cards','doc'].forEach(mode => {
|
|
29
|
-
const button = modes.querySelector('[data-mode="' + mode + '"]');
|
|
30
|
-
button.textContent = { mindmap: '脑图', cards: '卡片', doc: '文档' }[mode]; modes.append(button);
|
|
31
|
-
});
|
|
32
|
-
document.querySelector('#hint').hidden = true;
|
|
33
41
|
if (!window.__CLADO_LIVE__) {
|
|
34
42
|
const rewrite = () => document.querySelectorAll('a[href]:not(.edge)').forEach(a => {
|
|
35
43
|
const href = a.getAttribute('href');
|
package/src/html/page.js
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 组装那一页 HTML。
|
|
3
3
|
*
|
|
4
|
-
* 页面的形状(`docs/spec.md` §五):
|
|
5
|
-
*
|
|
6
|
-
* ┌ 顶栏 ── 模式开关 / 命令行 / 诊断 / 深浅色 ──────────────┐
|
|
7
|
-
* │ 卡片模式:无限画布,一张张卡片 + 它们之间的线 │
|
|
8
|
-
* │ 文档模式:左大纲右正文 │
|
|
9
|
-
* │ 脑图模式:同一块画布,换成一棵树 │
|
|
10
|
-
* └ 底部一行提示 ────────────────────────────────────────┘
|
|
11
|
-
*
|
|
12
4
|
* 三个模式**永远都在这一页里**,`--mode` 只决定进来先看哪个 —— 切模式不回服务端,
|
|
13
5
|
* 渲染全在浏览器里(`src/html/runtime.js`)。
|
|
14
6
|
*
|
|
@@ -17,6 +9,7 @@
|
|
|
17
9
|
*/
|
|
18
10
|
|
|
19
11
|
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { pluginMarkup } from './plugin-assets.js';
|
|
20
13
|
import { fileURLToPath } from 'node:url';
|
|
21
14
|
import { dirname, join } from 'node:path';
|
|
22
15
|
|
|
@@ -56,17 +49,6 @@ function hasCodeBlock(doc) {
|
|
|
56
49
|
return scan(doc.preamble) || doc.cards.some((c) => scan(c.md) || walk(c.nodes || []));
|
|
57
50
|
}
|
|
58
51
|
|
|
59
|
-
function diagChips(diagnostics) {
|
|
60
|
-
const errors = diagnostics.filter((d) => d.severity === 'error').length;
|
|
61
|
-
const warns = diagnostics.filter((d) => d.severity === 'warn' || d.severity === 'warning').length;
|
|
62
|
-
const e = `<div class="chip${errors ? ' bad' : ''}">${errors} error</div>`;
|
|
63
|
-
const w = warns
|
|
64
|
-
? `<div class="chip warn" id="warnChip" title="点开看构建输出">⚠ ${warns} warning</div>`
|
|
65
|
-
: '<div class="chip">0 warning</div>';
|
|
66
|
-
return e + w;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** 构建输出原样摆在放大镜里 —— 点顶栏那个 warning chip 就能看见 */
|
|
70
52
|
export function renderDiagnosticsText(diagnostics, file) {
|
|
71
53
|
if (!diagnostics.length) return `${file}: 没有任何问题。`;
|
|
72
54
|
return diagnostics.map((d) => {
|
|
@@ -115,6 +97,7 @@ export function renderHtml(doc, diagnostics = [], options = {}) {
|
|
|
115
97
|
const canvasCss = readFileSync(join(HERE, 'canvas-ui.css'), 'utf8');
|
|
116
98
|
const canvasUi = readFileSync(join(HERE, 'canvas-ui.js'), 'utf8');
|
|
117
99
|
const diag = renderDiagnosticsText(diagnostics, file);
|
|
100
|
+
const plugins = pluginMarkup({ inline: true, materialOnly: options.workspaceChrome });
|
|
118
101
|
|
|
119
102
|
return `<!DOCTYPE html>
|
|
120
103
|
<html lang="zh-CN" data-theme="${theme}">
|
|
@@ -128,21 +111,10 @@ ${vendorCss()}
|
|
|
128
111
|
${APP_CSS}
|
|
129
112
|
${canvasCss}
|
|
130
113
|
</style>
|
|
114
|
+
${plugins.styles}
|
|
131
115
|
</head>
|
|
132
116
|
<body data-mode="${mode}">
|
|
133
117
|
|
|
134
|
-
<header class="top">
|
|
135
|
-
<div class="brand">clado<span>${escapeHtml(version)}</span></div>
|
|
136
|
-
<div class="seg" id="modes">
|
|
137
|
-
<button data-mode="doc" title="文档 doc">doc</button>
|
|
138
|
-
<button data-mode="cards" title="卡片 cards">cards</button>
|
|
139
|
-
<button data-mode="mindmap" title="脑图 mindmap">mindmap</button>
|
|
140
|
-
</div>
|
|
141
|
-
<div class="diag">${diagChips(diagnostics)}</div>
|
|
142
|
-
<button type="button" id="exit-focus" hidden>退出聚焦</button>
|
|
143
|
-
<button class="icon" id="theme" title="切浅色 / 深色">☾︎</button>
|
|
144
|
-
</header>
|
|
145
|
-
|
|
146
118
|
<div id="stage">
|
|
147
119
|
<div id="world"><svg id="wires"></svg><div id="mind"><svg id="mwires"></svg></div></div>
|
|
148
120
|
</div>
|
|
@@ -150,15 +122,15 @@ ${canvasCss}
|
|
|
150
122
|
<div id="doc"><div class="docwrap"><nav class="toc" id="toc"></nav><article id="article"></article></div></div>
|
|
151
123
|
|
|
152
124
|
<div id="lens">
|
|
153
|
-
<div class="lensbar">
|
|
125
|
+
<div class="lensbar clado-ui-glass">
|
|
154
126
|
<span id="lensLabel">图</span>
|
|
155
|
-
<button id="lensOut" title="缩小">−</button>
|
|
127
|
+
<button id="lensOut" class="clado-ui-button" title="缩小">−</button>
|
|
156
128
|
<span id="lensPct" style="min-width:44px;text-align:center">100%</span>
|
|
157
|
-
<button id="lensIn" title="放大">+</button>
|
|
158
|
-
<button id="lensFit" title="适应窗口">⤢</button>
|
|
159
|
-
<button id="lensClose" title="关掉(Esc / 点背景)">✕</button>
|
|
129
|
+
<button id="lensIn" class="clado-ui-button" title="放大">+</button>
|
|
130
|
+
<button id="lensFit" class="clado-ui-button" title="适应窗口">⤢</button>
|
|
131
|
+
<button id="lensClose" class="clado-ui-button" title="关掉(Esc / 点背景)">✕</button>
|
|
160
132
|
</div>
|
|
161
|
-
<div id="lensStage"><div id="lensInner"></div></div>
|
|
133
|
+
<div id="lensStage"><div id="lensInner" class="clado-ui-glass clado-ui-glass-panel"></div></div>
|
|
162
134
|
</div>
|
|
163
135
|
|
|
164
136
|
<div class="hint" id="hint"></div>
|
|
@@ -167,6 +139,7 @@ ${canvasCss}
|
|
|
167
139
|
window.__CLADO__ = ${json(doc)};
|
|
168
140
|
window.__CLADO_CMD__ = ${json(command)};
|
|
169
141
|
window.__CLADO_LIVE__ = ${json(!!options.library)};
|
|
142
|
+
window.__CLADO_WORKSPACE_CHROME__ = ${json(!!options.workspaceChrome)};
|
|
170
143
|
window.__CLADO_DIAG__ = ${json(diag)};
|
|
171
144
|
window.__CLADO_DIAGNOSTICS__ = ${json(diagnostics)};
|
|
172
145
|
window.__CLADO_FILE__ = ${json(basenameForDisplay(file))};
|
|
@@ -174,6 +147,7 @@ window.__CLADO_FILE__ = ${json(basenameForDisplay(file))};
|
|
|
174
147
|
<script id="clado-runtime">
|
|
175
148
|
${runtime}
|
|
176
149
|
</script>
|
|
150
|
+
${plugins.scripts}
|
|
177
151
|
<script id="clado-canvas-ui">${canvasUi}</script>
|
|
178
152
|
</body>
|
|
179
153
|
</html>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
const shared = ['plugin-ui.css', 'plugin-ui.js'].map(name => ({
|
|
4
|
+
path: '/' + name,
|
|
5
|
+
file: new URL(name, import.meta.url),
|
|
6
|
+
}));
|
|
7
|
+
const packageAssets = id =>
|
|
8
|
+
['style.css', 'index.js'].map(name => {
|
|
9
|
+
const path = '/plugins/' + id + '/' + name;
|
|
10
|
+
return { path, file: new URL('../..' + path, import.meta.url) };
|
|
11
|
+
});
|
|
12
|
+
const canvasAssets = [...shared, ...packageAssets('brand'), ...packageAssets('view-controls')];
|
|
13
|
+
const screenshotAssets = [
|
|
14
|
+
{ path: '/html-to-image.js', file: new URL('../vendor/html-to-image.min.js', import.meta.url) },
|
|
15
|
+
{ path: '/canvas-screenshot.js', file: new URL('canvas-screenshot.js', import.meta.url) },
|
|
16
|
+
];
|
|
17
|
+
const workspaceAssets = [...canvasAssets, ...packageAssets('directory'), ...screenshotAssets];
|
|
18
|
+
const agentAssets = packageAssets('agent');
|
|
19
|
+
export const workspacePluginAssets = new Map([...workspaceAssets, ...agentAssets].map(({ path, file }) => [path, file]));
|
|
20
|
+
|
|
21
|
+
export function pluginMarkup({ workspace = false, inline = false, agent = false, materialOnly = false } = {}) {
|
|
22
|
+
const assets = materialOnly ? [shared[0]] : agent ? [...workspaceAssets, ...agentAssets] : workspace ? workspaceAssets : canvasAssets;
|
|
23
|
+
const tags = { styles: [], scripts: [] };
|
|
24
|
+
for (const { path, file } of assets) {
|
|
25
|
+
const css = path.endsWith('.css');
|
|
26
|
+
if (css) {
|
|
27
|
+
tags.styles.push(inline ? '<style>' + readFileSync(file, 'utf8') + '</style>' : '<link rel="stylesheet" href="' + path + '">');
|
|
28
|
+
} else {
|
|
29
|
+
tags.scripts.push(inline ? '<script>' + readFileSync(file, 'utf8').replace(/<\/script/gi, '<\\/script') + '</script>' : '<script src="' + path + '"></script>');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { styles: tags.styles.join('\n'), scripts: tags.scripts.join('\n') };
|
|
33
|
+
}
|