SPB Git

Repository Public

DesignSystem.swift 11.7 KB 243 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : MacLustr SMS Gateway9// File             : ios/MacLustrSMS/UI/DesignSystem.swift10// Description      : Identité visuelle : encre sombre, accent vert, composants11//                    sobres (carte, pastille d'état, logo, jauge de segments).12// Module           : ios13// Repository       : https://git.spboucher.ai/maclustr-sms14// Project Website  : https://sms.spboucher.ai15// Created          : 2026-11-3016// Last Modified    : 2026-11-3017//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author           : Simon-Pierre Boucher23// Position         : Professor of Finance24// Institution      : Université du Québec en Outaouais (UQO)25// Department       : Département des sciences administratives26// Organization     : SP Boucher27//28// Website          : https://spboucher.ai29// Git              : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General          : info@spboucher.ai36// Professional     : contact@spboucher.ai37// Direct           : simon@spboucher.ai38// Research         : research@spboucher.ai39// Development      : dev@spboucher.ai40// Support          : support@spboucher.ai41// Security/Admin   : admin@spboucher.ai42// Notifications    : notifications@spboucher.ai43//44// Preferred Contact: admin@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification   : Public69// Distribution     : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License          : None specified (no license file in this repository)83// Maintainer       : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import SwiftUI91import UIKit9293enum Theme {94    private static func dyn(_ dark: UInt32, _ light: UInt32) -> Color {95        Color(UIColor { $0.userInterfaceStyle == .dark ? UIColor(hex: dark) : UIColor(hex: light) })96    }97    static let bg = dyn(0x0F1317, 0xF4F5F2)98    static let panel = dyn(0x161B21, 0xFFFFFF)99    static let panel2 = dyn(0x1D242C, 0xECEFEA)100    static let line = dyn(0x2A323B, 0xD9DDD6)101    static let text = dyn(0xE9ECE8, 0x171C20)102    static let muted = dyn(0x8E99A3, 0x5B666F)103    static let faint = dyn(0x5D6871, 0x8B959C)104    static let accent = dyn(0x5FBF8F, 0x1F7A54)105    static let onAccent = dyn(0x0C1210, 0xFFFFFF)106    static let ok = accent107    static let warn = dyn(0xD9A441, 0x9A6B0C)108    static let bad = dyn(0xE0685C, 0xB83A2E)109    static let info = dyn(0x7FA7C9, 0x2F6492)110    static let bubbleOut = dyn(0x2F7D5B, 0x2F9E6F)111    static func tone(_ t: Tone) -> Color { switch t { case .ok: ok; case .info: info; case .warn: warn; case .bad: bad; case .neutral: muted } }112}113extension UIColor {114    convenience init(hex: UInt32) { self.init(red: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1) }115}116117/// Logo : carte SIM à coin coupé, trois barres de signal.118struct LogoMark: View {119    var size: CGFloat = 44120    var body: some View {121        Canvas { ctx, s in122            let w = s.width, h = s.height123            var card = Path()124            card.move(to: CGPoint(x: w * 0.24, y: h * 0.10)); card.addLine(to: CGPoint(x: w * 0.58, y: h * 0.10)); card.addLine(to: CGPoint(x: w * 0.78, y: h * 0.30))125            card.addLine(to: CGPoint(x: w * 0.78, y: h * 0.90)); card.addLine(to: CGPoint(x: w * 0.24, y: h * 0.90)); card.closeSubpath()126            ctx.stroke(card, with: .color(Theme.text), style: StrokeStyle(lineWidth: w * 0.06, lineJoin: .round))127            let base = h * 0.78, bw = w * 0.085128            for (i, hgt) in [0.16, 0.28, 0.40].enumerated() {129                let x = w * (0.345 + Double(i) * 0.125)130                ctx.fill(Path(roundedRect: CGRect(x: x, y: base - h * hgt, width: bw, height: h * hgt), cornerRadius: bw * 0.2), with: .color(i == 2 ? Theme.text : Theme.accent))131            }132        }133        .frame(width: size, height: size)134        .accessibilityHidden(true)135    }136}137138struct Card<Content: View>: View {139    var padding: CGFloat = 16140    @ViewBuilder var content: Content141    var body: some View {142        content.padding(padding).frame(maxWidth: .infinity, alignment: .leading)143            .background(Theme.panel, in: RoundedRectangle(cornerRadius: 14, style: .continuous))144            .overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder(Theme.line, lineWidth: 1))145    }146}147struct SectionLabel: View {148    let text: String149    init(_ text: String) { self.text = text }150    var body: some View { Text(text.uppercased()).font(.caption.weight(.semibold)).kerning(0.9).foregroundStyle(Theme.muted).accessibilityAddTraits(.isHeader) }151}152struct StatusDot: View { let tone: Tone; var body: some View { Circle().fill(Theme.tone(tone)).frame(width: 8, height: 8).accessibilityHidden(true) } }153struct StatusBadge: View {154    let status: MessageStatus155    var body: some View {156        Text(status.label).font(.caption.weight(.medium)).foregroundStyle(Theme.tone(status.tone))157            .padding(.horizontal, 8).padding(.vertical, 3)158            .overlay(Capsule().strokeBorder(Theme.tone(status.tone).opacity(0.45), lineWidth: 1))159    }160}161struct Banner: View {162    let text: String; var tone: Tone = .warn; var symbol: String = "exclamationmark.triangle"163    var body: some View {164        HStack(alignment: .top, spacing: 10) {165            Image(systemName: symbol).foregroundStyle(Theme.tone(tone)).accessibilityHidden(true)166            Text(text).font(.footnote).foregroundStyle(Theme.text).fixedSize(horizontal: false, vertical: true)167        }168        .padding(12).frame(maxWidth: .infinity, alignment: .leading)169        .background(Theme.tone(tone).opacity(0.12), in: RoundedRectangle(cornerRadius: 12, style: .continuous))170        .overlay(RoundedRectangle(cornerRadius: 12, style: .continuous).strokeBorder(Theme.tone(tone).opacity(0.5), lineWidth: 1))171    }172}173174/// Jauge de segments : dix cases (le maximum accepté), remplies au fil de la frappe ; la case en cours montre son remplissage.175struct SegmentGauge: View {176    let info: SegmentInfo177    var body: some View {178        let over = info.segments > Segments.maxSegments179        let fillOfCurrent = info.units == 0 ? 0 : Double(info.units - (info.segments - 1) * info.perSegment) / Double(info.perSegment)180        HStack(spacing: 3) {181            ForEach(0..<Segments.maxSegments, id: \.self) { i in182                GeometryReader { g in183                    ZStack(alignment: .leading) {184                        RoundedRectangle(cornerRadius: 2).fill(Theme.line)185                        RoundedRectangle(cornerRadius: 2).fill(over ? Theme.bad : info.encoding == .ucs2 ? Theme.warn : Theme.accent)186                            .frame(width: g.size.width * (i < info.segments - 1 ? 1 : i == info.segments - 1 && info.units > 0 ? min(max(fillOfCurrent, 0.06), 1) : 0))187                    }188                }189                .frame(height: 6)190            }191        }192        .accessibilityElement()193        .accessibilityLabel("\(info.segments) segment\(info.segments > 1 ? "s" : "") sur \(Segments.maxSegments)")194    }195}196197/// Bulle telle que le destinataire la verra : texte brut, sans mise en forme.198struct Bubble: View {199    let text: String; var outgoing = true; var footer: String? = nil200    var body: some View {201        VStack(alignment: outgoing ? .trailing : .leading, spacing: 3) {202            Text(text.isEmpty ? " " : text).font(.body).foregroundStyle(outgoing ? Color.white : Theme.text)203                .padding(.horizontal, 14).padding(.vertical, 9)204                .background(outgoing ? Theme.bubbleOut : Theme.panel2, in: UnevenRoundedRectangle(topLeadingRadius: 18, bottomLeadingRadius: outgoing ? 18 : 5, bottomTrailingRadius: outgoing ? 5 : 18, topTrailingRadius: 18, style: .continuous))205                .textSelection(.enabled)206            if let footer { Text(footer).font(.caption2).foregroundStyle(Theme.faint) }207        }208        .frame(maxWidth: .infinity, alignment: outgoing ? .trailing : .leading)209        .padding(outgoing ? .leading : .trailing, 44)210    }211}212struct PrimaryButtonStyle: ButtonStyle {213    @Environment(\.isEnabled) private var enabled214    func makeBody(configuration: Configuration) -> some View {215        configuration.label.font(.headline).foregroundStyle(Theme.onAccent).frame(maxWidth: .infinity).padding(.vertical, 14)216            .background(Theme.accent.opacity(enabled ? (configuration.isPressed ? 0.8 : 1) : 0.35), in: RoundedRectangle(cornerRadius: 13, style: .continuous))217    }218}219struct QuietButtonStyle: ButtonStyle {220    var tone: Color = Theme.text221    func makeBody(configuration: Configuration) -> some View {222        configuration.label.font(.subheadline.weight(.medium)).foregroundStyle(tone).padding(.horizontal, 14).padding(.vertical, 9)223            .background(Theme.panel2.opacity(configuration.isPressed ? 0.6 : 1), in: RoundedRectangle(cornerRadius: 10, style: .continuous))224            .overlay(RoundedRectangle(cornerRadius: 10, style: .continuous).strokeBorder(Theme.line, lineWidth: 1))225    }226}227extension Date {228    var shortStamp: String {229        let f = DateFormatter(); f.locale = Locale(identifier: "fr_CA")230        f.dateFormat = Calendar.current.isDateInToday(self) ? "HH:mm:ss" : "d MMM HH:mm"231        return f.string(from: self)232    }233    var ago: String {234        let s = Date.now.timeIntervalSince(self)235        if s < 5 { return "à l'instant" }; if s < 60 { return "il y a \(Int(s)) s" }; if s < 3600 { return "il y a \(Int(s / 60)) min" }236        if s < 86400 { return "il y a \(Int(s / 3600)) h" }; return "il y a \(Int(s / 86400)) j"237    }238}239struct Screen<Content: View>: View {240    @ViewBuilder var content: Content241    var body: some View { ScrollView { VStack(alignment: .leading, spacing: 14) { content }.padding(16).padding(.bottom, 28) }.background(Theme.bg).scrollDismissesKeyboard(.interactively) }242}243
Files main
Menu

Theme