Files
museion/Museion/ProseTypography.swift
T
AlexKucera c23ee0f62f
CI / ci (push) Canceled after 0s
feat(outline): outline type + outliner — S3 (#109)
Dedicated block surface (ADR-0013, #105 variant B): OutlineTree
parses/serializes plain nested-bullet markdown leniently and
normalizes on save; the outliner promotes one NSTextView over the
focused row with LogSeq-style keys (Tab/⇧Tab, ⌥↑/⌥↓ subtree move,
↑/↓ hop, ⇧↑/⇧↓ block selection, ⌘↑/⌥↓ fold, Enter split), folds
session-scoped by runtime node UUID. New Outline ⇧⌘N stages a
type: outline draft through the existing autosave/conflict
machinery; reading renders the serialized markdown unchanged.

Outline rows use the body face at its natural line box — the prose
CSS-1.8 lineHeightMultiple grew the focused row and detached the
bullet (test-pinned). Finish-audit fixes included: paste-multiline
sanitizing at setText, dead Enter disjunct, dead Row.path.

Closes #109
2026-10-15 13:09:31 +02:00

133 lines
5.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// ProseTypography.swift
// Museion
//
// #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 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).
/// ponytail: nonisolated(unsafe) — NSFont isn't Sendable; the cached
/// instances are never mutated after creation.
nonisolated(unsafe) static let bodyFont: NSFont = .init(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.
nonisolated(unsafe) static let headingFont: NSFont = .init(name: "ConcourseOT6Semibold", size: heading1Size) ?? NSFont.systemFont(ofSize: heading1Size, weight: .semibold)
/// h2 = the headings face at CSS's 0.85× ladder step (#77).
nonisolated(unsafe) static let heading2Font: NSFont = .init(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.
nonisolated(unsafe) static let heading3Font: NSFont = NSFontManager.shared.convert(
NSFontManager.shared.convert(bodyFont, toSize: heading3Size),
toHaveTrait: .boldFontMask,
)
/// h4+ floors at bold body (CSS h4–h6).
nonisolated(unsafe) static let headingBoldFont: NSFont = NSFontManager.shared.convert(bodyFont, toHaveTrait: .boldFontMask)
/// Code slot (inline code, fenced blocks, editing syntax dim).
nonisolated(unsafe) static let codeFont: NSFont = .init(name: "UbuntuMonoNFM", size: codeSize) ?? NSFont.monospacedSystemFont(ofSize: codeSize, weight: .regular)
/// Blank source lines at 9pt (#77 half-height separators).
nonisolated(unsafe) static let blankFont: NSFont = NSFontManager.shared.convert(bodyFont, toSize: blankSize)
/// Editor measure (#77): reading.css `--measure: 66ch` — the advance of
/// "0" × 66 in the body face (px→pt 1:1), + the text container's 24pt
/// lineFragmentPadding on both sides (the CSS body's 24px side padding).
static let measureWidth: CGFloat = {
let zero = NSAttributedString(string: "0", attributes: [.font: bodyFont])
let ch = zero.size().width
return (ch * 66).rounded() + 48
}()
/// 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
}
nonisolated(unsafe) static let italicBodyFont: NSFont = NSFontManager.shared.convert(bodyFont, toHaveTrait: .italicFontMask)
nonisolated(unsafe) static let boldBodyFont: NSFont = NSFontManager.shared.convert(bodyFont, toHaveTrait: .boldFontMask)
// 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.5 dim, #19).
static var syntaxColor: NSColor {
NSColor(white: 0.55, 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)
}
static var bodyAttributes: [NSAttributedString.Key: Any] {
[
.font: bodyFont,
.paragraphStyle: ProsePresenter.paragraph(.body),
.foregroundColor: foregroundColor,
]
}
/// Outline rows (#109): the body face at its NATURAL line box — no CSS
/// 1.8 lineHeightMultiple. The outliner chrome (27pt bullet cells) assumes
/// one row height; a live-row fragment inflated by the prose multiple
/// grows the row, parks the glyphs at the fragment bottom, and detaches
/// the bullet. Editing parity lives in the FACE, not the leading.
static var outlineRowAttributes: [NSAttributedString.Key: Any] {
[
.font: bodyFont,
.foregroundColor: foregroundColor,
]
}
static var codeAttributes: [NSAttributedString.Key: Any] {
[
.font: codeFont,
.foregroundColor: syntaxColor,
]
}
}