merman-render 0.5.0

Headless layout + SVG renderer for Mermaid (parity-focused; upstream SVG goldens).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
use crate::model::{
    ArchitectureDiagramLayout, BlockDiagramLayout, Bounds, ClassDiagramV2Layout, ErDiagramLayout,
    ErrorDiagramLayout, FlowchartV2Layout, InfoDiagramLayout, LayoutCluster, LayoutNode,
    MindmapDiagramLayout, PacketDiagramLayout, PieDiagramLayout, QuadrantChartDiagramLayout,
    RadarDiagramLayout, RequirementDiagramLayout, SankeyDiagramLayout, SequenceDiagramLayout,
    StateDiagramV2Layout, TimelineDiagramLayout, XyChartDiagramLayout,
};
use crate::text::{TextMeasurer, TextStyle, WrapMode};
use crate::{Error, Result};
use base64::Engine as _;
use indexmap::IndexMap;
use std::fmt::Write as _;

mod architecture;
mod block;
mod c4;
mod class;
mod css;
mod curve;
mod er;
mod error;
mod fallback;
mod flowchart;
mod gantt;
mod gitgraph;
mod info;
mod journey;
mod kanban;
mod layout_debug;
mod mindmap;
mod packet;
mod path_bounds;
mod pie;
mod quadrantchart;
mod radar;
mod requirement;
mod root_svg;
mod roughjs46;
mod roughjs_common;
mod sankey;
mod sequence;
mod state;
mod style;
mod timeline;
mod timing;
mod treemap;
mod util;
mod xychart;
use crate::math::MathRenderer;
use css::{
    er_css, gantt_css, info_css_parts_with_config, info_css_parts_with_theme_font_size_only,
    info_css_with_config, pie_css, push_xychart_css, requirement_css, sankey_css, treemap_css,
};
pub use fallback::foreign_object_label_fallback_svg_text;
use path_bounds::svg_path_bounds_from_d;
pub(crate) fn mindmap_cloud_rendered_bbox_size_px(w: f64, h: f64) -> Option<(f64, f64)> {
    mindmap::mindmap_cloud_rendered_bbox_size_px(w, h)
}
pub use state::{SvgEmittedBoundsContributor, SvgEmittedBoundsDebug, debug_svg_emitted_bounds};
use state::{
    roughjs_ops_to_svg_path_d, roughjs_parse_hex_color_to_srgba, roughjs_paths_for_rect,
    svg_emitted_bounds_from_svg, svg_emitted_bounds_from_svg_inner,
};
use style::{is_rect_style_key, is_text_style_key, parse_style_decl};
use util::{
    apply_root_viewport_override, config_bool, config_f64, config_f64_css_px, config_string,
    decode_mermaid_entities_for_render_text, escape_attr, escape_attr_display, escape_xml,
    escape_xml_display, escape_xml_into, fmt, fmt_debug_3dp, fmt_display, fmt_into,
    fmt_max_width_px, fmt_path, fmt_path_into, fmt_string, json_f64, json_stringify_points,
    json_stringify_points_into, normalize_css_font_family, theme_color,
};

const MERMAID_SEQUENCE_BASE_DEFS_11_12_2: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/assets/sequence_base_defs_11_12_2.svgfrag"
));

#[derive(Debug, Clone)]
pub struct SvgRenderOptions {
    /// Adds extra space around the computed viewBox.
    pub viewbox_padding: f64,
    /// Optional diagram id used for Mermaid-like marker ids.
    pub diagram_id: Option<String>,
    /// Optional override for the root SVG `aria-roledescription` attribute.
    ///
    /// This is primarily used to reproduce Mermaid's per-header accessibility metadata quirks
    /// (e.g. `classDiagram-v2` differs from `classDiagram` at Mermaid 11.12.2).
    pub aria_roledescription: Option<String>,
    /// When true, include edge polylines.
    pub include_edges: bool,
    /// When true, include node bounding boxes and ids.
    pub include_nodes: bool,
    /// When true, include cluster bounding boxes and titles.
    pub include_clusters: bool,
    /// When true, draw markers that visualize Mermaid cluster positioning metadata.
    pub include_cluster_debug_markers: bool,
    /// When true, label edge routes with edge ids.
    pub include_edge_id_labels: bool,
    /// Optional override for "current time" used by diagrams that render time-dependent markers
    /// (e.g. Gantt `today` line). This exists to make parity/golden comparisons reproducible.
    pub now_ms_override: Option<i64>,
    /// Optional math renderer for `$$...$$` style labels.
    pub math_renderer: Option<std::sync::Arc<dyn MathRenderer + Send + Sync>>,
    /// When false, renderers that support root viewport override lookup emit computed bounds.
    pub apply_root_overrides: bool,
}

impl Default for SvgRenderOptions {
    fn default() -> Self {
        Self {
            viewbox_padding: 8.0,
            diagram_id: None,
            aria_roledescription: None,
            include_edges: true,
            include_nodes: true,
            include_clusters: true,
            include_cluster_debug_markers: false,
            include_edge_id_labels: false,
            now_ms_override: None,
            math_renderer: None,
            apply_root_overrides: true,
        }
    }
}

pub fn render_layouted_svg(
    diagram: &crate::model::LayoutedDiagram,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    render_layout_svg_parts(
        &diagram.layout,
        &diagram.semantic,
        &diagram.meta.effective_config,
        diagram.meta.title.as_deref(),
        measurer,
        options,
    )
}

pub fn render_layout_svg_parts(
    layout: &crate::model::LayoutDiagram,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    use crate::model::LayoutDiagram;

    match layout {
        LayoutDiagram::ErrorDiagram(layout) => {
            render_error_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::BlockDiagram(layout) => {
            render_block_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::RequirementDiagram(layout) => {
            render_requirement_diagram_svg(layout, semantic, effective_config, title, options)
        }
        LayoutDiagram::ArchitectureDiagram(layout) => {
            render_architecture_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::MindmapDiagram(layout) => {
            render_mindmap_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::SankeyDiagram(layout) => {
            render_sankey_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::RadarDiagram(layout) => {
            render_radar_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::TreemapDiagram(layout) => {
            render_treemap_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::XyChartDiagram(layout) => {
            render_xychart_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::QuadrantChartDiagram(layout) => {
            render_quadrantchart_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::FlowchartV2(layout) => {
            render_flowchart_v2_svg(layout, semantic, effective_config, title, measurer, options)
        }
        LayoutDiagram::StateDiagramV2(layout) => render_state_diagram_v2_svg(
            layout,
            semantic,
            effective_config,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::ClassDiagramV2(layout) => render_class_diagram_v2_svg(
            layout,
            semantic,
            effective_config,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::ErDiagram(layout) => {
            render_er_diagram_svg(layout, semantic, effective_config, title, measurer, options)
        }
        LayoutDiagram::SequenceDiagram(layout) => render_sequence_diagram_svg(
            layout,
            semantic,
            effective_config,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::InfoDiagram(layout) => {
            render_info_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::PacketDiagram(layout) => {
            render_packet_diagram_svg(layout, semantic, effective_config, title, options)
        }
        LayoutDiagram::TimelineDiagram(layout) => render_timeline_diagram_svg(
            layout,
            semantic,
            effective_config,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::PieDiagram(layout) => {
            render_pie_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::JourneyDiagram(layout) => {
            render_journey_diagram_svg(layout, semantic, effective_config, title, measurer, options)
        }
        LayoutDiagram::KanbanDiagram(layout) => {
            render_kanban_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::GitGraphDiagram(layout) => render_gitgraph_diagram_svg(
            layout,
            semantic,
            effective_config,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::GanttDiagram(layout) => {
            render_gantt_diagram_svg(layout, semantic, effective_config, options)
        }
        LayoutDiagram::C4Diagram(layout) => {
            render_c4_diagram_svg(layout, semantic, effective_config, title, measurer, options)
        }
    }
}

pub fn render_layout_svg_parts_with_config(
    layout: &crate::model::LayoutDiagram,
    semantic: &serde_json::Value,
    effective_config: &merman_core::MermaidConfig,
    title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    use crate::model::LayoutDiagram;

    let effective_config_value = effective_config.as_value();

    match layout {
        LayoutDiagram::ErrorDiagram(layout) => {
            render_error_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::BlockDiagram(layout) => {
            render_block_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::RequirementDiagram(layout) => {
            render_requirement_diagram_svg(layout, semantic, effective_config_value, title, options)
        }
        LayoutDiagram::ArchitectureDiagram(layout) => {
            architecture::render_architecture_diagram_svg_with_config(
                layout,
                semantic,
                effective_config,
                options,
            )
        }
        LayoutDiagram::MindmapDiagram(layout) => {
            render_mindmap_diagram_svg_with_config(layout, semantic, effective_config, options)
        }
        LayoutDiagram::SankeyDiagram(layout) => {
            render_sankey_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::RadarDiagram(layout) => {
            render_radar_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::TreemapDiagram(layout) => {
            render_treemap_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::XyChartDiagram(layout) => {
            render_xychart_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::QuadrantChartDiagram(layout) => {
            render_quadrantchart_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::FlowchartV2(layout) => render_flowchart_v2_svg_with_config(
            layout,
            semantic,
            effective_config,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::StateDiagramV2(layout) => render_state_diagram_v2_svg(
            layout,
            semantic,
            effective_config_value,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::ClassDiagramV2(layout) => {
            let model = crate::json::from_value_ref(semantic)?;
            class::render_class_diagram_v2_svg_model_with_config(
                layout,
                &model,
                effective_config,
                title,
                measurer,
                options,
            )
        }
        LayoutDiagram::ErDiagram(layout) => render_er_diagram_svg(
            layout,
            semantic,
            effective_config_value,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::SequenceDiagram(layout) => {
            sequence::render_sequence_diagram_svg_with_config(
                layout,
                semantic,
                effective_config,
                title,
                measurer,
                options,
            )
        }
        LayoutDiagram::InfoDiagram(layout) => {
            render_info_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::PacketDiagram(layout) => {
            render_packet_diagram_svg(layout, semantic, effective_config_value, title, options)
        }
        LayoutDiagram::TimelineDiagram(layout) => render_timeline_diagram_svg(
            layout,
            semantic,
            effective_config_value,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::PieDiagram(layout) => {
            render_pie_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::JourneyDiagram(layout) => render_journey_diagram_svg(
            layout,
            semantic,
            effective_config_value,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::KanbanDiagram(layout) => {
            render_kanban_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::GitGraphDiagram(layout) => render_gitgraph_diagram_svg(
            layout,
            semantic,
            effective_config_value,
            title,
            measurer,
            options,
        ),
        LayoutDiagram::GanttDiagram(layout) => {
            render_gantt_diagram_svg(layout, semantic, effective_config_value, options)
        }
        LayoutDiagram::C4Diagram(layout) => render_c4_diagram_svg(
            layout,
            semantic,
            effective_config_value,
            title,
            measurer,
            options,
        ),
    }
}

pub fn render_layout_svg_parts_for_render_model_with_config(
    layout: &crate::model::LayoutDiagram,
    semantic: &merman_core::RenderSemanticModel,
    effective_config: &merman_core::MermaidConfig,
    title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    use crate::model::LayoutDiagram;
    use merman_core::RenderSemanticModel;

    match (layout, semantic) {
        (LayoutDiagram::ArchitectureDiagram(layout), RenderSemanticModel::Architecture(model)) => {
            architecture::render_architecture_diagram_svg_typed_with_config(
                layout,
                model,
                effective_config,
                options,
            )
        }
        (LayoutDiagram::FlowchartV2(layout), RenderSemanticModel::Flowchart(model)) => {
            render_flowchart_v2_svg_model_with_config(
                layout,
                model,
                effective_config,
                title,
                measurer,
                options,
            )
        }
        (LayoutDiagram::MindmapDiagram(layout), RenderSemanticModel::Mindmap(model)) => {
            mindmap::render_mindmap_diagram_svg_model_with_config(
                layout,
                model,
                effective_config,
                options,
            )
        }
        (LayoutDiagram::StateDiagramV2(layout), RenderSemanticModel::State(model)) => {
            state::render_state_diagram_v2_svg_model(
                layout,
                model,
                effective_config.as_value(),
                title,
                measurer,
                options,
            )
        }
        (LayoutDiagram::ClassDiagramV2(layout), RenderSemanticModel::Class(model)) => {
            class::render_class_diagram_v2_svg_model_with_config(
                layout,
                model,
                effective_config,
                title,
                measurer,
                options,
            )
        }
        (LayoutDiagram::SequenceDiagram(layout), RenderSemanticModel::Sequence(model)) => {
            sequence::render_sequence_diagram_svg_model_with_config(
                layout,
                model,
                effective_config,
                title,
                measurer,
                options,
            )
        }
        (LayoutDiagram::KanbanDiagram(layout), RenderSemanticModel::Kanban(_)) => {
            render_kanban_diagram_svg(
                layout,
                &serde_json::Value::Null,
                effective_config.as_value(),
                options,
            )
        }
        (LayoutDiagram::GanttDiagram(layout), RenderSemanticModel::Gantt(model)) => {
            gantt::render_gantt_diagram_svg_model(
                layout,
                model,
                effective_config.as_value(),
                options,
            )
        }
        (LayoutDiagram::PieDiagram(layout), RenderSemanticModel::Pie(model)) => {
            pie::render_pie_diagram_svg_model(layout, model, effective_config.as_value(), options)
        }
        (LayoutDiagram::PacketDiagram(layout), RenderSemanticModel::Packet(model)) => {
            packet::render_packet_diagram_svg_model(
                layout,
                model,
                effective_config.as_value(),
                title,
                options,
            )
        }
        (LayoutDiagram::TimelineDiagram(layout), RenderSemanticModel::Timeline(model)) => {
            timeline::render_timeline_diagram_svg_model(
                layout,
                model,
                effective_config.as_value(),
                title,
                measurer,
                options,
            )
        }
        (LayoutDiagram::JourneyDiagram(layout), RenderSemanticModel::Journey(model)) => {
            journey::render_journey_diagram_svg_model(
                layout,
                model,
                effective_config.as_value(),
                title,
                measurer,
                options,
            )
        }
        (LayoutDiagram::RequirementDiagram(layout), RenderSemanticModel::Requirement(model)) => {
            requirement::render_requirement_diagram_svg_model(
                layout,
                model,
                effective_config.as_value(),
                title,
                options,
            )
        }
        (LayoutDiagram::SankeyDiagram(layout), RenderSemanticModel::Sankey(_)) => {
            render_sankey_diagram_svg(
                layout,
                &serde_json::Value::Null,
                effective_config.as_value(),
                options,
            )
        }
        (LayoutDiagram::RadarDiagram(layout), RenderSemanticModel::Radar(model)) => {
            radar::render_radar_diagram_svg_model(
                layout,
                model,
                effective_config.as_value(),
                options,
            )
        }
        (LayoutDiagram::InfoDiagram(layout), RenderSemanticModel::Info(_)) => {
            render_info_diagram_svg(
                layout,
                &serde_json::Value::Null,
                effective_config.as_value(),
                options,
            )
        }
        (LayoutDiagram::TreemapDiagram(layout), RenderSemanticModel::Treemap(_)) => {
            render_treemap_diagram_svg(
                layout,
                &serde_json::Value::Null,
                effective_config.as_value(),
                options,
            )
        }
        (LayoutDiagram::BlockDiagram(layout), RenderSemanticModel::Block(model)) => {
            render_block_diagram_svg_model(layout, model, effective_config.as_value(), options)
        }
        (LayoutDiagram::ErDiagram(layout), RenderSemanticModel::Er(model)) => {
            render_er_diagram_svg_model(
                layout,
                model,
                effective_config.as_value(),
                title,
                measurer,
                options,
            )
        }
        (LayoutDiagram::QuadrantChartDiagram(layout), RenderSemanticModel::QuadrantChart(_)) => {
            render_quadrantchart_diagram_svg(
                layout,
                &serde_json::Value::Null,
                effective_config.as_value(),
                options,
            )
        }
        (LayoutDiagram::XyChartDiagram(layout), RenderSemanticModel::XyChart(_)) => {
            render_xychart_diagram_svg(
                layout,
                &serde_json::Value::Null,
                effective_config.as_value(),
                options,
            )
        }
        (LayoutDiagram::GitGraphDiagram(layout), RenderSemanticModel::GitGraph(model)) => {
            gitgraph::render_gitgraph_diagram_svg_model(
                layout,
                model,
                effective_config.as_value(),
                title,
                measurer,
                options,
            )
        }
        (LayoutDiagram::C4Diagram(layout), RenderSemanticModel::C4(model)) => {
            c4::render_c4_diagram_svg_typed(
                layout,
                model,
                effective_config.as_value(),
                title,
                measurer,
                options,
            )
        }
        (_, RenderSemanticModel::Json(semantic)) => render_layout_svg_parts_with_config(
            layout,
            semantic,
            effective_config,
            title,
            measurer,
            options,
        ),
        _ => Err(Error::InvalidModel {
            message: "semantic model does not match layout diagram type".to_string(),
        }),
    }
}

pub fn render_flowchart_v2_debug_svg(
    layout: &FlowchartV2Layout,
    options: &SvgRenderOptions,
) -> String {
    flowchart::render_flowchart_v2_debug_svg(layout, options)
}

pub fn render_sequence_diagram_debug_svg(
    layout: &SequenceDiagramLayout,
    options: &SvgRenderOptions,
) -> String {
    sequence::render_sequence_diagram_debug_svg(layout, options)
}

pub fn render_sequence_diagram_svg(
    layout: &SequenceDiagramLayout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    diagram_title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    sequence::render_sequence_diagram_svg(
        layout,
        semantic,
        effective_config,
        diagram_title,
        measurer,
        options,
    )
}

pub fn render_error_diagram_svg(
    layout: &ErrorDiagramLayout,
    _semantic: &serde_json::Value,
    _effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    error::render_error_diagram_svg(layout, _semantic, _effective_config, options)
}

pub fn render_info_diagram_svg(
    layout: &InfoDiagramLayout,
    _semantic: &serde_json::Value,
    _effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    info::render_info_diagram_svg(layout, _semantic, _effective_config, options)
}

pub fn render_pie_diagram_svg(
    layout: &PieDiagramLayout,
    semantic: &serde_json::Value,
    _effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    pie::render_pie_diagram_svg(layout, semantic, _effective_config, options)
}

pub fn render_requirement_diagram_svg(
    layout: &RequirementDiagramLayout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    diagram_title: Option<&str>,
    options: &SvgRenderOptions,
) -> Result<String> {
    requirement::render_requirement_diagram_svg(
        layout,
        semantic,
        effective_config,
        diagram_title,
        options,
    )
}

pub fn render_block_diagram_svg(
    layout: &BlockDiagramLayout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    block::render_block_diagram_svg(layout, semantic, effective_config, options)
}

pub fn render_block_diagram_svg_model(
    layout: &BlockDiagramLayout,
    model: &merman_core::diagrams::block::BlockDiagramRenderModel,
    effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    block::render_block_diagram_svg_model(layout, model, effective_config, options)
}

pub fn render_er_diagram_svg_model(
    layout: &ErDiagramLayout,
    model: &merman_core::diagrams::er::ErDiagramRenderModel,
    effective_config: &serde_json::Value,
    diagram_title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    er::render_er_diagram_svg_model(
        layout,
        model,
        effective_config,
        diagram_title,
        measurer,
        options,
    )
}

pub fn render_radar_diagram_svg(
    layout: &RadarDiagramLayout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    radar::render_radar_diagram_svg(layout, semantic, effective_config, options)
}

pub fn render_quadrantchart_diagram_svg(
    layout: &QuadrantChartDiagramLayout,
    _semantic: &serde_json::Value,
    _effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    quadrantchart::render_quadrantchart_diagram_svg(layout, _semantic, _effective_config, options)
}

pub fn render_xychart_diagram_svg(
    layout: &XyChartDiagramLayout,
    _semantic: &serde_json::Value,
    _effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    xychart::render_xychart_diagram_svg(layout, _semantic, _effective_config, options)
}

pub fn render_treemap_diagram_svg(
    layout: &crate::model::TreemapDiagramLayout,
    _semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    treemap::render_treemap_diagram_svg(layout, _semantic, effective_config, options)
}

pub fn render_packet_diagram_svg(
    layout: &PacketDiagramLayout,
    semantic: &serde_json::Value,
    _effective_config: &serde_json::Value,
    diagram_title: Option<&str>,
    options: &SvgRenderOptions,
) -> Result<String> {
    packet::render_packet_diagram_svg(layout, semantic, _effective_config, diagram_title, options)
}

pub fn render_timeline_diagram_svg(
    layout: &TimelineDiagramLayout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    _diagram_title: Option<&str>,
    _measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    timeline::render_timeline_diagram_svg(
        layout,
        semantic,
        effective_config,
        _diagram_title,
        _measurer,
        options,
    )
}

pub fn render_journey_diagram_svg(
    layout: &crate::model::JourneyDiagramLayout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    _diagram_title: Option<&str>,
    _measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    journey::render_journey_diagram_svg(
        layout,
        semantic,
        effective_config,
        _diagram_title,
        _measurer,
        options,
    )
}

pub fn render_kanban_diagram_svg(
    layout: &crate::model::KanbanDiagramLayout,
    _semantic: &serde_json::Value,
    _effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    kanban::render_kanban_diagram_svg(layout, _semantic, _effective_config, options)
}

pub fn render_gitgraph_diagram_svg(
    layout: &crate::model::GitGraphDiagramLayout,
    semantic: &serde_json::Value,
    _effective_config: &serde_json::Value,
    diagram_title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    gitgraph::render_gitgraph_diagram_svg(
        layout,
        semantic,
        _effective_config,
        diagram_title,
        measurer,
        options,
    )
}

pub fn render_gantt_diagram_svg(
    layout: &crate::model::GanttDiagramLayout,
    semantic: &serde_json::Value,
    _effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    gantt::render_gantt_diagram_svg(layout, semantic, _effective_config, options)
}

pub fn render_mindmap_diagram_svg(
    layout: &MindmapDiagramLayout,
    semantic: &serde_json::Value,
    _effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    mindmap::render_mindmap_diagram_svg(layout, semantic, _effective_config, options)
}

pub fn render_mindmap_diagram_svg_with_config(
    layout: &MindmapDiagramLayout,
    semantic: &serde_json::Value,
    effective_config: &merman_core::MermaidConfig,
    options: &SvgRenderOptions,
) -> Result<String> {
    mindmap::render_mindmap_diagram_svg_with_config(layout, semantic, effective_config, options)
}

pub fn render_architecture_diagram_svg(
    layout: &ArchitectureDiagramLayout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    architecture::render_architecture_diagram_svg(layout, semantic, effective_config, options)
}

pub fn render_c4_diagram_svg(
    layout: &crate::model::C4DiagramLayout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    diagram_title: Option<&str>,
    _measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    c4::render_c4_diagram_svg(
        layout,
        semantic,
        effective_config,
        diagram_title,
        _measurer,
        options,
    )
}

pub fn render_flowchart_v2_svg(
    layout: &FlowchartV2Layout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    diagram_title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    flowchart::render_flowchart_v2_svg(
        layout,
        semantic,
        effective_config,
        diagram_title,
        measurer,
        options,
    )
}

pub fn render_flowchart_v2_svg_with_config(
    layout: &FlowchartV2Layout,
    semantic: &serde_json::Value,
    effective_config: &merman_core::MermaidConfig,
    diagram_title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    flowchart::render_flowchart_v2_svg_with_config(
        layout,
        semantic,
        effective_config,
        diagram_title,
        measurer,
        options,
    )
}

pub fn render_flowchart_v2_svg_model_with_config(
    layout: &FlowchartV2Layout,
    model: &merman_core::diagrams::flowchart::FlowchartV2Model,
    effective_config: &merman_core::MermaidConfig,
    diagram_title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    flowchart::render_flowchart_v2_svg_model_with_config(
        layout,
        model,
        effective_config,
        diagram_title,
        measurer,
        options,
    )
}

pub fn render_state_diagram_v2_svg(
    layout: &StateDiagramV2Layout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    diagram_title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    state::render_state_diagram_v2_svg(
        layout,
        semantic,
        effective_config,
        diagram_title,
        measurer,
        options,
    )
}

pub fn render_state_diagram_v2_debug_svg(
    layout: &StateDiagramV2Layout,
    options: &SvgRenderOptions,
) -> String {
    state::render_state_diagram_v2_debug_svg(layout, options)
}

pub fn render_class_diagram_v2_debug_svg(
    layout: &ClassDiagramV2Layout,
    options: &SvgRenderOptions,
) -> String {
    class::render_class_diagram_v2_debug_svg(layout, options)
}

pub fn render_class_diagram_v2_svg(
    layout: &ClassDiagramV2Layout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    diagram_title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    class::render_class_diagram_v2_svg(
        layout,
        semantic,
        effective_config,
        diagram_title,
        measurer,
        options,
    )
}

pub fn render_er_diagram_debug_svg(layout: &ErDiagramLayout, options: &SvgRenderOptions) -> String {
    er::render_er_diagram_debug_svg(layout, options)
}

pub fn render_er_diagram_svg(
    layout: &ErDiagramLayout,
    semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    diagram_title: Option<&str>,
    measurer: &dyn TextMeasurer,
    options: &SvgRenderOptions,
) -> Result<String> {
    er::render_er_diagram_svg(
        layout,
        semantic,
        effective_config,
        diagram_title,
        measurer,
        options,
    )
}

pub fn render_sankey_diagram_svg(
    layout: &SankeyDiagramLayout,
    _semantic: &serde_json::Value,
    effective_config: &serde_json::Value,
    options: &SvgRenderOptions,
) -> Result<String> {
    sankey::render_sankey_diagram_svg(layout, _semantic, effective_config, options)
}

// Ported from D3 `curveBasis` (d3-shape v3.x), used by Mermaid ER renderer `@11.12.2`.
fn curve_basis_path_d(points: &[crate::model::LayoutPoint]) -> String {
    curve::curve_basis_path_d(points)
}
fn render_node(out: &mut String, n: &LayoutNode) {
    layout_debug::render_node(out, n)
}

fn render_state_node(out: &mut String, n: &LayoutNode) {
    layout_debug::render_state_node(out, n)
}

fn render_cluster(out: &mut String, c: &LayoutCluster, include_markers: bool) {
    layout_debug::render_cluster(out, c, include_markers)
}

fn compute_layout_bounds(
    clusters: &[LayoutCluster],
    nodes: &[LayoutNode],
    edges: &[crate::model::LayoutEdge],
) -> Option<Bounds> {
    layout_debug::compute_layout_bounds(clusters, nodes, edges)
}