sass-embedded 1.79.3-x86-mingw-ucrt → 1.79.4-x86-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/sass +1 -9
- data/ext/sass/dart-sass/src/sass.snapshot +0 -0
- data/lib/sass/compiler/connection.rb +1 -9
- data/lib/sass/compiler/host/protofier.rb +16 -55
- data/lib/sass/elf.rb +4 -4
- data/lib/sass/embedded/version.rb +1 -1
- data/lib/sass/value/color/channel.rb +79 -0
- data/lib/sass/value/color/conversions.rb +464 -0
- data/lib/sass/value/color/gamut_map_method/clip.rb +45 -0
- data/lib/sass/value/color/gamut_map_method/local_minde.rb +94 -0
- data/lib/sass/value/color/gamut_map_method.rb +45 -0
- data/lib/sass/value/color/interpolation_method.rb +51 -0
- data/lib/sass/value/color/space/a98_rgb.rb +57 -0
- data/lib/sass/value/color/space/display_p3.rb +57 -0
- data/lib/sass/value/color/space/hsl.rb +65 -0
- data/lib/sass/value/color/space/hwb.rb +70 -0
- data/lib/sass/value/color/space/lab.rb +77 -0
- data/lib/sass/value/color/space/lch.rb +53 -0
- data/lib/sass/value/color/space/lms.rb +129 -0
- data/lib/sass/value/color/space/oklab.rb +66 -0
- data/lib/sass/value/color/space/oklch.rb +54 -0
- data/lib/sass/value/color/space/prophoto_rgb.rb +59 -0
- data/lib/sass/value/color/space/rec2020.rb +69 -0
- data/lib/sass/value/color/space/rgb.rb +52 -0
- data/lib/sass/value/color/space/srgb.rb +141 -0
- data/lib/sass/value/color/space/srgb_linear.rb +72 -0
- data/lib/sass/value/color/space/utils.rb +86 -0
- data/lib/sass/value/color/space/xyz_d50.rb +100 -0
- data/lib/sass/value/color/space/xyz_d65.rb +57 -0
- data/lib/sass/value/color/space.rb +198 -0
- data/lib/sass/value/color.rb +537 -162
- data/lib/sass/value/fuzzy_math.rb +30 -3
- data/lib/sass/value/string.rb +1 -1
- metadata +29 -5
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
class Color
|
6
|
+
module Space
|
7
|
+
# @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/space/prophoto_rgb.dart
|
8
|
+
class ProphotoRgb
|
9
|
+
include Space
|
10
|
+
|
11
|
+
def bounded?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super('prophoto-rgb', Utils::RGB_CHANNELS)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_linear(channel)
|
20
|
+
abs = channel.abs
|
21
|
+
abs <= 16 / 512.0 ? channel / 16.0 : FuzzyMath.sign(channel) * (abs**1.8)
|
22
|
+
end
|
23
|
+
|
24
|
+
def from_linear(channel)
|
25
|
+
abs = channel.abs
|
26
|
+
abs >= 1 / 512.0 ? FuzzyMath.sign(channel) * (abs**(1 / 1.8)) : 16 * channel
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def transformation_matrix(dest)
|
32
|
+
case dest
|
33
|
+
when A98_RGB
|
34
|
+
Conversions::LINEAR_PROPHOTO_RGB_TO_LINEAR_A98_RGB
|
35
|
+
when DISPLAY_P3
|
36
|
+
Conversions::LINEAR_PROPHOTO_RGB_TO_LINEAR_DISPLAY_P3
|
37
|
+
when LMS
|
38
|
+
Conversions::LINEAR_PROPHOTO_RGB_TO_LMS
|
39
|
+
when REC2020
|
40
|
+
Conversions::LINEAR_PROPHOTO_RGB_TO_LINEAR_REC2020
|
41
|
+
when RGB, SRGB, SRGB_LINEAR
|
42
|
+
Conversions::LINEAR_PROPHOTO_RGB_TO_LINEAR_SRGB
|
43
|
+
when XYZ_D50
|
44
|
+
Conversions::LINEAR_PROPHOTO_RGB_TO_XYZ_D50
|
45
|
+
when XYZ_D65
|
46
|
+
Conversions::LINEAR_PROPHOTO_RGB_TO_XYZ_D65
|
47
|
+
else
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private_constant :ProphotoRgb
|
54
|
+
|
55
|
+
PROPHOTO_RGB = ProphotoRgb.new
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
class Color
|
6
|
+
module Space
|
7
|
+
# @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/space/rec2020.dart
|
8
|
+
class Rec2020
|
9
|
+
include Space
|
10
|
+
|
11
|
+
# A constant used in the rec2020 gamma encoding/decoding functions.
|
12
|
+
ALPHA = 1.09929682680944
|
13
|
+
|
14
|
+
private_constant :ALPHA
|
15
|
+
|
16
|
+
# A constant used in the rec2020 gamma encoding/decoding functions.
|
17
|
+
BETA = 0.018053968510807
|
18
|
+
|
19
|
+
private_constant :BETA
|
20
|
+
|
21
|
+
def bounded?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
super('rec2020', Utils::RGB_CHANNELS)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_linear(channel)
|
30
|
+
abs = channel.abs
|
31
|
+
abs < BETA * 4.5 ? channel / 4.5 : FuzzyMath.sign(channel) * (((abs + ALPHA - 1) / ALPHA)**(1 / 0.45))
|
32
|
+
end
|
33
|
+
|
34
|
+
def from_linear(channel)
|
35
|
+
abs = channel.abs
|
36
|
+
abs > BETA ? FuzzyMath.sign(channel) * ((ALPHA * (abs**0.45)) - (ALPHA - 1)) : 4.5 * channel
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def transformation_matrix(dest)
|
42
|
+
case dest
|
43
|
+
when A98_RGB
|
44
|
+
Conversions::LINEAR_REC2020_TO_LINEAR_A98_RGB
|
45
|
+
when DISPLAY_P3
|
46
|
+
Conversions::LINEAR_REC2020_TO_LINEAR_DISPLAY_P3
|
47
|
+
when LMS
|
48
|
+
Conversions::LINEAR_REC2020_TO_LMS
|
49
|
+
when PROPHOTO_RGB
|
50
|
+
Conversions::LINEAR_REC2020_TO_LINEAR_PROPHOTO_RGB
|
51
|
+
when RGB, SRGB, SRGB_LINEAR
|
52
|
+
Conversions::LINEAR_REC2020_TO_LINEAR_SRGB
|
53
|
+
when XYZ_D50
|
54
|
+
Conversions::LINEAR_REC2020_TO_XYZ_D50
|
55
|
+
when XYZ_D65
|
56
|
+
Conversions::LINEAR_REC2020_TO_XYZ_D65
|
57
|
+
else
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private_constant :Rec2020
|
64
|
+
|
65
|
+
REC2020 = Rec2020.new
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
class Color
|
6
|
+
module Space
|
7
|
+
# @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/space/rgb.dart
|
8
|
+
class Rgb
|
9
|
+
include Space
|
10
|
+
|
11
|
+
def bounded?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def legacy?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
super('rgb', [
|
21
|
+
LinearChannel.new('red', 0, 255, lower_clamped: true, upper_clamped: true).freeze,
|
22
|
+
LinearChannel.new('green', 0, 255, lower_clamped: true, upper_clamped: true).freeze,
|
23
|
+
LinearChannel.new('blue', 0, 255, lower_clamped: true, upper_clamped: true).freeze
|
24
|
+
].freeze)
|
25
|
+
end
|
26
|
+
|
27
|
+
def convert(dest, red, green, blue, alpha)
|
28
|
+
SRGB.convert(
|
29
|
+
dest,
|
30
|
+
red.nil? ? nil : red / 255.0,
|
31
|
+
green.nil? ? nil : green / 255.0,
|
32
|
+
blue.nil? ? nil : blue / 255.0,
|
33
|
+
alpha
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_linear(channel)
|
38
|
+
Utils.srgb_and_display_p3_to_linear(channel / 255.0)
|
39
|
+
end
|
40
|
+
|
41
|
+
def from_linear(channel)
|
42
|
+
Utils.srgb_and_display_p3_from_linear(channel) * 255
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private_constant :Rgb
|
47
|
+
|
48
|
+
RGB = Rgb.new
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
class Color
|
6
|
+
module Space
|
7
|
+
# @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/space/srgb.dart
|
8
|
+
class Srgb
|
9
|
+
include Space
|
10
|
+
|
11
|
+
def bounded?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super('srgb', Utils::RGB_CHANNELS)
|
17
|
+
end
|
18
|
+
|
19
|
+
def convert(dest, red, green, blue, alpha,
|
20
|
+
missing_lightness: false,
|
21
|
+
missing_chroma: false,
|
22
|
+
missing_hue: false)
|
23
|
+
case dest
|
24
|
+
when HSL, HWB
|
25
|
+
red = 0 if red.nil?
|
26
|
+
green = 0 if green.nil?
|
27
|
+
blue = 0 if blue.nil?
|
28
|
+
|
29
|
+
max = [red, green, blue].max
|
30
|
+
min = [red, green, blue].min
|
31
|
+
delta = max - min
|
32
|
+
|
33
|
+
hue = if max == min
|
34
|
+
0.0
|
35
|
+
elsif max == red
|
36
|
+
(60.0 * (green - blue) / delta) + 360
|
37
|
+
elsif max == green
|
38
|
+
(60.0 * (blue - red) / delta) + 120
|
39
|
+
else # max == blue
|
40
|
+
(60.0 * (red - green) / delta) + 240
|
41
|
+
end
|
42
|
+
|
43
|
+
if dest == HSL
|
44
|
+
lightness = (min + max) / 2.0
|
45
|
+
|
46
|
+
saturation = if [0, 1].include?(lightness)
|
47
|
+
0.0
|
48
|
+
else
|
49
|
+
100.0 * (max - lightness) / [lightness, 1 - lightness].min
|
50
|
+
end
|
51
|
+
if saturation.negative?
|
52
|
+
hue += 180
|
53
|
+
saturation = saturation.abs
|
54
|
+
end
|
55
|
+
|
56
|
+
Color.send(
|
57
|
+
:for_space_internal,
|
58
|
+
dest,
|
59
|
+
missing_hue || FuzzyMath.equals(saturation, 0) ? nil : hue % 360,
|
60
|
+
missing_chroma ? nil : saturation,
|
61
|
+
missing_lightness ? nil : lightness * 100,
|
62
|
+
alpha
|
63
|
+
)
|
64
|
+
else
|
65
|
+
whiteness = min * 100
|
66
|
+
blackness = 100 - (max * 100)
|
67
|
+
|
68
|
+
Color.send(
|
69
|
+
:for_space_internal,
|
70
|
+
dest,
|
71
|
+
missing_hue || FuzzyMath.greater_than_or_equals(whiteness + blackness, 100) ? nil : hue % 360,
|
72
|
+
whiteness,
|
73
|
+
blackness,
|
74
|
+
alpha
|
75
|
+
)
|
76
|
+
end
|
77
|
+
when RGB
|
78
|
+
Color.send(
|
79
|
+
:_for_space,
|
80
|
+
dest,
|
81
|
+
red.nil? ? nil : red * 255,
|
82
|
+
green.nil? ? nil : green * 255,
|
83
|
+
blue.nil? ? nil : blue * 255,
|
84
|
+
alpha
|
85
|
+
)
|
86
|
+
when SRGB_LINEAR
|
87
|
+
Color.send(
|
88
|
+
:_for_space,
|
89
|
+
dest,
|
90
|
+
red.nil? ? nil : to_linear(red),
|
91
|
+
green.nil? ? nil : to_linear(green),
|
92
|
+
blue.nil? ? nil : to_linear(blue),
|
93
|
+
alpha
|
94
|
+
)
|
95
|
+
else
|
96
|
+
convert_linear(dest, red, green, blue, alpha,
|
97
|
+
missing_lightness:,
|
98
|
+
missing_chroma:,
|
99
|
+
missing_hue:)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def to_linear(channel)
|
104
|
+
Utils.srgb_and_display_p3_to_linear(channel)
|
105
|
+
end
|
106
|
+
|
107
|
+
def from_linear(channel)
|
108
|
+
Utils.srgb_and_display_p3_from_linear(channel)
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def transformation_matrix(dest)
|
114
|
+
case dest
|
115
|
+
when A98_RGB
|
116
|
+
Conversions::LINEAR_SRGB_TO_LINEAR_A98_RGB
|
117
|
+
when DISPLAY_P3
|
118
|
+
Conversions::LINEAR_SRGB_TO_LINEAR_DISPLAY_P3
|
119
|
+
when LMS
|
120
|
+
Conversions::LINEAR_SRGB_TO_LMS
|
121
|
+
when PROPHOTO_RGB
|
122
|
+
Conversions::LINEAR_SRGB_TO_LINEAR_PROPHOTO_RGB
|
123
|
+
when REC2020
|
124
|
+
Conversions::LINEAR_SRGB_TO_LINEAR_REC2020
|
125
|
+
when XYZ_D50
|
126
|
+
Conversions::LINEAR_SRGB_TO_XYZ_D50
|
127
|
+
when XYZ_D65
|
128
|
+
Conversions::LINEAR_SRGB_TO_XYZ_D65
|
129
|
+
else
|
130
|
+
super
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
private_constant :Srgb
|
136
|
+
|
137
|
+
SRGB = Srgb.new
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
class Color
|
6
|
+
module Space
|
7
|
+
# @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/space/srgb_linear.dart
|
8
|
+
class SrgbLinear
|
9
|
+
include Space
|
10
|
+
|
11
|
+
def bounded?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super('srgb-linear', Utils::RGB_CHANNELS)
|
17
|
+
end
|
18
|
+
|
19
|
+
def convert(dest, red, green, blue, alpha)
|
20
|
+
case dest
|
21
|
+
when HSL, HWB, RGB, SRGB
|
22
|
+
SRGB.convert(
|
23
|
+
dest,
|
24
|
+
red.nil? ? nil : Utils.srgb_and_display_p3_from_linear(red),
|
25
|
+
green.nil? ? nil : Utils.srgb_and_display_p3_from_linear(green),
|
26
|
+
blue.nil? ? nil : Utils.srgb_and_display_p3_from_linear(blue),
|
27
|
+
alpha
|
28
|
+
)
|
29
|
+
else
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_linear(channel)
|
35
|
+
channel
|
36
|
+
end
|
37
|
+
|
38
|
+
def from_linear(channel)
|
39
|
+
channel
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def transformation_matrix(dest)
|
45
|
+
case dest
|
46
|
+
when A98_RGB
|
47
|
+
Conversions::LINEAR_SRGB_TO_LINEAR_A98_RGB
|
48
|
+
when DISPLAY_P3
|
49
|
+
Conversions::LINEAR_SRGB_TO_LINEAR_DISPLAY_P3
|
50
|
+
when PROPHOTO_RGB
|
51
|
+
Conversions::LINEAR_SRGB_TO_LINEAR_PROPHOTO_RGB
|
52
|
+
when REC2020
|
53
|
+
Conversions::LINEAR_SRGB_TO_LINEAR_REC2020
|
54
|
+
when XYZ_D65
|
55
|
+
Conversions::LINEAR_SRGB_TO_XYZ_D65
|
56
|
+
when XYZ_D50
|
57
|
+
Conversions::LINEAR_SRGB_TO_XYZ_D50
|
58
|
+
when LMS
|
59
|
+
Conversions::LINEAR_SRGB_TO_LMS
|
60
|
+
else
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private_constant :SrgbLinear
|
67
|
+
|
68
|
+
SRGB_LINEAR = SrgbLinear.new
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
class Color
|
6
|
+
module Space
|
7
|
+
# @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/space/utils.dart
|
8
|
+
module Utils
|
9
|
+
module_function
|
10
|
+
|
11
|
+
# A constant used to convert Lab to/from XYZ.
|
12
|
+
LAB_KAPPA = Rational(24_389, 27) # 29^3/3^3
|
13
|
+
|
14
|
+
# A constant used to convert Lab to/from XYZ.
|
15
|
+
LAB_EPSILON = Rational(216, 24_389) # 6^3/29^3
|
16
|
+
|
17
|
+
# The hue channel shared across all polar color spaces.
|
18
|
+
HUE_CHANNEL = ColorChannel.new('hue', polar_angle: true, associated_unit: 'deg').freeze
|
19
|
+
|
20
|
+
# The color channels shared across all RGB color spaces (except the legacy RGB space).
|
21
|
+
RGB_CHANNELS = [
|
22
|
+
LinearChannel.new('red', 0, 1).freeze,
|
23
|
+
LinearChannel.new('green', 0, 1).freeze,
|
24
|
+
LinearChannel.new('blue', 0, 1).freeze
|
25
|
+
].freeze
|
26
|
+
|
27
|
+
# The color channels shared across both XYZ color spaces.
|
28
|
+
XYZ_CHANNELS = [
|
29
|
+
LinearChannel.new('x', 0, 1).freeze,
|
30
|
+
LinearChannel.new('y', 0, 1).freeze,
|
31
|
+
LinearChannel.new('z', 0, 1).freeze
|
32
|
+
].freeze
|
33
|
+
|
34
|
+
# The algorithm for converting a single `srgb` or `display-p3` channel to
|
35
|
+
# linear-light form.
|
36
|
+
# @param [Numeric]
|
37
|
+
# @return [Numeric]
|
38
|
+
def srgb_and_display_p3_to_linear(channel)
|
39
|
+
abs = channel.abs
|
40
|
+
abs < 0.04045 ? channel / 12.92 : FuzzyMath.sign(channel) * (((abs + 0.055) / 1.055)**2.4)
|
41
|
+
end
|
42
|
+
|
43
|
+
# The algorithm for converting a single `srgb` or `display-p3` channel to
|
44
|
+
# gamma-corrected form.
|
45
|
+
# @param [Numeric]
|
46
|
+
# @return [Numeric]
|
47
|
+
def srgb_and_display_p3_from_linear(channel)
|
48
|
+
abs = channel.abs
|
49
|
+
abs <= 0.0031308 ? channel * 12.92 : FuzzyMath.sign(channel) * ((1.055 * (abs**(1 / 2.4))) - 0.055)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Converts a Lab or OKLab color to LCH or OKLCH, respectively.
|
53
|
+
#
|
54
|
+
# The [missing_chroma] and [missing_hue] arguments indicate whether this came
|
55
|
+
# from a color that was missing its chroma or hue channels, respectively.
|
56
|
+
# @param dest [Space]
|
57
|
+
# @param lightness [Numeric]
|
58
|
+
# @param a [Numeric]
|
59
|
+
# @param b [Numeric]
|
60
|
+
# @param alpha [Numeric]
|
61
|
+
# @return [Color]
|
62
|
+
def lab_to_lch(dest, lightness, a, b, alpha, # rubocop:disable Naming/MethodParameterName
|
63
|
+
missing_chroma: false, missing_hue: false)
|
64
|
+
chroma = Math.sqrt(((a.nil? ? 0 : a)**2) + ((b.nil? ? 0 : b)**2))
|
65
|
+
hue = if missing_hue || FuzzyMath.equals(chroma, 0)
|
66
|
+
nil
|
67
|
+
else
|
68
|
+
Math.atan2(b.nil? ? 0 : b, a.nil? ? 0 : a) * 180 / Math::PI
|
69
|
+
end
|
70
|
+
|
71
|
+
Color.send(
|
72
|
+
:for_space_internal,
|
73
|
+
dest,
|
74
|
+
lightness,
|
75
|
+
missing_chroma ? nil : chroma,
|
76
|
+
hue.nil? || hue >= 0 ? hue : hue + 360,
|
77
|
+
alpha
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private_constant :Utils
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
class Color
|
6
|
+
module Space
|
7
|
+
# @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/space/xyz_d50.dart
|
8
|
+
class XyzD50
|
9
|
+
include Space
|
10
|
+
|
11
|
+
def bounded?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super('xyz-d50', Utils::XYZ_CHANNELS)
|
17
|
+
end
|
18
|
+
|
19
|
+
def convert(dest, x, y, z, alpha, # rubocop:disable Naming/MethodParameterName
|
20
|
+
missing_lightness: false,
|
21
|
+
missing_chroma: false,
|
22
|
+
missing_hue: false,
|
23
|
+
missing_a: false,
|
24
|
+
missing_b: false)
|
25
|
+
case dest
|
26
|
+
when LAB, LCH
|
27
|
+
f0 = _convert_component_to_lab_f((x.nil? ? 0 : x) / Conversions::D50[0])
|
28
|
+
f1 = _convert_component_to_lab_f((y.nil? ? 0 : y) / Conversions::D50[1])
|
29
|
+
f2 = _convert_component_to_lab_f((z.nil? ? 0 : z) / Conversions::D50[2])
|
30
|
+
lightness = missing_lightness ? nil : (116 * f1) - 16
|
31
|
+
a = 500 * (f0 - f1)
|
32
|
+
b = 200 * (f1 - f2)
|
33
|
+
|
34
|
+
if dest == LAB
|
35
|
+
Color.send(:_for_space,
|
36
|
+
dest,
|
37
|
+
lightness,
|
38
|
+
missing_a ? nil : a,
|
39
|
+
missing_b ? nil : b,
|
40
|
+
alpha)
|
41
|
+
else
|
42
|
+
Utils.lab_to_lch(dest, lightness, a, b, alpha, missing_chroma:, missing_hue:)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
convert_linear(dest, x, y, z, alpha,
|
46
|
+
missing_lightness:,
|
47
|
+
missing_chroma:,
|
48
|
+
missing_hue:,
|
49
|
+
missing_a:,
|
50
|
+
missing_b:)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_linear(channel)
|
55
|
+
channel
|
56
|
+
end
|
57
|
+
|
58
|
+
def from_linear(channel)
|
59
|
+
channel
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def _convert_component_to_lab_f(component)
|
65
|
+
if component > Utils::LAB_EPSILON
|
66
|
+
Math.cbrt(component)
|
67
|
+
else
|
68
|
+
((Utils::LAB_KAPPA * component) + 16) / 116.0
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def transformation_matrix(dest)
|
73
|
+
case dest
|
74
|
+
when A98_RGB
|
75
|
+
Conversions::XYZ_D50_TO_LINEAR_A98_RGB
|
76
|
+
when DISPLAY_P3
|
77
|
+
Conversions::XYZ_D50_TO_LINEAR_DISPLAY_P3
|
78
|
+
when LMS
|
79
|
+
Conversions::XYZ_D50_TO_LMS
|
80
|
+
when PROPHOTO_RGB
|
81
|
+
Conversions::XYZ_D50_TO_LINEAR_PROPHOTO_RGB
|
82
|
+
when REC2020
|
83
|
+
Conversions::XYZ_D50_TO_LINEAR_REC2020
|
84
|
+
when RGB, SRGB, SRGB_LINEAR
|
85
|
+
Conversions::XYZ_D50_TO_LINEAR_SRGB
|
86
|
+
when XYZ_D65
|
87
|
+
Conversions::XYZ_D50_TO_XYZ_D65
|
88
|
+
else
|
89
|
+
super
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private_constant :XyzD50
|
95
|
+
|
96
|
+
XYZ_D50 = XyzD50.new
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Value
|
5
|
+
class Color
|
6
|
+
module Space
|
7
|
+
# @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/space/xyz_d65.dart
|
8
|
+
class XyzD65
|
9
|
+
include Space
|
10
|
+
|
11
|
+
def bounded?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super('xyz', Utils::XYZ_CHANNELS)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_linear(channel)
|
20
|
+
channel
|
21
|
+
end
|
22
|
+
|
23
|
+
def from_linear(channel)
|
24
|
+
channel
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def transformation_matrix(dest)
|
30
|
+
case dest
|
31
|
+
when A98_RGB
|
32
|
+
Conversions::XYZ_D65_TO_LINEAR_A98_RGB
|
33
|
+
when DISPLAY_P3
|
34
|
+
Conversions::XYZ_D65_TO_LINEAR_DISPLAY_P3
|
35
|
+
when LMS
|
36
|
+
Conversions::XYZ_D65_TO_LMS
|
37
|
+
when PROPHOTO_RGB
|
38
|
+
Conversions::XYZ_D65_TO_LINEAR_PROPHOTO_RGB
|
39
|
+
when REC2020
|
40
|
+
Conversions::XYZ_D65_TO_LINEAR_REC2020
|
41
|
+
when RGB, SRGB, SRGB_LINEAR
|
42
|
+
Conversions::XYZ_D65_TO_LINEAR_SRGB
|
43
|
+
when XYZ_D50
|
44
|
+
Conversions::XYZ_D65_TO_XYZ_D50
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private_constant :XyzD65
|
52
|
+
|
53
|
+
XYZ_D65 = XyzD65.new
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|