@theodo-group/epure 0.1.0 → 0.2.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/README.md CHANGED
@@ -45,6 +45,26 @@ npx @theodo-group/epure ./docs/diagrams/system.epr.d2
45
45
  This prints a local URL and serves the editor against that pair, syncing your
46
46
  edits both ways. (It creates a starter diagram if the file doesn't exist yet.)
47
47
 
48
+ ## Use it as a library
49
+
50
+ The npm package also exposes the editor's internals as importable entry points
51
+ (React 18 and 19 are both supported as peers):
52
+
53
+ ```ts
54
+ // Headless pair → SVG/PNG, no browser, no DOM — the editor's exact look.
55
+ import { renderDiagramSvg, packagedIconsDir } from '@theodo-group/epure/render'
56
+ const svg = await renderDiagramSvg(d2, layoutJson, { iconsDir: packagedIconsDir() })
57
+
58
+ // The bundled icon catalog (~9.4k icons) and its zero-dependency search.
59
+ import { searchIcons, iconById, ICON_CATALOG } from '@theodo-group/epure/icons'
60
+
61
+ // The presentational SVG components the renders are drawn with.
62
+ import { Node, Edge, EdgeDefs, Area, AreaLabel } from '@theodo-group/epure/react'
63
+ ```
64
+
65
+ The icon images ship with the package: on disk under `packagedIconsDir()`, or
66
+ per file via `@theodo-group/epure/icons/files/<id>.png`.
67
+
48
68
  ## Commands
49
69
 
50
70
  Every command is `npx @theodo-group/epure <command>`:
@@ -0,0 +1,96 @@
1
+ type ShapeName = 'rectangle' | 'cylinder' | 'person';
2
+ type EdgeStyle = 'solid' | 'dashed' | 'dotted';
3
+ type EdgeDirection = 'forward' | 'backward' | 'bidirectional' | 'none';
4
+
5
+ type PaletteColor = 'black' | 'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'purple' | 'pink';
6
+ type FillColor = PaletteColor | 'transparent' | 'white';
7
+ type Size = 'S' | 'M' | 'L' | 'XL';
8
+ type LineStyle = 'solid' | 'dashed' | 'dotted';
9
+ type EndCap = 'none' | 'arrow' | 'dot' | 'diamond';
10
+
11
+ type Side = 'N' | 'S' | 'E' | 'W';
12
+ interface NodeStyle {
13
+ textSize?: Size;
14
+ textColor?: PaletteColor;
15
+ borderColor?: PaletteColor;
16
+ borderStyle?: LineStyle;
17
+ fillColor?: FillColor;
18
+ /** Override the shape parsed from the D2 source. Useful from the style
19
+ * panel when the user wants to change a node's shape without editing the
20
+ * source. Unset → use the AST shape. */
21
+ shape?: ShapeName;
22
+ /** Icon id from the bundled catalog (e.g. "aws/compute/ec2"). */
23
+ icon?: string;
24
+ /** Where the icon sits on the node. `corner` (default) is a small badge in
25
+ * the bottom-right; `top` puts a larger icon centered above the label. */
26
+ iconPosition?: 'corner' | 'top';
27
+ }
28
+ interface EdgeStyleSpec {
29
+ color?: PaletteColor;
30
+ lineStyle?: LineStyle;
31
+ width?: Size;
32
+ startCap?: EndCap;
33
+ endCap?: EndCap;
34
+ /** Nudge the label off its auto-computed anchor, in grid units (integers,
35
+ * may be negative). Absent → label sits at the routed default. Shared by
36
+ * every parallel edge of the same source→target pair (like the other
37
+ * style fields). */
38
+ labelDx?: number;
39
+ labelDy?: number;
40
+ }
41
+ interface AreaStyleSpec {
42
+ borderColor?: PaletteColor;
43
+ borderStyle?: LineStyle;
44
+ fillColor?: FillColor;
45
+ }
46
+ interface NodeLayout extends NodeStyle {
47
+ id: string;
48
+ x: number;
49
+ y: number;
50
+ w: number;
51
+ h: number;
52
+ }
53
+ interface AreaLayout extends AreaStyleSpec {
54
+ id: string;
55
+ label?: string;
56
+ members: string[];
57
+ x: number;
58
+ y: number;
59
+ w: number;
60
+ h: number;
61
+ }
62
+ interface EdgeEndpoint {
63
+ nodeId: string;
64
+ side: Side;
65
+ }
66
+ interface EdgeRoute extends EdgeStyleSpec {
67
+ id: string;
68
+ source: EdgeEndpoint;
69
+ target: EdgeEndpoint;
70
+ points: {
71
+ x: number;
72
+ y: number;
73
+ }[];
74
+ labelAnchor?: {
75
+ x: number;
76
+ y: number;
77
+ };
78
+ }
79
+ interface RoutedDiagram {
80
+ gridSize: number;
81
+ nodes: NodeLayout[];
82
+ areas: AreaLayout[];
83
+ edges: EdgeRoute[];
84
+ }
85
+
86
+ interface NodeMeta {
87
+ shape: ShapeName;
88
+ label?: string;
89
+ }
90
+ interface EdgeMeta {
91
+ label?: string;
92
+ style?: EdgeStyle;
93
+ marker?: EdgeDirection;
94
+ }
95
+
96
+ export type { AreaLayout as A, EdgeRoute as E, FillColor as F, LineStyle as L, NodeMeta as N, PaletteColor as P, RoutedDiagram as R, ShapeName as S, Size as a, Side as b, EdgeStyle as c, EdgeDirection as d, EdgeMeta as e };