Cotton code
181 lines · 7.5 KB · SwiftRaw
// A studio's MEMBERSHIP (Sharmila's boards, syz-membership, 23 Oct 2026):// the brand card in its// heading ink — the plan spaced small (`title`), the member large// (`subtitle`), the core's validity line (`next_charge`, said whole by the// package: "Valid till 12 Nov"), the big number of sessions with its words// (`count`: "148 sessions attended"), its facts under their labels (`facts`:// Last class), and the classes taken of the period as a coral ring (`used`// of `limit`) with the core's words for it (`period`) over the studio's// photograph (`photo`) where the card names one. No invented portrait: the// member's initials. Every word is the core's (`DeckCard`).import CottonPaperimport CottonValuesimport SwiftUI/// A membership: the brand's card in its heading ink, its words in the/// paper's colour, the studio's photograph at its foot under the ring.public struct MembershipFace<Photo: View>: View {    let card: DeckCard    var photo: Photo?    @Environment(\.theme) private var theme    public init(card: DeckCard, photo: Photo?) {        self.card = card        self.photo = photo    }    public var body: some View {        GeometryReader { sheet in            let corner = theme.scale.radius(for: sheet.size)            ZStack(alignment: .bottom) {                theme.colors.ink.color                if let photo, card.text("photo") != nil {                    MembershipPhoto(photo: photo, height: sheet.size.height * StudioFaceKnobs.photoShare)                        .facePart(.picture)                }                MembershipWords(card: card)                    .padding(StudioFaceKnobs.inset)                    .frame(width: sheet.size.width, height: sheet.size.height, alignment: .topLeading)            }            .foregroundStyle(theme.colors.paper.color)            .clipShape(RoundedRectangle(cornerRadius: corner, style: .continuous))        }    }}/// The studio's photograph at the card's foot, fading up into its ink.private struct MembershipPhoto<Photo: View>: View {    let photo: Photo    let height: CGFloat    @Environment(\.theme) private var theme    var body: some View {        photo            .frame(height: height)            .frame(maxWidth: .infinity)            .clipped()            .overlay(LinearGradient(colors: [theme.colors.ink.color, theme.colors.ink.color.opacity(0.25)],                                    startPoint: .top, endPoint: .bottom))            .accessibilityIdentifier("face-photo")    }}/// The membership's words: head, figure, facts and ring.private struct MembershipWords: View {    let card: DeckCard    @Environment(\.theme) private var theme    var body: some View {        VStack(alignment: .leading, spacing: 12) {            MembershipHead(card: card)            Rectangle().fill(theme.colors.paper.color.opacity(StudioFaceKnobs.ruleFaint)).frame(height: 1)            HStack(alignment: .top, spacing: 8) {                MembershipFigure(card: card)                Spacer(minLength: 0)                if let seats = StudioReading.seats(card) {                    SessionsRing(taken: seats.taken, of: seats.of, words: card.text("period"))                }            }            Spacer(minLength: 0)        }    }}/// The plan spaced small, the member large, the core's validity line; the/// member's initials beside them.private struct MembershipHead: View {    let card: DeckCard    @Environment(\.theme) private var theme    var body: some View {        HStack(alignment: .top, spacing: 10) {            VStack(alignment: .leading, spacing: 6) {                if let plan = card.text("title") {                    Text(plan)                        .font(theme.type.title(StudioFaceKnobs.planSize))                        .tracking(StudioFaceKnobs.planTracking)                        .textCase(.uppercase)                        .lineLimit(2)                        .accessibilityIdentifier("deck-title")                        .facePart(.title)                }                if let member = card.text("subtitle") {                    Text(member)                        .font(theme.type.display(StudioFaceKnobs.memberSize))                        .lineLimit(2)                        .minimumScaleFactor(0.6)                        .accessibilityIdentifier("face-member")                        .facePart(.subtitle)                }                if let valid = card.text("next_charge") {                    Text(valid)                        .font(theme.type.body(StudioFaceKnobs.factSize + 2))                        .lineLimit(1)                        .accessibilityIdentifier("face-next_charge")                }            }            Spacer(minLength: 0)            if let member = card.text("subtitle") {                StudioMonogram(name: member, size: StudioFaceKnobs.monogram, inverse: true)            }        }    }}/// The big number with its words, the state, and the card's facts under/// their labels (the last class).private struct MembershipFigure: View {    let card: DeckCard    @Environment(\.theme) private var theme    var body: some View {        VStack(alignment: .leading, spacing: 10) {            if let count = StudioReading.figure(card.text("count")) {                VStack(alignment: .leading, spacing: 0) {                    Text(count.figure)                        .font(theme.type.display(StudioFaceKnobs.figureSize))                        .lineLimit(1)                        .minimumScaleFactor(0.5)                    if let words = count.words {                        Text(words).font(theme.type.body(StudioFaceKnobs.factSize + 2)).lineLimit(1)                    }                }                .accessibilityElement(children: .combine)                .accessibilityIdentifier("face-count")            } else if let price = card.text("price") {                Text(price).font(theme.type.title(StudioFaceKnobs.memberSize * 0.8)).lineLimit(1)            }            ForEach(Array(StudioReading.facts(card).prefix(2).enumerated()), id: \.offset) { _, fact in                VStack(alignment: .leading, spacing: 2) {                    if let label = fact.label {                        Text(label).font(theme.type.body(StudioFaceKnobs.factSize)).opacity(StudioFaceKnobs.labelFaint)                    }                    Text(fact.said).font(theme.type.title(StudioFaceKnobs.factSize + 3)).lineLimit(2)                }                .accessibilityElement(children: .combine)            }        }    }}/// The membership face, and the cards it is reviewed in. A kit names it for/// its packs and offers (`sharmila.membership`), and the deck draws it/// straight from the registry; here it is drawn from its card alone.public enum MembershipFaceCatalogue {    public static let stock: FaceStock = .own    public static let ground: FaceGround = .paper    public static let face = Face(id: "sharmila.membership", specimens: [Specimen("ten-classes", tenClasses)]) { card, picture, _ in        MembershipFace(card: card, photo: picture)    }    public static let tenClasses = DeckCard(face: .subscription, fields: [        "title": .text("Ten classes"), "subtitle": .text("Invented Member"), "used": .number(7), "limit": .number(10),        "count": .text("148 sessions attended"),        "facts": .list([            .object(["label": .text("Invented label"), "said": .text("Mon 9:15 AM")]),            .object(["label": .text("Invented label"), "said": .text("Wed 11:30 AM")]),        ]),        "period": .text("classes this quarter"), "photo": .text("k"),    ])}