Metadata-Version: 2.5
Name: umeko-drawio
Version: 0.2.1
Summary: Offline draw.io exports and interactive browser editing
Project-URL: Source, https://github.com/umeiko/umeko-drawio
Project-URL: Issues, https://github.com/umeiko/umeko-drawio/issues
License-Expression: MIT AND Apache-2.0
License-File: LICENSE
License-File: src/umeko_drawio/_vendor/LICENSE.drawio
License-File: src/umeko_drawio/_vendor/LICENSE.editor
Requires-Python: >=3.10
Requires-Dist: pillow<14,>=11
Requires-Dist: quickjs-ng<1,>=0.12
Requires-Dist: resvg-py<0.6,>=0.5
Provides-Extra: server
Requires-Dist: starlette<2,>=0.47; extra == 'server'
Requires-Dist: uvicorn<1,>=0.34; extra == 'server'
Description-Content-Type: text/markdown

# umeko-drawio

Offline export of draw.io diagrams as SVG, PNG, JPEG or PDF. Install from PyPI
or an approved mirror. The distribution includes the JavaScript renderer and
uses PyPI dependencies to execute it and encode images. Rendering requires no
network access.

## Command line and Python

```sh
python -m pip install umeko-drawio
umeko-drawio input.drawio -o output.svg
umeko-drawio input.drawio -o output.png --scale 2 --font-family "Noto Sans CJK SC"
umeko-drawio input.drawio -o output.pdf --page 1
```

```python
from pathlib import Path
from umeko_drawio import render

result = render(Path("input.drawio").read_text(encoding="utf-8"), "png", scale=2)
Path("output.png").write_bytes(result.data)
for warning in result.warnings:
    print(warning)
```

Each export renders one page. The default is the first page. Pass a zero-based
index, a page ID or a name with `--page` or `page=`. PNG and SVG can retain
transparency. JPEG and PDF use a white backing where the diagram is transparent.
PDF is a single raster page.

For Chinese labels, install a suitable font in the rendering environment or use
`--font-file` or `font_files=`. The CLI and server also accept
`DRAWIO_EXPORT_FONT_FILES` (paths separated by the platform's path separator)
and `DRAWIO_EXPORT_FONT_FAMILY`. Fonts are provided by the deployment.

## HTTP export

The server extra provides an HTTP interface for offline exports.

```sh
python -m pip install 'umeko-drawio[server]'
drawio-web --host 127.0.0.1 --port 8001
curl http://127.0.0.1:8001/ --data-urlencode xml@input.drawio -d format=svg -o output.svg
```

The service accepts form-encoded requests at `POST /` and exposes `GET /health`.
Export options include `format`, `scale`, `border`, `page` and `background`.
Responses contain the export bytes and their media type, with
`X-Drawio-Warning-Count` when applicable.

## Interactive web nodes

Install the server extra and start the package with a SQLite file and the
external service URL. The wheel includes the official draw.io Web editor.

```sh
python -m pip install 'umeko-drawio[server]'
drawio-web --node-db nodes.sqlite3 --public-url http://127.0.0.1:8001
curl -X POST http://127.0.0.1:8001/api/nodes \
  -H 'Content-Type: application/json' -d '{"title":"Example"}'
```

Open the returned `url` to edit and download the diagram. Pass `xml` with the
initial draw.io XML when creating a node. Use `GET /api/nodes/{id}/xml` to read
it and `PUT /api/nodes/{id}/xml` with the new XML to update it. The editor
autosaves and uses `ETag` and `If-Match` so an older page cannot overwrite a newer
revision. After an API update, reload any open editor to see the new revision.

Each node link grants read and write access to its diagram. Keep the service
on a private network or behind your application's access control, and treat
node links as credentials. Each browser saves its own edits with a revision
check. Reload to see changes saved in another browser.

For a deployment prefix, include it in `--public-url`. Forward every child
path to this service after stripping the prefix once. When mounting
`create_app(node_db=..., public_url=...)` in another ASGI app, mount it under
the path in the public URL.

The editor bundle contains the static browser resources from the official
[draw.io v32.6.10 release](https://github.com/jgraph/drawio/releases/tag/v32.6.10).
The build script verifies the pinned release SHA-256 and excludes the Java
server files. The editor's Apache-2.0 license ships with the wheel.
The package loads these resources from its own host and restricts editor
connections to that host.

## Renderer provenance and limits

- The bundled JavaScript is the unmodified `dist/index.cjs` from
  [@dskripchenko/drawio 0.1.0](https://github.com/dskripchenko/drawio), under MIT.
  The accompanying copyright and license ship with the wheel.
  SHA-256 of that file is
  `13d33c42c64a0cb7188702438f2fe3d14eaaf6a52aadfd8474c39297adeb31a4`.
- [quickjs-ng](https://pypi.org/project/quickjs-ng/) runs the bundled code,
  [resvg-py](https://pypi.org/project/resvg-py/) renders PNG, and
  [Pillow](https://pypi.org/project/Pillow/) encodes JPEG and raster PDF.
  These PyPI dependencies include platform-specific native wheels.
- The SVG renderer supports common shapes, orthogonal edges, waypoints, and
  nested groups. Vendor stencil libraries and rich labels can look different
  from draw.io Desktop. External images are disabled. The package targets
  flowchart and architecture exports, and it preserves the original diagram
  file for editing.
- The input limit is 4 MiB for the source and each expanded page. Each export is
  capped at 8,192 pixels per side and 16 megapixels total.

## Development

```sh
python -m pip install -e '.[server]' pytest httpx build twine
python scripts/bundle_editor.py
python -m pytest -q
python -m build
python -m twine check --strict dist/umeko_drawio-0.2.1*
```
