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.
28 lines
740 B
JavaScript
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 = '';
|
|
}
|