@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.
@@ -1,99 +1,133 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <mxfile host="drawio" version="26.0.9">
2
+ <mxfile host="drawio" version="31.1.5">
3
3
  <diagram id="drawme-install" name="Install DrawMe">
4
- <mxGraphModel dx="1800" dy="1300" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1920" pageHeight="1360" math="0" shadow="0" background="#FFFFFF">
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="2" value="Install DrawMe for Pi" style="text;html=1;align=left;verticalAlign=middle;fontSize=32;fontStyle=1;fontColor=#17365D;" vertex="1" parent="1">
9
- <mxGeometry x="40" y="20" width="1000" height="50" as="geometry" />
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="3" value="From prerequisites to your first editable .drawio diagram" style="text;html=1;align=left;verticalAlign=middle;fontSize=17;fontColor=#4F6475;" vertex="1" parent="1">
12
- <mxGeometry x="40" y="70" width="1100" height="40" as="geometry" />
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="4" value="QUICK SETUP • 3–5 MINUTES • EDITABLE OUTPUTS" style="rounded=1;arcSize=20;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#2D5E36;fillColor=#D5E8D4;strokeColor=#82B366;strokeWidth=2;" vertex="1" parent="1">
15
- <mxGeometry x="1370" y="35" width="470" height="50" as="geometry" />
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
- <mxCell id="5" value="1 CHECK THE PREREQUISITES" style="swimlane;horizontal=1;startSize=46;rounded=1;arcSize=8;container=1;pointerEvents=0;html=1;fontSize=17;fontStyle=1;fontColor=#FFFFFF;fillColor=#1F4E78;swimlaneFillColor=#F8FBFF;strokeColor=#6C8EBF;strokeWidth=2;" vertex="1" parent="1">
18
- <mxGeometry x="40" y="130" width="1800" height="230" as="geometry" />
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="6" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;PI CODING AGENT&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Pi must already be installed&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;pi --version&lt;/font&gt;" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="5">
21
- <mxGeometry x="40" y="75" width="500" height="120" as="geometry" />
21
+ <mxCell id="prereq-pi" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;01 · PI CODING AGENT&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Install and authenticate Pi first&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;pi --version&lt;/font&gt;" 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="7" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;NODE.JS 22.19+&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Required by DrawMe&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;node --version&lt;/font&gt;" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="5">
24
- <mxGeometry x="650" y="75" width="500" height="120" as="geometry" />
24
+ <mxCell id="prereq-node" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;02 · NODE.JS 22.19+&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Required by DrawMe&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;node --version&lt;/font&gt;" 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="8" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;DRAW.IO DESKTOP&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;macOS: &lt;font face=&quot;Courier New&quot;&gt;brew install --cask drawio&lt;/font&gt;&lt;br&gt;Linux / Windows: install the official desktop release" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="5">
27
- <mxGeometry x="1260" y="75" width="500" height="120" as="geometry" />
27
+ <mxCell id="prereq-drawio" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;03 · DRAW.IO DESKTOP&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;macOS: &lt;font face=&quot;Courier New&quot;&gt;brew install --cask drawio&lt;/font&gt;&lt;br&gt;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
- <mxCell id="9" value="↓" style="text;html=1;align=center;verticalAlign=middle;fontSize=24;fontStyle=1;fontColor=#1F4E78;" vertex="1" parent="1">
30
- <mxGeometry x="880" y="360" width="120" height="30" as="geometry" />
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="10" value="2 INSTALL DRAWME — CHOOSE ONE SCOPE" style="swimlane;horizontal=1;startSize=46;rounded=1;arcSize=8;container=1;pointerEvents=0;html=1;fontSize=17;fontStyle=1;fontColor=#FFFFFF;fillColor=#1F4E78;swimlaneFillColor=#F8FBFF;strokeColor=#6C8EBF;strokeWidth=2;" vertex="1" parent="1">
33
- <mxGeometry x="40" y="390" width="1800" height="360" as="geometry" />
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="11" 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="10">
36
- <mxGeometry x="760" y="60" width="280" height="90" as="geometry" />
37
+ <mxCell id="scope-user" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;USER SCOPE · DEFAULT&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;All projects • ~/.pi/agent/settings.json&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;pi install npm:@senad-d/drawme&lt;/font&gt;" 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="12" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;GLOBAL · RECOMMENDED&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Available in every project&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;pi install npm:@senad-d/drawme&lt;/font&gt;" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#EAF2F8;strokeColor=#1F4E78;strokeWidth=3;shadow=1;" vertex="1" parent="10">
39
- <mxGeometry x="70" y="180" width="500" height="115" as="geometry" />
40
+ <mxCell id="scope-project" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;PROJECT-LOCAL · TEAM&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;This project • .pi/settings.json&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;pi install npm:@senad-d/drawme -l&lt;/font&gt;" 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="13" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;PROJECT-LOCAL · TEAM&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Saved in .pi/settings.json&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;pi install npm:@senad-d/drawme -l&lt;/font&gt;" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="10">
42
- <mxGeometry x="650" y="180" width="500" height="115" as="geometry" />
43
+ <mxCell id="scope-trial" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;ONE-TIME TRIAL&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Current run only • no settings change&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;pi -e npm:@senad-d/drawme&lt;/font&gt;" 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="14" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;ONE-TIME TRIAL&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Temporary for the current run&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;pi -e npm:@senad-d/drawme&lt;/font&gt;" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="10">
45
- <mxGeometry x="1230" y="180" width="500" height="115" as="geometry" />
46
+ <mxCell id="install-source" value="&lt;b&gt;PIN OR DEVELOP&lt;/b&gt;&lt;br&gt;Pinned npm: &lt;font face=&quot;Courier New&quot;&gt;npm:@senad-d/drawme@&amp;lt;version&amp;gt;&lt;/font&gt; • Git: &lt;font face=&quot;Courier New&quot;&gt;git:github.com/senad-d/DrawMe@&amp;lt;tag&amp;gt;&lt;/font&gt;&lt;br&gt;Source checkout: &lt;font face=&quot;Courier New&quot;&gt;npm ci --ignore-scripts&lt;/font&gt; → &lt;font face=&quot;Courier New&quot;&gt;npm run validate&lt;/font&gt; → &lt;font face=&quot;Courier New&quot;&gt;pi --no-extensions -e .&lt;/font&gt;" 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="15" value="Source checkout: &lt;font face=&quot;Courier New&quot;&gt;cd /path/to/DrawMe &amp;&amp; pi --no-extensions -e .&lt;/font&gt;" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;fontSize=13;fontColor=#405466;fillColor=#F3F6F8;strokeColor=#AAB7C4;dashed=1;" vertex="1" parent="10">
48
- <mxGeometry x="300" y="310" width="1200" height="35" as="geometry" />
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="16" value="↓" style="text;html=1;align=center;verticalAlign=middle;fontSize=24;fontStyle=1;fontColor=#1F4E78;" vertex="1" parent="1">
51
- <mxGeometry x="880" y="750" width="120" height="30" as="geometry" />
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="17" value="3 LOAD, VERIFY, AND CREATE YOUR FIRST DIAGRAM" style="swimlane;horizontal=1;startSize=46;rounded=1;arcSize=8;container=1;pointerEvents=0;html=1;fontSize=17;fontStyle=1;fontColor=#FFFFFF;fillColor=#1F4E78;swimlaneFillColor=#F8FBFF;strokeColor=#6C8EBF;strokeWidth=2;" vertex="1" parent="1">
54
- <mxGeometry x="40" y="780" width="1800" height="300" as="geometry" />
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
- <mxCell id="18" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;LOAD&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Start or restart Pi&lt;br&gt;Already running? Use &lt;font face=&quot;Courier New&quot;&gt;/reload&lt;/font&gt;" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="17">
57
- <mxGeometry x="60" y="85" width="330" height="150" as="geometry" />
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="19" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;VERIFY&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;/drawme-check&lt;/font&gt;&lt;br&gt;Expect a CLI path and version" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="17">
60
- <mxGeometry x="500" y="85" width="330" height="150" as="geometry" />
62
+ <mxCell id="use-load" value="&lt;b&gt;&lt;font color=&quot;#674274&quot;&gt;01 · LOAD&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Start Pi after installation&lt;br&gt;Already open? Use &lt;font face=&quot;Courier New&quot;&gt;/reload&lt;/font&gt;" 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="20" value="&lt;b&gt;&lt;font color=&quot;#1F4E78&quot;&gt;CREATE&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;/drawme Create a login flow&lt;/font&gt;&lt;br&gt;Describe any diagram in plain language" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=12;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="17">
63
- <mxGeometry x="940" y="85" width="330" height="150" as="geometry" />
65
+ <mxCell id="use-verify" value="&lt;b&gt;&lt;font color=&quot;#674274&quot;&gt;02 · VERIFY&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;/drawme-check&lt;/font&gt;&lt;br&gt;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="21" value="&lt;b&gt;&lt;font color=&quot;#2D5E36&quot;&gt;DONE&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Receive an editable .drawio source&lt;br&gt;plus PNG by default" 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="17">
66
- <mxGeometry x="1380" y="85" width="330" height="150" as="geometry" />
68
+ <mxCell id="use-describe" value="&lt;b&gt;&lt;font color=&quot;#674274&quot;&gt;03 · DESCRIBE&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;/drawme a login flow with retry&lt;/font&gt;&lt;br&gt;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="22" value="TROUBLESHOOTING, TRUST, AND VERSION NOTES" style="swimlane;horizontal=1;startSize=42;rounded=1;arcSize=8;container=1;pointerEvents=0;html=1;fontSize=16;fontStyle=1;fontColor=#FFFFFF;fillColor=#405466;swimlaneFillColor=#F8FAFB;strokeColor=#7E8E9E;strokeWidth=2;" vertex="1" parent="1">
69
- <mxGeometry x="40" y="1110" width="1800" height="180" as="geometry" />
71
+ <mxCell id="use-autonomous" value="&lt;b&gt;&lt;font color=&quot;#674274&quot;&gt;04 · AUTONOMOUS RUN&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;plan → author → validate → critique&lt;br&gt;refine (≤5) → confirm → export&lt;br&gt;&lt;font color=&quot;#6B7C8A&quot;&gt;no approval pause&lt;/font&gt;" 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="23" value="&lt;b&gt;CLI NOT FOUND?&lt;/b&gt;&lt;br&gt;Install draw.io Desktop, keep its standard install path, then run &lt;font face=&quot;Courier New&quot;&gt;/drawme-check&lt;/font&gt; again. v30+ is needed only for Mermaid and ELK layout." style="rounded=1;arcSize=8;whiteSpace=wrap;html=1;align=left;verticalAlign=middle;spacing=12;fontSize=13;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#AAB7C4;" vertex="1" parent="22">
72
- <mxGeometry x="30" y="60" width="550" height="95" as="geometry" />
74
+ <mxCell id="use-delivered" value="&lt;b&gt;&lt;font color=&quot;#2D5E36&quot;&gt;05 · DELIVERED&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Editable .drawio source&lt;br&gt;PNG by default&lt;br&gt;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="24" value="&lt;b&gt;EXTENSION NOT VISIBLE?&lt;/b&gt;&lt;br&gt;Run &lt;font face=&quot;Courier New&quot;&gt;pi list&lt;/font&gt;, check &lt;font face=&quot;Courier New&quot;&gt;pi config&lt;/font&gt;, and use &lt;font face=&quot;Courier New&quot;&gt;/reload&lt;/font&gt;. Project-local packages load only after the project is trusted." style="rounded=1;arcSize=8;whiteSpace=wrap;html=1;align=left;verticalAlign=middle;spacing=12;fontSize=13;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#AAB7C4;" vertex="1" parent="22">
75
- <mxGeometry x="625" y="60" width="550" height="95" as="geometry" />
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="25" value="&lt;b&gt;INSTALL TRUSTED CODE ONLY&lt;/b&gt;&lt;br&gt;Pi extensions inherit the Pi process permissions, so review sources 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=12;fontSize=13;fontColor=#2D5E36;fillColor=#F3F9F1;strokeColor=#82B366;" vertex="1" parent="22">
78
- <mxGeometry x="1220" y="60" width="550" height="95" as="geometry" />
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="26" 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="1" source="11" target="12">
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="27" 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="1" source="11" target="13">
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
- <mxCell id="28" 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="1" source="11" target="14">
87
- <mxGeometry relative="1" as="geometry" />
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="29" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=blockThin;endFill=1;strokeColor=#1F4E78;strokeWidth=2;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="1" source="18" target="19">
90
- <mxGeometry relative="1" as="geometry" />
93
+ <mxCell id="support-cli" value="&lt;b&gt;CLI NOT FOUND?&lt;/b&gt;&lt;br&gt;&lt;br&gt;Install draw.io Desktop at a standard path, then rerun &lt;font face=&quot;Courier New&quot;&gt;/drawme-check&lt;/font&gt;. 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="30" value="CLI detected" 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=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="1" source="19" target="20">
93
- <mxGeometry relative="1" as="geometry" />
96
+ <mxCell id="support-package" value="&lt;b&gt;PACKAGE NOT VISIBLE?&lt;/b&gt;&lt;br&gt;&lt;br&gt;Run &lt;font face=&quot;Courier New&quot;&gt;pi list&lt;/font&gt;, check &lt;font face=&quot;Courier New&quot;&gt;pi config&lt;/font&gt;, and use &lt;font face=&quot;Courier New&quot;&gt;/reload&lt;/font&gt;. 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="31" value="produces" 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="1" source="20" target="21">
96
- <mxGeometry relative="1" as="geometry" />
99
+ <mxCell id="support-trust" value="&lt;b&gt;&lt;font color=&quot;#9A5B13&quot;&gt;INSTALL TRUSTED CODE ONLY&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senad-d/drawme",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Pi extension for authoring, validating, and exporting editable draw.io diagrams from natural-language descriptions.",
5
5
  "type": "module",
6
6
  "license": "MIT",
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 preview vs final export, the vision width cap, `-e` PNG
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
- /** Preview artifacts for this source that were removed after a successful final export. */
166
+ /** Superseded preview artifacts removed after this successful preview or final export. */
167
167
  removedPreviews: string[];
168
- /** Best-effort cleanup failures; the final export itself still succeeded. */
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
- function trackPreview(input: string, output: string): void {
185
- const previews = previewOutputs.get(sourceKey(input)) ?? new Map<string, string>();
186
- previews.set(resolve(output), output);
187
- previewOutputs.set(sourceKey(input), previews);
186
+ interface PreviewCleanup {
187
+ removed: string[];
188
+ warnings: string[];
188
189
  }
189
190
 
190
- async function removeTrackedPreviews(
191
- input: string,
192
- finalOutput: string,
193
- ): Promise<{ removed: string[]; warnings: string[] }> {
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 === "final" ? await removeTrackedPreviews(plan.input, plan.output) : { removed: [], warnings: [] };
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,
@@ -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
+ }