import SwiftUI struct DocumentThumbnailData: Decodable, Sendable { let bars: [Bar]? let width: Double let height: Double enum CodingKeys: String, CodingKey { case bars = "Bars", width = "W", height = "H" } struct Bar: Decodable, Sendable { let x: Double; let y: Double; let width: Double; let height: Double enum CodingKeys: String, CodingKey { case x = "X", y = "Y", width = "W", height = "H" } } } struct DocumentThumbnail: View { let data: DocumentThumbnailData? var width: CGFloat = 34 var height: CGFloat = 44 var body: some View { Canvas { context, size in guard let data, data.width > 0, data.height > 0 else { return } let scale = min(size.width / data.width, size.height / data.height) let x = (size.width - data.width * scale) / 2 let y = (size.height - data.height * scale) / 2 for bar in data.bars ?? [] { context.fill(Path(CGRect(x: x + bar.x * scale, y: y + bar.y * scale, width: max(0, bar.width * scale), height: max(0, bar.height * scale))), with: .foreground) } } .foregroundStyle(.secondary) .frame(width: width, height: height) .background(.background) .clipShape(.rect(cornerRadius: 3)) .overlay { RoundedRectangle(cornerRadius: 3).strokeBorder(.quaternary) } .accessibilityHidden(true) } }