|
| 1 | +import AppKit |
| 2 | +import MarkdownUI |
| 3 | +import SharedUIComponents |
| 4 | +import SwiftUI |
| 5 | + |
| 6 | +extension Color { |
| 7 | + static var contentBackground: Color { |
| 8 | + Color(nsColor: NSColor(name: nil, dynamicProvider: { appearance in |
| 9 | + if appearance.isDarkMode { |
| 10 | + return #colorLiteral(red: 0.1580096483, green: 0.1730263829, blue: 0.2026666105, alpha: 1) |
| 11 | + } |
| 12 | + return .white |
| 13 | + })) |
| 14 | + } |
| 15 | + |
| 16 | + static var userChatContentBackground: Color { |
| 17 | + Color(nsColor: NSColor(name: nil, dynamicProvider: { appearance in |
| 18 | + if appearance.isDarkMode { |
| 19 | + return #colorLiteral(red: 0.2284317913, green: 0.2145925438, blue: 0.3214019983, alpha: 1) |
| 20 | + } |
| 21 | + return #colorLiteral(red: 0.896820749, green: 0.8709097223, blue: 0.9766687925, alpha: 1) |
| 22 | + })) |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +extension NSAppearance { |
| 27 | + var isDarkMode: Bool { |
| 28 | + if bestMatch(from: [.darkAqua, .aqua]) == .darkAqua { |
| 29 | + return true |
| 30 | + } else { |
| 31 | + return false |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +extension MarkdownUI.Theme { |
| 37 | + static func custom(fontSize: Double) -> MarkdownUI.Theme { |
| 38 | + .gitHub.text { |
| 39 | + ForegroundColor(.primary) |
| 40 | + BackgroundColor(Color.clear) |
| 41 | + FontSize(fontSize) |
| 42 | + } |
| 43 | + .codeBlock { configuration in |
| 44 | + configuration.label |
| 45 | + .relativeLineSpacing(.em(0.225)) |
| 46 | + .markdownTextStyle { |
| 47 | + FontFamilyVariant(.monospaced) |
| 48 | + FontSize(.em(0.85)) |
| 49 | + } |
| 50 | + .padding(16) |
| 51 | + .padding(.top, 14) |
| 52 | + .background(Color(nsColor: .textBackgroundColor).opacity(0.7)) |
| 53 | + .clipShape(RoundedRectangle(cornerRadius: 6)) |
| 54 | + .overlay(alignment: .top) { |
| 55 | + HStack(alignment: .center) { |
| 56 | + Text(configuration.language ?? "code") |
| 57 | + .foregroundStyle(.tertiary) |
| 58 | + .font(.callout) |
| 59 | + .padding(.leading, 8) |
| 60 | + .lineLimit(1) |
| 61 | + Spacer() |
| 62 | + CopyButton { |
| 63 | + NSPasteboard.general.clearContents() |
| 64 | + NSPasteboard.general.setString(configuration.content, forType: .string) |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + .markdownMargin(top: 4, bottom: 16) |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + static func functionCall(fontSize: Double) -> MarkdownUI.Theme { |
| 73 | + .gitHub.text { |
| 74 | + ForegroundColor(.secondary) |
| 75 | + BackgroundColor(Color.clear) |
| 76 | + FontSize(fontSize - 1) |
| 77 | + } |
| 78 | + .list { configuration in |
| 79 | + configuration.label |
| 80 | + .markdownMargin(top: 4, bottom: 4) |
| 81 | + } |
| 82 | + .paragraph { configuration in |
| 83 | + configuration.label |
| 84 | + .markdownMargin(top: 0, bottom: 4) |
| 85 | + } |
| 86 | + .codeBlock { configuration in |
| 87 | + configuration.label |
| 88 | + .relativeLineSpacing(.em(0.225)) |
| 89 | + .markdownTextStyle { |
| 90 | + FontFamilyVariant(.monospaced) |
| 91 | + FontSize(.em(0.85)) |
| 92 | + } |
| 93 | + .padding(16) |
| 94 | + .background(Color(nsColor: .textBackgroundColor).opacity(0.7)) |
| 95 | + .clipShape(RoundedRectangle(cornerRadius: 6)) |
| 96 | + .markdownMargin(top: 4, bottom: 4) |
| 97 | + } |
| 98 | + } |
| 99 | +} |
| 100 | + |
0 commit comments