-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
104 lines (94 loc) · 2.56 KB
/
Copy pathindex.html
File metadata and controls
104 lines (94 loc) · 2.56 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
<!doctype html>
<html lang="en">
<head>
<title>WonderScript</title>
<style>
#main {
margin-right: 5px;
margin-left: 5px;
}
.frame {
display: flex;
align-items: start;
}
.frame > button {
margin-left: 5px;
}
#input {
font-size: 14pt;
font-family: monospace;
padding: 3px;
width: 100%;
border-radius: 4px;
border: 1px gray solid;
min-height: 400px;
}
#output {
font-size: 14pt;
margin-top: 5px;
margin-bottom: 15px;
max-width: 100%;
}
#error {
color: red;
}
</style>
</head>
<body>
<main id="main">
<div class="frame">
<div style="width: 50%">
<div id="output"></div>
<div id="error"></div>
</div>
<div style="width: 50%">
<label for="input">WonderScript Listener</label>
<textarea id="input" name="input"></textarea>
<button id="evalButton" type="button">Eval</button>
<button id="clearButton" type="button">Clear</button>
</div>
</div>
<div id="historyListing"></div>
</main>
<script type="module" src="dist/wonderscript.js"></script>
<script>
let compiler;
const historyItems = [];
function renderHistory() {
const entries = historyItems.map(
(h) => `<pre class="history-entry">${h}</pre>`
);
historyListing.innerHTML = entries.join("");
}
function clearErrorAndOutput() {
error.innerText = "";
output.innerText = "";
}
function initListener() {
evalButton.addEventListener("click", () => {
try {
historyItems.push(input.value);
clearErrorAndOutput();
const result = compiler.evalString(input.value, "listener-input");
output.innerHTML = compiler.prHTML(result);
renderHistory();
} catch (e) {
error.innerHTML = `
<strong>${e.constructor.name}</strong>:${e.message}<br>
${e.stack.replace(/\n/g, "<br>")}
`;
}
});
clearButton.addEventListener("click", clearErrorAndOutput);
}
const wsInter = setInterval(() => {
if (window.wonderscript) {
clearInterval(wsInter);
compiler = new wonderscript.Compiler("browser", this);
compiler.loadFile("src/wonderscript/core.ws");
initListener();
}
}, 500);
</script>
</body>
</html>