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
use super::*;
/// Fluent builder helpers for `EuvMermaid`.
impl EuvMermaid {
/// Registers a callback invoked when the user clicks Copy on the Mermaid diagram header.
///
/// # Arguments
///
/// - `Self` - Source Mermaid component.
/// - `F` - Callback receiving the raw Mermaid source text.
///
/// # Returns
///
/// - `Self` - Updated Mermaid component.
#[must_use]
pub fn on_copy<F>(mut self, handler: F) -> Self
where
F: Fn(&str) + 'static,
{
self.set_on_copy(Some(Rc::new(handler)));
self
}
}
/// Declarative `#[component]` implementation for `EuvMermaid`.
#[component]
/// Inherent implementation of [`EuvMermaid`].
impl EuvMermaid {
/// Renders a native vector Mermaid diagram with scrollable viewport, Copy button, and interactive Fullscreen modal.
///
/// # Arguments
///
/// - `&Self` - Mermaid component descriptor reference.
///
/// # Returns
///
/// - `NodeId` - Mounted Mermaid diagram card handle.
fn render(&self) -> NodeId {
let ctx: Context = current_context();
bind_fullscreen_context(&ctx);
let base_tokens: ThemeTokens = self.get_tokens();
let tokens: ThemeTokens = live_tokens_untracked(base_tokens);
let g: ThemeGeometry = tokens.get_geometry();
let ctrl_sm: f32 = g.get_control_sm();
let eva: CodeThemePalette = CodeThemePalette::resolve(tokens.get_mode());
let Self {
source,
style,
on_copy,
..
} = self;
let diagram: Rc<MermaidDiagram> = Rc::new(parse_mermaid_diagram(source));
let nat_sz: Size = measure_mermaid_diagram(&diagram);
let badge: &'static str = mermaid_badge_label(&diagram);
let title_raw: String = mermaid_diagram_title(&diagram);
let header_title_rc: Option<Rc<str>> = if title_raw.is_empty() {
None
} else {
Some(Rc::from(title_raw))
};
let inline_max_h: f32 = match style.map(|s: Style| s.get_layout().get_max_height()) {
Some(Length::Px(px)) if px > 0.0 => px,
_ => MERMAID_DEFAULT_MAX_HEIGHT,
};
let copied_sig: Signal<bool> = Signal::new(false);
let fs_open: Signal<bool> = Signal::new(false);
let source_rc: Rc<str> = Rc::from(source.as_str());
let copy_src: Rc<str> = Rc::clone(&source_rc);
let copy_cb: Option<MarkdownStrCallback> = on_copy.clone();
let ctx_copy: Context = ctx.clone();
let on_copy_click = move |_: &UiEvent| {
let _: bool = ctx_copy.copy_to_clipboard(©_src);
let _: bool = copied_sig.set(true);
if let Some(cb) = copy_cb.as_ref() {
cb(©_src);
}
};
let paint_inline_copy_icon = move |bounds: Rect, dl: &mut DisplayList| {
let cur_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let cur_eva: CodeThemePalette = CodeThemePalette::resolve(cur_tok.get_mode());
if copied_sig.get_untracked() {
draw_euv_icon(
EuvIconName::Check,
bounds,
dl,
cur_tok.get_palette().get_success(),
);
} else {
draw_euv_icon(EuvIconName::Copy, bounds, dl, cur_eva.get_function());
}
};
let on_open_fs = move |_: &UiEvent| {
let _: bool = fs_open.set_if_changed(true);
};
let diag_inline: Rc<MermaidDiagram> = Rc::clone(&diagram);
let inline_cache: RefCell<Option<(Rect, ThemeTokens, Vec<DrawCommand>)>> =
RefCell::new(None);
let paint_inline = move |bounds: Rect, dl: &mut DisplayList| {
let live_tok: ThemeTokens = live_tokens_untracked(base_tokens);
if let Ok(guard) = inline_cache.try_borrow()
&& let Some((cached_bounds, cached_tok, cached_cmds)) = guard.as_ref()
&& *cached_bounds == bounds
&& *cached_tok == live_tok
{
dl.get_mut_commands()
.extend_from_slice(cached_cmds.as_slice());
return;
}
let mut scratch: DisplayList = DisplayList::default();
draw_mermaid_diagram(&diag_inline, bounds, &mut scratch, live_tok);
let cmds: Vec<DrawCommand> = take(scratch.get_mut_commands());
dl.get_mut_commands().extend_from_slice(cmds.as_slice());
if let Ok(mut guard) = inline_cache.try_borrow_mut() {
*guard = Some((bounds, live_tok, cmds));
}
};
let paint_fs_icon = move |bounds: Rect, dl: &mut DisplayList| {
let live_eva: CodeThemePalette =
CodeThemePalette::resolve(live_tokens_untracked(base_tokens).get_mode());
draw_code_fullscreen_icon(bounds, dl, live_eva.get_function());
};
let diag_fs: Rc<MermaidDiagram> = Rc::clone(&diagram);
let fs_src_copy: Rc<str> = Rc::clone(&source_rc);
let fs_cb_copy: Option<MarkdownStrCallback> = on_copy.clone();
let fs_title_rc: Option<Rc<str>> = header_title_rc.clone();
let ctx_fs_copy: Context = ctx.clone();
let build_fs_panel = move || -> NodeId {
let live_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let live_p: ThemePalette = live_tok.get_palette();
let live_g: ThemeGeometry = live_tok.get_geometry();
let modal_ctrl_h: f32 = live_g.get_control_sm();
let close_surface: SurfaceColors = live_p.surface(SurfaceRole::Primary);
let live_eva: CodeThemePalette = CodeThemePalette::resolve(live_tok.get_mode());
let diag_modal: Rc<MermaidDiagram> = Rc::clone(&diag_fs);
let modal_base_w: f32 = nat_sz.get_width().max(640.0);
let modal_base_h: f32 = nat_sz.get_height().max(320.0);
let zoom_sig: Signal<f32> = Signal::new(1.0);
let modal_cache: RefCell<Option<MermaidModalPaintEntry>> = RefCell::new(None);
let paint_modal = move |bounds: Rect, dl: &mut DisplayList| {
let cur_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let cur_zoom: f32 = zoom_sig.get_untracked();
let zoom_bits: u32 = cur_zoom.to_bits();
if let Ok(guard) = modal_cache.try_borrow()
&& let Some(cached) = guard.as_ref()
&& cached.bounds == bounds
&& cached.tokens == cur_tok
&& cached.zoom_bits == zoom_bits
{
dl.get_mut_commands()
.extend_from_slice(cached.commands.as_slice());
return;
}
let mut scratch: DisplayList = DisplayList::default();
let base_rect: Rect =
Rect::new(bounds.get_x(), bounds.get_y(), modal_base_w, modal_base_h);
draw_mermaid_diagram(&diag_modal, base_rect, &mut scratch, cur_tok);
scale_mermaid_display_list(
scratch.get_mut_commands(),
Point::new(bounds.get_x(), bounds.get_y()),
cur_zoom,
);
let cmds: Vec<DrawCommand> = take(scratch.get_mut_commands());
dl.get_mut_commands().extend_from_slice(cmds.as_slice());
if let Ok(mut guard) = modal_cache.try_borrow_mut() {
*guard = Some(MermaidModalPaintEntry {
bounds,
tokens: cur_tok,
zoom_bits,
commands: cmds,
});
}
};
let modal_src: Rc<str> = Rc::clone(&fs_src_copy);
let modal_cb: Option<MarkdownStrCallback> = fs_cb_copy.clone();
let ctx_m: Context = ctx_fs_copy.clone();
let modal_copy_icon_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
let modal_copy_icon_cb: Rc<Cell<NodeId>> = Rc::clone(&modal_copy_icon_cell);
let modal_copy_btn_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
let modal_copy_btn_cb: Rc<Cell<NodeId>> = Rc::clone(&modal_copy_btn_cell);
let on_modal_copy = move |_: &UiEvent| {
let _: bool = ctx_m.copy_to_clipboard(&modal_src);
let _: bool = copied_sig.set(true);
let m_icon: NodeId = modal_copy_icon_cb.get();
let m_btn: NodeId = modal_copy_btn_cb.get();
ctx_m.get_scene().with_write(
|tree: &mut SceneTree| {
if let Some(n) = tree.get_node_mut(m_btn) {
*n.get_mut_a11y() = Some(A11yProps::new(
A11yRole::Button,
MERMAID_BTN_COPIED.to_string(),
));
}
tree.mark_dirty(m_icon, DIRTY_PAINT);
},
(),
);
if let Some(cb) = modal_cb.as_ref() {
cb(&modal_src);
}
};
let paint_modal_copy_icon = move |bounds: Rect, dl: &mut DisplayList| {
let cur_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let cur_eva: CodeThemePalette = CodeThemePalette::resolve(cur_tok.get_mode());
if copied_sig.get_untracked() {
draw_euv_icon(
EuvIconName::Check,
bounds,
dl,
cur_tok.get_palette().get_success(),
);
} else {
draw_euv_icon(EuvIconName::Copy, bounds, dl, cur_eva.get_function());
}
};
let paint_close_icon = move |bounds: Rect, dl: &mut DisplayList| {
let cur_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
let close_fg: Color = cur_p.surface(SurfaceRole::Primary).get_fg();
draw_euv_icon(EuvIconName::Minimize, bounds, dl, close_fg);
};
let on_close_fs = move |_: &UiEvent| {
let _: bool = fs_open.set_if_changed(false);
};
let on_zoom_out = move |_: &UiEvent| {
let _: bool = zoom_sig.update(|z: &mut f32| {
*z = (*z - MERMAID_ZOOM_STEP).clamp(MERMAID_ZOOM_MIN, MERMAID_ZOOM_MAX);
});
};
let on_zoom_in = move |_: &UiEvent| {
let _: bool = zoom_sig.update(|z: &mut f32| {
*z = (*z + MERMAID_ZOOM_STEP).clamp(MERMAID_ZOOM_MIN, MERMAID_ZOOM_MAX);
});
};
let body_scroll_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
let body_scroll_reset: Rc<Cell<NodeId>> = Rc::clone(&body_scroll_cell);
let scene_reset: SceneHandle = ctx_fs_copy.get_scene().clone();
let on_zoom_reset = move |_: &UiEvent| {
let _: bool = zoom_sig.set_if_changed(1.0);
let sc: NodeId = body_scroll_reset.get();
scene_reset.with_write(
|tree: &mut SceneTree| {
tree.set_scroll_offset(sc, Point::default());
},
(),
);
};
let init_copy_a11y: String = if copied_sig.get_untracked() {
MERMAID_BTN_COPIED.to_string()
} else {
MERMAID_BTN_COPY.to_string()
};
let modal_title_str: &str = fs_title_rc.as_deref().unwrap_or(badge);
let safe_sig: Signal<SafeAreaInsets> = ctx_fs_copy.get_safe_area();
let init_safe: SafeAreaInsets = safe_sig.get_untracked();
let mut modal_scroll_st: Style = Style::default();
modal_scroll_st
.get_mut_layout()
.set_flex_direction(FlexDirection::Column);
let mut top_bar_node: NodeId = NodeId::default();
let mut body_scroll_node: NodeId = NodeId::default();
let mut modal_canvas_node: NodeId = NodeId::default();
let mut zoom_reset_txt: NodeId = NodeId::default();
let mut modal_copy_btn: NodeId = NodeId::default();
let mut modal_copy_icon: NodeId = NodeId::default();
let modal_panel: NodeId = view! {
column {
style: {
width: Length::Percent(100.0)
height: Length::Percent(100.0)
flex_grow: 1.0
padding: Edges::all(0.0)
margin: Edges::all(0.0)
background: live_eva.get_background()
border: (0.0, COLOR_TRANSPARENT)
radius: 0.0
overflow: Overflow::Hidden
stop_event_propagation: true
}
row {
node_ref: top_bar_node
style: {
width: Length::Percent(100.0)
flex_shrink: 0.0
padding: Edges::new(
SPACE_SM + init_safe.get_top(),
SPACE_MD + init_safe.get_right(),
SPACE_SM,
SPACE_MD + init_safe.get_left()
)
justify: JustifyContent::SpaceBetween
align: AlignItems::Center
gap: SPACE_SM
overflow: Overflow::Hidden
background: live_eva.get_header_bg()
}
row {
style: {
flex_grow: 1.0
flex_shrink: 1.0
min_width: Length::Px(0.0)
align: AlignItems::Center
gap: SPACE_SM
overflow: Overflow::Hidden
}
row {
style: {
height: Length::Px(modal_ctrl_h)
padding: Edges::symmetric(0.0, SPACE_SM)
justify: JustifyContent::Center
align: AlignItems::Center
radius: live_g.get_radius_sm()
overflow: Overflow::Hidden
background: live_eva.get_background()
border: (1.0, live_eva.get_border())
}
text {
style: {
font_size: 10.5
font_weight: FontWeight::Bold
color: live_eva.get_keyword()
text_overflow: TextOverflow::Clip
}
{ badge }
}
}
text {
style: {
flex_shrink: 1.0
min_width: Length::Px(0.0)
overflow: Overflow::Hidden
text_overflow: TextOverflow::Ellipsis
font_size: 13.0
font_weight: FontWeight::SemiBold
color: live_p.get_foreground()
}
{ modal_title_str }
}
}
row {
style: {
flex_shrink: 0.0
align: AlignItems::Center
gap: SPACE_XS
}
row {
style: {
width: Length::Px(modal_ctrl_h)
height: Length::Px(modal_ctrl_h)
justify: JustifyContent::Center
align: AlignItems::Center
radius: live_g.get_radius_sm()
overflow: Overflow::Hidden
cursor: CursorIcon::Pointer
background: live_eva.get_background()
border: (1.0, live_eva.get_border())
}
role: A11yRole::Button
a11y_label: MERMAID_BTN_ZOOM_OUT.to_string()
on_click: on_zoom_out
text {
style: {
font_size: 14.0
font_weight: FontWeight::Bold
color: live_p.get_foreground()
text_overflow: TextOverflow::Clip
}
{ MERMAID_ZOOM_MINUS }
}
}
row {
style: {
height: Length::Px(modal_ctrl_h)
padding: Edges::symmetric(0.0, SPACE_SM)
justify: JustifyContent::Center
align: AlignItems::Center
radius: live_g.get_radius_sm()
overflow: Overflow::Hidden
cursor: CursorIcon::Pointer
background: live_eva.get_background()
border: (1.0, live_eva.get_border())
}
role: A11yRole::Button
a11y_label: MERMAID_BTN_ZOOM_RESET.to_string()
on_click: on_zoom_reset
text {
node_ref: zoom_reset_txt
style: {
font_size: 11.0
font_family: FontFamily::Monospace
font_weight: FontWeight::SemiBold
color: live_p.get_foreground()
text_overflow: TextOverflow::Clip
}
{ MERMAID_ZOOM_INIT_LABEL }
}
}
row {
style: {
width: Length::Px(modal_ctrl_h)
height: Length::Px(modal_ctrl_h)
justify: JustifyContent::Center
align: AlignItems::Center
radius: live_g.get_radius_sm()
overflow: Overflow::Hidden
cursor: CursorIcon::Pointer
background: live_eva.get_background()
border: (1.0, live_eva.get_border())
}
role: A11yRole::Button
a11y_label: MERMAID_BTN_ZOOM_IN.to_string()
on_click: on_zoom_in
text {
style: {
font_size: 14.0
font_weight: FontWeight::Bold
color: live_p.get_foreground()
text_overflow: TextOverflow::Clip
}
{ MERMAID_ZOOM_PLUS }
}
}
row {
node_ref: modal_copy_btn
style: {
width: Length::Px(modal_ctrl_h)
height: Length::Px(modal_ctrl_h)
justify: JustifyContent::Center
align: AlignItems::Center
radius: live_g.get_radius_sm()
overflow: Overflow::Hidden
cursor: CursorIcon::Pointer
background: live_eva.get_background()
border: (1.0, live_eva.get_border())
}
role: A11yRole::Button
a11y_label: init_copy_a11y
on_click: on_modal_copy
canvas {
node_ref: modal_copy_icon
style: {
width: Length::Px(14.0)
height: Length::Px(14.0)
}
painter: paint_modal_copy_icon
}
}
row {
style: {
width: Length::Px(modal_ctrl_h)
height: Length::Px(modal_ctrl_h)
justify: JustifyContent::Center
align: AlignItems::Center
radius: live_g.get_radius_sm()
overflow: Overflow::Hidden
cursor: CursorIcon::Pointer
background: close_surface.get_bg()
}
role: A11yRole::Button
a11y_label: MERMAID_BTN_CLOSE.to_string()
on_click: on_close_fs
canvas {
style: {
width: Length::Px(14.0)
height: Length::Px(14.0)
}
painter: paint_close_icon
}
}
}
}
view {
style: {
width: Length::Percent(100.0)
height: Length::Px(1.0)
background: live_eva.get_border()
}
}
scroll {
node_ref: body_scroll_node
style: {
modal_scroll_st
flex_grow: 1.0
flex_shrink: 1.0
min_height: Length::Px(0.0)
width: Length::Percent(100.0)
align: AlignItems::Start
padding: Edges::new(
SPACE_MD,
SPACE_MD + init_safe.get_right(),
SPACE_MD + init_safe.get_bottom(),
SPACE_MD + init_safe.get_left()
)
stop_scroll_propagation: true
}
canvas {
node_ref: modal_canvas_node
style: {
width: Length::Px(modal_base_w)
height: Length::Px(modal_base_h)
flex_shrink: 0.0
cursor: CursorIcon::Grab
}
painter: paint_modal
}
}
}
};
body_scroll_cell.set(body_scroll_node);
let handle_safe: SceneHandle = ctx_fs_copy.get_scene().clone();
let handle_zoom: SceneHandle = handle_safe.clone();
let (safe_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
let _: Effect = Effect::new(move || {
let z: f32 = zoom_sig.get();
let next_w: f32 = (modal_base_w * z).max(240.0);
let next_h: f32 = (modal_base_h * z).max(160.0);
if !fs_open.get_untracked() {
return;
}
let pct_label: String = format!("{}%", (z * 100.0).round() as u32);
handle_zoom.with_write(
|tree: &mut SceneTree| {
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
if let Some(n) = tree.get_node_mut(modal_canvas_node) {
let lay: &mut LayoutStyle = n.get_mut_style().get_mut_layout();
lay.set_width(Length::Px(next_w))
.set_height(Length::Px(next_h));
tree.mark_dirty(modal_canvas_node, dirty_l | DIRTY_PAINT);
}
tree.set_text(zoom_reset_txt, pct_label);
},
(),
);
});
Effect::new(move || {
let safe: SafeAreaInsets = safe_sig.get();
handle_safe.with_write(
|tree: &mut SceneTree| {
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
if let Some(n) = tree.get_node_mut(top_bar_node) {
n.get_mut_style().get_mut_layout().set_padding(Edges::new(
SPACE_SM + safe.get_top(),
SPACE_MD + safe.get_right(),
SPACE_SM,
SPACE_MD + safe.get_left(),
));
tree.mark_dirty(top_bar_node, dirty_l | DIRTY_PAINT);
}
if let Some(n) = tree.get_node_mut(body_scroll_node) {
n.get_mut_style().get_mut_layout().set_padding(Edges::new(
SPACE_MD,
SPACE_MD + safe.get_right(),
SPACE_MD + safe.get_bottom(),
SPACE_MD + safe.get_left(),
));
tree.mark_dirty(body_scroll_node, dirty_l | DIRTY_PAINT);
}
},
(),
);
})
});
ctx_fs_copy.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(modal_panel, safe_scope);
},
(),
);
modal_copy_btn_cell.set(modal_copy_btn);
modal_copy_icon_cell.set(modal_copy_icon);
modal_panel
};
let mut fs_portal: NodeId = NodeId::default();
let mut inline_copy_btn: NodeId = NodeId::default();
let mut inline_copy_icon: NodeId = NodeId::default();
let mut inline_scroll_st: Style = Style::default();
inline_scroll_st
.get_mut_layout()
.set_flex_direction(FlexDirection::Column);
let root: NodeId = view! {
column {
style: {
width: Length::Percent(100.0)
background: eva.get_background()
border: (1.0, eva.get_border())
radius: g.get_radius_lg()
overflow: Overflow::Hidden
}
row {
style: {
width: Length::Percent(100.0)
padding: Edges::symmetric(SPACE_SM, SPACE_MD)
justify: JustifyContent::SpaceBetween
align: AlignItems::Center
gap: SPACE_SM
overflow: Overflow::Hidden
background: eva.get_header_bg()
}
row {
style: {
flex_grow: 1.0
flex_shrink: 1.0
min_width: Length::Px(0.0)
align: AlignItems::Center
gap: SPACE_SM
overflow: Overflow::Hidden
}
row {
style: {
flex_shrink: 0.0
height: Length::Px(ctrl_sm)
padding: Edges::symmetric(0.0, SPACE_SM)
justify: JustifyContent::Center
align: AlignItems::Center
radius: g.get_radius_sm()
overflow: Overflow::Hidden
background: eva.get_background()
border: (1.0, eva.get_border())
}
text {
style: {
font_size: 10.5
font_weight: FontWeight::Bold
color: eva.get_keyword()
text_overflow: TextOverflow::Clip
}
{ badge }
}
}
if let Some(title_text) = header_title_rc.as_deref() {
text {
style: {
flex_grow: 1.0
flex_shrink: 1.0
min_width: Length::Px(0.0)
overflow: Overflow::Hidden
text_overflow: TextOverflow::Ellipsis
font_size: 12.0
font_weight: FontWeight::SemiBold
color: eva.get_foreground()
}
{ title_text }
}
}
}
row {
style: {
flex_shrink: 0.0
align: AlignItems::Center
gap: SPACE_XS
}
row {
style: {
width: Length::Px(ctrl_sm)
height: Length::Px(ctrl_sm)
radius: g.get_radius_sm()
overflow: Overflow::Hidden
justify: JustifyContent::Center
align: AlignItems::Center
cursor: CursorIcon::Pointer
background: eva.get_background()
border: (1.0, eva.get_border())
}
role: A11yRole::Button
a11y_label: MERMAID_BTN_FULLSCREEN.to_string()
on_click: on_open_fs
canvas {
style: {
width: Length::Px(13.0)
height: Length::Px(13.0)
}
painter: paint_fs_icon
}
}
row {
node_ref: inline_copy_btn
style: {
width: Length::Px(ctrl_sm)
height: Length::Px(ctrl_sm)
radius: g.get_radius_sm()
overflow: Overflow::Hidden
justify: JustifyContent::Center
align: AlignItems::Center
cursor: CursorIcon::Pointer
background: eva.get_background()
border: (1.0, eva.get_border())
}
role: A11yRole::Button
a11y_label: MERMAID_BTN_COPY.to_string()
on_click: on_copy_click
canvas {
node_ref: inline_copy_icon
style: {
width: Length::Px(13.0)
height: Length::Px(13.0)
}
painter: paint_inline_copy_icon
}
}
}
}
view {
style: {
width: Length::Percent(100.0)
height: Length::Px(1.0)
background: eva.get_border()
}
}
scroll {
style: {
inline_scroll_st
width: Length::Percent(100.0)
max_height: Length::Px(inline_max_h)
align: AlignItems::Start
}
canvas {
style: {
width: Length::Px(nat_sz.get_width())
height: Length::Px(nat_sz.get_height())
flex_shrink: 0.0
cursor: CursorIcon::Grab
}
painter: paint_inline
}
}
portal {
node_ref: fs_portal
style: {
Style::default().column()
display: Display::None
position: Position::Fixed
inset: (Some(0.0), Some(0.0), Some(0.0), Some(0.0))
width: Length::Percent(100.0)
height: Length::Percent(100.0)
padding: Edges::all(0.0)
margin: Edges::all(0.0)
justify: JustifyContent::Start
align: AlignItems::Stretch
background: eva.get_background()
border: (0.0, COLOR_TRANSPARENT)
radius: 0.0
overflow: Overflow::Hidden
pointer_events: PointerEvents::None
stop_scroll_propagation: true
stop_event_propagation: true
z_index: Z_INDEX_FULLSCREEN
}
}
}
};
let handle: SceneHandle = ctx.get_scene().clone();
let handle_copy: SceneHandle = handle.clone();
let ctx_build: Context = ctx.clone();
let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(false));
let fs_acquired: Rc<Cell<bool>> = Rc::new(Cell::new(false));
let fs_cleanup: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
on_cleanup(move || {
if fs_cleanup.replace(false) {
exit_fullscreen();
}
});
let _: Effect = Effect::new(move || {
let is_copied: bool = copied_sig.get();
let next_label: &str = if is_copied {
MERMAID_BTN_COPIED
} else {
MERMAID_BTN_COPY
};
handle_copy.with_write(
|tree: &mut SceneTree| {
if let Some(n) = tree.get_node_mut(inline_copy_btn) {
*n.get_mut_a11y() =
Some(A11yProps::new(A11yRole::Button, next_label.to_string()));
}
tree.mark_dirty(inline_copy_icon, DIRTY_PAINT);
},
(),
);
});
let _: Effect = EuvOverlayStack::bind_signal(
fs_open,
MERMAID_FULLSCREEN_OVERLAY_NAME,
Z_INDEX_FULLSCREEN,
);
Effect::new(move || {
let is_open: bool = fs_open.get();
if is_open == prev_open.replace(is_open) {
return;
}
if is_open {
if !fs_acquired.replace(true) {
enter_fullscreen();
}
let live_eva: CodeThemePalette =
CodeThemePalette::resolve(live_tokens_untracked(base_tokens).get_mode());
let modal_panel: NodeId = with_context(ctx_build.clone(), &build_fs_panel);
handle.with_write(
|tree: &mut SceneTree| {
let from_op: f32 = tree
.get_node(fs_portal)
.filter(|n: &&SceneNode| {
n.style_ref().get_layout().get_display() != Display::None
})
.map(|n: &SceneNode| n.style_ref().get_paint().get_opacity())
.unwrap_or(0.0);
tree.cancel_subtree_transitions(fs_portal);
tree.replace_children(fs_portal, vec![modal_panel]);
if let Some(n) = tree.get_node_mut(fs_portal) {
let st: &mut Style = n.get_mut_style();
st.get_mut_layout().set_display(Display::Flex);
st.get_mut_paint()
.set_background(Some(live_eva.get_background()))
.set_pointer_events(PointerEvents::Auto)
.set_opacity(from_op)
.set_transform(Transform2D::default());
}
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
tree.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
tree.start_transition(
NodeTransition::fade(
fs_portal,
from_op,
1.0,
motion_duration(MOTION_STANDARD_SECS),
false,
)
.with_easing(MOTION_EASE_ENTER),
);
},
(),
);
} else {
if fs_acquired.replace(false) {
exit_fullscreen();
}
handle.dismiss_portal_immediate(fs_portal);
}
})
});
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(root, scope);
},
(),
);
root
}
}