Cotton code
129 lines · 5.8 KB · SwiftRaw
// The MEMORY face (KINDS, 7f4a5f0fb; house references 91 and 93): one// sentence the owner's assistants keep, on the framed cream card — its// project on a luggage tag at the top and the day it was written by hand// under it, then the sentence itself typed heavy as large as the card lets// it stand; a sentence too long for that is typed out plain, a page at a// time (`FacePages`). A memory with a name over its sentence types the name// heavy and the sentence plain. At the foot the house fountain pen lies// across the card (cut from reference 93) and nothing is stamped: memory has// no review state (owner, 25 Oct 2026, #77). Every word is the core's// (`DeckCard`); the face lays them out.import CottonPaperimport CottonValuesimport SwiftUIenum MemoryFaceKnobs {    static let inset = EdgeInsets(top: 30, leading: 30, bottom: 28, trailing: 28)    static let dateHand: CGFloat = 26    static let nameSize: CGFloat = 19    /// The sentence alone, typed heavy while it is no longer than `heroRoom`    /// characters.    static let heroSize: CGFloat = 23    static let heroRoom = 140    static let heroLines = 8    static let sentenceSize: CGFloat = 16    static let sentenceLeading: CGFloat = 8    static let tagLead: CGFloat = 14    static let gap: CGFloat = 18    /// The fountain pen at the foot: its width, and how far it reaches    /// into the card's bottom margin.    static let penWidth: CGFloat = 176    static let penDrop: CGFloat = 10}public struct MemoryFace: View {    let card: DeckCard    public init(card: DeckCard) {        self.card = card    }    public var body: some View {        let name = card.text("title")        let sentence = card.text("body")        VStack(alignment: .leading, spacing: 0) {            if let project = card.text("subtitle") {                HangTag(words: project)                    .padding(.leading, MemoryFaceKnobs.tagLead)                    .accessibilityIdentifier("face-project")                    .facePart(.subtitle)            }            if let written = card.text("date") {                Text(HandRun.tail(written))                    .font(CottonFonts.hand(MemoryFaceKnobs.dateHand))                    .lineLimit(1)                    .minimumScaleFactor(0.7)                    .faceInk(.ink)                    .padding(.top, MemoryFaceKnobs.gap / 2)                    .accessibilityIdentifier("face-date")                    .facePart(.when)            }            if let sentence, let name {                HeavyType(words: name, size: MemoryFaceKnobs.nameSize)                    .lineLimit(3)                    .minimumScaleFactor(0.75)                    .padding(.top, MemoryFaceKnobs.gap)                    .accessibilityIdentifier("deck-title")                    .facePart(.title)                FacePages(text: sentence, size: MemoryFaceKnobs.sentenceSize, leading: MemoryFaceKnobs.sentenceLeading)                    .padding(.top, MemoryFaceKnobs.gap / 2)                    .accessibilityIdentifier("face-sentence")                    .facePart(.body)            } else if let said = sentence ?? name {                if said.count <= MemoryFaceKnobs.heroRoom {                    HeavyType(words: said, size: MemoryFaceKnobs.heroSize)                        .lineSpacing(MemoryFaceKnobs.sentenceLeading)                        .lineLimit(MemoryFaceKnobs.heroLines)                        .minimumScaleFactor(0.7)                        .padding(.top, MemoryFaceKnobs.gap + 8)                        .accessibilityIdentifier(sentence == nil ? "deck-title" : "face-sentence")                        .facePart(sentence == nil ? .title : .body)                    Spacer(minLength: 0)                } else {                    FacePages(text: said, size: MemoryFaceKnobs.sentenceSize, leading: MemoryFaceKnobs.sentenceLeading)                        .padding(.top, MemoryFaceKnobs.gap)                        .accessibilityIdentifier(sentence == nil ? "deck-title" : "face-sentence")                        .facePart(sentence == nil ? .title : .body)                }            } else {                Spacer(minLength: 0)            }            HStack(alignment: .center, spacing: 0) {                Spacer(minLength: 0)                FaceArt(name: "face-art-pen")                    .frame(width: MemoryFaceKnobs.penWidth)                    .padding(.bottom, -MemoryFaceKnobs.penDrop)            }            .padding(.top, MemoryFaceKnobs.gap / 2)        }        .padding(MemoryFaceKnobs.inset)        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)        .onCardPaper(MemoryFaceCatalogue.stock.laid(card.pace))    }}/// The memory face, by the kind's name, and the cards it is reviewed in.public enum MemoryFaceCatalogue {    public static let stock: FaceStock = .framed    public static let ground: FaceGround = .paper    public static let face = Face(id: "memory", specimens: [Specimen("named", namedMemory), Specimen("kept", keptMemory)]) { card, _, _ in        MemoryFace(card: card)    }    /// A memory with a name over its sentence, its project on the tag.    public static let namedMemory = DeckCard(face: .memory, fields: [        "subtitle": .text("example-garden"),        "title": .text("Water before the sun is up"),        "body": .text("The invented garden is watered before six in the summer months, never in the afternoon; the tank is topped up on Sundays."),        "date": .text("3 days ago"),    ])    /// A memory that is its sentence alone.    public static let keptMemory = DeckCard(face: .memory, fields: [        "subtitle": .text("example-house"),        "title": .text("The spare key"),        "body": .text("The spare key stays with the invented neighbour at number 12."),        "date": .text("last month"),    ])}