feat: Working on node builder

This commit is contained in:
2024-12-01 11:45:05 -05:00
parent 55d8888961
commit ff49b12198
20 changed files with 495 additions and 227 deletions

View File

@@ -0,0 +1,35 @@
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)
}
}