feat: Removes old version / files
This commit is contained in:
24
Sources/CliDoc/Modifiers/ColorModifier.swift
Normal file
24
Sources/CliDoc/Modifiers/ColorModifier.swift
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
35
Sources/CliDoc/Modifiers/LabelStyleModifier.swift
Normal file
35
Sources/CliDoc/Modifiers/LabelStyleModifier.swift
Normal 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() }
|
||||
}
|
||||
}
|
||||
32
Sources/CliDoc/Modifiers/StyleModifier.swift
Normal file
32
Sources/CliDoc/Modifiers/StyleModifier.swift
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user