-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathStyles.swift
More file actions
148 lines (138 loc) · 5.28 KB
/
Styles.swift
File metadata and controls
148 lines (138 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import AppKit
import MarkdownUI
import SharedUIComponents
import SwiftUI
enum Style {
static let panelHeight: Double = 560
static let panelWidth: Double = 504
static let minChatPanelWidth: Double = 242 // Following the minimal width of Navigator in Xcode
static let inlineSuggestionMaxHeight: Double = 400
static let inlineSuggestionPadding: Double = 25
static let widgetHeight: Double = 20
static var widgetWidth: Double { widgetHeight }
static let widgetPadding: Double = 4
static let chatWindowTitleBarHeight: Double = 24
static let trafficLightButtonSize: Double = 12
static let codeReviewPanelWidth: Double = 550
static let codeReviewPanelHeight: Double = 450
static let fixPanelToAnnotationSpacing: Double = 1
static let nesSuggestionMenuLeadingPadding: Double = 4
static let agentConfigurationWidgetLeadingSpacing: Double = 4
}
extension Color {
static var contentBackground: Color {
Color(nsColor: NSColor(name: nil, dynamicProvider: { appearance in
if appearance.isDarkMode {
return #colorLiteral(red: 0.1580096483, green: 0.1730263829, blue: 0.2026666105, alpha: 1)
}
return .white
}))
}
static var userChatContentBackground: Color {
Color(nsColor: NSColor(name: nil, dynamicProvider: { appearance in
if appearance.isDarkMode {
return #colorLiteral(red: 0.2284317913, green: 0.2145925438, blue: 0.3214019983, alpha: 1)
}
return #colorLiteral(red: 0.9458052187, green: 0.9311983998, blue: 0.9906365955, alpha: 1)
}))
}
}
extension NSAppearance {
var isDarkMode: Bool {
if bestMatch(from: [.darkAqua, .aqua]) == .darkAqua {
return true
} else {
return false
}
}
}
struct XcodeLikeFrame<Content: View>: View {
@Environment(\.colorScheme) var colorScheme
let content: Content
let cornerRadius: Double
var body: some View {
content.clipShape(RoundedRectangle(cornerRadius: cornerRadius, style: .continuous))
.background(
RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)
.fill(Color.chatWindowBackgroundColor)
)
.overlay(
RoundedRectangle(cornerRadius: max(0, cornerRadius), style: .continuous)
.stroke(Color.black.opacity(0.1), style: .init(lineWidth: 1))
) // Add an extra border just incase the background is not displayed.
.overlay(
RoundedRectangle(cornerRadius: max(0, cornerRadius - 1), style: .continuous)
.stroke(Color.white.opacity(0.2), style: .init(lineWidth: 1))
.padding(1)
)
}
}
extension View {
var xcodeStyleCornerRadius: Double { 16 }
func xcodeStyleFrame() -> some View {
XcodeLikeFrame(content: self, cornerRadius: xcodeStyleCornerRadius)
}
}
extension MarkdownUI.Theme {
static func custom(fontSize: Double) -> MarkdownUI.Theme {
.gitHub.text {
ForegroundColor(.primary)
BackgroundColor(Color.clear)
FontSize(fontSize)
}
.codeBlock { configuration in
configuration.label
.relativeLineSpacing(.em(0.225))
.markdownTextStyle {
FontFamilyVariant(.monospaced)
FontSize(.em(0.85))
}
.padding(16)
.padding(.top, 14)
.background(Color(nsColor: .textBackgroundColor).opacity(0.7))
.clipShape(RoundedRectangle(cornerRadius: 6))
.overlay(alignment: .top) {
HStack(alignment: .center) {
Text(configuration.language ?? "code")
.foregroundStyle(.tertiary)
.font(.callout)
.padding(.leading, 8)
.lineLimit(1)
Spacer()
CopyButton {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(configuration.content, forType: .string)
}
}
}
.markdownMargin(top: 4, bottom: 16)
}
}
static func functionCall(fontSize: Double) -> MarkdownUI.Theme {
.gitHub.text {
ForegroundColor(.secondary)
BackgroundColor(Color.clear)
FontSize(fontSize - 1)
}
.list { configuration in
configuration.label
.markdownMargin(top: 4, bottom: 4)
}
.paragraph { configuration in
configuration.label
.markdownMargin(top: 0, bottom: 4)
}
.codeBlock { configuration in
configuration.label
.relativeLineSpacing(.em(0.225))
.markdownTextStyle {
FontFamilyVariant(.monospaced)
FontSize(.em(0.85))
}
.padding(16)
.background(Color(nsColor: .textBackgroundColor).opacity(0.7))
.clipShape(RoundedRectangle(cornerRadius: 6))
.markdownMargin(top: 4, bottom: 4)
}
}
}