SPB Git

Repository Public

Theme.swift 7.1 KB 156 lines swift

1//2//  Auto-Ka iOS v23//  File: AutoKa/Design/Theme.swift4//  Description: jetons de design — identité « Portière » : givre, asphalte, bleu pétrole. Mêmes noms que5//               brand/tokens.css. Deux thèmes (jour, nuit). Aucun dégradé décoratif, aucun verre, aucune lueur.6//7//  Author: Simon-Pierre Boucher8//  Contact: contact@spboucher.ai9//1011import SwiftUI12import UIKit1314extension Color {15    /// Couleur adaptative à partir de deux valeurs hexadécimales (jour, nuit).16    init(light: UInt32, dark: UInt32, lightAlpha: Double = 1, darkAlpha: Double = 1) {17        self.init(uiColor: UIColor { trait in18            let (hex, a) = trait.userInterfaceStyle == .dark ? (dark, darkAlpha) : (light, lightAlpha)19            return UIColor(red: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255,20                           blue: CGFloat(hex & 0xFF) / 255, alpha: a)21        })22    }2324    init(hex: UInt32, alpha: Double = 1) {25        self.init(.sRGB, red: Double((hex >> 16) & 0xFF) / 255, green: Double((hex >> 8) & 0xFF) / 255,26                  blue: Double(hex & 0xFF) / 255, opacity: alpha)27    }28}2930enum Theme {31    // --- Jetons sémantiques (jour / nuit) : brand/tokens.css -----------------------32    static let bg = Color(light: 0xF2F3EF, dark: 0x0F1315)          // givre33    static let bg2 = Color(light: 0xE9EBE6, dark: 0x0A0D0F)34    static let surface = Color(light: 0xFFFFFF, dark: 0x171C1F)     // papier35    static let surface2 = Color(light: 0xECEEE9, dark: 0x1F2529)36    static let surface3 = Color(light: 0xE0E3DD, dark: 0x293035)37    static let ink = Color(light: 0x14181A, dark: 0xEEF0EC)         // asphalte38    static let ink2 = Color(light: 0x40474A, dark: 0xB7BCB8)39    static let ink3 = Color(light: 0x60686B, dark: 0x8A9296)        // gravier40    static let line = Color(light: 0xDDE0DA, dark: 0x232A2E)41    static let line2 = Color(light: 0xC5C9C2, dark: 0x363F44)42    /// Pétrole : la seule couleur de marque (action principale, liens, sélection, le battant, « Ka »).43    static let brand = Color(light: 0x0A5F6B, dark: 0x62C6D3)44    static let brandStrong = Color(light: 0x07454E, dark: 0x8FDAE4)45    static let brandInk = Color(light: 0xFFFFFF, dark: 0x06262B)46    static let brandSoft = Color(light: 0xD7E8EA, dark: 0x10323A)4748    // --- Verdicts : échelle divergente froid → neutre → chaud, descriptive et non morale ---49    static let good = Color(light: 0x1B5E9B, dark: 0x86B4F2)        // cobalt : sous le marché50    static let goodSoft = Color(light: 0xDBE7F4, dark: 0x15273F)51    static let fair = Color(light: 0x595E5C, dark: 0xA4A8A4)        // gris : dans le marché52    static let fairSoft = Color(light: 0xE7E9E4, dark: 0x24282A)53    static let high = Color(light: 0x8C5800, dark: 0xE5B05A)        // ocre : au-dessus du marché54    static let highSoft = Color(light: 0xF5E8C9, dark: 0x33291A)55    static let bad = Color(light: 0x931F27, dark: 0xFF9C92)         // brique : erreurs, retraits56    static let badSoft = Color(light: 0xF7DFDB, dark: 0x3B201E)57    /// Texte de l'étiquette de prix posée sur la couleur de verdict.58    static let tagInk = Color(light: 0xFFFFFF, dark: 0x0B1420)59    /// Bande du 1er au 3e quartile de la fourchette de marché.60    static let band = Color(light: 0xCFD3CC, dark: 0x3A4449)6162    // --- Pièces du battant animé ---------------------------------------------------63    static let door = Color(light: 0x0A5F6B, dark: 0x2F9AA8)64    static let doorGlass = Color(light: 0x07454E, dark: 0x06262B, lightAlpha: 0.46, darkAlpha: 0.5)65    static let doorEdge = Color(light: 0x07454E, dark: 0x1B6F7A)66    static let doorHandle = Color(light: 0xF2F3EF, dark: 0xEEF0EC)67    static let sill = Color(light: 0x14181A, dark: 0xEEF0EC)68    static let doorShade = Color(hex: 0x04181C)6970    // rayons : étiquettes 6 · contrôles 8 · cartes 10 · photos 1271    static let radiusTag: CGFloat = 672    static let radiusControl: CGFloat = 873    static let radiusCard: CGFloat = 1074    static let radiusPhoto: CGFloat = 127576    static func color(for position: PriceVerdict.Position?) -> Color {77        switch position {78        case .below: good79        case .within: fair80        case .above: high81        case .farAbove: bad82        case .unknown, nil: ink383        }84    }8586    static func softColor(for position: PriceVerdict.Position?) -> Color {87        switch position {88        case .below: goodSoft89        case .within: fairSoft90        case .above: highSoft91        case .farAbove: badSoft92        case .unknown, nil: surface293        }94    }9596    /// Icône de position du verdict : l'étiquette à gauche de la médiane, dessus, à droite.97    static func icon(for position: PriceVerdict.Position?) -> String {98        switch position {99        case .below: "ic-verdict-sous"100        case .above, .farAbove: "ic-verdict-dessus"101        default: "ic-verdict-dans"102        }103    }104105    /// Couleur d'un code ou d'une position de verdict du service (répartitions, filtres).106    static func color(forCode code: String) -> Color { color(for: VerdictRules.position(forCode: code)) }107}108109extension Font {110    /// Chiffres et libellés d'interface en grand : SF Pro. La taille suit Dynamic Type.111    static func display(_ size: CGFloat, weight: Font.Weight = .semibold) -> Font {112        .system(size: scaled(size), weight: weight, design: .default)113    }114115    /// Titres éditoriaux : New York (serif système), romain, graisse 500. La taille suit Dynamic Type.116    static func editorial(_ size: CGFloat, weight: Font.Weight = .medium) -> Font {117        .system(size: scaled(size), weight: weight, design: .serif)118    }119120    /// Taille mise à l'échelle du réglage « Taille du texte », selon la courbe du style système le plus proche.121    static func scaled(_ size: CGFloat) -> CGFloat {122        let style: UIFont.TextStyle = switch size {123        case 30...: .largeTitle124        case 25..<30: .title1125        case 21..<25: .title2126        case 18..<21: .title3127        default: .body128        }129        return UIFontMetrics(forTextStyle: style).scaledValue(for: size).rounded()130    }131}132133extension View {134    /// Carte : surface, filet, coins mesurés. À réserver aux blocs qui doivent se détacher ; ailleurs, des filets.135    func cardStyle(padding: CGFloat = 16, radius: CGFloat = Theme.radiusCard) -> some View {136        self.padding(padding)137            .background(Theme.surface, in: RoundedRectangle(cornerRadius: radius, style: .continuous))138            .overlay(RoundedRectangle(cornerRadius: radius, style: .continuous).strokeBorder(Theme.line, lineWidth: 1))139    }140141    /// Sur-titre : capitales espacées, gravier. Rare.142    func eyebrowStyle() -> some View {143        self.font(.caption2.weight(.semibold)).tracking(0.9).textCase(.uppercase).foregroundStyle(Theme.ink3)144    }145146    /// Chiffres tabulaires.147    func num() -> some View { self.monospacedDigit() }148149    /// Fond opaque d'un contrôle posé sur la carte géographique ou sur une photo (pas de verre décoratif).150    func solidControl<S: InsettableShape>(_ shape: S) -> some View {151        self.background(Theme.surface, in: shape)152            .overlay(shape.strokeBorder(Theme.line2, lineWidth: 1))153            .shadow(color: .black.opacity(0.10), radius: 5, y: 2)154    }155}156
Files main
Menu

Theme