@@ -25,37 +25,15 @@ def to_proto(obj)
2525 number : Number . to_proto ( obj )
2626 )
2727 when Sass ::Value ::Color
28- if obj . instance_eval { !defined? ( @hue ) }
29- EmbeddedProtocol ::Value . new (
30- color : EmbeddedProtocol ::Value ::Color . new (
31- channel1 : obj . red ,
32- channel2 : obj . green ,
33- channel3 : obj . blue ,
34- alpha : obj . alpha . to_f ,
35- space : 'rgb'
36- )
37- )
38- elsif obj . instance_eval { !defined? ( @saturation ) }
39- EmbeddedProtocol ::Value . new (
40- color : EmbeddedProtocol ::Value ::Color . new (
41- channel1 : obj . hue . to_f ,
42- channel2 : obj . whiteness . to_f ,
43- channel3 : obj . blackness . to_f ,
44- alpha : obj . alpha . to_f ,
45- space : 'hwb'
46- )
47- )
48- else
49- EmbeddedProtocol ::Value . new (
50- color : EmbeddedProtocol ::Value ::Color . new (
51- channel1 : obj . hue . to_f ,
52- channel2 : obj . saturation . to_f ,
53- channel3 : obj . lightness . to_f ,
54- alpha : obj . alpha . to_f ,
55- space : 'hsl'
56- )
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
5735 )
58- end
36+ )
5937 when Sass ::Value ::ArgumentList
6038 EmbeddedProtocol ::Value . new (
6139 argument_list : EmbeddedProtocol ::Value ::ArgumentList . new (
@@ -134,31 +112,14 @@ def from_proto(proto)
134112 when :number
135113 Number . from_proto ( obj )
136114 when :color
137- case obj . space
138- when 'rgb'
139- Sass ::Value ::Color . new (
140- red : obj . channel1 ,
141- green : obj . channel2 ,
142- blue : obj . channel3 ,
143- alpha : obj . alpha
144- )
145- when 'hsl'
146- Sass ::Value ::Color . new (
147- hue : obj . channel1 ,
148- saturation : obj . channel2 ,
149- lightness : obj . channel3 ,
150- alpha : obj . alpha
151- )
152- when 'hwb'
153- Sass ::Value ::Color . new (
154- hue : obj . channel1 ,
155- whiteness : obj . channel2 ,
156- blackness : obj . channel3 ,
157- alpha : obj . alpha
158- )
159- else
160- raise NotImplementedError , 'CSS Color Level 4 will be supported in a future release'
161- end
115+ Sass ::Value ::Color . send (
116+ :_for_space_name ,
117+ obj . space ,
118+ obj . channel1 ,
119+ obj . channel2 ,
120+ obj . channel3 ,
121+ obj . alpha
122+ )
162123 when :argument_list
163124 Sass ::Value ::ArgumentList . new (
164125 obj . contents . map do |element |
0 commit comments