Cotton code
52 lines · 2.1 KB · SwiftRaw
// The inks typed on an object, by name. Four, and the blend that makes them// print rather than paste.//// `ink` and `pencil` are the theme's PRINT colour — the ribbon on paper — and// the pencil is the same ribbon thinner. `red` and `green` are STATE (late,// missed, unread, an exception; totals agree, a credit), and state speaks in// the palette's voice on every surface, paper included. The colours live in// `ThemePalette`; every view asks the WORN theme — `theme.print(_:)`,// `theme.printBlend` — and this enum only names the ink.//// THE BLEND IS `.multiply` on a grained theme, inside a `compositingGroup()` —// the caps' and the cards' trick. A letter multiplied onto paper lets the fibre// under it show through the way a ribbon does; a letter drawn opaque sits ON// the paper like a sticker. A theme with no grain prints plainly.import SwiftUIpublic enum PaperInk: Sendable, CaseIterable {    /// The typewriter and the serif on paper: dark warm ink.    case ink    /// Annotation — dates, counts, meta. The same ink, thinner, the way a    /// pencil is lighter than a ribbon.    case pencil    /// Exception and state: late, missed, unread, the red ring.    case red    /// Agreement: totals agree, a credit.    case green}extension Theme {    /// An ink typed on an object.    public func print(_ ink: PaperInk) -> Color { colors.color(ink) }    /// A text ink by name.    public func text(_ ink: TextInk) -> Color { colors.color(ink) }    /// The blend everything printed on an object wears: multiplied into the    /// fibre when the theme has grain, plain when it has none.    public var printBlend: BlendMode { texture.grain ? .multiply : .normal }    /// A sheet's tilt in degrees: its seed's, when the theme tilts.    public func tilt(seed: String) -> Double {        texture.tilt ? PaperMetrics.tilt(seed: seed, range: Double(PaperInkKnobs.paperTiltRangeDegrees)) : 0    }}/// The sizes, counts and timings PaperInk draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enum PaperInkKnobs {    static let paperTiltRangeDegrees: CGFloat = 0.7}