La referencia de API proviene de los comentarios de documentación de Go en el código fuente y está redactada en inglés.
package theme
import "github.com/nsgo-dev/game/pkg/editor/theme"Resumen
Package theme holds the NSGo editor's design tokens from design/editor/Spec.dc.html: the embedded YAML theme, the dark and light palettes, type, spacing, shape and motion constants, and the WCAG 2.2 contrast table every palette is measured against.
Índice
- Constantes
- func AgentPulseOpacity(cx *core.Scope, elapsed time.Duration) float32
- func CompositeOver(fg, bg core.Color) core.Color
- func ContrastRatio(a, b core.Color) float64
- func Core() *core.Theme
- func MotionDuration(cx *core.Scope, d time.Duration) time.Duration
- func RelativeLuminance(c core.Color) float64
- func YAML() []byte
- type ContrastPair
- type Palette
- type Role
Constantes
const (
FontFamilySans = "Inter"
FontFamilyMono = "JetBrains Mono"
FontTitleSize core.Points = 14
FontTitleWeight core.FontWeight = core.FontWeightSemibold // 600
FontBodySize core.Points = 12.5
FontBodyWeight core.FontWeight = core.FontWeightNormal // 400
FontSectionSize core.Points = 11
FontSectionWeight core.FontWeight = core.FontWeightSemibold // 600
FontSectionTrack core.Points = 0.66 // +6% tracking on 11 px
FontCodeSize core.Points = 11.5
FontCodeWeight core.FontWeight = core.FontWeightNormal // 400
)Typography tokens from design/editor/Spec.dc.html ("Type, space, shape").
const (
Space4 core.Points = 4
Space8 core.Points = 8
Space12 core.Points = 12
Space16 core.Points = 16
Space24 core.Points = 24
)Spacing scale tokens from design/editor/Spec.dc.html: 4, 8, 12, 16, 24 px only.
const (
RadiusControl core.Points = 6 // Controls, inputs, tree rows, pills
RadiusButton core.Points = 8 // Buttons
RadiusCard core.Points = 12 // Cards, popovers, toasts
RadiusDialog core.Points = 18 // Dialogs
)Corner radius tokens from design/editor/Spec.dc.html.
const (
RowHeight core.Points = 28 // Rows and tool buttons
MinHitSize core.Points = 28 // Minimum interactive hit area (28 x 28)
ButtonHeight core.Points = 30 // Standard button height (30-32 px)
ButtonTallHeight core.Points = 32 // Tall button height (30-32 px)
HeaderHeight core.Points = 44 // Header / toolbar height
BorderWidth core.Points = 1 // 1 px inner borders in Line or LineRaised
IconSize core.Points = 15 // Inline stroke icon size
IconStrokeWidth float32 = 1.8
)Height, border, and icon geometry tokens from design/editor/Spec.dc.html.
const (
MotionHover = 120 * time.Millisecond // Hover and press transitions
MotionPanel = 180 * time.Millisecond // Panels, popovers, and toasts
MotionOverlay = 240 * time.Millisecond // Agent change overlays fading in
MotionAgentPulse = 1600 * time.Millisecond // Agent outline pulse (100% <-> 45% opacity)
AgentPulseMinOpacity float32 = 0.45
AgentPulseMaxOpacity float32 = 1.0
)Motion tokens from design/editor/Spec.dc.html ("Motion"). All durations drop to 0 under Env.ReduceMotion (see MotionDuration).
Funciones
func AgentPulseOpacity(cx *core.Scope, elapsed time.Duration) float32AgentPulseOpacity returns the Spec agent-working outline opacity in [0.45, 1.0] for elapsed time since the pulse began. Under Env.ReduceMotion it stays solid at 1.0.
func CompositeOver(fg, bg core.Color) core.ColorCompositeOver alpha-blends fg over an opaque background bg in sRGB space.
func ContrastRatio(a, b core.Color) float64ContrastRatio returns the WCAG 2.1 / 2.2 contrast ratio between foreground a and background b, in [1, 21]. If a is translucent (alpha < 1), it is composited over b first.
func Core() *core.ThemeCore returns a clone of the editor's Spec *core.Theme containing both dark and light palettes, mapped onto every NSGo core.Palette and ui.Colors role as well as all Spec-specific tokens.
func MotionDuration(cx *core.Scope, d time.Duration) time.DurationMotionDuration returns d when motion is enabled, or 0 when cx is non-nil and cx.Env().ReduceMotion() is true.
func RelativeLuminance(c core.Color) float64RelativeLuminance returns the WCAG 2.1 / 2.2 relative luminance of c in [0, 1].
func YAML() []byteYAML returns a copy of the embedded YAML theme file parsed by core.ParseTheme.
Tipos
type ContrastPair struct {
Name string
Foreground core.Color
Background core.Color
MinRatio float64
Usage string
}ContrastPair is one foreground/background measurement row in the Spec's WCAG 2.2 contrast table.
func ContrastTable(p Palette) []ContrastPairContrastTable returns every foreground/background and overlay contrast pair required by design/editor/Spec.dc.html for palette p (Dark or Light), with its WCAG 2.2 minimum threshold.
func (p ContrastPair) Ratio() float64Ratio returns the measured WCAG 2.2 contrast ratio for this pair.
type Palette struct {
// Dark reports whether this palette is the dark appearance.
Dark bool
// Surfaces.
Bg core.Color // Window and outer background (`bg`).
Panel core.Color // Side panels, inspector, agent panel (`panel`).
Raised core.Color // Cards, composer, toasts, popovers (`raised`).
Inset core.Color // Recessed wells, tracks, sidebar rails (`inset`).
Viewport core.Color // Viewport canvas surround (`.vp`).
ViewportDot core.Color // Viewport dot grid mark.
PillBg core.Color // Floating overlay pill background.
// Borders.
Line core.Color // Dividers between regions (`line`).
LineRaised core.Color // Edges of raised surfaces and quiet button fills (`line raised`).
// Four text levels, all meeting WCAG 2.2 AA (>= 4.5:1) on Bg, Panel, and Raised.
TextPrimary core.Color // Spec `text strong`: titles, selected rows, primary button fill.
TextSecondary core.Color // Spec `text`: body, messages, values.
TextMuted core.Color // Spec `text secondary`: labels, tree rows, file names.
TextFaint core.Color // Spec `text muted`: hints, placeholders, meta, section labels.
OnTextPrimary core.Color // Ink drawn on a solid TextPrimary primary button fill (Play, Send, Create).
// Semantic roles, each carrying Fg, Fill, Edge, and OnFill.
Accent Role // Selection, focus ring, Keep; solid.
Agent Role // Agent working; solid violet, never blue.
Added Role // New objects and lines; dashed.
Changed Role // Edited objects and values; dashed.
Removed Role // Deleted objects and problems/errors; solid.
Warning Role // Permission asks, waiting, warning toasts (with dedicated Fill and Edge).
// Surface interaction overlays and 3D viewport / axis tokens (design/editor/Viewport3D.dc.html).
HoverOverlay core.Color // Subtle hover wash over surfaces (`surfaceHover`).
ActiveOverlay core.Color // Subtle pressed wash over surfaces (`surfacePressed`).
PrimaryHover core.Color // Hover fill for solid TextPrimary buttons (`specPrimaryHover`).
AccentHover core.Color // Hover fill for solid Accent buttons (`accentHover`).
AccentPressed core.Color // Pressed fill for solid Accent buttons (`accentPressed`).
Viewport3DGround core.Color // 3D viewport ground plane (`specViewport3DGround`).
Viewport3DGrid core.Color // 3D viewport grid line (`specViewport3DGrid`).
AxisX core.Color // 3D X axis token (`specAxisX`, #FF6B6B dark / #C92A2A light).
AxisY core.Color // 3D Y axis token (`specAxisY`, #4FD38A dark / #0D7A43 light).
AxisZ core.Color // 3D Z axis token (`specAxisZ`, #3B7BFF dark / #1D5CE6 light).
}Palette holds every color token defined by design/editor/Spec.dc.html in either the Dark or Light appearance.
func Dark() PaletteDark returns the dark Spec token palette from design/editor/Spec.dc.html.
func Light() PaletteLight returns the light Spec token palette measured against the same WCAG 2.2 contrast table.
func PaletteFor(dark bool) PalettePaletteFor returns Dark when dark is true and Light otherwise.
func (p Palette) FocusRing(offset core.Points) *core.StyleFocusRing returns the Spec keyboard focus ring style (2 px Accent.Edge outline with the given offset).
func (p Palette) Problem() RoleProblem returns the semantic role shared by removed objects and problems/errors (Spec `removed · problem`).
type Role struct {
// Fg is the foreground text, icon, glyph, or solid badge fill color.
Fg core.Color
// Fill is the tinted surface or pill fill color behind Fg or body text.
Fill core.Color
// Edge is the border, focus ring, or viewport overlay outline stroke color.
Edge core.Color
// OnFill is the high-contrast ink drawn directly on a solid Fg fill (>= 4.5:1 AA).
// It is never white on a fill that fails WCAG AA (for example dark Accent #3B7BFF or dark Agent #9B7BFF).
OnFill core.Color
}Role holds the coordinated colors for a semantic Spec token role (Accent, Agent, Added, Changed, Removed/Problem, or Warning).