@@ -69,15 +69,15 @@ export class StyleUtils {
69
69
* Find the DOM element's raw attribute value (if any)
70
70
*/
71
71
lookupAttributeValue ( element : HTMLElement , attribute : string ) : string {
72
- return element . getAttribute ( attribute ) || '' ;
72
+ return element . getAttribute ( attribute ) ?? '' ;
73
73
}
74
74
75
75
/**
76
76
* Find the DOM element's inline style value (if any)
77
77
*/
78
78
lookupInlineStyle ( element : HTMLElement , styleName : string ) : string {
79
79
return isPlatformBrowser ( this . _platformId ) ?
80
- element . style . getPropertyValue ( styleName ) : this . _getServerStyle ( element , styleName ) ;
80
+ element . style . getPropertyValue ( styleName ) : getServerStyle ( element , styleName ) ;
81
81
}
82
82
83
83
/**
@@ -121,56 +121,56 @@ export class StyleUtils {
121
121
value = value ? value + '' : '' ;
122
122
if ( isPlatformBrowser ( this . _platformId ) || ! this . _serverModuleLoaded ) {
123
123
isPlatformBrowser ( this . _platformId ) ?
124
- element . style . setProperty ( key , value ) : this . _setServerStyle ( element , key , value ) ;
124
+ element . style . setProperty ( key , value ) : setServerStyle ( element , key , value ) ;
125
125
} else {
126
126
this . _serverStylesheet . addStyleToElement ( element , key , value ) ;
127
127
}
128
128
}
129
129
} ) ;
130
130
}
131
+ }
131
132
132
- private _setServerStyle ( element : any , styleName : string , styleValue ?: string | null ) {
133
- styleName = styleName . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, '$1-$2' ) . toLowerCase ( ) ;
134
- const styleMap = this . _readStyleAttribute ( element ) ;
135
- styleMap [ styleName ] = styleValue || '' ;
136
- this . _writeStyleAttribute ( element , styleMap ) ;
137
- }
133
+ function getServerStyle ( element : any , styleName : string ) : string {
134
+ const styleMap = readStyleAttribute ( element ) ;
135
+ return styleMap [ styleName ] ?? '' ;
136
+ }
138
137
139
- private _getServerStyle ( element : any , styleName : string ) : string {
140
- const styleMap = this . _readStyleAttribute ( element ) ;
141
- return styleMap [ styleName ] || '' ;
142
- }
138
+ function setServerStyle ( element : any , styleName : string , styleValue ?: string | null ) {
139
+ styleName = styleName . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, '$1-$2' ) . toLowerCase ( ) ;
140
+ const styleMap = readStyleAttribute ( element ) ;
141
+ styleMap [ styleName ] = styleValue ?? '' ;
142
+ writeStyleAttribute ( element , styleMap ) ;
143
+ }
143
144
144
- private _readStyleAttribute ( element : any ) : { [ name : string ] : string } {
145
- const styleMap : { [ name : string ] : string } = { } ;
146
- const styleAttribute = element . getAttribute ( 'style' ) ;
147
- if ( styleAttribute ) {
148
- const styleList = styleAttribute . split ( / ; + / g) ;
149
- for ( let i = 0 ; i < styleList . length ; i ++ ) {
150
- const style = styleList [ i ] . trim ( ) ;
151
- if ( style . length > 0 ) {
152
- const colonIndex = style . indexOf ( ':' ) ;
153
- if ( colonIndex === - 1 ) {
154
- throw new Error ( `Invalid CSS style: ${ style } ` ) ;
155
- }
156
- const name = style . substr ( 0 , colonIndex ) . trim ( ) ;
157
- styleMap [ name ] = style . substr ( colonIndex + 1 ) . trim ( ) ;
158
- }
159
- }
145
+ function writeStyleAttribute ( element : any , styleMap : { [ name : string ] : string } ) {
146
+ let styleAttrValue = '' ;
147
+ for ( const key in styleMap ) {
148
+ const newValue = styleMap [ key ] ;
149
+ if ( newValue ) {
150
+ styleAttrValue += `${ key } :${ styleMap [ key ] } ;` ;
160
151
}
161
- return styleMap ;
162
152
}
153
+ element . setAttribute ( 'style' , styleAttrValue ) ;
154
+ }
163
155
164
- private _writeStyleAttribute ( element : any , styleMap : { [ name : string ] : string } ) {
165
- let styleAttrValue = '' ;
166
- for ( const key in styleMap ) {
167
- const newValue = styleMap [ key ] ;
168
- if ( newValue ) {
169
- styleAttrValue += key + ':' + styleMap [ key ] + ';' ;
156
+ function readStyleAttribute ( element : any ) : { [ name : string ] : string } {
157
+ const styleMap : { [ name : string ] : string } = { } ;
158
+ const styleAttribute = element . getAttribute ( 'style' ) ;
159
+ if ( styleAttribute ) {
160
+ const styleList = styleAttribute . split ( / ; + / g) ;
161
+ for ( let i = 0 ; i < styleList . length ; i ++ ) {
162
+ const style = styleList [ i ] . trim ( ) ;
163
+ if ( style . length > 0 ) {
164
+ const colonIndex = style . indexOf ( ':' ) ;
165
+ if ( colonIndex === - 1 ) {
166
+ throw new Error ( `Invalid CSS style: ${ style } ` ) ;
167
+ }
168
+ const name = style . substr ( 0 , colonIndex ) . trim ( ) ;
169
+ styleMap [ name ] = style . substr ( colonIndex + 1 ) . trim ( ) ;
170
170
}
171
171
}
172
- element . setAttribute ( 'style' , styleAttrValue ) ;
173
172
}
173
+ return styleMap ;
174
174
}
175
175
176
176
/**
0 commit comments