feat: Removes old version / files

This commit is contained in:
2024-12-03 21:23:54 -05:00
parent 590df275cc
commit 0a18b57dc8
25 changed files with 206 additions and 606 deletions

View File

@@ -0,0 +1,24 @@
import Rainbow
public extension TextNode {
@inlinable
func color(_ color: NamedColor) -> some TextNode {
modifier(ColorModifier(color: color))
}
}
@usableFromInline
struct ColorModifier<Content: TextNode>: NodeModifier {
@usableFromInline
let color: NamedColor
@usableFromInline
init(color: NamedColor) {
self.color = color
}
@usableFromInline
func render(content: Content) -> some TextNode {
content.render().applyingColor(color)
}
}

View File

@@ -1,59 +0,0 @@
import Rainbow
public extension Group {
func labelColor(_ color: NamedColor) -> some Node {
modifier(GroupLabelModifier(color: color))
}
}
public extension Node where Self.Body == Group {
func labelColor(_ color: NamedColor) -> some Node {
body.modifier(GroupLabelModifier(color: color))
}
}
public extension Node where Self == Label {
func labelColor(_ color: NamedColor) -> some Node {
modifier(LabelColorModifier(color: color))
}
}
public extension Note where Label == CliDoc.Label {
func labelColor(_ color: NamedColor) -> some Node {
var node = self
node.label.color = color
return node
}
}
struct LabelColorModifier: NodeModifier {
let color: NamedColor
func render(content: Label) -> some Node {
var label = content
label.color = color
return label
}
}
struct GroupLabelModifier: NodeModifier {
let color: NamedColor
func render(content: Group) -> some Node {
var group = content
applyLabelColor(&group)
return group
}
private func applyLabelColor(_ group: inout Group) {
for (idx, node) in group.nodes.enumerated() {
if var label = node as? Label {
label.color = color
group.nodes[idx] = label
} else if var nestedGroup = node as? Group {
applyLabelColor(&nestedGroup)
group.nodes[idx] = nestedGroup
}
}
}
}

View File

@@ -1,21 +0,0 @@
import Rainbow
// public extension Node {
// func labelStyel(_ styles: Style...) -> any Node {}
// }
public extension Node where Self == Label {
func labelStyle(_ styles: Style...) -> some Node {
modifier(LabelStyleModifier(styles: styles))
}
}
struct LabelStyleModifier: NodeModifier {
let styles: [Style]
func render(content: Label) -> some Node {
var label = content
label.styles = styles
return label
}
}

View File

@@ -0,0 +1,35 @@
import Rainbow
public extension TextNode {
func labelStyle<C: TextNode>(color: NamedColor? = nil, styles: [Style] = []) -> some TextNode where Self == Label<C> {
modifier(LabelStyle(color: color, styles: styles))
}
func labelStyle<C: TextNode>(color: NamedColor? = nil, styles: Style...) -> some TextNode where Self == Label<C> {
labelStyle(color: color, styles: styles)
}
}
public struct LabelStyle<C: TextNode>: NodeModifier {
@usableFromInline
let color: NamedColor?
@usableFromInline
let styles: [Style]
@usableFromInline
init(color: NamedColor? = nil, styles: [Style] = []) {
self.color = color
self.styles = styles
}
@inlinable
public func render(content: Label<C>) -> some TextNode {
var label: any TextNode = content.content
label = label.style(styles)
if let color {
label = label.color(color)
}
return Label { label.eraseToAnyTextNode() }
}
}

View File

@@ -0,0 +1,32 @@
import Rainbow
public extension TextNode {
@inlinable
func style(_ styles: Style...) -> some TextNode {
modifier(StyleModifier(styles: styles))
}
@inlinable
func style(_ styles: [Style]) -> some TextNode {
modifier(StyleModifier(styles: styles))
}
}
@usableFromInline
struct StyleModifier<Content: TextNode>: NodeModifier {
@usableFromInline
let styles: [Style]
@usableFromInline
init(styles: [Style]) {
self.styles = styles
}
@usableFromInline
func render(content: Content) -> some TextNode {
styles.reduce(content.render()) {
$0.applyingStyle($1)
}
}
}