Help us shape the future of Go! Take the 2026 Go Developer Survey

theme

package
v0.1.56 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 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, the Agently web application shell, 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 the same resolved values to two web boundaries: --agently-theme-* variables on .agently-application and the established --forge-* variables on .agently-workspace. Native clients consume JSON, never CSS.

The application variables are an opt-in bridge, not an automatic restyle. Agently keeps its incumbent --app-* defaults until a workspace-scoped CSS file maps the portable values to the public shell roles. This lets existing workspaces remain visually unchanged while one selected theme can configure the shell and Forge surfaces without duplicating token values.

File references are only modeled here. The workspace style service owns filesystem containment, CSS parsing, WOFF2 validation, delivery, authentication, and caching. 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, the system or semantic workspace-primary typography family, and logical numeric dimensions. The semantic name identifies a workspace's primary typeface without constraining it to sans-serif, serif, or another classification. Workspaces own the registered WOFF2 faces and license; the style service validates and serves those assets through authenticated, content-addressed, same-origin URLs. Generated application and Forge variables share the same workspace-defined family stack. 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 and fall back to their system family when a workspace family asset is unavailable. Changing these rules or default palettes requires updating the versioned shared contract and cross-client fixtures/tests together.

Example workspace font registration:

fonts:
  - role: workspace-primary
    name: Example Serif Variable
    fallback: serif
    faces:
      - file: fonts/example-latin.woff2
        style: normal
        weight: '100 700'
        unicodeRange: U+0000-00FF

Only contained regular WOFF2 files are accepted. Family names, roles, styles, weights, fallbacks, and optional Unicode ranges are finite validated values; arbitrary URLs and CSS fragments are not part of this contract.

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 FontFace added in v0.1.55

type FontFace struct {
	File         string `json:"file" yaml:"file"`
	Style        string `json:"style" yaml:"style"`
	Weight       string `json:"weight" yaml:"weight"`
	UnicodeRange string `json:"unicodeRange,omitempty" yaml:"unicodeRange,omitempty"`
}

type FontFamily added in v0.1.55

type FontFamily struct {
	Role     string     `json:"role" yaml:"role"`
	Name     string     `json:"name" yaml:"name"`
	Fallback string     `json:"fallback,omitempty" yaml:"fallback,omitempty"`
	Faces    []FontFace `json:"faces" yaml:"faces"`
}

type Manifest

type Manifest struct {
	Overrides    []string     `json:"overrides,omitempty" yaml:"overrides,omitempty"`
	Version      int          `json:"version" yaml:"version"`
	Fonts        []FontFamily `json:"fonts,omitempty" yaml:"fonts,omitempty"`
	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