-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
64 lines (53 loc) · 3.11 KB
/
main.js
File metadata and controls
64 lines (53 loc) · 3.11 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
/*
* SPDX-FileCopyrightText: 2026 John Samuel <johnsamuelwrites@gmail.com>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
"use strict";
import { initTheme, initThemeToggle } from './theme.js';
import { editor, loadLang, loadExample, initLanguageKeywords, applyEditorHighlighting } from './editor.js';
import { setStatus, initTabs, initResizer, initShareFromUrl, initShareButton, initCopyButtons, initClearButton } from './ui.js';
import { initRuntimes, runCode } from './runtime.js';
import { applyI18n } from './i18n.js';
/* ── Theme ───────────────────────────────────────────────────────── */
initTheme(); // applies persisted / OS theme before editor exists
const resolvedTheme = document.documentElement.getAttribute('data-theme') || 'dark';
editor.setOption('theme', resolvedTheme === 'dark' ? 'dracula' : 'eclipse');
initThemeToggle(editor); // wires the toggle button with the editor reference
/* ── Keyboard shortcuts ──────────────────────────────────────────── */
editor.setOption('extraKeys', {
'Ctrl-Enter': runCode,
'Cmd-Enter': runCode,
});
/* ── Home link ───────────────────────────────────────────────────── */
(function configureHomeLink() {
const $homeLink = document.getElementById('home-link');
if (!$homeLink) return;
$homeLink.href = window.location.pathname.endsWith('/playground/') ? '../' : './';
})();
/* ── Language & example selectors ───────────────────────────────── */
const $lang = document.getElementById('lang-select');
const $exampleSel = document.getElementById('example-select');
const $runBtn = document.getElementById('run-btn');
$lang.addEventListener('change', () => {
const lang = $lang.value;
loadLang(lang);
applyI18n(lang);
});
$exampleSel.addEventListener('change', () => loadExample($lang.value, $exampleSel.value));
/* ── Initialise editor content, i18n, and keyword highlighting ───── */
loadLang('en');
applyI18n('en');
initLanguageKeywords().then(() => applyEditorHighlighting($lang.value));
/* ── UI subsystems ───────────────────────────────────────────────── */
document.getElementById('output-console').setAttribute('aria-live', 'polite');
initTabs();
initResizer();
initClearButton();
initCopyButtons();
initShareButton(setStatus);
initShareFromUrl();
/* ── Run button ──────────────────────────────────────────────────── */
$runBtn.addEventListener('click', runCode);
/* ── Boot runtimes ───────────────────────────────────────────────── */
initRuntimes();