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.
- package/README.md +4 -4
- package/dist/ascii.cjs +1 -11
- package/dist/ascii.d.cts +1 -167
- package/dist/ascii.d.ts +1 -167
- package/dist/ascii.js +1 -6591
- package/dist/cli.js +836 -10946
- package/dist/index.cjs +2 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -680
- package/dist/index.d.ts +42 -680
- package/dist/index.js +408 -10002
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +1 -17909
- package/dist/mcp.d.cts +1 -11
- package/dist/mcp.d.ts +1 -11
- package/dist/mcp.js +1 -17884
- package/package.json +29 -29
- package/src/__tests__/workspace-package-boundaries.test.ts +15 -16
- package/src/__tests__/xychart-parser-categories.test.ts +78 -0
- package/src/ascii-entry.ts +14 -0
- package/src/cli/html-viewer.ts +5 -0
- package/src/mcp-entry.ts +21 -0
- package/dist/ascii.cjs.map +0 -1
- package/dist/ascii.js.map +0 -1
- package/dist/mcp.cjs.map +0 -1
- package/dist/mcp.js.map +0 -1
- package/packages/ascii-renderer/LICENSE +0 -22
- package/packages/ascii-renderer/src/ansi.ts +0 -490
- package/packages/ascii-renderer/src/canvas.ts +0 -658
- package/packages/ascii-renderer/src/class-diagram.ts +0 -2001
- package/packages/ascii-renderer/src/converter.ts +0 -446
- package/packages/ascii-renderer/src/coords.ts +0 -58
- package/packages/ascii-renderer/src/display-width.ts +0 -151
- package/packages/ascii-renderer/src/draw-arrows.ts +0 -549
- package/packages/ascii-renderer/src/draw-boxes.ts +0 -267
- package/packages/ascii-renderer/src/draw-bundles.ts +0 -611
- package/packages/ascii-renderer/src/draw-lines.ts +0 -174
- package/packages/ascii-renderer/src/draw-subgraphs.ts +0 -108
- package/packages/ascii-renderer/src/draw.ts +0 -337
- package/packages/ascii-renderer/src/edge-bundling.ts +0 -435
- package/packages/ascii-renderer/src/edge-cell-styles.ts +0 -81
- package/packages/ascii-renderer/src/edge-routing.ts +0 -1049
- package/packages/ascii-renderer/src/er-diagram.ts +0 -1488
- package/packages/ascii-renderer/src/flowchart.ts +0 -94
- package/packages/ascii-renderer/src/grid-occupancy.ts +0 -234
- package/packages/ascii-renderer/src/grid.ts +0 -1267
- package/packages/ascii-renderer/src/hyperlinks.ts +0 -248
- package/packages/ascii-renderer/src/index.ts +0 -163
- package/packages/ascii-renderer/src/lane-search.ts +0 -68
- package/packages/ascii-renderer/src/multiline-utils.ts +0 -82
- package/packages/ascii-renderer/src/pathfinder.ts +0 -448
- package/packages/ascii-renderer/src/registry.ts +0 -88
- package/packages/ascii-renderer/src/sequence.ts +0 -1318
- package/packages/ascii-renderer/src/shapes/circle.ts +0 -31
- package/packages/ascii-renderer/src/shapes/corners.ts +0 -273
- package/packages/ascii-renderer/src/shapes/diamond.ts +0 -31
- package/packages/ascii-renderer/src/shapes/hexagon.ts +0 -31
- package/packages/ascii-renderer/src/shapes/index.ts +0 -123
- package/packages/ascii-renderer/src/shapes/rectangle.ts +0 -199
- package/packages/ascii-renderer/src/shapes/rounded.ts +0 -31
- package/packages/ascii-renderer/src/shapes/special.ts +0 -352
- package/packages/ascii-renderer/src/shapes/stadium.ts +0 -122
- package/packages/ascii-renderer/src/shapes/state.ts +0 -204
- package/packages/ascii-renderer/src/shapes/types.ts +0 -78
- package/packages/ascii-renderer/src/territory.ts +0 -136
- package/packages/ascii-renderer/src/types.ts +0 -454
- package/packages/ascii-renderer/src/validate.ts +0 -189
- package/packages/ascii-renderer/src/xychart.ts +0 -1085
- package/packages/core/LICENSE +0 -22
- package/packages/core/src/click-directive.ts +0 -106
- package/packages/core/src/color-utils.ts +0 -205
- package/packages/core/src/diagram-type.ts +0 -35
- package/packages/core/src/direction-override.ts +0 -46
- package/packages/core/src/direction.ts +0 -56
- package/packages/core/src/index.ts +0 -34
- package/packages/core/src/init-directive.ts +0 -248
- package/packages/core/src/multiline-utils.ts +0 -275
- package/packages/core/src/statements.ts +0 -197
- package/packages/core/src/style-directives.ts +0 -214
- package/packages/core/src/text-metrics.ts +0 -498
- package/packages/core/src/theme.ts +0 -696
- package/packages/core/src/types.ts +0 -670
- package/packages/mcp/LICENSE +0 -22
- package/packages/mcp/src/index.ts +0 -17
- package/packages/mcp/src/server.ts +0 -135
- package/packages/mcp/src/tools/check-sequence-activations.ts +0 -91
- package/packages/mcp/src/tools/fix-sequence-activations.ts +0 -77
- package/packages/mcp/src/tools/render-ascii.ts +0 -99
- package/packages/mcp/src/tools/render-svg.ts +0 -95
- package/packages/mermaid-parser/LICENSE +0 -22
- package/packages/mermaid-parser/src/class/format.ts +0 -15
- package/packages/mermaid-parser/src/class/parser.ts +0 -593
- package/packages/mermaid-parser/src/class/types.ts +0 -166
- package/packages/mermaid-parser/src/er/parser.ts +0 -286
- package/packages/mermaid-parser/src/er/types.ts +0 -99
- package/packages/mermaid-parser/src/expanded-shapes.ts +0 -376
- package/packages/mermaid-parser/src/index.ts +0 -48
- package/packages/mermaid-parser/src/sequence/activation-check.ts +0 -149
- package/packages/mermaid-parser/src/sequence/activation-fix.ts +0 -112
- package/packages/mermaid-parser/src/sequence/box-color.ts +0 -85
- package/packages/mermaid-parser/src/sequence/parser.ts +0 -613
- package/packages/mermaid-parser/src/sequence/types.ts +0 -242
- package/packages/mermaid-parser/src/xychart/colors.ts +0 -177
- package/packages/mermaid-parser/src/xychart/parser.ts +0 -203
- package/packages/mermaid-parser/src/xychart/types.ts +0 -150
- package/packages/svg-renderer/LICENSE +0 -22
- package/packages/svg-renderer/src/class/layout.ts +0 -360
- package/packages/svg-renderer/src/class/renderer.ts +0 -636
- package/packages/svg-renderer/src/edge-curves.ts +0 -204
- package/packages/svg-renderer/src/elk-instance.ts +0 -292
- package/packages/svg-renderer/src/er/layout.ts +0 -200
- package/packages/svg-renderer/src/er/renderer.ts +0 -493
- package/packages/svg-renderer/src/index.ts +0 -58
- package/packages/svg-renderer/src/layout-engine/constants.ts +0 -19
- package/packages/svg-renderer/src/layout-engine/edge-bundling.ts +0 -379
- package/packages/svg-renderer/src/layout-engine/elk-adapter-utils.ts +0 -81
- package/packages/svg-renderer/src/layout-engine/elk-graph-builder.ts +0 -240
- package/packages/svg-renderer/src/layout-engine/from-elk.ts +0 -685
- package/packages/svg-renderer/src/layout-engine/layer-alignment.ts +0 -174
- package/packages/svg-renderer/src/layout-engine/to-elk.ts +0 -695
- package/packages/svg-renderer/src/layout-engine.ts +0 -74
- package/packages/svg-renderer/src/layout.ts +0 -8
- package/packages/svg-renderer/src/renderer.ts +0 -1485
- package/packages/svg-renderer/src/resolve-colors.ts +0 -339
- package/packages/svg-renderer/src/sequence/layout.ts +0 -698
- package/packages/svg-renderer/src/sequence/renderer.ts +0 -546
- package/packages/svg-renderer/src/shape-clipping.ts +0 -197
- package/packages/svg-renderer/src/styles.ts +0 -118
- package/packages/svg-renderer/src/xychart/layout.ts +0 -682
- package/packages/svg-renderer/src/xychart/renderer.ts +0 -684
- package/src/__tests__/ascii-canvas-write.test.ts +0 -137
- package/src/__tests__/ascii-charset-border-junctions.test.ts +0 -63
- package/src/__tests__/ascii-cjk-width.test.ts +0 -150
- package/src/__tests__/ascii-class-box-occupancy.test.ts +0 -462
- package/src/__tests__/ascii-class-column-width-488-489.test.ts +0 -639
- package/src/__tests__/ascii-class-cross-level-jog-corruption.test.ts +0 -187
- package/src/__tests__/ascii-class-detour-label-routing-487.test.ts +0 -114
- package/src/__tests__/ascii-class-diagram-compartments.test.ts +0 -70
- package/src/__tests__/ascii-class-label-box-collision.test.ts +0 -60
- package/src/__tests__/ascii-class-label-row-collision-531.test.ts +0 -135
- package/src/__tests__/ascii-class-label-territory-row-awareness.test.ts +0 -57
- package/src/__tests__/ascii-class-padding.test.ts +0 -104
- package/src/__tests__/ascii-class-parent-alignment-971.test.ts +0 -139
- package/src/__tests__/ascii-class-parent-alignment-972.test.ts +0 -208
- package/src/__tests__/ascii-class-reciprocal-relationships-448.test.ts +0 -169
- package/src/__tests__/ascii-combining-mark-width.test.ts +0 -70
- package/src/__tests__/ascii-coords-overlay.test.ts +0 -64
- package/src/__tests__/ascii-decision-lr-box-start.test.ts +0 -106
- package/src/__tests__/ascii-display-width-unit.test.ts +0 -154
- package/src/__tests__/ascii-draw-arrows-coverage.test.ts +0 -171
- package/src/__tests__/ascii-draw-arrows-single-point-path.test.ts +0 -112
- package/src/__tests__/ascii-edge-bundling-rank-violation-454.test.ts +0 -72
- package/src/__tests__/ascii-edge-ending-glyphs.test.ts +0 -206
- package/src/__tests__/ascii-edge-label-diagonal-fallback-418.test.ts +0 -95
- package/src/__tests__/ascii-edge-routing-fixes.test.ts +0 -178
- package/src/__tests__/ascii-edge-routing-single-point-path.test.ts +0 -107
- package/src/__tests__/ascii-edge-styles.test.ts +0 -149
- package/src/__tests__/ascii-emoji-cluster-width.test.ts +0 -101
- package/src/__tests__/ascii-er-box-occupancy.test.ts +0 -251
- package/src/__tests__/ascii-er-cardinality.test.ts +0 -40
- package/src/__tests__/ascii-er-corner-glyphs.test.ts +0 -249
- package/src/__tests__/ascii-er-jog-stray-line.test.ts +0 -111
- package/src/__tests__/ascii-er-label-padding.test.ts +0 -118
- package/src/__tests__/ascii-er-padding.test.ts +0 -114
- package/src/__tests__/ascii-er-relationship-label-corruption-350.test.ts +0 -458
- package/src/__tests__/ascii-er-relationship-overwrite.test.ts +0 -325
- package/src/__tests__/ascii-er-stray-connectors.test.ts +0 -347
- package/src/__tests__/ascii-er-unrelated-stem-separation-411.test.ts +0 -98
- package/src/__tests__/ascii-er-vertical-one-marker.test.ts +0 -110
- package/src/__tests__/ascii-label-line-terminal-fallback.test.ts +0 -172
- package/src/__tests__/ascii-lane-search.test.ts +0 -207
- package/src/__tests__/ascii-multibox-cjk-width.test.ts +0 -184
- package/src/__tests__/ascii-multiline.test.ts +0 -291
- package/src/__tests__/ascii-padding-edge-cases.test.ts +0 -154
- package/src/__tests__/ascii-pathfinder-route-edge.test.ts +0 -194
- package/src/__tests__/ascii-sequence-alt-else-label.test.ts +0 -236
- package/src/__tests__/ascii-sequence-block-wall-clearance.test.ts +0 -217
- package/src/__tests__/ascii-sequence-box-group.test.ts +0 -159
- package/src/__tests__/ascii-sequence-cjk-width.test.ts +0 -235
- package/src/__tests__/ascii-sequence-create-destroy.test.ts +0 -114
- package/src/__tests__/ascii-sequence-form-invariants.test.ts +0 -432
- package/src/__tests__/ascii-sequence-mermaid-parity.test.ts +0 -219
- package/src/__tests__/ascii-sequence-notes.test.ts +0 -61
- package/src/__tests__/ascii-sequence-padding.test.ts +0 -119
- package/src/__tests__/ascii-sequence-self-arrow.test.ts +0 -206
- package/src/__tests__/ascii-shape-diamond.test.ts +0 -38
- package/src/__tests__/ascii-shape-rectangle.test.ts +0 -258
- package/src/__tests__/ascii-shape-rounded.test.ts +0 -36
- package/src/__tests__/ascii-shapes-circle.test.ts +0 -41
- package/src/__tests__/ascii-shapes-hexagon.test.ts +0 -42
- package/src/__tests__/ascii-shapes-special.test.ts +0 -349
- package/src/__tests__/ascii-shapes-stadium.test.ts +0 -217
- package/src/__tests__/ascii-shapes-state.test.ts +0 -234
- package/src/__tests__/ascii-state-bidirectional-label-swap-530.test.ts +0 -130
- package/src/__tests__/ascii-subgraph-direction-honored-445.test.ts +0 -90
- package/src/__tests__/ascii-subgraph-label-border-clip.test.ts +0 -152
- package/src/__tests__/ascii-subgraph-title-padding.test.ts +0 -77
- package/src/__tests__/ascii-territory-unit.test.ts +0 -219
- package/src/__tests__/ascii-validate.test.ts +0 -220
- package/src/__tests__/ascii.test.ts +0 -328
- package/src/__tests__/box-color.test.ts +0 -80
- package/src/__tests__/class-arrow-directions.test.ts +0 -505
- package/src/__tests__/click-directive.test.ts +0 -63
- package/src/__tests__/color-utils.test.ts +0 -186
- package/src/__tests__/diagram-type.test.ts +0 -28
- package/src/__tests__/draw-lines.test.ts +0 -93
- package/src/__tests__/edge-cell-styles.test.ts +0 -180
- package/src/__tests__/elk-adapter-utils.test.ts +0 -166
- package/src/__tests__/grid-occupancy.test.ts +0 -240
- package/src/__tests__/helpers/ascii-form.ts +0 -142
- package/src/__tests__/helpers/terminal-display-width.ts +0 -74
- package/src/__tests__/mcp-check-sequence-activations-tool.test.ts +0 -85
- package/src/__tests__/mcp-fix-sequence-activations-tool.test.ts +0 -134
- package/src/__tests__/mcp-server.test.ts +0 -163
- package/src/__tests__/pathfinder.test.ts +0 -246
- package/src/__tests__/sequence-activation-fix.test.ts +0 -91
- package/src/__tests__/testdata/ascii/ampersand_lhs.txt +0 -18
- package/src/__tests__/testdata/ascii/ampersand_lhs_and_rhs.txt +0 -18
- package/src/__tests__/testdata/ascii/ampersand_rhs.txt +0 -18
- package/src/__tests__/testdata/ascii/ampersand_td_fanin.txt +0 -18
- package/src/__tests__/testdata/ascii/ampersand_td_fanout.txt +0 -18
- package/src/__tests__/testdata/ascii/ampersand_without_edge.txt +0 -18
- package/src/__tests__/testdata/ascii/back_reference_from_child.txt +0 -10
- package/src/__tests__/testdata/ascii/backlink_from_bottom.txt +0 -22
- package/src/__tests__/testdata/ascii/backlink_from_top.txt +0 -22
- package/src/__tests__/testdata/ascii/backlink_with_short_y_padding.txt +0 -20
- package/src/__tests__/testdata/ascii/cls_all_relationships.txt +0 -19
- package/src/__tests__/testdata/ascii/cls_annotation.txt +0 -29
- package/src/__tests__/testdata/ascii/cls_association.txt +0 -14
- package/src/__tests__/testdata/ascii/cls_basic.txt +0 -15
- package/src/__tests__/testdata/ascii/cls_dependency.txt +0 -14
- package/src/__tests__/testdata/ascii/cls_inheritance.txt +0 -20
- package/src/__tests__/testdata/ascii/cls_methods.txt +0 -21
- package/src/__tests__/testdata/ascii/comments.txt +0 -23
- package/src/__tests__/testdata/ascii/custom_padding.txt +0 -10
- package/src/__tests__/testdata/ascii/duplicate_labels.txt +0 -19
- package/src/__tests__/testdata/ascii/er_attributes.txt +0 -21
- package/src/__tests__/testdata/ascii/er_basic.txt +0 -8
- package/src/__tests__/testdata/ascii/er_identifying.txt +0 -18
- package/src/__tests__/testdata/ascii/flowchart_tb_simple.txt +0 -29
- package/src/__tests__/testdata/ascii/graph_bt_direction.txt +0 -28
- package/src/__tests__/testdata/ascii/graph_tb_direction.txt +0 -26
- package/src/__tests__/testdata/ascii/nested_subgraphs_with_labels.txt +0 -36
- package/src/__tests__/testdata/ascii/preserve_order_of_definition.txt +0 -23
- package/src/__tests__/testdata/ascii/self_reference.txt +0 -10
- package/src/__tests__/testdata/ascii/self_reference_with_edge.txt +0 -10
- package/src/__tests__/testdata/ascii/seq_basic.txt +0 -17
- package/src/__tests__/testdata/ascii/seq_multiple_messages.txt +0 -25
- package/src/__tests__/testdata/ascii/seq_self_message.txt +0 -18
- package/src/__tests__/testdata/ascii/single_node.txt +0 -8
- package/src/__tests__/testdata/ascii/single_node_longer_name.txt +0 -8
- package/src/__tests__/testdata/ascii/subgraph_complex_mixed.txt +0 -38
- package/src/__tests__/testdata/ascii/subgraph_complex_nested.txt +0 -49
- package/src/__tests__/testdata/ascii/subgraph_direction_override.txt +0 -47
- package/src/__tests__/testdata/ascii/subgraph_empty.txt +0 -10
- package/src/__tests__/testdata/ascii/subgraph_mixed_nodes.txt +0 -20
- package/src/__tests__/testdata/ascii/subgraph_mixed_nodes_td.txt +0 -48
- package/src/__tests__/testdata/ascii/subgraph_multiple_edges.txt +0 -32
- package/src/__tests__/testdata/ascii/subgraph_multiple_nodes.txt +0 -16
- package/src/__tests__/testdata/ascii/subgraph_nested.txt +0 -24
- package/src/__tests__/testdata/ascii/subgraph_nested_with_external.txt +0 -30
- package/src/__tests__/testdata/ascii/subgraph_node_outside_lr.txt +0 -17
- package/src/__tests__/testdata/ascii/subgraph_single_node.txt +0 -16
- package/src/__tests__/testdata/ascii/subgraph_td_direction.txt +0 -26
- package/src/__tests__/testdata/ascii/subgraph_td_multiple.txt +0 -44
- package/src/__tests__/testdata/ascii/subgraph_td_multiple_paddingy.txt +0 -42
- package/src/__tests__/testdata/ascii/subgraph_three_levels_nested.txt +0 -32
- package/src/__tests__/testdata/ascii/subgraph_three_separate.txt +0 -24
- package/src/__tests__/testdata/ascii/subgraph_two_separate.txt +0 -20
- package/src/__tests__/testdata/ascii/subgraph_with_labels.txt +0 -20
- package/src/__tests__/testdata/ascii/three_nodes.txt +0 -9
- package/src/__tests__/testdata/ascii/three_nodes_single_line.txt +0 -8
- package/src/__tests__/testdata/ascii/two_layer_single_graph.txt +0 -19
- package/src/__tests__/testdata/ascii/two_layer_single_graph_longer_names.txt +0 -19
- package/src/__tests__/testdata/ascii/two_nodes_linked.txt +0 -8
- package/src/__tests__/testdata/ascii/two_nodes_longer_names.txt +0 -8
- package/src/__tests__/testdata/ascii/two_root_nodes.txt +0 -19
- package/src/__tests__/testdata/ascii/two_root_nodes_longer_names.txt +0 -19
- package/src/__tests__/testdata/ascii/two_single_root_nodes.txt +0 -19
- package/src/__tests__/testdata/unicode/ampersand_lhs.txt +0 -18
- package/src/__tests__/testdata/unicode/ampersand_lhs_and_rhs.txt +0 -18
- package/src/__tests__/testdata/unicode/ampersand_rhs.txt +0 -18
- package/src/__tests__/testdata/unicode/ampersand_without_edge.txt +0 -18
- package/src/__tests__/testdata/unicode/back_reference_from_child.txt +0 -10
- package/src/__tests__/testdata/unicode/backlink_from_bottom.txt +0 -22
- package/src/__tests__/testdata/unicode/backlink_from_top.txt +0 -22
- package/src/__tests__/testdata/unicode/cls_all_relationships.txt +0 -19
- package/src/__tests__/testdata/unicode/cls_annotation.txt +0 -29
- package/src/__tests__/testdata/unicode/cls_association.txt +0 -14
- package/src/__tests__/testdata/unicode/cls_basic.txt +0 -15
- package/src/__tests__/testdata/unicode/cls_dependency.txt +0 -14
- package/src/__tests__/testdata/unicode/cls_inheritance.txt +0 -20
- package/src/__tests__/testdata/unicode/cls_methods.txt +0 -21
- package/src/__tests__/testdata/unicode/comments.txt +0 -23
- package/src/__tests__/testdata/unicode/duplicate_labels.txt +0 -19
- package/src/__tests__/testdata/unicode/er_attributes.txt +0 -21
- package/src/__tests__/testdata/unicode/er_basic.txt +0 -8
- package/src/__tests__/testdata/unicode/er_identifying.txt +0 -18
- package/src/__tests__/testdata/unicode/graph_bt_direction.txt +0 -28
- package/src/__tests__/testdata/unicode/preserve_order_of_definition.txt +0 -23
- package/src/__tests__/testdata/unicode/self_reference.txt +0 -10
- package/src/__tests__/testdata/unicode/self_reference_with_edge.txt +0 -10
- package/src/__tests__/testdata/unicode/seq_basic.txt +0 -17
- package/src/__tests__/testdata/unicode/seq_multiple_messages.txt +0 -25
- package/src/__tests__/testdata/unicode/seq_self_message.txt +0 -18
- package/src/__tests__/testdata/unicode/single_node.txt +0 -8
- package/src/__tests__/testdata/unicode/single_node_longer_name.txt +0 -8
- package/src/__tests__/testdata/unicode/three_nodes.txt +0 -9
- package/src/__tests__/testdata/unicode/three_nodes_single_line.txt +0 -8
- package/src/__tests__/testdata/unicode/two_layer_single_graph.txt +0 -19
- package/src/__tests__/testdata/unicode/two_layer_single_graph_longer_names.txt +0 -19
- package/src/__tests__/testdata/unicode/two_nodes_linked.txt +0 -8
- package/src/__tests__/testdata/unicode/two_nodes_longer_names.txt +0 -8
- package/src/__tests__/testdata/unicode/two_root_nodes.txt +0 -19
- package/src/__tests__/testdata/unicode/two_root_nodes_longer_names.txt +0 -19
- package/src/__tests__/testdata/unicode/two_single_root_nodes.txt +0 -19
- package/src/__tests__/text-metrics.test.ts +0 -473
- package/src/__tests__/theme-palette-contrast.test.ts +0 -84
- package/src/__tests__/theme.test.ts +0 -132
- package/src/__tests__/xychart-ascii.test.ts +0 -376
- package/src/__tests__/xychart-colors.test.ts +0 -149
package/packages/core/LICENSE
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Craft Docs
|
|
4
|
-
Copyright (c) 2026 Dustin Fadler
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
in the Software without restriction, including without limitation the rights
|
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
furnished to do so, subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
SOFTWARE.
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { NodeInteraction } from './types.ts'
|
|
2
|
-
|
|
3
|
-
// ============================================================================
|
|
4
|
-
// Shared `click` directive parsing and href sanitization.
|
|
5
|
-
//
|
|
6
|
-
// Every diagram type that recognizes Mermaid's `click` statement (flowchart/
|
|
7
|
-
// state via src/parser.ts, class diagrams via
|
|
8
|
-
// packages/mermaid-parser/src/class/parser.ts) shares this exact grammar
|
|
9
|
-
// and the same href-safety rules — pulled out here so
|
|
10
|
-
// neither copy can drift from the other. See
|
|
11
|
-
// docs/decisions/no-script-interactivity.md for the tier model this
|
|
12
|
-
// implements: an `href` becomes a real `<a>` link (tier 2), a tooltip
|
|
13
|
-
// becomes a `<title>` (tier 1), and a `call`/`callback` binding is recorded
|
|
14
|
-
// as data but never executed (tier 3 stays unimplemented, permanently).
|
|
15
|
-
// ============================================================================
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Parse a `click <id> ...` statement and record the resulting
|
|
19
|
-
* {@link NodeInteraction} in `interactions`, keyed by whatever id scheme the
|
|
20
|
-
* caller's diagram type uses (flowchart/state node id, class diagram class
|
|
21
|
-
* id, ...).
|
|
22
|
-
*
|
|
23
|
-
* Supported forms:
|
|
24
|
-
* click id "url" ["tooltip"] [_blank|_self|_parent|_top]
|
|
25
|
-
* click id href "url" ["tooltip"] [_blank|_self|_parent|_top]
|
|
26
|
-
* click id call fn() ["tooltip"]
|
|
27
|
-
* click id callback fn() ["tooltip"]
|
|
28
|
-
*
|
|
29
|
-
* A line that doesn't match `click <id> ...` at all is a no-op — callers are
|
|
30
|
-
* expected to have already gated on a leading `click` keyword before calling
|
|
31
|
-
* this (see the `/^click\s+/i` checks at each call site) purely so this
|
|
32
|
-
* function's own regex can stay anchored to the id capture.
|
|
33
|
-
*/
|
|
34
|
-
export function applyClickStatement(
|
|
35
|
-
line: string,
|
|
36
|
-
interactions: Map<string, NodeInteraction>,
|
|
37
|
-
): void {
|
|
38
|
-
const match = line.match(/^click\s+([\w\p{L}-]+)\s+(.*)$/iu)
|
|
39
|
-
if (!match) return
|
|
40
|
-
|
|
41
|
-
const nodeId = match[1]!
|
|
42
|
-
let rest = match[2]!.trim()
|
|
43
|
-
|
|
44
|
-
const interaction: NodeInteraction = { ...interactions.get(nodeId) }
|
|
45
|
-
|
|
46
|
-
// `call fn()` / `callback fn()` — a script binding.
|
|
47
|
-
const callMatch = rest.match(/^(?:call|callback)\s+(.+?)\s*$/i)
|
|
48
|
-
if (callMatch) {
|
|
49
|
-
// A trailing quoted tooltip may follow the callback expression.
|
|
50
|
-
const withTooltip = callMatch[1]!.match(/^(.*?\))\s+"([^"]*)"\s*$/)
|
|
51
|
-
if (withTooltip) {
|
|
52
|
-
interaction.callback = withTooltip[1]!.trim()
|
|
53
|
-
interaction.tooltip = withTooltip[2]
|
|
54
|
-
} else {
|
|
55
|
-
interaction.callback = callMatch[1]!.trim()
|
|
56
|
-
}
|
|
57
|
-
interactions.set(nodeId, interaction)
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Optional explicit `href` keyword.
|
|
62
|
-
rest = rest.replace(/^href\s+/i, '')
|
|
63
|
-
|
|
64
|
-
// Remaining tokens: "url" ["tooltip"] [_target]
|
|
65
|
-
const quoted = [...rest.matchAll(/"([^"]*)"/g)].map((m) => m[1]!)
|
|
66
|
-
if (quoted.length > 0) interaction.href = quoted[0]
|
|
67
|
-
if (quoted.length > 1) interaction.tooltip = quoted[1]
|
|
68
|
-
|
|
69
|
-
const targetMatch = rest.match(/(_blank|_self|_parent|_top)\s*$/i)
|
|
70
|
-
if (targetMatch) interaction.target = targetMatch[1]!.toLowerCase()
|
|
71
|
-
|
|
72
|
-
if (interaction.href !== undefined || interaction.tooltip !== undefined) {
|
|
73
|
-
interactions.set(nodeId, interaction)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Accept only link schemes that cannot execute script.
|
|
79
|
-
*
|
|
80
|
-
* A `click` target comes from diagram text, which may be untrusted. An
|
|
81
|
-
* `href` of `javascript:...` (or a `data:` URL containing markup) would turn
|
|
82
|
-
* a rendered diagram into an XSS vector for any page that inlines the SVG, so
|
|
83
|
-
* anything but http/https/mailto and same-document or relative references is
|
|
84
|
-
* dropped rather than emitted.
|
|
85
|
-
*
|
|
86
|
-
* C0 controls are rejected outright, before any other check. The URL parser
|
|
87
|
-
* strips tab and newline from *anywhere* in a URL, so `java\tscript:` reaches
|
|
88
|
-
* a browser as `javascript:` — while the scheme match below sees `java\t…`,
|
|
89
|
-
* finds no scheme, and waves it through as a relative reference. Splitting a
|
|
90
|
-
* blocked scheme with a control character is the whole bypass; there is no
|
|
91
|
-
* legitimate URL with a raw control in it, so the entire range goes.
|
|
92
|
-
*/
|
|
93
|
-
export function safeHref(href: string | undefined): string | undefined {
|
|
94
|
-
if (!href) return undefined
|
|
95
|
-
|
|
96
|
-
if (/[\x00-\x1F\x7F]/.test(href)) return undefined
|
|
97
|
-
|
|
98
|
-
const trimmed = href.trim()
|
|
99
|
-
// Relative, absolute-path, and fragment references carry no scheme.
|
|
100
|
-
if (/^[./#?]/.test(trimmed)) return trimmed
|
|
101
|
-
|
|
102
|
-
const scheme = trimmed.match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/)?.[1]
|
|
103
|
-
if (scheme === undefined) return trimmed
|
|
104
|
-
|
|
105
|
-
return /^(https?|mailto)$/i.test(scheme) ? trimmed : undefined
|
|
106
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// CSS color primitives — parse, mix, and format sRGB colors.
|
|
3
|
-
//
|
|
4
|
-
// Shared by the SVG theme system (packages/core/src/theme.ts), the ASCII renderer's
|
|
5
|
-
// DiagramColors → AsciiTheme bridge (src/ascii/ansi.ts), and the
|
|
6
|
-
// `resolveColors` post-processor (packages/svg-renderer/src/resolve-colors.ts). All three need
|
|
7
|
-
// the same answer to "what does `color-mix(in srgb, fg 50%, bg)` come out
|
|
8
|
-
// to?", so the arithmetic lives here exactly once — the MIX percentages in
|
|
9
|
-
// packages/core/src/theme.ts stay the single source of truth for *which* percentages the
|
|
10
|
-
// renderer uses, and this module is the single source of truth for what a
|
|
11
|
-
// percentage *means*.
|
|
12
|
-
// ============================================================================
|
|
13
|
-
|
|
14
|
-
/** An sRGB color: 0-255 channels plus a 0-1 alpha. */
|
|
15
|
-
export interface RgbaColor {
|
|
16
|
-
r: number
|
|
17
|
-
g: number
|
|
18
|
-
b: number
|
|
19
|
-
a: number
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Matches #rgb, #rgba, #rrggbb, #rrggbbaa hex color literals. */
|
|
23
|
-
const HEX_COLOR_RE =
|
|
24
|
-
/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Matches `rgb()` / `rgba()` in both the legacy comma syntax
|
|
28
|
-
* (`rgb(1, 2, 3)`, `rgba(1, 2, 3, 0.5)`) and the modern space syntax
|
|
29
|
-
* (`rgb(1 2 3 / 50%)`). Channels may be integers or percentages; alpha may
|
|
30
|
-
* be a 0-1 number or a percentage.
|
|
31
|
-
*/
|
|
32
|
-
const RGB_FUNC_RE =
|
|
33
|
-
/^rgba?\(\s*([\d.]+%?)\s*[, ]\s*([\d.]+%?)\s*[, ]\s*([\d.]+%?)\s*(?:[,/]\s*([\d.]+%?)\s*)?\)$/i
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Parse a hex color string into 0-255 RGB components, ignoring any alpha
|
|
37
|
-
* digits. Returns null for anything that isn't a well-formed hex literal
|
|
38
|
-
* (e.g. `var(--foo)`, named CSS colors, or attribute-injection payloads) —
|
|
39
|
-
* the caller should treat those as unresolvable and fall back.
|
|
40
|
-
*/
|
|
41
|
-
export function parseHexColor(value: string): [number, number, number] | null {
|
|
42
|
-
const rgba = parseHexRgba(value)
|
|
43
|
-
return rgba ? [rgba.r, rgba.g, rgba.b] : null
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Parse a hex color literal (3/4/6/8 digits) into an RgbaColor, or null. */
|
|
47
|
-
export function parseHexRgba(value: string): RgbaColor | null {
|
|
48
|
-
const match = HEX_COLOR_RE.exec(value.trim())
|
|
49
|
-
if (!match) return null
|
|
50
|
-
// HEX_COLOR_RE has exactly one, non-optional capture group, so it's always
|
|
51
|
-
// populated when `match` is non-null — but that's a fact about the regex's
|
|
52
|
-
// construction, not something the type checker can see. Guard explicitly
|
|
53
|
-
// (falling back to "unresolvable", same as a non-match) rather than
|
|
54
|
-
// asserting past it, so a future edit to the pattern can't silently turn
|
|
55
|
-
// this into a runtime `undefined`.
|
|
56
|
-
const captured = match[1]
|
|
57
|
-
if (captured === undefined) return null
|
|
58
|
-
let hex = captured
|
|
59
|
-
if (hex.length === 3 || hex.length === 4) {
|
|
60
|
-
hex = hex
|
|
61
|
-
.split('')
|
|
62
|
-
.map((c) => c + c)
|
|
63
|
-
.join('')
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
r: parseInt(hex.slice(0, 2), 16),
|
|
67
|
-
g: parseInt(hex.slice(2, 4), 16),
|
|
68
|
-
b: parseInt(hex.slice(4, 6), 16),
|
|
69
|
-
a: hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1,
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Parse one rgb()/rgba() channel token: an integer/decimal or a percentage of 255. */
|
|
74
|
-
function parseRgbChannel(token: string): number {
|
|
75
|
-
return token.endsWith('%')
|
|
76
|
-
? (Number(token.slice(0, -1)) / 100) * 255
|
|
77
|
-
: Number(token)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Parse an alpha token: a 0-1 number or a percentage. */
|
|
81
|
-
function parseAlpha(token: string | undefined): number {
|
|
82
|
-
if (token === undefined) return 1
|
|
83
|
-
return token.endsWith('%') ? Number(token.slice(0, -1)) / 100 : Number(token)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Parse a concrete CSS color value into sRGB components.
|
|
88
|
-
*
|
|
89
|
-
* Accepts the forms this library's own theme system produces or documents:
|
|
90
|
-
* hex literals (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`), `rgb()`/`rgba()`,
|
|
91
|
-
* and the `transparent` keyword. Anything else — CSS named colors, `hsl()`,
|
|
92
|
-
* `var(...)`, an unresolved `color-mix(...)` — returns null so the caller
|
|
93
|
-
* can leave it untouched rather than guess.
|
|
94
|
-
*/
|
|
95
|
-
export function parseCssColor(value: string): RgbaColor | null {
|
|
96
|
-
const trimmed = value.trim()
|
|
97
|
-
if (trimmed.toLowerCase() === 'transparent') {
|
|
98
|
-
return { r: 0, g: 0, b: 0, a: 0 }
|
|
99
|
-
}
|
|
100
|
-
const hex = parseHexRgba(trimmed)
|
|
101
|
-
if (hex) return hex
|
|
102
|
-
const rgb = RGB_FUNC_RE.exec(trimmed)
|
|
103
|
-
if (rgb) {
|
|
104
|
-
const [, rTok, gTok, bTok, aTok] = rgb
|
|
105
|
-
if (rTok === undefined || gTok === undefined || bTok === undefined) {
|
|
106
|
-
return null
|
|
107
|
-
}
|
|
108
|
-
const color = {
|
|
109
|
-
r: parseRgbChannel(rTok),
|
|
110
|
-
g: parseRgbChannel(gTok),
|
|
111
|
-
b: parseRgbChannel(bTok),
|
|
112
|
-
a: parseAlpha(aTok),
|
|
113
|
-
}
|
|
114
|
-
if ([color.r, color.g, color.b, color.a].some((n) => Number.isNaN(n))) {
|
|
115
|
-
return null
|
|
116
|
-
}
|
|
117
|
-
return color
|
|
118
|
-
}
|
|
119
|
-
return null
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Evaluate `color-mix(in srgb, c1 p1%, c2 p2%)` per CSS Color Module
|
|
124
|
-
* Level 5 (https://www.w3.org/TR/css-color-5/#color-mix): percentages are
|
|
125
|
-
* normalized so they sum to 100 (a sum under 100 additionally scales the
|
|
126
|
-
* result's alpha by `sum / 100`), and the two colors are interpolated in
|
|
127
|
-
* premultiplied-alpha space, so mixing an opaque color toward
|
|
128
|
-
* `transparent` fades its alpha without darkening it.
|
|
129
|
-
*
|
|
130
|
-
* `p1`/`p2` follow the spec's omission rules: pass `undefined` for an
|
|
131
|
-
* omitted percentage (both omitted → 50/50; one omitted → 100 minus the
|
|
132
|
-
* other). Returns null when both percentages are zero, which the spec
|
|
133
|
-
* defines as invalid.
|
|
134
|
-
*/
|
|
135
|
-
export function mixSrgb(
|
|
136
|
-
c1: RgbaColor,
|
|
137
|
-
c2: RgbaColor,
|
|
138
|
-
p1?: number,
|
|
139
|
-
p2?: number,
|
|
140
|
-
): RgbaColor | null {
|
|
141
|
-
let w1: number
|
|
142
|
-
let w2: number
|
|
143
|
-
if (p1 === undefined && p2 === undefined) {
|
|
144
|
-
w1 = 50
|
|
145
|
-
w2 = 50
|
|
146
|
-
} else if (p1 === undefined) {
|
|
147
|
-
w2 = p2 ?? 50
|
|
148
|
-
w1 = 100 - w2
|
|
149
|
-
} else if (p2 === undefined) {
|
|
150
|
-
w1 = p1
|
|
151
|
-
w2 = 100 - w1
|
|
152
|
-
} else {
|
|
153
|
-
w1 = p1
|
|
154
|
-
w2 = p2
|
|
155
|
-
}
|
|
156
|
-
const sum = w1 + w2
|
|
157
|
-
if (sum === 0) return null
|
|
158
|
-
const alphaMultiplier = sum < 100 ? sum / 100 : 1
|
|
159
|
-
w1 /= sum
|
|
160
|
-
w2 /= sum
|
|
161
|
-
|
|
162
|
-
const alpha = c1.a * w1 + c2.a * w2
|
|
163
|
-
const premul = (ch1: number, ch2: number): number =>
|
|
164
|
-
alpha === 0 ? 0 : (ch1 * c1.a * w1 + ch2 * c2.a * w2) / alpha
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
r: premul(c1.r, c2.r),
|
|
168
|
-
g: premul(c1.g, c2.g),
|
|
169
|
-
b: premul(c1.b, c2.b),
|
|
170
|
-
a: alpha * alphaMultiplier,
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Mix `fg` into `bg` at `pct` percent — the shape every MIX entry in
|
|
176
|
-
* packages/core/src/theme.ts uses (`color-mix(in srgb, var(--fg) N%, var(--bg))`).
|
|
177
|
-
* Returns `fg` unchanged when either input isn't a concrete color this
|
|
178
|
-
* module can parse (a `var(...)` reference, a named color).
|
|
179
|
-
*/
|
|
180
|
-
export function mixHexColors(fg: string, bg: string, pct: number): string {
|
|
181
|
-
const f = parseCssColor(fg)
|
|
182
|
-
const b = parseCssColor(bg)
|
|
183
|
-
if (!f || !b) return fg
|
|
184
|
-
const mixed = mixSrgb(f, b, pct, 100 - pct)
|
|
185
|
-
return mixed ? formatCssColor(mixed) : fg
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const clampByte = (n: number): number =>
|
|
189
|
-
Math.min(255, Math.max(0, Math.round(n)))
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Serialize a color as `#rrggbb` when fully opaque, otherwise as
|
|
193
|
-
* `rgba(r, g, b, a)` — the two forms every SVG consumer (browsers, resvg,
|
|
194
|
-
* librsvg, Inkscape) agrees on.
|
|
195
|
-
*/
|
|
196
|
-
export function formatCssColor(c: RgbaColor): string {
|
|
197
|
-
const r = clampByte(c.r)
|
|
198
|
-
const g = clampByte(c.g)
|
|
199
|
-
const b = clampByte(c.b)
|
|
200
|
-
const a = Math.min(1, Math.max(0, c.a))
|
|
201
|
-
if (a >= 1) {
|
|
202
|
-
return '#' + [r, g, b].map((n) => n.toString(16).padStart(2, '0')).join('')
|
|
203
|
-
}
|
|
204
|
-
return `rgba(${r}, ${g}, ${b}, ${Number(a.toFixed(3))})`
|
|
205
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// zombie-mermaid — shared diagram-type detection
|
|
3
|
-
//
|
|
4
|
-
// Both the SVG renderer (src/index.ts) and the ASCII renderer
|
|
5
|
-
// (src/ascii/index.ts) need to classify Mermaid source text before
|
|
6
|
-
// dispatching to the right parse/layout/render pipeline. This module is the
|
|
7
|
-
// single source of truth for that classification so the two backends can
|
|
8
|
-
// never drift out of sync with each other again.
|
|
9
|
-
// ============================================================================
|
|
10
|
-
|
|
11
|
-
import { splitStatements } from './statements.ts'
|
|
12
|
-
|
|
13
|
-
/** The diagram types this library can detect and route to a renderer. */
|
|
14
|
-
export type DiagramType = 'flowchart' | 'sequence' | 'class' | 'er' | 'xychart'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Detect the diagram type from the mermaid source text.
|
|
18
|
-
* Returns the type keyword used for routing to the correct pipeline.
|
|
19
|
-
*
|
|
20
|
-
* The header keyword is the first *statement*, not the first line: Mermaid
|
|
21
|
-
* allows `;` as a statement separator, so `flowchart TD;A-->B` has its header
|
|
22
|
-
* and first edge on one line. Uses the same splitter every parser uses, so
|
|
23
|
-
* routing and parsing can never disagree about where the header ends.
|
|
24
|
-
*/
|
|
25
|
-
export function detectDiagramType(text: string): DiagramType {
|
|
26
|
-
const firstLine = splitStatements(text)[0]?.text.toLowerCase() ?? ''
|
|
27
|
-
|
|
28
|
-
if (/^xychart(?:-beta)?(?:\s|$)/.test(firstLine)) return 'xychart'
|
|
29
|
-
if (/^sequencediagram\s*$/.test(firstLine)) return 'sequence'
|
|
30
|
-
if (/^classdiagram\s*$/.test(firstLine)) return 'class'
|
|
31
|
-
if (/^erdiagram\s*$/.test(firstLine)) return 'er'
|
|
32
|
-
|
|
33
|
-
// Default: flowchart/state (handled by parseMermaid internally)
|
|
34
|
-
return 'flowchart'
|
|
35
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// Render-time direction override (issue #276)
|
|
3
|
-
//
|
|
4
|
-
// `RenderOptions.direction` / `AsciiRenderOptions.direction` replace the
|
|
5
|
-
// *top-level* direction a diagram declared in its source (a flowchart's
|
|
6
|
-
// `graph LR` header, a state diagram's or ER diagram's `direction LR`
|
|
7
|
-
// line) after parsing and before layout. Nothing here touches the source
|
|
8
|
-
// text, and nothing here touches a nested subgraph's or composite state's
|
|
9
|
-
// own `direction` — those live on the subgraph objects, not on the field
|
|
10
|
-
// replaced below, so they keep winning locally over the top-level
|
|
11
|
-
// direction exactly as they do relative to the diagram's own header.
|
|
12
|
-
//
|
|
13
|
-
// Shared by the SVG entry (src/index.ts) and the ASCII entry
|
|
14
|
-
// (src/ascii/index.ts). Deliberately dependency-free beyond the
|
|
15
|
-
// `isDirection` guard so the `zombie-mermaid/ascii` subpath stays free of
|
|
16
|
-
// elkjs — the guard itself moved out of `src/parser.ts` and into this
|
|
17
|
-
// package (see `direction.ts`) so that staying dependency-free survives
|
|
18
|
-
// the workspace split (zombie-mermaid#625).
|
|
19
|
-
// ============================================================================
|
|
20
|
-
|
|
21
|
-
import type { Direction } from './types.ts'
|
|
22
|
-
import { isDirection } from './direction.ts'
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Return `diagram` with its top-level `direction` replaced by `override`,
|
|
26
|
-
* or `diagram` itself (same reference) when there is nothing to apply.
|
|
27
|
-
*
|
|
28
|
-
* The parsed diagram is never mutated — a shallow clone carries the new
|
|
29
|
-
* direction, so `parseMermaid()` output a caller holds on to stays exactly
|
|
30
|
-
* what the parser produced, and a second render of the same parsed object
|
|
31
|
-
* without the option sees the source direction again.
|
|
32
|
-
*
|
|
33
|
-
* `isDirection` re-checks the value at runtime because `Direction` is only
|
|
34
|
-
* a compile-time guarantee: a plain-JavaScript caller can pass any string.
|
|
35
|
-
* An unrecognized value is ignored (the diagram's own direction stands)
|
|
36
|
-
* rather than thrown on — the same lenient treatment every other
|
|
37
|
-
* `RenderOptions` value gets, e.g. an unknown `interactivity` or `curve`
|
|
38
|
-
* string falls back to its default instead of failing the render.
|
|
39
|
-
*/
|
|
40
|
-
export function withDirectionOverride<T extends { direction?: Direction }>(
|
|
41
|
-
diagram: T,
|
|
42
|
-
override: Direction | undefined,
|
|
43
|
-
): T {
|
|
44
|
-
if (override === undefined || !isDirection(override)) return diagram
|
|
45
|
-
return { ...diagram, direction: override }
|
|
46
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// Direction token guard
|
|
3
|
-
//
|
|
4
|
-
// Lives in `core` rather than beside the flowchart parser that used to own
|
|
5
|
-
// it (`src/parser.ts`) because `direction-override.ts` — also `core`, and
|
|
6
|
-
// reached from the ASCII entry — needs it. Left in the parser, `core` would
|
|
7
|
-
// import `mermaid-parser`, i.e. the shared package would depend on one of
|
|
8
|
-
// its own consumers (zombie-mermaid#625, umbrella #620).
|
|
9
|
-
//
|
|
10
|
-
// `toDirection` joined `isDirection` here under #624 for the identical
|
|
11
|
-
// reason: it used to live in `src/parser.ts` too, with that file as its
|
|
12
|
-
// only caller, until splitting `er/parser.ts` out into
|
|
13
|
-
// `packages/mermaid-parser/` gave it a second caller that cannot import the
|
|
14
|
-
// umbrella's `src/parser.ts` without creating the same cycle `isDirection`
|
|
15
|
-
// was moved to avoid. `src/parser.ts` now imports it from here instead of
|
|
16
|
-
// defining it.
|
|
17
|
-
//
|
|
18
|
-
// `Direction` is only a compile-time guarantee, so every entry point that
|
|
19
|
-
// accepts a direction from outside (`RenderOptions.direction`, the CLI's
|
|
20
|
-
// `--direction` flag, a parsed `graph LR` header) re-checks it at runtime
|
|
21
|
-
// through this guard.
|
|
22
|
-
// ============================================================================
|
|
23
|
-
|
|
24
|
-
import type { Direction } from './types.ts'
|
|
25
|
-
|
|
26
|
-
/** True when `value` is one of the five directions Mermaid recognizes. */
|
|
27
|
-
export function isDirection(value: string): value is Direction {
|
|
28
|
-
return (
|
|
29
|
-
value === 'TD' ||
|
|
30
|
-
value === 'TB' ||
|
|
31
|
-
value === 'LR' ||
|
|
32
|
-
value === 'BT' ||
|
|
33
|
-
value === 'RL'
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Normalize a regex-captured direction token to a `Direction`.
|
|
39
|
-
*
|
|
40
|
-
* Accepts `string | undefined` because every call site passes a regex
|
|
41
|
-
* capture group value (`match[1]`, typed as possibly-`undefined` under
|
|
42
|
-
* `noUncheckedIndexedAccess`) straight through. Each call site's regex
|
|
43
|
-
* guards the capture with the same `(TD|TB|LR|BT|RL)` alternation
|
|
44
|
-
* (case-insensitively), so the group always participates in the match in
|
|
45
|
-
* practice — but that's a regex-structure guarantee the type checker can't
|
|
46
|
-
* see across the call site. Validating `undefined` here, instead of
|
|
47
|
-
* asserting non-null at each call site, turns a hypothetical violation into
|
|
48
|
-
* a clear, descriptive error rather than a raw `undefined` crash.
|
|
49
|
-
*/
|
|
50
|
-
export function toDirection(raw: string | undefined): Direction {
|
|
51
|
-
const upper = raw?.toUpperCase()
|
|
52
|
-
if (upper === undefined || !isDirection(upper)) {
|
|
53
|
-
throw new Error(`Invalid direction: "${raw}"`)
|
|
54
|
-
}
|
|
55
|
-
return upper
|
|
56
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// @zombie-mermaid/core — the module set both renderers import
|
|
3
|
-
//
|
|
4
|
-
// Every file re-exported below was grep-verified (zombie-mermaid#625,
|
|
5
|
-
// umbrella #620) as reachable from BOTH front doors — `src/index.ts` (SVG)
|
|
6
|
-
// and `src/ascii/index.ts` (ASCII) — either directly or through
|
|
7
|
-
// `src/parser.ts`, which both call. Nothing here imports anything outside
|
|
8
|
-
// this package, so `core` is a sink in the workspace graph: the ASCII
|
|
9
|
-
// renderer can depend on it without dragging in `elkjs` or any SVG
|
|
10
|
-
// emission code.
|
|
11
|
-
//
|
|
12
|
-
// The one external reference is a type-only `import type { ElkNode }` in
|
|
13
|
-
// `types.ts` (for `RenderOptions.layoutCache`), erased before bundling.
|
|
14
|
-
//
|
|
15
|
-
// A barrel rather than per-file subpath exports: `#620`'s recommendation 4
|
|
16
|
-
// has the umbrella's three entries eventually become thin re-exports of
|
|
17
|
-
// real packages, which needs a real package API. `sideEffects: false` plus
|
|
18
|
-
// this package's total absence of module-level side effects is what keeps
|
|
19
|
-
// the barrel from widening any bundle — verified against the pre-split
|
|
20
|
-
// `dist/` byte-for-byte.
|
|
21
|
-
// ============================================================================
|
|
22
|
-
|
|
23
|
-
export * from './click-directive.ts'
|
|
24
|
-
export * from './color-utils.ts'
|
|
25
|
-
export * from './diagram-type.ts'
|
|
26
|
-
export * from './direction.ts'
|
|
27
|
-
export * from './direction-override.ts'
|
|
28
|
-
export * from './init-directive.ts'
|
|
29
|
-
export * from './multiline-utils.ts'
|
|
30
|
-
export * from './statements.ts'
|
|
31
|
-
export * from './style-directives.ts'
|
|
32
|
-
export * from './text-metrics.ts'
|
|
33
|
-
export * from './theme.ts'
|
|
34
|
-
export * from './types.ts'
|