11const _ = require ( 'lodash' ) ;
22const Color = require ( 'color' ) ;
33
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+
419const normalizeColors = function ( colors , transparentFirst = true ) {
520 colors = _ . castArray ( colors ) ;
621 const unsupportedColorKeywords = [ 'inherit' , 'initial' , 'unset' , 'revert' ] ;
@@ -173,7 +188,7 @@ module.exports = function() {
173188
174189 const linearGradientUtilities = ( function ( ) {
175190 const utilities = { } ;
176- _ . forEach ( linearGradientColors , ( colors , colorKey ) => {
191+ _ . forEach ( flattenColorPalette ( linearGradientColors ) , ( colors , colorKey ) => {
177192 colors = normalizeColors ( colors , true ) ;
178193 if ( ! colors ) {
179194 return ; // continue
@@ -189,7 +204,7 @@ module.exports = function() {
189204
190205 const radialGradientUtilities = ( function ( ) {
191206 const utilities = { } ;
192- _ . forEach ( radialGradientColors , ( colors , colorKey ) => {
207+ _ . forEach ( flattenColorPalette ( radialGradientColors ) , ( colors , colorKey ) => {
193208 colors = normalizeColors ( colors , false ) ;
194209 if ( ! colors ) {
195210 return ; // continue
@@ -209,7 +224,7 @@ module.exports = function() {
209224
210225 const conicGradientUtilities = ( function ( ) {
211226 const utilities = { } ;
212- _ . forEach ( conicGradientColors , ( colors , colorKey ) => {
227+ _ . forEach ( flattenColorPalette ( conicGradientColors ) , ( colors , colorKey ) => {
213228 colors = normalizeColors ( colors , false ) ;
214229 if ( ! colors ) {
215230 return ; // continue
@@ -228,7 +243,7 @@ module.exports = function() {
228243 const repeatingLinearGradientUtilities = ( function ( ) {
229244 const utilities = { } ;
230245 _ . forEach ( repeatingLinearGradientLengths , ( length , lengthKey ) => {
231- _ . forEach ( repeatingLinearGradientColors , ( colors , colorKey ) => {
246+ _ . forEach ( flattenColorPalette ( repeatingLinearGradientColors ) , ( colors , colorKey ) => {
232247 colors = normalizeColors ( colors , true ) ;
233248 if ( ! colors ) {
234249 return ; // continue
@@ -246,7 +261,7 @@ module.exports = function() {
246261 const repeatingRadialGradientUtilities = ( function ( ) {
247262 const utilities = { } ;
248263 _ . forEach ( repeatingRadialGradientLengths , ( length , lengthKey ) => {
249- _ . forEach ( repeatingRadialGradientColors , ( colors , colorKey ) => {
264+ _ . forEach ( flattenColorPalette ( repeatingRadialGradientColors ) , ( colors , colorKey ) => {
250265 colors = normalizeColors ( colors , false ) ;
251266 if ( ! colors ) {
252267 return ; // continue
@@ -268,7 +283,7 @@ module.exports = function() {
268283 const repeatingConicGradientUtilities = ( function ( ) {
269284 const utilities = { } ;
270285 _ . forEach ( repeatingConicGradientLengths , ( length , lengthKey ) => {
271- _ . forEach ( repeatingConicGradientColors , ( colors , colorKey ) => {
286+ _ . forEach ( flattenColorPalette ( repeatingConicGradientColors ) , ( colors , colorKey ) => {
272287 colors = normalizeColors ( colors , false ) ;
273288 if ( ! colors ) {
274289 return ; // continue
0 commit comments