// The long NOTE drawing (image 3), no face of its own since the note face// left (3 Nov 2026): a studio's card with no photograph wears it// (`StudioPlaceFace`). A journal page on the cream stock inside a// thin printed border with leafy sprigs at its corners — the one face that// carries ornament, and no picture. The title typed heavy, the day written// by hand under it, then the text typed out a page at a time, open-leaded as// a typed list is; the foot types which page this is ("2 / 4") and, while// more follow, "continued →". A swipe turns the note's pages first; past its// last page (or before its first) the swipe goes on to the deck, to move// card.//// The pages are the core's: it cuts the text into pages from its length and// the card's typing room (`engine::text_pages`, asked by CottonUI's// `NotePages` for the room `NoteRoom` measures), worked out when drawn and// never stored. Every word is the core's (`FaceRead`, `NotePage`).importCottonPaperimportCottonValuesimportSwiftUIpublicenumNoteFaceKnobs {publicstaticlet textLead: CGFloat = 40publicstaticlet textTrail: CGFloat = 26publicstaticlet titleTop: CGFloat = 34/// The full-screen editor's title (CottonUI's `DeckLongTextEditor`); the/// face types its own heavy.publicstaticlet titleSize: CGFloat = 22publicstaticlet headSize: CGFloat = 26/// The date is written by hand, as on the photo and video faces.publicstaticlet dateHand: CGFloat = 24/// Who keeps an agent's note, under the day and tucked up to it.publicstaticlet keptHand: CGFloat = 17publicstaticlet keptTuck: CGFloat = 4/// The todo's notes and the editor type at this size and leading; the/// note's own pages at `pageSize` and `pageLeading`.publicstaticlet bodySize: CGFloat = 13.9publicstaticlet bodyLeading: CGFloat = 5.3publicstaticlet pageSize: CGFloat = 16.5publicstaticlet pageLeading: CGFloat = 12/// The first page's room under the title and the day, and over every page/// the foot's, as `NoteRoom` measures them.publicstaticlet headRoom: CGFloat = 118publicstaticlet footRoom: CGFloat = 70publicstaticlet pageTop: CGFloat = 24/// The note's foot, typed: which page, and "continued →" while more follow.publicstaticlet pageFoot: CGFloat = 13publicstaticlet footSize: CGFloat = 12publicstaticlet continuedHand: CGFloat = 18/// How far a swipe travels before it turns a page.publicstaticlet turn: CGFloat = 40}/// One page of a note as the core cut it.publicstructNotePage: Equatable, Sendable {publicvar text: String/// "2 / 4".publicvar label: Stringpublicinit(text: String, label: String) {self.text = textself.label = label }}/// How the note's text fits the card: its typing room, measured off the/// typewriter at the face's size, for the core to cut pages by.publicenumNoteRoom {/// The characters a line holds and the lines a page holds, the first/// page shorter by the title and date over it.publicstaticfunc measure(width: CGFloat, height: CGFloat) -> (columns: Int, first: Int, rest: Int) { #if canImport(UIKit)let font = UIFont(name: CottonFonts.typeFace, size: NoteFaceKnobs.pageSize) ?? .monospacedSystemFont(ofSize: NoteFaceKnobs.pageSize, weight: .regular)let advance = ("M"as NSString).size(withAttributes: [.font: font]).widthlet line = font.lineHeight + NoteFaceKnobs.pageLeading #elselet advance = NoteFaceKnobs.pageSize * 0.6let line = NoteFaceKnobs.pageSize * 1.2 + NoteFaceKnobs.pageLeading #endiflet typing = width - NoteFaceKnobs.textLead - NoteFaceKnobs.textTraillet columns = max(8, Int(typing / advance))let page = height - NoteFaceKnobs.titleTop - NoteFaceKnobs.footRoomlet first = max(2, Int((page - NoteFaceKnobs.headRoom) / line))let rest = max(2, Int((page + 20) / line))return (columns, first, rest) }}publicstructNoteFace: View {let card: DeckCardlet pages: [NotePage] @Binding var page: Int/// The swipe went past the note's first or last page: move card.var passOn: (_ forward: Bool) -> Void = { _ in }publicinit(card: DeckCard, pages: [NotePage], page: Binding<Int>, passOn: @escaping (_ forward: Bool) -> Void = { _ in }) {self.card = cardself.pages = pages _page = pageself.passOn = passOn } @Environment(\.theme) privatevar themeprivatevar current: NotePage? { pages.indices.contains(page) ? pages[page] : pages.first }publicvar body: someView { VStack(alignment: .leading, spacing: 0) {if page == 0 { head }if current != nil {Text(FaceMarkdown.print(FaceMarkdown.Document(card.text("body") ?? pages.map(\.text).joined(separator: "\n"), theme: theme).pages(pages.map(\.text))[min(page, pages.count - 1)], size: NoteFaceKnobs.pageSize, font: CottonFonts.type(NoteFaceKnobs.pageSize))) .font(CottonFonts.type(NoteFaceKnobs.pageSize)) .lineSpacing(NoteFaceKnobs.pageLeading) .faceInk(.ink) .fixedSize(horizontal: false, vertical: true) .padding(.top, page == 0 ? NoteFaceKnobs.pageTop : NoteFaceKnobs.titleTop + 8) .accessibilityIdentifier("note-page") }Spacer(minLength: 0) foot } .padding(.leading, NoteFaceKnobs.textLead) .padding(.trailing, NoteFaceKnobs.textTrail) .padding(.bottom, 26) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) .contentShape(Rectangle())// The page is the note's words: a tap writes them on the whole// screen, in the shell's editor. .facePart(.body) .facePages(pages.count > 1 ? turning : nil, at: "\(page)/\(pages.count)") { forward inlet next = page + (forward ? 1 : -1)if pages.indices.contains(next) { page = next } else { passOn(forward) } } .animation(.easeOut(duration: 0.18), value: page) .onCardPaper(FaceStock.ornamented.laid(card.pace)) }privatevar head: someView { VStack(alignment: .leading, spacing: 8) {iflet title = card.text("title") {HeavyType(words: String(FaceMarkdown.set(title, theme: theme).characters), size: NoteFaceKnobs.headSize) .lineLimit(3) .facePart(.title) }iflet date = card.text("date") {Text(HandRun.tail(date)) .font(CottonFonts.hand(NoteFaceKnobs.dateHand)) .lineLimit(1) .minimumScaleFactor(0.7) .faceInk(.ink) }// Who keeps a note an agent writes ("Kept by your assistant"),// small in pencil under its day; nothing on the owner's own.iflet kept = card.text("kept_by") {Text(HandRun.tail(kept)) .font(CottonFonts.hand(NoteFaceKnobs.keptHand)) .lineLimit(1) .minimumScaleFactor(0.7) .faceInk(.pencil) .padding(.top, -NoteFaceKnobs.keptTuck) .accessibilityIdentifier("note-kept-by") } } .padding(.top, NoteFaceKnobs.titleTop) }privatevar foot: someView { HStack(alignment: .lastTextBaseline) {if pages.count > 1, let label = current?.label {Text(label) .font(CottonFonts.type(NoteFaceKnobs.pageFoot)) .faceInk(.ink) .accessibilityIdentifier("note-page-label") }Spacer()if page < pages.count - 1 {Text(ShellLines.line("cards", "note.continued")) .font(CottonFonts.type(NoteFaceKnobs.pageFoot)) .faceInk(.ink) } } }privatevar turning: someGesture {DragGesture(minimumDistance: 16) .onEnded { end inlet dx = end.translation.widthguard abs(dx) > NoteFaceKnobs.turn, abs(dx) > abs(end.translation.height) else { return }let forward = dx < 0let next = page + (forward ? 1 : -1)if pages.indices.contains(next) { page = next } else { passOn(forward) } } }}/// A note's card: its words cut into pages by the installed cutter/// (`facePageCutter`: the core's in the app) for the room this card gives,/// again whenever the words or the room change; with no cutter, one page.publicstructNoteCard: View {let card: DeckCard @Environment(\.facePageCutter) privatevar cutter @Environment(\.deckPassOn) privatevar passOn @State privatevar pages: [NotePage] = [] @State privatevar page = 0publicinit(card: DeckCard) {self.card = card }publicvar body: someView {GeometryReader { room inNoteFace(card: card, pages: pages.isEmpty ? [NotePage(text: card.text("body") ?? "", label: "")] : pages, page: $page, passOn: { forward in passOn?(forward) }) .task(id: "\(card.record ?? "")|\(card.text("body")?.hashValue ?? 0)|\(Int(room.size.width))x\(Int(room.size.height))") {guardlet cutter, let text = card.text("body") else { return }let measured = NoteRoom.measure(width: room.size.width, height: room.size.height)let cut = await cutter.cut(text, columns: measured.columns, first: measured.first, rest: measured.rest)// A cut asked for a room since left is never shown: a// narrow room's slow cut, landing after the wide one's,// kept a note at "1 / 2,738" (walk 332).guard !Task.isCancelled else { return } pages = cut page = min(page, max(0, pages.count - 1)) } } }}