SPB Git

Repository Public

DesignSystem.swift 7.2 KB 152 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Packages/LocalChatUI/Sources/Design/DesignSystem.swift3// Description: Local Chat design tokens shared by macOS and iOS: graphite surfaces, accent gradient, type scale, radii, spacing, motion.4import SwiftUI5#if canImport(UIKit)6import UIKit7#elseif canImport(AppKit)8import AppKit9#endif1011public extension Color {12    /// A colour that follows the light / dark appearance.13    init(light: UInt32, dark: UInt32, lightAlpha: Double = 1, darkAlpha: Double = 1) {14        #if canImport(UIKit)15        self.init(uiColor: UIColor { $0.userInterfaceStyle == .dark ? UIColor(hex: dark, alpha: darkAlpha) : UIColor(hex: light, alpha: lightAlpha) })16        #else17        self.init(nsColor: NSColor(name: nil) { $0.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua ? NSColor(hex: dark, alpha: darkAlpha) : NSColor(hex: light, alpha: lightAlpha) })18        #endif19    }20    init(hex: UInt32, alpha: Double = 1) {21        self.init(.sRGB, red: Double((hex >> 16) & 0xFF) / 255, green: Double((hex >> 8) & 0xFF) / 255, blue: Double(hex & 0xFF) / 255, opacity: alpha)22    }23}24#if canImport(UIKit)25extension UIColor { convenience init(hex: UInt32, alpha: Double) { self.init(red: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: alpha) } }26#else27extension NSColor { convenience init(hex: UInt32, alpha: Double) { self.init(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: alpha) } }28#endif2930public enum DS {31    public enum C {32        public static let bg = Color(light: 0xF5F5F7, dark: 0x0D0E11)33        public static let surface = Color(light: 0xFFFFFF, dark: 0x15171C)34        public static let surface2 = Color(light: 0xF0F1F4, dark: 0x1C1F25)35        public static let surface3 = Color(light: 0xE5E7EC, dark: 0x262A32)36        public static let border = Color(light: 0x000000, dark: 0xFFFFFF, lightAlpha: 0.09, darkAlpha: 0.09)37        public static let borderStrong = Color(light: 0x000000, dark: 0xFFFFFF, lightAlpha: 0.16, darkAlpha: 0.18)38        public static let text = Color(light: 0x14151A, dark: 0xF2F3F5)39        public static let text2 = Color(light: 0x4A4D57, dark: 0xB4B8C2)40        public static let muted = Color(light: 0x7C808C, dark: 0x7D8290)41        public static let accent = Color(light: 0x5B5BF0, dark: 0x8587FF)42        public static let accent2 = Color(light: 0x8E4DF2, dark: 0xA97BFF)43        public static let accent3 = Color(light: 0x0FA9B8, dark: 0x43D9E3)44        public static let ok = Color(light: 0x1E9E63, dark: 0x3DD68C)45        public static let warn = Color(light: 0xC27A0C, dark: 0xF5B041)46        public static let danger = Color(light: 0xD23B43, dark: 0xFF6B72)47        public static let userBubble = Color(light: 0xECECFE, dark: 0x25284A)48        /// Series colours for charts (stable order, readable in both appearances).49        public static let series: [Color] = [accent, accent3, Color(light: 0xD9682B, dark: 0xFF9F5A), ok, accent2, Color(light: 0xC2388B, dark: 0xFF7AC0), warn, muted]50    }5152    public enum G {53        public static let accent = LinearGradient(colors: [C.accent, C.accent2], startPoint: .topLeading, endPoint: .bottomTrailing)54        public static let aurora = LinearGradient(colors: [C.accent, C.accent2, C.accent3], startPoint: .leading, endPoint: .trailing)55        public static let soft = LinearGradient(colors: [C.accent.opacity(0.16), C.accent3.opacity(0.07)], startPoint: .topLeading, endPoint: .bottomTrailing)56        public static let hairline = LinearGradient(colors: [C.borderStrong, C.border.opacity(0.3)], startPoint: .top, endPoint: .bottom)57    }5859    public enum F {60        public static let largeTitle = Font.system(size: 28, weight: .bold, design: .default)61        public static let title = Font.system(size: 20, weight: .semibold)62        public static let headline = Font.system(size: 15, weight: .semibold)63        public static let body = Font.system(size: 14)64        public static let callout = Font.system(size: 13)65        public static let caption = Font.system(size: 11.5)66        public static let micro = Font.system(size: 10.5, weight: .medium)67        public static let metric = Font.system(size: 22, weight: .semibold, design: .rounded).monospacedDigit()68        public static func mono(_ size: CGFloat = 12.5, weight: Font.Weight = .regular) -> Font { .system(size: size, weight: weight, design: .monospaced) }69        public static func rounded(_ size: CGFloat, weight: Font.Weight = .semibold) -> Font { .system(size: size, weight: weight, design: .rounded) }70    }7172    public enum R {73        public static let control: CGFloat = 874        public static let card: CGFloat = 1275        public static let panel: CGFloat = 1676        public static let bubble: CGFloat = 1877        public static let pill: CGFloat = 99978    }7980    public enum S {81        public static let xxs: CGFloat = 2, xs: CGFloat = 4, sm: CGFloat = 8, md: CGFloat = 12, lg: CGFloat = 16, xl: CGFloat = 24, xxl: CGFloat = 3682        /// Readable measure of the chat column.83        public static let column: CGFloat = 78084    }8586    public enum M {87        public static let snappy = Animation.spring(response: 0.28, dampingFraction: 0.86)88        public static let smooth = Animation.spring(response: 0.42, dampingFraction: 0.9)89        public static let bouncy = Animation.spring(response: 0.38, dampingFraction: 0.7)90        public static let fade = Animation.easeOut(duration: 0.18)91    }9293    /// Body size of the transcript: larger on touch devices.94    public static var transcriptSize: CGFloat {95        #if os(iOS)96        1697        #else98        1499        #endif100    }101}102103public enum Platform {104    public static var isMac: Bool {105        #if os(macOS)106        true107        #else108        false109        #endif110    }111    #if os(iOS)112    @MainActor public static var isPad: Bool { UIDevice.current.userInterfaceIdiom == .pad }113    #else114    public static var isPad: Bool { false }115    #endif116}117118public enum Pasteboard {119    public static func copy(_ string: String) {120        #if canImport(UIKit)121        UIPasteboard.general.string = string122        #else123        let pb = NSPasteboard.general; pb.clearContents(); pb.setString(string, forType: .string)124        #endif125    }126    public static var string: String? {127        #if canImport(UIKit)128        UIPasteboard.general.string129        #else130        NSPasteboard.general.string(forType: .string)131        #endif132    }133}134135public enum Haptics {136    @MainActor public static var enabled = true137    public enum Kind { case light, medium, success, warning, error, selection }138    @MainActor public static func play(_ kind: Kind) {139        #if os(iOS)140        guard enabled else { return }141        switch kind {142        case .light: UIImpactFeedbackGenerator(style: .light).impactOccurred()143        case .medium: UIImpactFeedbackGenerator(style: .medium).impactOccurred()144        case .success: UINotificationFeedbackGenerator().notificationOccurred(.success)145        case .warning: UINotificationFeedbackGenerator().notificationOccurred(.warning)146        case .error: UINotificationFeedbackGenerator().notificationOccurred(.error)147        case .selection: UISelectionFeedbackGenerator().selectionChanged()148        }149        #endif150    }151}152
Files main
Menu

Theme