@p10node/graphviz 0.0.0-stage → 0.9.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 p10node
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.
package/README.md CHANGED
@@ -1,3 +1,50 @@
1
- # Temporary Holding Version
1
+ # @p10node/graphviz
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Graphviz DOT text → SVG. No DOM needed (browser, Web Worker, Node, Bun), no server, no dependency.
4
+
5
+ Part of [office-engine](https://github.com/p10node/office-engine). All languages in one package, and drawing the diagram blocks of a page: [`@p10node/diagram`](../diagram).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm i @p10node/graphviz
11
+ ```
12
+
13
+ ## Use
14
+
15
+ ```ts
16
+ import { render, renderEach, renderTo, toPng } from '@p10node/graphviz'
17
+
18
+ const { svg, width, height } = render('digraph { rankdir=LR; a -> b -> c }')
19
+ const all = renderEach(text) // one per graph in the file
20
+ renderTo(document.getElementById('out')!, text) // into an element (browser)
21
+ const png = await toPng(svg, 2) // PNG Blob, 2× size (browser)
22
+ ```
23
+
24
+ `render` returns `{ svg, width, height }` (CSS pixels); a source that cannot be drawn throws a `DiagramError` with the reason.
25
+
26
+ From a CDN, no build step:
27
+
28
+ ```html
29
+ <div id="out"></div>
30
+ <script type="module">
31
+ import { renderTo } from 'https://cdn.jsdelivr.net/npm/@p10node/graphviz/dist/index.js'
32
+ renderTo(document.getElementById('out'), 'digraph { rankdir=LR; a -> b -> c }')
33
+ </script>
34
+ ```
35
+
36
+ ## What is drawn
37
+
38
+ graph / digraph / strict, subgraphs and `cluster_*` boxes, `node` / `edge` / `graph` defaults, edge chains and `{a b} -> c`, `rank=same`, shapes (box, ellipse, circle, diamond, record, cylinder, note…), styles (filled, dashed, dotted, bold, rounded, invis), colors (names, `#rgb`, HSV, X11 grays), arrowheads, `dir`, labels (`\n` `\l`, record fields, HTML labels as text).
39
+
40
+ Laid out by a built-in layered layout, so drawings look close to, not exactly like, the original tool's. Not drawn yet: layout engines other than `dot` (`neato`, `circo`, `fdp`… are laid out as `dot`), ports (edges meet the node), HTML table layouts (their text is shown).
41
+
42
+ The SVG has a fixed `width` / `height`; to fit a column: `svg { max-width: 100%; height: auto; }`.
43
+
44
+ ## Safety
45
+
46
+ Text from the source is escaped; only plain colors are kept; the SVG has no scripts, links, `<foreignObject>` or external references.
47
+
48
+ ## License
49
+
50
+ MIT
@@ -0,0 +1,18 @@
1
+ /** A drawing: a self-contained SVG document and its size in CSS pixels. */
2
+ export interface Diagram {
3
+ svg: string;
4
+ width: number;
5
+ height: number;
6
+ }
7
+ /** The source cannot be drawn (unsupported diagram kind, syntax the reader does not follow). */
8
+ export declare class DiagramError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ /** Every drawing of a source (one per graph). */
12
+ export declare function renderEach(source: string): Diagram[];
13
+ /** The (first) drawing of a source. */
14
+ export declare function render(source: string): Diagram;
15
+ /** Draws a source into an element (its content is replaced). */
16
+ export declare function renderTo(target: Element, source: string): Diagram[];
17
+ /** A PNG of a drawing's SVG, `scale` times its size. Browser only. */
18
+ export declare function toPng(svg: string, scale?: number): Promise<Blob>;