restores Helder in all its glory

This commit is contained in:
2026-09-28 11:34:49 +02:00
parent c2b38b853c
commit 1d29d0952d
280 changed files with 29205 additions and 7 deletions
+63
View File
@@ -0,0 +1,63 @@
import CoreText
import Foundation
import HelderServices
/// Registers the bundled IBM Plex faces for this process. CoreText reads WOFF2 directly.
public enum FontRegistry {
public static let resourceBundleName = "Helder_HelderUI.bundle"
/// The Fonts folder, found without `Bundle.module`: its generated accessor looks next to
/// the .app (not in Contents/Resources) and falls back to an absolute build path.
public static func fontsDirectory() -> URL? {
let fm = FileManager.default
let candidates = [
Bundle.main.resourceURL,
Bundle.main.bundleURL,
Bundle.main.executableURL?.deletingLastPathComponent(),
// Under `swift test` the code lives in an .xctest bundle beside the resource bundle.
Bundle(for: BundleToken.self).bundleURL.deletingLastPathComponent(),
]
for base in candidates.compactMap({ $0 }) {
let fonts = base.appendingPathComponent(resourceBundleName).appendingPathComponent("Fonts")
if fm.fileExists(atPath: fonts.path) { return fonts }
let flat = base.appendingPathComponent(resourceBundleName).appendingPathComponent("Contents/Resources/Fonts")
if fm.fileExists(atPath: flat.path) { return flat }
}
return nil
}
/// Registers every font file once; returns the PostScript names now available. Safe to call repeatedly.
@discardableResult
public static func registerBundledFonts() -> Set<String> {
lock.lock()
defer { lock.unlock() }
if let done = registered { return done }
var names = Set<String>()
guard let dir = fontsDirectory(),
let files = try? FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil) else {
Log.warn("fonts", "bundled fonts not found; using the system fonts")
registered = names
return names
}
for url in files where ["woff2", "woff", "ttf", "otf"].contains(url.pathExtension.lowercased()) {
var error: Unmanaged<CFError>?
let ok = CTFontManagerRegisterFontsForURL(url as CFURL, .process, &error)
let already = (error?.takeRetainedValue()).map { CFErrorGetCode($0) == CTFontManagerError.alreadyRegistered.rawValue } ?? false
if ok || already {
let descriptors = CTFontManagerCreateFontDescriptorsFromURL(url as CFURL) as? [CTFontDescriptor] ?? []
for d in descriptors {
if let name = CTFontDescriptorCopyAttribute(d, kCTFontNameAttribute) as? String { names.insert(name) }
}
} else {
Log.warn("fonts", "cannot register \(url.lastPathComponent)")
}
}
Log.info("fonts", "registered \(names.sorted().joined(separator: ", "))")
registered = names
return names
}
private final class BundleToken {}
private static let lock = NSLock()
nonisolated(unsafe) private static var registered: Set<String>?
}
+105
View File
@@ -0,0 +1,105 @@
import SwiftUI
public enum Metrics {
// MARK: Rows and bars
public static let explorerRow: CGFloat = 24
public static let sourceControlRow: CGFloat = 26
public static let statusBar: CGFloat = 28
public static let contextMenuItem: CGFloat = 30
/// The one top-bar height: Explorer head, Diff bar.
public static let panelHeader: CGFloat = 34
/// The bar above the code: the open file, its change counts, Preview and Diff.
public static let editorBar: CGFloat = 34
public static let titleBar: CGFloat = 44
public static let codeLine: CGFloat = 20
public static let searchHitLine: CGFloat = 24
public static let diffOverlayLine: CGFloat = 22
public static let launcherRow: CGFloat = 38
public static let launcherNewRow: CGFloat = 46
public static let searchQueryBar: CGFloat = 54
public static let commitBox: CGFloat = 52
public static let pushButton: CGFloat = 34
// MARK: Radii
/// Buttons, inputs, tags, keycaps, menu rows, code blocks.
public static let radiusSmall: CGFloat = 2
/// Panels, cards, menus.
public static let radiusMedium: CGFloat = 4
/// Overlays only.
public static let radiusOverlay: CGFloat = 8
// MARK: Lines
public static let hairline: CGFloat = 1
/// Selection rule, focus border, pull-quote.
public static let accentRule: CGFloat = 2
/// The focus ring drawn outside the 2px amber border.
public static let focusRingWidth: CGFloat = 2
// MARK: Columns
public static let sourceControlWidth: CGFloat = 236
public static let explorerWidth: CGFloat = 288
public static let agentWidth: CGFloat = 480
public static let minEditorWidth: CGFloat = 280
public static let explorerIndent: CGFloat = 16
public static let explorerBaseIndent: CGFloat = 12
/// Gutter of the code grid in the editor.
public static let codeGutter: CGFloat = 56
public static let diffOverlayGutter: CGFloat = 52
public static let searchHitGutter: CGFloat = 64
/// Room the hidden-inset title bar leaves for the traffic lights.
public static let trafficLightInset: CGFloat = 82
/// Where the traffic lights sit, measured from the window's top-left corner.
public static let trafficLightOrigin = CGPoint(x: 14, y: 12)
/// The pointer target of a 1pt splitter: 3pt either side of the line.
public static let splitterHitArea: CGFloat = 7
// MARK: Title bar and toolbar
public static let titleBarGap: CGFloat = 18
public static let titleClusterGap: CGFloat = 10
public static let crumbGap: CGFloat = 7
public static let toolbarGap: CGFloat = 4
public static let toolbarPadding = EdgeInsets(top: 6, leading: 9, bottom: 6, trailing: 9)
/// The `?` button: a square with a hairline border.
public static let toolbarIconButton: CGFloat = 26
public static let statusBarGap: CGFloat = 16
// MARK: Window
public static let defaultWindow = CGSize(width: 1680, height: 1040)
public static let minimumWindow = CGSize(width: 1100, height: 680)
// MARK: Overlays
public static let overlayInset: CGFloat = 34
public static let contextMenuWidth: CGFloat = 320
public static let passOnWidth: CGFloat = 460
public static let launcherWidth: CGFloat = 520
public static let launcherTopPadding: CGFloat = 40
public static let launcherFooter: CGFloat = 36
public static let tooltipMaxWidth: CGFloat = 300
public static let tooltipDelay: Duration = .milliseconds(350)
/// Toasts stack this far above the window's bottom edge.
public static let toastBottom: CGFloat = 44
// MARK: Elevation (only two shadows exist)
public static let menuShadowRadius: CGFloat = 16
public static let menuShadowY: CGFloat = 4
public static let overlayShadowRadius: CGFloat = 48
public static let overlayShadowY: CGFloat = 16
// MARK: Motion: colour transitions only
public static let colorTransition = Animation.timingCurve(0.22, 1, 0.36, 1, duration: 0.16)
public static let smallControlTransition = Animation.timingCurve(0.22, 1, 0.36, 1, duration: 0.12)
/// Stepped on/off blink of the caret, terminal cursor and wordmark period; no fade.
public static let blinkInterval: TimeInterval = 1.1
public static let refreshFlashDuration: TimeInterval = 0.26
/// How long the branch · project card shows when a window becomes key again.
public static let focusFlashDuration: Duration = .milliseconds(500)
}
+170
View File
@@ -0,0 +1,170 @@
// 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)
}
}
+108
View File
@@ -0,0 +1,108 @@
import AppKit
import SwiftUI
/// The bundled faces by PostScript name, as registered by `FontRegistry`.
public enum PlexFace: String, CaseIterable, Sendable {
case monoRegular = "IBMPlexMono-Regular"
case monoMedium = "IBMPlexMono-Medium"
case monoSemiBold = "IBMPlexMono-SemiBold"
case monoBold = "IBMPlexMono-Bold"
case sansRegular = "IBMPlexSans-Regular"
case sansMedium = "IBMPlexSans-Medium"
case sansSemiBold = "IBMPlexSans-SemiBold"
case sansBold = "IBMPlexSans-Bold"
case sansItalic = "IBMPlexSans-Italic"
public var isMono: Bool { rawValue.hasPrefix("IBMPlexMono") }
}
/// One typographic role: face, size, line box and tracking.
public struct TypeRole: Sendable {
public var face: PlexFace
public var size: CGFloat
/// Line box height in points; nil keeps the font's own.
public var lineHeight: CGFloat?
/// Tracking in points (the design's em values times the size).
public var tracking: CGFloat
public var uppercase: Bool
public init(_ face: PlexFace, _ size: CGFloat, lineHeight: CGFloat? = nil, trackingEm: CGFloat = 0, uppercase: Bool = false) {
self.face = face
self.size = size
self.lineHeight = lineHeight
self.tracking = trackingEm * size
self.uppercase = uppercase
}
/// Falls back to the system monospaced or UI font when the bundled face did not register.
public var nsFont: NSFont {
if let font = NSFont(name: face.rawValue, size: size) { return font }
let weight: NSFont.Weight = switch face {
case .monoMedium, .sansMedium: .medium
case .monoSemiBold, .sansSemiBold: .semibold
case .monoBold, .sansBold: .bold
default: .regular
}
return face.isMono ? .monospacedSystemFont(ofSize: size, weight: weight) : .systemFont(ofSize: size, weight: weight)
}
public var font: Font { Font(nsFont) }
}
public enum Typography {
public static let sectionTitle = TypeRole(.monoBold, 20, lineHeight: 24, trackingEm: -0.02)
public static let dialogTitle = TypeRole(.monoBold, 14, lineHeight: 14)
/// Section and panel labels: 10px mono, uppercase, text-4.
public static let panelLabel = TypeRole(.monoBold, 10, trackingEm: 0.14, uppercase: true)
public static let wordmark = TypeRole(.monoBold, 13, trackingEm: 0.02)
public static let launcherWordmark = TypeRole(.monoBold, 14, trackingEm: 0.02)
/// The last breadcrumb segment in the title bar.
public static let crumbLeaf = TypeRole(.monoSemiBold, 12)
/// The `esc`/`↵` chip and overlay footers.
public static let chip = TypeRole(.monoRegular, 11)
public static let keycapSmall = TypeRole(.monoSemiBold, 11)
public static let toastTitle = TypeRole(.sansRegular, 13)
public static let toastReference = TypeRole(.monoRegular, 12)
public static let focusFlash = TypeRole(.monoRegular, 19)
public static let focusFlashName = TypeRole(.monoBold, 19, trackingEm: -0.01)
public static let code = TypeRole(.monoRegular, 13, lineHeight: 20)
public static let searchHit = TypeRole(.monoRegular, 12, lineHeight: 24)
public static let path = TypeRole(.monoRegular, 12)
public static let meta = TypeRole(.monoRegular, 11)
public static let branch = TypeRole(.monoMedium, 12)
public static let keycap = TypeRole(.monoSemiBold, 12)
public static let statusLetter = TypeRole(.monoSemiBold, 10)
public static let badge = TypeRole(.monoSemiBold, 8)
public static let searchQuery = TypeRole(.monoMedium, 16)
public static let terminal = TypeRole(.monoRegular, 12, lineHeight: 20.4)
public static let row = TypeRole(.sansRegular, 13)
public static let rowSelected = TypeRole(.sansMedium, 13)
public static let sourceControlRow = TypeRole(.sansRegular, 12)
public static let body = TypeRole(.sansRegular, 14, lineHeight: 23.8)
public static let tooltip = TypeRole(.sansRegular, 12, lineHeight: 18)
public static let button = TypeRole(.sansMedium, 12)
public static let commitButton = TypeRole(.sansSemiBold, 12)
/// The editor bar's Preview and Diff buttons.
public static let segment = TypeRole(.sansRegular, 11)
public static let segmentOn = TypeRole(.sansMedium, 11)
public static let toolbarLabel = TypeRole(.sansRegular, 12)
public static let toolbarLabelOn = TypeRole(.sansMedium, 12)
public static let menuItem = TypeRole(.sansRegular, 13)
public static let menuItemHighlighted = TypeRole(.sansMedium, 13)
public static let note = TypeRole(.monoRegular, 14, lineHeight: 23.8)
public static let markdownH2 = TypeRole(.monoBold, 24, lineHeight: 26.4, trackingEm: -0.03)
public static let markdownH3 = TypeRole(.monoBold, 17, lineHeight: 20.4)
public static let markdownQuote = TypeRole(.sansItalic, 15)
}
extension View {
/// Applies a type role: font, tracking, line spacing and case.
public func typeRole(_ role: TypeRole) -> some View {
let natural = role.nsFont.ascender - role.nsFont.descender + role.nsFont.leading
return self
.font(role.font)
.tracking(role.tracking)
.lineSpacing(max(0, (role.lineHeight ?? natural) - natural))
.textCase(role.uppercase ? .uppercase : nil)
}
}