feat(editor): land reading toggle — render, interact, typography slots (S1.2 #71)

Map #20 execution child, built per decisions #68/#69/#70:

- ReadingPresenter: block-aware renderer (ADR-0010 stance) — blank-line
  split, one block per chunk; lists (bullets + ordered + nesting +
  auto-renumber via per-level counters — one rendering path), headings
  by level (h1 = slot size, h2 = 0.77x, ### = body+1, #### floors at
  bold body), HR via the editing syntaxOnly predicate, fenced code,
  blockquotes (QuoteTextBlock hairline), tables (NSTextTable 1px
  border, delimiter-row alignment), images (hover payload), links
  styled + retained. Footnotes stay fallback. Source ranges ride every
  block (click→edit map).
- ReadingSurface: read-only selectable NSTextView canvas (#68: a
  presentation of the same TextKit2 document). Tap with no selection
  after mouseDown returns = edit intent at the clicked block (the
  tracking-loop fix); ⌘-click opens links; scroll tracking feeds the
  flip-back caret; image hover NSPopover loads off-main.
- ProseTypography (#70): three role slots — Body / Headings / Code —
  each {face, size}, UserDefaults six values, member-based font
  resolution (family+weight lookup misresolves Concourse Book→Thin),
  silent system fallback; both prose surfaces read them; editing
  presenter's headings + dimmed syntax rewired through the slots.
- PostEditorView: Read⇄Edit toolbar button (far left) + View menu
  "Toggle Reading Mode" + ⌘R; reading state transient per open; drafts
  included (draft mirror); flip-back caret hint applied once per token.
- SettingsPaneView: Typography section — three slot rows (family
  picker incl. current face not in the installed list + size field).
- kitchen-sink.md (+png): corpus piece exercising constructs absent
  from the eight posts, per #69.

Verified: 94 unit tests (renderer classification, renumbering, source
ranges, fallbacks) + UI smoke; PERF-3k renders 128 blocks in ~17 ms;
live-app probe — Read renders kitchen-sink markers-hidden, renumbered,
byte-stable file after full round-trip; click-to-edit flips at the
clicked paragraph; typography ladder pixel-verified (20/15 ink px).
This commit is contained in:
AlexKucera committed 2026-10-05 15:51:28 +02:00
1 parent f2953ee07e
commit 4c91733e78
12 files changed
+1393 -33

No files matched your search

+17 -17
View File
@@ -71,30 +71,27 @@ nonisolated enum ProsePresenter {
dimSyntax(in: out, range: paragraphRange)
}
// Typography: Iowan Old Style prose stance (the export's stack), 17pt body,
// scaled headings.
// Typography: the #70 role slots (ProseTypography) — Body / Headings /
// Code — shared with reading mode; editing chrome (dimmed syntax) rides
// the Code slot.
static var bodyFont: NSFont {
NSFontManager.shared.font(withFamily: "Iowan Old Style", traits: [], weight: 5, size: 17)
?? NSFont.systemFont(ofSize: 17)
ProseTypography.bodyFont
}
static var bodyAttributes: [NSAttributedString.Key: Any] {
[
.font: bodyFont,
.paragraphStyle: paragraph(.body),
.foregroundColor: NSColor(red: 0.10, green: 0.10, blue: 0.09, alpha: 1),
]
ProseTypography.bodyAttributes
}
static func attributes(for kind: LineKind) -> [NSAttributedString.Key: Any] {
func headingFont(size: CGFloat, weight: Int) -> NSFont {
NSFontManager.shared.font(withFamily: "Iowan Old Style", traits: [.boldFontMask], weight: weight, size: size)
?? .boldSystemFont(ofSize: size)
}
switch kind {
case .heading1: return [.font: headingFont(size: 26, weight: 9), .paragraphStyle: paragraph(.heading1)]
case .heading2: return [.font: headingFont(size: 20, weight: 8), .paragraphStyle: paragraph(.heading2)]
case .quote, .syntaxOnly, .body: return bodyAttributes
case .heading1:
[.font: ProseTypography.headingFont, .paragraphStyle: paragraph(.heading1)]
case .heading2:
[
.font: ProseTypography.headingFont(size: (ProseTypography.headingFont.pointSize * 0.77).rounded()),
.paragraphStyle: paragraph(.heading2),
]
case .quote, .syntaxOnly, .body: bodyAttributes
}
}
@@ -111,7 +108,10 @@ nonisolated enum ProsePresenter {
case .quote: 2
default: 0
}
let dim: [NSAttributedString.Key: Any] = [.foregroundColor: NSColor(white: 0.55, alpha: 1), .font: NSFont.monospacedSystemFont(ofSize: 13, weight: .regular)]
let dim: [NSAttributedString.Key: Any] = [
.foregroundColor: ProseTypography.syntaxColor,
.font: ProseTypography.codeFont,
]
if markerLen > 0 {
out.addAttributes(dim, range: NSRange(location: range.location, length: min(markerLen, range.length)))
}