@@ -89,15 +89,16 @@ export function to_class(value, hash, directives) {
89
89
* @param {boolean } important
90
90
*/
91
91
function append_styles ( styles , important = false ) {
92
- let separator = important ? ' !important;' : ';' ;
93
- let css = '' ;
92
+ var separator = important ? ' !important;' : ';' ;
93
+ var css = '' ;
94
94
95
- for ( const key in styles ) {
96
- const value = styles [ key ] ;
95
+ for ( var key in styles ) {
96
+ var value = styles [ key ] ;
97
97
if ( value != null && value !== '' ) {
98
98
css += ' ' + key + ': ' + value + separator ;
99
99
}
100
100
}
101
+
101
102
return css ;
102
103
}
103
104
@@ -114,22 +115,26 @@ function to_css_name(name) {
114
115
115
116
/**
116
117
* @param {any } value
117
- * @param {Record<string,any>| [Record<string,any>,Record<string,any>] } [styles]
118
- * @returns {string| null }
118
+ * @param {Record<string, any> | [Record<string, any>, Record<string, any>] } [styles]
119
+ * @returns {string | null }
119
120
*/
120
121
export function to_style ( value , styles ) {
121
122
if ( styles ) {
122
123
var new_style = '' ;
124
+
123
125
/** @type {Record<string,any> | undefined } */
124
126
var normal_styles ;
127
+
125
128
/** @type {Record<string,any> | undefined } */
126
129
var important_styles ;
130
+
127
131
if ( Array . isArray ( styles ) ) {
128
132
normal_styles = styles [ 0 ] ;
129
133
important_styles = styles [ 1 ] ;
130
134
} else {
131
135
normal_styles = styles ;
132
136
}
137
+
133
138
if ( value ) {
134
139
value = String ( value )
135
140
. replaceAll ( / \s * \/ \* .* ?\* \/ \s * / g, '' )
@@ -141,6 +146,7 @@ export function to_style(value, styles) {
141
146
var in_comment = false ;
142
147
143
148
var reserved_names = [ ] ;
149
+
144
150
if ( normal_styles ) {
145
151
reserved_names . push ( ...Object . keys ( normal_styles ) . map ( to_css_name ) ) ;
146
152
}
@@ -150,6 +156,7 @@ export function to_style(value, styles) {
150
156
151
157
var start_index = 0 ;
152
158
var name_index = - 1 ;
159
+
153
160
const len = value . length ;
154
161
for ( var i = 0 ; i < len ; i ++ ) {
155
162
var c = value [ i ] ;
@@ -171,20 +178,24 @@ export function to_style(value, styles) {
171
178
} else if ( c === ')' ) {
172
179
in_apo -- ;
173
180
}
181
+
174
182
if ( ! in_comment && in_str === false && in_apo === 0 ) {
175
- if ( c === ':' && name_index < 0 ) {
183
+ if ( c === ':' && name_index === - 1 ) {
176
184
name_index = i ;
177
185
} else if ( c === ';' || i === len - 1 ) {
178
- if ( name_index > 0 ) {
179
- let name = to_css_name ( value . substring ( start_index , name_index ) . trim ( ) ) ;
186
+ if ( name_index !== - 1 ) {
187
+ var name = to_css_name ( value . substring ( start_index , name_index ) . trim ( ) ) ;
188
+
180
189
if ( ! reserved_names . includes ( name ) ) {
181
190
if ( c !== ';' ) {
182
191
i ++ ;
183
192
}
184
- const property = value . substring ( start_index , i ) . trim ( ) ;
193
+
194
+ var property = value . substring ( start_index , i ) . trim ( ) ;
185
195
new_style += ' ' + property + ';' ;
186
196
}
187
197
}
198
+
188
199
start_index = i + 1 ;
189
200
name_index = - 1 ;
190
201
}
@@ -195,13 +206,14 @@ export function to_style(value, styles) {
195
206
if ( normal_styles ) {
196
207
new_style += append_styles ( normal_styles ) ;
197
208
}
209
+
198
210
if ( important_styles ) {
199
211
new_style += append_styles ( important_styles , true ) ;
200
212
}
213
+
201
214
new_style = new_style . trim ( ) ;
202
215
return new_style === '' ? null : new_style ;
203
- } else if ( value == null ) {
204
- return null ;
205
216
}
206
- return String ( value ) ;
217
+
218
+ return value == null ? null : String ( value ) ;
207
219
}
0 commit comments