Repository Public
1// ORIX DJ2// File: App/Sources/DesignSystem/Tokens.swift3// Description: ORIX design tokens for ORIX DJ: family palette, deck colours, spacing, radii and type.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import AppKit8import SwiftUI910extension Color {11 /// A colour with distinct light and dark values (sRGB hex).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, alpha: CGFloat = 1) {23 self.init(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: alpha)24 }25}2627/// The family palette, shared with the other ORIX apps, with ORIX DJ's own accents.28enum ORIX {29 /// Text colours reach at least 4.5:1 (WCAG AA) on canvas, surface and raised surface, in both appearances.30 enum Palette {31 static let canvas = Color(light: 0xF4F5FA, dark: 0x0A0D18)32 static let surface = Color(light: 0xFFFFFF, dark: 0x141828)33 static let surfaceRaised = Color(light: 0xEEF0F7, dark: 0x1D2236)34 static let well = Color(light: 0xE3E6F0, dark: 0x070912)35 static let hairline = Color(light: 0xDDE0EA, dark: 0x262C42)36 static let textPrimary = Color(light: 0x0E1222, dark: 0xF2F4FB)37 static let textSecondary = Color(light: 0x596078, dark: 0xA3AAC2)38 static let textTertiary = Color(light: 0x5F657D, dark: 0x9097B0)39 static let success = Color(light: 0x0A7446, dark: 0x34D399)40 static let warning = Color(light: 0x8F5200, dark: 0xFBBF24)41 static let danger = Color(light: 0xC0283A, dark: 0xFF6B76)42 /// ORIX DJ's accent pair: violet over the family cyan.43 static let accent = Color(light: 0x6541E0, dark: 0x9B7CFF)44 static let accentSecondary = Color(light: 0x0B6E8A, dark: 0x22D3EE)45 /// Text on a lit (tinted) control: white on the darker light-mode tints, near-black on the bright dark-mode ones.46 static let onTint = Color(light: 0xFFFFFF, dark: 0x0B0D14)47 /// The CUE colour: amber, darkened in light mode to keep 4.5:1 on light surfaces.48 static let cue = Color(light: 0x8F5200, dark: 0xFF9F0A)49 /// Dark waveform well, the same in both appearances so waveform colours keep their contrast.50 static let waveformWell = Color(hex: 0x05070E)51 }5253 /// One colour per deck, used for every element that belongs to that deck. Letters always accompany the colour.54 static func deck(_ index: Int) -> Color {55 switch index {56 case 0: Color(light: 0x0B6E8A, dark: 0x22D3EE)57 case 1: Color(light: 0xB4500F, dark: 0xFF9F43)58 case 2: Color(light: 0x6541E0, dark: 0xA78BFA)59 default: Color(light: 0x0A7446, dark: 0x4ADE80)60 }61 }6263 static let hotCueColors: [Color] = [0xFF4B3A, 0xFF9F43, 0xFBBF24, 0x4ADE80, 0x22D3EE, 0x4D8DFF, 0xA78BFA, 0xF472B6].map { Color(hex: $0) }64 static let hotCueHex: [UInt32] = [0xFF4B3A, 0xFF9F43, 0xFBBF24, 0x4ADE80, 0x22D3EE, 0x4D8DFF, 0xA78BFA, 0xF472B6]6566 enum Space {67 static let xxs: CGFloat = 468 static let xs: CGFloat = 869 static let sm: CGFloat = 1270 static let md: CGFloat = 1671 static let lg: CGFloat = 2472 static let xl: CGFloat = 3273 }7475 enum Radius {76 static let chip: CGFloat = 677 static let control: CGFloat = 878 static let card: CGFloat = 1479 }8081 enum Typeface {82 static func readout(_ size: CGFloat = 28) -> Font { .system(size: size, weight: .semibold, design: .rounded).monospacedDigit() }83 static let label = Font.system(size: 10, weight: .semibold).smallCaps()84 static let value = Font.system(size: 12, weight: .medium).monospacedDigit()85 static let caption = Font.system(size: 11).monospacedDigit()86 static let mono = Font.system(size: 12, design: .monospaced)87 static let title = Font.system(size: 15, weight: .semibold)88 }89}9091/// "3:07.4" style time.92func formatTime(_ seconds: Double, tenths: Bool = true) -> String {93 guard seconds.isFinite else { return "–:––" }94 let s = max(0, seconds)95 let m = Int(s) / 6096 return tenths ? String(format: "%d:%04.1f", m, s - Double(m * 60)) : String(format: "%d:%02d", m, Int(s) % 60)97}9899func formatBPM(_ bpm: Double) -> String { bpm > 0 ? String(format: "%.1f", bpm) : "–" }100