// What the phone draws for a face beyond its card (CottonFaces' hooks,// installed on every card the deck draws, `DeckFace.view`): a document's// first page off the record's own file (`faceFilePage`), and the player a// face plays under (`faceTrackPlayer`): on a show's radio, its episode in the// app's one podcast player (`DeckRadioPlaying`); on Listening's player, its// song in the one music player (`DeckMusicPlaying`); on an album's tray, the// album in it (`DeckAlbumPlaying`); every other card stands still.importCottonFacesimportCottonKitimportCottonPaperimportCottonValuesimportSwiftUIenumDeckFaceKnobs {/// The pixels a card's photograph is decoded at, along its longest side.staticlet photoEdge: CGFloat = 420}/// A document's first page from its file, drawn as the Documents covers draw/// theirs (`FirstPageThumbnail`): once per file, kept for the session, and a/// blank page until it is drawn. It tells its card the page's shape.////// A card in the deck is the document being looked at, so its bytes are/// fetched when they are not on this phone (`ensure`, as the viewer fetches/// them): a document has no small copy a sync brings, as a photo has, and a/// card that only read the bytes already here stood blank until its file was/// opened (walk 332: every document card on a fresh phone).structDeckFirstPage: View {let ref: String @Binding var aspect: CGFloat @Environment(\.attachmentStore) privatevar store @Environment(\.cottonCore) privatevar core @State privatevar image: UIImage?/// How a face asks for it (`faceFilePage`).staticlet drawer: FaceFilePage = { ref, aspect inAnyView(DeckFirstPage(ref: ref, aspect: aspect)) }/// The file holding `ref`'s bytes: the one on this phone, else fetched.staticfunc file(_ ref: String, from source: any AttachmentStore) async -> URL? {iflet here = await source.localURL(for: ref), FileManager.default.fileExists(atPath: here.path) { return here }returntry? await source.ensure(for: ref) }var body: someView {Group {iflet image {Image(uiImage: image) .resizable() .scaledToFill() .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top) .clipped() .blendMode(.multiply) } else {BlankPage().padding(.horizontal, 12).padding(.vertical, 16) } } .task(id: ref) {let drawn: UIImageiflet kept = FirstPageThumbnail.cache.object(forKey: ref as NSString) { drawn = kept } else {guardlet source = store ?? core.map({ CoreAttachmentStore(core: $0) }),let url = awaitSelf.file(ref, from: source),let made = awaitTask.detached(priority: .utility, operation: { FirstPageThumbnail.draw(url) }).value, !Task.isCancelledelse { return }FirstPageThumbnail.cache.setObject(made, forKey: ref as NSString) drawn = made } image = drawnif drawn.size.width > 0, drawn.size.height > 0 { aspect = drawn.size.width / drawn.size.height } } }}/// A card under the player: a show's radio plays its episode in the app's/// one podcast player (`DeckRadioPlaying`), Listening's player its song in/// the one music player (`DeckMusicPlaying`), a cassette its list or its song/// (`DeckCassettePlaying`); every other card stands still.structDeckPlaying: View {let card: DeckCardlet drawn: (FaceTrackPlay) -> AnyView/// How a face asks for it (`faceTrackPlayer`).staticlet player: FaceTrackPlayer = { card, drawn inAnyView(DeckPlaying(card: card, drawn: drawn)) }var body: someView {ifListeningCard.song(of: card) != nil {DeckMusicPlaying(card: card, drawn: drawn) } elseif card.face == DefinitionCardKind.albumTray.rawValue {DeckAlbumPlaying(card: card, drawn: drawn) } elseif [DefinitionCardKind.listCassette.rawValue, DefinitionCardKind.songCassette.rawValue].contains(card.face) {DeckCassettePlaying(card: card, drawn: drawn) } else { #if os(iOS)ifcase .object(let episode)? = card.fields["episode"] {DeckRadioPlaying(card: card, episode: episode, drawn: drawn) } else { still } #else still #endif } }privatevar still: AnyView { drawn(FaceTrackPlay(play: .still, toggle: nil, seek: { _ in })) }}