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
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
use super::*;
/// Fluent builders and theme helpers for `EuvDocToc`.
impl EuvDocToc {
/// Sets a custom heading title displayed above the table-of-contents list.
///
/// # Arguments
///
/// - `Self` - Source table-of-contents component.
/// - `S` - Heading title convertible into `String`.
///
/// # Returns
///
/// - `Self` - Updated table-of-contents component.
#[must_use]
pub fn title<S>(mut self, title: S) -> Self
where
S: Into<String>,
{
self.set_title(title.into());
self
}
/// Registers a callback invoked with the clicked heading anchor slug.
///
/// # Arguments
///
/// - `Self` - Source table-of-contents component.
/// - `F` - Selection callback receiving the heading slug slice.
///
/// # Returns
///
/// - `Self` - Updated table-of-contents component.
#[must_use]
pub fn on_select<F>(mut self, handler: F) -> Self
where
F: Fn(&str) + 'static,
{
self.set_on_select(Some(Rc::new(handler)));
self
}
/// Resolves `(row_bg, bar_bg, label_fg)` for a documentation TOC row state.
///
/// # Arguments
///
/// - `ThemePalette` - Live theme palette.
/// - `bool` - Whether this heading matches the active slug.
/// - `bool` - Whether the pointer is currently hovering this row.
///
/// # Returns
///
/// - `(Color, Color, Color)` - Paired row background, rail indicator fill, and readable label color.
#[must_use]
pub fn row_colors(palette: ThemePalette, active: bool, hovered: bool) -> (Color, Color, Color) {
if active {
let bg: Color = palette.get_primary().with_alpha(22);
let effective_bg: Color = blend_over(bg, palette.get_card());
let fg: Color =
palette.readable_foreground_with(palette.get_foreground(), effective_bg);
(bg, palette.get_primary(), fg)
} else if hovered {
let accent: SurfaceColors = palette.surface(SurfaceRole::Accent);
(accent.get_bg(), palette.get_border(), accent.get_fg())
} else {
(
COLOR_TRANSPARENT,
palette.get_border(),
palette.get_muted_foreground(),
)
}
}
}
/// Declarative `#[component]` implementation for `EuvDocToc`.
#[component]
/// Inherent implementation of [`EuvDocToc`].
impl EuvDocToc {
/// Renders an interactive hierarchical table-of-contents outline with live active-slug highlighting.
///
/// # Arguments
///
/// - `&Self` - Table-of-contents component reference.
///
/// # Returns
///
/// - `NodeId` - Mounted outline card node handle.
fn render(&self) -> NodeId {
let mut ctx: Context = current_context();
let base_tokens: ThemeTokens = self.get_tokens();
let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let init_p: ThemePalette = init_tok.get_palette();
let init_g: ThemeGeometry = init_tok.get_geometry();
let active_slug: Signal<String> = self.get_active_slug();
let hovered_idx: Signal<Option<usize>> = Signal::new(None);
let Self {
items,
title,
on_select,
..
} = self;
let heading_label: &str = if title.trim().is_empty() {
DOC_TOC_DEFAULT_TITLE
} else {
title.as_str()
};
let init_slug: String = active_slug.get_untracked();
let slugs: Vec<String> = items
.iter()
.map(|item: &EuvDocTocItem| item.get_slug().clone())
.collect();
let outer_radius: f32 = init_g.get_radius_lg();
let row_radius: f32 = concentric_radius(outer_radius, CONTROL_INSET);
let mut bound_rows: Vec<(NodeId, NodeId, NodeId)> = Vec::with_capacity(items.len());
let mut owned_nodes: Vec<NodeId> = Vec::with_capacity(items.len() * 3 + 2);
let mut row_nodes: Vec<NodeId> = Vec::with_capacity(items.len());
let mut header_txt_node: NodeId = NodeId::default();
for (idx, item) in items.iter().enumerate() {
let depth_steps: u8 = item.get_level().saturating_sub(2).min(4);
let indent: f32 = (depth_steps as f32) * DOC_TOC_INDENT_STEP;
let is_active: bool = !init_slug.is_empty() && init_slug == *item.get_slug();
let (init_row_bg, init_bar_bg, init_lbl_fg): (Color, Color, Color) =
Self::row_colors(init_p, is_active, false);
let slug_owned: String = item.get_slug().clone();
let cb_opt: Option<MarkdownStrCallback> = on_select.clone();
let on_pick = move |_: &UiEvent| {
let _: bool = active_slug.set_if_changed(slug_owned.clone());
if let Some(cb) = cb_opt.as_ref() {
cb(&slug_owned);
}
};
let on_enter = move |_: &UiEvent| {
let _: bool = hovered_idx.set_if_changed(Some(idx));
};
let on_leave = move |_: &UiEvent| {
if hovered_idx.get_untracked() == Some(idx) {
let _: bool = hovered_idx.set_if_changed(None);
}
};
let mut row_id: NodeId = NodeId::default();
let mut bar_id: NodeId = NodeId::default();
let mut lbl_id: NodeId = NodeId::default();
let item_node: NodeId = view! {
row {
node_ref: row_id
style: {
width: Length::Percent(100.0)
padding: Edges::new(4.0, SPACE_SM, 4.0, SPACE_XS + indent)
align: AlignItems::Center
gap: SPACE_SM
radius: row_radius
background: init_row_bg
cursor: CursorIcon::Pointer
overflow: Overflow::Hidden
}
role: A11yRole::Button
a11y_label: item.get_title().clone()
on_click: on_pick
on_pointer_enter: on_enter
on_pointer_leave: on_leave
view {
node_ref: bar_id
style: {
width: Length::Px(2.5)
height: Length::Px(14.0)
flex_shrink: 0.0
radius: RADIUS_PILL
background: init_bar_bg
}
}
text {
node_ref: lbl_id
style: {
flex_grow: 1.0
flex_shrink: 1.0
min_width: Length::Px(0.0)
font_size: 12.5
font_weight: if is_active { FontWeight::SemiBold } else { FontWeight::Normal }
color: init_lbl_fg
overflow: Overflow::Hidden
text_overflow: TextOverflow::Ellipsis
}
{ item.get_title().as_str() }
}
}
};
owned_nodes.push(row_id);
owned_nodes.push(bar_id);
owned_nodes.push(lbl_id);
bound_rows.push((row_id, bar_id, lbl_id));
row_nodes.push(item_node);
}
let root: NodeId = view! {
column {
style: {
width: Length::Percent(100.0)
padding: Edges::all(SPACE_MD)
gap: SPACE_XS
background: init_p.get_card()
border: (init_g.get_border_width(), init_p.get_border())
radius: outer_radius
overflow: Overflow::Hidden
}
text {
node_ref: header_txt_node
style: {
width: Length::Percent(100.0)
font_size: 11.5
font_weight: FontWeight::Bold
color: init_p.get_muted_foreground()
}
{ heading_label }
}
}
};
owned_nodes.push(root);
owned_nodes.push(header_txt_node);
if !row_nodes.is_empty() {
ctx.append_many(root, row_nodes.as_slice());
}
let scene: SceneHandle = ctx.get_scene().clone();
let scene_eff: SceneHandle = scene.clone();
let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
let mut prev_tok: ThemeTokens = init_tok;
let mut prev_slug: String = init_slug;
let mut prev_hover: Option<usize> = None;
Effect::new(move || {
let next_slug: String = active_slug.get();
let next_hover: Option<usize> = hovered_idx.get();
let live_tok: ThemeTokens = use_live_tokens(base_tokens);
let theme_changed: bool = live_tok != prev_tok;
if !theme_changed && next_slug == prev_slug && next_hover == prev_hover {
return;
}
prev_tok = live_tok;
prev_slug = next_slug.clone();
prev_hover = next_hover;
let p: ThemePalette = live_tok.get_palette();
let g: ThemeGeometry = live_tok.get_geometry();
let muted: Color = p.get_muted_foreground();
scene_eff.with_write(
|tree: &mut SceneTree| {
if theme_changed {
if let Some(n) = tree.get_node_mut(root) {
n.get_mut_style()
.get_mut_paint()
.set_background(Some(p.get_card()))
.set_border(Border::new(g.get_border_width(), p.get_border()));
tree.mark_dirty(root, DIRTY_PAINT);
}
if let Some(n) = tree.get_node_mut(header_txt_node) {
n.get_mut_style().get_mut_text().set_color(muted);
tree.mark_dirty(header_txt_node, DIRTY_PAINT);
}
}
for (idx, &(row_id, bar_id, lbl_id)) in bound_rows.iter().enumerate() {
let is_cur: bool = slugs
.get(idx)
.is_some_and(|s: &String| !next_slug.is_empty() && s == &next_slug);
let is_hov: bool = !is_cur && next_hover == Some(idx);
let (row_bg, bar_bg, lbl_fg): (Color, Color, Color) =
Self::row_colors(p, is_cur, is_hov);
if let Some(n) = tree.get_node_mut(row_id) {
n.get_mut_style()
.get_mut_paint()
.set_background(Some(row_bg));
tree.mark_dirty(row_id, DIRTY_PAINT);
}
if let Some(n) = tree.get_node_mut(bar_id) {
n.get_mut_style()
.get_mut_paint()
.set_background(Some(bar_bg));
tree.mark_dirty(bar_id, DIRTY_PAINT);
}
if let Some(n) = tree.get_node_mut(lbl_id) {
n.get_mut_style()
.get_mut_text()
.set_weight(if is_cur {
FontWeight::SemiBold
} else {
FontWeight::Normal
})
.set_color(lbl_fg);
tree.mark_dirty(lbl_id, DIRTY_TEXT | DIRTY_PAINT);
}
}
},
(),
);
})
});
scene.with_write(
|tree: &mut SceneTree| {
mark_theme_owned(tree, owned_nodes.as_slice());
tree.attach_scope(root, scope);
},
(),
);
root
}
}
/// Fluent builders and theme helpers for `EuvDocPager`.
impl EuvDocPager {
/// Overrides the localized label displayed above the previous-page card.
///
/// # Arguments
///
/// - `Self` - Source documentation pager.
/// - `S` - Localized previous-page label.
///
/// # Returns
///
/// - `Self` - Updated documentation pager.
#[must_use]
pub fn prev_label<S>(mut self, label: S) -> Self
where
S: Into<String>,
{
self.set_prev_label(label.into());
self
}
/// Overrides the localized label displayed above the next-page card.
///
/// # Arguments
///
/// - `Self` - Source documentation pager.
/// - `S` - Localized next-page label.
///
/// # Returns
///
/// - `Self` - Updated documentation pager.
#[must_use]
pub fn next_label<S>(mut self, label: S) -> Self
where
S: Into<String>,
{
self.set_next_label(label.into());
self
}
/// Registers a callback invoked with the target route when Previous or Next is clicked.
///
/// # Arguments
///
/// - `Self` - Source documentation pager.
/// - `F` - Navigation callback receiving the destination route slice.
///
/// # Returns
///
/// - `Self` - Updated documentation pager.
#[must_use]
pub fn on_navigate<F>(mut self, handler: F) -> Self
where
F: Fn(&str) + 'static,
{
self.set_on_navigate(Some(Rc::new(handler)));
self
}
/// Resolves `(card_bg, border_color, title_fg, meta_fg)` for a documentation pager card.
///
/// # Arguments
///
/// - `ThemePalette` - Live theme palette.
/// - `bool` - Whether the pointer is currently hovering the pager card.
///
/// # Returns
///
/// - `(Color, Color, Color, Color)` - Paired card background, border color, readable title color, and muted caption color.
#[must_use]
pub fn card_colors(palette: ThemePalette, hovered: bool) -> (Color, Color, Color, Color) {
if hovered {
let accent: SurfaceColors = palette.surface(SurfaceRole::Accent);
let meta_fg: Color =
palette.readable_foreground_with(palette.get_muted_foreground(), accent.get_bg());
(
accent.get_bg(),
palette.get_primary(),
accent.get_fg(),
meta_fg,
)
} else {
let card: SurfaceColors = palette.surface(SurfaceRole::Card);
(
card.get_bg(),
card.get_border(),
card.get_fg(),
palette.get_muted_foreground(),
)
}
}
/// Mounts one directional pager card (`Previous` or `Next`) with compact height, vector arrow, and route handler.
///
/// # Arguments
///
/// - `&EuvDocPagerLink` - Destination link metadata.
/// - `bool` - `true` for next-page right-aligned card, `false` for previous-page left-aligned card.
/// - `&str` - Custom directional caption (falls back to `"Previous"` / `"Next"` when empty).
/// - `Signal<String>` - Active route signal to update on click.
/// - `Option<MarkdownStrCallback>` - Optional navigation callback.
/// - `ThemeTokens` - Base theme tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted pager card node handle.
fn mount_pager_card(
link: &EuvDocPagerLink,
is_next: bool,
custom_label: &str,
active_route: Signal<String>,
on_navigate: Option<MarkdownStrCallback>,
base_tokens: ThemeTokens,
) -> NodeId {
let ctx: Context = current_context();
let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let p: ThemePalette = init_tok.get_palette();
let g: ThemeGeometry = init_tok.get_geometry();
let hovered: Signal<bool> = Signal::new(false);
let (init_bg, init_border, init_title_fg, init_meta_fg): (Color, Color, Color, Color) =
Self::card_colors(p, false);
let target_route: String = link.get_route().clone();
let on_card_click = move |_: &UiEvent| {
let _: bool = active_route.set_if_changed(target_route.clone());
if let Some(cb) = on_navigate.as_ref() {
cb(&target_route);
}
};
let on_card_enter = move |_: &UiEvent| {
let _: bool = hovered.set_if_changed(true);
};
let on_card_leave = move |_: &UiEvent| {
let _: bool = hovered.set_if_changed(false);
};
let arrow_icon: EuvIconName = if is_next {
EuvIconName::ArrowRight
} else {
EuvIconName::ArrowLeft
};
let paint_arrow = move |bounds: Rect, dl: &mut DisplayList| {
let live_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
draw_euv_icon(arrow_icon, bounds, dl, live_p.get_primary());
};
let dir_label: &str = if !custom_label.trim().is_empty() {
custom_label.trim()
} else if is_next {
DOC_PAGER_NEXT_LABEL
} else {
DOC_PAGER_PREV_LABEL
};
let title_lbl: &str = link.get_title().as_str();
let align_items: AlignItems = if is_next {
AlignItems::End
} else {
AlignItems::Start
};
let text_align: TextAlign = if is_next {
TextAlign::Right
} else {
TextAlign::Left
};
let header_justify: JustifyContent = if is_next {
JustifyContent::End
} else {
JustifyContent::Start
};
let a11y_text: String = format!("{dir_label}: {title_lbl}");
let mut dir_txt_id: NodeId = NodeId::default();
let mut arrow_id: NodeId = NodeId::default();
let mut title_txt_id: NodeId = NodeId::default();
let dir_row: NodeId = if is_next {
view! {
row {
style: {
width: Length::Percent(100.0)
height: Length::Px(15.0)
justify: header_justify
align: AlignItems::Center
gap: SPACE_XS
}
text {
node_ref: dir_txt_id
style: {
flex_shrink: 0.0
height: Length::Px(15.0)
font_size: 11.0
font_weight: FontWeight::Medium
color: init_meta_fg
}
{ dir_label }
}
canvas {
node_ref: arrow_id
style: {
width: Length::Px(12.0)
height: Length::Px(12.0)
flex_shrink: 0.0
}
caching: CanvasCaching::RetainedStatic
painter: paint_arrow
}
}
}
} else {
view! {
row {
style: {
width: Length::Percent(100.0)
height: Length::Px(15.0)
justify: header_justify
align: AlignItems::Center
gap: SPACE_XS
}
canvas {
node_ref: arrow_id
style: {
width: Length::Px(12.0)
height: Length::Px(12.0)
flex_shrink: 0.0
}
caching: CanvasCaching::RetainedStatic
painter: paint_arrow
}
text {
node_ref: dir_txt_id
style: {
flex_shrink: 0.0
height: Length::Px(15.0)
font_size: 11.0
font_weight: FontWeight::Medium
color: init_meta_fg
}
{ dir_label }
}
}
}
};
let card_node: NodeId = view! {
column {
style: {
width: Length::Percent(100.0)
height: Length::Px(56.0)
min_width: Length::Px(0.0)
padding: Edges::symmetric(DOC_PAGER_PAD_V, DOC_PAGER_PAD_H)
gap: DOC_PAGER_INNER_GAP
justify: JustifyContent::Center
align: align_items
background: init_bg
border: (g.get_border_width(), init_border)
radius: g.get_radius_md()
overflow: Overflow::Hidden
cursor: CursorIcon::Pointer
}
role: A11yRole::Button
a11y_label: a11y_text
on_click: on_card_click
on_pointer_enter: on_card_enter
on_pointer_leave: on_card_leave
{ dir_row }
text {
node_ref: title_txt_id
style: {
width: Length::Percent(100.0)
height: Length::Px(20.0)
font_size: 14.0
font_weight: FontWeight::SemiBold
color: init_title_fg
text_align: text_align
overflow: Overflow::Hidden
text_overflow: TextOverflow::Ellipsis
}
{ title_lbl }
}
}
};
let scene: SceneHandle = ctx.get_scene().clone();
let scene_eff: SceneHandle = scene.clone();
let prev_state: Cell<(bool, ThemeKey)> = Cell::new((false, init_tok.key()));
let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
Effect::new(move || {
let is_hov: bool = hovered.get();
let live_tok: ThemeTokens = use_live_tokens(base_tokens);
let (old_hov, old_key): (bool, ThemeKey) =
prev_state.replace((is_hov, live_tok.key()));
if old_hov == is_hov && old_key == live_tok.key() {
return;
}
let live_p: ThemePalette = live_tok.get_palette();
let bw: f32 = live_tok.get_geometry().get_border_width();
let (bg, border, title_fg, meta_fg): (Color, Color, Color, Color) =
Self::card_colors(live_p, is_hov);
scene_eff.with_write(
|tree: &mut SceneTree| {
if let Some(n) = tree.get_node_mut(card_node) {
n.get_mut_style()
.get_mut_paint()
.set_background(Some(bg))
.set_border(Border::new(bw, border));
tree.mark_dirty(card_node, DIRTY_PAINT);
}
if let Some(n) = tree.get_node_mut(dir_txt_id) {
n.get_mut_style().get_mut_text().set_color(meta_fg);
tree.mark_dirty(dir_txt_id, DIRTY_PAINT);
}
if let Some(n) = tree.get_node_mut(title_txt_id) {
n.get_mut_style().get_mut_text().set_color(title_fg);
tree.mark_dirty(title_txt_id, DIRTY_PAINT);
}
tree.mark_dirty(arrow_id, DIRTY_PAINT);
},
(),
);
})
});
scene.with_write(
|tree: &mut SceneTree| {
let owned: [NodeId; 4] = [card_node, dir_txt_id, arrow_id, title_txt_id];
mark_theme_owned(tree, &owned);
tree.attach_scope(card_node, scope);
},
(),
);
card_node
}
}
/// Declarative `#[component]` implementation for `EuvDocPager`.
#[component]
/// Inherent implementation of [`EuvDocPager`].
impl EuvDocPager {
/// Renders responsive Previous and Next article navigation cards splitting width 50%/50% on wide viewports (`>= 640px`) and stacking cleanly on narrow screens.
///
/// # Arguments
///
/// - `&Self` - Documentation pager component reference.
///
/// # Returns
///
/// - `NodeId` - Mounted pager container handle.
fn render(&self) -> NodeId {
let mut ctx: Context = current_context();
let tokens: ThemeTokens = self.get_tokens();
let active_route: Signal<String> = self.get_active_route();
let vp_sig: Signal<Size> = ctx.get_viewport_size();
let init_wide: bool = vp_sig.get_untracked().get_width() >= DOC_PAGER_WIDE_BREAKPOINT;
let Self {
prev,
next,
prev_label,
next_label,
on_navigate,
..
} = self;
let has_any: bool = prev.is_some() || next.is_some();
if !has_any {
return view! {
view {
style: {
display: Display::None
width: Length::Percent(100.0)
}
}
};
}
let mut spacer_slots: Vec<NodeId> = Vec::with_capacity(1);
let left_slot: NodeId = if let Some(prev_link) = prev.as_ref() {
Self::mount_pager_card(
prev_link,
false,
prev_label.as_str(),
active_route,
on_navigate.clone(),
tokens,
)
} else {
let spacer: NodeId = view! {
view {
style: {
display: if init_wide { Display::Flex } else { Display::None }
width: Length::Percent(100.0)
height: Length::Px(1.0)
pointer_events: PointerEvents::None
}
}
};
spacer_slots.push(spacer);
spacer
};
let right_slot: NodeId = if let Some(next_link) = next.as_ref() {
Self::mount_pager_card(
next_link,
true,
next_label.as_str(),
active_route,
on_navigate.clone(),
tokens,
)
} else {
let spacer: NodeId = view! {
view {
style: {
display: if init_wide { Display::Flex } else { Display::None }
width: Length::Percent(100.0)
height: Length::Px(1.0)
pointer_events: PointerEvents::None
}
}
};
spacer_slots.push(spacer);
spacer
};
let root: NodeId = view! {
grid {
style: {
columns: if init_wide { 2 } else { 1 }
width: Length::Percent(100.0)
gap: if init_wide { SPACE_MD } else { SPACE_SM }
padding: Edges::new(SPACE_SM, 0.0, 0.0, 0.0)
}
}
};
ctx.append_many(root, &[left_slot, right_slot]);
let scene: SceneHandle = ctx.get_scene().clone();
let scene_eff: SceneHandle = scene.clone();
let prev_wide: Cell<bool> = Cell::new(init_wide);
let (bp_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
Effect::new(move || {
let is_wide: bool = vp_sig.get().get_width() >= DOC_PAGER_WIDE_BREAKPOINT;
let was_wide: bool = prev_wide.replace(is_wide);
if is_wide == was_wide {
return;
}
scene_eff.with_write(
|tree: &mut SceneTree| {
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
if let Some(n) = tree.get_node_mut(root) {
let lay: &mut LayoutStyle = n.get_mut_style().get_mut_layout();
lay.set_grid_columns(if is_wide { 2 } else { 1 });
tree.mark_dirty(root, dirty_l | DIRTY_PAINT);
}
for &spacer_id in spacer_slots.iter() {
if let Some(n) = tree.get_node_mut(spacer_id) {
n.get_mut_style().get_mut_layout().set_display(if is_wide {
Display::Flex
} else {
Display::None
});
tree.mark_dirty(spacer_id, dirty_l | DIRTY_PAINT);
}
}
},
(),
);
})
});
scene.with_write(
|tree: &mut SceneTree| {
tree.attach_scope(root, bp_scope);
},
(),
);
root
}
}
/// Fluent builders for `EuvDocSectionGroup`.
impl EuvDocSectionGroup {
/// Configures whether the section group starts collapsed.
///
/// # Arguments
///
/// - `Self` - Source section group.
/// - `bool` - When `true`, renders initially collapsed unless it contains the active route.
///
/// # Returns
///
/// - `Self` - Updated section group.
#[must_use]
pub fn collapsed(mut self, is_collapsed: bool) -> Self {
self.set_collapsed(is_collapsed);
self
}
}
/// Fluent builders and theme helpers for `EuvDocSectionNav`.
impl EuvDocSectionNav {
/// Registers a callback invoked whenever a sidebar navigation route is selected.
///
/// # Arguments
///
/// - `Self` - Source section navigation component.
/// - `F` - Callback receiving the selected route path slice.
///
/// # Returns
///
/// - `Self` - Updated section navigation component.
#[must_use]
pub fn on_select<F>(mut self, handler: F) -> Self
where
F: Fn(&str) + 'static,
{
self.set_on_select(Some(Rc::new(handler)));
self
}
/// Resolves `(row_bg, indicator_bg, label_fg)` for a documentation section nav item.
///
/// # Arguments
///
/// - `ThemePalette` - Live theme palette.
/// - `bool` - Whether this item matches the active route.
/// - `bool` - Whether the pointer is currently hovering this item.
///
/// # Returns
///
/// - `(Color, Color, Color)` - Paired row background, indicator fill, and readable label color.
#[must_use]
pub fn item_colors(
palette: ThemePalette,
active: bool,
hovered: bool,
) -> (Color, Color, Color) {
if active {
let bg: Color = palette.get_primary().with_alpha(24);
let effective_bg: Color = blend_over(bg, palette.get_card());
let fg: Color =
palette.readable_foreground_with(palette.get_foreground(), effective_bg);
(bg, palette.get_primary(), fg)
} else if hovered {
let accent: SurfaceColors = palette.surface(SurfaceRole::Accent);
(accent.get_bg(), COLOR_TRANSPARENT, accent.get_fg())
} else {
(
COLOR_TRANSPARENT,
COLOR_TRANSPARENT,
palette.get_muted_foreground(),
)
}
}
}
/// Declarative `#[component]` implementation for `EuvDocSectionNav`.
#[component]
/// Inherent implementation of [`EuvDocSectionNav`].
impl EuvDocSectionNav {
/// Renders grouped collapsible documentation sections with item count badges and reactive active route indicators.
///
/// # Arguments
///
/// - `&Self` - Section navigation component reference.
///
/// # Returns
///
/// - `NodeId` - Mounted sidebar section column handle.
fn render(&self) -> NodeId {
let mut ctx: Context = current_context();
let base_tokens: ThemeTokens = self.get_tokens();
let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let init_p: ThemePalette = init_tok.get_palette();
let init_g: ThemeGeometry = init_tok.get_geometry();
let active_route: Signal<String> = self.get_active_route();
let hovered_item: Signal<Option<usize>> = Signal::new(None);
let Self {
groups, on_select, ..
} = self;
let init_route: String = active_route.get_untracked();
let row_h: f32 = init_g.get_control_sm().max(DOC_NAV_ROW_MIN_HEIGHT);
let init_badge_fg: Color =
init_p.readable_foreground_with(init_p.get_muted_foreground(), init_p.get_muted());
let mut group_nodes: Vec<NodeId> = Vec::with_capacity(groups.len());
let mut group_headers: Vec<DocSectionHeaderEntry> = Vec::with_capacity(groups.len());
let mut bound_items: Vec<(String, NodeId, NodeId, NodeId)> = Vec::new();
let mut owned_nodes: Vec<NodeId> = Vec::new();
for group in groups.iter() {
let group_routes: Vec<String> = group
.get_items()
.iter()
.map(|it: &EuvNavItem| it.get_path().clone())
.collect();
let contains_active: bool = group_routes
.iter()
.any(|r: &String| r.as_str() == init_route.as_str());
let open_sig: Signal<bool> = Signal::new(contains_active || !group.get_collapsed());
let count_text: String = group.get_items().len().to_string();
let title_upper: String = group.get_title().to_ascii_uppercase();
let on_toggle_group = move |_: &UiEvent| {
let _: bool = open_sig.update(|v: &mut bool| *v = !*v);
};
let paint_chev = move |bounds: Rect, dl: &mut DisplayList| {
let live_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
let icon: EuvIconName = if open_sig.get_untracked() {
EuvIconName::ChevronDown
} else {
EuvIconName::ArrowRight
};
draw_euv_icon(icon, bounds, dl, live_p.get_muted_foreground());
};
let mut item_nodes: Vec<NodeId> = Vec::with_capacity(group.get_items().len());
for item in group.get_items().iter() {
let item_idx: usize = bound_items.len();
let is_active: bool = item.get_path().as_str() == init_route.as_str();
let (init_row_bg, init_ind_bg, init_lbl_fg): (Color, Color, Color) =
Self::item_colors(init_p, is_active, false);
let path_owned: String = item.get_path().clone();
let cb_opt: Option<MarkdownStrCallback> = on_select.clone();
let on_pick_route = move |_: &UiEvent| {
let _: bool = active_route.set_if_changed(path_owned.clone());
if let Some(cb) = cb_opt.as_ref() {
cb(&path_owned);
}
};
let on_enter_item = move |_: &UiEvent| {
let _: bool = hovered_item.set_if_changed(Some(item_idx));
};
let on_leave_item = move |_: &UiEvent| {
if hovered_item.get_untracked() == Some(item_idx) {
let _: bool = hovered_item.set_if_changed(None);
}
};
let mut row_id: NodeId = NodeId::default();
let mut ind_id: NodeId = NodeId::default();
let mut lbl_id: NodeId = NodeId::default();
let item_row: NodeId = view! {
row {
node_ref: row_id
style: {
width: Length::Percent(100.0)
height: Length::Px(row_h)
align: AlignItems::Center
gap: SPACE_SM
padding: Edges::symmetric(0.0, SPACE_SM)
radius: init_g.get_radius_md()
background: init_row_bg
cursor: CursorIcon::Pointer
overflow: Overflow::Hidden
}
role: A11yRole::Button
a11y_label: item.get_label().clone()
on_click: on_pick_route
on_pointer_enter: on_enter_item
on_pointer_leave: on_leave_item
view {
node_ref: ind_id
style: {
width: Length::Px(3.5)
height: Length::Px(18.0)
flex_shrink: 0.0
radius: RADIUS_PILL
background: init_ind_bg
}
}
text {
node_ref: lbl_id
style: {
flex_grow: 1.0
flex_shrink: 1.0
min_width: Length::Px(0.0)
font_size: 13.0
font_weight: if is_active { FontWeight::SemiBold } else { FontWeight::Medium }
color: init_lbl_fg
overflow: Overflow::Hidden
text_overflow: TextOverflow::Ellipsis
}
{ item.get_label().as_str() }
}
}
};
owned_nodes.push(row_id);
owned_nodes.push(ind_id);
owned_nodes.push(lbl_id);
bound_items.push((item.get_path().clone(), row_id, ind_id, lbl_id));
item_nodes.push(item_row);
}
let init_open: bool = open_sig.get_untracked();
let mut hdr_txt: NodeId = NodeId::default();
let mut badge_box: NodeId = NodeId::default();
let mut badge_txt: NodeId = NodeId::default();
let mut chev_node: NodeId = NodeId::default();
let mut list_col: NodeId = NodeId::default();
let group_col: NodeId = view! {
column {
style: {
width: Length::Percent(100.0)
gap: 2.0
padding: Edges::new(SPACE_XS, 0.0, SPACE_XS, 0.0)
}
row {
style: {
width: Length::Percent(100.0)
padding: Edges::symmetric(4.0, SPACE_SM)
justify: JustifyContent::SpaceBetween
align: AlignItems::Center
gap: SPACE_XS
radius: init_g.get_radius_sm()
cursor: CursorIcon::Pointer
overflow: Overflow::Hidden
}
role: A11yRole::Button
a11y_label: group.get_title().clone()
on_click: on_toggle_group
row {
style: {
flex_grow: 1.0
flex_shrink: 1.0
min_width: Length::Px(0.0)
align: AlignItems::Center
gap: SPACE_XS
overflow: Overflow::Hidden
}
canvas {
node_ref: chev_node
style: {
width: Length::Px(12.0)
height: Length::Px(12.0)
flex_shrink: 0.0
}
painter: paint_chev
}
text {
node_ref: hdr_txt
style: {
flex_grow: 1.0
flex_shrink: 1.0
min_width: Length::Px(0.0)
font_size: 11.0
font_weight: FontWeight::Bold
color: init_p.get_muted_foreground()
overflow: Overflow::Hidden
text_overflow: TextOverflow::Ellipsis
}
{ title_upper }
}
}
row {
node_ref: badge_box
style: {
flex_shrink: 0.0
padding: Edges::symmetric(1.0, 6.0)
radius: RADIUS_PILL
background: init_p.get_muted()
border: (init_g.get_border_width(), init_p.get_border())
overflow: Overflow::Hidden
}
text {
node_ref: badge_txt
style: {
font_size: 10.5
font_weight: FontWeight::SemiBold
color: init_badge_fg
}
{ count_text }
}
}
}
column {
node_ref: list_col
style: {
display: if init_open { Display::Flex } else { Display::None }
width: Length::Percent(100.0)
gap: 2.0
}
..item_nodes
}
}
};
owned_nodes.push(hdr_txt);
owned_nodes.push(badge_box);
owned_nodes.push(badge_txt);
owned_nodes.push(chev_node);
group_headers.push(DocSectionHeaderEntry {
hdr_id: hdr_txt,
badge_id: badge_box,
badge_txt_id: badge_txt,
chev_id: chev_node,
list_id: list_col,
open_sig,
routes: group_routes,
});
group_nodes.push(group_col);
}
let root: NodeId = view! {
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_XS
}
}
};
if !group_nodes.is_empty() {
ctx.append_many(root, group_nodes.as_slice());
}
let scene: SceneHandle = ctx.get_scene().clone();
let scene_eff: SceneHandle = scene.clone();
let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
for entry in group_headers.iter() {
let chev_id: NodeId = entry.chev_id;
let list_id: NodeId = entry.list_id;
let open_sig: Signal<bool> = entry.open_sig;
let sc: SceneHandle = scene_eff.clone();
let _: Effect = Effect::new(move || {
let is_open: bool = open_sig.get();
sc.with_write(
|tree: &mut SceneTree| {
if let Some(n) = tree.get_node_mut(list_id) {
n.get_mut_style().get_mut_layout().set_display(if is_open {
Display::Flex
} else {
Display::None
});
let dirty_flags: u16 =
(DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT) | DIRTY_PAINT;
tree.mark_dirty(list_id, dirty_flags);
}
tree.mark_dirty(chev_id, DIRTY_PAINT);
},
(),
);
});
}
let mut prev_tok: ThemeTokens = init_tok;
let mut prev_route: String = init_route;
let mut prev_hover: Option<usize> = None;
Effect::new(move || {
let next_route: String = active_route.get();
let next_hover: Option<usize> = hovered_item.get();
let live_tok: ThemeTokens = use_live_tokens(base_tokens);
let theme_changed: bool = live_tok != prev_tok;
if !theme_changed && next_route == prev_route && next_hover == prev_hover {
return;
}
let route_changed: bool = next_route != prev_route;
prev_tok = live_tok;
prev_route = next_route.clone();
prev_hover = next_hover;
if route_changed {
for entry in group_headers.iter() {
if entry
.routes
.iter()
.any(|r: &String| r.as_str() == next_route.as_str())
{
let _: bool = entry.open_sig.set_if_changed(true);
}
}
}
let p: ThemePalette = live_tok.get_palette();
let bw: f32 = live_tok.get_geometry().get_border_width();
let muted: Color = p.get_muted_foreground();
let badge_fg: Color = p.readable_foreground_with(muted, p.get_muted());
scene_eff.with_write(
|tree: &mut SceneTree| {
if theme_changed {
for entry in group_headers.iter() {
let hdr_id: NodeId = entry.hdr_id;
let badge_id: NodeId = entry.badge_id;
let badge_txt_id: NodeId = entry.badge_txt_id;
let chev_id: NodeId = entry.chev_id;
if let Some(n) = tree.get_node_mut(hdr_id) {
n.get_mut_style().get_mut_text().set_color(muted);
tree.mark_dirty(hdr_id, DIRTY_PAINT);
}
if let Some(n) = tree.get_node_mut(badge_id) {
n.get_mut_style()
.get_mut_paint()
.set_background(Some(p.get_muted()))
.set_border(Border::new(bw, p.get_border()));
tree.mark_dirty(badge_id, DIRTY_PAINT);
}
if let Some(n) = tree.get_node_mut(badge_txt_id) {
n.get_mut_style().get_mut_text().set_color(badge_fg);
tree.mark_dirty(badge_txt_id, DIRTY_PAINT);
}
tree.mark_dirty(chev_id, DIRTY_PAINT);
}
}
for (idx, (path, row_id, ind_id, lbl_id)) in bound_items.iter().enumerate()
{
let is_cur: bool = path.as_str() == next_route.as_str();
let is_hov: bool = !is_cur && next_hover == Some(idx);
let (row_bg, ind_bg, lbl_fg): (Color, Color, Color) =
Self::item_colors(p, is_cur, is_hov);
if let Some(n) = tree.get_node_mut(*row_id) {
n.get_mut_style()
.get_mut_paint()
.set_background(Some(row_bg));
tree.mark_dirty(*row_id, DIRTY_PAINT);
}
if let Some(n) = tree.get_node_mut(*ind_id) {
n.get_mut_style()
.get_mut_paint()
.set_background(Some(ind_bg));
tree.mark_dirty(*ind_id, DIRTY_PAINT);
}
if let Some(n) = tree.get_node_mut(*lbl_id) {
n.get_mut_style()
.get_mut_text()
.set_weight(if is_cur {
FontWeight::SemiBold
} else {
FontWeight::Medium
})
.set_color(lbl_fg);
tree.mark_dirty(*lbl_id, DIRTY_TEXT | DIRTY_PAINT);
}
}
},
(),
);
})
});
scene.with_write(
|tree: &mut SceneTree| {
mark_theme_owned(tree, owned_nodes.as_slice());
tree.attach_scope(root, scope);
},
(),
);
root
}
}
/// Fluent builders for `EuvDocMetaBar`.
impl EuvDocMetaBar {
/// Sets an optional last-updated label displayed as a metadata tag.
///
/// # Arguments
///
/// - `Self` - Source metadata bar.
/// - `S` - Updated date or label convertible into `String`.
///
/// # Returns
///
/// - `Self` - Updated metadata bar.
#[must_use]
pub fn updated<S>(mut self, updated: S) -> Self
where
S: Into<String>,
{
self.set_updated(updated.into());
self
}
/// Sets an optional source file or route metadata label displayed as a tag.
///
/// # Arguments
///
/// - `Self` - Source metadata bar.
/// - `S` - Source path label convertible into `String`.
///
/// # Returns
///
/// - `Self` - Updated metadata bar.
#[must_use]
pub fn source_path<S>(mut self, source_path: S) -> Self
where
S: Into<String>,
{
self.set_source_path(source_path.into());
self
}
}
/// Declarative `#[component]` implementation for `EuvDocMetaBar`.
#[component]
/// Inherent implementation of [`EuvDocMetaBar`].
impl EuvDocMetaBar {
/// Renders a wrapping documentation metadata strip composed from `EuvBadge` and `EuvTag`.
///
/// # Arguments
///
/// - `&Self` - Documentation metadata bar reference.
///
/// # Returns
///
/// - `NodeId` - Mounted metadata bar row handle.
fn render(&self) -> NodeId {
let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
let mins: usize = self.get_reading_minutes().max(1);
let words: usize = self.get_word_count();
let Self {
section,
updated,
source_path,
..
} = self;
let read_tag: String = format!("{mins} {DOC_META_MIN_READ_SUFFIX}");
let words_tag: String = format!("{words} {DOC_META_WORDS_SUFFIX}");
let has_updated: bool = !updated.trim().is_empty();
let updated_tag: String = format!("{DOC_META_UPDATED_PREFIX} {}", updated.trim());
let has_source: bool = !source_path.trim().is_empty();
view! {
row {
style: {
width: Length::Percent(100.0)
flex_wrap: FlexWrap::Wrap
align: AlignItems::Center
gap: SPACE_SM
}
if !section.trim().is_empty() {
EuvBadge {
label: section.clone()
tone: EuvTone::Primary
tokens: tokens
}
}
EuvTag {
label: read_tag
tone: EuvTone::Neutral
tokens: tokens
}
if words > 0 {
EuvTag {
label: words_tag
tone: EuvTone::Neutral
tokens: tokens
}
}
if has_updated {
EuvTag {
label: updated_tag
tone: EuvTone::Success
tokens: tokens
}
}
if has_source {
EuvTag {
label: source_path.clone()
tone: EuvTone::Neutral
tokens: tokens
}
}
}
}
}
}