sass-embedded 1.69.7-arm64-darwin → 1.71.0-arm64-darwin

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.
@@ -3,83 +3,385 @@
3
3
  module Sass
4
4
  class Compiler
5
5
  class Host
6
- # The {Protofier} module.
6
+ # The {Protofier} class.
7
7
  #
8
8
  # It converts Pure Ruby types and Protobuf Ruby types.
9
- module Protofier
10
- module_function
11
-
12
- def from_proto_canonicalize_context(canonicalize_request)
13
- CanonicalizeContext.new(
14
- canonicalize_request.containing_url == '' ? nil : canonicalize_request.containing_url,
15
- canonicalize_request.from_import
16
- )
9
+ class Protofier
10
+ def initialize(function_registry)
11
+ @function_registry = function_registry
17
12
  end
18
13
 
19
- def from_proto_compile_response(compile_response)
20
- oneof = compile_response.result
21
- result = compile_response.public_send(oneof)
14
+ def to_proto(obj)
15
+ case obj
16
+ when Sass::Value::String
17
+ EmbeddedProtocol::Value.new(
18
+ string: EmbeddedProtocol::Value::String.new(
19
+ text: obj.text.to_str,
20
+ quoted: obj.quoted?
21
+ )
22
+ )
23
+ when Sass::Value::Number
24
+ EmbeddedProtocol::Value.new(
25
+ number: Number.to_proto(obj)
26
+ )
27
+ when Sass::Value::Color
28
+ if obj.instance_eval { !defined?(@hue) }
29
+ EmbeddedProtocol::Value.new(
30
+ rgb_color: EmbeddedProtocol::Value::RgbColor.new(
31
+ red: obj.red,
32
+ green: obj.green,
33
+ blue: obj.blue,
34
+ alpha: obj.alpha.to_f
35
+ )
36
+ )
37
+ elsif obj.instance_eval { !defined?(@saturation) }
38
+ EmbeddedProtocol::Value.new(
39
+ hwb_color: EmbeddedProtocol::Value::HwbColor.new(
40
+ hue: obj.hue.to_f,
41
+ whiteness: obj.whiteness.to_f,
42
+ blackness: obj.blackness.to_f,
43
+ alpha: obj.alpha.to_f
44
+ )
45
+ )
46
+ else
47
+ EmbeddedProtocol::Value.new(
48
+ hsl_color: EmbeddedProtocol::Value::HslColor.new(
49
+ hue: obj.hue.to_f,
50
+ saturation: obj.saturation.to_f,
51
+ lightness: obj.lightness.to_f,
52
+ alpha: obj.alpha.to_f
53
+ )
54
+ )
55
+ end
56
+ when Sass::Value::ArgumentList
57
+ EmbeddedProtocol::Value.new(
58
+ argument_list: EmbeddedProtocol::Value::ArgumentList.new(
59
+ id: obj.instance_eval { @id },
60
+ contents: obj.to_a.map { |element| to_proto(element) },
61
+ keywords: obj.keywords.to_h { |key, value| [key.to_s, to_proto(value)] },
62
+ separator: ListSeparator.to_proto(obj.separator)
63
+ )
64
+ )
65
+ when Sass::Value::List
66
+ EmbeddedProtocol::Value.new(
67
+ list: EmbeddedProtocol::Value::List.new(
68
+ contents: obj.to_a.map { |element| to_proto(element) },
69
+ separator: ListSeparator.to_proto(obj.separator),
70
+ has_brackets: obj.bracketed?
71
+ )
72
+ )
73
+ when Sass::Value::Map
74
+ EmbeddedProtocol::Value.new(
75
+ map: EmbeddedProtocol::Value::Map.new(
76
+ entries: obj.contents.map do |key, value|
77
+ EmbeddedProtocol::Value::Map::Entry.new(
78
+ key: to_proto(key),
79
+ value: to_proto(value)
80
+ )
81
+ end
82
+ )
83
+ )
84
+ when Sass::Value::Function
85
+ if obj.instance_eval { @id }
86
+ EmbeddedProtocol::Value.new(
87
+ compiler_function: EmbeddedProtocol::Value::CompilerFunction.new(
88
+ id: obj.instance_eval { @id }
89
+ )
90
+ )
91
+ else
92
+ EmbeddedProtocol::Value.new(
93
+ host_function: EmbeddedProtocol::Value::HostFunction.new(
94
+ id: @function_registry.register(obj.callback),
95
+ signature: obj.signature
96
+ )
97
+ )
98
+ end
99
+ when Sass::Value::Mixin
100
+ EmbeddedProtocol::Value.new(
101
+ compiler_mixin: EmbeddedProtocol::Value::CompilerMixin.new(
102
+ id: obj.instance_eval { @id }
103
+ )
104
+ )
105
+ when Sass::Value::Calculation
106
+ EmbeddedProtocol::Value.new(
107
+ calculation: Calculation.to_proto(obj)
108
+ )
109
+ when Sass::Value::Boolean
110
+ EmbeddedProtocol::Value.new(
111
+ singleton: obj.value ? :TRUE : :FALSE
112
+ )
113
+ when Sass::Value::Null
114
+ EmbeddedProtocol::Value.new(
115
+ singleton: :NULL
116
+ )
117
+ else
118
+ raise Sass::ScriptError, "Unknown Sass::Value #{obj}"
119
+ end
120
+ end
121
+
122
+ def from_proto(proto)
123
+ oneof = proto.value
124
+ obj = proto.public_send(oneof)
22
125
  case oneof
23
- when :failure
24
- raise CompileError.new(
25
- result.message,
26
- result.formatted == '' ? nil : result.formatted,
27
- result.stack_trace == '' ? nil : result.stack_trace,
28
- from_proto_source_span(result.span),
29
- compile_response.loaded_urls
30
- )
31
- when :success
32
- CompileResult.new(
33
- result.css,
34
- result.source_map == '' ? nil : result.source_map,
35
- compile_response.loaded_urls
126
+ when :string
127
+ Sass::Value::String.new(
128
+ obj.text,
129
+ quoted: obj.quoted
130
+ )
131
+ when :number
132
+ Number.from_proto(obj)
133
+ when :rgb_color
134
+ Sass::Value::Color.new(
135
+ red: obj.red,
136
+ green: obj.green,
137
+ blue: obj.blue,
138
+ alpha: obj.alpha
139
+ )
140
+ when :hsl_color
141
+ Sass::Value::Color.new(
142
+ hue: obj.hue,
143
+ saturation: obj.saturation,
144
+ lightness: obj.lightness,
145
+ alpha: obj.alpha
146
+ )
147
+ when :hwb_color
148
+ Sass::Value::Color.new(
149
+ hue: obj.hue,
150
+ whiteness: obj.whiteness,
151
+ blackness: obj.blackness,
152
+ alpha: obj.alpha
153
+ )
154
+ when :argument_list
155
+ Sass::Value::ArgumentList.new(
156
+ obj.contents.map do |element|
157
+ from_proto(element)
158
+ end,
159
+ obj.keywords.entries.to_h do |key, value|
160
+ [key.to_sym, from_proto(value)]
161
+ end,
162
+ ListSeparator.from_proto(obj.separator)
163
+ ).instance_eval do
164
+ @id = obj.id
165
+ self
166
+ end
167
+ when :list
168
+ Sass::Value::List.new(
169
+ obj.contents.map do |element|
170
+ from_proto(element)
171
+ end,
172
+ separator: ListSeparator.from_proto(obj.separator),
173
+ bracketed: obj.has_brackets
174
+ )
175
+ when :map
176
+ Sass::Value::Map.new(
177
+ obj.entries.to_h do |entry|
178
+ [from_proto(entry.key), from_proto(entry.value)]
179
+ end
36
180
  )
181
+ when :compiler_function
182
+ Sass::Value::Function.new(nil).instance_eval do
183
+ @id = obj.id
184
+ self
185
+ end
186
+ when :host_function
187
+ raise Sass::ScriptError, 'The compiler may not send Value.host_function to host'
188
+ when :compiler_mixin
189
+ Sass::Value::Mixin.send(:new).instance_eval do
190
+ @id = obj.id
191
+ self
192
+ end
193
+ when :calculation
194
+ Calculation.from_proto(obj)
195
+ when :singleton
196
+ case obj
197
+ when :TRUE
198
+ Sass::Value::Boolean::TRUE
199
+ when :FALSE
200
+ Sass::Value::Boolean::FALSE
201
+ when :NULL
202
+ Sass::Value::Null::NULL
203
+ else
204
+ raise Sass::ScriptError, "Unknown Value.singleton #{obj}"
205
+ end
37
206
  else
38
- raise ArgumentError, "Unknown CompileResponse.result #{result}"
207
+ raise Sass::ScriptError, "Unknown Value.value #{obj}"
39
208
  end
40
209
  end
41
210
 
42
- def from_proto_source_span(source_span)
43
- return if source_span.nil?
211
+ # The {Number} Protofier.
212
+ module Number
213
+ module_function
44
214
 
45
- Logger::SourceSpan.new(from_proto_source_location(source_span.start),
46
- from_proto_source_location(source_span.end),
47
- source_span.text,
48
- source_span.url == '' ? nil : source_span.url,
49
- source_span.context == '' ? nil : source_span.context)
215
+ def to_proto(obj)
216
+ EmbeddedProtocol::Value::Number.new(
217
+ value: obj.value.to_f,
218
+ numerators: obj.numerator_units,
219
+ denominators: obj.denominator_units
220
+ )
221
+ end
222
+
223
+ def from_proto(obj)
224
+ Sass::Value::Number.new(
225
+ obj.value, {
226
+ numerator_units: obj.numerators.to_a,
227
+ denominator_units: obj.denominators.to_a
228
+ }
229
+ )
230
+ end
50
231
  end
51
232
 
52
- def from_proto_source_location(source_location)
53
- return if source_location.nil?
233
+ private_constant :Number
234
+
235
+ # The {Calculation} Protofier.
236
+ module Calculation
237
+ module_function
54
238
 
55
- Logger::SourceLocation.new(source_location.offset,
56
- source_location.line,
57
- source_location.column)
239
+ def to_proto(obj)
240
+ EmbeddedProtocol::Value::Calculation.new(
241
+ name: obj.name,
242
+ arguments: obj.arguments.map { |argument| CalculationValue.to_proto(argument) }
243
+ )
244
+ end
245
+
246
+ def from_proto(obj)
247
+ Sass::Value::Calculation.send(
248
+ :new,
249
+ obj.name,
250
+ obj.arguments.map { |argument| CalculationValue.from_proto(argument) }
251
+ )
252
+ end
58
253
  end
59
254
 
60
- def to_proto_syntax(syntax)
61
- case syntax&.to_sym
62
- when :scss
63
- EmbeddedProtocol::Syntax::SCSS
64
- when :indented
65
- EmbeddedProtocol::Syntax::INDENTED
66
- when :css
67
- EmbeddedProtocol::Syntax::CSS
68
- else
69
- raise ArgumentError, 'syntax must be one of :scss, :indented, :css'
255
+ private_constant :Calculation
256
+
257
+ # The {CalculationValue} Protofier.
258
+ module CalculationValue
259
+ module_function
260
+
261
+ def to_proto(value)
262
+ case value
263
+ when Sass::Value::Number
264
+ EmbeddedProtocol::Value::Calculation::CalculationValue.new(
265
+ number: Number.to_proto(value)
266
+ )
267
+ when Sass::Value::Calculation
268
+ EmbeddedProtocol::Value::Calculation::CalculationValue.new(
269
+ calculation: Calculation.to_proto(value)
270
+ )
271
+ when Sass::Value::String
272
+ EmbeddedProtocol::Value::Calculation::CalculationValue.new(
273
+ string: value.text
274
+ )
275
+ when Sass::CalculationValue::CalculationOperation
276
+ EmbeddedProtocol::Value::Calculation::CalculationValue.new(
277
+ operation: EmbeddedProtocol::Value::Calculation::CalculationOperation.new(
278
+ operator: CalculationOperator.to_proto(value.operator),
279
+ left: to_proto(value.left),
280
+ right: to_proto(value.right)
281
+ )
282
+ )
283
+ else
284
+ raise Sass::ScriptError, "Unknown CalculationValue #{value}"
285
+ end
286
+ end
287
+
288
+ def from_proto(value)
289
+ oneof = value.value
290
+ obj = value.public_send(oneof)
291
+ case oneof
292
+ when :number
293
+ Number.from_proto(obj)
294
+ when :calculation
295
+ Calculation.from_proto(obj)
296
+ when :string
297
+ Sass::Value::String.new(obj, quoted: false)
298
+ when :operation
299
+ Sass::CalculationValue::CalculationOperation.new(
300
+ CalculationOperator.from_proto(obj.operator),
301
+ from_proto(obj.left),
302
+ from_proto(obj.right)
303
+ )
304
+ else
305
+ raise Sass::ScriptError, "Unknown CalculationValue #{value}"
306
+ end
70
307
  end
71
308
  end
72
309
 
73
- def to_proto_output_style(style)
74
- case style&.to_sym
75
- when :expanded
76
- EmbeddedProtocol::OutputStyle::EXPANDED
77
- when :compressed
78
- EmbeddedProtocol::OutputStyle::COMPRESSED
79
- else
80
- raise ArgumentError, 'style must be one of :expanded, :compressed'
310
+ private_constant :CalculationValue
311
+
312
+ # The {CalculationOperator} Protofier.
313
+ module CalculationOperator
314
+ module_function
315
+
316
+ def to_proto(operator)
317
+ case operator
318
+ when '+'
319
+ :PLUS
320
+ when '-'
321
+ :MINUS
322
+ when '*'
323
+ :TIMES
324
+ when '/'
325
+ :DIVIDE
326
+ else
327
+ raise Sass::ScriptError, "Unknown CalculationOperator #{separator}"
328
+ end
329
+ end
330
+
331
+ def from_proto(operator)
332
+ case operator
333
+ when :PLUS
334
+ '+'
335
+ when :MINUS
336
+ '-'
337
+ when :TIMES
338
+ '*'
339
+ when :DIVIDE
340
+ '/'
341
+ else
342
+ raise Sass::ScriptError, "Unknown CalculationOperator #{separator}"
343
+ end
81
344
  end
82
345
  end
346
+
347
+ private_constant :CalculationOperator
348
+
349
+ # The {ListSeparator} Protofier.
350
+ module ListSeparator
351
+ module_function
352
+
353
+ def to_proto(separator)
354
+ case separator
355
+ when ','
356
+ :COMMA
357
+ when ' '
358
+ :SPACE
359
+ when '/'
360
+ :SLASH
361
+ when nil
362
+ :UNDECIDED
363
+ else
364
+ raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
365
+ end
366
+ end
367
+
368
+ def from_proto(separator)
369
+ case separator
370
+ when :COMMA
371
+ ','
372
+ when :SPACE
373
+ ' '
374
+ when :SLASH
375
+ '/'
376
+ when :UNDECIDED
377
+ nil
378
+ else
379
+ raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
380
+ end
381
+ end
382
+ end
383
+
384
+ private_constant :ListSeparator
83
385
  end
84
386
 
85
387
  private_constant :Protofier
@@ -5,7 +5,6 @@ require_relative 'host/importer_registry'
5
5
  require_relative 'host/logger_registry'
6
6
  require_relative 'host/protofier'
7
7
  require_relative 'host/structifier'
8
- require_relative 'host/value_protofier'
9
8
 
10
9
  module Sass
11
10
  class Compiler
@@ -13,8 +12,8 @@ module Sass
13
12
  #
14
13
  # It communicates with {Dispatcher} and handles the host logic.
15
14
  class Host
16
- def initialize(dispatcher)
17
- @dispatcher = dispatcher
15
+ def initialize(channel)
16
+ @channel = channel
18
17
  end
19
18
 
20
19
  def compile_request(path:,
@@ -46,12 +45,19 @@ module Sass
46
45
  EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
47
46
  source: source.to_str,
48
47
  url: url&.to_s,
49
- syntax: Protofier.to_proto_syntax(syntax),
48
+ syntax: @importer_registry.syntax_to_proto(syntax),
50
49
  importer: (@importer_registry.register(importer) unless importer.nil?)
51
50
  )
52
51
  end,
53
52
  path: (File.absolute_path(path) unless path.nil?),
54
- style: Protofier.to_proto_output_style(style),
53
+ style: case style&.to_sym
54
+ when :expanded
55
+ EmbeddedProtocol::OutputStyle::EXPANDED
56
+ when :compressed
57
+ EmbeddedProtocol::OutputStyle::COMPRESSED
58
+ else
59
+ raise ArgumentError, 'style must be one of :expanded, :compressed'
60
+ end,
55
61
  charset:,
56
62
  source_map:,
57
63
  source_map_include_sources:,
@@ -60,11 +66,31 @@ module Sass
60
66
  alert_ascii:,
61
67
  alert_color:,
62
68
  quiet_deps:,
69
+ silent: logger == Logger.silent,
63
70
  verbose:
64
71
  ))
65
72
  end
66
73
 
67
- Protofier.from_proto_compile_response(compile_response)
74
+ oneof = compile_response.result
75
+ result = compile_response.public_send(oneof)
76
+ case oneof
77
+ when :failure
78
+ raise CompileError.new(
79
+ result.message,
80
+ result.formatted == '' ? nil : result.formatted,
81
+ result.stack_trace == '' ? nil : result.stack_trace,
82
+ result.span.nil? ? nil : Logger::SourceSpan.new(result.span),
83
+ compile_response.loaded_urls
84
+ )
85
+ when :success
86
+ CompileResult.new(
87
+ result.css,
88
+ result.source_map == '' ? nil : result.source_map,
89
+ compile_response.loaded_urls
90
+ )
91
+ else
92
+ raise ArgumentError, "Unknown CompileResponse.result #{result}"
93
+ end
68
94
  end
69
95
 
70
96
  def version_request
@@ -74,14 +100,18 @@ module Sass
74
100
  ))
75
101
  end
76
102
 
77
- lang = case version_response.implementation_name
78
- when /\bdart\b/i
79
- '[Dart]'
80
- else
81
- '[?]'
82
- end
103
+ info = [
104
+ version_response.implementation_name,
105
+ version_response.implementation_version,
106
+ '(Sass Compiler)'
107
+ ]
108
+
109
+ case version_response.implementation_name
110
+ when 'dart-sass'
111
+ info << '[Dart]'
112
+ end
83
113
 
84
- "#{version_response.implementation_name}\t#{version_response.implementation_version}\t(Sass Compiler)\t#{lang}"
114
+ info
85
115
  end
86
116
 
87
117
  def compile_response(message)
@@ -98,7 +128,7 @@ module Sass
98
128
  case message
99
129
  when EmbeddedProtocol::ProtocolError
100
130
  @error = Errno::EPROTO.new(message.message)
101
- @channel.error(@error)
131
+ @stream.error(@error)
102
132
  else
103
133
  @error ||= message
104
134
  end
@@ -108,7 +138,7 @@ module Sass
108
138
  def log_event(message)
109
139
  @logger_registry.log(message)
110
140
  rescue StandardError => e
111
- @channel.error(e)
141
+ @stream.error(e)
112
142
  end
113
143
 
114
144
  def canonicalize_request(message)
@@ -156,7 +186,7 @@ module Sass
156
186
 
157
187
  def listen
158
188
  @queue = Queue.new
159
- @channel = @dispatcher.connect(self)
189
+ @stream = @channel.stream(self)
160
190
 
161
191
  yield
162
192
 
@@ -164,22 +194,22 @@ module Sass
164
194
 
165
195
  @result
166
196
  ensure
167
- @channel&.disconnect
197
+ @stream&.close
168
198
  @queue&.close
169
199
  end
170
200
 
171
201
  def id
172
- @channel.id
202
+ @stream.id
173
203
  end
174
204
 
175
205
  def send_message0(...)
176
206
  inbound_message = EmbeddedProtocol::InboundMessage.new(...)
177
- @channel.send_proto(0, inbound_message.to_proto)
207
+ @stream.send_proto(0, inbound_message.to_proto)
178
208
  end
179
209
 
180
210
  def send_message(...)
181
211
  inbound_message = EmbeddedProtocol::InboundMessage.new(...)
182
- @channel.send_proto(id, inbound_message.to_proto)
212
+ @stream.send_proto(id, inbound_message.to_proto)
183
213
  end
184
214
  end
185
215
 
data/lib/sass/compiler.rb CHANGED
@@ -2,32 +2,35 @@
2
2
 
3
3
  require_relative 'canonicalize_context'
4
4
  require_relative 'compile_result'
5
+ require_relative 'compiler/channel'
5
6
  require_relative 'compiler/connection'
6
7
  require_relative 'compiler/dispatcher'
7
- require_relative 'compiler/dispatcher_manager'
8
8
  require_relative 'compiler/host'
9
9
  require_relative 'compiler/varint'
10
+ require_relative 'embedded/version'
10
11
  require_relative 'embedded_protocol'
11
12
  require_relative 'exception'
12
13
  require_relative 'fork_tracker'
13
14
  require_relative 'logger/silent'
14
15
  require_relative 'logger/source_location'
15
16
  require_relative 'logger/source_span'
17
+ require_relative 'node_package_importer'
16
18
  require_relative 'serializer'
17
19
  require_relative 'value'
18
20
 
19
21
  module Sass
20
- # The {Compiler} for using dart-sass. Each instance creates its own
21
- # communication {Dispatcher} with a dedicated compiler process.
22
+ # A synchronous {Compiler}.
23
+ # Each compiler instance exposes the {#compile} and {#compile_string} methods within the lifespan of the compiler.
22
24
  #
23
25
  # @example
24
26
  # sass = Sass::Compiler.new
25
27
  # result = sass.compile_string('h1 { font-size: 40px; }')
26
28
  # result = sass.compile('style.scss')
27
29
  # sass.close
30
+ # @see https://sass-lang.com/documentation/js-api/classes/compiler/
28
31
  class Compiler
29
32
  def initialize
30
- @dispatcher = DispatcherManager.new(Dispatcher)
33
+ @channel = Channel.new(Dispatcher)
31
34
  end
32
35
 
33
36
  # Compiles the Sass file at +path+ to CSS.
@@ -76,7 +79,7 @@ module Sass
76
79
  verbose: false)
77
80
  raise ArgumentError, 'path must be set' if path.nil?
78
81
 
79
- Host.new(@dispatcher).compile_request(
82
+ Host.new(@channel).compile_request(
80
83
  path:,
81
84
  source: nil,
82
85
  importer: nil,
@@ -150,7 +153,7 @@ module Sass
150
153
  verbose: false)
151
154
  raise ArgumentError, 'source must be set' if source.nil?
152
155
 
153
- Host.new(@dispatcher).compile_request(
156
+ Host.new(@channel).compile_request(
154
157
  path: nil,
155
158
  source:,
156
159
  importer:,
@@ -174,18 +177,18 @@ module Sass
174
177
  # @return [String] Information about the Sass implementation.
175
178
  # @see https://sass-lang.com/documentation/js-api/variables/info/
176
179
  def info
177
- @info ||= <<~INFO.freeze
178
- sass-embedded\t#{Embedded::VERSION}\t(Embedded Host)\t[Ruby]
179
- #{Host.new(@dispatcher).version_request}
180
- INFO
180
+ @info ||= [
181
+ ['sass-embedded', Embedded::VERSION, '(Embedded Host)', '[Ruby]'].join("\t"),
182
+ Host.new(@channel).version_request.join("\t")
183
+ ].join("\n").freeze
181
184
  end
182
185
 
183
186
  def close
184
- @dispatcher.close
187
+ @channel.close
185
188
  end
186
189
 
187
190
  def closed?
188
- @dispatcher.closed?
191
+ @channel.closed?
189
192
  end
190
193
  end
191
194
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sass
4
4
  module Embedded
5
- VERSION = '1.69.7'
5
+ VERSION = '1.71.0'
6
6
  end
7
7
  end