5
5
* --------------------------------------------------------------------------
6
6
*/
7
7
8
- /* eslint-disable */
9
8
const getCssCustomProperties = ( ) => {
10
9
const cssCustomProperties = { }
11
- const stylesheets = new Map ( Object . entries ( document . styleSheets ) )
12
- stylesheets . forEach ( ( stylesheet ) => {
13
- console . log ( property )
14
- const rules = new Map ( Object . entries ( stylesheet . cssRules ) )
15
- rules . forEach ( ( rule ) => {
16
- if ( rule . selectorText === '.ie-custom-properties' ) {
17
- rule . style . cssText . split ( '; ' ) . forEach ( ( property ) => {
18
- console . log ( property )
19
- const name = property . split ( ': ' ) [ 0 ]
20
- const value = property . split ( ': ' ) [ 1 ]
21
- cssCustomProperties [ `--${ name } ` ] = value
22
- } )
23
- }
24
- } )
10
+ const root = Object . entries ( document . styleSheets ) . filter ( ( value ) => value [ 1 ] . cssText . substring ( 0 , ':root' . length ) === ':root' )
11
+ const rule = Object . entries ( root [ 0 ] [ 1 ] . cssRules ) . filter ( ( value ) => value [ 1 ] . selectorText === '.ie-custom-properties' )
12
+ const cssText = rule [ 0 ] [ 1 ] . style . cssText
13
+ cssText . split ( ';' ) . forEach ( ( property ) => {
14
+ if ( property ) {
15
+ const name = property . split ( ': ' ) [ 0 ]
16
+ const value = property . split ( ': ' ) [ 1 ]
17
+ cssCustomProperties [ `--${ name . trim ( ) } ` ] = value . trim ( )
18
+ }
25
19
} )
26
20
return cssCustomProperties
27
21
}
@@ -34,28 +28,22 @@ const getStyle = (property, element = document.body) => {
34
28
if ( isCustomProperty ( property ) && isIE11 ( ) ) {
35
29
const cssCustomProperties = getCssCustomProperties ( )
36
30
style = cssCustomProperties [ property ]
37
- // console.log(cssCustomProperties)
38
31
} else {
39
32
style = window . getComputedStyle ( element , null ) . getPropertyValue ( property ) . replace ( / ^ \s / , '' )
40
33
}
41
- // eslint-disable-next-line no-console
42
- // console.log(isIE11())
43
- // eslint-disable-next-line no-console
44
- // console.log(property)
45
- // eslint-disable-next-line no-console
46
- // console.log(isCustomProperty(property))
47
34
return style
48
35
}
49
36
50
- if ( ! Object . entries )
51
- Object . entries = function ( obj ) {
52
- var ownProps = Object . keys ( obj ) ,
53
- i = ownProps . length ,
54
- resArray = new Array ( i ) ; // preallocate the Array
55
- while ( i -- )
56
- resArray [ i ] = [ ownProps [ i ] , obj [ ownProps [ i ] ] ]
57
-
58
- return resArray
59
- } ;
37
+ if ( ! Object . entries ) {
38
+ Object . entries = function ( obj ) {
39
+ const ownProps = Object . keys ( obj )
40
+ let i = ownProps . length
41
+ const resArray = new Array ( i )
42
+ while ( i -- ) {
43
+ resArray [ i ] = [ ownProps [ i ] , obj [ ownProps [ i ] ] ]
44
+ }
45
+ return resArray
46
+ }
47
+ }
60
48
61
49
export default getStyle
0 commit comments