// A face and the pages its card turns to after it (`card.pages`, 10c993c7e):// the face first, then each column that holds words under its label, cut to// the room as a note's (`FacePages`) — a meeting's summary, decisions and// transcript, a coding session's task list. A tap turns to the next page,// the last back to the face; a swipe turns either way, and past either end// moves card. At the foot, as a note's, the page's place ("1 / 4") and// "continued →" while there is a page after it. A card with no pages is// its face alone, with no foot and no turning. Every word is the core's or// the record's; the app reads the pages off the card's definition// (CottonUI's `DeckCardFill`) onto the card, and the face turns them// inside its own paper (`AudioFace`, `SessionFace`, a studio's// faces).importCottonPaperimportCottonValuesimportSwiftUIenumFaceTurnsKnobs {staticlet inset = EdgeInsets(top: 26, leading: 24, bottom: 26, trailing: 22)staticlet pageSize: CGFloat = 13.5/// The foot's type, and how far it stands off the card's bottom.staticlet footSize: CGFloat = 12staticlet footBottom: CGFloat = 10/// How far a swipe travels before it turns a page.staticlet turn: CGFloat = 40}structFaceTurns<Front: View>: View {let pages: [CardPage]let front: Front @Environment(\.deckPassOn) privatevar passOn @State privatevar page = 0/// `opened` is the page shown first (a gallery's specimen of a page).init(pages: [CardPage], opened: Int = 0, @ViewBuilder front: () -> Front) {self.pages = pagesself.front = front() _page = State(initialValue: opened) }var body: someView {let count = 1 + pages.count ZStack(alignment: .bottom) {Group {if page > 0, pages.indices.contains(page - 1) { turned(pages[page - 1], count: count) } else { front } } .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)if count > 1 { foot(count) } } .contentShape(Rectangle()) .onTapGesture { if count > 1 { page = (page + 1) % count } } .facePages(count > 1 ? turning(count: count) : nil, at: "\(page)/\(count)") { forward inlet next = page + (forward ? 1 : -1)if (0..<count).contains(next) { page = next } else { passOn?(forward) } } .animation(.easeOut(duration: 0.18), value: page) }privatefunc turned(_ shown: CardPage, count: Int) -> someView { VStack(alignment: .leading, spacing: 10) {FaceLabel(words: shown.label)// The column's words cut to the room as a note's; past its last// page the card turns on, past its first back.FacePages(text: shown.text, size: FaceTurnsKnobs.pageSize, markdown: shown.markdown) .environment(\.deckPassOn, { forward inlet next = page + (forward ? 1 : -1)if (0..<count).contains(next) { page = next } else { passOn?(forward) } }) } .padding(FaceTurnsKnobs.inset) .accessibilityIdentifier("face-page-\(page)") }/// "2 / 4", and "continued →" while a page follows.privatefunc foot(_ count: Int) -> someView { HStack(alignment: .lastTextBaseline) {Text(ShellLines.line("cards", "note.page", ["at": String(page + 1), "of": String(count)])) .accessibilityIdentifier("face-page-label")Spacer(minLength: 0)if page < count - 1 {Text(ShellLines.line("cards", "note.continued")) } } .font(CottonFonts.type(FaceTurnsKnobs.footSize)) .lineLimit(1) .faceInk(.ink) .padding(.horizontal, FaceTurnsKnobs.inset.leading) .padding(.bottom, FaceTurnsKnobs.footBottom) .accessibilityHidden(true) }privatefunc turning(count: Int) -> someGesture {DragGesture(minimumDistance: 16) .onEnded { end inlet dx = end.translation.widthguard abs(dx) > FaceTurnsKnobs.turn, abs(dx) > abs(end.translation.height) else { return }let next = page + (dx < 0 ? 1 : -1)if (0..<count).contains(next) { page = next } else { passOn?(dx < 0) } } }}