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,1085 +0,0 @@
1
- // ============================================================================
2
- // ASCII renderer — XY Chart
3
- //
4
- // Renders xychart-beta diagrams to ASCII/Unicode text art.
5
- // Uses the parsed XYChart type directly (not PositionedXYChart) since
6
- // pixel coordinates don't map to character grids.
7
- //
8
- // Bar charts: █ (Unicode) or # (ASCII) block characters.
9
- // Line charts: continuous staircase routing with rounded corners (╭╮╰╯│─).
10
- //
11
- // Multi-series support: each series gets a distinct color from a palette.
12
- // ============================================================================
13
-
14
- import {
15
- parseXYChart,
16
- getSeriesColor,
17
- CHART_ACCENT_FALLBACK,
18
- } from '@zombie-mermaid/mermaid-parser'
19
- import type { XYChart } from '@zombie-mermaid/mermaid-parser'
20
- import type {
21
- AsciiConfig,
22
- AsciiTheme,
23
- ColorMode,
24
- CharRole,
25
- Canvas,
26
- RoleCanvas,
27
- } from './types.ts'
28
- import { colorizeText } from './ansi.ts'
29
- import { mkCanvas, mkRoleCanvas, write } from './canvas.ts'
30
- import { splitStatements } from '@zombie-mermaid/core'
31
-
32
- // ============================================================================
33
- // Constants
34
- // ============================================================================
35
-
36
- const PLOT_WIDTH = 60
37
- const PLOT_HEIGHT = 20
38
-
39
- // Unicode box-drawing characters
40
- const UNI = {
41
- hLine: '─',
42
- vLine: '│',
43
- origin: '┼',
44
- yTick: '┤',
45
- xTick: '┬',
46
- bar: '█',
47
- grid: '·',
48
- cornerTL: '╭', // top-left: down+right
49
- cornerTR: '╮', // top-right: down+left
50
- cornerBL: '╰', // bottom-left: up+right
51
- cornerBR: '╯', // bottom-right: up+left
52
- } as const
53
-
54
- // ASCII fallback characters
55
- const ASC = {
56
- hLine: '-',
57
- vLine: '|',
58
- origin: '+',
59
- yTick: '+',
60
- xTick: '+',
61
- bar: '#',
62
- grid: '.',
63
- cornerTL: '+',
64
- cornerTR: '+',
65
- cornerBL: '+',
66
- cornerBR: '+',
67
- } as const
68
-
69
- // ============================================================================
70
- // Multi-series color support
71
- // ============================================================================
72
-
73
- /** Per-cell hex color override canvas. Parallel to RoleCanvas. */
74
- type HexCanvas = (string | null)[][]
75
-
76
- /** Generate an array of hex colors, one per series. */
77
- function getSeriesColors(total: number, theme: AsciiTheme): string[] {
78
- const accent = theme.accent ?? CHART_ACCENT_FALLBACK
79
- if (total <= 1) return [accent]
80
- return Array.from({ length: total }, (_, i) =>
81
- getSeriesColor(i, accent, theme.bg),
82
- )
83
- }
84
-
85
- /** Map a CharRole to its hex color from the theme (for canvasToString fallback). */
86
- function roleToHex(role: CharRole, theme: AsciiTheme): string {
87
- switch (role) {
88
- case 'text':
89
- return theme.fg
90
- case 'border':
91
- return theme.border
92
- case 'line':
93
- return theme.line
94
- case 'arrow':
95
- return theme.arrow
96
- case 'corner':
97
- return theme.corner ?? theme.line
98
- case 'junction':
99
- return theme.junction ?? theme.border
100
- default:
101
- return theme.fg
102
- }
103
- }
104
-
105
- // ============================================================================
106
- // Public API
107
- // ============================================================================
108
-
109
- export function renderXYChartAscii(
110
- text: string,
111
- config: AsciiConfig,
112
- colorMode: ColorMode,
113
- theme: AsciiTheme,
114
- ): string {
115
- const lines = splitStatements(text)
116
- const chart = parseXYChart(lines)
117
- const ch = config.useAscii ? ASC : UNI
118
-
119
- if (chart.horizontal) {
120
- return renderHorizontal(chart, ch, colorMode, theme)
121
- }
122
- return renderVertical(chart, ch, colorMode, theme)
123
- }
124
-
125
- // ============================================================================
126
- // Vertical chart layout + rendering
127
- // ============================================================================
128
-
129
- function renderVertical(
130
- chart: XYChart,
131
- ch: typeof UNI | typeof ASC,
132
- colorMode: ColorMode,
133
- theme: AsciiTheme,
134
- ): string {
135
- const dataCount = getDataCount(chart)
136
- if (dataCount === 0) return ''
137
-
138
- // parseXYChart always derives a y-axis range (from data or a 0-100
139
- // fallback — see xychart/parser.ts) before returning, so this is never
140
- // actually undefined for parsed input. That guarantee lives in a
141
- // different module, so narrow it here explicitly instead of trusting it
142
- // silently across the boundary.
143
- const yRange = chart.yAxis.range
144
- if (!yRange) {
145
- /* v8 ignore next */
146
- throw new Error('XY chart: y-axis range was not set by the parser')
147
- }
148
- const yTicks = niceTickValues(yRange.min, yRange.max)
149
- const yLabels = yTicks.map((v) => formatTickValue(v))
150
- const yGutter = Math.max(...yLabels.map((l) => l.length)) + 1
151
-
152
- const plotW = Math.max(PLOT_WIDTH, dataCount * 6)
153
- const plotH = PLOT_HEIGHT
154
- const bandW = Math.floor(plotW / dataCount)
155
- const catLabels = getCategoryLabels(chart, dataCount)
156
-
157
- // Canvas dimensions
158
- const hasTitle = !!chart.title
159
- const hasXTitle = !!chart.xAxis.title
160
- const hasYTitle = !!chart.yAxis.title
161
- const hasLegend = chart.series.length > 1
162
- const titleRow = hasTitle ? 0 : -1
163
- const plotTop = (hasTitle ? 2 : 0) + (hasLegend ? 1 : 0)
164
- // Reserve a column for the rotated y-axis title (rendered top-to-bottom,
165
- // one character per row, mirroring how mermaid.js rotates it 90deg along
166
- // the left edge) plus a 1-column gap before the tick-value gutter.
167
- const yTitleWidth = hasYTitle ? 2 : 0
168
- const plotLeft = yTitleWidth + yGutter + 1 // +1 for axis character
169
- const totalW = plotLeft + bandW * dataCount + 2
170
- const xAxisRow = plotTop + plotH
171
- const xLabelRow = xAxisRow + 1
172
- const xTitleRow = hasXTitle ? xLabelRow + 1 : -1
173
- const totalH =
174
- xLabelRow + 1 + (hasXTitle ? 1 : 0) + (hasLegend && !hasTitle ? 0 : 0)
175
-
176
- // Create canvas
177
- const canvas = createCanvas(totalW, totalH)
178
- const roles = createRoleCanvas(totalW, totalH)
179
- const hexColors = createHexCanvas(totalW, totalH)
180
-
181
- // Series colors
182
- const seriesColors = getSeriesColors(chart.series.length, theme)
183
-
184
- // Scales
185
- const valueToRow = (v: number): number => {
186
- const t = (v - yRange.min) / (yRange.max - yRange.min || 1)
187
- return Math.round(t * (plotH - 1))
188
- }
189
- const bandCenter = (i: number): number =>
190
- plotLeft + Math.floor(bandW * (i + 0.5))
191
-
192
- // 1. Title
193
- if (chart.title && titleRow >= 0) {
194
- writeText(
195
- canvas,
196
- roles,
197
- titleRow,
198
- Math.floor(totalW / 2 - chart.title.length / 2),
199
- chart.title,
200
- 'text',
201
- )
202
- }
203
-
204
- // 2. Legend
205
- if (hasLegend) {
206
- const legendRow = hasTitle ? 1 : 0
207
- drawLegend(
208
- canvas,
209
- roles,
210
- hexColors,
211
- chart,
212
- legendRow,
213
- totalW,
214
- ch,
215
- seriesColors,
216
- )
217
- }
218
-
219
- // 3. Y-axis line + ticks + labels
220
- for (let row = 0; row < plotH; row++) {
221
- const displayRow = plotTop + (plotH - 1 - row)
222
- set(canvas, roles, displayRow, plotLeft - 1, ch.vLine, 'border')
223
- }
224
- // Origin
225
- set(canvas, roles, xAxisRow, plotLeft - 1, ch.origin, 'border')
226
-
227
- for (const tick of yTicks) {
228
- const row = valueToRow(tick)
229
- if (row < 0 || row >= plotH) continue
230
- const displayRow = plotTop + (plotH - 1 - row)
231
- const label = formatTickValue(tick)
232
- // Tick mark on axis
233
- set(
234
- canvas,
235
- roles,
236
- displayRow,
237
- plotLeft - 1,
238
- row === 0 ? ch.origin : ch.yTick,
239
- 'border',
240
- )
241
- // Label
242
- const labelStart = yTitleWidth + yGutter - label.length
243
- writeText(canvas, roles, displayRow, Math.max(0, labelStart), label, 'text')
244
- }
245
-
246
- // 4. X-axis line + ticks + labels
247
- for (let c = plotLeft; c < plotLeft + bandW * dataCount; c++) {
248
- set(canvas, roles, xAxisRow, c, ch.hLine, 'border')
249
- }
250
- for (let i = 0; i < dataCount; i++) {
251
- const cx = bandCenter(i)
252
- set(canvas, roles, xAxisRow, cx, ch.xTick, 'border')
253
- // Label below
254
- const label = catLabels[i]!
255
- const labelStart = cx - Math.floor(label.length / 2)
256
- writeText(canvas, roles, xLabelRow, Math.max(0, labelStart), label, 'text')
257
- }
258
-
259
- // 5. X-axis title
260
- if (chart.xAxis.title && xTitleRow >= 0) {
261
- const title = chart.xAxis.title
262
- writeText(
263
- canvas,
264
- roles,
265
- xTitleRow,
266
- Math.floor(totalW / 2 - title.length / 2),
267
- title,
268
- 'text',
269
- )
270
- }
271
-
272
- // 5b. Y-axis title — rendered rotated: one character per row, top-to-
273
- // bottom, in the leftmost column, mirroring how mermaid.js's SVG rotates
274
- // this label 90deg along the left edge of the chart. Vertically centered
275
- // within the plot's row range.
276
- if (chart.yAxis.title) {
277
- const title = chart.yAxis.title
278
- const startRow =
279
- plotTop + Math.max(0, Math.floor((plotH - title.length) / 2))
280
- for (let i = 0; i < title.length; i++) {
281
- const row = startRow + i
282
- if (row >= plotTop + plotH) break
283
- set(canvas, roles, row, 0, title[i]!, 'text')
284
- }
285
- }
286
-
287
- // 6. Grid lines (subtle horizontal dots at y-tick positions)
288
- for (const tick of yTicks) {
289
- const row = valueToRow(tick)
290
- if (row < 0 || row >= plotH) continue
291
- const displayRow = plotTop + (plotH - 1 - row)
292
- for (let c = plotLeft; c < plotLeft + bandW * dataCount; c++) {
293
- if (get(canvas, displayRow, c) === ' ') {
294
- set(canvas, roles, displayRow, c, ch.grid, 'line')
295
- }
296
- }
297
- }
298
-
299
- // 7. Bars — track global series index for per-series colors
300
- const barEntries: { data: number[]; globalIdx: number }[] = []
301
- for (let si = 0; si < chart.series.length; si++) {
302
- if (chart.series[si]!.type === 'bar')
303
- barEntries.push({ data: chart.series[si]!.data, globalIdx: si })
304
- }
305
-
306
- if (barEntries.length > 0) {
307
- // Multiple bar series in the same xychart-beta share one x-position and
308
- // width per category — mermaid.js overlays/occludes them rather than
309
- // laying them out as side-by-side grouped bars (confirmed against real
310
- // mermaid.js SVG output: bar-plot-N rects for every series in a category
311
- // carry identical x/width, differing only in y/height — see issue #452).
312
- // Draw order (series declaration order) is what produces the occlusion:
313
- // a later series drawn on top of an earlier, taller-or-shorter one.
314
- const usable = Math.max(1, bandW - 2)
315
- const singleBarW = Math.max(1, Math.min(usable, 8))
316
- const baseRow = valueToRow(Math.max(0, yRange.min))
317
-
318
- for (let bIdx = 0; bIdx < barEntries.length; bIdx++) {
319
- const entry = barEntries[bIdx]!
320
- const hexColor = seriesColors[entry.globalIdx]!
321
- for (let i = 0; i < entry.data.length; i++) {
322
- const cx = bandCenter(i)
323
- const bx = cx - Math.floor(singleBarW / 2)
324
- const valRow = valueToRow(entry.data[i]!)
325
- const fromRow = Math.min(baseRow, valRow)
326
- const toRow = Math.max(baseRow, valRow)
327
-
328
- for (let row = fromRow; row <= toRow; row++) {
329
- const displayRow = plotTop + (plotH - 1 - row)
330
- for (let c = bx; c < bx + singleBarW; c++) {
331
- set(
332
- canvas,
333
- roles,
334
- displayRow,
335
- c,
336
- ch.bar,
337
- 'arrow',
338
- hexColors,
339
- hexColor,
340
- )
341
- }
342
- }
343
- }
344
- }
345
- }
346
-
347
- // 8. Lines (staircase routing with rounded corners)
348
- const lineEntries: { data: number[]; globalIdx: number }[] = []
349
- for (let si = 0; si < chart.series.length; si++) {
350
- if (chart.series[si]!.type === 'line')
351
- lineEntries.push({ data: chart.series[si]!.data, globalIdx: si })
352
- }
353
-
354
- for (const entry of lineEntries) {
355
- if (entry.data.length === 0) continue
356
- const hexColor = seriesColors[entry.globalIdx]!
357
- drawStaircaseLine(
358
- canvas,
359
- roles,
360
- entry.data,
361
- bandCenter,
362
- valueToRow,
363
- plotTop,
364
- plotH,
365
- plotLeft,
366
- bandW * dataCount,
367
- ch,
368
- hexColors,
369
- hexColor,
370
- )
371
- }
372
-
373
- return canvasToString(canvas, roles, hexColors, colorMode, theme)
374
- }
375
-
376
- // ============================================================================
377
- // Horizontal chart layout + rendering
378
- // ============================================================================
379
-
380
- function renderHorizontal(
381
- chart: XYChart,
382
- ch: typeof UNI | typeof ASC,
383
- colorMode: ColorMode,
384
- theme: AsciiTheme,
385
- ): string {
386
- const dataCount = getDataCount(chart)
387
- if (dataCount === 0) return ''
388
-
389
- // See the matching comment in renderVertical: the parser always derives a
390
- // y-axis range before returning, but that guarantee lives in a different
391
- // module, so it's narrowed here explicitly rather than trusted silently.
392
- const yRange = chart.yAxis.range
393
- if (!yRange) {
394
- /* v8 ignore next */
395
- throw new Error('XY chart: y-axis range was not set by the parser')
396
- }
397
- const valueTicks = niceTickValues(yRange.min, yRange.max)
398
- const catLabels = getCategoryLabels(chart, dataCount)
399
- const catGutter = Math.max(...catLabels.map((l) => l.length)) + 1
400
-
401
- const plotW = Math.max(PLOT_WIDTH, 40)
402
- const bandH = Math.max(2, Math.floor(PLOT_HEIGHT / dataCount))
403
- const plotH = bandH * dataCount
404
-
405
- const hasTitle = !!chart.title
406
- const hasYTitle = !!chart.yAxis.title
407
- const hasLegend = chart.series.length > 1
408
- const plotTop = (hasTitle ? 2 : 0) + (hasLegend ? 1 : 0)
409
- const plotLeft = catGutter + 1
410
- const totalW = plotLeft + plotW + 2
411
- const totalH = plotTop + plotH + 2 + (hasYTitle ? 1 : 0)
412
- const xAxisRow = plotTop + plotH
413
-
414
- const canvas = createCanvas(totalW, totalH)
415
- const roles = createRoleCanvas(totalW, totalH)
416
- const hexColors = createHexCanvas(totalW, totalH)
417
-
418
- // Series colors
419
- const seriesColors = getSeriesColors(chart.series.length, theme)
420
-
421
- // Value scale (horizontal)
422
- const valueToCol = (v: number): number => {
423
- const t = (v - yRange.min) / (yRange.max - yRange.min || 1)
424
- return plotLeft + Math.round(t * (plotW - 1))
425
- }
426
- const bandMid = (i: number): number => plotTop + Math.floor(bandH * (i + 0.5))
427
-
428
- // Title
429
- if (chart.title) {
430
- writeText(
431
- canvas,
432
- roles,
433
- 0,
434
- Math.floor(totalW / 2 - chart.title.length / 2),
435
- chart.title,
436
- 'text',
437
- )
438
- }
439
-
440
- // Legend
441
- if (hasLegend) {
442
- const legendRow = hasTitle ? 1 : 0
443
- drawLegend(
444
- canvas,
445
- roles,
446
- hexColors,
447
- chart,
448
- legendRow,
449
- totalW,
450
- ch,
451
- seriesColors,
452
- )
453
- }
454
-
455
- // Y-axis (category axis on left)
456
- for (let r = plotTop; r < plotTop + plotH; r++) {
457
- set(canvas, roles, r, plotLeft - 1, ch.vLine, 'border')
458
- }
459
- set(canvas, roles, xAxisRow, plotLeft - 1, ch.origin, 'border')
460
-
461
- for (let i = 0; i < dataCount; i++) {
462
- const my = bandMid(i)
463
- const label = catLabels[i]!
464
- const labelStart = catGutter - label.length
465
- writeText(canvas, roles, my, Math.max(0, labelStart), label, 'text')
466
- }
467
-
468
- // X-axis (value axis on bottom)
469
- for (let c = plotLeft; c < plotLeft + plotW; c++) {
470
- set(canvas, roles, xAxisRow, c, ch.hLine, 'border')
471
- }
472
- for (const tick of valueTicks) {
473
- const cx = valueToCol(tick)
474
- if (cx < plotLeft || cx >= plotLeft + plotW) continue
475
- set(canvas, roles, xAxisRow, cx, ch.xTick, 'border')
476
- const label = formatTickValue(tick)
477
- writeText(
478
- canvas,
479
- roles,
480
- xAxisRow + 1,
481
- cx - Math.floor(label.length / 2),
482
- label,
483
- 'text',
484
- )
485
- }
486
-
487
- // Y-axis title
488
- if (chart.yAxis.title) {
489
- const title = chart.yAxis.title
490
- writeText(
491
- canvas,
492
- roles,
493
- totalH - 1,
494
- Math.floor(totalW / 2 - title.length / 2),
495
- title,
496
- 'text',
497
- )
498
- }
499
-
500
- // Grid lines (vertical at value tick positions)
501
- for (const tick of valueTicks) {
502
- const cx = valueToCol(tick)
503
- if (cx < plotLeft || cx >= plotLeft + plotW) continue
504
- for (let r = plotTop; r < plotTop + plotH; r++) {
505
- if (get(canvas, r, cx) === ' ') {
506
- set(canvas, roles, r, cx, ch.grid, 'line')
507
- }
508
- }
509
- }
510
-
511
- // Bars (horizontal) — with per-series colors
512
- const barEntries: { data: number[]; globalIdx: number }[] = []
513
- for (let si = 0; si < chart.series.length; si++) {
514
- if (chart.series[si]!.type === 'bar')
515
- barEntries.push({ data: chart.series[si]!.data, globalIdx: si })
516
- }
517
-
518
- if (barEntries.length > 0) {
519
- // Same overlay/occlusion behavior as the vertical layout above (issue
520
- // #452): every bar series in a category shares one row rather than
521
- // being split into grouped sub-rows, so a later series' bar paints over
522
- // an earlier one.
523
- const singleBarH = 1
524
- const baseCol = valueToCol(Math.max(0, yRange.min))
525
-
526
- for (let bIdx = 0; bIdx < barEntries.length; bIdx++) {
527
- const entry = barEntries[bIdx]!
528
- const hexColor = seriesColors[entry.globalIdx]!
529
- for (let i = 0; i < entry.data.length; i++) {
530
- const by = bandMid(i)
531
- const valCol = valueToCol(entry.data[i]!)
532
- const fromCol = Math.min(baseCol, valCol)
533
- const toCol = Math.max(baseCol, valCol)
534
-
535
- for (let r = by; r < by + singleBarH; r++) {
536
- for (let c = fromCol; c <= toCol; c++) {
537
- set(canvas, roles, r, c, ch.bar, 'arrow', hexColors, hexColor)
538
- }
539
- }
540
- }
541
- }
542
- }
543
-
544
- // Lines (horizontal staircase: value on x, category on y) — with per-series colors
545
- const lineEntries: { data: number[]; globalIdx: number }[] = []
546
- for (let si = 0; si < chart.series.length; si++) {
547
- if (chart.series[si]!.type === 'line')
548
- lineEntries.push({ data: chart.series[si]!.data, globalIdx: si })
549
- }
550
-
551
- for (const entry of lineEntries) {
552
- if (entry.data.length === 0) continue
553
- const hexColor = seriesColors[entry.globalIdx]!
554
- drawHorizontalStaircaseLine(
555
- canvas,
556
- roles,
557
- entry.data,
558
- bandMid,
559
- valueToCol,
560
- plotTop,
561
- plotH,
562
- plotLeft,
563
- plotW,
564
- ch,
565
- hexColors,
566
- hexColor,
567
- )
568
- }
569
-
570
- return canvasToString(canvas, roles, hexColors, colorMode, theme)
571
- }
572
-
573
- // ============================================================================
574
- // Staircase line drawing — vertical charts
575
- //
576
- // Connects data points with flat segments (─) at each value's row,
577
- // vertical segments (│) between rows, and rounded corners (╭╮╰╯)
578
- // at transitions. The vertical step happens at the midpoint column
579
- // between adjacent data points.
580
- // ============================================================================
581
-
582
- function drawStaircaseLine(
583
- canvas: Canvas,
584
- roles: RoleCanvas,
585
- data: number[],
586
- bandCenter: (i: number) => number,
587
- valueToRow: (v: number) => number,
588
- plotTop: number,
589
- plotH: number,
590
- plotLeft: number,
591
- plotTotalW: number,
592
- ch: typeof UNI | typeof ASC,
593
- hexCanvas?: HexCanvas,
594
- hexColor?: string | null,
595
- ): void {
596
- if (data.length === 0) return
597
-
598
- const points = data.map((v, i) => ({
599
- col: bandCenter(i),
600
- row: valueToRow(v),
601
- }))
602
-
603
- // Helper to draw on the canvas (row 0 = bottom, displayed inverted)
604
- const drawAt = (col: number, row: number, char: string) => {
605
- const displayRow = plotTop + (plotH - 1 - row)
606
- if (displayRow >= 0 && col >= plotLeft && col < plotLeft + plotTotalW) {
607
- set(canvas, roles, displayRow, col, char, 'arrow', hexCanvas, hexColor)
608
- }
609
- }
610
-
611
- // Single point: just draw a flat segment
612
- if (points.length === 1) {
613
- drawAt(points[0]!.col, points[0]!.row, ch.hLine)
614
- return
615
- }
616
-
617
- for (let i = 0; i < points.length - 1; i++) {
618
- const p1 = points[i]!
619
- const p2 = points[i + 1]!
620
-
621
- if (p1.row === p2.row) {
622
- // Flat: draw ─ across
623
- for (let c = p1.col; c <= p2.col; c++) {
624
- drawAt(c, p1.row, ch.hLine)
625
- }
626
- continue
627
- }
628
-
629
- const midCol = Math.round((p1.col + p2.col) / 2)
630
- const goingUp = p2.row > p1.row
631
-
632
- // 1. Flat at p1's row from p1.col to midCol-1
633
- for (let c = p1.col; c < midCol; c++) {
634
- drawAt(c, p1.row, ch.hLine)
635
- }
636
-
637
- // 2. Corner at (midCol, p1.row)
638
- // goingUp: ─ from LEFT, │ going UP → LEFT+TOP = ╯ (cornerBR)
639
- // goingDown: ─ from LEFT, │ going DOWN → LEFT+BOT = ╮ (cornerTR)
640
- if (goingUp) {
641
- drawAt(midCol, p1.row, ch.cornerBR) // ╯
642
- } else {
643
- drawAt(midCol, p1.row, ch.cornerTR) // ╮
644
- }
645
-
646
- // 3. Vertical from p1.row to p2.row (exclusive of endpoints)
647
- const minRow = Math.min(p1.row, p2.row)
648
- const maxRow = Math.max(p1.row, p2.row)
649
- for (let row = minRow + 1; row < maxRow; row++) {
650
- drawAt(midCol, row, ch.vLine)
651
- }
652
-
653
- // 4. Corner at (midCol, p2.row)
654
- // goingUp: │ from BOTTOM, ─ going RIGHT → BOT+RIGHT = ╭ (cornerTL)
655
- // goingDown: │ from TOP, ─ going RIGHT → TOP+RIGHT = ╰ (cornerBL)
656
- if (goingUp) {
657
- drawAt(midCol, p2.row, ch.cornerTL) // ╭
658
- } else {
659
- drawAt(midCol, p2.row, ch.cornerBL) // ╰
660
- }
661
-
662
- // 5. Flat at p2's row from midCol+1 to p2.col
663
- for (let c = midCol + 1; c <= p2.col; c++) {
664
- drawAt(c, p2.row, ch.hLine)
665
- }
666
-
667
- // Leading flat for first segment (before p1.col)
668
- if (i === 0) {
669
- const leadStart = Math.max(
670
- plotLeft,
671
- p1.col - Math.floor((p2.col - p1.col) / 4),
672
- )
673
- for (let c = leadStart; c < p1.col; c++) {
674
- drawAt(c, p1.row, ch.hLine)
675
- }
676
- }
677
-
678
- // Trailing flat for last segment (after p2.col)
679
- if (i === points.length - 2) {
680
- const trailEnd = Math.min(
681
- plotLeft + plotTotalW - 1,
682
- p2.col + Math.floor((p2.col - p1.col) / 4),
683
- )
684
- for (let c = p2.col + 1; c <= trailEnd; c++) {
685
- drawAt(c, p2.row, ch.hLine)
686
- }
687
- }
688
- }
689
- }
690
-
691
- // ============================================================================
692
- // Staircase line drawing — horizontal charts
693
- //
694
- // Same staircase approach but with axes swapped:
695
- // data values map to columns (horizontal position) and categories map to
696
- // rows (vertical position). Flat segments are vertical (│), transitions
697
- // are horizontal (─), with the same rounded corners.
698
- // ============================================================================
699
-
700
- function drawHorizontalStaircaseLine(
701
- canvas: Canvas,
702
- roles: RoleCanvas,
703
- data: number[],
704
- bandMid: (i: number) => number,
705
- valueToCol: (v: number) => number,
706
- plotTop: number,
707
- plotH: number,
708
- plotLeft: number,
709
- plotW: number,
710
- ch: typeof UNI | typeof ASC,
711
- hexCanvas?: HexCanvas,
712
- hexColor?: string | null,
713
- ): void {
714
- if (data.length === 0) return
715
-
716
- const points = data.map((v, i) => ({
717
- row: bandMid(i),
718
- col: valueToCol(v),
719
- }))
720
-
721
- const drawAt = (row: number, col: number, char: string) => {
722
- if (
723
- row >= plotTop &&
724
- row < plotTop + plotH &&
725
- col >= plotLeft &&
726
- col < plotLeft + plotW
727
- ) {
728
- set(canvas, roles, row, col, char, 'arrow', hexCanvas, hexColor)
729
- }
730
- }
731
-
732
- if (points.length === 1) {
733
- drawAt(points[0]!.row, points[0]!.col, ch.vLine)
734
- return
735
- }
736
-
737
- for (let i = 0; i < points.length - 1; i++) {
738
- const p1 = points[i]!
739
- const p2 = points[i + 1]!
740
-
741
- if (p1.col === p2.col) {
742
- // Same value: draw │ down
743
- for (let r = p1.row; r <= p2.row; r++) {
744
- drawAt(r, p1.col, ch.vLine)
745
- }
746
- continue
747
- }
748
-
749
- const midRow = Math.round((p1.row + p2.row) / 2)
750
- const goingRight = p2.col > p1.col
751
-
752
- // 1. Vertical at p1's col from p1.row to midRow-1
753
- for (let r = p1.row; r < midRow; r++) {
754
- drawAt(r, p1.col, ch.vLine)
755
- }
756
-
757
- // 2. Corner at (midRow, p1.col)
758
- // goingRight: │ from TOP, ─ going RIGHT → TOP+RIGHT = ╰ (cornerBL)
759
- // goingLeft: │ from TOP, ─ going LEFT → TOP+LEFT = ╯ (cornerBR)
760
- if (goingRight) {
761
- drawAt(midRow, p1.col, ch.cornerBL) // ╰
762
- } else {
763
- drawAt(midRow, p1.col, ch.cornerBR) // ╯
764
- }
765
-
766
- // 3. Horizontal from p1.col to p2.col (exclusive)
767
- const minCol = Math.min(p1.col, p2.col)
768
- const maxCol = Math.max(p1.col, p2.col)
769
- for (let c = minCol + 1; c < maxCol; c++) {
770
- drawAt(midRow, c, ch.hLine)
771
- }
772
-
773
- // 4. Corner at (midRow, p2.col)
774
- // goingRight: ─ from LEFT, │ going DOWN → LEFT+BOT = ╮ (cornerTR)
775
- // goingLeft: ─ from RIGHT, │ going DOWN → RIGHT+BOT = ╭ (cornerTL)
776
- if (goingRight) {
777
- drawAt(midRow, p2.col, ch.cornerTR) // ╮
778
- } else {
779
- drawAt(midRow, p2.col, ch.cornerTL) // ╭
780
- }
781
-
782
- // 5. Vertical at p2's col from midRow+1 to p2.row
783
- for (let r = midRow + 1; r <= p2.row; r++) {
784
- drawAt(r, p2.col, ch.vLine)
785
- }
786
- }
787
- }
788
-
789
- // ============================================================================
790
- // Legend — shows series symbols with per-series colors
791
- // ============================================================================
792
-
793
- function drawLegend(
794
- canvas: Canvas,
795
- roles: RoleCanvas,
796
- hexCanvas: HexCanvas,
797
- chart: XYChart,
798
- row: number,
799
- totalW: number,
800
- ch: typeof UNI | typeof ASC,
801
- seriesColors: string[],
802
- ): void {
803
- // Build legend items with global series indices
804
- type LegendItem = { symbol: string; label: string; globalIdx: number }
805
- const items: LegendItem[] = []
806
- let barIdx = 0,
807
- lineIdx = 0
808
- for (let si = 0; si < chart.series.length; si++) {
809
- const s = chart.series[si]!
810
- if (s.type === 'bar') {
811
- items.push({ symbol: ch.bar, label: `Bar ${barIdx + 1}`, globalIdx: si })
812
- barIdx++
813
- } else {
814
- items.push({
815
- symbol: ch.hLine,
816
- label: `Line ${lineIdx + 1}`,
817
- globalIdx: si,
818
- })
819
- lineIdx++
820
- }
821
- }
822
-
823
- // Calculate total legend width: "symbol space label symbol space label ..."
824
- let totalLen = 0
825
- for (let i = 0; i < items.length; i++) {
826
- if (i > 0) totalLen += 2 // gap between items
827
- totalLen += 1 + 1 + items[i]!.label.length // symbol + space + label
828
- }
829
-
830
- const startCol = Math.max(0, Math.floor(totalW / 2 - totalLen / 2))
831
- let col = startCol
832
-
833
- for (let i = 0; i < items.length; i++) {
834
- if (i > 0) col += 2 // gap
835
- const item = items[i]!
836
- // Symbol with series-specific color
837
- set(
838
- canvas,
839
- roles,
840
- row,
841
- col,
842
- item.symbol,
843
- 'arrow',
844
- hexCanvas,
845
- seriesColors[item.globalIdx],
846
- )
847
- col += 1
848
- // Space (already ' ' from canvas init)
849
- col += 1
850
- // Label text
851
- writeText(canvas, roles, row, col, item.label, 'text')
852
- col += item.label.length
853
- }
854
- }
855
-
856
- // ============================================================================
857
- // Canvas utilities
858
- // ============================================================================
859
-
860
- // createCanvas/createRoleCanvas delegate to the shared canvas.ts primitives
861
- // (mkCanvas/mkRoleCanvas), which take inclusive max-index arguments rather
862
- // than width/height — hence the `- 1`. createHexCanvas has no shared
863
- // equivalent: the per-cell hex color overlay is specific to xychart's
864
- // multi-series coloring and isn't part of the general Canvas/RoleCanvas
865
- // model in canvas.ts, so it keeps its own small implementation.
866
- function createCanvas(width: number, height: number): Canvas {
867
- return mkCanvas(width - 1, height - 1)
868
- }
869
-
870
- function createRoleCanvas(width: number, height: number): RoleCanvas {
871
- return mkRoleCanvas(width - 1, height - 1)
872
- }
873
-
874
- function createHexCanvas(width: number, height: number): HexCanvas {
875
- return Array.from({ length: width }, () =>
876
- Array.from<string | null>({ length: height }).fill(null),
877
- )
878
- }
879
-
880
- function set(
881
- canvas: Canvas,
882
- roles: RoleCanvas,
883
- row: number,
884
- col: number,
885
- char: string,
886
- role: CharRole,
887
- hexCanvas?: HexCanvas,
888
- hex?: string | null,
889
- ): void {
890
- // Delegate the character+role write to the shared bounds-checked
891
- // primitive (same clipping semantics as before: out-of-range coordinates
892
- // are silently ignored). The hex-color overlay isn't known to canvas.ts,
893
- // so it's still set here directly, guarded by the same bounds check.
894
- const inBounds =
895
- col >= 0 &&
896
- col < canvas.length &&
897
- row >= 0 &&
898
- row < (canvas[0]?.length ?? 0)
899
- if (!inBounds) return
900
- write(canvas, col, row, char, { role, roleCanvas: roles })
901
- if (hexCanvas && hex) hexCanvas[col]![row] = hex
902
- }
903
-
904
- function get(canvas: Canvas, row: number, col: number): string {
905
- if (col >= 0 && col < canvas.length && row >= 0 && row < canvas[0]!.length) {
906
- return canvas[col]![row]!
907
- }
908
- return ' '
909
- }
910
-
911
- function writeText(
912
- canvas: Canvas,
913
- roles: RoleCanvas,
914
- row: number,
915
- startCol: number,
916
- text: string,
917
- role: CharRole,
918
- ): void {
919
- for (let i = 0; i < text.length; i++) {
920
- set(canvas, roles, row, startCol + i, text[i]!, role)
921
- }
922
- }
923
-
924
- // ============================================================================
925
- // Canvas → string (with per-cell hex color support)
926
- // ============================================================================
927
-
928
- function canvasToString(
929
- canvas: Canvas,
930
- roles: RoleCanvas,
931
- hexCanvas: HexCanvas,
932
- colorMode: ColorMode,
933
- theme: AsciiTheme,
934
- ): string {
935
- if (canvas.length === 0) return ''
936
- const height = canvas[0]!.length
937
- const width = canvas.length
938
- const lines: string[] = []
939
-
940
- for (let row = 0; row < height; row++) {
941
- const chars: string[] = []
942
- const rowRoles: (CharRole | null)[] = []
943
- const rowHex: (string | null)[] = []
944
- for (let col = 0; col < width; col++) {
945
- chars.push(canvas[col]![row]!)
946
- rowRoles.push(roles[col]![row]!)
947
- rowHex.push(hexCanvas[col]![row]!)
948
- }
949
- // Trim trailing spaces
950
- let end = chars.length - 1
951
- while (end >= 0 && chars[end] === ' ') end--
952
- if (end < 0) {
953
- lines.push('')
954
- } else {
955
- lines.push(
956
- colorizeRow(
957
- chars.slice(0, end + 1),
958
- rowRoles.slice(0, end + 1),
959
- rowHex.slice(0, end + 1),
960
- theme,
961
- colorMode,
962
- ),
963
- )
964
- }
965
- }
966
-
967
- // Trim trailing empty lines
968
- while (lines.length > 0 && lines[lines.length - 1] === '') {
969
- lines.pop()
970
- }
971
-
972
- return lines.join('\n')
973
- }
974
-
975
- /**
976
- * Colorize a row of characters, using hex color overrides where available
977
- * and falling back to role-based theme colors otherwise.
978
- * Groups consecutive same-color characters for efficient escape sequences.
979
- */
980
- function colorizeRow(
981
- chars: string[],
982
- roles: (CharRole | null)[],
983
- hexOverrides: (string | null)[],
984
- theme: AsciiTheme,
985
- mode: ColorMode,
986
- ): string {
987
- if (mode === 'none') return chars.join('')
988
-
989
- let result = ''
990
- let currentColor: string | null = null
991
- let buffer = ''
992
-
993
- for (let i = 0; i < chars.length; i++) {
994
- const char = chars[i]!
995
-
996
- if (char === ' ') {
997
- // Flush buffer before whitespace
998
- if (buffer.length > 0) {
999
- result += currentColor
1000
- ? colorizeText(buffer, currentColor, mode)
1001
- : buffer
1002
- buffer = ''
1003
- currentColor = null
1004
- }
1005
- result += ' '
1006
- continue
1007
- }
1008
-
1009
- // Effective color: hex override > role-based > null
1010
- const hexOvr = hexOverrides[i] ?? null
1011
- const roleVal = roles[i] ?? null
1012
- const color = hexOvr ?? (roleVal ? roleToHex(roleVal, theme) : null)
1013
-
1014
- if (color === currentColor) {
1015
- buffer += char
1016
- } else {
1017
- // Flush previous group
1018
- if (buffer.length > 0) {
1019
- result += currentColor
1020
- ? colorizeText(buffer, currentColor, mode)
1021
- : buffer
1022
- }
1023
- buffer = char
1024
- currentColor = color
1025
- }
1026
- }
1027
-
1028
- // Flush remaining
1029
- if (buffer.length > 0) {
1030
- result += currentColor ? colorizeText(buffer, currentColor, mode) : buffer
1031
- }
1032
-
1033
- return result
1034
- }
1035
-
1036
- // ============================================================================
1037
- // Helpers (chart-level)
1038
- // ============================================================================
1039
-
1040
- function getDataCount(chart: XYChart): number {
1041
- if (chart.xAxis.categories) return chart.xAxis.categories.length
1042
- for (const s of chart.series) {
1043
- if (s.data.length > 0) return s.data.length
1044
- }
1045
- return 0
1046
- }
1047
-
1048
- function getCategoryLabels(chart: XYChart, count: number): string[] {
1049
- if (chart.xAxis.categories) return chart.xAxis.categories
1050
- if (chart.xAxis.range) {
1051
- const { min, max } = chart.xAxis.range
1052
- const step = count > 1 ? (max - min) / (count - 1) : 0
1053
- return Array.from({ length: count }, (_, i) =>
1054
- formatTickValue(min + step * i),
1055
- )
1056
- }
1057
- return Array.from({ length: count }, (_, i) => String(i + 1))
1058
- }
1059
-
1060
- /** Generate nice tick values for a numeric range. */
1061
- function niceTickValues(min: number, max: number): number[] {
1062
- const range = max - min
1063
- if (range <= 0) return [min]
1064
-
1065
- const rawInterval = range / 6
1066
- const magnitude = Math.pow(10, Math.floor(Math.log10(rawInterval)))
1067
- const residual = rawInterval / magnitude
1068
- let niceInterval: number
1069
- if (residual <= 1.5) niceInterval = magnitude
1070
- else if (residual <= 3) niceInterval = 2 * magnitude
1071
- else if (residual <= 7) niceInterval = 5 * magnitude
1072
- else niceInterval = 10 * magnitude
1073
-
1074
- const start = Math.ceil(min / niceInterval) * niceInterval
1075
- const ticks: number[] = []
1076
- for (let v = start; v <= max + niceInterval * 0.001; v += niceInterval) {
1077
- ticks.push(Math.round(v * 1e10) / 1e10)
1078
- }
1079
- return ticks
1080
- }
1081
-
1082
- function formatTickValue(v: number): string {
1083
- if (Number.isInteger(v)) return String(v)
1084
- return v.toFixed(Math.abs(v) < 10 ? 1 : 0)
1085
- }