// A record's tint: chosen once from the paper palette by a stable hash of its// id, so the same record is the same paper on every open and every device. A// tint never carries meaning — not the project, not lateness (rebuild note// 7b95efa4, "Slip tints").importCottonValuesimportSwiftUIpublicenumFaceTint {/// The papers a slip is cut from — the dyes the lists already use, never/// newsprint (a wash, not a sheet) nor buff (the todo index card's cream).publicstaticlet slipDyes: [PaperDye] = [.cream, .sage, .straw, .peach, .pink, .blue]publicstaticfunc dye(for id: String) -> PaperDye { slipDyes[Int(CapColour.fnv1a(id) % UInt64(slipDyes.count))] }publicstaticfunc dye(for id: String, stock: SlipStock?) -> PaperDye {switch stock {case .plain: return .creamcase .rose: returnToolCardTint.rose.papercase .sage: returnToolCardTint.sage.papercasenil: return dye(for: id) } }/// A cap's enamel, from the same hash, over every cap colour.publicstaticfunc cap(for id: String) -> CapColour {CapColour.allCases[Int(CapColour.fnv1a(id) % UInt64(CapColour.allCases.count))] }}/// The titles a link column's target ids read as, gathered by the surface that/// holds the records (a list of todos knows its projects' names). A face asks/// it and writes nothing for an id it does not know.publicstructLinkTitles: Sendable {publicvar byID: [String: String]/// The picture each linked record heads its page with — its slip's photo/// (a person's face) — by id, where it holds one, so a card that names/// the person prints their photo (architect, r8).publicvar pictures: [String: String]publicinit(_ byID: [String: String] = [:], pictures: [String: String] = [:]) {self.byID = byIDself.pictures = pictures }/// These titles and pictures under `newer`'s: the newer reading wins.publicfunc merging(_ newer: LinkTitles) -> LinkTitles {LinkTitles(byID.merging(newer.byID) { _, read in read }, pictures: pictures.merging(newer.pictures) { _, read in read }) }/// The picture `record` of `definition` heads its page with, when it has one.staticfunc picture(of record: TableRecord, in definition: TableDefinition) -> String? {guardlet key = definition.slip.photo, let picture = record[key].text, !picture.isEmpty else { returnnil }return picture }}privatestructLinkTitlesKey: EnvironmentKey {staticlet defaultValue = LinkTitles()}extensionEnvironmentValues {publicvar linkTitles: LinkTitles { get { self[LinkTitlesKey.self] } set { self[LinkTitlesKey.self] = newValue } }}