functions.rb (sass-3.5.5) | : | functions.rb (sass-3.5.6) | ||
---|---|---|---|---|
skipping to change at line 656 | skipping to change at line 656 | |||
# Must be between 0 and 255 inclusive, or between `0%` and `100%` | # Must be between 0 and 255 inclusive, or between `0%` and `100%` | |||
# inclusive | # inclusive | |||
# @param $green [Sass::Script::Value::Number] The amount of green in the | # @param $green [Sass::Script::Value::Number] The amount of green in the | |||
# color. Must be between 0 and 255 inclusive, or between `0%` and `100%` | # color. Must be between 0 and 255 inclusive, or between `0%` and `100%` | |||
# inclusive | # inclusive | |||
# @param $blue [Sass::Script::Value::Number] The amount of blue in the | # @param $blue [Sass::Script::Value::Number] The amount of blue in the | |||
# color. Must be between 0 and 255 inclusive, or between `0%` and `100%` | # color. Must be between 0 and 255 inclusive, or between `0%` and `100%` | |||
# inclusive | # inclusive | |||
# @return [Sass::Script::Value::Color] | # @return [Sass::Script::Value::Color] | |||
# @raise [ArgumentError] if any parameter is the wrong type or out of bounds | # @raise [ArgumentError] if any parameter is the wrong type or out of bounds | |||
def rgb(red, green, blue) | def rgb(red, green = nil, blue = nil) | |||
if green.nil? | ||||
return unquoted_string("rgb(#{red})") if var?(red) | ||||
raise ArgumentError.new("wrong number of arguments (1 for 3)") | ||||
elsif blue.nil? | ||||
return unquoted_string("rgb(#{red}, #{green})") if var?(red) || var?(gre | ||||
en) | ||||
raise ArgumentError.new("wrong number of arguments (2 for 3)") | ||||
end | ||||
if special_number?(red) || special_number?(green) || special_number?(blue) | if special_number?(red) || special_number?(green) || special_number?(blue) | |||
return unquoted_string("rgb(#{red}, #{green}, #{blue})") | return unquoted_string("rgb(#{red}, #{green}, #{blue})") | |||
end | end | |||
assert_type red, :Number, :red | assert_type red, :Number, :red | |||
assert_type green, :Number, :green | assert_type green, :Number, :green | |||
assert_type blue, :Number, :blue | assert_type blue, :Number, :blue | |||
color_attrs = [red, green, blue].map do |c| | color_attrs = [red, green, blue].map do |c| | |||
if c.is_unit?("%") | if c.is_unit?("%") | |||
c.value * 255 / 100.0 | c.value * 255 / 100.0 | |||
skipping to change at line 680 | skipping to change at line 688 | |||
raise ArgumentError.new("Expected #{c} to be unitless or have a unit o f % but got #{c}") | raise ArgumentError.new("Expected #{c} to be unitless or have a unit o f % but got #{c}") | |||
end | end | |||
end | end | |||
# Don't store the string representation for function-created colors, both | # Don't store the string representation for function-created colors, both | |||
# because it's not very useful and because some functions aren't supported | # because it's not very useful and because some functions aren't supported | |||
# on older browsers. | # on older browsers. | |||
Sass::Script::Value::Color.new(color_attrs) | Sass::Script::Value::Color.new(color_attrs) | |||
end | end | |||
declare :rgb, [:red, :green, :blue] | declare :rgb, [:red, :green, :blue] | |||
declare :rgb, [:red, :green] | ||||
declare :rgb, [:red] | ||||
# Creates a {Sass::Script::Value::Color Color} from red, green, blue, and | # Creates a {Sass::Script::Value::Color Color} from red, green, blue, and | |||
# alpha values. | # alpha values. | |||
# @see #rgb | # @see #rgb | |||
# | # | |||
# @overload rgba($red, $green, $blue, $alpha) | # @overload rgba($red, $green, $blue, $alpha) | |||
# @param $red [Sass::Script::Value::Number] The amount of red in the | # @param $red [Sass::Script::Value::Number] The amount of red in the | |||
# color. Must be between 0 and 255 inclusive or 0% and 100% inclusive | # color. Must be between 0 and 255 inclusive or 0% and 100% inclusive | |||
# @param $green [Sass::Script::Value::Number] The amount of green in the | # @param $green [Sass::Script::Value::Number] The amount of green in the | |||
# color. Must be between 0 and 255 inclusive or 0% and 100% inclusive | # color. Must be between 0 and 255 inclusive or 0% and 100% inclusive | |||
skipping to change at line 714 | skipping to change at line 724 | |||
# | # | |||
# @param $color [Sass::Script::Value::Color] The color whose opacity will | # @param $color [Sass::Script::Value::Color] The color whose opacity will | |||
# be changed. | # be changed. | |||
# @param $alpha [Sass::Script::Value::Number] The new opacity of the | # @param $alpha [Sass::Script::Value::Number] The new opacity of the | |||
# color. Must be between 0 and 1 inclusive | # color. Must be between 0 and 1 inclusive | |||
# @return [Sass::Script::Value::Color] | # @return [Sass::Script::Value::Color] | |||
# @raise [ArgumentError] if `$alpha` is out of bounds or either parameter | # @raise [ArgumentError] if `$alpha` is out of bounds or either parameter | |||
# is the wrong type | # is the wrong type | |||
def rgba(*args) | def rgba(*args) | |||
case args.size | case args.size | |||
when 1 | ||||
return unquoted_string("rgba(#{args.first})") if var?(args.first) | ||||
raise ArgumentError.new("wrong number of arguments (1 for 4)") | ||||
when 2 | when 2 | |||
color, alpha = args | color, alpha = args | |||
if var?(color) | ||||
return unquoted_string("rgba(#{color}, #{alpha})") | ||||
elsif var?(alpha) | ||||
if color.is_a?(Sass::Script::Value::Color) | ||||
return unquoted_string("rgba(#{color.red}, #{color.green}, #{color.b | ||||
lue}, #{alpha})") | ||||
else | ||||
return unquoted_string("rgba(#{color}, #{alpha})") | ||||
end | ||||
end | ||||
assert_type color, :Color, :color | assert_type color, :Color, :color | |||
if special_number?(alpha) | if special_number?(alpha) | |||
unquoted_string("rgba(#{color.red}, #{color.green}, #{color.blue}, #{a lpha})") | unquoted_string("rgba(#{color.red}, #{color.green}, #{color.blue}, #{a lpha})") | |||
else | else | |||
assert_type alpha, :Number, :alpha | assert_type alpha, :Number, :alpha | |||
check_alpha_unit alpha, 'rgba' | check_alpha_unit alpha, 'rgba' | |||
color.with(:alpha => alpha.value) | color.with(:alpha => alpha.value) | |||
end | end | |||
when 3 | ||||
if var?(args[0]) || var?(args[1]) || var?(args[2]) | ||||
unquoted_string("rgba(#{args.join(', ')})") | ||||
else | ||||
raise ArgumentError.new("wrong number of arguments (3 for 4)") | ||||
end | ||||
when 4 | when 4 | |||
red, green, blue, alpha = args | red, green, blue, alpha = args | |||
if special_number?(red) || special_number?(green) || | if special_number?(red) || special_number?(green) || | |||
special_number?(blue) || special_number?(alpha) | special_number?(blue) || special_number?(alpha) | |||
unquoted_string("rgba(#{red}, #{green}, #{blue}, #{alpha})") | unquoted_string("rgba(#{red}, #{green}, #{blue}, #{alpha})") | |||
else | else | |||
rgba(rgb(red, green, blue), alpha) | rgba(rgb(red, green, blue), alpha) | |||
end | end | |||
else | else | |||
raise ArgumentError.new("wrong number of arguments (#{args.size} for 4)" ) | raise ArgumentError.new("wrong number of arguments (#{args.size} for 4)" ) | |||
end | end | |||
end | end | |||
declare :rgba, [:red, :green, :blue, :alpha] | declare :rgba, [:red, :green, :blue, :alpha] | |||
declare :rgba, [:red, :green, :blue] | ||||
declare :rgba, [:color, :alpha] | declare :rgba, [:color, :alpha] | |||
declare :rgba, [:red] | ||||
# Creates a {Sass::Script::Value::Color Color} from hue, saturation, and | # Creates a {Sass::Script::Value::Color Color} from hue, saturation, and | |||
# lightness values. Uses the algorithm from the [CSS3 spec][]. | # lightness values. Uses the algorithm from the [CSS3 spec][]. | |||
# | # | |||
# [CSS3 spec]: http://www.w3.org/TR/css3-color/#hsl-color | # [CSS3 spec]: http://www.w3.org/TR/css3-color/#hsl-color | |||
# | # | |||
# @see #hsla | # @see #hsla | |||
# @overload hsl($hue, $saturation, $lightness) | # @overload hsl($hue, $saturation, $lightness) | |||
# @param $hue [Sass::Script::Value::Number] The hue of the color. Should b e | # @param $hue [Sass::Script::Value::Number] The hue of the color. Should b e | |||
# between 0 and 360 degrees, inclusive | # between 0 and 360 degrees, inclusive | |||
# @param $saturation [Sass::Script::Value::Number] The saturation of the | # @param $saturation [Sass::Script::Value::Number] The saturation of the | |||
# color. Must be between `0%` and `100%`, inclusive | # color. Must be between `0%` and `100%`, inclusive | |||
# @param $lightness [Sass::Script::Value::Number] The lightness of the | # @param $lightness [Sass::Script::Value::Number] The lightness of the | |||
# color. Must be between `0%` and `100%`, inclusive | # color. Must be between `0%` and `100%`, inclusive | |||
# @return [Sass::Script::Value::Color] | # @return [Sass::Script::Value::Color] | |||
# @raise [ArgumentError] if `$saturation` or `$lightness` are out of bounds | # @raise [ArgumentError] if `$saturation` or `$lightness` are out of bounds | |||
# or any parameter is the wrong type | # or any parameter is the wrong type | |||
def hsl(hue, saturation, lightness) | def hsl(hue, saturation = nil, lightness = nil) | |||
if saturation.nil? | ||||
return unquoted_string("hsl(#{hue})") if var?(hue) | ||||
raise ArgumentError.new("wrong number of arguments (1 for 3)") | ||||
elsif lightness.nil? | ||||
return unquoted_string("hsl(#{hue}, #{saturation})") if var?(hue) || var | ||||
?(saturation) | ||||
raise ArgumentError.new("wrong number of arguments (2 for 3)") | ||||
end | ||||
if special_number?(hue) || special_number?(saturation) || special_number?( lightness) | if special_number?(hue) || special_number?(saturation) || special_number?( lightness) | |||
unquoted_string("hsl(#{hue}, #{saturation}, #{lightness})") | unquoted_string("hsl(#{hue}, #{saturation}, #{lightness})") | |||
else | else | |||
hsla(hue, saturation, lightness, number(1)) | hsla(hue, saturation, lightness, number(1)) | |||
end | end | |||
end | end | |||
declare :hsl, [:hue, :saturation, :lightness] | declare :hsl, [:hue, :saturation, :lightness] | |||
declare :hsl, [:hue, :saturation] | ||||
declare :hsl, [:hue] | ||||
# Creates a {Sass::Script::Value::Color Color} from hue, | # Creates a {Sass::Script::Value::Color Color} from hue, | |||
# saturation, lightness, and alpha values. Uses the algorithm from | # saturation, lightness, and alpha values. Uses the algorithm from | |||
# the [CSS3 spec][]. | # the [CSS3 spec][]. | |||
# | # | |||
# [CSS3 spec]: http://www.w3.org/TR/css3-color/#hsl-color | # [CSS3 spec]: http://www.w3.org/TR/css3-color/#hsl-color | |||
# | # | |||
# @see #hsl | # @see #hsl | |||
# @overload hsla($hue, $saturation, $lightness, $alpha) | # @overload hsla($hue, $saturation, $lightness, $alpha) | |||
# @param $hue [Sass::Script::Value::Number] The hue of the color. Should b e | # @param $hue [Sass::Script::Value::Number] The hue of the color. Should b e | |||
# between 0 and 360 degrees, inclusive | # between 0 and 360 degrees, inclusive | |||
# @param $saturation [Sass::Script::Value::Number] The saturation of the | # @param $saturation [Sass::Script::Value::Number] The saturation of the | |||
# color. Must be between `0%` and `100%`, inclusive | # color. Must be between `0%` and `100%`, inclusive | |||
# @param $lightness [Sass::Script::Value::Number] The lightness of the | # @param $lightness [Sass::Script::Value::Number] The lightness of the | |||
# color. Must be between `0%` and `100%`, inclusive | # color. Must be between `0%` and `100%`, inclusive | |||
# @param $alpha [Sass::Script::Value::Number] The opacity of the color. Mu st | # @param $alpha [Sass::Script::Value::Number] The opacity of the color. Mu st | |||
# be between 0 and 1, inclusive | # be between 0 and 1, inclusive | |||
# @return [Sass::Script::Value::Color] | # @return [Sass::Script::Value::Color] | |||
# @raise [ArgumentError] if `$saturation`, `$lightness`, or `$alpha` are out | # @raise [ArgumentError] if `$saturation`, `$lightness`, or `$alpha` are out | |||
# of bounds or any parameter is the wrong type | # of bounds or any parameter is the wrong type | |||
def hsla(hue, saturation, lightness, alpha) | def hsla(hue, saturation = nil, lightness = nil, alpha = nil) | |||
if saturation.nil? | ||||
return unquoted_string("hsla(#{hue})") if var?(hue) | ||||
raise ArgumentError.new("wrong number of arguments (1 for 4)") | ||||
elsif lightness.nil? | ||||
return unquoted_string("hsla(#{hue}, #{saturation})") if var?(hue) || va | ||||
r?(saturation) | ||||
raise ArgumentError.new("wrong number of arguments (2 for 4)") | ||||
elsif alpha.nil? | ||||
if var?(hue) || var?(saturation) || var?(lightness) | ||||
return unquoted_string("hsla(#{hue}, #{saturation}, #{lightness})") | ||||
else | ||||
raise ArgumentError.new("wrong number of arguments (2 for 4)") | ||||
end | ||||
end | ||||
if special_number?(hue) || special_number?(saturation) || | if special_number?(hue) || special_number?(saturation) || | |||
special_number?(lightness) || special_number?(alpha) | special_number?(lightness) || special_number?(alpha) | |||
return unquoted_string("hsla(#{hue}, #{saturation}, #{lightness}, #{alph a})") | return unquoted_string("hsla(#{hue}, #{saturation}, #{lightness}, #{alph a})") | |||
end | end | |||
assert_type hue, :Number, :hue | assert_type hue, :Number, :hue | |||
assert_type saturation, :Number, :saturation | assert_type saturation, :Number, :saturation | |||
assert_type lightness, :Number, :lightness | assert_type lightness, :Number, :lightness | |||
assert_type alpha, :Number, :alpha | assert_type alpha, :Number, :alpha | |||
check_alpha_unit alpha, 'hsla' | check_alpha_unit alpha, 'hsla' | |||
skipping to change at line 806 | skipping to change at line 861 | |||
s = saturation.value | s = saturation.value | |||
l = lightness.value | l = lightness.value | |||
# Don't store the string representation for function-created colors, both | # Don't store the string representation for function-created colors, both | |||
# because it's not very useful and because some functions aren't supported | # because it's not very useful and because some functions aren't supported | |||
# on older browsers. | # on older browsers. | |||
Sass::Script::Value::Color.new( | Sass::Script::Value::Color.new( | |||
:hue => h, :saturation => s, :lightness => l, :alpha => alpha.value) | :hue => h, :saturation => s, :lightness => l, :alpha => alpha.value) | |||
end | end | |||
declare :hsla, [:hue, :saturation, :lightness, :alpha] | declare :hsla, [:hue, :saturation, :lightness, :alpha] | |||
declare :hsla, [:hue, :saturation, :lightness] | ||||
declare :hsla, [:hue, :saturation] | ||||
declare :hsla, [:hue] | ||||
# Gets the red component of a color. Calculated from HSL where necessary via | # Gets the red component of a color. Calculated from HSL where necessary via | |||
# [this algorithm][hsl-to-rgb]. | # [this algorithm][hsl-to-rgb]. | |||
# | # | |||
# [hsl-to-rgb]: http://www.w3.org/TR/css3-color/#hsl-color | # [hsl-to-rgb]: http://www.w3.org/TR/css3-color/#hsl-color | |||
# | # | |||
# @overload red($color) | # @overload red($color) | |||
# @param $color [Sass::Script::Value::Color] | # @param $color [Sass::Script::Value::Color] | |||
# @return [Sass::Script::Value::Number] The red component, between 0 and 255 | # @return [Sass::Script::Value::Number] The red component, between 0 and 255 | |||
# inclusive | # inclusive | |||
End of changes. 11 change blocks. | ||||
3 lines changed or deleted | 65 lines changed or added |