Repository Public License
1// ORIX Clean — App/Sources/DesignSystem/Tokens.swift2// Description: ORIX design tokens for ORIX Clean: colour roles, spacing, radii, type, density, storage palettes.3// Author: Simon-Pierre Boucher — contact@spboucher.ai4import AppKit5import ORIXCleanCore6import SwiftUI78/// The core measurement type; Foundation also defines a generic `Measurement`.9typealias Measurement = ORIXCleanCore.Measurement1011extension Color {12 init(light: UInt32, dark: UInt32) {13 self.init(nsColor: NSColor(name: nil) { $0.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua ? NSColor(hex: dark) : NSColor(hex: light) })14 }1516 init(hex: UInt32, opacity: Double = 1) {17 self.init(.sRGB, red: Double((hex >> 16) & 0xFF) / 255, green: Double((hex >> 8) & 0xFF) / 255, blue: Double(hex & 0xFF) / 255, opacity: opacity)18 }19}2021extension NSColor {22 convenience init(hex: UInt32) {23 self.init(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1)24 }25}2627enum ORIX {28 enum Palette {29 /// Window background behind grouped content (shared ORIX family values).30 static let canvas = Color(light: 0xF4F5FA, dark: 0x0A0D18)31 static let surface = Color(light: 0xFFFFFF, dark: 0x141828)32 static let surfaceRaised = Color(light: 0xFFFFFF, dark: 0x1B2034)33 static let hairline = Color(light: 0xE3E6EF, dark: 0x262C44)34 static let textSecondary = Color(light: 0x5A6072, dark: 0x9AA2B8)35 static let textTertiary = Color(light: 0x8A90A2, dark: 0x6B738C)36 /// ORIX Clean accent pair: "clear water" teal with the family indigo.37 static let accent = Color(light: 0x0A9E96, dark: 0x2DD4BF)38 static let accentSecondary = Color(light: 0x5B5BF0, dark: 0x8484FF)39 static let low = Color(light: 0x16A34A, dark: 0x4ADE80)40 static let review = Color(light: 0xD97706, dark: 0xFBBF24)41 static let high = Color(light: 0xDC2626, dark: 0xF87171)42 static var brandGradient: LinearGradient {43 LinearGradient(colors: [Color(hex: 0x2DD4BF), Color(hex: 0x06B6D4), Color(hex: 0x5B5BF0)], startPoint: .topLeading, endPoint: .bottomTrailing)44 }45 }4647 enum Space {48 static let xs: CGFloat = 4, s: CGFloat = 8, m: CGFloat = 12, l: CGFloat = 16, xl: CGFloat = 24, xxl: CGFloat = 3249 }5051 enum Radius {52 static let s: CGFloat = 6, m: CGFloat = 10, l: CGFloat = 1453 }54}5556extension Risk {57 var color: Color {58 switch self {59 case .low: return ORIX.Palette.low60 case .review: return ORIX.Palette.review61 case .high: return ORIX.Palette.high62 }63 }6465 /// Shape differs per level so the meaning never depends on colour alone.66 var symbol: String {67 switch self {68 case .low: return "checkmark.circle.fill"69 case .review: return "eye.circle.fill"70 case .high: return "exclamationmark.triangle.fill"71 }72 }73}7475enum Density: String, CaseIterable, Identifiable {76 case comfortable, compact77 var id: String { rawValue }78 var rowPadding: CGFloat { self == .compact ? 3 : 7 }79 var title: String { self == .compact ? L("Compact") : L("Comfortable") }80}8182enum MapPalette: String, CaseIterable, Identifiable {83 case orix, colorblind84 var id: String { rawValue }85 var title: String { self == .orix ? L("ORIX") : L("Colour-blind friendly") }8687 /// Base colour of a file category. The colour-blind set is the Okabe–Ito palette.88 func color(_ c: FileCategory) -> (r: Double, g: Double, b: Double) {89 let hex: UInt3290 switch (self, c) {91 case (.orix, .video): hex = 0x8B5CF692 case (.orix, .audio): hex = 0xEC489993 case (.orix, .image): hex = 0xF59E0B94 case (.orix, .archive): hex = 0x64748B95 case (.orix, .diskImage): hex = 0x0EA5E996 case (.orix, .installer): hex = 0xEF444497 case (.orix, .document): hex = 0x22C55E98 case (.orix, .code): hex = 0x06B6D499 case (.orix, .application): hex = 0x6366F1100 case (.orix, .other): hex = 0x94A3B8101 case (.colorblind, .video): hex = 0xCC79A7102 case (.colorblind, .audio): hex = 0xD55E00103 case (.colorblind, .image): hex = 0xE69F00104 case (.colorblind, .archive): hex = 0x7F7F7F105 case (.colorblind, .diskImage): hex = 0x56B4E9106 case (.colorblind, .installer): hex = 0xB34700107 case (.colorblind, .document): hex = 0x009E73108 case (.colorblind, .code): hex = 0x0072B2109 case (.colorblind, .application): hex = 0xF0E442110 case (.colorblind, .other): hex = 0xA9A9A9111 }112 return (Double((hex >> 16) & 0xFF) / 255, Double((hex >> 8) & 0xFF) / 255, Double(hex & 0xFF) / 255)113 }114115 func swiftUIColor(_ c: FileCategory) -> Color {116 let v = color(c)117 return Color(.sRGB, red: v.r, green: v.g, blue: v.b, opacity: 1)118 }119}120121extension FileCategory {122 var symbol: String {123 switch self {124 case .video: return "film"125 case .audio: return "waveform"126 case .image: return "photo"127 case .archive: return "archivebox"128 case .diskImage: return "externaldrive"129 case .installer: return "shippingbox"130 case .document: return "doc.text"131 case .code: return "chevron.left.forwardslash.chevron.right"132 case .application: return "app.badge"133 case .other: return "doc"134 }135 }136}137