\SassColour
SassColour class.
A SassScript object representing a CSS colour.
A colour may be represented internally as RGBA, HSLA, or both. It is
originally represented as whatever its input is; if it’s created with RGB
values, it’s represented as RGBA, and if it’s created with HSL values, it’s
represented as HSLA. Once a property is accessed that requires the other
representation – for example, SassColour::red for an HSL color – that
component is calculated and cached.
The alpha channel of a color is independent of its RGB or HSL representation.
It’s always stored, as 1 if nothing else is specified. If only the alpha
channel is modified using SassColour::with(), the cached RGB and HSL values
are retained.
Colour operations are all piecewise, e.g. when adding two colours each
component is added independantly; Rr = R1 + R2, Gr = G1 + G2, Br = B1 + B2.
Colours are returned as a named colour if possible or #rrggbb.
Synopsis
- // constants
- const MATCH = '/^((#([\da-f]{6}|[\da-f]{3}))|transparent|{CSS_COLOURS})/';
- const EXTRACT_3 = '/#([\da-f])([\da-f])([\da-f])/';
- const EXTRACT_6 = '/#([\da-f]{2})([\da-f]{2})([\da-f]{2})/';
- const TRANSPARENT = 'transparent';
- // members
- public static array $svgColours = ;
- public static $_svgColours;
- public static array $_html4Colours = ;
- public static $regex;
- public static array $rgb = ;
- public $red;
- public $green;
- public $blue;
- public static array $hsl = ;
- public $hue;
- public $saturation;
- public $lightness;
- public integer $alpha = 1;
- // methods
- public SassColour __construct()
- public sassColour op_plus()
- public sassColour op_minus()
- public sassColour op_times()
- public sassColour op_div()
- public sassColour op_modulo()
- public sassColour op_bw_and()
- public sassColour op_bw_or()
- public sassColour op_bw_xor()
- public sassColour op_not()
- public sassColour op_shiftl()
- public sassColour op_shiftr()
- public void with()
- public float getAlpha()
- public float getHue()
- public float getSaturation()
- public float getLightness()
- public integer getBlue()
- public integer getGreen()
- public integer getRed()
- public array getRgb()
- public array getRgba()
- public array getHsl()
- public array getHsla()
- public array getValue()
- public boolean isTranslucent()
- public string toString()
- public void asHex()
- public void hsl2rgb()
- public void hue2rgb()
- public void rgb2hsl()
- public string assertValid()
- public static mixed isa()
- // Inherited methods from SassLiteral
- public SassLiteral __construct()
- public mixed __get()
- public void __toString()
- public boolean toBoolean()
- public string getTypeOf()
- public mixed getValue()
- public void getChildren()
- public void addChild()
- public sassString op_plus()
- public sassString op_minus()
- public sassString op_times()
- public sassString op_div()
- public SassLiteral op_modulo()
- public string op_bw_and()
- public string op_bw_or()
- public string op_bw_xor()
- public string op_bw_not()
- public string op_shiftl()
- public string op_shiftr()
- public SassLiteral op_and()
- public SassLiteral op_or()
- public void op_assign()
- public SassBoolean op_xor()
- public SassBoolean op_not()
- public SassBoolean op_gt()
- public SassBoolean op_gte()
- public SassBoolean op_lt()
- public SassBoolean op_lte()
- public SassBoolean op_eq()
- public SassBoolean op_neq()
- public sassString op_concat()
- public sassString op_comma()
- public static void assertType()
- public static void assertInRange()
- public abstract string toString()
- public void render()
- public static mixed isa()
Hierarchy
Extends
Constants
Name | Value |
---|---|
MATCH | '/^((#([\da-f]{6}|[\da-f]{3}))|transparent|{CSS_COLOURS})/' |
EXTRACT_3 | '/#([\da-f])([\da-f])([\da-f])/' |
EXTRACT_6 | '/#([\da-f]{2})([\da-f]{2})([\da-f]{2})/' |
TRANSPARENT | 'transparent' |
Members
public
- $_html4Colours — array
- $_svgColours — array
- $alpha — float
- $blue — integer
- $green — integer
- $hsl — array
- $hue — float
- $lightness — float
- $red — integer
- $regex
- $rgb — array
- $saturation — float
- $svgColours
- $typeOf — array
- $value — mixed
Methods
public
- __construct() — Constructs an RGB or HSL color object, optionally with an alpha channel.
- asHex()
- assertValid() — Asserts that the colour space is valid.
- getAlpha() — Returns the alpha component (opacity) of this colour.
- getBlue() — Returns the blue component of this colour.
- getGreen() — Returns the green component of this colour.
- getHsl() — Returns an array with the HSL components of this colour.
- getHsla() — Returns an array with the HSL and alpha components of this colour.
- getHue() — Returns the hue of this colour.
- getLightness() — Returns the lightness of this colour.
- getRed() — Returns the red component of this colour.
- getRgb() — Returns an array with the RGB components of this colour.
- getRgba() — Returns an array with the RGB and alpha components of this colour.
- getSaturation() — Returns the saturation of this colour.
- getValue() — Returns the value of this colour.
- hsl2rgb() — Converts from HSL to RGB colourspace Algorithm from the CSS3 spec: {@link http://www.w3.org/TR/css3-color/#hsl-color}
- hue2rgb() — Converts from hue to RGB colourspace
- isTranslucent() — Returns whether this colour object is translucent; that is, whether the alpha channel is non-1.
- isa() — Returns a value indicating if a token of this type can be matched at the start of the subject string.
- op_bw_and() — Colour bitwise AND
- op_bw_or() — Colour bitwise OR
- op_bw_xor() — Colour bitwise XOR
- op_div() — Colour division
- op_minus() — Colour subraction
- op_modulo() — Colour modulus
- op_not() — Colour bitwise NOT
- op_plus() — Colour addition
- op_shiftl() — Colour bitwise Shift Left
- op_shiftr() — Colour bitwise Shift Right
- op_times() — Colour multiplication
- rgb2hsl() — Converts from RGB to HSL colourspace Algorithm adapted from {@link http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript}
- toString() — Converts the colour to a string.
- with() — Returns a copy of this colour with one or more channels changed.
Inherited from SassLiteral
public
- __get() — Getter.
- __toString()
- addChild() — Adds a child object to this.
- assertInRange() — Asserts that the value of a literal is within the expected range
- assertType() — Asserts that the literal is the expected type
- getChildren()
- getTypeOf() — Returns the type of this
- getValue() — Returns the value of this
- isa() — Returns a value indicating if a token of this type can be matched at the start of the subject string.
- op_and() — The SassScript and operation.
- op_assign()
- op_bw_and() — Bitwise AND the value of other and this value
- op_bw_not() — Bitwise NOT the value of other and the value of this
- op_bw_or() — Bitwise OR the value of other and this value
- op_bw_xor() — Bitwise XOR the value of other and the value of this
- op_comma() — SassScript ',' operation.
- op_concat() — The SassScript default operation (e.g. $a $b, "foo" "bar").
- op_div() — SassScript '/' operation.
- op_eq() — The SassScript == operation.
- op_gt() — The SassScript > operation.
- op_gte() — The SassScript >= operation.
- op_lt() — The SassScript < operation.
- op_lte() — The SassScript <= operation.
- op_minus() — SassScript '-' operation.
- op_modulo() — SassScript '%' operation.
- op_neq() — The SassScript != operation.
- op_not() — The SassScript not operation.
- op_or() — The SassScript or operation.
- op_plus() — SassScript '+' operation.
- op_shiftl() — Shifts the value of this left by the number of bits given in value
- op_shiftr() — Shifts the value of this right by the number of bits given in value
- op_times() — SassScript '*' operation.
- op_xor() — The SassScript xor operation.
- render()
- toBoolean() — Returns the boolean representation of the value of this
- toString() — Returns a string representation of the value.