SPB Git

Repository Public

VQProviderLogo.swift 6.3 KB 82 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Sources/VQuantUI/Components/VQProviderLogo.swift3// Description: The five provider marks drawn as SwiftUI Paths, converted from the SVG path data of the web app's4//              client/public/brand/providers/*.svg (viewBox 0 0 24 24, fill = current colour). No asset, no network.5import SwiftUI6import VQuantKit78public enum VQProviderMark: String, Sendable, Hashable, CaseIterable {9    case anthropic, openai, google, openrouter, local1011    /// The SVG path data of the filled marks (the `local` mark is stroked shapes, see `VQProviderLogo`).12    public var svgPathData: String? {13        switch self {14        case .anthropic: return "M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z"15        case .openai: return "M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"16        case .google: return "M11.04 19.32Q12 21.51 12 24q0-2.49.93-4.68.96-2.19 2.58-3.81t3.81-2.55Q21.51 12 24 12q-2.49 0-4.68-.93a12.3 12.3 0 0 1-3.81-2.58 12.3 12.3 0 0 1-2.58-3.81Q12 2.49 12 0q0 2.49-.96 4.68-.93 2.19-2.55 3.81a12.3 12.3 0 0 1-3.81 2.58Q2.49 12 0 12q2.49 0 4.68.96 2.19.93 3.81 2.55t2.55 3.81"17        case .openrouter: return "M16.778 1.844v1.919q-.569-.026-1.138-.032-.708-.008-1.415.037c-1.93.126-4.023.728-6.149 2.237-2.911 2.066-2.731 1.95-4.14 2.75-.396.223-1.342.574-2.185.798-.841.225-1.753.333-1.751.333v4.229s.768.108 1.61.333c.842.224 1.789.575 2.185.799 1.41.798 1.228.683 4.14 2.75 2.126 1.509 4.22 2.11 6.148 2.236.88.058 1.716.041 2.555.005v1.918l7.222-4.168-7.222-4.17v2.176c-.86.038-1.611.065-2.278.021-1.364-.09-2.417-.357-3.979-1.465-2.244-1.593-2.866-2.027-3.68-2.508.889-.518 1.449-.906 3.822-2.59 1.56-1.109 2.614-1.377 3.978-1.466.667-.044 1.418-.017 2.278.02v2.176L24 6.014Z"18        case .local: return nil19        }20    }2122    /// The mark in its 24 × 24 design space.23    public var path: Path { svgPathData.map(VQSVGPath.path) ?? VQProviderMark.localChip }2425    public var displayName: String { displayName(.preferred) }26    /// The provider's name; only "Local model" is ours to translate.27    public func displayName(_ language: VQLanguage) -> String {28        switch self {29        case .anthropic: return "Anthropic"30        case .openai: return "OpenAI"31        case .google: return "Google Gemini"32        case .openrouter: return "OpenRouter"33        case .local: return VQL10n.string("Local model", language)34        }35    }3637    /// local.svg: a rounded chip outline (stroked), its core (filled) and eight pins (stroked).38    static var localChip: Path {39        var p = Path()40        p.addRoundedRect(in: CGRect(x: 5, y: 5, width: 14, height: 14), cornerSize: CGSize(width: 2.5, height: 2.5))41        p.addPath(VQSVGPath.path("M9 2.5V5M15 2.5V5M9 19v2.5M15 19v2.5M2.5 9H5M2.5 15H5M19 9h2.5M19 15h2.5"))42        return p43    }44    static var localCore: Path { Path(roundedRect: CGRect(x: 9.25, y: 9.25, width: 5.5, height: 5.5), cornerRadius: 1) }45}4647/// A provider's mark in the current foreground colour; a neutral glyph for a provider this version does not know.48public struct VQProviderLogo: View {49    private let provider: String50    private let size: CGFloat51    @ScaledMetric(relativeTo: .body) private var unit: CGFloat = 15253    public init(provider: String, size: CGFloat = 14) { self.provider = provider; self.size = size }54    public init(_ mark: VQProviderMark, size: CGFloat = 14) { self.provider = mark.rawValue; self.size = size }5556    @Environment(\.vqTheme) private var theme57    public var body: some View {58        let side = size * unit59        Canvas { context, canvasSize in60            let scale = min(canvasSize.width, canvasSize.height) / 2461            let transform = CGAffineTransform(scaleX: scale, y: scale)62            let ink = GraphicsContext.Shading.foreground63            if let mark = VQProviderMark(rawValue: provider.lowercased()) {64                if mark == .local {65                    context.stroke(VQProviderMark.localChip.applying(transform), with: ink, style: StrokeStyle(lineWidth: 1.6 * scale, lineCap: .round, lineJoin: .round))66                    context.fill(VQProviderMark.localCore.applying(transform), with: ink)67                } else {68                    context.fill(mark.path.applying(transform), with: ink, style: FillStyle(eoFill: false))69                }70            } else {71                // unknown provider: a neutral ring with a dot72                context.stroke(Path(ellipseIn: CGRect(x: 4, y: 4, width: 16, height: 16)).applying(transform), with: ink, lineWidth: 1.6 * scale)73                context.fill(Path(ellipseIn: CGRect(x: 10, y: 10, width: 4, height: 4)).applying(transform), with: ink)74            }75        }76        .frame(width: side, height: side)77        .accessibilityElement()78        .accessibilityLabel(VQProviderMark(rawValue: provider.lowercased())?.displayName(theme.language) ?? provider)79        .accessibilityAddTraits(.isImage)80    }81}82
Files main
Menu

Theme