sass-embedded 1.74.1-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +48 -0
  4. data/exe/sass +21 -0
  5. data/ext/sass/cli.rb +12 -0
  6. data/ext/sass/dart-sass/sass.bat +7 -0
  7. data/ext/sass/dart-sass/src/LICENSE +1687 -0
  8. data/ext/sass/dart-sass/src/dart.exe +0 -0
  9. data/ext/sass/dart-sass/src/sass.snapshot +0 -0
  10. data/ext/sass/embedded_sass_pb.rb +63 -0
  11. data/lib/sass/calculation_value/calculation_operation.rb +49 -0
  12. data/lib/sass/calculation_value.rb +22 -0
  13. data/lib/sass/canonicalize_context.rb +21 -0
  14. data/lib/sass/compile_result.rb +24 -0
  15. data/lib/sass/compiler/channel.rb +68 -0
  16. data/lib/sass/compiler/connection.rb +92 -0
  17. data/lib/sass/compiler/dispatcher.rb +115 -0
  18. data/lib/sass/compiler/host/function_registry.rb +87 -0
  19. data/lib/sass/compiler/host/importer_registry.rb +137 -0
  20. data/lib/sass/compiler/host/logger_registry.rb +55 -0
  21. data/lib/sass/compiler/host/protofier.rb +390 -0
  22. data/lib/sass/compiler/host/structifier.rb +37 -0
  23. data/lib/sass/compiler/host.rb +226 -0
  24. data/lib/sass/compiler/varint.rb +39 -0
  25. data/lib/sass/compiler.rb +212 -0
  26. data/lib/sass/elf.rb +276 -0
  27. data/lib/sass/embedded/version.rb +7 -0
  28. data/lib/sass/embedded.rb +107 -0
  29. data/lib/sass/embedded_protocol.rb +10 -0
  30. data/lib/sass/exception.rb +69 -0
  31. data/lib/sass/fork_tracker.rb +51 -0
  32. data/lib/sass/logger/silent.rb +28 -0
  33. data/lib/sass/logger/source_location.rb +22 -0
  34. data/lib/sass/logger/source_span.rb +28 -0
  35. data/lib/sass/node_package_importer.rb +17 -0
  36. data/lib/sass/serializer.rb +36 -0
  37. data/lib/sass/value/argument_list.rb +37 -0
  38. data/lib/sass/value/boolean.rb +52 -0
  39. data/lib/sass/value/calculation.rb +90 -0
  40. data/lib/sass/value/color.rb +253 -0
  41. data/lib/sass/value/function.rb +51 -0
  42. data/lib/sass/value/fuzzy_math.rb +80 -0
  43. data/lib/sass/value/list.rb +79 -0
  44. data/lib/sass/value/map.rb +71 -0
  45. data/lib/sass/value/mixin.rb +36 -0
  46. data/lib/sass/value/null.rb +48 -0
  47. data/lib/sass/value/number/unit.rb +186 -0
  48. data/lib/sass/value/number.rb +366 -0
  49. data/lib/sass/value/string.rb +61 -0
  50. data/lib/sass/value.rb +136 -0
  51. data/lib/sass-embedded.rb +4 -0
  52. metadata +120 -0
@@ -0,0 +1,226 @@
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/protofier'
7
+ require_relative 'host/structifier'
8
+
9
+ module Sass
10
+ class Compiler
11
+ # The {Host} class.
12
+ #
13
+ # It communicates with {Dispatcher} and handles the host logic.
14
+ class Host
15
+ def initialize(channel)
16
+ @channel = channel
17
+ end
18
+
19
+ def compile_request(path:,
20
+ source:,
21
+ importer:,
22
+ load_paths:,
23
+ syntax:,
24
+ url:,
25
+ charset:,
26
+ source_map:,
27
+ source_map_include_sources:,
28
+ style:,
29
+ functions:,
30
+ importers:,
31
+ alert_ascii:,
32
+ alert_color:,
33
+ fatal_deprecations:,
34
+ future_deprecations:,
35
+ logger:,
36
+ quiet_deps:,
37
+ silence_deprecations:,
38
+ verbose:)
39
+ alert_color = Exception.respond_to?(:to_tty?) && Exception.to_tty? if alert_color.nil?
40
+
41
+ @function_registry = FunctionRegistry.new(functions, alert_color:)
42
+ @importer_registry = ImporterRegistry.new(importers, load_paths, alert_color:)
43
+ @logger_registry = LoggerRegistry.new(logger)
44
+
45
+ compile_request = EmbeddedProtocol::InboundMessage::CompileRequest.new(
46
+ string: unless source.nil?
47
+ EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
48
+ source: source.to_str,
49
+ url: url&.to_s,
50
+ syntax: @importer_registry.syntax_to_proto(syntax),
51
+ importer: (@importer_registry.register(importer) unless importer.nil?)
52
+ )
53
+ end,
54
+ path: (File.absolute_path(path) unless path.nil?),
55
+ style: case style&.to_sym
56
+ when :expanded
57
+ EmbeddedProtocol::OutputStyle::EXPANDED
58
+ when :compressed
59
+ EmbeddedProtocol::OutputStyle::COMPRESSED
60
+ else
61
+ raise ArgumentError, 'style must be one of :expanded, :compressed'
62
+ end,
63
+ charset:,
64
+ source_map:,
65
+ source_map_include_sources:,
66
+ importers: @importer_registry.importers,
67
+ global_functions: @function_registry.global_functions,
68
+ alert_ascii:,
69
+ alert_color:,
70
+ fatal_deprecation: fatal_deprecations,
71
+ future_deprecation: future_deprecations,
72
+ quiet_deps:,
73
+ silent: logger == Logger.silent,
74
+ silence_deprecation: silence_deprecations,
75
+ verbose:
76
+ )
77
+
78
+ compile_response = await do
79
+ send_message(compile_request:)
80
+ end
81
+
82
+ oneof = compile_response.result
83
+ result = compile_response.public_send(oneof)
84
+ case oneof
85
+ when :failure
86
+ raise CompileError.new(
87
+ result.message,
88
+ result.formatted == '' ? nil : result.formatted,
89
+ result.stack_trace == '' ? nil : result.stack_trace,
90
+ result.span.nil? ? nil : Logger::SourceSpan.new(result.span),
91
+ compile_response.loaded_urls.to_a
92
+ )
93
+ when :success
94
+ CompileResult.new(
95
+ result.css,
96
+ result.source_map == '' ? nil : result.source_map,
97
+ compile_response.loaded_urls.to_a
98
+ )
99
+ else
100
+ raise ArgumentError, "Unknown CompileResponse.result #{result}"
101
+ end
102
+ end
103
+
104
+ def version_request
105
+ version_response = await0 do
106
+ send_message0(version_request: EmbeddedProtocol::InboundMessage::VersionRequest.new(
107
+ id:
108
+ ))
109
+ end
110
+
111
+ info = [
112
+ version_response.implementation_name,
113
+ version_response.implementation_version,
114
+ '(Sass Compiler)'
115
+ ]
116
+
117
+ case version_response.implementation_name
118
+ when 'dart-sass'
119
+ info << '[Dart]'
120
+ end
121
+
122
+ info
123
+ end
124
+
125
+ def compile_response(message)
126
+ @result = message
127
+ @queue.close
128
+ end
129
+
130
+ def version_response(message)
131
+ @result = message
132
+ @queue.close
133
+ end
134
+
135
+ def error(message)
136
+ case message
137
+ when EmbeddedProtocol::ProtocolError
138
+ raise Errno::EPROTO, message.message
139
+ else
140
+ @error ||= message
141
+ @queue.close
142
+ end
143
+ end
144
+
145
+ def log_event(message)
146
+ @logger_registry.log(message)
147
+ end
148
+
149
+ def canonicalize_request(message)
150
+ send_message(canonicalize_response: @importer_registry.canonicalize(message))
151
+ end
152
+
153
+ def import_request(message)
154
+ send_message(import_response: @importer_registry.import(message))
155
+ end
156
+
157
+ def file_import_request(message)
158
+ send_message(file_import_response: @importer_registry.file_import(message))
159
+ end
160
+
161
+ def function_call_request(message)
162
+ send_message(function_call_response: @function_registry.function_call(message))
163
+ end
164
+
165
+ def receive_proto(proto)
166
+ @queue.push(proto)
167
+ end
168
+
169
+ private
170
+
171
+ def await0
172
+ listen do
173
+ yield
174
+
175
+ @queue.pop
176
+ end
177
+ end
178
+
179
+ def await
180
+ listen do
181
+ yield
182
+
183
+ while (proto = @queue.pop)
184
+ outbound_message = EmbeddedProtocol::OutboundMessage.decode(proto)
185
+ oneof = outbound_message.message
186
+ message = outbound_message.public_send(oneof)
187
+ public_send(oneof, message)
188
+ end
189
+ rescue Exception => e # rubocop:disable Lint/RescueException
190
+ @stream.error(e)
191
+ raise
192
+ end
193
+ end
194
+
195
+ def listen
196
+ @queue = Queue.new
197
+ @stream = @channel.stream(self)
198
+
199
+ yield
200
+
201
+ raise @error if @error
202
+
203
+ @result
204
+ ensure
205
+ @stream&.close
206
+ @queue&.close
207
+ end
208
+
209
+ def id
210
+ @stream.id
211
+ end
212
+
213
+ def send_message0(...)
214
+ inbound_message = EmbeddedProtocol::InboundMessage.new(...)
215
+ @stream.send_proto(0, EmbeddedProtocol::InboundMessage.encode(inbound_message))
216
+ end
217
+
218
+ def send_message(...)
219
+ inbound_message = EmbeddedProtocol::InboundMessage.new(...)
220
+ @stream.send_proto(id, EmbeddedProtocol::InboundMessage.encode(inbound_message))
221
+ end
222
+ end
223
+
224
+ private_constant :Host
225
+ end
226
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Compiler
5
+ # The {Varint} module.
6
+ #
7
+ # It reads and writes varints.
8
+ module Varint
9
+ module_function
10
+
11
+ def length(value)
12
+ return 1 if value < 128
13
+
14
+ (value.bit_length + 6) / 7
15
+ end
16
+
17
+ def read(readable)
18
+ value = bits = 0
19
+ loop do
20
+ byte = readable.readbyte
21
+ value |= (byte & 0x7f) << bits
22
+ bits += 7
23
+ break if byte < 0x80
24
+ end
25
+ value
26
+ end
27
+
28
+ def write(writeable, value)
29
+ until value < 0x80
30
+ writeable << ((value & 0x7f) | 0x80)
31
+ value >>= 7
32
+ end
33
+ writeable << value
34
+ end
35
+ end
36
+
37
+ private_constant :Varint
38
+ end
39
+ end
@@ -0,0 +1,212 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'canonicalize_context'
4
+ require_relative 'compile_result'
5
+ require_relative 'compiler/channel'
6
+ require_relative 'compiler/connection'
7
+ require_relative 'compiler/dispatcher'
8
+ require_relative 'compiler/host'
9
+ require_relative 'compiler/varint'
10
+ require_relative 'embedded/version'
11
+ require_relative 'embedded_protocol'
12
+ require_relative 'exception'
13
+ require_relative 'fork_tracker'
14
+ require_relative 'logger/silent'
15
+ require_relative 'logger/source_location'
16
+ require_relative 'logger/source_span'
17
+ require_relative 'node_package_importer'
18
+ require_relative 'serializer'
19
+ require_relative 'value'
20
+
21
+ module Sass
22
+ # A synchronous {Compiler}.
23
+ # Each compiler instance exposes the {#compile} and {#compile_string} methods within the lifespan of the compiler.
24
+ #
25
+ # @example
26
+ # sass = Sass::Compiler.new
27
+ # result = sass.compile_string('h1 { font-size: 40px; }')
28
+ # result = sass.compile('style.scss')
29
+ # sass.close
30
+ # @see https://sass-lang.com/documentation/js-api/classes/compiler/
31
+ class Compiler
32
+ def initialize
33
+ @channel = Channel.new(Dispatcher)
34
+ end
35
+
36
+ # Compiles the Sass file at +path+ to CSS.
37
+ # @param path [String]
38
+ # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
39
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
40
+ # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
41
+ # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
42
+ # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
43
+ # @param source_map [Boolean] Whether or not Sass should generate a source map.
44
+ # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
45
+ # @param style [Symbol] The OutputStyle of the compiled CSS.
46
+ # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
47
+ # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
48
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
49
+ # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
50
+ # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
51
+ # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
52
+ # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
53
+ # not to use colors depending on whether the user is using an interactive terminal.
54
+ # @param fatal_deprecations [Array<String>] A set of deprecations to treat as fatal.
55
+ # @param future_deprecations [Array<String>] A set of future deprecations to opt into early.
56
+ # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
57
+ # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
58
+ # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
59
+ # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
60
+ # @param silence_deprecations [Array<String>] A set of active deprecations to ignore.
61
+ # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
62
+ # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
63
+ # deprecation warning it encounters.
64
+ # @return [CompileResult]
65
+ # @raise [ArgumentError, CompileError]
66
+ # @see https://sass-lang.com/documentation/js-api/functions/compile/
67
+ def compile(path,
68
+ load_paths: [],
69
+
70
+ charset: true,
71
+ source_map: false,
72
+ source_map_include_sources: false,
73
+ style: :expanded,
74
+
75
+ functions: {},
76
+ importers: [],
77
+
78
+ alert_ascii: false,
79
+ alert_color: nil,
80
+ fatal_deprecations: [],
81
+ future_deprecations: [],
82
+ logger: nil,
83
+ quiet_deps: false,
84
+ silence_deprecations: [],
85
+ verbose: false)
86
+ raise ArgumentError, 'path must be set' if path.nil?
87
+
88
+ Host.new(@channel).compile_request(
89
+ path:,
90
+ source: nil,
91
+ importer: nil,
92
+ load_paths:,
93
+ syntax: nil,
94
+ url: nil,
95
+ charset:,
96
+ source_map:,
97
+ source_map_include_sources:,
98
+ style:,
99
+ functions:,
100
+ importers:,
101
+ alert_color:,
102
+ alert_ascii:,
103
+ fatal_deprecations:,
104
+ future_deprecations:,
105
+ logger:,
106
+ quiet_deps:,
107
+ silence_deprecations:,
108
+ verbose:
109
+ )
110
+ end
111
+
112
+ # Compiles a stylesheet whose contents is +source+ to CSS.
113
+ # @param source [String]
114
+ # @param importer [Object] The importer to use to handle loads that are relative to the entrypoint stylesheet.
115
+ # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
116
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
117
+ # @param syntax [Symbol] The Syntax to use to parse the entrypoint stylesheet.
118
+ # @param url [String] The canonical URL of the entrypoint stylesheet. If this is passed along with +importer+, it's
119
+ # used to resolve relative loads in the entrypoint stylesheet.
120
+ # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
121
+ # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
122
+ # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
123
+ # @param source_map [Boolean] Whether or not Sass should generate a source map.
124
+ # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
125
+ # @param style [Symbol] The OutputStyle of the compiled CSS.
126
+ # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
127
+ # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
128
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
129
+ # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
130
+ # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
131
+ # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
132
+ # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
133
+ # not to use colors depending on whether the user is using an interactive terminal.
134
+ # @param fatal_deprecations [Array<String>] A set of deprecations to treat as fatal.
135
+ # @param future_deprecations [Array<String>] A set of future deprecations to opt into early.
136
+ # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
137
+ # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
138
+ # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
139
+ # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
140
+ # @param silence_deprecations [Array<String>] A set of active deprecations to ignore.
141
+ # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
142
+ # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
143
+ # deprecation warning it encounters.
144
+ # @return [CompileResult]
145
+ # @raise [ArgumentError, CompileError]
146
+ # @see https://sass-lang.com/documentation/js-api/functions/compilestring/
147
+ def compile_string(source,
148
+ importer: nil,
149
+ load_paths: [],
150
+ syntax: :scss,
151
+ url: nil,
152
+
153
+ charset: true,
154
+ source_map: false,
155
+ source_map_include_sources: false,
156
+ style: :expanded,
157
+
158
+ functions: {},
159
+ importers: [],
160
+
161
+ alert_ascii: false,
162
+ alert_color: nil,
163
+ fatal_deprecations: [],
164
+ future_deprecations: [],
165
+ logger: nil,
166
+ quiet_deps: false,
167
+ silence_deprecations: [],
168
+ verbose: false)
169
+ raise ArgumentError, 'source must be set' if source.nil?
170
+
171
+ Host.new(@channel).compile_request(
172
+ path: nil,
173
+ source:,
174
+ importer:,
175
+ load_paths:,
176
+ syntax:,
177
+ url:,
178
+ charset:,
179
+ source_map:,
180
+ source_map_include_sources:,
181
+ style:,
182
+ functions:,
183
+ importers:,
184
+ alert_color:,
185
+ alert_ascii:,
186
+ fatal_deprecations:,
187
+ future_deprecations:,
188
+ logger:,
189
+ quiet_deps:,
190
+ silence_deprecations:,
191
+ verbose:
192
+ )
193
+ end
194
+
195
+ # @return [String] Information about the Sass implementation.
196
+ # @see https://sass-lang.com/documentation/js-api/variables/info/
197
+ def info
198
+ @info ||= [
199
+ ['sass-embedded', Embedded::VERSION, '(Embedded Host)', '[Ruby]'].join("\t"),
200
+ Host.new(@channel).version_request.join("\t")
201
+ ].join("\n").freeze
202
+ end
203
+
204
+ def close
205
+ @channel.close
206
+ end
207
+
208
+ def closed?
209
+ @channel.closed?
210
+ end
211
+ end
212
+ end