importCottonKitimportCottonPaperimportSwiftUI#if canImport(UIKit)import UIKit#endif/// A list's fan tile, made from what it holds (5 Nov 2026), for every tool/// that draws lists (Books, Cinemas, Music, a Calendar list): the view tiles'/// own worn cream card with no object on it (`list-tile-ground`), its name/// and count typed beneath in Courier as a view tile's are (`ViewTile`), and/// where a view tile's painted object stands, one of three things:////// - the person's own picture (`record_group.picture`), a print pinned inside/// the card's frame;/// - else a small stack of its first three members' pictures (a book's/// cover, a film's poster), the way a playlist's cover is built from its/// albums — fewer members, fewer in the stack;/// - else three blank sheets laid the same way: the list's default tile,/// never the blank card.////// Every picture is the thumbnail this phone already holds (`read.mediaPath`,/// the 256 px rendition the pictures sweep collects): nothing here asks the/// network. A fan tile is printed once, never live (`FanPrints`), so the arc/// decodes a list's pictures into `ListTilePictureCache` before it prints/// the tile, and prints it again as more land (`FanTierArc`); the tile draws/// what the cache holds. Until the own picture's thumbnail lands the tile/// draws the stack, and until a cover's lands the stack goes without it.structListTile: View {let pictures: ListTilePictureslet label: Stringlet count: Int?let width: Doublelet height: Doublevar growth: CGFloat = 1/// The catalogue name of the card the tile is laid on. nonisolated staticlet ground = "list-tile-ground"var body: someView { ZStack(alignment: .top) {ViewTile(painted: Self.ground, label: label, count: count, width: width, height: height, growth: growth) #if canImport(UIKit)ListTileArt(drawn: ListTileArt.drawn(own: pictures.cover.flatMap(ListTilePictureCache.image), stack: pictures.stack.map(ListTilePictureCache.image)), width: width, height: height) #elseListTileArt(drawn: .plain, width: width, height: height) #endif } .frame(width: width, height: height) }}#if canImport(UIKit)/// The lists' pictures this phone has decoded for their tiles, by media key:/// filled by the arc before it prints a list's tile (`load`), read by the/// tile as it is printed. A key not on this phone yet is asked again when/// bytes land.@MainActorenumListTilePictureCache {privatestaticvar held: [String: UIImage] = [:]staticfunc image(_ key: String) -> UIImage? { held[key] }/// For tests and the specimen: a picture in hand under `key`.staticfunc keep(_ image: UIImage, as key: String) { held[key] = image }/// Decodes each of `keys` not held yet from this phone (`read.mediaPath`,/// never the network) at `edge` pixels; whether any came.staticfunc load(_ keys: [String], core: any CottonCalling, edge: CGFloat) async -> Bool {var came = falsefor key in keys where held[key] == nil {ifcase .ready(let image) = awaitMediaImages.load(from: core, key: key, edge: edge) { held[key] = image came = true } }return came }/// The keys of `pictures` the cache does not hold.staticfunc missing(_ pictures: ListTilePictures) -> [String] { ([pictures.cover].compactMap { $0 } + pictures.stack).filter { held[$0] == nil } }}#endif/// What a list's tile is made from (`shell.fan`): the person's own picture/// and its first members' pictures, as media keys.structListTilePictures: Equatable, Sendable {var cover: String?var stack: [String]}/// What stands in the list tile's object place, drawn from pictures in hand.structListTileArt: View { #if canImport(UIKit)typealiasPicture = UIImage #elsetypealiasPicture = Never #endifenumDrawn {/// The person's own picture, pinned.case own(Picture)/// The first members' pictures, the first on top.case stack([Picture])/// No picture in hand: three blank sheets.case plainvar name: String {switchself {case .own: "own"case .stack(let pictures): "stack \(pictures.count)"case .plain: "plain" } } }/// RULE (5 Nov 2026): the person's own picture wins when it is on this phone; else the members' pictures that are, in order, at most three; else the blank sheets — never the blank card.staticfunc drawn(own: Picture?, stack: [Picture?]) -> Drawn {iflet own { return .own(own) }let held = Array(stack.compactMap { $0 }.prefix(ListTileKnobs.lay.count))return held.isEmpty ? .plain : .stack(held) }let drawn: Drawnlet width: Doublelet height: Double @Environment(\.theme) privatevar themevar body: someView { ZStack {switch drawn {case .own(let picture): pinned(picture)case .stack(let pictures):// Drawn last first, so the list's first member is on top.ForEach(Array(pictures.enumerated()).reversed(), id: \.offset) { index, picture in laid(index) { cover(picture) } }case .plain:ForEach((0..<ListTileKnobs.lay.count).reversed(), id: \.self) { index in laid(index) { sheet } } } } .frame(width: width, height: height * ListTileKnobs.place) .position(x: width / 2, y: height * ListTileKnobs.centre) .frame(width: width, height: height) .allowsHitTesting(false) .accessibilityHidden(true) }/// One of the stack's places: turned and moved as the knobs lay it.privatefunc laid(_ index: Int, @ViewBuilder _ content: () -> someView) -> someView {let lay = ListTileKnobs.lay[index]return content() .rotationEffect(.degrees(lay.turn)) .offset(x: width * lay.x, y: height * lay.y) }privatevar coverSize: CGSize { CGSize(width: width * ListTileKnobs.coverWidth, height: width * ListTileKnobs.coverWidth / ListTileKnobs.coverAspect) } @ViewBuilder privatefunc cover(_ picture: Picture) -> someView { #if canImport(UIKit)Image(uiImage: picture) .resizable() .scaledToFill() .frame(width: coverSize.width, height: coverSize.height) .clipShape(RoundedRectangle(cornerRadius: 1.5)) .shadow(color: .black.opacity(0.28), radius: 1.5, x: 0.5, y: 1) #endif }/// A blank sheet where a cover would be: the default list tile.privatevar sheet: someView {RoundedRectangle(cornerRadius: 1.5) .fill(theme.sheet(.cream)) .overlay(RoundedRectangle(cornerRadius: 1.5).strokeBorder(theme.print(.pencil).opacity(0.35), lineWidth: 0.6)) .frame(width: coverSize.width, height: coverSize.height) .shadow(color: .black.opacity(0.18), radius: 1.2, x: 0.5, y: 1) }/// The person's picture as a print: a white border round it, turned a/// little, a red pin at its head. @ViewBuilder privatefunc pinned(_ picture: Picture) -> someView { #if canImport(UIKit)let side = width * ListTileKnobs.printWidthlet border = side * ListTileKnobs.printBorder ZStack(alignment: .top) {Image(uiImage: picture) .resizable() .scaledToFill() .frame(width: side - border * 2, height: side - border * 2) .clipped() .padding(border) .background(PhotosMaterial.border.colour) .shadow(color: .black.opacity(0.3), radius: 2, x: 0.5, y: 1.5)Circle() .fill(theme.print(.red)) .frame(width: side * ListTileKnobs.pin, height: side * ListTileKnobs.pin) .shadow(color: .black.opacity(0.35), radius: 0.8, x: 0.4, y: 0.8) .offset(y: -side * ListTileKnobs.pin / 3) } .rotationEffect(.degrees(ListTileKnobs.printTurn)) #endif }}/// Measured against the view tiles (`ViewTileKnobs`): the object place is/// the card's upper half, the words start a little past its middle.enumListTileKnobs {/// The object place's centre and height, against the card's height.staticlet centre = 0.29staticlet place = 0.46/// A cover's width against the card's, and its paperback's aspect.staticlet coverWidth = 0.36staticlet coverAspect = 2.0 / 3.0/// Each place of the stack, the first on top: turned (degrees) and moved/// (against the card's width and height).staticlet lay: [(turn: Double, x: Double, y: Double)] = [(0, 0, 0.012), (-9, -0.2, -0.008), (8, 0.2, -0.004)]/// The print's side against the card's width, its border against its/// side, its turn, and its pin against its side.staticlet printWidth = 0.6staticlet printBorder = 0.06staticlet printTurn = -2.5staticlet pin = 0.11}