SassCalculation

Swift
public final class SassCalculation: SassValue

A Sass calculation value.

These correspond to Sass calc(), min(), max(), or clamp() expressions. See the Sass docs.

The Sass compiler simplifies these before sending them to custom functions: this means that if you receive a SassCalculation argument then it cannot be further simplified at compile time, for example calc(20px + 30%).

The API here allows you to construct SassCalculations representing calc()-type expressions including invalid ones such as calc(20px, 30px) as though you were writing a stylesheet. The validity is checked – and the overall expression simplified – by the compiler when it receives the value.


Topics

Types

enum Kind

The kind of the SassCalculation expression

Declaration
Swift
public enum Kind: String

enum Operator

Arithmetic operators valid within Value.operation(_:_:_:).

Declaration
Swift
public enum Operator: Character

enum Value

A subexpression of a SassCalculation.

Declaration
Swift
public indirect enum Value: Hashable, Equatable, CustomStringConvertible

Initializers

init(calc: Value)

Create a Sass calc() expression.

Declaration
Swift
public convenience init(calc value: Value)

init(kind: Kind, arguments: [Value])

Create an arbitrary SassCalculation.

Declaration
Swift
public init(kind: Kind, arguments: [Value])

Properties

var kind: Kind

Declaration
Swift
public let kind: Kind

var arguments: [Value]

The SassCalculation’s arguments. The Sass specification says how many are actually valid for each Kind but this API does not check this.

Declaration
Swift
public let arguments: [Value]

Misc

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

Two SassCalculations are equal if they have the same kind and arguments.

There’s no attempt at simplification here – so calc(10px) and calc(5px + 5px) compare as different.

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

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 }

func hash(into: inout Hasher)

Hash the calculation.

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