quilr-cli-bridge 0.1.0__py3-none-any.whl
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.
- quilr_cli_bridge/__init__.py +3 -0
- quilr_cli_bridge/__main__.py +21 -0
- quilr_cli_bridge/_vendor/LICENSE +201 -0
- quilr_cli_bridge/_vendor/__init__.py +0 -0
- quilr_cli_bridge/_vendor/drawio/README.md +84 -0
- quilr_cli_bridge/_vendor/drawio/__init__.py +1 -0
- quilr_cli_bridge/_vendor/drawio/core/__init__.py +0 -0
- quilr_cli_bridge/_vendor/drawio/core/connectors.py +124 -0
- quilr_cli_bridge/_vendor/drawio/core/export.py +130 -0
- quilr_cli_bridge/_vendor/drawio/core/pages.py +59 -0
- quilr_cli_bridge/_vendor/drawio/core/project.py +122 -0
- quilr_cli_bridge/_vendor/drawio/core/session.py +202 -0
- quilr_cli_bridge/_vendor/drawio/core/shapes.py +172 -0
- quilr_cli_bridge/_vendor/drawio/drawio_cli.py +811 -0
- quilr_cli_bridge/_vendor/drawio/skills/SKILL.md +214 -0
- quilr_cli_bridge/_vendor/drawio/utils/__init__.py +0 -0
- quilr_cli_bridge/_vendor/drawio/utils/drawio_backend.py +145 -0
- quilr_cli_bridge/_vendor/drawio/utils/drawio_xml.py +532 -0
- quilr_cli_bridge/_vendor/drawio/utils/repl_skin.py +567 -0
- quilr_cli_bridge/_vendor/harnesses.json +14 -0
- quilr_cli_bridge/click_tools.py +347 -0
- quilr_cli_bridge/harnesses.py +146 -0
- quilr_cli_bridge/stdio.py +100 -0
- quilr_cli_bridge/workspace.py +35 -0
- quilr_cli_bridge-0.1.0.dist-info/METADATA +98 -0
- quilr_cli_bridge-0.1.0.dist-info/RECORD +30 -0
- quilr_cli_bridge-0.1.0.dist-info/WHEEL +4 -0
- quilr_cli_bridge-0.1.0.dist-info/entry_points.txt +2 -0
- quilr_cli_bridge-0.1.0.dist-info/licenses/NOTICE +8 -0
- quilr_cli_bridge-0.1.0.dist-info/licenses/src/quilr_cli_bridge/_vendor/LICENSE +201 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""python -m quilr_cli_bridge <harness>"""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main() -> None:
|
|
7
|
+
if len(sys.argv) != 2:
|
|
8
|
+
raise SystemExit("usage: python -m quilr_cli_bridge <harness>")
|
|
9
|
+
from .stdio import private_stdout
|
|
10
|
+
|
|
11
|
+
out = private_stdout()
|
|
12
|
+
from . import harnesses
|
|
13
|
+
from .stdio import Server, serve
|
|
14
|
+
from .workspace import Workspace
|
|
15
|
+
|
|
16
|
+
harness = harnesses.load(sys.argv[1])
|
|
17
|
+
serve(Server(harness, Workspace(), harnesses.instructions(harness)), out)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if __name__ == "__main__":
|
|
21
|
+
main()
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [HKUDS CLI-Anything Team]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
File without changes
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# cli-anything-drawio
|
|
2
|
+
|
|
3
|
+
A CLI harness for **Draw.io** — create, edit, and export diagrams from the command line.
|
|
4
|
+
|
|
5
|
+
Designed for AI agents and power users who need to generate diagrams programmatically.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- **Python 3.10+**
|
|
10
|
+
- **draw.io desktop app** (for PNG/PDF/SVG export):
|
|
11
|
+
- macOS: `brew install --cask drawio`
|
|
12
|
+
- Linux: `snap install drawio`
|
|
13
|
+
- Windows: `winget install JGraph.Draw`
|
|
14
|
+
|
|
15
|
+
Note: The CLI can create and manipulate `.drawio` files without the desktop app installed. The app is only needed for rasterized export (PNG, PDF, SVG).
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
cd drawio/agent-harness
|
|
21
|
+
pip install -e .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### One-shot commands
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Create a new diagram
|
|
30
|
+
cli-anything-drawio project new --preset letter -o diagram.drawio
|
|
31
|
+
|
|
32
|
+
# Add shapes
|
|
33
|
+
cli-anything-drawio --project diagram.drawio shape add rectangle --label "Server"
|
|
34
|
+
cli-anything-drawio --project diagram.drawio shape add cylinder --label "Database" --x 300 --y 100
|
|
35
|
+
|
|
36
|
+
# Connect shapes
|
|
37
|
+
cli-anything-drawio --project diagram.drawio connect add <source_id> <target_id>
|
|
38
|
+
|
|
39
|
+
# Export
|
|
40
|
+
cli-anything-drawio --project diagram.drawio export render output.png -f png
|
|
41
|
+
cli-anything-drawio --project diagram.drawio export render output.svg -f svg
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### JSON mode (for AI agents)
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
cli-anything-drawio --json project new -o diagram.drawio
|
|
48
|
+
cli-anything-drawio --json --project diagram.drawio shape add rectangle --label "API"
|
|
49
|
+
cli-anything-drawio --json --project diagram.drawio shape list
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Interactive REPL
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
cli-anything-drawio
|
|
56
|
+
# or
|
|
57
|
+
cli-anything-drawio repl --project diagram.drawio
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Command Reference
|
|
61
|
+
|
|
62
|
+
| Group | Command | Description |
|
|
63
|
+
|-------|---------|-------------|
|
|
64
|
+
| `project` | `new`, `open`, `save`, `info`, `xml`, `presets` | Project lifecycle |
|
|
65
|
+
| `shape` | `add`, `remove`, `list`, `label`, `move`, `resize`, `style`, `info`, `types` | Shape operations |
|
|
66
|
+
| `connect` | `add`, `remove`, `label`, `style`, `list`, `styles` | Connector operations |
|
|
67
|
+
| `page` | `add`, `remove`, `rename`, `list` | Multi-page management |
|
|
68
|
+
| `export` | `render`, `formats` | Export to PNG/PDF/SVG/XML |
|
|
69
|
+
| `session` | `status`, `undo`, `redo`, `save-state`, `list` | Session management |
|
|
70
|
+
|
|
71
|
+
## Shape Types
|
|
72
|
+
|
|
73
|
+
rectangle, rounded, ellipse, diamond, triangle, hexagon, cylinder, cloud, parallelogram, process, document, callout, note, actor, text
|
|
74
|
+
|
|
75
|
+
## Edge Styles
|
|
76
|
+
|
|
77
|
+
straight, orthogonal, curved, entity-relation
|
|
78
|
+
|
|
79
|
+
## Running Tests
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
cd drawio/agent-harness
|
|
83
|
+
python3 -m pytest cli_anything/drawio/tests/ -v
|
|
84
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Draw.io CLI package."""
|
|
File without changes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""Connector (edge) operations: add, remove, modify, list."""
|
|
2
|
+
|
|
3
|
+
from ..utils import drawio_xml
|
|
4
|
+
from .session import Session
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def list_connectors(session: Session, diagram_index: int = 0) -> list[dict]:
|
|
8
|
+
"""List all connectors (edges) on a page."""
|
|
9
|
+
if not session.is_open:
|
|
10
|
+
raise RuntimeError("No project is open")
|
|
11
|
+
cells = drawio_xml.get_edges(session.root, diagram_index)
|
|
12
|
+
return [drawio_xml.get_cell_info(c) for c in cells]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def add_connector(session: Session, source_id: str, target_id: str,
|
|
16
|
+
edge_style: str = "orthogonal", label: str = "",
|
|
17
|
+
diagram_index: int = 0, edge_id: str = None) -> dict:
|
|
18
|
+
"""Add a connector between two shapes.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
session: Active session.
|
|
22
|
+
source_id: Source shape cell ID.
|
|
23
|
+
target_id: Target shape cell ID.
|
|
24
|
+
edge_style: Edge style preset (straight, orthogonal, curved,
|
|
25
|
+
entity-relation) or raw style string.
|
|
26
|
+
label: Optional label on the edge.
|
|
27
|
+
edge_id: Optional custom ID. Auto-generated if not provided.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
Dict with action and new edge info.
|
|
31
|
+
"""
|
|
32
|
+
if not session.is_open:
|
|
33
|
+
raise RuntimeError("No project is open")
|
|
34
|
+
|
|
35
|
+
# Validate source and target exist
|
|
36
|
+
if drawio_xml.find_cell_by_id(session.root, source_id, diagram_index) is None:
|
|
37
|
+
raise ValueError(f"Source cell not found: {source_id}")
|
|
38
|
+
if drawio_xml.find_cell_by_id(session.root, target_id, diagram_index) is None:
|
|
39
|
+
raise ValueError(f"Target cell not found: {target_id}")
|
|
40
|
+
|
|
41
|
+
if edge_id is not None and drawio_xml.find_cell_by_id(session.root, edge_id, diagram_index) is not None:
|
|
42
|
+
raise ValueError(f"Cell ID already exists: {edge_id}")
|
|
43
|
+
|
|
44
|
+
session.checkpoint()
|
|
45
|
+
edge_id = drawio_xml.add_edge(
|
|
46
|
+
session.root, source_id, target_id, edge_style, label,
|
|
47
|
+
diagram_index=diagram_index, edge_id=edge_id,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
"action": "add_connector",
|
|
52
|
+
"id": edge_id,
|
|
53
|
+
"source": source_id,
|
|
54
|
+
"target": target_id,
|
|
55
|
+
"style": edge_style,
|
|
56
|
+
"label": label,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def remove_connector(session: Session, edge_id: str,
|
|
61
|
+
diagram_index: int = 0) -> dict:
|
|
62
|
+
"""Remove a connector by ID."""
|
|
63
|
+
if not session.is_open:
|
|
64
|
+
raise RuntimeError("No project is open")
|
|
65
|
+
|
|
66
|
+
session.checkpoint()
|
|
67
|
+
found = drawio_xml.remove_cell(session.root, edge_id, diagram_index)
|
|
68
|
+
if not found:
|
|
69
|
+
raise ValueError(f"Connector not found: {edge_id}")
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
"action": "remove_connector",
|
|
73
|
+
"id": edge_id,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def update_connector_label(session: Session, edge_id: str, label: str,
|
|
78
|
+
diagram_index: int = 0) -> dict:
|
|
79
|
+
"""Update a connector's label."""
|
|
80
|
+
if not session.is_open:
|
|
81
|
+
raise RuntimeError("No project is open")
|
|
82
|
+
|
|
83
|
+
session.checkpoint()
|
|
84
|
+
found = drawio_xml.update_cell_label(session.root, edge_id, label, diagram_index)
|
|
85
|
+
if not found:
|
|
86
|
+
raise ValueError(f"Connector not found: {edge_id}")
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
"action": "update_connector_label",
|
|
90
|
+
"id": edge_id,
|
|
91
|
+
"label": label,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def set_connector_style(session: Session, edge_id: str,
|
|
96
|
+
key: str, value: str,
|
|
97
|
+
diagram_index: int = 0) -> dict:
|
|
98
|
+
"""Set a style property on a connector.
|
|
99
|
+
|
|
100
|
+
Common style keys:
|
|
101
|
+
strokeColor, strokeWidth, dashed, endArrow, startArrow,
|
|
102
|
+
edgeStyle, curved, rounded, opacity
|
|
103
|
+
"""
|
|
104
|
+
if not session.is_open:
|
|
105
|
+
raise RuntimeError("No project is open")
|
|
106
|
+
|
|
107
|
+
cell = drawio_xml.find_cell_by_id(session.root, edge_id, diagram_index)
|
|
108
|
+
if cell is None:
|
|
109
|
+
raise ValueError(f"Connector not found: {edge_id}")
|
|
110
|
+
|
|
111
|
+
session.checkpoint()
|
|
112
|
+
drawio_xml.set_style_property(cell, key, value)
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
"action": "set_connector_style",
|
|
116
|
+
"id": edge_id,
|
|
117
|
+
"key": key,
|
|
118
|
+
"value": value,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def list_edge_styles() -> dict:
|
|
123
|
+
"""List all available edge style presets."""
|
|
124
|
+
return {name: style for name, style in sorted(drawio_xml.EDGE_STYLES.items())}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Export/render operations: export diagrams to PNG, PDF, SVG."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import tempfile
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from ..utils import drawio_xml
|
|
9
|
+
from ..utils import drawio_backend
|
|
10
|
+
from .session import Session
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Export format configurations
|
|
14
|
+
EXPORT_FORMATS = {
|
|
15
|
+
"png": {"ext": ".png", "description": "PNG image (raster)"},
|
|
16
|
+
"pdf": {"ext": ".pdf", "description": "PDF document"},
|
|
17
|
+
"svg": {"ext": ".svg", "description": "SVG vector image"},
|
|
18
|
+
"vsdx": {"ext": ".vsdx", "description": "Microsoft Visio format"},
|
|
19
|
+
"xml": {"ext": ".xml", "description": "Uncompressed draw.io XML"},
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def list_formats() -> list[dict]:
|
|
24
|
+
"""List all available export formats."""
|
|
25
|
+
return [
|
|
26
|
+
{"name": name, **info}
|
|
27
|
+
for name, info in sorted(EXPORT_FORMATS.items())
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def render(session: Session, output_path: str,
|
|
32
|
+
fmt: str = "png",
|
|
33
|
+
page_index: Optional[int] = None,
|
|
34
|
+
scale: Optional[float] = None,
|
|
35
|
+
width: Optional[int] = None,
|
|
36
|
+
height: Optional[int] = None,
|
|
37
|
+
transparent: bool = False,
|
|
38
|
+
crop: bool = False,
|
|
39
|
+
overwrite: bool = False) -> dict:
|
|
40
|
+
"""Export the current project to a file.
|
|
41
|
+
|
|
42
|
+
This works by:
|
|
43
|
+
1. Saving the project to a temporary .drawio file
|
|
44
|
+
2. Invoking draw.io CLI to render/export
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
session: Active session with an open project.
|
|
48
|
+
output_path: Path for the output file.
|
|
49
|
+
fmt: Export format (png, pdf, svg, vsdx, xml).
|
|
50
|
+
page_index: Page index to export (default: first page).
|
|
51
|
+
scale: Scale factor for PNG export.
|
|
52
|
+
width: Output width in pixels (PNG only).
|
|
53
|
+
height: Output height in pixels (PNG only).
|
|
54
|
+
transparent: Transparent background (PNG only).
|
|
55
|
+
crop: Crop to content.
|
|
56
|
+
overwrite: Overwrite existing output.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
Dict with export results.
|
|
60
|
+
"""
|
|
61
|
+
if not session.is_open:
|
|
62
|
+
raise RuntimeError("No project is open")
|
|
63
|
+
|
|
64
|
+
if fmt not in EXPORT_FORMATS:
|
|
65
|
+
available = ", ".join(sorted(EXPORT_FORMATS.keys()))
|
|
66
|
+
raise ValueError(f"Unknown format: {fmt!r}. Available: {available}")
|
|
67
|
+
|
|
68
|
+
output_path = os.path.abspath(output_path)
|
|
69
|
+
if os.path.exists(output_path) and not overwrite:
|
|
70
|
+
raise FileExistsError(
|
|
71
|
+
f"Output file already exists: {output_path}. Use --overwrite to replace."
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# For XML format, just save the drawio XML directly
|
|
75
|
+
if fmt == "xml":
|
|
76
|
+
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
|
77
|
+
drawio_xml.write_drawio(session.root, output_path)
|
|
78
|
+
return {
|
|
79
|
+
"action": "export",
|
|
80
|
+
"output": output_path,
|
|
81
|
+
"format": "xml",
|
|
82
|
+
"method": "direct-write",
|
|
83
|
+
"file_size": os.path.getsize(output_path),
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# Save to temp file, then invoke draw.io CLI
|
|
87
|
+
with tempfile.NamedTemporaryFile(suffix=".drawio", delete=False, mode="wb") as f:
|
|
88
|
+
temp_path = f.name
|
|
89
|
+
drawio_xml.write_drawio(session.root, temp_path)
|
|
90
|
+
|
|
91
|
+
try:
|
|
92
|
+
result = drawio_backend.export_diagram(
|
|
93
|
+
drawio_path=temp_path,
|
|
94
|
+
output_path=output_path,
|
|
95
|
+
fmt=fmt,
|
|
96
|
+
page_index=page_index,
|
|
97
|
+
scale=scale,
|
|
98
|
+
width=width,
|
|
99
|
+
height=height,
|
|
100
|
+
transparent=transparent,
|
|
101
|
+
crop=crop,
|
|
102
|
+
overwrite=True, # We already checked above
|
|
103
|
+
)
|
|
104
|
+
result["action"] = "export"
|
|
105
|
+
return result
|
|
106
|
+
finally:
|
|
107
|
+
os.unlink(temp_path)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def render_or_save(session: Session, output_path: str,
|
|
111
|
+
fmt: str = "png", **kwargs) -> dict:
|
|
112
|
+
"""Export with fallback: if draw.io CLI is not available, save the .drawio
|
|
113
|
+
file and provide instructions for manual export.
|
|
114
|
+
"""
|
|
115
|
+
try:
|
|
116
|
+
return render(session, output_path, fmt, **kwargs)
|
|
117
|
+
except RuntimeError as e:
|
|
118
|
+
if "not installed" not in str(e):
|
|
119
|
+
raise
|
|
120
|
+
# Fallback: save .drawio and generate instructions
|
|
121
|
+
drawio_path = os.path.splitext(output_path)[0] + ".drawio"
|
|
122
|
+
drawio_xml.write_drawio(session.root, drawio_path)
|
|
123
|
+
return {
|
|
124
|
+
"action": "export_fallback",
|
|
125
|
+
"drawio_file": os.path.abspath(drawio_path),
|
|
126
|
+
"target_output": output_path,
|
|
127
|
+
"target_format": fmt,
|
|
128
|
+
"note": "draw.io CLI not found. Open the .drawio file in draw.io to export manually.",
|
|
129
|
+
"install_hint": str(e),
|
|
130
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Multi-page operations: add, remove, rename, list pages."""
|
|
2
|
+
|
|
3
|
+
from ..utils import drawio_xml
|
|
4
|
+
from .session import Session
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def list_pages(session: Session) -> list[dict]:
|
|
8
|
+
"""List all pages in the diagram."""
|
|
9
|
+
if not session.is_open:
|
|
10
|
+
raise RuntimeError("No project is open")
|
|
11
|
+
return drawio_xml.list_pages(session.root)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def add_page(session: Session, name: str = "",
|
|
15
|
+
page_width: int = 850, page_height: int = 1100) -> dict:
|
|
16
|
+
"""Add a new page to the diagram."""
|
|
17
|
+
if not session.is_open:
|
|
18
|
+
raise RuntimeError("No project is open")
|
|
19
|
+
|
|
20
|
+
session.checkpoint()
|
|
21
|
+
diagram_id = drawio_xml.add_page(session.root, name, page_width, page_height)
|
|
22
|
+
|
|
23
|
+
pages = drawio_xml.list_pages(session.root)
|
|
24
|
+
return {
|
|
25
|
+
"action": "add_page",
|
|
26
|
+
"diagram_id": diagram_id,
|
|
27
|
+
"page_count": len(pages),
|
|
28
|
+
"name": pages[-1]["name"],
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def remove_page(session: Session, page_index: int) -> dict:
|
|
33
|
+
"""Remove a page by index. Cannot remove the last page."""
|
|
34
|
+
if not session.is_open:
|
|
35
|
+
raise RuntimeError("No project is open")
|
|
36
|
+
|
|
37
|
+
session.checkpoint()
|
|
38
|
+
drawio_xml.remove_page(session.root, page_index)
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
"action": "remove_page",
|
|
42
|
+
"removed_index": page_index,
|
|
43
|
+
"page_count": len(session.root.findall("diagram")),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def rename_page(session: Session, page_index: int, name: str) -> dict:
|
|
48
|
+
"""Rename a page."""
|
|
49
|
+
if not session.is_open:
|
|
50
|
+
raise RuntimeError("No project is open")
|
|
51
|
+
|
|
52
|
+
session.checkpoint()
|
|
53
|
+
drawio_xml.rename_page(session.root, page_index, name)
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
"action": "rename_page",
|
|
57
|
+
"page_index": page_index,
|
|
58
|
+
"name": name,
|
|
59
|
+
}
|