SPB Git

Repository Public

Theme.swift 7.4 KB 188 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : Groupe Ka — app iOS native7// File             : Shared/Theme.swift8// Module           : Utilities9// Repository       : https://git.spboucher.ai/groupe-ka-ios10// Project Website  : Not specified11// Created          : 2026-12-0312// Last Modified    : 2026-12-0313//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import UIKit4344// L'identité du Groupe Ka : un dessin d'architecte. Papier, encre, pierre ; des aplats et des filets.45// Le groupe n'a pas de couleur à lui : les seules couleurs sont celles des six sites.46// Mêmes valeurs que les jetons de `src/style.css` du site, en clair et en sombre.4748extension Color {49    init(hex: UInt32, opacite: Double = 1) {50        self.init(.sRGB, red: Double((hex >> 16) & 0xFF) / 255, green: Double((hex >> 8) & 0xFF) / 255,51                  blue: Double(hex & 0xFF) / 255, opacity: opacite)52    }5354    /// `#rrggbb` tel que publié par l'API (`couleur`)55    init?(hexTexte: String?) {56        guard var t = hexTexte?.trimmingCharacters(in: .whitespaces), !t.isEmpty else { return nil }57        if t.hasPrefix("#") { t.removeFirst() }58        guard t.count == 6, let v = UInt32(t, radix: 16) else { return nil }59        self.init(hex: v)60    }6162    static func ka(_ clair: UInt32, _ sombre: UInt32, opClair: CGFloat = 1, opSombre: CGFloat = 1) -> Color {63        Color(UIColor { traits in64            let sombreActif = traits.userInterfaceStyle == .dark65            let v = sombreActif ? sombre : clair66            return UIColor(red: CGFloat((v >> 16) & 0xFF) / 255, green: CGFloat((v >> 8) & 0xFF) / 255,67                           blue: CGFloat(v & 0xFF) / 255, alpha: sombreActif ? opSombre : opClair)68        })69    }70}7172enum Ka {73    /// le papier74    static let papier = Color.ka(0xF4F2EC, 0x111214)75    /// le sol de la pièce, un ton plus clair que le papier76    static let sol = Color.ka(0xFBFAF6, 0x18191C)77    static let encre = Color.ka(0x1A1B1E, 0xEFEDE6)78    static let encre2 = Color.ka(0x44464B, 0xC9C7C1)79    static let encre3 = Color.ka(0x67696E, 0x989A9F)80    /// filets81    static let filet = Color.ka(0xDEDAD0, 0x2A2C30)82    static let filet2 = Color.ka(0xBDB9AE, 0x4A4C51)83    /// ombre portée franche, sans flou84    static let ombre = Color.ka(0x1A1B1E, 0x000000, opClair: 0.11, opSombre: 0.5)8586    /// intensité de la lumière qui entre par une porte, et de la teinte que prend la pièce87    static func lumiere(_ sombre: Bool) -> Double { sombre ? 0.2 : 0.15 }88    static func teinte(_ sombre: Bool) -> Double { sombre ? 0.085 : 0.07 }89    /// part de couleur du seuil d'une baie, mêlée au sol90    static func seuil(_ sombre: Bool) -> Double { sombre ? 0.55 : 0.30 }91}9293extension SiteID {94    /// `--c` : la couleur de la marque95    var couleur: Color {96        switch self {97        case .louka: .ka(0xE96B32, 0xE96B32)98        case .immoka: .ka(0xD12C37, 0xEA5A61)99        case .vraiprix: .ka(0x2540A6, 0x9DB0FF)100        case .valoplex: .ka(0xA23B2A, 0xD9735F)101        case .autoka: .ka(0x0A5F6B, 0x62C6D3)102        case .foodka: .ka(0x8A1F52, 0xE58FB0)103        }104    }105106    /// `--e` : l'encre de la marque107    var encre: Color {108        switch self {109        case .louka: .ka(0x181C1A, 0xF7F6F0)110        case .immoka: .ka(0x1B1D22, 0xF6F3EC)111        case .vraiprix: .ka(0x15171C, 0xF1EFE9)112        case .valoplex: .ka(0x1C1B18, 0xECE5D6)113        case .autoka: .ka(0x14181A, 0xEEF0EC)114        case .foodka: .ka(0x1B2023, 0xF2EEE4)115        }116    }117118    /// `--ct` : la couleur de la marque quand elle porte du texte (contraste suffisant sur le papier)119    var couleurTexte: Color {120        switch self {121        case .louka: .ka(0xB0471A, 0xF08A57)122        case .immoka: .ka(0xB5252F, 0xF0777B)123        case .vraiprix: .ka(0x2540A6, 0x9DB0FF)124        case .valoplex: .ka(0xA23B2A, 0xD9735F)125        case .autoka: .ka(0x0A5F6B, 0x62C6D3)126        case .foodka: .ka(0x8A1F52, 0xE58FB0)127        }128    }129}130131// ── Typographie : Newsreader (titres, grands chiffres) et Geist (interface), polices variables embarquées ──132133enum KaPolice: Sendable {134    case serif, sans135    var nom: String { self == .serif ? "Newsreader16pt16pt-Regular" : "Geist-Regular" }136}137138enum KaFont {139    /// axe `wght` d'une police variable140    private static let axeGraisse = 0x7767_6874141142    static func ui(_ police: KaPolice, _ taille: CGFloat, graisse: CGFloat = 400) -> UIFont {143        let d = UIFontDescriptor(fontAttributes: [144            .name: police.nom,145            UIFontDescriptor.AttributeName(rawValue: "NSCTFontVariationAttribute"): [axeGraisse: graisse],146        ])147        return UIFont(descriptor: d, size: taille)148    }149150    static func police(_ police: KaPolice, _ taille: CGFloat, graisse: CGFloat = 400) -> Font {151        Font(ui(police, taille, graisse: graisse))152    }153154    /// taille mise à l'échelle du texte dynamique, plafonnée pour que les très grandes tailles restent lisibles155    static func echelle(_ taille: CGFloat, style: UIFont.TextStyle, categorie: DynamicTypeSize, plafond: CGFloat = 2.2) -> CGFloat {156        let traits = UITraitCollection(preferredContentSizeCategory: UIContentSizeCategory(categorie))157        let v = UIFontMetrics(forTextStyle: style).scaledValue(for: taille, compatibleWith: traits)158        return min(v, taille * plafond)159    }160}161162private struct KaPoliceModifier: ViewModifier {163    @Environment(\.dynamicTypeSize) private var categorie164    let police: KaPolice165    let taille: CGFloat166    let graisse: CGFloat167    let style: UIFont.TextStyle168    let plafond: CGFloat169170    func body(content: Content) -> some View {171        content.font(KaFont.police(police, KaFont.echelle(taille, style: style, categorie: categorie, plafond: plafond), graisse: graisse))172    }173}174175extension View {176    /// Police de la marque, mise à l'échelle du texte dynamique.177    func ka(_ police: KaPolice, _ taille: CGFloat, graisse: CGFloat = 400, style: UIFont.TextStyle = .body, plafond: CGFloat = 2.2) -> some View {178        modifier(KaPoliceModifier(police: police, taille: taille, graisse: graisse, style: style, plafond: plafond))179    }180}181182/// Filet horizontal d'un point physique.183struct Filet: View {184    var couleur: Color = Ka.filet185    var epaisseur: CGFloat = 1186    var body: some View { Rectangle().fill(couleur).frame(height: epaisseur) }187}188
Files main
Menu

Theme