Files
fiddle/public/js/console-panel.js
root 463b563423 Initial commit: code playground with multi-framework support
Express + SQLite backend with Monaco editor frontend.
Supports HTML/CSS/JS, TypeScript, React (JSX/TSX), Vue SFC,
and Svelte with live preview, console output, save/fork/share.

Includes CSS preprocessors (SCSS, Less), framework-specific
compilation (Babel, TypeScript, Svelte compiler), and
CDN-loaded runtime libraries for preview rendering.
2026-02-26 08:12:39 -06:00

28 lines
740 B
JavaScript

const output = () => document.getElementById('console-output');
export function initConsole() {
window.addEventListener('message', (e) => {
if (!e.data || e.data.type !== 'console') return;
if (e.data.method === 'clear') {
clearConsole();
return;
}
appendLine(e.data.method, (e.data.args || []).join(' '));
});
document.getElementById('btn-clear-console').addEventListener('click', clearConsole);
}
function appendLine(method, text) {
const el = document.createElement('div');
el.className = `console-line console-${method}`;
el.textContent = text;
const out = output();
out.appendChild(el);
out.scrollTop = out.scrollHeight;
}
export function clearConsole() {
output().innerHTML = '';
}