sass-embedded 1.77.5 → 1.100.0

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +18 -17
  3. data/README.md +1 -1
  4. data/exe/sass +2 -10
  5. data/ext/sass/Rakefile +162 -385
  6. data/ext/sass/file_utils.rb +75 -0
  7. data/ext/sass/package.json +1 -1
  8. data/ext/sass/platform.rb +44 -0
  9. data/ext/sass/sass-1.100.0.tgz +0 -0
  10. data/ext/sass/sass_config.rb +183 -0
  11. data/ext/sass/utils.rb +39 -0
  12. data/lib/sass/compiler/channel.rb +6 -4
  13. data/lib/sass/compiler/connection.rb +17 -21
  14. data/lib/sass/compiler/dispatcher.rb +27 -1
  15. data/lib/sass/compiler/host/function_registry.rb +6 -6
  16. data/lib/sass/compiler/host/importer_registry.rb +17 -11
  17. data/lib/sass/compiler/host/logger_registry.rb +17 -20
  18. data/lib/sass/compiler/host/protofier.rb +59 -73
  19. data/lib/sass/compiler/host/struct.rb +36 -0
  20. data/lib/sass/compiler/host.rb +2 -2
  21. data/lib/sass/compiler.rb +4 -3
  22. data/lib/sass/elf.rb +282 -172
  23. data/lib/sass/embedded/version.rb +1 -1
  24. data/lib/sass/embedded.rb +2 -41
  25. data/lib/sass/embedded_protocol.rb +1 -1
  26. data/{ext → lib}/sass/embedded_sass_pb.rb +3 -5
  27. data/lib/sass/exception.rb +7 -2
  28. data/lib/sass/fork_tracker.rb +36 -28
  29. data/lib/sass/gem_package_importer.rb +19 -0
  30. data/lib/sass/serializer.rb +5 -11
  31. data/lib/sass/value/argument_list.rb +0 -8
  32. data/lib/sass/value/color/channel.rb +79 -0
  33. data/lib/sass/value/color/conversions.rb +473 -0
  34. data/lib/sass/value/color/gamut_map_method/clip.rb +45 -0
  35. data/lib/sass/value/color/gamut_map_method/local_minde.rb +94 -0
  36. data/lib/sass/value/color/gamut_map_method.rb +45 -0
  37. data/lib/sass/value/color/interpolation_method.rb +51 -0
  38. data/lib/sass/value/color/space/a98_rgb.rb +57 -0
  39. data/lib/sass/value/color/space/display_p3.rb +72 -0
  40. data/lib/sass/value/color/space/display_p3_linear.rb +72 -0
  41. data/lib/sass/value/color/space/hsl.rb +65 -0
  42. data/lib/sass/value/color/space/hwb.rb +70 -0
  43. data/lib/sass/value/color/space/lab.rb +77 -0
  44. data/lib/sass/value/color/space/lch.rb +53 -0
  45. data/lib/sass/value/color/space/lms.rb +129 -0
  46. data/lib/sass/value/color/space/oklab.rb +66 -0
  47. data/lib/sass/value/color/space/oklch.rb +54 -0
  48. data/lib/sass/value/color/space/prophoto_rgb.rb +59 -0
  49. data/lib/sass/value/color/space/rec2020.rb +69 -0
  50. data/lib/sass/value/color/space/rgb.rb +52 -0
  51. data/lib/sass/value/color/space/srgb.rb +140 -0
  52. data/lib/sass/value/color/space/srgb_linear.rb +72 -0
  53. data/lib/sass/value/color/space/utils.rb +86 -0
  54. data/lib/sass/value/color/space/xyz_d50.rb +100 -0
  55. data/lib/sass/value/color/space/xyz_d65.rb +57 -0
  56. data/lib/sass/value/color/space.rb +201 -0
  57. data/lib/sass/value/color.rb +539 -162
  58. data/lib/sass/value/function.rb +9 -6
  59. data/lib/sass/value/fuzzy_math.rb +34 -30
  60. data/lib/sass/value/mixin.rb +5 -2
  61. data/lib/sass/value/null.rb +1 -1
  62. data/lib/sass/value/number/unit.rb +5 -4
  63. data/lib/sass/value/number.rb +15 -17
  64. data/lib/sass/value/string.rb +1 -1
  65. data/lib/sass/value.rb +1 -1
  66. metadata +42 -21
  67. data/ext/sass/expand-archive.ps1 +0 -1
  68. data/lib/sass/compiler/host/structifier.rb +0 -37
@@ -25,43 +25,31 @@ module Sass
25
25
  number: Number.to_proto(obj)
26
26
  )
27
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
- )
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
36
35
  )
37
- elsif obj.instance_eval { !defined?(@saturation) }
36
+ )
37
+ when Sass::Value::ArgumentList
38
+ if obj.instance_variable_get(:@compile_context) == @function_registry.compile_context
38
39
  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
40
+ argument_list: EmbeddedProtocol::Value::ArgumentList.new(
41
+ id: obj.instance_variable_get(:@id)
44
42
  )
45
43
  )
46
44
  else
47
45
  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
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)
53
50
  )
54
51
  )
55
52
  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
53
  when Sass::Value::List
66
54
  EmbeddedProtocol::Value.new(
67
55
  list: EmbeddedProtocol::Value::List.new(
@@ -82,10 +70,10 @@ module Sass
82
70
  )
83
71
  )
84
72
  when Sass::Value::Function
85
- if obj.instance_eval { @id }
73
+ if obj.instance_variable_defined?(:@id)
86
74
  EmbeddedProtocol::Value.new(
87
75
  compiler_function: EmbeddedProtocol::Value::CompilerFunction.new(
88
- id: obj.instance_eval { @id }
76
+ id: assert_compiler_value(obj).instance_variable_get(:@id)
89
77
  )
90
78
  )
91
79
  else
@@ -99,7 +87,7 @@ module Sass
99
87
  when Sass::Value::Mixin
100
88
  EmbeddedProtocol::Value.new(
101
89
  compiler_mixin: EmbeddedProtocol::Value::CompilerMixin.new(
102
- id: obj.instance_eval { @id }
90
+ id: assert_compiler_value(obj).instance_variable_get(:@id)
103
91
  )
104
92
  )
105
93
  when Sass::Value::Calculation
@@ -130,40 +118,28 @@ module Sass
130
118
  )
131
119
  when :number
132
120
  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
121
+ when :color
122
+ Sass::Value::Color.send(
123
+ :for_space,
124
+ obj.space,
125
+ obj.has_channel1? ? obj.channel1 : nil,
126
+ obj.has_channel2? ? obj.channel2 : nil,
127
+ obj.has_channel3? ? obj.channel3 : nil,
128
+ obj.has_alpha? ? obj.alpha : nil
153
129
  )
154
130
  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
131
+ compiler_value(
132
+ Sass::Value::ArgumentList.new(
133
+ obj.contents.map do |element|
134
+ from_proto(element)
135
+ end,
136
+ obj.keywords.to_enum.with_object({}) do |(key, value), hash|
137
+ hash[key.to_sym] = from_proto(value)
138
+ end,
139
+ ListSeparator.from_proto(obj.separator)
140
+ ),
141
+ obj.id
142
+ )
167
143
  when :list
168
144
  Sass::Value::List.new(
169
145
  obj.contents.map do |element|
@@ -174,22 +150,16 @@ module Sass
174
150
  )
175
151
  when :map
176
152
  Sass::Value::Map.new(
177
- obj.entries.to_h do |entry|
178
- [from_proto(entry.key), from_proto(entry.value)]
153
+ obj.entries.to_enum.with_object({}) do |entry, hash|
154
+ hash[from_proto(entry.key)] = from_proto(entry.value)
179
155
  end
180
156
  )
181
157
  when :compiler_function
182
- Sass::Value::Function.new(nil).instance_eval do
183
- @id = obj.id
184
- self
185
- end
158
+ compiler_value(Sass::Value::Function.allocate, obj.id)
186
159
  when :host_function
187
160
  raise Sass::ScriptError, 'The compiler may not send Value.host_function to host'
188
161
  when :compiler_mixin
189
- Sass::Value::Mixin.send(:new).instance_eval do
190
- @id = obj.id
191
- self
192
- end
162
+ compiler_value(Sass::Value::Mixin.allocate, obj.id)
193
163
  when :calculation
194
164
  Calculation.from_proto(obj)
195
165
  when :singleton
@@ -208,6 +178,22 @@ module Sass
208
178
  end
209
179
  end
210
180
 
181
+ private
182
+
183
+ def assert_compiler_value(value)
184
+ unless value.instance_variable_get(:@compile_context) == @function_registry.compile_context
185
+ raise Sass::ScriptError, "Value #{value} does not belong to this compilation"
186
+ end
187
+
188
+ value
189
+ end
190
+
191
+ def compiler_value(value, id)
192
+ value.instance_variable_set(:@compile_context, @function_registry.compile_context)
193
+ value.instance_variable_set(:@id, id)
194
+ value
195
+ end
196
+
211
197
  # The {Number} Protofier.
212
198
  module Number
213
199
  module_function
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Compiler
5
+ class Host
6
+ # The {Struct} class.
7
+ #
8
+ # It creates {::Struct}-like objects from {::Hash}.
9
+ class Struct
10
+ def initialize(hash, attrs: nil, methods: nil)
11
+ @hash = hash
12
+ @attrs = attrs
13
+ @methods = methods
14
+ end
15
+
16
+ def method_missing(symbol, ...)
17
+ return super unless @hash.key?(symbol)
18
+
19
+ if @attrs&.include?(symbol)
20
+ @hash.send(:[], symbol, ...)
21
+ elsif @methods&.include?(symbol)
22
+ @hash[symbol].call(...)
23
+ else
24
+ super
25
+ end
26
+ end
27
+
28
+ def respond_to_missing?(symbol, _include_all)
29
+ @hash.key?(symbol) && (@attrs&.include?(symbol) || @methods&.include?(symbol))
30
+ end
31
+ end
32
+
33
+ private_constant :Struct
34
+ end
35
+ end
36
+ end
@@ -4,7 +4,7 @@ require_relative 'host/function_registry'
4
4
  require_relative 'host/importer_registry'
5
5
  require_relative 'host/logger_registry'
6
6
  require_relative 'host/protofier'
7
- require_relative 'host/structifier'
7
+ require_relative 'host/struct'
8
8
 
9
9
  module Sass
10
10
  class Compiler
@@ -116,7 +116,7 @@ module Sass
116
116
 
117
117
  case version_response.implementation_name
118
118
  when 'dart-sass'
119
- info << '[Dart]'
119
+ info << (File.basename(CLI::COMMAND.first, '.exe') == 'node' ? '[JavaScript]' : '[Dart]')
120
120
  end
121
121
 
122
122
  info
data/lib/sass/compiler.rb CHANGED
@@ -11,6 +11,7 @@ require_relative 'embedded/version'
11
11
  require_relative 'embedded_protocol'
12
12
  require_relative 'exception'
13
13
  require_relative 'fork_tracker'
14
+ require_relative 'gem_package_importer'
14
15
  require_relative 'logger/silent'
15
16
  require_relative 'logger/source_location'
16
17
  require_relative 'logger/source_span'
@@ -30,7 +31,7 @@ module Sass
30
31
  # @see https://sass-lang.com/documentation/js-api/classes/compiler/
31
32
  class Compiler
32
33
  def initialize
33
- @channel = Channel.new(Dispatcher)
34
+ @channel = Channel.new
34
35
  end
35
36
 
36
37
  # Compiles the Sass file at +path+ to CSS.
@@ -62,7 +63,7 @@ module Sass
62
63
  # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
63
64
  # deprecation warning it encounters.
64
65
  # @return [CompileResult]
65
- # @raise [ArgumentError, CompileError]
66
+ # @raise [ArgumentError, CompileError, IOError]
66
67
  # @see https://sass-lang.com/documentation/js-api/functions/compile/
67
68
  def compile(path,
68
69
  load_paths: [],
@@ -142,7 +143,7 @@ module Sass
142
143
  # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
143
144
  # deprecation warning it encounters.
144
145
  # @return [CompileResult]
145
- # @raise [ArgumentError, CompileError]
146
+ # @raise [ArgumentError, CompileError, IOError]
146
147
  # @see https://sass-lang.com/documentation/js-api/functions/compilestring/
147
148
  def compile_string(source,
148
149
  importer: nil,