@senad-d/drawme 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,205 @@
1
+ # Authoring .drawio XML
2
+
3
+ Read this **before hand-writing any `.drawio` XML** (workflow step 3). Skip it when a bundled generator writes the XML for you (`autolayout.py` + importers, `seqlayout.py`).
4
+
5
+
6
+ ### File skeleton
7
+
8
+ ```xml
9
+ <?xml version="1.0" encoding="UTF-8"?>
10
+ <mxfile host="drawio" version="26.0.0">
11
+ <diagram name="Page-1">
12
+ <mxGraphModel>
13
+ <root>
14
+ <mxCell id="0" />
15
+ <mxCell id="1" parent="0" />
16
+ <!-- user shapes start at id="2" -->
17
+ </root>
18
+ </mxGraphModel>
19
+ </diagram>
20
+ </mxfile>
21
+ ```
22
+
23
+ **Rules:**
24
+ - `id="0"` and `id="1"` are required root cells — never omit them
25
+ - User shapes start at `id="2"` and increment sequentially
26
+ - All shapes have `parent="1"` (unless inside a container — then use container's id)
27
+ - All text uses `html=1` in style for proper rendering
28
+ - **Never use `--` inside XML comments** — it's illegal per XML spec and causes parse errors
29
+ - Escape special characters in attribute values: `&amp;`, `&lt;`, `&gt;`, `&quot;`
30
+ - **Multi-line text in labels:** use `&#xa;` for line breaks inside `value` attributes (not literal `\n`). Example: `value="Line 1&#xa;Line 2"`
31
+
32
+ ### Shape types (vertex)
33
+
34
+ | Style keyword | Use for |
35
+ |--------------|---------|
36
+ | `rounded=0` | plain rectangle (default) |
37
+ | `rounded=1` | rounded rectangle — services, modules |
38
+ | `ellipse;` | circles/ovals — start/end, databases |
39
+ | `rhombus;` | diamond — decision points |
40
+ | `shape=mxgraph.aws4.resourceIcon;` | AWS icons |
41
+ | `shape=cylinder3;` | cylinder — databases |
42
+ | `swimlane;` | group/container with title bar |
43
+
44
+ For **vendor/branded icons** (AWS/Azure/GCP/Cisco/Kubernetes) and any non-trivial shape, don't guess the `shape=mxgraph.*` name — a wrong name renders as a blank box. Run `python3 <this-skill-dir>/scripts/shapesearch.py "<keywords>"` to get the exact official style + size, or see `references/shapes.md` for the hand-writable cheatsheet. For **AI/LLM brand logos** (OpenAI, Claude, Gemini, …), which draw.io has none of, use `python3 <this-skill-dir>/scripts/aiicons.py "<brand>"`.
45
+
46
+ ### Required properties
47
+
48
+ ```xml
49
+ <!-- Rectangle / rounded box -->
50
+ <mxCell id="2" value="Label" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
51
+ <mxGeometry x="100" y="100" width="160" height="60" as="geometry" />
52
+ </mxCell>
53
+
54
+ <!-- Cylinder (database) -->
55
+ <mxCell id="3" value="DB" style="shape=cylinder3;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontColor=#333333;" vertex="1" parent="1">
56
+ <mxGeometry x="350" y="100" width="120" height="80" as="geometry" />
57
+ </mxCell>
58
+
59
+ <!-- Diamond (decision) -->
60
+ <mxCell id="4" value="Check?" style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="1">
61
+ <mxGeometry x="100" y="220" width="160" height="80" as="geometry" />
62
+ </mxCell>
63
+ ```
64
+
65
+ ### Containers and groups
66
+
67
+ For architecture diagrams with nested elements, use draw.io's parent-child containment — do **not** just place shapes on top of larger shapes.
68
+
69
+ | Type | Style | When to use |
70
+ |------|-------|-------------|
71
+ | **Group** (invisible) | `group;pointerEvents=0;` | No visual border needed, container has no connections |
72
+ | **Swimlane** (titled) | `swimlane;startSize=30;` | Container needs a visible title bar, or container itself has connections |
73
+ | **Custom container** | Add `container=1;pointerEvents=0;` to any shape | Any shape acting as a container without its own connections |
74
+
75
+ **Key rules:**
76
+ - Add `pointerEvents=0;` to container styles that should not capture connections between children
77
+ - Children set `parent="containerId"` and use coordinates **relative to the container**
78
+
79
+ ```xml
80
+ <!-- Swimlane container -->
81
+ <mxCell id="svc1" value="User Service" style="swimlane;startSize=30;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
82
+ <mxGeometry x="100" y="100" width="300" height="200" as="geometry"/>
83
+ </mxCell>
84
+ <!-- Child inside container — coordinates relative to parent -->
85
+ <mxCell id="api1" value="REST API" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="svc1">
86
+ <mxGeometry x="20" y="40" width="120" height="60" as="geometry"/>
87
+ </mxCell>
88
+ <mxCell id="db1" value="Database" style="shape=cylinder3;whiteSpace=wrap;html=1;" vertex="1" parent="svc1">
89
+ <mxGeometry x="160" y="40" width="120" height="60" as="geometry"/>
90
+ </mxCell>
91
+ ```
92
+
93
+ ### Connector (edge)
94
+
95
+ **CRITICAL:** Every edge `mxCell` must contain a `<mxGeometry relative="1" as="geometry" />` child element. Self-closing edge cells (`<mxCell ... edge="1" ... />`) are **invalid** and will not render. Always use the expanded form.
96
+
97
+ ```xml
98
+ <!-- Directed arrow — always include rounded, orthogonalLoop, jettySize for clean routing -->
99
+ <mxCell id="10" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="2" target="3">
100
+ <mxGeometry relative="1" as="geometry" />
101
+ </mxCell>
102
+
103
+ <!-- Arrow with label + explicit entry/exit points to control direction -->
104
+ <mxCell id="11" value="HTTP/REST" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="2" target="4">
105
+ <mxGeometry relative="1" as="geometry" />
106
+ </mxCell>
107
+
108
+ <!-- Arrow with waypoints — use when edge must route around other shapes -->
109
+ <mxCell id="12" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="3" target="5">
110
+ <mxGeometry relative="1" as="geometry">
111
+ <Array as="points">
112
+ <mxPoint x="500" y="50" />
113
+ </Array>
114
+ </mxGeometry>
115
+ </mxCell>
116
+ ```
117
+
118
+ **Edge style rules:**
119
+ - **Animated connectors:** add `flowAnimation=1;` to any edge style to show a moving dot animation along the arrow. Works in SVG export and draw.io desktop — ideal for data-flow and pipeline diagrams. Example: `style="edgeStyle=orthogonalEdgeStyle;flowAnimation=1;rounded=1;..."`
120
+ - **Always** include `rounded=1;orthogonalLoop=1;jettySize=auto` — these enable smart routing that avoids overlaps
121
+ - Pin `exitX/exitY/entryX/entryY` on every edge when a node has 2+ connections — distributes lines across the shape perimeter. `scripts/edgeports.py <file>` does this for a whole diagram: it picks the side facing each peer and spreads that side's edges over even slots ordered by the far endpoint, so they don't stack or cross at the boundary. It skips ends you pinned by hand and is idempotent
122
+ - Add `<Array as="points">` waypoints when an edge must detour around an intermediate shape
123
+ - **Leave room for arrowheads:** the final straight segment between the last bend and the target shape must be ≥20px long. If too short, the arrowhead overlaps the bend and looks broken. Fix by increasing node spacing or adding explicit waypoints
124
+ - **libavoid obstacle-avoiding routing (editor-side, draw.io ≥ 30):** draw.io has a newer connector router that recomputes edge paths to run *around* shapes (fanning out parallel edges) without moving any node. It runs interactively in the draw.io desktop editor (or via jgraph's MCP app-server `routing:"libavoid"`) — it is **not** a headless CLI flag. Passing `--layout libavoid` opens a modal `Unknown layout:` error dialog and hangs the run; the CLI `--layout` values are ELK *node* layout presets, a different thing (see `mermaid-authoring.md`). For CLI-authored files keep the orthogonal rules above; if a dense diagram still has crossings after export, open the `.drawio` in draw.io desktop once and let libavoid re-route. Don't stack it on an ELK `--layout` pass — pick one router, not both.
125
+
126
+ ### Distributing connections on a shape
127
+
128
+ When multiple edges connect to the same shape, assign different entry/exit points to prevent stacking:
129
+
130
+ | Position | exitX/entryX | exitY/entryY | Use when |
131
+ |----------|-------------|-------------|----------|
132
+ | Top center | 0.5 | 0 | connecting to node above |
133
+ | Top-left | 0.25 | 0 | 2nd connection from top |
134
+ | Top-right | 0.75 | 0 | 3rd connection from top |
135
+ | Right center | 1 | 0.5 | connecting to node on right |
136
+ | Bottom center | 0.5 | 1 | connecting to node below |
137
+ | Left center | 0 | 0.5 | connecting to node on left |
138
+
139
+ **Rule:** if a shape has N connections on one side, space them evenly (e.g., 3 connections on bottom → exitX = 0.25, 0.5, 0.75)
140
+
141
+ ### Color palette (fillColor / strokeColor)
142
+
143
+ *Used only when no user style preset is active (see `references/style-presets.md` → "Applying a preset").*
144
+
145
+ | Color name | fillColor | strokeColor | Use for |
146
+ |-----------|-----------|-------------|---------|
147
+ | Blue | `#dae8fc` | `#6c8ebf` | services, clients |
148
+ | Green | `#d5e8d4` | `#82b366` | success, databases |
149
+ | Yellow | `#fff2cc` | `#d6b656` | queues, decisions |
150
+ | Orange | `#ffe6cc` | `#d79b00` | gateways, APIs |
151
+ | Red/Pink | `#f8cecc` | `#b85450` | errors, alerts |
152
+ | Grey | `#f5f5f5` | `#666666` | external/neutral |
153
+ | Purple | `#e1d5e7` | `#9673a6` | security, auth |
154
+
155
+ ### Legend (auto-generate from the palette)
156
+
157
+ When a diagram uses 3+ semantic colors, add a legend so the color coding is self-explanatory. Generate it mechanically from the roles actually present — never invent legend entries that aren't in the diagram:
158
+
159
+ ```xml
160
+ <!-- Legend container: place in a corner clear of the diagram (e.g. below-left) -->
161
+ <mxCell id="legend" value="Legend" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeColor=#666666;verticalAlign=top;fontStyle=1;" vertex="1" parent="1">
162
+ <mxGeometry x="40" y="720" width="180" height="110" as="geometry"/>
163
+ </mxCell>
164
+ <!-- One swatch + label pair per used role, 24px row pitch, children of the legend -->
165
+ <mxCell id="leg1" value="" style="rounded=0;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="legend">
166
+ <mxGeometry x="10" y="30" width="30" height="16" as="geometry"/>
167
+ </mxCell>
168
+ <mxCell id="leg1t" value="Service" style="text;html=1;align=left;verticalAlign=middle;" vertex="1" parent="legend">
169
+ <mxGeometry x="50" y="28" width="120" height="20" as="geometry"/>
170
+ </mxCell>
171
+ ```
172
+
173
+ Rules: swatch colors come from the active palette (preset or the table above) with the **role name** as the label (Service, Database, Queue, …); height = `30 + 24 × rows`; the legend is a container (`parent="legend"`, relative coordinates); skip it entirely for single-color diagrams.
174
+
175
+ ### Layout tips
176
+
177
+ **Spacing — scale with complexity:**
178
+
179
+ | Diagram complexity | Nodes | Horizontal gap | Vertical gap |
180
+ |-------------------|-------|----------------|--------------|
181
+ | Simple | ≤5 | 200px | 150px |
182
+ | Medium | 6–10 | 280px | 200px |
183
+ | Complex | >10 | 350px | 250px |
184
+
185
+ **Routing corridors:** between shape rows/columns, leave an extra ~80px empty corridor where edges can route without crossing shapes. Never place a shape in a gap that edges need to traverse.
186
+
187
+ **Grid alignment:** snap all `x`, `y`, `width`, `height` values to **multiples of 10** — this ensures shapes align cleanly on draw.io's default grid and makes manual editing easier.
188
+
189
+ **General rules:**
190
+ - Plan a grid before assigning x/y coordinates — sketch node positions on paper/mentally first
191
+ - Group related nodes in the same horizontal or vertical band
192
+ - Use `swimlane` cells for logical grouping with visible borders
193
+ - Place heavily-connected "hub" nodes centrally so edges radiate outward instead of crossing
194
+ - To force straight vertical connections, pin entry/exit points explicitly on edges:
195
+ `exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0`
196
+ - Always center-align a child node under its parent (same center x) to avoid diagonal routing
197
+ - **Event bus pattern**: place Kafka/bus nodes in the **center of the service row**, not below — services on either side can reach it with short horizontal arrows (`exitX=1` left side, `exitX=0` right side), eliminating all line crossings
198
+ - Horizontal connections (`exitX=1` or `exitX=0`) never cross vertical nodes in the same row; use them for peer-to-peer and publish connections
199
+
200
+ **Avoiding edge-shape overlap:**
201
+ - Before finalizing coordinates, trace each edge path mentally — if it must cross an unrelated shape, either move the shape or add waypoints
202
+ - For tree/hierarchical layouts: assign nodes to layers (rows), connect only between adjacent layers to minimize crossings
203
+ - For star/hub layouts: place the hub center, satellites around it — edges stay short and radial
204
+ - When an edge must span multiple rows/columns, route it along the outer corridor, not through the middle of the diagram
205
+
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@senad-d/drawme",
3
+ "version": "0.1.0",
4
+ "description": "Pi extension: turn natural-language descriptions into .drawio diagrams and export to PNG/SVG/PDF/JPG via the draw.io desktop CLI. Local-only, no network.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Senad Dizdarević",
8
+ "homepage": "https://github.com/senad-d/DrawMe#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/senad-d/DrawMe.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/senad-d/DrawMe/issues"
15
+ },
16
+ "keywords": [
17
+ "pi",
18
+ "pi-extension",
19
+ "drawio",
20
+ "diagram",
21
+ "flowchart",
22
+ "architecture",
23
+ "mermaid",
24
+ "svg",
25
+ "png",
26
+ "visualization"
27
+ ],
28
+ "engines": {
29
+ "node": ">=22.19"
30
+ },
31
+ "pi": {
32
+ "extensions": [
33
+ "./src/index.ts"
34
+ ]
35
+ },
36
+ "files": [
37
+ "src",
38
+ "assets"
39
+ ],
40
+ "scripts": {
41
+ "typecheck": "tsc --noEmit",
42
+ "lint:eslint": "eslint . --max-warnings=0",
43
+ "format:check": "node scripts/format-check.mjs",
44
+ "lint": "npm run typecheck && npm run lint:eslint && npm run format:check",
45
+ "check:golden": "node scripts/check-golden.mjs",
46
+ "test": "vitest run",
47
+ "coverage": "vitest run --coverage",
48
+ "test:coverage": "npm run coverage",
49
+ "validate": "npm run check:golden && npm run lint && npm test",
50
+ "dev": "pi --no-extensions -e ."
51
+ },
52
+ "dependencies": {
53
+ "@xmldom/xmldom": "^0.9.8",
54
+ "typebox": "1.3.9"
55
+ },
56
+ "devDependencies": {
57
+ "@earendil-works/pi-coding-agent": "^0.83.0",
58
+ "@eslint/js": "^10.0.1",
59
+ "@types/node": "^26.1.2",
60
+ "@vitest/coverage-v8": "^4.1.10",
61
+ "eslint": "^10.8.0",
62
+ "globals": "^17.8.0",
63
+ "typescript": "^5.6.0",
64
+ "typescript-eslint": "^8.10.0",
65
+ "vitest": "^4.1.10"
66
+ }
67
+ }
package/src/dom.ts ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Minimal shared helpers over `@xmldom/xmldom` nodes. Typed structurally so the
3
+ * `.drawio` ports (validate, explain) read like the ElementTree originals without
4
+ * fighting xmldom's exported types. Local-only, no network.
5
+ */
6
+ export const ELEMENT_NODE = 1;
7
+ export const TEXT_NODE = 3;
8
+
9
+ export interface DomEl {
10
+ nodeType: number;
11
+ tagName?: string;
12
+ nodeValue?: string | null;
13
+ childNodes: { length: number; [i: number]: DomEl };
14
+ getAttribute(name: string): string | null;
15
+ hasAttribute(name: string): boolean;
16
+ setAttribute(name: string, value: string): void;
17
+ }
18
+
19
+ /** Element children only (skips text/comment nodes). */
20
+ export function elemChildren(el: DomEl): DomEl[] {
21
+ const out: DomEl[] = [];
22
+ for (const n of Array.from(el.childNodes)) {
23
+ if (n?.nodeType === ELEMENT_NODE) out.push(n);
24
+ }
25
+ return out;
26
+ }
27
+
28
+ /** Direct element children with the given tag (non-recursive, like ElementTree.findall). */
29
+ export function childrenByTag(el: DomEl, tag: string): DomEl[] {
30
+ return elemChildren(el).filter((c) => c.tagName === tag);
31
+ }
32
+
33
+ /** First direct child with the given tag, or null (like ElementTree.find). */
34
+ export function firstByTag(el: DomEl, tag: string): DomEl | null {
35
+ for (const c of elemChildren(el)) if (c.tagName === tag) return c;
36
+ return null;
37
+ }
38
+
39
+ /** Attribute value, or null when absent (distinguishes absent from empty). */
40
+ export function attr(el: DomEl, name: string): string | null {
41
+ return el.hasAttribute(name) ? el.getAttribute(name) : null;
42
+ }
43
+
44
+ /** Direct (non-descendant) text of an element, mirroring ElementTree's `.text`. */
45
+ export function directText(el: DomEl): string {
46
+ let s = "";
47
+ for (const n of Array.from(el.childNodes)) {
48
+ if (n?.nodeType === TEXT_NODE) s += n.nodeValue ?? "";
49
+ }
50
+ return s;
51
+ }