zombie-mermaid 2.2.3 → 2.2.6

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 (321) hide show
  1. package/README.md +4 -4
  2. package/dist/ascii.cjs +1 -11
  3. package/dist/ascii.d.cts +1 -167
  4. package/dist/ascii.d.ts +1 -167
  5. package/dist/ascii.js +1 -6591
  6. package/dist/cli.js +836 -10946
  7. package/dist/index.cjs +2 -81
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +42 -680
  10. package/dist/index.d.ts +42 -680
  11. package/dist/index.js +408 -10002
  12. package/dist/index.js.map +1 -1
  13. package/dist/mcp.cjs +1 -17909
  14. package/dist/mcp.d.cts +1 -11
  15. package/dist/mcp.d.ts +1 -11
  16. package/dist/mcp.js +1 -17884
  17. package/package.json +29 -29
  18. package/src/__tests__/workspace-package-boundaries.test.ts +15 -16
  19. package/src/__tests__/xychart-parser-categories.test.ts +78 -0
  20. package/src/ascii-entry.ts +14 -0
  21. package/src/cli/html-viewer.ts +5 -0
  22. package/src/mcp-entry.ts +21 -0
  23. package/dist/ascii.cjs.map +0 -1
  24. package/dist/ascii.js.map +0 -1
  25. package/dist/mcp.cjs.map +0 -1
  26. package/dist/mcp.js.map +0 -1
  27. package/packages/ascii-renderer/LICENSE +0 -22
  28. package/packages/ascii-renderer/src/ansi.ts +0 -490
  29. package/packages/ascii-renderer/src/canvas.ts +0 -658
  30. package/packages/ascii-renderer/src/class-diagram.ts +0 -2001
  31. package/packages/ascii-renderer/src/converter.ts +0 -446
  32. package/packages/ascii-renderer/src/coords.ts +0 -58
  33. package/packages/ascii-renderer/src/display-width.ts +0 -151
  34. package/packages/ascii-renderer/src/draw-arrows.ts +0 -549
  35. package/packages/ascii-renderer/src/draw-boxes.ts +0 -267
  36. package/packages/ascii-renderer/src/draw-bundles.ts +0 -611
  37. package/packages/ascii-renderer/src/draw-lines.ts +0 -174
  38. package/packages/ascii-renderer/src/draw-subgraphs.ts +0 -108
  39. package/packages/ascii-renderer/src/draw.ts +0 -337
  40. package/packages/ascii-renderer/src/edge-bundling.ts +0 -435
  41. package/packages/ascii-renderer/src/edge-cell-styles.ts +0 -81
  42. package/packages/ascii-renderer/src/edge-routing.ts +0 -1049
  43. package/packages/ascii-renderer/src/er-diagram.ts +0 -1488
  44. package/packages/ascii-renderer/src/flowchart.ts +0 -94
  45. package/packages/ascii-renderer/src/grid-occupancy.ts +0 -234
  46. package/packages/ascii-renderer/src/grid.ts +0 -1267
  47. package/packages/ascii-renderer/src/hyperlinks.ts +0 -248
  48. package/packages/ascii-renderer/src/index.ts +0 -163
  49. package/packages/ascii-renderer/src/lane-search.ts +0 -68
  50. package/packages/ascii-renderer/src/multiline-utils.ts +0 -82
  51. package/packages/ascii-renderer/src/pathfinder.ts +0 -448
  52. package/packages/ascii-renderer/src/registry.ts +0 -88
  53. package/packages/ascii-renderer/src/sequence.ts +0 -1318
  54. package/packages/ascii-renderer/src/shapes/circle.ts +0 -31
  55. package/packages/ascii-renderer/src/shapes/corners.ts +0 -273
  56. package/packages/ascii-renderer/src/shapes/diamond.ts +0 -31
  57. package/packages/ascii-renderer/src/shapes/hexagon.ts +0 -31
  58. package/packages/ascii-renderer/src/shapes/index.ts +0 -123
  59. package/packages/ascii-renderer/src/shapes/rectangle.ts +0 -199
  60. package/packages/ascii-renderer/src/shapes/rounded.ts +0 -31
  61. package/packages/ascii-renderer/src/shapes/special.ts +0 -352
  62. package/packages/ascii-renderer/src/shapes/stadium.ts +0 -122
  63. package/packages/ascii-renderer/src/shapes/state.ts +0 -204
  64. package/packages/ascii-renderer/src/shapes/types.ts +0 -78
  65. package/packages/ascii-renderer/src/territory.ts +0 -136
  66. package/packages/ascii-renderer/src/types.ts +0 -454
  67. package/packages/ascii-renderer/src/validate.ts +0 -189
  68. package/packages/ascii-renderer/src/xychart.ts +0 -1085
  69. package/packages/core/LICENSE +0 -22
  70. package/packages/core/src/click-directive.ts +0 -106
  71. package/packages/core/src/color-utils.ts +0 -205
  72. package/packages/core/src/diagram-type.ts +0 -35
  73. package/packages/core/src/direction-override.ts +0 -46
  74. package/packages/core/src/direction.ts +0 -56
  75. package/packages/core/src/index.ts +0 -34
  76. package/packages/core/src/init-directive.ts +0 -248
  77. package/packages/core/src/multiline-utils.ts +0 -275
  78. package/packages/core/src/statements.ts +0 -197
  79. package/packages/core/src/style-directives.ts +0 -214
  80. package/packages/core/src/text-metrics.ts +0 -498
  81. package/packages/core/src/theme.ts +0 -696
  82. package/packages/core/src/types.ts +0 -670
  83. package/packages/mcp/LICENSE +0 -22
  84. package/packages/mcp/src/index.ts +0 -17
  85. package/packages/mcp/src/server.ts +0 -135
  86. package/packages/mcp/src/tools/check-sequence-activations.ts +0 -91
  87. package/packages/mcp/src/tools/fix-sequence-activations.ts +0 -77
  88. package/packages/mcp/src/tools/render-ascii.ts +0 -99
  89. package/packages/mcp/src/tools/render-svg.ts +0 -95
  90. package/packages/mermaid-parser/LICENSE +0 -22
  91. package/packages/mermaid-parser/src/class/format.ts +0 -15
  92. package/packages/mermaid-parser/src/class/parser.ts +0 -593
  93. package/packages/mermaid-parser/src/class/types.ts +0 -166
  94. package/packages/mermaid-parser/src/er/parser.ts +0 -286
  95. package/packages/mermaid-parser/src/er/types.ts +0 -99
  96. package/packages/mermaid-parser/src/expanded-shapes.ts +0 -376
  97. package/packages/mermaid-parser/src/index.ts +0 -48
  98. package/packages/mermaid-parser/src/sequence/activation-check.ts +0 -149
  99. package/packages/mermaid-parser/src/sequence/activation-fix.ts +0 -112
  100. package/packages/mermaid-parser/src/sequence/box-color.ts +0 -85
  101. package/packages/mermaid-parser/src/sequence/parser.ts +0 -613
  102. package/packages/mermaid-parser/src/sequence/types.ts +0 -242
  103. package/packages/mermaid-parser/src/xychart/colors.ts +0 -177
  104. package/packages/mermaid-parser/src/xychart/parser.ts +0 -203
  105. package/packages/mermaid-parser/src/xychart/types.ts +0 -150
  106. package/packages/svg-renderer/LICENSE +0 -22
  107. package/packages/svg-renderer/src/class/layout.ts +0 -360
  108. package/packages/svg-renderer/src/class/renderer.ts +0 -636
  109. package/packages/svg-renderer/src/edge-curves.ts +0 -204
  110. package/packages/svg-renderer/src/elk-instance.ts +0 -292
  111. package/packages/svg-renderer/src/er/layout.ts +0 -200
  112. package/packages/svg-renderer/src/er/renderer.ts +0 -493
  113. package/packages/svg-renderer/src/index.ts +0 -58
  114. package/packages/svg-renderer/src/layout-engine/constants.ts +0 -19
  115. package/packages/svg-renderer/src/layout-engine/edge-bundling.ts +0 -379
  116. package/packages/svg-renderer/src/layout-engine/elk-adapter-utils.ts +0 -81
  117. package/packages/svg-renderer/src/layout-engine/elk-graph-builder.ts +0 -240
  118. package/packages/svg-renderer/src/layout-engine/from-elk.ts +0 -685
  119. package/packages/svg-renderer/src/layout-engine/layer-alignment.ts +0 -174
  120. package/packages/svg-renderer/src/layout-engine/to-elk.ts +0 -695
  121. package/packages/svg-renderer/src/layout-engine.ts +0 -74
  122. package/packages/svg-renderer/src/layout.ts +0 -8
  123. package/packages/svg-renderer/src/renderer.ts +0 -1485
  124. package/packages/svg-renderer/src/resolve-colors.ts +0 -339
  125. package/packages/svg-renderer/src/sequence/layout.ts +0 -698
  126. package/packages/svg-renderer/src/sequence/renderer.ts +0 -546
  127. package/packages/svg-renderer/src/shape-clipping.ts +0 -197
  128. package/packages/svg-renderer/src/styles.ts +0 -118
  129. package/packages/svg-renderer/src/xychart/layout.ts +0 -682
  130. package/packages/svg-renderer/src/xychart/renderer.ts +0 -684
  131. package/src/__tests__/ascii-canvas-write.test.ts +0 -137
  132. package/src/__tests__/ascii-charset-border-junctions.test.ts +0 -63
  133. package/src/__tests__/ascii-cjk-width.test.ts +0 -150
  134. package/src/__tests__/ascii-class-box-occupancy.test.ts +0 -462
  135. package/src/__tests__/ascii-class-column-width-488-489.test.ts +0 -639
  136. package/src/__tests__/ascii-class-cross-level-jog-corruption.test.ts +0 -187
  137. package/src/__tests__/ascii-class-detour-label-routing-487.test.ts +0 -114
  138. package/src/__tests__/ascii-class-diagram-compartments.test.ts +0 -70
  139. package/src/__tests__/ascii-class-label-box-collision.test.ts +0 -60
  140. package/src/__tests__/ascii-class-label-row-collision-531.test.ts +0 -135
  141. package/src/__tests__/ascii-class-label-territory-row-awareness.test.ts +0 -57
  142. package/src/__tests__/ascii-class-padding.test.ts +0 -104
  143. package/src/__tests__/ascii-class-parent-alignment-971.test.ts +0 -139
  144. package/src/__tests__/ascii-class-parent-alignment-972.test.ts +0 -208
  145. package/src/__tests__/ascii-class-reciprocal-relationships-448.test.ts +0 -169
  146. package/src/__tests__/ascii-combining-mark-width.test.ts +0 -70
  147. package/src/__tests__/ascii-coords-overlay.test.ts +0 -64
  148. package/src/__tests__/ascii-decision-lr-box-start.test.ts +0 -106
  149. package/src/__tests__/ascii-display-width-unit.test.ts +0 -154
  150. package/src/__tests__/ascii-draw-arrows-coverage.test.ts +0 -171
  151. package/src/__tests__/ascii-draw-arrows-single-point-path.test.ts +0 -112
  152. package/src/__tests__/ascii-edge-bundling-rank-violation-454.test.ts +0 -72
  153. package/src/__tests__/ascii-edge-ending-glyphs.test.ts +0 -206
  154. package/src/__tests__/ascii-edge-label-diagonal-fallback-418.test.ts +0 -95
  155. package/src/__tests__/ascii-edge-routing-fixes.test.ts +0 -178
  156. package/src/__tests__/ascii-edge-routing-single-point-path.test.ts +0 -107
  157. package/src/__tests__/ascii-edge-styles.test.ts +0 -149
  158. package/src/__tests__/ascii-emoji-cluster-width.test.ts +0 -101
  159. package/src/__tests__/ascii-er-box-occupancy.test.ts +0 -251
  160. package/src/__tests__/ascii-er-cardinality.test.ts +0 -40
  161. package/src/__tests__/ascii-er-corner-glyphs.test.ts +0 -249
  162. package/src/__tests__/ascii-er-jog-stray-line.test.ts +0 -111
  163. package/src/__tests__/ascii-er-label-padding.test.ts +0 -118
  164. package/src/__tests__/ascii-er-padding.test.ts +0 -114
  165. package/src/__tests__/ascii-er-relationship-label-corruption-350.test.ts +0 -458
  166. package/src/__tests__/ascii-er-relationship-overwrite.test.ts +0 -325
  167. package/src/__tests__/ascii-er-stray-connectors.test.ts +0 -347
  168. package/src/__tests__/ascii-er-unrelated-stem-separation-411.test.ts +0 -98
  169. package/src/__tests__/ascii-er-vertical-one-marker.test.ts +0 -110
  170. package/src/__tests__/ascii-label-line-terminal-fallback.test.ts +0 -172
  171. package/src/__tests__/ascii-lane-search.test.ts +0 -207
  172. package/src/__tests__/ascii-multibox-cjk-width.test.ts +0 -184
  173. package/src/__tests__/ascii-multiline.test.ts +0 -291
  174. package/src/__tests__/ascii-padding-edge-cases.test.ts +0 -154
  175. package/src/__tests__/ascii-pathfinder-route-edge.test.ts +0 -194
  176. package/src/__tests__/ascii-sequence-alt-else-label.test.ts +0 -236
  177. package/src/__tests__/ascii-sequence-block-wall-clearance.test.ts +0 -217
  178. package/src/__tests__/ascii-sequence-box-group.test.ts +0 -159
  179. package/src/__tests__/ascii-sequence-cjk-width.test.ts +0 -235
  180. package/src/__tests__/ascii-sequence-create-destroy.test.ts +0 -114
  181. package/src/__tests__/ascii-sequence-form-invariants.test.ts +0 -432
  182. package/src/__tests__/ascii-sequence-mermaid-parity.test.ts +0 -219
  183. package/src/__tests__/ascii-sequence-notes.test.ts +0 -61
  184. package/src/__tests__/ascii-sequence-padding.test.ts +0 -119
  185. package/src/__tests__/ascii-sequence-self-arrow.test.ts +0 -206
  186. package/src/__tests__/ascii-shape-diamond.test.ts +0 -38
  187. package/src/__tests__/ascii-shape-rectangle.test.ts +0 -258
  188. package/src/__tests__/ascii-shape-rounded.test.ts +0 -36
  189. package/src/__tests__/ascii-shapes-circle.test.ts +0 -41
  190. package/src/__tests__/ascii-shapes-hexagon.test.ts +0 -42
  191. package/src/__tests__/ascii-shapes-special.test.ts +0 -349
  192. package/src/__tests__/ascii-shapes-stadium.test.ts +0 -217
  193. package/src/__tests__/ascii-shapes-state.test.ts +0 -234
  194. package/src/__tests__/ascii-state-bidirectional-label-swap-530.test.ts +0 -130
  195. package/src/__tests__/ascii-subgraph-direction-honored-445.test.ts +0 -90
  196. package/src/__tests__/ascii-subgraph-label-border-clip.test.ts +0 -152
  197. package/src/__tests__/ascii-subgraph-title-padding.test.ts +0 -77
  198. package/src/__tests__/ascii-territory-unit.test.ts +0 -219
  199. package/src/__tests__/ascii-validate.test.ts +0 -220
  200. package/src/__tests__/ascii.test.ts +0 -328
  201. package/src/__tests__/box-color.test.ts +0 -80
  202. package/src/__tests__/class-arrow-directions.test.ts +0 -505
  203. package/src/__tests__/click-directive.test.ts +0 -63
  204. package/src/__tests__/color-utils.test.ts +0 -186
  205. package/src/__tests__/diagram-type.test.ts +0 -28
  206. package/src/__tests__/draw-lines.test.ts +0 -93
  207. package/src/__tests__/edge-cell-styles.test.ts +0 -180
  208. package/src/__tests__/elk-adapter-utils.test.ts +0 -166
  209. package/src/__tests__/grid-occupancy.test.ts +0 -240
  210. package/src/__tests__/helpers/ascii-form.ts +0 -142
  211. package/src/__tests__/helpers/terminal-display-width.ts +0 -74
  212. package/src/__tests__/mcp-check-sequence-activations-tool.test.ts +0 -85
  213. package/src/__tests__/mcp-fix-sequence-activations-tool.test.ts +0 -134
  214. package/src/__tests__/mcp-server.test.ts +0 -163
  215. package/src/__tests__/pathfinder.test.ts +0 -246
  216. package/src/__tests__/sequence-activation-fix.test.ts +0 -91
  217. package/src/__tests__/testdata/ascii/ampersand_lhs.txt +0 -18
  218. package/src/__tests__/testdata/ascii/ampersand_lhs_and_rhs.txt +0 -18
  219. package/src/__tests__/testdata/ascii/ampersand_rhs.txt +0 -18
  220. package/src/__tests__/testdata/ascii/ampersand_td_fanin.txt +0 -18
  221. package/src/__tests__/testdata/ascii/ampersand_td_fanout.txt +0 -18
  222. package/src/__tests__/testdata/ascii/ampersand_without_edge.txt +0 -18
  223. package/src/__tests__/testdata/ascii/back_reference_from_child.txt +0 -10
  224. package/src/__tests__/testdata/ascii/backlink_from_bottom.txt +0 -22
  225. package/src/__tests__/testdata/ascii/backlink_from_top.txt +0 -22
  226. package/src/__tests__/testdata/ascii/backlink_with_short_y_padding.txt +0 -20
  227. package/src/__tests__/testdata/ascii/cls_all_relationships.txt +0 -19
  228. package/src/__tests__/testdata/ascii/cls_annotation.txt +0 -29
  229. package/src/__tests__/testdata/ascii/cls_association.txt +0 -14
  230. package/src/__tests__/testdata/ascii/cls_basic.txt +0 -15
  231. package/src/__tests__/testdata/ascii/cls_dependency.txt +0 -14
  232. package/src/__tests__/testdata/ascii/cls_inheritance.txt +0 -20
  233. package/src/__tests__/testdata/ascii/cls_methods.txt +0 -21
  234. package/src/__tests__/testdata/ascii/comments.txt +0 -23
  235. package/src/__tests__/testdata/ascii/custom_padding.txt +0 -10
  236. package/src/__tests__/testdata/ascii/duplicate_labels.txt +0 -19
  237. package/src/__tests__/testdata/ascii/er_attributes.txt +0 -21
  238. package/src/__tests__/testdata/ascii/er_basic.txt +0 -8
  239. package/src/__tests__/testdata/ascii/er_identifying.txt +0 -18
  240. package/src/__tests__/testdata/ascii/flowchart_tb_simple.txt +0 -29
  241. package/src/__tests__/testdata/ascii/graph_bt_direction.txt +0 -28
  242. package/src/__tests__/testdata/ascii/graph_tb_direction.txt +0 -26
  243. package/src/__tests__/testdata/ascii/nested_subgraphs_with_labels.txt +0 -36
  244. package/src/__tests__/testdata/ascii/preserve_order_of_definition.txt +0 -23
  245. package/src/__tests__/testdata/ascii/self_reference.txt +0 -10
  246. package/src/__tests__/testdata/ascii/self_reference_with_edge.txt +0 -10
  247. package/src/__tests__/testdata/ascii/seq_basic.txt +0 -17
  248. package/src/__tests__/testdata/ascii/seq_multiple_messages.txt +0 -25
  249. package/src/__tests__/testdata/ascii/seq_self_message.txt +0 -18
  250. package/src/__tests__/testdata/ascii/single_node.txt +0 -8
  251. package/src/__tests__/testdata/ascii/single_node_longer_name.txt +0 -8
  252. package/src/__tests__/testdata/ascii/subgraph_complex_mixed.txt +0 -38
  253. package/src/__tests__/testdata/ascii/subgraph_complex_nested.txt +0 -49
  254. package/src/__tests__/testdata/ascii/subgraph_direction_override.txt +0 -47
  255. package/src/__tests__/testdata/ascii/subgraph_empty.txt +0 -10
  256. package/src/__tests__/testdata/ascii/subgraph_mixed_nodes.txt +0 -20
  257. package/src/__tests__/testdata/ascii/subgraph_mixed_nodes_td.txt +0 -48
  258. package/src/__tests__/testdata/ascii/subgraph_multiple_edges.txt +0 -32
  259. package/src/__tests__/testdata/ascii/subgraph_multiple_nodes.txt +0 -16
  260. package/src/__tests__/testdata/ascii/subgraph_nested.txt +0 -24
  261. package/src/__tests__/testdata/ascii/subgraph_nested_with_external.txt +0 -30
  262. package/src/__tests__/testdata/ascii/subgraph_node_outside_lr.txt +0 -17
  263. package/src/__tests__/testdata/ascii/subgraph_single_node.txt +0 -16
  264. package/src/__tests__/testdata/ascii/subgraph_td_direction.txt +0 -26
  265. package/src/__tests__/testdata/ascii/subgraph_td_multiple.txt +0 -44
  266. package/src/__tests__/testdata/ascii/subgraph_td_multiple_paddingy.txt +0 -42
  267. package/src/__tests__/testdata/ascii/subgraph_three_levels_nested.txt +0 -32
  268. package/src/__tests__/testdata/ascii/subgraph_three_separate.txt +0 -24
  269. package/src/__tests__/testdata/ascii/subgraph_two_separate.txt +0 -20
  270. package/src/__tests__/testdata/ascii/subgraph_with_labels.txt +0 -20
  271. package/src/__tests__/testdata/ascii/three_nodes.txt +0 -9
  272. package/src/__tests__/testdata/ascii/three_nodes_single_line.txt +0 -8
  273. package/src/__tests__/testdata/ascii/two_layer_single_graph.txt +0 -19
  274. package/src/__tests__/testdata/ascii/two_layer_single_graph_longer_names.txt +0 -19
  275. package/src/__tests__/testdata/ascii/two_nodes_linked.txt +0 -8
  276. package/src/__tests__/testdata/ascii/two_nodes_longer_names.txt +0 -8
  277. package/src/__tests__/testdata/ascii/two_root_nodes.txt +0 -19
  278. package/src/__tests__/testdata/ascii/two_root_nodes_longer_names.txt +0 -19
  279. package/src/__tests__/testdata/ascii/two_single_root_nodes.txt +0 -19
  280. package/src/__tests__/testdata/unicode/ampersand_lhs.txt +0 -18
  281. package/src/__tests__/testdata/unicode/ampersand_lhs_and_rhs.txt +0 -18
  282. package/src/__tests__/testdata/unicode/ampersand_rhs.txt +0 -18
  283. package/src/__tests__/testdata/unicode/ampersand_without_edge.txt +0 -18
  284. package/src/__tests__/testdata/unicode/back_reference_from_child.txt +0 -10
  285. package/src/__tests__/testdata/unicode/backlink_from_bottom.txt +0 -22
  286. package/src/__tests__/testdata/unicode/backlink_from_top.txt +0 -22
  287. package/src/__tests__/testdata/unicode/cls_all_relationships.txt +0 -19
  288. package/src/__tests__/testdata/unicode/cls_annotation.txt +0 -29
  289. package/src/__tests__/testdata/unicode/cls_association.txt +0 -14
  290. package/src/__tests__/testdata/unicode/cls_basic.txt +0 -15
  291. package/src/__tests__/testdata/unicode/cls_dependency.txt +0 -14
  292. package/src/__tests__/testdata/unicode/cls_inheritance.txt +0 -20
  293. package/src/__tests__/testdata/unicode/cls_methods.txt +0 -21
  294. package/src/__tests__/testdata/unicode/comments.txt +0 -23
  295. package/src/__tests__/testdata/unicode/duplicate_labels.txt +0 -19
  296. package/src/__tests__/testdata/unicode/er_attributes.txt +0 -21
  297. package/src/__tests__/testdata/unicode/er_basic.txt +0 -8
  298. package/src/__tests__/testdata/unicode/er_identifying.txt +0 -18
  299. package/src/__tests__/testdata/unicode/graph_bt_direction.txt +0 -28
  300. package/src/__tests__/testdata/unicode/preserve_order_of_definition.txt +0 -23
  301. package/src/__tests__/testdata/unicode/self_reference.txt +0 -10
  302. package/src/__tests__/testdata/unicode/self_reference_with_edge.txt +0 -10
  303. package/src/__tests__/testdata/unicode/seq_basic.txt +0 -17
  304. package/src/__tests__/testdata/unicode/seq_multiple_messages.txt +0 -25
  305. package/src/__tests__/testdata/unicode/seq_self_message.txt +0 -18
  306. package/src/__tests__/testdata/unicode/single_node.txt +0 -8
  307. package/src/__tests__/testdata/unicode/single_node_longer_name.txt +0 -8
  308. package/src/__tests__/testdata/unicode/three_nodes.txt +0 -9
  309. package/src/__tests__/testdata/unicode/three_nodes_single_line.txt +0 -8
  310. package/src/__tests__/testdata/unicode/two_layer_single_graph.txt +0 -19
  311. package/src/__tests__/testdata/unicode/two_layer_single_graph_longer_names.txt +0 -19
  312. package/src/__tests__/testdata/unicode/two_nodes_linked.txt +0 -8
  313. package/src/__tests__/testdata/unicode/two_nodes_longer_names.txt +0 -8
  314. package/src/__tests__/testdata/unicode/two_root_nodes.txt +0 -19
  315. package/src/__tests__/testdata/unicode/two_root_nodes_longer_names.txt +0 -19
  316. package/src/__tests__/testdata/unicode/two_single_root_nodes.txt +0 -19
  317. package/src/__tests__/text-metrics.test.ts +0 -473
  318. package/src/__tests__/theme-palette-contrast.test.ts +0 -84
  319. package/src/__tests__/theme.test.ts +0 -132
  320. package/src/__tests__/xychart-ascii.test.ts +0 -376
  321. package/src/__tests__/xychart-colors.test.ts +0 -149
@@ -1,204 +0,0 @@
1
- // ============================================================================
2
- // zombie-mermaid — edge path interpolation (Mermaid's `flowchart.curve`)
3
- //
4
- // ELK routes an edge as a list of bend points. How those points are joined
5
- // into a drawn line is a separate, purely presentational choice, which
6
- // Mermaid exposes as `%%{init: {"flowchart": {"curve": "basis"}}}%%`.
7
- //
8
- // Every curve here consumes the same routed points, so switching styles never
9
- // changes where an edge goes — only how it looks getting there.
10
- // ============================================================================
11
-
12
- import type { Point, CurveStyle } from '@zombie-mermaid/core'
13
-
14
- /** `M x y` for the first point. */
15
- function moveTo(p: Point): string {
16
- return `M ${p.x} ${p.y}`
17
- }
18
-
19
- /** Straight segments through every point — the historical default. */
20
- function linearPath(points: Point[]): string {
21
- return (
22
- moveTo(points[0]!) +
23
- points
24
- .slice(1)
25
- .map((p) => ` L ${p.x} ${p.y}`)
26
- .join('')
27
- )
28
- }
29
-
30
- /**
31
- * Uniform cubic B-spline, matching d3's `curveBasis` (what Mermaid uses for
32
- * `basis`).
33
- *
34
- * A B-spline is *approximating*, not interpolating: it passes through neither
35
- * the interior points nor, without the endpoint handling below, the ends. The
36
- * first and last points are therefore emitted explicitly so an edge still
37
- * touches the nodes it connects — otherwise it would visibly detach.
38
- *
39
- * This is a direct port of d3's `Basis` curve rather than a lookalike, so a
40
- * diagram rendered here traces the same path Mermaid would draw. For each
41
- * point d3 emits one cubic whose controls are the thirds between the two
42
- * preceding points and whose end is the B-spline knot `(p0 + 4p1 + p2) / 6`;
43
- * it leads in at `(5p0 + p1) / 6` and closes with a final cubic against a
44
- * repeated last point, then a line to it.
45
- */
46
- function basisPath(points: Point[]): string {
47
- if (points.length < 3) return linearPath(points)
48
-
49
- const last = points[points.length - 1]!
50
- const parts: string[] = [moveTo(points[0]!)]
51
-
52
- /** One B-spline segment across three successive control points. */
53
- const segment = (p0: Point, p1: Point, p2: Point): string =>
54
- ` C ${(2 * p0.x + p1.x) / 3} ${(2 * p0.y + p1.y) / 3},` +
55
- ` ${(p0.x + 2 * p1.x) / 3} ${(p0.y + 2 * p1.y) / 3},` +
56
- ` ${(p0.x + 4 * p1.x + p2.x) / 6} ${(p0.y + 4 * p1.y + p2.y) / 6}`
57
-
58
- // Lead-in to the first knot, one sixth of the way along the opening leg.
59
- parts.push(
60
- ` L ${(5 * points[0]!.x + points[1]!.x) / 6}` +
61
- ` ${(5 * points[0]!.y + points[1]!.y) / 6}`,
62
- )
63
-
64
- for (let i = 2; i < points.length; i++) {
65
- parts.push(segment(points[i - 2]!, points[i - 1]!, points[i]!))
66
- }
67
-
68
- // d3 closes by feeding the last point twice, then drawing to it.
69
- parts.push(segment(points[points.length - 2]!, last, last))
70
- parts.push(` L ${last.x} ${last.y}`)
71
-
72
- return parts.join('')
73
- }
74
-
75
- /**
76
- * Straight runs joined by rounded corners. Mermaid calls this `natural`.
77
- *
78
- * NOTE: this is deliberately *not* d3's interpolating natural cubic spline.
79
- * ELK routes edges orthogonally, so every bend is a right angle, and at a
80
- * right angle the tangent of any C1-smooth interpolating spline is the
81
- * average of the two segment directions — i.e. diagonal. The curve must then
82
- * arrive at the corner travelling diagonally while approaching from directly
83
- * above, so it bulges sideways past the straight line. Two mirrored edges
84
- * leaving one decision node turned that bulge into a visible teardrop loop.
85
- * Scaling the tangents down shrinks the overshoot but cannot remove it; it is
86
- * a property of interpolating a 90° corner smoothly.
87
- *
88
- * Rounding the corners instead gives a smooth path that never overshoots and
89
- * stays visually distinct from `basis`, which cuts corners far more deeply.
90
- * The trade is that the path passes *near* each bend rather than exactly
91
- * through it — documented in docs/diagrams.md.
92
- */
93
- function naturalPath(points: Point[]): string {
94
- if (points.length < 3) return linearPath(points)
95
-
96
- /** Largest corner radius, in px. Kept small so edges stay readable. */
97
- const MAX_RADIUS = 12
98
-
99
- const parts: string[] = [moveTo(points[0]!)]
100
-
101
- for (let i = 1; i < points.length - 1; i++) {
102
- const prev = points[i - 1]!
103
- const corner = points[i]!
104
- const next = points[i + 1]!
105
-
106
- const inLen = Math.hypot(corner.x - prev.x, corner.y - prev.y)
107
- const outLen = Math.hypot(next.x - corner.x, next.y - corner.y)
108
-
109
- // A zero-length leg means duplicated routed points; there is no corner
110
- // to round, so pass straight through.
111
- if (inLen === 0 || outLen === 0) {
112
- parts.push(` L ${corner.x} ${corner.y}`)
113
- continue
114
- }
115
-
116
- // Never consume more than half of either adjacent leg, so neighbouring
117
- // corners cannot overlap and invert the path.
118
- const radius = Math.min(MAX_RADIUS, inLen / 2, outLen / 2)
119
-
120
- const startX = corner.x - ((corner.x - prev.x) / inLen) * radius
121
- const startY = corner.y - ((corner.y - prev.y) / inLen) * radius
122
- const endX = corner.x + ((next.x - corner.x) / outLen) * radius
123
- const endY = corner.y + ((next.y - corner.y) / outLen) * radius
124
-
125
- // Straight up to the fillet, then a quadratic through the corner.
126
- parts.push(` L ${startX} ${startY}`)
127
- parts.push(` Q ${corner.x} ${corner.y}, ${endX} ${endY}`)
128
- }
129
-
130
- const last = points[points.length - 1]!
131
- parts.push(` L ${last.x} ${last.y}`)
132
-
133
- return parts.join('')
134
- }
135
-
136
- /**
137
- * Right-angle staircase between consecutive points.
138
- *
139
- * `where` picks when the step happens: at the midpoint (`step`), immediately
140
- * (`stepBefore`), or at the end of the run (`stepAfter`) — matching d3's
141
- * curveStep family.
142
- *
143
- * The final segment is deliberately left straight, running along the original
144
- * approach direction. An SVG marker with `orient="auto"` takes its angle from
145
- * the last path segment, so a staircase that ends on a horizontal leg points
146
- * the arrowhead sideways into the target node instead of at it. Keeping the
147
- * last leg means the arrow still aims the way the routed edge does.
148
- */
149
- function stepPath(points: Point[], where: 'mid' | 'before' | 'after'): string {
150
- const parts: string[] = [moveTo(points[0]!)]
151
- const lastIndex = points.length - 1
152
-
153
- for (let i = 0; i < lastIndex; i++) {
154
- const a = points[i]!
155
- const b = points[i + 1]!
156
-
157
- if (i === lastIndex - 1) {
158
- parts.push(` L ${b.x} ${b.y}`)
159
- break
160
- }
161
-
162
- if (where === 'before') {
163
- parts.push(` L ${a.x} ${b.y} L ${b.x} ${b.y}`)
164
- } else if (where === 'after') {
165
- parts.push(` L ${b.x} ${a.y} L ${b.x} ${b.y}`)
166
- } else {
167
- const midY = (a.y + b.y) / 2
168
- parts.push(` L ${a.x} ${midY} L ${b.x} ${midY} L ${b.x} ${b.y}`)
169
- }
170
- }
171
-
172
- return parts.join('')
173
- }
174
-
175
- /**
176
- * Build the `d` attribute for an edge's routed points under `curve`.
177
- *
178
- * A path with fewer than two points cannot be drawn; the caller already skips
179
- * those, but this degrades to an empty string rather than emitting `M`
180
- * followed by nothing.
181
- */
182
- export function pointsToPath(
183
- points: Point[],
184
- curve: CurveStyle = 'linear',
185
- ): string {
186
- if (points.length === 0) return ''
187
- if (points.length === 1) return moveTo(points[0]!)
188
-
189
- switch (curve) {
190
- case 'basis':
191
- return basisPath(points)
192
- case 'natural':
193
- return naturalPath(points)
194
- case 'step':
195
- return stepPath(points, 'mid')
196
- case 'stepBefore':
197
- return stepPath(points, 'before')
198
- case 'stepAfter':
199
- return stepPath(points, 'after')
200
- case 'linear':
201
- default:
202
- return linearPath(points)
203
- }
204
- }
@@ -1,292 +0,0 @@
1
- /**
2
- * Shared ELK instance singleton.
3
- *
4
- * Uses elk.bundled.js (pure synchronous JS, ~1.6 MB) for all environments.
5
- * The singleton is created lazily on first use and cached forever.
6
- *
7
- * ELK's FakeWorker wraps both postMessage and onmessage in setTimeout(0),
8
- * making the normal API fully async. To bypass this:
9
- * 1. During construction, we capture setTimeout(0) callbacks and flush them
10
- * synchronously — this registers the layout algorithms immediately.
11
- * 2. For layout calls, we call dispatcher.saveDispatch() directly (skipping
12
- * the FakeWorker's postMessage setTimeout) and intercept the result via
13
- * rawWorker.onmessage (which the dispatcher calls synchronously).
14
- */
15
-
16
- import type { ELK, ElkNode } from 'elkjs'
17
- import ELKBundled from 'elkjs/lib/elk.bundled.js'
18
- import type { LayoutCache } from '@zombie-mermaid/core'
19
-
20
- /** The message envelope ELK's FakeWorker passes to `dispatcher.saveDispatch()`
21
- * to request a layout run. Mirrors the shape elk-worker.min.js expects on
22
- * `data` for a `cmd: 'layout'` request — not part of elkjs's public types. */
23
- interface ElkWorkerRequest {
24
- id: number
25
- cmd: 'layout'
26
- graph: ElkNode
27
- }
28
-
29
- /** The message envelope ELK's dispatcher passes back to `onmessage` once a
30
- * layout run completes. Mirrors elk-worker.min.js's response shape for a
31
- * `cmd: 'layout'` request — not part of elkjs's public types. */
32
- interface ElkWorkerResponse {
33
- id: number
34
- data?: ElkNode
35
- error?: unknown
36
- }
37
-
38
- interface RawFakeWorker {
39
- postMessage(msg: unknown): void
40
- onmessage: ((e: { data: ElkWorkerResponse }) => void) | null
41
- dispatcher: {
42
- saveDispatch(msg: { data: ElkWorkerRequest }): void
43
- }
44
- }
45
-
46
- /**
47
- * The shape of elkjs's bundled `ELK` instance that actually exists at
48
- * runtime, including the internal `worker` handle. elkjs's public `ELK`
49
- * type (from `elk-api.d.ts`) only declares `layout`/`knownLayout*`/
50
- * `terminateWorker` — it deliberately doesn't expose worker internals,
51
- * since those aren't a supported API. We rely on them anyway (see file
52
- * header), so this extends the public type with the internal piece we
53
- * touch instead of casting through `unknown`.
54
- */
55
- interface ElkBundledInternal extends ELK {
56
- worker: { worker: RawFakeWorker }
57
- }
58
-
59
- let elk: ELK | null = null
60
- let rawWorker: RawFakeWorker | null = null
61
-
62
- // ============================================================================
63
- // Opt-in layout cache
64
- // ============================================================================
65
-
66
- /**
67
- * `LayoutCache`'s shape lives in `@zombie-mermaid/core`'s `types.ts`
68
- * because `RenderOptions.layoutCache` references it and `core` must not
69
- * type-import this package (zombie-mermaid#625). Re-exported here so this
70
- * module stays the single import site for everything layout-cache-related,
71
- * exactly as before the split.
72
- */
73
- export type { LayoutCache }
74
-
75
- /**
76
- * Concrete shape of a `LayoutCache`, restated locally.
77
- *
78
- * `core`'s `LayoutCache` interface marks `map`/`maxSize` `@internal`
79
- * (see the comment on that interface in packages/core/src/types.ts), so
80
- * api-extractor strips them from `@zombie-mermaid/core`'s *published*
81
- * `dist/index.d.ts` — deliberately, so they stay invisible to
82
- * `@zombie-mermaid/core` consumers and to `zombie-mermaid`'s own public
83
- * types (which re-export `LayoutCache` from this package). As of #769,
84
- * `@zombie-mermaid/core` is a real, independently-built dependency of this
85
- * package rather than bundled source, so this module now resolves
86
- * `LayoutCache` through that same trimmed public declaration too — same as
87
- * any other consumer. This module is the one place, in or out of `core`,
88
- * that actually builds and mutates those fields (`createLayoutCache()`
89
- * below; the cache read/evict logic in `elkLayoutSync()`), so it restates
90
- * the concrete shape here — kept in sync by hand with `core`'s source of
91
- * truth — rather than either widening `core`'s public surface or fighting
92
- * api-extractor's trimming in the build config to get it back.
93
- */
94
- interface LayoutCacheShape {
95
- map: Map<string, ElkNode>
96
- maxSize: number
97
- }
98
-
99
- const DEFAULT_LAYOUT_CACHE_SIZE = 20
100
-
101
- /**
102
- * Create a new opt-in layout cache with a bounded size (default 20
103
- * entries). Once full, the least-recently-used entry is evicted to make
104
- * room for a new one.
105
- *
106
- * Pass the result to `elkLayoutSync()` directly, or via
107
- * `RenderOptions.layoutCache` (threaded through by `layoutGraphSync()`,
108
- * `layoutClassDiagramSync()`, and `layoutErDiagramSync()`) to memoize
109
- * layout across repeated renders of the same diagram + options.
110
- */
111
- export function createLayoutCache(
112
- maxSize: number = DEFAULT_LAYOUT_CACHE_SIZE,
113
- ): LayoutCache {
114
- if (!Number.isInteger(maxSize) || maxSize < 1) {
115
- throw new Error(
116
- `createLayoutCache: maxSize must be a positive integer, got ${maxSize}`,
117
- )
118
- }
119
- // Typed as the concrete shape first (see `LayoutCacheShape` above), then
120
- // returned as the public, trimmed `LayoutCache` — a plain widening
121
- // assignment, not a cast.
122
- const cache: LayoutCacheShape = { map: new Map(), maxSize }
123
- return cache
124
- }
125
-
126
- /**
127
- * Deterministically serialize a value for use as a cache key, sorting
128
- * object keys recursively so two structurally-equal ELK input graphs
129
- * always produce an identical string regardless of property-insertion
130
- * order. Plain `JSON.stringify()` does not guarantee that — and this
131
- * function is the only thing standing between a cache hit and returning
132
- * some *other* diagram's layout, so it can't be allowed to drift with
133
- * insertion order.
134
- *
135
- * The ELK input graph built by `mermaidToElk()` is plain JSON (arrays,
136
- * plain objects, strings, numbers, booleans — the shape ELK's own JSON
137
- * schema requires) with every render option that affects layout already
138
- * baked in (direction, spacing, per-subgraph overrides, etc.), so
139
- * serializing the graph itself is a complete and correct cache key: equal
140
- * serialized input always means equal ELK output, since ELK layout is a
141
- * pure function of its input graph.
142
- */
143
- function stableStringify(value: unknown): string {
144
- if (Array.isArray(value)) {
145
- return `[${value.map(stableStringify).join(',')}]`
146
- }
147
- if (value !== null && typeof value === 'object') {
148
- const record = value as Record<string, unknown>
149
- const keys = Object.keys(record).sort()
150
- const entries = keys.map(
151
- (key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`,
152
- )
153
- return `{${entries.join(',')}}`
154
- }
155
- return JSON.stringify(value)
156
- }
157
-
158
- /**
159
- * Ensure the ELK singleton exists.
160
- *
161
- * Patches setTimeout during construction to capture and synchronously flush
162
- * the algorithm registration callback that ELK queues via setTimeout(0).
163
- * Without this, layout calls fail with "algorithm not found" until the
164
- * next macrotask.
165
- */
166
- function ensureElk(): RawFakeWorker {
167
- if (elk && rawWorker) return rawWorker
168
-
169
- // Capture setTimeout(0) callbacks queued during ELK construction
170
- const pending: (() => void)[] = []
171
- const origSetTimeout = globalThis.setTimeout
172
- // @ts-expect-error — simplified signature for our interception, not
173
- // assignment-compatible with the full `typeof setTimeout` overload set
174
- globalThis.setTimeout = (fn: () => void, delay?: number) => {
175
- if (delay === 0) {
176
- pending.push(fn)
177
- return 0
178
- }
179
- return origSetTimeout(fn, delay)
180
- }
181
-
182
- // Bun defines `self` (= globalThis) but not `document`, which tricks
183
- // elk-worker.min.js into taking the Web Worker branch instead of the
184
- // CJS branch. Temporarily hide `self` so it exports {Worker: FakeWorker}.
185
- // `lib` in tsconfig.json is `["ESNext"]` (no `dom`), so `self`/`document`
186
- // aren't ambiently declared on `globalThis` — narrow to just the two
187
- // properties this probe touches instead of a blanket `Record`.
188
- const g = globalThis as { self?: unknown; document?: unknown }
189
- const hadSelf = 'self' in g
190
- const origSelf = g.self
191
- if (hadSelf && typeof g.document === 'undefined') {
192
- delete g.self
193
- }
194
-
195
- elk = new ELKBundled()
196
- if (!elk) {
197
- // Unreachable — `new ELKBundled()` always returns an instance — but
198
- // makes the invariant explicit rather than letting the cast below
199
- // silently paper over a null `elk` if that ever stopped being true.
200
- throw new Error('ELKBundled construction unexpectedly produced no instance')
201
- }
202
-
203
- // Restore self
204
- if (hadSelf) g.self = origSelf
205
-
206
- // Restore setTimeout immediately
207
- globalThis.setTimeout = origSetTimeout
208
-
209
- // Flush captured callbacks synchronously — registers layout algorithms
210
- pending.forEach((fn) => fn())
211
-
212
- // Cache the raw FakeWorker for elkLayoutSync()
213
- rawWorker = (elk as ElkBundledInternal).worker.worker
214
- return rawWorker
215
- }
216
-
217
- /**
218
- * Run ELK layout synchronously.
219
- *
220
- * Bypasses BOTH of ELK's setTimeout(0) wrappers:
221
- * - FakeWorker.postMessage wraps dispatch in setTimeout(0) — bypassed by
222
- * calling dispatcher.saveDispatch() directly
223
- * - PromisedWorker.onmessage wraps receive in setTimeout(0) — bypassed by
224
- * replacing rawWorker.onmessage with a direct interceptor
225
- *
226
- * @param cache - Optional opt-in layout cache (see `createLayoutCache()`).
227
- * When provided, a cache hit returns the previous result without running
228
- * ELK layout again. Omitted/undefined preserves the original
229
- * always-recompute behavior exactly.
230
- */
231
- export function elkLayoutSync(graph: ElkNode, cache?: LayoutCache): ElkNode {
232
- // `cache`, when provided, is always an object this module itself built
233
- // via `createLayoutCache()` above — never anything constructed outside
234
- // this package. Restated as the concrete shape here (see
235
- // `LayoutCacheShape`'s doc comment) since the public `LayoutCache` type
236
- // this parameter is declared with intentionally hides `map`/`maxSize`.
237
- const internalCache = cache as LayoutCacheShape | undefined
238
- const cacheKey = internalCache ? stableStringify(graph) : undefined
239
- if (internalCache && cacheKey !== undefined) {
240
- const cached = internalCache.map.get(cacheKey)
241
- if (cached) {
242
- // Mark as most-recently-used: Map iteration order follows insertion
243
- // order, so a delete+re-set moves this entry to the end — which is
244
- // what the LRU eviction below relies on to find the *least*
245
- // recently used entry (the current first key).
246
- internalCache.map.delete(cacheKey)
247
- internalCache.map.set(cacheKey, cached)
248
- return cached
249
- }
250
- }
251
-
252
- const worker = ensureElk()
253
-
254
- let result: ElkNode | undefined
255
- let error: unknown
256
-
257
- // Replace onmessage to intercept the result synchronously
258
- // (the dispatcher calls this directly, without setTimeout)
259
- const origOnmessage = worker.onmessage
260
- worker.onmessage = (answer: { data: ElkWorkerResponse }) => {
261
- if (answer.data.error) {
262
- error = answer.data.error
263
- } else {
264
- result = answer.data.data
265
- }
266
- }
267
-
268
- // Call dispatcher.saveDispatch directly — bypasses FakeWorker.postMessage's
269
- // setTimeout(0) wrapper. The dispatcher processes the layout synchronously
270
- // and calls rawWorker.onmessage with the result.
271
- worker.dispatcher.saveDispatch({
272
- data: { id: 0, cmd: 'layout', graph },
273
- })
274
-
275
- // Restore original handler
276
- worker.onmessage = origOnmessage
277
-
278
- if (error) throw error
279
- if (!result) throw new Error('ELK layout did not return synchronously')
280
-
281
- if (internalCache && cacheKey !== undefined) {
282
- internalCache.map.set(cacheKey, result)
283
- if (internalCache.map.size > internalCache.maxSize) {
284
- // Map iteration order is insertion order, so the first key is the
285
- // least recently used (see the recency bump on hit, above).
286
- const oldestKey = internalCache.map.keys().next().value
287
- if (oldestKey !== undefined) internalCache.map.delete(oldestKey)
288
- }
289
- }
290
-
291
- return result
292
- }
@@ -1,200 +0,0 @@
1
- /**
2
- * ER diagram layout engine (ELK.js).
3
- *
4
- * Each entity box has:
5
- * 1. Header (entity name)
6
- * 2. Attribute rows (type, name, keys)
7
- */
8
-
9
- import type { ElkNode, ElkExtendedEdge } from 'elkjs'
10
- import type {
11
- ErDiagram,
12
- ErEntity,
13
- PositionedErDiagram,
14
- PositionedErEntity,
15
- PositionedErRelationship,
16
- } from '@zombie-mermaid/mermaid-parser'
17
- import type { ErRenderOptions } from '@zombie-mermaid/core'
18
- import {
19
- estimateTextWidth,
20
- estimateMonoTextWidth,
21
- FONT_WEIGHTS,
22
- resolveFontSizes,
23
- } from '../styles.ts'
24
- import { elkLayoutSync } from '../elk-instance.ts'
25
- import { extractEdgePoints } from '../layout-engine/elk-adapter-utils.ts'
26
- import {
27
- ELK_DIRECTION_FALLBACK,
28
- baseElkLayoutOptions,
29
- buildElkEdge,
30
- buildElkLeafNode,
31
- directionToElk,
32
- } from '../layout-engine/elk-graph-builder.ts'
33
-
34
- /** Layout constants for ER diagrams */
35
- const ER = {
36
- padding: 40,
37
- boxPadX: 14,
38
- headerHeight: 34,
39
- rowHeight: 22,
40
- minWidth: 140,
41
- attrFontSize: 11,
42
- attrFontWeight: 400,
43
- nodeSpacing: 70,
44
- layerSpacing: 90,
45
- } as const
46
-
47
- type EntitySizeMap = Map<string, { width: number; height: number }>
48
-
49
- /** Build ELK graph and size map from an ER diagram. */
50
- function buildErElkGraph(
51
- diagram: ErDiagram,
52
- options: ErRenderOptions,
53
- ): { elkGraph: ElkNode; entitySizes: EntitySizeMap } {
54
- const entitySizes: EntitySizeMap = new Map()
55
- const fontSizes = resolveFontSizes(options.fontSizes)
56
-
57
- for (const entity of diagram.entities) {
58
- const headerTextW = estimateTextWidth(
59
- entity.label,
60
- fontSizes.nodeLabel,
61
- FONT_WEIGHTS.nodeLabel,
62
- )
63
- let maxAttrW = 0
64
- for (const attr of entity.attributes) {
65
- const attrText = `${attr.type} ${attr.name}${attr.keys.length > 0 ? ' ' + attr.keys.join(',') : ''}`
66
- const w = estimateMonoTextWidth(attrText, ER.attrFontSize)
67
- if (w > maxAttrW) maxAttrW = w
68
- }
69
- const width = Math.max(
70
- ER.minWidth,
71
- headerTextW + ER.boxPadX * 2,
72
- maxAttrW + ER.boxPadX * 2,
73
- )
74
- const height =
75
- ER.headerHeight + Math.max(entity.attributes.length, 1) * ER.rowHeight
76
- entitySizes.set(entity.id, { width, height })
77
- }
78
-
79
- // Iterate entitySizes directly (populated above, in diagram.entities order)
80
- // rather than looking each entity back up by id — sidesteps needing an
81
- // assertion or invariant check for a lookup that can't actually miss.
82
- const children: ElkNode[] = []
83
- for (const [id, size] of entitySizes) {
84
- children.push(buildElkLeafNode(id, size))
85
- }
86
-
87
- // ER edge labels carry no per-label layout options — placement is set
88
- // once on the root graph below (`elk.edgeLabels.placement: CENTER`).
89
- const labelStyle = { fontSize: fontSizes.edgeLabel }
90
-
91
- const edges: ElkExtendedEdge[] = []
92
- for (const [i, rel] of diagram.relationships.entries()) {
93
- edges.push(
94
- buildElkEdge({
95
- id: `e${i}`,
96
- source: rel.entity1,
97
- target: rel.entity2,
98
- label: rel.label,
99
- labelStyle,
100
- }),
101
- )
102
- }
103
-
104
- const elkGraph: ElkNode = {
105
- id: 'root',
106
- layoutOptions: {
107
- ...baseElkLayoutOptions({
108
- // A source with no `direction` statement lays out left-to-right —
109
- // ER's own default, unlike flowchart/class's DOWN. See
110
- // ELK_DIRECTION_FALLBACK.
111
- direction: directionToElk(diagram.direction, ELK_DIRECTION_FALLBACK.er),
112
- nodeSpacing: ER.nodeSpacing,
113
- layerSpacing: ER.layerSpacing,
114
- padding: ER.padding,
115
- }),
116
- 'elk.edgeLabels.placement': 'CENTER',
117
- },
118
- children,
119
- edges,
120
- }
121
-
122
- return { elkGraph, entitySizes }
123
- }
124
-
125
- /** Extract positioned entities and relationships from ELK result. */
126
- function extractErLayout(
127
- result: ElkNode,
128
- diagram: ErDiagram,
129
- entitySizes: EntitySizeMap,
130
- ): PositionedErDiagram {
131
- const entityLookup = new Map<string, ErEntity>()
132
- for (const entity of diagram.entities) entityLookup.set(entity.id, entity)
133
-
134
- const positionedEntities: PositionedErEntity[] = []
135
- for (const child of result.children ?? []) {
136
- const entity = entityLookup.get(child.id)
137
- if (entity) {
138
- const size = entitySizes.get(entity.id)
139
- if (!size) {
140
- // Unreachable — entitySizes is populated for every diagram.entities
141
- // entry, and entityLookup/entity.id come from that same list.
142
- /* v8 ignore next */
143
- throw new Error(`Missing computed size for entity "${entity.id}"`)
144
- }
145
- positionedEntities.push({
146
- id: entity.id,
147
- label: entity.label,
148
- attributes: entity.attributes,
149
- x: child.x ?? 0,
150
- y: child.y ?? 0,
151
- width: child.width ?? size.width,
152
- height: child.height ?? size.height,
153
- headerHeight: ER.headerHeight,
154
- rowHeight: ER.rowHeight,
155
- })
156
- }
157
- }
158
-
159
- const relationships: PositionedErRelationship[] = []
160
- for (const [i, elkEdge] of (result.edges ?? []).entries()) {
161
- // diagram.relationships[i] is guaranteed by construction: buildErElkGraph
162
- // creates exactly one ELK edge per relationship, in the same order.
163
- const rel = diagram.relationships[i]!
164
-
165
- const points = extractEdgePoints(elkEdge)
166
-
167
- relationships.push({
168
- entity1: rel.entity1,
169
- entity2: rel.entity2,
170
- cardinality1: rel.cardinality1,
171
- cardinality2: rel.cardinality2,
172
- label: rel.label,
173
- identifying: rel.identifying,
174
- points,
175
- })
176
- }
177
-
178
- return {
179
- width: result.width ?? 600,
180
- height: result.height ?? 400,
181
- entities: positionedEntities,
182
- relationships,
183
- }
184
- }
185
-
186
- /**
187
- * Lay out a parsed ER diagram using ELK.js (synchronous).
188
- */
189
- export function layoutErDiagramSync(
190
- diagram: ErDiagram,
191
- options: ErRenderOptions = {},
192
- ): PositionedErDiagram {
193
- if (diagram.entities.length === 0) {
194
- return { width: 0, height: 0, entities: [], relationships: [] }
195
- }
196
-
197
- const { elkGraph, entitySizes } = buildErElkGraph(diagram, options)
198
- const result = elkLayoutSync(elkGraph, options.layoutCache)
199
- return extractErLayout(result, diagram, entitySizes)
200
- }