1
1
import { rgbTo6hex } from "../color" ;
2
- import {
3
- swiftuiColor ,
4
- swiftuiGradient ,
5
- } from "../../swiftui/builderImpl/swiftuiColor" ;
6
- import {
7
- getTailwindFromVariable ,
8
- tailwindColors ,
9
- tailwindGradient ,
10
- tailwindNearestColor ,
11
- tailwindSolidColor
12
- } from "../../tailwind/builderImpl/tailwindColor" ;
13
- import {
14
- flutterColor ,
15
- flutterGradient ,
16
- } from "../../flutter/builderImpl/flutterColor" ;
17
- import {
18
- htmlColor ,
19
- htmlGradientFromFills ,
20
- } from "../../html/builderImpl/htmlColor" ;
2
+ import { swiftuiColor , swiftuiGradient } from "../../swiftui/builderImpl/swiftuiColor" ;
3
+ import { tailwindColor , tailwindGradient } from "../../tailwind/builderImpl/tailwindColor" ;
4
+ import { flutterColor , flutterGradient } from "../../flutter/builderImpl/flutterColor" ;
5
+ import { htmlColor , htmlGradientFromFills } from "../../html/builderImpl/htmlColor" ;
21
6
import { calculateContrastRatio } from "./commonUI" ;
22
7
import { FrameworkTypes } from "../../code" ;
23
8
@@ -27,6 +12,7 @@ export type ExportSolidColor = {
27
12
exportValue : string ;
28
13
contrastWhite : number ;
29
14
contrastBlack : number ;
15
+ meta ?: string
30
16
} ;
31
17
32
18
export const retrieveGenericSolidUIColors = (
@@ -35,15 +21,18 @@ export const retrieveGenericSolidUIColors = (
35
21
const selectionColors = figma . getSelectionColors ( ) ;
36
22
if ( ! selectionColors || selectionColors . paints . length === 0 ) return [ ] ;
37
23
38
- const colorStr : Array < ExportSolidColor > = [ ] ;
24
+ const colors : Array < ExportSolidColor > = [ ] ;
39
25
selectionColors . paints . forEach ( ( paint ) => {
40
26
const fill = convertSolidColor ( paint , framework ) ;
41
27
if ( fill ) {
42
- colorStr . push ( fill ) ;
28
+ const exists = colors . find ( col => col . colorName === fill . colorName )
29
+ if ( ! exists ) {
30
+ colors . push ( fill ) ;
31
+ }
43
32
}
44
33
} ) ;
45
34
46
- return colorStr . sort ( ( a , b ) => a . hex . localeCompare ( b . hex ) ) ;
35
+ return colors . sort ( ( a , b ) => a . hex . localeCompare ( b . hex ) ) ;
47
36
} ;
48
37
49
38
const convertSolidColor = (
@@ -56,35 +45,25 @@ const convertSolidColor = (
56
45
if ( fill . type !== "SOLID" ) return null ;
57
46
58
47
const opacity = fill . opacity ?? 1.0 ;
59
- let exported = "" ;
60
- let colorName = "" ;
61
- let contrastBlack = calculateContrastRatio ( fill . color , black ) ;
62
- let contrastWhite = calculateContrastRatio ( fill . color , white ) ;
48
+ const output = {
49
+ hex : rgbTo6hex ( fill . color ) . toUpperCase ( ) ,
50
+ colorName : "" ,
51
+ exportValue : "" ,
52
+ contrastBlack : calculateContrastRatio ( fill . color , black ) ,
53
+ contrastWhite : calculateContrastRatio ( fill . color , white ) ,
54
+ } ;
63
55
64
56
if ( framework === "Flutter" ) {
65
- exported = flutterColor ( fill . color , opacity ) ;
57
+ output . exportValue = flutterColor ( fill . color , opacity ) ;
66
58
} else if ( framework === "HTML" ) {
67
- exported = htmlColor ( fill . color , opacity ) ;
59
+ output . exportValue = htmlColor ( fill . color , opacity ) ;
68
60
} else if ( framework === "Tailwind" ) {
69
- const kind = "solid" ;
70
- const hex = rgbTo6hex ( fill . color ) ;
71
- const hexNearestColor = tailwindNearestColor ( hex ) ;
72
- const colorVar = fill . boundVariables ?. color
73
- exported = tailwindSolidColor ( fill , kind ) ;
74
- colorName = colorVar
75
- ? getTailwindFromVariable ( colorVar )
76
- : tailwindColors [ hexNearestColor ] ;
61
+ Object . assign ( output , tailwindColor ( fill ) ) ;
77
62
} else if ( framework === "SwiftUI" ) {
78
- exported = swiftuiColor ( fill . color , opacity ) ;
63
+ output . exportValue = swiftuiColor ( fill . color , opacity ) ;
79
64
}
80
65
81
- return {
82
- hex : rgbTo6hex ( fill . color ) . toUpperCase ( ) ,
83
- colorName,
84
- exportValue : exported ,
85
- contrastBlack,
86
- contrastWhite,
87
- } ;
66
+ return output ;
88
67
} ;
89
68
90
69
type ExportLinearGradient = { cssPreview : string ; exportValue : string } ;
@@ -97,24 +76,24 @@ export const retrieveGenericLinearGradients = (
97
76
98
77
selectionColors ?. paints . forEach ( ( paint ) => {
99
78
if ( paint . type === "GRADIENT_LINEAR" ) {
100
- let exported = "" ;
79
+ let exportValue = "" ;
101
80
switch ( framework ) {
102
81
case "Flutter" :
103
- exported = flutterGradient ( paint ) ;
82
+ exportValue = flutterGradient ( paint ) ;
104
83
break ;
105
84
case "HTML" :
106
- exported = htmlGradientFromFills ( [ paint ] ) ;
85
+ exportValue = htmlGradientFromFills ( [ paint ] ) ;
107
86
break ;
108
87
case "Tailwind" :
109
- exported = tailwindGradient ( paint ) ;
88
+ exportValue = tailwindGradient ( paint ) ;
110
89
break ;
111
90
case "SwiftUI" :
112
- exported = swiftuiGradient ( paint ) ;
91
+ exportValue = swiftuiGradient ( paint ) ;
113
92
break ;
114
93
}
115
94
colorStr . push ( {
116
95
cssPreview : htmlGradientFromFills ( [ paint ] ) ,
117
- exportValue : exported ,
96
+ exportValue,
118
97
} ) ;
119
98
}
120
99
} ) ;
0 commit comments