import SwiftUI /// Help → Colophon: every open-source project and typeface the app ships, /// what it is, what Base uses it for, who made it, its licence and the /// licence's text (Resources/Colophon.json, scripts/colophon.py, with /// estilo's catalog's words where it has the project). public enum BaseColophon { public struct Entry: Decodable, Hashable, Identifiable, Sendable { public struct Licence: Decodable, Hashable, Sendable { public let spdx: String; public let name: String } public let id: String public let name: String /// Catalog keys: what it is, and what Base uses it for, are copy. public let blurbKey: String public let usageKey: String public var blurb: String { BaseText.text(blurbKey) } public var usage: String { BaseText.text(usageKey) } public let author: String public let licence: Licence public let home: String public let source: String public let licenceText: String public let platforms: [String]? } public struct Section: Decodable, Hashable, Identifiable, Sendable { public let id: String public let entries: [Entry] } private struct File: Decodable { let sections: [Section] } static func heading(_ section: String) -> String { switch section { case "typefaces": BaseText.text("native.colophon.section.typefaces") default: BaseText.text("native.colophon.section.swift") } } #if os(macOS) static let platform = "mac" #else static let platform = "ios" #endif /// This platform's sections; nil when the file is missing (a broken build). public static let sections: [Section] = { guard let url = Bundle.module.url(forResource: "Colophon", withExtension: "json"), let data = try? Data(contentsOf: url), let file = try? JSONDecoder().decode(File.self, from: data) else { return [] } return file.sections.map { s in Section(id: s.id, entries: s.entries.filter { $0.platforms?.contains(platform) ?? true }) }.filter { !$0.entries.isEmpty } }() } /// The Colophon's window: the list, and an entry's details beside it. public struct ColophonView: View { @State private var chosen: BaseColophon.Entry? public init() {} public static var title: String { BaseText.text("native.colophon") } public var body: some View { NavigationSplitView { List(selection: $chosen) { Section { Text(BaseText.text("native.colophon.intro")).fixedSize(horizontal: false, vertical: true) } ForEach(BaseColophon.sections) { section in Section(BaseColophon.heading(section.id)) { ForEach(section.entries) { entry in VStack(alignment: .leading, spacing: 2) { Text(verbatim: entry.name) Text(verbatim: entry.licence.name).font(.subheadline).foregroundStyle(.secondary) } .tag(entry) .accessibilityElement(children: .combine) } } } } .navigationSplitViewColumnWidth(min: 220, ideal: 260) } detail: { if let entry = chosen { ScrollView { VStack(alignment: .leading, spacing: 12) { Text(verbatim: entry.name).font(.title2.weight(.semibold)) Text(verbatim: entry.blurb) Text(verbatim: entry.usage).foregroundStyle(.secondary) LabeledContent(BaseText.text("native.colophon.by"), value: entry.author) LabeledContent(BaseText.text("native.colophon.licence"), value: entry.licence.name) if let home = URL(string: entry.home) { Link(BaseText.text("native.colophon.home"), destination: home) } if let source = URL(string: entry.source), entry.source != entry.home { Link(BaseText.text("native.colophon.source"), destination: source) } Text(verbatim: entry.licenceText).font(.callout.monospaced()).textSelection(.enabled) } .padding(20) .frame(maxWidth: .infinity, alignment: .leading) } } else { Text(verbatim: "").frame(maxWidth: .infinity, maxHeight: .infinity) } } .frame(minWidth: 680, minHeight: 460) } }