PHP Class SassColour

Provides operations and type testing for Sass colours. 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. Resulting colours are returned as a named colour if possible or #rrggbb. Transparent is a SassColour. Operations on transparent return transparent.
Inheritance: extends SassLiteral
Afficher le fichier Open project: richthegeek/phpsass Class Usage Examples

Méthodes publiques

Свойство Type Description
$_html4Colours reverse array (value => name) of named HTML4 colours
$_svgColours reverse array (value => name) of named SVG1.0 colours
$alpha alpha component. 0 - 1
$blue blue component. 0 - 255
$green green component. 0 - 255
$hsl HSL colour components. Used to check for HSL attributes.
$hue hue component. 0 - 360
$lightness lightness component. 0 - 100
$red red component. 0 - 255
$regex
$rgb RGB colour components. Used to check for RGB attributes.
$saturation saturation component. 0 - 100
$svgColours

Méthodes publiques

Méthode Description
__construct ( mixed $colour ) : SassColour Constructs an RGB or HSL color object, optionally with an alpha channel.
asHex ( $inc_hash = TRUE )
assertValid ( array $colour, boolean $all = true ) : string Asserts that the colour space is valid.
getAlpha ( boolean $value = false ) : float Returns the alpha component (opacity) of this colour.
getBlue ( boolean $value = false ) : integer Returns the blue component of this colour.
getGreen ( boolean $value = false ) : integer Returns the green component of this colour.
getHsl ( ) : array Returns an array with the HSL components of this colour.
getHsla ( ) : array Returns an array with the HSL and alpha components of this colour.
getHue ( boolean $value = false ) : float Returns the hue of this colour.
getLightness ( boolean $value = false ) : float Returns the lightness of this colour.
getRed ( boolean $value = false ) : integer Returns the red component of this colour.
getRgb ( ) : array Returns an array with the RGB components of this colour.
getRgba ( ) : array Returns an array with the RGB and alpha components of this colour.
getSaturation ( boolean $value = false ) : float Returns the saturation of this colour.
getValue ( ) : array 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 ( $p, $q, $t ) Converts from hue to RGB colourspace
isTranslucent ( ) : boolean Returns whether this colour object is translucent; that is, whether the alpha channel is non-1.
isa ( string $subject ) : mixed Returns a value indicating if a token of this type can be matched at the start of the subject string.
length ( )
nth ( $i )
op_bw_and ( mixed $other ) : sassColour Colour bitwise AND
op_bw_or ( mixed $other ) : sassColour Colour bitwise OR
op_bw_xor ( mixed $other ) : sassColour Colour bitwise XOR
op_div ( mixed $other ) : sassColour Colour division
op_minus ( mixed $other ) : sassColour Colour subraction
op_modulo ( mixed $other ) : sassColour Colour modulus
op_not ( ) : sassColour Colour bitwise NOT
op_plus ( $other ) : sassColour Colour addition
op_shiftl ( sassNumber $other ) : sassColour Colour bitwise Shift Left
op_shiftr ( sassNumber $other ) : sassColour Colour bitwise Shift Right
op_times ( $other ) : sassColour 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 ( boolean $css3 = true ) : string Converts the colour to a string.
with ( array $attributes ) Returns a copy of this colour with one or more channels changed.

Method Details

__construct() public méthode

RGB values must be between 0 and 255. Saturation and lightness values must be between 0 and 100. The alpha value must be between 0 and 1. The colour can be specified as: + a string that is an SVG colour or of the form #rgb or #rrggbb + an array with either 'red', 'green', and 'blue' keys, and optionally an alpha key. + an array with 'hue', 'saturation', and 'lightness' keys, and optionally an alpha key. + an array of red, green, and blue values, and optionally an alpha value.
public __construct ( mixed $colour ) : SassColour
$colour mixed the colour
Résultat SassColour

asHex() public méthode

public asHex ( $inc_hash = TRUE )

assertValid() public méthode

Returns the name of the colour space: 'rgb' if red, green, or blue keys given; 'hsl' if hue, saturation or lightness keys given; null if a non-associative array
public assertValid ( array $colour, boolean $all = true ) : string
$colour array the colour to test
$all boolean whether all colour space keys must be given
Résultat string name of the colour space

getAlpha() public méthode

Returns the alpha component (opacity) of this colour.
public getAlpha ( boolean $value = false ) : float
$value boolean
Résultat float the alpha component (opacity) of this colour.

getBlue() public méthode

Returns the blue component of this colour.
public getBlue ( boolean $value = false ) : integer
$value boolean
Résultat integer the blue component of this colour.

getGreen() public méthode

Returns the green component of this colour.
public getGreen ( boolean $value = false ) : integer
$value boolean
Résultat integer the green component of this colour.

getHsl() public méthode

Returns an array with the HSL components of this colour.
public getHsl ( ) : array
Résultat array the HSL components of this colour

getHsla() public méthode

Returns an array with the HSL and alpha components of this colour.
public getHsla ( ) : array
Résultat array the HSL and alpha components of this colour

getHue() public méthode

Returns the hue of this colour.
public getHue ( boolean $value = false ) : float
$value boolean
Résultat float the hue of this colour.

getLightness() public méthode

Returns the lightness of this colour.
public getLightness ( boolean $value = false ) : float
$value boolean
Résultat float the lightness of this colour.

getRed() public méthode

Returns the red component of this colour.
public getRed ( boolean $value = false ) : integer
$value boolean
Résultat integer the red component of this colour.

getRgb() public méthode

Returns an array with the RGB components of this colour.
public getRgb ( ) : array
Résultat array the RGB components of this colour

getRgba() public méthode

Returns an array with the RGB and alpha components of this colour.
public getRgba ( ) : array
Résultat array the RGB and alpha components of this colour

getSaturation() public méthode

Returns the saturation of this colour.
public getSaturation ( boolean $value = false ) : float
$value boolean
Résultat float the saturation of this colour.

getValue() public méthode

Returns the value of this colour.
Deprecation:
public getValue ( ) : array
Résultat array the colour

hsl2rgb() public méthode

Converts from HSL to RGB colourspace Algorithm from the CSS3 spec: {@link http://www.w3.org/TR/css3-color/#hsl-color}
public hsl2rgb ( )

hue2rgb() public méthode

Converts from hue to RGB colourspace
public hue2rgb ( $p, $q, $t )

isTranslucent() public méthode

Returns whether this colour object is translucent; that is, whether the alpha channel is non-1.
public isTranslucent ( ) : boolean
Résultat boolean true if this colour is translucent, false if not

isa() public static méthode

Returns a value indicating if a token of this type can be matched at the start of the subject string.
public static isa ( string $subject ) : mixed
$subject string the subject string
Résultat mixed match at the start of the string or false if no match

length() public méthode

public length ( )

nth() public méthode

public nth ( $i )

op_bw_and() public méthode

Colour bitwise AND
public op_bw_and ( mixed $other ) : sassColour
$other mixed value (SassColour or SassNumber) to bitwise AND with
Résultat sassColour the colour result

op_bw_or() public méthode

Colour bitwise OR
public op_bw_or ( mixed $other ) : sassColour
$other mixed value (SassColour or SassNumber) to bitwise OR with
Résultat sassColour the colour result

op_bw_xor() public méthode

Colour bitwise XOR
public op_bw_xor ( mixed $other ) : sassColour
$other mixed value (SassColour or SassNumber) to bitwise XOR with
Résultat sassColour the colour result

op_div() public méthode

Colour division
public op_div ( mixed $other ) : sassColour
$other mixed value (SassColour or SassNumber) to divide by
Résultat sassColour the colour result

op_minus() public méthode

Colour subraction
public op_minus ( mixed $other ) : sassColour
$other mixed value (SassColour or SassNumber) to subtract
Résultat sassColour the colour result

op_modulo() public méthode

Colour modulus
public op_modulo ( mixed $other ) : sassColour
$other mixed value (SassColour or SassNumber) to divide by
Résultat sassColour the colour result

op_not() public méthode

Colour bitwise NOT
public op_not ( ) : sassColour
Résultat sassColour the colour result

op_plus() public méthode

Colour addition
public op_plus ( $other ) : sassColour
Résultat sassColour the colour result

op_shiftl() public méthode

Colour bitwise Shift Left
public op_shiftl ( sassNumber $other ) : sassColour
$other sassNumber amount to shift left by
Résultat sassColour the colour result

op_shiftr() public méthode

Colour bitwise Shift Right
public op_shiftr ( sassNumber $other ) : sassColour
$other sassNumber amount to shift right by
Résultat sassColour the colour result

op_times() public méthode

Colour multiplication
public op_times ( $other ) : sassColour
Résultat sassColour the colour result

rgb2hsl() public méthode

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}
public rgb2hsl ( )

toString() public méthode

Converts the colour to a string.
public toString ( boolean $css3 = true ) : string
$css3 boolean whether to use CSS3 SVG1.0 colour names
Résultat string the colour as a named colour, rgba(r,g,g,a) or #rrggbb

with() public méthode

RGB or HSL attributes may be changed, but not both at once.
public with ( array $attributes )
$attributes array attributes to change

Property Details

$_html4Colours public_oe static_oe property

reverse array (value => name) of named HTML4 colours
public static $_html4Colours

$_svgColours public_oe static_oe property

reverse array (value => name) of named SVG1.0 colours
public static $_svgColours

$alpha public_oe property

alpha component. 0 - 1
public $alpha

$blue public_oe property

blue component. 0 - 255
public $blue

$green public_oe property

green component. 0 - 255
public $green

$hsl public_oe static_oe property

HSL colour components. Used to check for HSL attributes.
public static $hsl

$hue public_oe property

hue component. 0 - 360
public $hue

$lightness public_oe property

lightness component. 0 - 100
public $lightness

$red public_oe property

red component. 0 - 255
public $red

$regex public_oe static_oe property

public static $regex

$rgb public_oe static_oe property

RGB colour components. Used to check for RGB attributes.
public static $rgb

$saturation public_oe property

saturation component. 0 - 100
public $saturation

$svgColours public_oe static_oe property

public static $svgColours