// A face's tap map (owner, 28 Oct 2026: a face has one state, view, plus a // tap map). A face says what its parts are — its title, its day, its done // box, its picture, its words — by tagging the region that draws each // (`facePart`), and draws them plainly. The tagged regions ride up as a // preference (`FacePartsKey`), and the shell routes a tap by part // (`facePartTaps`: CottonUI's `DeckFaceParts` — the part's column to its // editor: the days fan, the statuses fan, the short-text input, the // full-screen editor; a picture to the viewer, a person's ways to their // apps). The tap stands on the part itself, so a face's own swipes and page // turns keep their place under it. With none installed — the Loom app, the // face shots — every part draws exactly as it is, and taps nothing. import SwiftUI /// A part of a face, by what it shows: the card places a person taps /// (`DefinitionCardSlot`'s, named as the shell edits them), a picture, and /// a person's ways to be reached. public enum FacePart: String, Sendable, CaseIterable { /// The card's name (`title`). case title /// The line under it (`subtitle`). case subtitle /// Its words (`body`): a note's page, a todo's notes. case body /// The words it quotes (`quote`): a highlight's passage. case quote /// The person's own note on it (`note`): why a passage was marked. case note /// The date corner, ringed while its days are open: a todo's stamp and /// foot date, an event's corner. case corner /// A day it shows anywhere else (`date`). case when /// The status word (`state`). case state /// The done box (`check`) — a toggle the face keeps (`FaceTaps.toggle`). case done /// Its photograph, cover, print, still or page (`photo`). case picture /// Its sum (`amount`). case amount /// Where it is (`place`). case place /// Who it is with (`people`). case people /// The group it stands in (`group`). case group /// A person's ways to be reached. case call, message, email /// A video call to the person (Cotton Calling's camera, beside its handset). case videoCall /// A track's or a recording's disc — a toggle the face keeps /// (`FaceTaps.play`). case play /// A player's position control, turned or dragged to seek (a hi-fi's /// time knob) — the face seeks through its player. case scrub /// The next and the previous song, on a player's face — the shell's acts. case next, previous /// Its rating, drawn as stars (`count`), or its favourite's mark (a /// single's brass star). case stars /// The mood it is sealed with (`seal`): a diary's wax seal, drawn by its /// choice, whose tap turns the fan into the choices. case seal /// The day's weather (`weather`), a glyph drawn by its choice, tapped as /// the seal is. case weather } /// One tagged region of a face: its part, and where it is drawn. public struct FacePartRegion: Equatable { public let part: FacePart public let bounds: Anchor } /// The regions a face tagged, in the order it drew them. public struct FacePartsKey: PreferenceKey { public static var defaultValue: [FacePartRegion] { [] } public static func reduce(value: inout [FacePartRegion], nextValue: () -> [FacePartRegion]) { value.append(contentsOf: nextValue()) } } /// How the shell takes a face's part: the part and its drawing in, the /// drawing with its tap out — drawn as it was where the shell takes none. public typealias FacePartTaps = @MainActor @Sendable (FacePart, AnyView) -> AnyView extension EnvironmentValues { /// How the face's parts are tapped; nil draws them as they are. @Entry public var facePartTaps: FacePartTaps? = nil /// The part of the card drawn whose editor or fan the shell has open, /// which a face that knows its parts rings in pencil (`pencilRinged`); /// nil, none. @Entry public var selectedFacePart: FacePart? = nil } extension View { /// This view is the face's `part`: its region tagged, drawn as it is, its /// tap the shell's. public func facePart(_ part: FacePart) -> some View { modifier(FacePartTagged(part: part)) } } private struct FacePartTagged: ViewModifier { let part: FacePart @Environment(\.facePartTaps) private var taps func body(content: Content) -> some View { Group { if let taps { taps(part, AnyView(content)) } else { content } } // Added to the regions tagged inside it, never in their place: a // note's page holds its title. .transformAnchorPreference(key: FacePartsKey.self, value: .bounds) { $0.append(FacePartRegion(part: part, bounds: $1)) } } }