aesthetic

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package aesthetic provides design token management for markata-go themes.

Overview

Aesthetics define non-color design tokens including:

  • Radius tokens: Border radius values for different UI elements
  • Spacing tokens: Spacing scale for consistent layout
  • Border tokens: Border width and style definitions
  • Shadow tokens: Box shadow definitions for elevation
  • Typography tokens: Font families, sizes, and line heights

Aesthetic Presets

Five built-in aesthetic presets are available:

  • brutal: Sharp corners, tight spacing, bold borders
  • precision: Subtle corners, compact spacing, clean lines
  • balanced: Comfortable rounding, normal spacing (default)
  • elevated: Generous rounding, layered shadows
  • minimal: Maximum whitespace, flat design

Aesthetic Discovery

Aesthetics are discovered in order:

  1. Project local: ./aesthetics/{name}.toml
  2. User config: ~/.config/markata-go/aesthetics/{name}.toml
  3. Built-in: embedded aesthetics

Usage

// Load an aesthetic by name
a, err := aesthetic.LoadAesthetic("modern")
if err != nil {
    log.Fatal(err)
}

// Generate CSS custom properties
css := a.GenerateCSS()

// List available aesthetics
names := aesthetic.ListAesthetics()

Relationship to Palettes

Aesthetics complement palettes: palettes define colors, aesthetics define everything else. Together they form a complete theme system.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAestheticNotFound is returned when an aesthetic cannot be found.
	ErrAestheticNotFound = errors.New("aesthetic not found")

	// ErrInvalidAesthetic is returned when an aesthetic file is malformed.
	ErrInvalidAesthetic = errors.New("invalid aesthetic")
)

Common errors returned by the aesthetic package.

View Source
var DefaultLoader = NewLoader()

DefaultLoader is the default aesthetic loader instance.

Functions

func BuiltinNames

func BuiltinNames() []string

BuiltinNames returns the names of all built-in aesthetics.

func HasBuiltin

func HasBuiltin(name string) bool

HasBuiltin checks if a built-in aesthetic with the given name exists.

Types

type Aesthetic

type Aesthetic struct {
	// Metadata
	Name        string `json:"name" yaml:"name" toml:"name"`
	Description string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"`

	// Tokens organized by category
	Tokens Tokens `json:"tokens" yaml:"tokens" toml:"tokens"`

	// Legacy flat maps for CSS generation compatibility
	// These are populated from Tokens when GenerateCSS is called
	Typography map[string]string `json:"-" yaml:"-" toml:"-"`
	Spacing    map[string]string `json:"-" yaml:"-" toml:"-"`
	Borders    map[string]string `json:"-" yaml:"-" toml:"-"`
	Shadows    map[string]string `json:"-" yaml:"-" toml:"-"`

	// Source information (set after loading)
	Source     string `json:"-" yaml:"-" toml:"-"` // "built-in", "user", "project"
	SourcePath string `json:"-" yaml:"-" toml:"-"` // File path if loaded from file
}

Aesthetic represents a complete design token set with metadata.

func Load

func Load(name string) (*Aesthetic, error)

Load loads an aesthetic using the default loader.

func LoadBuiltin

func LoadBuiltin(name string) (*Aesthetic, error)

LoadBuiltin loads a built-in aesthetic by name.

func LoadFromFile

func LoadFromFile(path string) (*Aesthetic, error)

LoadFromFile loads an aesthetic from a specific file path.

func NewAesthetic

func NewAesthetic(name string) *Aesthetic

NewAesthetic creates a new empty aesthetic with initialized maps.

func (*Aesthetic) Clone

func (a *Aesthetic) Clone() *Aesthetic

Clone creates a deep copy of the aesthetic.

func (*Aesthetic) GenerateCSS

func (a *Aesthetic) GenerateCSS() string

GenerateCSS generates CSS custom properties for the aesthetic.

func (*Aesthetic) GenerateCSSMinified

func (a *Aesthetic) GenerateCSSMinified() string

GenerateCSSMinified generates minified CSS custom properties.

func (*Aesthetic) GenerateCSSWithFormat

func (a *Aesthetic) GenerateCSSWithFormat(format CSSFormat) string

GenerateCSSWithFormat generates CSS with the specified format options.

func (*Aesthetic) Get

func (a *Aesthetic) Get(tokenType, tokenKey string) string

Get retrieves a token value by type and key. Returns empty string if not found.

func (*Aesthetic) GetSpacingScale

func (a *Aesthetic) GetSpacingScale() float64

GetSpacingScale returns the spacing scale multiplier. Returns 1.0 if no spacing is configured.

func (*Aesthetic) GetWithDefault

func (a *Aesthetic) GetWithDefault(tokenType, tokenKey, defaultVal string) string

GetWithDefault retrieves a token value, returning defaultVal if not found.

func (*Aesthetic) Merge

func (a *Aesthetic) Merge(override *Aesthetic) *Aesthetic

Merge combines this aesthetic with an override aesthetic. The override values take precedence. Returns a new aesthetic.

func (*Aesthetic) Validate

func (a *Aesthetic) Validate() []error

Validate checks if the aesthetic has required fields. Returns a slice of validation errors (empty if valid).

type CSSFormat

type CSSFormat struct {
	IncludeTypography bool   // Include typography tokens
	IncludeSpacing    bool   // Include spacing tokens
	IncludeBorders    bool   // Include border tokens
	IncludeShadows    bool   // Include shadow tokens
	Minify            bool   // Produce minified output
	Prefix            string // Custom prefix for CSS variables (e.g., "theme" -> "--theme-radius-sm")
}

CSSFormat controls how CSS is generated.

func DefaultCSSFormat

func DefaultCSSFormat() CSSFormat

DefaultCSSFormat returns the default CSS format options.

type Info

type Info struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Source      string `json:"source"` // "built-in", "user", "project"
	Path        string `json:"path,omitempty"`
}

Info contains summary information about an aesthetic for listing.

func Discover

func Discover() ([]Info, error)

Discover discovers all aesthetics using the default loader.

func DiscoverBuiltin

func DiscoverBuiltin() []Info

DiscoverBuiltin returns info for all built-in aesthetics.

func ListAesthetics

func ListAesthetics() []Info

ListAesthetics returns info for all available aesthetics (built-in and discovered).

type LoadError

type LoadError struct {
	Name    string // Aesthetic name that failed to load
	Path    string // Path attempted (if applicable)
	Message string // Human-readable error message
	Err     error  // Underlying error
}

LoadError provides context for aesthetic loading failures.

func NewLoadError

func NewLoadError(name, path, message string, err error) *LoadError

NewLoadError creates a new LoadError.

func (*LoadError) Error

func (e *LoadError) Error() string

func (*LoadError) Unwrap

func (e *LoadError) Unwrap() error

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader handles aesthetic discovery and loading from multiple sources.

func NewLoader

func NewLoader() *Loader

NewLoader creates a new Loader with default search paths. Search order: built-in, user config, project directory.

func NewLoaderWithPaths

func NewLoaderWithPaths(paths []string) *Loader

NewLoaderWithPaths creates a new Loader with custom search paths.

func (*Loader) AddPath

func (l *Loader) AddPath(path string)

AddPath adds a search path to the loader. Paths added later have higher priority.

func (*Loader) ClearCache

func (l *Loader) ClearCache()

ClearCache clears the aesthetic cache.

func (*Loader) Discover

func (l *Loader) Discover() ([]Info, error)

Discover finds all available aesthetics across all sources. Returns aesthetic info sorted by source priority.

func (*Loader) Load

func (l *Loader) Load(name string) (*Aesthetic, error)

Load loads an aesthetic by name. It searches built-in aesthetics first, then search paths in order. Returns ErrAestheticNotFound if the aesthetic cannot be found.

type ParseError

type ParseError struct {
	Path    string // File path that failed to parse
	Message string // Human-readable error message
	Err     error  // Underlying error
}

ParseError provides context for aesthetic parsing failures.

func NewParseError

func NewParseError(path, message string, err error) *ParseError

NewParseError creates a new ParseError.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

type SpacingTokens

type SpacingTokens struct {
	Scale float64 `json:"scale" yaml:"scale" toml:"scale"`
}

SpacingTokens holds spacing-related design tokens.

type Tokens

type Tokens struct {
	Radius     map[string]string `json:"radius,omitempty" yaml:"radius,omitempty" toml:"radius,omitempty"`
	Spacing    *SpacingTokens    `json:"spacing,omitempty" yaml:"spacing,omitempty" toml:"spacing,omitempty"`
	Border     map[string]string `json:"border,omitempty" yaml:"border,omitempty" toml:"border,omitempty"`
	Shadow     map[string]string `json:"shadow,omitempty" yaml:"shadow,omitempty" toml:"shadow,omitempty"`
	Typography map[string]string `json:"typography,omitempty" yaml:"typography,omitempty" toml:"typography,omitempty"`
}

Tokens holds all design token categories for an aesthetic.

type ValidationError

type ValidationError struct {
	Field   string // Field that failed validation
	Message string // Human-readable error message
}

ValidationError represents an aesthetic validation failure.

func NewValidationError

func NewValidationError(field, message string) *ValidationError

NewValidationError creates a new ValidationError.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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