// // SettingsPaneView.swift // Museion // // #17 (S1.1): Settings — the Museion Home path, repoint-only (ADR-0004). // #71 (map #20 / #70): the Typography section — three role slots (Body / // Headings / Code), each {face, size}: a Picker over every installed font // family (defaults are being auditioned; shrinks to a curated shortlist // once they settle) + a size field. UserDefaults persistence; re-picking a // face is reset. Chrome stays system. // import AppKit import SwiftUI /// Settings pane. Home control per #17; typography slots per #70. struct SettingsPaneView: View { @Binding var home: URL /// Full family list once per pane lifetime (#70: full list while /// auditioning; the picker's current selection must be listed even when /// NSFontManager omits it — Iowan Old Style is such a case). private var families: [String] { let current = [ UserDefaults.standard.string(forKey: "proseBodyFace"), UserDefaults.standard.string(forKey: "proseHeadingsFace"), UserDefaults.standard.string(forKey: "proseCodeFace"), ].compactMap(\.self) let all = NSFontManager.shared.availableFontFamilies return Array((current + all).uniqued()) } var body: some View { ScrollView { VStack(alignment: .leading, spacing: 24) { contentSection typographySection } .padding(24) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) } .background(DesignTokens.background) } // MARK: Home (#17) private var contentSection: some View { VStack(alignment: .leading, spacing: 12) { Text("Content") .font(.system(size: 13, weight: .semibold)) HStack(spacing: 8) { Text(home.path(percentEncoded: false)) .font(.system(size: 12, design: DesignTokens.mono)) .lineLimit(1) .truncationMode(.middle) .textSelection(.enabled) Spacer(minLength: 12) Button("Choose…") { chooseHome() } } Text( "Repoint-only: Museion never moves content. The Posts list reads this folder's posts/ directory.", ) .font(.callout) .foregroundStyle(DesignTokens.muted) } } // MARK: Typography (#70) private var typographySection: some View { VStack(alignment: .leading, spacing: 12) { Text("Typography") .font(.system(size: 13, weight: .semibold)) Text( "The three prose roles. Both the editor and reading mode use them; a missing face falls back to the system font.", ) .font(.callout) .foregroundStyle(DesignTokens.muted) SlotRow( label: "Body", faceKey: "proseBodyFace", sizeKey: "proseBodySize", families: families, ) SlotRow( label: "Headings", faceKey: "proseHeadingsFace", sizeKey: "proseHeadingsSize", families: families, ) SlotRow( label: "Code", faceKey: "proseCodeFace", sizeKey: "proseCodeSize", families: families, ) } } private func chooseHome() { let panel = NSOpenPanel() panel.canChooseDirectories = true panel.canChooseFiles = false panel.canCreateDirectories = true panel.message = "Choose the folder holding your posts. Museion never moves content." if panel.runModal() == .OK, let url = panel.url { home = url } } } /// One role slot: face picker (full family list) + size stepper. private struct SlotRow: View { let label: String let faceKey: String let sizeKey: String let families: [String] var body: some View { HStack(spacing: 10) { Text(label) .font(.system(size: 12, weight: .semibold)) .frame(width: 76, alignment: .leading) Picker("", selection: faceBinding) { ForEach(families, id: \.self) { family in Text(family).tag(family) } } .labelsHidden() .frame(maxWidth: 320) TextField("", value: sizeBinding, format: .number) .textFieldStyle(.roundedBorder) .frame(width: 56) Text("pt") .font(.system(size: 11, design: DesignTokens.mono)) .foregroundStyle(DesignTokens.muted) } } private var faceBinding: Binding { Binding( get: { UserDefaults.standard.string(forKey: faceKey) ?? "" }, set: { UserDefaults.standard.set($0, forKey: faceKey) }, ) } private var sizeBinding: Binding { Binding( get: { UserDefaults.standard.double(forKey: sizeKey) }, set: { UserDefaults.standard.set(max(6, min(72, $0)), forKey: sizeKey) }, ) } } private extension Array { /// Order-preserving dedupe (face lists merge current + installed). func uniqued() -> [Element] where Element: Hashable { var seen = Set() return filter { seen.insert($0).inserted } } }