// A picture as a page draws it: from the LARGEST copy on this phone// (original → display → thumbnail, `tier: .largest`), because a hero drawn at// the width of the screen asked with a tile's order is handed the 256 px// thumbnail enlarged while the original sits on disk (`ThumbFetchSweepTests`).// It asks `read.mediaPath` through `PhotosPicture` and nothing else; a tap// opens the viewer, which is what fetches. Without the core (a preview, a// test) it draws the thumbnail-tier picture every face draws. Where the// environment hands pictures by key (`facePictures`: a gallery, a face// capture's fixtures) it draws that one and asks nothing. A key that is a web// address is a kept page's own picture (Cotton Pages), drawn from it. On a business app's// shell a key is the business's photo, fetched from its object's photos// (`facePhotoBase`, `BusinessPages.photo`).importCottonKitimportSwiftUIstructPagePicture: View {let key: Stringlet edge: CGFloatvar blankWhileLoading = false @Environment(\.cottonCore) privatevar core @Environment(\.facePictures) privatevar pictures @Environment(\.facePhotoBase) privatevar photoBasevar body: someView {iflet shown = pictures?(key) { shown.resizable().interpolation(.high).scaledToFill() } elseiflet photoBase, let url = BusinessPages.photo(key, at: photoBase) {AsyncImage(url: url) { phase iniflet image = phase.image { image.resizable().interpolation(.high).scaledToFill() } else {Color.clear } } } elseiflet url = Self.web(key) {// A kept page's lead picture is the page's own, on the web// (`own_pages__picture`, Cotton Pages): drawn from its address.AsyncImage(url: url) { phase iniflet image = phase.image { image.resizable().interpolation(.high).scaledToFill() } else {Color.clear } } } elseiflet core {PhotosPicture( media: PhotosMediaSource(core: core), key: key, maxPixel: Int(edge * PagePicture.scale), tier: .largest, blankWhileLoading: blankWhileLoading) } else {RecordPicture(avatarKey: key, edge: edge) } }/// A key that is a web address (a page's own picture), as its URL; nil/// for a key of this phone's media.staticfunc web(_ key: String) -> URL? {guard key.hasPrefix("https://") || key.hasPrefix("http://") else { returnnil }return URL(string: key) } @MainActor staticvar scale: CGFloat { #if canImport(UIKit) UIScreen.main.scale #else2 #endif }}extensionEnvironmentValues {/// Pictures a face draws by key without the core — a gallery's invented/// people; nil asks the phone. @Entry var facePictures: ((String) -> Image?)? = nil/// Where a business's photos are fetched (`BusinessPages.photos`): a/// photo column's key is drawn from this base with the key after it; nil/// asks the phone. @Entry var facePhotoBase: String? = nil}