Skip Navigation
EnumerationEnumeration

ThemeSettingsParser

Parses theme-settings.json files and generates CSS variable overrides.

enum ThemeSettingsParser

Overview

This parser implements the same logic as swift-docc-render’s objectToCustomProperties() function, converting nested JSON objects into CSS custom properties.

Example

Given a theme-settings.json:

{
  "theme": {
    "color": {
      "fill": { "light": "#ffffff", "dark": "#1d1d1f" }
    }
  }
}

The parser generates:

:root, body {
    --color-fill: #ffffff;
}
@supports (color: light-dark(#000, #fff)) {
    :root, body {
        --color-fill: light-dark(#ffffff, #1d1d1f);
    }
}

The properties are defined on the body element, like the colour palette of the base stylesheet, so that they replace the palette’s values. They are also defined on the root element, whose rule reads the root font size (--spacing-html-font-size) that rem values are based on. A value that differs between the light and the dark appearance becomes a light-dark() pair, which follows the colour scheme of the body (the reader’s system setting, or the scheme chosen with ColourSchemeToggle).