schema.rs

   1use anyhow::Result;
   2use gpui::{FontStyle, FontWeight, HighlightStyle, Hsla, WindowBackgroundAppearance};
   3use indexmap::IndexMap;
   4use palette::FromColor;
   5use schemars::gen::SchemaGenerator;
   6use schemars::schema::{Schema, SchemaObject};
   7use schemars::JsonSchema;
   8use serde::{Deserialize, Deserializer, Serialize};
   9use serde_json::Value;
  10use serde_repr::{Deserialize_repr, Serialize_repr};
  11
  12use crate::{StatusColorsRefinement, ThemeColorsRefinement};
  13
  14pub(crate) fn try_parse_color(color: &str) -> Result<Hsla> {
  15    let rgba = gpui::Rgba::try_from(color)?;
  16    let rgba = palette::rgb::Srgba::from_components((rgba.r, rgba.g, rgba.b, rgba.a));
  17    let hsla = palette::Hsla::from_color(rgba);
  18
  19    let hsla = gpui::hsla(
  20        hsla.hue.into_positive_degrees() / 360.,
  21        hsla.saturation,
  22        hsla.lightness,
  23        hsla.alpha,
  24    );
  25
  26    Ok(hsla)
  27}
  28
  29#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
  30#[serde(rename_all = "snake_case")]
  31pub enum AppearanceContent {
  32    Light,
  33    Dark,
  34}
  35
  36/// The background appearance of the window.
  37#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
  38#[serde(rename_all = "snake_case")]
  39pub enum WindowBackgroundContent {
  40    Opaque,
  41    Transparent,
  42    Blurred,
  43}
  44
  45impl From<WindowBackgroundContent> for WindowBackgroundAppearance {
  46    fn from(value: WindowBackgroundContent) -> Self {
  47        match value {
  48            WindowBackgroundContent::Opaque => WindowBackgroundAppearance::Opaque,
  49            WindowBackgroundContent::Transparent => WindowBackgroundAppearance::Transparent,
  50            WindowBackgroundContent::Blurred => WindowBackgroundAppearance::Blurred,
  51        }
  52    }
  53}
  54
  55/// The content of a serialized theme family.
  56#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
  57pub struct ThemeFamilyContent {
  58    pub name: String,
  59    pub author: String,
  60    pub themes: Vec<ThemeContent>,
  61}
  62
  63/// The content of a serialized theme.
  64#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
  65pub struct ThemeContent {
  66    pub name: String,
  67    pub appearance: AppearanceContent,
  68    pub style: ThemeStyleContent,
  69}
  70
  71/// The content of a serialized theme.
  72#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
  73#[serde(default)]
  74pub struct ThemeStyleContent {
  75    #[serde(default, rename = "background.appearance")]
  76    pub window_background_appearance: Option<WindowBackgroundContent>,
  77
  78    #[serde(default)]
  79    pub accents: Vec<AccentContent>,
  80
  81    #[serde(flatten, default)]
  82    pub colors: ThemeColorsContent,
  83
  84    #[serde(flatten, default)]
  85    pub status: StatusColorsContent,
  86
  87    #[serde(default)]
  88    pub players: Vec<PlayerColorContent>,
  89
  90    /// The styles for syntax nodes.
  91    #[serde(default)]
  92    pub syntax: IndexMap<String, HighlightStyleContent>,
  93}
  94
  95impl ThemeStyleContent {
  96    /// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeContent`].
  97    #[inline(always)]
  98    pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement {
  99        self.colors.theme_colors_refinement()
 100    }
 101
 102    /// Returns a [`StatusColorsRefinement`] based on the colors in the [`ThemeContent`].
 103    #[inline(always)]
 104    pub fn status_colors_refinement(&self) -> StatusColorsRefinement {
 105        self.status.status_colors_refinement()
 106    }
 107
 108    /// Returns the syntax style overrides in the [`ThemeContent`].
 109    pub fn syntax_overrides(&self) -> Vec<(String, HighlightStyle)> {
 110        self.syntax
 111            .iter()
 112            .map(|(key, style)| {
 113                (
 114                    key.clone(),
 115                    HighlightStyle {
 116                        color: style
 117                            .color
 118                            .as_ref()
 119                            .and_then(|color| try_parse_color(color).ok()),
 120                        background_color: style
 121                            .background_color
 122                            .as_ref()
 123                            .and_then(|color| try_parse_color(color).ok()),
 124                        font_style: style
 125                            .font_style
 126                            .map(|font_style| FontStyle::from(font_style)),
 127                        font_weight: style
 128                            .font_weight
 129                            .map(|font_weight| FontWeight::from(font_weight)),
 130                        ..Default::default()
 131                    },
 132                )
 133            })
 134            .collect()
 135    }
 136}
 137
 138#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
 139#[serde(default)]
 140pub struct ThemeColorsContent {
 141    /// Border color. Used for most borders, is usually a high contrast color.
 142    #[serde(rename = "border")]
 143    pub border: Option<String>,
 144
 145    /// Border color. Used for deemphasized borders, like a visual divider between two sections
 146    #[serde(rename = "border.variant")]
 147    pub border_variant: Option<String>,
 148
 149    /// Border color. Used for focused elements, like keyboard focused list item.
 150    #[serde(rename = "border.focused")]
 151    pub border_focused: Option<String>,
 152
 153    /// Border color. Used for selected elements, like an active search filter or selected checkbox.
 154    #[serde(rename = "border.selected")]
 155    pub border_selected: Option<String>,
 156
 157    /// Border color. Used for transparent borders. Used for placeholder borders when an element gains a border on state change.
 158    #[serde(rename = "border.transparent")]
 159    pub border_transparent: Option<String>,
 160
 161    /// Border color. Used for disabled elements, like a disabled input or button.
 162    #[serde(rename = "border.disabled")]
 163    pub border_disabled: Option<String>,
 164
 165    /// Border color. Used for elevated surfaces, like a context menu, popup, or dialog.
 166    #[serde(rename = "elevated_surface.background")]
 167    pub elevated_surface_background: Option<String>,
 168
 169    /// Background Color. Used for grounded surfaces like a panel or tab.
 170    #[serde(rename = "surface.background")]
 171    pub surface_background: Option<String>,
 172
 173    /// Background Color. Used for the app background and blank panels or windows.
 174    #[serde(rename = "background")]
 175    pub background: Option<String>,
 176
 177    /// Background Color. Used for the background of an element that should have a different background than the surface it's on.
 178    ///
 179    /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
 180    ///
 181    /// For an element that should have the same background as the surface it's on, use `ghost_element_background`.
 182    #[serde(rename = "element.background")]
 183    pub element_background: Option<String>,
 184
 185    /// Background Color. Used for the hover state of an element that should have a different background than the surface it's on.
 186    ///
 187    /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
 188    #[serde(rename = "element.hover")]
 189    pub element_hover: Option<String>,
 190
 191    /// Background Color. Used for the active state of an element that should have a different background than the surface it's on.
 192    ///
 193    /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd.
 194    #[serde(rename = "element.active")]
 195    pub element_active: Option<String>,
 196
 197    /// Background Color. Used for the selected state of an element that should have a different background than the surface it's on.
 198    ///
 199    /// Selected states are triggered by the element being selected (or "activated") by the user.
 200    ///
 201    /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
 202    #[serde(rename = "element.selected")]
 203    pub element_selected: Option<String>,
 204
 205    /// Background Color. Used for the disabled state of an element that should have a different background than the surface it's on.
 206    ///
 207    /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
 208    #[serde(rename = "element.disabled")]
 209    pub element_disabled: Option<String>,
 210
 211    /// Background Color. Used for the area that shows where a dragged element will be dropped.
 212    #[serde(rename = "drop_target.background")]
 213    pub drop_target_background: Option<String>,
 214
 215    /// Used for the background of a ghost element that should have the same background as the surface it's on.
 216    ///
 217    /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
 218    ///
 219    /// For an element that should have a different background than the surface it's on, use `element_background`.
 220    #[serde(rename = "ghost_element.background")]
 221    pub ghost_element_background: Option<String>,
 222
 223    /// Background Color. Used for the hover state of a ghost element that should have the same background as the surface it's on.
 224    ///
 225    /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
 226    #[serde(rename = "ghost_element.hover")]
 227    pub ghost_element_hover: Option<String>,
 228
 229    /// Background Color. Used for the active state of a ghost element that should have the same background as the surface it's on.
 230    ///
 231    /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd.
 232    #[serde(rename = "ghost_element.active")]
 233    pub ghost_element_active: Option<String>,
 234
 235    /// Background Color. Used for the selected state of a ghost element that should have the same background as the surface it's on.
 236    ///
 237    /// Selected states are triggered by the element being selected (or "activated") by the user.
 238    ///
 239    /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
 240    #[serde(rename = "ghost_element.selected")]
 241    pub ghost_element_selected: Option<String>,
 242
 243    /// Background Color. Used for the disabled state of a ghost element that should have the same background as the surface it's on.
 244    ///
 245    /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
 246    #[serde(rename = "ghost_element.disabled")]
 247    pub ghost_element_disabled: Option<String>,
 248
 249    /// Text Color. Default text color used for most text.
 250    #[serde(rename = "text")]
 251    pub text: Option<String>,
 252
 253    /// Text Color. Color of muted or deemphasized text. It is a subdued version of the standard text color.
 254    #[serde(rename = "text.muted")]
 255    pub text_muted: Option<String>,
 256
 257    /// Text Color. Color of the placeholder text typically shown in input fields to guide the user to enter valid data.
 258    #[serde(rename = "text.placeholder")]
 259    pub text_placeholder: Option<String>,
 260
 261    /// Text Color. Color used for text denoting disabled elements. Typically, the color is faded or grayed out to emphasize the disabled state.
 262    #[serde(rename = "text.disabled")]
 263    pub text_disabled: Option<String>,
 264
 265    /// Text Color. Color used for emphasis or highlighting certain text, like an active filter or a matched character in a search.
 266    #[serde(rename = "text.accent")]
 267    pub text_accent: Option<String>,
 268
 269    /// Fill Color. Used for the default fill color of an icon.
 270    #[serde(rename = "icon")]
 271    pub icon: Option<String>,
 272
 273    /// Fill Color. Used for the muted or deemphasized fill color of an icon.
 274    ///
 275    /// This might be used to show an icon in an inactive pane, or to demphasize a series of icons to give them less visual weight.
 276    #[serde(rename = "icon.muted")]
 277    pub icon_muted: Option<String>,
 278
 279    /// Fill Color. Used for the disabled fill color of an icon.
 280    ///
 281    /// Disabled states are shown when a user cannot interact with an element, like a icon button.
 282    #[serde(rename = "icon.disabled")]
 283    pub icon_disabled: Option<String>,
 284
 285    /// Fill Color. Used for the placeholder fill color of an icon.
 286    ///
 287    /// This might be used to show an icon in an input that disappears when the user enters text.
 288    #[serde(rename = "icon.placeholder")]
 289    pub icon_placeholder: Option<String>,
 290
 291    /// Fill Color. Used for the accent fill color of an icon.
 292    ///
 293    /// This might be used to show when a toggleable icon button is selected.
 294    #[serde(rename = "icon.accent")]
 295    pub icon_accent: Option<String>,
 296
 297    #[serde(rename = "status_bar.background")]
 298    pub status_bar_background: Option<String>,
 299
 300    #[serde(rename = "title_bar.background")]
 301    pub title_bar_background: Option<String>,
 302
 303    #[serde(rename = "toolbar.background")]
 304    pub toolbar_background: Option<String>,
 305
 306    #[serde(rename = "tab_bar.background")]
 307    pub tab_bar_background: Option<String>,
 308
 309    #[serde(rename = "tab.inactive_background")]
 310    pub tab_inactive_background: Option<String>,
 311
 312    #[serde(rename = "tab.active_background")]
 313    pub tab_active_background: Option<String>,
 314
 315    #[serde(rename = "search.match_background")]
 316    pub search_match_background: Option<String>,
 317
 318    #[serde(rename = "panel.background")]
 319    pub panel_background: Option<String>,
 320
 321    #[serde(rename = "panel.focused_border")]
 322    pub panel_focused_border: Option<String>,
 323
 324    #[serde(rename = "pane.focused_border")]
 325    pub pane_focused_border: Option<String>,
 326
 327    #[serde(rename = "pane_group.border")]
 328    pub pane_group_border: Option<String>,
 329
 330    /// The deprecated version of `scrollbar.thumb.background`.
 331    ///
 332    /// Don't use this field.
 333    #[serde(rename = "scrollbar_thumb.background", skip_serializing)]
 334    #[schemars(skip)]
 335    pub deprecated_scrollbar_thumb_background: Option<String>,
 336
 337    /// The color of the scrollbar thumb.
 338    #[serde(rename = "scrollbar.thumb.background")]
 339    pub scrollbar_thumb_background: Option<String>,
 340
 341    /// The color of the scrollbar thumb when hovered over.
 342    #[serde(rename = "scrollbar.thumb.hover_background")]
 343    pub scrollbar_thumb_hover_background: Option<String>,
 344
 345    /// The border color of the scrollbar thumb.
 346    #[serde(rename = "scrollbar.thumb.border")]
 347    pub scrollbar_thumb_border: Option<String>,
 348
 349    /// The background color of the scrollbar track.
 350    #[serde(rename = "scrollbar.track.background")]
 351    pub scrollbar_track_background: Option<String>,
 352
 353    /// The border color of the scrollbar track.
 354    #[serde(rename = "scrollbar.track.border")]
 355    pub scrollbar_track_border: Option<String>,
 356
 357    #[serde(rename = "editor.foreground")]
 358    pub editor_foreground: Option<String>,
 359
 360    #[serde(rename = "editor.background")]
 361    pub editor_background: Option<String>,
 362
 363    #[serde(rename = "editor.gutter.background")]
 364    pub editor_gutter_background: Option<String>,
 365
 366    #[serde(rename = "editor.subheader.background")]
 367    pub editor_subheader_background: Option<String>,
 368
 369    #[serde(rename = "editor.active_line.background")]
 370    pub editor_active_line_background: Option<String>,
 371
 372    #[serde(rename = "editor.highlighted_line.background")]
 373    pub editor_highlighted_line_background: Option<String>,
 374
 375    /// Text Color. Used for the text of the line number in the editor gutter.
 376    #[serde(rename = "editor.line_number")]
 377    pub editor_line_number: Option<String>,
 378
 379    /// Text Color. Used for the text of the line number in the editor gutter when the line is highlighted.
 380    #[serde(rename = "editor.active_line_number")]
 381    pub editor_active_line_number: Option<String>,
 382
 383    /// Text Color. Used to mark invisible characters in the editor.
 384    ///
 385    /// Example: spaces, tabs, carriage returns, etc.
 386    #[serde(rename = "editor.invisible")]
 387    pub editor_invisible: Option<String>,
 388
 389    #[serde(rename = "editor.wrap_guide")]
 390    pub editor_wrap_guide: Option<String>,
 391
 392    #[serde(rename = "editor.active_wrap_guide")]
 393    pub editor_active_wrap_guide: Option<String>,
 394
 395    #[serde(rename = "editor.indent_guide")]
 396    pub editor_indent_guide: Option<String>,
 397
 398    #[serde(rename = "editor.indent_guide_active")]
 399    pub editor_indent_guide_active: Option<String>,
 400
 401    /// Read-access of a symbol, like reading a variable.
 402    ///
 403    /// A document highlight is a range inside a text document which deserves
 404    /// special attention. Usually a document highlight is visualized by changing
 405    /// the background color of its range.
 406    #[serde(rename = "editor.document_highlight.read_background")]
 407    pub editor_document_highlight_read_background: Option<String>,
 408
 409    /// Read-access of a symbol, like reading a variable.
 410    ///
 411    /// A document highlight is a range inside a text document which deserves
 412    /// special attention. Usually a document highlight is visualized by changing
 413    /// the background color of its range.
 414    #[serde(rename = "editor.document_highlight.write_background")]
 415    pub editor_document_highlight_write_background: Option<String>,
 416
 417    /// Terminal background color.
 418    #[serde(rename = "terminal.background")]
 419    pub terminal_background: Option<String>,
 420
 421    /// Terminal foreground color.
 422    #[serde(rename = "terminal.foreground")]
 423    pub terminal_foreground: Option<String>,
 424
 425    /// Bright terminal foreground color.
 426    #[serde(rename = "terminal.bright_foreground")]
 427    pub terminal_bright_foreground: Option<String>,
 428
 429    /// Dim terminal foreground color.
 430    #[serde(rename = "terminal.dim_foreground")]
 431    pub terminal_dim_foreground: Option<String>,
 432
 433    /// Black ANSI terminal color.
 434    #[serde(rename = "terminal.ansi.black")]
 435    pub terminal_ansi_black: Option<String>,
 436
 437    /// Bright black ANSI terminal color.
 438    #[serde(rename = "terminal.ansi.bright_black")]
 439    pub terminal_ansi_bright_black: Option<String>,
 440
 441    /// Dim black ANSI terminal color.
 442    #[serde(rename = "terminal.ansi.dim_black")]
 443    pub terminal_ansi_dim_black: Option<String>,
 444
 445    /// Red ANSI terminal color.
 446    #[serde(rename = "terminal.ansi.red")]
 447    pub terminal_ansi_red: Option<String>,
 448
 449    /// Bright red ANSI terminal color.
 450    #[serde(rename = "terminal.ansi.bright_red")]
 451    pub terminal_ansi_bright_red: Option<String>,
 452
 453    /// Dim red ANSI terminal color.
 454    #[serde(rename = "terminal.ansi.dim_red")]
 455    pub terminal_ansi_dim_red: Option<String>,
 456
 457    /// Green ANSI terminal color.
 458    #[serde(rename = "terminal.ansi.green")]
 459    pub terminal_ansi_green: Option<String>,
 460
 461    /// Bright green ANSI terminal color.
 462    #[serde(rename = "terminal.ansi.bright_green")]
 463    pub terminal_ansi_bright_green: Option<String>,
 464
 465    /// Dim green ANSI terminal color.
 466    #[serde(rename = "terminal.ansi.dim_green")]
 467    pub terminal_ansi_dim_green: Option<String>,
 468
 469    /// Yellow ANSI terminal color.
 470    #[serde(rename = "terminal.ansi.yellow")]
 471    pub terminal_ansi_yellow: Option<String>,
 472
 473    /// Bright yellow ANSI terminal color.
 474    #[serde(rename = "terminal.ansi.bright_yellow")]
 475    pub terminal_ansi_bright_yellow: Option<String>,
 476
 477    /// Dim yellow ANSI terminal color.
 478    #[serde(rename = "terminal.ansi.dim_yellow")]
 479    pub terminal_ansi_dim_yellow: Option<String>,
 480
 481    /// Blue ANSI terminal color.
 482    #[serde(rename = "terminal.ansi.blue")]
 483    pub terminal_ansi_blue: Option<String>,
 484
 485    /// Bright blue ANSI terminal color.
 486    #[serde(rename = "terminal.ansi.bright_blue")]
 487    pub terminal_ansi_bright_blue: Option<String>,
 488
 489    /// Dim blue ANSI terminal color.
 490    #[serde(rename = "terminal.ansi.dim_blue")]
 491    pub terminal_ansi_dim_blue: Option<String>,
 492
 493    /// Magenta ANSI terminal color.
 494    #[serde(rename = "terminal.ansi.magenta")]
 495    pub terminal_ansi_magenta: Option<String>,
 496
 497    /// Bright magenta ANSI terminal color.
 498    #[serde(rename = "terminal.ansi.bright_magenta")]
 499    pub terminal_ansi_bright_magenta: Option<String>,
 500
 501    /// Dim magenta ANSI terminal color.
 502    #[serde(rename = "terminal.ansi.dim_magenta")]
 503    pub terminal_ansi_dim_magenta: Option<String>,
 504
 505    /// Cyan ANSI terminal color.
 506    #[serde(rename = "terminal.ansi.cyan")]
 507    pub terminal_ansi_cyan: Option<String>,
 508
 509    /// Bright cyan ANSI terminal color.
 510    #[serde(rename = "terminal.ansi.bright_cyan")]
 511    pub terminal_ansi_bright_cyan: Option<String>,
 512
 513    /// Dim cyan ANSI terminal color.
 514    #[serde(rename = "terminal.ansi.dim_cyan")]
 515    pub terminal_ansi_dim_cyan: Option<String>,
 516
 517    /// White ANSI terminal color.
 518    #[serde(rename = "terminal.ansi.white")]
 519    pub terminal_ansi_white: Option<String>,
 520
 521    /// Bright white ANSI terminal color.
 522    #[serde(rename = "terminal.ansi.bright_white")]
 523    pub terminal_ansi_bright_white: Option<String>,
 524
 525    /// Dim white ANSI terminal color.
 526    #[serde(rename = "terminal.ansi.dim_white")]
 527    pub terminal_ansi_dim_white: Option<String>,
 528
 529    #[serde(rename = "link_text.hover")]
 530    pub link_text_hover: Option<String>,
 531}
 532
 533impl ThemeColorsContent {
 534    /// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeColorsContent`].
 535    pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement {
 536        let border = self
 537            .border
 538            .as_ref()
 539            .and_then(|color| try_parse_color(color).ok());
 540        ThemeColorsRefinement {
 541            border,
 542            border_variant: self
 543                .border_variant
 544                .as_ref()
 545                .and_then(|color| try_parse_color(color).ok()),
 546            border_focused: self
 547                .border_focused
 548                .as_ref()
 549                .and_then(|color| try_parse_color(color).ok()),
 550            border_selected: self
 551                .border_selected
 552                .as_ref()
 553                .and_then(|color| try_parse_color(color).ok()),
 554            border_transparent: self
 555                .border_transparent
 556                .as_ref()
 557                .and_then(|color| try_parse_color(color).ok()),
 558            border_disabled: self
 559                .border_disabled
 560                .as_ref()
 561                .and_then(|color| try_parse_color(color).ok()),
 562            elevated_surface_background: self
 563                .elevated_surface_background
 564                .as_ref()
 565                .and_then(|color| try_parse_color(color).ok()),
 566            surface_background: self
 567                .surface_background
 568                .as_ref()
 569                .and_then(|color| try_parse_color(color).ok()),
 570            background: self
 571                .background
 572                .as_ref()
 573                .and_then(|color| try_parse_color(color).ok()),
 574            element_background: self
 575                .element_background
 576                .as_ref()
 577                .and_then(|color| try_parse_color(color).ok()),
 578            element_hover: self
 579                .element_hover
 580                .as_ref()
 581                .and_then(|color| try_parse_color(color).ok()),
 582            element_active: self
 583                .element_active
 584                .as_ref()
 585                .and_then(|color| try_parse_color(color).ok()),
 586            element_selected: self
 587                .element_selected
 588                .as_ref()
 589                .and_then(|color| try_parse_color(color).ok()),
 590            element_disabled: self
 591                .element_disabled
 592                .as_ref()
 593                .and_then(|color| try_parse_color(color).ok()),
 594            drop_target_background: self
 595                .drop_target_background
 596                .as_ref()
 597                .and_then(|color| try_parse_color(color).ok()),
 598            ghost_element_background: self
 599                .ghost_element_background
 600                .as_ref()
 601                .and_then(|color| try_parse_color(color).ok()),
 602            ghost_element_hover: self
 603                .ghost_element_hover
 604                .as_ref()
 605                .and_then(|color| try_parse_color(color).ok()),
 606            ghost_element_active: self
 607                .ghost_element_active
 608                .as_ref()
 609                .and_then(|color| try_parse_color(color).ok()),
 610            ghost_element_selected: self
 611                .ghost_element_selected
 612                .as_ref()
 613                .and_then(|color| try_parse_color(color).ok()),
 614            ghost_element_disabled: self
 615                .ghost_element_disabled
 616                .as_ref()
 617                .and_then(|color| try_parse_color(color).ok()),
 618            text: self
 619                .text
 620                .as_ref()
 621                .and_then(|color| try_parse_color(color).ok()),
 622            text_muted: self
 623                .text_muted
 624                .as_ref()
 625                .and_then(|color| try_parse_color(color).ok()),
 626            text_placeholder: self
 627                .text_placeholder
 628                .as_ref()
 629                .and_then(|color| try_parse_color(color).ok()),
 630            text_disabled: self
 631                .text_disabled
 632                .as_ref()
 633                .and_then(|color| try_parse_color(color).ok()),
 634            text_accent: self
 635                .text_accent
 636                .as_ref()
 637                .and_then(|color| try_parse_color(color).ok()),
 638            icon: self
 639                .icon
 640                .as_ref()
 641                .and_then(|color| try_parse_color(color).ok()),
 642            icon_muted: self
 643                .icon_muted
 644                .as_ref()
 645                .and_then(|color| try_parse_color(color).ok()),
 646            icon_disabled: self
 647                .icon_disabled
 648                .as_ref()
 649                .and_then(|color| try_parse_color(color).ok()),
 650            icon_placeholder: self
 651                .icon_placeholder
 652                .as_ref()
 653                .and_then(|color| try_parse_color(color).ok()),
 654            icon_accent: self
 655                .icon_accent
 656                .as_ref()
 657                .and_then(|color| try_parse_color(color).ok()),
 658            status_bar_background: self
 659                .status_bar_background
 660                .as_ref()
 661                .and_then(|color| try_parse_color(color).ok()),
 662            title_bar_background: self
 663                .title_bar_background
 664                .as_ref()
 665                .and_then(|color| try_parse_color(color).ok()),
 666            toolbar_background: self
 667                .toolbar_background
 668                .as_ref()
 669                .and_then(|color| try_parse_color(color).ok()),
 670            tab_bar_background: self
 671                .tab_bar_background
 672                .as_ref()
 673                .and_then(|color| try_parse_color(color).ok()),
 674            tab_inactive_background: self
 675                .tab_inactive_background
 676                .as_ref()
 677                .and_then(|color| try_parse_color(color).ok()),
 678            tab_active_background: self
 679                .tab_active_background
 680                .as_ref()
 681                .and_then(|color| try_parse_color(color).ok()),
 682            search_match_background: self
 683                .search_match_background
 684                .as_ref()
 685                .and_then(|color| try_parse_color(color).ok()),
 686            panel_background: self
 687                .panel_background
 688                .as_ref()
 689                .and_then(|color| try_parse_color(color).ok()),
 690            panel_focused_border: self
 691                .panel_focused_border
 692                .as_ref()
 693                .and_then(|color| try_parse_color(color).ok()),
 694            pane_focused_border: self
 695                .pane_focused_border
 696                .as_ref()
 697                .and_then(|color| try_parse_color(color).ok()),
 698            pane_group_border: self
 699                .pane_group_border
 700                .as_ref()
 701                .and_then(|color| try_parse_color(color).ok())
 702                .or(border),
 703            scrollbar_thumb_background: self
 704                .scrollbar_thumb_background
 705                .as_ref()
 706                .and_then(|color| try_parse_color(color).ok())
 707                .or_else(|| {
 708                    self.deprecated_scrollbar_thumb_background
 709                        .as_ref()
 710                        .and_then(|color| try_parse_color(color).ok())
 711                }),
 712            scrollbar_thumb_hover_background: self
 713                .scrollbar_thumb_hover_background
 714                .as_ref()
 715                .and_then(|color| try_parse_color(color).ok()),
 716            scrollbar_thumb_border: self
 717                .scrollbar_thumb_border
 718                .as_ref()
 719                .and_then(|color| try_parse_color(color).ok()),
 720            scrollbar_track_background: self
 721                .scrollbar_track_background
 722                .as_ref()
 723                .and_then(|color| try_parse_color(color).ok()),
 724            scrollbar_track_border: self
 725                .scrollbar_track_border
 726                .as_ref()
 727                .and_then(|color| try_parse_color(color).ok()),
 728            editor_foreground: self
 729                .editor_foreground
 730                .as_ref()
 731                .and_then(|color| try_parse_color(color).ok()),
 732            editor_background: self
 733                .editor_background
 734                .as_ref()
 735                .and_then(|color| try_parse_color(color).ok()),
 736            editor_gutter_background: self
 737                .editor_gutter_background
 738                .as_ref()
 739                .and_then(|color| try_parse_color(color).ok()),
 740            editor_subheader_background: self
 741                .editor_subheader_background
 742                .as_ref()
 743                .and_then(|color| try_parse_color(color).ok()),
 744            editor_active_line_background: self
 745                .editor_active_line_background
 746                .as_ref()
 747                .and_then(|color| try_parse_color(color).ok()),
 748            editor_highlighted_line_background: self
 749                .editor_highlighted_line_background
 750                .as_ref()
 751                .and_then(|color| try_parse_color(color).ok()),
 752            editor_line_number: self
 753                .editor_line_number
 754                .as_ref()
 755                .and_then(|color| try_parse_color(color).ok()),
 756            editor_active_line_number: self
 757                .editor_active_line_number
 758                .as_ref()
 759                .and_then(|color| try_parse_color(color).ok()),
 760            editor_invisible: self
 761                .editor_invisible
 762                .as_ref()
 763                .and_then(|color| try_parse_color(color).ok()),
 764            editor_wrap_guide: self
 765                .editor_wrap_guide
 766                .as_ref()
 767                .and_then(|color| try_parse_color(color).ok()),
 768            editor_active_wrap_guide: self
 769                .editor_active_wrap_guide
 770                .as_ref()
 771                .and_then(|color| try_parse_color(color).ok()),
 772            editor_indent_guide: self
 773                .editor_indent_guide
 774                .as_ref()
 775                .and_then(|color| try_parse_color(color).ok()),
 776            editor_indent_guide_active: self
 777                .editor_indent_guide_active
 778                .as_ref()
 779                .and_then(|color| try_parse_color(color).ok()),
 780            editor_document_highlight_read_background: self
 781                .editor_document_highlight_read_background
 782                .as_ref()
 783                .and_then(|color| try_parse_color(color).ok()),
 784            editor_document_highlight_write_background: self
 785                .editor_document_highlight_write_background
 786                .as_ref()
 787                .and_then(|color| try_parse_color(color).ok()),
 788            terminal_background: self
 789                .terminal_background
 790                .as_ref()
 791                .and_then(|color| try_parse_color(color).ok()),
 792            terminal_foreground: self
 793                .terminal_foreground
 794                .as_ref()
 795                .and_then(|color| try_parse_color(color).ok()),
 796            terminal_bright_foreground: self
 797                .terminal_bright_foreground
 798                .as_ref()
 799                .and_then(|color| try_parse_color(color).ok()),
 800            terminal_dim_foreground: self
 801                .terminal_dim_foreground
 802                .as_ref()
 803                .and_then(|color| try_parse_color(color).ok()),
 804            terminal_ansi_black: self
 805                .terminal_ansi_black
 806                .as_ref()
 807                .and_then(|color| try_parse_color(color).ok()),
 808            terminal_ansi_bright_black: self
 809                .terminal_ansi_bright_black
 810                .as_ref()
 811                .and_then(|color| try_parse_color(color).ok()),
 812            terminal_ansi_dim_black: self
 813                .terminal_ansi_dim_black
 814                .as_ref()
 815                .and_then(|color| try_parse_color(color).ok()),
 816            terminal_ansi_red: self
 817                .terminal_ansi_red
 818                .as_ref()
 819                .and_then(|color| try_parse_color(color).ok()),
 820            terminal_ansi_bright_red: self
 821                .terminal_ansi_bright_red
 822                .as_ref()
 823                .and_then(|color| try_parse_color(color).ok()),
 824            terminal_ansi_dim_red: self
 825                .terminal_ansi_dim_red
 826                .as_ref()
 827                .and_then(|color| try_parse_color(color).ok()),
 828            terminal_ansi_green: self
 829                .terminal_ansi_green
 830                .as_ref()
 831                .and_then(|color| try_parse_color(color).ok()),
 832            terminal_ansi_bright_green: self
 833                .terminal_ansi_bright_green
 834                .as_ref()
 835                .and_then(|color| try_parse_color(color).ok()),
 836            terminal_ansi_dim_green: self
 837                .terminal_ansi_dim_green
 838                .as_ref()
 839                .and_then(|color| try_parse_color(color).ok()),
 840            terminal_ansi_yellow: self
 841                .terminal_ansi_yellow
 842                .as_ref()
 843                .and_then(|color| try_parse_color(color).ok()),
 844            terminal_ansi_bright_yellow: self
 845                .terminal_ansi_bright_yellow
 846                .as_ref()
 847                .and_then(|color| try_parse_color(color).ok()),
 848            terminal_ansi_dim_yellow: self
 849                .terminal_ansi_dim_yellow
 850                .as_ref()
 851                .and_then(|color| try_parse_color(color).ok()),
 852            terminal_ansi_blue: self
 853                .terminal_ansi_blue
 854                .as_ref()
 855                .and_then(|color| try_parse_color(color).ok()),
 856            terminal_ansi_bright_blue: self
 857                .terminal_ansi_bright_blue
 858                .as_ref()
 859                .and_then(|color| try_parse_color(color).ok()),
 860            terminal_ansi_dim_blue: self
 861                .terminal_ansi_dim_blue
 862                .as_ref()
 863                .and_then(|color| try_parse_color(color).ok()),
 864            terminal_ansi_magenta: self
 865                .terminal_ansi_magenta
 866                .as_ref()
 867                .and_then(|color| try_parse_color(color).ok()),
 868            terminal_ansi_bright_magenta: self
 869                .terminal_ansi_bright_magenta
 870                .as_ref()
 871                .and_then(|color| try_parse_color(color).ok()),
 872            terminal_ansi_dim_magenta: self
 873                .terminal_ansi_dim_magenta
 874                .as_ref()
 875                .and_then(|color| try_parse_color(color).ok()),
 876            terminal_ansi_cyan: self
 877                .terminal_ansi_cyan
 878                .as_ref()
 879                .and_then(|color| try_parse_color(color).ok()),
 880            terminal_ansi_bright_cyan: self
 881                .terminal_ansi_bright_cyan
 882                .as_ref()
 883                .and_then(|color| try_parse_color(color).ok()),
 884            terminal_ansi_dim_cyan: self
 885                .terminal_ansi_dim_cyan
 886                .as_ref()
 887                .and_then(|color| try_parse_color(color).ok()),
 888            terminal_ansi_white: self
 889                .terminal_ansi_white
 890                .as_ref()
 891                .and_then(|color| try_parse_color(color).ok()),
 892            terminal_ansi_bright_white: self
 893                .terminal_ansi_bright_white
 894                .as_ref()
 895                .and_then(|color| try_parse_color(color).ok()),
 896            terminal_ansi_dim_white: self
 897                .terminal_ansi_dim_white
 898                .as_ref()
 899                .and_then(|color| try_parse_color(color).ok()),
 900            link_text_hover: self
 901                .link_text_hover
 902                .as_ref()
 903                .and_then(|color| try_parse_color(color).ok()),
 904        }
 905    }
 906}
 907
 908#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
 909#[serde(default)]
 910pub struct StatusColorsContent {
 911    /// Indicates some kind of conflict, like a file changed on disk while it was open, or
 912    /// merge conflicts in a Git repository.
 913    #[serde(rename = "conflict")]
 914    pub conflict: Option<String>,
 915
 916    #[serde(rename = "conflict.background")]
 917    pub conflict_background: Option<String>,
 918
 919    #[serde(rename = "conflict.border")]
 920    pub conflict_border: Option<String>,
 921
 922    /// Indicates something new, like a new file added to a Git repository.
 923    #[serde(rename = "created")]
 924    pub created: Option<String>,
 925
 926    #[serde(rename = "created.background")]
 927    pub created_background: Option<String>,
 928
 929    #[serde(rename = "created.border")]
 930    pub created_border: Option<String>,
 931
 932    /// Indicates that something no longer exists, like a deleted file.
 933    #[serde(rename = "deleted")]
 934    pub deleted: Option<String>,
 935
 936    #[serde(rename = "deleted.background")]
 937    pub deleted_background: Option<String>,
 938
 939    #[serde(rename = "deleted.border")]
 940    pub deleted_border: Option<String>,
 941
 942    /// Indicates a system error, a failed operation or a diagnostic error.
 943    #[serde(rename = "error")]
 944    pub error: Option<String>,
 945
 946    #[serde(rename = "error.background")]
 947    pub error_background: Option<String>,
 948
 949    #[serde(rename = "error.border")]
 950    pub error_border: Option<String>,
 951
 952    /// Represents a hidden status, such as a file being hidden in a file tree.
 953    #[serde(rename = "hidden")]
 954    pub hidden: Option<String>,
 955
 956    #[serde(rename = "hidden.background")]
 957    pub hidden_background: Option<String>,
 958
 959    #[serde(rename = "hidden.border")]
 960    pub hidden_border: Option<String>,
 961
 962    /// Indicates a hint or some kind of additional information.
 963    #[serde(rename = "hint")]
 964    pub hint: Option<String>,
 965
 966    #[serde(rename = "hint.background")]
 967    pub hint_background: Option<String>,
 968
 969    #[serde(rename = "hint.border")]
 970    pub hint_border: Option<String>,
 971
 972    /// Indicates that something is deliberately ignored, such as a file or operation ignored by Git.
 973    #[serde(rename = "ignored")]
 974    pub ignored: Option<String>,
 975
 976    #[serde(rename = "ignored.background")]
 977    pub ignored_background: Option<String>,
 978
 979    #[serde(rename = "ignored.border")]
 980    pub ignored_border: Option<String>,
 981
 982    /// Represents informational status updates or messages.
 983    #[serde(rename = "info")]
 984    pub info: Option<String>,
 985
 986    #[serde(rename = "info.background")]
 987    pub info_background: Option<String>,
 988
 989    #[serde(rename = "info.border")]
 990    pub info_border: Option<String>,
 991
 992    /// Indicates a changed or altered status, like a file that has been edited.
 993    #[serde(rename = "modified")]
 994    pub modified: Option<String>,
 995
 996    #[serde(rename = "modified.background")]
 997    pub modified_background: Option<String>,
 998
 999    #[serde(rename = "modified.border")]
1000    pub modified_border: Option<String>,
1001
1002    /// Indicates something that is predicted, like automatic code completion, or generated code.
1003    #[serde(rename = "predictive")]
1004    pub predictive: Option<String>,
1005
1006    #[serde(rename = "predictive.background")]
1007    pub predictive_background: Option<String>,
1008
1009    #[serde(rename = "predictive.border")]
1010    pub predictive_border: Option<String>,
1011
1012    /// Represents a renamed status, such as a file that has been renamed.
1013    #[serde(rename = "renamed")]
1014    pub renamed: Option<String>,
1015
1016    #[serde(rename = "renamed.background")]
1017    pub renamed_background: Option<String>,
1018
1019    #[serde(rename = "renamed.border")]
1020    pub renamed_border: Option<String>,
1021
1022    /// Indicates a successful operation or task completion.
1023    #[serde(rename = "success")]
1024    pub success: Option<String>,
1025
1026    #[serde(rename = "success.background")]
1027    pub success_background: Option<String>,
1028
1029    #[serde(rename = "success.border")]
1030    pub success_border: Option<String>,
1031
1032    /// Indicates some kind of unreachable status, like a block of code that can never be reached.
1033    #[serde(rename = "unreachable")]
1034    pub unreachable: Option<String>,
1035
1036    #[serde(rename = "unreachable.background")]
1037    pub unreachable_background: Option<String>,
1038
1039    #[serde(rename = "unreachable.border")]
1040    pub unreachable_border: Option<String>,
1041
1042    /// Represents a warning status, like an operation that is about to fail.
1043    #[serde(rename = "warning")]
1044    pub warning: Option<String>,
1045
1046    #[serde(rename = "warning.background")]
1047    pub warning_background: Option<String>,
1048
1049    #[serde(rename = "warning.border")]
1050    pub warning_border: Option<String>,
1051}
1052
1053impl StatusColorsContent {
1054    /// Returns a [`StatusColorsRefinement`] based on the colors in the [`StatusColorsContent`].
1055    pub fn status_colors_refinement(&self) -> StatusColorsRefinement {
1056        StatusColorsRefinement {
1057            conflict: self
1058                .conflict
1059                .as_ref()
1060                .and_then(|color| try_parse_color(color).ok()),
1061            conflict_background: self
1062                .conflict_background
1063                .as_ref()
1064                .and_then(|color| try_parse_color(color).ok()),
1065            conflict_border: self
1066                .conflict_border
1067                .as_ref()
1068                .and_then(|color| try_parse_color(color).ok()),
1069            created: self
1070                .created
1071                .as_ref()
1072                .and_then(|color| try_parse_color(color).ok()),
1073            created_background: self
1074                .created_background
1075                .as_ref()
1076                .and_then(|color| try_parse_color(color).ok()),
1077            created_border: self
1078                .created_border
1079                .as_ref()
1080                .and_then(|color| try_parse_color(color).ok()),
1081            deleted: self
1082                .deleted
1083                .as_ref()
1084                .and_then(|color| try_parse_color(color).ok()),
1085            deleted_background: self
1086                .deleted_background
1087                .as_ref()
1088                .and_then(|color| try_parse_color(color).ok()),
1089            deleted_border: self
1090                .deleted_border
1091                .as_ref()
1092                .and_then(|color| try_parse_color(color).ok()),
1093            error: self
1094                .error
1095                .as_ref()
1096                .and_then(|color| try_parse_color(color).ok()),
1097            error_background: self
1098                .error_background
1099                .as_ref()
1100                .and_then(|color| try_parse_color(color).ok()),
1101            error_border: self
1102                .error_border
1103                .as_ref()
1104                .and_then(|color| try_parse_color(color).ok()),
1105            hidden: self
1106                .hidden
1107                .as_ref()
1108                .and_then(|color| try_parse_color(color).ok()),
1109            hidden_background: self
1110                .hidden_background
1111                .as_ref()
1112                .and_then(|color| try_parse_color(color).ok()),
1113            hidden_border: self
1114                .hidden_border
1115                .as_ref()
1116                .and_then(|color| try_parse_color(color).ok()),
1117            hint: self
1118                .hint
1119                .as_ref()
1120                .and_then(|color| try_parse_color(color).ok()),
1121            hint_background: self
1122                .hint_background
1123                .as_ref()
1124                .and_then(|color| try_parse_color(color).ok()),
1125            hint_border: self
1126                .hint_border
1127                .as_ref()
1128                .and_then(|color| try_parse_color(color).ok()),
1129            ignored: self
1130                .ignored
1131                .as_ref()
1132                .and_then(|color| try_parse_color(color).ok()),
1133            ignored_background: self
1134                .ignored_background
1135                .as_ref()
1136                .and_then(|color| try_parse_color(color).ok()),
1137            ignored_border: self
1138                .ignored_border
1139                .as_ref()
1140                .and_then(|color| try_parse_color(color).ok()),
1141            info: self
1142                .info
1143                .as_ref()
1144                .and_then(|color| try_parse_color(color).ok()),
1145            info_background: self
1146                .info_background
1147                .as_ref()
1148                .and_then(|color| try_parse_color(color).ok()),
1149            info_border: self
1150                .info_border
1151                .as_ref()
1152                .and_then(|color| try_parse_color(color).ok()),
1153            modified: self
1154                .modified
1155                .as_ref()
1156                .and_then(|color| try_parse_color(color).ok()),
1157            modified_background: self
1158                .modified_background
1159                .as_ref()
1160                .and_then(|color| try_parse_color(color).ok()),
1161            modified_border: self
1162                .modified_border
1163                .as_ref()
1164                .and_then(|color| try_parse_color(color).ok()),
1165            predictive: self
1166                .predictive
1167                .as_ref()
1168                .and_then(|color| try_parse_color(color).ok()),
1169            predictive_background: self
1170                .predictive_background
1171                .as_ref()
1172                .and_then(|color| try_parse_color(color).ok()),
1173            predictive_border: self
1174                .predictive_border
1175                .as_ref()
1176                .and_then(|color| try_parse_color(color).ok()),
1177            renamed: self
1178                .renamed
1179                .as_ref()
1180                .and_then(|color| try_parse_color(color).ok()),
1181            renamed_background: self
1182                .renamed_background
1183                .as_ref()
1184                .and_then(|color| try_parse_color(color).ok()),
1185            renamed_border: self
1186                .renamed_border
1187                .as_ref()
1188                .and_then(|color| try_parse_color(color).ok()),
1189            success: self
1190                .success
1191                .as_ref()
1192                .and_then(|color| try_parse_color(color).ok()),
1193            success_background: self
1194                .success_background
1195                .as_ref()
1196                .and_then(|color| try_parse_color(color).ok()),
1197            success_border: self
1198                .success_border
1199                .as_ref()
1200                .and_then(|color| try_parse_color(color).ok()),
1201            unreachable: self
1202                .unreachable
1203                .as_ref()
1204                .and_then(|color| try_parse_color(color).ok()),
1205            unreachable_background: self
1206                .unreachable_background
1207                .as_ref()
1208                .and_then(|color| try_parse_color(color).ok()),
1209            unreachable_border: self
1210                .unreachable_border
1211                .as_ref()
1212                .and_then(|color| try_parse_color(color).ok()),
1213            warning: self
1214                .warning
1215                .as_ref()
1216                .and_then(|color| try_parse_color(color).ok()),
1217            warning_background: self
1218                .warning_background
1219                .as_ref()
1220                .and_then(|color| try_parse_color(color).ok()),
1221            warning_border: self
1222                .warning_border
1223                .as_ref()
1224                .and_then(|color| try_parse_color(color).ok()),
1225        }
1226    }
1227}
1228
1229#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
1230pub struct AccentContent(pub Option<String>);
1231
1232#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
1233pub struct PlayerColorContent {
1234    pub cursor: Option<String>,
1235    pub background: Option<String>,
1236    pub selection: Option<String>,
1237}
1238
1239#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
1240#[serde(rename_all = "snake_case")]
1241pub enum FontStyleContent {
1242    Normal,
1243    Italic,
1244    Oblique,
1245}
1246
1247impl From<FontStyleContent> for FontStyle {
1248    fn from(value: FontStyleContent) -> Self {
1249        match value {
1250            FontStyleContent::Normal => FontStyle::Normal,
1251            FontStyleContent::Italic => FontStyle::Italic,
1252            FontStyleContent::Oblique => FontStyle::Oblique,
1253        }
1254    }
1255}
1256
1257#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)]
1258#[repr(u16)]
1259pub enum FontWeightContent {
1260    Thin = 100,
1261    ExtraLight = 200,
1262    Light = 300,
1263    Normal = 400,
1264    Medium = 500,
1265    Semibold = 600,
1266    Bold = 700,
1267    ExtraBold = 800,
1268    Black = 900,
1269}
1270
1271impl JsonSchema for FontWeightContent {
1272    fn schema_name() -> String {
1273        "FontWeightContent".to_owned()
1274    }
1275
1276    fn is_referenceable() -> bool {
1277        false
1278    }
1279
1280    fn json_schema(_: &mut SchemaGenerator) -> Schema {
1281        SchemaObject {
1282            enum_values: Some(vec![
1283                100.into(),
1284                200.into(),
1285                300.into(),
1286                400.into(),
1287                500.into(),
1288                600.into(),
1289                700.into(),
1290                800.into(),
1291                900.into(),
1292            ]),
1293            ..Default::default()
1294        }
1295        .into()
1296    }
1297}
1298
1299impl From<FontWeightContent> for FontWeight {
1300    fn from(value: FontWeightContent) -> Self {
1301        match value {
1302            FontWeightContent::Thin => FontWeight::THIN,
1303            FontWeightContent::ExtraLight => FontWeight::EXTRA_LIGHT,
1304            FontWeightContent::Light => FontWeight::LIGHT,
1305            FontWeightContent::Normal => FontWeight::NORMAL,
1306            FontWeightContent::Medium => FontWeight::MEDIUM,
1307            FontWeightContent::Semibold => FontWeight::SEMIBOLD,
1308            FontWeightContent::Bold => FontWeight::BOLD,
1309            FontWeightContent::ExtraBold => FontWeight::EXTRA_BOLD,
1310            FontWeightContent::Black => FontWeight::BLACK,
1311        }
1312    }
1313}
1314
1315#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
1316#[serde(default)]
1317pub struct HighlightStyleContent {
1318    pub color: Option<String>,
1319
1320    #[serde(deserialize_with = "treat_error_as_none")]
1321    pub background_color: Option<String>,
1322
1323    #[serde(deserialize_with = "treat_error_as_none")]
1324    pub font_style: Option<FontStyleContent>,
1325
1326    #[serde(deserialize_with = "treat_error_as_none")]
1327    pub font_weight: Option<FontWeightContent>,
1328}
1329
1330impl HighlightStyleContent {
1331    pub fn is_empty(&self) -> bool {
1332        self.color.is_none()
1333            && self.background_color.is_none()
1334            && self.font_style.is_none()
1335            && self.font_weight.is_none()
1336    }
1337}
1338
1339fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
1340where
1341    T: Deserialize<'de>,
1342    D: Deserializer<'de>,
1343{
1344    let value: Value = Deserialize::deserialize(deserializer)?;
1345    Ok(T::deserialize(value).ok())
1346}