// The receipt, the seventh face (shared format, added 30 Sep on the owner's// word): the cream paper card with the perforated bottom edge that the Import// chat screen draws — a small-capitals label line typed across its head, a// pencil rule, then a handwritten title and a plain explanation. It is the face// for a step in progress or just finished: imports, pairing, wait and gate// screens, and the change receipt (what a command did, with its Undo).//// Drawn once, here. A screen that shows such a card passes its label and puts// whatever that step has to say inside; a table whose tile is `receipt` draws// its records with the definition's slip columns. Never delete this card when// converting a screen (`ReceiptFaceTests` holds the screens that wear it).importCottonValuesimportSwiftUIpublicstructReceiptFace<Content: View>: View { @Environment(\.theme) privatevar themeprivatelet label: Stringprivatelet seed: Stringprivatelet dye: PaperDyeprivatelet labelIdentifier: String?privatelet content: Content/// - Parameters:/// - label: the line typed across the head ("WHATSAPP EXPORT · READING")./// - seed: keeps the perforation and the rule the same on every draw./// - labelIdentifier: the label line's accessibility identifier, for UI tests.publicinit( label: String, seed: String, dye: PaperDye = .cream, labelIdentifier: String? = nil, @ViewBuilder content: () -> Content ) {self.label = labelself.seed = seedself.dye = dyeself.labelIdentifier = labelIdentifierself.content = content() }publicvar body: someView {Paper(dye: dye, edge: .receipt, seed: seed, tilt: false, inset: ReceiptFaceKnobs.receiptInset) { VStack(alignment: .leading, spacing: 0) {Text(label) .paperMeta(theme.scale.metaSize - 0.5) .accessibilityIdentifier(labelIdentifier ?? "receipt-label")PencilRule(seed: "\(seed)-head", theme: theme) .stroke(theme.print(.pencil), lineWidth: ReceiptFaceKnobs.receiptRuleLineWidth) .frame(height: ReceiptFaceKnobs.receiptRuleHeight) .padding(.top, ReceiptFaceKnobs.receiptRuleTopPadding) .padding(.bottom, ReceiptFaceKnobs.receiptRuleBottomPadding) content } .frame(maxWidth: .infinity, alignment: .leading) } .fixedSize(horizontal: false, vertical: true) }}/// The receipt's usual inside: a handwritten title over a plain explanation.structReceiptBody: View { @Environment(\.theme) privatevar themeprivatelet title: Stringprivatelet explanation: String?init(title: String, explanation: String?) {self.title = titleself.explanation = explanation }var body: someView { VStack(alignment: .leading, spacing: ReceiptFaceKnobs.receiptContentSpacing) {Text(title) .paperHand(theme.scale.handSize + 4, ink: .ink) .lineLimit(ReceiptFaceKnobs.receiptTitleLineLimit) .fixedSize(horizontal: false, vertical: true)iflet explanation {Text(explanation) .paperBody(theme.scale.bodySize - 1, ink: .pencil) .lineSpacing(ReceiptFaceKnobs.receiptBodyLineSpacing) .fixedSize(horizontal: false, vertical: true) } } .frame(maxWidth: .infinity, alignment: .leading) }}extensionReceiptFacewhereContent == ReceiptBody {/// A receipt that says one thing: its title and an explanation.init(label: String, title: String, explanation: String?, seed: String) {self.init(label: label, seed: seed) { ReceiptBody(title: title, explanation: explanation) } }/// One record as a receipt, from its definition: the table's name and the/// slip's trailing value across the head, the slip's title handwritten,/// its subtitle as the explanation.init(definition: TableDefinition, record: TableRecord) {let slip = definition.slipfunc words(_ key: String?) -> String? { key.flatMap { FaceText.line(record[$0], words: record.columnWords($0), column: definition.column($0), currency: record[definition.column($0)?.currency].text) } }let head = [definition.name.uppercased(), words(slip.trailing)?.uppercased()] .compactMap { $0 } .joined(separator: " · ")self.init( label: head, title: words(slip.title) ?? definition.name, explanation: words(slip.subtitle), seed: "receipt-\(record.id)") }}/// The sizes, counts and timings ReceiptFace draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enumReceiptFaceKnobs {staticlet receiptBodyLineSpacing: CGFloat = 3staticlet receiptContentSpacing: CGFloat = 12staticlet receiptInset: CGFloat = 22staticlet receiptRuleBottomPadding: CGFloat = 16staticlet receiptRuleHeight: CGFloat = 3staticlet receiptRuleLineWidth: CGFloat = 0.8staticlet receiptRuleTopPadding: CGFloat = 10staticlet receiptTitleLineLimit = 2}