-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdocumentation.html
More file actions
489 lines (415 loc) · 20.3 KB
/
documentation.html
File metadata and controls
489 lines (415 loc) · 20.3 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>StruktoLab — Documentation</title>
<style>
*, *::before, *::after { box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
margin: 0;
padding: 0;
background: #f5f5f5;
color: #242428;
line-height: 1.6;
}
header {
background: #004c45;
color: #fff;
padding: 10px 20px;
display: flex;
align-items: center;
gap: 12px;
}
header h1 { font-size: 20px; margin: 0; font-weight: 600; }
header h1 span { color: #b5e3d9; }
header h1 a { color: inherit; text-decoration: none; }
header .spacer { flex: 1; }
header a.back {
color: #b5e3d9;
text-decoration: none;
font-size: 13px;
}
header a.back:hover { color: #fff; }
.container {
max-width: 860px;
margin: 0 auto;
padding: 24px 16px 40px;
}
h2 {
color: #004c45;
border-bottom: 2px solid #017460;
padding-bottom: 6px;
margin-top: 40px;
}
h3 {
color: #3c3c3c;
margin-top: 28px;
}
code {
background: #b5e3d9;
padding: 2px 6px;
border-radius: 3px;
font-size: 0.9em;
font-family: "Fira Code", "Consolas", monospace;
}
pre {
background: #242428;
color: #d6d6d6;
padding: 16px;
border-radius: 6px;
overflow-x: auto;
font-family: "Fira Code", "Consolas", monospace;
font-size: 13px;
line-height: 1.5;
}
pre code {
background: none;
padding: 0;
color: inherit;
}
.keyword { color: #b5e3d9; }
.string { color: #a6e3a1; }
.comment { color: #a4a4a4; font-style: italic; }
.tag { color: #b5e3d9; }
.attr { color: #f9e2af; }
table {
width: 100%;
border-collapse: collapse;
margin: 12px 0;
}
th, td {
border: 1px solid #d6d6d6;
padding: 8px 12px;
text-align: left;
}
th { background: #f5f5f5; font-weight: 600; color: #004c45; }
tr:nth-child(even) { background: #f5f5f5; }
.two-col {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
margin: 16px 0;
}
.two-col > div > h4 { margin-top: 0; color: #3c3c3c; }
@media (max-width: 640px) {
.two-col { grid-template-columns: 1fr; }
}
.note {
background: rgba(181, 227, 217, 0.3);
border-left: 4px solid #017460;
padding: 12px 16px;
border-radius: 0 4px 4px 0;
margin: 16px 0;
font-size: 14px;
}
footer {
text-align: center;
padding: 20px 16px;
color: #a4a4a4;
font-size: 13px;
}
footer a { color: #017460; text-decoration: none; }
footer a:hover { text-decoration: underline; }
footer .sep { margin: 0 6px; color: #d6d6d6; }
</style>
</head>
<body>
<header>
<h1><a href="index.html">Strukto<span>Lab</span></a></h1>
<div class="spacer"></div>
<a class="back" href="index.html">← Back to Editor</a>
</header>
<div class="container">
<h2>Pseudocode Reference</h2>
<p>StruktoLab uses a simple pseudocode syntax to define structograms. Two languages are supported: <strong>German</strong> (default) and <strong>English</strong>. Indentation (4 spaces) defines nesting.</p>
<h3>Statements</h3>
<div class="two-col">
<div>
<h4>🇩🇪 German</h4>
<pre><code><span class="comment">// Task (any plain statement)</span>
ergebnis = 1
<span class="comment">// Input</span>
<span class="keyword">eingabe</span>(<span class="string">"Zahl n"</span>)
<span class="comment">// Output</span>
<span class="keyword">ausgabe</span>(<span class="string">"Ergebnis"</span>)</code></pre>
</div>
<div>
<h4>🇬🇧 English</h4>
<pre><code><span class="comment">// Task (any plain statement)</span>
result = 1
<span class="comment">// Input</span>
<span class="keyword">input</span>(<span class="string">"number n"</span>)
<span class="comment">// Output</span>
<span class="keyword">output</span>(<span class="string">"result"</span>)</code></pre>
</div>
</div>
<h3>Branching (If/Else)</h3>
<div class="two-col">
<div>
<h4>🇩🇪 German</h4>
<pre><code><span class="keyword">falls</span> x > 0:
<span class="keyword">ausgabe</span>(<span class="string">"positiv"</span>)
<span class="keyword">sonst</span>:
<span class="keyword">ausgabe</span>(<span class="string">"nicht positiv"</span>)</code></pre>
</div>
<div>
<h4>🇬🇧 English</h4>
<pre><code><span class="keyword">if</span> x > 0:
<span class="keyword">output</span>(<span class="string">"positive"</span>)
<span class="keyword">else</span>:
<span class="keyword">output</span>(<span class="string">"not positive"</span>)</code></pre>
</div>
</div>
<div class="note">
You can set custom column widths with <code>[ratio, ratio]</code>:<br>
<code>falls x > 0 [0.7, 0.3]:</code> — 70% for true, 30% for false.
</div>
<h3>Switch / Case</h3>
<div class="two-col">
<div>
<h4>🇩🇪 German</h4>
<pre><code><span class="keyword">unterscheide</span> farbe:
<span class="keyword">fall</span> <span class="string">"rot"</span>:
<span class="keyword">ausgabe</span>(<span class="string">"stopp"</span>)
<span class="keyword">fall</span> <span class="string">"grün"</span>:
<span class="keyword">ausgabe</span>(<span class="string">"los"</span>)
<span class="keyword">sonst</span>:
<span class="keyword">ausgabe</span>(<span class="string">"unbekannt"</span>)</code></pre>
</div>
<div>
<h4>🇬🇧 English</h4>
<pre><code><span class="keyword">switch</span> color:
<span class="keyword">case</span> <span class="string">"red"</span>:
<span class="keyword">output</span>(<span class="string">"stop"</span>)
<span class="keyword">case</span> <span class="string">"green"</span>:
<span class="keyword">output</span>(<span class="string">"go"</span>)
<span class="keyword">else</span>:
<span class="keyword">output</span>(<span class="string">"unknown"</span>)</code></pre>
</div>
</div>
<div class="note">
Column widths also work for switch: <code>unterscheide farbe [0.4, 0.3, 0.3]:</code>
</div>
<h3>Loops</h3>
<div class="two-col">
<div>
<h4>🇩🇪 German</h4>
<pre><code><span class="comment">// Count loop (for)</span>
<span class="keyword">wiederhole für</span> i = 1 <span class="keyword">bis</span> 10:
<span class="keyword">ausgabe</span>(i)
<span class="comment">// Head loop (while)</span>
<span class="keyword">wiederhole solange</span> x > 0:
x = x - 1
<span class="comment">// Foot loop (do-while)</span>
<span class="keyword">wiederhole</span>:
<span class="keyword">eingabe</span>(<span class="string">"Wert"</span>)
<span class="keyword">solange</span> wert != 0</code></pre>
</div>
<div>
<h4>🇬🇧 English</h4>
<pre><code><span class="comment">// Count loop (for)</span>
<span class="keyword">repeat for</span> i = 1 <span class="keyword">to</span> 10:
<span class="keyword">output</span>(i)
<span class="comment">// Head loop (while)</span>
<span class="keyword">repeat while</span> x > 0:
x = x - 1
<span class="comment">// Foot loop (do-while)</span>
<span class="keyword">repeat</span>:
<span class="keyword">input</span>(<span class="string">"value"</span>)
<span class="keyword">while</span> value != 0</code></pre>
</div>
</div>
<h3>Functions</h3>
<div class="two-col">
<div>
<h4>🇩🇪 German</h4>
<pre><code><span class="keyword">funktion</span> factorial(n):
<span class="keyword">falls</span> n <= 1:
ergebnis = 1
<span class="keyword">sonst</span>:
ergebnis = n * factorial(n - 1)</code></pre>
</div>
<div>
<h4>🇬🇧 English</h4>
<pre><code><span class="keyword">function</span> factorial(n):
<span class="keyword">if</span> n <= 1:
result = 1
<span class="keyword">else</span>:
result = n * factorial(n - 1)</code></pre>
</div>
</div>
<h3>Try / Catch</h3>
<div class="two-col">
<div>
<h4>🇩🇪 German</h4>
<pre><code><span class="keyword">versuche</span>:
x = parse(eingabe)
<span class="keyword">fange</span> Exception e:
<span class="keyword">ausgabe</span>(<span class="string">"Fehler"</span>)</code></pre>
</div>
<div>
<h4>🇬🇧 English</h4>
<pre><code><span class="keyword">try</span>:
x = parse(input)
<span class="keyword">catch</span> Exception e:
<span class="keyword">output</span>(<span class="string">"error"</span>)</code></pre>
</div>
</div>
<h3>Line Breaks</h3>
<p>Use <code>\n</code> in node text for manual line breaks within a single node. In the visual editor, press <strong>Shift+Enter</strong> while editing a node.</p>
<!-- ───────────────────────────────────────── -->
<h2>Keyword Reference</h2>
<table>
<tr><th>Concept</th><th>German</th><th>English</th></tr>
<tr><td>If</td><td><code>falls</code></td><td><code>if</code></td></tr>
<tr><td>Else</td><td><code>sonst</code></td><td><code>else</code></td></tr>
<tr><td>Repeat</td><td><code>wiederhole</code></td><td><code>repeat</code></td></tr>
<tr><td>While</td><td><code>solange</code></td><td><code>while</code></td></tr>
<tr><td>For</td><td><code>für</code></td><td><code>for</code></td></tr>
<tr><td>To (range)</td><td><code>bis</code></td><td><code>to</code></td></tr>
<tr><td>Switch</td><td><code>unterscheide</code></td><td><code>switch</code></td></tr>
<tr><td>Case</td><td><code>fall</code></td><td><code>case</code></td></tr>
<tr><td>Function</td><td><code>funktion</code></td><td><code>function</code></td></tr>
<tr><td>Try</td><td><code>versuche</code></td><td><code>try</code></td></tr>
<tr><td>Catch</td><td><code>fange</code></td><td><code>catch</code></td></tr>
<tr><td>Input</td><td><code>eingabe</code></td><td><code>input</code></td></tr>
<tr><td>Output</td><td><code>ausgabe</code></td><td><code>output</code></td></tr>
<tr><td>True label</td><td>Wahr</td><td>True</td></tr>
<tr><td>False label</td><td>Falsch</td><td>False</td></tr>
<tr><td>Default label</td><td>Sonst</td><td>Default</td></tr>
</table>
<!-- ───────────────────────────────────────── -->
<h2>Web Components</h2>
<h3><code><struktolab-editor></code></h3>
<p>A full-featured visual structogram editor with toolbar, pseudocode sync, and import/export.</p>
<h4>Basic Usage</h4>
<pre><code><span class="comment"><!-- Load the script --></span>
<span class="tag"><script</span> <span class="attr">src</span>=<span class="string">"struktolab-editor.js"</span><span class="tag">></script></span>
<span class="comment"><!-- Empty editor --></span>
<span class="tag"><struktolab-editor</span> <span class="attr">font-size</span>=<span class="string">"14"</span><span class="tag">></struktolab-editor></span>
<span class="comment"><!-- With pseudocode --></span>
<span class="tag"><struktolab-editor</span> <span class="attr">font-size</span>=<span class="string">"14"</span> <span class="attr">lang</span>=<span class="string">"en"</span><span class="tag">></span>
<span class="tag"><script</span> <span class="attr">type</span>=<span class="string">"text/pseudocode"</span><span class="tag">></span>
input("number n")
result = 1
repeat for i = 1 to n:
result = result * i
output(result)
<span class="tag"></script></span>
<span class="tag"></struktolab-editor></span>
<span class="comment"><!-- With JSON --></span>
<span class="tag"><struktolab-editor</span> <span class="attr">font-size</span>=<span class="string">"14"</span><span class="tag">></span>
<span class="tag"><script</span> <span class="attr">type</span>=<span class="string">"application/json"</span><span class="tag">></span>
{ "type": "TaskNode", "text": "x = 42" }
<span class="tag"></script></span>
<span class="tag"></struktolab-editor></span>
<span class="comment"><!-- From external JSON file --></span>
<span class="tag"><struktolab-editor</span> <span class="attr">src</span>=<span class="string">"my-diagram.json"</span><span class="tag">></struktolab-editor></span></code></pre>
<h4>Attributes</h4>
<table>
<tr><th>Attribute</th><th>Description</th><th>Default</th></tr>
<tr><td><code>width</code></td><td>Fixed width in pixels (auto-sizes if omitted)</td><td>auto</td></tr>
<tr><td><code>font-size</code></td><td>Font size in pixels</td><td><code>14</code></td></tr>
<tr><td><code>lang</code></td><td>Pseudocode language: <code>de</code> or <code>en</code></td><td><code>de</code></td></tr>
<tr><td><code>src</code></td><td>URL to a JSON tree file</td><td>—</td></tr>
</table>
<h4>JavaScript API</h4>
<pre><code><span class="keyword">const</span> editor = document.querySelector(<span class="string">'struktolab-editor'</span>);
<span class="comment">// Get / set the tree object</span>
editor.tree = { type: <span class="string">"TaskNode"</span>, text: <span class="string">"hello"</span> };
console.log(editor.tree);
<span class="comment">// Set from pseudocode string</span>
editor.pseudocode = <span class="string">'input("name")\noutput("Hello " + name)'</span>;
<span class="comment">// Code generation</span>
editor.toCode(<span class="string">'python'</span>); <span class="comment">// → Python code</span>
editor.toCode(<span class="string">'java'</span>); <span class="comment">// → Java code</span>
editor.toCode(<span class="string">'javascript'</span>); <span class="comment">// → JavaScript code</span>
<span class="comment">// Save / Load JSON (clean, no internal IDs)</span>
<span class="keyword">const</span> json = editor.saveJSON();
editor.loadJSON(json);
<span class="comment">// Export as image</span>
<span class="keyword">const</span> pngBlob = <span class="keyword">await</span> editor.exportImage(<span class="string">'png'</span>);
<span class="keyword">const</span> svgBlob = <span class="keyword">await</span> editor.exportImage(<span class="string">'svg'</span>);
<span class="comment">// Programmatic update (re-renders + emits change event)</span>
editor.change({ type: <span class="string">"TaskNode"</span>, text: <span class="string">"updated"</span> });
<span class="comment">// Listen for changes</span>
editor.addEventListener(<span class="string">'change'</span>, (e) => {
console.log(<span class="string">'Tree changed:'</span>, e.detail.tree);
});</code></pre>
<h3><code><struktolab-renderer></code></h3>
<p>A read-only SVG renderer for displaying structograms. Same attributes and tree format as the editor, but without editing capabilities.</p>
<pre><code><span class="tag"><script</span> <span class="attr">src</span>=<span class="string">"struktolab-renderer.js"</span><span class="tag">></script></span>
<span class="tag"><struktolab-renderer</span> <span class="attr">font-size</span>=<span class="string">"14"</span> <span class="attr">lang</span>=<span class="string">"en"</span><span class="tag">></span>
<span class="tag"><script</span> <span class="attr">type</span>=<span class="string">"text/pseudocode"</span><span class="tag">></span>
if x > 0:
output("positive")
else:
output("not positive")
<span class="tag"></script></span>
<span class="tag"></struktolab-renderer></span></code></pre>
<h4>Renderer API</h4>
<pre><code><span class="keyword">const</span> renderer = document.querySelector(<span class="string">'struktolab-renderer'</span>);
<span class="comment">// Set tree or pseudocode</span>
renderer.tree = { type: <span class="string">"TaskNode"</span>, text: <span class="string">"hello"</span> };
renderer.pseudocode = <span class="string">'output("hello")'</span>;
<span class="comment">// Code generation</span>
renderer.toCode(<span class="string">'python'</span>);</code></pre>
<!-- ───────────────────────────────────────── -->
<h2>JSON Tree Format</h2>
<p>The tree is a nested JSON structure. Each node has a <code>type</code>, optional <code>text</code>, and a <code>followElement</code> for the next sibling.</p>
<h4>Node Types</h4>
<table>
<tr><th>Type</th><th>Properties</th></tr>
<tr><td><code>TaskNode</code></td><td><code>text</code>, <code>followElement</code></td></tr>
<tr><td><code>InputNode</code></td><td><code>text</code>, <code>followElement</code></td></tr>
<tr><td><code>OutputNode</code></td><td><code>text</code>, <code>followElement</code></td></tr>
<tr><td><code>BranchNode</code></td><td><code>text</code>, <code>trueChild</code>, <code>falseChild</code>, <code>columnWidths</code>, <code>followElement</code></td></tr>
<tr><td><code>CaseNode</code></td><td><code>text</code>, <code>cases</code> (array of InsertCase), <code>defaultOn</code>, <code>defaultNode</code>, <code>columnWidths</code>, <code>followElement</code></td></tr>
<tr><td><code>HeadLoopNode</code></td><td><code>text</code>, <code>child</code>, <code>followElement</code></td></tr>
<tr><td><code>FootLoopNode</code></td><td><code>text</code>, <code>child</code>, <code>followElement</code></td></tr>
<tr><td><code>CountLoopNode</code></td><td><code>text</code>, <code>child</code>, <code>followElement</code></td></tr>
<tr><td><code>FunctionNode</code></td><td><code>text</code>, <code>parameters</code> (array), <code>child</code>, <code>followElement</code></td></tr>
<tr><td><code>TryCatchNode</code></td><td><code>text</code>, <code>tryChild</code>, <code>catchChild</code>, <code>followElement</code></td></tr>
</table>
<h4>Example</h4>
<pre><code>{
<span class="string">"type"</span>: <span class="string">"BranchNode"</span>,
<span class="string">"text"</span>: <span class="string">"x > 0"</span>,
<span class="string">"columnWidths"</span>: [0.6, 0.4],
<span class="string">"trueChild"</span>: {
<span class="string">"type"</span>: <span class="string">"OutputNode"</span>,
<span class="string">"text"</span>: <span class="string">"positive"</span>
},
<span class="string">"falseChild"</span>: {
<span class="string">"type"</span>: <span class="string">"OutputNode"</span>,
<span class="string">"text"</span>: <span class="string">"not positive"</span>
},
<span class="string">"followElement"</span>: {
<span class="string">"type"</span>: <span class="string">"TaskNode"</span>,
<span class="string">"text"</span>: <span class="string">"done"</span>
}
}</code></pre>
<!-- ───────────────────────────────────────── -->
<h2>Shareable URLs</h2>
<p>StruktoLab encodes the entire structogram state in the URL hash using <a href="https://github.com/nickstenning/pako" target="_blank">pako</a> (zlib compression). This makes diagrams shareable via a single link — no server required.</p>
<p>URLs from <a href="https://struktolab.openpatch.org" target="_blank">struktolab.openpatch.org</a> are compatible and can be opened directly.</p>
<p>Format: <code>#pako:<base64url-compressed-json></code></p>
<p>The compressed JSON contains:</p>
<pre><code>{
<span class="string">"origin"</span>: <span class="string">"https://example.com"</span>,
<span class="string">"version"</span>: 2,
<span class="string">"model"</span>: { <span class="comment">/* tree JSON */</span> },
<span class="string">"settings"</span>: { <span class="string">"lang"</span>: <span class="string">"de"</span>, <span class="string">"fontSize"</span>: <span class="string">"14"</span> }
}</code></pre>
<footer>
Built with ❤️ by <a href="https://openpatch.org" target="_blank">OpenPatch</a>
<br>
<a href="documentation.html">Documentation</a>
<span class="sep">•</span>
<a href="https://github.com/openpatch/struktolab" target="_blank">GitHub</a>
</footer>
</div>
</body>
</html>