// A record's sleeve while it keeps no art of its own (`TypeSleeve`), and the// sizes the music faces share (`MusicPartsKnobs`): a track's art, an album's// and a playlist's, the record, the play disc and the scrubber (CottonUI's// `MusicParts`) all read them.importCottonPaperimportSwiftUIpublicenumMusicPartsKnobs {/// The record's grooves, as rings between its edge and its label.publicstaticlet grooves = 7publicstaticlet groove: CGFloat = 0.6publicstaticlet label: CGFloat = 0.36publicstaticlet spindle: CGFloat = 0.035/// The scrubber's line, its filled part and its knob.publicstaticlet line: CGFloat = 2publicstaticlet knob: CGFloat = 14publicstaticlet knobDragging: CGFloat = 20/// The scrubber's height: the knob's room, so a finger finds it.publicstaticlet height: CGFloat = 28/// One VoiceOver swipe on the scrubber moves the playhead this far.publicstaticlet step: TimeInterval = 10publicstaticlet clockSize: CGFloat = 12/// A sleeve kept without art, of the slot its art would fill: smaller,/// so it never reads as an empty frame.publicstaticlet sleeveShare: CGFloat = 0.84/// The sleeve's words, of its side: the room round them, the title's/// size and the artist's. Below `sleeveFull` points it sets the title/// alone, larger (`sleeveSmallTitle`); below `sleeveWords`, nothing.publicstaticlet sleevePadding: CGFloat = 0.09publicstaticlet sleeveTitle: CGFloat = 0.13publicstaticlet sleeveArtist: CGFloat = 0.12publicstaticlet sleeveFull: CGFloat = 110publicstaticlet sleeveSmallTitle: CGFloat = 0.2publicstaticlet sleeveWords: CGFloat = 40/// The grooves rippling out of its lower corner: how many, how far the/// widest reaches (of its side), their line and how faint.publicstaticlet sleeveGrooves = 6publicstaticlet sleeveReach: CGFloat = 0.78publicstaticlet sleeveCorner = UnitPoint(x: 0.92, y: 0.94)publicstaticlet sleeveGroove: CGFloat = 0.8publicstaticlet sleeveGrooveOpacity: Double = 0.32publicstaticlet sleeveStamp: Double = 0.94publicstaticlet sleeveShadow: Double = 0.28}/// A record's sleeve while it keeps no art of its own: printed in the ink/// its title chooses on the house paper, grooves rippling faintly out of its/// lower corner, and the title set in the display face at its head with the/// artist by hand under it, in the paper's cream — never a picture that is/// not the record's. Small, it sets the title alone; too small to read, it/// is the sleeve and its grooves.publicstructTypeSleeve: View {let title: String?var artist: String? = nil @Environment(\.theme) privatevar themepublicinit(title: String?, artist: String? = nil) {self.title = titleself.artist = artist }publicvar body: someView {GeometryReader { box inlet side = min(box.size.width, box.size.height)let cream = theme.faceStocks.cream ZStack(alignment: .topLeading) {InkedPaper(ink: CoverInk.of(title, theme: theme), seed: "sleeve-\(title ?? "")")Grooves() .stroke(cream.opacity(MusicPartsKnobs.sleeveGrooveOpacity), lineWidth: MusicPartsKnobs.sleeveGroove)if side >= MusicPartsKnobs.sleeveWords {let full = side >= MusicPartsKnobs.sleeveFull VStack(alignment: .leading, spacing: side * MusicPartsKnobs.sleevePadding / 3) {iflet title {Text(title) .font(CottonFonts.display(side * (full ? MusicPartsKnobs.sleeveTitle : MusicPartsKnobs.sleeveSmallTitle))) .lineLimit(3) .minimumScaleFactor(0.6) }if full, let artist {Text(artist) .font(CottonFonts.hand(side * MusicPartsKnobs.sleeveArtist)) .lineLimit(2) .minimumScaleFactor(0.6) } } .multilineTextAlignment(.leading) .foregroundStyle(cream.opacity(MusicPartsKnobs.sleeveStamp)) .padding(side * MusicPartsKnobs.sleevePadding) } } .frame(width: box.size.width, height: box.size.height, alignment: .topLeading) .clipped() } .compositingGroup() .shadow(color: theme.colors.shadow.color.opacity(MusicPartsKnobs.sleeveShadow), radius: 2.5, x: 1, y: 2) .accessibilityHidden(true) }/// Rings round the sleeve's lower corner, the widest reaching most of/// the way across.privatestructGrooves: Shape {func path(in rect: CGRect) -> Path {let side = min(rect.width, rect.height)let centre = CGPoint(x: rect.minX + rect.width * MusicPartsKnobs.sleeveCorner.x, y: rect.minY + rect.height * MusicPartsKnobs.sleeveCorner.y)var path = Path()for ring in1...MusicPartsKnobs.sleeveGrooves {let radius = side * MusicPartsKnobs.sleeveReach * CGFloat(ring) / CGFloat(MusicPartsKnobs.sleeveGrooves) path.addEllipse(in: CGRect(x: centre.x - radius, y: centre.y - radius, width: radius * 2, height: radius * 2)) }return path } }}