// The slip: one record on the one slip paper (`ObjectSlip`), its slots filled// from its table's slip layout (recordface row 1, 21 Oct 2026: one slip face// on every list). What the layout names decides what goes in which slot://// * a TOGGLE drawn as a SWITCH (`toggle_style: "switch"`): the title as the// headline — a time as its figures with the meridiem small beside them —// the subtitle in the serif under it, the trailing value in pencil, and// the paper switch at the side. Off prints the lettering faint, never// struck. An empty slot reads its column's placeholder in pencil;// * a TOGGLE drawn as a check: the check leading, the title typed as its// prose, the trailing value and the project along the foot — on an// `upcoming` list how late it is, the hour or when a snooze brings it// back, in place of the day its heading names — then the badge, the// byline by hand and the DONE / DROPPED stamp at the foot's end;// * a PLAYER: the title in the serif, its line in pencil, and below them// the play disc and the waveform (`MeetingWaveform`, seeded by the id).// The disc is a picture of "a recording", not a control: the slip opens// the record's page, which plays it. Only bytes on this phone draw it;// * TWO PICTURES — a `photo` and a `trailing_picture` that is a photo too:// the pair below, each under its column's name with its own words,// each a tap that opens the record its column `opens`;// * a PHOTO column: the print leading, or nothing — never initials — and// the note by hand at the title's end: the byline when it is red, else// the trailing value;// * an OBJECT column: the catalogue object leading;// * a TRAILING PICTURE: the picture at the side (a place's map, a photo);// * anything else: the title in the serif, the subtitle as prose, the// trailing value along the foot. A STUB is the day's stub leading; a// numbered table (`ordinal`) writes the record's place there.//// Every slip: the unread dot in its top corner while its `opened` column is// empty; the badge at its foot's end (or its corner when it has no foot);// the figure typed and the byline by hand there; its `links` by hand under// the paper; and, while it asks its owner something, its verbs under the// paper — the reply in red hand first, then the typed answers. A `red_when`// value writes the foot in red. Only a notice (`edge: receipt`) keeps its// perforated edge; every other slip's edge is the theme's.importCottonValuesimportSwiftUIpublicstructSlipFace: View { @Environment(\.theme) privatevar themeprivatelet definition: TableDefinitionprivatelet record: TableRecordprivatelet onToggle: (() -> Void)?privatelet compact: Boolprivatelet ordinal: Int?privatelet upcoming: Bool/// What the heading this slip stands under already said of its day.privatelet dayWords: DayWordsprivatelet onAnswer: ((String) -> Void)?privatelet onReply: (() -> Void)?privatelet answering: Bool/// What the core said of the record (`RecordSaid`): the row a list/// answered, else what the record carries from its read.privatelet said: RecordSaid @Environment(\.linkTitles) privatevar links @Environment(\.cottonCore) privatevar core/// Whether the player's recording is on this phone, once the ledger has/// said: a slip offers no play disc for bytes that are not here. @State privatevar recordingHere: Bool? @Environment(\.recordOpener) privatevar opener/// - Parameters:/// - onToggle: what a tap on the check does; nil draws the check/// without a control (a tile, the preview)./// - compact: one of several across a list's grid./// - ordinal: the record's place in its list, counted from 1, for a/// table whose slip numbers its records./// - upcoming: drawn under a day heading of an `upcoming` list, which/// names the day: the foot says how late, the hour, or when a snooze/// brings the record back (`upcomingFoot`), never the day again./// - onAnswer: what a tap on one of the slip's answers does, handed the/// value it writes; nil draws no answers (a tile, the preview)./// - onReply: what a tap on the slip's reply does (opens its sheet);/// nil draws no reply./// - answering: an answer is on its way: the verbs wait, faint.publicinit( definition: TableDefinition, record: TableRecord, onToggle: (() -> Void)? = nil, compact: Bool = false, ordinal: Int? = nil, upcoming: Bool = false, onAnswer: ((String) -> Void)? = nil, onReply: (() -> Void)? = nil, answering: Bool = false, dayWords: DayWords = .full ) {self.init(definition: definition, record: record, onToggle: onToggle, compact: compact, ordinal: ordinal, upcoming: upcoming, onAnswer: onAnswer, onReply: onReply, answering: answering, dayWords: dayWords, row: nil) }/// A list's slip, its words as the core answered them (`said`).init( definition: TableDefinition, record: TableRecord, onToggle: (() -> Void)? = nil, compact: Bool = false, ordinal: Int? = nil, upcoming: Bool = false, onAnswer: ((String) -> Void)? = nil, onReply: (() -> Void)? = nil, answering: Bool = false, dayWords: DayWords = .full, row: ListAnswer.Row? ) {self.said = row?.said ?? record.said ?? .nothing// A slip typed by a choice column draws this record's variant.self.definition = definition.slip(for: record)self.record = recordself.onToggle = onToggleself.compact = compactself.ordinal = definition.slip.ordinal ? ordinal : nilself.upcoming = upcomingself.dayWords = dayWordsself.onAnswer = onAnswerself.onReply = onReplyself.answering = answering }/// Each part built in its own frame and handed on boxed (`boxed`): one/// evaluation of this body touched 737 KB of main-thread stack in a debug/// build — the phone has 1 MB for all of SwiftUI (builds 227/230/231)./// Guard: `FaceStackTests`./// A slip that opens a record: on a fan tile's page, the record grows out of it (`TilePage`).publicvar body: someView { face.zoomSource() } @ViewBuilder privatevar face: someView {// Only a slip that asks its owner something stands its verbs under// it, and only one naming its links their hand links.if definition.slip.answers == nil, definition.slip.reply == nil, definition.slip.links == nil, definition.slip.lines == nil {return boxed { dotted } }return boxed { VStack(alignment: .leading, spacing: SlipFaceKnobs.slipRowContentSpacing) { boxed { dotted } boxed { rowLines } boxed { verbs } boxed { linkRow } } } }/// The rows of another table the slip names (an order's items), one/// pencil line each, as the core said them. @ViewBuilder privatevar rowLines: someView {let lines = definition.slipRowLines(of: record)if !lines.isEmpty { VStack(alignment: .leading, spacing: SlipFaceKnobs.slipRowLineGap) {ForEach(Array(lines.enumerated()), id: \.offset) { _, line inText(line).paperMeta(theme.scale.metaSize) } } .padding(.horizontal, SlipFaceKnobs.slipButtonHorizontalPadding) .accessibilityElement(children: .combine) .accessibilityIdentifier("slip-\(definition.id)-lines-\(record.id)") } }/// The records this one is linked to, by hand under the slip ("Todo/// \u{203A}"), each opening its record through `recordOpener`; nothing/// when there is no opener (a tile, the preview) or no link. @ViewBuilder privatevar linkRow: someView {let linked = definition.slipLinks(of: record)iflet opener, !linked.isEmpty { HStack(spacing: SlipFaceKnobs.slipActionGap) {ForEach(linked, id: \.key) { link inButton { opener(link.table, TableRecord(id: link.id, values: [:])) } label: {Text(link.handLink) .paperHand(theme.scale.handSize + 1, ink: .pencil) .frame(minHeight: SlipFaceKnobs.slipLinkMinHeight) .contentShape(Rectangle()) } .buttonStyle(OpacityButtonStyle()) .accessibilityLabel(ShellLines.line("faces", "slip.open_linked", ["kind": BadgeKind.label(forKind: link.table).lowercased()])) .accessibilityIdentifier("slip-\(definition.id)-link-\(link.table)-\(link.id)-\(record.id)") }Spacer(minLength: 0) } .padding(.horizontal, SlipFaceKnobs.slipButtonHorizontalPadding) } }/// The paper, wearing the red ink dot while its record is unread.privatevar dotted: someView { paper .overlay(alignment: .topTrailing) {if said.slip.unread {UnreadDot(spoken: true) .padding(SlipFaceKnobs.slipUnreadDotPadding) .accessibilityIdentifier("\(definition.id)-\(record.id)-unread") } } }/// The reply and the typed answers, while the question is open: the/// reply first, then one verb each in its column's order, side by side or/// stacked when the slip is narrow. @ViewBuilder privatevar verbs: someView {let reply = onReply == nil ? nil : definition.replyOffered(record)let answers = onAnswer == nil ? [] : definition.answerVerbs(record)if reply != nil || !answers.isEmpty {ViewThatFits(in: .horizontal) { HStack(spacing: SlipFaceKnobs.slipVerbGap) { verbButtons(reply, answers) } VStack(alignment: .leading, spacing: 0) { verbButtons(reply, answers) } } .disabled(answering) .opacity(answering ? 0.5 : 1) .padding(.horizontal, SlipFaceKnobs.slipButtonHorizontalPadding) .accessibilityIdentifier("slip-\(definition.id)-answers-\(record.id)") } } @ViewBuilder privatefunc verbButtons(_ reply: SlipReply?, _ answers: [(value: String, words: String)]) -> someView {iflet reply, let onReply {Button(action: onReply) {Text(reply.verb) .paperHand(theme.scale.handSize + 3, ink: .red) .underline(color: theme.print(.red).opacity(SlipFaceKnobs.faceSlipUnderlineOpacity)) .frame(minWidth: SlipFaceKnobs.slipButtonMinTarget, minHeight: SlipFaceKnobs.slipButtonMinTarget) .contentShape(Rectangle()) } .buttonStyle(OpacityButtonStyle()) .accessibilityLabel("\(reply.verb) \u{2014} \(title)") .accessibilityIdentifier("slip-\(definition.id)-reply-\(record.id)") }iflet onAnswer {ForEach(answers, id: \.value) { verb in// The agreeing answer (`primary`) is a filled capsule; the rest typed words.Group {if verb.value == definition.slip.answers?.primary {VerbCapsule(title: verb.words) { onAnswer(verb.value) } } else {PaperTypedButton(verb.words, size: SlipFaceKnobs.slipAnswerSize) { onAnswer(verb.value) } } } .accessibilityLabel("\(verb.words) \u{2014} \(title)") .accessibilityIdentifier("slip-\(definition.id)-answer-\(verb.value)-\(record.id)") } } }/// Each paper in its own frame (`boxed`): only the one drawn is entered.privatevar paper: AnyView {switch said.toggled.map({ on in definition.drawsSwitch ? Form.switched(on) : Form.checked(on) }) ?? Self.form(definition, record) {case .switched(let on): return boxed { switched(on) }case .checked(let on): return boxed { checked(on) }case .played(let recording): return boxed { cornered { played(has: recording) } }case .pair: return boxed { cornered { pair } }case .strip(let photo): return boxed { cornered { strip(photo: photo) } }case .object(let key): return boxed { cornered { objectStrip(key) } }case .pictured: return boxed { cornered { pictured } }case .memory: return boxed { memory } } }/// A slip with no foot of its own wears its badge in the bottom corner.privatefunc cornered<Paper: View>(@ViewBuilder _ paper: () -> Paper) -> someView { paper().overlay(alignment: .bottomTrailing) { badgeMark.padding(SlipFaceKnobs.slipUnreadDotPadding) } }/// Whether the slip is the receipt: its `edge` says so.staticfunc isReceipt(_ definition: TableDefinition) -> Bool { definition.slip.edge == .receipt }/// Which paper a slip is, in the order the layout's slots win: a toggle,/// a player, a photo, a trailing picture, else the memory slip.enumForm: Equatable {/// A toggle drawn as a switch, and whether it is on.case switched(Bool)case checked(Bool)/// Whether the player column holds a recording.case played(Bool)/// Two pictures side by side (`photo` and a photo `trailing_picture`).case paircase strip(String?)/// A catalogue object at the left, named by the slip's `object` column.case object(String?)case picturedcase memory }staticfunc form(_ definition: TableDefinition, _ record: TableRecord) -> Form {iflet player = definition.slip.player { return .played(!RecordValue.isBlank(record[player])) }iflet photo = definition.slip.photo, definition.column(photo)?.type == .photo, definition.column(definition.slip.trailingPicture)?.type == .photo {return .pair }if definition.slip.photoName != nil { return .strip(record[definition.slip.photo].text) }iflet photo = definition.slip.photo { return .strip(record[photo].text) }iflet object = definition.slip.object { return .object(record[object].text) }if definition.slip.trailingPicture != nil { return .pictured }return .memory }/// The record's title, else its day's weekday (a journal page has none).privatevar title: String { said.slip.title ?? "" }/// The caption when the layout has one; else, under a weekday title, the/// date written out rather than the weekday again; else the trailing/// column. Under a day or month heading a date says only what the heading/// did not (`dayWords`, R7 b, c).privatevar trailing: String? { said.slip.day_foot ?? said.slip.caption ?? said.slip.trailing }privatefunc ink(_ key: String?, fallback: PaperInk = .ink) -> PaperInk { record.ink(key, fallback: fallback) }privatevar titleInk: PaperInk {let key = RecordValue.isBlank(record[definition.slip.title]) ? definition.slip.titleFallback ?? definition.title : definition.slip.titlereturn ink(key) }privatevar trailingInk: PaperInk {let keys = definition.slip.caption.map { $0.columns + [$0.status].compactMap { $0 } + $0.dates } ?? [definition.slip.trailing].compactMap { $0 }return keys.contains { ink($0) == .red } || overdue ? .red : .pencil }/// Whether the caption's date has gone by on a record still open: a/// column that names its past (`past_name`, a goal's "Was") is a day/// that was aimed at, and missing it reads in the attention colour/// (walker 604bcce6), never the quiet grey of a day ahead.privatevar overdue: Bool { said.slip.caption_late == true }/// The foot's red where a `red_when` names its value; nil otherwise, so/// a foot's own red (a todo late, a record `isRed`) still reads.privatevar trailingRed: PaperInk? { trailingInk == .red ? .red : nil }privatevar stamp: StampKind? { said.stamp.flatMap(StampKind.of(status:)) }/// Whether the slip's check is on, as answered; nil with no check.privatevar toggled: Bool? { said.toggled }/// The slip's paper: the stock its state names, else its table's dye/// (`slip.dye` — a pink slip anywhere is a todo), else the run's.privatevar dye: PaperDye {iflet stock = said.slip.stock.flatMap(SlipStock.init(rawValue:)) { returnFaceTint.dye(for: record.id, stock: stock) }return definition.slip.dye.flatMap(PaperDye.init(rawValue:)) ?? FaceTint.dye(for: record.id) }privatevar subtitleInk: PaperInk { ink(definition.slip.subtitle, fallback: .pencil) }privatevar figure: String? { said.slip.figure?.text }/// The first subtitle column holding words, else its `subtitle_fallback`'s — unless the/// title already says it (a title fallen back to the site).privatevar subtitle: String? { said.slip.subtitle == title ? nil : said.slip.subtitle }privatevar byline: String? { said.slip.byline?.words }/// The project's name, when the table files records under one.privatevar project: String? { said.slip.project_words }// ── The todo slip ───────────────────────────────────────────────────────/// On an upcoming list, an open record's foot is `upcomingFoot` (or no/// day at all); a done one keeps its own date.privatevar upcomingFoot: (day: String?, late: Bool) {guard upcoming, definition.upcoming != nil, toggled != trueelse { return (trailing, false) }return (said.slip.foot?.text ?? trailing, said.slip.foot_late?.bool ?? false) }privatefunc checked(_ on: Bool) -> someView {let foot = upcomingFootreturnObjectSlip( seed: record.id, dye: dye, proseInk: titleInk, metaInk: trailingRed, prose: title, clamp: definition.slip.titleLines(otherwise: SlipFaceKnobs.paperSlipProseLines), meta: TodoSlipFoot.line(day: foot.day, meta: nil, project: project), metaLate: foot.late, struck: definition.strikes(record), leading: {iflet onToggle {TodoPaperCheck(done: on, side: FieldLineKnobs.slipCheckSide, label: title) { _ in onToggle() } } else {TodoCheckSquare(done: on, side: FieldLineKnobs.slipCheckSide) } }, trailing: { stamped } ) .contentShape(Rectangle()) }/// The badge, the byline by hand ("high priority") and the stamp, in/// that order, at the foot's end. @ViewBuilder privatevar stamped: someView { HStack(alignment: .center, spacing: SlipFaceKnobs.slipStampGap) { badgeMarkiflet byline {Text(byline) .paperHand(theme.scale.handSize - 1, ink: .red) .lineLimit(1) .accessibilityIdentifier("slip-\(definition.id)-byline-\(record.id)") }iflet stamp {Stamp(stamp, width: SlipFaceKnobs.slipStampWidth) .rotationEffect(.degrees(SlipFaceKnobs.faceSlipStampRotationDegrees)) } } }/// The slip's badge (`slip.badge`) while its column holds a value: the/// one place any slip draws it, at its foot's end — a todo's repeat, an/// email's star — or in the corner of a slip with no foot.privatevar showsBadge: Bool { said.slip.badge != nil } @ViewBuilder privatevar badgeMark: someView {iflet badge = definition.slip.badge, showsBadge {Image(systemName: badge.symbol) .font(theme.type.interface(SlipFaceKnobs.slipBadgeSize, weight: .medium)) .foregroundStyle(theme.print(.ink)) .blendMode(theme.printBlend) .accessibilityLabel(badge.spoken) .accessibilityIdentifier("slip-\(definition.id)-badge-\(record.id)") } }// ── The switch paper ────────────────────────────────────────────────────/// The slip and its switch at the side. The words are one element for/// VoiceOver, read as the slip says them ("6:30 am, Wake, Monday,/// Friday"); the switch is its own control.privatefunc switched(_ on: Bool) -> AnyView {let spoken = definition.spoken(record, links: links.byID)let digits = compact ? SlipFaceKnobs.slipSwitchCardDigitsSize : SlipFaceKnobs.slipSwitchRowDigitsSizelet meridiem = compact ? SlipFaceKnobs.slipSwitchCardMeridiemSize : SlipFaceKnobs.slipSwitchRowMeridiemSizelet words = VStack(alignment: .leading, spacing: SlipFaceKnobs.slipSwitchDetailGap) { boxed { switchHeadline(digits: digits, meridiem: meridiem) } boxed { switchName(compact ? SlipFaceKnobs.slipSwitchTitleSize : SlipFaceKnobs.slipSwitchRowTitleSize) } boxed { switchFoot } } .accessibilityElement(children: .ignore) .accessibilityLabel(spoken)return boxed {ObjectSlip( seed: record.id, dye: dye, headline: AnyView(words), side: AnyView(paperSwitch(on, spoken).scaleEffect(compact ? SlipFaceKnobs.faceSlipSwitchScale : 1)), leading: { EmptyView() }, trailing: { EmptyView() }) } }/// The lettering's strength: full when on, faint when off.privatevar lettering: Double { toggled == false ? TableDefinition.offStrength : 1 }/// The title, large: a time as its figures with the meridiem small on the/// same baseline ("6:30" and "am"), anything else in the serif. @ViewBuilder privatefunc switchHeadline(digits: CGFloat, meridiem: CGFloat) -> someView {let column = definition.column(definition.slip.title)if column?.type == .time, let clock = FaceText.clockParts(record.columnWords(definition.slip.title)?.said) { HStack(alignment: .firstTextBaseline, spacing: SlipFaceKnobs.slipSwitchBaselineGap) {// The figures shrink to the card's width, never cut: an// ellipsis took "11:45" to "11:..." (290 walk, Alarms).Text(clock.digits).paperBody(digits).lineLimit(1).minimumScaleFactor(SlipFaceKnobs.slipSwitchDigitsMinScale)iflet small = clock.meridiem { Text(small).paperBody(meridiem) } } .opacity(lettering) } elseiflet words = definition.slipWords(definition.slip.title, of: record, links: links.byID) {Text(words.text) .paperTitle(digits * SlipFaceKnobs.slipSwitchWordsScale, ink: words.placeholder ? .pencil : .ink) .lineLimit(nil) .fixedSize(horizontal: false, vertical: true) .opacity(lettering) } }/// The subtitle in the serif, or its placeholder in pencil. @ViewBuilder privatefunc switchName(_ size: CGFloat) -> someView {iflet words = definition.slipWords(definition.slip.subtitle, of: record, links: links.byID) {Text(words.text) .paperTitle(size, ink: words.placeholder ? .pencil : .ink) .lineLimit(nil) .fixedSize(horizontal: false, vertical: true) .opacity(lettering) } }/// The trailing value in pencil ("Mon\u{2013}Fri"), or its placeholder. @ViewBuilder privatevar switchFoot: someView { HStack(alignment: .firstTextBaseline, spacing: SlipFaceKnobs.slipStampGap) {iflet words = definition.slipWords(definition.slip.trailing, of: record, links: links.byID) {Text(words.text) .paperBody(theme.scale.bodySize - 1.5, ink: .pencil) .lineLimit(nil) .fixedSize(horizontal: false, vertical: true) .opacity(lettering) } badgeMark } }/// The paper switch: a tap writes the toggle through `onToggle`; without/// one (a tile, the preview) it is drawn and does nothing. The slip's/// words are what VoiceOver reads for it.privatefunc paperSwitch(_ on: Bool, _ spoken: String) -> someView {Toggle( spoken, isOn: Binding(get: { on }, set: { _ in onToggle?() }) ) .labelsHidden() .toggleStyle(.paper) .disabled(onToggle == nil) .accessibilityIdentifier("slip-\(definition.id)-switch-\(record.id)") }// ── The message strip ─────────────────────────────────────────────────── @ViewBuilder privatefunc strip(photo: String?) -> someView {iflet nameColumn = definition.slip.photoName { printed {RecordPrint(key: photo, name: record[nameColumn].text ?? "Somebody", detail: nil, seed: record[nameColumn].text ?? record.id, caption: nil, edge: SlipFaceKnobs.paperStripLeadingSide, size: .thumb, tilts: false) } } elseiflet photo { printed {InstantPrint(seed: record.id, size: .thumb) {RecordPicture(avatarKey: photo, edge: SlipFaceKnobs.paperStripLeadingSide) } } } else { printed { EmptyView() } } }/// The slip with a photographed object leading — the same picture Home's/// tile draws, its label left off since the slip says the name. A key/// with no object draws the slip alone, never a hole. @ViewBuilder privatefunc objectStrip(_ key: String?) -> someView { printed {iflet key, let asset = ToolObjects.asset(for: key) {ToolObject(name: title, asset: asset, printing: .contentOnly, side: SlipFaceKnobs.paperStripLeadingSide) .accessibilityHidden(true) } } }/// A slip with a picture leading: the title on one line with the note by/// hand at its end — the byline by hand stands in it when nothing/// trails ("Very likely"), and a red one ("suggested") is the note even/// when something does — and the subtitle on one line under it.privatefunc printed<Print: View>(@ViewBuilder _ print: @escaping () -> Print) -> someView {let note = definition.bylineIsRed ? (byline ?? trailing) : (trailing ?? byline)returnObjectSlip( seed: record.id, dye: dye, title: title, titleInk: titleInk, proseInk: subtitleInk, titleLines: 1, prose: subtitle, clamp: 1, note: note, noteInk: trailingInk, leading: {// No print, no gap: nothing stands in for a missing picture.ifPrint.self != EmptyView.self { print().frame(width: SlipFaceKnobs.paperStripLeadingSide) } }, trailing: { EmptyView() }) }// ── The pair ────────────────────────────────────────────────────────────privatevar pair: someView {ObjectSlip( seed: record.id, dye: dye, meta: trailing, below: AnyView(HStack(alignment: .top, spacing: SlipFaceKnobs.slipPairSideGap) { side(definition.slip.photo) side(definition.slip.trailingPicture) }), leading: { EmptyView() }, trailing: { EmptyView() }) }/// One side of the pair: its column's name, its picture opening what the/// column `opens` (or quiet ground when the picture is gone), its words.privatefunc side(_ key: String?) -> someView {let column = definition.column(key)let picture = record[key].textlet target = definition.opening(record, column: key)return VStack(alignment: .leading, spacing: SlipFaceKnobs.slipPairLabelGap) {Text(column?.label ?? "") .paperMeta(theme.scale.metaSize - 0.5)Button {iflet target { opener?(target.table, TableRecord(id: target.id, values: [:])) } } label: {GeometryReader { geo iniflet picture {RecordPicture(avatarKey: picture, edge: geo.size.width) } else { ZStack {Rectangle().fill(theme.colors.groundMuted.color)Text(ShellLines.line("faces", "slip.picture_gone")) .paperHand(theme.scale.handSize - 1, ink: .pencil) .multilineTextAlignment(.center) .padding(SlipFaceKnobs.slipPairGonePadding) } } } .aspectRatio(1, contentMode: .fit) .clipShape(PaperShape(edge: .cut, seed: record.id + "-\(key ?? "")", theme: theme)) } .buttonStyle(MotionButtonStyle()) .disabled(target == nil || opener == nil || picture == nil) .accessibilityIdentifier("slip-\(definition.id)-\(record.id)-\(key ?? "")")iflet words = definition.pictureCaption(of: key, in: record, links: links.byID) {Text(words) .paperBody(theme.scale.bodySize - 2, ink: .pencil) .lineLimit(SlipFaceKnobs.slipPairWordsMaxLines) } } .frame(maxWidth: .infinity, alignment: .leading) }// ── The meeting sheet ───────────────────────────────────────────────────privatefunc played(has recording: Bool) -> someView {// Nothing is offered that cannot work: the disc and the waveform// only for a recording whose bytes are on this phone (a store with// no ledger to ask draws what the record names).let player = HStack(spacing: SlipFaceKnobs.slipMeetingPlayerGap) { playDisc(enabled: true) waveform } .frame(height: SlipFaceKnobs.slipMeetingPlayerHeight)returnObjectSlip( seed: record.id, dye: dye, title: title, titleInk: titleInk, proseInk: ink(subtitle == nil ? definition.slip.trailing : definition.slip.subtitle, fallback: .pencil), titleLines: definition.slip.titleLines(otherwise: SlipFaceKnobs.slipMeetingTitleLines), prose: Self.playerLine(subtitle: subtitle, trailing: trailing), clamp: 2, below: recording && (core == nil || recordingHere == true) ? AnyView(player) : nil, leading: { EmptyView() }, trailing: { EmptyView() }) .task(id: playerKey) { await askRecordingHere() } .onMediaArrival { await askRecordingHere() } }/// The object key of the recording the slip's player names.privatevar playerKey: String? { definition.slip.player.flatMap { MediaStage.key(record[$0]) } }/// Asks the ledger whether the recording's bytes are here — never a fetch.privatefunc askRecordingHere() async {guardlet core, let key = playerKey else { return } recordingHere = awaitPhotosMediaSource(core: core).answer(for: key, tier: .original) != nil }staticfunc playerLine(subtitle: String?, trailing: String?) -> String? {let parts = [subtitle, trailing].compactMap { $0 }.filter { !$0.isEmpty }var seen: Set<String> = []let unique = parts.filter { seen.insert($0).inserted }return unique.isEmpty ? nil : unique.joined(separator: " · ") }/// The sheet's picture of a recording; hidden from VoiceOver, since the/// whole slip is the control.privatefunc playDisc(enabled: Bool) -> someView { ZStack {Circle().fill(theme.print(.pencil).opacity(SlipFaceKnobs.faceSlipControlFillOpacity))Image(systemName: "play.fill") .font(theme.type.interface(SlipFaceKnobs.slipMeetingDiscSymbolSize)) .foregroundStyle(theme.print(.ink)) .offset(x: 1) } .frame(width: SlipFaceKnobs.slipMeetingDiscSide, height: SlipFaceKnobs.slipMeetingDiscSide) .opacity(enabled ? 1 : SlipFaceKnobs.faceSlipControlDisabledOpacity) .accessibilityHidden(true) }privatevar waveform: someView {GeometryReader { geo inWaveform( samples: MeetingWaveform.bars(MeetingWaveform.samples(id: record.id), count: MeetingWaveform.barCount(width: geo.size.width, pitch: SlipFaceKnobs.slipMeetingWavePitch) ), barFraction: SlipFaceKnobs.slipMeetingWaveBarFraction, theme: theme ) .fill(theme.print(.pencil)) } .accessibilityHidden(true) }// ── The place row ───────────────────────────────────────────────────────privatevar pictured: someView {ObjectSlip( seed: record.id, dye: dye, title: title, titleInk: titleInk, proseInk: ink(subtitle == nil ? definition.slip.trailing : definition.slip.subtitle, fallback: .pencil), titleLines: definition.slip.titleLines(otherwise: 1), prose: subtitle ?? trailing, clamp: 1, side: TrailingPicture.has(definition, record) ? AnyView(TrailingPicture(definition: definition, record: record) .clipShape(PaperShape(edge: .cut, seed: record.id + "-picture", theme: theme)) .frame(width: SlipFaceKnobs.slipPlacePictureWidth, height: SlipFaceKnobs.slipPlacePictureHeight) ) : nil, leading: { EmptyView() }, trailing: { EmptyView() }) }// ── The memory slip ─────────────────────────────────────────────────────/// With a stamp only when it wears one: a slip whose foot is empty draws/// no foot band (`ObjectSlip.foot`). @ViewBuilder privatevar memory: someView {iflet stamp { memory(mark: { figured { Stamp(stamp, width: SlipFaceKnobs.slipStampWidth).rotationEffect(.degrees(SlipFaceKnobs.faceSlipStampRotationDegrees)) } }) .accessibilityValue(stamp.spoken) } elseif figure != nil || byline != nil || showsBadge { memory(mark: { figured { EmptyView() } }) } else { memory(mark: { EmptyView() }) } }/// The byline by hand, then the figure, typed, before whatever else ends/// the foot.privatefunc figured<Mark: View>(@ViewBuilder _ mark: () -> Mark) -> someView { HStack(alignment: .firstTextBaseline, spacing: SlipFaceKnobs.slipFigureGap) {iflet byline {Text(byline) .paperHand(theme.scale.handSize - 1, ink: definition.bylineIsRed ? .red : .pencil) .lineLimit(1) .accessibilityIdentifier("slip-\(definition.id)-byline-\(record.id)") }iflet figure {Text(figure) .font(theme.type.body(theme.scale.bodySize - 0.5)) .foregroundStyle(ink(definition.slip.figure) == .red ? theme.print(.red) : theme.colors.ink.color) .fixedSize() } badgeMark mark() } }privatefunc memory<Mark: View>(@ViewBuilder mark: @escaping () -> Mark) -> someView {let stub = definition.slip.stub == nil ? nil : said.slip.stub.map { stub in (day: stub.day?.text ?? stub.day?.number.map { String(Int($0)) } ?? "", month: stub.month?.text ?? "") }returnObjectSlip( seed: record.id, dye: dye,// Only a notice keeps its perforated edge; the rest are the theme's. edge: Self.isReceipt(definition) ? .receipt : nil, title: title.isEmpty ? nil : title, titleInk: titleInk, proseInk: ink(definition.slip.subtitle), metaInk: trailingRed,// A receipt is read whole: its server sentences are not folded. titleLines: Self.isReceipt(definition) ? Int.max : definition.slip.titleLines(otherwise: compact ? SlipFaceKnobs.slipMemoryCompactTitleLines : SlipFaceKnobs.slipMemoryTitleLines), prose: subtitle, clamp: Self.isReceipt(definition) ? Int.max : (compact ? SlipFaceKnobs.slipMemoryCompactProseLines : SlipFaceKnobs.paperSlipProseLines), meta: TodoSlipFoot.line(day: trailing, meta: nil, project: project), metaLate: definition.isRed(record), leading: {if definition.slip.stub != nil {DayStub(stub: stub, seed: record.id) } elseiflet ordinal {Text("\(ordinal)") .paperHand(theme.scale.handSize + 6, ink: .pencil) .frame(minWidth: SlipFaceKnobs.slipOrdinalMinWidth, alignment: .leading) .accessibilityIdentifier("\(definition.id)-\(record.id)-ordinal") } }, trailing: mark ) }}/// A receipt's stub: the day's number large over its month small, both by/// hand, on a tab a dashed pencil tear divides from the slip. An empty stub/// stays blank paper rather than a made-up day.structDayStub: View { @Environment(\.theme) privatevar themelet stub: (day: String, month: String)?let seed: Stringvar body: someView { HStack(spacing: SlipFaceKnobs.slipStubGap) { VStack(spacing: SlipFaceKnobs.slipStubLineGap) {iflet stub {Text(stub.day).paperHand(theme.scale.handSize + 6)Text(stub.month).paperHand(theme.scale.handSize - 2) } } .frame(width: SlipFaceKnobs.slipStubWidth)PencilDash(seed: seed, startRange: SlipFaceKnobs.slipStubDashStartRange) .stroke(theme.print(.pencil), style: StrokeStyle(lineWidth: 1, dash: [SlipFaceKnobs.slipStubDashLength, SlipFaceKnobs.slipStubDashGap])) .frame(width: 1) } .fixedSize(horizontal: true, vertical: false) .accessibilityElement(children: .combine) }}/// A vertical pencil line the dash pattern breaks into a tear; the seed/// nudges where the dashes start so two stubs never match exactly.structPencilDash: Shape {let seed: String/// How far down the dashes may start, read from the theme by the stub.let startRange: CGFloatfunc path(in rect: CGRect) -> Path {let start = CGFloat(PaperNoise(seed: seed, salt: 0x7374_7562, count: 4).value(at: 0)) * startRangevar path = Path() path.move(to: CGPoint(x: rect.midX, y: rect.minY + start)) path.addLine(to: CGPoint(x: rect.midX, y: rect.maxY))return path }}/// The sizes, counts and timings SlipFace draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enumSlipFaceKnobs {/// How far a switch paper's time may shrink to stand whole on its card.staticlet slipSwitchDigitsMinScale: CGFloat = 0.5staticlet faceSlipControlDisabledOpacity: CGFloat = 0.4staticlet faceSlipControlFillOpacity: CGFloat = 0.16staticlet faceSlipStampRotationDegrees: CGFloat = -9staticlet faceSlipSwitchScale: CGFloat = 0.72staticlet faceSlipUnderlineOpacity: CGFloat = 0.6staticlet paperSlipProseLines = 3staticlet paperStripLeadingSide: CGFloat = 44staticlet slipActionGap: CGFloat = 14staticlet slipAnswerSize: CGFloat = 15staticlet slipBadgeSize: CGFloat = 11staticlet slipButtonHorizontalPadding: CGFloat = 6staticlet slipButtonMinTarget: CGFloat = 44staticlet slipFigureGap: CGFloat = 8staticlet slipLinkMinHeight: CGFloat = 32staticlet slipMeetingDiscSide: CGFloat = 32staticlet slipMeetingDiscSymbolSize: CGFloat = 12staticlet slipMeetingPlayerGap: CGFloat = 12staticlet slipMeetingPlayerHeight: CGFloat = 34staticlet slipMeetingTitleLines = 2staticlet slipMeetingWaveBarFraction: CGFloat = 0.45staticlet slipMeetingWavePitch: CGFloat = 3staticlet slipMemoryCompactProseLines = 5staticlet slipMemoryCompactTitleLines = 3staticlet slipMemoryTitleLines = 2staticlet slipOrdinalMinWidth: CGFloat = 22staticlet slipPairGonePadding: CGFloat = 6staticlet slipPairLabelGap: CGFloat = 4/// Between the lines a slip says from another table (an order's items).staticlet slipRowLineGap: CGFloat = 2staticlet slipPairSideGap: CGFloat = 12staticlet slipPairWordsMaxLines = 2staticlet slipPlacePictureHeight: CGFloat = 50staticlet slipPlacePictureWidth: CGFloat = 72staticlet slipRowContentSpacing: CGFloat = 6staticlet slipStampGap: CGFloat = 8staticlet slipStampWidth: CGFloat = 88staticlet slipStubDashGap: CGFloat = 3staticlet slipStubDashLength: CGFloat = 3staticlet slipStubDashStartRange: CGFloat = 3staticlet slipStubGap: CGFloat = 10staticlet slipStubLineGap: CGFloat = -2staticlet slipStubWidth: CGFloat = 34staticlet slipSwitchBaselineGap: CGFloat = 5staticlet slipSwitchCardDigitsSize: CGFloat = 38staticlet slipSwitchCardMeridiemSize: CGFloat = 15staticlet slipSwitchDetailGap: CGFloat = 3staticlet slipSwitchRowDigitsSize: CGFloat = 26staticlet slipSwitchRowMeridiemSize: CGFloat = 12staticlet slipSwitchRowTitleSize: CGFloat = 17staticlet slipSwitchTitleSize: CGFloat = 19staticlet slipSwitchWordsScale: CGFloat = 0.75staticlet slipUnreadDotPadding: CGFloat = 10staticlet slipVerbGap: CGFloat = 18}