reladraw 0.1.0 → 0.2.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.
- package/README.md +25 -23
- package/SYNTAX.md +137 -54
- package/dist/ast.d.ts +73 -5
- package/dist/ast.js +99 -6
- package/dist/constants.d.ts +8 -5
- package/dist/constants.js +14 -12
- package/dist/grammar.d.ts +7 -7
- package/dist/grammar.js +9 -9
- package/dist/icons.d.ts +3 -3
- package/dist/icons.js +2 -2
- package/dist/lexer.d.ts +1 -1
- package/dist/lexer.js +1 -1
- package/dist/parser.js +47 -6
- package/dist/render.js +97 -81
- package/dist/resolve.js +144 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,33 +16,35 @@ Every distance in the second picture was worked out from statements like `above-
|
|
|
16
16
|
|
|
17
17
|
## The gap
|
|
18
18
|
|
|
19
|
-
Mermaid, Graphviz and D2
|
|
19
|
+
Mermaid, Graphviz and D2 have you declare entities and connections, and then place everything for you. That is a superpower, and for most diagrams it is the right one. It stops being the right one as soon as you have a particular picture in mind and care where things go. Say you are actively building your understanding of a system by diagramming it, and you want some module over to the right with its connections placed just so: the auto-layout languages have no way to say it.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
On the other end of the spectrum are the absolute-positioning tools — draw.io, Excalidraw, Figma. They give you total control of placement, at the cost of making every edit to a complex diagram slow hand-work. And it is slow for a human but expensive for an agent, which has to work the picture out from the coordinates before it can decide which ones to change.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
reladraw aims at the middle. Every position is stated relative to something else, and nothing in the file is a coordinate:
|
|
24
26
|
|
|
25
27
|
```
|
|
26
|
-
box
|
|
27
|
-
box
|
|
28
|
-
box
|
|
28
|
+
box app "Web app"
|
|
29
|
+
box app.ui "Interface"
|
|
30
|
+
box app.api "API" below app.ui
|
|
31
|
+
|
|
32
|
+
box store "Database" right of app level with app
|
|
29
33
|
|
|
30
|
-
link
|
|
34
|
+
link app.api -> store "queries" from: right to: left
|
|
31
35
|
```
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
Nothing is nested, so no line depends on another line's position or indentation.
|
|
34
38
|
|
|
35
39
|
The draft is in [SYNTAX.md](SYNTAX.md), with a worked example in [examples/](examples/).
|
|
36
40
|
|
|
37
41
|
## Why an agent needs this
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Reading matters more than writing, and it is where every other tool is weakest. Ask an agent to move the auth service left and add a queue behind it. Given pixel coordinates it has to reconstruct a picture from numbers before it can reason at all; given auto-layout there is no stored intent to read, because the arrangement was never written down. Given stated placement it reads sentences and already knows the arrangement. Diagrams get changed far more often than they get created, so this is the common case.
|
|
43
|
+
The common case is not drawing a diagram, it is changing one. Ask for the auth service to move left and a queue to go behind it. With pixel coordinates, an agent has to rebuild the picture from the numbers before it can work out which numbers to change. With auto-layout there is nothing to read at all, because the arrangement was never written down — it can only reword the source and re-render. With stated placement the arrangement is in the file as sentences, and changing the picture is changing the sentence that says where the thing goes.
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
Writing has the same shape. An agent emitting Mermaid is guessing at a layout that an algorithm settles later, and its only way to find out is to render and look — a round trip that comes back as a picture rather than as a list of what is wrong.
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
Intent is confirmable, outcomes are not, and the difference is worth being precise about. An agent can re-read its own file and see that the database is under the API and all four machines hang off Dropbox. It cannot see that two clusters anchored to different things now overlap, that a label overflowed its box, or that an edge crosses four others — those are resolved from the statements rather than stated, so they need the diagnostics in the scope section below.
|
|
46
48
|
|
|
47
49
|
### Using it with an agent
|
|
48
50
|
|
|
@@ -58,7 +60,7 @@ It is [plain Markdown](.claude/skills/reladraw/SKILL.md) with the syntax referen
|
|
|
58
60
|
|
|
59
61
|
## Status
|
|
60
62
|
|
|
61
|
-
Version 0.
|
|
63
|
+
Version 0.2.0. Early, but it runs: a parser, resolver and SVG renderer in TypeScript with no runtime dependencies, and a command-line tool that takes a text file and writes a standalone SVG. The comparison at the top of this page is that pipeline run on [`examples/arch.reladraw`](examples/arch.reladraw). What is still visibly off there is typography, not placement.
|
|
62
64
|
|
|
63
65
|
```
|
|
64
66
|
npm install -g reladraw
|
|
@@ -75,20 +77,20 @@ node dist/cli.js examples/arch.reladraw -o out.svg
|
|
|
75
77
|
Not built yet, roughly in the order they are missed:
|
|
76
78
|
|
|
77
79
|
- **The diagnostics report.** The scope section below says what it is for. Today the tool either renders or fails; it will not tell you what is wrong with a picture it drew successfully.
|
|
78
|
-
- **Edge routing around boxes.** A link can be told which side of a box to leave and arrive on, and which gap to run down on the way. A link that says none of that is a straight line between two
|
|
80
|
+
- **Edge routing around boxes.** A link can be told which side of a box to leave and arrive on, and which gap to run down on the way. A link that says none of that is a straight line between two centers, and it will cut through whatever stands in the way.
|
|
79
81
|
- **More glyphs.** Icons and shapes are closed sets drawn from path data inside the tool, so a diagram wanting one that is not there has nowhere to go.
|
|
80
82
|
|
|
81
83
|
The language is not stable. Expect the syntax to change.
|
|
82
84
|
|
|
83
85
|
## How it works
|
|
84
86
|
|
|
85
|
-
A gap is a *minimum* distance, never an exact one. Say two things sit side by side, then say a third goes between them, and the first two are pushed apart by exactly what the third needs; delete the third and they close back up.
|
|
87
|
+
A gap is a *minimum* distance, never an exact one. Say two things sit side by side, then say a third goes between them, and the first two are pushed apart by exactly what the third needs; delete the third and they close back up. That is the step an author otherwise does by hand — shove things apart to make room, then drag everything back so the diagram is not full of holes — and no number goes stale when a label grows.
|
|
86
88
|
|
|
87
89
|
So the resolver solves a system rather than walking a chain. Each axis is a set of minimum distances, and the tightest arrangement satisfying all of them is found by longest paths: one answer, no search, no arrangement ever tried and rejected. The engine works out distances; which side of what a thing sits on came from the file.
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
That is also what makes non-overlap affordable, so it holds for every pair of boxes without anyone writing it down. On its own "these two must not overlap" is a choice among four directions, which is the search this design refuses — but the file has usually settled it already: if your arrangement lets one box travel away from another and offers no way back, that is the only separation it permits. Where the file orders a pair on neither axis, the tool names them rather than guessing; where it orders them on both, the tie breaks toward the axis of least overlap, which is the smallest movement and the one place the tool decides something nobody wrote.
|
|
90
92
|
|
|
91
|
-
Nothing is nudged. Each round derives the separations the file already implied, adds them as ordinary minimum distances, and solves the whole thing again from scratch
|
|
93
|
+
Nothing is nudged. Each round derives the separations the file already implied, adds them as ordinary minimum distances, and solves the whole thing again from scratch — repairing a solved layout in place is the thing being avoided.
|
|
92
94
|
|
|
93
95
|
## Scope for a first version
|
|
94
96
|
|
|
@@ -115,21 +117,21 @@ Three design problems decide how much machinery this needs, and the first outran
|
|
|
115
117
|
|
|
116
118
|
## Prior art
|
|
117
119
|
|
|
118
|
-
Four things sit near this and
|
|
120
|
+
Four things sit near this, and each answers a different part of the problem.
|
|
119
121
|
|
|
120
|
-
**[Archify](https://github.com/tt-a1i/archify).**
|
|
122
|
+
**[Archify](https://github.com/tt-a1i/archify).** Built for agents to write: an agent emits typed JSON, a validator checks it against a schema and lints the layout, and it compiles deterministically to a good-looking, self-contained HTML file, with stepped playback and nodes pinned to git-verified source lines. Its positioning is grid or free coordinates, though — auto-arrangement on one side, absolute pixels on the other — and a JSON template says nothing about where the picture will end up, so the loop is still emit, render, look, tweak.
|
|
121
123
|
|
|
122
|
-
**PIC and [pikchr](https://pikchr.org).**
|
|
124
|
+
**PIC and [pikchr](https://pikchr.org).** A text diagram format with no layout engine, where placement is stated and deterministic. But it is turtle graphics — a movable cursor that drops shapes and steps along — so a diagram is a sequence of pen movements rather than a set of stated relationships between named things. There is no group that reflows when a member is added.
|
|
123
125
|
|
|
124
126
|
**Graphviz `rank` and `cluster`.** Constraints on an auto-layout engine rather than a replacement for one, so output stays emergent and unpredictable from the source.
|
|
125
127
|
|
|
126
|
-
**Structurizr.** Has real manual layout, but is bound to the C4 model, which makes it a
|
|
128
|
+
**Structurizr.** Has real manual layout, but is bound to the C4 model, which makes it a modeling notation with a renderer attached rather than a general placement language.
|
|
127
129
|
|
|
128
130
|
## License
|
|
129
131
|
|
|
130
132
|
Apache-2.0. This is a reusable primitive where adoption is the value, so restricting commercial use would defeat the purpose. See [LICENSE](LICENSE).
|
|
131
133
|
|
|
132
|
-
The
|
|
134
|
+
The license covers the code, not the name: it grants no rights to use "reladraw", the project logo, or the project's other marks. Forks are welcome and should carry a different name. See [NOTICE](NOTICE).
|
|
133
135
|
|
|
134
136
|
## Contributing
|
|
135
137
|
|