// The ALBUM as its 12-INCH SLEEVE lying on the music's black tolex// (`FaceGround.tolex`, the dark room's one lamp glowing upper left; the// coordinator's look for Cotton Music, 4 Nov 2026, after the dark-room// pictures `music10-darkroom/albums`, `album-back` and `opened-album`): a// worn card sleeve square-on, bare of the deck's paper. The sleeve's worn// frame with its brass corner lower left, the black blank stock with its// cream double rule, the wordless back with its two cream rules and the// shadow are PAINTED (`Media.xcassets`, imported by// `scripts/import-music-materials.py sleeve`), each laid where the// materials' `layout.json` places it in the 1130 x 1130 sleeve box, scaled by// the drawn width over 1130. The face draws live only what the card decides://// the FRONT is the album's own cover, laid behind the frame's cut-out and// multiplied softly by the stock's grain. An album kept without a cover// shows the blank stock there instead, its title set in a condensed heavy// sans (Barlow Condensed ExtraBold Italic, the dark room's covers' voice)// in up to three balanced lines, a short cream rule under it and the// artist in spaced small capitals under the rule, cream on black.// the BACK, the sleeve turned over by a tap on it (a plain cut, nothing// animated; a tap turns it back): the title and the artist typed at its// head in Courier Prime, then under the first painted rule the year left// and the album's songs and length right, then the track list, a line// each — its number on its disc, its title cut to one line, its length// flush right — a disc's first song after a line saying "Disc 2"; more// than the back holds, the last line says how many more. A tap on a// song's line plays it, the album from there on, where the shell plays// songs (`facePlaysSong`); the sleeve stays as it lies.//// Tagged: the cut-out (`picture`), the blank's or the back's title and// artist (`title`, `subtitle`), the back's year (`when`) and its track list// (`body`). Stepped by a tap beside it, it cuts. Print on an object scales// with the object, never with Dynamic Type.//// The songs are the card's entries (`songs`, as the cassette reads them:// each its title, its length in seconds and, on an album of several discs,// its `disc`), in the album's order; every word is the core's (`DeckCard`)// or a line: the face only sets them.importCottonPaperimportCottonValuesimportCoreTextimportSwiftUIenumAlbumSleeveFaceKnobs {// THE SLEEVE BOX every placement is in, in the paintings' pixels// (`layout.json` `sleeve.box`): the face draws the sleeve at most// `widest` points wide (its `phoneBox`), and every place below is scaled// by the drawn width over the box's.staticlet box: CGFloat = 1130staticlet widest: CGFloat = 300/// The most of the card's room the sleeve takes, of its width and height.staticlet fill: CGFloat = 0.92staticlet shadow = CGRect(x: -80, y: -80, width: 1290, height: 1290)// THE FRONT: the frame's cut-out (`coverRect`), where the blank stock is// laid, and how far a cover runs under the frame's rim.staticlet cover = CGRect(x: 82, y: 84, width: 964, height: 964)staticlet coverBleed: CGFloat = 3/// The stock's grain laid over a cover: the blank stock's middle, clear/// of its double rule (as shares of it), screened over the cover so its/// weave marks it without darkening it, and how strongly.staticlet grain = CGRect(x: 0.15, y: 0.15, width: 0.7, height: 0.7)staticlet grainStrength: Double = 0.5/// The blank's words: the room they take inside its double rule (the/// stock's inner rule runs at 149 and 978 of the box), the title's size/// and the least it is taken down to, the step from one baseline to the/// next as a share of its size, the most lines it takes and the step its/// size is taken down by until it fits them.staticlet words = CGRect(x: 190, y: 190, width: 740, height: 740)staticlet titleSize: CGFloat = 200staticlet titleLeast: CGFloat = 84staticlet titleStep: CGFloat = 0.92staticlet titleLines = 3staticlet titleShrink: CGFloat = 0.94/// The short rule under the title: the gap above it, its length, and the/// painted rule it is cut from (the back's upper rule, from its left/// end, in the back's pixels).staticlet ruleGap: CGFloat = 44staticlet rule = CGSize(width: 260, height: 9)staticlet ruleFrom = CGPoint(x: 81, y: 351)/// The artist under the rule: the gap, its size, its tracking (a share/// of its size) and the room its line takes (a share of its size).staticlet artistGap: CGFloat = 30staticlet artistSize: CGFloat = 52staticlet artistTracking: CGFloat = 0.22staticlet artistLine: CGFloat = 1.3// THE BACK (`sleeve-back`): the column its words are typed in (the// materials' `backTextRect`'s), the head above the upper rule// (painted at 355) and its sizes, the facts under the rule, the track// list's first line, the step from line to line, how many lines it// holds above the lower rule (painted at 901) and its columns.staticlet column = CGRect(x: 110, y: 100, width: 900, height: 830)staticlet head = CGRect(x: 110, y: 110, width: 900, height: 218)staticlet backTitleSize: CGFloat = 68staticlet backArtistSize: CGFloat = 46staticlet headGap: CGFloat = 10staticlet facts = CGRect(x: 110, y: 380, width: 900, height: 52)staticlet factsSize: CGFloat = 34staticlet tracksTop: CGFloat = 462staticlet trackStep: CGFloat = 47staticlet trackSize: CGFloat = 36staticlet trackLines = 9staticlet numberColumn: CGFloat = 90staticlet lengthColumn: CGFloat = 150}/// One line of the back's track list.publicenumAlbumSleeveLine: Equatable, Sendable {/// A song: its number on its disc, its title, its length in seconds, its record.case song(number: Int, title: String?, seconds: TimeInterval, record: String? = nil)/// The line before a disc's first song, on an album of several.case disc(Int)/// The songs the back does not type.case more(Int)}/// How the sleeve is set.publicenumAlbumSleeveSetting {/// The back's track list: every song, a line each, numbered on its disc;/// before each disc after the first, a line naming it; more lines than/// the back holds, as many as it holds less one — never ending on a/// disc's name — and a last line saying how many songs it left out.publicstaticfunc lines(_ card: DeckCard) -> [AlbumSleeveLine] {var all: [AlbumSleeveLine] = []var disc: Int?var number = 0for entry in card.entries("songs") {let on = Int(entry["disc"]?.number ?? 1)iflet disc, on != disc { all.append(.disc(on)) number = 0 } disc = on number += 1 all.append(.song(number: number, title: entry["title"]?.text, seconds: max(0, entry["duration"]?.number ?? 0), record: entry["record"]?.text)) }let room = AlbumSleeveFaceKnobs.trackLinesguard all.count > room else { return all }var shown = Array(all.prefix(room - 1))whilecase .disc? = shown.last { shown.removeLast() }let typed = shown.filter { ifcase .song = $0 { true } else { false } }.countlet songs = all.filter { ifcase .song = $0 { true } else { false } }.countreturn shown + [.more(songs - typed)] }/// A line's words: the disc's name, or how many more.publicstaticfunc said(_ line: AlbumSleeveLine) -> String? {switch line {case .song: nilcase .disc(let disc): ShellLines.line("cards", "sleeve.disc", ["n": disc.formatted()])case .more(let more): ShellLines.line("cards", "sleeve.more", ["n": more.formatted()]) } }/// A song's number on its disc, two figures as a sleeve prints it.publicstaticfunc number(_ number: Int) -> String { number.formatted(.number.precision(.integerLength(2...)).grouping(.never)) }/// The album's songs and its length, as the cards join words; nil, none/// known.publicstaticfunc whole(_ card: DeckCard) -> String? {MusicWhole.joined([card.text("count"), card.text("length")]) }/// The blank's title in the sleeve's sans, in capitals: its lines and the/// size they are set at — the sleeve's own size until the title takes/// more lines than it has or more room than the rule and the artist/// leave it, then taken down a step at a time until it fits, and past/// the least size cut with an ellipsis — the lines balanced. In the/// sleeve box's pixels.publicstaticfunc title(_ card: DeckCard) -> (lines: [String], size: CGFloat) {let knobs = AlbumSleeveFaceKnobs.selfvar size = knobs.titleSizeguardlet title = card.text("title")?.split(whereSeparator: \.isWhitespace).joined(separator: " ").uppercased() else {return ([], size) }let room = knobs.words.height - knobs.ruleGap - knobs.rule.height - knobs.artistGap - knobs.artistSize * knobs.artistLine// Every word whole: a word wider than the box shrinks the title// before it would be broken mid-word ("HARBOU / R TEST", the Music// gaps walk, 5 Nov 2026); only past the least size is one broken.let words = title.split(separator: " ").map(String.init)func fits(_ size: CGFloat) -> Bool {let font = sans(size)guard words.allSatisfy({ HighlightPassageSetting.wide($0, font) <= knobs.words.width }) else { returnfalse }let lines = HighlightPassageSetting.lines(title, font: font, width: knobs.words.width, limit: .max)return lines.count <= knobs.titleLines && CGFloat(lines.count) * size * knobs.titleStep <= room }while !fits(size), size * knobs.titleShrink >= knobs.titleLeast { size *= knobs.titleShrink }return (BookHardbackSetting.balanced(title, font: sans(size), width: knobs.words.width, limit: knobs.titleLines), size) }/// The sleeve's sans at `size`, as CoreText measures it.staticfunc sans(_ size: CGFloat) -> CTFont { _ = CottonFonts.sleeve(1)return CTFontCreateWithName(CottonFonts.sleeveFace as CFString, max(1, size), nil) }}/// A painted layer, by its catalogue name, at the scale it was painted for;/// nothing where this build carries no pictures.privatestructSleevePainted: View {let name: Stringvar body: someView {iflet image = CottonMedia.image(name, scale: 3) { image.resizable().interpolation(.high).accessibilityHidden(true) } }}privateextensionView {/// This view laid at `rect` of the sleeve box, in its pixels, scaled by `s`.func laid(_ rect: CGRect, _ s: CGFloat, alignment: Alignment = .center) -> someView { frame(width: rect.width * s, height: rect.height * s, alignment: alignment) .offset(x: rect.minX * s, y: rect.minY * s) }/// This view moved to `rect`'s corner of the sleeve box: last, after a/// part is tagged (`facePart`), so the region the deck reads for it is/// where it is drawn.func at(_ rect: CGRect, _ s: CGFloat) -> someView { offset(x: rect.minX * s, y: rect.minY * s) }}publicstructAlbumSleeveFace<Cover: View>: View {let card: DeckCard/// The cover laid behind the frame's cut-out; nil lays the blank stock.var cover: Cover?/// The side the card lies on (a specimen reviewed turned over). @Environment(\.faceTurnedOver) privatevar lies/// Turned over by a tap since the card came. @State privatevar turned = falsepublicinit(card: DeckCard, cover: Cover? = nil) {self.card = cardself.cover = cover }publicvar body: someView {let knobs = AlbumSleeveFaceKnobs.selfGeometryReader { room inlet side = min(knobs.widest, room.size.width * knobs.fill, room.size.height * knobs.fill)let s = side / knobs.boxGroup {if lies != turned {SleeveBack(card: card, s: s) } else {SleeveFront(card: card, cover: cover, s: s) } } .frame(width: side, height: side, alignment: .topLeading) .contentShape(Rectangle()) .onTapGesture { turned.toggle() } .accessibilityAction(named: ShellLines.line("cards", "sleeve.turn")) { turned.toggle() } .offset(x: (room.size.width - side) / 2, y: (room.size.height - side) / 2) .frame(width: room.size.width, height: room.size.height, alignment: .topLeading) } .onChange(of: card.record) { turned = false } .accessibilityElement(children: .contain) .accessibilityIdentifier("album-sleeve") }}/// The sleeve's front in its box, scaled by `s`: its shadow, the cover or/// the blank stock, the frame, and the blank's words.privatestructSleeveFront<Cover: View>: View {let card: DeckCardlet cover: Cover?let s: CGFloatvar body: someView {let knobs = AlbumSleeveFaceKnobs.self ZStack(alignment: .topLeading) {SleevePainted(name: "sleeve-shadow").laid(knobs.shadow, s)iflet cover {SleeveCover(cover: cover, s: s) } else {SleevePainted(name: "sleeve-blank").laid(knobs.cover, s) }SleevePainted(name: "sleeve-front").laid(CGRect(x: 0, y: 0, width: knobs.box, height: knobs.box), s)CoverPart(card: card, covered: cover != nil, s: s)if cover == nil { BlankWords(card: card, s: s) } } .frame(width: knobs.box * s, height: knobs.box * s, alignment: .topLeading) }}/// The cover in the cut-out, a hair past it so it runs under the frame's/// rim, multiplied softly by the stock's grain.privatestructSleeveCover<Cover: View>: View {let cover: Coverlet s: CGFloatvar body: someView {let knobs = AlbumSleeveFaceKnobs.selflet rect = knobs.cover.insetBy(dx: -knobs.coverBleed, dy: -knobs.coverBleed)let size = CGSize(width: rect.width * s, height: rect.height * s) ZStack(alignment: .topLeading) { cover .frame(width: size.width, height: size.height) .clipped()// The stock's grain: the blank's middle, clear of its rule,// lifted pale and stretched over the cover.SleevePainted(name: "sleeve-blank") .frame(width: size.width / knobs.grain.width, height: size.height / knobs.grain.height) .offset(x: -knobs.grain.minX * size.width / knobs.grain.width, y: -knobs.grain.minY * size.height / knobs.grain.height) .frame(width: size.width, height: size.height, alignment: .topLeading) .clipped() .blendMode(.screen) .opacity(knobs.grainStrength) } .frame(width: size.width, height: size.height, alignment: .topLeading) .compositingGroup() .accessibilityHidden(true) .offset(x: rect.minX * s, y: rect.minY * s) }}/// The cut-out as the card's part: the cover (tagged where it is drawn, the/// album's name read for it), or the blank stock under its title and artist.privatestructCoverPart: View {let card: DeckCardlet covered: Boollet s: CGFloatvar body: someView {let knobs = AlbumSleeveFaceKnobs.selfColor.clear .contentShape(Rectangle()) .frame(width: knobs.cover.width * s, height: knobs.cover.height * s) .accessibilityElement() .accessibilityLabel(covered ? MusicWhole.joined([card.text("title"), card.text("subtitle")]) ?? "" : "") .accessibilityAddTraits(covered ? .isHeader : []) .accessibilityIdentifier(covered ? "deck-title" : "sleeve-blank") .accessibilityHidden(!covered) .facePart(.picture) .at(knobs.cover, s) }}/// The blank's words: the title in the sleeve's sans, balanced, a short/// painted rule under it, and the artist in spaced small capitals.privatestructBlankWords: View {let card: DeckCardlet s: CGFloatvar body: someView {let knobs = AlbumSleeveFaceKnobs.selflet (lines, size) = AlbumSleeveSetting.title(card) VStack(alignment: .leading, spacing: 0) {if !lines.isEmpty { VStack(alignment: .leading, spacing: 0) {ForEach(Array(lines.enumerated()), id: \.offset) { _, line inText(line) .font(CottonFonts.sleeve(size * s)) .lineLimit(1) .fixedSize() .frame(height: size * knobs.titleStep * s, alignment: .leading) } } .contentShape(Rectangle()) .accessibilityElement() .accessibilityLabel(card.text("title") ?? "") .accessibilityAddTraits(.isHeader) .accessibilityIdentifier("deck-title") .facePart(.title) }iflet artist = card.text("subtitle") {// The rule: the back's own painted rule, cut short.SleevePainted(name: "sleeve-back") .frame(width: knobs.box * s, height: knobs.box * s) .offset(x: -knobs.ruleFrom.x * s, y: -knobs.ruleFrom.y * s) .frame(width: knobs.rule.width * s, height: knobs.rule.height * s, alignment: .topLeading) .clipped() .padding(.top, (lines.isEmpty ? 0 : knobs.ruleGap) * s)Text(artist.uppercased()) .font(CottonFonts.sleeve(knobs.artistSize * s)) .tracking(knobs.artistSize * knobs.artistTracking * s) .lineLimit(1) .minimumScaleFactor(0.5) .frame(maxWidth: knobs.words.width * s, alignment: .leading) .frame(height: knobs.artistSize * knobs.artistLine * s, alignment: .leading) .contentShape(Rectangle()) .accessibilityLabel(artist) .accessibilityIdentifier("sleeve-artist") .facePart(.subtitle) .padding(.top, knobs.artistGap * s) } } .foregroundStyle(MusicMaterial.engraving.colour) .frame(width: knobs.words.width * s, height: knobs.words.height * s, alignment: .topLeading) .at(knobs.words, s) }}/// The sleeve turned over, in its box: its shadow, the painted back, and/// what is typed on it.privatestructSleeveBack: View {let card: DeckCardlet s: CGFloatvar body: someView {let knobs = AlbumSleeveFaceKnobs.self ZStack(alignment: .topLeading) {SleevePainted(name: "sleeve-shadow").laid(knobs.shadow, s)SleevePainted(name: "sleeve-back").laid(CGRect(x: 0, y: 0, width: knobs.box, height: knobs.box), s) head facts tracks } .foregroundStyle(MusicMaterial.engraving.colour) .frame(width: knobs.box * s, height: knobs.box * s, alignment: .topLeading) }/// The title and the artist typed above the upper rule.privatevar head: someView {let knobs = AlbumSleeveFaceKnobs.selfreturn VStack(alignment: .leading, spacing: knobs.headGap * s) {iflet title = card.text("title") {Text(title) .font(CottonFonts.type(knobs.backTitleSize * s)) .lineLimit(2) .minimumScaleFactor(0.6) .accessibilityAddTraits(.isHeader) .accessibilityIdentifier("deck-title") .facePart(.title) }iflet artist = card.text("subtitle") {Text(artist) .font(CottonFonts.type(knobs.backArtistSize * s)) .lineLimit(1) .minimumScaleFactor(0.6) .accessibilityIdentifier("sleeve-artist") .facePart(.subtitle) } } .frame(width: knobs.head.width * s, height: knobs.head.height * s, alignment: .bottomLeading) .at(knobs.head, s) }/// The year left, the songs and length right, under the upper rule.privatevar facts: someView {let knobs = AlbumSleeveFaceKnobs.selfreturn HStack(spacing: 0) {iflet year = card.text("year") {Text(year) .lineLimit(1) .accessibilityIdentifier("sleeve-year") .facePart(.when) }Spacer(minLength: knobs.factsSize * s)iflet whole = AlbumSleeveSetting.whole(card) {Text(whole) .lineLimit(1) .minimumScaleFactor(0.6) .accessibilityIdentifier("sleeve-whole") } } .font(CottonFonts.type(knobs.factsSize * s)) .monospacedDigit() .frame(width: knobs.facts.width * s, height: knobs.facts.height * s) .at(knobs.facts, s) }/// The track list, a line each, above the lower rule. @ViewBuilder privatevar tracks: someView {let knobs = AlbumSleeveFaceKnobs.selflet lines = AlbumSleeveSetting.lines(card)if !lines.isEmpty { VStack(alignment: .leading, spacing: 0) {ForEach(Array(lines.enumerated()), id: \.offset) { _, line inTrackLine(line: line, s: s) .frame(height: knobs.trackStep * s) } } .font(CottonFonts.type(knobs.trackSize * s)) .monospacedDigit() .frame(width: knobs.column.width * s, alignment: .topLeading) .contentShape(Rectangle()) .accessibilityElement(children: .contain) .accessibilityIdentifier("sleeve-tracks") .facePart(.body) .offset(x: knobs.column.minX * s, y: knobs.tracksTop * s) } }}/// One line of the track list: a song's number, title cut to one line and/// length flush right; a disc's name; how many more.privatestructTrackLine: View {let line: AlbumSleeveLinelet s: CGFloat @Environment(\.facePlaysSong) privatevar playsvar body: someView {ifcase .song(_, _, _, let record?) = line, let plays { words .contentShape(Rectangle()) .onTapGesture { plays(record) }// The tap map's play part: its tap plays, and never opens the album. .facePart(.play) .accessibilityElement(children: .combine) .accessibilityAddTraits(.isButton) .accessibilityIdentifier("sleeve-song") } else { words.accessibilityElement(children: .combine) } }privatevar words: someView {let knobs = AlbumSleeveFaceKnobs.selfreturn HStack(spacing: 0) {switch line {case .song(let number, let title, let seconds, _):Text(AlbumSleeveSetting.number(number)) .frame(width: knobs.numberColumn * s, alignment: .leading)Text(title ?? "") .lineLimit(1) .truncationMode(.tail) .frame(maxWidth: .infinity, alignment: .leading)Text(TrackClock.said(seconds)) .frame(width: knobs.lengthColumn * s, alignment: .trailing)case .disc, .more:Text(AlbumSleeveSetting.said(line) ?? "") .lineLimit(1) .frame(maxWidth: .infinity, alignment: .leading) } } }}/// The album's sleeve, by its id beside the album's other faces, and the/// albums it is reviewed in: invented albums by invented artists, an/// invented cover.publicenumAlbumSleeveFaceCatalogue {publicstaticlet stock: FaceStock = .ownpublicstaticlet ground: FaceGround = .tolexpublicstaticlet face = Face(id: "album.sleeve", specimens: [Specimen("cover", ferry, picture: "cover-night-ferry"), Specimen("no-cover", common),Specimen("back", ferry, picture: "cover-night-ferry", turned: true), Specimen("back-two-discs", moons, turned: true),Specimen("largest", largest), ], steps: .cut) { card, picture, _ inAlbumSleeveFace(card: card, cover: picture) }staticfunc album(_ fields: [String: RecordValue], songs: [(String, TimeInterval, Int)]) -> DeckCard {var fields = fields fields["songs"] = .list(songs.map { title, seconds, disc in .object(["title": .text(title), "duration": .number(seconds), "disc": .number(Double(disc))]) })returnDeckCard(face: "album.sleeve", corner: nil, pressing: false, pace: nil, plate: nil, fields: fields) }/// Nine songs on one disc, its cover kept.publicstaticlet ferry = album(["title": .text("Night Ferry"),"subtitle": .text("The Low Tide"),"photo": .text("cover-night-ferry"),"year": .text("2024"),"count": .text("9 songs"),"length": .text("38:46"), ], songs: [ ("Harbour Lights", 242, 1), ("Slow Train", 218, 1), ("Blue Hour", 310, 1), ("Lantern Street", 251, 1), ("Salt and Iron", 199, 1), ("The Last Crossing", 287, 1), ("Fog Bell", 236, 1), ("Paper Moons", 264, 1), ("Night Ferry", 319, 1), ])/// No cover kept: the blank stock with its title and artist set.publicstaticlet common = album(["title": .text("Common Ground"),"subtitle": .text("Mara Vance"),"year": .text("2019"),"count": .text("4 songs"),"length": .text("16:20"), ], songs: [("Common Ground", 241, 1), ("Slow Train", 263, 1), ("Blue Hour", 228, 1), ("Harbour Lights", 248, 1)])/// Two discs, more songs than the back holds and a title too long for/// its line, no cover.publicstaticlet moons = album(["title": .text("Paper Moons"),"subtitle": .text("Sixteen Lanterns"),"year": .text("2021"),"count": .text("14 songs"),"length": .text("1:02:18"), ], songs: [ ("Paper Moons", 245, 1), ("Blue Hour", 271, 1), ("Slow Train Home Through the Sixteen Lanterns", 402, 1), ("Harbour Lights", 233, 1), ("Lantern Street", 260, 1), ("Night Ferry", 284, 2), ("Common Ground", 219, 2), ("Fog Bell", 301, 2), ("Salt and Iron", 246, 2), ("The Last Crossing", 288, 2), ("Paper Moons, Reprise", 132, 2), ("Low Tide", 255, 2), ("Mara's Song", 212, 2), ("Blue Hour, Live", 342, 2), ])/// The fullest card: a title that takes the blank's three lines and is/// cut, a long artist, drawn at every text size Loom has, the largest/// among them.publicstaticlet largest = album(["title": .text("The Harbour Lights Sessions, Recorded Live Across Sixteen Lanterns and the Blue Hour Ferry Crossings"),"subtitle": .text("Mara Vance and The Low Tide Orchestra"),"year": .text("2026"),"count": .text("2 songs"),"length": .text("9:02"), ], songs: [("Harbour Lights", 242, 1), ("Slow Train", 300, 1)])}