SPB Git

Repository Public MIT

Tokens.swift 11.0 KB 235 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Astra9// File             : Packages/AstraDesign/Sources/Tokens.swift10// Module           : Packages11// Repository       : https://git.spboucher.ai/orix-astra12// Created          : 2026-11-2113// Last Modified    : 2026-11-2114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : Proprietary, all rights reserved (see license file)80// License File     : LICENSE81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import SwiftUI89#if canImport(UIKit)90import UIKit91#elseif canImport(AppKit)92import AppKit93#endif9495// MARK: - Colour9697public extension Color {98    /// A colour that resolves per appearance and per contrast setting.99    init(light: UInt32, dark: UInt32, lightHC: UInt32? = nil, darkHC: UInt32? = nil) {100        #if canImport(UIKit)101        self.init(uiColor: UIColor { traits in102            let isDark = traits.userInterfaceStyle == .dark103            let high = traits.accessibilityContrast == .high104            let hex = isDark ? (high ? (darkHC ?? dark) : dark) : (high ? (lightHC ?? light) : light)105            return UIColor(hex: hex)106        })107        #elseif canImport(AppKit)108        self.init(nsColor: NSColor(name: nil) { appearance in109            let isDark = appearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua110            return NSColor(srgbRed: CGFloat((isDark ? dark : light) >> 16 & 0xFF) / 255, green: CGFloat((isDark ? dark : light) >> 8 & 0xFF) / 255,111                           blue: CGFloat((isDark ? dark : light) & 0xFF) / 255, alpha: 1)112        })113        #endif114    }115    init(hex: UInt32, opacity: Double = 1) {116        self.init(.sRGB, red: Double(hex >> 16 & 0xFF) / 255, green: Double(hex >> 8 & 0xFF) / 255, blue: Double(hex & 0xFF) / 255, opacity: opacity)117    }118}119120#if canImport(UIKit)121extension UIColor {122    convenience init(hex: UInt32) {123        self.init(red: CGFloat(hex >> 16 & 0xFF) / 255, green: CGFloat(hex >> 8 & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1)124    }125}126#endif127128/// ORIX Astra colour tokens. Every pair below was checked for WCAG contrast against the surface it is used on129/// (see docs/DESIGN_SYSTEM.md for the measured ratios).130public enum AstraColor {131    // Surfaces: obsidian in dark, cool paper in light.132    public static let background = Color(light: 0xF5F5FA, dark: 0x06060B)133    public static let surface = Color(light: 0xFFFFFF, dark: 0x0F0F18, darkHC: 0x12121D)134    public static let surfaceRaised = Color(light: 0xEEEEF6, dark: 0x181826, darkHC: 0x1E1E30)135    public static let surfaceSunken = Color(light: 0xE8E8F2, dark: 0x0A0A12)136    public static let stroke = Color(light: 0xD9D9E6, dark: 0x25253A, lightHC: 0x8A8AA3, darkHC: 0x6C6C8C)137    public static let strokeStrong = Color(light: 0xB9B9CE, dark: 0x3A3A58, lightHC: 0x55556E, darkHC: 0x9A9ABB)138139    // Text.140    public static let textPrimary = Color(light: 0x0B0B14, dark: 0xF3F3FA)141    public static let textSecondary = Color(light: 0x45475C, dark: 0xA9ABC2, lightHC: 0x2A2B3C, darkHC: 0xD0D2E4)142    public static let textTertiary = Color(light: 0x6A6C82, dark: 0x7C7F99, lightHC: 0x45475C, darkHC: 0xB0B2C8)143    public static let onAccent = Color(hex: 0xFFFFFF)144145    // Accents: restrained electric violet, indigo and cyan.146    public static let violet = Color(light: 0x6B3BEA, dark: 0x9B7BFF, lightHC: 0x4E22C4, darkHC: 0xBBA4FF)147    public static let indigo = Color(light: 0x4338CA, dark: 0x7C83FF, lightHC: 0x2F27A0, darkHC: 0xA5AAFF)148    public static let cyan = Color(light: 0x086C82, dark: 0x3FD8F2, lightHC: 0x065E72, darkHC: 0x7BE8FA)149    /// Fill for primary buttons: dark enough in both appearances for white text (≥ 4.5:1).150    public static let accentFill = Color(light: 0x6B3BEA, dark: 0x7446F2)151    /// Fill for destructive buttons and the stop control: white text stays ≥ 4.5:1 in both appearances.152    public static let dangerFill = Color(light: 0xC0261F, dark: 0xCF2F27)153    public static let accentSoft = Color(light: 0xECE6FF, dark: 0x1D1740)154155    // Semantic.156    public static let success = Color(light: 0x0A744A, dark: 0x3DDC97)157    public static let warning = Color(light: 0x9A5B00, dark: 0xF6C453)158    public static let danger = Color(light: 0xC0261F, dark: 0xFF7B72)159    public static let successSoft = Color(light: 0xDFF6EC, dark: 0x0F2A20)160    public static let warningSoft = Color(light: 0xFCF0D6, dark: 0x2E2410)161    public static let dangerSoft = Color(light: 0xFCE4E2, dark: 0x331513)162163    // Code.164    public static let codeBackground = Color(light: 0xF0F0F7, dark: 0x0B0B13)165    public static let codeKeyword = Color(light: 0x7A2BD6, dark: 0xC4A7FF)166    public static let codeString = Color(light: 0x0A7A4B, dark: 0x7EE2A8)167    public static let codeNumber = Color(light: 0xA14A00, dark: 0xF6B26B)168    public static let codeComment = Color(light: 0x6A6C82, dark: 0x7C7F99)169    public static let codeType = Color(light: 0x0B6E8A, dark: 0x67D8EF)170171    /// The signature gradient: violet → indigo → cyan. Used on the glyph, primary emphasis and stream activity only.172    public static let signature = LinearGradient(colors: [violet, indigo, cyan], startPoint: .topLeading, endPoint: .bottomTrailing)173    public static let signatureHorizontal = LinearGradient(colors: [violet, indigo, cyan], startPoint: .leading, endPoint: .trailing)174}175176// MARK: - Spacing, radius, type177178public enum AstraSpace {179    public static let xxs: CGFloat = 2180    public static let xs: CGFloat = 4181    public static let sm: CGFloat = 8182    public static let md: CGFloat = 12183    public static let lg: CGFloat = 16184    public static let xl: CGFloat = 20185    public static let xxl: CGFloat = 28186    public static let xxxl: CGFloat = 40187    /// Minimum touch target on every interactive control.188    public static let hit: CGFloat = 44189    /// Horizontal page margin.190    public static let page: CGFloat = 16191}192193public enum AstraRadius {194    public static let sm: CGFloat = 8195    public static let md: CGFloat = 12196    public static let lg: CGFloat = 18197    public static let xl: CGFloat = 24198    public static let bubble: CGFloat = 20199    public static let pill: CGFloat = 999200}201202/// Typography: SF Pro through Dynamic Type text styles only, so every size scales with the user's setting.203public enum AstraFont {204    public static let display = Font.system(.largeTitle, design: .rounded, weight: .bold)205    public static let title = Font.system(.title2, design: .rounded, weight: .semibold)206    public static let headline = Font.system(.headline, design: .default, weight: .semibold)207    public static let body = Font.system(.body)208    public static let bodyEmphasis = Font.system(.body, weight: .semibold)209    public static let callout = Font.system(.callout)210    public static let subheadline = Font.system(.subheadline)211    public static let footnote = Font.system(.footnote)212    public static let caption = Font.system(.caption)213    public static let captionEmphasis = Font.system(.caption, weight: .semibold)214    public static let micro = Font.system(.caption2, weight: .medium)215    public static let mono = Font.system(.callout, design: .monospaced)216    public static let monoSmall = Font.system(.footnote, design: .monospaced)217    /// Figures in metrics: monospaced digits so numbers do not jitter while they update.218    public static let metric = Font.system(.title3, design: .rounded, weight: .semibold).monospacedDigit()219    public static let metricSmall = Font.system(.subheadline, design: .rounded, weight: .semibold).monospacedDigit()220}221222// MARK: - Elevation223224public struct AstraShadow: Sendable {225    public var color: Color; public var radius: CGFloat; public var y: CGFloat226    public static let none = AstraShadow(color: .clear, radius: 0, y: 0)227    public static let low = AstraShadow(color: Color.black.opacity(0.10), radius: 8, y: 2)228    public static let mid = AstraShadow(color: Color.black.opacity(0.16), radius: 18, y: 8)229    public static let glow = AstraShadow(color: Color(hex: 0x7446F2, opacity: 0.35), radius: 18, y: 6)230}231232public extension View {233    func astraShadow(_ s: AstraShadow) -> some View { shadow(color: s.color, radius: s.radius, x: 0, y: s.y) }234}235
Files main
Menu

Theme