1
- using System ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
2
+ using System . Security ;
3
3
using System . Text ;
4
4
5
5
namespace BlazorStyled . Internal
@@ -18,16 +18,21 @@ public ParsedClass(string name, string body)
18
18
IsDynamic = false ;
19
19
Name = name ;
20
20
}
21
- if ( IsMediaQuery )
21
+ if ( ( IsMediaQuery && name . Contains ( "&" ) ) || ( IsMediaQuery & body . Contains ( "{" ) ) || IsKeyframes )
22
22
{
23
23
ChildClasses = new List < ParsedClass > ( ) ;
24
+ body = null ;
24
25
}
25
- if ( body . EndsWith ( "} }" ) || body . EndsWith ( "}}" ) )
26
+ else if ( IsMediaQuery )
27
+ {
28
+ ChildClasses = new List < ParsedClass > ( ) ;
29
+ }
30
+ if ( body != null && ( body . EndsWith ( "} }" ) || body . EndsWith ( "}}" ) ) )
26
31
{
27
32
Declarations = ParseDeclerations ( body . Substring ( 0 , body . Length - 1 ) ) ;
28
33
IsLastChild = true ;
29
34
}
30
- else if ( body == "{" )
35
+ else if ( body != null && body == "{" ) //TODO: This might not be needed anymore
31
36
{
32
37
ChildClasses = new List < ParsedClass > ( ) ;
33
38
}
@@ -50,6 +55,7 @@ public ParsedClass(string importUri)
50
55
51
56
private string ParseDeclerations ( string body )
52
57
{
58
+ if ( body == null ) return null ;
53
59
string str = body . Trim ( ) ;
54
60
if ( str . Contains ( "label" ) )
55
61
{
@@ -60,40 +66,21 @@ private string ParseDeclerations(string body)
60
66
if ( end != - 1 )
61
67
{
62
68
Label = str . Substring ( start + 1 , end - start - 1 ) . Trim ( ) ;
63
- str = str . Substring ( 0 , start - 5 ) + str . Substring ( end , str . Length - end - 1 ) ;
69
+ str = str . Substring ( 0 , start - 5 ) + str . Substring ( end + 1 , str . Length - end - 1 ) . Trim ( ) ;
64
70
}
65
71
}
66
72
}
67
73
return str . StartsWith ( "{" ) && str . EndsWith ( "}" ) ? str . Substring ( 1 , str . Trim ( ) . Length - 2 ) . Trim ( ) : str ;
68
74
}
69
75
70
- private Tuple < string , string > ParseDeclaration ( string input )
71
- {
72
- if ( string . IsNullOrEmpty ( input ) )
73
- {
74
- return null ;
75
- }
76
-
77
- try
78
- {
79
- string property = input . Substring ( 0 , input . IndexOf ( ':' ) ) . ToLower ( ) . Trim ( ) ;
80
- string value = input . Substring ( input . IndexOf ( ':' ) + 1 ) . Trim ( ) ;
81
- return new Tuple < string , string > ( property , value ) ;
82
- }
83
- catch ( Exception e )
84
- {
85
- throw StyledException . GetException ( input , "This is likely cause by a missing ':' character" , e ) ;
86
- }
87
- }
88
-
89
76
public string Name { get ; set ; }
90
77
public string Label { get ; private set ; }
91
78
public IList < ParsedClass > ChildClasses { get ; private set ; }
92
79
public bool IsDynamic { get ; private set ; }
93
80
public bool IsParent => ChildClasses != null ;
94
81
public bool IsMediaQuery => ! IsDynamic && Name . IndexOf ( "@media" ) != - 1 ;
95
82
public bool IsFontface => ! IsDynamic && Name . IndexOf ( "@font-face" ) != - 1 ;
96
- public bool IsKeyframes => ! IsDynamic && IsParent && Name . IndexOf ( "@keyframe" ) != - 1 ;
83
+ public bool IsKeyframes => ! IsDynamic && Name . IndexOf ( "@keyframe" ) != - 1 ;
97
84
public bool IsElement => ! IsDynamic && ! IsFontface && ! IsKeyframes && ! IsMediaQuery ; //TODO: This might not be correct
98
85
public bool IsLastChild { get ; private set ; }
99
86
public string Parent { get ; set ; }
0 commit comments