@@ -56,12 +56,22 @@ public extension CSSSelector {
56
56
for block in selectors {
57
57
var select = Select ( )
58
58
// Merge the selectors
59
- select. selector = selector + block. selector
59
+ select. selector = " \( selector) \( block. selector) "
60
60
select. children = block. children
61
61
res += select. string ( )
62
62
}
63
63
}
64
- let root = children. filter { !( $0 is CSSSelector || $0 is ConditionalDeclaration || $0 is Media || $0 is Group || $0 is Parent ) }
64
+ let childCombinators = children. filter { $0 is Child } as! [ Child ]
65
+ for child in childCombinators {
66
+ let selectors = child. children. filter { $0 is CSSSelector } as! [ CSSSelector ]
67
+ for block in selectors {
68
+ var select = Select ( )
69
+ select. selector = " \( selector) > \( block. selector) "
70
+ select. children = block. children
71
+ res += select. string ( )
72
+ }
73
+ }
74
+ let root = children. filter { !( $0 is CSSSelector || $0 is ConditionalDeclaration || $0 is Media || $0 is Group || $0 is Parent || $0 is Child ) }
65
75
if root. count > 0 {
66
76
res += """
67
77
\( selector) { \( root. map { $0. string ( ) } . reduce ( into: " " , { $0 += " \n \( $1) " } ) )
@@ -146,3 +156,21 @@ public struct Parent: CSSBlock {
146
156
children. map { $0. string ( ) } . joined ( separator: " \n " )
147
157
}
148
158
}
159
+
160
+ /// The child combinator (a direct descendent of the parent)
161
+ public struct Child : CSSBlock {
162
+ public var children : [ CSS ]
163
+
164
+ public init ( @StylesheetBuilder _ body: ( ) -> CSSBlock ) {
165
+ let built = body ( )
166
+ if let container = built as? CSSContainer {
167
+ children = container. children
168
+ } else {
169
+ children = [ built]
170
+ }
171
+ }
172
+
173
+ public func string( ) -> String {
174
+ children. map { $0. string ( ) } . joined ( separator: " \n " )
175
+ }
176
+ }
0 commit comments