sass-embedded 1.79.3-x64-mingw32 → 1.79.5-x64-mingw32

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 (37) 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/ext/sass/embedded_sass_pb.rb +1 -1
  5. data/lib/sass/compiler/connection.rb +1 -9
  6. data/lib/sass/compiler/host/protofier.rb +17 -55
  7. data/lib/sass/elf.rb +4 -4
  8. data/lib/sass/embedded/version.rb +1 -1
  9. data/lib/sass/value/color/channel.rb +79 -0
  10. data/lib/sass/value/color/conversions.rb +473 -0
  11. data/lib/sass/value/color/gamut_map_method/clip.rb +45 -0
  12. data/lib/sass/value/color/gamut_map_method/local_minde.rb +94 -0
  13. data/lib/sass/value/color/gamut_map_method.rb +45 -0
  14. data/lib/sass/value/color/interpolation_method.rb +51 -0
  15. data/lib/sass/value/color/space/a98_rgb.rb +57 -0
  16. data/lib/sass/value/color/space/display_p3.rb +57 -0
  17. data/lib/sass/value/color/space/hsl.rb +65 -0
  18. data/lib/sass/value/color/space/hwb.rb +70 -0
  19. data/lib/sass/value/color/space/lab.rb +77 -0
  20. data/lib/sass/value/color/space/lch.rb +53 -0
  21. data/lib/sass/value/color/space/lms.rb +129 -0
  22. data/lib/sass/value/color/space/oklab.rb +66 -0
  23. data/lib/sass/value/color/space/oklch.rb +54 -0
  24. data/lib/sass/value/color/space/prophoto_rgb.rb +59 -0
  25. data/lib/sass/value/color/space/rec2020.rb +69 -0
  26. data/lib/sass/value/color/space/rgb.rb +52 -0
  27. data/lib/sass/value/color/space/srgb.rb +140 -0
  28. data/lib/sass/value/color/space/srgb_linear.rb +72 -0
  29. data/lib/sass/value/color/space/utils.rb +86 -0
  30. data/lib/sass/value/color/space/xyz_d50.rb +100 -0
  31. data/lib/sass/value/color/space/xyz_d65.rb +57 -0
  32. data/lib/sass/value/color/space.rb +198 -0
  33. data/lib/sass/value/color.rb +537 -162
  34. data/lib/sass/value/fuzzy_math.rb +23 -19
  35. data/lib/sass/value/number.rb +1 -1
  36. data/lib/sass/value/string.rb +1 -1
  37. metadata +29 -5
@@ -0,0 +1,473 @@
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
+ #
11
+ # Definition from https://www.w3.org/TR/css-color-4/#color-conversion-code.
12
+ D50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585].freeze
13
+
14
+ # Matrix values from https://www.w3.org/TR/css-color-4/#color-conversion-code.
15
+
16
+ # The transformation matrix for converting LMS colors to OKLab.
17
+ #
18
+ # Note that this can't be directly multiplied with [XYZ_D65_TO_LMS]; see Color
19
+ # Level 4 spec for details on how to convert between XYZ and OKLab.
20
+ LMS_TO_OKLAB = [
21
+ 0.21045426830931400, 0.79361777470230540, -0.00407204301161930,
22
+ 1.97799853243116840, -2.42859224204858000, 0.45059370961741100,
23
+ 0.02590404246554780, 0.78277171245752960, -0.80867575492307740
24
+ ].freeze
25
+
26
+ # The transformation matrix for converting OKLab colors to LMS.
27
+ #
28
+ # Note that this can't be directly multiplied with [LMS_TO_XYZ_D65]; see Color
29
+ # Level 4 spec for details on how to convert between XYZ and OKLab.
30
+ OKLAB_TO_LMS = [
31
+ 1.00000000000000020, 0.39633777737617490, 0.21580375730991360,
32
+ 0.99999999999999980, -0.10556134581565854, -0.06385417282581334,
33
+ 0.99999999999999990, -0.08948417752981180, -1.29148554801940940
34
+ ].freeze
35
+
36
+ # The following matrices were precomputed using
37
+ # https://gist.github.com/nex3/3d7ecfef467b22e02e7a666db1b8a316.
38
+
39
+ # The transformation matrix for converting linear-light srgb colors to
40
+ # linear-light display-p3.
41
+ LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = [
42
+ 0.82246196871436230, 0.17753803128563775, 0.00000000000000000,
43
+ 0.03319419885096161, 0.96680580114903840, 0.00000000000000000,
44
+ 0.01708263072112003, 0.07239744066396346, 0.91051992861491650
45
+ ].freeze
46
+
47
+ # The transformation matrix for converting linear-light display-p3 colors to
48
+ # linear-light srgb.
49
+ LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = [
50
+ 1.22494017628055980, -0.22494017628055996, 0.00000000000000000,
51
+ -0.04205695470968816, 1.04205695470968800, 0.00000000000000000,
52
+ -0.01963755459033443, -0.07863604555063188, 1.09827360014096630
53
+ ].freeze
54
+
55
+ # The transformation matrix for converting linear-light srgb colors to
56
+ # linear-light a98-rgb.
57
+ LINEAR_SRGB_TO_LINEAR_A98_RGB = [
58
+ 0.71512560685562470, 0.28487439314437535, 0.00000000000000000,
59
+ 0.00000000000000000, 1.00000000000000000, 0.00000000000000000,
60
+ 0.00000000000000000, 0.04116194845011846, 0.95883805154988160
61
+ ].freeze
62
+
63
+ # The transformation matrix for converting linear-light a98-rgb colors to
64
+ # linear-light srgb.
65
+ LINEAR_A98_RGB_TO_LINEAR_SRGB = [
66
+ 1.39835574396077830, -0.39835574396077830, 0.00000000000000000,
67
+ 0.00000000000000000, 1.00000000000000000, 0.00000000000000000,
68
+ 0.00000000000000000, -0.04292898929447326, 1.04292898929447330
69
+ ].freeze
70
+
71
+ # The transformation matrix for converting linear-light srgb colors to
72
+ # linear-light rec2020.
73
+ LINEAR_SRGB_TO_LINEAR_REC2020 = [
74
+ 0.62740389593469900, 0.32928303837788370, 0.04331306568741722,
75
+ 0.06909728935823208, 0.91954039507545870, 0.01136231556630917,
76
+ 0.01639143887515027, 0.08801330787722575, 0.89559525324762400
77
+ ].freeze
78
+
79
+ # The transformation matrix for converting linear-light rec2020 colors to
80
+ # linear-light srgb.
81
+ LINEAR_REC2020_TO_LINEAR_SRGB = [
82
+ 1.66049100210843450, -0.58764113878854950, -0.07284986331988487,
83
+ -0.12455047452159074, 1.13289989712596030, -0.00834942260436947,
84
+ -0.01815076335490530, -0.10057889800800737, 1.11872966136291270
85
+ ].freeze
86
+
87
+ # The transformation matrix for converting linear-light srgb colors to xyz.
88
+ LINEAR_SRGB_TO_XYZ_D65 = [
89
+ 0.41239079926595950, 0.35758433938387796, 0.18048078840183430,
90
+ 0.21263900587151036, 0.71516867876775590, 0.07219231536073371,
91
+ 0.01933081871559185, 0.11919477979462598, 0.95053215224966060
92
+ ].freeze
93
+
94
+ # The transformation matrix for converting xyz colors to linear-light srgb.
95
+ XYZ_D65_TO_LINEAR_SRGB = [
96
+ 3.24096994190452130, -1.53738317757009350, -0.49861076029300330,
97
+ -0.96924363628087980, 1.87596750150772060, 0.04155505740717561,
98
+ 0.05563007969699360, -0.20397695888897657, 1.05697151424287860
99
+ ].freeze
100
+
101
+ # The transformation matrix for converting linear-light srgb colors to lms.
102
+ LINEAR_SRGB_TO_LMS = [
103
+ 0.41222146947076300, 0.53633253726173480, 0.05144599326750220,
104
+ 0.21190349581782520, 0.68069955064523420, 0.10739695353694050,
105
+ 0.08830245919005641, 0.28171883913612150, 0.62997870167382210
106
+ ].freeze
107
+
108
+ # The transformation matrix for converting lms colors to linear-light srgb.
109
+ LMS_TO_LINEAR_SRGB = [
110
+ 4.07674163607595800, -3.30771153925806200, 0.23096990318210417,
111
+ -1.26843797328503200, 2.60975734928768900, -0.34131937600265710,
112
+ -0.00419607613867551, -0.70341861793593630, 1.70761469407461200
113
+ ].freeze
114
+
115
+ # The transformation matrix for converting linear-light srgb colors to
116
+ # linear-light prophoto-rgb.
117
+ LINEAR_SRGB_TO_LINEAR_PROPHOTO_RGB = [
118
+ 0.52927697762261160, 0.33015450197849283, 0.14056852039889556,
119
+ 0.09836585954044917, 0.87347071290696180, 0.02816342755258900,
120
+ 0.01687534092138684, 0.11765941425612084, 0.86546524482249230
121
+ ].freeze
122
+
123
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
124
+ # linear-light srgb.
125
+ LINEAR_PROPHOTO_RGB_TO_LINEAR_SRGB = [
126
+ 2.03438084951699600, -0.72763578993413420, -0.30674505958286180,
127
+ -0.22882573163305037, 1.23174254119010480, -0.00291680955705449,
128
+ -0.00855882878391742, -0.15326670213803720, 1.16182553092195470
129
+ ].freeze
130
+
131
+ # The transformation matrix for converting linear-light srgb colors to
132
+ # xyz-d50.
133
+ LINEAR_SRGB_TO_XYZ_D50 = [
134
+ 0.43606574687426936, 0.38515150959015960, 0.14307841996513868,
135
+ 0.22249317711056518, 0.71688701309448240, 0.06061980979495235,
136
+ 0.01392392146316939, 0.09708132423141015, 0.71409935681588070
137
+ ].freeze
138
+
139
+ # The transformation matrix for converting xyz-d50 colors to linear-light
140
+ # srgb.
141
+ XYZ_D50_TO_LINEAR_SRGB = [
142
+ 3.13413585290011780, -1.61738599801804200, -0.49066221791109754,
143
+ -0.97879547655577770, 1.91625437739598840, 0.03344287339036693,
144
+ 0.07195539255794733, -0.22897675981518200, 1.40538603511311820
145
+ ].freeze
146
+
147
+ # The transformation matrix for converting linear-light display-p3 colors to
148
+ # linear-light a98-rgb.
149
+ LINEAR_DISPLAY_P3_TO_LINEAR_A98_RGB = [
150
+ 0.86400513747404840, 0.13599486252595164, 0.00000000000000000,
151
+ -0.04205695470968816, 1.04205695470968800, 0.00000000000000000,
152
+ -0.02056038078232985, -0.03250613804550798, 1.05306651882783790
153
+ ].freeze
154
+
155
+ # The transformation matrix for converting linear-light a98-rgb colors to
156
+ # linear-light display-p3.
157
+ LINEAR_A98_RGB_TO_LINEAR_DISPLAY_P3 = [
158
+ 1.15009441814101840, -0.15009441814101834, 0.00000000000000000,
159
+ 0.04641729862941844, 0.95358270137058150, 0.00000000000000000,
160
+ 0.02388759479083904, 0.02650477632633013, 0.94960762888283080
161
+ ].freeze
162
+
163
+ # The transformation matrix for converting linear-light display-p3 colors to
164
+ # linear-light rec2020.
165
+ LINEAR_DISPLAY_P3_TO_LINEAR_REC2020 = [
166
+ 0.75383303436172180, 0.19859736905261630, 0.04756959658566187,
167
+ 0.04574384896535833, 0.94177721981169350, 0.01247893122294812,
168
+ -0.00121034035451832, 0.01760171730108989, 0.98360862305342840
169
+ ].freeze
170
+
171
+ # The transformation matrix for converting linear-light rec2020 colors to
172
+ # linear-light display-p3.
173
+ LINEAR_REC2020_TO_LINEAR_DISPLAY_P3 = [
174
+ 1.34357825258433200, -0.28217967052613570, -0.06139858205819628,
175
+ -0.06529745278911953, 1.07578791584857460, -0.01049046305945495,
176
+ 0.00282178726170095, -0.01959849452449406, 1.01677670726279310
177
+ ].freeze
178
+
179
+ # The transformation matrix for converting linear-light display-p3 colors to
180
+ # xyz.
181
+ LINEAR_DISPLAY_P3_TO_XYZ_D65 = [
182
+ 0.48657094864821626, 0.26566769316909294, 0.19821728523436250,
183
+ 0.22897456406974884, 0.69173852183650620, 0.07928691409374500,
184
+ 0.00000000000000000, 0.04511338185890257, 1.04394436890097570
185
+ ].freeze
186
+
187
+ # The transformation matrix for converting xyz colors to linear-light
188
+ # display-p3.
189
+ XYZ_D65_TO_LINEAR_DISPLAY_P3 = [
190
+ 2.49349691194142450, -0.93138361791912360, -0.40271078445071684,
191
+ -0.82948896956157490, 1.76266406031834680, 0.02362468584194359,
192
+ 0.03584583024378433, -0.07617238926804170, 0.95688452400768730
193
+ ].freeze
194
+
195
+ # The transformation matrix for converting linear-light display-p3 colors to
196
+ # lms.
197
+ LINEAR_DISPLAY_P3_TO_LMS = [
198
+ 0.48137985274995443, 0.46211837101131803, 0.05650177623872756,
199
+ 0.22883194181124472, 0.65321681938356760, 0.11795123880518774,
200
+ 0.08394575232299319, 0.22416527097756642, 0.69188897669944040
201
+ ].freeze
202
+
203
+ # The transformation matrix for converting lms colors to linear-light
204
+ # display-p3.
205
+ LMS_TO_LINEAR_DISPLAY_P3 = [
206
+ 3.12776897136187370, -2.25713576259163860, 0.12936679122976494,
207
+ -1.09100901843779790, 2.41333171030692250, -0.32232269186912466,
208
+ -0.02601080193857045, -0.50804133170416700, 1.53405213364273730
209
+ ].freeze
210
+
211
+ # The transformation matrix for converting linear-light display-p3 colors to
212
+ # linear-light prophoto-rgb.
213
+ LINEAR_DISPLAY_P3_TO_LINEAR_PROPHOTO_RGB = [
214
+ 0.63168691934035890, 0.21393038569465722, 0.15438269496498390,
215
+ 0.08320371426648458, 0.88586513676302430, 0.03093114897049121,
216
+ -0.00127273456473881, 0.05075510433665735, 0.95051763022808140
217
+ ].freeze
218
+
219
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
220
+ # linear-light display-p3.
221
+ LINEAR_PROPHOTO_RGB_TO_LINEAR_DISPLAY_P3 = [
222
+ 1.63257560870691790, -0.37977161848259840, -0.25280399022431950,
223
+ -0.15370040233755072, 1.16670254724250140, -0.01300214490495082,
224
+ 0.01039319529676572, -0.06280731264959440, 1.05241411735282870
225
+ ].freeze
226
+
227
+ # The transformation matrix for converting linear-light display-p3 colors to
228
+ # xyz-d50.
229
+ LINEAR_DISPLAY_P3_TO_XYZ_D50 = [
230
+ 0.51514644296811600, 0.29200998206385770, 0.15713925139759397,
231
+ 0.24120032212525520, 0.69222254113138180, 0.06657713674336294,
232
+ -0.00105013914714014, 0.04187827018907460, 0.78427647146852570
233
+ ].freeze
234
+
235
+ # The transformation matrix for converting xyz-d50 colors to linear-light
236
+ # display-p3.
237
+ XYZ_D50_TO_LINEAR_DISPLAY_P3 = [
238
+ 2.40393412185549730, -0.99003044249559310, -0.39761363181465614,
239
+ -0.84227001614546880, 1.79895801610670820, 0.01604562477090472,
240
+ 0.04819381686413303, -0.09738519815446048, 1.27367136933212730
241
+ ].freeze
242
+
243
+ # The transformation matrix for converting linear-light a98-rgb colors to
244
+ # linear-light rec2020.
245
+ LINEAR_A98_RGB_TO_LINEAR_REC2020 = [
246
+ 0.87733384166365680, 0.07749370651571998, 0.04517245182062317,
247
+ 0.09662259146620378, 0.89152732024418050, 0.01185008828961569,
248
+ 0.02292106270284839, 0.04303668501067932, 0.93404225228647230
249
+ ].freeze
250
+
251
+ # The transformation matrix for converting linear-light rec2020 colors to
252
+ # linear-light a98-rgb.
253
+ LINEAR_REC2020_TO_LINEAR_A98_RGB = [
254
+ 1.15197839471591630, -0.09750305530240860, -0.05447533941350766,
255
+ -0.12455047452159074, 1.13289989712596030, -0.00834942260436947,
256
+ -0.02253038278105590, -0.04980650742838876, 1.07233689020944460
257
+ ].freeze
258
+
259
+ # The transformation matrix for converting linear-light a98-rgb colors to xyz.
260
+ LINEAR_A98_RGB_TO_XYZ_D65 = [
261
+ 0.57666904291013080, 0.18555823790654627, 0.18822864623499472,
262
+ 0.29734497525053616, 0.62736356625546600, 0.07529145849399789,
263
+ 0.02703136138641237, 0.07068885253582714, 0.99133753683763890
264
+ ].freeze
265
+
266
+ # The transformation matrix for converting xyz colors to linear-light a98-rgb.
267
+ XYZ_D65_TO_LINEAR_A98_RGB = [
268
+ 2.04158790381074600, -0.56500697427885960, -0.34473135077832950,
269
+ -0.96924363628087980, 1.87596750150772060, 0.04155505740717561,
270
+ 0.01344428063203102, -0.11836239223101823, 1.01517499439120540
271
+ ].freeze
272
+
273
+ # The transformation matrix for converting linear-light a98-rgb colors to lms.
274
+ LINEAR_A98_RGB_TO_LMS = [
275
+ 0.57643225961839410, 0.36991322261987963, 0.05365451776172635,
276
+ 0.29631647054222465, 0.59167613325218850, 0.11200739620558686,
277
+ 0.12347825101427760, 0.21949869837199862, 0.65702305061372380
278
+ ].freeze
279
+
280
+ # The transformation matrix for converting lms colors to linear-light a98-rgb.
281
+ LMS_TO_LINEAR_A98_RGB = [
282
+ 2.55403683861155660, -1.62197618068286990, 0.06793934207131327,
283
+ -1.26843797328503200, 2.60975734928768900, -0.34131937600265710,
284
+ -0.05623473593749381, -0.56704183956690610, 1.62327657550439990
285
+ ].freeze
286
+
287
+ # The transformation matrix for converting linear-light a98-rgb colors to
288
+ # linear-light prophoto-rgb.
289
+ LINEAR_A98_RGB_TO_LINEAR_PROPHOTO_RGB = [
290
+ 0.74011750180477920, 0.11327951328898105, 0.14660298490623970,
291
+ 0.13755046469802620, 0.83307708026948400, 0.02937245503248977,
292
+ 0.02359772990871766, 0.07378347703906656, 0.90261879305221580
293
+ ].freeze
294
+
295
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
296
+ # linear-light a98-rgb.
297
+ LINEAR_PROPHOTO_RGB_TO_LINEAR_A98_RGB = [
298
+ 1.38965124815152000, -0.16945907691487766, -0.22019217123664242,
299
+ -0.22882573163305037, 1.23174254119010480, -0.00291680955705449,
300
+ -0.01762544368426068, -0.09625702306122665, 1.11388246674548740
301
+ ].freeze
302
+
303
+ # The transformation matrix for converting linear-light a98-rgb colors to
304
+ # xyz-d50.
305
+ LINEAR_A98_RGB_TO_XYZ_D50 = [
306
+ 0.60977504188618140, 0.20530000261929401, 0.14922063192409227,
307
+ 0.31112461220464155, 0.62565323083468560, 0.06322215696067286,
308
+ 0.01947059555648168, 0.06087908649415867, 0.74475492045981980
309
+ ].freeze
310
+
311
+ # The transformation matrix for converting xyz-d50 colors to linear-light
312
+ # a98-rgb.
313
+ XYZ_D50_TO_LINEAR_A98_RGB = [
314
+ 1.96246703637688060, -0.61074234048150730, -0.34135809808271540,
315
+ -0.97879547655577770, 1.91625437739598840, 0.03344287339036693,
316
+ 0.02870443944957101, -0.14067486633170680, 1.34891418141379370
317
+ ].freeze
318
+
319
+ # The transformation matrix for converting linear-light rec2020 colors to xyz.
320
+ LINEAR_REC2020_TO_XYZ_D65 = [
321
+ 0.63695804830129130, 0.14461690358620838, 0.16888097516417205,
322
+ 0.26270021201126703, 0.67799807151887100, 0.05930171646986194,
323
+ 0.00000000000000000, 0.02807269304908750, 1.06098505771079090
324
+ ].freeze
325
+
326
+ # The transformation matrix for converting xyz colors to linear-light rec2020.
327
+ XYZ_D65_TO_LINEAR_REC2020 = [
328
+ 1.71665118797126760, -0.35567078377639240, -0.25336628137365980,
329
+ -0.66668435183248900, 1.61648123663493900, 0.01576854581391113,
330
+ 0.01763985744531091, -0.04277061325780865, 0.94210312123547400
331
+ ].freeze
332
+
333
+ # The transformation matrix for converting linear-light rec2020 colors to lms.
334
+ LINEAR_REC2020_TO_LMS = [
335
+ 0.61675578486544440, 0.36019840122646335, 0.02304581390809228,
336
+ 0.26513305939263670, 0.63583937206784910, 0.09902756853951408,
337
+ 0.10010262952034828, 0.20390652261661452, 0.69599084786303720
338
+ ].freeze
339
+
340
+ # The transformation matrix for converting lms colors to linear-light rec2020.
341
+ LMS_TO_LINEAR_REC2020 = [
342
+ 2.13990673043465130, -1.24638949376061800, 0.10648276332596668,
343
+ -0.88473583575776740, 2.16323093836120070, -0.27849510260343340,
344
+ -0.04857374640044396, -0.45450314971409640, 1.50307689611454040
345
+ ].freeze
346
+
347
+ # The transformation matrix for converting linear-light rec2020 colors to
348
+ # linear-light prophoto-rgb.
349
+ LINEAR_REC2020_TO_LINEAR_PROPHOTO_RGB = [
350
+ 0.83518733312972350, 0.04886884858605698, 0.11594381828421951,
351
+ 0.05403324519953363, 0.92891840856920440, 0.01704834623126199,
352
+ -0.00234203897072539, 0.03633215316169465, 0.96600988580903070
353
+ ].freeze
354
+
355
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
356
+ # linear-light rec2020.
357
+ LINEAR_PROPHOTO_RGB_TO_LINEAR_REC2020 = [
358
+ 1.20065932951740800, -0.05756805370122346, -0.14309127581618444,
359
+ -0.06994154955888504, 1.08061789759721400, -0.01067634803832895,
360
+ 0.00554147334294746, -0.04078219298657951, 1.03524071964363200
361
+ ].freeze
362
+
363
+ # The transformation matrix for converting linear-light rec2020 colors to
364
+ # xyz-d50.
365
+ LINEAR_REC2020_TO_XYZ_D50 = [
366
+ 0.67351546318827600, 0.16569726370390453, 0.12508294953738705,
367
+ 0.27905900514112060, 0.67531800574910980, 0.04562298910976962,
368
+ -0.00193242713400438, 0.02997782679282923, 0.79705920285163550
369
+ ].freeze
370
+
371
+ # The transformation matrix for converting xyz-d50 colors to linear-light
372
+ # rec2020.
373
+ XYZ_D50_TO_LINEAR_REC2020 = [
374
+ 1.64718490467176600, -0.39368189813164710, -0.23595963848828266,
375
+ -0.68266410741738180, 1.64771461274440760, 0.01281708338512084,
376
+ 0.02966887665275675, -0.06292589642970030, 1.25355782018657710
377
+ ].freeze
378
+
379
+ # The transformation matrix for converting xyz colors to lms.
380
+ XYZ_D65_TO_LMS = [
381
+ 0.81902243799670300, 0.36190626005289034, -0.12887378152098788,
382
+ 0.03298365393238846, 0.92928686158634330, 0.03614466635064235,
383
+ 0.04817718935962420, 0.26423953175273080, 0.63354782846943080
384
+ ].freeze
385
+
386
+ # The transformation matrix for converting lms colors to xyz.
387
+ LMS_TO_XYZ_D65 = [
388
+ 1.22687987584592430, -0.55781499446021710, 0.28139104566596460,
389
+ -0.04057574521480084, 1.11228680328031730, -0.07171105806551635,
390
+ -0.07637293667466007, -0.42149333240224324, 1.58692401983678180
391
+ ].freeze
392
+
393
+ # The transformation matrix for converting xyz colors to linear-light
394
+ # prophoto-rgb.
395
+ XYZ_D65_TO_LINEAR_PROPHOTO_RGB = [
396
+ 1.40319046337749790, -0.22301514479051668, -0.10160668507413790,
397
+ -0.52623840216330720, 1.48163196292346440, 0.01701879027252688,
398
+ -0.01120226528622150, 0.01824640347962099, 0.91124722749150480
399
+ ].freeze
400
+
401
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
402
+ # xyz.
403
+ LINEAR_PROPHOTO_RGB_TO_XYZ_D65 = [
404
+ 0.75559074229692100, 0.11271984265940525, 0.08214534209534540,
405
+ 0.26832184357857190, 0.71511525666179120, 0.01656289975963685,
406
+ 0.00391597276242580, -0.01293344283684181, 1.09807522083429450
407
+ ].freeze
408
+
409
+ # The transformation matrix for converting xyz colors to xyz-d50.
410
+ XYZ_D65_TO_XYZ_D50 = [
411
+ 1.04792979254499660, 0.02294687060160952, -0.05019226628920519,
412
+ 0.02962780877005567, 0.99043442675388000, -0.01707379906341879,
413
+ -0.00924304064620452, 0.01505519149029816, 0.75187428142813700
414
+ ].freeze
415
+
416
+ # The transformation matrix for converting xyz-d50 colors to xyz.
417
+ XYZ_D50_TO_XYZ_D65 = [
418
+ 0.95547342148807520, -0.02309845494876452, 0.06325924320057065,
419
+ -0.02836970933386358, 1.00999539808130410, 0.02104144119191730,
420
+ 0.01231401486448199, -0.02050764929889898, 1.33036592624212400
421
+ ].freeze
422
+
423
+ # The transformation matrix for converting lms colors to linear-light
424
+ # prophoto-rgb.
425
+ LMS_TO_LINEAR_PROPHOTO_RGB = [
426
+ 1.73835514811572070, -0.98795094275144580, 0.24959579463572504,
427
+ -0.70704940153292660, 1.93437004444013820, -0.22732064290721150,
428
+ -0.08407882206239634, -0.35754060521141334, 1.44161942727380970
429
+ ].freeze
430
+
431
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
432
+ # lms.
433
+ LINEAR_PROPHOTO_RGB_TO_LMS = [
434
+ 0.71544846056555340, 0.35279155007721186, -0.06824001064276530,
435
+ 0.27441164900156710, 0.66779764984123670, 0.05779070115719616,
436
+ 0.10978443261622942, 0.18619829115002018, 0.70401727623375040
437
+ ].freeze
438
+
439
+ # The transformation matrix for converting lms colors to xyz-d50.
440
+ LMS_TO_XYZ_D50 = [
441
+ 1.28858621817270600, -0.53787174449737450, 0.21358120275423640,
442
+ -0.00253387643187372, 1.09231679887191650, -0.08978292244004273,
443
+ -0.06937382305734124, -0.29500839894431263, 1.18948682451211420
444
+ ].freeze
445
+
446
+ # The transformation matrix for converting xyz-d50 colors to lms.
447
+ XYZ_D50_TO_LMS = [
448
+ 0.77070004204311720, 0.34924840261939616, -0.11202351884164681,
449
+ 0.00559649248368848, 0.93707234011367690, 0.06972568836252771,
450
+ 0.04633714262191069, 0.25277531574310524, 0.85145807674679600
451
+ ].freeze
452
+
453
+ # The transformation matrix for converting linear-light prophoto-rgb colors to
454
+ # xyz-d50.
455
+ LINEAR_PROPHOTO_RGB_TO_XYZ_D50 = [
456
+ 0.79776664490064230, 0.13518129740053308, 0.03134773412839220,
457
+ 0.28807482881940130, 0.71183523424187300, 0.00008993693872564,
458
+ 0.00000000000000000, 0.00000000000000000, 0.82510460251046020
459
+ ].freeze
460
+
461
+ # The transformation matrix for converting xyz-d50 colors to linear-light
462
+ # prophoto-rgb.
463
+ XYZ_D50_TO_LINEAR_PROPHOTO_RGB = [
464
+ 1.34578688164715830, -0.25557208737979464, -0.05110186497554526,
465
+ -0.54463070512490190, 1.50824774284514680, 0.02052744743642139,
466
+ 0.00000000000000000, 0.00000000000000000, 1.21196754563894520
467
+ ].freeze
468
+ end
469
+
470
+ private_constant :Conversions
471
+ end
472
+ end
473
+ 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'