Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Claude Remote / Codex Remote9// File : Packages/ClaudeRemoteKit/Sources/ClaudeRemoteDesign/Components.swift10// Module : ClaudeRemoteDesign11// Repository : https://git.spboucher.ai/claude-remote-apple12// Project Website : https://claude.spboucher.ai13// Created : 2026-11-2914// Last Modified : 2026-11-2915//16// =============================================================================17// AUTHOR & PROFESSIONAL AFFILIATION18// =============================================================================19//20// Author : Simon-Pierre Boucher21// Position : Professor of Finance22// Institution : Université du Québec en Outaouais (UQO)23// Department : Département des sciences administratives24// Organization : SP Boucher25//26// Website : https://spboucher.ai27// Git : https://git.spboucher.ai28//29// =============================================================================30// OFFICIAL CONTACT DIRECTORY31// =============================================================================32//33// General : info@spboucher.ai34// Professional : contact@spboucher.ai35// Direct : simon@spboucher.ai36// Research : research@spboucher.ai37// Development : dev@spboucher.ai38// Support : support@spboucher.ai39// Security/Admin : admin@spboucher.ai40// Notifications : notifications@spboucher.ai41//42// Preferred Contact: support@spboucher.ai43//44// =============================================================================45// COPYRIGHT & INTELLECTUAL PROPERTY46// =============================================================================47//48// Copyright (c) 202649// Simon-Pierre Boucher50//51// All rights reserved where applicable.52//53// This file is governed by the applicable project license,54// copyright notices, institutional agreements and relevant law.55//56// Unless expressly authorized by the applicable license or57// rights holder, copying, redistribution, sublicensing,58// publication and commercial exploitation are not permitted.59//60// Existing third-party rights and notices remain unaffected.61//62// =============================================================================63// CONFIDENTIALITY & SECURITY64// =============================================================================65//66// Classification : Public67// Distribution : Public repository; use is governed by the project license68// Security Contact : admin@spboucher.ai69//70// Access to this source does not independently grant permission71// to redistribute or disclose confidential materials.72//73// Do not embed credentials, private keys, access tokens,74// certificates or confidential personal information.75//76// =============================================================================77// LICENSE & MAINTENANCE78// =============================================================================79//80// License : None specified (no license file in this repository)81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import ClaudeRemoteModels89import SwiftUI9091/// A number with its label, for dashboards (sessions live, tasks running, CPU…).92public struct StatTile: View {93 /// Direction of change shown next to the value.94 public enum Trend: Hashable, Sendable {95 case up(String), down(String), flat(String)96 var symbolName: String {97 switch self {98 case .up: "arrow.up.right"99 case .down: "arrow.down.right"100 case .flat: "arrow.right"101 }102 }103 var text: String {104 switch self {105 case .up(let t), .down(let t), .flat(let t): t106 }107 }108 var spoken: String {109 switch self {110 case .up(let t): "up \(t)"111 case .down(let t): "down \(t)"112 case .flat(let t): "unchanged \(t)"113 }114 }115 }116117 @Environment(\.crTheme) private var theme118 private let title: String119 private let value: String120 private let unit: String?121 private let trend: Trend?122 private let symbolName: String?123 private let tone: StatusTone124125 public init(_ title: String, value: String, unit: String? = nil, trend: Trend? = nil, symbolName: String? = nil, tone: StatusTone = .neutral) {126 self.title = title127 self.value = value128 self.unit = unit129 self.trend = trend130 self.symbolName = symbolName131 self.tone = tone132 }133134 public var body: some View {135 VStack(alignment: .leading, spacing: CRSpacing.sm) {136 HStack(spacing: CRSpacing.xs) {137 if let symbolName {138 Image(systemName: symbolName).foregroundStyle(tone == .neutral ? CRPalette.muted.color : tone.color(theme: theme))139 }140 Text(title).foregroundStyle(CRPalette.text2.color).lineLimit(1)141 Spacer(minLength: 0)142 }143 .font(.caption.weight(.medium))144 HStack(alignment: .firstTextBaseline, spacing: CRSpacing.xs) {145 Text(value)146 .font(CRTypography.metric)147 .foregroundStyle(tone == .neutral ? CRPalette.text.color : tone.color(theme: theme))148 .lineLimit(1)149 .minimumScaleFactor(0.6)150 if let unit {151 Text(unit).font(.callout).foregroundStyle(CRPalette.muted.color)152 }153 Spacer(minLength: 0)154 if let trend {155 Label(trend.text, systemImage: trend.symbolName)156 .font(.caption)157 .foregroundStyle(CRPalette.muted.color)158 }159 }160 }161 .frame(maxWidth: .infinity, alignment: .leading)162 .crCard(padding: CRSpacing.md)163 .accessibilityElement(children: .ignore)164 .accessibilityLabel(Text(title))165 .accessibilityValue(Text([value, unit, trend?.spoken].compactMap { $0 }.joined(separator: " ")))166 }167}168169/// Titled card grouping related content.170public struct SectionCard<Accessory: View, Content: View>: View {171 private let title: String172 private let subtitle: String?173 private let accessory: Accessory174 private let content: Content175176 public init(_ title: String, subtitle: String? = nil, @ViewBuilder accessory: () -> Accessory, @ViewBuilder content: () -> Content) {177 self.title = title178 self.subtitle = subtitle179 self.accessory = accessory()180 self.content = content()181 }182183 public var body: some View {184 VStack(alignment: .leading, spacing: CRSpacing.md) {185 HStack(alignment: .firstTextBaseline) {186 VStack(alignment: .leading, spacing: CRSpacing.xxs) {187 Text(title).font(.headline).foregroundStyle(CRPalette.text.color).accessibilityAddTraits(.isHeader)188 if let subtitle {189 Text(subtitle).font(.caption).foregroundStyle(CRPalette.muted.color)190 }191 }192 Spacer(minLength: CRSpacing.sm)193 accessory194 }195 content196 }197 .frame(maxWidth: .infinity, alignment: .leading)198 .crCard()199 }200}201202extension SectionCard where Accessory == EmptyView {203 public init(_ title: String, subtitle: String? = nil, @ViewBuilder content: () -> Content) {204 self.init(title, subtitle: subtitle, accessory: { EmptyView() }, content: content)205 }206}207208/// "Nothing here yet" placeholder with an optional action.209public struct EmptyStateView: View {210 private let title: String211 private let message: String?212 private let symbolName: String213 private let actionTitle: String?214 private let action: (@MainActor () -> Void)?215216 public init(_ title: String, message: String? = nil, symbolName: String = "tray", actionTitle: String? = nil, action: (@MainActor () -> Void)? = nil) {217 self.title = title218 self.message = message219 self.symbolName = symbolName220 self.actionTitle = actionTitle221 self.action = action222 }223224 public var body: some View {225 VStack(spacing: CRSpacing.md) {226 Image(systemName: symbolName)227 .font(.largeTitle)228 .foregroundStyle(CRPalette.faint.color)229 .accessibilityHidden(true)230 Text(title).font(.headline).foregroundStyle(CRPalette.text.color)231 if let message {232 Text(message).font(.callout).foregroundStyle(CRPalette.muted.color).multilineTextAlignment(.center)233 }234 if let actionTitle, let action {235 Button(actionTitle, action: action).buttonStyle(CRSecondaryButtonStyle())236 }237 }238 .padding(CRSpacing.xl)239 .frame(maxWidth: .infinity, maxHeight: .infinity)240 .accessibilityElement(children: .combine)241 }242}243244/// Centered spinner with an optional caption.245public struct LoadingStateView: View {246 private let title: String?247248 public init(_ title: String? = nil) {249 self.title = title250 }251252 public var body: some View {253 VStack(spacing: CRSpacing.md) {254 ProgressView()255 if let title {256 Text(title).font(.callout).foregroundStyle(CRPalette.muted.color)257 }258 }259 .padding(CRSpacing.xl)260 .frame(maxWidth: .infinity, maxHeight: .infinity)261 .accessibilityElement(children: .ignore)262 .accessibilityLabel(Text(title ?? "Loading"))263 }264}265266/// Error placeholder with a retry action.267public struct ErrorStateView: View {268 private let title: String269 private let message: String270 private let retryTitle: String271 private let retry: (@MainActor () -> Void)?272273 public init(_ title: String = "Something went wrong", message: String, retryTitle: String = "Try again", retry: (@MainActor () -> Void)? = nil) {274 self.title = title275 self.message = message276 self.retryTitle = retryTitle277 self.retry = retry278 }279280 public var body: some View {281 VStack(spacing: CRSpacing.md) {282 Image(systemName: "exclamationmark.triangle.fill")283 .font(.largeTitle)284 .foregroundStyle(CRPalette.errorVivid.color)285 .accessibilityHidden(true)286 Text(title).font(.headline).foregroundStyle(CRPalette.text.color)287 Text(message).font(.callout).foregroundStyle(CRPalette.text2.color).multilineTextAlignment(.center)288 if let retry {289 Button(retryTitle, action: retry).buttonStyle(CRSecondaryButtonStyle())290 }291 }292 .padding(CRSpacing.xl)293 .frame(maxWidth: .infinity, maxHeight: .infinity)294 .accessibilityElement(children: .combine)295 }296}297298/// Placeholder block shown while content loads.299public struct SkeletonBlock: View {300 private let width: CGFloat?301 private let height: CGFloat302 private let radius: CGFloat303304 public init(width: CGFloat? = nil, height: CGFloat = 14, radius: CGFloat = CRRadius.xs) {305 self.width = width306 self.height = height307 self.radius = radius308 }309310 public var body: some View {311 RoundedRectangle(cornerRadius: radius, style: .continuous)312 .fill(CRPalette.surface2.color)313 .frame(width: width, height: height)314 .frame(maxWidth: width == nil ? .infinity : nil, alignment: .leading)315 .crSkeleton(active: true, redact: false)316 .accessibilityHidden(true)317 }318}319320private struct SkeletonModifier: ViewModifier {321 @Environment(\.accessibilityReduceMotion) private var reduceMotion322 let active: Bool323 let redact: Bool324 @State private var dimmed = false325326 func body(content: Content) -> some View {327 if active {328 content329 .redacted(reason: redact ? .placeholder : [])330 .opacity(reduceMotion ? 0.7 : (dimmed ? 0.45 : 1))331 .animation(reduceMotion ? nil : .easeInOut(duration: 0.9).repeatForever(autoreverses: true), value: dimmed)332 .onAppear { if !reduceMotion { dimmed = true } }333 .allowsHitTesting(false)334 .accessibilityLabel(Text("Loading"))335 } else {336 content337 }338 }339}340341extension View {342 /// Shows the view as a pulsing placeholder while `active` (static under Reduce Motion).343 public func crSkeleton(active: Bool, redact: Bool = true) -> some View {344 modifier(SkeletonModifier(active: active, redact: redact))345 }346}347348/// Auto-updating short relative time ("5m ago"); VoiceOver reads the absolute date.349public struct RelativeTimeText: View {350 private let date: Date?351 private let placeholder: String352353 public init(_ date: Date?, placeholder: String = CRFormat.missing) {354 self.date = date355 self.placeholder = placeholder356 }357358 public var body: some View {359 if let date {360 TimelineView(.periodic(from: .now, by: 30)) { context in361 Text(CRFormat.relative(date, now: context.date))362 }363 .monospacedDigit()364 .accessibilityLabel(Text(CRFormat.absolute(date)))365 #if os(macOS)366 .help(CRFormat.absolute(date))367 #endif368 } else {369 Text(placeholder).accessibilityLabel(Text("Unknown time"))370 }371 }372}373374/// "Label … value" row for detail panes.375public struct KeyValueRow: View {376 private let key: String377 private let value: String378 private let monospaced: Bool379380 public init(_ key: String, value: String?, monospaced: Bool = false) {381 self.key = key382 self.value = value ?? CRFormat.missing383 self.monospaced = monospaced384 }385386 public var body: some View {387 HStack(alignment: .firstTextBaseline, spacing: CRSpacing.md) {388 Text(key).foregroundStyle(CRPalette.muted.color)389 Spacer(minLength: CRSpacing.sm)390 Text(value)391 .font(monospaced ? CRTypography.mono : .callout)392 .foregroundStyle(CRPalette.text.color)393 .multilineTextAlignment(.trailing)394 .textSelection(.enabled)395 }396 .font(.callout)397 .accessibilityElement(children: .ignore)398 .accessibilityLabel(Text(key))399 .accessibilityValue(Text(value))400 }401}402403/// Small rounded tag (project tags, scopes, hosts).404public struct TagChip: View {405 @Environment(\.crTheme) private var theme406 private let text: String407 private let symbolName: String?408 private let tone: StatusTone409410 public init(_ text: String, symbolName: String? = nil, tone: StatusTone = .neutral) {411 self.text = text412 self.symbolName = symbolName413 self.tone = tone414 }415416 public var body: some View {417 HStack(spacing: CRSpacing.xs) {418 if let symbolName { Image(systemName: symbolName).accessibilityHidden(true) }419 Text(text).lineLimit(1)420 }421 .font(.caption)422 .foregroundStyle(tone == .neutral ? CRPalette.text2.color : tone.color(theme: theme))423 .padding(.horizontal, CRSpacing.sm)424 .padding(.vertical, 3)425 .background(tone == .neutral ? CRPalette.surface2.color : tone.fill(theme: theme).opacity(0.14), in: Capsule())426 .accessibilityElement(children: .ignore)427 .accessibilityLabel(Text(text))428 }429}430431/// Usage meter for a 0…1 fraction; turns warning / error above thresholds.432public struct ProgressBar: View {433 @Environment(\.crTheme) private var theme434 private let value: Double?435 private let label: String436 private let warningAt: Double437 private let criticalAt: Double438 private let height: CGFloat439440 /// - Parameter value: fraction 0…1; nil = unknown (empty track, "unknown" for VoiceOver).441 public init(value: Double?, label: String = "Usage", warningAt: Double = 0.75, criticalAt: Double = 0.9, height: CGFloat = 6) {442 self.value = value.map { min(max($0, 0), 1) }443 self.label = label444 self.warningAt = warningAt445 self.criticalAt = criticalAt446 self.height = height447 }448449 /// Tone for a fraction given the thresholds (pure; unit-tested).450 public nonisolated static func tone(for value: Double?, warningAt: Double = 0.75, criticalAt: Double = 0.9) -> StatusTone {451 guard let value else { return .neutral }452 if value >= criticalAt { return .error }453 if value >= warningAt { return .warning }454 return .accent455 }456457 public var body: some View {458 GeometryReader { geo in459 ZStack(alignment: .leading) {460 Capsule().fill(CRPalette.surface2.color)461 if let value {462 Capsule()463 .fill(Self.tone(for: value, warningAt: warningAt, criticalAt: criticalAt).fill(theme: theme))464 .frame(width: max(height, geo.size.width * value))465 }466 }467 }468 .frame(height: height)469 .accessibilityElement()470 .accessibilityLabel(Text(label))471 .accessibilityValue(Text(value.map { CRFormat.percent($0 * 100) } ?? "unknown"))472 }473}474475/// The product mark: a rounded gradient tile with the agent's symbol.476public struct AgentMark: View {477 @Environment(\.crTheme) private var theme478 private let size: CGFloat479480 public init(size: CGFloat = 40) {481 self.size = size482 }483484 public var body: some View {485 RoundedRectangle(cornerRadius: size * 0.28, style: .continuous)486 .fill(theme.gradient)487 .frame(width: size, height: size)488 .overlay(489 Image(systemName: theme.symbolName)490 .font(.system(size: size * 0.46, weight: .semibold))491 .foregroundStyle(.white)492 )493 .accessibilityElement()494 .accessibilityLabel(Text(theme.productName))495 }496}497