sass-embedded 1.58.3-arm-linux-androideabi

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 (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 +12 -0
  5. data/ext/sass/embedded_sass_pb.rb +349 -0
  6. data/ext/sass/sass_embedded/dart-sass-embedded +20 -0
  7. data/ext/sass/sass_embedded/src/LICENSE +1434 -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 +58 -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 +98 -0
  16. data/lib/sass/embedded/host/function_registry.rb +89 -0
  17. data/lib/sass/embedded/host/importer_registry.rb +104 -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 +39 -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 +251 -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 +10 -0
  30. data/lib/sass/value/argument_list.rb +37 -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 +80 -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 +365 -0
  40. data/lib/sass/value/string.rb +55 -0
  41. data/lib/sass/value.rb +128 -0
  42. data/lib/sass-embedded.rb +4 -0
  43. metadata +186 -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 Sass::ScriptError, '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 compile_request(path:,
19
+ source:,
20
+ importer:,
21
+ load_paths:,
22
+ syntax:,
23
+ url:,
24
+ charset:,
25
+ source_map:,
26
+ source_map_include_sources:,
27
+ style:,
28
+ functions:,
29
+ importers:,
30
+ alert_ascii:,
31
+ alert_color:,
32
+ logger:,
33
+ quiet_deps:,
34
+ verbose:)
35
+ compile_response = await do
36
+ alert_color = $stderr.tty? if alert_color.nil?
37
+
38
+ @function_registry = FunctionRegistry.new(functions, alert_color: alert_color)
39
+ @importer_registry = ImporterRegistry.new(importers, load_paths, alert_color: alert_color)
40
+ @logger_registry = LoggerRegistry.new(logger)
41
+
42
+ send_message(compile_request: EmbeddedProtocol::InboundMessage::CompileRequest.new(
43
+ id: id,
44
+ string: unless source.nil?
45
+ EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
46
+ source: source,
47
+ url: url&.to_s,
48
+ syntax: Protofier.to_proto_syntax(syntax),
49
+ importer: (@importer_registry.register(importer) unless importer.nil?)
50
+ )
51
+ end,
52
+ path: (File.absolute_path(path) unless path.nil?),
53
+ style: Protofier.to_proto_output_style(style),
54
+ charset: charset,
55
+ source_map: source_map,
56
+ source_map_include_sources: source_map_include_sources,
57
+ importers: @importer_registry.importers,
58
+ global_functions: @function_registry.global_functions,
59
+ alert_ascii: alert_ascii,
60
+ alert_color: alert_color,
61
+ quiet_deps: quiet_deps,
62
+ verbose: verbose
63
+ ))
64
+ end
65
+
66
+ Protofier.from_proto_compile_response(compile_response)
67
+ end
68
+
69
+ def version_request
70
+ version_response = await do
71
+ send_message(version_request: EmbeddedProtocol::InboundMessage::VersionRequest.new(
72
+ id: id
73
+ ))
74
+ end
75
+
76
+ "sass-embedded\t#{version_response.implementation_version}"
77
+ end
78
+
79
+ def log_event(message)
80
+ @logger_registry.log(message)
81
+ end
82
+
83
+ def compile_response(message)
84
+ resolve(message)
85
+ end
86
+
87
+ def version_response(message)
88
+ resolve(message)
89
+ end
90
+
91
+ def canonicalize_request(message)
92
+ send_message(canonicalize_response: @importer_registry.canonicalize(message))
93
+ end
94
+
95
+ def import_request(message)
96
+ send_message(import_response: @importer_registry.import(message))
97
+ end
98
+
99
+ def file_import_request(message)
100
+ send_message(file_import_response: @importer_registry.file_import(message))
101
+ end
102
+
103
+ def function_call_request(message)
104
+ send_message(function_call_response: @function_registry.function_call(message))
105
+ end
106
+
107
+ def error(message)
108
+ reject(CompileError.new(message.message, nil, nil, nil))
109
+ end
110
+
111
+ private
112
+
113
+ def await
114
+ @connection = @channel.connect(self)
115
+ @async = Async.new
116
+ yield
117
+ @async.await
118
+ ensure
119
+ @connection&.disconnect
120
+ end
121
+
122
+ def resolve(value)
123
+ @async.resolve(value)
124
+ end
125
+
126
+ def reject(reason)
127
+ @async.reject(reason)
128
+ end
129
+
130
+ def id
131
+ @connection.id
132
+ end
133
+
134
+ def send_message(**kwargs)
135
+ @connection.send_message(**kwargs)
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,39 @@
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, *symbols)
12
+ return obj unless obj.is_a? Hash
13
+
14
+ struct = Object.new
15
+ symbols.each do |key|
16
+ next unless obj.key?(key)
17
+
18
+ value = obj[key]
19
+ if value.respond_to? :call
20
+ struct.define_singleton_method key do |*args, **kwargs|
21
+ if kwargs.empty?
22
+ value.call(*args)
23
+ else
24
+ value.call(*args, **kwargs)
25
+ end
26
+ end
27
+ else
28
+ struct.define_singleton_method key do
29
+ value
30
+ end
31
+ end
32
+ end
33
+ struct
34
+ end
35
+ end
36
+
37
+ private_constant :Structifier
38
+ end
39
+ 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 << ((value & 0x7f) | 0x80)
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.58.3'
6
+ end
7
+ end