@littledragon_wxl/drawio-style-graph 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/README_zh.md +25 -0
- package/SKILL.md +30 -3
- package/package.json +1 -2
- package/scripts/autolayout.py +6 -6
- package/scripts/open_drawio.py +148 -0
package/README.md
CHANGED
|
@@ -78,6 +78,31 @@ Each style is a complete design system mapped to draw.io `style=` token strings:
|
|
|
78
78
|
|
|
79
79
|
## Quick Start
|
|
80
80
|
|
|
81
|
+
### Install
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npx skills add Littledragon-wxl/drawio-style-graph
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Or via npm:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npm install @littledragon_wxl/drawio-style-graph
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Update to Latest Version
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Using npm
|
|
97
|
+
npm update @littledragon_wxl/drawio-style-graph
|
|
98
|
+
|
|
99
|
+
# Or reinstall to latest
|
|
100
|
+
npm install @littledragon_wxl/drawio-style-graph@latest
|
|
101
|
+
|
|
102
|
+
# Check current version
|
|
103
|
+
npm list @littledragon_wxl/drawio-style-graph
|
|
104
|
+
```
|
|
105
|
+
|
|
81
106
|
### Prerequisites
|
|
82
107
|
|
|
83
108
|
1. Install draw.io desktop: [download](https://github.com/jgraph/drawio-desktop/releases)
|
package/README_zh.md
CHANGED
|
@@ -78,6 +78,31 @@ fireworks-tech-graph drawio-skill
|
|
|
78
78
|
|
|
79
79
|
## 快速开始
|
|
80
80
|
|
|
81
|
+
### 安装
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npx skills add Littledragon-wxl/drawio-style-graph
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
或通过 npm:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npm install @littledragon_wxl/drawio-style-graph
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 更新到最新版本
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# 使用 npm 更新
|
|
97
|
+
npm update @littledragon_wxl/drawio-style-graph
|
|
98
|
+
|
|
99
|
+
# 或重新安装最新版本
|
|
100
|
+
npm install @littledragon_wxl/drawio-style-graph@latest
|
|
101
|
+
|
|
102
|
+
# 查看当前版本
|
|
103
|
+
npm list @littledragon_wxl/drawio-style-graph
|
|
104
|
+
```
|
|
105
|
+
|
|
81
106
|
### 前置条件
|
|
82
107
|
|
|
83
108
|
1. 安装 draw.io 桌面版:[下载](https://github.com/jgraph/drawio-desktop/releases)
|
package/SKILL.md
CHANGED
|
@@ -18,7 +18,7 @@ description: >-
|
|
|
18
18
|
or mermaid/plantuml code blocks.
|
|
19
19
|
license: MIT
|
|
20
20
|
homepage: https://github.com/Agents365-ai/drawio-style-graph
|
|
21
|
-
install: npx skills add
|
|
21
|
+
install: npx skills add Littledragon-wxl/drawio-style-graph
|
|
22
22
|
compatibility: >-
|
|
23
23
|
Requires draw.io desktop app CLI on PATH (macOS/Linux/Windows) for export.
|
|
24
24
|
Core .drawio generation needs Python 3 only.
|
|
@@ -38,13 +38,13 @@ exported file in draw.io recovers the editable diagram.
|
|
|
38
38
|
## Install
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
npx skills add
|
|
41
|
+
npx skills add Littledragon-wxl/drawio-style-graph
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Or directly from npm:
|
|
45
45
|
|
|
46
46
|
```bash
|
|
47
|
-
npm install @
|
|
47
|
+
npm install @littledragon_wxl/drawio-style-graph
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
No other skills required — everything is self-contained.
|
|
@@ -305,6 +305,33 @@ python3 scripts/encode_drawio_url.py diagram.drawio # viewer
|
|
|
305
305
|
python3 scripts/encode_drawio_url.py --edit diagram.drawio # editor
|
|
306
306
|
```
|
|
307
307
|
|
|
308
|
+
### Optional: Preview in draw.io Browser
|
|
309
|
+
|
|
310
|
+
To open the generated `.drawio` file for live editing and preview in draw.io, use the
|
|
311
|
+
built-in preview script:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
# Opens in native draw.io desktop app (preferred if installed)
|
|
315
|
+
python3 scripts/open_drawio.py diagram.drawio
|
|
316
|
+
|
|
317
|
+
# Or force browser editor mode
|
|
318
|
+
python3 scripts/open_drawio.py diagram.drawio --edit
|
|
319
|
+
|
|
320
|
+
# Or force browser-based preview (if desktop app unavailable)
|
|
321
|
+
python3 scripts/open_drawio.py diagram.drawio --browser
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
**Supported platforms:**
|
|
325
|
+
- **macOS:** Automatically detects `/Applications/draw.io.app`
|
|
326
|
+
- **Windows:** Looks for `C:\Program Files\draw.io\draw.io.exe`
|
|
327
|
+
- **Linux:** Uses `drawio` command if in PATH
|
|
328
|
+
- **Browser fallback:** Generates a diagrams.net URL if desktop app unavailable
|
|
329
|
+
|
|
330
|
+
**Behind the scenes:**
|
|
331
|
+
1. Tries to open with the native draw.io app first (fastest, no browser needed)
|
|
332
|
+
2. Falls back to generating a diagrams.net URL if app not found
|
|
333
|
+
3. Automatically opens your default browser with the sharable URL
|
|
334
|
+
|
|
308
335
|
## Draw.io XML Quick Reference
|
|
309
336
|
|
|
310
337
|
### Vertex (Shape)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@littledragon_wxl/drawio-style-graph",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Generate .drawio diagrams with 8 professional visual styles. Self-contained — no external skill dependencies.",
|
|
5
5
|
"main": "SKILL.md",
|
|
6
6
|
"keywords": [
|
|
@@ -40,4 +40,3 @@
|
|
|
40
40
|
"node": ">=14.0.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
|
package/scripts/autolayout.py
CHANGED
|
@@ -305,13 +305,13 @@ def to_drawio(graph, height, pos, edge_pts, color=True):
|
|
|
305
305
|
f" </mxCell>"
|
|
306
306
|
)
|
|
307
307
|
return (
|
|
308
|
-
'
|
|
309
|
-
'
|
|
310
|
-
'
|
|
311
|
-
'
|
|
308
|
+
'<?xml version="1.0" encoding="UTF-8"?>\n'
|
|
309
|
+
'<mxfile host="drawio" version="26.0.0">\n'
|
|
310
|
+
' <diagram name="Page-1">\n'
|
|
311
|
+
' <mxGraphModel>\n'
|
|
312
312
|
" <root>\n"
|
|
313
|
-
' <mxCell id="0"/>\n'
|
|
314
|
-
' <mxCell id="1" parent="0"/>\n'
|
|
313
|
+
' <mxCell id="0" />\n'
|
|
314
|
+
' <mxCell id="1" parent="0" />\n'
|
|
315
315
|
+ "\n".join(cells)
|
|
316
316
|
+ "\n </root>\n </mxGraphModel>\n </diagram>\n</mxfile>\n"
|
|
317
317
|
)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Open a .drawio file in the native draw.io application or browser.
|
|
3
|
+
|
|
4
|
+
Automatically detects the draw.io desktop app across platforms (macOS/Windows/Linux)
|
|
5
|
+
and opens the file. Falls back to generating a diagrams.net URL if the app is unavailable.
|
|
6
|
+
|
|
7
|
+
Usage: python3 open_drawio.py diagram.drawio
|
|
8
|
+
python3 open_drawio.py diagram.drawio --edit
|
|
9
|
+
python3 open_drawio.py diagram.drawio --browser
|
|
10
|
+
"""
|
|
11
|
+
import argparse
|
|
12
|
+
import os
|
|
13
|
+
import platform
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def find_drawio_app():
|
|
20
|
+
"""Detect the draw.io desktop app path across platforms."""
|
|
21
|
+
system = platform.system()
|
|
22
|
+
|
|
23
|
+
if system == "Darwin": # macOS
|
|
24
|
+
app_path = Path("/Applications/draw.io.app/Contents/MacOS/draw.io")
|
|
25
|
+
if app_path.exists():
|
|
26
|
+
return str(app_path)
|
|
27
|
+
elif system == "Windows":
|
|
28
|
+
# Try default installation paths
|
|
29
|
+
paths = [
|
|
30
|
+
Path("C:/Program Files/draw.io/draw.io.exe"),
|
|
31
|
+
Path("C:/Program Files (x86)/draw.io/draw.io.exe"),
|
|
32
|
+
]
|
|
33
|
+
for p in paths:
|
|
34
|
+
if p.exists():
|
|
35
|
+
return str(p)
|
|
36
|
+
elif system == "Linux":
|
|
37
|
+
# Try common Linux paths and PATH
|
|
38
|
+
if subprocess.run(["which", "drawio"], capture_output=True).returncode == 0:
|
|
39
|
+
return "drawio"
|
|
40
|
+
if subprocess.run(["which", "draw.io"], capture_output=True).returncode == 0:
|
|
41
|
+
return "draw.io"
|
|
42
|
+
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def open_with_desktop_app(file_path):
|
|
47
|
+
"""Open .drawio file in the native draw.io desktop app."""
|
|
48
|
+
app = find_drawio_app()
|
|
49
|
+
if not app:
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
system = platform.system()
|
|
54
|
+
if system == "Darwin": # macOS
|
|
55
|
+
subprocess.Popen(["open", "-a", "draw.io", file_path])
|
|
56
|
+
elif system == "Windows":
|
|
57
|
+
subprocess.Popen([app, file_path])
|
|
58
|
+
else: # Linux
|
|
59
|
+
subprocess.Popen([app, file_path])
|
|
60
|
+
return True
|
|
61
|
+
except Exception as e:
|
|
62
|
+
print(f"Failed to open with desktop app: {e}", file=sys.stderr)
|
|
63
|
+
return False
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def open_with_browser(file_path, edit_mode=False):
|
|
67
|
+
"""Generate a diagrams.net URL and open in browser."""
|
|
68
|
+
try:
|
|
69
|
+
# Use encode_drawio_url.py to generate the URL
|
|
70
|
+
args = ["python3", "scripts/encode_drawio_url.py"]
|
|
71
|
+
if edit_mode:
|
|
72
|
+
args.append("--edit")
|
|
73
|
+
args.append(file_path)
|
|
74
|
+
|
|
75
|
+
result = subprocess.run(args, capture_output=True, text=True, timeout=15)
|
|
76
|
+
if result.returncode != 0:
|
|
77
|
+
print(f"Failed to generate URL: {result.stderr}", file=sys.stderr)
|
|
78
|
+
return False
|
|
79
|
+
|
|
80
|
+
url = result.stdout.strip()
|
|
81
|
+
if not url:
|
|
82
|
+
print("No URL generated", file=sys.stderr)
|
|
83
|
+
return False
|
|
84
|
+
|
|
85
|
+
# Open in default browser
|
|
86
|
+
webbrowser_cmd = None
|
|
87
|
+
system = platform.system()
|
|
88
|
+
if system == "Darwin": # macOS
|
|
89
|
+
webbrowser_cmd = ["open", url]
|
|
90
|
+
elif system == "Windows":
|
|
91
|
+
webbrowser_cmd = ["cmd", "/c", f'start "" "{url}"']
|
|
92
|
+
else: # Linux
|
|
93
|
+
webbrowser_cmd = ["xdg-open", url]
|
|
94
|
+
|
|
95
|
+
if webbrowser_cmd:
|
|
96
|
+
subprocess.Popen(webbrowser_cmd)
|
|
97
|
+
print(f"Opened in browser: {url[:80]}...", file=sys.stderr)
|
|
98
|
+
return True
|
|
99
|
+
except Exception as e:
|
|
100
|
+
print(f"Failed to open in browser: {e}", file=sys.stderr)
|
|
101
|
+
return False
|
|
102
|
+
|
|
103
|
+
return False
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def main():
|
|
107
|
+
ap = argparse.ArgumentParser(
|
|
108
|
+
description="Open a .drawio file in draw.io (desktop or browser).",
|
|
109
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
110
|
+
epilog="""
|
|
111
|
+
Examples:
|
|
112
|
+
python3 open_drawio.py diagram.drawio # Opens in desktop app (preferred)
|
|
113
|
+
python3 open_drawio.py diagram.drawio --edit # Opens in browser editor mode
|
|
114
|
+
python3 open_drawio.py diagram.drawio --browser # Force browser (diagrams.net)
|
|
115
|
+
""",
|
|
116
|
+
)
|
|
117
|
+
ap.add_argument("file", help=".drawio file path")
|
|
118
|
+
ap.add_argument(
|
|
119
|
+
"--edit",
|
|
120
|
+
action="store_true",
|
|
121
|
+
help="Open in edit mode (browser only)",
|
|
122
|
+
)
|
|
123
|
+
ap.add_argument(
|
|
124
|
+
"--browser",
|
|
125
|
+
action="store_true",
|
|
126
|
+
help="Force opening in browser (skip desktop app)",
|
|
127
|
+
)
|
|
128
|
+
args = ap.parse_args()
|
|
129
|
+
|
|
130
|
+
file_path = Path(args.file)
|
|
131
|
+
if not file_path.exists():
|
|
132
|
+
sys.exit(f"error: file not found: {args.file}")
|
|
133
|
+
|
|
134
|
+
if not args.browser:
|
|
135
|
+
# Try desktop app first
|
|
136
|
+
if open_with_desktop_app(str(file_path)):
|
|
137
|
+
print(f"Opened in draw.io desktop app: {file_path}", file=sys.stderr)
|
|
138
|
+
return
|
|
139
|
+
|
|
140
|
+
# Fallback to browser
|
|
141
|
+
if open_with_browser(str(file_path), edit_mode=args.edit):
|
|
142
|
+
return
|
|
143
|
+
|
|
144
|
+
sys.exit("error: could not open .drawio file (no draw.io app or browser available)")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
if __name__ == "__main__":
|
|
148
|
+
main()
|