@@ -3,30 +3,19 @@ import Foundation
33
44/// Visual configuration for rendering text diff segments.
55public struct TextDiffStyle : @unchecked Sendable {
6- /// Fill color used for inserted token chips.
7- public var additionFillColor : NSColor
8- /// Stroke color used for inserted token chips.
9- public var additionStrokeColor : NSColor
10- /// Optional text color override for inserted tokens.
11- public var additionTextColorOverride : NSColor ?
12-
13- /// Fill color used for deleted token chips.
14- public var deletionFillColor : NSColor
15- /// Stroke color used for deleted token chips.
16- public var deletionStrokeColor : NSColor
17- /// Optional text color override for deleted tokens.
18- public var deletionTextColorOverride : NSColor ?
6+ /// Visual style used for inserted token chips.
7+ public var additionsStyle : TextDiffChangeStyle
8+ /// Visual style used for deleted token chips.
9+ public var removalsStyle : TextDiffChangeStyle
1910
2011 /// Text color used for unchanged tokens.
21- public var unchangedTextColor : NSColor
12+ public var textColor : NSColor
2213 /// Font used for all rendered tokens.
2314 public var font : NSFont
2415 /// Corner radius applied to changed-token chips.
2516 public var chipCornerRadius : CGFloat
2617 /// Insets used to draw changed-token chips. Horizontal insets are floored to 3 points by the renderer.
2718 public var chipInsets : NSEdgeInsets
28- /// Controls whether deleted lexical tokens are drawn with a strikethrough.
29- public var deletionStrikethrough : Bool
3019 /// Minimum visual gap between adjacent changed lexical chips.
3120 public var interChipSpacing : CGFloat
3221 /// Additional vertical spacing between wrapped lines.
@@ -35,54 +24,67 @@ public struct TextDiffStyle: @unchecked Sendable {
3524 /// Creates a style for rendering text diffs.
3625 ///
3726 /// - Parameters:
38- /// - additionFillColor: Fill color used for inserted token chips.
39- /// - additionStrokeColor: Stroke color used for inserted token chips.
40- /// - additionTextColorOverride: Optional text color override for inserted tokens.
41- /// - deletionFillColor: Fill color used for deleted token chips.
42- /// - deletionStrokeColor: Stroke color used for deleted token chips.
43- /// - deletionTextColorOverride: Optional text color override for deleted tokens.
44- /// - unchangedTextColor: Text color used for unchanged tokens.
27+ /// - additionsStyle: Change style used for inserted token chips.
28+ /// - removalsStyle: Change style used for deleted token chips.
29+ /// - textColor: Text color used for unchanged tokens.
4530 /// - font: Font used for all rendered tokens.
4631 /// - chipCornerRadius: Corner radius applied to changed-token chips.
4732 /// - chipInsets: Insets applied around changed-token text when drawing chips.
48- /// - deletionStrikethrough: Whether deleted lexical tokens use a strikethrough.
4933 /// - interChipSpacing: Gap between adjacent changed lexical chips.
5034 /// - lineSpacing: Additional vertical spacing between wrapped lines.
5135 public init (
52- additionFillColor: NSColor ,
53- additionStrokeColor: NSColor ,
54- additionTextColorOverride: NSColor ? = nil ,
55- deletionFillColor: NSColor ,
56- deletionStrokeColor: NSColor ,
57- deletionTextColorOverride: NSColor ? = nil ,
58- unchangedTextColor: NSColor = . labelColor,
36+ additionsStyle: TextDiffChangeStyle = . defaultAddition,
37+ removalsStyle: TextDiffChangeStyle = . defaultRemoval,
38+ textColor: NSColor = . labelColor,
5939 font: NSFont = . monospacedSystemFont( ofSize: 14 , weight: . regular) ,
6040 chipCornerRadius: CGFloat = 4 ,
6141 chipInsets: NSEdgeInsets = NSEdgeInsets ( top: 1 , left: 3 , bottom: 1 , right: 3 ) ,
62- deletionStrikethrough: Bool = false ,
6342 interChipSpacing: CGFloat = 0 ,
6443 lineSpacing: CGFloat = 2
6544 ) {
66- self . additionFillColor = additionFillColor
67- self . additionStrokeColor = additionStrokeColor
68- self . additionTextColorOverride = additionTextColorOverride
69- self . deletionFillColor = deletionFillColor
70- self . deletionStrokeColor = deletionStrokeColor
71- self . deletionTextColorOverride = deletionTextColorOverride
72- self . unchangedTextColor = unchangedTextColor
45+ self . additionsStyle = additionsStyle
46+ self . removalsStyle = removalsStyle
47+ self . textColor = textColor
7348 self . font = font
7449 self . chipCornerRadius = chipCornerRadius
7550 self . chipInsets = chipInsets
76- self . deletionStrikethrough = deletionStrikethrough
7751 self . interChipSpacing = interChipSpacing
7852 self . lineSpacing = lineSpacing
7953 }
8054
55+ /// Creates a style by converting protocol-based operation styles to concrete change styles.
56+ ///
57+ /// - Parameters:
58+ /// - additionsStyle: Protocol-based style for inserted token chips.
59+ /// - removalsStyle: Protocol-based style for deleted token chips.
60+ /// - textColor: Text color used for unchanged tokens.
61+ /// - font: Font used for all rendered tokens.
62+ /// - chipCornerRadius: Corner radius applied to changed-token chips.
63+ /// - chipInsets: Insets applied around changed-token text when drawing chips.
64+ /// - interChipSpacing: Gap between adjacent changed lexical chips.
65+ /// - lineSpacing: Additional vertical spacing between wrapped lines.
66+ public init (
67+ additionsStyle: some TextDiffStyling ,
68+ removalsStyle: some TextDiffStyling ,
69+ textColor: NSColor = . labelColor,
70+ font: NSFont = . monospacedSystemFont( ofSize: 14 , weight: . regular) ,
71+ chipCornerRadius: CGFloat = 4 ,
72+ chipInsets: NSEdgeInsets = NSEdgeInsets ( top: 1 , left: 3 , bottom: 1 , right: 3 ) ,
73+ interChipSpacing: CGFloat = 0 ,
74+ lineSpacing: CGFloat = 2
75+ ) {
76+ self . init (
77+ additionsStyle: TextDiffChangeStyle ( additionsStyle) ,
78+ removalsStyle: TextDiffChangeStyle ( removalsStyle) ,
79+ textColor: textColor,
80+ font: font,
81+ chipCornerRadius: chipCornerRadius,
82+ chipInsets: chipInsets,
83+ interChipSpacing: interChipSpacing,
84+ lineSpacing: lineSpacing
85+ )
86+ }
87+
8188 /// The default style tuned for system green insertions and system red deletions.
82- public static let `default` = TextDiffStyle (
83- additionFillColor: NSColor . systemGreen. withAlphaComponent ( 0.22 ) ,
84- additionStrokeColor: NSColor . systemGreen. withAlphaComponent ( 0.65 ) ,
85- deletionFillColor: NSColor . systemRed. withAlphaComponent ( 0.22 ) ,
86- deletionStrokeColor: NSColor . systemRed. withAlphaComponent ( 0.65 )
87- )
89+ public static let `default` = TextDiffStyle ( )
8890}
0 commit comments