@zombie-mermaid/svg-renderer 2.2.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 +22 -0
- package/dist/index.cjs +56 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +524 -0
- package/dist/index.d.ts +524 -0
- package/dist/index.js +2994 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
- package/src/__tests__/elk-adapter-utils.test.ts +166 -0
- package/src/class/layout.ts +360 -0
- package/src/class/renderer.ts +636 -0
- package/src/edge-curves.ts +204 -0
- package/src/elk-instance.ts +292 -0
- package/src/er/layout.ts +200 -0
- package/src/er/renderer.ts +493 -0
- package/src/index.ts +58 -0
- package/src/layout-engine/constants.ts +19 -0
- package/src/layout-engine/edge-bundling.ts +379 -0
- package/src/layout-engine/elk-adapter-utils.ts +81 -0
- package/src/layout-engine/elk-graph-builder.ts +240 -0
- package/src/layout-engine/from-elk.ts +685 -0
- package/src/layout-engine/layer-alignment.ts +174 -0
- package/src/layout-engine/to-elk.ts +695 -0
- package/src/layout-engine.ts +74 -0
- package/src/layout.ts +8 -0
- package/src/renderer.ts +1485 -0
- package/src/resolve-colors.ts +339 -0
- package/src/sequence/layout.ts +698 -0
- package/src/sequence/renderer.ts +546 -0
- package/src/shape-clipping.ts +197 -0
- package/src/styles.ts +118 -0
- package/src/xychart/layout.ts +682 -0
- package/src/xychart/renderer.ts +684 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layout engine for zombie-mermaid (ELK.js based).
|
|
3
|
+
*
|
|
4
|
+
* Converts MermaidGraph to ELK's JSON format, runs layout, and converts
|
|
5
|
+
* the result back to PositionedGraph. This is the core layout engine used
|
|
6
|
+
* by all graph-based diagram types (flowcharts, state, ER, class).
|
|
7
|
+
*
|
|
8
|
+
* ELK (Eclipse Layout Kernel) features:
|
|
9
|
+
* - Native orthogonal edge routing (no post-processing needed)
|
|
10
|
+
* - Proper handling of compound nodes (subgraphs)
|
|
11
|
+
* - Support for disconnected graphs
|
|
12
|
+
* - Direction overrides per subgraph
|
|
13
|
+
* - Sophisticated algorithms for complex graphs
|
|
14
|
+
*
|
|
15
|
+
* Uses elk.bundled.js (pure synchronous JS, no WASM/Workers).
|
|
16
|
+
* Safe for Electron, Node, and browser environments.
|
|
17
|
+
*
|
|
18
|
+
* This file is the public entry point (layoutGraphSync, convertToElkFormat).
|
|
19
|
+
* The implementation is split across src/layout-engine/ by pipeline stage:
|
|
20
|
+
* - to-elk.ts MermaidGraph → ELK JSON input
|
|
21
|
+
* - from-elk.ts ELK result → PositionedGraph, plus shape clipping
|
|
22
|
+
* - layer-alignment.ts post-process: snap same-layer nodes to a uniform position
|
|
23
|
+
* - edge-bundling.ts post-process: merge fan-out/fan-in edges into shared trunks
|
|
24
|
+
* See packages/svg-renderer/src/layout-engine/constants.ts for the shared DEFAULTS used across stages.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import type { ElkNode } from 'elkjs'
|
|
28
|
+
import type {
|
|
29
|
+
MermaidGraph,
|
|
30
|
+
PositionedGraph,
|
|
31
|
+
FlowchartRenderOptions,
|
|
32
|
+
} from '@zombie-mermaid/core'
|
|
33
|
+
import { elkLayoutSync } from './elk-instance.ts'
|
|
34
|
+
import { resolveFontSizes } from './styles.ts'
|
|
35
|
+
import { DEFAULTS } from './layout-engine/constants.ts'
|
|
36
|
+
import { mermaidToElk } from './layout-engine/to-elk.ts'
|
|
37
|
+
import { elkToPositioned } from './layout-engine/from-elk.ts'
|
|
38
|
+
|
|
39
|
+
// ============================================================================
|
|
40
|
+
// Public API
|
|
41
|
+
// ============================================================================
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Lay out a parsed MermaidGraph using ELK.js (synchronous).
|
|
45
|
+
* Returns a fully positioned graph ready for rendering.
|
|
46
|
+
*/
|
|
47
|
+
export function layoutGraphSync(
|
|
48
|
+
graph: MermaidGraph,
|
|
49
|
+
options: FlowchartRenderOptions = {},
|
|
50
|
+
): PositionedGraph {
|
|
51
|
+
const opts = {
|
|
52
|
+
...DEFAULTS,
|
|
53
|
+
...options,
|
|
54
|
+
fontSizes: resolveFontSizes(options.fontSizes),
|
|
55
|
+
}
|
|
56
|
+
const elkGraph = mermaidToElk(graph, opts)
|
|
57
|
+
const result = elkLayoutSync(elkGraph, options.layoutCache)
|
|
58
|
+
return elkToPositioned(result, graph, opts.mergeEdges)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Convert MermaidGraph to ELK format (for benchmarking conversion overhead).
|
|
63
|
+
*/
|
|
64
|
+
export function convertToElkFormat(
|
|
65
|
+
graph: MermaidGraph,
|
|
66
|
+
options: FlowchartRenderOptions = {},
|
|
67
|
+
): ElkNode {
|
|
68
|
+
const opts = {
|
|
69
|
+
...DEFAULTS,
|
|
70
|
+
...options,
|
|
71
|
+
fontSizes: resolveFontSizes(options.fontSizes),
|
|
72
|
+
}
|
|
73
|
+
return mermaidToElk(graph, opts)
|
|
74
|
+
}
|
package/src/layout.ts
ADDED