@@ -33,12 +33,12 @@ const expandHexColor = (hexColor) => {
33
33
return hexColor ;
34
34
} ;
35
35
const prefixOrder = {
36
- brand : 1 ,
37
- neutral : 2 ,
38
- critical : 3 ,
39
- informational : 4 ,
40
- successful : 5 ,
41
- warning : 6 ,
36
+ "db- brand" : 1 ,
37
+ "db- neutral" : 2 ,
38
+ "db- critical" : 3 ,
39
+ "db- informational" : 4 ,
40
+ "db- successful" : 5 ,
41
+ "db- warning" : 6 ,
42
42
} ;
43
43
44
44
const createSwatch = ( document , name , hexColor , alpha ) => {
@@ -75,13 +75,11 @@ const generateColorName = (theme, colorName) => {
75
75
let prefix , color , state ;
76
76
[ prefix , color , state ] = colorName . split ( "/" ) ;
77
77
78
- const capitalizedTheme = capitalize ( theme ) ;
79
78
const capitalizedColor = capitalize ( color ) ;
80
- const capitalizedState = capitalizeState ( state ) ;
81
79
82
80
function getFormattedCount ( prefixOrder , prefix ) {
83
81
let count ;
84
- if ( prefixOrder . hasOwnProperty ( prefix ) ) {
82
+ if ( prefixOrder . hasOwnProperty ( [ prefix ] ) ) {
85
83
count = prefixOrder [ prefix ] ;
86
84
} else {
87
85
count = Object . keys ( prefixOrder ) . length + 1 ;
@@ -91,52 +89,43 @@ const generateColorName = (theme, colorName) => {
91
89
}
92
90
const formattedCount = getFormattedCount ( prefixOrder , prefix ) ;
93
91
94
- const componentName = `${ formattedCount } --${ capitalize ( prefix ) } ` ;
92
+ const componentName = `${ formattedCount } --${ prefix } ` ;
95
93
96
- if ( color . includes ( "On" ) ) {
94
+ if ( color === "on" ) {
97
95
const parts = colorName . split ( "/" ) . slice ( 0 ) ;
98
96
const on = parts [ 1 ] ;
99
97
color = parts [ 2 ] ;
100
98
if ( parts . length > 2 ) {
101
- state = capitalizeState ( parts [ 3 ] ) ;
99
+ state = parts [ 3 ] ;
102
100
}
103
- if ( parts [ 2 ] . includes ( "01-Enabled" ) ) {
104
- state = capitalizeState ( parts [ 2 ] ) ;
101
+ if ( colorName === "db-brand/on/enabled" ) {
102
+ state = parts [ 2 ] ;
105
103
}
106
104
if ( color === "bg-weak" ) {
107
- return `${ capitalizedTheme } /${ componentName } /${ on } /Background/Weak--${ state } ` ;
108
- } else if ( color === "bg" ) {
109
- return `${ capitalizedTheme } /${ componentName } /${ on } /Background/${ state } ` ;
110
- } else if ( color === "contrast" ) {
111
- return `${ capitalizedTheme } /${ componentName } /${ on } /Contrast/${ state } ` ;
112
- }
113
- return `${ capitalizedTheme } /${ componentName } /${ on } /${ state } ` ;
105
+ return `${ theme } /${ componentName } /${ on } /bg/weak-${ state } ` ;
106
+ } else if ( color === "bg" || color === "contrast" ) {
107
+ return `${ theme } /${ componentName } /${ on } /${ color } /${ state } ` ;
108
+ }
109
+ return `${ theme } /${ componentName } /${ on } /${ state } ` ;
114
110
}
115
- if ( color . includes ( "bg" ) ) {
116
- if ( color === "bg-lvl-1" ) {
117
- return `${ capitalizedTheme } /${ componentName } /Background/Level-1--${ capitalizedState } ` ;
118
- } else if ( color === "bg-lvl-2" ) {
119
- return `${ capitalizedTheme } /${ componentName } /Background/Level-2--${ capitalizedState } ` ;
120
- } else if ( color === "bg-lvl-3" ) {
121
- return `${ capitalizedTheme } /${ componentName } /Background/Level-3--${ capitalizedState } ` ;
122
- } else if ( color . includes ( "bg-transparent" ) ) {
123
- if ( color === "bg-transparent-full" ) {
124
- return `${ capitalizedTheme } /${ componentName } /Background-Transparent/Full--${ capitalizedState } ` ;
125
- } else {
126
- return `${ capitalizedTheme } /${ componentName } /Background-Transparent/Semi--${ capitalizedState } ` ;
127
- }
111
+
112
+ if ( color . includes ( "bg-lvl-" ) ) {
113
+ const extractedColor = color . split ( "bg-" ) [ 1 ] ;
114
+ return `${ theme } /${ componentName } /bg/${ extractedColor } -${ state } ` ;
115
+ } else if ( color . includes ( "bg-transparent" ) ) {
116
+ if ( color === "bg-transparent-full" ) {
117
+ return `${ theme } /${ componentName } /bg-transparent/full-${ state } ` ;
118
+ } else if ( color === "bg-transparent-semi" ) {
119
+ return `${ theme } /${ componentName } /bg-transparent/semi-${ state } ` ;
120
+ } else {
121
+ return `${ theme } /${ componentName } /bg-transparent/${ state } ` ;
128
122
}
129
123
}
130
- if ( color . includes ( "contrast" ) ) {
131
- if ( color === "contrast-high" ) {
132
- return `${ capitalizedTheme } /${ componentName } /Contrast-High/${ capitalizedState } ` ;
133
- }
134
- if ( color === "contrast-low" ) {
135
- return `${ capitalizedTheme } /${ componentName } /Contrast-Low/${ capitalizedState } ` ;
136
- }
124
+
125
+ if ( ! state ) {
126
+ return `${ theme } /${ componentName } /${ color } ` ;
137
127
}
138
-
139
- return `${ capitalizedTheme } /${ componentName } /${ capitalizedColor } /${ capitalizedState } ` ;
128
+ return `${ theme } /${ componentName } /${ color } /${ state } ` ;
140
129
} ;
141
130
142
131
const createArtboard = (
@@ -185,7 +174,7 @@ const importThemes = async () => {
185
174
const response = await sketch . UI . getInputFromUser (
186
175
"Select themes to import (Light/Dark/Both):" ,
187
176
{
188
- initialValue : "Both " ,
177
+ initialValue : "Light " ,
189
178
} ,
190
179
async ( err , value ) => {
191
180
if ( err ) {
@@ -208,7 +197,7 @@ const importThemes = async () => {
208
197
const alpha = 1 - transparencyPercentage / 100 ;
209
198
210
199
const newNames = generateColorName ( theme , colorName ) ;
211
-
200
+ //console.log(newNames);
212
201
createSwatch ( document , newNames , hexValue , alpha ) ;
213
202
}
214
203
} ;
0 commit comments