// FULL SCREEN IS THE THING (owner, 26 Oct 2026), not the deck's card a// little larger: the card is the thing's tile in the deck. A pinch out on a// card, or a tap on the picture of a photo or a film, opens what the card// holds. One function decides which, from the record's definition alone// (`FullScreenRoute`): a picture, a film or a document opens in the one// viewer (`MediaViewer`), over the deck's own records in deck order, so a// swipe sideways walks the deck and a swipe down puts it back on the card it// grew out of; a note, a memory or a book's notes on the reader (`ReadPage`); every// other card ignores pinch out; tap opens its card at rest with acts.importCottonValuesimportSwiftUI/// What a pinch out on a card opens.enumDeckOpening {/// The one viewer, by the act that opens it there.case viewer(() -> Void)/// The record's reading page (`ReadPage`).case reading(ReadDocument)/// No reader or viewer: pinch out is inert.case whole}/// Which of the three a pinch out on a record's card opens, decided from its/// definition alone; nothing is wired to a table.enumFullScreenRoute: Equatable {/// The one viewer: the table names the viewer, or a film's player.case viewer/// The reading page, with the columns it reads.case reading(ReadSlots)/// No reader or viewer.case wholestaticfunc of(_ definition: TableDefinition?) -> FullScreenRoute {guardlet definition else { return .whole }ifDeckViewer.shows(definition) { return .viewer }iflet slots = ReadSlots.of(definition) { return .reading(slots) }return .whole }/// Does it open the reading page?var reads: Bool {ifcase .reading = self { returntrue }returnfalse }}extensionDeckOpening {/// What a pinch out on `record`'s card opens, by its route: the viewer/// over `records` (the deck, in deck order), its reading page, or the/// inert pinch. A deck drawn where no viewer is hosted (a preview)/// also ignores pinch out. @MainActorstaticfunc of(_ record: TableRecord, card: DeckCard?, in records: [TableRecord], definition: TableDefinition?, presenter: ViewerPresenter?, readAll: (@MainActor () async -> [TableRecord])? = nil) -> DeckOpening {guardlet definition else { return .whole }switchFullScreenRoute.of(definition) {case .viewer:guardlet presenter else { return .whole }// The viewer opens at once on the cards dealt; the deck's whole// read follows it, and stops when the viewer closes.return .viewer {DeckViewer.open(record.id, in: records, definition: definition, presenter: presenter, rest: readAll) }case .reading(let slots):// A record with nothing to read (a book with neither notes nor// a quote) has no reader to open.let document = ReadSource(record: record, card: card, slots: slots, definition: definition).reading(record)return document.bodies.isEmpty ? .whole : .reading(document)case .whole:return .whole } }var reads: Bool {ifcase .reading = self { returntrue }returnfalse }/// The act that opens the card's thing in the viewer — what a tap on a/// photo's print or a film's still does — when that is where it opens.var viewer: (() -> Void)? {ifcase .viewer(letopen) = self { returnopen }returnnil }}/// The deck's records opened in the one viewer.enumDeckViewer {/// A record of `definition` is a thing the viewer shows: its table names/// the viewer (`viewer`: a picture, a document), or its slip names the/// column a film plays from (`player`).staticfunc shows(_ definition: TableDefinition) -> Bool { definition.viewer != nil || definition.slip.player != nil }/// The item id a record of `definition` stands under in the viewer — the/// id the card is the viewer's source by (`ViewerItem(record:definition:)`).staticfunc itemID(_ definition: TableDefinition, _ record: String) -> String { "\(definition.id)/\(record)" }/// The deck's records the viewer can show, in deck order, opened on/// `record`; nil when that one is not among them.staticfunc set(opening record: String, in records: [TableRecord], definition: TableDefinition) -> ViewerSet? {let items = records.compactMap { ViewerItem(record: $0, definition: definition) }guardlet start = items.firstIndex(where: { $0.id == itemID(definition, record) }) else { returnnil }returnViewerSet(items: items, start: start) }/// Opens `record` in `presenter` over the deck's records; false when its/// table is not one the viewer shows, or nothing of it can be shown./// `rest`, where `records` are a window of more, reads the whole for/// the viewer to grow into (`ViewerPresenter.open`). @MainActor @discardableResultstaticfuncopen(_ record: String, in records: [TableRecord], definition: TableDefinition, presenter: ViewerPresenter, rest: (@MainActor () async -> [TableRecord])? = nil) -> Bool {guard shows(definition), let set = set(opening: record, in: records, definition: definition) else { returnfalse } presenter.open(set, rest: rest.map { items($0, definition: definition) })returntrue }/// The whole read `read` gives, as the viewer's items. @MainActorprivatestaticfunc items(_ read: @escaping @MainActor () async -> [TableRecord], definition: TableDefinition) -> @MainActor () async -> [ViewerItem] {return { @MainActor inlet all = await read()return all.compactMap { ViewerItem(record: $0, definition: definition) } } }}