Cotton code
563 lines · 26.9 KB · SwiftRaw
// COTTON SITES' LOOK (assets/design/sites/DECISIONS.md "The look", sites.html palette B): Rose by day, Night by dark,// Cranberry the accent, Instrument Sans throughout. Thin 1 pt rules and space; no cards, shadows or gradients. The// accent goes only on the thread, a sheet's main button, "Here" in the switcher and the caret; rows, marks and// switches are ink. Every Sites screen draws from this file, and every value here is sites.html's `:root` or one of// its rules, by name. The colours are the core's `look {app: sites}` as the person's Look stands (`LookModel`).#if os(iOS)import CoreTextimport CottonWritingimport SwiftUIimport UIKit/// sites.html's `:root`, as Look stands: the chosen paper's half for the phone's appearance, in the chosen ink.@MainActorenum Cranberry {    private static var look: LookModel { LookModel.standing("sites") }    /// `--ground`: every Sites screen is drawn on it.    static var ground: Color { look.colour("ground", 0xF5F1F1) }    static var ink: Color { look.colour("ink", 0x221A1C) }    static var quiet: Color { look.colour("quiet", 0x65595C) }    static var faint: Color { look.colour("faint", 0x9A8E91) }    static var rule: Color { look.colour("rule", 0xDDD3D5) }    /// `--acc`: the thread, a sheet's main button, "Here", the caret. Nowhere else.    static var accent: Color { look.colour("accent", 0x9A2C4C) }    static var onAccent: Color { look.colour("on_accent", 0xFFFFFF) }    /// `--veil`: behind a sheet raised over a page.    static var veil: Color { ink.opacity(look.groundIsLight ? 0.30 : 0.55) }    /// Whether the standing paper is light (keyboards, the status bar).    static var light: Bool { look.groundIsLight }    /// `.ph` padding: the screen's side margin.    static let side: CGFloat = 22    /// A button's and a round's outline (`1.5px solid`).    static let stroke: CGFloat = 1.5}/// Instrument Sans (SIL OFL, `assets/fonts/look`), one variable file, registered once for the process.enum SitesFonts {    static let upright: String? = register("InstrumentSans")    static let italic: String? = register("InstrumentSans-Italic")    private static func register(_ file: String) -> String? {        guard let url = Bundle.main.url(forResource: file, withExtension: "ttf", subdirectory: "look") else { return nil }        CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil)        let descriptors = CTFontManagerCreateFontDescriptorsFromURL(url as CFURL) as? [CTFontDescriptor] ?? []        return descriptors.first.flatMap { CTFontDescriptorCopyAttribute($0, kCTFontNameAttribute) as? String }    }    /// Instrument Sans at `size` and `weight`, scaled with the phone's text size.    static func font(_ size: CGFloat, _ weight: UIFont.Weight, style: UIFont.TextStyle) -> UIFont {        let wght: Double = switch weight {        case .medium: 500        case .semibold: 600        case .bold, .heavy, .black: 700        default: 400        }        let base: UIFont        if let name = upright {            let variation = UIFontDescriptor.AttributeName(rawValue: kCTFontVariationAttribute as String)            base = UIFont(descriptor: UIFontDescriptor(name: name, size: size).addingAttributes([variation: [0x7767_6874: wght]]), size: size)        } else {            base = .systemFont(ofSize: size, weight: weight)        }        return UIFontMetrics(forTextStyle: style).scaledFont(for: base)    }}/// sites.html's type. Every size scales with the phone's text size and Look's size, up to the largest/// accessibility size; another face chosen in Look stands in for Instrument Sans.@MainActorenum SitesType {    static func sans(_ size: CGFloat, _ weight: UIFont.Weight = .regular, _ style: UIFont.TextStyle = .body) -> Font {        let look = LookModel.standing("sites")        let size = size * look.scale        if look.face != LookFaces.own {            return Font(WritingFonts.font(LookFaces.drawn(look.face, own: "sans"), size: size, weight: weight))        }        return Font(SitesFonts.font(size, weight, style: style))    }    /// Instrument Sans itself, whatever Look's face (the Look screen's chip for it).    static func own(_ size: CGFloat) -> Font { Font(SitesFonts.font(size, .regular, style: .body)) }    /// `.ph h3`: a screen's title.    static var title: Font { sans(31, .bold, .largeTitle) }    /// `.sheet h3`: a sheet's title.    static var sheetTitle: Font { sans(24, .bold, .title2) }    /// `.r .t`: a row's name.    static var name: Font { sans(17, .semibold, .body) }    /// A quiet row's name (Quick visit, Hidden): `font-weight:500`.    static var plainName: Font { sans(17, .medium, .body) }    /// `.r .s`, `.note`: a second line.    static var line: Font { sans(14, .regular, .subheadline) }    /// `.ph h4`: a group's heading.    static var group: Font { sans(14, .semibold, .subheadline) }    /// `body`, `.big`.    static var body: Font { sans(17, .regular, .body) }    static var bodySmall: Font { sans(16, .regular, .callout) }    /// `.btn`.    static var button: Font { sans(17, .bold, .body) }    static var buttonQuiet: Font { sans(17, .semibold, .body) }    /// `.pillx .nm` / `.ad`: the bar's name and address.    static var barName: Font { sans(15, .semibold, .subheadline) }    static var barAddress: Font { sans(12.5, .regular, .caption1) }    /// `.mg`: a site's letter.    static func letter(_ size: CGFloat) -> Font { sans(size, .semibold, .footnote) }}/// The words of the `sites` line set (`ShellLines`), the same as Android's.enum SitesWords {    static func line(_ path: String, _ fills: [String: String] = [:]) -> String {        ShellLines.line("sites", path, fills)    }}// MARK: - The page's icons/// sites.html's line icons (`<symbol id="u-…">`, viewBox 22), drawn at 1.6 in the ink.enum SitesIcon: String {    case search, plus, sites, back, next, more, reload, find, key, words, share, copy, move, gear, lock, face, quick,         close, open, check, pin, pinon, wifi, rest    var path: String {        switch self {        case .search: "M15.5 9.5a6 6 0 1 1-12 0a6 6 0 1 1 12 0M14 14l5 5"        case .plus: "M11 4v14M4 11h14"        case .sites: "M4 6.5h14M4 11h14M4 15.5h9"        case .back: "M13.5 4.5L7 11l6.5 6.5"        case .next: "M8.5 4.5L15 11l-6.5 6.5"        case .more: ""        case .reload: "M17.5 11a6.5 6.5 0 1 1-2-4.7M16 3.5v3.5h-3.5"        case .find: "M4 5h8M4 9h5M4 13h4M18 13a3.5 3.5 0 1 1-7 0a3.5 3.5 0 1 1 7 0M17 15.5l2.5 2.5"        case .key: "M10.8 11a3.8 3.8 0 1 1-7.6 0a3.8 3.8 0 1 1 7.6 0M10.8 11h8.2M16.5 11v3M19 11v2"        case .words: "M5 3h12v16H5zM8 7.5h6M8 11h4M14.5 13v4"        case .share: "M11 3v11M7 7l4-4 4 4M5 11v7h12v-7"        case .copy: "M9.5 7.5h6a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-6a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2zM14.5 7.5V5.5a2 2 0 0 0-2-2h-6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h1"        case .move: "M3.5 7h11M11 3.5L14.5 7 11 10.5M18.5 15h-11M11 11.5L7.5 15l3.5 3.5"        case .gear: "M4 6h8M16 6h2M4 16h2M10 16h8M16 6a2 2 0 1 1-4 0a2 2 0 1 1 4 0M10 16a2 2 0 1 1-4 0a2 2 0 1 1 4 0"        case .lock: "M6.5 9.5h9a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-9a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2zM7.5 9.5V7a3.5 3.5 0 0 1 7 0v2.5"        case .face: "M3 7V5a2 2 0 0 1 2-2h2M15 3h2a2 2 0 0 1 2 2v2M19 15v2a2 2 0 0 1-2 2h-2M7 19H5a2 2 0 0 1-2-2v-2M8 8v1.5M14 8v1.5M11 8v4h-1M8.5 14.5c0 0 1 1.2 2.5 1.2s2.5-1.2 2.5-1.2"        case .quick: ""        case .close: "M5.5 5.5l11 11M16.5 5.5l-11 11"        case .open: "M12 4h6v6M18 4l-8 8M15 13v5H4V7h5"        case .check: "M4.5 11.5l4 4 9-9"        case .pin, .pinon: "M8 3.5h6M9 3.5v5L6 12h10l-3-3.5v-5M11 12v6.5"        case .wifi: "M3 9a11.5 11.5 0 0 1 16 0M6 12.2a7 7 0 0 1 10 0M8.8 15.2a3 3 0 0 1 4.4 0"        case .rest: "M17 13.5A7 7 0 1 1 8.5 5a5.5 5.5 0 0 0 8.5 8.5z"        }    }}/// One of the page's icons, `size` points square, stroked in the current foreground.struct SitesGlyph: View {    let icon: SitesIcon    var size: CGFloat = 22    var weight: CGFloat = 1.6    /// Grows with the phone's text size (to twice at the largest), as the words beside it do.    @ScaledMetric(relativeTo: .body) private var grow: CGFloat = 1    var body: some View {        let size = size * min(max(grow, 1), 2)        Canvas { context, box in            let scale = box.width / 22            let transform = CGAffineTransform(scaleX: scale, y: scale)            let style = StrokeStyle(lineWidth: weight, lineCap: .round, lineJoin: .round)            let shading = GraphicsContext.Shading.foreground            switch icon {            case .more:                for x in [5.0, 11, 17] {                    context.fill(Path(ellipseIn: CGRect(x: x - 1.4, y: 9.6, width: 2.8, height: 2.8)).applying(transform), with: shading)                }            case .quick:                context.stroke(Path(ellipseIn: CGRect(x: 3.5, y: 3.5, width: 15, height: 15)).applying(transform), with: shading,                               style: StrokeStyle(lineWidth: weight, lineCap: .round, dash: [2.2 * scale, 2.6 * scale]))            case .pinon:                let path = SVGPath.parse(icon.path).applying(transform)                context.fill(SVGPath.parse("M8 3.5h6M9 3.5v5L6 12h10l-3-3.5v-5z").applying(transform), with: shading)                context.stroke(path, with: shading, style: style)            case .wifi:                context.stroke(SVGPath.parse(icon.path).applying(transform), with: shading, style: style)                context.fill(Path(ellipseIn: CGRect(x: 10.2, y: 17.2, width: 1.6, height: 1.6)).applying(transform), with: shading)            default:                context.stroke(SVGPath.parse(icon.path).applying(transform), with: shading, style: style)            }        }        .frame(width: size, height: size)        .accessibilityHidden(true)    }}/// The few SVG path commands sites.html's icons use (M L H V C S A Z, absolute and relative), as a SwiftUI `Path`.enum SVGPath {    static func parse(_ d: String) -> Path {        var path = Path()        var tokens: [String] = []        var number = ""        func flush() { if !number.isEmpty { tokens.append(number); number = "" } }        for ch in d {            if ch.isLetter && ch != "e" { flush(); tokens.append(String(ch)) }            else if ch == "-" && !number.isEmpty && number.last != "e" { flush(); number = "-" }            else if ch == "," || ch == " " { flush() }            else if ch == "." && number.contains(".") { flush(); number = "." }            else { number.append(ch) }        }        flush()        var i = 0, command: Character = "M"        var current = CGPoint.zero, start = CGPoint.zero, lastControl: CGPoint?        func next() -> CGFloat { defer { i += 1 }; return i < tokens.count ? CGFloat(Double(tokens[i]) ?? 0) : 0 }        while i < tokens.count {            if let c = tokens[i].first, c.isLetter { command = c; i += 1; if c == "z" || c == "Z" { path.closeSubpath(); current = start; lastControl = nil; continue } }            let relative = command.isLowercase            func point(_ x: CGFloat, _ y: CGFloat) -> CGPoint { relative ? CGPoint(x: current.x + x, y: current.y + y) : CGPoint(x: x, y: y) }            switch command.uppercased().first! {            case "M":                current = point(next(), next()); start = current; path.move(to: current)                command = relative ? "l" : "L"; lastControl = nil            case "L": current = point(next(), next()); path.addLine(to: current); lastControl = nil            case "H": let x = next(); current = CGPoint(x: relative ? current.x + x : x, y: current.y); path.addLine(to: current); lastControl = nil            case "V": let y = next(); current = CGPoint(x: current.x, y: relative ? current.y + y : y); path.addLine(to: current); lastControl = nil            case "C":                let c1 = point(next(), next()), c2 = point(next(), next()), end = point(next(), next())                path.addCurve(to: end, control1: c1, control2: c2); current = end; lastControl = c2            case "S":                let c1 = lastControl.map { CGPoint(x: 2 * current.x - $0.x, y: 2 * current.y - $0.y) } ?? current                let c2 = point(next(), next()), end = point(next(), next())                path.addCurve(to: end, control1: c1, control2: c2); current = end; lastControl = c2            case "A":                let rx = next(), ry = next(), angle = next(), large = next() != 0, sweep = next() != 0                let end = point(next(), next())                arc(&path, from: current, to: end, rx: rx, ry: ry, angle: angle, large: large, sweep: sweep)                current = end; lastControl = nil            default: i += 1            }        }        return path    }    /// An SVG elliptical arc (endpoint form) as cubic curves, by the SVG spec's centre conversion.    private static func arc(_ path: inout Path, from p1: CGPoint, to p2: CGPoint, rx: CGFloat, ry: CGFloat, angle: CGFloat, large: Bool, sweep: Bool) {        var rx = abs(rx), ry = abs(ry)        guard rx > 0, ry > 0, p1 != p2 else { path.addLine(to: p2); return }        let phi = angle * .pi / 180, c = cos(phi), s = sin(phi)        let dx = (p1.x - p2.x) / 2, dy = (p1.y - p2.y) / 2        let x1 = c * dx + s * dy, y1 = -s * dx + c * dy        let lambda = x1 * x1 / (rx * rx) + y1 * y1 / (ry * ry)        if lambda > 1 { rx *= sqrt(lambda); ry *= sqrt(lambda) }        let num = rx * rx * ry * ry - rx * rx * y1 * y1 - ry * ry * x1 * x1        let den = rx * rx * y1 * y1 + ry * ry * x1 * x1        var co = sqrt(max(0, num / den)); if large == sweep { co = -co }        let cx1 = co * rx * y1 / ry, cy1 = -co * ry * x1 / rx        let cx = c * cx1 - s * cy1 + (p1.x + p2.x) / 2, cy = s * cx1 + c * cy1 + (p1.y + p2.y) / 2        func angleOf(_ ux: CGFloat, _ uy: CGFloat, _ vx: CGFloat, _ vy: CGFloat) -> CGFloat {            let a = atan2(ux * vy - uy * vx, ux * vx + uy * vy); return a        }        let theta1 = angleOf(1, 0, (x1 - cx1) / rx, (y1 - cy1) / ry)        var delta = angleOf((x1 - cx1) / rx, (y1 - cy1) / ry, (-x1 - cx1) / rx, (-y1 - cy1) / ry)        if !sweep && delta > 0 { delta -= 2 * .pi } else if sweep && delta < 0 { delta += 2 * .pi }        let pieces = Int(ceil(abs(delta) / (.pi / 2)))        let step = delta / CGFloat(pieces)        let k = 4 / 3 * tan(step / 4)        var t = theta1        func on(_ a: CGFloat) -> CGPoint { CGPoint(x: cx + rx * cos(a) * c - ry * sin(a) * s, y: cy + rx * cos(a) * s + ry * sin(a) * c) }        func d(_ a: CGFloat) -> CGPoint { CGPoint(x: -rx * sin(a) * c - ry * cos(a) * s, y: -rx * sin(a) * s + ry * cos(a) * c) }        for _ in 0..<pieces {            let a = on(t), b = on(t + step), da = d(t), db = d(t + step)            path.addCurve(to: b, control1: CGPoint(x: a.x + k * da.x, y: a.y + k * da.y), control2: CGPoint(x: b.x - k * db.x, y: b.y - k * db.y))            t += step        }    }}// MARK: - Drawn things/// Double Slash, the app's mark: the two slashes of every web address (`scripts/draw-app-icons.mjs` sites).struct SitesMark: View {    var size: CGFloat = 64    var colour: Color = Cranberry.accent    var body: some View {        Canvas { context, box in            let s = box.width / 1024            var path = Path()            path.move(to: CGPoint(x: 474 * s, y: 232 * s)); path.addLine(to: CGPoint(x: 334 * s, y: 792 * s))            path.move(to: CGPoint(x: 694 * s, y: 232 * s)); path.addLine(to: CGPoint(x: 554 * s, y: 792 * s))            context.stroke(path, with: .color(colour), style: StrokeStyle(lineWidth: 112 * s, lineCap: .round))        }        .frame(width: size, height: size)        .accessibilityHidden(true)    }}/// `.mg`: a site's letter in a thin ring, drawn by the app (no favicons). Dashed for a hidden site, dotted for a/// quick visit or a search.struct SitesLetter: View {    enum Kind { case plain, hidden, quick }    let letter: String    var kind: Kind = .plain    var size: CGFloat = 32    @ScaledMetric(relativeTo: .body) private var grow: CGFloat = 1    var body: some View {        let size = size * min(max(grow, 1), 1.8)        let width: CGFloat = size < 28 ? 1.1 : (kind == .quick ? 1.6 : 1.3)        let dash: [CGFloat] = switch kind {        case .plain: []        case .hidden: [3, 2.2]        case .quick: [0.1, 3]        }        Text(letter)            .font(SitesType.letter(size * 0.44))            .foregroundStyle(Cranberry.ink)            .lineLimit(1)            .minimumScaleFactor(0.5)            .frame(width: size, height: size)            .background(Circle().fill(Cranberry.ground))            .overlay(Circle().inset(by: width / 2).stroke(Cranberry.ink, style: StrokeStyle(lineWidth: width, lineCap: .round, dash: dash)))            .accessibilityHidden(true)    }}/// `.live`: the small dot for a page the phone keeps alive now.struct SitesLiveDot: View {    var body: some View {        Circle().fill(Cranberry.ink).frame(width: 7, height: 7)            .accessibilityHidden(true)    }}/// A 1 pt rule across.struct SitesRule: View {    var body: some View { Rectangle().fill(Cranberry.rule).frame(height: 1).accessibilityHidden(true) }}/// `.round`: the list's round buttons (+, You's initial).struct SitesRound<Label: View>: View {    var size: CGFloat = 40    @ViewBuilder let label: () -> Label    @ScaledMetric(relativeTo: .body) private var grow: CGFloat = 1    var body: some View {        let size = size * min(max(grow, 1), 2)        return label()            .foregroundStyle(Cranberry.ink)            .frame(width: size, height: size)            .overlay(Circle().strokeBorder(Cranberry.ink, lineWidth: Cranberry.stroke))            .contentShape(Circle())    }}/// `.btn`, `.btn.go`, `.btn.quiet`: 52 tall, rounded 16.struct SitesButtonStyle: ButtonStyle {    enum Kind { case go, plain, quiet }    var kind: Kind = .plain    func makeBody(configuration: Configuration) -> some View {        configuration.label            .font(kind == .quiet ? SitesType.buttonQuiet : SitesType.button)            .multilineTextAlignment(.center)            .foregroundStyle(kind == .go ? Cranberry.onAccent : Cranberry.ink)            .frame(maxWidth: .infinity, minHeight: 52)            .padding(.horizontal, 16)            .background(RoundedRectangle(cornerRadius: 16).fill(kind == .go ? Cranberry.accent : .clear))            .overlay(RoundedRectangle(cornerRadius: 16).strokeBorder(kind == .go ? Cranberry.accent : (kind == .quiet ? Cranberry.rule : Cranberry.ink),                                                                      lineWidth: Cranberry.stroke))            .contentShape(RoundedRectangle(cornerRadius: 16))            .opacity(configuration.isPressed ? 0.6 : 1)    }}/// `.tog`: the ink switch, 44 by 26.struct SitesToggle: View {    let label: String    var line: String?    @Binding var on: Bool    var tag: String    var body: some View {        Button { on.toggle() } label: {            HStack(spacing: 12) {                VStack(alignment: .leading, spacing: 2) {                    Text(label).font(SitesType.plainName).foregroundStyle(Cranberry.ink)                    if let line { Text(line).font(SitesType.line).foregroundStyle(Cranberry.quiet) }                }                .frame(maxWidth: .infinity, alignment: .leading)                ZStack(alignment: on ? .trailing : .leading) {                    Capsule().fill(on ? Cranberry.ink : .clear)                    Capsule().strokeBorder(on ? Cranberry.ink : Cranberry.rule, lineWidth: Cranberry.stroke)                    Circle().fill(on ? Cranberry.ground : Cranberry.faint).frame(width: 17, height: 17).padding(.horizontal, 4)                }                .frame(width: 44, height: 26)                .animation(.easeOut(duration: 0.15), value: on)            }            .padding(.vertical, 11)            .contentShape(Rectangle())        }        .buttonStyle(.plain)        .accessibilityElement(children: .ignore)        .accessibilityLabel(label)        .accessibilityValue(on ? "On" : "Off")        .accessibilityAddTraits(.isButton)        .accessibilityIdentifier(tag)    }}/// `.opt`: one of a few choices, the chosen one's ring filled in ink.struct SitesOption: View {    let label: String    var line: String?    let chosen: Bool    var tag: String    let choose: () -> Void    var body: some View {        Button(action: choose) {            HStack(spacing: 10) {                VStack(alignment: .leading, spacing: 2) {                    Text(label).font(SitesType.sans(17, chosen ? .bold : .semibold)).foregroundStyle(Cranberry.ink)                    if let line { Text(line).font(SitesType.line).foregroundStyle(Cranberry.quiet) }                }                .frame(maxWidth: .infinity, alignment: .leading)                Circle().strokeBorder(chosen ? Cranberry.ink : Cranberry.rule, lineWidth: chosen ? 6.5 : 1.5)                    .frame(width: 22, height: 22)            }            .padding(.vertical, 12)            .contentShape(Rectangle())        }        .buttonStyle(.plain)        .accessibilityElement(children: .combine)        .accessibilityAddTraits(chosen ? [.isButton, .isSelected] : .isButton)        .accessibilityIdentifier(tag)    }}/// `.ph h4`: a group's heading.struct SitesGroupHead: View {    let words: String    var body: some View {        Text(words).font(SitesType.group).foregroundStyle(Cranberry.quiet)            .frame(maxWidth: .infinity, alignment: .leading)            .padding(.top, 22).padding(.bottom, 2)            .accessibilityAddTraits(.isHeader)    }}/// `.sheet`: a sheet rising over a page or the list, with its grab and the ground's top edge, closed by a swipe down/// or a tap on the veil.struct SitesSheet<Content: View>: View {    let close: () -> Void    var tag: String    @ViewBuilder let content: () -> Content    @State private var drag: CGFloat = 0    /// The content's own height, so the sheet hugs it and scrolls only past most of the screen.    @State private var tall: CGFloat = 0    /// A swipe down: followed while it moves, closing past 80 points or on a flick.    private var pull: some Gesture {        DragGesture(minimumDistance: 14)            .onChanged { move in                guard move.translation.height > abs(move.translation.width) else { return }                drag = move.translation.height            }            .onEnded { end in                if end.translation.height > abs(end.translation.width),                   end.translation.height > 80 || end.predictedEndTranslation.height > 240 { close() }                withAnimation(.easeOut(duration: 0.2)) { drag = 0 }            }    }    var body: some View {        GeometryReader { screen in            ZStack(alignment: .bottom) {                Cranberry.veil.ignoresSafeArea()                    .onTapGesture(perform: close)                    // A swipe down over the veil closes the sheet as a tap on it does.                    .gesture(DragGesture(minimumDistance: 14).onEnded { end in                        if end.translation.height > 40, end.translation.height > abs(end.translation.width) { close() }                    })                    .accessibilityHidden(true)                VStack(spacing: 0) {                    Capsule().fill(Cranberry.rule).frame(width: 38, height: 4).padding(.top, 10).padding(.bottom, 10)                        .frame(maxWidth: .infinity)                        .contentShape(Rectangle())                        .gesture(pull)                        .accessibilityHidden(true)                    ScrollView {                        content()                            .padding(.horizontal, Cranberry.side)                            .padding(.bottom, 26)                            .onGeometryChange(for: CGFloat.self) { $0.size.height } action: { tall = $0 }                    }                    .scrollBounceBehavior(.basedOnSize)                    .scrollDismissesKeyboard(.interactively)                    // A sheet long enough to scroll closes when pulled down past its top, as the phone's own do.                    .onScrollGeometryChange(for: CGFloat.self) { $0.contentOffset.y + $0.contentInsets.top } action: { _, top in                        if top < -64 { close() }                    }                    .frame(height: min(max(tall, 1), screen.size.height * 0.86))                }                // A sheet that fits closes from a swipe down anywhere on it; one that scrolls, from its grab or a pull past its top.                .simultaneousGesture(tall <= screen.size.height * 0.86 ? pull : nil)                .frame(maxWidth: .infinity)                .background(UnevenRoundedRectangle(topLeadingRadius: 26, topTrailingRadius: 26).fill(Cranberry.ground).ignoresSafeArea(edges: .bottom))                .overlay(alignment: .top) {                    UnevenRoundedRectangle(topLeadingRadius: 26, topTrailingRadius: 26).stroke(Cranberry.rule, lineWidth: 1)                        .frame(height: 30).mask(Rectangle().frame(height: 30))                        .accessibilityHidden(true)                }                .offset(y: max(0, drag))                .accessibilityElement(children: .contain)                .accessibilityIdentifier(tag)                .accessibilityAction(.escape, close)            }        }        .transition(.move(edge: .bottom).combined(with: .opacity))    }}/// A line passing at the foot ("Link copied", "Saved"), said to VoiceOver as it comes.struct SitesToast: View {    let words: String    var body: some View {        Text(words)            .font(SitesType.sans(15, .semibold))            .foregroundStyle(Cranberry.ground)            .padding(.horizontal, 16).padding(.vertical, 11)            .background(Capsule().fill(Cranberry.ink))            .padding(.horizontal, Cranberry.side)            .accessibilityIdentifier("sites-toast")            .onAppear { UIAccessibility.post(notification: .announcement, argument: words) }    }}/// "Club removed · Undo": the toast that stands while a removal can still be taken back.struct SitesUndoToast: View {    let words: String    let label: String    let undo: () -> Void    var body: some View {        HStack(spacing: 14) {            Text(words)                .font(SitesType.sans(15, .semibold))                .foregroundStyle(Cranberry.ground)                .fixedSize(horizontal: false, vertical: true)            Button(action: undo) {                Text(label)                    .font(SitesType.sans(15, .bold))                    .foregroundStyle(Cranberry.ground)                    .underline()                    .frame(minHeight: 44)                    .contentShape(Rectangle())            }            .buttonStyle(.plain)            .accessibilityIdentifier("sites-undo")        }        .padding(.leading, 18).padding(.trailing, 12).padding(.vertical, 2)        .background(Capsule().fill(Cranberry.ink))        .padding(.horizontal, Cranberry.side)        .accessibilityElement(children: .contain)        .accessibilityIdentifier("sites-removing")        .onAppear { UIAccessibility.post(notification: .announcement, argument: words) }    }}#endif