// What a face asks the app for beyond its card, as a picture is asked// (`FacePicture`): a document's first page off its file, and where the player// stands with a track. The app installs each (CottonUI's `DeckFirstPage`,// `DeckTrackPlaying`); unset — the Loom app, the face shots — a document// draws its blank page and a track stands still.importCottonValuesimportSwiftUI/// A record's file's first page, by its ref; it tells its card the page's/// shape (width over height) once it is drawn.publictypealiasFaceFilePage = @MainActor @Sendable (_ ref: String, _ aspect: Binding<CGFloat>) -> AnyView/// Where the player stands with a track's card, and what its disc does: plays/// or pauses it, moves the playhead in what it holds, and — on a card of/// several songs (a playlist's tape) — plays from one of them. An object with/// a volume knob of its own (a podcast's radio) reads and turns the sound's/// volume through it too.publicstructFaceTrackPlay {publicvar play: TrackPlaypublicvar toggle: (() -> Void)?publicvar seek: (TimeInterval) -> Void/// Plays the card's song at this place in its songs (from 0), from its/// start; nil on a card of one track, or where nothing plays.publicvar start: ((Int) -> Void)?/// The sound's volume, nought to one (on the phone the system's); nil/// where none is known.publicvar volume: Double?/// Turns the volume to a share, nought to one; nil where it cannot be turned.publicvar turnVolume: ((Double) -> Void)?publicinit( play: TrackPlay, toggle: (() -> Void)?, seek: @escaping (TimeInterval) -> Void, start: ((Int) -> Void)? = nil, volume: Double? = nil, turnVolume: ((Double) -> Void)? = nil ) {self.play = playself.toggle = toggleself.seek = seekself.start = startself.volume = volumeself.turnVolume = turnVolume }}/// The player's word on a track's card, or a card of several songs, handed to/// what draws it.publictypealiasFaceTrackPlayer = @MainActor @Sendable (_ card: DeckCard, _ drawn: @escaping (FaceTrackPlay) -> AnyView) -> AnyViewextensionEnvironmentValues { @Entry publicvar faceFilePage: FaceFilePage? = nil @Entry publicvar faceTrackPlayer: FaceTrackPlayer? = nil}/// A track's card under the installed player, or still where none is/// installed.structTrackPlaying<Drawn: View>: View {let card: DeckCard @ViewBuilder let drawn: (FaceTrackPlay) -> Drawn @Environment(\.faceTrackPlayer) privatevar playervar body: someView {iflet player { player(card) { AnyView(drawn($0)) } } else { drawn(FaceTrackPlay(play: .still, toggle: nil, seek: { _ in })) } }}/// A document's card with its first page off its file, where the app draws/// one (`faceFilePage`) and the card names a file; else the drawn blank page.structDocumentFileCard: View {let card: DeckCard @Environment(\.faceFilePage) privatevar filePage @State privatevar aspect = DocumentFaceKnobs.blankAspectvar body: someView {iflet filePage, let file = card.file {DocumentFace(card: card, page: filePage(file, $aspect), pageAspect: aspect) } else {DocumentFace<EmptyView>(card: card, page: nil, pageAspect: aspect) } }}