-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (67 loc) · 2.15 KB
/
Copy pathindex.js
File metadata and controls
80 lines (67 loc) · 2.15 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
import init, { format } from '@wasm-fmt/clang-format';
const mainDiv = document.getElementById('main');
const loadingDiv = document.getElementById('loading');
const formatBtn = document.getElementById('formatBtn');
const sourceTextArea = document.getElementById('sourceTextArea');
const formattedTextArea = document.getElementById('formattedTextArea');
const settingsTextArea = document.getElementById('settingsTextArea');
const resetConfiguration = document.getElementById('resetConfiguration');
const copyBtn = document.getElementById('copyBtn');
const defaultSettings = {
BasedOnStyle: "Microsoft",
IndentWidth: 4,
ColumnLimit: 120,
};
const defaultCode = `#include <priority_queue>
#include <unordered_map>
using namespace std ;
class FreqStack{
priority_queue<pair<int, pair<int, int>>> q;
unordered_map<int, int> freq;
int pos=0;
public:
void push(int x){
q.emplace(++freq[x], make_pair(++pos, x));}
int pop(){
auto val = q.top();
q.pop();
int x = val.second.second;
freq[x]--;
return x;}
};
int main(){ FreqStack fs;
fs.push(5); fs.push(7); fs.push(5);
fs.pop();
return 0;
}
`;
formatBtn.addEventListener('click', () => {
const source = sourceTextArea.value;
const rawSettings = settingsTextArea.value;
let formattedSource = "";
try {
const settings = JSON.parse(rawSettings);
formattedSource = format(source, "main.cc", JSON.stringify(settings));
}
catch (e) {
formattedSource = `Invalid JSON provided in settings: ${e}`;
}
formattedTextArea.value = formattedSource;
formattedTextArea.focus();
formattedTextArea.setSelectionRange(0, 0);
});
resetConfiguration.addEventListener('click', () => {
settingsTextArea.value = JSON.stringify(defaultSettings, null, 4);
});
copyBtn.addEventListener('click', () => {
navigator.clipboard.writeText(formattedTextArea.value);
});
window.addEventListener('load', () => {
init();
loadingDiv.style.display = 'none';
mainDiv.style.display = 'block';
sourceTextArea.value = defaultCode;
sourceTextArea.focus();
settingsTextArea.value = JSON.stringify(defaultSettings, null, 4);
formattedTextArea.value = "";
});