Files
helder/Sources/HelderUI/Theme/Palette.swift
T

218 lines
9.0 KiB
Swift

// Dark only: there is no light mode by decision.
import AppKit
import HelderCore
import SwiftUI
public enum Palette {
// MARK: Surfaces (four, no more)
/// Editor canvas, terminal, launcher backdrop, code blocks.
public static let editor = Color(hex: 0x101720)
/// Title bar, side panels, status bar, overlays, menus.
public static let panel = Color(hex: 0x18202B)
/// Selected row, hairline borders, tooltip surface, keycap borders.
public static let raised = Color(hex: 0x232C39)
/// Row hover fill only.
public static let hover = Color(hex: 0x1E2733)
/// A side column with keyboard focus: one step of fill, nothing else.
public static let panelActive = Color(hex: 0x1B242F)
/// The editor column with keyboard focus.
public static let editorActive = Color(hex: 0x131B25)
/// What ⌘R adds on top of a column for a moment, so a refresh that changes nothing still reads.
public static let refreshFlash = Color(hex: 0x0F1113)
// MARK: Text on dark
/// Active file, dialog titles, selected row.
public static let text1 = Color(hex: 0xF4F5F4)
/// Body copy, code plain text.
public static let text2 = Color(hex: 0xE4E7E6)
/// Inactive rows, identifiers, secondary copy.
public static let text3 = Color(hex: 0xBAC0C0)
/// Labels, paths, meta, comments.
public static let text4 = Color(hex: 0x6C7783)
/// Line numbers, disabled.
public static let text5 = Color(hex: 0x3A424C)
/// Label on a destructive (amber-deep) button.
public static let onDeep = Color(hex: 0xF4F5F4)
/// Tooltip border.
public static let tooltipBorder = Color(hex: 0x3A424C)
// MARK: Accent: amber, reserved for the uses listed in the design README
public static let amber = Color(hex: 0xE8913A)
public static let amberDeep = Color(hex: 0xC4741F)
public static let amberSoft = Color(hex: 0xF0B476)
public static let amberTint = Color(hex: 0xE8913A, alpha: 0.10)
public static let focusRing = Color(hex: 0xE8913A, alpha: 0.22)
/// Border of a lit key in the symbol popup.
public static let amberKeycapBorder = Color(hex: 0xE8913A, alpha: 0.35)
/// Text on an amber fill: always ink, never white.
public static let ink = Color(hex: 0x171C22)
/// Keycap border on an amber fill.
public static let inkKeycapBorder = Color(hex: 0x171C22, alpha: 0.25)
// MARK: Syntax: six muted colours, weight 400, no italics
public static let syntaxPlain = Color(hex: 0xE4E7E6)
public static let syntaxVariable = Color(hex: 0xBAC0C0)
public static let syntaxComment = Color(hex: 0x6C7783)
public static let syntaxKeyword = Color(hex: 0xC3A6CE)
public static let syntaxString = Color(hex: 0x8FBFB4)
public static let syntaxNumber = Color(hex: 0xF0B476)
public static func syntax(_ role: TokenRole) -> Color {
switch role {
case .plain, .symbol: syntaxPlain
case .variable: syntaxVariable
case .comment: syntaxComment
case .keyword: syntaxKeyword
case .string: syntaxString
case .number: syntaxNumber
}
}
// MARK: Diff: no green, no red; it reads on shape and the 2px rule
public static let addedText = Color(hex: 0x8FBFB4)
public static let addedFill = Color(hex: 0x8FBFB4, alpha: 0.12)
public static let addedRule = Color(hex: 0x8FBFB4)
public static let removedText = Color(hex: 0xC4741F)
public static let removedFill = Color(hex: 0xC4741F, alpha: 0.14)
public static let removedRule = Color(hex: 0xC4741F)
// MARK: Overlays and elevation
/// Flat ink scrim behind every overlay; no blur.
public static let scrim = Color(hex: 0x101720, alpha: 0.72)
public static let menuShadow = Color(hex: 0x171C22, alpha: 0.10)
public static let overlayShadow = Color(hex: 0x171C22, alpha: 0.18)
// MARK: Type badges
public static let badgePurple = Color(hex: 0xC3A6CE)
public static let badgeAmber = Color(hex: 0xF0B476)
public static let badgeTeal = Color(hex: 0x8FBFB4)
public static let badgeGrey = Color(hex: 0xBAC0C0)
/// Badge text: ink on the fill.
public static let badgeText = Color(hex: 0x101720)
/// The fill of a workspace column: every column rests on `panel`; a focused one steps once.
public static func column(_ column: Panel, active: Bool) -> Color {
guard active else { return panel }
return column == .editor ? editorActive : panelActive
}
public static func badge(_ tint: BadgeTint) -> Color {
switch tint {
case .purple: badgePurple
case .amber: badgeAmber
case .teal: badgeTeal
case .grey: badgeGrey
}
}
/// The dot on a file with a git change in Search and Recent files.
public static let changedDot = Color(hex: 0x8FBFB4)
/// Menu icon tints: teal adds, amber-soft modifies or leaves the app, grey renames or passes on.
public static let menuIconAdd = Color(hex: 0x8FBFB4)
public static let menuIconModify = Color(hex: 0xF0B476)
public static let menuIconRename = Color(hex: 0xBAC0C0)
// MARK: Git view
/// Secondary meta between text-3 and text-4: the sync label, the author, directories, hints.
public static let textMuted = Color(hex: 0x828D9A)
/// A file row under the pointer.
public static let gitRowHover = Color(hex: 0x1F2834)
/// The idle Commit button under the pointer: `raised` one step darker.
public static let commitIdleHover = Color(hex: 0x202834)
/// Status colours: modified, new, deleted; staged is `amber`.
public static let gitModified = Color(hex: 0xF0B476)
public static let gitNew = Color(hex: 0x8FBFB4)
public static let gitDeleted = Color(hex: 0xC3A6CE)
/// The one red in the app: a merge conflict must not blend in with the soft status colours.
public static let gitConflict = Color(hex: 0xE5534B)
/// Section header fills.
public static let gitStagedTint = Color(hex: 0xE8913A, alpha: 0.08)
public static let gitModifiedTint = Color(hex: 0xF0B476, alpha: 0.06)
public static let gitNewTint = Color(hex: 0x8FBFB4, alpha: 0.06)
public static let gitDeletedTint = Color(hex: 0xC3A6CE, alpha: 0.06)
/// The fill of a conflicted row.
public static let gitConflictTint = Color(hex: 0xE5534B, alpha: 0.08)
/// The current branch row.
public static let gitCurrentBranch = Color(hex: 0xE8913A, alpha: 0.08)
/// Inline diff: line fills, the differing middle of a paired line, and the side with no line.
public static let inlineRemovedFill = Color(hex: 0xE8913A, alpha: 0.12)
public static let inlineAddedFill = Color(hex: 0x8FBFB4, alpha: 0.12)
public static let inlineRemovedHighlight = Color(hex: 0xE8913A, alpha: 0.38)
public static let inlineAddedHighlight = Color(hex: 0x8FBFB4, alpha: 0.36)
public static let inlineFiller = Color(hex: 0x232C39, alpha: 0.35)
/// The colour of an artisan console line in the Schema view.
public static func artisan(_ kind: ArtisanLineKind) -> Color {
switch kind {
case .command: text1
case .output: text3
case .error: amber
case .success: gitNew
}
}
/// The colour of a console line.
public static func console(_ kind: GitLineKind) -> Color {
switch kind {
case .command: text1
case .output: text3
case .error: amber
case .hint: textMuted
case .staged, .success: gitNew
case .unstaged: gitModified
}
}
}
extension Color {
/// A colour from a 0xRRGGBB literal.
public init(hex: UInt32, alpha: Double = 1) {
self.init(
.sRGB,
red: Double((hex >> 16) & 0xFF) / 255,
green: Double((hex >> 8) & 0xFF) / 255,
blue: Double(hex & 0xFF) / 255,
opacity: alpha
)
}
}
extension NSColor {
/// A colour from a 0xRRGGBB literal, for AppKit and SwiftTerm.
public convenience init(hex: UInt32, alpha: CGFloat = 1) {
self.init(
srgbRed: CGFloat((hex >> 16) & 0xFF) / 255,
green: CGFloat((hex >> 8) & 0xFF) / 255,
blue: CGFloat(hex & 0xFF) / 255,
alpha: alpha
)
}
/// Parses the config's CSS colours: `#RGB`, `#RRGGBB` and `rgba(r,g,b,a)`; nil for anything else.
public convenience init?(css: String) {
let s = css.trimmingCharacters(in: .whitespaces).lowercased()
if s.hasPrefix("#") {
var hex = String(s.dropFirst())
if hex.count == 3 { hex = hex.map { "\($0)\($0)" }.joined() }
guard hex.count == 6, let value = UInt32(hex, radix: 16) else { return nil }
self.init(hex: value)
return
}
guard s.hasPrefix("rgb"), let open = s.firstIndex(of: "("), let close = s.lastIndex(of: ")") else { return nil }
let parts = s[s.index(after: open)..<close].split(separator: ",").compactMap {
Double($0.trimmingCharacters(in: .whitespaces))
}
guard parts.count == 3 || parts.count == 4 else { return nil }
self.init(srgbRed: parts[0] / 255, green: parts[1] / 255, blue: parts[2] / 255, alpha: parts.count == 4 ? parts[3] : 1)
}
}