171 lines
7.0 KiB
Swift
171 lines
7.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 an active toolbar toggle's keycap.
|
|
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)
|
|
/// The Commit button's label, a warmer ink than `ink`.
|
|
public static let commitInk = Color(hex: 0x201608)
|
|
/// 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)
|
|
|
|
/// Git status letters: staged rows in teal, unstaged in amber-soft.
|
|
public static let stagedLetter = Color(hex: 0x8FBFB4)
|
|
public static let unstagedLetter = Color(hex: 0xF0B476)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|