// The CODING SESSION face (KINDS, 7f4a5f0fb; the house references 99 and// 100): the framed cream card with its title typed heavy and when it was// last active by hand under it; where it runs — the machine, the branch, the// model (`source`, cut where the core joined them) — typed one under another// on the left, with its state stamped at their right in the ink its stored// value calls for, green while it runs (a green dot beside the stamp), red// while it waits on the owner or has failed, pencil while it queues or// starts, and nothing stamped once it has ended; the last line it said typed// under them, in a speech bubble while it waits, since then the line is// what it asks the owner; what it has done (`body`) in pencil beside the// laptop at the foot. Its task list is the page after it (`card.pages`,// `FaceTurns`, its pages on its card). Every// word is the core's (`DeckCard`); the face lays them out.importCottonPaperimportCottonValuesimportSwiftUIenumSessionFaceKnobs {staticlet inset = EdgeInsets(top: 28, leading: 26, bottom: 34, trailing: 24)staticlet titleSize: CGFloat = 26staticlet dateHand: CGFloat = 24staticlet whereSize: CGFloat = 15staticlet whereLeading: CGFloat = 4staticlet stampSize: CGFloat = 16staticlet stampTurn: Double = -7staticlet dot: CGFloat = 9/// The rings of the dot's glow, as multiples of the dot.staticlet glow: [CGFloat] = [2.2, 3.6]staticlet glowOpacity: Double = 0.16staticlet lineSize: CGFloat = 15staticlet lineLimit = 3staticlet bubbleSize: CGFloat = 16staticlet summarySize: CGFloat = 12.5staticlet artShare: CGFloat = 0.3/// The laptop with no summary beside it.staticlet artAlone: CGFloat = 0.36staticlet gap: CGFloat = 16}/// How a session's state is marked, by its stored value.publicenumSessionStateMark {/// The ink its stamp is laid in.publicstaticfunc ink(_ state: String?) -> PaperInk {switch state {case"running": .greencase"waiting", "failed": .reddefault: .pencil } }/// Waiting on the owner: its last line is what it asks.publicstaticfunc asks(_ state: String?) -> Bool { state == "waiting" }}publicstructSessionFace: View {let card: DeckCard/// The ink its state is stamped in (`SessionStateMark.ink`).var mark: PaperInk = .pencil/// Its last line is a question to the owner (`SessionStateMark.asks`).var asking = false/// The pages its card turns to after it (`card.pages`), each a column's/// words under its label (`FaceTurns`).var pages: [CardPage] = []/// The page shown first: 0, the face (a gallery's specimen of a page).var opened = 0publicinit(card: DeckCard, mark: PaperInk = .pencil, asking: Bool = false, pages: [CardPage] = [], opened: Int = 0) {self.card = cardself.mark = markself.asking = askingself.pages = pagesself.opened = opened }publicvar body: someView {FaceTurns(pages: pages, opened: opened) { front } .onCardPaper(SessionFaceCatalogue.stock.laid(card.pace)) }/// The face itself, before the pages its card turns to. @ViewBuilder privatevar front: someView {GeometryReader { sheet in VStack(alignment: .leading, spacing: 0) {iflet title = card.text("title") {HeavyType(words: title, size: SessionFaceKnobs.titleSize) .lineLimit(3) .minimumScaleFactor(0.75) .accessibilityIdentifier("deck-title") .facePart(.title) }iflet active = card.text("date") {Text(HandRun.tail(active)) .font(CottonFonts.hand(SessionFaceKnobs.dateHand)) .lineLimit(1) .minimumScaleFactor(0.7) .faceInk(.ink) .padding(.top, 2) .accessibilityIdentifier("face-date") .facePart(.when) } place.padding(.top, SessionFaceKnobs.gap)iflet line = card.text("subtitle") {Group {if asking {SpeechBubble(words: line, size: SessionFaceKnobs.bubbleSize, lines: SessionFaceKnobs.lineLimit) .padding(.leading, ChatSlipShape.tail) } else {Text(line) .font(CottonFonts.type(SessionFaceKnobs.lineSize)) .lineLimit(SessionFaceKnobs.lineLimit) .lineSpacing(3) .faceInk(.ink) .fixedSize(horizontal: false, vertical: true) } } .padding(.top, SessionFaceKnobs.gap) .accessibilityIdentifier("face-last-line") .facePart(.subtitle) } HStack(alignment: .bottom, spacing: SessionFaceKnobs.gap) {iflet summary = card.text("body") {Text(summary) .font(CottonFonts.type(SessionFaceKnobs.summarySize)) .lineSpacing(3)// As many lines as the room beside the laptop holds. .truncationMode(.tail) .faceInk(.pencil) .frame(maxWidth: .infinity, alignment: .topLeading) .frame(maxHeight: .infinity, alignment: .top) .accessibilityIdentifier("face-summary") .facePart(.body) } else {Spacer(minLength: 0) }FaceArt(name: "face-art-laptop") .frame(width: sheet.size.width * (card.text("body") == nil ? SessionFaceKnobs.artAlone : SessionFaceKnobs.artShare)) .frame(maxHeight: .infinity, alignment: .bottom) } .padding(.top, SessionFaceKnobs.gap) } .padding(SessionFaceKnobs.inset) } }/// Where it runs, typed one under another, its state stamped at their right. @ViewBuilder privatevar place: someView {let chips = DeckCard.chips(card.text("source"))let state = card.text("state")if !chips.isEmpty || state != nil { HStack(alignment: .center, spacing: SessionFaceKnobs.gap) { VStack(alignment: .leading, spacing: SessionFaceKnobs.whereLeading) {ForEach(Array(chips.enumerated()), id: \.offset) { _, chip inText(chip) .font(CottonFonts.type(SessionFaceKnobs.whereSize)) .lineLimit(1) .minimumScaleFactor(0.7) .faceInk(.ink) } } .accessibilityElement(children: .combine) .accessibilityIdentifier("face-chips")Spacer(minLength: 0)iflet state { HStack(spacing: SessionFaceKnobs.gap) {if mark == .green { SessionDot() }RubberStamp(words: state, size: SessionFaceKnobs.stampSize, turn: SessionFaceKnobs.stampTurn, ink: mark) } .fixedSize() .facePart(.state) } } } }}/// The green dot of a session at work, its glow in fading rings.privatestructSessionDot: View { @Environment(\.theme) privatevar themevar body: someView { ZStack {ForEach(SessionFaceKnobs.glow, id: \.self) { ring inCircle() .fill(theme.print(.green).opacity(SessionFaceKnobs.glowOpacity)) .frame(width: SessionFaceKnobs.dot * ring, height: SessionFaceKnobs.dot * ring) }Circle() .fill(theme.print(.green)) .frame(width: SessionFaceKnobs.dot, height: SessionFaceKnobs.dot) } .blendMode(theme.printBlend) .accessibilityHidden(true) }}/// The coding session face, by the kind's name, and the cards it is reviewed/// in: its state marked off the stored value (`stored`), its task list the/// page after it.publicenumSessionFaceCatalogue {publicstaticlet stock: FaceStock = .framedpublicstaticlet ground: FaceGround = .paperpublicstaticlet face = Face(id: "session", specimens: [Specimen("running", runningSession.reading { $0.stored = ["state": "running"] $0.pages = [CardPage(label: "Task list", text: "Draw the shelf face\nRegister it on the deck\nPush to main")] }),Specimen("failed", failedSession.reading { $0.stored = ["state": "failed"] }), ]) { card, _, _ inSessionFace(card: card, mark: SessionStateMark.ink(card.stored["state"]), asking: SessionStateMark.asks(card.stored["state"]), pages: card.pages) }/// A session running, with a task list to turn to.publicstaticlet runningSession = DeckCard(face: .session, fields: ["state": .text("Running"),"title": .text("Example lane: the invented shelf face"),"subtitle": .text("Built the shelf, now running the face tests"),"body": .text("Drew the shelf face on the framed cream card, registered it on the deck and in the gallery, and measured it on the phone's stack."),"source": .text("example-mac \u{00B7} shelf-face \u{00B7} model-x"),"date": .text("2 minutes ago"), ])/// A session that failed, its last line the error.publicstaticlet failedSession = DeckCard(face: .session, fields: ["state": .text("Failed"),"title": .text("Invented importer"),"subtitle": .text("error: the example file could not be read"),"source": .text("example-mini \u{00B7} main"),"date": .text("yesterday"), ])}