sass-embedded 1.74.1-aarch64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +48 -0
- data/exe/sass +21 -0
- data/ext/sass/cli.rb +12 -0
- data/ext/sass/dart-sass/sass.bat +7 -0
- data/ext/sass/dart-sass/src/LICENSE +1687 -0
- data/ext/sass/dart-sass/src/dart.exe +0 -0
- data/ext/sass/dart-sass/src/sass.snapshot +0 -0
- data/ext/sass/embedded_sass_pb.rb +63 -0
- data/lib/sass/calculation_value/calculation_operation.rb +49 -0
- data/lib/sass/calculation_value.rb +22 -0
- data/lib/sass/canonicalize_context.rb +21 -0
- data/lib/sass/compile_result.rb +24 -0
- data/lib/sass/compiler/channel.rb +68 -0
- data/lib/sass/compiler/connection.rb +92 -0
- data/lib/sass/compiler/dispatcher.rb +115 -0
- data/lib/sass/compiler/host/function_registry.rb +87 -0
- data/lib/sass/compiler/host/importer_registry.rb +137 -0
- data/lib/sass/compiler/host/logger_registry.rb +55 -0
- data/lib/sass/compiler/host/protofier.rb +390 -0
- data/lib/sass/compiler/host/structifier.rb +37 -0
- data/lib/sass/compiler/host.rb +226 -0
- data/lib/sass/compiler/varint.rb +39 -0
- data/lib/sass/compiler.rb +212 -0
- data/lib/sass/elf.rb +276 -0
- data/lib/sass/embedded/version.rb +7 -0
- data/lib/sass/embedded.rb +107 -0
- data/lib/sass/embedded_protocol.rb +10 -0
- data/lib/sass/exception.rb +69 -0
- data/lib/sass/fork_tracker.rb +51 -0
- data/lib/sass/logger/silent.rb +28 -0
- data/lib/sass/logger/source_location.rb +22 -0
- data/lib/sass/logger/source_span.rb +28 -0
- data/lib/sass/node_package_importer.rb +17 -0
- data/lib/sass/serializer.rb +36 -0
- data/lib/sass/value/argument_list.rb +37 -0
- data/lib/sass/value/boolean.rb +52 -0
- data/lib/sass/value/calculation.rb +90 -0
- data/lib/sass/value/color.rb +253 -0
- data/lib/sass/value/function.rb +51 -0
- data/lib/sass/value/fuzzy_math.rb +80 -0
- data/lib/sass/value/list.rb +79 -0
- data/lib/sass/value/map.rb +71 -0
- data/lib/sass/value/mixin.rb +36 -0
- data/lib/sass/value/null.rb +48 -0
- data/lib/sass/value/number/unit.rb +186 -0
- data/lib/sass/value/number.rb +366 -0
- data/lib/sass/value/string.rb +61 -0
- data/lib/sass/value.rb +136 -0
- data/lib/sass-embedded.rb +4 -0
- metadata +120 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
# Sass's boolean type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/sassboolean/
|
8
|
+
class Boolean
|
9
|
+
include Value
|
10
|
+
|
11
|
+
# @param value [::Boolean]
|
12
|
+
def initialize(value)
|
13
|
+
@value = value
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [::Boolean]
|
17
|
+
attr_reader :value
|
18
|
+
|
19
|
+
# @return [Boolean]
|
20
|
+
def !
|
21
|
+
value ? Boolean::FALSE : Boolean::TRUE
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [::Boolean]
|
25
|
+
def ==(other)
|
26
|
+
other.is_a?(Sass::Value::Boolean) && other.value == value
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Integer]
|
30
|
+
def hash
|
31
|
+
@hash ||= value.hash
|
32
|
+
end
|
33
|
+
|
34
|
+
alias to_bool value
|
35
|
+
|
36
|
+
# @return [Boolean]
|
37
|
+
def assert_boolean(_name = nil)
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
# Sass's true value.
|
42
|
+
TRUE = Boolean.new(true)
|
43
|
+
|
44
|
+
# Sass's false value.
|
45
|
+
FALSE = Boolean.new(false)
|
46
|
+
|
47
|
+
def self.new(value)
|
48
|
+
value ? Boolean::TRUE : Boolean::FALSE
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
# Sass's calculation type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/sasscalculation/
|
8
|
+
class Calculation
|
9
|
+
include Value
|
10
|
+
include CalculationValue
|
11
|
+
|
12
|
+
class << self
|
13
|
+
private :new
|
14
|
+
|
15
|
+
# @param argument [CalculationValue]
|
16
|
+
# @return [Calculation]
|
17
|
+
def calc(argument)
|
18
|
+
new('calc', [argument])
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param arguments [Array<CalculationValue>]
|
22
|
+
# @return [Calculation]
|
23
|
+
def min(arguments)
|
24
|
+
new('min', arguments)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param arguments [Array<CalculationValue>]
|
28
|
+
# @return [Calculation]
|
29
|
+
def max(arguments)
|
30
|
+
new('max', arguments)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param min [CalculationValue]
|
34
|
+
# @param value [CalculationValue]
|
35
|
+
# @param max [CalculationValue]
|
36
|
+
# @return [Calculation]
|
37
|
+
def clamp(min, value = nil, max = nil)
|
38
|
+
if (value.nil? && !valid_clamp_arg?(min)) ||
|
39
|
+
(max.nil? && [min, value].none? { |x| x && valid_clamp_arg?(x) })
|
40
|
+
raise Sass::ScriptError, 'Argument must be an unquoted SassString.'
|
41
|
+
end
|
42
|
+
|
43
|
+
new('clamp', [min, value, max].compact)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def valid_clamp_arg?(value)
|
49
|
+
value.is_a?(Sass::Value::String) && !value.quoted?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def initialize(name, arguments)
|
56
|
+
arguments.each do |value|
|
57
|
+
assert_calculation_value(value)
|
58
|
+
end
|
59
|
+
|
60
|
+
@name = name.freeze
|
61
|
+
@arguments = arguments.freeze
|
62
|
+
end
|
63
|
+
|
64
|
+
public
|
65
|
+
|
66
|
+
# @return [::String]
|
67
|
+
attr_reader :name
|
68
|
+
|
69
|
+
# @return [Array<CalculationValue>]
|
70
|
+
attr_reader :arguments
|
71
|
+
|
72
|
+
# @return [Calculation]
|
73
|
+
def assert_calculation(_name = nil)
|
74
|
+
self
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [::Boolean]
|
78
|
+
def ==(other)
|
79
|
+
other.is_a?(Sass::Value::Calculation) &&
|
80
|
+
other.name == name &&
|
81
|
+
other.arguments == arguments
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [Integer]
|
85
|
+
def hash
|
86
|
+
@hash ||= [name, *arguments].hash
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
# Sass's color type.
|
6
|
+
#
|
7
|
+
# No matter what representation was originally used to create this color, all of its channels are accessible.
|
8
|
+
#
|
9
|
+
# @see https://sass-lang.com/documentation/js-api/classes/sasscolor/
|
10
|
+
class Color
|
11
|
+
include Value
|
12
|
+
|
13
|
+
# @param red [Numeric]
|
14
|
+
# @param green [Numeric]
|
15
|
+
# @param blue [Numeric]
|
16
|
+
# @param hue [Numeric]
|
17
|
+
# @param saturation [Numeric]
|
18
|
+
# @param lightness [Numeric]
|
19
|
+
# @param whiteness [Numeric]
|
20
|
+
# @param blackness [Numeric]
|
21
|
+
# @param alpha [Numeric]
|
22
|
+
def initialize(red: nil,
|
23
|
+
green: nil,
|
24
|
+
blue: nil,
|
25
|
+
hue: nil,
|
26
|
+
saturation: nil,
|
27
|
+
lightness: nil,
|
28
|
+
whiteness: nil,
|
29
|
+
blackness: nil,
|
30
|
+
alpha: 1)
|
31
|
+
@alpha = alpha.nil? ? 1 : FuzzyMath.assert_between(alpha, 0, 1, 'alpha')
|
32
|
+
if red && green && blue
|
33
|
+
@red = FuzzyMath.assert_between(FuzzyMath.round(red), 0, 255, 'red')
|
34
|
+
@green = FuzzyMath.assert_between(FuzzyMath.round(green), 0, 255, 'green')
|
35
|
+
@blue = FuzzyMath.assert_between(FuzzyMath.round(blue), 0, 255, 'blue')
|
36
|
+
elsif hue && saturation && lightness
|
37
|
+
@hue = hue % 360
|
38
|
+
@saturation = FuzzyMath.assert_between(saturation, 0, 100, 'saturation')
|
39
|
+
@lightness = FuzzyMath.assert_between(lightness, 0, 100, 'lightness')
|
40
|
+
elsif hue && whiteness && blackness
|
41
|
+
@hue = hue % 360
|
42
|
+
@whiteness = FuzzyMath.assert_between(whiteness, 0, 100, 'whiteness')
|
43
|
+
@blackness = FuzzyMath.assert_between(blackness, 0, 100, 'blackness')
|
44
|
+
hwb_to_rgb
|
45
|
+
@whiteness = @blackness = nil
|
46
|
+
else
|
47
|
+
raise Sass::ScriptError, 'Invalid Color'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Integer]
|
52
|
+
def red
|
53
|
+
hsl_to_rgb unless defined?(@red)
|
54
|
+
|
55
|
+
@red
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [Integer]
|
59
|
+
def green
|
60
|
+
hsl_to_rgb unless defined?(@green)
|
61
|
+
|
62
|
+
@green
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Integer]
|
66
|
+
def blue
|
67
|
+
hsl_to_rgb unless defined?(@blue)
|
68
|
+
|
69
|
+
@blue
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [Numeric]
|
73
|
+
def hue
|
74
|
+
rgb_to_hsl unless defined?(@hue)
|
75
|
+
|
76
|
+
@hue
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [Numeric]
|
80
|
+
def saturation
|
81
|
+
rgb_to_hsl unless defined?(@saturation)
|
82
|
+
|
83
|
+
@saturation
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Numeric]
|
87
|
+
def lightness
|
88
|
+
rgb_to_hsl unless defined?(@lightness)
|
89
|
+
|
90
|
+
@lightness
|
91
|
+
end
|
92
|
+
|
93
|
+
# @return [Numeric]
|
94
|
+
def whiteness
|
95
|
+
@whiteness ||= Rational([red, green, blue].min, 255) * 100
|
96
|
+
end
|
97
|
+
|
98
|
+
# @return [Numeric]
|
99
|
+
def blackness
|
100
|
+
@blackness ||= 100 - (Rational([red, green, blue].max, 255) * 100)
|
101
|
+
end
|
102
|
+
|
103
|
+
# @return [Numeric]
|
104
|
+
attr_reader :alpha
|
105
|
+
|
106
|
+
# @param red [Numeric]
|
107
|
+
# @param green [Numeric]
|
108
|
+
# @param blue [Numeric]
|
109
|
+
# @param hue [Numeric]
|
110
|
+
# @param saturation [Numeric]
|
111
|
+
# @param lightness [Numeric]
|
112
|
+
# @param whiteness [Numeric]
|
113
|
+
# @param blackness [Numeric]
|
114
|
+
# @param alpha [Numeric]
|
115
|
+
# @return [Color]
|
116
|
+
def change(red: nil,
|
117
|
+
green: nil,
|
118
|
+
blue: nil,
|
119
|
+
hue: nil,
|
120
|
+
saturation: nil,
|
121
|
+
lightness: nil,
|
122
|
+
whiteness: nil,
|
123
|
+
blackness: nil,
|
124
|
+
alpha: nil)
|
125
|
+
if whiteness || blackness
|
126
|
+
Sass::Value::Color.new(hue: hue || self.hue,
|
127
|
+
whiteness: whiteness || self.whiteness,
|
128
|
+
blackness: blackness || self.blackness,
|
129
|
+
alpha: alpha || self.alpha)
|
130
|
+
elsif hue || saturation || lightness
|
131
|
+
Sass::Value::Color.new(hue: hue || self.hue,
|
132
|
+
saturation: saturation || self.saturation,
|
133
|
+
lightness: lightness || self.lightness,
|
134
|
+
alpha: alpha || self.alpha)
|
135
|
+
elsif red || green || blue
|
136
|
+
Sass::Value::Color.new(red: red ? FuzzyMath.round(red) : self.red,
|
137
|
+
green: green ? FuzzyMath.round(green) : self.green,
|
138
|
+
blue: blue ? FuzzyMath.round(blue) : self.blue,
|
139
|
+
alpha: alpha || self.alpha)
|
140
|
+
else
|
141
|
+
dup.instance_eval do
|
142
|
+
@alpha = FuzzyMath.assert_between(alpha, 0, 1, 'alpha')
|
143
|
+
self
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# @return [::Boolean]
|
149
|
+
def ==(other)
|
150
|
+
other.is_a?(Sass::Value::Color) &&
|
151
|
+
other.red == red &&
|
152
|
+
other.green == green &&
|
153
|
+
other.blue == blue &&
|
154
|
+
other.alpha == alpha
|
155
|
+
end
|
156
|
+
|
157
|
+
# @return [Integer]
|
158
|
+
def hash
|
159
|
+
@hash ||= [red, green, blue, alpha].hash
|
160
|
+
end
|
161
|
+
|
162
|
+
# @return [Color]
|
163
|
+
def assert_color(_name = nil)
|
164
|
+
self
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
def rgb_to_hsl
|
170
|
+
scaled_red = Rational(red, 255)
|
171
|
+
scaled_green = Rational(green, 255)
|
172
|
+
scaled_blue = Rational(blue, 255)
|
173
|
+
|
174
|
+
max = [scaled_red, scaled_green, scaled_blue].max
|
175
|
+
min = [scaled_red, scaled_green, scaled_blue].min
|
176
|
+
delta = max - min
|
177
|
+
|
178
|
+
if max == min
|
179
|
+
@hue = 0
|
180
|
+
elsif max == scaled_red
|
181
|
+
@hue = ((scaled_green - scaled_blue) * 60 / delta) % 360
|
182
|
+
elsif max == scaled_green
|
183
|
+
@hue = (((scaled_blue - scaled_red) * 60 / delta) + 120) % 360
|
184
|
+
elsif max == scaled_blue
|
185
|
+
@hue = (((scaled_red - scaled_green) * 60 / delta) + 240) % 360
|
186
|
+
end
|
187
|
+
|
188
|
+
lightness = @lightness = (max + min) * 50
|
189
|
+
|
190
|
+
@saturation = if max == min
|
191
|
+
0
|
192
|
+
elsif lightness < 50
|
193
|
+
delta * 100 / (max + min)
|
194
|
+
else
|
195
|
+
delta * 100 / (2 - max - min)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def hsl_to_rgb
|
200
|
+
scaled_hue = Rational(hue, 360)
|
201
|
+
scaled_saturation = Rational(saturation, 100)
|
202
|
+
scaled_lightness = Rational(lightness, 100)
|
203
|
+
|
204
|
+
tmp2 = if scaled_lightness <= 0.5
|
205
|
+
scaled_lightness * (scaled_saturation + 1)
|
206
|
+
else
|
207
|
+
scaled_lightness + scaled_saturation - (scaled_lightness * scaled_saturation)
|
208
|
+
end
|
209
|
+
tmp1 = (scaled_lightness * 2) - tmp2
|
210
|
+
@red = FuzzyMath.round(hsl_hue_to_rgb(tmp1, tmp2, scaled_hue + Rational(1, 3)) * 255)
|
211
|
+
@green = FuzzyMath.round(hsl_hue_to_rgb(tmp1, tmp2, scaled_hue) * 255)
|
212
|
+
@blue = FuzzyMath.round(hsl_hue_to_rgb(tmp1, tmp2, scaled_hue - Rational(1, 3)) * 255)
|
213
|
+
end
|
214
|
+
|
215
|
+
def hsl_hue_to_rgb(tmp1, tmp2, hue)
|
216
|
+
hue += 1 if hue.negative?
|
217
|
+
hue -= 1 if hue > 1
|
218
|
+
|
219
|
+
if hue < Rational(1, 6)
|
220
|
+
tmp1 + ((tmp2 - tmp1) * hue * 6)
|
221
|
+
elsif hue < Rational(1, 2)
|
222
|
+
tmp2
|
223
|
+
elsif hue < Rational(2, 3)
|
224
|
+
tmp1 + ((tmp2 - tmp1) * (Rational(2, 3) - hue) * 6)
|
225
|
+
else
|
226
|
+
tmp1
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def hwb_to_rgb
|
231
|
+
scaled_hue = Rational(hue, 360)
|
232
|
+
scaled_whiteness = Rational(whiteness, 100)
|
233
|
+
scaled_blackness = Rational(blackness, 100)
|
234
|
+
|
235
|
+
sum = scaled_whiteness + scaled_blackness
|
236
|
+
if sum > 1
|
237
|
+
scaled_whiteness /= sum
|
238
|
+
scaled_blackness /= sum
|
239
|
+
end
|
240
|
+
|
241
|
+
factor = 1 - scaled_whiteness - scaled_blackness
|
242
|
+
@red = hwb_hue_to_rgb(factor, scaled_whiteness, scaled_hue + Rational(1, 3))
|
243
|
+
@green = hwb_hue_to_rgb(factor, scaled_whiteness, scaled_hue)
|
244
|
+
@blue = hwb_hue_to_rgb(factor, scaled_whiteness, scaled_hue - Rational(1, 3))
|
245
|
+
end
|
246
|
+
|
247
|
+
def hwb_hue_to_rgb(factor, scaled_whiteness, scaled_hue)
|
248
|
+
channel = (hsl_hue_to_rgb(0, 1, scaled_hue) * factor) + scaled_whiteness
|
249
|
+
FuzzyMath.round(channel * 255)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
# Sass's function type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/sassfunction/
|
8
|
+
class Function
|
9
|
+
include Value
|
10
|
+
|
11
|
+
# @param signature [::String]
|
12
|
+
# @param callback [Proc]
|
13
|
+
def initialize(signature, &callback)
|
14
|
+
raise Sass::ScriptError, 'no block given' unless signature.nil? || callback
|
15
|
+
|
16
|
+
@signature = signature.freeze
|
17
|
+
@callback = callback.freeze
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Integer, nil]
|
21
|
+
attr_reader :id
|
22
|
+
|
23
|
+
protected :id
|
24
|
+
|
25
|
+
# @return [::String, nil]
|
26
|
+
attr_reader :signature
|
27
|
+
|
28
|
+
# @return [Proc, nil]
|
29
|
+
attr_reader :callback
|
30
|
+
|
31
|
+
# @return [::Boolean]
|
32
|
+
def ==(other)
|
33
|
+
if id.nil?
|
34
|
+
other.equal?(self)
|
35
|
+
else
|
36
|
+
other.is_a?(Sass::Value::Function) && other.id == id
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Integer]
|
41
|
+
def hash
|
42
|
+
@hash ||= id.nil? ? signature.hash : id.hash
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Function]
|
46
|
+
def assert_function(_name = nil)
|
47
|
+
self
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
# Sass's {FuzzyMath} module.
|
6
|
+
module FuzzyMath
|
7
|
+
PRECISION = 10
|
8
|
+
|
9
|
+
EPSILON = 10.pow(-PRECISION - 1)
|
10
|
+
|
11
|
+
INVERSE_EPSILON = 1 / EPSILON
|
12
|
+
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def equals(number1, number2)
|
16
|
+
(number1 - number2).abs < EPSILON
|
17
|
+
end
|
18
|
+
|
19
|
+
def less_than(number1, number2)
|
20
|
+
number1 < number2 && !equals(number1, number2)
|
21
|
+
end
|
22
|
+
|
23
|
+
def less_than_or_equals(number1, number2)
|
24
|
+
number1 < number2 || equals(number1, number2)
|
25
|
+
end
|
26
|
+
|
27
|
+
def greater_than(number1, number2)
|
28
|
+
number1 > number2 && !equals(number1, number2)
|
29
|
+
end
|
30
|
+
|
31
|
+
def greater_than_or_equals(number1, number2)
|
32
|
+
number1 > number2 || equals(number1, number2)
|
33
|
+
end
|
34
|
+
|
35
|
+
def integer?(number)
|
36
|
+
return false unless number.finite?
|
37
|
+
return true if number.integer?
|
38
|
+
|
39
|
+
equals((number - 0.5).abs % 1, 0.5)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_i(number)
|
43
|
+
integer?(number) ? number.round : nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def round(number)
|
47
|
+
if number.positive?
|
48
|
+
less_than(number % 1, 0.5) ? number.floor : number.ceil
|
49
|
+
else
|
50
|
+
less_than_or_equals(number % 1, 0.5) ? number.floor : number.ceil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def between(number, min, max)
|
55
|
+
return min if equals(number, min)
|
56
|
+
return max if equals(number, max)
|
57
|
+
return number if number > min && number < max
|
58
|
+
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def assert_between(number, min, max, name)
|
63
|
+
result = between(number, min, max)
|
64
|
+
return result unless result.nil?
|
65
|
+
|
66
|
+
raise Sass::ScriptError.new("#{number} must be between #{min} and #{max}.", name)
|
67
|
+
end
|
68
|
+
|
69
|
+
def hash(number)
|
70
|
+
if number.finite?
|
71
|
+
(number * INVERSE_EPSILON).round.hash
|
72
|
+
else
|
73
|
+
number.hash
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private_constant :FuzzyMath
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
# Sass's list type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/sasslist/
|
8
|
+
class List
|
9
|
+
include Value
|
10
|
+
|
11
|
+
# @param contents [Array<Value>]
|
12
|
+
# @param separator [::String]
|
13
|
+
# @param bracketed [::Boolean]
|
14
|
+
def initialize(contents = [], separator: ',', bracketed: false)
|
15
|
+
if separator.nil? && contents.length > 1
|
16
|
+
raise Sass::ScriptError, 'A list with more than one element must have an explicit separator'
|
17
|
+
end
|
18
|
+
|
19
|
+
@contents = contents.freeze
|
20
|
+
@separator = separator.freeze
|
21
|
+
@bracketed = bracketed.freeze
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [::String, nil]
|
25
|
+
attr_reader :separator
|
26
|
+
|
27
|
+
# @return [::Boolean]
|
28
|
+
def bracketed?
|
29
|
+
@bracketed
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [::Boolean]
|
33
|
+
def ==(other)
|
34
|
+
(other.is_a?(Sass::Value::List) &&
|
35
|
+
other.to_a == to_a &&
|
36
|
+
other.separator == separator &&
|
37
|
+
other.bracketed? == bracketed?) ||
|
38
|
+
(to_a.empty? && other.is_a?(Sass::Value::Map) && other.to_a.empty?)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param index [Numeric]
|
42
|
+
# @return [Value]
|
43
|
+
def at(index)
|
44
|
+
index = index.floor
|
45
|
+
index = to_a.length + index if index.negative?
|
46
|
+
return nil if index.negative? || index >= to_a.length
|
47
|
+
|
48
|
+
to_a[index]
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Integer]
|
52
|
+
def hash
|
53
|
+
@hash ||= contents.hash
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Array<Value>]
|
57
|
+
def to_a
|
58
|
+
@contents
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Map, nil]
|
62
|
+
def to_map
|
63
|
+
to_a.empty? ? Sass::Value::Map.new({}) : nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Map]
|
67
|
+
# @raise [ScriptError]
|
68
|
+
def assert_map(name = nil)
|
69
|
+
to_a.empty? ? Sass::Value::Map.new({}) : super.assert_map(name)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def to_a_length
|
75
|
+
to_a.length
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
# Sass's map type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/sassmap/
|
8
|
+
class Map
|
9
|
+
include Value
|
10
|
+
|
11
|
+
# @param contents [Hash<Value, Value>]
|
12
|
+
def initialize(contents = {})
|
13
|
+
@contents = contents.freeze
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Hash<Value, Value>]
|
17
|
+
attr_reader :contents
|
18
|
+
|
19
|
+
# @return [::String, nil]
|
20
|
+
def separator
|
21
|
+
contents.empty? ? nil : ','
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [::Boolean]
|
25
|
+
def ==(other)
|
26
|
+
(other.is_a?(Sass::Value::Map) && other.contents == contents) ||
|
27
|
+
(contents.empty? && other.is_a?(Sass::Value::List) && other.to_a.empty?)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param index [Numeric, Value]
|
31
|
+
# @return [List<(Value, Value)>, Value]
|
32
|
+
def at(index)
|
33
|
+
if index.is_a?(Numeric)
|
34
|
+
index = index.floor
|
35
|
+
index = to_a_length + index if index.negative?
|
36
|
+
return nil if index.negative? || index >= to_a_length
|
37
|
+
|
38
|
+
Sass::Value::List.new(contents.to_a[index], separator: ' ')
|
39
|
+
else
|
40
|
+
contents[index]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Integer]
|
45
|
+
def hash
|
46
|
+
@hash ||= contents.hash
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [Array<List<(Value, Value)>>]
|
50
|
+
def to_a
|
51
|
+
contents.map { |key, value| Sass::Value::List.new([key, value], separator: ' ') }
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Map]
|
55
|
+
def to_map
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Map]
|
60
|
+
def assert_map(_name = nil)
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def to_a_length
|
67
|
+
contents.length
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
# Sass's mixin type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/sassmixin/
|
8
|
+
class Mixin
|
9
|
+
include Value
|
10
|
+
|
11
|
+
class << self
|
12
|
+
private :new
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Integer]
|
16
|
+
attr_reader :id
|
17
|
+
|
18
|
+
protected :id
|
19
|
+
|
20
|
+
# @return [::Boolean]
|
21
|
+
def ==(other)
|
22
|
+
other.is_a?(Sass::Value::Mixin) && other.id == id
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Integer]
|
26
|
+
def hash
|
27
|
+
@hash ||= id.hash
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Mixin]
|
31
|
+
def assert_mixin(_name = nil)
|
32
|
+
self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|