add theming

This commit is contained in:
mr0xb 2026-08-24 15:43:03 -04:00
commit 8639799f6d
10 changed files with 1069 additions and 287 deletions

55
internal/report/themes.go Normal file
View file

@ -0,0 +1,55 @@
package report
import "sort"
// themeAssets bundles everything a report or index page needs to render in
// one visual theme: the shared stylesheet (cards, tables, nav, badges, ...),
// report-only CSS (map + map label), and the color/URL values referenced by
// the inline Chart.js / Leaflet JS.
type themeAssets struct {
CSS string // shared :root + component stylesheet
ExtraCSS string // report-only overrides (map, map label)
ChartFont string // Chart.js font-family
ChartText string // Chart.js default text color
ChartGrid string // Chart.js default grid/border color
Chart1 string // 2xx / success series color
Chart2 string // 3xx / timeline series color
Chart2Fill string // timeline area fill (rgba)
Chart3 string // top-paths bar color / decorative accent
ChartWarn string // 4xx series color
ChartErr string // 5xx series color
MapTileURL string
MapAttribution string
MarkerColor string
}
// DefaultTheme is used when no theme is specified or an unknown name is given.
const DefaultTheme = "cyberpunk"
var themeRegistry = map[string]themeAssets{
"cyberpunk": cyberpunkTheme,
"purplerain": purplerainTheme,
"cactus": cactusTheme,
}
// ThemeNames returns the sorted list of valid --theme values.
func ThemeNames() []string {
names := make([]string, 0, len(themeRegistry))
for name := range themeRegistry {
names = append(names, name)
}
sort.Strings(names)
return names
}
// themeFor looks up a theme by name, falling back to DefaultTheme for an
// empty or unrecognized name.
func themeFor(name string) themeAssets {
if t, ok := themeRegistry[name]; ok {
return t
}
return themeRegistry[DefaultTheme]
}