sass-embedded 1.54.7-aarch64-linux-gnu

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.
Files changed (41) 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 +0 -0
  7. data/ext/sass/sass_embedded/src/LICENSE +1470 -0
  8. data/lib/sass/compile_error.rb +28 -0
  9. data/lib/sass/compile_result.rb +23 -0
  10. data/lib/sass/embedded/async.rb +65 -0
  11. data/lib/sass/embedded/channel.rb +61 -0
  12. data/lib/sass/embedded/compiler.rb +60 -0
  13. data/lib/sass/embedded/dispatcher.rb +90 -0
  14. data/lib/sass/embedded/host/function_registry.rb +90 -0
  15. data/lib/sass/embedded/host/importer_registry.rb +108 -0
  16. data/lib/sass/embedded/host/logger_registry.rb +50 -0
  17. data/lib/sass/embedded/host/value_protofier.rb +241 -0
  18. data/lib/sass/embedded/host.rb +141 -0
  19. data/lib/sass/embedded/protofier.rb +78 -0
  20. data/lib/sass/embedded/structifier.rb +36 -0
  21. data/lib/sass/embedded/varint.rb +35 -0
  22. data/lib/sass/embedded/version.rb +7 -0
  23. data/lib/sass/embedded.rb +245 -0
  24. data/lib/sass/logger/silent.rb +26 -0
  25. data/lib/sass/logger/source_location.rb +21 -0
  26. data/lib/sass/logger/source_span.rb +27 -0
  27. data/lib/sass/script_error.rb +6 -0
  28. data/lib/sass/value/argument_list.rb +30 -0
  29. data/lib/sass/value/boolean.rb +52 -0
  30. data/lib/sass/value/color.rb +253 -0
  31. data/lib/sass/value/function.rb +54 -0
  32. data/lib/sass/value/fuzzy_math.rb +81 -0
  33. data/lib/sass/value/list.rb +79 -0
  34. data/lib/sass/value/map.rb +71 -0
  35. data/lib/sass/value/null.rb +48 -0
  36. data/lib/sass/value/number/unit.rb +186 -0
  37. data/lib/sass/value/number.rb +358 -0
  38. data/lib/sass/value/string.rb +55 -0
  39. data/lib/sass/value.rb +132 -0
  40. data/lib/sass-embedded.rb +4 -0
  41. metadata +184 -0
@@ -0,0 +1,241 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Embedded
5
+ class Host
6
+ # The {ValueProtofier} class.
7
+ #
8
+ # It converts Pure Ruby types and Protobuf Ruby types.
9
+ class ValueProtofier
10
+ def initialize(function_registry)
11
+ @function_registry = function_registry
12
+ end
13
+
14
+ def to_proto(obj)
15
+ case obj
16
+ when Sass::Value::String
17
+ Sass::EmbeddedProtocol::Value.new(
18
+ string: Sass::EmbeddedProtocol::Value::String.new(
19
+ text: obj.text,
20
+ quoted: obj.quoted?
21
+ )
22
+ )
23
+ when Sass::Value::Number
24
+ Sass::EmbeddedProtocol::Value.new(
25
+ number: Sass::EmbeddedProtocol::Value::Number.new(
26
+ value: obj.value.to_f,
27
+ numerators: obj.numerator_units,
28
+ denominators: obj.denominator_units
29
+ )
30
+ )
31
+ when Sass::Value::Color
32
+ if obj.instance_eval { !defined?(@hue) }
33
+ Sass::EmbeddedProtocol::Value.new(
34
+ rgb_color: Sass::EmbeddedProtocol::Value::RgbColor.new(
35
+ red: obj.red,
36
+ green: obj.green,
37
+ blue: obj.blue,
38
+ alpha: obj.alpha.to_f
39
+ )
40
+ )
41
+ elsif obj.instance_eval { !defined?(@saturation) }
42
+ Sass::EmbeddedProtocol::Value.new(
43
+ hwb_color: Sass::EmbeddedProtocol::Value::HwbColor.new(
44
+ hue: obj.hue.to_f,
45
+ whiteness: obj.whiteness.to_f,
46
+ blackness: obj.blackness.to_f,
47
+ alpha: obj.alpha.to_f
48
+ )
49
+ )
50
+ else
51
+ Sass::EmbeddedProtocol::Value.new(
52
+ hsl_color: Sass::EmbeddedProtocol::Value::HslColor.new(
53
+ hue: obj.hue.to_f,
54
+ saturation: obj.saturation.to_f,
55
+ lightness: obj.lightness.to_f,
56
+ alpha: obj.alpha.to_f
57
+ )
58
+ )
59
+ end
60
+ when Sass::Value::ArgumentList
61
+ Sass::EmbeddedProtocol::Value.new(
62
+ argument_list: Sass::EmbeddedProtocol::Value::ArgumentList.new(
63
+ id: obj.instance_eval { @id },
64
+ contents: obj.contents.map { |element| to_proto(element) },
65
+ keywords: obj.keywords.transform_values { |value| to_proto(value) },
66
+ separator: ListSeparator.to_proto(obj.separator)
67
+ )
68
+ )
69
+ when Sass::Value::List
70
+ Sass::EmbeddedProtocol::Value.new(
71
+ list: Sass::EmbeddedProtocol::Value::List.new(
72
+ contents: obj.contents.map { |element| to_proto(element) },
73
+ separator: ListSeparator.to_proto(obj.separator),
74
+ has_brackets: obj.bracketed?
75
+ )
76
+ )
77
+ when Sass::Value::Map
78
+ Sass::EmbeddedProtocol::Value.new(
79
+ map: Sass::EmbeddedProtocol::Value::Map.new(
80
+ entries: obj.contents.map do |key, value|
81
+ Sass::EmbeddedProtocol::Value::Map::Entry.new(
82
+ key: to_proto(key),
83
+ value: to_proto(value)
84
+ )
85
+ end
86
+ )
87
+ )
88
+ when Sass::Value::Function
89
+ if obj.id
90
+ Sass::EmbeddedProtocol::Value.new(
91
+ compiler_function: Sass::EmbeddedProtocol::Value::CompilerFunction.new(
92
+ id: obj.id
93
+ )
94
+ )
95
+ else
96
+ Sass::EmbeddedProtocol::Value.new(
97
+ host_function: Sass::EmbeddedProtocol::Value::HostFunction.new(
98
+ id: @function_registry.register(obj.callback),
99
+ signature: obj.signature
100
+ )
101
+ )
102
+ end
103
+ when Sass::Value::Boolean
104
+ Sass::EmbeddedProtocol::Value.new(
105
+ singleton: obj.value ? :TRUE : :FALSE
106
+ )
107
+ when Sass::Value::Null
108
+ Sass::EmbeddedProtocol::Value.new(
109
+ singleton: :NULL
110
+ )
111
+ else
112
+ raise Sass::ScriptError, "Unknown Sass::Value #{obj}"
113
+ end
114
+ end
115
+
116
+ def from_proto(proto)
117
+ oneof = proto.value
118
+ obj = proto.public_send(oneof)
119
+ case oneof
120
+ when :string
121
+ Sass::Value::String.new(
122
+ obj.text,
123
+ quoted: obj.quoted
124
+ )
125
+ when :number
126
+ Sass::Value::Number.new(
127
+ obj.value, {
128
+ numerator_units: obj.numerators.to_a,
129
+ denominator_units: obj.denominators.to_a
130
+ }
131
+ )
132
+ when :rgb_color
133
+ Sass::Value::Color.new(
134
+ red: obj.red,
135
+ green: obj.green,
136
+ blue: obj.blue,
137
+ alpha: obj.alpha
138
+ )
139
+ when :hsl_color
140
+ Sass::Value::Color.new(
141
+ hue: obj.hue,
142
+ saturation: obj.saturation,
143
+ lightness: obj.lightness,
144
+ alpha: obj.alpha
145
+ )
146
+ when :hwb_color
147
+ Sass::Value::Color.new(
148
+ hue: obj.hue,
149
+ whiteness: obj.whiteness,
150
+ blackness: obj.blackness,
151
+ alpha: obj.alpha
152
+ )
153
+ when :argument_list
154
+ Sass::Value::ArgumentList.new(
155
+ obj.contents.map do |element|
156
+ from_proto(element)
157
+ end,
158
+ obj.keywords.entries.to_h.transform_values! do |value|
159
+ from_proto(value)
160
+ end,
161
+ ListSeparator.from_proto(obj.separator)
162
+ ).instance_eval do
163
+ @id = obj.id
164
+ self
165
+ end
166
+ when :list
167
+ Sass::Value::List.new(
168
+ obj.contents.map do |element|
169
+ from_proto(element)
170
+ end,
171
+ separator: ListSeparator.from_proto(obj.separator),
172
+ bracketed: obj.has_brackets
173
+ )
174
+ when :map
175
+ Sass::Value::Map.new(
176
+ obj.entries.to_h do |entry|
177
+ [from_proto(entry.key), from_proto(entry.value)]
178
+ end
179
+ )
180
+ when :compiler_function
181
+ Sass::Value::Function.new(obj.id)
182
+ when :host_function
183
+ raise ProtocolError, 'The compiler may not send Value.host_function to host'
184
+ when :singleton
185
+ case obj
186
+ when :TRUE
187
+ Sass::Value::Boolean::TRUE
188
+ when :FALSE
189
+ Sass::Value::Boolean::FALSE
190
+ when :NULL
191
+ Sass::Value::Null::NULL
192
+ else
193
+ raise Sass::ScriptError, "Unknown Value.singleton #{obj}"
194
+ end
195
+ else
196
+ raise Sass::ScriptError, "Unknown Value.value #{obj}"
197
+ end
198
+ end
199
+
200
+ # The {ListSeparator} Protofier.
201
+ module ListSeparator
202
+ module_function
203
+
204
+ def to_proto(separator)
205
+ case separator
206
+ when ','
207
+ :COMMA
208
+ when ' '
209
+ :SPACE
210
+ when '/'
211
+ :SLASH
212
+ when nil
213
+ :UNDECIDED
214
+ else
215
+ raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
216
+ end
217
+ end
218
+
219
+ def from_proto(separator)
220
+ case separator
221
+ when :COMMA
222
+ ','
223
+ when :SPACE
224
+ ' '
225
+ when :SLASH
226
+ '/'
227
+ when :UNDECIDED
228
+ nil
229
+ else
230
+ raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
231
+ end
232
+ end
233
+ end
234
+
235
+ private_constant :ListSeparator
236
+ end
237
+
238
+ private_constant :ValueProtofier
239
+ end
240
+ end
241
+ end
@@ -0,0 +1,141 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'host/function_registry'
4
+ require_relative 'host/importer_registry'
5
+ require_relative 'host/logger_registry'
6
+ require_relative 'host/value_protofier'
7
+
8
+ module Sass
9
+ class Embedded
10
+ # The {Host} class.
11
+ #
12
+ # It communicates with {Dispatcher} and handles the host logic.
13
+ class Host
14
+ def initialize(channel)
15
+ @channel = channel
16
+ end
17
+
18
+ def id
19
+ @connection.id
20
+ end
21
+
22
+ def send_message(message)
23
+ @connection.send_message(message)
24
+ end
25
+
26
+ def compile_request(path:,
27
+ source:,
28
+ importer:,
29
+ load_paths:,
30
+ syntax:,
31
+ url:,
32
+ charset:,
33
+ source_map:,
34
+ source_map_include_sources:,
35
+ style:,
36
+ functions:,
37
+ importers:,
38
+ alert_ascii:,
39
+ alert_color:,
40
+ logger:,
41
+ quiet_deps:,
42
+ verbose:)
43
+ await do
44
+ alert_color = $stderr.tty? if alert_color.nil?
45
+
46
+ @function_registry = FunctionRegistry.new(functions, alert_color: alert_color)
47
+ @importer_registry = ImporterRegistry.new(importers, load_paths, alert_color: alert_color)
48
+ @logger_registry = LoggerRegistry.new(logger)
49
+
50
+ send_message EmbeddedProtocol::InboundMessage.new(
51
+ compile_request: EmbeddedProtocol::InboundMessage::CompileRequest.new(
52
+ id: id,
53
+ string: unless source.nil?
54
+ EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
55
+ source: source,
56
+ url: url&.to_s,
57
+ syntax: Protofier.to_proto_syntax(syntax),
58
+ importer: (@importer_registry.register(importer) unless importer.nil?)
59
+ )
60
+ end,
61
+ path: (File.absolute_path(path) unless path.nil?),
62
+ style: Protofier.to_proto_output_style(style),
63
+ charset: charset,
64
+ source_map: source_map,
65
+ source_map_include_sources: source_map_include_sources,
66
+ importers: @importer_registry.importers,
67
+ global_functions: @function_registry.global_functions,
68
+ alert_ascii: alert_ascii,
69
+ alert_color: alert_color,
70
+ quiet_deps: quiet_deps,
71
+ verbose: verbose
72
+ )
73
+ )
74
+ end
75
+ end
76
+
77
+ def version_request
78
+ await do
79
+ send_message EmbeddedProtocol::InboundMessage.new(
80
+ version_request: EmbeddedProtocol::InboundMessage::VersionRequest.new(
81
+ id: id
82
+ )
83
+ )
84
+ end
85
+ end
86
+
87
+ def log_event(message)
88
+ @logger_registry.log(message)
89
+ end
90
+
91
+ def compile_response(message)
92
+ @async.resolve(message)
93
+ end
94
+
95
+ def version_response(message)
96
+ @async.resolve(message)
97
+ end
98
+
99
+ def canonicalize_request(message)
100
+ send_message EmbeddedProtocol::InboundMessage.new(
101
+ canonicalize_response: @importer_registry.canonicalize(message)
102
+ )
103
+ end
104
+
105
+ def import_request(message)
106
+ send_message EmbeddedProtocol::InboundMessage.new(
107
+ import_response: @importer_registry.import(message)
108
+ )
109
+ end
110
+
111
+ def file_import_request(message)
112
+ send_message EmbeddedProtocol::InboundMessage.new(
113
+ file_import_response: @importer_registry.file_import(message)
114
+ )
115
+ end
116
+
117
+ def function_call_request(message)
118
+ send_message EmbeddedProtocol::InboundMessage.new(
119
+ function_call_response: @function_registry.function_call(message)
120
+ )
121
+ end
122
+
123
+ def error(message)
124
+ @async.reject(CompileError.new(message.message, nil, nil, nil))
125
+ end
126
+
127
+ private
128
+
129
+ def await
130
+ @connection = @channel.connect(self)
131
+ @async = Async.new
132
+ yield
133
+ @async.await
134
+ ensure
135
+ @connection.disconnect
136
+ end
137
+ end
138
+
139
+ private_constant :Host
140
+ end
141
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Embedded
5
+ # The {Protofier} module.
6
+ #
7
+ # It converts Pure Ruby types and Protobuf Ruby types.
8
+ module Protofier
9
+ module_function
10
+
11
+ def from_proto_compile_response(compile_response)
12
+ oneof = compile_response.result
13
+ result = compile_response.public_send(oneof)
14
+ case oneof
15
+ when :failure
16
+ raise CompileError.new(
17
+ result.message,
18
+ result.formatted,
19
+ result.stack_trace,
20
+ from_proto_source_span(result.span)
21
+ )
22
+ when :success
23
+ CompileResult.new(
24
+ result.css,
25
+ result.source_map,
26
+ result.loaded_urls
27
+ )
28
+ else
29
+ raise ArgumentError, "Unknown CompileResponse.result #{result}"
30
+ end
31
+ end
32
+
33
+ def from_proto_source_span(source_span)
34
+ return if source_span.nil?
35
+
36
+ Logger::SourceSpan.new(from_proto_source_location(source_span.start),
37
+ from_proto_source_location(source_span.end),
38
+ source_span.text,
39
+ source_span.url,
40
+ source_span.context)
41
+ end
42
+
43
+ def from_proto_source_location(source_location)
44
+ return if source_location.nil?
45
+
46
+ Logger::SourceLocation.new(source_location.offset,
47
+ source_location.line,
48
+ source_location.column)
49
+ end
50
+
51
+ def to_proto_syntax(syntax)
52
+ case syntax&.to_sym
53
+ when :scss
54
+ EmbeddedProtocol::Syntax::SCSS
55
+ when :indented
56
+ EmbeddedProtocol::Syntax::INDENTED
57
+ when :css
58
+ EmbeddedProtocol::Syntax::CSS
59
+ else
60
+ raise ArgumentError, 'syntax must be one of :scss, :indented, :css'
61
+ end
62
+ end
63
+
64
+ def to_proto_output_style(style)
65
+ case style&.to_sym
66
+ when :expanded
67
+ EmbeddedProtocol::OutputStyle::EXPANDED
68
+ when :compressed
69
+ EmbeddedProtocol::OutputStyle::COMPRESSED
70
+ else
71
+ raise ArgumentError, 'style must be one of :expanded, :compressed'
72
+ end
73
+ end
74
+ end
75
+
76
+ private_constant :Protofier
77
+ end
78
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Embedded
5
+ # The {Structifier} module.
6
+ #
7
+ # It converts {::Hash} to {Struct}-like objects.
8
+ module Structifier
9
+ module_function
10
+
11
+ def to_struct(obj)
12
+ return obj unless obj.is_a? Hash
13
+
14
+ struct = Object.new
15
+ obj.each do |key, value|
16
+ if value.respond_to? :call
17
+ struct.define_singleton_method key.to_sym do |*args, **kwargs|
18
+ if kwargs.empty?
19
+ value.call(*args)
20
+ else
21
+ value.call(*args, **kwargs)
22
+ end
23
+ end
24
+ else
25
+ struct.define_singleton_method key.to_sym do
26
+ value
27
+ end
28
+ end
29
+ end
30
+ struct
31
+ end
32
+ end
33
+
34
+ private_constant :Structifier
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Embedded
5
+ # The {Varint} module.
6
+ #
7
+ # It reads and writes varints.
8
+ module Varint
9
+ module_function
10
+
11
+ def read(readable)
12
+ value = bits = 0
13
+ loop do
14
+ byte = readable.readbyte
15
+ value |= (byte & 0x7f) << bits
16
+ bits += 7
17
+ break if byte < 0x80
18
+ end
19
+ value
20
+ end
21
+
22
+ def write(writeable, value)
23
+ bytes = []
24
+ until value < 0x80
25
+ bytes << (0x80 | (value & 0x7f))
26
+ value >>= 7
27
+ end
28
+ bytes << value
29
+ writeable.write bytes.pack('C*')
30
+ end
31
+ end
32
+
33
+ private_constant :Varint
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Embedded
5
+ VERSION = '1.54.7'
6
+ end
7
+ end