// What the money's objects share: how a transaction's card is read for the// figures they type, and how a painted object is laid on the money's pink// terrazzo (`FaceGround.terrazzo`).//// A transaction's card (`DeckCard`, the money tool's Past and Future views)// carries its amount as the core said it ("₹2,340"), the account by its name,// and, among its facts, the account's balance before and after it ("Balance// before", "Balance after", 27 Oct 2026). It carries no direction: whether// money went out or came in is the kit's to choose by the face it names (a// receipt for a spend, a cheque for money in), and the faces draw what they// are handed. An object types the figures as a period object does, "Rs" and// two places ("Rs 1,24,500.00"), grouped as the core grouped them.importCottonPaperimportCottonValuesimportSwiftUIpublicenumMoneyReading {/// The table's columns the balances are read from, as the transaction/// table names them; their labels are what a fact stands under.staticlet beforeColumn = "balance_before_minor"staticlet afterColumn = "balance_after_minor"/// The account's balance before and after the transaction, off the/// card's facts: each by its column's label where the deck read the/// labels, else the two facts in the order the view names them (before,/// then after). Nil where the card does not say it.publicstaticfunc balances(_ card: DeckCard) -> (before: SaidAmount?, after: SaidAmount?) {let facts = StudioReading.facts(card)let labelled = { (column: String) -> SaidAmount? inguardlet label = card.labels[column: column] else { returnnil }return facts.first { $0.label == label }.flatMap { SaidAmount($0.said) } }if card.labels[column: beforeColumn] != nil || card.labels[column: afterColumn] != nil {return (labelled(beforeColumn), labelled(afterColumn)) }guard facts.count == 2else { return (nil, nil) }return (SaidAmount(facts[0].said), SaidAmount(facts[1].said)) }/// The print's mark for an amount: "Rs" for rupees, as a period object/// prints it, else the core's own mark ("$", "SGD").publicstaticfunc mark(_ amount: SaidAmount) -> String { amount.isRupees || amount.mark.isEmpty ? "Rs" : amount.mark }/// An amount typed with its mark: "Rs 2,340.00".publicstaticfunc typed(_ amount: SaidAmount) -> String {"\(mark(amount)) \(amount.typed)" }/// The amount in words, for rupees; nil for another currency, whose/// words this writer does not know.publicstaticfunc words(_ amount: SaidAmount) -> String? {guard amount.isRupees || amount.mark.isEmpty else { returnnil }returnRupeeWords.written(rupees: amount.units, paise: amount.hundredths) }/// The record's short id, as a serial is printed: its last six letters/// and figures, in capitals; nil for a card read off no record.publicstaticfunc serial(_ card: DeckCard) -> String? {guardlet id = card.record else { returnnil }let kept = id.filter { $0.isLetter || $0.isNumber }guard !kept.isEmpty else { returnnil }returnString(kept.suffix(6)).uppercased() }/// What a transaction is for: its description (`subtitle`), else its/// category (`body`), and the part it is tagged as.publicstaticfunc purpose(_ card: DeckCard) -> (words: String, part: FacePart)? {iflet subtitle = card.text("subtitle") { return (subtitle, .subtitle) }iflet body = card.text("body") { return (body, .body) }returnnil }}/// A painted layer of a money object, by its catalogue name, at the scale/// it was painted for; nil where this build carries no pictures.func moneyPainted(_ name: String) -> Image? {CottonMedia.image(name, scale: 3)}/// A painted object lying on the felt: its shadow (painted larger than it/// by `reach` of its width on every side), then the object, at `size`; a/// flat stand-in of `standIn` where the build carries no pictures.structMoneyPaper: View {let name: Stringlet size: CGSizelet reach: CGFloatlet standIn: Colorvar corner: CGFloat = 0.02var body: someView {let pad = reach * size.width ZStack(alignment: .topLeading) {iflet shadow = moneyPainted("\(name)-shadow") { shadow.resizable().interpolation(.high) .frame(width: size.width + 2 * pad, height: size.height + 2 * pad) .offset(x: -pad, y: -pad) }iflet paper = moneyPainted(name) { paper.resizable().interpolation(.high) .frame(width: size.width, height: size.height) .cardPaperLaid() } else {RoundedRectangle(cornerRadius: corner * size.width).fill(standIn) .frame(width: size.width, height: size.height) } } .frame(width: size.width, height: size.height, alignment: .topLeading) .accessibilityHidden(true) }}/// A dashed rule a till prints between its parts.structPrintedDashes: View {let ink: Colorvar weight: CGFloat = 1var body: someView {GeometryReader { box inPath { path in path.move(to: CGPoint(x: 0, y: box.size.height / 2)) path.addLine(to: CGPoint(x: box.size.width, y: box.size.height / 2)) } .stroke(ink, style: StrokeStyle(lineWidth: weight, dash: [weight * 3.5, weight * 2.2])) } .frame(height: max(weight, 1)) .accessibilityHidden(true) }}/// One line set in a face, made to fit its room: never wrapped, squeezed/// to the room rather than cut.structFittedLine: View {let words: Stringlet font: Fontlet ink: Colorvar alignment: Alignment = .leadingvar tracking: CGFloat = 0var shrink: CGFloat = 0.5var body: someView {Text(words) .font(font) .tracking(tracking) .foregroundStyle(ink) .lineLimit(1) .minimumScaleFactor(shrink) .frame(maxWidth: .infinity, alignment: alignment) }}extensionView {/// Set `x` in and `y` down from its container's top leading corner, as/// laid out — not an offset, which moves the drawing and leaves the/// part's tagged frame (`facePart`) and its accessibility frame behind./// A part is tagged before it is placed, so its tag is its own frame.func placed(x: CGFloat = 0, y: CGFloat = 0) -> someView { padding(.leading, x).padding(.top, y) }}