sass 3.3.0.alpha.196 → 3.3.0.alpha.198
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/REVISION +1 -1
- data/VERSION +1 -1
- data/VERSION_DATE +1 -1
- data/lib/sass/script/functions.rb +639 -546
- data/test/sass/functions_test.rb +82 -79
- metadata +3 -3
data/REVISION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
be5f2f981c18818dbb8dd8b08f13262bbf112ef1
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.3.0.alpha.
|
1
|
+
3.3.0.alpha.198
|
data/VERSION_DATE
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
03 July 2013 00:40:44 GMT
|
@@ -2,7 +2,7 @@ module Sass::Script
|
|
2
2
|
# Methods in this module are accessible from the SassScript context.
|
3
3
|
# For example, you can write
|
4
4
|
#
|
5
|
-
# $color
|
5
|
+
# $color: hsl(120deg, 100%, 50%)
|
6
6
|
#
|
7
7
|
# and it will call {Functions#hsl}.
|
8
8
|
#
|
@@ -13,13 +13,12 @@ module Sass::Script
|
|
13
13
|
# ## RGB Functions
|
14
14
|
#
|
15
15
|
# \{#rgb rgb($red, $green, $blue)}
|
16
|
-
# :
|
16
|
+
# : Creates a {Sass::Script::Value::Color Color} from red, green, and blue
|
17
|
+
# values.
|
17
18
|
#
|
18
19
|
# \{#rgba rgba($red, $green, $blue, $alpha)}
|
19
|
-
# :
|
20
|
-
#
|
21
|
-
# \{#rgba rgba($color, $alpha)}
|
22
|
-
# : Adds an alpha layer to any color value.
|
20
|
+
# : Creates a {Sass::Script::Value::Color Color} from red, green, blue, and
|
21
|
+
# alpha values.
|
23
22
|
#
|
24
23
|
# \{#red red($color)}
|
25
24
|
# : Gets the red component of a color.
|
@@ -36,10 +35,12 @@ module Sass::Script
|
|
36
35
|
# ## HSL Functions
|
37
36
|
#
|
38
37
|
# \{#hsl hsl($hue, $saturation, $lightness)}
|
39
|
-
# :
|
38
|
+
# : Creates a {Sass::Script::Value::Color Color} from hue, saturation, and
|
39
|
+
# lightness values.
|
40
40
|
#
|
41
41
|
# \{#hsla hsla($hue, $saturation, $lightness, $alpha)}
|
42
|
-
# :
|
42
|
+
# : Creates a {Sass::Script::Value::Color Color} from hue, saturation,
|
43
|
+
# lightness, lightness, and alpha values.
|
43
44
|
#
|
44
45
|
# \{#hue hue($color)}
|
45
46
|
# : Gets the hue component of a color.
|
@@ -80,7 +81,7 @@ module Sass::Script
|
|
80
81
|
# : Gets the alpha component (opacity) of a color.
|
81
82
|
#
|
82
83
|
# \{#rgba rgba($color, $alpha)}
|
83
|
-
# :
|
84
|
+
# : Changes the alpha component for a color.
|
84
85
|
#
|
85
86
|
# \{#opacify opacify($color, $amount)} / \{#fade_in fade-in($color, $amount)}
|
86
87
|
# : Makes a color more opaque.
|
@@ -91,10 +92,10 @@ module Sass::Script
|
|
91
92
|
# ## Other Color Functions
|
92
93
|
#
|
93
94
|
# \{#adjust_color adjust-color($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\])}
|
94
|
-
# :
|
95
|
+
# : Increases or decreases one or more components of a color.
|
95
96
|
#
|
96
97
|
# \{#scale_color scale-color($color, \[$red\], \[$green\], \[$blue\], \[$saturation\], \[$lightness\], \[$alpha\])}
|
97
|
-
# : Fluidly
|
98
|
+
# : Fluidly scales one or more properties of a color.
|
98
99
|
#
|
99
100
|
# \{#change_color change-color($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\])}
|
100
101
|
# : Changes one or more properties of a color.
|
@@ -105,7 +106,7 @@ module Sass::Script
|
|
105
106
|
# ## String Functions
|
106
107
|
#
|
107
108
|
# \{#unquote unquote($string)}
|
108
|
-
# : Removes
|
109
|
+
# : Removes quotes from a string.
|
109
110
|
#
|
110
111
|
# \{#quote quote($string)}
|
111
112
|
# : Adds quotes to a string.
|
@@ -114,13 +115,13 @@ module Sass::Script
|
|
114
115
|
# : Returns the number of characters in a string.
|
115
116
|
#
|
116
117
|
# \{#str_insert str-insert($string, $insert, $index)}
|
117
|
-
# : Inserts
|
118
|
+
# : Inserts `$insert` into `$string` at `$index`.
|
118
119
|
#
|
119
120
|
# \{#str_index str-index($string, $substring)}
|
120
|
-
# : Returns the index
|
121
|
+
# : Returns the index of the first occurance of `$substring` in `$string`.
|
121
122
|
#
|
122
|
-
# \{#str_slice str-slice($string, $start, $end)}
|
123
|
-
# : Extracts a substring
|
123
|
+
# \{#str_slice str-slice($string, $start-at, [$end-at])}
|
124
|
+
# : Extracts a substring from `$string`.
|
124
125
|
#
|
125
126
|
# \{#to_upper_case to-upper-case($string)}
|
126
127
|
# : Converts a string to upper case.
|
@@ -137,19 +138,19 @@ module Sass::Script
|
|
137
138
|
# : Rounds a number to the nearest whole number.
|
138
139
|
#
|
139
140
|
# \{#ceil ceil($value)}
|
140
|
-
# : Rounds a number up to the
|
141
|
+
# : Rounds a number up to the next whole number.
|
141
142
|
#
|
142
143
|
# \{#floor floor($value)}
|
143
|
-
# : Rounds a number down to the
|
144
|
+
# : Rounds a number down to the previous whole number.
|
144
145
|
#
|
145
146
|
# \{#abs abs($value)}
|
146
147
|
# : Returns the absolute value of a number.
|
147
148
|
#
|
148
|
-
# \{#min min($
|
149
|
-
# : Finds the minimum of several
|
149
|
+
# \{#min min($numbers...)\}
|
150
|
+
# : Finds the minimum of several numbers.
|
150
151
|
#
|
151
|
-
# \{#max max($
|
152
|
-
# : Finds the maximum of several
|
152
|
+
# \{#max max($numbers...)\}
|
153
|
+
# : Finds the maximum of several numbers.
|
153
154
|
#
|
154
155
|
# ## List Functions {#list-functions}
|
155
156
|
#
|
@@ -165,11 +166,11 @@ module Sass::Script
|
|
165
166
|
# \{#append append($list1, $val, \[$separator\])}
|
166
167
|
# : Appends a single value onto the end of a list.
|
167
168
|
#
|
168
|
-
# \{#zip zip($
|
169
|
+
# \{#zip zip($lists...)}
|
169
170
|
# : Combines several lists into a single multidimensional list.
|
170
171
|
#
|
171
172
|
# \{#index index($list, $value)}
|
172
|
-
# : Returns the position of a value within a list
|
173
|
+
# : Returns the position of a value within a list.
|
173
174
|
#
|
174
175
|
# \{#list_separator list-separator(#list)}
|
175
176
|
# : Returns the separator of a list.
|
@@ -177,24 +178,25 @@ module Sass::Script
|
|
177
178
|
# ## Introspection Functions
|
178
179
|
#
|
179
180
|
# \{#feature_exists feature-exists($feature)}
|
180
|
-
# : Returns whether
|
181
|
+
# : Returns whether a feature exists in the current Sass runtime.
|
181
182
|
#
|
182
183
|
# \{#type_of type-of($value)}
|
183
184
|
# : Returns the type of a value.
|
184
185
|
#
|
185
186
|
# \{#unit unit($number)}
|
186
|
-
# : Returns the
|
187
|
+
# : Returns the unit(s) associated with a number.
|
187
188
|
#
|
188
189
|
# \{#unitless unitless($number)}
|
189
|
-
# : Returns whether a number has units
|
190
|
+
# : Returns whether a number has units.
|
190
191
|
#
|
191
192
|
# \{#comparable comparable($number-1, $number-2)}
|
192
|
-
# : Returns whether two numbers can be added or compared.
|
193
|
+
# : Returns whether two numbers can be added, subtracted, or compared.
|
193
194
|
#
|
194
195
|
# ## Miscellaneous Functions
|
195
196
|
#
|
196
197
|
# \{#if if($condition, $if-true, $if-false)}
|
197
|
-
# : Returns one of two values, depending on whether or not
|
198
|
+
# : Returns one of two values, depending on whether or not `$condition` is
|
199
|
+
# true.
|
198
200
|
#
|
199
201
|
# \{#unique_id unique-id()}
|
200
202
|
# : Returns a unique CSS identifier.
|
@@ -274,6 +276,12 @@ module Sass::Script
|
|
274
276
|
# but none of them but the first will be used
|
275
277
|
# unless the user uses keyword arguments.
|
276
278
|
#
|
279
|
+
# @example
|
280
|
+
# declare :rgba, [:hex, :alpha]
|
281
|
+
# declare :rgba, [:red, :green, :blue, :alpha]
|
282
|
+
# declare :accepts_anything, [], :var_args => true, :var_kwargs => true
|
283
|
+
# declare :some_func, [:foo, :bar, :baz], :var_kwargs => true
|
284
|
+
#
|
277
285
|
# @param method_name [Symbol] The name of the method
|
278
286
|
# whose signature is being declared.
|
279
287
|
# @param args [Array<Symbol>] The names of the arguments for the function signature.
|
@@ -287,12 +295,6 @@ module Sass::Script
|
|
287
295
|
# to {Value}s as the last argument.
|
288
296
|
# In addition, if this is true and `:var_args` is not,
|
289
297
|
# Sass will ensure that the last argument passed is a hash.
|
290
|
-
#
|
291
|
-
# @example
|
292
|
-
# declare :rgba, [:hex, :alpha]
|
293
|
-
# declare :rgba, [:red, :green, :blue, :alpha]
|
294
|
-
# declare :accepts_anything, [], :var_args => true, :var_kwargs => true
|
295
|
-
# declare :some_func, [:foo, :bar, :baz], :var_kwargs => true
|
296
298
|
def self.declare(method_name, args, options = {})
|
297
299
|
@signatures[method_name] ||= []
|
298
300
|
@signatures[method_name] << Signature.new(
|
@@ -370,14 +372,14 @@ module Sass::Script
|
|
370
372
|
# @example
|
371
373
|
# assert_type value, :String
|
372
374
|
# assert_type value, :Number
|
373
|
-
# @param value [Value] A SassScript value
|
375
|
+
# @param value [Sass::Script::Value::Base] A SassScript value
|
374
376
|
# @param type [Symbol] The name of the type the value is expected to be
|
375
|
-
# @param name [String, nil] The name of the argument.
|
377
|
+
# @param name [String, Symbol, nil] The name of the argument.
|
376
378
|
# @raise [ArgumentError] if value is not of the correct type.
|
377
379
|
def assert_type(value, type, name = nil)
|
378
380
|
return if value.is_a?(Sass::Script::Value.const_get(type))
|
379
381
|
err = "#{value.inspect} is not a #{type.to_s.downcase}"
|
380
|
-
err = "$#{name}: " + err if name
|
382
|
+
err = "$#{name.to_s.gsub('_', '-')}: " + err if name
|
381
383
|
raise ArgumentError.new(err)
|
382
384
|
end
|
383
385
|
|
@@ -442,29 +444,31 @@ module Sass::Script
|
|
442
444
|
# Creates a {Sass::Script::Value::Color Color} object from red, green, and
|
443
445
|
# blue values.
|
444
446
|
#
|
445
|
-
# @param red [Sass::Script::Value::Number]
|
446
|
-
# A number between 0 and 255 inclusive,
|
447
|
-
# or between 0% and 100% inclusive
|
448
|
-
# @param green [Sass::Script::Value::Number]
|
449
|
-
# A number between 0 and 255 inclusive,
|
450
|
-
# or between 0% and 100% inclusive
|
451
|
-
# @param blue [Sass::Script::Value::Number]
|
452
|
-
# A number between 0 and 255 inclusive,
|
453
|
-
# or between 0% and 100% inclusive
|
454
447
|
# @see #rgba
|
448
|
+
# @overload rgb($red, $green, $blue)
|
449
|
+
# @param $red [Sass::Script::Value::Number] The amount of red in the color.
|
450
|
+
# Must be between 0 and 255 inclusive, or between `0%` and `100%`
|
451
|
+
# inclusive
|
452
|
+
# @param $green [Sass::Script::Value::Number] The amount of green in the
|
453
|
+
# color. Must be between 0 and 255 inclusive, or between `0%` and `100%`
|
454
|
+
# inclusive
|
455
|
+
# @param $blue [Sass::Script::Value::Number] The amount of blue in the
|
456
|
+
# color. Must be between 0 and 255 inclusive, or between `0%` and `100%`
|
457
|
+
# inclusive
|
455
458
|
# @return [Sass::Script::Value::Color]
|
459
|
+
# @raise [ArgumentError] if any parameter is the wrong type or out of bounds
|
456
460
|
def rgb(red, green, blue)
|
457
|
-
assert_type red, :Number
|
458
|
-
assert_type green, :Number
|
459
|
-
assert_type blue, :Number
|
461
|
+
assert_type red, :Number, :red
|
462
|
+
assert_type green, :Number, :green
|
463
|
+
assert_type blue, :Number, :blue
|
460
464
|
|
461
|
-
Sass::Script::Value::Color.new([red, green, blue].map do |c|
|
465
|
+
Sass::Script::Value::Color.new([[red, :red], [green, :green], [blue, :blue]].map do |(c, name)|
|
462
466
|
v = c.value
|
463
467
|
if c.is_unit?("%")
|
464
|
-
v = Sass::Util.check_range("Color value", 0..100, c, '%')
|
468
|
+
v = Sass::Util.check_range("$#{name}: Color value", 0..100, c, '%')
|
465
469
|
v * 255 / 100.0
|
466
470
|
elsif c.unitless?
|
467
|
-
Sass::Util.check_range("Color value", 0..255, c)
|
471
|
+
Sass::Util.check_range("$#{name}: Color value", 0..255, c)
|
468
472
|
else
|
469
473
|
raise ArgumentError.new("Expected #{c} to be unitless or have a unit of % but got #{c}")
|
470
474
|
end
|
@@ -472,39 +476,44 @@ module Sass::Script
|
|
472
476
|
end
|
473
477
|
declare :rgb, [:red, :green, :blue]
|
474
478
|
|
479
|
+
# Creates a {Sass::Script::Value::Color Color} from red, green, blue, and
|
480
|
+
# alpha values.
|
475
481
|
# @see #rgb
|
476
|
-
#
|
477
|
-
#
|
478
|
-
#
|
479
|
-
#
|
480
|
-
# @param
|
481
|
-
#
|
482
|
-
# @param
|
483
|
-
#
|
484
|
-
# @param
|
485
|
-
#
|
486
|
-
# @param alpha [Sass::Script::Value::Number]
|
487
|
-
# A number between 0 and 1
|
482
|
+
#
|
483
|
+
# @overload rgba($red, $green, $blue, $alpha)
|
484
|
+
# @param $red [Sass::Script::Value::Number] The amount of red in the
|
485
|
+
# color. Must be between 0 and 255 inclusive
|
486
|
+
# @param $green [Sass::Script::Value::Number] The amount of green in the
|
487
|
+
# color. Must be between 0 and 255 inclusive
|
488
|
+
# @param $blue [Sass::Script::Value::Number] The amount of blue in the
|
489
|
+
# color. Must be between 0 and 255 inclusive
|
490
|
+
# @param $alpha [Sass::Script::Value::Number] The opacity of the color.
|
491
|
+
# Must be between 0 and 1 inclusive
|
488
492
|
# @return [Sass::Script::Value::Color]
|
493
|
+
# @raise [ArgumentError] if any parameter is the wrong type or out of
|
494
|
+
# bounds
|
489
495
|
#
|
490
|
-
# @overload rgba(color, alpha)
|
491
|
-
# Sets the opacity of
|
496
|
+
# @overload rgba($color, $alpha)
|
497
|
+
# Sets the opacity of an existing color.
|
492
498
|
#
|
493
499
|
# @example
|
494
500
|
# rgba(#102030, 0.5) => rgba(16, 32, 48, 0.5)
|
495
501
|
# rgba(blue, 0.2) => rgba(0, 0, 255, 0.2)
|
496
502
|
#
|
497
|
-
# @param color [Sass::Script::Value::Color]
|
498
|
-
#
|
499
|
-
#
|
503
|
+
# @param $color [Sass::Script::Value::Color] The color whose opacity will
|
504
|
+
# be changed.
|
505
|
+
# @param $alpha [Sass::Script::Value::Number] The new opacity of the
|
506
|
+
# color. Must be between 0 and 1 inclusive
|
500
507
|
# @return [Sass::Script::Value::Color]
|
508
|
+
# @raise [ArgumentError] if `$alpha` is out of bounds or either parameter
|
509
|
+
# is the wrong type
|
501
510
|
def rgba(*args)
|
502
511
|
case args.size
|
503
512
|
when 2
|
504
513
|
color, alpha = args
|
505
514
|
|
506
|
-
assert_type color, :Color
|
507
|
-
assert_type alpha, :Number
|
515
|
+
assert_type color, :Color, :color
|
516
|
+
assert_type alpha, :Number, :alpha
|
508
517
|
|
509
518
|
Sass::Util.check_range('Alpha channel', 0..1, alpha)
|
510
519
|
color.with(:alpha => alpha.value)
|
@@ -518,43 +527,51 @@ module Sass::Script
|
|
518
527
|
declare :rgba, [:red, :green, :blue, :alpha]
|
519
528
|
declare :rgba, [:color, :alpha]
|
520
529
|
|
521
|
-
# Creates a {Sass::Script::Value::Color Color}
|
522
|
-
#
|
530
|
+
# Creates a {Sass::Script::Value::Color Color} from hue, saturation, and
|
531
|
+
# lightness values. Uses the algorithm from the [CSS3 spec][].
|
532
|
+
#
|
533
|
+
# [CSS3 spec]: http://www.w3.org/TR/css3-color/#hsl-color
|
523
534
|
#
|
524
|
-
# @param hue [Sass::Script::Value::Number]
|
525
|
-
# The hue of the color. Should be between 0 and 360 degrees, inclusive
|
526
|
-
# @param saturation [Sass::Script::Value::Number]
|
527
|
-
# The saturation of the color. Must be between `0%` and `100%`, inclusive
|
528
|
-
# @param lightness [Sass::Script::Value::Number]
|
529
|
-
# The lightness of the color. Must be between `0%` and `100%`, inclusive
|
530
|
-
# @return [Sass::Script::Value::Color] The resulting color
|
531
535
|
# @see #hsla
|
532
|
-
# @
|
536
|
+
# @overload hsl($hue, $saturation, $lightness)
|
537
|
+
# @param $hue [Sass::Script::Value::Number] The hue of the color. Should be
|
538
|
+
# between 0 and 360 degrees, inclusive
|
539
|
+
# @param $saturation [Sass::Script::Value::Number] The saturation of the
|
540
|
+
# color. Must be between `0%` and `100%`, inclusive
|
541
|
+
# @param $lightness [Sass::Script::Value::Number] The lightness of the
|
542
|
+
# color. Must be between `0%` and `100%`, inclusive
|
543
|
+
# @return [Sass::Script::Value::Color]
|
544
|
+
# @raise [ArgumentError] if `$saturation` or `$lightness` are out of bounds
|
545
|
+
# or any parameter is the wrong type
|
533
546
|
def hsl(hue, saturation, lightness)
|
534
547
|
hsla(hue, saturation, lightness, Sass::Script::Value::Number.new(1))
|
535
548
|
end
|
536
549
|
declare :hsl, [:hue, :saturation, :lightness]
|
537
550
|
|
538
|
-
# Creates a {Sass::Script::Value::Color Color}
|
539
|
-
#
|
540
|
-
#
|
541
|
-
#
|
542
|
-
#
|
543
|
-
#
|
544
|
-
# @param saturation [Sass::Script::Value::Number] The saturation of the color.
|
545
|
-
# Must be between `0%` and `100%`, inclusive
|
546
|
-
# @param lightness [Sass::Script::Value::Number] The lightness of the color.
|
547
|
-
# Must be between `0%` and `100%`, inclusive
|
548
|
-
# @param alpha [Sass::Script::Value::Number] The opacity of the color.
|
549
|
-
# Must be between 0 and 1, inclusive
|
550
|
-
# @return [Sass::Script::Value::Color] The resulting color
|
551
|
+
# Creates a {Sass::Script::Value::Color Color} from hue, saturation,
|
552
|
+
# lightness, lightness, and alpha values. Uses the algorithm from the [CSS3
|
553
|
+
# spec][].
|
554
|
+
#
|
555
|
+
# [CSS3 spec]: http://www.w3.org/TR/css3-color/#hsl-color
|
556
|
+
#
|
551
557
|
# @see #hsl
|
552
|
-
# @
|
558
|
+
# @overload hsla($hue, $saturation, $lightness, $alpha)
|
559
|
+
# @param $hue [Sass::Script::Value::Number] The hue of the color. Should be
|
560
|
+
# between 0 and 360 degrees, inclusive
|
561
|
+
# @param $saturation [Sass::Script::Value::Number] The saturation of the
|
562
|
+
# color. Must be between `0%` and `100%`, inclusive
|
563
|
+
# @param $lightness [Sass::Script::Value::Number] The lightness of the
|
564
|
+
# color. Must be between `0%` and `100%`, inclusive
|
565
|
+
# @param $alpha [Sass::Script::Value::Number] The opacity of the color. Must
|
566
|
+
# be between 0 and 1, inclusive
|
567
|
+
# @return [Sass::Script::Value::Color]
|
568
|
+
# @raise [ArgumentError] if `$saturation`, `$lightness`, or `$alpha` are out
|
569
|
+
# of bounds or any parameter is the wrong type
|
553
570
|
def hsla(hue, saturation, lightness, alpha)
|
554
|
-
assert_type hue, :Number
|
555
|
-
assert_type saturation, :Number
|
556
|
-
assert_type lightness, :Number
|
557
|
-
assert_type alpha, :Number
|
571
|
+
assert_type hue, :Number, :hue
|
572
|
+
assert_type saturation, :Number, :saturation
|
573
|
+
assert_type lightness, :Number, :lightness
|
574
|
+
assert_type alpha, :Number, :alpha
|
558
575
|
|
559
576
|
Sass::Util.check_range('Alpha channel', 0..1, alpha)
|
560
577
|
|
@@ -566,104 +583,118 @@ module Sass::Script
|
|
566
583
|
end
|
567
584
|
declare :hsla, [:hue, :saturation, :lightness, :alpha]
|
568
585
|
|
569
|
-
#
|
586
|
+
# Gets the red component of a color. Calculated from HSL where necessary via
|
587
|
+
# [this algorithm][hsl-to-rgb].
|
570
588
|
#
|
571
|
-
#
|
572
|
-
#
|
573
|
-
# @
|
589
|
+
# [hsl-to-rgb]: http://www.w3.org/TR/css3-color/#hsl-color
|
590
|
+
#
|
591
|
+
# @overload red($color)
|
592
|
+
# @param $color [Sass::Script::Value::Color]
|
593
|
+
# @return [Sass::Script::Value::Number] The red component, between 0 and 255
|
594
|
+
# inclusive
|
595
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
574
596
|
def red(color)
|
575
|
-
assert_type color, :Color
|
597
|
+
assert_type color, :Color, :color
|
576
598
|
Sass::Script::Value::Number.new(color.red)
|
577
599
|
end
|
578
600
|
declare :red, [:color]
|
579
601
|
|
580
|
-
#
|
602
|
+
# Gets the green component of a color. Calculated from HSL where necessary
|
603
|
+
# via [this algorithm][hsl-to-rgb].
|
581
604
|
#
|
582
|
-
#
|
583
|
-
#
|
584
|
-
# @
|
605
|
+
# [hsl-to-rgb]: http://www.w3.org/TR/css3-color/#hsl-color
|
606
|
+
#
|
607
|
+
# @overload green($color)
|
608
|
+
# @param $color [Sass::Script::Value::Color]
|
609
|
+
# @return [Sass::Script::Value::Number] The green component, between 0 and
|
610
|
+
# 255 inclusive
|
611
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
585
612
|
def green(color)
|
586
|
-
assert_type color, :Color
|
613
|
+
assert_type color, :Color, :color
|
587
614
|
Sass::Script::Value::Number.new(color.green)
|
588
615
|
end
|
589
616
|
declare :green, [:color]
|
590
617
|
|
591
|
-
#
|
618
|
+
# Gets the blue component of a color. Calculated from HSL where necessary
|
619
|
+
# via [this algorithm][hsl-to-rgb].
|
592
620
|
#
|
593
|
-
#
|
594
|
-
#
|
595
|
-
# @
|
621
|
+
# [hsl-to-rgb]: http://www.w3.org/TR/css3-color/#hsl-color
|
622
|
+
#
|
623
|
+
# @overload blue($color)
|
624
|
+
# @param $color [Sass::Script::Value::Color]
|
625
|
+
# @return [Sass::Script::Value::Number] The blue component, between 0 and
|
626
|
+
# 255 inclusive
|
627
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
596
628
|
def blue(color)
|
597
|
-
assert_type color, :Color
|
629
|
+
assert_type color, :Color, :color
|
598
630
|
Sass::Script::Value::Number.new(color.blue)
|
599
631
|
end
|
600
632
|
declare :blue, [:color]
|
601
633
|
|
602
|
-
# Returns the hue component of a color.
|
634
|
+
# Returns the hue component of a color. See [the CSS3 HSL
|
635
|
+
# specification][hsl]. Calculated from RGB where necessary via [this
|
636
|
+
# algorithm][rgb-to-hsl].
|
603
637
|
#
|
604
|
-
#
|
638
|
+
# [hsl]: http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV
|
639
|
+
# [rgb-to-hsl]: http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV
|
605
640
|
#
|
606
|
-
#
|
607
|
-
#
|
608
|
-
# @
|
609
|
-
#
|
610
|
-
# @
|
611
|
-
# @raise [ArgumentError] if `color` isn't a color
|
641
|
+
# @overload hue($color)
|
642
|
+
# @param $color [Sass::Script::Value::Color]
|
643
|
+
# @return [Sass::Script::Value::Number] The hue component, between 0deg and
|
644
|
+
# 360deg
|
645
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
612
646
|
def hue(color)
|
613
|
-
assert_type color, :Color
|
647
|
+
assert_type color, :Color, :color
|
614
648
|
Sass::Script::Value::Number.new(color.hue, ["deg"])
|
615
649
|
end
|
616
650
|
declare :hue, [:color]
|
617
651
|
|
618
|
-
# Returns the saturation component of a color.
|
619
|
-
#
|
620
|
-
#
|
652
|
+
# Returns the saturation component of a color. See [the CSS3 HSL
|
653
|
+
# specification][hsl]. Calculated from RGB where necessary via [this
|
654
|
+
# algorithm][rgb-to-hsl].
|
621
655
|
#
|
622
|
-
#
|
656
|
+
# [hsl]: http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV
|
657
|
+
# [rgb-to-hsl]: http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV
|
623
658
|
#
|
624
|
-
# @
|
625
|
-
# @
|
626
|
-
# @
|
627
|
-
#
|
628
|
-
# @raise [ArgumentError] if
|
659
|
+
# @overload saturation($color)
|
660
|
+
# @param $color [Sass::Script::Value::Color]
|
661
|
+
# @return [Sass::Script::Value::Number] The saturation component, between 0%
|
662
|
+
# and 100%
|
663
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
629
664
|
def saturation(color)
|
630
|
-
assert_type color, :Color
|
665
|
+
assert_type color, :Color, :color
|
631
666
|
Sass::Script::Value::Number.new(color.saturation, ["%"])
|
632
667
|
end
|
633
668
|
declare :saturation, [:color]
|
634
669
|
|
635
|
-
# Returns the
|
636
|
-
#
|
637
|
-
#
|
670
|
+
# Returns the lightness component of a color. See [the CSS3 HSL
|
671
|
+
# specification][hsl]. Calculated from RGB where necessary via [this
|
672
|
+
# algorithm][rgb-to-hsl].
|
638
673
|
#
|
639
|
-
#
|
674
|
+
# [hsl]: http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV
|
675
|
+
# [rgb-to-hsl]: http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV
|
640
676
|
#
|
641
|
-
# @
|
642
|
-
# @
|
643
|
-
# @
|
644
|
-
#
|
645
|
-
# @raise [ArgumentError] if
|
677
|
+
# @overload lightness($color)
|
678
|
+
# @param $color [Sass::Script::Value::Color]
|
679
|
+
# @return [Sass::Script::Value::Number] The lightness component, between 0%
|
680
|
+
# and 100%
|
681
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
646
682
|
def lightness(color)
|
647
|
-
assert_type color, :Color
|
683
|
+
assert_type color, :Color, :color
|
648
684
|
Sass::Script::Value::Number.new(color.lightness, ["%"])
|
649
685
|
end
|
650
686
|
declare :lightness, [:color]
|
651
687
|
|
652
|
-
#
|
653
|
-
#
|
654
|
-
# This is 1 unless otherwise specified.
|
655
|
-
#
|
656
|
-
# @param color [Sass::Script::Value::Color]
|
657
|
-
# @return [Sass::Script::Value::Number]
|
658
|
-
# @see #opacify
|
659
|
-
# @see #transparentize
|
660
|
-
# @raise [ArgumentError] If `color` isn't a color
|
688
|
+
# Returns the alpha component (opacity) of a color. This is 1 unless
|
689
|
+
# otherwise specified.
|
661
690
|
#
|
662
|
-
#
|
663
|
-
#
|
691
|
+
# This function also supports the proprietary Microsoft `alpha(opacity=20)`
|
692
|
+
# syntax as a special case.
|
664
693
|
#
|
665
|
-
#
|
666
|
-
#
|
694
|
+
# @overload alpha($color)
|
695
|
+
# @param $color [Sass::Script::Value::Color]
|
696
|
+
# @return [Sass::Script::Value::Number] The alpha component, between 0 and 1
|
697
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
667
698
|
def alpha(*args)
|
668
699
|
if args.all? do |a|
|
669
700
|
a.is_a?(Sass::Script::Value::String) && a.type == :identifier &&
|
@@ -675,41 +706,41 @@ module Sass::Script
|
|
675
706
|
|
676
707
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 1)") if args.size != 1
|
677
708
|
|
678
|
-
assert_type args.first, :Color
|
709
|
+
assert_type args.first, :Color, :color
|
679
710
|
Sass::Script::Value::Number.new(args.first.alpha)
|
680
711
|
end
|
681
712
|
declare :alpha, [:color]
|
682
713
|
|
683
|
-
# Returns the alpha component (opacity) of a color.
|
684
|
-
#
|
714
|
+
# Returns the alpha component (opacity) of a color. This is 1 unless
|
715
|
+
# otherwise specified.
|
685
716
|
#
|
686
|
-
# @
|
687
|
-
# @
|
688
|
-
# @
|
689
|
-
# @
|
690
|
-
# @raise [ArgumentError] If `color` isn't a color
|
717
|
+
# @overload opacity($color)
|
718
|
+
# @param $color [Sass::Script::Value::Color]
|
719
|
+
# @return [Sass::Script::Value::Number] The alpha component, between 0 and 1
|
720
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
691
721
|
def opacity(color)
|
692
722
|
if color.is_a?(Sass::Script::Value::Number)
|
693
723
|
return Sass::Script::Value::String.new("opacity(#{color})")
|
694
724
|
end
|
695
|
-
assert_type color, :Color
|
725
|
+
assert_type color, :Color, :color
|
696
726
|
Sass::Script::Value::Number.new(color.alpha)
|
697
727
|
end
|
698
728
|
declare :opacity, [:color]
|
699
729
|
|
700
|
-
# Makes a color more opaque.
|
701
|
-
#
|
702
|
-
# and returns a color with the opacity increased by that value.
|
730
|
+
# Makes a color more opaque. Takes a color and a number between 0 and 1, and
|
731
|
+
# returns a color with the opacity increased by that amount.
|
703
732
|
#
|
733
|
+
# @see #transparentize
|
704
734
|
# @example
|
705
735
|
# opacify(rgba(0, 0, 0, 0.5), 0.1) => rgba(0, 0, 0, 0.6)
|
706
736
|
# opacify(rgba(0, 0, 17, 0.8), 0.2) => #001
|
707
|
-
# @
|
708
|
-
# @param
|
737
|
+
# @overload opacify($color, $amount)
|
738
|
+
# @param $color [Sass::Script::Value::Color]
|
739
|
+
# @param $amount [Sass::Script::Value::Number] The amount to increase the
|
740
|
+
# opacity by, between 0 and 1
|
709
741
|
# @return [Sass::Script::Value::Color]
|
710
|
-
# @
|
711
|
-
#
|
712
|
-
# or `number` isn't a number between 0 and 1
|
742
|
+
# @raise [ArgumentError] if `$amount` is out of bounds, or either parameter
|
743
|
+
# is the wrong type
|
713
744
|
def opacify(color, amount)
|
714
745
|
_adjust(color, amount, :alpha, 0..1, :+)
|
715
746
|
end
|
@@ -718,19 +749,20 @@ module Sass::Script
|
|
718
749
|
alias_method :fade_in, :opacify
|
719
750
|
declare :fade_in, [:color, :amount]
|
720
751
|
|
721
|
-
# Makes a color more transparent.
|
722
|
-
#
|
723
|
-
# and returns a color with the opacity decreased by that value.
|
752
|
+
# Makes a color more transparent. Takes a color and a number between 0 and
|
753
|
+
# 1, and returns a color with the opacity decreased by that amount.
|
724
754
|
#
|
755
|
+
# @see #opacify
|
725
756
|
# @example
|
726
757
|
# transparentize(rgba(0, 0, 0, 0.5), 0.1) => rgba(0, 0, 0, 0.4)
|
727
758
|
# transparentize(rgba(0, 0, 0, 0.8), 0.2) => rgba(0, 0, 0, 0.6)
|
728
|
-
# @
|
729
|
-
# @param
|
759
|
+
# @overload transparentize($color, $amount)
|
760
|
+
# @param $color [Sass::Script::Value::Color]
|
761
|
+
# @param $amount [Sass::Script::Value::Number] The amount to decrease the
|
762
|
+
# opacity by, between 0 and 1
|
730
763
|
# @return [Sass::Script::Value::Color]
|
731
|
-
# @
|
732
|
-
#
|
733
|
-
# or `number` isn't a number between 0 and 1
|
764
|
+
# @raise [ArgumentError] if `$amount` is out of bounds, or either parameter
|
765
|
+
# is the wrong type
|
734
766
|
def transparentize(color, amount)
|
735
767
|
_adjust(color, amount, :alpha, 0..1, :-)
|
736
768
|
end
|
@@ -739,56 +771,58 @@ module Sass::Script
|
|
739
771
|
alias_method :fade_out, :transparentize
|
740
772
|
declare :fade_out, [:color, :amount]
|
741
773
|
|
742
|
-
# Makes a color lighter.
|
743
|
-
#
|
744
|
-
# and returns a color with the lightness increased by that value.
|
774
|
+
# Makes a color lighter. Takes a color and a number between `0%` and `100%`,
|
775
|
+
# and returns a color with the lightness increased by that amount.
|
745
776
|
#
|
777
|
+
# @see #darken
|
746
778
|
# @example
|
747
779
|
# lighten(hsl(0, 0%, 0%), 30%) => hsl(0, 0, 30)
|
748
780
|
# lighten(#800, 20%) => #e00
|
749
|
-
# @
|
750
|
-
# @param
|
781
|
+
# @overload lighten($color, $amount)
|
782
|
+
# @param $color [Sass::Script::Value::Color]
|
783
|
+
# @param $amount [Sass::Script::Value::Number] The amount to increase the
|
784
|
+
# lightness by, between `0%` and `100%`
|
751
785
|
# @return [Sass::Script::Value::Color]
|
752
|
-
# @
|
753
|
-
#
|
754
|
-
# or `number` isn't a number between 0% and 100%
|
786
|
+
# @raise [ArgumentError] if `$amount` is out of bounds, or either parameter
|
787
|
+
# is the wrong type
|
755
788
|
def lighten(color, amount)
|
756
789
|
_adjust(color, amount, :lightness, 0..100, :+, "%")
|
757
790
|
end
|
758
791
|
declare :lighten, [:color, :amount]
|
759
792
|
|
760
|
-
# Makes a color darker.
|
761
|
-
#
|
762
|
-
# and returns a color with the lightness decreased by that value.
|
793
|
+
# Makes a color darker. Takes a color and a number between 0% and 100%, and
|
794
|
+
# returns a color with the lightness decreased by that amount.
|
763
795
|
#
|
796
|
+
# @see #lighten
|
764
797
|
# @example
|
765
798
|
# darken(hsl(25, 100%, 80%), 30%) => hsl(25, 100%, 50%)
|
766
799
|
# darken(#800, 20%) => #200
|
767
|
-
# @
|
768
|
-
# @param
|
800
|
+
# @overload darken($color, $amount)
|
801
|
+
# @param $color [Sass::Script::Value::Color]
|
802
|
+
# @param $amount [Sass::Script::Value::Number] The amount to dencrease the
|
803
|
+
# lightness by, between `0%` and `100%`
|
769
804
|
# @return [Sass::Script::Value::Color]
|
770
|
-
# @
|
771
|
-
#
|
772
|
-
# or `number` isn't a number between 0% and 100%
|
805
|
+
# @raise [ArgumentError] if `$amount` is out of bounds, or either parameter
|
806
|
+
# is the wrong type
|
773
807
|
def darken(color, amount)
|
774
808
|
_adjust(color, amount, :lightness, 0..100, :-, "%")
|
775
809
|
end
|
776
810
|
declare :darken, [:color, :amount]
|
777
811
|
|
778
|
-
# Makes a color more saturated.
|
779
|
-
#
|
780
|
-
# and returns a color with the saturation increased by that value.
|
812
|
+
# Makes a color more saturated. Takes a color and a number between 0% and
|
813
|
+
# 100%, and returns a color with the saturation increased by that amount.
|
781
814
|
#
|
815
|
+
# @see #desaturate
|
782
816
|
# @example
|
783
817
|
# saturate(hsl(120, 30%, 90%), 20%) => hsl(120, 50%, 90%)
|
784
818
|
# saturate(#855, 20%) => #9e3f3f
|
785
|
-
# @overload saturate(color, amount)
|
786
|
-
#
|
787
|
-
#
|
788
|
-
#
|
789
|
-
#
|
790
|
-
#
|
791
|
-
#
|
819
|
+
# @overload saturate($color, $amount)
|
820
|
+
# @param $color [Sass::Script::Value::Color]
|
821
|
+
# @param $amount [Sass::Script::Value::Number] The amount to increase the
|
822
|
+
# saturation by, between `0%` and `100%`
|
823
|
+
# @return [Sass::Script::Value::Color]
|
824
|
+
# @raise [ArgumentError] if `$amount` is out of bounds, or either parameter
|
825
|
+
# is the wrong type
|
792
826
|
def saturate(color, amount = nil)
|
793
827
|
# Support the filter effects definition of saturate.
|
794
828
|
# https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html
|
@@ -798,93 +832,99 @@ module Sass::Script
|
|
798
832
|
declare :saturate, [:color, :amount]
|
799
833
|
declare :saturate, [:amount]
|
800
834
|
|
801
|
-
# Makes a color less saturated.
|
802
|
-
#
|
803
|
-
# and returns a color with the saturation decreased by that value.
|
835
|
+
# Makes a color less saturated. Takes a color and a number between 0% and
|
836
|
+
# 100%, and returns a color with the saturation decreased by that value.
|
804
837
|
#
|
838
|
+
# @see #saturate
|
805
839
|
# @example
|
806
840
|
# desaturate(hsl(120, 30%, 90%), 20%) => hsl(120, 10%, 90%)
|
807
841
|
# desaturate(#855, 20%) => #726b6b
|
808
|
-
# @
|
809
|
-
# @param
|
842
|
+
# @overload desaturate($color, $amount)
|
843
|
+
# @param $color [Sass::Script::Value::Color]
|
844
|
+
# @param $amount [Sass::Script::Value::Number] The amount to decrease the
|
845
|
+
# saturation by, between `0%` and `100%`
|
810
846
|
# @return [Sass::Script::Value::Color]
|
811
|
-
# @
|
812
|
-
#
|
813
|
-
# or `number` isn't a number between 0% and 100%
|
847
|
+
# @raise [ArgumentError] if `$amount` is out of bounds, or either parameter
|
848
|
+
# is the wrong type
|
814
849
|
def desaturate(color, amount)
|
815
850
|
_adjust(color, amount, :saturation, 0..100, :-, "%")
|
816
851
|
end
|
817
852
|
declare :desaturate, [:color, :amount]
|
818
853
|
|
819
|
-
# Changes the hue of a color
|
820
|
-
#
|
821
|
-
#
|
854
|
+
# Changes the hue of a color. Takes a color and a number of degrees (usually
|
855
|
+
# between `-360deg` and `360deg`), and returns a color with the hue rotated
|
856
|
+
# along the color wheel by that amount.
|
822
857
|
#
|
823
858
|
# @example
|
824
859
|
# adjust-hue(hsl(120, 30%, 90%), 60deg) => hsl(180, 30%, 90%)
|
825
860
|
# adjust-hue(hsl(120, 30%, 90%), 060deg) => hsl(60, 30%, 90%)
|
826
861
|
# adjust-hue(#811, 45deg) => #886a11
|
827
|
-
# @
|
828
|
-
# @param
|
829
|
-
# @
|
830
|
-
#
|
862
|
+
# @overload adjust_hue($color, $degrees)
|
863
|
+
# @param $color [Sass::Script::Value::Color]
|
864
|
+
# @param $degrees [Sass::Script::Value::Number] The number of degrees to
|
865
|
+
# rotate the hue
|
866
|
+
# @return [Sass::Script::Value::Color]
|
867
|
+
# @raise [ArgumentError] if either parameter is the wrong type
|
831
868
|
def adjust_hue(color, degrees)
|
832
|
-
assert_type color, :Color
|
833
|
-
assert_type degrees, :Number
|
869
|
+
assert_type color, :Color, :color
|
870
|
+
assert_type degrees, :Number, :degrees
|
834
871
|
color.with(:hue => color.hue + degrees.value)
|
835
872
|
end
|
836
873
|
declare :adjust_hue, [:color, :degrees]
|
837
874
|
|
838
|
-
#
|
839
|
-
# suitable for passing to IE filters.
|
875
|
+
# Converts a color into the format understood by IE filters.
|
840
876
|
#
|
841
877
|
# @example
|
842
878
|
# ie-hex-str(#abc) => #FFAABBCC
|
843
879
|
# ie-hex-str(#3322BB) => #FF3322BB
|
844
880
|
# ie-hex-str(rgba(0, 255, 0, 0.5)) => #8000FF00
|
845
|
-
# @
|
846
|
-
# @
|
847
|
-
# @
|
881
|
+
# @overload ie_hex_str($color)
|
882
|
+
# @param $color [Sass::Script::Value::Color]
|
883
|
+
# @return [Sass::Script::Value::String] The IE-formatted string
|
884
|
+
# representation of the color
|
885
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
848
886
|
def ie_hex_str(color)
|
849
|
-
assert_type color, :Color
|
887
|
+
assert_type color, :Color, :color
|
850
888
|
alpha = (color.alpha * 255).round.to_s(16).rjust(2, '0')
|
851
889
|
Sass::Script::Value::String.new("##{alpha}#{color.send(:hex_str)[1..-1]}".upcase)
|
852
890
|
end
|
853
891
|
declare :ie_hex_str, [:color]
|
854
892
|
|
855
|
-
#
|
856
|
-
#
|
857
|
-
#
|
858
|
-
#
|
859
|
-
#
|
860
|
-
# `$red`, `$green`, and `$blue` properties should be between 0 and 255.
|
861
|
-
# `$saturation` and `$lightness` should be between 0% and 100%.
|
862
|
-
# `$alpha` should be between 0 and 1.
|
893
|
+
# Increases or decreases one or more properties of a color. This can change
|
894
|
+
# the red, green, blue, hue, saturation, value, and alpha properties. The
|
895
|
+
# properties are specified as keyword arguments, and are added to or
|
896
|
+
# subtracted from the color's current value for that property.
|
863
897
|
#
|
864
|
-
# All properties are optional.
|
865
|
-
#
|
866
|
-
#
|
898
|
+
# All properties are optional. You can't specify both RGB properties
|
899
|
+
# (`$red`, `$green`, `$blue`) and HSL properties (`$hue`, `$saturation`,
|
900
|
+
# `$value`) at the same time.
|
867
901
|
#
|
868
902
|
# @example
|
869
903
|
# adjust-color(#102030, $blue: 5) => #102035
|
870
904
|
# adjust-color(#102030, $red: -5, $blue: 5) => #0b2035
|
871
905
|
# adjust-color(hsl(25, 100%, 80%), $lightness: -30%, $alpha: -0.4) => hsla(25, 100%, 50%, 0.6)
|
872
|
-
# @
|
873
|
-
# @
|
874
|
-
# @
|
875
|
-
#
|
876
|
-
# @
|
877
|
-
#
|
878
|
-
# @
|
879
|
-
#
|
906
|
+
# @overload adjust_color($color, [$red], [$green], [$blue], [$hue], [$saturation], [$lightness], [$alpha])
|
907
|
+
# @param $color [Sass::Script::Value::Color]
|
908
|
+
# @param $red [Sass::Script::Value::Number] The adjustment to make on the
|
909
|
+
# red component, between -255 and 255 inclusive
|
910
|
+
# @param $green [Sass::Script::Value::Number] The adjustment to make on the
|
911
|
+
# green component, between -255 and 255 inclusive
|
912
|
+
# @param $blue [Sass::Script::Value::Number] The adjustment to make on the
|
913
|
+
# blue component, between -255 and 255 inclusive
|
914
|
+
# @param $hue [Sass::Script::Value::Number] The adjustment to make on the
|
915
|
+
# hue component, in degrees
|
916
|
+
# @param $saturation [Sass::Script::Value::Number] The adjustment to make on
|
917
|
+
# the saturation component, between `-100%` and `100%` inclusive
|
918
|
+
# @param $lightness [Sass::Script::Value::Number] The adjustment to make on
|
919
|
+
# the lightness component, between `-100%` and `100%` inclusive
|
920
|
+
# @param $alpha [Sass::Script::Value::Number] The adjustment to make on the
|
921
|
+
# alpha component, between -1 and 1 inclusive
|
880
922
|
# @return [Sass::Script::Value::Color]
|
881
|
-
# @raise [ArgumentError] if
|
882
|
-
# if
|
883
|
-
#
|
884
|
-
# if an unexpected keyword argument is given,
|
885
|
-
# or if both HSL and RGB properties are given.
|
923
|
+
# @raise [ArgumentError] if any parameter is the wrong type or out-of
|
924
|
+
# bounds, or if RGB properties and HSL properties are adjusted at the
|
925
|
+
# same time
|
886
926
|
def adjust_color(color, kwargs)
|
887
|
-
assert_type color, :Color
|
927
|
+
assert_type color, :Color, :color
|
888
928
|
with = Sass::Util.map_hash({
|
889
929
|
"red" => [-255..255, ""],
|
890
930
|
"green" => [-255..255, ""],
|
@@ -912,47 +952,47 @@ module Sass::Script
|
|
912
952
|
end
|
913
953
|
declare :adjust_color, [:color], :var_kwargs => true
|
914
954
|
|
915
|
-
#
|
916
|
-
#
|
917
|
-
# \{#scale_color scale-color} fluidly changes them based on how
|
918
|
-
# That means that lightening an already-light
|
919
|
-
# won't change the lightness much,
|
920
|
-
# but lightening a dark color by the same amount will change it more
|
921
|
-
# This has the benefit of making `scale-color($color, ...)`
|
922
|
-
# regardless of what `$color` is.
|
923
|
-
#
|
924
|
-
# For example, the lightness of a color can be anywhere between 0 and
|
925
|
-
# If `scale-color($color, $lightness: 40%)` is called, the resulting
|
926
|
-
# will be 40% of the way between its original lightness
|
927
|
-
# If `scale-color($color, $lightness: -40%)` is called instead,
|
928
|
-
#
|
929
|
-
#
|
930
|
-
# This can change the red, green, blue, saturation, value, and alpha
|
931
|
-
# The properties are specified as keyword arguments.
|
932
|
-
#
|
933
|
-
#
|
934
|
-
# All properties are optional.
|
935
|
-
#
|
936
|
-
#
|
955
|
+
# Fluidly scales one or more properties of a color. Unlike
|
956
|
+
# \{#adjust_color adjust-color}, which changes a color's properties by fixed
|
957
|
+
# amounts, \{#scale_color scale-color} fluidly changes them based on how
|
958
|
+
# high or low they already are. That means that lightening an already-light
|
959
|
+
# color with \{#scale_color scale-color} won't change the lightness much,
|
960
|
+
# but lightening a dark color by the same amount will change it more
|
961
|
+
# dramatically. This has the benefit of making `scale-color($color, ...)`
|
962
|
+
# have a similar effect regardless of what `$color` is.
|
963
|
+
#
|
964
|
+
# For example, the lightness of a color can be anywhere between `0%` and
|
965
|
+
# `100%`. If `scale-color($color, $lightness: 40%)` is called, the resulting
|
966
|
+
# color's lightness will be 40% of the way between its original lightness
|
967
|
+
# and 100. If `scale-color($color, $lightness: -40%)` is called instead, the
|
968
|
+
# lightness will be 40% of the way between the original and 0.
|
969
|
+
#
|
970
|
+
# This can change the red, green, blue, saturation, value, and alpha
|
971
|
+
# properties. The properties are specified as keyword arguments. All
|
972
|
+
# arguments should be percentages between `0%` and `100%`.
|
973
|
+
#
|
974
|
+
# All properties are optional. You can't specify both RGB properties
|
975
|
+
# (`$red`, `$green`, `$blue`) and HSL properties (`$saturation`, `$value`)
|
976
|
+
# at the same time.
|
937
977
|
#
|
938
978
|
# @example
|
939
|
-
# scale-color(hsl(120, 70
|
940
|
-
# scale-color(rgb(200, 150
|
941
|
-
# scale-color(hsl(200, 70
|
942
|
-
# @
|
943
|
-
# @
|
944
|
-
# @
|
945
|
-
# @
|
946
|
-
# @
|
947
|
-
# @
|
948
|
-
# @
|
979
|
+
# scale-color(hsl(120, 70%, 80%), $lightness: 50%) => hsl(120, 70%, 90%)
|
980
|
+
# scale-color(rgb(200, 150%, 170%), $green: -40%, $blue: 70%) => rgb(200, 90, 229)
|
981
|
+
# scale-color(hsl(200, 70%, 80%), $saturation: -90%, $alpha: -30%) => hsla(200, 7%, 80%, 0.7)
|
982
|
+
# @overload scale_color($color, [$red], [$green], [$blue], [$saturation], [$lightness], [$alpha])
|
983
|
+
# @param $color [Sass::Script::Value::Color]
|
984
|
+
# @param $red [Sass::Script::Value::Number]
|
985
|
+
# @param $green [Sass::Script::Value::Number]
|
986
|
+
# @param $blue [Sass::Script::Value::Number]
|
987
|
+
# @param $saturation [Sass::Script::Value::Number]
|
988
|
+
# @param $lightness [Sass::Script::Value::Number]
|
989
|
+
# @param $alpha [Sass::Script::Value::Number]
|
949
990
|
# @return [Sass::Script::Value::Color]
|
950
|
-
# @raise [ArgumentError] if
|
951
|
-
#
|
952
|
-
#
|
953
|
-
# or if both HSL and RGB properties are given.
|
991
|
+
# @raise [ArgumentError] if any parameter is the wrong type or out-of
|
992
|
+
# bounds, or if RGB properties and HSL properties are adjusted at the
|
993
|
+
# same time
|
954
994
|
def scale_color(color, kwargs)
|
955
|
-
assert_type color, :Color
|
995
|
+
assert_type color, :Color, :color
|
956
996
|
with = Sass::Util.map_hash({
|
957
997
|
"red" => 255,
|
958
998
|
"green" => 255,
|
@@ -982,39 +1022,41 @@ module Sass::Script
|
|
982
1022
|
end
|
983
1023
|
declare :scale_color, [:color], :var_kwargs => true
|
984
1024
|
|
985
|
-
# Changes one or more properties of a color.
|
986
|
-
#
|
987
|
-
#
|
988
|
-
#
|
989
|
-
#
|
990
|
-
# `$red`, `$green`, and `$blue` properties should be between 0 and 255.
|
991
|
-
# `$saturation` and `$lightness` should be between 0% and 100%.
|
992
|
-
# `$alpha` should be between 0 and 1.
|
1025
|
+
# Changes one or more properties of a color. This can change the red, green,
|
1026
|
+
# blue, hue, saturation, value, and alpha properties. The properties are
|
1027
|
+
# specified as keyword arguments, and replace the color's current value for
|
1028
|
+
# that property.
|
993
1029
|
#
|
994
|
-
# All properties are optional.
|
995
|
-
#
|
996
|
-
#
|
1030
|
+
# All properties are optional. You can't specify both RGB properties
|
1031
|
+
# (`$red`, `$green`, `$blue`) and HSL properties (`$hue`, `$saturation`,
|
1032
|
+
# `$value`) at the same time.
|
997
1033
|
#
|
998
1034
|
# @example
|
999
1035
|
# change-color(#102030, $blue: 5) => #102005
|
1000
1036
|
# change-color(#102030, $red: 120, $blue: 5) => #782005
|
1001
1037
|
# change-color(hsl(25, 100%, 80%), $lightness: 40%, $alpha: 0.8) => hsla(25, 100%, 40%, 0.8)
|
1002
|
-
# @
|
1003
|
-
# @
|
1004
|
-
# @
|
1005
|
-
#
|
1006
|
-
# @
|
1007
|
-
#
|
1008
|
-
# @
|
1009
|
-
#
|
1038
|
+
# @overload change_color($color, [$red], [$green], [$blue], [$hue], [$saturation], [$lightness], [$alpha])
|
1039
|
+
# @param $color [Sass::Script::Value::Color]
|
1040
|
+
# @param $red [Sass::Script::Value::Number] The new red component for the
|
1041
|
+
# color, within 0 and 255 inclusive
|
1042
|
+
# @param $green [Sass::Script::Value::Number] The new green component for
|
1043
|
+
# the color, within 0 and 255 inclusive
|
1044
|
+
# @param $blue [Sass::Script::Value::Number] The new blue component for the
|
1045
|
+
# color, within 0 and 255 inclusive
|
1046
|
+
# @param $hue [Sass::Script::Value::Number] The new hue component for the
|
1047
|
+
# color, in degrees
|
1048
|
+
# @param $saturation [Sass::Script::Value::Number] The new saturation
|
1049
|
+
# component for the color, between `0%` and `100%` inclusive
|
1050
|
+
# @param $lightness [Sass::Script::Value::Number] The new lightness
|
1051
|
+
# component for the color, within `0%` and `100%` inclusive
|
1052
|
+
# @param $alpha [Sass::Script::Value::Number] The new alpha component for
|
1053
|
+
# the color, within 0 and 1 inclusive
|
1010
1054
|
# @return [Sass::Script::Value::Color]
|
1011
|
-
# @raise [ArgumentError] if
|
1012
|
-
# if
|
1013
|
-
#
|
1014
|
-
# if an unexpected keyword argument is given,
|
1015
|
-
# or if both HSL and RGB properties are given.
|
1055
|
+
# @raise [ArgumentError] if any parameter is the wrong type or out-of
|
1056
|
+
# bounds, or if RGB properties and HSL properties are adjusted at the
|
1057
|
+
# same time
|
1016
1058
|
def change_color(color, kwargs)
|
1017
|
-
assert_type color, :Color
|
1059
|
+
assert_type color, :Color, :color
|
1018
1060
|
with = Sass::Util.map_hash(%w[red green blue hue saturation lightness alpha]) do |name, max|
|
1019
1061
|
next unless val = kwargs.delete(name)
|
1020
1062
|
assert_type val, :Number, name
|
@@ -1030,33 +1072,32 @@ module Sass::Script
|
|
1030
1072
|
end
|
1031
1073
|
declare :change_color, [:color], :var_kwargs => true
|
1032
1074
|
|
1033
|
-
# Mixes
|
1034
|
-
#
|
1035
|
-
#
|
1036
|
-
# The opacity of the colors is also considered when weighting the components.
|
1075
|
+
# Mixes two colors together. Specifically, takes the average of each of the
|
1076
|
+
# RGB components, optionally weighted by the given percentage. The opacity
|
1077
|
+
# of the colors is also considered when weighting the components.
|
1037
1078
|
#
|
1038
1079
|
# The weight specifies the amount of the first color that should be included
|
1039
|
-
# in the returned color.
|
1040
|
-
#
|
1041
|
-
# and
|
1042
|
-
# 25% means that a quarter of the first color
|
1043
|
-
# and three quarters of the second color should be used.
|
1080
|
+
# in the returned color. The default, `50%`, means that half the first color
|
1081
|
+
# and half the second color should be used. `25%` means that a quarter of
|
1082
|
+
# the first color and three quarters of the second color should be used.
|
1044
1083
|
#
|
1045
1084
|
# @example
|
1046
1085
|
# mix(#f00, #00f) => #7f007f
|
1047
1086
|
# mix(#f00, #00f, 25%) => #3f00bf
|
1048
1087
|
# mix(rgba(255, 0, 0, 0.5), #00f) => rgba(63, 0, 191, 0.75)
|
1049
|
-
# @overload mix(
|
1050
|
-
#
|
1051
|
-
#
|
1052
|
-
#
|
1053
|
-
#
|
1054
|
-
#
|
1055
|
-
#
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
assert_type
|
1088
|
+
# @overload mix($color-1, $color-2, $weight: 50%)
|
1089
|
+
# @param $color-1 [Sass::Script::Value::Color]
|
1090
|
+
# @param $color-2 [Sass::Script::Value::Color]
|
1091
|
+
# @param $weight [Sass::Script::Value::Number] The relative weight of each
|
1092
|
+
# color. Closer to `0%` gives more weight to `$color`, closer to `100%`
|
1093
|
+
# gives more weight to `$color2`
|
1094
|
+
# @return [Sass::Script::Value::Color]
|
1095
|
+
# @raise [ArgumentError] if `$weight` is out of bounds or any parameter is
|
1096
|
+
# the wrong type
|
1097
|
+
def mix(color_1, color_2, weight = Sass::Script::Value::Number.new(50))
|
1098
|
+
assert_type color_1, :Color, :color_1
|
1099
|
+
assert_type color_2, :Color, :color_2
|
1100
|
+
assert_type weight, :Number, :weight
|
1060
1101
|
|
1061
1102
|
Sass::Util.check_range("Weight", 0..100, weight, '%')
|
1062
1103
|
|
@@ -1065,11 +1106,11 @@ module Sass::Script
|
|
1065
1106
|
# to perform the weighted average of the two RGB values.
|
1066
1107
|
#
|
1067
1108
|
# It works by first normalizing both parameters to be within [-1, 1],
|
1068
|
-
# where 1 indicates "only use
|
1109
|
+
# where 1 indicates "only use color_1", -1 indicates "only use color_2", and
|
1069
1110
|
# all values in between indicated a proportionately weighted average.
|
1070
1111
|
#
|
1071
1112
|
# Once we have the normalized variables w and a, we apply the formula
|
1072
|
-
# (w + a)/(1 + w*a) to get the combined weight (in [-1, 1]) of
|
1113
|
+
# (w + a)/(1 + w*a) to get the combined weight (in [-1, 1]) of color_1.
|
1073
1114
|
# This formula has two especially nice properties:
|
1074
1115
|
#
|
1075
1116
|
# * When either w or a are -1 or 1, the combined weight is also that number
|
@@ -1077,29 +1118,30 @@ module Sass::Script
|
|
1077
1118
|
#
|
1078
1119
|
# * When a is 0, the combined weight is w, and vice versa.
|
1079
1120
|
#
|
1080
|
-
# Finally, the weight of
|
1081
|
-
# and the weight of
|
1121
|
+
# Finally, the weight of color_1 is renormalized to be within [0, 1]
|
1122
|
+
# and the weight of color_2 is given by 1 minus the weight of color_1.
|
1082
1123
|
p = (weight.value/100.0).to_f
|
1083
1124
|
w = p*2 - 1
|
1084
|
-
a =
|
1125
|
+
a = color_1.alpha - color_2.alpha
|
1085
1126
|
|
1086
1127
|
w1 = (((w * a == -1) ? w : (w + a)/(1 + w*a)) + 1)/2.0
|
1087
1128
|
w2 = 1 - w1
|
1088
1129
|
|
1089
|
-
rgb =
|
1090
|
-
alpha =
|
1130
|
+
rgb = color_1.rgb.zip(color_2.rgb).map {|v1, v2| v1*w1 + v2*w2}
|
1131
|
+
alpha = color_1.alpha*p + color_2.alpha*(1-p)
|
1091
1132
|
Sass::Script::Value::Color.new(rgb + [alpha])
|
1092
1133
|
end
|
1093
1134
|
declare :mix, [:color_1, :color_2]
|
1094
1135
|
declare :mix, [:color_1, :color_2, :weight]
|
1095
1136
|
|
1096
|
-
# Converts a color to grayscale.
|
1097
|
-
#
|
1137
|
+
# Converts a color to grayscale. This is identical to `desaturate(color,
|
1138
|
+
# 100%)`.
|
1098
1139
|
#
|
1099
|
-
# @param color [Sass::Script::Value::Color]
|
1100
|
-
# @return [Sass::Script::Value::Color]
|
1101
|
-
# @raise [ArgumentError] if `color` isn't a color
|
1102
1140
|
# @see #desaturate
|
1141
|
+
# @overload grayscale($color)
|
1142
|
+
# @param $color [Sass::Script::Value::Color]
|
1143
|
+
# @return [Sass::Script::Value::Color]
|
1144
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
1103
1145
|
def grayscale(color)
|
1104
1146
|
if color.is_a?(Sass::Script::Value::Number)
|
1105
1147
|
return Sass::Script::Value::String.new("grayscale(#{color})")
|
@@ -1108,30 +1150,32 @@ module Sass::Script
|
|
1108
1150
|
end
|
1109
1151
|
declare :grayscale, [:color]
|
1110
1152
|
|
1111
|
-
# Returns the complement of a color.
|
1112
|
-
#
|
1153
|
+
# Returns the complement of a color. This is identical to `adjust-hue(color,
|
1154
|
+
# 180deg)`.
|
1113
1155
|
#
|
1114
|
-
# @param color [Sass::Script::Value::Color]
|
1115
|
-
# @return [Sass::Script::Value::Color]
|
1116
|
-
# @raise [ArgumentError] if `color` isn't a color
|
1117
1156
|
# @see #adjust_hue #adjust-hue
|
1157
|
+
# @overload complement($color)
|
1158
|
+
# @param $color [Sass::Script::Value::Color]
|
1159
|
+
# @return [Sass::Script::Value::Color]
|
1160
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
1118
1161
|
def complement(color)
|
1119
1162
|
adjust_hue color, Sass::Script::Value::Number.new(180)
|
1120
1163
|
end
|
1121
1164
|
declare :complement, [:color]
|
1122
1165
|
|
1123
|
-
# Returns the inverse (negative) of a color.
|
1124
|
-
#
|
1166
|
+
# Returns the inverse (negative) of a color. The red, green, and blue values
|
1167
|
+
# are inverted, while the opacity is left alone.
|
1125
1168
|
#
|
1126
|
-
# @
|
1169
|
+
# @overload invert($color)
|
1170
|
+
# @param $color [Sass::Script::Value::Color]
|
1127
1171
|
# @return [Sass::Script::Value::Color]
|
1128
|
-
# @raise [ArgumentError] if
|
1172
|
+
# @raise [ArgumentError] if `$color` isn't a color
|
1129
1173
|
def invert(color)
|
1130
1174
|
if color.is_a?(Sass::Script::Value::Number)
|
1131
1175
|
return Sass::Script::Value::String.new("invert(#{color})")
|
1132
1176
|
end
|
1133
1177
|
|
1134
|
-
assert_type color, :Color
|
1178
|
+
assert_type color, :Color, :color
|
1135
1179
|
color.with(
|
1136
1180
|
:red => (255 - color.red),
|
1137
1181
|
:green => (255 - color.green),
|
@@ -1139,16 +1183,17 @@ module Sass::Script
|
|
1139
1183
|
end
|
1140
1184
|
declare :invert, [:color]
|
1141
1185
|
|
1142
|
-
# Removes quotes from a string
|
1143
|
-
#
|
1186
|
+
# Removes quotes from a string. If the string is already unquoted, this will
|
1187
|
+
# return it unmodified.
|
1144
1188
|
#
|
1145
|
-
# @param string [Sass::Script::Value::String]
|
1146
|
-
# @return [Sass::Script::Value::String]
|
1147
|
-
# @raise [ArgumentError] if `string` isn't a string
|
1148
1189
|
# @see #quote
|
1149
1190
|
# @example
|
1150
1191
|
# unquote("foo") => foo
|
1151
1192
|
# unquote(foo) => foo
|
1193
|
+
# @overload unquote($string)
|
1194
|
+
# @param $string [Sass::Script::Value::String]
|
1195
|
+
# @return [Sass::Script::Value::String]
|
1196
|
+
# @raise [ArgumentError] if `$string` isn't a string
|
1152
1197
|
def unquote(string)
|
1153
1198
|
if string.is_a?(Sass::Script::Value::String)
|
1154
1199
|
Sass::Script::Value::String.new(string.value, :identifier)
|
@@ -1161,113 +1206,117 @@ module Sass::Script
|
|
1161
1206
|
# Add quotes to a string if the string isn't quoted,
|
1162
1207
|
# or returns the same string if it is.
|
1163
1208
|
#
|
1164
|
-
# @param string [Sass::Script::Value::String]
|
1165
|
-
# @return [Sass::Script::Value::String]
|
1166
|
-
# @raise [ArgumentError] if `string` isn't a string
|
1167
1209
|
# @see #unquote
|
1168
1210
|
# @example
|
1169
1211
|
# quote("foo") => "foo"
|
1170
1212
|
# quote(foo) => "foo"
|
1213
|
+
# @overload quote($string)
|
1214
|
+
# @param $string [Sass::Script::Value::String]
|
1215
|
+
# @return [Sass::Script::Value::String]
|
1216
|
+
# @raise [ArgumentError] if `$string` isn't a string
|
1171
1217
|
def quote(string)
|
1172
|
-
assert_type string, :String
|
1218
|
+
assert_type string, :String, :string
|
1173
1219
|
Sass::Script::Value::String.new(string.value, :string)
|
1174
1220
|
end
|
1175
1221
|
declare :quote, [:string]
|
1176
1222
|
|
1177
1223
|
# Returns the number of characters in a string.
|
1178
1224
|
#
|
1179
|
-
# @return [Sass::Script::Value::Number]
|
1180
|
-
# @raise [ArgumentError] if `string` isn't a string
|
1181
1225
|
# @example
|
1182
1226
|
# str-length("foo") => 3
|
1227
|
+
# @overload str_length($string)
|
1228
|
+
# @param $string [Sass::Script::Value::String]
|
1229
|
+
# @return [Sass::Script::Value::Number]
|
1230
|
+
# @raise [ArgumentError] if `$string` isn't a string
|
1183
1231
|
def str_length(string)
|
1184
|
-
assert_type string, :String
|
1232
|
+
assert_type string, :String, :string
|
1185
1233
|
Sass::Script::Value::Number.new(string.value.size)
|
1186
1234
|
end
|
1187
1235
|
declare :str_length, [:string]
|
1188
1236
|
|
1189
|
-
# Inserts
|
1237
|
+
# Inserts `$insert` into `$string` at `$index`.
|
1190
1238
|
#
|
1191
|
-
#
|
1192
|
-
# the
|
1239
|
+
# Note that unlike some languages, the first character in a Sass string is
|
1240
|
+
# number 1, the second number 2, and so forth.
|
1193
1241
|
#
|
1194
|
-
# @param original [Sass::Script::Value::String]
|
1195
|
-
# The string that will receive the insertion.
|
1196
|
-
# @param insert [Sass::Script::Value::String]
|
1197
|
-
# The string that will be inserted.
|
1198
|
-
# @param index [Sass::Script::Value::Number]
|
1199
|
-
# The position where inserted string will start.
|
1200
|
-
# Negative indices count from the end of the original string.
|
1201
|
-
#
|
1202
|
-
# @return [Sass::Script::Value::String] A new string
|
1203
|
-
# @raise [ArgumentError] if `$original` isn't a string, `$insert` isn't a string, or `$index` isn't a number.
|
1204
1242
|
# @example
|
1205
1243
|
# str-insert("abcd", "X", 1) => "Xabcd"
|
1206
1244
|
# str-insert("abcd", "X", 4) => "abcXd"
|
1207
|
-
# str-insert("abcd", "X",
|
1208
|
-
#
|
1245
|
+
# str-insert("abcd", "X", 5) => "abcXd"
|
1246
|
+
#
|
1247
|
+
# @overload str_insert($string, $insert, $index)
|
1248
|
+
# @param $string [Sass::Script::Value::String]
|
1249
|
+
# @param $insert [Sass::Script::Value::String]
|
1250
|
+
# @param $index [Sass::Script::Value::Number] The position at which
|
1251
|
+
# `$insert` will be inserted. Negative indices count from the end of
|
1252
|
+
# `$string`. An index that's outside the bounds of the string will insert
|
1253
|
+
# `$insert` at the front or back of the string
|
1254
|
+
# @return [Sass::Script::Value::String] The result string. This will be
|
1255
|
+
# quoted if and only if `$string` was quoted
|
1256
|
+
# @raise [ArgumentError] if any parameter is the wrong type
|
1209
1257
|
def str_insert(original, insert, index)
|
1210
|
-
assert_type original, :String,
|
1211
|
-
assert_type insert, :String,
|
1212
|
-
assert_integer index,
|
1213
|
-
assert_unit index, nil,
|
1258
|
+
assert_type original, :String, :string
|
1259
|
+
assert_type insert, :String, :insert
|
1260
|
+
assert_integer index, :index
|
1261
|
+
assert_unit index, nil, :index
|
1214
1262
|
insertion_point = index.value > 0 ? [index.value - 1, original.value.size].min : [index.value, -original.value.size - 1].max
|
1215
1263
|
Sass::Script::Value::String.new(original.value.dup.insert(insertion_point, insert.value), original.type)
|
1216
1264
|
end
|
1217
|
-
declare :str_insert, [:
|
1265
|
+
declare :str_insert, [:string, :insert, :index]
|
1218
1266
|
|
1219
|
-
#
|
1220
|
-
#
|
1267
|
+
# Returns the index of the first occurance of `$substring` in `$string`. If
|
1268
|
+
# there is no such occurance, returns 0.
|
1269
|
+
#
|
1270
|
+
# Note that unlike some languages, the first character in a Sass string is
|
1271
|
+
# number 1, the second number 2, and so forth.
|
1221
1272
|
#
|
1222
|
-
# @return [Sass::Script::Value::Number] The index of the substring, or 0 if not found.
|
1223
|
-
# @raise [ArgumentError] if `original` isn't a string, `insert` isn't a string, or `index` isn't a number.
|
1224
|
-
# @param string The string to search
|
1225
|
-
# @param substring The string to search for
|
1226
1273
|
# @example
|
1227
1274
|
# str-index(abcd, a) => 1
|
1228
1275
|
# str-index(abcd, ab) => 1
|
1229
1276
|
# str-index(abcd, X) => 0
|
1230
1277
|
# str-index(abcd, c) => 3
|
1278
|
+
#
|
1279
|
+
# @overload str_index($string, $substring)
|
1280
|
+
# @param $string [Sass::Script::Value::String]
|
1281
|
+
# @param $substring [Sass::Script::Value::String]
|
1282
|
+
# @return [Sass::Script::Value::Number]
|
1283
|
+
# @raise [ArgumentError] if any parameter is the wrong type
|
1231
1284
|
def str_index(string, substring)
|
1232
|
-
assert_type string, :String
|
1233
|
-
assert_type substring, :String
|
1285
|
+
assert_type string, :String, :string
|
1286
|
+
assert_type substring, :String, :substring
|
1234
1287
|
index = string.value.index(substring.value) || -1
|
1235
1288
|
Sass::Script::Value::Number.new(index + 1)
|
1236
1289
|
end
|
1237
1290
|
declare :str_index, [:string, :substring]
|
1238
1291
|
|
1239
1292
|
|
1240
|
-
#
|
1293
|
+
# Extracts a substring from `$string`. The substring will begin at index
|
1294
|
+
# `$start-at` and ends at index `$end-at`.
|
1295
|
+
#
|
1296
|
+
# Note that unlike some languages, the first character in a Sass string is
|
1297
|
+
# number 1, the second number 2, and so forth.
|
1241
1298
|
#
|
1242
|
-
# @return [Sass::Script::Value::String] A new string
|
1243
|
-
# @param start_at
|
1244
|
-
# The index (inclusive) of the first character to slice out of the string.
|
1245
|
-
# If negative, counts from the end of the string.
|
1246
|
-
# @param end_at
|
1247
|
-
# The index (inclusive) of the last character to slice out of the string.
|
1248
|
-
# @overload str_slice(string, start_at)
|
1249
|
-
# Slice starting at `start_at` to the end of the string.
|
1250
|
-
# @overload str_slice(string, start_at, end_at)
|
1251
|
-
# Slice starting at `start_at` to `end_at`
|
1252
|
-
# @raise [ArgumentError] if `string` isn't a string or `start_at` and `end_at` aren't unitless numbers
|
1253
1299
|
# @example
|
1254
|
-
# str-slice(abcd,
|
1255
|
-
# str-slice(abcd,
|
1256
|
-
# str-slice(abcd,
|
1257
|
-
# str-slice(abcd,
|
1258
|
-
#
|
1259
|
-
#
|
1260
|
-
#
|
1261
|
-
#
|
1262
|
-
#
|
1263
|
-
#
|
1264
|
-
#
|
1265
|
-
#
|
1300
|
+
# str-slice("abcd", 2, 3) => "bc"
|
1301
|
+
# str-slice("abcd", 2) => "bcd"
|
1302
|
+
# str-slice("abcd", -3, -2) => "bc"
|
1303
|
+
# str-slice("abcd", 2, -2) => "bc"
|
1304
|
+
#
|
1305
|
+
# @overload str_slice($string, $start-at, $end-at: -1)
|
1306
|
+
# @param $start-at [Sass::Script::Value::Number] The index of the first
|
1307
|
+
# character of the substring. If this is negative, it counts from the end
|
1308
|
+
# of `$string`
|
1309
|
+
# @param $end-before [Sass::Script::Value::Number] The index of the last
|
1310
|
+
# character of the substring. If this is negative, it counts from the end
|
1311
|
+
# of `$string`. Defaults to -1
|
1312
|
+
# @return [Sass::Script::Value::String] The substring. This will be quoted
|
1313
|
+
# if and only if `$string` was quoted
|
1314
|
+
# @raise [ArgumentError] if any parameter is the wrong type
|
1266
1315
|
def str_slice(string, start_at, end_at = nil)
|
1267
|
-
assert_type string, :String
|
1316
|
+
assert_type string, :String, :string
|
1268
1317
|
assert_unit start_at, nil, "start-at"
|
1269
1318
|
|
1270
|
-
end_at = Sass::Script::Value::Number.new(-1)if end_at.nil?
|
1319
|
+
end_at = Sass::Script::Value::Number.new(-1) if end_at.nil?
|
1271
1320
|
assert_unit end_at, nil, "end-at"
|
1272
1321
|
|
1273
1322
|
s = start_at.value > 0 ? start_at.value - 1 : start_at.value
|
@@ -1282,33 +1331,37 @@ module Sass::Script
|
|
1282
1331
|
declare :str_slice, [:string, :start_at]
|
1283
1332
|
declare :str_slice, [:string, :start_at, :end_at]
|
1284
1333
|
|
1285
|
-
#
|
1334
|
+
# Converts a string to upper case.
|
1286
1335
|
#
|
1287
|
-
# @return [Sass::Script::Value::String]
|
1288
|
-
# @raise [ArgumentError] if `string` isn't a string
|
1289
1336
|
# @example
|
1290
1337
|
# to-upper-case(abcd) => ABCD
|
1291
|
-
#
|
1338
|
+
#
|
1339
|
+
# @overload to_upper_case($string)
|
1340
|
+
# @param $string [Sass::Script::Value::String]
|
1341
|
+
# @return [Sass::Script::Value::String]
|
1342
|
+
# @raise [ArgumentError] if `$string` isn't a string
|
1292
1343
|
def to_upper_case(string)
|
1293
|
-
assert_type string, :String
|
1344
|
+
assert_type string, :String, :string
|
1294
1345
|
Sass::Script::Value::String.new(string.value.upcase, string.type)
|
1295
1346
|
end
|
1296
1347
|
declare :to_upper_case, [:string]
|
1297
1348
|
|
1298
|
-
# Convert a string to lower case
|
1349
|
+
# Convert a string to lower case,
|
1299
1350
|
#
|
1300
|
-
# @return [Sass::Script::Value::String]
|
1301
|
-
# @raise [ArgumentError] if `string` isn't a string
|
1302
1351
|
# @example
|
1303
1352
|
# to-lower-case(ABCD) => abcd
|
1304
|
-
#
|
1353
|
+
#
|
1354
|
+
# @overload to_lower_case($string)
|
1355
|
+
# @param $string [Sass::Script::Value::String]
|
1356
|
+
# @return [Sass::Script::Value::String]
|
1357
|
+
# @raise [ArgumentError] if `$string` isn't a string
|
1305
1358
|
def to_lower_case(string)
|
1306
|
-
assert_type string, :String
|
1359
|
+
assert_type string, :String, :string
|
1307
1360
|
Sass::Script::Value::String.new(string.value.downcase, string.type)
|
1308
1361
|
end
|
1309
1362
|
declare :to_lower_case, [:string]
|
1310
1363
|
|
1311
|
-
#
|
1364
|
+
# Returns the type of a value.
|
1312
1365
|
#
|
1313
1366
|
# @example
|
1314
1367
|
# type-of(100px) => number
|
@@ -1317,29 +1370,33 @@ module Sass::Script
|
|
1317
1370
|
# type-of(true) => bool
|
1318
1371
|
# type-of(#fff) => color
|
1319
1372
|
# type-of(blue) => color
|
1320
|
-
# @
|
1321
|
-
# @
|
1373
|
+
# @overload type_of($value)
|
1374
|
+
# @param $value [Sass::Script::Value::Base] The value to inspect
|
1375
|
+
# @return [Sass::Script::Value::String] The unquoted string name of the
|
1376
|
+
# value's type
|
1322
1377
|
def type_of(value)
|
1323
1378
|
Sass::Script::Value::String.new(value.class.name.gsub(/Sass::Script::Value::/,'').downcase)
|
1324
1379
|
end
|
1325
1380
|
declare :type_of, [:value]
|
1326
1381
|
|
1327
|
-
# Returns
|
1382
|
+
# Returns whether a feature exists in the current Sass runtime.
|
1328
1383
|
#
|
1329
1384
|
# @example
|
1330
1385
|
# feature-exists(some-feature-that-exists) => true
|
1331
1386
|
# feature-exists(what-is-this-i-dont-know) => false
|
1332
1387
|
#
|
1333
|
-
# @
|
1334
|
-
# @
|
1388
|
+
# @overload feature_exists($feature)
|
1389
|
+
# @param $feature [Sass::Script::Value::String] The name of the feature
|
1390
|
+
# @return [Sass::Script::Value::Bool] Whether the feature is supported in this version of Sass
|
1391
|
+
# @raise [ArgumentError] if `$feature` isn't a string
|
1335
1392
|
def feature_exists(feature)
|
1393
|
+
assert_type feature, :String, :feature
|
1336
1394
|
Sass::Script::Value::Bool.new(Sass.has_feature?(feature.value))
|
1337
1395
|
end
|
1338
1396
|
declare :feature_exists, [:feature]
|
1339
1397
|
|
1340
|
-
|
1341
|
-
#
|
1342
|
-
# Complex units are sorted in alphabetical order by numerator and denominator.
|
1398
|
+
# Returns the unit(s) associated with a number. Complex units are sorted in
|
1399
|
+
# alphabetical order by numerator and denominator.
|
1343
1400
|
#
|
1344
1401
|
# @example
|
1345
1402
|
# unit(100) => ""
|
@@ -1347,57 +1404,62 @@ module Sass::Script
|
|
1347
1404
|
# unit(3em) => "em"
|
1348
1405
|
# unit(10px * 5em) => "em*px"
|
1349
1406
|
# unit(10px * 5em / 30cm / 1rem) => "em*px/cm*rem"
|
1350
|
-
# @
|
1351
|
-
# @
|
1352
|
-
# @
|
1407
|
+
# @overload unit($number)
|
1408
|
+
# @param $number [Sass::Script::Value::Number]
|
1409
|
+
# @return [Sass::Script::Value::String] The unit(s) of the number, as a
|
1410
|
+
# quoted string
|
1411
|
+
# @raise [ArgumentError] if `$number` isn't a number
|
1353
1412
|
def unit(number)
|
1354
|
-
assert_type number, :Number
|
1413
|
+
assert_type number, :Number, :number
|
1355
1414
|
Sass::Script::Value::String.new(number.unit_str, :string)
|
1356
1415
|
end
|
1357
1416
|
declare :unit, [:number]
|
1358
1417
|
|
1359
|
-
#
|
1418
|
+
# Returns whether a number has units.
|
1360
1419
|
#
|
1361
1420
|
# @example
|
1362
1421
|
# unitless(100) => true
|
1363
1422
|
# unitless(100px) => false
|
1364
|
-
# @
|
1365
|
-
# @
|
1366
|
-
# @
|
1423
|
+
# @overload unitless($number)
|
1424
|
+
# @param $number [Sass::Script::Value::Number]
|
1425
|
+
# @return [Sass::Script::Value::Bool]
|
1426
|
+
# @raise [ArgumentError] if `$number` isn't a number
|
1367
1427
|
def unitless(number)
|
1368
|
-
assert_type number, :Number
|
1428
|
+
assert_type number, :Number, :number
|
1369
1429
|
Sass::Script::Value::Bool.new(number.unitless?)
|
1370
1430
|
end
|
1371
1431
|
declare :unitless, [:number]
|
1372
1432
|
|
1373
|
-
# Returns
|
1433
|
+
# Returns whether two numbers can added, subtracted, or compared.
|
1374
1434
|
#
|
1375
1435
|
# @example
|
1376
1436
|
# comparable(2px, 1px) => true
|
1377
1437
|
# comparable(100px, 3em) => false
|
1378
1438
|
# comparable(10cm, 3mm) => true
|
1379
|
-
# @
|
1380
|
-
# @param
|
1381
|
-
# @
|
1382
|
-
# @
|
1439
|
+
# @overload comparable($number-1, $number-2)
|
1440
|
+
# @param $number-1 [Sass::Script::Value::Number]
|
1441
|
+
# @param $number-2 [Sass::Script::Value::Number]
|
1442
|
+
# @return [Sass::Script::Value::Bool]
|
1443
|
+
# @raise [ArgumentError] if either parameter is the wrong type
|
1383
1444
|
def comparable(number_1, number_2)
|
1384
|
-
assert_type number_1, :Number
|
1385
|
-
assert_type number_2, :Number
|
1445
|
+
assert_type number_1, :Number, :number_1
|
1446
|
+
assert_type number_2, :Number, :number_2
|
1386
1447
|
Sass::Script::Value::Bool.new(number_1.comparable_to?(number_2))
|
1387
1448
|
end
|
1388
1449
|
declare :comparable, [:number_1, :number_2]
|
1389
1450
|
|
1390
|
-
# Converts a
|
1451
|
+
# Converts a unitless number to a percentage.
|
1391
1452
|
#
|
1392
1453
|
# @example
|
1454
|
+
# percentage(0.2) => 20%
|
1393
1455
|
# percentage(100px / 50px) => 200%
|
1394
|
-
# @
|
1395
|
-
#
|
1396
|
-
# @return [Sass::Script::Value::Number]
|
1397
|
-
# @raise [ArgumentError]
|
1456
|
+
# @overload percentage($value)
|
1457
|
+
# @param $value [Sass::Script::Value::Number]
|
1458
|
+
# @return [Sass::Script::Value::Number]
|
1459
|
+
# @raise [ArgumentError] if `$value` isn't a unitless number
|
1398
1460
|
def percentage(value)
|
1399
1461
|
unless value.is_a?(Sass::Script::Value::Number) && value.unitless?
|
1400
|
-
raise ArgumentError.new("#{value.inspect} is not a unitless number")
|
1462
|
+
raise ArgumentError.new("$value: #{value.inspect} is not a unitless number")
|
1401
1463
|
end
|
1402
1464
|
Sass::Script::Value::Number.new(value.value * 100, ['%'])
|
1403
1465
|
end
|
@@ -1408,76 +1470,83 @@ module Sass::Script
|
|
1408
1470
|
# @example
|
1409
1471
|
# round(10.4px) => 10px
|
1410
1472
|
# round(10.6px) => 11px
|
1411
|
-
# @
|
1412
|
-
# @
|
1413
|
-
# @
|
1473
|
+
# @overload round($value)
|
1474
|
+
# @param $value [Sass::Script::Value::Number]
|
1475
|
+
# @return [Sass::Script::Value::Number]
|
1476
|
+
# @raise [ArgumentError] if `$value` isn't a number
|
1414
1477
|
def round(value)
|
1415
1478
|
numeric_transformation(value) {|n| n.round}
|
1416
1479
|
end
|
1417
1480
|
declare :round, [:value]
|
1418
1481
|
|
1419
|
-
# Rounds a number up to the
|
1482
|
+
# Rounds a number up to the next whole number.
|
1420
1483
|
#
|
1421
1484
|
# @example
|
1422
1485
|
# ceil(10.4px) => 11px
|
1423
1486
|
# ceil(10.6px) => 11px
|
1424
|
-
# @
|
1425
|
-
# @
|
1426
|
-
# @
|
1487
|
+
# @overload ceil($value)
|
1488
|
+
# @param $value [Sass::Script::Value::Number]
|
1489
|
+
# @return [Sass::Script::Value::Number]
|
1490
|
+
# @raise [ArgumentError] if `$value` isn't a number
|
1427
1491
|
def ceil(value)
|
1428
1492
|
numeric_transformation(value) {|n| n.ceil}
|
1429
1493
|
end
|
1430
1494
|
declare :ceil, [:value]
|
1431
1495
|
|
1432
|
-
# Rounds down to the
|
1496
|
+
# Rounds a number down to the previous whole number.
|
1433
1497
|
#
|
1434
1498
|
# @example
|
1435
1499
|
# floor(10.4px) => 10px
|
1436
1500
|
# floor(10.6px) => 10px
|
1437
|
-
# @
|
1438
|
-
# @
|
1439
|
-
# @
|
1501
|
+
# @overload floor($value)
|
1502
|
+
# @param $value [Sass::Script::Value::Number]
|
1503
|
+
# @return [Sass::Script::Value::Number]
|
1504
|
+
# @raise [ArgumentError] if `$value` isn't a number
|
1440
1505
|
def floor(value)
|
1441
1506
|
numeric_transformation(value) {|n| n.floor}
|
1442
1507
|
end
|
1443
1508
|
declare :floor, [:value]
|
1444
1509
|
|
1445
|
-
#
|
1510
|
+
# Returns the absolute value of a number.
|
1446
1511
|
#
|
1447
1512
|
# @example
|
1448
1513
|
# abs(10px) => 10px
|
1449
1514
|
# abs(-10px) => 10px
|
1450
|
-
# @
|
1451
|
-
# @
|
1452
|
-
# @
|
1515
|
+
# @overload abs($value)
|
1516
|
+
# @param $value [Sass::Script::Value::Number]
|
1517
|
+
# @return [Sass::Script::Value::Number]
|
1518
|
+
# @raise [ArgumentError] if `$value` isn't a number
|
1453
1519
|
def abs(value)
|
1454
1520
|
numeric_transformation(value) {|n| n.abs}
|
1455
1521
|
end
|
1456
1522
|
declare :abs, [:value]
|
1457
1523
|
|
1458
|
-
# Finds the minimum of several
|
1524
|
+
# Finds the minimum of several numbers. This function takes any number of
|
1459
1525
|
# arguments.
|
1460
1526
|
#
|
1461
1527
|
# @example
|
1462
1528
|
# min(1px, 4px) => 1px
|
1463
1529
|
# min(5em, 3em, 4em) => 3em
|
1464
|
-
# @
|
1465
|
-
# @
|
1530
|
+
# @overload min($numbers...)
|
1531
|
+
# @param $numbers [[Sass::Script::Value::Number]]
|
1532
|
+
# @return [Sass::Script::Value::Number]
|
1466
1533
|
# @raise [ArgumentError] if any argument isn't a number, or if not all of
|
1467
1534
|
# the arguments have comparable units
|
1468
|
-
def min(*
|
1469
|
-
|
1470
|
-
|
1535
|
+
def min(*numbers)
|
1536
|
+
numbers.each {|n| assert_type n, :Number}
|
1537
|
+
numbers.inject {|min, num| min.lt(num).to_bool ? min : num}
|
1471
1538
|
end
|
1472
1539
|
declare :min, [], :var_args => :true
|
1473
1540
|
|
1474
|
-
# Finds the maximum of several
|
1541
|
+
# Finds the maximum of several numbers. This function takes any number of
|
1475
1542
|
# arguments.
|
1476
1543
|
#
|
1477
1544
|
# @example
|
1478
1545
|
# max(1px, 4px) => 4px
|
1479
1546
|
# max(5em, 3em, 4em) => 5em
|
1480
|
-
# @
|
1547
|
+
# @overload max($numbers...)
|
1548
|
+
# @param $numbers [[Sass::Script::Value::Number]]
|
1549
|
+
# @return [Sass::Script::Value::Number]
|
1481
1550
|
# @raise [ArgumentError] if any argument isn't a number, or if not all of
|
1482
1551
|
# the arguments have comparable units
|
1483
1552
|
def max(*values)
|
@@ -1491,8 +1560,9 @@ module Sass::Script
|
|
1491
1560
|
# @example
|
1492
1561
|
# length(10px) => 1
|
1493
1562
|
# length(10px 20px 30px) => 3
|
1494
|
-
# @
|
1495
|
-
# @
|
1563
|
+
# @overload length($list)
|
1564
|
+
# @param $list [Sass::Script::Value::Base]
|
1565
|
+
# @return [Sass::Script::Value::Number]
|
1496
1566
|
def length(list)
|
1497
1567
|
Sass::Script::Value::Number.new(list.to_a.size)
|
1498
1568
|
end
|
@@ -1500,21 +1570,21 @@ module Sass::Script
|
|
1500
1570
|
|
1501
1571
|
# Gets the nth item in a list.
|
1502
1572
|
#
|
1503
|
-
# Note that unlike some languages, the first item in a Sass list is number
|
1504
|
-
# the second number 2, and so forth.
|
1505
|
-
# count from the end of the list. So -1 is the last item, -2 is the
|
1506
|
-
# second-to-last item, etc.
|
1573
|
+
# Note that unlike some languages, the first item in a Sass list is number
|
1574
|
+
# 1, the second number 2, and so forth.
|
1507
1575
|
#
|
1508
1576
|
# @example
|
1509
1577
|
# nth(10px 20px 30px, 1) => 10px
|
1510
1578
|
# nth((Helvetica, Arial, sans-serif), 3) => sans-serif
|
1511
|
-
#
|
1512
|
-
# @param list [Value]
|
1513
|
-
# @param n [Sass::Script::Value::Number] The index
|
1514
|
-
#
|
1515
|
-
# @
|
1579
|
+
# @overload nth($list, $n)
|
1580
|
+
# @param $list [Sass::Script::Value::Base]
|
1581
|
+
# @param $n [Sass::Script::Value::Number] The index of the item to get.
|
1582
|
+
# Negative indices count from the end of the list.
|
1583
|
+
# @return [Sass::Script::Value::Base]
|
1584
|
+
# @raise [ArgumentError] if `$n` isn't an integer between 1 and the length
|
1585
|
+
# of `$list`
|
1516
1586
|
def nth(list, n)
|
1517
|
-
assert_type n, :Number
|
1587
|
+
assert_type n, :Number, :n
|
1518
1588
|
if !n.int? || n.to_i == 0
|
1519
1589
|
raise ArgumentError.new("List index #{n} must be a non-zero integer")
|
1520
1590
|
elsif list.to_a.size == 0
|
@@ -1528,12 +1598,12 @@ module Sass::Script
|
|
1528
1598
|
end
|
1529
1599
|
declare :nth, [:list, :n]
|
1530
1600
|
|
1531
|
-
# Joins together two lists into
|
1601
|
+
# Joins together two lists into one.
|
1532
1602
|
#
|
1533
|
-
# Unless
|
1534
|
-
#
|
1535
|
-
#
|
1536
|
-
#
|
1603
|
+
# Unless `$separator` is passed, if one list is comma-separated and one is
|
1604
|
+
# space-separated, the first parameter's separator is used for the resulting
|
1605
|
+
# list. If both lists have fewer than two items, spaces are used for the
|
1606
|
+
# resulting list.
|
1537
1607
|
#
|
1538
1608
|
# @example
|
1539
1609
|
# join(10px 20px, 30px 40px) => 10px 20px 30px 40px
|
@@ -1541,15 +1611,15 @@ module Sass::Script
|
|
1541
1611
|
# join(10px, 20px) => 10px 20px
|
1542
1612
|
# join(10px, 20px, comma) => 10px, 20px
|
1543
1613
|
# join((blue, red), (#abc, #def), space) => blue red #abc #def
|
1544
|
-
# @overload join(list1, list2, separator: auto)
|
1545
|
-
#
|
1546
|
-
#
|
1547
|
-
#
|
1548
|
-
#
|
1549
|
-
#
|
1550
|
-
#
|
1614
|
+
# @overload join($list1, $list2, $separator: auto)
|
1615
|
+
# @param $list1 [Sass::Script::Value::Base]
|
1616
|
+
# @param $list2 [Sass::Script::Value::Base]
|
1617
|
+
# @param $separator [Sass::Script::Value::String] The list separator to use.
|
1618
|
+
# If this is `comma` or `space`, that separator will be used. If this is
|
1619
|
+
# `auto` (the default), the separator is determined as explained above.
|
1620
|
+
# @return [Sass::Script::Value::List]
|
1551
1621
|
def join(list1, list2, separator = Sass::Script::Value::String.new("auto"))
|
1552
|
-
assert_type separator, :String
|
1622
|
+
assert_type separator, :String, :separator
|
1553
1623
|
unless %w[auto space comma].include?(separator.value)
|
1554
1624
|
raise ArgumentError.new("Separator name must be space, comma, or auto")
|
1555
1625
|
end
|
@@ -1568,8 +1638,7 @@ module Sass::Script
|
|
1568
1638
|
|
1569
1639
|
# Appends a single value onto the end of a list.
|
1570
1640
|
#
|
1571
|
-
# Unless the `$separator` argument is passed,
|
1572
|
-
# if the list has only one item,
|
1641
|
+
# Unless the `$separator` argument is passed, if the list had only one item,
|
1573
1642
|
# the resulting list will be space-separated.
|
1574
1643
|
#
|
1575
1644
|
# @example
|
@@ -1578,15 +1647,15 @@ module Sass::Script
|
|
1578
1647
|
# append(10px 20px, 30px 40px) => 10px 20px (30px 40px)
|
1579
1648
|
# append(10px, 20px, comma) => 10px, 20px
|
1580
1649
|
# append((blue, red), green, space) => blue red green
|
1581
|
-
# @overload append(list, val, separator: auto)
|
1582
|
-
#
|
1583
|
-
#
|
1584
|
-
#
|
1585
|
-
#
|
1586
|
-
#
|
1587
|
-
#
|
1588
|
-
def append(list, val, separator = Sass::Script::
|
1589
|
-
assert_type separator, :String
|
1650
|
+
# @overload append($list, $val, $separator: auto)
|
1651
|
+
# @param $list [Sass::Script::Value::Base]
|
1652
|
+
# @param $val [Sass::Script::Value::Base]
|
1653
|
+
# @param $separator [Sass::Script::Value::String] The list separator to use.
|
1654
|
+
# If this is `comma` or `space`, that separator will be used. If this is
|
1655
|
+
# `auto` (the default), the separator is determined as explained above.
|
1656
|
+
# @return [Sass::Script::Value::List]
|
1657
|
+
def append(list, val, separator = Sass::Script::String.new("auto"))
|
1658
|
+
assert_type separator, :String, :separator
|
1590
1659
|
unless %w[auto space comma].include?(separator.value)
|
1591
1660
|
raise ArgumentError.new("Separator name must be space, comma, or auto")
|
1592
1661
|
end
|
@@ -1602,8 +1671,9 @@ module Sass::Script
|
|
1602
1671
|
declare :append, [:list, :val]
|
1603
1672
|
declare :append, [:list, :val, :separator]
|
1604
1673
|
|
1605
|
-
# Combines several lists into a single
|
1606
|
-
#
|
1674
|
+
# Combines several lists into a single multidimensional list. The nth value
|
1675
|
+
# of the resulting list is a space separated list of the source lists' nth
|
1676
|
+
# values.
|
1607
1677
|
#
|
1608
1678
|
# The length of the resulting list is the length of the
|
1609
1679
|
# shortest list.
|
@@ -1611,6 +1681,9 @@ module Sass::Script
|
|
1611
1681
|
# @example
|
1612
1682
|
# zip(1px 1px 3px, solid dashed solid, red green blue)
|
1613
1683
|
# => 1px solid red, 1px dashed green, 3px solid blue
|
1684
|
+
# @overload zip($lists...)
|
1685
|
+
# @param $lists [[Sass::Script::Value::Base]]
|
1686
|
+
# @return [Sass::Script::Value::List]
|
1614
1687
|
def zip(*lists)
|
1615
1688
|
length = nil
|
1616
1689
|
values = []
|
@@ -1628,12 +1701,20 @@ module Sass::Script
|
|
1628
1701
|
declare :zip, [], :var_args => true
|
1629
1702
|
|
1630
1703
|
|
1631
|
-
# Returns the position of a value within a list. If
|
1632
|
-
# false.
|
1704
|
+
# Returns the position of a value within a list. If the value isn't found,
|
1705
|
+
# returns false instead.
|
1706
|
+
#
|
1707
|
+
# Note that unlike some languages, the first item in a Sass list is number
|
1708
|
+
# 1, the second number 2, and so forth.
|
1633
1709
|
#
|
1634
1710
|
# @example
|
1635
1711
|
# index(1px solid red, solid) => 2
|
1636
1712
|
# index(1px solid red, dashed) => false
|
1713
|
+
# @overload index($list, $value)
|
1714
|
+
# @param $list [Sass::Script::Value::Base]
|
1715
|
+
# @param $value [Sass::Script::Value::Base]
|
1716
|
+
# @return [Sass::Script::Value::Number, Sass::Script::Value::Bool] The
|
1717
|
+
# 1-based index of `$value` in `$list`, or `false`
|
1637
1718
|
def index(list, value)
|
1638
1719
|
index = list.to_a.index {|e| e.eq(value).to_bool }
|
1639
1720
|
if index
|
@@ -1644,13 +1725,16 @@ module Sass::Script
|
|
1644
1725
|
end
|
1645
1726
|
declare :index, [:list, :value]
|
1646
1727
|
|
1647
|
-
# Returns the separator of the
|
1648
|
-
#
|
1728
|
+
# Returns the separator of a list. If the list doesn't have a separator due
|
1729
|
+
# to having fewer than two elements, returns `space`.
|
1649
1730
|
#
|
1650
1731
|
# @example
|
1651
|
-
# list-separator(1px 2px 3px) =>
|
1652
|
-
# list-separator(1px, 2px, 3px) =>
|
1653
|
-
# list-separator('foo') =>
|
1732
|
+
# list-separator(1px 2px 3px) => space
|
1733
|
+
# list-separator(1px, 2px, 3px) => comma
|
1734
|
+
# list-separator('foo') => space
|
1735
|
+
# @overload list_separator($list)
|
1736
|
+
# @param $list [Sass::Script::Value::Base]
|
1737
|
+
# @return [Sass::Script::Value::String] `comma` or `space`
|
1654
1738
|
def list_separator(list)
|
1655
1739
|
if list.is_a?(Sass::Script::Value::List)
|
1656
1740
|
Sass::Script::Value::String.new(list.separator.to_s)
|
@@ -1660,15 +1744,19 @@ module Sass::Script
|
|
1660
1744
|
end
|
1661
1745
|
declare :separator, [:list]
|
1662
1746
|
|
1663
|
-
# Returns one of two values
|
1747
|
+
# Returns one of two values, depending on whether or not `$condition` is
|
1748
|
+
# true. Just like in `@if`, all values other than `false` and `null` are
|
1749
|
+
# considered to be true.
|
1664
1750
|
#
|
1665
1751
|
# @example
|
1666
1752
|
# if(true, 1px, 2px) => 1px
|
1667
1753
|
# if(false, 1px, 2px) => 2px
|
1668
|
-
# @
|
1669
|
-
#
|
1670
|
-
#
|
1671
|
-
# @param
|
1754
|
+
# @overload if($condition, $if-true, $if-false)
|
1755
|
+
# @param $condition [Sass::Script::Value::Base] Whether the `$if-true` or
|
1756
|
+
# `$if-false` will be returned
|
1757
|
+
# @param $if-true [Sass::Script::Value::Base]
|
1758
|
+
# @param $if-false [Sass::Script::Value::Base]
|
1759
|
+
# @return [Sass::Script::Value::Base] `$if-true` or `$if-false`
|
1672
1760
|
def if(condition, if_true, if_false)
|
1673
1761
|
if condition.to_bool
|
1674
1762
|
if_true
|
@@ -1678,9 +1766,12 @@ module Sass::Script
|
|
1678
1766
|
end
|
1679
1767
|
declare :if, [:condition, :if_true, :if_false]
|
1680
1768
|
|
1681
|
-
# Returns a unique
|
1682
|
-
# identifier returned is only guaranteed to be unique within the
|
1683
|
-
# single Sass run.
|
1769
|
+
# Returns a unique CSS identifier. The identifier is returned as an unquoted
|
1770
|
+
# string. The identifier returned is only guaranteed to be unique within the
|
1771
|
+
# scope of a single Sass run.
|
1772
|
+
#
|
1773
|
+
# @overload unique_id()
|
1774
|
+
# @return [Sass::Script::Value::String]
|
1684
1775
|
def unique_id
|
1685
1776
|
Thread.current[:sass_last_unique_id] ||= rand(36**8)
|
1686
1777
|
# avoid the temptation of trying to guess the next unique value.
|
@@ -1697,6 +1788,8 @@ module Sass::Script
|
|
1697
1788
|
#
|
1698
1789
|
# @example
|
1699
1790
|
# counter(item, ".") => counter(item,".")
|
1791
|
+
# @overload counter($args...)
|
1792
|
+
# @return [String]
|
1700
1793
|
def counter(*args)
|
1701
1794
|
Sass::Script::Value::String.new("counter(#{args.map {|a| a.to_s(options)}.join(',')})")
|
1702
1795
|
end
|
@@ -1708,13 +1801,13 @@ module Sass::Script
|
|
1708
1801
|
# another numeric value with the same units.
|
1709
1802
|
# It yields a number to a block to perform the operation and return a number
|
1710
1803
|
def numeric_transformation(value)
|
1711
|
-
assert_type value, :Number
|
1804
|
+
assert_type value, :Number, :value
|
1712
1805
|
Sass::Script::Value::Number.new(yield(value.value), value.numerator_units, value.denominator_units)
|
1713
1806
|
end
|
1714
1807
|
|
1715
1808
|
def _adjust(color, amount, attr, range, op, units = "")
|
1716
|
-
assert_type color, :Color
|
1717
|
-
assert_type amount, :Number
|
1809
|
+
assert_type color, :Color, :color
|
1810
|
+
assert_type amount, :Number, :amount
|
1718
1811
|
Sass::Util.check_range('Amount', range, amount, units)
|
1719
1812
|
|
1720
1813
|
# TODO: is it worth restricting here,
|