pidraw 1.2.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.
Files changed (122) hide show
  1. pidraw-1.2.0/LICENSE +21 -0
  2. pidraw-1.2.0/PKG-INFO +360 -0
  3. pidraw-1.2.0/README.md +310 -0
  4. pidraw-1.2.0/pidraw/__init__.py +192 -0
  5. pidraw-1.2.0/pidraw/async_api.py +93 -0
  6. pidraw-1.2.0/pidraw/backend/__init__.py +5 -0
  7. pidraw-1.2.0/pidraw/backend/png.py +215 -0
  8. pidraw-1.2.0/pidraw/backend/svg.py +265 -0
  9. pidraw-1.2.0/pidraw/benchmark.py +294 -0
  10. pidraw-1.2.0/pidraw/cache.py +220 -0
  11. pidraw-1.2.0/pidraw/cli/__init__.py +1 -0
  12. pidraw-1.2.0/pidraw/cli/commands.py +815 -0
  13. pidraw-1.2.0/pidraw/cli/logging.py +49 -0
  14. pidraw-1.2.0/pidraw/cli/main.py +366 -0
  15. pidraw-1.2.0/pidraw/cli/setup.py +176 -0
  16. pidraw-1.2.0/pidraw/core/__init__.py +41 -0
  17. pidraw-1.2.0/pidraw/core/converters/__init__.py +41 -0
  18. pidraw-1.2.0/pidraw/core/converters/ascii.py +107 -0
  19. pidraw-1.2.0/pidraw/core/converters/base.py +29 -0
  20. pidraw-1.2.0/pidraw/core/converters/d2.py +179 -0
  21. pidraw-1.2.0/pidraw/core/converters/graphviz.py +153 -0
  22. pidraw-1.2.0/pidraw/core/converters/mermaid.py +290 -0
  23. pidraw-1.2.0/pidraw/core/converters/plantuml.py +94 -0
  24. pidraw-1.2.0/pidraw/core/models.py +244 -0
  25. pidraw-1.2.0/pidraw/core/shapes.py +153 -0
  26. pidraw-1.2.0/pidraw/core/style.py +80 -0
  27. pidraw-1.2.0/pidraw/detector.py +124 -0
  28. pidraw-1.2.0/pidraw/diagnostics.py +89 -0
  29. pidraw-1.2.0/pidraw/docs.py +344 -0
  30. pidraw-1.2.0/pidraw/engines/__init__.py +99 -0
  31. pidraw-1.2.0/pidraw/engines/base.py +36 -0
  32. pidraw-1.2.0/pidraw/engines/bpmn.py +82 -0
  33. pidraw-1.2.0/pidraw/engines/d2.py +130 -0
  34. pidraw-1.2.0/pidraw/engines/excalidraw.py +205 -0
  35. pidraw-1.2.0/pidraw/engines/graphviz.py +107 -0
  36. pidraw-1.2.0/pidraw/engines/kroki.py +89 -0
  37. pidraw-1.2.0/pidraw/engines/markmap.py +106 -0
  38. pidraw-1.2.0/pidraw/engines/mermaid.py +204 -0
  39. pidraw-1.2.0/pidraw/engines/native.py +48 -0
  40. pidraw-1.2.0/pidraw/engines/nomnoml.py +82 -0
  41. pidraw-1.2.0/pidraw/engines/plantuml.py +196 -0
  42. pidraw-1.2.0/pidraw/engines/structurizr.py +102 -0
  43. pidraw-1.2.0/pidraw/engines/tikz.py +129 -0
  44. pidraw-1.2.0/pidraw/engines/vega.py +78 -0
  45. pidraw-1.2.0/pidraw/engines/vega_lite.py +128 -0
  46. pidraw-1.2.0/pidraw/engines/wavedrom.py +82 -0
  47. pidraw-1.2.0/pidraw/exceptions.py +105 -0
  48. pidraw-1.2.0/pidraw/formats.py +246 -0
  49. pidraw-1.2.0/pidraw/incremental.py +178 -0
  50. pidraw-1.2.0/pidraw/large.py +138 -0
  51. pidraw-1.2.0/pidraw/layout/__init__.py +38 -0
  52. pidraw-1.2.0/pidraw/layout/base.py +20 -0
  53. pidraw-1.2.0/pidraw/layout/flow.py +82 -0
  54. pidraw-1.2.0/pidraw/layout/grid.py +54 -0
  55. pidraw-1.2.0/pidraw/layout/layered.py +104 -0
  56. pidraw-1.2.0/pidraw/layout/tree.py +74 -0
  57. pidraw-1.2.0/pidraw/models.py +54 -0
  58. pidraw-1.2.0/pidraw/optimizer/__init__.py +15 -0
  59. pidraw-1.2.0/pidraw/optimizer/levels.py +135 -0
  60. pidraw-1.2.0/pidraw/optimizer/passes.py +525 -0
  61. pidraw-1.2.0/pidraw/optimizer/svg_optimizer.py +219 -0
  62. pidraw-1.2.0/pidraw/optimizer/validators.py +30 -0
  63. pidraw-1.2.0/pidraw/pipeline.py +81 -0
  64. pidraw-1.2.0/pidraw/pool.py +267 -0
  65. pidraw-1.2.0/pidraw/py.typed +0 -0
  66. pidraw-1.2.0/pidraw/quality/__init__.py +9 -0
  67. pidraw-1.2.0/pidraw/quality/processor.py +247 -0
  68. pidraw-1.2.0/pidraw/recovery.py +127 -0
  69. pidraw-1.2.0/pidraw/registry.py +121 -0
  70. pidraw-1.2.0/pidraw/renderer.py +311 -0
  71. pidraw-1.2.0/pidraw/renderer_class.py +139 -0
  72. pidraw-1.2.0/pidraw/result.py +58 -0
  73. pidraw-1.2.0/pidraw/themes/__init__.py +39 -0
  74. pidraw-1.2.0/pidraw/themes/base.py +29 -0
  75. pidraw-1.2.0/pidraw/themes/blueprint.py +41 -0
  76. pidraw-1.2.0/pidraw/themes/dark.py +39 -0
  77. pidraw-1.2.0/pidraw/themes/light.py +39 -0
  78. pidraw-1.2.0/pidraw/themes/minimal.py +40 -0
  79. pidraw-1.2.0/pidraw/themes/professional.py +44 -0
  80. pidraw-1.2.0/pidraw/typography.py +122 -0
  81. pidraw-1.2.0/pidraw/utils/__init__.py +1 -0
  82. pidraw-1.2.0/pidraw.egg-info/PKG-INFO +360 -0
  83. pidraw-1.2.0/pidraw.egg-info/SOURCES.txt +120 -0
  84. pidraw-1.2.0/pidraw.egg-info/dependency_links.txt +1 -0
  85. pidraw-1.2.0/pidraw.egg-info/entry_points.txt +2 -0
  86. pidraw-1.2.0/pidraw.egg-info/requires.txt +29 -0
  87. pidraw-1.2.0/pidraw.egg-info/top_level.txt +1 -0
  88. pidraw-1.2.0/pyproject.toml +125 -0
  89. pidraw-1.2.0/setup.cfg +4 -0
  90. pidraw-1.2.0/setup.py +35 -0
  91. pidraw-1.2.0/tests/test_async.py +69 -0
  92. pidraw-1.2.0/tests/test_backend.py +120 -0
  93. pidraw-1.2.0/tests/test_cache.py +116 -0
  94. pidraw-1.2.0/tests/test_cli.py +371 -0
  95. pidraw-1.2.0/tests/test_converters.py +70 -0
  96. pidraw-1.2.0/tests/test_core_models.py +148 -0
  97. pidraw-1.2.0/tests/test_core_shapes.py +77 -0
  98. pidraw-1.2.0/tests/test_d2.py +237 -0
  99. pidraw-1.2.0/tests/test_detector.py +208 -0
  100. pidraw-1.2.0/tests/test_diagnostics.py +110 -0
  101. pidraw-1.2.0/tests/test_error_handling.py +129 -0
  102. pidraw-1.2.0/tests/test_formats.py +53 -0
  103. pidraw-1.2.0/tests/test_graphviz.py +167 -0
  104. pidraw-1.2.0/tests/test_incremental.py +96 -0
  105. pidraw-1.2.0/tests/test_large.py +42 -0
  106. pidraw-1.2.0/tests/test_layout.py +124 -0
  107. pidraw-1.2.0/tests/test_mermaid.py +215 -0
  108. pidraw-1.2.0/tests/test_optimizer.py +715 -0
  109. pidraw-1.2.0/tests/test_optimizer_levels.py +66 -0
  110. pidraw-1.2.0/tests/test_pipeline.py +69 -0
  111. pidraw-1.2.0/tests/test_plantuml.py +437 -0
  112. pidraw-1.2.0/tests/test_plugin_discovery.py +36 -0
  113. pidraw-1.2.0/tests/test_png.py +108 -0
  114. pidraw-1.2.0/tests/test_pool.py +61 -0
  115. pidraw-1.2.0/tests/test_quality.py +67 -0
  116. pidraw-1.2.0/tests/test_recovery.py +81 -0
  117. pidraw-1.2.0/tests/test_registry.py +94 -0
  118. pidraw-1.2.0/tests/test_render_api.py +77 -0
  119. pidraw-1.2.0/tests/test_render_result.py +87 -0
  120. pidraw-1.2.0/tests/test_renderer_class.py +99 -0
  121. pidraw-1.2.0/tests/test_themes.py +65 -0
  122. pidraw-1.2.0/tests/test_typography.py +59 -0
pidraw-1.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Devasish Pal
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.
pidraw-1.2.0/PKG-INFO ADDED
@@ -0,0 +1,360 @@
1
+ Metadata-Version: 2.4
2
+ Name: pidraw
3
+ Version: 1.2.0
4
+ Summary: Universal diagram rendering platform — render any diagram language to SVG or PNG
5
+ Author: PiDraw Contributors
6
+ License: MIT
7
+ Project-URL: homepage, https://github.com/devasishpal/PiDraw
8
+ Project-URL: repository, https://github.com/devasishpal/PiDraw
9
+ Project-URL: documentation, https://github.com/devasishpal/PiDraw
10
+ Project-URL: changelog, https://github.com/devasishpal/PiDraw/releases
11
+ Project-URL: issues, https://github.com/devasishpal/PiDraw/issues
12
+ Keywords: diagram,svg,mermaid,graphviz,plantuml,d2,diagram-as-code,renderer,visualization,documentation
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Text Processing :: Markup
22
+ Classifier: Topic :: Multimedia :: Graphics
23
+ Classifier: Topic :: Utilities
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: typer>=0.12
29
+ Requires-Dist: vl-convert-python
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7; extra == "dev"
32
+ Requires-Dist: ruff>=0.3; extra == "dev"
33
+ Requires-Dist: mypy>=1.8; extra == "dev"
34
+ Provides-Extra: docs
35
+ Requires-Dist: mkdocs>=1.5; extra == "docs"
36
+ Requires-Dist: mkdocs-material>=9.0; extra == "docs"
37
+ Provides-Extra: png
38
+ Requires-Dist: cairosvg>=2.7; extra == "png"
39
+ Provides-Extra: png-playwright
40
+ Requires-Dist: playwright>=1.40; extra == "png-playwright"
41
+ Provides-Extra: docx
42
+ Requires-Dist: python-docx>=1.0; extra == "docx"
43
+ Provides-Extra: all
44
+ Requires-Dist: pidraw[dev,docs,png]; extra == "all"
45
+ Provides-Extra: all-png
46
+ Requires-Dist: pidraw[dev,docs,png,png-playwright]; extra == "all-png"
47
+ Provides-Extra: all-docx
48
+ Requires-Dist: pidraw[dev,docs,docx,png,png-playwright]; extra == "all-docx"
49
+ Dynamic: license-file
50
+
51
+ # PiDraw
52
+
53
+ > Universal diagram rendering platform — convert any diagram language to SVG.
54
+
55
+ PiDraw is a Python library and CLI tool that renders source code from **14+ diagram languages** into optimized SVG. It supports native (pure Python) rendering for 7 formats, external CLI tools for the rest (auto-installed on first use), SVG optimization, quality enhancement, caching, parallel batch processing, watch mode, and a plugin architecture.
56
+
57
+ ---
58
+
59
+ ## Supported Formats
60
+
61
+ | Format | Language ID | File Extensions | Render Method |
62
+ |---|---|---|---|
63
+ | Mermaid | `mermaid` | `.mmd`, `.mermaid` | CLI (`mmdc`) or Native |
64
+ | PlantUML | `plantuml` | `.puml`, `.plantuml`, `.iuml` | CLI (`plantuml`) or Native |
65
+ | Graphviz DOT | `graphviz` | `.dot`, `.gv` | CLI (`dot`) or Native |
66
+ | D2 | `d2` | `.d2` | CLI (`d2`) or Native |
67
+ | ASCII Art | `ascii` | `.txt` | **Native** (pure Python) |
68
+ | BPMN 2.0 | `bpmn` | `.bpmn` | CLI (`bpmn-svg`) |
69
+ | Markmap | `markmap` | `.mm` | CLI (`markmap` + Playwright) |
70
+ | Nomnoml | `nomnoml` | `.noml` | CLI (`nomnoml`) |
71
+ | WaveDrom | `wavedrom` | `.json` | CLI (`wavedrom-cli`) |
72
+ | Structurizr | `structurizr` | `.dsl` | CLI (`structurizr-cli` → PlantUML) |
73
+ | Vega | `vega` | `.json` | CLI (`vg2svg`) |
74
+ | Vega-Lite | `vega-lite` | `.json` | **Native** (`vl-convert-python`) or CLI |
75
+ | Excalidraw | `excalidraw` | `.json`, `.excalidraw` | **Native** (pure Python) |
76
+ | Kroki | `kroki` | `.txt`, `.kroki` | **HTTP API** (no CLI needed) |
77
+ | TikZ | `tikz` | `.tex` | CLI (`pdflatex` + `pdf2svg`) |
78
+
79
+ **7 formats work immediately with no extra tools** — mermaid, plantuml, graphviz, d2, ascii, excalidraw, kroki.
80
+
81
+ ---
82
+
83
+ ## Installation
84
+
85
+ ```bash
86
+ # Install from PyPI (recommended)
87
+ pip install pidraw
88
+
89
+ # Or install from source
90
+ git clone https://github.com/devasishpal/PiDraw.git
91
+ cd PiDraw
92
+ pip install -e .
93
+ ```
94
+
95
+ On first import, missing CLI tools (npm packages, structurizr-cli, Playwright Chromium) are automatically installed in a background thread. You can also trigger setup manually:
96
+
97
+ ```bash
98
+ pidraw setup
99
+ ```
100
+
101
+ ---
102
+
103
+ ## Quick Start
104
+
105
+ ```bash
106
+ # Render a single diagram
107
+ pidraw render diagram.mmd output.svg
108
+
109
+ # Auto-detect language
110
+ pidraw detect diagram.txt
111
+
112
+ # Full analysis with diagnostics
113
+ pidraw analyze diagram.puml
114
+
115
+ # Batch render all diagrams in a directory
116
+ pidraw batch *.mmd *.puml --output-dir ./svg
117
+
118
+ # Watch for changes and auto-render
119
+ pidraw watch *.mmd --output-dir ./svg
120
+
121
+ # List all supported formats with live availability
122
+ pidraw formats
123
+
124
+ # Optimize an existing SVG
125
+ pidraw optimize diagram.svg -o optimized.svg
126
+
127
+ # Run benchmarks
128
+ pidraw benchmark
129
+ ```
130
+
131
+ ### Python API
132
+
133
+ ```python
134
+ from pidraw import render
135
+
136
+ # Explicit language
137
+ svg = render("graph TD; A-->B", language="mermaid")
138
+
139
+ # Auto-detect
140
+ svg = render("digraph { A -> B }")
141
+
142
+ # With optimization
143
+ svg = render(source, language="graphviz", optimize="balanced")
144
+
145
+ # With quality enhancement
146
+ svg = render(source, language="plantuml", quality=True)
147
+
148
+ # Render from file
149
+ from pidraw import render_file
150
+ svg = render_file("diagram.mmd")
151
+ ```
152
+
153
+ ---
154
+
155
+ ## CLI Reference
156
+
157
+ ### `pidraw render <file> [options]`
158
+
159
+ | Option | Description |
160
+ |---|---|
161
+ | `-o, --output FILE` | Output SVG file (default: stdout) |
162
+ | `-l, --language TEXT` | Explicit language (skip auto-detection) |
163
+ | `-O, --optimize` | Apply SVG optimization |
164
+ | `-q, --quiet` | Suppress non-error output |
165
+ | `-v, --verbose` | Verbose output |
166
+ | `-d, --debug` | Debug output |
167
+
168
+ ### `pidraw batch <paths...> [options]`
169
+
170
+ | Option | Description |
171
+ |---|---|
172
+ | `--output-dir DIR` | Output directory for SVGs |
173
+ | `-l, --language TEXT` | Language override for all files |
174
+ | `-O, --optimize` | Enable optimization |
175
+ | `-r, --recursive` | Scan directories recursively |
176
+ | `-w, --workers INT` | Parallel worker count (default: CPU count) |
177
+ | `--debounce FLOAT` | Watch debounce seconds (default: 1.0) |
178
+
179
+ ### `pidraw formats [options]`
180
+
181
+ Lists all supported diagram formats. Use `-v` for a live status table showing which engines and CLI tools are available on your system.
182
+
183
+ ### `pidraw analyze <file> [options]`
184
+
185
+ Full diagnostic report: detected language, confidence, renderer, warnings, SVG length, optimization stats.
186
+
187
+ ### `pidraw setup`
188
+
189
+ Auto-install missing CLI tools:
190
+ - npm: `nomnoml`, `markmap-cli`, `wavedrom-cli`, `vega-cli`, `vega-lite`, `bpmn-svg-generator`, `playwright`
191
+ - Java: structurizr-cli (98MB download from GitHub)
192
+ - Browser: Playwright Chromium (used by markmap and bpmn renderers)
193
+ - Python: `vl-convert-python`
194
+
195
+ ### `pidraw benchmark [--quick]`
196
+
197
+ Runs performance benchmarks for render speed, optimization, cache efficiency, and large diagrams.
198
+
199
+ ---
200
+
201
+ ## Architecture
202
+
203
+ ```
204
+ Source Code (string or file)
205
+
206
+
207
+ detect_language() ──► Language ID (e.g. "mermaid")
208
+
209
+
210
+ get_renderer(language) ──► Engine Registry
211
+
212
+ ├── CLI-Based Renderer
213
+ │ └── subprocess → temp file/pipe → SVG
214
+
215
+ ├── NativeRenderer (for converter-supported languages)
216
+ │ ├── converter.parse(source) → Diagram model
217
+ │ ├── apply_layout(diagram) → positioned nodes
218
+ │ ├── apply_theme(diagram) → styled diagram
219
+ │ └── SvgBackend.render(diagram) → SVG string
220
+
221
+ ├── KrokiRenderer (HTTP POST to kroki.io)
222
+
223
+ └── ExcalidrawRenderer (pure Python JSON → SVG)
224
+
225
+
226
+ [Optional] optimize_svg(svg, level="balanced")
227
+ │ 10 passes: comments → metadata → defs → groups → paths → ...
228
+
229
+ [Optional] QualityProcessor.process(svg)
230
+ │ viewBox → text alignment → arrow heads → spacing → paths
231
+
232
+ Output SVG string
233
+ ```
234
+
235
+ ### Engines
236
+
237
+ Each diagram format has a dedicated renderer engine in `pidraw/engines/`. Engines auto-register on import; if a CLI tool is missing and no native fallback exists, a `_BrokenRenderer` placeholder is registered instead (raises a helpful error at render time).
238
+
239
+ ### Converters
240
+
241
+ 5 formats have pure-Python parsers (`pidraw/core/converters/`) that produce an internal `Diagram` model, which `SvgBackend` renders to SVG — no CLI tools needed:
242
+
243
+ | Converter | What it parses |
244
+ |---|---|
245
+ | `MermaidConverter` | `graph TD`, `flowchart`, `sequenceDiagram`, `classDiagram`, etc. |
246
+ | `PlantUMLConverter` | `@startuml` blocks, participants, actors, arrows |
247
+ | `GraphvizConverter` | `digraph`/`graph` statements with attributes |
248
+ | `D2Converter` | D2 node/edge syntax with shapes and styles |
249
+ | `ASCIIConverter` | Simple box-drawing diagrams (`+--+` boxes, `-->` arrows) |
250
+
251
+ ### SVG Optimizer
252
+
253
+ Three optimization levels (`pidraw/optimizer/`):
254
+
255
+ | Level | Passes | Description |
256
+ |---|---|---|
257
+ | `fast` | 3 | Remove comments, editor metadata, trim whitespace |
258
+ | `balanced` | 10 | All fast passes + unused defs, duplicate merging, group collapsing, empty elements, transform normalization, path simplification, attribute ordering |
259
+ | `maximum` | 10 | Same 10 passes (maximum available) |
260
+
261
+ ### Layout Engines
262
+
263
+ 4 layout strategies for native-rendered diagrams (`pidraw/layout/`):
264
+
265
+ | Engine | Algorithm |
266
+ |---|---|
267
+ | `FlowLayout` | Topological sort, single-row/column |
268
+ | `GridLayout` | Square-ish grid (√N columns) |
269
+ | `LayeredLayout` | Sugiyama-style layered layout |
270
+ | `TreeLayout` | Recursive subtree positioning |
271
+
272
+ ### Themes
273
+
274
+ 5 built-in themes (`pidraw/themes/`):
275
+
276
+ | Theme | Description |
277
+ |---|---|
278
+ | `light` | White background, dark text, sans-serif |
279
+ | `dark` | Dark background (`#1e1e1e`), light text |
280
+ | `minimal` | Light minimal (`#fafafa`), thin strokes, Helvetica |
281
+ | `professional` | Colorful node palette, shadows, Segoe UI |
282
+ | `blueprint` | Blue-on-light-blue, monospace, engineering aesthetic |
283
+
284
+ ---
285
+
286
+ ## Caching
287
+
288
+ PiDraw includes a two-tier content-addressable cache:
289
+
290
+ - **Memory tier**: LRU-eviction dict (default 10,000 entries)
291
+ - **Disk tier**: JSON files in configurable directory
292
+ - Cache key: SHA-256 hash of `language + "\x00" + source`
293
+ - Configurable TTL per entry
294
+
295
+ Used automatically by `RenderPool` (parallel rendering) and `IncrementalRenderer`.
296
+
297
+ ---
298
+
299
+ ## Plugin System
300
+
301
+ Extend PiDraw with custom renderers via entry points:
302
+
303
+ ```toml
304
+ # pyproject.toml
305
+ [project.entry-points."pidraw.renderers"]
306
+ myengine = "mypackage:MyRenderer"
307
+ ```
308
+
309
+ Your class must extend `BaseRenderer` and implement `render(source: str) -> str`.
310
+
311
+ ```python
312
+ from pidraw.engines.base import BaseRenderer
313
+
314
+ class MyRenderer(BaseRenderer):
315
+ name = "myformat"
316
+ def render(self, source: str) -> str:
317
+ # ... return SVG string
318
+ pass
319
+ ```
320
+
321
+ ---
322
+
323
+ ## Recovery & Error Handling
324
+
325
+ | Mechanism | Description |
326
+ |---|---|
327
+ | `render_with_retry()` | Exponential backoff retry with optional fallback renderer |
328
+ | `safe_render()` | Returns a red-box error SVG instead of raising |
329
+ | `RecoverableRenderingError` | Distinguishable from hard failures |
330
+
331
+ ---
332
+
333
+ ## Large File Support
334
+
335
+ Files up to 10 MB are handled with streaming reads and chunked SVG writes. Language detection reads only the first 512 KB for efficiency.
336
+
337
+ ---
338
+
339
+ ## Parallel Rendering
340
+
341
+ `RenderPool` uses `ThreadPoolExecutor` (I/O-bound subprocess calls) or `ProcessPoolExecutor` (CPU-bound work) with auto-configured worker count.
342
+
343
+ ```python
344
+ from pidraw import render_many
345
+ svgs = render_many([source1, source2, source3], language="mermaid")
346
+ ```
347
+
348
+ ---
349
+
350
+ ## Requirements
351
+
352
+ - Python >= 3.10
353
+ - Optional: Node.js + npm (for CLI-based formats)
354
+ - Optional: Java Runtime (for structurizr-cli)
355
+
356
+ ---
357
+
358
+ ## License
359
+
360
+ MIT
pidraw-1.2.0/README.md ADDED
@@ -0,0 +1,310 @@
1
+ # PiDraw
2
+
3
+ > Universal diagram rendering platform — convert any diagram language to SVG.
4
+
5
+ PiDraw is a Python library and CLI tool that renders source code from **14+ diagram languages** into optimized SVG. It supports native (pure Python) rendering for 7 formats, external CLI tools for the rest (auto-installed on first use), SVG optimization, quality enhancement, caching, parallel batch processing, watch mode, and a plugin architecture.
6
+
7
+ ---
8
+
9
+ ## Supported Formats
10
+
11
+ | Format | Language ID | File Extensions | Render Method |
12
+ |---|---|---|---|
13
+ | Mermaid | `mermaid` | `.mmd`, `.mermaid` | CLI (`mmdc`) or Native |
14
+ | PlantUML | `plantuml` | `.puml`, `.plantuml`, `.iuml` | CLI (`plantuml`) or Native |
15
+ | Graphviz DOT | `graphviz` | `.dot`, `.gv` | CLI (`dot`) or Native |
16
+ | D2 | `d2` | `.d2` | CLI (`d2`) or Native |
17
+ | ASCII Art | `ascii` | `.txt` | **Native** (pure Python) |
18
+ | BPMN 2.0 | `bpmn` | `.bpmn` | CLI (`bpmn-svg`) |
19
+ | Markmap | `markmap` | `.mm` | CLI (`markmap` + Playwright) |
20
+ | Nomnoml | `nomnoml` | `.noml` | CLI (`nomnoml`) |
21
+ | WaveDrom | `wavedrom` | `.json` | CLI (`wavedrom-cli`) |
22
+ | Structurizr | `structurizr` | `.dsl` | CLI (`structurizr-cli` → PlantUML) |
23
+ | Vega | `vega` | `.json` | CLI (`vg2svg`) |
24
+ | Vega-Lite | `vega-lite` | `.json` | **Native** (`vl-convert-python`) or CLI |
25
+ | Excalidraw | `excalidraw` | `.json`, `.excalidraw` | **Native** (pure Python) |
26
+ | Kroki | `kroki` | `.txt`, `.kroki` | **HTTP API** (no CLI needed) |
27
+ | TikZ | `tikz` | `.tex` | CLI (`pdflatex` + `pdf2svg`) |
28
+
29
+ **7 formats work immediately with no extra tools** — mermaid, plantuml, graphviz, d2, ascii, excalidraw, kroki.
30
+
31
+ ---
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ # Install from PyPI (recommended)
37
+ pip install pidraw
38
+
39
+ # Or install from source
40
+ git clone https://github.com/devasishpal/PiDraw.git
41
+ cd PiDraw
42
+ pip install -e .
43
+ ```
44
+
45
+ On first import, missing CLI tools (npm packages, structurizr-cli, Playwright Chromium) are automatically installed in a background thread. You can also trigger setup manually:
46
+
47
+ ```bash
48
+ pidraw setup
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Quick Start
54
+
55
+ ```bash
56
+ # Render a single diagram
57
+ pidraw render diagram.mmd output.svg
58
+
59
+ # Auto-detect language
60
+ pidraw detect diagram.txt
61
+
62
+ # Full analysis with diagnostics
63
+ pidraw analyze diagram.puml
64
+
65
+ # Batch render all diagrams in a directory
66
+ pidraw batch *.mmd *.puml --output-dir ./svg
67
+
68
+ # Watch for changes and auto-render
69
+ pidraw watch *.mmd --output-dir ./svg
70
+
71
+ # List all supported formats with live availability
72
+ pidraw formats
73
+
74
+ # Optimize an existing SVG
75
+ pidraw optimize diagram.svg -o optimized.svg
76
+
77
+ # Run benchmarks
78
+ pidraw benchmark
79
+ ```
80
+
81
+ ### Python API
82
+
83
+ ```python
84
+ from pidraw import render
85
+
86
+ # Explicit language
87
+ svg = render("graph TD; A-->B", language="mermaid")
88
+
89
+ # Auto-detect
90
+ svg = render("digraph { A -> B }")
91
+
92
+ # With optimization
93
+ svg = render(source, language="graphviz", optimize="balanced")
94
+
95
+ # With quality enhancement
96
+ svg = render(source, language="plantuml", quality=True)
97
+
98
+ # Render from file
99
+ from pidraw import render_file
100
+ svg = render_file("diagram.mmd")
101
+ ```
102
+
103
+ ---
104
+
105
+ ## CLI Reference
106
+
107
+ ### `pidraw render <file> [options]`
108
+
109
+ | Option | Description |
110
+ |---|---|
111
+ | `-o, --output FILE` | Output SVG file (default: stdout) |
112
+ | `-l, --language TEXT` | Explicit language (skip auto-detection) |
113
+ | `-O, --optimize` | Apply SVG optimization |
114
+ | `-q, --quiet` | Suppress non-error output |
115
+ | `-v, --verbose` | Verbose output |
116
+ | `-d, --debug` | Debug output |
117
+
118
+ ### `pidraw batch <paths...> [options]`
119
+
120
+ | Option | Description |
121
+ |---|---|
122
+ | `--output-dir DIR` | Output directory for SVGs |
123
+ | `-l, --language TEXT` | Language override for all files |
124
+ | `-O, --optimize` | Enable optimization |
125
+ | `-r, --recursive` | Scan directories recursively |
126
+ | `-w, --workers INT` | Parallel worker count (default: CPU count) |
127
+ | `--debounce FLOAT` | Watch debounce seconds (default: 1.0) |
128
+
129
+ ### `pidraw formats [options]`
130
+
131
+ Lists all supported diagram formats. Use `-v` for a live status table showing which engines and CLI tools are available on your system.
132
+
133
+ ### `pidraw analyze <file> [options]`
134
+
135
+ Full diagnostic report: detected language, confidence, renderer, warnings, SVG length, optimization stats.
136
+
137
+ ### `pidraw setup`
138
+
139
+ Auto-install missing CLI tools:
140
+ - npm: `nomnoml`, `markmap-cli`, `wavedrom-cli`, `vega-cli`, `vega-lite`, `bpmn-svg-generator`, `playwright`
141
+ - Java: structurizr-cli (98MB download from GitHub)
142
+ - Browser: Playwright Chromium (used by markmap and bpmn renderers)
143
+ - Python: `vl-convert-python`
144
+
145
+ ### `pidraw benchmark [--quick]`
146
+
147
+ Runs performance benchmarks for render speed, optimization, cache efficiency, and large diagrams.
148
+
149
+ ---
150
+
151
+ ## Architecture
152
+
153
+ ```
154
+ Source Code (string or file)
155
+
156
+
157
+ detect_language() ──► Language ID (e.g. "mermaid")
158
+
159
+
160
+ get_renderer(language) ──► Engine Registry
161
+
162
+ ├── CLI-Based Renderer
163
+ │ └── subprocess → temp file/pipe → SVG
164
+
165
+ ├── NativeRenderer (for converter-supported languages)
166
+ │ ├── converter.parse(source) → Diagram model
167
+ │ ├── apply_layout(diagram) → positioned nodes
168
+ │ ├── apply_theme(diagram) → styled diagram
169
+ │ └── SvgBackend.render(diagram) → SVG string
170
+
171
+ ├── KrokiRenderer (HTTP POST to kroki.io)
172
+
173
+ └── ExcalidrawRenderer (pure Python JSON → SVG)
174
+
175
+
176
+ [Optional] optimize_svg(svg, level="balanced")
177
+ │ 10 passes: comments → metadata → defs → groups → paths → ...
178
+
179
+ [Optional] QualityProcessor.process(svg)
180
+ │ viewBox → text alignment → arrow heads → spacing → paths
181
+
182
+ Output SVG string
183
+ ```
184
+
185
+ ### Engines
186
+
187
+ Each diagram format has a dedicated renderer engine in `pidraw/engines/`. Engines auto-register on import; if a CLI tool is missing and no native fallback exists, a `_BrokenRenderer` placeholder is registered instead (raises a helpful error at render time).
188
+
189
+ ### Converters
190
+
191
+ 5 formats have pure-Python parsers (`pidraw/core/converters/`) that produce an internal `Diagram` model, which `SvgBackend` renders to SVG — no CLI tools needed:
192
+
193
+ | Converter | What it parses |
194
+ |---|---|
195
+ | `MermaidConverter` | `graph TD`, `flowchart`, `sequenceDiagram`, `classDiagram`, etc. |
196
+ | `PlantUMLConverter` | `@startuml` blocks, participants, actors, arrows |
197
+ | `GraphvizConverter` | `digraph`/`graph` statements with attributes |
198
+ | `D2Converter` | D2 node/edge syntax with shapes and styles |
199
+ | `ASCIIConverter` | Simple box-drawing diagrams (`+--+` boxes, `-->` arrows) |
200
+
201
+ ### SVG Optimizer
202
+
203
+ Three optimization levels (`pidraw/optimizer/`):
204
+
205
+ | Level | Passes | Description |
206
+ |---|---|---|
207
+ | `fast` | 3 | Remove comments, editor metadata, trim whitespace |
208
+ | `balanced` | 10 | All fast passes + unused defs, duplicate merging, group collapsing, empty elements, transform normalization, path simplification, attribute ordering |
209
+ | `maximum` | 10 | Same 10 passes (maximum available) |
210
+
211
+ ### Layout Engines
212
+
213
+ 4 layout strategies for native-rendered diagrams (`pidraw/layout/`):
214
+
215
+ | Engine | Algorithm |
216
+ |---|---|
217
+ | `FlowLayout` | Topological sort, single-row/column |
218
+ | `GridLayout` | Square-ish grid (√N columns) |
219
+ | `LayeredLayout` | Sugiyama-style layered layout |
220
+ | `TreeLayout` | Recursive subtree positioning |
221
+
222
+ ### Themes
223
+
224
+ 5 built-in themes (`pidraw/themes/`):
225
+
226
+ | Theme | Description |
227
+ |---|---|
228
+ | `light` | White background, dark text, sans-serif |
229
+ | `dark` | Dark background (`#1e1e1e`), light text |
230
+ | `minimal` | Light minimal (`#fafafa`), thin strokes, Helvetica |
231
+ | `professional` | Colorful node palette, shadows, Segoe UI |
232
+ | `blueprint` | Blue-on-light-blue, monospace, engineering aesthetic |
233
+
234
+ ---
235
+
236
+ ## Caching
237
+
238
+ PiDraw includes a two-tier content-addressable cache:
239
+
240
+ - **Memory tier**: LRU-eviction dict (default 10,000 entries)
241
+ - **Disk tier**: JSON files in configurable directory
242
+ - Cache key: SHA-256 hash of `language + "\x00" + source`
243
+ - Configurable TTL per entry
244
+
245
+ Used automatically by `RenderPool` (parallel rendering) and `IncrementalRenderer`.
246
+
247
+ ---
248
+
249
+ ## Plugin System
250
+
251
+ Extend PiDraw with custom renderers via entry points:
252
+
253
+ ```toml
254
+ # pyproject.toml
255
+ [project.entry-points."pidraw.renderers"]
256
+ myengine = "mypackage:MyRenderer"
257
+ ```
258
+
259
+ Your class must extend `BaseRenderer` and implement `render(source: str) -> str`.
260
+
261
+ ```python
262
+ from pidraw.engines.base import BaseRenderer
263
+
264
+ class MyRenderer(BaseRenderer):
265
+ name = "myformat"
266
+ def render(self, source: str) -> str:
267
+ # ... return SVG string
268
+ pass
269
+ ```
270
+
271
+ ---
272
+
273
+ ## Recovery & Error Handling
274
+
275
+ | Mechanism | Description |
276
+ |---|---|
277
+ | `render_with_retry()` | Exponential backoff retry with optional fallback renderer |
278
+ | `safe_render()` | Returns a red-box error SVG instead of raising |
279
+ | `RecoverableRenderingError` | Distinguishable from hard failures |
280
+
281
+ ---
282
+
283
+ ## Large File Support
284
+
285
+ Files up to 10 MB are handled with streaming reads and chunked SVG writes. Language detection reads only the first 512 KB for efficiency.
286
+
287
+ ---
288
+
289
+ ## Parallel Rendering
290
+
291
+ `RenderPool` uses `ThreadPoolExecutor` (I/O-bound subprocess calls) or `ProcessPoolExecutor` (CPU-bound work) with auto-configured worker count.
292
+
293
+ ```python
294
+ from pidraw import render_many
295
+ svgs = render_many([source1, source2, source3], language="mermaid")
296
+ ```
297
+
298
+ ---
299
+
300
+ ## Requirements
301
+
302
+ - Python >= 3.10
303
+ - Optional: Node.js + npm (for CLI-based formats)
304
+ - Optional: Java Runtime (for structurizr-cli)
305
+
306
+ ---
307
+
308
+ ## License
309
+
310
+ MIT