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 move only through neutral surface tiers; focus is
1278            // communicated by neutral contrast instead of a brand wash.
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(73, 84, 107),
1301            selection: rgba8(73, 84, 107, 0.12),
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(166, 178, 200),
1394            selection: rgba8(166, 178, 200, 0.14),
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(223, 229, 240),
1425            selection: rgba8(223, 229, 240, 0.18),
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    /// Accent-colored outline for selected tiles, segmented thumbs, and
1460    /// swatches. Selection fill remains neutral; this narrow border is the
1461    /// decorative brand cue.
1462    pub selection_border: Color,
1463    pub accent: Color,
1464    pub accent_hover: Color,
1465    pub accent_pressed: Color,
1466    pub accent_border: Color,
1467    pub accent_border_hover: Color,
1468    pub accent_border_focus: Color,
1469    pub accent_text: Color,
1470    /// Translucent accent wash (`--sm-accent-soft`): explicit accent badges,
1471    /// callouts, and decorative live signals. Selection and focus use their
1472    /// dedicated neutral roles instead.
1473    pub accent_soft: Color,
1474    /// Accent-hued text that stays legible on plain and soft surfaces
1475    /// (`--sm-accent-text` in Mesh terms; `accent_text` remains the
1476    /// on-solid-accent content color).
1477    pub accent_soft_text: Color,
1478    pub info: Color,
1479    pub info_text: Color,
1480    pub info_soft: Color,
1481    pub info_soft_text: Color,
1482    pub success: Color,
1483    pub success_text: Color,
1484    pub success_soft: Color,
1485    pub success_soft_text: Color,
1486    pub warning: Color,
1487    pub warning_text: Color,
1488    pub warning_soft: Color,
1489    pub warning_soft_text: Color,
1490    pub danger: Color,
1491    pub danger_text: Color,
1492    pub danger_soft: Color,
1493    pub danger_soft_text: Color,
1494    pub danger_hover: Color,
1495}
1496
1497impl ControlPalette {
1498    pub fn from_colors(colors: &ThemeColors) -> Self {
1499        let is_dark = matches!(
1500            colors.scheme,
1501            ThemeColorScheme::Dark | ThemeColorScheme::HighContrast
1502        );
1503        let roles = builtin_color_roles(colors);
1504        let surface = colors.base_100;
1505        let surface_raised = roles.map(|r| r.surface).unwrap_or(colors.base_200);
1506        // Mesh authors its translucent tokens as CSS rgba values, which
1507        // composite in encoded (gamma) space. The renderer blends in linear
1508        // space — noticeably heavier — so translucent roles are flattened
1509        // onto the card surface here with the CSS arithmetic.
1510        let flatten = move |color: Color| color.over(surface_raised);
1511        // Neutral raised control fill (buttons, chips): Mesh `--sm-surface-2`.
1512        let control = roles.map(|r| r.surface_2).unwrap_or(colors.base_200);
1513        let control_hover = roles
1514            .map(|r| r.surface_3)
1515            .unwrap_or_else(|| interactive_surface(control, colors.scheme, 0.035));
1516        let control_active = roles
1517            .map(|r| mix(r.surface_3, colors.base_content, 0.04))
1518            .unwrap_or_else(|| interactive_surface(control, colors.scheme, 0.075));
1519        let field = roles.map(|r| r.field).unwrap_or(control);
1520        let text_muted = roles.map(|r| r.text_2).unwrap_or_else(|| {
1521            mix(
1522                colors.base_content,
1523                surface,
1524                if is_dark { 0.34 } else { 0.16 },
1525            )
1526        });
1527        let placeholder = roles.map(|r| r.text_3).unwrap_or_else(|| {
1528            mix(
1529                colors.base_content,
1530                surface,
1531                if is_dark { 0.50 } else { 0.22 },
1532            )
1533        });
1534        let border = roles.map(|r| flatten(r.border)).unwrap_or_else(|| {
1535            if is_dark {
1536                mix(colors.base_300, surface, 0.22)
1537            } else {
1538                colors.base_300
1539            }
1540        });
1541        let border_strong = roles.map(|r| flatten(r.border_strong)).unwrap_or_else(|| {
1542            mix(
1543                colors.base_300,
1544                colors.base_content,
1545                if is_dark { 0.18 } else { 0.10 },
1546            )
1547        });
1548        // Hovered controls strengthen their neutral border. Brand color never
1549        // participates in structural interaction chrome.
1550        let border_hover = roles
1551            .map(|r| flatten(r.border_strong))
1552            .unwrap_or(border_strong);
1553        let focus = roles.map(|r| r.focus).unwrap_or_else(|| {
1554            mix(
1555                colors.base_content,
1556                surface_raised,
1557                if is_dark { 0.34 } else { 0.28 },
1558            )
1559        });
1560        let border_focus = mix(border_strong, focus, if is_dark { 0.45 } else { 0.38 });
1561        let selection = roles.map(|r| flatten(r.selection)).unwrap_or_else(|| {
1562            mix(
1563                surface_raised,
1564                colors.base_content,
1565                if is_dark { 0.14 } else { 0.08 },
1566            )
1567        });
1568        let selection_border_alpha = match colors.name {
1569            "neutral" | "neutral-dark" => 0.28,
1570            "void" => 0.32,
1571            _ => 0.35,
1572        };
1573        let selection_border = colors
1574            .primary
1575            .with_alpha(selection_border_alpha)
1576            .over(surface_raised);
1577        // Fallback derivations for soft washes and on-surface status text used
1578        // by custom themes; built-ins take the exact Mesh values.
1579        let soft_alpha = if is_dark { 0.12 } else { 0.10 };
1580        let derived_soft = move |color: Color| color.with_alpha(soft_alpha).over(surface_raised);
1581        let derived_soft_text = |color: Color| {
1582            if is_dark {
1583                mix(color, Color::WHITE, 0.22)
1584            } else {
1585                mix(color, Color::BLACK, 0.12)
1586            }
1587        };
1588
1589        Self {
1590            text: colors.base_content,
1591            text_muted,
1592            placeholder,
1593            surface,
1594            surface_raised,
1595            control,
1596            control_hover,
1597            control_active,
1598            field,
1599            surface_hover: control_hover,
1600            surface_pressed: control_active,
1601            surface_focus: mix(field, control_hover, if is_dark { 0.55 } else { 0.65 }),
1602            border,
1603            border_strong,
1604            border_hover,
1605            border_focus,
1606            focus,
1607            focus_ring: focus,
1608            caret: colors.base_content,
1609            selection,
1610            selection_border,
1611            accent: colors.primary,
1612            accent_hover: roles
1613                .map(|r| r.accent_hover)
1614                .unwrap_or_else(|| interactive_variant(colors.primary, colors.scheme, 0.08)),
1615            accent_pressed: interactive_variant(colors.primary, colors.scheme, 0.16),
1616            accent_border: roles
1617                .map(|r| flatten(r.accent_border))
1618                .unwrap_or_else(|| interactive_variant(colors.primary, colors.scheme, 0.12)),
1619            accent_border_hover: roles
1620                .map(|r| flatten(r.accent_border))
1621                .unwrap_or_else(|| interactive_variant(colors.primary, colors.scheme, 0.2)),
1622            accent_border_focus: colors.primary,
1623            accent_text: colors.primary_content,
1624            accent_soft: roles
1625                .map(|r| flatten(r.accent_soft))
1626                .unwrap_or_else(|| derived_soft(colors.primary)),
1627            accent_soft_text: roles
1628                .map(|r| r.accent_text)
1629                .unwrap_or_else(|| derived_soft_text(colors.primary)),
1630            info: colors.info,
1631            info_text: colors.info_content,
1632            info_soft: roles
1633                .map(|r| flatten(r.info_soft))
1634                .unwrap_or_else(|| derived_soft(colors.info)),
1635            info_soft_text: roles
1636                .map(|r| r.info_text)
1637                .unwrap_or_else(|| derived_soft_text(colors.info)),
1638            success: colors.success,
1639            success_text: colors.success_content,
1640            success_soft: roles
1641                .map(|r| flatten(r.ok_soft))
1642                .unwrap_or_else(|| derived_soft(colors.success)),
1643            success_soft_text: roles
1644                .map(|r| r.ok_text)
1645                .unwrap_or_else(|| derived_soft_text(colors.success)),
1646            warning: colors.warning,
1647            warning_text: colors.warning_content,
1648            warning_soft: roles
1649                .map(|r| flatten(r.warn_soft))
1650                .unwrap_or_else(|| derived_soft(colors.warning)),
1651            warning_soft_text: roles
1652                .map(|r| r.warn_text)
1653                .unwrap_or_else(|| derived_soft_text(colors.warning)),
1654            danger: colors.error,
1655            danger_text: colors.error_content,
1656            danger_soft: roles
1657                .map(|r| flatten(r.danger_soft))
1658                .unwrap_or_else(|| derived_soft(colors.error)),
1659            danger_soft_text: roles
1660                .map(|r| r.danger_text)
1661                .unwrap_or_else(|| derived_soft_text(colors.error)),
1662            danger_hover: roles
1663                .map(|r| r.danger_hover)
1664                .unwrap_or_else(|| interactive_variant(colors.error, colors.scheme, 0.08)),
1665        }
1666    }
1667}
1668
1669impl Default for ControlPalette {
1670    fn default() -> Self {
1671        Self::from_colors(&ThemeColors::default())
1672    }
1673}
1674
1675#[derive(Debug, Clone, Copy, PartialEq)]
1676pub struct SurfacePalette {
1677    pub dark: bool,
1678    pub window: Color,
1679    /// Slightly recessed window background (`--sm-bg-subtle`): sidebars,
1680    /// table headers, code block chrome.
1681    pub window_subtle: Color,
1682    pub sidebar: Color,
1683    pub panel: Color,
1684    /// Nested/raised fill one step above `panel` (`--sm-surface-2`).
1685    pub surface_2: Color,
1686    /// The strongest neutral fill tier (`--sm-surface-3`): hover wells,
1687    /// track backgrounds, avatar fills.
1688    pub surface_3: Color,
1689    /// Floating surface for menus, popovers, dialogs, toasts (`--sm-overlay`).
1690    pub overlay: Color,
1691    pub titlebar: Color,
1692    pub field: Color,
1693    pub border: Color,
1694    pub border_strong: Color,
1695    /// Hairline separators inside components (`--sm-border-subtle`).
1696    pub border_subtle: Color,
1697    pub text: Color,
1698    pub text_muted: Color,
1699    pub text_faint: Color,
1700    /// Disabled content (`--sm-text-disabled`).
1701    pub text_disabled: Color,
1702    /// Content drawn on inverted surfaces (`--sm-text-invert`).
1703    pub text_invert: Color,
1704    pub accent: Color,
1705    pub accent_hover: Color,
1706    pub on_accent: Color,
1707    /// Accent-hued text legible on plain surfaces (`--sm-accent-text`). Use
1708    /// for links and sparse decorative emphasis, not selected content.
1709    pub accent_text: Color,
1710    /// Translucent accent wash (`--sm-accent-soft`) for explicit decorative
1711    /// emphasis and live signals.
1712    pub accent_soft: Color,
1713    /// Translucent accent border (`--sm-accent-border`).
1714    pub accent_border: Color,
1715    /// The dedicated neutral keyboard-focus ring color (`--sm-focus`).
1716    pub focus: Color,
1717    pub hover: Color,
1718    pub selected: Color,
1719    /// Thin decorative selection outline; pair with neutral `selected` fill.
1720    pub selected_border: Color,
1721    pub overlay_scrim: Color,
1722    pub tooltip: Color,
1723    pub tooltip_border: Color,
1724    pub tooltip_text: Color,
1725    // Internal compatibility caches for widget-owned appearance resolvers.
1726    // External code customizes these through Canvas*/ColorPicker appearance types.
1727    pub(crate) canvas: Color,
1728    pub(crate) canvas_grid: Color,
1729    pub(crate) canvas_axis_x: Color,
1730    pub(crate) canvas_axis_y: Color,
1731    pub(crate) pixel_canvas_paper: Color,
1732    pub(crate) pixel_canvas_document_edge: Color,
1733    pub(crate) pixel_canvas_shadow_near: Color,
1734    pub(crate) pixel_canvas_shadow_far: Color,
1735    pub(crate) pixel_canvas_grid: Color,
1736    pub(crate) canvas_ruler: Color,
1737    pub(crate) canvas_ruler_border: Color,
1738    pub(crate) canvas_ruler_tick: Color,
1739    pub(crate) canvas_ruler_text: Color,
1740    pub(crate) checkerboard_light: Color,
1741    pub(crate) checkerboard_dark: Color,
1742    pub(crate) color_picker_chrome_border: Color,
1743    pub(crate) color_picker_plane_border: Color,
1744    pub(crate) color_picker_bar_border: Color,
1745    pub(crate) color_picker_marker_outer: Color,
1746    pub(crate) color_picker_marker_dark: Color,
1747    pub(crate) color_picker_marker_light: Color,
1748    pub(crate) color_picker_sdr_marker: Color,
1749    pub(crate) color_picker_hdr_divider: Color,
1750    pub good: Color,
1751    /// Positive-status text legible on plain/soft surfaces (`--sm-ok-text`).
1752    pub good_text: Color,
1753    /// Translucent positive wash (`--sm-ok-soft`).
1754    pub good_soft: Color,
1755    pub warn: Color,
1756    /// Warning text legible on plain/soft surfaces (`--sm-warn-text`).
1757    pub warn_text: Color,
1758    /// Translucent warning wash (`--sm-warn-soft`).
1759    pub warn_soft: Color,
1760    pub bad: Color,
1761    /// Danger text legible on plain/soft surfaces (`--sm-danger-text`).
1762    pub bad_text: Color,
1763    /// Translucent danger wash (`--sm-danger-soft`).
1764    pub bad_soft: Color,
1765    /// Solid informational status (`--sm-info`).
1766    pub info: Color,
1767    /// Informational text legible on plain/soft surfaces (`--sm-info-text`).
1768    pub info_text: Color,
1769    /// Translucent informational wash (`--sm-info-soft`).
1770    pub info_soft: Color,
1771}
1772
1773impl SurfacePalette {
1774    pub fn from_theme_parts(colors: &ThemeColors, controls: &ControlPalette) -> Self {
1775        let dark = matches!(
1776            colors.scheme,
1777            ThemeColorScheme::Dark | ThemeColorScheme::HighContrast
1778        );
1779        let neutral = is_neutral_theme(colors);
1780        let roles = builtin_color_roles(colors);
1781        let text_muted = controls.text_muted;
1782        let text_faint = controls.placeholder;
1783        let window_subtle = roles
1784            .map(|r| r.bg_subtle)
1785            .unwrap_or_else(|| mix(controls.surface, controls.control, 0.4));
1786        let overlay = roles.map(|r| r.overlay).unwrap_or(controls.surface_raised);
1787
1788        Self {
1789            dark,
1790            window: controls.surface,
1791            window_subtle,
1792            // The workspace chrome (sidebars, title bars) sits on the subtle
1793            // background tier so content panes read as the brighter surface.
1794            sidebar: window_subtle,
1795            panel: controls.surface_raised,
1796            surface_2: controls.control,
1797            surface_3: controls.control_hover,
1798            overlay,
1799            titlebar: window_subtle,
1800            field: controls.field,
1801            border: controls.border,
1802            border_strong: controls.border_strong,
1803            border_subtle: roles
1804                .map(|r| r.border_subtle.over(controls.surface_raised))
1805                .unwrap_or_else(|| mix(controls.border, controls.surface_raised, 0.44)),
1806            text: controls.text,
1807            text_muted,
1808            text_faint,
1809            text_disabled: roles.map(|r| r.text_disabled).unwrap_or_else(|| {
1810                mix(
1811                    controls.text,
1812                    controls.surface,
1813                    if dark { 0.62 } else { 0.44 },
1814                )
1815            }),
1816            text_invert: roles.map(|r| r.text_invert).unwrap_or(controls.surface),
1817            accent: controls.accent,
1818            accent_hover: controls.accent_hover,
1819            on_accent: controls.accent_text,
1820            accent_text: controls.accent_soft_text,
1821            accent_soft: controls.accent_soft,
1822            accent_border: controls.accent_border,
1823            focus: controls.focus,
1824            hover: controls.text.with_alpha(if dark { 0.06 } else { 0.045 }),
1825            selected: controls.selection,
1826            selected_border: controls.selection_border,
1827            overlay_scrim: roles
1828                .map(|r| r.scrim)
1829                .unwrap_or_else(|| Color::rgba(0.06, 0.08, 0.12, if dark { 0.38 } else { 0.24 })),
1830            // Mesh tooltips are quiet floating surfaces, not inverted bubbles:
1831            // overlay fill, strong border, secondary ink.
1832            tooltip: overlay,
1833            tooltip_border: controls.border_strong,
1834            tooltip_text: text_muted,
1835            canvas: controls.surface,
1836            canvas_grid: controls.border.with_alpha(if dark { 0.30 } else { 0.18 }),
1837            canvas_axis_x: colors.error.with_alpha(if dark { 0.72 } else { 0.55 }),
1838            canvas_axis_y: colors.success.with_alpha(if dark { 0.72 } else { 0.55 }),
1839            pixel_canvas_paper: if dark {
1840                mix(controls.surface_raised, controls.text, 0.10)
1841            } else if neutral {
1842                rgb8(250, 250, 250)
1843            } else {
1844                Color::rgba(0.975, 0.980, 0.988, 1.0)
1845            },
1846            pixel_canvas_document_edge: controls.text.with_alpha(if dark { 0.82 } else { 0.72 }),
1847            pixel_canvas_shadow_near: if neutral {
1848                Color::BLACK.with_alpha(if dark { 0.30 } else { 0.16 })
1849            } else {
1850                Color::rgba(0.05, 0.07, 0.10, if dark { 0.30 } else { 0.16 })
1851            },
1852            pixel_canvas_shadow_far: if neutral {
1853                Color::BLACK.with_alpha(if dark { 0.18 } else { 0.08 })
1854            } else {
1855                Color::rgba(0.05, 0.07, 0.10, if dark { 0.18 } else { 0.08 })
1856            },
1857            pixel_canvas_grid: controls.text.with_alpha(if dark { 0.32 } else { 0.28 }),
1858            canvas_ruler: controls.surface_raised,
1859            canvas_ruler_border: controls.border.with_alpha(0.78),
1860            canvas_ruler_tick: controls.text_muted.with_alpha(0.72),
1861            canvas_ruler_text: controls.text.with_alpha(0.76),
1862            checkerboard_light: if dark {
1863                mix(controls.surface_raised, controls.text, 0.18)
1864            } else if neutral {
1865                rgb8(250, 250, 250)
1866            } else {
1867                Color::rgba(0.980, 0.980, 0.990, 1.0)
1868            },
1869            checkerboard_dark: if dark {
1870                mix(controls.surface_raised, controls.text, 0.10)
1871            } else if neutral {
1872                rgb8(229, 229, 229)
1873            } else {
1874                Color::rgba(0.900, 0.920, 0.950, 1.0)
1875            },
1876            color_picker_chrome_border: controls.text.with_alpha(if dark { 0.24 } else { 0.18 }),
1877            color_picker_plane_border: controls.text.with_alpha(if dark { 0.22 } else { 0.16 }),
1878            color_picker_bar_border: controls.text.with_alpha(if dark { 0.20 } else { 0.14 }),
1879            color_picker_marker_outer: controls.surface_raised.with_alpha(0.92),
1880            color_picker_marker_dark: Color::BLACK.with_alpha(0.84),
1881            color_picker_marker_light: Color::WHITE.with_alpha(0.95),
1882            color_picker_sdr_marker: controls.surface_raised.with_alpha(0.30),
1883            color_picker_hdr_divider: controls.surface_raised.with_alpha(0.28),
1884            good: colors.success,
1885            good_text: controls.success_soft_text,
1886            good_soft: controls.success_soft,
1887            warn: colors.warning,
1888            warn_text: controls.warning_soft_text,
1889            warn_soft: controls.warning_soft,
1890            bad: colors.error,
1891            bad_text: controls.danger_soft_text,
1892            bad_soft: controls.danger_soft,
1893            info: colors.info,
1894            info_text: controls.info_soft_text,
1895            info_soft: controls.info_soft,
1896        }
1897    }
1898}
1899
1900impl Default for SurfacePalette {
1901    fn default() -> Self {
1902        let colors = ThemeColors::default();
1903        let controls = ControlPalette::from_colors(&colors);
1904        Self::from_theme_parts(&colors, &controls)
1905    }
1906}
1907
1908#[derive(Debug, Clone, Copy, PartialEq)]
1909pub struct ControlTypography {
1910    pub body_font_size: f32,
1911    pub body_line_height: f32,
1912}
1913
1914impl ControlTypography {
1915    pub fn from_text_scale(text: &ThemeTextScale) -> Self {
1916        Self::for_density(text, ThemeDensity::default())
1917    }
1918
1919    /// Legacy density typography. Authored interfaces should prefer
1920    /// [`Self::for_size`]; the legacy Compact/Comfortable/Touch tiers mirror
1921    /// Small/Medium/Large so both paths resolve the same text-ramp tokens.
1922    pub fn for_density(text: &ThemeTextScale, density: ThemeDensity) -> Self {
1923        let token = match density {
1924            ThemeDensity::Compact => text.sm,
1925            ThemeDensity::Comfortable => text.base,
1926            ThemeDensity::Touch => text.lg,
1927        };
1928        Self {
1929            body_font_size: token.size,
1930            body_line_height: token.line_height,
1931        }
1932    }
1933
1934    /// Resolve authored interface-size typography from the current text scale.
1935    /// Text scaling remains independent: each size selects a token from the
1936    /// already-scaled ramp instead of applying another multiplier.
1937    pub fn for_size(text: &ThemeTextScale, size: ControlSize) -> Self {
1938        let token = match size {
1939            ControlSize::Small => text.sm,
1940            ControlSize::Medium => text.base,
1941            ControlSize::Large => text.lg,
1942        };
1943        Self {
1944            body_font_size: token.size,
1945            body_line_height: token.line_height,
1946        }
1947    }
1948}
1949
1950impl Default for ControlTypography {
1951    fn default() -> Self {
1952        Self::from_text_scale(&ThemeTextScale::default())
1953    }
1954}
1955
1956#[derive(Debug, Clone, Copy, PartialEq)]
1957pub struct ControlStateMetrics {
1958    pub hover_blend: f32,
1959    pub pressed_blend: f32,
1960    pub selected_blend: f32,
1961    pub tab_selected_blend: f32,
1962    pub disabled_opacity: f32,
1963    pub disabled_content_opacity: f32,
1964    pub pressed_offset: f32,
1965    pub active_indicator_thickness: f32,
1966}
1967
1968impl ControlStateMetrics {
1969    pub fn for_density(density: ThemeDensity) -> Self {
1970        match density {
1971            ThemeDensity::Compact => Self {
1972                hover_blend: 0.78,
1973                pressed_blend: 0.88,
1974                selected_blend: 0.20,
1975                tab_selected_blend: 0.07,
1976                disabled_opacity: 0.70,
1977                disabled_content_opacity: 0.46,
1978                pressed_offset: 0.0,
1979                active_indicator_thickness: 2.0,
1980            },
1981            ThemeDensity::Comfortable => Self {
1982                hover_blend: 0.86,
1983                pressed_blend: 1.0,
1984                selected_blend: 0.22,
1985                tab_selected_blend: 0.08,
1986                disabled_opacity: 0.74,
1987                disabled_content_opacity: 0.50,
1988                pressed_offset: 0.0,
1989                active_indicator_thickness: 3.0,
1990            },
1991            ThemeDensity::Touch => Self {
1992                hover_blend: 0.94,
1993                pressed_blend: 1.0,
1994                selected_blend: 0.24,
1995                tab_selected_blend: 0.09,
1996                disabled_opacity: 0.78,
1997                disabled_content_opacity: 0.54,
1998                pressed_offset: 0.0,
1999                active_indicator_thickness: 4.0,
2000            },
2001        }
2002    }
2003}
2004
2005impl Default for ControlStateMetrics {
2006    fn default() -> Self {
2007        Self::for_density(ThemeDensity::default())
2008    }
2009}
2010
2011#[derive(Debug, Clone, Copy, PartialEq)]
2012pub struct ControlMetrics {
2013    pub min_height: f32,
2014    pub touch_target_size: f32,
2015    pub button_min_width: f32,
2016    pub button_padding: Insets,
2017    pub checkbox_padding: Insets,
2018    pub checkbox_indicator_size: f32,
2019    pub checkbox_gap: f32,
2020    pub icon_label_gap: f32,
2021    pub separator_thickness: f32,
2022    pub icon_size: f32,
2023    pub icon_button_size: f32,
2024    pub switch_track_width: f32,
2025    pub switch_track_height: f32,
2026    pub switch_thumb_inset: f32,
2027    pub slider_min_width: f32,
2028    pub slider_padding: Insets,
2029    pub slider_track_height: f32,
2030    pub slider_thumb_size: f32,
2031    pub number_input_stepper_width: f32,
2032    pub text_input_min_width: f32,
2033    pub text_input_padding: Insets,
2034    pub text_area_min_height: f32,
2035    pub select_menu_max_height: f32,
2036    pub select_menu_gap: f32,
2037    pub select_menu_edge_padding: f32,
2038    pub tab_height: f32,
2039    pub tab_min_width: f32,
2040    pub tab_gap: f32,
2041    pub tab_padding: Insets,
2042    pub tab_panel_padding: Insets,
2043    pub tab_panel_gap: f32,
2044    pub menu_row_height: f32,
2045    pub menu_padding: Insets,
2046    pub menu_item_padding: Insets,
2047    pub menu_shortcut_width: f32,
2048    pub popover_padding: Insets,
2049    pub popover_gap: f32,
2050    pub popover_reveal_offset: f32,
2051    pub tooltip_padding: Insets,
2052    pub tooltip_min_width: f32,
2053    pub tooltip_gap: f32,
2054    pub tooltip_reveal_offset: f32,
2055    pub dialog_min_width: f32,
2056    pub dialog_max_width: f32,
2057    pub dialog_outer_margin: f32,
2058    pub dialog_padding: Insets,
2059    pub dialog_title_font_size: f32,
2060    pub dialog_title_line_height: f32,
2061    pub dialog_description_gap: f32,
2062    pub dialog_body_gap: f32,
2063    pub dialog_footer_gap: f32,
2064    pub dialog_action_gap: f32,
2065    pub dialog_action_min_width: f32,
2066    pub toolbar_extent: f32,
2067    pub toolbar_padding: Insets,
2068    pub toolbar_spacing: f32,
2069    pub command_group_padding: Insets,
2070    pub command_group_spacing: f32,
2071    pub command_group_radius: f32,
2072    pub tool_palette_item_size: f32,
2073    pub tool_palette_icon_size: f32,
2074    pub preset_strip_item_height: f32,
2075    pub preset_strip_item_min_width: f32,
2076    pub preset_strip_item_padding: Insets,
2077    pub preset_strip_gap: f32,
2078    pub preset_strip_label_padding: Insets,
2079    pub action_card_min_width: f32,
2080    pub action_card_min_height: f32,
2081    pub action_card_padding: Insets,
2082    pub action_card_icon_box_size: f32,
2083    pub action_card_icon_size: f32,
2084    pub action_card_icon_gap: f32,
2085    pub action_card_text_gap: f32,
2086    pub action_card_trailing_gap: f32,
2087    pub action_card_chevron_size: f32,
2088    pub action_card_accent_width: f32,
2089    pub action_card_accent_inset: f32,
2090    pub status_bar_height: f32,
2091    pub status_bar_segment_padding: f32,
2092    pub status_bar_segment_min_width: f32,
2093    pub status_bar_separator_inset: f32,
2094    pub progress_bar_min_width: f32,
2095    pub progress_bar_height: f32,
2096    pub progress_bar_value_height: f32,
2097    pub progress_bar_label_padding: Insets,
2098    pub property_row_label_width: f32,
2099    pub property_row_inline_gap: f32,
2100    pub property_row_stacked_gap: f32,
2101    pub form_row_label_width: f32,
2102    pub form_row_control_width: f32,
2103    pub form_row_gap: f32,
2104    pub field_group_spacing: f32,
2105    pub form_section_padding: Insets,
2106    pub form_section_body_gap: f32,
2107    pub form_section_header_gap: f32,
2108    pub form_section_description_gap: f32,
2109    pub form_section_max_width: f32,
2110    pub form_section_radius: f32,
2111    pub panel_section_gap: f32,
2112    pub panel_section_action_gap: f32,
2113    pub panel_section_disclosure_size: f32,
2114    pub dock_panel_header_height: f32,
2115    pub dock_panel_padding: Insets,
2116    pub data_viewport_padding: Insets,
2117    pub data_row_padding: Insets,
2118    pub data_row_icon_size: f32,
2119    pub data_row_icon_gap: f32,
2120    pub data_row_trailing_gap: f32,
2121    pub data_scroll_thumb_width: f32,
2122    pub data_scroll_thumb_inset: f32,
2123    pub data_scroll_thumb_radius: f32,
2124    pub data_scroll_thumb_min_length: f32,
2125    pub data_scroll_thumb_opacity: f32,
2126    pub list_row_height: f32,
2127    pub layer_row_height: f32,
2128    pub layer_action_size: f32,
2129    pub layer_action_icon_inset: f32,
2130    pub layer_lock_icon_inset: f32,
2131    pub layer_visibility_stroke_width: f32,
2132    pub layer_visibility_slash_stroke_width: f32,
2133    pub layer_thumbnail_size: f32,
2134    pub layer_thumbnail_inset: f32,
2135    pub layer_thumbnail_radius: f32,
2136    pub layer_thumbnail_disabled_opacity: f32,
2137    pub layer_thumbnail_disabled_border_opacity: f32,
2138    pub tree_row_height: f32,
2139    pub tree_indent: f32,
2140    pub tree_disclosure_size: f32,
2141    pub tree_disclosure_gap: f32,
2142    pub table_row_height: f32,
2143    pub table_header_height: f32,
2144    pub table_cell_padding: f32,
2145    pub table_header_separator_inset: f32,
2146    pub table_separator_width: f32,
2147    pub table_row_border_opacity: f32,
2148    pub breadcrumb_height: f32,
2149    pub breadcrumb_item_padding: Insets,
2150    pub breadcrumb_gap: f32,
2151    pub breadcrumb_separator_size: f32,
2152    pub image_corner_radius: f32,
2153    pub color_swatch_width: f32,
2154    pub color_swatch_height: f32,
2155    pub color_swatch_inner_inset: f32,
2156    pub color_swatch_checker_size: f32,
2157    pub color_palette_swatch_size: f32,
2158    pub color_palette_gap: f32,
2159    pub color_palette_swatch_inset: f32,
2160    pub color_palette_selected_swatch_inset: f32,
2161    pub color_palette_checker_size: f32,
2162    pub brush_preview_min_width: f32,
2163    pub brush_preview_min_height: f32,
2164    pub brush_preview_padding: Insets,
2165    pub brush_preview_swatch_width: f32,
2166    pub brush_preview_swatch_gap: f32,
2167    pub brush_preview_checker_size: f32,
2168    pub brush_preview_text_height: f32,
2169    pub brush_preview_text_font_size: f32,
2170    pub brush_preview_text_line_height: f32,
2171    pub color_picker_content_inset: f32,
2172    pub color_picker_panel_gap: f32,
2173    pub color_picker_top_bar_height: f32,
2174    pub color_picker_swatch_width: f32,
2175    pub color_picker_swatch_gap: f32,
2176    pub color_picker_section_gap: f32,
2177    pub color_picker_wheel_size: f32,
2178    pub color_picker_map_size: f32,
2179    pub color_picker_row_height: f32,
2180    pub color_picker_row_gap: f32,
2181    pub color_picker_right_panel_width: f32,
2182    pub color_picker_field_height: f32,
2183    pub color_picker_field_gap: f32,
2184    pub color_picker_dropdown_gap: f32,
2185    pub color_picker_encoding_menu_row_height: f32,
2186    pub scroll_bar_thickness: f32,
2187    pub scroll_bar_min_thumb_length: f32,
2188    pub split_view_divider_thickness: f32,
2189    pub split_view_drag_target_thickness: f32,
2190    pub floating_workspace_margin: f32,
2191    pub floating_view_title_bar_height: f32,
2192    pub floating_view_title_padding: Insets,
2193    pub floating_view_resize_handle_size: f32,
2194    pub canvas_ruler_extent: f32,
2195    pub canvas_ruler_major_tick: f32,
2196    pub canvas_ruler_minor_tick: f32,
2197    pub canvas_ruler_target_major_spacing: f32,
2198    pub canvas_ruler_label_padding: Insets,
2199    pub canvas_ruler_label_max_width: f32,
2200    pub canvas_grid_step: f32,
2201    pub canvas_axis_overscan: f32,
2202    pub pixel_canvas_fit_padding: f32,
2203    pub pixel_canvas_grid_zoom: f32,
2204    pub pixel_canvas_nearest_sampling_zoom: f32,
2205    pub pixel_canvas_zoom_step: f32,
2206    pub corner_radius: f32,
2207    pub indicator_corner_radius: f32,
2208    pub border_width: f32,
2209    pub focus_ring_width: f32,
2210    pub focus_ring_outset: f32,
2211    pub caret_width: f32,
2212}
2213
2214impl ControlMetrics {
2215    pub fn from_tokens(spacing: f32, radius: ThemeRadii, density: ThemeDensity) -> Self {
2216        let unit = spacing.max(1.0);
2217        let (
2218            min_height,
2219            touch_target_size,
2220            button_padding,
2221            checkbox_padding,
2222            checkbox_indicator_size,
2223            icon_size,
2224            icon_button_size,
2225            switch_track_width,
2226            switch_track_height,
2227            switch_thumb_inset,
2228            slider_min_width,
2229            slider_padding,
2230            slider_track_height,
2231            slider_thumb_size,
2232            number_input_stepper_width,
2233            text_input_min_width,
2234            text_input_padding,
2235            text_area_min_height,
2236            select_menu_max_height,
2237            tab_height,
2238            tab_min_width,
2239            tab_padding,
2240            tab_panel_padding,
2241            tab_panel_gap,
2242            menu_row_height,
2243            menu_padding,
2244            menu_item_padding,
2245            popover_padding,
2246            action_card_min_width,
2247            action_card_min_height,
2248            action_card_padding,
2249            action_card_icon_box_size,
2250            action_card_icon_size,
2251            action_card_icon_gap,
2252            action_card_text_gap,
2253            action_card_trailing_gap,
2254            action_card_chevron_size,
2255            action_card_accent_width,
2256            action_card_accent_inset,
2257            status_bar_height,
2258            status_bar_segment_padding,
2259            status_bar_segment_min_width,
2260            status_bar_separator_inset,
2261            progress_bar_min_width,
2262            progress_bar_height,
2263            progress_bar_value_height,
2264            progress_bar_label_padding,
2265            data_viewport_padding,
2266            data_row_padding,
2267            data_row_icon_size,
2268            data_row_icon_gap,
2269            data_row_trailing_gap,
2270            list_row_height,
2271            layer_row_height,
2272            layer_action_size,
2273            layer_thumbnail_size,
2274            tree_row_height,
2275            tree_indent,
2276            tree_disclosure_size,
2277            tree_disclosure_gap,
2278            table_row_height,
2279            table_header_height,
2280            table_cell_padding,
2281            breadcrumb_height,
2282            breadcrumb_item_padding,
2283            breadcrumb_gap,
2284            breadcrumb_separator_size,
2285        ) = match density {
2286            ThemeDensity::Compact => (
2287                28.0,
2288                28.0,
2289                Insets {
2290                    left: unit * 1.5,
2291                    top: unit * 0.75,
2292                    right: unit * 1.5,
2293                    bottom: unit * 0.75,
2294                },
2295                Insets {
2296                    left: unit,
2297                    top: unit * 0.5,
2298                    right: unit,
2299                    bottom: unit * 0.5,
2300                },
2301                15.0,
2302                14.0,
2303                28.0,
2304                32.0,
2305                19.0,
2306                3.0,
2307                120.0,
2308                Insets {
2309                    left: unit * 1.5,
2310                    top: unit * 0.5,
2311                    right: unit * 1.5,
2312                    bottom: unit * 0.5,
2313                },
2314                4.0,
2315                14.0,
2316                22.0,
2317                150.0,
2318                Insets {
2319                    left: unit * 2.0,
2320                    top: unit * 0.75,
2321                    right: unit * 2.0,
2322                    bottom: unit * 0.75,
2323                },
2324                56.0,
2325                176.0,
2326                32.0,
2327                84.0,
2328                Insets {
2329                    left: unit * 2.5,
2330                    top: unit * 0.75,
2331                    right: unit * 2.5,
2332                    bottom: unit * 0.75,
2333                },
2334                Insets::all(unit * 3.0),
2335                unit * 2.0,
2336                28.0,
2337                Insets::all(unit),
2338                Insets {
2339                    left: unit * 2.0,
2340                    top: unit * 0.5,
2341                    right: unit * 2.0,
2342                    bottom: unit * 0.5,
2343                },
2344                Insets::all(unit * 2.5),
2345                252.0,
2346                84.0,
2347                Insets {
2348                    left: unit * 3.0,
2349                    top: unit * 2.5,
2350                    right: unit * 2.5,
2351                    bottom: unit * 2.5,
2352                },
2353                32.0,
2354                16.0,
2355                unit * 2.5,
2356                unit,
2357                18.0,
2358                14.0,
2359                2.0,
2360                unit * 2.0,
2361                34.0,
2362                unit * 2.0,
2363                72.0,
2364                unit * 1.25,
2365                180.0,
2366                14.0,
2367                22.0,
2368                Insets::all(unit * 0.5),
2369                Insets::all(unit * 1.5),
2370                Insets {
2371                    left: unit * 3.0,
2372                    top: unit * 0.5,
2373                    right: unit * 2.0,
2374                    bottom: unit * 0.5,
2375                },
2376                12.0,
2377                unit * 1.5,
2378                unit * 2.0,
2379                30.0,
2380                38.0,
2381                22.0,
2382                26.0,
2383                30.0,
2384                unit * 4.0,
2385                10.0,
2386                unit,
2387                30.0,
2388                28.0,
2389                unit * 2.5,
2390                28.0,
2391                Insets {
2392                    left: unit * 2.0,
2393                    top: unit * 0.75,
2394                    right: unit * 2.0,
2395                    bottom: unit * 0.75,
2396                },
2397                unit * 4.0,
2398                9.0,
2399            ),
2400            ThemeDensity::Comfortable => (
2401                32.0,
2402                36.0,
2403                Insets {
2404                    left: unit * 2.0,
2405                    top: unit * 1.25,
2406                    right: unit * 2.0,
2407                    bottom: unit * 1.25,
2408                },
2409                Insets {
2410                    left: unit * 1.5,
2411                    top: unit,
2412                    right: unit * 1.5,
2413                    bottom: unit,
2414                },
2415                15.0,
2416                16.0,
2417                32.0,
2418                32.0,
2419                19.0,
2420                3.0,
2421                140.0,
2422                Insets {
2423                    left: unit * 2.0,
2424                    top: unit,
2425                    right: unit * 2.0,
2426                    bottom: unit,
2427                },
2428                4.0,
2429                14.0,
2430                24.0,
2431                180.0,
2432                Insets {
2433                    left: unit * 2.0,
2434                    top: unit * 1.25,
2435                    right: unit * 2.0,
2436                    bottom: unit * 1.25,
2437                },
2438                64.0,
2439                200.0,
2440                36.0,
2441                96.0,
2442                Insets {
2443                    left: unit * 2.5,
2444                    top: unit,
2445                    right: unit * 2.5,
2446                    bottom: unit,
2447                },
2448                Insets::all(unit * 4.0),
2449                unit * 3.0,
2450                32.0,
2451                Insets::all(unit * 1.5),
2452                Insets {
2453                    left: unit * 3.0,
2454                    top: unit,
2455                    right: unit * 3.0,
2456                    bottom: unit,
2457                },
2458                Insets::all(unit * 3.5),
2459                280.0,
2460                104.0,
2461                Insets {
2462                    left: unit * 4.0,
2463                    top: unit * 3.5,
2464                    right: unit * 3.5,
2465                    bottom: unit * 3.5,
2466                },
2467                38.0,
2468                20.0,
2469                unit * 3.0,
2470                unit * 1.25,
2471                22.0,
2472                16.0,
2473                3.0,
2474                unit * 2.5,
2475                40.0,
2476                unit * 2.5,
2477                86.0,
2478                unit * 1.5,
2479                240.0,
2480                18.0,
2481                18.0,
2482                Insets::all(unit * 0.5),
2483                Insets::all(unit * 2.0),
2484                Insets {
2485                    left: 14.0,
2486                    top: unit,
2487                    right: 10.0,
2488                    bottom: unit,
2489                },
2490                14.0,
2491                unit * 2.0,
2492                unit * 3.0,
2493                36.0,
2494                40.0,
2495                26.0,
2496                34.0,
2497                36.0,
2498                18.0,
2499                12.0,
2500                6.0,
2501                36.0,
2502                34.0,
2503                unit * 2.5,
2504                36.0,
2505                Insets {
2506                    left: unit * 2.0,
2507                    top: unit,
2508                    right: unit * 2.0,
2509                    bottom: unit,
2510                },
2511                unit * 5.0,
2512                10.0,
2513            ),
2514            ThemeDensity::Touch => (
2515                36.0,
2516                44.0,
2517                Insets {
2518                    left: unit * 2.5,
2519                    top: unit * 1.5,
2520                    right: unit * 2.5,
2521                    bottom: unit * 1.5,
2522                },
2523                Insets {
2524                    left: unit * 2.0,
2525                    top: unit * 1.5,
2526                    right: unit * 2.0,
2527                    bottom: unit * 1.5,
2528                },
2529                15.0,
2530                18.0,
2531                36.0,
2532                32.0,
2533                19.0,
2534                3.0,
2535                160.0,
2536                Insets {
2537                    left: unit * 2.5,
2538                    top: unit * 1.5,
2539                    right: unit * 2.5,
2540                    bottom: unit * 1.5,
2541                },
2542                4.0,
2543                14.0,
2544                30.0,
2545                200.0,
2546                Insets {
2547                    left: unit * 2.0,
2548                    top: unit * 1.5,
2549                    right: unit * 2.0,
2550                    bottom: unit * 1.5,
2551                },
2552                72.0,
2553                230.0,
2554                40.0,
2555                104.0,
2556                Insets {
2557                    left: unit * 2.5,
2558                    top: unit * 1.5,
2559                    right: unit * 2.5,
2560                    bottom: unit * 1.5,
2561                },
2562                Insets::all(unit * 4.5),
2563                unit * 3.5,
2564                40.0,
2565                Insets::all(unit * 1.75),
2566                Insets {
2567                    left: unit * 3.25,
2568                    top: unit * 1.5,
2569                    right: unit * 3.25,
2570                    bottom: unit * 1.5,
2571                },
2572                Insets::all(unit * 4.0),
2573                300.0,
2574                112.0,
2575                Insets {
2576                    left: unit * 4.5,
2577                    top: unit * 4.0,
2578                    right: unit * 4.0,
2579                    bottom: unit * 4.0,
2580                },
2581                42.0,
2582                22.0,
2583                unit * 3.25,
2584                unit * 1.5,
2585                26.0,
2586                18.0,
2587                3.5,
2588                unit * 2.75,
2589                46.0,
2590                unit * 2.75,
2591                96.0,
2592                unit * 1.75,
2593                260.0,
2594                22.0,
2595                22.0,
2596                Insets::all(unit * 0.75),
2597                Insets::all(unit * 2.25),
2598                Insets {
2599                    left: unit * 3.5,
2600                    top: unit * 1.5,
2601                    right: unit * 2.75,
2602                    bottom: unit * 1.5,
2603                },
2604                16.0,
2605                unit * 2.25,
2606                unit * 3.5,
2607                40.0,
2608                44.0,
2609                32.0,
2610                38.0,
2611                40.0,
2612                22.0,
2613                14.0,
2614                unit * 1.5,
2615                40.0,
2616                38.0,
2617                unit * 2.5,
2618                40.0,
2619                Insets {
2620                    left: unit * 2.5,
2621                    top: unit * 1.5,
2622                    right: unit * 2.5,
2623                    bottom: unit * 1.5,
2624                },
2625                unit * 5.5,
2626                11.0,
2627            ),
2628        };
2629
2630        let (
2631            popover_reveal_offset,
2632            tooltip_padding,
2633            tooltip_min_width,
2634            tooltip_gap,
2635            tooltip_reveal_offset,
2636            dialog_min_width,
2637            dialog_max_width,
2638            dialog_outer_margin,
2639            dialog_padding,
2640            dialog_title_font_size,
2641            dialog_title_line_height,
2642            dialog_description_gap,
2643            dialog_body_gap,
2644            dialog_footer_gap,
2645            dialog_action_gap,
2646            dialog_action_min_width,
2647        ) = match density {
2648            ThemeDensity::Compact => (
2649                8.0,
2650                Insets {
2651                    left: unit * 2.0,
2652                    top: unit * 1.5,
2653                    right: unit * 2.0,
2654                    bottom: unit * 1.5,
2655                },
2656                80.0,
2657                unit * 2.0,
2658                6.0,
2659                240.0,
2660                440.0,
2661                unit * 4.0,
2662                Insets::all(unit * 3.5),
2663                16.0,
2664                24.0,
2665                unit * 1.5,
2666                unit * 3.0,
2667                unit * 3.5,
2668                unit * 2.0,
2669                92.0,
2670            ),
2671            ThemeDensity::Comfortable => (
2672                10.0,
2673                Insets {
2674                    left: unit * 2.25,
2675                    top: unit * 2.25,
2676                    right: unit * 2.25,
2677                    bottom: unit * 2.25,
2678                },
2679                96.0,
2680                unit * 2.5,
2681                8.0,
2682                280.0,
2683                520.0,
2684                unit * 6.0,
2685                Insets::all(18.0),
2686                16.0,
2687                24.0,
2688                unit * 2.0,
2689                14.0,
2690                18.0,
2691                unit * 2.5,
2692                110.0,
2693            ),
2694            ThemeDensity::Touch => (
2695                12.0,
2696                Insets {
2697                    left: unit * 3.0,
2698                    top: unit * 2.5,
2699                    right: unit * 3.0,
2700                    bottom: unit * 2.5,
2701                },
2702                112.0,
2703                unit * 3.0,
2704                10.0,
2705                320.0,
2706                600.0,
2707                unit * 8.0,
2708                Insets::all(unit * 6.0),
2709                18.0,
2710                26.0,
2711                unit * 2.5,
2712                unit * 4.5,
2713                unit * 5.0,
2714                unit * 3.0,
2715                128.0,
2716            ),
2717        };
2718
2719        let (
2720            layer_action_icon_inset,
2721            layer_lock_icon_inset,
2722            layer_visibility_stroke_width,
2723            layer_visibility_slash_stroke_width,
2724            layer_thumbnail_inset,
2725            layer_thumbnail_radius,
2726            layer_thumbnail_disabled_opacity,
2727            layer_thumbnail_disabled_border_opacity,
2728        ) = match density {
2729            ThemeDensity::Compact => (4.5, 3.5, 1.25, 1.45, 1.5, radius.md, 0.34, 0.52),
2730            ThemeDensity::Comfortable => (5.0, 4.0, 1.4, 1.6, 2.0, radius.md, 0.36, 0.55),
2731            ThemeDensity::Touch => (7.0, 6.0, 1.8, 2.0, 3.0, radius.lg, 0.40, 0.60),
2732        };
2733
2734        let (
2735            data_scroll_thumb_width,
2736            data_scroll_thumb_inset,
2737            data_scroll_thumb_radius,
2738            data_scroll_thumb_min_length,
2739            data_scroll_thumb_opacity,
2740            table_header_separator_inset,
2741            table_separator_width,
2742            table_row_border_opacity,
2743        ) = match density {
2744            ThemeDensity::Compact => (3.0, 5.0, radius.sm, 24.0, 0.68, 3.0, 1.0, 0.50),
2745            ThemeDensity::Comfortable => (4.0, 6.0, radius.sm, 28.0, 0.75, 4.0, 1.0, 0.55),
2746            ThemeDensity::Touch => (6.0, 8.0, radius.md, 44.0, 0.78, 8.0, 1.5, 0.60),
2747        };
2748
2749        let (
2750            toolbar_extent,
2751            toolbar_padding,
2752            toolbar_spacing,
2753            command_group_padding,
2754            command_group_spacing,
2755            command_group_radius,
2756            tool_palette_item_size,
2757            tool_palette_icon_size,
2758            preset_strip_item_height,
2759            preset_strip_item_min_width,
2760            preset_strip_item_padding,
2761            preset_strip_gap,
2762            preset_strip_label_padding,
2763        ) = match density {
2764            ThemeDensity::Compact => (
2765                40.0,
2766                Insets::all(unit * 1.5),
2767                unit * 1.5,
2768                Insets::all(unit * 0.25),
2769                unit * 0.5,
2770                radius.md,
2771                30.0,
2772                16.0,
2773                24.0,
2774                36.0,
2775                Insets {
2776                    left: unit * 2.0,
2777                    top: unit,
2778                    right: unit * 2.0,
2779                    bottom: unit,
2780                },
2781                unit,
2782                Insets::all(unit * 0.75),
2783            ),
2784            ThemeDensity::Comfortable => (
2785                52.0,
2786                Insets::all(unit * 2.0),
2787                unit * 2.0,
2788                Insets::all(unit * 0.5),
2789                unit * 0.75,
2790                radius.lg,
2791                40.0,
2792                20.0,
2793                28.0,
2794                44.0,
2795                Insets {
2796                    left: unit * 3.0,
2797                    top: unit,
2798                    right: unit * 3.0,
2799                    bottom: unit,
2800                },
2801                unit * 1.5,
2802                Insets::all(unit),
2803            ),
2804            ThemeDensity::Touch => (
2805                56.0,
2806                Insets::all(unit * 2.25),
2807                unit * 2.25,
2808                Insets::all(unit * 0.75),
2809                unit * 0.875,
2810                radius.xl,
2811                44.0,
2812                22.0,
2813                36.0,
2814                50.0,
2815                Insets {
2816                    left: unit * 3.5,
2817                    top: unit * 1.5,
2818                    right: unit * 3.5,
2819                    bottom: unit * 1.5,
2820                },
2821                unit * 1.75,
2822                Insets::all(unit * 1.5),
2823            ),
2824        };
2825
2826        let (
2827            property_row_label_width,
2828            property_row_inline_gap,
2829            property_row_stacked_gap,
2830            form_row_label_width,
2831            form_row_control_width,
2832            form_row_gap,
2833            field_group_spacing,
2834            form_section_padding,
2835            form_section_body_gap,
2836            form_section_header_gap,
2837            form_section_description_gap,
2838            form_section_max_width,
2839            form_section_radius,
2840            panel_section_gap,
2841            panel_section_action_gap,
2842            panel_section_disclosure_size,
2843            dock_panel_header_height,
2844            dock_panel_padding,
2845        ) = match density {
2846            ThemeDensity::Compact => (
2847                96.0,
2848                unit * 1.5,
2849                unit,
2850                112.0,
2851                300.0,
2852                unit * 2.0,
2853                unit * 1.5,
2854                Insets {
2855                    left: unit * 2.5,
2856                    top: unit * 2.0,
2857                    right: unit * 2.5,
2858                    bottom: unit * 2.5,
2859                },
2860                unit * 2.0,
2861                unit * 2.0,
2862                unit * 0.5,
2863                600.0,
2864                radius.md,
2865                unit * 1.5,
2866                unit,
2867                14.0,
2868                28.0,
2869                Insets {
2870                    left: unit * 2.0,
2871                    top: unit * 1.5,
2872                    right: unit * 2.0,
2873                    bottom: unit * 1.5,
2874                },
2875            ),
2876            ThemeDensity::Comfortable => (
2877                112.0,
2878                unit * 2.0,
2879                unit * 1.5,
2880                128.0,
2881                340.0,
2882                unit * 3.0,
2883                unit * 2.0,
2884                Insets {
2885                    left: 14.0,
2886                    top: unit * 3.0,
2887                    right: 14.0,
2888                    bottom: 14.0,
2889                },
2890                unit * 3.0,
2891                unit * 2.5,
2892                unit * 0.75,
2893                640.0,
2894                radius.lg,
2895                unit * 2.0,
2896                unit * 1.5,
2897                16.0,
2898                34.0,
2899                Insets {
2900                    left: unit * 2.5,
2901                    top: unit * 2.0,
2902                    right: unit * 2.5,
2903                    bottom: unit * 2.0,
2904                },
2905            ),
2906            ThemeDensity::Touch => (
2907                136.0,
2908                unit * 3.0,
2909                unit * 2.0,
2910                144.0,
2911                380.0,
2912                unit * 4.0,
2913                unit * 3.0,
2914                Insets {
2915                    left: unit * 4.5,
2916                    top: unit * 4.0,
2917                    right: unit * 4.5,
2918                    bottom: unit * 4.5,
2919                },
2920                unit * 4.0,
2921                unit * 3.0,
2922                unit,
2923                720.0,
2924                radius.xl,
2925                unit * 3.0,
2926                unit * 2.0,
2927                20.0,
2928                44.0,
2929                Insets {
2930                    left: unit * 3.5,
2931                    top: unit * 3.0,
2932                    right: unit * 3.5,
2933                    bottom: unit * 3.0,
2934                },
2935            ),
2936        };
2937
2938        let (
2939            image_corner_radius,
2940            color_swatch_width,
2941            color_swatch_height,
2942            color_swatch_inner_inset,
2943            color_swatch_checker_size,
2944            color_palette_swatch_size,
2945            color_palette_gap,
2946            color_palette_swatch_inset,
2947            color_palette_selected_swatch_inset,
2948            color_palette_checker_size,
2949            brush_preview_min_width,
2950            brush_preview_min_height,
2951            brush_preview_padding,
2952            brush_preview_swatch_width,
2953            brush_preview_swatch_gap,
2954            brush_preview_checker_size,
2955            brush_preview_text_height,
2956            brush_preview_text_font_size,
2957            brush_preview_text_line_height,
2958            color_picker_content_inset,
2959            color_picker_panel_gap,
2960            color_picker_top_bar_height,
2961            color_picker_swatch_width,
2962            color_picker_swatch_gap,
2963            color_picker_section_gap,
2964            color_picker_wheel_size,
2965            color_picker_map_size,
2966            color_picker_row_height,
2967            color_picker_row_gap,
2968            color_picker_right_panel_width,
2969            color_picker_field_height,
2970            color_picker_field_gap,
2971            color_picker_dropdown_gap,
2972            color_picker_encoding_menu_row_height,
2973            scroll_bar_thickness,
2974            scroll_bar_min_thumb_length,
2975            split_view_divider_thickness,
2976            split_view_drag_target_thickness,
2977            floating_workspace_margin,
2978            floating_view_title_bar_height,
2979            floating_view_title_padding,
2980            floating_view_resize_handle_size,
2981            canvas_ruler_extent,
2982            canvas_ruler_major_tick,
2983            canvas_ruler_minor_tick,
2984            canvas_ruler_target_major_spacing,
2985            canvas_ruler_label_padding,
2986            canvas_ruler_label_max_width,
2987            canvas_grid_step,
2988            canvas_axis_overscan,
2989            pixel_canvas_fit_padding,
2990            pixel_canvas_grid_zoom,
2991            pixel_canvas_nearest_sampling_zoom,
2992            pixel_canvas_zoom_step,
2993        ) = match density {
2994            ThemeDensity::Compact => (
2995                radius.md,
2996                48.0,
2997                28.0,
2998                1.0,
2999                5.0,
3000                24.0,
3001                unit * 1.25,
3002                2.0,
3003                3.0,
3004                5.0,
3005                220.0,
3006                58.0,
3007                Insets::all(unit * 1.5),
3008                46.0,
3009                unit * 2.0,
3010                5.0,
3011                15.0,
3012                10.0,
3013                13.0,
3014                unit * 3.0,
3015                unit * 2.5,
3016                40.0,
3017                64.0,
3018                unit * 2.0,
3019                14.0,
3020                128.0,
3021                132.0,
3022                24.0,
3023                unit * 2.0,
3024                150.0,
3025                28.0,
3026                12.0,
3027                unit,
3028                28.0,
3029                10.0,
3030                24.0,
3031                1.0,
3032                10.0,
3033                unit * 2.0,
3034                30.0,
3035                Insets {
3036                    left: unit * 2.5,
3037                    top: unit * 1.5,
3038                    right: unit * 2.5,
3039                    bottom: unit * 1.5,
3040                },
3041                16.0,
3042                20.0,
3043                9.0,
3044                4.0,
3045                84.0,
3046                Insets {
3047                    left: unit * 0.5,
3048                    top: unit * 0.5,
3049                    right: unit * 0.5,
3050                    bottom: unit * 0.5,
3051                },
3052                48.0,
3053                32.0,
3054                72.0,
3055                20.0,
3056                6.0,
3057                1.0,
3058                1.1,
3059            ),
3060            ThemeDensity::Comfortable => (
3061                radius.lg,
3062                56.0,
3063                32.0,
3064                1.0,
3065                6.0,
3066                28.0,
3067                unit * 1.5,
3068                2.0,
3069                3.0,
3070                5.0,
3071                260.0,
3072                70.0,
3073                Insets::all(unit * 2.0),
3074                54.0,
3075                unit * 2.5,
3076                6.0,
3077                16.0,
3078                11.0,
3079                14.0,
3080                14.0,
3081                14.0,
3082                52.0,
3083                96.0,
3084                unit * 2.5,
3085                14.0,
3086                166.0,
3087                210.0,
3088                24.0,
3089                unit * 2.0,
3090                226.0,
3091                30.0,
3092                12.0,
3093                unit,
3094                28.0,
3095                12.0,
3096                28.0,
3097                1.0,
3098                12.0,
3099                unit * 3.0,
3100                32.0,
3101                Insets {
3102                    left: 14.0,
3103                    top: unit * 2.0,
3104                    right: 14.0,
3105                    bottom: unit * 2.0,
3106                },
3107                18.0,
3108                22.0,
3109                10.0,
3110                5.0,
3111                96.0,
3112                Insets {
3113                    left: unit * 0.75,
3114                    top: unit * 0.5,
3115                    right: unit * 0.75,
3116                    bottom: unit * 0.5,
3117                },
3118                54.0,
3119                40.0,
3120                80.0,
3121                24.0,
3122                6.0,
3123                1.0,
3124                1.1,
3125            ),
3126            ThemeDensity::Touch => (
3127                radius.xl,
3128                72.0,
3129                44.0,
3130                1.5,
3131                8.0,
3132                40.0,
3133                unit * 2.0,
3134                3.0,
3135                4.0,
3136                7.0,
3137                320.0,
3138                88.0,
3139                Insets::all(unit * 3.0),
3140                72.0,
3141                unit * 3.5,
3142                8.0,
3143                18.0,
3144                12.0,
3145                16.0,
3146                unit * 4.5,
3147                unit * 4.5,
3148                64.0,
3149                112.0,
3150                unit * 3.0,
3151                18.0,
3152                210.0,
3153                240.0,
3154                44.0,
3155                unit * 3.0,
3156                280.0,
3157                44.0,
3158                16.0,
3159                unit * 2.0,
3160                44.0,
3161                18.0,
3162                44.0,
3163                2.0,
3164                44.0,
3165                unit * 4.5,
3166                52.0,
3167                Insets {
3168                    left: unit * 4.5,
3169                    top: unit * 3.5,
3170                    right: unit * 4.5,
3171                    bottom: unit * 3.5,
3172                },
3173                28.0,
3174                32.0,
3175                16.0,
3176                8.0,
3177                120.0,
3178                Insets::all(unit),
3179                72.0,
3180                48.0,
3181                96.0,
3182                32.0,
3183                6.0,
3184                1.0,
3185                1.1,
3186            ),
3187        };
3188
3189        Self {
3190            min_height,
3191            touch_target_size,
3192            button_min_width: 64.0,
3193            button_padding,
3194            checkbox_padding,
3195            checkbox_indicator_size,
3196            checkbox_gap: 6.0,
3197            icon_label_gap: 6.0,
3198            separator_thickness: 1.0,
3199            icon_size,
3200            icon_button_size,
3201            switch_track_width,
3202            switch_track_height,
3203            switch_thumb_inset,
3204            slider_min_width,
3205            slider_padding,
3206            slider_track_height,
3207            slider_thumb_size,
3208            number_input_stepper_width,
3209            text_input_min_width,
3210            text_input_padding,
3211            text_area_min_height,
3212            select_menu_max_height,
3213            select_menu_gap: 6.0,
3214            select_menu_edge_padding: 8.0,
3215            tab_height,
3216            tab_min_width,
3217            tab_gap: 6.0,
3218            tab_padding,
3219            tab_panel_padding,
3220            tab_panel_gap,
3221            menu_row_height,
3222            menu_padding,
3223            menu_item_padding,
3224            menu_shortcut_width: 108.0,
3225            popover_padding,
3226            popover_gap: unit * 2.0,
3227            popover_reveal_offset,
3228            tooltip_padding,
3229            tooltip_min_width,
3230            tooltip_gap,
3231            tooltip_reveal_offset,
3232            dialog_min_width,
3233            dialog_max_width,
3234            dialog_outer_margin,
3235            dialog_padding,
3236            dialog_title_font_size,
3237            dialog_title_line_height,
3238            dialog_description_gap,
3239            dialog_body_gap,
3240            dialog_footer_gap,
3241            dialog_action_gap,
3242            dialog_action_min_width,
3243            toolbar_extent,
3244            toolbar_padding,
3245            toolbar_spacing,
3246            command_group_padding,
3247            command_group_spacing,
3248            command_group_radius,
3249            tool_palette_item_size,
3250            tool_palette_icon_size,
3251            preset_strip_item_height,
3252            preset_strip_item_min_width,
3253            preset_strip_item_padding,
3254            preset_strip_gap,
3255            preset_strip_label_padding,
3256            action_card_min_width,
3257            action_card_min_height,
3258            action_card_padding,
3259            action_card_icon_box_size,
3260            action_card_icon_size,
3261            action_card_icon_gap,
3262            action_card_text_gap,
3263            action_card_trailing_gap,
3264            action_card_chevron_size,
3265            action_card_accent_width,
3266            action_card_accent_inset,
3267            status_bar_height,
3268            status_bar_segment_padding,
3269            status_bar_segment_min_width,
3270            status_bar_separator_inset,
3271            progress_bar_min_width,
3272            progress_bar_height,
3273            progress_bar_value_height,
3274            progress_bar_label_padding,
3275            property_row_label_width,
3276            property_row_inline_gap,
3277            property_row_stacked_gap,
3278            form_row_label_width,
3279            form_row_control_width,
3280            form_row_gap,
3281            field_group_spacing,
3282            form_section_padding,
3283            form_section_body_gap,
3284            form_section_header_gap,
3285            form_section_description_gap,
3286            form_section_max_width,
3287            form_section_radius,
3288            panel_section_gap,
3289            panel_section_action_gap,
3290            panel_section_disclosure_size,
3291            dock_panel_header_height,
3292            dock_panel_padding,
3293            data_viewport_padding,
3294            data_row_padding,
3295            data_row_icon_size,
3296            data_row_icon_gap,
3297            data_row_trailing_gap,
3298            data_scroll_thumb_width,
3299            data_scroll_thumb_inset,
3300            data_scroll_thumb_radius,
3301            data_scroll_thumb_min_length,
3302            data_scroll_thumb_opacity,
3303            list_row_height,
3304            layer_row_height,
3305            layer_action_size,
3306            layer_action_icon_inset,
3307            layer_lock_icon_inset,
3308            layer_visibility_stroke_width,
3309            layer_visibility_slash_stroke_width,
3310            layer_thumbnail_size,
3311            layer_thumbnail_inset,
3312            layer_thumbnail_radius,
3313            layer_thumbnail_disabled_opacity,
3314            layer_thumbnail_disabled_border_opacity,
3315            tree_row_height,
3316            tree_indent,
3317            tree_disclosure_size,
3318            tree_disclosure_gap,
3319            table_row_height,
3320            table_header_height,
3321            table_cell_padding,
3322            table_header_separator_inset,
3323            table_separator_width,
3324            table_row_border_opacity,
3325            breadcrumb_height,
3326            breadcrumb_item_padding,
3327            breadcrumb_gap,
3328            breadcrumb_separator_size,
3329            image_corner_radius,
3330            color_swatch_width,
3331            color_swatch_height,
3332            color_swatch_inner_inset,
3333            color_swatch_checker_size,
3334            color_palette_swatch_size,
3335            color_palette_gap,
3336            color_palette_swatch_inset,
3337            color_palette_selected_swatch_inset,
3338            color_palette_checker_size,
3339            brush_preview_min_width,
3340            brush_preview_min_height,
3341            brush_preview_padding,
3342            brush_preview_swatch_width,
3343            brush_preview_swatch_gap,
3344            brush_preview_checker_size,
3345            brush_preview_text_height,
3346            brush_preview_text_font_size,
3347            brush_preview_text_line_height,
3348            color_picker_content_inset,
3349            color_picker_panel_gap,
3350            color_picker_top_bar_height,
3351            color_picker_swatch_width,
3352            color_picker_swatch_gap,
3353            color_picker_section_gap,
3354            color_picker_wheel_size,
3355            color_picker_map_size,
3356            color_picker_row_height,
3357            color_picker_row_gap,
3358            color_picker_right_panel_width,
3359            color_picker_field_height,
3360            color_picker_field_gap,
3361            color_picker_dropdown_gap,
3362            color_picker_encoding_menu_row_height,
3363            scroll_bar_thickness,
3364            scroll_bar_min_thumb_length,
3365            split_view_divider_thickness,
3366            split_view_drag_target_thickness,
3367            floating_workspace_margin,
3368            floating_view_title_bar_height,
3369            floating_view_title_padding,
3370            floating_view_resize_handle_size,
3371            canvas_ruler_extent,
3372            canvas_ruler_major_tick,
3373            canvas_ruler_minor_tick,
3374            canvas_ruler_target_major_spacing,
3375            canvas_ruler_label_padding,
3376            canvas_ruler_label_max_width,
3377            canvas_grid_step,
3378            canvas_axis_overscan,
3379            pixel_canvas_fit_padding,
3380            pixel_canvas_grid_zoom,
3381            pixel_canvas_nearest_sampling_zoom,
3382            pixel_canvas_zoom_step,
3383            corner_radius: match density {
3384                ThemeDensity::Compact | ThemeDensity::Comfortable => radius.md,
3385                ThemeDensity::Touch => radius.lg,
3386            },
3387            indicator_corner_radius: radius.sm + 1.0,
3388            border_width: 1.0,
3389            focus_ring_width: 2.0,
3390            // Keep the 2px ring wholly clear of the control border.
3391            focus_ring_outset: 2.0,
3392            caret_width: 2.0,
3393        }
3394    }
3395}
3396
3397impl Default for ControlMetrics {
3398    fn default() -> Self {
3399        Self::from_tokens(4.0, ThemeRadii::default(), ThemeDensity::default())
3400    }
3401}
3402
3403#[derive(Debug, Clone, Copy, PartialEq)]
3404pub struct DefaultTheme {
3405    pub fonts: ThemeFontFamilies,
3406    pub colors: ThemeColors,
3407    pub density: ThemeDensity,
3408    /// Contextual authored size, when this theme copy is scoped to an interface surface.
3409    pub control_size: Option<ControlSize>,
3410    pub spacing: f32,
3411    pub breakpoints: ThemeBreakpoints,
3412    pub containers: ThemeContainers,
3413    pub text: ThemeTextScale,
3414    pub font_weights: ThemeFontWeights,
3415    pub tracking: ThemeTracking,
3416    pub leading: ThemeLeading,
3417    pub radius: ThemeRadii,
3418    pub shadows: ThemeShadows,
3419    /// Live-signal glow halos (`--sm-glow-*`): empty in Light, damped in the
3420    /// true-black theme. Paint with [`paint_theme_shadow`].
3421    pub glows: ThemeGlows,
3422    pub blur: ThemeBlurScale,
3423    pub perspective: ThemePerspective,
3424    pub aspect: ThemeAspectRatios,
3425    pub motion: ThemeMotion,
3426    pub hdr: HdrThemeTokens,
3427    pub palette: ControlPalette,
3428    pub surfaces: SurfacePalette,
3429    pub typography: ControlTypography,
3430    pub interaction: ControlStateMetrics,
3431    pub metrics: ControlMetrics,
3432}
3433
3434impl DefaultTheme {
3435    pub fn new() -> Self {
3436        Self::default()
3437    }
3438
3439    /// SUI's branded default theme.
3440    pub fn sui() -> Self {
3441        Self::light()
3442    }
3443
3444    pub fn light() -> Self {
3445        Self::from_colors(ThemeColors::light())
3446    }
3447
3448    /// A neutral light theme for serious, professional interfaces without an
3449    /// application-specific color preference.
3450    pub fn neutral() -> Self {
3451        Self::from_colors(ThemeColors::neutral())
3452    }
3453
3454    /// Dark companion to [`Self::neutral`].
3455    pub fn neutral_dark() -> Self {
3456        Self::from_colors(ThemeColors::neutral_dark())
3457    }
3458
3459    pub fn dark() -> Self {
3460        Self::from_colors(ThemeColors::dark())
3461    }
3462
3463    pub fn high_contrast() -> Self {
3464        Self::from_colors(ThemeColors::high_contrast())
3465    }
3466
3467    /// The Mesh true-black OLED theme ("Void"): borders instead of shadows,
3468    /// dimmed whites, damped glows. Alias for [`Self::high_contrast`].
3469    pub fn void() -> Self {
3470        Self::high_contrast()
3471    }
3472
3473    pub fn compact() -> Self {
3474        Self::default().with_size(ControlSize::Small)
3475    }
3476
3477    pub fn comfortable() -> Self {
3478        Self::default().with_size(ControlSize::Medium)
3479    }
3480
3481    pub fn touch() -> Self {
3482        Self::default().with_size(ControlSize::Large)
3483    }
3484
3485    pub fn from_colors(colors: ThemeColors) -> Self {
3486        let text = ThemeTextScale::default();
3487        let radius = ThemeRadii::default();
3488        let spacing = 4.0;
3489        let density = ThemeDensity::default();
3490        let hdr = HdrThemeTokens::from_colors(colors);
3491        let palette = ControlPalette::from_colors(&colors);
3492        let surfaces = SurfacePalette::from_theme_parts(&colors, &palette);
3493
3494        let mut theme = Self {
3495            fonts: ThemeFontFamilies::default(),
3496            colors,
3497            density,
3498            control_size: Some(ControlSize::Medium),
3499            spacing,
3500            breakpoints: ThemeBreakpoints::default(),
3501            containers: ThemeContainers::default(),
3502            text,
3503            font_weights: ThemeFontWeights::default(),
3504            tracking: ThemeTracking::default(),
3505            leading: ThemeLeading::default(),
3506            radius,
3507            shadows: ThemeShadows::for_colors(&colors),
3508            glows: ThemeGlows::for_colors(&colors),
3509            blur: ThemeBlurScale::default(),
3510            perspective: ThemePerspective::default(),
3511            aspect: ThemeAspectRatios::default(),
3512            motion: ThemeMotion::default(),
3513            hdr,
3514            palette,
3515            surfaces,
3516            typography: ControlTypography::for_density(&text, density),
3517            interaction: ControlStateMetrics::for_density(density),
3518            metrics: ControlMetrics::from_tokens(spacing, radius, density),
3519        };
3520        theme.sync_size_fields(ControlSize::Medium);
3521        theme
3522    }
3523
3524    pub fn with_density(mut self, density: ThemeDensity) -> Self {
3525        self.density = density;
3526        self.control_size = None;
3527        self.sync_density_fields();
3528        self
3529    }
3530
3531    /// Apply contextual interface sizing without changing the text-scale ramp.
3532    ///
3533    /// The existing density tiers provide the mature detailed metric ladders
3534    /// behind `Small`, `Medium`, and `Large`. The authored size contract then
3535    /// normalizes the primary control, row, icon, and control-text tokens while
3536    /// leaving the caller's text ramp intact.
3537    pub fn with_size(mut self, size: ControlSize) -> Self {
3538        self.density = size.legacy_density();
3539        self.control_size = Some(size);
3540        self.sync_size_fields(size);
3541        self
3542    }
3543
3544    fn sync_size_fields(&mut self, size: ControlSize) {
3545        self.interaction = ControlStateMetrics::for_density(size.legacy_density());
3546        self.metrics =
3547            ControlMetrics::from_tokens(self.spacing, self.radius, size.legacy_density());
3548        self.metrics.min_height = size.control_height();
3549        self.metrics.touch_target_size = 44.0;
3550        self.metrics.icon_size = size.icon_size();
3551        self.metrics.icon_button_size = size.control_height();
3552        self.metrics.list_row_height = size.row_height();
3553        self.metrics.tree_row_height = size.row_height();
3554        self.metrics.table_row_height = size.row_height();
3555        self.metrics.menu_row_height = size.row_height();
3556        self.typography = ControlTypography::for_size(&self.text, size);
3557    }
3558
3559    fn sync_density_fields(&mut self) {
3560        if let Some(size) = self
3561            .control_size
3562            .filter(|size| size.legacy_density() == self.density)
3563        {
3564            self.sync_size_fields(size);
3565            return;
3566        }
3567        self.control_size = None;
3568        self.typography = ControlTypography::for_density(&self.text, self.density);
3569        self.interaction = ControlStateMetrics::for_density(self.density);
3570        self.metrics = ControlMetrics::from_tokens(self.spacing, self.radius, self.density);
3571    }
3572
3573    pub fn sync_derived_fields(&mut self) {
3574        self.hdr.sync_semantic_defaults(self.colors);
3575        self.palette = ControlPalette::from_colors(&self.colors);
3576        self.surfaces = SurfacePalette::from_theme_parts(&self.colors, &self.palette);
3577        self.shadows = ThemeShadows::for_colors(&self.colors);
3578        self.glows = ThemeGlows::for_colors(&self.colors);
3579        self.sync_density_fields();
3580    }
3581
3582    pub fn text_style(&self, color: Color) -> TextStyle {
3583        self.text_style_with_font_stack(color, self.fonts.sans)
3584    }
3585
3586    /// Build a text style using the theme's serif family preference stack.
3587    pub fn serif_text_style(&self, color: Color) -> TextStyle {
3588        self.text_style_with_font_stack(color, self.fonts.serif)
3589    }
3590
3591    /// Build a text style using the theme's monospace family preference stack.
3592    pub fn mono_text_style(&self, color: Color) -> TextStyle {
3593        self.text_style_with_font_stack(color, self.fonts.mono)
3594    }
3595
3596    fn text_style_with_font_stack(&self, color: Color, fonts: ThemeFontStack) -> TextStyle {
3597        TextStyle {
3598            font_families: Some(fonts.into()),
3599            font_size: self.typography.body_font_size.max(1.0),
3600            line_height: self.typography.body_line_height.max(1.0),
3601            color,
3602            ..TextStyle::default()
3603        }
3604    }
3605
3606    pub fn semantic_tone_colors(&self, tone: SemanticTone) -> (Color, Color) {
3607        match tone {
3608            SemanticTone::Neutral => (self.palette.control, self.palette.text),
3609            SemanticTone::Accent => (self.palette.accent, self.palette.accent_text),
3610            SemanticTone::Info => (self.palette.info, self.palette.info_text),
3611            SemanticTone::Success => (self.palette.success, self.palette.success_text),
3612            SemanticTone::Warning => (self.palette.warning, self.palette.warning_text),
3613            SemanticTone::Danger => (self.palette.danger, self.palette.danger_text),
3614        }
3615    }
3616
3617    pub fn semantic_tone_color(&self, tone: SemanticTone) -> Color {
3618        self.semantic_tone_colors(tone).0
3619    }
3620
3621    pub fn semantic_tone_text_color(&self, tone: SemanticTone) -> Color {
3622        self.semantic_tone_colors(tone).1
3623    }
3624
3625    /// Professional soft pair for an explicitly semantic tone: a restrained
3626    /// wash to fill with and semantic ink that stays legible on it.
3627    /// status-hued ink that stays legible on it (`--sm-*-soft` / `--sm-*-text`).
3628    /// Use for badges and callouts; selected rows use the neutral `selection`
3629    /// role. The solid pair from
3630    /// [`Self::semantic_tone_colors`] is for filled controls.
3631    pub fn semantic_tone_soft_colors(&self, tone: SemanticTone) -> (Color, Color) {
3632        match tone {
3633            SemanticTone::Neutral => (self.palette.control_hover, self.palette.text_muted),
3634            SemanticTone::Accent => (self.palette.accent_soft, self.palette.accent_soft_text),
3635            SemanticTone::Info => (self.palette.info_soft, self.palette.info_soft_text),
3636            SemanticTone::Success => (self.palette.success_soft, self.palette.success_soft_text),
3637            SemanticTone::Warning => (self.palette.warning_soft, self.palette.warning_soft_text),
3638            SemanticTone::Danger => (self.palette.danger_soft, self.palette.danger_soft_text),
3639        }
3640    }
3641
3642    pub fn body_text_style(&self) -> TextStyle {
3643        self.text_style(self.palette.text)
3644    }
3645
3646    pub fn placeholder_text_style(&self) -> TextStyle {
3647        self.text_style(self.palette.placeholder)
3648    }
3649
3650    pub fn button_text_style(&self) -> TextStyle {
3651        self.text_style(self.palette.accent_text)
3652    }
3653}
3654
3655impl Default for DefaultTheme {
3656    fn default() -> Self {
3657        Self::sui()
3658    }
3659}
3660
3661fn mix(from: Color, to: Color, amount: f32) -> Color {
3662    let amount = amount.clamp(0.0, 1.0);
3663
3664    Color::new(
3665        from.space,
3666        from.red + (to.red - from.red) * amount,
3667        from.green + (to.green - from.green) * amount,
3668        from.blue + (to.blue - from.blue) * amount,
3669        from.alpha + (to.alpha - from.alpha) * amount,
3670    )
3671    .clamped()
3672}
3673
3674fn interactive_variant(color: Color, scheme: ThemeColorScheme, amount: f32) -> Color {
3675    match scheme {
3676        ThemeColorScheme::Light => mix(color, Color::BLACK, amount),
3677        ThemeColorScheme::Dark | ThemeColorScheme::HighContrast => mix(color, Color::WHITE, amount),
3678    }
3679}
3680
3681fn interactive_surface(color: Color, scheme: ThemeColorScheme, amount: f32) -> Color {
3682    match scheme {
3683        ThemeColorScheme::Light => mix(color, Color::BLACK, amount),
3684        ThemeColorScheme::Dark | ThemeColorScheme::HighContrast => mix(color, Color::WHITE, amount),
3685    }
3686}
3687
3688fn rgb8(red: u8, green: u8, blue: u8) -> Color {
3689    Color::rgba(
3690        f32::from(red) / 255.0,
3691        f32::from(green) / 255.0,
3692        f32::from(blue) / 255.0,
3693        1.0,
3694    )
3695}
3696
3697fn rgba8(red: u8, green: u8, blue: u8, alpha: f32) -> Color {
3698    rgb8(red, green, blue).with_alpha(alpha)
3699}
3700
3701fn is_neutral_theme(colors: &ThemeColors) -> bool {
3702    matches!(colors.name, "neutral" | "neutral-dark")
3703}
3704
3705fn shadow_layer(
3706    offset_x: f32,
3707    offset_y: f32,
3708    blur: f32,
3709    spread: f32,
3710    color: Color,
3711    inset: bool,
3712) -> ThemeShadowLayer {
3713    ThemeShadowLayer {
3714        offset_x,
3715        offset_y,
3716        blur,
3717        spread,
3718        color,
3719        inset,
3720    }
3721}
3722
3723#[cfg(test)]
3724mod tests {
3725    use super::{
3726        Color, ControlSize, ControlTypography, DefaultTheme, SemanticTone, ThemeColorScheme,
3727        ThemeColors, ThemeDensity, ThemeShadow, ThemeTextScale, rgb8, rgba8,
3728    };
3729    use crate::hdr_theme::HdrThemeMode;
3730
3731    #[test]
3732    fn default_theme_uses_body_text_scale_for_typography() {
3733        let theme = DefaultTheme::default();
3734
3735        assert_eq!(theme.typography.body_font_size, theme.text.base.size);
3736        assert_eq!(
3737            theme.typography.body_line_height,
3738            theme.text.base.line_height
3739        );
3740        assert_eq!(theme.typography.body_font_size, 15.0);
3741        assert_eq!(theme.typography.body_line_height, 22.0);
3742        assert_eq!(theme.control_size, Some(ControlSize::Medium));
3743        assert_eq!(theme.density, ThemeDensity::Comfortable);
3744        assert_eq!(theme.metrics.min_height, 32.0);
3745        assert_eq!(theme.metrics.touch_target_size, 44.0);
3746        assert_eq!(theme.metrics.icon_button_size, 32.0);
3747        assert_eq!(
3748            theme.body_text_style().font_families,
3749            Some(theme.fonts.sans.into())
3750        );
3751        assert_eq!(
3752            theme.serif_text_style(theme.palette.text).font_families,
3753            Some(theme.fonts.serif.into())
3754        );
3755        assert_eq!(
3756            theme.mono_text_style(theme.palette.text).font_families,
3757            Some(theme.fonts.mono.into())
3758        );
3759    }
3760
3761    #[test]
3762    fn density_presets_update_control_metrics_and_interactions() {
3763        let compact = DefaultTheme::compact();
3764        let comfortable = DefaultTheme::comfortable();
3765        let touch = DefaultTheme::touch();
3766
3767        assert_eq!(compact.density, ThemeDensity::Compact);
3768        assert_eq!(comfortable.density, ThemeDensity::Comfortable);
3769        assert_eq!(touch.density, ThemeDensity::Touch);
3770        assert!(compact.metrics.min_height < comfortable.metrics.min_height);
3771        assert!(comfortable.metrics.min_height < touch.metrics.min_height);
3772        assert!(compact.metrics.menu_row_height < comfortable.metrics.menu_row_height);
3773        assert!(comfortable.metrics.menu_row_height < touch.metrics.menu_row_height);
3774        assert!(compact.metrics.list_row_height < comfortable.metrics.list_row_height);
3775        assert!(comfortable.metrics.list_row_height < touch.metrics.list_row_height);
3776        assert!(compact.metrics.layer_row_height < comfortable.metrics.layer_row_height);
3777        assert!(comfortable.metrics.layer_row_height < touch.metrics.layer_row_height);
3778        assert!(
3779            compact.metrics.layer_action_icon_inset < comfortable.metrics.layer_action_icon_inset
3780        );
3781        assert!(
3782            comfortable.metrics.layer_action_icon_inset < touch.metrics.layer_action_icon_inset
3783        );
3784        assert!(
3785            compact.metrics.layer_visibility_stroke_width
3786                < comfortable.metrics.layer_visibility_stroke_width
3787        );
3788        assert!(
3789            comfortable.metrics.layer_visibility_stroke_width
3790                < touch.metrics.layer_visibility_stroke_width
3791        );
3792        assert!(compact.metrics.layer_thumbnail_inset < comfortable.metrics.layer_thumbnail_inset);
3793        assert!(comfortable.metrics.layer_thumbnail_inset < touch.metrics.layer_thumbnail_inset);
3794        assert!(
3795            compact.metrics.layer_thumbnail_radius <= comfortable.metrics.layer_thumbnail_radius
3796        );
3797        assert!(comfortable.metrics.layer_thumbnail_radius < touch.metrics.layer_thumbnail_radius);
3798        assert!(compact.metrics.table_row_height < comfortable.metrics.table_row_height);
3799        assert!(comfortable.metrics.table_row_height < touch.metrics.table_row_height);
3800        assert!(
3801            compact.metrics.data_scroll_thumb_width < comfortable.metrics.data_scroll_thumb_width
3802        );
3803        assert!(
3804            comfortable.metrics.data_scroll_thumb_width < touch.metrics.data_scroll_thumb_width
3805        );
3806        assert!(
3807            compact.metrics.data_scroll_thumb_min_length
3808                < comfortable.metrics.data_scroll_thumb_min_length
3809        );
3810        assert!(
3811            comfortable.metrics.data_scroll_thumb_min_length
3812                < touch.metrics.data_scroll_thumb_min_length
3813        );
3814        assert!(
3815            compact.metrics.table_header_separator_inset
3816                < comfortable.metrics.table_header_separator_inset
3817        );
3818        assert!(
3819            comfortable.metrics.table_header_separator_inset
3820                < touch.metrics.table_header_separator_inset
3821        );
3822        assert!(compact.metrics.breadcrumb_height < comfortable.metrics.breadcrumb_height);
3823        assert!(comfortable.metrics.breadcrumb_height < touch.metrics.breadcrumb_height);
3824        assert!(
3825            compact.metrics.action_card_min_height < comfortable.metrics.action_card_min_height
3826        );
3827        assert!(comfortable.metrics.action_card_min_height < touch.metrics.action_card_min_height);
3828        assert!(compact.metrics.status_bar_height < comfortable.metrics.status_bar_height);
3829        assert!(comfortable.metrics.status_bar_height < touch.metrics.status_bar_height);
3830        assert!(compact.metrics.progress_bar_height < comfortable.metrics.progress_bar_height);
3831        assert!(comfortable.metrics.progress_bar_height < touch.metrics.progress_bar_height);
3832        assert!(compact.metrics.tooltip_gap < comfortable.metrics.tooltip_gap);
3833        assert!(comfortable.metrics.tooltip_gap < touch.metrics.tooltip_gap);
3834        assert!(compact.metrics.tooltip_min_width < comfortable.metrics.tooltip_min_width);
3835        assert!(comfortable.metrics.tooltip_min_width < touch.metrics.tooltip_min_width);
3836        assert!(compact.metrics.popover_reveal_offset < comfortable.metrics.popover_reveal_offset);
3837        assert!(comfortable.metrics.popover_reveal_offset < touch.metrics.popover_reveal_offset);
3838        assert!(compact.metrics.dialog_max_width < comfortable.metrics.dialog_max_width);
3839        assert!(comfortable.metrics.dialog_max_width < touch.metrics.dialog_max_width);
3840        assert!(
3841            compact.metrics.dialog_action_min_width < comfortable.metrics.dialog_action_min_width
3842        );
3843        assert!(
3844            comfortable.metrics.dialog_action_min_width < touch.metrics.dialog_action_min_width
3845        );
3846        assert!(compact.metrics.toolbar_extent < comfortable.metrics.toolbar_extent);
3847        assert!(comfortable.metrics.toolbar_extent < touch.metrics.toolbar_extent);
3848        assert!(
3849            compact.metrics.tool_palette_item_size < comfortable.metrics.tool_palette_item_size
3850        );
3851        assert!(comfortable.metrics.tool_palette_item_size < touch.metrics.tool_palette_item_size);
3852        assert!(
3853            compact.metrics.preset_strip_item_height < comfortable.metrics.preset_strip_item_height
3854        );
3855        assert!(
3856            comfortable.metrics.preset_strip_item_height < touch.metrics.preset_strip_item_height
3857        );
3858        assert!(
3859            compact.metrics.property_row_label_width < comfortable.metrics.property_row_label_width
3860        );
3861        assert!(
3862            comfortable.metrics.property_row_label_width < touch.metrics.property_row_label_width
3863        );
3864        assert!(compact.metrics.form_row_gap < comfortable.metrics.form_row_gap);
3865        assert!(comfortable.metrics.form_row_gap < touch.metrics.form_row_gap);
3866        assert!(compact.metrics.field_group_spacing < comfortable.metrics.field_group_spacing);
3867        assert!(comfortable.metrics.field_group_spacing < touch.metrics.field_group_spacing);
3868        assert!(
3869            compact.metrics.form_section_max_width < comfortable.metrics.form_section_max_width
3870        );
3871        assert!(comfortable.metrics.form_section_max_width < touch.metrics.form_section_max_width);
3872        assert!(compact.metrics.panel_section_gap < comfortable.metrics.panel_section_gap);
3873        assert!(comfortable.metrics.panel_section_gap < touch.metrics.panel_section_gap);
3874        assert!(
3875            compact.metrics.dock_panel_header_height < comfortable.metrics.dock_panel_header_height
3876        );
3877        assert!(
3878            comfortable.metrics.dock_panel_header_height < touch.metrics.dock_panel_header_height
3879        );
3880        assert!(compact.metrics.tab_height < comfortable.metrics.tab_height);
3881        assert!(comfortable.metrics.tab_height < touch.metrics.tab_height);
3882        assert!(compact.metrics.scroll_bar_thickness < comfortable.metrics.scroll_bar_thickness);
3883        assert!(comfortable.metrics.scroll_bar_thickness < touch.metrics.scroll_bar_thickness);
3884        assert!(
3885            compact.metrics.scroll_bar_min_thumb_length
3886                < comfortable.metrics.scroll_bar_min_thumb_length
3887        );
3888        assert!(
3889            comfortable.metrics.scroll_bar_min_thumb_length
3890                < touch.metrics.scroll_bar_min_thumb_length
3891        );
3892        assert!(
3893            compact.metrics.split_view_drag_target_thickness
3894                < comfortable.metrics.split_view_drag_target_thickness
3895        );
3896        assert!(
3897            comfortable.metrics.split_view_drag_target_thickness
3898                < touch.metrics.split_view_drag_target_thickness
3899        );
3900        assert!(
3901            compact.metrics.floating_workspace_margin
3902                < comfortable.metrics.floating_workspace_margin
3903        );
3904        assert!(
3905            comfortable.metrics.floating_workspace_margin < touch.metrics.floating_workspace_margin
3906        );
3907        assert!(
3908            compact.metrics.floating_view_title_bar_height
3909                < comfortable.metrics.floating_view_title_bar_height
3910        );
3911        assert!(
3912            comfortable.metrics.floating_view_title_bar_height
3913                < touch.metrics.floating_view_title_bar_height
3914        );
3915        assert!(
3916            compact.metrics.floating_view_resize_handle_size
3917                < comfortable.metrics.floating_view_resize_handle_size
3918        );
3919        assert!(
3920            comfortable.metrics.floating_view_resize_handle_size
3921                < touch.metrics.floating_view_resize_handle_size
3922        );
3923        assert!(compact.metrics.canvas_ruler_extent < comfortable.metrics.canvas_ruler_extent);
3924        assert!(comfortable.metrics.canvas_ruler_extent < touch.metrics.canvas_ruler_extent);
3925        assert!(
3926            compact.metrics.canvas_ruler_label_max_width
3927                < comfortable.metrics.canvas_ruler_label_max_width
3928        );
3929        assert!(
3930            comfortable.metrics.canvas_ruler_label_max_width
3931                < touch.metrics.canvas_ruler_label_max_width
3932        );
3933        assert!(
3934            compact.metrics.canvas_ruler_target_major_spacing
3935                < comfortable.metrics.canvas_ruler_target_major_spacing
3936        );
3937        assert!(
3938            comfortable.metrics.canvas_ruler_target_major_spacing
3939                < touch.metrics.canvas_ruler_target_major_spacing
3940        );
3941        assert!(compact.metrics.canvas_grid_step < comfortable.metrics.canvas_grid_step);
3942        assert!(comfortable.metrics.canvas_grid_step < touch.metrics.canvas_grid_step);
3943        assert!(
3944            compact.metrics.pixel_canvas_fit_padding < comfortable.metrics.pixel_canvas_fit_padding
3945        );
3946        assert!(
3947            comfortable.metrics.pixel_canvas_fit_padding < touch.metrics.pixel_canvas_fit_padding
3948        );
3949        assert!(compact.metrics.icon_size < comfortable.metrics.icon_size);
3950        assert!(comfortable.metrics.icon_size < touch.metrics.icon_size);
3951        assert!(
3952            compact.interaction.tab_selected_blend < comfortable.interaction.tab_selected_blend
3953        );
3954        assert!(comfortable.interaction.tab_selected_blend < touch.interaction.tab_selected_blend);
3955        assert_eq!(compact.interaction.pressed_offset, 0.0);
3956        assert_eq!(comfortable.interaction.pressed_offset, 0.0);
3957        assert_eq!(touch.interaction.pressed_offset, 0.0);
3958    }
3959
3960    #[test]
3961    fn contextual_control_sizes_match_authored_geometry_and_typography() {
3962        assert_eq!(ControlSize::default(), ControlSize::Medium);
3963
3964        let base = DefaultTheme::default();
3965        let small = base.with_size(ControlSize::Small);
3966        let medium = base.with_size(ControlSize::Medium);
3967        let large = base.with_size(ControlSize::Large);
3968
3969        assert_eq!(small.density, ThemeDensity::Compact);
3970        assert_eq!(medium.density, ThemeDensity::Comfortable);
3971        assert_eq!(large.density, ThemeDensity::Touch);
3972        assert_eq!(small.metrics.min_height, 28.0);
3973        assert_eq!(medium.metrics.min_height, 32.0);
3974        assert_eq!(large.metrics.min_height, 40.0);
3975        assert_eq!(small.metrics.list_row_height, 30.0);
3976        assert_eq!(medium.metrics.list_row_height, 36.0);
3977        assert_eq!(large.metrics.list_row_height, 44.0);
3978        assert_eq!(small.metrics.touch_target_size, 44.0);
3979        assert_eq!(medium.metrics.touch_target_size, 44.0);
3980        assert_eq!(large.metrics.touch_target_size, 44.0);
3981        assert_eq!(small.typography.body_font_size, base.text.sm.size);
3982        assert_eq!(medium.typography.body_font_size, base.text.base.size);
3983        assert_eq!(large.typography.body_font_size, base.text.lg.size);
3984        assert_eq!(large.text, base.text);
3985    }
3986
3987    #[test]
3988    fn contextual_control_size_uses_the_callers_scaled_text_ramp() {
3989        let mut theme = DefaultTheme::default();
3990        theme.text.sm.size = 15.0;
3991        theme.text.base.size = 17.0;
3992        theme.text.lg.size = 19.0;
3993
3994        let small = theme.with_size(ControlSize::Small);
3995        let medium = theme.with_size(ControlSize::Medium);
3996        let large = theme.with_size(ControlSize::Large);
3997
3998        assert_eq!(small.typography.body_font_size, 15.0);
3999        assert_eq!(medium.typography.body_font_size, 17.0);
4000        assert_eq!(large.typography.body_font_size, 19.0);
4001    }
4002
4003    #[test]
4004    fn contextual_control_size_survives_derived_theme_refresh() {
4005        let mut theme = DefaultTheme::dark().with_size(ControlSize::Small);
4006        theme.text.sm.size = 14.5;
4007
4008        theme.sync_derived_fields();
4009
4010        assert_eq!(theme.control_size, Some(ControlSize::Small));
4011        assert_eq!(theme.metrics.min_height, 28.0);
4012        assert_eq!(theme.metrics.touch_target_size, 44.0);
4013        assert_eq!(theme.typography.body_font_size, 14.5);
4014    }
4015
4016    #[test]
4017    fn default_theme_initializes_hdr_tokens() {
4018        let theme = DefaultTheme::default();
4019
4020        assert_eq!(theme.hdr.mode, HdrThemeMode::Disabled);
4021        assert_eq!(theme.hdr.color_roles.surface.sdr, theme.colors.base_100);
4022        assert_eq!(theme.hdr.color_roles.accent.sdr, theme.colors.primary);
4023        assert_eq!(
4024            theme.hdr.color_roles.accent_text.sdr,
4025            theme.colors.primary_content
4026        );
4027    }
4028
4029    #[test]
4030    fn mesh_theme_colors_use_cyan_as_signal_accent_and_amber_as_warning() {
4031        let light = ThemeColors::light();
4032        assert_eq!(light.primary, rgb8(8, 124, 164));
4033        assert_eq!(light.accent, light.primary);
4034        assert_eq!(light.accent_content, light.primary_content);
4035        assert_eq!(light.secondary, rgb8(143, 125, 248));
4036        assert_eq!(light.warning, rgb8(220, 154, 16));
4037
4038        let dark = ThemeColors::dark();
4039        assert_eq!(dark.primary, rgb8(53, 210, 238));
4040        assert_eq!(dark.accent, dark.primary);
4041        assert_eq!(dark.accent_content, dark.primary_content);
4042        assert_eq!(dark.secondary, rgb8(143, 125, 248));
4043        assert_eq!(dark.base_300, rgb8(29, 36, 49));
4044        assert_eq!(dark.warning, rgb8(253, 176, 34));
4045
4046        let void = ThemeColors::high_contrast();
4047        assert_eq!(void.primary, rgb8(33, 199, 229));
4048        assert_eq!(void.accent, void.primary);
4049        assert_eq!(void.accent_content, void.primary_content);
4050        assert_eq!(void.base_100, Color::BLACK);
4051        assert_eq!(void.base_300, rgb8(19, 23, 34));
4052    }
4053
4054    #[test]
4055    fn professional_interaction_roles_are_neutral_and_independent_from_brand_color() {
4056        for theme in [
4057            DefaultTheme::light(),
4058            DefaultTheme::dark(),
4059            DefaultTheme::void(),
4060        ] {
4061            assert_ne!(theme.palette.border_focus, theme.palette.border_strong);
4062            assert_ne!(theme.palette.border_focus, theme.palette.focus);
4063            assert_eq!(theme.palette.caret, theme.palette.text);
4064            assert_ne!(theme.palette.focus, theme.palette.accent);
4065            assert_ne!(theme.palette.selection, theme.palette.accent_soft);
4066            assert_eq!(theme.palette.selection_border, theme.palette.accent_border);
4067            assert_ne!(theme.palette.surface_focus, theme.palette.accent_soft);
4068            assert_eq!(theme.surfaces.selected, theme.palette.selection);
4069            assert_eq!(
4070                theme.surfaces.selected_border,
4071                theme.palette.selection_border
4072            );
4073        }
4074
4075        let mut custom = ThemeColors::light();
4076        custom.name = "custom-professional";
4077        custom.primary = Color::rgba(0.92, 0.08, 0.56, 1.0);
4078        custom.primary_content = Color::WHITE;
4079        let theme = DefaultTheme::from_colors(custom);
4080        assert_eq!(theme.palette.accent, custom.primary);
4081        assert_eq!(theme.palette.caret, custom.base_content);
4082        assert_ne!(theme.palette.selection, custom.primary);
4083        assert_eq!(
4084            theme.palette.selection_border,
4085            custom
4086                .primary
4087                .with_alpha(0.35)
4088                .over(theme.palette.surface_raised)
4089        );
4090        assert_ne!(theme.palette.focus, custom.primary);
4091        assert_ne!(theme.palette.surface_focus, custom.primary);
4092    }
4093
4094    #[test]
4095    fn neutral_themes_are_achromatic_professional_presets() {
4096        let light = DefaultTheme::neutral();
4097        let colors = light.colors;
4098
4099        assert_eq!(DefaultTheme::sui(), DefaultTheme::light());
4100        assert_eq!(ThemeColors::sui(), ThemeColors::light());
4101        assert_eq!(colors.name, "neutral");
4102        assert_eq!(colors.scheme, ThemeColorScheme::Light);
4103        assert_eq!(colors.primary, rgb8(23, 23, 23));
4104        assert_eq!(colors.primary_content, Color::WHITE);
4105        assert_eq!(colors.secondary, rgb8(64, 64, 64));
4106        assert_eq!(colors.accent, colors.primary);
4107        assert_eq!(light.palette.accent, colors.primary);
4108        assert_eq!(light.palette.control, rgb8(245, 245, 245));
4109        assert_eq!(light.palette.border, rgb8(229, 229, 229));
4110        assert_eq!(light.palette.focus, rgb8(64, 64, 64));
4111        assert_eq!(light.surfaces.window_subtle, rgb8(250, 250, 250));
4112        assert_eq!(light.surfaces.checkerboard_dark, rgb8(229, 229, 229));
4113        assert_eq!(light.hdr.color_roles.accent.wide_gamut, None);
4114        assert_eq!(light.hdr.color_roles.accent.hdr, None);
4115
4116        let shadow = light
4117            .shadows
4118            .box_shadow
4119            .xs
4120            .first
4121            .expect("neutral theme should retain restrained elevation");
4122        assert_eq!(shadow.color.red, shadow.color.green);
4123        assert_eq!(shadow.color.green, shadow.color.blue);
4124
4125        for color in [
4126            colors.base_100,
4127            colors.base_200,
4128            colors.base_300,
4129            colors.base_content,
4130            colors.primary,
4131            colors.secondary,
4132            colors.accent,
4133            light.palette.focus,
4134            light.palette.selection,
4135        ] {
4136            assert_eq!(color.red, color.green);
4137            assert_eq!(color.green, color.blue);
4138        }
4139
4140        let dark = DefaultTheme::neutral_dark();
4141        let dark_colors = dark.colors;
4142        assert_eq!(dark_colors.name, "neutral-dark");
4143        assert_eq!(dark_colors.scheme, ThemeColorScheme::Dark);
4144        assert_eq!(dark_colors.base_100, rgb8(10, 10, 10));
4145        assert_eq!(dark_colors.base_content, rgb8(245, 245, 245));
4146        assert_eq!(dark_colors.primary, rgb8(245, 245, 245));
4147        assert_eq!(dark_colors.primary_content, rgb8(23, 23, 23));
4148        assert_eq!(dark.palette.surface_raised, rgb8(23, 23, 23));
4149        assert_eq!(dark.palette.control, rgb8(38, 38, 38));
4150        assert_eq!(dark.palette.control_hover, rgb8(51, 51, 51));
4151        assert_eq!(dark.palette.focus, rgb8(212, 212, 212));
4152        assert_eq!(dark.surfaces.window_subtle, rgb8(10, 10, 10));
4153        assert_eq!(dark.hdr.color_roles.accent.wide_gamut, None);
4154        assert_eq!(dark.hdr.color_roles.accent.hdr, None);
4155
4156        let glow = dark
4157            .glows
4158            .accent
4159            .first
4160            .expect("neutral dark should retain a restrained live-signal glow");
4161        assert_eq!(glow.color.red, glow.color.green);
4162        assert_eq!(glow.color.green, glow.color.blue);
4163
4164        for color in [
4165            dark_colors.base_100,
4166            dark_colors.base_200,
4167            dark_colors.base_300,
4168            dark_colors.base_content,
4169            dark_colors.primary,
4170            dark_colors.secondary,
4171            dark_colors.accent,
4172            dark.palette.focus,
4173            dark.palette.selection,
4174        ] {
4175            assert_eq!(color.red, color.green);
4176            assert_eq!(color.green, color.blue);
4177        }
4178    }
4179
4180    #[test]
4181    fn built_in_themes_use_professional_role_tokens() {
4182        // Translucent Mesh tokens are flattened onto the card surface with
4183        // CSS (gamma-space) compositing at theme build time, because the
4184        // renderer blends in linear space (which reads far heavier).
4185        let light = DefaultTheme::light();
4186        let light_surface = Color::WHITE;
4187        assert_eq!(light.palette.border, rgb8(227, 232, 239));
4188        assert_eq!(light.palette.border_strong, rgb8(205, 213, 224));
4189        assert_eq!(light.palette.text_muted, rgb8(73, 84, 107));
4190        assert_eq!(light.palette.placeholder, rgb8(104, 115, 144));
4191        assert_eq!(light.palette.control, rgb8(243, 245, 248));
4192        assert_eq!(light.palette.control_hover, rgb8(234, 238, 243));
4193        assert_eq!(light.palette.field, rgb8(248, 250, 252));
4194        assert_ne!(light.palette.field, light.palette.surface);
4195        assert_eq!(light.palette.focus, rgb8(73, 84, 107));
4196        assert_eq!(
4197            light.palette.selection,
4198            rgba8(73, 84, 107, 0.12).over(light_surface)
4199        );
4200        assert_eq!(
4201            light.palette.accent_soft,
4202            rgba8(8, 124, 164, 0.08).over(light_surface)
4203        );
4204        assert_eq!(light.palette.accent_soft.alpha, 1.0);
4205        assert_eq!(light.palette.accent_soft_text, rgb8(8, 124, 164));
4206        assert_eq!(light.palette.warning_soft_text, rgb8(154, 103, 0));
4207        assert_eq!(light.palette.danger_hover, rgb8(180, 35, 24));
4208        assert_eq!(light.surfaces.window_subtle, rgb8(247, 248, 250));
4209        assert_eq!(light.surfaces.sidebar, light.surfaces.window_subtle);
4210        assert_eq!(light.surfaces.overlay, Color::WHITE);
4211
4212        let dark = DefaultTheme::dark();
4213        let dark_surface = rgb8(18, 22, 31);
4214        assert_eq!(
4215            dark.palette.border,
4216            rgba8(151, 168, 199, 0.16).over(dark_surface)
4217        );
4218        assert_eq!(
4219            dark.palette.border_strong,
4220            rgba8(151, 168, 199, 0.27).over(dark_surface)
4221        );
4222        assert_eq!(dark.palette.text_muted, rgb8(166, 178, 200));
4223        assert_eq!(dark.palette.control, rgb8(23, 28, 39));
4224        assert_eq!(dark.palette.control_hover, rgb8(29, 36, 49));
4225        assert_eq!(dark.palette.field, rgb8(15, 19, 27));
4226        assert_eq!(dark.palette.surface_raised, dark_surface);
4227        assert_eq!(dark.palette.focus, rgb8(166, 178, 200));
4228        assert_eq!(
4229            dark.palette.selection,
4230            rgba8(166, 178, 200, 0.14).over(dark_surface)
4231        );
4232        assert_eq!(dark.palette.accent_hover, rgb8(95, 224, 246));
4233        assert_eq!(
4234            dark.palette.success_soft,
4235            rgba8(74, 222, 128, 0.12).over(dark_surface)
4236        );
4237        assert_eq!(dark.palette.success_soft_text, rgb8(74, 222, 128));
4238        assert_eq!(dark.surfaces.window_subtle, rgb8(14, 18, 26));
4239        assert_eq!(dark.surfaces.overlay, rgb8(22, 27, 38));
4240        assert_eq!(
4241            dark.surfaces.border_subtle,
4242            rgba8(151, 168, 199, 0.09).over(dark_surface)
4243        );
4244        assert_eq!(dark.surfaces.text_disabled, rgb8(81, 93, 117));
4245        assert_eq!(dark.surfaces.text_invert, rgb8(13, 18, 32));
4246
4247        let void = DefaultTheme::void();
4248        assert_eq!(
4249            void.palette.border,
4250            rgba8(158, 175, 205, 0.18).over(Color::BLACK)
4251        );
4252        assert_eq!(void.palette.field, rgb8(11, 14, 20));
4253        assert_eq!(void.palette.focus, rgb8(223, 229, 240));
4254        assert_eq!(void.surfaces.window_subtle, Color::BLACK);
4255        assert_eq!(void.surfaces.overlay, rgb8(10, 13, 19));
4256        // The scrim stays translucent: it is a true overlay above arbitrary
4257        // content, not a token that can be flattened ahead of time.
4258        assert_eq!(void.surfaces.overlay_scrim, rgba8(0, 0, 0, 0.72));
4259    }
4260
4261    #[test]
4262    fn elevation_follows_the_mesh_ladder_per_scheme() {
4263        let light = DefaultTheme::light();
4264        let dark = DefaultTheme::dark();
4265        let void = DefaultTheme::void();
4266
4267        // Light casts faint ink shadows.
4268        let light_sm = light.shadows.box_shadow.xs.first.expect("light xs shadow");
4269        assert!(light_sm.color.alpha > 0.0 && light_sm.color.alpha < 0.1);
4270        // Dark casts deeper black shadows.
4271        let dark_sm = dark.shadows.box_shadow.xs.first.expect("dark xs shadow");
4272        assert!(dark_sm.color.alpha > light_sm.color.alpha);
4273        // Void casts none: elevation is drawn with borders.
4274        assert_eq!(void.shadows.box_shadow.xs, ThemeShadow::empty());
4275        assert_eq!(void.shadows.box_shadow._2xl, ThemeShadow::empty());
4276        assert_eq!(void.shadows.drop.sm, ThemeShadow::empty());
4277
4278        // Glows: absent in Light, present in Dark, damped in Void.
4279        assert_eq!(light.glows.accent, ThemeShadow::empty());
4280        let dark_glow = dark.glows.accent.first.expect("dark accent glow");
4281        let void_glow = void.glows.accent.first.expect("void accent glow");
4282        assert!(dark_glow.blur > void_glow.blur);
4283        assert!(dark_glow.color.alpha > void_glow.color.alpha);
4284        assert_eq!(dark_glow.offset_x, 0.0);
4285        assert_eq!(dark_glow.offset_y, 0.0);
4286    }
4287
4288    #[test]
4289    fn density_tiers_match_the_mesh_contract() {
4290        let text = ThemeTextScale::default();
4291        assert_eq!(
4292            ControlTypography::for_density(&text, ThemeDensity::Compact),
4293            ControlTypography::for_size(&text, ControlSize::Small)
4294        );
4295        assert_eq!(
4296            ControlTypography::for_density(&text, ThemeDensity::Comfortable),
4297            ControlTypography::for_size(&text, ControlSize::Medium)
4298        );
4299        assert_eq!(
4300            ControlTypography::for_density(&text, ThemeDensity::Touch),
4301            ControlTypography::for_size(&text, ControlSize::Large)
4302        );
4303        let legacy_compact = DefaultTheme::default().with_density(ThemeDensity::Compact);
4304        let legacy_comfortable = DefaultTheme::default().with_density(ThemeDensity::Comfortable);
4305        let legacy_touch = DefaultTheme::default().with_density(ThemeDensity::Touch);
4306        assert_eq!(legacy_compact.typography.body_font_size, text.sm.size);
4307        assert_eq!(legacy_comfortable.typography.body_font_size, text.base.size);
4308        assert_eq!(legacy_touch.typography.body_font_size, text.lg.size);
4309
4310        let compact = DefaultTheme::compact();
4311        let comfortable = DefaultTheme::comfortable();
4312        let touch = DefaultTheme::touch();
4313
4314        // Authored control heights: 28 / 32 / 40, with a separate 44px target.
4315        assert_eq!(compact.metrics.min_height, 28.0);
4316        assert_eq!(comfortable.metrics.min_height, 32.0);
4317        assert_eq!(touch.metrics.min_height, 40.0);
4318        assert_eq!(compact.metrics.touch_target_size, 44.0);
4319        assert_eq!(comfortable.metrics.touch_target_size, 44.0);
4320        assert_eq!(touch.metrics.touch_target_size, 44.0);
4321
4322        // Rows: 30 / 36 / 44.
4323        assert_eq!(compact.metrics.list_row_height, 30.0);
4324        assert_eq!(comfortable.metrics.list_row_height, 36.0);
4325        assert_eq!(touch.metrics.list_row_height, 44.0);
4326        assert_eq!(compact.metrics.table_row_height, 30.0);
4327
4328        // Control type follows Small / Medium / Large on the shared text ramp.
4329        assert_eq!(compact.typography.body_font_size, 13.0);
4330        assert_eq!(comfortable.typography.body_font_size, 15.0);
4331        assert_eq!(touch.typography.body_font_size, 17.0);
4332
4333        // Control radius: 6 compact/comfortable, 8 touch.
4334        assert_eq!(compact.metrics.corner_radius, 6.0);
4335        assert_eq!(comfortable.metrics.corner_radius, 6.0);
4336        assert_eq!(touch.metrics.corner_radius, 8.0);
4337
4338        // The switch is a fixed 32x19 control at every density.
4339        for theme in [&compact, &comfortable, &touch] {
4340            assert_eq!(theme.metrics.switch_track_width, 32.0);
4341            assert_eq!(theme.metrics.switch_track_height, 19.0);
4342            assert_eq!(theme.metrics.checkbox_indicator_size, 15.0);
4343        }
4344    }
4345
4346    #[test]
4347    fn mesh_motion_ladder_is_70_140_220_340() {
4348        let motion = super::ThemeMotion::standard();
4349        assert_eq!(motion.duration_fast, 0.07);
4350        assert_eq!(motion.duration_normal, 0.14);
4351        assert_eq!(motion.duration_slow, 0.22);
4352        assert_eq!(motion.duration_slower, 0.34);
4353    }
4354
4355    #[test]
4356    fn light_and_dark_themes_derive_hdr_role_colors_from_semantics() {
4357        let light = DefaultTheme::light();
4358        let dark = DefaultTheme::dark();
4359
4360        assert_eq!(light.hdr.color_roles.surface.sdr, light.colors.base_100);
4361        assert_eq!(light.hdr.color_roles.text.sdr, light.colors.base_content);
4362        assert_eq!(dark.hdr.color_roles.surface.sdr, dark.colors.base_100);
4363        assert_eq!(dark.hdr.color_roles.accent.sdr, dark.colors.primary);
4364    }
4365
4366    #[test]
4367    fn sync_derived_fields_updates_semantic_palette_and_typography() {
4368        let mut theme = DefaultTheme::default();
4369        theme.colors.primary = Color::rgba(0.2, 0.3, 0.4, 1.0);
4370        theme.text.base.size = 11.0;
4371        theme.text.base.line_height = 15.0;
4372        theme.text.lg.size = 15.0;
4373        theme.text.lg.line_height = 22.0;
4374        theme.density = ThemeDensity::Touch;
4375        theme.sync_derived_fields();
4376
4377        assert_eq!(theme.palette.accent, Color::rgba(0.2, 0.3, 0.4, 1.0));
4378        assert_eq!(theme.palette.caret, theme.colors.base_content);
4379        assert_eq!(theme.surfaces.accent, theme.palette.accent);
4380        assert_eq!(theme.surfaces.window, theme.palette.surface);
4381        // Mesh tooltips are quiet floating surfaces: overlay fill, secondary ink.
4382        assert_eq!(theme.surfaces.tooltip, theme.surfaces.overlay);
4383        assert_eq!(theme.surfaces.tooltip_text, theme.palette.text_muted);
4384        assert!(theme.surfaces.overlay_scrim.alpha > 0.0);
4385        // Touch density reads at the lg body size per the Mesh density contract.
4386        assert_eq!(theme.typography.body_font_size, 15.0);
4387        assert_eq!(theme.typography.body_line_height, 22.0);
4388        assert_eq!(
4389            theme.metrics.min_height,
4390            DefaultTheme::default()
4391                .with_density(ThemeDensity::Touch)
4392                .metrics
4393                .min_height
4394        );
4395        assert_eq!(
4396            theme.interaction.pressed_offset,
4397            DefaultTheme::default()
4398                .with_density(ThemeDensity::Touch)
4399                .interaction
4400                .pressed_offset
4401        );
4402    }
4403
4404    #[test]
4405    fn control_palette_exposes_semantic_status_colors() {
4406        let theme = DefaultTheme::default();
4407
4408        assert_eq!(theme.palette.info, theme.colors.info);
4409        assert_eq!(theme.palette.info_text, theme.colors.info_content);
4410        assert_eq!(theme.palette.success, theme.colors.success);
4411        assert_eq!(theme.palette.success_text, theme.colors.success_content);
4412        assert_eq!(theme.palette.warning, theme.colors.warning);
4413        assert_eq!(theme.palette.warning_text, theme.colors.warning_content);
4414        assert_eq!(theme.palette.danger, theme.colors.error);
4415        assert_eq!(theme.palette.danger_text, theme.colors.error_content);
4416        assert_eq!(
4417            theme.semantic_tone_colors(SemanticTone::Warning),
4418            (theme.palette.warning, theme.palette.warning_text)
4419        );
4420        assert_eq!(
4421            theme.semantic_tone_color(SemanticTone::Danger),
4422            theme.palette.danger
4423        );
4424        assert_eq!(
4425            theme.semantic_tone_text_color(SemanticTone::Success),
4426            theme.palette.success_text
4427        );
4428    }
4429
4430    #[test]
4431    fn sync_derived_fields_updates_hdr_semantic_fallbacks() {
4432        let mut theme = DefaultTheme::default();
4433        let stale_wide_gamut = Color::display_p3(0.9, 0.4, 0.2, 1.0);
4434        let stale_hdr = Color::linear_display_p3(1.6, 0.5, 0.3, 1.0);
4435
4436        theme.hdr.color_roles.accent.wide_gamut = Some(stale_wide_gamut);
4437        theme.hdr.color_roles.accent.hdr = Some(stale_hdr);
4438        theme.colors = ThemeColors::dark();
4439        theme.colors.base_100 = Color::rgba(0.96, 0.97, 0.98, 1.0);
4440        theme.sync_derived_fields();
4441
4442        assert_eq!(theme.hdr.color_roles.surface.sdr, theme.colors.base_100);
4443        assert_eq!(theme.hdr.color_roles.accent.sdr, theme.colors.primary);
4444        assert_eq!(
4445            theme.hdr.color_roles.accent.wide_gamut,
4446            Some(Color::display_p3(0.13, 0.84, 0.95, 1.0))
4447        );
4448        assert_eq!(
4449            theme.hdr.color_roles.accent.hdr,
4450            Some(Color::linear_display_p3(0.16, 0.95, 1.10, 1.0))
4451        );
4452    }
4453
4454    #[test]
4455    fn dark_theme_uses_professional_dark_tokens() {
4456        let theme = DefaultTheme::dark();
4457
4458        assert_eq!(theme.colors.scheme, ThemeColorScheme::Dark);
4459        assert_eq!(theme.colors.name, "dark");
4460        assert_ne!(theme.colors.base_100, Color::BLACK);
4461        assert_eq!(theme.palette.surface, theme.colors.base_100);
4462        assert_ne!(theme.palette.surface_raised, Color::BLACK);
4463        assert_eq!(theme.palette.text, theme.colors.base_content);
4464        assert_ne!(theme.palette.text, Color::WHITE);
4465        assert_eq!(theme.palette.caret, theme.colors.base_content);
4466        assert_eq!(theme.palette.accent, theme.colors.primary);
4467        assert_eq!(theme.palette.accent_text, theme.colors.primary_content);
4468        assert_eq!(theme.surfaces.window, theme.palette.surface);
4469        assert_eq!(theme.surfaces.panel, theme.palette.surface_raised);
4470        assert_eq!(theme.surfaces.border, theme.palette.border);
4471        assert_ne!(theme.surfaces.border, Color::WHITE);
4472        assert_ne!(theme.surfaces.text_faint, theme.palette.surface);
4473    }
4474
4475    #[test]
4476    fn high_contrast_scheme_uses_true_black_oled_palette() {
4477        let theme = DefaultTheme::high_contrast();
4478
4479        assert_eq!(theme.colors.scheme, ThemeColorScheme::HighContrast);
4480        assert_eq!(theme.colors.name, "void");
4481        assert_eq!(theme.palette.surface, theme.colors.base_100);
4482        assert_eq!(theme.palette.surface, Color::BLACK);
4483        assert_eq!(theme.surfaces.window, Color::BLACK);
4484        // The Void OLED contract keeps cards true black — the border is the
4485        // card. Only input wells and hover fills lift off black.
4486        assert_eq!(theme.palette.surface_raised, Color::BLACK);
4487        assert!(theme.palette.border.alpha > 0.0);
4488        assert_ne!(theme.palette.control, Color::BLACK);
4489        assert_ne!(theme.palette.field, Color::BLACK);
4490        assert_ne!(theme.palette.text, Color::WHITE);
4491        assert_ne!(theme.palette.control_hover, Color::BLACK);
4492        assert_ne!(theme.palette.control_active, Color::BLACK);
4493        assert_ne!(theme.palette.surface_focus, Color::BLACK);
4494        assert_eq!(theme.palette.text, theme.colors.base_content);
4495        assert_eq!(
4496            theme.metrics.border_width,
4497            DefaultTheme::default().metrics.border_width
4498        );
4499        assert_eq!(
4500            theme.metrics.focus_ring_width,
4501            DefaultTheme::default().metrics.focus_ring_width
4502        );
4503
4504        let touch = DefaultTheme::high_contrast().with_density(ThemeDensity::Touch);
4505        assert_eq!(touch.density, ThemeDensity::Touch);
4506        assert!(touch.metrics.min_height > theme.metrics.min_height);
4507        assert_eq!(
4508            touch.metrics.border_width,
4509            DefaultTheme::touch().metrics.border_width
4510        );
4511        assert_eq!(
4512            touch.metrics.focus_ring_width,
4513            DefaultTheme::touch().metrics.focus_ring_width
4514        );
4515    }
4516}