// A project's cap, small, wherever a project is named on paper.//// Home's board draws caps at ~80pt. A todo card, a person's page, a search// result and a project header want the same object at 28, 36, 44 and hero — and// the cap already scales its lettering as a fraction of its side// (`ProjectCaps.swift`), so this is a frame and an accessible name, not a second// design. It exists so nobody writes `ProjectCap(...).frame(width: 32)` in ten// screens and gets ten different answers about what small means.//// A cap chip is never a label with a coloured dot: the whole point of the cap is// that a project is recognised by its enamel before its name is read.importSwiftUIpublicstructCapChip: View { @Environment(\.theme) privatevar theme/// The sizes a cap is worn at away from Home's board.publicenumSize: String, CaseIterable, Sendable {/// Beside a line of type — a todo card's project, a search result.case small/// A row's leading object — a person's page, a project list.case medium/// A screen's own subject — a project page's header.case large/// The side this size is worn at, as `scale` sets it.publicfunc side(in scale: ThemeScale) -> CGFloat {switchself {case .small: returnCapChipKnobs.capChipSmallSidecase .medium: returnCapChipKnobs.capChipMediumSidecase .large: returnCapChipKnobs.capChipLargeSide } } }privatelet name: Stringprivatelet colour: CapColour/// The size the caller named, read off the theme when the chip is drawn;/// `fixedSide` wins when the caller gave points instead.privatelet size: Sizeprivatelet fixedSide: CGFloat?publicinit(name: String, colour: CapColour, size: Size = .medium) {self.name = nameself.colour = colourself.size = sizeself.fixedSide = nil }publicinit(name: String, colour: CapColour, side: CGFloat) {self.name = nameself.colour = colourself.size = .mediumself.fixedSide = side }privatevar side: CGFloat { fixedSide ?? size.side(in: theme.scale) }publicvar body: someView {ProjectCap(name: name, colour: colour) .frame(width: side, height: side) .shadow( color: theme.colors.shadow.color.opacity(Double(CapChipKnobs.capChipShadowOpacity)), radius: CapChipKnobs.capChipShadowRadius, x: 0, y: 1 ) .accessibilityElement() .accessibilityLabel(name) }}/// The sizes, counts and timings CapChip draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enumCapChipKnobs {staticlet capChipLargeSide: CGFloat = 44staticlet capChipMediumSide: CGFloat = 36staticlet capChipShadowOpacity: CGFloat = 0.34staticlet capChipShadowRadius: CGFloat = 1.5staticlet capChipSmallSide: CGFloat = 28}