@md2nativedocx/core 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.
- package/README.md +15 -0
- package/dist/diagrams/architecture-diagram/parser.d.ts +29 -0
- package/dist/diagrams/architecture-diagram/parser.js +142 -0
- package/dist/diagrams/architecture-diagram/parser.js.map +1 -0
- package/dist/diagrams/architecture-diagram/translator.d.ts +41 -0
- package/dist/diagrams/architecture-diagram/translator.js +172 -0
- package/dist/diagrams/architecture-diagram/translator.js.map +1 -0
- package/dist/diagrams/architecture-diagram/types.d.ts +39 -0
- package/dist/diagrams/architecture-diagram/types.js +18 -0
- package/dist/diagrams/architecture-diagram/types.js.map +1 -0
- package/dist/diagrams/block/parser.d.ts +17 -0
- package/dist/diagrams/block/parser.js +312 -0
- package/dist/diagrams/block/parser.js.map +1 -0
- package/dist/diagrams/block/translator.d.ts +16 -0
- package/dist/diagrams/block/translator.js +137 -0
- package/dist/diagrams/block/translator.js.map +1 -0
- package/dist/diagrams/block/types.d.ts +38 -0
- package/dist/diagrams/block/types.js +6 -0
- package/dist/diagrams/block/types.js.map +1 -0
- package/dist/diagrams/c4/parser.d.ts +29 -0
- package/dist/diagrams/c4/parser.js +264 -0
- package/dist/diagrams/c4/parser.js.map +1 -0
- package/dist/diagrams/c4/translator.d.ts +50 -0
- package/dist/diagrams/c4/translator.js +240 -0
- package/dist/diagrams/c4/translator.js.map +1 -0
- package/dist/diagrams/c4/types.d.ts +74 -0
- package/dist/diagrams/c4/types.js +46 -0
- package/dist/diagrams/c4/types.js.map +1 -0
- package/dist/diagrams/class-diagram/parser.d.ts +40 -0
- package/dist/diagrams/class-diagram/parser.js +213 -0
- package/dist/diagrams/class-diagram/parser.js.map +1 -0
- package/dist/diagrams/class-diagram/translator.d.ts +48 -0
- package/dist/diagrams/class-diagram/translator.js +197 -0
- package/dist/diagrams/class-diagram/translator.js.map +1 -0
- package/dist/diagrams/class-diagram/types.d.ts +54 -0
- package/dist/diagrams/class-diagram/types.js +16 -0
- package/dist/diagrams/class-diagram/types.js.map +1 -0
- package/dist/diagrams/cynefin/parser.d.ts +24 -0
- package/dist/diagrams/cynefin/parser.js +102 -0
- package/dist/diagrams/cynefin/parser.js.map +1 -0
- package/dist/diagrams/cynefin/translator.d.ts +37 -0
- package/dist/diagrams/cynefin/translator.js +190 -0
- package/dist/diagrams/cynefin/translator.js.map +1 -0
- package/dist/diagrams/cynefin/types.d.ts +45 -0
- package/dist/diagrams/cynefin/types.js +36 -0
- package/dist/diagrams/cynefin/types.js.map +1 -0
- package/dist/diagrams/er-diagram/parser.d.ts +29 -0
- package/dist/diagrams/er-diagram/parser.js +156 -0
- package/dist/diagrams/er-diagram/parser.js.map +1 -0
- package/dist/diagrams/er-diagram/translator.d.ts +26 -0
- package/dist/diagrams/er-diagram/translator.js +151 -0
- package/dist/diagrams/er-diagram/translator.js.map +1 -0
- package/dist/diagrams/er-diagram/types.d.ts +44 -0
- package/dist/diagrams/er-diagram/types.js +17 -0
- package/dist/diagrams/er-diagram/types.js.map +1 -0
- package/dist/diagrams/event-modeling/parser.d.ts +16 -0
- package/dist/diagrams/event-modeling/parser.js +193 -0
- package/dist/diagrams/event-modeling/parser.js.map +1 -0
- package/dist/diagrams/event-modeling/translator.d.ts +17 -0
- package/dist/diagrams/event-modeling/translator.js +154 -0
- package/dist/diagrams/event-modeling/translator.js.map +1 -0
- package/dist/diagrams/event-modeling/types.d.ts +46 -0
- package/dist/diagrams/event-modeling/types.js +6 -0
- package/dist/diagrams/event-modeling/types.js.map +1 -0
- package/dist/diagrams/gantt/date-utils.d.ts +51 -0
- package/dist/diagrams/gantt/date-utils.js +131 -0
- package/dist/diagrams/gantt/date-utils.js.map +1 -0
- package/dist/diagrams/gantt/parser.d.ts +37 -0
- package/dist/diagrams/gantt/parser.js +221 -0
- package/dist/diagrams/gantt/parser.js.map +1 -0
- package/dist/diagrams/gantt/translator.d.ts +23 -0
- package/dist/diagrams/gantt/translator.js +259 -0
- package/dist/diagrams/gantt/translator.js.map +1 -0
- package/dist/diagrams/gantt/types.d.ts +31 -0
- package/dist/diagrams/gantt/types.js +14 -0
- package/dist/diagrams/gantt/types.js.map +1 -0
- package/dist/diagrams/git-graph/parser.d.ts +29 -0
- package/dist/diagrams/git-graph/parser.js +237 -0
- package/dist/diagrams/git-graph/parser.js.map +1 -0
- package/dist/diagrams/git-graph/translator.d.ts +49 -0
- package/dist/diagrams/git-graph/translator.js +224 -0
- package/dist/diagrams/git-graph/translator.js.map +1 -0
- package/dist/diagrams/git-graph/types.d.ts +72 -0
- package/dist/diagrams/git-graph/types.js +35 -0
- package/dist/diagrams/git-graph/types.js.map +1 -0
- package/dist/diagrams/ishikawa/parser.d.ts +15 -0
- package/dist/diagrams/ishikawa/parser.js +85 -0
- package/dist/diagrams/ishikawa/parser.js.map +1 -0
- package/dist/diagrams/ishikawa/translator.d.ts +12 -0
- package/dist/diagrams/ishikawa/translator.js +95 -0
- package/dist/diagrams/ishikawa/translator.js.map +1 -0
- package/dist/diagrams/ishikawa/types.d.ts +19 -0
- package/dist/diagrams/ishikawa/types.js +6 -0
- package/dist/diagrams/ishikawa/types.js.map +1 -0
- package/dist/diagrams/journey/parser.d.ts +14 -0
- package/dist/diagrams/journey/parser.js +78 -0
- package/dist/diagrams/journey/parser.js.map +1 -0
- package/dist/diagrams/journey/translator.d.ts +11 -0
- package/dist/diagrams/journey/translator.js +90 -0
- package/dist/diagrams/journey/translator.js.map +1 -0
- package/dist/diagrams/journey/types.d.ts +20 -0
- package/dist/diagrams/journey/types.js +6 -0
- package/dist/diagrams/journey/types.js.map +1 -0
- package/dist/diagrams/kanban/parser.d.ts +17 -0
- package/dist/diagrams/kanban/parser.js +129 -0
- package/dist/diagrams/kanban/parser.js.map +1 -0
- package/dist/diagrams/kanban/translator.d.ts +13 -0
- package/dist/diagrams/kanban/translator.js +72 -0
- package/dist/diagrams/kanban/translator.js.map +1 -0
- package/dist/diagrams/kanban/types.d.ts +21 -0
- package/dist/diagrams/kanban/types.js +6 -0
- package/dist/diagrams/kanban/types.js.map +1 -0
- package/dist/diagrams/mindmap/parser.d.ts +23 -0
- package/dist/diagrams/mindmap/parser.js +108 -0
- package/dist/diagrams/mindmap/parser.js.map +1 -0
- package/dist/diagrams/mindmap/translator.d.ts +31 -0
- package/dist/diagrams/mindmap/translator.js +249 -0
- package/dist/diagrams/mindmap/translator.js.map +1 -0
- package/dist/diagrams/mindmap/types.d.ts +19 -0
- package/dist/diagrams/mindmap/types.js +10 -0
- package/dist/diagrams/mindmap/types.js.map +1 -0
- package/dist/diagrams/packet/parser.d.ts +15 -0
- package/dist/diagrams/packet/parser.js +99 -0
- package/dist/diagrams/packet/parser.js.map +1 -0
- package/dist/diagrams/packet/translator.d.ts +14 -0
- package/dist/diagrams/packet/translator.js +66 -0
- package/dist/diagrams/packet/translator.js.map +1 -0
- package/dist/diagrams/packet/types.d.ts +14 -0
- package/dist/diagrams/packet/types.js +6 -0
- package/dist/diagrams/packet/types.js.map +1 -0
- package/dist/diagrams/pie/chart.d.ts +26 -0
- package/dist/diagrams/pie/chart.js +64 -0
- package/dist/diagrams/pie/chart.js.map +1 -0
- package/dist/diagrams/pie/parser.d.ts +18 -0
- package/dist/diagrams/pie/parser.js +93 -0
- package/dist/diagrams/pie/parser.js.map +1 -0
- package/dist/diagrams/pie/translator.d.ts +15 -0
- package/dist/diagrams/pie/translator.js +150 -0
- package/dist/diagrams/pie/translator.js.map +1 -0
- package/dist/diagrams/pie/types.d.ts +16 -0
- package/dist/diagrams/pie/types.js +6 -0
- package/dist/diagrams/pie/types.js.map +1 -0
- package/dist/diagrams/quadrant/parser.d.ts +24 -0
- package/dist/diagrams/quadrant/parser.js +96 -0
- package/dist/diagrams/quadrant/parser.js.map +1 -0
- package/dist/diagrams/quadrant/translator.d.ts +21 -0
- package/dist/diagrams/quadrant/translator.js +204 -0
- package/dist/diagrams/quadrant/translator.js.map +1 -0
- package/dist/diagrams/quadrant/types.d.ts +41 -0
- package/dist/diagrams/quadrant/types.js +10 -0
- package/dist/diagrams/quadrant/types.js.map +1 -0
- package/dist/diagrams/radar/chart.d.ts +21 -0
- package/dist/diagrams/radar/chart.js +65 -0
- package/dist/diagrams/radar/chart.js.map +1 -0
- package/dist/diagrams/radar/parser.d.ts +15 -0
- package/dist/diagrams/radar/parser.js +186 -0
- package/dist/diagrams/radar/parser.js.map +1 -0
- package/dist/diagrams/radar/translator.d.ts +12 -0
- package/dist/diagrams/radar/translator.js +98 -0
- package/dist/diagrams/radar/translator.js.map +1 -0
- package/dist/diagrams/radar/types.d.ts +29 -0
- package/dist/diagrams/radar/types.js +6 -0
- package/dist/diagrams/radar/types.js.map +1 -0
- package/dist/diagrams/requirement-diagram/parser.d.ts +29 -0
- package/dist/diagrams/requirement-diagram/parser.js +156 -0
- package/dist/diagrams/requirement-diagram/parser.js.map +1 -0
- package/dist/diagrams/requirement-diagram/translator.d.ts +24 -0
- package/dist/diagrams/requirement-diagram/translator.js +214 -0
- package/dist/diagrams/requirement-diagram/translator.js.map +1 -0
- package/dist/diagrams/requirement-diagram/types.d.ts +37 -0
- package/dist/diagrams/requirement-diagram/types.js +18 -0
- package/dist/diagrams/requirement-diagram/types.js.map +1 -0
- package/dist/diagrams/sankey/parser.d.ts +14 -0
- package/dist/diagrams/sankey/parser.js +123 -0
- package/dist/diagrams/sankey/parser.js.map +1 -0
- package/dist/diagrams/sankey/translator.d.ts +15 -0
- package/dist/diagrams/sankey/translator.js +132 -0
- package/dist/diagrams/sankey/translator.js.map +1 -0
- package/dist/diagrams/sankey/types.d.ts +16 -0
- package/dist/diagrams/sankey/types.js +6 -0
- package/dist/diagrams/sankey/types.js.map +1 -0
- package/dist/diagrams/sequence/parser.d.ts +22 -0
- package/dist/diagrams/sequence/parser.js +256 -0
- package/dist/diagrams/sequence/parser.js.map +1 -0
- package/dist/diagrams/sequence/translator.d.ts +21 -0
- package/dist/diagrams/sequence/translator.js +309 -0
- package/dist/diagrams/sequence/translator.js.map +1 -0
- package/dist/diagrams/sequence/types.d.ts +62 -0
- package/dist/diagrams/sequence/types.js +8 -0
- package/dist/diagrams/sequence/types.js.map +1 -0
- package/dist/diagrams/state-diagram/parser.d.ts +37 -0
- package/dist/diagrams/state-diagram/parser.js +215 -0
- package/dist/diagrams/state-diagram/parser.js.map +1 -0
- package/dist/diagrams/state-diagram/translator.d.ts +25 -0
- package/dist/diagrams/state-diagram/translator.js +165 -0
- package/dist/diagrams/state-diagram/translator.js.map +1 -0
- package/dist/diagrams/state-diagram/types.d.ts +38 -0
- package/dist/diagrams/state-diagram/types.js +13 -0
- package/dist/diagrams/state-diagram/types.js.map +1 -0
- package/dist/diagrams/timeline/parser.d.ts +17 -0
- package/dist/diagrams/timeline/parser.js +82 -0
- package/dist/diagrams/timeline/parser.js.map +1 -0
- package/dist/diagrams/timeline/translator.d.ts +13 -0
- package/dist/diagrams/timeline/translator.js +90 -0
- package/dist/diagrams/timeline/translator.js.map +1 -0
- package/dist/diagrams/timeline/types.d.ts +18 -0
- package/dist/diagrams/timeline/types.js +6 -0
- package/dist/diagrams/timeline/types.js.map +1 -0
- package/dist/diagrams/tree-view/parser.d.ts +16 -0
- package/dist/diagrams/tree-view/parser.js +129 -0
- package/dist/diagrams/tree-view/parser.js.map +1 -0
- package/dist/diagrams/tree-view/translator.d.ts +11 -0
- package/dist/diagrams/tree-view/translator.js +73 -0
- package/dist/diagrams/tree-view/translator.js.map +1 -0
- package/dist/diagrams/tree-view/types.d.ts +22 -0
- package/dist/diagrams/tree-view/types.js +6 -0
- package/dist/diagrams/tree-view/types.js.map +1 -0
- package/dist/diagrams/treemap/parser.d.ts +15 -0
- package/dist/diagrams/treemap/parser.js +131 -0
- package/dist/diagrams/treemap/parser.js.map +1 -0
- package/dist/diagrams/treemap/translator.d.ts +15 -0
- package/dist/diagrams/treemap/translator.js +136 -0
- package/dist/diagrams/treemap/translator.js.map +1 -0
- package/dist/diagrams/treemap/types.d.ts +22 -0
- package/dist/diagrams/treemap/types.js +6 -0
- package/dist/diagrams/treemap/types.js.map +1 -0
- package/dist/diagrams/venn/parser.d.ts +27 -0
- package/dist/diagrams/venn/parser.js +129 -0
- package/dist/diagrams/venn/parser.js.map +1 -0
- package/dist/diagrams/venn/translator.d.ts +25 -0
- package/dist/diagrams/venn/translator.js +214 -0
- package/dist/diagrams/venn/translator.js.map +1 -0
- package/dist/diagrams/venn/types.d.ts +33 -0
- package/dist/diagrams/venn/types.js +11 -0
- package/dist/diagrams/venn/types.js.map +1 -0
- package/dist/diagrams/wardley/parser.d.ts +14 -0
- package/dist/diagrams/wardley/parser.js +254 -0
- package/dist/diagrams/wardley/parser.js.map +1 -0
- package/dist/diagrams/wardley/translator.d.ts +15 -0
- package/dist/diagrams/wardley/translator.js +196 -0
- package/dist/diagrams/wardley/translator.js.map +1 -0
- package/dist/diagrams/wardley/types.d.ts +74 -0
- package/dist/diagrams/wardley/types.js +8 -0
- package/dist/diagrams/wardley/types.js.map +1 -0
- package/dist/diagrams/xychart/chart.d.ts +24 -0
- package/dist/diagrams/xychart/chart.js +113 -0
- package/dist/diagrams/xychart/chart.js.map +1 -0
- package/dist/diagrams/xychart/parser.d.ts +16 -0
- package/dist/diagrams/xychart/parser.js +190 -0
- package/dist/diagrams/xychart/parser.js.map +1 -0
- package/dist/diagrams/xychart/translator.d.ts +14 -0
- package/dist/diagrams/xychart/translator.js +187 -0
- package/dist/diagrams/xychart/translator.js.map +1 -0
- package/dist/diagrams/xychart/types.d.ts +32 -0
- package/dist/diagrams/xychart/types.js +6 -0
- package/dist/diagrams/xychart/types.js.map +1 -0
- package/dist/diagrams/zenuml/parser.d.ts +21 -0
- package/dist/diagrams/zenuml/parser.js +228 -0
- package/dist/diagrams/zenuml/parser.js.map +1 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +189 -0
- package/dist/index.js.map +1 -0
- package/dist/label-runs.d.ts +16 -0
- package/dist/label-runs.js +30 -0
- package/dist/label-runs.js.map +1 -0
- package/dist/layout/layout.d.ts +53 -0
- package/dist/layout/layout.js +536 -0
- package/dist/layout/layout.js.map +1 -0
- package/dist/parser/diagram-type.d.ts +41 -0
- package/dist/parser/diagram-type.js +97 -0
- package/dist/parser/diagram-type.js.map +1 -0
- package/dist/parser/index.d.ts +2 -0
- package/dist/parser/index.js +2 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/parser.d.ts +25 -0
- package/dist/parser/parser.js +1134 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/render-diagram.d.ts +156 -0
- package/dist/render-diagram.js +326 -0
- package/dist/render-diagram.js.map +1 -0
- package/dist/rendering-plan.d.ts +47 -0
- package/dist/rendering-plan.js +43 -0
- package/dist/rendering-plan.js.map +1 -0
- package/dist/smartart/chain.d.ts +216 -0
- package/dist/smartart/chain.js +558 -0
- package/dist/smartart/chain.js.map +1 -0
- package/dist/smartart/classify.d.ts +96 -0
- package/dist/smartart/classify.js +162 -0
- package/dist/smartart/classify.js.map +1 -0
- package/dist/smartart/cycle.d.ts +91 -0
- package/dist/smartart/cycle.js +323 -0
- package/dist/smartart/cycle.js.map +1 -0
- package/dist/smartart/dispatch.d.ts +48 -0
- package/dist/smartart/dispatch.js +49 -0
- package/dist/smartart/dispatch.js.map +1 -0
- package/dist/smartart/drawing.d.ts +155 -0
- package/dist/smartart/drawing.js +574 -0
- package/dist/smartart/drawing.js.map +1 -0
- package/dist/smartart/embed.d.ts +78 -0
- package/dist/smartart/embed.js +136 -0
- package/dist/smartart/embed.js.map +1 -0
- package/dist/smartart/from-graph.d.ts +42 -0
- package/dist/smartart/from-graph.js +106 -0
- package/dist/smartart/from-graph.js.map +1 -0
- package/dist/smartart/from-timeline.d.ts +30 -0
- package/dist/smartart/from-timeline.js +59 -0
- package/dist/smartart/from-timeline.js.map +1 -0
- package/dist/smartart/from-tree.d.ts +36 -0
- package/dist/smartart/from-tree.js +74 -0
- package/dist/smartart/from-tree.js.map +1 -0
- package/dist/smartart/generate-options.d.ts +12 -0
- package/dist/smartart/generate-options.js +2 -0
- package/dist/smartart/generate-options.js.map +1 -0
- package/dist/smartart/kanban.d.ts +24 -0
- package/dist/smartart/kanban.js +250 -0
- package/dist/smartart/kanban.js.map +1 -0
- package/dist/smartart/node-shape.d.ts +16 -0
- package/dist/smartart/node-shape.js +22 -0
- package/dist/smartart/node-shape.js.map +1 -0
- package/dist/smartart/styles.d.ts +114 -0
- package/dist/smartart/styles.js +141 -0
- package/dist/smartart/styles.js.map +1 -0
- package/dist/smartart/text.d.ts +16 -0
- package/dist/smartart/text.js +48 -0
- package/dist/smartart/text.js.map +1 -0
- package/dist/smartart/timeline-grouped.d.ts +40 -0
- package/dist/smartart/timeline-grouped.js +279 -0
- package/dist/smartart/timeline-grouped.js.map +1 -0
- package/dist/smartart/timeline.d.ts +51 -0
- package/dist/smartart/timeline.js +276 -0
- package/dist/smartart/timeline.js.map +1 -0
- package/dist/smartart/tree-deep.d.ts +61 -0
- package/dist/smartart/tree-deep.js +293 -0
- package/dist/smartart/tree-deep.js.map +1 -0
- package/dist/smartart/tree.d.ts +159 -0
- package/dist/smartart/tree.js +497 -0
- package/dist/smartart/tree.js.map +1 -0
- package/dist/translator/boxes.d.ts +36 -0
- package/dist/translator/boxes.js +95 -0
- package/dist/translator/boxes.js.map +1 -0
- package/dist/translator/canvas.d.ts +82 -0
- package/dist/translator/canvas.js +135 -0
- package/dist/translator/canvas.js.map +1 -0
- package/dist/translator/graph-shapes.d.ts +98 -0
- package/dist/translator/graph-shapes.js +223 -0
- package/dist/translator/graph-shapes.js.map +1 -0
- package/dist/translator/native-chart.d.ts +64 -0
- package/dist/translator/native-chart.js +109 -0
- package/dist/translator/native-chart.js.map +1 -0
- package/dist/translator/ooxml-translator.d.ts +79 -0
- package/dist/translator/ooxml-translator.js +1213 -0
- package/dist/translator/ooxml-translator.js.map +1 -0
- package/dist/translator/path-shape.d.ts +11 -0
- package/dist/translator/path-shape.js +37 -0
- package/dist/translator/path-shape.js.map +1 -0
- package/dist/translator/unsupported-diagram-note.d.ts +16 -0
- package/dist/translator/unsupported-diagram-note.js +34 -0
- package/dist/translator/unsupported-diagram-note.js.map +1 -0
- package/dist/translator/xml-escape.d.ts +28 -0
- package/dist/translator/xml-escape.js +40 -0
- package/dist/translator/xml-escape.js.map +1 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layered graph layout engine producing pixel coordinates.
|
|
3
|
+
*
|
|
4
|
+
* V1 delegates to **Dagre** (the same engine Mermaid uses internally, spec §5.2,
|
|
5
|
+
* ADR 0001). This is a thin, pure wrapper: AST -> Dagre graph -> pixel
|
|
6
|
+
* coordinates. Graphviz-WASM remains an optional future fallback for dense
|
|
7
|
+
* graphs (>25 nodes) via the `engine` option, without changing the output
|
|
8
|
+
* contract (pixel coordinates).
|
|
9
|
+
*
|
|
10
|
+
* This module is a pure function from AST to coordinates. It has no knowledge
|
|
11
|
+
* of OOXML.
|
|
12
|
+
*/
|
|
13
|
+
import dagre from 'dagre';
|
|
14
|
+
import { labelLines } from '../label-runs.js';
|
|
15
|
+
/**
|
|
16
|
+
* Minimum node dimensions in logical pixels — a floor under
|
|
17
|
+
* {@link nodeDimensions}'s text-driven sizing, not the fixed size every node
|
|
18
|
+
* used to get regardless of its label. Kept as the public export name for
|
|
19
|
+
* source compatibility (`packages/core`'s barrel, `index.ts`).
|
|
20
|
+
*/
|
|
21
|
+
export const NODE_WIDTH = 70;
|
|
22
|
+
export const NODE_HEIGHT = 40;
|
|
23
|
+
/** Horizontal gap between nodes in the same rank. */
|
|
24
|
+
const RANK_GAP = 60;
|
|
25
|
+
/** Vertical gap between ranks. */
|
|
26
|
+
const LEVEL_GAP = 80;
|
|
27
|
+
/**
|
|
28
|
+
* Vertical space reserved at the top of every subgraph box for its title bar.
|
|
29
|
+
* Dagre sizes a cluster tightly around its child nodes with no allowance for
|
|
30
|
+
* a label, so without this a subgraph's title (drawn by the translator at the
|
|
31
|
+
* top of the box) overlaps the first contained node. Shared with
|
|
32
|
+
* `ooxml-translator.ts`, which sizes the title textbox to this same height
|
|
33
|
+
* (in EMU) — a single source of truth so the two can't drift apart.
|
|
34
|
+
*/
|
|
35
|
+
export const SUBGRAPH_TITLE_HEIGHT = 24;
|
|
36
|
+
/**
|
|
37
|
+
* Text-driven node sizing (spec follow-up, found 2026-09-02): every node used
|
|
38
|
+
* to get the exact same fixed box (`NODE_WIDTH`x`NODE_HEIGHT`) regardless of
|
|
39
|
+
* its label — short labels sat lost in an oversized box, long ones wrapped
|
|
40
|
+
* awkwardly, and a `diamond`'s usable interior (a diamond's inscribed text
|
|
41
|
+
* area is much smaller than its bounding box) was routinely too small for
|
|
42
|
+
* its own label, which is what produced the severe text clipping/corruption
|
|
43
|
+
* documented in TODO.md. Mermaid's own renderer sizes every node to its
|
|
44
|
+
* text; this is the same idea, minus real font-metrics measurement (no DOM,
|
|
45
|
+
* no canvas, no new dependency — rule #6, AGENTS.md) — a per-character-class
|
|
46
|
+
* average-width estimate instead. It won't match Word's actual glyph metrics
|
|
47
|
+
* pixel-for-pixel (nothing short of asking Word to lay out the text could),
|
|
48
|
+
* but it only has to get the box roughly right: Word still wraps the text
|
|
49
|
+
* itself at render time (`wrap="square"` in `bodyPr()`), this just has to
|
|
50
|
+
* stop being wrong by a factor of 2-3x.
|
|
51
|
+
*/
|
|
52
|
+
/** Effective font size node/subgraph-title text renders at: no explicit
|
|
53
|
+
* `w:sz` is set on that text (`ooxml-translator.ts`), so it inherits Pandoc's
|
|
54
|
+
* reference.docx `docDefaults` (`w:sz w:val="24"` = 12pt = 16px at 96 DPI) —
|
|
55
|
+
* which, calibrating against it, turns out to already be close to Mermaid's
|
|
56
|
+
* own 16px default. Duplicated here rather than imported: the translator
|
|
57
|
+
* doesn't set this value, it merely doesn't override the inherited default,
|
|
58
|
+
* so there is no single source of truth to import from. */
|
|
59
|
+
const FONT_SIZE_PX = 16;
|
|
60
|
+
/** Roughly 1.25x font size, the usual single-line-height rule of thumb. */
|
|
61
|
+
const LINE_HEIGHT_PX = 20;
|
|
62
|
+
/** Horizontal/vertical padding between a node's text and its border. */
|
|
63
|
+
const PAD_X = 16;
|
|
64
|
+
const PAD_Y = 12;
|
|
65
|
+
/**
|
|
66
|
+
* Width `wrapEstimate`'s greedy word-packing wraps to a new line past —
|
|
67
|
+
* otherwise a long label would produce an arbitrarily wide, increasingly
|
|
68
|
+
* implausible box. Mermaid does the same (wrap past a threshold rather than
|
|
69
|
+
* grow forever). Safe to size on the generous side now that wrapping only
|
|
70
|
+
* ever happens at a word boundary (never mid-word, see `wrapEstimate`):
|
|
71
|
+
* wrapping a little earlier than strictly necessary just costs a bit of
|
|
72
|
+
* vertical space, which is a much smaller problem than the mid-word breaks
|
|
73
|
+
* an earlier, lower value caused.
|
|
74
|
+
*/
|
|
75
|
+
const MAX_LINE_WIDTH_PX = 190;
|
|
76
|
+
/**
|
|
77
|
+
* Safety margin applied to every box's text-driven dimensions, to survive
|
|
78
|
+
* `scaledExtent()` shrinking the whole diagram to fit the page.
|
|
79
|
+
*
|
|
80
|
+
* Found empirically (2026-09-02): a box sized to exactly fit its label at
|
|
81
|
+
* native scale wraps anyway once the diagram is large enough that
|
|
82
|
+
* `scaledExtent()` (further down this file) scales the whole group down —
|
|
83
|
+
* `wp:extent` (display size) ends up smaller than `a:chExt` (native size),
|
|
84
|
+
* and Word/LibreOffice appear to scale a group's *shape geometry* by that
|
|
85
|
+
* ratio without correspondingly shrinking the *literal point size* of text
|
|
86
|
+
* inside its `wps:txbx` content — so the same text that fit its box at
|
|
87
|
+
* native scale visibly no longer does once the group is displayed smaller.
|
|
88
|
+
* Reproduced directly: the label "Traitement" fits its exactly-sized box on
|
|
89
|
+
* one line in an isolated single-node diagram (never scaled down), but
|
|
90
|
+
* wraps to two lines in a 5-node `flowchart LR` where the whole group is
|
|
91
|
+
* scaled to ~80% to fit the page — identical computed box width in both
|
|
92
|
+
* cases, different rendered outcome. There is no single correct
|
|
93
|
+
* compensation factor (the actual scale ratio isn't known until the whole
|
|
94
|
+
* diagram's bounding box is computed, after node sizing), so this errs
|
|
95
|
+
* generous rather than trying to predict it exactly.
|
|
96
|
+
*/
|
|
97
|
+
const SCALE_SAFETY_MARGIN = 1.5;
|
|
98
|
+
/**
|
|
99
|
+
* Per-character-class average glyph width, as a fraction of font size (em).
|
|
100
|
+
* A coarse three-tier estimate — no real font metrics available without a
|
|
101
|
+
* DOM/canvas or a new dependency. Calibrated empirically (2026-09-02) by
|
|
102
|
+
* bisecting the real minimum non-wrapping box width for "Rectangle" (9
|
|
103
|
+
* characters, no space to wrap at — the `shapes` fixture's worst case) in an
|
|
104
|
+
* *unscaled* single-node diagram, isolating this baseline from the separate
|
|
105
|
+
* `SCALE_SAFETY_MARGIN` effect: 120px fit, 80px didn't. A first pass at this
|
|
106
|
+
* table (0.52 em/char for lowercase) implied ~77px was enough — undershooting
|
|
107
|
+
* by roughly a third even before any scale-down is in play.
|
|
108
|
+
*/
|
|
109
|
+
const AVG_CHAR_WIDTH_EM = {
|
|
110
|
+
upper: 0.7,
|
|
111
|
+
digit: 0.58,
|
|
112
|
+
space: 0.3,
|
|
113
|
+
other: 0.6,
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Estimate a label's single-line rendered width in pixels at `fontSizePx`
|
|
117
|
+
* (defaults to `FONT_SIZE_PX`, node/subgraph-title text's effective size —
|
|
118
|
+
* pass a different size for text that renders at an explicit `w:sz`, e.g.
|
|
119
|
+
* the 8pt edge-label captions in `ooxml-translator.ts`). Exported (not part
|
|
120
|
+
* of the public `packages/core` barrel, `index.ts`) so the translator can
|
|
121
|
+
* size an edge-label box to its own text instead of a fixed constant, the
|
|
122
|
+
* same reasoning `nodeDimensions` below already applies to node boxes.
|
|
123
|
+
*/
|
|
124
|
+
export function estimateTextWidth(text, fontSizePx = FONT_SIZE_PX) {
|
|
125
|
+
let em = 0;
|
|
126
|
+
for (const ch of text) {
|
|
127
|
+
if (ch === ' ')
|
|
128
|
+
em += AVG_CHAR_WIDTH_EM.space;
|
|
129
|
+
else if (ch >= '0' && ch <= '9')
|
|
130
|
+
em += AVG_CHAR_WIDTH_EM.digit;
|
|
131
|
+
else if (ch === ch.toUpperCase() && ch !== ch.toLowerCase())
|
|
132
|
+
em += AVG_CHAR_WIDTH_EM.upper;
|
|
133
|
+
else
|
|
134
|
+
em += AVG_CHAR_WIDTH_EM.other;
|
|
135
|
+
}
|
|
136
|
+
return em * fontSizePx;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* How many lines a label wraps to, and the resulting box's inner (text)
|
|
140
|
+
* width, simulating a real greedy word-wrap (pack words onto a line until
|
|
141
|
+
* the next word would push it past `MAX_LINE_WIDTH_PX`, then start a new
|
|
142
|
+
* line) rather than dividing the label's total width by the cap.
|
|
143
|
+
*
|
|
144
|
+
* That flatter approach — this function's first version — actively broke
|
|
145
|
+
* things: dividing "Commande recue"'s total estimated width by a threshold
|
|
146
|
+
* doesn't know where the word boundary is, so it could (and did, once the
|
|
147
|
+
* threshold was lowered enough to fix the clipping below) size a box too
|
|
148
|
+
* narrow for even a *single* word, forcing Word to hyphenate/break mid-word
|
|
149
|
+
* ("Reserver" -> "Rese" / "rver"). Wrapping only ever happens at a space, so
|
|
150
|
+
* this has to reason in words, not raw character counts. A lone word wider
|
|
151
|
+
* than the cap is left on its own line at its own (over-cap) width rather
|
|
152
|
+
* than force-broken — the resulting box is wider than `MAX_LINE_WIDTH_PX`
|
|
153
|
+
* for that one case, which is a far smaller problem than a split word.
|
|
154
|
+
*
|
|
155
|
+
* `SCALE_SAFETY_MARGIN` is applied to the width each packing decision is
|
|
156
|
+
* based on, not just to the final box — seeding the *packing itself* with
|
|
157
|
+
* the optimistic, un-margined estimate under-packed lines relative to what
|
|
158
|
+
* Word's own (wider, in practice) wrapping produced, which is what caused
|
|
159
|
+
* the clipping this function was rewritten to fix in the first place: a
|
|
160
|
+
* label predicted to need one line that actually needed two, with no height
|
|
161
|
+
* reserved for the second.
|
|
162
|
+
*/
|
|
163
|
+
function wrapEstimate(label) {
|
|
164
|
+
const words = label.split(' ').filter((w) => w.length > 0);
|
|
165
|
+
if (words.length === 0)
|
|
166
|
+
return { lines: 1, textWidth: 1 };
|
|
167
|
+
const lineWidths = [];
|
|
168
|
+
let current = words[0];
|
|
169
|
+
for (const word of words.slice(1)) {
|
|
170
|
+
const candidate = `${current} ${word}`;
|
|
171
|
+
if (estimateTextWidth(candidate) * SCALE_SAFETY_MARGIN <= MAX_LINE_WIDTH_PX) {
|
|
172
|
+
current = candidate;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
lineWidths.push(estimateTextWidth(current) * SCALE_SAFETY_MARGIN);
|
|
176
|
+
current = word;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
lineWidths.push(estimateTextWidth(current) * SCALE_SAFETY_MARGIN);
|
|
180
|
+
return { lines: lineWidths.length, textWidth: Math.max(1, ...lineWidths) };
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* A node's box dimensions, sized to its label instead of a fixed constant.
|
|
184
|
+
*
|
|
185
|
+
* `diamond` doubles both axes over what a rectangle with the same label
|
|
186
|
+
* would need: a rhombus's largest centered inscribed rectangle of half-width
|
|
187
|
+
* x and half-height y, within a rhombus of half-diagonals a and b, must
|
|
188
|
+
* satisfy x/a + y/b <= 1 — setting the rhombus's full width/height to twice
|
|
189
|
+
* the text box's is a simple sufficient (not tightest) bound that guarantees
|
|
190
|
+
* the label fits without clipping, at the cost of a visibly larger diamond
|
|
191
|
+
* than a tightly-fitted one. Favouring "clearly big enough" over "exactly
|
|
192
|
+
* as small as provably safe" on purpose: the bug this fixes was severe text
|
|
193
|
+
* corruption from a diamond sized too close to the edge, not a diamond a
|
|
194
|
+
* few pixels larger than ideal.
|
|
195
|
+
*/
|
|
196
|
+
function nodeDimensions(labelRuns, shape) {
|
|
197
|
+
// A `<br/>` (types.ts's `LabelToken` `{ break: true }`) is a forced line
|
|
198
|
+
// break, not something wrapEstimate's own greedy word-wrap should ever
|
|
199
|
+
// reflow across — each forced line is wrapped independently and their line
|
|
200
|
+
// counts summed, so a 2-line label that also wraps once still reports 3
|
|
201
|
+
// lines rather than either line bleeding into the other's word-wrap.
|
|
202
|
+
// wrapEstimate's textWidth already has SCALE_SAFETY_MARGIN baked in (it
|
|
203
|
+
// needs it before the 1-vs-2-line decision, see its own doc comment); only
|
|
204
|
+
// height still needs it applied here.
|
|
205
|
+
let lines = 0;
|
|
206
|
+
let textWidth = 1;
|
|
207
|
+
for (const line of labelLines(labelRuns)) {
|
|
208
|
+
const estimate = wrapEstimate(line);
|
|
209
|
+
lines += estimate.lines;
|
|
210
|
+
textWidth = Math.max(textWidth, estimate.textWidth);
|
|
211
|
+
}
|
|
212
|
+
// A small fractional buffer, not a whole extra line: wrapEstimate's greedy
|
|
213
|
+
// word-packing (with the same SCALE_SAFETY_MARGIN already folded into its
|
|
214
|
+
// own packing decisions) is the thing actually responsible for predicting
|
|
215
|
+
// the right line count now: inflating every box's height by a full line
|
|
216
|
+
// regardless of whether it needs one (an earlier version of this line)
|
|
217
|
+
// made every box taller than its label warranted — including single-word
|
|
218
|
+
// labels that never wrap at all ("Fin" got a 96px-tall box for 3
|
|
219
|
+
// characters) — which in turn made scaledExtent() shrink the whole
|
|
220
|
+
// diagram more aggressively to fit the page, which made
|
|
221
|
+
// SCALE_SAFETY_MARGIN's job *harder*, not easier. This buffer only has to
|
|
222
|
+
// cover descender/rounding slack at a line boundary.
|
|
223
|
+
const textHeight = (lines + 0.3) * LINE_HEIGHT_PX;
|
|
224
|
+
const rectWidth = textWidth + 2 * PAD_X;
|
|
225
|
+
const rectHeight = (textHeight + 2 * PAD_Y) * SCALE_SAFETY_MARGIN;
|
|
226
|
+
if (shape === 'diamond') {
|
|
227
|
+
return {
|
|
228
|
+
width: Math.max(NODE_WIDTH, 2 * rectWidth),
|
|
229
|
+
height: Math.max(NODE_HEIGHT, 2 * rectHeight),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
if (SLANTED_SHAPES.has(shape)) {
|
|
233
|
+
// Like diamond above, but milder: a hexagon/parallelogram/trapezoid's
|
|
234
|
+
// slanted sides eat into the corners of its bounding box, just less
|
|
235
|
+
// aggressively than a rhombus does. The text box itself isn't clipped by
|
|
236
|
+
// the shape outline (it's an independent overlay), but without this the
|
|
237
|
+
// label visibly overhangs the slant near a corner.
|
|
238
|
+
return {
|
|
239
|
+
width: Math.max(NODE_WIDTH, SLANTED_WIDTH_MARGIN * rectWidth),
|
|
240
|
+
height: Math.max(NODE_HEIGHT, rectHeight),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
width: Math.max(NODE_WIDTH, rectWidth),
|
|
245
|
+
height: Math.max(NODE_HEIGHT, rectHeight),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/** Node shapes whose sides slant inward, needing extra width so a label clears the corners. */
|
|
249
|
+
const SLANTED_SHAPES = new Set([
|
|
250
|
+
'hexagon',
|
|
251
|
+
'parallelogram',
|
|
252
|
+
'parallelogramAlt',
|
|
253
|
+
'trapezoid',
|
|
254
|
+
'trapezoidAlt',
|
|
255
|
+
]);
|
|
256
|
+
/** Extra width factor for {@link SLANTED_SHAPES}, well under diamond's 2x since the loss is milder. */
|
|
257
|
+
const SLANTED_WIDTH_MARGIN = 1.35;
|
|
258
|
+
/**
|
|
259
|
+
* Compute pixel coordinates for every node and subgraph in the flowchart.
|
|
260
|
+
* Returns a {@link LayoutResult} with node boxes and subgraph container boxes.
|
|
261
|
+
*/
|
|
262
|
+
export function layout(flowchart, options = {}) {
|
|
263
|
+
// Explicit nodeWidth/nodeHeight forces every node to that fixed size, as
|
|
264
|
+
// before (an escape hatch, e.g. for a caller comparing layouts head-to-head
|
|
265
|
+
// without label-length noise). Omitted (the normal case): each node is
|
|
266
|
+
// sized to its own label via nodeDimensions().
|
|
267
|
+
const fixedSize = options.nodeWidth !== undefined || options.nodeHeight !== undefined
|
|
268
|
+
? { width: options.nodeWidth ?? NODE_WIDTH, height: options.nodeHeight ?? NODE_HEIGHT }
|
|
269
|
+
: null;
|
|
270
|
+
const engine = options.engine ?? 'dagre';
|
|
271
|
+
if (engine === 'graphviz') {
|
|
272
|
+
// Graphviz-WASM is a reserved future option (ADR 0001). Not wired up yet.
|
|
273
|
+
throw new Error('Layout engine "graphviz" is not implemented yet (see ADR 0001).');
|
|
274
|
+
}
|
|
275
|
+
// Dagre's `rankdir` values are `TB`/`BT`/`LR`/`RL` — note `TB`, not `TD`.
|
|
276
|
+
// Mermaid's `TD` (top-down) had been passed straight through as the literal
|
|
277
|
+
// string `'TD'`, which isn't a value Dagre recognizes; it silently fell
|
|
278
|
+
// back to Dagre's own default (`TB`), which happens to coincide visually
|
|
279
|
+
// with `TD`, masking the mismatch. Mapped explicitly here now that `BT`/
|
|
280
|
+
// `RL` are real, distinct directions this parser produces (`parser.ts`).
|
|
281
|
+
const RANKDIR_BY_DIRECTION = {
|
|
282
|
+
TD: 'TB',
|
|
283
|
+
BT: 'BT',
|
|
284
|
+
LR: 'LR',
|
|
285
|
+
RL: 'RL',
|
|
286
|
+
};
|
|
287
|
+
const warnings = [];
|
|
288
|
+
const buildGraph = (useClusters) => {
|
|
289
|
+
const g = new dagre.graphlib.Graph({ compound: true });
|
|
290
|
+
g.setGraph({
|
|
291
|
+
rankdir: RANKDIR_BY_DIRECTION[flowchart.direction],
|
|
292
|
+
nodesep: RANK_GAP,
|
|
293
|
+
ranksep: LEVEL_GAP,
|
|
294
|
+
marginx: 0,
|
|
295
|
+
marginy: 0,
|
|
296
|
+
});
|
|
297
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
298
|
+
for (const node of flowchart.nodes) {
|
|
299
|
+
const { width, height } = fixedSize ?? nodeDimensions(node.labelRuns, node.shape);
|
|
300
|
+
g.setNode(node.id, { width, height });
|
|
301
|
+
}
|
|
302
|
+
for (const edge of flowchart.edges) {
|
|
303
|
+
if (g.hasNode(edge.from) && g.hasNode(edge.to)) {
|
|
304
|
+
g.setEdge(edge.from, edge.to);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (useClusters) {
|
|
308
|
+
// Register subgraphs as Dagre clusters and assign their nodes to them.
|
|
309
|
+
for (const sg of flowchart.subgraphs) {
|
|
310
|
+
g.setNode(sg.id, { width: 0, height: 0, cluster: true });
|
|
311
|
+
for (const nodeId of sg.nodeIds) {
|
|
312
|
+
if (g.hasNode(nodeId))
|
|
313
|
+
g.setParent(nodeId, sg.id);
|
|
314
|
+
}
|
|
315
|
+
for (const childId of sg.subgraphIds) {
|
|
316
|
+
if (g.hasNode(childId))
|
|
317
|
+
g.setParent(childId, sg.id);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return g;
|
|
322
|
+
};
|
|
323
|
+
// Dagre has a long-standing, unfixed bug (dagre is unmaintained upstream)
|
|
324
|
+
// where its `order` phase crashes — `Cannot set properties of undefined
|
|
325
|
+
// (setting 'order')` — on some large graphs that combine many compound
|
|
326
|
+
// clusters (subgraphs) with cycles among their members. Found empirically
|
|
327
|
+
// (2026-09-04) on a 169-node/295-edge/36-subgraph real-world fixture
|
|
328
|
+
// (`medium3.mmd`): reproduces with clustering on, but the identical
|
|
329
|
+
// node/edge set lays out fine with clustering off, and isolating the
|
|
330
|
+
// implicated subgraph alone (or pre-breaking every cycle before handing
|
|
331
|
+
// the graph to Dagre) does not stop the crash — so this is Dagre's own
|
|
332
|
+
// cluster+order interaction, not something this parser's output can
|
|
333
|
+
// sidestep by construction. Retrying without clusters trades subgraph
|
|
334
|
+
// container boxes (silently dropped by the translator when
|
|
335
|
+
// `layout.subgraphs` has no entry for an id, see `renderSubgraph`) for a
|
|
336
|
+
// diagram that still renders, instead of the whole export falling back to
|
|
337
|
+
// ~1000 lines of raw ```mermaid text (spec §10 "surface warnings" — this
|
|
338
|
+
// degradation is reported as a warning, not hidden).
|
|
339
|
+
let g = buildGraph(true);
|
|
340
|
+
try {
|
|
341
|
+
dagre.layout(g);
|
|
342
|
+
}
|
|
343
|
+
catch (err) {
|
|
344
|
+
if (flowchart.subgraphs.length === 0)
|
|
345
|
+
throw err;
|
|
346
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
347
|
+
warnings.push(`Layout with subgraph containers failed (${message}); retried without them -- subgraph boxes are omitted from this diagram.`);
|
|
348
|
+
g = buildGraph(false);
|
|
349
|
+
dagre.layout(g);
|
|
350
|
+
}
|
|
351
|
+
// Use a null-prototype object so hostile node ids like `__proto__` or
|
|
352
|
+
// `constructor` cannot collide with Object.prototype members (prototype
|
|
353
|
+
// pollution). This is a security boundary: node ids come from untrusted text.
|
|
354
|
+
const nodes = Object.create(null);
|
|
355
|
+
for (const node of flowchart.nodes) {
|
|
356
|
+
const n = g.node(node.id);
|
|
357
|
+
// Dagre positions by center; convert to top-left origin.
|
|
358
|
+
nodes[node.id] = {
|
|
359
|
+
x: n.x - n.width / 2,
|
|
360
|
+
y: n.y - n.height / 2,
|
|
361
|
+
width: n.width,
|
|
362
|
+
height: n.height,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
// Subgraph container boxes from Dagre cluster geometry.
|
|
366
|
+
const subgraphs = Object.create(null);
|
|
367
|
+
for (const sg of flowchart.subgraphs) {
|
|
368
|
+
const c = g.node(sg.id);
|
|
369
|
+
if (c) {
|
|
370
|
+
subgraphs[sg.id] = {
|
|
371
|
+
x: c.x - c.width / 2,
|
|
372
|
+
y: c.y - c.height / 2,
|
|
373
|
+
width: c.width,
|
|
374
|
+
height: c.height,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
// The route Dagre computed for each edge (>2 points when it routed around
|
|
379
|
+
// an intermediate rank's nodes — see LayoutPoint's doc comment). Captured
|
|
380
|
+
// in the same raw coordinate space as `nodes`/`subgraphs` above, before
|
|
381
|
+
// normalization.
|
|
382
|
+
const edges = flowchart.edges.map((edge) => {
|
|
383
|
+
const e = g.edge({ v: edge.from, w: edge.to });
|
|
384
|
+
return e ? e.points.map((p) => ({ x: p.x, y: p.y })) : [];
|
|
385
|
+
});
|
|
386
|
+
// Normalize so the top-left of the diagram is at (0,0), using ONE offset
|
|
387
|
+
// derived from nodes, subgraph boxes, AND edge routes, applied consistently
|
|
388
|
+
// to all three. A subgraph's cluster box is not just the tight bbox of its
|
|
389
|
+
// children — Dagre pads it with its own cluster margin — so it can extend
|
|
390
|
+
// further left/up than every node combined; computing the offset from
|
|
391
|
+
// nodes alone (an earlier version of this function did, matching the
|
|
392
|
+
// original pre-refactor code's behaviour for nodes) left such a subgraph at
|
|
393
|
+
// a negative x/y, which breaks rendering entirely (verified empirically:
|
|
394
|
+
// LibreOffice renders nothing at all for a drawing with a negative-origin
|
|
395
|
+
// child, no partial/degraded output). (That earlier version also inherited
|
|
396
|
+
// a second, previously-latent bug: subgraphs were normalized using the
|
|
397
|
+
// *already-normalized* nodes' minX/minY, i.e. always 0, so they were never
|
|
398
|
+
// actually shifted at all — invisible only because Dagre's raw subgraph
|
|
399
|
+
// origin happened to already be non-negative in every shape tried so far.)
|
|
400
|
+
// Edge routes joined the offset for the same reason (self-loop audit,
|
|
401
|
+
// 2026-09-04, punch list item 5): a self-loop's route bulges out past its
|
|
402
|
+
// own node's perimeter by construction (`ooxml-translator.ts`'s
|
|
403
|
+
// `connectorGeometry` doc comment) — every case actually exercised so far
|
|
404
|
+
// bulges toward positive x/y (away from the origin), but there is no
|
|
405
|
+
// guarantee from Dagre that some rankdir/position combination couldn't
|
|
406
|
+
// bulge the other way, and the failure mode if one ever did (an
|
|
407
|
+
// un-accounted-for negative coordinate) is the same total rendering
|
|
408
|
+
// failure the subgraph case above already hit once.
|
|
409
|
+
const [minX, minY] = boundsOrigin(nodes, subgraphs, edges);
|
|
410
|
+
const normalizedNodes = shiftLayout(nodes, minX, minY);
|
|
411
|
+
const normalizedSubgraphs = shiftSubgraphs(subgraphs, minX, minY);
|
|
412
|
+
const normalizedEdges = edges.map((points) => points.map((p) => ({ x: p.x - minX, y: p.y - minY })));
|
|
413
|
+
// Reserve title-bar space in every subgraph box (spec §6.1) — see
|
|
414
|
+
// reserveSubgraphTitleSpace for why this is safe to do once per subgraph,
|
|
415
|
+
// independent of nesting order. Edge routes are NOT shifted by this pass:
|
|
416
|
+
// the translator always re-derives an edge's actual start/end from the
|
|
417
|
+
// (already title-shifted) node boxes, so only an edge that both crosses a
|
|
418
|
+
// subgraph boundary AND routes around an intermediate rank could show a
|
|
419
|
+
// few-pixel seam at the boundary — accepted for now as a minor cosmetic
|
|
420
|
+
// gap, not a correctness one.
|
|
421
|
+
reserveSubgraphTitleSpace(flowchart, normalizedNodes, normalizedSubgraphs);
|
|
422
|
+
return { nodes: normalizedNodes, subgraphs: normalizedSubgraphs, edges: normalizedEdges, warnings };
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* The (minX, minY) across every node's top-left corner, every subgraph's
|
|
426
|
+
* top-left corner, AND every edge route point, or (0, 0) if there are none.
|
|
427
|
+
* Must include subgraphs and edges — see the caller.
|
|
428
|
+
*/
|
|
429
|
+
function boundsOrigin(nodes, subgraphs, edges) {
|
|
430
|
+
let minX = Infinity;
|
|
431
|
+
let minY = Infinity;
|
|
432
|
+
for (const box of Object.values(nodes)) {
|
|
433
|
+
minX = Math.min(minX, box.x);
|
|
434
|
+
minY = Math.min(minY, box.y);
|
|
435
|
+
}
|
|
436
|
+
for (const box of Object.values(subgraphs)) {
|
|
437
|
+
minX = Math.min(minX, box.x);
|
|
438
|
+
minY = Math.min(minY, box.y);
|
|
439
|
+
}
|
|
440
|
+
for (const points of edges) {
|
|
441
|
+
for (const point of points) {
|
|
442
|
+
minX = Math.min(minX, point.x);
|
|
443
|
+
minY = Math.min(minY, point.y);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return minX === Infinity ? [0, 0] : [minX, minY];
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Collect every node id transitively contained in a subgraph (direct members
|
|
450
|
+
* plus members of any nested subgraph, at any depth).
|
|
451
|
+
*/
|
|
452
|
+
function descendantNodeIds(sg, flowchart) {
|
|
453
|
+
const ids = [...sg.nodeIds];
|
|
454
|
+
for (const childId of sg.subgraphIds) {
|
|
455
|
+
const child = flowchart.subgraphs.find((s) => s.id === childId);
|
|
456
|
+
if (child)
|
|
457
|
+
ids.push(...descendantNodeIds(child, flowchart));
|
|
458
|
+
}
|
|
459
|
+
return ids;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Collect every subgraph id transitively nested inside a subgraph (its direct
|
|
463
|
+
* children plus their own children, at any depth) — not including `sg`
|
|
464
|
+
* itself.
|
|
465
|
+
*/
|
|
466
|
+
function descendantSubgraphIds(sg, flowchart) {
|
|
467
|
+
const ids = [];
|
|
468
|
+
for (const childId of sg.subgraphIds) {
|
|
469
|
+
ids.push(childId);
|
|
470
|
+
const child = flowchart.subgraphs.find((s) => s.id === childId);
|
|
471
|
+
if (child)
|
|
472
|
+
ids.push(...descendantSubgraphIds(child, flowchart));
|
|
473
|
+
}
|
|
474
|
+
return ids;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Grow every subgraph's box by `SUBGRAPH_TITLE_HEIGHT` and push its
|
|
478
|
+
* descendants down by the same amount, mutating `nodes`/`subgraphs` in place.
|
|
479
|
+
*
|
|
480
|
+
* Order does not matter: each subgraph's adjustment only reads the flowchart's
|
|
481
|
+
* static containment tree (`nodeIds`/`subgraphIds`), never another
|
|
482
|
+
* subgraph's already-mutated box, so processing subgraphs in any order (or in
|
|
483
|
+
* parallel, conceptually) yields the same final, self-consistent result. A
|
|
484
|
+
* node nested two levels deep ends up shifted down by two title heights, one
|
|
485
|
+
* per ancestor subgraph — correct, since there are two title bars stacked
|
|
486
|
+
* above it.
|
|
487
|
+
*/
|
|
488
|
+
function reserveSubgraphTitleSpace(flowchart, nodes, subgraphs) {
|
|
489
|
+
for (const sg of flowchart.subgraphs) {
|
|
490
|
+
const box = subgraphs[sg.id];
|
|
491
|
+
if (!box)
|
|
492
|
+
continue;
|
|
493
|
+
for (const nodeId of descendantNodeIds(sg, flowchart)) {
|
|
494
|
+
const n = nodes[nodeId];
|
|
495
|
+
if (n)
|
|
496
|
+
n.y += SUBGRAPH_TITLE_HEIGHT;
|
|
497
|
+
}
|
|
498
|
+
for (const childId of descendantSubgraphIds(sg, flowchart)) {
|
|
499
|
+
const childBox = subgraphs[childId];
|
|
500
|
+
if (childBox)
|
|
501
|
+
childBox.y += SUBGRAPH_TITLE_HEIGHT;
|
|
502
|
+
}
|
|
503
|
+
box.height += SUBGRAPH_TITLE_HEIGHT;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function shiftSubgraphs(subgraphs, offsetX, offsetY) {
|
|
507
|
+
const out = Object.create(null);
|
|
508
|
+
for (const [id, box] of Object.entries(subgraphs)) {
|
|
509
|
+
out[id] = { ...box, x: box.x - offsetX, y: box.y - offsetY };
|
|
510
|
+
}
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
513
|
+
function shiftLayout(layout, offsetX, offsetY) {
|
|
514
|
+
const out = Object.create(null);
|
|
515
|
+
for (const [id, box] of Object.entries(layout)) {
|
|
516
|
+
out[id] = { ...box, x: box.x - offsetX, y: box.y - offsetY };
|
|
517
|
+
}
|
|
518
|
+
return out;
|
|
519
|
+
}
|
|
520
|
+
/** Compute the total bounding box of a layout, in pixels. */
|
|
521
|
+
export function boundingBox(layout) {
|
|
522
|
+
let minX = Infinity;
|
|
523
|
+
let minY = Infinity;
|
|
524
|
+
let maxX = -Infinity;
|
|
525
|
+
let maxY = -Infinity;
|
|
526
|
+
for (const box of Object.values(layout)) {
|
|
527
|
+
minX = Math.min(minX, box.x);
|
|
528
|
+
minY = Math.min(minY, box.y);
|
|
529
|
+
maxX = Math.max(maxX, box.x + box.width);
|
|
530
|
+
maxY = Math.max(maxY, box.y + box.height);
|
|
531
|
+
}
|
|
532
|
+
if (minX === Infinity)
|
|
533
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
534
|
+
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
535
|
+
}
|
|
536
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/layout/layout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAC7B,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAC9B,qDAAqD;AACrD,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,kCAAkC;AAClC,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AASxC;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;2DAM2D;AAC3D,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,2EAA2E;AAC3E,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,wEAAwE;AACxE,MAAM,KAAK,GAAG,EAAE,CAAC;AACjB,MAAM,KAAK,GAAG,EAAE,CAAC;AACjB;;;;;;;;;GASG;AACH,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC;;;;;;;;;;GAUG;AACH,MAAM,iBAAiB,GAAG;IACxB,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,GAAG;CACF,CAAC;AAEX;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,aAAqB,YAAY;IAC/E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G,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IAClE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cheap diagram-type guard-rail (`docs/specs/FUTURE_full_mermaid_coverage_SPEC.md`
|
|
3
|
+
* §4 "Phase 0", item 1). `parseMermaid()` has zero notion of "this isn't a
|
|
4
|
+
* flowchart" — it just reads whatever text it's given and does its best to
|
|
5
|
+
* find flowchart-shaped statements in it. That's fine for actual flowcharts
|
|
6
|
+
* (and for genuinely malformed input — the fuzz suite requires `parseMermaid`
|
|
7
|
+
* to never throw on arbitrary text), but it means a diagram written in one of
|
|
8
|
+
* Mermaid's other ~28 syntaxes can produce a silently-wrong result: `gitGraph`
|
|
9
|
+
* bare words and `mindmap` `((...))` bullets happen to look enough like valid
|
|
10
|
+
* flowchart node syntax to "parse" into a nonsense diagram instead of being
|
|
11
|
+
* cleanly rejected.
|
|
12
|
+
*
|
|
13
|
+
* This module is deliberately separate from `parser.ts` and knows nothing
|
|
14
|
+
* about OOXML — it only classifies the *first significant line* of the raw
|
|
15
|
+
* Mermaid text. Callers (`packages/pandoc-filter/bin/md2nativedocx-core.mjs`)
|
|
16
|
+
* use it to decide, before ever calling `parseMermaid()`, whether to run the
|
|
17
|
+
* flowchart pipeline at all.
|
|
18
|
+
*/
|
|
19
|
+
/** One of Mermaid's ~28 non-flowchart diagram types that this project does
|
|
20
|
+
* not implement yet, or `'flowchart'`/`'unknown'`. See module doc comment. */
|
|
21
|
+
export type DiagramType = 'flowchart' | 'unknown' | 'sequence' | 'class' | 'state' | 'er' | 'journey' | 'gantt' | 'pie' | 'quadrant' | 'requirement' | 'gitGraph' | 'c4' | 'mindmap' | 'timeline' | 'zenuml' | 'sankey' | 'xychart' | 'block' | 'packet' | 'kanban' | 'architecture' | 'radar' | 'eventModeling' | 'treemap' | 'venn' | 'ishikawa' | 'wardley' | 'cynefin' | 'treeView';
|
|
22
|
+
export interface DiagramTypeInfo {
|
|
23
|
+
type: DiagramType;
|
|
24
|
+
/** Mermaid's own name for the type, for warnings/notes shown to the user. */
|
|
25
|
+
label: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Classify raw Mermaid text by its first significant line (skipping blank
|
|
29
|
+
* lines and `%%`-prefixed comments/init directives, same convention as
|
|
30
|
+
* `parseMermaid()`).
|
|
31
|
+
*
|
|
32
|
+
* Returns `'unknown'` — not a diversion type — when nothing recognized
|
|
33
|
+
* matches, including a missing `graph`/`flowchart` header entirely. This is
|
|
34
|
+
* deliberate: real Mermaid requires that header, but `parseMermaid()` itself
|
|
35
|
+
* has never enforced it (the fuzz suite requires it to accept arbitrary text
|
|
36
|
+
* without throwing), so treating "no recognized header" as license to divert
|
|
37
|
+
* away from the flowchart pipeline would be a behavior change with no actual
|
|
38
|
+
* evidence backing it. Only an *explicitly recognized* non-flowchart keyword
|
|
39
|
+
* should divert — that's the one case with a real, cheaply-detectable signal.
|
|
40
|
+
*/
|
|
41
|
+
export declare function detectDiagramType(text: string): DiagramTypeInfo;
|