// A picture, a film, a document or a recording that is not on this phone yet,// drawn the one way everywhere it can stand (walker 604bcce6 and its offline// pass): a paper slip with the kind's picture, the file's name and the one// sentence, and Fetch when it can be fetched — over the poster dimmed under a// scrim when there is one. Never grey words over the picture, never a bare// "Photo". Every word is the media definition's `viewer.words`.importFoundationimportSwiftUI/// What kind of thing is missing: the picture the slip draws for it.enumAbsentKind {case photo, video, document, recording, filevar symbol: String {switchself {case .photo: return"photo"case .video: return"film"case .document: return"doc.text"case .recording: return"waveform"case .file: return"doc" } }/// The kind a file's content type names, else its name's extension.staticfunc of(contentType: String? = nil, name: String? = nil) -> AbsentKind {let type = (contentType ?? "").lowercased()if type.hasPrefix("image/") { return .photo }if type.hasPrefix("video/") { return .video }if type.hasPrefix("audio/") { return .recording }if type == "application/pdf" || type.hasPrefix("text/") { return .document }switch ((name ?? "") as NSString).pathExtension.lowercased() {case"jpg", "jpeg", "png", "heic", "gif", "webp": return .photocase"mov", "mp4", "m4v": return .videocase"m4a", "mp3", "wav", "aac", "caf": return .recordingcase"pdf", "txt", "md", "doc", "docx", "pages", "rtf": return .documentdefault: return .file } }}/// The slip: the kind's picture, the name, the sentence, Fetch.structAbsentSlip: View {let kind: AbsentKindvar name: String? = nillet words: ViewerWords?var removed = falsevar fetching = false/// nil when nothing here can fetch it.var onFetch: (() -> Void)? = nil/// Small, in a row or a bubble: the picture and the sentence beside each other.var compact = false @Environment(\.theme) privatevar themeprivatevar sentence: String {// The definition's line, never the core's own sentence for why a// fetch failed: an engine composes no sentence for a slip. (removed ? words?.removed : words?.absent) ?? "" }var body: someView {Paper(dye: .cream, edge: .cut, seed: name ?? kind.symbol, tilt: false, shadow: .lifted, inset: 0) {Group {if compact { HStack(alignment: .center, spacing: AbsentSlipKnobs.gap) { glyph VStack(alignment: .leading, spacing: AbsentSlipKnobs.lineGap) { lines }Spacer(minLength: 0) } } else { VStack(spacing: AbsentSlipKnobs.gap) { glyph VStack(spacing: AbsentSlipKnobs.lineGap) { lines }.multilineTextAlignment(.center) } } } .padding(.horizontal, AbsentSlipKnobs.inset) .padding(.vertical, compact ? AbsentSlipKnobs.compactVertical : AbsentSlipKnobs.inset) } .frame(maxWidth: compact ? .infinity : AbsentSlipKnobs.maxWidth) .accessibilityElement(children: .combine) .accessibilityIdentifier("absent-slip") }privatevar glyph: someView {Image(systemName: kind.symbol) .font(theme.type.interface(compact ? AbsentSlipKnobs.compactGlyph : AbsentSlipKnobs.glyph, weight: .light)) .foregroundStyle(theme.print(.pencil)) .accessibilityHidden(true) } @ViewBuilder privatevar lines: someView {iflet name, !name.isEmpty {Text(name) .paperMeta(theme.scale.metaSize, ink: .ink) .lineLimit(2) .fixedSize(horizontal: false, vertical: true) }Text(sentence) .paperHand(theme.scale.handSize, ink: .pencil) .fixedSize(horizontal: false, vertical: true) .accessibilityIdentifier("viewer-absent")if !removed, let onFetch {PaperTypedButton(fetching ? (words?.fetching ?? "") : (words?.fetch ?? ""), size: theme.scale.metaSize, action: onFetch) .disabled(fetching) .accessibilityIdentifier("absent-fetch") } }}/// The poster dimmed under the page's own ground, the slip on it — or the/// slip alone when there is no poster.structAbsentOverPoster<Poster: View>: View {let slip: AbsentSlip @ViewBuilder let poster: Poster @Environment(\.theme) privatevar themevar body: someView { ZStack { poster .overlay(theme.colors.ground.color.opacity(AbsentSlipKnobs.scrim)) .accessibilityHidden(true) slip.padding(AbsentSlipKnobs.inset) } }}enumAbsentSlipKnobs {staticlet gap: CGFloat = 10staticlet lineGap: CGFloat = 4staticlet inset: CGFloat = 16staticlet compactVertical: CGFloat = 10staticlet glyph: CGFloat = 30staticlet compactGlyph: CGFloat = 20staticlet maxWidth: CGFloat = 300/// How much of the ground lies over a poster the slip stands on.staticlet scrim: Double = 0.55}