36 lines
686 B
Swift
36 lines
686 B
Swift
import Rainbow
|
|
|
|
public extension NodeRepresentable {
|
|
|
|
@inlinable
|
|
func color(_ color: NamedColor) -> any NodeRepresentable {
|
|
modifier(ColorModifier(color: color))
|
|
}
|
|
|
|
}
|
|
|
|
public extension NodeModifier {
|
|
|
|
@inlinable
|
|
static func color(_ color: NamedColor) -> Self where Self == AnyNodeModifier {
|
|
.init(ColorModifier(color: color))
|
|
}
|
|
|
|
}
|
|
|
|
@usableFromInline
|
|
struct ColorModifier: NodeModifier, @unchecked Sendable {
|
|
@usableFromInline
|
|
let color: NamedColor
|
|
|
|
@usableFromInline
|
|
init(color: NamedColor) {
|
|
self.color = color
|
|
}
|
|
|
|
@usableFromInline
|
|
func render(_ node: any NodeRepresentable) -> any NodeRepresentable {
|
|
node.render().applyingColor(color)
|
|
}
|
|
}
|