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
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>CodeStream | AI Code Generator</title>
|
| 7 |
+
<!-- Import Icons -->
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<!-- Import Fonts -->
|
| 10 |
+
<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">
|
| 11 |
+
|
| 12 |
+
<style>
|
| 13 |
+
:root {
|
| 14 |
+
--bg-dark: #0f1117;
|
| 15 |
+
--bg-panel: #161b22;
|
| 16 |
+
--bg-editor: #0d1117;
|
| 17 |
+
--accent: #2f81f7;
|
| 18 |
+
--accent-glow: rgba(47, 129, 247, 0.4);
|
| 19 |
+
--text-main: #c9d1d9;
|
| 20 |
+
--text-muted: #8b949e;
|
| 21 |
+
--border: #30363d;
|
| 22 |
+
--syntax-keyword: #ff7b72;
|
| 23 |
+
--syntax-string: #a5d6ff;
|
| 24 |
+
--syntax-function: #d2a8ff;
|
| 25 |
+
--syntax-comment: #8b949e;
|
| 26 |
+
--terminal-bg: #010409;
|
| 27 |
+
--success: #238636;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
* {
|
| 31 |
+
box-sizing: box-sizing;
|
| 32 |
+
margin: 0;
|
| 33 |
+
padding: 0;
|
| 34 |
+
scrollbar-width: thin;
|
| 35 |
+
scrollbar-color: var(--border) var(--bg-dark);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
body {
|
| 39 |
+
font-family: 'Inter', sans-serif;
|
| 40 |
+
background-color: var(--bg-dark);
|
| 41 |
+
color: var(--text-main);
|
| 42 |
+
height: 100vh;
|
| 43 |
+
overflow: hidden;
|
| 44 |
+
display: flex;
|
| 45 |
+
flex-direction: column;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
/* --- Header --- */
|
| 49 |
+
header {
|
| 50 |
+
height: 60px;
|
| 51 |
+
border-bottom: 1px solid var(--border);
|
| 52 |
+
display: flex;
|
| 53 |
+
align-items: center;
|
| 54 |
+
justify-content: space-between;
|
| 55 |
+
padding: 0 20px;
|
| 56 |
+
background: var(--bg-panel);
|
| 57 |
+
z-index: 10;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.brand {
|
| 61 |
+
display: flex;
|
| 62 |
+
align-items: center;
|
| 63 |
+
gap: 10px;
|
| 64 |
+
font-weight: 700;
|
| 65 |
+
font-size: 1.1rem;
|
| 66 |
+
letter-spacing: -0.5px;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
.brand i { color: var(--accent); }
|
| 70 |
+
|
| 71 |
+
.anycoder-link {
|
| 72 |
+
background: rgba(255, 255, 255, 0.05);
|
| 73 |
+
padding: 8px 16px;
|
| 74 |
+
border-radius: 6px;
|
| 75 |
+
text-decoration: none;
|
| 76 |
+
color: var(--text-main);
|
| 77 |
+
font-size: 0.85rem;
|
| 78 |
+
border: 1px solid var(--border);
|
| 79 |
+
transition: all 0.3s ease;
|
| 80 |
+
display: flex;
|
| 81 |
+
align-items: center;
|
| 82 |
+
gap: 8px;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.anycoder-link:hover {
|
| 86 |
+
background: var(--accent);
|
| 87 |
+
border-color: var(--accent);
|
| 88 |
+
color: white;
|
| 89 |
+
box-shadow: 0 0 15px var(--accent-glow);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/* --- Main Layout --- */
|
| 93 |
+
.workspace {
|
| 94 |
+
display: grid;
|
| 95 |
+
grid-template-columns: 250px 1fr 350px;
|
| 96 |
+
flex-grow: 1;
|
| 97 |
+
height: 100%;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/* --- Sidebar --- */
|
| 101 |
+
.sidebar {
|
| 102 |
+
border-right: 1px solid var(--border);
|
| 103 |
+
padding: 20px;
|
| 104 |
+
display: flex;
|
| 105 |
+
flex-direction: column;
|
| 106 |
+
gap: 20px;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
.file-tree-header {
|
| 110 |
+
font-size: 0.75rem;
|
| 111 |
+
text-transform: uppercase;
|
| 112 |
+
letter-spacing: 1px;
|
| 113 |
+
color: var(--text-muted);
|
| 114 |
+
margin-bottom: 10px;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
.file-item {
|
| 118 |
+
display: flex;
|
| 119 |
+
align-items: center;
|
| 120 |
+
gap: 10px;
|
| 121 |
+
padding: 8px 10px;
|
| 122 |
+
border-radius: 4px;
|
| 123 |
+
cursor: pointer;
|
| 124 |
+
color: var(--text-main);
|
| 125 |
+
font-size: 0.9rem;
|
| 126 |
+
transition: 0.2s;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
.file-item:hover { background: rgba(255,255,255, 0.05); }
|
| 130 |
+
.file-item.active { background: rgba(47, 129, 247, 0.1); color: var(--accent); }
|
| 131 |
+
.file-item i { width: 20px; text-align: center; }
|
| 132 |
+
|
| 133 |
+
/* --- Editor Area --- */
|
| 134 |
+
.editor-container {
|
| 135 |
+
position: relative;
|
| 136 |
+
background: var(--bg-editor);
|
| 137 |
+
overflow: hidden;
|
| 138 |
+
display: flex;
|
| 139 |
+
flex-direction: column;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
.editor-tabs {
|
| 143 |
+
display: flex;
|
| 144 |
+
background: var(--bg-panel);
|
| 145 |
+
border-bottom: 1px solid var(--border);
|
| 146 |
+
height: 35px;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
.tab {
|
| 150 |
+
padding: 0 15px;
|
| 151 |
+
display: flex;
|
| 152 |
+
align-items: center;
|
| 153 |
+
gap: 8px;
|
| 154 |
+
font-size: 0.8rem;
|
| 155 |
+
color: var(--text-muted);
|
| 156 |
+
border-right: 1px solid var(--border);
|
| 157 |
+
background: var(--bg-editor);
|
| 158 |
+
color: var(--text-main);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
.tab i { color: #e34c26; } /* JS color */
|
| 162 |
+
|
| 163 |
+
.toolbar {
|
| 164 |
+
padding: 10px 20px;
|
| 165 |
+
display: flex;
|
| 166 |
+
justify-content: flex-end;
|
| 167 |
+
gap: 10px;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.btn {
|
| 171 |
+
padding: 6px 12px;
|
| 172 |
+
border-radius: 4px;
|
| 173 |
+
border: 1px solid var(--border);
|
| 174 |
+
background: transparent;
|
| 175 |
+
color: var(--text-main);
|
| 176 |
+
cursor: pointer;
|
| 177 |
+
font-size: 0.8rem;
|
| 178 |
+
transition: 0.2s;
|
| 179 |
+
display: flex;
|
| 180 |
+
align-items: center;
|
| 181 |
+
gap: 6px;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.btn-primary {
|
| 185 |
+
background: var(--success);
|
| 186 |
+
border-color: var(--success);
|
| 187 |
+
color: white;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
.btn-primary:hover { opacity: 0.9; }
|
| 191 |
+
|
| 192 |
+
/* Code Editor Logic */
|
| 193 |
+
.code-area {
|
| 194 |
+
position: relative;
|
| 195 |
+
flex-grow: 1;
|
| 196 |
+
font-family: 'Fira Code', monospace;
|
| 197 |
+
font-size: 14px;
|
| 198 |
+
line-height: 1.6;
|
| 199 |
+
padding: 20px;
|
| 200 |
+
overflow: auto;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
/* The textarea is transparent and sits on top */
|
| 204 |
+
#code-input {
|
| 205 |
+
position: absolute;
|
| 206 |
+
top: 0;
|
| 207 |
+
left: 0;
|
| 208 |
+
width: 100%;
|
| 209 |
+
height: 100%;
|
| 210 |
+
padding: 20px;
|
| 211 |
+
background: transparent;
|
| 212 |
+
color: transparent; /* Text is invisible, we see the highlight layer */
|
| 213 |
+
caret-color: var(--accent);
|
| 214 |
+
border: none;
|
| 215 |
+
resize: none;
|
| 216 |
+
outline: none;
|
| 217 |
+
z-index: 2;
|
| 218 |
+
white-space: pre;
|
| 219 |
+
overflow: hidden;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
/* The highlight layer sits behind */
|
| 223 |
+
#code-highlight {
|
| 224 |
+
position: absolute;
|
| 225 |
+
top: 0;
|
| 226 |
+
left: 0;
|
| 227 |
+
width: 100%;
|
| 228 |
+
height: 100%;
|
| 229 |
+
padding: 20px;
|
| 230 |
+
pointer-events: none;
|
| 231 |
+
z-index: 1;
|
| 232 |
+
white-space: pre;
|
| 233 |
+
overflow: hidden;
|
| 234 |
+
color: var(--text-main);
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
/* Syntax Highlighting Classes */
|
| 238 |
+
.keyword { color: var(--syntax-keyword); font-weight: bold; }
|
| 239 |
+
.string { color: var(--syntax-string); }
|
| 240 |
+
.function { color: var(--syntax-function); }
|
| 241 |
+
.comment { color: var(--syntax-comment); font-style: italic; }
|
| 242 |
+
|
| 243 |
+
/* --- Terminal/Preview --- */
|
| 244 |
+
.terminal-panel {
|
| 245 |
+
background: var(--terminal-bg);
|
| 246 |
+
border-left: 1px solid var(--border);
|
| 247 |
+
display: flex;
|
| 248 |
+
flex-direction: column;
|
| 249 |
+
font-family: 'Fira Code', monospace;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
.terminal-header {
|
| 253 |
+
padding: 10px 20px;
|
| 254 |
+
border-bottom: 1px solid var(--border);
|
| 255 |
+
font-size: 0.8rem;
|
| 256 |
+
color: var(--text-muted);
|
| 257 |
+
display: flex;
|
| 258 |
+
justify-content: space-between;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
.terminal-content {
|
| 262 |
+
padding: 20px;
|
| 263 |
+
flex-grow: 1;
|
| 264 |
+
overflow-y: auto;
|
| 265 |
+
color: var(--text-main);
|
| 266 |
+
font-size: 0.85rem;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
.log-entry {
|
| 270 |
+
margin-bottom: 10px;
|
| 271 |
+
display: flex;
|
| 272 |
+
gap: 10px;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
.log-entry.error { color: var(--syntax-keyword); }
|
| 276 |
+
.log-entry.success { color: var(--success); }
|
| 277 |
+
.log-time { color: var(--text-muted); opacity: 0.5; }
|
| 278 |
+
|
| 279 |
+
.cursor-blink {
|
| 280 |
+
display: inline-block;
|
| 281 |
+
width: 8px;
|
| 282 |
+
height: 15px;
|
| 283 |
+
background: var(--accent);
|
| 284 |
+
animation: blink 1s infinite;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
@keyframes blink {
|
| 288 |
+
0%, 100% { opacity: 1; }
|
| 289 |
+
50% { opacity: 0; }
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
/* Responsive */
|
| 293 |
+
@media (max-width: 900px) {
|
| 294 |
+
.workspace {
|
| 295 |
+
grid-template-columns: 1fr;
|
| 296 |
+
grid-template-rows: auto 1fr 300px;
|
| 297 |
+
}
|
| 298 |
+
.sidebar { display: none; }
|
| 299 |
+
}
|
| 300 |
+
</style>
|
| 301 |
+
</head>
|
| 302 |
+
<body>
|
| 303 |
+
|
| 304 |
+
<header>
|
| 305 |
+
<div class="brand">
|
| 306 |
+
<i class="fa-solid fa-code"></i>
|
| 307 |
+
<span>CodeStream</span>
|
| 308 |
+
</div>
|
| 309 |
+
|
| 310 |
+
<!-- CRITICAL LINK -->
|
| 311 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" class="anycoder-link" target="_blank">
|
| 312 |
+
<i class="fa-solid fa-robot"></i> Built with anycoder
|
| 313 |
+
</a>
|
| 314 |
+
</header>
|
| 315 |
+
|
| 316 |
+
<div class="workspace">
|
| 317 |
+
<!-- Sidebar -->
|
| 318 |
+
<aside class="sidebar">
|
| 319 |
+
<div class="file-tree-header">Explorer</div>
|
| 320 |
+
<div class="file-item active">
|
| 321 |
+
<i class="fa-brands fa-js"></i> main.js
|
| 322 |
+
</div>
|
| 323 |
+
<div class="file-item">
|
| 324 |
+
<i class="fa-brands fa-css3-alt"></i> styles.css
|
| 325 |
+
</div>
|
| 326 |
+
<div class="file-item">
|
| 327 |
+
<i class="fa-brands fa-html5"></i> index.html
|
| 328 |
+
</div>
|
| 329 |
+
<div class="file-item">
|
| 330 |
+
<i class="fa-solid fa-gear"></i> config.json
|
| 331 |
+
</div>
|
| 332 |
+
</aside>
|
| 333 |
+
|
| 334 |
+
<!-- Editor -->
|
| 335 |
+
<main class="editor-container">
|
| 336 |
+
<div class="editor-tabs">
|
| 337 |
+
<div class="tab"><i class="fa-brands fa-js"></i> main.js</div>
|
| 338 |
+
</div>
|
| 339 |
+
|
| 340 |
+
<div class="toolbar">
|
| 341 |
+
<button class="btn" onclick="clearTerminal()"><i class="fa-solid fa-trash"></i> Clear</button>
|
| 342 |
+
<button class="btn btn-primary" onclick="runCode()"><i class="fa-solid fa-play"></i> Run Code</button>
|
| 343 |
+
</div>
|
| 344 |
+
|
| 345 |
+
<div class="code-area">
|
| 346 |
+
<div id="code-highlight"></div>
|
| 347 |
+
<textarea id="code-input" spellcheck="false"></textarea>
|
| 348 |
+
</div>
|
| 349 |
+
</main>
|
| 350 |
+
|
| 351 |
+
<!-- Terminal -->
|
| 352 |
+
<aside class="terminal-panel">
|
| 353 |
+
<div class="terminal-header">
|
| 354 |
+
<span>Output Console</span>
|
| 355 |
+
<i class="fa-solid fa-terminal"></i>
|
| 356 |
+
</div>
|
| 357 |
+
<div class="terminal-content" id="terminal-output">
|
| 358 |
+
<div class="log-entry">
|
| 359 |
+
<span class="log-time">System</span>
|
| 360 |
+
<span>Ready for input...</span>
|
| 361 |
+
</div>
|
| 362 |
+
</div>
|
| 363 |
+
</aside>
|
| 364 |
+
</div>
|
| 365 |
+
|
| 366 |
+
<script>
|
| 367 |
+
const textarea = document.getElementById('code-input');
|
| 368 |
+
const highlight = document.getElementById('code-highlight');
|
| 369 |
+
const terminal = document.getElementById('terminal-output');
|
| 370 |
+
|
| 371 |
+
// Sample code to simulate "AI Generation"
|
| 372 |
+
const sampleCode = `// AI Code Generation Simulation
|
| 373 |
+
// Initializing environment...
|
| 374 |
+
|
| 375 |
+
const initSystem = () => {
|
| 376 |
+
console.log("System Booting...");
|
| 377 |
+
const modules = ['Core', 'UI', 'Logic'];
|
| 378 |
+
|
| 379 |
+
modules.forEach(m => {
|
| 380 |
+
loadModule(m);
|
| 381 |
+
});
|
| 382 |
+
};
|
| 383 |
+
|
| 384 |
+
const loadModule = (name) => {
|
| 385 |
+
// Simulating async load
|
| 386 |
+
return Promise.resolve(name);
|
| 387 |
+
};
|
| 388 |
+
|
| 389 |
+
// Execute
|
| 390 |
+
initSystem();`;
|
| 391 |
+
|
| 392 |
+
// 1. Auto-Resize Textarea
|
| 393 |
+
textarea.addEventListener('input', () => {
|
| 394 |
+
textarea.style.height = 'auto';
|
| 395 |
+
textarea.style.height = textarea.scrollHeight + 'px';
|
| 396 |
+
highlightCode();
|
| 397 |
+
});
|
| 398 |
+
|
| 399 |
+
// 2. Syntax Highlighting Logic
|
| 400 |
+
function highlightCode() {
|
| 401 |
+
let text = textarea.value;
|
| 402 |
+
|
| 403 |
+
// Escape HTML
|
| 404 |
+
text = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
| 405 |
+
|
| 406 |
+
// Regex for syntax highlighting (Simple implementation)
|
| 407 |
+
// Keywords
|
| 408 |
+
text = text.replace(/\b(const|let|var|function|return|if|else|for|while|import|from)\b/g, '<span class="keyword">$1</span>');
|
| 409 |
+
// Functions
|
| 410 |
+
text = text.replace(/\b(console\.log|initSystem|loadModule|forEach|resolve)\b/g, '<span class="function">$1</span>');
|
| 411 |
+
// Strings
|
| 412 |
+
text = text.replace(/(["'])(?:(?=(\\?))\2.)*?\1/g, '<span class="string">$&</span>');
|
| 413 |
+
// Comments
|
| 414 |
+
text = text.replace(/\/\/.*$/gm, '<span class="comment">$&</span>');
|
| 415 |
+
|
| 416 |
+
highlight.innerHTML = text;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
// 3. Typing Effect (Simulate AI writing code)
|
| 420 |
+
let typeIndex = 0;
|
| 421 |
+
|
| 422 |
+
function typeCode() {
|
| 423 |
+
if (typeIndex < sampleCode.length) {
|
| 424 |
+
textarea.value += sampleCode.charAt(typeIndex);
|
| 425 |
+
textarea.style.height = 'auto';
|
| 426 |
+
textarea.style.height = textarea.scrollHeight + 'px';
|
| 427 |
+
highlightCode();
|
| 428 |
+
typeIndex++;
|
| 429 |
+
setTimeout(typeCode, 30 + Math.random() * 50); // Random typing speed
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
// 4. Terminal Logic
|
| 434 |
+
function logToTerminal(msg, type = 'normal') {
|
| 435 |
+
const entry = document.createElement('div');
|
| 436 |
+
entry.className = `log-entry ${type}`;
|
| 437 |
+
|
| 438 |
+
const time = new Date().toLocaleTimeString();
|
| 439 |
+
entry.innerHTML = `<span class="log-time">[${time}]</span> <span>${msg}</span>`;
|
| 440 |
+
|
| 441 |
+
terminal.appendChild(entry);
|
| 442 |
+
terminal.scrollTop = terminal.scrollHeight;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
function clearTerminal() {
|
| 446 |
+
terminal.innerHTML = '';
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
// 5. Run Code Logic (Simulation)
|
| 450 |
+
function runCode() {
|
| 451 |
+
logToTerminal("Compiling...", "normal");
|
| 452 |
+
|
| 453 |
+
setTimeout(() => {
|
| 454 |
+
logToTerminal("Build successful.", "success");
|
| 455 |
+
|
| 456 |
+
// Try to actually execute the JS if it's safe/simple
|
| 457 |
+
try {
|
| 458 |
+
// We use a safe wrapper to prevent breaking the UI
|
| 459 |
+
const code = textarea.value;
|
| 460 |
+
// Replace console.log to capture output
|
| 461 |
+
const wrappedCode = code.replace(/console\.log/g, 'window.mockLog');
|
| 462 |
+
|
| 463 |
+
window.mockLog = (arg) => {
|
| 464 |
+
logToTerminal(`> ${arg}`, 'success');
|
| 465 |
+
};
|
| 466 |
+
|
| 467 |
+
// Create a function from the string
|
| 468 |
+
const runFunc = new Function(wrappedCode);
|
| 469 |
+
runFunc();
|
| 470 |
+
|
| 471 |
+
logToTerminal("Process finished with exit code 0", "normal");
|
| 472 |
+
|
| 473 |
+
} catch (e) {
|
| 474 |
+
logToTerminal(`Error: ${e.message}`, "error");
|
| 475 |
+
}
|
| 476 |
+
}, 800);
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
// Initialize
|
| 480 |
+
window.onload = () => {
|
| 481 |
+
// Start typing the code automatically when page loads
|
| 482 |
+
setTimeout(typeCode, 500);
|
| 483 |
+
};
|
| 484 |
+
|
| 485 |
+
</script>
|
| 486 |
+
</body>
|
| 487 |
+
</html>
|