sass-embedded 1.6.2 → 1.83.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -3
  3. data/exe/sass +13 -0
  4. data/ext/sass/Rakefile +352 -76
  5. data/ext/sass/embedded_sass_pb.rb +61 -0
  6. data/ext/sass/expand-archive.ps1 +1 -0
  7. data/ext/sass/package.json +1 -1
  8. data/lib/sass/calculation_value/calculation_operation.rb +49 -0
  9. data/lib/sass/calculation_value.rb +22 -0
  10. data/lib/sass/canonicalize_context.rb +25 -0
  11. data/lib/sass/compile_result.rb +3 -2
  12. data/lib/sass/compiler/channel.rb +68 -0
  13. data/lib/sass/compiler/connection.rb +89 -0
  14. data/lib/sass/compiler/dispatcher.rb +116 -0
  15. data/lib/sass/{embedded → compiler}/host/function_registry.rb +31 -34
  16. data/lib/sass/compiler/host/importer_registry.rb +141 -0
  17. data/lib/sass/compiler/host/logger_registry.rb +80 -0
  18. data/lib/sass/compiler/host/protofier.rb +360 -0
  19. data/lib/sass/compiler/host/structifier.rb +37 -0
  20. data/lib/sass/compiler/host.rb +226 -0
  21. data/lib/sass/{embedded → compiler}/varint.rb +9 -5
  22. data/lib/sass/compiler.rb +212 -0
  23. data/lib/sass/elf.rb +222 -0
  24. data/lib/sass/embedded/version.rb +2 -2
  25. data/lib/sass/embedded.rb +76 -204
  26. data/lib/sass/embedded_protocol.rb +10 -0
  27. data/lib/sass/exception.rb +74 -0
  28. data/lib/sass/fork_tracker.rb +51 -0
  29. data/lib/sass/logger/silent.rb +5 -3
  30. data/lib/sass/logger/source_location.rb +6 -5
  31. data/lib/sass/logger/source_span.rb +8 -7
  32. data/lib/sass/node_package_importer.rb +17 -0
  33. data/lib/sass/serializer.rb +30 -0
  34. data/lib/sass/value/argument_list.rb +13 -6
  35. data/lib/sass/value/boolean.rb +1 -1
  36. data/lib/sass/value/calculation.rb +90 -0
  37. data/lib/sass/value/color/channel.rb +79 -0
  38. data/lib/sass/value/color/conversions.rb +473 -0
  39. data/lib/sass/value/color/gamut_map_method/clip.rb +45 -0
  40. data/lib/sass/value/color/gamut_map_method/local_minde.rb +94 -0
  41. data/lib/sass/value/color/gamut_map_method.rb +45 -0
  42. data/lib/sass/value/color/interpolation_method.rb +51 -0
  43. data/lib/sass/value/color/space/a98_rgb.rb +57 -0
  44. data/lib/sass/value/color/space/display_p3.rb +57 -0
  45. data/lib/sass/value/color/space/hsl.rb +65 -0
  46. data/lib/sass/value/color/space/hwb.rb +70 -0
  47. data/lib/sass/value/color/space/lab.rb +77 -0
  48. data/lib/sass/value/color/space/lch.rb +53 -0
  49. data/lib/sass/value/color/space/lms.rb +129 -0
  50. data/lib/sass/value/color/space/oklab.rb +66 -0
  51. data/lib/sass/value/color/space/oklch.rb +54 -0
  52. data/lib/sass/value/color/space/prophoto_rgb.rb +59 -0
  53. data/lib/sass/value/color/space/rec2020.rb +69 -0
  54. data/lib/sass/value/color/space/rgb.rb +52 -0
  55. data/lib/sass/value/color/space/srgb.rb +140 -0
  56. data/lib/sass/value/color/space/srgb_linear.rb +72 -0
  57. data/lib/sass/value/color/space/utils.rb +86 -0
  58. data/lib/sass/value/color/space/xyz_d50.rb +100 -0
  59. data/lib/sass/value/color/space/xyz_d65.rb +57 -0
  60. data/lib/sass/value/color/space.rb +198 -0
  61. data/lib/sass/value/color.rb +538 -163
  62. data/lib/sass/value/function.rb +11 -16
  63. data/lib/sass/value/fuzzy_math.rb +24 -21
  64. data/lib/sass/value/list.rb +7 -7
  65. data/lib/sass/value/map.rb +6 -6
  66. data/lib/sass/value/mixin.rb +34 -0
  67. data/lib/sass/value/null.rb +1 -1
  68. data/lib/sass/value/number/unit.rb +7 -6
  69. data/lib/sass/value/number.rb +34 -26
  70. data/lib/sass/value/string.rb +9 -3
  71. data/lib/sass/value.rb +20 -16
  72. metadata +67 -103
  73. data/ext/sass/unzip.vbs +0 -13
  74. data/lib/sass/compile_error.rb +0 -28
  75. data/lib/sass/embedded/async.rb +0 -65
  76. data/lib/sass/embedded/channel.rb +0 -61
  77. data/lib/sass/embedded/compiler.rb +0 -60
  78. data/lib/sass/embedded/dispatcher.rb +0 -90
  79. data/lib/sass/embedded/host/importer_registry.rb +0 -107
  80. data/lib/sass/embedded/host/logger_registry.rb +0 -50
  81. data/lib/sass/embedded/host/value_protofier.rb +0 -241
  82. data/lib/sass/embedded/host.rb +0 -139
  83. data/lib/sass/embedded/protofier.rb +0 -78
  84. data/lib/sass/embedded/structifier.rb +0 -36
  85. data/lib/sass/script_error.rb +0 -6
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sass
4
- class Embedded
5
- class Host
6
- # The {LoggerRegistry} class.
7
- #
8
- # It stores logger and handles log events.
9
- class LoggerRegistry
10
- attr_reader :logger
11
-
12
- def initialize(logger)
13
- @logger = Structifier.to_struct(logger)
14
- end
15
-
16
- def log(event)
17
- case event.type
18
- when :DEBUG
19
- if logger.respond_to? :debug
20
- logger.debug(event.message,
21
- span: Protofier.from_proto_source_span(event.span))
22
- else
23
- warn(event.formatted)
24
- end
25
- when :DEPRECATION_WARNING
26
- if logger.respond_to? :warn
27
- logger.warn(event.message,
28
- deprecation: true,
29
- span: Protofier.from_proto_source_span(event.span),
30
- stack: event.stack_trace)
31
- else
32
- warn(event.formatted)
33
- end
34
- when :WARNING
35
- if logger.respond_to? :warn
36
- logger.warn(event.message,
37
- deprecation: false,
38
- span: Protofier.from_proto_source_span(event.span),
39
- stack: event.stack_trace)
40
- else
41
- warn(event.formatted)
42
- end
43
- end
44
- end
45
- end
46
-
47
- private_constant :LoggerRegistry
48
- end
49
- end
50
- end
@@ -1,241 +0,0 @@
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 do |entry|
159
- [entry.first, from_proto(entry.last)]
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
@@ -1,139 +0,0 @@
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
- source_map:,
33
- source_map_include_sources:,
34
- style:,
35
- functions:,
36
- importers:,
37
- alert_ascii:,
38
- alert_color:,
39
- logger:,
40
- quiet_deps:,
41
- verbose:)
42
- await do
43
- alert_color = $stderr.tty? if alert_color.nil?
44
-
45
- @function_registry = FunctionRegistry.new(functions, alert_color: alert_color)
46
- @importer_registry = ImporterRegistry.new(importers, load_paths, alert_color: alert_color)
47
- @logger_registry = LoggerRegistry.new(logger)
48
-
49
- send_message EmbeddedProtocol::InboundMessage.new(
50
- compile_request: EmbeddedProtocol::InboundMessage::CompileRequest.new(
51
- id: id,
52
- string: unless source.nil?
53
- EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
54
- source: source,
55
- url: url&.to_s,
56
- syntax: Protofier.to_proto_syntax(syntax),
57
- importer: (@importer_registry.register(importer) unless importer.nil?)
58
- )
59
- end,
60
- path: (File.absolute_path(path) unless path.nil?),
61
- style: Protofier.to_proto_output_style(style),
62
- source_map: source_map,
63
- source_map_include_sources: source_map_include_sources,
64
- importers: @importer_registry.importers,
65
- global_functions: @function_registry.global_functions,
66
- alert_ascii: alert_ascii,
67
- alert_color: alert_color,
68
- quiet_deps: quiet_deps,
69
- verbose: verbose
70
- )
71
- )
72
- end
73
- end
74
-
75
- def version_request
76
- await do
77
- send_message EmbeddedProtocol::InboundMessage.new(
78
- version_request: EmbeddedProtocol::InboundMessage::VersionRequest.new(
79
- id: id
80
- )
81
- )
82
- end
83
- end
84
-
85
- def log_event(message)
86
- @logger_registry.log(message)
87
- end
88
-
89
- def compile_response(message)
90
- @async.resolve(message)
91
- end
92
-
93
- def version_response(message)
94
- @async.resolve(message)
95
- end
96
-
97
- def canonicalize_request(message)
98
- send_message EmbeddedProtocol::InboundMessage.new(
99
- canonicalize_response: @importer_registry.canonicalize(message)
100
- )
101
- end
102
-
103
- def import_request(message)
104
- send_message EmbeddedProtocol::InboundMessage.new(
105
- import_response: @importer_registry.import(message)
106
- )
107
- end
108
-
109
- def file_import_request(message)
110
- send_message EmbeddedProtocol::InboundMessage.new(
111
- file_import_response: @importer_registry.file_import(message)
112
- )
113
- end
114
-
115
- def function_call_request(message)
116
- send_message EmbeddedProtocol::InboundMessage.new(
117
- function_call_response: @function_registry.function_call(message)
118
- )
119
- end
120
-
121
- def error(message)
122
- @async.reject(CompileError.new(message.message, nil, nil, nil))
123
- end
124
-
125
- private
126
-
127
- def await
128
- @connection = @channel.connect(self)
129
- @async = Async.new
130
- yield
131
- @async.await
132
- ensure
133
- @connection.disconnect
134
- end
135
- end
136
-
137
- private_constant :Host
138
- end
139
- end
@@ -1,78 +0,0 @@
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
@@ -1,36 +0,0 @@
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
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sass
4
- # An exception thrown by Sass Script.
5
- class ScriptError < StandardError; end
6
- end