cladogram 0.5.3 → 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 +19 -0
- package/bin/clado.js +13 -2
- package/docs/plugin-development.md +135 -0
- package/docs/plugin-ui.md +43 -0
- package/docs/release.md +7 -0
- package/package.json +7 -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 +4 -0
- package/src/html/app-css.js +9 -40
- package/src/html/canvas-chain.js +5 -6
- package/src/html/canvas-focus.js +2 -4
- package/src/html/canvas-screenshot.js +199 -0
- package/src/html/canvas-ui.css +5 -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 +41 -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 +12 -9
- 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 +227 -44
- package/src/server/canvas-capture.js +47 -0
- package/src/server/export.js +5 -2
- package/src/server/mcp.js +29 -6
- 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 +127 -11
- package/src/vendor/html-to-image.min.js +24 -0
- package/src/server/assets/tree.js +0 -26
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
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--clado-ui-text: #191919;
|
|
3
|
+
--clado-ui-muted: #565656;
|
|
4
|
+
--clado-ui-accent: #252525;
|
|
5
|
+
--clado-ui-surface: rgb(252 252 252 / .04);
|
|
6
|
+
--clado-ui-panel-surface: rgb(250 250 250 / .13);
|
|
7
|
+
--clado-ui-well: rgb(231 231 231 / .46);
|
|
8
|
+
--clado-ui-solid: #f8f8f8;
|
|
9
|
+
--clado-ui-edge: #17171724;
|
|
10
|
+
--clado-ui-active: #e9e9e9;
|
|
11
|
+
--clado-ui-highlight: rgb(255 255 255 / .34);
|
|
12
|
+
--clado-ui-rim: rgb(93 93 93 / .08);
|
|
13
|
+
--clado-ui-shadow: 0 3px 12px rgb(21 21 21 / .10), 0 1px 3px rgb(21 21 21 / .06);
|
|
14
|
+
--clado-ui-glass-outline: rgb(100 100 100 / .17);
|
|
15
|
+
--clado-ui-glass-shadow: 0 5px 22px rgb(21 21 21 / .09);
|
|
16
|
+
--clado-ui-control-blur: 14px;
|
|
17
|
+
--clado-ui-panel-blur: 18px;
|
|
18
|
+
--clado-ui-radius: 16px;
|
|
19
|
+
--clado-ui-gap: 8px;
|
|
20
|
+
}
|
|
21
|
+
:root[data-theme="dark"] {
|
|
22
|
+
color-scheme: dark;
|
|
23
|
+
--clado-ui-text: #f3f3f3;
|
|
24
|
+
--clado-ui-muted: #b4b4b4;
|
|
25
|
+
--clado-ui-accent: #ededed;
|
|
26
|
+
--clado-ui-surface: rgb(33 33 33 / .38);
|
|
27
|
+
--clado-ui-panel-surface: rgb(30 30 30 / .68);
|
|
28
|
+
--clado-ui-well: rgb(128 128 128 / .16);
|
|
29
|
+
--clado-ui-solid: #292929;
|
|
30
|
+
--clado-ui-edge: #ffffff2a;
|
|
31
|
+
--clado-ui-active: #424242;
|
|
32
|
+
--clado-ui-highlight: #ffffff23;
|
|
33
|
+
--clado-ui-rim: #ffffff23;
|
|
34
|
+
--clado-ui-shadow: 0 8px 26px #0005, 0 2px 6px #0003;
|
|
35
|
+
--clado-ui-glass-outline: rgb(180 180 180 / .23);
|
|
36
|
+
--clado-ui-glass-shadow: 0 6px 24px #0005;
|
|
37
|
+
--clado-ui-control-blur: 14px;
|
|
38
|
+
--clado-ui-panel-blur: 30px;
|
|
39
|
+
}
|
|
40
|
+
.clado-plugin-slot {
|
|
41
|
+
position: fixed;
|
|
42
|
+
display: flex;
|
|
43
|
+
gap: var(--clado-ui-gap);
|
|
44
|
+
z-index: 18;
|
|
45
|
+
font: 13px/1.35 system-ui, sans-serif;
|
|
46
|
+
pointer-events: none;
|
|
47
|
+
}
|
|
48
|
+
.clado-plugin-slot[hidden], .clado-plugin-slot [hidden] { display: none !important; }
|
|
49
|
+
.clado-plugin-slot > * { pointer-events: auto; }
|
|
50
|
+
.clado-plugin-slot[data-slot="top-left"] { top: 14px; left: 16px; max-width: calc(100vw - 250px); flex-direction: column; align-items: start; }
|
|
51
|
+
.clado-plugin-slot[data-slot="top-right"] { top: 14px; right: 16px; flex-direction: column; align-items: end; }
|
|
52
|
+
.clado-plugin-slot[data-slot="bottom-left"] { bottom: 16px; left: 16px; align-items: end; }
|
|
53
|
+
.clado-plugin-slot[data-slot="bottom-right"] { bottom: 16px; right: 16px; flex-direction: column-reverse; align-items: end; }
|
|
54
|
+
:where(.clado-ui-glass) {
|
|
55
|
+
position: relative;
|
|
56
|
+
z-index: 0;
|
|
57
|
+
}
|
|
58
|
+
.clado-ui-glass {
|
|
59
|
+
--clado-ui-glass-fill: var(--clado-ui-surface);
|
|
60
|
+
--clado-ui-glass-blur: var(--clado-ui-control-blur);
|
|
61
|
+
--clado-ui-glass-feather: 3px;
|
|
62
|
+
color: var(--clado-ui-text);
|
|
63
|
+
background: var(--clado-ui-solid);
|
|
64
|
+
border: 1px solid var(--clado-ui-edge);
|
|
65
|
+
border-radius: var(--clado-ui-radius);
|
|
66
|
+
box-shadow: var(--clado-ui-shadow);
|
|
67
|
+
}
|
|
68
|
+
.clado-ui-glass.clado-ui-glass-panel {
|
|
69
|
+
--clado-ui-glass-fill: var(--clado-ui-panel-surface);
|
|
70
|
+
--clado-ui-glass-blur: var(--clado-ui-panel-blur);
|
|
71
|
+
--clado-ui-glass-feather: 5px;
|
|
72
|
+
}
|
|
73
|
+
.clado-ui-button {
|
|
74
|
+
appearance: none;
|
|
75
|
+
border: 1px solid transparent;
|
|
76
|
+
background: transparent;
|
|
77
|
+
color: var(--clado-ui-muted);
|
|
78
|
+
border-radius: 10px;
|
|
79
|
+
font: inherit;
|
|
80
|
+
line-height: 1.15;
|
|
81
|
+
min-height: 32px;
|
|
82
|
+
padding: 5px 10px;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
white-space: nowrap;
|
|
85
|
+
}
|
|
86
|
+
.clado-ui-button:where(:hover:not(:disabled), [aria-pressed="true"], [aria-expanded="true"], [aria-current="page"], .clado-ui-button-primary) {
|
|
87
|
+
color: var(--clado-ui-accent);
|
|
88
|
+
background: var(--clado-ui-active);
|
|
89
|
+
}
|
|
90
|
+
.clado-ui-button:focus-visible { outline: 2px solid var(--clado-ui-accent); outline-offset: 2px; }
|
|
91
|
+
.clado-ui-button:disabled { opacity: .5; cursor: default; }
|
|
92
|
+
.clado-ui-dialog {
|
|
93
|
+
color-scheme: light;
|
|
94
|
+
--clado-ui-text: #191919;
|
|
95
|
+
--clado-ui-muted: #565656;
|
|
96
|
+
--clado-ui-accent: #252525;
|
|
97
|
+
--clado-ui-edge: #17171724;
|
|
98
|
+
--clado-ui-active: #e9e9e9;
|
|
99
|
+
--ink: var(--clado-ui-text);
|
|
100
|
+
--muted: var(--clado-ui-muted);
|
|
101
|
+
--line: #e3e3e3;
|
|
102
|
+
color: var(--clado-ui-text);
|
|
103
|
+
background: #fff;
|
|
104
|
+
border: 1px solid #e3e3e3;
|
|
105
|
+
border-radius: var(--clado-ui-radius);
|
|
106
|
+
box-shadow: 0 10px 36px rgb(21 21 21 / .14);
|
|
107
|
+
}
|
|
108
|
+
.clado-ui-dialog::backdrop { background: transparent; }
|
|
109
|
+
.clado-ui-glass.clado-ui-button {
|
|
110
|
+
background-color: var(--clado-ui-solid);
|
|
111
|
+
border-color: var(--clado-ui-edge);
|
|
112
|
+
}
|
|
113
|
+
.clado-ui-glass.clado-ui-button:where(:hover:not(:disabled), [aria-expanded="true"], [aria-pressed="true"], [aria-current="page"], .clado-ui-button-primary) {
|
|
114
|
+
background-color: var(--clado-ui-active);
|
|
115
|
+
}
|
|
116
|
+
@supports (backdrop-filter: blur(1px)) {
|
|
117
|
+
@media (prefers-reduced-transparency: no-preference) {
|
|
118
|
+
.clado-ui-glass {
|
|
119
|
+
background: transparent;
|
|
120
|
+
border-color: var(--clado-ui-glass-outline);
|
|
121
|
+
box-shadow: var(--clado-ui-glass-shadow);
|
|
122
|
+
}
|
|
123
|
+
.clado-ui-glass::before {
|
|
124
|
+
content: "";
|
|
125
|
+
position: absolute;
|
|
126
|
+
z-index: -1;
|
|
127
|
+
inset: 0;
|
|
128
|
+
border-radius: inherit;
|
|
129
|
+
pointer-events: none;
|
|
130
|
+
background: var(--clado-ui-glass-fill);
|
|
131
|
+
backdrop-filter: blur(var(--clado-ui-glass-blur)) saturate(145%);
|
|
132
|
+
/* Retain enough blur at the edge to keep text behind the glass indistinct. */
|
|
133
|
+
mask-image:
|
|
134
|
+
linear-gradient(to right, rgb(0 0 0 / .95), #000 var(--clado-ui-glass-feather), #000 calc(100% - var(--clado-ui-glass-feather)), rgb(0 0 0 / .95)),
|
|
135
|
+
linear-gradient(to bottom, rgb(0 0 0 / .95), #000 var(--clado-ui-glass-feather), #000 calc(100% - var(--clado-ui-glass-feather)), rgb(0 0 0 / .95));
|
|
136
|
+
mask-composite: intersect;
|
|
137
|
+
}
|
|
138
|
+
.clado-ui-button, .clado-ui-glass.clado-ui-button {
|
|
139
|
+
--clado-ui-button-tint: 4%;
|
|
140
|
+
--clado-ui-button-outline: color-mix(in srgb, var(--clado-ui-edge) 36%, transparent);
|
|
141
|
+
background: color-mix(in srgb, var(--clado-ui-accent) var(--clado-ui-button-tint), transparent) padding-box;
|
|
142
|
+
border-color: var(--clado-ui-button-outline);
|
|
143
|
+
}
|
|
144
|
+
.clado-ui-button:hover:where(:not(:disabled)) {
|
|
145
|
+
--clado-ui-button-tint: 8%;
|
|
146
|
+
}
|
|
147
|
+
.clado-ui-button:is([aria-expanded="true"], [aria-pressed="true"], [aria-current="page"], .clado-ui-button-primary) {
|
|
148
|
+
--clado-ui-button-tint: 12%;
|
|
149
|
+
--clado-ui-button-outline: color-mix(in srgb, var(--clado-ui-accent) 16%, transparent);
|
|
150
|
+
}
|
|
151
|
+
.clado-ui-glass.clado-ui-button {
|
|
152
|
+
border-color: var(--clado-ui-glass-outline);
|
|
153
|
+
}
|
|
154
|
+
@supports (mask-composite: exclude) {
|
|
155
|
+
/* Keep the highlights on a thin rim so a white canvas does not become a white fill. */
|
|
156
|
+
.clado-ui-glass::after {
|
|
157
|
+
content: "";
|
|
158
|
+
position: absolute;
|
|
159
|
+
z-index: 1;
|
|
160
|
+
inset: -1px;
|
|
161
|
+
padding: 1px;
|
|
162
|
+
border-radius: inherit;
|
|
163
|
+
pointer-events: none;
|
|
164
|
+
background: linear-gradient(146deg, var(--clado-ui-highlight), transparent 32% 58%, var(--clado-ui-rim));
|
|
165
|
+
mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
|
|
166
|
+
mask-composite: exclude;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
@media (max-width: 460px) {
|
|
172
|
+
.clado-plugin-slot[data-slot="top-left"] { top: 10px; left: 10px; max-width: calc(100vw - 207px); }
|
|
173
|
+
.clado-plugin-slot[data-slot="top-right"] { top: 10px; right: 10px; }
|
|
174
|
+
.clado-plugin-slot[data-slot="bottom-left"] { bottom: 10px; left: 10px; }
|
|
175
|
+
.clado-plugin-slot[data-slot="bottom-right"] { bottom: 10px; right: 10px; }
|
|
176
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
function createHost(bridge, isEnabled = () => true) {
|
|
3
|
+
const slots = new Map();
|
|
4
|
+
let hidden = false;
|
|
5
|
+
return {
|
|
6
|
+
capabilities(pluginId, mountId) {
|
|
7
|
+
if (!bridge || !isEnabled(pluginId)) return undefined;
|
|
8
|
+
const identity = { pluginId, mountId };
|
|
9
|
+
return {
|
|
10
|
+
provide: invoke => bridge.provide(identity, invoke),
|
|
11
|
+
list: query => bridge.list(identity, query),
|
|
12
|
+
call: (to, input) => bridge.call(identity, to, input),
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
mount(slot, element, pluginId) {
|
|
16
|
+
if (!isEnabled(pluginId)) return () => {};
|
|
17
|
+
if (!slots.has(slot)) {
|
|
18
|
+
const region = document.createElement('div');
|
|
19
|
+
region.className = 'clado-plugin-slot';
|
|
20
|
+
region.dataset.slot = slot;
|
|
21
|
+
region.hidden = hidden;
|
|
22
|
+
slots.set(slot, region);
|
|
23
|
+
document.body.append(region);
|
|
24
|
+
}
|
|
25
|
+
const region = slots.get(slot);
|
|
26
|
+
element.dataset.pluginId = pluginId;
|
|
27
|
+
region.append(element);
|
|
28
|
+
return () => {
|
|
29
|
+
element.remove();
|
|
30
|
+
if (!region.childElementCount) {
|
|
31
|
+
region.remove();
|
|
32
|
+
slots.delete(slot);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
setHidden(next) {
|
|
37
|
+
if (hidden === next) return;
|
|
38
|
+
hidden = next;
|
|
39
|
+
for (const slot of slots.values()) slot.hidden = hidden;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
window.CladoPluginUI = { createHost };
|
|
45
|
+
})();
|
package/src/html/runtime-api.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
setMode: setMode, setTheme: setTheme, clearFocus: clearLit,
|
|
4
4
|
focusPath: focusPath,
|
|
5
5
|
isChainOpen: canvasChainIsOpen,
|
|
6
|
+
isLensOpen: function () { return $('#lens').classList.contains('open'); },
|
|
7
|
+
isFocused: function () { return !!canvasFocusId; },
|
|
6
8
|
contentPath: function (id) { var r = canvasRecords[id]; return r ? r.fullPath : null; },
|
|
7
9
|
selectionPath: function (target) { var r = canvasRecordForTarget(target); return r && r.titlePath || null; },
|
|
8
10
|
hasSelectionPath: function (path) {
|
|
@@ -10,6 +12,45 @@
|
|
|
10
12
|
for (var record of Object.values(canvasRecords)) if (record.titlePath.length === path.length && path.every(function (part, i) { return part === record.titlePath[i]; })) count++;
|
|
11
13
|
return count === 1;
|
|
12
14
|
},
|
|
15
|
+
readPluginContext: function (fields, selectedPaths, page) {
|
|
16
|
+
var result = {}, mode = document.body.dataset.mode;
|
|
17
|
+
if (fields.includes('document')) {
|
|
18
|
+
result.document = { title: DOC.title, mode: mode, theme: document.documentElement.dataset.theme };
|
|
19
|
+
}
|
|
20
|
+
if (fields.includes('viewport')) {
|
|
21
|
+
var view = $(mode === 'doc' ? '#doc' : '#stage');
|
|
22
|
+
var bounds = view.getBoundingClientRect();
|
|
23
|
+
result.viewport = { width: bounds.width, height: bounds.height, scale: mode === 'doc' ? 1 : scale };
|
|
24
|
+
}
|
|
25
|
+
if (fields.includes('selection')) {
|
|
26
|
+
var byPath = new Map((selectedPaths.length ? Object.values(canvasRecords) : []).map(function (record) {
|
|
27
|
+
return [JSON.stringify(record.titlePath), record];
|
|
28
|
+
}));
|
|
29
|
+
function selectedContent(record) {
|
|
30
|
+
return { nodePath: record.titlePath, markdown: record.markdown,
|
|
31
|
+
children: record.kids.map(function (id) { return selectedContent(canvasRecords[id]); }) };
|
|
32
|
+
}
|
|
33
|
+
result.selection = selectedPaths.map(function (path) { return byPath.get(JSON.stringify(path)); })
|
|
34
|
+
.filter(Boolean).map(selectedContent);
|
|
35
|
+
}
|
|
36
|
+
if (fields.includes('graph')) {
|
|
37
|
+
var records = Object.values(canvasRecords);
|
|
38
|
+
var rows = records.map(function (record) {
|
|
39
|
+
return { kind: 'node', nodePath: record.titlePath,
|
|
40
|
+
parent: record.parent ? canvasRecords[record.parent].titlePath : null };
|
|
41
|
+
});
|
|
42
|
+
records.forEach(function (record) {
|
|
43
|
+
(canvasOut[record.id] || []).forEach(function (target) {
|
|
44
|
+
rows.push({ kind: 'link', from: record.titlePath, to: canvasRecords[target].titlePath });
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
result.graph = {
|
|
48
|
+
items: rows.slice(page.offset, page.offset + page.limit),
|
|
49
|
+
nextOffset: page.offset + page.limit < rows.length ? page.offset + page.limit : null
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
},
|
|
13
54
|
focusTitle: function (title) {
|
|
14
55
|
var r = Object.values(canvasRecords).find(function (r) { return r.title === title || r.fullPath === title; });
|
|
15
56
|
if (!r) return;
|
package/src/html/runtime.js
CHANGED
|
@@ -1328,10 +1328,18 @@
|
|
|
1328
1328
|
});
|
|
1329
1329
|
$$('img', inn).forEach(function (i) { i.style.maxWidth = 'none'; });
|
|
1330
1330
|
$('#lensLabel').textContent = label || '图';
|
|
1331
|
-
|
|
1331
|
+
if (!$('#lens').classList.contains('open')) {
|
|
1332
|
+
$('#lens').classList.add('open');
|
|
1333
|
+
document.dispatchEvent(new CustomEvent('clado:lens-open'));
|
|
1334
|
+
}
|
|
1332
1335
|
requestAnimationFrame(lensFit);
|
|
1333
1336
|
}
|
|
1334
|
-
function closeLens() {
|
|
1337
|
+
function closeLens() {
|
|
1338
|
+
if (!$('#lens').classList.contains('open')) return;
|
|
1339
|
+
$('#lens').classList.remove('open');
|
|
1340
|
+
$('#lensInner').innerHTML = '';
|
|
1341
|
+
document.dispatchEvent(new CustomEvent('clado:lens-close'));
|
|
1342
|
+
}
|
|
1335
1343
|
|
|
1336
1344
|
function flash(id) {
|
|
1337
1345
|
var el = render.card[id];
|
|
@@ -1464,14 +1472,13 @@
|
|
|
1464
1472
|
|
|
1465
1473
|
function setTheme(t, save) {
|
|
1466
1474
|
document.documentElement.dataset.theme = t;
|
|
1467
|
-
$('#theme').textContent = t === 'light' ? '☾︎' : '☀︎';
|
|
1468
1475
|
if (save !== false) { try { localStorage.setItem('clado-theme', t); } catch (e) {} }
|
|
1469
1476
|
renderMermaid(true).then(afterMedia);
|
|
1477
|
+
document.dispatchEvent(new CustomEvent('clado:view-state'));
|
|
1470
1478
|
}
|
|
1471
1479
|
|
|
1472
1480
|
function setMode(m) {
|
|
1473
1481
|
document.body.dataset.mode = m;
|
|
1474
|
-
$$('#modes button').forEach(function (b) { b.classList.toggle('on', b.dataset.mode === m); });
|
|
1475
1482
|
if (m === 'cards') {
|
|
1476
1483
|
requestAnimationFrame(function () {
|
|
1477
1484
|
applyVisibility();
|
|
@@ -1493,6 +1500,7 @@
|
|
|
1493
1500
|
} else {
|
|
1494
1501
|
renderMermaid().then(function () { canvasPlaceMediaJumps($('#article')); });
|
|
1495
1502
|
}
|
|
1503
|
+
document.dispatchEvent(new CustomEvent('clado:view-state'));
|
|
1496
1504
|
}
|
|
1497
1505
|
|
|
1498
1506
|
(function build() {
|
|
@@ -1515,9 +1523,10 @@
|
|
|
1515
1523
|
// 主题三级兜底:本机上次切过的 > 编译时写进 <html data-theme> 的 > light。
|
|
1516
1524
|
// 中间那一级就是 `--theme=dark` 生效的地方 —— 少了它,那个旗标收下来也没人看。
|
|
1517
1525
|
var t = document.documentElement.dataset.theme || 'light';
|
|
1518
|
-
|
|
1526
|
+
if (!window.__CLADO_WORKSPACE_CHROME__ && !window.__CLADO_CHAIN__) {
|
|
1527
|
+
try { t = localStorage.getItem('clado-theme') || t; } catch (e) {}
|
|
1528
|
+
}
|
|
1519
1529
|
document.documentElement.dataset.theme = t;
|
|
1520
|
-
$('#theme').textContent = t === 'light' ? '☾︎' : '☀︎';
|
|
1521
1530
|
|
|
1522
1531
|
fit();
|
|
1523
1532
|
applyVisibility(); // 淡出收起来的卡、给端口上灰/蓝,顺带把线画了(此时 scale 已经对了)
|
|
@@ -1556,11 +1565,5 @@
|
|
|
1556
1565
|
DOC.cards.forEach(function (c) { ro.observe(render.card[c.id]); });
|
|
1557
1566
|
}
|
|
1558
1567
|
|
|
1559
|
-
$$('#modes button').forEach(function (b) {
|
|
1560
|
-
b.addEventListener('click', function () { setMode(b.dataset.mode); });
|
|
1561
|
-
});
|
|
1562
|
-
$('#theme').addEventListener('click', function () {
|
|
1563
|
-
setTheme(document.documentElement.dataset.theme === 'light' ? 'dark' : 'light');
|
|
1564
|
-
});
|
|
1565
1568
|
})();
|
|
1566
1569
|
})();
|