Skip to content

openpatch/struktolab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

197 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

StruktoLab

A free, web-based structogram (Nassi-Shneiderman diagram) editor with automatic code generation. Built entirely with web components β€” no framework dependencies.

Features

  • πŸ“ Bidirectional pseudocode editing (visual ↔ text)
  • 🌍 German and English pseudocode support
  • πŸ’» Code generation for Python, Java, and JavaScript
  • πŸ’Ύ Save/Load as JSON
  • πŸ–Ό Export as PNG or SVG image
  • πŸ”— Shareable URLs (state compressed in URL hash, compatible with struktolab.openpatch.org)
  • πŸ“¦ Web components β€” embed anywhere with zero dependencies

Web Components

<struktolab-editor>

Full-featured visual editor with toolbar, pseudocode sync, and import/export.

<script src="https://cdn.jsdelivr.net/npm/struktolab/dist/editor/struktolab-editor.umd.min.js"></script>

<!-- Empty editor -->
<struktolab-editor font-size="14"></struktolab-editor>

<!-- With German pseudocode -->
<struktolab-editor font-size="14">
  <script type="text/pseudocode">
    eingabe("Zahl n")
    ergebnis = 1
    wiederhole fΓΌr i = 1 bis n:
        ergebnis = ergebnis * i
    ausgabe(ergebnis)
  </script>
</struktolab-editor>

<!-- With English pseudocode -->
<struktolab-editor font-size="14" lang="en">
  <script type="text/pseudocode">
    input("number n")
    result = 1
    repeat for i = 1 to n:
        result = result * i
    output(result)
  </script>
</struktolab-editor>

<!-- From JSON -->
<struktolab-editor font-size="14">
  <script type="application/json">
    { "type": "TaskNode", "text": "x = 42" }
  </script>
</struktolab-editor>

Attributes

Attribute Description Default
width Fixed width in pixels auto
font-size Font size in pixels 14
lang Pseudocode language (de or en) de
src URL to a JSON tree file β€”
color-mode Color mode (color, bw) color

JavaScript API

const editor = document.querySelector('struktolab-editor');

// Get/set tree
editor.tree = { type: "TaskNode", text: "hello" };
console.log(editor.tree);

// Pseudocode
editor.pseudocode = 'eingabe("Zahl n")';

// Code generation
editor.toCode('python');    // β†’ Python code
editor.toCode('java');      // β†’ Java code
editor.toCode('javascript'); // β†’ JavaScript code

// Save/Load JSON (clean, no internal IDs)
const json = editor.saveJSON();
editor.loadJSON(json);

// Export image
const pngBlob = await editor.exportImage('png');
const svgBlob = await editor.exportImage('svg');

// Programmatic update
editor.change({ type: "TaskNode", text: "updated" });

// Listen for changes
editor.addEventListener('change', (e) => {
  console.log('Tree changed:', e.detail.tree);
});

<struktolab-renderer>

Read-only SVG renderer for displaying structograms.

<script src="https://cdn.jsdelivr.net/npm/struktolab/dist/renderer/struktolab-renderer.umd.min.js"></script>

<struktolab-renderer font-size="14">
  <script type="text/pseudocode">
    falls x > 0:
        ausgabe("positiv")
    sonst:
        ausgabe("nicht positiv")
  </script>
</struktolab-renderer>

Same attributes and tree format as the editor.

Shareable URLs

StruktoLab supports shareable URLs with the structogram state compressed in the URL hash using pako (zlib). This is compatible with existing URLs from struktolab.openpatch.org.

Example:

https://example.com/#pako:eNqlkstuE0EQRf-l166kH9Ov2UaJ...

The state is updated automatically as you edit.

Development

Prerequisites

  • Node.js (v14+)
  • npm

Setup

git clone https://github.com/openpatch/struktolab.git
cd struktog
npm install

Dev Server

npm run dev

Production Build

# App (index.html + bundled editor)
npm run build

# Component libraries (UMD + ES modules)
npm run build:renderer
npm run build:editor

# All at once
npm run build:all

Outputs:

  • build/ β€” app with index.html
  • dist/renderer/ β€” struktolab-renderer.umd.js / .es.js
  • dist/editor/ β€” struktolab-editor.umd.js / .es.js

Supported Node Types

Node Description
Task Simple statement
Input Read input
Output Write output
If/Else Two-way branch
Switch/Case Multi-way branch
While Head-controlled loop
Do-While Foot-controlled loop
For Counter-controlled loop
Function Function definition
Try/Catch Exception handling

License

MIT β€” see license.md

Credits

Based on the original structogram editor by Didaktik der Informatik, TU Dresden.

About

Structogram editor and renderer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 11