functions

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// BaseDir is set by the renderer to enable resolving relative image paths
	BaseDir string
)

Functions

func ARGB

func ARGB(colorStr string) string

ARGB returns a color in #ARGB format (alpha in first position)

func Abs

func Abs(value string) string

Abs returns the absolute value

func Acos

func Acos(value string) string

Acos returns the arccosine of a number (in radians)

func Alpha

func Alpha(colorStr string) string

Alpha extracts the alpha channel (0-1) from a color

func Asin

func Asin(value string) string

Asin returns the arcsine of a number (in radians)

func Atan

func Atan(value string) string

Atan returns the arctangent of a number (in radians)

func Average

func Average(color1Str, color2Str string) string

Average blends two colors using average mode

func Blue

func Blue(colorStr string) string

Blue extracts the blue channel (0-255) from a color

func Boolean

func Boolean(value string) string

Boolean converts a value to a boolean In LESS, only the literal keyword "true" returns true; everything else is false

func Ceil

func Ceil(value string) string

Ceil returns the smallest integer >= x

func ClearImageDimCache

func ClearImageDimCache()

ClearImageDimCache clears the image dimension cache (useful for testing)

func ColorFunction

func ColorFunction(colorStr string) string

ColorFunction parses a string as a color

func Contrast

func Contrast(colorStr string, args ...string) string

Contrast returns the dark or light color with greatest contrast

func Convert

func Convert(value string, targetUnit string) string

Convert converts a number to a different unit Supports: px, cm, mm, in, pt, pc, em, ex, ch, rem, vw, vh, vmin, vmax, %

func Cos

func Cos(value string) string

Cos returns the cosine of a number (in radians)

func Darken

func Darken(colorStr, amount string) string

Darken darkens a color by a percentage

func Desaturate

func Desaturate(colorStr, amount string) string

Desaturate decreases saturation

func Difference

func Difference(color1Str, color2Str string) string

Difference blends two colors using difference mode

func E

func E(str string) string

E returns the escaped string (similar to escape but used in LESS for removing quotes)

func Escape

func Escape(str string) string

Escape URL-encodes a string (using strict LESS escaping rules) LESS escape() does NOT escape all special characters - only specific ones

func EvaluateExpression

func EvaluateExpression(expr string) string

EvaluateExpression evaluates a mathematical expression with units e.g., "10px * 2" -> "20px", "20px - 5px" -> "15px"

func Exclusion

func Exclusion(color1Str, color2Str string) string

Exclusion blends two colors using exclusion mode

func Extract

func Extract(args ...string) string

Extract gets an item from a list by index (1-based) Can be called as extract(list, index) or extract(item1, item2, item3, index)

func Fade

func Fade(colorStr, amount string) string

Fade sets the opacity of a color (0-100%)

func Fadein

func Fadein(colorStr, amount string) string

Fadein increases opacity

func Fadeout

func Fadeout(colorStr, amount string) string

Fadeout decreases opacity

func Floor

func Floor(value string) string

Floor returns the largest integer <= x

func Format

func Format(format string, args ...string) string

Format string - simple % formatting similar to LESS

func GetUnit

func GetUnit(value string) string

GetUnit returns the unit of a dimension as a string (without quotes)

func Green

func Green(colorStr string) string

Green extracts the green channel (0-255) from a color

func Greyscale

func Greyscale(colorStr string) string

Greyscale returns the greyscale version of the color

func HSL

func HSL(h, s, l string) string

HSL creates a color from HSL components (hue 0-360, saturation 0-100, lightness 0-100) Returns in hsl() format, not hex

func HSLA

func HSLA(h, s, l, a string) string

HSLA creates a color from HSLA components (hue 0-360, saturation 0-100, lightness 0-100, alpha 0-1) Returns in hsla() format

func HSV

func HSV(h, s, v string) string

HSV creates a color from HSV values, returning it as hex

func HSVA

func HSVA(h, s, v, a string) string

HSVA creates a color from HSVA values, returning it as rgba

func HSVHue

func HSVHue(colorStr string) string

HSVHue extracts the hue from a color

func HSVSaturation

func HSVSaturation(colorStr string) string

HSVSaturation extracts the saturation from a color (HSV saturation)

func HSVValue

func HSVValue(colorStr string) string

HSVValue extracts the value (brightness) from a color (HSV value)

func Hardlight

func Hardlight(color1Str, color2Str string) string

Hardlight blends two colors using hard light mode

func Hue

func Hue(colorStr string) string

Hue extracts the hue component (0-360) from a color

func If

func If(condition string, valueIfTrue string, valueIfFalse string) string

If - logical conditional function if(condition, value-if-true, value-if-false)

func ImageHeight

func ImageHeight(filePath string) (string, error)

ImageHeight returns the height of an image file in pixels

func ImageSize

func ImageSize(filePath string) (string, error)

ImageSize returns both width and height as a space-separated string

func ImageWidth

func ImageWidth(filePath string) (string, error)

ImageWidth returns the width of an image file in pixels

func IsColor

func IsColor(value string) bool

IsColor checks if a value is a color

func IsColorFunction

func IsColorFunction(value string) string

IsColorFunction is the exposed function for iscolor()

func IsDefined

func IsDefined(varName string) bool

IsDefined checks if a variable is defined (this requires context) For now, return false as this needs renderer context

func IsEm

func IsEm(value string) bool

IsEm checks if a value is in em units

func IsEmFunction

func IsEmFunction(value string) string

IsEmFunction is the exposed function for isem()

func IsKeyword

func IsKeyword(value string) bool

IsKeyword checks if a value is a keyword In LESS, any bare word/identifier (not a number, color, or string) is a keyword

func IsKeywordFunction

func IsKeywordFunction(value string) string

IsKeywordFunction is the exposed function for iskeyword()

func IsList

func IsList(value string) bool

IsList checks if a value is a list (comma or space-separated values)

func IsListFunction

func IsListFunction(value string) string

IsListFunction is the exposed function for islist()

func IsNumber

func IsNumber(value string) bool

IsNumber checks if a value is a number (with optional unit)

func IsNumberFunction

func IsNumberFunction(value string) string

IsNumberFunction is the exposed function for isnumber()

func IsPercentage

func IsPercentage(value string) bool

IsPercentage checks if a value is a percentage

func IsPercentageFunction

func IsPercentageFunction(value string) string

IsPercentageFunction is the exposed function for ispercentage()

func IsPixel

func IsPixel(value string) bool

IsPixel checks if a value is in pixels

func IsPixelFunction

func IsPixelFunction(value string) string

IsPixelFunction is the exposed function for ispixel()

func IsRuleset

func IsRuleset(value string) bool

IsRuleset checks if a value is a ruleset/object (stored in a variable) This would need context from the renderer to properly determine

func IsRulesetFunction

func IsRulesetFunction(value string) string

IsRulesetFunction is the exposed function for isruleset()

func IsString

func IsString(value string) bool

IsString checks if a value is a string literal

func IsStringFunction

func IsStringFunction(value string) string

IsStringFunction is the exposed function for isstring()

func IsURL

func IsURL(value string) bool

IsURL checks if a value is a URL

func IsURLFunction

func IsURLFunction(value string) string

IsURLFunction is the exposed function for isurl()

func IsUnit

func IsUnit(value string, unit string) bool

IsUnit checks if a value has the specified unit

func IsUnitFunction

func IsUnitFunction(value string, unit string) string

IsUnitFunction is the exposed function for isunit()

func Length

func Length(values ...string) string

Length returns the length of a list/string value In LESS, quoted strings count as a single item (length 1), not character count Can be called as length(value) or length(item1, item2, item3) where items form a list

func Lighten

func Lighten(colorStr, amount string) string

Lighten lightens a color by a percentage

func Lightness

func Lightness(colorStr string) string

Lightness extracts the lightness component (0-100) from a color

func LumaFunction

func LumaFunction(colorStr string) string

LumaFunction returns the perceived brightness (luminance) of a color as a string

func Luminance

func Luminance(colorStr string) string

Luminance calculates the luminance of a color (without gamma correction)

func Max

func Max(values ...string) string

Max returns the maximum of the provided values

func Min

func Min(values ...string) string

Min returns the minimum of the provided values

func Mix

func Mix(color1Str, color2Str string, args ...string) string

Mix mixes two colors

func Mod

func Mod(a, b string) string

Mod returns the remainder of a / b

func Multiply

func Multiply(color1Str, color2Str string) string

Multiply blends two colors using multiply mode

func Negation

func Negation(color1Str, color2Str string) string

Negation blends two colors using negation mode

func Overlay

func Overlay(color1Str, color2Str string) string

Overlay blends two colors using overlay mode

func Percentage

func Percentage(value string) string

Percentage converts a decimal number to a percentage

func Pi

func Pi() string

Pi returns the value of pi

func Pow

func Pow(base, exponent string) string

Pow returns base to the power of exponent

func RGB

func RGB(r, g, b string) string

RGB creates a color from RGB components (0-255)

func Range

func Range(args ...string) string

Range generates a comma-separated list of numbers from start to end Supports: range(end), range(start, end), range(start, end, step)

func Red

func Red(colorStr string) string

Red extracts the red channel (0-255) from a color

func Replace

func Replace(str, pattern, replacement string, flags ...string) string

Replace replaces a pattern in a string with a replacement string replace(string, pattern, replacement, flags?)

func Round

func Round(value string) string

Round returns the nearest integer

func Saturate

func Saturate(colorStr, amount string) string

Saturate increases saturation

func Saturation

func Saturation(colorStr string) string

Saturation extracts the saturation component (0-100) from a color

func Screen

func Screen(color1Str, color2Str string) string

Screen blends two colors using screen mode

func Shade

func Shade(colorStr, weight string) string

Shade mixes a color with black

func Sin

func Sin(value string) string

Sin returns the sine of a number (in radians)

func Softlight

func Softlight(color1Str, color2Str string) string

Softlight blends two colors using soft light mode

func Spin

func Spin(colorStr, degrees string) string

Spin rotates the hue

func Sqrt

func Sqrt(value string) string

Sqrt returns the square root

func Tan

func Tan(value string) string

Tan returns the tangent of a number (in radians)

func Tint

func Tint(colorStr, weight string) string

Tint mixes a color with white

func Unit

func Unit(args ...string) string

Unit removes or changes the unit of a dimension unit(value) returns dimensionless number unit(value, newUnit) returns the number part of value with the new unit

Types

type Color

type Color struct {
	R, G, B, A float64 // values 0-255 for RGB, 0-1 for A
}

Color represents an RGBA color

func HSLToColor

func HSLToColor(h, s, l float64, a float64) *Color

HSLToColor converts HSL to RGB Color

func HSVToColor

func HSVToColor(h, s, v float64, a float64) *Color

HSVToColor converts HSV to RGB Color

func ParseColor

func ParseColor(s string) (*Color, error)

ParseColor parses a color from a hex string, rgb(a) function, hsl(a) function, or CSS keyword

func ParseHSL

func ParseHSL(input string) (*Color, error)

ParseHSL parses hsl() or hsla() format

func ParseHex

func ParseHex(hex string) (*Color, error)

ParseHex parses a hex color string (#fff, #ffffff, #rrggbbaa)

func ParseRGB

func ParseRGB(s string) (*Color, error)

ParseRGB parses rgb() or rgba() format

func (*Color) Darken

func (c *Color) Darken(amount float64) *Color

Darken darkens a color by a percentage

func (*Color) Desaturate

func (c *Color) Desaturate(amount float64) *Color

Desaturate decreases saturation

func (*Color) Greyscale

func (c *Color) Greyscale() *Color

Greyscale returns the greyscale version of the color

func (*Color) Lighten

func (c *Color) Lighten(amount float64) *Color

Lighten lightens a color by a percentage

func (*Color) Luma

func (c *Color) Luma() float64

Luma returns the perceived brightness (luminance) of the color as a percentage Uses the formula: luma = 0.2126*R + 0.7152*G + 0.0722*B (relative luminance)

func (*Color) Mix

func (c *Color) Mix(other *Color, weight float64) *Color

Mix mixes two colors

func (*Color) Saturate

func (c *Color) Saturate(amount float64) *Color

Saturate increases saturation

func (*Color) Spin

func (c *Color) Spin(degrees float64) *Color

Spin rotates the hue

func (*Color) ToHSL

func (c *Color) ToHSL() (h, s, l float64)

ToHSL converts RGB to HSL

func (*Color) ToHSV

func (c *Color) ToHSV() (h, s, v float64)

ToHSV converts RGB to HSV

func (*Color) ToHex

func (c *Color) ToHex() string

ToHex returns the color as a hex string

func (*Color) ToRGB

func (c *Color) ToRGB() string

ToRGB returns the color as rgb() or rgba() format

Jump to

Keyboard shortcuts

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