feat(editor): reading-parity presentation for the editing surface (#77)

ProsePresenter rewritten to mirror the calm-ruled reading surface (#78):
- leading calibrated to CSS 1.8 via font metrics (not the raw number)
- heading ladder 30/22/19-w600, h4+ bold body, new h3/h4+/fence/blank kinds
- half-height blank separators (9pt)
- quotes secondary-ink + 20pt indent; fence interiors mono-14 on substrate
- inline traits: bold, italic (CommonMark intraword _ rule), code, links
  (label ink + underline, marks dim); list markers dim
- 11 new tests pin the ladder, blanks, quote, fence, traits
This commit is contained in:
AlexKucera committed 2026-10-08 13:33:21 +02:00
1 parent 1a5f04c9f4
commit 8fe5f48e0e
3 files changed
+593 -77

No files matched your search

+67 -5
View File
@@ -15,19 +15,66 @@ import AppKit
/// Prose typography constants (#72 rework). The editing surface reads these;
/// reading mode reads Resources/reading.css.
nonisolated enum ProseTypography {
// #77: sizes mirror reading.css exactly (px → pt 1:1 at 1×).
static let bodySize: CGFloat = 17
static let heading1Size: CGFloat = 30 // CSS: --headings-size 26 × 1.15
static let heading2Size: CGFloat = 22 // CSS: 26 × 0.85
static let heading3Size: CGFloat = 19 // CSS: --body-size × 1.12
static let codeSize: CGFloat = 14
static let blankSize: CGFloat = 9 // half-height blank separator lines (#77)
/// 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) }
static var bodyFont: NSFont {
NSFont(name: "ValkyrieOTBRegular", size: bodySize) ?? NSFont.systemFont(ofSize: bodySize)
}
/// 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) }
static var headingFont: NSFont {
NSFont(name: "ConcourseOT6Semibold", size: heading1Size) ?? NSFont.systemFont(ofSize: heading1Size, weight: .semibold)
}
/// h2 = the headings face at CSS's 0.85× ladder step (#77).
static var heading2Font: NSFont {
NSFont(name: "ConcourseOT6Semibold", size: heading2Size) ?? NSFont.systemFont(ofSize: heading2Size, weight: .semibold)
}
/// h3 = body face, sized up, weight 600 (CSS h3: body-face w600). The B
/// cut has no 600 member — the bold trait (700, real or synthesized) is
/// the nearest expressible. ponytail: trait-convert; a true semibold face
/// would drop in here if ever installed.
static var heading3Font: NSFont {
NSFontManager.shared.convert(
NSFontManager.shared.convert(bodyFont, toSize: heading3Size),
toHaveTrait: .boldFontMask,
)
}
/// h4+ floors at bold body (CSS h4–h6).
static var headingBoldFont: NSFont {
NSFontManager.shared.convert(bodyFont, toHaveTrait: .boldFontMask)
}
/// Code slot (inline code, fenced blocks, editing syntax dim).
static var codeFont: NSFont { NSFont(name: "UbuntuMonoNFM", size: 14) ?? NSFont.monospacedSystemFont(ofSize: 14, weight: .regular) }
static var codeFont: NSFont {
NSFont(name: "UbuntuMonoNFM", size: codeSize) ?? NSFont.monospacedSystemFont(ofSize: codeSize, weight: .regular)
}
/// Editing-surface leading (blank source lines are the separator there).
static let lineHeightMultiple: CGFloat = 1.5
/// Blank source lines at 9pt (#77 half-height separators).
static var blankFont: NSFont {
NSFontManager.shared.convert(bodyFont, toSize: blankSize)
}
/// Line-height parity with reading.css (#77): CSS `line-height: n` means
/// n × font-size pixels; TextKit's lineHeightMultiple multiplies the
/// font's natural box (ascender − descender + leading ≈ 1.2 × size).
/// Copying the CSS number would overshoot ~20% — calibrate instead.
static func lineHeightMultiple(font: NSFont, cssLineHeight: CGFloat) -> CGFloat {
let natural = font.ascender - font.descender + font.leading
guard natural > 0 else { return cssLineHeight }
return (font.pointSize * cssLineHeight) / natural
}
static var italicBodyFont: NSFont {
NSFontManager.shared.convert(bodyFont, toHaveTrait: .italicFontMask)
@@ -52,6 +99,21 @@ nonisolated enum ProseTypography {
NSColor(white: 0.78, alpha: 1)
}
/// Secondary ink — reading.css --secondary #48484d (quotes, #77).
static var secondaryColor: NSColor {
NSColor(red: 0x48 / 255, green: 0x48 / 255, blue: 0x4D / 255, alpha: 1)
}
/// Muted ink — reading.css --muted #6e6e73 (link underline rule, #77).
static var mutedColor: NSColor {
NSColor(red: 0x6E / 255, green: 0x6E / 255, blue: 0x73 / 255, alpha: 1)
}
/// Substrate — reading.css --substrate #f5f5f7 (code panels, #77).
static var substrateColor: NSColor {
NSColor(red: 0xF5 / 255, green: 0xF5 / 255, blue: 0xF7 / 255, alpha: 1)
}
/// Table borders + editing-surface hairline (≈ DesignTokens.border).
static var tableBorderColor: NSColor {
NSColor(red: 0xE8 / 255, green: 0xE5 / 255, blue: 0xDF / 255, alpha: 1)