appearance

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package appearance provides value objects related to appearance information.

Package appearance provides value objects related to appearance information.

This package contains value objects that represent visual appearance attributes such as colors, styles, and other visual properties. These value objects are immutable and follow the Value Object pattern from Domain-Driven Design.

Key value objects in this package:

  • Color: Represents a color in hexadecimal format (#RRGGBB)

The Color value object provides methods for:

  • Creating and validating colors in hexadecimal format
  • Converting between different color formats
  • Extracting RGB components
  • Adding alpha channel information
  • Determining if a color is dark or light
  • Inverting colors

Example usage:

// Create a new color
color, err := appearance.NewColor("#FF5500")
if err != nil {
    // Handle validation error
}

// Get RGB components
r, g, b, err := color.RGB()
if err != nil {
    // Handle error
}

// Check if color is dark
isDark, err := color.IsDark()
if err != nil {
    // Handle error
}

// Invert the color
invertedColor, err := color.Invert()
if err != nil {
    // Handle error
}

All value objects in this package are designed to be immutable, so they cannot be changed after creation. To modify a value object, create a new instance with the desired values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color string

Color represents a color value object in hexadecimal format (#RRGGBB)

func NewColor

func NewColor(hexColor string) (Color, error)

NewColor creates a new Color with validation

func (Color) Equals

func (c Color) Equals(other Color) bool

Equals checks if two Colors are equal (case insensitive)

func (Color) Invert

func (c Color) Invert() (Color, error)

Invert returns the inverted color

func (Color) IsDark

func (c Color) IsDark() (bool, error)

IsDark returns true if the color is considered dark

func (Color) IsEmpty

func (c Color) IsEmpty() bool

IsEmpty checks if the Color is empty

func (Color) RGB

func (c Color) RGB() (r, g, b int, err error)

RGB returns the RGB components of the color

func (Color) String

func (c Color) String() string

String returns the string representation of the Color

func (Color) Validate

func (c Color) Validate() error

Validate checks if the Color is valid

func (Color) WithAlpha

func (c Color) WithAlpha(alpha int) (string, error)

WithAlpha returns a new color with the specified alpha component (0-255)

Jump to

Keyboard shortcuts

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