Swift Only

hue

Pool

Modern Swift color utilities with hex parsing, HSL conversion, WCAG accessibility, color theory, and platform bridging

$ lpm install @lpm.dev/swiftd.hue
21 exportsAI-Generated

These docs were generated by AI and may not be fully accurate.

Sources/Hue/Hue.swift

Classes

Hueimplements Sendable, Equatable, Hashable, Codable

A modern, type-safe color representation with hex parsing, HSL conversion, WCAG accessibility, and platform bridging.

constructor(red: Double, green: Double, blue: Double, alpha?: Double)
PropertyTypeDescription
red
DoubleRed component (0.0–1.0)
green
DoubleGreen component (0.0–1.0)
blue
DoubleBlue component (0.0–1.0)
alpha
DoubleAlpha component (0.0–1.0)
black
HuePure black (#000000)
white
HuePure white (#FFFFFF)
red
HuePure red (#FF0000)
green
HuePure green (#00FF00)
blue
HuePure blue (#0000FF)
clear
HueFully transparent black
description
StringTextual representation as hex string

Sources/Hue/Hue+Components.swift

Classes

Hue

Component accessor extensions for Hue.

MethodReturn TypeDescription
withAlpha(alpha)HueReturns a new color with the specified alpha value.
withRed(red)HueReturns a new color with the specified red component.
withGreen(green)HueReturns a new color with the specified green component.
withBlue(blue)HueReturns a new color with the specified blue component.
PropertyTypeDescription
rgba
(red: Double, green: Double, blue: Double, alpha: Double)The RGBA components as a tuple.

Sources/Hue/Hue+Accessibility.swift

Classes

Hue

WCAG accessibility extensions for Hue.

MethodReturn TypeDescription
contrastRatio(other)DoubleCalculates the contrast ratio between this color and another (1.0–21.0).
meetsWCAG(level, size, against)BoolChecks whether this color meets WCAG contrast requirements against another color.
bestTextColor(from)HueReturns the candidate color with the best contrast against this color.
PropertyTypeDescription
relativeLuminance
DoubleThe relative luminance of the color per WCAG 2.0.
isLight
BoolWhether the color is perceived as light (luminance > 0.5).
isDark
BoolWhether the color is perceived as dark (luminance ≤ 0.5).

Enums

WCAGLevel

WCAG conformance levels.

MemberValue
aanull
aaanull
WCAGTextSize

WCAG text size categories.

MemberValue
normalnull
largenull

Sources/Hue/Hue+Hex.swift

Functions

init(hex:)
function init(hex:)(hex: String): Hue

Creates a color from a hex string. Supports #RGB, #RRGGBB, #RRGGBBAA formats.

ParameterTypeDescription
hex
StringA hex color string
init(hex:)
function init(hex:)(hex: UInt32): Hue

Creates a color from a 24-bit RGB hex integer.

ParameterTypeDescription
hex
UInt32A 24-bit RGB hex value

Classes

Hue

Hex parsing extensions for Hue.

MethodReturn TypeDescription
toHex(includeAlpha)StringConverts the color to a hex string with # prefix.

Sources/Hue/Hue+HSL.swift

Functions

init(hue:saturation:lightness:alpha:)
function init(hue:saturation:lightness:alpha:)(hue: Double, saturation: Double, lightness: Double, alpha?: Double): Hue

Creates a color from HSL components.

ParameterTypeDescription
hue
DoubleHue angle in degrees (0–360)
saturation
DoubleSaturation (0.0–1.0)
lightness
DoubleLightness (0.0–1.0)
alphaoptional
DoubleAlpha (0.0–1.0). Defaults to 1.0

Classes

Hue

HSL conversion extensions for Hue.

PropertyTypeDescription
hue
DoubleThe hue angle in degrees (0–360).
saturation
DoubleThe HSL saturation (0.0–1.0).
lightness
DoubleThe HSL lightness (0.0–1.0).
hsla
(hue: Double, saturation: Double, lightness: Double, alpha: Double)The HSLA components as a tuple.

Sources/Hue/Hue+Manipulation.swift

Classes

Hue

Color manipulation extensions for Hue.

MethodReturn TypeDescription
lighter(by)HueReturns a lighter version of the color.
darker(by)HueReturns a darker version of the color.
saturated(by)HueReturns a more saturated version of the color.
desaturated(by)HueReturns a less saturated version of the color.
adjustHue(by)HueReturns a color with the hue rotated by the given degrees.
inverted()HueReturns the inverted (RGB complement) color.
grayscale()HueReturns a grayscale version of the color.

Sources/Hue/Hue+Mixing.swift

Classes

Hue

Color mixing extensions for Hue.

MethodReturn TypeDescription
mixed(with, amount)HueMixes this color with another using linear interpolation.

Sources/Hue/Hue+ColorTheory.swift

Classes

Hue

Color theory extensions for Hue.

PropertyTypeDescription
complementary
HueThe complementary color (hue rotated 180 degrees).
analogous
(Hue, Hue)The two analogous colors (hue ±30 degrees).
triadic
(Hue, Hue)The two triadic colors (hue ±120 degrees).
splitComplementary
(Hue, Hue)The two split-complementary colors (150° and 210°).
tetradic
(Hue, Hue, Hue)The three tetradic colors (90°, 180°, 270°).

Sources/Hue/Hue+SwiftUI.swift

Functions

init(hex:)
function init(hex:)(hex: String): Color

Creates a SwiftUI Color from a hex string.

ParameterTypeDescription
hex
StringA hex color string (#RGB, #RRGGBB, or #RRGGBBAA)
init(_:)
function init(_:)(hue: Hue): Color

Creates a SwiftUI Color from a Hue value.

ParameterTypeDescription
hue
HueA Hue color value

Classes

Hue

SwiftUI integration extensions for Hue.

PropertyTypeDescription
color
ColorConverts to a SwiftUI Color.
Color

SwiftUI Color extensions for Hue integration.

Sources/Hue/Hue+Platform.swift

Functions

init(cgColor:)
function init(cgColor:)(cgColor: CGColor): Hue

Creates a Hue from a CGColor.

ParameterTypeDescription
cgColor
CGColorA Core Graphics color
init(uiColor:)
function init(uiColor:)(uiColor: UIColor): Hue

Creates a Hue from a UIColor (iOS/watchOS/tvOS/visionOS only).

ParameterTypeDescription
uiColor
UIColorA UIKit color
init(nsColor:)
function init(nsColor:)(nsColor: NSColor): Hue

Creates a Hue from an NSColor (macOS only).

ParameterTypeDescription
nsColor
NSColorAn AppKit color

Classes

Hue

Platform bridging extensions for Hue.

PropertyTypeDescription
cgColor
CGColorConverts to a CGColor.
uiColor
UIColorConverts to a UIColor (iOS/watchOS/tvOS/visionOS only).
nsColor
NSColorConverts to an NSColor (macOS only).
Unlimited AccessInstall as many Pool packages as you need.
Fund Real WorkEvery install you run sends revenue directly to the developer who built it.

Taxes calculated at checkout based on your location.

Weekly Installs
1
Version
1.0.2
Published
LicenseMIT
Size106.51 KB
Files28
Swift Tools5.9.0
Platforms
iOS 13.0+macOS 10.15+watchOS 6.0+tvOS 13.0+visionOS 1.0+