sass-embedded 1.54.6-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +42 -0
  4. data/ext/sass/embedded.rb +9 -0
  5. data/ext/sass/embedded_sass_pb.rb +349 -0
  6. data/ext/sass/sass_embedded/dart-sass-embedded +17 -0
  7. data/ext/sass/sass_embedded/src/LICENSE +1476 -0
  8. data/ext/sass/sass_embedded/src/dart +0 -0
  9. data/ext/sass/sass_embedded/src/dart-sass-embedded.snapshot +0 -0
  10. data/lib/sass/compile_error.rb +28 -0
  11. data/lib/sass/compile_result.rb +23 -0
  12. data/lib/sass/embedded/async.rb +65 -0
  13. data/lib/sass/embedded/channel.rb +61 -0
  14. data/lib/sass/embedded/compiler.rb +60 -0
  15. data/lib/sass/embedded/dispatcher.rb +90 -0
  16. data/lib/sass/embedded/host/function_registry.rb +90 -0
  17. data/lib/sass/embedded/host/importer_registry.rb +108 -0
  18. data/lib/sass/embedded/host/logger_registry.rb +50 -0
  19. data/lib/sass/embedded/host/value_protofier.rb +241 -0
  20. data/lib/sass/embedded/host.rb +141 -0
  21. data/lib/sass/embedded/protofier.rb +78 -0
  22. data/lib/sass/embedded/structifier.rb +36 -0
  23. data/lib/sass/embedded/varint.rb +35 -0
  24. data/lib/sass/embedded/version.rb +7 -0
  25. data/lib/sass/embedded.rb +245 -0
  26. data/lib/sass/logger/silent.rb +26 -0
  27. data/lib/sass/logger/source_location.rb +21 -0
  28. data/lib/sass/logger/source_span.rb +27 -0
  29. data/lib/sass/script_error.rb +6 -0
  30. data/lib/sass/value/argument_list.rb +30 -0
  31. data/lib/sass/value/boolean.rb +52 -0
  32. data/lib/sass/value/color.rb +253 -0
  33. data/lib/sass/value/function.rb +54 -0
  34. data/lib/sass/value/fuzzy_math.rb +81 -0
  35. data/lib/sass/value/list.rb +79 -0
  36. data/lib/sass/value/map.rb +71 -0
  37. data/lib/sass/value/null.rb +48 -0
  38. data/lib/sass/value/number/unit.rb +186 -0
  39. data/lib/sass/value/number.rb +358 -0
  40. data/lib/sass/value/string.rb +55 -0
  41. data/lib/sass/value.rb +132 -0
  42. data/lib/sass-embedded.rb +4 -0
  43. metadata +186 -0
@@ -0,0 +1,54 @@
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
+ # @overload initialize(id)
12
+ # @param id [Numeric]
13
+ # @overload initialize(signature, callback)
14
+ # @param signature [::String]
15
+ # @param callback [Proc]
16
+ def initialize(id_or_signature, callback = nil)
17
+ if id_or_signature.is_a? Numeric
18
+ @id = id_or_signature
19
+ else
20
+ @signature = id_or_signature
21
+ @callback = callback
22
+ end
23
+ end
24
+
25
+ # @return [Integer, nil]
26
+ attr_reader :id
27
+
28
+ # @return [::String, nil]
29
+ attr_reader :signature
30
+
31
+ # @return [Proc, nil]
32
+ attr_reader :callback
33
+
34
+ # @return [::Boolean]
35
+ def ==(other)
36
+ if id.nil?
37
+ other.equal? self
38
+ else
39
+ other.is_a?(Sass::Value::Function) && other.id == id
40
+ end
41
+ end
42
+
43
+ # @return [Integer]
44
+ def hash
45
+ id.nil? ? signature.hash : id.hash
46
+ end
47
+
48
+ # @return [Function]
49
+ def assert_function(_name = nil)
50
+ self
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,81 @@
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
+ message = "#{number} must be between #{min} and #{max}."
67
+ raise Sass::ScriptError, name.nil? ? message : "$#{name}: #{message}"
68
+ end
69
+
70
+ def hash(number)
71
+ @hash ||= if number.finite?
72
+ (number * INVERSE_EPSILON).round.hash
73
+ else
74
+ number.hash
75
+ end
76
+ end
77
+ end
78
+
79
+ private_constant :FuzzyMath
80
+ end
81
+ 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 error '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 [Array<Value>]
25
+ attr_reader :contents
26
+
27
+ # @return [::String, nil]
28
+ attr_reader :separator
29
+
30
+ # @return [::Boolean]
31
+ def bracketed?
32
+ @bracketed
33
+ end
34
+
35
+ # @return [::Boolean]
36
+ def ==(other)
37
+ (other.is_a?(Sass::Value::List) &&
38
+ other.contents == contents &&
39
+ other.separator == separator &&
40
+ other.bracketed? == bracketed?) ||
41
+ (to_a.empty? && other.is_a?(Sass::Value::Map) && other.to_a.empty?)
42
+ end
43
+
44
+ # @param index [Numeric]
45
+ # @return [Value]
46
+ def at(index)
47
+ index = index.floor
48
+ index = to_a.length + index if index.negative?
49
+ return nil if index.negative? || index >= to_a.length
50
+
51
+ to_a[index]
52
+ end
53
+
54
+ # @return [Integer]
55
+ def hash
56
+ @hash ||= contents.hash
57
+ end
58
+
59
+ alias to_a contents
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
+ to_a[index]
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.to_a.map { |entry| Sass::Value::List.new(entry, 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,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ module Value
5
+ # Sass's null type.
6
+ #
7
+ # @see https://sass-lang.com/documentation/js-api/modules#sassNull
8
+ class Null
9
+ include Value
10
+
11
+ def initialize
12
+ @value = nil
13
+ end
14
+
15
+ # @return [nil]
16
+ attr_reader :value
17
+
18
+ # @return [Boolean]
19
+ def !
20
+ Boolean::TRUE
21
+ end
22
+
23
+ # @return [::Boolean]
24
+ def ==(other)
25
+ other.is_a?(Sass::Value::Null)
26
+ end
27
+
28
+ # @return [Integer]
29
+ def hash
30
+ @hash ||= value.hash
31
+ end
32
+
33
+ # @return [::Boolean]
34
+ def to_bool
35
+ false
36
+ end
37
+
38
+ alias to_nil value
39
+
40
+ # Sass's null value.
41
+ NULL = Null.new
42
+
43
+ def self.new
44
+ NULL
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,186 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ module Value
5
+ class Number
6
+ # The {Unit} module.
7
+ module Unit
8
+ CONVERSIONS = {
9
+ # Length
10
+ 'in' => {
11
+ 'in' => Rational(1),
12
+ 'cm' => Rational(1, 2.54),
13
+ 'pc' => Rational(1, 6),
14
+ 'mm' => Rational(1, 25.4),
15
+ 'q' => Rational(1, 101.6),
16
+ 'pt' => Rational(1, 72),
17
+ 'px' => Rational(1, 96)
18
+ },
19
+ 'cm' => {
20
+ 'in' => Rational(2.54),
21
+ 'cm' => Rational(1),
22
+ 'pc' => Rational(2.54, 6),
23
+ 'mm' => Rational(1, 10),
24
+ 'q' => Rational(1, 40),
25
+ 'pt' => Rational(2.54, 72),
26
+ 'px' => Rational(2.54, 96)
27
+ },
28
+ 'pc' => {
29
+ 'in' => Rational(6),
30
+ 'cm' => Rational(6, 2.54),
31
+ 'pc' => Rational(1),
32
+ 'mm' => Rational(6, 25.4),
33
+ 'q' => Rational(6, 101.6),
34
+ 'pt' => Rational(1, 12),
35
+ 'px' => Rational(1, 16)
36
+ },
37
+ 'mm' => {
38
+ 'in' => Rational(25.4),
39
+ 'cm' => Rational(10),
40
+ 'pc' => Rational(25.4, 6),
41
+ 'mm' => Rational(1),
42
+ 'q' => Rational(1, 4),
43
+ 'pt' => Rational(25.4, 72),
44
+ 'px' => Rational(25.4, 96)
45
+ },
46
+ 'q' => {
47
+ 'in' => Rational(101.6),
48
+ 'cm' => Rational(40),
49
+ 'pc' => Rational(101.6, 6),
50
+ 'mm' => Rational(4),
51
+ 'q' => Rational(1),
52
+ 'pt' => Rational(101.6, 72),
53
+ 'px' => Rational(101.6, 96)
54
+ },
55
+ 'pt' => {
56
+ 'in' => Rational(72),
57
+ 'cm' => Rational(72, 2.54),
58
+ 'pc' => Rational(12),
59
+ 'mm' => Rational(72, 25.4),
60
+ 'q' => Rational(72, 101.6),
61
+ 'pt' => Rational(1),
62
+ 'px' => Rational(3, 4)
63
+ },
64
+ 'px' => {
65
+ 'in' => Rational(96),
66
+ 'cm' => Rational(96, 2.54),
67
+ 'pc' => Rational(16),
68
+ 'mm' => Rational(96, 25.4),
69
+ 'q' => Rational(96, 101.6),
70
+ 'pt' => Rational(4, 3),
71
+ 'px' => Rational(1)
72
+ },
73
+
74
+ # Rotation
75
+ 'deg' => {
76
+ 'deg' => Rational(1),
77
+ 'grad' => Rational(9, 10),
78
+ 'rad' => Rational(180, Math::PI),
79
+ 'turn' => Rational(360)
80
+ },
81
+ 'grad' => {
82
+ 'deg' => Rational(10, 9),
83
+ 'grad' => Rational(1),
84
+ 'rad' => Rational(200, Math::PI),
85
+ 'turn' => Rational(400)
86
+ },
87
+ 'rad' => {
88
+ 'deg' => Rational(Math::PI, 180),
89
+ 'grad' => Rational(Math::PI, 200),
90
+ 'rad' => Rational(1),
91
+ 'turn' => Rational(2 * Math::PI)
92
+ },
93
+ 'turn' => {
94
+ 'deg' => Rational(1, 360),
95
+ 'grad' => Rational(1, 400),
96
+ 'rad' => Rational(1, 2 * Math::PI),
97
+ 'turn' => Rational(1)
98
+ },
99
+
100
+ # Time
101
+ 's' => {
102
+ 's' => Rational(1),
103
+ 'ms' => Rational(1, 1000)
104
+ },
105
+ 'ms' => {
106
+ 's' => Rational(1000),
107
+ 'ms' => Rational(1)
108
+ },
109
+
110
+ # Frequency
111
+ 'Hz' => {
112
+ 'Hz' => Rational(1),
113
+ 'kHz' => Rational(1000)
114
+ },
115
+ 'kHz' => {
116
+ 'Hz' => Rational(1, 1000),
117
+ 'kHz' => Rational(1)
118
+ },
119
+
120
+ # Pixel density
121
+ 'dpi' => {
122
+ 'dpi' => Rational(1),
123
+ 'dpcm' => Rational(2.54),
124
+ 'dppx' => Rational(96)
125
+ },
126
+ 'dpcm' => {
127
+ 'dpi' => Rational(1, 2.54),
128
+ 'dpcm' => Rational(1),
129
+ 'dppx' => Rational(96, 2.54)
130
+ },
131
+ 'dppx' => {
132
+ 'dpi' => Rational(1, 96),
133
+ 'dpcm' => Rational(2.54, 96),
134
+ 'dppx' => Rational(1)
135
+ }
136
+ }.freeze
137
+
138
+ UNITS_BY_TYPE = {
139
+ time: %w[s ms],
140
+ frequency: %w[Hz kHz],
141
+ 'pixel density': %w[dpi dpcm dppx]
142
+ }.freeze
143
+
144
+ TYPES_BY_UNIT = UNITS_BY_TYPE.invert
145
+ .to_a
146
+ .flat_map { |pair| pair[0].map { |key| [key, pair[1]] } }
147
+ .to_h
148
+
149
+ module_function
150
+
151
+ def conversion_factor(unit1, unit2)
152
+ return 1 if unit1 == unit2
153
+
154
+ CONVERSIONS.dig(unit1, unit2)
155
+ end
156
+
157
+ def canonicalize_units(units)
158
+ return units if units.empty?
159
+
160
+ if units.length == 1
161
+ type = TYPES_BY_UNIT[units.first]
162
+ return type.nil? ? units : [UNITS_BY_TYPE[type].first]
163
+ end
164
+
165
+ units.map do |unit|
166
+ type = TYPES_BY_UNIT[unit]
167
+ type.nil? ? units : [UNITS_BY_TYPE[type].first]
168
+ end.sort
169
+ end
170
+
171
+ def canonical_multiplier(units)
172
+ units.reduce(1) do |multiplier, unit|
173
+ multiplier * canonical_multiplier_for_unit(unit)
174
+ end
175
+ end
176
+
177
+ def canonical_multiplier_for_unit(unit)
178
+ inner_map = CONVERSIONS[unit]
179
+ inner_map.nil? ? 1 : 1 / inner_map.values.first
180
+ end
181
+ end
182
+
183
+ private_constant :Unit
184
+ end
185
+ end
186
+ end