-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
89 lines (64 loc) · 1.94 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
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
// Generated by CoffeeScript 2.7.0
var defaultCode, editor, editorJar, errorBox, highlight, initialSourceCode, onShare, onUpdate, preview, previewJar, shareButton, withoutHash;
import {
CodeJar
} from "https://medv.io/codejar/codejar.js";
import {
compile
} from "https://esm.sh/@danielx/civet";
import Prism from "https://cdn.skypack.dev/prismjs";
defaultCode = `sum := (a:number, b:number) => a + b
square := (a:number) => a * a
fun := ->
console.log "It's all fun and games till it breaks"
song := ["do", "re", "mi", "fa", "so"]
singers := {Jagger: "Rock", Elvis: "Roll"}
bitlist := [
1, 0, 1
0, 0, 1
1, 1, 0
];
// hey jsx dudes... here
Component := () => <>{bitlist.map (x) => <p>x</p> }</>`;
editor = document.getElementById("editor");
preview = document.getElementById("preview");
errorBox = document.getElementById("error-box");
shareButton = document.getElementById("share-btn");
initialSourceCode = defaultCode;
if (window.location.hash) {
withoutHash = window.location.hash.trim().replace(/^#/, "");
initialSourceCode = atob(withoutHash);
}
highlight = function(c) {
var out;
out = Prism.highlight(c.innerText, Prism.languages.javascript, "javascript");
return c.innerHTML = out;
};
previewJar = CodeJar(preview, highlight, {
tab: " ".repeat(2)
});
editorJar = CodeJar(editor, function() {}, {
tab: " ".repeat(2)
});
onUpdate = function(c) {
var browserCompile, err;
try {
browserCompile = compile(c);
previewJar.updateCode(browserCompile);
return errorBox.innerText = "";
} catch (error) {
err = error;
return errorBox.innerText = err.message;
}
};
editorJar.onUpdate(onUpdate);
editorJar.updateCode(initialSourceCode);
previewJar.updateCode(compile(initialSourceCode));
onShare = function() {
var base64, code;
code = editorJar.toString();
base64 = btoa(code);
window.location.hash = base64;
return copyToClipboard(window.location.href);
};
shareButton.addEventListener("click", onShare);