@crazyhappyone/auto-graph 0.0.1

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 auto-graph
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 ADDED
@@ -0,0 +1,154 @@
1
+ # auto-graph
2
+
3
+ [中文文档](./README.zh-CN.md)
4
+
5
+ auto-graph is a deterministic geometry engine for diagrams. It turns high-level YAML or JSON diagram intent into stable, collision-aware, text-safe coordinates that can be exported as SVG or editable Excalidraw JSON.
6
+
7
+ The project is not a visual editor and not a renderer-first diagramming tool. It is the geometry layer between graph intent and downstream formats, built for coding agents, LLM workflows, CLI automation, and developers who need repeatable diagrams without hand-tuning x/y coordinates.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install auto-graph
13
+ ```
14
+
15
+ The CLI command is `agh`.
16
+
17
+ ```bash
18
+ agh --input examples/architecture.yaml --format svg --output architecture.svg
19
+ cat examples/architecture.yaml | agh --format excalidraw > architecture.excalidraw.json
20
+ ```
21
+
22
+ For local development, build before running the compiled CLI directly:
23
+
24
+ ```bash
25
+ npm run build
26
+ node dist/cli/index.js --input examples/architecture.yaml --format svg --output architecture.svg
27
+ ```
28
+
29
+ ## Why It Exists
30
+
31
+ Most diagram generators either rely on a renderer for layout feedback or expose coordinates that humans and agents must tweak by hand. auto-graph keeps geometry solving deterministic and headless:
32
+
33
+ 1. Measure labels before layout through a `TextMeasurer` abstraction.
34
+ 2. Place nodes with Dagre-backed directed layout plus deterministic constraints.
35
+ 3. Route straight or orthogonal connectors from resolved shape ports.
36
+ 4. Export already-coordinated geometry without recomputing layout.
37
+
38
+ Given the same input, auto-graph is designed to produce stable numeric output that can be snapshot-tested and reused by downstream exporters.
39
+
40
+ ## TypeScript API
41
+
42
+ ```typescript
43
+ import {
44
+ exportExcalidraw,
45
+ exportSvg,
46
+ normalizeDiagramDsl,
47
+ parseDiagramDsl,
48
+ solveDiagram,
49
+ } from "auto-graph";
50
+
51
+ const source = `
52
+ title: Architecture
53
+ layout: { direction: LR }
54
+ nodes:
55
+ api: { label: "API Gateway", shape: rounded-rectangle }
56
+ db: { label: "Database", shape: cylinder }
57
+ edges:
58
+ - api -> db: "reads"
59
+ constraints:
60
+ - kind: relative-position
61
+ source: db
62
+ reference: api
63
+ relation: right-of
64
+ offset: { x: 140, y: 0 }
65
+ `;
66
+
67
+ const parsed = parseDiagramDsl(source);
68
+ if (parsed.value === undefined) {
69
+ throw new Error(parsed.diagnostics.map((d) => d.message).join("\n"));
70
+ }
71
+
72
+ const normalized = normalizeDiagramDsl(parsed.value);
73
+ const coordinated = solveDiagram(normalized.diagram);
74
+
75
+ const svg = exportSvg(coordinated, { title: "Architecture" });
76
+ const excalidraw = exportExcalidraw(coordinated);
77
+ ```
78
+
79
+ ## DSL Example
80
+
81
+ ```yaml
82
+ title: Architecture
83
+ layout:
84
+ direction: LR
85
+ nodes:
86
+ web:
87
+ label: Web App
88
+ shape: rounded-rectangle
89
+ api:
90
+ label: API
91
+ shape: hexagon
92
+ db:
93
+ label: Database
94
+ shape: cylinder
95
+ edges:
96
+ - web -> api: calls
97
+ - api -> db: reads
98
+ constraints:
99
+ - kind: relative-position
100
+ source: api
101
+ reference: web
102
+ relation: right-of
103
+ offset: { x: 160, y: 0 }
104
+ ```
105
+
106
+ ## CLI
107
+
108
+ ```bash
109
+ agh --input diagram.yaml --format svg --output diagram.svg
110
+ agh --input diagram.yaml --format excalidraw --output diagram.excalidraw.json
111
+ cat diagram.yaml | agh --json
112
+ ```
113
+
114
+ Supported output formats:
115
+
116
+ - `svg`
117
+ - `excalidraw`
118
+
119
+ Format precedence is CLI `--format`, then DSL `output.format`, then `svg`.
120
+
121
+ ## Current Scope
122
+
123
+ auto-graph v0.0.1 includes:
124
+
125
+ - TypeScript public API with ESM and CJS builds
126
+ - YAML and JSON DSL parsing
127
+ - Layered diagnostics for parse, validation, solve, export, and I/O errors
128
+ - Text measurement abstraction with Pretext-backed and fallback measurers
129
+ - Label fitting, shape geometry, AABB collision utilities, and edge ports
130
+ - Dagre-backed initial layout
131
+ - Exact, relative, align, distribute, and containment constraints
132
+ - Straight and orthogonal routing
133
+ - SVG and Excalidraw exporters
134
+ - Golden and determinism tests
135
+
136
+ Out of scope for this first release:
137
+
138
+ - Browser UI
139
+ - draw.io XML export
140
+ - Mermaid import/export
141
+ - Full styling engine
142
+ - CAD-grade dense routing
143
+
144
+ ## Verification
145
+
146
+ ```bash
147
+ npm run verify
148
+ ```
149
+
150
+ This runs TypeScript type-checking, the dual-format build, Vitest, and Biome checks.
151
+
152
+ ## Credits
153
+
154
+ auto-graph uses `@chenglou/pretext` for renderer-free text preparation and `@dagrejs/dagre` for directed graph initial layout.
@@ -0,0 +1,154 @@
1
+ # auto-graph
2
+
3
+ [English README](./README.md)
4
+
5
+ auto-graph 是一个确定性的图形几何计算引擎。它把高层 YAML 或 JSON 图表意图转换成稳定、避碰、文本安全的坐标,并导出为 SVG 或可编辑的 Excalidraw JSON。
6
+
7
+ 它不是可视化编辑器,也不是以渲染为中心的画图工具。auto-graph 解决的是“意图”和“可渲染坐标”之间的几何求解层,适合编码 Agent、LLM 自动化流程、CLI 管线和需要可重复图表输出的开发者。
8
+
9
+ ## 安装
10
+
11
+ ```bash
12
+ npm install auto-graph
13
+ ```
14
+
15
+ CLI 命令是 `agh`。
16
+
17
+ ```bash
18
+ agh --input examples/architecture.yaml --format svg --output architecture.svg
19
+ cat examples/architecture.yaml | agh --format excalidraw > architecture.excalidraw.json
20
+ ```
21
+
22
+ 本地开发时,先构建再直接运行编译后的 CLI:
23
+
24
+ ```bash
25
+ npm run build
26
+ node dist/cli/index.js --input examples/architecture.yaml --format svg --output architecture.svg
27
+ ```
28
+
29
+ ## 为什么需要它
30
+
31
+ 很多图表生成工具要么依赖渲染器反馈来确定布局,要么暴露坐标让人或 Agent 反复微调。auto-graph 保持几何求解的确定性和无头运行:
32
+
33
+ 1. 通过 `TextMeasurer` 抽象在布局前测量文本。
34
+ 2. 用 Dagre 生成有向初始布局,再叠加确定性约束。
35
+ 3. 从已解析的形状端口生成直线或正交连接线。
36
+ 4. 导出已求解的坐标,不在导出阶段重新排版。
37
+
38
+ 同样的输入应产生稳定的数值输出,方便快照测试、自动化生成和下游导出器复用。
39
+
40
+ ## TypeScript API
41
+
42
+ ```typescript
43
+ import {
44
+ exportExcalidraw,
45
+ exportSvg,
46
+ normalizeDiagramDsl,
47
+ parseDiagramDsl,
48
+ solveDiagram,
49
+ } from "auto-graph";
50
+
51
+ const source = `
52
+ title: Architecture
53
+ layout: { direction: LR }
54
+ nodes:
55
+ api: { label: "API Gateway", shape: rounded-rectangle }
56
+ db: { label: "Database", shape: cylinder }
57
+ edges:
58
+ - api -> db: "reads"
59
+ constraints:
60
+ - kind: relative-position
61
+ source: db
62
+ reference: api
63
+ relation: right-of
64
+ offset: { x: 140, y: 0 }
65
+ `;
66
+
67
+ const parsed = parseDiagramDsl(source);
68
+ if (parsed.value === undefined) {
69
+ throw new Error(parsed.diagnostics.map((d) => d.message).join("\n"));
70
+ }
71
+
72
+ const normalized = normalizeDiagramDsl(parsed.value);
73
+ const coordinated = solveDiagram(normalized.diagram);
74
+
75
+ const svg = exportSvg(coordinated, { title: "Architecture" });
76
+ const excalidraw = exportExcalidraw(coordinated);
77
+ ```
78
+
79
+ ## DSL 示例
80
+
81
+ ```yaml
82
+ title: Architecture
83
+ layout:
84
+ direction: LR
85
+ nodes:
86
+ web:
87
+ label: Web App
88
+ shape: rounded-rectangle
89
+ api:
90
+ label: API
91
+ shape: hexagon
92
+ db:
93
+ label: Database
94
+ shape: cylinder
95
+ edges:
96
+ - web -> api: calls
97
+ - api -> db: reads
98
+ constraints:
99
+ - kind: relative-position
100
+ source: api
101
+ reference: web
102
+ relation: right-of
103
+ offset: { x: 160, y: 0 }
104
+ ```
105
+
106
+ ## CLI
107
+
108
+ ```bash
109
+ agh --input diagram.yaml --format svg --output diagram.svg
110
+ agh --input diagram.yaml --format excalidraw --output diagram.excalidraw.json
111
+ cat diagram.yaml | agh --json
112
+ ```
113
+
114
+ 支持的输出格式:
115
+
116
+ - `svg`
117
+ - `excalidraw`
118
+
119
+ 格式优先级为 CLI `--format`、DSL 中的 `output.format`,最后默认 `svg`。
120
+
121
+ ## 当前范围
122
+
123
+ auto-graph v0.0.1 包含:
124
+
125
+ - TypeScript 公共 API,支持 ESM 和 CJS 构建
126
+ - YAML 和 JSON DSL 解析
127
+ - parse、validate、solve、export、I/O 分层诊断
128
+ - 基于 Pretext 的文本测量抽象和测试 fallback
129
+ - 标签适配、形状几何、AABB 避碰工具和连接端口
130
+ - Dagre 初始有向布局
131
+ - exact、relative、align、distribute、containment 约束
132
+ - 直线和正交连接线
133
+ - SVG 和 Excalidraw 导出
134
+ - Golden fixture 与确定性测试
135
+
136
+ 首个版本暂不包含:
137
+
138
+ - 浏览器 UI
139
+ - draw.io XML 导出
140
+ - Mermaid 导入/导出
141
+ - 完整样式系统
142
+ - CAD 级密集走线
143
+
144
+ ## 验证
145
+
146
+ ```bash
147
+ npm run verify
148
+ ```
149
+
150
+ 该命令会运行 TypeScript 类型检查、双格式构建、Vitest 测试和 Biome 检查。
151
+
152
+ ## 致谢
153
+
154
+ auto-graph 使用 `@chenglou/pretext` 做无渲染器文本准备,使用 `@dagrejs/dagre` 做有向图初始布局。