Files
LektorenPlan/Sources/LektorenPlan/Theme.swift
T
2026-11-07 11:32:18 +01:00

582 lines
19 KiB
Swift

import SwiftUI
import AppKit
import LektorenPlanCore
enum LP {
static func dynamic(light: NSColor, dark: NSColor) -> Color {
Color(nsColor: NSColor(name: nil) { appearance in
appearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua ? dark : light
})
}
static let paper = dynamic(
light: NSColor(calibratedRed: 0.973, green: 0.957, blue: 0.925, alpha: 1),
dark: NSColor(calibratedRed: 0.075, green: 0.078, blue: 0.086, alpha: 1)
)
static let paperDeep = dynamic(
light: NSColor(calibratedRed: 0.945, green: 0.924, blue: 0.882, alpha: 1),
dark: NSColor(calibratedRed: 0.055, green: 0.058, blue: 0.065, alpha: 1)
)
static let card = dynamic(
light: NSColor(calibratedWhite: 1.0, alpha: 1),
dark: NSColor(calibratedRed: 0.125, green: 0.129, blue: 0.141, alpha: 1)
)
static let cardMuted = dynamic(
light: NSColor(calibratedRed: 0.985, green: 0.975, blue: 0.955, alpha: 1),
dark: NSColor(calibratedRed: 0.155, green: 0.159, blue: 0.172, alpha: 1)
)
static let ink = dynamic(
light: NSColor(calibratedRed: 0.12, green: 0.135, blue: 0.155, alpha: 1),
dark: NSColor(calibratedRed: 0.93, green: 0.92, blue: 0.90, alpha: 1)
)
static let inkSecondary = dynamic(
light: NSColor(calibratedRed: 0.36, green: 0.37, blue: 0.38, alpha: 1),
dark: NSColor(calibratedRed: 0.68, green: 0.68, blue: 0.68, alpha: 1)
)
static let inkTertiary = dynamic(
light: NSColor(calibratedRed: 0.52, green: 0.51, blue: 0.49, alpha: 1),
dark: NSColor(calibratedRed: 0.48, green: 0.48, blue: 0.48, alpha: 1)
)
static let line = dynamic(
light: NSColor(calibratedRed: 0.86, green: 0.835, blue: 0.79, alpha: 1),
dark: NSColor(calibratedRed: 0.24, green: 0.245, blue: 0.26, alpha: 1)
)
static let accent = Color(hex: "#2E5B57")
static let accentSoft = dynamic(
light: NSColor(calibratedRed: 0.88, green: 0.925, blue: 0.905, alpha: 1),
dark: NSColor(calibratedRed: 0.13, green: 0.21, blue: 0.20, alpha: 1)
)
static let gold = Color(hex: "#B7863B")
static let goldSoft = dynamic(
light: NSColor(calibratedRed: 0.976, green: 0.925, blue: 0.80, alpha: 1),
dark: NSColor(calibratedRed: 0.24, green: 0.20, blue: 0.105, alpha: 1)
)
static let burgundy = Color(hex: "#7E3D4A")
static let burgundySoft = dynamic(
light: NSColor(calibratedRed: 0.966, green: 0.90, blue: 0.90, alpha: 1),
dark: NSColor(calibratedRed: 0.245, green: 0.13, blue: 0.15, alpha: 1)
)
static let sundayWash = dynamic(
light: NSColor(calibratedRed: 0.985, green: 0.955, blue: 0.885, alpha: 1),
dark: NSColor(calibratedRed: 0.18, green: 0.155, blue: 0.105, alpha: 1)
)
static let feastWash = dynamic(
light: NSColor(calibratedRed: 0.998, green: 0.955, blue: 0.79, alpha: 1),
dark: NSColor(calibratedRed: 0.23, green: 0.185, blue: 0.085, alpha: 1)
)
static let open = Color(hex: "#B26A22")
static let openSoft = dynamic(
light: NSColor(calibratedRed: 0.99, green: 0.93, blue: 0.84, alpha: 1),
dark: NSColor(calibratedRed: 0.24, green: 0.17, blue: 0.075, alpha: 1)
)
static let success = Color(hex: "#3F7A55")
static let successSoft = dynamic(
light: NSColor(calibratedRed: 0.89, green: 0.945, blue: 0.90, alpha: 1),
dark: NSColor(calibratedRed: 0.10, green: 0.22, blue: 0.14, alpha: 1)
)
static let danger = Color(hex: "#A5453F")
static let numberFont = Font.system(size: 13, weight: .semibold, design: .rounded)
static let labelFont = Font.system(size: 11, weight: .semibold, design: .rounded)
static let serifTitle = Font.system(size: 30, weight: .semibold, design: .serif)
static let serifHeadline = Font.system(size: 19, weight: .semibold, design: .serif)
static let serifSubhead = Font.system(size: 15, weight: .medium, design: .serif)
static func churchColor(_ hex: String) -> Color {
Color(hex: hex)
}
static func liturgicalColor(_ color: LiturgicalColor) -> Color {
switch color {
case .white, .gold: return Color(hex: "#C2A14D")
case .red: return Color(hex: "#A5453F")
case .green: return Color(hex: "#4F7D5A")
case .violet: return Color(hex: "#6E4B8E")
case .rose: return Color(hex: "#C07A8B")
case .black: return Color(hex: "#4A4440")
}
}
}
extension Color {
init(hex: String) {
let cleaned = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
var value: UInt64 = 0
Scanner(string: cleaned).scanHexInt64(&value)
let r, g, b, a: UInt64
switch cleaned.count {
case 8:
r = (value >> 24) & 0xFF
g = (value >> 16) & 0xFF
b = (value >> 8) & 0xFF
a = value & 0xFF
case 6:
r = (value >> 16) & 0xFF
g = (value >> 8) & 0xFF
b = value & 0xFF
a = 255
default:
r = 120; g = 120; b = 120; a = 255
}
self.init(.sRGB, red: Double(r) / 255, green: Double(g) / 255, blue: Double(b) / 255, opacity: Double(a) / 255)
}
}
// MARK: - Surfaces
struct SurfaceCard<Content: View>: View {
var padding: CGFloat
var radius: CGFloat
var background: Color
var bordered: Bool
@ViewBuilder var content: Content
init(
padding: CGFloat = 18,
radius: CGFloat = 16,
background: Color = LP.card,
bordered: Bool = true,
@ViewBuilder content: () -> Content
) {
self.padding = padding
self.radius = radius
self.background = background
self.bordered = bordered
self.content = content()
}
var body: some View {
content
.padding(padding)
.background(
RoundedRectangle(cornerRadius: radius, style: .continuous)
.fill(background)
.shadow(color: .black.opacity(0.035), radius: 10, x: 0, y: 4)
)
.overlay(
RoundedRectangle(cornerRadius: radius, style: .continuous)
.strokeBorder(bordered ? LP.line.opacity(0.55) : .clear, lineWidth: 1)
)
}
}
struct AppBackground: View {
var body: some View {
ZStack {
LinearGradient(
colors: [LP.paper, LP.paperDeep, LP.paper],
startPoint: .topLeading,
endPoint: .bottomTrailing
)
RadialGradient(
colors: [LP.gold.opacity(0.055), .clear],
center: .topTrailing,
startRadius: 20,
endRadius: 620
)
RadialGradient(
colors: [LP.accent.opacity(0.045), .clear],
center: .bottomLeading,
startRadius: 20,
endRadius: 700
)
}
.ignoresSafeArea()
}
}
// MARK: - Badges
struct TinyBadge: View {
var text: String
var color: Color
var filled: Bool = false
var body: some View {
Text(text)
.font(.system(size: 9.5, weight: .bold, design: .rounded))
.tracking(0.4)
.foregroundStyle(filled ? Color.white : color)
.padding(.horizontal, 7)
.padding(.vertical, 3)
.background(
Capsule().fill(filled ? color : color.opacity(0.12))
)
.overlay(
Capsule().strokeBorder(filled ? .clear : color.opacity(0.20), lineWidth: 0.8)
)
}
}
struct RankBadge: View {
var day: LiturgicalDay
var body: some View {
if day.isHighFeast {
TinyBadge(text: "HOCHFEST", color: LP.gold, filled: true)
} else if day.rank == .feast {
TinyBadge(text: "FEST", color: LP.burgundy, filled: true)
} else if day.rank == .obligatoryMemorial {
TinyBadge(text: "GEDENKTAG", color: LP.accent)
} else if day.isObligation && !day.isSunday {
TinyBadge(text: "GEBOTEN", color: LP.burgundy)
}
}
}
struct RoleBadge: View {
var role: Role
var compact: Bool = false
var body: some View {
HStack(spacing: 4) {
Image(systemName: role.symbolName)
.font(.system(size: compact ? 8 : 9, weight: .semibold))
if !compact {
Text(role.title)
.font(.system(size: 9.5, weight: .semibold))
}
}
.foregroundStyle(role == .lector ? LP.accent : LP.burgundy)
.padding(.horizontal, compact ? 5 : 6)
.padding(.vertical, 2.5)
.background(
Capsule().fill(role == .lector ? LP.accent.opacity(0.09) : LP.burgundy.opacity(0.09))
)
}
}
struct Avatar: View {
var initials: String
var color: Color
var size: CGFloat = 26
var body: some View {
Text(initials)
.font(.system(size: size * 0.34, weight: .bold, design: .rounded))
.foregroundStyle(.white)
.frame(width: size, height: size)
.background(
Circle().fill(
LinearGradient(colors: [color.opacity(0.9), color.opacity(0.65)],
startPoint: .topLeading, endPoint: .bottomTrailing)
)
)
.overlay(Circle().strokeBorder(.white.opacity(0.28), lineWidth: 0.7))
}
}
struct PersonMiniChip: View {
var person: Person
var role: Role
var color: Color
var body: some View {
HStack(spacing: 4) {
Avatar(initials: person.initials, color: color, size: 18)
Text(person.firstNameWithInitial)
.font(.system(size: 10.5, weight: .medium))
.foregroundStyle(LP.ink)
.lineLimit(1)
}
.padding(.horizontal, 4)
.padding(.vertical, 2)
.background(
Capsule().fill(LP.cardMuted)
)
.overlay(
Capsule().strokeBorder(LP.line.opacity(0.5), lineWidth: 0.6)
)
.help("\(person.fullName) · \(role.title)\n\(person.preferredChurchIDs.isEmpty ? "Alle Orte" : "Bevorzugte Orte") · max. \(person.maxPerMonth) Einsätze/Monat")
}
}
// MARK: - Buttons
struct PrimaryActionButton: View {
var title: String
var icon: String
var action: () -> Void
var disabled: Bool = false
var body: some View {
Button(action: action) {
HStack(spacing: 7) {
Image(systemName: icon)
.font(.system(size: 11, weight: .bold))
Text(title)
.font(.system(size: 12, weight: .semibold))
}
.foregroundStyle(.white)
.padding(.horizontal, 14)
.padding(.vertical, 8)
.background(
RoundedRectangle(cornerRadius: 9, style: .continuous)
.fill(LinearGradient(colors: [LP.accent, LP.accent.opacity(0.82)],
startPoint: .top, endPoint: .bottom))
.shadow(color: LP.accent.opacity(0.20), radius: 5, y: 2)
)
}
.buttonStyle(.plain)
.disabled(disabled)
.opacity(disabled ? 0.45 : 1)
}
}
struct SecondaryActionButton: View {
var title: String
var icon: String
var action: () -> Void
var disabled: Bool = false
var tint: Color = LP.ink
var body: some View {
Button(action: action) {
HStack(spacing: 6) {
Image(systemName: icon)
.font(.system(size: 10.5, weight: .semibold))
Text(title)
.font(.system(size: 11.5, weight: .medium))
}
.foregroundStyle(tint)
.padding(.horizontal, 12)
.padding(.vertical, 7)
.background(
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(LP.card)
)
.overlay(
RoundedRectangle(cornerRadius: 8, style: .continuous)
.strokeBorder(LP.line.opacity(0.8), lineWidth: 1)
)
}
.buttonStyle(.plain)
.disabled(disabled)
.opacity(disabled ? 0.45 : 1)
}
}
struct IconActionButton: View {
var icon: String
var help: String
var action: () -> Void
var tint: Color = LP.inkSecondary
var body: some View {
Button(action: action) {
Image(systemName: icon)
.font(.system(size: 12, weight: .semibold))
.foregroundStyle(tint)
.frame(width: 28, height: 28)
.background(Circle().fill(LP.card))
.overlay(Circle().strokeBorder(LP.line.opacity(0.7), lineWidth: 0.8))
}
.buttonStyle(.plain)
.help(help)
}
}
// MARK: - Headers
struct PageHeader<Trailing: View>: View {
var eyebrow: String
var title: String
var subtitle: String
@ViewBuilder var trailing: Trailing
init(eyebrow: String, title: String, subtitle: String, @ViewBuilder trailing: () -> Trailing) {
self.eyebrow = eyebrow
self.title = title
self.subtitle = subtitle
self.trailing = trailing()
}
var body: some View {
HStack(alignment: .bottom, spacing: 22) {
VStack(alignment: .leading, spacing: 5) {
Text(eyebrow.uppercased())
.font(.system(size: 9.5, weight: .bold, design: .rounded))
.tracking(1.5)
.foregroundStyle(LP.accent)
Text(title)
.font(LP.serifTitle)
.foregroundStyle(LP.ink)
Text(subtitle)
.font(.system(size: 12, weight: .regular))
.foregroundStyle(LP.inkSecondary)
}
Spacer(minLength: 16)
trailing
}
}
}
extension PageHeader where Trailing == EmptyView {
init(eyebrow: String, title: String, subtitle: String) {
self.init(eyebrow: eyebrow, title: title, subtitle: subtitle) { EmptyView() }
}
}
struct SectionLabel: View {
var title: String
var trailing: String? = nil
var body: some View {
HStack(alignment: .firstTextBaseline) {
Text(title)
.font(.system(size: 10, weight: .bold, design: .rounded))
.tracking(1.3)
.foregroundStyle(LP.inkTertiary)
Spacer()
if let trailing {
Text(trailing)
.font(.system(size: 10, weight: .medium))
.foregroundStyle(LP.inkTertiary)
}
}
}
}
struct StatPill: View {
var icon: String
var value: String
var label: String
var tint: Color = LP.accent
var body: some View {
HStack(spacing: 9) {
Image(systemName: icon)
.font(.system(size: 12, weight: .semibold))
.foregroundStyle(tint)
.frame(width: 26, height: 26)
.background(Circle().fill(tint.opacity(0.10)))
VStack(alignment: .leading, spacing: 1) {
Text(value)
.font(.system(size: 17, weight: .bold, design: .rounded))
.foregroundStyle(LP.ink)
Text(label)
.font(.system(size: 9.5, weight: .medium))
.foregroundStyle(LP.inkTertiary)
}
}
}
}
struct EmptyStateView: View {
var icon: String
var title: String
var message: String
var actionTitle: String? = nil
var action: (() -> Void)? = nil
var body: some View {
VStack(spacing: 12) {
Image(systemName: icon)
.font(.system(size: 30, weight: .light))
.foregroundStyle(LP.inkTertiary)
Text(title)
.font(LP.serifHeadline)
.foregroundStyle(LP.ink)
Text(message)
.font(.system(size: 12))
.foregroundStyle(LP.inkSecondary)
.multilineTextAlignment(.center)
.frame(maxWidth: 360)
if let actionTitle, let action {
PrimaryActionButton(title: actionTitle, icon: "plus", action: action)
.padding(.top, 4)
}
}
.frame(maxWidth: .infinity)
.padding(.vertical, 44)
}
}
// MARK: - Toast
struct ToastView: View {
var toast: Toast
@Environment(\.colorScheme) private var scheme
var body: some View {
HStack(spacing: 10) {
Image(systemName: toast.kind.icon)
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(toast.kind.color)
Text(toast.message)
.font(.system(size: 12, weight: .medium))
.foregroundStyle(LP.ink)
.lineLimit(3)
}
.padding(.horizontal, 16)
.padding(.vertical, 11)
.background(
Capsule()
.fill(.regularMaterial)
.shadow(color: .black.opacity(0.16), radius: 16, y: 8)
)
.overlay(Capsule().strokeBorder(LP.line.opacity(0.6), lineWidth: 0.8))
.padding(.bottom, 24)
}
}
enum ToastKind {
case success, info, warning, error
var icon: String {
switch self {
case .success: "checkmark.circle.fill"
case .info: "info.circle.fill"
case .warning: "exclamationmark.triangle.fill"
case .error: "xmark.octagon.fill"
}
}
var color: Color {
switch self {
case .success: LP.success
case .info: LP.accent
case .warning: LP.open
case .error: LP.danger
}
}
}
struct Toast: Identifiable, Equatable {
var id = UUID()
var message: String
var kind: ToastKind
static func == (lhs: Toast, rhs: Toast) -> Bool { lhs.id == rhs.id }
}
// MARK: - Misc
struct Hairline: View {
var body: some View {
Rectangle().fill(LP.line.opacity(0.6)).frame(height: 1)
}
}
struct KeyboardShortcutHint: View {
var keys: String
var body: some View {
Text(keys)
.font(.system(size: 9, weight: .semibold, design: .rounded))
.foregroundStyle(LP.inkTertiary)
.padding(.horizontal, 5)
.padding(.vertical, 2)
.background(RoundedRectangle(cornerRadius: 4).fill(LP.cardMuted))
.overlay(RoundedRectangle(cornerRadius: 4).strokeBorder(LP.line.opacity(0.7), lineWidth: 0.6))
}
}
struct FlowingSubhead: View {
var text: String
var body: some View {
Text(text)
.font(.system(size: 10.5, weight: .medium))
.foregroundStyle(LP.inkTertiary)
}
}