feat(reading): polish typography, externalize CSS
Critique-directed polish of the reading surface (#72 ruling: pipeline calm, surface not-calm) plus the single-user typography rework: - Flow: leading 1.5, paragraph gap tightened; heading ladder rescaled (h1 1.15x / h2 0.85x / h3 body-face semibold) with cling margins, hN+hN suppression, no title dead space - Constructs: confident blockquote (near-ink text, 3px rail, nesting degrades), booktabs tables, tinted code panels, relative inline code - Fonts hardcoded for Alexander's faces: Valkyrie OT B 17 body, Concourse OT Semibold headings, UbuntuMono 14 code; 66ch measure - Stylesheet moved to Museion/Resources/reading.css, read fresh per page build — Debug builds load the repo copy (#filePath), so CSS edits hot-reload on the next reading toggle - Settings Typography/Text Flow sections and all flow-key plumbing deleted (56 insertions, 417 deletions) Refs #72, #78. Detector: 192 findings -> 0. Build + 93 tests green. [Generated by AI]
This commit is contained in:
1 parent
eae86dd2ef
commit
4cb753d17f
9 files changed
+134
-417
No files matched your search
+22
-139
@@ -2,137 +2,48 @@
|
||||
// ProseTypography.swift
|
||||
// Museion
|
||||
//
|
||||
// #71 (S1.2, map #20 / #70): the three role slots — Body / Headings / Code —
|
||||
// each {face, size}, persisted in UserDefaults (six values), read by BOTH
|
||||
// prose surfaces (styled-source editing + reading). Machine-local faces,
|
||||
// nothing bundled; a missing face falls back to the system font silently.
|
||||
// Chrome stays on system faces.
|
||||
//
|
||||
// Resolution note (#70 deviation, probed in-session): family+weight lookup
|
||||
// misresolves Concourse OT — Thin and Book both advertise weight 4, and
|
||||
// NSFontManager picks Thin. Faces therefore resolve through the family's
|
||||
// member list: prefer the Book/Regular member, else the middle weight.
|
||||
// #72 rework: single-user app — the prose typography is hardcoded constants,
|
||||
// dialled in on Alexander's exact fonts (Valkyrie OT B body / Concourse OT
|
||||
// headings / UbuntuMono code). The Settings typography/flow sections are
|
||||
// gone; the reading surface's look lives in Museion/Resources/reading.css
|
||||
// (editable while the app runs). These constants feed the EDITING surface;
|
||||
// the CSS :root block is the source of truth for reading.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
|
||||
/// Prose typography slots (#70). Static computed accessors — surfaces read
|
||||
/// on render; the Settings pane writes UserDefaults and the surfaces rebuild
|
||||
/// (pane re-entry rebuilds the editor; reading rebuilds per toggle).
|
||||
/// Prose typography constants (#72 rework). The editing surface reads these;
|
||||
/// reading mode reads Resources/reading.css.
|
||||
nonisolated enum ProseTypography {
|
||||
/// v1 defaults (#70): Body = Concourse OT Book 17, Headings = Iowan Old
|
||||
/// Style bold 26, Code = UbuntuMono Nerd Font Mono 13.
|
||||
static let defaultBodyFace = "Concourse OT"
|
||||
static let defaultHeadingsFace = "Iowan Old Style"
|
||||
static let defaultCodeFace = "UbuntuMono Nerd Font Mono"
|
||||
static let defaultBodySize: Double = 17
|
||||
static let defaultHeadingsSize: Double = 26
|
||||
static let defaultCodeSize: Double = 13
|
||||
/// Text flow (#71 polish): line-height multiple + paragraph/heading
|
||||
/// spacing measured in body lines — different faces need different flow.
|
||||
static let defaultLineHeight: Double = 1.25
|
||||
static let defaultParagraphSpacingLines: Double = 1
|
||||
static let defaultHeadingSpacingLines: Double = 2
|
||||
/// Body = Valkyrie OT B (the screen cut; CoreText unifies the OT family
|
||||
/// as "Valkyrie OT" — only B members installed, no A/B ambiguity).
|
||||
static var bodyFont: NSFont { NSFont(name: "ValkyrieOTBRegular", size: 17) ?? NSFont.systemFont(ofSize: 17) }
|
||||
|
||||
/// Register the six defaults once at app start.
|
||||
static func registerDefaults() {
|
||||
UserDefaults.standard.register(defaults: [
|
||||
"proseBodyFace": defaultBodyFace,
|
||||
"proseBodySize": defaultBodySize,
|
||||
"proseHeadingsFace": defaultHeadingsFace,
|
||||
"proseHeadingsSize": defaultHeadingsSize,
|
||||
"proseCodeFace": defaultCodeFace,
|
||||
"proseCodeSize": defaultCodeSize,
|
||||
"proseLineHeight": defaultLineHeight,
|
||||
"proseParagraphSpacingLines": defaultParagraphSpacingLines,
|
||||
"proseHeadingSpacingLines": defaultHeadingSpacingLines,
|
||||
])
|
||||
}
|
||||
/// Headings = Concourse OT (the designer's own pairing with Valkyrie);
|
||||
/// Semibold carries heading weight better than Book on screen.
|
||||
static var headingFont: NSFont { NSFont(name: "ConcourseOT6Semibold", size: 26) ?? NSFont.systemFont(ofSize: 26, weight: .semibold) }
|
||||
|
||||
private static func face(_ key: String, defaultFace: String) -> String {
|
||||
UserDefaults.standard.string(forKey: key) ?? defaultFace
|
||||
}
|
||||
/// Code slot (inline code, fenced blocks, editing syntax dim).
|
||||
static var codeFont: NSFont { NSFont(name: "UbuntuMonoNFM", size: 14) ?? NSFont.monospacedSystemFont(ofSize: 14, weight: .regular) }
|
||||
|
||||
private static func size(_ key: String, defaultSize: Double) -> CGFloat {
|
||||
let stored = UserDefaults.standard.double(forKey: key)
|
||||
return stored == 0 ? defaultSize : stored
|
||||
}
|
||||
|
||||
// MARK: Slot fonts
|
||||
|
||||
/// Body slot font — the family's Book/Regular member at the slot size.
|
||||
static var bodyFont: NSFont {
|
||||
font(family: face("proseBodyFace", defaultFace: defaultBodyFace),
|
||||
size: size("proseBodySize", defaultSize: defaultBodySize))
|
||||
}
|
||||
|
||||
/// Headings slot font — the family's Book/Regular member, bold trait, at
|
||||
/// the slot size (h1). Scaled levels call `headingFont(size:)`.
|
||||
static var headingFont: NSFont {
|
||||
bolded(headingFont(size: size("proseHeadingsSize", defaultSize: defaultHeadingsSize)))
|
||||
}
|
||||
|
||||
static func headingFont(size: CGFloat) -> NSFont {
|
||||
bolded(font(family: face("proseHeadingsFace", defaultFace: defaultHeadingsFace), size: size))
|
||||
}
|
||||
|
||||
/// Code slot font (inline code, fenced blocks, and the editing surface's
|
||||
/// dimmed syntax).
|
||||
static var codeFont: NSFont {
|
||||
font(family: face("proseCodeFace", defaultFace: defaultCodeFace),
|
||||
size: size("proseCodeSize", defaultSize: defaultCodeSize))
|
||||
}
|
||||
/// Editing-surface leading (blank source lines are the separator there).
|
||||
static let lineHeightMultiple: CGFloat = 1.5
|
||||
|
||||
static var italicBodyFont: NSFont {
|
||||
NSFontManager.shared.convert(bodyFont, toHaveTrait: .italicFontMask)
|
||||
}
|
||||
|
||||
static var boldBodyFont: NSFont {
|
||||
bolded(bodyFont)
|
||||
NSFontManager.shared.convert(bodyFont, toHaveTrait: .boldFontMask)
|
||||
}
|
||||
|
||||
// MARK: Text flow (#71 polish)
|
||||
|
||||
/// Line-height multiple (clamped 1…2; 0/absent → default).
|
||||
static var lineHeightMultiple: CGFloat {
|
||||
clamped("proseLineHeight", default: defaultLineHeight, 1 ... 2)
|
||||
}
|
||||
|
||||
/// Spacing after body paragraphs, in body lines.
|
||||
static var paragraphSpacingLines: CGFloat {
|
||||
clamped("proseParagraphSpacingLines", default: defaultParagraphSpacingLines, 0 ... 4)
|
||||
}
|
||||
|
||||
/// Spacing after headings, in body lines.
|
||||
static var headingSpacingLines: CGFloat {
|
||||
clamped("proseHeadingSpacingLines", default: defaultHeadingSpacingLines, 0 ... 6)
|
||||
}
|
||||
|
||||
/// Every value the prose surfaces render from, summed — a change key
|
||||
/// for live re-attribution when settings move.
|
||||
static var flowKey: String {
|
||||
"\(bodyFont.fontName)@\(bodyFont.pointSize)|\(codeFont.fontName)@\(codeFont.pointSize)|\(headingFont.fontName)@\(headingFont.pointSize)|lh=\(lineHeightMultiple)|p=\(paragraphSpacingLines)|h=\(headingSpacingLines)"
|
||||
}
|
||||
|
||||
/// One body line at the configured flow, in points.
|
||||
static var linePoints: CGFloat {
|
||||
let f = bodyFont
|
||||
return (f.ascender - f.descender + f.leading) * lineHeightMultiple
|
||||
}
|
||||
|
||||
private static func clamped(_ key: String, default def: Double, _ range: ClosedRange<Double>) -> CGFloat {
|
||||
let stored = UserDefaults.standard.double(forKey: key)
|
||||
let value = stored == 0 ? def : stored
|
||||
return CGFloat(min(max(value, range.lowerBound), range.upperBound))
|
||||
}
|
||||
|
||||
// MARK: Attribute stacks (reading + editing share them)
|
||||
// MARK: Attribute stacks (editing surface)
|
||||
|
||||
static var foregroundColor: NSColor {
|
||||
NSColor(red: 0.10, green: 0.10, blue: 0.09, alpha: 1)
|
||||
}
|
||||
|
||||
/// Dimmed syntax color (the editing surface's 0.55 dim, #19).
|
||||
/// Dimmed syntax color (the editing surface's 0.5 dim, #19).
|
||||
static var syntaxColor: NSColor {
|
||||
NSColor(white: 0.55, alpha: 1)
|
||||
}
|
||||
@@ -141,7 +52,7 @@ nonisolated enum ProseTypography {
|
||||
NSColor(white: 0.78, alpha: 1)
|
||||
}
|
||||
|
||||
/// Table borders + reading HR hairline (≈ DesignTokens.border).
|
||||
/// Table borders + editing-surface hairline (≈ DesignTokens.border).
|
||||
static var tableBorderColor: NSColor {
|
||||
NSColor(red: 0xE8 / 255, green: 0xE5 / 255, blue: 0xDF / 255, alpha: 1)
|
||||
}
|
||||
@@ -160,32 +71,4 @@ nonisolated enum ProseTypography {
|
||||
.foregroundColor: syntaxColor,
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: Resolution
|
||||
|
||||
/// Family → member PS name → NSFont. Prefer Book/Regular styles, else the
|
||||
/// member closest to weight 5; unknown family → system font (silent, #70).
|
||||
private static func font(family: String, size: CGFloat) -> NSFont {
|
||||
let members = NSFontManager.shared.availableMembers(ofFontFamily: family) ?? []
|
||||
let regular = members.first { entry in
|
||||
guard let style = entry[safe: 1] as? String else { return false }
|
||||
return style.range(of: "book|regular", options: [.caseInsensitive, .regularExpression]) != nil
|
||||
} ?? members.min { lhs, rhs in
|
||||
abs((lhs[safe: 2] as? Int ?? 5) - 5) < abs((rhs[safe: 2] as? Int ?? 5) - 5)
|
||||
}
|
||||
guard let name = regular?[safe: 0] as? String else {
|
||||
return NSFont.systemFont(ofSize: size)
|
||||
}
|
||||
return NSFont(name: name, size: size) ?? NSFont.systemFont(ofSize: size)
|
||||
}
|
||||
|
||||
private static func bolded(_ base: NSFont) -> NSFont {
|
||||
NSFontManager.shared.convert(base, toHaveTrait: .boldFontMask)
|
||||
}
|
||||
}
|
||||
|
||||
private nonisolated extension Array {
|
||||
subscript(safe index: Int) -> Element? {
|
||||
indices.contains(index) ? self[index] : nil
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user