design

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const CSSTemplate = `` /* 167-byte string literal not displayed */

CSSTemplate is the template for CSS variables generation

View Source
const JavaScriptTemplate = `` /* 193-byte string literal not displayed */

JavaScriptTemplate is the template for JavaScript constants generation

View Source
const SCSSTemplate = `` /* 147-byte string literal not displayed */

SCSSTemplate is the template for SCSS variables generation

View Source
const TailwindTemplate = `` /* 1029-byte string literal not displayed */

TailwindTemplate is the template for Tailwind config generation

View Source
const TypeScriptTemplate = `` /* 250-byte string literal not displayed */

TypeScriptTemplate is the template for TypeScript constants generation

Variables

This section is empty.

Functions

func PrintConflictSummary

func PrintConflictSummary(conflicts []Conflict)

PrintConflictSummary prints a summary of conflicts and their resolutions.

Types

type CSSParser

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

CSSParser parses CSS files to extract design tokens.

func NewCSSParser

func NewCSSParser() *CSSParser

NewCSSParser creates a new CSS parser.

func (*CSSParser) Parse

func (p *CSSParser) Parse(reader io.Reader) (*ExtractionResult, error)

Parse parses a CSS file and extracts design tokens.

type CSSVariablesFormatter

type CSSVariablesFormatter struct {
	Prefix string
}

CSSVariablesFormatter formats tokens as CSS custom properties.

func NewCSSVariablesFormatter

func NewCSSVariablesFormatter(prefix string) *CSSVariablesFormatter

NewCSSVariablesFormatter creates a new CSS variables formatter.

func (*CSSVariablesFormatter) Format

func (f *CSSVariablesFormatter) Format(tokens []Token) (string, error)

Format converts tokens to CSS custom properties.

type Change

type Change struct {
	// Type is the type of change.
	Type ChangeType

	// Token is the token that changed.
	Token *Token

	// OldToken is the previous version of the token (for updates).
	OldToken *Token

	// Timestamp is when the change was detected.
	Timestamp time.Time
}

Change represents a change detected in tokens.

type ChangeType

type ChangeType string

ChangeType represents the type of change detected.

const (
	// ChangeTypeCreate indicates a token was created.
	ChangeTypeCreate ChangeType = "create"

	// ChangeTypeUpdate indicates a token was updated.
	ChangeTypeUpdate ChangeType = "update"

	// ChangeTypeDelete indicates a token was deleted.
	ChangeTypeDelete ChangeType = "delete"
)

type ColorFormat

type ColorFormat string

ColorFormat represents the format of a color value.

const (
	ColorFormatHex  ColorFormat = "hex"
	ColorFormatRGB  ColorFormat = "rgb"
	ColorFormatRGBA ColorFormat = "rgba"
	ColorFormatHSL  ColorFormat = "hsl"
	ColorFormatHSLA ColorFormat = "hsla"
)

type Conflict

type Conflict struct {
	// TokenName is the name of the conflicting token.
	TokenName string

	// LocalToken is the local version of the token.
	LocalToken *Token

	// RemoteToken is the remote version of the token.
	RemoteToken *Token

	// ConflictType is the type of conflict.
	ConflictType ConflictType

	// Resolution is the chosen resolution for this conflict.
	Resolution *ConflictResolution
}

Conflict represents a conflict between local and remote tokens.

type ConflictResolution

type ConflictResolution struct {
	// Strategy is the strategy used to resolve the conflict.
	Strategy ConflictResolutionStrategy

	// SelectedToken is the token that was selected as the resolution.
	SelectedToken *Token

	// Reason is the reason for the resolution.
	Reason string
}

ConflictResolution represents the resolution of a conflict.

type ConflictResolutionStrategy

type ConflictResolutionStrategy string

ConflictResolutionStrategy represents how to handle conflicts.

const (
	// ConflictResolutionLocal prefers local changes over remote.
	ConflictResolutionLocal ConflictResolutionStrategy = "local"

	// ConflictResolutionRemote prefers remote changes over remote.
	ConflictResolutionRemote ConflictResolutionStrategy = "remote"

	// ConflictResolutionNewest prefers the newest changes based on timestamp.
	ConflictResolutionNewest ConflictResolutionStrategy = "newest"

	// ConflictResolutionPrompt prompts the user to resolve conflicts.
	ConflictResolutionPrompt ConflictResolutionStrategy = "prompt"

	// ConflictResolutionMerge attempts to merge changes.
	ConflictResolutionMerge ConflictResolutionStrategy = "merge"
)

type ConflictResolutionStrategyUpload

type ConflictResolutionStrategyUpload string

ConflictResolutionStrategy defines how to handle conflicting tokens during upload. Renamed from ConflictResolution to avoid conflict with sync_types.go

const (
	// ConflictOverwrite replaces existing tokens with new values
	ConflictOverwrite ConflictResolutionStrategyUpload = "overwrite"

	// ConflictMerge merges new tokens with existing, preferring new values
	ConflictMerge ConflictResolutionStrategyUpload = "merge"

	// ConflictSkip skips conflicting tokens and keeps existing values
	ConflictSkip ConflictResolutionStrategyUpload = "skip"
)

type ConflictResolver

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

ConflictResolver handles conflict resolution during synchronization.

func NewConflictResolver

func NewConflictResolver(config ConflictResolverConfig) *ConflictResolver

NewConflictResolver creates a new conflict resolver.

func (*ConflictResolver) Resolve

func (r *ConflictResolver) Resolve(conflict Conflict) ConflictResolution

Resolve resolves a conflict based on the configured strategy.

func (*ConflictResolver) ResolveAll

func (r *ConflictResolver) ResolveAll(conflicts []Conflict) []ConflictResolution

ResolveAll resolves multiple conflicts in batch.

type ConflictResolverConfig

type ConflictResolverConfig struct {
	// Strategy is the default strategy for resolving conflicts.
	Strategy ConflictResolutionStrategy

	// Interactive enables interactive prompts for conflict resolution.
	Interactive bool
}

ConflictResolverConfig configures the conflict resolver.

type ConflictType

type ConflictType string

ConflictType represents the type of conflict.

const (
	// ConflictTypeBothModified indicates both local and remote were modified.
	ConflictTypeBothModified ConflictType = "both_modified"

	// ConflictTypeLocalDeleted indicates local was deleted but remote was modified.
	ConflictTypeLocalDeleted ConflictType = "local_deleted"

	// ConflictTypeRemoteDeleted indicates remote was deleted but local was modified.
	ConflictTypeRemoteDeleted ConflictType = "remote_deleted"

	// ConflictTypeTypeChange indicates the token type changed.
	ConflictTypeTypeChange ConflictType = "type_change"
)

type DesignClient

type DesignClient interface {
	// GetTokens retrieves all design tokens for a project.
	GetTokens(ctx context.Context, projectID string) ([]Token, error)

	// UploadTokens uploads design tokens to the remote project.
	UploadTokens(ctx context.Context, projectID string, tokens []Token) error

	// DeleteToken deletes a design token from the remote project.
	DeleteToken(ctx context.Context, projectID string, tokenName string) error
}

DesignClient defines the interface for interacting with the design API.

type ExtractionResult

type ExtractionResult struct {
	Tokens   []Token
	Warnings []string
	Errors   []error
}

ExtractionResult represents the result of token extraction.

type Extractor

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

Extractor extracts design tokens from CSS/SCSS/LESS files.

func NewExtractor

func NewExtractor(opts *ExtractorOptions) *Extractor

NewExtractor creates a new design token extractor.

func (*Extractor) Extract

func (e *Extractor) Extract(reader io.Reader, parser Parser) (*ExtractionResult, error)

Extract extracts design tokens using the specified parser.

func (*Extractor) ExtractFromFile

func (e *Extractor) ExtractFromFile(filePath string) (*ExtractionResult, error)

ExtractFromFile extracts design tokens from a file.

type ExtractorOptions

type ExtractorOptions struct {
	EnableValidation bool
	IncludeComments  bool
	InferCategories  bool
}

ExtractorOptions configures the token extractor.

type Formatter

type Formatter interface {
	Format(tokens []Token) (string, error)
}

Formatter formats design tokens into various output formats.

func GetFormatter

func GetFormatter(format OutputFormat, options map[string]interface{}) (Formatter, error)

GetFormatter returns the appropriate formatter based on the output format.

type JSONFormatter

type JSONFormatter struct {
	Pretty bool
}

JSONFormatter formats tokens as JSON.

func NewJSONFormatter

func NewJSONFormatter(pretty bool) *JSONFormatter

NewJSONFormatter creates a new JSON formatter.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(tokens []Token) (string, error)

Format converts tokens to JSON format.

type LESSParser

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

LESSParser parses LESS files to extract design tokens.

func NewLESSParser

func NewLESSParser() *LESSParser

NewLESSParser creates a new LESS parser.

func (*LESSParser) Parse

func (p *LESSParser) Parse(reader io.Reader) (*ExtractionResult, error)

Parse parses a LESS file and extracts design tokens.

type OutputFormat

type OutputFormat string

OutputFormat represents the format for token output.

const (
	OutputFormatJSON     OutputFormat = "json"
	OutputFormatYAML     OutputFormat = "yaml"
	OutputFormatTailwind OutputFormat = "tailwind"
)

type ParseError

type ParseError struct {
	Line    int
	Column  int
	Message string
	Source  string
}

ParseError represents an error that occurred during parsing.

func (*ParseError) Error

func (e *ParseError) Error() string

type Parser

type Parser interface {
	Parse(reader io.Reader) (*ExtractionResult, error)
}

Parser is an interface for parsing different CSS-like formats.

type SCSSParser

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

SCSSParser parses SCSS files to extract design tokens.

func NewSCSSParser

func NewSCSSParser() *SCSSParser

NewSCSSParser creates a new SCSS parser.

func (*SCSSParser) Parse

func (p *SCSSParser) Parse(reader io.Reader) (*ExtractionResult, error)

Parse parses an SCSS file and extracts design tokens.

type SCSSVariablesFormatter

type SCSSVariablesFormatter struct{}

SCSSVariablesFormatter formats tokens as SCSS variables.

func NewSCSSVariablesFormatter

func NewSCSSVariablesFormatter() *SCSSVariablesFormatter

NewSCSSVariablesFormatter creates a new SCSS variables formatter.

func (*SCSSVariablesFormatter) Format

func (f *SCSSVariablesFormatter) Format(tokens []Token) (string, error)

Format converts tokens to SCSS variables.

type StyleDictionaryFormatter

type StyleDictionaryFormatter struct {
	Pretty bool
}

StyleDictionaryFormatter formats tokens in Style Dictionary format.

func NewStyleDictionaryFormatter

func NewStyleDictionaryFormatter(pretty bool) *StyleDictionaryFormatter

NewStyleDictionaryFormatter creates a new Style Dictionary formatter.

func (*StyleDictionaryFormatter) Format

func (f *StyleDictionaryFormatter) Format(tokens []Token) (string, error)

Format converts tokens to Style Dictionary format.

type SyncConfig

type SyncConfig struct {
	// ProjectID is the ID of the project to sync.
	ProjectID string

	// Direction is the direction of synchronization.
	Direction SyncDirection

	// WatchMode enables continuous watching for changes.
	WatchMode bool

	// WatchInterval is the interval for checking changes in watch mode.
	WatchInterval time.Duration

	// LocalPath is the local file path for tokens.
	LocalPath string

	// ConflictResolution is the strategy for resolving conflicts.
	ConflictResolution ConflictResolutionStrategy

	// DryRun performs a dry run without making actual changes.
	DryRun bool

	// Verbose enables verbose logging.
	Verbose bool
}

SyncConfig represents the configuration for synchronization.

type SyncDirection

type SyncDirection string

SyncDirection represents the direction of synchronization.

const (
	// SyncDirectionPull pulls tokens from remote to local.
	SyncDirectionPull SyncDirection = "pull"

	// SyncDirectionPush pushes tokens from local to remote.
	SyncDirectionPush SyncDirection = "push"

	// SyncDirectionBidirectional performs bidirectional sync.
	SyncDirectionBidirectional SyncDirection = "bidirectional"
)

type SyncResult

type SyncResult struct {
	// Added is the number of tokens added.
	Added int

	// Updated is the number of tokens updated.
	Updated int

	// Deleted is the number of tokens deleted.
	Deleted int

	// Conflicts is the list of conflicts encountered.
	Conflicts []Conflict

	// Errors is the list of errors encountered.
	Errors []error

	// Duration is the time taken for the sync operation.
	Duration time.Duration

	// DryRun indicates if this was a dry run.
	DryRun bool
}

SyncResult represents the result of a synchronization operation.

type SyncState

type SyncState struct {
	// ProjectID is the project being synced.
	ProjectID string

	// LastSyncedAt is the last successful sync timestamp.
	LastSyncedAt time.Time

	// LocalTokens is the snapshot of local tokens.
	LocalTokens map[string]*TokenWithMetadata

	// RemoteTokens is the snapshot of remote tokens.
	RemoteTokens map[string]*TokenWithMetadata
}

SyncState represents the state of a synchronization session.

type Syncer

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

Syncer handles bidirectional design token synchronization.

func NewSyncer

func NewSyncer(client DesignClient, config SyncConfig) *Syncer

NewSyncer creates a new design token syncer.

func (*Syncer) Sync

func (s *Syncer) Sync(ctx context.Context) (*SyncResult, error)

Sync performs a synchronization operation based on the configured direction.

type TailwindFormatter

type TailwindFormatter struct {
	IncludeComments bool
}

TailwindFormatter formats tokens as a Tailwind CSS configuration.

func NewTailwindFormatter

func NewTailwindFormatter(includeComments bool) *TailwindFormatter

NewTailwindFormatter creates a new Tailwind formatter.

func (*TailwindFormatter) Format

func (f *TailwindFormatter) Format(tokens []Token) (string, error)

Format converts tokens to Tailwind config format.

type TemplateEngine

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

TemplateEngine provides template-based code generation functionality

func NewTemplateEngine

func NewTemplateEngine() *TemplateEngine

NewTemplateEngine creates a new template engine with built-in functions

func (*TemplateEngine) Execute

func (te *TemplateEngine) Execute(name string, data interface{}) (string, error)

Execute executes a registered template with the given data

func (*TemplateEngine) ExecuteString

func (te *TemplateEngine) ExecuteString(templateStr string, data interface{}) (string, error)

ExecuteString executes an inline template string with the given data

func (*TemplateEngine) RegisterTemplate

func (te *TemplateEngine) RegisterTemplate(name string, content string) error

RegisterTemplate registers a new template with the engine

type Token

type Token struct {
	Name        string            `json:"name" yaml:"name"`
	Type        TokenType         `json:"type" yaml:"type"`
	Value       string            `json:"value" yaml:"value"`
	Description string            `json:"description,omitempty" yaml:"description,omitempty"`
	Category    string            `json:"category,omitempty" yaml:"category,omitempty"`
	Metadata    map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}

Token represents a single design token extracted from CSS/SCSS/LESS.

func (*Token) ComputeHash

func (t *Token) ComputeHash() (string, error)

ComputeHash computes a hash of the token for change detection.

func (*Token) Equals

func (t *Token) Equals(other *Token) bool

Equals checks if two tokens are equal based on their content.

type TokenCategorizer

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

TokenCategorizer categorizes tokens based on their properties.

func NewTokenCategorizer

func NewTokenCategorizer() *TokenCategorizer

NewTokenCategorizer creates a new token categorizer.

func (*TokenCategorizer) Categorize

func (c *TokenCategorizer) Categorize(token *Token)

Categorize assigns a category to a token based on its name and type.

type TokenCollection

type TokenCollection struct {
	Tokens   []Token           `json:"tokens" yaml:"tokens"`
	Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}

TokenCollection represents a collection of design tokens organized by type.

type TokenType

type TokenType string

TokenType represents the category of a design token.

const (
	// TokenTypeColor represents color tokens (hex, rgb, hsl)
	TokenTypeColor TokenType = "color"
	// TokenTypeTypography represents typography-related tokens
	TokenTypeTypography TokenType = "typography"
	// TokenTypeSpacing represents spacing tokens (margin, padding)
	TokenTypeSpacing TokenType = "spacing"
	// TokenTypeShadow represents shadow tokens
	TokenTypeShadow TokenType = "shadow"
	// TokenTypeBorderRadius represents border-radius tokens
	TokenTypeBorderRadius TokenType = "border-radius"
)

type TokenWithMetadata

type TokenWithMetadata struct {
	Token

	// LastSyncedAt is the timestamp when this token was last synced.
	LastSyncedAt time.Time `json:"last_synced_at,omitempty"`

	// Hash is the hash of the token for change detection.
	Hash string `json:"hash"`

	// Version is the version number for optimistic locking.
	Version int `json:"version"`
}

TokenWithMetadata extends Token with sync metadata.

type ValidationError

type ValidationError struct {
	TokenName string
	Field     string
	Message   string
}

ValidationError represents a token validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface.

type ValidationResult

type ValidationResult struct {
	Valid  bool
	Errors []*ValidationError
}

ValidationResult contains the results of token validation.

type Validator

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

Validator provides design token validation functionality.

func NewValidator

func NewValidator() *Validator

NewValidator creates a new token validator.

func (*Validator) Validate

func (v *Validator) Validate(token *Token) *ValidationResult

Validate validates a single design token.

func (*Validator) ValidateBatch

func (v *Validator) ValidateBatch(tokens []*Token) *ValidationResult

ValidateBatch validates a batch of design tokens.

type WatchConfig

type WatchConfig struct {
	// Paths to watch for changes.
	Paths []string

	// Debounce duration to prevent rapid re-syncs.
	DebounceDuration time.Duration

	// SyncOnStart triggers an initial sync when watch mode starts.
	SyncOnStart bool

	// MaxRetries for sync operations.
	MaxRetries int

	// RetryDelay between sync retries.
	RetryDelay time.Duration
}

WatchConfig configures the file watcher.

type WatchEvent

type WatchEvent struct {
	// Path is the path of the file that changed.
	Path string

	// Type is the type of change.
	Type ChangeType

	// Timestamp is when the change was detected.
	Timestamp time.Time
}

WatchEvent represents a file system change event.

type Watcher

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

Watcher monitors file system changes and triggers synchronization.

func NewWatcher

func NewWatcher(syncer *Syncer, config WatchConfig) (*Watcher, error)

NewWatcher creates a new file system watcher.

func (*Watcher) IsRunning

func (w *Watcher) IsRunning() bool

IsRunning returns whether the watcher is currently running.

func (*Watcher) Start

func (w *Watcher) Start(ctx context.Context) error

Start begins watching for file changes.

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop stops the file watcher.

type YAMLFormatter

type YAMLFormatter struct{}

YAMLFormatter formats tokens as YAML.

func NewYAMLFormatter

func NewYAMLFormatter() *YAMLFormatter

NewYAMLFormatter creates a new YAML formatter.

func (*YAMLFormatter) Format

func (f *YAMLFormatter) Format(tokens []Token) (string, error)

Format converts tokens to YAML format.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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