Documentation
¶
Index ¶
- Variables
- func ClassToBgColor(class string) termenv.Color
- func ClassToFgColor(class string) termenv.Color
- func Color(colorClass string) string
- func ExtractProperty(style, property string) string
- func GetTailwindColorName(colorClass string) string
- func GetTailwindShade(colorClass string) string
- func IsTailwindColor(colorClass string) bool
- func IsTextUtilityClass(class string) bool
- func MergeClasses(baseClasses, overrideClasses string) string
- func MergePadding(existing, new struct{ ... }) struct{ ... }
- func MergeStyles(styles ...string) string
- func ParseFontSize(class string) float64
- func ParsePadding(class string) (top, right, bottom, left *float64)
- func ParseRawTailwindColor(colorClass string) (string, error)
- func ParseTailwindColor(colorClass string) (string, error)
- func ResolveLayoutFromStyle(style string) (*WidthSpec, ParsedAlignment)
- func TransformText(text, transform string) string
- func TruncateForAppend(text, styleStr string) string
- func TruncateText(text string, maxLines, maxWidth int, mode string) string
- type Alignment
- type AlignmentParser
- type BorderColor
- type Borders
- func NewDashedBorder(width float64, color BorderColor) Borders
- func NewLeftRightBorder(width float64, color BorderColor, style LineStyle) Borders
- func NewSolidBorder(width float64, color BorderColor) Borders
- func NewTopBottomBorder(width float64, color BorderColor, style LineStyle) Borders
- func ParseBorders(styles ...string) Borders
- type Line
- type LineStyle
- type PaddingValue
- type ParsedAlignment
- type Style
- type StyleMerger
- type VerticalAlign
- type WidthParser
- type WidthSpec
- type WidthType
Constants ¶
This section is empty.
Variables ¶
var DefaultAlignmentParser = NewAlignmentParser()
Global parser instance for public API
var DefaultStyleMerger = &StyleMerger{}
Global merger instance for public API
var DefaultWidthParser = NewWidthParser()
Global parser instance for public API
var TailwindColors = map[string]map[string]string{
"slate": {
"50": "#f8fafc",
"100": "#f1f5f9",
"200": "#e2e8f0",
"300": "#cbd5e1",
"400": "#94a3b8",
"500": "#64748b",
"600": "#475569",
"700": "#334155",
"800": "#1e293b",
"900": "#0f172a",
"950": "#020617",
},
"gray": {
"50": "#f9fafb",
"100": "#f3f4f6",
"200": "#e5e7eb",
"300": "#d1d5db",
"400": "#9ca3af",
"500": "#6b7280",
"600": "#4b5563",
"700": "#374151",
"800": "#1f2937",
"900": "#111827",
"950": "#030712",
},
"zinc": {
"50": "#fafafa",
"100": "#f4f4f5",
"200": "#e4e4e7",
"300": "#d4d4d8",
"400": "#a1a1aa",
"500": "#71717a",
"600": "#52525b",
"700": "#3f3f46",
"800": "#27272a",
"900": "#18181b",
"950": "#09090b",
},
"neutral": {
"50": "#fafafa",
"100": "#f5f5f5",
"200": "#e5e5e5",
"300": "#d4d4d4",
"400": "#a3a3a3",
"500": "#737373",
"600": "#525252",
"700": "#404040",
"800": "#262626",
"900": "#171717",
"950": "#0a0a0a",
},
"stone": {
"50": "#fafaf9",
"100": "#f5f5f4",
"200": "#e7e5e4",
"300": "#d6d3d1",
"400": "#a8a29e",
"500": "#78716c",
"600": "#57534e",
"700": "#44403c",
"800": "#292524",
"900": "#1c1917",
"950": "#0c0a09",
},
"red": {
"50": "#fef2f2",
"100": "#fee2e2",
"200": "#fecaca",
"300": "#fca5a5",
"400": "#f87171",
"500": "#ef4444",
"600": "#dc2626",
"700": "#b91c1c",
"800": "#991b1b",
"900": "#7f1d1d",
"950": "#450a0a",
},
"orange": {
"50": "#fff7ed",
"100": "#ffedd5",
"200": "#fed7aa",
"300": "#fdba74",
"400": "#fb923c",
"500": "#f97316",
"600": "#ea580c",
"700": "#c2410c",
"800": "#9a3412",
"900": "#7c2d12",
"950": "#431407",
},
"amber": {
"50": "#fffbeb",
"100": "#fef3c7",
"200": "#fde68a",
"300": "#fcd34d",
"400": "#fbbf24",
"500": "#f59e0b",
"600": "#d97706",
"700": "#b45309",
"800": "#92400e",
"900": "#78350f",
"950": "#451a03",
},
"yellow": {
"50": "#fefce8",
"100": "#fef9c3",
"200": "#fef08a",
"300": "#fde047",
"400": "#facc15",
"500": "#eab308",
"600": "#ca8a04",
"700": "#a16207",
"800": "#854d0e",
"900": "#713f12",
"950": "#422006",
},
"lime": {
"50": "#f7fee7",
"100": "#ecfccb",
"200": "#d9f99d",
"300": "#bef264",
"400": "#a3e635",
"500": "#84cc16",
"600": "#65a30d",
"700": "#4d7c0f",
"800": "#3f6212",
"900": "#365314",
"950": "#1a2e05",
},
"green": {
"50": "#f0fdf4",
"100": "#dcfce7",
"200": "#bbf7d0",
"300": "#86efac",
"400": "#4ade80",
"500": "#22c55e",
"600": "#16a34a",
"700": "#15803d",
"800": "#166534",
"900": "#14532d",
"950": "#052e16",
},
"emerald": {
"50": "#ecfdf5",
"100": "#d1fae5",
"200": "#a7f3d0",
"300": "#6ee7b7",
"400": "#34d399",
"500": "#10b981",
"600": "#059669",
"700": "#047857",
"800": "#065f46",
"900": "#064e3b",
"950": "#022c22",
},
"teal": {
"50": "#f0fdfa",
"100": "#ccfbf1",
"200": "#99f6e4",
"300": "#5eead4",
"400": "#2dd4bf",
"500": "#14b8a6",
"600": "#0d9488",
"700": "#0f766e",
"800": "#115e59",
"900": "#134e4a",
"950": "#042f2e",
},
"cyan": {
"50": "#ecfeff",
"100": "#cffafe",
"200": "#a5f3fc",
"300": "#67e8f9",
"400": "#22d3ee",
"500": "#06b6d4",
"600": "#0891b2",
"700": "#0e7490",
"800": "#155e75",
"900": "#164e63",
"950": "#083344",
},
"sky": {
"50": "#f0f9ff",
"100": "#e0f2fe",
"200": "#bae6fd",
"300": "#7dd3fc",
"400": "#38bdf8",
"500": "#0ea5e9",
"600": "#0284c7",
"700": "#0369a1",
"800": "#075985",
"900": "#0c4a6e",
"950": "#082f49",
},
"blue": {
"50": "#eff6ff",
"100": "#dbeafe",
"200": "#bfdbfe",
"300": "#93c5fd",
"400": "#60a5fa",
"500": "#3b82f6",
"600": "#2563eb",
"700": "#1d4ed8",
"800": "#1e40af",
"900": "#1e3a8a",
"950": "#172554",
},
"indigo": {
"50": "#eef2ff",
"100": "#e0e7ff",
"200": "#c7d2fe",
"300": "#a5b4fc",
"400": "#818cf8",
"500": "#6366f1",
"600": "#4f46e5",
"700": "#4338ca",
"800": "#3730a3",
"900": "#312e81",
"950": "#1e1b4b",
},
"violet": {
"50": "#f5f3ff",
"100": "#ede9fe",
"200": "#ddd6fe",
"300": "#c4b5fd",
"400": "#a78bfa",
"500": "#8b5cf6",
"600": "#7c3aed",
"700": "#6d28d9",
"800": "#5b21b6",
"900": "#4c1d95",
"950": "#2e1065",
},
"purple": {
"50": "#faf5ff",
"100": "#f3e8ff",
"200": "#e9d5ff",
"300": "#d8b4fe",
"400": "#c084fc",
"500": "#a855f7",
"600": "#9333ea",
"700": "#7e22ce",
"800": "#6b21a8",
"900": "#581c87",
"950": "#3b0764",
},
"fuchsia": {
"50": "#fdf4ff",
"100": "#fae8ff",
"200": "#f5d0fe",
"300": "#f0abfc",
"400": "#e879f9",
"500": "#d946ef",
"600": "#c026d3",
"700": "#a21caf",
"800": "#86198f",
"900": "#701a75",
"950": "#4a044e",
},
"pink": {
"50": "#fdf2f8",
"100": "#fce7f3",
"200": "#fbcfe8",
"300": "#f9a8d4",
"400": "#f472b6",
"500": "#ec4899",
"600": "#db2777",
"700": "#be185d",
"800": "#9d174d",
"900": "#831843",
"950": "#500724",
},
"rose": {
"50": "#fff1f2",
"100": "#ffe4e6",
"200": "#fecdd3",
"300": "#fda4af",
"400": "#fb7185",
"500": "#f43f5e",
"600": "#e11d48",
"700": "#be123c",
"800": "#9f1239",
"900": "#881337",
"950": "#4c0519",
},
}
TailwindColors defines the Tailwind CSS color palette
var TailwindFontSizes = map[string]float64{
"xs": 0.75,
"sm": 0.875,
"base": 1,
"lg": 1.125,
"xl": 1.25,
"2xl": 1.5,
"3xl": 1.875,
"4xl": 2.25,
"5xl": 3,
"6xl": 3.75,
"7xl": 4.5,
"8xl": 6,
"9xl": 8,
}
TailwindFontSizes defines Tailwind font size scale in rem units
var TailwindSpacing = map[string]float64{
"0": 0,
"px": 0.0625,
"0.5": 0.125,
"1": 0.25,
"1.5": 0.375,
"2": 0.5,
"2.5": 0.625,
"3": 0.75,
"3.5": 0.875,
"4": 1,
"5": 1.25,
"6": 1.5,
"7": 1.75,
"8": 2,
"9": 2.25,
"10": 2.5,
"11": 2.75,
"12": 3,
"14": 3.5,
"16": 4,
"20": 5,
"24": 6,
"28": 7,
"32": 8,
"36": 9,
"40": 10,
"44": 11,
"48": 12,
"52": 13,
"56": 14,
"60": 15,
"64": 16,
"72": 18,
"80": 20,
"96": 24,
}
TailwindSpacing defines the Tailwind CSS spacing scale in rem units
var TailwindSpecialColors = map[string]string{
"transparent": "transparent",
"success": "#22c55e",
"error": "#ef4444",
"info": "#3b82f6",
"warning": "#f59e0b",
"muted": "#6b7280",
"current": "currentColor",
"black": "#000000",
"white": "#ffffff",
}
Special Tailwind colors
var TerminalHeightFunc = func() int { return 40 }
TerminalHeightFunc returns the current terminal height in lines.
var TerminalWidthFunc = func() int { return 120 }
TerminalWidthFunc returns the current terminal width in characters. Set by the api package to avoid circular imports.
Functions ¶
func ClassToBgColor ¶
ClassToBgColor converts a Tailwind class to a termenv background color
func ClassToFgColor ¶
ClassToFgColor converts a Tailwind class to a termenv foreground color
func Color ¶
Color converts a Tailwind color class to a raw color string without adaptation It parses the Tailwind color and returns the appropriate color value
func ExtractProperty ¶
ExtractProperty extracts a specific property type from a style string Returns the last occurrence of that property type (last wins)
func GetTailwindColorName ¶
GetTailwindColorName extracts the base color name from a Tailwind class e.g., "bg-red-500" -> "red", "text-blue-300" -> "blue"
func GetTailwindShade ¶
GetTailwindShade extracts the shade from a Tailwind color class e.g., "bg-red-500" -> "500", "blue-300" -> "300", "green" -> "500" (default)
func IsTailwindColor ¶
IsTailwindColor checks if a string is a valid Tailwind color class
func IsTextUtilityClass ¶
IsTextUtilityClass checks if a text- prefixed class is a utility rather than a color
func MergeClasses ¶
MergeClasses is a convenience function for merging base and override classes
func MergePadding ¶
func MergePadding(existing, new struct{ Top, Right, Bottom, Left *float64 }) struct{ Top, Right, Bottom, Left *float64 }
MergePadding merges padding values, with later values overriding earlier ones nil values don't override existing values
func MergeStyles ¶
MergeStyles is the public API for merging style strings
func ParseFontSize ¶
ParseFontSize parses a Tailwind font size utility class Returns the font size in rem units, or 0 if not a font size class
func ParsePadding ¶
ParsePadding parses a Tailwind padding utility class Returns padding values in rem units for each side (top, right, bottom, left) Returns nil values for sides that are not set
func ParseRawTailwindColor ¶
ParseRawTailwindColor parses a Tailwind color class and returns the raw hex color value without any background adaptation. This is used for getting the original Tailwind color values.
func ParseTailwindColor ¶
ParseTailwindColor parses a Tailwind color class and returns the hex color value with adaptive color adjustment for terminal background. Supports formats like: - "red-500" -> base color with shade - "bg-blue-700" -> background color prefix - "text-green-300" -> text color prefix - "border-gray-400" -> border color prefix - "red" -> defaults to 500 shade - "black", "white", "transparent" -> special colors
func ResolveLayoutFromStyle ¶
func ResolveLayoutFromStyle(style string) (*WidthSpec, ParsedAlignment)
ResolveLayoutFromStyle extracts width and alignment from a style string This avoids import cycles by not depending on api.Class
func TransformText ¶
TransformText applies text transformation based on the transform type
func TruncateForAppend ¶
func TruncateText ¶
TruncateText truncates text based on line and width constraints maxLines: maximum number of lines (0 = no limit) maxWidth: maximum character width (0 = no limit) mode: "suffix" (ellipsis at end), "prefix" (ellipsis at start), "headtail" (first N + last N lines), or "" (no truncation) Returns truncated text with ellipsis if constraints exceeded
Types ¶
type Alignment ¶
type Alignment string
Type is a representation of a column align.
const ( // Left represents a left horizontal align. Left Alignment = "L" // Right represents a right horizontal align. Right Alignment = "R" // Center represents a center horizontal and/or vertical align. Center Alignment = "C" // Top represents a top vertical align. Top Alignment = "T" // Bottom represents a bottom vertical align. Bottom Alignment = "B" // Middle represents a middle align (from gofpdf). Middle Alignment = "M" // Justify represents a horizontal alignment that distributes // the text evenly between the left and right margins. Justify Alignment = "J" )
type AlignmentParser ¶
type AlignmentParser struct{}
AlignmentParser handles parsing of Tailwind alignment classes
func NewAlignmentParser ¶
func NewAlignmentParser() *AlignmentParser
NewAlignmentParser creates a new alignment parser
func (*AlignmentParser) ParseAlignment ¶
func (ap *AlignmentParser) ParseAlignment(style string) ParsedAlignment
ParseAlignment extracts alignment information from a style string
type BorderColor ¶
Border structs to avoid import cycle
type Borders ¶
func NewDashedBorder ¶
func NewDashedBorder(width float64, color BorderColor) Borders
NewDashedBorder creates a dashed border with specified width and color
func NewLeftRightBorder ¶
func NewLeftRightBorder(width float64, color BorderColor, style LineStyle) Borders
NewLeftRightBorder creates borders only on left and right
func NewSolidBorder ¶
func NewSolidBorder(width float64, color BorderColor) Borders
NewSolidBorder creates a solid border with specified width and color
func NewTopBottomBorder ¶
func NewTopBottomBorder(width float64, color BorderColor, style LineStyle) Borders
NewTopBottomBorder creates borders only on top and bottom
func ParseBorders ¶
ParseBorders parses Tailwind border classes and returns a Borders struct Supports: - Width: border, border-0, border-2, border-4, border-8, border-[3px] - Style: border-solid, border-dashed, border-dotted, border-double, border-none - Color: border-gray-700, border-red-500, etc. - Side-specific: border-t-2, border-r-0, border-b-4, border-l-2 - Combined: border-t-2 border-t-gray-500 border-t-dashed
type Line ¶
type Line struct {
Color BorderColor
Style LineStyle
Width float64
}
type PaddingValue ¶
PaddingValue represents padding for a single side
type ParsedAlignment ¶
type ParsedAlignment struct {
Horizontal Alignment
Vertical VerticalAlign
}
ParsedAlignment contains both horizontal and vertical alignment information
func ParseAlignment ¶
func ParseAlignment(style string) ParsedAlignment
ParseAlignment is the public API for parsing alignment from style strings
type Style ¶
type Style struct {
// Text styling
Foreground string // Text color
Background string // Background color
Bold bool // Bold text
Faint bool // Faint text
Italic bool // Italic text
Underline bool // Underlined text
Strikethrough bool // Strikethrough text
// Layout
MaxWidth int // Maximum width (character count for truncation)
MaxLines int // Maximum lines (line count for truncation)
// Text transformation (not in lipgloss, but handled separately)
TextTransform string
TruncateMode string // "suffix" (ellipsis at end), "prefix" (ellipsis at start), "headtail" (first N + last N lines), or "" (no truncation)
}
Style represents a parsed Tailwind style with transform info This mirrors the key fields from lipgloss.Style without importing lipgloss
func ApplyStyle ¶
ApplyStyle applies a Tailwind style string to text, including text transforms
func ParseStyle ¶
ParseStyle parses a Tailwind style string and returns a Style struct
type StyleMerger ¶
type StyleMerger struct{}
StyleMerger handles merging of Tailwind class strings with conflict resolution
func (*StyleMerger) MergeStyles ¶
func (sm *StyleMerger) MergeStyles(styles ...string) string
MergeStyles combines multiple Tailwind class strings Last class wins for conflicting properties (e.g., text-red-500 overrides text-blue-500)
type VerticalAlign ¶
type VerticalAlign int
VerticalAlign represents vertical alignment options
const ( VerticalTop VerticalAlign = iota VerticalMiddle VerticalBottom )
type WidthParser ¶
type WidthParser struct {
// contains filtered or unexported fields
}
WidthParser handles parsing of Tailwind width classes
func NewWidthParser ¶
func NewWidthParser() *WidthParser
NewWidthParser creates a new width parser with compiled regex patterns
func (*WidthParser) ParseWidth ¶
func (wp *WidthParser) ParseWidth(class string) (*WidthSpec, bool)
ParseWidth parses a single width class and returns the specification
func (*WidthParser) ParseWidthFromStyle ¶
func (wp *WidthParser) ParseWidthFromStyle(style string) *WidthSpec
ParseWidthFromStyle extracts the last width specification from a style string
type WidthSpec ¶
type WidthSpec struct {
Type WidthType
Value float64
Unit string
IsMin bool // min-w-[...]
IsMax bool // max-w-[...]
Original string // Original class for debugging
}
WidthSpec represents a parsed width specification
func ParseWidth ¶
ParseWidth is the public API for parsing width classes
func ParseWidthFromStyle ¶
ParseWidthFromStyle is the public API for extracting width from style strings