-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (41 loc) · 1.4 KB
/
index.js
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
import init, { Clue, getVersion } from "./pkg/clue_wasm.js";
const input = document.getElementById("input");
const output = document.getElementById("output");
const button = document.getElementById("compile-button");
const versionText = document.getElementById("version");
/**@typedef {import('./ace/src/ace.js').Ace.Document} Editor */
/**@type {Editor} */
const inputEditor = ace.edit("input");
inputEditor.setTheme("ace/theme/one_dark");
inputEditor.session.setMode("ace/mode/clue");
/**@type {Editor} */
const outputEditor = ace.edit("output");
outputEditor.setTheme("ace/theme/one_dark");
outputEditor.session.setMode("ace/mode/lua");
outputEditor.setReadOnly(true);
outputEditor.setOptions({
readOnly: true,
highlightActiveLine: false,
highlightGutterLine: false,
});
outputEditor.renderer.$cursorLayer.element.style.display = "none";
inputEditor.setShowPrintMargin(false);
outputEditor.setShowPrintMargin(false);
(async () => {
await init();
const clue = new Clue();
button.addEventListener("click", () => {
let compiled;
try {
compiled = clue.compileCode(inputEditor.getValue());
output.style.color = "#BBBBBB";
outputEditor.setValue(compiled, 1);
outputEditor.setValue;
} catch (error) {
output.style.color = "#EE5D43";
outputEditor.setValue(error, 1);
}
});
button.textContent = "Compile";
versionText.textContent = `Version: ${getVersion()}`;
})();