-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
672 lines (624 loc) · 23.9 KB
/
Copy pathindex.html
File metadata and controls
672 lines (624 loc) · 23.9 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
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Code Editor</title>
<!-- Tailwind CSS v2.2.19 CDN -->
<link
href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"
rel="stylesheet"
/>
<!-- Material Icons -->
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
/>
<link rel="icon" type="image/svg+xml" href="assets\codash.svg" />
<!-- Anime.js CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
<!-- ACE Editor CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.14/ace.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.14/ext-language_tools.min.js"></script>
<!-- js-beautify CDN -->
<script src="https://cdn.jsdelivr.net/npm/js-beautify@1.14.7/js/lib/beautify.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-beautify@1.14.7/js/lib/beautify-css.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-beautify@1.14.7/js/lib/beautify-html.js"></script>
<style>
body {
font-family: "Inter", sans-serif;
}
/* Smooth resizing transitions (applied after drag) */
.editor-pane,
#editor-area,
#preview {
transition: width 0.2s ease, height 0.2s ease;
}
:root {
--resize-bar-thickness: 20px;
}
.resize-handle-x {
cursor: col-resize;
flex: 0 0 var(--resize-bar-thickness) !important;
width: var(--resize-bar-thickness) !important;
background-color: #1c1c1c;
height: 100%;
margin: 0;
padding: 0;
border: none;
box-shadow: none;
}
.resize-handle-y {
cursor: row-resize;
flex: 0 0 var(--resize-bar-thickness) !important;
height: var(--resize-bar-thickness) !important;
background-color: #1c1c1c;
width: 100%;
margin: 0;
padding: 0;
border: none;
box-shadow: none;
}
.editor-pane {
background-color: #262626;
}
.editor-header {
background-color: #1c1c1c !important; /* Background for header */
color: #ffffff8e !important; /* Text color for header */
border-bottom: 1px solid #444444; /* Optional: change border color */
}
/* Hide native scrollbars */
body::-webkit-scrollbar {
display: none;
}
body {
-ms-overflow-style: none;
scrollbar-width: none;
}
/* Remove white lines on the code panes */
.editor-pane,
#html-editor-container,
#css-editor-container,
#js-editor-container {
margin: 0 !important;
padding: 0 !important;
border: none !important;
background-clip: padding-box; /* Prevent background bleeding */
}
/* Also ensure the ACE editor container has no extra space */
.ace_editor {
border: none !important;
box-shadow: none !important;
}
.ace_gutter {
background: #1d1e22 !important; /* gutter background */
color: #34363e !important; /* line number color */
}
.editor-header,
.editor-header:focus {
outline: none !important;
box-shadow: none !important;
}
/* Remove any outline, shadow, or border from the editor header and its children */
.editor-header,
.editor-header:focus,
.editor-header *:focus,
.editor-header:active,
.editor-header *:active {
outline: none !important;
box-shadow: none !important;
border: none !important;
}
/* For horizontal resizer bars (code panes):
Add border on the left and right but none on top and bottom */
.resize-handle-x {
border-left: 1px solid #2d2d2d;
border-right: 1px solid #2d2d2d;
border-top: none;
border-bottom: none;
}
/* For vertical resizer bar (between editors and preview):
Add border on the top and bottom but none on left and right */
.resize-handle-y {
border-top: 1px solid #2d2d2d;
border-bottom: 1px solid #2d2d2d;
border-left: none;
border-right: none;
}
/* Animate the pencil icon on hover */
#editIcon:hover {
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% {
opacity: 1;
transform: scale(1);
}
50% {
opacity: 0.7;
transform: scale(1.1);
}
100% {
opacity: 1;
transform: scale(1);
}
}
/* For Webkit-based browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
width: 12px;
}
/* Track */
::-webkit-scrollbar-track {
background: #1d1e22;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #666b7a;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #666b7a;
}
/* Make the Ace Editor caret longer and thinner */
.ace_editor .ace_cursor {
width: 0.5px !important; /* Thinner width */
height: 1.65em !important; /* Longer height; adjust value as needed */
}
[contenteditable]:focus {
outline: none !important;
box-shadow: none !important;
}
@keyframes vsCodeCursor {
0%,
100% {
transform: scaleY(0.9);
}
50% {
transform: scaleY(0);
}
}
/* Only animate the cursor in the active (focused) Ace editor */
.ace_editor.ace_focus .ace_cursor {
animation: vsCodeCursor 1s infinite ease-in-out !important;
}
/* Stop animation for inactive editors */
.ace_editor:not(.ace_focus) .ace_cursor {
animation: none !important;
}
</style>
</head>
<body
class="bg-gray-900 text-gray-200 flex flex-col h-screen overflow-hidden"
>
<!-- Header -->
<header
style="height: 65px"
class="bg-black text-white p-3 flex justify-between items-center border-b border-gray-700 shadow-md"
>
<div class="flex items-center">
<img
src="assets/codash.png"
alt="Codash"
class="w-16 h-50 object-contain"
/>
<div>
<!-- File name + pencil icon -->
<div class="flex items-center">
<h1 id="filename" class="text-lg font-semibold">Untitled</h1>
<span
id="editIcon"
class="material-icons cursor-pointer text-base ml-1"
>edit</span
>
</div>
<p id="captainName" class="text-xs text-gray-400">
Captain Anonymous
</p>
</div>
</div>
<div class="flex items-center space-x-2">
<button
onclick="prettifyCode()"
class="bg-green-600 hover:bg-green-500 text-white px-4 py-2 rounded-md text-sm font-medium flex items-center"
>
<span class="material-icons mr-1 text-base">done_all</span> Prettify
</button>
</div>
</header>
<!-- Main Body -->
<div class="flex flex-col flex-grow overflow-hidden">
<!-- Editors (Top 60% of body) -->
<div
id="editor-area"
class="flex flex-grow h-3/5 border-b border-gray-800"
>
<!-- HTML Editor -->
<div
class="flex-1 flex flex-col editor-pane"
id="html-editor-container"
>
<!-- HTML Editor Header -->
<div
class="editor-header relative border-b border-gray-700"
style="height: 35px"
>
<div
class="absolute inset-y-0 left-0 flex items-center px-3"
style="background-color: #1d1e22; border-top: 3px solid #34363e"
>
<svg
viewBox="0 0 15 15"
class="file-type-icon mr-2 w-5 h-4"
id="icon-file-html"
>
<rect fill="#FF3C41" width="15" height="15" rx="4"></rect>
<path
d="M10.97 2.29a.563.563 0 0 0-.495-.29.572.572 0 0 0-.488.277l-5.905 9.86a.565.565 0 0 0-.007.574c.102.18.287.289.495.289a.572.572 0 0 0 .488-.277l5.905-9.86a.565.565 0 0 0 .007-.574"
fill="#28282B"
></path>
</svg>
<span class="font-medium text-sm">HTML</span>
</div>
</div>
<!-- ACE container for HTML -->
<div id="html-editor" class="flex-grow"></div>
</div>
<div class="resize-handle-x"></div>
<!-- CSS Editor -->
<div class="flex-1 flex flex-col editor-pane" id="css-editor-container">
<!-- CSS Editor Header -->
<div
class="editor-header relative border-b border-gray-700"
style="height: 35px"
>
<div
class="absolute inset-y-0 left-0 flex items-center px-3"
style="background-color: #1d1e22; border-top: 3px solid #34363e"
>
<svg
viewBox="0 0 15 15"
class="file-type-icon mr-2 w-6 h-4"
id="icon-file-css"
>
<rect fill="#0EBEFF" width="15" height="15" rx="4"></rect>
<path
d="M8 8.366l1.845 1.065a.507.507 0 0 0 .686-.181.507.507 0 0 0-.186-.685L8.5 7.5l1.845-1.065a.507.507 0 0 0 .186-.685.507.507 0 0 0-.686-.181L8 6.634v-2.13A.507.507 0 0 0 7.5 4c-.268 0-.5.225-.5.503v2.131L5.155 5.569a.507.507 0 0 0-.686.181.507.507 0 0 0 .186.685L6.5 7.5 4.655 8.565a.507.507 0 0 0-.186.685c.134.232.445.32.686.181L7 8.366v2.13c0 .271.224.504.5.504.268 0 .5-.225.5-.503V8.366z"
fill="#282828"
></path>
</svg>
<span class="font-medium text-sm">CSS</span>
</div>
</div>
<!-- ACE container for CSS -->
<div id="css-editor" class="flex-grow"></div>
</div>
<div class="resize-handle-x"></div>
<!-- JS Editor -->
<div class="flex-1 flex flex-col editor-pane" id="js-editor-container">
<!-- JS Editor Header -->
<div
class="editor-header relative border-b border-gray-700"
style="height: 35px"
>
<div
class="absolute inset-y-0 left-0 flex items-center px-3"
style="background-color: #1d1e22; border-top: 3px solid #34363e"
>
<svg
viewBox="0 0 15 15"
class="file-type-icon mr-2 w-6 h-4"
id="icon-file-js"
>
<rect fill="#FCD000" width="15" height="15" rx="4"></rect>
<path
d="M6.554 3.705c0 .267-.19.496-.452.543-1.2.217-2.12 1.61-2.12 3.275 0 1.665.92 3.057 2.12 3.274a.554.554 0 0 1-.205 1.087c-1.733-.322-3.022-2.175-3.022-4.361 0-2.187 1.289-4.04 3.022-4.362a.554.554 0 0 1 .657.544zm1.892 0c0-.347.316-.607.657-.544 1.733.322 3.022 2.175 3.022 4.362 0 2.186-1.289 4.04-3.022 4.361a.554.554 0 0 1-.205-1.087c1.2-.217 2.12-1.61 2.12-3.274 0-1.665-.92-3.058-2.12-3.275a.551.551 0 0 1-.452-.543z"
fill="#282828"
></path>
</svg>
<span class="font-medium text-sm">JS</span>
</div>
</div>
<!-- ACE container for JS -->
<div id="js-editor" class="flex-grow"></div>
</div>
</div>
<!-- Vertical Resize Handle between Editors and Preview -->
<div class="resize-handle-y"></div>
<!-- Preview (Bottom 40% of body) -->
<iframe
id="preview"
class="flex-grow bg-white"
style="height: 356px"
sandbox="allow-scripts"
></iframe>
</div>
<!-- Footer -->
<footer
class="bg-gray-800 text-gray-400 p-2 flex items-center border-t border-gray-700 text-sm"
>
<button
id="toggleConsoleBtn"
class="px-3 py-1 rounded-md hover:bg-gray-700 hover:text-white"
>
Console
</button>
</footer>
<!-- Console Output (Hidden by default) -->
<div
id="consoleOutput"
class="bg-black text-green-400 p-3 text-xs font-mono hidden overflow-y-auto max-h-48 border-t border-gray-700"
>
<!-- Console output will appear here -->
</div>
<script>
// Initialize ACE Editors
const htmlEditor = ace.edit("html-editor");
htmlEditor.setTheme("ace/theme/twilight");
htmlEditor.session.setMode("ace/mode/html");
htmlEditor.setOptions({
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
});
htmlEditor.setOption("highlightActiveLine", false); // Disable active line highlighting
htmlEditor.renderer.setOption("highlightGutterLine", false); // Disable gutter line highlighting
htmlEditor.setFontSize(15); // Set font size
const cssEditor = ace.edit("css-editor");
cssEditor.setTheme("ace/theme/twilight");
cssEditor.session.setMode("ace/mode/css");
cssEditor.setOptions({
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
});
cssEditor.setOption("highlightActiveLine", false); // Disable active line highlighting
cssEditor.renderer.setOption("highlightGutterLine", false); // Disable gutter line highlighting
cssEditor.setFontSize(15); // Set font size
const jsEditor = ace.edit("js-editor");
jsEditor.setTheme("ace/theme/twilight");
jsEditor.session.setMode("ace/mode/javascript");
jsEditor.setOptions({
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
});
jsEditor.setOption("highlightActiveLine", false); // Disable active line highlighting
jsEditor.renderer.setOption("highlightGutterLine", false); // Disable gutter line highlighting
jsEditor.setFontSize(15); // Set font size
// Change the background color for each Ace editor container
htmlEditor.container.style.backgroundColor = "#1d1e22"; // or any valid CSS color
cssEditor.container.style.backgroundColor = "#1d1e22";
jsEditor.container.style.backgroundColor = "#1d1e22";
// Horizontal Resize of Editor Panes (with smoother final transition via CSS)
const resizeHandlesX = document.querySelectorAll(".resize-handle-x");
const minWidth = 50; // Minimum width for each pane in pixels
resizeHandlesX.forEach((handle) => {
handle.addEventListener("mousedown", (e) => {
e.preventDefault(); // Prevent default text selection
// Get bounding rectangle of the container holding the panes
const containerRect = handle.parentNode.getBoundingClientRect();
const containerLeft = containerRect.left;
const containerRight = containerRect.right;
const startX = e.clientX;
const prevSibling = handle.previousElementSibling;
const nextSibling = handle.nextElementSibling;
const startWidthPrev = prevSibling.offsetWidth;
const startWidthNext = nextSibling.offsetWidth;
function onMouseMove(e) {
let posX = e.clientX;
// Limit posX so the handle stays within the container and respects min widths
const limitedX = Math.max(
containerLeft + minWidth,
Math.min(posX, containerRight - minWidth)
);
let diffX = limitedX - startX;
prevSibling.style.flex = "none";
nextSibling.style.flex = "none";
prevSibling.style.width = startWidthPrev + diffX + "px";
nextSibling.style.width = startWidthNext - diffX + "px";
}
function onMouseUp() {
document.removeEventListener("mousemove", onMouseMove);
document.removeEventListener("mouseup", onMouseUp);
}
document.addEventListener("mousemove", onMouseMove);
document.addEventListener("mouseup", onMouseUp);
});
});
// Vertical Resize: between editor area and preview (using pointer events)
const resizeHandleY = document.querySelector(".resize-handle-y");
const editorArea = document.getElementById("editor-area");
const preview = document.getElementById("preview");
resizeHandleY.addEventListener("pointerdown", (e) => {
e.preventDefault();
// Capture pointer so that events keep firing even if the pointer moves off the element
resizeHandleY.setPointerCapture(e.pointerId);
const startY = e.clientY;
const startEditorHeight = editorArea.offsetHeight;
const startPreviewHeight = preview.offsetHeight;
function onPointerMove(e) {
const diffY = e.clientY - startY;
editorArea.style.height = startEditorHeight + diffY + "px";
preview.style.height = startPreviewHeight - diffY + "px";
}
function onPointerUp(e) {
resizeHandleY.releasePointerCapture(e.pointerId);
document.removeEventListener("pointermove", onPointerMove);
document.removeEventListener("pointerup", onPointerUp);
}
document.addEventListener("pointermove", onPointerMove);
document.addEventListener("pointerup", onPointerUp);
});
// Working Console Implementation:
// The preview iframe’s srcdoc includes a script which overrides window.console to send log/error
// messages via postMessage to the parent that appends the messages to the #consoleOutput panel.
// Flag to track if the JS editor was modified at least once
let jsEdited = false;
function updatePreview() {
const html = htmlEditor.getValue();
const css = `<style>${cssEditor.getValue()}</style>`;
let jsBlock = "";
const currentJS = jsEditor.getValue();
// Only inject the JS block after the first edit
if (jsEdited) {
jsBlock = `<script>
window.console = {
log: (...args) => parent.postMessage({ type: 'log', args }, '*'),
error: (...args) => parent.postMessage({ type: 'error', args }, '*')
};
try {
${currentJS}
} catch(e) {
parent.postMessage({ type: 'error', args: [e.toString()] }, '*');
}
<\/script>`;
}
preview.srcdoc = html + css + jsBlock;
}
// Listen for JS changes
jsEditor.on("change", () => {
// On the first change, mark that JS was edited
if (!jsEdited) {
jsEdited = true;
}
// Clear console and update preview
document.getElementById("consoleOutput").textContent = "";
updatePreview();
});
// Update preview on blur for HTML and CSS editors
htmlEditor.on("blur", updatePreview);
cssEditor.on("blur", updatePreview);
// (Optional) Call updatePreview() at init—but without JS block injected since jsEdited is false.
updatePreview();
// Listen for console messages from the preview frame.
window.addEventListener("message", (e) => {
const msg = e.data;
const consoleEl = document.getElementById("consoleOutput");
if (msg.type === "log") {
consoleEl.textContent += msg.args.join(" ") + "\n";
} else if (msg.type === "error") {
consoleEl.textContent += "Error: " + msg.args.join(" ") + "\n";
}
consoleEl.scrollTop = consoleEl.scrollHeight;
});
// Toggle Console with Anime.js animation (smooth opening/closing)
const toggleBtn = document.getElementById("toggleConsoleBtn");
const consoleEl = document.getElementById("consoleOutput");
let consoleVisible = false;
toggleBtn.addEventListener("click", () => {
if (!consoleVisible) {
consoleEl.classList.remove("hidden");
anime({
targets: "#consoleOutput",
height: ["0px", "200px"],
opacity: [0, 1],
duration: 400,
easing: "easeOutQuad",
});
} else {
anime({
targets: "#consoleOutput",
height: 0,
opacity: 0,
duration: 300,
easing: "easeInQuad",
complete: () => consoleEl.classList.add("hidden"),
});
}
consoleVisible = !consoleVisible;
});
// Prettify Code Function: formats each editor's content using js-beautify.
function prettifyCode() {
const htmlCode = htmlEditor.getValue();
const cssCode = cssEditor.getValue();
const jsCode = jsEditor.getValue();
htmlEditor.setValue(html_beautify(htmlCode), -1);
cssEditor.setValue(css_beautify(cssCode), -1);
jsEditor.setValue(js_beautify(jsCode), -1);
updatePreview();
}
document.addEventListener("DOMContentLoaded", function () {
const filename = document.getElementById("filename");
const editIcon = document.getElementById("editIcon");
// Initialize lastSaved with the current value or default "Untitled"
let lastSaved = filename.innerText.trim() || "Untitled";
// Ensure editing is off by default.
filename.setAttribute("contenteditable", "false");
editIcon.addEventListener("click", function (e) {
// Clear the text when editing is enabled.
filename.innerText = "";
filename.setAttribute("contenteditable", "true");
filename.focus();
// Hide the pencil icon
editIcon.style.display = "none";
// Ensure no border is applied
filename.style.border = "none";
});
filename.addEventListener("blur", function (e) {
let newValue = filename.innerText.trim();
// If empty, revert to lastSaved if available, else "Untitled"
if (newValue === "") {
filename.innerText = lastSaved || "Untitled";
} else {
lastSaved = newValue;
}
filename.setAttribute("contenteditable", "false");
filename.style.border = "none";
// Show the pencil icon again
editIcon.style.display = "inline";
});
});
document.addEventListener("DOMContentLoaded", function () {
const captainName = document.getElementById("captainName");
// Load saved name from localStorage, if it exists.
captainName.innerText =
localStorage.getItem("captainName") || "Captain Anonymous";
// Enable editing on double-click and clear the text immediately
captainName.addEventListener("dblclick", function () {
captainName.innerText = "";
captainName.setAttribute("contenteditable", "true");
captainName.focus();
captainName.style.border = "none";
});
// When editing is finished, save the value.
captainName.addEventListener("blur", function () {
captainName.setAttribute("contenteditable", "false");
captainName.style.border = "none";
let newName = captainName.innerText.trim();
// If empty, revert to "Captain Anonymous"
if (newName === "") {
newName = "Captain Anonymous";
captainName.innerText = newName;
}
localStorage.setItem("captainName", newName);
});
});
</script>
<style>
.editor-header,
.editor-header * {
-webkit-user-select: none !important;
-moz-user-select: none !important;
-ms-user-select: none !important;
user-select: none !important;
-webkit-touch-callout: none !important;
}
/* Prevent text selection in the code panes while resizing */
.editor-pane,
.ace_editor,
.ace_content {
-webkit-user-select: none !important;
-moz-user-select: none !important;
-ms-user-select: none !important;
user-select: none !important;
}
</style>
<style>
.editor-header > div {
pointer-events: none;
}
</style>
<style>
.ace_editor {
padding-top: 11px;
}
</style>
</body>
</html>