@senad-d/drawme 0.1.4 → 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,105 +1,133 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
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 an approval-gated, editable .drawio export" 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="LOCAL RENDERING • HUMAN APPROVAL • EDITABLE" 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: prefer .deb / .rpm • Windows: official installer" 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;USER SCOPE · DEFAULT&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Writes ~/.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=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;Writes .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;No settings change; current run only&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="Git / pinned: &lt;font face=&quot;Courier New&quot;&gt;pi install git:senad-d/DrawMe@&amp;lt;tag&amp;gt;&lt;/font&gt; • Checkout: &lt;font face=&quot;Courier New&quot;&gt;npm ci --ignore-scripts &amp;&amp; npm run validate &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="200" y="310" width="1400" 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, CREATE, AND APPROVE" 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=10;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="17">
57
- <mxGeometry x="40" y="85" width="300" 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 path, version, and v30+ support" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=10;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="17">
60
- <mxGeometry x="390" y="85" width="300" 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;Agent authors, validates, and previews" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=10;fontSize=14;fontColor=#263746;fillColor=#FFFFFF;strokeColor=#6C8EBF;strokeWidth=2;shadow=1;" vertex="1" parent="17">
63
- <mxGeometry x="740" y="85" width="300" 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;#1F4E78&quot;&gt;REVIEW &amp;amp; APPROVE&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Inspect the holistic preview&lt;br&gt;Request changes or explicitly approve" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=10;fontSize=14;fontColor=#263746;fillColor=#FFF7E6;strokeColor=#D6B656;strokeWidth=2;shadow=1;" vertex="1" parent="17">
66
- <mxGeometry x="1090" y="85" width="300" 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="32" value="&lt;b&gt;&lt;font color=&quot;#2D5E36&quot;&gt;DONE&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 on request" style="rounded=1;arcSize=10;whiteSpace=wrap;html=1;align=center;verticalAlign=middle;spacing=10;fontSize=14;fontColor=#263746;fillColor=#EAF4E8;strokeColor=#82B366;strokeWidth=2;shadow=1;" vertex="1" parent="17">
69
- <mxGeometry x="1440" y="85" width="300" height="150" 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="22" value="TROUBLESHOOTING, TRUST, AND COMPATIBILITY" 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">
72
- <mxGeometry x="40" y="1110" width="1800" height="180" 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="23" value="&lt;b&gt;CLI NOT FOUND?&lt;/b&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 still work without it; v30+ only gates 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">
75
- <mxGeometry x="30" 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="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">
78
- <mxGeometry x="625" 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="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">
81
- <mxGeometry x="1220" y="60" width="550" height="95" 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="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">
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="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">
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="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">
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="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">
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="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">
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"/>
97
101
  </mxCell>
98
- <mxCell id="31" value="preview ready" 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="20" target="21">
99
- <mxGeometry relative="1" as="geometry" />
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"/>
100
104
  </mxCell>
101
- <mxCell id="33" value="approved" 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="21" target="32">
102
- <mxGeometry relative="1" as="geometry" />
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"/>
103
131
  </mxCell>
104
132
  </root>
105
133
  </mxGraphModel>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senad-d/drawme",
3
- "version": "0.1.4",
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",
@@ -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
+ }