1
1
const _ = require ( 'lodash' ) ;
2
2
const Color = require ( 'color' ) ;
3
3
4
+ const flattenColorPalette = function ( colors ) {
5
+ return _ ( colors )
6
+ . flatMap ( ( color , name ) => {
7
+ if ( ! _ . isPlainObject ( color ) ) {
8
+ return [ [ name , color ] ] ;
9
+ }
10
+ return _ . map ( color , ( value , key ) => {
11
+ const suffix = key === 'default' ? '' : `-${ key } ` ;
12
+ return [ `${ name } ${ suffix } ` , value ] ;
13
+ } ) ;
14
+ } )
15
+ . fromPairs ( )
16
+ . value ( ) ;
17
+ } ;
18
+
4
19
const normalizeColors = function ( colors , transparentFirst = true ) {
5
20
colors = _ . castArray ( colors ) ;
6
21
const unsupportedColorKeywords = [ 'inherit' , 'initial' , 'unset' , 'revert' ] ;
@@ -173,7 +188,7 @@ module.exports = function() {
173
188
174
189
const linearGradientUtilities = ( function ( ) {
175
190
const utilities = { } ;
176
- _ . forEach ( linearGradientColors , ( colors , colorKey ) => {
191
+ _ . forEach ( flattenColorPalette ( linearGradientColors ) , ( colors , colorKey ) => {
177
192
colors = normalizeColors ( colors , true ) ;
178
193
if ( ! colors ) {
179
194
return ; // continue
@@ -189,7 +204,7 @@ module.exports = function() {
189
204
190
205
const radialGradientUtilities = ( function ( ) {
191
206
const utilities = { } ;
192
- _ . forEach ( radialGradientColors , ( colors , colorKey ) => {
207
+ _ . forEach ( flattenColorPalette ( radialGradientColors ) , ( colors , colorKey ) => {
193
208
colors = normalizeColors ( colors , false ) ;
194
209
if ( ! colors ) {
195
210
return ; // continue
@@ -209,7 +224,7 @@ module.exports = function() {
209
224
210
225
const conicGradientUtilities = ( function ( ) {
211
226
const utilities = { } ;
212
- _ . forEach ( conicGradientColors , ( colors , colorKey ) => {
227
+ _ . forEach ( flattenColorPalette ( conicGradientColors ) , ( colors , colorKey ) => {
213
228
colors = normalizeColors ( colors , false ) ;
214
229
if ( ! colors ) {
215
230
return ; // continue
@@ -228,7 +243,7 @@ module.exports = function() {
228
243
const repeatingLinearGradientUtilities = ( function ( ) {
229
244
const utilities = { } ;
230
245
_ . forEach ( repeatingLinearGradientLengths , ( length , lengthKey ) => {
231
- _ . forEach ( repeatingLinearGradientColors , ( colors , colorKey ) => {
246
+ _ . forEach ( flattenColorPalette ( repeatingLinearGradientColors ) , ( colors , colorKey ) => {
232
247
colors = normalizeColors ( colors , true ) ;
233
248
if ( ! colors ) {
234
249
return ; // continue
@@ -246,7 +261,7 @@ module.exports = function() {
246
261
const repeatingRadialGradientUtilities = ( function ( ) {
247
262
const utilities = { } ;
248
263
_ . forEach ( repeatingRadialGradientLengths , ( length , lengthKey ) => {
249
- _ . forEach ( repeatingRadialGradientColors , ( colors , colorKey ) => {
264
+ _ . forEach ( flattenColorPalette ( repeatingRadialGradientColors ) , ( colors , colorKey ) => {
250
265
colors = normalizeColors ( colors , false ) ;
251
266
if ( ! colors ) {
252
267
return ; // continue
@@ -268,7 +283,7 @@ module.exports = function() {
268
283
const repeatingConicGradientUtilities = ( function ( ) {
269
284
const utilities = { } ;
270
285
_ . forEach ( repeatingConicGradientLengths , ( length , lengthKey ) => {
271
- _ . forEach ( repeatingConicGradientColors , ( colors , colorKey ) => {
286
+ _ . forEach ( flattenColorPalette ( repeatingConicGradientColors ) , ( colors , colorKey ) => {
272
287
colors = normalizeColors ( colors , false ) ;
273
288
if ( ! colors ) {
274
289
return ; // continue
0 commit comments