Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
428 lines (385 loc) · 11.8 KB
/
Copy pathindex.html
File metadata and controls
428 lines (385 loc) · 11.8 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WasmBasic</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@latest/tabler-icons.min.css"
/>
<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
* {
margin: 0;
}
body {
font-family: system-ui, sans-serif;
background: #f5f5f3;
}
.ide-root {
display: grid;
grid-template-columns: 220px 1fr 1fr;
height: 100vh;
}
.pane {
display: flex;
flex-direction: column;
min-height: 0;
}
.pane-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 16px;
background: #fff;
border-bottom: 0.5px solid rgba(0, 0, 0, 0.12);
flex-shrink: 0;
}
.pane-label {
font-size: 12px;
color: #888;
letter-spacing: 0.06em;
text-transform: uppercase;
font-weight: 500;
}
/* ── Examples ── */
.examples-pane {
background: white;
border-right: 0.5px solid rgba(0, 0, 0, 0.12);
}
.examples-list {
overflow-y: auto;
padding: 12px;
}
.example-card {
background: #f5f5f3;
border-radius: 8px;
padding: 12px;
cursor: pointer;
margin-bottom: 8px;
transition: background 0.15s;
}
.example-card:hover {
background: #e9e9e6;
}
.example-card.active {
background: #ddf0e9;
}
.example-title {
font-size: 13px;
font-weight: 600;
color: #222;
}
.example-desc {
margin-top: 4px;
font-size: 12px;
color: #777;
line-height: 1.4;
}
/* ── Editor ── */
.editor-pane {
border-right: 0.5px solid rgba(0, 0, 0, 0.12);
}
.run-btn {
display: flex;
align-items: center;
gap: 6px;
padding: 6px 14px;
border-radius: 8px;
background: #1d9e75;
border: none;
color: white;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: background 0.15s;
}
.run-btn:hover {
background: #0f6e56;
}
.run-btn:active {
transform: scale(0.97);
}
/* Hand-rolled editor */
.editor-wrap {
flex: 1;
display: flex;
overflow: hidden;
background: #1a1a2e;
position: relative;
}
.line-numbers {
padding: 20px 0;
width: 44px;
flex-shrink: 0;
background: #14142a;
border-right: 0.5px solid rgba(255, 255, 255, 0.06);
overflow: hidden;
user-select: none;
}
.line-numbers span {
display: block;
text-align: right;
padding-right: 10px;
font-size: 13px;
font-family: "SF Mono", Monaco, Consolas, monospace;
line-height: 1.7;
color: #3d4a5c;
}
.line-numbers span.active-ln {
color: #7a8a9a;
}
textarea#editor {
flex: 1;
border: none;
outline: none;
resize: none;
padding: 20px 20px 20px 16px;
background: transparent;
color: #e2e8f0;
font-family: "SF Mono", Monaco, Consolas, monospace;
font-size: 13px;
line-height: 1.7;
caret-color: #1d9e75;
overflow-y: auto;
/* sync scroll with line numbers */
position: relative;
z-index: 1;
tab-size: 4;
-moz-tab-size: 4;
white-space: pre;
overflow-wrap: normal;
overflow-x: auto;
spellcheck: false;
}
textarea#editor::selection {
background: rgba(29, 158, 117, 0.28);
}
/* ── Status bar ── */
.status-bar {
padding: 4px 16px;
background: #f5f5f3;
border-top: 0.5px solid rgba(0, 0, 0, 0.1);
font-size: 11px;
color: #888;
flex-shrink: 0;
display: flex;
justify-content: space-between;
}
.status-bar.ok {
color: #1d9e75;
}
.status-bar.err {
color: #a32d2d;
}
/* ── Output ── */
.output-pane {
background: white;
}
.output-body {
flex: 1;
overflow-y: auto;
padding: 20px;
font-family: monospace;
font-size: 14px;
line-height: 1.8;
}
.output-empty {
color: #aaa;
font-size: 13px;
font-family: system-ui, sans-serif;
}
.output-line {
display: flex;
gap: 12px;
padding: 2px 0;
}
.output-line .arrow {
color: #1d9e75;
}
.output-line .value {
color: #1a1a2e;
}
.output-error {
color: #a32d2d;
background: #fcebeb;
border-radius: 8px;
padding: 10px 14px;
margin-top: 8px;
font-size: 13px;
}
</style>
</head>
<body>
<div class="ide-root">
<div class="pane examples-pane">
<div class="pane-header">
<span class="pane-label">Examples</span>
</div>
<div class="examples-list" id="examples"></div>
</div>
<div class="pane editor-pane">
<div class="pane-header">
<span class="pane-label">Source</span>
<button class="run-btn" id="run">
<i class="ti ti-player-play-filled"></i>
Run
</button>
</div>
<div class="editor-wrap">
<div class="line-numbers" id="line-numbers"></div>
<textarea
id="editor"
spellcheck="false"
autocorrect="off"
autocapitalize="off"
placeholder="LET A = 10 PRINT A"
></textarea>
</div>
<div class="status-bar" id="status">
<span id="status-msg">Ready</span>
<span id="status-pos">Ln 1, Col 1</span>
</div>
</div>
<div class="pane output-pane">
<div class="pane-header">
<span class="pane-label">Output</span>
</div>
<div class="output-body" id="output">
<div class="output-empty">Run your program to see output here.</div>
</div>
</div>
</div>
<script type="module">
const EXAMPLES = [
{
title: "Hello Numbers",
desc: "Simple PRINT statements",
code: "PRINT 1\nPRINT 2\nPRINT 3",
},
{
title: "Variables",
desc: "LET declarations and arithmetic",
code: "LET A = 10\nLET B = 20\n\nPRINT A + B",
},
{
title: "If Statement",
desc: "Conditional execution",
code: "LET A = 10\n\nIF A > 5 THEN\n PRINT A\nEND",
},
{
title: "For Loop",
desc: "Inclusive loop range",
code: "FOR I = 1 TO 5\n PRINT I\nEND",
},
{
title: "Sum 1 to 100",
desc: "Accumulating values in a loop",
code: "LET TOTAL = 0\n\nFOR I = 1 TO 100\n TOTAL = TOTAL + I\nEND\n\nPRINT TOTAL",
},
{
title: "Even Numbers",
desc: "Using the modulo (%) operator",
code: "FOR I = 1 TO 10\n IF I % 2 == 0 THEN\n PRINT I\n END\nEND",
},
{
title: "Absolute Value",
desc: "Handling negatives via subtraction",
code: "LET X = 0 - 42\nLET RESULT = X\n\nIF X < 0 THEN\n RESULT = 0 - X\nEND\n\nPRINT RESULT",
},
{
title: "Fibonacci Sequence",
desc: "Generates the first 10 Fibonacci numbers",
code: "LET A = 0\nLET B = 1\nLET TEMP = 0\n\nFOR I = 1 TO 10\n PRINT A\n TEMP = A + B\n A = B\n B = TEMP\nEND",
},
];
const editor = document.getElementById("editor");
const lnPanel = document.getElementById("line-numbers");
const statusMsg = document.getElementById("status-msg");
const statusPos = document.getElementById("status-pos");
// ── Line numbers ──────────────────────────────────────────────
function renderLineNumbers() {
const lines = editor.value.split("\n");
const totalLines = lines.length;
const cursorPos = editor.selectionStart;
const activeLine = editor.value.slice(0, cursorPos).split("\n").length;
lnPanel.innerHTML = lines
.map((_, i) => {
const n = i + 1;
return `<span class="${n === activeLine ? "active-ln" : ""}">${n}</span>`;
})
.join("");
}
// Sync line number scroll with textarea scroll
editor.addEventListener("scroll", () => {
lnPanel.scrollTop = editor.scrollTop;
});
// ── Cursor position ───────────────────────────────────────────
function updateCursor() {
const pos = editor.selectionStart;
const text = editor.value.slice(0, pos);
const ln = text.split("\n").length;
const col = text.split("\n").pop().length + 1;
statusPos.textContent = `Ln ${ln}, Col ${col}`;
renderLineNumbers();
}
editor.addEventListener("keyup", updateCursor);
editor.addEventListener("click", updateCursor);
editor.addEventListener("input", updateCursor);
editor.addEventListener("selectionchange", updateCursor);
// ── Tab key → 4 spaces ────────────────────────────────────────
editor.addEventListener("keydown", (e) => {
if (e.key === "Tab") {
e.preventDefault();
const s = editor.selectionStart;
const v = editor.value;
editor.value = v.slice(0, s) + " " + v.slice(editor.selectionEnd);
editor.selectionStart = editor.selectionEnd = s + 4;
renderLineNumbers();
}
// Ctrl/Cmd+Enter → run
if ((e.ctrlKey || e.metaKey) && e.key === "Enter") {
e.preventDefault();
document.getElementById("run").click();
}
});
// ── Examples sidebar ──────────────────────────────────────────
const container = document.getElementById("examples");
const cards = [];
EXAMPLES.forEach((example, i) => {
const card = document.createElement("div");
card.className = "example-card" + (i === 0 ? " active" : "");
card.innerHTML = `
<div class="example-title">${example.title}</div>
<div class="example-desc">${example.desc}</div>
`;
card.addEventListener("click", () => {
editor.value = example.code;
cards.forEach((c) => c.classList.remove("active"));
card.classList.add("active");
editor.focus();
renderLineNumbers();
updateCursor();
});
container.appendChild(card);
cards.push(card);
});
// ── Init ──────────────────────────────────────────────────────
editor.value = EXAMPLES[0].code;
renderLineNumbers();
// Expose for script.js
window.getEditorCode = () => editor.value;
window.setEditorStatus = (msg, type) => {
statusMsg.textContent = msg;
const bar = document.getElementById("status");
bar.className = "status-bar" + (type ? " " + type : "");
};
</script>
<script src="script.js" type="module"></script>
</body>
</html>