@agent-clis/diagrams 0.1.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.
Files changed (45) hide show
  1. package/dist/cli.d.ts +2 -0
  2. package/dist/cli.js +64870 -0
  3. package/dist/cloud-icons-index.d.ts +1 -0
  4. package/dist/diagrams/gantt/layout.d.ts +2 -0
  5. package/dist/diagrams/gantt/pptx.d.ts +2 -0
  6. package/dist/diagrams/gantt/tree.d.ts +2 -0
  7. package/dist/diagrams/gantt/types.d.ts +1 -0
  8. package/dist/diagrams/quadrant/layout.d.ts +2 -0
  9. package/dist/diagrams/quadrant/pptx.d.ts +2 -0
  10. package/dist/diagrams/quadrant/tree.d.ts +2 -0
  11. package/dist/diagrams/quadrant/types.d.ts +1 -0
  12. package/dist/diagrams/timeline/layout.d.ts +2 -0
  13. package/dist/diagrams/timeline/pptx.d.ts +2 -0
  14. package/dist/diagrams/timeline/tree.d.ts +2 -0
  15. package/dist/diagrams/timeline/types.d.ts +1 -0
  16. package/dist/fonts.d.ts +6 -0
  17. package/dist/generate-cloud-index.d.ts +1 -0
  18. package/dist/icons.d.ts +4 -0
  19. package/dist/index.d.ts +7 -0
  20. package/dist/index.js +62682 -0
  21. package/dist/layout/edges.d.ts +11 -0
  22. package/dist/layout/groups.d.ts +6 -0
  23. package/dist/layout/index.d.ts +3 -0
  24. package/dist/layout/order.d.ts +6 -0
  25. package/dist/layout/position.d.ts +14 -0
  26. package/dist/layout/rank.d.ts +11 -0
  27. package/dist/parse.d.ts +2 -0
  28. package/dist/render/edges.d.ts +6 -0
  29. package/dist/render/groups.d.ts +5 -0
  30. package/dist/render/html.d.ts +5 -0
  31. package/dist/render/index.d.ts +2 -0
  32. package/dist/render/nodes.d.ts +5 -0
  33. package/dist/render/pptx.d.ts +2 -0
  34. package/dist/render/rasterize.d.ts +3 -0
  35. package/dist/render/tree.d.ts +5 -0
  36. package/dist/resvgjs.darwin-arm64-h8sackw6.node +0 -0
  37. package/dist/themes/dark.d.ts +2 -0
  38. package/dist/themes/default.d.ts +2 -0
  39. package/dist/themes/index.d.ts +5 -0
  40. package/dist/types.d.ts +320 -0
  41. package/dist/validate.d.ts +2 -0
  42. package/fonts/Inter-Medium.ttf +0 -0
  43. package/fonts/Inter-Regular.ttf +0 -0
  44. package/fonts/Inter-SemiBold.ttf +0 -0
  45. package/package.json +64 -0
@@ -0,0 +1,11 @@
1
+ import type { DiagramSpec, LayoutNode, NodeId, EdgeRoute, ThemeConfig } from '../types.js';
2
+ /**
3
+ * Compute edge paths (SVG path data) and arrowhead polygons.
4
+ */
5
+ export declare function routeEdges(spec: DiagramSpec, positions: Map<NodeId, LayoutNode>, theme: ThemeConfig): EdgeRoute[];
6
+ /**
7
+ * Position-based edge routing for grouped layouts.
8
+ * Instead of using a single global direction, picks ports based on the relative
9
+ * positions of the two nodes (dominant axis determines port choice).
10
+ */
11
+ export declare function routeEdgesGlobal(spec: DiagramSpec, positions: Map<NodeId, LayoutNode>, theme: ThemeConfig): EdgeRoute[];
@@ -0,0 +1,6 @@
1
+ import type { DiagramSpec, ThemeConfig, LayoutResult } from '../types.js';
2
+ /**
3
+ * Two-level layout: lay out nodes within groups, then arrange groups on a grid.
4
+ * Falls back to regular layout() when no groups are defined.
5
+ */
6
+ export declare function layoutWithGroups(spec: DiagramSpec, theme: ThemeConfig, padding?: number): LayoutResult;
@@ -0,0 +1,3 @@
1
+ import type { DiagramSpec, ThemeConfig, LayoutResult } from '../types.js';
2
+ export { layoutWithGroups } from './groups.js';
3
+ export declare function layout(spec: DiagramSpec, theme: ThemeConfig, padding?: number): LayoutResult;
@@ -0,0 +1,6 @@
1
+ import type { DiagramSpec, NodeId } from '../types.js';
2
+ /**
3
+ * Order nodes within each rank to minimize edge crossings.
4
+ * Uses barycenter heuristic. Back-edges are excluded from adjacency.
5
+ */
6
+ export declare function orderNodes(spec: DiagramSpec, ranks: Map<NodeId, number>, backEdges?: Set<number>): NodeId[][];
@@ -0,0 +1,14 @@
1
+ import type { DiagramNode, DiagramSpec, NodeId, ThemeConfig, LayoutNode } from '../types.js';
2
+ /**
3
+ * Estimate a node's rendered dimensions based on label text and theme.
4
+ */
5
+ export declare function measureNode(node: DiagramNode, theme: ThemeConfig): {
6
+ width: number;
7
+ height: number;
8
+ };
9
+ /**
10
+ * Assign pixel positions to nodes.
11
+ * TB: ranks go top to bottom, nodes within a rank spread horizontally.
12
+ * LR: ranks go left to right, nodes within a rank spread vertically.
13
+ */
14
+ export declare function positionNodes(spec: DiagramSpec, layers: NodeId[][], theme: ThemeConfig, padding: number): Map<NodeId, LayoutNode>;
@@ -0,0 +1,11 @@
1
+ import type { DiagramSpec, NodeId } from '../types.js';
2
+ export interface RankResult {
3
+ ranks: Map<NodeId, number>;
4
+ /** Indices into spec.edges that are back-edges (cycle-forming) */
5
+ backEdges: Set<number>;
6
+ }
7
+ /**
8
+ * Assign each node to a rank (layer).
9
+ * Detects back-edges (cycle-forming) via DFS and excludes them from ranking.
10
+ */
11
+ export declare function assignRanks(spec: DiagramSpec): RankResult;
@@ -0,0 +1,2 @@
1
+ import type { AnyDiagramSpec } from './types.js';
2
+ export declare function parseSpec(input: string): AnyDiagramSpec;
@@ -0,0 +1,6 @@
1
+ import type { DiagramEdge, EdgeRoute, ThemeConfig, SatoriElement } from '../types.js';
2
+ /**
3
+ * Render all edges: SVG overlay for paths/arrows + div overlays for labels.
4
+ * Returns an array of elements to be placed in the root container.
5
+ */
6
+ export declare function renderEdges(specEdges: DiagramEdge[], routes: EdgeRoute[], theme: ThemeConfig, canvasWidth: number, canvasHeight: number): SatoriElement[];
@@ -0,0 +1,5 @@
1
+ import type { GroupLayout, ThemeConfig, SatoriElement } from '../types.js';
2
+ /**
3
+ * Render a group card as a Satori element (background container with optional label).
4
+ */
5
+ export declare function renderGroupCard(group: GroupLayout, theme: ThemeConfig): SatoriElement;
@@ -0,0 +1,5 @@
1
+ import type { SatoriElement } from '../types.js';
2
+ /**
3
+ * Serialize the Satori element tree to a standalone HTML file.
4
+ */
5
+ export declare function renderToHTML(tree: SatoriElement): string;
@@ -0,0 +1,2 @@
1
+ import type { AnyDiagramSpec, RenderOptions } from '../types.js';
2
+ export declare function renderDiagram(spec: AnyDiagramSpec, options?: RenderOptions): Promise<string | Buffer>;
@@ -0,0 +1,5 @@
1
+ import type { DiagramNode, ThemeConfig, LayoutNode, SatoriElement } from '../types.js';
2
+ /**
3
+ * Render a single node as a Satori element tree.
4
+ */
5
+ export declare function renderNode(node: DiagramNode, pos: LayoutNode, theme: ThemeConfig): SatoriElement;
@@ -0,0 +1,2 @@
1
+ import type { DiagramSpec, LayoutResult, ThemeConfig } from '../types.js';
2
+ export declare function renderToPptx(spec: DiagramSpec, layout: LayoutResult, theme: ThemeConfig): Promise<Buffer>;
@@ -0,0 +1,3 @@
1
+ import type { SatoriElement } from '../types.js';
2
+ export declare function renderToSvg(tree: SatoriElement, width: number, height: number): Promise<string>;
3
+ export declare function renderToPng(tree: SatoriElement, width: number, height: number, scale?: number): Promise<Buffer>;
@@ -0,0 +1,5 @@
1
+ import type { DiagramSpec, ThemeConfig, LayoutResult, SatoriElement } from '../types.js';
2
+ /**
3
+ * Build the complete Satori-compatible element tree.
4
+ */
5
+ export declare function buildTree(spec: DiagramSpec, layoutResult: LayoutResult, theme: ThemeConfig): SatoriElement;
@@ -0,0 +1,2 @@
1
+ import type { ThemeConfig } from '../types.js';
2
+ export declare const darkTheme: ThemeConfig;
@@ -0,0 +1,2 @@
1
+ import type { ThemeConfig } from '../types.js';
2
+ export declare const defaultTheme: ThemeConfig;
@@ -0,0 +1,5 @@
1
+ import type { ThemeConfig } from '../types.js';
2
+ import { defaultTheme } from './default.js';
3
+ import { darkTheme } from './dark.js';
4
+ export declare function getTheme(nameOrConfig: string | ThemeConfig | undefined): ThemeConfig;
5
+ export { defaultTheme, darkTheme };
@@ -0,0 +1,320 @@
1
+ export type NodeId = string;
2
+ export type Direction = 'TB' | 'LR';
3
+ export type OutputFormat = 'svg' | 'png' | 'html' | 'pptx';
4
+ export type NodeShape = 'rectangle' | 'rounded' | 'pill' | 'diamond' | 'circle';
5
+ export type EdgeStyle = 'solid' | 'dashed' | 'dotted';
6
+ export type NodeVariant = 'default' | 'icon';
7
+ export type DiagramType = 'flow' | 'gantt' | 'timeline' | 'quadrant';
8
+ export interface NodeStyleOverrides {
9
+ backgroundColor?: string;
10
+ borderColor?: string;
11
+ textColor?: string;
12
+ iconBorderRadius?: number;
13
+ }
14
+ export interface DiagramNode {
15
+ id: NodeId;
16
+ label: string;
17
+ description?: string;
18
+ shape?: NodeShape;
19
+ variant?: NodeVariant;
20
+ icon?: string;
21
+ iconDataUri?: string;
22
+ style?: NodeStyleOverrides;
23
+ }
24
+ export interface DiagramEdge {
25
+ from: NodeId;
26
+ to: NodeId;
27
+ label?: string;
28
+ style?: EdgeStyle;
29
+ color?: string;
30
+ }
31
+ export interface GroupStyleOverrides {
32
+ backgroundColor?: string;
33
+ borderColor?: string;
34
+ labelColor?: string;
35
+ }
36
+ export interface DiagramGroup {
37
+ id: string;
38
+ label?: string;
39
+ members: NodeId[];
40
+ direction?: Direction;
41
+ style?: GroupStyleOverrides;
42
+ }
43
+ export interface DiagramSpec {
44
+ type?: DiagramType;
45
+ nodes: DiagramNode[];
46
+ edges: DiagramEdge[];
47
+ direction?: Direction;
48
+ title?: string;
49
+ theme?: string | ThemeConfig;
50
+ groups?: DiagramGroup[];
51
+ rows?: string[][];
52
+ }
53
+ export interface GanttTask {
54
+ id: string;
55
+ label: string;
56
+ start: string;
57
+ end: string;
58
+ color?: string;
59
+ group?: string;
60
+ dependencies?: string[];
61
+ progress?: number;
62
+ }
63
+ export interface GanttSpec {
64
+ type: 'gantt';
65
+ title?: string;
66
+ theme?: string | ThemeConfig;
67
+ tasks: GanttTask[];
68
+ }
69
+ export interface TimelineEvent {
70
+ date: string;
71
+ label: string;
72
+ description?: string;
73
+ icon?: string;
74
+ iconDataUri?: string;
75
+ color?: string;
76
+ }
77
+ export interface TimelineSpec {
78
+ type: 'timeline';
79
+ title?: string;
80
+ theme?: string | ThemeConfig;
81
+ direction?: Direction;
82
+ events: TimelineEvent[];
83
+ }
84
+ export interface QuadrantAxis {
85
+ label: string;
86
+ low: string;
87
+ high: string;
88
+ }
89
+ export interface QuadrantDef {
90
+ label: string;
91
+ position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
92
+ color?: string;
93
+ }
94
+ export interface QuadrantItem {
95
+ label: string;
96
+ x: number;
97
+ y: number;
98
+ color?: string;
99
+ }
100
+ export interface QuadrantSpec {
101
+ type: 'quadrant';
102
+ title?: string;
103
+ theme?: string | ThemeConfig;
104
+ xAxis: QuadrantAxis;
105
+ yAxis: QuadrantAxis;
106
+ quadrants?: QuadrantDef[];
107
+ items: QuadrantItem[];
108
+ }
109
+ export type AnyDiagramSpec = DiagramSpec | GanttSpec | TimelineSpec | QuadrantSpec;
110
+ export interface RenderOptions {
111
+ format?: OutputFormat;
112
+ width?: number;
113
+ scale?: number;
114
+ background?: string;
115
+ padding?: number;
116
+ }
117
+ export interface ThemeConfig {
118
+ name: string;
119
+ canvas: {
120
+ background: string;
121
+ };
122
+ node: {
123
+ background: string;
124
+ border: string;
125
+ borderWidth: number;
126
+ borderRadius: number;
127
+ textColor: string;
128
+ textColorSecondary: string;
129
+ fontSize: number;
130
+ fontWeight: number;
131
+ descriptionFontSize: number;
132
+ paddingX: number;
133
+ paddingY: number;
134
+ minWidth: number;
135
+ maxWidth: number;
136
+ shadow: string;
137
+ icon: {
138
+ size: number;
139
+ marginBottom: number;
140
+ dominantSize: number;
141
+ dominantMarginBottom: number;
142
+ dominantLabelFontSize: number;
143
+ };
144
+ };
145
+ edge: {
146
+ color: string;
147
+ width: number;
148
+ arrowSize: number;
149
+ labelColor: string;
150
+ labelFontSize: number;
151
+ labelBackground: string;
152
+ };
153
+ spacing: {
154
+ rankSep: number;
155
+ nodeSep: number;
156
+ };
157
+ group: {
158
+ background: string;
159
+ border: string;
160
+ borderWidth: number;
161
+ borderRadius: number;
162
+ paddingX: number;
163
+ paddingY: number;
164
+ labelFontSize: number;
165
+ labelColor: string;
166
+ labelMarginBottom: number;
167
+ gap: number;
168
+ };
169
+ fontFamily: string;
170
+ gantt?: GanttTheme;
171
+ timeline?: TimelineTheme;
172
+ quadrant?: QuadrantTheme;
173
+ }
174
+ export interface GanttTheme {
175
+ barHeight: number;
176
+ barRadius: number;
177
+ barGap: number;
178
+ headerHeight: number;
179
+ gridLineColor: string;
180
+ groupLabelColor: string;
181
+ groupLabelFontSize: number;
182
+ barLabelColor: string;
183
+ barLabelFontSize: number;
184
+ progressFillOpacity: number;
185
+ dependencyArrowColor: string;
186
+ dateHeaderColor: string;
187
+ dateHeaderFontSize: number;
188
+ }
189
+ export interface TimelineTheme {
190
+ lineColor: string;
191
+ lineWidth: number;
192
+ dotSize: number;
193
+ cardWidth: number;
194
+ cardGap: number;
195
+ connectorLength: number;
196
+ dateFontSize: number;
197
+ dateColor: string;
198
+ labelFontSize: number;
199
+ descriptionFontSize: number;
200
+ }
201
+ export interface QuadrantTheme {
202
+ gridSize: number;
203
+ axisColor: string;
204
+ axisWidth: number;
205
+ axisLabelColor: string;
206
+ axisLabelFontSize: number;
207
+ quadrantOpacity: number;
208
+ dotSize: number;
209
+ dotLabelFontSize: number;
210
+ dotLabelColor: string;
211
+ }
212
+ export interface LayoutNode {
213
+ id: NodeId;
214
+ x: number;
215
+ y: number;
216
+ width: number;
217
+ height: number;
218
+ }
219
+ export interface EdgeRoute {
220
+ from: NodeId;
221
+ to: NodeId;
222
+ pathData: string;
223
+ labelX?: number;
224
+ labelY?: number;
225
+ arrowPoints: string;
226
+ }
227
+ export interface GroupLayout {
228
+ id: string;
229
+ label?: string;
230
+ x: number;
231
+ y: number;
232
+ width: number;
233
+ height: number;
234
+ style?: GroupStyleOverrides;
235
+ }
236
+ export interface LayoutResult {
237
+ nodes: Map<NodeId, LayoutNode>;
238
+ edges: EdgeRoute[];
239
+ width: number;
240
+ height: number;
241
+ groups?: GroupLayout[];
242
+ }
243
+ export interface GanttLayoutResult {
244
+ tasks: Array<{
245
+ id: string;
246
+ label: string;
247
+ x: number;
248
+ y: number;
249
+ width: number;
250
+ height: number;
251
+ color: string;
252
+ progress: number;
253
+ group?: string;
254
+ }>;
255
+ dependencies: Array<{
256
+ pathData: string;
257
+ }>;
258
+ dateLabels: Array<{
259
+ label: string;
260
+ x: number;
261
+ }>;
262
+ groupLabels: Array<{
263
+ label: string;
264
+ y: number;
265
+ }>;
266
+ width: number;
267
+ height: number;
268
+ headerHeight: number;
269
+ }
270
+ export interface TimelineLayoutResult {
271
+ events: Array<{
272
+ date: string;
273
+ label: string;
274
+ description?: string;
275
+ icon?: string;
276
+ iconDataUri?: string;
277
+ color?: string;
278
+ dotX: number;
279
+ dotY: number;
280
+ cardX: number;
281
+ cardY: number;
282
+ connectorPath: string;
283
+ side: 'left' | 'right' | 'top' | 'bottom';
284
+ }>;
285
+ linePath: string;
286
+ width: number;
287
+ height: number;
288
+ }
289
+ export interface QuadrantLayoutResult {
290
+ items: Array<{
291
+ label: string;
292
+ x: number;
293
+ y: number;
294
+ color?: string;
295
+ }>;
296
+ quadrants: Array<{
297
+ label: string;
298
+ x: number;
299
+ y: number;
300
+ width: number;
301
+ height: number;
302
+ color: string;
303
+ }>;
304
+ gridOrigin: {
305
+ x: number;
306
+ y: number;
307
+ };
308
+ gridSize: number;
309
+ xAxis: QuadrantAxis;
310
+ yAxis: QuadrantAxis;
311
+ width: number;
312
+ height: number;
313
+ }
314
+ export interface SatoriElement {
315
+ type: string;
316
+ props: Record<string, unknown> & {
317
+ children?: SatoriElement | (SatoriElement | string)[] | string;
318
+ style?: Record<string, unknown>;
319
+ };
320
+ }
@@ -0,0 +1,2 @@
1
+ import type { AnyDiagramSpec } from './types.js';
2
+ export declare function validate(spec: AnyDiagramSpec): string[];
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@agent-clis/diagrams",
3
+ "version": "0.1.0",
4
+ "description": "Generate beautiful architecture diagrams from declarative YAML specs",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "bin": {
15
+ "diagrams": "./dist/cli.js"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "fonts"
20
+ ],
21
+ "scripts": {
22
+ "dev": "bun run src/cli.ts",
23
+ "build": "bun run build:sdk && bun run build:cli:js",
24
+ "build:sdk": "bun build ./src/index.ts --outdir ./dist --target node && tsc --emitDeclarationOnly",
25
+ "build:cli:js": "bun build ./src/cli.ts --outdir ./dist --target node --entry-naming cli.js",
26
+ "build:cli": "bun build ./src/cli.ts --compile --outfile diagrams",
27
+ "build:cli:linux-x64": "bun build ./src/cli.ts --compile --target=bun-linux-x64 --outfile diagrams-linux-x64",
28
+ "build:cli:linux-arm64": "bun build ./src/cli.ts --compile --target=bun-linux-arm64 --outfile diagrams-linux-arm64",
29
+ "build:cli:darwin-x64": "bun build ./src/cli.ts --compile --target=bun-darwin-x64 --outfile diagrams-darwin-x64",
30
+ "build:cli:darwin-arm64": "bun build ./src/cli.ts --compile --target=bun-darwin-arm64 --outfile diagrams-darwin-arm64",
31
+ "build:cli:windows-x64": "bun build ./src/cli.ts --compile --target=bun-windows-x64 --outfile diagrams-windows-x64.exe",
32
+ "typecheck": "tsc --noEmit",
33
+ "test": "bun test",
34
+ "prepublishOnly": "bun run build"
35
+ },
36
+ "keywords": [
37
+ "diagrams",
38
+ "architecture",
39
+ "flowchart",
40
+ "svg",
41
+ "png",
42
+ "cli",
43
+ "yaml"
44
+ ],
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/daviddrummond95/diagrams.git"
49
+ },
50
+ "author": "David Drummond",
51
+ "homepage": "https://github.com/daviddrummond95/diagrams",
52
+ "dependencies": {
53
+ "@resvg/resvg-js": "^2.6.0",
54
+ "commander": "^14.0.0",
55
+ "pptxgenjs": "^4.0.1",
56
+ "satori": "^0.12.0",
57
+ "simple-icons": "^16.8.0",
58
+ "yaml": "^2.6.0"
59
+ },
60
+ "devDependencies": {
61
+ "@types/bun": "latest",
62
+ "typescript": "^5.7.0"
63
+ }
64
+ }