excalidraw-render 0.1.0__tar.gz
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.
- excalidraw_render-0.1.0/.github/workflows/ci.yml +43 -0
- excalidraw_render-0.1.0/.gitignore +34 -0
- excalidraw_render-0.1.0/CHANGELOG.md +37 -0
- excalidraw_render-0.1.0/LICENSE +21 -0
- excalidraw_render-0.1.0/PKG-INFO +206 -0
- excalidraw_render-0.1.0/README.md +154 -0
- excalidraw_render-0.1.0/RELEASING.md +88 -0
- excalidraw_render-0.1.0/docs/announcement-drafts.md +171 -0
- excalidraw_render-0.1.0/docs/elements.md +49 -0
- excalidraw_render-0.1.0/docs/hero.png +0 -0
- excalidraw_render-0.1.0/pyproject.toml +86 -0
- excalidraw_render-0.1.0/src/excalidraw_render/__init__.py +5 -0
- excalidraw_render-0.1.0/src/excalidraw_render/_version.py +1 -0
- excalidraw_render-0.1.0/src/excalidraw_render/cli.py +143 -0
- excalidraw_render-0.1.0/src/excalidraw_render/element.py +347 -0
- excalidraw_render-0.1.0/src/excalidraw_render/render.py +169 -0
- excalidraw_render-0.1.0/src/excalidraw_render/renderers/__init__.py +32 -0
- excalidraw_render-0.1.0/src/excalidraw_render/renderers/_util.py +79 -0
- excalidraw_render-0.1.0/src/excalidraw_render/renderers/frame.py +35 -0
- excalidraw_render-0.1.0/src/excalidraw_render/renderers/freedraw.py +65 -0
- excalidraw_render-0.1.0/src/excalidraw_render/renderers/image.py +33 -0
- excalidraw_render-0.1.0/src/excalidraw_render/renderers/linear.py +160 -0
- excalidraw_render-0.1.0/src/excalidraw_render/renderers/shapes.py +77 -0
- excalidraw_render-0.1.0/src/excalidraw_render/renderers/text.py +72 -0
- excalidraw_render-0.1.0/tests/__init__.py +0 -0
- excalidraw_render-0.1.0/tests/fixtures/arrow_with_head.excalidraw +27 -0
- excalidraw_render-0.1.0/tests/fixtures/freedraw_simple.excalidraw +34 -0
- excalidraw_render-0.1.0/tests/fixtures/mixed_scene.excalidraw +44 -0
- excalidraw_render-0.1.0/tests/fixtures/rectangle_basic.excalidraw +25 -0
- excalidraw_render-0.1.0/tests/fixtures/text_in_rectangle.excalidraw +47 -0
- excalidraw_render-0.1.0/tests/test_cli.py +55 -0
- excalidraw_render-0.1.0/tests/test_element.py +161 -0
- excalidraw_render-0.1.0/tests/test_render.py +97 -0
- excalidraw_render-0.1.0/tests/test_smoke.py +10 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
test:
|
|
12
|
+
name: Test (Python ${{ matrix.python-version }})
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
# cairosvg needs libcairo at runtime; ubuntu-latest doesn't have it by default
|
|
23
|
+
- name: Install system libs for cairosvg
|
|
24
|
+
run: sudo apt-get update && sudo apt-get install -y libcairo2
|
|
25
|
+
|
|
26
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
27
|
+
uses: actions/setup-python@v5
|
|
28
|
+
with:
|
|
29
|
+
python-version: ${{ matrix.python-version }}
|
|
30
|
+
cache: pip
|
|
31
|
+
cache-dependency-path: pyproject.toml
|
|
32
|
+
|
|
33
|
+
- name: Install package + dev deps
|
|
34
|
+
run: python -m pip install --upgrade pip && python -m pip install -e ".[dev]"
|
|
35
|
+
|
|
36
|
+
- name: Lint (ruff)
|
|
37
|
+
run: ruff check src tests
|
|
38
|
+
|
|
39
|
+
- name: Type-check (mypy)
|
|
40
|
+
run: mypy src
|
|
41
|
+
|
|
42
|
+
- name: Run tests
|
|
43
|
+
run: pytest -q
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.egg-info/
|
|
6
|
+
.eggs/
|
|
7
|
+
build/
|
|
8
|
+
dist/
|
|
9
|
+
.venv/
|
|
10
|
+
venv/
|
|
11
|
+
|
|
12
|
+
# Coverage / pytest / mypy / ruff
|
|
13
|
+
.coverage
|
|
14
|
+
.coverage.*
|
|
15
|
+
htmlcov/
|
|
16
|
+
.pytest_cache/
|
|
17
|
+
.mypy_cache/
|
|
18
|
+
.ruff_cache/
|
|
19
|
+
coverage.xml
|
|
20
|
+
|
|
21
|
+
# Editors
|
|
22
|
+
.vscode/
|
|
23
|
+
.idea/
|
|
24
|
+
*.swp
|
|
25
|
+
*~
|
|
26
|
+
|
|
27
|
+
# OS
|
|
28
|
+
.DS_Store
|
|
29
|
+
Thumbs.db
|
|
30
|
+
|
|
31
|
+
# Local rendered output
|
|
32
|
+
*.local.png
|
|
33
|
+
*.local.svg
|
|
34
|
+
.scratch/
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-05-29
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial repo scaffold: `pyproject.toml`, package layout (`src/excalidraw_render/`), MIT license, ruff + mypy + pytest config.
|
|
12
|
+
- Typed element model (`element.py`): dataclasses for every common Excalidraw element type with a tolerant JSON parser.
|
|
13
|
+
- Renderers (`renderers/`): SVG output for `rectangle`, `ellipse`, `diamond`, `arrow`, `line`, `text`, `freedraw`, `image`, `frame`.
|
|
14
|
+
- Arrowhead variants: `arrow`, `triangle`, `triangle_outline`, `bar`, `dot`, `diamond`, `diamond_outline`, `crowfoot_one`, `crowfoot_many`, `crowfoot_one_or_many`.
|
|
15
|
+
- Stroke styles: `solid`, `dashed`, `dotted`. Opacity. Element rotation via `angle`.
|
|
16
|
+
- Multi-line text with `text_align` and `vertical_align`, mapped to web-safe font families.
|
|
17
|
+
- Freedraw smoothing via Catmull-Rom to cubic Bezier conversion.
|
|
18
|
+
- Image elements decoded from the scene's `files` dict (data URLs embedded into SVG).
|
|
19
|
+
- Frame elements rendered as labeled dashed boundary rectangles.
|
|
20
|
+
- Top-level `render_svg(scene)` and `render_png(scene, out, ...)` entry points.
|
|
21
|
+
- CLI `excalidraw-render FILE [DIR]` with `-o/--output`, `-f/--format {png,svg}`, `--width`, `--scale`, `--no-background`, `--padding`. Single-file and batch-directory modes.
|
|
22
|
+
- 30 tests (`test_element.py`, `test_render.py`, `test_cli.py`) with hand-crafted fixtures covering every supported element type. Ruff + mypy clean.
|
|
23
|
+
|
|
24
|
+
### Deferred to v0.2
|
|
25
|
+
- Roughness (`roughjs`-style hand-drawn look). Pure-Python port (`pyroughjs`) on the roadmap.
|
|
26
|
+
- PDF and JPEG output.
|
|
27
|
+
- Container-bound text positioning fidelity (`containerId` lookup → padding-respecting text placement).
|
|
28
|
+
- Hachure / cross-hatch / zigzag / dots fill patterns (currently fall back to solid).
|
|
29
|
+
- Terminal output subcommands (iTerm2 OSC-1337, Kitty graphics protocol, Sixel).
|
|
30
|
+
- Markdown preprocessor subcommand (replaces `mdview`).
|
|
31
|
+
- Watch mode (re-render on file change).
|
|
32
|
+
- Real Excalidraw export round-trip tests against the public Excalidraw repo's example files.
|
|
33
|
+
|
|
34
|
+
### Known limitations
|
|
35
|
+
- Shorthand `label` field on shapes (an MCP / `mdview` extension, not standard Excalidraw) is not rendered. Use a separate `text` element with `containerId` instead. Adding shorthand support is tracked for v0.2.
|
|
36
|
+
- Text positioning inside container shapes is currently text-element-driven (x/y must already match the container). True container-relative layout (padding, vertical alignment relative to container) is deferred.
|
|
37
|
+
- Group-level transforms are not yet applied as a single matrix; per-element rotation/transform works.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shivam Mathur
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: excalidraw-render
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Clean, deterministic, browser-free renderer for .excalidraw files (PNG/SVG).
|
|
5
|
+
Project-URL: Homepage, https://github.com/shivama205/excalidraw-render
|
|
6
|
+
Project-URL: Source, https://github.com/shivama205/excalidraw-render
|
|
7
|
+
Project-URL: Issues, https://github.com/shivama205/excalidraw-render/issues
|
|
8
|
+
Author: Shivam Mathur
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 Shivam Mathur
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: diagram,excalidraw,png,renderer,svg
|
|
32
|
+
Classifier: Development Status :: 3 - Alpha
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
40
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
41
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
42
|
+
Classifier: Topic :: Utilities
|
|
43
|
+
Requires-Python: >=3.10
|
|
44
|
+
Requires-Dist: cairosvg>=2.7
|
|
45
|
+
Requires-Dist: pillow>=10.0
|
|
46
|
+
Provides-Extra: dev
|
|
47
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
48
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
49
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
50
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
51
|
+
Description-Content-Type: text/markdown
|
|
52
|
+
|
|
53
|
+
# excalidraw-render
|
|
54
|
+
|
|
55
|
+
[](https://github.com/shivama205/excalidraw-render/actions/workflows/ci.yml)
|
|
56
|
+
[](https://pypi.org/project/excalidraw-render/)
|
|
57
|
+
[](https://pypi.org/project/excalidraw-render/)
|
|
58
|
+
[](LICENSE)
|
|
59
|
+
|
|
60
|
+
Clean, deterministic, browser-free renderer for `.excalidraw` files. Pure Python + cairosvg. No Node, no headless browser, no `node-canvas`.
|
|
61
|
+
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install excalidraw-render
|
|
66
|
+
|
|
67
|
+
excalidraw-render diagram.excalidraw # → diagram.png
|
|
68
|
+
excalidraw-render diagram.excalidraw -f svg # → diagram.svg
|
|
69
|
+
excalidraw-render diagram.excalidraw --width 1200 # PNG at 1200px wide
|
|
70
|
+
excalidraw-render ./docs/ # batch: every .excalidraw → .png
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Why this exists
|
|
74
|
+
|
|
75
|
+
The Excalidraw ecosystem's existing exporters either need Node + `node-canvas` ([`excalidraw_export`](https://www.npmjs.com/package/excalidraw_export)) or a headless browser running React ([`@excalidraw/excalidraw`](https://www.npmjs.com/package/@excalidraw/excalidraw)). Both are heavy, fragile in CI, and slow to start.
|
|
76
|
+
|
|
77
|
+
`excalidraw-render` is Python + cairosvg. Single-digit-megabyte install, instant startup, no native canvas libs, no Chromium. Useful for:
|
|
78
|
+
|
|
79
|
+
- **Static-site generators** (Hugo, MkDocs, Sphinx) baking `.excalidraw` to PNG at build time
|
|
80
|
+
- **CI/screenshot pipelines** where pulling Chromium is overkill
|
|
81
|
+
- **Doc + slide generators** that want predictable, deterministic vector output
|
|
82
|
+
- **Terminal viewers** (Kitty, iTerm2, Sixel) — coming in v0.2
|
|
83
|
+
|
|
84
|
+
## Trade-off: no hand-drawn style
|
|
85
|
+
|
|
86
|
+
Excalidraw's signature squiggly look comes from [`roughjs`](https://roughjs.com/), a JavaScript library with no native Python port. `excalidraw-render` produces **clean vector output** instead. This is a deliberate trade-off — clean output is what most doc / slide / report pipelines actually want, and skipping roughjs removes the heaviest dependency.
|
|
87
|
+
|
|
88
|
+
A pure-Python roughjs port (`pyroughjs`) is on the v0.2 roadmap. Until then, if you need the hand-drawn look, use Excalidraw's official export.
|
|
89
|
+
|
|
90
|
+
## Comparison
|
|
91
|
+
|
|
92
|
+
| | `excalidraw-render` | [`excalidraw_export`](https://www.npmjs.com/package/excalidraw_export) | [`@excalidraw/excalidraw`](https://www.npmjs.com/package/@excalidraw/excalidraw) |
|
|
93
|
+
|---|---|---|---|
|
|
94
|
+
| Language | Python | Node | React + Node |
|
|
95
|
+
| Hand-drawn (roughjs) | No (v0.2 stretch) | Yes | Yes |
|
|
96
|
+
| PNG output | Yes | via `rsvg-convert` | Yes |
|
|
97
|
+
| SVG output | Yes | Yes | Yes |
|
|
98
|
+
| PDF output | v0.2 | via `rsvg-convert` | No |
|
|
99
|
+
| Headless browser needed | No | No | Yes |
|
|
100
|
+
| Native canvas / image libs | No | Yes (`node-canvas`) | No |
|
|
101
|
+
| Install size | ~10 MB | ~150 MB | Depends |
|
|
102
|
+
| Batch / watch mode | Batch ✓ / watch v0.2 | No | No |
|
|
103
|
+
| Terminal protocols | v0.2 (iTerm / Kitty / Sixel) | No | No |
|
|
104
|
+
|
|
105
|
+
## Install
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install excalidraw-render
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
On Linux you may need `libcairo2`:
|
|
112
|
+
```bash
|
|
113
|
+
sudo apt-get install libcairo2 # Debian / Ubuntu
|
|
114
|
+
sudo dnf install cairo # Fedora
|
|
115
|
+
sudo pacman -S cairo # Arch
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
On macOS, Cairo is typically already present via Homebrew. If not:
|
|
119
|
+
```bash
|
|
120
|
+
brew install cairo
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Usage
|
|
124
|
+
|
|
125
|
+
### CLI
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Single file → PNG next to source
|
|
129
|
+
excalidraw-render diagram.excalidraw
|
|
130
|
+
|
|
131
|
+
# Specify output + format
|
|
132
|
+
excalidraw-render diagram.excalidraw -o /tmp/out.svg -f svg
|
|
133
|
+
|
|
134
|
+
# Higher resolution PNG
|
|
135
|
+
excalidraw-render diagram.excalidraw --width 1600
|
|
136
|
+
|
|
137
|
+
# Or scale instead of fixed width
|
|
138
|
+
excalidraw-render diagram.excalidraw --scale 2.0
|
|
139
|
+
|
|
140
|
+
# Transparent background
|
|
141
|
+
excalidraw-render diagram.excalidraw --no-background
|
|
142
|
+
|
|
143
|
+
# Batch mode: every .excalidraw in a directory
|
|
144
|
+
excalidraw-render ./docs/diagrams/ -o ./public/diagrams/
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Python API
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from excalidraw_render.render import load_scene, render_svg, render_png
|
|
151
|
+
|
|
152
|
+
scene = load_scene("diagram.excalidraw")
|
|
153
|
+
|
|
154
|
+
# SVG as a string
|
|
155
|
+
svg = render_svg(scene)
|
|
156
|
+
|
|
157
|
+
# PNG to a file
|
|
158
|
+
render_png(scene, "diagram.png", width=1200)
|
|
159
|
+
|
|
160
|
+
# PNG to a binary stream
|
|
161
|
+
import io
|
|
162
|
+
buf = io.BytesIO()
|
|
163
|
+
render_png(scene, buf, scale=2.0)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## What's supported in v0.1
|
|
167
|
+
|
|
168
|
+
**Elements:** rectangle, ellipse, diamond, arrow, line, text, freedraw, image, frame.
|
|
169
|
+
**Arrowheads:** `arrow`, `triangle`, `triangle_outline`, `bar`, `dot`, `diamond`, `diamond_outline`, `crowfoot_one`, `crowfoot_many`, `crowfoot_one_or_many`.
|
|
170
|
+
**Styling:** stroke color/width, fill color, stroke style (solid/dashed/dotted), opacity, per-element rotation.
|
|
171
|
+
**Text:** multi-line, text-align (left/center/right), vertical-align (top/middle/bottom), Excalidraw font families mapped to web-safe fonts.
|
|
172
|
+
**Freedraw:** smooth path via Catmull-Rom → cubic Bezier conversion.
|
|
173
|
+
**Image:** embedded raster data from the scene's `files` dict.
|
|
174
|
+
**Frame:** dashed boundary box with optional label.
|
|
175
|
+
|
|
176
|
+
Coverage matrix: [`docs/elements.md`](docs/elements.md).
|
|
177
|
+
|
|
178
|
+
## What's not supported yet
|
|
179
|
+
|
|
180
|
+
Documented in [`CHANGELOG.md`](CHANGELOG.md). Highlights:
|
|
181
|
+
|
|
182
|
+
- Roughness / hand-drawn look (v0.2 — needs roughjs port)
|
|
183
|
+
- PDF / JPEG output (v0.2)
|
|
184
|
+
- Hachure / cross-hatch / zigzag / dots fill patterns (currently fall back to solid)
|
|
185
|
+
- Container-bound text positioning fidelity (padding-aware layout)
|
|
186
|
+
- Terminal output (iTerm / Kitty / Sixel) — v0.2
|
|
187
|
+
- Markdown preprocessor subcommand — v0.2
|
|
188
|
+
- Watch mode — v0.2
|
|
189
|
+
|
|
190
|
+
## Contributing
|
|
191
|
+
|
|
192
|
+
This is pre-alpha and breaking changes between minor versions are likely until v1.0. Issues, ideas, and PRs welcome — please file at https://github.com/shivama205/excalidraw-render/issues.
|
|
193
|
+
|
|
194
|
+
Local dev:
|
|
195
|
+
```bash
|
|
196
|
+
git clone https://github.com/shivama205/excalidraw-render
|
|
197
|
+
cd excalidraw-render
|
|
198
|
+
python -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
199
|
+
.venv/bin/pytest
|
|
200
|
+
.venv/bin/ruff check src tests
|
|
201
|
+
.venv/bin/mypy src
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# excalidraw-render
|
|
2
|
+
|
|
3
|
+
[](https://github.com/shivama205/excalidraw-render/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/excalidraw-render/)
|
|
5
|
+
[](https://pypi.org/project/excalidraw-render/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
Clean, deterministic, browser-free renderer for `.excalidraw` files. Pure Python + cairosvg. No Node, no headless browser, no `node-canvas`.
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install excalidraw-render
|
|
14
|
+
|
|
15
|
+
excalidraw-render diagram.excalidraw # → diagram.png
|
|
16
|
+
excalidraw-render diagram.excalidraw -f svg # → diagram.svg
|
|
17
|
+
excalidraw-render diagram.excalidraw --width 1200 # PNG at 1200px wide
|
|
18
|
+
excalidraw-render ./docs/ # batch: every .excalidraw → .png
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Why this exists
|
|
22
|
+
|
|
23
|
+
The Excalidraw ecosystem's existing exporters either need Node + `node-canvas` ([`excalidraw_export`](https://www.npmjs.com/package/excalidraw_export)) or a headless browser running React ([`@excalidraw/excalidraw`](https://www.npmjs.com/package/@excalidraw/excalidraw)). Both are heavy, fragile in CI, and slow to start.
|
|
24
|
+
|
|
25
|
+
`excalidraw-render` is Python + cairosvg. Single-digit-megabyte install, instant startup, no native canvas libs, no Chromium. Useful for:
|
|
26
|
+
|
|
27
|
+
- **Static-site generators** (Hugo, MkDocs, Sphinx) baking `.excalidraw` to PNG at build time
|
|
28
|
+
- **CI/screenshot pipelines** where pulling Chromium is overkill
|
|
29
|
+
- **Doc + slide generators** that want predictable, deterministic vector output
|
|
30
|
+
- **Terminal viewers** (Kitty, iTerm2, Sixel) — coming in v0.2
|
|
31
|
+
|
|
32
|
+
## Trade-off: no hand-drawn style
|
|
33
|
+
|
|
34
|
+
Excalidraw's signature squiggly look comes from [`roughjs`](https://roughjs.com/), a JavaScript library with no native Python port. `excalidraw-render` produces **clean vector output** instead. This is a deliberate trade-off — clean output is what most doc / slide / report pipelines actually want, and skipping roughjs removes the heaviest dependency.
|
|
35
|
+
|
|
36
|
+
A pure-Python roughjs port (`pyroughjs`) is on the v0.2 roadmap. Until then, if you need the hand-drawn look, use Excalidraw's official export.
|
|
37
|
+
|
|
38
|
+
## Comparison
|
|
39
|
+
|
|
40
|
+
| | `excalidraw-render` | [`excalidraw_export`](https://www.npmjs.com/package/excalidraw_export) | [`@excalidraw/excalidraw`](https://www.npmjs.com/package/@excalidraw/excalidraw) |
|
|
41
|
+
|---|---|---|---|
|
|
42
|
+
| Language | Python | Node | React + Node |
|
|
43
|
+
| Hand-drawn (roughjs) | No (v0.2 stretch) | Yes | Yes |
|
|
44
|
+
| PNG output | Yes | via `rsvg-convert` | Yes |
|
|
45
|
+
| SVG output | Yes | Yes | Yes |
|
|
46
|
+
| PDF output | v0.2 | via `rsvg-convert` | No |
|
|
47
|
+
| Headless browser needed | No | No | Yes |
|
|
48
|
+
| Native canvas / image libs | No | Yes (`node-canvas`) | No |
|
|
49
|
+
| Install size | ~10 MB | ~150 MB | Depends |
|
|
50
|
+
| Batch / watch mode | Batch ✓ / watch v0.2 | No | No |
|
|
51
|
+
| Terminal protocols | v0.2 (iTerm / Kitty / Sixel) | No | No |
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install excalidraw-render
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
On Linux you may need `libcairo2`:
|
|
60
|
+
```bash
|
|
61
|
+
sudo apt-get install libcairo2 # Debian / Ubuntu
|
|
62
|
+
sudo dnf install cairo # Fedora
|
|
63
|
+
sudo pacman -S cairo # Arch
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
On macOS, Cairo is typically already present via Homebrew. If not:
|
|
67
|
+
```bash
|
|
68
|
+
brew install cairo
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
### CLI
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Single file → PNG next to source
|
|
77
|
+
excalidraw-render diagram.excalidraw
|
|
78
|
+
|
|
79
|
+
# Specify output + format
|
|
80
|
+
excalidraw-render diagram.excalidraw -o /tmp/out.svg -f svg
|
|
81
|
+
|
|
82
|
+
# Higher resolution PNG
|
|
83
|
+
excalidraw-render diagram.excalidraw --width 1600
|
|
84
|
+
|
|
85
|
+
# Or scale instead of fixed width
|
|
86
|
+
excalidraw-render diagram.excalidraw --scale 2.0
|
|
87
|
+
|
|
88
|
+
# Transparent background
|
|
89
|
+
excalidraw-render diagram.excalidraw --no-background
|
|
90
|
+
|
|
91
|
+
# Batch mode: every .excalidraw in a directory
|
|
92
|
+
excalidraw-render ./docs/diagrams/ -o ./public/diagrams/
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Python API
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from excalidraw_render.render import load_scene, render_svg, render_png
|
|
99
|
+
|
|
100
|
+
scene = load_scene("diagram.excalidraw")
|
|
101
|
+
|
|
102
|
+
# SVG as a string
|
|
103
|
+
svg = render_svg(scene)
|
|
104
|
+
|
|
105
|
+
# PNG to a file
|
|
106
|
+
render_png(scene, "diagram.png", width=1200)
|
|
107
|
+
|
|
108
|
+
# PNG to a binary stream
|
|
109
|
+
import io
|
|
110
|
+
buf = io.BytesIO()
|
|
111
|
+
render_png(scene, buf, scale=2.0)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## What's supported in v0.1
|
|
115
|
+
|
|
116
|
+
**Elements:** rectangle, ellipse, diamond, arrow, line, text, freedraw, image, frame.
|
|
117
|
+
**Arrowheads:** `arrow`, `triangle`, `triangle_outline`, `bar`, `dot`, `diamond`, `diamond_outline`, `crowfoot_one`, `crowfoot_many`, `crowfoot_one_or_many`.
|
|
118
|
+
**Styling:** stroke color/width, fill color, stroke style (solid/dashed/dotted), opacity, per-element rotation.
|
|
119
|
+
**Text:** multi-line, text-align (left/center/right), vertical-align (top/middle/bottom), Excalidraw font families mapped to web-safe fonts.
|
|
120
|
+
**Freedraw:** smooth path via Catmull-Rom → cubic Bezier conversion.
|
|
121
|
+
**Image:** embedded raster data from the scene's `files` dict.
|
|
122
|
+
**Frame:** dashed boundary box with optional label.
|
|
123
|
+
|
|
124
|
+
Coverage matrix: [`docs/elements.md`](docs/elements.md).
|
|
125
|
+
|
|
126
|
+
## What's not supported yet
|
|
127
|
+
|
|
128
|
+
Documented in [`CHANGELOG.md`](CHANGELOG.md). Highlights:
|
|
129
|
+
|
|
130
|
+
- Roughness / hand-drawn look (v0.2 — needs roughjs port)
|
|
131
|
+
- PDF / JPEG output (v0.2)
|
|
132
|
+
- Hachure / cross-hatch / zigzag / dots fill patterns (currently fall back to solid)
|
|
133
|
+
- Container-bound text positioning fidelity (padding-aware layout)
|
|
134
|
+
- Terminal output (iTerm / Kitty / Sixel) — v0.2
|
|
135
|
+
- Markdown preprocessor subcommand — v0.2
|
|
136
|
+
- Watch mode — v0.2
|
|
137
|
+
|
|
138
|
+
## Contributing
|
|
139
|
+
|
|
140
|
+
This is pre-alpha and breaking changes between minor versions are likely until v1.0. Issues, ideas, and PRs welcome — please file at https://github.com/shivama205/excalidraw-render/issues.
|
|
141
|
+
|
|
142
|
+
Local dev:
|
|
143
|
+
```bash
|
|
144
|
+
git clone https://github.com/shivama205/excalidraw-render
|
|
145
|
+
cd excalidraw-render
|
|
146
|
+
python -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
147
|
+
.venv/bin/pytest
|
|
148
|
+
.venv/bin/ruff check src tests
|
|
149
|
+
.venv/bin/mypy src
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Releasing `excalidraw-render`
|
|
2
|
+
|
|
3
|
+
This is the runbook for publishing a new version to PyPI.
|
|
4
|
+
|
|
5
|
+
## Prerequisites (one-time)
|
|
6
|
+
|
|
7
|
+
1. PyPI account: https://pypi.org/account/register/
|
|
8
|
+
2. Optional: TestPyPI account (a separate registration): https://test.pypi.org/account/register/
|
|
9
|
+
3. Generate a PyPI API token scoped to this project:
|
|
10
|
+
- https://pypi.org/manage/account/token/
|
|
11
|
+
- Scope: "Project: excalidraw-render" (after the first release; before that, scope it more broadly and re-scope later)
|
|
12
|
+
4. Save the token securely. Suggested: `~/.pypirc` with `[pypi]` and `[testpypi]` sections, or use `keyring`.
|
|
13
|
+
```ini
|
|
14
|
+
# ~/.pypirc — chmod 600
|
|
15
|
+
[pypi]
|
|
16
|
+
username = __token__
|
|
17
|
+
password = pypi-...
|
|
18
|
+
|
|
19
|
+
[testpypi]
|
|
20
|
+
repository = https://test.pypi.org/legacy/
|
|
21
|
+
username = __token__
|
|
22
|
+
password = pypi-...
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Release procedure
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
cd ~/Projects/Hobby/excalidraw-render
|
|
29
|
+
|
|
30
|
+
# 1. Sanity: clean tree, tests green
|
|
31
|
+
git status # no uncommitted changes
|
|
32
|
+
.venv/bin/pytest -q # all tests pass
|
|
33
|
+
.venv/bin/ruff check src tests # clean
|
|
34
|
+
.venv/bin/mypy src # clean
|
|
35
|
+
|
|
36
|
+
# 2. Bump version in src/excalidraw_render/_version.py
|
|
37
|
+
# Also update CHANGELOG.md: move [Unreleased] section to [vX.Y.Z] - YYYY-MM-DD
|
|
38
|
+
|
|
39
|
+
# 3. Commit the version bump
|
|
40
|
+
git add src/excalidraw_render/_version.py CHANGELOG.md
|
|
41
|
+
git commit -m "release: vX.Y.Z"
|
|
42
|
+
git tag -a vX.Y.Z -m "vX.Y.Z"
|
|
43
|
+
git push origin main --follow-tags
|
|
44
|
+
|
|
45
|
+
# 4. Clean any previous build artifacts
|
|
46
|
+
rm -rf dist/ build/ *.egg-info
|
|
47
|
+
|
|
48
|
+
# 5. Build wheel + sdist
|
|
49
|
+
.venv/bin/python -m build
|
|
50
|
+
|
|
51
|
+
# 6. Validate
|
|
52
|
+
.venv/bin/twine check dist/*
|
|
53
|
+
|
|
54
|
+
# 7. (Optional but recommended for the first release) upload to TestPyPI first
|
|
55
|
+
.venv/bin/twine upload --repository testpypi dist/*
|
|
56
|
+
|
|
57
|
+
# Verify in a clean venv:
|
|
58
|
+
python -m venv /tmp/verify-test-pypi
|
|
59
|
+
/tmp/verify-test-pypi/bin/pip install --index-url https://test.pypi.org/simple/ \
|
|
60
|
+
--extra-index-url https://pypi.org/simple/ excalidraw-render
|
|
61
|
+
/tmp/verify-test-pypi/bin/excalidraw-render --help
|
|
62
|
+
|
|
63
|
+
# 8. Upload to real PyPI
|
|
64
|
+
.venv/bin/twine upload dist/*
|
|
65
|
+
|
|
66
|
+
# 9. Create a GitHub release tied to the tag
|
|
67
|
+
gh release create vX.Y.Z dist/* \
|
|
68
|
+
--title "vX.Y.Z" \
|
|
69
|
+
--notes-file CHANGELOG.md \
|
|
70
|
+
--repo shivama205/excalidraw-render
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Version scheme
|
|
74
|
+
|
|
75
|
+
Semver:
|
|
76
|
+
- `0.1.0` — first public release. Anything ≥ 0.1.0 is considered usable.
|
|
77
|
+
- `0.2.0` — first feature-release after 0.1.0. (Backlog: roughness, terminal, markdown subcommand, etc.)
|
|
78
|
+
- `0.x.y` — `x` minor bumps for features; `y` patches for bugfixes.
|
|
79
|
+
- Pre-1.0: API may break between minor versions; CHANGELOG.md flags any breakage.
|
|
80
|
+
- `1.0.0` — API stabilized. After this, semver is strict.
|
|
81
|
+
|
|
82
|
+
Pre-release suffixes (`a1`, `b1`, `rc1`) and dev releases (`.dev0`) are allowed for testing on TestPyPI without burning version numbers on real PyPI.
|
|
83
|
+
|
|
84
|
+
## After every release
|
|
85
|
+
|
|
86
|
+
- Update CHANGELOG.md: open a new `[Unreleased]` section above the released one.
|
|
87
|
+
- Bump version to the next `.dev0` (e.g. after releasing `0.1.0`, set `_version.py` to `0.2.0.dev0`).
|
|
88
|
+
- Commit and push.
|