// Home's projects as a board of bottle caps.//// The owner's design of 2026-09-13, from a reference picture: every active// project is an enamelled bottle cap with its name printed on the face, laid// out four to a row on a plaster ground; the rest of a row that a count does// not fill is bare caps with a plus, and "New project" is the plus over the// grid. It is the first screen of a warmer, more physical phone — "delightful,// joyous software" — and it is deliberately unlike the settings-grammar cards// under it, which change later or not at all.//// THE CAP IS A PHOTOGRAPH, THE NAME IS TYPE. The thirteen caps in// `Media.xcassets` (twelve enamels and the bare one) were generated once, from// one master, so they share a geometry, a lighting and a lens; the name is// set live in `CottonFonts.cap` and BLENDED onto the enamel — multiplied when// the ink is dark, screened when it is cream — so the cap's own scratches and// chips show through the letters the way print on metal wears. A rename is a// redraw, not a new picture, and adding a project costs nothing.//// WHICH CAP A PROJECT GETS is decided here, from the slug, and nowhere else:// a project row carries no colour (`cotton_memory_projects` has none, and the// colour rule wants none), so `CapColour.assign` folds the slug through a// FIXED hash — not `Hasher`, which is seeded per launch — and takes the next// free enamel in slug order when two projects land on one. The same set of// slugs is the same board every launch and on every phone; a project keeps// its cap until a neighbour with a colliding slug is added, which with twelve// enamels and a handful of projects is rare.//// THE COLOUR RULE. The ink on a cap is cream or near-black and does not flip// with the theme, because it is not a colour of the design system: it is paint// on a photograph, fixed the way the photograph is. `PaletteGuardTests` exempts// this file from the CHANNELS sweep for that reason and from nothing else. The// two paints are `PrintInk`, below, and Home's tool objects print with the// same two (`Paper/ToolPrint.swift`).//importSwiftUI// MARK: - The twelve enamels/// The enamels a cap comes in, in the board's order. The raw value is the/// imageset's name less its `cap-` prefix.publicenumCapColour: String, CaseIterable, Sendable {case cream, red, navy, yellow, green, silver, orange, burgundy, sky, pink, black, teal/// The imageset in `Media.xcassets`.publicvar asset: String { "cap-\(rawValue)" }/// The light enamels take dark ink; the rest take cream.publicvar inkIsDark: Bool {switchself {case .cream, .yellow, .silver, .sky, .pink: returntruecase .red, .navy, .green, .orange, .burgundy, .black, .teal: returnfalse } }/// Which of the two paints this enamel takes — see `PrintInk`.publicvar paint: PrintInk { inkIsDark ? .dark : .cream }/// The ink itself. Two fixed paints, not palette roles — see the header.publicvar ink: Color { paint.color }/// The blend that makes the ink read as PRINTED rather than pasted: dark/// ink darkens the enamel and cream ink lightens it, so a scratch or a/// chip under a letter still shows.publicvar blend: BlendMode { paint.blend }/// Each slug's enamel. Deterministic in the SET of slugs, not their order:/// the slugs are walked alphabetically, each takes the enamel its hash/// names or the next free one after it, and only once every enamel is/// taken do two projects share.publicstaticfunc assign(_ slugs: [String]) -> [String: CapColour] {var taken = Set<CapColour>()var out: [String: CapColour] = [:]for slug inSet(slugs).sorted() {let start = Int(fnv1a(slug) % UInt64(allCases.count))var pick = allCases[start]for offset in0..<allCases.count {let candidate = allCases[(start + offset) % allCases.count]if !taken.contains(candidate) { pick = candidatebreak } } taken.insert(pick) out[slug] = pick }return out }/// FNV-1a over the slug's UTF-8 — the same number on every launch and/// every device, which `Hasher` is not.publicstaticfunc fnv1a(_ text: String) -> UInt64 { StableHash.fnv1a(text) }}// MARK: - The board's arithmeticpublicenumCapBoard {/// Caps to a row, as `scale` sets it (`cap_board_columns`).publicstaticfunc columns(in scale: ThemeScale) -> Int { ProjectCapsKnobs.capBoardColumns }}// MARK: - One cap/// One project's cap: the enamel, the name blended onto it, the short rule/// under the name. Square; the caller decides the side.////// **It draws on BOTH hosts.** The enamel used to be `Image(_:bundle: .module)`/// inside `#if canImport(UIKit)`, and the `#else` was a bare `Text(name)` — no/// font, no enamel, squeezed into whatever frame the caller had set. That is/// what the Mac walk photographed (finding 7): "T…" in the sidebar at 22pt,/// "…" on a scope chip at 18pt, and "The Walk" in the SYSTEM font filling the/// project page's 118pt picture slot. The picture is reachable on the Mac —/// `CottonMedia.image` reads it out of the located bundle, compiled catalogue/// or raw imageset, which is how `AllProjectsRing` draws the same enamels —/// and so is the cap face (`CottonFonts.cap`). So there is no platform branch/// here at all now:/// one view, two hosts, and a name that cannot fall back to system text.publicstructProjectCap: View { @Environment(\.theme) privatevar themepubliclet name: Stringpubliclet colour: CapColour/// The cap's side, when the caller already knows it — a board of caps does,/// and a board of caps each measuring itself is one layout container per/// cap for a figure the grid decided. `nil` measures, which is what a chip/// and a page's picture slot want.publiclet side: CGFloat?publicinit(name: String, colour: CapColour, side: CGFloat? = nil) {self.name = nameself.colour = colourself.side = side }publicvar body: someView {iflet side {// A cap is a photograph with a name printed on it and nothing in// it moves, so it is drawn once and kept — on the SIZED path// alone, which is the board's (as `ToolCard.sized`).// Rasterised, the subtree is ONE element with no text in it, and// the tree read the cap as its asset's name ("cap-navy"); the cap// says its printed name on both paths. face(side: side).drawingGroup() .accessibilityElement(children: .ignore) .accessibilityLabel(name) } else {GeometryReader { geo in face(side: geo.size.width) } .aspectRatio(1, contentMode: .fit) .accessibilityElement(children: .ignore) .accessibilityLabel(name) } } @ViewBuilder privatefunc face(side: CGFloat) -> someView {switch theme.cap.texture {case .enamel: enamel(side: side)case .flat: flat(side: side) } }/// A flat disc in the enamel's colour, the name set plainly on it.privatefunc flat(side: CGFloat) -> someView { ZStack {Circle().fill(colour.flat.color)// Whole words, cut at a word, never mid-word (the card-text rule).let set = InkFit.set(name, face: theme.type.cap, preferred: side * ProjectCapsKnobs.capFlatNameSize, width: side * ProjectCapsKnobs.capFlatNameWidth, lines: ProjectCapsKnobs.capNameLines, scale: theme.scale)Text(set.words) .accessibilityLabel(name) .font(theme.type.cap(set.size)) .multilineTextAlignment(.center) .lineLimit(ProjectCapsKnobs.capNameLines) .frame(width: side * ProjectCapsKnobs.capFlatNameWidth, height: side * ProjectCapsKnobs.capFlatNameHeight) .foregroundStyle(colour.ink) } .frame(width: side, height: side) }privatefunc enamel(side: CGFloat) -> someView { ZStack {CottonMedia.image(colour.asset)? .resizable() .interpolation(.medium) .scaledToFit()// The enamel is the cap's material; its NAME is the text// printed on it, below. .accessibilityHidden(true)let set = InkFit.set(name, face: theme.type.cap, preferred: side * ProjectCapsKnobs.capEnamelNameSize, width: side * ProjectCapsKnobs.capEnamelPrintWidth, lines: ProjectCapsKnobs.capNameLines, scale: theme.scale) VStack(spacing: side * ProjectCapsKnobs.capEnamelPrintGap) {Text(set.words) .accessibilityLabel(name) .font(theme.type.cap(set.size)) .multilineTextAlignment(.center) .lineLimit(ProjectCapsKnobs.capNameLines)Capsule() .frame( width: side * ProjectCapsKnobs.capEnamelRuleWidth, height: max(ProjectCapsKnobs.capEnamelRuleHeightMin, side * ProjectCapsKnobs.capEnamelRuleHeight) ) }// The enamel's face is ~64 % of the cap's side once the pad// and the skirt are taken off; the print stays inside it. .frame(width: side * ProjectCapsKnobs.capEnamelPrintWidth, height: side * ProjectCapsKnobs.capEnamelPrintHeight) .foregroundStyle(colour.ink) .blendMode(colour.blend) .offset(y: -side * ProjectCapsKnobs.capEnamelPrintLift) } .compositingGroup() .frame(width: side, height: side) }}/// The bare cap that fills out a row — a plus on unpainted steel.////// The plus is drawn, not baked: the photograph's own plus is a hairline at/// a phone's cap size, so a glyph in tertiary ink is multiplied onto the/// steel over it — printed, like the names, and legible.publicstructEmptyCap: View { @Environment(\.theme) privatevar theme/// The cap's side, when the caller knows it — `ProjectCap.side`'s reason,/// and the bare caps sit in the same board.publiclet side: CGFloat?/// Whether the cap carries its printed plus — a cap that adds (new or/// join). An empty link card's cap is the cap alone, faint (architect,/// 13 Oct 2026): the plus is the add card's, never the object's.publiclet adds: Boolpublicinit(side: CGFloat? = nil, adds: Bool = true) {self.side = sideself.adds = adds }publicvar body: someView {iflet side {// Steel and a printed plus: nothing moves. Rasterised like a// painted cap, and on the sized path for the same reason. face(side: side).drawingGroup() } else {GeometryReader { geo in face(side: geo.size.width) } .aspectRatio(1, contentMode: .fit) } }privatefunc face(side: CGFloat) -> someView { ZStack {switch theme.cap.texture {case .enamel:CottonMedia.image(CapBoard.emptyAsset)? .resizable() .interpolation(.medium) .scaledToFit() .accessibilityHidden(true)case .flat:Circle().strokeBorder(theme.colors.hairline.color, lineWidth: theme.scale.stroke) }if adds {Image(systemName: Glyph.symbol("plus") ?? "plus") .font(theme.type.interface((side * ProjectCapsKnobs.capEmptyPlusSize), weight: .light)) .foregroundStyle(theme.colors.inkTertiary.color) .blendMode(.multiply) } } .compositingGroup() .frame(width: side, height: side) }}extensionCapBoard {publicstaticlet emptyAsset = "cap-empty"/// The lift off the plaster. One shadow for every cap on the board.publicstaticfunc shadow<V: View>(_ view: V) -> someView { view.modifier(CapBoardShadow()) }}/// `CapBoard.shadow`, in the theme's shadow colour and only when the theme/// casts one.privatestructCapBoardShadow: ViewModifier { @Environment(\.theme) privatevar themefunc body(content: Content) -> someView {if theme.texture.shadow == .none { content } else { content.shadow( color: theme.colors.shadow.color.opacity(Double(ProjectCapsKnobs.capBoardShadowOpacity)), radius: ProjectCapsKnobs.capBoardShadowRadius, x: 0, y: ProjectCapsKnobs.capBoardShadowY ) } }}/// The sizes, counts and timings ProjectCaps draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enumProjectCapsKnobs {staticlet capBoardColumns = 4staticlet capBoardShadowOpacity: CGFloat = 0.22staticlet capBoardShadowRadius: CGFloat = 7staticlet capBoardShadowY: CGFloat = 5staticlet capEmptyPlusSize: CGFloat = 0.2staticlet capEnamelNameSize: CGFloat = 0.205staticlet capEnamelPrintGap: CGFloat = 0.035staticlet capEnamelPrintHeight: CGFloat = 0.56staticlet capEnamelPrintLift: CGFloat = 0.005staticlet capEnamelPrintWidth: CGFloat = 0.6staticlet capEnamelRuleHeight: CGFloat = 0.012staticlet capEnamelRuleHeightMin: CGFloat = 1.2staticlet capEnamelRuleWidth: CGFloat = 0.15staticlet capFlatNameHeight: CGFloat = 0.6staticlet capFlatNameSize: CGFloat = 0.19staticlet capFlatNameWidth: CGFloat = 0.7staticlet capNameLines = 3}