// Where the page meets Home's fan. The page area runs to the record// button's band and its scroll on under the band to the foot of the screen,// with ONE bottom inset — the band's — whether the fan stands or folds; the// standing fan lies over the page's foot and its rows run under it (291 rows// C and F; architect's ruling 01:30 IST 17 Oct 2026). Folding the fan into// the circle is a scale and an opacity on the arcs and the record button,// never a change of the page's frame or inset: a fold that moved the inset in// its spring laid the list out again in every frame of a fling. The fan's// room in every state is `FanRoom` (`FanEdgeTests`).importCottonFacesimportCottonWritingimportSwiftUI/// The room the fan takes at the foot of Home: the tiles' arc and, under it,/// the caps' arc, over the record button's band (`page`) — the same numbers/// the fan's own frames are laid out from. Where the standing fan covers the/// page, never the page's inset.enumFanRoom {/// The gap the board's foot column keeps over the record button, under/// the receipt's slot — there with no receipt shown, so the button/// stands this far under the fan's foot.staticlet recordGap: CGFloat = 8/// The tiles' frame: none while the fan is put away under the thought/// field or the keyboard. Collapsed, the arcs keep their frame — they/// shrink into the circle as drawn, not as laid out.staticfunc deck(height: Double, tucked: Bool, keyboardUp: Bool) -> Double { putAway(tucked: tucked, keyboardUp: keyboardUp) ? 0 : height }/// The fan is put away — under Home's thought field, a page's own/// composer, or the keyboard: no tiles, no caps, and the page's scroll/// leaves its collapse as it was.staticfunc putAway(tucked: Bool, keyboardUp: Bool) -> Bool { tucked || keyboardUp }/// The caps' room: their own while the tiles stand, none once the tiles/// are put away — they go with them.staticfunc caps(natural: Double, deck: Double, height: Double) -> Double { deck == height ? natural : 0 }/// The fan is folded into the circle and not put away: the arcs are/// drawn shrunk into the circle and faded, standing where they stood.staticfunc folded(collapsed: Bool, tucked: Bool, keyboardUp: Bool) -> Bool { collapsed && !tucked && !keyboardUp }/// Where the bloomed fan covers the page, in the window — the page/// area's foot, the fan's top — and nil while the fan is folded or put/// away: under the folded band rows read as they are, so VoiceOver's/// swipe to the next row scrolls it in (architect's rulings 14:50 and/// 21:15 IST 16 Oct 2026).staticfunc cover(collapsed: Bool, tucked: Bool, keyboardUp: Bool, areaFoot: Double?) -> Double? { collapsed || putAway(tucked: tucked, keyboardUp: keyboardUp) ? nil : areaFoot }/// Where the standing fan's top lies in the window (`FanCover.standingEdge`):/// the page area's foot, as measured while the fan was out, less the/// standing fan's room. It reads no fold, tuck or keyboard: the fan/// hovers over the page, and the card under it never moves.staticfunc standingEdge(areaFoot: Double?, standingRoom: Double) -> Double? { areaFoot.map { $0 - standingRoom } }/// The fan's room over the band: the ring of views over the tiles, the/// tiles and the caps, none while the fan is put away. Folded or not it/// is the same — a fold lays nothing out. The ring's band is room on every/// tile, whether or not its tool has a ring yet, so the page's picture/// region never changes as the fan turns.staticfunc page(height: Double, caps natural: Double, tucked: Bool, keyboardUp: Bool) -> Double {let deck = deck(height: height, tucked: tucked, keyboardUp: keyboardUp)return deck + caps(natural: natural, deck: deck, height: height) }}/// A tile's page as the fan shows it, live or painted (`FanHome.framed`), in/// a page area that runs to the band. A concrete view, so the/// fan's page passes through no `AnyView` of its own (NavigationSweepTests).structFramedPage: View {let page: AnyView/// The bloomed fan's cover (`FanCover`).var cover: FanCover?/// The views the ring over the fan chose (`ToolViews`).var views: ToolViews?var tiers: FanTiers?/// Only the live page lays the shell ground; offscreen painters never do.var laysGround = false/// UIKit stacks report inside their hosting controller.var hosted = falsevar arrival: FanPageArrival?var body: someView { page.modifier(FanGroundReport(enabled: !hosted)) .environment(\.fanPageArrival, arrival) .environment(\.fanCover, cover) .environment(\.fanLaysGround, laysGround) .environment(views) .environment(tiers) }}/// Preferences do not cross a UIHostingController. Read the page's ground/// inside its host, then hand it to the shell through the shared environment.structFanGroundReport: ViewModifier {var enabled = true @Environment(\.fanCover) privatevar cover @Environment(\.fanLaysGround) privatevar laysGround @Environment(\.fanPageArrival) privatevar arrivalfunc body(content: Content) -> someView { content .backgroundPreferenceValue(DeckGroundPreference.self) { reading inColor.clear.preference(key: FanPageReadingPreference.self, value: FanPageReading(ground: reading)) } .overlayPreferenceValue(FanPageReadingPreference.self) { report inColor.clear.task(id: FanPageReport(reading: report, arrival: arrival?.id, active: enabled && laysGround)) {guard enabled && laysGround else { return }awaitTask.yield()guard !Task.isCancelled else { return }iflet arrival { arrival.report(report) }elseif laysGround { cover?.lay(report.ground) } }.allowsHitTesting(false) } }}/// Where the bloomed fan covers the page, in the window (`FanRoom.cover`):/// one box per fan, handed to its pages once. A fold changes only `edge`,/// which only the rows' own `UnreadUnderTheFan` read — never the page's/// environment, whose change drew every page of the card's stack again in/// the fold's first frame (291 row F).@MainActor @ObservablefinalclassFanCover {/// Before any page reports, the app's own ground (`FaceGround.app`), so/// the first frame after the splash stands on what the splash did.var ground: FaceGround? = FaceGround.app/// The colour a page on the plain ground (`FaceGround.blank`) draws its/// own theme on (Notes' look, from the core), laid through the status/// bar and under the home indicator so the page meets the window's edges/// in one colour; nil, the plain ground's own (`deckPlainGround`).var plainGround: Color?/// A new deck has not read its first card yet: keep the leaving ground./// A known nil is paper, including an empty deck and a non-deck page.func lay(_ reading: DeckGroundReading) {switch reading {case .pending: breakcase .known(let ground): self.ground = groundcase .unspecified: ground = nil } }/// Stable room above the record band; folding never relays the page.var scrollClearance: Double = 0/// Where the bloomed fan covers the page now (`FanRoom.cover`), nil while/// it is folded or put away: what a row reads to leave the accessibility/// tree under the fan. Never a page's layout: the fan hovers.var edge: Double?/// Where the standing fan's top lies in the window, whatever the fan is/// doing now — open, closed into the hub, tucked or under the keyboard/// (`FanRoom.standingEdge`): the foot a deck stands its card above. The/// fan hovers over the page, so opening or closing it moves neither/// this nor the card by a point (owner, 12 Nov 2026).var standingEdge: Double?/// The keyboard is up and the fan put away under it (`FanHome`).var keyboardUp = false}extensionEnvironmentValues {/// The fan's cover; nil off the fan. @Entry var fanCover: FanCover? = nil @Entry var fanLaysGround = false}/// A row under the bloomed fan is covered — a tap there lands on the fan —/// so it is neither announced nor tappable: it leaves the accessibility tree/// (walker pass 4 row 3; walker on 289; architect's ruling 21:15 IST 16 Oct/// 2026, form (i)). The fan's state decides: folded or put away there is no/// cover and every row reads as it is. The test is the row's middle against/// the cover, read only when it flips, so a scroll redraws no row. One chain/// whether a cover stands or not: a branch on it gave every row on the page/// a new identity at each fold and bloom, and built them all again mid-fling/// (291 row F).structUnreadUnderTheFan: ViewModifier { @Environment(\.fanCover) privatevar cover @State privatevar under = falsestaticfunc covered(midY: Double, cover: Double?) -> Bool {guardlet cover else { returnfalse }return midY > cover }func body(content: Content) -> someView {let edge = cover?.edge content .onGeometryChange(for: Bool.self, of: { Self.covered(midY: Double($0.frame(in: .global).midY), cover: edge) }) { under = $0 } .accessibilityHidden(edge != nil && under) }}/// The fan's clip: its own frame, and while `hangs` the fan's own height/// again below its foot — the outer caps lean down beside the record button/// whole; only a fan sliding away is cut at its foot.structFanFootClip: Shape {var hangs: Boolfunc path(in rect: CGRect) -> Path {Path(hangs ? rect.union(rect.offsetBy(dx: 0, dy: rect.height)) : rect) }}/// The first page frame is ready only after both its list and its card fill.structFanPageReading: Equatable, Sendable {var ground: DeckGroundReading = .unspecifiedvar filled = truevar ready: Bool { ground != .pending && filled }}structFanPageReadingPreference: PreferenceKey {staticlet defaultValue = FanPageReading()staticfunc reduce(value: inoutFanPageReading, nextValue: () -> FanPageReading) {let next = nextValue()if next.ground != .unspecified { value.ground = next.ground } value.filled = value.filled && next.filled }}/// A report belongs to the mounted page, including its request generation.privatestructFanPageReport: Equatable {let reading: FanPageReadinglet arrival: String?let active: Bool}structFanPageArrival {let id: Stringlet report: @MainActor (FanPageReading) -> Void}extensionEnvironmentValues { @Entry var fanPageArrival: FanPageArrival? = nil}#if os(iOS)import UIKit/// A tapped destination is mounted under the leaving frame. The fan starts/// only when its first card and ground are ready, then one fade reveals it.@MainActor @ObservablefinalclassFanPageTurn {private(set) var key: String?private(set) var generation = 0private(set) var ready = falseprivate(set) var snapshot: UIView?private(set) var opacity = 1.0 @ObservationIgnored privatevar start: ((DeckGroundReading) -> Void)? @ObservationIgnored privatevar duration = 0.0 @ObservationIgnored privatevar faded = false @ObservationIgnored privatevar settled = falsefunc prepare(key: String, snapshot: UIView, duration: Double, start: @escaping (DeckGroundReading) -> Void) { generation += 1self.key = keyself.snapshot = snapshotself.duration = durationself.start = start ready = false faded = false settled = false opacity = 1 }func report(_ reading: FanPageReading, key: String, generation: Int) {guardself.key == key, self.generation == generation, !ready, reading.ready else { return } ready = truelet start = startself.start = nil start?(reading.ground) withAnimation(.easeInOut(duration: duration)) { opacity = 0 } completion: { [weakself] inguardletself, self.generation == generation else { return }self.faded = trueself.finish() } }func didSettle(on key: String) {guardself.key == key, ready else { return } settled = true finish() }privatefunc finish() {guard faded && settled else { return } key = nil snapshot = nil }func cancel() { generation += 1 key = nil snapshot = nil start = nil ready = false }}#endif/// Selecting another tool leaves both page pictures valid. Only a change/// of path on the same tool makes its old picture stale.structFanPageStand: Equatable {var key = ""var path = ""staticfunc changedPage(from old: Self, to new: Self) -> String? { old.key == new.key && old.path != new.path ? new.key : nil }}extensionView {/// Names the colour this page draws its plain ground in (a theme's/// `#RRGGBB`), for the shell to lay outside the page's host/// (`FanCover.plainGround`), while it shows.func deckPlainGround(_ hex: String?) -> someView { modifier(DeckPlainGround(hex: hex)) }}privatestructDeckPlainGround: ViewModifier {let hex: String? @Environment(\.fanCover) privatevar coverfunc body(content: Content) -> someView {// `WritingTheme.ui` is UIKit's; a macOS host build (the UI-tests stub) draws no theme ground. #if canImport(UIKit) content .onChange(of: hex, initial: true) { _, now in cover?.plainGround = now.map { Color(uiColor: WritingTheme.ui($0)) } } .onDisappear { cover?.plainGround = nil } #else content #endif }}