util/appearance

Utility functions for inline scripts that follow the appearance of the page.

Methods

(inner) getAppearance() → {string}

Get a JavaScript expression for the appearance of the page: 'dark', 'auto', or 'light'.
Source:
See:
  • module:util/appearance.isDark
Returns:
Type:
string
The JavaScript expression.

(inner) isDark() → {string}

Get a JavaScript expression that is true when the page looks dark.

A theme can set the appearance of a page with the data-appearance attribute of <html>: dark always looks dark, auto looks dark when the system prefers a dark color scheme, and any other value, or no attribute, looks light.

Source:
Returns:
Type:
string
The JavaScript expression.
Example
const js = `var theme = ${isDark()} ? 'dark' : 'light';`;