Skip to main content

sui_widgets/
theme.rs

1use sui_core::Color;
2use sui_layout::Padding as Insets;
3use sui_text::{FontFamilyStack, TextStyle};
4
5use crate::animation::Easing;
6use crate::hdr_theme::HdrThemeTokens;
7
8/// Motion design tokens: a shared vocabulary of animation durations and easing
9/// curves so widgets and applications animate consistently.
10///
11/// Durations are expressed in **seconds** (matching the `delta` supplied by
12/// [`crate::animation::AnimatedValue::tick`] and the `time`/`delta` fields of
13/// `WakeEvent::AnimationFrame`). Easing curves are built from the
14/// [`Easing`] enum and are [`Copy`], keeping [`DefaultTheme`] `Copy`.
15///
16/// The duration ladder follows the Mesh design language: 70ms micro feedback,
17/// 140ms small state changes, 220ms medium surfaces (popovers, dialogs) and
18/// 340ms large transitions (drawers, sheets, page changes).
19#[derive(Debug, Clone, Copy, PartialEq)]
20pub struct ThemeMotion {
21    /// No animation: state changes apply immediately (0.0s).
22    pub duration_instant: f32,
23    /// Micro feedback such as hover tint / press state changes (0.07s).
24    pub duration_fast: f32,
25    /// Small state changes: toggles, fades, tooltips (0.14s).
26    pub duration_normal: f32,
27    /// Medium surfaces: popovers, dialogs, expanding panels (0.22s).
28    pub duration_slow: f32,
29    /// Large transitions: drawers, sheets, page changes (0.34s).
30    pub duration_slower: f32,
31    /// The standard easing curve: gentle acceleration, firm deceleration.
32    /// Use for the majority of UI transitions.
33    pub easing_standard: Easing,
34    /// A more expressive curve for prominent, attention-drawing motion.
35    pub easing_emphasized: Easing,
36    /// Decelerate curve: enters quickly, settles softly. Good for elements
37    /// entering the screen.
38    pub easing_decelerate: Easing,
39    /// Accelerate curve: starts softly, exits quickly. Good for elements
40    /// leaving the screen.
41    pub easing_accelerate: Easing,
42}
43
44impl ThemeMotion {
45    /// The standard motion tokens shared by every built-in theme.
46    pub const fn standard() -> Self {
47        Self {
48            duration_instant: 0.0,
49            duration_fast: 0.07,
50            duration_normal: 0.14,
51            duration_slow: 0.22,
52            duration_slower: 0.34,
53            easing_standard: Easing::CubicBezier {
54                x1: 0.2,
55                y1: 0.0,
56                x2: 0.0,
57                y2: 1.0,
58            },
59            easing_emphasized: Easing::CubicBezier {
60                x1: 0.45,
61                y1: 0.0,
62                x2: 0.15,
63                y2: 1.0,
64            },
65            easing_decelerate: Easing::CubicBezier {
66                x1: 0.2,
67                y1: 0.0,
68                x2: 0.0,
69                y2: 1.0,
70            },
71            easing_accelerate: Easing::CubicBezier {
72                x1: 0.45,
73                y1: 0.0,
74                x2: 1.0,
75                y2: 1.0,
76            },
77        }
78    }
79
80    pub fn hover_duration(&self) -> f64 {
81        f64::from(self.duration_fast)
82    }
83
84    pub fn press_duration(&self) -> f64 {
85        f64::from(self.duration_fast)
86    }
87
88    pub fn focus_duration(&self) -> f64 {
89        f64::from(self.duration_normal)
90    }
91
92    pub fn toggle_duration(&self) -> f64 {
93        f64::from(self.duration_normal)
94    }
95
96    pub fn entrance_duration(&self) -> f64 {
97        f64::from(self.duration_normal)
98    }
99
100    pub fn tab_switch_duration(&self) -> f64 {
101        f64::from(self.duration_fast)
102    }
103
104    pub const fn hover_easing(&self) -> Easing {
105        self.easing_standard
106    }
107
108    pub const fn press_easing(&self) -> Easing {
109        self.easing_standard
110    }
111
112    pub const fn focus_easing(&self) -> Easing {
113        self.easing_decelerate
114    }
115
116    pub const fn toggle_easing(&self) -> Easing {
117        self.easing_emphasized
118    }
119
120    pub const fn entrance_easing(&self) -> Easing {
121        self.easing_decelerate
122    }
123
124    pub const fn tab_switch_easing(&self) -> Easing {
125        self.easing_standard
126    }
127}
128
129impl Default for ThemeMotion {
130    fn default() -> Self {
131        Self::standard()
132    }
133}
134
135#[derive(Debug, Clone, Copy, PartialEq, Eq)]
136pub struct ThemeFontStack {
137    pub primary: &'static str,
138    pub fallbacks: &'static [&'static str],
139}
140
141impl From<ThemeFontStack> for FontFamilyStack {
142    fn from(value: ThemeFontStack) -> Self {
143        Self::new(value.primary, value.fallbacks)
144    }
145}
146
147#[derive(Debug, Clone, Copy, PartialEq, Eq)]
148pub struct ThemeFontFamilies {
149    pub sans: ThemeFontStack,
150    pub serif: ThemeFontStack,
151    pub mono: ThemeFontStack,
152}
153
154impl Default for ThemeFontFamilies {
155    fn default() -> Self {
156        Self {
157            sans: ThemeFontStack {
158                primary: "ui-sans-serif",
159                fallbacks: &[
160                    "system-ui",
161                    "sans-serif",
162                    "Apple Color Emoji",
163                    "Segoe UI Emoji",
164                    "Segoe UI Symbol",
165                    "Noto Color Emoji",
166                ],
167            },
168            serif: ThemeFontStack {
169                primary: "ui-serif",
170                fallbacks: &["Georgia", "Cambria", "Times New Roman", "Times", "serif"],
171            },
172            mono: ThemeFontStack {
173                primary: "ui-monospace",
174                fallbacks: &[
175                    "SFMono-Regular",
176                    "Menlo",
177                    "Monaco",
178                    "Consolas",
179                    "Liberation Mono",
180                    "Courier New",
181                    "monospace",
182                ],
183            },
184        }
185    }
186}
187
188#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
189pub enum ThemeColorScheme {
190    #[default]
191    Light,
192    Dark,
193    HighContrast,
194}
195
196#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
197pub enum ThemeDensity {
198    Compact,
199    #[default]
200    Comfortable,
201    Touch,
202}
203
204/// Contextual interface-control sizing.
205///
206/// Unlike [`ThemeDensity`], which is retained as the legacy global theme API,
207/// control size is intended to be chosen for the interface being designed:
208/// small for dense toolbars and configuration surfaces, medium for standard
209/// controls, and large for hero actions or focused overlays. It changes
210/// control geometry and typography while leaving the independent text-scale
211/// ramp unchanged.
212#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
213pub enum ControlSize {
214    Small,
215    #[default]
216    Medium,
217    Large,
218}
219
220impl ControlSize {
221    const fn legacy_density(self) -> ThemeDensity {
222        match self {
223            Self::Small => ThemeDensity::Compact,
224            Self::Medium => ThemeDensity::Comfortable,
225            Self::Large => ThemeDensity::Touch,
226        }
227    }
228
229    const fn control_height(self) -> f32 {
230        match self {
231            Self::Small => 28.0,
232            Self::Medium => 32.0,
233            Self::Large => 40.0,
234        }
235    }
236
237    const fn row_height(self) -> f32 {
238        match self {
239            Self::Small => 30.0,
240            Self::Medium => 36.0,
241            Self::Large => 44.0,
242        }
243    }
244
245    const fn icon_size(self) -> f32 {
246        match self {
247            Self::Small => 13.0,
248            Self::Medium => 15.0,
249            Self::Large => 17.0,
250        }
251    }
252}
253
254#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
255pub enum SemanticTone {
256    #[default]
257    Neutral,
258    Accent,
259    Info,
260    Success,
261    Warning,
262    Danger,
263}
264
265#[derive(Debug, Clone, Copy, PartialEq)]
266pub struct ThemeColors {
267    pub name: &'static str,
268    pub scheme: ThemeColorScheme,
269    pub base_100: Color,
270    pub base_200: Color,
271    pub base_300: Color,
272    pub base_content: Color,
273    pub primary: Color,
274    pub primary_content: Color,
275    pub secondary: Color,
276    pub secondary_content: Color,
277    pub accent: Color,
278    pub accent_content: Color,
279    pub neutral: Color,
280    pub neutral_content: Color,
281    pub info: Color,
282    pub info_content: Color,
283    pub success: Color,
284    pub success_content: Color,
285    pub warning: Color,
286    pub warning_content: Color,
287    pub error: Color,
288    pub error_content: Color,
289}
290
291impl ThemeColors {
292    /// SUI's branded light palette. This is an explicit alias for
293    /// [`Self::light`] so applications can distinguish the SUI preset from
294    /// other built-in light themes.
295    pub fn sui() -> Self {
296        Self::light()
297    }
298
299    pub fn light() -> Self {
300        Self {
301            name: "light",
302            scheme: ThemeColorScheme::Light,
303            base_100: rgb8(255, 255, 255),
304            base_200: rgb8(247, 248, 250),
305            base_300: rgb8(227, 232, 239),
306            base_content: rgb8(13, 18, 32),
307            primary: rgb8(8, 124, 164),
308            primary_content: Color::WHITE,
309            secondary: rgb8(143, 125, 248),
310            secondary_content: Color::WHITE,
311            accent: rgb8(8, 124, 164),
312            accent_content: Color::WHITE,
313            neutral: rgb8(73, 84, 107),
314            neutral_content: Color::WHITE,
315            info: rgb8(41, 112, 255),
316            info_content: Color::WHITE,
317            success: rgb8(22, 163, 74),
318            success_content: Color::WHITE,
319            warning: rgb8(220, 154, 16),
320            warning_content: rgb8(36, 22, 0),
321            error: rgb8(217, 45, 32),
322            error_content: Color::WHITE,
323        }
324    }
325
326    /// Neutral black, white, and gray tokens for professional interfaces that
327    /// do not have an application-specific color preference.
328    ///
329    /// Status colors remain semantic so success, warning, danger, and
330    /// informational feedback do not lose meaning.
331    pub fn neutral() -> Self {
332        Self {
333            name: "neutral",
334            scheme: ThemeColorScheme::Light,
335            base_100: Color::WHITE,
336            base_200: rgb8(250, 250, 250),
337            base_300: rgb8(229, 229, 229),
338            base_content: rgb8(23, 23, 23),
339            primary: rgb8(23, 23, 23),
340            primary_content: Color::WHITE,
341            secondary: rgb8(64, 64, 64),
342            secondary_content: Color::WHITE,
343            accent: rgb8(23, 23, 23),
344            accent_content: Color::WHITE,
345            neutral: rgb8(38, 38, 38),
346            neutral_content: Color::WHITE,
347            info: rgb8(37, 99, 235),
348            info_content: Color::WHITE,
349            success: rgb8(21, 128, 61),
350            success_content: Color::WHITE,
351            warning: rgb8(180, 83, 9),
352            warning_content: Color::WHITE,
353            error: rgb8(185, 28, 28),
354            error_content: Color::WHITE,
355        }
356    }
357
358    /// Dark companion to [`Self::neutral`], using achromatic surfaces,
359    /// controls, focus, selection, and primary actions.
360    pub fn neutral_dark() -> Self {
361        Self {
362            name: "neutral-dark",
363            scheme: ThemeColorScheme::Dark,
364            base_100: rgb8(10, 10, 10),
365            base_200: rgb8(23, 23, 23),
366            base_300: rgb8(38, 38, 38),
367            base_content: rgb8(245, 245, 245),
368            primary: rgb8(245, 245, 245),
369            primary_content: rgb8(23, 23, 23),
370            secondary: rgb8(163, 163, 163),
371            secondary_content: rgb8(23, 23, 23),
372            accent: rgb8(245, 245, 245),
373            accent_content: rgb8(23, 23, 23),
374            neutral: rgb8(38, 38, 38),
375            neutral_content: rgb8(245, 245, 245),
376            info: rgb8(96, 165, 250),
377            info_content: rgb8(23, 37, 84),
378            success: rgb8(74, 222, 128),
379            success_content: rgb8(5, 46, 22),
380            warning: rgb8(251, 191, 36),
381            warning_content: rgb8(66, 32, 6),
382            error: rgb8(248, 113, 113),
383            error_content: rgb8(69, 10, 10),
384        }
385    }
386
387    pub fn dark() -> Self {
388        Self {
389            name: "dark",
390            scheme: ThemeColorScheme::Dark,
391            base_100: rgb8(11, 14, 19),
392            base_200: rgb8(18, 22, 31),
393            base_300: rgb8(29, 36, 49),
394            base_content: rgb8(231, 235, 244),
395            primary: rgb8(53, 210, 238),
396            primary_content: rgb8(5, 33, 41),
397            secondary: rgb8(143, 125, 248),
398            secondary_content: rgb8(16, 11, 36),
399            accent: rgb8(53, 210, 238),
400            accent_content: rgb8(5, 33, 41),
401            neutral: rgb8(23, 28, 39),
402            neutral_content: rgb8(231, 235, 244),
403            info: rgb8(109, 149, 245),
404            info_content: rgb8(7, 19, 48),
405            success: rgb8(52, 211, 116),
406            success_content: rgb8(2, 38, 20),
407            warning: rgb8(253, 176, 34),
408            warning_content: rgb8(40, 24, 0),
409            error: rgb8(241, 87, 92),
410            error_content: rgb8(42, 8, 8),
411        }
412    }
413
414    pub fn high_contrast() -> Self {
415        Self {
416            name: "void",
417            scheme: ThemeColorScheme::HighContrast,
418            base_100: Color::BLACK,
419            base_200: rgb8(11, 14, 20),
420            base_300: rgb8(19, 23, 34),
421            base_content: rgb8(223, 229, 240),
422            primary: rgb8(33, 199, 229),
423            primary_content: rgb8(3, 19, 24),
424            secondary: rgb8(143, 125, 248),
425            secondary_content: rgb8(16, 11, 36),
426            accent: rgb8(33, 199, 229),
427            accent_content: rgb8(3, 19, 24),
428            neutral: rgb8(11, 14, 20),
429            neutral_content: rgb8(223, 229, 240),
430            info: rgb8(100, 141, 240),
431            info_content: rgb8(5, 16, 42),
432            success: rgb8(46, 201, 108),
433            success_content: rgb8(1, 33, 16),
434            warning: rgb8(242, 169, 31),
435            warning_content: rgb8(38, 23, 0),
436            error: rgb8(233, 78, 83),
437            error_content: rgb8(36, 6, 6),
438        }
439    }
440
441    pub fn with_scheme(scheme: ThemeColorScheme) -> Self {
442        match scheme {
443            ThemeColorScheme::Light => Self::light(),
444            ThemeColorScheme::Dark => Self::dark(),
445            ThemeColorScheme::HighContrast => Self::high_contrast(),
446        }
447    }
448}
449
450impl Default for ThemeColors {
451    fn default() -> Self {
452        Self::light()
453    }
454}
455
456#[derive(Debug, Clone, Copy, PartialEq)]
457pub struct ThemeBreakpoints {
458    pub sm: f32,
459    pub md: f32,
460    pub lg: f32,
461    pub xl: f32,
462    pub _2xl: f32,
463}
464
465impl Default for ThemeBreakpoints {
466    fn default() -> Self {
467        Self {
468            sm: 640.0,
469            md: 768.0,
470            lg: 1024.0,
471            xl: 1280.0,
472            _2xl: 1536.0,
473        }
474    }
475}
476
477#[derive(Debug, Clone, Copy, PartialEq)]
478pub struct ThemeContainers {
479    pub _3xs: f32,
480    pub _2xs: f32,
481    pub xs: f32,
482    pub sm: f32,
483    pub md: f32,
484    pub lg: f32,
485    pub xl: f32,
486    pub _2xl: f32,
487    pub _3xl: f32,
488    pub _4xl: f32,
489    pub _5xl: f32,
490    pub _6xl: f32,
491    pub _7xl: f32,
492}
493
494impl Default for ThemeContainers {
495    fn default() -> Self {
496        Self {
497            _3xs: 256.0,
498            _2xs: 288.0,
499            xs: 320.0,
500            sm: 384.0,
501            md: 448.0,
502            lg: 512.0,
503            xl: 576.0,
504            _2xl: 672.0,
505            _3xl: 768.0,
506            _4xl: 896.0,
507            _5xl: 1024.0,
508            _6xl: 1152.0,
509            _7xl: 1280.0,
510        }
511    }
512}
513
514#[derive(Debug, Clone, Copy, PartialEq)]
515pub struct ThemeTextToken {
516    pub size: f32,
517    pub line_height: f32,
518}
519
520#[derive(Debug, Clone, Copy, PartialEq)]
521pub struct ThemeTextScale {
522    pub xs: ThemeTextToken,
523    pub sm: ThemeTextToken,
524    pub base: ThemeTextToken,
525    pub lg: ThemeTextToken,
526    pub xl: ThemeTextToken,
527    pub _2xl: ThemeTextToken,
528    pub _3xl: ThemeTextToken,
529    pub _4xl: ThemeTextToken,
530    pub _5xl: ThemeTextToken,
531    pub _6xl: ThemeTextToken,
532    pub _7xl: ThemeTextToken,
533    pub _8xl: ThemeTextToken,
534    pub _9xl: ThemeTextToken,
535}
536
537impl Default for ThemeTextScale {
538    fn default() -> Self {
539        Self {
540            xs: ThemeTextToken {
541                size: 12.0,
542                line_height: 17.0,
543            },
544            sm: ThemeTextToken {
545                size: 13.0,
546                line_height: 18.0,
547            },
548            base: ThemeTextToken {
549                size: 15.0,
550                line_height: 22.0,
551            },
552            lg: ThemeTextToken {
553                size: 17.0,
554                line_height: 25.0,
555            },
556            xl: ThemeTextToken {
557                size: 19.0,
558                line_height: 27.0,
559            },
560            _2xl: ThemeTextToken {
561                size: 21.0,
562                line_height: 29.0,
563            },
564            _3xl: ThemeTextToken {
565                size: 25.0,
566                line_height: 33.0,
567            },
568            _4xl: ThemeTextToken {
569                size: 31.0,
570                line_height: 39.0,
571            },
572            _5xl: ThemeTextToken {
573                size: 37.0,
574                line_height: 45.0,
575            },
576            _6xl: ThemeTextToken {
577                size: 49.0,
578                line_height: 55.0,
579            },
580            _7xl: ThemeTextToken {
581                size: 61.0,
582                line_height: 67.0,
583            },
584            _8xl: ThemeTextToken {
585                size: 73.0,
586                line_height: 79.0,
587            },
588            _9xl: ThemeTextToken {
589                size: 97.0,
590                line_height: 103.0,
591            },
592        }
593    }
594}
595
596#[derive(Debug, Clone, Copy, PartialEq, Eq)]
597pub struct ThemeFontWeights {
598    pub thin: u16,
599    pub extralight: u16,
600    pub light: u16,
601    pub normal: u16,
602    pub medium: u16,
603    pub semibold: u16,
604    pub bold: u16,
605    pub extrabold: u16,
606    pub black: u16,
607}
608
609impl Default for ThemeFontWeights {
610    fn default() -> Self {
611        Self {
612            thin: 100,
613            extralight: 200,
614            light: 300,
615            normal: 400,
616            medium: 500,
617            semibold: 600,
618            bold: 700,
619            extrabold: 800,
620            black: 900,
621        }
622    }
623}
624
625#[derive(Debug, Clone, Copy, PartialEq)]
626pub struct ThemeTracking {
627    pub tighter: f32,
628    pub tight: f32,
629    pub normal: f32,
630    pub wide: f32,
631    pub wider: f32,
632    pub widest: f32,
633}
634
635impl Default for ThemeTracking {
636    fn default() -> Self {
637        Self {
638            tighter: 0.0,
639            tight: 0.0,
640            normal: 0.0,
641            wide: 0.02,
642            wider: 0.04,
643            widest: 0.06,
644        }
645    }
646}
647
648#[derive(Debug, Clone, Copy, PartialEq)]
649pub struct ThemeLeading {
650    pub tight: f32,
651    pub snug: f32,
652    pub normal: f32,
653    pub relaxed: f32,
654    pub loose: f32,
655}
656
657impl Default for ThemeLeading {
658    fn default() -> Self {
659        Self {
660            tight: 1.3,
661            snug: 1.4,
662            normal: 1.5,
663            relaxed: 1.6,
664            loose: 1.65,
665        }
666    }
667}
668
669#[derive(Debug, Clone, Copy, PartialEq)]
670pub struct ThemeRadii {
671    pub xs: f32,
672    pub sm: f32,
673    pub md: f32,
674    pub lg: f32,
675    pub xl: f32,
676    pub _2xl: f32,
677    pub _3xl: f32,
678    pub _4xl: f32,
679}
680
681impl Default for ThemeRadii {
682    fn default() -> Self {
683        Self {
684            xs: 2.0,
685            sm: 4.0,
686            md: 6.0,
687            lg: 8.0,
688            xl: 10.0,
689            _2xl: 14.0,
690            _3xl: 18.0,
691            _4xl: 999.0,
692        }
693    }
694}
695
696#[derive(Debug, Clone, Copy, PartialEq)]
697pub struct ThemeShadowLayer {
698    pub offset_x: f32,
699    pub offset_y: f32,
700    pub blur: f32,
701    pub spread: f32,
702    pub color: Color,
703    pub inset: bool,
704}
705
706#[derive(Debug, Clone, Copy, PartialEq)]
707pub struct ThemeShadow {
708    pub first: Option<ThemeShadowLayer>,
709    pub second: Option<ThemeShadowLayer>,
710}
711
712impl ThemeShadow {
713    pub const fn empty() -> Self {
714        Self {
715            first: None,
716            second: None,
717        }
718    }
719
720    pub const fn single(layer: ThemeShadowLayer) -> Self {
721        Self {
722            first: Some(layer),
723            second: None,
724        }
725    }
726
727    pub const fn double(first: ThemeShadowLayer, second: ThemeShadowLayer) -> Self {
728        Self {
729            first: Some(first),
730            second: Some(second),
731        }
732    }
733}
734
735impl ThemeShadowLayer {
736    /// Convert this theme shadow layer into the renderer primitive
737    /// [`sui_scene::ShadowParams`] consumed by `PaintCtx::draw_shadow`.
738    pub fn to_shadow_params(&self) -> sui_scene::ShadowParams {
739        sui_scene::ShadowParams {
740            offset_x: self.offset_x,
741            offset_y: self.offset_y,
742            blur: self.blur,
743            spread: self.spread,
744            color: self.color,
745        }
746    }
747
748    /// An outer (drop) shadow casts beyond the surface edge; an inset layer
749    /// renders an inner shadow. Only outer layers are paintable today.
750    pub const fn is_outer(&self) -> bool {
751        !self.inset
752    }
753}
754
755/// Paint the outer (drop) layers of a [`ThemeShadow`] behind a rounded-rect
756/// surface. The tighter `second` layer is drawn first and the wider/more-diffuse
757/// `first` layer on top — matching CSS `box-shadow`, where the first-listed
758/// shadow is topmost.
759///
760/// Inset layers are skipped: inner shadows are future work.
761///
762/// The caller MUST invoke this BEFORE filling the surface background and BEFORE
763/// pushing any clip tight to the widget, so the soft shadow renders behind the
764/// fill and is not clipped away.
765pub fn paint_theme_shadow(
766    paint: &mut sui_runtime::PaintCtx,
767    rect: sui_core::Rect,
768    radii: [f32; 4],
769    shadow: &ThemeShadow,
770) {
771    // Draw the tighter `second` layer first, then the wider/more-diffuse `first`
772    // layer on top (CSS box-shadow order: the first-listed shadow is topmost).
773    if let Some(layer) = shadow.second
774        && layer.is_outer()
775    {
776        paint.draw_shadow(rect, radii, layer.to_shadow_params());
777        // inset layers are inner shadows -> future work
778    }
779    if let Some(layer) = shadow.first
780        && layer.is_outer()
781    {
782        paint.draw_shadow(rect, radii, layer.to_shadow_params());
783        // inset layers are inner shadows -> future work
784    }
785}
786
787#[derive(Debug, Clone, Copy, PartialEq)]
788pub struct ThemeBoxShadowScale {
789    pub _2xs: ThemeShadow,
790    pub xs: ThemeShadow,
791    pub sm: ThemeShadow,
792    pub md: ThemeShadow,
793    pub lg: ThemeShadow,
794    pub xl: ThemeShadow,
795    pub _2xl: ThemeShadow,
796}
797
798#[derive(Debug, Clone, Copy, PartialEq)]
799pub struct ThemeInsetShadowScale {
800    pub _2xs: ThemeShadow,
801    pub xs: ThemeShadow,
802    pub sm: ThemeShadow,
803}
804
805#[derive(Debug, Clone, Copy, PartialEq)]
806pub struct ThemeDropShadowScale {
807    pub xs: ThemeShadow,
808    pub sm: ThemeShadow,
809    pub md: ThemeShadow,
810    pub lg: ThemeShadow,
811    pub xl: ThemeShadow,
812    pub _2xl: ThemeShadow,
813}
814
815#[derive(Debug, Clone, Copy, PartialEq)]
816pub struct ThemeTextShadowScale {
817    pub _2xs: ThemeShadow,
818    pub xs: ThemeShadow,
819    pub sm: ThemeShadow,
820    pub md: ThemeShadow,
821    pub lg: ThemeShadow,
822}
823
824#[derive(Debug, Clone, Copy, PartialEq)]
825pub struct ThemeShadows {
826    pub box_shadow: ThemeBoxShadowScale,
827    pub inset: ThemeInsetShadowScale,
828    pub drop: ThemeDropShadowScale,
829    pub text: ThemeTextShadowScale,
830}
831
832impl Default for ThemeShadows {
833    fn default() -> Self {
834        let black_005 = Color::BLACK.with_alpha(0.05);
835        let black_01 = Color::BLACK.with_alpha(0.1);
836        let black_012 = Color::BLACK.with_alpha(0.12);
837        let black_015 = Color::BLACK.with_alpha(0.15);
838        let black_02 = Color::BLACK.with_alpha(0.2);
839        let black_025 = Color::BLACK.with_alpha(0.25);
840        let black_075 = Color::BLACK.with_alpha(0.075);
841
842        Self {
843            box_shadow: ThemeBoxShadowScale {
844                _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, black_005, false)),
845                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, black_005, false)),
846                sm: ThemeShadow::double(
847                    shadow_layer(0.0, 1.0, 3.0, 0.0, black_01, false),
848                    shadow_layer(0.0, 1.0, 2.0, -1.0, black_01, false),
849                ),
850                md: ThemeShadow::double(
851                    shadow_layer(0.0, 4.0, 6.0, -1.0, black_01, false),
852                    shadow_layer(0.0, 2.0, 4.0, -2.0, black_01, false),
853                ),
854                lg: ThemeShadow::double(
855                    shadow_layer(0.0, 10.0, 15.0, -3.0, black_01, false),
856                    shadow_layer(0.0, 4.0, 6.0, -4.0, black_01, false),
857                ),
858                xl: ThemeShadow::double(
859                    shadow_layer(0.0, 20.0, 25.0, -5.0, black_01, false),
860                    shadow_layer(0.0, 8.0, 10.0, -6.0, black_01, false),
861                ),
862                _2xl: ThemeShadow::single(shadow_layer(0.0, 25.0, 50.0, -12.0, black_025, false)),
863            },
864            inset: ThemeInsetShadowScale {
865                _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, black_005, true)),
866                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black_005, true)),
867                sm: ThemeShadow::single(shadow_layer(0.0, 2.0, 4.0, 0.0, black_005, true)),
868            },
869            drop: ThemeDropShadowScale {
870                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black_005, false)),
871                sm: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, black_015, false)),
872                md: ThemeShadow::single(shadow_layer(0.0, 3.0, 3.0, 0.0, black_012, false)),
873                lg: ThemeShadow::single(shadow_layer(0.0, 4.0, 4.0, 0.0, black_015, false)),
874                xl: ThemeShadow::single(shadow_layer(0.0, 9.0, 7.0, 0.0, black_01, false)),
875                _2xl: ThemeShadow::single(shadow_layer(0.0, 25.0, 25.0, 0.0, black_015, false)),
876            },
877            text: ThemeTextShadowScale {
878                _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, black_015, false)),
879                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black_02, false)),
880                sm: ThemeShadow::double(
881                    shadow_layer(0.0, 1.0, 0.0, 0.0, black_075, false),
882                    shadow_layer(0.0, 1.0, 1.0, 0.0, black_075, false),
883                ),
884                md: ThemeShadow::double(
885                    shadow_layer(0.0, 1.0, 1.0, 0.0, black_01, false),
886                    shadow_layer(0.0, 2.0, 4.0, 0.0, black_01, false),
887                ),
888                lg: ThemeShadow::double(
889                    shadow_layer(0.0, 1.0, 2.0, 0.0, black_01, false),
890                    shadow_layer(0.0, 4.0, 8.0, 0.0, black_01, false),
891                ),
892            },
893        }
894    }
895}
896
897impl ThemeShadows {
898    /// Choose the elevation treatment for a complete built-in color palette.
899    pub fn for_colors(colors: &ThemeColors) -> Self {
900        if is_neutral_theme(colors) && matches!(colors.scheme, ThemeColorScheme::Light) {
901            Self::neutral()
902        } else {
903            Self::for_scheme(colors.scheme)
904        }
905    }
906
907    /// Scheme-aware elevation per the Mesh design language: Light casts faint
908    /// ink-tinted shadows, Dark casts deeper black shadows, and the true-black
909    /// OLED theme casts none at all — elevation there is drawn with borders,
910    /// never shadows (`--sm-shadow-*: none` in Void).
911    pub fn for_scheme(scheme: ThemeColorScheme) -> Self {
912        match scheme {
913            ThemeColorScheme::Light => Self::light(),
914            ThemeColorScheme::Dark => Self::dark(),
915            ThemeColorScheme::HighContrast => Self::none(),
916        }
917    }
918
919    /// Mesh Light ladder: `0 1px 2px 6%`, `0 2px 10px 8%`, `0 16px 40px 16%`
920    /// anchors interpolated across the scale, tinted with ink `#0d1220`.
921    pub fn light() -> Self {
922        Self::light_with_ink(rgb8(13, 18, 32))
923    }
924
925    fn light_with_ink(shadow_ink: Color) -> Self {
926        let ink = |alpha: f32| shadow_ink.with_alpha(alpha);
927
928        Self {
929            box_shadow: ThemeBoxShadowScale {
930                _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, ink(0.04), false)),
931                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, ink(0.06), false)),
932                sm: ThemeShadow::double(
933                    shadow_layer(0.0, 1.0, 3.0, 0.0, ink(0.07), false),
934                    shadow_layer(0.0, 1.0, 2.0, -1.0, ink(0.06), false),
935                ),
936                md: ThemeShadow::single(shadow_layer(0.0, 2.0, 10.0, 0.0, ink(0.08), false)),
937                lg: ThemeShadow::single(shadow_layer(0.0, 8.0, 24.0, -2.0, ink(0.12), false)),
938                xl: ThemeShadow::single(shadow_layer(0.0, 16.0, 40.0, -4.0, ink(0.16), false)),
939                _2xl: ThemeShadow::single(shadow_layer(0.0, 24.0, 56.0, -8.0, ink(0.20), false)),
940            },
941            inset: ThemeInsetShadowScale {
942                _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, ink(0.05), true)),
943                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, ink(0.05), true)),
944                sm: ThemeShadow::single(shadow_layer(0.0, 2.0, 4.0, 0.0, ink(0.05), true)),
945            },
946            drop: ThemeDropShadowScale {
947                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, ink(0.05), false)),
948                sm: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, ink(0.12), false)),
949                md: ThemeShadow::single(shadow_layer(0.0, 3.0, 3.0, 0.0, ink(0.10), false)),
950                lg: ThemeShadow::single(shadow_layer(0.0, 4.0, 4.0, 0.0, ink(0.12), false)),
951                xl: ThemeShadow::single(shadow_layer(0.0, 9.0, 7.0, 0.0, ink(0.09), false)),
952                _2xl: ThemeShadow::single(shadow_layer(0.0, 25.0, 25.0, 0.0, ink(0.12), false)),
953            },
954            text: ThemeTextShadowScale {
955                _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, ink(0.12), false)),
956                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, ink(0.16), false)),
957                sm: ThemeShadow::double(
958                    shadow_layer(0.0, 1.0, 0.0, 0.0, ink(0.07), false),
959                    shadow_layer(0.0, 1.0, 1.0, 0.0, ink(0.07), false),
960                ),
961                md: ThemeShadow::double(
962                    shadow_layer(0.0, 1.0, 1.0, 0.0, ink(0.09), false),
963                    shadow_layer(0.0, 2.0, 4.0, 0.0, ink(0.09), false),
964                ),
965                lg: ThemeShadow::double(
966                    shadow_layer(0.0, 1.0, 2.0, 0.0, ink(0.09), false),
967                    shadow_layer(0.0, 4.0, 8.0, 0.0, ink(0.09), false),
968                ),
969            },
970        }
971    }
972
973    /// Neutral light elevation uses the same restrained geometry as the SUI
974    /// light theme with pure-black shadow ink.
975    pub fn neutral() -> Self {
976        Self::light_with_ink(Color::BLACK)
977    }
978
979    /// Mesh Dark ladder: `0 1px 2px 30%`, `0 4px 16px 40%`, `0 20px 48px 55%`
980    /// anchors interpolated across the scale (pure black, deeper than Light).
981    pub fn dark() -> Self {
982        let black = |alpha: f32| Color::BLACK.with_alpha(alpha);
983
984        Self {
985            box_shadow: ThemeBoxShadowScale {
986                _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, black(0.24), false)),
987                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, black(0.30), false)),
988                sm: ThemeShadow::double(
989                    shadow_layer(0.0, 2.0, 6.0, 0.0, black(0.32), false),
990                    shadow_layer(0.0, 1.0, 2.0, -1.0, black(0.28), false),
991                ),
992                md: ThemeShadow::single(shadow_layer(0.0, 4.0, 16.0, 0.0, black(0.40), false)),
993                lg: ThemeShadow::single(shadow_layer(0.0, 10.0, 28.0, -2.0, black(0.46), false)),
994                xl: ThemeShadow::single(shadow_layer(0.0, 20.0, 48.0, -4.0, black(0.55), false)),
995                _2xl: ThemeShadow::single(shadow_layer(0.0, 28.0, 64.0, -8.0, black(0.60), false)),
996            },
997            inset: ThemeInsetShadowScale {
998                _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, black(0.24), true)),
999                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black(0.24), true)),
1000                sm: ThemeShadow::single(shadow_layer(0.0, 2.0, 4.0, 0.0, black(0.24), true)),
1001            },
1002            drop: ThemeDropShadowScale {
1003                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black(0.24), false)),
1004                sm: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, black(0.34), false)),
1005                md: ThemeShadow::single(shadow_layer(0.0, 3.0, 3.0, 0.0, black(0.32), false)),
1006                lg: ThemeShadow::single(shadow_layer(0.0, 4.0, 4.0, 0.0, black(0.34), false)),
1007                xl: ThemeShadow::single(shadow_layer(0.0, 9.0, 7.0, 0.0, black(0.30), false)),
1008                _2xl: ThemeShadow::single(shadow_layer(0.0, 25.0, 25.0, 0.0, black(0.34), false)),
1009            },
1010            text: ThemeTextShadowScale {
1011                _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, black(0.30), false)),
1012                xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black(0.36), false)),
1013                sm: ThemeShadow::double(
1014                    shadow_layer(0.0, 1.0, 0.0, 0.0, black(0.20), false),
1015                    shadow_layer(0.0, 1.0, 1.0, 0.0, black(0.20), false),
1016                ),
1017                md: ThemeShadow::double(
1018                    shadow_layer(0.0, 1.0, 1.0, 0.0, black(0.24), false),
1019                    shadow_layer(0.0, 2.0, 4.0, 0.0, black(0.24), false),
1020                ),
1021                lg: ThemeShadow::double(
1022                    shadow_layer(0.0, 1.0, 2.0, 0.0, black(0.24), false),
1023                    shadow_layer(0.0, 4.0, 8.0, 0.0, black(0.24), false),
1024                ),
1025            },
1026        }
1027    }
1028
1029    /// No shadows anywhere: the Void/OLED elevation contract. Shadows are dead
1030    /// pixels on OLED; surfaces separate with borders instead.
1031    pub fn none() -> Self {
1032        let empty_box = ThemeBoxShadowScale {
1033            _2xs: ThemeShadow::empty(),
1034            xs: ThemeShadow::empty(),
1035            sm: ThemeShadow::empty(),
1036            md: ThemeShadow::empty(),
1037            lg: ThemeShadow::empty(),
1038            xl: ThemeShadow::empty(),
1039            _2xl: ThemeShadow::empty(),
1040        };
1041
1042        Self {
1043            box_shadow: empty_box,
1044            inset: ThemeInsetShadowScale {
1045                _2xs: ThemeShadow::empty(),
1046                xs: ThemeShadow::empty(),
1047                sm: ThemeShadow::empty(),
1048            },
1049            drop: ThemeDropShadowScale {
1050                xs: ThemeShadow::empty(),
1051                sm: ThemeShadow::empty(),
1052                md: ThemeShadow::empty(),
1053                lg: ThemeShadow::empty(),
1054                xl: ThemeShadow::empty(),
1055                _2xl: ThemeShadow::empty(),
1056            },
1057            text: ThemeTextShadowScale {
1058                _2xs: ThemeShadow::empty(),
1059                xs: ThemeShadow::empty(),
1060                sm: ThemeShadow::empty(),
1061                md: ThemeShadow::empty(),
1062                lg: ThemeShadow::empty(),
1063            },
1064        }
1065    }
1066}
1067
1068/// Glow tokens: soft zero-offset halos reserved for **live signals** (streaming,
1069/// voice, busy indicators, the primary action). Mesh keeps Light glow-free
1070/// (light does not glow on paper), gives Dark full glows, and damps Void to
1071/// protect OLED panels. Paint with [`paint_theme_shadow`].
1072#[derive(Debug, Clone, Copy, PartialEq)]
1073pub struct ThemeGlows {
1074    /// Accent-hued glow: live/primary signals (`--sm-glow-accent`).
1075    pub accent: ThemeShadow,
1076    /// Secondary-hued glow: voice/duplex signals (`--sm-glow-voice`).
1077    pub secondary: ThemeShadow,
1078}
1079
1080impl ThemeGlows {
1081    /// Choose glow tokens for a complete built-in color palette.
1082    pub fn for_colors(colors: &ThemeColors) -> Self {
1083        if is_neutral_theme(colors) {
1084            match colors.scheme {
1085                ThemeColorScheme::Light => Self::none(),
1086                ThemeColorScheme::Dark => Self::neutral_dark(),
1087                ThemeColorScheme::HighContrast => Self::none(),
1088            }
1089        } else {
1090            Self::for_scheme(colors.scheme)
1091        }
1092    }
1093
1094    pub fn for_scheme(scheme: ThemeColorScheme) -> Self {
1095        match scheme {
1096            ThemeColorScheme::Light => Self::none(),
1097            ThemeColorScheme::Dark => Self {
1098                accent: ThemeShadow::single(shadow_layer(
1099                    0.0,
1100                    0.0,
1101                    16.0,
1102                    0.0,
1103                    rgb8(53, 210, 238).with_alpha(0.22),
1104                    false,
1105                )),
1106                secondary: ThemeShadow::single(shadow_layer(
1107                    0.0,
1108                    0.0,
1109                    18.0,
1110                    0.0,
1111                    rgb8(143, 125, 248).with_alpha(0.26),
1112                    false,
1113                )),
1114            },
1115            ThemeColorScheme::HighContrast => Self {
1116                accent: ThemeShadow::single(shadow_layer(
1117                    0.0,
1118                    0.0,
1119                    10.0,
1120                    0.0,
1121                    rgb8(33, 199, 229).with_alpha(0.14),
1122                    false,
1123                )),
1124                secondary: ThemeShadow::single(shadow_layer(
1125                    0.0,
1126                    0.0,
1127                    12.0,
1128                    0.0,
1129                    rgb8(143, 125, 248).with_alpha(0.16),
1130                    false,
1131                )),
1132            },
1133        }
1134    }
1135
1136    pub fn none() -> Self {
1137        Self {
1138            accent: ThemeShadow::empty(),
1139            secondary: ThemeShadow::empty(),
1140        }
1141    }
1142
1143    /// Subtle achromatic halos for live signals in the neutral dark preset.
1144    pub fn neutral_dark() -> Self {
1145        Self {
1146            accent: ThemeShadow::single(shadow_layer(
1147                0.0,
1148                0.0,
1149                12.0,
1150                0.0,
1151                rgb8(245, 245, 245).with_alpha(0.12),
1152                false,
1153            )),
1154            secondary: ThemeShadow::single(shadow_layer(
1155                0.0,
1156                0.0,
1157                14.0,
1158                0.0,
1159                rgb8(163, 163, 163).with_alpha(0.12),
1160                false,
1161            )),
1162        }
1163    }
1164}
1165
1166impl Default for ThemeGlows {
1167    fn default() -> Self {
1168        Self::for_scheme(ThemeColorScheme::Light)
1169    }
1170}
1171
1172#[derive(Debug, Clone, Copy, PartialEq)]
1173pub struct ThemeBlurScale {
1174    pub xs: f32,
1175    pub sm: f32,
1176    pub md: f32,
1177    pub lg: f32,
1178    pub xl: f32,
1179    pub _2xl: f32,
1180    pub _3xl: f32,
1181}
1182
1183impl Default for ThemeBlurScale {
1184    fn default() -> Self {
1185        Self {
1186            xs: 4.0,
1187            sm: 8.0,
1188            md: 12.0,
1189            lg: 16.0,
1190            xl: 24.0,
1191            _2xl: 40.0,
1192            _3xl: 64.0,
1193        }
1194    }
1195}
1196
1197#[derive(Debug, Clone, Copy, PartialEq)]
1198pub struct ThemePerspective {
1199    pub dramatic: f32,
1200    pub near: f32,
1201    pub normal: f32,
1202    pub midrange: f32,
1203    pub distant: f32,
1204}
1205
1206impl Default for ThemePerspective {
1207    fn default() -> Self {
1208        Self {
1209            dramatic: 100.0,
1210            near: 300.0,
1211            normal: 500.0,
1212            midrange: 800.0,
1213            distant: 1200.0,
1214        }
1215    }
1216}
1217
1218#[derive(Debug, Clone, Copy, PartialEq)]
1219pub struct ThemeAspectRatios {
1220    pub video: f32,
1221}
1222
1223impl Default for ThemeAspectRatios {
1224    fn default() -> Self {
1225        Self { video: 16.0 / 9.0 }
1226    }
1227}
1228
1229/// Exact semantic role values for built-in themes. The SUI design language
1230/// specifies its light/dark/void roles directly, and the neutral preset uses
1231/// its own grayscale role table. Custom [`ThemeColors`] continue to use the
1232/// generic mix-based derivation.
1233#[derive(Debug, Clone, Copy, PartialEq)]
1234struct BuiltinColorRoles {
1235    bg_subtle: Color,
1236    surface: Color,
1237    surface_2: Color,
1238    surface_3: Color,
1239    overlay: Color,
1240    field: Color,
1241    border: Color,
1242    border_strong: Color,
1243    border_subtle: Color,
1244    text_2: Color,
1245    text_3: Color,
1246    text_disabled: Color,
1247    text_invert: Color,
1248    accent_hover: Color,
1249    accent_text: Color,
1250    accent_soft: Color,
1251    accent_border: Color,
1252    ok_text: Color,
1253    ok_soft: Color,
1254    warn_text: Color,
1255    warn_soft: Color,
1256    danger_text: Color,
1257    danger_soft: Color,
1258    danger_hover: Color,
1259    info_text: Color,
1260    info_soft: Color,
1261    focus: Color,
1262    selection: Color,
1263    scrim: Color,
1264}
1265
1266/// Look up the exact role table for one of the built-in themes. Returns
1267/// `None` for custom palettes, which fall back to derived roles.
1268fn builtin_color_roles(colors: &ThemeColors) -> Option<BuiltinColorRoles> {
1269    match (colors.name, colors.scheme) {
1270        ("light", ThemeColorScheme::Light) => Some(BuiltinColorRoles {
1271            bg_subtle: rgb8(247, 248, 250),
1272            surface: rgb8(255, 255, 255),
1273            surface_2: rgb8(243, 245, 248),
1274            surface_3: rgb8(234, 238, 243),
1275            overlay: rgb8(255, 255, 255),
1276            // A quiet inset well against the white card surface. Interactive
1277            // fields lift back toward white on hover and use the soft accent
1278            // surface while focused.
1279            field: rgb8(248, 250, 252),
1280            border: rgb8(227, 232, 239),
1281            border_strong: rgb8(205, 213, 224),
1282            border_subtle: rgb8(238, 241, 246),
1283            text_2: rgb8(73, 84, 107),
1284            text_3: rgb8(104, 115, 144),
1285            text_disabled: rgb8(163, 173, 194),
1286            text_invert: rgb8(255, 255, 255),
1287            accent_hover: rgb8(7, 109, 144),
1288            accent_text: rgb8(8, 124, 164),
1289            accent_soft: rgba8(8, 124, 164, 0.08),
1290            accent_border: rgba8(8, 124, 164, 0.35),
1291            ok_text: rgb8(21, 128, 61),
1292            ok_soft: rgba8(22, 163, 74, 0.10),
1293            warn_text: rgb8(154, 103, 0),
1294            warn_soft: rgba8(154, 103, 0, 0.10),
1295            danger_text: rgb8(217, 45, 32),
1296            danger_soft: rgba8(217, 45, 32, 0.08),
1297            danger_hover: rgb8(180, 35, 24),
1298            info_text: rgb8(23, 92, 211),
1299            info_soft: rgba8(41, 112, 255, 0.09),
1300            focus: rgb8(9, 148, 198),
1301            selection: rgba8(8, 124, 164, 0.18),
1302            scrim: rgba8(9, 12, 20, 0.45),
1303        }),
1304        ("neutral", ThemeColorScheme::Light) => Some(BuiltinColorRoles {
1305            bg_subtle: rgb8(250, 250, 250),
1306            surface: Color::WHITE,
1307            surface_2: rgb8(245, 245, 245),
1308            surface_3: rgb8(229, 229, 229),
1309            overlay: Color::WHITE,
1310            field: rgb8(250, 250, 250),
1311            border: rgb8(229, 229, 229),
1312            border_strong: rgb8(212, 212, 212),
1313            border_subtle: rgb8(240, 240, 240),
1314            text_2: rgb8(82, 82, 82),
1315            text_3: rgb8(115, 115, 115),
1316            text_disabled: rgb8(163, 163, 163),
1317            text_invert: Color::WHITE,
1318            accent_hover: rgb8(38, 38, 38),
1319            accent_text: rgb8(23, 23, 23),
1320            accent_soft: rgba8(23, 23, 23, 0.06),
1321            accent_border: rgba8(23, 23, 23, 0.28),
1322            ok_text: rgb8(21, 128, 61),
1323            ok_soft: rgba8(21, 128, 61, 0.10),
1324            warn_text: rgb8(146, 64, 14),
1325            warn_soft: rgba8(180, 83, 9, 0.10),
1326            danger_text: rgb8(185, 28, 28),
1327            danger_soft: rgba8(185, 28, 28, 0.08),
1328            danger_hover: rgb8(153, 27, 27),
1329            info_text: rgb8(29, 78, 216),
1330            info_soft: rgba8(37, 99, 235, 0.09),
1331            focus: rgb8(64, 64, 64),
1332            selection: rgba8(23, 23, 23, 0.12),
1333            scrim: Color::BLACK.with_alpha(0.45),
1334        }),
1335        ("neutral-dark", ThemeColorScheme::Dark) => Some(BuiltinColorRoles {
1336            bg_subtle: rgb8(10, 10, 10),
1337            surface: rgb8(23, 23, 23),
1338            surface_2: rgb8(38, 38, 38),
1339            surface_3: rgb8(51, 51, 51),
1340            overlay: rgb8(31, 31, 31),
1341            field: rgb8(18, 18, 18),
1342            border: Color::WHITE.with_alpha(0.14),
1343            border_strong: Color::WHITE.with_alpha(0.22),
1344            border_subtle: Color::WHITE.with_alpha(0.08),
1345            text_2: rgb8(212, 212, 212),
1346            text_3: rgb8(163, 163, 163),
1347            text_disabled: rgb8(115, 115, 115),
1348            text_invert: rgb8(23, 23, 23),
1349            accent_hover: Color::WHITE,
1350            accent_text: rgb8(245, 245, 245),
1351            accent_soft: Color::WHITE.with_alpha(0.10),
1352            accent_border: Color::WHITE.with_alpha(0.28),
1353            ok_text: rgb8(74, 222, 128),
1354            ok_soft: rgba8(74, 222, 128, 0.12),
1355            warn_text: rgb8(251, 191, 36),
1356            warn_soft: rgba8(251, 191, 36, 0.12),
1357            danger_text: rgb8(248, 113, 113),
1358            danger_soft: rgba8(248, 113, 113, 0.12),
1359            danger_hover: rgb8(252, 165, 165),
1360            info_text: rgb8(147, 197, 253),
1361            info_soft: rgba8(96, 165, 250, 0.12),
1362            focus: rgb8(212, 212, 212),
1363            selection: Color::WHITE.with_alpha(0.16),
1364            scrim: Color::BLACK.with_alpha(0.65),
1365        }),
1366        ("dark", ThemeColorScheme::Dark) => Some(BuiltinColorRoles {
1367            bg_subtle: rgb8(14, 18, 26),
1368            surface: rgb8(18, 22, 31),
1369            surface_2: rgb8(23, 28, 39),
1370            surface_3: rgb8(29, 36, 49),
1371            overlay: rgb8(22, 27, 38),
1372            field: rgb8(15, 19, 27),
1373            border: rgba8(151, 168, 199, 0.16),
1374            border_strong: rgba8(151, 168, 199, 0.27),
1375            border_subtle: rgba8(151, 168, 199, 0.09),
1376            text_2: rgb8(166, 178, 200),
1377            text_3: rgb8(124, 137, 163),
1378            text_disabled: rgb8(81, 93, 117),
1379            text_invert: rgb8(13, 18, 32),
1380            accent_hover: rgb8(95, 224, 246),
1381            accent_text: rgb8(83, 215, 240),
1382            accent_soft: rgba8(53, 210, 238, 0.12),
1383            accent_border: rgba8(53, 210, 238, 0.35),
1384            ok_text: rgb8(74, 222, 128),
1385            ok_soft: rgba8(74, 222, 128, 0.12),
1386            warn_text: rgb8(253, 176, 34),
1387            warn_soft: rgba8(253, 176, 34, 0.12),
1388            danger_text: rgb8(249, 112, 102),
1389            danger_soft: rgba8(249, 112, 102, 0.12),
1390            danger_hover: rgb8(246, 121, 125),
1391            info_text: rgb8(132, 169, 255),
1392            info_soft: rgba8(132, 169, 255, 0.12),
1393            focus: rgb8(73, 199, 234),
1394            selection: rgba8(53, 210, 238, 0.24),
1395            scrim: rgba8(2, 4, 8, 0.6),
1396        }),
1397        ("void", ThemeColorScheme::HighContrast) => Some(BuiltinColorRoles {
1398            bg_subtle: Color::BLACK,
1399            surface: Color::BLACK,
1400            surface_2: rgb8(11, 14, 20),
1401            surface_3: rgb8(19, 23, 34),
1402            overlay: rgb8(10, 13, 19),
1403            field: rgb8(11, 14, 20),
1404            border: rgba8(158, 175, 205, 0.18),
1405            border_strong: rgba8(158, 175, 205, 0.30),
1406            border_subtle: rgba8(158, 175, 205, 0.10),
1407            text_2: rgb8(153, 165, 188),
1408            text_3: rgb8(117, 129, 154),
1409            text_disabled: rgb8(72, 83, 107),
1410            text_invert: rgb8(13, 18, 32),
1411            accent_hover: rgb8(76, 212, 236),
1412            accent_text: rgb8(64, 205, 232),
1413            accent_soft: rgba8(33, 199, 229, 0.10),
1414            accent_border: rgba8(33, 199, 229, 0.32),
1415            ok_text: rgb8(64, 212, 122),
1416            ok_soft: rgba8(64, 212, 122, 0.10),
1417            warn_text: rgb8(242, 169, 31),
1418            warn_soft: rgba8(242, 169, 31, 0.10),
1419            danger_text: rgb8(244, 104, 94),
1420            danger_soft: rgba8(244, 104, 94, 0.10),
1421            danger_hover: rgb8(240, 104, 109),
1422            info_text: rgb8(123, 162, 252),
1423            info_soft: rgba8(123, 162, 252, 0.10),
1424            focus: rgb8(63, 196, 228),
1425            selection: rgba8(33, 199, 229, 0.22),
1426            scrim: rgba8(0, 0, 0, 0.72),
1427        }),
1428        _ => None,
1429    }
1430}
1431
1432#[derive(Debug, Clone, Copy, PartialEq)]
1433pub struct ControlPalette {
1434    pub text: Color,
1435    pub text_muted: Color,
1436    pub placeholder: Color,
1437    pub surface: Color,
1438    pub surface_raised: Color,
1439    pub control: Color,
1440    pub control_hover: Color,
1441    pub control_active: Color,
1442    /// Inset field background for text inputs and editable surfaces
1443    /// (`--sm-field-bg`). Distinct from `control`, the raised neutral fill
1444    /// used by buttons and similar controls (`--sm-surface-2`).
1445    pub field: Color,
1446    pub surface_hover: Color,
1447    pub surface_pressed: Color,
1448    pub surface_focus: Color,
1449    pub border: Color,
1450    pub border_strong: Color,
1451    pub border_hover: Color,
1452    pub border_focus: Color,
1453    /// The dedicated keyboard focus color (`--sm-focus`): a solid ring drawn
1454    /// at `focus_ring_width` with `focus_ring_outset` offset.
1455    pub focus: Color,
1456    pub focus_ring: Color,
1457    pub caret: Color,
1458    pub selection: Color,
1459    pub accent: Color,
1460    pub accent_hover: Color,
1461    pub accent_pressed: Color,
1462    pub accent_border: Color,
1463    pub accent_border_hover: Color,
1464    pub accent_border_focus: Color,
1465    pub accent_text: Color,
1466    /// Translucent accent wash (`--sm-accent-soft`): selected rows, badges,
1467    /// input focus halos. Pair with `accent_soft_text` for legible content.
1468    pub accent_soft: Color,
1469    /// Accent-hued text that stays legible on plain and soft surfaces
1470    /// (`--sm-accent-text` in Mesh terms; `accent_text` remains the
1471    /// on-solid-accent content color).
1472    pub accent_soft_text: Color,
1473    pub info: Color,
1474    pub info_text: Color,
1475    pub info_soft: Color,
1476    pub info_soft_text: Color,
1477    pub success: Color,
1478    pub success_text: Color,
1479    pub success_soft: Color,
1480    pub success_soft_text: Color,
1481    pub warning: Color,
1482    pub warning_text: Color,
1483    pub warning_soft: Color,
1484    pub warning_soft_text: Color,
1485    pub danger: Color,
1486    pub danger_text: Color,
1487    pub danger_soft: Color,
1488    pub danger_soft_text: Color,
1489    pub danger_hover: Color,
1490}
1491
1492impl ControlPalette {
1493    pub fn from_colors(colors: &ThemeColors) -> Self {
1494        let is_dark = matches!(
1495            colors.scheme,
1496            ThemeColorScheme::Dark | ThemeColorScheme::HighContrast
1497        );
1498        let roles = builtin_color_roles(colors);
1499        let surface = colors.base_100;
1500        let surface_raised = roles.map(|r| r.surface).unwrap_or(colors.base_200);
1501        // Mesh authors its translucent tokens as CSS rgba values, which
1502        // composite in encoded (gamma) space. The renderer blends in linear
1503        // space — noticeably heavier — so translucent roles are flattened
1504        // onto the card surface here with the CSS arithmetic.
1505        let flatten = move |color: Color| color.over(surface_raised);
1506        // Neutral raised control fill (buttons, chips): Mesh `--sm-surface-2`.
1507        let control = roles.map(|r| r.surface_2).unwrap_or(colors.base_200);
1508        let control_hover = roles
1509            .map(|r| r.surface_3)
1510            .unwrap_or_else(|| interactive_surface(control, colors.scheme, 0.035));
1511        let control_active = roles
1512            .map(|r| mix(r.surface_3, colors.base_content, 0.04))
1513            .unwrap_or_else(|| interactive_surface(control, colors.scheme, 0.075));
1514        let field = roles.map(|r| r.field).unwrap_or(control);
1515        let text_muted = roles.map(|r| r.text_2).unwrap_or_else(|| {
1516            mix(
1517                colors.base_content,
1518                surface,
1519                if is_dark { 0.34 } else { 0.16 },
1520            )
1521        });
1522        let placeholder = roles.map(|r| r.text_3).unwrap_or_else(|| {
1523            mix(
1524                colors.base_content,
1525                surface,
1526                if is_dark { 0.50 } else { 0.22 },
1527            )
1528        });
1529        let border = roles.map(|r| flatten(r.border)).unwrap_or_else(|| {
1530            if is_dark {
1531                mix(colors.base_300, surface, 0.22)
1532            } else {
1533                colors.base_300
1534            }
1535        });
1536        let border_strong = roles.map(|r| flatten(r.border_strong)).unwrap_or_else(|| {
1537            mix(
1538                colors.base_300,
1539                colors.base_content,
1540                if is_dark { 0.18 } else { 0.10 },
1541            )
1542        });
1543        // Hovered controls strengthen their border rather than tinting toward
1544        // the accent (Mesh keeps accent reserved for live signals).
1545        let border_hover = roles
1546            .map(|r| flatten(r.border_strong))
1547            .unwrap_or_else(|| mix(border, colors.primary, if is_dark { 0.28 } else { 0.18 }));
1548        let border_focus = colors.primary;
1549        let focus = roles.map(|r| r.focus).unwrap_or(colors.primary);
1550        let selection = roles
1551            .map(|r| flatten(r.selection))
1552            .unwrap_or_else(|| mix(surface, colors.primary, if is_dark { 0.30 } else { 0.14 }));
1553        // Fallback derivations for soft washes and on-surface status text used
1554        // by custom themes; built-ins take the exact Mesh values.
1555        let soft_alpha = if is_dark { 0.12 } else { 0.10 };
1556        let derived_soft = move |color: Color| color.with_alpha(soft_alpha).over(surface_raised);
1557        let derived_soft_text = |color: Color| {
1558            if is_dark {
1559                mix(color, Color::WHITE, 0.22)
1560            } else {
1561                mix(color, Color::BLACK, 0.12)
1562            }
1563        };
1564
1565        Self {
1566            text: colors.base_content,
1567            text_muted,
1568            placeholder,
1569            surface,
1570            surface_raised,
1571            control,
1572            control_hover,
1573            control_active,
1574            field,
1575            surface_hover: control_hover,
1576            surface_pressed: control_active,
1577            surface_focus: roles
1578                .map(|r| flatten(r.accent_soft))
1579                .unwrap_or_else(|| mix(control, colors.primary, if is_dark { 0.14 } else { 0.08 })),
1580            border,
1581            border_strong,
1582            border_hover,
1583            border_focus,
1584            focus,
1585            focus_ring: focus,
1586            caret: colors.primary,
1587            selection,
1588            accent: colors.primary,
1589            accent_hover: roles
1590                .map(|r| r.accent_hover)
1591                .unwrap_or_else(|| interactive_variant(colors.primary, colors.scheme, 0.08)),
1592            accent_pressed: interactive_variant(colors.primary, colors.scheme, 0.16),
1593            accent_border: roles
1594                .map(|r| flatten(r.accent_border))
1595                .unwrap_or_else(|| interactive_variant(colors.primary, colors.scheme, 0.12)),
1596            accent_border_hover: roles
1597                .map(|r| flatten(r.accent_border))
1598                .unwrap_or_else(|| interactive_variant(colors.primary, colors.scheme, 0.2)),
1599            accent_border_focus: colors.primary,
1600            accent_text: colors.primary_content,
1601            accent_soft: roles
1602                .map(|r| flatten(r.accent_soft))
1603                .unwrap_or_else(|| derived_soft(colors.primary)),
1604            accent_soft_text: roles
1605                .map(|r| r.accent_text)
1606                .unwrap_or_else(|| derived_soft_text(colors.primary)),
1607            info: colors.info,
1608            info_text: colors.info_content,
1609            info_soft: roles
1610                .map(|r| flatten(r.info_soft))
1611                .unwrap_or_else(|| derived_soft(colors.info)),
1612            info_soft_text: roles
1613                .map(|r| r.info_text)
1614                .unwrap_or_else(|| derived_soft_text(colors.info)),
1615            success: colors.success,
1616            success_text: colors.success_content,
1617            success_soft: roles
1618                .map(|r| flatten(r.ok_soft))
1619                .unwrap_or_else(|| derived_soft(colors.success)),
1620            success_soft_text: roles
1621                .map(|r| r.ok_text)
1622                .unwrap_or_else(|| derived_soft_text(colors.success)),
1623            warning: colors.warning,
1624            warning_text: colors.warning_content,
1625            warning_soft: roles
1626                .map(|r| flatten(r.warn_soft))
1627                .unwrap_or_else(|| derived_soft(colors.warning)),
1628            warning_soft_text: roles
1629                .map(|r| r.warn_text)
1630                .unwrap_or_else(|| derived_soft_text(colors.warning)),
1631            danger: colors.error,
1632            danger_text: colors.error_content,
1633            danger_soft: roles
1634                .map(|r| flatten(r.danger_soft))
1635                .unwrap_or_else(|| derived_soft(colors.error)),
1636            danger_soft_text: roles
1637                .map(|r| r.danger_text)
1638                .unwrap_or_else(|| derived_soft_text(colors.error)),
1639            danger_hover: roles
1640                .map(|r| r.danger_hover)
1641                .unwrap_or_else(|| interactive_variant(colors.error, colors.scheme, 0.08)),
1642        }
1643    }
1644}
1645
1646impl Default for ControlPalette {
1647    fn default() -> Self {
1648        Self::from_colors(&ThemeColors::default())
1649    }
1650}
1651
1652#[derive(Debug, Clone, Copy, PartialEq)]
1653pub struct SurfacePalette {
1654    pub dark: bool,
1655    pub window: Color,
1656    /// Slightly recessed window background (`--sm-bg-subtle`): sidebars,
1657    /// table headers, code block chrome.
1658    pub window_subtle: Color,
1659    pub sidebar: Color,
1660    pub panel: Color,
1661    /// Nested/raised fill one step above `panel` (`--sm-surface-2`).
1662    pub surface_2: Color,
1663    /// The strongest neutral fill tier (`--sm-surface-3`): hover wells,
1664    /// track backgrounds, avatar fills.
1665    pub surface_3: Color,
1666    /// Floating surface for menus, popovers, dialogs, toasts (`--sm-overlay`).
1667    pub overlay: Color,
1668    pub titlebar: Color,
1669    pub field: Color,
1670    pub border: Color,
1671    pub border_strong: Color,
1672    /// Hairline separators inside components (`--sm-border-subtle`).
1673    pub border_subtle: Color,
1674    pub text: Color,
1675    pub text_muted: Color,
1676    pub text_faint: Color,
1677    /// Disabled content (`--sm-text-disabled`).
1678    pub text_disabled: Color,
1679    /// Content drawn on inverted surfaces (`--sm-text-invert`).
1680    pub text_invert: Color,
1681    pub accent: Color,
1682    pub accent_hover: Color,
1683    pub on_accent: Color,
1684    /// Accent-hued text legible on plain surfaces (`--sm-accent-text`).
1685    pub accent_text: Color,
1686    /// Translucent accent wash (`--sm-accent-soft`).
1687    pub accent_soft: Color,
1688    /// Translucent accent border (`--sm-accent-border`).
1689    pub accent_border: Color,
1690    /// The dedicated keyboard-focus ring color (`--sm-focus`).
1691    pub focus: Color,
1692    pub hover: Color,
1693    pub selected: Color,
1694    pub overlay_scrim: Color,
1695    pub tooltip: Color,
1696    pub tooltip_border: Color,
1697    pub tooltip_text: Color,
1698    pub canvas: Color,
1699    pub canvas_grid: Color,
1700    pub canvas_axis_x: Color,
1701    pub canvas_axis_y: Color,
1702    pub pixel_canvas_paper: Color,
1703    pub pixel_canvas_document_edge: Color,
1704    pub pixel_canvas_shadow_near: Color,
1705    pub pixel_canvas_shadow_far: Color,
1706    pub pixel_canvas_grid: Color,
1707    pub canvas_ruler: Color,
1708    pub canvas_ruler_border: Color,
1709    pub canvas_ruler_tick: Color,
1710    pub canvas_ruler_text: Color,
1711    pub checkerboard_light: Color,
1712    pub checkerboard_dark: Color,
1713    pub color_picker_chrome_border: Color,
1714    pub color_picker_plane_border: Color,
1715    pub color_picker_bar_border: Color,
1716    pub color_picker_marker_outer: Color,
1717    pub color_picker_marker_dark: Color,
1718    pub color_picker_marker_light: Color,
1719    pub color_picker_sdr_marker: Color,
1720    pub color_picker_hdr_divider: Color,
1721    pub good: Color,
1722    /// Positive-status text legible on plain/soft surfaces (`--sm-ok-text`).
1723    pub good_text: Color,
1724    /// Translucent positive wash (`--sm-ok-soft`).
1725    pub good_soft: Color,
1726    pub warn: Color,
1727    /// Warning text legible on plain/soft surfaces (`--sm-warn-text`).
1728    pub warn_text: Color,
1729    /// Translucent warning wash (`--sm-warn-soft`).
1730    pub warn_soft: Color,
1731    pub bad: Color,
1732    /// Danger text legible on plain/soft surfaces (`--sm-danger-text`).
1733    pub bad_text: Color,
1734    /// Translucent danger wash (`--sm-danger-soft`).
1735    pub bad_soft: Color,
1736    /// Solid informational status (`--sm-info`).
1737    pub info: Color,
1738    /// Informational text legible on plain/soft surfaces (`--sm-info-text`).
1739    pub info_text: Color,
1740    /// Translucent informational wash (`--sm-info-soft`).
1741    pub info_soft: Color,
1742}
1743
1744impl SurfacePalette {
1745    pub fn from_theme_parts(colors: &ThemeColors, controls: &ControlPalette) -> Self {
1746        let dark = matches!(
1747            colors.scheme,
1748            ThemeColorScheme::Dark | ThemeColorScheme::HighContrast
1749        );
1750        let neutral = is_neutral_theme(colors);
1751        let roles = builtin_color_roles(colors);
1752        let text_muted = controls.text_muted;
1753        let text_faint = controls.placeholder;
1754        let window_subtle = roles
1755            .map(|r| r.bg_subtle)
1756            .unwrap_or_else(|| mix(controls.surface, controls.control, 0.4));
1757        let overlay = roles.map(|r| r.overlay).unwrap_or(controls.surface_raised);
1758
1759        Self {
1760            dark,
1761            window: controls.surface,
1762            window_subtle,
1763            // The workspace chrome (sidebars, title bars) sits on the subtle
1764            // background tier so content panes read as the brighter surface.
1765            sidebar: window_subtle,
1766            panel: controls.surface_raised,
1767            surface_2: controls.control,
1768            surface_3: controls.control_hover,
1769            overlay,
1770            titlebar: window_subtle,
1771            field: controls.field,
1772            border: controls.border,
1773            border_strong: controls.border_strong,
1774            border_subtle: roles
1775                .map(|r| r.border_subtle.over(controls.surface_raised))
1776                .unwrap_or_else(|| mix(controls.border, controls.surface_raised, 0.44)),
1777            text: controls.text,
1778            text_muted,
1779            text_faint,
1780            text_disabled: roles.map(|r| r.text_disabled).unwrap_or_else(|| {
1781                mix(
1782                    controls.text,
1783                    controls.surface,
1784                    if dark { 0.62 } else { 0.44 },
1785                )
1786            }),
1787            text_invert: roles.map(|r| r.text_invert).unwrap_or(controls.surface),
1788            accent: controls.accent,
1789            accent_hover: controls.accent_hover,
1790            on_accent: controls.accent_text,
1791            accent_text: controls.accent_soft_text,
1792            accent_soft: controls.accent_soft,
1793            accent_border: controls.accent_border,
1794            focus: controls.focus,
1795            hover: controls.text.with_alpha(if dark { 0.06 } else { 0.045 }),
1796            selected: controls.selection,
1797            overlay_scrim: roles
1798                .map(|r| r.scrim)
1799                .unwrap_or_else(|| Color::rgba(0.06, 0.08, 0.12, if dark { 0.38 } else { 0.24 })),
1800            // Mesh tooltips are quiet floating surfaces, not inverted bubbles:
1801            // overlay fill, strong border, secondary ink.
1802            tooltip: overlay,
1803            tooltip_border: controls.border_strong,
1804            tooltip_text: text_muted,
1805            canvas: controls.surface,
1806            canvas_grid: controls.border.with_alpha(if dark { 0.30 } else { 0.18 }),
1807            canvas_axis_x: colors.error.with_alpha(if dark { 0.72 } else { 0.55 }),
1808            canvas_axis_y: colors.success.with_alpha(if dark { 0.72 } else { 0.55 }),
1809            pixel_canvas_paper: if dark {
1810                mix(controls.surface_raised, controls.text, 0.10)
1811            } else if neutral {
1812                rgb8(250, 250, 250)
1813            } else {
1814                Color::rgba(0.975, 0.980, 0.988, 1.0)
1815            },
1816            pixel_canvas_document_edge: controls.text.with_alpha(if dark { 0.82 } else { 0.72 }),
1817            pixel_canvas_shadow_near: if neutral {
1818                Color::BLACK.with_alpha(if dark { 0.30 } else { 0.16 })
1819            } else {
1820                Color::rgba(0.05, 0.07, 0.10, if dark { 0.30 } else { 0.16 })
1821            },
1822            pixel_canvas_shadow_far: if neutral {
1823                Color::BLACK.with_alpha(if dark { 0.18 } else { 0.08 })
1824            } else {
1825                Color::rgba(0.05, 0.07, 0.10, if dark { 0.18 } else { 0.08 })
1826            },
1827            pixel_canvas_grid: controls.text.with_alpha(if dark { 0.32 } else { 0.28 }),
1828            canvas_ruler: controls.surface_raised,
1829            canvas_ruler_border: controls.border.with_alpha(0.78),
1830            canvas_ruler_tick: controls.text_muted.with_alpha(0.72),
1831            canvas_ruler_text: controls.text.with_alpha(0.76),
1832            checkerboard_light: if dark {
1833                mix(controls.surface_raised, controls.text, 0.18)
1834            } else if neutral {
1835                rgb8(250, 250, 250)
1836            } else {
1837                Color::rgba(0.980, 0.980, 0.990, 1.0)
1838            },
1839            checkerboard_dark: if dark {
1840                mix(controls.surface_raised, controls.text, 0.10)
1841            } else if neutral {
1842                rgb8(229, 229, 229)
1843            } else {
1844                Color::rgba(0.900, 0.920, 0.950, 1.0)
1845            },
1846            color_picker_chrome_border: controls.text.with_alpha(if dark { 0.24 } else { 0.18 }),
1847            color_picker_plane_border: controls.text.with_alpha(if dark { 0.22 } else { 0.16 }),
1848            color_picker_bar_border: controls.text.with_alpha(if dark { 0.20 } else { 0.14 }),
1849            color_picker_marker_outer: controls.surface_raised.with_alpha(0.92),
1850            color_picker_marker_dark: Color::BLACK.with_alpha(0.84),
1851            color_picker_marker_light: Color::WHITE.with_alpha(0.95),
1852            color_picker_sdr_marker: controls.surface_raised.with_alpha(0.30),
1853            color_picker_hdr_divider: controls.surface_raised.with_alpha(0.28),
1854            good: colors.success,
1855            good_text: controls.success_soft_text,
1856            good_soft: controls.success_soft,
1857            warn: colors.warning,
1858            warn_text: controls.warning_soft_text,
1859            warn_soft: controls.warning_soft,
1860            bad: colors.error,
1861            bad_text: controls.danger_soft_text,
1862            bad_soft: controls.danger_soft,
1863            info: colors.info,
1864            info_text: controls.info_soft_text,
1865            info_soft: controls.info_soft,
1866        }
1867    }
1868}
1869
1870impl Default for SurfacePalette {
1871    fn default() -> Self {
1872        let colors = ThemeColors::default();
1873        let controls = ControlPalette::from_colors(&colors);
1874        Self::from_theme_parts(&colors, &controls)
1875    }
1876}
1877
1878#[derive(Debug, Clone, Copy, PartialEq)]
1879pub struct ControlTypography {
1880    pub body_font_size: f32,
1881    pub body_line_height: f32,
1882}
1883
1884impl ControlTypography {
1885    pub fn from_text_scale(text: &ThemeTextScale) -> Self {
1886        Self::for_density(text, ThemeDensity::default())
1887    }
1888
1889    /// Legacy density typography. Authored interfaces should prefer
1890    /// [`Self::for_size`]; the legacy Compact/Comfortable/Touch tiers mirror
1891    /// Small/Medium/Large so both paths resolve the same text-ramp tokens.
1892    pub fn for_density(text: &ThemeTextScale, density: ThemeDensity) -> Self {
1893        let token = match density {
1894            ThemeDensity::Compact => text.sm,
1895            ThemeDensity::Comfortable => text.base,
1896            ThemeDensity::Touch => text.lg,
1897        };
1898        Self {
1899            body_font_size: token.size,
1900            body_line_height: token.line_height,
1901        }
1902    }
1903
1904    /// Resolve authored interface-size typography from the current text scale.
1905    /// Text scaling remains independent: each size selects a token from the
1906    /// already-scaled ramp instead of applying another multiplier.
1907    pub fn for_size(text: &ThemeTextScale, size: ControlSize) -> Self {
1908        let token = match size {
1909            ControlSize::Small => text.sm,
1910            ControlSize::Medium => text.base,
1911            ControlSize::Large => text.lg,
1912        };
1913        Self {
1914            body_font_size: token.size,
1915            body_line_height: token.line_height,
1916        }
1917    }
1918}
1919
1920impl Default for ControlTypography {
1921    fn default() -> Self {
1922        Self::from_text_scale(&ThemeTextScale::default())
1923    }
1924}
1925
1926#[derive(Debug, Clone, Copy, PartialEq)]
1927pub struct ControlStateMetrics {
1928    pub hover_blend: f32,
1929    pub pressed_blend: f32,
1930    pub selected_blend: f32,
1931    pub tab_selected_blend: f32,
1932    pub disabled_opacity: f32,
1933    pub disabled_content_opacity: f32,
1934    pub pressed_offset: f32,
1935    pub active_indicator_thickness: f32,
1936}
1937
1938impl ControlStateMetrics {
1939    pub fn for_density(density: ThemeDensity) -> Self {
1940        match density {
1941            ThemeDensity::Compact => Self {
1942                hover_blend: 0.78,
1943                pressed_blend: 0.88,
1944                selected_blend: 0.20,
1945                tab_selected_blend: 0.07,
1946                disabled_opacity: 0.70,
1947                disabled_content_opacity: 0.46,
1948                pressed_offset: 0.0,
1949                active_indicator_thickness: 2.0,
1950            },
1951            ThemeDensity::Comfortable => Self {
1952                hover_blend: 0.86,
1953                pressed_blend: 1.0,
1954                selected_blend: 0.22,
1955                tab_selected_blend: 0.08,
1956                disabled_opacity: 0.74,
1957                disabled_content_opacity: 0.50,
1958                pressed_offset: 0.0,
1959                active_indicator_thickness: 3.0,
1960            },
1961            ThemeDensity::Touch => Self {
1962                hover_blend: 0.94,
1963                pressed_blend: 1.0,
1964                selected_blend: 0.24,
1965                tab_selected_blend: 0.09,
1966                disabled_opacity: 0.78,
1967                disabled_content_opacity: 0.54,
1968                pressed_offset: 0.0,
1969                active_indicator_thickness: 4.0,
1970            },
1971        }
1972    }
1973}
1974
1975impl Default for ControlStateMetrics {
1976    fn default() -> Self {
1977        Self::for_density(ThemeDensity::default())
1978    }
1979}
1980
1981#[derive(Debug, Clone, Copy, PartialEq)]
1982pub struct ControlMetrics {
1983    pub min_height: f32,
1984    pub touch_target_size: f32,
1985    pub button_min_width: f32,
1986    pub button_padding: Insets,
1987    pub checkbox_padding: Insets,
1988    pub checkbox_indicator_size: f32,
1989    pub checkbox_gap: f32,
1990    pub icon_label_gap: f32,
1991    pub separator_thickness: f32,
1992    pub icon_size: f32,
1993    pub icon_button_size: f32,
1994    pub switch_track_width: f32,
1995    pub switch_track_height: f32,
1996    pub switch_thumb_inset: f32,
1997    pub slider_min_width: f32,
1998    pub slider_padding: Insets,
1999    pub slider_track_height: f32,
2000    pub slider_thumb_size: f32,
2001    pub number_input_stepper_width: f32,
2002    pub text_input_min_width: f32,
2003    pub text_input_padding: Insets,
2004    pub text_area_min_height: f32,
2005    pub select_menu_max_height: f32,
2006    pub select_menu_gap: f32,
2007    pub select_menu_edge_padding: f32,
2008    pub tab_height: f32,
2009    pub tab_min_width: f32,
2010    pub tab_gap: f32,
2011    pub tab_padding: Insets,
2012    pub tab_panel_padding: Insets,
2013    pub tab_panel_gap: f32,
2014    pub menu_row_height: f32,
2015    pub menu_padding: Insets,
2016    pub menu_item_padding: Insets,
2017    pub menu_shortcut_width: f32,
2018    pub popover_padding: Insets,
2019    pub popover_gap: f32,
2020    pub popover_reveal_offset: f32,
2021    pub tooltip_padding: Insets,
2022    pub tooltip_min_width: f32,
2023    pub tooltip_gap: f32,
2024    pub tooltip_reveal_offset: f32,
2025    pub dialog_min_width: f32,
2026    pub dialog_max_width: f32,
2027    pub dialog_outer_margin: f32,
2028    pub dialog_padding: Insets,
2029    pub dialog_title_font_size: f32,
2030    pub dialog_title_line_height: f32,
2031    pub dialog_description_gap: f32,
2032    pub dialog_body_gap: f32,
2033    pub dialog_footer_gap: f32,
2034    pub dialog_action_gap: f32,
2035    pub dialog_action_min_width: f32,
2036    pub toolbar_extent: f32,
2037    pub toolbar_padding: Insets,
2038    pub toolbar_spacing: f32,
2039    pub command_group_padding: Insets,
2040    pub command_group_spacing: f32,
2041    pub command_group_radius: f32,
2042    pub tool_palette_item_size: f32,
2043    pub tool_palette_icon_size: f32,
2044    pub preset_strip_item_height: f32,
2045    pub preset_strip_item_min_width: f32,
2046    pub preset_strip_item_padding: Insets,
2047    pub preset_strip_gap: f32,
2048    pub preset_strip_label_padding: Insets,
2049    pub action_card_min_width: f32,
2050    pub action_card_min_height: f32,
2051    pub action_card_padding: Insets,
2052    pub action_card_icon_box_size: f32,
2053    pub action_card_icon_size: f32,
2054    pub action_card_icon_gap: f32,
2055    pub action_card_text_gap: f32,
2056    pub action_card_trailing_gap: f32,
2057    pub action_card_chevron_size: f32,
2058    pub action_card_accent_width: f32,
2059    pub action_card_accent_inset: f32,
2060    pub status_bar_height: f32,
2061    pub status_bar_segment_padding: f32,
2062    pub status_bar_segment_min_width: f32,
2063    pub status_bar_separator_inset: f32,
2064    pub progress_bar_min_width: f32,
2065    pub progress_bar_height: f32,
2066    pub progress_bar_value_height: f32,
2067    pub progress_bar_label_padding: Insets,
2068    pub property_row_label_width: f32,
2069    pub property_row_inline_gap: f32,
2070    pub property_row_stacked_gap: f32,
2071    pub form_row_label_width: f32,
2072    pub form_row_control_width: f32,
2073    pub form_row_gap: f32,
2074    pub field_group_spacing: f32,
2075    pub form_section_padding: Insets,
2076    pub form_section_body_gap: f32,
2077    pub form_section_header_gap: f32,
2078    pub form_section_description_gap: f32,
2079    pub form_section_max_width: f32,
2080    pub form_section_radius: f32,
2081    pub panel_section_gap: f32,
2082    pub panel_section_action_gap: f32,
2083    pub panel_section_disclosure_size: f32,
2084    pub dock_panel_header_height: f32,
2085    pub dock_panel_padding: Insets,
2086    pub data_viewport_padding: Insets,
2087    pub data_row_padding: Insets,
2088    pub data_row_icon_size: f32,
2089    pub data_row_icon_gap: f32,
2090    pub data_row_trailing_gap: f32,
2091    pub data_scroll_thumb_width: f32,
2092    pub data_scroll_thumb_inset: f32,
2093    pub data_scroll_thumb_radius: f32,
2094    pub data_scroll_thumb_min_length: f32,
2095    pub data_scroll_thumb_opacity: f32,
2096    pub list_row_height: f32,
2097    pub layer_row_height: f32,
2098    pub layer_action_size: f32,
2099    pub layer_action_icon_inset: f32,
2100    pub layer_lock_icon_inset: f32,
2101    pub layer_visibility_stroke_width: f32,
2102    pub layer_visibility_slash_stroke_width: f32,
2103    pub layer_thumbnail_size: f32,
2104    pub layer_thumbnail_inset: f32,
2105    pub layer_thumbnail_radius: f32,
2106    pub layer_thumbnail_disabled_opacity: f32,
2107    pub layer_thumbnail_disabled_border_opacity: f32,
2108    pub tree_row_height: f32,
2109    pub tree_indent: f32,
2110    pub tree_disclosure_size: f32,
2111    pub tree_disclosure_gap: f32,
2112    pub table_row_height: f32,
2113    pub table_header_height: f32,
2114    pub table_cell_padding: f32,
2115    pub table_header_separator_inset: f32,
2116    pub table_separator_width: f32,
2117    pub table_row_border_opacity: f32,
2118    pub breadcrumb_height: f32,
2119    pub breadcrumb_item_padding: Insets,
2120    pub breadcrumb_gap: f32,
2121    pub breadcrumb_separator_size: f32,
2122    pub image_corner_radius: f32,
2123    pub color_swatch_width: f32,
2124    pub color_swatch_height: f32,
2125    pub color_swatch_inner_inset: f32,
2126    pub color_swatch_checker_size: f32,
2127    pub color_palette_swatch_size: f32,
2128    pub color_palette_gap: f32,
2129    pub color_palette_swatch_inset: f32,
2130    pub color_palette_selected_swatch_inset: f32,
2131    pub color_palette_checker_size: f32,
2132    pub brush_preview_min_width: f32,
2133    pub brush_preview_min_height: f32,
2134    pub brush_preview_padding: Insets,
2135    pub brush_preview_swatch_width: f32,
2136    pub brush_preview_swatch_gap: f32,
2137    pub brush_preview_checker_size: f32,
2138    pub brush_preview_text_height: f32,
2139    pub brush_preview_text_font_size: f32,
2140    pub brush_preview_text_line_height: f32,
2141    pub color_picker_content_inset: f32,
2142    pub color_picker_panel_gap: f32,
2143    pub color_picker_top_bar_height: f32,
2144    pub color_picker_swatch_width: f32,
2145    pub color_picker_swatch_gap: f32,
2146    pub color_picker_section_gap: f32,
2147    pub color_picker_wheel_size: f32,
2148    pub color_picker_map_size: f32,
2149    pub color_picker_row_height: f32,
2150    pub color_picker_row_gap: f32,
2151    pub color_picker_right_panel_width: f32,
2152    pub color_picker_field_height: f32,
2153    pub color_picker_field_gap: f32,
2154    pub color_picker_dropdown_gap: f32,
2155    pub color_picker_encoding_menu_row_height: f32,
2156    pub scroll_bar_thickness: f32,
2157    pub scroll_bar_min_thumb_length: f32,
2158    pub split_view_divider_thickness: f32,
2159    pub split_view_drag_target_thickness: f32,
2160    pub floating_workspace_margin: f32,
2161    pub floating_view_title_bar_height: f32,
2162    pub floating_view_title_padding: Insets,
2163    pub floating_view_resize_handle_size: f32,
2164    pub canvas_ruler_extent: f32,
2165    pub canvas_ruler_major_tick: f32,
2166    pub canvas_ruler_minor_tick: f32,
2167    pub canvas_ruler_target_major_spacing: f32,
2168    pub canvas_ruler_label_padding: Insets,
2169    pub canvas_ruler_label_max_width: f32,
2170    pub canvas_grid_step: f32,
2171    pub canvas_axis_overscan: f32,
2172    pub pixel_canvas_fit_padding: f32,
2173    pub pixel_canvas_grid_zoom: f32,
2174    pub pixel_canvas_nearest_sampling_zoom: f32,
2175    pub pixel_canvas_zoom_step: f32,
2176    pub corner_radius: f32,
2177    pub indicator_corner_radius: f32,
2178    pub border_width: f32,
2179    pub focus_ring_width: f32,
2180    pub focus_ring_outset: f32,
2181    pub caret_width: f32,
2182}
2183
2184impl ControlMetrics {
2185    pub fn from_tokens(spacing: f32, radius: ThemeRadii, density: ThemeDensity) -> Self {
2186        let unit = spacing.max(1.0);
2187        let (
2188            min_height,
2189            touch_target_size,
2190            button_padding,
2191            checkbox_padding,
2192            checkbox_indicator_size,
2193            icon_size,
2194            icon_button_size,
2195            switch_track_width,
2196            switch_track_height,
2197            switch_thumb_inset,
2198            slider_min_width,
2199            slider_padding,
2200            slider_track_height,
2201            slider_thumb_size,
2202            number_input_stepper_width,
2203            text_input_min_width,
2204            text_input_padding,
2205            text_area_min_height,
2206            select_menu_max_height,
2207            tab_height,
2208            tab_min_width,
2209            tab_padding,
2210            tab_panel_padding,
2211            tab_panel_gap,
2212            menu_row_height,
2213            menu_padding,
2214            menu_item_padding,
2215            popover_padding,
2216            action_card_min_width,
2217            action_card_min_height,
2218            action_card_padding,
2219            action_card_icon_box_size,
2220            action_card_icon_size,
2221            action_card_icon_gap,
2222            action_card_text_gap,
2223            action_card_trailing_gap,
2224            action_card_chevron_size,
2225            action_card_accent_width,
2226            action_card_accent_inset,
2227            status_bar_height,
2228            status_bar_segment_padding,
2229            status_bar_segment_min_width,
2230            status_bar_separator_inset,
2231            progress_bar_min_width,
2232            progress_bar_height,
2233            progress_bar_value_height,
2234            progress_bar_label_padding,
2235            data_viewport_padding,
2236            data_row_padding,
2237            data_row_icon_size,
2238            data_row_icon_gap,
2239            data_row_trailing_gap,
2240            list_row_height,
2241            layer_row_height,
2242            layer_action_size,
2243            layer_thumbnail_size,
2244            tree_row_height,
2245            tree_indent,
2246            tree_disclosure_size,
2247            tree_disclosure_gap,
2248            table_row_height,
2249            table_header_height,
2250            table_cell_padding,
2251            breadcrumb_height,
2252            breadcrumb_item_padding,
2253            breadcrumb_gap,
2254            breadcrumb_separator_size,
2255        ) = match density {
2256            ThemeDensity::Compact => (
2257                28.0,
2258                28.0,
2259                Insets {
2260                    left: unit * 1.5,
2261                    top: unit * 0.75,
2262                    right: unit * 1.5,
2263                    bottom: unit * 0.75,
2264                },
2265                Insets {
2266                    left: unit,
2267                    top: unit * 0.5,
2268                    right: unit,
2269                    bottom: unit * 0.5,
2270                },
2271                15.0,
2272                14.0,
2273                28.0,
2274                32.0,
2275                19.0,
2276                3.0,
2277                120.0,
2278                Insets {
2279                    left: unit * 1.5,
2280                    top: unit * 0.5,
2281                    right: unit * 1.5,
2282                    bottom: unit * 0.5,
2283                },
2284                4.0,
2285                14.0,
2286                22.0,
2287                150.0,
2288                Insets {
2289                    left: unit * 2.0,
2290                    top: unit * 0.75,
2291                    right: unit * 2.0,
2292                    bottom: unit * 0.75,
2293                },
2294                56.0,
2295                176.0,
2296                32.0,
2297                84.0,
2298                Insets {
2299                    left: unit * 2.5,
2300                    top: unit * 0.75,
2301                    right: unit * 2.5,
2302                    bottom: unit * 0.75,
2303                },
2304                Insets::all(unit * 3.0),
2305                unit * 2.0,
2306                28.0,
2307                Insets::all(unit),
2308                Insets {
2309                    left: unit * 2.0,
2310                    top: unit * 0.5,
2311                    right: unit * 2.0,
2312                    bottom: unit * 0.5,
2313                },
2314                Insets::all(unit * 2.5),
2315                252.0,
2316                84.0,
2317                Insets {
2318                    left: unit * 3.0,
2319                    top: unit * 2.5,
2320                    right: unit * 2.5,
2321                    bottom: unit * 2.5,
2322                },
2323                32.0,
2324                16.0,
2325                unit * 2.5,
2326                unit,
2327                18.0,
2328                14.0,
2329                2.0,
2330                unit * 2.0,
2331                34.0,
2332                unit * 2.0,
2333                72.0,
2334                unit * 1.25,
2335                180.0,
2336                14.0,
2337                22.0,
2338                Insets::all(unit * 0.5),
2339                Insets::all(unit * 1.5),
2340                Insets {
2341                    left: unit * 3.0,
2342                    top: unit * 0.5,
2343                    right: unit * 2.0,
2344                    bottom: unit * 0.5,
2345                },
2346                12.0,
2347                unit * 1.5,
2348                unit * 2.0,
2349                30.0,
2350                38.0,
2351                22.0,
2352                26.0,
2353                30.0,
2354                unit * 4.0,
2355                10.0,
2356                unit,
2357                30.0,
2358                28.0,
2359                unit * 2.5,
2360                28.0,
2361                Insets {
2362                    left: unit * 2.0,
2363                    top: unit * 0.75,
2364                    right: unit * 2.0,
2365                    bottom: unit * 0.75,
2366                },
2367                unit * 4.0,
2368                9.0,
2369            ),
2370            ThemeDensity::Comfortable => (
2371                32.0,
2372                36.0,
2373                Insets {
2374                    left: unit * 2.0,
2375                    top: unit * 1.25,
2376                    right: unit * 2.0,
2377                    bottom: unit * 1.25,
2378                },
2379                Insets {
2380                    left: unit * 1.5,
2381                    top: unit,
2382                    right: unit * 1.5,
2383                    bottom: unit,
2384                },
2385                15.0,
2386                16.0,
2387                32.0,
2388                32.0,
2389                19.0,
2390                3.0,
2391                140.0,
2392                Insets {
2393                    left: unit * 2.0,
2394                    top: unit,
2395                    right: unit * 2.0,
2396                    bottom: unit,
2397                },
2398                4.0,
2399                14.0,
2400                24.0,
2401                180.0,
2402                Insets {
2403                    left: unit * 2.0,
2404                    top: unit * 1.25,
2405                    right: unit * 2.0,
2406                    bottom: unit * 1.25,
2407                },
2408                64.0,
2409                200.0,
2410                36.0,
2411                96.0,
2412                Insets {
2413                    left: unit * 2.5,
2414                    top: unit,
2415                    right: unit * 2.5,
2416                    bottom: unit,
2417                },
2418                Insets::all(unit * 4.0),
2419                unit * 3.0,
2420                32.0,
2421                Insets::all(unit * 1.5),
2422                Insets {
2423                    left: unit * 3.0,
2424                    top: unit,
2425                    right: unit * 3.0,
2426                    bottom: unit,
2427                },
2428                Insets::all(unit * 3.5),
2429                280.0,
2430                104.0,
2431                Insets {
2432                    left: unit * 4.0,
2433                    top: unit * 3.5,
2434                    right: unit * 3.5,
2435                    bottom: unit * 3.5,
2436                },
2437                38.0,
2438                20.0,
2439                unit * 3.0,
2440                unit * 1.25,
2441                22.0,
2442                16.0,
2443                3.0,
2444                unit * 2.5,
2445                40.0,
2446                unit * 2.5,
2447                86.0,
2448                unit * 1.5,
2449                240.0,
2450                18.0,
2451                18.0,
2452                Insets::all(unit * 0.5),
2453                Insets::all(unit * 2.0),
2454                Insets {
2455                    left: 14.0,
2456                    top: unit,
2457                    right: 10.0,
2458                    bottom: unit,
2459                },
2460                14.0,
2461                unit * 2.0,
2462                unit * 3.0,
2463                36.0,
2464                40.0,
2465                26.0,
2466                34.0,
2467                36.0,
2468                18.0,
2469                12.0,
2470                6.0,
2471                36.0,
2472                34.0,
2473                unit * 2.5,
2474                36.0,
2475                Insets {
2476                    left: unit * 2.0,
2477                    top: unit,
2478                    right: unit * 2.0,
2479                    bottom: unit,
2480                },
2481                unit * 5.0,
2482                10.0,
2483            ),
2484            ThemeDensity::Touch => (
2485                36.0,
2486                44.0,
2487                Insets {
2488                    left: unit * 2.5,
2489                    top: unit * 1.5,
2490                    right: unit * 2.5,
2491                    bottom: unit * 1.5,
2492                },
2493                Insets {
2494                    left: unit * 2.0,
2495                    top: unit * 1.5,
2496                    right: unit * 2.0,
2497                    bottom: unit * 1.5,
2498                },
2499                15.0,
2500                18.0,
2501                36.0,
2502                32.0,
2503                19.0,
2504                3.0,
2505                160.0,
2506                Insets {
2507                    left: unit * 2.5,
2508                    top: unit * 1.5,
2509                    right: unit * 2.5,
2510                    bottom: unit * 1.5,
2511                },
2512                4.0,
2513                14.0,
2514                30.0,
2515                200.0,
2516                Insets {
2517                    left: unit * 2.0,
2518                    top: unit * 1.5,
2519                    right: unit * 2.0,
2520                    bottom: unit * 1.5,
2521                },
2522                72.0,
2523                230.0,
2524                40.0,
2525                104.0,
2526                Insets {
2527                    left: unit * 2.5,
2528                    top: unit * 1.5,
2529                    right: unit * 2.5,
2530                    bottom: unit * 1.5,
2531                },
2532                Insets::all(unit * 4.5),
2533                unit * 3.5,
2534                40.0,
2535                Insets::all(unit * 1.75),
2536                Insets {
2537                    left: unit * 3.25,
2538                    top: unit * 1.5,
2539                    right: unit * 3.25,
2540                    bottom: unit * 1.5,
2541                },
2542                Insets::all(unit * 4.0),
2543                300.0,
2544                112.0,
2545                Insets {
2546                    left: unit * 4.5,
2547                    top: unit * 4.0,
2548                    right: unit * 4.0,
2549                    bottom: unit * 4.0,
2550                },
2551                42.0,
2552                22.0,
2553                unit * 3.25,
2554                unit * 1.5,
2555                26.0,
2556                18.0,
2557                3.5,
2558                unit * 2.75,
2559                46.0,
2560                unit * 2.75,
2561                96.0,
2562                unit * 1.75,
2563                260.0,
2564                22.0,
2565                22.0,
2566                Insets::all(unit * 0.75),
2567                Insets::all(unit * 2.25),
2568                Insets {
2569                    left: unit * 3.5,
2570                    top: unit * 1.5,
2571                    right: unit * 2.75,
2572                    bottom: unit * 1.5,
2573                },
2574                16.0,
2575                unit * 2.25,
2576                unit * 3.5,
2577                40.0,
2578                44.0,
2579                32.0,
2580                38.0,
2581                40.0,
2582                22.0,
2583                14.0,
2584                unit * 1.5,
2585                40.0,
2586                38.0,
2587                unit * 2.5,
2588                40.0,
2589                Insets {
2590                    left: unit * 2.5,
2591                    top: unit * 1.5,
2592                    right: unit * 2.5,
2593                    bottom: unit * 1.5,
2594                },
2595                unit * 5.5,
2596                11.0,
2597            ),
2598        };
2599
2600        let (
2601            popover_reveal_offset,
2602            tooltip_padding,
2603            tooltip_min_width,
2604            tooltip_gap,
2605            tooltip_reveal_offset,
2606            dialog_min_width,
2607            dialog_max_width,
2608            dialog_outer_margin,
2609            dialog_padding,
2610            dialog_title_font_size,
2611            dialog_title_line_height,
2612            dialog_description_gap,
2613            dialog_body_gap,
2614            dialog_footer_gap,
2615            dialog_action_gap,
2616            dialog_action_min_width,
2617        ) = match density {
2618            ThemeDensity::Compact => (
2619                8.0,
2620                Insets {
2621                    left: unit * 2.0,
2622                    top: unit * 1.5,
2623                    right: unit * 2.0,
2624                    bottom: unit * 1.5,
2625                },
2626                80.0,
2627                unit * 2.0,
2628                6.0,
2629                240.0,
2630                440.0,
2631                unit * 4.0,
2632                Insets::all(unit * 3.5),
2633                16.0,
2634                24.0,
2635                unit * 1.5,
2636                unit * 3.0,
2637                unit * 3.5,
2638                unit * 2.0,
2639                92.0,
2640            ),
2641            ThemeDensity::Comfortable => (
2642                10.0,
2643                Insets {
2644                    left: unit * 2.25,
2645                    top: unit * 2.25,
2646                    right: unit * 2.25,
2647                    bottom: unit * 2.25,
2648                },
2649                96.0,
2650                unit * 2.5,
2651                8.0,
2652                280.0,
2653                520.0,
2654                unit * 6.0,
2655                Insets::all(18.0),
2656                16.0,
2657                24.0,
2658                unit * 2.0,
2659                14.0,
2660                18.0,
2661                unit * 2.5,
2662                110.0,
2663            ),
2664            ThemeDensity::Touch => (
2665                12.0,
2666                Insets {
2667                    left: unit * 3.0,
2668                    top: unit * 2.5,
2669                    right: unit * 3.0,
2670                    bottom: unit * 2.5,
2671                },
2672                112.0,
2673                unit * 3.0,
2674                10.0,
2675                320.0,
2676                600.0,
2677                unit * 8.0,
2678                Insets::all(unit * 6.0),
2679                18.0,
2680                26.0,
2681                unit * 2.5,
2682                unit * 4.5,
2683                unit * 5.0,
2684                unit * 3.0,
2685                128.0,
2686            ),
2687        };
2688
2689        let (
2690            layer_action_icon_inset,
2691            layer_lock_icon_inset,
2692            layer_visibility_stroke_width,
2693            layer_visibility_slash_stroke_width,
2694            layer_thumbnail_inset,
2695            layer_thumbnail_radius,
2696            layer_thumbnail_disabled_opacity,
2697            layer_thumbnail_disabled_border_opacity,
2698        ) = match density {
2699            ThemeDensity::Compact => (4.5, 3.5, 1.25, 1.45, 1.5, radius.md, 0.34, 0.52),
2700            ThemeDensity::Comfortable => (5.0, 4.0, 1.4, 1.6, 2.0, radius.md, 0.36, 0.55),
2701            ThemeDensity::Touch => (7.0, 6.0, 1.8, 2.0, 3.0, radius.lg, 0.40, 0.60),
2702        };
2703
2704        let (
2705            data_scroll_thumb_width,
2706            data_scroll_thumb_inset,
2707            data_scroll_thumb_radius,
2708            data_scroll_thumb_min_length,
2709            data_scroll_thumb_opacity,
2710            table_header_separator_inset,
2711            table_separator_width,
2712            table_row_border_opacity,
2713        ) = match density {
2714            ThemeDensity::Compact => (3.0, 5.0, radius.sm, 24.0, 0.68, 3.0, 1.0, 0.50),
2715            ThemeDensity::Comfortable => (4.0, 6.0, radius.sm, 28.0, 0.75, 4.0, 1.0, 0.55),
2716            ThemeDensity::Touch => (6.0, 8.0, radius.md, 44.0, 0.78, 8.0, 1.5, 0.60),
2717        };
2718
2719        let (
2720            toolbar_extent,
2721            toolbar_padding,
2722            toolbar_spacing,
2723            command_group_padding,
2724            command_group_spacing,
2725            command_group_radius,
2726            tool_palette_item_size,
2727            tool_palette_icon_size,
2728            preset_strip_item_height,
2729            preset_strip_item_min_width,
2730            preset_strip_item_padding,
2731            preset_strip_gap,
2732            preset_strip_label_padding,
2733        ) = match density {
2734            ThemeDensity::Compact => (
2735                40.0,
2736                Insets::all(unit * 1.5),
2737                unit * 1.5,
2738                Insets::all(unit * 0.25),
2739                unit * 0.5,
2740                radius.md,
2741                30.0,
2742                16.0,
2743                24.0,
2744                36.0,
2745                Insets {
2746                    left: unit * 2.0,
2747                    top: unit,
2748                    right: unit * 2.0,
2749                    bottom: unit,
2750                },
2751                unit,
2752                Insets::all(unit * 0.75),
2753            ),
2754            ThemeDensity::Comfortable => (
2755                52.0,
2756                Insets::all(unit * 2.0),
2757                unit * 2.0,
2758                Insets::all(unit * 0.5),
2759                unit * 0.75,
2760                radius.lg,
2761                40.0,
2762                20.0,
2763                28.0,
2764                44.0,
2765                Insets {
2766                    left: unit * 3.0,
2767                    top: unit,
2768                    right: unit * 3.0,
2769                    bottom: unit,
2770                },
2771                unit * 1.5,
2772                Insets::all(unit),
2773            ),
2774            ThemeDensity::Touch => (
2775                56.0,
2776                Insets::all(unit * 2.25),
2777                unit * 2.25,
2778                Insets::all(unit * 0.75),
2779                unit * 0.875,
2780                radius.xl,
2781                44.0,
2782                22.0,
2783                36.0,
2784                50.0,
2785                Insets {
2786                    left: unit * 3.5,
2787                    top: unit * 1.5,
2788                    right: unit * 3.5,
2789                    bottom: unit * 1.5,
2790                },
2791                unit * 1.75,
2792                Insets::all(unit * 1.5),
2793            ),
2794        };
2795
2796        let (
2797            property_row_label_width,
2798            property_row_inline_gap,
2799            property_row_stacked_gap,
2800            form_row_label_width,
2801            form_row_control_width,
2802            form_row_gap,
2803            field_group_spacing,
2804            form_section_padding,
2805            form_section_body_gap,
2806            form_section_header_gap,
2807            form_section_description_gap,
2808            form_section_max_width,
2809            form_section_radius,
2810            panel_section_gap,
2811            panel_section_action_gap,
2812            panel_section_disclosure_size,
2813            dock_panel_header_height,
2814            dock_panel_padding,
2815        ) = match density {
2816            ThemeDensity::Compact => (
2817                96.0,
2818                unit * 1.5,
2819                unit,
2820                112.0,
2821                300.0,
2822                unit * 2.0,
2823                unit * 1.5,
2824                Insets {
2825                    left: unit * 2.5,
2826                    top: unit * 2.0,
2827                    right: unit * 2.5,
2828                    bottom: unit * 2.5,
2829                },
2830                unit * 2.0,
2831                unit * 2.0,
2832                unit * 0.5,
2833                600.0,
2834                radius.md,
2835                unit * 1.5,
2836                unit,
2837                14.0,
2838                28.0,
2839                Insets {
2840                    left: unit * 2.0,
2841                    top: unit * 1.5,
2842                    right: unit * 2.0,
2843                    bottom: unit * 1.5,
2844                },
2845            ),
2846            ThemeDensity::Comfortable => (
2847                112.0,
2848                unit * 2.0,
2849                unit * 1.5,
2850                128.0,
2851                340.0,
2852                unit * 3.0,
2853                unit * 2.0,
2854                Insets {
2855                    left: 14.0,
2856                    top: unit * 3.0,
2857                    right: 14.0,
2858                    bottom: 14.0,
2859                },
2860                unit * 3.0,
2861                unit * 2.5,
2862                unit * 0.75,
2863                640.0,
2864                radius.lg,
2865                unit * 2.0,
2866                unit * 1.5,
2867                16.0,
2868                34.0,
2869                Insets {
2870                    left: unit * 2.5,
2871                    top: unit * 2.0,
2872                    right: unit * 2.5,
2873                    bottom: unit * 2.0,
2874                },
2875            ),
2876            ThemeDensity::Touch => (
2877                136.0,
2878                unit * 3.0,
2879                unit * 2.0,
2880                144.0,
2881                380.0,
2882                unit * 4.0,
2883                unit * 3.0,
2884                Insets {
2885                    left: unit * 4.5,
2886                    top: unit * 4.0,
2887                    right: unit * 4.5,
2888                    bottom: unit * 4.5,
2889                },
2890                unit * 4.0,
2891                unit * 3.0,
2892                unit,
2893                720.0,
2894                radius.xl,
2895                unit * 3.0,
2896                unit * 2.0,
2897                20.0,
2898                44.0,
2899                Insets {
2900                    left: unit * 3.5,
2901                    top: unit * 3.0,
2902                    right: unit * 3.5,
2903                    bottom: unit * 3.0,
2904                },
2905            ),
2906        };
2907
2908        let (
2909            image_corner_radius,
2910            color_swatch_width,
2911            color_swatch_height,
2912            color_swatch_inner_inset,
2913            color_swatch_checker_size,
2914            color_palette_swatch_size,
2915            color_palette_gap,
2916            color_palette_swatch_inset,
2917            color_palette_selected_swatch_inset,
2918            color_palette_checker_size,
2919            brush_preview_min_width,
2920            brush_preview_min_height,
2921            brush_preview_padding,
2922            brush_preview_swatch_width,
2923            brush_preview_swatch_gap,
2924            brush_preview_checker_size,
2925            brush_preview_text_height,
2926            brush_preview_text_font_size,
2927            brush_preview_text_line_height,
2928            color_picker_content_inset,
2929            color_picker_panel_gap,
2930            color_picker_top_bar_height,
2931            color_picker_swatch_width,
2932            color_picker_swatch_gap,
2933            color_picker_section_gap,
2934            color_picker_wheel_size,
2935            color_picker_map_size,
2936            color_picker_row_height,
2937            color_picker_row_gap,
2938            color_picker_right_panel_width,
2939            color_picker_field_height,
2940            color_picker_field_gap,
2941            color_picker_dropdown_gap,
2942            color_picker_encoding_menu_row_height,
2943            scroll_bar_thickness,
2944            scroll_bar_min_thumb_length,
2945            split_view_divider_thickness,
2946            split_view_drag_target_thickness,
2947            floating_workspace_margin,
2948            floating_view_title_bar_height,
2949            floating_view_title_padding,
2950            floating_view_resize_handle_size,
2951            canvas_ruler_extent,
2952            canvas_ruler_major_tick,
2953            canvas_ruler_minor_tick,
2954            canvas_ruler_target_major_spacing,
2955            canvas_ruler_label_padding,
2956            canvas_ruler_label_max_width,
2957            canvas_grid_step,
2958            canvas_axis_overscan,
2959            pixel_canvas_fit_padding,
2960            pixel_canvas_grid_zoom,
2961            pixel_canvas_nearest_sampling_zoom,
2962            pixel_canvas_zoom_step,
2963        ) = match density {
2964            ThemeDensity::Compact => (
2965                radius.md,
2966                48.0,
2967                28.0,
2968                1.0,
2969                5.0,
2970                24.0,
2971                unit * 1.25,
2972                2.0,
2973                3.0,
2974                5.0,
2975                220.0,
2976                58.0,
2977                Insets::all(unit * 1.5),
2978                46.0,
2979                unit * 2.0,
2980                5.0,
2981                15.0,
2982                10.0,
2983                13.0,
2984                unit * 3.0,
2985                unit * 2.5,
2986                40.0,
2987                64.0,
2988                unit * 2.0,
2989                14.0,
2990                128.0,
2991                132.0,
2992                24.0,
2993                unit * 2.0,
2994                150.0,
2995                28.0,
2996                12.0,
2997                unit,
2998                28.0,
2999                10.0,
3000                24.0,
3001                1.0,
3002                10.0,
3003                unit * 2.0,
3004                30.0,
3005                Insets {
3006                    left: unit * 2.5,
3007                    top: unit * 1.5,
3008                    right: unit * 2.5,
3009                    bottom: unit * 1.5,
3010                },
3011                16.0,
3012                20.0,
3013                9.0,
3014                4.0,
3015                84.0,
3016                Insets {
3017                    left: unit * 0.5,
3018                    top: unit * 0.5,
3019                    right: unit * 0.5,
3020                    bottom: unit * 0.5,
3021                },
3022                48.0,
3023                32.0,
3024                72.0,
3025                20.0,
3026                6.0,
3027                1.0,
3028                1.1,
3029            ),
3030            ThemeDensity::Comfortable => (
3031                radius.lg,
3032                56.0,
3033                32.0,
3034                1.0,
3035                6.0,
3036                28.0,
3037                unit * 1.5,
3038                2.0,
3039                3.0,
3040                5.0,
3041                260.0,
3042                70.0,
3043                Insets::all(unit * 2.0),
3044                54.0,
3045                unit * 2.5,
3046                6.0,
3047                16.0,
3048                11.0,
3049                14.0,
3050                14.0,
3051                14.0,
3052                52.0,
3053                96.0,
3054                unit * 2.5,
3055                14.0,
3056                166.0,
3057                210.0,
3058                24.0,
3059                unit * 2.0,
3060                226.0,
3061                30.0,
3062                12.0,
3063                unit,
3064                28.0,
3065                12.0,
3066                28.0,
3067                1.0,
3068                12.0,
3069                unit * 3.0,
3070                32.0,
3071                Insets {
3072                    left: 14.0,
3073                    top: unit * 2.0,
3074                    right: 14.0,
3075                    bottom: unit * 2.0,
3076                },
3077                18.0,
3078                22.0,
3079                10.0,
3080                5.0,
3081                96.0,
3082                Insets {
3083                    left: unit * 0.75,
3084                    top: unit * 0.5,
3085                    right: unit * 0.75,
3086                    bottom: unit * 0.5,
3087                },
3088                54.0,
3089                40.0,
3090                80.0,
3091                24.0,
3092                6.0,
3093                1.0,
3094                1.1,
3095            ),
3096            ThemeDensity::Touch => (
3097                radius.xl,
3098                72.0,
3099                44.0,
3100                1.5,
3101                8.0,
3102                40.0,
3103                unit * 2.0,
3104                3.0,
3105                4.0,
3106                7.0,
3107                320.0,
3108                88.0,
3109                Insets::all(unit * 3.0),
3110                72.0,
3111                unit * 3.5,
3112                8.0,
3113                18.0,
3114                12.0,
3115                16.0,
3116                unit * 4.5,
3117                unit * 4.5,
3118                64.0,
3119                112.0,
3120                unit * 3.0,
3121                18.0,
3122                210.0,
3123                240.0,
3124                44.0,
3125                unit * 3.0,
3126                280.0,
3127                44.0,
3128                16.0,
3129                unit * 2.0,
3130                44.0,
3131                18.0,
3132                44.0,
3133                2.0,
3134                44.0,
3135                unit * 4.5,
3136                52.0,
3137                Insets {
3138                    left: unit * 4.5,
3139                    top: unit * 3.5,
3140                    right: unit * 4.5,
3141                    bottom: unit * 3.5,
3142                },
3143                28.0,
3144                32.0,
3145                16.0,
3146                8.0,
3147                120.0,
3148                Insets::all(unit),
3149                72.0,
3150                48.0,
3151                96.0,
3152                32.0,
3153                6.0,
3154                1.0,
3155                1.1,
3156            ),
3157        };
3158
3159        Self {
3160            min_height,
3161            touch_target_size,
3162            button_min_width: 64.0,
3163            button_padding,
3164            checkbox_padding,
3165            checkbox_indicator_size,
3166            checkbox_gap: 6.0,
3167            icon_label_gap: 6.0,
3168            separator_thickness: 1.0,
3169            icon_size,
3170            icon_button_size,
3171            switch_track_width,
3172            switch_track_height,
3173            switch_thumb_inset,
3174            slider_min_width,
3175            slider_padding,
3176            slider_track_height,
3177            slider_thumb_size,
3178            number_input_stepper_width,
3179            text_input_min_width,
3180            text_input_padding,
3181            text_area_min_height,
3182            select_menu_max_height,
3183            select_menu_gap: 6.0,
3184            select_menu_edge_padding: 8.0,
3185            tab_height,
3186            tab_min_width,
3187            tab_gap: 6.0,
3188            tab_padding,
3189            tab_panel_padding,
3190            tab_panel_gap,
3191            menu_row_height,
3192            menu_padding,
3193            menu_item_padding,
3194            menu_shortcut_width: 108.0,
3195            popover_padding,
3196            popover_gap: unit * 2.0,
3197            popover_reveal_offset,
3198            tooltip_padding,
3199            tooltip_min_width,
3200            tooltip_gap,
3201            tooltip_reveal_offset,
3202            dialog_min_width,
3203            dialog_max_width,
3204            dialog_outer_margin,
3205            dialog_padding,
3206            dialog_title_font_size,
3207            dialog_title_line_height,
3208            dialog_description_gap,
3209            dialog_body_gap,
3210            dialog_footer_gap,
3211            dialog_action_gap,
3212            dialog_action_min_width,
3213            toolbar_extent,
3214            toolbar_padding,
3215            toolbar_spacing,
3216            command_group_padding,
3217            command_group_spacing,
3218            command_group_radius,
3219            tool_palette_item_size,
3220            tool_palette_icon_size,
3221            preset_strip_item_height,
3222            preset_strip_item_min_width,
3223            preset_strip_item_padding,
3224            preset_strip_gap,
3225            preset_strip_label_padding,
3226            action_card_min_width,
3227            action_card_min_height,
3228            action_card_padding,
3229            action_card_icon_box_size,
3230            action_card_icon_size,
3231            action_card_icon_gap,
3232            action_card_text_gap,
3233            action_card_trailing_gap,
3234            action_card_chevron_size,
3235            action_card_accent_width,
3236            action_card_accent_inset,
3237            status_bar_height,
3238            status_bar_segment_padding,
3239            status_bar_segment_min_width,
3240            status_bar_separator_inset,
3241            progress_bar_min_width,
3242            progress_bar_height,
3243            progress_bar_value_height,
3244            progress_bar_label_padding,
3245            property_row_label_width,
3246            property_row_inline_gap,
3247            property_row_stacked_gap,
3248            form_row_label_width,
3249            form_row_control_width,
3250            form_row_gap,
3251            field_group_spacing,
3252            form_section_padding,
3253            form_section_body_gap,
3254            form_section_header_gap,
3255            form_section_description_gap,
3256            form_section_max_width,
3257            form_section_radius,
3258            panel_section_gap,
3259            panel_section_action_gap,
3260            panel_section_disclosure_size,
3261            dock_panel_header_height,
3262            dock_panel_padding,
3263            data_viewport_padding,
3264            data_row_padding,
3265            data_row_icon_size,
3266            data_row_icon_gap,
3267            data_row_trailing_gap,
3268            data_scroll_thumb_width,
3269            data_scroll_thumb_inset,
3270            data_scroll_thumb_radius,
3271            data_scroll_thumb_min_length,
3272            data_scroll_thumb_opacity,
3273            list_row_height,
3274            layer_row_height,
3275            layer_action_size,
3276            layer_action_icon_inset,
3277            layer_lock_icon_inset,
3278            layer_visibility_stroke_width,
3279            layer_visibility_slash_stroke_width,
3280            layer_thumbnail_size,
3281            layer_thumbnail_inset,
3282            layer_thumbnail_radius,
3283            layer_thumbnail_disabled_opacity,
3284            layer_thumbnail_disabled_border_opacity,
3285            tree_row_height,
3286            tree_indent,
3287            tree_disclosure_size,
3288            tree_disclosure_gap,
3289            table_row_height,
3290            table_header_height,
3291            table_cell_padding,
3292            table_header_separator_inset,
3293            table_separator_width,
3294            table_row_border_opacity,
3295            breadcrumb_height,
3296            breadcrumb_item_padding,
3297            breadcrumb_gap,
3298            breadcrumb_separator_size,
3299            image_corner_radius,
3300            color_swatch_width,
3301            color_swatch_height,
3302            color_swatch_inner_inset,
3303            color_swatch_checker_size,
3304            color_palette_swatch_size,
3305            color_palette_gap,
3306            color_palette_swatch_inset,
3307            color_palette_selected_swatch_inset,
3308            color_palette_checker_size,
3309            brush_preview_min_width,
3310            brush_preview_min_height,
3311            brush_preview_padding,
3312            brush_preview_swatch_width,
3313            brush_preview_swatch_gap,
3314            brush_preview_checker_size,
3315            brush_preview_text_height,
3316            brush_preview_text_font_size,
3317            brush_preview_text_line_height,
3318            color_picker_content_inset,
3319            color_picker_panel_gap,
3320            color_picker_top_bar_height,
3321            color_picker_swatch_width,
3322            color_picker_swatch_gap,
3323            color_picker_section_gap,
3324            color_picker_wheel_size,
3325            color_picker_map_size,
3326            color_picker_row_height,
3327            color_picker_row_gap,
3328            color_picker_right_panel_width,
3329            color_picker_field_height,
3330            color_picker_field_gap,
3331            color_picker_dropdown_gap,
3332            color_picker_encoding_menu_row_height,
3333            scroll_bar_thickness,
3334            scroll_bar_min_thumb_length,
3335            split_view_divider_thickness,
3336            split_view_drag_target_thickness,
3337            floating_workspace_margin,
3338            floating_view_title_bar_height,
3339            floating_view_title_padding,
3340            floating_view_resize_handle_size,
3341            canvas_ruler_extent,
3342            canvas_ruler_major_tick,
3343            canvas_ruler_minor_tick,
3344            canvas_ruler_target_major_spacing,
3345            canvas_ruler_label_padding,
3346            canvas_ruler_label_max_width,
3347            canvas_grid_step,
3348            canvas_axis_overscan,
3349            pixel_canvas_fit_padding,
3350            pixel_canvas_grid_zoom,
3351            pixel_canvas_nearest_sampling_zoom,
3352            pixel_canvas_zoom_step,
3353            corner_radius: match density {
3354                ThemeDensity::Compact | ThemeDensity::Comfortable => radius.md,
3355                ThemeDensity::Touch => radius.lg,
3356            },
3357            indicator_corner_radius: radius.sm + 1.0,
3358            border_width: 1.0,
3359            focus_ring_width: 2.0,
3360            // Keep the 2px ring wholly clear of the control border.
3361            focus_ring_outset: 2.0,
3362            caret_width: 2.0,
3363        }
3364    }
3365}
3366
3367impl Default for ControlMetrics {
3368    fn default() -> Self {
3369        Self::from_tokens(4.0, ThemeRadii::default(), ThemeDensity::default())
3370    }
3371}
3372
3373#[derive(Debug, Clone, Copy, PartialEq)]
3374pub struct DefaultTheme {
3375    pub fonts: ThemeFontFamilies,
3376    pub colors: ThemeColors,
3377    pub density: ThemeDensity,
3378    /// Contextual authored size, when this theme copy is scoped to an interface surface.
3379    pub control_size: Option<ControlSize>,
3380    pub spacing: f32,
3381    pub breakpoints: ThemeBreakpoints,
3382    pub containers: ThemeContainers,
3383    pub text: ThemeTextScale,
3384    pub font_weights: ThemeFontWeights,
3385    pub tracking: ThemeTracking,
3386    pub leading: ThemeLeading,
3387    pub radius: ThemeRadii,
3388    pub shadows: ThemeShadows,
3389    /// Live-signal glow halos (`--sm-glow-*`): empty in Light, damped in the
3390    /// true-black theme. Paint with [`paint_theme_shadow`].
3391    pub glows: ThemeGlows,
3392    pub blur: ThemeBlurScale,
3393    pub perspective: ThemePerspective,
3394    pub aspect: ThemeAspectRatios,
3395    pub motion: ThemeMotion,
3396    pub hdr: HdrThemeTokens,
3397    pub palette: ControlPalette,
3398    pub surfaces: SurfacePalette,
3399    pub typography: ControlTypography,
3400    pub interaction: ControlStateMetrics,
3401    pub metrics: ControlMetrics,
3402}
3403
3404impl DefaultTheme {
3405    pub fn new() -> Self {
3406        Self::default()
3407    }
3408
3409    /// SUI's branded default theme.
3410    pub fn sui() -> Self {
3411        Self::light()
3412    }
3413
3414    pub fn light() -> Self {
3415        Self::from_colors(ThemeColors::light())
3416    }
3417
3418    /// A neutral light theme for serious, professional interfaces without an
3419    /// application-specific color preference.
3420    pub fn neutral() -> Self {
3421        Self::from_colors(ThemeColors::neutral())
3422    }
3423
3424    /// Dark companion to [`Self::neutral`].
3425    pub fn neutral_dark() -> Self {
3426        Self::from_colors(ThemeColors::neutral_dark())
3427    }
3428
3429    pub fn dark() -> Self {
3430        Self::from_colors(ThemeColors::dark())
3431    }
3432
3433    pub fn high_contrast() -> Self {
3434        Self::from_colors(ThemeColors::high_contrast())
3435    }
3436
3437    /// The Mesh true-black OLED theme ("Void"): borders instead of shadows,
3438    /// dimmed whites, damped glows. Alias for [`Self::high_contrast`].
3439    pub fn void() -> Self {
3440        Self::high_contrast()
3441    }
3442
3443    pub fn compact() -> Self {
3444        Self::default().with_size(ControlSize::Small)
3445    }
3446
3447    pub fn comfortable() -> Self {
3448        Self::default().with_size(ControlSize::Medium)
3449    }
3450
3451    pub fn touch() -> Self {
3452        Self::default().with_size(ControlSize::Large)
3453    }
3454
3455    pub fn from_colors(colors: ThemeColors) -> Self {
3456        let text = ThemeTextScale::default();
3457        let radius = ThemeRadii::default();
3458        let spacing = 4.0;
3459        let density = ThemeDensity::default();
3460        let hdr = HdrThemeTokens::from_colors(colors);
3461        let palette = ControlPalette::from_colors(&colors);
3462        let surfaces = SurfacePalette::from_theme_parts(&colors, &palette);
3463
3464        let mut theme = Self {
3465            fonts: ThemeFontFamilies::default(),
3466            colors,
3467            density,
3468            control_size: Some(ControlSize::Medium),
3469            spacing,
3470            breakpoints: ThemeBreakpoints::default(),
3471            containers: ThemeContainers::default(),
3472            text,
3473            font_weights: ThemeFontWeights::default(),
3474            tracking: ThemeTracking::default(),
3475            leading: ThemeLeading::default(),
3476            radius,
3477            shadows: ThemeShadows::for_colors(&colors),
3478            glows: ThemeGlows::for_colors(&colors),
3479            blur: ThemeBlurScale::default(),
3480            perspective: ThemePerspective::default(),
3481            aspect: ThemeAspectRatios::default(),
3482            motion: ThemeMotion::default(),
3483            hdr,
3484            palette,
3485            surfaces,
3486            typography: ControlTypography::for_density(&text, density),
3487            interaction: ControlStateMetrics::for_density(density),
3488            metrics: ControlMetrics::from_tokens(spacing, radius, density),
3489        };
3490        theme.sync_size_fields(ControlSize::Medium);
3491        theme
3492    }
3493
3494    pub fn with_density(mut self, density: ThemeDensity) -> Self {
3495        self.density = density;
3496        self.control_size = None;
3497        self.sync_density_fields();
3498        self
3499    }
3500
3501    /// Apply contextual interface sizing without changing the text-scale ramp.
3502    ///
3503    /// The existing density tiers provide the mature detailed metric ladders
3504    /// behind `Small`, `Medium`, and `Large`. The authored size contract then
3505    /// normalizes the primary control, row, icon, and control-text tokens while
3506    /// leaving the caller's text ramp intact.
3507    pub fn with_size(mut self, size: ControlSize) -> Self {
3508        self.density = size.legacy_density();
3509        self.control_size = Some(size);
3510        self.sync_size_fields(size);
3511        self
3512    }
3513
3514    fn sync_size_fields(&mut self, size: ControlSize) {
3515        self.interaction = ControlStateMetrics::for_density(size.legacy_density());
3516        self.metrics =
3517            ControlMetrics::from_tokens(self.spacing, self.radius, size.legacy_density());
3518        self.metrics.min_height = size.control_height();
3519        self.metrics.touch_target_size = 44.0;
3520        self.metrics.icon_size = size.icon_size();
3521        self.metrics.icon_button_size = size.control_height();
3522        self.metrics.list_row_height = size.row_height();
3523        self.metrics.tree_row_height = size.row_height();
3524        self.metrics.table_row_height = size.row_height();
3525        self.metrics.menu_row_height = size.row_height();
3526        self.typography = ControlTypography::for_size(&self.text, size);
3527    }
3528
3529    fn sync_density_fields(&mut self) {
3530        if let Some(size) = self
3531            .control_size
3532            .filter(|size| size.legacy_density() == self.density)
3533        {
3534            self.sync_size_fields(size);
3535            return;
3536        }
3537        self.control_size = None;
3538        self.typography = ControlTypography::for_density(&self.text, self.density);
3539        self.interaction = ControlStateMetrics::for_density(self.density);
3540        self.metrics = ControlMetrics::from_tokens(self.spacing, self.radius, self.density);
3541    }
3542
3543    pub fn sync_derived_fields(&mut self) {
3544        self.hdr.sync_semantic_defaults(self.colors);
3545        self.palette = ControlPalette::from_colors(&self.colors);
3546        self.surfaces = SurfacePalette::from_theme_parts(&self.colors, &self.palette);
3547        self.shadows = ThemeShadows::for_colors(&self.colors);
3548        self.glows = ThemeGlows::for_colors(&self.colors);
3549        self.sync_density_fields();
3550    }
3551
3552    pub fn text_style(&self, color: Color) -> TextStyle {
3553        self.text_style_with_font_stack(color, self.fonts.sans)
3554    }
3555
3556    /// Build a text style using the theme's serif family preference stack.
3557    pub fn serif_text_style(&self, color: Color) -> TextStyle {
3558        self.text_style_with_font_stack(color, self.fonts.serif)
3559    }
3560
3561    /// Build a text style using the theme's monospace family preference stack.
3562    pub fn mono_text_style(&self, color: Color) -> TextStyle {
3563        self.text_style_with_font_stack(color, self.fonts.mono)
3564    }
3565
3566    fn text_style_with_font_stack(&self, color: Color, fonts: ThemeFontStack) -> TextStyle {
3567        TextStyle {
3568            font_families: Some(fonts.into()),
3569            font_size: self.typography.body_font_size.max(1.0),
3570            line_height: self.typography.body_line_height.max(1.0),
3571            color,
3572            ..TextStyle::default()
3573        }
3574    }
3575
3576    pub fn semantic_tone_colors(&self, tone: SemanticTone) -> (Color, Color) {
3577        match tone {
3578            SemanticTone::Neutral => (self.palette.control, self.palette.text),
3579            SemanticTone::Accent => (self.palette.accent, self.palette.accent_text),
3580            SemanticTone::Info => (self.palette.info, self.palette.info_text),
3581            SemanticTone::Success => (self.palette.success, self.palette.success_text),
3582            SemanticTone::Warning => (self.palette.warning, self.palette.warning_text),
3583            SemanticTone::Danger => (self.palette.danger, self.palette.danger_text),
3584        }
3585    }
3586
3587    pub fn semantic_tone_color(&self, tone: SemanticTone) -> Color {
3588        self.semantic_tone_colors(tone).0
3589    }
3590
3591    pub fn semantic_tone_text_color(&self, tone: SemanticTone) -> Color {
3592        self.semantic_tone_colors(tone).1
3593    }
3594
3595    /// The Mesh soft pair for a tone: a translucent wash to fill with and the
3596    /// status-hued ink that stays legible on it (`--sm-*-soft` / `--sm-*-text`).
3597    /// Use for badges, callouts and selected rows; the solid pair from
3598    /// [`Self::semantic_tone_colors`] is for filled controls.
3599    pub fn semantic_tone_soft_colors(&self, tone: SemanticTone) -> (Color, Color) {
3600        match tone {
3601            SemanticTone::Neutral => (self.palette.control_hover, self.palette.text_muted),
3602            SemanticTone::Accent => (self.palette.accent_soft, self.palette.accent_soft_text),
3603            SemanticTone::Info => (self.palette.info_soft, self.palette.info_soft_text),
3604            SemanticTone::Success => (self.palette.success_soft, self.palette.success_soft_text),
3605            SemanticTone::Warning => (self.palette.warning_soft, self.palette.warning_soft_text),
3606            SemanticTone::Danger => (self.palette.danger_soft, self.palette.danger_soft_text),
3607        }
3608    }
3609
3610    pub fn body_text_style(&self) -> TextStyle {
3611        self.text_style(self.palette.text)
3612    }
3613
3614    pub fn placeholder_text_style(&self) -> TextStyle {
3615        self.text_style(self.palette.placeholder)
3616    }
3617
3618    pub fn button_text_style(&self) -> TextStyle {
3619        self.text_style(self.palette.accent_text)
3620    }
3621}
3622
3623impl Default for DefaultTheme {
3624    fn default() -> Self {
3625        Self::sui()
3626    }
3627}
3628
3629fn mix(from: Color, to: Color, amount: f32) -> Color {
3630    let amount = amount.clamp(0.0, 1.0);
3631
3632    Color::new(
3633        from.space,
3634        from.red + (to.red - from.red) * amount,
3635        from.green + (to.green - from.green) * amount,
3636        from.blue + (to.blue - from.blue) * amount,
3637        from.alpha + (to.alpha - from.alpha) * amount,
3638    )
3639    .clamped()
3640}
3641
3642fn interactive_variant(color: Color, scheme: ThemeColorScheme, amount: f32) -> Color {
3643    match scheme {
3644        ThemeColorScheme::Light => mix(color, Color::BLACK, amount),
3645        ThemeColorScheme::Dark | ThemeColorScheme::HighContrast => mix(color, Color::WHITE, amount),
3646    }
3647}
3648
3649fn interactive_surface(color: Color, scheme: ThemeColorScheme, amount: f32) -> Color {
3650    match scheme {
3651        ThemeColorScheme::Light => mix(color, Color::BLACK, amount),
3652        ThemeColorScheme::Dark | ThemeColorScheme::HighContrast => mix(color, Color::WHITE, amount),
3653    }
3654}
3655
3656fn rgb8(red: u8, green: u8, blue: u8) -> Color {
3657    Color::rgba(
3658        f32::from(red) / 255.0,
3659        f32::from(green) / 255.0,
3660        f32::from(blue) / 255.0,
3661        1.0,
3662    )
3663}
3664
3665fn rgba8(red: u8, green: u8, blue: u8, alpha: f32) -> Color {
3666    rgb8(red, green, blue).with_alpha(alpha)
3667}
3668
3669fn is_neutral_theme(colors: &ThemeColors) -> bool {
3670    matches!(colors.name, "neutral" | "neutral-dark")
3671}
3672
3673fn shadow_layer(
3674    offset_x: f32,
3675    offset_y: f32,
3676    blur: f32,
3677    spread: f32,
3678    color: Color,
3679    inset: bool,
3680) -> ThemeShadowLayer {
3681    ThemeShadowLayer {
3682        offset_x,
3683        offset_y,
3684        blur,
3685        spread,
3686        color,
3687        inset,
3688    }
3689}
3690
3691#[cfg(test)]
3692mod tests {
3693    use super::{
3694        Color, ControlSize, ControlTypography, DefaultTheme, SemanticTone, ThemeColorScheme,
3695        ThemeColors, ThemeDensity, ThemeShadow, ThemeTextScale, rgb8, rgba8,
3696    };
3697    use crate::hdr_theme::HdrThemeMode;
3698
3699    #[test]
3700    fn default_theme_uses_body_text_scale_for_typography() {
3701        let theme = DefaultTheme::default();
3702
3703        assert_eq!(theme.typography.body_font_size, theme.text.base.size);
3704        assert_eq!(
3705            theme.typography.body_line_height,
3706            theme.text.base.line_height
3707        );
3708        assert_eq!(theme.typography.body_font_size, 15.0);
3709        assert_eq!(theme.typography.body_line_height, 22.0);
3710        assert_eq!(theme.control_size, Some(ControlSize::Medium));
3711        assert_eq!(theme.density, ThemeDensity::Comfortable);
3712        assert_eq!(theme.metrics.min_height, 32.0);
3713        assert_eq!(theme.metrics.touch_target_size, 44.0);
3714        assert_eq!(theme.metrics.icon_button_size, 32.0);
3715        assert_eq!(
3716            theme.body_text_style().font_families,
3717            Some(theme.fonts.sans.into())
3718        );
3719        assert_eq!(
3720            theme.serif_text_style(theme.palette.text).font_families,
3721            Some(theme.fonts.serif.into())
3722        );
3723        assert_eq!(
3724            theme.mono_text_style(theme.palette.text).font_families,
3725            Some(theme.fonts.mono.into())
3726        );
3727    }
3728
3729    #[test]
3730    fn density_presets_update_control_metrics_and_interactions() {
3731        let compact = DefaultTheme::compact();
3732        let comfortable = DefaultTheme::comfortable();
3733        let touch = DefaultTheme::touch();
3734
3735        assert_eq!(compact.density, ThemeDensity::Compact);
3736        assert_eq!(comfortable.density, ThemeDensity::Comfortable);
3737        assert_eq!(touch.density, ThemeDensity::Touch);
3738        assert!(compact.metrics.min_height < comfortable.metrics.min_height);
3739        assert!(comfortable.metrics.min_height < touch.metrics.min_height);
3740        assert!(compact.metrics.menu_row_height < comfortable.metrics.menu_row_height);
3741        assert!(comfortable.metrics.menu_row_height < touch.metrics.menu_row_height);
3742        assert!(compact.metrics.list_row_height < comfortable.metrics.list_row_height);
3743        assert!(comfortable.metrics.list_row_height < touch.metrics.list_row_height);
3744        assert!(compact.metrics.layer_row_height < comfortable.metrics.layer_row_height);
3745        assert!(comfortable.metrics.layer_row_height < touch.metrics.layer_row_height);
3746        assert!(
3747            compact.metrics.layer_action_icon_inset < comfortable.metrics.layer_action_icon_inset
3748        );
3749        assert!(
3750            comfortable.metrics.layer_action_icon_inset < touch.metrics.layer_action_icon_inset
3751        );
3752        assert!(
3753            compact.metrics.layer_visibility_stroke_width
3754                < comfortable.metrics.layer_visibility_stroke_width
3755        );
3756        assert!(
3757            comfortable.metrics.layer_visibility_stroke_width
3758                < touch.metrics.layer_visibility_stroke_width
3759        );
3760        assert!(compact.metrics.layer_thumbnail_inset < comfortable.metrics.layer_thumbnail_inset);
3761        assert!(comfortable.metrics.layer_thumbnail_inset < touch.metrics.layer_thumbnail_inset);
3762        assert!(
3763            compact.metrics.layer_thumbnail_radius <= comfortable.metrics.layer_thumbnail_radius
3764        );
3765        assert!(comfortable.metrics.layer_thumbnail_radius < touch.metrics.layer_thumbnail_radius);
3766        assert!(compact.metrics.table_row_height < comfortable.metrics.table_row_height);
3767        assert!(comfortable.metrics.table_row_height < touch.metrics.table_row_height);
3768        assert!(
3769            compact.metrics.data_scroll_thumb_width < comfortable.metrics.data_scroll_thumb_width
3770        );
3771        assert!(
3772            comfortable.metrics.data_scroll_thumb_width < touch.metrics.data_scroll_thumb_width
3773        );
3774        assert!(
3775            compact.metrics.data_scroll_thumb_min_length
3776                < comfortable.metrics.data_scroll_thumb_min_length
3777        );
3778        assert!(
3779            comfortable.metrics.data_scroll_thumb_min_length
3780                < touch.metrics.data_scroll_thumb_min_length
3781        );
3782        assert!(
3783            compact.metrics.table_header_separator_inset
3784                < comfortable.metrics.table_header_separator_inset
3785        );
3786        assert!(
3787            comfortable.metrics.table_header_separator_inset
3788                < touch.metrics.table_header_separator_inset
3789        );
3790        assert!(compact.metrics.breadcrumb_height < comfortable.metrics.breadcrumb_height);
3791        assert!(comfortable.metrics.breadcrumb_height < touch.metrics.breadcrumb_height);
3792        assert!(
3793            compact.metrics.action_card_min_height < comfortable.metrics.action_card_min_height
3794        );
3795        assert!(comfortable.metrics.action_card_min_height < touch.metrics.action_card_min_height);
3796        assert!(compact.metrics.status_bar_height < comfortable.metrics.status_bar_height);
3797        assert!(comfortable.metrics.status_bar_height < touch.metrics.status_bar_height);
3798        assert!(compact.metrics.progress_bar_height < comfortable.metrics.progress_bar_height);
3799        assert!(comfortable.metrics.progress_bar_height < touch.metrics.progress_bar_height);
3800        assert!(compact.metrics.tooltip_gap < comfortable.metrics.tooltip_gap);
3801        assert!(comfortable.metrics.tooltip_gap < touch.metrics.tooltip_gap);
3802        assert!(compact.metrics.tooltip_min_width < comfortable.metrics.tooltip_min_width);
3803        assert!(comfortable.metrics.tooltip_min_width < touch.metrics.tooltip_min_width);
3804        assert!(compact.metrics.popover_reveal_offset < comfortable.metrics.popover_reveal_offset);
3805        assert!(comfortable.metrics.popover_reveal_offset < touch.metrics.popover_reveal_offset);
3806        assert!(compact.metrics.dialog_max_width < comfortable.metrics.dialog_max_width);
3807        assert!(comfortable.metrics.dialog_max_width < touch.metrics.dialog_max_width);
3808        assert!(
3809            compact.metrics.dialog_action_min_width < comfortable.metrics.dialog_action_min_width
3810        );
3811        assert!(
3812            comfortable.metrics.dialog_action_min_width < touch.metrics.dialog_action_min_width
3813        );
3814        assert!(compact.metrics.toolbar_extent < comfortable.metrics.toolbar_extent);
3815        assert!(comfortable.metrics.toolbar_extent < touch.metrics.toolbar_extent);
3816        assert!(
3817            compact.metrics.tool_palette_item_size < comfortable.metrics.tool_palette_item_size
3818        );
3819        assert!(comfortable.metrics.tool_palette_item_size < touch.metrics.tool_palette_item_size);
3820        assert!(
3821            compact.metrics.preset_strip_item_height < comfortable.metrics.preset_strip_item_height
3822        );
3823        assert!(
3824            comfortable.metrics.preset_strip_item_height < touch.metrics.preset_strip_item_height
3825        );
3826        assert!(
3827            compact.metrics.property_row_label_width < comfortable.metrics.property_row_label_width
3828        );
3829        assert!(
3830            comfortable.metrics.property_row_label_width < touch.metrics.property_row_label_width
3831        );
3832        assert!(compact.metrics.form_row_gap < comfortable.metrics.form_row_gap);
3833        assert!(comfortable.metrics.form_row_gap < touch.metrics.form_row_gap);
3834        assert!(compact.metrics.field_group_spacing < comfortable.metrics.field_group_spacing);
3835        assert!(comfortable.metrics.field_group_spacing < touch.metrics.field_group_spacing);
3836        assert!(
3837            compact.metrics.form_section_max_width < comfortable.metrics.form_section_max_width
3838        );
3839        assert!(comfortable.metrics.form_section_max_width < touch.metrics.form_section_max_width);
3840        assert!(compact.metrics.panel_section_gap < comfortable.metrics.panel_section_gap);
3841        assert!(comfortable.metrics.panel_section_gap < touch.metrics.panel_section_gap);
3842        assert!(
3843            compact.metrics.dock_panel_header_height < comfortable.metrics.dock_panel_header_height
3844        );
3845        assert!(
3846            comfortable.metrics.dock_panel_header_height < touch.metrics.dock_panel_header_height
3847        );
3848        assert!(compact.metrics.tab_height < comfortable.metrics.tab_height);
3849        assert!(comfortable.metrics.tab_height < touch.metrics.tab_height);
3850        assert!(compact.metrics.scroll_bar_thickness < comfortable.metrics.scroll_bar_thickness);
3851        assert!(comfortable.metrics.scroll_bar_thickness < touch.metrics.scroll_bar_thickness);
3852        assert!(
3853            compact.metrics.scroll_bar_min_thumb_length
3854                < comfortable.metrics.scroll_bar_min_thumb_length
3855        );
3856        assert!(
3857            comfortable.metrics.scroll_bar_min_thumb_length
3858                < touch.metrics.scroll_bar_min_thumb_length
3859        );
3860        assert!(
3861            compact.metrics.split_view_drag_target_thickness
3862                < comfortable.metrics.split_view_drag_target_thickness
3863        );
3864        assert!(
3865            comfortable.metrics.split_view_drag_target_thickness
3866                < touch.metrics.split_view_drag_target_thickness
3867        );
3868        assert!(
3869            compact.metrics.floating_workspace_margin
3870                < comfortable.metrics.floating_workspace_margin
3871        );
3872        assert!(
3873            comfortable.metrics.floating_workspace_margin < touch.metrics.floating_workspace_margin
3874        );
3875        assert!(
3876            compact.metrics.floating_view_title_bar_height
3877                < comfortable.metrics.floating_view_title_bar_height
3878        );
3879        assert!(
3880            comfortable.metrics.floating_view_title_bar_height
3881                < touch.metrics.floating_view_title_bar_height
3882        );
3883        assert!(
3884            compact.metrics.floating_view_resize_handle_size
3885                < comfortable.metrics.floating_view_resize_handle_size
3886        );
3887        assert!(
3888            comfortable.metrics.floating_view_resize_handle_size
3889                < touch.metrics.floating_view_resize_handle_size
3890        );
3891        assert!(compact.metrics.canvas_ruler_extent < comfortable.metrics.canvas_ruler_extent);
3892        assert!(comfortable.metrics.canvas_ruler_extent < touch.metrics.canvas_ruler_extent);
3893        assert!(
3894            compact.metrics.canvas_ruler_label_max_width
3895                < comfortable.metrics.canvas_ruler_label_max_width
3896        );
3897        assert!(
3898            comfortable.metrics.canvas_ruler_label_max_width
3899                < touch.metrics.canvas_ruler_label_max_width
3900        );
3901        assert!(
3902            compact.metrics.canvas_ruler_target_major_spacing
3903                < comfortable.metrics.canvas_ruler_target_major_spacing
3904        );
3905        assert!(
3906            comfortable.metrics.canvas_ruler_target_major_spacing
3907                < touch.metrics.canvas_ruler_target_major_spacing
3908        );
3909        assert!(compact.metrics.canvas_grid_step < comfortable.metrics.canvas_grid_step);
3910        assert!(comfortable.metrics.canvas_grid_step < touch.metrics.canvas_grid_step);
3911        assert!(
3912            compact.metrics.pixel_canvas_fit_padding < comfortable.metrics.pixel_canvas_fit_padding
3913        );
3914        assert!(
3915            comfortable.metrics.pixel_canvas_fit_padding < touch.metrics.pixel_canvas_fit_padding
3916        );
3917        assert!(compact.metrics.icon_size < comfortable.metrics.icon_size);
3918        assert!(comfortable.metrics.icon_size < touch.metrics.icon_size);
3919        assert!(
3920            compact.interaction.tab_selected_blend < comfortable.interaction.tab_selected_blend
3921        );
3922        assert!(comfortable.interaction.tab_selected_blend < touch.interaction.tab_selected_blend);
3923        assert_eq!(compact.interaction.pressed_offset, 0.0);
3924        assert_eq!(comfortable.interaction.pressed_offset, 0.0);
3925        assert_eq!(touch.interaction.pressed_offset, 0.0);
3926    }
3927
3928    #[test]
3929    fn contextual_control_sizes_match_authored_geometry_and_typography() {
3930        assert_eq!(ControlSize::default(), ControlSize::Medium);
3931
3932        let base = DefaultTheme::default();
3933        let small = base.with_size(ControlSize::Small);
3934        let medium = base.with_size(ControlSize::Medium);
3935        let large = base.with_size(ControlSize::Large);
3936
3937        assert_eq!(small.density, ThemeDensity::Compact);
3938        assert_eq!(medium.density, ThemeDensity::Comfortable);
3939        assert_eq!(large.density, ThemeDensity::Touch);
3940        assert_eq!(small.metrics.min_height, 28.0);
3941        assert_eq!(medium.metrics.min_height, 32.0);
3942        assert_eq!(large.metrics.min_height, 40.0);
3943        assert_eq!(small.metrics.list_row_height, 30.0);
3944        assert_eq!(medium.metrics.list_row_height, 36.0);
3945        assert_eq!(large.metrics.list_row_height, 44.0);
3946        assert_eq!(small.metrics.touch_target_size, 44.0);
3947        assert_eq!(medium.metrics.touch_target_size, 44.0);
3948        assert_eq!(large.metrics.touch_target_size, 44.0);
3949        assert_eq!(small.typography.body_font_size, base.text.sm.size);
3950        assert_eq!(medium.typography.body_font_size, base.text.base.size);
3951        assert_eq!(large.typography.body_font_size, base.text.lg.size);
3952        assert_eq!(large.text, base.text);
3953    }
3954
3955    #[test]
3956    fn contextual_control_size_uses_the_callers_scaled_text_ramp() {
3957        let mut theme = DefaultTheme::default();
3958        theme.text.sm.size = 15.0;
3959        theme.text.base.size = 17.0;
3960        theme.text.lg.size = 19.0;
3961
3962        let small = theme.with_size(ControlSize::Small);
3963        let medium = theme.with_size(ControlSize::Medium);
3964        let large = theme.with_size(ControlSize::Large);
3965
3966        assert_eq!(small.typography.body_font_size, 15.0);
3967        assert_eq!(medium.typography.body_font_size, 17.0);
3968        assert_eq!(large.typography.body_font_size, 19.0);
3969    }
3970
3971    #[test]
3972    fn contextual_control_size_survives_derived_theme_refresh() {
3973        let mut theme = DefaultTheme::dark().with_size(ControlSize::Small);
3974        theme.text.sm.size = 14.5;
3975
3976        theme.sync_derived_fields();
3977
3978        assert_eq!(theme.control_size, Some(ControlSize::Small));
3979        assert_eq!(theme.metrics.min_height, 28.0);
3980        assert_eq!(theme.metrics.touch_target_size, 44.0);
3981        assert_eq!(theme.typography.body_font_size, 14.5);
3982    }
3983
3984    #[test]
3985    fn default_theme_initializes_hdr_tokens() {
3986        let theme = DefaultTheme::default();
3987
3988        assert_eq!(theme.hdr.mode, HdrThemeMode::Disabled);
3989        assert_eq!(theme.hdr.color_roles.surface.sdr, theme.colors.base_100);
3990        assert_eq!(theme.hdr.color_roles.accent.sdr, theme.colors.primary);
3991        assert_eq!(
3992            theme.hdr.color_roles.accent_text.sdr,
3993            theme.colors.primary_content
3994        );
3995    }
3996
3997    #[test]
3998    fn mesh_theme_colors_use_cyan_as_signal_accent_and_amber_as_warning() {
3999        let light = ThemeColors::light();
4000        assert_eq!(light.primary, rgb8(8, 124, 164));
4001        assert_eq!(light.accent, light.primary);
4002        assert_eq!(light.accent_content, light.primary_content);
4003        assert_eq!(light.secondary, rgb8(143, 125, 248));
4004        assert_eq!(light.warning, rgb8(220, 154, 16));
4005
4006        let dark = ThemeColors::dark();
4007        assert_eq!(dark.primary, rgb8(53, 210, 238));
4008        assert_eq!(dark.accent, dark.primary);
4009        assert_eq!(dark.accent_content, dark.primary_content);
4010        assert_eq!(dark.secondary, rgb8(143, 125, 248));
4011        assert_eq!(dark.base_300, rgb8(29, 36, 49));
4012        assert_eq!(dark.warning, rgb8(253, 176, 34));
4013
4014        let void = ThemeColors::high_contrast();
4015        assert_eq!(void.primary, rgb8(33, 199, 229));
4016        assert_eq!(void.accent, void.primary);
4017        assert_eq!(void.accent_content, void.primary_content);
4018        assert_eq!(void.base_100, Color::BLACK);
4019        assert_eq!(void.base_300, rgb8(19, 23, 34));
4020    }
4021
4022    #[test]
4023    fn neutral_themes_are_achromatic_professional_presets() {
4024        let light = DefaultTheme::neutral();
4025        let colors = light.colors;
4026
4027        assert_eq!(DefaultTheme::sui(), DefaultTheme::light());
4028        assert_eq!(ThemeColors::sui(), ThemeColors::light());
4029        assert_eq!(colors.name, "neutral");
4030        assert_eq!(colors.scheme, ThemeColorScheme::Light);
4031        assert_eq!(colors.primary, rgb8(23, 23, 23));
4032        assert_eq!(colors.primary_content, Color::WHITE);
4033        assert_eq!(colors.secondary, rgb8(64, 64, 64));
4034        assert_eq!(colors.accent, colors.primary);
4035        assert_eq!(light.palette.accent, colors.primary);
4036        assert_eq!(light.palette.control, rgb8(245, 245, 245));
4037        assert_eq!(light.palette.border, rgb8(229, 229, 229));
4038        assert_eq!(light.palette.focus, rgb8(64, 64, 64));
4039        assert_eq!(light.surfaces.window_subtle, rgb8(250, 250, 250));
4040        assert_eq!(light.surfaces.checkerboard_dark, rgb8(229, 229, 229));
4041        assert_eq!(light.hdr.color_roles.accent.wide_gamut, None);
4042        assert_eq!(light.hdr.color_roles.accent.hdr, None);
4043
4044        let shadow = light
4045            .shadows
4046            .box_shadow
4047            .xs
4048            .first
4049            .expect("neutral theme should retain restrained elevation");
4050        assert_eq!(shadow.color.red, shadow.color.green);
4051        assert_eq!(shadow.color.green, shadow.color.blue);
4052
4053        for color in [
4054            colors.base_100,
4055            colors.base_200,
4056            colors.base_300,
4057            colors.base_content,
4058            colors.primary,
4059            colors.secondary,
4060            colors.accent,
4061            light.palette.focus,
4062            light.palette.selection,
4063        ] {
4064            assert_eq!(color.red, color.green);
4065            assert_eq!(color.green, color.blue);
4066        }
4067
4068        let dark = DefaultTheme::neutral_dark();
4069        let dark_colors = dark.colors;
4070        assert_eq!(dark_colors.name, "neutral-dark");
4071        assert_eq!(dark_colors.scheme, ThemeColorScheme::Dark);
4072        assert_eq!(dark_colors.base_100, rgb8(10, 10, 10));
4073        assert_eq!(dark_colors.base_content, rgb8(245, 245, 245));
4074        assert_eq!(dark_colors.primary, rgb8(245, 245, 245));
4075        assert_eq!(dark_colors.primary_content, rgb8(23, 23, 23));
4076        assert_eq!(dark.palette.surface_raised, rgb8(23, 23, 23));
4077        assert_eq!(dark.palette.control, rgb8(38, 38, 38));
4078        assert_eq!(dark.palette.control_hover, rgb8(51, 51, 51));
4079        assert_eq!(dark.palette.focus, rgb8(212, 212, 212));
4080        assert_eq!(dark.surfaces.window_subtle, rgb8(10, 10, 10));
4081        assert_eq!(dark.hdr.color_roles.accent.wide_gamut, None);
4082        assert_eq!(dark.hdr.color_roles.accent.hdr, None);
4083
4084        let glow = dark
4085            .glows
4086            .accent
4087            .first
4088            .expect("neutral dark should retain a restrained live-signal glow");
4089        assert_eq!(glow.color.red, glow.color.green);
4090        assert_eq!(glow.color.green, glow.color.blue);
4091
4092        for color in [
4093            dark_colors.base_100,
4094            dark_colors.base_200,
4095            dark_colors.base_300,
4096            dark_colors.base_content,
4097            dark_colors.primary,
4098            dark_colors.secondary,
4099            dark_colors.accent,
4100            dark.palette.focus,
4101            dark.palette.selection,
4102        ] {
4103            assert_eq!(color.red, color.green);
4104            assert_eq!(color.green, color.blue);
4105        }
4106    }
4107
4108    #[test]
4109    fn built_in_themes_use_exact_mesh_role_tokens() {
4110        // Translucent Mesh tokens are flattened onto the card surface with
4111        // CSS (gamma-space) compositing at theme build time, because the
4112        // renderer blends in linear space (which reads far heavier).
4113        let light = DefaultTheme::light();
4114        let light_surface = Color::WHITE;
4115        assert_eq!(light.palette.border, rgb8(227, 232, 239));
4116        assert_eq!(light.palette.border_strong, rgb8(205, 213, 224));
4117        assert_eq!(light.palette.text_muted, rgb8(73, 84, 107));
4118        assert_eq!(light.palette.placeholder, rgb8(104, 115, 144));
4119        assert_eq!(light.palette.control, rgb8(243, 245, 248));
4120        assert_eq!(light.palette.control_hover, rgb8(234, 238, 243));
4121        assert_eq!(light.palette.field, rgb8(248, 250, 252));
4122        assert_ne!(light.palette.field, light.palette.surface);
4123        assert_eq!(light.palette.focus, rgb8(9, 148, 198));
4124        assert_eq!(
4125            light.palette.selection,
4126            rgba8(8, 124, 164, 0.18).over(light_surface)
4127        );
4128        assert_eq!(
4129            light.palette.accent_soft,
4130            rgba8(8, 124, 164, 0.08).over(light_surface)
4131        );
4132        assert_eq!(light.palette.accent_soft.alpha, 1.0);
4133        assert_eq!(light.palette.accent_soft_text, rgb8(8, 124, 164));
4134        assert_eq!(light.palette.warning_soft_text, rgb8(154, 103, 0));
4135        assert_eq!(light.palette.danger_hover, rgb8(180, 35, 24));
4136        assert_eq!(light.surfaces.window_subtle, rgb8(247, 248, 250));
4137        assert_eq!(light.surfaces.sidebar, light.surfaces.window_subtle);
4138        assert_eq!(light.surfaces.overlay, Color::WHITE);
4139
4140        let dark = DefaultTheme::dark();
4141        let dark_surface = rgb8(18, 22, 31);
4142        assert_eq!(
4143            dark.palette.border,
4144            rgba8(151, 168, 199, 0.16).over(dark_surface)
4145        );
4146        assert_eq!(
4147            dark.palette.border_strong,
4148            rgba8(151, 168, 199, 0.27).over(dark_surface)
4149        );
4150        assert_eq!(dark.palette.text_muted, rgb8(166, 178, 200));
4151        assert_eq!(dark.palette.control, rgb8(23, 28, 39));
4152        assert_eq!(dark.palette.control_hover, rgb8(29, 36, 49));
4153        assert_eq!(dark.palette.field, rgb8(15, 19, 27));
4154        assert_eq!(dark.palette.surface_raised, dark_surface);
4155        assert_eq!(dark.palette.focus, rgb8(73, 199, 234));
4156        assert_eq!(
4157            dark.palette.selection,
4158            rgba8(53, 210, 238, 0.24).over(dark_surface)
4159        );
4160        assert_eq!(dark.palette.accent_hover, rgb8(95, 224, 246));
4161        assert_eq!(
4162            dark.palette.success_soft,
4163            rgba8(74, 222, 128, 0.12).over(dark_surface)
4164        );
4165        assert_eq!(dark.palette.success_soft_text, rgb8(74, 222, 128));
4166        assert_eq!(dark.surfaces.window_subtle, rgb8(14, 18, 26));
4167        assert_eq!(dark.surfaces.overlay, rgb8(22, 27, 38));
4168        assert_eq!(
4169            dark.surfaces.border_subtle,
4170            rgba8(151, 168, 199, 0.09).over(dark_surface)
4171        );
4172        assert_eq!(dark.surfaces.text_disabled, rgb8(81, 93, 117));
4173        assert_eq!(dark.surfaces.text_invert, rgb8(13, 18, 32));
4174
4175        let void = DefaultTheme::void();
4176        assert_eq!(
4177            void.palette.border,
4178            rgba8(158, 175, 205, 0.18).over(Color::BLACK)
4179        );
4180        assert_eq!(void.palette.field, rgb8(11, 14, 20));
4181        assert_eq!(void.palette.focus, rgb8(63, 196, 228));
4182        assert_eq!(void.surfaces.window_subtle, Color::BLACK);
4183        assert_eq!(void.surfaces.overlay, rgb8(10, 13, 19));
4184        // The scrim stays translucent: it is a true overlay above arbitrary
4185        // content, not a token that can be flattened ahead of time.
4186        assert_eq!(void.surfaces.overlay_scrim, rgba8(0, 0, 0, 0.72));
4187    }
4188
4189    #[test]
4190    fn elevation_follows_the_mesh_ladder_per_scheme() {
4191        let light = DefaultTheme::light();
4192        let dark = DefaultTheme::dark();
4193        let void = DefaultTheme::void();
4194
4195        // Light casts faint ink shadows.
4196        let light_sm = light.shadows.box_shadow.xs.first.expect("light xs shadow");
4197        assert!(light_sm.color.alpha > 0.0 && light_sm.color.alpha < 0.1);
4198        // Dark casts deeper black shadows.
4199        let dark_sm = dark.shadows.box_shadow.xs.first.expect("dark xs shadow");
4200        assert!(dark_sm.color.alpha > light_sm.color.alpha);
4201        // Void casts none: elevation is drawn with borders.
4202        assert_eq!(void.shadows.box_shadow.xs, ThemeShadow::empty());
4203        assert_eq!(void.shadows.box_shadow._2xl, ThemeShadow::empty());
4204        assert_eq!(void.shadows.drop.sm, ThemeShadow::empty());
4205
4206        // Glows: absent in Light, present in Dark, damped in Void.
4207        assert_eq!(light.glows.accent, ThemeShadow::empty());
4208        let dark_glow = dark.glows.accent.first.expect("dark accent glow");
4209        let void_glow = void.glows.accent.first.expect("void accent glow");
4210        assert!(dark_glow.blur > void_glow.blur);
4211        assert!(dark_glow.color.alpha > void_glow.color.alpha);
4212        assert_eq!(dark_glow.offset_x, 0.0);
4213        assert_eq!(dark_glow.offset_y, 0.0);
4214    }
4215
4216    #[test]
4217    fn density_tiers_match_the_mesh_contract() {
4218        let text = ThemeTextScale::default();
4219        assert_eq!(
4220            ControlTypography::for_density(&text, ThemeDensity::Compact),
4221            ControlTypography::for_size(&text, ControlSize::Small)
4222        );
4223        assert_eq!(
4224            ControlTypography::for_density(&text, ThemeDensity::Comfortable),
4225            ControlTypography::for_size(&text, ControlSize::Medium)
4226        );
4227        assert_eq!(
4228            ControlTypography::for_density(&text, ThemeDensity::Touch),
4229            ControlTypography::for_size(&text, ControlSize::Large)
4230        );
4231        let legacy_compact = DefaultTheme::default().with_density(ThemeDensity::Compact);
4232        let legacy_comfortable = DefaultTheme::default().with_density(ThemeDensity::Comfortable);
4233        let legacy_touch = DefaultTheme::default().with_density(ThemeDensity::Touch);
4234        assert_eq!(legacy_compact.typography.body_font_size, text.sm.size);
4235        assert_eq!(legacy_comfortable.typography.body_font_size, text.base.size);
4236        assert_eq!(legacy_touch.typography.body_font_size, text.lg.size);
4237
4238        let compact = DefaultTheme::compact();
4239        let comfortable = DefaultTheme::comfortable();
4240        let touch = DefaultTheme::touch();
4241
4242        // Authored control heights: 28 / 32 / 40, with a separate 44px target.
4243        assert_eq!(compact.metrics.min_height, 28.0);
4244        assert_eq!(comfortable.metrics.min_height, 32.0);
4245        assert_eq!(touch.metrics.min_height, 40.0);
4246        assert_eq!(compact.metrics.touch_target_size, 44.0);
4247        assert_eq!(comfortable.metrics.touch_target_size, 44.0);
4248        assert_eq!(touch.metrics.touch_target_size, 44.0);
4249
4250        // Rows: 30 / 36 / 44.
4251        assert_eq!(compact.metrics.list_row_height, 30.0);
4252        assert_eq!(comfortable.metrics.list_row_height, 36.0);
4253        assert_eq!(touch.metrics.list_row_height, 44.0);
4254        assert_eq!(compact.metrics.table_row_height, 30.0);
4255
4256        // Control type follows Small / Medium / Large on the shared text ramp.
4257        assert_eq!(compact.typography.body_font_size, 13.0);
4258        assert_eq!(comfortable.typography.body_font_size, 15.0);
4259        assert_eq!(touch.typography.body_font_size, 17.0);
4260
4261        // Control radius: 6 compact/comfortable, 8 touch.
4262        assert_eq!(compact.metrics.corner_radius, 6.0);
4263        assert_eq!(comfortable.metrics.corner_radius, 6.0);
4264        assert_eq!(touch.metrics.corner_radius, 8.0);
4265
4266        // The switch is a fixed 32x19 control at every density.
4267        for theme in [&compact, &comfortable, &touch] {
4268            assert_eq!(theme.metrics.switch_track_width, 32.0);
4269            assert_eq!(theme.metrics.switch_track_height, 19.0);
4270            assert_eq!(theme.metrics.checkbox_indicator_size, 15.0);
4271        }
4272    }
4273
4274    #[test]
4275    fn mesh_motion_ladder_is_70_140_220_340() {
4276        let motion = super::ThemeMotion::standard();
4277        assert_eq!(motion.duration_fast, 0.07);
4278        assert_eq!(motion.duration_normal, 0.14);
4279        assert_eq!(motion.duration_slow, 0.22);
4280        assert_eq!(motion.duration_slower, 0.34);
4281    }
4282
4283    #[test]
4284    fn light_and_dark_themes_derive_hdr_role_colors_from_semantics() {
4285        let light = DefaultTheme::light();
4286        let dark = DefaultTheme::dark();
4287
4288        assert_eq!(light.hdr.color_roles.surface.sdr, light.colors.base_100);
4289        assert_eq!(light.hdr.color_roles.text.sdr, light.colors.base_content);
4290        assert_eq!(dark.hdr.color_roles.surface.sdr, dark.colors.base_100);
4291        assert_eq!(dark.hdr.color_roles.accent.sdr, dark.colors.primary);
4292    }
4293
4294    #[test]
4295    fn sync_derived_fields_updates_semantic_palette_and_typography() {
4296        let mut theme = DefaultTheme::default();
4297        theme.colors.primary = Color::rgba(0.2, 0.3, 0.4, 1.0);
4298        theme.text.base.size = 11.0;
4299        theme.text.base.line_height = 15.0;
4300        theme.text.lg.size = 15.0;
4301        theme.text.lg.line_height = 22.0;
4302        theme.density = ThemeDensity::Touch;
4303        theme.sync_derived_fields();
4304
4305        assert_eq!(theme.palette.accent, Color::rgba(0.2, 0.3, 0.4, 1.0));
4306        assert_eq!(theme.palette.caret, Color::rgba(0.2, 0.3, 0.4, 1.0));
4307        assert_eq!(theme.surfaces.accent, theme.palette.accent);
4308        assert_eq!(theme.surfaces.window, theme.palette.surface);
4309        // Mesh tooltips are quiet floating surfaces: overlay fill, secondary ink.
4310        assert_eq!(theme.surfaces.tooltip, theme.surfaces.overlay);
4311        assert_eq!(theme.surfaces.tooltip_text, theme.palette.text_muted);
4312        assert!(theme.surfaces.overlay_scrim.alpha > 0.0);
4313        // Touch density reads at the lg body size per the Mesh density contract.
4314        assert_eq!(theme.typography.body_font_size, 15.0);
4315        assert_eq!(theme.typography.body_line_height, 22.0);
4316        assert_eq!(
4317            theme.metrics.min_height,
4318            DefaultTheme::default()
4319                .with_density(ThemeDensity::Touch)
4320                .metrics
4321                .min_height
4322        );
4323        assert_eq!(
4324            theme.interaction.pressed_offset,
4325            DefaultTheme::default()
4326                .with_density(ThemeDensity::Touch)
4327                .interaction
4328                .pressed_offset
4329        );
4330    }
4331
4332    #[test]
4333    fn control_palette_exposes_semantic_status_colors() {
4334        let theme = DefaultTheme::default();
4335
4336        assert_eq!(theme.palette.info, theme.colors.info);
4337        assert_eq!(theme.palette.info_text, theme.colors.info_content);
4338        assert_eq!(theme.palette.success, theme.colors.success);
4339        assert_eq!(theme.palette.success_text, theme.colors.success_content);
4340        assert_eq!(theme.palette.warning, theme.colors.warning);
4341        assert_eq!(theme.palette.warning_text, theme.colors.warning_content);
4342        assert_eq!(theme.palette.danger, theme.colors.error);
4343        assert_eq!(theme.palette.danger_text, theme.colors.error_content);
4344        assert_eq!(
4345            theme.semantic_tone_colors(SemanticTone::Warning),
4346            (theme.palette.warning, theme.palette.warning_text)
4347        );
4348        assert_eq!(
4349            theme.semantic_tone_color(SemanticTone::Danger),
4350            theme.palette.danger
4351        );
4352        assert_eq!(
4353            theme.semantic_tone_text_color(SemanticTone::Success),
4354            theme.palette.success_text
4355        );
4356    }
4357
4358    #[test]
4359    fn sync_derived_fields_updates_hdr_semantic_fallbacks() {
4360        let mut theme = DefaultTheme::default();
4361        let stale_wide_gamut = Color::display_p3(0.9, 0.4, 0.2, 1.0);
4362        let stale_hdr = Color::linear_display_p3(1.6, 0.5, 0.3, 1.0);
4363
4364        theme.hdr.color_roles.accent.wide_gamut = Some(stale_wide_gamut);
4365        theme.hdr.color_roles.accent.hdr = Some(stale_hdr);
4366        theme.colors = ThemeColors::dark();
4367        theme.colors.base_100 = Color::rgba(0.96, 0.97, 0.98, 1.0);
4368        theme.sync_derived_fields();
4369
4370        assert_eq!(theme.hdr.color_roles.surface.sdr, theme.colors.base_100);
4371        assert_eq!(theme.hdr.color_roles.accent.sdr, theme.colors.primary);
4372        assert_eq!(
4373            theme.hdr.color_roles.accent.wide_gamut,
4374            Some(Color::display_p3(0.13, 0.84, 0.95, 1.0))
4375        );
4376        assert_eq!(
4377            theme.hdr.color_roles.accent.hdr,
4378            Some(Color::linear_display_p3(0.16, 0.95, 1.10, 1.0))
4379        );
4380    }
4381
4382    #[test]
4383    fn dark_theme_uses_professional_dark_tokens() {
4384        let theme = DefaultTheme::dark();
4385
4386        assert_eq!(theme.colors.scheme, ThemeColorScheme::Dark);
4387        assert_eq!(theme.colors.name, "dark");
4388        assert_ne!(theme.colors.base_100, Color::BLACK);
4389        assert_eq!(theme.palette.surface, theme.colors.base_100);
4390        assert_ne!(theme.palette.surface_raised, Color::BLACK);
4391        assert_eq!(theme.palette.text, theme.colors.base_content);
4392        assert_ne!(theme.palette.text, Color::WHITE);
4393        assert_eq!(theme.palette.caret, theme.colors.primary);
4394        assert_eq!(theme.palette.accent, theme.colors.primary);
4395        assert_eq!(theme.palette.accent_text, theme.colors.primary_content);
4396        assert_eq!(theme.surfaces.window, theme.palette.surface);
4397        assert_eq!(theme.surfaces.panel, theme.palette.surface_raised);
4398        assert_eq!(theme.surfaces.border, theme.palette.border);
4399        assert_ne!(theme.surfaces.border, Color::WHITE);
4400        assert_ne!(theme.surfaces.text_faint, theme.palette.surface);
4401    }
4402
4403    #[test]
4404    fn high_contrast_scheme_uses_true_black_oled_palette() {
4405        let theme = DefaultTheme::high_contrast();
4406
4407        assert_eq!(theme.colors.scheme, ThemeColorScheme::HighContrast);
4408        assert_eq!(theme.colors.name, "void");
4409        assert_eq!(theme.palette.surface, theme.colors.base_100);
4410        assert_eq!(theme.palette.surface, Color::BLACK);
4411        assert_eq!(theme.surfaces.window, Color::BLACK);
4412        // The Void OLED contract keeps cards true black — the border is the
4413        // card. Only input wells and hover fills lift off black.
4414        assert_eq!(theme.palette.surface_raised, Color::BLACK);
4415        assert!(theme.palette.border.alpha > 0.0);
4416        assert_ne!(theme.palette.control, Color::BLACK);
4417        assert_ne!(theme.palette.field, Color::BLACK);
4418        assert_ne!(theme.palette.text, Color::WHITE);
4419        assert_ne!(theme.palette.control_hover, Color::BLACK);
4420        assert_ne!(theme.palette.control_active, Color::BLACK);
4421        assert_ne!(theme.palette.surface_focus, Color::BLACK);
4422        assert_eq!(theme.palette.text, theme.colors.base_content);
4423        assert_eq!(
4424            theme.metrics.border_width,
4425            DefaultTheme::default().metrics.border_width
4426        );
4427        assert_eq!(
4428            theme.metrics.focus_ring_width,
4429            DefaultTheme::default().metrics.focus_ring_width
4430        );
4431
4432        let touch = DefaultTheme::high_contrast().with_density(ThemeDensity::Touch);
4433        assert_eq!(touch.density, ThemeDensity::Touch);
4434        assert!(touch.metrics.min_height > theme.metrics.min_height);
4435        assert_eq!(
4436            touch.metrics.border_width,
4437            DefaultTheme::touch().metrics.border_width
4438        );
4439        assert_eq!(
4440            touch.metrics.focus_ring_width,
4441            DefaultTheme::touch().metrics.focus_ring_width
4442        );
4443    }
4444}