euv_ui/component/mermaid/struct.rs
1use super::*;
2
3/// Custom Mermaid `classDef` style palette entry applied to flowchart nodes.
4#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
5pub struct MermaidClassDef {
6 /// Declared class name.
7 pub(crate) name: String,
8 /// Optional fill color expression (`#hex` or named CSS color).
9 pub(crate) fill: Option<String>,
10 /// Optional stroke border color expression.
11 pub(crate) stroke: Option<String>,
12 /// Optional label text color expression.
13 pub(crate) text_color: Option<String>,
14}
15
16/// Single node inside a Mermaid flowchart or state diagram.
17#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
18pub struct MermaidFlowNode {
19 /// Unique identifier referenced by edges.
20 pub(crate) id: String,
21 /// Visible human-readable label.
22 pub(crate) label: String,
23 /// Rendered geometric node shape.
24 #[get(type(copy))]
25 pub(crate) shape: MermaidNodeShape,
26 /// Optional enclosing subgraph index.
27 #[get(type(copy))]
28 pub(crate) subgraph: Option<usize>,
29 /// Attached Mermaid CSS class names from `:::` or `class` directives.
30 #[new(skip)]
31 pub(crate) classes: Vec<String>,
32 /// Optional custom fill color resolved from `style` or `classDef`.
33 #[new(skip)]
34 pub(crate) fill: Option<String>,
35 /// Optional custom border stroke color resolved from `style` or `classDef`.
36 #[new(skip)]
37 pub(crate) stroke: Option<String>,
38 /// Optional custom text foreground color resolved from `style` or `classDef`.
39 #[new(skip)]
40 pub(crate) text_color: Option<String>,
41 /// Optional click directive target URL or callback name.
42 #[new(skip)]
43 pub(crate) click_url: Option<String>,
44}
45
46/// Directed or undirected edge connecting two flowchart/state nodes.
47#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
48pub struct MermaidFlowEdge {
49 /// Source node identifier.
50 pub(crate) from: String,
51 /// Destination node identifier.
52 pub(crate) to: String,
53 /// Optional edge label rendered along the connector.
54 pub(crate) label: String,
55 /// Line stroke and arrowhead style.
56 #[get(type(copy))]
57 pub(crate) style: MermaidEdgeStyle,
58}
59
60/// Named subgraph group box enclosing a subset of flowchart or composite state nodes.
61#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
62pub struct MermaidSubgraph {
63 /// Visible subgraph title.
64 pub(crate) title: String,
65 /// Optional subgraph identifier used for references.
66 #[new(skip)]
67 pub(crate) id: String,
68 /// Optional enclosing parent subgraph index for nested subgraphs.
69 #[new(skip)]
70 #[get(type(copy))]
71 pub(crate) parent: Option<usize>,
72 /// Optional inner layout direction override (`direction LR`, `direction TD`, etc.).
73 #[new(skip)]
74 pub(crate) direction: Option<MermaidFlowDirection>,
75}
76
77/// Parsed Mermaid flowchart or state graph.
78#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
79pub struct MermaidFlowchart {
80 /// Layout flow direction (`TD`, `BT`, `LR`, `RL`).
81 #[get(type(copy))]
82 pub(crate) direction: MermaidFlowDirection,
83 /// Ordered unique nodes.
84 pub(crate) nodes: Vec<MermaidFlowNode>,
85 /// Ordered connectors.
86 pub(crate) edges: Vec<MermaidFlowEdge>,
87 /// Named subgraph frames (including nested subgraphs).
88 pub(crate) subgraphs: Vec<MermaidSubgraph>,
89 /// Declared `classDef` style definitions.
90 pub(crate) class_defs: Vec<MermaidClassDef>,
91}
92
93/// Active execution bar along a participant lifeline in a `sequenceDiagram`.
94#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
95pub struct MermaidSeqActivation {
96 /// Participant column index.
97 #[get(type(copy))]
98 pub(crate) participant_idx: usize,
99 /// Starting message row index.
100 #[get(type(copy))]
101 pub(crate) start_row: usize,
102 /// Ending message row index (inclusive).
103 #[get(type(copy))]
104 pub(crate) end_row: usize,
105}
106
107/// Branch separator row (`else`, `and`, `option`) inside a `MermaidSeqBlock`.
108#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
109pub struct MermaidSeqBlockDivider {
110 /// Message row index where the divider splits the block.
111 #[get(type(copy))]
112 pub(crate) row_idx: usize,
113 /// Optional branch condition label.
114 pub(crate) label: String,
115}
116
117/// Framed control-flow block (`loop`, `alt`, `opt`, `par`, `critical`, `break`, `rect`) in a `sequenceDiagram`.
118#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
119pub struct MermaidSeqBlock {
120 /// Fragment block kind.
121 #[get(type(copy))]
122 pub(crate) kind: MermaidSeqBlockKind,
123 /// Fragment header caption.
124 pub(crate) label: String,
125 /// First message row index inside this block.
126 #[get(type(copy))]
127 pub(crate) start_row: usize,
128 /// Last message row index inside this block (inclusive).
129 #[get(type(copy))]
130 pub(crate) end_row: usize,
131 /// Nesting depth (`0` = outermost).
132 #[get(type(copy))]
133 pub(crate) depth: usize,
134 /// Internal `else` / `and` / `option` divider rows.
135 pub(crate) dividers: Vec<MermaidSeqBlockDivider>,
136}
137
138/// Single message or note step inside a Mermaid `sequenceDiagram`.
139#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
140pub struct MermaidSequenceMessage {
141 /// Source participant index.
142 #[get(type(copy))]
143 pub(crate) from_idx: usize,
144 /// Target participant index.
145 #[get(type(copy))]
146 pub(crate) to_idx: usize,
147 /// Message label or note copy.
148 pub(crate) text: String,
149 /// Connector style (`Solid`, `Dashed`, `OpenArrow`, `CrossArrow`, `AsyncArrow`, etc.).
150 #[get(type(copy))]
151 pub(crate) style: MermaidEdgeStyle,
152 /// When `true`, renders as a callout note anchored to `from_idx..=to_idx`.
153 #[get(type(copy))]
154 pub(crate) is_note: bool,
155 /// Placement rule for sequence notes (`Over`, `LeftOf`, `RightOf`).
156 #[new(skip)]
157 #[get(type(copy))]
158 pub(crate) note_placement: MermaidSeqNotePlacement,
159}
160
161/// Parsed Mermaid `sequenceDiagram` with ordered participants, actor markers, autonumbering, activations, and nested control blocks.
162#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
163pub struct MermaidSequence {
164 /// Ordered participant `(id, display_label)` entries.
165 pub(crate) participants: Vec<(String, String)>,
166 /// Ordered chronological message/note steps.
167 pub(crate) messages: Vec<MermaidSequenceMessage>,
168 /// Parallel flags indicating whether each participant is an `actor` (`true`) or box (`false`).
169 pub(crate) actor_flags: Vec<bool>,
170 /// Whether `autonumber` prefixes message labels sequentially.
171 #[get(type(copy))]
172 pub(crate) autonumber: bool,
173 /// Recorded lifeline activation spans.
174 pub(crate) activations: Vec<MermaidSeqActivation>,
175 /// Recorded nested control-flow fragment boxes.
176 pub(crate) blocks: Vec<MermaidSeqBlock>,
177}
178
179/// Single class entity inside a Mermaid `classDiagram`.
180#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
181pub struct MermaidClassBox {
182 /// Class identifier and header name.
183 pub(crate) name: String,
184 /// Declared field and method member lines.
185 pub(crate) members: Vec<String>,
186 /// Optional UML stereotype annotation (for example `<<interface>>`, `<<abstract>>`, `<<service>>`).
187 #[new(skip)]
188 pub(crate) stereotype: String,
189}
190
191/// Relationship connector between two classes inside a `classDiagram`.
192#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
193pub struct MermaidClassRelation {
194 /// Source class name.
195 pub(crate) from: String,
196 /// Target class name.
197 pub(crate) to: String,
198 /// Relationship label.
199 pub(crate) label: String,
200 /// Dashed or solid connector style.
201 #[get(type(copy))]
202 pub(crate) style: MermaidEdgeStyle,
203 /// UML marker semantics (`Inheritance`, `Composition`, `Aggregation`, `Dependency`, etc.).
204 #[new(skip)]
205 #[get(type(copy))]
206 pub(crate) rel_kind: MermaidClassRelKind,
207}
208
209/// Parsed Mermaid `classDiagram`.
210#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
211pub struct MermaidClassDiagram {
212 /// Ordered class boxes.
213 pub(crate) classes: Vec<MermaidClassBox>,
214 /// Ordered relationships.
215 pub(crate) relations: Vec<MermaidClassRelation>,
216}
217
218/// Single entity table inside a Mermaid `erDiagram`.
219#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
220pub struct MermaidErEntity {
221 /// Entity name.
222 pub(crate) name: String,
223 /// Declared attribute rows (e.g. `"int id PK"`).
224 pub(crate) attributes: Vec<String>,
225}
226
227/// Cardinality relationship between two ER entities.
228#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
229pub struct MermaidErRelation {
230 /// Left entity name.
231 pub(crate) left: String,
232 /// Right entity name.
233 pub(crate) right: String,
234 /// Left cardinality token (e.g. `"||"`).
235 pub(crate) left_card: String,
236 /// Right cardinality token (e.g. `"o{"`).
237 pub(crate) right_card: String,
238 /// Relationship verb label.
239 pub(crate) label: String,
240 /// When `true`, renders a non-identifying dashed relationship line (`..`).
241 #[new(skip)]
242 #[get(type(copy))]
243 pub(crate) dashed: bool,
244}
245
246/// Parsed Mermaid `erDiagram`.
247#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
248pub struct MermaidErDiagram {
249 /// Ordered entities.
250 pub(crate) entities: Vec<MermaidErEntity>,
251 /// Ordered cardinality relationships.
252 pub(crate) relations: Vec<MermaidErRelation>,
253}
254
255/// Single proportional slice inside a Mermaid `pie` chart.
256#[derive(Clone, Data, Debug, New, PartialEq)]
257pub struct MermaidPieSlice {
258 /// Slice display label.
259 pub(crate) label: String,
260 /// Positive numeric weight.
261 #[get(type(copy))]
262 pub(crate) value: f32,
263}
264
265/// Parsed Mermaid `pie` chart.
266#[derive(Clone, Data, Debug, Default, PartialEq)]
267pub struct MermaidPieChart {
268 /// Optional chart title.
269 pub(crate) title: String,
270 /// Ordered pie slices.
271 pub(crate) slices: Vec<MermaidPieSlice>,
272}
273
274/// Single timeline task bar inside a Mermaid `gantt` chart.
275#[derive(Clone, Data, Debug, New, PartialEq)]
276pub struct MermaidGanttTask {
277 /// Enclosing section label.
278 pub(crate) section: String,
279 /// Task display title.
280 pub(crate) label: String,
281 /// Visual bar status.
282 #[get(type(copy))]
283 pub(crate) status: MermaidGanttStatus,
284 /// Relative start offset in timeline units.
285 #[get(type(copy))]
286 pub(crate) start_unit: f32,
287 /// Duration span in timeline units.
288 #[get(type(copy))]
289 pub(crate) duration_unit: f32,
290}
291
292/// Parsed Mermaid `gantt` chart.
293#[derive(Clone, Data, Debug, Default, PartialEq)]
294pub struct MermaidGanttChart {
295 /// Optional chart title.
296 pub(crate) title: String,
297 /// Ordered timeline tasks.
298 pub(crate) tasks: Vec<MermaidGanttTask>,
299}
300
301/// Single chronological milestone period inside a Mermaid `timeline` diagram.
302#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
303pub struct MermaidTimelineEvent {
304 /// Optional enclosing section name.
305 pub(crate) section: String,
306 /// Period heading label (e.g. `"2026 Q1"`).
307 pub(crate) period: String,
308 /// Ordered event descriptions within this period.
309 pub(crate) items: Vec<String>,
310}
311
312/// Parsed Mermaid `timeline` diagram.
313#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
314pub struct MermaidTimeline {
315 /// Optional timeline heading title.
316 pub(crate) title: String,
317 /// Ordered milestone period columns.
318 pub(crate) events: Vec<MermaidTimelineEvent>,
319}
320
321/// Single hierarchical node inside a Mermaid `mindmap` diagram.
322#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
323pub struct MermaidMindmapNode {
324 /// Visible node caption.
325 pub(crate) label: String,
326 /// Tree indentation depth (`0` = root).
327 #[get(type(copy))]
328 pub(crate) depth: usize,
329 /// Node geometric outline shape.
330 #[get(type(copy))]
331 pub(crate) shape: MermaidNodeShape,
332}
333
334/// Parsed Mermaid `mindmap` hierarchy.
335#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
336pub struct MermaidMindmap {
337 /// Ordered pre-order mindmap nodes.
338 pub(crate) nodes: Vec<MermaidMindmapNode>,
339}
340
341/// Single bar or line series inside a Mermaid `xychart-beta` diagram.
342#[derive(Clone, Data, Debug, New, PartialEq)]
343pub struct MermaidXySeries {
344 /// `true` for bar series, `false` for line series.
345 #[get(type(copy))]
346 pub(crate) is_bar: bool,
347 /// Ordered numeric data points matching `x_labels`.
348 pub(crate) values: Vec<f32>,
349}
350
351/// Parsed Mermaid `xychart-beta` / `xychart` diagram.
352#[derive(Clone, Data, Debug, Default, PartialEq)]
353pub struct MermaidXyChart {
354 /// Optional chart title.
355 pub(crate) title: String,
356 /// Categorical X-axis tick labels.
357 pub(crate) x_labels: Vec<String>,
358 /// Optional Y-axis caption.
359 pub(crate) y_label: String,
360 /// Resolved minimum Y-axis scale bound.
361 #[get(type(copy))]
362 pub(crate) y_min: f32,
363 /// Resolved maximum Y-axis scale bound.
364 #[get(type(copy))]
365 pub(crate) y_max: f32,
366 /// Ordered bar and line series.
367 pub(crate) series: Vec<MermaidXySeries>,
368}
369
370/// Single commit node inside a Mermaid `gitGraph` diagram.
371#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
372pub struct MermaidGitCommit {
373 /// Commit display identifier or short hash.
374 pub(crate) id: String,
375 /// Active branch name where this commit lives.
376 pub(crate) branch: String,
377 /// Zero-based horizontal branch lane index.
378 #[get(type(copy))]
379 pub(crate) lane: usize,
380 /// Optional tag badge attached to this commit.
381 pub(crate) tag: String,
382 /// Optional commit highlight style (`""`, `"HIGHLIGHT"`, `"REVERSE"`).
383 pub(crate) commit_type: String,
384 /// Optional source branch lane index when this commit represents a `merge`.
385 #[get(type(copy))]
386 pub(crate) merge_from_lane: Option<usize>,
387 /// Optional previous commit index on the same branch or branch point.
388 #[get(type(copy))]
389 pub(crate) parent_idx: Option<usize>,
390}
391
392/// Parsed Mermaid `gitGraph` commit and branch topology.
393#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
394pub struct MermaidGitGraph {
395 /// Ordered branch names (index = lane).
396 pub(crate) branches: Vec<String>,
397 /// Ordered commit history steps.
398 pub(crate) commits: Vec<MermaidGitCommit>,
399}
400
401/// Native vector Mermaid diagram component rendering flowcharts, sequence, state, class, ER, pie, Gantt, timeline, mindmap, XY chart, and gitGraph diagrams onto `euv` `canvas` with H+V scrolling and fullscreen inspection.
402#[derive(Clone, CustomDebug, Data, New, Props)]
403pub struct EuvMermaid {
404 /// Raw Mermaid diagram source text.
405 pub(crate) source: String,
406 /// Active theme tokens.
407 #[get(type(copy))]
408 pub(crate) tokens: ThemeTokens,
409 /// Optional style overrides controlling maximum inline viewport height and container styling (defaults to `max_height: Length::Px(420.0)`).
410 #[new(skip)]
411 #[get(type(copy))]
412 pub(crate) style: Option<Style>,
413 /// Optional copy callback invoked with the raw Mermaid source when Copy is clicked.
414 #[new(skip)]
415 #[debug(skip)]
416 #[get(skip)]
417 #[prop(custom)]
418 pub(crate) on_copy: Option<MarkdownStrCallback>,
419}
420
421/// Cached inline Mermaid display-list entry keyed by `(bounds, tokens, scale_bits)`.
422pub(crate) struct MermaidInlinePaintEntry {
423 /// Logical canvas bounds when cached.
424 pub(crate) bounds: Rect,
425 /// Active theme tokens when cached.
426 pub(crate) tokens: ThemeTokens,
427 /// Display DPI scale factor raw `f32` bits when cached.
428 pub(crate) scale_bits: u32,
429 /// Cached draw commands.
430 pub(crate) commands: Vec<DrawCommand>,
431}
432
433/// Cached scaled fullscreen display-list entry keyed by `(bounds, tokens, zoom_bits, scale_bits)`.
434pub(crate) struct MermaidModalPaintEntry {
435 /// Logical canvas bounds when cached.
436 pub(crate) bounds: Rect,
437 /// Active theme tokens when cached.
438 pub(crate) tokens: ThemeTokens,
439 /// Zoom factor raw `f32` bits when cached.
440 pub(crate) zoom_bits: u32,
441 /// Display DPI scale factor raw `f32` bits when cached.
442 pub(crate) scale_bits: u32,
443 /// Cached scaled draw commands.
444 pub(crate) commands: Vec<DrawCommand>,
445}