1
+ const warnings = new Set ( ) ;
2
+
1
3
const getThemeMetadata = ( ) => {
2
4
// Check if the class was already applied, most commonly to the link/style tag with the CSS Variables
3
5
let el = document . querySelector ( ".sapThemeMetaData-Base-baseLib" ) || document . querySelector ( ".sapThemeMetaData-UI5-sap-ui-core" ) ;
@@ -7,10 +9,18 @@ const getThemeMetadata = () => {
7
9
8
10
el = document . createElement ( "span" ) ;
9
11
el . style . display = "none" ;
12
+
13
+ // Try with sapThemeMetaData-Base-baseLib first
10
14
el . classList . add ( "sapThemeMetaData-Base-baseLib" ) ;
11
- el . classList . add ( "sapThemeMetaData-UI5-sap-ui-core" ) ;
12
15
document . body . appendChild ( el ) ;
13
- const metadata = getComputedStyle ( el ) . backgroundImage ;
16
+ let metadata = getComputedStyle ( el ) . backgroundImage ;
17
+
18
+ // Try with sapThemeMetaData-UI5-sap-ui-core only if the previous selector was not found
19
+ if ( metadata === "none" ) {
20
+ el . classList . add ( "sapThemeMetaData-UI5-sap-ui-core" ) ;
21
+ metadata = getComputedStyle ( el ) . backgroundImage ;
22
+ }
23
+
14
24
document . body . removeChild ( el ) ;
15
25
16
26
return metadata ;
@@ -25,14 +35,20 @@ const parseThemeMetadata = metadataString => {
25
35
try {
26
36
paramsString = decodeURIComponent ( paramsString ) ;
27
37
} catch ( ex ) {
28
- console . warn ( "Malformed theme metadata string, unable to decodeURIComponent" ) ; // eslint-disable-line
38
+ if ( ! warnings . has ( "decode" ) ) {
39
+ console . warn ( "Malformed theme metadata string, unable to decodeURIComponent" ) ; // eslint-disable-line
40
+ warnings . add ( "decode" ) ;
41
+ }
29
42
return ;
30
43
}
31
44
}
32
45
try {
33
46
return JSON . parse ( paramsString ) ;
34
47
} catch ( ex ) {
35
- console . warn ( "Malformed theme metadata string, unable to parse JSON" ) ; // eslint-disable-line
48
+ if ( ! warnings . has ( "parse" ) ) {
49
+ console . warn ( "Malformed theme metadata string, unable to parse JSON" ) ; // eslint-disable-line
50
+ warnings . add ( "parse" ) ;
51
+ }
36
52
}
37
53
}
38
54
} ;
@@ -45,7 +61,10 @@ const processThemeMetadata = metadata => {
45
61
themeName = metadata . Path . match ( / \. ( [ ^ . ] + ) \. c s s _ v a r i a b l e s $ / ) [ 1 ] ;
46
62
baseThemeName = metadata . Extends [ 0 ] ;
47
63
} catch ( ex ) {
48
- console . warn ( "Malformed theme metadata Object" , metadata ) ; // eslint-disable-line
64
+ if ( ! warnings . has ( "object" ) ) {
65
+ console . warn ( "Malformed theme metadata Object" , metadata ) ; // eslint-disable-line
66
+ warnings . add ( "object" ) ;
67
+ }
49
68
return ;
50
69
}
51
70
0 commit comments