Spaces:
Running
Running
File size: 15,015 Bytes
d3bbabf | 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodeStream | AI Code Generator</title>
<!-- Import Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Import Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&family=Inter:wght@300;400;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-dark: #0f1117;
--bg-panel: #161b22;
--bg-editor: #0d1117;
--accent: #2f81f7;
--accent-glow: rgba(47, 129, 247, 0.4);
--text-main: #c9d1d9;
--text-muted: #8b949e;
--border: #30363d;
--syntax-keyword: #ff7b72;
--syntax-string: #a5d6ff;
--syntax-function: #d2a8ff;
--syntax-comment: #8b949e;
--terminal-bg: #010409;
--success: #238636;
}
* {
box-sizing: box-sizing;
margin: 0;
padding: 0;
scrollbar-width: thin;
scrollbar-color: var(--border) var(--bg-dark);
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--bg-dark);
color: var(--text-main);
height: 100vh;
overflow: hidden;
display: flex;
flex-direction: column;
}
/* --- Header --- */
header {
height: 60px;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20px;
background: var(--bg-panel);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
font-weight: 700;
font-size: 1.1rem;
letter-spacing: -0.5px;
}
.brand i { color: var(--accent); }
.anycoder-link {
background: rgba(255, 255, 255, 0.05);
padding: 8px 16px;
border-radius: 6px;
text-decoration: none;
color: var(--text-main);
font-size: 0.85rem;
border: 1px solid var(--border);
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 8px;
}
.anycoder-link:hover {
background: var(--accent);
border-color: var(--accent);
color: white;
box-shadow: 0 0 15px var(--accent-glow);
}
/* --- Main Layout --- */
.workspace {
display: grid;
grid-template-columns: 250px 1fr 350px;
flex-grow: 1;
height: 100%;
}
/* --- Sidebar --- */
.sidebar {
border-right: 1px solid var(--border);
padding: 20px;
display: flex;
flex-direction: column;
gap: 20px;
}
.file-tree-header {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 1px;
color: var(--text-muted);
margin-bottom: 10px;
}
.file-item {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 10px;
border-radius: 4px;
cursor: pointer;
color: var(--text-main);
font-size: 0.9rem;
transition: 0.2s;
}
.file-item:hover { background: rgba(255,255,255, 0.05); }
.file-item.active { background: rgba(47, 129, 247, 0.1); color: var(--accent); }
.file-item i { width: 20px; text-align: center; }
/* --- Editor Area --- */
.editor-container {
position: relative;
background: var(--bg-editor);
overflow: hidden;
display: flex;
flex-direction: column;
}
.editor-tabs {
display: flex;
background: var(--bg-panel);
border-bottom: 1px solid var(--border);
height: 35px;
}
.tab {
padding: 0 15px;
display: flex;
align-items: center;
gap: 8px;
font-size: 0.8rem;
color: var(--text-muted);
border-right: 1px solid var(--border);
background: var(--bg-editor);
color: var(--text-main);
}
.tab i { color: #e34c26; } /* JS color */
.toolbar {
padding: 10px 20px;
display: flex;
justify-content: flex-end;
gap: 10px;
}
.btn {
padding: 6px 12px;
border-radius: 4px;
border: 1px solid var(--border);
background: transparent;
color: var(--text-main);
cursor: pointer;
font-size: 0.8rem;
transition: 0.2s;
display: flex;
align-items: center;
gap: 6px;
}
.btn-primary {
background: var(--success);
border-color: var(--success);
color: white;
}
.btn-primary:hover { opacity: 0.9; }
/* Code Editor Logic */
.code-area {
position: relative;
flex-grow: 1;
font-family: 'Fira Code', monospace;
font-size: 14px;
line-height: 1.6;
padding: 20px;
overflow: auto;
}
/* The textarea is transparent and sits on top */
#code-input {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 20px;
background: transparent;
color: transparent; /* Text is invisible, we see the highlight layer */
caret-color: var(--accent);
border: none;
resize: none;
outline: none;
z-index: 2;
white-space: pre;
overflow: hidden;
}
/* The highlight layer sits behind */
#code-highlight {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 20px;
pointer-events: none;
z-index: 1;
white-space: pre;
overflow: hidden;
color: var(--text-main);
}
/* Syntax Highlighting Classes */
.keyword { color: var(--syntax-keyword); font-weight: bold; }
.string { color: var(--syntax-string); }
.function { color: var(--syntax-function); }
.comment { color: var(--syntax-comment); font-style: italic; }
/* --- Terminal/Preview --- */
.terminal-panel {
background: var(--terminal-bg);
border-left: 1px solid var(--border);
display: flex;
flex-direction: column;
font-family: 'Fira Code', monospace;
}
.terminal-header {
padding: 10px 20px;
border-bottom: 1px solid var(--border);
font-size: 0.8rem;
color: var(--text-muted);
display: flex;
justify-content: space-between;
}
.terminal-content {
padding: 20px;
flex-grow: 1;
overflow-y: auto;
color: var(--text-main);
font-size: 0.85rem;
}
.log-entry {
margin-bottom: 10px;
display: flex;
gap: 10px;
}
.log-entry.error { color: var(--syntax-keyword); }
.log-entry.success { color: var(--success); }
.log-time { color: var(--text-muted); opacity: 0.5; }
.cursor-blink {
display: inline-block;
width: 8px;
height: 15px;
background: var(--accent);
animation: blink 1s infinite;
}
@keyframes blink {
0%, 100% { opacity: 1; }
50% { opacity: 0; }
}
/* Responsive */
@media (max-width: 900px) {
.workspace {
grid-template-columns: 1fr;
grid-template-rows: auto 1fr 300px;
}
.sidebar { display: none; }
}
</style>
</head>
<body>
<header>
<div class="brand">
<i class="fa-solid fa-code"></i>
<span>CodeStream</span>
</div>
<!-- CRITICAL LINK -->
<a href="https://huggingface.co/spaces/akhaliq/anycoder" class="anycoder-link" target="_blank">
<i class="fa-solid fa-robot"></i> Built with anycoder
</a>
</header>
<div class="workspace">
<!-- Sidebar -->
<aside class="sidebar">
<div class="file-tree-header">Explorer</div>
<div class="file-item active">
<i class="fa-brands fa-js"></i> main.js
</div>
<div class="file-item">
<i class="fa-brands fa-css3-alt"></i> styles.css
</div>
<div class="file-item">
<i class="fa-brands fa-html5"></i> index.html
</div>
<div class="file-item">
<i class="fa-solid fa-gear"></i> config.json
</div>
</aside>
<!-- Editor -->
<main class="editor-container">
<div class="editor-tabs">
<div class="tab"><i class="fa-brands fa-js"></i> main.js</div>
</div>
<div class="toolbar">
<button class="btn" onclick="clearTerminal()"><i class="fa-solid fa-trash"></i> Clear</button>
<button class="btn btn-primary" onclick="runCode()"><i class="fa-solid fa-play"></i> Run Code</button>
</div>
<div class="code-area">
<div id="code-highlight"></div>
<textarea id="code-input" spellcheck="false"></textarea>
</div>
</main>
<!-- Terminal -->
<aside class="terminal-panel">
<div class="terminal-header">
<span>Output Console</span>
<i class="fa-solid fa-terminal"></i>
</div>
<div class="terminal-content" id="terminal-output">
<div class="log-entry">
<span class="log-time">System</span>
<span>Ready for input...</span>
</div>
</div>
</aside>
</div>
<script>
const textarea = document.getElementById('code-input');
const highlight = document.getElementById('code-highlight');
const terminal = document.getElementById('terminal-output');
// Sample code to simulate "AI Generation"
const sampleCode = `// AI Code Generation Simulation
// Initializing environment...
const initSystem = () => {
console.log("System Booting...");
const modules = ['Core', 'UI', 'Logic'];
modules.forEach(m => {
loadModule(m);
});
};
const loadModule = (name) => {
// Simulating async load
return Promise.resolve(name);
};
// Execute
initSystem();`;
// 1. Auto-Resize Textarea
textarea.addEventListener('input', () => {
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
highlightCode();
});
// 2. Syntax Highlighting Logic
function highlightCode() {
let text = textarea.value;
// Escape HTML
text = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
// Regex for syntax highlighting (Simple implementation)
// Keywords
text = text.replace(/\b(const|let|var|function|return|if|else|for|while|import|from)\b/g, '<span class="keyword">$1</span>');
// Functions
text = text.replace(/\b(console\.log|initSystem|loadModule|forEach|resolve)\b/g, '<span class="function">$1</span>');
// Strings
text = text.replace(/(["'])(?:(?=(\\?))\2.)*?\1/g, '<span class="string">$&</span>');
// Comments
text = text.replace(/\/\/.*$/gm, '<span class="comment">$&</span>');
highlight.innerHTML = text;
}
// 3. Typing Effect (Simulate AI writing code)
let typeIndex = 0;
function typeCode() {
if (typeIndex < sampleCode.length) {
textarea.value += sampleCode.charAt(typeIndex);
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
highlightCode();
typeIndex++;
setTimeout(typeCode, 30 + Math.random() * 50); // Random typing speed
}
}
// 4. Terminal Logic
function logToTerminal(msg, type = 'normal') {
const entry = document.createElement('div');
entry.className = `log-entry ${type}`;
const time = new Date().toLocaleTimeString();
entry.innerHTML = `<span class="log-time">[${time}]</span> <span>${msg}</span>`;
terminal.appendChild(entry);
terminal.scrollTop = terminal.scrollHeight;
}
function clearTerminal() {
terminal.innerHTML = '';
}
// 5. Run Code Logic (Simulation)
function runCode() {
logToTerminal("Compiling...", "normal");
setTimeout(() => {
logToTerminal("Build successful.", "success");
// Try to actually execute the JS if it's safe/simple
try {
// We use a safe wrapper to prevent breaking the UI
const code = textarea.value;
// Replace console.log to capture output
const wrappedCode = code.replace(/console\.log/g, 'window.mockLog');
window.mockLog = (arg) => {
logToTerminal(`> ${arg}`, 'success');
};
// Create a function from the string
const runFunc = new Function(wrappedCode);
runFunc();
logToTerminal("Process finished with exit code 0", "normal");
} catch (e) {
logToTerminal(`Error: ${e.message}`, "error");
}
}, 800);
}
// Initialize
window.onload = () => {
// Start typing the code automatically when page loads
setTimeout(typeCode, 500);
};
</script>
</body>
</html> |