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
- Variables
- func CSS(t Tokens) string
- func ColourNames() []string
- func Contrast(a, b RGB) float64
- func ETag(b []byte) string
- func Failures(label string, t Tokens) []string
- func Luminance(c RGB) float64
- func Names() []string
- type Choice
- type ContrastError
- type Pair
- type Preset
- type RGB
- type Tokens
Constants ¶
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).
const Default = "brass"
Default is the default preset's name.
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 ¶
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.
var Durations = []string{"dur-fast", "dur-base", "dur-slow"}
Durations are the Fixed tokens prefers-reduced-motion sets to 0ms.
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.
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.
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.
var Statuses = []string{"open", "progress", "review", "complete", "error", "warning", "running"}
Statuses are the status roles, in display order.
Functions ¶
func CSS ¶
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 ETag ¶
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).
Types ¶
type Choice ¶
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 ¶
IsDefault reports whether c draws exactly the shipped palette: the default preset and no accent of its own.
func (Choice) Normalize ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
ParseHex reads "#rrggbb" (either case). Nothing else: no short form, no alpha, no name.