SPB Git

Repository Public License

ORIXTokens.swift 4.2 KB 78 lines swift

1//2//  ORIX Audio3//  File: ORIXAudio/DesignSystem/Tokens/ORIXTokens.swift4//  Description: ORIX design tokens: adaptive colours, the seven band colours, spacing, radii and type styles.5//6//  Author: Simon-Pierre Boucher7//  Contact: contact@spboucher.ai8//9import SwiftUI10import UIKit1112extension Color {13    init(light: UInt32, dark: UInt32) {14        self.init(uiColor: UIColor { $0.userInterfaceStyle == .dark ? UIColor(hex: dark) : UIColor(hex: light) })15    }16}1718extension UIColor {19    convenience init(hex: UInt32) {20        self.init(red: CGFloat(hex >> 16 & 0xFF) / 255, green: CGFloat(hex >> 8 & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1)21    }22}2324/// The ORIX design system as used by ORIX Audio. Neutral colours, spacing and radii are the ORIX family values (the same25/// numbers as ORIX Scan and ORIX Calc); the accent pair — cyan with violet — and the seven band colours belong to ORIX Audio.26/// The values are copied, not linked: ORIX apps share a look, never a runtime dependency.27enum ORIX {28    enum Palette {29        static let ink = Color(light: 0xF4F5FA, dark: 0x0A0D18)30        static let surface = Color(light: 0xFFFFFF, dark: 0x141828)31        static let raised = Color(light: 0xEEF0F7, dark: 0x1D2236)32        static let hairline = Color(light: 0xDDE0EA, dark: 0x262C42)33        static let text = Color(light: 0x0E1222, dark: 0xF2F4FB)34        static let textSecondary = Color(light: 0x4F566C, dark: 0xB1B8CE)        // family value nudged for WCAG AA at caption sizes35        static let cyan = Color(light: 0x0891B2, dark: 0x22D3EE)36        static let violet = Color(light: 0x7C3AED, dark: 0x8B5CF6)37        static let record = Color(light: 0xE11D48, dark: 0xF43F5E)38        static let warning = Color(light: 0xB86A00, dark: 0xFBBF24)39        static let good = Color(light: 0x12925A, dark: 0x34D399)40        /// Plot backgrounds stay dark in both appearances so spectral colours keep their meaning and contrast.41        static let plot = Color(light: 0x0A0D18, dark: 0x05070E)42        static let plotGrid = Color.white.opacity(0.09)43        static let plotText = Color.white.opacity(0.6)44    }4546    /// Band colours, low → high frequency. Fixed (not appearance-dependent) because they are drawn on the dark plot surface.47    static let bandHex: [UInt32] = [0x7C3AED, 0x3B82F6, 0x06B6D4, 0x22C55E, 0xEAB308, 0xF97316, 0xF43F5E]48    static let bandColors: [Color] = bandHex.map { Color(uiColor: UIColor(hex: $0)) }49    static let bandRGB: [SIMD3<Float>] = bandHex.map { SIMD3(Float($0 >> 16 & 0xFF) / 255, Float($0 >> 8 & 0xFF) / 255, Float($0 & 0xFF) / 255) }50    /// Short labels shown next to the band colours so the mapping never depends on colour alone.51    static let bandShortNames = ["SUB", "BASS", "LO-MID", "MID", "UP-MID", "PRES", "BRIL"]5253    /// Mixes the band colours by measured band shares (weights sum to 1).54    static func blend(_ fractions: [Float]) -> Color {55        var rgb = SIMD3<Float>(repeating: 0)56        var total: Float = 057        for (i, f) in fractions.enumerated() where i < bandRGB.count { rgb += bandRGB[i] * f; total += f }58        guard total > 0 else { return Palette.plotText }59        rgb /= total60        return Color(red: Double(rgb.x), green: Double(rgb.y), blue: Double(rgb.z))61    }6263    static let brandGradient = LinearGradient(colors: [Color(uiColor: UIColor(hex: 0x22D3EE)), Color(uiColor: UIColor(hex: 0x8B5CF6))], startPoint: .topLeading, endPoint: .bottomTrailing)64    static let spectrumGradient = LinearGradient(colors: bandColors, startPoint: .leading, endPoint: .trailing)6566    enum Radius { static let card: CGFloat = 22; static let control: CGFloat = 14; static let plot: CGFloat = 16 }67    enum Space { static let xs: CGFloat = 4; static let s: CGFloat = 8; static let m: CGFloat = 12; static let l: CGFloat = 16; static let xl: CGFloat = 24 }68}6970extension Font {71    /// Large tabular numerals for timers and readouts. Scales with Dynamic Type.72    static func orixNumeral(_ style: Font.TextStyle = .largeTitle, weight: Font.Weight = .light) -> Font {73        .system(style, design: .rounded, weight: weight).monospacedDigit()74    }75    static let orixCaption = Font.caption2.weight(.semibold)76    static let orixReadout = Font.system(.footnote, design: .monospaced).weight(.medium)77}78
Files main
Menu

Theme