native-theme 0.7.0

Cross-platform native theme detection and loading for Rust GUI applications
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
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
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
//! Gate: the native themes state what their platform documents
//! (spec `docs/archive/todo_v0.5.9_unstated-sizes-and-chrome-ux-spec.md` §1.4–§1.6).
//!
//! One row per (preset, widget) gives every padding side, and for the toolbar
//! its `bar_height` and `item_gap`, for the tab bar its `item_gap`, for the
//! menu and the list their `row_height`, for the list its `header_height`,
//! for the expander its `arrow_gap` and `content_indent`, and for the
//! combobox its `arrow_area_width` where the platform gives one number, as
//! `Some(v)` where `docs/platform-facts.md` documents a value for that
//! platform and `None` where it does not, or where a ruling leaves it
//! unstated. Each row cites the platform-facts lines it reads. Rows are keyed
//! by preset, not by platform: a cell that tags its values by OS version
//! gives each value to that version's preset (platform-facts' Conventions),
//! so a platform's next generation gets rows of its own.
//!
//! Presets that platform-facts does not cover (the colour schemes, and the
//! `ios-13` platform preset, which no platform-facts column documents) state
//! none of these sizes: nothing cites a source for them, so the toolkit's own
//! stand. The Material column counts a material-web or Compose implementation
//! constant cited at a pinned line, which its cells tag **(impl)**, as
//! documented, as the KDE and GNOME columns count a Breeze or libadwaita
//! source constant.
//!
//! A second table, one row per (preset, field), gives the text scale's
//! sizes and weights, the dialog title font's size and weight, the slider's
//! `track_height` and `thumb_diameter`, the progress bar's `track_height`,
//! the checkbox's `radio_dot_diameter`, `check_mark_stroke_width` and
//! `radio_indicator_width`, the switch's `unchecked_thumb_diameter` and the
//! tab's `active_indicator_width` and `active_outward_corner_radius`. A cell
//! that leaves the field to inheritance ("← `defaults.font`", "(none)") is
//! checked as not stated.
//!
//! Every row is checked in both variants against two resolutions:
//!
//! - **static**: the platform's full preset;
//! - **live**: the full preset with the reader's size constants merged over
//!   it, in `pipeline.rs`'s order.
//!
//! The KDE reader returns one variant (`ReaderOutput::Single`), so the real
//! pipeline applies its constants to the active variant only and takes the
//! inactive variant from the full preset, which the static resolution covers.
//! The live resolution here applies the constants to each variant in turn, as
//! the pipeline does when that variant is the active one. GNOME's reader
//! states no sizes, the Windows and macOS readers only what the OS reports,
//! which no row here covers, and Material has no reader, so only their static
//! resolution is checked.
//!
//! This lives inside the crate because the KDE reader's constants
//! (`kde_metrics::populate_widget_sizing`) are `pub(crate)`.

use crate::model::border::ResolvedPadding;
use crate::resolve::ResolutionContext;
use crate::{ColorMode, ResolvedTheme, Theme, ThemeMode};

const PLATFORM_FACTS: &str = include_str!("../../../docs/platform-facts.md");

/// The native presets the gate checks, each a platform's generation.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum NativePreset {
    KdeBreeze,
    Adwaita,
    MacosMonterey,
    MacosTahoe,
    Windows11,
    Material3,
}

impl NativePreset {
    const ALL: [NativePreset; 6] = [
        NativePreset::KdeBreeze,
        NativePreset::Adwaita,
        NativePreset::MacosMonterey,
        NativePreset::MacosTahoe,
        NativePreset::Windows11,
        NativePreset::Material3,
    ];

    fn key(self) -> &'static str {
        match self {
            NativePreset::KdeBreeze => "kde-breeze",
            NativePreset::Adwaita => "adwaita",
            NativePreset::MacosMonterey => "macos-monterey",
            NativePreset::MacosTahoe => "macos-tahoe",
            NativePreset::Windows11 => "windows-11",
            NativePreset::Material3 => "material-3",
        }
    }

    /// The resolutions the gate checks: static, and live where the
    /// platform's reader states sizes.
    fn resolutions(self) -> &'static [bool] {
        match self.reader_constants() {
            Some(_) => &[false, true],
            None => &[false],
        }
    }

    /// The reader's size constants as the sparse variant the reader returns.
    fn reader_constants(self) -> Option<ThemeMode> {
        match self {
            NativePreset::KdeBreeze => {
                let mut v = ThemeMode::default();
                crate::kde_metrics::populate_widget_sizing(&mut v);
                Some(v)
            }
            NativePreset::Adwaita
            | NativePreset::Material3
            | NativePreset::Windows11
            | NativePreset::MacosMonterey
            | NativePreset::MacosTahoe => None,
        }
    }
}

/// Top, right, bottom, left.
type Sides = [Option<f32>; 4];

const NONE: Sides = [None; 4];

const fn all(v: f32) -> Sides {
    [Some(v); 4]
}

/// Equal top/bottom and equal left/right.
const fn axes(vertical: f32, horizontal: f32) -> Sides {
    [
        Some(vertical),
        Some(horizontal),
        Some(vertical),
        Some(horizontal),
    ]
}

const fn trbl(t: f32, r: f32, b: f32, l: f32) -> Sides {
    [Some(t), Some(r), Some(b), Some(l)]
}

struct Row {
    preset: NativePreset,
    widget: &'static str,
    padding: Sides,
    /// platform-facts.md lines this row reads: the padding rows, or the
    /// section heading where the section has no padding row.
    lines: &'static [usize],
    /// How the cells were read.
    note: &'static str,
    /// Further fields: (field, expected, platform-facts.md line).
    extra: &'static [(&'static str, Option<f32>, usize)],
}

impl Row {
    const fn with(self, extra: &'static [(&'static str, Option<f32>, usize)]) -> Row {
        Row { extra, ..self }
    }
}

const fn row(
    preset: NativePreset,
    widget: &'static str,
    padding: Sides,
    lines: &'static [usize],
    note: &'static str,
) -> Row {
    Row {
        preset,
        widget,
        padding,
        lines,
        note,
        extra: &[],
    }
}

use NativePreset::{Adwaita, KdeBreeze, MacosMonterey, MacosTahoe, Material3, Windows11};

#[rustfmt::skip]
const ROWS: &[Row] = &[
    // --- KDE (kde-breeze, kde_metrics) ---
    row(KdeBreeze, "window", NONE, &[1170, 1171], "pointer to §2.20 layout margins"),
    row(KdeBreeze, "button", all(6.0), &[1184, 1185], "Button_MarginWidth = 6, both axes"),
    row(KdeBreeze, "input", axes(6.0, 7.0), &[1213, 1214], "inside the frame line: LineEdit_FrameWidth 6 + QLineEdit's 2 / 1 − 1"),
    row(KdeBreeze, "text_area", all(5.0), &[1714, 1715], "inside the frame line: Frame_FrameWidth 2 + documentMargin 4 − 1"),
    row(KdeBreeze, "checkbox", NONE, &[1237, 1238], "(none)"),
    row(KdeBreeze, "menu", all(4.0), &[1261, 1262], "MenuItem_MarginWidth = 4; MenuItem_MarginHeight = 4")
        .with(&[("row_height", None, 1260)]),
    row(KdeBreeze, "tooltip", all(3.0), &[1283, 1284], "ToolTip_FrameWidth = 3"),
    row(KdeBreeze, "progress_bar", all(0.0), &[1341, 1342], "0; 0, the contents span the groove"),
    row(KdeBreeze, "tab", axes(4.0, 8.0), &[1352, 1353], "TabBar_TabMarginWidth = 8; TabBar_TabMarginHeight = 4")
        .with(&[("item_gap", Some(0.0), 1360)]),
    row(KdeBreeze, "sidebar", NONE, &[1380, 1381], "❓: the GlobalDrawer states no padding"),
    Row {
        preset: KdeBreeze,
        widget: "toolbar",
        padding: all(6.0),
        lines: &[1392, 1393],
        note: "ToolBar_ItemMargin = 6 on all four sides (qtoolbarlayout.cpp:87-89)",
        extra: &[("bar_height", None, 1390), ("item_gap", Some(0.0), 1391)],
    },
    row(KdeBreeze, "status_bar", trbl(3.0, 14.0, 2.0, 2.0), &[1414, 1415], "QStatusBar: 2 left, 3 top / 2 bottom; 14 right, the 1 + 13px size grip Breeze paints as nothing (not maximized)"),
    row(KdeBreeze, "list", axes(1.0, 2.0), &[1433, 1434], "2; 1")
        .with(&[("row_height", None, 1431), ("header_height", None, 1432)]),
    row(KdeBreeze, "popover", all(12.0), &[1461, 1462], "qqc2-desktop-style Popup: padding 12"),
    row(KdeBreeze, "dialog", all(10.0), &[1556, 1557], "Layout_TopLevelMarginWidth = 10"),
    row(KdeBreeze, "combo_box", trbl(6.0, 0.0, 6.0, 6.0), &[1618, 1623], "ComboBox_FrameWidth = 6 left, top and bottom; 0 right, to the 20px arrow column")
        .with(&[("arrow_area_width", Some(20.0), 1620)]),
    row(KdeBreeze, "segmented_control", NONE, &[1640, 1645], "tab bar as proxy, not the platform's value"),
    row(KdeBreeze, "card", all(7.0), &[1662, 1663], "Kirigami Card: Units.largeSpacing 8 from the outer edge, 8 − 1 inside the frame line"),
    row(KdeBreeze, "expander", NONE, &[1677, 1678], "(none), app-defined")
        .with(&[("arrow_gap", Some(9.0), 1684), ("content_indent", Some(20.0), 1685)]),
    // --- GNOME (adwaita; the reader states no sizes) ---
    row(Adwaita, "window", NONE, &[1170, 1171], "pointer to §2.20 layout margins"),
    row(Adwaita, "button", axes(5.0, 17.0), &[1184, 1185], "label-only .text-button 17; 5"),
    row(Adwaita, "input", axes(0.0, 9.0), &[1213, 1214], "9; 0"),
    row(Adwaita, "text_area", all(0.0), &[1714, 1715], "textview: no padding, GtkTextView margins 0"),
    row(Adwaita, "checkbox", all(3.0), &[1237, 1238], "check { padding: 3px }"),
    row(Adwaita, "menu", axes(0.0, 12.0), &[1261, 1262], "12 ($menu_padding); 0")
        .with(&[("row_height", Some(32.0), 1260)]),
    row(Adwaita, "tooltip", axes(6.0, 10.0), &[1283, 1284], "10; 6"),
    row(Adwaita, "progress_bar", all(0.0), &[1341, 1342], "0; 0, the progress fills the trough"),
    row(Adwaita, "tab", axes(3.0, 12.0), &[1352, 1353], "12; 3")
        .with(&[("item_gap", Some(0.0), 1360)]),
    row(Adwaita, "sidebar", trbl(6.0, 6.0, 4.0, 6.0), &[1380, 1381], ".navigation-sidebar > row margin 0 $menu_margin, 6; padding-top 6, padding-bottom $menu_margin - 2px, 4"),
    Row {
        preset: Adwaita,
        widget: "toolbar",
        padding: all(6.0),
        lines: &[1392, 1393],
        note: ".toolbar { padding: 6px }",
        extra: &[("bar_height", None, 1390), ("item_gap", Some(6.0), 1391)],
    },
    row(Adwaita, "status_bar", axes(6.0, 10.0), &[1414, 1415], "statusbar { padding: 6px 10px }"),
    row(Adwaita, "list", all(2.0), &[1433, 1434], "plain list context: 2")
        .with(&[("row_height", None, 1431), ("header_height", Some(30.0), 1432)]),
    row(Adwaita, "popover", all(8.0), &[1461, 1462], "popover > contents { padding: 8px }"),
    row(Adwaita, "dialog", trbl(32.0, 24.0, 24.0, 24.0), &[1556, 1557], "24; 32 top / 24 bottom"),
    row(Adwaita, "combo_box", axes(5.0, 10.0), &[1618, 1623], "base button rule, the dropdown's button has a box child: 10; 5")
        .with(&[("arrow_area_width", None, 1620)]),
    row(Adwaita, "segmented_control", axes(0.0, 8.0), &[1640, 1645], "AdwToggleGroup text toggle 11 − 3 = 8; 0"),
    row(Adwaita, "card", NONE, &[1662, 1663], "(none), app-defined"),
    row(Adwaita, "expander", axes(8.0, 14.0), &[1677, 1678], "AdwExpanderRow header sums: 2 + 12 = 14; 2 + 6 = 8")
        .with(&[("arrow_gap", Some(9.0), 1684), ("content_indent", Some(0.0), 1685)]),
    // --- macOS 12-15 (macos-monterey; the reader states no sizes) ---
    row(MacosMonterey, "window", NONE, &[1170, 1171], "pointer to §2.20 layout margins"),
    row(MacosMonterey, "button", trbl(1.0, 8.0, 3.0, 8.0), &[1184, 1185], "~8 (WebKit); 1 top / 3 bottom (API, the macOS 14.8.9 probe)"),
    row(MacosMonterey, "input", all(2.0), &[1213, 1214], "2; 2 top / 2 bottom (API, the macOS 14.8.9 probe)"),
    row(MacosMonterey, "text_area", NONE, &[1714, 1715], "(none): textContainerInset's default is not stated"),
    row(MacosMonterey, "checkbox", NONE, &[1237, 1238], "(none)"),
    row(MacosMonterey, "menu", axes(3.0, 12.0), &[1261, 1262], "12; 3 (measured)")
        .with(&[("row_height", Some(22.0), 1260)]),
    row(MacosMonterey, "tooltip", all(4.0), &[1283, 1284], "4; 4"),
    row(MacosMonterey, "progress_bar", all(0.0), &[1341, 1342], "0; 0 (measured, macOS 14.8.9 and 15.7.9)"),
    row(MacosMonterey, "tab", axes(4.0, 12.0), &[1352, 1353], "12; 4 (measured)")
        .with(&[("item_gap", None, 1360)]),
    row(MacosMonterey, "sidebar", NONE, &[1380, 1381], "❓"),
    Row {
        preset: MacosMonterey,
        widget: "toolbar",
        padding: axes(0.0, 8.0),
        lines: &[1392, 1393],
        note: "8 (measured); 0",
        extra: &[("bar_height", Some(38.0), 1390), ("item_gap", Some(8.0), 1391)],
    },
    row(MacosMonterey, "status_bar", NONE, &[1414, 1415], "(none): no window status bar"),
    row(MacosMonterey, "list", all(4.0), &[1433, 1434], "4; 4 (measured)")
        .with(&[("row_height", Some(24.0), 1431), ("header_height", Some(28.0), 1432)]),
    row(MacosMonterey, "popover", NONE, &[1461, 1462], "(none)"),
    row(MacosMonterey, "dialog", all(20.0), &[1556, 1557], "~20 (measured)"),
    row(MacosMonterey, "combo_box", [Some(1.0), None, Some(3.0), Some(8.0)], &[1618, 1623], "8 left, the arrow on the right; 1 top / 3 bottom (API, the macOS 14.8.9 probe)")
        .with(&[("arrow_area_width", None, 1620)]),
    row(MacosMonterey, "segmented_control", [Some(3.0), None, Some(3.0), None], &[1640, 1645], "horizontal is a range; ~3 (measured)"),
    row(MacosMonterey, "card", all(5.0), &[1662, 1663], "NSBox.contentViewMargins 5 (API)"),
    row(MacosMonterey, "expander", NONE, &[1677, 1678], "(none), app-defined")
        .with(&[("arrow_gap", None, 1684), ("content_indent", None, 1685)]),
    // --- macOS 26 (macos-tahoe; the "macOS 26:" values; ❓ is None) ---
    row(MacosTahoe, "window", NONE, &[1170, 1171], "pointer to §2.20 layout margins"),
    row(MacosTahoe, "button", axes(4.0, 12.0), &[1184, 1185], "macOS 26: 12; 4 top / 4 bottom (API, the macOS 26.6.2 probe)"),
    row(MacosTahoe, "input", all(4.0), &[1213, 1214], "macOS 26: 4; 4 top / 4 bottom (API)"),
    row(MacosTahoe, "text_area", NONE, &[1714, 1715], "(none): textContainerInset's default is not stated"),
    row(MacosTahoe, "checkbox", NONE, &[1237, 1238], "(none)"),
    row(MacosTahoe, "menu", NONE, &[1261, 1262], "macOS 26 ❓")
        .with(&[("row_height", None, 1260)]),
    row(MacosTahoe, "tooltip", NONE, &[1283, 1284], "macOS 26 ❓"),
    row(MacosTahoe, "progress_bar", all(0.0), &[1341, 1342], "macOS 26: 0; 0 (measured, macOS 26.6.2)"),
    row(MacosTahoe, "tab", NONE, &[1352, 1353], "macOS 26 ❓")
        .with(&[("item_gap", None, 1360)]),
    row(MacosTahoe, "sidebar", NONE, &[1380, 1381], "macOS 26 ❓"),
    Row {
        preset: MacosTahoe,
        widget: "toolbar",
        padding: NONE,
        lines: &[1392, 1393],
        note: "macOS 26 ❓",
        extra: &[("bar_height", None, 1390), ("item_gap", None, 1391)],
    },
    row(MacosTahoe, "status_bar", NONE, &[1414, 1415], "(none): no window status bar"),
    row(MacosTahoe, "list", NONE, &[1433, 1434], "macOS 26 ❓")
        .with(&[("row_height", Some(24.0), 1431), ("header_height", Some(28.0), 1432)]),
    row(MacosTahoe, "popover", NONE, &[1461, 1462], "(none)"),
    row(MacosTahoe, "dialog", NONE, &[1556, 1557], "macOS 26 ❓"),
    row(MacosTahoe, "combo_box", [Some(4.0), None, Some(4.0), Some(12.0)], &[1618, 1623], "macOS 26: 12 left, the arrow on the right; 4 top / 4 bottom (API)")
        .with(&[("arrow_area_width", None, 1620)]),
    row(MacosTahoe, "segmented_control", NONE, &[1640, 1645], "macOS 26 ❓"),
    row(MacosTahoe, "card", all(5.0), &[1662, 1663], "macOS 26: the same 5, inferred from the unversioned page"),
    row(MacosTahoe, "expander", NONE, &[1677, 1678], "(none), app-defined")
        .with(&[("arrow_gap", None, 1684), ("content_indent", None, 1685)]),
    // --- Windows (windows-11; the reader states no sizes) ---
    row(Windows11, "window", NONE, &[1170, 1171], "pointer to §2.20 layout margins"),
    row(Windows11, "button", trbl(5.0, 11.0, 6.0, 11.0), &[1184, 1185], "11; 5 top / 6 bottom"),
    row(Windows11, "input", trbl(5.0, 6.0, 6.0, 10.0), &[1213, 1214], "10 left / 6 right; 5 top / 6 bottom"),
    row(Windows11, "text_area", trbl(5.0, 6.0, 6.0, 10.0), &[1714, 1715], "the same TextBox: TextControlThemePadding=10,5,6,6"),
    row(Windows11, "checkbox", NONE, &[1237, 1238], "(none)"),
    row(Windows11, "menu", trbl(4.0, 11.0, 5.0, 11.0), &[1261, 1262], "11; mouse context 4 top / 5 bottom")
        .with(&[("row_height", None, 1260)]),
    row(Windows11, "tooltip", trbl(6.0, 9.0, 8.0, 9.0), &[1283, 1284], "ToolTipBorderPadding=9,6,9,8"),
    row(Windows11, "progress_bar", all(0.0), &[1341, 1342], "Control.Padding's default 0; 0"),
    row(Windows11, "tab", axes(3.0, 8.0), &[1352, 1353], "without-close-button context: TabViewItemHeaderPaddingWithoutCloseButton=8,3,8,3")
        .with(&[("item_gap", Some(0.0), 1360)]),
    row(Windows11, "sidebar", [None, Some(3.0), None, Some(3.0)], &[1380, 1381], "(derived) 3 across, -1 + 4; the vertical ❓, no one value"),
    Row {
        preset: Windows11,
        widget: "toolbar",
        padding: trbl(0.0, 0.0, 0.0, 4.0),
        lines: &[1392, 1393],
        note: "Padding=\"4,0,0,0\"",
        extra: &[("bar_height", Some(48.0), 1390), ("item_gap", Some(0.0), 1391)],
    },
    row(Windows11, "status_bar", NONE, &[1414, 1415], "(none): not specified"),
    row(Windows11, "list", trbl(0.0, 12.0, 0.0, 16.0), &[1433, 1434], "Padding=16,0,12,0")
        .with(&[("row_height", Some(40.0), 1431), ("header_height", None, 1432)]),
    row(Windows11, "popover", trbl(15.0, 16.0, 17.0, 16.0), &[1461, 1462], "FlyoutContentPadding=16,15,16,17"),
    row(Windows11, "dialog", all(24.0), &[1556, 1557], "ContentDialogPadding=24"),
    row(Windows11, "combo_box", trbl(5.0, 0.0, 7.0, 12.0), &[1618, 1623], "ComboBoxPadding=12,5,0,7: 0 right, to the 38px arrow column")
        .with(&[("arrow_area_width", Some(38.0), 1620)]),
    row(Windows11, "segmented_control", [Some(5.0), Some(11.0), Some(6.0), Some(11.0)], &[1640, 1645], "Toolkit Segmented: the item content's 11,0,11,0 margin, the label's 0,5,0,6"),
    row(Windows11, "card", all(12.0), &[1662, 1663], "12 (convention)"),
    row(Windows11, "expander", trbl(0.0, 0.0, 0.0, 16.0), &[1677, 1678], "header context: ExpanderHeaderPadding=16,0,0,0")
        .with(&[("arrow_gap", Some(30.0), 1684), ("content_indent", Some(16.0), 1685)]),
    // --- Material (material-3; no reader) ---
    row(Material3, "window", NONE, &[1170, 1171], "(none): M3 has no window chrome"),
    row(Material3, "button", axes(10.0, 24.0), &[1184, 1185], "material-web leading/trailing-space 24; its padding-block (40 − 20) / 2 = 10"),
    row(Material3, "input", all(15.0), &[1213, 1214], "outlined field 16 from the edge, less the 1 outline; the same down"),
    row(Material3, "text_area", all(15.0), &[1714, 1715], "the outlined field's 16 less the 1 outline; the same down"),
    row(Material3, "checkbox", NONE, &[1237, 1238], "(none): the mark fills the box"),
    row(Material3, "menu", [None, Some(16.0), None, Some(16.0)], &[1261, 1262], "16 (md-menu-item); vertical left to the row height: the cell's 14 is (derived), material-web's item 12, latest 8")
        .with(&[("row_height", Some(48.0), 1260)]),
    row(Material3, "tooltip", axes(4.0, 8.0), &[1283, 1284], "Compose PlainTooltipHorizontalPadding 8; PlainTooltipVerticalPadding 4"),
    row(Material3, "progress_bar", NONE, &[1329], "§2.10's padding rows give 0, which the preset does not state yet (docs/todo.md, *Presets: values the M8 T15 platform-facts rows disagree with*)"),
    row(Material3, "tab", [None, Some(16.0), None, Some(16.0)], &[1352, 1353], "material-web padding: 0 16px; vertical (derived) from the fixed height, not stated")
        .with(&[("item_gap", None, 1360)]),
    row(Material3, "sidebar", [None, Some(12.0), None, Some(12.0)], &[1380, 1381], "Compose NavigationDrawerItemDefaults.ItemPadding horizontal 12; the vertical app-defined, not stated"),
    Row {
        preset: Material3,
        widget: "toolbar",
        padding: NONE,
        lines: &[1392, 1393],
        note: "v0_192 has no app-bar space token (latest's 4 not taken); none",
        extra: &[("bar_height", Some(64.0), 1390), ("item_gap", None, 1391)],
    },
    row(Material3, "status_bar", NONE, &[1414, 1415], "(none): M3 has no status bar"),
    row(Material3, "list", [None, Some(16.0), None, Some(16.0)], &[1433, 1434], "list-item-leading/trailing-space 16; vertical 12 (list item) or 10 (latest), a list or a data table: not stated")
        .with(&[("row_height", None, 1431), ("header_height", Some(56.0), 1432)]),
    row(Material3, "popover", axes(8.0, 0.0), &[1461, 1462], "the menu container pads 8 top and bottom, 0 at the sides"),
    row(Material3, "dialog", all(24.0), &[1556, 1557], "material-web dialog 24; 24 top / 24 bottom"),
    row(Material3, "combo_box", trbl(15.0, 11.0, 15.0, 15.0), &[1618, 1623], "outlined field 16 leading / 12 trailing (the arrow's trailing space), 16 down, each less the 1 outline")
        .with(&[("arrow_area_width", None, 1620)]),
    row(Material3, "segmented_control", [None, Some(12.0), None, Some(12.0)], &[1640, 1645], "material-web labs spacing-leading/trailing 12; vertical (derived), not stated"),
    row(Material3, "card", NONE, &[1662, 1663], "(app-defined)"),
    row(Material3, "expander", NONE, &[1677, 1678], "(none): M3 has no expander")
        .with(&[("arrow_gap", None, 1684), ("content_indent", None, 1685)]),
];

/// Every widget whose border carries padding.
const WIDGETS: [&str; 19] = [
    "window",
    "button",
    "input",
    "text_area",
    "checkbox",
    "menu",
    "tooltip",
    "progress_bar",
    "tab",
    "sidebar",
    "toolbar",
    "status_bar",
    "list",
    "popover",
    "dialog",
    "combo_box",
    "segmented_control",
    "card",
    "expander",
];

/// The platform-facts section each widget's rows live in.
fn section(widget: &str) -> &'static str {
    match widget {
        "window" => "2.2",
        "button" => "2.3",
        "input" => "2.4",
        "text_area" => "2.29",
        "checkbox" => "2.5",
        "menu" => "2.6",
        "tooltip" => "2.7",
        "progress_bar" => "2.10",
        "tab" => "2.11",
        "sidebar" => "2.12",
        "toolbar" => "2.13",
        "status_bar" => "2.14",
        "list" => "2.15",
        "popover" => "2.16",
        "dialog" => "2.22",
        "combo_box" => "2.24",
        "segmented_control" => "2.25",
        "card" => "2.26",
        "expander" => "2.27",
        _ => "",
    }
}

fn padding(theme: &ResolvedTheme, widget: &str) -> Option<ResolvedPadding> {
    let border = match widget {
        "window" => &theme.window.border,
        "button" => &theme.button.border,
        "input" => &theme.input.border,
        "text_area" => &theme.text_area.border,
        "checkbox" => &theme.checkbox.border,
        "menu" => &theme.menu.border,
        "tooltip" => &theme.tooltip.border,
        "progress_bar" => &theme.progress_bar.border,
        "tab" => &theme.tab.border,
        "sidebar" => &theme.sidebar.border,
        "toolbar" => &theme.toolbar.border,
        "status_bar" => &theme.status_bar.border,
        "list" => &theme.list.border,
        "popover" => &theme.popover.border,
        "dialog" => &theme.dialog.border,
        "combo_box" => &theme.combo_box.border,
        "segmented_control" => &theme.segmented_control.border,
        "card" => &theme.card.border,
        "expander" => &theme.expander.border,
        _ => return None,
    };
    Some(border.padding)
}

/// The in-scope sizing keys a preset states for one widget, unresolved: the
/// four padding sides, and the widget's further fields (`bar_height` and
/// `item_gap` for the toolbar, `item_gap` for the tab bar, `row_height` for
/// the menu and the list, `header_height` for the list, `arrow_gap` and
/// `content_indent` for the expander, `arrow_area_width` for the combobox).
fn stated_sizes(v: &ThemeMode, widget: &str) -> Option<Vec<(&'static str, Option<f32>)>> {
    let border = match widget {
        "window" => &v.window.border,
        "button" => &v.button.border,
        "input" => &v.input.border,
        "text_area" => &v.text_area.border,
        "checkbox" => &v.checkbox.border,
        "menu" => &v.menu.border,
        "tooltip" => &v.tooltip.border,
        "progress_bar" => &v.progress_bar.border,
        "tab" => &v.tab.border,
        "sidebar" => &v.sidebar.border,
        "toolbar" => &v.toolbar.border,
        "status_bar" => &v.status_bar.border,
        "list" => &v.list.border,
        "popover" => &v.popover.border,
        "dialog" => &v.dialog.border,
        "combo_box" => &v.combo_box.border,
        "segmented_control" => &v.segmented_control.border,
        "card" => &v.card.border,
        "expander" => &v.expander.border,
        _ => return None,
    };
    let side =
        |f: fn(&crate::model::border::WidgetBorderSpec) -> Option<f32>| border.as_ref().and_then(f);
    let mut sizes = vec![
        ("border.padding_top", side(|b| b.padding_top)),
        ("border.padding_right", side(|b| b.padding_right)),
        ("border.padding_bottom", side(|b| b.padding_bottom)),
        ("border.padding_left", side(|b| b.padding_left)),
    ];
    match widget {
        "toolbar" => {
            sizes.push(("bar_height", v.toolbar.bar_height));
            sizes.push(("item_gap", v.toolbar.item_gap));
        }
        "tab" => sizes.push(("item_gap", v.tab.item_gap)),
        "expander" => {
            sizes.push(("arrow_gap", v.expander.arrow_gap));
            sizes.push(("content_indent", v.expander.content_indent));
        }
        "menu" => sizes.push(("row_height", v.menu.row_height)),
        "list" => {
            sizes.push(("row_height", v.list.row_height));
            sizes.push(("header_height", v.list.header_height));
        }
        "combo_box" => sizes.push(("arrow_area_width", v.combo_box.arrow_area_width)),
        _ => {}
    }
    Some(sizes)
}

/// A row's further field, resolved.
fn extra_field(theme: &ResolvedTheme, widget: &str, field: &str) -> Option<Option<f32>> {
    match (widget, field) {
        ("toolbar", "bar_height") => Some(theme.toolbar.bar_height),
        ("toolbar", "item_gap") => Some(theme.toolbar.item_gap),
        ("tab", "item_gap") => Some(theme.tab.item_gap),
        ("expander", "arrow_gap") => Some(theme.expander.arrow_gap),
        ("expander", "content_indent") => Some(theme.expander.content_indent),
        ("menu", "row_height") => Some(theme.menu.row_height),
        ("list", "row_height") => Some(theme.list.row_height),
        ("list", "header_height") => Some(theme.list.header_height),
        ("combo_box", "arrow_area_width") => Some(theme.combo_box.arrow_area_width),
        _ => None,
    }
}

fn resolve(variant: ThemeMode) -> Result<ResolvedTheme, String> {
    variant
        .into_resolved(&ResolutionContext::for_tests())
        .map_err(|e| format!("resolution failed: {e}"))
}

/// The static resolution's input: the full preset, unresolved.
fn static_variant(preset: NativePreset, mode: ColorMode) -> Result<ThemeMode, String> {
    let full = Theme::preset(preset.key()).map_err(|e| e.to_string())?;
    full.into_variant(mode).map_err(|e| e.to_string())
}

/// The live resolution's input, unresolved: the full preset with the
/// reader's size constants merged over it.
fn live_variant(preset: NativePreset, mode: ColorMode) -> Result<ThemeMode, String> {
    let mut variant = static_variant(preset, mode)?;
    if let Some(reader) = preset.reader_constants() {
        variant.merge(&reader);
    }
    Ok(variant)
}

fn gate_variant(preset: NativePreset, mode: ColorMode, live: bool) -> Result<ThemeMode, String> {
    if live {
        live_variant(preset, mode)
    } else {
        static_variant(preset, mode)
    }
}

fn source(preset: NativePreset, live: bool) -> String {
    if live {
        format!("{} + reader constants", preset.key())
    } else {
        preset.key().to_string()
    }
}

/// Line `n` (1-based) of platform-facts.md, or "" past its end.
fn facts_line(n: usize) -> &'static str {
    PLATFORM_FACTS.lines().nth(n.wrapping_sub(1)).unwrap_or("")
}

/// The `### 2.` section heading line `n` of platform-facts.md sits under.
fn facts_heading(n: usize) -> &'static str {
    PLATFORM_FACTS
        .lines()
        .take(n)
        .filter(|l| l.starts_with("### 2."))
        .last()
        .unwrap_or("")
}

fn cite(lines: &[usize]) -> String {
    let lines: Vec<String> = lines.iter().map(|l| format!(":{l}")).collect();
    format!("docs/platform-facts.md{}", lines.join(", "))
}

#[test]
fn native_themes_state_documented_sizes() {
    let mut failures = Vec::new();
    for preset in NativePreset::ALL {
        for (mode, variant) in [(ColorMode::Light, "light"), (ColorMode::Dark, "dark")] {
            for &live in preset.resolutions() {
                let theme = match gate_variant(preset, mode, live).and_then(resolve) {
                    Ok(t) => t,
                    Err(e) => {
                        failures.push(format!("{} {variant}: {e}", source(preset, live)));
                        continue;
                    }
                };
                for row in ROWS.iter().filter(|r| r.preset == preset) {
                    let Some(got) = padding(&theme, row.widget) else {
                        failures.push(format!("unknown widget `{}`", row.widget));
                        continue;
                    };
                    let got = [got.top, got.right, got.bottom, got.left];
                    for (i, side) in ["top", "right", "bottom", "left"].iter().enumerate() {
                        if got[i] != row.padding[i] {
                            failures.push(format!(
                                "{}.border.padding_{side}: {} {variant}: resolved {:?}, \
                                 platform-facts gives {:?} ({}; {})",
                                row.widget,
                                source(preset, live),
                                got[i],
                                row.padding[i],
                                cite(row.lines),
                                row.note,
                            ));
                        }
                    }
                    for &(field, expected, line) in row.extra {
                        let got = extra_field(&theme, row.widget, field);
                        if got != Some(expected) {
                            failures.push(format!(
                                "{}.{field}: {} {variant}: resolved {:?}, \
                                 platform-facts gives {expected:?} ({})",
                                row.widget,
                                source(preset, live),
                                got.flatten(),
                                cite(&[line]),
                            ));
                        }
                    }
                }
            }
        }
    }
    assert!(
        failures.is_empty(),
        "{} documented-size mismatches:\n{}",
        failures.len(),
        failures.join("\n")
    );
}

#[test]
fn every_preset_and_widget_has_one_row() {
    for preset in NativePreset::ALL {
        for widget in WIDGETS {
            let n = ROWS
                .iter()
                .filter(|r| r.preset == preset && r.widget == widget)
                .count();
            assert_eq!(n, 1, "{preset:?} {widget}: {n} rows");
        }
    }
    assert_eq!(ROWS.len(), NativePreset::ALL.len() * WIDGETS.len());
}

/// Each cited line is the row it claims to be, inside the widget's section:
/// a padding row, the section heading where a section has no padding row,
/// or the named toolbar field.
#[test]
fn every_citation_names_its_platform_facts_row() {
    for row in ROWS {
        let title = format!("### {} ", section(row.widget));
        let extra_lines = row.extra.iter().map(|&(_, _, n)| n);
        for n in row.lines.iter().copied().chain(extra_lines) {
            assert!(
                facts_heading(n).starts_with(&title),
                "{:?} {}: platform-facts.md:{n} is outside §{}",
                row.preset,
                row.widget,
                section(row.widget),
            );
        }
        for &n in row.lines {
            let text = facts_line(n);
            assert!(
                text.starts_with("| `border.padding_") || text.starts_with(&title),
                "{:?} {}: platform-facts.md:{n} is neither a padding row nor the \
                 section heading: {text:?}",
                row.preset,
                row.widget,
            );
        }
        for &(field, _, n) in row.extra {
            let text = facts_line(n);
            assert!(
                text.starts_with(&format!("| `{field}`")),
                "{:?} {}.{field}: platform-facts.md:{n} is not the `{field}` row: {text:?}",
                row.preset,
                row.widget,
            );
        }
    }
}

/// Presets that platform-facts does not cover: the colour schemes, and the
/// `ios-13` platform preset, which no platform-facts column documents.
const UNSOURCED_PRESETS: [&str; 11] = [
    "catppuccin-latte",
    "catppuccin-frappe",
    "catppuccin-macchiato",
    "catppuccin-mocha",
    "dracula",
    "gruvbox",
    "nord",
    "one-dark",
    "solarized",
    "tokyo-night",
    "ios-13",
];

/// Every bundled preset is a `NativePreset` with rows or an unsourced preset,
/// so no preset escapes the gates that iterate those two lists.
#[test]
fn every_bundled_preset_is_native_or_unsourced() {
    let mut gated: Vec<&str> = NativePreset::ALL
        .iter()
        .map(|p| p.key())
        .chain(UNSOURCED_PRESETS)
        .collect();
    gated.sort_unstable();
    let mut bundled: Vec<&str> = crate::presets::list_presets()
        .iter()
        .map(|info| info.key)
        .collect();
    bundled.sort_unstable();
    assert_eq!(gated, bundled);
}

/// The second table's sizes the model leaves optional: a preset that states
/// one without a source overrides the toolkit's own.
const OPTIONAL_FIELDS: [&str; 6] = [
    "checkbox.radio_dot_diameter",
    "checkbox.check_mark_stroke_width",
    "checkbox.radio_indicator_width",
    "switch.unchecked_thumb_diameter",
    "tab.active_indicator_width",
    "tab.active_outward_corner_radius",
];

/// A preset platform-facts does not cover cites no source for a size, so it
/// states no padding side, `row_height`, `header_height`, `bar_height`,
/// `item_gap`, `arrow_gap`, `content_indent` or `arrow_area_width`, and none
/// of [`OPTIONAL_FIELDS`], and the toolkit's own sizes stand.
#[test]
fn unsourced_presets_state_no_gated_size() {
    let mut failures = Vec::new();
    for name in UNSOURCED_PRESETS {
        for mode in [ColorMode::Light, ColorMode::Dark] {
            let variant = match Theme::preset(name).and_then(|t| t.into_variant(mode)) {
                Ok(v) => v,
                Err(e) => {
                    failures.push(format!("{name} {mode:?}: {e}"));
                    continue;
                }
            };
            for widget in WIDGETS {
                let Some(sizes) = stated_sizes(&variant, widget) else {
                    failures.push(format!("unknown widget `{widget}`"));
                    continue;
                };
                for (key, value) in sizes {
                    if let Some(value) = value {
                        failures.push(format!(
                            "{name} {mode:?}: states {widget}.{key} = {value}, with no source"
                        ));
                    }
                }
            }
            for field in OPTIONAL_FIELDS {
                match states_field(&variant, field) {
                    Some(false) => {}
                    Some(true) => {
                        failures.push(format!("{name} {mode:?}: states {field}, with no source"));
                    }
                    None => failures.push(format!("unknown field `{field}`")),
                }
            }
        }
    }
    assert!(
        failures.is_empty(),
        "{} unsourced sizes:\n{}",
        failures.len(),
        failures.join("\n")
    );
}

/// What platform-facts gives for one number.
#[derive(Clone, Copy, Debug)]
enum Want {
    /// A font size in points, resolved to logical pixels at the gate's 96 dpi.
    Pt(f32),
    /// A size in logical pixels (Windows' effective pixels).
    Px(f32),
    /// The resolved body font's size times a factor (Kirigami's heading levels).
    BodyTimes(f32),
    /// A CSS font weight.
    Weight(u16),
    /// The cell leaves it to inheritance ("← `defaults.font`", "(none)"): the
    /// merged variant states nothing and the resolver fills it.
    Unstated,
}

struct FieldRow {
    preset: NativePreset,
    /// `text_scale.<role>.size` / `.weight`, `dialog.title_font.size` /
    /// `.weight`, `slider.track_height`, `slider.thumb_diameter`,
    /// `progress_bar.track_height`, `checkbox.radio_dot_diameter`,
    /// `checkbox.check_mark_stroke_width`, `checkbox.radio_indicator_width`,
    /// `switch.unchecked_thumb_diameter`, `tab.active_indicator_width` or
    /// `tab.active_outward_corner_radius`.
    field: &'static str,
    want: Want,
    /// The platform-facts.md line of the cell.
    line: usize,
    /// How the cell was read.
    note: &'static str,
}

const fn field(
    preset: NativePreset,
    field: &'static str,
    want: Want,
    line: usize,
    note: &'static str,
) -> FieldRow {
    FieldRow {
        preset,
        field,
        want,
        line,
        note,
    }
}

use Want::{BodyTimes, Pt, Px, Unstated, Weight};

#[rustfmt::skip]
const FIELD_ROWS: &[FieldRow] = &[
    // --- KDE ---
    field(KdeBreeze, "text_scale.caption.size", Pt(8.0), 1485, "smallestReadableFont; its default is 8pt (:573)"),
    field(KdeBreeze, "text_scale.caption.weight", Weight(400), 1485, "smallestReadableFont; its default is 400 (:573)"),
    field(KdeBreeze, "text_scale.section_heading.size", BodyTimes(1.20), 1486, "Kirigami Heading level 2: body × 1.20"),
    field(KdeBreeze, "text_scale.section_heading.weight", Weight(400), 1486, "Font.Normal unless type: Primary"),
    field(KdeBreeze, "text_scale.dialog_title.size", BodyTimes(1.35), 1487, "Kirigami Heading level 1: body × 1.35"),
    field(KdeBreeze, "text_scale.dialog_title.weight", Weight(400), 1487, "Font.Normal unless type: Primary"),
    field(KdeBreeze, "text_scale.display.size", Unstated, 1488, "(none): resolves from the body font"),
    field(KdeBreeze, "text_scale.display.weight", Unstated, 1488, "(none): resolves from the body font"),
    field(KdeBreeze, "dialog.title_font.size", Unstated, 1561, "← defaults.font"),
    field(KdeBreeze, "dialog.title_font.weight", Unstated, 1562, "← defaults.font"),
    field(KdeBreeze, "slider.track_height", Px(6.0), 1320, "Slider_GrooveThickness = 6"),
    field(KdeBreeze, "slider.thumb_diameter", Px(20.0), 1321, "Slider_ControlThickness = 20"),
    field(KdeBreeze, "progress_bar.track_height", Px(6.0), 1335, "ProgressBar_Thickness = 6"),
    field(KdeBreeze, "checkbox.radio_dot_diameter", Px(6.0), 1241, "renderRadioButton: radius (18 - 12) / 2 = 3"),
    field(KdeBreeze, "checkbox.check_mark_stroke_width", Px(2.0), 1242, "the check pen: PenWidth::Frame * 2 = 2.002"),
    field(KdeBreeze, "checkbox.radio_indicator_width", Unstated, 1243, "← indicator_width: CheckBox_Size for both"),
    field(KdeBreeze, "switch.unchecked_thumb_diameter", Unstated, 1525, "← thumb_diameter: one handle in both states"),
    field(KdeBreeze, "tab.active_indicator_width", Px(3.0), 1362, "TabBar_ActiveEffectSize = 3"),
    field(KdeBreeze, "tab.active_outward_corner_radius", Unstated, 1366, "(none): CornersTop"),
    // --- GNOME ---
    field(Adwaita, "text_scale.caption.size", Pt(9.0), 1485, ".caption: ≈9pt"),
    field(Adwaita, "text_scale.caption.weight", Weight(400), 1485, ".caption: 400"),
    field(Adwaita, "text_scale.section_heading.size", Pt(11.0), 1486, ".heading: 11pt"),
    field(Adwaita, "text_scale.section_heading.weight", Weight(700), 1486, ".heading: 700"),
    field(Adwaita, "text_scale.dialog_title.size", Pt(15.0), 1487, ".title-2: ≈15pt"),
    field(Adwaita, "text_scale.dialog_title.weight", Weight(800), 1487, ".title-2: 800"),
    field(Adwaita, "text_scale.display.size", Pt(20.0), 1488, ".title-1: ≈20pt"),
    field(Adwaita, "text_scale.display.weight", Weight(800), 1488, ".title-1: 800"),
    field(Adwaita, "dialog.title_font.size", Pt(15.0), 1561, "136% of base ≈15pt (.title-2)"),
    field(Adwaita, "dialog.title_font.weight", Weight(800), 1562, "800 (.title-2)"),
    field(Adwaita, "slider.track_height", Px(10.0), 1320, "libadwaita .scale: 10"),
    field(Adwaita, "slider.thumb_diameter", Px(20.0), 1321, "libadwaita: 20"),
    field(Adwaita, "progress_bar.track_height", Px(8.0), 1335, "libadwaita .progressbar: 8"),
    field(Adwaita, "checkbox.radio_dot_diameter", Px(8.0), 1241, "bullet.svg: a circle of radius 4"),
    field(Adwaita, "checkbox.check_mark_stroke_width", Px(2.0), 1242, "check.svg (1.10.0): a stroke 2 wide"),
    field(Adwaita, "checkbox.radio_indicator_width", Unstated, 1243, "← indicator_width: one check, radio rule"),
    field(Adwaita, "switch.unchecked_thumb_diameter", Unstated, 1525, "← thumb_diameter: one slider rule"),
    field(Adwaita, "tab.active_indicator_width", Px(4.0), 1362, "_notebook.scss: inset 0 -4px"),
    field(Adwaita, "tab.active_outward_corner_radius", Unstated, 1366, "(none): a square notebook tab"),
    // --- macOS ---
    field(MacosMonterey, "text_scale.caption.size", Pt(10.0), 1485, ".caption1: 10pt"),
    field(MacosMonterey, "text_scale.caption.weight", Weight(400), 1485, ".caption1: 400"),
    field(MacosMonterey, "text_scale.section_heading.size", Pt(13.0), 1486, ".headline: 13pt"),
    field(MacosMonterey, "text_scale.section_heading.weight", Weight(700), 1486, ".headline: 700"),
    field(MacosMonterey, "text_scale.dialog_title.size", Pt(22.0), 1487, ".title1: 22pt"),
    field(MacosMonterey, "text_scale.dialog_title.weight", Weight(400), 1487, ".title1: 400"),
    field(MacosMonterey, "text_scale.display.size", Pt(26.0), 1488, ".largeTitle: 26pt"),
    field(MacosMonterey, "text_scale.display.weight", Weight(400), 1488, ".largeTitle: 400"),
    field(MacosMonterey, "dialog.title_font.size", Pt(13.0), 1561, "emphasized system font: systemFontSize, 13pt"),
    field(MacosMonterey, "dialog.title_font.weight", Weight(700), 1562, "emphasized system font: Bold (700)"),
    field(MacosMonterey, "slider.track_height", Px(4.0), 1320, "macOS 14-15: NSSlider 4 (API)"),
    field(MacosMonterey, "slider.thumb_diameter", Px(20.0), 1321, "NSSlider knob: 20 (measured, the macOS 14.8.9 probe)"),
    field(MacosMonterey, "progress_bar.track_height", Px(6.0), 1335, "NSProgressIndicator: 6"),
    field(MacosMonterey, "checkbox.radio_dot_diameter", Px(6.0), 1241, "macOS 14-15: 6 (measured, the probe's radio render)"),
    field(MacosMonterey, "checkbox.check_mark_stroke_width", Unstated, 1242, "(none): not published"),
    field(MacosMonterey, "checkbox.radio_indicator_width", Unstated, 1243, "← indicator_width: not published"),
    field(MacosMonterey, "switch.unchecked_thumb_diameter", Unstated, 1525, "← thumb_diameter: not published"),
    field(MacosMonterey, "tab.active_indicator_width", Unstated, 1362, "(none): no line"),
    field(MacosMonterey, "tab.active_outward_corner_radius", Unstated, 1366, "❓: the bezel's shape is unpublished"),
    // --- macOS 26 ---
    field(MacosTahoe, "text_scale.caption.size", Pt(10.0), 1485, ".caption1: 10pt, the same on 26"),
    field(MacosTahoe, "text_scale.caption.weight", Weight(400), 1485, ".caption1: 400"),
    field(MacosTahoe, "text_scale.section_heading.size", Pt(13.0), 1486, ".headline: 13pt"),
    field(MacosTahoe, "text_scale.section_heading.weight", Weight(700), 1486, ".headline: 700"),
    field(MacosTahoe, "text_scale.dialog_title.size", Pt(22.0), 1487, ".title1: 22pt"),
    field(MacosTahoe, "text_scale.dialog_title.weight", Weight(400), 1487, ".title1: 400"),
    field(MacosTahoe, "text_scale.display.size", Pt(26.0), 1488, ".largeTitle: 26pt"),
    field(MacosTahoe, "text_scale.display.weight", Weight(400), 1488, ".largeTitle: 400"),
    field(MacosTahoe, "dialog.title_font.size", Pt(13.0), 1561, "macOS 26 ❓: macos-monterey's 13pt, carried"),
    field(MacosTahoe, "dialog.title_font.weight", Weight(700), 1562, "macOS 26 ❓: macos-monterey's Bold (700), carried"),
    field(MacosTahoe, "slider.track_height", Px(6.0), 1320, "macOS 26: 6 (API)"),
    field(MacosTahoe, "slider.thumb_diameter", Px(16.0), 1321, "macOS 26: the 20 x 16 capsule, 16 across the track"),
    field(MacosTahoe, "progress_bar.track_height", Px(8.0), 1335, "macOS 26: 8 (measured)"),
    field(MacosTahoe, "checkbox.radio_dot_diameter", Px(5.0), 1241, "macOS 26: 5 (measured, the probe's radio render)"),
    field(MacosTahoe, "checkbox.check_mark_stroke_width", Unstated, 1242, "(none): not published"),
    field(MacosTahoe, "checkbox.radio_indicator_width", Unstated, 1243, "← indicator_width: not published"),
    field(MacosTahoe, "switch.unchecked_thumb_diameter", Unstated, 1525, "← thumb_diameter: not published"),
    field(MacosTahoe, "tab.active_indicator_width", Unstated, 1362, "(none): no line"),
    field(MacosTahoe, "tab.active_outward_corner_radius", Unstated, 1366, "❓: the bezel's shape is unpublished"),
    // --- Windows ---
    // The presets state the type ramp and title in points, each epx × 72/96
    // (Caption 9pt, Subtitle 15, Title 21, Display 51, dialog title 15). The
    // Windows reader's font_dpi is 96 (`windows::LOGICAL_DPI`), as is the
    // gate's, so they resolve to the epx below at any display scale.
    field(Windows11, "text_scale.caption.size", Px(12.0), 1485, "Caption: 12epx"),
    field(Windows11, "text_scale.caption.weight", Weight(400), 1485, "Caption: 400"),
    field(Windows11, "text_scale.section_heading.size", Px(20.0), 1486, "Subtitle: 20epx"),
    field(Windows11, "text_scale.section_heading.weight", Weight(600), 1486, "Subtitle: 600"),
    field(Windows11, "text_scale.dialog_title.size", Px(28.0), 1487, "Title: 28epx"),
    field(Windows11, "text_scale.dialog_title.weight", Weight(600), 1487, "Title: 600"),
    field(Windows11, "text_scale.display.size", Px(68.0), 1488, "Display: 68epx"),
    field(Windows11, "text_scale.display.weight", Weight(600), 1488, "Display: 600"),
    field(Windows11, "dialog.title_font.size", Px(20.0), 1561, "20px (ContentDialog template)"),
    field(Windows11, "dialog.title_font.weight", Weight(600), 1562, "SemiBold (600)"),
    field(Windows11, "slider.track_height", Px(4.0), 1320, "WinUI3: 4"),
    field(Windows11, "slider.thumb_diameter", Px(18.0), 1321, "WinUI3: 18"),
    field(Windows11, "progress_bar.track_height", Px(1.0), 1335, "the groove, ProgressBarTrackHeight: 1"),
    field(Windows11, "checkbox.radio_dot_diameter", Px(12.0), 1241, "RadioButtonCheckGlyphSize: 12"),
    field(Windows11, "checkbox.check_mark_stroke_width", Unstated, 1242, "(none): a font glyph"),
    field(Windows11, "checkbox.radio_indicator_width", Unstated, 1243, "← indicator_width: OuterEllipse 20 as CheckBoxSize 20"),
    field(Windows11, "switch.unchecked_thumb_diameter", Unstated, 1525, "← thumb_diameter: SwitchKnobOff 12 as SwitchKnobOn 12"),
    field(Windows11, "tab.active_indicator_width", Unstated, 1362, "(none): no line"),
    field(Windows11, "tab.active_outward_corner_radius", Px(4.0), 1366, "TabViewItem.cpp:106: 4px curving-out corners"),
    // --- Material (dp = logical pixels, rem × 16) ---
    field(Material3, "text_scale.caption.size", Px(12.0), 1485, "body-small: 12"),
    field(Material3, "text_scale.caption.weight", Weight(400), 1485, "body-small: 400"),
    field(Material3, "text_scale.section_heading.size", Px(16.0), 1486, "title-medium: 16"),
    field(Material3, "text_scale.section_heading.weight", Weight(500), 1486, "title-medium: 500"),
    field(Material3, "text_scale.dialog_title.size", Px(24.0), 1487, "headline-small: 24"),
    field(Material3, "text_scale.dialog_title.weight", Weight(400), 1487, "headline-small: 400"),
    field(Material3, "text_scale.display.size", Px(36.0), 1488, "display-small: 36"),
    field(Material3, "text_scale.display.weight", Weight(400), 1488, "display-small: 400"),
    field(Material3, "dialog.title_font.size", Px(24.0), 1561, "comp.dialog headline-size: 24"),
    field(Material3, "dialog.title_font.weight", Weight(400), 1562, "headline-small-weight: 400"),
    field(Material3, "slider.track_height", Px(4.0), 1320, "active/inactive-track-height: 4"),
    field(Material3, "slider.thumb_diameter", Px(20.0), 1321, "handle-width/height: 20"),
    field(Material3, "progress_bar.track_height", Px(4.0), 1335, "linear track-height: 4"),
    field(Material3, "checkbox.radio_dot_diameter", Px(10.0), 1241, "material-web radio.ts: inner circle r = 5"),
    field(Material3, "checkbox.check_mark_stroke_width", Px(2.0), 1242, "material-web $_mark-stroke: 2px"),
    field(Material3, "checkbox.radio_indicator_width", Px(20.0), 1243, "comp.radio-button icon-size: 20"),
    field(Material3, "switch.unchecked_thumb_diameter", Px(16.0), 1525, "unselected-handle-width/height: 16"),
    field(Material3, "tab.active_indicator_width", Px(3.0), 1362, "active-indicator-height: 3"),
    field(Material3, "tab.active_outward_corner_radius", Unstated, 1366, "(none): corner-none"),
];

/// Every field a [`FieldRow`] may name.
const FIELDS: [&str; 19] = [
    "text_scale.caption.size",
    "text_scale.caption.weight",
    "text_scale.section_heading.size",
    "text_scale.section_heading.weight",
    "text_scale.dialog_title.size",
    "text_scale.dialog_title.weight",
    "text_scale.display.size",
    "text_scale.display.weight",
    "dialog.title_font.size",
    "dialog.title_font.weight",
    "slider.track_height",
    "slider.thumb_diameter",
    "progress_bar.track_height",
    "checkbox.radio_dot_diameter",
    "checkbox.check_mark_stroke_width",
    "checkbox.radio_indicator_width",
    "switch.unchecked_thumb_diameter",
    "tab.active_indicator_width",
    "tab.active_outward_corner_radius",
];

/// The platform-facts section and row key of a field's cell.
fn field_cell(field: &str) -> Option<(&'static str, &'static str)> {
    Some(match field {
        "text_scale.caption.size" | "text_scale.caption.weight" => ("2.19", "caption"),
        "text_scale.section_heading.size" | "text_scale.section_heading.weight" => {
            ("2.19", "section_heading")
        }
        "text_scale.dialog_title.size" | "text_scale.dialog_title.weight" => {
            ("2.19", "dialog_title")
        }
        "text_scale.display.size" | "text_scale.display.weight" => ("2.19", "display"),
        "dialog.title_font.size" => ("2.22", "title_font.size"),
        "dialog.title_font.weight" => ("2.22", "title_font.weight"),
        "slider.track_height" => ("2.9", "track_height"),
        "slider.thumb_diameter" => ("2.9", "thumb_diameter"),
        "progress_bar.track_height" => ("2.10", "track_height"),
        "checkbox.radio_dot_diameter" => ("2.5", "radio_dot_diameter"),
        "checkbox.check_mark_stroke_width" => ("2.5", "check_mark_stroke_width"),
        "checkbox.radio_indicator_width" => ("2.5", "radio_indicator_width"),
        "switch.unchecked_thumb_diameter" => ("2.21", "unchecked_thumb_diameter"),
        "tab.active_indicator_width" => ("2.11", "active_indicator_width"),
        "tab.active_outward_corner_radius" => ("2.11", "active_outward_corner_radius"),
        _ => return None,
    })
}

fn stated_entry<'a>(v: &'a ThemeMode, role: &str) -> Option<&'a crate::TextScaleEntry> {
    match role {
        "caption" => v.text_scale.caption.as_ref(),
        "section_heading" => v.text_scale.section_heading.as_ref(),
        "dialog_title" => v.text_scale.dialog_title.as_ref(),
        "display" => v.text_scale.display.as_ref(),
        _ => None,
    }
}

/// Whether the unresolved variant states the field; `None` for an unknown field.
fn states_field(v: &ThemeMode, field: &str) -> Option<bool> {
    let title = v.dialog.title_font.as_ref();
    Some(match field {
        "dialog.title_font.size" => title.and_then(|f| f.size).is_some(),
        "dialog.title_font.weight" => title.and_then(|f| f.weight).is_some(),
        "slider.track_height" => v.slider.track_height.is_some(),
        "slider.thumb_diameter" => v.slider.thumb_diameter.is_some(),
        "progress_bar.track_height" => v.progress_bar.track_height.is_some(),
        "checkbox.radio_dot_diameter" => v.checkbox.radio_dot_diameter.is_some(),
        "checkbox.check_mark_stroke_width" => v.checkbox.check_mark_stroke_width.is_some(),
        "checkbox.radio_indicator_width" => v.checkbox.radio_indicator_width.is_some(),
        "switch.unchecked_thumb_diameter" => v.switch.unchecked_thumb_diameter.is_some(),
        "tab.active_indicator_width" => v.tab.active_indicator_width.is_some(),
        "tab.active_outward_corner_radius" => v.tab.active_outward_corner_radius.is_some(),
        _ => {
            let (role, sub) = field.strip_prefix("text_scale.")?.split_once('.')?;
            let entry = stated_entry(v, role);
            match sub {
                "size" => entry.and_then(|e| e.size).is_some(),
                "weight" => entry.and_then(|e| e.weight).is_some(),
                _ => return None,
            }
        }
    })
}

/// The field resolved: sizes in logical pixels, weights as numbers.
fn resolved_field(theme: &ResolvedTheme, field: &str) -> Option<f32> {
    let ts = &theme.text_scale;
    Some(match field {
        "text_scale.caption.size" => ts.caption.size,
        "text_scale.caption.weight" => f32::from(ts.caption.weight),
        "text_scale.section_heading.size" => ts.section_heading.size,
        "text_scale.section_heading.weight" => f32::from(ts.section_heading.weight),
        "text_scale.dialog_title.size" => ts.dialog_title.size,
        "text_scale.dialog_title.weight" => f32::from(ts.dialog_title.weight),
        "text_scale.display.size" => ts.display.size,
        "text_scale.display.weight" => f32::from(ts.display.weight),
        "dialog.title_font.size" => theme.dialog.title_font.size,
        "dialog.title_font.weight" => f32::from(theme.dialog.title_font.weight),
        "slider.track_height" => theme.slider.track_height,
        "slider.thumb_diameter" => theme.slider.thumb_diameter,
        "progress_bar.track_height" => theme.progress_bar.track_height,
        "checkbox.radio_dot_diameter" => theme.checkbox.radio_dot_diameter?,
        "checkbox.check_mark_stroke_width" => theme.checkbox.check_mark_stroke_width?,
        "checkbox.radio_indicator_width" => theme.checkbox.radio_indicator_width?,
        "switch.unchecked_thumb_diameter" => theme.switch.unchecked_thumb_diameter?,
        "tab.active_indicator_width" => theme.tab.active_indicator_width?,
        "tab.active_outward_corner_radius" => theme.tab.active_outward_corner_radius?,
        _ => return None,
    })
}

/// The gate's variants of one preset, unresolved: `(source, variant name, variant)`.
fn gate_variants(preset: NativePreset) -> Vec<Result<(String, &'static str, ThemeMode), String>> {
    let mut out = Vec::new();
    for (mode, name) in [(ColorMode::Light, "light"), (ColorMode::Dark, "dark")] {
        for &live in preset.resolutions() {
            out.push(
                gate_variant(preset, mode, live)
                    .map(|v| (source(preset, live), name, v))
                    .map_err(|e| format!("{} {name}: {e}", source(preset, live))),
            );
        }
    }
    out
}

/// The text-scale, dialog-title, slider and progress-bar numbers of the
/// native themes, static and live, against platform-facts.
#[test]
fn native_themes_state_documented_fields() {
    let mut failures = Vec::new();
    for preset in NativePreset::ALL {
        for variant in gate_variants(preset) {
            let (source, name, variant) = match variant {
                Ok(v) => v,
                Err(e) => {
                    failures.push(e);
                    continue;
                }
            };
            let theme = match resolve(variant.clone()) {
                Ok(t) => t,
                Err(e) => {
                    failures.push(format!("{source} {name}: {e}"));
                    continue;
                }
            };
            let body = theme.defaults.font.size;
            for row in FIELD_ROWS.iter().filter(|r| r.preset == preset) {
                let at = format!(
                    "{}: {source} {name} ({}; {})",
                    row.field,
                    cite(&[row.line]),
                    row.note
                );
                if let Want::Unstated = row.want {
                    match states_field(&variant, row.field) {
                        Some(false) => {}
                        Some(true) => failures.push(format!(
                            "{at}: stated, but platform-facts leaves it to inheritance"
                        )),
                        None => failures.push(format!("{at}: unknown field")),
                    }
                    continue;
                }
                let expected = match row.want {
                    Want::Pt(v) => v * ResolutionContext::for_tests().font_dpi / 72.0,
                    Want::Px(v) => v,
                    Want::BodyTimes(f) => body * f,
                    Want::Weight(w) => f32::from(w),
                    Want::Unstated => continue,
                };
                match resolved_field(&theme, row.field) {
                    Some(got) if (got - expected).abs() < 1e-3 => {}
                    Some(got) => failures.push(format!(
                        "{at}: resolved {got}, platform-facts gives {:?} = {expected}",
                        row.want
                    )),
                    None => failures.push(format!("{at}: unknown field")),
                }
            }
        }
    }
    assert!(
        failures.is_empty(),
        "{} documented-field mismatches:\n{}",
        failures.len(),
        failures.join("\n")
    );
}

/// The Windows rows state effective pixels, which the presets' points reach
/// only at the Windows reader's `font_dpi`: it is the gate's 96.
#[test]
fn windows_reader_font_dpi_is_the_gates() {
    assert_eq!(
        crate::windows::LOGICAL_DPI as f32,
        ResolutionContext::for_tests().font_dpi
    );
}

#[test]
fn every_preset_and_field_has_one_row() {
    for preset in NativePreset::ALL {
        for f in FIELDS {
            let n = FIELD_ROWS
                .iter()
                .filter(|r| r.preset == preset && r.field == f)
                .count();
            assert_eq!(n, 1, "{preset:?} {f}: {n} rows");
        }
    }
    for f in FIELDS {
        assert!(field_cell(f).is_some(), "{f}: no platform-facts cell");
    }
    assert_eq!(FIELD_ROWS.len(), NativePreset::ALL.len() * FIELDS.len());
}

/// Each field row cites its own cell's line, inside the cell's section.
#[test]
fn every_field_citation_names_its_platform_facts_row() {
    for row in FIELD_ROWS {
        let (section, key) = field_cell(row.field).unwrap_or(("?", "?"));
        assert!(
            facts_heading(row.line).starts_with(&format!("### {section} ")),
            "{:?} {}: platform-facts.md:{} is outside §{section}",
            row.preset,
            row.field,
            row.line,
        );
        let text = facts_line(row.line);
        assert!(
            text.starts_with(&format!("| `{key}`")),
            "{:?} {}: platform-facts.md:{} is not the `{key}` row: {text:?}",
            row.preset,
            row.field,
            row.line,
        );
    }
}

/// Platform-facts gives no other desktop platform's text-scale line height, so
/// no other desktop preset states one and the resolver computes it from
/// `defaults.line_height` (E5). Material's typescale states each style's line
/// height (platform-facts §2.19), and so does WinUI 3's type ramp
/// (platform-facts §1.2.1), so the material-3 and windows-11 presets state them.
#[test]
fn native_presets_state_no_text_scale_line_height() {
    let mut failures = Vec::new();
    for preset in NativePreset::ALL {
        if preset == Material3 || preset == NativePreset::Windows11 {
            continue;
        }
        let name = preset.key();
        for mode in [ColorMode::Light, ColorMode::Dark] {
            let variant = match Theme::preset(name).and_then(|t| t.into_variant(mode)) {
                Ok(v) => v,
                Err(e) => {
                    failures.push(format!("{name} {mode:?}: {e}"));
                    continue;
                }
            };
            for role in ["caption", "section_heading", "dialog_title", "display"] {
                if let Some(lh) = stated_entry(&variant, role).and_then(|e| e.line_height) {
                    failures.push(format!(
                        "{name} {mode:?}: states text_scale.{role}.line_height = {lh:?}, \
                         with no source"
                    ));
                }
            }
        }
    }
    assert!(
        failures.is_empty(),
        "{} unsourced line heights:\n{}",
        failures.len(),
        failures.join("\n")
    );
}

/// The expander's structure per platform, from platform-facts §2.27: the
/// arrow's side (`platform-facts.md:1683`) and whether a frame holds header and content
/// (`:1686`); `None` where the cell states none.
#[rustfmt::skip]
const EXPANDER_STRUCTURE: [(NativePreset, Option<crate::model::ArrowSide>, Option<bool>); 6] = [
    (KdeBreeze, Some(crate::model::ArrowSide::Leading), Some(false)),
    (Adwaita, Some(crate::model::ArrowSide::Trailing), Some(true)),
    (MacosMonterey, Some(crate::model::ArrowSide::Leading), None),
    (MacosTahoe, Some(crate::model::ArrowSide::Leading), None),
    (Windows11, Some(crate::model::ArrowSide::Trailing), Some(true)),
    (Material3, None, None),
];

/// The native themes state the expander's side and frame as platform-facts
/// gives them, static and live, and no other preset states either.
#[test]
fn native_themes_state_the_expanders_structure() {
    assert!(facts_line(1683).starts_with("| `arrow_side`"));
    assert!(facts_line(1686).starts_with("| `frame_enabled`"));
    let mut failures = Vec::new();
    for (preset, side, frame) in EXPANDER_STRUCTURE {
        for variant in gate_variants(preset) {
            match variant.and_then(|(source, name, v)| resolve(v).map(|t| (source, name, t))) {
                Ok((source, name, t)) => {
                    let got = (t.expander.arrow_side, t.expander.frame_enabled);
                    if got != (side, frame) {
                        failures.push(format!(
                            "{source} {name}: expander side and frame {got:?}, \
                             platform-facts gives {:?} (docs/platform-facts.md:1683, :1686)",
                            (side, frame)
                        ));
                    }
                }
                Err(e) => failures.push(e),
            }
        }
    }
    for name in UNSOURCED_PRESETS {
        for mode in [ColorMode::Light, ColorMode::Dark] {
            match Theme::preset(name).and_then(|t| t.into_variant(mode)) {
                Ok(v) if v.expander.arrow_side.is_some() || v.expander.frame_enabled.is_some() => {
                    failures.push(format!(
                        "{name} {mode:?}: states the expander's side or frame, with no source"
                    ));
                }
                Ok(_) => {}
                Err(e) => failures.push(format!("{name} {mode:?}: {e}")),
            }
        }
    }
    assert!(failures.is_empty(), "{}", failures.join("\n"));
}

/// One soft field per native preset against platform-facts' row at `line`,
/// static and live, and the unsourced presets stating none: the mismatches.
fn soft_field_failures<T: Copy + PartialEq + std::fmt::Debug>(
    field: &str,
    line: usize,
    want: &[(NativePreset, Option<T>)],
    resolved: fn(&ResolvedTheme) -> Option<T>,
    stated: fn(&ThemeMode) -> Option<T>,
) -> Vec<String> {
    let mut failures = Vec::new();
    for preset in NativePreset::ALL {
        let n = want.iter().filter(|(p, _)| *p == preset).count();
        if n != 1 {
            failures.push(format!("{preset:?}: {n} rows for {field}"));
        }
    }
    for &(preset, expected) in want {
        for variant in gate_variants(preset) {
            match variant.and_then(|(source, name, v)| resolve(v).map(|t| (source, name, t))) {
                Ok((source, name, t)) => {
                    let got = resolved(&t);
                    if got != expected {
                        failures.push(format!(
                            "{source} {name}: {field} {got:?}, platform-facts gives \
                             {expected:?} (docs/platform-facts.md:{line})"
                        ));
                    }
                }
                Err(e) => failures.push(e),
            }
        }
    }
    for name in UNSOURCED_PRESETS {
        for mode in [ColorMode::Light, ColorMode::Dark] {
            match Theme::preset(name).and_then(|t| t.into_variant(mode)) {
                Ok(v) => {
                    if let Some(got) = stated(&v) {
                        failures.push(format!(
                            "{name} {mode:?}: states {field} = {got:?}, with no source"
                        ));
                    }
                }
                Err(e) => failures.push(format!("{name} {mode:?}: {e}")),
            }
        }
    }
    failures
}

/// The tooltip's show delay per platform, in milliseconds, from
/// platform-facts §2.7 (`platform-facts.md:1290`); `None` where the cell states none.
#[rustfmt::skip]
const TOOLTIP_SHOW_DELAY: [(NativePreset, Option<u16>); 6] = [
    (KdeBreeze, Some(700)),
    (Adwaita, Some(500)),
    (MacosMonterey, None),
    (MacosTahoe, None),
    (Windows11, Some(800)),
    (Material3, Some(0)),
];

/// The native themes state the tooltip's show delay as platform-facts gives
/// it, static and live, and no other preset states one.
#[test]
fn native_themes_state_the_tooltip_show_delay() {
    assert!(facts_line(1290).starts_with("| `show_delay`"));
    assert!(facts_heading(1277).starts_with("### 2.7 "));
    let failures = soft_field_failures(
        "tooltip.show_delay_ms",
        1277,
        &TOOLTIP_SHOW_DELAY,
        |t| t.tooltip.show_delay,
        |v| v.tooltip.show_delay,
    );
    assert!(failures.is_empty(), "{}", failures.join("\n"));
}

/// The dialog's entrance per platform, from platform-facts §2.22 (`platform-facts.md:1569`);
/// `None` where the cell states none.
#[rustfmt::skip]
const DIALOG_ENTRANCE: [(NativePreset, Option<crate::model::DialogEntranceStyle>); 6] = [
    (KdeBreeze, Some(crate::model::DialogEntranceStyle::FadeRise)),
    (Adwaita, Some(crate::model::DialogEntranceStyle::ScaleFade)),
    (MacosMonterey, None),
    (MacosTahoe, None),
    (Windows11, Some(crate::model::DialogEntranceStyle::ScaleFade)),
    (Material3, Some(crate::model::DialogEntranceStyle::ScaleFade)),
];

/// The native themes state the dialog's entrance as platform-facts gives it,
/// static and live, and no other preset states one.
#[test]
fn native_themes_state_the_dialog_entrance() {
    assert!(facts_line(1569).starts_with("| `entrance`"));
    assert!(facts_heading(1556).starts_with("### 2.22 "));
    let failures = soft_field_failures(
        "dialog.entrance",
        1556,
        &DIALOG_ENTRANCE,
        |t| t.dialog.entrance,
        |v| v.dialog.entrance,
    );
    assert!(failures.is_empty(), "{}", failures.join("\n"));
}