sass-embedded 1.79.3-x86_64-darwin → 1.79.4-x86_64-darwin

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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/exe/sass +1 -9
  3. data/ext/sass/dart-sass/src/sass.snapshot +0 -0
  4. data/lib/sass/compiler/connection.rb +1 -9
  5. data/lib/sass/compiler/host/protofier.rb +16 -55
  6. data/lib/sass/elf.rb +4 -4
  7. data/lib/sass/embedded/version.rb +1 -1
  8. data/lib/sass/value/color/channel.rb +79 -0
  9. data/lib/sass/value/color/conversions.rb +464 -0
  10. data/lib/sass/value/color/gamut_map_method/clip.rb +45 -0
  11. data/lib/sass/value/color/gamut_map_method/local_minde.rb +94 -0
  12. data/lib/sass/value/color/gamut_map_method.rb +45 -0
  13. data/lib/sass/value/color/interpolation_method.rb +51 -0
  14. data/lib/sass/value/color/space/a98_rgb.rb +57 -0
  15. data/lib/sass/value/color/space/display_p3.rb +57 -0
  16. data/lib/sass/value/color/space/hsl.rb +65 -0
  17. data/lib/sass/value/color/space/hwb.rb +70 -0
  18. data/lib/sass/value/color/space/lab.rb +77 -0
  19. data/lib/sass/value/color/space/lch.rb +53 -0
  20. data/lib/sass/value/color/space/lms.rb +129 -0
  21. data/lib/sass/value/color/space/oklab.rb +66 -0
  22. data/lib/sass/value/color/space/oklch.rb +54 -0
  23. data/lib/sass/value/color/space/prophoto_rgb.rb +59 -0
  24. data/lib/sass/value/color/space/rec2020.rb +69 -0
  25. data/lib/sass/value/color/space/rgb.rb +52 -0
  26. data/lib/sass/value/color/space/srgb.rb +141 -0
  27. data/lib/sass/value/color/space/srgb_linear.rb +72 -0
  28. data/lib/sass/value/color/space/utils.rb +86 -0
  29. data/lib/sass/value/color/space/xyz_d50.rb +100 -0
  30. data/lib/sass/value/color/space/xyz_d65.rb +57 -0
  31. data/lib/sass/value/color/space.rb +198 -0
  32. data/lib/sass/value/color.rb +537 -162
  33. data/lib/sass/value/fuzzy_math.rb +30 -3
  34. data/lib/sass/value/string.rb +1 -1
  35. metadata +29 -5
@@ -0,0 +1,464 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ module Value
5
+ class Color
6
+ # @see https:#www.w3.org/TR/css-color-4/#color-conversion-code.
7
+ # @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/conversions.dart
8
+ module Conversions
9
+ # The D50 white point.
10
+ D50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585].freeze
11
+
12
+ # The transformation matrix for converting LMS colors to OKLab.
13
+ #
14
+ # Note that this can't be directly multiplied with {XYZ_D65_TO_LMS}; see Color
15
+ # Level 4 spec for details on how to convert between XYZ and OKLab.
16
+ LMS_TO_OKLAB = [
17
+ 0.2104542553, 0.7936177850, -0.0040720468,
18
+ 1.9779984951, -2.4285922050, 0.4505937099,
19
+ 0.0259040371, 0.7827717662, -0.8086757660
20
+ ].freeze
21
+
22
+ # The transformation matrix for converting OKLab colors to LMS.
23
+ #
24
+ # Note that this can't be directly multiplied with {LMS_TO_XYZ_D65}; see Color
25
+ # Level 4 spec for details on how to convert between XYZ and OKLab.
26
+ OKLAB_TO_LMS = [
27
+ 0.99999999845051981432, 0.396337792173767856780, 0.215803758060758803390,
28
+ 1.00000000888176077670, -0.105561342323656349400, -0.063854174771705903402,
29
+ 1.00000005467241091770, -0.089484182094965759684, -1.291485537864091739900
30
+ ].freeze
31
+
32
+ # The transformation matrix for converting linear-light srgb colors to
33
+ # linear-light display-p3.
34
+ LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = [
35
+ 0.82246196871436230, 0.17753803128563775, 0.00000000000000000,
36
+ 0.03319419885096161, 0.96680580114903840, 0.00000000000000000,
37
+ 0.01708263072112003, 0.07239744066396346, 0.91051992861491650
38
+ ].freeze
39
+
40
+ # The transformation matrix for converting linear-light display-p3 colors to
41
+ # linear-light srgb.
42
+ LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = [
43
+ 1.22494017628055980, -0.22494017628055996, 0.00000000000000000,
44
+ -0.04205695470968816, 1.04205695470968800, 0.00000000000000000,
45
+ -0.01963755459033443, -0.07863604555063188, 1.09827360014096630
46
+ ].freeze
47
+
48
+ # The transformation matrix for converting linear-light srgb colors to
49
+ # linear-light a98-rgb.
50
+ LINEAR_SRGB_TO_LINEAR_A98_RGB = [
51
+ 0.71512560685562470, 0.28487439314437535, 0.00000000000000000,
52
+ 0.00000000000000000, 1.00000000000000000, 0.00000000000000000,
53
+ 0.00000000000000000, 0.04116194845011846, 0.95883805154988160
54
+ ].freeze
55
+
56
+ # The transformation matrix for converting linear-light a98-rgb colors to
57
+ # linear-light srgb.
58
+ LINEAR_A98_RGB_TO_LINEAR_SRGB = [
59
+ 1.39835574396077830, -0.39835574396077830, 0.00000000000000000,
60
+ 0.00000000000000000, 1.00000000000000000, 0.00000000000000000,
61
+ 0.00000000000000000, -0.04292898929447326, 1.04292898929447330
62
+ ].freeze
63
+
64
+ # The transformation matrix for converting linear-light srgb colors to
65
+ # linear-light rec2020.
66
+ LINEAR_SRGB_TO_LINEAR_REC2020 = [
67
+ 0.62740389593469900, 0.32928303837788370, 0.04331306568741722,
68
+ 0.06909728935823208, 0.91954039507545870, 0.01136231556630917,
69
+ 0.01639143887515027, 0.08801330787722575, 0.89559525324762400
70
+ ].freeze
71
+
72
+ # The transformation matrix for converting linear-light rec2020 colors to
73
+ # linear-light srgb.
74
+ LINEAR_REC2020_TO_LINEAR_SRGB = [
75
+ 1.66049100210843450, -0.58764113878854950, -0.07284986331988487,
76
+ -0.12455047452159074, 1.13289989712596030, -0.00834942260436947,
77
+ -0.01815076335490530, -0.10057889800800737, 1.11872966136291270
78
+ ].freeze
79
+
80
+ # The transformation matrix for converting linear-light srgb colors to xyz.
81
+ LINEAR_SRGB_TO_XYZ_D65 = [
82
+ 0.41239079926595950, 0.35758433938387796, 0.18048078840183430,
83
+ 0.21263900587151036, 0.71516867876775590, 0.07219231536073371,
84
+ 0.01933081871559185, 0.11919477979462598, 0.95053215224966060
85
+ ].freeze
86
+
87
+ # The transformation matrix for converting xyz colors to linear-light srgb.
88
+ XYZ_D65_TO_LINEAR_SRGB = [
89
+ 3.24096994190452130, -1.53738317757009350, -0.49861076029300330,
90
+ -0.96924363628087980, 1.87596750150772060, 0.04155505740717561,
91
+ 0.05563007969699360, -0.20397695888897657, 1.05697151424287860
92
+ ].freeze
93
+
94
+ # The transformation matrix for converting linear-light srgb colors to lms.
95
+ LINEAR_SRGB_TO_LMS = [
96
+ 0.41222147080000016, 0.53633253629999990, 0.05144599290000001,
97
+ 0.21190349820000007, 0.68069954509999990, 0.10739695660000000,
98
+ 0.08830246190000005, 0.28171883759999994, 0.62997870050000000
99
+ ].freeze
100
+
101
+ # The transformation matrix for converting lms colors to linear-light srgb.
102
+ LMS_TO_LINEAR_SRGB = [
103
+ 4.07674166134799300, -3.30771159040819240, 0.23096992872942781,
104
+ -1.26843800409217660, 2.60975740066337240, -0.34131939631021974,
105
+ -0.00419608654183720, -0.70341861445944950, 1.70761470093094480
106
+ ].freeze
107
+
108
+ # The transformation matrix for converting linear-light srgb colors to
109
+ # linear-light prophoto-rgb.
110
+ LINEAR_SRGB_TO_LINEAR_PROPHOTO_RGB = [
111
+ 0.52927697762261160, 0.33015450197849283, 0.14056852039889556,
112
+ 0.09836585954044917, 0.87347071290696180, 0.02816342755258900,
113
+ 0.01687534092138684, 0.11765941425612084, 0.86546524482249230
114
+ ].freeze
115
+
116
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
117
+ # linear-light srgb.
118
+ LINEAR_PROPHOTO_RGB_TO_LINEAR_SRGB = [
119
+ 2.03438084951699600, -0.72763578993413420, -0.30674505958286180,
120
+ -0.22882573163305037, 1.23174254119010480, -0.00291680955705449,
121
+ -0.00855882878391742, -0.15326670213803720, 1.16182553092195470
122
+ ].freeze
123
+
124
+ # The transformation matrix for converting linear-light srgb colors to xyz-d50.
125
+ LINEAR_SRGB_TO_XYZ_D50 = [
126
+ 0.43606574687426936, 0.38515150959015960, 0.14307841996513868,
127
+ 0.22249317711056518, 0.71688701309448240, 0.06061980979495235,
128
+ 0.01392392146316939, 0.09708132423141015, 0.71409935681588070
129
+ ].freeze
130
+
131
+ # The transformation matrix for converting xyz-d50 colors to linear-light srgb.
132
+ XYZ_D50_TO_LINEAR_SRGB = [
133
+ 3.13413585290011780, -1.61738599801804200, -0.49066221791109754,
134
+ -0.97879547655577770, 1.91625437739598840, 0.03344287339036693,
135
+ 0.07195539255794733, -0.22897675981518200, 1.40538603511311820
136
+ ].freeze
137
+
138
+ # The transformation matrix for converting linear-light display-p3 colors to
139
+ # linear-light a98-rgb.
140
+ LINEAR_DISPLAY_P3_TO_LINEAR_A98_RGB = [
141
+ 0.86400513747404840, 0.13599486252595164, 0.00000000000000000,
142
+ -0.04205695470968816, 1.04205695470968800, 0.00000000000000000,
143
+ -0.02056038078232985, -0.03250613804550798, 1.05306651882783790
144
+ ].freeze
145
+
146
+ # The transformation matrix for converting linear-light a98-rgb colors to
147
+ # linear-light display-p3.
148
+ LINEAR_A98_RGB_TO_LINEAR_DISPLAY_P3 = [
149
+ 1.15009441814101840, -0.15009441814101834, 0.00000000000000000,
150
+ 0.04641729862941844, 0.95358270137058150, 0.00000000000000000,
151
+ 0.02388759479083904, 0.02650477632633013, 0.94960762888283080
152
+ ].freeze
153
+
154
+ # The transformation matrix for converting linear-light display-p3 colors to
155
+ # linear-light rec2020.
156
+ LINEAR_DISPLAY_P3_TO_LINEAR_REC2020 = [
157
+ 0.75383303436172180, 0.19859736905261630, 0.04756959658566187,
158
+ 0.04574384896535833, 0.94177721981169350, 0.01247893122294812,
159
+ -0.00121034035451832, 0.01760171730108989, 0.98360862305342840
160
+ ].freeze
161
+
162
+ # The transformation matrix for converting linear-light rec2020 colors to
163
+ # linear-light display-p3.
164
+ LINEAR_REC2020_TO_LINEAR_DISPLAY_P3 = [
165
+ 1.34357825258433200, -0.28217967052613570, -0.06139858205819628,
166
+ -0.06529745278911953, 1.07578791584857460, -0.01049046305945495,
167
+ 0.00282178726170095, -0.01959849452449406, 1.01677670726279310
168
+ ].freeze
169
+
170
+ # The transformation matrix for converting linear-light display-p3 colors to
171
+ # xyz.
172
+ LINEAR_DISPLAY_P3_TO_XYZ_D65 = [
173
+ 0.48657094864821626, 0.26566769316909294, 0.19821728523436250,
174
+ 0.22897456406974884, 0.69173852183650620, 0.07928691409374500,
175
+ 0.00000000000000000, 0.04511338185890257, 1.04394436890097570
176
+ ].freeze
177
+
178
+ # The transformation matrix for converting xyz colors to linear-light
179
+ # display-p3.
180
+ XYZ_D65_TO_LINEAR_DISPLAY_P3 = [
181
+ 2.49349691194142450, -0.93138361791912360, -0.40271078445071684,
182
+ -0.82948896956157490, 1.76266406031834680, 0.02362468584194359,
183
+ 0.03584583024378433, -0.07617238926804170, 0.95688452400768730
184
+ ].freeze
185
+
186
+ # The transformation matrix for converting linear-light display-p3 colors to
187
+ # lms.
188
+ LINEAR_DISPLAY_P3_TO_LMS = [
189
+ 0.48137985442585490, 0.46211836973903553, 0.05650177583510960,
190
+ 0.22883194490233110, 0.65321681282840370, 0.11795124216926511,
191
+ 0.08394575573016760, 0.22416526885956980, 0.69188897541026260
192
+ ].freeze
193
+
194
+ # The transformation matrix for converting lms colors to linear-light
195
+ # display-p3.
196
+ LMS_TO_LINEAR_DISPLAY_P3 = [
197
+ 3.12776898667772140, -2.25713579553953770, 0.12936680863610234,
198
+ -1.09100904738343900, 2.41333175827934370, -0.32232271065457110,
199
+ -0.02601081320950207, -0.50804132569306730, 1.53405213885176520
200
+ ].freeze
201
+
202
+ # The transformation matrix for converting linear-light display-p3 colors to
203
+ # linear-light prophoto-rgb.
204
+ LINEAR_DISPLAY_P3_TO_LINEAR_PROPHOTO_RGB = [
205
+ 0.63168691934035890, 0.21393038569465722, 0.15438269496498390,
206
+ 0.08320371426648458, 0.88586513676302430, 0.03093114897049121,
207
+ -0.00127273456473881, 0.05075510433665735, 0.95051763022808140
208
+ ].freeze
209
+
210
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
211
+ # linear-light display-p3.
212
+ LINEAR_PROPHOTO_RGB_TO_LINEAR_DISPLAY_P3 = [
213
+ 1.63257560870691790, -0.37977161848259840, -0.25280399022431950,
214
+ -0.15370040233755072, 1.16670254724250140, -0.01300214490495082,
215
+ 0.01039319529676572, -0.06280731264959440, 1.05241411735282870
216
+ ].freeze
217
+
218
+ # The transformation matrix for converting linear-light display-p3 colors to
219
+ # xyz-d50.
220
+ LINEAR_DISPLAY_P3_TO_XYZ_D50 = [
221
+ 0.51514644296811600, 0.29200998206385770, 0.15713925139759397,
222
+ 0.24120032212525520, 0.69222254113138180, 0.06657713674336294,
223
+ -0.00105013914714014, 0.04187827018907460, 0.78427647146852570
224
+ ].freeze
225
+
226
+ # The transformation matrix for converting xyz-d50 colors to linear-light
227
+ # display-p3.
228
+ XYZ_D50_TO_LINEAR_DISPLAY_P3 = [
229
+ 2.40393412185549730, -0.99003044249559310, -0.39761363181465614,
230
+ -0.84227001614546880, 1.79895801610670820, 0.01604562477090472,
231
+ 0.04819381686413303, -0.09738519815446048, 1.27367136933212730
232
+ ].freeze
233
+
234
+ # The transformation matrix for converting linear-light a98-rgb colors to
235
+ # linear-light rec2020.
236
+ LINEAR_A98_RGB_TO_LINEAR_REC2020 = [
237
+ 0.87733384166365680, 0.07749370651571998, 0.04517245182062317,
238
+ 0.09662259146620378, 0.89152732024418050, 0.01185008828961569,
239
+ 0.02292106270284839, 0.04303668501067932, 0.93404225228647230
240
+ ].freeze
241
+
242
+ # The transformation matrix for converting linear-light rec2020 colors to
243
+ # linear-light a98-rgb.
244
+ LINEAR_REC2020_TO_LINEAR_A98_RGB = [
245
+ 1.15197839471591630, -0.09750305530240860, -0.05447533941350766,
246
+ -0.12455047452159074, 1.13289989712596030, -0.00834942260436947,
247
+ -0.02253038278105590, -0.04980650742838876, 1.07233689020944460
248
+ ].freeze
249
+
250
+ # The transformation matrix for converting linear-light a98-rgb colors to xyz.
251
+ LINEAR_A98_RGB_TO_XYZ_D65 = [
252
+ 0.57666904291013080, 0.18555823790654627, 0.18822864623499472,
253
+ 0.29734497525053616, 0.62736356625546600, 0.07529145849399789,
254
+ 0.02703136138641237, 0.07068885253582714, 0.99133753683763890
255
+ ].freeze
256
+
257
+ # The transformation matrix for converting xyz colors to linear-light a98-rgb.
258
+ XYZ_D65_TO_LINEAR_A98_RGB = [
259
+ 2.04158790381074600, -0.56500697427885960, -0.34473135077832950,
260
+ -0.96924363628087980, 1.87596750150772060, 0.04155505740717561,
261
+ 0.01344428063203102, -0.11836239223101823, 1.01517499439120540
262
+ ].freeze
263
+
264
+ # The transformation matrix for converting linear-light a98-rgb colors to lms.
265
+ LINEAR_A98_RGB_TO_LMS = [
266
+ 0.57643226147714040, 0.36991322114441194, 0.05365451737844765,
267
+ 0.29631647387335260, 0.59167612662650690, 0.11200739940014041,
268
+ 0.12347825480374285, 0.21949869580674647, 0.65702304938951070
269
+ ].freeze
270
+
271
+ # The transformation matrix for converting lms colors to linear-light a98-rgb.
272
+ LMS_TO_LINEAR_A98_RGB = [
273
+ 2.55403684790806950, -1.62197620262602140, 0.06793935455575403,
274
+ -1.26843800409217660, 2.60975740066337240, -0.34131939631021974,
275
+ -0.05623474718052319, -0.56704183411879500, 1.62327658124261400
276
+ ].freeze
277
+
278
+ # The transformation matrix for converting linear-light a98-rgb colors to
279
+ # linear-light prophoto-rgb.
280
+ LINEAR_A98_RGB_TO_LINEAR_PROPHOTO_RGB = [
281
+ 0.74011750180477920, 0.11327951328898105, 0.14660298490623970,
282
+ 0.13755046469802620, 0.83307708026948400, 0.02937245503248977,
283
+ 0.02359772990871766, 0.07378347703906656, 0.90261879305221580
284
+ ].freeze
285
+
286
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
287
+ # linear-light a98-rgb.
288
+ LINEAR_PROPHOTO_RGB_TO_LINEAR_A98_RGB = [
289
+ 1.38965124815152000, -0.16945907691487766, -0.22019217123664242,
290
+ -0.22882573163305037, 1.23174254119010480, -0.00291680955705449,
291
+ -0.01762544368426068, -0.09625702306122665, 1.11388246674548740
292
+ ].freeze
293
+
294
+ # The transformation matrix for converting linear-light a98-rgb colors to
295
+ # xyz-d50.
296
+ LINEAR_A98_RGB_TO_XYZ_D50 = [
297
+ 0.60977504188618140, 0.20530000261929401, 0.14922063192409227,
298
+ 0.31112461220464155, 0.62565323083468560, 0.06322215696067286,
299
+ 0.01947059555648168, 0.06087908649415867, 0.74475492045981980
300
+ ].freeze
301
+
302
+ # The transformation matrix for converting xyz-d50 colors to linear-light
303
+ # a98-rgb.
304
+ XYZ_D50_TO_LINEAR_A98_RGB = [
305
+ 1.96246703637688060, -0.61074234048150730, -0.34135809808271540,
306
+ -0.97879547655577770, 1.91625437739598840, 0.03344287339036693,
307
+ 0.02870443944957101, -0.14067486633170680, 1.34891418141379370
308
+ ].freeze
309
+
310
+ # The transformation matrix for converting linear-light rec2020 colors to xyz.
311
+ LINEAR_REC2020_TO_XYZ_D65 = [
312
+ 0.63695804830129130, 0.14461690358620838, 0.16888097516417205,
313
+ 0.26270021201126703, 0.67799807151887100, 0.05930171646986194,
314
+ 0.00000000000000000, 0.02807269304908750, 1.06098505771079090
315
+ ].freeze
316
+
317
+ # The transformation matrix for converting xyz colors to linear-light rec2020.
318
+ XYZ_D65_TO_LINEAR_REC2020 = [
319
+ 1.71665118797126760, -0.35567078377639240, -0.25336628137365980,
320
+ -0.66668435183248900, 1.61648123663493900, 0.01576854581391113,
321
+ 0.01763985744531091, -0.04277061325780865, 0.94210312123547400
322
+ ].freeze
323
+
324
+ # The transformation matrix for converting linear-light rec2020 colors to lms.
325
+ LINEAR_REC2020_TO_LMS = [
326
+ 0.61675578719908560, 0.36019839939276255, 0.02304581340815186,
327
+ 0.26513306398328140, 0.63583936407771060, 0.09902757183900800,
328
+ 0.10010263423281572, 0.20390651940192997, 0.69599084636525430
329
+ ].freeze
330
+
331
+ # The transformation matrix for converting lms colors to linear-light rec2020.
332
+ LMS_TO_LINEAR_REC2020 = [
333
+ 2.13990673569556170, -1.24638950878469060, 0.10648277296448995,
334
+ -0.88473586245815630, 2.16323098210838260, -0.27849511943390290,
335
+ -0.04857375801465988, -0.45450314291725170, 1.50307690088646130
336
+ ].freeze
337
+
338
+ # The transformation matrix for converting linear-light rec2020 colors to
339
+ # linear-light prophoto-rgb.
340
+ LINEAR_REC2020_TO_LINEAR_PROPHOTO_RGB = [
341
+ 0.83518733312972350, 0.04886884858605698, 0.11594381828421951,
342
+ 0.05403324519953363, 0.92891840856920440, 0.01704834623126199,
343
+ -0.00234203897072539, 0.03633215316169465, 0.96600988580903070
344
+ ].freeze
345
+
346
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
347
+ # linear-light rec2020.
348
+ LINEAR_PROPHOTO_RGB_TO_LINEAR_REC2020 = [
349
+ 1.20065932951740800, -0.05756805370122346, -0.14309127581618444,
350
+ -0.06994154955888504, 1.08061789759721400, -0.01067634803832895,
351
+ 0.00554147334294746, -0.04078219298657951, 1.03524071964363200
352
+ ].freeze
353
+
354
+ # The transformation matrix for converting linear-light rec2020 colors to
355
+ # xyz-d50.
356
+ LINEAR_REC2020_TO_XYZ_D50 = [
357
+ 0.67351546318827600, 0.16569726370390453, 0.12508294953738705,
358
+ 0.27905900514112060, 0.67531800574910980, 0.04562298910976962,
359
+ -0.00193242713400438, 0.02997782679282923, 0.79705920285163550
360
+ ].freeze
361
+
362
+ # The transformation matrix for converting xyz-d50 colors to linear-light
363
+ # rec2020.
364
+ XYZ_D50_TO_LINEAR_REC2020 = [
365
+ 1.64718490467176600, -0.39368189813164710, -0.23595963848828266,
366
+ -0.68266410741738180, 1.64771461274440760, 0.01281708338512084,
367
+ 0.02966887665275675, -0.06292589642970030, 1.25355782018657710
368
+ ].freeze
369
+
370
+ # The transformation matrix for converting xyz colors to lms.
371
+ XYZ_D65_TO_LMS = [
372
+ 0.81902244321643190, 0.36190625628012210, -0.12887378261216414,
373
+ 0.03298366719802710, 0.92928684689655460, 0.03614466816999844,
374
+ 0.04817719956604625, 0.26423952494422764, 0.63354782581369370
375
+ ].freeze
376
+
377
+ # The transformation matrix for converting lms colors to xyz.
378
+ LMS_TO_XYZ_D65 = [
379
+ 1.22687987337415570, -0.55781499655548140, 0.28139105017721590,
380
+ -0.04057576262431372, 1.11228682939705960, -0.07171106666151703,
381
+ -0.07637294974672143, -0.42149332396279143, 1.58692402442724180
382
+ ].freeze
383
+
384
+ # The transformation matrix for converting xyz colors to linear-light
385
+ # prophoto-rgb.
386
+ XYZ_D65_TO_LINEAR_PROPHOTO_RGB = [
387
+ 1.40319046337749790, -0.22301514479051668, -0.10160668507413790,
388
+ -0.52623840216330720, 1.48163196292346440, 0.01701879027252688,
389
+ -0.01120226528622150, 0.01824640347962099, 0.91124722749150480
390
+ ].freeze
391
+
392
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
393
+ # xyz.
394
+ LINEAR_PROPHOTO_RGB_TO_XYZ_D65 = [
395
+ 0.75559074229692100, 0.11271984265940525, 0.08214534209534540,
396
+ 0.26832184357857190, 0.71511525666179120, 0.01656289975963685,
397
+ 0.00391597276242580, -0.01293344283684181, 1.09807522083429450
398
+ ].freeze
399
+
400
+ # The transformation matrix for converting xyz colors to xyz-d50.
401
+ XYZ_D65_TO_XYZ_D50 = [
402
+ 1.04792979254499660, 0.02294687060160952, -0.05019226628920519,
403
+ 0.02962780877005567, 0.99043442675388000, -0.01707379906341879,
404
+ -0.00924304064620452, 0.01505519149029816, 0.75187428142813700
405
+ ].freeze
406
+
407
+ # The transformation matrix for converting xyz-d50 colors to xyz.
408
+ XYZ_D50_TO_XYZ_D65 = [
409
+ 0.95547342148807520, -0.02309845494876452, 0.06325924320057065,
410
+ -0.02836970933386358, 1.00999539808130410, 0.02104144119191730,
411
+ 0.01231401486448199, -0.02050764929889898, 1.33036592624212400
412
+ ].freeze
413
+
414
+ # The transformation matrix for converting lms colors to linear-light
415
+ # prophoto-rgb.
416
+ LMS_TO_LINEAR_PROPHOTO_RGB = [
417
+ 1.73835514985815240, -0.98795095237343430, 0.24959580241648663,
418
+ -0.70704942624914860, 1.93437008438177620, -0.22732065793919040,
419
+ -0.08407883426424761, -0.35754059702097796, 1.44161943124947150
420
+ ].freeze
421
+
422
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
423
+ # lms.
424
+ LINEAR_PROPHOTO_RGB_TO_LMS = [
425
+ 0.71544846349294310, 0.35279154798172740, -0.06824001147467047,
426
+ 0.27441165509049420, 0.66779764080811480, 0.05779070400139092,
427
+ 0.10978443849083751, 0.18619828746596980, 0.70401727404319270
428
+ ].freeze
429
+
430
+ # The transformation matrix for converting lms colors to xyz-d50.
431
+ LMS_TO_XYZ_D50 = [
432
+ 1.28858621583908840, -0.53787174651736210, 0.21358120705405403,
433
+ -0.00253389352489796, 1.09231682453266550, -0.08978293089853581,
434
+ -0.06937383312514489, -0.29500839218634667, 1.18948682779245090
435
+ ].freeze
436
+
437
+ # The transformation matrix for converting xyz-d50 colors to lms.
438
+ XYZ_D50_TO_LMS = [
439
+ 0.77070004712402500, 0.34924839871072740, -0.11202352004249890,
440
+ 0.00559650559780223, 0.93707232493333150, 0.06972569131301698,
441
+ 0.04633715253432816, 0.25277530868525870, 0.85145807371608350
442
+ ].freeze
443
+
444
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
445
+ # xyz-d50.
446
+ LINEAR_PROPHOTO_RGB_TO_XYZ_D50 = [
447
+ 0.79776664490064230, 0.13518129740053308, 0.03134773412839220,
448
+ 0.28807482881940130, 0.71183523424187300, 0.00008993693872564,
449
+ 0.00000000000000000, 0.00000000000000000, 0.82510460251046020
450
+ ].freeze
451
+
452
+ # The transformation matrix for converting xyz-d50 colors to linear-light
453
+ # prophoto-rgb.
454
+ XYZ_D50_TO_LINEAR_PROPHOTO_RGB = [
455
+ 1.34578688164715830, -0.25557208737979464, -0.05110186497554526,
456
+ -0.54463070512490190, 1.50824774284514680, 0.02052744743642139,
457
+ 0.00000000000000000, 0.00000000000000000, 1.21196754563894520
458
+ ].freeze
459
+ end
460
+
461
+ private_constant :Conversions
462
+ end
463
+ end
464
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ module Value
5
+ class Color
6
+ module GamutMapMethod
7
+ # @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/gamut_map_method/local_minde.dart
8
+ class Clip
9
+ include GamutMapMethod
10
+
11
+ def initialize
12
+ super('clip')
13
+ end
14
+
15
+ def map(color)
16
+ space = color.send(:_space)
17
+ Color.send(:for_space_internal,
18
+ space,
19
+ _clamp_channel(color.send(:channel0_or_nil), space.channels[0]),
20
+ _clamp_channel(color.send(:channel1_or_nil), space.channels[1]),
21
+ _clamp_channel(color.send(:channel2_or_nil), space.channels[2]),
22
+ color.send(:alpha_or_nil))
23
+ end
24
+
25
+ private
26
+
27
+ def _clamp_channel(value, channel)
28
+ return nil if value.nil?
29
+
30
+ case channel
31
+ when LinearChannel
32
+ FuzzyMath.clamp_like_css(value, channel.min, channel.max)
33
+ else
34
+ value
35
+ end
36
+ end
37
+ end
38
+
39
+ private_constant :Clip
40
+
41
+ CLIP = Clip.new
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ module Value
5
+ class Color
6
+ module GamutMapMethod
7
+ # @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/gamut_map_method/local_minde.dart
8
+ class LocalMinde
9
+ include GamutMapMethod
10
+
11
+ # A constant from the gamut-mapping algorithm.
12
+ JND = 0.02
13
+
14
+ private_constant :JND
15
+
16
+ # A constant from the gamut-mapping algorithm.
17
+ EPSILON = 0.0001
18
+
19
+ private_constant :EPSILON
20
+
21
+ def initialize
22
+ super('local-minde')
23
+ end
24
+
25
+ def map(color)
26
+ original_oklch = color.send(:_to_space, Space::OKLCH)
27
+ lightness = original_oklch.send(:channel0_or_nil)
28
+ hue = original_oklch.send(:channel2_or_nil)
29
+ alpha = original_oklch.send(:alpha_or_nil)
30
+
31
+ if FuzzyMath.greater_than_or_equals(lightness.nil? ? 0 : lightness, 1)
32
+ if color.legacy?
33
+ return Color.send(:_for_space,
34
+ Space::RGB, 255, 255, 255, color.send(:alpha_or_nil))
35
+ .send(:_to_space, color.send(:_space))
36
+ else
37
+ return Color.send(:for_space_internal,
38
+ color.send(:_space), 1, 1, 1, color.send(:alpha_or_nil))
39
+ end
40
+ elsif FuzzyMath.less_than_or_equals(lightness.nil? ? 0 : lightness, 0)
41
+ return Color.send(:_for_space,
42
+ Space::RGB, 0, 0, 0, color.send(:alpha_or_nil))
43
+ .send(:_to_space, color.send(:_space))
44
+ end
45
+
46
+ clipped = color.send(:_to_gamut, CLIP)
47
+ return clipped if _delta_eok(clipped, color) < JND
48
+
49
+ min = 0.0
50
+ max = original_oklch.send(:channel1)
51
+ min_in_gamut = true
52
+ while max - min > EPSILON
53
+ chroma = (min + max) / 2
54
+
55
+ current = Space::OKLCH.convert(color.send(:_space), lightness, chroma, hue, alpha)
56
+
57
+ if min_in_gamut && current.in_gamut?
58
+ min = chroma
59
+ next
60
+ end
61
+
62
+ clipped = current.send(:_to_gamut, CLIP)
63
+ e = _delta_eok(clipped, current)
64
+
65
+ if e < JND
66
+ return clipped if JND - e < EPSILON
67
+
68
+ min_in_gamut = false
69
+ min = chroma
70
+ else
71
+ max = chroma
72
+ end
73
+ end
74
+ clipped
75
+ end
76
+
77
+ private
78
+
79
+ def _delta_eok(color1, color2)
80
+ lab1 = color1.send(:_to_space, Space::OKLAB)
81
+ lab2 = color2.send(:_to_space, Space::OKLAB)
82
+ Math.sqrt(((lab1.send(:channel0) - lab2.send(:channel0))**2) +
83
+ ((lab1.send(:channel1) - lab2.send(:channel1))**2) +
84
+ ((lab1.send(:channel2) - lab2.send(:channel2))**2))
85
+ end
86
+ end
87
+
88
+ private_constant :LocalMinde
89
+
90
+ LOCAL_MINDE = LocalMinde.new
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ module Value
5
+ class Color
6
+ # @see https://github.com/sass/dart-sass/blob/main/lib/src/value/color/gamut_map_method.dart
7
+ module GamutMapMethod
8
+ # @return [::String]
9
+ attr_reader :name
10
+
11
+ # @param name [::String]
12
+ def initialize(name)
13
+ @name = name
14
+ end
15
+
16
+ class << self
17
+ # @param name [::String]
18
+ # @param argument_name [::String]
19
+ # @return [GamutMapMethod]
20
+ def from_name(name, argument_name = nil)
21
+ case name
22
+ when 'clip'
23
+ CLIP
24
+ when 'local-minde'
25
+ LOCAL_MINDE
26
+ else
27
+ raise Sass::ScriptError.new("Unknown gamut map method \"#{name}\".", argument_name)
28
+ end
29
+ end
30
+ end
31
+
32
+ # @param color [Color]
33
+ # @return [Color]
34
+ def map(color)
35
+ raise NotImplementedError, "[BUG] gamut map method #{name} doesn't implement map."
36
+ end
37
+ end
38
+
39
+ private_constant :GamutMapMethod
40
+ end
41
+ end
42
+ end
43
+
44
+ require_relative 'gamut_map_method/clip'
45
+ require_relative 'gamut_map_method/local_minde'