cladogram 0.5.5-beta.9 → 0.6.0-beta.1
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 +102 -79
- package/bin/clado.js +1 -1
- package/docs/release.md +7 -0
- package/package.json +3 -3
- package/plugins/agent/index.js +928 -3131
- package/plugins/agent/style.css +404 -1511
- package/plugins/brand/index.js +84 -466
- package/plugins/brand/style.css +39 -172
- package/plugins/directory/index.js +10 -10
- package/plugins/view-controls/index.js +17 -1
- package/plugins/view-controls/style.css +47 -29
- package/src/agent/clado-tools.js +299 -0
- package/src/agent/pi-bridge.js +487 -0
- package/src/agent/pi-config.js +630 -0
- package/src/html/plugin-ui.css +159 -134
- package/src/html/plugin-ui.js +3 -2
- package/src/server/agent.js +329 -1590
- package/src/server/assets/library.css +396 -11
- package/src/server/assets/library.html +37 -4
- package/src/server/assets/library.js +428 -203
- package/src/server/plugin-registry.js +7 -7
- package/src/server/plugins.js +1 -1
- package/src/server/workspace-hub.js +50 -0
- package/src/server/workspace.js +4 -15
- package/src/agent/commands.js +0 -204
- package/src/agent/context.js +0 -445
- package/src/agent/executors.js +0 -213
- package/src/agent/mcp-client.js +0 -308
- package/src/agent/probe.js +0 -234
- package/src/agent/providers/anthropic.js +0 -220
- package/src/agent/providers/index.js +0 -235
- package/src/agent/providers/openai.js +0 -146
- package/src/agent/runtime.js +0 -995
- package/src/agent/sessions.js +0 -336
- package/src/agent/skills.js +0 -190
package/plugins/brand/index.js
CHANGED
|
@@ -1,480 +1,98 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} catch (error) {
|
|
51
|
-
if (request === epoch) status.textContent = error.message;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
confirm.onclick = async () => {
|
|
55
|
-
if (!selected || confirm.disabled) return;
|
|
56
|
-
confirm.disabled = true;
|
|
57
|
-
status.textContent = '正在安装…';
|
|
58
|
-
try {
|
|
59
|
-
const files = await Promise.all(selected.map(({ file, path }) => new Promise((resolve, reject) => {
|
|
60
|
-
const reader = new FileReader();
|
|
61
|
-
reader.onload = () => resolve({ path, data: reader.result.split(',')[1] });
|
|
62
|
-
reader.onerror = reject;
|
|
63
|
-
reader.readAsDataURL(file);
|
|
64
|
-
})));
|
|
65
|
-
await plugins.install(files);
|
|
66
|
-
plugins.refresh();
|
|
67
|
-
} catch (error) {
|
|
68
|
-
status.textContent = error.message || '安装失败。';
|
|
69
|
-
confirm.disabled = false;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
return clear;
|
|
73
|
-
}
|
|
2
|
+
const icoBack = '<svg class="clado-svg-ico" aria-hidden="true" viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>';
|
|
3
|
+
const icoGear = '<svg class="clado-svg-ico" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9c.26.6.85 1 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>';
|
|
4
|
+
const icoSun = '<svg class="clado-svg-ico" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M2 12h2m16 0h2M4.9 4.9l1.4 1.4m11.4 11.4 1.4 1.4M6.3 17.7l-1.4 1.4M17.7 6.3l1.4-1.4"/></svg>';
|
|
5
|
+
const icoMoon = '<svg class="clado-svg-ico" aria-hidden="true" viewBox="0 0 24 24"><path d="M19.8 15.2A8.4 8.4 0 0 1 8.8 4.1 8.5 8.5 0 1 0 19.8 15.2Z"/></svg>';
|
|
6
|
+
const icoCamera = '<svg class="clado-svg-ico" aria-hidden="true" viewBox="0 0 24 24"><path d="M8 3H5a2 2 0 0 0-2 2v3m13-5h3a2 2 0 0 1 2 2v3M3 16v3a2 2 0 0 0 2 2h3m13-5v3a2 2 0 0 1-2 2h-3"/><rect x="8" y="8" width="8" height="8" rx="1.5"/></svg>';
|
|
7
|
+
|
|
8
|
+
function mountBrand(host, actions = {}) {
|
|
9
|
+
const wrap = document.createElement('div');
|
|
10
|
+
wrap.className = 'clado-brand-plugin';
|
|
11
|
+
|
|
12
|
+
// Live Workspace Pill Mode: [< 大厅] workspaceName | [设置]
|
|
13
|
+
if (actions.openLobby || actions.openSettings) {
|
|
14
|
+
const pill = document.createElement('div');
|
|
15
|
+
pill.className = 'clado-ui-glass clado-top-pill';
|
|
16
|
+
|
|
17
|
+
const lobbyBtn = document.createElement('button');
|
|
18
|
+
lobbyBtn.type = 'button';
|
|
19
|
+
lobbyBtn.className = 'clado-ui-button clado-top-pill-btn';
|
|
20
|
+
lobbyBtn.innerHTML = icoBack + '<span>大厅</span>';
|
|
21
|
+
lobbyBtn.title = '返回工作区大厅';
|
|
22
|
+
lobbyBtn.onclick = () => actions.openLobby?.();
|
|
23
|
+
|
|
24
|
+
const wsName = document.createElement('span');
|
|
25
|
+
wsName.className = 'clado-top-pill-ws';
|
|
26
|
+
wsName.textContent = actions.workspaceName || 'clado';
|
|
27
|
+
|
|
28
|
+
const sep = document.createElement('span');
|
|
29
|
+
sep.className = 'clado-top-pill-sep';
|
|
30
|
+
|
|
31
|
+
const settingsBtn = document.createElement('button');
|
|
32
|
+
settingsBtn.type = 'button';
|
|
33
|
+
settingsBtn.className = 'clado-ui-button clado-top-pill-btn';
|
|
34
|
+
settingsBtn.innerHTML = icoGear + '<span>设置</span>';
|
|
35
|
+
settingsBtn.title = '打开统一设置中心';
|
|
36
|
+
settingsBtn.onclick = () => actions.openSettings?.();
|
|
37
|
+
|
|
38
|
+
pill.append(lobbyBtn, wsName, sep, settingsBtn);
|
|
39
|
+
wrap.append(pill);
|
|
40
|
+
host.mount('top-left', wrap, 'clado.brand');
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
sync() {},
|
|
44
|
+
setWorkspaceName(name) {
|
|
45
|
+
wsName.textContent = name || 'clado';
|
|
46
|
+
},
|
|
47
|
+
close() {},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
74
50
|
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
dialog.querySelector('.clado-plugin-editor-path').textContent = '.clado/plugin-settings.json';
|
|
95
|
-
dialog.querySelector('pre').textContent = '';
|
|
96
|
-
field.value = '';
|
|
97
|
-
field.disabled = save.disabled = true;
|
|
98
|
-
status.textContent = '正在读取配置…';
|
|
99
|
-
dialog.showModal();
|
|
100
|
-
try {
|
|
101
|
-
const { value, schema, defaults, path } = await edit(plugin.id);
|
|
102
|
-
if (current !== request) return;
|
|
103
|
-
field.value = JSON.stringify(value, null, 2);
|
|
104
|
-
dialog.querySelector('.clado-plugin-editor-path').textContent = path;
|
|
105
|
-
dialog.querySelector('pre').textContent = JSON.stringify({ schema, defaults }, null, 2);
|
|
106
|
-
field.disabled = save.disabled = false;
|
|
107
|
-
status.textContent = '';
|
|
108
|
-
save.onclick = async () => {
|
|
109
|
-
let next;
|
|
110
|
-
try { next = JSON.parse(field.value); }
|
|
111
|
-
catch { status.textContent = 'JSON 格式有误,请修改后再保存。'; field.focus(); return; }
|
|
112
|
-
field.disabled = save.disabled = true;
|
|
113
|
-
try { await edit(plugin.id, next, value); }
|
|
114
|
-
catch (error) {
|
|
115
|
-
if (current !== request) return;
|
|
116
|
-
status.textContent = error.message;
|
|
117
|
-
field.disabled = save.disabled = false;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
} catch (error) {
|
|
121
|
-
if (current === request) status.textContent = error.message;
|
|
122
|
-
}
|
|
51
|
+
// Standalone / Offline Export Pill Mode
|
|
52
|
+
const pill = document.createElement('div');
|
|
53
|
+
pill.className = 'clado-ui-glass clado-top-pill';
|
|
54
|
+
|
|
55
|
+
const title = document.createElement('span');
|
|
56
|
+
title.className = 'clado-top-pill-ws';
|
|
57
|
+
title.style.paddingLeft = '8px';
|
|
58
|
+
title.textContent = 'clado';
|
|
59
|
+
|
|
60
|
+
const sep = document.createElement('span');
|
|
61
|
+
sep.className = 'clado-top-pill-sep';
|
|
62
|
+
|
|
63
|
+
let currentTheme = 'light';
|
|
64
|
+
const themeBtn = document.createElement('button');
|
|
65
|
+
themeBtn.type = 'button';
|
|
66
|
+
themeBtn.className = 'clado-ui-button clado-top-pill-btn';
|
|
67
|
+
themeBtn.onclick = () => {
|
|
68
|
+
const next = currentTheme === 'dark' ? 'light' : 'dark';
|
|
69
|
+
actions.setTheme?.(next);
|
|
123
70
|
};
|
|
124
|
-
}
|
|
125
71
|
|
|
126
|
-
|
|
127
|
-
if (!market || !document.body) return null;
|
|
128
|
-
const overlay = document.createElement('div');
|
|
129
|
-
overlay.id = 'clado-market-overlay';
|
|
130
|
-
overlay.className = 'clado-market-overlay';
|
|
131
|
-
overlay.innerHTML = `
|
|
132
|
-
<div class="clado-market-sheet">
|
|
133
|
-
<div class="clado-market-well" style="padding:12px;display:flex;flex-direction:column;gap:9px;">
|
|
134
|
-
<div style="display:flex;align-items:center;justify-content:space-between;gap:6px;flex-wrap:wrap;">
|
|
135
|
-
<strong style="font-size:15px;">插件市场</strong>
|
|
136
|
-
<div style="display:flex;align-items:center;gap:5px;">
|
|
137
|
-
<div class="clado-market-tabs">
|
|
138
|
-
<button type="button" class="clado-market-tab active" data-m-src="official">官方源</button>
|
|
139
|
-
<button type="button" class="clado-market-tab" data-m-src="team">团队私有源</button>
|
|
140
|
-
</div>
|
|
141
|
-
<button type="button" class="clado-market-tab active" data-m-close style="padding:4.5px 10px;">完成</button>
|
|
142
|
-
</div>
|
|
143
|
-
</div>
|
|
144
|
-
<input type="text" data-m-search placeholder="搜索插件…" style="width:100%;padding:8px 11px;border-radius:10px;border:1px solid var(--clado-ui-well-border);background:var(--clado-ui-well);color:var(--clado-ui-text);font:inherit;font-size:13px;outline:none;" />
|
|
145
|
-
<div style="display:flex;gap:4px;overflow-x:auto;">
|
|
146
|
-
<button type="button" class="clado-market-tab active" data-m-cat="all">全部</button>
|
|
147
|
-
<button type="button" class="clado-market-tab" data-m-cat="multi">多实例</button>
|
|
148
|
-
<button type="button" class="clado-market-tab" data-m-cat="tool">纯工具</button>
|
|
149
|
-
<button type="button" class="clado-market-tab" data-m-cat="hybrid">视图+工具</button>
|
|
150
|
-
<button type="button" class="clado-market-tab" data-m-cat="executor">执行器</button>
|
|
151
|
-
</div>
|
|
152
|
-
</div>
|
|
153
|
-
<div data-m-list style="display:flex;flex-direction:column;gap:8px;"></div>
|
|
154
|
-
<div data-m-detail class="clado-market-well" style="display:none;padding:14px;flex-direction:column;gap:11px;"></div>
|
|
155
|
-
</div>`;
|
|
156
|
-
document.body.append(overlay);
|
|
72
|
+
pill.append(title, sep, themeBtn);
|
|
157
73
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const kindLabels = { multi: '多实例', tool: '纯工具', hybrid: '视图+工具', executor: '执行器', ui: '界面插件' };
|
|
167
|
-
const inferKind = p => p.kind || (p.category === 'executor' ? 'executor' : 'tool');
|
|
168
|
-
|
|
169
|
-
function renderList() {
|
|
170
|
-
const q = (searchInput.value || '').trim().toLowerCase();
|
|
171
|
-
detailEl.style.display = 'none';
|
|
172
|
-
listEl.style.display = 'flex';
|
|
173
|
-
listEl.replaceChildren();
|
|
174
|
-
|
|
175
|
-
const filtered = catalog.filter(p => {
|
|
176
|
-
const pSrc = p.source || 'official';
|
|
177
|
-
if (sourceFilter === 'team' && pSrc !== 'team') return false;
|
|
178
|
-
const k = inferKind(p);
|
|
179
|
-
if (catFilter !== 'all' && k !== catFilter) return false;
|
|
180
|
-
if (q && !(p.name + ' ' + p.description + ' ' + p.id).toLowerCase().includes(q)) return false;
|
|
181
|
-
return true;
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
if (!filtered.length) {
|
|
185
|
-
const empty = document.createElement('div');
|
|
186
|
-
empty.className = 'clado-market-well';
|
|
187
|
-
empty.style.cssText = 'padding:16px;text-align:center;color:var(--clado-ui-muted);font-size:12.5px;';
|
|
188
|
-
empty.textContent = '当前筛选下暂无匹配插件';
|
|
189
|
-
listEl.append(empty);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
for (const p of filtered) {
|
|
194
|
-
const card = document.createElement('div');
|
|
195
|
-
card.className = 'clado-market-well clado-market-card';
|
|
196
|
-
card.dataset.mId = p.id;
|
|
197
|
-
const risk = p.audit?.highestRisk || 'low';
|
|
198
|
-
const k = inferKind(p);
|
|
199
|
-
const installed = installedSet.has(p.id);
|
|
200
|
-
card.innerHTML = `
|
|
201
|
-
<div style="display:flex;align-items:flex-start;gap:10px;">
|
|
202
|
-
<span style="width:36px;height:36px;border-radius:11px;background:var(--clado-ui-well);border:1px solid var(--clado-ui-well-border);display:inline-flex;align-items:center;justify-content:center;font-size:17px;flex:none;">${p.icon || '🧩'}</span>
|
|
203
|
-
<div style="flex:1;min-width:0;">
|
|
204
|
-
<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap;">
|
|
205
|
-
<strong style="font-size:13.5px;">${p.name}</strong>
|
|
206
|
-
<span style="padding:1px 6px;border-radius:6px;background:rgba(59,130,246,0.13);color:var(--clado-ui-brand);font-size:10px;font-weight:600;">${kindLabels[k] || '扩展'}</span>
|
|
207
|
-
${installed ? '<span style="font-size:10px;color:#059669;font-weight:600;">已安装</span>' : ''}
|
|
208
|
-
<span class="clado-risk-pill clado-risk-${risk}" style="margin-left:auto;">${risk}</span>
|
|
209
|
-
</div>
|
|
210
|
-
<div style="font-size:12px;color:var(--clado-ui-muted);margin-top:4px;line-height:1.45;">${p.description || ''}</div>
|
|
211
|
-
</div>
|
|
212
|
-
</div>`;
|
|
213
|
-
card.onclick = () => openDetail(p);
|
|
214
|
-
listEl.append(card);
|
|
215
|
-
}
|
|
74
|
+
if (actions.capture) {
|
|
75
|
+
const capBtn = document.createElement('button');
|
|
76
|
+
capBtn.type = 'button';
|
|
77
|
+
capBtn.className = 'clado-ui-button clado-top-pill-btn';
|
|
78
|
+
capBtn.innerHTML = icoCamera + '<span>截图</span>';
|
|
79
|
+
capBtn.onclick = () => actions.capture();
|
|
80
|
+
pill.append(capBtn);
|
|
216
81
|
}
|
|
217
82
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
detailEl.style.display = 'flex';
|
|
221
|
-
const risk = p.audit?.highestRisk || 'low';
|
|
222
|
-
const installed = installedSet.has(p.id);
|
|
223
|
-
const auditItems = Array.isArray(p.audit?.items) ? p.audit.items : [];
|
|
224
|
-
detailEl.innerHTML = `
|
|
225
|
-
<div style="display:flex;justify-content:space-between;align-items:center;">
|
|
226
|
-
<button type="button" class="clado-market-tab active" data-m-back>← 返回列表</button>
|
|
227
|
-
<span class="clado-risk-pill clado-risk-${risk}">权限风险:${risk}</span>
|
|
228
|
-
</div>
|
|
229
|
-
<div style="display:flex;align-items:center;gap:10px;">
|
|
230
|
-
<span style="width:42px;height:42px;border-radius:12px;background:var(--clado-ui-well);border:1px solid var(--clado-ui-well-border);display:inline-flex;align-items:center;justify-content:center;font-size:20px;flex:none;">${p.icon || '🧩'}</span>
|
|
231
|
-
<div style="flex:1;min-width:0;">
|
|
232
|
-
<div style="font-size:15px;font-weight:700;">${p.name}</div>
|
|
233
|
-
<div style="font-size:11.5px;color:var(--clado-ui-subtle);">${p.id} · v${p.version} · ${p.author || 'community'}</div>
|
|
234
|
-
</div>
|
|
235
|
-
<button type="button" data-m-toggle style="height:32px;padding:0 13px;border-radius:9px;border:0;background:${installed ? 'var(--clado-ui-well)' : 'var(--clado-ui-brand)'};color:${installed ? 'var(--clado-ui-text)' : '#fff'};font:inherit;font-size:12px;font-weight:600;cursor:pointer;">${installed ? '卸载' : '安装'}</button>
|
|
236
|
-
</div>
|
|
237
|
-
<div style="font-size:12.5px;line-height:1.55;color:var(--clado-ui-muted);">${p.readme || p.description || ''}</div>
|
|
238
|
-
<div style="border-top:1px solid var(--clado-ui-edge);padding-top:9px;font-size:11.5px;color:var(--clado-ui-muted);display:flex;flex-direction:column;gap:4px;">
|
|
239
|
-
<strong style="color:var(--clado-ui-text);font-size:11.5px;">权限审计明细</strong>
|
|
240
|
-
${auditItems.length ? auditItems.map(a => `<div>· [${a.risk}] ${a.summary}</div>`).join('') : '<div>· 无额外敏感权限声明</div>'}
|
|
241
|
-
</div>
|
|
242
|
-
<div data-m-status style="font-size:11.5px;color:var(--clado-ui-brand);"></div>`;
|
|
243
|
-
|
|
244
|
-
detailEl.querySelector('[data-m-back]').onclick = () => renderList();
|
|
245
|
-
const toggleBtn = detailEl.querySelector('[data-m-toggle]');
|
|
246
|
-
const statusLine = detailEl.querySelector('[data-m-status]');
|
|
247
|
-
toggleBtn.onclick = async () => {
|
|
248
|
-
toggleBtn.disabled = true;
|
|
249
|
-
statusLine.textContent = installed ? '正在卸载…' : '正在安装并审计…';
|
|
250
|
-
try {
|
|
251
|
-
if (installed) {
|
|
252
|
-
await market.uninstall(p.id);
|
|
253
|
-
installedSet.delete(p.id);
|
|
254
|
-
} else {
|
|
255
|
-
await market.install(p.id);
|
|
256
|
-
installedSet.add(p.id);
|
|
257
|
-
}
|
|
258
|
-
openDetail(p);
|
|
259
|
-
} catch (err) {
|
|
260
|
-
statusLine.textContent = err.message || '操作失败';
|
|
261
|
-
toggleBtn.disabled = false;
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
}
|
|
83
|
+
wrap.append(pill);
|
|
84
|
+
host.mount('top-left', wrap, 'clado.brand');
|
|
265
85
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const res = await market.load();
|
|
270
|
-
catalog = Array.isArray(res?.plugins) ? res.plugins : [];
|
|
271
|
-
installedSet = new Set(res?.installedIds || []);
|
|
272
|
-
if (res?.origin && res.origin !== 'builtin') {
|
|
273
|
-
for (const p of catalog) if (!p.source) p.source = 'team';
|
|
274
|
-
}
|
|
275
|
-
} catch {}
|
|
276
|
-
renderList();
|
|
86
|
+
function sync(theme) {
|
|
87
|
+
currentTheme = theme === 'dark' ? 'dark' : 'light';
|
|
88
|
+
themeBtn.innerHTML = (currentTheme === 'dark' ? icoSun : icoMoon) + '<span>' + (currentTheme === 'dark' ? '浅色' : '暗色') + '</span>';
|
|
277
89
|
}
|
|
90
|
+
sync('light');
|
|
278
91
|
|
|
279
|
-
function close() {
|
|
280
|
-
overlay.classList.remove('show');
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
overlay.addEventListener('click', ev => {
|
|
284
|
-
if (ev.target === overlay || ev.target.closest('[data-m-close]')) {
|
|
285
|
-
close();
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
const srcBtn = ev.target.closest('[data-m-src]');
|
|
289
|
-
if (srcBtn) {
|
|
290
|
-
sourceFilter = srcBtn.dataset.mSrc;
|
|
291
|
-
overlay.querySelectorAll('[data-m-src]').forEach(b => b.classList.toggle('active', b === srcBtn));
|
|
292
|
-
renderList();
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
const catBtn = ev.target.closest('[data-m-cat]');
|
|
296
|
-
if (catBtn) {
|
|
297
|
-
catFilter = catBtn.dataset.mCat;
|
|
298
|
-
overlay.querySelectorAll('[data-m-cat]').forEach(b => b.classList.toggle('active', b === catBtn));
|
|
299
|
-
renderList();
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
searchInput.addEventListener('input', () => renderList());
|
|
303
|
-
window.addEventListener('clado:open-market', () => open());
|
|
304
|
-
document.addEventListener('keydown', ev => {
|
|
305
|
-
if (ev.key === 'Escape' && overlay.classList.contains('show')) close();
|
|
306
|
-
});
|
|
307
|
-
return { open, close };
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function mountBrand(host, { setTheme, capture, plugins, market, openWorkspacePicker }) {
|
|
311
|
-
const brand = document.createElement('div');
|
|
312
|
-
brand.className = 'clado-brand-plugin';
|
|
313
|
-
const brandLogo = '<svg viewBox="0 0 64 64" fill="none" aria-hidden="true">' +
|
|
314
|
-
'<defs>' +
|
|
315
|
-
'<linearGradient id="cladoLogoBg" x1="8" y1="6" x2="56" y2="58" gradientUnits="userSpaceOnUse"><stop offset="0%" stop-color="#333842"/><stop offset="100%" stop-color="#14171d"/></linearGradient>' +
|
|
316
|
-
'<linearGradient id="cladoLogoAura" x1="12" y1="56" x2="52" y2="56" gradientUnits="userSpaceOnUse"><stop offset="0%" stop-color="#38bdf8" stop-opacity="0"/><stop offset="28%" stop-color="#38bdf8" stop-opacity="0.95"/><stop offset="50%" stop-color="#818cf8" stop-opacity="1"/><stop offset="72%" stop-color="#e879f9" stop-opacity="0.9"/><stop offset="100%" stop-color="#f472b6" stop-opacity="0"/></linearGradient>' +
|
|
317
|
-
'</defs>' +
|
|
318
|
-
'<rect x="4" y="4" width="56" height="56" rx="16" fill="url(#cladoLogoBg)"/>' +
|
|
319
|
-
'<rect x="4.5" y="4.5" width="55" height="55" rx="15.5" stroke="rgba(255,255,255,0.14)"/>' +
|
|
320
|
-
'<path d="M40.5 23.2C38.6 20.6 35.6 19 32.1 19C25.5 19 20.5 24.4 20.5 32C20.5 39.6 25.5 45 32.1 45C35.7 45 38.7 43.3 40.6 40.6" stroke="#ffffff" stroke-width="5.2" stroke-linecap="round"/>' +
|
|
321
|
-
'<circle cx="43.5" cy="32" r="3" fill="#60a5fa"/>' +
|
|
322
|
-
'<rect x="12" y="57.2" width="40" height="2.4" rx="1.2" fill="url(#cladoLogoAura)"/>' +
|
|
323
|
-
'</svg>';
|
|
324
|
-
brand.innerHTML = `
|
|
325
|
-
<button type="button" class="clado-ui-glass clado-ui-button clado-brand" aria-label="Clado 设置" aria-expanded="false" aria-controls="clado-brand-settings" title="Clado 设置">
|
|
326
|
-
<span class="clado-brand-mark" aria-hidden="true">${brandLogo}</span><strong>clado</strong>
|
|
327
|
-
</button>
|
|
328
|
-
<div class="clado-ui-glass clado-ui-glass-panel clado-brand-settings" id="clado-brand-settings" role="group" aria-labelledby="clado-brand-settings-title" hidden>
|
|
329
|
-
<p id="clado-brand-settings-title">设置</p>
|
|
330
|
-
</div>`;
|
|
331
|
-
const trigger = brand.querySelector('.clado-brand');
|
|
332
|
-
const panel = brand.querySelector('.clado-brand-settings');
|
|
333
|
-
function setOpen(open, returnFocus = false) {
|
|
334
|
-
panel.hidden = !open;
|
|
335
|
-
trigger.setAttribute('aria-expanded', String(open));
|
|
336
|
-
if (returnFocus) trigger.focus();
|
|
337
|
-
}
|
|
338
|
-
const choices = themes.map(([theme, label, shape]) => {
|
|
339
|
-
const choice = document.createElement('button');
|
|
340
|
-
choice.type = 'button';
|
|
341
|
-
choice.className = 'clado-ui-button clado-brand-choice';
|
|
342
|
-
choice.innerHTML = icon(shape) + '<span>' + label + '</span>' +
|
|
343
|
-
'<span class="clado-brand-check">' + icon('<path d="m5 12 4 4L19 6"/>') + '</span>';
|
|
344
|
-
choice.onclick = () => { setTheme(theme); setOpen(false, true); };
|
|
345
|
-
panel.append(choice);
|
|
346
|
-
return { theme, choice };
|
|
347
|
-
});
|
|
348
|
-
if (openWorkspacePicker) {
|
|
349
|
-
const wsBtn = document.createElement('button');
|
|
350
|
-
wsBtn.type = 'button';
|
|
351
|
-
wsBtn.className = 'clado-ui-button clado-brand-choice clado-brand-capture';
|
|
352
|
-
wsBtn.dataset.openWorkspacePicker = 'true';
|
|
353
|
-
wsBtn.innerHTML = icon('<path d="M4 7a2 2 0 0 1 2-2h4l2 2h6a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2Z"/>') + '<span>切换工作区…</span>';
|
|
354
|
-
wsBtn.onclick = () => {
|
|
355
|
-
setOpen(false);
|
|
356
|
-
openWorkspacePicker();
|
|
357
|
-
};
|
|
358
|
-
panel.append(wsBtn);
|
|
359
|
-
}
|
|
360
|
-
if (capture) {
|
|
361
|
-
const action = document.createElement('button');
|
|
362
|
-
action.type = 'button';
|
|
363
|
-
action.className = 'clado-ui-button clado-brand-choice clado-brand-capture';
|
|
364
|
-
action.innerHTML = icon(camera) + '<span>截取当前画布</span>';
|
|
365
|
-
action.onclick = async () => {
|
|
366
|
-
setOpen(false, true);
|
|
367
|
-
action.disabled = true;
|
|
368
|
-
action.querySelector('span').textContent = '正在截图…';
|
|
369
|
-
try { await capture(); }
|
|
370
|
-
finally {
|
|
371
|
-
action.disabled = false;
|
|
372
|
-
action.querySelector('span').textContent = '截取当前画布';
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
panel.append(action);
|
|
376
|
-
}
|
|
377
|
-
const marketCtrl = mountPluginMarket(market);
|
|
378
|
-
if (marketCtrl) {
|
|
379
|
-
const marketBtn = document.createElement('button');
|
|
380
|
-
marketBtn.type = 'button';
|
|
381
|
-
marketBtn.className = 'clado-ui-button clado-brand-choice clado-brand-capture';
|
|
382
|
-
marketBtn.dataset.openMarket = 'true';
|
|
383
|
-
marketBtn.innerHTML = icon('<path d="M4 9h16l-1.5 10.5a2 2 0 0 1-2 1.5H7.5a2 2 0 0 1-2-1.5L4 9Zm2-5h12l2 5H4l2-5Z"/>') + '<span>插件市场</span>';
|
|
384
|
-
marketBtn.onclick = () => {
|
|
385
|
-
setOpen(false);
|
|
386
|
-
marketCtrl.open();
|
|
387
|
-
};
|
|
388
|
-
panel.append(marketBtn);
|
|
389
|
-
}
|
|
390
|
-
if (plugins) {
|
|
391
|
-
const action = document.createElement('button');
|
|
392
|
-
action.type = 'button';
|
|
393
|
-
action.className = 'clado-ui-button clado-brand-choice clado-brand-capture';
|
|
394
|
-
action.innerHTML = icon('<rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/>') + '<span>插件管理</span>';
|
|
395
|
-
const dialog = document.createElement('dialog');
|
|
396
|
-
dialog.className = 'clado-ui-dialog clado-plugin-manager';
|
|
397
|
-
dialog.setAttribute('aria-labelledby', 'clado-plugin-manager-title');
|
|
398
|
-
dialog.innerHTML = `
|
|
399
|
-
<header><h2 id="clado-plugin-manager-title">插件管理</h2><div class="clado-plugin-manager-actions">
|
|
400
|
-
<button type="button" class="clado-ui-button clado-plugin-install-trigger" data-install-trigger>安装插件</button>
|
|
401
|
-
<button type="button" class="clado-ui-button" aria-label="关闭插件管理">×</button>
|
|
402
|
-
</div></header>
|
|
403
|
-
<input type="file" webkitdirectory multiple hidden aria-label="选择本地插件文件夹">
|
|
404
|
-
<section class="clado-plugin-install" hidden><p role="status"></p><div class="clado-plugin-manager-actions">
|
|
405
|
-
<button type="button" class="clado-ui-button" data-install-cancel>取消</button>
|
|
406
|
-
<button type="button" class="clado-ui-button clado-plugin-install-trigger" data-install-confirm>确认安装</button>
|
|
407
|
-
</div></section>
|
|
408
|
-
<div class="clado-plugin-manager-list"></div>
|
|
409
|
-
<footer><span role="status"></span><button type="button" class="clado-ui-button clado-ui-button-primary" disabled>应用并刷新</button></footer>`;
|
|
410
|
-
const list = dialog.querySelector('.clado-plugin-manager-list');
|
|
411
|
-
const apply = dialog.querySelector('footer button');
|
|
412
|
-
const status = dialog.querySelector('footer [role="status"]');
|
|
413
|
-
const clearInstaller = mountInstaller(dialog, plugins);
|
|
414
|
-
const editSettings = plugins.edit && settingsEditor(brand, plugins.edit);
|
|
415
|
-
const controls = plugins.items.map(plugin => {
|
|
416
|
-
const row = document.createElement('article');
|
|
417
|
-
row.innerHTML = '<span class="clado-plugin-card-icon">' + icon(pluginIcons[plugin.id] || '<path d="m12 3 8 5v8l-8 5-8-5V8z"/>') + '</span>';
|
|
418
|
-
const name = document.createElement('strong');
|
|
419
|
-
name.textContent = plugin.name;
|
|
420
|
-
const toggle = document.createElement('input');
|
|
421
|
-
toggle.type = 'checkbox';
|
|
422
|
-
toggle.setAttribute('role', 'switch');
|
|
423
|
-
toggle.setAttribute('aria-label', plugin.name);
|
|
424
|
-
toggle.checked = plugins.isEnabled(plugin.id);
|
|
425
|
-
toggle.disabled = !!plugin.reason;
|
|
426
|
-
row.append(name);
|
|
427
|
-
if (plugin.reason || plugin.detail || plugin.version) {
|
|
428
|
-
const detail = document.createElement('small');
|
|
429
|
-
detail.textContent = plugin.reason || plugin.detail || 'v' + plugin.version;
|
|
430
|
-
row.append(detail);
|
|
431
|
-
}
|
|
432
|
-
row.append(toggle);
|
|
433
|
-
const settings = document.createElement('button');
|
|
434
|
-
settings.type = 'button';
|
|
435
|
-
settings.className = 'clado-ui-button';
|
|
436
|
-
settings.textContent = '设置';
|
|
437
|
-
settings.setAttribute('aria-label', plugin.name + '配置');
|
|
438
|
-
settings.disabled = !editSettings || !!plugin.pending;
|
|
439
|
-
if (settings.disabled) settings.title = '插件启用后可编辑配置';
|
|
440
|
-
settings.onclick = () => editSettings(plugin);
|
|
441
|
-
row.append(settings);
|
|
442
|
-
list.append(row);
|
|
443
|
-
return { plugin, toggle };
|
|
444
|
-
});
|
|
445
|
-
list.onchange = () => {
|
|
446
|
-
apply.disabled = controls.every(({ plugin, toggle }) => toggle.checked === plugins.isEnabled(plugin.id));
|
|
447
|
-
status.textContent = apply.disabled ? '' : '刷新会结束当前对话';
|
|
448
|
-
};
|
|
449
|
-
apply.onclick = () => {
|
|
450
|
-
try { plugins.save(controls.filter(({ toggle }) => !toggle.checked && !toggle.disabled).map(({ plugin }) => plugin.id)); }
|
|
451
|
-
catch { status.textContent = '保存失败,请检查浏览器的本地存储设置。'; }
|
|
452
|
-
};
|
|
453
|
-
dialog.querySelector('[aria-label="关闭插件管理"]').onclick = () => dialog.close();
|
|
454
|
-
dialog.onclose = () => { clearInstaller(); trigger.focus(); };
|
|
455
|
-
action.onclick = () => {
|
|
456
|
-
for (const { plugin, toggle } of controls) toggle.checked = plugins.isEnabled(plugin.id);
|
|
457
|
-
apply.disabled = true;
|
|
458
|
-
status.textContent = '';
|
|
459
|
-
setOpen(false);
|
|
460
|
-
dialog.showModal();
|
|
461
|
-
};
|
|
462
|
-
brand.append(dialog);
|
|
463
|
-
panel.append(action);
|
|
464
|
-
}
|
|
465
|
-
trigger.onclick = () => setOpen(panel.hidden);
|
|
466
|
-
document.addEventListener('pointerdown', event => {
|
|
467
|
-
if (!panel.hidden && !brand.contains(event.target)) setOpen(false);
|
|
468
|
-
});
|
|
469
|
-
document.addEventListener('keydown', event => {
|
|
470
|
-
if (event.key === 'Escape' && !panel.hidden) setOpen(false, true);
|
|
471
|
-
});
|
|
472
|
-
host.mount('top-left', brand, 'clado.brand');
|
|
473
92
|
return {
|
|
474
|
-
sync
|
|
475
|
-
|
|
476
|
-
},
|
|
477
|
-
close: () => { setOpen(false); marketCtrl?.close(); },
|
|
93
|
+
sync,
|
|
94
|
+
setWorkspaceName(name) { title.textContent = name || 'clado'; },
|
|
95
|
+
close() {},
|
|
478
96
|
};
|
|
479
97
|
}
|
|
480
98
|
|