@@ -110,12 +110,12 @@ export class CustomizeMailingPlugin extends Plugin {
110
110
if ( currentValue === "" && defaultValue !== "" ) {
111
111
varRule . style . setProperty ( variable , defaultValue ) ;
112
112
}
113
- this . refreshMailingVariableSelector ( variable ) ;
113
+ this . refreshMailingVariableSelector ( variable , true ) ;
114
114
}
115
115
console . log ( this . toRemove ) ;
116
116
}
117
117
118
- refreshMailingVariableSelector ( variable ) {
118
+ refreshMailingVariableSelector ( variable , isSetup = false ) {
119
119
const toRemove = { } ;
120
120
this . toRemove [ variable ] = toRemove ;
121
121
const options = CUSTOMIZE_MAILING_VARIABLES [ variable ] ;
@@ -128,7 +128,11 @@ export class CustomizeMailingPlugin extends Plugin {
128
128
const rule = this . getRule ( selector ) ;
129
129
for ( const property of options . properties ) {
130
130
const important = PRIORITY_STYLES [ selector ] ?. has ( property ) ? "important" : "" ;
131
- rule . style . setProperty ( property , value , important ) ;
131
+ if ( isSetup && rule . style . getPropertyValue ( property ) ) {
132
+ this . setVariable ( variable , rule . style . getPropertyValue ( property ) )
133
+ } else {
134
+ rule . style . setProperty ( property , value , important ) ;
135
+ }
132
136
}
133
137
}
134
138
// toremove
@@ -142,6 +146,28 @@ export class CustomizeMailingPlugin extends Plugin {
142
146
}
143
147
}
144
148
149
+ getVariableName ( selector , property ) {
150
+ let prefix = "text" ;
151
+ if ( selector . includes ( "h1" ) ) {
152
+ prefix = "h1" ;
153
+ } else if ( selector . includes ( "h2" ) ) {
154
+ prefix = "h2" ;
155
+ } else if ( selector . includes ( "h3" ) ) {
156
+ prefix = "h3" ;
157
+ } else if ( / ( ( \b p \b ) | ( \b p > \* ) | ( \b l i \b ) | ( \b l i > \* ) ) / . test ( selector ) ) {
158
+ prefix = "text" ;
159
+ } else if ( / ( a \. .* \. b t n \- .* \- ? p r i m a r y ) / . test ( selector ) ) {
160
+ prefix = "btn-primary" ;
161
+ } else if ( / ( a \. .* \. b t n \- .* \- ? s e c o n d a r y ) / . test ( selector ) ) {
162
+ prefix = "btn-secondary" ;
163
+ } else if ( / ( ( a : n o t \( \. b t n \) ) | ( a \. b t n \. b t n \- l i n k ) ) / . test ( selector ) ) {
164
+ prefix = "link" ;
165
+ } else if ( / h r / . test ( selector ) ) {
166
+ prefix = "separator"
167
+ }
168
+ return `--${ prefix } -${ property } ` ;
169
+ }
170
+
145
171
parseDesignElement ( styleEl ) {
146
172
const rules = [ ...styleEl . sheet . cssRules ] ;
147
173
for ( const rule of rules ) {
@@ -221,6 +247,8 @@ export class CustomizeMailingPlugin extends Plugin {
221
247
ruleStyle . getPropertyValue ( property ) ,
222
248
ruleStyle . getPropertyPriority ( property )
223
249
) ;
250
+ const variable = this . getVariableName ( selector , property )
251
+ this . getRule ( this . cssPrefix ) . style . setProperty ( variable , ruleStyle . getPropertyValue ( property ) ) ;
224
252
}
225
253
}
226
254
}
0 commit comments