// THE DECK MOVES BY TAP (owner, 29 Oct 2026): the screen's width in three.// A tap on the LEFT third is the record before, on the RIGHT third the next,// at once — a plain cut, the next card simply there, so records fly by as// fast as they are tapped; the MIDDLE third is the object's own tap (what// the card's tap opens: a whole's parts, a group's deck, a chat, the// viewer). The zones are the screen's, not the card's: the ground beside// and above the card counts as well. A tap that lands on a part the face// tagged (`FacePart`) or a region the shell keeps (`deckKeepsTaps`) never// moves: an editable part opens the record, an act still acts.// Past either end the deck rolls into the neighbouring view, as a swipe// does. VoiceOver reaches the same moves as the card's "Next record" and// "Previous record" actions.importCottonFacesimportCottonValuesimportSwiftUI/// The deck's three zones across the screen.structDeckZones: Equatable {/// The screen's span the zones divide, in global points.var minX: CGFloatvar width: CGFloatinit(minX: CGFloat = 0, width: CGFloat) {self.minX = minXself.width = width }/// The zones of the page whose global frame is `frame`.init(_ frame: CGRect) {self.init(minX: frame.minX, width: frame.width) }enumZone: Equatable {case previous, own, next }func zone(at x: CGFloat) -> Zone {guard width > 0else { return .own }let share = (x - minX) / widthif share < 1.0 / 3 { return .previous }if share >= 2.0 / 3 { return .next }return .own }/// The step a tap at `point` moves the deck: -1 or 1 on a side third,/// nil in the middle third or on a region that keeps its own tap.func step(at point: CGPoint, kept: [CGRect] = []) -> Int? {guard !kept.contains(where: { $0.contains(point) }) else { returnnil }switch zone(at: point.x) {case .previous: return -1case .next: return1case .own: returnnil } }/// Editable parts open even outside the middle third. Acts and shell/// controls retain their own tap wherever they stand.func opens(at point: CGPoint, parts: [CGRect], acts: [CGRect], kept: [CGRect]) -> Bool { !((acts + kept).contains { $0.contains(point) }) && (isOwn(point) || parts.contains { $0.contains(point) }) }/// Is a tap at `point` the object's own (the middle third)?func isOwn(_ point: CGPoint) -> Bool { zone(at: point.x) == .own }}/// Where a step from `at` among `count` cards lands: another card, or past/// an end, into the neighbouring view (`DeckSurface.roll`).enumDeckStep: Equatable {case card(Int)case past(forward: Bool)staticfunc of(_ step: Int, from at: Int, count: Int) -> DeckStep {if count > 0, abs(step) > 1 { return .card(min(count - 1, max(0, at + step))) }let next = at + stepreturn (0..<count).contains(next) ? .card(next) : .past(forward: step > 0) }}/// The card's moves for VoiceOver, in the shell's words.enumDeckZoneWords {staticvar next: String {ShellLines.line("record", "side.next", ["name": ShellLines.line("home", "questions.a_record")]) }staticvar previous: String {ShellLines.line("record", "side.previous", ["name": ShellLines.line("home", "questions.a_record")]) }}/// The regions on a card the shell keeps the tap of, beside the face's/// tagged parts: Home's own part cards, whose rows and buttons are theirs.structDeckKeptTapsKey: PreferenceKey {staticvar defaultValue: [Anchor<CGRect>] { [] }staticfunc reduce(value: inout [Anchor<CGRect>], nextValue: () -> [Anchor<CGRect>]) { value.append(contentsOf: nextValue()) }}extensionView {/// The front card, moved by the zones: a tap on a side third that lands/// on no tagged part moves the deck by `move`, one in the middle third/// is the object's own (`own`).func deckZoned(_ zones: DeckZones, move: @escaping (Int) -> Void, own: @escaping () -> Void) -> someView { modifier(DeckZonedCard(zones: zones, move: move, own: own)) }/// The card's moves for VoiceOver, so the zones are not the only way:/// "Next record" and "Previous record".func deckMoveActions(_ move: @escaping (Int) -> Void) -> someView { accessibilityAction(named: Text(DeckZoneWords.next)) { move(1) } .accessibilityAction(named: Text(DeckZoneWords.previous)) { move(-1) } }/// The ground the card stands on, moved by the zones: a tap on a side/// third moves the deck, the middle third's is nobody's.func deckZonedGround(_ zones: DeckZones?, move: @escaping (Int) -> Void) -> someView { modifier(DeckZonedGround(zones: zones, move: move)) }/// This region keeps its taps: the deck's zones never move over it.func deckKeepsTaps() -> someView { transformAnchorPreference(key: DeckKeptTapsKey.self, value: .bounds) { $0.append($1) } }}/// The front card under the zones. The side thirds' tap rides with every/// other gesture on the card (`simultaneousGesture`), so a face's own tap on/// its bare page — a todo's or an album's page turn — never holds the deck/// back; it moves only where no tagged part stands, the parts' rectangles/// read off the face's tap map (`FacePartsKey`). The middle third's tap is/// the card's own too, even when a face also turns its page there. Acts/// retain their tap without opening the record.privatestructDeckZonedCard: ViewModifier {let zones: DeckZoneslet move: (Int) -> Voidlet own: () -> Void/// The tagged parts on the card and the regions the shell keeps, in/// global points. @State privatevar parts: [CGRect] = [] @State privatevar shell: [CGRect] = [] @State privatevar acts: [CGRect] = []func body(content: Content) -> someView { content .overlayPreferenceValue(FacePartsKey.self) { tagged inGeometryReader { proxy inlet origin = proxy.frame(in: .global).originlet rects = tagged.map { proxy[$0.bounds].offsetBy(dx: origin.x, dy: origin.y) }let actions = tagged.filter { [.call, .message, .email, .play, .scrub, .next, .previous].contains($0.part) } .map { proxy[$0.bounds].offsetBy(dx: origin.x, dy: origin.y) }Color.clear .onChange(of: rects, initial: true) { _, now in parts = now } .onChange(of: actions, initial: true) { _, now in acts = now } } .allowsHitTesting(false) } .overlayPreferenceValue(DeckKeptTapsKey.self) { regions inGeometryReader { proxy inlet origin = proxy.frame(in: .global).originlet rects = regions.map { proxy[$0].offsetBy(dx: origin.x, dy: origin.y) }Color.clear.onChange(of: rects, initial: true) { _, now in shell = now } } .allowsHitTesting(false) } .contentShape(Rectangle()) .simultaneousGesture(SpatialTapGesture(coordinateSpace: .global).onEnded { tap inif zones.opens(at: tap.location, parts: parts, acts: acts, kept: shell) { own() }iflet step = zones.step(at: tap.location, kept: parts + shell) { move(step) } }) }}/// The ground around the card under the zones: only taps no card, line or/// button took reach it. No zones (an empty deck, a search) stands the tap/// down on the one view path: swapping the wrapper rebuilt everything under/// it, the ink ground's letter in progress with it, whenever the deck emptied/// or filled ("co" read "c", 8 Nov 2026).privatestructDeckZonedGround: ViewModifier {let zones: DeckZones?let move: (Int) -> Voidfunc body(content: Content) -> someView { content .background { Color.clear.contentShape(Rectangle()).allowsHitTesting(zones != nil) } .gesture(SpatialTapGesture(coordinateSpace: .global).onEnded { tap iniflet step = zones?.step(at: tap.location) { move(step) } }, including: zones == nil ? .subviews : .all) }}