Skip to content

Go based framework agnostic theming registry for web applications

License

Notifications You must be signed in to change notification settings

tj-smith47/gothememe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go • Theme • Me

Go Reference CI Go Report Card Coverage License: MIT

Buy Me A Coffee

A comprehensive Go theming package for web applications. The web counterpart to bubbletint.

Features

  • 450+ Built-in Themes - Dracula, Nord, Gruvbox, Tokyo Night, Catppuccin, and more
  • Multiple Output Formats - CSS variables, SCSS, JSON, DTCG design tokens
  • Syntax Highlighting - Compatible with Prism.js, Highlight.js, and Chroma
  • WCAG Accessibility - Built-in contrast ratio validation
  • Framework Agnostic - Works with any web framework (HTMX, React, Vue, Svelte, etc.)
  • Custom Themes - Fluent builder API for creating custom themes
  • Type Safe - Full Go type safety with comprehensive documentation

Installation

go get github.com/tj-smith47/gothememe

Quick Start

package main

import (
    "fmt"
    "github.com/tj-smith47/gothememe"
)

func main() {
    // Initialize the default registry with all themes
    gothememe.NewDefaultRegistry()

    // Generate CSS for the current theme (Dracula by default)
    css := gothememe.CSS(gothememe.DefaultCSSOptions())
    fmt.Println(css)
}

Usage Patterns

Pattern 1: Global Registry (Simplest)

For applications with a single, application-wide theme:

gothememe.NewDefaultRegistry()
gothememe.SetThemeID("dracula")

// Generate CSS
css := gothememe.CSS(gothememe.DefaultCSSOptions())

// Access theme colors directly
bg := gothememe.Background()
text := gothememe.TextPrimary()
accent := gothememe.Accent()

Pattern 2: Custom Registry (Dynamic Switching)

For applications that need runtime theme switching:

registry := gothememe.NewRegistry(
    gothememe.ThemeDracula,
    gothememe.ThemeNord,
)

// Navigate through themes
registry.NextTheme()
registry.PreviousTheme()
registry.SetThemeID("nord")

// Generate CSS for current theme
css := gothememe.GenerateCSS(registry.GetCurrentTheme(), gothememe.DefaultCSSOptions())

Pattern 3: Direct Theme Usage (Static)

For compile-time theme selection without a registry:

css := gothememe.GenerateCSS(gothememe.ThemeDracula, gothememe.DefaultCSSOptions())

Output Formats

CSS Variables

opts := gothememe.CSSOptions{
    Prefix:      "theme",
    IncludeRoot: true,
}
css := gothememe.GenerateCSS(theme, opts)

Output:

:root {
    --theme-background: #282a36;
    --theme-text-primary: #f8f8f2;
    --theme-accent: #bd93f9;
    /* ... */
}

Multi-Theme CSS

Generate CSS for all themes using data-theme attribute:

css := gothememe.AllThemesCSS(gothememe.DefaultCSSOptions())

Output:

[data-theme="dracula"] { --theme-background: #282a36; ... }
[data-theme="nord"] { --theme-background: #2e3440; ... }

Switch themes in HTML:

<html data-theme="dracula">

Design Tokens (DTCG)

Generate DTCG v1 compliant design tokens:

tokens, _ := gothememe.GenerateDesignTokens(theme, gothememe.DefaultTokenOptions())

Syntax Highlighting

Generate CSS for code syntax highlighting:

// Prism.js compatible
syntaxCSS := gothememe.GenerateSyntaxCSS(theme, gothememe.SyntaxOptions{
    Format:       gothememe.SyntaxPrism,
    UseVariables: true,
})

// Highlight.js compatible
syntaxCSS := gothememe.GenerateSyntaxCSS(theme, gothememe.SyntaxOptions{
    Format: gothememe.SyntaxHighlightJS,
})

Custom Themes

Using the Builder

theme := gothememe.NewThemeBuilder("my-theme", "My Custom Theme").
    WithBackground(gothememe.Hex("#1a1a2e")).
    WithTextPrimary(gothememe.Hex("#e4e4e4")).
    WithAccent(gothememe.Hex("#e94560")).
    WithGreen(gothememe.Hex("#22c55e")).
    WithRed(gothememe.Hex("#ef4444")).
    Build()

From Minimal Palette

Generate a complete theme from just 3 colors:

theme := gothememe.GenerateThemeFromPalette("minimal", "Minimal Theme", gothememe.Palette{
    Background: gothememe.Hex("#1a1a2e"),
    Foreground: gothememe.Hex("#e4e4e4"),
    Accent:     gothememe.Hex("#e94560"),
})

Deriving from Existing Theme

theme := gothememe.DeriveTheme(gothememe.ThemeDracula, "dracula-custom", "Dracula Custom", map[string]gothememe.Color{
    "accent": gothememe.Hex("#ff0000"),
})

Color Manipulation

color := gothememe.Hex("#e94560")

// Modify colors
lighter := color.Lighten(0.1)
darker := color.Darken(0.1)
transparent := color.WithAlpha(0.5)
opposite := color.Complement()
mixed := color.Mix(gothememe.Hex("#ffffff"), 0.5)

// Convert formats
hex := color.Hex()           // "#e94560"
rgb := color.CSSRGB()        // "rgb(233, 69, 96)"
hsl := color.CSSHSL()        // "hsl(350, 79%, 59%)"

Accessibility

Check WCAG contrast requirements:

import "github.com/tj-smith47/gothememe/pkg/contrast"

// Calculate contrast ratio
ratio := contrast.RatioHex("#ffffff", "#000000") // 21.0

// Check compliance levels
meetsAA := contrast.MeetsAAHex("#f8f8f2", "#282a36", false)   // true
meetsAAA := contrast.MeetsAAAHex("#f8f8f2", "#282a36", false) // true

// Get compliance level
level := contrast.CheckHex("#f8f8f2", "#282a36") // contrast.LevelAAA

CLI Tools

syntaxgen

Generate syntax highlighting CSS for use with Hugo, Chroma, Prism.js, or Highlight.js:

# Generate Chroma CSS for Dracula Pro (default)
syntaxgen > syntax.css

# Generate for a specific theme and format
syntaxgen -theme nord -format prism -output nord-prism.css

# List all available themes
syntaxgen -list

# Use CSS variables instead of inline colors
syntaxgen -theme catppuccin_mocha -variables > syntax.css

Flags:

  • -theme - Theme ID (default: dracula_pro)
  • -format - Output format: chroma, prism, highlightjs (default: chroma)
  • -output - Output file (default: stdout)
  • -variables - Use CSS variables instead of inline colors
  • -minify - Minify output
  • -list - List available themes

themegen

Regenerate Go theme source files from iTerm2-Color-Schemes:

themegen -source iterm2 -output themes

Available Themes

See DEFAULT_THEMES.md for a complete list of themes with previews.

Popular themes include:

  • Dracula, Dracula Plus
  • Nord
  • Gruvbox (Dark/Light)
  • Tokyo Night (variants)
  • Catppuccin (Frappe, Latte, Macchiato, Mocha)
  • One Dark
  • Solarized (Dark/Light)
  • And 100+ more...

Framework Integration

GoThemeMe works with any web framework. See docs/INTEGRATION.md for examples with:

  • Vanilla HTML/CSS
  • HTMX + templ
  • React
  • Vue
  • Svelte
  • Tailwind CSS

Contributing

Contributions are welcome! See docs/CONTRIBUTING.md for guidelines.

Disclaimer

Generated entirely by Claude Opus 4.5 over many iterations 🤖

License

MIT License - see LICENSE for details.

Credits

About

Go based framework agnostic theming registry for web applications

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

Contributors 2

  •  
  •