theme

package
v0.1.39 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

Portable theme contract

This package resolves manifest v1 into complete semantic token maps shared by Forge web, Agently iOS, and Agently Android. Parse rejects unknown manifest fields and invalid tokens; Resolve overlays common/mode tokens on independent built-in palettes. CSS maps resolved tokens to scoped web declarations. Native clients consume JSON, never CSS.

File references are only modeled here. Filesystem containment, CSS parsing, delivery, authentication, and caching belong to the pending workspace asset service. Do not serve a manifest's file list without that validation.

The canonical fixture is testdata/baseline.yaml. Regenerate JSON and CSS from this directory with:

go generate
go test ./...

The Swift and Kotlin theme tests read the same JSON in the sibling checkout. Forge's npm run test:workspace-theme uses the generated CSS and actual widget runtime in a browser. It expects sibling forge, agently, and agently-core directories. This is an integration fixture, not a runtime filesystem dependency for native clients.

Version 1 uses literal hex colors, system typography, and logical numeric dimensions. Bounds: font size 8–72; minimum control height 16–128; radius and inline padding 0–64. Native adapters retain platform touch-target minimums and text scaling. Changing these rules or default palettes requires updating the versioned shared contract and cross-client fixtures/tests together.

Documentation

Index

Constants

View Source
const MaxManifestBytes = 512 * 1024
View Source
const PaletteVersion = 1
View Source
const Version = 1

Variables

This section is empty.

Functions

func CSS

func CSS(c *Catalog) (string, error)

CSS emits only validated tokens. It does not load or compile workspace CSS. Passing a catalog not produced by Resolve still validates selector/value input.

Types

type Catalog

type Catalog struct {
	Version        int             `json:"version"`
	PaletteVersion int             `json:"paletteVersion"`
	DefaultTheme   string          `json:"defaultTheme"`
	DefaultMode    string          `json:"defaultMode"`
	Themes         []ResolvedTheme `json:"themes"`
}

func Resolve

func Resolve(m Manifest) (*Catalog, error)

Resolve returns independently allocated, complete token maps in stable ID order. Asset path/content validation is performed by the workspace asset loader.

type Manifest

type Manifest struct {
	Overrides    []string `json:"overrides,omitempty" yaml:"overrides,omitempty"`
	Version      int      `json:"version" yaml:"version"`
	Files        []string `json:"files,omitempty" yaml:"files,omitempty"`
	DefaultTheme string   `json:"defaultTheme,omitempty" yaml:"defaultTheme,omitempty"`
	DefaultMode  string   `json:"defaultMode,omitempty" yaml:"defaultMode,omitempty"`
	Themes       []Theme  `json:"themes,omitempty" yaml:"themes,omitempty"`
}

func Parse

func Parse(data []byte) (*Manifest, error)

Parse rejects unknown fields, duplicate YAML keys, and multiple documents.

type ResolvedTheme

type ResolvedTheme struct {
	ID           string            `json:"id"`
	Label        string            `json:"label"`
	FallbackMode string            `json:"fallbackMode"`
	Modes        map[string]Tokens `json:"modes"`
}

func (ResolvedTheme) EffectiveMode

func (t ResolvedTheme) EffectiveMode(preference, systemMode string) string

EffectiveMode implements the same fallback rule expected of all clients.

type Theme

type Theme struct {
	ID           string             `json:"id" yaml:"id"`
	Label        string             `json:"label" yaml:"label"`
	FallbackMode string             `json:"fallbackMode" yaml:"fallbackMode"`
	Tokens       Tokens             `json:"tokens,omitempty" yaml:"tokens,omitempty"`
	Files        []string           `json:"files,omitempty" yaml:"files,omitempty"`
	Modes        map[string]Variant `json:"modes" yaml:"modes"`
}

type Tokens

type Tokens map[string]interface{}

func Defaults

func Defaults(mode string) Tokens

Defaults returns a fresh palette. Dimensions are logical units, not CSS strings.

type Variant

type Variant struct {
	Tokens Tokens   `json:"tokens,omitempty" yaml:"tokens,omitempty"`
	Files  []string `json:"files,omitempty" yaml:"files,omitempty"`
}

Directories

Path Synopsis
cmd
generate command
Command generate refreshes the shared web/native theme fixtures.
Command generate refreshes the shared web/native theme fixtures.

Jump to

Keyboard shortcuts

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