feat: Working on node builder
This commit is contained in:
41
Sources/CliDoc/Modifiers/Style.swift
Normal file
41
Sources/CliDoc/Modifiers/Style.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
import Rainbow
|
||||
|
||||
public extension NodeRepresentable {
|
||||
@inlinable
|
||||
func style(_ styles: Style...) -> any NodeRepresentable {
|
||||
modifier(StyleModifier(styles: styles))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
func style(_ styles: [Style]) -> any NodeRepresentable {
|
||||
modifier(StyleModifier(styles: styles))
|
||||
}
|
||||
}
|
||||
|
||||
public extension NodeModifier {
|
||||
@inlinable
|
||||
static func style(_ styles: Style...) -> Self where Self == AnyNodeModifier {
|
||||
.init(StyleModifier(styles: styles))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
static func style(_ styles: [Style]) -> Self where Self == AnyNodeModifier {
|
||||
.init(StyleModifier(styles: styles))
|
||||
}
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
struct StyleModifier: NodeModifier, @unchecked Sendable {
|
||||
@usableFromInline
|
||||
let styles: [Style]
|
||||
|
||||
@usableFromInline
|
||||
init(styles: [Style]) {
|
||||
self.styles = styles
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
func render(_ node: any NodeRepresentable) -> any NodeRepresentable {
|
||||
styles.reduce(node.render()) { $0.applyingStyle($1) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user