SPB Git

Repository Public License

Tokens.swift 10.2 KB 265 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Monitor9// File             : App/Sources/DesignSystem/Tokens.swift10// Description      : ORIX design tokens for macOS: colour roles, metric palette11//                    (standard and colour-blind safe), spacing, radii, type.12// Module           : DesignSystem13// Repository       : https://git.spboucher.ai/orix-monitor14// Created          : 2026-11-2115// Last Modified    : 2026-11-2116//17// =============================================================================18// AUTHOR & PROFESSIONAL AFFILIATION19// =============================================================================20//21// Author           : Simon-Pierre Boucher22// Position         : Professor of Finance23// Institution      : Université du Québec en Outaouais (UQO)24// Department       : Département des sciences administratives25// Organization     : SP Boucher26//27// Website          : https://spboucher.ai28// Git              : https://git.spboucher.ai29//30// =============================================================================31// OFFICIAL CONTACT DIRECTORY32// =============================================================================33//34// General          : info@spboucher.ai35// Professional     : contact@spboucher.ai36// Direct           : simon@spboucher.ai37// Research         : research@spboucher.ai38// Development      : dev@spboucher.ai39// Support          : support@spboucher.ai40// Security/Admin   : admin@spboucher.ai41// Notifications    : notifications@spboucher.ai42//43// Preferred Contact: support@spboucher.ai44//45// =============================================================================46// COPYRIGHT & INTELLECTUAL PROPERTY47// =============================================================================48//49// Copyright (c) 202650// Simon-Pierre Boucher51//52// All rights reserved where applicable.53//54// This file is governed by the applicable project license,55// copyright notices, institutional agreements and relevant law.56//57// Unless expressly authorized by the applicable license or58// rights holder, copying, redistribution, sublicensing,59// publication and commercial exploitation are not permitted.60//61// Existing third-party rights and notices remain unaffected.62//63// =============================================================================64// CONFIDENTIALITY & SECURITY65// =============================================================================66//67// Classification   : Public68// Distribution     : Public repository; use is governed by the project license69// Security Contact : admin@spboucher.ai70//71// Access to this source does not independently grant permission72// to redistribute or disclose confidential materials.73//74// Do not embed credentials, private keys, access tokens,75// certificates or confidential personal information.76//77// =============================================================================78// LICENSE & MAINTENANCE79// =============================================================================80//81// License          : Proprietary, all rights reserved (see license file)82// License File     : LICENSE83// Maintainer       : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import AppKit91import ORIXMonitorCore92import SwiftUI9394extension Color {95    /// A colour with distinct light and dark values (sRGB hex).96    init(light: UInt32, dark: UInt32) {97        self.init(nsColor: NSColor(name: nil) { $0.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua ? NSColor(hex: dark) : NSColor(hex: light) })98    }99100    init(hex: UInt32, opacity: Double = 1) {101        self.init(.sRGB, red: Double((hex >> 16) & 0xFF) / 255, green: Double((hex >> 8) & 0xFF) / 255, blue: Double(hex & 0xFF) / 255, opacity: opacity)102    }103}104105extension NSColor {106    convenience init(hex: UInt32) {107        self.init(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1)108    }109}110111/// The family palette, shared with the other ORIX apps.112enum ORIX {113    /// Text colours are chosen to reach at least 4.5:1 (WCAG AA) on canvas, surface and raised surface, in both appearances.114    enum Palette {115        static let canvas = Color(light: 0xF4F5FA, dark: 0x0A0D18)116        static let surface = Color(light: 0xFFFFFF, dark: 0x141828)117        static let surfaceRaised = Color(light: 0xEEF0F7, dark: 0x1D2236)118        static let hairline = Color(light: 0xDDE0EA, dark: 0x262C42)119        static let textPrimary = Color(light: 0x0E1222, dark: 0xF2F4FB)120        static let textSecondary = Color(light: 0x596078, dark: 0xA3AAC2)121        static let textTertiary = Color(light: 0x5F657D, dark: 0x9097B0)122        static let success = Color(light: 0x0A7446, dark: 0x34D399)123        static let warning = Color(light: 0x8F5200, dark: 0xFBBF24)124        static let danger = Color(light: 0xC0283A, dark: 0xFF6B76)125        /// ORIX Monitor's accent pair: the cyan pulse over the family indigo.126        static let accent = Color(light: 0x0B6E8A, dark: 0x22D3EE)127        static let accentSecondary = Color(light: 0x5B5BF0, dark: 0x8484FF)128    }129130    enum Space {131        static let xxs: CGFloat = 4132        static let xs: CGFloat = 8133        static let sm: CGFloat = 12134        static let md: CGFloat = 16135        static let lg: CGFloat = 24136        static let xl: CGFloat = 32137    }138139    enum Radius {140        static let chip: CGFloat = 6141        static let control: CGFloat = 8142        static let card: CGFloat = 14143    }144145    enum Typeface {146        /// Large numeric readout.147        static func readout(_ size: CGFloat = 28) -> Font { .system(size: size, weight: .semibold, design: .rounded).monospacedDigit() }148        static let label = Font.system(size: 11, weight: .semibold).smallCaps()149        static let value = Font.system(size: 13, weight: .medium).monospacedDigit()150        static let caption = Font.system(size: 11).monospacedDigit()151        static let mono = Font.system(size: 12, design: .monospaced)152    }153}154155/// The subsystem a metric belongs to. Drives colour, icon and navigation.156enum MetricFamily: String, CaseIterable, Codable, Sendable {157    case cpu, gpu, memory, disk, network, power, thermal, system158159    var symbol: String {160        switch self {161        case .cpu: "cpu"162        case .gpu: "square.stack.3d.up"163        case .memory: "memorychip"164        case .disk: "internaldrive"165        case .network: "network"166        case .power: "bolt.fill"167        case .thermal: "thermometer.medium"168        case .system: "desktopcomputer"169        }170    }171172    /// Standard palette: one hue per family, tuned for contrast on both canvases.173    private var standard: Color {174        switch self {175        case .cpu: Color(light: 0x2563EB, dark: 0x60A5FA)176        case .gpu: Color(light: 0x7C3AED, dark: 0xA78BFA)177        case .memory: Color(light: 0x059669, dark: 0x34D399)178        case .disk: Color(light: 0xC2620A, dark: 0xFBBF24)179        case .network: Color(light: 0x0891B2, dark: 0x22D3EE)180        case .power: Color(light: 0x4D7C0F, dark: 0xA3E635)181        case .thermal: Color(light: 0xDB2777, dark: 0xF472B6)182        case .system: Color(light: 0x596078, dark: 0xA3AAC2)183        }184    }185186    /// Okabe–Ito palette: distinguishable under the common forms of colour-vision deficiency.187    private var colorBlindSafe: Color {188        switch self {189        case .cpu: Color(light: 0x0072B2, dark: 0x56B4E9)190        case .gpu: Color(light: 0xAA4499, dark: 0xCC79A7)191        case .memory: Color(light: 0x007A5A, dark: 0x009E73)192        case .disk: Color(light: 0xB07800, dark: 0xE69F00)193        case .network: Color(light: 0x2A7FB8, dark: 0x88CCEE)194        case .power: Color(light: 0x8A7A00, dark: 0xF0E442)195        case .thermal: Color(light: 0xD55E00, dark: 0xFF8A3D)196        case .system: Color(light: 0x596078, dark: 0xA3AAC2)197        }198    }199200    func color(colorBlindSafe safe: Bool) -> Color { safe ? colorBlindSafe : standard }201}202203extension MetricID {204    var family: MetricFamily {205        switch self {206        case .cpuTotal, .cpuUser, .cpuSystem, .loadAverage1: .cpu207        case .memUsed, .memApp, .memWired, .memCompressed, .memCached, .memFree, .memPressure, .swapUsed, .pageIns, .pageOuts: .memory208        case .diskRead, .diskWrite, .diskFree: .disk209        case .netDown, .netUp: .network210        case .batteryCharge, .batteryPower: .power211        case .batteryTemperature, .thermalState: .thermal212        case .gpuUtilization: .gpu213        case .processCount, .selfCPU, .selfMemory: .system214        }215    }216}217218private struct PaletteKey: EnvironmentKey { static let defaultValue = false }219private struct DensityKey: EnvironmentKey { static let defaultValue: CGFloat = 1 }220221extension EnvironmentValues {222    /// True when the colour-blind-safe metric palette is selected.223    var colorBlindSafe: Bool {224        get { self[PaletteKey.self] }225        set { self[PaletteKey.self] = newValue }226    }227228    /// Padding multiplier: 0.72 compact, 1 regular, 1.25 comfortable.229    var density: CGFloat {230        get { self[DensityKey.self] }231        set { self[DensityKey.self] = newValue }232    }233}234235/// Runtime lookup in the string catalogue for English text produced outside SwiftUI (core metric names, report strings).236func L(_ english: String) -> String {237    String(localized: String.LocalizationValue(english))238}239240extension Severity {241    var color: Color {242        switch self {243        case .info: ORIX.Palette.accent244        case .warning: ORIX.Palette.warning245        case .critical: ORIX.Palette.danger246        }247    }248249    var symbol: String {250        switch self {251        case .info: "info.circle.fill"252        case .warning: "exclamationmark.triangle.fill"253        case .critical: "exclamationmark.octagon.fill"254        }255    }256257    var title: String {258        switch self {259        case .info: L("Info")260        case .warning: L("Warning")261        case .critical: L("Critical")262        }263    }264}265
Files main
Menu

Theme