-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
index.html
504 lines (425 loc) · 15.3 KB
/
index.html
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
<!DOCTYPE html>
<html lang="en">
<head>
@google-analytics@
<title>Diagon: ASCII art diagram generator</title>
<meta charset="utf-8">
<meta name="description" content="Generate beautiful ASCII art diagrams.
Diagon is a collection of interactive generators. Math formulas, sequences diagrams, graph,
border, ... This is written in C++, available online with WebAssembly.">
<meta name="og:title" property="og:title" content="Diagon: ASCII art diagram generators">
<meta name="robots" content="index, follow">
<link rel="canonical" href="https://arthursonzogni.com/Diagon/" />
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel=apple-touch-icon sizes=180x180 href=/apple-touch-icon.png>
<link rel=icon type=image/png sizes=16x16 href=/favicon-16x16.png>
<link rel=icon type=image/png sizes=32x32 href=/favicon-32x32.png>
<link rel=manifest href=/manifest.json>
<meta name=theme-color content="#FFFFFF">
<meta name=viewport content="width=device-width,initial-scale=1">
</head>
<body>
<!--First page-->
<div class="fullscreen" id="landing_page">
<!--Header-->
<div id="landing_page_content" class="flex">
<h1>Diagon</h1>
<h2><b>Diag</b>ram <b>On</b>line</h2>
<p>Interactive ASCII art diagram collection.</p>
<a href="#code_area" id="begin_button">Begin</a>
</div>
<!--Version number-->
<div class="container vertical fill_space">
<div class="flex"></div>
<div class="container horizontal">
<div class="flex"></div>
<div id="version">Version @git_version@</div>
</div>
</div>
<!-- Theme -->
<div id="style_button">
Dark theme
</div>
<!-- Links -->
<div id="links">
<a href="..">Home</a>
<a href="https://github.com/ArthurSonzogni/Diagon">Contribute</a>
</div>
</div>
<!--Second page-->
<div class="fullscreen" id="code_area">
<div class="container vertical fill_space">
<!--1 Menu bar-->
<div id="menu_bar" class="container horizontal y-scrollable nonflex">
<!--A Tool selection-->
<div class="menu_bar_submenu">
<label for="tools">Tool:</label>
<select type="text" id="tools">
<option>Chargement...</option>
</select>
</div>
<!--B Example selection-->
<div class="menu_bar_submenu">
<label for="examples">Example:</label>
<select type="text" id="examples">
<option>Chargement...</option>
</select>
</div>
<!--C Options selection selection-->
<div class="menu_bar_submenu container horizontal" id="options">
</div>
</div>
<!--2 Input / Output -->
<div class="container device-orientation flex">
<div id="input" class="highlight-container flex-equal">
<textarea
autofocus
spellcheck="false"
aria-label="input"
placeholder='input'
wrap="soft"
></textarea>
<div id="highlights" aria-hidden="true"></div>
</div>
<div class="container flex-equal vertical">
<div id="latex" class="flex displaylatex"></div>
<iframe id="html" class="flex displayhtml"></iframe>
<div class="copy-wrapper">
<div class="copy" id="copy-output">
Copy
</div>
</div>
<div id="output" class="highlight-container flex">
<textarea
spellcheck="false"
aria-label="output"
class="flex"
placeholder='output'
readonly
wrap="soft"
></textarea>
</div>
</div>
</div>
<!--3 Errors-->
<div id="errors" class="highlight-container nonflex">
<textarea
spellcheck="false"
aria-label="Errors"
placeholder='errors'
readonly
rows=3
></textarea>
</div>
</div>
</div>
<script>
const tools = document.querySelector('#tools');
const examples = document.querySelector('#examples');
const options = document.querySelector('#options');
const input = document.querySelector('#input > textarea');
const highlights = document.querySelector('#input > #highlights');
const output = document.querySelector('#output > textarea');
const errors = document.querySelector('#errors > textarea');
let tools_data = [];
const style_button = document.querySelector("#style_button");
const theme_style = document.querySelector("#theme_style");
const latex = document.querySelector('#latex');
const html = document.querySelector('#html');
errors.value = '';
function ClearSelectBox(select_box) {
while(select_box.options.length > 0)
select_box.options[0] = null;
}
function UpdateTools() {
ClearSelectBox(tools);
for(let i in tools_data) {
let tool = tools_data[i];
tools.options[i] = new Option(tool.description, i);
}
}
function UpdateExamples() {
let index = tools.value;
let tool = tools_data[index];
ClearSelectBox(examples);
examples.options = [];
examples.options.add(new Option("---------", -1));
for(let i in tool.examples)
examples.options.add(new Option(tool.examples[i].title, i));
}
let nextInstance = 0;
function UpdateOptions() {
while(options.firstChild)
options.removeChild(options.firstChild);
let index = tools.value;
let tool = tools_data[index];
for(let i in tool.options) {
let option = tool.options[i];
let option_box = document.createElement('p');
option_box.className = "option";
let instance = "instance-" + nextInstance;
nextInstance++;
let label = document.createElement('label');
label.innerText = option.label + " : ";
label.htmlFor = instance;
option_box.appendChild(label);
if (option.type == "checkbox") {
let checkbox = document.createElement("input");
checkbox.id = instance;
checkbox.type = "checkbox";
checkbox.data = option.name;
checkbox.checked = option.default == "true";
checkbox.addEventListener("change", UpdateOutput);
option_box.appendChild(checkbox);
}
if (option.type == "combobox") {
let select = document.createElement('select');
select.id = instance;
select.data = option.name
select.type = "text";
for(let i in option.values) {
select.options[i] = new Option(option.values[i]);
}
select.addEventListener("change", UpdateOutput);
option_box.appendChild(select);
}
options.appendChild(option_box);
}
}
function GetOptions() {
let output = "";
let index = tools.value;
let tool = tools_data[index];
for(let i in tool.options) {
let option = tool.options[i];
let name;
let value;
if (option.type == "checkbox") {
name = options.childNodes[i].childNodes[1].data;
value = options.childNodes[i].childNodes[1].checked;
}
if (option.type == "combobox") {
name = options.childNodes[i].childNodes[1].data;
value = options.childNodes[i].childNodes[1].value;
}
output += name + "\n";
output += value + "\n";
}
return output;
}
function UpdateInput() {
let tool_index = tools.value;
let example_index = examples.value;
if (example_index == -1)
return;
let example = tools_data[tool_index].examples[example_index];
input.value = example.content;
UpdateOutput();
}
window.MathJax = {
tex: { },
svg: {
fontCache: 'global'
},
};
let withKatex = f => {
if (window.myKatex != undefined) {
window.myKatex.execute(f);
return;
}
window.myKatex = {
onloaded: f,
execute: f => {
let ff = window.myKatex.onloaded;
window.myKatex.onloaded = () => {
ff();
f();
};
}
};
let katex_css = document.createElement("link");
katex_css.rel = "stylesheet";
katex_css.href = "https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css"
katex_css.integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq"
katex_css.crossOrigin="anonymous";
katex_css.defer = "true";
let katex_js = document.createElement("script");
katex_js.src = "https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js";
katex_js.integrity = "sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz";
katex_js.crossOrigin = "anonymous";
katex_js.defer = "true";
katex_js.onload = () => {
window.myKatex.onloaded();
window.myKatex.execute = f => f();
}
document.head.appendChild(katex_css);
document.head.appendChild(katex_js);
}
const diagon = {
translate: () => {},
highlight: () => {},
API: () => {},
}
let push_state = () => {};
function UpdateOutput() {
push_state();
errors.value = '';
document.querySelector("#highlights").innerHTML =
diagon.highlight(tools_data[tools.value].tool, input.value);
output.value =
diagon.translate(tools_data[tools.value].tool, input.value, GetOptions());
if (GetOptions().includes("Latex")) {
document.documentElement.setAttribute("data-display-latex", "true");
withKatex(() => {
katex.render(output.value, latex, {
throwOnError: false,
displayMode: true,
fleqn: true,
});
})
} else {
document.documentElement.setAttribute("data-display-latex", "false");
}
if (GetOptions().includes("html") ||
GetOptions().includes("svg")) {
document.documentElement.setAttribute("data-display-html", "true");
html.srcdoc = output.value;
} else {
document.documentElement.setAttribute("data-display-html", "false");
}
}
let OnToolsChanged = function() {
UpdateOptions();
UpdateExamples();
UpdateOutput();
}
function OnRuntimeInitialized() {
diagon.translate = Module.cwrap('translate', 'string', ['string', 'string', 'string']);
diagon.highlight = Module.cwrap('highlight', 'string', ['string', 'string']);
diagon.API = Module.cwrap('API', 'string', []);
tools.addEventListener("input", OnToolsChanged);
examples.addEventListener("input", UpdateInput);
input.addEventListener('input', UpdateOutput);
input.addEventListener('scroll', () => {
highlights.scroll({
top: input.scrollTop,
left: input.scrollLeft,
});
});
let api = diagon.API();
tools_data = JSON.parse(api);
setTimeout(PullState, 0);
UpdateTools();
UpdateExamples()
UpdateOptions();
UpdateInput();
UpdateOutput();
}
function print(text) {
if (arguments.length > 1)
text = Array.prototype.slice.call(arguments).join(' ');
errors.value += text + '\n';
};
window.Module = {
preRun: [],
postRun: [],
print: print,
printErr: print,
canvas: undefined,
onRuntimeInitialized: OnRuntimeInitialized,
};
// Theme ---
function getColorScheme() {
if(localStorage.getItem("theme"))
return localStorage.getItem("theme");
if(!window.matchMedia)
return "light";
if(window.matchMedia("(prefers-color-scheme: dark)").matches)
return "dark";
else
return "light";
}
//determines if the user has a set theme
function setColorScheme(scheme){
document.documentElement.setAttribute("data-theme", scheme);
}
let scheme = getColorScheme();
setColorScheme(scheme);
if (scheme == "dark")
style_button.innerText = "Light theme";
else
style_button.innerText = "Dark theme";
style_button.addEventListener("click", function() {
setTheme(style_button.innerText == "Dark theme");
});
function setTheme(is_dark) {
if (is_dark) {
localStorage.setItem('theme', 'dark');
style_button.innerText = "Light theme";
} else {
localStorage.setItem('theme', 'light');
style_button.innerText = "Dark theme";
}
setColorScheme(getColorScheme());
};
if (window.matchMedia) {
window.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', e => setTheme(e.matches));
}
setTimeout(() => {
let style = document.documentElement.style;
style.setProperty("--transition-time", "0.5s");
}, 500);
function clearSelection() {
if (window.getSelection)
window.getSelection().removeAllRanges();
else if (document.selection)
document.selection.empty();
}
const copyOutput = document.querySelector('#copy-output');
let copying_output = false;
copyOutput.addEventListener("click", async function() {
if (copyOutput.getAttribute("data-active") == "true")
return;
copyOutput.setAttribute("data-active", "true");
let length = output.value.length;
output.select();
output.setSelectionRange(0, 99999); /*For mobile devices*/
document.execCommand("copy");
clearSelection()
copyOutput.innerText = "Copied " + length + " letters";
await new Promise(r => setTimeout(r, 5000));
copyOutput.innerText = "Copy";
copyOutput.setAttribute("data-active", "false")
});
const PushState = async function() {
await new Promise(r => setTimeout(r, 0));
let data = tools_data[tools.value].tool;
history.pushState({},'Flowchart', '#' + data);
}
const PullState = async function() {
push_state = PushState;
if (!location.hash || location.hash == "#landing_page") {
document.querySelector("#landing_page").scrollIntoView();
return;
}
let data = location.hash.substr(1);
for(let i in tools_data) {
if (tools_data[i].tool !== data)
continue;
tools.selectedIndex = i;
document.querySelector("#code_area").scrollIntoView();
OnToolsChanged();
}
}
window.onpopstate = PullState;
</script>
<script src="diagon.js"></script>
<link
rel="preload"
as="style"
onload="this.rel=stylesheet"
type="text/css"
href="https://fontlibrary.org/face/dejavu-sans-mono"
/>
</html>