-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrototype.html
More file actions
390 lines (341 loc) · 18.1 KB
/
Prototype.html
File metadata and controls
390 lines (341 loc) · 18.1 KB
1
2
3
4
5
6
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!DOCTYPE html>
<html lang="zh-CN" class="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GenUI - 文档日志流</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/@phosphor-icons/web"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
fontFamily: { sans: ['Inter', 'sans-serif'], mono: ['JetBrains Mono', 'monospace'] },
colors: {
bg: { canvas: 'var(--bg-canvas)', sidebar: 'var(--bg-sidebar)', card: 'var(--bg-card)' },
border: 'var(--border-color)',
accent: 'var(--col-accent)',
},
animation: {
'fade-in': 'fadeIn 0.3s ease-out forwards',
'slide-down': 'slideDown 0.3s ease-out forwards',
},
keyframes: {
fadeIn: { '0%': { opacity: '0' }, '100%': { opacity: '1' } },
slideDown: { '0%': { opacity: '0', transform: 'translateY(-10px)' }, '100%': { opacity: '1', transform: 'translateY(0)' } }
}
}
}
}
</script>
<style>
:root {
/* Light: 极简文档风 */
--bg-canvas: #f3f4f6;
--bg-sidebar: #ffffff;
--bg-card: #ffffff;
--border-color: #e5e7eb;
--col-accent: #3b82f6; /* Blue-500 */
}
.dark {
/* Dark: 深色编辑器风 */
--bg-canvas: #09090b;
--bg-sidebar: #18181b;
--bg-card: #27272a;
--border-color: #3f3f46;
--col-accent: #60a5fa; /* Blue-400 */
}
/* 侧边栏宽度过渡 */
#right-sidebar { transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
/* --- 核心:折叠动画 --- */
.accordion-content {
transition: max-height 0.4s ease-in-out, opacity 0.3s ease-in-out;
max-height: 1000px; /* 展开状态 */
opacity: 1;
overflow: hidden;
}
.accordion-content.collapsed {
max-height: 0;
opacity: 0;
}
/* 树状连接线 */
.tree-line {
position: absolute; left: 15px; top: 24px; bottom: 0; width: 1px;
background-color: var(--border-color);
z-index: 0;
}
/* 最后一个节点不显示延长线 */
.step-node:last-child .tree-line { display: none; }
</style>
</head>
<body class="bg-bg-canvas text-slate-700 dark:text-slate-300 font-sans h-screen w-screen overflow-hidden flex transition-colors duration-200">
<!-- 主画布 -->
<div class="flex-1 relative flex flex-col h-full overflow-hidden min-w-0">
<!-- 装饰背景 -->
<div class="absolute inset-0 opacity-[0.03] pointer-events-none bg-[url('https://grainy-gradients.vercel.app/noise.svg')]"></div>
<header class="absolute top-0 left-0 right-0 p-6 flex justify-between items-center z-10 pointer-events-none">
<div class="pointer-events-auto font-bold text-lg tracking-tight flex items-center gap-2">
<div class="w-6 h-6 bg-accent rounded-md"></div>
GenUI <span class="font-normal text-slate-400">Docs</span>
</div>
<button onclick="toggleSidebar()" class="pointer-events-auto p-2 rounded-md hover:bg-black/5 dark:hover:bg-white/10 transition">
<i class="ph ph-sidebar-simple text-xl"></i>
</button>
</header>
<main id="canvas-area" class="flex-1 overflow-y-auto z-0 p-8 pt-24 pb-40 scroll-smooth">
<div id="dynamic-grid" class="max-w-5xl mx-auto grid grid-cols-1 md:grid-cols-2 lg:grid-cols-12 gap-6 auto-rows-min">
<!-- Welcome -->
<div id="welcome-state" class="col-span-12 h-[50vh] flex flex-col items-center justify-center text-center space-y-4">
<div class="text-4xl font-semibold text-slate-900 dark:text-white">How can I help you?</div>
<div class="text-slate-500 max-w-md">I will document my thought process in the sidebar as I build your UI.</div>
</div>
</div>
</main>
<!-- 输入框 -->
<div class="absolute bottom-10 left-0 right-0 flex justify-center z-50 px-6">
<div class="w-full max-w-2xl bg-bg-card border border-border-color shadow-xl rounded-xl flex items-center p-2 focus-within:ring-2 focus-within:ring-accent/20 transition-all">
<input id="user-input" type="text" placeholder="Describe a task..." class="flex-1 bg-transparent border-none focus:ring-0 px-4 py-3 text-sm" onkeydown="if(event.key==='Enter') handleSend()">
<button onclick="handleSend()" class="p-2 bg-slate-100 dark:bg-slate-700 rounded-lg hover:bg-accent hover:text-white transition">
<i class="ph ph-arrow-right font-bold"></i>
</button>
</div>
</div>
</div>
<!-- 右侧侧边栏:文档日志流 -->
<aside id="right-sidebar" class="w-[420px] bg-bg-sidebar border-l border-border-color z-30 flex flex-col relative shadow-2xl">
<div class="h-14 flex items-center justify-between px-5 border-b border-border-color bg-bg-sidebar z-20">
<span class="text-sm font-semibold">Agent Activity Log</span>
<button onclick="toggleTheme()"><i id="theme-icon" class="ph ph-moon text-lg text-slate-400"></i></button>
</div>
<div id="workflow-container" class="flex-1 overflow-y-auto p-4 space-y-4 pb-10">
<!-- 任务卡片将在这里插入 -->
<div class="text-center mt-10 text-xs text-slate-400 italic">No active tasks.</div>
</div>
</aside>
<script>
// --- 核心类:DocumentTask (文档流任务) ---
class DocumentTask {
constructor(containerId, title) {
this.container = document.getElementById(containerId);
this.id = 'task-' + Date.now();
this.isExpanded = true;
// 1. 创建任务容器 (Card)
this.element = document.createElement('div');
this.element.className = "bg-bg-card border border-border-color rounded-lg shadow-sm overflow-hidden transition-all duration-300";
// 2. 结构:Header (摘要) + Body (详情)
this.element.innerHTML = `
<!-- Header: 点击可折叠/展开 -->
<div class="flex items-center justify-between p-4 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-800/50 transition border-b border-transparent" onclick="toggleTask('${this.id}')" id="${this.id}-header">
<div class="flex items-center gap-3">
<!-- 状态图标 -->
<div class="status-icon w-6 h-6 rounded-md bg-blue-50 dark:bg-blue-900/20 flex items-center justify-center text-accent">
<i class="ph ph-spinner animate-spin"></i>
</div>
<div>
<div class="text-sm font-semibold text-slate-800 dark:text-slate-100 leading-none mb-1">${title}</div>
<div class="text-[10px] text-slate-400 font-mono" id="${this.id}-meta">Processing...</div>
</div>
</div>
<i class="chevron ph ph-caret-down text-slate-400 transition-transform duration-300"></i>
</div>
<!-- Body: 包含步骤树和详细日志 -->
<div id="${this.id}-body" class="accordion-content bg-slate-50/50 dark:bg-black/20 border-t border-border-color">
<div class="p-4 pt-2 space-y-0" id="${this.id}-steps">
<!-- 步骤节点插入位置 -->
</div>
</div>
`;
// 清除空状态提示
if(this.container.innerText.includes('No active tasks')) this.container.innerHTML = '';
this.container.appendChild(this.element);
// 缓存 DOM
this.stepContainer = this.element.querySelector(`#${this.id}-steps`);
this.metaText = this.element.querySelector(`#${this.id}-meta`);
this.statusIcon = this.element.querySelector('.status-icon');
this.header = this.element.querySelector(`#${this.id}-header`);
this.body = this.element.querySelector(`#${this.id}-body`);
this.chevron = this.element.querySelector('.chevron');
this.scrollToBottom();
}
// 添加一个步骤节点 (Step Node)
addStep(name) {
const step = document.createElement('div');
step.className = "step-node relative pl-8 pb-6 animate-slide-down";
// 结构:连接线 + 图标 + 标题 + 日志容器
step.innerHTML = `
<!-- 垂直连接线 -->
<div class="tree-line"></div>
<!-- 步骤图标 (小圆点) -->
<div class="absolute left-[11px] top-1 w-2.5 h-2.5 rounded-full bg-white dark:bg-slate-800 border-2 border-slate-300 dark:border-slate-600 z-10 transition-colors duration-300 step-dot"></div>
<!-- 步骤内容 -->
<div>
<div class="text-xs font-medium text-slate-700 dark:text-slate-200 mb-2 flex items-center gap-2">
${name}
<span class="text-[9px] px-1.5 py-0.5 rounded bg-slate-200 dark:bg-slate-700 text-slate-500">RUNNING</span>
</div>
<!-- 详细日志区 (Code block style) -->
<div class="log-container font-mono text-[10px] text-slate-500 dark:text-slate-400 bg-white dark:bg-slate-900 border border-border-color rounded p-2.5 space-y-1.5 shadow-sm">
<!-- 日志行 -->
</div>
</div>
`;
// 激活当前步骤小圆点
const dot = step.querySelector('.step-dot');
dot.style.borderColor = 'var(--col-accent)';
dot.classList.add('animate-pulse');
this.stepContainer.appendChild(step);
return { element: step, logBox: step.querySelector('.log-container'), dot: dot };
}
// 向某个步骤添加日志
addLogToStep(stepObj, text) {
const line = document.createElement('div');
line.className = "flex gap-2 opacity-0 animate-fade-in";
line.innerHTML = `<span class="text-slate-300 select-none">$</span> <span>${text}</span>`;
stepObj.logBox.appendChild(line);
// 保持容器滚动
this.scrollToBottom();
}
// 完成一个步骤
finishStep(stepObj) {
stepObj.dot.classList.remove('animate-pulse');
stepObj.dot.style.backgroundColor = 'var(--col-accent)'; // 实心
stepObj.dot.style.borderColor = 'var(--col-accent)';
const badge = stepObj.element.querySelector('span');
badge.className = "text-[9px] px-1.5 py-0.5 rounded bg-green-100 dark:bg-green-900/30 text-green-600 dark:text-green-400";
badge.innerText = "DONE";
}
// 完成整个任务 -> 折叠
complete() {
// 1. 更新 Header 状态
this.statusIcon.className = "status-icon w-6 h-6 rounded-md bg-green-500 flex items-center justify-center text-white shadow-sm";
this.statusIcon.innerHTML = `<i class="ph ph-check font-bold"></i>`;
this.metaText.innerText = "Completed successfully";
this.metaText.classList.add('text-green-600');
// 2. 自动折叠
setTimeout(() => {
this.collapse();
}, 800);
}
collapse() {
this.body.classList.add('collapsed');
this.chevron.style.transform = 'rotate(-90deg)';
this.header.classList.add('border-transparent'); // 移除分割线
this.isExpanded = false;
}
expand() {
this.body.classList.remove('collapsed');
this.chevron.style.transform = 'rotate(0deg)';
this.header.classList.remove('border-transparent');
this.header.classList.add('border-border-color');
this.isExpanded = true;
}
toggle() {
this.isExpanded ? this.collapse() : this.expand();
}
scrollToBottom() {
// 滚动整个侧边栏容器
this.container.scrollTop = this.container.scrollHeight;
}
}
// 全局 Toggle 挂载
window.activeTaskMap = {};
// 实际上我们可以直接在onclick里用DOM查找,或者存实例。
// 为了简单,这里用DOM查找
window.toggleTask = function(id) {
const body = document.getElementById(id + '-body');
const chevron = document.getElementById(id + '-header').querySelector('.chevron');
if (body.classList.contains('collapsed')) {
body.classList.remove('collapsed');
chevron.style.transform = 'rotate(0deg)';
} else {
body.classList.add('collapsed');
chevron.style.transform = 'rotate(-90deg)';
}
}
// --- Workflow Simulation ---
const delay = (ms) => new Promise(res => setTimeout(res, ms));
async function handleSend() {
const input = document.getElementById('user-input');
const val = input.value.trim();
if(!val) return;
input.value = '';
const sb = document.getElementById('right-sidebar');
if (sb.classList.contains('w-0')) toggleSidebar();
document.getElementById('welcome-state').style.display = 'none';
document.getElementById('workflow-container').innerHTML = ''; // 清空旧的
// 定义任务
const tasks = [
{
title: "Analyze Requirements",
steps: [
{ name: "Intent Classification", logs: ["Reading input...", "Detected intent: 'Create Dashboard'", "Confidence: 0.99"] },
{ name: "Parameter Extraction", logs: ["Theme: Dark", "Components: [Chart, Table]", "Data: Mock"] }
]
},
{
title: "Generate Components",
steps: [
{ name: "Scaffold Structure", logs: ["Creating grid layout...", "Injecting Tailwind classes...", "Done."] },
{ name: "Fill Content", logs: ["Generating mock data...", "Binding events...", "Render complete."] }
]
}
];
for (const tData of tasks) {
// 1. 创建任务 (Card)
const task = new DocumentTask('workflow-container', tData.title);
await delay(300);
// 2. 遍历步骤
for (const sData of tData.steps) {
// 添加步骤节点
const stepObj = task.addStep(sData.name);
await delay(400);
// 实时输出日志
for (const log of sData.logs) {
task.addLogToStep(stepObj, log);
await delay(200 + Math.random() * 300);
}
// 完成步骤
task.finishStep(stepObj);
await delay(200);
}
// 3. 完成任务 -> 折叠
task.complete();
await delay(500);
}
renderUI();
}
function renderUI() {
const grid = document.getElementById('dynamic-grid');
const el = document.createElement('div');
el.className = "col-span-12 animate-fade-in";
el.innerHTML = `
<div class="bg-bg-card border border-border-color rounded-lg p-8 shadow-lg">
<h2 class="text-2xl font-bold mb-4">Dashboard Generated</h2>
<div class="grid grid-cols-3 gap-4">
<div class="h-32 bg-slate-100 dark:bg-slate-800 rounded animate-pulse"></div>
<div class="h-32 bg-slate-100 dark:bg-slate-800 rounded animate-pulse"></div>
<div class="h-32 bg-slate-100 dark:bg-slate-800 rounded animate-pulse"></div>
</div>
</div>
`;
grid.appendChild(el);
document.getElementById('canvas-area').scrollTo({top: 10000, behavior:'smooth'});
}
function toggleSidebar() {
const sb = document.getElementById('right-sidebar');
if (sb.classList.contains('w-[420px]')) {
sb.classList.replace('w-[420px]', 'w-0');
sb.classList.remove('border-l');
} else {
sb.classList.replace('w-0', 'w-[420px]');
sb.classList.add('border-l');
}
}
function toggleTheme() {
document.documentElement.classList.toggle('dark');
}
</script>
</body>
</html>