Repository Public License
1// ORIX Scan2// File: Packages/ORIXKit/Sources/ORIXDesign/Tokens.swift3// Description: ORIX design tokens: colour roles (light and dark), spacing, radii, typography, motion. Shared by every ORIX app.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI89#if canImport(UIKit)10import UIKit11#elseif canImport(AppKit)12import AppKit13#endif1415public extension Color {16 /// A colour with distinct light and dark values (sRGB hex).17 init(light: UInt32, dark: UInt32) {18 #if canImport(UIKit)19 self.init(uiColor: UIColor { $0.userInterfaceStyle == .dark ? UIColor(hex: dark) : UIColor(hex: light) })20 #else21 self.init(nsColor: NSColor(name: nil) { $0.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua ? NSColor(hex: dark) : NSColor(hex: light) })22 #endif23 }2425 init(hex: UInt32, opacity: Double = 1) {26 self.init(.sRGB, red: Double((hex >> 16) & 0xFF) / 255, green: Double((hex >> 8) & 0xFF) / 255, blue: Double(hex & 0xFF) / 255, opacity: opacity)27 }28}2930#if canImport(UIKit)31extension UIColor {32 convenience init(hex: UInt32) {33 self.init(red: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1)34 }35}36#else37extension NSColor {38 convenience init(hex: UInt32) {39 self.init(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1)40 }41}42#endif4344/// The accent pair of one ORIX app. The family shares every other token; each app brings its own pair.45public struct ORIXAccent: Sendable, Equatable {46 public var primary: Color47 public var secondary: Color48 public init(primary: Color, secondary: Color) {49 self.primary = primary50 self.secondary = secondary51 }5253 /// ORIX Scan: indigo with the cyan "optical beam".54 public static let scan = ORIXAccent(primary: Color(light: 0x5B5BF0, dark: 0x8484FF), secondary: Color(light: 0x0FB5CF, dark: 0x22D3EE))5556 public var gradient: LinearGradient {57 LinearGradient(colors: [Color(hex: 0x7673FF), Color(hex: 0x5B5BF0), Color(hex: 0x3F3BD6)], startPoint: .topLeading, endPoint: .bottomTrailing)58 }5960 public var beam: LinearGradient {61 LinearGradient(colors: [secondary.opacity(0), secondary, secondary.opacity(0)], startPoint: .leading, endPoint: .trailing)62 }63}6465public enum ORIX {66 public enum Palette {67 /// App background behind grouped content.68 public static let canvas = Color(light: 0xF4F5FA, dark: 0x0A0D18)69 /// Cards and rows.70 public static let surface = Color(light: 0xFFFFFF, dark: 0x141828)71 /// Raised or nested surfaces (fields inside cards, chips).72 public static let surfaceRaised = Color(light: 0xEEF0F7, dark: 0x1D2236)73 /// The neutral backdrop documents sit on (never pure white, so page edges stay visible).74 public static let desk = Color(light: 0xE4E7F0, dark: 0x05070E)75 public static let hairline = Color(light: 0xDDE0EA, dark: 0x262C42)76 public static let textPrimary = Color(light: 0x0E1222, dark: 0xF2F4FB)77 public static let textSecondary = Color(light: 0x596078, dark: 0xA3AAC2)78 public static let textTertiary = Color(light: 0x8A90A6, dark: 0x6F7690)79 public static let success = Color(light: 0x12925A, dark: 0x34D399)80 public static let warning = Color(light: 0xB86A00, dark: 0xFBBF24)81 public static let danger = Color(light: 0xD4313F, dark: 0xFF6B76)82 public static let onAccent = Color.white83 }8485 /// 4-point spacing scale.86 public enum Space {87 public static let xxs: CGFloat = 488 public static let xs: CGFloat = 889 public static let sm: CGFloat = 1290 public static let md: CGFloat = 1691 public static let lg: CGFloat = 2092 public static let xl: CGFloat = 2893 public static let xxl: CGFloat = 4094 }9596 /// Continuous-corner radii.97 public enum Radius {98 public static let chip: CGFloat = 1099 public static let control: CGFloat = 14100 public static let card: CGFloat = 20101 public static let hero: CGFloat = 28102 /// Paper has almost square corners.103 public static let page: CGFloat = 5104 }105106 public enum Motion {107 /// State changes of controls.108 public static let quick = Animation.snappy(duration: 0.22)109 /// Layout changes, sheets of content moving.110 public static let standard = Animation.smooth(duration: 0.35)111 /// Emphasis (the scan beam, success marks).112 public static let expressive = Animation.spring(response: 0.5, dampingFraction: 0.72)113 }114115 /// Minimum touch target (Apple Human Interface Guidelines).116 public static let minimumTarget: CGFloat = 44117}118119/// Text styles. All of them are built on Dynamic Type styles, so they scale with the user's text size.120public extension Font {121 static let orixDisplay = Font.system(.largeTitle, design: .rounded, weight: .bold)122 static let orixTitle = Font.system(.title2, design: .rounded, weight: .semibold)123 static let orixHeadline = Font.system(.headline, design: .default, weight: .semibold)124 static let orixBody = Font.system(.body)125 static let orixCallout = Font.system(.callout)126 static let orixCaption = Font.system(.caption, weight: .medium)127 static let orixOverline = Font.system(.caption2, weight: .semibold)128 static let orixMono = Font.system(.footnote, design: .monospaced)129}130131private struct ORIXAccentKey: EnvironmentKey {132 static let defaultValue = ORIXAccent.scan133}134135public extension EnvironmentValues {136 var orixAccent: ORIXAccent {137 get { self[ORIXAccentKey.self] }138 set { self[ORIXAccentKey.self] = newValue }139 }140}141