theme

package
v0.273.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package theme is the server's THEME: muster's palette as named tokens, the presets an admin picks from, an optional accent colour of the admin's own, and the contrast table every theme must pass before it is saved (docs/ui-kit.md#the-theme).

🔴 ONE CONTRAST TABLE. Pairs is the table the palette was designed against. internal/ui's TestThemeTokensMeetWCAG checks the shipped stylesheet with it, and Choice.Validate checks a theme an admin is about to save with it: the test and the save refuse the same things because they read the same rows.

🔴 THE DEFAULT PRESET IS THE SHIPPED PALETTE. web/css/tokens.css is what app.css is built from; the default preset here must equal its dark block, token for token (internal/ui TestTheDefaultPresetIsTheShippedPalette), so a server with no theme set and a server that chose the default draw the same colours. Likewise the shape and motion tokens (Fixed) equal web/css/kit.css's own defaults (internal/uikit TestFixedTokensAreKitCSSDefaults).

Index

Constants

View Source
const (
	OnAccentDarken = 0.87
	FocusLighten   = 0.3
)

The derivation's two factors: how far the label moves toward black, and the focus ring toward white. Exported because the Account page's preview derives in the browser with these same numbers (internal/api theme.go).

View Source
const Default = "brass"

Default is the default preset's name.

View Source
const Selector = ":root:root"

Selector is the theme block's selector. `:root:root` out-ranks app.css's own `:root, .dark` palette whatever the order the two stylesheets load in, and on a plugin's page it is simply the root.

Variables

View Source
var (
	ErrUnknownPreset = errors.New("theme: there is no such preset")
	ErrAccentFormat  = errors.New("theme: an accent colour is #RRGGBB")
)

The refusals. Each is a distinct value, so a caller (and a test) can tell which guard refused.

View Source
var Durations = []string{"dur-fast", "dur-base", "dur-slow"}

Durations are the Fixed tokens prefers-reduced-motion sets to 0ms.

View Source
var Fixed = []struct{ Name, Value string }{
	{"radius-sm", ".375rem"},
	{"radius-md", ".5rem"},
	{"radius-lg", "1rem"},
	{"radius-full", "9999px"},

	{"font-sans", `ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"`},
	{"font-mono", `ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace`},
	{"dur-fast", "120ms"},
	{"dur-base", "200ms"},
	{"dur-slow", "320ms"},
	{"ease-standard", "cubic-bezier(.2, 0, 0, 1)"},
	{"ease-enter", "cubic-bezier(0, 0, 0, 1)"},
	{"ease-exit", "cubic-bezier(.3, 0, 1, 1)"},
}

Fixed are the shape, type and motion tokens: the same in every theme, in v1. Their values equal web/css/kit.css's :root defaults.

View Source
var Presets = []Preset{
	{Name: Default, Label: "Brass (muster)", Accent: base["accent"], OnAccent: ptr(base["on-accent"]), Focus: ptr(base["focus"])},
	{Name: "harbor", Label: "Harbor (blue)", Accent: RGB{110, 176, 245}},
	{Name: "verdigris", Label: "Verdigris (green)", Accent: RGB{92, 204, 158}},
	{Name: "ember", Label: "Ember (coral)", Accent: RGB{246, 140, 112}},
}

Presets is the closed list, the default first.

View Source
var Roles = []string{"bg", "s1", "s2", "s3", "line", "edge", "text", "text2", "muted", "accent", "on-accent", "focus", "danger", "on-danger"}

Roles are the theme's colour roles that are not a status.

View Source
var Statuses = []string{"open", "progress", "review", "complete", "error", "warning", "running"}

Statuses are the status roles, in display order.

Functions

func CSS

func CSS(t Tokens) string

CSS is the theme block for t: every colour token, then every Fixed token, on Selector; then the reduced-motion rule. Names are sorted in ColourNames' order, so equal themes are equal bytes.

func ColourNames

func ColourNames() []string

ColourNames is every colour token of a theme, without the --mu- prefix: the 14 roles, then each status's -fg and -bg (28).

func Contrast

func Contrast(a, b RGB) float64

Contrast is the WCAG 2.x contrast ratio of a and b.

func ETag

func ETag(b []byte) string

ETag is the first 16 hex digits of a sha256 over b: the one spelling of an ETag for a kit file (and of the theme's own, over its CSS).

func Failures

func Failures(label string, t Tokens) []string

Failures checks every Pair against t and returns one line per failure (or per missing token), each starting with label.

func Luminance

func Luminance(c RGB) float64

Luminance is the WCAG 2.x relative luminance.

func Names

func Names() []string

Names lists the preset names, sorted (for an error message).

Types

type Choice

type Choice struct {
	Preset string
	Accent string
}

Choice is what an admin saves: a preset, and optionally an accent of their own ("#rrggbb", lower case; "" for the preset's own). The zero value is the default theme.

func (Choice) IsDefault

func (c Choice) IsDefault() bool

IsDefault reports whether c draws exactly the shipped palette: the default preset and no accent of its own.

func (Choice) Normalize

func (c Choice) Normalize() (Choice, error)

Normalize is c with the default preset spelled out and the accent in lower case, or an error for an unknown preset or a malformed accent.

func (Choice) Resolve

func (c Choice) Resolve() (Tokens, error)

Resolve is every colour token c draws. It does not check contrast (Validate does).

func (Choice) Validate

func (c Choice) Validate() (Tokens, error)

Validate is Resolve, refused with a *ContrastError when any Pair fails.

type ContrastError

type ContrastError struct{ Failures []string }

ContrastError refuses a theme that fails the contrast table. Failures names each failing pair.

func (*ContrastError) Error

func (e *ContrastError) Error() string

type Pair

type Pair struct {
	FG, BG string
	Min    float64
}

Pair is one row of the contrast table: fg on bg needs at least Min.

func Pairs

func Pairs() []Pair

Pairs is the table the palette was designed against (WCAG 2.2 AA): text roles on every surface at 4.5, the accent as link text, the two filled- button labels, the focus ring and the control edge at 3 (1.4.11 / 2.4.13), and every status's chip label at 4.5 and glyph on the card at 3.

⚠ `line` IS ABSENT ON PURPOSE: it is a decorative divider between regions, which 1.4.11 does not cover. A control's boundary is `edge`, which is here.

type Preset

type Preset struct {
	Name, Label string
	Accent      RGB
	// OnAccent and Focus are set for the default preset, whose values are the
	// shipped palette's; a zero value is derived from Accent (Derive).
	OnAccent, Focus *RGB
}

Preset is one of the themes an admin picks from. A preset changes the accent and the two colours drawn from it; the surfaces, the text and the statuses stay muster's (docs/ui-kit.md#the-theme says why).

func PresetNamed

func PresetNamed(name string) (Preset, bool)

PresetNamed is the preset called name, and whether there is one.

type RGB

type RGB struct{ R, G, B uint8 }

RGB is one colour.

func Derive

func Derive(accent RGB) (onAccent, focus RGB)

Derive is the two colours an accent brings with it: on-accent, a label on the accent fill (the accent darkened to near black, as brass's own label is), and focus, the ring (the accent lightened toward white).

⚠ NO WHITE LABEL, ON PURPOSE. An accent that can be saved reads at 4.5:1 on every surface, so it is light (relative luminance about 0.29 or more); white on it is then at most about 3:1 and the near-black label at least about 6:1. A "white if it reads better" branch could never be taken by a theme that passes Validate — a mutation test showed it dead — so it is not written.

func ParseHex

func ParseHex(s string) (RGB, error)

ParseHex reads "#rrggbb" (either case). Nothing else: no short form, no alpha, no name.

func (RGB) Channels

func (c RGB) Channels() string

Channels is the custom property value: "R G B" (so rgb(var(--x) / a) works).

func (RGB) Hex

func (c RGB) Hex() string

Hex is "#RRGGBB", upper case.

type Tokens

type Tokens map[string]RGB

Tokens is one theme's colours, keyed by name without the --mu- prefix.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL