@senad-d/drawme 0.1.3 → 0.1.5
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/CHANGELOG.md +39 -2
- package/README.md +34 -23
- package/assets/references/troubleshooting.md +3 -3
- package/assets/references/xml-authoring.md +21 -1
- package/docs/{agent-guide.md → reference.md} +66 -140
- package/docs/visual-review-implementation-tasks.md +271 -0
- package/example/drawme-extension-waterfall-overview.drawio +72 -0
- package/example/drawme-how-it-works.drawio +127 -77
- package/example/drawme-installation-guide.drawio +98 -64
- package/package.json +1 -1
- package/src/drawio.ts +67 -15
- package/src/fitcanvas.ts +172 -0
- package/src/geometry.ts +259 -0
- package/src/index.ts +107 -15
- package/src/validate.ts +405 -223
- package/src/workflow.ts +86 -21
|
@@ -1,99 +1,133 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<mxfile host="drawio" version="
|
|
2
|
+
<mxfile host="drawio" version="31.1.5">
|
|
3
3
|
<diagram id="drawme-install" name="Install DrawMe">
|
|
4
|
-
<mxGraphModel dx="
|
|
4
|
+
<mxGraphModel dx="2000" dy="1650" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" math="0" shadow="0" background="#F4F7FB" pageWidth="2000" pageHeight="1685">
|
|
5
5
|
<root>
|
|
6
|
-
<mxCell id="0"
|
|
7
|
-
<mxCell id="1" parent="0"
|
|
8
|
-
<mxCell id="
|
|
9
|
-
<mxGeometry x="40" y="
|
|
6
|
+
<mxCell id="0"/>
|
|
7
|
+
<mxCell id="1" parent="0"/>
|
|
8
|
+
<mxCell id="title" value="Install DrawMe for Pi" style="text;html=1;align=left;verticalAlign=middle;fontSize=34;fontStyle=1;fontColor=#17365D;" vertex="1" parent="1">
|
|
9
|
+
<mxGeometry x="40" y="40" width="1100" height="50" as="geometry"/>
|
|
10
10
|
</mxCell>
|
|
11
|
-
<mxCell id="
|
|
12
|
-
<mxGeometry x="40" y="
|
|
11
|
+
<mxCell id="subtitle" value="From prerequisites to an autonomous, editable .drawio export" style="text;html=1;align=left;verticalAlign=middle;fontSize=16;fontColor=#4F6475;" vertex="1" parent="1">
|
|
12
|
+
<mxGeometry x="40" y="92" width="1200" height="32" as="geometry"/>
|
|
13
13
|
</mxCell>
|
|
14
|
-
<mxCell id="
|
|
15
|
-
<mxGeometry x="
|
|
14
|
+
<mxCell id="badge" value="LOCAL RENDERING • ONE PROMPT • EDITABLE OUTPUT" style="rounded=1;arcSize=22;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=10;fontSize=13;fontStyle=1;fontColor=#2D5E36;fillColor=#EAF4E8;strokeColor=#82B366;strokeWidth=2;" vertex="1" parent="1">
|
|
15
|
+
<mxGeometry x="1450" y="45" width="510" height="54" as="geometry"/>
|
|
16
16
|
</mxCell>
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
|
|
18
|
+
<mxCell id="prereqs" value="1 CHECK THE PREREQUISITES" style="swimlane;horizontal=1;startSize=60;rounded=1;arcSize=8;container=1;pointerEvents=0;html=1;fontSize=19;fontStyle=1;fontColor=#FFFFFF;fillColor=#1F4E78;swimlaneFillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;" vertex="1" parent="1">
|
|
19
|
+
<mxGeometry x="40" y="150" width="1920" height="270" as="geometry"/>
|
|
19
20
|
</mxCell>
|
|
20
|
-
<mxCell id="
|
|
21
|
-
<mxGeometry x="40" y="
|
|
21
|
+
<mxCell id="prereq-pi" value="<b><font color="#1F4E78">01 · PI CODING AGENT</font></b><br><br>Install and authenticate Pi first<br><font face="Courier New">pi --version</font>" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=14;fontSize=14;fontColor=#263746;fillColor=#F8FBFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="prereqs">
|
|
22
|
+
<mxGeometry x="40" y="85" width="540" height="135" as="geometry"/>
|
|
22
23
|
</mxCell>
|
|
23
|
-
<mxCell id="
|
|
24
|
-
<mxGeometry x="
|
|
24
|
+
<mxCell id="prereq-node" value="<b><font color="#1F4E78">02 · NODE.JS 22.19+</font></b><br><br>Required by DrawMe<br><font face="Courier New">node --version</font>" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=14;fontSize=14;fontColor=#263746;fillColor=#F8FBFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="prereqs">
|
|
25
|
+
<mxGeometry x="660" y="85" width="540" height="135" as="geometry"/>
|
|
25
26
|
</mxCell>
|
|
26
|
-
<mxCell id="
|
|
27
|
-
<mxGeometry x="
|
|
27
|
+
<mxCell id="prereq-drawio" value="<b><font color="#1F4E78">03 · DRAW.IO DESKTOP</font></b><br><br>macOS: <font face="Courier New">brew install --cask drawio</font><br>Linux: .deb / .rpm • Windows: official installer" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=14;fontSize=14;fontColor=#263746;fillColor=#F8FBFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="prereqs">
|
|
28
|
+
<mxGeometry x="1280" y="85" width="540" height="135" as="geometry"/>
|
|
28
29
|
</mxCell>
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
<mxCell id="install" value="2 INSTALL DRAWME · CHOOSE ONE SCOPE" style="swimlane;horizontal=1;startSize=60;rounded=1;arcSize=8;container=1;pointerEvents=0;html=1;fontSize=19;fontStyle=1;fontColor=#FFFFFF;fillColor=#1F4E78;swimlaneFillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;" vertex="1" parent="1">
|
|
32
|
+
<mxGeometry x="40" y="460" width="1920" height="465" as="geometry"/>
|
|
31
33
|
</mxCell>
|
|
32
|
-
<mxCell id="
|
|
33
|
-
<mxGeometry x="
|
|
34
|
+
<mxCell id="scope-decision" value="Choose scope" style="rhombus;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;fontSize=16;fontStyle=1;fontColor=#6B5500;fillColor=#FFF2CC;strokeColor=#D6B656;strokeWidth=2;" vertex="1" parent="install">
|
|
35
|
+
<mxGeometry x="790" y="80" width="280" height="90" as="geometry"/>
|
|
34
36
|
</mxCell>
|
|
35
|
-
<mxCell id="
|
|
36
|
-
<mxGeometry x="
|
|
37
|
+
<mxCell id="scope-user" value="<b><font color="#1F4E78">USER SCOPE · DEFAULT</font></b><br><br>All projects • ~/.pi/agent/settings.json<br><font face="Courier New">pi install npm:@senad-d/drawme</font>" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=14;fontSize=14;fontColor=#263746;fillColor=#EAF2F8;strokeColor=#1F4E78;strokeWidth=3;shadow=1;" vertex="1" parent="install">
|
|
38
|
+
<mxGeometry x="40" y="210" width="540" height="130" as="geometry"/>
|
|
37
39
|
</mxCell>
|
|
38
|
-
<mxCell id="
|
|
39
|
-
<mxGeometry x="
|
|
40
|
+
<mxCell id="scope-project" value="<b><font color="#1F4E78">PROJECT-LOCAL · TEAM</font></b><br><br>This project • .pi/settings.json<br><font face="Courier New">pi install npm:@senad-d/drawme -l</font>" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=14;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="install">
|
|
41
|
+
<mxGeometry x="660" y="210" width="540" height="130" as="geometry"/>
|
|
40
42
|
</mxCell>
|
|
41
|
-
<mxCell id="
|
|
42
|
-
<mxGeometry x="
|
|
43
|
+
<mxCell id="scope-trial" value="<b><font color="#1F4E78">ONE-TIME TRIAL</font></b><br><br>Current run only • no settings change<br><font face="Courier New">pi -e npm:@senad-d/drawme</font>" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=14;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="install">
|
|
44
|
+
<mxGeometry x="1280" y="210" width="540" height="130" as="geometry"/>
|
|
43
45
|
</mxCell>
|
|
44
|
-
<mxCell id="
|
|
45
|
-
<mxGeometry x="
|
|
46
|
+
<mxCell id="install-source" value="<b>PIN OR DEVELOP</b><br>Pinned npm: <font face="Courier New">npm:@senad-d/drawme@&lt;version&gt;</font> • Git: <font face="Courier New">git:github.com/senad-d/DrawMe@&lt;tag&gt;</font><br>Source checkout: <font face="Courier New">npm ci --ignore-scripts</font> → <font face="Courier New">npm run validate</font> → <font face="Courier New">pi --no-extensions -e .</font>" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=left;verticalAlign=middle;spacingLeft=14;spacingRight=14;spacingTop=8;spacingBottom=8;fontSize=13;fontColor=#405466;fillColor=#F3F6F8;strokeColor=#AAB7C4;dashed=1;" vertex="1" parent="install">
|
|
47
|
+
<mxGeometry x="40" y="360" width="1780" height="80" as="geometry"/>
|
|
46
48
|
</mxCell>
|
|
47
|
-
<mxCell id="
|
|
48
|
-
<mxGeometry
|
|
49
|
+
<mxCell id="edge-scope-user" value="all projects" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=blockThin;endFill=1;strokeColor=#1F4E78;strokeWidth=2;fontSize=11;fontColor=#405466;labelBackgroundColor=#FFFFFF;exitX=0.25;exitY=1;entryX=0.5;entryY=0;" edge="1" parent="install" source="scope-decision" target="scope-user">
|
|
50
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
49
51
|
</mxCell>
|
|
50
|
-
<mxCell id="
|
|
51
|
-
<mxGeometry
|
|
52
|
+
<mxCell id="edge-scope-project" value="this project" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=blockThin;endFill=1;strokeColor=#1F4E78;strokeWidth=2;fontSize=11;fontColor=#405466;labelBackgroundColor=#FFFFFF;exitX=0.5;exitY=1;entryX=0.5;entryY=0;" edge="1" parent="install" source="scope-decision" target="scope-project">
|
|
53
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
52
54
|
</mxCell>
|
|
53
|
-
<mxCell id="
|
|
54
|
-
<mxGeometry
|
|
55
|
+
<mxCell id="edge-scope-trial" value="current run" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=blockThin;endFill=1;strokeColor=#1F4E78;strokeWidth=2;fontSize=11;fontColor=#405466;labelBackgroundColor=#FFFFFF;exitX=0.75;exitY=1;entryX=0.5;entryY=0;" edge="1" parent="install" source="scope-decision" target="scope-trial">
|
|
56
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
55
57
|
</mxCell>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
|
|
59
|
+
<mxCell id="use" value="3 LOAD, VERIFY, DESCRIBE · DRAWME DOES THE REST" style="swimlane;horizontal=1;startSize=60;rounded=1;arcSize=8;container=1;pointerEvents=0;html=1;fontSize=19;fontStyle=1;fontColor=#FFFFFF;fillColor=#674274;swimlaneFillColor=#FCF9FD;strokeColor=#9673A6;strokeWidth=2;" vertex="1" parent="1">
|
|
60
|
+
<mxGeometry x="40" y="965" width="1920" height="340" as="geometry"/>
|
|
58
61
|
</mxCell>
|
|
59
|
-
<mxCell id="
|
|
60
|
-
<mxGeometry x="
|
|
62
|
+
<mxCell id="use-load" value="<b><font color="#674274">01 · LOAD</font></b><br><br>Start Pi after installation<br>Already open? Use <font face="Courier New">/reload</font>" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#B69BC2;strokeWidth=2;" vertex="1" parent="use">
|
|
63
|
+
<mxGeometry x="40" y="95" width="320" height="170" as="geometry"/>
|
|
61
64
|
</mxCell>
|
|
62
|
-
<mxCell id="
|
|
63
|
-
<mxGeometry x="
|
|
65
|
+
<mxCell id="use-verify" value="<b><font color="#674274">02 · VERIFY</font></b><br><br><font face="Courier New">/drawme-check</font><br>Confirm path · version · v30+ features" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#B69BC2;strokeWidth=2;" vertex="1" parent="use">
|
|
66
|
+
<mxGeometry x="410" y="95" width="320" height="170" as="geometry"/>
|
|
64
67
|
</mxCell>
|
|
65
|
-
<mxCell id="
|
|
66
|
-
<mxGeometry x="
|
|
68
|
+
<mxCell id="use-describe" value="<b><font color="#674274">03 · DESCRIBE</font></b><br><br><font face="Courier New">/drawme a login flow with retry</font><br>Use plain language" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#B69BC2;strokeWidth=2;" vertex="1" parent="use">
|
|
69
|
+
<mxGeometry x="780" y="95" width="320" height="170" as="geometry"/>
|
|
67
70
|
</mxCell>
|
|
68
|
-
<mxCell id="
|
|
69
|
-
<mxGeometry x="
|
|
71
|
+
<mxCell id="use-autonomous" value="<b><font color="#674274">04 · AUTONOMOUS RUN</font></b><br><br>plan → author → validate → critique<br>refine (≤5) → confirm → export<br><font color="#6B7C8A">no approval pause</font>" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#F7F0FA;strokeColor=#9673A6;strokeWidth=3;shadow=1;" vertex="1" parent="use">
|
|
72
|
+
<mxGeometry x="1150" y="95" width="320" height="170" as="geometry"/>
|
|
70
73
|
</mxCell>
|
|
71
|
-
<mxCell id="
|
|
72
|
-
<mxGeometry x="
|
|
74
|
+
<mxCell id="use-delivered" value="<b><font color="#2D5E36">05 · DELIVERED</font></b><br><br>Editable .drawio source<br>PNG by default<br>SVG · PDF · JPG when requested" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#EAF4E8;strokeColor=#82B366;strokeWidth=2;shadow=1;" vertex="1" parent="use">
|
|
75
|
+
<mxGeometry x="1520" y="95" width="320" height="170" as="geometry"/>
|
|
73
76
|
</mxCell>
|
|
74
|
-
<mxCell id="
|
|
75
|
-
<mxGeometry
|
|
77
|
+
<mxCell id="edge-use-load-verify" value="loaded" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=blockThin;endFill=1;strokeColor=#674274;strokeWidth=2;fontSize=11;fontColor=#405466;labelBackgroundColor=#FFFFFF;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="use" source="use-load" target="use-verify">
|
|
78
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
76
79
|
</mxCell>
|
|
77
|
-
<mxCell id="
|
|
78
|
-
<mxGeometry
|
|
80
|
+
<mxCell id="edge-use-verify-describe" value="CLI ready" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=blockThin;endFill=1;strokeColor=#674274;strokeWidth=2;fontSize=11;fontColor=#405466;labelBackgroundColor=#FFFFFF;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="use" source="use-verify" target="use-describe">
|
|
81
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
79
82
|
</mxCell>
|
|
80
|
-
<mxCell id="
|
|
81
|
-
<mxGeometry relative="1" as="geometry"
|
|
83
|
+
<mxCell id="edge-use-describe-autonomous" value="one prompt" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=blockThin;endFill=1;strokeColor=#674274;strokeWidth=2;fontSize=11;fontColor=#405466;labelBackgroundColor=#FFFFFF;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="use" source="use-describe" target="use-autonomous">
|
|
84
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
82
85
|
</mxCell>
|
|
83
|
-
<mxCell id="
|
|
84
|
-
<mxGeometry relative="1" as="geometry"
|
|
86
|
+
<mxCell id="edge-use-autonomous-delivered" value="automatic" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=blockThin;endFill=1;strokeColor=#2D5E36;strokeWidth=2;fontSize=11;fontColor=#405466;labelBackgroundColor=#FFFFFF;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="use" source="use-autonomous" target="use-delivered">
|
|
87
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
85
88
|
</mxCell>
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
|
|
90
|
+
<mxCell id="support" value="TROUBLESHOOTING, TRUST, AND COMPATIBILITY" style="swimlane;horizontal=1;startSize=56;rounded=1;arcSize=8;container=1;pointerEvents=0;html=1;fontSize=18;fontStyle=1;fontColor=#FFFFFF;fillColor=#405466;swimlaneFillColor=#F8FAFB;strokeColor=#7E8E9E;strokeWidth=2;" vertex="1" parent="1">
|
|
91
|
+
<mxGeometry x="40" y="1345" width="1920" height="300" as="geometry"/>
|
|
88
92
|
</mxCell>
|
|
89
|
-
<mxCell id="
|
|
90
|
-
<mxGeometry
|
|
93
|
+
<mxCell id="support-cli" value="<b>CLI NOT FOUND?</b><br><br>Install draw.io Desktop at a standard path, then rerun <font face="Courier New">/drawme-check</font>. XML authoring and validation can still run, but preview, export, Mermaid import, and ELK layout need the CLI." style="rounded=1;arcSize=8;whiteSpace=wrap;html=1;align=left;verticalAlign=middle;spacing=14;fontSize=13;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#AAB7C4;" vertex="1" parent="support">
|
|
94
|
+
<mxGeometry x="40" y="80" width="540" height="130" as="geometry"/>
|
|
91
95
|
</mxCell>
|
|
92
|
-
<mxCell id="
|
|
93
|
-
<mxGeometry
|
|
96
|
+
<mxCell id="support-package" value="<b>PACKAGE NOT VISIBLE?</b><br><br>Run <font face="Courier New">pi list</font>, check <font face="Courier New">pi config</font>, and use <font face="Courier New">/reload</font>. Project-local packages load from trusted projects; Pi installs missing project packages on startup." style="rounded=1;arcSize=8;whiteSpace=wrap;html=1;align=left;verticalAlign=middle;spacing=14;fontSize=13;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#AAB7C4;" vertex="1" parent="support">
|
|
97
|
+
<mxGeometry x="660" y="80" width="540" height="130" as="geometry"/>
|
|
94
98
|
</mxCell>
|
|
95
|
-
<mxCell id="
|
|
96
|
-
<mxGeometry
|
|
99
|
+
<mxCell id="support-trust" value="<b><font color="#9A5B13">INSTALL TRUSTED CODE ONLY</font></b><br><br>Pi packages run with full system access. Review third-party source before installation. DrawMe reads and writes requested diagram files and may launch draw.io or the OS file opener." style="rounded=1;arcSize=8;whiteSpace=wrap;html=1;align=left;verticalAlign=middle;spacing=14;fontSize=13;fontColor=#6A4513;fillColor=#FFF4E6;strokeColor=#D79B00;strokeWidth=1.5;" vertex="1" parent="support">
|
|
100
|
+
<mxGeometry x="1280" y="80" width="540" height="130" as="geometry"/>
|
|
101
|
+
</mxCell>
|
|
102
|
+
<mxCell id="legend" value="" style="rounded=1;arcSize=10;container=1;pointerEvents=0;html=1;fillColor=#F7F9FC;strokeColor=#C7D1DC;" vertex="1" parent="support">
|
|
103
|
+
<mxGeometry x="40" y="230" width="1780" height="45" as="geometry"/>
|
|
104
|
+
</mxCell>
|
|
105
|
+
<mxCell id="legend-title" value="COLOR KEY" style="text;html=1;align=left;verticalAlign=middle;fontSize=12;fontStyle=1;fontColor=#405466;" vertex="1" parent="legend">
|
|
106
|
+
<mxGeometry x="20" y="8" width="90" height="28" as="geometry"/>
|
|
107
|
+
</mxCell>
|
|
108
|
+
<mxCell id="legend-blue" value="" style="rounded=1;arcSize=6;html=1;fillColor=#D9EAF7;strokeColor=#6C8EBF;" vertex="1" parent="legend">
|
|
109
|
+
<mxGeometry x="130" y="14" width="18" height="18" as="geometry"/>
|
|
110
|
+
</mxCell>
|
|
111
|
+
<mxCell id="legend-blue-text" value="Setup / installation" style="text;html=1;align=left;verticalAlign=middle;fontSize=12;fontColor=#405466;" vertex="1" parent="legend">
|
|
112
|
+
<mxGeometry x="155" y="8" width="210" height="28" as="geometry"/>
|
|
113
|
+
</mxCell>
|
|
114
|
+
<mxCell id="legend-purple" value="" style="rounded=1;arcSize=6;html=1;fillColor=#E1D5E7;strokeColor=#9673A6;" vertex="1" parent="legend">
|
|
115
|
+
<mxGeometry x="430" y="14" width="18" height="18" as="geometry"/>
|
|
116
|
+
</mxCell>
|
|
117
|
+
<mxCell id="legend-purple-text" value="Autonomous workflow" style="text;html=1;align=left;verticalAlign=middle;fontSize=12;fontColor=#405466;" vertex="1" parent="legend">
|
|
118
|
+
<mxGeometry x="455" y="8" width="210" height="28" as="geometry"/>
|
|
119
|
+
</mxCell>
|
|
120
|
+
<mxCell id="legend-green" value="" style="rounded=1;arcSize=6;html=1;fillColor=#D5E8D4;strokeColor=#82B366;" vertex="1" parent="legend">
|
|
121
|
+
<mxGeometry x="730" y="14" width="18" height="18" as="geometry"/>
|
|
122
|
+
</mxCell>
|
|
123
|
+
<mxCell id="legend-green-text" value="Delivered files" style="text;html=1;align=left;verticalAlign=middle;fontSize=12;fontColor=#405466;" vertex="1" parent="legend">
|
|
124
|
+
<mxGeometry x="755" y="8" width="170" height="28" as="geometry"/>
|
|
125
|
+
</mxCell>
|
|
126
|
+
<mxCell id="legend-orange" value="" style="rounded=1;arcSize=6;html=1;fillColor=#FFF4E6;strokeColor=#D79B00;" vertex="1" parent="legend">
|
|
127
|
+
<mxGeometry x="990" y="14" width="18" height="18" as="geometry"/>
|
|
128
|
+
</mxCell>
|
|
129
|
+
<mxCell id="legend-orange-text" value="Security / caution" style="text;html=1;align=left;verticalAlign=middle;fontSize=12;fontColor=#405466;" vertex="1" parent="legend">
|
|
130
|
+
<mxGeometry x="1015" y="8" width="190" height="28" as="geometry"/>
|
|
97
131
|
</mxCell>
|
|
98
132
|
</root>
|
|
99
133
|
</mxGraphModel>
|
package/package.json
CHANGED
package/src/drawio.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* draw.io desktop CLI wrapper: binary resolution + export. Encodes the tricky
|
|
3
|
-
* flag knowledge for
|
|
4
|
-
* IEND repair, page indexing, and headless-Linux handling so callers never
|
|
3
|
+
* flag knowledge for focused previews vs final export, the vision width cap,
|
|
4
|
+
* `-e` PNG IEND repair, page indexing, and headless-Linux handling so callers never
|
|
5
5
|
* hand-build a draw.io command line.
|
|
6
6
|
*/
|
|
7
7
|
import { execFile } from "node:child_process";
|
|
@@ -163,15 +163,17 @@ export interface ExportResult {
|
|
|
163
163
|
version?: string;
|
|
164
164
|
/** True if the truncated `-e` PNG IEND chunk was repaired after export. */
|
|
165
165
|
repaired: boolean;
|
|
166
|
-
/**
|
|
166
|
+
/** Superseded preview artifacts removed after this successful preview or final export. */
|
|
167
167
|
removedPreviews: string[];
|
|
168
|
-
/** Best-effort cleanup failures; the
|
|
168
|
+
/** Best-effort preview cleanup failures; the export itself still succeeded. */
|
|
169
169
|
previewCleanupWarnings: string[];
|
|
170
170
|
command: string;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
/** Successful preview outputs, grouped by their canonical source path. */
|
|
173
|
+
/** Successful preview outputs still present, grouped by their canonical source path. */
|
|
174
174
|
const previewOutputs = new Map<string, Map<string, string>>();
|
|
175
|
+
/** Serialize exports per source so concurrent preview calls cannot leave multiple latest artifacts. */
|
|
176
|
+
const exportQueues = new Map<string, Promise<void>>();
|
|
175
177
|
|
|
176
178
|
function sourceKey(input: string): string {
|
|
177
179
|
try {
|
|
@@ -181,16 +183,42 @@ function sourceKey(input: string): string {
|
|
|
181
183
|
}
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
previewOutputs.set(sourceKey(input), previews);
|
|
186
|
+
interface PreviewCleanup {
|
|
187
|
+
removed: string[];
|
|
188
|
+
warnings: string[];
|
|
188
189
|
}
|
|
189
190
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Keep the newly exported preview and retire every older tracked preview for the
|
|
193
|
+
* same source. Cleanup happens only after the replacement exists, so a failed
|
|
194
|
+
* export never destroys the last usable review image.
|
|
195
|
+
*/
|
|
196
|
+
async function replaceTrackedPreview(input: string, latestOutput: string): Promise<PreviewCleanup> {
|
|
197
|
+
const key = sourceKey(input);
|
|
198
|
+
const previous = previewOutputs.get(key) ?? new Map<string, string>();
|
|
199
|
+
const latestPath = resolve(latestOutput);
|
|
200
|
+
const retained = new Map<string, string>([[latestPath, latestOutput]]);
|
|
201
|
+
const removed: string[] = [];
|
|
202
|
+
const warnings: string[] = [];
|
|
203
|
+
|
|
204
|
+
for (const [path, displayPath] of previous) {
|
|
205
|
+
if (path === latestPath) continue;
|
|
206
|
+
const existed = existsSync(path);
|
|
207
|
+
try {
|
|
208
|
+
await rm(path, { force: true });
|
|
209
|
+
if (existed) removed.push(displayPath);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
retained.set(path, displayPath);
|
|
212
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
213
|
+
warnings.push(`${displayPath}: ${message}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
previewOutputs.set(key, retained);
|
|
218
|
+
return { removed, warnings };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function removeTrackedPreviews(input: string, finalOutput: string): Promise<PreviewCleanup> {
|
|
194
222
|
const key = sourceKey(input);
|
|
195
223
|
const previews = previewOutputs.get(key);
|
|
196
224
|
if (!previews) return { removed: [], warnings: [] };
|
|
@@ -218,6 +246,25 @@ async function removeTrackedPreviews(
|
|
|
218
246
|
return { removed, warnings };
|
|
219
247
|
}
|
|
220
248
|
|
|
249
|
+
async function withSourceExportQueue<T>(input: string, action: () => Promise<T>): Promise<T> {
|
|
250
|
+
const key = sourceKey(input);
|
|
251
|
+
const previous = exportQueues.get(key) ?? Promise.resolve();
|
|
252
|
+
let release = (): void => {};
|
|
253
|
+
const current = new Promise<void>((resolveCurrent) => {
|
|
254
|
+
release = resolveCurrent;
|
|
255
|
+
});
|
|
256
|
+
const tail = previous.then(() => current);
|
|
257
|
+
exportQueues.set(key, tail);
|
|
258
|
+
|
|
259
|
+
await previous;
|
|
260
|
+
try {
|
|
261
|
+
return await action();
|
|
262
|
+
} finally {
|
|
263
|
+
release();
|
|
264
|
+
if (exportQueues.get(key) === tail) exportQueues.delete(key);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
221
268
|
function isRootUser(): boolean {
|
|
222
269
|
const getuid = (process as NodeJS.Process & { getuid?: () => number }).getuid;
|
|
223
270
|
return typeof getuid === "function" && getuid() === 0;
|
|
@@ -245,6 +292,10 @@ async function invoke(binary: string, fullArgs: string[]): Promise<string> {
|
|
|
245
292
|
*/
|
|
246
293
|
export async function exportDiagram(opts: ExportOptions): Promise<ExportResult> {
|
|
247
294
|
if (!existsSync(opts.input)) throw new Error(`input file not found: ${opts.input}`);
|
|
295
|
+
return withSourceExportQueue(opts.input, () => exportDiagramQueued(opts));
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async function exportDiagramQueued(opts: ExportOptions): Promise<ExportResult> {
|
|
248
299
|
const info = await resolveBinary(opts.binary);
|
|
249
300
|
if (!info.available || !info.binary) {
|
|
250
301
|
throw new Error(
|
|
@@ -268,9 +319,10 @@ export async function exportDiagram(opts: ExportOptions): Promise<ExportResult>
|
|
|
268
319
|
}
|
|
269
320
|
|
|
270
321
|
const repaired = plan.embed && plan.format === "png" ? await repairPng(plan.output) : false;
|
|
271
|
-
if (plan.mode === "preview") trackPreview(plan.input, plan.output);
|
|
272
322
|
const cleanup =
|
|
273
|
-
plan.mode === "
|
|
323
|
+
plan.mode === "preview"
|
|
324
|
+
? await replaceTrackedPreview(plan.input, plan.output)
|
|
325
|
+
: await removeTrackedPreviews(plan.input, plan.output);
|
|
274
326
|
return {
|
|
275
327
|
output: plan.output,
|
|
276
328
|
format: plan.format,
|
package/src/fitcanvas.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic canvas fit for `.drawio` files: per page, resize
|
|
3
|
+
* pageWidth/pageHeight to the visible content plus a margin and shift content
|
|
4
|
+
* so it starts exactly at that margin. Grows cramped pages and tightens
|
|
5
|
+
* oversized ones without touching element sizes or relative positions. No
|
|
6
|
+
* draw.io CLI involved.
|
|
7
|
+
*/
|
|
8
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
9
|
+
import { DOMParser, XMLSerializer } from "@xmldom/xmldom";
|
|
10
|
+
import { type DomEl, attr, childrenByTag, directText, firstByTag } from "./dom";
|
|
11
|
+
import { type ById, collectCellsWithIds, contentBounds, geometryIsRelative, pyFloat } from "./geometry";
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_FIT_MARGIN = 40;
|
|
14
|
+
|
|
15
|
+
export interface FitPageResult {
|
|
16
|
+
page: string;
|
|
17
|
+
status: "fitted" | "unchanged" | "skipped";
|
|
18
|
+
/** Why the page was skipped. */
|
|
19
|
+
reason?: string;
|
|
20
|
+
before?: { width?: number; height?: number };
|
|
21
|
+
after?: { width: number; height: number };
|
|
22
|
+
shift?: { dx: number; dy: number };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface FitCanvasOptions {
|
|
26
|
+
input: string;
|
|
27
|
+
/** Outer margin between content and page edge, in model px (default 40). */
|
|
28
|
+
margin?: number;
|
|
29
|
+
/** Destination path; defaults to overwriting the input. */
|
|
30
|
+
output?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FitCanvasResult {
|
|
34
|
+
input: string;
|
|
35
|
+
output: string;
|
|
36
|
+
margin: number;
|
|
37
|
+
/** True when at least one page was resized or shifted. */
|
|
38
|
+
changed: boolean;
|
|
39
|
+
pages: FitPageResult[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function fmt(value: number): string {
|
|
43
|
+
return String(Math.round(value * 1000) / 1000);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function shiftAttr(el: DomEl, name: "x" | "y", delta: number): void {
|
|
47
|
+
const current = pyFloat(attr(el, name) ?? "0");
|
|
48
|
+
if (current === undefined || !Number.isFinite(current)) return;
|
|
49
|
+
el.setAttribute(name, fmt(current + delta));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Shift one top-level cell: absolute vertex origin, or edge points/waypoints. */
|
|
53
|
+
function shiftCell(cell: DomEl, dx: number, dy: number): void {
|
|
54
|
+
const geometry = firstByTag(cell, "mxGeometry");
|
|
55
|
+
if (!geometry) return;
|
|
56
|
+
if (cell.getAttribute("vertex") === "1" && !geometryIsRelative(cell)) {
|
|
57
|
+
shiftAttr(geometry, "x", dx);
|
|
58
|
+
shiftAttr(geometry, "y", dy);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (cell.getAttribute("edge") === "1") {
|
|
62
|
+
for (const point of childrenByTag(geometry, "mxPoint")) {
|
|
63
|
+
const as = attr(point, "as");
|
|
64
|
+
if (as === "sourcePoint" || as === "targetPoint") {
|
|
65
|
+
shiftAttr(point, "x", dx);
|
|
66
|
+
shiftAttr(point, "y", dy);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const waypoints = firstByTag(geometry, "Array");
|
|
70
|
+
for (const point of waypoints ? childrenByTag(waypoints, "mxPoint") : []) {
|
|
71
|
+
shiftAttr(point, "x", dx);
|
|
72
|
+
shiftAttr(point, "y", dy);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Ids of layer cells (direct children of the root cell `0`). */
|
|
78
|
+
function layerIds(ids: ById): Set<string> {
|
|
79
|
+
const layers = new Set<string>();
|
|
80
|
+
for (const [id, cell] of ids) {
|
|
81
|
+
if (attr(cell, "parent") === "0") layers.add(id);
|
|
82
|
+
}
|
|
83
|
+
return layers;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function pageScale(model: DomEl): number {
|
|
87
|
+
const raw = attr(model, "pageScale");
|
|
88
|
+
const parsed = raw === null ? 1 : pyFloat(raw);
|
|
89
|
+
return parsed !== undefined && Number.isFinite(parsed) && parsed > 0 ? parsed : 1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function currentDimension(model: DomEl, name: "pageWidth" | "pageHeight"): number | undefined {
|
|
93
|
+
const raw = attr(model, name);
|
|
94
|
+
if (raw === null) return undefined;
|
|
95
|
+
const value = pyFloat(raw);
|
|
96
|
+
return value !== undefined && Number.isFinite(value) && value > 0 ? value : undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Fit a single page's model in place; returns what happened. */
|
|
100
|
+
function fitModel(name: string, model: DomEl, margin: number): FitPageResult {
|
|
101
|
+
if (attr(model, "page") === "0") {
|
|
102
|
+
return { page: name, status: "skipped", reason: "page canvas disabled (infinite canvas)" };
|
|
103
|
+
}
|
|
104
|
+
const { cells, ids } = collectCellsWithIds(firstByTag(model, "root"));
|
|
105
|
+
const bounds = contentBounds(cells, ids);
|
|
106
|
+
if (!bounds) return { page: name, status: "skipped", reason: "no measurable content" };
|
|
107
|
+
|
|
108
|
+
const scale = pageScale(model);
|
|
109
|
+
const rawDx = margin - bounds.minX;
|
|
110
|
+
const rawDy = margin - bounds.minY;
|
|
111
|
+
const dx = Math.abs(rawDx) < 0.005 ? 0 : Math.round(rawDx * 1000) / 1000;
|
|
112
|
+
const dy = Math.abs(rawDy) < 0.005 ? 0 : Math.round(rawDy * 1000) / 1000;
|
|
113
|
+
const width = Math.ceil((bounds.maxX - bounds.minX + 2 * margin) / scale);
|
|
114
|
+
const height = Math.ceil((bounds.maxY - bounds.minY + 2 * margin) / scale);
|
|
115
|
+
const before = { width: currentDimension(model, "pageWidth"), height: currentDimension(model, "pageHeight") };
|
|
116
|
+
|
|
117
|
+
if (dx === 0 && dy === 0 && before.width === width && before.height === height) {
|
|
118
|
+
return { page: name, status: "unchanged", before, after: { width, height } };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (dx !== 0 || dy !== 0) {
|
|
122
|
+
const layers = layerIds(ids);
|
|
123
|
+
for (const cell of cells) {
|
|
124
|
+
const parent = attr(cell, "parent");
|
|
125
|
+
if (parent !== null && layers.has(parent)) shiftCell(cell, dx, dy);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
model.setAttribute("pageWidth", String(width));
|
|
129
|
+
model.setAttribute("pageHeight", String(height));
|
|
130
|
+
return { page: name, status: "fitted", before, after: { width, height }, shift: { dx, dy } };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function fitPage(diagram: DomEl, margin: number): FitPageResult {
|
|
134
|
+
const name = attr(diagram, "name") ?? "?";
|
|
135
|
+
const model = firstByTag(diagram, "mxGraphModel");
|
|
136
|
+
if (!model) {
|
|
137
|
+
const reason = directText(diagram).trim() ? "compressed page (cannot fit)" : "no <mxGraphModel>";
|
|
138
|
+
return { page: name, status: "skipped", reason };
|
|
139
|
+
}
|
|
140
|
+
return fitModel(name, model, margin);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Fit every page of a `.drawio` file. Throws on read/parse failure or invalid margin. */
|
|
144
|
+
export async function fitCanvasFile(options: FitCanvasOptions): Promise<FitCanvasResult> {
|
|
145
|
+
const margin = options.margin ?? DEFAULT_FIT_MARGIN;
|
|
146
|
+
if (!Number.isFinite(margin) || margin < 0) throw new Error(`invalid margin ${String(options.margin)}`);
|
|
147
|
+
const output = options.output ?? options.input;
|
|
148
|
+
const xml = await readFile(options.input, "utf8");
|
|
149
|
+
const doc = new DOMParser().parseFromString(xml, "text/xml");
|
|
150
|
+
const root = doc.documentElement as unknown as DomEl | null;
|
|
151
|
+
if (!root) throw new Error("no root element (malformed XML)");
|
|
152
|
+
|
|
153
|
+
const diagrams = childrenByTag(root, "diagram");
|
|
154
|
+
let pages: FitPageResult[];
|
|
155
|
+
if (diagrams.length > 0) {
|
|
156
|
+
pages = diagrams.map((diagram) => fitPage(diagram, margin));
|
|
157
|
+
} else if (root.tagName === "mxGraphModel") {
|
|
158
|
+
pages = [fitModel("?", root, margin)];
|
|
159
|
+
} else {
|
|
160
|
+
pages = [{ page: "?", status: "skipped", reason: "no <diagram> pages and root is not <mxGraphModel>" }];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const changed = pages.some((page) => page.status === "fitted");
|
|
164
|
+
if (changed || output !== options.input) {
|
|
165
|
+
let serialized = new XMLSerializer().serializeToString(doc as never);
|
|
166
|
+
const declaration = /^<\?xml[^>]*\?>/.exec(xml)?.[0];
|
|
167
|
+
if (declaration && !serialized.startsWith("<?xml")) serialized = `${declaration}\n${serialized}`;
|
|
168
|
+
if (xml.endsWith("\n") && !serialized.endsWith("\n")) serialized += "\n";
|
|
169
|
+
await writeFile(output, serialized, "utf8");
|
|
170
|
+
}
|
|
171
|
+
return { input: options.input, output, margin, changed, pages };
|
|
172
|
+
}
|