@@ -109,11 +109,11 @@ export class CustomizeMailingPlugin extends Plugin {
109
109
if ( currentValue === "" && defaultValue !== "" ) {
110
110
varRule . style . setProperty ( variable , defaultValue ) ;
111
111
}
112
- this . refreshMailingVariableSelector ( variable ) ;
112
+ this . refreshMailingVariableSelector ( variable , true ) ;
113
113
}
114
114
}
115
115
116
- refreshMailingVariableSelector ( variable ) {
116
+ refreshMailingVariableSelector ( variable , isSetup = false ) {
117
117
const options = CUSTOMIZE_MAILING_VARIABLES [ variable ] ;
118
118
const currentValue = this . getVariableValue ( variable ) ;
119
119
let value = "" ;
@@ -124,11 +124,37 @@ export class CustomizeMailingPlugin extends Plugin {
124
124
const rule = this . getRule ( selector ) ;
125
125
for ( const property of options . properties ) {
126
126
const important = PRIORITY_STYLES [ selector ] ?. has ( property ) ? "important" : "" ;
127
- rule . style . setProperty ( property , value , important ) ;
127
+ if ( isSetup && rule . style . getPropertyValue ( property ) ) {
128
+ this . setVariable ( variable , rule . style . getPropertyValue ( property ) )
129
+ } else {
130
+ rule . style . setProperty ( property , value , important ) ;
131
+ }
128
132
}
129
133
}
130
134
}
131
135
136
+ getVariableName ( selector , property ) {
137
+ let prefix = "text" ;
138
+ if ( selector . includes ( "h1" ) ) {
139
+ prefix = "h1" ;
140
+ } else if ( selector . includes ( "h2" ) ) {
141
+ prefix = "h2" ;
142
+ } else if ( selector . includes ( "h3" ) ) {
143
+ prefix = "h3" ;
144
+ } else if ( / ( ( \b p \b ) | ( \b p > \* ) | ( \b l i \b ) | ( \b l i > \* ) ) / . test ( selector ) ) {
145
+ prefix = "text" ;
146
+ } else if ( / ( a \. .* \. b t n \- .* \- ? p r i m a r y ) / . test ( selector ) ) {
147
+ prefix = "btn-primary" ;
148
+ } else if ( / ( a \. .* \. b t n \- .* \- ? s e c o n d a r y ) / . test ( selector ) ) {
149
+ prefix = "btn-secondary" ;
150
+ } else if ( / ( ( a : n o t \( \. b t n \) ) | ( a \. b t n \. b t n \- l i n k ) ) / . test ( selector ) ) {
151
+ prefix = "link" ;
152
+ } else if ( / h r / . test ( selector ) ) {
153
+ prefix = "separator"
154
+ }
155
+ return `--${ prefix } -${ property } ` ;
156
+ }
157
+
132
158
parseDesignElement ( styleEl ) {
133
159
const rules = [ ...styleEl . sheet . cssRules ] ;
134
160
for ( const rule of rules ) {
@@ -208,6 +234,8 @@ export class CustomizeMailingPlugin extends Plugin {
208
234
ruleStyle . getPropertyValue ( property ) ,
209
235
ruleStyle . getPropertyPriority ( property )
210
236
) ;
237
+ const variable = this . getVariableName ( selector , property )
238
+ this . getRule ( this . cssPrefix ) . style . setProperty ( variable , ruleStyle . getPropertyValue ( property ) ) ;
211
239
}
212
240
}
213
241
}
0 commit comments