sass-embedded 1.107.0-aarch64-mswin64

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 (81) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +48 -0
  4. data/exe/sass +13 -0
  5. data/lib/sass/calculation_value/calculation_operation.rb +49 -0
  6. data/lib/sass/calculation_value.rb +22 -0
  7. data/lib/sass/canonicalize_context.rb +25 -0
  8. data/lib/sass/cli.rb +12 -0
  9. data/lib/sass/compile_result.rb +24 -0
  10. data/lib/sass/compiler/channel.rb +70 -0
  11. data/lib/sass/compiler/connection.rb +109 -0
  12. data/lib/sass/compiler/dispatcher.rb +142 -0
  13. data/lib/sass/compiler/session/function_registry.rb +88 -0
  14. data/lib/sass/compiler/session/importer_registry.rb +190 -0
  15. data/lib/sass/compiler/session/logger_registry.rb +99 -0
  16. data/lib/sass/compiler/session/path.rb +23 -0
  17. data/lib/sass/compiler/session/protofier.rb +384 -0
  18. data/lib/sass/compiler/session/stack_trace.rb +46 -0
  19. data/lib/sass/compiler/session.rb +242 -0
  20. data/lib/sass/compiler/varint.rb +39 -0
  21. data/lib/sass/compiler.rb +214 -0
  22. data/lib/sass/dart-sass/sass.bat +7 -0
  23. data/lib/sass/dart-sass/src/LICENSE +1659 -0
  24. data/lib/sass/dart-sass/src/dart.exe +0 -0
  25. data/lib/sass/dart-sass/src/sass.snapshot +0 -0
  26. data/lib/sass/elf.rb +386 -0
  27. data/lib/sass/embedded/version.rb +7 -0
  28. data/lib/sass/embedded.rb +67 -0
  29. data/lib/sass/embedded_protocol.rb +10 -0
  30. data/lib/sass/embedded_sass_pb.rb +62 -0
  31. data/lib/sass/exception.rb +73 -0
  32. data/lib/sass/fork_tracker.rb +56 -0
  33. data/lib/sass/gem_package_importer.rb +28 -0
  34. data/lib/sass/logger/silent.rb +28 -0
  35. data/lib/sass/logger/source_location.rb +22 -0
  36. data/lib/sass/logger/source_span.rb +28 -0
  37. data/lib/sass/node_package_importer.rb +17 -0
  38. data/lib/sass/serializer.rb +30 -0
  39. data/lib/sass/uri.rb +56 -0
  40. data/lib/sass/value/argument_list.rb +29 -0
  41. data/lib/sass/value/boolean.rb +59 -0
  42. data/lib/sass/value/calculation.rb +90 -0
  43. data/lib/sass/value/color/channel.rb +79 -0
  44. data/lib/sass/value/color/conversions.rb +473 -0
  45. data/lib/sass/value/color/gamut_map_method/clip.rb +45 -0
  46. data/lib/sass/value/color/gamut_map_method/local_minde.rb +94 -0
  47. data/lib/sass/value/color/gamut_map_method.rb +45 -0
  48. data/lib/sass/value/color/interpolation_method.rb +51 -0
  49. data/lib/sass/value/color/space/a98_rgb.rb +57 -0
  50. data/lib/sass/value/color/space/display_p3.rb +72 -0
  51. data/lib/sass/value/color/space/display_p3_linear.rb +72 -0
  52. data/lib/sass/value/color/space/hsl.rb +65 -0
  53. data/lib/sass/value/color/space/hwb.rb +94 -0
  54. data/lib/sass/value/color/space/lab.rb +85 -0
  55. data/lib/sass/value/color/space/lch.rb +53 -0
  56. data/lib/sass/value/color/space/lms.rb +146 -0
  57. data/lib/sass/value/color/space/oklab.rb +71 -0
  58. data/lib/sass/value/color/space/oklch.rb +54 -0
  59. data/lib/sass/value/color/space/prophoto_rgb.rb +59 -0
  60. data/lib/sass/value/color/space/rec2020.rb +57 -0
  61. data/lib/sass/value/color/space/rgb.rb +52 -0
  62. data/lib/sass/value/color/space/srgb.rb +145 -0
  63. data/lib/sass/value/color/space/srgb_linear.rb +72 -0
  64. data/lib/sass/value/color/space/utils.rb +89 -0
  65. data/lib/sass/value/color/space/xyz_d50.rb +113 -0
  66. data/lib/sass/value/color/space/xyz_d65.rb +57 -0
  67. data/lib/sass/value/color/space.rb +218 -0
  68. data/lib/sass/value/color.rb +631 -0
  69. data/lib/sass/value/function.rb +66 -0
  70. data/lib/sass/value/fuzzy_math.rb +84 -0
  71. data/lib/sass/value/list.rb +89 -0
  72. data/lib/sass/value/map.rb +77 -0
  73. data/lib/sass/value/mixin.rb +47 -0
  74. data/lib/sass/value/module.rb +47 -0
  75. data/lib/sass/value/null.rb +58 -0
  76. data/lib/sass/value/number/unit.rb +187 -0
  77. data/lib/sass/value/number.rb +364 -0
  78. data/lib/sass/value/string.rb +78 -0
  79. data/lib/sass/value.rb +174 -0
  80. data/lib/sass-embedded.rb +4 -0
  81. metadata +140 -0
@@ -0,0 +1,190 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Compiler
5
+ class Session
6
+ # The {ImporterRegistry} class.
7
+ #
8
+ # It stores importers and handles import requests.
9
+ class ImporterRegistry
10
+ attr_reader :importers
11
+
12
+ def initialize(importers, load_paths, session:)
13
+ @id = 0
14
+ @importers_by_id = {}.compare_by_identity
15
+ @importers = importers
16
+ .map { |importer| register(importer) }
17
+ .concat(
18
+ load_paths.map do |load_path|
19
+ EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
20
+ path: File.absolute_path(load_path)
21
+ )
22
+ end
23
+ )
24
+
25
+ @session = session
26
+ end
27
+
28
+ def register(importer)
29
+ if importer.is_a?(Sass::NodePackageImporter)
30
+ EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
31
+ node_package_importer: EmbeddedProtocol::NodePackageImporter.new(
32
+ entry_point_directory: importer.instance_variable_get(:@entry_point_directory)
33
+ )
34
+ )
35
+ else
36
+ if importer.is_a?(::Hash)
37
+ is_importer = importer[:canonicalize].respond_to?(:call) && importer[:load].respond_to?(:call)
38
+ is_file_importer = importer[:find_file_url].respond_to?(:call)
39
+ importer = ImporterStruct.new(importer) if is_importer || is_file_importer
40
+ else
41
+ is_importer = importer.respond_to?(:canonicalize) && importer.respond_to?(:load)
42
+ is_file_importer = importer.respond_to?(:find_file_url)
43
+ end
44
+
45
+ raise ArgumentError, 'importer must be an Importer or a FileImporter' if is_importer == is_file_importer
46
+
47
+ id = @id
48
+ @id = id.next
49
+
50
+ @importers_by_id[id] = importer
51
+ if is_importer
52
+ EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
53
+ importer_id: id,
54
+ non_canonical_scheme: if importer.respond_to?(:non_canonical_scheme)
55
+ Array(importer.non_canonical_scheme)
56
+ else
57
+ []
58
+ end
59
+ )
60
+ else
61
+ EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
62
+ file_importer_id: id
63
+ )
64
+ end
65
+ end
66
+ end
67
+
68
+ def canonicalize(canonicalize_request)
69
+ importer = @importers_by_id[canonicalize_request.importer_id]
70
+ canonicalize_context = CanonicalizeContext.new(canonicalize_request)
71
+ url = importer.canonicalize(canonicalize_request.url,
72
+ canonicalize_context)&.to_s
73
+
74
+ EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
75
+ id: canonicalize_request.id,
76
+ url:,
77
+ containing_url_unused: canonicalize_context.instance_variable_get(:@containing_url_unused)
78
+ )
79
+ rescue StandardError => e
80
+ @session.backtrace = e.backtrace
81
+ EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
82
+ id: canonicalize_request.id,
83
+ error: e.detailed_message(highlight: false)
84
+ )
85
+ end
86
+
87
+ def import(import_request)
88
+ importer = @importers_by_id[import_request.importer_id]
89
+ importer_result = importer.load(import_request.url)
90
+ importer_result = ImporterResultStruct.new(importer_result) if importer_result.is_a?(::Hash)
91
+
92
+ EmbeddedProtocol::InboundMessage::ImportResponse.new(
93
+ id: import_request.id,
94
+ success: EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
95
+ contents: importer_result.contents.to_str,
96
+ syntax: syntax_to_proto(importer_result.syntax),
97
+ source_map_url: (importer_result.source_map_url&.to_s if importer_result.respond_to?(:source_map_url))
98
+ )
99
+ )
100
+ rescue StandardError => e
101
+ @session.backtrace = e.backtrace
102
+ EmbeddedProtocol::InboundMessage::ImportResponse.new(
103
+ id: import_request.id,
104
+ error: e.detailed_message(highlight: false)
105
+ )
106
+ end
107
+
108
+ def file_import(file_import_request)
109
+ importer = @importers_by_id[file_import_request.importer_id]
110
+ canonicalize_context = CanonicalizeContext.new(file_import_request)
111
+ file_url = importer.find_file_url(file_import_request.url,
112
+ canonicalize_context)&.to_s
113
+
114
+ EmbeddedProtocol::InboundMessage::FileImportResponse.new(
115
+ id: file_import_request.id,
116
+ file_url:,
117
+ containing_url_unused: canonicalize_context.instance_variable_get(:@containing_url_unused)
118
+ )
119
+ rescue StandardError => e
120
+ @session.backtrace = e.backtrace
121
+ EmbeddedProtocol::InboundMessage::FileImportResponse.new(
122
+ id: file_import_request.id,
123
+ error: e.detailed_message(highlight: false)
124
+ )
125
+ end
126
+
127
+ def syntax_to_proto(syntax)
128
+ case syntax&.to_sym
129
+ when :scss
130
+ EmbeddedProtocol::Syntax::SCSS
131
+ when :indented
132
+ EmbeddedProtocol::Syntax::INDENTED
133
+ when :css
134
+ EmbeddedProtocol::Syntax::CSS
135
+ else
136
+ raise ArgumentError, 'syntax must be one of :scss, :indented, :css'
137
+ end
138
+ end
139
+
140
+ # The {ImporterStruct} class.
141
+ class ImporterStruct
142
+ def initialize(hash)
143
+ @hash = hash
144
+ end
145
+
146
+ def canonicalize(...)
147
+ @hash[:canonicalize].call(...)
148
+ end
149
+
150
+ def load(...)
151
+ @hash[:load].call(...)
152
+ end
153
+
154
+ def non_canonical_scheme
155
+ @hash[:non_canonical_scheme]
156
+ end
157
+
158
+ def find_file_url(...)
159
+ @hash[:find_file_url].call(...)
160
+ end
161
+ end
162
+
163
+ private_constant :ImporterStruct
164
+
165
+ # The {ImporterResultStruct} class.
166
+ class ImporterResultStruct
167
+ def initialize(hash)
168
+ @hash = hash
169
+ end
170
+
171
+ def contents
172
+ @hash[:contents]
173
+ end
174
+
175
+ def syntax
176
+ @hash[:syntax]
177
+ end
178
+
179
+ def source_map_url
180
+ @hash[:source_map_url]
181
+ end
182
+ end
183
+
184
+ private_constant :ImporterResultStruct
185
+ end
186
+
187
+ private_constant :ImporterRegistry
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Compiler
5
+ class Session
6
+ # The {LoggerRegistry} class.
7
+ class LoggerRegistry
8
+ def initialize(logger, alert_color:)
9
+ if logger.is_a?(::Hash)
10
+ respond_to_debug = logger[:debug].respond_to?(:call)
11
+ respond_to_warn = logger[:warn].respond_to?(:call)
12
+ logger = LoggerStruct.new(logger) if respond_to_debug || respond_to_warn
13
+ else
14
+ respond_to_debug = logger.respond_to?(:debug)
15
+ respond_to_warn = logger.respond_to?(:warn)
16
+ end
17
+ @logger = logger
18
+ @alert_color = alert_color
19
+ @respond_to_debug = respond_to_debug
20
+ @respond_to_warn = respond_to_warn
21
+ end
22
+
23
+ def log(event)
24
+ case event.type
25
+ when :DEBUG
26
+ if @respond_to_debug
27
+ @logger.debug(event.message, DebugContext.new(event))
28
+ else
29
+ path = event.span.url == '' ? '-' : Path.pretty_uri(event.span.url)
30
+ line = event.span.start.line + 1
31
+ type = @alert_color ? "\e[1mDebug\e[0m" : 'DEBUG'
32
+ Warning.warn("#{path}:#{line} #{type}: #{event.message}\n")
33
+ end
34
+ when :DEPRECATION_WARNING, :WARNING
35
+ if @respond_to_warn
36
+ @logger.warn(event.message, WarnContext.new(event))
37
+ else
38
+ Warning.warn(StackTrace.pretty_formatted!(+event.formatted, event.stack_trace))
39
+ end
40
+ else
41
+ raise ArgumentError, "Unknown LogEvent.type #{event.type}"
42
+ end
43
+ end
44
+
45
+ # Contextual information passed to `debug`.
46
+ class DebugContext
47
+ # @return [Logger::SourceSpan, nil]
48
+ attr_reader :span
49
+
50
+ def initialize(event)
51
+ @span = event.span.nil? ? nil : Logger::SourceSpan.new(event.span)
52
+ end
53
+ end
54
+
55
+ private_constant :DebugContext
56
+
57
+ # Contextual information passed to `warn`.
58
+ class WarnContext < DebugContext
59
+ # @return [Boolean]
60
+ attr_reader :deprecation
61
+
62
+ # @return [String, nil]
63
+ attr_reader :deprecation_type
64
+
65
+ # @return [String]
66
+ attr_reader :stack
67
+
68
+ def initialize(event)
69
+ super
70
+ @deprecation = event.type == :DEPRECATION_WARNING
71
+ @deprecation_type = (event.deprecation_type if @deprecation)
72
+ @stack = event.stack_trace
73
+ end
74
+ end
75
+
76
+ private_constant :WarnContext
77
+
78
+ # The {LoggerStruct} class.
79
+ class LoggerStruct
80
+ def initialize(hash)
81
+ @hash = hash
82
+ end
83
+
84
+ def debug(...)
85
+ @hash[:debug].call(...)
86
+ end
87
+
88
+ def warn(...)
89
+ @hash[:warn].call(...)
90
+ end
91
+ end
92
+
93
+ private_constant :LoggerStruct
94
+ end
95
+
96
+ private_constant :LoggerRegistry
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Compiler
5
+ class Session
6
+ # @see https://pub.dev/documentation/path/latest/path/
7
+ module Path
8
+ module_function
9
+
10
+ # @see https://pub.dev/documentation/path/latest/path/Context/prettyUri.html
11
+ def pretty_uri(uri)
12
+ return uri unless uri&.start_with?('file:')
13
+
14
+ absolute_path = Uri.file_uri_to_path(uri)
15
+ relative_path = Uri.decode_uri_component(Uri.relative(uri, Uri.pwd))
16
+ relative_path.count('/') > absolute_path.count('/') ? absolute_path : relative_path
17
+ end
18
+ end
19
+
20
+ private_constant :Path
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,384 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Compiler
5
+ class Session
6
+ # The {Protofier} class.
7
+ #
8
+ # It converts Pure Ruby types and Protobuf Ruby types.
9
+ class Protofier
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
+ 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
+ EmbeddedProtocol::Value.new(
29
+ color: EmbeddedProtocol::Value::Color.new(
30
+ channel1: obj.send(:channel0_or_nil),
31
+ channel2: obj.send(:channel1_or_nil),
32
+ channel3: obj.send(:channel2_or_nil),
33
+ alpha: obj.send(:alpha_or_nil),
34
+ space: obj.space
35
+ )
36
+ )
37
+ when Sass::Value::ArgumentList
38
+ if obj.instance_variable_get(:@compile_context) == @function_registry.compile_context
39
+ EmbeddedProtocol::Value.new(
40
+ argument_list: EmbeddedProtocol::Value::ArgumentList.new(
41
+ id: obj.instance_variable_get(:@id)
42
+ )
43
+ )
44
+ else
45
+ EmbeddedProtocol::Value.new(
46
+ argument_list: EmbeddedProtocol::Value::ArgumentList.new(
47
+ contents: obj.to_a.map { |element| to_proto(element) },
48
+ keywords: obj.keywords.each_with_object({}) { |(key, value), hash| hash[key.to_s] = to_proto(value) },
49
+ separator: ListSeparator.to_proto(obj.separator)
50
+ )
51
+ )
52
+ end
53
+ when Sass::Value::List
54
+ EmbeddedProtocol::Value.new(
55
+ list: EmbeddedProtocol::Value::List.new(
56
+ contents: obj.to_a.map { |element| to_proto(element) },
57
+ separator: ListSeparator.to_proto(obj.separator),
58
+ has_brackets: obj.bracketed?
59
+ )
60
+ )
61
+ when Sass::Value::Map
62
+ EmbeddedProtocol::Value.new(
63
+ map: EmbeddedProtocol::Value::Map.new(
64
+ entries: obj.contents.map do |key, value|
65
+ EmbeddedProtocol::Value::Map::Entry.new(
66
+ key: to_proto(key),
67
+ value: to_proto(value)
68
+ )
69
+ end
70
+ )
71
+ )
72
+ when Sass::Value::Function
73
+ if obj.instance_variable_defined?(:@id)
74
+ EmbeddedProtocol::Value.new(
75
+ compiler_function: EmbeddedProtocol::Value::CompilerFunction.new(
76
+ id: assert_compiler_value(obj).instance_variable_get(:@id)
77
+ )
78
+ )
79
+ else
80
+ EmbeddedProtocol::Value.new(
81
+ host_function: EmbeddedProtocol::Value::HostFunction.new(
82
+ id: @function_registry.register(obj.callback),
83
+ signature: obj.signature
84
+ )
85
+ )
86
+ end
87
+ when Sass::Value::Mixin
88
+ EmbeddedProtocol::Value.new(
89
+ compiler_mixin: EmbeddedProtocol::Value::CompilerMixin.new(
90
+ id: assert_compiler_value(obj).instance_variable_get(:@id)
91
+ )
92
+ )
93
+ when Sass::Value::Module
94
+ EmbeddedProtocol::Value.new(
95
+ compiler_module: EmbeddedProtocol::Value::CompilerModule.new(
96
+ id: assert_compiler_value(obj).instance_variable_get(:@id)
97
+ )
98
+ )
99
+ when Sass::Value::Calculation
100
+ EmbeddedProtocol::Value.new(
101
+ calculation: Calculation.to_proto(obj)
102
+ )
103
+ when Sass::Value::Boolean
104
+ EmbeddedProtocol::Value.new(
105
+ singleton: obj.value ? :TRUE : :FALSE
106
+ )
107
+ when Sass::Value::Null
108
+ EmbeddedProtocol::Value.new(
109
+ singleton: :NULL
110
+ )
111
+ else
112
+ raise Sass::ScriptError, "Unknown Sass::Value #{obj.inspect}"
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
+ Number.from_proto(obj)
127
+ when :color
128
+ Sass::Value::Color.send(
129
+ :for_space,
130
+ obj.space,
131
+ obj.has_channel1? ? obj.channel1 : nil,
132
+ obj.has_channel2? ? obj.channel2 : nil,
133
+ obj.has_channel3? ? obj.channel3 : nil,
134
+ obj.has_alpha? ? obj.alpha : nil
135
+ )
136
+ when :argument_list
137
+ compiler_value(
138
+ Sass::Value::ArgumentList.new(
139
+ obj.contents.map do |element|
140
+ from_proto(element)
141
+ end,
142
+ obj.keywords.to_enum.with_object({}) do |(key, value), hash|
143
+ hash[key.to_sym] = from_proto(value)
144
+ end,
145
+ ListSeparator.from_proto(obj.separator)
146
+ ),
147
+ obj.id
148
+ )
149
+ when :list
150
+ Sass::Value::List.new(
151
+ obj.contents.map do |element|
152
+ from_proto(element)
153
+ end,
154
+ separator: ListSeparator.from_proto(obj.separator),
155
+ bracketed: obj.has_brackets
156
+ )
157
+ when :map
158
+ Sass::Value::Map.new(
159
+ obj.entries.to_enum.with_object({}) do |entry, hash|
160
+ hash[from_proto(entry.key)] = from_proto(entry.value)
161
+ end
162
+ )
163
+ when :compiler_function
164
+ compiler_value(Sass::Value::Function.allocate, obj.id)
165
+ when :host_function
166
+ raise Sass::ScriptError, 'The compiler may not send Value.host_function to host'
167
+ when :compiler_mixin
168
+ compiler_value(Sass::Value::Mixin.allocate, obj.id)
169
+ when :compiler_module
170
+ compiler_value(Sass::Value::Module.allocate, obj.id)
171
+ when :calculation
172
+ Calculation.from_proto(obj)
173
+ when :singleton
174
+ case obj
175
+ when :TRUE
176
+ Sass::Value::Boolean::TRUE
177
+ when :FALSE
178
+ Sass::Value::Boolean::FALSE
179
+ when :NULL
180
+ Sass::Value::Null::NULL
181
+ else
182
+ raise Sass::ScriptError, "Unknown Value.singleton #{obj}"
183
+ end
184
+ else
185
+ raise Sass::ScriptError, "Unknown Value.value #{obj}"
186
+ end
187
+ end
188
+
189
+ private
190
+
191
+ def assert_compiler_value(value)
192
+ unless value.instance_variable_get(:@compile_context) == @function_registry.compile_context
193
+ raise Sass::ScriptError, "Value #{value.inspect} does not belong to this compilation"
194
+ end
195
+
196
+ value
197
+ end
198
+
199
+ def compiler_value(value, id)
200
+ value.instance_variable_set(:@compile_context, @function_registry.compile_context)
201
+ value.instance_variable_set(:@id, id)
202
+ value
203
+ end
204
+
205
+ # The {Number} Protofier.
206
+ module Number
207
+ module_function
208
+
209
+ def to_proto(obj)
210
+ EmbeddedProtocol::Value::Number.new(
211
+ value: obj.value.to_f,
212
+ numerators: obj.numerator_units,
213
+ denominators: obj.denominator_units
214
+ )
215
+ end
216
+
217
+ def from_proto(obj)
218
+ Sass::Value::Number.new(
219
+ obj.value, {
220
+ numerator_units: obj.numerators.to_a,
221
+ denominator_units: obj.denominators.to_a
222
+ }
223
+ )
224
+ end
225
+ end
226
+
227
+ private_constant :Number
228
+
229
+ # The {Calculation} Protofier.
230
+ module Calculation
231
+ module_function
232
+
233
+ def to_proto(obj)
234
+ EmbeddedProtocol::Value::Calculation.new(
235
+ name: obj.name,
236
+ arguments: obj.arguments.map { |argument| CalculationValue.to_proto(argument) }
237
+ )
238
+ end
239
+
240
+ def from_proto(obj)
241
+ Sass::Value::Calculation.send(
242
+ :new,
243
+ obj.name,
244
+ obj.arguments.map { |argument| CalculationValue.from_proto(argument) }
245
+ )
246
+ end
247
+ end
248
+
249
+ private_constant :Calculation
250
+
251
+ # The {CalculationValue} Protofier.
252
+ module CalculationValue
253
+ module_function
254
+
255
+ def to_proto(value)
256
+ case value
257
+ when Sass::Value::Number
258
+ EmbeddedProtocol::Value::Calculation::CalculationValue.new(
259
+ number: Number.to_proto(value)
260
+ )
261
+ when Sass::Value::Calculation
262
+ EmbeddedProtocol::Value::Calculation::CalculationValue.new(
263
+ calculation: Calculation.to_proto(value)
264
+ )
265
+ when Sass::Value::String
266
+ EmbeddedProtocol::Value::Calculation::CalculationValue.new(
267
+ string: value.text
268
+ )
269
+ when Sass::CalculationValue::CalculationOperation
270
+ EmbeddedProtocol::Value::Calculation::CalculationValue.new(
271
+ operation: EmbeddedProtocol::Value::Calculation::CalculationOperation.new(
272
+ operator: CalculationOperator.to_proto(value.operator),
273
+ left: to_proto(value.left),
274
+ right: to_proto(value.right)
275
+ )
276
+ )
277
+ else
278
+ raise Sass::ScriptError, "Unknown CalculationValue #{value.inspect}"
279
+ end
280
+ end
281
+
282
+ def from_proto(value)
283
+ oneof = value.value
284
+ obj = value.public_send(oneof)
285
+ case oneof
286
+ when :number
287
+ Number.from_proto(obj)
288
+ when :calculation
289
+ Calculation.from_proto(obj)
290
+ when :string
291
+ Sass::Value::String.new(obj, quoted: false)
292
+ when :operation
293
+ Sass::CalculationValue::CalculationOperation.new(
294
+ CalculationOperator.from_proto(obj.operator),
295
+ from_proto(obj.left),
296
+ from_proto(obj.right)
297
+ )
298
+ else
299
+ raise Sass::ScriptError, "Unknown CalculationValue #{value}"
300
+ end
301
+ end
302
+ end
303
+
304
+ private_constant :CalculationValue
305
+
306
+ # The {CalculationOperator} Protofier.
307
+ module CalculationOperator
308
+ module_function
309
+
310
+ def to_proto(operator)
311
+ case operator
312
+ when '+'
313
+ :PLUS
314
+ when '-'
315
+ :MINUS
316
+ when '*'
317
+ :TIMES
318
+ when '/'
319
+ :DIVIDE
320
+ else
321
+ raise Sass::ScriptError, "Unknown CalculationOperator #{separator.inspect}"
322
+ end
323
+ end
324
+
325
+ def from_proto(operator)
326
+ case operator
327
+ when :PLUS
328
+ '+'
329
+ when :MINUS
330
+ '-'
331
+ when :TIMES
332
+ '*'
333
+ when :DIVIDE
334
+ '/'
335
+ else
336
+ raise Sass::ScriptError, "Unknown CalculationOperator #{separator}"
337
+ end
338
+ end
339
+ end
340
+
341
+ private_constant :CalculationOperator
342
+
343
+ # The {ListSeparator} Protofier.
344
+ module ListSeparator
345
+ module_function
346
+
347
+ def to_proto(separator)
348
+ case separator
349
+ when ','
350
+ :COMMA
351
+ when ' '
352
+ :SPACE
353
+ when '/'
354
+ :SLASH
355
+ when nil
356
+ :UNDECIDED
357
+ else
358
+ raise Sass::ScriptError, "Unknown ListSeparator #{separator.inspect}"
359
+ end
360
+ end
361
+
362
+ def from_proto(separator)
363
+ case separator
364
+ when :COMMA
365
+ ','
366
+ when :SPACE
367
+ ' '
368
+ when :SLASH
369
+ '/'
370
+ when :UNDECIDED
371
+ nil
372
+ else
373
+ raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
374
+ end
375
+ end
376
+ end
377
+
378
+ private_constant :ListSeparator
379
+ end
380
+
381
+ private_constant :Protofier
382
+ end
383
+ end
384
+ end