// The object that stands on a card — a field's or an act's.//// The architect's ruling of 13 Oct 2026: every object on a card is in ONE// style, the flat enamel of Home's caps — a small object on the card's paper,// centred, never photographed stationery or a tear-off pad. Most are generated// pictures (`CardEnamel`, `scripts/gen-cards/make_enamel_objects.py`); the rest// are the value itself, drawn: a date is the calendar's month leaf with// its day, a status an ink ring filled when done, a number its figure, words// their first words, a link the linked tool's cap, a person their print.// `CardObject` names which, as data, and `CardObjectView` draws it in the// square the card gives it.importCottonValuesimportSwiftUI/// The generated enamel objects. The raw value is the imageset's name less its/// `object-` prefix.enumCardEnamel: String, CaseIterable, Sendable {// Fields.case clock, bell, pin, flame, file, picture, link, personcase repeats = "repeat"// Acts.case done, snooze, move, share, agent, bin, archive, open, editcase phone, message, mail, star, pushpin, retry, restore, copy, cameracase group, bookmark, flag/// A chat over a phone number (WhatsApp) and the pictures someone posts/// (Instagram) — each drawn as what it is, never the app's mark.case chat, lens/// A bell that will not ring (Mute), and this phone (Keep on this phone)/// — never the pushpin, which is Pin's.case muted, device/// Generated device kinds, separate from Call's handset.case devicePhone = "device-phone"case mac, linux/// Junk: the envelope crossed out; Block sender: a raised hand — never/// the bin, which is Delete's and Bin's alone (architect, r7).case junk, block/// Hide: an eye struck through — a held message hidden from your copy,/// never the bin (architect, r8).case hidden/// Revoke: the link's two links pulled apart, a red break between them —/// never Make the link's chain (one object per act).case unlink/// Only you: a closed padlock — a record held for its owner alone; never/// the person, which is a field's and Call's.case lockvar asset: String { "object-\(rawValue)" }/// The object a definition names (`"object": "bell"`), when it is one.staticfunc named(_ name: String?) -> CardEnamel? {guardlet name else { returnnil }switch name {// The names the first card kit's definitions used for its objects.case"ring": return .repeatscase"note": return .editcase"arrow.triangle.2.circlepath": return .repeatsdefault: returnCardEnamel(rawValue: name) } }}enumCardObject: Equatable, Sendable {staticfunc named(_ word: String, cards: ThemeCards) -> CardObject? {let name = cards.objects[word] ?? wordif name == "ring" { return .ring(filled: false) }if name == "check" { return .enamel(.done) }if name == "gauge" { return .gauge }returnCardEnamel.named(name).map(CardObject.enamel) }case gauge/// The calendar's month leaf: the month on its band, the day under/// it; neither for an empty date.case leaf(day: Int?, month: String?)/// The clock face with its hands at the time; no hands for an empty time.case clock(ClockTime?)/// One of the generated enamel objects.case enamel(CardEnamel)case tool(name: String, picture: ToolPicture?)/// The value itself set large — a number is its own object.case figure(String)/// Words are their own first words, in handwriting.case words(String)/// A status: an ink ring, filled when the record is done.case ring(filled: Bool)/// A tool's or a project's cap, printed with its name.case cap(name: String, colour: CapColour)/// A cap nobody has picked yet: the cap alone, no plus.case emptyCap/// People, as their prints, the first in front.case people([CardPerson])/// A polaroid of a stored picture, or an empty print.case print(key: String?, seed: String)}structCardObjectView: View { @Environment(\.theme) privatevar themelet object: CardObject/// The square the card gives the object.let side: CGFloatvar body: someView { drawn .frame(width: side, height: side) .accessibilityHidden(true) } @ViewBuilder privatevar drawn: someView {switch object {case .gauge:Image(systemName: "gauge.with.dots.needle.33percent") .resizable() .scaledToFit() .foregroundStyle(theme.print(.ink)) .frame(width: side * CardObjectKnobs.cardObjectEnamelSide, height: side * CardObjectKnobs.cardObjectEnamelSide)case .leaf(let day, let month):CardMonthLeaf(day: day, month: month, side: side * CardObjectKnobs.cardObjectLeafSideFraction)case .clock(let time): enamel(.clock) {iflet time {let hands = CardEnamelPrint.hands(time)// Where the live hands sit on the clock picture, in unit// coordinates of its square — measured off the generated// pictures, so a regenerated clock owes new keys.let reach = CardObjectKnobs.cardObjectClockReach hand( length: reach * CardObjectKnobs.cardObjectClockHourHandLength, width: CardObjectKnobs.cardObjectClockHourHandWidth, degrees: hands.hour) hand( length: reach * CardObjectKnobs.cardObjectClockMinuteHandLength, width: CardObjectKnobs.cardObjectClockMinuteHandWidth, degrees: hands.minute) } }case .enamel(let picture): enamel(picture) { EmptyView() }case .tool(let name, let picture):ToolObject(name: name, picture: picture, printing: .contentOnly, side: side, imageVariant: .small)case .figure(let text):Text(text) .font(theme.type.display(InkFit.figureSize(text, face: theme.type.display, preferred: side * CardObjectKnobs.cardObjectFigureTypeFraction, width: side * CardObjectKnobs.cardObjectFigureWidth, scale: theme.scale))) .foregroundStyle(theme.print(.ink).opacity(Double(CardObjectKnobs.cardObjectFigureInkOpacity))) .lineLimit(1) .fixedSize(horizontal: true, vertical: true) .frame(width: side * CardObjectKnobs.cardObjectFigureWidth)case .words(let words):// A name of a word or two is set large, as its own object, wrapping// to a second line before it shrinks; a longer run of words smaller,// three lines at most. Never cut off: `InkFit` sizes it so every// line's ink, the hand's last swash included, stands inside.let name = words.count <= CardObjectKnobs.cardObjectWordsNameMaxCharacterslet width = side * CardObjectKnobs.cardObjectWordsWidthlet lines = name ? CardObjectKnobs.cardObjectWordsNameLines : CardObjectKnobs.cardObjectWordsSentenceLines// The phone's Text clips ink at its own typographic bounds, and the// hand's last letter leans past its advance (Hyderabad's final d// drew as an a): a hair space at each end puts that ink inside the// bounds, measured by InkFit exactly as it is drawn.let room = CardObjectKnobs.cardObjectWordsInkRoomlet set = InkFit.set( words, face: theme.type.hand, preferred: side * (name ? CardObjectKnobs.cardObjectWordsShortTypeFraction : CardObjectKnobs.cardObjectWordsLongTypeFraction), width: width, lines: lines, padded: room, scale: theme.scale)let size = set.sizeText(room + set.words + room) .accessibilityLabel(words) .font(theme.type.hand(size)) .foregroundStyle(theme.print(.ink).opacity(Double(CardObjectKnobs.cardObjectWordsInkOpacity))) .multilineTextAlignment(.center) .fixedSize(horizontal: false, vertical: true) .frame(width: width, height: side * CardObjectKnobs.cardObjectWordsHeight)case .ring(let filled): ZStack {if filled {Circle().fill(theme.print(.ink).opacity(Double(CardObjectKnobs.cardObjectRingFillInkOpacity))) } else {Circle().strokeBorder( theme.print(.ink).opacity(Double(CardObjectKnobs.cardObjectRingInkOpacity)), lineWidth: max(CardObjectKnobs.cardObjectRingStrokeMin, side * CardObjectKnobs.cardObjectRingStrokeFraction)) } } .frame(width: side * CardObjectKnobs.cardObjectRingSide, height: side * CardObjectKnobs.cardObjectRingSide)case .cap(let name, let colour):ProjectCap(name: name, colour: colour, side: side * CardObjectKnobs.cardObjectCapSide)case .emptyCap:EmptyCap(side: side * CardObjectKnobs.cardObjectCapSide, adds: false)case .people(let people):CardPeople(people: people, side: side)case .print(let key, let seed):CardPrint(key: key, seed: seed, width: side * CardObjectKnobs.cardObjectPrintSide) } }/// A generated enamel object, with what is drawn live on it.privatefunc enamel(_ picture: CardEnamel, @ViewBuilder prints: () -> someView) -> someView { ZStack {iflet image = CottonMedia.image(picture.asset) { image .resizable() .interpolation(.high) .scaledToFit() .accessibilityHidden(true) } prints() } .frame(width: side * CardObjectKnobs.cardObjectEnamelSide, height: side * CardObjectKnobs.cardObjectEnamelSide) }/// One hand of the clock, turning about the dial's centre.privatefunc hand(length: CGFloat, width: CGFloat, degrees: Double) -> someView {let square = side * CardObjectKnobs.cardObjectEnamelSidereturnCapsule() .fill(theme.print(.ink).opacity(Double(CardObjectKnobs.cardObjectClockHandInkOpacity))) .frame(width: max(CardObjectKnobs.cardObjectClockHandWidthMin, square * width), height: square * length) .offset(y: -square * length * 0.5) .rotationEffect(.degrees(degrees)) .position(x: CardObjectKnobs.cardObjectClockCentreX * square, y: CardObjectKnobs.cardObjectClockCentreY * square) }}/// The calendar's month leaf, small: a cream leaf with the month on its/// red band and the day set large under it.structCardMonthLeaf: View { @Environment(\.theme) privatevar themelet day: Int?let month: String?let side: CGFloatvar body: someView {let shape = RoundedRectangle(cornerRadius: side * CardObjectKnobs.cardLeafCorner, style: .continuous) VStack(spacing: 0) {Text(month?.uppercased() ?? " ") .font(theme.type.meta(side * CardObjectKnobs.cardLeafMonthTypeFraction)) .tracking(side * CardObjectKnobs.cardLeafMonthTracking) .foregroundStyle(theme.sheet(.cream)) .lineLimit(1) .frame(maxWidth: .infinity) .frame(height: side * CardObjectKnobs.cardLeafBandHeight) .background(theme.print(.red).opacity(Double(CardObjectKnobs.cardLeafBandOpacity)))Text(day.map(String.init) ?? "") .font(theme.type.display(side * CardObjectKnobs.cardLeafDayTypeFraction)) .foregroundStyle(theme.print(.ink).opacity(Double(CardObjectKnobs.cardLeafDayInkOpacity))) .monospacedDigit() .lineLimit(1) .frame(maxWidth: .infinity, maxHeight: .infinity) } .background(theme.sheet(.cream)) .clipShape(shape) .overlay(shape.strokeBorder(theme.colors.hairline.color, lineWidth: theme.scale.hairline)) .frame(width: side * CardObjectKnobs.cardLeafWidth, height: side * CardObjectKnobs.cardLeafHeight) }}/// People on a card: up to three prints, overlapped, the first in front. A/// person with no picture is a face print with their initials, never a blank/// grey square (architect, r7).privatestructCardPeople: View { @Environment(\.theme) privatevar themelet people: [CardPerson]let side: CGFloatvar body: someView {let drawn = Array(people.prefix(CardObjectKnobs.cardObjectPeopleMax))let width = side * (drawn.count > 1 ? CardObjectKnobs.cardObjectPeopleManyWidth : CardObjectKnobs.cardObjectPeopleOneWidth)let step = width * CardObjectKnobs.cardObjectPeopleSteplet span = width + step * CGFloat(max(0, drawn.count - 1)) ZStack(alignment: .leading) {ForEach(Array(drawn.enumerated().reversed()), id: \.element.id) { index, person inCardPrint(key: person.pictureKey, seed: person.id, width: width, name: person.name) .offset(x: step * CGFloat(index)) } } .frame(width: span, alignment: .leading) }}/// A thumb-size polaroid of a stored picture; a person's face print with/// their initials until they have one, an empty print for anything else.privatestructCardPrint: View { @Environment(\.theme) privatevar themelet key: String?let seed: Stringlet width: CGFloat/// Whose print it is, when it is a person's.var name: String? = nil @State privatevar slot = MediaImageSlot()var body: someView {Group {iflet image = slot.image(for: key) {InstantPrint(seed: seed, size: .thumb) {Image(uiImage: image).resizable().scaledToFill() } } elseiflet initials = name.flatMap(CardPerson.initials) {InstantPrint(seed: seed, size: .thumb) { ZStack {Rectangle().fill(theme.sheet(.cream))Text(initials) .font(theme.type.title(width * CardObjectKnobs.cardPrintInitialsTypeFraction)) .foregroundStyle(theme.print(.pencil)) .lineLimit(1) } } } else {EmptyPrint(seed: seed, size: .thumb) } } .frame(width: width) .mediaSlot($slot, key: key, edge: width) }}/// The sizes, counts and timings CardObject draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enumCardObjectKnobs {staticlet cardObjectWordsLongTypeFraction: CGFloat = 0.17staticlet cardObjectWordsShortTypeFraction: CGFloat = 0.26staticlet cardObjectWordsNameLines = 2staticlet cardObjectWordsSentenceLines = 3staticlet cardObjectPeopleManyWidth: CGFloat = 0.5staticlet cardObjectPeopleOneWidth: CGFloat = 0.64staticlet cardLeafBandHeight: CGFloat = 0.26staticlet cardLeafBandOpacity: CGFloat = 0.86staticlet cardLeafCorner: CGFloat = 0.12staticlet cardLeafDayInkOpacity: CGFloat = 0.88staticlet cardLeafDayTypeFraction: CGFloat = 0.46staticlet cardLeafHeight: CGFloat = 0.9staticlet cardLeafMonthTracking: CGFloat = 0.01staticlet cardLeafMonthTypeFraction: CGFloat = 0.15staticlet cardLeafWidth: CGFloat = 0.82staticlet cardObjectCapSide: CGFloat = 0.78staticlet cardObjectClockCentreX: CGFloat = 0.5staticlet cardObjectClockCentreY: CGFloat = 0.5staticlet cardObjectClockHandInkOpacity: CGFloat = 0.9staticlet cardObjectClockHandWidthMin: CGFloat = 1.2staticlet cardObjectClockHourHandLength: CGFloat = 0.62staticlet cardObjectClockHourHandWidth: CGFloat = 0.03staticlet cardObjectClockMinuteHandLength: CGFloat = 0.92staticlet cardObjectClockMinuteHandWidth: CGFloat = 0.02staticlet cardObjectClockReach: CGFloat = 0.206staticlet cardObjectEnamelSide: CGFloat = 0.78staticlet cardObjectFigureInkOpacity: CGFloat = 0.88staticlet cardObjectFigureTypeFraction: CGFloat = 0.4staticlet cardObjectFigureWidth: CGFloat = 0.96staticlet cardObjectLeafSideFraction: CGFloat = 0.7staticlet cardObjectPeopleMax = 3staticlet cardObjectPeopleStep: CGFloat = 0.62staticlet cardObjectPrintSide: CGFloat = 0.7staticlet cardObjectRingFillInkOpacity: CGFloat = 0.86staticlet cardObjectRingInkOpacity: CGFloat = 0.78staticlet cardObjectRingSide: CGFloat = 0.52staticlet cardObjectRingStrokeFraction: CGFloat = 0.045staticlet cardObjectRingStrokeMin: CGFloat = 1.5staticlet cardObjectWordsHeight: CGFloat = 0.8/// The room either end of a card's words for the hand's overhanging ink.staticlet cardObjectWordsInkRoom = "\u{200A}"staticlet cardObjectWordsInkOpacity: CGFloat = 0.78staticlet cardObjectWordsNameMaxCharacters = 16staticlet cardObjectWordsWidth: CGFloat = 0.92staticlet cardPrintInitialsTypeFraction: CGFloat = 0.3}