SassColor

Swift
public final class SassColor: SassValue

A Sass color value.

Color values are originally defined using either the RGB-A, HSL-A, or HWB-A color model, but can be accessed as any: conversions are performed and cached internally.

note

Parameter values follow web standards rather the Apple SDK standards, so for example ‘red’ is modelled as an integer in 0…255.


Topics

Initializers

init(red: Int, green: Int, blue: Int, alpha: Double)

Create a SassColor from RGB and alpha components.

Declaration
Swift
public init(red: Int, green: Int, blue: Int, alpha: Double = 1.0) throws
Parameters
red

Red channel, must be between 0 and 255.

green

Green channel, must be between 0 and 255.

blue

Blue channel, must be between 0 and 255.

alpha

Alpha channel, between 0.0 and 1.0.

Throws

SassFunctionError.channelNotInRange(...) if any parameter is out of range.

init(hue: Double, saturation: Double, lightness: Double, alpha: Double)

Create a SassColor from HSL and alpha components.

Declaration
Swift
public init(
    hue: Double, saturation: Double, lightness: Double, alpha: Double = 1.0)
    throws
Parameters
hue

Hue, from 0 to 360.

saturation

Saturation, from 0 to 100.

lightness

Lightness, from 0 to 100.

alpha

Alpha channel, between 0.0 and 1.0.

Throws

SassFunctionError.channelNotInRange(...) if any parameter is out of range.

init(hue: Double, whiteness: Double, blackness: Double, alpha: Double)

Create a SassColor from HWB and alpha components.

Declaration
Swift
public init(
    hue: Double, whiteness: Double, blackness: Double, alpha: Double = 1.0)
    throws
Parameters
hue

Hue, from 0 to 360.

whiteness

Whiteness, from 0 to 100.

blackness

Blackness, from 0 to 100.

alpha

Alpha channel, between 0.0 and 1.0.

Throws

SassFunctionError.channelNotInRange(...) if any parameter is out of range.

Properties

var red: Int

The red channel, between 0 and 255.

Declaration
Swift
public var red: Int { get }

var green: Int

The green channel, between 0 and 255.

Declaration
Swift
public var green: Int { get }

var blue: Int

The blue channel, between 0 and 255.

Declaration
Swift
public var blue: Int { get }

var hue: Double

The HSL or HWB hue channel, between 0 and 360.

Declaration
Swift
public var hue: Double { get }

var saturation: Double

The HSL saturation channel, between 0 and 100.

Declaration
Swift
public var saturation: Double { get }

var lightness: Double

The HSL lightness channel, between 0 and 100.

Declaration
Swift
public var lightness: Double { get }

var whiteness: Double

The HWB whiteness channel, between 0 and 100.

Declaration
Swift
public var whiteness: Double { get }

var blackness: Double

The HWB blackness channel, between 0 and 100.

Declaration
Swift
public var blackness: Double { get }

var alpha: Double

The alpha channel between 0 and 1.

Declaration
Swift
public var alpha: Double { get }

Channel Modification

func change(red: Int?, green: Int?, blue: Int?, alpha: Double?) -> SassColor

Create a new SassColor by changing some of the RGB-A channels of this color.

Declaration
Swift
public func change(
    red: Int? = nil, green: Int? = nil, blue: Int? = nil, alpha: Double? = nil
) throws -> SassColor

func change(hue: Double?, saturation: Double?, lightness: Double?, alpha: Double?) -> SassColor

Create a new SassColor by changing some of the HSL-A channels of this color.

Declaration
Swift
public func change(
    hue: Double? = nil, saturation: Double? = nil, lightness: Double? = nil,
    alpha: Double? = nil
) throws -> SassColor

func change(hue: Double?, whiteness: Double?, blackness: Double?, alpha: Double?) -> SassColor

Create a new SassColor by changing some of the HWB-A channels of this color.

Declaration
Swift
public func change(
    hue: Double? = nil, whiteness: Double? = nil, blackness: Double? = nil,
    alpha: Double? = nil
) throws -> SassColor

func change(hue: Double) -> SassColor

Create a new SassColor by changing only the hue channel of this color.

Declaration
Swift
public func change(hue: Double) throws -> SassColor

func change(alpha: Double) -> SassColor

Create a new SassColor by changing only the alpha channel of this color.

Declaration
Swift
public func change(alpha: Double) throws -> SassColor

Misc

static func ==(lhs: SassColor, rhs: SassColor) -> Bool

Colors are compared in their RGB-A forms, using only 10 DP for the alpha.

Declaration
Swift
public static func == (lhs: SassColor, rhs: SassColor) -> Bool

func hash(into: inout Hasher)

Hash the color.

Declaration
Swift
public override func hash(into hasher: inout Hasher)

func accept<V, R>(visitor: V) -> R

Take part in the SassValueVisitor protocol.

Declaration
Swift
public override func accept<V, R>(visitor: V) throws -> R
where V: SassValueVisitor, R == V.ReturnType

var description: String

A short description of the value.

Declaration
Swift
public override var description: String { get }